From 2037edb5a22cf9c7d2dd665a3ce8b1eb470cadd1 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 2 Jan 2024 18:11:41 +1100 Subject: [PATCH 001/408] all: Bump version to 1.23.0-preview. Signed-off-by: Damien George --- py/mpconfig.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/py/mpconfig.h b/py/mpconfig.h index 66a083da457b5..a1e9660bf46a6 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -30,9 +30,9 @@ // as well as a fallback to generate MICROPY_GIT_TAG if the git repo or tags // are unavailable. #define MICROPY_VERSION_MAJOR 1 -#define MICROPY_VERSION_MINOR 22 +#define MICROPY_VERSION_MINOR 23 #define MICROPY_VERSION_MICRO 0 -#define MICROPY_VERSION_PRERELEASE 0 +#define MICROPY_VERSION_PRERELEASE 1 // Combined version as a 32-bit number for convenience to allow version // comparison. Doesn't include prerelease state. From 87d3f8b367dfe97d03863f62f565a3ddee1cb945 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sun, 31 Dec 2023 08:32:09 +0100 Subject: [PATCH 002/408] mimxrt/mphalport: Remove redundant NVIC/IRQ defines. These are already defined in `irq.h`. Signed-off-by: iabdalkader --- ports/mimxrt/mphalport.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/ports/mimxrt/mphalport.h b/ports/mimxrt/mphalport.h index c4e5b052c9d00..4f1f4bfd123a9 100644 --- a/ports/mimxrt/mphalport.h +++ b/ports/mimxrt/mphalport.h @@ -41,9 +41,6 @@ // For regular code that wants to prevent "background tasks" from running. // These background tasks (LWIP, Bluetooth) run in PENDSV context. -// TODO: Check for the settings of the STM32 port in irq.h -#define NVIC_PRIORITYGROUP_4 ((uint32_t)0x00000003) -#define IRQ_PRI_PENDSV NVIC_EncodePriority(NVIC_PRIORITYGROUP_4, 15, 0) #define MICROPY_PY_PENDSV_ENTER uint32_t atomic_state = raise_irq_pri(IRQ_PRI_PENDSV); #define MICROPY_PY_PENDSV_REENTER atomic_state = raise_irq_pri(IRQ_PRI_PENDSV); #define MICROPY_PY_PENDSV_EXIT restore_irq_pri(atomic_state); From f34e27f178afe707062173b9394cd994ab8c82cc Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sun, 31 Dec 2023 09:42:39 +0100 Subject: [PATCH 003/408] mimxrt/mpbthciport: Add missing extmod/modmachine.h header. Include extmod/modmachine.h for machine_uart_type declaration. Signed-off-by: iabdalkader --- ports/mimxrt/mpbthciport.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/mimxrt/mpbthciport.c b/ports/mimxrt/mpbthciport.c index 4325655e57407..2b0bcd2cf6c4d 100644 --- a/ports/mimxrt/mpbthciport.c +++ b/ports/mimxrt/mpbthciport.c @@ -29,6 +29,7 @@ #include "py/stream.h" #include "py/mphal.h" #include "extmod/modbluetooth.h" +#include "extmod/modmachine.h" #include "extmod/mpbthci.h" #include "shared/runtime/softtimer.h" #include "modmachine.h" From 8498b0b13e9a14e1ee009623cedd14701ae398f1 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Fri, 24 Nov 2023 08:23:26 +0100 Subject: [PATCH 004/408] docs/samd/pinout: Update pinout docs with fixed pin assignment. Fixes a wrong assignment for Sparkfun SAMD51 Thing Plus, and updates the sample script for printing the pin info table. Signed-off-by: robert-hh --- docs/samd/pinout.rst | 50 +++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/docs/samd/pinout.rst b/docs/samd/pinout.rst index 272f7c58df087..5ff72b83586ac 100644 --- a/docs/samd/pinout.rst +++ b/docs/samd/pinout.rst @@ -870,7 +870,7 @@ Adafruit ItsyBitsy M4 Express :ref:`samd51_pinout_table`. The default devices at the board are: -- UART 1 at pins PB23/PB22, labelled RXD/TXD +- UART 2 at pins PA13/PA12, labelled RXD/TXD - I2C 5 at pins PA22/PA23, labelled SDA/SCL - SPI 4 at pins PB12/PB11/PB13, labelled MOSI, MISO and SCK - DAC output on pins PA02 and PA05, labelled A0 and A4 @@ -884,36 +884,36 @@ The tables shown above were created with small a Python script running on the ta from machine import Pin import os - def print_entry(e, txt): + def print_item(e, txt): print(txt, end=": ") if e == 255: print(" - ", end="") else: print("%d/%d" % (e >> 4, e & 0x0f), end="") - def print_pininfo(pin, info): - print("%3d" % pin, end=" ") - print("P%c%02d" % ("ABCD"[pin // 32], pin % 32), end="") - print(" %12s" % info[0], end="") + def print_pininfo(pin_id, name, info): + + print("%3d" % pin_id, end=" ") + print("%4s %12s" % (info[0], name), end="") print(" IRQ:%2s" % (info[1] if info[1] != 255 else "-"), end="") print(" ADC0:%2s" % (info[2] if info[2] != 255 else "-"), end="") if len(info) == 7: - print_entry(info[3], " Serial1") - print_entry(info[4], " Serial2") - print_entry(info[5], " PWM1" if (info[5] >> 4) < 3 else " TC") - print_entry(info[6], " PWM2") + print_item(info[3], " Serial1") + print_item(info[4], " Serial2") + print_item(info[5], " PWM1" if (info[5] >> 4) < 3 else " TC") + print_item(info[6], " PWM2") else: print(" ADC1:%2s" % (info[3] if info[3] != 255 else "-"), end="") - print_entry(info[4], " Serial1") - print_entry(info[5], " Serial2") - print_entry(info[6], " TC") - print_entry(info[7], " PWM1") - print_entry(info[8], " PWM2") + print_item(info[4], " Serial1") + print_item(info[5], " Serial2") + print_item(info[6], " TC") + print_item(info[7], " PWM1") + print_item(info[8], " PWM2") print() def tblkey(i): - name = i[1][0] - if name != "-": + name = i[1] + if name != "": if len(name) < 3: return " " + name else: @@ -921,17 +921,25 @@ The tables shown above were created with small a Python script running on the ta else: return "zzzzzzz%03d" % i[0] - def table(num = 127): + def table(num=127, sort=True): pintbl = [] + inv_bd = {v: k for k, v in Pin.board.__dict__.items()} for i in range(num): try: - pintbl.append((i, pininfo(i))) + p = Pin(i) + pi = pininfo(p) + if p in inv_bd.keys(): + name = inv_bd[p] + else: + name = "" + pintbl.append((i, name, pininfo(i))) except: pass # print("not defined") - pintbl.sort(key=tblkey) + if sort: + pintbl.sort(key=tblkey) for item in pintbl: - print_pininfo(item[0], item[1]) + print_pininfo(item[0], item[1], item[2]) table() From 36d9e98fc6b5fb0315ade399fbd8f357a44196a6 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Thu, 30 Nov 2023 21:27:23 +0100 Subject: [PATCH 005/408] samd: Remove the MICROPY_PY_MACHINE_RTC config option. RTC is enabled on all boards. Therefore the conditional compile is not needed. Removing it simplifies the source code a little bit. Signed-off-by: robert-hh --- ports/samd/fatfs_port.c | 8 -------- ports/samd/machine_rtc.c | 4 ---- ports/samd/modmachine.c | 8 +------- ports/samd/mpconfigport.h | 1 - ports/samd/samd_soc.c | 4 ---- 5 files changed, 1 insertion(+), 24 deletions(-) diff --git a/ports/samd/fatfs_port.c b/ports/samd/fatfs_port.c index a3e3f1b67b3a9..91912d97d8e01 100644 --- a/ports/samd/fatfs_port.c +++ b/ports/samd/fatfs_port.c @@ -33,13 +33,5 @@ extern uint32_t time_offset; MP_WEAK DWORD get_fattime(void) { - #if MICROPY_PY_MACHINE_RTC return (RTC->MODE2.CLOCK.reg >> 1) + (20 << 25); - #else - extern void rtc_gettime(timeutils_struct_time_t *tm); - timeutils_struct_time_t tm; - timeutils_seconds_since_epoch_to_struct_time(mp_hal_ticks_ms_64() / 1000 + time_offset, &tm); - return ((tm.tm_year - 1980) << 25) | ((tm.tm_mon) << 21) | ((tm.tm_mday) << 16) | - ((tm.tm_hour) << 11) | ((tm.tm_min) << 5) | (tm.tm_sec / 2); - #endif } diff --git a/ports/samd/machine_rtc.c b/ports/samd/machine_rtc.c index e6237f3f3609a..1f0c9f4dca990 100644 --- a/ports/samd/machine_rtc.c +++ b/ports/samd/machine_rtc.c @@ -31,8 +31,6 @@ #include "extmod/modmachine.h" #include "sam.h" -#if MICROPY_PY_MACHINE_RTC - typedef struct _machine_rtc_obj_t { mp_obj_base_t base; mp_obj_t callback; @@ -177,5 +175,3 @@ MP_DEFINE_CONST_OBJ_TYPE( make_new, machine_rtc_make_new, locals_dict, &machine_rtc_locals_dict ); - -#endif // MICROPY_PY_MACHINE_RTC diff --git a/ports/samd/modmachine.c b/ports/samd/modmachine.c index 9aab705bf70a8..c39aec95ea156 100644 --- a/ports/samd/modmachine.c +++ b/ports/samd/modmachine.c @@ -48,16 +48,10 @@ #define LIGHTSLEEP_CPU_FREQ 200000 -#if MICROPY_PY_MACHINE_RTC -#define MICROPY_PY_MACHINE_RTC_ENTRY { MP_ROM_QSTR(MP_QSTR_RTC), MP_ROM_PTR(&machine_rtc_type) }, -#else -#define MICROPY_PY_MACHINE_RTC_ENTRY -#endif - #define MICROPY_PY_MACHINE_EXTRA_GLOBALS \ { MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&machine_pin_type) }, \ { MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&machine_timer_type) }, \ - MICROPY_PY_MACHINE_RTC_ENTRY \ + { MP_ROM_QSTR(MP_QSTR_RTC), MP_ROM_PTR(&machine_rtc_type) }, \ \ /* Class constants. */ \ /* Use numerical constants instead of the symbolic names, */ \ diff --git a/ports/samd/mpconfigport.h b/ports/samd/mpconfigport.h index 21c29be24e3ae..466a4d7751c97 100644 --- a/ports/samd/mpconfigport.h +++ b/ports/samd/mpconfigport.h @@ -109,7 +109,6 @@ #define MICROPY_PY_RANDOM (1) #define MICROPY_PY_DEFLATE (1) #define MICROPY_PY_ASYNCIO (1) -#define MICROPY_PY_MACHINE_RTC (1) #ifndef MICROPY_PY_MACHINE_ADC #define MICROPY_PY_MACHINE_ADC (1) #endif diff --git a/ports/samd/samd_soc.c b/ports/samd/samd_soc.c index dcfff9dc22744..259640e93db0d 100644 --- a/ports/samd/samd_soc.c +++ b/ports/samd/samd_soc.c @@ -38,9 +38,7 @@ #include "tusb.h" #include "mphalport.h" -#if MICROPY_PY_MACHINE_RTC extern void machine_rtc_start(bool force); -#endif static void usb_init(void) { // Init USB clock @@ -124,9 +122,7 @@ void samd_init(void) { #if defined(MCU_SAMD51) mp_hal_ticks_cpu_enable(); #endif - #if MICROPY_PY_MACHINE_RTC machine_rtc_start(false); - #endif } #if MICROPY_PY_MACHINE_I2C || MICROPY_PY_MACHINE_SPI || MICROPY_PY_MACHINE_UART From aea93a88f82105699f44431b76ff3107fd7b5a45 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Wed, 14 Jun 2023 16:56:58 +0200 Subject: [PATCH 006/408] samd/mcu/samd21: Reorganize and enable more firmware features. This commit enables additional features for SAMD21 with external flash: - Viper and native code support. On a relatively slow devices, viper and native code can be helpful. - Freeze the asyncio scripts and add the select module. - Enable Framebuffer support. - Enable UART flow control. - Enable a few more features from the extra features set. Drop onewire and asyncio support from SAMD21 firmware without external flash, leaving a little bit more room for future extensions. Asyncio was anyhow incomplete. Signed-off-by: robert-hh --- ports/samd/Makefile | 3 +- ports/samd/mcu/samd21/manifest.py | 5 +++ ports/samd/mcu/samd21/mpconfigmcu.h | 52 +++++++++++++++++++++------- ports/samd/mcu/samd21/mpconfigmcu.mk | 4 +++ ports/samd/mcu/samd51/mpconfigmcu.h | 1 + ports/samd/mpconfigport.h | 3 -- 6 files changed, 51 insertions(+), 17 deletions(-) create mode 100644 ports/samd/mcu/samd21/manifest.py diff --git a/ports/samd/Makefile b/ports/samd/Makefile index 4f4c22c57daa9..5a7cb9916a349 100644 --- a/ports/samd/Makefile +++ b/ports/samd/Makefile @@ -68,7 +68,8 @@ CFLAGS += $(INC) -Wall -Werror -std=c99 -nostdlib -mthumb $(CFLAGS_MCU) -fsingle CFLAGS += -DMCU_$(MCU_SERIES) -D__$(CMSIS_MCU)__ CFLAGS += $(CFLAGS_EXTRA) -CFLAGS += -DMICROPY_HW_CODESIZE=$(MICROPY_HW_CODESIZE) +# Strip the letter 'K' from MICROPY_HW_CODESIZE for use by C code. +CFLAGS += -DMICROPY_HW_CODESIZE=$(strip $(subst K,' ', $(MICROPY_HW_CODESIZE))) LDFLAGS += -nostdlib $(addprefix -T,$(LD_FILES)) -Map=$@.map --cref LDFLAGS += --defsym=_codesize=$(MICROPY_HW_CODESIZE) diff --git a/ports/samd/mcu/samd21/manifest.py b/ports/samd/mcu/samd21/manifest.py new file mode 100644 index 0000000000000..2a19a843f8a9b --- /dev/null +++ b/ports/samd/mcu/samd21/manifest.py @@ -0,0 +1,5 @@ +include("$(PORT_DIR)/boards/manifest.py") +include("$(MPY_DIR)/extmod/asyncio") +require("onewire") +require("ds18x20") +require("dht") diff --git a/ports/samd/mcu/samd21/mpconfigmcu.h b/ports/samd/mcu/samd21/mpconfigmcu.h index 1a3d9587291fe..35e59a6706cdd 100644 --- a/ports/samd/mcu/samd21/mpconfigmcu.h +++ b/ports/samd/mcu/samd21/mpconfigmcu.h @@ -1,25 +1,28 @@ // Deinitions common to all SAMD21 boards #include "samd21.h" -#define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_CORE_FEATURES) +#define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_BASIC_FEATURES) +#if MICROPY_HW_CODESIZE == 248 +#define SAMD21_EXTRA_FEATURES 1 +#else +#define SAMD21_EXTRA_FEATURES 0 +#endif // MicroPython emitters -#define MICROPY_EMIT_THUMB (0) -#define MICROPY_EMIT_INLINE_THUMB (0) +#define MICROPY_EMIT_THUMB (SAMD21_EXTRA_FEATURES) +#define MICROPY_EMIT_INLINE_THUMB (SAMD21_EXTRA_FEATURES) +#define MICROPY_EMIT_THUMB_ARMV7M (0) #define MICROPY_MODULE_BUILTIN_INIT (1) #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT) -#ifndef MICROPY_PY_BUILTINS_COMPLEX -#define MICROPY_PY_BUILTINS_COMPLEX (0) -#endif - -#ifndef MICROPY_PY_TIME -#define MICROPY_PY_TIME (1) -#endif - #ifndef MICROPY_PY_MATH #define MICROPY_PY_MATH (1) +#define MP_NEED_LOG2 (1) +#endif + +#ifndef MICROPY_PY_BUILTINS_COMPLEX +#define MICROPY_PY_BUILTINS_COMPLEX (0) #endif #ifndef MICROPY_PY_CMATH @@ -29,13 +32,36 @@ #define MICROPY_PY_RANDOM_SEED_INIT_FUNC (trng_random_u32(300)) unsigned long trng_random_u32(int delay); -#define VFS_BLOCK_SIZE_BYTES (1536) // 24x 64B flash pages; - #ifndef MICROPY_HW_UART_TXBUF #define MICROPY_HW_UART_TXBUF (1) #endif +#ifndef MICROPY_HW_UART_RTSCTS +#define MICROPY_HW_UART_RTSCTS (SAMD21_EXTRA_FEATURES) +#endif +// selected extensions of the extra features set #define MICROPY_PY_OS_URANDOM (1) +#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (SAMD21_EXTRA_FEATURES) +#define MICROPY_COMP_RETURN_IF_EXPR (SAMD21_EXTRA_FEATURES) +#define MICROPY_OPT_MPZ_BITWISE (SAMD21_EXTRA_FEATURES) +#define MICROPY_PY_BUILTINS_STR_CENTER (SAMD21_EXTRA_FEATURES) +#define MICROPY_PY_BUILTINS_STR_PARTITION (SAMD21_EXTRA_FEATURES) +#define MICROPY_PY_BUILTINS_STR_SPLITLINES (SAMD21_EXTRA_FEATURES) +#define MICROPY_PY_BUILTINS_ROUND_INT (SAMD21_EXTRA_FEATURES) +#define MICROPY_CAN_OVERRIDE_BUILTINS (SAMD21_EXTRA_FEATURES) +#define MICROPY_PY_SYS_STDIO_BUFFER (SAMD21_EXTRA_FEATURES) +#define MICROPY_PY_FRAMEBUF (SAMD21_EXTRA_FEATURES) +#define MICROPY_PY_ASYNCIO (SAMD21_EXTRA_FEATURES) +#define MICROPY_PY_SELECT (SAMD21_EXTRA_FEATURES) +#define MICROPY_PY_ERRNO (SAMD21_EXTRA_FEATURES) +#define MICROPY_PY_DEFLATE (SAMD21_EXTRA_FEATURES) +#define MICROPY_PY_ONEWIRE (SAMD21_EXTRA_FEATURES) + +#ifndef MICROPY_PY_MACHINE_PIN_BOARD_CPU +#define MICROPY_PY_MACHINE_PIN_BOARD_CPU (1) +#endif + +#define VFS_BLOCK_SIZE_BYTES (1536) // 24x 64B flash pages; #define CPU_FREQ (48000000) #define DFLL48M_FREQ (48000000) diff --git a/ports/samd/mcu/samd21/mpconfigmcu.mk b/ports/samd/mcu/samd21/mpconfigmcu.mk index b3092837cbd15..89e63c3aaf2b4 100644 --- a/ports/samd/mcu/samd21/mpconfigmcu.mk +++ b/ports/samd/mcu/samd21/mpconfigmcu.mk @@ -6,6 +6,10 @@ MPY_CROSS_MCU_ARCH = armv6m MICROPY_HW_CODESIZE ?= 184K +ifeq ($(MICROPY_HW_CODESIZE), 248K) +FROZEN_MANIFEST ?= mcu/$(MCU_SERIES_LOWER)/manifest.py +endif + MICROPY_VFS_LFS1 ?= 1 SRC_S += shared/runtime/gchelper_thumb1.s diff --git a/ports/samd/mcu/samd51/mpconfigmcu.h b/ports/samd/mcu/samd51/mpconfigmcu.h index 7c95c341b9aef..b8206558b4676 100644 --- a/ports/samd/mcu/samd51/mpconfigmcu.h +++ b/ports/samd/mcu/samd51/mpconfigmcu.h @@ -27,6 +27,7 @@ #define MICROPY_PY_OS_SYNC (1) #define MICROPY_PY_OS_URANDOM (1) +#define MICROPY_PY_ONEWIRE (1) #define MICROPY_PY_RANDOM_SEED_INIT_FUNC (trng_random_u32()) unsigned long trng_random_u32(void); diff --git a/ports/samd/mpconfigport.h b/ports/samd/mpconfigport.h index 466a4d7751c97..a7a6e26629272 100644 --- a/ports/samd/mpconfigport.h +++ b/ports/samd/mpconfigport.h @@ -107,8 +107,6 @@ #define MICROPY_PY_UCTYPES (1) #define MICROPY_PY_HEAPQ (1) #define MICROPY_PY_RANDOM (1) -#define MICROPY_PY_DEFLATE (1) -#define MICROPY_PY_ASYNCIO (1) #ifndef MICROPY_PY_MACHINE_ADC #define MICROPY_PY_MACHINE_ADC (1) #endif @@ -150,7 +148,6 @@ #define MICROPY_PY_MACHINE_WDT (1) #define MICROPY_PY_MACHINE_WDT_INCLUDEFILE "ports/samd/machine_wdt.c" #define MICROPY_PY_MACHINE_WDT_TIMEOUT_MS (1) -#define MICROPY_PY_ONEWIRE (1) #define MICROPY_PY_PLATFORM (1) #define MICROPY_PLATFORM_VERSION "ASF4" From 3d0b6276f3a4500df0a3df5feb1266eb186054b3 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Sat, 30 Dec 2023 09:04:18 +0100 Subject: [PATCH 007/408] samd/mcu: Fix wrong EIC table entries in pin-af-table.csv. Fixes: - SAMD21: PB16 - SAMD51: PB03, PB22 and PB00. Signed-off-by: robert-hh --- ports/samd/mcu/samd21/pin-af-table.csv | 2 +- ports/samd/mcu/samd51/pin-af-table.csv | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ports/samd/mcu/samd21/pin-af-table.csv b/ports/samd/mcu/samd21/pin-af-table.csv index 37bb592597edc..31ca2936f66c1 100644 --- a/ports/samd/mcu/samd21/pin-af-table.csv +++ b/ports/samd/mcu/samd21/pin-af-table.csv @@ -42,7 +42,7 @@ PA16,0,,10,30,20,06 PA17,1,,11,31,21,07 PA18,2,,12,32,30,02 PA19,3,,13,33,31,03 -PB16,9,,50,,60,04 +PB16,0,,50,,60,04 PB17,1,,51,,61,05 PA20,4,,52,32,70,04 PA21,5,,53,33,71,07 diff --git a/ports/samd/mcu/samd51/pin-af-table.csv b/ports/samd/mcu/samd51/pin-af-table.csv index 69f51a33ca170..c8f9a240dd38e 100644 --- a/ports/samd/mcu/samd51/pin-af-table.csv +++ b/ports/samd/mcu/samd51/pin-af-table.csv @@ -11,7 +11,7 @@ # Rows not starting with pa, pb, pc or pd are ignored. # When editing the table with a spread sheet, take care to import the data as text. Pin,EIC,ADC0,ADC1,SERCOM1,SERCOM2,TC,TCC1,TCC2 -PB03,9,15,,,51,61,, +PB03,3,15,,,51,61,, PA00,0,,,,10,20,, PA01,1,,,,11,21,, PC00,0,,10,,,,, @@ -87,7 +87,7 @@ PA22,6,,,30,51,40,16,02 PA23,7,,,31,50,41,17,03 PA24,8,,,32,52,50,22, PA25,9,,,33,53,51,, -PB22,22,,,12,52,70,, +PB22,6,,,12,52,70,, PB23,7,,,13,53,71,, PB24,8,,,00,21,,, PB25,9,,,01,20,,, @@ -107,6 +107,6 @@ PB30,14,,,70,51,00,40,06 PB31,15,,,71,50,01,41,07 PC30,14,,12,,,,, PC31,15,,13,,,,, -PB00,9,12,,,52,70,, +PB00,0,12,,,52,70,, PB01,1,13,,,53,71,, PB02,2,14,,,50,60,22, From c3989e398f809dcde2b0ed1b956498a4d9738619 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 2 Jan 2024 01:03:13 +1100 Subject: [PATCH 008/408] rp2/rp2_flash: Lockout second core only when doing flash erase/write. Using the multicore lockout feature in the general atomic section makes it much more difficult to get correct. Signed-off-by: Damien George --- ports/rp2/mpthreadport.c | 4 ---- ports/rp2/rp2_flash.c | 31 ++++++++++++++++++++++--------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/ports/rp2/mpthreadport.c b/ports/rp2/mpthreadport.c index 968de1f782e69..7bffabb3355eb 100644 --- a/ports/rp2/mpthreadport.c +++ b/ports/rp2/mpthreadport.c @@ -52,9 +52,6 @@ uint32_t mp_thread_begin_atomic_section(void) { // When both cores are executing, we also need to provide // full mutual exclusion. mp_thread_mutex_lock(&atomic_mutex, 1); - // In case this atomic section is for flash access, then - // suspend the other core. - multicore_lockout_start_blocking(); } return save_and_disable_interrupts(); @@ -64,7 +61,6 @@ void mp_thread_end_atomic_section(uint32_t state) { restore_interrupts(state); if (core1_entry) { - multicore_lockout_end_blocking(); mp_thread_mutex_unlock(&atomic_mutex); } } diff --git a/ports/rp2/rp2_flash.c b/ports/rp2/rp2_flash.c index b1afe1cbd1e72..35c51641692f4 100644 --- a/ports/rp2/rp2_flash.c +++ b/ports/rp2/rp2_flash.c @@ -70,6 +70,22 @@ bi_decl(bi_block_device( BINARY_INFO_BLOCK_DEV_FLAG_WRITE | BINARY_INFO_BLOCK_DEV_FLAG_PT_UNKNOWN)); +// Flash erase and write must run with interrupts disabled and the other core suspended, +// because the XIP bit gets disabled. +static uint32_t begin_critical_flash_section(void) { + if (multicore_lockout_victim_is_initialized(1 - get_core_num())) { + multicore_lockout_start_blocking(); + } + return save_and_disable_interrupts(); +} + +static void end_critical_flash_section(uint32_t state) { + restore_interrupts(state); + if (multicore_lockout_victim_is_initialized(1 - get_core_num())) { + multicore_lockout_end_blocking(); + } +} + STATIC mp_obj_t rp2_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // Parse arguments enum { ARG_start, ARG_len }; @@ -135,19 +151,17 @@ STATIC mp_obj_t rp2_flash_writeblocks(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_READ); if (n_args == 3) { - // Flash erase/program must run in an atomic section because the XIP bit gets disabled. - mp_uint_t atomic_state = MICROPY_BEGIN_ATOMIC_SECTION(); + mp_uint_t atomic_state = begin_critical_flash_section(); flash_range_erase(self->flash_base + offset, bufinfo.len); - MICROPY_END_ATOMIC_SECTION(atomic_state); + end_critical_flash_section(atomic_state); mp_event_handle_nowait(); // TODO check return value } else { offset += mp_obj_get_int(args[3]); } - // Flash erase/program must run in an atomic section because the XIP bit gets disabled. - mp_uint_t atomic_state = MICROPY_BEGIN_ATOMIC_SECTION(); + mp_uint_t atomic_state = begin_critical_flash_section(); flash_range_program(self->flash_base + offset, bufinfo.buf, bufinfo.len); - MICROPY_END_ATOMIC_SECTION(atomic_state); + end_critical_flash_section(atomic_state); mp_event_handle_nowait(); // TODO check return value return mp_const_none; @@ -170,10 +184,9 @@ STATIC mp_obj_t rp2_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_ return MP_OBJ_NEW_SMALL_INT(BLOCK_SIZE_BYTES); case MP_BLOCKDEV_IOCTL_BLOCK_ERASE: { uint32_t offset = mp_obj_get_int(arg_in) * BLOCK_SIZE_BYTES; - // Flash erase/program must run in an atomic section because the XIP bit gets disabled. - mp_uint_t atomic_state = MICROPY_BEGIN_ATOMIC_SECTION(); + mp_uint_t atomic_state = begin_critical_flash_section(); flash_range_erase(self->flash_base + offset, BLOCK_SIZE_BYTES); - MICROPY_END_ATOMIC_SECTION(atomic_state); + end_critical_flash_section(atomic_state); // TODO check return value return MP_OBJ_NEW_SMALL_INT(0); } From 8438c8790c0ad11545371a07f0b0ce4c65c62101 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 2 Jan 2024 14:45:44 +1100 Subject: [PATCH 009/408] rp2/mutex_extra: Implement additional mutex functions. These allow entering/exiting a mutex and also disabling/restoring interrupts, in an atomic way. Signed-off-by: Damien George --- LICENSE | 2 ++ ports/rp2/CMakeLists.txt | 1 + ports/rp2/mutex_extra.c | 30 ++++++++++++++++++++++++++++++ ports/rp2/mutex_extra.h | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 ports/rp2/mutex_extra.c create mode 100644 ports/rp2/mutex_extra.h diff --git a/LICENSE b/LICENSE index 9bd457b42acea..b85f31808a483 100644 --- a/LICENSE +++ b/LICENSE @@ -69,6 +69,8 @@ used during the build process and is not part of the compiled source code. /FreeRTOS (GPL-2.0 with FreeRTOS exception) /esp32 /ppp_set_auth.* (Apache-2.0) + /rp2 + /mutex_extra.c (BSD-3-clause) /stm32 /usbd*.c (MCD-ST Liberty SW License Agreement V2) /stm32_it.* (MIT + BSD-3-clause) diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt index 559ae23f52e3c..281b0c3bc2846 100644 --- a/ports/rp2/CMakeLists.txt +++ b/ports/rp2/CMakeLists.txt @@ -129,6 +129,7 @@ set(MICROPY_SOURCE_PORT mphalport.c mpnetworkport.c mpthreadport.c + mutex_extra.c pendsv.c rp2_flash.c rp2_pio.c diff --git a/ports/rp2/mutex_extra.c b/ports/rp2/mutex_extra.c new file mode 100644 index 0000000000000..6df57e64ce50f --- /dev/null +++ b/ports/rp2/mutex_extra.c @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "mutex_extra.h" + +// These functions are taken from lib/pico-sdk/src/common/pico_sync/mutex.c and modified +// so that they atomically obtain the mutex and disable interrupts. + +uint32_t __time_critical_func(mutex_enter_blocking_and_disable_interrupts)(mutex_t * mtx) { + lock_owner_id_t caller = lock_get_caller_owner_id(); + do { + uint32_t save = spin_lock_blocking(mtx->core.spin_lock); + if (!lock_is_owner_id_valid(mtx->owner)) { + mtx->owner = caller; + spin_unlock_unsafe(mtx->core.spin_lock); + return save; + } + lock_internal_spin_unlock_with_wait(&mtx->core, save); + } while (true); +} + +void __time_critical_func(mutex_exit_and_restore_interrupts)(mutex_t * mtx, uint32_t save) { + spin_lock_unsafe_blocking(mtx->core.spin_lock); + assert(lock_is_owner_id_valid(mtx->owner)); + mtx->owner = LOCK_INVALID_OWNER_ID; + lock_internal_spin_unlock_with_notify(&mtx->core, save); +} diff --git a/ports/rp2/mutex_extra.h b/ports/rp2/mutex_extra.h new file mode 100644 index 0000000000000..be7cb96dcc53d --- /dev/null +++ b/ports/rp2/mutex_extra.h @@ -0,0 +1,34 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023 Damien P. George + * + * 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_RP2_MUTEX_EXTRA_H +#define MICROPY_INCLUDED_RP2_MUTEX_EXTRA_H + +#include "pico/mutex.h" + +uint32_t mutex_enter_blocking_and_disable_interrupts(mutex_t *mtx); +void mutex_exit_and_restore_interrupts(mutex_t *mtx, uint32_t save); + +#endif // MICROPY_INCLUDED_RP2_MUTEX_EXTRA_H From dc2a4e3cbd1755228ae3de2d15ec8f95721b9ac9 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 2 Jan 2024 01:04:03 +1100 Subject: [PATCH 010/408] rp2/mpthreadport: Fix race with IRQ when entering atomic section. Prior to this commit there is a potential deadlock in mp_thread_begin_atomic_section(), when obtaining the atomic_mutex, in the following situation: - main thread calls mp_thread_begin_atomic_section() (for whatever reason, doesn't matter) - the second core is running so the main thread grabs the mutex via the call mp_thread_mutex_lock(&atomic_mutex, 1), and this succeeds - before the main thread has a chance to run save_and_disable_interrupts() a USB IRQ comes in and the main thread jumps off to process this IRQ - that USB processing triggers a call to the dcd_event_handler() wrapper from commit bcbdee235719d459a4cd60d51021454fba54cd0f - that then calls mp_sched_schedule_node() - that then attempts to obtain the atomic section, calling mp_thread_begin_atomic_section() - that call then blocks trying to obtain atomic_mutex - core0 is now deadlocked on itself, because the main thread has the mutex but the IRQ handler (which preempted the main thread) is blocked waiting for the mutex, which will never be free The solution in this commit is to use mutex enter/exit functions that also atomically disable/restore interrupts. Fixes issues #12980 and #13288. Signed-off-by: Damien George --- ports/rp2/mpthreadport.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/ports/rp2/mpthreadport.c b/ports/rp2/mpthreadport.c index 7bffabb3355eb..fd868329c38d5 100644 --- a/ports/rp2/mpthreadport.c +++ b/ports/rp2/mpthreadport.c @@ -30,6 +30,7 @@ #include "py/mpthread.h" #include "pico/stdlib.h" #include "pico/multicore.h" +#include "mutex_extra.h" #if MICROPY_PY_THREAD @@ -45,23 +46,23 @@ STATIC uint32_t *core1_stack = NULL; STATIC size_t core1_stack_num_words = 0; // Thread mutex. -STATIC mp_thread_mutex_t atomic_mutex; +STATIC mutex_t atomic_mutex; uint32_t mp_thread_begin_atomic_section(void) { if (core1_entry) { // When both cores are executing, we also need to provide // full mutual exclusion. - mp_thread_mutex_lock(&atomic_mutex, 1); + return mutex_enter_blocking_and_disable_interrupts(&atomic_mutex); + } else { + return save_and_disable_interrupts(); } - - return save_and_disable_interrupts(); } void mp_thread_end_atomic_section(uint32_t state) { - restore_interrupts(state); - - if (core1_entry) { - mp_thread_mutex_unlock(&atomic_mutex); + if (atomic_mutex.owner != LOCK_INVALID_OWNER_ID) { + mutex_exit_and_restore_interrupts(&atomic_mutex, state); + } else { + restore_interrupts(state); } } @@ -69,7 +70,7 @@ void mp_thread_end_atomic_section(uint32_t state) { void mp_thread_init(void) { assert(get_core_num() == 0); - mp_thread_mutex_init(&atomic_mutex); + mutex_init(&atomic_mutex); // Allow MICROPY_BEGIN_ATOMIC_SECTION to be invoked from core1. multicore_lockout_victim_init(); From 231fc20ce0cf776d64d2a0f1ad0ada99cc178552 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 4 Jan 2024 14:52:07 +1100 Subject: [PATCH 011/408] tests/run-tests.py: Remove machine_mem.py test from skip list. This test was removed long ago in eb0e3bab1ed5aa09e491641f427a5d637fe688bd. Signed-off-by: Damien George --- tests/run-tests.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/run-tests.py b/tests/run-tests.py index 2dc387946ca7a..e5d7123036cbe 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -573,7 +573,6 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): if args.target != "unix": skip_tests.add("basics/exception_chain.py") # warning is not printed skip_tests.add("micropython/meminfo.py") # output is very different to PC output - skip_tests.add("extmod/machine_mem.py") # raw memory access not supported if args.target == "wipy": skip_tests.add("misc/print_exception.py") # requires error reporting full From 2265d70add3ecfaf2ffbfb8393ab29a887d8d7fd Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 5 Jan 2024 09:53:05 +1100 Subject: [PATCH 012/408] tests/thread: Adjust thread tests so most are able to run on rp2 port. The aim of this commit is to make it so that the existing thread tests can be used to test the _thread module on the rp2 port. The rp2 port only allows up to one thread to be created at a time, and does not have the GIL enabled. The following changes have been made: - run-tests.py skips mutation tests on rp2, because there's no GIL. - run-tests.py skips other tests on rp2 that require more than one thread. - The tests stop trying to start a new thread after there is an OSError, which indicates that the system cannot create more threads. - Some of these tests also now run the test function on the main thread, not just the spawned threads. - In some tests the output printing is adjusted so it's the same regardless of how many threads were spawned. - Some time.sleep(1) are replaced with time.sleep(0) to make the tests run a little faster (finish sooner when the work is done). For the most part the tests are unchanged for existing platforms like esp32 and unix. Signed-off-by: Damien George --- tests/run-tests.py | 14 ++++++++++---- tests/thread/stress_schedule.py | 13 +++++++++++-- tests/thread/thread_gc1.py | 25 +++++++++++++++++++------ tests/thread/thread_ident1.py | 6 +++++- tests/thread/thread_lock4.py | 8 ++++++-- tests/thread/thread_qstr1.py | 18 ++++++++++++++---- tests/thread/thread_shared1.py | 16 +++++++++++++--- tests/thread/thread_sleep1.py | 19 +++++++++++++++---- 8 files changed, 93 insertions(+), 26 deletions(-) diff --git a/tests/run-tests.py b/tests/run-tests.py index e5d7123036cbe..bbc98cad96011 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -562,13 +562,19 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): skip_tests.add("cmdline/repl_sys_ps1_ps2.py") skip_tests.add("extmod/ssl_poll.py") - # Some tests shouldn't be run on a PC - if args.target == "unix": - # unix build does not have the GIL so can't run thread mutation tests + # Skip thread mutation tests on targets that don't have the GIL. + if args.target in ("rp2", "unix"): for t in tests: if t.startswith("thread/mutate_"): skip_tests.add(t) + # Skip thread tests that require many threads on targets that don't support multiple threads. + if args.target == "rp2": + skip_tests.add("thread/stress_heap.py") + skip_tests.add("thread/thread_lock2.py") + skip_tests.add("thread/thread_lock3.py") + skip_tests.add("thread/thread_shared2.py") + # Some tests shouldn't be run on pyboard if args.target != "unix": skip_tests.add("basics/exception_chain.py") # warning is not printed @@ -987,7 +993,7 @@ def main(): elif args.target in ("renesas-ra"): test_dirs += ("float", "inlineasm", "renesas-ra") elif args.target == "rp2": - test_dirs += ("float", "stress", "inlineasm") + test_dirs += ("float", "stress", "inlineasm", "thread") elif args.target in ("esp8266", "esp32", "minimal", "nrf"): test_dirs += ("float",) elif args.target == "wipy": diff --git a/tests/thread/stress_schedule.py b/tests/thread/stress_schedule.py index 40191e6620986..a5d7dc824edea 100644 --- a/tests/thread/stress_schedule.py +++ b/tests/thread/stress_schedule.py @@ -19,6 +19,7 @@ n = 0 # How many times the task successfully ran. t = None # Start time of test, assigned here to preallocate entry in globals dict. +thread_run = True # If the thread should continue running. def task(x): @@ -27,7 +28,7 @@ def task(x): def thread(): - while True: + while thread_run: try: micropython.schedule(task, None) except RuntimeError: @@ -36,13 +37,21 @@ def thread(): for i in range(8): - _thread.start_new_thread(thread, ()) + try: + _thread.start_new_thread(thread, ()) + except OSError: + # System cannot create a new thead, so stop trying to create them. + break # Wait up to 10 seconds for 10000 tasks to be scheduled. t = time.ticks_ms() while n < _NUM_TASKS and time.ticks_diff(time.ticks_ms(), t) < _TIMEOUT_MS: pass +# Stop all threads. +thread_run = False +time.sleep_ms(20) + if n < _NUM_TASKS: # Not all the tasks were scheduled, likely the scheduler stopped working. print(n) diff --git a/tests/thread/thread_gc1.py b/tests/thread/thread_gc1.py index dd1e64d89444d..b36ea9d4c8421 100644 --- a/tests/thread/thread_gc1.py +++ b/tests/thread/thread_gc1.py @@ -16,21 +16,34 @@ def thread_entry(n): data[i] = data[i] gc.collect() - # print whether the data remains intact and indicate we are finished + # check whether the data remains intact and indicate we are finished with lock: - print(list(data) == list(range(256))) - global n_finished + global n_correct, n_finished + n_correct += list(data) == list(range(256)) n_finished += 1 lock = _thread.allocate_lock() -n_thread = 4 +n_thread = 0 +n_thread_max = 4 +n_correct = 0 n_finished = 0 # spawn threads -for i in range(n_thread): - _thread.start_new_thread(thread_entry, (10,)) +for _ in range(n_thread_max): + try: + _thread.start_new_thread(thread_entry, (10,)) + n_thread += 1 + except OSError: + # System cannot create a new thead, so stop trying to create them. + break + +# also run the function on this main thread +thread_entry(10) +n_thread += 1 # busy wait for threads to finish while n_finished < n_thread: pass + +print(n_correct == n_finished) diff --git a/tests/thread/thread_ident1.py b/tests/thread/thread_ident1.py index 8e106cd317f4e..2a3732eff53dc 100644 --- a/tests/thread/thread_ident1.py +++ b/tests/thread/thread_ident1.py @@ -5,7 +5,12 @@ import _thread +# Initialise variables (also preallocate their spot in the globals dict so the +# globals dict is not resized while threads are running). tid = None +tid_main = None +new_tid = None +finished = False def thread_entry(): @@ -19,7 +24,6 @@ def thread_entry(): tid_main = _thread.get_ident() print("main", type(tid_main) == int, tid_main != 0) -finished = False new_tid = _thread.start_new_thread(thread_entry, ()) while not finished: diff --git a/tests/thread/thread_lock4.py b/tests/thread/thread_lock4.py index 97c3dc538007d..b424ee3d02f98 100644 --- a/tests/thread/thread_lock4.py +++ b/tests/thread/thread_lock4.py @@ -36,14 +36,18 @@ def thread_entry(): # spawn threads to do the jobs for i in range(4): - _thread.start_new_thread(thread_entry, ()) + try: + _thread.start_new_thread(thread_entry, ()) + except OSError: + # System cannot create a new thead, so stop trying to create them. + break # wait for the jobs to complete while True: with jobs_lock: if len(output) == n_jobs: break - time.sleep(1) + time.sleep(0) # sort and print the results output.sort(key=lambda x: x[0]) diff --git a/tests/thread/thread_qstr1.py b/tests/thread/thread_qstr1.py index f184d2a58e1d4..96f12c5d8c93f 100644 --- a/tests/thread/thread_qstr1.py +++ b/tests/thread/thread_qstr1.py @@ -24,16 +24,26 @@ def th(base, n): lock = _thread.allocate_lock() -n_thread = 4 +n_thread = 0 +n_thread_max = 4 n_finished = 0 n_qstr_per_thread = 100 # make 1000 for a more stressful test (uses more heap) # spawn threads -for i in range(n_thread): - _thread.start_new_thread(th, (i * n_qstr_per_thread, n_qstr_per_thread)) +for _ in range(n_thread_max): + try: + _thread.start_new_thread(th, (n_thread * n_qstr_per_thread, n_qstr_per_thread)) + n_thread += 1 + except OSError: + # System cannot create a new thead, so stop trying to create them. + break + +# also run the function on this main thread +th(n_thread * n_qstr_per_thread, n_qstr_per_thread) +n_thread += 1 # wait for threads to finish while n_finished < n_thread: - time.sleep(1) + time.sleep(0) print("pass") diff --git a/tests/thread/thread_shared1.py b/tests/thread/thread_shared1.py index 582b01fc34356..251e26fae6ca3 100644 --- a/tests/thread/thread_shared1.py +++ b/tests/thread/thread_shared1.py @@ -18,15 +18,25 @@ def thread_entry(n, tup): lock = _thread.allocate_lock() -n_thread = 2 +n_thread = 0 +n_thread_max = 2 n_finished = 0 # the shared data structure tup = (1, 2, 3, 4) # spawn threads -for i in range(n_thread): - _thread.start_new_thread(thread_entry, (100, tup)) +for _ in range(n_thread_max): + try: + _thread.start_new_thread(thread_entry, (100, tup)) + n_thread += 1 + except OSError: + # System cannot create a new thead, so stop trying to create them. + break + +# also run the function on this main thread +thread_entry(100, tup) +n_thread += 1 # busy wait for threads to finish while n_finished < n_thread: diff --git a/tests/thread/thread_sleep1.py b/tests/thread/thread_sleep1.py index add9b02f1573b..36f775d1f6eff 100644 --- a/tests/thread/thread_sleep1.py +++ b/tests/thread/thread_sleep1.py @@ -12,7 +12,8 @@ import _thread lock = _thread.allocate_lock() -n_thread = 4 +n_thread = 0 +n_thread_max = 4 n_finished = 0 @@ -24,10 +25,20 @@ def thread_entry(t): n_finished += 1 -for i in range(n_thread): - _thread.start_new_thread(thread_entry, (10 * i,)) +# spawn threads +for _ in range(n_thread_max): + try: + _thread.start_new_thread(thread_entry, (10 * n_thread,)) + n_thread += 1 + except OSError: + # System cannot create a new thead, so stop trying to create them. + break + +# also run the function on this main thread +thread_entry(10 * n_thread) +n_thread += 1 # wait for threads to finish while n_finished < n_thread: sleep_ms(100) -print("done", n_thread) +print("done") From a003ac2f73b8f54643e42138ad10249e2b861b63 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 5 Jan 2024 10:35:34 +1100 Subject: [PATCH 013/408] tests/thread: Add a test for accuracy of sleep within a thread. The existing thread_sleep1.py test only tests execution, not accuracy, of time.sleep. Also the existing test only tests sleep(0) on targets like rp2 that can only create a single thread. The new test in this commit checks for timing accuracy on the main thread and one other thread when they run at the same time. Signed-off-by: Damien George --- tests/thread/thread_sleep2.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/thread/thread_sleep2.py diff --git a/tests/thread/thread_sleep2.py b/tests/thread/thread_sleep2.py new file mode 100644 index 0000000000000..2dec24cabec93 --- /dev/null +++ b/tests/thread/thread_sleep2.py @@ -0,0 +1,31 @@ +# Test accuracy of sleep within a thread. + +import time +import _thread + + +def sleep(t, valid_range): + t0 = time.time_ns() + time.sleep(t) + dt_ms = (time.time_ns() - t0) // 1_000_000 + if dt_ms in valid_range: + print("dt in range", t) + else: + print("dt not in range:", dt_ms) + + +def thread_entry(): + lock.acquire() + print("thread start") + sleep(0.2, range(180, 400)) + print("thread end") + + +lock = _thread.allocate_lock() +lock.acquire() +_thread.start_new_thread(thread_entry, ()) + +print("main start") +lock.release() +sleep(0.5, range(480, 800)) +print("main end") From f0392b8d3d7e37a74f448c8fe4789f0f6bc76541 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 3 Jan 2024 16:26:52 +1100 Subject: [PATCH 014/408] tests/run-multitests.py: Change to dir of test script when running it. This matches the behaviour of run-tests.py, which sets cwd to the directory containing the test script, which helps to isolate the filesystem. It means that the SSL tests no longer need to know the name of their containing directory to find the certificate files, and helps to run these tests on bare-metal. Signed-off-by: Damien George --- tests/multi_net/asyncio_tls_server_client.py | 4 ++-- ...io_tls_server_client_cert_required_error.py | 4 ++-- .../asyncio_tls_server_client_readline.py | 4 ++-- .../asyncio_tls_server_client_verify_error.py | 4 ++-- tests/multi_net/ssl_cert_rsa.py | 4 ++-- .../sslcontext_check_hostname_error.py | 4 ++-- tests/multi_net/sslcontext_getpeercert.py | 4 ++-- tests/multi_net/sslcontext_server_client.py | 4 ++-- .../sslcontext_server_client_ciphers.py | 4 ++-- .../sslcontext_server_client_files.py | 4 ++-- tests/multi_net/sslcontext_verify_error.py | 4 ++-- .../multi_net/sslcontext_verify_time_error.py | 4 ++-- tests/run-multitests.py | 18 ++++++++++++------ 13 files changed, 36 insertions(+), 30 deletions(-) diff --git a/tests/multi_net/asyncio_tls_server_client.py b/tests/multi_net/asyncio_tls_server_client.py index 996cdb3e0def9..59e13ec45d1dd 100644 --- a/tests/multi_net/asyncio_tls_server_client.py +++ b/tests/multi_net/asyncio_tls_server_client.py @@ -11,8 +11,8 @@ PORT = 8000 # These are test certificates. See tests/README.md for details. -cert = cafile = "multi_net/rsa_cert.der" -key = "multi_net/rsa_key.der" +cert = cafile = "rsa_cert.der" +key = "rsa_key.der" try: os.stat(cafile) diff --git a/tests/multi_net/asyncio_tls_server_client_cert_required_error.py b/tests/multi_net/asyncio_tls_server_client_cert_required_error.py index bd4d7b82ea75b..8607e4ff10a9d 100644 --- a/tests/multi_net/asyncio_tls_server_client_cert_required_error.py +++ b/tests/multi_net/asyncio_tls_server_client_cert_required_error.py @@ -11,8 +11,8 @@ PORT = 8000 # These are test certificates. See tests/README.md for details. -cert = cafile = "multi_net/rsa_cert.der" -key = "multi_net/rsa_key.der" +cert = cafile = "rsa_cert.der" +key = "rsa_key.der" try: os.stat(cafile) diff --git a/tests/multi_net/asyncio_tls_server_client_readline.py b/tests/multi_net/asyncio_tls_server_client_readline.py index 28add38f5d804..fd8685f5af878 100644 --- a/tests/multi_net/asyncio_tls_server_client_readline.py +++ b/tests/multi_net/asyncio_tls_server_client_readline.py @@ -11,8 +11,8 @@ PORT = 8000 # These are test certificates. See tests/README.md for details. -cert = cafile = "multi_net/rsa_cert.der" -key = "multi_net/rsa_key.der" +cert = cafile = "rsa_cert.der" +key = "rsa_key.der" try: os.stat(cafile) diff --git a/tests/multi_net/asyncio_tls_server_client_verify_error.py b/tests/multi_net/asyncio_tls_server_client_verify_error.py index 46a476addfbf6..c600dcc2c8b6f 100644 --- a/tests/multi_net/asyncio_tls_server_client_verify_error.py +++ b/tests/multi_net/asyncio_tls_server_client_verify_error.py @@ -11,8 +11,8 @@ PORT = 8000 # These are test certificates. See tests/README.md for details. -cert = cafile = "multi_net/rsa_cert.der" -key = "multi_net/rsa_key.der" +cert = cafile = "rsa_cert.der" +key = "rsa_key.der" try: os.stat(cafile) diff --git a/tests/multi_net/ssl_cert_rsa.py b/tests/multi_net/ssl_cert_rsa.py index 71c9a34797606..d148c8ebcfea8 100644 --- a/tests/multi_net/ssl_cert_rsa.py +++ b/tests/multi_net/ssl_cert_rsa.py @@ -10,8 +10,8 @@ PORT = 8000 # These are test certificates. See tests/README.md for details. -certfile = "multi_net/rsa_cert.der" -keyfile = "multi_net/rsa_key.der" +certfile = "rsa_cert.der" +keyfile = "rsa_key.der" try: os.stat(certfile) diff --git a/tests/multi_net/sslcontext_check_hostname_error.py b/tests/multi_net/sslcontext_check_hostname_error.py index 94bd472767df3..ac39211b092f0 100644 --- a/tests/multi_net/sslcontext_check_hostname_error.py +++ b/tests/multi_net/sslcontext_check_hostname_error.py @@ -11,8 +11,8 @@ PORT = 8000 # These are test certificates. See tests/README.md for details. -cert = cafile = "multi_net/rsa_cert.der" -key = "multi_net/rsa_key.der" +cert = cafile = "rsa_cert.der" +key = "rsa_key.der" try: os.stat(cafile) diff --git a/tests/multi_net/sslcontext_getpeercert.py b/tests/multi_net/sslcontext_getpeercert.py index c75a37952ee4b..8748c1f78e8fc 100644 --- a/tests/multi_net/sslcontext_getpeercert.py +++ b/tests/multi_net/sslcontext_getpeercert.py @@ -12,8 +12,8 @@ PORT = 8000 # These are test certificates. See tests/README.md for details. -cert = cafile = "multi_net/rsa_cert.der" -key = "multi_net/rsa_key.der" +cert = cafile = "rsa_cert.der" +key = "rsa_key.der" try: os.stat(cafile) diff --git a/tests/multi_net/sslcontext_server_client.py b/tests/multi_net/sslcontext_server_client.py index 4d2ac06c58d1e..c263ae31bb4e8 100644 --- a/tests/multi_net/sslcontext_server_client.py +++ b/tests/multi_net/sslcontext_server_client.py @@ -11,8 +11,8 @@ PORT = 8000 # These are test certificates. See tests/README.md for details. -certfile = "multi_net/rsa_cert.der" -keyfile = "multi_net/rsa_key.der" +certfile = "rsa_cert.der" +keyfile = "rsa_key.der" try: os.stat(certfile) diff --git a/tests/multi_net/sslcontext_server_client_ciphers.py b/tests/multi_net/sslcontext_server_client_ciphers.py index e2de4e6ad4f0f..be7c332b4c747 100644 --- a/tests/multi_net/sslcontext_server_client_ciphers.py +++ b/tests/multi_net/sslcontext_server_client_ciphers.py @@ -11,8 +11,8 @@ PORT = 8000 # These are test certificates. See tests/README.md for details. -cert = cafile = "multi_net/rsa_cert.der" -key = "multi_net/rsa_key.der" +cert = cafile = "rsa_cert.der" +key = "rsa_key.der" try: os.stat(cafile) diff --git a/tests/multi_net/sslcontext_server_client_files.py b/tests/multi_net/sslcontext_server_client_files.py index 2c8af21d23a30..e1ea1b3aa8b32 100644 --- a/tests/multi_net/sslcontext_server_client_files.py +++ b/tests/multi_net/sslcontext_server_client_files.py @@ -11,8 +11,8 @@ PORT = 8000 # These are test certificates. See tests/README.md for details. -cert = cafile = "multi_net/rsa_cert.der" -key = "multi_net/rsa_key.der" +cert = cafile = "rsa_cert.der" +key = "rsa_key.der" try: os.stat(cafile) diff --git a/tests/multi_net/sslcontext_verify_error.py b/tests/multi_net/sslcontext_verify_error.py index 4feb4ce983b3d..4a7a6cfcc14c2 100644 --- a/tests/multi_net/sslcontext_verify_error.py +++ b/tests/multi_net/sslcontext_verify_error.py @@ -11,8 +11,8 @@ PORT = 8000 # These are test certificates. See tests/README.md for details. -cert = cafile = "multi_net/rsa_cert.der" -key = "multi_net/rsa_key.der" +cert = cafile = "rsa_cert.der" +key = "rsa_key.der" try: os.stat(cafile) diff --git a/tests/multi_net/sslcontext_verify_time_error.py b/tests/multi_net/sslcontext_verify_time_error.py index 36711acfc8f67..e5dc496451649 100644 --- a/tests/multi_net/sslcontext_verify_time_error.py +++ b/tests/multi_net/sslcontext_verify_time_error.py @@ -11,8 +11,8 @@ PORT = 8000 # These are test certificates. See tests/README.md for details. -cert = cafile = "multi_net/expired_cert.der" -key = "multi_net/rsa_key.der" +cert = cafile = "expired_cert.der" +key = "rsa_key.der" try: os.stat(cafile) diff --git a/tests/run-multitests.py b/tests/run-multitests.py index 5ae8b8ea48014..93a6d3844d235 100755 --- a/tests/run-multitests.py +++ b/tests/run-multitests.py @@ -27,13 +27,15 @@ if os.name == "nt": CPYTHON3 = os.getenv("MICROPY_CPYTHON3", "python3.exe") - MICROPYTHON = os.getenv( - "MICROPY_MICROPYTHON", test_dir + "/../ports/windows/build-standard/micropython.exe" + MICROPYTHON = os.path.abspath( + os.getenv( + "MICROPY_MICROPYTHON", test_dir + "/../ports/windows/build-standard/micropython.exe" + ) ) else: CPYTHON3 = os.getenv("MICROPY_CPYTHON3", "python3") - MICROPYTHON = os.getenv( - "MICROPY_MICROPYTHON", test_dir + "/../ports/unix/build-standard/micropython" + MICROPYTHON = os.path.abspath( + os.getenv("MICROPY_MICROPYTHON", test_dir + "/../ports/unix/build-standard/micropython") ) # For diff'ing test output @@ -155,6 +157,7 @@ def start_file(self, filename, prepend="", append=""): class PyInstanceSubProcess(PyInstance): def __init__(self, argv, env=None): self.argv = argv + self.cwd = None self.env = {n: v for n, v in (i.split("=") for i in env)} if env else None self.popen = None self.finished = True @@ -163,8 +166,9 @@ def __str__(self): return self.argv[0].rsplit("/")[-1] def prepare_script_from_file(self, filename, prepend, append): - # Make tests run in an isolated environment (i.e. `import io` would - # otherwise get the `tests/io` directory). + # Make tests run in the directory of the test file, and in an isolated environment + # (i.e. `import io` would otherwise get the `tests/io` directory). + self.cwd = os.path.dirname(filename) remove_cwd_from_sys_path = b"import sys\nsys.path.remove('')\n\n" return remove_cwd_from_sys_path + super().prepare_script_from_file( filename, prepend, append @@ -179,6 +183,7 @@ def run_script(self, script): stdout=subprocess.PIPE, stderr=subprocess.STDOUT, input=script, + cwd=self.cwd, env=self.env, ) output = p.stdout @@ -192,6 +197,7 @@ def start_script(self, script): stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + cwd=self.cwd, env=self.env, ) self.finished = False From 0c81ffd31a70a320b5038f6f81a24a3b68120241 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 3 Jan 2024 16:34:58 +1100 Subject: [PATCH 015/408] tests/multi_net: Generate smaller certs with 2048-bit RSA. Otherwise running the tests can take a long time when the server is a slow target (RP2040 takes 23 seconds for a handshake when using 4096-bit RSA). Also add instructions on how to generate elliptic curve key/certs. Signed-off-by: Damien George --- tests/README.md | 10 ++++++++-- tests/multi_net/rsa_cert.der | Bin 1421 -> 867 bytes tests/multi_net/rsa_key.der | Bin 2347 -> 1217 bytes 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/README.md b/tests/README.md index 083269d6e822f..47fcacf409743 100644 --- a/tests/README.md +++ b/tests/README.md @@ -181,9 +181,9 @@ SSL/TLS tests in `multi_net` and `net_inet` use a self-signed key/cert pair that is randomly generated and to be used for testing/demonstration only. You should always generate your own key/cert. -To generate a new self-signed key/cert pair with openssl do: +To generate a new self-signed RSA key/cert pair with openssl do: ``` -$ openssl req -x509 -newkey rsa:4096 -keyout rsa_key.pem -out rsa_cert.pem -days 365 -nodes +$ openssl req -x509 -newkey rsa:2048 -keyout rsa_key.pem -out rsa_cert.pem -days 365 -nodes -subj '/CN=micropython.local/O=MicroPython/C=AU' ``` In this case CN is: micropython.local @@ -192,3 +192,9 @@ Convert them to DER format: $ openssl rsa -in rsa_key.pem -out rsa_key.der -outform DER $ openssl x509 -in rsa_cert.pem -out rsa_cert.der -outform DER ``` + +To test elliptic curve key/cert pairs, create a key then a certificate using: +``` +$ openssl ecparam -name prime256v1 -genkey -noout -out ec_key.der -outform DER +$ openssl req -new -x509 -key ec_key.der -out ec_cert.der -outform DER -days 365 -nodes -subj '/CN=micropython.local/O=MicroPython/C=AU' +``` diff --git a/tests/multi_net/rsa_cert.der b/tests/multi_net/rsa_cert.der index 24ed957eb2c5a21ec4e351abce0c802645462b02..8fae71d4baa8cd3e2be3f3d2bedb62ebb33e371c 100644 GIT binary patch literal 867 zcmXqLVvaXxVsc-=%*4pVBoe@|NlMGet2}@2#kEB;9S?HiSmzq>vTGz;cG%2Am*K zHen{mPy;z}ULz9&Ljz+2Q)6R8lPDn96v#D#aw)f<#_zlU&U8&swe%nkG{sq}SoG|LsT9g{#{8 zW=@nSvD+?GvVu!}iovWW=VN9D{SnJ}$QcvTc7FGA9(+|e-L7_V?T^DD(LvkZ zd`a7|@8qUv>9n{>=eC^LYtNzXp%ir3t@PeGM~!Tm>W8~eR6Lcgnz@SU3Zs?LQa;v* zpJwU@ugh>Ra+I@I~ zYHrnMo#u)6YPcNk7AJ+Y>+ZF^k;mM|@8VT8Rbc57j~#x7a~DicE9m0`?xiYyme{CboTN+dt>tj^5PtSm*4FMhg)o z19_0NGK++PSOazi{2&FwjEw(TSPhtg6mqZw(+V)y85vx>R%pDOyRS>O?zZhcA2v3* z&F9_x1M-*MZ+mj%b(*;9!{tIx%Z_qBd0$mG%X-4}!>mrFC#+^?o{CcS6a9IcrA1mW z=+%xSokBZCD(4)!VC9o+fi5j zw?Xo$%(Mvw>^6Uw?0tK~``()!KbGz9Sfx5$s_MrzY3>K9e;*Xduzox*9{NRl;byCn z5B1M%>vcn}^c-g`cx0ip$MMhojD{_YoGUql0~!*p1ubBnnD2Eoa}x9ai5U$~?)@-! wth)C8UfZti-6esW@tft)z6k+Gqnp{0S5k)@G&6p(8Hn3tJ`Fy)Mj<@xN%K`$BBmnODsnEgSN~F28;<=R=r4z_%agu73aW(Uv1y zqkPsh_uapq9sayFW9g>87YomAO1M$Cn87f0=8?Pe6PkWZOxZf&e%sWwS0#++ryJZm z@*!I8o2iGuWNH`}Zk~KH z*C$^4#H0JCYFBsW>96p87kp`V?p}eg>HG^Dl|^5?n>%Uq>B$eaCSNMq&wjTuf$t0R zPFbH9B97e}=hto8e#1d7<=d6dlbY`vv3&Z+`0204{8)vGoA30eZM!FbMZq`T7r(T|YZ9R*lT;n0W>?Ne#jry@#TCI9X_-oCm(!O=x`q0}Vp_3`_5zI)|A-}AJ5>g+HHwo77j_g$!Q4(*xH zGv#5*#D7vsXD99WY$MoWYJF!$Oh=J^>XQbQiTp(drUx!tSIpGV%-=Zq+%Z#*78PrT z{eeze7v^tg)V_J@N?``GllFs)g7?Wr zAkaV-m~v(LSj1RFYAv;zR=atc{jDugN}CdzrRn;&*FYX5t;`}}Al86g0Y6BAFeBrC z7FGjhAcdUlfVm2o>=+r=IUEpu{OVrs>JxsC!`IBs^sBix=gGoNsU1wk7n8yTXD!#? zw5q#BPGjc2#V;}$-9GtFvoddrnY_Ow#QjdzhS~9&?&-3pgf~8ykFj%Rlr1@XtmCba z=w`-*!gWQa*Xt{7tG4V^zIuHo>-Qhq7WOzjN&9z9zh&FgskN^jO!HmcVz%MI zSw9X&wZvV&r*{1QTafWLhhuf6fRy+BN3v7T@;z8}{ce}tMGbZtzC#z1@8teUmY5f~ oKXy{&^Rnwn_9aopUmohkXixC8eR#|{+jyP`L#Ldb>0yCz0E4|}w*UYD diff --git a/tests/multi_net/rsa_key.der b/tests/multi_net/rsa_key.der index 5a4666402a6a5e7b34bded6c3dd5b59bd49e4d18..c2cfb76d207e7afb33394bbcaf5525d7382dc2b6 100644 GIT binary patch literal 1217 zcmV;y1U~yPf&{$+0RS)!1_>&LNQUrr!ay9qXGc{0)hbn0LZlpRD`B= z9t9&SjV$Giv?z(F5>j2*FZYr}H!saOt`e3UbP_IzNWbmzHKD49j+v1dbUwEdbf^j^ zlrWm)&s>>O{1#~830zcx*6GlfNp!&A^&rcKCef|sUuZ>>e$^!hXNN<%`3xC2e~1EQ68WdaUJHGH6KNdf}_009Dm0RSW} zE{uuQ59_yeU6yxmaqG|;@P|zO$;j){93}3e3Ng(4?rA0!=}%+%+OL*V4Op>iEQDAA z+uBBMa|DdLj^L zh2>yytH@+-8JoegV^T#X1+$KCb{_(PfdJW>=*RfG!M;vGYUSVov*B)gB2e0lZJ`Ot z{m-JTH`87cEMkJFkmPGH8{9`dhN8^bciA$-J=V6fn#a~2FJRRUe}rMH$}fUo9PtXs zP@5c3YA(E?dApGqU>9Vw|Ii<8LgQ%}$MtF_7}?!8LBAO-^`8Z&-xqhL{)rW4K$il6 zfHW#`SlXmXKSpq(1GJX?`k09(o_0b?5Ih;PkL=P9OV3+=Kqp=SX|q8D{;-r)F9^ zopAt`tYM8J_NVcODA_lcw&Gq79%ojH!vcYT3@6|#6O{pctq5>^NartdKW4Xs2Et=` zWPh0>88$zp8Wb`b8s@|osShE~L|i?ZuYf|E6!)=&%1lFFNN1Ps06N8gqwCa? z4uvEmmJn0!Dsg7Wc#(kwt%h`(-nNd;|5pZCibaOl+{eJYc^;i2_5ka!cIl`*W-6f{ z0)c@5#<6P*4-tn^u^N#BUGa_+Bhj_x8=HnWhab^MWBD<g_) zfWDZ7Aax0^@U*8#QrcEUcV8%n1x#c*n>Jm literal 2347 zcmV+`3Dov5f(a)A0RRGm0s#Qt?l*W2yrg~)K}(=B>*kWuyf;b?vGgTYzb0ze1R#MH z?hT7C(6tx`O3;`bPth_h=oXgD>Vt@cuy0n=>*Sp9RuEA3_|Db$^zl6iYbbY`mPfn# z=EL)?Xr;1_=%LQCVAy`605N5m#ND4@g7}eSwUFP2m95nnGoNQL-o)@*9`-dzGMfrW zf-p6*H#hSzJ65VC9oXFP!VYX5DHC+Tg|20LG@KxE9DD(xvy;hfOkXR=;@`@BtBGze zs7>xu(z|WF5LTBDp@Ab6=m_qa3DcMEuk8cE3aR^ zx$f#upGnIfWt&zQ2GSOtzR-L_Rg92~l;LEN{u(09lDP9c5rj26+?ZU5axZ1%fFzL* zaxgW((>r*XC@F8Tlg`F92!td%0KZW}D$t*|0V~!xLk?6Vy$jI-0|5X50)hemAuly*WO>Yjn+UE{#HUg}U8$%>-5@iXli1A>4Du~l zlHXoC6C=vkG`qCxcOJ9fBrMfWnLdA= zLW`TzyFD_fsqzzFi((uxMvc+xSA!S~Lg=AL&A78$$UX-e9Z^JpL&8>#2&5Zp^+Gf8 zK~ilyc`n{jCz_kcKX^Ey1T4W4CB+sDK9$2aAnO=mWw_rk%^-lf)3>Q2v-5W0Am=k2 z6VTpK(iI?ob{!n{Kv}M*ng7eizeWqWsbyB~b6g`0S^mJXC3B0(1#**2Cvx~^=nzEy z9g5!|zZn5|`_2hgX&`q$U&#iV{E6^ZW7tff>kr;rSgX%9f?YyiG>tC8&!UR)d>XJw zG&4{b(2y&1E2#|r+k6zTx~Ue>eq4Pf)Fv@YWo;ArAc*u<0B_X0ldgpEE-d&rb2V-x zi$*wq^|%|Onu3H0&}qM<`D;Bem+{umwc^W=#uJv-acEC65b93Xh> za(+uPAe=MR#Nt=8W{$4I)?N{y;3RtL>K;4ghtX216nlfw^9=sW7~Qs(2l`|nOuJE= z7y#U}O)ca7NEE>Wf&l>l^l9pp`hF%31L6wnEy|keTNMj}eyFH2$_&`6V4-8s+ZNKQ zH?u(MS9>R3G3sdjrk8HAtkTS!j}&eg4ovZVj0=g6xNd>B2b7I%tXGR9tssavXqIGl zn|`1xeEVW^TZweHKEGPna@WH<4RK-^HK8obSl_- zuQ=n_(MfS`kRycdCc1plL-3VIb4R_L-fH0W{7svwl+Y4OYbGHpVU?Ty6(vgZ(sO7N zqgIp#l`I}2aU>wI3nG1#{S~vv#$)pVp0yc6LN#tDqf(pMjUeaXX5LUCn-7-NkN-qf z)JP$G*!Al3JP$B&0)hbn0O^01L#>?8-%Gk0FWD1~9ynrMFAjCPD(?J1MKjt0+Hv)8 zya%0earfe?tx)yHcs zJ72hs$F8E4bpi35X##aSr6l*#fqy^L&^995F0%0G;1Sa~=hiTP2jG!?l`-SLS~o;)xH7RapJffj}dm zvKq#hsImc&og;zodK~KqJ@kTyWqw|_Z48Or;?e-<%S@hNUJe2b>NmZyy|ta9Vai|u zLlYR%;UqzlejQ6qYkIenQopm~J>HD=?G_V1KMhH#AxI%WSeds!e>v+KbqnA#hlhFJ zeo~p;`A~0n*-h}gX>CWr2oZ+O-^7A7GxCYG$7d7jX{1<=rXPq{ifo)qKsR+`IG--& z7ujV(>I`=PERJuZ>@Ena+&N(Ohp0>BbCWqHwtD5omPyn{p7QZ(P6!Ill+pcW8H%a3 zd;Na4A9uPAwP3MYfdYa70RXRrEzi;etr@_jX-6g57dLhDAgaY@dy6{=vx)(vB`)o_ zwQkqe{$H(61G6P3i@fuAoaz?;#1@SCR7e-Z92ErjG(#cO3wat=06*Mteh?OZE)0Iw z?S{iYRCIxyg!5k#PWDcOCB%y%UZ4ga6j9$1@P#OT#sXhh(c~@<2e|f|Z}VTUXTy!6 zHuTgpQzJ&(0DOGIr3@vELQz}T9NAnv5TUn*rN+~{trGV5L?giXKd0;hBF320EEXLF z0BeuCxZ5ls_?NlGyfLV=oqp91{12#JD{a5X5 R=4H2VfSVY8Uv66Pf#LLHc!2-_ From 2b56bab22673797b1a8753d018bf8759e11df3a3 Mon Sep 17 00:00:00 2001 From: stijn Date: Mon, 18 Dec 2023 12:09:30 +0100 Subject: [PATCH 016/408] tests/run-tests.py: Add an option for running only the failed tests. Implement the typical 're-run the failed tests' most test runners have, for convenience. Accessible via the new --run-failures argument, and implemented using a json file containing a list of the failed tests. Signed-off-by: stijn --- tests/run-tests.py | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/tests/run-tests.py b/tests/run-tests.py index bbc98cad96011..32333857f1cb7 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -6,6 +6,7 @@ import platform import argparse import inspect +import json import re from glob import glob import multiprocessing @@ -47,6 +48,8 @@ def base_path(*p): # (not site packages which may clash with u-module names), and improve start up time. CPYTHON3_CMD = [CPYTHON3, "-BS"] +# File with the test results. +RESULTS_FILE = "_results.json" # For diff'ing test output DIFF = os.getenv("MICROPY_DIFF", "diff -u") @@ -770,7 +773,7 @@ def run_one_test(test_file): with open(filename_mupy, "wb") as f: f.write(output_mupy) print("FAIL ", test_file) - failed_tests.append(test_name) + failed_tests.append((test_name, test_file)) test_count.increment() @@ -784,6 +787,7 @@ def run_one_test(test_file): for test in tests: run_one_test(test) + # Leave RESULTS_FILE untouched here for future runs. if args.list_tests: return True @@ -798,8 +802,26 @@ def run_one_test(test_file): if len(skipped_tests) > 0: print("{} tests skipped: {}".format(len(skipped_tests), " ".join(skipped_tests))) failed_tests = sorted(failed_tests.value) + + # Serialize regex added by append_filter. + def to_json(obj): + if isinstance(obj, re.Pattern): + return obj.pattern + return obj + + with open(os.path.join(result_dir, RESULTS_FILE), "w") as f: + json.dump( + {"args": vars(args), "failed_tests": [test[1] for test in failed_tests]}, + f, + default=to_json, + ) + if len(failed_tests) > 0: - print("{} tests failed: {}".format(len(failed_tests), " ".join(failed_tests))) + print( + "{} tests failed: {}".format( + len(failed_tests), " ".join(test[0] for test in failed_tests) + ) + ) return False # all tests succeeded @@ -915,6 +937,11 @@ def main(): action="store_true", help="delete the .exp and .out files from failed tests and exit", ) + cmd_parser.add_argument( + "--run-failures", + action="store_true", + help="re-run only the failed tests", + ) args = cmd_parser.parse_args() if args.print_failures: @@ -931,6 +958,7 @@ def main(): os.path.join(args.result_dir, "*.out") ): os.remove(f) + rm_f(os.path.join(args.result_dir, RESULTS_FILE)) sys.exit(0) @@ -979,7 +1007,19 @@ def main(): else: raise ValueError("target must be one of %s" % ", ".join(LOCAL_TARGETS + EXTERNAL_TARGETS)) - if len(args.files) == 0: + if args.run_failures and (any(args.files) or args.test_dirs is not None): + raise ValueError( + "--run-failures cannot be used together with files or --test-dirs arguments" + ) + + if args.run_failures: + results_file = os.path.join(args.result_dir, RESULTS_FILE) + if os.path.exists(results_file): + with open(results_file, "r") as f: + tests = json.load(f)["failed_tests"] + else: + tests = [] + elif len(args.files) == 0: if args.test_dirs is None: test_dirs = ( "basics", From 7a794d0d8ec61d37b871ee0efd14735fcfcd8b11 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 5 Jan 2024 15:06:14 +1100 Subject: [PATCH 017/408] tools/gen-changelog.sh: Exclude "-preview" tags from generated log. Signed-off-by: Damien George --- tools/gen-changelog.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/gen-changelog.sh b/tools/gen-changelog.sh index 6eca1b4b1104e..4111348fb9cf8 100755 --- a/tools/gen-changelog.sh +++ b/tools/gen-changelog.sh @@ -2,7 +2,7 @@ echo "MicroPython change log" -for t in $(git tag | grep -v v1.0-rc1 | sort -rV); do +for t in $(git tag | grep -v -- '-rc1\|-preview' | sort -rV); do echo '' echo '========' echo '' From ee226a8b4340111eee0b13e7b840948f4bb70465 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 5 Jan 2024 15:07:18 +1100 Subject: [PATCH 018/408] all: Fix "reuse" and "overridden" spelling mistakes. Codespell doesn't pick up "re-used" or "re-uses", and ignores the tests/ directory, so fix these manually. Signed-off-by: Damien George --- docs/library/bluetooth.rst | 2 +- docs/library/rp2.StateMachine.rst | 2 +- docs/reference/constrained.rst | 2 +- tests/basics/bytearray_byte_operations.py | 2 +- tests/extmod/vfs_fat_ilistdir_del.py | 2 +- tests/extmod/vfs_lfs_ilistdir_del.py | 2 +- tests/extmod/vfs_posix_ilistdir_del.py | 2 +- tests/import/ext/micropython.py | 2 +- tests/import/ext/sys.py | 2 +- tests/import/ext/usys.py | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/library/bluetooth.rst b/docs/library/bluetooth.rst index 78cb4cc281486..fb3c23400e51d 100644 --- a/docs/library/bluetooth.rst +++ b/docs/library/bluetooth.rst @@ -312,7 +312,7 @@ Broadcaster Role (Advertiser) in all broadcasts, and *resp_data* is send in reply to an active scan. **Note:** if *adv_data* (or *resp_data*) is ``None``, then the data passed - to the previous call to ``gap_advertise`` will be re-used. This allows a + to the previous call to ``gap_advertise`` will be reused. This allows a broadcaster to resume advertising with just ``gap_advertise(interval_us)``. To clear the advertising payload pass an empty ``bytes``, i.e. ``b''``. diff --git a/docs/library/rp2.StateMachine.rst b/docs/library/rp2.StateMachine.rst index ee16ce3c513da..e8c167c09f573 100644 --- a/docs/library/rp2.StateMachine.rst +++ b/docs/library/rp2.StateMachine.rst @@ -32,7 +32,7 @@ Methods The program is added to the instruction memory of this PIO instance. If the instruction memory already contains this program, then its offset is - re-used so as to save on instruction memory. + reused so as to save on instruction memory. - *freq* is the frequency in Hz to run the state machine at. Defaults to the system clock frequency. diff --git a/docs/reference/constrained.rst b/docs/reference/constrained.rst index 59c375159b2c6..d9a349aa6bb27 100644 --- a/docs/reference/constrained.rst +++ b/docs/reference/constrained.rst @@ -211,7 +211,7 @@ two loops: spi.readinto(buf) # process data in buf -The first creates a buffer on each pass whereas the second re-uses a pre-allocated +The first creates a buffer on each pass whereas the second reuses a pre-allocated buffer; this is both faster and more efficient in terms of memory fragmentation. **Bytes are smaller than ints** diff --git a/tests/basics/bytearray_byte_operations.py b/tests/basics/bytearray_byte_operations.py index 7ce53cac535a1..48b08ab26196f 100644 --- a/tests/basics/bytearray_byte_operations.py +++ b/tests/basics/bytearray_byte_operations.py @@ -1,4 +1,4 @@ -# test bytearray with its re-use of byte functions +# test bytearray with its reuse of byte functions print(bytearray(b"hello world").find(b"ll")) print(bytearray(b"hello\x00world").rfind(b"l")) diff --git a/tests/extmod/vfs_fat_ilistdir_del.py b/tests/extmod/vfs_fat_ilistdir_del.py index 055836ad71bef..ed3ca3df670bc 100644 --- a/tests/extmod/vfs_fat_ilistdir_del.py +++ b/tests/extmod/vfs_fat_ilistdir_del.py @@ -57,7 +57,7 @@ def test(bdev, vfs_class): break vfs.mkdir(dname) - # Also create a fully drained iterator and ensure trying to re-use it + # Also create a fully drained iterator and ensure trying to reuse it # throws the correct exception. idir_emptied = vfs.ilistdir("/") l = list(idir_emptied) diff --git a/tests/extmod/vfs_lfs_ilistdir_del.py b/tests/extmod/vfs_lfs_ilistdir_del.py index ff66717147868..c183118fe0022 100644 --- a/tests/extmod/vfs_lfs_ilistdir_del.py +++ b/tests/extmod/vfs_lfs_ilistdir_del.py @@ -57,7 +57,7 @@ def test(bdev, vfs_class): break vfs.mkdir(dname) - # Also create a fully drained iterator and ensure trying to re-use it + # Also create a fully drained iterator and ensure trying to reuse it # throws the correct exception. idir_emptied = vfs.ilistdir("/") l = list(idir_emptied) diff --git a/tests/extmod/vfs_posix_ilistdir_del.py b/tests/extmod/vfs_posix_ilistdir_del.py index 8c8e6978b6540..11b45e619781e 100644 --- a/tests/extmod/vfs_posix_ilistdir_del.py +++ b/tests/extmod/vfs_posix_ilistdir_del.py @@ -37,7 +37,7 @@ def test(testdir): break vfs.mkdir(dname) - # Also create a fully drained iterator and ensure trying to re-use it + # Also create a fully drained iterator and ensure trying to reuse it # throws the correct exception. idir_emptied = vfs.ilistdir("/") l = list(idir_emptied) diff --git a/tests/import/ext/micropython.py b/tests/import/ext/micropython.py index 88c8b770e1780..251e1e0aa911e 100644 --- a/tests/import/ext/micropython.py +++ b/tests/import/ext/micropython.py @@ -1,2 +1,2 @@ -# micropython is always builtin and cannot be overriden by the filesystem. +# micropython is always builtin and cannot be overridden by the filesystem. print("ERROR: micropython from filesystem") diff --git a/tests/import/ext/sys.py b/tests/import/ext/sys.py index 71ee633e1196b..a041c407f53bf 100644 --- a/tests/import/ext/sys.py +++ b/tests/import/ext/sys.py @@ -1,2 +1,2 @@ -# sys is always builtin and cannot be overriden by the filesystem. +# sys is always builtin and cannot be overridden by the filesystem. print("ERROR: sys from filesystem") diff --git a/tests/import/ext/usys.py b/tests/import/ext/usys.py index d7629a4499d5b..302d1df338b95 100644 --- a/tests/import/ext/usys.py +++ b/tests/import/ext/usys.py @@ -1,3 +1,3 @@ -# usys (and any u-prefix) is always builtin and cannot be overriden by the +# usys (and any u-prefix) is always builtin and cannot be overridden by the # filesystem. print("ERROR: usys from filesystem") From d45176fc271d4d5e264bec2809faeb906787a6f9 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 5 Jan 2024 15:37:17 +1100 Subject: [PATCH 019/408] ports: Move MICROPY_PY_LWIP_ENTER/REENTER/EXIT defns to mphalport.h. Following ad806df857b52e9814dbd857b14f09b63eb847fe where the MICROPY_PY_PENDSV_ENTER/REENTER/EXIT macro definitions were moved to mphalport.h. Signed-off-by: Damien George --- ports/mimxrt/mpconfigport.h | 5 ----- ports/mimxrt/mphalport.h | 5 +++++ ports/renesas-ra/mpconfigport.h | 4 ---- ports/renesas-ra/mphalport.h | 4 ++++ ports/rp2/mpconfigport.h | 5 ----- ports/rp2/mphalport.h | 5 +++++ ports/stm32/mpconfigport.h | 5 ----- ports/stm32/mphalport.h | 5 +++++ 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/ports/mimxrt/mpconfigport.h b/ports/mimxrt/mpconfigport.h index 5feb5b62b80da..c67b010c01acb 100644 --- a/ports/mimxrt/mpconfigport.h +++ b/ports/mimxrt/mpconfigport.h @@ -134,11 +134,6 @@ uint32_t trng_random_u32(void); #define MICROPY_PY_HASHLIB_SHA1 (MICROPY_PY_SSL) // #define MICROPY_PY_CRYPTOLIB (MICROPY_PY_SSL) -// Prevent the "LWIP task" from running. -#define MICROPY_PY_LWIP_ENTER MICROPY_PY_PENDSV_ENTER -#define MICROPY_PY_LWIP_REENTER MICROPY_PY_PENDSV_REENTER -#define MICROPY_PY_LWIP_EXIT MICROPY_PY_PENDSV_EXIT - #ifndef MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE #define MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE (1) #endif diff --git a/ports/mimxrt/mphalport.h b/ports/mimxrt/mphalport.h index 4f1f4bfd123a9..7f5a228fada9f 100644 --- a/ports/mimxrt/mphalport.h +++ b/ports/mimxrt/mphalport.h @@ -45,6 +45,11 @@ #define MICROPY_PY_PENDSV_REENTER atomic_state = raise_irq_pri(IRQ_PRI_PENDSV); #define MICROPY_PY_PENDSV_EXIT restore_irq_pri(atomic_state); +// Prevent the "lwIP task" from running. +#define MICROPY_PY_LWIP_ENTER MICROPY_PY_PENDSV_ENTER +#define MICROPY_PY_LWIP_REENTER MICROPY_PY_PENDSV_REENTER +#define MICROPY_PY_LWIP_EXIT MICROPY_PY_PENDSV_EXIT + #define MICROPY_HW_USB_CDC_TX_TIMEOUT (500) #define MP_HAL_PIN_FMT "%q" diff --git a/ports/renesas-ra/mpconfigport.h b/ports/renesas-ra/mpconfigport.h index 63537fa5abc32..ebd055f2ee9bb 100644 --- a/ports/renesas-ra/mpconfigport.h +++ b/ports/renesas-ra/mpconfigport.h @@ -292,10 +292,6 @@ typedef long mp_off_t; #define MICROPY_THREAD_YIELD() #endif -#define MICROPY_PY_LWIP_ENTER -#define MICROPY_PY_LWIP_REENTER -#define MICROPY_PY_LWIP_EXIT - #ifndef MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE #define MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE (1) #endif diff --git a/ports/renesas-ra/mphalport.h b/ports/renesas-ra/mphalport.h index b8441e37676cd..c5d27f2e43e9d 100644 --- a/ports/renesas-ra/mphalport.h +++ b/ports/renesas-ra/mphalport.h @@ -35,6 +35,10 @@ #define MICROPY_PY_PENDSV_ENTER uint32_t atomic_state = raise_irq_pri(IRQ_PRI_PENDSV) #define MICROPY_PY_PENDSV_EXIT restore_irq_pri(atomic_state) +#define MICROPY_PY_LWIP_ENTER +#define MICROPY_PY_LWIP_REENTER +#define MICROPY_PY_LWIP_EXIT + #define MICROPY_HW_USB_CDC_TX_TIMEOUT (500) extern const unsigned char mp_hal_status_to_errno_table[4]; diff --git a/ports/rp2/mpconfigport.h b/ports/rp2/mpconfigport.h index 1cc9b96160396..8431357ffe83e 100644 --- a/ports/rp2/mpconfigport.h +++ b/ports/rp2/mpconfigport.h @@ -245,11 +245,6 @@ extern const struct _mp_obj_type_t mod_network_nic_type_wiznet5k; #define MICROPY_HW_BOOTSEL_DELAY_US 8 #endif -// Prevent the "lwIP task" from running when unsafe to do so. -#define MICROPY_PY_LWIP_ENTER lwip_lock_acquire(); -#define MICROPY_PY_LWIP_REENTER lwip_lock_acquire(); -#define MICROPY_PY_LWIP_EXIT lwip_lock_release(); - // Port level Wait-for-Event macro // // Do not use this macro directly, include py/runtime.h and diff --git a/ports/rp2/mphalport.h b/ports/rp2/mphalport.h index 9feace2f43ae2..b2576c2275471 100644 --- a/ports/rp2/mphalport.h +++ b/ports/rp2/mphalport.h @@ -43,6 +43,11 @@ #define MICROPY_PY_PENDSV_ENTER pendsv_suspend() #define MICROPY_PY_PENDSV_EXIT pendsv_resume() +// Prevent the "lwIP task" from running when unsafe to do so. +#define MICROPY_PY_LWIP_ENTER lwip_lock_acquire(); +#define MICROPY_PY_LWIP_REENTER lwip_lock_acquire(); +#define MICROPY_PY_LWIP_EXIT lwip_lock_release(); + extern int mp_interrupt_char; extern ringbuf_t stdin_ringbuf; diff --git a/ports/stm32/mpconfigport.h b/ports/stm32/mpconfigport.h index 21fab6ffd658f..300ad086bf473 100644 --- a/ports/stm32/mpconfigport.h +++ b/ports/stm32/mpconfigport.h @@ -268,11 +268,6 @@ typedef long mp_off_t; // Configuration for shared/runtime/softtimer.c. #define MICROPY_SOFT_TIMER_TICKS_MS uwTick -// Prevent the "LWIP task" from running. -#define MICROPY_PY_LWIP_ENTER MICROPY_PY_PENDSV_ENTER -#define MICROPY_PY_LWIP_REENTER MICROPY_PY_PENDSV_REENTER -#define MICROPY_PY_LWIP_EXIT MICROPY_PY_PENDSV_EXIT - #ifndef MICROPY_PY_NETWORK_HOSTNAME_DEFAULT #define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-stm32" #endif diff --git a/ports/stm32/mphalport.h b/ports/stm32/mphalport.h index 4983970876f73..e520bc54ae6c0 100644 --- a/ports/stm32/mphalport.h +++ b/ports/stm32/mphalport.h @@ -53,6 +53,11 @@ void mp_hal_set_interrupt_char(int c); // -1 to disable #define MICROPY_PY_PENDSV_REENTER atomic_state = raise_irq_pri(IRQ_PRI_PENDSV); #define MICROPY_PY_PENDSV_EXIT restore_irq_pri(atomic_state); +// Prevent the "lwIP task" from running. +#define MICROPY_PY_LWIP_ENTER MICROPY_PY_PENDSV_ENTER +#define MICROPY_PY_LWIP_REENTER MICROPY_PY_PENDSV_REENTER +#define MICROPY_PY_LWIP_EXIT MICROPY_PY_PENDSV_EXIT + // Timing functions. #if __CORTEX_M == 0 From 0640ff3b97f608a9f55ac380c6681cc48cc1e737 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 5 Jan 2024 15:47:06 +1100 Subject: [PATCH 020/408] ports: Move MICROPY_INTERNAL_WFE definition to mphalport.h. It belongs here because the default value is defined in py/mphal.h. Signed-off-by: Damien George --- ports/rp2/mpconfigport.h | 13 ------------- ports/rp2/mphalport.h | 13 +++++++++++++ ports/unix/mpconfigport.h | 6 ------ ports/unix/mphalport.h | 6 ++++++ ports/windows/mpconfigport.h | 9 --------- ports/windows/windows_mphal.h | 11 +++++++++++ 6 files changed, 30 insertions(+), 28 deletions(-) diff --git a/ports/rp2/mpconfigport.h b/ports/rp2/mpconfigport.h index 8431357ffe83e..ce89763d5ea58 100644 --- a/ports/rp2/mpconfigport.h +++ b/ports/rp2/mpconfigport.h @@ -245,19 +245,6 @@ extern const struct _mp_obj_type_t mod_network_nic_type_wiznet5k; #define MICROPY_HW_BOOTSEL_DELAY_US 8 #endif -// Port level Wait-for-Event macro -// -// Do not use this macro directly, include py/runtime.h and -// call mp_event_wait_indefinite() or mp_event_wait_ms(timeout) -#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) \ - do { \ - if ((TIMEOUT_MS) < 0) { \ - __wfe(); \ - } else { \ - best_effort_wfe_or_timeout(make_timeout_time_ms(TIMEOUT_MS)); \ - } \ - } while (0) - #define MICROPY_MAKE_POINTER_CALLABLE(p) ((void *)((mp_uint_t)(p) | 1)) #define MP_SSIZE_MAX (0x7fffffff) diff --git a/ports/rp2/mphalport.h b/ports/rp2/mphalport.h index b2576c2275471..c8e2301a92ea9 100644 --- a/ports/rp2/mphalport.h +++ b/ports/rp2/mphalport.h @@ -48,6 +48,19 @@ #define MICROPY_PY_LWIP_REENTER lwip_lock_acquire(); #define MICROPY_PY_LWIP_EXIT lwip_lock_release(); +// Port level Wait-for-Event macro +// +// Do not use this macro directly, include py/runtime.h and +// call mp_event_wait_indefinite() or mp_event_wait_ms(timeout) +#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) \ + do { \ + if ((TIMEOUT_MS) < 0) { \ + __wfe(); \ + } else { \ + best_effort_wfe_or_timeout(make_timeout_time_ms(TIMEOUT_MS)); \ + } \ + } while (0) + extern int mp_interrupt_char; extern ringbuf_t stdin_ringbuf; diff --git a/ports/unix/mpconfigport.h b/ports/unix/mpconfigport.h index c7e7347cbb2b4..1086baea06c60 100644 --- a/ports/unix/mpconfigport.h +++ b/ports/unix/mpconfigport.h @@ -221,12 +221,6 @@ static inline unsigned long mp_random_seed_init(void) { #include #endif -// In lieu of a WFI(), slow down polling from being a tight loop. -// -// Note that we don't delay for the full TIMEOUT_MS, as execution -// can't be woken from the delay. -#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) mp_hal_delay_us(500) - // Configure the implementation of machine.idle(). #include #define MICROPY_UNIX_MACHINE_IDLE sched_yield(); diff --git a/ports/unix/mphalport.h b/ports/unix/mphalport.h index ca951e5001012..02b60d8a873b9 100644 --- a/ports/unix/mphalport.h +++ b/ports/unix/mphalport.h @@ -36,6 +36,12 @@ #define MICROPY_END_ATOMIC_SECTION(x) (void)x; mp_thread_unix_end_atomic_section() #endif +// In lieu of a WFI(), slow down polling from being a tight loop. +// +// Note that we don't delay for the full TIMEOUT_MS, as execution +// can't be woken from the delay. +#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) mp_hal_delay_us(500) + void mp_hal_set_interrupt_char(char c); #define mp_hal_stdio_poll unused // this is not implemented, nor needed diff --git a/ports/windows/mpconfigport.h b/ports/windows/mpconfigport.h index e615fe8502b0c..dee5568c6225c 100644 --- a/ports/windows/mpconfigport.h +++ b/ports/windows/mpconfigport.h @@ -224,15 +224,6 @@ typedef long mp_off_t; #include "realpath.h" #include "init.h" -#include "sleep.h" - -#if MICROPY_ENABLE_SCHEDULER -// Use minimum 1mSec sleep to make sure there is effectively a wait period: -// something like usleep(500) truncates and ends up calling Sleep(0). -#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) msec_sleep(MAX(1.0, (double)(TIMEOUT_MS))) -#else -#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) /* No-op */ -#endif #ifdef __GNUC__ #define MP_NOINLINE __attribute__((noinline)) diff --git a/ports/windows/windows_mphal.h b/ports/windows/windows_mphal.h index 2b7aab44a0fd4..e70d00def77b5 100644 --- a/ports/windows/windows_mphal.h +++ b/ports/windows/windows_mphal.h @@ -27,6 +27,17 @@ #include "sleep.h" #include "ports/unix/mphalport.h" +// Don't use the unix version of this macro. +#undef MICROPY_INTERNAL_WFE + +#if MICROPY_ENABLE_SCHEDULER +// Use minimum 1mSec sleep to make sure there is effectively a wait period: +// something like usleep(500) truncates and ends up calling Sleep(0). +#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) msec_sleep(MAX(1.0, (double)(TIMEOUT_MS))) +#else +#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) /* No-op */ +#endif + #define MICROPY_HAL_HAS_VT100 (0) void mp_hal_move_cursor_back(unsigned int pos); From 42eab32a36f70840c7e670a61269fb795d43991b Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 5 Jan 2024 15:56:34 +1100 Subject: [PATCH 021/408] windows/windows_mphal: Fix mp_hal_delay_ms() so it runs events. This changed behaviour in c393f5c12321a80bea40af7ef2e42a077df5d806 when the MICROPY_EVENT_POLL_HOOK macro was removed. Signed-off-by: Damien George --- ports/windows/windows_mphal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/windows/windows_mphal.c b/ports/windows/windows_mphal.c index f88491707f193..dcee20784e79f 100644 --- a/ports/windows/windows_mphal.c +++ b/ports/windows/windows_mphal.c @@ -279,10 +279,10 @@ int usleep(__int64 usec) { #endif void mp_hal_delay_ms(mp_uint_t ms) { - #ifdef MICROPY_EVENT_POLL_HOOK + #if MICROPY_ENABLE_SCHEDULER mp_uint_t start = mp_hal_ticks_ms(); while (mp_hal_ticks_ms() - start < ms) { - MICROPY_EVENT_POLL_HOOK + mp_event_wait_ms(1); } #else msec_sleep((double)ms); From 80fd575c8cc103133fed4c7386f0b7165abd2678 Mon Sep 17 00:00:00 2001 From: darc Date: Fri, 5 Jan 2024 00:47:57 -0600 Subject: [PATCH 022/408] embed: Fix alloca include for FreeBSD and NetBSD. Signed-off-by: darc --- ports/embed/port/mpconfigport_common.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ports/embed/port/mpconfigport_common.h b/ports/embed/port/mpconfigport_common.h index 69216a7582681..8e19859ed2ed9 100644 --- a/ports/embed/port/mpconfigport_common.h +++ b/ports/embed/port/mpconfigport_common.h @@ -33,6 +33,10 @@ typedef uintptr_t mp_uint_t; // must be pointer size typedef long mp_off_t; // Need to provide a declaration/definition of alloca() +#if defined(__FreeBSD__) || defined(__NetBSD__) +#include +#else #include +#endif #define MICROPY_MPHALPORT_H "port/mphalport.h" From f8cabe82f71add182702f32e1b1444a44c83eb74 Mon Sep 17 00:00:00 2001 From: Nicko van Someren Date: Sat, 6 Jan 2024 16:33:12 -0700 Subject: [PATCH 023/408] rp2/rp2_dma: Fix fetching 'write' buffers for writing not reading. Signed-off-by: Nicko van Someren --- ports/rp2/rp2_dma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/rp2/rp2_dma.c b/ports/rp2/rp2_dma.c index acc18d08c58da..893498265aa41 100644 --- a/ports/rp2/rp2_dma.c +++ b/ports/rp2/rp2_dma.c @@ -86,7 +86,7 @@ STATIC const uint32_t rp2_dma_ctrl_field_count = MP_ARRAY_SIZE(rp2_dma_ctrl_fiel STATIC uint32_t rp2_dma_register_value_from_obj(mp_obj_t o, int reg_type) { if (reg_type == REG_TYPE_ADDR_READ || reg_type == REG_TYPE_ADDR_WRITE) { mp_buffer_info_t buf_info; - mp_uint_t flags = MP_BUFFER_READ; + mp_uint_t flags = (reg_type == REG_TYPE_ADDR_READ) ? MP_BUFFER_READ : MP_BUFFER_WRITE; if (mp_get_buffer(o, &buf_info, flags)) { return (uint32_t)buf_info.buf; } From 1da45e887af1b5e6e608a13e292aa343f5b9f976 Mon Sep 17 00:00:00 2001 From: Nicko van Someren Date: Sat, 6 Jan 2024 16:33:51 -0700 Subject: [PATCH 024/408] rp2: Provide direct memory access to PIO and SPI FIFOs via proxy arrays. Signed-off-by: Nicko van Someren --- ports/rp2/machine_spi.c | 13 +++++++++++++ ports/rp2/rp2_pio.c | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/ports/rp2/machine_spi.c b/ports/rp2/machine_spi.c index fb8e9f56caec5..a4f4243b7a1fd 100644 --- a/ports/rp2/machine_spi.c +++ b/ports/rp2/machine_spi.c @@ -302,6 +302,18 @@ STATIC void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8 } } +// Buffer protocol implementation for SPI. +// The buffer represents the SPI data FIFO. +STATIC mp_int_t machine_spi_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { + machine_spi_obj_t *self = MP_OBJ_TO_PTR(o_in); + + bufinfo->len = 4; + bufinfo->typecode = 'I'; + bufinfo->buf = (void *)&spi_get_hw(self->spi_inst)->dr; + + return 0; +} + STATIC const mp_machine_spi_p_t machine_spi_p = { .init = machine_spi_init, .transfer = machine_spi_transfer, @@ -314,6 +326,7 @@ MP_DEFINE_CONST_OBJ_TYPE( make_new, machine_spi_make_new, print, machine_spi_print, protocol, &machine_spi_p, + buffer, machine_spi_get_buffer, locals_dict, &mp_machine_spi_locals_dict ); diff --git a/ports/rp2/rp2_pio.c b/ports/rp2/rp2_pio.c index 3a0ab844eafd4..42e61684b3369 100644 --- a/ports/rp2/rp2_pio.c +++ b/ports/rp2/rp2_pio.c @@ -809,6 +809,23 @@ STATIC mp_obj_t rp2_state_machine_tx_fifo(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(rp2_state_machine_tx_fifo_obj, rp2_state_machine_tx_fifo); +// Buffer protocol implementation for StateMachine. +// The buffer represents one of the FIFO ports of the state machine. Note that a different +// pointer is returned depending on if this is for reading or writing. +STATIC mp_int_t rp2_state_machine_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { + rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(o_in); + + bufinfo->len = 4; + bufinfo->typecode = 'I'; + + if (flags & MP_BUFFER_WRITE) { + bufinfo->buf = (void *)&self->pio->txf[self->sm]; + } else { + bufinfo->buf = (void *)&self->pio->rxf[self->sm]; + } + return 0; +} + // StateMachine.irq(handler=None, trigger=0|1, hard=False) STATIC mp_obj_t rp2_state_machine_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_handler, ARG_trigger, ARG_hard }; @@ -884,6 +901,7 @@ MP_DEFINE_CONST_OBJ_TYPE( MP_TYPE_FLAG_NONE, make_new, rp2_state_machine_make_new, print, rp2_state_machine_print, + buffer, rp2_state_machine_get_buffer, locals_dict, &rp2_state_machine_locals_dict ); From b7b99522e4fb6ccf46d996c5ee52e8aceb1f7439 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 29 Nov 2023 17:19:34 +1100 Subject: [PATCH 025/408] stm32/mboot: Improve detection of invalid flash erase/write. This commit replaces the linker symbol `_mboot_writable_flash_start` with `_mboot_protected_flash_start` and `_mboot_protected_flash_end_exclusive`, to provide better configuration of the protected flash area. Signed-off-by: Damien George --- .../stm32/boards/LEGO_HUB_NO6/mboot_memory.ld | 6 +-- ports/stm32/mboot/main.c | 50 +++++++++---------- ports/stm32/mboot/stm32_memory.ld | 6 +-- 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/ports/stm32/boards/LEGO_HUB_NO6/mboot_memory.ld b/ports/stm32/boards/LEGO_HUB_NO6/mboot_memory.ld index f48f2056cae61..3e457995b641f 100644 --- a/ports/stm32/boards/LEGO_HUB_NO6/mboot_memory.ld +++ b/ports/stm32/boards/LEGO_HUB_NO6/mboot_memory.ld @@ -8,6 +8,6 @@ MEMORY RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 120K } -/* Location from which mboot is allowed to write to flash. - Must be the start of a flash erase sector. */ -_mboot_writable_flash_start = ORIGIN(FLASH_BL) + LENGTH(FLASH_BL); +/* Location of protected flash area which must not be modified, because mboot lives there. */ +_mboot_protected_flash_start = ORIGIN(FLASH_BL); +_mboot_protected_flash_end_exclusive = ORIGIN(FLASH_BL) + LENGTH(FLASH_BL); diff --git a/ports/stm32/mboot/main.c b/ports/stm32/mboot/main.c index d034996afbf69..0791182871f63 100644 --- a/ports/stm32/mboot/main.c +++ b/ports/stm32/mboot/main.c @@ -109,15 +109,13 @@ // These bits are used to detect valid application firmware at APPLICATION_ADDR #define APP_VALIDITY_BITS (0x00000003) -// Symbol provided by the linker, at the address in flash where mboot can start erasing/writing. -extern uint8_t _mboot_writable_flash_start; +// Symbols provided by the linker, the protected flash address range where mboot lives. +extern uint8_t _mboot_protected_flash_start; +extern uint8_t _mboot_protected_flash_end_exclusive; // For 1ms system ticker. volatile uint32_t systick_ms; -// The sector number of the first sector that can be erased/written. -int32_t first_writable_flash_sector; - // Global dfu state dfu_context_t dfu_context SECTION_NOZERO_BSS; @@ -410,10 +408,10 @@ void mp_hal_pin_config_speed(uint32_t port_pin, uint32_t speed) { /******************************************************************************/ // FLASH -#if defined(STM32G0) +#define FLASH_START (FLASH_BASE) + +#if defined(STM32G0) || defined(STM32H5) #define FLASH_END (FLASH_BASE + FLASH_SIZE - 1) -#elif defined(STM32H5) -#define FLASH_END (0x08000000 + 2 * 1024 * 1024) #elif defined(STM32WB) #define FLASH_END FLASH_END_ADDR #endif @@ -446,30 +444,36 @@ void mp_hal_pin_config_speed(uint32_t port_pin, uint32_t speed) { #define FLASH_LAYOUT_STR "@Internal Flash /0x08000000/256*04Kg" MBOOT_SPIFLASH_LAYOUT MBOOT_SPIFLASH2_LAYOUT #endif +static bool flash_is_modifiable_addr_range(uint32_t addr, uint32_t len) { + return addr + len < (uint32_t)&_mboot_protected_flash_start + || addr >= (uint32_t)&_mboot_protected_flash_end_exclusive; +} + static int mboot_flash_mass_erase(void) { // Erase all flash pages after mboot. - uint32_t start_addr = (uint32_t)&_mboot_writable_flash_start; + uint32_t start_addr = (uint32_t)&_mboot_protected_flash_end_exclusive; uint32_t num_words = (FLASH_END + 1 - start_addr) / sizeof(uint32_t); int ret = flash_erase(start_addr, num_words); return ret; } static int mboot_flash_page_erase(uint32_t addr, uint32_t *next_addr) { + // Compute start and end address of the sector being erased. uint32_t sector_size = 0; uint32_t sector_start = 0; - int32_t sector = flash_get_sector_info(addr, §or_start, §or_size); - if (sector < first_writable_flash_sector) { + int ret = flash_get_sector_info(addr, §or_start, §or_size); + *next_addr = sector_start + sector_size; + + if (ret < 0 || !flash_is_modifiable_addr_range(addr, *next_addr - addr)) { // Don't allow to erase the sector with this bootloader in it, or invalid sectors dfu_context.status = DFU_STATUS_ERROR_ADDRESS; - dfu_context.error = (sector == 0) ? MBOOT_ERROR_STR_OVERWRITE_BOOTLOADER_IDX - : MBOOT_ERROR_STR_INVALID_ADDRESS_IDX; + dfu_context.error = (ret < 0) ? MBOOT_ERROR_STR_INVALID_ADDRESS_IDX + : MBOOT_ERROR_STR_OVERWRITE_BOOTLOADER_IDX; return -MBOOT_ERRNO_FLASH_ERASE_DISALLOWED; } - *next_addr = sector_start + sector_size; - // Erase the flash page. - int ret = flash_erase(sector_start, sector_size / sizeof(uint32_t)); + ret = flash_erase(sector_start, sector_size / sizeof(uint32_t)); if (ret != 0) { return ret; } @@ -485,12 +489,12 @@ static int mboot_flash_page_erase(uint32_t addr, uint32_t *next_addr) { } static int mboot_flash_write(uint32_t addr, const uint8_t *src8, size_t len) { - int32_t sector = flash_get_sector_info(addr, NULL, NULL); - if (sector < first_writable_flash_sector) { + bool valid = flash_is_valid_addr(addr); + if (!valid || !flash_is_modifiable_addr_range(addr, len)) { // Don't allow to write the sector with this bootloader in it, or invalid sectors. dfu_context.status = DFU_STATUS_ERROR_ADDRESS; - dfu_context.error = (sector == 0) ? MBOOT_ERROR_STR_OVERWRITE_BOOTLOADER_IDX - : MBOOT_ERROR_STR_INVALID_ADDRESS_IDX; + dfu_context.error = (!valid) ? MBOOT_ERROR_STR_INVALID_ADDRESS_IDX + : MBOOT_ERROR_STR_OVERWRITE_BOOTLOADER_IDX; return -MBOOT_ERRNO_FLASH_WRITE_DISALLOWED; } @@ -1496,12 +1500,6 @@ void stm32_main(uint32_t initial_r0) { __ASM volatile ("msr basepri_max, %0" : : "r" (pri) : "memory"); #endif - // Compute the first erasable/writable internal flash sector. - first_writable_flash_sector = flash_get_sector_info((uint32_t)&_mboot_writable_flash_start, NULL, NULL); - if (first_writable_flash_sector < 0) { - first_writable_flash_sector = INT32_MAX; - } - #if defined(MBOOT_SPIFLASH_ADDR) MBOOT_SPIFLASH_SPIFLASH->config = MBOOT_SPIFLASH_CONFIG; mp_spiflash_init(MBOOT_SPIFLASH_SPIFLASH); diff --git a/ports/stm32/mboot/stm32_memory.ld b/ports/stm32/mboot/stm32_memory.ld index ef1b83f30bf72..365693b3a304c 100644 --- a/ports/stm32/mboot/stm32_memory.ld +++ b/ports/stm32/mboot/stm32_memory.ld @@ -9,6 +9,6 @@ MEMORY RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 120K } -/* Location from which mboot is allowed to write to flash. - Must be the start of a flash erase sector. */ -_mboot_writable_flash_start = ORIGIN(FLASH_BL) + LENGTH(FLASH_BL); +/* Location of protected flash area which must not be modified, because mboot lives there. */ +_mboot_protected_flash_start = ORIGIN(FLASH_BL); +_mboot_protected_flash_end_exclusive = ORIGIN(FLASH_BL) + LENGTH(FLASH_BL); From 7002a19be2bbc598b6dcdef4db2dd37e7e7753c5 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 29 Nov 2023 17:20:03 +1100 Subject: [PATCH 026/408] stm32/mboot: Improve mass erase to erase all non-protected pages. Signed-off-by: Damien George --- ports/stm32/mboot/main.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/ports/stm32/mboot/main.c b/ports/stm32/mboot/main.c index 0791182871f63..11755308716fb 100644 --- a/ports/stm32/mboot/main.c +++ b/ports/stm32/mboot/main.c @@ -449,14 +449,6 @@ static bool flash_is_modifiable_addr_range(uint32_t addr, uint32_t len) { || addr >= (uint32_t)&_mboot_protected_flash_end_exclusive; } -static int mboot_flash_mass_erase(void) { - // Erase all flash pages after mboot. - uint32_t start_addr = (uint32_t)&_mboot_protected_flash_end_exclusive; - uint32_t num_words = (FLASH_END + 1 - start_addr) / sizeof(uint32_t); - int ret = flash_erase(start_addr, num_words); - return ret; -} - static int mboot_flash_page_erase(uint32_t addr, uint32_t *next_addr) { // Compute start and end address of the sector being erased. uint32_t sector_size = 0; @@ -488,6 +480,23 @@ static int mboot_flash_page_erase(uint32_t addr, uint32_t *next_addr) { return 0; } +static int mboot_flash_mass_erase(void) { + // Erase all flash pages except those disallowed because they overlap with mboot. + uint32_t addr = FLASH_START; + while (addr <= FLASH_END) { + int ret = mboot_flash_page_erase(addr, &addr); + if (ret != 0 && ret != -MBOOT_ERRNO_FLASH_ERASE_DISALLOWED) { + return ret; + } + } + + // Reset any errors from disallowed page erases. + dfu_context.status = DFU_STATUS_OK; + dfu_context.error = 0; + + return 0; +} + static int mboot_flash_write(uint32_t addr, const uint8_t *src8, size_t len) { bool valid = flash_is_valid_addr(addr); if (!valid || !flash_is_modifiable_addr_range(addr, len)) { From cd0f75069cf7488d5b26760c3c9a2f357df919f3 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 1 Nov 2023 16:05:21 +1100 Subject: [PATCH 027/408] stm32/flash: Remove commented-out flash functions. Signed-off-by: Damien George --- ports/stm32/flash.c | 73 ----------------------------------------- ports/stm32/flashbdev.c | 19 ----------- 2 files changed, 92 deletions(-) diff --git a/ports/stm32/flash.c b/ports/stm32/flash.c index a8f50dbcbaf7a..04448a1186e82 100644 --- a/ports/stm32/flash.c +++ b/ports/stm32/flash.c @@ -355,35 +355,6 @@ int flash_erase(uint32_t flash_dest, uint32_t num_word32) { return mp_hal_status_to_neg_errno(status); } -/* -// erase the sector using an interrupt -void flash_erase_it(uint32_t flash_dest, uint32_t num_word32) { - // check there is something to write - if (num_word32 == 0) { - return; - } - - // unlock - HAL_FLASH_Unlock(); - - // Clear pending flags (if any) - __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | - FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR); - - // erase the sector(s) - FLASH_EraseInitTypeDef EraseInitStruct; - EraseInitStruct.TypeErase = TYPEERASE_SECTORS; - EraseInitStruct.VoltageRange = VOLTAGE_RANGE_3; // voltage range needs to be 2.7V to 3.6V - EraseInitStruct.Sector = flash_get_sector_info(flash_dest, NULL, NULL); - EraseInitStruct.NbSectors = flash_get_sector_info(flash_dest + 4 * num_word32 - 1, NULL, NULL) - EraseInitStruct.Sector + 1; - if (HAL_FLASHEx_Erase_IT(&EraseInitStruct) != HAL_OK) { - // error occurred during sector erase - HAL_FLASH_Lock(); // lock the flash - return; - } -} -*/ - int flash_write(uint32_t flash_dest, const uint32_t *src, uint32_t num_word32) { #if MICROPY_HW_STM32WB_FLASH_SYNCRONISATION // Acquire lock on the flash peripheral. @@ -498,47 +469,3 @@ int flash_write(uint32_t flash_dest, const uint32_t *src, uint32_t num_word32) { return mp_hal_status_to_neg_errno(status); } - -/* - use erase, then write -void flash_erase_and_write(uint32_t flash_dest, const uint32_t *src, uint32_t num_word32) { - // check there is something to write - if (num_word32 == 0) { - return; - } - - // unlock - HAL_FLASH_Unlock(); - - // Clear pending flags (if any) - __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | - FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR); - - // erase the sector(s) - FLASH_EraseInitTypeDef EraseInitStruct; - EraseInitStruct.TypeErase = TYPEERASE_SECTORS; - EraseInitStruct.VoltageRange = VOLTAGE_RANGE_3; // voltage range needs to be 2.7V to 3.6V - EraseInitStruct.Sector = flash_get_sector_info(flash_dest, NULL, NULL); - EraseInitStruct.NbSectors = flash_get_sector_info(flash_dest + 4 * num_word32 - 1, NULL, NULL) - EraseInitStruct.Sector + 1; - uint32_t SectorError = 0; - if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) { - // error occurred during sector erase - HAL_FLASH_Lock(); // lock the flash - return; - } - - // program the flash word by word - for (int i = 0; i < num_word32; i++) { - if (HAL_FLASH_Program(TYPEPROGRAM_WORD, flash_dest, *src) != HAL_OK) { - // error occurred during flash write - HAL_FLASH_Lock(); // lock the flash - return; - } - flash_dest += 4; - src += 1; - } - - // lock the flash - HAL_FLASH_Lock(); -} -*/ diff --git a/ports/stm32/flashbdev.c b/ports/stm32/flashbdev.c index bcff94b15d4e9..19edde2108c79 100644 --- a/ports/stm32/flashbdev.c +++ b/ports/stm32/flashbdev.c @@ -159,25 +159,6 @@ static void flash_bdev_irq_handler(void) { return; } - // This code uses interrupts to erase the flash - /* - if (flash_erase_state == 0) { - flash_erase_it(flash_cache_sector_start, flash_cache_sector_size / 4); - flash_erase_state = 1; - return; - } - - if (flash_erase_state == 1) { - // wait for erase - // TODO add timeout - #define flash_erase_done() (__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY) == RESET) - if (!flash_erase_done()) { - return; - } - flash_erase_state = 2; - } - */ - // This code erases the flash directly, waiting for it to finish if (!(flash_flags & FLASH_FLAG_ERASED)) { flash_erase(flash_cache_sector_start, flash_cache_sector_size / 4); From cf115918e66bea460256661848d9198ca6ca994d Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 1 Nov 2023 17:06:41 +1100 Subject: [PATCH 028/408] stm32/flash: Simplify sector calculation for homogeneous flash layout. Newer STM32 parts have homogeneous flash layout, and in this case the MCU configuration and page/sector calculation can be simplified. The affected functions are `flash_is_valid_addr()` and `flash_get_sector_info()`, which are now simpler for homogeneous flash. Signed-off-by: Damien George --- ports/stm32/flash.c | 78 +++++++++++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 24 deletions(-) diff --git a/ports/stm32/flash.c b/ports/stm32/flash.c index 04448a1186e82..d9f7af8a24f65 100644 --- a/ports/stm32/flash.c +++ b/ports/stm32/flash.c @@ -66,12 +66,15 @@ typedef struct { #if defined(STM32F0) -static const flash_layout_t flash_layout[] = { - { FLASH_BASE, FLASH_PAGE_SIZE, (FLASH_BANK1_END + 1 - FLASH_BASE) / FLASH_PAGE_SIZE }, -}; +#define FLASH_LAYOUT_IS_HOMOGENEOUS (1) +#define FLASH_LAYOUT_START_ADDR (FLASH_BASE) +#define FLASH_LAYOUT_SECTOR_SIZE (FLASH_PAGE_SIZE) +#define FLASH_LAYOUT_NUM_SECTORS ((FLASH_BANK1_END + 1 - FLASH_BASE) / FLASH_PAGE_SIZE) #elif defined(STM32F4) +#define FLASH_LAYOUT_IS_HOMOGENEOUS (0) + static const flash_layout_t flash_layout[] = { { 0x08000000, 0x04000, 4 }, { 0x08010000, 0x10000, 1 }, @@ -88,6 +91,8 @@ static const flash_layout_t flash_layout[] = { #elif defined(STM32F7) +#define FLASH_LAYOUT_IS_HOMOGENEOUS (0) + // FLASH_FLAG_PGSERR (Programming Sequence Error) was renamed to // FLASH_FLAG_ERSERR (Erasing Sequence Error) in STM32F7 #define FLASH_FLAG_PGSERR FLASH_FLAG_ERSERR @@ -113,27 +118,31 @@ static const flash_layout_t flash_layout[] = { #elif defined(STM32G0) || defined(STM32G4) || defined(STM32L0) || defined(STM32L4) || defined(STM32WB) || defined(STM32WL) -static const flash_layout_t flash_layout[] = { - { (uint32_t)FLASH_BASE, (uint32_t)FLASH_PAGE_SIZE, 512 }, -}; +#define FLASH_LAYOUT_IS_HOMOGENEOUS (1) +#define FLASH_LAYOUT_START_ADDR (FLASH_BASE) +#define FLASH_LAYOUT_SECTOR_SIZE (FLASH_PAGE_SIZE) +#define FLASH_LAYOUT_NUM_SECTORS (512) #elif defined(STM32L1) -static const flash_layout_t flash_layout[] = { - { (uint32_t)FLASH_BASE, 0x200, 1024 }, -}; +#define FLASH_LAYOUT_IS_HOMOGENEOUS (1) +#define FLASH_LAYOUT_START_ADDR (FLASH_BASE) +#define FLASH_LAYOUT_SECTOR_SIZE (0x200) +#define FLASH_LAYOUT_NUM_SECTORS (1024) #elif defined(STM32H5) -static const flash_layout_t flash_layout[] = { - { 0x08000000, 8192, 256 }, -}; +#define FLASH_LAYOUT_IS_HOMOGENEOUS (1) +#define FLASH_LAYOUT_START_ADDR (FLASH_BASE_NS) +#define FLASH_LAYOUT_SECTOR_SIZE (0x2000) +#define FLASH_LAYOUT_NUM_SECTORS (256) #elif defined(STM32H7) -static const flash_layout_t flash_layout[] = { - { 0x08000000, 0x20000, 16 }, -}; +#define FLASH_LAYOUT_IS_HOMOGENEOUS (1) +#define FLASH_LAYOUT_START_ADDR (FLASH_BASE) +#define FLASH_LAYOUT_SECTOR_SIZE (0x20000) +#define FLASH_LAYOUT_NUM_SECTORS (16) #else #error Unsupported processor @@ -156,14 +165,14 @@ static uint32_t get_bank(uint32_t addr) { if (READ_BIT(SYSCFG->MEMRMP, SYSCFG_MEMRMP_FB_MODE) == 0) { #endif // no bank swap - if (addr < (FLASH_BASE + FLASH_BANK_SIZE)) { + if (addr < (FLASH_LAYOUT_START_ADDR + FLASH_BANK_SIZE)) { return FLASH_BANK_1; } else { return FLASH_BANK_2; } } else { // bank swap - if (addr < (FLASH_BASE + FLASH_BANK_SIZE)) { + if (addr < (FLASH_LAYOUT_START_ADDR + FLASH_BANK_SIZE)) { return FLASH_BANK_2; } else { return FLASH_BANK_1; @@ -174,12 +183,12 @@ static uint32_t get_bank(uint32_t addr) { #if (defined(STM32L4) && defined(SYSCFG_MEMRMP_FB_MODE)) // get the page of a given flash address static uint32_t get_page(uint32_t addr) { - if (addr < (FLASH_BASE + FLASH_BANK_SIZE)) { + if (addr < (FLASH_LAYOUT_START_ADDR + FLASH_BANK_SIZE)) { // bank 1 - return (addr - FLASH_BASE) / FLASH_PAGE_SIZE; + return (addr - FLASH_LAYOUT_START_ADDR) / FLASH_LAYOUT_SECTOR_SIZE; } else { // bank 2 - return (addr - (FLASH_BASE + FLASH_BANK_SIZE)) / FLASH_PAGE_SIZE; + return (addr - (FLASH_LAYOUT_START_ADDR + FLASH_BANK_SIZE)) / FLASH_LAYOUT_SECTOR_SIZE; } } #endif @@ -187,18 +196,18 @@ static uint32_t get_page(uint32_t addr) { #elif (defined(STM32L4) && !defined(SYSCFG_MEMRMP_FB_MODE)) || defined(STM32WB) || defined(STM32WL) static uint32_t get_page(uint32_t addr) { - return (addr - FLASH_BASE) / FLASH_PAGE_SIZE; + return (addr - FLASH_LAYOUT_START_ADDR) / FLASH_LAYOUT_SECTOR_SIZE; } #elif defined(STM32G0) || defined(STM32G4) static uint32_t get_page(uint32_t addr) { - return (addr - FLASH_BASE) / FLASH_PAGE_SIZE; + return (addr - FLASH_LAYOUT_START_ADDR) / FLASH_LAYOUT_SECTOR_SIZE; } static uint32_t get_bank(uint32_t addr) { // no bank swap - if (addr < (FLASH_BASE + FLASH_BANK_SIZE)) { + if (addr < (FLASH_LAYOUT_START_ADDR + FLASH_BANK_SIZE)) { return FLASH_BANK_1; } else { #if defined(FLASH_OPTR_DBANK) @@ -212,13 +221,33 @@ static uint32_t get_bank(uint32_t addr) { #endif bool flash_is_valid_addr(uint32_t addr) { + #if FLASH_LAYOUT_IS_HOMOGENEOUS + uint32_t base = FLASH_LAYOUT_START_ADDR; + uint32_t end_of_flash = FLASH_LAYOUT_START_ADDR + FLASH_LAYOUT_NUM_SECTORS * FLASH_LAYOUT_SECTOR_SIZE; + #else + uint32_t base = flash_layout[0].base_address; uint8_t last = MP_ARRAY_SIZE(flash_layout) - 1; uint32_t end_of_flash = flash_layout[last].base_address + flash_layout[last].sector_count * flash_layout[last].sector_size; - return flash_layout[0].base_address <= addr && addr < end_of_flash; + #endif + return base <= addr && addr < end_of_flash; } int32_t flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *size) { + #if FLASH_LAYOUT_IS_HOMOGENEOUS + if (addr >= FLASH_LAYOUT_START_ADDR) { + uint32_t sector_index = (addr - FLASH_LAYOUT_START_ADDR) / FLASH_LAYOUT_SECTOR_SIZE; + if (sector_index < FLASH_LAYOUT_NUM_SECTORS) { + if (start_addr != NULL) { + *start_addr = FLASH_LAYOUT_START_ADDR + sector_index * FLASH_LAYOUT_SECTOR_SIZE; + } + if (size != NULL) { + *size = FLASH_LAYOUT_SECTOR_SIZE; + } + return sector_index; + } + } + #else if (addr >= flash_layout[0].base_address) { uint32_t sector_index = 0; for (int i = 0; i < MP_ARRAY_SIZE(flash_layout); ++i) { @@ -239,6 +268,7 @@ int32_t flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *siz } } } + #endif return -1; } From b6ab9e420b0a874eb2f8f6b7597430ed9e526bf7 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 1 Nov 2023 19:12:09 +1100 Subject: [PATCH 029/408] stm32/flash: Change flash_erase to only erase a single sector at a time. An erase sector sits in a given flash bank and some MCUs have two flash banks. If trying to erase a range of sectors and that range crosses from one flash bank into the next, the original implementation of `flash_erase()` would not handle this case and would do the wrong thing. This commit changes `flash_erase()` to only erase a single sector, which sidesteps the need to handle flash-bank-crossing. Most callers of this function only need to erase a single sector anyway. Signed-off-by: Damien George --- ports/stm32/flash.c | 21 ++++++++++----------- ports/stm32/flash.h | 2 +- ports/stm32/flashbdev.c | 2 +- ports/stm32/mboot/main.c | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/ports/stm32/flash.c b/ports/stm32/flash.c index d9f7af8a24f65..fb1e6059c1fa0 100644 --- a/ports/stm32/flash.c +++ b/ports/stm32/flash.c @@ -272,11 +272,10 @@ int32_t flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *siz return -1; } -int flash_erase(uint32_t flash_dest, uint32_t num_word32) { - // check there is something to write - if (num_word32 == 0) { - return 0; - } +// Erase a single flash page which starts at the given address. +// The address will be converted to a bank and sector number. +int flash_erase(uint32_t flash_dest) { + const unsigned int num_sectors = 1; #if MICROPY_HW_STM32WB_FLASH_SYNCRONISATION // Acquire lock on the flash peripheral. @@ -306,23 +305,23 @@ int flash_erase(uint32_t flash_dest, uint32_t num_word32) { __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR); EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; EraseInitStruct.PageAddress = flash_dest; - EraseInitStruct.NbPages = (4 * num_word32 + FLASH_PAGE_SIZE - 4) / FLASH_PAGE_SIZE; + EraseInitStruct.NbPages = num_sectors; #elif defined(STM32G0) || defined(STM32G4) __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS); EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; EraseInitStruct.Page = get_page(flash_dest); EraseInitStruct.Banks = get_bank(flash_dest); - EraseInitStruct.NbPages = (4 * num_word32 + FLASH_PAGE_SIZE - 4) / FLASH_PAGE_SIZE; + EraseInitStruct.NbPages = num_sectors; #elif defined(STM32L0) || defined(STM32L1) __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR); EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; EraseInitStruct.PageAddress = flash_dest; - EraseInitStruct.NbPages = (4 * num_word32 + FLASH_PAGE_SIZE - 4) / FLASH_PAGE_SIZE; + EraseInitStruct.NbPages = num_sectors; #elif (defined(STM32L4) && !defined(SYSCFG_MEMRMP_FB_MODE)) || defined(STM32WB) || defined(STM32WL) __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS); EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; EraseInitStruct.Page = get_page(flash_dest); - EraseInitStruct.NbPages = (4 * num_word32 + FLASH_PAGE_SIZE - 4) / FLASH_PAGE_SIZE; + EraseInitStruct.NbPages = num_sectors; #elif defined(STM32L4) __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS); // The sector returned by flash_get_sector_info can not be used @@ -330,7 +329,7 @@ int flash_erase(uint32_t flash_dest, uint32_t num_word32) { EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; EraseInitStruct.Banks = get_bank(flash_dest); EraseInitStruct.Page = get_page(flash_dest); - EraseInitStruct.NbPages = get_page(flash_dest + 4 * num_word32 - 1) - EraseInitStruct.Page + 1; + EraseInitStruct.NbPages = num_sectors; #else #if defined(STM32H5) @@ -354,7 +353,7 @@ int flash_erase(uint32_t flash_dest, uint32_t num_word32) { EraseInitStruct.Banks = get_bank(flash_dest); #endif EraseInitStruct.Sector = flash_get_sector_info(flash_dest, NULL, NULL); - EraseInitStruct.NbSectors = flash_get_sector_info(flash_dest + 4 * num_word32 - 1, NULL, NULL) - EraseInitStruct.Sector + 1; + EraseInitStruct.NbSectors = num_sectors; #if defined(STM32H5) EraseInitStruct.Sector &= 0x7f; // second bank should start counting at 0 #endif diff --git a/ports/stm32/flash.h b/ports/stm32/flash.h index ecda923db7826..e5ba35cf7d234 100644 --- a/ports/stm32/flash.h +++ b/ports/stm32/flash.h @@ -28,7 +28,7 @@ bool flash_is_valid_addr(uint32_t addr); int32_t flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *size); -int flash_erase(uint32_t flash_dest, uint32_t num_word32); +int flash_erase(uint32_t flash_dest); int flash_write(uint32_t flash_dest, const uint32_t *src, uint32_t num_word32); #endif // MICROPY_INCLUDED_STM32_FLASH_H diff --git a/ports/stm32/flashbdev.c b/ports/stm32/flashbdev.c index 19edde2108c79..e96c54e791d3f 100644 --- a/ports/stm32/flashbdev.c +++ b/ports/stm32/flashbdev.c @@ -161,7 +161,7 @@ static void flash_bdev_irq_handler(void) { // This code erases the flash directly, waiting for it to finish if (!(flash_flags & FLASH_FLAG_ERASED)) { - flash_erase(flash_cache_sector_start, flash_cache_sector_size / 4); + flash_erase(flash_cache_sector_start); flash_flags |= FLASH_FLAG_ERASED; return; } diff --git a/ports/stm32/mboot/main.c b/ports/stm32/mboot/main.c index 11755308716fb..2424b37da3a8b 100644 --- a/ports/stm32/mboot/main.c +++ b/ports/stm32/mboot/main.c @@ -465,7 +465,7 @@ static int mboot_flash_page_erase(uint32_t addr, uint32_t *next_addr) { } // Erase the flash page. - ret = flash_erase(sector_start, sector_size / sizeof(uint32_t)); + ret = flash_erase(sector_start); if (ret != 0) { return ret; } From cd6e0e1022443e9d099768a2d5cccc8202c80080 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 22 Nov 2023 17:52:27 +1100 Subject: [PATCH 030/408] stm32/flashbdev: Don't rely on flash sector id. This commit removes the need for a separate `flash_cache_sector_id` variable, instead using `flash_cache_sector_start` to indicate which sector is curretly cached (and -1 indicates no sector). Signed-off-by: Damien George --- ports/stm32/flashbdev.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/ports/stm32/flashbdev.c b/ports/stm32/flashbdev.c index e96c54e791d3f..e9542d7a3451e 100644 --- a/ports/stm32/flashbdev.c +++ b/ports/stm32/flashbdev.c @@ -68,7 +68,6 @@ extern uint8_t _micropy_hw_internal_flash_storage_ram_cache_end[]; #define FLASH_FLAG_FORCE_WRITE (2) #define FLASH_FLAG_ERASED (4) static __IO uint8_t flash_flags = 0; -static uint32_t flash_cache_sector_id; static uint32_t flash_cache_sector_start; static uint32_t flash_cache_sector_size; static uint32_t flash_tick_counter_last_write; @@ -80,7 +79,7 @@ int32_t flash_bdev_ioctl(uint32_t op, uint32_t arg) { switch (op) { case BDEV_IOCTL_INIT: flash_flags = 0; - flash_cache_sector_id = 0; + flash_cache_sector_start = (uint32_t)-1; flash_tick_counter_last_write = 0; return 0; @@ -110,14 +109,13 @@ int32_t flash_bdev_ioctl(uint32_t op, uint32_t arg) { static uint8_t *flash_cache_get_addr_for_write(uint32_t flash_addr) { uint32_t flash_sector_start; uint32_t flash_sector_size; - int32_t flash_sector_id = flash_get_sector_info(flash_addr, &flash_sector_start, &flash_sector_size); + flash_get_sector_info(flash_addr, &flash_sector_start, &flash_sector_size); if (flash_sector_size > FLASH_SECTOR_SIZE_MAX) { flash_sector_size = FLASH_SECTOR_SIZE_MAX; } - if (flash_cache_sector_id != flash_sector_id) { + if (flash_cache_sector_start != flash_sector_start) { flash_bdev_ioctl(BDEV_IOCTL_SYNC, 0); memcpy((void *)CACHE_MEM_START_ADDR, (const void *)flash_sector_start, flash_sector_size); - flash_cache_sector_id = flash_sector_id; flash_cache_sector_start = flash_sector_start; flash_cache_sector_size = flash_sector_size; } @@ -130,8 +128,8 @@ static uint8_t *flash_cache_get_addr_for_write(uint32_t flash_addr) { static uint8_t *flash_cache_get_addr_for_read(uint32_t flash_addr) { uint32_t flash_sector_start; uint32_t flash_sector_size; - int32_t flash_sector_id = flash_get_sector_info(flash_addr, &flash_sector_start, &flash_sector_size); - if (flash_cache_sector_id == flash_sector_id) { + flash_get_sector_info(flash_addr, &flash_sector_start, &flash_sector_size); + if (flash_cache_sector_start == flash_sector_start) { // in cache, copy from there return (uint8_t *)CACHE_MEM_START_ADDR + flash_addr - flash_sector_start; } From 5cb93f63fb8555302ae5e4fdfe469ef4aefb0410 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 22 Nov 2023 19:29:09 +1100 Subject: [PATCH 031/408] stm32/flash: Factor and simplify erase code. Signed-off-by: Damien George --- ports/stm32/flash.c | 96 ++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/ports/stm32/flash.c b/ports/stm32/flash.c index fb1e6059c1fa0..22bdf57ec7e0b 100644 --- a/ports/stm32/flash.c +++ b/ports/stm32/flash.c @@ -29,7 +29,17 @@ #include "py/mphal.h" #include "flash.h" -#if defined(STM32G0) +#if defined(STM32F0) + +#define FLASH_FLAG_ALL_ERRORS (FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR) + +#elif defined(STM32F4) + +#define FLASH_FLAG_ALL_ERRORS (FLASH_FLAG_EOP | FLASH_FLAG_OPERR \ + | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR) + +#elif defined(STM32G0) + // These are not defined on the CMSIS header #define FLASH_FLAG_SR_ERRORS (FLASH_FLAG_OPERR | FLASH_FLAG_PROGERR | FLASH_FLAG_WRPERR | \ FLASH_FLAG_PGAERR | FLASH_FLAG_SIZERR | FLASH_FLAG_PGSERR | \ @@ -41,6 +51,15 @@ #define FLASH_FLAG_ECCR_ERRORS (FLASH_FLAG_ECCC | FLASH_FLAG_ECCD) #endif #define FLASH_FLAG_ALL_ERRORS (FLASH_FLAG_SR_ERRORS | FLASH_FLAG_ECCR_ERRORS) + +#elif defined(STM32H7) + +#define FLASH_FLAG_ALL_ERRORS (FLASH_FLAG_ALL_ERRORS_BANK1 | FLASH_FLAG_ALL_ERRORS_BANK2) + +#elif defined(STM32L0) || defined(STM32L1) + +#define FLASH_FLAG_ALL_ERRORS (FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR) + #endif #if MICROPY_HW_STM32WB_FLASH_SYNCRONISATION @@ -93,10 +112,6 @@ static const flash_layout_t flash_layout[] = { #define FLASH_LAYOUT_IS_HOMOGENEOUS (0) -// FLASH_FLAG_PGSERR (Programming Sequence Error) was renamed to -// FLASH_FLAG_ERSERR (Erasing Sequence Error) in STM32F7 -#define FLASH_FLAG_PGSERR FLASH_FLAG_ERSERR - #if defined(STM32F722xx) || defined(STM32F723xx) || defined(STM32F732xx) || defined(STM32F733xx) static const flash_layout_t flash_layout[] = { { 0x08000000, 0x04000, 4 }, @@ -298,66 +313,51 @@ int flash_erase(uint32_t flash_dest) { } #endif - // Clear pending flags (if any) and set up EraseInitStruct. + // Clear pending flags (if any). + __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS); + // Set up EraseInitStruct... FLASH_EraseInitTypeDef EraseInitStruct; - #if defined(STM32F0) - __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR); - EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; - EraseInitStruct.PageAddress = flash_dest; - EraseInitStruct.NbPages = num_sectors; - #elif defined(STM32G0) || defined(STM32G4) - __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS); - EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; - EraseInitStruct.Page = get_page(flash_dest); - EraseInitStruct.Banks = get_bank(flash_dest); - EraseInitStruct.NbPages = num_sectors; - #elif defined(STM32L0) || defined(STM32L1) - __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR); - EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; - EraseInitStruct.PageAddress = flash_dest; - EraseInitStruct.NbPages = num_sectors; - #elif (defined(STM32L4) && !defined(SYSCFG_MEMRMP_FB_MODE)) || defined(STM32WB) || defined(STM32WL) - __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS); - EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; - EraseInitStruct.Page = get_page(flash_dest); - EraseInitStruct.NbPages = num_sectors; - #elif defined(STM32L4) - __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS); - // The sector returned by flash_get_sector_info can not be used - // as the flash has on each bank 0/1 pages 0..255 + + // ... the erase type and number of pages/sectors, + #if defined(STM32F0) || defined(STM32G0) || defined(STM32G4) || defined(STM32L0) \ + || defined(STM32L1) || defined(STM32L4) || defined(STM32WB) || defined(STM32WL) + EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; - EraseInitStruct.Banks = get_bank(flash_dest); - EraseInitStruct.Page = get_page(flash_dest); EraseInitStruct.NbPages = num_sectors; - #else - #if defined(STM32H5) - __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS); - #elif defined(STM32H7) - __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS_BANK1 | FLASH_FLAG_ALL_ERRORS_BANK2); - #elif defined(STM32L1) - __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR); - #else - __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | - FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR); - #endif + #elif defined(STM32F4) || defined(STM32F7) || defined(STM32H5) || defined(STM32H7) EraseInitStruct.TypeErase = TYPEERASE_SECTORS; + EraseInitStruct.NbSectors = num_sectors; #if defined(FLASH_CR_PSIZE) EraseInitStruct.VoltageRange = VOLTAGE_RANGE_3; // voltage range needs to be 2.7V to 3.6V #elif !defined(STM32H5) EraseInitStruct.VoltageRange = 0; // unused parameter on STM32H7A3/B3 #endif - #if defined(STM32G0) || defined(STM32G4) || defined(STM32H5) || defined(STM32H7) - EraseInitStruct.Banks = get_bank(flash_dest); + + #else + #error Unsupported processor #endif + + // ... and the flash bank and page/sector. + #if defined(STM32F0) || defined(STM32L0) || defined(STM32L1) + EraseInitStruct.PageAddress = flash_dest; + #elif defined(STM32G0) || defined(STM32G4) || (defined(STM32L4) && defined(SYSCFG_MEMRMP_FB_MODE)) + EraseInitStruct.Page = get_page(flash_dest); + EraseInitStruct.Banks = get_bank(flash_dest); + #elif (defined(STM32L4) && !defined(SYSCFG_MEMRMP_FB_MODE)) || defined(STM32WB) || defined(STM32WL) + EraseInitStruct.Page = get_page(flash_dest); + #elif defined(STM32F4) || defined(STM32F7) + EraseInitStruct.Sector = flash_get_sector_info(flash_dest, NULL, NULL); + #elif defined(STM32H5) || defined(STM32H7) + EraseInitStruct.Banks = get_bank(flash_dest); EraseInitStruct.Sector = flash_get_sector_info(flash_dest, NULL, NULL); - EraseInitStruct.NbSectors = num_sectors; #if defined(STM32H5) EraseInitStruct.Sector &= 0x7f; // second bank should start counting at 0 #endif - + #else + #error Unsupported processor #endif // Erase the sectors. From 7ecff515d7fcb1087a621198f939cc99b1c914b6 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 23 Nov 2023 10:29:28 +1100 Subject: [PATCH 032/408] stm32/flash: Fix sector and bank calculation for H5 and H7 MCUs. Flash sectors should start counting at 0 for each bank. This commit makes sure that is the case on all H5 and H7 MCUs, by using `get_page()` instead of `flash_get_sector_info()`. Signed-off-by: Damien George --- ports/stm32/flash.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ports/stm32/flash.c b/ports/stm32/flash.c index 22bdf57ec7e0b..10c5f296a28c8 100644 --- a/ports/stm32/flash.c +++ b/ports/stm32/flash.c @@ -163,13 +163,18 @@ static const flash_layout_t flash_layout[] = { #error Unsupported processor #endif -#if defined(STM32H723xx) || defined(STM32H750xx) +#if defined(STM32H7) && !defined(DUAL_BANK) // get the bank of a given flash address static uint32_t get_bank(uint32_t addr) { return FLASH_BANK_1; } +// get the page of a given flash address +static uint32_t get_page(uint32_t addr) { + return (addr - FLASH_LAYOUT_START_ADDR) / FLASH_LAYOUT_SECTOR_SIZE; +} + #elif (defined(STM32L4) && defined(SYSCFG_MEMRMP_FB_MODE)) || defined(STM32H5) || defined(STM32H7) // get the bank of a given flash address @@ -195,7 +200,6 @@ static uint32_t get_bank(uint32_t addr) { } } -#if (defined(STM32L4) && defined(SYSCFG_MEMRMP_FB_MODE)) // get the page of a given flash address static uint32_t get_page(uint32_t addr) { if (addr < (FLASH_LAYOUT_START_ADDR + FLASH_BANK_SIZE)) { @@ -206,7 +210,6 @@ static uint32_t get_page(uint32_t addr) { return (addr - (FLASH_LAYOUT_START_ADDR + FLASH_BANK_SIZE)) / FLASH_LAYOUT_SECTOR_SIZE; } } -#endif #elif (defined(STM32L4) && !defined(SYSCFG_MEMRMP_FB_MODE)) || defined(STM32WB) || defined(STM32WL) @@ -352,10 +355,7 @@ int flash_erase(uint32_t flash_dest) { EraseInitStruct.Sector = flash_get_sector_info(flash_dest, NULL, NULL); #elif defined(STM32H5) || defined(STM32H7) EraseInitStruct.Banks = get_bank(flash_dest); - EraseInitStruct.Sector = flash_get_sector_info(flash_dest, NULL, NULL); - #if defined(STM32H5) - EraseInitStruct.Sector &= 0x7f; // second bank should start counting at 0 - #endif + EraseInitStruct.Sector = get_page(flash_dest); #else #error Unsupported processor #endif From e456ee40e0df65ccda628ecce010c558bb44ca72 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 5 Jan 2024 16:41:07 +1100 Subject: [PATCH 033/408] samd/mpconfigport: Simplify and consolidate config options. This is a no-op in terms of firmware functionality. Signed-off-by: Damien George --- ports/samd/mcu/samd21/mpconfigmcu.h | 40 ++++++++++++++++++---------- ports/samd/mcu/samd51/mpconfigmcu.h | 15 ----------- ports/samd/mpconfigport.h | 41 ++++++----------------------- 3 files changed, 34 insertions(+), 62 deletions(-) diff --git a/ports/samd/mcu/samd21/mpconfigmcu.h b/ports/samd/mcu/samd21/mpconfigmcu.h index 35e59a6706cdd..8e4071b649715 100644 --- a/ports/samd/mcu/samd21/mpconfigmcu.h +++ b/ports/samd/mcu/samd21/mpconfigmcu.h @@ -14,20 +14,32 @@ #define MICROPY_EMIT_THUMB_ARMV7M (0) #define MICROPY_MODULE_BUILTIN_INIT (1) -#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT) - -#ifndef MICROPY_PY_MATH -#define MICROPY_PY_MATH (1) -#define MP_NEED_LOG2 (1) -#endif - -#ifndef MICROPY_PY_BUILTINS_COMPLEX -#define MICROPY_PY_BUILTINS_COMPLEX (0) -#endif - -#ifndef MICROPY_PY_CMATH -#define MICROPY_PY_CMATH (0) -#endif +// Selected extensions beyond the basic features set. +#define MICROPY_ENABLE_FINALISER (1) +#define MICROPY_KBD_EXCEPTION (1) +#define MICROPY_HELPER_REPL (1) +#define MICROPY_REPL_AUTO_INDENT (1) +#define MICROPY_ENABLE_SOURCE_LINE (1) +#define MICROPY_STREAMS_NON_BLOCK (1) +#define MICROPY_PY_BUILTINS_HELP (1) +#define MICROPY_PY_BUILTINS_HELP_MODULES (1) +#define MICROPY_ENABLE_SCHEDULER (1) +#define MICROPY_PY_BUILTINS_BYTES_HEX (1) +#define MICROPY_PY_BUILTINS_MEMORYVIEW (1) +#define MICROPY_PY_BUILTINS_INPUT (1) +#define MICROPY_PY_MICROPYTHON_MEM_INFO (1) +#define MICROPY_PY_ARRAY_SLICE_ASSIGN (1) +#define MICROPY_PY_SYS_STDFILES (1) +#define MICROPY_PY_SYS_MAXSIZE (1) +#define MICROPY_PY_IO_IOBASE (1) +#define MICROPY_PY_OS (1) +#define MICROPY_PY_JSON (1) +#define MICROPY_PY_RE (1) +#define MICROPY_PY_BINASCII (1) +#define MICROPY_PY_UCTYPES (1) +#define MICROPY_PY_HEAPQ (1) +#define MICROPY_PY_RANDOM (1) +#define MICROPY_PY_PLATFORM (1) #define MICROPY_PY_RANDOM_SEED_INIT_FUNC (trng_random_u32(300)) unsigned long trng_random_u32(int delay); diff --git a/ports/samd/mcu/samd51/mpconfigmcu.h b/ports/samd/mcu/samd51/mpconfigmcu.h index b8206558b4676..d567f28eb423a 100644 --- a/ports/samd/mcu/samd51/mpconfigmcu.h +++ b/ports/samd/mcu/samd51/mpconfigmcu.h @@ -10,21 +10,6 @@ // Python internal features #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1) -#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT) - -#ifndef MICROPY_PY_BUILTINS_COMPLEX -#define MICROPY_PY_BUILTINS_COMPLEX (0) -#endif - -#ifndef MICROPY_PY_MATH -#define MICROPY_PY_MATH (1) -#define MP_NEED_LOG2 (1) -#endif - -#ifndef MICROPY_PY_CMATH -#define MICROPY_PY_CMATH (0) -#endif - #define MICROPY_PY_OS_SYNC (1) #define MICROPY_PY_OS_URANDOM (1) #define MICROPY_PY_ONEWIRE (1) diff --git a/ports/samd/mpconfigport.h b/ports/samd/mpconfigport.h index a7a6e26629272..218e4bb96ab3d 100644 --- a/ports/samd/mpconfigport.h +++ b/ports/samd/mpconfigport.h @@ -40,25 +40,18 @@ // MicroPython emitters #define MICROPY_PERSISTENT_CODE_LOAD (1) -// Compiler configuration -#define MICROPY_COMP_CONST (1) - // Python internal features #define MICROPY_ENABLE_GC (1) -#define MICROPY_ENABLE_FINALISER (1) -#define MICROPY_KBD_EXCEPTION (1) -#define MICROPY_HELPER_REPL (1) -#define MICROPY_REPL_AUTO_INDENT (1) #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ) -#define MICROPY_ENABLE_SOURCE_LINE (1) -#define MICROPY_STREAMS_NON_BLOCK (1) +#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT) +#ifndef MICROPY_PY_BUILTINS_COMPLEX +#define MICROPY_PY_BUILTINS_COMPLEX (0) +#endif #define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_TERSE) -#define MICROPY_PY_BUILTINS_HELP (1) #define MICROPY_PY_BUILTINS_HELP_TEXT samd_help_text -#define MICROPY_PY_BUILTINS_HELP_MODULES (1) #define MICROPY_USE_INTERNAL_ERRNO (1) -#define MICROPY_ENABLE_SCHEDULER (1) #define MICROPY_SCHEDULER_STATIC_NODES (1) + #define MICROPY_HW_ENABLE_USBDEV (1) #define MICROPY_HW_USB_CDC_1200BPS_TOUCH (1) @@ -71,22 +64,9 @@ #ifndef MICROPY_HW_USB_DESC_STR_MAX #define MICROPY_HW_USB_DESC_STR_MAX (32) #endif - #endif -// Control over Python builtins -#define MICROPY_PY_BUILTINS_BYTES_HEX (1) -#define MICROPY_PY_BUILTINS_MEMORYVIEW (1) -#define MICROPY_PY_BUILTINS_INPUT (1) -#define MICROPY_PY_MICROPYTHON_MEM_INFO (1) -#define MICROPY_PY_ARRAY_SLICE_ASSIGN (1) -#define MICROPY_PY_SYS (1) #define MICROPY_PY_SYS_PLATFORM "samd" -#define MICROPY_PY_SYS_EXIT (1) -#define MICROPY_PY_SYS_STDFILES (1) -#define MICROPY_PY_SYS_MAXSIZE (1) -#define MICROPY_PY_IO (1) -#define MICROPY_PY_IO_IOBASE (1) // Extended modules #define MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME (1) @@ -97,16 +77,9 @@ #define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1) #define MICROPY_PY_MACHINE_BOOTLOADER (1) #define MICROPY_PY_MACHINE_DISABLE_IRQ_ENABLE_IRQ (1) -#define MICROPY_PY_OS (1) #define MICROPY_PY_OS_INCLUDEFILE "ports/samd/modos.c" #define MICROPY_READER_VFS (1) #define MICROPY_VFS (1) -#define MICROPY_PY_JSON (1) -#define MICROPY_PY_RE (1) -#define MICROPY_PY_BINASCII (1) -#define MICROPY_PY_UCTYPES (1) -#define MICROPY_PY_HEAPQ (1) -#define MICROPY_PY_RANDOM (1) #ifndef MICROPY_PY_MACHINE_ADC #define MICROPY_PY_MACHINE_ADC (1) #endif @@ -148,7 +121,6 @@ #define MICROPY_PY_MACHINE_WDT (1) #define MICROPY_PY_MACHINE_WDT_INCLUDEFILE "ports/samd/machine_wdt.c" #define MICROPY_PY_MACHINE_WDT_TIMEOUT_MS (1) -#define MICROPY_PY_PLATFORM (1) #define MICROPY_PLATFORM_VERSION "ASF4" #define MP_STATE_PORT MP_STATE_VM @@ -188,5 +160,8 @@ typedef int mp_int_t; // must be pointer size typedef unsigned mp_uint_t; // must be pointer size typedef long mp_off_t; +// Need an implementation of the log2 function which is not a macro. +#define MP_NEED_LOG2 (1) + // Need to provide a declaration/definition of alloca() #include From 2ed976f1406e33a266d25cb6505020c76746ecbc Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 5 Jan 2024 16:54:33 +1100 Subject: [PATCH 034/408] samd/mcu/samd21: Enable MICROPY_STACK_CHECK on SAMD21. Increases firmware size by +140 bytes and uses +4 extra bytes of RAM, but allows the test suite to run without crashing. Signed-off-by: Damien George --- ports/samd/mcu/samd21/mpconfigmcu.h | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/samd/mcu/samd21/mpconfigmcu.h b/ports/samd/mcu/samd21/mpconfigmcu.h index 8e4071b649715..fdad3fee4a71b 100644 --- a/ports/samd/mcu/samd21/mpconfigmcu.h +++ b/ports/samd/mcu/samd21/mpconfigmcu.h @@ -16,6 +16,7 @@ // Selected extensions beyond the basic features set. #define MICROPY_ENABLE_FINALISER (1) +#define MICROPY_STACK_CHECK (1) #define MICROPY_KBD_EXCEPTION (1) #define MICROPY_HELPER_REPL (1) #define MICROPY_REPL_AUTO_INDENT (1) From ba4330ba102ac1d61e2e0e29ad2c2f361b9109c0 Mon Sep 17 00:00:00 2001 From: stijn Date: Thu, 24 Aug 2023 13:11:42 +0200 Subject: [PATCH 035/408] tests/run-tests.py: Remove unneeded argument from run_feature_check(). In 405893af this was likely left as-is to minimize the diff, but it just complicates things. Signed-off-by: stijn --- tests/run-tests.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/run-tests.py b/tests/run-tests.py index 32333857f1cb7..cae5708087fdc 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -360,7 +360,7 @@ def send_get(what): return output_mupy -def run_feature_check(pyb, args, base_path, test_file): +def run_feature_check(pyb, args, test_file): if pyb is not None and test_file.startswith("repl_"): # REPL feature tests will not run via pyboard because they require prompt interactivity return b"" @@ -419,57 +419,57 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): # run-tests.py script itself so use base_path. # Check if micropython.native is supported, and skip such tests if it's not - output = run_feature_check(pyb, args, base_path, "native_check.py") + output = run_feature_check(pyb, args, "native_check.py") if output != b"native\n": skip_native = True # Check if arbitrary-precision integers are supported, and skip such tests if it's not - output = run_feature_check(pyb, args, base_path, "int_big.py") + output = run_feature_check(pyb, args, "int_big.py") if output != b"1000000000000000000000000000000000000000000000\n": skip_int_big = True # Check if bytearray is supported, and skip such tests if it's not - output = run_feature_check(pyb, args, base_path, "bytearray.py") + output = run_feature_check(pyb, args, "bytearray.py") if output != b"bytearray\n": skip_bytearray = True # Check if set type (and set literals) is supported, and skip such tests if it's not - output = run_feature_check(pyb, args, base_path, "set_check.py") + output = run_feature_check(pyb, args, "set_check.py") if output != b"{1}\n": skip_set_type = True # Check if slice is supported, and skip such tests if it's not - output = run_feature_check(pyb, args, base_path, "slice.py") + output = run_feature_check(pyb, args, "slice.py") if output != b"slice\n": skip_slice = True # Check if async/await keywords are supported, and skip such tests if it's not - output = run_feature_check(pyb, args, base_path, "async_check.py") + output = run_feature_check(pyb, args, "async_check.py") if output != b"async\n": skip_async = True # Check if const keyword (MicroPython extension) is supported, and skip such tests if it's not - output = run_feature_check(pyb, args, base_path, "const.py") + output = run_feature_check(pyb, args, "const.py") if output != b"1\n": skip_const = True # Check if __rOP__ special methods are supported, and skip such tests if it's not - output = run_feature_check(pyb, args, base_path, "reverse_ops.py") + output = run_feature_check(pyb, args, "reverse_ops.py") if output == b"TypeError\n": skip_revops = True # Check if io module exists, and skip such tests if it doesn't - output = run_feature_check(pyb, args, base_path, "io_module.py") + output = run_feature_check(pyb, args, "io_module.py") if output != b"io\n": skip_io_module = True # Check if fstring feature is enabled, and skip such tests if it doesn't - output = run_feature_check(pyb, args, base_path, "fstring.py") + output = run_feature_check(pyb, args, "fstring.py") if output != b"a=1\n": skip_fstring = True # Check if @micropython.asm_thumb supports Thumb2 instructions, and skip such tests if it doesn't - output = run_feature_check(pyb, args, base_path, "inlineasm_thumb2.py") + output = run_feature_check(pyb, args, "inlineasm_thumb2.py") if output != b"thumb2\n": skip_tests.add("inlineasm/asmbcc.py") skip_tests.add("inlineasm/asmbitops.py") @@ -484,23 +484,23 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): skip_tests.add("inlineasm/asmspecialregs.py") # Check if emacs repl is supported, and skip such tests if it's not - t = run_feature_check(pyb, args, base_path, "repl_emacs_check.py") + t = run_feature_check(pyb, args, "repl_emacs_check.py") if "True" not in str(t, "ascii"): skip_tests.add("cmdline/repl_emacs_keys.py") # Check if words movement in repl is supported, and skip such tests if it's not - t = run_feature_check(pyb, args, base_path, "repl_words_move_check.py") + t = run_feature_check(pyb, args, "repl_words_move_check.py") if "True" not in str(t, "ascii"): skip_tests.add("cmdline/repl_words_move.py") - upy_byteorder = run_feature_check(pyb, args, base_path, "byteorder.py") - upy_float_precision = run_feature_check(pyb, args, base_path, "float.py") + upy_byteorder = run_feature_check(pyb, args, "byteorder.py") + upy_float_precision = run_feature_check(pyb, args, "float.py") try: upy_float_precision = int(upy_float_precision) except ValueError: upy_float_precision = 0 - has_complex = run_feature_check(pyb, args, base_path, "complex.py") == b"complex\n" - has_coverage = run_feature_check(pyb, args, base_path, "coverage.py") == b"coverage\n" + has_complex = run_feature_check(pyb, args, "complex.py") == b"complex\n" + has_coverage = run_feature_check(pyb, args, "coverage.py") == b"coverage\n" cpy_byteorder = subprocess.check_output( CPYTHON3_CMD + [base_path("feature_check/byteorder.py")] ) From 88d21f186bc8ca9ef9728a36f5ca27731f2d86bc Mon Sep 17 00:00:00 2001 From: stijn Date: Thu, 24 Aug 2023 13:15:23 +0200 Subject: [PATCH 036/408] tests/run-tests.py: Make repl test detection more correct. Avoid unrelated tests which happen to have "repl_" anywhere in their path to be treated as repl tests. Signed-off-by: stijn --- tests/run-tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run-tests.py b/tests/run-tests.py index cae5708087fdc..8fe97be6cc8e8 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -205,7 +205,7 @@ def run_micropython(pyb, args, test_file, is_special=False): # run the test, possibly with redirected input try: - if "repl_" in test_file: + if os.path.basename(test_file).startswith("repl_"): # Need to use a PTY to test command line editing try: import pty From bd21820b4cc7d3c6c293b2fd104cb8214df686cd Mon Sep 17 00:00:00 2001 From: stijn Date: Thu, 24 Aug 2023 13:29:58 +0200 Subject: [PATCH 037/408] tests/run-tests.py: Fix path-based special test detection. Compare the full absolute path instead of relying on the path form passed by the user. For instance, this will make python3 run-tests.py -d basics python3 run-tests.py -d ./basics python3 run-tests.py -d ../tests/basics python3 run-tests.py -d /full/path/to/basics all behave the same by correctly treating the bytes_compare3 and builtin_help tests as special, whereas previously only the first invocation would do that and hence result in these tests to fail when called with a different path form. Signed-off-by: stijn --- tests/run-tests.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/tests/run-tests.py b/tests/run-tests.py index 8fe97be6cc8e8..4d4c2543b2f59 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -176,20 +176,25 @@ def run_script_on_remote_target(pyb, args, test_file, is_special): return had_crash, output_mupy -def run_micropython(pyb, args, test_file, is_special=False): - special_tests = ( +special_tests = [ + base_path(file) + for file in ( "micropython/meminfo.py", "basics/bytes_compare3.py", "basics/builtin_help.py", "thread/thread_exc2.py", "esp32/partition_ota.py", ) +] + + +def run_micropython(pyb, args, test_file, test_file_abspath, is_special=False): had_crash = False if pyb is None: # run on PC if ( - test_file.startswith(("cmdline/", base_path("feature_check/"))) - or test_file in special_tests + test_file_abspath.startswith((base_path("cmdline/"), base_path("feature_check/"))) + or test_file_abspath in special_tests ): # special handling for tests of the unix cmdline program is_special = True @@ -283,7 +288,7 @@ def send_get(what): mpy_modname = os.path.splitext(os.path.basename(mpy_filename))[0] cmdlist.extend(["-m", mpy_modname]) else: - cmdlist.append(os.path.abspath(test_file)) + cmdlist.append(test_file_abspath) # run the actual test try: @@ -316,7 +321,7 @@ def send_get(what): if is_special and not had_crash and b"\nSKIP\n" in output_mupy: return b"SKIP\n" - if is_special or test_file in special_tests: + if is_special or test_file_abspath in special_tests: # convert parts of the output that are not stable across runs with open(test_file + ".exp", "rb") as f: lines_exp = [] @@ -364,7 +369,8 @@ def run_feature_check(pyb, args, test_file): if pyb is not None and test_file.startswith("repl_"): # REPL feature tests will not run via pyboard because they require prompt interactivity return b"" - return run_micropython(pyb, args, base_path("feature_check", test_file), is_special=True) + test_file_path = base_path("feature_check", test_file) + return run_micropython(pyb, args, test_file_path, test_file_path, is_special=True) class ThreadSafeCounter: @@ -673,6 +679,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): def run_one_test(test_file): test_file = test_file.replace("\\", "/") + test_file_abspath = os.path.abspath(test_file).replace("\\", "/") if args.filters: # Default verdict is the opposit of the first action @@ -733,7 +740,7 @@ def run_one_test(test_file): # run CPython to work out expected output try: output_expected = subprocess.check_output( - CPYTHON3_CMD + [os.path.abspath(test_file)], + CPYTHON3_CMD + [test_file_abspath], cwd=os.path.dirname(test_file), stderr=subprocess.STDOUT, ) @@ -750,7 +757,7 @@ def run_one_test(test_file): return # run MicroPython - output_mupy = run_micropython(pyb, args, test_file) + output_mupy = run_micropython(pyb, args, test_file, test_file_abspath) if output_mupy == b"SKIP\n": print("skip ", test_file) From 07472d05db64a0990b4d47cb001d1a40ba78414f Mon Sep 17 00:00:00 2001 From: robert-hh Date: Sun, 7 Jan 2024 17:53:53 +0100 Subject: [PATCH 038/408] rp2/machine_uart: Fix event wait in uart.flush() and uart.read(). Do not wait in the worst case up to the timeout. Fixes issue #13377. Signed-off-by: robert-hh --- ports/rp2/machine_uart.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/rp2/machine_uart.c b/ports/rp2/machine_uart.c index d751b7af07a2e..bca07cebfcbf3 100644 --- a/ports/rp2/machine_uart.c +++ b/ports/rp2/machine_uart.c @@ -483,7 +483,7 @@ STATIC mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t return i; } } - mp_event_wait_ms(timeout - elapsed); + mp_event_handle_nowait(); } *dest++ = ringbuf_get(&(self->read_buffer)); start = mp_hal_ticks_ms(); // Inter-character timeout @@ -559,7 +559,7 @@ STATIC mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uint if (now >= timeout) { break; } - mp_event_wait_ms((timeout - now) / 1000); + mp_event_handle_nowait(); } *errcode = MP_ETIMEDOUT; ret = MP_STREAM_ERROR; From c41b421d48a86ed1c1406123e7ee6d084e462afa Mon Sep 17 00:00:00 2001 From: robert-hh Date: Mon, 8 Jan 2024 09:25:33 +0100 Subject: [PATCH 039/408] tests/extmod/machine_uart_tx.py: Add a test for timing of UART.flush(). Currently only runs on rp2 but could be extended to run on other targets. Signed-off-by: robert-hh --- tests/extmod/machine_uart_tx.py | 34 +++++++++++++++++++++++++++++ tests/extmod/machine_uart_tx.py.exp | 3 +++ 2 files changed, 37 insertions(+) create mode 100644 tests/extmod/machine_uart_tx.py create mode 100644 tests/extmod/machine_uart_tx.py.exp diff --git a/tests/extmod/machine_uart_tx.py b/tests/extmod/machine_uart_tx.py new file mode 100644 index 0000000000000..54c0af2b2314e --- /dev/null +++ b/tests/extmod/machine_uart_tx.py @@ -0,0 +1,34 @@ +# Test machine.UART transmission. +# Does not require any external connections. + +try: + from machine import UART +except ImportError: + print("SKIP") + raise SystemExit + +import time, sys + +# Configure pins based on the target. +if "rp2" in sys.platform: + uart_id = 0 + tx_pin = "GPIO0" + rx_pin = "GPIO1" +else: + print("SKIP") + raise SystemExit + +# Test that write+flush takes the expected amount of time to execute. +for bits_per_s in (2400, 9600, 115200): + text = "Hello World" + uart = UART(uart_id, bits_per_s, bits=8, parity=None, stop=1, tx=tx_pin, rx=rx_pin) + + start_us = time.ticks_us() + uart.write(text) + uart.flush() + duration_us = time.ticks_diff(time.ticks_us(), start_us) + + # 1(startbit) + 8(bits) + 1(stopbit) + 0(parity) + bits_per_char = 10 + expect_us = (len(text)) * bits_per_char * 1_000_000 // bits_per_s + print(bits_per_s, duration_us <= expect_us) diff --git a/tests/extmod/machine_uart_tx.py.exp b/tests/extmod/machine_uart_tx.py.exp new file mode 100644 index 0000000000000..0432ab94aee97 --- /dev/null +++ b/tests/extmod/machine_uart_tx.py.exp @@ -0,0 +1,3 @@ +2400 True +9600 True +115200 True From f9df08d8ee29145b547d7bf37a7977aa465c437c Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 16 Jan 2024 11:12:12 +1100 Subject: [PATCH 040/408] docs/develop/porting: Fix argument type of mp_lexer_new_from_file(). Follow up to 5015779a6f4a180233a78ec8b5fd1ea095057a91. Signed-off-by: Damien George --- docs/develop/porting.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/develop/porting.rst b/docs/develop/porting.rst index 63919b97a6ccd..09e61d5d9bfe0 100644 --- a/docs/develop/porting.rst +++ b/docs/develop/porting.rst @@ -83,7 +83,7 @@ The basic MicroPython firmware is implemented in the main port file, e.g ``main. } // There is no filesystem so opening a file raises an exception. - mp_lexer_t *mp_lexer_new_from_file(const char *filename) { + mp_lexer_t *mp_lexer_new_from_file(qstr filename) { mp_raise_OSError(MP_ENOENT); } From a70367e293a2293918a3649dc8c6f875c39543cd Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 16 Jan 2024 11:13:22 +1100 Subject: [PATCH 041/408] nrf/modules/os/microbitfs: Sweep the filesystem if any free chunk found. If there are any free chunks found then it's better to sweep the filesystem and use the available chunks, rather than error out with ENOSPC when there is in fact a bit of space remaining. Signed-off-by: Damien George --- ports/nrf/modules/os/microbitfs.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/ports/nrf/modules/os/microbitfs.c b/ports/nrf/modules/os/microbitfs.c index 5ffe837efea6e..bc007c161f340 100644 --- a/ports/nrf/modules/os/microbitfs.c +++ b/ports/nrf/modules/os/microbitfs.c @@ -80,10 +80,6 @@ /** Must be such that sizeof(file_header) < DATA_PER_CHUNK */ #define MAX_FILENAME_LENGTH 120 -//Minimum number of free chunks to justify sweeping. -//If this is too low it may cause excessive wear -#define MIN_CHUNKS_FOR_SWEEP (FLASH_PAGESIZE / CHUNK_SIZE) - #define FILE_NOT_FOUND ((uint8_t)-1) /** Maximum number of chunks allowed in filesystem. 252 chunks is 31.5kB */ @@ -268,9 +264,9 @@ STATIC uint8_t microbit_find_file(const char *name, int name_len) { // Search the chunks: // 1 If an UNUSED chunk is found, then return that. // 2. If an entire page of FREED chunks is found, then erase the page and return the first chunk -// 3. If the number of FREED chunks is >= MIN_CHUNKS_FOR_SWEEP, then +// 3. If the number of FREED chunks is > 0, then // 3a. Sweep the filesystem and restart. -// 3b. Fail and return FILE_NOT_FOUND +// 3b. Otherwise, fail and return FILE_NOT_FOUND. // STATIC uint8_t find_chunk_and_erase(void) { // Start search at a random chunk to spread the wear more evenly. @@ -311,7 +307,7 @@ STATIC uint8_t find_chunk_and_erase(void) { if (index == chunks_in_file_system+1) index = 1; } while (index != start_index); DEBUG(("FILE DEBUG: %lu free chunks\r\n", freed_chunks)); - if (freed_chunks < MIN_CHUNKS_FOR_SWEEP) { + if (freed_chunks == 0) { return FILE_NOT_FOUND; } // No freed pages, so sweep file system. From efa54c27b9eab3b61319e7f16d05db0ac3b6bc14 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 16 Jan 2024 11:36:27 +1100 Subject: [PATCH 042/408] rp2/mpconfigport: Allow MICROPY_PY_THREAD to be disabled by a board. Signed-off-by: Damien George --- ports/rp2/mpconfigport.h | 2 ++ ports/rp2/mphalport.h | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/ports/rp2/mpconfigport.h b/ports/rp2/mpconfigport.h index ce89763d5ea58..8f073002e8632 100644 --- a/ports/rp2/mpconfigport.h +++ b/ports/rp2/mpconfigport.h @@ -89,9 +89,11 @@ // Fine control over Python builtins, classes, modules, etc #define MICROPY_PY_BUILTINS_HELP_TEXT rp2_help_text #define MICROPY_PY_SYS_PLATFORM "rp2" +#ifndef MICROPY_PY_THREAD #define MICROPY_PY_THREAD (1) #define MICROPY_PY_THREAD_GIL (0) #define MICROPY_THREAD_YIELD() mp_handle_pending(true) +#endif // Extended modules #define MICROPY_EPOCH_IS_1970 (1) diff --git a/ports/rp2/mphalport.h b/ports/rp2/mphalport.h index c8e2301a92ea9..d2d74d783a628 100644 --- a/ports/rp2/mphalport.h +++ b/ports/rp2/mphalport.h @@ -37,8 +37,13 @@ #define MICROPY_HW_USB_CDC_TX_TIMEOUT (500) // Entering a critical section. +#if MICROPY_PY_THREAD #define MICROPY_BEGIN_ATOMIC_SECTION() mp_thread_begin_atomic_section() #define MICROPY_END_ATOMIC_SECTION(state) mp_thread_end_atomic_section(state) +#else +#define MICROPY_BEGIN_ATOMIC_SECTION() save_and_disable_interrupts() +#define MICROPY_END_ATOMIC_SECTION(state) restore_interrupts(state) +#endif #define MICROPY_PY_PENDSV_ENTER pendsv_suspend() #define MICROPY_PY_PENDSV_EXIT pendsv_resume() From bdaea866b712c85d3bffaaae147c9b3470a4f896 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Fri, 12 Jan 2024 09:47:48 +1100 Subject: [PATCH 043/408] rp2/mpthreadport: Make result of thread.get_ident() a non-zero integer. CPython says thread identifier is a "nonzero integer", so rp2 should use a 1-indexed core number rather than 0-indexed. This fixes the thread/thread_ident1 test failure on rp2 port. Unfortunately this may be a breaking change for rp2 code which makes a hard-coded comparison of thread identifier to 0 or 1. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- ports/rp2/mpthreadport.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ports/rp2/mpthreadport.c b/ports/rp2/mpthreadport.c index fd868329c38d5..977df80449b1e 100644 --- a/ports/rp2/mpthreadport.c +++ b/ports/rp2/mpthreadport.c @@ -115,9 +115,9 @@ STATIC void core1_entry_wrapper(void) { } mp_uint_t mp_thread_get_id(void) { - // On RP2, there are only two threads, one for each core, so the thread id - // is the core number. - return get_core_num(); + // On RP2, there are only two threads, one for each core. + // _thread.get_ident() must be non-zero. + return get_core_num() + 1; } mp_uint_t mp_thread_create(void *(*entry)(void *), void *arg, size_t *stack_size) { @@ -149,7 +149,7 @@ mp_uint_t mp_thread_create(void *(*entry)(void *), void *arg, size_t *stack_size // Adjust stack_size to provide room to recover from hitting the limit. *stack_size -= 512; - return 1; + return 2; // mp_thread_get_id() result for core 1 } void mp_thread_start(void) { From 215a982c1469df214b2beda2db5ed8d562040738 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sun, 14 Jan 2024 20:22:18 +0200 Subject: [PATCH 044/408] py/py.mk: Remove extra build dir created for frozen_content. This was originally needed because the .c --> .o rule is: $(BUILD)/%.o: %.c and because the generated frozen_content.c is inside build-FOO, it must therefore generate build-FOO/build-FOO/frozen_content.o. But 2eda5138701d6a7d36f8d8e3700d136b3c1161b7 added a new build rule for pins.c that can also be used for frozen_content.c. Signed-off-by: iabdalkader --- py/py.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/py.mk b/py/py.mk index ffb853c652db9..e81df52fb7f99 100644 --- a/py/py.mk +++ b/py/py.mk @@ -203,7 +203,7 @@ PY_O += $(PY_CORE_O) # object file for frozen code specified via a manifest ifneq ($(FROZEN_MANIFEST),) -PY_O += $(BUILD)/$(BUILD)/frozen_content.o +PY_O += $(BUILD)/frozen_content.o endif # Sources that may contain qstrings From a75ca8a1c07d7da1d0f97189cbe3238f65dda2df Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 10 Jan 2024 14:11:00 +1100 Subject: [PATCH 045/408] esp32/modsocket: Use all supplied arguments to socket.getaddrinfo(). - Completes a longstanding TODO in the code, to not ignore the optional family, type, proto and flags arguments to socket.getaddrinfo(). - Note that passing family=socket.AF_INET6 will now cause queries to fail (OSError -202). Previously this argument was ignored so IPV4 results were returned instead. - Optional 'type' argument is now always copied into the result. If not set, results have type SOCK_STREAM. - Fixes inconsistency where previously querying mDNS local suffix (.local) hostnames returned results with socket type 0 (invalid), but all other queries returned results with socket type SOCK_STREAM (regardless of 'type' argument). - Optional proto argument is now returned in the result tuple, if supplied. - Optional flags argument is now passed through to lwIP. lwIP has handling for AI_NUMERICHOST, AI_V4MAPPED, AI_PASSIVE (untested, constants for these are not currently exposed in the esp32 socket module). - Also fixes a possible memory leak in an obscure code path (lwip_getaddrinfo apparently sometimes returns a result structure with address "0.0.0.0" instead of failing, and this structure would have been leaked.) This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- ports/esp32/modsocket.c | 157 ++++++++++++++++++++++++---------------- 1 file changed, 95 insertions(+), 62 deletions(-) diff --git a/ports/esp32/modsocket.c b/ports/esp32/modsocket.c index ca8c63030cd74..af949401569cd 100644 --- a/ports/esp32/modsocket.c +++ b/ports/esp32/modsocket.c @@ -156,64 +156,67 @@ static inline void check_for_exceptions(void) { mp_handle_pending(true); } -// This function mimics lwip_getaddrinfo, with added support for mDNS queries -static int _socket_getaddrinfo3(const char *nodename, const char *servname, +#if MICROPY_HW_ENABLE_MDNS_QUERIES +// This function mimics lwip_getaddrinfo, but makes an mDNS query +STATIC int mdns_getaddrinfo(const char *host_str, const char *port_str, const struct addrinfo *hints, struct addrinfo **res) { - - #if MICROPY_HW_ENABLE_MDNS_QUERIES - int nodename_len = strlen(nodename); + int host_len = strlen(host_str); const int local_len = sizeof(MDNS_LOCAL_SUFFIX) - 1; - if (nodename_len > local_len - && strcasecmp(nodename + nodename_len - local_len, MDNS_LOCAL_SUFFIX) == 0) { - // mDNS query - char nodename_no_local[nodename_len - local_len + 1]; - memcpy(nodename_no_local, nodename, nodename_len - local_len); - nodename_no_local[nodename_len - local_len] = '\0'; - - esp_ip4_addr_t addr = {0}; - - esp_err_t err = mdns_query_a(nodename_no_local, MDNS_QUERY_TIMEOUT_MS, &addr); - if (err != ESP_OK) { - if (err == ESP_ERR_NOT_FOUND) { - *res = NULL; - return 0; - } + if (host_len <= local_len || + strcasecmp(host_str + host_len - local_len, MDNS_LOCAL_SUFFIX) != 0) { + return 0; + } + + // mDNS query + char host_no_local[host_len - local_len + 1]; + memcpy(host_no_local, host_str, host_len - local_len); + host_no_local[host_len - local_len] = '\0'; + + esp_ip4_addr_t addr = {0}; + + esp_err_t err = mdns_query_a(host_no_local, MDNS_QUERY_TIMEOUT_MS, &addr); + if (err != ESP_OK) { + if (err == ESP_ERR_NOT_FOUND) { *res = NULL; - return err; + return 0; } + *res = NULL; + return err; + } - struct addrinfo *ai = memp_malloc(MEMP_NETDB); - if (ai == NULL) { - *res = NULL; - return EAI_MEMORY; - } - memset(ai, 0, sizeof(struct addrinfo) + sizeof(struct sockaddr_storage)); - - struct sockaddr_in *sa = (struct sockaddr_in *)((uint8_t *)ai + sizeof(struct addrinfo)); - inet_addr_from_ip4addr(&sa->sin_addr, &addr); - sa->sin_family = AF_INET; - sa->sin_len = sizeof(struct sockaddr_in); - sa->sin_port = lwip_htons((u16_t)atoi(servname)); - ai->ai_family = AF_INET; - ai->ai_canonname = ((char *)sa + sizeof(struct sockaddr_storage)); - memcpy(ai->ai_canonname, nodename, nodename_len + 1); - ai->ai_addrlen = sizeof(struct sockaddr_storage); - ai->ai_addr = (struct sockaddr *)sa; - - *res = ai; - return 0; + struct addrinfo *ai = memp_malloc(MEMP_NETDB); + if (ai == NULL) { + *res = NULL; + return EAI_MEMORY; + } + memset(ai, 0, sizeof(struct addrinfo) + sizeof(struct sockaddr_storage)); + + struct sockaddr_in *sa = (struct sockaddr_in *)((uint8_t *)ai + sizeof(struct addrinfo)); + inet_addr_from_ip4addr(&sa->sin_addr, &addr); + sa->sin_family = AF_INET; + sa->sin_len = sizeof(struct sockaddr_in); + sa->sin_port = lwip_htons((u16_t)atoi(port_str)); + ai->ai_family = AF_INET; + ai->ai_canonname = ((char *)sa + sizeof(struct sockaddr_storage)); + memcpy(ai->ai_canonname, host_str, host_len + 1); + ai->ai_addrlen = sizeof(struct sockaddr_storage); + ai->ai_addr = (struct sockaddr *)sa; + ai->ai_socktype = SOCK_STREAM; + if (hints) { + ai->ai_socktype = hints->ai_socktype; + ai->ai_protocol = hints->ai_protocol; } - #endif - // Normal query - return lwip_getaddrinfo(nodename, servname, hints, res); + *res = ai; + return 0; } +#endif // MICROPY_HW_ENABLE_MDNS_QUERIES -static int _socket_getaddrinfo2(const mp_obj_t host, const mp_obj_t portx, struct addrinfo **resp) { - const struct addrinfo hints = { - .ai_family = AF_INET, - .ai_socktype = SOCK_STREAM, - }; +static void _getaddrinfo_inner(const mp_obj_t host, const mp_obj_t portx, + const struct addrinfo *hints, struct addrinfo **res) { + int retval = 0; + + *res = NULL; mp_obj_t port = portx; if (mp_obj_is_integer(port)) { @@ -231,27 +234,37 @@ static int _socket_getaddrinfo2(const mp_obj_t host, const mp_obj_t portx, struc } MP_THREAD_GIL_EXIT(); - int res = _socket_getaddrinfo3(host_str, port_str, &hints, resp); + + #if MICROPY_HW_ENABLE_MDNS_QUERIES + retval = mdns_getaddrinfo(host_str, port_str, hints, res); + #endif + + if (retval == 0 && *res == NULL) { + // Normal query + retval = lwip_getaddrinfo(host_str, port_str, hints, res); + } + MP_THREAD_GIL_ENTER(); // Per docs: instead of raising gaierror getaddrinfo raises negative error number - if (res != 0) { - mp_raise_OSError(res > 0 ? -res : res); + if (retval != 0) { + mp_raise_OSError(retval > 0 ? -retval : retval); } // Somehow LwIP returns a resolution of 0.0.0.0 for failed lookups, traced it as far back // as netconn_gethostbyname_addrtype returning OK instead of error. - if (*resp == NULL || - (strcmp(resp[0]->ai_canonname, "0.0.0.0") == 0 && strcmp(host_str, "0.0.0.0") != 0)) { + if (*res == NULL || + (strcmp(res[0]->ai_canonname, "0.0.0.0") == 0 && strcmp(host_str, "0.0.0.0") != 0)) { + lwip_freeaddrinfo(*res); mp_raise_OSError(-2); // name or service not known } - return res; + assert(retval == 0 && *res != NULL); } STATIC void _socket_getaddrinfo(const mp_obj_t addrtuple, struct addrinfo **resp) { mp_obj_t *elem; mp_obj_get_array_fixed_n(addrtuple, 2, &elem); - _socket_getaddrinfo2(elem[0], elem[1], resp); + _getaddrinfo_inner(elem[0], elem[1], NULL, resp); } STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { @@ -897,10 +910,32 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); STATIC mp_obj_t esp_socket_getaddrinfo(size_t n_args, const mp_obj_t *args) { - // TODO support additional args beyond the first two - + struct addrinfo hints = { }; struct addrinfo *res = NULL; - _socket_getaddrinfo2(args[0], args[1], &res); + + // Optional args: family=0, type=0, proto=0, flags=0, where 0 is "least narrow" + if (n_args > 2) { + hints.ai_family = mp_obj_get_int(args[2]); + } + if (n_args > 3) { + hints.ai_socktype = mp_obj_get_int(args[3]); + } + if (hints.ai_socktype == 0) { + // This is slightly different to CPython with POSIX getaddrinfo. In + // CPython, calling socket.getaddrinfo() with socktype=0 returns any/all + // supported SocketKind values. Here, lwip_getaddrinfo() will echo + // whatever socktype was supplied to the caller. Rather than returning 0 + // (invalid in a result), make it SOCK_STREAM. + hints.ai_socktype = SOCK_STREAM; + } + if (n_args > 4) { + hints.ai_protocol = mp_obj_get_int(args[4]); + } + if (n_args > 5) { + hints.ai_flags = mp_obj_get_int(args[5]); + } + + _getaddrinfo_inner(args[0], args[1], &hints, &res); mp_obj_t ret_list = mp_obj_new_list(0, NULL); for (struct addrinfo *resi = res; resi; resi = resi->ai_next) { @@ -927,9 +962,7 @@ STATIC mp_obj_t esp_socket_getaddrinfo(size_t n_args, const mp_obj_t *args) { mp_obj_list_append(ret_list, mp_obj_new_tuple(5, addrinfo_objs)); } - if (res) { - lwip_freeaddrinfo(res); - } + lwip_freeaddrinfo(res); return ret_list; } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_socket_getaddrinfo_obj, 2, 6, esp_socket_getaddrinfo); From 1f04808151cf0b99eefe5dff036fac0ad76356c0 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Fri, 12 Jan 2024 14:17:44 +0200 Subject: [PATCH 046/408] renesas-ra/ra: Fix SysTick clock source. The SysTick_Config function must use the system/CPU clock to configure the ticks. Signed-off-by: iabdalkader --- ports/renesas-ra/ra/ra_config.h | 1 + ports/renesas-ra/ra/ra_init.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ports/renesas-ra/ra/ra_config.h b/ports/renesas-ra/ra/ra_config.h index a2df775c8902b..a9d4bb803d29c 100644 --- a/ports/renesas-ra/ra/ra_config.h +++ b/ports/renesas-ra/ra/ra_config.h @@ -26,6 +26,7 @@ #define RA_RA_CONFIG_H_ #include +#include "py/mpconfig.h" #if defined(RA4M1) | defined(RA4W1) #define SCI_CH_MAX 10 diff --git a/ports/renesas-ra/ra/ra_init.c b/ports/renesas-ra/ra/ra_init.c index c9b78e0dd17fc..a784aec707ac8 100644 --- a/ports/renesas-ra/ra/ra_init.c +++ b/ports/renesas-ra/ra/ra_init.c @@ -30,7 +30,7 @@ void ra_init(void) { ra_int_init(); - SysTick_Config(PCLK / 1000); + SysTick_Config(MICROPY_HW_MCU_SYSCLK / 1000); internal_flash_init(); } From c6f6f345e6f9e92b4876c6b70ad200e6c814f4df Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Fri, 12 Jan 2024 14:17:44 +0200 Subject: [PATCH 047/408] renesas-ra/ra: Remove unnecessary min_delay() declaration. This function is private to ra_adc.c. Signed-off-by: iabdalkader --- ports/renesas-ra/ra/ra_timer.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/ports/renesas-ra/ra/ra_timer.h b/ports/renesas-ra/ra/ra_timer.h index a04ecd709b074..85eabe3e12b1d 100644 --- a/ports/renesas-ra/ra/ra_timer.h +++ b/ports/renesas-ra/ra/ra_timer.h @@ -34,8 +34,6 @@ uint32_t HAL_GetTick(void); #define TENUSEC_COUNT (PCLK / DEF_CLKDEV / 100000) #define MSEC_COUNT (PCLK / DEF_CLKDEV / 100) -__attribute__((naked)) void min_delay(__attribute__((unused)) uint32_t loop_cnt); - typedef void (*AGT_TIMER_CB)(void *); void ra_agt_timer_set_callback(uint32_t ch, AGT_TIMER_CB cb, void *param); From 16c6bc47cf2b9247418bca8c0d1361167d08594e Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Thu, 11 Jan 2024 16:21:15 +0100 Subject: [PATCH 048/408] tools/mpremote: Reduce dependency on importlib_metadata. No longer require importlib_metadata on new Python versions as it is included in the standard distribution. Signed-off-by: Jochen Sprickerhof --- tools/mpremote/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/mpremote/requirements.txt b/tools/mpremote/requirements.txt index e4ca98fcaa233..6209cde5c331d 100644 --- a/tools/mpremote/requirements.txt +++ b/tools/mpremote/requirements.txt @@ -1,2 +1,2 @@ pyserial >= 3.3 -importlib_metadata >= 1.4 +importlib_metadata >= 1.4; python_version < "3.8" From 490e8e01d577247798d10fbe63860b914b9ae135 Mon Sep 17 00:00:00 2001 From: "Kwabena W. Agyeman" Date: Fri, 19 Jan 2024 22:56:08 -0800 Subject: [PATCH 049/408] extmod/extmod.mk: Disable uninitialized warnings in kf_rem_pio2.c. GCC 13.2 thinks that fq is uninitialized. Signed-off-by: Kwabena W. Agyeman --- extmod/extmod.mk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/extmod/extmod.mk b/extmod/extmod.mk index 9b1e51718e41d..59e530d3476b0 100644 --- a/extmod/extmod.mk +++ b/extmod/extmod.mk @@ -107,6 +107,9 @@ SRC_LIB_LIBM_C += $(addprefix lib/libm/,\ SRC_LIB_LIBM_SQRT_SW_C += lib/libm/ef_sqrt.c SRC_LIB_LIBM_SQRT_HW_C += lib/libm/thumb_vfp_sqrtf.c +# Disable warnings in libm. +$(BUILD)/lib/libm/kf_rem_pio2.o: CFLAGS += -Wno-maybe-uninitialized + # Double-precision math library. SRC_LIB_LIBM_DBL_C += $(addprefix lib/libm_dbl/,\ __cos.c \ From 4fd7e456f0b850566f6e99ad1785a15e2a117636 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Wed, 17 Jan 2024 12:05:57 +0200 Subject: [PATCH 050/408] renesas-ra/boards/ARDUINO_PORTENTA_C33: Fix the RTC clock source. Switch the RTC clock source to Sub-clock (XCIN). This board has an accurate LSE crystal, and it should be used for the RTC clock source. Signed-off-by: iabdalkader --- ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/mpconfigboard.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/mpconfigboard.h b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/mpconfigboard.h index 52346dedc44ee..f28deb0cebcaf 100644 --- a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/mpconfigboard.h +++ b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/mpconfigboard.h @@ -28,7 +28,7 @@ // peripheral config #define MICROPY_HW_ENABLE_RNG (1) #define MICROPY_HW_ENABLE_RTC (1) -#define MICROPY_HW_RTC_SOURCE (1) +#define MICROPY_HW_RTC_SOURCE (0) #define MICROPY_HW_ENABLE_ADC (1) #define MICROPY_HW_HAS_FLASH (1) #define MICROPY_HW_ENABLE_USBDEV (1) From f93ffc2875c57ce3b8a608ebf5ae9050aa62f069 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 17 Jan 2024 19:06:41 +0000 Subject: [PATCH 051/408] github/workflows: Bump actions/cache from 3 to 4. Bumps [actions/cache](https://github.com/actions/cache) from 3 to 4. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/ports_esp32.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ports_esp32.yml b/.github/workflows/ports_esp32.yml index 6872b9d12de78..45808b659add7 100644 --- a/.github/workflows/ports_esp32.yml +++ b/.github/workflows/ports_esp32.yml @@ -35,7 +35,7 @@ jobs: - name: Cached ESP-IDF install id: cache_esp_idf - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ./esp-idf/ From 7bbcee3cf09a08199b3ffefb6c5e37208cba5f0a Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 18 Jan 2024 16:32:31 +1100 Subject: [PATCH 052/408] tests: Move port-specific test directories into tests/ports/ directory. To keep them all together, mirroring the top-level directory structure. Signed-off-by: Damien George --- tests/{wipy => ports/cc3200}/adc.py | 0 tests/{wipy => ports/cc3200}/adc.py.exp | 0 tests/{wipy => ports/cc3200}/i2c.py | 0 tests/{wipy => ports/cc3200}/i2c.py.exp | 0 tests/{wipy => ports/cc3200}/modwipy.py | 0 tests/{wipy => ports/cc3200}/modwipy.py.exp | 0 tests/{wipy => ports/cc3200}/os.py | 0 tests/{wipy => ports/cc3200}/os.py.exp | 0 tests/{wipy => ports/cc3200}/pin.py | 0 tests/{wipy => ports/cc3200}/pin.py.exp | 0 tests/{wipy => ports/cc3200}/pin_irq.py | 0 tests/{wipy => ports/cc3200}/pin_irq.py.exp | 0 tests/{wipy => ports/cc3200}/reset/reset.py | 0 tests/{wipy => ports/cc3200}/reset/reset.py.exp | 0 tests/{wipy => ports/cc3200}/rtc.py | 0 tests/{wipy => ports/cc3200}/rtc.py.exp | 0 tests/{wipy => ports/cc3200}/sd.py | 0 tests/{wipy => ports/cc3200}/sd.py.exp | 0 tests/{wipy => ports/cc3200}/skipped/rtc_irq.py | 0 tests/{wipy => ports/cc3200}/skipped/rtc_irq.py.exp | 0 tests/{wipy => ports/cc3200}/spi.py | 0 tests/{wipy => ports/cc3200}/spi.py.exp | 0 tests/{wipy => ports/cc3200}/time.py | 0 tests/{wipy => ports/cc3200}/time.py.exp | 0 tests/{wipy => ports/cc3200}/timer.py | 0 tests/{wipy => ports/cc3200}/timer.py.exp | 0 tests/{wipy => ports/cc3200}/uart.py | 0 tests/{wipy => ports/cc3200}/uart.py.exp | 0 tests/{wipy => ports/cc3200}/uart_irq.py | 0 tests/{wipy => ports/cc3200}/uart_irq.py.exp | 0 tests/{wipy => ports/cc3200}/wdt.py | 0 tests/{wipy => ports/cc3200}/wdt.py.exp | 0 tests/{wipy => ports/cc3200}/wlan/machine.py | 0 tests/{wipy => ports/cc3200}/wlan/machine.py.exp | 0 tests/{wipy => ports/cc3200}/wlan/server.py | 0 tests/{wipy => ports/cc3200}/wlan/server.py.exp | 0 tests/{wipy => ports/cc3200}/wlan/wlan.py | 0 tests/{wipy => ports/cc3200}/wlan/wlan.py.exp | 0 tests/{ => ports}/esp32/check_err_str.py | 0 tests/{ => ports}/esp32/check_err_str.py.exp | 0 tests/{ => ports}/esp32/esp32_idf_heap_info.py | 0 tests/{ => ports}/esp32/esp32_idf_heap_info.py.exp | 0 tests/{ => ports}/esp32/esp32_nvs.py | 0 tests/{ => ports}/esp32/esp32_nvs.py.exp | 0 tests/{ => ports}/esp32/partition_ota.py | 0 tests/{ => ports}/esp32/partition_ota.py.exp | 0 tests/{ => ports}/esp32/resolve_on_connect.py | 0 tests/{ => ports}/qemu-arm/asm_test.py | 0 tests/{ => ports}/qemu-arm/asm_test.py.exp | 0 tests/{ => ports}/qemu-arm/native_test.py | 0 tests/{ => ports}/qemu-arm/native_test.py.exp | 0 tests/{ => ports}/qemu-arm/viper_test.py | 0 tests/{ => ports}/qemu-arm/viper_test.py.exp | 0 tests/{ => ports}/renesas-ra/freq.py | 0 tests/{ => ports}/renesas-ra/freq.py.exp | 0 tests/{ => ports}/renesas-ra/i2c.py | 0 tests/{ => ports}/renesas-ra/i2c.py.exp | 0 tests/{pyb => ports/renesas-ra}/modtime.py | 0 tests/{pyb => ports/renesas-ra}/modtime.py.exp | 0 tests/{ => ports}/renesas-ra/pin.py | 0 tests/{ => ports}/renesas-ra/pin.py.exp | 0 tests/{ => ports}/renesas-ra/rtc_init.py | 0 tests/{ => ports}/renesas-ra/rtc_init.py.exp | 0 tests/{ => ports}/renesas-ra/spi.py | 0 tests/{ => ports}/renesas-ra/spi.py.exp | 0 tests/{ => ports}/renesas-ra/uart1.py | 0 tests/{ => ports}/renesas-ra/uart1.py.exp | 0 tests/{pyb => ports/stm32}/accel.py | 0 tests/{pyb => ports/stm32}/accel.py.exp | 0 tests/{pyb => ports/stm32}/adc.py | 0 tests/{pyb => ports/stm32}/adc.py.exp | 0 tests/{pyb => ports/stm32}/adcall.py | 0 tests/{pyb => ports/stm32}/adcall.py.exp | 0 tests/{pyb => ports/stm32}/board_pybv1x.py | 0 tests/{pyb => ports/stm32}/board_pybv1x.py.exp | 0 tests/{pyb => ports/stm32}/can.py | 0 tests/{pyb => ports/stm32}/can.py.exp | 0 tests/{pyb => ports/stm32}/can2.py | 0 tests/{pyb => ports/stm32}/can2.py.exp | 0 tests/{pyb => ports/stm32}/dac.py | 0 tests/{pyb => ports/stm32}/dac.py.exp | 0 tests/{pyb => ports/stm32}/extint.py | 0 tests/{pyb => ports/stm32}/extint.py.exp | 0 tests/{pyb => ports/stm32}/i2c.py | 0 tests/{pyb => ports/stm32}/i2c.py.exp | 0 tests/{pyb => ports/stm32}/i2c_accel.py | 0 tests/{pyb => ports/stm32}/i2c_accel.py.exp | 0 tests/{pyb => ports/stm32}/i2c_error.py | 0 tests/{pyb => ports/stm32}/i2c_error.py.exp | 0 tests/{pyb => ports/stm32}/irq.py | 0 tests/{pyb => ports/stm32}/irq.py.exp | 0 tests/{pyb => ports/stm32}/led.py | 0 tests/{pyb => ports/stm32}/led.py.exp | 0 tests/{pyb => ports/stm32}/modstm.py | 0 tests/{pyb => ports/stm32}/modstm.py.exp | 0 tests/{renesas-ra => ports/stm32}/modtime.py | 0 tests/{renesas-ra => ports/stm32}/modtime.py.exp | 0 tests/{pyb => ports/stm32}/pin.py | 0 tests/{pyb => ports/stm32}/pin.py.exp | 0 tests/{pyb => ports/stm32}/pyb1.py | 0 tests/{pyb => ports/stm32}/pyb1.py.exp | 0 tests/{pyb => ports/stm32}/pyb_f405.py | 0 tests/{pyb => ports/stm32}/pyb_f405.py.exp | 0 tests/{pyb => ports/stm32}/pyb_f411.py | 0 tests/{pyb => ports/stm32}/pyb_f411.py.exp | 0 tests/{pyb => ports/stm32}/rtc.py | 0 tests/{pyb => ports/stm32}/rtc.py.exp | 0 tests/{pyb => ports/stm32}/servo.py | 0 tests/{pyb => ports/stm32}/servo.py.exp | 0 tests/{pyb => ports/stm32}/spi.py | 0 tests/{pyb => ports/stm32}/spi.py.exp | 0 tests/{pyb => ports/stm32}/switch.py | 0 tests/{pyb => ports/stm32}/switch.py.exp | 0 tests/{pyb => ports/stm32}/timer.py | 0 tests/{pyb => ports/stm32}/timer.py.exp | 0 tests/{pyb => ports/stm32}/timer_callback.py | 0 tests/{pyb => ports/stm32}/timer_callback.py.exp | 0 tests/{pyb => ports/stm32}/uart.py | 0 tests/{pyb => ports/stm32}/uart.py.exp | 0 tests/{ => ports}/unix/extra_coverage.py | 0 tests/{ => ports}/unix/extra_coverage.py.exp | 0 tests/{ => ports}/unix/ffi_callback.py | 0 tests/{ => ports}/unix/ffi_callback.py.exp | 0 tests/{ => ports}/unix/ffi_float.py | 0 tests/{ => ports}/unix/ffi_float.py.exp | 0 tests/{ => ports}/unix/ffi_float2.py | 0 tests/{ => ports}/unix/ffi_float2.py.exp | 0 tests/{ => ports}/unix/ffi_lib.c | 0 tests/{ => ports}/unix/ffi_types.py | 0 tests/{ => ports}/unix/ffi_types.py.exp | 0 tests/{ => ports}/unix/mod_os.py | 0 tests/{ => ports}/unix/mod_os.py.exp | 0 tests/{ => ports}/unix/time_mktime_localtime.py | 0 tests/run-tests.py | 12 ++++++------ tools/ci.sh | 2 +- 135 files changed, 7 insertions(+), 7 deletions(-) rename tests/{wipy => ports/cc3200}/adc.py (100%) rename tests/{wipy => ports/cc3200}/adc.py.exp (100%) rename tests/{wipy => ports/cc3200}/i2c.py (100%) rename tests/{wipy => ports/cc3200}/i2c.py.exp (100%) rename tests/{wipy => ports/cc3200}/modwipy.py (100%) rename tests/{wipy => ports/cc3200}/modwipy.py.exp (100%) rename tests/{wipy => ports/cc3200}/os.py (100%) rename tests/{wipy => ports/cc3200}/os.py.exp (100%) rename tests/{wipy => ports/cc3200}/pin.py (100%) rename tests/{wipy => ports/cc3200}/pin.py.exp (100%) rename tests/{wipy => ports/cc3200}/pin_irq.py (100%) rename tests/{wipy => ports/cc3200}/pin_irq.py.exp (100%) rename tests/{wipy => ports/cc3200}/reset/reset.py (100%) rename tests/{wipy => ports/cc3200}/reset/reset.py.exp (100%) rename tests/{wipy => ports/cc3200}/rtc.py (100%) rename tests/{wipy => ports/cc3200}/rtc.py.exp (100%) rename tests/{wipy => ports/cc3200}/sd.py (100%) rename tests/{wipy => ports/cc3200}/sd.py.exp (100%) rename tests/{wipy => ports/cc3200}/skipped/rtc_irq.py (100%) rename tests/{wipy => ports/cc3200}/skipped/rtc_irq.py.exp (100%) rename tests/{wipy => ports/cc3200}/spi.py (100%) rename tests/{wipy => ports/cc3200}/spi.py.exp (100%) rename tests/{wipy => ports/cc3200}/time.py (100%) rename tests/{wipy => ports/cc3200}/time.py.exp (100%) rename tests/{wipy => ports/cc3200}/timer.py (100%) rename tests/{wipy => ports/cc3200}/timer.py.exp (100%) rename tests/{wipy => ports/cc3200}/uart.py (100%) rename tests/{wipy => ports/cc3200}/uart.py.exp (100%) rename tests/{wipy => ports/cc3200}/uart_irq.py (100%) rename tests/{wipy => ports/cc3200}/uart_irq.py.exp (100%) rename tests/{wipy => ports/cc3200}/wdt.py (100%) rename tests/{wipy => ports/cc3200}/wdt.py.exp (100%) rename tests/{wipy => ports/cc3200}/wlan/machine.py (100%) rename tests/{wipy => ports/cc3200}/wlan/machine.py.exp (100%) rename tests/{wipy => ports/cc3200}/wlan/server.py (100%) rename tests/{wipy => ports/cc3200}/wlan/server.py.exp (100%) rename tests/{wipy => ports/cc3200}/wlan/wlan.py (100%) rename tests/{wipy => ports/cc3200}/wlan/wlan.py.exp (100%) rename tests/{ => ports}/esp32/check_err_str.py (100%) rename tests/{ => ports}/esp32/check_err_str.py.exp (100%) rename tests/{ => ports}/esp32/esp32_idf_heap_info.py (100%) rename tests/{ => ports}/esp32/esp32_idf_heap_info.py.exp (100%) rename tests/{ => ports}/esp32/esp32_nvs.py (100%) rename tests/{ => ports}/esp32/esp32_nvs.py.exp (100%) rename tests/{ => ports}/esp32/partition_ota.py (100%) rename tests/{ => ports}/esp32/partition_ota.py.exp (100%) rename tests/{ => ports}/esp32/resolve_on_connect.py (100%) rename tests/{ => ports}/qemu-arm/asm_test.py (100%) rename tests/{ => ports}/qemu-arm/asm_test.py.exp (100%) rename tests/{ => ports}/qemu-arm/native_test.py (100%) rename tests/{ => ports}/qemu-arm/native_test.py.exp (100%) rename tests/{ => ports}/qemu-arm/viper_test.py (100%) rename tests/{ => ports}/qemu-arm/viper_test.py.exp (100%) rename tests/{ => ports}/renesas-ra/freq.py (100%) rename tests/{ => ports}/renesas-ra/freq.py.exp (100%) rename tests/{ => ports}/renesas-ra/i2c.py (100%) rename tests/{ => ports}/renesas-ra/i2c.py.exp (100%) rename tests/{pyb => ports/renesas-ra}/modtime.py (100%) rename tests/{pyb => ports/renesas-ra}/modtime.py.exp (100%) rename tests/{ => ports}/renesas-ra/pin.py (100%) rename tests/{ => ports}/renesas-ra/pin.py.exp (100%) rename tests/{ => ports}/renesas-ra/rtc_init.py (100%) rename tests/{ => ports}/renesas-ra/rtc_init.py.exp (100%) rename tests/{ => ports}/renesas-ra/spi.py (100%) rename tests/{ => ports}/renesas-ra/spi.py.exp (100%) rename tests/{ => ports}/renesas-ra/uart1.py (100%) rename tests/{ => ports}/renesas-ra/uart1.py.exp (100%) rename tests/{pyb => ports/stm32}/accel.py (100%) rename tests/{pyb => ports/stm32}/accel.py.exp (100%) rename tests/{pyb => ports/stm32}/adc.py (100%) rename tests/{pyb => ports/stm32}/adc.py.exp (100%) rename tests/{pyb => ports/stm32}/adcall.py (100%) rename tests/{pyb => ports/stm32}/adcall.py.exp (100%) rename tests/{pyb => ports/stm32}/board_pybv1x.py (100%) rename tests/{pyb => ports/stm32}/board_pybv1x.py.exp (100%) rename tests/{pyb => ports/stm32}/can.py (100%) rename tests/{pyb => ports/stm32}/can.py.exp (100%) rename tests/{pyb => ports/stm32}/can2.py (100%) rename tests/{pyb => ports/stm32}/can2.py.exp (100%) rename tests/{pyb => ports/stm32}/dac.py (100%) rename tests/{pyb => ports/stm32}/dac.py.exp (100%) rename tests/{pyb => ports/stm32}/extint.py (100%) rename tests/{pyb => ports/stm32}/extint.py.exp (100%) rename tests/{pyb => ports/stm32}/i2c.py (100%) rename tests/{pyb => ports/stm32}/i2c.py.exp (100%) rename tests/{pyb => ports/stm32}/i2c_accel.py (100%) rename tests/{pyb => ports/stm32}/i2c_accel.py.exp (100%) rename tests/{pyb => ports/stm32}/i2c_error.py (100%) rename tests/{pyb => ports/stm32}/i2c_error.py.exp (100%) rename tests/{pyb => ports/stm32}/irq.py (100%) rename tests/{pyb => ports/stm32}/irq.py.exp (100%) rename tests/{pyb => ports/stm32}/led.py (100%) rename tests/{pyb => ports/stm32}/led.py.exp (100%) rename tests/{pyb => ports/stm32}/modstm.py (100%) rename tests/{pyb => ports/stm32}/modstm.py.exp (100%) rename tests/{renesas-ra => ports/stm32}/modtime.py (100%) rename tests/{renesas-ra => ports/stm32}/modtime.py.exp (100%) rename tests/{pyb => ports/stm32}/pin.py (100%) rename tests/{pyb => ports/stm32}/pin.py.exp (100%) rename tests/{pyb => ports/stm32}/pyb1.py (100%) rename tests/{pyb => ports/stm32}/pyb1.py.exp (100%) rename tests/{pyb => ports/stm32}/pyb_f405.py (100%) rename tests/{pyb => ports/stm32}/pyb_f405.py.exp (100%) rename tests/{pyb => ports/stm32}/pyb_f411.py (100%) rename tests/{pyb => ports/stm32}/pyb_f411.py.exp (100%) rename tests/{pyb => ports/stm32}/rtc.py (100%) rename tests/{pyb => ports/stm32}/rtc.py.exp (100%) rename tests/{pyb => ports/stm32}/servo.py (100%) rename tests/{pyb => ports/stm32}/servo.py.exp (100%) rename tests/{pyb => ports/stm32}/spi.py (100%) rename tests/{pyb => ports/stm32}/spi.py.exp (100%) rename tests/{pyb => ports/stm32}/switch.py (100%) rename tests/{pyb => ports/stm32}/switch.py.exp (100%) rename tests/{pyb => ports/stm32}/timer.py (100%) rename tests/{pyb => ports/stm32}/timer.py.exp (100%) rename tests/{pyb => ports/stm32}/timer_callback.py (100%) rename tests/{pyb => ports/stm32}/timer_callback.py.exp (100%) rename tests/{pyb => ports/stm32}/uart.py (100%) rename tests/{pyb => ports/stm32}/uart.py.exp (100%) rename tests/{ => ports}/unix/extra_coverage.py (100%) rename tests/{ => ports}/unix/extra_coverage.py.exp (100%) rename tests/{ => ports}/unix/ffi_callback.py (100%) rename tests/{ => ports}/unix/ffi_callback.py.exp (100%) rename tests/{ => ports}/unix/ffi_float.py (100%) rename tests/{ => ports}/unix/ffi_float.py.exp (100%) rename tests/{ => ports}/unix/ffi_float2.py (100%) rename tests/{ => ports}/unix/ffi_float2.py.exp (100%) rename tests/{ => ports}/unix/ffi_lib.c (100%) rename tests/{ => ports}/unix/ffi_types.py (100%) rename tests/{ => ports}/unix/ffi_types.py.exp (100%) rename tests/{ => ports}/unix/mod_os.py (100%) rename tests/{ => ports}/unix/mod_os.py.exp (100%) rename tests/{ => ports}/unix/time_mktime_localtime.py (100%) diff --git a/tests/wipy/adc.py b/tests/ports/cc3200/adc.py similarity index 100% rename from tests/wipy/adc.py rename to tests/ports/cc3200/adc.py diff --git a/tests/wipy/adc.py.exp b/tests/ports/cc3200/adc.py.exp similarity index 100% rename from tests/wipy/adc.py.exp rename to tests/ports/cc3200/adc.py.exp diff --git a/tests/wipy/i2c.py b/tests/ports/cc3200/i2c.py similarity index 100% rename from tests/wipy/i2c.py rename to tests/ports/cc3200/i2c.py diff --git a/tests/wipy/i2c.py.exp b/tests/ports/cc3200/i2c.py.exp similarity index 100% rename from tests/wipy/i2c.py.exp rename to tests/ports/cc3200/i2c.py.exp diff --git a/tests/wipy/modwipy.py b/tests/ports/cc3200/modwipy.py similarity index 100% rename from tests/wipy/modwipy.py rename to tests/ports/cc3200/modwipy.py diff --git a/tests/wipy/modwipy.py.exp b/tests/ports/cc3200/modwipy.py.exp similarity index 100% rename from tests/wipy/modwipy.py.exp rename to tests/ports/cc3200/modwipy.py.exp diff --git a/tests/wipy/os.py b/tests/ports/cc3200/os.py similarity index 100% rename from tests/wipy/os.py rename to tests/ports/cc3200/os.py diff --git a/tests/wipy/os.py.exp b/tests/ports/cc3200/os.py.exp similarity index 100% rename from tests/wipy/os.py.exp rename to tests/ports/cc3200/os.py.exp diff --git a/tests/wipy/pin.py b/tests/ports/cc3200/pin.py similarity index 100% rename from tests/wipy/pin.py rename to tests/ports/cc3200/pin.py diff --git a/tests/wipy/pin.py.exp b/tests/ports/cc3200/pin.py.exp similarity index 100% rename from tests/wipy/pin.py.exp rename to tests/ports/cc3200/pin.py.exp diff --git a/tests/wipy/pin_irq.py b/tests/ports/cc3200/pin_irq.py similarity index 100% rename from tests/wipy/pin_irq.py rename to tests/ports/cc3200/pin_irq.py diff --git a/tests/wipy/pin_irq.py.exp b/tests/ports/cc3200/pin_irq.py.exp similarity index 100% rename from tests/wipy/pin_irq.py.exp rename to tests/ports/cc3200/pin_irq.py.exp diff --git a/tests/wipy/reset/reset.py b/tests/ports/cc3200/reset/reset.py similarity index 100% rename from tests/wipy/reset/reset.py rename to tests/ports/cc3200/reset/reset.py diff --git a/tests/wipy/reset/reset.py.exp b/tests/ports/cc3200/reset/reset.py.exp similarity index 100% rename from tests/wipy/reset/reset.py.exp rename to tests/ports/cc3200/reset/reset.py.exp diff --git a/tests/wipy/rtc.py b/tests/ports/cc3200/rtc.py similarity index 100% rename from tests/wipy/rtc.py rename to tests/ports/cc3200/rtc.py diff --git a/tests/wipy/rtc.py.exp b/tests/ports/cc3200/rtc.py.exp similarity index 100% rename from tests/wipy/rtc.py.exp rename to tests/ports/cc3200/rtc.py.exp diff --git a/tests/wipy/sd.py b/tests/ports/cc3200/sd.py similarity index 100% rename from tests/wipy/sd.py rename to tests/ports/cc3200/sd.py diff --git a/tests/wipy/sd.py.exp b/tests/ports/cc3200/sd.py.exp similarity index 100% rename from tests/wipy/sd.py.exp rename to tests/ports/cc3200/sd.py.exp diff --git a/tests/wipy/skipped/rtc_irq.py b/tests/ports/cc3200/skipped/rtc_irq.py similarity index 100% rename from tests/wipy/skipped/rtc_irq.py rename to tests/ports/cc3200/skipped/rtc_irq.py diff --git a/tests/wipy/skipped/rtc_irq.py.exp b/tests/ports/cc3200/skipped/rtc_irq.py.exp similarity index 100% rename from tests/wipy/skipped/rtc_irq.py.exp rename to tests/ports/cc3200/skipped/rtc_irq.py.exp diff --git a/tests/wipy/spi.py b/tests/ports/cc3200/spi.py similarity index 100% rename from tests/wipy/spi.py rename to tests/ports/cc3200/spi.py diff --git a/tests/wipy/spi.py.exp b/tests/ports/cc3200/spi.py.exp similarity index 100% rename from tests/wipy/spi.py.exp rename to tests/ports/cc3200/spi.py.exp diff --git a/tests/wipy/time.py b/tests/ports/cc3200/time.py similarity index 100% rename from tests/wipy/time.py rename to tests/ports/cc3200/time.py diff --git a/tests/wipy/time.py.exp b/tests/ports/cc3200/time.py.exp similarity index 100% rename from tests/wipy/time.py.exp rename to tests/ports/cc3200/time.py.exp diff --git a/tests/wipy/timer.py b/tests/ports/cc3200/timer.py similarity index 100% rename from tests/wipy/timer.py rename to tests/ports/cc3200/timer.py diff --git a/tests/wipy/timer.py.exp b/tests/ports/cc3200/timer.py.exp similarity index 100% rename from tests/wipy/timer.py.exp rename to tests/ports/cc3200/timer.py.exp diff --git a/tests/wipy/uart.py b/tests/ports/cc3200/uart.py similarity index 100% rename from tests/wipy/uart.py rename to tests/ports/cc3200/uart.py diff --git a/tests/wipy/uart.py.exp b/tests/ports/cc3200/uart.py.exp similarity index 100% rename from tests/wipy/uart.py.exp rename to tests/ports/cc3200/uart.py.exp diff --git a/tests/wipy/uart_irq.py b/tests/ports/cc3200/uart_irq.py similarity index 100% rename from tests/wipy/uart_irq.py rename to tests/ports/cc3200/uart_irq.py diff --git a/tests/wipy/uart_irq.py.exp b/tests/ports/cc3200/uart_irq.py.exp similarity index 100% rename from tests/wipy/uart_irq.py.exp rename to tests/ports/cc3200/uart_irq.py.exp diff --git a/tests/wipy/wdt.py b/tests/ports/cc3200/wdt.py similarity index 100% rename from tests/wipy/wdt.py rename to tests/ports/cc3200/wdt.py diff --git a/tests/wipy/wdt.py.exp b/tests/ports/cc3200/wdt.py.exp similarity index 100% rename from tests/wipy/wdt.py.exp rename to tests/ports/cc3200/wdt.py.exp diff --git a/tests/wipy/wlan/machine.py b/tests/ports/cc3200/wlan/machine.py similarity index 100% rename from tests/wipy/wlan/machine.py rename to tests/ports/cc3200/wlan/machine.py diff --git a/tests/wipy/wlan/machine.py.exp b/tests/ports/cc3200/wlan/machine.py.exp similarity index 100% rename from tests/wipy/wlan/machine.py.exp rename to tests/ports/cc3200/wlan/machine.py.exp diff --git a/tests/wipy/wlan/server.py b/tests/ports/cc3200/wlan/server.py similarity index 100% rename from tests/wipy/wlan/server.py rename to tests/ports/cc3200/wlan/server.py diff --git a/tests/wipy/wlan/server.py.exp b/tests/ports/cc3200/wlan/server.py.exp similarity index 100% rename from tests/wipy/wlan/server.py.exp rename to tests/ports/cc3200/wlan/server.py.exp diff --git a/tests/wipy/wlan/wlan.py b/tests/ports/cc3200/wlan/wlan.py similarity index 100% rename from tests/wipy/wlan/wlan.py rename to tests/ports/cc3200/wlan/wlan.py diff --git a/tests/wipy/wlan/wlan.py.exp b/tests/ports/cc3200/wlan/wlan.py.exp similarity index 100% rename from tests/wipy/wlan/wlan.py.exp rename to tests/ports/cc3200/wlan/wlan.py.exp diff --git a/tests/esp32/check_err_str.py b/tests/ports/esp32/check_err_str.py similarity index 100% rename from tests/esp32/check_err_str.py rename to tests/ports/esp32/check_err_str.py diff --git a/tests/esp32/check_err_str.py.exp b/tests/ports/esp32/check_err_str.py.exp similarity index 100% rename from tests/esp32/check_err_str.py.exp rename to tests/ports/esp32/check_err_str.py.exp diff --git a/tests/esp32/esp32_idf_heap_info.py b/tests/ports/esp32/esp32_idf_heap_info.py similarity index 100% rename from tests/esp32/esp32_idf_heap_info.py rename to tests/ports/esp32/esp32_idf_heap_info.py diff --git a/tests/esp32/esp32_idf_heap_info.py.exp b/tests/ports/esp32/esp32_idf_heap_info.py.exp similarity index 100% rename from tests/esp32/esp32_idf_heap_info.py.exp rename to tests/ports/esp32/esp32_idf_heap_info.py.exp diff --git a/tests/esp32/esp32_nvs.py b/tests/ports/esp32/esp32_nvs.py similarity index 100% rename from tests/esp32/esp32_nvs.py rename to tests/ports/esp32/esp32_nvs.py diff --git a/tests/esp32/esp32_nvs.py.exp b/tests/ports/esp32/esp32_nvs.py.exp similarity index 100% rename from tests/esp32/esp32_nvs.py.exp rename to tests/ports/esp32/esp32_nvs.py.exp diff --git a/tests/esp32/partition_ota.py b/tests/ports/esp32/partition_ota.py similarity index 100% rename from tests/esp32/partition_ota.py rename to tests/ports/esp32/partition_ota.py diff --git a/tests/esp32/partition_ota.py.exp b/tests/ports/esp32/partition_ota.py.exp similarity index 100% rename from tests/esp32/partition_ota.py.exp rename to tests/ports/esp32/partition_ota.py.exp diff --git a/tests/esp32/resolve_on_connect.py b/tests/ports/esp32/resolve_on_connect.py similarity index 100% rename from tests/esp32/resolve_on_connect.py rename to tests/ports/esp32/resolve_on_connect.py diff --git a/tests/qemu-arm/asm_test.py b/tests/ports/qemu-arm/asm_test.py similarity index 100% rename from tests/qemu-arm/asm_test.py rename to tests/ports/qemu-arm/asm_test.py diff --git a/tests/qemu-arm/asm_test.py.exp b/tests/ports/qemu-arm/asm_test.py.exp similarity index 100% rename from tests/qemu-arm/asm_test.py.exp rename to tests/ports/qemu-arm/asm_test.py.exp diff --git a/tests/qemu-arm/native_test.py b/tests/ports/qemu-arm/native_test.py similarity index 100% rename from tests/qemu-arm/native_test.py rename to tests/ports/qemu-arm/native_test.py diff --git a/tests/qemu-arm/native_test.py.exp b/tests/ports/qemu-arm/native_test.py.exp similarity index 100% rename from tests/qemu-arm/native_test.py.exp rename to tests/ports/qemu-arm/native_test.py.exp diff --git a/tests/qemu-arm/viper_test.py b/tests/ports/qemu-arm/viper_test.py similarity index 100% rename from tests/qemu-arm/viper_test.py rename to tests/ports/qemu-arm/viper_test.py diff --git a/tests/qemu-arm/viper_test.py.exp b/tests/ports/qemu-arm/viper_test.py.exp similarity index 100% rename from tests/qemu-arm/viper_test.py.exp rename to tests/ports/qemu-arm/viper_test.py.exp diff --git a/tests/renesas-ra/freq.py b/tests/ports/renesas-ra/freq.py similarity index 100% rename from tests/renesas-ra/freq.py rename to tests/ports/renesas-ra/freq.py diff --git a/tests/renesas-ra/freq.py.exp b/tests/ports/renesas-ra/freq.py.exp similarity index 100% rename from tests/renesas-ra/freq.py.exp rename to tests/ports/renesas-ra/freq.py.exp diff --git a/tests/renesas-ra/i2c.py b/tests/ports/renesas-ra/i2c.py similarity index 100% rename from tests/renesas-ra/i2c.py rename to tests/ports/renesas-ra/i2c.py diff --git a/tests/renesas-ra/i2c.py.exp b/tests/ports/renesas-ra/i2c.py.exp similarity index 100% rename from tests/renesas-ra/i2c.py.exp rename to tests/ports/renesas-ra/i2c.py.exp diff --git a/tests/pyb/modtime.py b/tests/ports/renesas-ra/modtime.py similarity index 100% rename from tests/pyb/modtime.py rename to tests/ports/renesas-ra/modtime.py diff --git a/tests/pyb/modtime.py.exp b/tests/ports/renesas-ra/modtime.py.exp similarity index 100% rename from tests/pyb/modtime.py.exp rename to tests/ports/renesas-ra/modtime.py.exp diff --git a/tests/renesas-ra/pin.py b/tests/ports/renesas-ra/pin.py similarity index 100% rename from tests/renesas-ra/pin.py rename to tests/ports/renesas-ra/pin.py diff --git a/tests/renesas-ra/pin.py.exp b/tests/ports/renesas-ra/pin.py.exp similarity index 100% rename from tests/renesas-ra/pin.py.exp rename to tests/ports/renesas-ra/pin.py.exp diff --git a/tests/renesas-ra/rtc_init.py b/tests/ports/renesas-ra/rtc_init.py similarity index 100% rename from tests/renesas-ra/rtc_init.py rename to tests/ports/renesas-ra/rtc_init.py diff --git a/tests/renesas-ra/rtc_init.py.exp b/tests/ports/renesas-ra/rtc_init.py.exp similarity index 100% rename from tests/renesas-ra/rtc_init.py.exp rename to tests/ports/renesas-ra/rtc_init.py.exp diff --git a/tests/renesas-ra/spi.py b/tests/ports/renesas-ra/spi.py similarity index 100% rename from tests/renesas-ra/spi.py rename to tests/ports/renesas-ra/spi.py diff --git a/tests/renesas-ra/spi.py.exp b/tests/ports/renesas-ra/spi.py.exp similarity index 100% rename from tests/renesas-ra/spi.py.exp rename to tests/ports/renesas-ra/spi.py.exp diff --git a/tests/renesas-ra/uart1.py b/tests/ports/renesas-ra/uart1.py similarity index 100% rename from tests/renesas-ra/uart1.py rename to tests/ports/renesas-ra/uart1.py diff --git a/tests/renesas-ra/uart1.py.exp b/tests/ports/renesas-ra/uart1.py.exp similarity index 100% rename from tests/renesas-ra/uart1.py.exp rename to tests/ports/renesas-ra/uart1.py.exp diff --git a/tests/pyb/accel.py b/tests/ports/stm32/accel.py similarity index 100% rename from tests/pyb/accel.py rename to tests/ports/stm32/accel.py diff --git a/tests/pyb/accel.py.exp b/tests/ports/stm32/accel.py.exp similarity index 100% rename from tests/pyb/accel.py.exp rename to tests/ports/stm32/accel.py.exp diff --git a/tests/pyb/adc.py b/tests/ports/stm32/adc.py similarity index 100% rename from tests/pyb/adc.py rename to tests/ports/stm32/adc.py diff --git a/tests/pyb/adc.py.exp b/tests/ports/stm32/adc.py.exp similarity index 100% rename from tests/pyb/adc.py.exp rename to tests/ports/stm32/adc.py.exp diff --git a/tests/pyb/adcall.py b/tests/ports/stm32/adcall.py similarity index 100% rename from tests/pyb/adcall.py rename to tests/ports/stm32/adcall.py diff --git a/tests/pyb/adcall.py.exp b/tests/ports/stm32/adcall.py.exp similarity index 100% rename from tests/pyb/adcall.py.exp rename to tests/ports/stm32/adcall.py.exp diff --git a/tests/pyb/board_pybv1x.py b/tests/ports/stm32/board_pybv1x.py similarity index 100% rename from tests/pyb/board_pybv1x.py rename to tests/ports/stm32/board_pybv1x.py diff --git a/tests/pyb/board_pybv1x.py.exp b/tests/ports/stm32/board_pybv1x.py.exp similarity index 100% rename from tests/pyb/board_pybv1x.py.exp rename to tests/ports/stm32/board_pybv1x.py.exp diff --git a/tests/pyb/can.py b/tests/ports/stm32/can.py similarity index 100% rename from tests/pyb/can.py rename to tests/ports/stm32/can.py diff --git a/tests/pyb/can.py.exp b/tests/ports/stm32/can.py.exp similarity index 100% rename from tests/pyb/can.py.exp rename to tests/ports/stm32/can.py.exp diff --git a/tests/pyb/can2.py b/tests/ports/stm32/can2.py similarity index 100% rename from tests/pyb/can2.py rename to tests/ports/stm32/can2.py diff --git a/tests/pyb/can2.py.exp b/tests/ports/stm32/can2.py.exp similarity index 100% rename from tests/pyb/can2.py.exp rename to tests/ports/stm32/can2.py.exp diff --git a/tests/pyb/dac.py b/tests/ports/stm32/dac.py similarity index 100% rename from tests/pyb/dac.py rename to tests/ports/stm32/dac.py diff --git a/tests/pyb/dac.py.exp b/tests/ports/stm32/dac.py.exp similarity index 100% rename from tests/pyb/dac.py.exp rename to tests/ports/stm32/dac.py.exp diff --git a/tests/pyb/extint.py b/tests/ports/stm32/extint.py similarity index 100% rename from tests/pyb/extint.py rename to tests/ports/stm32/extint.py diff --git a/tests/pyb/extint.py.exp b/tests/ports/stm32/extint.py.exp similarity index 100% rename from tests/pyb/extint.py.exp rename to tests/ports/stm32/extint.py.exp diff --git a/tests/pyb/i2c.py b/tests/ports/stm32/i2c.py similarity index 100% rename from tests/pyb/i2c.py rename to tests/ports/stm32/i2c.py diff --git a/tests/pyb/i2c.py.exp b/tests/ports/stm32/i2c.py.exp similarity index 100% rename from tests/pyb/i2c.py.exp rename to tests/ports/stm32/i2c.py.exp diff --git a/tests/pyb/i2c_accel.py b/tests/ports/stm32/i2c_accel.py similarity index 100% rename from tests/pyb/i2c_accel.py rename to tests/ports/stm32/i2c_accel.py diff --git a/tests/pyb/i2c_accel.py.exp b/tests/ports/stm32/i2c_accel.py.exp similarity index 100% rename from tests/pyb/i2c_accel.py.exp rename to tests/ports/stm32/i2c_accel.py.exp diff --git a/tests/pyb/i2c_error.py b/tests/ports/stm32/i2c_error.py similarity index 100% rename from tests/pyb/i2c_error.py rename to tests/ports/stm32/i2c_error.py diff --git a/tests/pyb/i2c_error.py.exp b/tests/ports/stm32/i2c_error.py.exp similarity index 100% rename from tests/pyb/i2c_error.py.exp rename to tests/ports/stm32/i2c_error.py.exp diff --git a/tests/pyb/irq.py b/tests/ports/stm32/irq.py similarity index 100% rename from tests/pyb/irq.py rename to tests/ports/stm32/irq.py diff --git a/tests/pyb/irq.py.exp b/tests/ports/stm32/irq.py.exp similarity index 100% rename from tests/pyb/irq.py.exp rename to tests/ports/stm32/irq.py.exp diff --git a/tests/pyb/led.py b/tests/ports/stm32/led.py similarity index 100% rename from tests/pyb/led.py rename to tests/ports/stm32/led.py diff --git a/tests/pyb/led.py.exp b/tests/ports/stm32/led.py.exp similarity index 100% rename from tests/pyb/led.py.exp rename to tests/ports/stm32/led.py.exp diff --git a/tests/pyb/modstm.py b/tests/ports/stm32/modstm.py similarity index 100% rename from tests/pyb/modstm.py rename to tests/ports/stm32/modstm.py diff --git a/tests/pyb/modstm.py.exp b/tests/ports/stm32/modstm.py.exp similarity index 100% rename from tests/pyb/modstm.py.exp rename to tests/ports/stm32/modstm.py.exp diff --git a/tests/renesas-ra/modtime.py b/tests/ports/stm32/modtime.py similarity index 100% rename from tests/renesas-ra/modtime.py rename to tests/ports/stm32/modtime.py diff --git a/tests/renesas-ra/modtime.py.exp b/tests/ports/stm32/modtime.py.exp similarity index 100% rename from tests/renesas-ra/modtime.py.exp rename to tests/ports/stm32/modtime.py.exp diff --git a/tests/pyb/pin.py b/tests/ports/stm32/pin.py similarity index 100% rename from tests/pyb/pin.py rename to tests/ports/stm32/pin.py diff --git a/tests/pyb/pin.py.exp b/tests/ports/stm32/pin.py.exp similarity index 100% rename from tests/pyb/pin.py.exp rename to tests/ports/stm32/pin.py.exp diff --git a/tests/pyb/pyb1.py b/tests/ports/stm32/pyb1.py similarity index 100% rename from tests/pyb/pyb1.py rename to tests/ports/stm32/pyb1.py diff --git a/tests/pyb/pyb1.py.exp b/tests/ports/stm32/pyb1.py.exp similarity index 100% rename from tests/pyb/pyb1.py.exp rename to tests/ports/stm32/pyb1.py.exp diff --git a/tests/pyb/pyb_f405.py b/tests/ports/stm32/pyb_f405.py similarity index 100% rename from tests/pyb/pyb_f405.py rename to tests/ports/stm32/pyb_f405.py diff --git a/tests/pyb/pyb_f405.py.exp b/tests/ports/stm32/pyb_f405.py.exp similarity index 100% rename from tests/pyb/pyb_f405.py.exp rename to tests/ports/stm32/pyb_f405.py.exp diff --git a/tests/pyb/pyb_f411.py b/tests/ports/stm32/pyb_f411.py similarity index 100% rename from tests/pyb/pyb_f411.py rename to tests/ports/stm32/pyb_f411.py diff --git a/tests/pyb/pyb_f411.py.exp b/tests/ports/stm32/pyb_f411.py.exp similarity index 100% rename from tests/pyb/pyb_f411.py.exp rename to tests/ports/stm32/pyb_f411.py.exp diff --git a/tests/pyb/rtc.py b/tests/ports/stm32/rtc.py similarity index 100% rename from tests/pyb/rtc.py rename to tests/ports/stm32/rtc.py diff --git a/tests/pyb/rtc.py.exp b/tests/ports/stm32/rtc.py.exp similarity index 100% rename from tests/pyb/rtc.py.exp rename to tests/ports/stm32/rtc.py.exp diff --git a/tests/pyb/servo.py b/tests/ports/stm32/servo.py similarity index 100% rename from tests/pyb/servo.py rename to tests/ports/stm32/servo.py diff --git a/tests/pyb/servo.py.exp b/tests/ports/stm32/servo.py.exp similarity index 100% rename from tests/pyb/servo.py.exp rename to tests/ports/stm32/servo.py.exp diff --git a/tests/pyb/spi.py b/tests/ports/stm32/spi.py similarity index 100% rename from tests/pyb/spi.py rename to tests/ports/stm32/spi.py diff --git a/tests/pyb/spi.py.exp b/tests/ports/stm32/spi.py.exp similarity index 100% rename from tests/pyb/spi.py.exp rename to tests/ports/stm32/spi.py.exp diff --git a/tests/pyb/switch.py b/tests/ports/stm32/switch.py similarity index 100% rename from tests/pyb/switch.py rename to tests/ports/stm32/switch.py diff --git a/tests/pyb/switch.py.exp b/tests/ports/stm32/switch.py.exp similarity index 100% rename from tests/pyb/switch.py.exp rename to tests/ports/stm32/switch.py.exp diff --git a/tests/pyb/timer.py b/tests/ports/stm32/timer.py similarity index 100% rename from tests/pyb/timer.py rename to tests/ports/stm32/timer.py diff --git a/tests/pyb/timer.py.exp b/tests/ports/stm32/timer.py.exp similarity index 100% rename from tests/pyb/timer.py.exp rename to tests/ports/stm32/timer.py.exp diff --git a/tests/pyb/timer_callback.py b/tests/ports/stm32/timer_callback.py similarity index 100% rename from tests/pyb/timer_callback.py rename to tests/ports/stm32/timer_callback.py diff --git a/tests/pyb/timer_callback.py.exp b/tests/ports/stm32/timer_callback.py.exp similarity index 100% rename from tests/pyb/timer_callback.py.exp rename to tests/ports/stm32/timer_callback.py.exp diff --git a/tests/pyb/uart.py b/tests/ports/stm32/uart.py similarity index 100% rename from tests/pyb/uart.py rename to tests/ports/stm32/uart.py diff --git a/tests/pyb/uart.py.exp b/tests/ports/stm32/uart.py.exp similarity index 100% rename from tests/pyb/uart.py.exp rename to tests/ports/stm32/uart.py.exp diff --git a/tests/unix/extra_coverage.py b/tests/ports/unix/extra_coverage.py similarity index 100% rename from tests/unix/extra_coverage.py rename to tests/ports/unix/extra_coverage.py diff --git a/tests/unix/extra_coverage.py.exp b/tests/ports/unix/extra_coverage.py.exp similarity index 100% rename from tests/unix/extra_coverage.py.exp rename to tests/ports/unix/extra_coverage.py.exp diff --git a/tests/unix/ffi_callback.py b/tests/ports/unix/ffi_callback.py similarity index 100% rename from tests/unix/ffi_callback.py rename to tests/ports/unix/ffi_callback.py diff --git a/tests/unix/ffi_callback.py.exp b/tests/ports/unix/ffi_callback.py.exp similarity index 100% rename from tests/unix/ffi_callback.py.exp rename to tests/ports/unix/ffi_callback.py.exp diff --git a/tests/unix/ffi_float.py b/tests/ports/unix/ffi_float.py similarity index 100% rename from tests/unix/ffi_float.py rename to tests/ports/unix/ffi_float.py diff --git a/tests/unix/ffi_float.py.exp b/tests/ports/unix/ffi_float.py.exp similarity index 100% rename from tests/unix/ffi_float.py.exp rename to tests/ports/unix/ffi_float.py.exp diff --git a/tests/unix/ffi_float2.py b/tests/ports/unix/ffi_float2.py similarity index 100% rename from tests/unix/ffi_float2.py rename to tests/ports/unix/ffi_float2.py diff --git a/tests/unix/ffi_float2.py.exp b/tests/ports/unix/ffi_float2.py.exp similarity index 100% rename from tests/unix/ffi_float2.py.exp rename to tests/ports/unix/ffi_float2.py.exp diff --git a/tests/unix/ffi_lib.c b/tests/ports/unix/ffi_lib.c similarity index 100% rename from tests/unix/ffi_lib.c rename to tests/ports/unix/ffi_lib.c diff --git a/tests/unix/ffi_types.py b/tests/ports/unix/ffi_types.py similarity index 100% rename from tests/unix/ffi_types.py rename to tests/ports/unix/ffi_types.py diff --git a/tests/unix/ffi_types.py.exp b/tests/ports/unix/ffi_types.py.exp similarity index 100% rename from tests/unix/ffi_types.py.exp rename to tests/ports/unix/ffi_types.py.exp diff --git a/tests/unix/mod_os.py b/tests/ports/unix/mod_os.py similarity index 100% rename from tests/unix/mod_os.py rename to tests/ports/unix/mod_os.py diff --git a/tests/unix/mod_os.py.exp b/tests/ports/unix/mod_os.py.exp similarity index 100% rename from tests/unix/mod_os.py.exp rename to tests/ports/unix/mod_os.py.exp diff --git a/tests/unix/time_mktime_localtime.py b/tests/ports/unix/time_mktime_localtime.py similarity index 100% rename from tests/unix/time_mktime_localtime.py rename to tests/ports/unix/time_mktime_localtime.py diff --git a/tests/run-tests.py b/tests/run-tests.py index 4d4c2543b2f59..39f2d73a2078a 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -183,7 +183,7 @@ def run_script_on_remote_target(pyb, args, test_file, is_special): "basics/bytes_compare3.py", "basics/builtin_help.py", "thread/thread_exc2.py", - "esp32/partition_ota.py", + "ports/esp32/partition_ota.py", ) ] @@ -1036,16 +1036,16 @@ def main(): ) if args.target == "pyboard": # run pyboard tests - test_dirs += ("float", "stress", "pyb", "inlineasm") + test_dirs += ("float", "stress", "inlineasm", "ports/stm32") elif args.target in ("renesas-ra"): - test_dirs += ("float", "inlineasm", "renesas-ra") + test_dirs += ("float", "inlineasm", "ports/renesas-ra") elif args.target == "rp2": test_dirs += ("float", "stress", "inlineasm", "thread") elif args.target in ("esp8266", "esp32", "minimal", "nrf"): test_dirs += ("float",) elif args.target == "wipy": # run WiPy tests - test_dirs += ("wipy",) + test_dirs += ("ports/cc3200",) elif args.target == "unix": # run PC tests test_dirs += ( @@ -1054,8 +1054,8 @@ def main(): "io", "stress", "unicode", - "unix", "cmdline", + "ports/unix", ) elif args.target == "qemu-arm": if not args.write_exp: @@ -1065,7 +1065,7 @@ def main(): test_dirs += ( "float", "inlineasm", - "qemu-arm", + "ports/qemu-arm", ) else: # run tests from these directories diff --git a/tools/ci.sh b/tools/ci.sh index 95b1f19ffc4a6..e18027ae5addb 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -415,7 +415,7 @@ function ci_unix_build_helper { } function ci_unix_build_ffi_lib_helper { - $1 $2 -shared -o tests/unix/ffi_lib.so tests/unix/ffi_lib.c + $1 $2 -shared -o tests/ports/unix/ffi_lib.so tests/ports/unix/ffi_lib.c } function ci_unix_run_tests_helper { From 50b809c8e8bb909b2d69e91f5d2eab2e16d3636e Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 18 Jan 2024 16:36:22 +1100 Subject: [PATCH 053/408] tests/ports/rp2: Add rp2-specific tests with a test for rp2.DMA. Signed-off-by: Damien George --- tests/ports/rp2/rp2_dma.py | 90 ++++++++++++++++++++++++++++++++++ tests/ports/rp2/rp2_dma.py.exp | 16 ++++++ tests/run-tests.py | 2 +- 3 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 tests/ports/rp2/rp2_dma.py create mode 100644 tests/ports/rp2/rp2_dma.py.exp diff --git a/tests/ports/rp2/rp2_dma.py b/tests/ports/rp2/rp2_dma.py new file mode 100644 index 0000000000000..cd97f0357b788 --- /dev/null +++ b/tests/ports/rp2/rp2_dma.py @@ -0,0 +1,90 @@ +# Test rp2.DMA functionality. + +import time +import machine +import rp2 + +src = bytes(i & 0xFF for i in range(16 * 1024)) + +print("# test basic usage") + +dma = rp2.DMA() +print(dma) +print(rp2.DMA.unpack_ctrl(dma.pack_ctrl())) +dma.read = 0 +dma.write = 0 +dma.count = 0 +dma.ctrl = dma.pack_ctrl() +print(dma.read, dma.write, dma.count, dma.ctrl & 0x01FFFFFF, dma.channel, dma.registers) +dma.close() + +# Test closing when already closed. +dma.close() + +# Test using when closed. +try: + dma.active() + assert False +except ValueError: + print("ValueError") + +# Test simple memory copy. +print("# test memory copy") +dest = bytearray(1024) +dma = rp2.DMA() +dma.config(read=src, write=dest, count=len(dest) // 4, ctrl=dma.pack_ctrl(), trigger=False) +print(not any(dest)) +dma.active(True) +while dma.active(): + pass +print(dest[:8], dest[-8:]) +dma.close() + + +# Test time taken for a large memory copy. +def run_and_time_dma(dma): + ticks_us = time.ticks_us + irq_state = machine.disable_irq() + t0 = ticks_us() + dma.active(True) + while dma.active(): + pass + t1 = ticks_us() + machine.enable_irq(irq_state) + return time.ticks_diff(t1, t0) + + +print("# test timing") +dest = bytearray(16 * 1024) +dma = rp2.DMA() +dma.read = src +dma.write = dest +dma.count = len(dest) // 4 +dma.ctrl = dma.pack_ctrl() +dt = run_and_time_dma(dma) +print(60 <= dt <= 90) +print(dest[:8], dest[-8:]) +dma.close() + +# Test using .config(trigger=True). +print("# test immediate trigger") +dest = bytearray(1024) +dma = rp2.DMA() +dma.config(read=src, write=dest, count=len(dest) // 4, ctrl=dma.pack_ctrl(), trigger=True) +while dma.active(): + pass +print(dest[:8], dest[-8:]) +dma.close() + +# Test the DMA.irq() method. +print("# test irq") +dest = bytearray(1024) +dma = rp2.DMA() +dma.irq(lambda _: print("irq fired")) +dma.config( + read=src, write=dest, count=len(dest) // 4, ctrl=dma.pack_ctrl(irq_quiet=0), trigger=True +) +while dma.active(): + pass +print(dest[:8], dest[-8:]) +dma.close() diff --git a/tests/ports/rp2/rp2_dma.py.exp b/tests/ports/rp2/rp2_dma.py.exp new file mode 100644 index 0000000000000..956aee4e34c1f --- /dev/null +++ b/tests/ports/rp2/rp2_dma.py.exp @@ -0,0 +1,16 @@ +# test basic usage +DMA(0) +{'inc_read': 1, 'high_pri': 0, 'write_err': 0, 'ring_sel': 0, 'enable': 1, 'treq_sel': 63, 'sniff_en': 0, 'irq_quiet': 1, 'read_err': 0, 'chain_to': 0, 'busy': 0, 'inc_write': 1, 'ring_size': 0, 'bswap': 0, 'size': 2, 'ahb_err': 0} +0 0 0 4161593 0 +ValueError +# test memory copy +True +bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07') bytearray(b'\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff') +# test timing +True +bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07') bytearray(b'\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff') +# test immediate trigger +bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07') bytearray(b'\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff') +# test irq +irq fired +bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07') bytearray(b'\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff') diff --git a/tests/run-tests.py b/tests/run-tests.py index 39f2d73a2078a..ecd49a7d75fea 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -1040,7 +1040,7 @@ def main(): elif args.target in ("renesas-ra"): test_dirs += ("float", "inlineasm", "ports/renesas-ra") elif args.target == "rp2": - test_dirs += ("float", "stress", "inlineasm", "thread") + test_dirs += ("float", "stress", "inlineasm", "thread", "ports/rp2") elif args.target in ("esp8266", "esp32", "minimal", "nrf"): test_dirs += ("float",) elif args.target == "wipy": From 51fbec2780b9c095c7eabdabab043c30dbb99d1d Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 18 Jan 2024 16:36:47 +1100 Subject: [PATCH 054/408] tests/extmod/machine_i2s_rate.py: Test multiple I2S instances. Signed-off-by: Damien George --- tests/extmod/machine_i2s_rate.py | 66 +++++++++++++++++++------------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/tests/extmod/machine_i2s_rate.py b/tests/extmod/machine_i2s_rate.py index d2cd1ae105f8f..bf4b7235a9cdf 100644 --- a/tests/extmod/machine_i2s_rate.py +++ b/tests/extmod/machine_i2s_rate.py @@ -9,28 +9,28 @@ import time, sys # Configure pins based on the board. +# A board must have at least one instance to test, both TX and RX mode. if "pyboard" in sys.platform: - i2s_id = 2 - sck_pin = Pin("Y6") - ws_pin = Pin("Y5") - sd_tx_pin = sd_rx_pin = Pin("Y8") + i2s_instances = ((2, Pin("Y6"), Pin("Y5"), Pin("Y8"), Pin("Y8")),) elif "rp2" in sys.platform: - i2s_id = 1 - sck_pin = Pin(0) - ws_pin = Pin(1) - sd_tx_pin = sd_rx_pin = Pin(2) + i2s_instances = ( + (0, Pin(0), Pin(1), Pin(2), Pin(2)), + (1, Pin(0), Pin(1), Pin(2), Pin(2)), + ) elif "mimxrt" in sys.platform: - i2s_id = 1 - sck_pin = Pin(26) - ws_pin = Pin(27) - sd_tx_pin = Pin(7) - sd_rx_pin = Pin(8) + i2s_instances = ( + (1, Pin("D26"), Pin("D27"), Pin("D7"), Pin("D8")), + (2, Pin("D4"), Pin("D3"), Pin("D2"), None), + ) TEST_BYTES = b"01234567" RATE = 11025 # frames/sec -def test(mode, sd_pin, bits_per_sample, frame_format): +def test(i2s_id, sck_pin, ws_pin, sd_pin, mode, bits_per_sample, frame_format): + if sd_pin is None: + return + i2s = I2S( i2s_id, sck=sck_pin, @@ -48,16 +48,16 @@ def test(mode, sd_pin, bits_per_sample, frame_format): else: channels = 2 bits_per_frame = bits_per_sample * channels - buf_len_250ms = bits_per_frame // 8 * RATE // 4 + buf_len_200ms = bits_per_frame // 8 * RATE // 5 # Create test data and preload I2S buffers. if mode == I2S.TX: mode_str = "TX" - data = TEST_BYTES * (buf_len_250ms // len(TEST_BYTES)) + data = TEST_BYTES * (buf_len_200ms // len(TEST_BYTES)) i2s.write(data) else: mode_str = "RX" - data = bytearray(len(TEST_BYTES) * (buf_len_250ms // len(TEST_BYTES))) + data = bytearray(len(TEST_BYTES) * (buf_len_200ms // len(TEST_BYTES))) i2s.readinto(data) # Time how long it takes to read/write 2 lots of data. @@ -72,15 +72,27 @@ def test(mode, sd_pin, bits_per_sample, frame_format): i2s.deinit() - # Print out test result, time should be in range of 500ms. - print(mode_str, bits_per_sample, channels, abs(dt - 500) <= 4) + # Time should be in range of 400ms. + time_in_range = abs(dt - 400) <= 4 + + # Print out test result if requested, or if time not in range. + if print_results or not time_in_range: + print(mode_str, bits_per_sample, channels, time_in_range) + + +print_results = True +for i2s_id, sck_pin, ws_pin, sd_tx_pin, sd_rx_pin in i2s_instances: + test(i2s_id, sck_pin, ws_pin, sd_tx_pin, I2S.TX, 16, I2S.MONO) + test(i2s_id, sck_pin, ws_pin, sd_tx_pin, I2S.TX, 16, I2S.STEREO) + test(i2s_id, sck_pin, ws_pin, sd_tx_pin, I2S.TX, 32, I2S.MONO) + test(i2s_id, sck_pin, ws_pin, sd_tx_pin, I2S.TX, 32, I2S.STEREO) + test(i2s_id, sck_pin, ws_pin, sd_rx_pin, I2S.RX, 16, I2S.MONO) + test(i2s_id, sck_pin, ws_pin, sd_rx_pin, I2S.RX, 16, I2S.STEREO) + test(i2s_id, sck_pin, ws_pin, sd_rx_pin, I2S.RX, 32, I2S.MONO) + test(i2s_id, sck_pin, ws_pin, sd_rx_pin, I2S.RX, 32, I2S.STEREO) -test(I2S.TX, sd_tx_pin, 16, I2S.MONO) -test(I2S.TX, sd_tx_pin, 16, I2S.STEREO) -test(I2S.TX, sd_tx_pin, 32, I2S.MONO) -test(I2S.TX, sd_tx_pin, 32, I2S.STEREO) -test(I2S.RX, sd_rx_pin, 16, I2S.MONO) -test(I2S.RX, sd_rx_pin, 16, I2S.STEREO) -test(I2S.RX, sd_rx_pin, 32, I2S.MONO) -test(I2S.RX, sd_rx_pin, 32, I2S.STEREO) + # For any remaining tests, don't print the results if they pass. + # This is to have the same output on all boards regardless of + # how many I2S instances they test. + print_results = False From 2ecbad4e91192c88f831d8690dbad31ddba72135 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 19 Jan 2024 10:07:51 +1100 Subject: [PATCH 055/408] extmod/asyncio: Support gather of tasks that finish early. Adds support to asyncio.gather() for the case that one or more (or all) sub-tasks finish and/or raise an exception before the gather starts. Signed-off-by: Damien George --- extmod/asyncio/core.py | 5 ++ extmod/asyncio/funcs.py | 49 +++++++++----- tests/extmod/asyncio_gather_finished_early.py | 65 +++++++++++++++++++ 3 files changed, 102 insertions(+), 17 deletions(-) create mode 100644 tests/extmod/asyncio_gather_finished_early.py diff --git a/extmod/asyncio/core.py b/extmod/asyncio/core.py index 214cc52f45f53..e5af3038f77bb 100644 --- a/extmod/asyncio/core.py +++ b/extmod/asyncio/core.py @@ -219,6 +219,11 @@ def run_until_complete(main_task=None): elif t.state is None: # Task is already finished and nothing await'ed on the task, # so call the exception handler. + + # Save exception raised by the coro for later use. + t.data = exc + + # Create exception context and call the exception handler. _exc_context["exception"] = exc _exc_context["future"] = t Loop.call_exception_handler(_exc_context) diff --git a/extmod/asyncio/funcs.py b/extmod/asyncio/funcs.py index 599091dfbdc2b..3ef8a76b1d151 100644 --- a/extmod/asyncio/funcs.py +++ b/extmod/asyncio/funcs.py @@ -63,9 +63,6 @@ def remove(t): # async def gather(*aws, return_exceptions=False): - if not aws: - return [] - def done(t, er): # Sub-task "t" has finished, with exception "er". nonlocal state @@ -86,26 +83,39 @@ def done(t, er): # Gather waiting is done, schedule the main gather task. core._task_queue.push(gather_task) + # Prepare the sub-tasks for the gather. + # The `state` variable counts the number of tasks to wait for, and can be negative + # if the gather should not run at all (because a task already had an exception). ts = [core._promote_to_task(aw) for aw in aws] + state = 0 for i in range(len(ts)): - if ts[i].state is not True: - # Task is not running, gather not currently supported for this case. + if ts[i].state is True: + # Task is running, register the callback to call when the task is done. + ts[i].state = done + state += 1 + elif not ts[i].state: + # Task finished already. + if not isinstance(ts[i].data, StopIteration): + # Task finished by raising an exception. + if not return_exceptions: + # Do not run this gather at all. + state = -len(ts) + else: + # Task being waited on, gather not currently supported for this case. raise RuntimeError("can't gather") - # Register the callback to call when the task is done. - ts[i].state = done # Set the state for execution of the gather. gather_task = core.cur_task - state = len(ts) cancel_all = False - # Wait for the a sub-task to need attention. - gather_task.data = _Remove - try: - yield - except core.CancelledError as er: - cancel_all = True - state = er + # Wait for a sub-task to need attention (if there are any to wait for). + if state > 0: + gather_task.data = _Remove + try: + yield + except core.CancelledError as er: + cancel_all = True + state = er # Clean up tasks. for i in range(len(ts)): @@ -118,8 +128,13 @@ def done(t, er): # Sub-task ran to completion, get its return value. ts[i] = ts[i].data.value else: - # Sub-task had an exception with return_exceptions==True, so get its exception. - ts[i] = ts[i].data + # Sub-task had an exception. + if return_exceptions: + # Get the sub-task exception to return in the list of return values. + ts[i] = ts[i].data + elif isinstance(state, int): + # Raise the sub-task exception, if there is not already an exception to raise. + state = ts[i].data # Either this gather was cancelled, or one of the sub-tasks raised an exception with # return_exceptions==False, so reraise the exception here. diff --git a/tests/extmod/asyncio_gather_finished_early.py b/tests/extmod/asyncio_gather_finished_early.py new file mode 100644 index 0000000000000..030e79e3571b5 --- /dev/null +++ b/tests/extmod/asyncio_gather_finished_early.py @@ -0,0 +1,65 @@ +# Test asyncio.gather() when a task is already finished before the gather starts. + +try: + import asyncio +except ImportError: + print("SKIP") + raise SystemExit + + +# CPython and MicroPython differ in when they signal (and print) that a task raised an +# uncaught exception. So define an empty custom_handler() to suppress this output. +def custom_handler(loop, context): + pass + + +async def task_that_finishes_early(id, event, fail): + print("task_that_finishes_early", id) + event.set() + if fail: + raise ValueError("intentional exception", id) + + +async def task_that_runs(): + for i in range(5): + print("task_that_runs", i) + await asyncio.sleep(0) + + +async def main(start_task_that_runs, task_fail, return_exceptions): + print("== start", start_task_that_runs, task_fail, return_exceptions) + + # Set exception handler to suppress exception output. + loop = asyncio.get_event_loop() + loop.set_exception_handler(custom_handler) + + # Create tasks. + event_a = asyncio.Event() + event_b = asyncio.Event() + tasks = [] + if start_task_that_runs: + tasks.append(asyncio.create_task(task_that_runs())) + tasks.append(asyncio.create_task(task_that_finishes_early("a", event_a, task_fail))) + tasks.append(asyncio.create_task(task_that_finishes_early("b", event_b, task_fail))) + + # Make sure task_that_finishes_early() are both done, before calling gather(). + await event_a.wait() + await event_b.wait() + + # Gather the tasks. + try: + result = "complete", await asyncio.gather(*tasks, return_exceptions=return_exceptions) + except Exception as er: + result = "exception", er, start_task_that_runs and tasks[0].done() + + # Wait for the final task to finish (if it was started). + if start_task_that_runs: + await tasks[0] + + # Print results. + print(result) + + +# Run the test in the 8 different combinations of its arguments. +for i in range(8): + asyncio.run(main(bool(i & 4), bool(i & 2), bool(i & 1))) From e2fa0c639528c84709fef237fc5d80ff970a4cd1 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Thu, 18 Jan 2024 16:16:20 +0200 Subject: [PATCH 056/408] lib/cmsis: Update to CMSIS 5.9.0. This update brings support for Cortex-M55 and Cortex-M85, zero and copy tables and more. Signed-off-by: iabdalkader --- lib/cmsis/inc/cachel1_armv7.h | 411 +++ lib/cmsis/inc/cmsis_armcc.h | 831 ++--- lib/cmsis/inc/cmsis_armclang.h | 1683 +++++----- lib/cmsis/inc/cmsis_armclang_ltm.h | 1646 +++++----- lib/cmsis/inc/cmsis_compiler.h | 12 + lib/cmsis/inc/cmsis_gcc.h | 2026 ++++++------ lib/cmsis/inc/cmsis_iccarm.h | 86 +- lib/cmsis/inc/cmsis_version.h | 8 +- lib/cmsis/inc/core_armv81mml.h | 2257 ++++++++++--- lib/cmsis/inc/core_armv8mbl.h | 426 ++- lib/cmsis/inc/core_armv8mml.h | 567 +++- lib/cmsis/inc/core_cm0.h | 15 +- lib/cmsis/inc/core_cm0plus.h | 23 +- lib/cmsis/inc/core_cm1.h | 3 + lib/cmsis/inc/core_cm23.h | 426 ++- lib/cmsis/inc/core_cm3.h | 39 +- lib/cmsis/inc/core_cm33.h | 562 +++- lib/cmsis/inc/core_cm35p.h | 562 +++- lib/cmsis/inc/core_cm4.h | 34 +- lib/cmsis/inc/core_cm55.h | 4817 ++++++++++++++++++++++++++++ lib/cmsis/inc/core_cm7.h | 395 +-- lib/cmsis/inc/core_cm85.h | 4672 +++++++++++++++++++++++++++ lib/cmsis/inc/core_sc000.h | 16 +- lib/cmsis/inc/core_sc300.h | 68 +- lib/cmsis/inc/core_starmc1.h | 3592 +++++++++++++++++++++ lib/cmsis/inc/mpu_armv7.h | 17 +- lib/cmsis/inc/mpu_armv8.h | 36 +- lib/cmsis/inc/pac_armv81.h | 206 ++ lib/cmsis/inc/pmu_armv8.h | 337 ++ 29 files changed, 21432 insertions(+), 4341 deletions(-) create mode 100644 lib/cmsis/inc/cachel1_armv7.h create mode 100644 lib/cmsis/inc/core_cm55.h create mode 100644 lib/cmsis/inc/core_cm85.h create mode 100644 lib/cmsis/inc/core_starmc1.h create mode 100644 lib/cmsis/inc/pac_armv81.h create mode 100644 lib/cmsis/inc/pmu_armv8.h diff --git a/lib/cmsis/inc/cachel1_armv7.h b/lib/cmsis/inc/cachel1_armv7.h new file mode 100644 index 0000000000000..abebc95f94602 --- /dev/null +++ b/lib/cmsis/inc/cachel1_armv7.h @@ -0,0 +1,411 @@ +/****************************************************************************** + * @file cachel1_armv7.h + * @brief CMSIS Level 1 Cache API for Armv7-M and later + * @version V1.0.1 + * @date 19. April 2021 + ******************************************************************************/ +/* + * Copyright (c) 2020-2021 Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 + * + * 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. + */ + +#if defined ( __ICCARM__ ) + #pragma system_include /* treat file as system include file for MISRA check */ +#elif defined (__clang__) + #pragma clang system_header /* treat file as system include file */ +#endif + +#ifndef ARM_CACHEL1_ARMV7_H +#define ARM_CACHEL1_ARMV7_H + +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_CacheFunctions Cache Functions + \brief Functions that configure Instruction and Data cache. + @{ + */ + +/* Cache Size ID Register Macros */ +#define CCSIDR_WAYS(x) (((x) & SCB_CCSIDR_ASSOCIATIVITY_Msk) >> SCB_CCSIDR_ASSOCIATIVITY_Pos) +#define CCSIDR_SETS(x) (((x) & SCB_CCSIDR_NUMSETS_Msk ) >> SCB_CCSIDR_NUMSETS_Pos ) + +#ifndef __SCB_DCACHE_LINE_SIZE +#define __SCB_DCACHE_LINE_SIZE 32U /*!< Cortex-M7 cache line size is fixed to 32 bytes (8 words). See also register SCB_CCSIDR */ +#endif + +#ifndef __SCB_ICACHE_LINE_SIZE +#define __SCB_ICACHE_LINE_SIZE 32U /*!< Cortex-M7 cache line size is fixed to 32 bytes (8 words). See also register SCB_CCSIDR */ +#endif + +/** + \brief Enable I-Cache + \details Turns on I-Cache + */ +__STATIC_FORCEINLINE void SCB_EnableICache (void) +{ + #if defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U) + if (SCB->CCR & SCB_CCR_IC_Msk) return; /* return if ICache is already enabled */ + + __DSB(); + __ISB(); + SCB->ICIALLU = 0UL; /* invalidate I-Cache */ + __DSB(); + __ISB(); + SCB->CCR |= (uint32_t)SCB_CCR_IC_Msk; /* enable I-Cache */ + __DSB(); + __ISB(); + #endif +} + + +/** + \brief Disable I-Cache + \details Turns off I-Cache + */ +__STATIC_FORCEINLINE void SCB_DisableICache (void) +{ + #if defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U) + __DSB(); + __ISB(); + SCB->CCR &= ~(uint32_t)SCB_CCR_IC_Msk; /* disable I-Cache */ + SCB->ICIALLU = 0UL; /* invalidate I-Cache */ + __DSB(); + __ISB(); + #endif +} + + +/** + \brief Invalidate I-Cache + \details Invalidates I-Cache + */ +__STATIC_FORCEINLINE void SCB_InvalidateICache (void) +{ + #if defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U) + __DSB(); + __ISB(); + SCB->ICIALLU = 0UL; + __DSB(); + __ISB(); + #endif +} + + +/** + \brief I-Cache Invalidate by address + \details Invalidates I-Cache for the given address. + I-Cache is invalidated starting from a 32 byte aligned address in 32 byte granularity. + I-Cache memory blocks which are part of given address + given size are invalidated. + \param[in] addr address + \param[in] isize size of memory block (in number of bytes) +*/ +__STATIC_FORCEINLINE void SCB_InvalidateICache_by_Addr (volatile void *addr, int32_t isize) +{ + #if defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U) + if ( isize > 0 ) { + int32_t op_size = isize + (((uint32_t)addr) & (__SCB_ICACHE_LINE_SIZE - 1U)); + uint32_t op_addr = (uint32_t)addr /* & ~(__SCB_ICACHE_LINE_SIZE - 1U) */; + + __DSB(); + + do { + SCB->ICIMVAU = op_addr; /* register accepts only 32byte aligned values, only bits 31..5 are valid */ + op_addr += __SCB_ICACHE_LINE_SIZE; + op_size -= __SCB_ICACHE_LINE_SIZE; + } while ( op_size > 0 ); + + __DSB(); + __ISB(); + } + #endif +} + + +/** + \brief Enable D-Cache + \details Turns on D-Cache + */ +__STATIC_FORCEINLINE void SCB_EnableDCache (void) +{ + #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) + uint32_t ccsidr; + uint32_t sets; + uint32_t ways; + + if (SCB->CCR & SCB_CCR_DC_Msk) return; /* return if DCache is already enabled */ + + SCB->CSSELR = 0U; /* select Level 1 data cache */ + __DSB(); + + ccsidr = SCB->CCSIDR; + + /* invalidate D-Cache */ + sets = (uint32_t)(CCSIDR_SETS(ccsidr)); + do { + ways = (uint32_t)(CCSIDR_WAYS(ccsidr)); + do { + SCB->DCISW = (((sets << SCB_DCISW_SET_Pos) & SCB_DCISW_SET_Msk) | + ((ways << SCB_DCISW_WAY_Pos) & SCB_DCISW_WAY_Msk) ); + #if defined ( __CC_ARM ) + __schedule_barrier(); + #endif + } while (ways-- != 0U); + } while(sets-- != 0U); + __DSB(); + + SCB->CCR |= (uint32_t)SCB_CCR_DC_Msk; /* enable D-Cache */ + + __DSB(); + __ISB(); + #endif +} + + +/** + \brief Disable D-Cache + \details Turns off D-Cache + */ +__STATIC_FORCEINLINE void SCB_DisableDCache (void) +{ + #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) + uint32_t ccsidr; + uint32_t sets; + uint32_t ways; + + SCB->CSSELR = 0U; /* select Level 1 data cache */ + __DSB(); + + SCB->CCR &= ~(uint32_t)SCB_CCR_DC_Msk; /* disable D-Cache */ + __DSB(); + + ccsidr = SCB->CCSIDR; + + /* clean & invalidate D-Cache */ + sets = (uint32_t)(CCSIDR_SETS(ccsidr)); + do { + ways = (uint32_t)(CCSIDR_WAYS(ccsidr)); + do { + SCB->DCCISW = (((sets << SCB_DCCISW_SET_Pos) & SCB_DCCISW_SET_Msk) | + ((ways << SCB_DCCISW_WAY_Pos) & SCB_DCCISW_WAY_Msk) ); + #if defined ( __CC_ARM ) + __schedule_barrier(); + #endif + } while (ways-- != 0U); + } while(sets-- != 0U); + + __DSB(); + __ISB(); + #endif +} + + +/** + \brief Invalidate D-Cache + \details Invalidates D-Cache + */ +__STATIC_FORCEINLINE void SCB_InvalidateDCache (void) +{ + #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) + uint32_t ccsidr; + uint32_t sets; + uint32_t ways; + + SCB->CSSELR = 0U; /* select Level 1 data cache */ + __DSB(); + + ccsidr = SCB->CCSIDR; + + /* invalidate D-Cache */ + sets = (uint32_t)(CCSIDR_SETS(ccsidr)); + do { + ways = (uint32_t)(CCSIDR_WAYS(ccsidr)); + do { + SCB->DCISW = (((sets << SCB_DCISW_SET_Pos) & SCB_DCISW_SET_Msk) | + ((ways << SCB_DCISW_WAY_Pos) & SCB_DCISW_WAY_Msk) ); + #if defined ( __CC_ARM ) + __schedule_barrier(); + #endif + } while (ways-- != 0U); + } while(sets-- != 0U); + + __DSB(); + __ISB(); + #endif +} + + +/** + \brief Clean D-Cache + \details Cleans D-Cache + */ +__STATIC_FORCEINLINE void SCB_CleanDCache (void) +{ + #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) + uint32_t ccsidr; + uint32_t sets; + uint32_t ways; + + SCB->CSSELR = 0U; /* select Level 1 data cache */ + __DSB(); + + ccsidr = SCB->CCSIDR; + + /* clean D-Cache */ + sets = (uint32_t)(CCSIDR_SETS(ccsidr)); + do { + ways = (uint32_t)(CCSIDR_WAYS(ccsidr)); + do { + SCB->DCCSW = (((sets << SCB_DCCSW_SET_Pos) & SCB_DCCSW_SET_Msk) | + ((ways << SCB_DCCSW_WAY_Pos) & SCB_DCCSW_WAY_Msk) ); + #if defined ( __CC_ARM ) + __schedule_barrier(); + #endif + } while (ways-- != 0U); + } while(sets-- != 0U); + + __DSB(); + __ISB(); + #endif +} + + +/** + \brief Clean & Invalidate D-Cache + \details Cleans and Invalidates D-Cache + */ +__STATIC_FORCEINLINE void SCB_CleanInvalidateDCache (void) +{ + #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) + uint32_t ccsidr; + uint32_t sets; + uint32_t ways; + + SCB->CSSELR = 0U; /* select Level 1 data cache */ + __DSB(); + + ccsidr = SCB->CCSIDR; + + /* clean & invalidate D-Cache */ + sets = (uint32_t)(CCSIDR_SETS(ccsidr)); + do { + ways = (uint32_t)(CCSIDR_WAYS(ccsidr)); + do { + SCB->DCCISW = (((sets << SCB_DCCISW_SET_Pos) & SCB_DCCISW_SET_Msk) | + ((ways << SCB_DCCISW_WAY_Pos) & SCB_DCCISW_WAY_Msk) ); + #if defined ( __CC_ARM ) + __schedule_barrier(); + #endif + } while (ways-- != 0U); + } while(sets-- != 0U); + + __DSB(); + __ISB(); + #endif +} + + +/** + \brief D-Cache Invalidate by address + \details Invalidates D-Cache for the given address. + D-Cache is invalidated starting from a 32 byte aligned address in 32 byte granularity. + D-Cache memory blocks which are part of given address + given size are invalidated. + \param[in] addr address + \param[in] dsize size of memory block (in number of bytes) +*/ +__STATIC_FORCEINLINE void SCB_InvalidateDCache_by_Addr (volatile void *addr, int32_t dsize) +{ + #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) + if ( dsize > 0 ) { + int32_t op_size = dsize + (((uint32_t)addr) & (__SCB_DCACHE_LINE_SIZE - 1U)); + uint32_t op_addr = (uint32_t)addr /* & ~(__SCB_DCACHE_LINE_SIZE - 1U) */; + + __DSB(); + + do { + SCB->DCIMVAC = op_addr; /* register accepts only 32byte aligned values, only bits 31..5 are valid */ + op_addr += __SCB_DCACHE_LINE_SIZE; + op_size -= __SCB_DCACHE_LINE_SIZE; + } while ( op_size > 0 ); + + __DSB(); + __ISB(); + } + #endif +} + + +/** + \brief D-Cache Clean by address + \details Cleans D-Cache for the given address + D-Cache is cleaned starting from a 32 byte aligned address in 32 byte granularity. + D-Cache memory blocks which are part of given address + given size are cleaned. + \param[in] addr address + \param[in] dsize size of memory block (in number of bytes) +*/ +__STATIC_FORCEINLINE void SCB_CleanDCache_by_Addr (volatile void *addr, int32_t dsize) +{ + #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) + if ( dsize > 0 ) { + int32_t op_size = dsize + (((uint32_t)addr) & (__SCB_DCACHE_LINE_SIZE - 1U)); + uint32_t op_addr = (uint32_t)addr /* & ~(__SCB_DCACHE_LINE_SIZE - 1U) */; + + __DSB(); + + do { + SCB->DCCMVAC = op_addr; /* register accepts only 32byte aligned values, only bits 31..5 are valid */ + op_addr += __SCB_DCACHE_LINE_SIZE; + op_size -= __SCB_DCACHE_LINE_SIZE; + } while ( op_size > 0 ); + + __DSB(); + __ISB(); + } + #endif +} + + +/** + \brief D-Cache Clean and Invalidate by address + \details Cleans and invalidates D_Cache for the given address + D-Cache is cleaned and invalidated starting from a 32 byte aligned address in 32 byte granularity. + D-Cache memory blocks which are part of given address + given size are cleaned and invalidated. + \param[in] addr address (aligned to 32-byte boundary) + \param[in] dsize size of memory block (in number of bytes) +*/ +__STATIC_FORCEINLINE void SCB_CleanInvalidateDCache_by_Addr (volatile void *addr, int32_t dsize) +{ + #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) + if ( dsize > 0 ) { + int32_t op_size = dsize + (((uint32_t)addr) & (__SCB_DCACHE_LINE_SIZE - 1U)); + uint32_t op_addr = (uint32_t)addr /* & ~(__SCB_DCACHE_LINE_SIZE - 1U) */; + + __DSB(); + + do { + SCB->DCCIMVAC = op_addr; /* register accepts only 32byte aligned values, only bits 31..5 are valid */ + op_addr += __SCB_DCACHE_LINE_SIZE; + op_size -= __SCB_DCACHE_LINE_SIZE; + } while ( op_size > 0 ); + + __DSB(); + __ISB(); + } + #endif +} + +/*@} end of CMSIS_Core_CacheFunctions */ + +#endif /* ARM_CACHEL1_ARMV7_H */ diff --git a/lib/cmsis/inc/cmsis_armcc.h b/lib/cmsis/inc/cmsis_armcc.h index 174d744033029..a955d4713911e 100644 --- a/lib/cmsis/inc/cmsis_armcc.h +++ b/lib/cmsis/inc/cmsis_armcc.h @@ -1,11 +1,11 @@ /**************************************************************************//** * @file cmsis_armcc.h * @brief CMSIS compiler ARMCC (Arm Compiler 5) header file - * @version V5.0.5 - * @date 14. December 2018 + * @version V5.3.2 + * @date 27. May 2021 ******************************************************************************/ /* - * Copyright (c) 2009-2018 Arm Limited. All rights reserved. + * Copyright (c) 2009-2021 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -46,6 +46,7 @@ /* __ARM_ARCH_8M_BASE__ not applicable */ /* __ARM_ARCH_8M_MAIN__ not applicable */ + /* __ARM_ARCH_8_1M_MAIN__ not applicable */ /* CMSIS compiler control DSP macros */ #if ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) @@ -62,9 +63,9 @@ #ifndef __STATIC_INLINE #define __STATIC_INLINE static __inline #endif -#ifndef __STATIC_FORCEINLINE +#ifndef __STATIC_FORCEINLINE #define __STATIC_FORCEINLINE static __forceinline -#endif +#endif #ifndef __NO_RETURN #define __NO_RETURN __declspec(noreturn) #endif @@ -104,279 +105,31 @@ #ifndef __RESTRICT #define __RESTRICT __restrict #endif +#ifndef __COMPILER_BARRIER + #define __COMPILER_BARRIER() __memory_changed() +#endif -/* ########################### Core Function Access ########################### */ -/** \ingroup CMSIS_Core_FunctionInterface - \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions - @{ - */ - -/** - \brief Enable IRQ Interrupts - \details Enables IRQ interrupts by clearing the I-bit in the CPSR. - Can only be executed in Privileged modes. - */ -/* intrinsic void __enable_irq(); */ - - -/** - \brief Disable IRQ Interrupts - \details Disables IRQ interrupts by setting the I-bit in the CPSR. - Can only be executed in Privileged modes. - */ -/* intrinsic void __disable_irq(); */ - -/** - \brief Get Control Register - \details Returns the content of the Control Register. - \return Control Register value - */ -__STATIC_INLINE uint32_t __get_CONTROL(void) -{ - register uint32_t __regControl __ASM("control"); - return(__regControl); -} - - -/** - \brief Set Control Register - \details Writes the given value to the Control Register. - \param [in] control Control Register value to set - */ -__STATIC_INLINE void __set_CONTROL(uint32_t control) -{ - register uint32_t __regControl __ASM("control"); - __regControl = control; -} - - -/** - \brief Get IPSR Register - \details Returns the content of the IPSR Register. - \return IPSR Register value - */ -__STATIC_INLINE uint32_t __get_IPSR(void) -{ - register uint32_t __regIPSR __ASM("ipsr"); - return(__regIPSR); -} - - -/** - \brief Get APSR Register - \details Returns the content of the APSR Register. - \return APSR Register value - */ -__STATIC_INLINE uint32_t __get_APSR(void) -{ - register uint32_t __regAPSR __ASM("apsr"); - return(__regAPSR); -} - - -/** - \brief Get xPSR Register - \details Returns the content of the xPSR Register. - \return xPSR Register value - */ -__STATIC_INLINE uint32_t __get_xPSR(void) -{ - register uint32_t __regXPSR __ASM("xpsr"); - return(__regXPSR); -} - - -/** - \brief Get Process Stack Pointer - \details Returns the current value of the Process Stack Pointer (PSP). - \return PSP Register value - */ -__STATIC_INLINE uint32_t __get_PSP(void) -{ - register uint32_t __regProcessStackPointer __ASM("psp"); - return(__regProcessStackPointer); -} - - -/** - \brief Set Process Stack Pointer - \details Assigns the given value to the Process Stack Pointer (PSP). - \param [in] topOfProcStack Process Stack Pointer value to set - */ -__STATIC_INLINE void __set_PSP(uint32_t topOfProcStack) -{ - register uint32_t __regProcessStackPointer __ASM("psp"); - __regProcessStackPointer = topOfProcStack; -} - - -/** - \brief Get Main Stack Pointer - \details Returns the current value of the Main Stack Pointer (MSP). - \return MSP Register value - */ -__STATIC_INLINE uint32_t __get_MSP(void) -{ - register uint32_t __regMainStackPointer __ASM("msp"); - return(__regMainStackPointer); -} - - -/** - \brief Set Main Stack Pointer - \details Assigns the given value to the Main Stack Pointer (MSP). - \param [in] topOfMainStack Main Stack Pointer value to set - */ -__STATIC_INLINE void __set_MSP(uint32_t topOfMainStack) -{ - register uint32_t __regMainStackPointer __ASM("msp"); - __regMainStackPointer = topOfMainStack; -} - - -/** - \brief Get Priority Mask - \details Returns the current state of the priority mask bit from the Priority Mask Register. - \return Priority Mask value - */ -__STATIC_INLINE uint32_t __get_PRIMASK(void) -{ - register uint32_t __regPriMask __ASM("primask"); - return(__regPriMask); -} - - -/** - \brief Set Priority Mask - \details Assigns the given value to the Priority Mask Register. - \param [in] priMask Priority Mask - */ -__STATIC_INLINE void __set_PRIMASK(uint32_t priMask) -{ - register uint32_t __regPriMask __ASM("primask"); - __regPriMask = (priMask); -} - - -#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ - (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) - -/** - \brief Enable FIQ - \details Enables FIQ interrupts by clearing the F-bit in the CPSR. - Can only be executed in Privileged modes. - */ -#define __enable_fault_irq __enable_fiq - - -/** - \brief Disable FIQ - \details Disables FIQ interrupts by setting the F-bit in the CPSR. - Can only be executed in Privileged modes. - */ -#define __disable_fault_irq __disable_fiq - - -/** - \brief Get Base Priority - \details Returns the current value of the Base Priority register. - \return Base Priority register value - */ -__STATIC_INLINE uint32_t __get_BASEPRI(void) -{ - register uint32_t __regBasePri __ASM("basepri"); - return(__regBasePri); -} - - -/** - \brief Set Base Priority - \details Assigns the given value to the Base Priority register. - \param [in] basePri Base Priority value to set - */ -__STATIC_INLINE void __set_BASEPRI(uint32_t basePri) -{ - register uint32_t __regBasePri __ASM("basepri"); - __regBasePri = (basePri & 0xFFU); -} - - -/** - \brief Set Base Priority with condition - \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled, - or the new value increases the BASEPRI priority level. - \param [in] basePri Base Priority value to set - */ -__STATIC_INLINE void __set_BASEPRI_MAX(uint32_t basePri) -{ - register uint32_t __regBasePriMax __ASM("basepri_max"); - __regBasePriMax = (basePri & 0xFFU); -} - - -/** - \brief Get Fault Mask - \details Returns the current value of the Fault Mask register. - \return Fault Mask register value - */ -__STATIC_INLINE uint32_t __get_FAULTMASK(void) -{ - register uint32_t __regFaultMask __ASM("faultmask"); - return(__regFaultMask); -} - - -/** - \brief Set Fault Mask - \details Assigns the given value to the Fault Mask register. - \param [in] faultMask Fault Mask value to set - */ -__STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask) -{ - register uint32_t __regFaultMask __ASM("faultmask"); - __regFaultMask = (faultMask & (uint32_t)1U); -} - -#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ - (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */ - +/* ######################### Startup and Lowlevel Init ######################## */ -/** - \brief Get FPSCR - \details Returns the current value of the Floating Point Status/Control register. - \return Floating Point Status/Control register value - */ -__STATIC_INLINE uint32_t __get_FPSCR(void) -{ -#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ - (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) - register uint32_t __regfpscr __ASM("fpscr"); - return(__regfpscr); -#else - return(0U); +#ifndef __PROGRAM_START +#define __PROGRAM_START __main #endif -} - -/** - \brief Set FPSCR - \details Assigns the given value to the Floating Point Status/Control register. - \param [in] fpscr Floating Point Status/Control value to set - */ -__STATIC_INLINE void __set_FPSCR(uint32_t fpscr) -{ -#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ - (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) - register uint32_t __regfpscr __ASM("fpscr"); - __regfpscr = (fpscr); -#else - (void)fpscr; +#ifndef __INITIAL_SP +#define __INITIAL_SP Image$$ARM_LIB_STACK$$ZI$$Limit #endif -} +#ifndef __STACK_LIMIT +#define __STACK_LIMIT Image$$ARM_LIB_STACK$$ZI$$Base +#endif -/*@} end of CMSIS_Core_RegAccFunctions */ +#ifndef __VECTOR_TABLE +#define __VECTOR_TABLE __Vectors +#endif +#ifndef __VECTOR_TABLE_ATTRIBUTE +#define __VECTOR_TABLE_ATTRIBUTE __attribute__((used, section("RESET"))) +#endif /* ########################## Core Instruction Access ######################### */ /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface @@ -419,35 +172,23 @@ __STATIC_INLINE void __set_FPSCR(uint32_t fpscr) so that all instructions following the ISB are fetched from cache or memory, after the instruction has been completed. */ -#define __ISB() do {\ - __schedule_barrier();\ - __isb(0xF);\ - __schedule_barrier();\ - } while (0U) +#define __ISB() __isb(0xF) /** \brief Data Synchronization Barrier \details Acts as a special kind of Data Memory Barrier. It completes when all explicit memory accesses before this instruction complete. */ -#define __DSB() do {\ - __schedule_barrier();\ - __dsb(0xF);\ - __schedule_barrier();\ - } while (0U) +#define __DSB() __dsb(0xF) /** \brief Data Memory Barrier \details Ensures the apparent order of the explicit memory operations before and after the instruction, without ensuring their completion. */ -#define __DMB() do {\ - __schedule_barrier();\ - __dmb(0xF);\ - __schedule_barrier();\ - } while (0U) +#define __DMB() __dmb(0xF) + - /** \brief Reverse byte order (32 bit) \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412. @@ -602,187 +343,461 @@ __attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value) /** - \brief STR Exclusive (16 bit) - \details Executes a exclusive STR instruction for 16 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed + \brief STR Exclusive (16 bit) + \details Executes a exclusive STR instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) + #define __STREXH(value, ptr) __strex(value, ptr) +#else + #define __STREXH(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") +#endif + + +/** + \brief STR Exclusive (32 bit) + \details Executes a exclusive STR instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) + #define __STREXW(value, ptr) __strex(value, ptr) +#else + #define __STREXW(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") +#endif + + +/** + \brief Remove the exclusive lock + \details Removes the exclusive lock which is created by LDREX. + */ +#define __CLREX __clrex + + +/** + \brief Signed Saturate + \details Saturates a signed value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (1..32) + \return Saturated value + */ +#define __SSAT __ssat + + +/** + \brief Unsigned Saturate + \details Saturates an unsigned value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (0..31) + \return Saturated value + */ +#define __USAT __usat + + +/** + \brief Rotate Right with Extend (32 bit) + \details Moves each bit of a bitstring right by one bit. + The carry input is shifted in at the left end of the bitstring. + \param [in] value Value to rotate + \return Rotated value + */ +#ifndef __NO_EMBEDDED_ASM +__attribute__((section(".rrx_text"))) __STATIC_INLINE __ASM uint32_t __RRX(uint32_t value) +{ + rrx r0, r0 + bx lr +} +#endif + + +/** + \brief LDRT Unprivileged (8 bit) + \details Executes a Unprivileged LDRT instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) + */ +#define __LDRBT(ptr) ((uint8_t ) __ldrt(ptr)) + + +/** + \brief LDRT Unprivileged (16 bit) + \details Executes a Unprivileged LDRT instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) + */ +#define __LDRHT(ptr) ((uint16_t) __ldrt(ptr)) + + +/** + \brief LDRT Unprivileged (32 bit) + \details Executes a Unprivileged LDRT instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) + */ +#define __LDRT(ptr) ((uint32_t ) __ldrt(ptr)) + + +/** + \brief STRT Unprivileged (8 bit) + \details Executes a Unprivileged STRT instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +#define __STRBT(value, ptr) __strt(value, ptr) + + +/** + \brief STRT Unprivileged (16 bit) + \details Executes a Unprivileged STRT instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +#define __STRHT(value, ptr) __strt(value, ptr) + + +/** + \brief STRT Unprivileged (32 bit) + \details Executes a Unprivileged STRT instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +#define __STRT(value, ptr) __strt(value, ptr) + +#else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */ + +/** + \brief Signed Saturate + \details Saturates a signed value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (1..32) + \return Saturated value + */ +__attribute__((always_inline)) __STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat) +{ + if ((sat >= 1U) && (sat <= 32U)) + { + const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); + const int32_t min = -1 - max ; + if (val > max) + { + return max; + } + else if (val < min) + { + return min; + } + } + return val; +} + +/** + \brief Unsigned Saturate + \details Saturates an unsigned value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (0..31) + \return Saturated value + */ +__attribute__((always_inline)) __STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat) +{ + if (sat <= 31U) + { + const uint32_t max = ((1U << sat) - 1U); + if (val > (int32_t)max) + { + return max; + } + else if (val < 0) + { + return 0U; + } + } + return (uint32_t)val; +} + +#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */ + +/*@}*/ /* end of group CMSIS_Core_InstructionInterface */ + + +/* ########################### Core Function Access ########################### */ +/** \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions + @{ + */ + +/** + \brief Enable IRQ Interrupts + \details Enables IRQ interrupts by clearing special-purpose register PRIMASK. + Can only be executed in Privileged modes. + */ +/* intrinsic void __enable_irq(); */ + + +/** + \brief Disable IRQ Interrupts + \details Disables IRQ interrupts by setting special-purpose register PRIMASK. + Can only be executed in Privileged modes. + */ +/* intrinsic void __disable_irq(); */ + +/** + \brief Get Control Register + \details Returns the content of the Control Register. + \return Control Register value + */ +__STATIC_INLINE uint32_t __get_CONTROL(void) +{ + register uint32_t __regControl __ASM("control"); + return(__regControl); +} + + +/** + \brief Set Control Register + \details Writes the given value to the Control Register. + \param [in] control Control Register value to set + */ +__STATIC_INLINE void __set_CONTROL(uint32_t control) +{ + register uint32_t __regControl __ASM("control"); + __regControl = control; + __ISB(); +} + + +/** + \brief Get IPSR Register + \details Returns the content of the IPSR Register. + \return IPSR Register value + */ +__STATIC_INLINE uint32_t __get_IPSR(void) +{ + register uint32_t __regIPSR __ASM("ipsr"); + return(__regIPSR); +} + + +/** + \brief Get APSR Register + \details Returns the content of the APSR Register. + \return APSR Register value + */ +__STATIC_INLINE uint32_t __get_APSR(void) +{ + register uint32_t __regAPSR __ASM("apsr"); + return(__regAPSR); +} + + +/** + \brief Get xPSR Register + \details Returns the content of the xPSR Register. + \return xPSR Register value + */ +__STATIC_INLINE uint32_t __get_xPSR(void) +{ + register uint32_t __regXPSR __ASM("xpsr"); + return(__regXPSR); +} + + +/** + \brief Get Process Stack Pointer + \details Returns the current value of the Process Stack Pointer (PSP). + \return PSP Register value */ -#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) - #define __STREXH(value, ptr) __strex(value, ptr) -#else - #define __STREXH(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") -#endif +__STATIC_INLINE uint32_t __get_PSP(void) +{ + register uint32_t __regProcessStackPointer __ASM("psp"); + return(__regProcessStackPointer); +} /** - \brief STR Exclusive (32 bit) - \details Executes a exclusive STR instruction for 32 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed + \brief Set Process Stack Pointer + \details Assigns the given value to the Process Stack Pointer (PSP). + \param [in] topOfProcStack Process Stack Pointer value to set */ -#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) - #define __STREXW(value, ptr) __strex(value, ptr) -#else - #define __STREXW(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") -#endif +__STATIC_INLINE void __set_PSP(uint32_t topOfProcStack) +{ + register uint32_t __regProcessStackPointer __ASM("psp"); + __regProcessStackPointer = topOfProcStack; +} /** - \brief Remove the exclusive lock - \details Removes the exclusive lock which is created by LDREX. + \brief Get Main Stack Pointer + \details Returns the current value of the Main Stack Pointer (MSP). + \return MSP Register value */ -#define __CLREX __clrex +__STATIC_INLINE uint32_t __get_MSP(void) +{ + register uint32_t __regMainStackPointer __ASM("msp"); + return(__regMainStackPointer); +} /** - \brief Signed Saturate - \details Saturates a signed value. - \param [in] value Value to be saturated - \param [in] sat Bit position to saturate to (1..32) - \return Saturated value + \brief Set Main Stack Pointer + \details Assigns the given value to the Main Stack Pointer (MSP). + \param [in] topOfMainStack Main Stack Pointer value to set */ -#define __SSAT __ssat +__STATIC_INLINE void __set_MSP(uint32_t topOfMainStack) +{ + register uint32_t __regMainStackPointer __ASM("msp"); + __regMainStackPointer = topOfMainStack; +} /** - \brief Unsigned Saturate - \details Saturates an unsigned value. - \param [in] value Value to be saturated - \param [in] sat Bit position to saturate to (0..31) - \return Saturated value + \brief Get Priority Mask + \details Returns the current state of the priority mask bit from the Priority Mask Register. + \return Priority Mask value */ -#define __USAT __usat +__STATIC_INLINE uint32_t __get_PRIMASK(void) +{ + register uint32_t __regPriMask __ASM("primask"); + return(__regPriMask); +} /** - \brief Rotate Right with Extend (32 bit) - \details Moves each bit of a bitstring right by one bit. - The carry input is shifted in at the left end of the bitstring. - \param [in] value Value to rotate - \return Rotated value + \brief Set Priority Mask + \details Assigns the given value to the Priority Mask Register. + \param [in] priMask Priority Mask */ -#ifndef __NO_EMBEDDED_ASM -__attribute__((section(".rrx_text"))) __STATIC_INLINE __ASM uint32_t __RRX(uint32_t value) +__STATIC_INLINE void __set_PRIMASK(uint32_t priMask) { - rrx r0, r0 - bx lr + register uint32_t __regPriMask __ASM("primask"); + __regPriMask = (priMask); } -#endif +#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) + /** - \brief LDRT Unprivileged (8 bit) - \details Executes a Unprivileged LDRT instruction for 8 bit value. - \param [in] ptr Pointer to data - \return value of type uint8_t at (*ptr) + \brief Enable FIQ + \details Enables FIQ interrupts by clearing special-purpose register FAULTMASK. + Can only be executed in Privileged modes. */ -#define __LDRBT(ptr) ((uint8_t ) __ldrt(ptr)) +#define __enable_fault_irq __enable_fiq /** - \brief LDRT Unprivileged (16 bit) - \details Executes a Unprivileged LDRT instruction for 16 bit values. - \param [in] ptr Pointer to data - \return value of type uint16_t at (*ptr) + \brief Disable FIQ + \details Disables FIQ interrupts by setting special-purpose register FAULTMASK. + Can only be executed in Privileged modes. */ -#define __LDRHT(ptr) ((uint16_t) __ldrt(ptr)) +#define __disable_fault_irq __disable_fiq /** - \brief LDRT Unprivileged (32 bit) - \details Executes a Unprivileged LDRT instruction for 32 bit values. - \param [in] ptr Pointer to data - \return value of type uint32_t at (*ptr) + \brief Get Base Priority + \details Returns the current value of the Base Priority register. + \return Base Priority register value */ -#define __LDRT(ptr) ((uint32_t ) __ldrt(ptr)) +__STATIC_INLINE uint32_t __get_BASEPRI(void) +{ + register uint32_t __regBasePri __ASM("basepri"); + return(__regBasePri); +} /** - \brief STRT Unprivileged (8 bit) - \details Executes a Unprivileged STRT instruction for 8 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location + \brief Set Base Priority + \details Assigns the given value to the Base Priority register. + \param [in] basePri Base Priority value to set */ -#define __STRBT(value, ptr) __strt(value, ptr) +__STATIC_INLINE void __set_BASEPRI(uint32_t basePri) +{ + register uint32_t __regBasePri __ASM("basepri"); + __regBasePri = (basePri & 0xFFU); +} /** - \brief STRT Unprivileged (16 bit) - \details Executes a Unprivileged STRT instruction for 16 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location + \brief Set Base Priority with condition + \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled, + or the new value increases the BASEPRI priority level. + \param [in] basePri Base Priority value to set */ -#define __STRHT(value, ptr) __strt(value, ptr) +__STATIC_INLINE void __set_BASEPRI_MAX(uint32_t basePri) +{ + register uint32_t __regBasePriMax __ASM("basepri_max"); + __regBasePriMax = (basePri & 0xFFU); +} /** - \brief STRT Unprivileged (32 bit) - \details Executes a Unprivileged STRT instruction for 32 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location + \brief Get Fault Mask + \details Returns the current value of the Fault Mask register. + \return Fault Mask register value */ -#define __STRT(value, ptr) __strt(value, ptr) +__STATIC_INLINE uint32_t __get_FAULTMASK(void) +{ + register uint32_t __regFaultMask __ASM("faultmask"); + return(__regFaultMask); +} -#else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + +/** + \brief Set Fault Mask + \details Assigns the given value to the Fault Mask register. + \param [in] faultMask Fault Mask value to set + */ +__STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask) +{ + register uint32_t __regFaultMask __ASM("faultmask"); + __regFaultMask = (faultMask & (uint32_t)1U); +} + +#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */ + /** - \brief Signed Saturate - \details Saturates a signed value. - \param [in] value Value to be saturated - \param [in] sat Bit position to saturate to (1..32) - \return Saturated value + \brief Get FPSCR + \details Returns the current value of the Floating Point Status/Control register. + \return Floating Point Status/Control register value */ -__attribute__((always_inline)) __STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat) +__STATIC_INLINE uint32_t __get_FPSCR(void) { - if ((sat >= 1U) && (sat <= 32U)) - { - const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); - const int32_t min = -1 - max ; - if (val > max) - { - return max; - } - else if (val < min) - { - return min; - } - } - return val; +#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ + (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) + register uint32_t __regfpscr __ASM("fpscr"); + return(__regfpscr); +#else + return(0U); +#endif } + /** - \brief Unsigned Saturate - \details Saturates an unsigned value. - \param [in] value Value to be saturated - \param [in] sat Bit position to saturate to (0..31) - \return Saturated value + \brief Set FPSCR + \details Assigns the given value to the Floating Point Status/Control register. + \param [in] fpscr Floating Point Status/Control value to set */ -__attribute__((always_inline)) __STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat) +__STATIC_INLINE void __set_FPSCR(uint32_t fpscr) { - if (sat <= 31U) - { - const uint32_t max = ((1U << sat) - 1U); - if (val > (int32_t)max) - { - return max; - } - else if (val < 0) - { - return 0U; - } - } - return (uint32_t)val; +#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ + (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) + register uint32_t __regfpscr __ASM("fpscr"); + __regfpscr = (fpscr); +#else + (void)fpscr; +#endif } -#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ - (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */ -/*@}*/ /* end of group CMSIS_Core_InstructionInterface */ +/*@} end of CMSIS_Core_RegAccFunctions */ /* ################### Compiler specific Intrinsics ########################### */ @@ -862,6 +877,10 @@ __attribute__((always_inline)) __STATIC_INLINE uint32_t __USAT(int32_t val, uint #define __SMMLA(ARG1,ARG2,ARG3) ( (int32_t)((((int64_t)(ARG1) * (ARG2)) + \ ((int64_t)(ARG3) << 32U) ) >> 32U)) +#define __SXTB16_RORn(ARG1, ARG2) __SXTB16(__ROR(ARG1, ARG2)) + +#define __SXTAB16_RORn(ARG1, ARG2, ARG3) __SXTAB16(ARG1, __ROR(ARG2, ARG3)) + #endif /* ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */ /*@} end of group CMSIS_SIMD_intrinsics */ diff --git a/lib/cmsis/inc/cmsis_armclang.h b/lib/cmsis/inc/cmsis_armclang.h index 6a8867d57417e..691141774773f 100644 --- a/lib/cmsis/inc/cmsis_armclang.h +++ b/lib/cmsis/inc/cmsis_armclang.h @@ -1,11 +1,11 @@ /**************************************************************************//** * @file cmsis_armclang.h * @brief CMSIS compiler armclang (Arm Compiler 6) header file - * @version V5.1.0 - * @date 14. March 2019 + * @version V5.4.3 + * @date 27. May 2021 ******************************************************************************/ /* - * Copyright (c) 2009-2019 Arm Limited. All rights reserved. + * Copyright (c) 2009-2021 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -29,10 +29,6 @@ #pragma clang system_header /* treat file as system include file */ -#ifndef __ARM_COMPAT_H -#include /* Compatibility header for Arm Compiler 5 intrinsics */ -#endif - /* CMSIS compiler specific defines */ #ifndef __ASM #define __ASM __asm @@ -110,1225 +106,1308 @@ #ifndef __RESTRICT #define __RESTRICT __restrict #endif +#ifndef __COMPILER_BARRIER + #define __COMPILER_BARRIER() __ASM volatile("":::"memory") +#endif +/* ######################### Startup and Lowlevel Init ######################## */ -/* ########################### Core Function Access ########################### */ -/** \ingroup CMSIS_Core_FunctionInterface - \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions - @{ - */ +#ifndef __PROGRAM_START +#define __PROGRAM_START __main +#endif -/** - \brief Enable IRQ Interrupts - \details Enables IRQ interrupts by clearing the I-bit in the CPSR. - Can only be executed in Privileged modes. - */ -/* intrinsic void __enable_irq(); see arm_compat.h */ +#ifndef __INITIAL_SP +#define __INITIAL_SP Image$$ARM_LIB_STACK$$ZI$$Limit +#endif +#ifndef __STACK_LIMIT +#define __STACK_LIMIT Image$$ARM_LIB_STACK$$ZI$$Base +#endif -/** - \brief Disable IRQ Interrupts - \details Disables IRQ interrupts by setting the I-bit in the CPSR. - Can only be executed in Privileged modes. - */ -/* intrinsic void __disable_irq(); see arm_compat.h */ +#ifndef __VECTOR_TABLE +#define __VECTOR_TABLE __Vectors +#endif +#ifndef __VECTOR_TABLE_ATTRIBUTE +#define __VECTOR_TABLE_ATTRIBUTE __attribute__((used, section("RESET"))) +#endif -/** - \brief Get Control Register - \details Returns the content of the Control Register. - \return Control Register value - */ -__STATIC_FORCEINLINE uint32_t __get_CONTROL(void) -{ - uint32_t result; +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +#ifndef __STACK_SEAL +#define __STACK_SEAL Image$$STACKSEAL$$ZI$$Base +#endif - __ASM volatile ("MRS %0, control" : "=r" (result) ); - return(result); -} +#ifndef __TZ_STACK_SEAL_SIZE +#define __TZ_STACK_SEAL_SIZE 8U +#endif +#ifndef __TZ_STACK_SEAL_VALUE +#define __TZ_STACK_SEAL_VALUE 0xFEF5EDA5FEF5EDA5ULL +#endif -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) -/** - \brief Get Control Register (non-secure) - \details Returns the content of the non-secure Control Register when in secure mode. - \return non-secure Control Register value - */ -__STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void) -{ - uint32_t result; - __ASM volatile ("MRS %0, control_ns" : "=r" (result) ); - return(result); +__STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) { + *((uint64_t *)stackTop) = __TZ_STACK_SEAL_VALUE; } #endif -/** - \brief Set Control Register - \details Writes the given value to the Control Register. - \param [in] control Control Register value to set - */ -__STATIC_FORCEINLINE void __set_CONTROL(uint32_t control) -{ - __ASM volatile ("MSR control, %0" : : "r" (control) : "memory"); -} +/* ########################## Core Instruction Access ######################### */ +/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface + Access to dedicated instructions + @{ +*/ +/* Define macros for porting to both thumb1 and thumb2. + * For thumb1, use low register (r0-r7), specified by constraint "l" + * Otherwise, use general registers, specified by constraint "r" */ +#if defined (__thumb__) && !defined (__thumb2__) +#define __CMSIS_GCC_OUT_REG(r) "=l" (r) +#define __CMSIS_GCC_RW_REG(r) "+l" (r) +#define __CMSIS_GCC_USE_REG(r) "l" (r) +#else +#define __CMSIS_GCC_OUT_REG(r) "=r" (r) +#define __CMSIS_GCC_RW_REG(r) "+r" (r) +#define __CMSIS_GCC_USE_REG(r) "r" (r) +#endif -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Set Control Register (non-secure) - \details Writes the given value to the non-secure Control Register when in secure state. - \param [in] control Control Register value to set + \brief No Operation + \details No Operation does nothing. This instruction can be used for code alignment purposes. */ -__STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control) -{ - __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory"); -} -#endif - +#define __NOP __builtin_arm_nop /** - \brief Get IPSR Register - \details Returns the content of the IPSR Register. - \return IPSR Register value + \brief Wait For Interrupt + \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs. */ -__STATIC_FORCEINLINE uint32_t __get_IPSR(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, ipsr" : "=r" (result) ); - return(result); -} +#define __WFI __builtin_arm_wfi /** - \brief Get APSR Register - \details Returns the content of the APSR Register. - \return APSR Register value + \brief Wait For Event + \details Wait For Event is a hint instruction that permits the processor to enter + a low-power state until one of a number of events occurs. */ -__STATIC_FORCEINLINE uint32_t __get_APSR(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, apsr" : "=r" (result) ); - return(result); -} +#define __WFE __builtin_arm_wfe /** - \brief Get xPSR Register - \details Returns the content of the xPSR Register. - \return xPSR Register value + \brief Send Event + \details Send Event is a hint instruction. It causes an event to be signaled to the CPU. */ -__STATIC_FORCEINLINE uint32_t __get_xPSR(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, xpsr" : "=r" (result) ); - return(result); -} +#define __SEV __builtin_arm_sev /** - \brief Get Process Stack Pointer - \details Returns the current value of the Process Stack Pointer (PSP). - \return PSP Register value + \brief Instruction Synchronization Barrier + \details Instruction Synchronization Barrier flushes the pipeline in the processor, + so that all instructions following the ISB are fetched from cache or memory, + after the instruction has been completed. */ -__STATIC_FORCEINLINE uint32_t __get_PSP(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, psp" : "=r" (result) ); - return(result); -} - +#define __ISB() __builtin_arm_isb(0xF) -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Get Process Stack Pointer (non-secure) - \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state. - \return PSP Register value + \brief Data Synchronization Barrier + \details Acts as a special kind of Data Memory Barrier. + It completes when all explicit memory accesses before this instruction complete. */ -__STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, psp_ns" : "=r" (result) ); - return(result); -} -#endif +#define __DSB() __builtin_arm_dsb(0xF) /** - \brief Set Process Stack Pointer - \details Assigns the given value to the Process Stack Pointer (PSP). - \param [in] topOfProcStack Process Stack Pointer value to set + \brief Data Memory Barrier + \details Ensures the apparent order of the explicit memory operations before + and after the instruction, without ensuring their completion. */ -__STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack) -{ - __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : ); -} +#define __DMB() __builtin_arm_dmb(0xF) -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Set Process Stack Pointer (non-secure) - \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state. - \param [in] topOfProcStack Process Stack Pointer value to set + \brief Reverse byte order (32 bit) + \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412. + \param [in] value Value to reverse + \return Reversed value */ -__STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack) -{ - __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : ); -} -#endif +#define __REV(value) __builtin_bswap32(value) /** - \brief Get Main Stack Pointer - \details Returns the current value of the Main Stack Pointer (MSP). - \return MSP Register value + \brief Reverse byte order (16 bit) + \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856. + \param [in] value Value to reverse + \return Reversed value */ -__STATIC_FORCEINLINE uint32_t __get_MSP(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, msp" : "=r" (result) ); - return(result); -} +#define __REV16(value) __ROR(__REV(value), 16) -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Get Main Stack Pointer (non-secure) - \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state. - \return MSP Register value + \brief Reverse byte order (16 bit) + \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000. + \param [in] value Value to reverse + \return Reversed value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, msp_ns" : "=r" (result) ); - return(result); -} -#endif +#define __REVSH(value) (int16_t)__builtin_bswap16(value) /** - \brief Set Main Stack Pointer - \details Assigns the given value to the Main Stack Pointer (MSP). - \param [in] topOfMainStack Main Stack Pointer value to set + \brief Rotate Right in unsigned value (32 bit) + \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits. + \param [in] op1 Value to rotate + \param [in] op2 Number of Bits to rotate + \return Rotated value */ -__STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack) +__STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2) { - __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : ); + op2 %= 32U; + if (op2 == 0U) + { + return op1; + } + return (op1 >> op2) | (op1 << (32U - op2)); } -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Set Main Stack Pointer (non-secure) - \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state. - \param [in] topOfMainStack Main Stack Pointer value to set + \brief Breakpoint + \details Causes the processor to enter Debug state. + Debug tools can use this to investigate system state when the instruction at a particular address is reached. + \param [in] value is ignored by the processor. + If required, a debugger can use it to store additional information about the breakpoint. */ -__STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack) -{ - __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : ); -} -#endif +#define __BKPT(value) __ASM volatile ("bkpt "#value) -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Get Stack Pointer (non-secure) - \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state. - \return SP Register value + \brief Reverse bit order of value + \details Reverses the bit order of the given value. + \param [in] value Value to reverse + \return Reversed value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, sp_ns" : "=r" (result) ); - return(result); -} - +#define __RBIT __builtin_arm_rbit /** - \brief Set Stack Pointer (non-secure) - \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state. - \param [in] topOfStack Stack Pointer value to set + \brief Count leading zeros + \details Counts the number of leading zeros of a data value. + \param [in] value Value to count the leading zeros + \return number of leading zeros in value */ -__STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack) +__STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value) { - __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : ); + /* Even though __builtin_clz produces a CLZ instruction on ARM, formally + __builtin_clz(0) is undefined behaviour, so handle this case specially. + This guarantees ARM-compatible results if happening to compile on a non-ARM + target, and ensures the compiler doesn't decide to activate any + optimisations using the logic "value was passed to __builtin_clz, so it + is non-zero". + ARM Compiler 6.10 and possibly earlier will optimise this test away, leaving a + single CLZ instruction. + */ + if (value == 0U) + { + return 32U; + } + return __builtin_clz(value); } -#endif +#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) || \ + (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) + /** - \brief Get Priority Mask - \details Returns the current state of the priority mask bit from the Priority Mask Register. - \return Priority Mask value + \brief LDR Exclusive (8 bit) + \details Executes a exclusive LDR instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) */ -__STATIC_FORCEINLINE uint32_t __get_PRIMASK(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, primask" : "=r" (result) ); - return(result); -} +#define __LDREXB (uint8_t)__builtin_arm_ldrex -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Get Priority Mask (non-secure) - \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state. - \return Priority Mask value + \brief LDR Exclusive (16 bit) + \details Executes a exclusive LDR instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) */ -__STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, primask_ns" : "=r" (result) ); - return(result); -} -#endif +#define __LDREXH (uint16_t)__builtin_arm_ldrex /** - \brief Set Priority Mask - \details Assigns the given value to the Priority Mask Register. - \param [in] priMask Priority Mask + \brief LDR Exclusive (32 bit) + \details Executes a exclusive LDR instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) */ -__STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask) -{ - __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory"); -} +#define __LDREXW (uint32_t)__builtin_arm_ldrex -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Set Priority Mask (non-secure) - \details Assigns the given value to the non-secure Priority Mask Register when in secure state. - \param [in] priMask Priority Mask + \brief STR Exclusive (8 bit) + \details Executes a exclusive STR instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed */ -__STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask) -{ - __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory"); -} -#endif +#define __STREXB (uint32_t)__builtin_arm_strex -#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ - (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ - (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) /** - \brief Enable FIQ - \details Enables FIQ interrupts by clearing the F-bit in the CPSR. - Can only be executed in Privileged modes. + \brief STR Exclusive (16 bit) + \details Executes a exclusive STR instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed */ -#define __enable_fault_irq __enable_fiq /* see arm_compat.h */ +#define __STREXH (uint32_t)__builtin_arm_strex /** - \brief Disable FIQ - \details Disables FIQ interrupts by setting the F-bit in the CPSR. - Can only be executed in Privileged modes. + \brief STR Exclusive (32 bit) + \details Executes a exclusive STR instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed */ -#define __disable_fault_irq __disable_fiq /* see arm_compat.h */ +#define __STREXW (uint32_t)__builtin_arm_strex /** - \brief Get Base Priority - \details Returns the current value of the Base Priority register. - \return Base Priority register value + \brief Remove the exclusive lock + \details Removes the exclusive lock which is created by LDREX. */ -__STATIC_FORCEINLINE uint32_t __get_BASEPRI(void) -{ - uint32_t result; +#define __CLREX __builtin_arm_clrex - __ASM volatile ("MRS %0, basepri" : "=r" (result) ); - return(result); -} +#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) || \ + (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) */ -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) + /** - \brief Get Base Priority (non-secure) - \details Returns the current value of the non-secure Base Priority register when in secure state. - \return Base Priority register value + \brief Signed Saturate + \details Saturates a signed value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (1..32) + \return Saturated value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) ); - return(result); -} -#endif +#define __SSAT __builtin_arm_ssat /** - \brief Set Base Priority - \details Assigns the given value to the Base Priority register. - \param [in] basePri Base Priority value to set + \brief Unsigned Saturate + \details Saturates an unsigned value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (0..31) + \return Saturated value */ -__STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri) -{ - __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory"); -} +#define __USAT __builtin_arm_usat -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Set Base Priority (non-secure) - \details Assigns the given value to the non-secure Base Priority register when in secure state. - \param [in] basePri Base Priority value to set + \brief Rotate Right with Extend (32 bit) + \details Moves each bit of a bitstring right by one bit. + The carry input is shifted in at the left end of the bitstring. + \param [in] value Value to rotate + \return Rotated value */ -__STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri) +__STATIC_FORCEINLINE uint32_t __RRX(uint32_t value) { - __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory"); + uint32_t result; + + __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); + return(result); } -#endif /** - \brief Set Base Priority with condition - \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled, - or the new value increases the BASEPRI priority level. - \param [in] basePri Base Priority value to set + \brief LDRT Unprivileged (8 bit) + \details Executes a Unprivileged LDRT instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) */ -__STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri) +__STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr) { - __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory"); + uint32_t result; + + __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) ); + return ((uint8_t) result); /* Add explicit type cast here */ } /** - \brief Get Fault Mask - \details Returns the current value of the Fault Mask register. - \return Fault Mask register value + \brief LDRT Unprivileged (16 bit) + \details Executes a Unprivileged LDRT instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) */ -__STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void) +__STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr) { uint32_t result; - __ASM volatile ("MRS %0, faultmask" : "=r" (result) ); - return(result); + __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) ); + return ((uint16_t) result); /* Add explicit type cast here */ } -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Get Fault Mask (non-secure) - \details Returns the current value of the non-secure Fault Mask register when in secure state. - \return Fault Mask register value + \brief LDRT Unprivileged (32 bit) + \details Executes a Unprivileged LDRT instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) */ -__STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void) +__STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr) { uint32_t result; - __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) ); + __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) ); return(result); } -#endif /** - \brief Set Fault Mask - \details Assigns the given value to the Fault Mask register. - \param [in] faultMask Fault Mask value to set + \brief STRT Unprivileged (8 bit) + \details Executes a Unprivileged STRT instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask) +__STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr) { - __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory"); + __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); } -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Set Fault Mask (non-secure) - \details Assigns the given value to the non-secure Fault Mask register when in secure state. - \param [in] faultMask Fault Mask value to set + \brief STRT Unprivileged (16 bit) + \details Executes a Unprivileged STRT instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask) +__STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr) { - __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory"); + __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); } -#endif - -#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ - (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ - (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */ - -#if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ - (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) /** - \brief Get Process Stack Pointer Limit - Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure - Stack Pointer Limit register hence zero is returned always in non-secure - mode. - - \details Returns the current value of the Process Stack Pointer Limit (PSPLIM). - \return PSPLIM Register value + \brief STRT Unprivileged (32 bit) + \details Executes a Unprivileged STRT instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE uint32_t __get_PSPLIM(void) +__STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr) { -#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ - (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - return 0U; -#else - uint32_t result; - __ASM volatile ("MRS %0, psplim" : "=r" (result) ); - return result; -#endif + __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) ); } -#if (defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)) -/** - \brief Get Process Stack Pointer Limit (non-secure) - Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure - Stack Pointer Limit register hence zero is returned always in non-secure - mode. +#else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) */ - \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state. - \return PSPLIM Register value +/** + \brief Signed Saturate + \details Saturates a signed value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (1..32) + \return Saturated value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void) +__STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat) { -#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - return 0U; -#else - uint32_t result; - __ASM volatile ("MRS %0, psplim_ns" : "=r" (result) ); - return result; -#endif + if ((sat >= 1U) && (sat <= 32U)) + { + const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); + const int32_t min = -1 - max ; + if (val > max) + { + return max; + } + else if (val < min) + { + return min; + } + } + return val; } -#endif - /** - \brief Set Process Stack Pointer Limit - Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure - Stack Pointer Limit register hence the write is silently ignored in non-secure - mode. - - \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM). - \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set + \brief Unsigned Saturate + \details Saturates an unsigned value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (0..31) + \return Saturated value */ -__STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit) +__STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat) { -#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ - (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - (void)ProcStackPtrLimit; -#else - __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit)); -#endif + if (sat <= 31U) + { + const uint32_t max = ((1U << sat) - 1U); + if (val > (int32_t)max) + { + return max; + } + else if (val < 0) + { + return 0U; + } + } + return (uint32_t)val; } +#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) */ -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) -/** - \brief Set Process Stack Pointer (non-secure) - Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure - Stack Pointer Limit register hence the write is silently ignored in non-secure - mode. - \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state. - \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set +#if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) || \ + (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) + +/** + \brief Load-Acquire (8 bit) + \details Executes a LDAB instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) */ -__STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit) +__STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr) { -#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - (void)ProcStackPtrLimit; -#else - __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit)); -#endif + uint32_t result; + + __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" ); + return ((uint8_t) result); } -#endif /** - \brief Get Main Stack Pointer Limit - Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure - Stack Pointer Limit register hence zero is returned always. - - \details Returns the current value of the Main Stack Pointer Limit (MSPLIM). - \return MSPLIM Register value + \brief Load-Acquire (16 bit) + \details Executes a LDAH instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) */ -__STATIC_FORCEINLINE uint32_t __get_MSPLIM(void) +__STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr) { -#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ - (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - return 0U; -#else uint32_t result; - __ASM volatile ("MRS %0, msplim" : "=r" (result) ); - return result; -#endif + + __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" ); + return ((uint16_t) result); } -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Get Main Stack Pointer Limit (non-secure) - Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure - Stack Pointer Limit register hence zero is returned always. - - \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state. - \return MSPLIM Register value + \brief Load-Acquire (32 bit) + \details Executes a LDA instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) */ -__STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void) +__STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr) { -#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - return 0U; -#else uint32_t result; - __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) ); - return result; -#endif + + __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" ); + return(result); } -#endif /** - \brief Set Main Stack Pointer Limit - Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure - Stack Pointer Limit register hence the write is silently ignored. - - \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM). - \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set + \brief Store-Release (8 bit) + \details Executes a STLB instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit) +__STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr) { -#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ - (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - (void)MainStackPtrLimit; -#else - __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit)); -#endif + __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" ); } -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Set Main Stack Pointer Limit (non-secure) - Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure - Stack Pointer Limit register hence the write is silently ignored. - - \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state. - \param [in] MainStackPtrLimit Main Stack Pointer value to set + \brief Store-Release (16 bit) + \details Executes a STLH instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit) +__STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr) { -#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - (void)MainStackPtrLimit; -#else - __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit)); -#endif + __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" ); } -#endif -#endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ - (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */ /** - \brief Get FPSCR - \details Returns the current value of the Floating Point Status/Control register. - \return Floating Point Status/Control register value + \brief Store-Release (32 bit) + \details Executes a STL instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location */ -#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ - (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) -#define __get_FPSCR (uint32_t)__builtin_arm_get_fpscr -#else -#define __get_FPSCR() ((uint32_t)0U) -#endif +__STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr) +{ + __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" ); +} + /** - \brief Set FPSCR - \details Assigns the given value to the Floating Point Status/Control register. - \param [in] fpscr Floating Point Status/Control value to set + \brief Load-Acquire Exclusive (8 bit) + \details Executes a LDAB exclusive instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) */ -#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ - (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) -#define __set_FPSCR __builtin_arm_set_fpscr -#else -#define __set_FPSCR(x) ((void)(x)) -#endif +#define __LDAEXB (uint8_t)__builtin_arm_ldaex -/*@} end of CMSIS_Core_RegAccFunctions */ +/** + \brief Load-Acquire Exclusive (16 bit) + \details Executes a LDAH exclusive instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) + */ +#define __LDAEXH (uint16_t)__builtin_arm_ldaex -/* ########################## Core Instruction Access ######################### */ -/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface - Access to dedicated instructions - @{ -*/ +/** + \brief Load-Acquire Exclusive (32 bit) + \details Executes a LDA exclusive instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) + */ +#define __LDAEX (uint32_t)__builtin_arm_ldaex -/* Define macros for porting to both thumb1 and thumb2. - * For thumb1, use low register (r0-r7), specified by constraint "l" - * Otherwise, use general registers, specified by constraint "r" */ -#if defined (__thumb__) && !defined (__thumb2__) -#define __CMSIS_GCC_OUT_REG(r) "=l" (r) -#define __CMSIS_GCC_RW_REG(r) "+l" (r) -#define __CMSIS_GCC_USE_REG(r) "l" (r) -#else -#define __CMSIS_GCC_OUT_REG(r) "=r" (r) -#define __CMSIS_GCC_RW_REG(r) "+r" (r) -#define __CMSIS_GCC_USE_REG(r) "r" (r) -#endif /** - \brief No Operation - \details No Operation does nothing. This instruction can be used for code alignment purposes. + \brief Store-Release Exclusive (8 bit) + \details Executes a STLB exclusive instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed */ -#define __NOP __builtin_arm_nop +#define __STLEXB (uint32_t)__builtin_arm_stlex + /** - \brief Wait For Interrupt - \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs. + \brief Store-Release Exclusive (16 bit) + \details Executes a STLH exclusive instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed */ -#define __WFI __builtin_arm_wfi +#define __STLEXH (uint32_t)__builtin_arm_stlex /** - \brief Wait For Event - \details Wait For Event is a hint instruction that permits the processor to enter - a low-power state until one of a number of events occurs. + \brief Store-Release Exclusive (32 bit) + \details Executes a STL exclusive instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed */ -#define __WFE __builtin_arm_wfe +#define __STLEX (uint32_t)__builtin_arm_stlex + +#endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) || \ + (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) */ + +/*@}*/ /* end of group CMSIS_Core_InstructionInterface */ +/* ########################### Core Function Access ########################### */ +/** \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions + @{ + */ + /** - \brief Send Event - \details Send Event is a hint instruction. It causes an event to be signaled to the CPU. + \brief Enable IRQ Interrupts + \details Enables IRQ interrupts by clearing special-purpose register PRIMASK. + Can only be executed in Privileged modes. */ -#define __SEV __builtin_arm_sev +#ifndef __ARM_COMPAT_H +__STATIC_FORCEINLINE void __enable_irq(void) +{ + __ASM volatile ("cpsie i" : : : "memory"); +} +#endif /** - \brief Instruction Synchronization Barrier - \details Instruction Synchronization Barrier flushes the pipeline in the processor, - so that all instructions following the ISB are fetched from cache or memory, - after the instruction has been completed. + \brief Disable IRQ Interrupts + \details Disables IRQ interrupts by setting special-purpose register PRIMASK. + Can only be executed in Privileged modes. */ -#define __ISB() __builtin_arm_isb(0xF) +#ifndef __ARM_COMPAT_H +__STATIC_FORCEINLINE void __disable_irq(void) +{ + __ASM volatile ("cpsid i" : : : "memory"); +} +#endif + /** - \brief Data Synchronization Barrier - \details Acts as a special kind of Data Memory Barrier. - It completes when all explicit memory accesses before this instruction complete. + \brief Get Control Register + \details Returns the content of the Control Register. + \return Control Register value */ -#define __DSB() __builtin_arm_dsb(0xF) +__STATIC_FORCEINLINE uint32_t __get_CONTROL(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, control" : "=r" (result) ); + return(result); +} +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Data Memory Barrier - \details Ensures the apparent order of the explicit memory operations before - and after the instruction, without ensuring their completion. + \brief Get Control Register (non-secure) + \details Returns the content of the non-secure Control Register when in secure mode. + \return non-secure Control Register value */ -#define __DMB() __builtin_arm_dmb(0xF) +__STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, control_ns" : "=r" (result) ); + return(result); +} +#endif /** - \brief Reverse byte order (32 bit) - \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412. - \param [in] value Value to reverse - \return Reversed value + \brief Set Control Register + \details Writes the given value to the Control Register. + \param [in] control Control Register value to set */ -#define __REV(value) __builtin_bswap32(value) +__STATIC_FORCEINLINE void __set_CONTROL(uint32_t control) +{ + __ASM volatile ("MSR control, %0" : : "r" (control) : "memory"); + __ISB(); +} +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Reverse byte order (16 bit) - \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856. - \param [in] value Value to reverse - \return Reversed value + \brief Set Control Register (non-secure) + \details Writes the given value to the non-secure Control Register when in secure state. + \param [in] control Control Register value to set */ -#define __REV16(value) __ROR(__REV(value), 16) +__STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control) +{ + __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory"); + __ISB(); +} +#endif /** - \brief Reverse byte order (16 bit) - \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000. - \param [in] value Value to reverse - \return Reversed value + \brief Get IPSR Register + \details Returns the content of the IPSR Register. + \return IPSR Register value */ -#define __REVSH(value) (int16_t)__builtin_bswap16(value) +__STATIC_FORCEINLINE uint32_t __get_IPSR(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, ipsr" : "=r" (result) ); + return(result); +} /** - \brief Rotate Right in unsigned value (32 bit) - \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits. - \param [in] op1 Value to rotate - \param [in] op2 Number of Bits to rotate - \return Rotated value + \brief Get APSR Register + \details Returns the content of the APSR Register. + \return APSR Register value */ -__STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE uint32_t __get_APSR(void) { - op2 %= 32U; - if (op2 == 0U) - { - return op1; - } - return (op1 >> op2) | (op1 << (32U - op2)); + uint32_t result; + + __ASM volatile ("MRS %0, apsr" : "=r" (result) ); + return(result); } /** - \brief Breakpoint - \details Causes the processor to enter Debug state. - Debug tools can use this to investigate system state when the instruction at a particular address is reached. - \param [in] value is ignored by the processor. - If required, a debugger can use it to store additional information about the breakpoint. + \brief Get xPSR Register + \details Returns the content of the xPSR Register. + \return xPSR Register value */ -#define __BKPT(value) __ASM volatile ("bkpt "#value) +__STATIC_FORCEINLINE uint32_t __get_xPSR(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, xpsr" : "=r" (result) ); + return(result); +} /** - \brief Reverse bit order of value - \details Reverses the bit order of the given value. - \param [in] value Value to reverse - \return Reversed value + \brief Get Process Stack Pointer + \details Returns the current value of the Process Stack Pointer (PSP). + \return PSP Register value */ -#define __RBIT __builtin_arm_rbit +__STATIC_FORCEINLINE uint32_t __get_PSP(void) +{ + uint32_t result; + __ASM volatile ("MRS %0, psp" : "=r" (result) ); + return(result); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Count leading zeros - \details Counts the number of leading zeros of a data value. - \param [in] value Value to count the leading zeros - \return number of leading zeros in value + \brief Get Process Stack Pointer (non-secure) + \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state. + \return PSP Register value */ -__STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value) +__STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void) { - /* Even though __builtin_clz produces a CLZ instruction on ARM, formally - __builtin_clz(0) is undefined behaviour, so handle this case specially. - This guarantees ARM-compatible results if happening to compile on a non-ARM - target, and ensures the compiler doesn't decide to activate any - optimisations using the logic "value was passed to __builtin_clz, so it - is non-zero". - ARM Compiler 6.10 and possibly earlier will optimise this test away, leaving a - single CLZ instruction. - */ - if (value == 0U) - { - return 32U; - } - return __builtin_clz(value); + uint32_t result; + + __ASM volatile ("MRS %0, psp_ns" : "=r" (result) ); + return(result); } +#endif -#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ - (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ - (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ - (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) /** - \brief LDR Exclusive (8 bit) - \details Executes a exclusive LDR instruction for 8 bit value. - \param [in] ptr Pointer to data - \return value of type uint8_t at (*ptr) + \brief Set Process Stack Pointer + \details Assigns the given value to the Process Stack Pointer (PSP). + \param [in] topOfProcStack Process Stack Pointer value to set */ -#define __LDREXB (uint8_t)__builtin_arm_ldrex +__STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack) +{ + __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : ); +} +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief LDR Exclusive (16 bit) - \details Executes a exclusive LDR instruction for 16 bit values. - \param [in] ptr Pointer to data - \return value of type uint16_t at (*ptr) + \brief Set Process Stack Pointer (non-secure) + \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state. + \param [in] topOfProcStack Process Stack Pointer value to set */ -#define __LDREXH (uint16_t)__builtin_arm_ldrex +__STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack) +{ + __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : ); +} +#endif /** - \brief LDR Exclusive (32 bit) - \details Executes a exclusive LDR instruction for 32 bit values. - \param [in] ptr Pointer to data - \return value of type uint32_t at (*ptr) + \brief Get Main Stack Pointer + \details Returns the current value of the Main Stack Pointer (MSP). + \return MSP Register value */ -#define __LDREXW (uint32_t)__builtin_arm_ldrex +__STATIC_FORCEINLINE uint32_t __get_MSP(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, msp" : "=r" (result) ); + return(result); +} +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief STR Exclusive (8 bit) - \details Executes a exclusive STR instruction for 8 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed + \brief Get Main Stack Pointer (non-secure) + \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state. + \return MSP Register value */ -#define __STREXB (uint32_t)__builtin_arm_strex +__STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, msp_ns" : "=r" (result) ); + return(result); +} +#endif /** - \brief STR Exclusive (16 bit) - \details Executes a exclusive STR instruction for 16 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed + \brief Set Main Stack Pointer + \details Assigns the given value to the Main Stack Pointer (MSP). + \param [in] topOfMainStack Main Stack Pointer value to set */ -#define __STREXH (uint32_t)__builtin_arm_strex +__STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack) +{ + __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : ); +} +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief STR Exclusive (32 bit) - \details Executes a exclusive STR instruction for 32 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed + \brief Set Main Stack Pointer (non-secure) + \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state. + \param [in] topOfMainStack Main Stack Pointer value to set */ -#define __STREXW (uint32_t)__builtin_arm_strex +__STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack) +{ + __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : ); +} +#endif +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Remove the exclusive lock - \details Removes the exclusive lock which is created by LDREX. + \brief Get Stack Pointer (non-secure) + \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state. + \return SP Register value */ -#define __CLREX __builtin_arm_clrex - -#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ - (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ - (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ - (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */ +__STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void) +{ + uint32_t result; + __ASM volatile ("MRS %0, sp_ns" : "=r" (result) ); + return(result); +} -#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ - (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ - (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) /** - \brief Signed Saturate - \details Saturates a signed value. - \param [in] value Value to be saturated - \param [in] sat Bit position to saturate to (1..32) - \return Saturated value + \brief Set Stack Pointer (non-secure) + \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state. + \param [in] topOfStack Stack Pointer value to set */ -#define __SSAT __builtin_arm_ssat +__STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack) +{ + __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : ); +} +#endif /** - \brief Unsigned Saturate - \details Saturates an unsigned value. - \param [in] value Value to be saturated - \param [in] sat Bit position to saturate to (0..31) - \return Saturated value + \brief Get Priority Mask + \details Returns the current state of the priority mask bit from the Priority Mask Register. + \return Priority Mask value */ -#define __USAT __builtin_arm_usat +__STATIC_FORCEINLINE uint32_t __get_PRIMASK(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, primask" : "=r" (result) ); + return(result); +} +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Rotate Right with Extend (32 bit) - \details Moves each bit of a bitstring right by one bit. - The carry input is shifted in at the left end of the bitstring. - \param [in] value Value to rotate - \return Rotated value + \brief Get Priority Mask (non-secure) + \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state. + \return Priority Mask value */ -__STATIC_FORCEINLINE uint32_t __RRX(uint32_t value) +__STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void) { uint32_t result; - __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); + __ASM volatile ("MRS %0, primask_ns" : "=r" (result) ); return(result); } +#endif /** - \brief LDRT Unprivileged (8 bit) - \details Executes a Unprivileged LDRT instruction for 8 bit value. - \param [in] ptr Pointer to data - \return value of type uint8_t at (*ptr) + \brief Set Priority Mask + \details Assigns the given value to the Priority Mask Register. + \param [in] priMask Priority Mask */ -__STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr) +__STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask) { - uint32_t result; + __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory"); +} - __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) ); - return ((uint8_t) result); /* Add explicit type cast here */ + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Priority Mask (non-secure) + \details Assigns the given value to the non-secure Priority Mask Register when in secure state. + \param [in] priMask Priority Mask + */ +__STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask) +{ + __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory"); } +#endif +#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) /** - \brief LDRT Unprivileged (16 bit) - \details Executes a Unprivileged LDRT instruction for 16 bit values. - \param [in] ptr Pointer to data - \return value of type uint16_t at (*ptr) + \brief Enable FIQ + \details Enables FIQ interrupts by clearing special-purpose register FAULTMASK. + Can only be executed in Privileged modes. */ -__STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr) +__STATIC_FORCEINLINE void __enable_fault_irq(void) { - uint32_t result; + __ASM volatile ("cpsie f" : : : "memory"); +} - __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) ); - return ((uint16_t) result); /* Add explicit type cast here */ + +/** + \brief Disable FIQ + \details Disables FIQ interrupts by setting special-purpose register FAULTMASK. + Can only be executed in Privileged modes. + */ +__STATIC_FORCEINLINE void __disable_fault_irq(void) +{ + __ASM volatile ("cpsid f" : : : "memory"); } /** - \brief LDRT Unprivileged (32 bit) - \details Executes a Unprivileged LDRT instruction for 32 bit values. - \param [in] ptr Pointer to data - \return value of type uint32_t at (*ptr) + \brief Get Base Priority + \details Returns the current value of the Base Priority register. + \return Base Priority register value */ -__STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr) +__STATIC_FORCEINLINE uint32_t __get_BASEPRI(void) { uint32_t result; - __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) ); + __ASM volatile ("MRS %0, basepri" : "=r" (result) ); return(result); } +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief STRT Unprivileged (8 bit) - \details Executes a Unprivileged STRT instruction for 8 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location + \brief Get Base Priority (non-secure) + \details Returns the current value of the non-secure Base Priority register when in secure state. + \return Base Priority register value */ -__STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr) +__STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void) { - __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); + uint32_t result; + + __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) ); + return(result); } +#endif /** - \brief STRT Unprivileged (16 bit) - \details Executes a Unprivileged STRT instruction for 16 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location + \brief Set Base Priority + \details Assigns the given value to the Base Priority register. + \param [in] basePri Base Priority value to set */ -__STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr) +__STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri) { - __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); + __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory"); } +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief STRT Unprivileged (32 bit) - \details Executes a Unprivileged STRT instruction for 32 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location + \brief Set Base Priority (non-secure) + \details Assigns the given value to the non-secure Base Priority register when in secure state. + \param [in] basePri Base Priority value to set */ -__STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr) +__STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri) { - __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) ); + __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory"); } +#endif -#else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ - (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ - (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */ /** - \brief Signed Saturate - \details Saturates a signed value. - \param [in] value Value to be saturated - \param [in] sat Bit position to saturate to (1..32) - \return Saturated value + \brief Set Base Priority with condition + \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled, + or the new value increases the BASEPRI priority level. + \param [in] basePri Base Priority value to set */ -__STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat) +__STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri) { - if ((sat >= 1U) && (sat <= 32U)) - { - const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); - const int32_t min = -1 - max ; - if (val > max) - { - return max; - } - else if (val < min) - { - return min; - } - } - return val; + __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory"); } + /** - \brief Unsigned Saturate - \details Saturates an unsigned value. - \param [in] value Value to be saturated - \param [in] sat Bit position to saturate to (0..31) - \return Saturated value - */ -__STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat) -{ - if (sat <= 31U) - { - const uint32_t max = ((1U << sat) - 1U); - if (val > (int32_t)max) - { - return max; - } - else if (val < 0) - { - return 0U; - } - } - return (uint32_t)val; -} + \brief Get Fault Mask + \details Returns the current value of the Fault Mask register. + \return Fault Mask register value + */ +__STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void) +{ + uint32_t result; -#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ - (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ - (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */ + __ASM volatile ("MRS %0, faultmask" : "=r" (result) ); + return(result); +} -#if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ - (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Load-Acquire (8 bit) - \details Executes a LDAB instruction for 8 bit value. - \param [in] ptr Pointer to data - \return value of type uint8_t at (*ptr) + \brief Get Fault Mask (non-secure) + \details Returns the current value of the non-secure Fault Mask register when in secure state. + \return Fault Mask register value */ -__STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr) +__STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void) { uint32_t result; - __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) ); - return ((uint8_t) result); + __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) ); + return(result); } +#endif /** - \brief Load-Acquire (16 bit) - \details Executes a LDAH instruction for 16 bit values. - \param [in] ptr Pointer to data - \return value of type uint16_t at (*ptr) + \brief Set Fault Mask + \details Assigns the given value to the Fault Mask register. + \param [in] faultMask Fault Mask value to set */ -__STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr) +__STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask) { - uint32_t result; + __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory"); +} - __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) ); - return ((uint16_t) result); + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Fault Mask (non-secure) + \details Assigns the given value to the non-secure Fault Mask register when in secure state. + \param [in] faultMask Fault Mask value to set + */ +__STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask) +{ + __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory"); } +#endif + +#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) */ +#if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) || \ + (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) + /** - \brief Load-Acquire (32 bit) - \details Executes a LDA instruction for 32 bit values. - \param [in] ptr Pointer to data - \return value of type uint32_t at (*ptr) + \brief Get Process Stack Pointer Limit + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence zero is returned always in non-secure + mode. + + \details Returns the current value of the Process Stack Pointer Limit (PSPLIM). + \return PSPLIM Register value */ -__STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr) +__STATIC_FORCEINLINE uint32_t __get_PSPLIM(void) { +#if (!((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + return 0U; +#else uint32_t result; - - __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) ); - return(result); + __ASM volatile ("MRS %0, psplim" : "=r" (result) ); + return result; +#endif } - +#if (defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Store-Release (8 bit) - \details Executes a STLB instruction for 8 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location + \brief Get Process Stack Pointer Limit (non-secure) + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence zero is returned always in non-secure + mode. + + \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state. + \return PSPLIM Register value */ -__STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr) +__STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void) { - __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +#if (!((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) ) + // without main extensions, the non-secure PSPLIM is RAZ/WI + return 0U; +#else + uint32_t result; + __ASM volatile ("MRS %0, psplim_ns" : "=r" (result) ); + return result; +#endif } +#endif /** - \brief Store-Release (16 bit) - \details Executes a STLH instruction for 16 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location + \brief Set Process Stack Pointer Limit + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence the write is silently ignored in non-secure + mode. + + \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM). + \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set */ -__STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr) +__STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit) { - __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +#if (!((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + (void)ProcStackPtrLimit; +#else + __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit)); +#endif } +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Store-Release (32 bit) - \details Executes a STL instruction for 32 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location + \brief Set Process Stack Pointer (non-secure) + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence the write is silently ignored in non-secure + mode. + + \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state. + \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set */ -__STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr) +__STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit) { - __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +#if (!((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) ) + // without main extensions, the non-secure PSPLIM is RAZ/WI + (void)ProcStackPtrLimit; +#else + __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit)); +#endif } +#endif /** - \brief Load-Acquire Exclusive (8 bit) - \details Executes a LDAB exclusive instruction for 8 bit value. - \param [in] ptr Pointer to data - \return value of type uint8_t at (*ptr) + \brief Get Main Stack Pointer Limit + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence zero is returned always. + + \details Returns the current value of the Main Stack Pointer Limit (MSPLIM). + \return MSPLIM Register value */ -#define __LDAEXB (uint8_t)__builtin_arm_ldaex +__STATIC_FORCEINLINE uint32_t __get_MSPLIM(void) +{ +#if (!((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + return 0U; +#else + uint32_t result; + __ASM volatile ("MRS %0, msplim" : "=r" (result) ); + return result; +#endif +} +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Load-Acquire Exclusive (16 bit) - \details Executes a LDAH exclusive instruction for 16 bit values. - \param [in] ptr Pointer to data - \return value of type uint16_t at (*ptr) + \brief Get Main Stack Pointer Limit (non-secure) + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence zero is returned always. + + \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state. + \return MSPLIM Register value */ -#define __LDAEXH (uint16_t)__builtin_arm_ldaex +__STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void) +{ +#if (!((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) ) + // without main extensions, the non-secure MSPLIM is RAZ/WI + return 0U; +#else + uint32_t result; + __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) ); + return result; +#endif +} +#endif /** - \brief Load-Acquire Exclusive (32 bit) - \details Executes a LDA exclusive instruction for 32 bit values. - \param [in] ptr Pointer to data - \return value of type uint32_t at (*ptr) + \brief Set Main Stack Pointer Limit + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence the write is silently ignored. + + \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM). + \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set */ -#define __LDAEX (uint32_t)__builtin_arm_ldaex +__STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit) +{ +#if (!((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + (void)MainStackPtrLimit; +#else + __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit)); +#endif +} +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Store-Release Exclusive (8 bit) - \details Executes a STLB exclusive instruction for 8 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed + \brief Set Main Stack Pointer Limit (non-secure) + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence the write is silently ignored. + + \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state. + \param [in] MainStackPtrLimit Main Stack Pointer value to set */ -#define __STLEXB (uint32_t)__builtin_arm_stlex +__STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit) +{ +#if (!((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) ) + // without main extensions, the non-secure MSPLIM is RAZ/WI + (void)MainStackPtrLimit; +#else + __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit)); +#endif +} +#endif +#endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) || \ + (defined (__ARM_ARCH_8_1M_MAIN__) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) */ /** - \brief Store-Release Exclusive (16 bit) - \details Executes a STLH exclusive instruction for 16 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed + \brief Get FPSCR + \details Returns the current value of the Floating Point Status/Control register. + \return Floating Point Status/Control register value */ -#define __STLEXH (uint32_t)__builtin_arm_stlex - +#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ + (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) +#define __get_FPSCR (uint32_t)__builtin_arm_get_fpscr +#else +#define __get_FPSCR() ((uint32_t)0U) +#endif /** - \brief Store-Release Exclusive (32 bit) - \details Executes a STL exclusive instruction for 32 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed + \brief Set FPSCR + \details Assigns the given value to the Floating Point Status/Control register. + \param [in] fpscr Floating Point Status/Control value to set */ -#define __STLEX (uint32_t)__builtin_arm_stlex +#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ + (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) +#define __set_FPSCR __builtin_arm_set_fpscr +#else +#define __set_FPSCR(x) ((void)(x)) +#endif -#endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ - (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */ -/*@}*/ /* end of group CMSIS_Core_InstructionInterface */ +/*@} end of CMSIS_Core_RegAccFunctions */ /* ################### Compiler specific Intrinsics ########################### */ @@ -1405,6 +1484,10 @@ __STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr) #define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \ ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) ) +#define __SXTB16_RORn(ARG1, ARG2) __SXTB16(__ROR(ARG1, ARG2)) + +#define __SXTAB16_RORn(ARG1, ARG2, ARG3) __SXTAB16(ARG1, __ROR(ARG2, ARG3)) + __STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3) { int32_t result; diff --git a/lib/cmsis/inc/cmsis_armclang_ltm.h b/lib/cmsis/inc/cmsis_armclang_ltm.h index e4002a3fc4c93..1e255d5907f66 100644 --- a/lib/cmsis/inc/cmsis_armclang_ltm.h +++ b/lib/cmsis/inc/cmsis_armclang_ltm.h @@ -1,11 +1,11 @@ /**************************************************************************//** * @file cmsis_armclang_ltm.h * @brief CMSIS compiler armclang (Arm Compiler 6) header file - * @version V1.0.1 - * @date 19. March 2019 + * @version V1.5.3 + * @date 27. May 2021 ******************************************************************************/ /* - * Copyright (c) 2018-2019 Arm Limited. All rights reserved. + * Copyright (c) 2018-2021 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -29,10 +29,6 @@ #pragma clang system_header /* treat file as system include file */ -#ifndef __ARM_COMPAT_H -#include /* Compatibility header for Arm Compiler 5 intrinsics */ -#endif - /* CMSIS compiler specific defines */ #ifndef __ASM #define __ASM __asm @@ -110,1071 +106,1073 @@ #ifndef __RESTRICT #define __RESTRICT __restrict #endif +#ifndef __COMPILER_BARRIER + #define __COMPILER_BARRIER() __ASM volatile("":::"memory") +#endif +/* ######################### Startup and Lowlevel Init ######################## */ -/* ########################### Core Function Access ########################### */ -/** \ingroup CMSIS_Core_FunctionInterface - \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions - @{ - */ +#ifndef __PROGRAM_START +#define __PROGRAM_START __main +#endif -/** - \brief Enable IRQ Interrupts - \details Enables IRQ interrupts by clearing the I-bit in the CPSR. - Can only be executed in Privileged modes. - */ -/* intrinsic void __enable_irq(); see arm_compat.h */ +#ifndef __INITIAL_SP +#define __INITIAL_SP Image$$ARM_LIB_STACK$$ZI$$Limit +#endif +#ifndef __STACK_LIMIT +#define __STACK_LIMIT Image$$ARM_LIB_STACK$$ZI$$Base +#endif -/** - \brief Disable IRQ Interrupts - \details Disables IRQ interrupts by setting the I-bit in the CPSR. - Can only be executed in Privileged modes. - */ -/* intrinsic void __disable_irq(); see arm_compat.h */ +#ifndef __VECTOR_TABLE +#define __VECTOR_TABLE __Vectors +#endif +#ifndef __VECTOR_TABLE_ATTRIBUTE +#define __VECTOR_TABLE_ATTRIBUTE __attribute__((used, section("RESET"))) +#endif -/** - \brief Get Control Register - \details Returns the content of the Control Register. - \return Control Register value - */ -__STATIC_FORCEINLINE uint32_t __get_CONTROL(void) -{ - uint32_t result; +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +#ifndef __STACK_SEAL +#define __STACK_SEAL Image$$STACKSEAL$$ZI$$Base +#endif - __ASM volatile ("MRS %0, control" : "=r" (result) ); - return(result); -} +#ifndef __TZ_STACK_SEAL_SIZE +#define __TZ_STACK_SEAL_SIZE 8U +#endif +#ifndef __TZ_STACK_SEAL_VALUE +#define __TZ_STACK_SEAL_VALUE 0xFEF5EDA5FEF5EDA5ULL +#endif -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) -/** - \brief Get Control Register (non-secure) - \details Returns the content of the non-secure Control Register when in secure mode. - \return non-secure Control Register value - */ -__STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void) -{ - uint32_t result; - __ASM volatile ("MRS %0, control_ns" : "=r" (result) ); - return(result); +__STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) { + *((uint64_t *)stackTop) = __TZ_STACK_SEAL_VALUE; } #endif -/** - \brief Set Control Register - \details Writes the given value to the Control Register. - \param [in] control Control Register value to set - */ -__STATIC_FORCEINLINE void __set_CONTROL(uint32_t control) -{ - __ASM volatile ("MSR control, %0" : : "r" (control) : "memory"); -} +/* ########################## Core Instruction Access ######################### */ +/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface + Access to dedicated instructions + @{ +*/ +/* Define macros for porting to both thumb1 and thumb2. + * For thumb1, use low register (r0-r7), specified by constraint "l" + * Otherwise, use general registers, specified by constraint "r" */ +#if defined (__thumb__) && !defined (__thumb2__) +#define __CMSIS_GCC_OUT_REG(r) "=l" (r) +#define __CMSIS_GCC_USE_REG(r) "l" (r) +#else +#define __CMSIS_GCC_OUT_REG(r) "=r" (r) +#define __CMSIS_GCC_USE_REG(r) "r" (r) +#endif -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Set Control Register (non-secure) - \details Writes the given value to the non-secure Control Register when in secure state. - \param [in] control Control Register value to set + \brief No Operation + \details No Operation does nothing. This instruction can be used for code alignment purposes. */ -__STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control) -{ - __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory"); -} -#endif - +#define __NOP __builtin_arm_nop /** - \brief Get IPSR Register - \details Returns the content of the IPSR Register. - \return IPSR Register value + \brief Wait For Interrupt + \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs. */ -__STATIC_FORCEINLINE uint32_t __get_IPSR(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, ipsr" : "=r" (result) ); - return(result); -} +#define __WFI __builtin_arm_wfi /** - \brief Get APSR Register - \details Returns the content of the APSR Register. - \return APSR Register value + \brief Wait For Event + \details Wait For Event is a hint instruction that permits the processor to enter + a low-power state until one of a number of events occurs. */ -__STATIC_FORCEINLINE uint32_t __get_APSR(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, apsr" : "=r" (result) ); - return(result); -} +#define __WFE __builtin_arm_wfe /** - \brief Get xPSR Register - \details Returns the content of the xPSR Register. - \return xPSR Register value + \brief Send Event + \details Send Event is a hint instruction. It causes an event to be signaled to the CPU. */ -__STATIC_FORCEINLINE uint32_t __get_xPSR(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, xpsr" : "=r" (result) ); - return(result); -} +#define __SEV __builtin_arm_sev /** - \brief Get Process Stack Pointer - \details Returns the current value of the Process Stack Pointer (PSP). - \return PSP Register value + \brief Instruction Synchronization Barrier + \details Instruction Synchronization Barrier flushes the pipeline in the processor, + so that all instructions following the ISB are fetched from cache or memory, + after the instruction has been completed. */ -__STATIC_FORCEINLINE uint32_t __get_PSP(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, psp" : "=r" (result) ); - return(result); -} - +#define __ISB() __builtin_arm_isb(0xF) -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Get Process Stack Pointer (non-secure) - \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state. - \return PSP Register value + \brief Data Synchronization Barrier + \details Acts as a special kind of Data Memory Barrier. + It completes when all explicit memory accesses before this instruction complete. */ -__STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, psp_ns" : "=r" (result) ); - return(result); -} -#endif +#define __DSB() __builtin_arm_dsb(0xF) /** - \brief Set Process Stack Pointer - \details Assigns the given value to the Process Stack Pointer (PSP). - \param [in] topOfProcStack Process Stack Pointer value to set + \brief Data Memory Barrier + \details Ensures the apparent order of the explicit memory operations before + and after the instruction, without ensuring their completion. */ -__STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack) -{ - __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : ); -} +#define __DMB() __builtin_arm_dmb(0xF) -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Set Process Stack Pointer (non-secure) - \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state. - \param [in] topOfProcStack Process Stack Pointer value to set + \brief Reverse byte order (32 bit) + \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412. + \param [in] value Value to reverse + \return Reversed value */ -__STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack) -{ - __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : ); -} -#endif +#define __REV(value) __builtin_bswap32(value) /** - \brief Get Main Stack Pointer - \details Returns the current value of the Main Stack Pointer (MSP). - \return MSP Register value + \brief Reverse byte order (16 bit) + \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856. + \param [in] value Value to reverse + \return Reversed value */ -__STATIC_FORCEINLINE uint32_t __get_MSP(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, msp" : "=r" (result) ); - return(result); -} +#define __REV16(value) __ROR(__REV(value), 16) -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Get Main Stack Pointer (non-secure) - \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state. - \return MSP Register value + \brief Reverse byte order (16 bit) + \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000. + \param [in] value Value to reverse + \return Reversed value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, msp_ns" : "=r" (result) ); - return(result); -} -#endif +#define __REVSH(value) (int16_t)__builtin_bswap16(value) /** - \brief Set Main Stack Pointer - \details Assigns the given value to the Main Stack Pointer (MSP). - \param [in] topOfMainStack Main Stack Pointer value to set + \brief Rotate Right in unsigned value (32 bit) + \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits. + \param [in] op1 Value to rotate + \param [in] op2 Number of Bits to rotate + \return Rotated value */ -__STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack) +__STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2) { - __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : ); + op2 %= 32U; + if (op2 == 0U) + { + return op1; + } + return (op1 >> op2) | (op1 << (32U - op2)); } -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Set Main Stack Pointer (non-secure) - \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state. - \param [in] topOfMainStack Main Stack Pointer value to set + \brief Breakpoint + \details Causes the processor to enter Debug state. + Debug tools can use this to investigate system state when the instruction at a particular address is reached. + \param [in] value is ignored by the processor. + If required, a debugger can use it to store additional information about the breakpoint. */ -__STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack) -{ - __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : ); -} -#endif +#define __BKPT(value) __ASM volatile ("bkpt "#value) -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Get Stack Pointer (non-secure) - \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state. - \return SP Register value + \brief Reverse bit order of value + \details Reverses the bit order of the given value. + \param [in] value Value to reverse + \return Reversed value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void) -{ - uint32_t result; +#define __RBIT __builtin_arm_rbit - __ASM volatile ("MRS %0, sp_ns" : "=r" (result) ); - return(result); +/** + \brief Count leading zeros + \details Counts the number of leading zeros of a data value. + \param [in] value Value to count the leading zeros + \return number of leading zeros in value + */ +__STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value) +{ + /* Even though __builtin_clz produces a CLZ instruction on ARM, formally + __builtin_clz(0) is undefined behaviour, so handle this case specially. + This guarantees ARM-compatible results if happening to compile on a non-ARM + target, and ensures the compiler doesn't decide to activate any + optimisations using the logic "value was passed to __builtin_clz, so it + is non-zero". + ARM Compiler 6.10 and possibly earlier will optimise this test away, leaving a + single CLZ instruction. + */ + if (value == 0U) + { + return 32U; + } + return __builtin_clz(value); } +#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) /** - \brief Set Stack Pointer (non-secure) - \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state. - \param [in] topOfStack Stack Pointer value to set + \brief LDR Exclusive (8 bit) + \details Executes a exclusive LDR instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) */ -__STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack) -{ - __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : ); -} -#endif +#define __LDREXB (uint8_t)__builtin_arm_ldrex /** - \brief Get Priority Mask - \details Returns the current state of the priority mask bit from the Priority Mask Register. - \return Priority Mask value + \brief LDR Exclusive (16 bit) + \details Executes a exclusive LDR instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) */ -__STATIC_FORCEINLINE uint32_t __get_PRIMASK(void) -{ - uint32_t result; +#define __LDREXH (uint16_t)__builtin_arm_ldrex - __ASM volatile ("MRS %0, primask" : "=r" (result) ); - return(result); -} + +/** + \brief LDR Exclusive (32 bit) + \details Executes a exclusive LDR instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) + */ +#define __LDREXW (uint32_t)__builtin_arm_ldrex -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Get Priority Mask (non-secure) - \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state. - \return Priority Mask value + \brief STR Exclusive (8 bit) + \details Executes a exclusive STR instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed */ -__STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void) -{ - uint32_t result; +#define __STREXB (uint32_t)__builtin_arm_strex - __ASM volatile ("MRS %0, primask_ns" : "=r" (result) ); - return(result); -} -#endif + +/** + \brief STR Exclusive (16 bit) + \details Executes a exclusive STR instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +#define __STREXH (uint32_t)__builtin_arm_strex /** - \brief Set Priority Mask - \details Assigns the given value to the Priority Mask Register. - \param [in] priMask Priority Mask + \brief STR Exclusive (32 bit) + \details Executes a exclusive STR instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed */ -__STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask) -{ - __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory"); -} +#define __STREXW (uint32_t)__builtin_arm_strex -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Set Priority Mask (non-secure) - \details Assigns the given value to the non-secure Priority Mask Register when in secure state. - \param [in] priMask Priority Mask + \brief Remove the exclusive lock + \details Removes the exclusive lock which is created by LDREX. */ -__STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask) -{ - __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory"); -} -#endif +#define __CLREX __builtin_arm_clrex + +#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */ #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) + /** - \brief Enable FIQ - \details Enables FIQ interrupts by clearing the F-bit in the CPSR. - Can only be executed in Privileged modes. + \brief Signed Saturate + \details Saturates a signed value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (1..32) + \return Saturated value */ -#define __enable_fault_irq __enable_fiq /* see arm_compat.h */ +#define __SSAT __builtin_arm_ssat /** - \brief Disable FIQ - \details Disables FIQ interrupts by setting the F-bit in the CPSR. - Can only be executed in Privileged modes. + \brief Unsigned Saturate + \details Saturates an unsigned value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (0..31) + \return Saturated value */ -#define __disable_fault_irq __disable_fiq /* see arm_compat.h */ +#define __USAT __builtin_arm_usat /** - \brief Get Base Priority - \details Returns the current value of the Base Priority register. - \return Base Priority register value + \brief Rotate Right with Extend (32 bit) + \details Moves each bit of a bitstring right by one bit. + The carry input is shifted in at the left end of the bitstring. + \param [in] value Value to rotate + \return Rotated value */ -__STATIC_FORCEINLINE uint32_t __get_BASEPRI(void) +__STATIC_FORCEINLINE uint32_t __RRX(uint32_t value) { uint32_t result; - __ASM volatile ("MRS %0, basepri" : "=r" (result) ); + __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); return(result); } -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Get Base Priority (non-secure) - \details Returns the current value of the non-secure Base Priority register when in secure state. - \return Base Priority register value + \brief LDRT Unprivileged (8 bit) + \details Executes a Unprivileged LDRT instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) */ -__STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void) +__STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr) { uint32_t result; - __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) ); - return(result); -} -#endif - - -/** - \brief Set Base Priority - \details Assigns the given value to the Base Priority register. - \param [in] basePri Base Priority value to set - */ -__STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri) -{ - __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory"); + __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) ); + return ((uint8_t) result); /* Add explicit type cast here */ } -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Set Base Priority (non-secure) - \details Assigns the given value to the non-secure Base Priority register when in secure state. - \param [in] basePri Base Priority value to set + \brief LDRT Unprivileged (16 bit) + \details Executes a Unprivileged LDRT instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) */ -__STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri) +__STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr) { - __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory"); -} -#endif - + uint32_t result; -/** - \brief Set Base Priority with condition - \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled, - or the new value increases the BASEPRI priority level. - \param [in] basePri Base Priority value to set - */ -__STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri) -{ - __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory"); + __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) ); + return ((uint16_t) result); /* Add explicit type cast here */ } /** - \brief Get Fault Mask - \details Returns the current value of the Fault Mask register. - \return Fault Mask register value + \brief LDRT Unprivileged (32 bit) + \details Executes a Unprivileged LDRT instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) */ -__STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void) +__STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr) { uint32_t result; - __ASM volatile ("MRS %0, faultmask" : "=r" (result) ); + __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) ); return(result); } -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Get Fault Mask (non-secure) - \details Returns the current value of the non-secure Fault Mask register when in secure state. - \return Fault Mask register value + \brief STRT Unprivileged (8 bit) + \details Executes a Unprivileged STRT instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void) +__STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr) { - uint32_t result; - - __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) ); - return(result); + __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); } -#endif /** - \brief Set Fault Mask - \details Assigns the given value to the Fault Mask register. - \param [in] faultMask Fault Mask value to set + \brief STRT Unprivileged (16 bit) + \details Executes a Unprivileged STRT instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask) +__STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr) { - __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory"); + __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); } -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Set Fault Mask (non-secure) - \details Assigns the given value to the non-secure Fault Mask register when in secure state. - \param [in] faultMask Fault Mask value to set + \brief STRT Unprivileged (32 bit) + \details Executes a Unprivileged STRT instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask) +__STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr) { - __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory"); + __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) ); } -#endif -#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ +#else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */ + +/** + \brief Signed Saturate + \details Saturates a signed value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (1..32) + \return Saturated value + */ +__STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat) +{ + if ((sat >= 1U) && (sat <= 32U)) + { + const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); + const int32_t min = -1 - max ; + if (val > max) + { + return max; + } + else if (val < min) + { + return min; + } + } + return val; +} + +/** + \brief Unsigned Saturate + \details Saturates an unsigned value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (0..31) + \return Saturated value + */ +__STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat) +{ + if (sat <= 31U) + { + const uint32_t max = ((1U << sat) - 1U); + if (val > (int32_t)max) + { + return max; + } + else if (val < 0) + { + return 0U; + } + } + return (uint32_t)val; +} + +#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */ #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) - /** - \brief Get Process Stack Pointer Limit - Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure - Stack Pointer Limit register hence zero is returned always in non-secure - mode. - - \details Returns the current value of the Process Stack Pointer Limit (PSPLIM). - \return PSPLIM Register value + \brief Load-Acquire (8 bit) + \details Executes a LDAB instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) */ -__STATIC_FORCEINLINE uint32_t __get_PSPLIM(void) +__STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr) { -#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ - (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - return 0U; -#else uint32_t result; - __ASM volatile ("MRS %0, psplim" : "=r" (result) ); - return result; -#endif + + __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" ); + return ((uint8_t) result); } -#if (defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)) -/** - \brief Get Process Stack Pointer Limit (non-secure) - Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure - Stack Pointer Limit register hence zero is returned always in non-secure - mode. - \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state. - \return PSPLIM Register value +/** + \brief Load-Acquire (16 bit) + \details Executes a LDAH instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) */ -__STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void) +__STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr) { -#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - return 0U; -#else uint32_t result; - __ASM volatile ("MRS %0, psplim_ns" : "=r" (result) ); - return result; -#endif + + __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" ); + return ((uint16_t) result); } -#endif /** - \brief Set Process Stack Pointer Limit - Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure - Stack Pointer Limit register hence the write is silently ignored in non-secure - mode. - - \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM). - \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set + \brief Load-Acquire (32 bit) + \details Executes a LDA instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) */ -__STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit) +__STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr) { -#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ - (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - (void)ProcStackPtrLimit; -#else - __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit)); -#endif + uint32_t result; + + __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" ); + return(result); } -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Set Process Stack Pointer (non-secure) - Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure - Stack Pointer Limit register hence the write is silently ignored in non-secure - mode. - - \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state. - \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set + \brief Store-Release (8 bit) + \details Executes a STLB instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit) +__STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr) { -#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - (void)ProcStackPtrLimit; -#else - __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit)); -#endif + __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" ); } -#endif /** - \brief Get Main Stack Pointer Limit - Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure - Stack Pointer Limit register hence zero is returned always. - - \details Returns the current value of the Main Stack Pointer Limit (MSPLIM). - \return MSPLIM Register value + \brief Store-Release (16 bit) + \details Executes a STLH instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE uint32_t __get_MSPLIM(void) +__STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr) { -#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ - (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - return 0U; -#else - uint32_t result; - __ASM volatile ("MRS %0, msplim" : "=r" (result) ); - return result; -#endif + __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" ); } -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Get Main Stack Pointer Limit (non-secure) - Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure - Stack Pointer Limit register hence zero is returned always. - - \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state. - \return MSPLIM Register value + \brief Store-Release (32 bit) + \details Executes a STL instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void) +__STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr) { -#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - return 0U; -#else - uint32_t result; - __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) ); - return result; -#endif + __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" ); } -#endif /** - \brief Set Main Stack Pointer Limit - Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure - Stack Pointer Limit register hence the write is silently ignored. + \brief Load-Acquire Exclusive (8 bit) + \details Executes a LDAB exclusive instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) + */ +#define __LDAEXB (uint8_t)__builtin_arm_ldaex - \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM). - \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set + +/** + \brief Load-Acquire Exclusive (16 bit) + \details Executes a LDAH exclusive instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) */ -__STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit) -{ -#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ - (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - (void)MainStackPtrLimit; -#else - __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit)); -#endif -} +#define __LDAEXH (uint16_t)__builtin_arm_ldaex -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Set Main Stack Pointer Limit (non-secure) - Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure - Stack Pointer Limit register hence the write is silently ignored. + \brief Load-Acquire Exclusive (32 bit) + \details Executes a LDA exclusive instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) + */ +#define __LDAEX (uint32_t)__builtin_arm_ldaex - \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state. - \param [in] MainStackPtrLimit Main Stack Pointer value to set + +/** + \brief Store-Release Exclusive (8 bit) + \details Executes a STLB exclusive instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed */ -__STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit) +#define __STLEXB (uint32_t)__builtin_arm_stlex + + +/** + \brief Store-Release Exclusive (16 bit) + \details Executes a STLH exclusive instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +#define __STLEXH (uint32_t)__builtin_arm_stlex + + +/** + \brief Store-Release Exclusive (32 bit) + \details Executes a STL exclusive instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +#define __STLEX (uint32_t)__builtin_arm_stlex + +#endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */ + +/*@}*/ /* end of group CMSIS_Core_InstructionInterface */ + + +/* ########################### Core Function Access ########################### */ +/** \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions + @{ + */ + +/** + \brief Enable IRQ Interrupts + \details Enables IRQ interrupts by clearing special-purpose register PRIMASK. + Can only be executed in Privileged modes. + */ +#ifndef __ARM_COMPAT_H +__STATIC_FORCEINLINE void __enable_irq(void) { -#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - (void)MainStackPtrLimit; -#else - __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit)); -#endif + __ASM volatile ("cpsie i" : : : "memory"); } #endif -#endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ - (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */ /** - \brief Get FPSCR - \details Returns the current value of the Floating Point Status/Control register. - \return Floating Point Status/Control register value + \brief Disable IRQ Interrupts + \details Disables IRQ interrupts by setting special-purpose register PRIMASK. + Can only be executed in Privileged modes. */ -#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ - (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) -#define __get_FPSCR (uint32_t)__builtin_arm_get_fpscr -#else -#define __get_FPSCR() ((uint32_t)0U) +#ifndef __ARM_COMPAT_H +__STATIC_FORCEINLINE void __disable_irq(void) +{ + __ASM volatile ("cpsid i" : : : "memory"); +} #endif + /** - \brief Set FPSCR - \details Assigns the given value to the Floating Point Status/Control register. - \param [in] fpscr Floating Point Status/Control value to set + \brief Get Control Register + \details Returns the content of the Control Register. + \return Control Register value */ -#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ - (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) -#define __set_FPSCR __builtin_arm_set_fpscr -#else -#define __set_FPSCR(x) ((void)(x)) -#endif - +__STATIC_FORCEINLINE uint32_t __get_CONTROL(void) +{ + uint32_t result; -/*@} end of CMSIS_Core_RegAccFunctions */ + __ASM volatile ("MRS %0, control" : "=r" (result) ); + return(result); +} -/* ########################## Core Instruction Access ######################### */ -/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface - Access to dedicated instructions - @{ -*/ +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Control Register (non-secure) + \details Returns the content of the non-secure Control Register when in secure mode. + \return non-secure Control Register value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void) +{ + uint32_t result; -/* Define macros for porting to both thumb1 and thumb2. - * For thumb1, use low register (r0-r7), specified by constraint "l" - * Otherwise, use general registers, specified by constraint "r" */ -#if defined (__thumb__) && !defined (__thumb2__) -#define __CMSIS_GCC_OUT_REG(r) "=l" (r) -#define __CMSIS_GCC_USE_REG(r) "l" (r) -#else -#define __CMSIS_GCC_OUT_REG(r) "=r" (r) -#define __CMSIS_GCC_USE_REG(r) "r" (r) + __ASM volatile ("MRS %0, control_ns" : "=r" (result) ); + return(result); +} #endif -/** - \brief No Operation - \details No Operation does nothing. This instruction can be used for code alignment purposes. - */ -#define __NOP __builtin_arm_nop /** - \brief Wait For Interrupt - \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs. + \brief Set Control Register + \details Writes the given value to the Control Register. + \param [in] control Control Register value to set */ -#define __WFI __builtin_arm_wfi +__STATIC_FORCEINLINE void __set_CONTROL(uint32_t control) +{ + __ASM volatile ("MSR control, %0" : : "r" (control) : "memory"); + __ISB(); +} +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Wait For Event - \details Wait For Event is a hint instruction that permits the processor to enter - a low-power state until one of a number of events occurs. + \brief Set Control Register (non-secure) + \details Writes the given value to the non-secure Control Register when in secure state. + \param [in] control Control Register value to set */ -#define __WFE __builtin_arm_wfe +__STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control) +{ + __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory"); + __ISB(); +} +#endif /** - \brief Send Event - \details Send Event is a hint instruction. It causes an event to be signaled to the CPU. + \brief Get IPSR Register + \details Returns the content of the IPSR Register. + \return IPSR Register value */ -#define __SEV __builtin_arm_sev +__STATIC_FORCEINLINE uint32_t __get_IPSR(void) +{ + uint32_t result; + __ASM volatile ("MRS %0, ipsr" : "=r" (result) ); + return(result); +} -/** - \brief Instruction Synchronization Barrier - \details Instruction Synchronization Barrier flushes the pipeline in the processor, - so that all instructions following the ISB are fetched from cache or memory, - after the instruction has been completed. - */ -#define __ISB() __builtin_arm_isb(0xF) /** - \brief Data Synchronization Barrier - \details Acts as a special kind of Data Memory Barrier. - It completes when all explicit memory accesses before this instruction complete. + \brief Get APSR Register + \details Returns the content of the APSR Register. + \return APSR Register value */ -#define __DSB() __builtin_arm_dsb(0xF) +__STATIC_FORCEINLINE uint32_t __get_APSR(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, apsr" : "=r" (result) ); + return(result); +} /** - \brief Data Memory Barrier - \details Ensures the apparent order of the explicit memory operations before - and after the instruction, without ensuring their completion. + \brief Get xPSR Register + \details Returns the content of the xPSR Register. + \return xPSR Register value */ -#define __DMB() __builtin_arm_dmb(0xF) +__STATIC_FORCEINLINE uint32_t __get_xPSR(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, xpsr" : "=r" (result) ); + return(result); +} /** - \brief Reverse byte order (32 bit) - \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412. - \param [in] value Value to reverse - \return Reversed value + \brief Get Process Stack Pointer + \details Returns the current value of the Process Stack Pointer (PSP). + \return PSP Register value */ -#define __REV(value) __builtin_bswap32(value) +__STATIC_FORCEINLINE uint32_t __get_PSP(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, psp" : "=r" (result) ); + return(result); +} +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Reverse byte order (16 bit) - \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856. - \param [in] value Value to reverse - \return Reversed value + \brief Get Process Stack Pointer (non-secure) + \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state. + \return PSP Register value */ -#define __REV16(value) __ROR(__REV(value), 16) +__STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, psp_ns" : "=r" (result) ); + return(result); +} +#endif /** - \brief Reverse byte order (16 bit) - \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000. - \param [in] value Value to reverse - \return Reversed value + \brief Set Process Stack Pointer + \details Assigns the given value to the Process Stack Pointer (PSP). + \param [in] topOfProcStack Process Stack Pointer value to set */ -#define __REVSH(value) (int16_t)__builtin_bswap16(value) +__STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack) +{ + __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : ); +} +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Rotate Right in unsigned value (32 bit) - \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits. - \param [in] op1 Value to rotate - \param [in] op2 Number of Bits to rotate - \return Rotated value + \brief Set Process Stack Pointer (non-secure) + \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state. + \param [in] topOfProcStack Process Stack Pointer value to set */ -__STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack) { - op2 %= 32U; - if (op2 == 0U) - { - return op1; - } - return (op1 >> op2) | (op1 << (32U - op2)); + __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : ); } +#endif /** - \brief Breakpoint - \details Causes the processor to enter Debug state. - Debug tools can use this to investigate system state when the instruction at a particular address is reached. - \param [in] value is ignored by the processor. - If required, a debugger can use it to store additional information about the breakpoint. + \brief Get Main Stack Pointer + \details Returns the current value of the Main Stack Pointer (MSP). + \return MSP Register value */ -#define __BKPT(value) __ASM volatile ("bkpt "#value) +__STATIC_FORCEINLINE uint32_t __get_MSP(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, msp" : "=r" (result) ); + return(result); +} +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Reverse bit order of value - \details Reverses the bit order of the given value. - \param [in] value Value to reverse - \return Reversed value + \brief Get Main Stack Pointer (non-secure) + \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state. + \return MSP Register value */ -#define __RBIT __builtin_arm_rbit +__STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, msp_ns" : "=r" (result) ); + return(result); +} +#endif + /** - \brief Count leading zeros - \details Counts the number of leading zeros of a data value. - \param [in] value Value to count the leading zeros - \return number of leading zeros in value + \brief Set Main Stack Pointer + \details Assigns the given value to the Main Stack Pointer (MSP). + \param [in] topOfMainStack Main Stack Pointer value to set */ -__STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value) +__STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack) { - /* Even though __builtin_clz produces a CLZ instruction on ARM, formally - __builtin_clz(0) is undefined behaviour, so handle this case specially. - This guarantees ARM-compatible results if happening to compile on a non-ARM - target, and ensures the compiler doesn't decide to activate any - optimisations using the logic "value was passed to __builtin_clz, so it - is non-zero". - ARM Compiler 6.10 and possibly earlier will optimise this test away, leaving a - single CLZ instruction. - */ - if (value == 0U) - { - return 32U; - } - return __builtin_clz(value); + __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : ); } -#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ - (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ - (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ - (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief LDR Exclusive (8 bit) - \details Executes a exclusive LDR instruction for 8 bit value. - \param [in] ptr Pointer to data - \return value of type uint8_t at (*ptr) + \brief Set Main Stack Pointer (non-secure) + \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state. + \param [in] topOfMainStack Main Stack Pointer value to set */ -#define __LDREXB (uint8_t)__builtin_arm_ldrex +__STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack) +{ + __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : ); +} +#endif +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief LDR Exclusive (16 bit) - \details Executes a exclusive LDR instruction for 16 bit values. - \param [in] ptr Pointer to data - \return value of type uint16_t at (*ptr) + \brief Get Stack Pointer (non-secure) + \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state. + \return SP Register value */ -#define __LDREXH (uint16_t)__builtin_arm_ldrex +__STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, sp_ns" : "=r" (result) ); + return(result); +} /** - \brief LDR Exclusive (32 bit) - \details Executes a exclusive LDR instruction for 32 bit values. - \param [in] ptr Pointer to data - \return value of type uint32_t at (*ptr) + \brief Set Stack Pointer (non-secure) + \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state. + \param [in] topOfStack Stack Pointer value to set */ -#define __LDREXW (uint32_t)__builtin_arm_ldrex +__STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack) +{ + __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : ); +} +#endif /** - \brief STR Exclusive (8 bit) - \details Executes a exclusive STR instruction for 8 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed + \brief Get Priority Mask + \details Returns the current state of the priority mask bit from the Priority Mask Register. + \return Priority Mask value */ -#define __STREXB (uint32_t)__builtin_arm_strex +__STATIC_FORCEINLINE uint32_t __get_PRIMASK(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, primask" : "=r" (result) ); + return(result); +} +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief STR Exclusive (16 bit) - \details Executes a exclusive STR instruction for 16 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed + \brief Get Priority Mask (non-secure) + \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state. + \return Priority Mask value */ -#define __STREXH (uint32_t)__builtin_arm_strex +__STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, primask_ns" : "=r" (result) ); + return(result); +} +#endif /** - \brief STR Exclusive (32 bit) - \details Executes a exclusive STR instruction for 32 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed + \brief Set Priority Mask + \details Assigns the given value to the Priority Mask Register. + \param [in] priMask Priority Mask */ -#define __STREXW (uint32_t)__builtin_arm_strex +__STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask) +{ + __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory"); +} +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Remove the exclusive lock - \details Removes the exclusive lock which is created by LDREX. + \brief Set Priority Mask (non-secure) + \details Assigns the given value to the non-secure Priority Mask Register when in secure state. + \param [in] priMask Priority Mask */ -#define __CLREX __builtin_arm_clrex - -#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ - (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ - (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ - (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */ +__STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask) +{ + __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory"); +} +#endif #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) - /** - \brief Signed Saturate - \details Saturates a signed value. - \param [in] value Value to be saturated - \param [in] sat Bit position to saturate to (1..32) - \return Saturated value + \brief Enable FIQ + \details Enables FIQ interrupts by clearing special-purpose register FAULTMASK. + Can only be executed in Privileged modes. */ -#define __SSAT __builtin_arm_ssat +__STATIC_FORCEINLINE void __enable_fault_irq(void) +{ + __ASM volatile ("cpsie f" : : : "memory"); +} /** - \brief Unsigned Saturate - \details Saturates an unsigned value. - \param [in] value Value to be saturated - \param [in] sat Bit position to saturate to (0..31) - \return Saturated value + \brief Disable FIQ + \details Disables FIQ interrupts by setting special-purpose register FAULTMASK. + Can only be executed in Privileged modes. */ -#define __USAT __builtin_arm_usat +__STATIC_FORCEINLINE void __disable_fault_irq(void) +{ + __ASM volatile ("cpsid f" : : : "memory"); +} /** - \brief Rotate Right with Extend (32 bit) - \details Moves each bit of a bitstring right by one bit. - The carry input is shifted in at the left end of the bitstring. - \param [in] value Value to rotate - \return Rotated value + \brief Get Base Priority + \details Returns the current value of the Base Priority register. + \return Base Priority register value */ -__STATIC_FORCEINLINE uint32_t __RRX(uint32_t value) +__STATIC_FORCEINLINE uint32_t __get_BASEPRI(void) { uint32_t result; - __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); + __ASM volatile ("MRS %0, basepri" : "=r" (result) ); return(result); } +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief LDRT Unprivileged (8 bit) - \details Executes a Unprivileged LDRT instruction for 8 bit value. - \param [in] ptr Pointer to data - \return value of type uint8_t at (*ptr) + \brief Get Base Priority (non-secure) + \details Returns the current value of the non-secure Base Priority register when in secure state. + \return Base Priority register value */ -__STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr) +__STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void) { uint32_t result; - __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) ); - return ((uint8_t) result); /* Add explicit type cast here */ + __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) ); + return(result); } +#endif /** - \brief LDRT Unprivileged (16 bit) - \details Executes a Unprivileged LDRT instruction for 16 bit values. - \param [in] ptr Pointer to data - \return value of type uint16_t at (*ptr) + \brief Set Base Priority + \details Assigns the given value to the Base Priority register. + \param [in] basePri Base Priority value to set */ -__STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr) +__STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri) { - uint32_t result; - - __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) ); - return ((uint16_t) result); /* Add explicit type cast here */ + __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory"); } +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief LDRT Unprivileged (32 bit) - \details Executes a Unprivileged LDRT instruction for 32 bit values. - \param [in] ptr Pointer to data - \return value of type uint32_t at (*ptr) + \brief Set Base Priority (non-secure) + \details Assigns the given value to the non-secure Base Priority register when in secure state. + \param [in] basePri Base Priority value to set */ -__STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr) +__STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri) { - uint32_t result; - - __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) ); - return(result); + __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory"); } +#endif /** - \brief STRT Unprivileged (8 bit) - \details Executes a Unprivileged STRT instruction for 8 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location + \brief Set Base Priority with condition + \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled, + or the new value increases the BASEPRI priority level. + \param [in] basePri Base Priority value to set */ -__STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr) +__STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri) { - __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); + __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory"); } /** - \brief STRT Unprivileged (16 bit) - \details Executes a Unprivileged STRT instruction for 16 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location + \brief Get Fault Mask + \details Returns the current value of the Fault Mask register. + \return Fault Mask register value */ -__STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr) +__STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void) { - __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); + uint32_t result; + + __ASM volatile ("MRS %0, faultmask" : "=r" (result) ); + return(result); } +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief STRT Unprivileged (32 bit) - \details Executes a Unprivileged STRT instruction for 32 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location + \brief Get Fault Mask (non-secure) + \details Returns the current value of the non-secure Fault Mask register when in secure state. + \return Fault Mask register value */ -__STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr) +__STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void) { - __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) ); + uint32_t result; + + __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) ); + return(result); } +#endif -#else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ - (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ - (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */ /** - \brief Signed Saturate - \details Saturates a signed value. - \param [in] value Value to be saturated - \param [in] sat Bit position to saturate to (1..32) - \return Saturated value + \brief Set Fault Mask + \details Assigns the given value to the Fault Mask register. + \param [in] faultMask Fault Mask value to set */ -__STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat) +__STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask) { - if ((sat >= 1U) && (sat <= 32U)) - { - const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); - const int32_t min = -1 - max ; - if (val > max) - { - return max; - } - else if (val < min) - { - return min; - } - } - return val; + __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory"); } + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Unsigned Saturate - \details Saturates an unsigned value. - \param [in] value Value to be saturated - \param [in] sat Bit position to saturate to (0..31) - \return Saturated value + \brief Set Fault Mask (non-secure) + \details Assigns the given value to the non-secure Fault Mask register when in secure state. + \param [in] faultMask Fault Mask value to set */ -__STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat) +__STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask) { - if (sat <= 31U) - { - const uint32_t max = ((1U << sat) - 1U); - if (val > (int32_t)max) - { - return max; - } - else if (val < 0) - { - return 0U; - } - } - return (uint32_t)val; + __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory"); } +#endif #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ @@ -1183,150 +1181,210 @@ __STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat) #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) + /** - \brief Load-Acquire (8 bit) - \details Executes a LDAB instruction for 8 bit value. - \param [in] ptr Pointer to data - \return value of type uint8_t at (*ptr) + \brief Get Process Stack Pointer Limit + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence zero is returned always in non-secure + mode. + + \details Returns the current value of the Process Stack Pointer Limit (PSPLIM). + \return PSPLIM Register value */ -__STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr) +__STATIC_FORCEINLINE uint32_t __get_PSPLIM(void) { +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + return 0U; +#else uint32_t result; - - __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) ); - return ((uint8_t) result); + __ASM volatile ("MRS %0, psplim" : "=r" (result) ); + return result; +#endif } - +#if (defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Load-Acquire (16 bit) - \details Executes a LDAH instruction for 16 bit values. - \param [in] ptr Pointer to data - \return value of type uint16_t at (*ptr) + \brief Get Process Stack Pointer Limit (non-secure) + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence zero is returned always in non-secure + mode. + + \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state. + \return PSPLIM Register value */ -__STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr) +__STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void) { +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + return 0U; +#else uint32_t result; - - __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) ); - return ((uint16_t) result); + __ASM volatile ("MRS %0, psplim_ns" : "=r" (result) ); + return result; +#endif } +#endif /** - \brief Load-Acquire (32 bit) - \details Executes a LDA instruction for 32 bit values. - \param [in] ptr Pointer to data - \return value of type uint32_t at (*ptr) + \brief Set Process Stack Pointer Limit + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence the write is silently ignored in non-secure + mode. + + \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM). + \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set */ -__STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr) +__STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit) { - uint32_t result; - - __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) ); - return(result); +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + (void)ProcStackPtrLimit; +#else + __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit)); +#endif } +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Store-Release (8 bit) - \details Executes a STLB instruction for 8 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location + \brief Set Process Stack Pointer (non-secure) + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence the write is silently ignored in non-secure + mode. + + \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state. + \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set */ -__STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr) +__STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit) { - __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + (void)ProcStackPtrLimit; +#else + __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit)); +#endif } +#endif /** - \brief Store-Release (16 bit) - \details Executes a STLH instruction for 16 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location + \brief Get Main Stack Pointer Limit + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence zero is returned always. + + \details Returns the current value of the Main Stack Pointer Limit (MSPLIM). + \return MSPLIM Register value */ -__STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr) +__STATIC_FORCEINLINE uint32_t __get_MSPLIM(void) { - __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + return 0U; +#else + uint32_t result; + __ASM volatile ("MRS %0, msplim" : "=r" (result) ); + return result; +#endif } +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Store-Release (32 bit) - \details Executes a STL instruction for 32 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location + \brief Get Main Stack Pointer Limit (non-secure) + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence zero is returned always. + + \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state. + \return MSPLIM Register value */ -__STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr) +__STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void) { - __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + return 0U; +#else + uint32_t result; + __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) ); + return result; +#endif } +#endif /** - \brief Load-Acquire Exclusive (8 bit) - \details Executes a LDAB exclusive instruction for 8 bit value. - \param [in] ptr Pointer to data - \return value of type uint8_t at (*ptr) - */ -#define __LDAEXB (uint8_t)__builtin_arm_ldaex - + \brief Set Main Stack Pointer Limit + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence the write is silently ignored. -/** - \brief Load-Acquire Exclusive (16 bit) - \details Executes a LDAH exclusive instruction for 16 bit values. - \param [in] ptr Pointer to data - \return value of type uint16_t at (*ptr) + \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM). + \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set */ -#define __LDAEXH (uint16_t)__builtin_arm_ldaex +__STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + (void)MainStackPtrLimit; +#else + __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit)); +#endif +} +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Load-Acquire Exclusive (32 bit) - \details Executes a LDA exclusive instruction for 32 bit values. - \param [in] ptr Pointer to data - \return value of type uint32_t at (*ptr) - */ -#define __LDAEX (uint32_t)__builtin_arm_ldaex - + \brief Set Main Stack Pointer Limit (non-secure) + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence the write is silently ignored. -/** - \brief Store-Release Exclusive (8 bit) - \details Executes a STLB exclusive instruction for 8 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed + \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state. + \param [in] MainStackPtrLimit Main Stack Pointer value to set */ -#define __STLEXB (uint32_t)__builtin_arm_stlex +__STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + (void)MainStackPtrLimit; +#else + __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit)); +#endif +} +#endif +#endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */ /** - \brief Store-Release Exclusive (16 bit) - \details Executes a STLH exclusive instruction for 16 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed + \brief Get FPSCR + \details Returns the current value of the Floating Point Status/Control register. + \return Floating Point Status/Control register value */ -#define __STLEXH (uint32_t)__builtin_arm_stlex - +#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ + (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) +#define __get_FPSCR (uint32_t)__builtin_arm_get_fpscr +#else +#define __get_FPSCR() ((uint32_t)0U) +#endif /** - \brief Store-Release Exclusive (32 bit) - \details Executes a STL exclusive instruction for 32 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed + \brief Set FPSCR + \details Assigns the given value to the Floating Point Status/Control register. + \param [in] fpscr Floating Point Status/Control value to set */ -#define __STLEX (uint32_t)__builtin_arm_stlex +#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ + (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) +#define __set_FPSCR __builtin_arm_set_fpscr +#else +#define __set_FPSCR(x) ((void)(x)) +#endif -#endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ - (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */ -/*@}*/ /* end of group CMSIS_Core_InstructionInterface */ +/*@} end of CMSIS_Core_RegAccFunctions */ /* ################### Compiler specific Intrinsics ########################### */ @@ -1851,6 +1909,10 @@ __STATIC_FORCEINLINE int32_t __QSUB( int32_t op1, int32_t op2) #define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \ ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) ) +#define __SXTB16_RORn(ARG1, ARG2) __SXTB16(__ROR(ARG1, ARG2)) + +#define __SXTAB16_RORn(ARG1, ARG2, ARG3) __SXTAB16(ARG1, __ROR(ARG2, ARG3)) + __STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3) { int32_t result; diff --git a/lib/cmsis/inc/cmsis_compiler.h b/lib/cmsis/inc/cmsis_compiler.h index fdb1a971c6a8c..adbf296f15a47 100644 --- a/lib/cmsis/inc/cmsis_compiler.h +++ b/lib/cmsis/inc/cmsis_compiler.h @@ -123,6 +123,10 @@ #ifndef __RESTRICT #define __RESTRICT __restrict #endif + #ifndef __COMPILER_BARRIER + #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. + #define __COMPILER_BARRIER() (void)0 + #endif /* @@ -192,6 +196,10 @@ #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. #define __RESTRICT #endif + #ifndef __COMPILER_BARRIER + #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. + #define __COMPILER_BARRIER() (void)0 + #endif /* @@ -260,6 +268,10 @@ #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. #define __RESTRICT #endif + #ifndef __COMPILER_BARRIER + #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. + #define __COMPILER_BARRIER() (void)0 + #endif #else diff --git a/lib/cmsis/inc/cmsis_gcc.h b/lib/cmsis/inc/cmsis_gcc.h index d86b0a2d5a6d3..67bda4ef3c38d 100644 --- a/lib/cmsis/inc/cmsis_gcc.h +++ b/lib/cmsis/inc/cmsis_gcc.h @@ -1,11 +1,11 @@ /**************************************************************************//** * @file cmsis_gcc.h * @brief CMSIS compiler GCC header file - * @version V5.1.0 - * @date 20. December 2018 + * @version V5.4.1 + * @date 27. May 2021 ******************************************************************************/ /* - * Copyright (c) 2009-2018 Arm Limited. All rights reserved. + * Copyright (c) 2009-2021 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -46,9 +46,9 @@ #ifndef __STATIC_INLINE #define __STATIC_INLINE static inline #endif -#ifndef __STATIC_FORCEINLINE +#ifndef __STATIC_FORCEINLINE #define __STATIC_FORCEINLINE __attribute__((always_inline)) static inline -#endif +#endif #ifndef __NO_RETURN #define __NO_RETURN __attribute__((__noreturn__)) #endif @@ -113,464 +113,638 @@ #ifndef __RESTRICT #define __RESTRICT __restrict #endif +#ifndef __COMPILER_BARRIER + #define __COMPILER_BARRIER() __ASM volatile("":::"memory") +#endif +/* ######################### Startup and Lowlevel Init ######################## */ -/* ########################### Core Function Access ########################### */ -/** \ingroup CMSIS_Core_FunctionInterface - \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions - @{ - */ +#ifndef __PROGRAM_START /** - \brief Enable IRQ Interrupts - \details Enables IRQ interrupts by clearing the I-bit in the CPSR. - Can only be executed in Privileged modes. + \brief Initializes data and bss sections + \details This default implementations initialized all data and additional bss + sections relying on .copy.table and .zero.table specified properly + in the used linker script. + */ -__STATIC_FORCEINLINE void __enable_irq(void) +__STATIC_FORCEINLINE __NO_RETURN void __cmsis_start(void) { - __ASM volatile ("cpsie i" : : : "memory"); -} + extern void _start(void) __NO_RETURN; + typedef struct { + uint32_t const* src; + uint32_t* dest; + uint32_t wlen; + } __copy_table_t; -/** - \brief Disable IRQ Interrupts - \details Disables IRQ interrupts by setting the I-bit in the CPSR. - Can only be executed in Privileged modes. - */ -__STATIC_FORCEINLINE void __disable_irq(void) -{ - __ASM volatile ("cpsid i" : : : "memory"); -} + typedef struct { + uint32_t* dest; + uint32_t wlen; + } __zero_table_t; + extern const __copy_table_t __copy_table_start__; + extern const __copy_table_t __copy_table_end__; + extern const __zero_table_t __zero_table_start__; + extern const __zero_table_t __zero_table_end__; -/** - \brief Get Control Register - \details Returns the content of the Control Register. - \return Control Register value - */ -__STATIC_FORCEINLINE uint32_t __get_CONTROL(void) -{ - uint32_t result; + for (__copy_table_t const* pTable = &__copy_table_start__; pTable < &__copy_table_end__; ++pTable) { + for(uint32_t i=0u; iwlen; ++i) { + pTable->dest[i] = pTable->src[i]; + } + } - __ASM volatile ("MRS %0, control" : "=r" (result) ); - return(result); + for (__zero_table_t const* pTable = &__zero_table_start__; pTable < &__zero_table_end__; ++pTable) { + for(uint32_t i=0u; iwlen; ++i) { + pTable->dest[i] = 0u; + } + } + + _start(); } +#define __PROGRAM_START __cmsis_start +#endif -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) -/** - \brief Get Control Register (non-secure) - \details Returns the content of the non-secure Control Register when in secure mode. - \return non-secure Control Register value - */ -__STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void) -{ - uint32_t result; +#ifndef __INITIAL_SP +#define __INITIAL_SP __StackTop +#endif - __ASM volatile ("MRS %0, control_ns" : "=r" (result) ); - return(result); -} +#ifndef __STACK_LIMIT +#define __STACK_LIMIT __StackLimit #endif +#ifndef __VECTOR_TABLE +#define __VECTOR_TABLE __Vectors +#endif -/** - \brief Set Control Register - \details Writes the given value to the Control Register. - \param [in] control Control Register value to set - */ -__STATIC_FORCEINLINE void __set_CONTROL(uint32_t control) -{ - __ASM volatile ("MSR control, %0" : : "r" (control) : "memory"); -} +#ifndef __VECTOR_TABLE_ATTRIBUTE +#define __VECTOR_TABLE_ATTRIBUTE __attribute__((used, section(".vectors"))) +#endif +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +#ifndef __STACK_SEAL +#define __STACK_SEAL __StackSeal +#endif -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) -/** - \brief Set Control Register (non-secure) - \details Writes the given value to the non-secure Control Register when in secure state. - \param [in] control Control Register value to set - */ -__STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control) -{ - __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory"); -} +#ifndef __TZ_STACK_SEAL_SIZE +#define __TZ_STACK_SEAL_SIZE 8U #endif +#ifndef __TZ_STACK_SEAL_VALUE +#define __TZ_STACK_SEAL_VALUE 0xFEF5EDA5FEF5EDA5ULL +#endif -/** - \brief Get IPSR Register - \details Returns the content of the IPSR Register. - \return IPSR Register value - */ -__STATIC_FORCEINLINE uint32_t __get_IPSR(void) -{ - uint32_t result; - __ASM volatile ("MRS %0, ipsr" : "=r" (result) ); - return(result); +__STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) { + *((uint64_t *)stackTop) = __TZ_STACK_SEAL_VALUE; } +#endif + + +/* ########################## Core Instruction Access ######################### */ +/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface + Access to dedicated instructions + @{ +*/ +/* Define macros for porting to both thumb1 and thumb2. + * For thumb1, use low register (r0-r7), specified by constraint "l" + * Otherwise, use general registers, specified by constraint "r" */ +#if defined (__thumb__) && !defined (__thumb2__) +#define __CMSIS_GCC_OUT_REG(r) "=l" (r) +#define __CMSIS_GCC_RW_REG(r) "+l" (r) +#define __CMSIS_GCC_USE_REG(r) "l" (r) +#else +#define __CMSIS_GCC_OUT_REG(r) "=r" (r) +#define __CMSIS_GCC_RW_REG(r) "+r" (r) +#define __CMSIS_GCC_USE_REG(r) "r" (r) +#endif /** - \brief Get APSR Register - \details Returns the content of the APSR Register. - \return APSR Register value + \brief No Operation + \details No Operation does nothing. This instruction can be used for code alignment purposes. */ -__STATIC_FORCEINLINE uint32_t __get_APSR(void) -{ - uint32_t result; +#define __NOP() __ASM volatile ("nop") - __ASM volatile ("MRS %0, apsr" : "=r" (result) ); - return(result); -} +/** + \brief Wait For Interrupt + \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs. + */ +#define __WFI() __ASM volatile ("wfi":::"memory") /** - \brief Get xPSR Register - \details Returns the content of the xPSR Register. - \return xPSR Register value + \brief Wait For Event + \details Wait For Event is a hint instruction that permits the processor to enter + a low-power state until one of a number of events occurs. */ -__STATIC_FORCEINLINE uint32_t __get_xPSR(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, xpsr" : "=r" (result) ); - return(result); -} +#define __WFE() __ASM volatile ("wfe":::"memory") /** - \brief Get Process Stack Pointer - \details Returns the current value of the Process Stack Pointer (PSP). - \return PSP Register value + \brief Send Event + \details Send Event is a hint instruction. It causes an event to be signaled to the CPU. */ -__STATIC_FORCEINLINE uint32_t __get_PSP(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, psp" : "=r" (result) ); - return(result); -} +#define __SEV() __ASM volatile ("sev") -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Get Process Stack Pointer (non-secure) - \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state. - \return PSP Register value + \brief Instruction Synchronization Barrier + \details Instruction Synchronization Barrier flushes the pipeline in the processor, + so that all instructions following the ISB are fetched from cache or memory, + after the instruction has been completed. */ -__STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void) +__STATIC_FORCEINLINE void __ISB(void) { - uint32_t result; - - __ASM volatile ("MRS %0, psp_ns" : "=r" (result) ); - return(result); + __ASM volatile ("isb 0xF":::"memory"); } -#endif /** - \brief Set Process Stack Pointer - \details Assigns the given value to the Process Stack Pointer (PSP). - \param [in] topOfProcStack Process Stack Pointer value to set + \brief Data Synchronization Barrier + \details Acts as a special kind of Data Memory Barrier. + It completes when all explicit memory accesses before this instruction complete. */ -__STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack) +__STATIC_FORCEINLINE void __DSB(void) { - __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : ); + __ASM volatile ("dsb 0xF":::"memory"); } -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Set Process Stack Pointer (non-secure) - \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state. - \param [in] topOfProcStack Process Stack Pointer value to set + \brief Data Memory Barrier + \details Ensures the apparent order of the explicit memory operations before + and after the instruction, without ensuring their completion. */ -__STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack) +__STATIC_FORCEINLINE void __DMB(void) { - __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : ); + __ASM volatile ("dmb 0xF":::"memory"); } -#endif /** - \brief Get Main Stack Pointer - \details Returns the current value of the Main Stack Pointer (MSP). - \return MSP Register value + \brief Reverse byte order (32 bit) + \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412. + \param [in] value Value to reverse + \return Reversed value */ -__STATIC_FORCEINLINE uint32_t __get_MSP(void) +__STATIC_FORCEINLINE uint32_t __REV(uint32_t value) { +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) + return __builtin_bswap32(value); +#else uint32_t result; - __ASM volatile ("MRS %0, msp" : "=r" (result) ); - return(result); + __ASM ("rev %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); + return result; +#endif } -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Get Main Stack Pointer (non-secure) - \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state. - \return MSP Register value + \brief Reverse byte order (16 bit) + \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856. + \param [in] value Value to reverse + \return Reversed value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void) +__STATIC_FORCEINLINE uint32_t __REV16(uint32_t value) { uint32_t result; - __ASM volatile ("MRS %0, msp_ns" : "=r" (result) ); - return(result); + __ASM ("rev16 %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); + return result; } -#endif /** - \brief Set Main Stack Pointer - \details Assigns the given value to the Main Stack Pointer (MSP). - \param [in] topOfMainStack Main Stack Pointer value to set + \brief Reverse byte order (16 bit) + \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000. + \param [in] value Value to reverse + \return Reversed value */ -__STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack) +__STATIC_FORCEINLINE int16_t __REVSH(int16_t value) { - __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : ); +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) + return (int16_t)__builtin_bswap16(value); +#else + int16_t result; + + __ASM ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); + return result; +#endif } -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Set Main Stack Pointer (non-secure) - \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state. - \param [in] topOfMainStack Main Stack Pointer value to set + \brief Rotate Right in unsigned value (32 bit) + \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits. + \param [in] op1 Value to rotate + \param [in] op2 Number of Bits to rotate + \return Rotated value */ -__STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack) +__STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2) { - __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : ); + op2 %= 32U; + if (op2 == 0U) + { + return op1; + } + return (op1 >> op2) | (op1 << (32U - op2)); } -#endif -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Get Stack Pointer (non-secure) - \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state. - \return SP Register value - */ -__STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, sp_ns" : "=r" (result) ); - return(result); -} - - -/** - \brief Set Stack Pointer (non-secure) - \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state. - \param [in] topOfStack Stack Pointer value to set + \brief Breakpoint + \details Causes the processor to enter Debug state. + Debug tools can use this to investigate system state when the instruction at a particular address is reached. + \param [in] value is ignored by the processor. + If required, a debugger can use it to store additional information about the breakpoint. */ -__STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack) -{ - __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : ); -} -#endif +#define __BKPT(value) __ASM volatile ("bkpt "#value) /** - \brief Get Priority Mask - \details Returns the current state of the priority mask bit from the Priority Mask Register. - \return Priority Mask value + \brief Reverse bit order of value + \details Reverses the bit order of the given value. + \param [in] value Value to reverse + \return Reversed value */ -__STATIC_FORCEINLINE uint32_t __get_PRIMASK(void) +__STATIC_FORCEINLINE uint32_t __RBIT(uint32_t value) { uint32_t result; - __ASM volatile ("MRS %0, primask" : "=r" (result) :: "memory"); - return(result); +#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) + __ASM ("rbit %0, %1" : "=r" (result) : "r" (value) ); +#else + uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */ + + result = value; /* r will be reversed bits of v; first get LSB of v */ + for (value >>= 1U; value != 0U; value >>= 1U) + { + result <<= 1U; + result |= value & 1U; + s--; + } + result <<= s; /* shift when v's highest bits are zero */ +#endif + return result; } -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Get Priority Mask (non-secure) - \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state. - \return Priority Mask value + \brief Count leading zeros + \details Counts the number of leading zeros of a data value. + \param [in] value Value to count the leading zeros + \return number of leading zeros in value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void) +__STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value) { - uint32_t result; - - __ASM volatile ("MRS %0, primask_ns" : "=r" (result) :: "memory"); - return(result); + /* Even though __builtin_clz produces a CLZ instruction on ARM, formally + __builtin_clz(0) is undefined behaviour, so handle this case specially. + This guarantees ARM-compatible results if happening to compile on a non-ARM + target, and ensures the compiler doesn't decide to activate any + optimisations using the logic "value was passed to __builtin_clz, so it + is non-zero". + ARM GCC 7.3 and possibly earlier will optimise this test away, leaving a + single CLZ instruction. + */ + if (value == 0U) + { + return 32U; + } + return __builtin_clz(value); } -#endif +#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) /** - \brief Set Priority Mask - \details Assigns the given value to the Priority Mask Register. - \param [in] priMask Priority Mask + \brief LDR Exclusive (8 bit) + \details Executes a exclusive LDR instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) */ -__STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask) +__STATIC_FORCEINLINE uint8_t __LDREXB(volatile uint8_t *addr) { - __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory"); + uint32_t result; + +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) + __ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) ); +#else + /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not + accepted by assembler. So has to use following less efficient pattern. + */ + __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" ); +#endif + return ((uint8_t) result); /* Add explicit type cast here */ } -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Set Priority Mask (non-secure) - \details Assigns the given value to the non-secure Priority Mask Register when in secure state. - \param [in] priMask Priority Mask + \brief LDR Exclusive (16 bit) + \details Executes a exclusive LDR instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) */ -__STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask) +__STATIC_FORCEINLINE uint16_t __LDREXH(volatile uint16_t *addr) { - __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory"); -} + uint32_t result; + +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) + __ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) ); +#else + /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not + accepted by assembler. So has to use following less efficient pattern. + */ + __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" ); #endif + return ((uint16_t) result); /* Add explicit type cast here */ +} -#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ - (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ - (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) /** - \brief Enable FIQ - \details Enables FIQ interrupts by clearing the F-bit in the CPSR. - Can only be executed in Privileged modes. + \brief LDR Exclusive (32 bit) + \details Executes a exclusive LDR instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) */ -__STATIC_FORCEINLINE void __enable_fault_irq(void) +__STATIC_FORCEINLINE uint32_t __LDREXW(volatile uint32_t *addr) { - __ASM volatile ("cpsie f" : : : "memory"); + uint32_t result; + + __ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) ); + return(result); } /** - \brief Disable FIQ - \details Disables FIQ interrupts by setting the F-bit in the CPSR. - Can only be executed in Privileged modes. + \brief STR Exclusive (8 bit) + \details Executes a exclusive STR instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed */ -__STATIC_FORCEINLINE void __disable_fault_irq(void) +__STATIC_FORCEINLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr) { - __ASM volatile ("cpsid f" : : : "memory"); + uint32_t result; + + __ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) ); + return(result); } /** - \brief Get Base Priority - \details Returns the current value of the Base Priority register. - \return Base Priority register value + \brief STR Exclusive (16 bit) + \details Executes a exclusive STR instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed */ -__STATIC_FORCEINLINE uint32_t __get_BASEPRI(void) +__STATIC_FORCEINLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr) { - uint32_t result; + uint32_t result; - __ASM volatile ("MRS %0, basepri" : "=r" (result) ); - return(result); + __ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) ); + return(result); } -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Get Base Priority (non-secure) - \details Returns the current value of the non-secure Base Priority register when in secure state. - \return Base Priority register value + \brief STR Exclusive (32 bit) + \details Executes a exclusive STR instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed */ -__STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void) +__STATIC_FORCEINLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr) { - uint32_t result; + uint32_t result; - __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) ); - return(result); + __ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) ); + return(result); } -#endif /** - \brief Set Base Priority - \details Assigns the given value to the Base Priority register. - \param [in] basePri Base Priority value to set + \brief Remove the exclusive lock + \details Removes the exclusive lock which is created by LDREX. */ -__STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri) +__STATIC_FORCEINLINE void __CLREX(void) { - __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory"); + __ASM volatile ("clrex" ::: "memory"); } +#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */ -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) + +#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) /** - \brief Set Base Priority (non-secure) - \details Assigns the given value to the non-secure Base Priority register when in secure state. - \param [in] basePri Base Priority value to set + \brief Signed Saturate + \details Saturates a signed value. + \param [in] ARG1 Value to be saturated + \param [in] ARG2 Bit position to saturate to (1..32) + \return Saturated value */ -__STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri) -{ - __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory"); -} -#endif +#define __SSAT(ARG1, ARG2) \ +__extension__ \ +({ \ + int32_t __RES, __ARG1 = (ARG1); \ + __ASM volatile ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \ + __RES; \ + }) /** - \brief Set Base Priority with condition - \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled, - or the new value increases the BASEPRI priority level. - \param [in] basePri Base Priority value to set + \brief Unsigned Saturate + \details Saturates an unsigned value. + \param [in] ARG1 Value to be saturated + \param [in] ARG2 Bit position to saturate to (0..31) + \return Saturated value */ -__STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri) -{ - __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory"); -} +#define __USAT(ARG1, ARG2) \ +__extension__ \ +({ \ + uint32_t __RES, __ARG1 = (ARG1); \ + __ASM volatile ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \ + __RES; \ + }) /** - \brief Get Fault Mask - \details Returns the current value of the Fault Mask register. - \return Fault Mask register value + \brief Rotate Right with Extend (32 bit) + \details Moves each bit of a bitstring right by one bit. + The carry input is shifted in at the left end of the bitstring. + \param [in] value Value to rotate + \return Rotated value */ -__STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void) +__STATIC_FORCEINLINE uint32_t __RRX(uint32_t value) { uint32_t result; - __ASM volatile ("MRS %0, faultmask" : "=r" (result) ); + __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); return(result); } -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Get Fault Mask (non-secure) - \details Returns the current value of the non-secure Fault Mask register when in secure state. - \return Fault Mask register value + \brief LDRT Unprivileged (8 bit) + \details Executes a Unprivileged LDRT instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) */ -__STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void) +__STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr) { - uint32_t result; + uint32_t result; - __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) ); - return(result); +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) + __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) ); +#else + /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not + accepted by assembler. So has to use following less efficient pattern. + */ + __ASM volatile ("ldrbt %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" ); +#endif + return ((uint8_t) result); /* Add explicit type cast here */ } + + +/** + \brief LDRT Unprivileged (16 bit) + \details Executes a Unprivileged LDRT instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) + */ +__STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr) +{ + uint32_t result; + +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) + __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) ); +#else + /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not + accepted by assembler. So has to use following less efficient pattern. + */ + __ASM volatile ("ldrht %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" ); #endif + return ((uint16_t) result); /* Add explicit type cast here */ +} /** - \brief Set Fault Mask - \details Assigns the given value to the Fault Mask register. - \param [in] faultMask Fault Mask value to set + \brief LDRT Unprivileged (32 bit) + \details Executes a Unprivileged LDRT instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) */ -__STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask) +__STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr) { - __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory"); + uint32_t result; + + __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) ); + return(result); } -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Set Fault Mask (non-secure) - \details Assigns the given value to the non-secure Fault Mask register when in secure state. - \param [in] faultMask Fault Mask value to set + \brief STRT Unprivileged (8 bit) + \details Executes a Unprivileged STRT instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask) +__STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr) { - __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory"); + __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +} + + +/** + \brief STRT Unprivileged (16 bit) + \details Executes a Unprivileged STRT instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +__STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr) +{ + __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +} + + +/** + \brief STRT Unprivileged (32 bit) + \details Executes a Unprivileged STRT instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +__STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr) +{ + __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) ); +} + +#else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */ + +/** + \brief Signed Saturate + \details Saturates a signed value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (1..32) + \return Saturated value + */ +__STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat) +{ + if ((sat >= 1U) && (sat <= 32U)) + { + const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); + const int32_t min = -1 - max ; + if (val > max) + { + return max; + } + else if (val < min) + { + return min; + } + } + return val; +} + +/** + \brief Unsigned Saturate + \details Saturates an unsigned value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (0..31) + \return Saturated value + */ +__STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat) +{ + if (sat <= 31U) + { + const uint32_t max = ((1U << sat) - 1U); + if (val > (int32_t)max) + { + return max; + } + else if (val < 0) + { + return 0U; + } + } + return (uint32_t)val; } -#endif #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ @@ -579,780 +753,646 @@ __STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask) #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) +/** + \brief Load-Acquire (8 bit) + \details Executes a LDAB instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) + */ +__STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr) +{ + uint32_t result; + + __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" ); + return ((uint8_t) result); +} + /** - \brief Get Process Stack Pointer Limit - Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure - Stack Pointer Limit register hence zero is returned always in non-secure - mode. - - \details Returns the current value of the Process Stack Pointer Limit (PSPLIM). - \return PSPLIM Register value + \brief Load-Acquire (16 bit) + \details Executes a LDAH instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) */ -__STATIC_FORCEINLINE uint32_t __get_PSPLIM(void) +__STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr) { -#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ - (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - return 0U; -#else - uint32_t result; - __ASM volatile ("MRS %0, psplim" : "=r" (result) ); - return result; -#endif + uint32_t result; + + __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" ); + return ((uint16_t) result); } -#if (defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)) + /** - \brief Get Process Stack Pointer Limit (non-secure) - Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure - Stack Pointer Limit register hence zero is returned always. + \brief Load-Acquire (32 bit) + \details Executes a LDA instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) + */ +__STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr) +{ + uint32_t result; - \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state. - \return PSPLIM Register value + __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" ); + return(result); +} + + +/** + \brief Store-Release (8 bit) + \details Executes a STLB instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void) +__STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr) { -#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - return 0U; -#else - uint32_t result; - __ASM volatile ("MRS %0, psplim_ns" : "=r" (result) ); - return result; -#endif + __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" ); } -#endif /** - \brief Set Process Stack Pointer Limit - Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure - Stack Pointer Limit register hence the write is silently ignored in non-secure - mode. - - \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM). - \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set + \brief Store-Release (16 bit) + \details Executes a STLH instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit) +__STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr) { -#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ - (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - (void)ProcStackPtrLimit; -#else - __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit)); -#endif + __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" ); } -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Set Process Stack Pointer (non-secure) - Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure - Stack Pointer Limit register hence the write is silently ignored. + \brief Store-Release (32 bit) + \details Executes a STL instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +__STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr) +{ + __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" ); +} - \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state. - \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set + +/** + \brief Load-Acquire Exclusive (8 bit) + \details Executes a LDAB exclusive instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) */ -__STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit) +__STATIC_FORCEINLINE uint8_t __LDAEXB(volatile uint8_t *ptr) { -#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - (void)ProcStackPtrLimit; -#else - __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit)); -#endif + uint32_t result; + + __ASM volatile ("ldaexb %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" ); + return ((uint8_t) result); } -#endif /** - \brief Get Main Stack Pointer Limit - Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure - Stack Pointer Limit register hence zero is returned always in non-secure - mode. + \brief Load-Acquire Exclusive (16 bit) + \details Executes a LDAH exclusive instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) + */ +__STATIC_FORCEINLINE uint16_t __LDAEXH(volatile uint16_t *ptr) +{ + uint32_t result; + + __ASM volatile ("ldaexh %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" ); + return ((uint16_t) result); +} - \details Returns the current value of the Main Stack Pointer Limit (MSPLIM). - \return MSPLIM Register value + +/** + \brief Load-Acquire Exclusive (32 bit) + \details Executes a LDA exclusive instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) */ -__STATIC_FORCEINLINE uint32_t __get_MSPLIM(void) +__STATIC_FORCEINLINE uint32_t __LDAEX(volatile uint32_t *ptr) { -#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ - (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - return 0U; -#else - uint32_t result; - __ASM volatile ("MRS %0, msplim" : "=r" (result) ); - return result; -#endif + uint32_t result; + + __ASM volatile ("ldaex %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" ); + return(result); } -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Get Main Stack Pointer Limit (non-secure) - Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure - Stack Pointer Limit register hence zero is returned always. - - \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state. - \return MSPLIM Register value + \brief Store-Release Exclusive (8 bit) + \details Executes a STLB exclusive instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed */ -__STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void) +__STATIC_FORCEINLINE uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr) { -#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - return 0U; -#else - uint32_t result; - __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) ); - return result; -#endif + uint32_t result; + + __ASM volatile ("stlexb %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" ); + return(result); } -#endif /** - \brief Set Main Stack Pointer Limit - Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure - Stack Pointer Limit register hence the write is silently ignored in non-secure - mode. - - \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM). - \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set + \brief Store-Release Exclusive (16 bit) + \details Executes a STLH exclusive instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed */ -__STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit) +__STATIC_FORCEINLINE uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr) { -#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ - (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - (void)MainStackPtrLimit; -#else - __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit)); -#endif + uint32_t result; + + __ASM volatile ("stlexh %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" ); + return(result); } -#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Set Main Stack Pointer Limit (non-secure) - Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure - Stack Pointer Limit register hence the write is silently ignored. - - \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state. - \param [in] MainStackPtrLimit Main Stack Pointer value to set + \brief Store-Release Exclusive (32 bit) + \details Executes a STL exclusive instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed */ -__STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit) +__STATIC_FORCEINLINE uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr) { -#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - (void)MainStackPtrLimit; -#else - __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit)); -#endif + uint32_t result; + + __ASM volatile ("stlex %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" ); + return(result); } -#endif #endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */ +/*@}*/ /* end of group CMSIS_Core_InstructionInterface */ + + +/* ########################### Core Function Access ########################### */ +/** \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions + @{ + */ /** - \brief Get FPSCR - \details Returns the current value of the Floating Point Status/Control register. - \return Floating Point Status/Control register value + \brief Enable IRQ Interrupts + \details Enables IRQ interrupts by clearing special-purpose register PRIMASK. + Can only be executed in Privileged modes. */ -__STATIC_FORCEINLINE uint32_t __get_FPSCR(void) +__STATIC_FORCEINLINE void __enable_irq(void) { -#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ - (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) -#if __has_builtin(__builtin_arm_get_fpscr) -// Re-enable using built-in when GCC has been fixed -// || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2) - /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */ - return __builtin_arm_get_fpscr(); -#else - uint32_t result; - - __ASM volatile ("VMRS %0, fpscr" : "=r" (result) ); - return(result); -#endif -#else - return(0U); -#endif + __ASM volatile ("cpsie i" : : : "memory"); } /** - \brief Set FPSCR - \details Assigns the given value to the Floating Point Status/Control register. - \param [in] fpscr Floating Point Status/Control value to set + \brief Disable IRQ Interrupts + \details Disables IRQ interrupts by setting special-purpose register PRIMASK. + Can only be executed in Privileged modes. */ -__STATIC_FORCEINLINE void __set_FPSCR(uint32_t fpscr) +__STATIC_FORCEINLINE void __disable_irq(void) { -#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ - (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) -#if __has_builtin(__builtin_arm_set_fpscr) -// Re-enable using built-in when GCC has been fixed -// || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2) - /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */ - __builtin_arm_set_fpscr(fpscr); -#else - __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc", "memory"); -#endif -#else - (void)fpscr; -#endif + __ASM volatile ("cpsid i" : : : "memory"); } -/*@} end of CMSIS_Core_RegAccFunctions */ - +/** + \brief Get Control Register + \details Returns the content of the Control Register. + \return Control Register value + */ +__STATIC_FORCEINLINE uint32_t __get_CONTROL(void) +{ + uint32_t result; -/* ########################## Core Instruction Access ######################### */ -/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface - Access to dedicated instructions - @{ -*/ + __ASM volatile ("MRS %0, control" : "=r" (result) ); + return(result); +} -/* Define macros for porting to both thumb1 and thumb2. - * For thumb1, use low register (r0-r7), specified by constraint "l" - * Otherwise, use general registers, specified by constraint "r" */ -#if defined (__thumb__) && !defined (__thumb2__) -#define __CMSIS_GCC_OUT_REG(r) "=l" (r) -#define __CMSIS_GCC_RW_REG(r) "+l" (r) -#define __CMSIS_GCC_USE_REG(r) "l" (r) -#else -#define __CMSIS_GCC_OUT_REG(r) "=r" (r) -#define __CMSIS_GCC_RW_REG(r) "+r" (r) -#define __CMSIS_GCC_USE_REG(r) "r" (r) -#endif +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief No Operation - \details No Operation does nothing. This instruction can be used for code alignment purposes. + \brief Get Control Register (non-secure) + \details Returns the content of the non-secure Control Register when in secure mode. + \return non-secure Control Register value */ -#define __NOP() __ASM volatile ("nop") +__STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void) +{ + uint32_t result; -/** - \brief Wait For Interrupt - \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs. - */ -#define __WFI() __ASM volatile ("wfi") + __ASM volatile ("MRS %0, control_ns" : "=r" (result) ); + return(result); +} +#endif /** - \brief Wait For Event - \details Wait For Event is a hint instruction that permits the processor to enter - a low-power state until one of a number of events occurs. + \brief Set Control Register + \details Writes the given value to the Control Register. + \param [in] control Control Register value to set */ -#define __WFE() __ASM volatile ("wfe") +__STATIC_FORCEINLINE void __set_CONTROL(uint32_t control) +{ + __ASM volatile ("MSR control, %0" : : "r" (control) : "memory"); + __ISB(); +} +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Send Event - \details Send Event is a hint instruction. It causes an event to be signaled to the CPU. + \brief Set Control Register (non-secure) + \details Writes the given value to the non-secure Control Register when in secure state. + \param [in] control Control Register value to set */ -#define __SEV() __ASM volatile ("sev") +__STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control) +{ + __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory"); + __ISB(); +} +#endif /** - \brief Instruction Synchronization Barrier - \details Instruction Synchronization Barrier flushes the pipeline in the processor, - so that all instructions following the ISB are fetched from cache or memory, - after the instruction has been completed. + \brief Get IPSR Register + \details Returns the content of the IPSR Register. + \return IPSR Register value */ -__STATIC_FORCEINLINE void __ISB(void) +__STATIC_FORCEINLINE uint32_t __get_IPSR(void) { - __ASM volatile ("isb 0xF":::"memory"); + uint32_t result; + + __ASM volatile ("MRS %0, ipsr" : "=r" (result) ); + return(result); } /** - \brief Data Synchronization Barrier - \details Acts as a special kind of Data Memory Barrier. - It completes when all explicit memory accesses before this instruction complete. + \brief Get APSR Register + \details Returns the content of the APSR Register. + \return APSR Register value */ -__STATIC_FORCEINLINE void __DSB(void) +__STATIC_FORCEINLINE uint32_t __get_APSR(void) { - __ASM volatile ("dsb 0xF":::"memory"); + uint32_t result; + + __ASM volatile ("MRS %0, apsr" : "=r" (result) ); + return(result); } /** - \brief Data Memory Barrier - \details Ensures the apparent order of the explicit memory operations before - and after the instruction, without ensuring their completion. + \brief Get xPSR Register + \details Returns the content of the xPSR Register. + \return xPSR Register value */ -__STATIC_FORCEINLINE void __DMB(void) +__STATIC_FORCEINLINE uint32_t __get_xPSR(void) { - __ASM volatile ("dmb 0xF":::"memory"); + uint32_t result; + + __ASM volatile ("MRS %0, xpsr" : "=r" (result) ); + return(result); } /** - \brief Reverse byte order (32 bit) - \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412. - \param [in] value Value to reverse - \return Reversed value + \brief Get Process Stack Pointer + \details Returns the current value of the Process Stack Pointer (PSP). + \return PSP Register value */ -__STATIC_FORCEINLINE uint32_t __REV(uint32_t value) +__STATIC_FORCEINLINE uint32_t __get_PSP(void) { -#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) - return __builtin_bswap32(value); -#else uint32_t result; - __ASM volatile ("rev %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); - return result; -#endif + __ASM volatile ("MRS %0, psp" : "=r" (result) ); + return(result); } +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Reverse byte order (16 bit) - \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856. - \param [in] value Value to reverse - \return Reversed value + \brief Get Process Stack Pointer (non-secure) + \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state. + \return PSP Register value */ -__STATIC_FORCEINLINE uint32_t __REV16(uint32_t value) +__STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void) { uint32_t result; - __ASM volatile ("rev16 %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); - return result; + __ASM volatile ("MRS %0, psp_ns" : "=r" (result) ); + return(result); } +#endif /** - \brief Reverse byte order (16 bit) - \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000. - \param [in] value Value to reverse - \return Reversed value + \brief Set Process Stack Pointer + \details Assigns the given value to the Process Stack Pointer (PSP). + \param [in] topOfProcStack Process Stack Pointer value to set */ -__STATIC_FORCEINLINE int16_t __REVSH(int16_t value) +__STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack) { -#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) - return (int16_t)__builtin_bswap16(value); -#else - int16_t result; - - __ASM volatile ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); - return result; -#endif + __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : ); } +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Rotate Right in unsigned value (32 bit) - \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits. - \param [in] op1 Value to rotate - \param [in] op2 Number of Bits to rotate - \return Rotated value + \brief Set Process Stack Pointer (non-secure) + \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state. + \param [in] topOfProcStack Process Stack Pointer value to set */ -__STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2) +__STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack) { - op2 %= 32U; - if (op2 == 0U) - { - return op1; - } - return (op1 >> op2) | (op1 << (32U - op2)); + __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : ); } +#endif /** - \brief Breakpoint - \details Causes the processor to enter Debug state. - Debug tools can use this to investigate system state when the instruction at a particular address is reached. - \param [in] value is ignored by the processor. - If required, a debugger can use it to store additional information about the breakpoint. + \brief Get Main Stack Pointer + \details Returns the current value of the Main Stack Pointer (MSP). + \return MSP Register value */ -#define __BKPT(value) __ASM volatile ("bkpt "#value) +__STATIC_FORCEINLINE uint32_t __get_MSP(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, msp" : "=r" (result) ); + return(result); +} +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Reverse bit order of value - \details Reverses the bit order of the given value. - \param [in] value Value to reverse - \return Reversed value + \brief Get Main Stack Pointer (non-secure) + \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state. + \return MSP Register value */ -__STATIC_FORCEINLINE uint32_t __RBIT(uint32_t value) +__STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void) { uint32_t result; -#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ - (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ - (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) - __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) ); -#else - uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */ - - result = value; /* r will be reversed bits of v; first get LSB of v */ - for (value >>= 1U; value != 0U; value >>= 1U) - { - result <<= 1U; - result |= value & 1U; - s--; - } - result <<= s; /* shift when v's highest bits are zero */ -#endif - return result; + __ASM volatile ("MRS %0, msp_ns" : "=r" (result) ); + return(result); } +#endif /** - \brief Count leading zeros - \details Counts the number of leading zeros of a data value. - \param [in] value Value to count the leading zeros - \return number of leading zeros in value + \brief Set Main Stack Pointer + \details Assigns the given value to the Main Stack Pointer (MSP). + \param [in] topOfMainStack Main Stack Pointer value to set */ -__STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value) +__STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack) { - /* Even though __builtin_clz produces a CLZ instruction on ARM, formally - __builtin_clz(0) is undefined behaviour, so handle this case specially. - This guarantees ARM-compatible results if happening to compile on a non-ARM - target, and ensures the compiler doesn't decide to activate any - optimisations using the logic "value was passed to __builtin_clz, so it - is non-zero". - ARM GCC 7.3 and possibly earlier will optimise this test away, leaving a - single CLZ instruction. - */ - if (value == 0U) - { - return 32U; - } - return __builtin_clz(value); + __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : ); } -#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ - (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ - (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ - (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief LDR Exclusive (8 bit) - \details Executes a exclusive LDR instruction for 8 bit value. - \param [in] ptr Pointer to data - \return value of type uint8_t at (*ptr) + \brief Set Main Stack Pointer (non-secure) + \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state. + \param [in] topOfMainStack Main Stack Pointer value to set */ -__STATIC_FORCEINLINE uint8_t __LDREXB(volatile uint8_t *addr) +__STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack) { - uint32_t result; - -#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) - __ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) ); -#else - /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not - accepted by assembler. So has to use following less efficient pattern. - */ - __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" ); -#endif - return ((uint8_t) result); /* Add explicit type cast here */ + __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : ); } +#endif +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief LDR Exclusive (16 bit) - \details Executes a exclusive LDR instruction for 16 bit values. - \param [in] ptr Pointer to data - \return value of type uint16_t at (*ptr) + \brief Get Stack Pointer (non-secure) + \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state. + \return SP Register value */ -__STATIC_FORCEINLINE uint16_t __LDREXH(volatile uint16_t *addr) +__STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void) { - uint32_t result; + uint32_t result; -#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) - __ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) ); -#else - /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not - accepted by assembler. So has to use following less efficient pattern. - */ - __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" ); -#endif - return ((uint16_t) result); /* Add explicit type cast here */ + __ASM volatile ("MRS %0, sp_ns" : "=r" (result) ); + return(result); } /** - \brief LDR Exclusive (32 bit) - \details Executes a exclusive LDR instruction for 32 bit values. - \param [in] ptr Pointer to data - \return value of type uint32_t at (*ptr) + \brief Set Stack Pointer (non-secure) + \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state. + \param [in] topOfStack Stack Pointer value to set */ -__STATIC_FORCEINLINE uint32_t __LDREXW(volatile uint32_t *addr) +__STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack) { - uint32_t result; - - __ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) ); - return(result); + __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : ); } +#endif /** - \brief STR Exclusive (8 bit) - \details Executes a exclusive STR instruction for 8 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed + \brief Get Priority Mask + \details Returns the current state of the priority mask bit from the Priority Mask Register. + \return Priority Mask value */ -__STATIC_FORCEINLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr) +__STATIC_FORCEINLINE uint32_t __get_PRIMASK(void) { - uint32_t result; + uint32_t result; - __ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) ); - return(result); + __ASM volatile ("MRS %0, primask" : "=r" (result) ); + return(result); } +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief STR Exclusive (16 bit) - \details Executes a exclusive STR instruction for 16 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed + \brief Get Priority Mask (non-secure) + \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state. + \return Priority Mask value */ -__STATIC_FORCEINLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr) +__STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void) { - uint32_t result; + uint32_t result; - __ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) ); - return(result); + __ASM volatile ("MRS %0, primask_ns" : "=r" (result) ); + return(result); } +#endif /** - \brief STR Exclusive (32 bit) - \details Executes a exclusive STR instruction for 32 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed + \brief Set Priority Mask + \details Assigns the given value to the Priority Mask Register. + \param [in] priMask Priority Mask */ -__STATIC_FORCEINLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr) -{ - uint32_t result; - - __ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) ); - return(result); +__STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask) +{ + __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory"); } +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Remove the exclusive lock - \details Removes the exclusive lock which is created by LDREX. + \brief Set Priority Mask (non-secure) + \details Assigns the given value to the non-secure Priority Mask Register when in secure state. + \param [in] priMask Priority Mask */ -__STATIC_FORCEINLINE void __CLREX(void) +__STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask) { - __ASM volatile ("clrex" ::: "memory"); + __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory"); } - -#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ - (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ - (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ - (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */ +#endif #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) /** - \brief Signed Saturate - \details Saturates a signed value. - \param [in] ARG1 Value to be saturated - \param [in] ARG2 Bit position to saturate to (1..32) - \return Saturated value + \brief Enable FIQ + \details Enables FIQ interrupts by clearing special-purpose register FAULTMASK. + Can only be executed in Privileged modes. */ -#define __SSAT(ARG1,ARG2) \ -__extension__ \ -({ \ - int32_t __RES, __ARG1 = (ARG1); \ - __ASM ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ - __RES; \ - }) +__STATIC_FORCEINLINE void __enable_fault_irq(void) +{ + __ASM volatile ("cpsie f" : : : "memory"); +} /** - \brief Unsigned Saturate - \details Saturates an unsigned value. - \param [in] ARG1 Value to be saturated - \param [in] ARG2 Bit position to saturate to (0..31) - \return Saturated value + \brief Disable FIQ + \details Disables FIQ interrupts by setting special-purpose register FAULTMASK. + Can only be executed in Privileged modes. */ -#define __USAT(ARG1,ARG2) \ - __extension__ \ -({ \ - uint32_t __RES, __ARG1 = (ARG1); \ - __ASM ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ - __RES; \ - }) +__STATIC_FORCEINLINE void __disable_fault_irq(void) +{ + __ASM volatile ("cpsid f" : : : "memory"); +} /** - \brief Rotate Right with Extend (32 bit) - \details Moves each bit of a bitstring right by one bit. - The carry input is shifted in at the left end of the bitstring. - \param [in] value Value to rotate - \return Rotated value + \brief Get Base Priority + \details Returns the current value of the Base Priority register. + \return Base Priority register value */ -__STATIC_FORCEINLINE uint32_t __RRX(uint32_t value) +__STATIC_FORCEINLINE uint32_t __get_BASEPRI(void) { uint32_t result; - __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); + __ASM volatile ("MRS %0, basepri" : "=r" (result) ); return(result); } +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief LDRT Unprivileged (8 bit) - \details Executes a Unprivileged LDRT instruction for 8 bit value. - \param [in] ptr Pointer to data - \return value of type uint8_t at (*ptr) + \brief Get Base Priority (non-secure) + \details Returns the current value of the non-secure Base Priority register when in secure state. + \return Base Priority register value */ -__STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr) +__STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void) { - uint32_t result; + uint32_t result; -#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) - __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) ); -#else - /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not - accepted by assembler. So has to use following less efficient pattern. - */ - __ASM volatile ("ldrbt %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" ); -#endif - return ((uint8_t) result); /* Add explicit type cast here */ + __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) ); + return(result); } +#endif /** - \brief LDRT Unprivileged (16 bit) - \details Executes a Unprivileged LDRT instruction for 16 bit values. - \param [in] ptr Pointer to data - \return value of type uint16_t at (*ptr) + \brief Set Base Priority + \details Assigns the given value to the Base Priority register. + \param [in] basePri Base Priority value to set */ -__STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr) +__STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri) { - uint32_t result; - -#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) - __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) ); -#else - /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not - accepted by assembler. So has to use following less efficient pattern. - */ - __ASM volatile ("ldrht %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" ); -#endif - return ((uint16_t) result); /* Add explicit type cast here */ + __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory"); } +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief LDRT Unprivileged (32 bit) - \details Executes a Unprivileged LDRT instruction for 32 bit values. - \param [in] ptr Pointer to data - \return value of type uint32_t at (*ptr) + \brief Set Base Priority (non-secure) + \details Assigns the given value to the non-secure Base Priority register when in secure state. + \param [in] basePri Base Priority value to set */ -__STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr) +__STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri) { - uint32_t result; - - __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) ); - return(result); + __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory"); } +#endif /** - \brief STRT Unprivileged (8 bit) - \details Executes a Unprivileged STRT instruction for 8 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location + \brief Set Base Priority with condition + \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled, + or the new value increases the BASEPRI priority level. + \param [in] basePri Base Priority value to set */ -__STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr) +__STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri) { - __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); + __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory"); } /** - \brief STRT Unprivileged (16 bit) - \details Executes a Unprivileged STRT instruction for 16 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location + \brief Get Fault Mask + \details Returns the current value of the Fault Mask register. + \return Fault Mask register value */ -__STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr) +__STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void) { - __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); + uint32_t result; + + __ASM volatile ("MRS %0, faultmask" : "=r" (result) ); + return(result); } +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief STRT Unprivileged (32 bit) - \details Executes a Unprivileged STRT instruction for 32 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location + \brief Get Fault Mask (non-secure) + \details Returns the current value of the non-secure Fault Mask register when in secure state. + \return Fault Mask register value */ -__STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr) +__STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void) { - __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) ); + uint32_t result; + + __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) ); + return(result); } +#endif -#else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ - (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ - (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */ /** - \brief Signed Saturate - \details Saturates a signed value. - \param [in] value Value to be saturated - \param [in] sat Bit position to saturate to (1..32) - \return Saturated value + \brief Set Fault Mask + \details Assigns the given value to the Fault Mask register. + \param [in] faultMask Fault Mask value to set */ -__STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat) +__STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask) { - if ((sat >= 1U) && (sat <= 32U)) - { - const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); - const int32_t min = -1 - max ; - if (val > max) - { - return max; - } - else if (val < min) - { - return min; - } - } - return val; + __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory"); } + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Unsigned Saturate - \details Saturates an unsigned value. - \param [in] value Value to be saturated - \param [in] sat Bit position to saturate to (0..31) - \return Saturated value + \brief Set Fault Mask (non-secure) + \details Assigns the given value to the non-secure Fault Mask register when in secure state. + \param [in] faultMask Fault Mask value to set */ -__STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat) +__STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask) { - if (sat <= 31U) - { - const uint32_t max = ((1U << sat) - 1U); - if (val > (int32_t)max) - { - return max; - } - else if (val < 0) - { - return 0U; - } - } - return (uint32_t)val; + __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory"); } +#endif #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ @@ -1361,186 +1401,235 @@ __STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat) #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) -/** - \brief Load-Acquire (8 bit) - \details Executes a LDAB instruction for 8 bit value. - \param [in] ptr Pointer to data - \return value of type uint8_t at (*ptr) - */ -__STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr) -{ - uint32_t result; - - __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) ); - return ((uint8_t) result); -} - /** - \brief Load-Acquire (16 bit) - \details Executes a LDAH instruction for 16 bit values. - \param [in] ptr Pointer to data - \return value of type uint16_t at (*ptr) - */ -__STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr) -{ - uint32_t result; - - __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) ); - return ((uint16_t) result); -} - + \brief Get Process Stack Pointer Limit + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence zero is returned always in non-secure + mode. -/** - \brief Load-Acquire (32 bit) - \details Executes a LDA instruction for 32 bit values. - \param [in] ptr Pointer to data - \return value of type uint32_t at (*ptr) + \details Returns the current value of the Process Stack Pointer Limit (PSPLIM). + \return PSPLIM Register value */ -__STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr) +__STATIC_FORCEINLINE uint32_t __get_PSPLIM(void) { - uint32_t result; - - __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) ); - return(result); +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + return 0U; +#else + uint32_t result; + __ASM volatile ("MRS %0, psplim" : "=r" (result) ); + return result; +#endif } - +#if (defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Store-Release (8 bit) - \details Executes a STLB instruction for 8 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location + \brief Get Process Stack Pointer Limit (non-secure) + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence zero is returned always. + + \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state. + \return PSPLIM Register value */ -__STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr) +__STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void) { - __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + return 0U; +#else + uint32_t result; + __ASM volatile ("MRS %0, psplim_ns" : "=r" (result) ); + return result; +#endif } +#endif /** - \brief Store-Release (16 bit) - \details Executes a STLH instruction for 16 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location + \brief Set Process Stack Pointer Limit + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence the write is silently ignored in non-secure + mode. + + \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM). + \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set */ -__STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr) +__STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit) { - __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + (void)ProcStackPtrLimit; +#else + __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit)); +#endif } +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Store-Release (32 bit) - \details Executes a STL instruction for 32 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location + \brief Set Process Stack Pointer (non-secure) + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence the write is silently ignored. + + \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state. + \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set */ -__STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr) +__STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit) { - __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + (void)ProcStackPtrLimit; +#else + __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit)); +#endif } +#endif /** - \brief Load-Acquire Exclusive (8 bit) - \details Executes a LDAB exclusive instruction for 8 bit value. - \param [in] ptr Pointer to data - \return value of type uint8_t at (*ptr) + \brief Get Main Stack Pointer Limit + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence zero is returned always in non-secure + mode. + + \details Returns the current value of the Main Stack Pointer Limit (MSPLIM). + \return MSPLIM Register value */ -__STATIC_FORCEINLINE uint8_t __LDAEXB(volatile uint8_t *ptr) +__STATIC_FORCEINLINE uint32_t __get_MSPLIM(void) { - uint32_t result; - - __ASM volatile ("ldaexb %0, %1" : "=r" (result) : "Q" (*ptr) ); - return ((uint8_t) result); +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + return 0U; +#else + uint32_t result; + __ASM volatile ("MRS %0, msplim" : "=r" (result) ); + return result; +#endif } +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Load-Acquire Exclusive (16 bit) - \details Executes a LDAH exclusive instruction for 16 bit values. - \param [in] ptr Pointer to data - \return value of type uint16_t at (*ptr) + \brief Get Main Stack Pointer Limit (non-secure) + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence zero is returned always. + + \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state. + \return MSPLIM Register value */ -__STATIC_FORCEINLINE uint16_t __LDAEXH(volatile uint16_t *ptr) +__STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void) { - uint32_t result; - - __ASM volatile ("ldaexh %0, %1" : "=r" (result) : "Q" (*ptr) ); - return ((uint16_t) result); +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + return 0U; +#else + uint32_t result; + __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) ); + return result; +#endif } +#endif /** - \brief Load-Acquire Exclusive (32 bit) - \details Executes a LDA exclusive instruction for 32 bit values. - \param [in] ptr Pointer to data - \return value of type uint32_t at (*ptr) + \brief Set Main Stack Pointer Limit + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence the write is silently ignored in non-secure + mode. + + \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM). + \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set */ -__STATIC_FORCEINLINE uint32_t __LDAEX(volatile uint32_t *ptr) +__STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit) { - uint32_t result; - - __ASM volatile ("ldaex %0, %1" : "=r" (result) : "Q" (*ptr) ); - return(result); +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + (void)MainStackPtrLimit; +#else + __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit)); +#endif } +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) /** - \brief Store-Release Exclusive (8 bit) - \details Executes a STLB exclusive instruction for 8 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed + \brief Set Main Stack Pointer Limit (non-secure) + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence the write is silently ignored. + + \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state. + \param [in] MainStackPtrLimit Main Stack Pointer value to set */ -__STATIC_FORCEINLINE uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr) +__STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit) { - uint32_t result; - - __ASM volatile ("stlexb %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) ); - return(result); +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + (void)MainStackPtrLimit; +#else + __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit)); +#endif } +#endif + +#endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */ /** - \brief Store-Release Exclusive (16 bit) - \details Executes a STLH exclusive instruction for 16 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed + \brief Get FPSCR + \details Returns the current value of the Floating Point Status/Control register. + \return Floating Point Status/Control register value */ -__STATIC_FORCEINLINE uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr) +__STATIC_FORCEINLINE uint32_t __get_FPSCR(void) { - uint32_t result; +#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ + (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) +#if __has_builtin(__builtin_arm_get_fpscr) +// Re-enable using built-in when GCC has been fixed +// || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2) + /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */ + return __builtin_arm_get_fpscr(); +#else + uint32_t result; - __ASM volatile ("stlexh %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) ); - return(result); + __ASM volatile ("VMRS %0, fpscr" : "=r" (result) ); + return(result); +#endif +#else + return(0U); +#endif } /** - \brief Store-Release Exclusive (32 bit) - \details Executes a STL exclusive instruction for 32 bit values. - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed + \brief Set FPSCR + \details Assigns the given value to the Floating Point Status/Control register. + \param [in] fpscr Floating Point Status/Control value to set */ -__STATIC_FORCEINLINE uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr) +__STATIC_FORCEINLINE void __set_FPSCR(uint32_t fpscr) { - uint32_t result; - - __ASM volatile ("stlex %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) ); - return(result); +#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ + (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) +#if __has_builtin(__builtin_arm_set_fpscr) +// Re-enable using built-in when GCC has been fixed +// || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2) + /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */ + __builtin_arm_set_fpscr(fpscr); +#else + __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc", "memory"); +#endif +#else + (void)fpscr; +#endif } -#endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ - (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */ -/*@}*/ /* end of group CMSIS_Core_InstructionInterface */ +/*@} end of CMSIS_Core_RegAccFunctions */ /* ################### Compiler specific Intrinsics ########################### */ @@ -1563,7 +1652,7 @@ __STATIC_FORCEINLINE uint32_t __QADD8(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1571,7 +1660,7 @@ __STATIC_FORCEINLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("shadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("shadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1587,7 +1676,7 @@ __STATIC_FORCEINLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("uqadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("uqadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1595,7 +1684,7 @@ __STATIC_FORCEINLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("uhadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("uhadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1612,7 +1701,7 @@ __STATIC_FORCEINLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1620,7 +1709,7 @@ __STATIC_FORCEINLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("shsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("shsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1636,7 +1725,7 @@ __STATIC_FORCEINLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("uqsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("uqsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1644,7 +1733,7 @@ __STATIC_FORCEINLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("uhsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("uhsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1661,7 +1750,7 @@ __STATIC_FORCEINLINE uint32_t __QADD16(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1669,7 +1758,7 @@ __STATIC_FORCEINLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1685,7 +1774,7 @@ __STATIC_FORCEINLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("uqadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("uqadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1693,7 +1782,7 @@ __STATIC_FORCEINLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("uhadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("uhadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1709,7 +1798,7 @@ __STATIC_FORCEINLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1717,7 +1806,7 @@ __STATIC_FORCEINLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1733,7 +1822,7 @@ __STATIC_FORCEINLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("uqsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("uqsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1741,7 +1830,7 @@ __STATIC_FORCEINLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("uhsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("uhsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1757,7 +1846,7 @@ __STATIC_FORCEINLINE uint32_t __QASX(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1765,7 +1854,7 @@ __STATIC_FORCEINLINE uint32_t __SHASX(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1781,7 +1870,7 @@ __STATIC_FORCEINLINE uint32_t __UQASX(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("uqasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("uqasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1789,7 +1878,7 @@ __STATIC_FORCEINLINE uint32_t __UHASX(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("uhasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("uhasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1805,7 +1894,7 @@ __STATIC_FORCEINLINE uint32_t __QSAX(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1813,7 +1902,7 @@ __STATIC_FORCEINLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1829,7 +1918,7 @@ __STATIC_FORCEINLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("uqsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("uqsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1837,7 +1926,7 @@ __STATIC_FORCEINLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("uhsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("uhsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1845,7 +1934,7 @@ __STATIC_FORCEINLINE uint32_t __USAD8(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("usad8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("usad8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1853,21 +1942,23 @@ __STATIC_FORCEINLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3) { uint32_t result; - __ASM volatile ("usada8 %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); + __ASM ("usada8 %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); return(result); } -#define __SSAT16(ARG1,ARG2) \ +#define __SSAT16(ARG1, ARG2) \ +__extension__ \ ({ \ int32_t __RES, __ARG1 = (ARG1); \ - __ASM ("ssat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ + __ASM volatile ("ssat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \ __RES; \ }) -#define __USAT16(ARG1,ARG2) \ +#define __USAT16(ARG1, ARG2) \ +__extension__ \ ({ \ uint32_t __RES, __ARG1 = (ARG1); \ - __ASM ("usat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ + __ASM volatile ("usat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \ __RES; \ }) @@ -1875,7 +1966,7 @@ __STATIC_FORCEINLINE uint32_t __UXTB16(uint32_t op1) { uint32_t result; - __ASM volatile ("uxtb16 %0, %1" : "=r" (result) : "r" (op1)); + __ASM ("uxtb16 %0, %1" : "=r" (result) : "r" (op1)); return(result); } @@ -1883,7 +1974,7 @@ __STATIC_FORCEINLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("uxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("uxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } @@ -1891,18 +1982,41 @@ __STATIC_FORCEINLINE uint32_t __SXTB16(uint32_t op1) { uint32_t result; - __ASM volatile ("sxtb16 %0, %1" : "=r" (result) : "r" (op1)); + __ASM ("sxtb16 %0, %1" : "=r" (result) : "r" (op1)); return(result); } +__STATIC_FORCEINLINE uint32_t __SXTB16_RORn(uint32_t op1, uint32_t rotate) +{ + uint32_t result; + if (__builtin_constant_p(rotate) && ((rotate == 8U) || (rotate == 16U) || (rotate == 24U))) { + __ASM volatile ("sxtb16 %0, %1, ROR %2" : "=r" (result) : "r" (op1), "i" (rotate) ); + } else { + result = __SXTB16(__ROR(op1, rotate)) ; + } + return result; +} + __STATIC_FORCEINLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2) { uint32_t result; - __ASM volatile ("sxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + __ASM ("sxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); return(result); } +__STATIC_FORCEINLINE uint32_t __SXTAB16_RORn(uint32_t op1, uint32_t op2, uint32_t rotate) +{ + uint32_t result; + if (__builtin_constant_p(rotate) && ((rotate == 8U) || (rotate == 16U) || (rotate == 24U))) { + __ASM volatile ("sxtab16 %0, %1, %2, ROR %3" : "=r" (result) : "r" (op1) , "r" (op2) , "i" (rotate)); + } else { + result = __SXTAB16(op1, __ROR(op2, rotate)); + } + return result; +} + + __STATIC_FORCEINLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2) { uint32_t result; @@ -2059,8 +2173,9 @@ __STATIC_FORCEINLINE int32_t __QSUB( int32_t op1, int32_t op2) return(result); } -#if 0 + #define __PKHBT(ARG1,ARG2,ARG3) \ +__extension__ \ ({ \ uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \ __ASM ("pkhbt %0, %1, %2, lsl %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \ @@ -2068,6 +2183,7 @@ __STATIC_FORCEINLINE int32_t __QSUB( int32_t op1, int32_t op2) }) #define __PKHTB(ARG1,ARG2,ARG3) \ +__extension__ \ ({ \ uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \ if (ARG3 == 0) \ @@ -2076,19 +2192,13 @@ __STATIC_FORCEINLINE int32_t __QSUB( int32_t op1, int32_t op2) __ASM ("pkhtb %0, %1, %2, asr %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \ __RES; \ }) -#endif - -#define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \ - ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) ) -#define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \ - ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) ) __STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3) { int32_t result; - __ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) ); + __ASM ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) ); return(result); } diff --git a/lib/cmsis/inc/cmsis_iccarm.h b/lib/cmsis/inc/cmsis_iccarm.h index 20b50ce380d6c..65b824b009caa 100644 --- a/lib/cmsis/inc/cmsis_iccarm.h +++ b/lib/cmsis/inc/cmsis_iccarm.h @@ -1,13 +1,16 @@ /**************************************************************************//** * @file cmsis_iccarm.h * @brief CMSIS compiler ICCARM (IAR Compiler for Arm) header file - * @version V5.0.8 - * @date 04. September 2018 + * @version V5.3.0 + * @date 14. April 2021 ******************************************************************************/ //------------------------------------------------------------------------------ // -// Copyright (c) 2017-2018 IAR Systems +// Copyright (c) 2017-2021 IAR Systems +// Copyright (c) 2017-2021 Arm Limited. All rights reserved. +// +// SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License") // you may not use this file except in compliance with the License. @@ -110,6 +113,10 @@ #define __ASM __asm #endif +#ifndef __COMPILER_BARRIER + #define __COMPILER_BARRIER() __ASM volatile("":::"memory") +#endif + #ifndef __INLINE #define __INLINE inline #endif @@ -231,6 +238,7 @@ __packed struct __iar_u32 { uint32_t v; }; #endif #endif +#undef __WEAK /* undo the definition from DLib_Defaults.h */ #ifndef __WEAK #if __ICCARM_V8 #define __WEAK __attribute__((weak)) @@ -239,6 +247,43 @@ __packed struct __iar_u32 { uint32_t v; }; #endif #endif +#ifndef __PROGRAM_START +#define __PROGRAM_START __iar_program_start +#endif + +#ifndef __INITIAL_SP +#define __INITIAL_SP CSTACK$$Limit +#endif + +#ifndef __STACK_LIMIT +#define __STACK_LIMIT CSTACK$$Base +#endif + +#ifndef __VECTOR_TABLE +#define __VECTOR_TABLE __vector_table +#endif + +#ifndef __VECTOR_TABLE_ATTRIBUTE +#define __VECTOR_TABLE_ATTRIBUTE @".intvec" +#endif + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +#ifndef __STACK_SEAL +#define __STACK_SEAL STACKSEAL$$Base +#endif + +#ifndef __TZ_STACK_SEAL_SIZE +#define __TZ_STACK_SEAL_SIZE 8U +#endif + +#ifndef __TZ_STACK_SEAL_VALUE +#define __TZ_STACK_SEAL_VALUE 0xFEF5EDA5FEF5EDA5ULL +#endif + +__STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) { + *((uint64_t *)stackTop) = __TZ_STACK_SEAL_VALUE; +} +#endif #ifndef __ICCARM_INTRINSICS_VERSION__ #define __ICCARM_INTRINSICS_VERSION__ 0 @@ -310,7 +355,13 @@ __packed struct __iar_u32 { uint32_t v; }; #define __set_BASEPRI(VALUE) (__arm_wsr("BASEPRI", (VALUE))) #define __set_BASEPRI_MAX(VALUE) (__arm_wsr("BASEPRI_MAX", (VALUE))) - #define __set_CONTROL(VALUE) (__arm_wsr("CONTROL", (VALUE))) + +__STATIC_FORCEINLINE void __set_CONTROL(uint32_t control) +{ + __arm_wsr("CONTROL", control); + __iar_builtin_ISB(); +} + #define __set_FAULTMASK(VALUE) (__arm_wsr("FAULTMASK", (VALUE))) #define __set_MSP(VALUE) (__arm_wsr("MSP", (VALUE))) @@ -332,7 +383,13 @@ __packed struct __iar_u32 { uint32_t v; }; #endif #define __TZ_get_CONTROL_NS() (__arm_rsr("CONTROL_NS")) - #define __TZ_set_CONTROL_NS(VALUE) (__arm_wsr("CONTROL_NS", (VALUE))) + +__STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control) +{ + __arm_wsr("CONTROL_NS", control); + __iar_builtin_ISB(); +} + #define __TZ_get_PSP_NS() (__arm_rsr("PSP_NS")) #define __TZ_set_PSP_NS(VALUE) (__arm_wsr("PSP_NS", (VALUE))) #define __TZ_get_MSP_NS() (__arm_rsr("MSP_NS")) @@ -572,7 +629,7 @@ __packed struct __iar_u32 { uint32_t v; }; __IAR_FT uint32_t __RRX(uint32_t value) { uint32_t result; - __ASM("RRX %0, %1" : "=r"(result) : "r" (value) : "cc"); + __ASM volatile("RRX %0, %1" : "=r"(result) : "r" (value)); return(result); } @@ -654,6 +711,7 @@ __packed struct __iar_u32 { uint32_t v; }; __IAR_FT void __TZ_set_CONTROL_NS(uint32_t value) { __asm volatile("MSR CONTROL_NS,%0" :: "r" (value)); + __iar_builtin_ISB(); } __IAR_FT uint32_t __TZ_get_PSP_NS(void) @@ -811,37 +869,37 @@ __packed struct __iar_u32 { uint32_t v; }; __IAR_FT uint8_t __LDRBT(volatile uint8_t *addr) { uint32_t res; - __ASM("LDRBT %0, [%1]" : "=r" (res) : "r" (addr) : "memory"); + __ASM volatile ("LDRBT %0, [%1]" : "=r" (res) : "r" (addr) : "memory"); return ((uint8_t)res); } __IAR_FT uint16_t __LDRHT(volatile uint16_t *addr) { uint32_t res; - __ASM("LDRHT %0, [%1]" : "=r" (res) : "r" (addr) : "memory"); + __ASM volatile ("LDRHT %0, [%1]" : "=r" (res) : "r" (addr) : "memory"); return ((uint16_t)res); } __IAR_FT uint32_t __LDRT(volatile uint32_t *addr) { uint32_t res; - __ASM("LDRT %0, [%1]" : "=r" (res) : "r" (addr) : "memory"); + __ASM volatile ("LDRT %0, [%1]" : "=r" (res) : "r" (addr) : "memory"); return res; } __IAR_FT void __STRBT(uint8_t value, volatile uint8_t *addr) { - __ASM("STRBT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory"); + __ASM volatile ("STRBT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory"); } __IAR_FT void __STRHT(uint16_t value, volatile uint16_t *addr) { - __ASM("STRHT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory"); + __ASM volatile ("STRHT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory"); } __IAR_FT void __STRT(uint32_t value, volatile uint32_t *addr) { - __ASM("STRT %1, [%0]" : : "r" (addr), "r" (value) : "memory"); + __ASM volatile ("STRT %1, [%0]" : : "r" (addr), "r" (value) : "memory"); } #endif /* (__CORTEX_M >= 0x03) */ @@ -937,4 +995,8 @@ __packed struct __iar_u32 { uint32_t v; }; #pragma diag_default=Pe940 #pragma diag_default=Pe177 +#define __SXTB16_RORn(ARG1, ARG2) __SXTB16(__ROR(ARG1, ARG2)) + +#define __SXTAB16_RORn(ARG1, ARG2, ARG3) __SXTAB16(ARG1, __ROR(ARG2, ARG3)) + #endif /* __CMSIS_ICCARM_H__ */ diff --git a/lib/cmsis/inc/cmsis_version.h b/lib/cmsis/inc/cmsis_version.h index 660f612aa31fe..8b4765f186efe 100644 --- a/lib/cmsis/inc/cmsis_version.h +++ b/lib/cmsis/inc/cmsis_version.h @@ -1,11 +1,11 @@ /**************************************************************************//** * @file cmsis_version.h * @brief CMSIS Core(M) Version definitions - * @version V5.0.2 - * @date 19. April 2017 + * @version V5.0.5 + * @date 02. February 2022 ******************************************************************************/ /* - * Copyright (c) 2009-2017 ARM Limited. All rights reserved. + * Copyright (c) 2009-2022 ARM Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -33,7 +33,7 @@ /* CMSIS Version definitions */ #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ -#define __CM_CMSIS_VERSION_SUB ( 1U) /*!< [15:0] CMSIS Core(M) sub version */ +#define __CM_CMSIS_VERSION_SUB ( 6U) /*!< [15:0] CMSIS Core(M) sub version */ #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ #endif diff --git a/lib/cmsis/inc/core_armv81mml.h b/lib/cmsis/inc/core_armv81mml.h index db6d9f23638b6..94128a1a7095c 100644 --- a/lib/cmsis/inc/core_armv81mml.h +++ b/lib/cmsis/inc/core_armv81mml.h @@ -1,11 +1,11 @@ /**************************************************************************//** * @file core_armv81mml.h * @brief CMSIS Armv8.1-M Mainline Core Peripheral Access Layer Header File - * @version V1.0.0 - * @date 15. March 2019 + * @version V1.4.2 + * @date 13. October 2021 ******************************************************************************/ /* - * Copyright (c) 2018-2019 Arm Limited. All rights reserved. + * Copyright (c) 2018-2021 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -23,9 +23,11 @@ */ #if defined ( __ICCARM__ ) - #pragma system_include /* treat file as system include file for MISRA check */ + #pragma system_include /* treat file as system include file for MISRA check */ #elif defined (__clang__) - #pragma clang system_header /* treat file as system include file */ + #pragma clang system_header /* treat file as system include file */ +#elif defined ( __GNUC__ ) + #pragma GCC diagnostic ignored "-Wpedantic" /* disable pedantic warning due to unnamed structs/unions */ #endif #ifndef __CORE_ARMV81MML_H_GENERIC @@ -61,48 +63,23 @@ */ #include "cmsis_version.h" - -#define __ARM_ARCH_8M_MAIN__ 1 // patching for now + /* CMSIS ARMV81MML definitions */ #define __ARMv81MML_CMSIS_VERSION_MAIN (__CM_CMSIS_VERSION_MAIN) /*!< \deprecated [31:16] CMSIS HAL main version */ #define __ARMv81MML_CMSIS_VERSION_SUB (__CM_CMSIS_VERSION_SUB) /*!< \deprecated [15:0] CMSIS HAL sub version */ #define __ARMv81MML_CMSIS_VERSION ((__ARMv81MML_CMSIS_VERSION_MAIN << 16U) | \ __ARMv81MML_CMSIS_VERSION_SUB ) /*!< \deprecated CMSIS HAL version number */ -#define __CORTEX_M (81U) /*!< Cortex-M Core */ +#define __CORTEX_M (81U) /*!< Cortex-M Core */ -/** __FPU_USED indicates whether an FPU is used or not. - For this, __FPU_PRESENT has to be checked prior to making use of FPU specific registers and functions. -*/ #if defined ( __CC_ARM ) - #if defined __TARGET_FPU_VFP - #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) - #define __FPU_USED 1U - #else - #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #define __FPU_USED 0U - #endif - #else - #define __FPU_USED 0U - #endif - - #if defined(__ARM_FEATURE_DSP) - #if defined(__DSP_PRESENT) && (__DSP_PRESENT == 1U) - #define __DSP_USED 1U - #else - #error "Compiler generates DSP (SIMD) instructions for a devices without DSP extensions (check __DSP_PRESENT)" - #define __DSP_USED 0U - #endif - #else - #define __DSP_USED 0U - #endif - + #error Legacy Arm Compiler does not support Armv8.1-M target architecture. #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) #if defined __ARM_FP #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) #define __FPU_USED 1U #else - #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" #define __FPU_USED 0U #endif #else @@ -114,7 +91,7 @@ #define __DSP_USED 1U #else #error "Compiler generates DSP (SIMD) instructions for a devices without DSP extensions (check __DSP_PRESENT)" - #define __DSP_USED 0U + #define __DSP_USED 0U #endif #else #define __DSP_USED 0U @@ -131,18 +108,18 @@ #else #define __FPU_USED 0U #endif - + #if defined(__ARM_FEATURE_DSP) #if defined(__DSP_PRESENT) && (__DSP_PRESENT == 1U) #define __DSP_USED 1U #else #error "Compiler generates DSP (SIMD) instructions for a devices without DSP extensions (check __DSP_PRESENT)" - #define __DSP_USED 0U + #define __DSP_USED 0U #endif #else #define __DSP_USED 0U #endif - + #elif defined ( __ICCARM__ ) #if defined __ARMVFP__ #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) @@ -160,12 +137,12 @@ #define __DSP_USED 1U #else #error "Compiler generates DSP (SIMD) instructions for a devices without DSP extensions (check __DSP_PRESENT)" - #define __DSP_USED 0U + #define __DSP_USED 0U #endif #else #define __DSP_USED 0U #endif - + #elif defined ( __TI_ARM__ ) #if defined __TI_VFP_SUPPORT__ #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) @@ -234,11 +211,42 @@ #warning "__FPU_PRESENT not defined in device header file; using default!" #endif + #if __FPU_PRESENT != 0U + #ifndef __FPU_DP + #define __FPU_DP 0U + #warning "__FPU_DP not defined in device header file; using default!" + #endif + #endif + #ifndef __MPU_PRESENT #define __MPU_PRESENT 0U #warning "__MPU_PRESENT not defined in device header file; using default!" #endif + #ifndef __ICACHE_PRESENT + #define __ICACHE_PRESENT 0U + #warning "__ICACHE_PRESENT not defined in device header file; using default!" + #endif + + #ifndef __DCACHE_PRESENT + #define __DCACHE_PRESENT 0U + #warning "__DCACHE_PRESENT not defined in device header file; using default!" + #endif + + #ifndef __PMU_PRESENT + #define __PMU_PRESENT 0U + #warning "__PMU_PRESENT not defined in device header file; using default!" + #endif + + #if __PMU_PRESENT != 0U + #ifndef __PMU_NUM_EVENTCNT + #define __PMU_NUM_EVENTCNT 2U + #warning "__PMU_NUM_EVENTCNT not defined in device header file; using default!" + #elif (__PMU_NUM_EVENTCNT > 31 || __PMU_NUM_EVENTCNT < 2) + #error "__PMU_NUM_EVENTCNT is out of range in device header file!" */ + #endif + #endif + #ifndef __SAUREGION_PRESENT #define __SAUREGION_PRESENT 0U #warning "__SAUREGION_PRESENT not defined in device header file; using default!" @@ -249,6 +257,11 @@ #warning "__DSP_PRESENT not defined in device header file; using default!" #endif + #ifndef __VTOR_PRESENT + #define __VTOR_PRESENT 1U + #warning "__VTOR_PRESENT not defined in device header file; using default!" + #endif + #ifndef __NVIC_PRIO_BITS #define __NVIC_PRIO_BITS 3U #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" @@ -513,7 +526,7 @@ typedef struct __IOM uint32_t AFSR; /*!< Offset: 0x03C (R/W) Auxiliary Fault Status Register */ __IM uint32_t ID_PFR[2U]; /*!< Offset: 0x040 (R/ ) Processor Feature Register */ __IM uint32_t ID_DFR; /*!< Offset: 0x048 (R/ ) Debug Feature Register */ - __IM uint32_t ID_ADR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */ + __IM uint32_t ID_AFR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */ __IM uint32_t ID_MMFR[4U]; /*!< Offset: 0x050 (R/ ) Memory Model Feature Register */ __IM uint32_t ID_ISAR[6U]; /*!< Offset: 0x060 (R/ ) Instruction Set Attributes Register */ __IM uint32_t CLIDR; /*!< Offset: 0x078 (R/ ) Cache Level ID register */ @@ -522,9 +535,13 @@ typedef struct __IOM uint32_t CSSELR; /*!< Offset: 0x084 (R/W) Cache Size Selection Register */ __IOM uint32_t CPACR; /*!< Offset: 0x088 (R/W) Coprocessor Access Control Register */ __IOM uint32_t NSACR; /*!< Offset: 0x08C (R/W) Non-Secure Access Control Register */ - uint32_t RESERVED3[92U]; + uint32_t RESERVED7[21U]; + __IOM uint32_t SFSR; /*!< Offset: 0x0E4 (R/W) Secure Fault Status Register */ + __IOM uint32_t SFAR; /*!< Offset: 0x0E8 (R/W) Secure Fault Address Register */ + uint32_t RESERVED3[69U]; __OM uint32_t STIR; /*!< Offset: 0x200 ( /W) Software Triggered Interrupt Register */ - uint32_t RESERVED4[15U]; + __IOM uint32_t RFSR; /*!< Offset: 0x204 (R/W) RAS Fault Status Register */ + uint32_t RESERVED4[14U]; __IM uint32_t MVFR0; /*!< Offset: 0x240 (R/ ) Media and VFP Feature Register 0 */ __IM uint32_t MVFR1; /*!< Offset: 0x244 (R/ ) Media and VFP Feature Register 1 */ __IM uint32_t MVFR2; /*!< Offset: 0x248 (R/ ) Media and VFP Feature Register 2 */ @@ -539,14 +556,7 @@ typedef struct __OM uint32_t DCCSW; /*!< Offset: 0x26C ( /W) D-Cache Clean by Set-way */ __OM uint32_t DCCIMVAC; /*!< Offset: 0x270 ( /W) D-Cache Clean and Invalidate by MVA to PoC */ __OM uint32_t DCCISW; /*!< Offset: 0x274 ( /W) D-Cache Clean and Invalidate by Set-way */ - uint32_t RESERVED7[6U]; - __IOM uint32_t ITCMCR; /*!< Offset: 0x290 (R/W) Instruction Tightly-Coupled Memory Control Register */ - __IOM uint32_t DTCMCR; /*!< Offset: 0x294 (R/W) Data Tightly-Coupled Memory Control Registers */ - __IOM uint32_t AHBPCR; /*!< Offset: 0x298 (R/W) AHBP Control Register */ - __IOM uint32_t CACR; /*!< Offset: 0x29C (R/W) L1 Cache Control Register */ - __IOM uint32_t AHBSCR; /*!< Offset: 0x2A0 (R/W) AHB Slave Control Register */ - uint32_t RESERVED8[1U]; - __IOM uint32_t ABFSR; /*!< Offset: 0x2A8 (R/W) Auxiliary Bus Fault Status Register */ + __OM uint32_t BPIALL; /*!< Offset: 0x278 ( /W) Branch Predictor Invalidate All */ } SCB_Type; /* SCB CPUID Register Definitions */ @@ -628,6 +638,12 @@ typedef struct #define SCB_AIRCR_PRIGROUP_Pos 8U /*!< SCB AIRCR: PRIGROUP Position */ #define SCB_AIRCR_PRIGROUP_Msk (7UL << SCB_AIRCR_PRIGROUP_Pos) /*!< SCB AIRCR: PRIGROUP Mask */ +#define SCB_AIRCR_IESB_Pos 5U /*!< SCB AIRCR: Implicit ESB Enable Position */ +#define SCB_AIRCR_IESB_Msk (1UL << SCB_AIRCR_IESB_Pos) /*!< SCB AIRCR: Implicit ESB Enable Mask */ + +#define SCB_AIRCR_DIT_Pos 4U /*!< SCB AIRCR: Data Independent Timing Position */ +#define SCB_AIRCR_DIT_Msk (1UL << SCB_AIRCR_DIT_Pos) /*!< SCB AIRCR: Data Independent Timing Mask */ + #define SCB_AIRCR_SYSRESETREQS_Pos 3U /*!< SCB AIRCR: SYSRESETREQS Position */ #define SCB_AIRCR_SYSRESETREQS_Msk (1UL << SCB_AIRCR_SYSRESETREQS_Pos) /*!< SCB AIRCR: SYSRESETREQS Mask */ @@ -651,6 +667,12 @@ typedef struct #define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */ /* SCB Configuration Control Register Definitions */ +#define SCB_CCR_TRD_Pos 20U /*!< SCB CCR: TRD Position */ +#define SCB_CCR_TRD_Msk (1UL << SCB_CCR_TRD_Pos) /*!< SCB CCR: TRD Mask */ + +#define SCB_CCR_LOB_Pos 19U /*!< SCB CCR: LOB Position */ +#define SCB_CCR_LOB_Msk (1UL << SCB_CCR_LOB_Pos) /*!< SCB CCR: LOB Mask */ + #define SCB_CCR_BP_Pos 18U /*!< SCB CCR: BP Position */ #define SCB_CCR_BP_Msk (1UL << SCB_CCR_BP_Pos) /*!< SCB CCR: BP Mask */ @@ -747,22 +769,22 @@ typedef struct #define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */ /* MemManage Fault Status Register (part of SCB Configurable Fault Status Register) */ -#define SCB_CFSR_MMARVALID_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */ +#define SCB_CFSR_MMARVALID_Pos (SCB_CFSR_MEMFAULTSR_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */ #define SCB_CFSR_MMARVALID_Msk (1UL << SCB_CFSR_MMARVALID_Pos) /*!< SCB CFSR (MMFSR): MMARVALID Mask */ -#define SCB_CFSR_MLSPERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 5U) /*!< SCB CFSR (MMFSR): MLSPERR Position */ +#define SCB_CFSR_MLSPERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 5U) /*!< SCB CFSR (MMFSR): MLSPERR Position */ #define SCB_CFSR_MLSPERR_Msk (1UL << SCB_CFSR_MLSPERR_Pos) /*!< SCB CFSR (MMFSR): MLSPERR Mask */ -#define SCB_CFSR_MSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */ +#define SCB_CFSR_MSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */ #define SCB_CFSR_MSTKERR_Msk (1UL << SCB_CFSR_MSTKERR_Pos) /*!< SCB CFSR (MMFSR): MSTKERR Mask */ -#define SCB_CFSR_MUNSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */ +#define SCB_CFSR_MUNSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */ #define SCB_CFSR_MUNSTKERR_Msk (1UL << SCB_CFSR_MUNSTKERR_Pos) /*!< SCB CFSR (MMFSR): MUNSTKERR Mask */ -#define SCB_CFSR_DACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */ +#define SCB_CFSR_DACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */ #define SCB_CFSR_DACCVIOL_Msk (1UL << SCB_CFSR_DACCVIOL_Pos) /*!< SCB CFSR (MMFSR): DACCVIOL Mask */ -#define SCB_CFSR_IACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */ +#define SCB_CFSR_IACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */ #define SCB_CFSR_IACCVIOL_Msk (1UL /*<< SCB_CFSR_IACCVIOL_Pos*/) /*!< SCB CFSR (MMFSR): IACCVIOL Mask */ /* BusFault Status Register (part of SCB Configurable Fault Status Register) */ @@ -820,6 +842,9 @@ typedef struct #define SCB_HFSR_VECTTBL_Msk (1UL << SCB_HFSR_VECTTBL_Pos) /*!< SCB HFSR: VECTTBL Mask */ /* SCB Debug Fault Status Register Definitions */ +#define SCB_DFSR_PMU_Pos 5U /*!< SCB DFSR: PMU Position */ +#define SCB_DFSR_PMU_Msk (1UL << SCB_DFSR_PMU_Pos) /*!< SCB DFSR: PMU Mask */ + #define SCB_DFSR_EXTERNAL_Pos 4U /*!< SCB DFSR: EXTERNAL Position */ #define SCB_DFSR_EXTERNAL_Msk (1UL << SCB_DFSR_EXTERNAL_Pos) /*!< SCB DFSR: EXTERNAL Mask */ @@ -842,8 +867,36 @@ typedef struct #define SCB_NSACR_CP10_Pos 10U /*!< SCB NSACR: CP10 Position */ #define SCB_NSACR_CP10_Msk (1UL << SCB_NSACR_CP10_Pos) /*!< SCB NSACR: CP10 Mask */ -#define SCB_NSACR_CPn_Pos 0U /*!< SCB NSACR: CPn Position */ -#define SCB_NSACR_CPn_Msk (1UL /*<< SCB_NSACR_CPn_Pos*/) /*!< SCB NSACR: CPn Mask */ +#define SCB_NSACR_CP7_Pos 7U /*!< SCB NSACR: CP7 Position */ +#define SCB_NSACR_CP7_Msk (1UL << SCB_NSACR_CP7_Pos) /*!< SCB NSACR: CP7 Mask */ + +#define SCB_NSACR_CP6_Pos 6U /*!< SCB NSACR: CP6 Position */ +#define SCB_NSACR_CP6_Msk (1UL << SCB_NSACR_CP6_Pos) /*!< SCB NSACR: CP6 Mask */ + +#define SCB_NSACR_CP5_Pos 5U /*!< SCB NSACR: CP5 Position */ +#define SCB_NSACR_CP5_Msk (1UL << SCB_NSACR_CP5_Pos) /*!< SCB NSACR: CP5 Mask */ + +#define SCB_NSACR_CP4_Pos 4U /*!< SCB NSACR: CP4 Position */ +#define SCB_NSACR_CP4_Msk (1UL << SCB_NSACR_CP4_Pos) /*!< SCB NSACR: CP4 Mask */ + +#define SCB_NSACR_CP3_Pos 3U /*!< SCB NSACR: CP3 Position */ +#define SCB_NSACR_CP3_Msk (1UL << SCB_NSACR_CP3_Pos) /*!< SCB NSACR: CP3 Mask */ + +#define SCB_NSACR_CP2_Pos 2U /*!< SCB NSACR: CP2 Position */ +#define SCB_NSACR_CP2_Msk (1UL << SCB_NSACR_CP2_Pos) /*!< SCB NSACR: CP2 Mask */ + +#define SCB_NSACR_CP1_Pos 1U /*!< SCB NSACR: CP1 Position */ +#define SCB_NSACR_CP1_Msk (1UL << SCB_NSACR_CP1_Pos) /*!< SCB NSACR: CP1 Mask */ + +#define SCB_NSACR_CP0_Pos 0U /*!< SCB NSACR: CP0 Position */ +#define SCB_NSACR_CP0_Msk (1UL /*<< SCB_NSACR_CP0_Pos*/) /*!< SCB NSACR: CP0 Mask */ + +/* SCB Debug Feature Register 0 Definitions */ +#define SCB_ID_DFR_UDE_Pos 28U /*!< SCB ID_DFR: UDE Position */ +#define SCB_ID_DFR_UDE_Msk (0xFUL << SCB_ID_DFR_UDE_Pos) /*!< SCB ID_DFR: UDE Mask */ + +#define SCB_ID_DFR_MProfDbg_Pos 20U /*!< SCB ID_DFR: MProfDbg Position */ +#define SCB_ID_DFR_MProfDbg_Msk (0xFUL << SCB_ID_DFR_MProfDbg_Pos) /*!< SCB ID_DFR: MProfDbg Mask */ /* SCB Cache Level ID Register Definitions */ #define SCB_CLIDR_LOUU_Pos 27U /*!< SCB CLIDR: LoUU Position */ @@ -901,6 +954,16 @@ typedef struct #define SCB_STIR_INTID_Pos 0U /*!< SCB STIR: INTID Position */ #define SCB_STIR_INTID_Msk (0x1FFUL /*<< SCB_STIR_INTID_Pos*/) /*!< SCB STIR: INTID Mask */ +/* SCB RAS Fault Status Register Definitions */ +#define SCB_RFSR_V_Pos 31U /*!< SCB RFSR: V Position */ +#define SCB_RFSR_V_Msk (1UL << SCB_RFSR_V_Pos) /*!< SCB RFSR: V Mask */ + +#define SCB_RFSR_IS_Pos 16U /*!< SCB RFSR: IS Position */ +#define SCB_RFSR_IS_Msk (0x7FFFUL << SCB_RFSR_IS_Pos) /*!< SCB RFSR: IS Mask */ + +#define SCB_RFSR_UET_Pos 0U /*!< SCB RFSR: UET Position */ +#define SCB_RFSR_UET_Msk (3UL /*<< SCB_RFSR_UET_Pos*/) /*!< SCB RFSR: UET Mask */ + /* SCB D-Cache Invalidate by Set-way Register Definitions */ #define SCB_DCISW_WAY_Pos 30U /*!< SCB DCISW: Way Position */ #define SCB_DCISW_WAY_Msk (3UL << SCB_DCISW_WAY_Pos) /*!< SCB DCISW: Way Mask */ @@ -922,78 +985,6 @@ typedef struct #define SCB_DCCISW_SET_Pos 5U /*!< SCB DCCISW: Set Position */ #define SCB_DCCISW_SET_Msk (0x1FFUL << SCB_DCCISW_SET_Pos) /*!< SCB DCCISW: Set Mask */ -/* Instruction Tightly-Coupled Memory Control Register Definitions */ -#define SCB_ITCMCR_SZ_Pos 3U /*!< SCB ITCMCR: SZ Position */ -#define SCB_ITCMCR_SZ_Msk (0xFUL << SCB_ITCMCR_SZ_Pos) /*!< SCB ITCMCR: SZ Mask */ - -#define SCB_ITCMCR_RETEN_Pos 2U /*!< SCB ITCMCR: RETEN Position */ -#define SCB_ITCMCR_RETEN_Msk (1UL << SCB_ITCMCR_RETEN_Pos) /*!< SCB ITCMCR: RETEN Mask */ - -#define SCB_ITCMCR_RMW_Pos 1U /*!< SCB ITCMCR: RMW Position */ -#define SCB_ITCMCR_RMW_Msk (1UL << SCB_ITCMCR_RMW_Pos) /*!< SCB ITCMCR: RMW Mask */ - -#define SCB_ITCMCR_EN_Pos 0U /*!< SCB ITCMCR: EN Position */ -#define SCB_ITCMCR_EN_Msk (1UL /*<< SCB_ITCMCR_EN_Pos*/) /*!< SCB ITCMCR: EN Mask */ - -/* Data Tightly-Coupled Memory Control Register Definitions */ -#define SCB_DTCMCR_SZ_Pos 3U /*!< SCB DTCMCR: SZ Position */ -#define SCB_DTCMCR_SZ_Msk (0xFUL << SCB_DTCMCR_SZ_Pos) /*!< SCB DTCMCR: SZ Mask */ - -#define SCB_DTCMCR_RETEN_Pos 2U /*!< SCB DTCMCR: RETEN Position */ -#define SCB_DTCMCR_RETEN_Msk (1UL << SCB_DTCMCR_RETEN_Pos) /*!< SCB DTCMCR: RETEN Mask */ - -#define SCB_DTCMCR_RMW_Pos 1U /*!< SCB DTCMCR: RMW Position */ -#define SCB_DTCMCR_RMW_Msk (1UL << SCB_DTCMCR_RMW_Pos) /*!< SCB DTCMCR: RMW Mask */ - -#define SCB_DTCMCR_EN_Pos 0U /*!< SCB DTCMCR: EN Position */ -#define SCB_DTCMCR_EN_Msk (1UL /*<< SCB_DTCMCR_EN_Pos*/) /*!< SCB DTCMCR: EN Mask */ - -/* AHBP Control Register Definitions */ -#define SCB_AHBPCR_SZ_Pos 1U /*!< SCB AHBPCR: SZ Position */ -#define SCB_AHBPCR_SZ_Msk (7UL << SCB_AHBPCR_SZ_Pos) /*!< SCB AHBPCR: SZ Mask */ - -#define SCB_AHBPCR_EN_Pos 0U /*!< SCB AHBPCR: EN Position */ -#define SCB_AHBPCR_EN_Msk (1UL /*<< SCB_AHBPCR_EN_Pos*/) /*!< SCB AHBPCR: EN Mask */ - -/* L1 Cache Control Register Definitions */ -#define SCB_CACR_FORCEWT_Pos 2U /*!< SCB CACR: FORCEWT Position */ -#define SCB_CACR_FORCEWT_Msk (1UL << SCB_CACR_FORCEWT_Pos) /*!< SCB CACR: FORCEWT Mask */ - -#define SCB_CACR_ECCEN_Pos 1U /*!< SCB CACR: ECCEN Position */ -#define SCB_CACR_ECCEN_Msk (1UL << SCB_CACR_ECCEN_Pos) /*!< SCB CACR: ECCEN Mask */ - -#define SCB_CACR_SIWT_Pos 0U /*!< SCB CACR: SIWT Position */ -#define SCB_CACR_SIWT_Msk (1UL /*<< SCB_CACR_SIWT_Pos*/) /*!< SCB CACR: SIWT Mask */ - -/* AHBS Control Register Definitions */ -#define SCB_AHBSCR_INITCOUNT_Pos 11U /*!< SCB AHBSCR: INITCOUNT Position */ -#define SCB_AHBSCR_INITCOUNT_Msk (0x1FUL << SCB_AHBPCR_INITCOUNT_Pos) /*!< SCB AHBSCR: INITCOUNT Mask */ - -#define SCB_AHBSCR_TPRI_Pos 2U /*!< SCB AHBSCR: TPRI Position */ -#define SCB_AHBSCR_TPRI_Msk (0x1FFUL << SCB_AHBPCR_TPRI_Pos) /*!< SCB AHBSCR: TPRI Mask */ - -#define SCB_AHBSCR_CTL_Pos 0U /*!< SCB AHBSCR: CTL Position*/ -#define SCB_AHBSCR_CTL_Msk (3UL /*<< SCB_AHBPCR_CTL_Pos*/) /*!< SCB AHBSCR: CTL Mask */ - -/* Auxiliary Bus Fault Status Register Definitions */ -#define SCB_ABFSR_AXIMTYPE_Pos 8U /*!< SCB ABFSR: AXIMTYPE Position*/ -#define SCB_ABFSR_AXIMTYPE_Msk (3UL << SCB_ABFSR_AXIMTYPE_Pos) /*!< SCB ABFSR: AXIMTYPE Mask */ - -#define SCB_ABFSR_EPPB_Pos 4U /*!< SCB ABFSR: EPPB Position*/ -#define SCB_ABFSR_EPPB_Msk (1UL << SCB_ABFSR_EPPB_Pos) /*!< SCB ABFSR: EPPB Mask */ - -#define SCB_ABFSR_AXIM_Pos 3U /*!< SCB ABFSR: AXIM Position*/ -#define SCB_ABFSR_AXIM_Msk (1UL << SCB_ABFSR_AXIM_Pos) /*!< SCB ABFSR: AXIM Mask */ - -#define SCB_ABFSR_AHBP_Pos 2U /*!< SCB ABFSR: AHBP Position*/ -#define SCB_ABFSR_AHBP_Msk (1UL << SCB_ABFSR_AHBP_Pos) /*!< SCB ABFSR: AHBP Mask */ - -#define SCB_ABFSR_DTCM_Pos 1U /*!< SCB ABFSR: DTCM Position*/ -#define SCB_ABFSR_DTCM_Msk (1UL << SCB_ABFSR_DTCM_Pos) /*!< SCB ABFSR: DTCM Mask */ - -#define SCB_ABFSR_ITCM_Pos 0U /*!< SCB ABFSR: ITCM Position*/ -#define SCB_ABFSR_ITCM_Msk (1UL /*<< SCB_ABFSR_ITCM_Pos*/) /*!< SCB ABFSR: ITCM Mask */ - /*@} end of group CMSIS_SCB */ @@ -1098,16 +1089,14 @@ typedef struct __IOM uint32_t TPR; /*!< Offset: 0xE40 (R/W) ITM Trace Privilege Register */ uint32_t RESERVED2[15U]; __IOM uint32_t TCR; /*!< Offset: 0xE80 (R/W) ITM Trace Control Register */ - uint32_t RESERVED3[29U]; - __OM uint32_t IWR; /*!< Offset: 0xEF8 ( /W) ITM Integration Write Register */ - __IM uint32_t IRR; /*!< Offset: 0xEFC (R/ ) ITM Integration Read Register */ - __IOM uint32_t IMCR; /*!< Offset: 0xF00 (R/W) ITM Integration Mode Control Register */ + uint32_t RESERVED3[32U]; uint32_t RESERVED4[43U]; __OM uint32_t LAR; /*!< Offset: 0xFB0 ( /W) ITM Lock Access Register */ __IM uint32_t LSR; /*!< Offset: 0xFB4 (R/ ) ITM Lock Status Register */ uint32_t RESERVED5[1U]; __IM uint32_t DEVARCH; /*!< Offset: 0xFBC (R/ ) ITM Device Architecture Register */ - uint32_t RESERVED6[4U]; + uint32_t RESERVED6[3U]; + __IM uint32_t DEVTYPE; /*!< Offset: 0xFCC (R/ ) ITM Device Type Register */ __IM uint32_t PID4; /*!< Offset: 0xFD0 (R/ ) ITM Peripheral Identification Register #4 */ __IM uint32_t PID5; /*!< Offset: 0xFD4 (R/ ) ITM Peripheral Identification Register #5 */ __IM uint32_t PID6; /*!< Offset: 0xFD8 (R/ ) ITM Peripheral Identification Register #6 */ @@ -1164,18 +1153,6 @@ typedef struct #define ITM_TCR_ITMENA_Pos 0U /*!< ITM TCR: ITM Enable bit Position */ #define ITM_TCR_ITMENA_Msk (1UL /*<< ITM_TCR_ITMENA_Pos*/) /*!< ITM TCR: ITM Enable bit Mask */ -/* ITM Integration Write Register Definitions */ -#define ITM_IWR_ATVALIDM_Pos 0U /*!< ITM IWR: ATVALIDM Position */ -#define ITM_IWR_ATVALIDM_Msk (1UL /*<< ITM_IWR_ATVALIDM_Pos*/) /*!< ITM IWR: ATVALIDM Mask */ - -/* ITM Integration Read Register Definitions */ -#define ITM_IRR_ATREADYM_Pos 0U /*!< ITM IRR: ATREADYM Position */ -#define ITM_IRR_ATREADYM_Msk (1UL /*<< ITM_IRR_ATREADYM_Pos*/) /*!< ITM IRR: ATREADYM Mask */ - -/* ITM Integration Mode Control Register Definitions */ -#define ITM_IMCR_INTEGRATION_Pos 0U /*!< ITM IMCR: INTEGRATION Position */ -#define ITM_IMCR_INTEGRATION_Msk (1UL /*<< ITM_IMCR_INTEGRATION_Pos*/) /*!< ITM IMCR: INTEGRATION Mask */ - /* ITM Lock Status Register Definitions */ #define ITM_LSR_ByteAcc_Pos 2U /*!< ITM LSR: ByteAcc Position */ #define ITM_LSR_ByteAcc_Msk (1UL << ITM_LSR_ByteAcc_Pos) /*!< ITM LSR: ByteAcc Mask */ @@ -1396,26 +1373,18 @@ typedef struct uint32_t RESERVED2[131U]; __IM uint32_t FFSR; /*!< Offset: 0x300 (R/ ) Formatter and Flush Status Register */ __IOM uint32_t FFCR; /*!< Offset: 0x304 (R/W) Formatter and Flush Control Register */ - __IM uint32_t FSCR; /*!< Offset: 0x308 (R/ ) Formatter Synchronization Counter Register */ - uint32_t RESERVED3[759U]; - __IM uint32_t TRIGGER; /*!< Offset: 0xEE8 (R/ ) TRIGGER */ - __IM uint32_t FIFO0; /*!< Offset: 0xEEC (R/ ) Integration ETM Data */ - __IM uint32_t ITATBCTR2; /*!< Offset: 0xEF0 (R/ ) ITATBCTR2 */ - uint32_t RESERVED4[1U]; - __IM uint32_t ITATBCTR0; /*!< Offset: 0xEF8 (R/ ) ITATBCTR0 */ - __IM uint32_t FIFO1; /*!< Offset: 0xEFC (R/ ) Integration ITM Data */ - __IOM uint32_t ITCTRL; /*!< Offset: 0xF00 (R/W) Integration Mode Control */ - uint32_t RESERVED5[39U]; - __IOM uint32_t CLAIMSET; /*!< Offset: 0xFA0 (R/W) Claim tag set */ - __IOM uint32_t CLAIMCLR; /*!< Offset: 0xFA4 (R/W) Claim tag clear */ - uint32_t RESERVED7[8U]; - __IM uint32_t DEVID; /*!< Offset: 0xFC8 (R/ ) TPIU_DEVID */ - __IM uint32_t DEVTYPE; /*!< Offset: 0xFCC (R/ ) TPIU_DEVTYPE */ + __IOM uint32_t PSCR; /*!< Offset: 0x308 (R/W) Periodic Synchronization Control Register */ + uint32_t RESERVED3[809U]; + __OM uint32_t LAR; /*!< Offset: 0xFB0 ( /W) Software Lock Access Register */ + __IM uint32_t LSR; /*!< Offset: 0xFB4 (R/ ) Software Lock Status Register */ + uint32_t RESERVED4[4U]; + __IM uint32_t TYPE; /*!< Offset: 0xFC8 (R/ ) Device Identifier Register */ + __IM uint32_t DEVTYPE; /*!< Offset: 0xFCC (R/ ) Device Type Register */ } TPI_Type; /* TPI Asynchronous Clock Prescaler Register Definitions */ -#define TPI_ACPR_PRESCALER_Pos 0U /*!< TPI ACPR: PRESCALER Position */ -#define TPI_ACPR_PRESCALER_Msk (0x1FFFUL /*<< TPI_ACPR_PRESCALER_Pos*/) /*!< TPI ACPR: PRESCALER Mask */ +#define TPI_ACPR_SWOSCALER_Pos 0U /*!< TPI ACPR: SWOSCALER Position */ +#define TPI_ACPR_SWOSCALER_Msk (0xFFFFUL /*<< TPI_ACPR_SWOSCALER_Pos*/) /*!< TPI ACPR: SWOSCALER Mask */ /* TPI Selected Pin Protocol Register Definitions */ #define TPI_SPPR_TXMODE_Pos 0U /*!< TPI SPPR: TXMODE Position */ @@ -1438,68 +1407,25 @@ typedef struct #define TPI_FFCR_TrigIn_Pos 8U /*!< TPI FFCR: TrigIn Position */ #define TPI_FFCR_TrigIn_Msk (0x1UL << TPI_FFCR_TrigIn_Pos) /*!< TPI FFCR: TrigIn Mask */ -#define TPI_FFCR_EnFCont_Pos 1U /*!< TPI FFCR: EnFCont Position */ -#define TPI_FFCR_EnFCont_Msk (0x1UL << TPI_FFCR_EnFCont_Pos) /*!< TPI FFCR: EnFCont Mask */ - -/* TPI TRIGGER Register Definitions */ -#define TPI_TRIGGER_TRIGGER_Pos 0U /*!< TPI TRIGGER: TRIGGER Position */ -#define TPI_TRIGGER_TRIGGER_Msk (0x1UL /*<< TPI_TRIGGER_TRIGGER_Pos*/) /*!< TPI TRIGGER: TRIGGER Mask */ - -/* TPI Integration ETM Data Register Definitions (FIFO0) */ -#define TPI_FIFO0_ITM_ATVALID_Pos 29U /*!< TPI FIFO0: ITM_ATVALID Position */ -#define TPI_FIFO0_ITM_ATVALID_Msk (0x3UL << TPI_FIFO0_ITM_ATVALID_Pos) /*!< TPI FIFO0: ITM_ATVALID Mask */ - -#define TPI_FIFO0_ITM_bytecount_Pos 27U /*!< TPI FIFO0: ITM_bytecount Position */ -#define TPI_FIFO0_ITM_bytecount_Msk (0x3UL << TPI_FIFO0_ITM_bytecount_Pos) /*!< TPI FIFO0: ITM_bytecount Mask */ - -#define TPI_FIFO0_ETM_ATVALID_Pos 26U /*!< TPI FIFO0: ETM_ATVALID Position */ -#define TPI_FIFO0_ETM_ATVALID_Msk (0x3UL << TPI_FIFO0_ETM_ATVALID_Pos) /*!< TPI FIFO0: ETM_ATVALID Mask */ - -#define TPI_FIFO0_ETM_bytecount_Pos 24U /*!< TPI FIFO0: ETM_bytecount Position */ -#define TPI_FIFO0_ETM_bytecount_Msk (0x3UL << TPI_FIFO0_ETM_bytecount_Pos) /*!< TPI FIFO0: ETM_bytecount Mask */ - -#define TPI_FIFO0_ETM2_Pos 16U /*!< TPI FIFO0: ETM2 Position */ -#define TPI_FIFO0_ETM2_Msk (0xFFUL << TPI_FIFO0_ETM2_Pos) /*!< TPI FIFO0: ETM2 Mask */ - -#define TPI_FIFO0_ETM1_Pos 8U /*!< TPI FIFO0: ETM1 Position */ -#define TPI_FIFO0_ETM1_Msk (0xFFUL << TPI_FIFO0_ETM1_Pos) /*!< TPI FIFO0: ETM1 Mask */ - -#define TPI_FIFO0_ETM0_Pos 0U /*!< TPI FIFO0: ETM0 Position */ -#define TPI_FIFO0_ETM0_Msk (0xFFUL /*<< TPI_FIFO0_ETM0_Pos*/) /*!< TPI FIFO0: ETM0 Mask */ - -/* TPI ITATBCTR2 Register Definitions */ -#define TPI_ITATBCTR2_ATREADY_Pos 0U /*!< TPI ITATBCTR2: ATREADY Position */ -#define TPI_ITATBCTR2_ATREADY_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY_Pos*/) /*!< TPI ITATBCTR2: ATREADY Mask */ - -/* TPI Integration ITM Data Register Definitions (FIFO1) */ -#define TPI_FIFO1_ITM_ATVALID_Pos 29U /*!< TPI FIFO1: ITM_ATVALID Position */ -#define TPI_FIFO1_ITM_ATVALID_Msk (0x3UL << TPI_FIFO1_ITM_ATVALID_Pos) /*!< TPI FIFO1: ITM_ATVALID Mask */ - -#define TPI_FIFO1_ITM_bytecount_Pos 27U /*!< TPI FIFO1: ITM_bytecount Position */ -#define TPI_FIFO1_ITM_bytecount_Msk (0x3UL << TPI_FIFO1_ITM_bytecount_Pos) /*!< TPI FIFO1: ITM_bytecount Mask */ - -#define TPI_FIFO1_ETM_ATVALID_Pos 26U /*!< TPI FIFO1: ETM_ATVALID Position */ -#define TPI_FIFO1_ETM_ATVALID_Msk (0x3UL << TPI_FIFO1_ETM_ATVALID_Pos) /*!< TPI FIFO1: ETM_ATVALID Mask */ +#define TPI_FFCR_FOnMan_Pos 6U /*!< TPI FFCR: FOnMan Position */ +#define TPI_FFCR_FOnMan_Msk (0x1UL << TPI_FFCR_FOnMan_Pos) /*!< TPI FFCR: FOnMan Mask */ -#define TPI_FIFO1_ETM_bytecount_Pos 24U /*!< TPI FIFO1: ETM_bytecount Position */ -#define TPI_FIFO1_ETM_bytecount_Msk (0x3UL << TPI_FIFO1_ETM_bytecount_Pos) /*!< TPI FIFO1: ETM_bytecount Mask */ +#define TPI_FFCR_EnFmt_Pos 0U /*!< TPI FFCR: EnFmt Position */ +#define TPI_FFCR_EnFmt_Msk (0x3UL << /*TPI_FFCR_EnFmt_Pos*/) /*!< TPI FFCR: EnFmt Mask */ -#define TPI_FIFO1_ITM2_Pos 16U /*!< TPI FIFO1: ITM2 Position */ -#define TPI_FIFO1_ITM2_Msk (0xFFUL << TPI_FIFO1_ITM2_Pos) /*!< TPI FIFO1: ITM2 Mask */ +/* TPI Periodic Synchronization Control Register Definitions */ +#define TPI_PSCR_PSCount_Pos 0U /*!< TPI PSCR: PSCount Position */ +#define TPI_PSCR_PSCount_Msk (0x1FUL /*<< TPI_PSCR_PSCount_Pos*/) /*!< TPI PSCR: TPSCount Mask */ -#define TPI_FIFO1_ITM1_Pos 8U /*!< TPI FIFO1: ITM1 Position */ -#define TPI_FIFO1_ITM1_Msk (0xFFUL << TPI_FIFO1_ITM1_Pos) /*!< TPI FIFO1: ITM1 Mask */ +/* TPI Software Lock Status Register Definitions */ +#define TPI_LSR_nTT_Pos 1U /*!< TPI LSR: Not thirty-two bit. Position */ +#define TPI_LSR_nTT_Msk (0x1UL << TPI_LSR_nTT_Pos) /*!< TPI LSR: Not thirty-two bit. Mask */ -#define TPI_FIFO1_ITM0_Pos 0U /*!< TPI FIFO1: ITM0 Position */ -#define TPI_FIFO1_ITM0_Msk (0xFFUL /*<< TPI_FIFO1_ITM0_Pos*/) /*!< TPI FIFO1: ITM0 Mask */ +#define TPI_LSR_SLK_Pos 1U /*!< TPI LSR: Software Lock status Position */ +#define TPI_LSR_SLK_Msk (0x1UL << TPI_LSR_SLK_Pos) /*!< TPI LSR: Software Lock status Mask */ -/* TPI ITATBCTR0 Register Definitions */ -#define TPI_ITATBCTR0_ATREADY_Pos 0U /*!< TPI ITATBCTR0: ATREADY Position */ -#define TPI_ITATBCTR0_ATREADY_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY_Pos*/) /*!< TPI ITATBCTR0: ATREADY Mask */ - -/* TPI Integration Mode Control Register Definitions */ -#define TPI_ITCTRL_Mode_Pos 0U /*!< TPI ITCTRL: Mode Position */ -#define TPI_ITCTRL_Mode_Msk (0x1UL /*<< TPI_ITCTRL_Mode_Pos*/) /*!< TPI ITCTRL: Mode Mask */ +#define TPI_LSR_SLI_Pos 0U /*!< TPI LSR: Software Lock implemented Position */ +#define TPI_LSR_SLI_Msk (0x1UL /*<< TPI_LSR_SLI_Pos*/) /*!< TPI LSR: Software Lock implemented Mask */ /* TPI DEVID Register Definitions */ #define TPI_DEVID_NRZVALID_Pos 11U /*!< TPI DEVID: NRZVALID Position */ @@ -1511,237 +1437,1047 @@ typedef struct #define TPI_DEVID_PTINVALID_Pos 9U /*!< TPI DEVID: PTINVALID Position */ #define TPI_DEVID_PTINVALID_Msk (0x1UL << TPI_DEVID_PTINVALID_Pos) /*!< TPI DEVID: PTINVALID Mask */ -#define TPI_DEVID_MinBufSz_Pos 6U /*!< TPI DEVID: MinBufSz Position */ -#define TPI_DEVID_MinBufSz_Msk (0x7UL << TPI_DEVID_MinBufSz_Pos) /*!< TPI DEVID: MinBufSz Mask */ - -#define TPI_DEVID_AsynClkIn_Pos 5U /*!< TPI DEVID: AsynClkIn Position */ -#define TPI_DEVID_AsynClkIn_Msk (0x1UL << TPI_DEVID_AsynClkIn_Pos) /*!< TPI DEVID: AsynClkIn Mask */ - -#define TPI_DEVID_NrTraceInput_Pos 0U /*!< TPI DEVID: NrTraceInput Position */ -#define TPI_DEVID_NrTraceInput_Msk (0x1FUL /*<< TPI_DEVID_NrTraceInput_Pos*/) /*!< TPI DEVID: NrTraceInput Mask */ +#define TPI_DEVID_FIFOSZ_Pos 6U /*!< TPI DEVID: FIFO depth Position */ +#define TPI_DEVID_FIFOSZ_Msk (0x7UL << TPI_DEVID_FIFOSZ_Pos) /*!< TPI DEVID: FIFO depth Mask */ /* TPI DEVTYPE Register Definitions */ -#define TPI_DEVTYPE_MajorType_Pos 4U /*!< TPI DEVTYPE: MajorType Position */ -#define TPI_DEVTYPE_MajorType_Msk (0xFUL << TPI_DEVTYPE_MajorType_Pos) /*!< TPI DEVTYPE: MajorType Mask */ - -#define TPI_DEVTYPE_SubType_Pos 0U /*!< TPI DEVTYPE: SubType Position */ +#define TPI_DEVTYPE_SubType_Pos 4U /*!< TPI DEVTYPE: SubType Position */ #define TPI_DEVTYPE_SubType_Msk (0xFUL /*<< TPI_DEVTYPE_SubType_Pos*/) /*!< TPI DEVTYPE: SubType Mask */ -/*@}*/ /* end of group CMSIS_TPI */ +#define TPI_DEVTYPE_MajorType_Pos 0U /*!< TPI DEVTYPE: MajorType Position */ +#define TPI_DEVTYPE_MajorType_Msk (0xFUL << TPI_DEVTYPE_MajorType_Pos) /*!< TPI DEVTYPE: MajorType Mask */ +/*@}*/ /* end of group CMSIS_TPI */ -#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) +#if defined (__PMU_PRESENT) && (__PMU_PRESENT == 1U) /** \ingroup CMSIS_core_register - \defgroup CMSIS_MPU Memory Protection Unit (MPU) - \brief Type definitions for the Memory Protection Unit (MPU) + \defgroup CMSIS_PMU Performance Monitoring Unit (PMU) + \brief Type definitions for the Performance Monitoring Unit (PMU) @{ */ /** - \brief Structure type to access the Memory Protection Unit (MPU). + \brief Structure type to access the Performance Monitoring Unit (PMU). */ typedef struct { - __IM uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */ - __IOM uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */ - __IOM uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region Number Register */ - __IOM uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */ - __IOM uint32_t RLAR; /*!< Offset: 0x010 (R/W) MPU Region Limit Address Register */ - __IOM uint32_t RBAR_A1; /*!< Offset: 0x014 (R/W) MPU Region Base Address Register Alias 1 */ - __IOM uint32_t RLAR_A1; /*!< Offset: 0x018 (R/W) MPU Region Limit Address Register Alias 1 */ - __IOM uint32_t RBAR_A2; /*!< Offset: 0x01C (R/W) MPU Region Base Address Register Alias 2 */ - __IOM uint32_t RLAR_A2; /*!< Offset: 0x020 (R/W) MPU Region Limit Address Register Alias 2 */ - __IOM uint32_t RBAR_A3; /*!< Offset: 0x024 (R/W) MPU Region Base Address Register Alias 3 */ - __IOM uint32_t RLAR_A3; /*!< Offset: 0x028 (R/W) MPU Region Limit Address Register Alias 3 */ - uint32_t RESERVED0[1]; - union { - __IOM uint32_t MAIR[2]; - struct { - __IOM uint32_t MAIR0; /*!< Offset: 0x030 (R/W) MPU Memory Attribute Indirection Register 0 */ - __IOM uint32_t MAIR1; /*!< Offset: 0x034 (R/W) MPU Memory Attribute Indirection Register 1 */ - }; - }; -} MPU_Type; + __IOM uint32_t EVCNTR[__PMU_NUM_EVENTCNT]; /*!< Offset: 0x0 (R/W) PMU Event Counter Registers */ +#if __PMU_NUM_EVENTCNT<31 + uint32_t RESERVED0[31U-__PMU_NUM_EVENTCNT]; +#endif + __IOM uint32_t CCNTR; /*!< Offset: 0x7C (R/W) PMU Cycle Counter Register */ + uint32_t RESERVED1[224]; + __IOM uint32_t EVTYPER[__PMU_NUM_EVENTCNT]; /*!< Offset: 0x400 (R/W) PMU Event Type and Filter Registers */ +#if __PMU_NUM_EVENTCNT<31 + uint32_t RESERVED2[31U-__PMU_NUM_EVENTCNT]; +#endif + __IOM uint32_t CCFILTR; /*!< Offset: 0x47C (R/W) PMU Cycle Counter Filter Register */ + uint32_t RESERVED3[480]; + __IOM uint32_t CNTENSET; /*!< Offset: 0xC00 (R/W) PMU Count Enable Set Register */ + uint32_t RESERVED4[7]; + __IOM uint32_t CNTENCLR; /*!< Offset: 0xC20 (R/W) PMU Count Enable Clear Register */ + uint32_t RESERVED5[7]; + __IOM uint32_t INTENSET; /*!< Offset: 0xC40 (R/W) PMU Interrupt Enable Set Register */ + uint32_t RESERVED6[7]; + __IOM uint32_t INTENCLR; /*!< Offset: 0xC60 (R/W) PMU Interrupt Enable Clear Register */ + uint32_t RESERVED7[7]; + __IOM uint32_t OVSCLR; /*!< Offset: 0xC80 (R/W) PMU Overflow Flag Status Clear Register */ + uint32_t RESERVED8[7]; + __IOM uint32_t SWINC; /*!< Offset: 0xCA0 (R/W) PMU Software Increment Register */ + uint32_t RESERVED9[7]; + __IOM uint32_t OVSSET; /*!< Offset: 0xCC0 (R/W) PMU Overflow Flag Status Set Register */ + uint32_t RESERVED10[79]; + __IOM uint32_t TYPE; /*!< Offset: 0xE00 (R/W) PMU Type Register */ + __IOM uint32_t CTRL; /*!< Offset: 0xE04 (R/W) PMU Control Register */ + uint32_t RESERVED11[108]; + __IOM uint32_t AUTHSTATUS; /*!< Offset: 0xFB8 (R/W) PMU Authentication Status Register */ + __IOM uint32_t DEVARCH; /*!< Offset: 0xFBC (R/W) PMU Device Architecture Register */ + uint32_t RESERVED12[3]; + __IOM uint32_t DEVTYPE; /*!< Offset: 0xFCC (R/W) PMU Device Type Register */ + __IOM uint32_t PIDR4; /*!< Offset: 0xFD0 (R/W) PMU Peripheral Identification Register 4 */ + uint32_t RESERVED13[3]; + __IOM uint32_t PIDR0; /*!< Offset: 0xFE0 (R/W) PMU Peripheral Identification Register 0 */ + __IOM uint32_t PIDR1; /*!< Offset: 0xFE4 (R/W) PMU Peripheral Identification Register 1 */ + __IOM uint32_t PIDR2; /*!< Offset: 0xFE8 (R/W) PMU Peripheral Identification Register 2 */ + __IOM uint32_t PIDR3; /*!< Offset: 0xFEC (R/W) PMU Peripheral Identification Register 3 */ + __IOM uint32_t CIDR0; /*!< Offset: 0xFF0 (R/W) PMU Component Identification Register 0 */ + __IOM uint32_t CIDR1; /*!< Offset: 0xFF4 (R/W) PMU Component Identification Register 1 */ + __IOM uint32_t CIDR2; /*!< Offset: 0xFF8 (R/W) PMU Component Identification Register 2 */ + __IOM uint32_t CIDR3; /*!< Offset: 0xFFC (R/W) PMU Component Identification Register 3 */ +} PMU_Type; -#define MPU_TYPE_RALIASES 4U +/** \brief PMU Event Counter Registers (0-30) Definitions */ -/* MPU Type Register Definitions */ -#define MPU_TYPE_IREGION_Pos 16U /*!< MPU TYPE: IREGION Position */ -#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */ +#define PMU_EVCNTR_CNT_Pos 0U /*!< PMU EVCNTR: Counter Position */ +#define PMU_EVCNTR_CNT_Msk (0xFFFFUL /*<< PMU_EVCNTRx_CNT_Pos*/) /*!< PMU EVCNTR: Counter Mask */ -#define MPU_TYPE_DREGION_Pos 8U /*!< MPU TYPE: DREGION Position */ -#define MPU_TYPE_DREGION_Msk (0xFFUL << MPU_TYPE_DREGION_Pos) /*!< MPU TYPE: DREGION Mask */ +/** \brief PMU Event Type and Filter Registers (0-30) Definitions */ -#define MPU_TYPE_SEPARATE_Pos 0U /*!< MPU TYPE: SEPARATE Position */ -#define MPU_TYPE_SEPARATE_Msk (1UL /*<< MPU_TYPE_SEPARATE_Pos*/) /*!< MPU TYPE: SEPARATE Mask */ +#define PMU_EVTYPER_EVENTTOCNT_Pos 0U /*!< PMU EVTYPER: Event to Count Position */ +#define PMU_EVTYPER_EVENTTOCNT_Msk (0xFFFFUL /*<< EVTYPERx_EVENTTOCNT_Pos*/) /*!< PMU EVTYPER: Event to Count Mask */ -/* MPU Control Register Definitions */ -#define MPU_CTRL_PRIVDEFENA_Pos 2U /*!< MPU CTRL: PRIVDEFENA Position */ -#define MPU_CTRL_PRIVDEFENA_Msk (1UL << MPU_CTRL_PRIVDEFENA_Pos) /*!< MPU CTRL: PRIVDEFENA Mask */ +/** \brief PMU Count Enable Set Register Definitions */ -#define MPU_CTRL_HFNMIENA_Pos 1U /*!< MPU CTRL: HFNMIENA Position */ -#define MPU_CTRL_HFNMIENA_Msk (1UL << MPU_CTRL_HFNMIENA_Pos) /*!< MPU CTRL: HFNMIENA Mask */ +#define PMU_CNTENSET_CNT0_ENABLE_Pos 0U /*!< PMU CNTENSET: Event Counter 0 Enable Set Position */ +#define PMU_CNTENSET_CNT0_ENABLE_Msk (1UL /*<< PMU_CNTENSET_CNT0_ENABLE_Pos*/) /*!< PMU CNTENSET: Event Counter 0 Enable Set Mask */ -#define MPU_CTRL_ENABLE_Pos 0U /*!< MPU CTRL: ENABLE Position */ -#define MPU_CTRL_ENABLE_Msk (1UL /*<< MPU_CTRL_ENABLE_Pos*/) /*!< MPU CTRL: ENABLE Mask */ +#define PMU_CNTENSET_CNT1_ENABLE_Pos 1U /*!< PMU CNTENSET: Event Counter 1 Enable Set Position */ +#define PMU_CNTENSET_CNT1_ENABLE_Msk (1UL << PMU_CNTENSET_CNT1_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 1 Enable Set Mask */ -/* MPU Region Number Register Definitions */ -#define MPU_RNR_REGION_Pos 0U /*!< MPU RNR: REGION Position */ -#define MPU_RNR_REGION_Msk (0xFFUL /*<< MPU_RNR_REGION_Pos*/) /*!< MPU RNR: REGION Mask */ +#define PMU_CNTENSET_CNT2_ENABLE_Pos 2U /*!< PMU CNTENSET: Event Counter 2 Enable Set Position */ +#define PMU_CNTENSET_CNT2_ENABLE_Msk (1UL << PMU_CNTENSET_CNT2_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 2 Enable Set Mask */ -/* MPU Region Base Address Register Definitions */ -#define MPU_RBAR_ADDR_Pos 5U /*!< MPU RBAR: ADDR Position */ -#define MPU_RBAR_ADDR_Msk (0x7FFFFFFUL << MPU_RBAR_ADDR_Pos) /*!< MPU RBAR: ADDR Mask */ +#define PMU_CNTENSET_CNT3_ENABLE_Pos 3U /*!< PMU CNTENSET: Event Counter 3 Enable Set Position */ +#define PMU_CNTENSET_CNT3_ENABLE_Msk (1UL << PMU_CNTENSET_CNT3_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 3 Enable Set Mask */ -#define MPU_RBAR_SH_Pos 3U /*!< MPU RBAR: SH Position */ -#define MPU_RBAR_SH_Msk (0x3UL << MPU_RBAR_SH_Pos) /*!< MPU RBAR: SH Mask */ +#define PMU_CNTENSET_CNT4_ENABLE_Pos 4U /*!< PMU CNTENSET: Event Counter 4 Enable Set Position */ +#define PMU_CNTENSET_CNT4_ENABLE_Msk (1UL << PMU_CNTENSET_CNT4_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 4 Enable Set Mask */ -#define MPU_RBAR_AP_Pos 1U /*!< MPU RBAR: AP Position */ -#define MPU_RBAR_AP_Msk (0x3UL << MPU_RBAR_AP_Pos) /*!< MPU RBAR: AP Mask */ +#define PMU_CNTENSET_CNT5_ENABLE_Pos 5U /*!< PMU CNTENSET: Event Counter 5 Enable Set Position */ +#define PMU_CNTENSET_CNT5_ENABLE_Msk (1UL << PMU_CNTENSET_CNT5_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 5 Enable Set Mask */ -#define MPU_RBAR_XN_Pos 0U /*!< MPU RBAR: XN Position */ -#define MPU_RBAR_XN_Msk (01UL /*<< MPU_RBAR_XN_Pos*/) /*!< MPU RBAR: XN Mask */ +#define PMU_CNTENSET_CNT6_ENABLE_Pos 6U /*!< PMU CNTENSET: Event Counter 6 Enable Set Position */ +#define PMU_CNTENSET_CNT6_ENABLE_Msk (1UL << PMU_CNTENSET_CNT6_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 6 Enable Set Mask */ -/* MPU Region Limit Address Register Definitions */ -#define MPU_RLAR_LIMIT_Pos 5U /*!< MPU RLAR: LIMIT Position */ -#define MPU_RLAR_LIMIT_Msk (0x7FFFFFFUL << MPU_RLAR_LIMIT_Pos) /*!< MPU RLAR: LIMIT Mask */ +#define PMU_CNTENSET_CNT7_ENABLE_Pos 7U /*!< PMU CNTENSET: Event Counter 7 Enable Set Position */ +#define PMU_CNTENSET_CNT7_ENABLE_Msk (1UL << PMU_CNTENSET_CNT7_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 7 Enable Set Mask */ -#define MPU_RLAR_PXN_Pos 4U /*!< MPU RLAR: PXN Position */ -#define MPU_RLAR_PXN_Msk (0x1UL << MPU_RLAR_PXN_Pos) /*!< MPU RLAR: PXN Mask */ +#define PMU_CNTENSET_CNT8_ENABLE_Pos 8U /*!< PMU CNTENSET: Event Counter 8 Enable Set Position */ +#define PMU_CNTENSET_CNT8_ENABLE_Msk (1UL << PMU_CNTENSET_CNT8_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 8 Enable Set Mask */ -#define MPU_RLAR_AttrIndx_Pos 1U /*!< MPU RLAR: AttrIndx Position */ -#define MPU_RLAR_AttrIndx_Msk (0x7UL << MPU_RLAR_AttrIndx_Pos) /*!< MPU RLAR: AttrIndx Mask */ +#define PMU_CNTENSET_CNT9_ENABLE_Pos 9U /*!< PMU CNTENSET: Event Counter 9 Enable Set Position */ +#define PMU_CNTENSET_CNT9_ENABLE_Msk (1UL << PMU_CNTENSET_CNT9_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 9 Enable Set Mask */ -#define MPU_RLAR_EN_Pos 0U /*!< MPU RLAR: Region enable bit Position */ -#define MPU_RLAR_EN_Msk (1UL /*<< MPU_RLAR_EN_Pos*/) /*!< MPU RLAR: Region enable bit Disable Mask */ +#define PMU_CNTENSET_CNT10_ENABLE_Pos 10U /*!< PMU CNTENSET: Event Counter 10 Enable Set Position */ +#define PMU_CNTENSET_CNT10_ENABLE_Msk (1UL << PMU_CNTENSET_CNT10_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 10 Enable Set Mask */ -/* MPU Memory Attribute Indirection Register 0 Definitions */ -#define MPU_MAIR0_Attr3_Pos 24U /*!< MPU MAIR0: Attr3 Position */ -#define MPU_MAIR0_Attr3_Msk (0xFFUL << MPU_MAIR0_Attr3_Pos) /*!< MPU MAIR0: Attr3 Mask */ +#define PMU_CNTENSET_CNT11_ENABLE_Pos 11U /*!< PMU CNTENSET: Event Counter 11 Enable Set Position */ +#define PMU_CNTENSET_CNT11_ENABLE_Msk (1UL << PMU_CNTENSET_CNT11_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 11 Enable Set Mask */ -#define MPU_MAIR0_Attr2_Pos 16U /*!< MPU MAIR0: Attr2 Position */ -#define MPU_MAIR0_Attr2_Msk (0xFFUL << MPU_MAIR0_Attr2_Pos) /*!< MPU MAIR0: Attr2 Mask */ +#define PMU_CNTENSET_CNT12_ENABLE_Pos 12U /*!< PMU CNTENSET: Event Counter 12 Enable Set Position */ +#define PMU_CNTENSET_CNT12_ENABLE_Msk (1UL << PMU_CNTENSET_CNT12_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 12 Enable Set Mask */ -#define MPU_MAIR0_Attr1_Pos 8U /*!< MPU MAIR0: Attr1 Position */ -#define MPU_MAIR0_Attr1_Msk (0xFFUL << MPU_MAIR0_Attr1_Pos) /*!< MPU MAIR0: Attr1 Mask */ +#define PMU_CNTENSET_CNT13_ENABLE_Pos 13U /*!< PMU CNTENSET: Event Counter 13 Enable Set Position */ +#define PMU_CNTENSET_CNT13_ENABLE_Msk (1UL << PMU_CNTENSET_CNT13_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 13 Enable Set Mask */ -#define MPU_MAIR0_Attr0_Pos 0U /*!< MPU MAIR0: Attr0 Position */ -#define MPU_MAIR0_Attr0_Msk (0xFFUL /*<< MPU_MAIR0_Attr0_Pos*/) /*!< MPU MAIR0: Attr0 Mask */ +#define PMU_CNTENSET_CNT14_ENABLE_Pos 14U /*!< PMU CNTENSET: Event Counter 14 Enable Set Position */ +#define PMU_CNTENSET_CNT14_ENABLE_Msk (1UL << PMU_CNTENSET_CNT14_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 14 Enable Set Mask */ -/* MPU Memory Attribute Indirection Register 1 Definitions */ -#define MPU_MAIR1_Attr7_Pos 24U /*!< MPU MAIR1: Attr7 Position */ -#define MPU_MAIR1_Attr7_Msk (0xFFUL << MPU_MAIR1_Attr7_Pos) /*!< MPU MAIR1: Attr7 Mask */ +#define PMU_CNTENSET_CNT15_ENABLE_Pos 15U /*!< PMU CNTENSET: Event Counter 15 Enable Set Position */ +#define PMU_CNTENSET_CNT15_ENABLE_Msk (1UL << PMU_CNTENSET_CNT15_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 15 Enable Set Mask */ -#define MPU_MAIR1_Attr6_Pos 16U /*!< MPU MAIR1: Attr6 Position */ -#define MPU_MAIR1_Attr6_Msk (0xFFUL << MPU_MAIR1_Attr6_Pos) /*!< MPU MAIR1: Attr6 Mask */ +#define PMU_CNTENSET_CNT16_ENABLE_Pos 16U /*!< PMU CNTENSET: Event Counter 16 Enable Set Position */ +#define PMU_CNTENSET_CNT16_ENABLE_Msk (1UL << PMU_CNTENSET_CNT16_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 16 Enable Set Mask */ -#define MPU_MAIR1_Attr5_Pos 8U /*!< MPU MAIR1: Attr5 Position */ -#define MPU_MAIR1_Attr5_Msk (0xFFUL << MPU_MAIR1_Attr5_Pos) /*!< MPU MAIR1: Attr5 Mask */ +#define PMU_CNTENSET_CNT17_ENABLE_Pos 17U /*!< PMU CNTENSET: Event Counter 17 Enable Set Position */ +#define PMU_CNTENSET_CNT17_ENABLE_Msk (1UL << PMU_CNTENSET_CNT17_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 17 Enable Set Mask */ -#define MPU_MAIR1_Attr4_Pos 0U /*!< MPU MAIR1: Attr4 Position */ -#define MPU_MAIR1_Attr4_Msk (0xFFUL /*<< MPU_MAIR1_Attr4_Pos*/) /*!< MPU MAIR1: Attr4 Mask */ +#define PMU_CNTENSET_CNT18_ENABLE_Pos 18U /*!< PMU CNTENSET: Event Counter 18 Enable Set Position */ +#define PMU_CNTENSET_CNT18_ENABLE_Msk (1UL << PMU_CNTENSET_CNT18_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 18 Enable Set Mask */ -/*@} end of group CMSIS_MPU */ -#endif +#define PMU_CNTENSET_CNT19_ENABLE_Pos 19U /*!< PMU CNTENSET: Event Counter 19 Enable Set Position */ +#define PMU_CNTENSET_CNT19_ENABLE_Msk (1UL << PMU_CNTENSET_CNT19_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 19 Enable Set Mask */ +#define PMU_CNTENSET_CNT20_ENABLE_Pos 20U /*!< PMU CNTENSET: Event Counter 20 Enable Set Position */ +#define PMU_CNTENSET_CNT20_ENABLE_Msk (1UL << PMU_CNTENSET_CNT20_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 20 Enable Set Mask */ -#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) -/** - \ingroup CMSIS_core_register - \defgroup CMSIS_SAU Security Attribution Unit (SAU) - \brief Type definitions for the Security Attribution Unit (SAU) - @{ - */ +#define PMU_CNTENSET_CNT21_ENABLE_Pos 21U /*!< PMU CNTENSET: Event Counter 21 Enable Set Position */ +#define PMU_CNTENSET_CNT21_ENABLE_Msk (1UL << PMU_CNTENSET_CNT21_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 21 Enable Set Mask */ -/** - \brief Structure type to access the Security Attribution Unit (SAU). - */ -typedef struct -{ - __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) SAU Control Register */ - __IM uint32_t TYPE; /*!< Offset: 0x004 (R/ ) SAU Type Register */ -#if defined (__SAUREGION_PRESENT) && (__SAUREGION_PRESENT == 1U) - __IOM uint32_t RNR; /*!< Offset: 0x008 (R/W) SAU Region Number Register */ - __IOM uint32_t RBAR; /*!< Offset: 0x00C (R/W) SAU Region Base Address Register */ - __IOM uint32_t RLAR; /*!< Offset: 0x010 (R/W) SAU Region Limit Address Register */ -#else - uint32_t RESERVED0[3]; -#endif - __IOM uint32_t SFSR; /*!< Offset: 0x014 (R/W) Secure Fault Status Register */ - __IOM uint32_t SFAR; /*!< Offset: 0x018 (R/W) Secure Fault Address Register */ -} SAU_Type; +#define PMU_CNTENSET_CNT22_ENABLE_Pos 22U /*!< PMU CNTENSET: Event Counter 22 Enable Set Position */ +#define PMU_CNTENSET_CNT22_ENABLE_Msk (1UL << PMU_CNTENSET_CNT22_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 22 Enable Set Mask */ -/* SAU Control Register Definitions */ -#define SAU_CTRL_ALLNS_Pos 1U /*!< SAU CTRL: ALLNS Position */ -#define SAU_CTRL_ALLNS_Msk (1UL << SAU_CTRL_ALLNS_Pos) /*!< SAU CTRL: ALLNS Mask */ +#define PMU_CNTENSET_CNT23_ENABLE_Pos 23U /*!< PMU CNTENSET: Event Counter 23 Enable Set Position */ +#define PMU_CNTENSET_CNT23_ENABLE_Msk (1UL << PMU_CNTENSET_CNT23_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 23 Enable Set Mask */ -#define SAU_CTRL_ENABLE_Pos 0U /*!< SAU CTRL: ENABLE Position */ -#define SAU_CTRL_ENABLE_Msk (1UL /*<< SAU_CTRL_ENABLE_Pos*/) /*!< SAU CTRL: ENABLE Mask */ +#define PMU_CNTENSET_CNT24_ENABLE_Pos 24U /*!< PMU CNTENSET: Event Counter 24 Enable Set Position */ +#define PMU_CNTENSET_CNT24_ENABLE_Msk (1UL << PMU_CNTENSET_CNT24_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 24 Enable Set Mask */ -/* SAU Type Register Definitions */ -#define SAU_TYPE_SREGION_Pos 0U /*!< SAU TYPE: SREGION Position */ -#define SAU_TYPE_SREGION_Msk (0xFFUL /*<< SAU_TYPE_SREGION_Pos*/) /*!< SAU TYPE: SREGION Mask */ +#define PMU_CNTENSET_CNT25_ENABLE_Pos 25U /*!< PMU CNTENSET: Event Counter 25 Enable Set Position */ +#define PMU_CNTENSET_CNT25_ENABLE_Msk (1UL << PMU_CNTENSET_CNT25_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 25 Enable Set Mask */ -#if defined (__SAUREGION_PRESENT) && (__SAUREGION_PRESENT == 1U) -/* SAU Region Number Register Definitions */ -#define SAU_RNR_REGION_Pos 0U /*!< SAU RNR: REGION Position */ -#define SAU_RNR_REGION_Msk (0xFFUL /*<< SAU_RNR_REGION_Pos*/) /*!< SAU RNR: REGION Mask */ +#define PMU_CNTENSET_CNT26_ENABLE_Pos 26U /*!< PMU CNTENSET: Event Counter 26 Enable Set Position */ +#define PMU_CNTENSET_CNT26_ENABLE_Msk (1UL << PMU_CNTENSET_CNT26_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 26 Enable Set Mask */ -/* SAU Region Base Address Register Definitions */ -#define SAU_RBAR_BADDR_Pos 5U /*!< SAU RBAR: BADDR Position */ -#define SAU_RBAR_BADDR_Msk (0x7FFFFFFUL << SAU_RBAR_BADDR_Pos) /*!< SAU RBAR: BADDR Mask */ +#define PMU_CNTENSET_CNT27_ENABLE_Pos 27U /*!< PMU CNTENSET: Event Counter 27 Enable Set Position */ +#define PMU_CNTENSET_CNT27_ENABLE_Msk (1UL << PMU_CNTENSET_CNT27_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 27 Enable Set Mask */ -/* SAU Region Limit Address Register Definitions */ -#define SAU_RLAR_LADDR_Pos 5U /*!< SAU RLAR: LADDR Position */ -#define SAU_RLAR_LADDR_Msk (0x7FFFFFFUL << SAU_RLAR_LADDR_Pos) /*!< SAU RLAR: LADDR Mask */ +#define PMU_CNTENSET_CNT28_ENABLE_Pos 28U /*!< PMU CNTENSET: Event Counter 28 Enable Set Position */ +#define PMU_CNTENSET_CNT28_ENABLE_Msk (1UL << PMU_CNTENSET_CNT28_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 28 Enable Set Mask */ -#define SAU_RLAR_NSC_Pos 1U /*!< SAU RLAR: NSC Position */ -#define SAU_RLAR_NSC_Msk (1UL << SAU_RLAR_NSC_Pos) /*!< SAU RLAR: NSC Mask */ +#define PMU_CNTENSET_CNT29_ENABLE_Pos 29U /*!< PMU CNTENSET: Event Counter 29 Enable Set Position */ +#define PMU_CNTENSET_CNT29_ENABLE_Msk (1UL << PMU_CNTENSET_CNT29_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 29 Enable Set Mask */ -#define SAU_RLAR_ENABLE_Pos 0U /*!< SAU RLAR: ENABLE Position */ -#define SAU_RLAR_ENABLE_Msk (1UL /*<< SAU_RLAR_ENABLE_Pos*/) /*!< SAU RLAR: ENABLE Mask */ +#define PMU_CNTENSET_CNT30_ENABLE_Pos 30U /*!< PMU CNTENSET: Event Counter 30 Enable Set Position */ +#define PMU_CNTENSET_CNT30_ENABLE_Msk (1UL << PMU_CNTENSET_CNT30_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 30 Enable Set Mask */ -#endif /* defined (__SAUREGION_PRESENT) && (__SAUREGION_PRESENT == 1U) */ +#define PMU_CNTENSET_CCNTR_ENABLE_Pos 31U /*!< PMU CNTENSET: Cycle Counter Enable Set Position */ +#define PMU_CNTENSET_CCNTR_ENABLE_Msk (1UL << PMU_CNTENSET_CCNTR_ENABLE_Pos) /*!< PMU CNTENSET: Cycle Counter Enable Set Mask */ -/* Secure Fault Status Register Definitions */ -#define SAU_SFSR_LSERR_Pos 7U /*!< SAU SFSR: LSERR Position */ -#define SAU_SFSR_LSERR_Msk (1UL << SAU_SFSR_LSERR_Pos) /*!< SAU SFSR: LSERR Mask */ +/** \brief PMU Count Enable Clear Register Definitions */ -#define SAU_SFSR_SFARVALID_Pos 6U /*!< SAU SFSR: SFARVALID Position */ -#define SAU_SFSR_SFARVALID_Msk (1UL << SAU_SFSR_SFARVALID_Pos) /*!< SAU SFSR: SFARVALID Mask */ +#define PMU_CNTENSET_CNT0_ENABLE_Pos 0U /*!< PMU CNTENCLR: Event Counter 0 Enable Clear Position */ +#define PMU_CNTENCLR_CNT0_ENABLE_Msk (1UL /*<< PMU_CNTENCLR_CNT0_ENABLE_Pos*/) /*!< PMU CNTENCLR: Event Counter 0 Enable Clear Mask */ -#define SAU_SFSR_LSPERR_Pos 5U /*!< SAU SFSR: LSPERR Position */ -#define SAU_SFSR_LSPERR_Msk (1UL << SAU_SFSR_LSPERR_Pos) /*!< SAU SFSR: LSPERR Mask */ +#define PMU_CNTENCLR_CNT1_ENABLE_Pos 1U /*!< PMU CNTENCLR: Event Counter 1 Enable Clear Position */ +#define PMU_CNTENCLR_CNT1_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT1_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 1 Enable Clear */ -#define SAU_SFSR_INVTRAN_Pos 4U /*!< SAU SFSR: INVTRAN Position */ -#define SAU_SFSR_INVTRAN_Msk (1UL << SAU_SFSR_INVTRAN_Pos) /*!< SAU SFSR: INVTRAN Mask */ +#define PMU_CNTENCLR_CNT2_ENABLE_Pos 2U /*!< PMU CNTENCLR: Event Counter 2 Enable Clear Position */ +#define PMU_CNTENCLR_CNT2_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT2_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 2 Enable Clear Mask */ -#define SAU_SFSR_AUVIOL_Pos 3U /*!< SAU SFSR: AUVIOL Position */ -#define SAU_SFSR_AUVIOL_Msk (1UL << SAU_SFSR_AUVIOL_Pos) /*!< SAU SFSR: AUVIOL Mask */ +#define PMU_CNTENCLR_CNT3_ENABLE_Pos 3U /*!< PMU CNTENCLR: Event Counter 3 Enable Clear Position */ +#define PMU_CNTENCLR_CNT3_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT3_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 3 Enable Clear Mask */ -#define SAU_SFSR_INVER_Pos 2U /*!< SAU SFSR: INVER Position */ -#define SAU_SFSR_INVER_Msk (1UL << SAU_SFSR_INVER_Pos) /*!< SAU SFSR: INVER Mask */ +#define PMU_CNTENCLR_CNT4_ENABLE_Pos 4U /*!< PMU CNTENCLR: Event Counter 4 Enable Clear Position */ +#define PMU_CNTENCLR_CNT4_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT4_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 4 Enable Clear Mask */ -#define SAU_SFSR_INVIS_Pos 1U /*!< SAU SFSR: INVIS Position */ -#define SAU_SFSR_INVIS_Msk (1UL << SAU_SFSR_INVIS_Pos) /*!< SAU SFSR: INVIS Mask */ +#define PMU_CNTENCLR_CNT5_ENABLE_Pos 5U /*!< PMU CNTENCLR: Event Counter 5 Enable Clear Position */ +#define PMU_CNTENCLR_CNT5_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT5_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 5 Enable Clear Mask */ -#define SAU_SFSR_INVEP_Pos 0U /*!< SAU SFSR: INVEP Position */ -#define SAU_SFSR_INVEP_Msk (1UL /*<< SAU_SFSR_INVEP_Pos*/) /*!< SAU SFSR: INVEP Mask */ +#define PMU_CNTENCLR_CNT6_ENABLE_Pos 6U /*!< PMU CNTENCLR: Event Counter 6 Enable Clear Position */ +#define PMU_CNTENCLR_CNT6_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT6_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 6 Enable Clear Mask */ -/*@} end of group CMSIS_SAU */ -#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ +#define PMU_CNTENCLR_CNT7_ENABLE_Pos 7U /*!< PMU CNTENCLR: Event Counter 7 Enable Clear Position */ +#define PMU_CNTENCLR_CNT7_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT7_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 7 Enable Clear Mask */ +#define PMU_CNTENCLR_CNT8_ENABLE_Pos 8U /*!< PMU CNTENCLR: Event Counter 8 Enable Clear Position */ +#define PMU_CNTENCLR_CNT8_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT8_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 8 Enable Clear Mask */ -/** - \ingroup CMSIS_core_register - \defgroup CMSIS_FPU Floating Point Unit (FPU) - \brief Type definitions for the Floating Point Unit (FPU) - @{ - */ +#define PMU_CNTENCLR_CNT9_ENABLE_Pos 9U /*!< PMU CNTENCLR: Event Counter 9 Enable Clear Position */ +#define PMU_CNTENCLR_CNT9_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT9_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 9 Enable Clear Mask */ -/** - \brief Structure type to access the Floating Point Unit (FPU). +#define PMU_CNTENCLR_CNT10_ENABLE_Pos 10U /*!< PMU CNTENCLR: Event Counter 10 Enable Clear Position */ +#define PMU_CNTENCLR_CNT10_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT10_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 10 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT11_ENABLE_Pos 11U /*!< PMU CNTENCLR: Event Counter 11 Enable Clear Position */ +#define PMU_CNTENCLR_CNT11_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT11_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 11 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT12_ENABLE_Pos 12U /*!< PMU CNTENCLR: Event Counter 12 Enable Clear Position */ +#define PMU_CNTENCLR_CNT12_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT12_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 12 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT13_ENABLE_Pos 13U /*!< PMU CNTENCLR: Event Counter 13 Enable Clear Position */ +#define PMU_CNTENCLR_CNT13_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT13_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 13 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT14_ENABLE_Pos 14U /*!< PMU CNTENCLR: Event Counter 14 Enable Clear Position */ +#define PMU_CNTENCLR_CNT14_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT14_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 14 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT15_ENABLE_Pos 15U /*!< PMU CNTENCLR: Event Counter 15 Enable Clear Position */ +#define PMU_CNTENCLR_CNT15_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT15_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 15 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT16_ENABLE_Pos 16U /*!< PMU CNTENCLR: Event Counter 16 Enable Clear Position */ +#define PMU_CNTENCLR_CNT16_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT16_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 16 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT17_ENABLE_Pos 17U /*!< PMU CNTENCLR: Event Counter 17 Enable Clear Position */ +#define PMU_CNTENCLR_CNT17_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT17_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 17 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT18_ENABLE_Pos 18U /*!< PMU CNTENCLR: Event Counter 18 Enable Clear Position */ +#define PMU_CNTENCLR_CNT18_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT18_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 18 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT19_ENABLE_Pos 19U /*!< PMU CNTENCLR: Event Counter 19 Enable Clear Position */ +#define PMU_CNTENCLR_CNT19_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT19_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 19 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT20_ENABLE_Pos 20U /*!< PMU CNTENCLR: Event Counter 20 Enable Clear Position */ +#define PMU_CNTENCLR_CNT20_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT20_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 20 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT21_ENABLE_Pos 21U /*!< PMU CNTENCLR: Event Counter 21 Enable Clear Position */ +#define PMU_CNTENCLR_CNT21_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT21_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 21 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT22_ENABLE_Pos 22U /*!< PMU CNTENCLR: Event Counter 22 Enable Clear Position */ +#define PMU_CNTENCLR_CNT22_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT22_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 22 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT23_ENABLE_Pos 23U /*!< PMU CNTENCLR: Event Counter 23 Enable Clear Position */ +#define PMU_CNTENCLR_CNT23_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT23_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 23 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT24_ENABLE_Pos 24U /*!< PMU CNTENCLR: Event Counter 24 Enable Clear Position */ +#define PMU_CNTENCLR_CNT24_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT24_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 24 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT25_ENABLE_Pos 25U /*!< PMU CNTENCLR: Event Counter 25 Enable Clear Position */ +#define PMU_CNTENCLR_CNT25_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT25_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 25 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT26_ENABLE_Pos 26U /*!< PMU CNTENCLR: Event Counter 26 Enable Clear Position */ +#define PMU_CNTENCLR_CNT26_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT26_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 26 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT27_ENABLE_Pos 27U /*!< PMU CNTENCLR: Event Counter 27 Enable Clear Position */ +#define PMU_CNTENCLR_CNT27_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT27_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 27 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT28_ENABLE_Pos 28U /*!< PMU CNTENCLR: Event Counter 28 Enable Clear Position */ +#define PMU_CNTENCLR_CNT28_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT28_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 28 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT29_ENABLE_Pos 29U /*!< PMU CNTENCLR: Event Counter 29 Enable Clear Position */ +#define PMU_CNTENCLR_CNT29_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT29_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 29 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT30_ENABLE_Pos 30U /*!< PMU CNTENCLR: Event Counter 30 Enable Clear Position */ +#define PMU_CNTENCLR_CNT30_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT30_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 30 Enable Clear Mask */ + +#define PMU_CNTENCLR_CCNTR_ENABLE_Pos 31U /*!< PMU CNTENCLR: Cycle Counter Enable Clear Position */ +#define PMU_CNTENCLR_CCNTR_ENABLE_Msk (1UL << PMU_CNTENCLR_CCNTR_ENABLE_Pos) /*!< PMU CNTENCLR: Cycle Counter Enable Clear Mask */ + +/** \brief PMU Interrupt Enable Set Register Definitions */ + +#define PMU_INTENSET_CNT0_ENABLE_Pos 0U /*!< PMU INTENSET: Event Counter 0 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT0_ENABLE_Msk (1UL /*<< PMU_INTENSET_CNT0_ENABLE_Pos*/) /*!< PMU INTENSET: Event Counter 0 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT1_ENABLE_Pos 1U /*!< PMU INTENSET: Event Counter 1 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT1_ENABLE_Msk (1UL << PMU_INTENSET_CNT1_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 1 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT2_ENABLE_Pos 2U /*!< PMU INTENSET: Event Counter 2 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT2_ENABLE_Msk (1UL << PMU_INTENSET_CNT2_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 2 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT3_ENABLE_Pos 3U /*!< PMU INTENSET: Event Counter 3 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT3_ENABLE_Msk (1UL << PMU_INTENSET_CNT3_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 3 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT4_ENABLE_Pos 4U /*!< PMU INTENSET: Event Counter 4 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT4_ENABLE_Msk (1UL << PMU_INTENSET_CNT4_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 4 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT5_ENABLE_Pos 5U /*!< PMU INTENSET: Event Counter 5 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT5_ENABLE_Msk (1UL << PMU_INTENSET_CNT5_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 5 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT6_ENABLE_Pos 6U /*!< PMU INTENSET: Event Counter 6 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT6_ENABLE_Msk (1UL << PMU_INTENSET_CNT6_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 6 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT7_ENABLE_Pos 7U /*!< PMU INTENSET: Event Counter 7 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT7_ENABLE_Msk (1UL << PMU_INTENSET_CNT7_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 7 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT8_ENABLE_Pos 8U /*!< PMU INTENSET: Event Counter 8 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT8_ENABLE_Msk (1UL << PMU_INTENSET_CNT8_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 8 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT9_ENABLE_Pos 9U /*!< PMU INTENSET: Event Counter 9 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT9_ENABLE_Msk (1UL << PMU_INTENSET_CNT9_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 9 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT10_ENABLE_Pos 10U /*!< PMU INTENSET: Event Counter 10 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT10_ENABLE_Msk (1UL << PMU_INTENSET_CNT10_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 10 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT11_ENABLE_Pos 11U /*!< PMU INTENSET: Event Counter 11 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT11_ENABLE_Msk (1UL << PMU_INTENSET_CNT11_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 11 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT12_ENABLE_Pos 12U /*!< PMU INTENSET: Event Counter 12 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT12_ENABLE_Msk (1UL << PMU_INTENSET_CNT12_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 12 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT13_ENABLE_Pos 13U /*!< PMU INTENSET: Event Counter 13 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT13_ENABLE_Msk (1UL << PMU_INTENSET_CNT13_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 13 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT14_ENABLE_Pos 14U /*!< PMU INTENSET: Event Counter 14 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT14_ENABLE_Msk (1UL << PMU_INTENSET_CNT14_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 14 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT15_ENABLE_Pos 15U /*!< PMU INTENSET: Event Counter 15 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT15_ENABLE_Msk (1UL << PMU_INTENSET_CNT15_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 15 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT16_ENABLE_Pos 16U /*!< PMU INTENSET: Event Counter 16 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT16_ENABLE_Msk (1UL << PMU_INTENSET_CNT16_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 16 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT17_ENABLE_Pos 17U /*!< PMU INTENSET: Event Counter 17 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT17_ENABLE_Msk (1UL << PMU_INTENSET_CNT17_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 17 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT18_ENABLE_Pos 18U /*!< PMU INTENSET: Event Counter 18 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT18_ENABLE_Msk (1UL << PMU_INTENSET_CNT18_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 18 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT19_ENABLE_Pos 19U /*!< PMU INTENSET: Event Counter 19 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT19_ENABLE_Msk (1UL << PMU_INTENSET_CNT19_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 19 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT20_ENABLE_Pos 20U /*!< PMU INTENSET: Event Counter 20 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT20_ENABLE_Msk (1UL << PMU_INTENSET_CNT20_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 20 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT21_ENABLE_Pos 21U /*!< PMU INTENSET: Event Counter 21 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT21_ENABLE_Msk (1UL << PMU_INTENSET_CNT21_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 21 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT22_ENABLE_Pos 22U /*!< PMU INTENSET: Event Counter 22 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT22_ENABLE_Msk (1UL << PMU_INTENSET_CNT22_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 22 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT23_ENABLE_Pos 23U /*!< PMU INTENSET: Event Counter 23 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT23_ENABLE_Msk (1UL << PMU_INTENSET_CNT23_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 23 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT24_ENABLE_Pos 24U /*!< PMU INTENSET: Event Counter 24 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT24_ENABLE_Msk (1UL << PMU_INTENSET_CNT24_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 24 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT25_ENABLE_Pos 25U /*!< PMU INTENSET: Event Counter 25 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT25_ENABLE_Msk (1UL << PMU_INTENSET_CNT25_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 25 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT26_ENABLE_Pos 26U /*!< PMU INTENSET: Event Counter 26 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT26_ENABLE_Msk (1UL << PMU_INTENSET_CNT26_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 26 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT27_ENABLE_Pos 27U /*!< PMU INTENSET: Event Counter 27 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT27_ENABLE_Msk (1UL << PMU_INTENSET_CNT27_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 27 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT28_ENABLE_Pos 28U /*!< PMU INTENSET: Event Counter 28 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT28_ENABLE_Msk (1UL << PMU_INTENSET_CNT28_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 28 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT29_ENABLE_Pos 29U /*!< PMU INTENSET: Event Counter 29 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT29_ENABLE_Msk (1UL << PMU_INTENSET_CNT29_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 29 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT30_ENABLE_Pos 30U /*!< PMU INTENSET: Event Counter 30 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT30_ENABLE_Msk (1UL << PMU_INTENSET_CNT30_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 30 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CYCCNT_ENABLE_Pos 31U /*!< PMU INTENSET: Cycle Counter Interrupt Enable Set Position */ +#define PMU_INTENSET_CCYCNT_ENABLE_Msk (1UL << PMU_INTENSET_CYCCNT_ENABLE_Pos) /*!< PMU INTENSET: Cycle Counter Interrupt Enable Set Mask */ + +/** \brief PMU Interrupt Enable Clear Register Definitions */ + +#define PMU_INTENSET_CNT0_ENABLE_Pos 0U /*!< PMU INTENCLR: Event Counter 0 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT0_ENABLE_Msk (1UL /*<< PMU_INTENCLR_CNT0_ENABLE_Pos*/) /*!< PMU INTENCLR: Event Counter 0 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT1_ENABLE_Pos 1U /*!< PMU INTENCLR: Event Counter 1 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT1_ENABLE_Msk (1UL << PMU_INTENCLR_CNT1_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 1 Interrupt Enable Clear */ + +#define PMU_INTENCLR_CNT2_ENABLE_Pos 2U /*!< PMU INTENCLR: Event Counter 2 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT2_ENABLE_Msk (1UL << PMU_INTENCLR_CNT2_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 2 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT3_ENABLE_Pos 3U /*!< PMU INTENCLR: Event Counter 3 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT3_ENABLE_Msk (1UL << PMU_INTENCLR_CNT3_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 3 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT4_ENABLE_Pos 4U /*!< PMU INTENCLR: Event Counter 4 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT4_ENABLE_Msk (1UL << PMU_INTENCLR_CNT4_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 4 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT5_ENABLE_Pos 5U /*!< PMU INTENCLR: Event Counter 5 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT5_ENABLE_Msk (1UL << PMU_INTENCLR_CNT5_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 5 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT6_ENABLE_Pos 6U /*!< PMU INTENCLR: Event Counter 6 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT6_ENABLE_Msk (1UL << PMU_INTENCLR_CNT6_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 6 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT7_ENABLE_Pos 7U /*!< PMU INTENCLR: Event Counter 7 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT7_ENABLE_Msk (1UL << PMU_INTENCLR_CNT7_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 7 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT8_ENABLE_Pos 8U /*!< PMU INTENCLR: Event Counter 8 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT8_ENABLE_Msk (1UL << PMU_INTENCLR_CNT8_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 8 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT9_ENABLE_Pos 9U /*!< PMU INTENCLR: Event Counter 9 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT9_ENABLE_Msk (1UL << PMU_INTENCLR_CNT9_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 9 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT10_ENABLE_Pos 10U /*!< PMU INTENCLR: Event Counter 10 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT10_ENABLE_Msk (1UL << PMU_INTENCLR_CNT10_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 10 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT11_ENABLE_Pos 11U /*!< PMU INTENCLR: Event Counter 11 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT11_ENABLE_Msk (1UL << PMU_INTENCLR_CNT11_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 11 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT12_ENABLE_Pos 12U /*!< PMU INTENCLR: Event Counter 12 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT12_ENABLE_Msk (1UL << PMU_INTENCLR_CNT12_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 12 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT13_ENABLE_Pos 13U /*!< PMU INTENCLR: Event Counter 13 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT13_ENABLE_Msk (1UL << PMU_INTENCLR_CNT13_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 13 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT14_ENABLE_Pos 14U /*!< PMU INTENCLR: Event Counter 14 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT14_ENABLE_Msk (1UL << PMU_INTENCLR_CNT14_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 14 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT15_ENABLE_Pos 15U /*!< PMU INTENCLR: Event Counter 15 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT15_ENABLE_Msk (1UL << PMU_INTENCLR_CNT15_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 15 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT16_ENABLE_Pos 16U /*!< PMU INTENCLR: Event Counter 16 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT16_ENABLE_Msk (1UL << PMU_INTENCLR_CNT16_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 16 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT17_ENABLE_Pos 17U /*!< PMU INTENCLR: Event Counter 17 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT17_ENABLE_Msk (1UL << PMU_INTENCLR_CNT17_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 17 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT18_ENABLE_Pos 18U /*!< PMU INTENCLR: Event Counter 18 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT18_ENABLE_Msk (1UL << PMU_INTENCLR_CNT18_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 18 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT19_ENABLE_Pos 19U /*!< PMU INTENCLR: Event Counter 19 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT19_ENABLE_Msk (1UL << PMU_INTENCLR_CNT19_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 19 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT20_ENABLE_Pos 20U /*!< PMU INTENCLR: Event Counter 20 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT20_ENABLE_Msk (1UL << PMU_INTENCLR_CNT20_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 20 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT21_ENABLE_Pos 21U /*!< PMU INTENCLR: Event Counter 21 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT21_ENABLE_Msk (1UL << PMU_INTENCLR_CNT21_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 21 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT22_ENABLE_Pos 22U /*!< PMU INTENCLR: Event Counter 22 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT22_ENABLE_Msk (1UL << PMU_INTENCLR_CNT22_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 22 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT23_ENABLE_Pos 23U /*!< PMU INTENCLR: Event Counter 23 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT23_ENABLE_Msk (1UL << PMU_INTENCLR_CNT23_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 23 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT24_ENABLE_Pos 24U /*!< PMU INTENCLR: Event Counter 24 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT24_ENABLE_Msk (1UL << PMU_INTENCLR_CNT24_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 24 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT25_ENABLE_Pos 25U /*!< PMU INTENCLR: Event Counter 25 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT25_ENABLE_Msk (1UL << PMU_INTENCLR_CNT25_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 25 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT26_ENABLE_Pos 26U /*!< PMU INTENCLR: Event Counter 26 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT26_ENABLE_Msk (1UL << PMU_INTENCLR_CNT26_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 26 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT27_ENABLE_Pos 27U /*!< PMU INTENCLR: Event Counter 27 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT27_ENABLE_Msk (1UL << PMU_INTENCLR_CNT27_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 27 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT28_ENABLE_Pos 28U /*!< PMU INTENCLR: Event Counter 28 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT28_ENABLE_Msk (1UL << PMU_INTENCLR_CNT28_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 28 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT29_ENABLE_Pos 29U /*!< PMU INTENCLR: Event Counter 29 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT29_ENABLE_Msk (1UL << PMU_INTENCLR_CNT29_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 29 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT30_ENABLE_Pos 30U /*!< PMU INTENCLR: Event Counter 30 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT30_ENABLE_Msk (1UL << PMU_INTENCLR_CNT30_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 30 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CYCCNT_ENABLE_Pos 31U /*!< PMU INTENCLR: Cycle Counter Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CYCCNT_ENABLE_Msk (1UL << PMU_INTENCLR_CYCCNT_ENABLE_Pos) /*!< PMU INTENCLR: Cycle Counter Interrupt Enable Clear Mask */ + +/** \brief PMU Overflow Flag Status Set Register Definitions */ + +#define PMU_OVSSET_CNT0_STATUS_Pos 0U /*!< PMU OVSSET: Event Counter 0 Overflow Set Position */ +#define PMU_OVSSET_CNT0_STATUS_Msk (1UL /*<< PMU_OVSSET_CNT0_STATUS_Pos*/) /*!< PMU OVSSET: Event Counter 0 Overflow Set Mask */ + +#define PMU_OVSSET_CNT1_STATUS_Pos 1U /*!< PMU OVSSET: Event Counter 1 Overflow Set Position */ +#define PMU_OVSSET_CNT1_STATUS_Msk (1UL << PMU_OVSSET_CNT1_STATUS_Pos) /*!< PMU OVSSET: Event Counter 1 Overflow Set Mask */ + +#define PMU_OVSSET_CNT2_STATUS_Pos 2U /*!< PMU OVSSET: Event Counter 2 Overflow Set Position */ +#define PMU_OVSSET_CNT2_STATUS_Msk (1UL << PMU_OVSSET_CNT2_STATUS_Pos) /*!< PMU OVSSET: Event Counter 2 Overflow Set Mask */ + +#define PMU_OVSSET_CNT3_STATUS_Pos 3U /*!< PMU OVSSET: Event Counter 3 Overflow Set Position */ +#define PMU_OVSSET_CNT3_STATUS_Msk (1UL << PMU_OVSSET_CNT3_STATUS_Pos) /*!< PMU OVSSET: Event Counter 3 Overflow Set Mask */ + +#define PMU_OVSSET_CNT4_STATUS_Pos 4U /*!< PMU OVSSET: Event Counter 4 Overflow Set Position */ +#define PMU_OVSSET_CNT4_STATUS_Msk (1UL << PMU_OVSSET_CNT4_STATUS_Pos) /*!< PMU OVSSET: Event Counter 4 Overflow Set Mask */ + +#define PMU_OVSSET_CNT5_STATUS_Pos 5U /*!< PMU OVSSET: Event Counter 5 Overflow Set Position */ +#define PMU_OVSSET_CNT5_STATUS_Msk (1UL << PMU_OVSSET_CNT5_STATUS_Pos) /*!< PMU OVSSET: Event Counter 5 Overflow Set Mask */ + +#define PMU_OVSSET_CNT6_STATUS_Pos 6U /*!< PMU OVSSET: Event Counter 6 Overflow Set Position */ +#define PMU_OVSSET_CNT6_STATUS_Msk (1UL << PMU_OVSSET_CNT6_STATUS_Pos) /*!< PMU OVSSET: Event Counter 6 Overflow Set Mask */ + +#define PMU_OVSSET_CNT7_STATUS_Pos 7U /*!< PMU OVSSET: Event Counter 7 Overflow Set Position */ +#define PMU_OVSSET_CNT7_STATUS_Msk (1UL << PMU_OVSSET_CNT7_STATUS_Pos) /*!< PMU OVSSET: Event Counter 7 Overflow Set Mask */ + +#define PMU_OVSSET_CNT8_STATUS_Pos 8U /*!< PMU OVSSET: Event Counter 8 Overflow Set Position */ +#define PMU_OVSSET_CNT8_STATUS_Msk (1UL << PMU_OVSSET_CNT8_STATUS_Pos) /*!< PMU OVSSET: Event Counter 8 Overflow Set Mask */ + +#define PMU_OVSSET_CNT9_STATUS_Pos 9U /*!< PMU OVSSET: Event Counter 9 Overflow Set Position */ +#define PMU_OVSSET_CNT9_STATUS_Msk (1UL << PMU_OVSSET_CNT9_STATUS_Pos) /*!< PMU OVSSET: Event Counter 9 Overflow Set Mask */ + +#define PMU_OVSSET_CNT10_STATUS_Pos 10U /*!< PMU OVSSET: Event Counter 10 Overflow Set Position */ +#define PMU_OVSSET_CNT10_STATUS_Msk (1UL << PMU_OVSSET_CNT10_STATUS_Pos) /*!< PMU OVSSET: Event Counter 10 Overflow Set Mask */ + +#define PMU_OVSSET_CNT11_STATUS_Pos 11U /*!< PMU OVSSET: Event Counter 11 Overflow Set Position */ +#define PMU_OVSSET_CNT11_STATUS_Msk (1UL << PMU_OVSSET_CNT11_STATUS_Pos) /*!< PMU OVSSET: Event Counter 11 Overflow Set Mask */ + +#define PMU_OVSSET_CNT12_STATUS_Pos 12U /*!< PMU OVSSET: Event Counter 12 Overflow Set Position */ +#define PMU_OVSSET_CNT12_STATUS_Msk (1UL << PMU_OVSSET_CNT12_STATUS_Pos) /*!< PMU OVSSET: Event Counter 12 Overflow Set Mask */ + +#define PMU_OVSSET_CNT13_STATUS_Pos 13U /*!< PMU OVSSET: Event Counter 13 Overflow Set Position */ +#define PMU_OVSSET_CNT13_STATUS_Msk (1UL << PMU_OVSSET_CNT13_STATUS_Pos) /*!< PMU OVSSET: Event Counter 13 Overflow Set Mask */ + +#define PMU_OVSSET_CNT14_STATUS_Pos 14U /*!< PMU OVSSET: Event Counter 14 Overflow Set Position */ +#define PMU_OVSSET_CNT14_STATUS_Msk (1UL << PMU_OVSSET_CNT14_STATUS_Pos) /*!< PMU OVSSET: Event Counter 14 Overflow Set Mask */ + +#define PMU_OVSSET_CNT15_STATUS_Pos 15U /*!< PMU OVSSET: Event Counter 15 Overflow Set Position */ +#define PMU_OVSSET_CNT15_STATUS_Msk (1UL << PMU_OVSSET_CNT15_STATUS_Pos) /*!< PMU OVSSET: Event Counter 15 Overflow Set Mask */ + +#define PMU_OVSSET_CNT16_STATUS_Pos 16U /*!< PMU OVSSET: Event Counter 16 Overflow Set Position */ +#define PMU_OVSSET_CNT16_STATUS_Msk (1UL << PMU_OVSSET_CNT16_STATUS_Pos) /*!< PMU OVSSET: Event Counter 16 Overflow Set Mask */ + +#define PMU_OVSSET_CNT17_STATUS_Pos 17U /*!< PMU OVSSET: Event Counter 17 Overflow Set Position */ +#define PMU_OVSSET_CNT17_STATUS_Msk (1UL << PMU_OVSSET_CNT17_STATUS_Pos) /*!< PMU OVSSET: Event Counter 17 Overflow Set Mask */ + +#define PMU_OVSSET_CNT18_STATUS_Pos 18U /*!< PMU OVSSET: Event Counter 18 Overflow Set Position */ +#define PMU_OVSSET_CNT18_STATUS_Msk (1UL << PMU_OVSSET_CNT18_STATUS_Pos) /*!< PMU OVSSET: Event Counter 18 Overflow Set Mask */ + +#define PMU_OVSSET_CNT19_STATUS_Pos 19U /*!< PMU OVSSET: Event Counter 19 Overflow Set Position */ +#define PMU_OVSSET_CNT19_STATUS_Msk (1UL << PMU_OVSSET_CNT19_STATUS_Pos) /*!< PMU OVSSET: Event Counter 19 Overflow Set Mask */ + +#define PMU_OVSSET_CNT20_STATUS_Pos 20U /*!< PMU OVSSET: Event Counter 20 Overflow Set Position */ +#define PMU_OVSSET_CNT20_STATUS_Msk (1UL << PMU_OVSSET_CNT20_STATUS_Pos) /*!< PMU OVSSET: Event Counter 20 Overflow Set Mask */ + +#define PMU_OVSSET_CNT21_STATUS_Pos 21U /*!< PMU OVSSET: Event Counter 21 Overflow Set Position */ +#define PMU_OVSSET_CNT21_STATUS_Msk (1UL << PMU_OVSSET_CNT21_STATUS_Pos) /*!< PMU OVSSET: Event Counter 21 Overflow Set Mask */ + +#define PMU_OVSSET_CNT22_STATUS_Pos 22U /*!< PMU OVSSET: Event Counter 22 Overflow Set Position */ +#define PMU_OVSSET_CNT22_STATUS_Msk (1UL << PMU_OVSSET_CNT22_STATUS_Pos) /*!< PMU OVSSET: Event Counter 22 Overflow Set Mask */ + +#define PMU_OVSSET_CNT23_STATUS_Pos 23U /*!< PMU OVSSET: Event Counter 23 Overflow Set Position */ +#define PMU_OVSSET_CNT23_STATUS_Msk (1UL << PMU_OVSSET_CNT23_STATUS_Pos) /*!< PMU OVSSET: Event Counter 23 Overflow Set Mask */ + +#define PMU_OVSSET_CNT24_STATUS_Pos 24U /*!< PMU OVSSET: Event Counter 24 Overflow Set Position */ +#define PMU_OVSSET_CNT24_STATUS_Msk (1UL << PMU_OVSSET_CNT24_STATUS_Pos) /*!< PMU OVSSET: Event Counter 24 Overflow Set Mask */ + +#define PMU_OVSSET_CNT25_STATUS_Pos 25U /*!< PMU OVSSET: Event Counter 25 Overflow Set Position */ +#define PMU_OVSSET_CNT25_STATUS_Msk (1UL << PMU_OVSSET_CNT25_STATUS_Pos) /*!< PMU OVSSET: Event Counter 25 Overflow Set Mask */ + +#define PMU_OVSSET_CNT26_STATUS_Pos 26U /*!< PMU OVSSET: Event Counter 26 Overflow Set Position */ +#define PMU_OVSSET_CNT26_STATUS_Msk (1UL << PMU_OVSSET_CNT26_STATUS_Pos) /*!< PMU OVSSET: Event Counter 26 Overflow Set Mask */ + +#define PMU_OVSSET_CNT27_STATUS_Pos 27U /*!< PMU OVSSET: Event Counter 27 Overflow Set Position */ +#define PMU_OVSSET_CNT27_STATUS_Msk (1UL << PMU_OVSSET_CNT27_STATUS_Pos) /*!< PMU OVSSET: Event Counter 27 Overflow Set Mask */ + +#define PMU_OVSSET_CNT28_STATUS_Pos 28U /*!< PMU OVSSET: Event Counter 28 Overflow Set Position */ +#define PMU_OVSSET_CNT28_STATUS_Msk (1UL << PMU_OVSSET_CNT28_STATUS_Pos) /*!< PMU OVSSET: Event Counter 28 Overflow Set Mask */ + +#define PMU_OVSSET_CNT29_STATUS_Pos 29U /*!< PMU OVSSET: Event Counter 29 Overflow Set Position */ +#define PMU_OVSSET_CNT29_STATUS_Msk (1UL << PMU_OVSSET_CNT29_STATUS_Pos) /*!< PMU OVSSET: Event Counter 29 Overflow Set Mask */ + +#define PMU_OVSSET_CNT30_STATUS_Pos 30U /*!< PMU OVSSET: Event Counter 30 Overflow Set Position */ +#define PMU_OVSSET_CNT30_STATUS_Msk (1UL << PMU_OVSSET_CNT30_STATUS_Pos) /*!< PMU OVSSET: Event Counter 30 Overflow Set Mask */ + +#define PMU_OVSSET_CYCCNT_STATUS_Pos 31U /*!< PMU OVSSET: Cycle Counter Overflow Set Position */ +#define PMU_OVSSET_CYCCNT_STATUS_Msk (1UL << PMU_OVSSET_CYCCNT_STATUS_Pos) /*!< PMU OVSSET: Cycle Counter Overflow Set Mask */ + +/** \brief PMU Overflow Flag Status Clear Register Definitions */ + +#define PMU_OVSCLR_CNT0_STATUS_Pos 0U /*!< PMU OVSCLR: Event Counter 0 Overflow Clear Position */ +#define PMU_OVSCLR_CNT0_STATUS_Msk (1UL /*<< PMU_OVSCLR_CNT0_STATUS_Pos*/) /*!< PMU OVSCLR: Event Counter 0 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT1_STATUS_Pos 1U /*!< PMU OVSCLR: Event Counter 1 Overflow Clear Position */ +#define PMU_OVSCLR_CNT1_STATUS_Msk (1UL << PMU_OVSCLR_CNT1_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 1 Overflow Clear */ + +#define PMU_OVSCLR_CNT2_STATUS_Pos 2U /*!< PMU OVSCLR: Event Counter 2 Overflow Clear Position */ +#define PMU_OVSCLR_CNT2_STATUS_Msk (1UL << PMU_OVSCLR_CNT2_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 2 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT3_STATUS_Pos 3U /*!< PMU OVSCLR: Event Counter 3 Overflow Clear Position */ +#define PMU_OVSCLR_CNT3_STATUS_Msk (1UL << PMU_OVSCLR_CNT3_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 3 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT4_STATUS_Pos 4U /*!< PMU OVSCLR: Event Counter 4 Overflow Clear Position */ +#define PMU_OVSCLR_CNT4_STATUS_Msk (1UL << PMU_OVSCLR_CNT4_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 4 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT5_STATUS_Pos 5U /*!< PMU OVSCLR: Event Counter 5 Overflow Clear Position */ +#define PMU_OVSCLR_CNT5_STATUS_Msk (1UL << PMU_OVSCLR_CNT5_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 5 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT6_STATUS_Pos 6U /*!< PMU OVSCLR: Event Counter 6 Overflow Clear Position */ +#define PMU_OVSCLR_CNT6_STATUS_Msk (1UL << PMU_OVSCLR_CNT6_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 6 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT7_STATUS_Pos 7U /*!< PMU OVSCLR: Event Counter 7 Overflow Clear Position */ +#define PMU_OVSCLR_CNT7_STATUS_Msk (1UL << PMU_OVSCLR_CNT7_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 7 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT8_STATUS_Pos 8U /*!< PMU OVSCLR: Event Counter 8 Overflow Clear Position */ +#define PMU_OVSCLR_CNT8_STATUS_Msk (1UL << PMU_OVSCLR_CNT8_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 8 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT9_STATUS_Pos 9U /*!< PMU OVSCLR: Event Counter 9 Overflow Clear Position */ +#define PMU_OVSCLR_CNT9_STATUS_Msk (1UL << PMU_OVSCLR_CNT9_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 9 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT10_STATUS_Pos 10U /*!< PMU OVSCLR: Event Counter 10 Overflow Clear Position */ +#define PMU_OVSCLR_CNT10_STATUS_Msk (1UL << PMU_OVSCLR_CNT10_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 10 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT11_STATUS_Pos 11U /*!< PMU OVSCLR: Event Counter 11 Overflow Clear Position */ +#define PMU_OVSCLR_CNT11_STATUS_Msk (1UL << PMU_OVSCLR_CNT11_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 11 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT12_STATUS_Pos 12U /*!< PMU OVSCLR: Event Counter 12 Overflow Clear Position */ +#define PMU_OVSCLR_CNT12_STATUS_Msk (1UL << PMU_OVSCLR_CNT12_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 12 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT13_STATUS_Pos 13U /*!< PMU OVSCLR: Event Counter 13 Overflow Clear Position */ +#define PMU_OVSCLR_CNT13_STATUS_Msk (1UL << PMU_OVSCLR_CNT13_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 13 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT14_STATUS_Pos 14U /*!< PMU OVSCLR: Event Counter 14 Overflow Clear Position */ +#define PMU_OVSCLR_CNT14_STATUS_Msk (1UL << PMU_OVSCLR_CNT14_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 14 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT15_STATUS_Pos 15U /*!< PMU OVSCLR: Event Counter 15 Overflow Clear Position */ +#define PMU_OVSCLR_CNT15_STATUS_Msk (1UL << PMU_OVSCLR_CNT15_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 15 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT16_STATUS_Pos 16U /*!< PMU OVSCLR: Event Counter 16 Overflow Clear Position */ +#define PMU_OVSCLR_CNT16_STATUS_Msk (1UL << PMU_OVSCLR_CNT16_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 16 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT17_STATUS_Pos 17U /*!< PMU OVSCLR: Event Counter 17 Overflow Clear Position */ +#define PMU_OVSCLR_CNT17_STATUS_Msk (1UL << PMU_OVSCLR_CNT17_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 17 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT18_STATUS_Pos 18U /*!< PMU OVSCLR: Event Counter 18 Overflow Clear Position */ +#define PMU_OVSCLR_CNT18_STATUS_Msk (1UL << PMU_OVSCLR_CNT18_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 18 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT19_STATUS_Pos 19U /*!< PMU OVSCLR: Event Counter 19 Overflow Clear Position */ +#define PMU_OVSCLR_CNT19_STATUS_Msk (1UL << PMU_OVSCLR_CNT19_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 19 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT20_STATUS_Pos 20U /*!< PMU OVSCLR: Event Counter 20 Overflow Clear Position */ +#define PMU_OVSCLR_CNT20_STATUS_Msk (1UL << PMU_OVSCLR_CNT20_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 20 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT21_STATUS_Pos 21U /*!< PMU OVSCLR: Event Counter 21 Overflow Clear Position */ +#define PMU_OVSCLR_CNT21_STATUS_Msk (1UL << PMU_OVSCLR_CNT21_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 21 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT22_STATUS_Pos 22U /*!< PMU OVSCLR: Event Counter 22 Overflow Clear Position */ +#define PMU_OVSCLR_CNT22_STATUS_Msk (1UL << PMU_OVSCLR_CNT22_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 22 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT23_STATUS_Pos 23U /*!< PMU OVSCLR: Event Counter 23 Overflow Clear Position */ +#define PMU_OVSCLR_CNT23_STATUS_Msk (1UL << PMU_OVSCLR_CNT23_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 23 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT24_STATUS_Pos 24U /*!< PMU OVSCLR: Event Counter 24 Overflow Clear Position */ +#define PMU_OVSCLR_CNT24_STATUS_Msk (1UL << PMU_OVSCLR_CNT24_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 24 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT25_STATUS_Pos 25U /*!< PMU OVSCLR: Event Counter 25 Overflow Clear Position */ +#define PMU_OVSCLR_CNT25_STATUS_Msk (1UL << PMU_OVSCLR_CNT25_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 25 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT26_STATUS_Pos 26U /*!< PMU OVSCLR: Event Counter 26 Overflow Clear Position */ +#define PMU_OVSCLR_CNT26_STATUS_Msk (1UL << PMU_OVSCLR_CNT26_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 26 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT27_STATUS_Pos 27U /*!< PMU OVSCLR: Event Counter 27 Overflow Clear Position */ +#define PMU_OVSCLR_CNT27_STATUS_Msk (1UL << PMU_OVSCLR_CNT27_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 27 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT28_STATUS_Pos 28U /*!< PMU OVSCLR: Event Counter 28 Overflow Clear Position */ +#define PMU_OVSCLR_CNT28_STATUS_Msk (1UL << PMU_OVSCLR_CNT28_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 28 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT29_STATUS_Pos 29U /*!< PMU OVSCLR: Event Counter 29 Overflow Clear Position */ +#define PMU_OVSCLR_CNT29_STATUS_Msk (1UL << PMU_OVSCLR_CNT29_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 29 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT30_STATUS_Pos 30U /*!< PMU OVSCLR: Event Counter 30 Overflow Clear Position */ +#define PMU_OVSCLR_CNT30_STATUS_Msk (1UL << PMU_OVSCLR_CNT30_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 30 Overflow Clear Mask */ + +#define PMU_OVSCLR_CYCCNT_STATUS_Pos 31U /*!< PMU OVSCLR: Cycle Counter Overflow Clear Position */ +#define PMU_OVSCLR_CYCCNT_STATUS_Msk (1UL << PMU_OVSCLR_CYCCNT_STATUS_Pos) /*!< PMU OVSCLR: Cycle Counter Overflow Clear Mask */ + +/** \brief PMU Software Increment Counter */ + +#define PMU_SWINC_CNT0_Pos 0U /*!< PMU SWINC: Event Counter 0 Software Increment Position */ +#define PMU_SWINC_CNT0_Msk (1UL /*<< PMU_SWINC_CNT0_Pos */) /*!< PMU SWINC: Event Counter 0 Software Increment Mask */ + +#define PMU_SWINC_CNT1_Pos 1U /*!< PMU SWINC: Event Counter 1 Software Increment Position */ +#define PMU_SWINC_CNT1_Msk (1UL << PMU_SWINC_CNT1_Pos) /*!< PMU SWINC: Event Counter 1 Software Increment Mask */ + +#define PMU_SWINC_CNT2_Pos 2U /*!< PMU SWINC: Event Counter 2 Software Increment Position */ +#define PMU_SWINC_CNT2_Msk (1UL << PMU_SWINC_CNT2_Pos) /*!< PMU SWINC: Event Counter 2 Software Increment Mask */ + +#define PMU_SWINC_CNT3_Pos 3U /*!< PMU SWINC: Event Counter 3 Software Increment Position */ +#define PMU_SWINC_CNT3_Msk (1UL << PMU_SWINC_CNT3_Pos) /*!< PMU SWINC: Event Counter 3 Software Increment Mask */ + +#define PMU_SWINC_CNT4_Pos 4U /*!< PMU SWINC: Event Counter 4 Software Increment Position */ +#define PMU_SWINC_CNT4_Msk (1UL << PMU_SWINC_CNT4_Pos) /*!< PMU SWINC: Event Counter 4 Software Increment Mask */ + +#define PMU_SWINC_CNT5_Pos 5U /*!< PMU SWINC: Event Counter 5 Software Increment Position */ +#define PMU_SWINC_CNT5_Msk (1UL << PMU_SWINC_CNT5_Pos) /*!< PMU SWINC: Event Counter 5 Software Increment Mask */ + +#define PMU_SWINC_CNT6_Pos 6U /*!< PMU SWINC: Event Counter 6 Software Increment Position */ +#define PMU_SWINC_CNT6_Msk (1UL << PMU_SWINC_CNT6_Pos) /*!< PMU SWINC: Event Counter 6 Software Increment Mask */ + +#define PMU_SWINC_CNT7_Pos 7U /*!< PMU SWINC: Event Counter 7 Software Increment Position */ +#define PMU_SWINC_CNT7_Msk (1UL << PMU_SWINC_CNT7_Pos) /*!< PMU SWINC: Event Counter 7 Software Increment Mask */ + +#define PMU_SWINC_CNT8_Pos 8U /*!< PMU SWINC: Event Counter 8 Software Increment Position */ +#define PMU_SWINC_CNT8_Msk (1UL << PMU_SWINC_CNT8_Pos) /*!< PMU SWINC: Event Counter 8 Software Increment Mask */ + +#define PMU_SWINC_CNT9_Pos 9U /*!< PMU SWINC: Event Counter 9 Software Increment Position */ +#define PMU_SWINC_CNT9_Msk (1UL << PMU_SWINC_CNT9_Pos) /*!< PMU SWINC: Event Counter 9 Software Increment Mask */ + +#define PMU_SWINC_CNT10_Pos 10U /*!< PMU SWINC: Event Counter 10 Software Increment Position */ +#define PMU_SWINC_CNT10_Msk (1UL << PMU_SWINC_CNT10_Pos) /*!< PMU SWINC: Event Counter 10 Software Increment Mask */ + +#define PMU_SWINC_CNT11_Pos 11U /*!< PMU SWINC: Event Counter 11 Software Increment Position */ +#define PMU_SWINC_CNT11_Msk (1UL << PMU_SWINC_CNT11_Pos) /*!< PMU SWINC: Event Counter 11 Software Increment Mask */ + +#define PMU_SWINC_CNT12_Pos 12U /*!< PMU SWINC: Event Counter 12 Software Increment Position */ +#define PMU_SWINC_CNT12_Msk (1UL << PMU_SWINC_CNT12_Pos) /*!< PMU SWINC: Event Counter 12 Software Increment Mask */ + +#define PMU_SWINC_CNT13_Pos 13U /*!< PMU SWINC: Event Counter 13 Software Increment Position */ +#define PMU_SWINC_CNT13_Msk (1UL << PMU_SWINC_CNT13_Pos) /*!< PMU SWINC: Event Counter 13 Software Increment Mask */ + +#define PMU_SWINC_CNT14_Pos 14U /*!< PMU SWINC: Event Counter 14 Software Increment Position */ +#define PMU_SWINC_CNT14_Msk (1UL << PMU_SWINC_CNT14_Pos) /*!< PMU SWINC: Event Counter 14 Software Increment Mask */ + +#define PMU_SWINC_CNT15_Pos 15U /*!< PMU SWINC: Event Counter 15 Software Increment Position */ +#define PMU_SWINC_CNT15_Msk (1UL << PMU_SWINC_CNT15_Pos) /*!< PMU SWINC: Event Counter 15 Software Increment Mask */ + +#define PMU_SWINC_CNT16_Pos 16U /*!< PMU SWINC: Event Counter 16 Software Increment Position */ +#define PMU_SWINC_CNT16_Msk (1UL << PMU_SWINC_CNT16_Pos) /*!< PMU SWINC: Event Counter 16 Software Increment Mask */ + +#define PMU_SWINC_CNT17_Pos 17U /*!< PMU SWINC: Event Counter 17 Software Increment Position */ +#define PMU_SWINC_CNT17_Msk (1UL << PMU_SWINC_CNT17_Pos) /*!< PMU SWINC: Event Counter 17 Software Increment Mask */ + +#define PMU_SWINC_CNT18_Pos 18U /*!< PMU SWINC: Event Counter 18 Software Increment Position */ +#define PMU_SWINC_CNT18_Msk (1UL << PMU_SWINC_CNT18_Pos) /*!< PMU SWINC: Event Counter 18 Software Increment Mask */ + +#define PMU_SWINC_CNT19_Pos 19U /*!< PMU SWINC: Event Counter 19 Software Increment Position */ +#define PMU_SWINC_CNT19_Msk (1UL << PMU_SWINC_CNT19_Pos) /*!< PMU SWINC: Event Counter 19 Software Increment Mask */ + +#define PMU_SWINC_CNT20_Pos 20U /*!< PMU SWINC: Event Counter 20 Software Increment Position */ +#define PMU_SWINC_CNT20_Msk (1UL << PMU_SWINC_CNT20_Pos) /*!< PMU SWINC: Event Counter 20 Software Increment Mask */ + +#define PMU_SWINC_CNT21_Pos 21U /*!< PMU SWINC: Event Counter 21 Software Increment Position */ +#define PMU_SWINC_CNT21_Msk (1UL << PMU_SWINC_CNT21_Pos) /*!< PMU SWINC: Event Counter 21 Software Increment Mask */ + +#define PMU_SWINC_CNT22_Pos 22U /*!< PMU SWINC: Event Counter 22 Software Increment Position */ +#define PMU_SWINC_CNT22_Msk (1UL << PMU_SWINC_CNT22_Pos) /*!< PMU SWINC: Event Counter 22 Software Increment Mask */ + +#define PMU_SWINC_CNT23_Pos 23U /*!< PMU SWINC: Event Counter 23 Software Increment Position */ +#define PMU_SWINC_CNT23_Msk (1UL << PMU_SWINC_CNT23_Pos) /*!< PMU SWINC: Event Counter 23 Software Increment Mask */ + +#define PMU_SWINC_CNT24_Pos 24U /*!< PMU SWINC: Event Counter 24 Software Increment Position */ +#define PMU_SWINC_CNT24_Msk (1UL << PMU_SWINC_CNT24_Pos) /*!< PMU SWINC: Event Counter 24 Software Increment Mask */ + +#define PMU_SWINC_CNT25_Pos 25U /*!< PMU SWINC: Event Counter 25 Software Increment Position */ +#define PMU_SWINC_CNT25_Msk (1UL << PMU_SWINC_CNT25_Pos) /*!< PMU SWINC: Event Counter 25 Software Increment Mask */ + +#define PMU_SWINC_CNT26_Pos 26U /*!< PMU SWINC: Event Counter 26 Software Increment Position */ +#define PMU_SWINC_CNT26_Msk (1UL << PMU_SWINC_CNT26_Pos) /*!< PMU SWINC: Event Counter 26 Software Increment Mask */ + +#define PMU_SWINC_CNT27_Pos 27U /*!< PMU SWINC: Event Counter 27 Software Increment Position */ +#define PMU_SWINC_CNT27_Msk (1UL << PMU_SWINC_CNT27_Pos) /*!< PMU SWINC: Event Counter 27 Software Increment Mask */ + +#define PMU_SWINC_CNT28_Pos 28U /*!< PMU SWINC: Event Counter 28 Software Increment Position */ +#define PMU_SWINC_CNT28_Msk (1UL << PMU_SWINC_CNT28_Pos) /*!< PMU SWINC: Event Counter 28 Software Increment Mask */ + +#define PMU_SWINC_CNT29_Pos 29U /*!< PMU SWINC: Event Counter 29 Software Increment Position */ +#define PMU_SWINC_CNT29_Msk (1UL << PMU_SWINC_CNT29_Pos) /*!< PMU SWINC: Event Counter 29 Software Increment Mask */ + +#define PMU_SWINC_CNT30_Pos 30U /*!< PMU SWINC: Event Counter 30 Software Increment Position */ +#define PMU_SWINC_CNT30_Msk (1UL << PMU_SWINC_CNT30_Pos) /*!< PMU SWINC: Event Counter 30 Software Increment Mask */ + +/** \brief PMU Control Register Definitions */ + +#define PMU_CTRL_ENABLE_Pos 0U /*!< PMU CTRL: ENABLE Position */ +#define PMU_CTRL_ENABLE_Msk (1UL /*<< PMU_CTRL_ENABLE_Pos*/) /*!< PMU CTRL: ENABLE Mask */ + +#define PMU_CTRL_EVENTCNT_RESET_Pos 1U /*!< PMU CTRL: Event Counter Reset Position */ +#define PMU_CTRL_EVENTCNT_RESET_Msk (1UL << PMU_CTRL_EVENTCNT_RESET_Pos) /*!< PMU CTRL: Event Counter Reset Mask */ + +#define PMU_CTRL_CYCCNT_RESET_Pos 2U /*!< PMU CTRL: Cycle Counter Reset Position */ +#define PMU_CTRL_CYCCNT_RESET_Msk (1UL << PMU_CTRL_CYCCNT_RESET_Pos) /*!< PMU CTRL: Cycle Counter Reset Mask */ + +#define PMU_CTRL_CYCCNT_DISABLE_Pos 5U /*!< PMU CTRL: Disable Cycle Counter Position */ +#define PMU_CTRL_CYCCNT_DISABLE_Msk (1UL << PMU_CTRL_CYCCNT_DISABLE_Pos) /*!< PMU CTRL: Disable Cycle Counter Mask */ + +#define PMU_CTRL_FRZ_ON_OV_Pos 9U /*!< PMU CTRL: Freeze-on-overflow Position */ +#define PMU_CTRL_FRZ_ON_OV_Msk (1UL << PMU_CTRL_FRZ_ON_OVERFLOW_Pos) /*!< PMU CTRL: Freeze-on-overflow Mask */ + +#define PMU_CTRL_TRACE_ON_OV_Pos 11U /*!< PMU CTRL: Trace-on-overflow Position */ +#define PMU_CTRL_TRACE_ON_OV_Msk (1UL << PMU_CTRL_TRACE_ON_OVERFLOW_Pos) /*!< PMU CTRL: Trace-on-overflow Mask */ + +/** \brief PMU Type Register Definitions */ + +#define PMU_TYPE_NUM_CNTS_Pos 0U /*!< PMU TYPE: Number of Counters Position */ +#define PMU_TYPE_NUM_CNTS_Msk (0xFFUL /*<< PMU_TYPE_NUM_CNTS_Pos*/) /*!< PMU TYPE: Number of Counters Mask */ + +#define PMU_TYPE_SIZE_CNTS_Pos 8U /*!< PMU TYPE: Size of Counters Position */ +#define PMU_TYPE_SIZE_CNTS_Msk (0x3FUL << PMU_TYPE_SIZE_CNTS_Pos) /*!< PMU TYPE: Size of Counters Mask */ + +#define PMU_TYPE_CYCCNT_PRESENT_Pos 14U /*!< PMU TYPE: Cycle Counter Present Position */ +#define PMU_TYPE_CYCCNT_PRESENT_Msk (1UL << PMU_TYPE_CYCCNT_PRESENT_Pos) /*!< PMU TYPE: Cycle Counter Present Mask */ + +#define PMU_TYPE_FRZ_OV_SUPPORT_Pos 21U /*!< PMU TYPE: Freeze-on-overflow Support Position */ +#define PMU_TYPE_FRZ_OV_SUPPORT_Msk (1UL << PMU_TYPE_FRZ_OV_SUPPORT_Pos) /*!< PMU TYPE: Freeze-on-overflow Support Mask */ + +#define PMU_TYPE_TRACE_ON_OV_SUPPORT_Pos 23U /*!< PMU TYPE: Trace-on-overflow Support Position */ +#define PMU_TYPE_TRACE_ON_OV_SUPPORT_Msk (1UL << PMU_TYPE_FRZ_OV_SUPPORT_Pos) /*!< PMU TYPE: Trace-on-overflow Support Mask */ + +/** \brief PMU Authentication Status Register Definitions */ + +#define PMU_AUTHSTATUS_NSID_Pos 0U /*!< PMU AUTHSTATUS: Non-secure Invasive Debug Position */ +#define PMU_AUTHSTATUS_NSID_Msk (0x3UL /*<< PMU_AUTHSTATUS_NSID_Pos*/) /*!< PMU AUTHSTATUS: Non-secure Invasive Debug Mask */ + +#define PMU_AUTHSTATUS_NSNID_Pos 2U /*!< PMU AUTHSTATUS: Non-secure Non-invasive Debug Position */ +#define PMU_AUTHSTATUS_NSNID_Msk (0x3UL << PMU_AUTHSTATUS_NSNID_Pos) /*!< PMU AUTHSTATUS: Non-secure Non-invasive Debug Mask */ + +#define PMU_AUTHSTATUS_SID_Pos 4U /*!< PMU AUTHSTATUS: Secure Invasive Debug Position */ +#define PMU_AUTHSTATUS_SID_Msk (0x3UL << PMU_AUTHSTATUS_SID_Pos) /*!< PMU AUTHSTATUS: Secure Invasive Debug Mask */ + +#define PMU_AUTHSTATUS_SNID_Pos 6U /*!< PMU AUTHSTATUS: Secure Non-invasive Debug Position */ +#define PMU_AUTHSTATUS_SNID_Msk (0x3UL << PMU_AUTHSTATUS_SNID_Pos) /*!< PMU AUTHSTATUS: Secure Non-invasive Debug Mask */ + +#define PMU_AUTHSTATUS_NSUID_Pos 16U /*!< PMU AUTHSTATUS: Non-secure Unprivileged Invasive Debug Position */ +#define PMU_AUTHSTATUS_NSUID_Msk (0x3UL << PMU_AUTHSTATUS_NSUID_Pos) /*!< PMU AUTHSTATUS: Non-secure Unprivileged Invasive Debug Mask */ + +#define PMU_AUTHSTATUS_NSUNID_Pos 18U /*!< PMU AUTHSTATUS: Non-secure Unprivileged Non-invasive Debug Position */ +#define PMU_AUTHSTATUS_NSUNID_Msk (0x3UL << PMU_AUTHSTATUS_NSUNID_Pos) /*!< PMU AUTHSTATUS: Non-secure Unprivileged Non-invasive Debug Mask */ + +#define PMU_AUTHSTATUS_SUID_Pos 20U /*!< PMU AUTHSTATUS: Secure Unprivileged Invasive Debug Position */ +#define PMU_AUTHSTATUS_SUID_Msk (0x3UL << PMU_AUTHSTATUS_SUID_Pos) /*!< PMU AUTHSTATUS: Secure Unprivileged Invasive Debug Mask */ + +#define PMU_AUTHSTATUS_SUNID_Pos 22U /*!< PMU AUTHSTATUS: Secure Unprivileged Non-invasive Debug Position */ +#define PMU_AUTHSTATUS_SUNID_Msk (0x3UL << PMU_AUTHSTATUS_SUNID_Pos) /*!< PMU AUTHSTATUS: Secure Unprivileged Non-invasive Debug Mask */ + +/*@} end of group CMSIS_PMU */ +#endif + +#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_MPU Memory Protection Unit (MPU) + \brief Type definitions for the Memory Protection Unit (MPU) + @{ + */ + +/** + \brief Structure type to access the Memory Protection Unit (MPU). + */ +typedef struct +{ + __IM uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */ + __IOM uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */ + __IOM uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region Number Register */ + __IOM uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */ + __IOM uint32_t RLAR; /*!< Offset: 0x010 (R/W) MPU Region Limit Address Register */ + __IOM uint32_t RBAR_A1; /*!< Offset: 0x014 (R/W) MPU Region Base Address Register Alias 1 */ + __IOM uint32_t RLAR_A1; /*!< Offset: 0x018 (R/W) MPU Region Limit Address Register Alias 1 */ + __IOM uint32_t RBAR_A2; /*!< Offset: 0x01C (R/W) MPU Region Base Address Register Alias 2 */ + __IOM uint32_t RLAR_A2; /*!< Offset: 0x020 (R/W) MPU Region Limit Address Register Alias 2 */ + __IOM uint32_t RBAR_A3; /*!< Offset: 0x024 (R/W) MPU Region Base Address Register Alias 3 */ + __IOM uint32_t RLAR_A3; /*!< Offset: 0x028 (R/W) MPU Region Limit Address Register Alias 3 */ + uint32_t RESERVED0[1]; + union { + __IOM uint32_t MAIR[2]; + struct { + __IOM uint32_t MAIR0; /*!< Offset: 0x030 (R/W) MPU Memory Attribute Indirection Register 0 */ + __IOM uint32_t MAIR1; /*!< Offset: 0x034 (R/W) MPU Memory Attribute Indirection Register 1 */ + }; + }; +} MPU_Type; + +#define MPU_TYPE_RALIASES 4U + +/* MPU Type Register Definitions */ +#define MPU_TYPE_IREGION_Pos 16U /*!< MPU TYPE: IREGION Position */ +#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */ + +#define MPU_TYPE_DREGION_Pos 8U /*!< MPU TYPE: DREGION Position */ +#define MPU_TYPE_DREGION_Msk (0xFFUL << MPU_TYPE_DREGION_Pos) /*!< MPU TYPE: DREGION Mask */ + +#define MPU_TYPE_SEPARATE_Pos 0U /*!< MPU TYPE: SEPARATE Position */ +#define MPU_TYPE_SEPARATE_Msk (1UL /*<< MPU_TYPE_SEPARATE_Pos*/) /*!< MPU TYPE: SEPARATE Mask */ + +/* MPU Control Register Definitions */ +#define MPU_CTRL_PRIVDEFENA_Pos 2U /*!< MPU CTRL: PRIVDEFENA Position */ +#define MPU_CTRL_PRIVDEFENA_Msk (1UL << MPU_CTRL_PRIVDEFENA_Pos) /*!< MPU CTRL: PRIVDEFENA Mask */ + +#define MPU_CTRL_HFNMIENA_Pos 1U /*!< MPU CTRL: HFNMIENA Position */ +#define MPU_CTRL_HFNMIENA_Msk (1UL << MPU_CTRL_HFNMIENA_Pos) /*!< MPU CTRL: HFNMIENA Mask */ + +#define MPU_CTRL_ENABLE_Pos 0U /*!< MPU CTRL: ENABLE Position */ +#define MPU_CTRL_ENABLE_Msk (1UL /*<< MPU_CTRL_ENABLE_Pos*/) /*!< MPU CTRL: ENABLE Mask */ + +/* MPU Region Number Register Definitions */ +#define MPU_RNR_REGION_Pos 0U /*!< MPU RNR: REGION Position */ +#define MPU_RNR_REGION_Msk (0xFFUL /*<< MPU_RNR_REGION_Pos*/) /*!< MPU RNR: REGION Mask */ + +/* MPU Region Base Address Register Definitions */ +#define MPU_RBAR_BASE_Pos 5U /*!< MPU RBAR: BASE Position */ +#define MPU_RBAR_BASE_Msk (0x7FFFFFFUL << MPU_RBAR_BASE_Pos) /*!< MPU RBAR: BASE Mask */ + +#define MPU_RBAR_SH_Pos 3U /*!< MPU RBAR: SH Position */ +#define MPU_RBAR_SH_Msk (0x3UL << MPU_RBAR_SH_Pos) /*!< MPU RBAR: SH Mask */ + +#define MPU_RBAR_AP_Pos 1U /*!< MPU RBAR: AP Position */ +#define MPU_RBAR_AP_Msk (0x3UL << MPU_RBAR_AP_Pos) /*!< MPU RBAR: AP Mask */ + +#define MPU_RBAR_XN_Pos 0U /*!< MPU RBAR: XN Position */ +#define MPU_RBAR_XN_Msk (01UL /*<< MPU_RBAR_XN_Pos*/) /*!< MPU RBAR: XN Mask */ + +/* MPU Region Limit Address Register Definitions */ +#define MPU_RLAR_LIMIT_Pos 5U /*!< MPU RLAR: LIMIT Position */ +#define MPU_RLAR_LIMIT_Msk (0x7FFFFFFUL << MPU_RLAR_LIMIT_Pos) /*!< MPU RLAR: LIMIT Mask */ + +#define MPU_RLAR_PXN_Pos 4U /*!< MPU RLAR: PXN Position */ +#define MPU_RLAR_PXN_Msk (1UL << MPU_RLAR_PXN_Pos) /*!< MPU RLAR: PXN Mask */ + +#define MPU_RLAR_AttrIndx_Pos 1U /*!< MPU RLAR: AttrIndx Position */ +#define MPU_RLAR_AttrIndx_Msk (7UL << MPU_RLAR_AttrIndx_Pos) /*!< MPU RLAR: AttrIndx Mask */ + +#define MPU_RLAR_EN_Pos 0U /*!< MPU RLAR: Region enable bit Position */ +#define MPU_RLAR_EN_Msk (1UL /*<< MPU_RLAR_EN_Pos*/) /*!< MPU RLAR: Region enable bit Disable Mask */ + +/* MPU Memory Attribute Indirection Register 0 Definitions */ +#define MPU_MAIR0_Attr3_Pos 24U /*!< MPU MAIR0: Attr3 Position */ +#define MPU_MAIR0_Attr3_Msk (0xFFUL << MPU_MAIR0_Attr3_Pos) /*!< MPU MAIR0: Attr3 Mask */ + +#define MPU_MAIR0_Attr2_Pos 16U /*!< MPU MAIR0: Attr2 Position */ +#define MPU_MAIR0_Attr2_Msk (0xFFUL << MPU_MAIR0_Attr2_Pos) /*!< MPU MAIR0: Attr2 Mask */ + +#define MPU_MAIR0_Attr1_Pos 8U /*!< MPU MAIR0: Attr1 Position */ +#define MPU_MAIR0_Attr1_Msk (0xFFUL << MPU_MAIR0_Attr1_Pos) /*!< MPU MAIR0: Attr1 Mask */ + +#define MPU_MAIR0_Attr0_Pos 0U /*!< MPU MAIR0: Attr0 Position */ +#define MPU_MAIR0_Attr0_Msk (0xFFUL /*<< MPU_MAIR0_Attr0_Pos*/) /*!< MPU MAIR0: Attr0 Mask */ + +/* MPU Memory Attribute Indirection Register 1 Definitions */ +#define MPU_MAIR1_Attr7_Pos 24U /*!< MPU MAIR1: Attr7 Position */ +#define MPU_MAIR1_Attr7_Msk (0xFFUL << MPU_MAIR1_Attr7_Pos) /*!< MPU MAIR1: Attr7 Mask */ + +#define MPU_MAIR1_Attr6_Pos 16U /*!< MPU MAIR1: Attr6 Position */ +#define MPU_MAIR1_Attr6_Msk (0xFFUL << MPU_MAIR1_Attr6_Pos) /*!< MPU MAIR1: Attr6 Mask */ + +#define MPU_MAIR1_Attr5_Pos 8U /*!< MPU MAIR1: Attr5 Position */ +#define MPU_MAIR1_Attr5_Msk (0xFFUL << MPU_MAIR1_Attr5_Pos) /*!< MPU MAIR1: Attr5 Mask */ + +#define MPU_MAIR1_Attr4_Pos 0U /*!< MPU MAIR1: Attr4 Position */ +#define MPU_MAIR1_Attr4_Msk (0xFFUL /*<< MPU_MAIR1_Attr4_Pos*/) /*!< MPU MAIR1: Attr4 Mask */ + +/*@} end of group CMSIS_MPU */ +#endif + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_SAU Security Attribution Unit (SAU) + \brief Type definitions for the Security Attribution Unit (SAU) + @{ + */ + +/** + \brief Structure type to access the Security Attribution Unit (SAU). + */ +typedef struct +{ + __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) SAU Control Register */ + __IM uint32_t TYPE; /*!< Offset: 0x004 (R/ ) SAU Type Register */ +#if defined (__SAUREGION_PRESENT) && (__SAUREGION_PRESENT == 1U) + __IOM uint32_t RNR; /*!< Offset: 0x008 (R/W) SAU Region Number Register */ + __IOM uint32_t RBAR; /*!< Offset: 0x00C (R/W) SAU Region Base Address Register */ + __IOM uint32_t RLAR; /*!< Offset: 0x010 (R/W) SAU Region Limit Address Register */ +#else + uint32_t RESERVED0[3]; +#endif + __IOM uint32_t SFSR; /*!< Offset: 0x014 (R/W) Secure Fault Status Register */ + __IOM uint32_t SFAR; /*!< Offset: 0x018 (R/W) Secure Fault Address Register */ +} SAU_Type; + +/* SAU Control Register Definitions */ +#define SAU_CTRL_ALLNS_Pos 1U /*!< SAU CTRL: ALLNS Position */ +#define SAU_CTRL_ALLNS_Msk (1UL << SAU_CTRL_ALLNS_Pos) /*!< SAU CTRL: ALLNS Mask */ + +#define SAU_CTRL_ENABLE_Pos 0U /*!< SAU CTRL: ENABLE Position */ +#define SAU_CTRL_ENABLE_Msk (1UL /*<< SAU_CTRL_ENABLE_Pos*/) /*!< SAU CTRL: ENABLE Mask */ + +/* SAU Type Register Definitions */ +#define SAU_TYPE_SREGION_Pos 0U /*!< SAU TYPE: SREGION Position */ +#define SAU_TYPE_SREGION_Msk (0xFFUL /*<< SAU_TYPE_SREGION_Pos*/) /*!< SAU TYPE: SREGION Mask */ + +#if defined (__SAUREGION_PRESENT) && (__SAUREGION_PRESENT == 1U) +/* SAU Region Number Register Definitions */ +#define SAU_RNR_REGION_Pos 0U /*!< SAU RNR: REGION Position */ +#define SAU_RNR_REGION_Msk (0xFFUL /*<< SAU_RNR_REGION_Pos*/) /*!< SAU RNR: REGION Mask */ + +/* SAU Region Base Address Register Definitions */ +#define SAU_RBAR_BADDR_Pos 5U /*!< SAU RBAR: BADDR Position */ +#define SAU_RBAR_BADDR_Msk (0x7FFFFFFUL << SAU_RBAR_BADDR_Pos) /*!< SAU RBAR: BADDR Mask */ + +/* SAU Region Limit Address Register Definitions */ +#define SAU_RLAR_LADDR_Pos 5U /*!< SAU RLAR: LADDR Position */ +#define SAU_RLAR_LADDR_Msk (0x7FFFFFFUL << SAU_RLAR_LADDR_Pos) /*!< SAU RLAR: LADDR Mask */ + +#define SAU_RLAR_NSC_Pos 1U /*!< SAU RLAR: NSC Position */ +#define SAU_RLAR_NSC_Msk (1UL << SAU_RLAR_NSC_Pos) /*!< SAU RLAR: NSC Mask */ + +#define SAU_RLAR_ENABLE_Pos 0U /*!< SAU RLAR: ENABLE Position */ +#define SAU_RLAR_ENABLE_Msk (1UL /*<< SAU_RLAR_ENABLE_Pos*/) /*!< SAU RLAR: ENABLE Mask */ + +#endif /* defined (__SAUREGION_PRESENT) && (__SAUREGION_PRESENT == 1U) */ + +/* Secure Fault Status Register Definitions */ +#define SAU_SFSR_LSERR_Pos 7U /*!< SAU SFSR: LSERR Position */ +#define SAU_SFSR_LSERR_Msk (1UL << SAU_SFSR_LSERR_Pos) /*!< SAU SFSR: LSERR Mask */ + +#define SAU_SFSR_SFARVALID_Pos 6U /*!< SAU SFSR: SFARVALID Position */ +#define SAU_SFSR_SFARVALID_Msk (1UL << SAU_SFSR_SFARVALID_Pos) /*!< SAU SFSR: SFARVALID Mask */ + +#define SAU_SFSR_LSPERR_Pos 5U /*!< SAU SFSR: LSPERR Position */ +#define SAU_SFSR_LSPERR_Msk (1UL << SAU_SFSR_LSPERR_Pos) /*!< SAU SFSR: LSPERR Mask */ + +#define SAU_SFSR_INVTRAN_Pos 4U /*!< SAU SFSR: INVTRAN Position */ +#define SAU_SFSR_INVTRAN_Msk (1UL << SAU_SFSR_INVTRAN_Pos) /*!< SAU SFSR: INVTRAN Mask */ + +#define SAU_SFSR_AUVIOL_Pos 3U /*!< SAU SFSR: AUVIOL Position */ +#define SAU_SFSR_AUVIOL_Msk (1UL << SAU_SFSR_AUVIOL_Pos) /*!< SAU SFSR: AUVIOL Mask */ + +#define SAU_SFSR_INVER_Pos 2U /*!< SAU SFSR: INVER Position */ +#define SAU_SFSR_INVER_Msk (1UL << SAU_SFSR_INVER_Pos) /*!< SAU SFSR: INVER Mask */ + +#define SAU_SFSR_INVIS_Pos 1U /*!< SAU SFSR: INVIS Position */ +#define SAU_SFSR_INVIS_Msk (1UL << SAU_SFSR_INVIS_Pos) /*!< SAU SFSR: INVIS Mask */ + +#define SAU_SFSR_INVEP_Pos 0U /*!< SAU SFSR: INVEP Position */ +#define SAU_SFSR_INVEP_Msk (1UL /*<< SAU_SFSR_INVEP_Pos*/) /*!< SAU SFSR: INVEP Mask */ + +/*@} end of group CMSIS_SAU */ +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_FPU Floating Point Unit (FPU) + \brief Type definitions for the Floating Point Unit (FPU) + @{ + */ + +/** + \brief Structure type to access the Floating Point Unit (FPU). */ typedef struct { @@ -1749,8 +2485,9 @@ typedef struct __IOM uint32_t FPCCR; /*!< Offset: 0x004 (R/W) Floating-Point Context Control Register */ __IOM uint32_t FPCAR; /*!< Offset: 0x008 (R/W) Floating-Point Context Address Register */ __IOM uint32_t FPDSCR; /*!< Offset: 0x00C (R/W) Floating-Point Default Status Control Register */ - __IM uint32_t MVFR0; /*!< Offset: 0x010 (R/ ) Media and FP Feature Register 0 */ - __IM uint32_t MVFR1; /*!< Offset: 0x014 (R/ ) Media and FP Feature Register 1 */ + __IM uint32_t MVFR0; /*!< Offset: 0x010 (R/ ) Media and VFP Feature Register 0 */ + __IM uint32_t MVFR1; /*!< Offset: 0x014 (R/ ) Media and VFP Feature Register 1 */ + __IM uint32_t MVFR2; /*!< Offset: 0x018 (R/ ) Media and VFP Feature Register 2 */ } FPU_Type; /* Floating-Point Context Control Register Definitions */ @@ -1822,47 +2559,57 @@ typedef struct #define FPU_FPDSCR_RMode_Pos 22U /*!< FPDSCR: RMode bit Position */ #define FPU_FPDSCR_RMode_Msk (3UL << FPU_FPDSCR_RMode_Pos) /*!< FPDSCR: RMode bit Mask */ -/* Media and FP Feature Register 0 Definitions */ -#define FPU_MVFR0_FP_rounding_modes_Pos 28U /*!< MVFR0: FP rounding modes bits Position */ -#define FPU_MVFR0_FP_rounding_modes_Msk (0xFUL << FPU_MVFR0_FP_rounding_modes_Pos) /*!< MVFR0: FP rounding modes bits Mask */ +#define FPU_FPDSCR_FZ16_Pos 19U /*!< FPDSCR: FZ16 bit Position */ +#define FPU_FPDSCR_FZ16_Msk (1UL << FPU_FPDSCR_FZ16_Pos) /*!< FPDSCR: FZ16 bit Mask */ -#define FPU_MVFR0_Short_vectors_Pos 24U /*!< MVFR0: Short vectors bits Position */ -#define FPU_MVFR0_Short_vectors_Msk (0xFUL << FPU_MVFR0_Short_vectors_Pos) /*!< MVFR0: Short vectors bits Mask */ +#define FPU_FPDSCR_LTPSIZE_Pos 16U /*!< FPDSCR: LTPSIZE bit Position */ +#define FPU_FPDSCR_LTPSIZE_Msk (7UL << FPU_FPDSCR_LTPSIZE_Pos) /*!< FPDSCR: LTPSIZE bit Mask */ -#define FPU_MVFR0_Square_root_Pos 20U /*!< MVFR0: Square root bits Position */ -#define FPU_MVFR0_Square_root_Msk (0xFUL << FPU_MVFR0_Square_root_Pos) /*!< MVFR0: Square root bits Mask */ +/* Media and VFP Feature Register 0 Definitions */ +#define FPU_MVFR0_FPRound_Pos 28U /*!< MVFR0: FPRound bits Position */ +#define FPU_MVFR0_FPRound_Msk (0xFUL << FPU_MVFR0_FPRound_Pos) /*!< MVFR0: FPRound bits Mask */ -#define FPU_MVFR0_Divide_Pos 16U /*!< MVFR0: Divide bits Position */ -#define FPU_MVFR0_Divide_Msk (0xFUL << FPU_MVFR0_Divide_Pos) /*!< MVFR0: Divide bits Mask */ +#define FPU_MVFR0_FPSqrt_Pos 20U /*!< MVFR0: FPSqrt bits Position */ +#define FPU_MVFR0_FPSqrt_Msk (0xFUL << FPU_MVFR0_FPSqrt_Pos) /*!< MVFR0: FPSqrt bits Mask */ -#define FPU_MVFR0_FP_excep_trapping_Pos 12U /*!< MVFR0: FP exception trapping bits Position */ -#define FPU_MVFR0_FP_excep_trapping_Msk (0xFUL << FPU_MVFR0_FP_excep_trapping_Pos) /*!< MVFR0: FP exception trapping bits Mask */ +#define FPU_MVFR0_FPDivide_Pos 16U /*!< MVFR0: FPDivide bits Position */ +#define FPU_MVFR0_FPDivide_Msk (0xFUL << FPU_MVFR0_FPDivide_Pos) /*!< MVFR0: Divide bits Mask */ -#define FPU_MVFR0_Double_precision_Pos 8U /*!< MVFR0: Double-precision bits Position */ -#define FPU_MVFR0_Double_precision_Msk (0xFUL << FPU_MVFR0_Double_precision_Pos) /*!< MVFR0: Double-precision bits Mask */ +#define FPU_MVFR0_FPDP_Pos 8U /*!< MVFR0: FPDP bits Position */ +#define FPU_MVFR0_FPDP_Msk (0xFUL << FPU_MVFR0_FPDP_Pos) /*!< MVFR0: FPDP bits Mask */ -#define FPU_MVFR0_Single_precision_Pos 4U /*!< MVFR0: Single-precision bits Position */ -#define FPU_MVFR0_Single_precision_Msk (0xFUL << FPU_MVFR0_Single_precision_Pos) /*!< MVFR0: Single-precision bits Mask */ +#define FPU_MVFR0_FPSP_Pos 4U /*!< MVFR0: FPSP bits Position */ +#define FPU_MVFR0_FPSP_Msk (0xFUL << FPU_MVFR0_FPSP_Pos) /*!< MVFR0: FPSP bits Mask */ -#define FPU_MVFR0_A_SIMD_registers_Pos 0U /*!< MVFR0: A_SIMD registers bits Position */ -#define FPU_MVFR0_A_SIMD_registers_Msk (0xFUL /*<< FPU_MVFR0_A_SIMD_registers_Pos*/) /*!< MVFR0: A_SIMD registers bits Mask */ +#define FPU_MVFR0_SIMDReg_Pos 0U /*!< MVFR0: SIMDReg bits Position */ +#define FPU_MVFR0_SIMDReg_Msk (0xFUL /*<< FPU_MVFR0_SIMDReg_Pos*/) /*!< MVFR0: SIMDReg bits Mask */ -/* Media and FP Feature Register 1 Definitions */ -#define FPU_MVFR1_FP_fused_MAC_Pos 28U /*!< MVFR1: FP fused MAC bits Position */ -#define FPU_MVFR1_FP_fused_MAC_Msk (0xFUL << FPU_MVFR1_FP_fused_MAC_Pos) /*!< MVFR1: FP fused MAC bits Mask */ +/* Media and VFP Feature Register 1 Definitions */ +#define FPU_MVFR1_FMAC_Pos 28U /*!< MVFR1: FMAC bits Position */ +#define FPU_MVFR1_FMAC_Msk (0xFUL << FPU_MVFR1_FMAC_Pos) /*!< MVFR1: FMAC bits Mask */ -#define FPU_MVFR1_FP_HPFP_Pos 24U /*!< MVFR1: FP HPFP bits Position */ -#define FPU_MVFR1_FP_HPFP_Msk (0xFUL << FPU_MVFR1_FP_HPFP_Pos) /*!< MVFR1: FP HPFP bits Mask */ +#define FPU_MVFR1_FPHP_Pos 24U /*!< MVFR1: FPHP bits Position */ +#define FPU_MVFR1_FPHP_Msk (0xFUL << FPU_MVFR1_FPHP_Pos) /*!< MVFR1: FPHP bits Mask */ -#define FPU_MVFR1_D_NaN_mode_Pos 4U /*!< MVFR1: D_NaN mode bits Position */ -#define FPU_MVFR1_D_NaN_mode_Msk (0xFUL << FPU_MVFR1_D_NaN_mode_Pos) /*!< MVFR1: D_NaN mode bits Mask */ +#define FPU_MVFR1_FP16_Pos 20U /*!< MVFR1: FP16 bits Position */ +#define FPU_MVFR1_FP16_Msk (0xFUL << FPU_MVFR1_FP16_Pos) /*!< MVFR1: FP16 bits Mask */ -#define FPU_MVFR1_FtZ_mode_Pos 0U /*!< MVFR1: FtZ mode bits Position */ -#define FPU_MVFR1_FtZ_mode_Msk (0xFUL /*<< FPU_MVFR1_FtZ_mode_Pos*/) /*!< MVFR1: FtZ mode bits Mask */ +#define FPU_MVFR1_MVE_Pos 8U /*!< MVFR1: MVE bits Position */ +#define FPU_MVFR1_MVE_Msk (0xFUL << FPU_MVFR1_MVE_Pos) /*!< MVFR1: MVE bits Mask */ -/*@} end of group CMSIS_FPU */ +#define FPU_MVFR1_FPDNaN_Pos 4U /*!< MVFR1: FPDNaN bits Position */ +#define FPU_MVFR1_FPDNaN_Msk (0xFUL << FPU_MVFR1_FPDNaN_Pos) /*!< MVFR1: FPDNaN bits Mask */ +#define FPU_MVFR1_FPFtZ_Pos 0U /*!< MVFR1: FPFtZ bits Position */ +#define FPU_MVFR1_FPFtZ_Msk (0xFUL /*<< FPU_MVFR1_FPFtZ_Pos*/) /*!< MVFR1: FPFtZ bits Mask */ +/* Media and VFP Feature Register 2 Definitions */ +#define FPU_MVFR2_FPMisc_Pos 4U /*!< MVFR2: FPMisc bits Position */ +#define FPU_MVFR2_FPMisc_Msk (0xFUL << FPU_MVFR2_FPMisc_Pos) /*!< MVFR2: FPMisc bits Mask */ + +/*@} end of group CMSIS_FPU */ + +/* CoreDebug is deprecated. replaced by DCB (Debug Control Block) */ /** \ingroup CMSIS_core_register \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug) @@ -1871,7 +2618,7 @@ typedef struct */ /** - \brief Structure type to access the Core Debug Register (CoreDebug). + \brief \deprecated Structure type to access the Core Debug Register (CoreDebug). */ typedef struct { @@ -1879,124 +2626,437 @@ typedef struct __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ - uint32_t RESERVED4[1U]; + __OM uint32_t DSCEMCR; /*!< Offset: 0x010 ( /W) Debug Set Clear Exception and Monitor Control Register */ __IOM uint32_t DAUTHCTRL; /*!< Offset: 0x014 (R/W) Debug Authentication Control Register */ __IOM uint32_t DSCSR; /*!< Offset: 0x018 (R/W) Debug Security Control and Status Register */ } CoreDebug_Type; /* Debug Halting Control and Status Register Definitions */ -#define CoreDebug_DHCSR_DBGKEY_Pos 16U /*!< CoreDebug DHCSR: DBGKEY Position */ -#define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos) /*!< CoreDebug DHCSR: DBGKEY Mask */ +#define CoreDebug_DHCSR_DBGKEY_Pos 16U /*!< \deprecated CoreDebug DHCSR: DBGKEY Position */ +#define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos) /*!< \deprecated CoreDebug DHCSR: DBGKEY Mask */ -#define CoreDebug_DHCSR_S_RESTART_ST_Pos 26U /*!< CoreDebug DHCSR: S_RESTART_ST Position */ -#define CoreDebug_DHCSR_S_RESTART_ST_Msk (1UL << CoreDebug_DHCSR_S_RESTART_ST_Pos) /*!< CoreDebug DHCSR: S_RESTART_ST Mask */ +#define CoreDebug_DHCSR_S_RESTART_ST_Pos 26U /*!< \deprecated CoreDebug DHCSR: S_RESTART_ST Position */ +#define CoreDebug_DHCSR_S_RESTART_ST_Msk (1UL << CoreDebug_DHCSR_S_RESTART_ST_Pos) /*!< \deprecated CoreDebug DHCSR: S_RESTART_ST Mask */ -#define CoreDebug_DHCSR_S_RESET_ST_Pos 25U /*!< CoreDebug DHCSR: S_RESET_ST Position */ -#define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< CoreDebug DHCSR: S_RESET_ST Mask */ +#define CoreDebug_DHCSR_S_RESET_ST_Pos 25U /*!< \deprecated CoreDebug DHCSR: S_RESET_ST Position */ +#define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< \deprecated CoreDebug DHCSR: S_RESET_ST Mask */ -#define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24U /*!< CoreDebug DHCSR: S_RETIRE_ST Position */ -#define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< CoreDebug DHCSR: S_RETIRE_ST Mask */ +#define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24U /*!< \deprecated CoreDebug DHCSR: S_RETIRE_ST Position */ +#define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< \deprecated CoreDebug DHCSR: S_RETIRE_ST Mask */ -#define CoreDebug_DHCSR_S_LOCKUP_Pos 19U /*!< CoreDebug DHCSR: S_LOCKUP Position */ -#define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< CoreDebug DHCSR: S_LOCKUP Mask */ +#define CoreDebug_DHCSR_S_FPD_Pos 23U /*!< \deprecated CoreDebug DHCSR: S_FPD Position */ +#define CoreDebug_DHCSR_S_FPD_Msk (1UL << CoreDebug_DHCSR_S_FPD_Pos) /*!< \deprecated CoreDebug DHCSR: S_FPD Mask */ -#define CoreDebug_DHCSR_S_SLEEP_Pos 18U /*!< CoreDebug DHCSR: S_SLEEP Position */ -#define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< CoreDebug DHCSR: S_SLEEP Mask */ +#define CoreDebug_DHCSR_S_SUIDE_Pos 22U /*!< \deprecated CoreDebug DHCSR: S_SUIDE Position */ +#define CoreDebug_DHCSR_S_SUIDE_Msk (1UL << CoreDebug_DHCSR_S_SUIDE_Pos) /*!< \deprecated CoreDebug DHCSR: S_SUIDE Mask */ -#define CoreDebug_DHCSR_S_HALT_Pos 17U /*!< CoreDebug DHCSR: S_HALT Position */ -#define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos) /*!< CoreDebug DHCSR: S_HALT Mask */ +#define CoreDebug_DHCSR_S_NSUIDE_Pos 21U /*!< \deprecated CoreDebug DHCSR: S_NSUIDE Position */ +#define CoreDebug_DHCSR_S_NSUIDE_Msk (1UL << CoreDebug_DHCSR_S_NSUIDE_Pos) /*!< \deprecated CoreDebug DHCSR: S_NSUIDE Mask */ -#define CoreDebug_DHCSR_S_REGRDY_Pos 16U /*!< CoreDebug DHCSR: S_REGRDY Position */ -#define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< CoreDebug DHCSR: S_REGRDY Mask */ +#define CoreDebug_DHCSR_S_SDE_Pos 20U /*!< \deprecated CoreDebug DHCSR: S_SDE Position */ +#define CoreDebug_DHCSR_S_SDE_Msk (1UL << CoreDebug_DHCSR_S_SDE_Pos) /*!< \deprecated CoreDebug DHCSR: S_SDE Mask */ -#define CoreDebug_DHCSR_C_SNAPSTALL_Pos 5U /*!< CoreDebug DHCSR: C_SNAPSTALL Position */ -#define CoreDebug_DHCSR_C_SNAPSTALL_Msk (1UL << CoreDebug_DHCSR_C_SNAPSTALL_Pos) /*!< CoreDebug DHCSR: C_SNAPSTALL Mask */ +#define CoreDebug_DHCSR_S_LOCKUP_Pos 19U /*!< \deprecated CoreDebug DHCSR: S_LOCKUP Position */ +#define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< \deprecated CoreDebug DHCSR: S_LOCKUP Mask */ -#define CoreDebug_DHCSR_C_MASKINTS_Pos 3U /*!< CoreDebug DHCSR: C_MASKINTS Position */ -#define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< CoreDebug DHCSR: C_MASKINTS Mask */ +#define CoreDebug_DHCSR_S_SLEEP_Pos 18U /*!< \deprecated CoreDebug DHCSR: S_SLEEP Position */ +#define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< \deprecated CoreDebug DHCSR: S_SLEEP Mask */ -#define CoreDebug_DHCSR_C_STEP_Pos 2U /*!< CoreDebug DHCSR: C_STEP Position */ -#define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos) /*!< CoreDebug DHCSR: C_STEP Mask */ +#define CoreDebug_DHCSR_S_HALT_Pos 17U /*!< \deprecated CoreDebug DHCSR: S_HALT Position */ +#define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos) /*!< \deprecated CoreDebug DHCSR: S_HALT Mask */ -#define CoreDebug_DHCSR_C_HALT_Pos 1U /*!< CoreDebug DHCSR: C_HALT Position */ -#define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos) /*!< CoreDebug DHCSR: C_HALT Mask */ +#define CoreDebug_DHCSR_S_REGRDY_Pos 16U /*!< \deprecated CoreDebug DHCSR: S_REGRDY Position */ +#define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< \deprecated CoreDebug DHCSR: S_REGRDY Mask */ -#define CoreDebug_DHCSR_C_DEBUGEN_Pos 0U /*!< CoreDebug DHCSR: C_DEBUGEN Position */ -#define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL /*<< CoreDebug_DHCSR_C_DEBUGEN_Pos*/) /*!< CoreDebug DHCSR: C_DEBUGEN Mask */ +#define CoreDebug_DHCSR_C_PMOV_Pos 6U /*!< \deprecated CoreDebug DHCSR: C_PMOV Position */ +#define CoreDebug_DHCSR_C_PMOV_Msk (1UL << CoreDebug_DHCSR_C_PMOV_Pos) /*!< \deprecated CoreDebug DHCSR: C_PMOV Mask */ + +#define CoreDebug_DHCSR_C_SNAPSTALL_Pos 5U /*!< \deprecated CoreDebug DHCSR: C_SNAPSTALL Position */ +#define CoreDebug_DHCSR_C_SNAPSTALL_Msk (1UL << CoreDebug_DHCSR_C_SNAPSTALL_Pos) /*!< \deprecated CoreDebug DHCSR: C_SNAPSTALL Mask */ + +#define CoreDebug_DHCSR_C_MASKINTS_Pos 3U /*!< \deprecated CoreDebug DHCSR: C_MASKINTS Position */ +#define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< \deprecated CoreDebug DHCSR: C_MASKINTS Mask */ + +#define CoreDebug_DHCSR_C_STEP_Pos 2U /*!< \deprecated CoreDebug DHCSR: C_STEP Position */ +#define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos) /*!< \deprecated CoreDebug DHCSR: C_STEP Mask */ + +#define CoreDebug_DHCSR_C_HALT_Pos 1U /*!< \deprecated CoreDebug DHCSR: C_HALT Position */ +#define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos) /*!< \deprecated CoreDebug DHCSR: C_HALT Mask */ + +#define CoreDebug_DHCSR_C_DEBUGEN_Pos 0U /*!< \deprecated CoreDebug DHCSR: C_DEBUGEN Position */ +#define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL /*<< CoreDebug_DHCSR_C_DEBUGEN_Pos*/) /*!< \deprecated CoreDebug DHCSR: C_DEBUGEN Mask */ /* Debug Core Register Selector Register Definitions */ -#define CoreDebug_DCRSR_REGWnR_Pos 16U /*!< CoreDebug DCRSR: REGWnR Position */ -#define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos) /*!< CoreDebug DCRSR: REGWnR Mask */ +#define CoreDebug_DCRSR_REGWnR_Pos 16U /*!< \deprecated CoreDebug DCRSR: REGWnR Position */ +#define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos) /*!< \deprecated CoreDebug DCRSR: REGWnR Mask */ -#define CoreDebug_DCRSR_REGSEL_Pos 0U /*!< CoreDebug DCRSR: REGSEL Position */ -#define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL /*<< CoreDebug_DCRSR_REGSEL_Pos*/) /*!< CoreDebug DCRSR: REGSEL Mask */ +#define CoreDebug_DCRSR_REGSEL_Pos 0U /*!< \deprecated CoreDebug DCRSR: REGSEL Position */ +#define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL /*<< CoreDebug_DCRSR_REGSEL_Pos*/) /*!< \deprecated CoreDebug DCRSR: REGSEL Mask */ /* Debug Exception and Monitor Control Register Definitions */ -#define CoreDebug_DEMCR_TRCENA_Pos 24U /*!< CoreDebug DEMCR: TRCENA Position */ -#define CoreDebug_DEMCR_TRCENA_Msk (1UL << CoreDebug_DEMCR_TRCENA_Pos) /*!< CoreDebug DEMCR: TRCENA Mask */ +#define CoreDebug_DEMCR_TRCENA_Pos 24U /*!< \deprecated CoreDebug DEMCR: TRCENA Position */ +#define CoreDebug_DEMCR_TRCENA_Msk (1UL << CoreDebug_DEMCR_TRCENA_Pos) /*!< \deprecated CoreDebug DEMCR: TRCENA Mask */ + +#define CoreDebug_DEMCR_MON_REQ_Pos 19U /*!< \deprecated CoreDebug DEMCR: MON_REQ Position */ +#define CoreDebug_DEMCR_MON_REQ_Msk (1UL << CoreDebug_DEMCR_MON_REQ_Pos) /*!< \deprecated CoreDebug DEMCR: MON_REQ Mask */ + +#define CoreDebug_DEMCR_MON_STEP_Pos 18U /*!< \deprecated CoreDebug DEMCR: MON_STEP Position */ +#define CoreDebug_DEMCR_MON_STEP_Msk (1UL << CoreDebug_DEMCR_MON_STEP_Pos) /*!< \deprecated CoreDebug DEMCR: MON_STEP Mask */ + +#define CoreDebug_DEMCR_MON_PEND_Pos 17U /*!< \deprecated CoreDebug DEMCR: MON_PEND Position */ +#define CoreDebug_DEMCR_MON_PEND_Msk (1UL << CoreDebug_DEMCR_MON_PEND_Pos) /*!< \deprecated CoreDebug DEMCR: MON_PEND Mask */ -#define CoreDebug_DEMCR_MON_REQ_Pos 19U /*!< CoreDebug DEMCR: MON_REQ Position */ -#define CoreDebug_DEMCR_MON_REQ_Msk (1UL << CoreDebug_DEMCR_MON_REQ_Pos) /*!< CoreDebug DEMCR: MON_REQ Mask */ +#define CoreDebug_DEMCR_MON_EN_Pos 16U /*!< \deprecated CoreDebug DEMCR: MON_EN Position */ +#define CoreDebug_DEMCR_MON_EN_Msk (1UL << CoreDebug_DEMCR_MON_EN_Pos) /*!< \deprecated CoreDebug DEMCR: MON_EN Mask */ -#define CoreDebug_DEMCR_MON_STEP_Pos 18U /*!< CoreDebug DEMCR: MON_STEP Position */ -#define CoreDebug_DEMCR_MON_STEP_Msk (1UL << CoreDebug_DEMCR_MON_STEP_Pos) /*!< CoreDebug DEMCR: MON_STEP Mask */ +#define CoreDebug_DEMCR_VC_HARDERR_Pos 10U /*!< \deprecated CoreDebug DEMCR: VC_HARDERR Position */ +#define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_HARDERR Mask */ -#define CoreDebug_DEMCR_MON_PEND_Pos 17U /*!< CoreDebug DEMCR: MON_PEND Position */ -#define CoreDebug_DEMCR_MON_PEND_Msk (1UL << CoreDebug_DEMCR_MON_PEND_Pos) /*!< CoreDebug DEMCR: MON_PEND Mask */ +#define CoreDebug_DEMCR_VC_INTERR_Pos 9U /*!< \deprecated CoreDebug DEMCR: VC_INTERR Position */ +#define CoreDebug_DEMCR_VC_INTERR_Msk (1UL << CoreDebug_DEMCR_VC_INTERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_INTERR Mask */ -#define CoreDebug_DEMCR_MON_EN_Pos 16U /*!< CoreDebug DEMCR: MON_EN Position */ -#define CoreDebug_DEMCR_MON_EN_Msk (1UL << CoreDebug_DEMCR_MON_EN_Pos) /*!< CoreDebug DEMCR: MON_EN Mask */ +#define CoreDebug_DEMCR_VC_BUSERR_Pos 8U /*!< \deprecated CoreDebug DEMCR: VC_BUSERR Position */ +#define CoreDebug_DEMCR_VC_BUSERR_Msk (1UL << CoreDebug_DEMCR_VC_BUSERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_BUSERR Mask */ -#define CoreDebug_DEMCR_VC_HARDERR_Pos 10U /*!< CoreDebug DEMCR: VC_HARDERR Position */ -#define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< CoreDebug DEMCR: VC_HARDERR Mask */ +#define CoreDebug_DEMCR_VC_STATERR_Pos 7U /*!< \deprecated CoreDebug DEMCR: VC_STATERR Position */ +#define CoreDebug_DEMCR_VC_STATERR_Msk (1UL << CoreDebug_DEMCR_VC_STATERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_STATERR Mask */ -#define CoreDebug_DEMCR_VC_INTERR_Pos 9U /*!< CoreDebug DEMCR: VC_INTERR Position */ -#define CoreDebug_DEMCR_VC_INTERR_Msk (1UL << CoreDebug_DEMCR_VC_INTERR_Pos) /*!< CoreDebug DEMCR: VC_INTERR Mask */ +#define CoreDebug_DEMCR_VC_CHKERR_Pos 6U /*!< \deprecated CoreDebug DEMCR: VC_CHKERR Position */ +#define CoreDebug_DEMCR_VC_CHKERR_Msk (1UL << CoreDebug_DEMCR_VC_CHKERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_CHKERR Mask */ -#define CoreDebug_DEMCR_VC_BUSERR_Pos 8U /*!< CoreDebug DEMCR: VC_BUSERR Position */ -#define CoreDebug_DEMCR_VC_BUSERR_Msk (1UL << CoreDebug_DEMCR_VC_BUSERR_Pos) /*!< CoreDebug DEMCR: VC_BUSERR Mask */ +#define CoreDebug_DEMCR_VC_NOCPERR_Pos 5U /*!< \deprecated CoreDebug DEMCR: VC_NOCPERR Position */ +#define CoreDebug_DEMCR_VC_NOCPERR_Msk (1UL << CoreDebug_DEMCR_VC_NOCPERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_NOCPERR Mask */ -#define CoreDebug_DEMCR_VC_STATERR_Pos 7U /*!< CoreDebug DEMCR: VC_STATERR Position */ -#define CoreDebug_DEMCR_VC_STATERR_Msk (1UL << CoreDebug_DEMCR_VC_STATERR_Pos) /*!< CoreDebug DEMCR: VC_STATERR Mask */ +#define CoreDebug_DEMCR_VC_MMERR_Pos 4U /*!< \deprecated CoreDebug DEMCR: VC_MMERR Position */ +#define CoreDebug_DEMCR_VC_MMERR_Msk (1UL << CoreDebug_DEMCR_VC_MMERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_MMERR Mask */ -#define CoreDebug_DEMCR_VC_CHKERR_Pos 6U /*!< CoreDebug DEMCR: VC_CHKERR Position */ -#define CoreDebug_DEMCR_VC_CHKERR_Msk (1UL << CoreDebug_DEMCR_VC_CHKERR_Pos) /*!< CoreDebug DEMCR: VC_CHKERR Mask */ +#define CoreDebug_DEMCR_VC_CORERESET_Pos 0U /*!< \deprecated CoreDebug DEMCR: VC_CORERESET Position */ +#define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL /*<< CoreDebug_DEMCR_VC_CORERESET_Pos*/) /*!< \deprecated CoreDebug DEMCR: VC_CORERESET Mask */ -#define CoreDebug_DEMCR_VC_NOCPERR_Pos 5U /*!< CoreDebug DEMCR: VC_NOCPERR Position */ -#define CoreDebug_DEMCR_VC_NOCPERR_Msk (1UL << CoreDebug_DEMCR_VC_NOCPERR_Pos) /*!< CoreDebug DEMCR: VC_NOCPERR Mask */ +/* Debug Set Clear Exception and Monitor Control Register Definitions */ +#define CoreDebug_DSCEMCR_CLR_MON_REQ_Pos 19U /*!< \deprecated CoreDebug DSCEMCR: CLR_MON_REQ, Position */ +#define CoreDebug_DSCEMCR_CLR_MON_REQ_Msk (1UL << CoreDebug_DSCEMCR_CLR_MON_REQ_Pos) /*!< \deprecated CoreDebug DSCEMCR: CLR_MON_REQ, Mask */ -#define CoreDebug_DEMCR_VC_MMERR_Pos 4U /*!< CoreDebug DEMCR: VC_MMERR Position */ -#define CoreDebug_DEMCR_VC_MMERR_Msk (1UL << CoreDebug_DEMCR_VC_MMERR_Pos) /*!< CoreDebug DEMCR: VC_MMERR Mask */ +#define CoreDebug_DSCEMCR_CLR_MON_PEND_Pos 17U /*!< \deprecated CoreDebug DSCEMCR: CLR_MON_PEND, Position */ +#define CoreDebug_DSCEMCR_CLR_MON_PEND_Msk (1UL << CoreDebug_DSCEMCR_CLR_MON_PEND_Pos) /*!< \deprecated CoreDebug DSCEMCR: CLR_MON_PEND, Mask */ -#define CoreDebug_DEMCR_VC_CORERESET_Pos 0U /*!< CoreDebug DEMCR: VC_CORERESET Position */ -#define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL /*<< CoreDebug_DEMCR_VC_CORERESET_Pos*/) /*!< CoreDebug DEMCR: VC_CORERESET Mask */ +#define CoreDebug_DSCEMCR_SET_MON_REQ_Pos 3U /*!< \deprecated CoreDebug DSCEMCR: SET_MON_REQ, Position */ +#define CoreDebug_DSCEMCR_SET_MON_REQ_Msk (1UL << CoreDebug_DSCEMCR_SET_MON_REQ_Pos) /*!< \deprecated CoreDebug DSCEMCR: SET_MON_REQ, Mask */ + +#define CoreDebug_DSCEMCR_SET_MON_PEND_Pos 1U /*!< \deprecated CoreDebug DSCEMCR: SET_MON_PEND, Position */ +#define CoreDebug_DSCEMCR_SET_MON_PEND_Msk (1UL << CoreDebug_DSCEMCR_SET_MON_PEND_Pos) /*!< \deprecated CoreDebug DSCEMCR: SET_MON_PEND, Mask */ /* Debug Authentication Control Register Definitions */ -#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos 3U /*!< CoreDebug DAUTHCTRL: INTSPNIDEN, Position */ -#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos) /*!< CoreDebug DAUTHCTRL: INTSPNIDEN, Mask */ +#define CoreDebug_DAUTHCTRL_UIDEN_Pos 10U /*!< \deprecated CoreDebug DAUTHCTRL: UIDEN, Position */ +#define CoreDebug_DAUTHCTRL_UIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_UIDEN_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: UIDEN, Mask */ + +#define CoreDebug_DAUTHCTRL_UIDAPEN_Pos 9U /*!< \deprecated CoreDebug DAUTHCTRL: UIDAPEN, Position */ +#define CoreDebug_DAUTHCTRL_UIDAPEN_Msk (1UL << CoreDebug_DAUTHCTRL_UIDAPEN_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: UIDAPEN, Mask */ + +#define CoreDebug_DAUTHCTRL_FSDMA_Pos 8U /*!< \deprecated CoreDebug DAUTHCTRL: FSDMA, Position */ +#define CoreDebug_DAUTHCTRL_FSDMA_Msk (1UL << CoreDebug_DAUTHCTRL_FSDMA_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: FSDMA, Mask */ + +#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos 3U /*!< \deprecated CoreDebug DAUTHCTRL: INTSPNIDEN, Position */ +#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: INTSPNIDEN, Mask */ -#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos 2U /*!< CoreDebug DAUTHCTRL: SPNIDENSEL Position */ -#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Msk (1UL << CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos) /*!< CoreDebug DAUTHCTRL: SPNIDENSEL Mask */ +#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos 2U /*!< \deprecated CoreDebug DAUTHCTRL: SPNIDENSEL Position */ +#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Msk (1UL << CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: SPNIDENSEL Mask */ -#define CoreDebug_DAUTHCTRL_INTSPIDEN_Pos 1U /*!< CoreDebug DAUTHCTRL: INTSPIDEN Position */ -#define CoreDebug_DAUTHCTRL_INTSPIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPIDEN_Pos) /*!< CoreDebug DAUTHCTRL: INTSPIDEN Mask */ +#define CoreDebug_DAUTHCTRL_INTSPIDEN_Pos 1U /*!< \deprecated CoreDebug DAUTHCTRL: INTSPIDEN Position */ +#define CoreDebug_DAUTHCTRL_INTSPIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPIDEN_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: INTSPIDEN Mask */ -#define CoreDebug_DAUTHCTRL_SPIDENSEL_Pos 0U /*!< CoreDebug DAUTHCTRL: SPIDENSEL Position */ -#define CoreDebug_DAUTHCTRL_SPIDENSEL_Msk (1UL /*<< CoreDebug_DAUTHCTRL_SPIDENSEL_Pos*/) /*!< CoreDebug DAUTHCTRL: SPIDENSEL Mask */ +#define CoreDebug_DAUTHCTRL_SPIDENSEL_Pos 0U /*!< \deprecated CoreDebug DAUTHCTRL: SPIDENSEL Position */ +#define CoreDebug_DAUTHCTRL_SPIDENSEL_Msk (1UL /*<< CoreDebug_DAUTHCTRL_SPIDENSEL_Pos*/) /*!< \deprecated CoreDebug DAUTHCTRL: SPIDENSEL Mask */ /* Debug Security Control and Status Register Definitions */ -#define CoreDebug_DSCSR_CDS_Pos 16U /*!< CoreDebug DSCSR: CDS Position */ -#define CoreDebug_DSCSR_CDS_Msk (1UL << CoreDebug_DSCSR_CDS_Pos) /*!< CoreDebug DSCSR: CDS Mask */ +#define CoreDebug_DSCSR_CDS_Pos 16U /*!< \deprecated CoreDebug DSCSR: CDS Position */ +#define CoreDebug_DSCSR_CDS_Msk (1UL << CoreDebug_DSCSR_CDS_Pos) /*!< \deprecated CoreDebug DSCSR: CDS Mask */ -#define CoreDebug_DSCSR_SBRSEL_Pos 1U /*!< CoreDebug DSCSR: SBRSEL Position */ -#define CoreDebug_DSCSR_SBRSEL_Msk (1UL << CoreDebug_DSCSR_SBRSEL_Pos) /*!< CoreDebug DSCSR: SBRSEL Mask */ +#define CoreDebug_DSCSR_SBRSEL_Pos 1U /*!< \deprecated CoreDebug DSCSR: SBRSEL Position */ +#define CoreDebug_DSCSR_SBRSEL_Msk (1UL << CoreDebug_DSCSR_SBRSEL_Pos) /*!< \deprecated CoreDebug DSCSR: SBRSEL Mask */ -#define CoreDebug_DSCSR_SBRSELEN_Pos 0U /*!< CoreDebug DSCSR: SBRSELEN Position */ -#define CoreDebug_DSCSR_SBRSELEN_Msk (1UL /*<< CoreDebug_DSCSR_SBRSELEN_Pos*/) /*!< CoreDebug DSCSR: SBRSELEN Mask */ +#define CoreDebug_DSCSR_SBRSELEN_Pos 0U /*!< \deprecated CoreDebug DSCSR: SBRSELEN Position */ +#define CoreDebug_DSCSR_SBRSELEN_Msk (1UL /*<< CoreDebug_DSCSR_SBRSELEN_Pos*/) /*!< \deprecated CoreDebug DSCSR: SBRSELEN Mask */ /*@} end of group CMSIS_CoreDebug */ +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_DCB Debug Control Block + \brief Type definitions for the Debug Control Block Registers + @{ + */ + +/** + \brief Structure type to access the Debug Control Block Registers (DCB). + */ +typedef struct +{ + __IOM uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */ + __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ + __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ + __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ + __OM uint32_t DSCEMCR; /*!< Offset: 0x010 ( /W) Debug Set Clear Exception and Monitor Control Register */ + __IOM uint32_t DAUTHCTRL; /*!< Offset: 0x014 (R/W) Debug Authentication Control Register */ + __IOM uint32_t DSCSR; /*!< Offset: 0x018 (R/W) Debug Security Control and Status Register */ +} DCB_Type; + +/* DHCSR, Debug Halting Control and Status Register Definitions */ +#define DCB_DHCSR_DBGKEY_Pos 16U /*!< DCB DHCSR: Debug key Position */ +#define DCB_DHCSR_DBGKEY_Msk (0xFFFFUL << DCB_DHCSR_DBGKEY_Pos) /*!< DCB DHCSR: Debug key Mask */ + +#define DCB_DHCSR_S_RESTART_ST_Pos 26U /*!< DCB DHCSR: Restart sticky status Position */ +#define DCB_DHCSR_S_RESTART_ST_Msk (0x1UL << DCB_DHCSR_S_RESTART_ST_Pos) /*!< DCB DHCSR: Restart sticky status Mask */ + +#define DCB_DHCSR_S_RESET_ST_Pos 25U /*!< DCB DHCSR: Reset sticky status Position */ +#define DCB_DHCSR_S_RESET_ST_Msk (0x1UL << DCB_DHCSR_S_RESET_ST_Pos) /*!< DCB DHCSR: Reset sticky status Mask */ + +#define DCB_DHCSR_S_RETIRE_ST_Pos 24U /*!< DCB DHCSR: Retire sticky status Position */ +#define DCB_DHCSR_S_RETIRE_ST_Msk (0x1UL << DCB_DHCSR_S_RETIRE_ST_Pos) /*!< DCB DHCSR: Retire sticky status Mask */ + +#define DCB_DHCSR_S_FPD_Pos 23U /*!< DCB DHCSR: Floating-point registers Debuggable Position */ +#define DCB_DHCSR_S_FPD_Msk (0x1UL << DCB_DHCSR_S_FPD_Pos) /*!< DCB DHCSR: Floating-point registers Debuggable Mask */ + +#define DCB_DHCSR_S_SUIDE_Pos 22U /*!< DCB DHCSR: Secure unprivileged halting debug enabled Position */ +#define DCB_DHCSR_S_SUIDE_Msk (0x1UL << DCB_DHCSR_S_SUIDE_Pos) /*!< DCB DHCSR: Secure unprivileged halting debug enabled Mask */ + +#define DCB_DHCSR_S_NSUIDE_Pos 21U /*!< DCB DHCSR: Non-secure unprivileged halting debug enabled Position */ +#define DCB_DHCSR_S_NSUIDE_Msk (0x1UL << DCB_DHCSR_S_NSUIDE_Pos) /*!< DCB DHCSR: Non-secure unprivileged halting debug enabled Mask */ + +#define DCB_DHCSR_S_SDE_Pos 20U /*!< DCB DHCSR: Secure debug enabled Position */ +#define DCB_DHCSR_S_SDE_Msk (0x1UL << DCB_DHCSR_S_SDE_Pos) /*!< DCB DHCSR: Secure debug enabled Mask */ + +#define DCB_DHCSR_S_LOCKUP_Pos 19U /*!< DCB DHCSR: Lockup status Position */ +#define DCB_DHCSR_S_LOCKUP_Msk (0x1UL << DCB_DHCSR_S_LOCKUP_Pos) /*!< DCB DHCSR: Lockup status Mask */ + +#define DCB_DHCSR_S_SLEEP_Pos 18U /*!< DCB DHCSR: Sleeping status Position */ +#define DCB_DHCSR_S_SLEEP_Msk (0x1UL << DCB_DHCSR_S_SLEEP_Pos) /*!< DCB DHCSR: Sleeping status Mask */ + +#define DCB_DHCSR_S_HALT_Pos 17U /*!< DCB DHCSR: Halted status Position */ +#define DCB_DHCSR_S_HALT_Msk (0x1UL << DCB_DHCSR_S_HALT_Pos) /*!< DCB DHCSR: Halted status Mask */ + +#define DCB_DHCSR_S_REGRDY_Pos 16U /*!< DCB DHCSR: Register ready status Position */ +#define DCB_DHCSR_S_REGRDY_Msk (0x1UL << DCB_DHCSR_S_REGRDY_Pos) /*!< DCB DHCSR: Register ready status Mask */ + +#define DCB_DHCSR_C_PMOV_Pos 6U /*!< DCB DHCSR: Halt on PMU overflow control Position */ +#define DCB_DHCSR_C_PMOV_Msk (0x1UL << DCB_DHCSR_C_PMOV_Pos) /*!< DCB DHCSR: Halt on PMU overflow control Mask */ + +#define DCB_DHCSR_C_SNAPSTALL_Pos 5U /*!< DCB DHCSR: Snap stall control Position */ +#define DCB_DHCSR_C_SNAPSTALL_Msk (0x1UL << DCB_DHCSR_C_SNAPSTALL_Pos) /*!< DCB DHCSR: Snap stall control Mask */ + +#define DCB_DHCSR_C_MASKINTS_Pos 3U /*!< DCB DHCSR: Mask interrupts control Position */ +#define DCB_DHCSR_C_MASKINTS_Msk (0x1UL << DCB_DHCSR_C_MASKINTS_Pos) /*!< DCB DHCSR: Mask interrupts control Mask */ + +#define DCB_DHCSR_C_STEP_Pos 2U /*!< DCB DHCSR: Step control Position */ +#define DCB_DHCSR_C_STEP_Msk (0x1UL << DCB_DHCSR_C_STEP_Pos) /*!< DCB DHCSR: Step control Mask */ + +#define DCB_DHCSR_C_HALT_Pos 1U /*!< DCB DHCSR: Halt control Position */ +#define DCB_DHCSR_C_HALT_Msk (0x1UL << DCB_DHCSR_C_HALT_Pos) /*!< DCB DHCSR: Halt control Mask */ + +#define DCB_DHCSR_C_DEBUGEN_Pos 0U /*!< DCB DHCSR: Debug enable control Position */ +#define DCB_DHCSR_C_DEBUGEN_Msk (0x1UL /*<< DCB_DHCSR_C_DEBUGEN_Pos*/) /*!< DCB DHCSR: Debug enable control Mask */ + +/* DCRSR, Debug Core Register Select Register Definitions */ +#define DCB_DCRSR_REGWnR_Pos 16U /*!< DCB DCRSR: Register write/not-read Position */ +#define DCB_DCRSR_REGWnR_Msk (0x1UL << DCB_DCRSR_REGWnR_Pos) /*!< DCB DCRSR: Register write/not-read Mask */ + +#define DCB_DCRSR_REGSEL_Pos 0U /*!< DCB DCRSR: Register selector Position */ +#define DCB_DCRSR_REGSEL_Msk (0x7FUL /*<< DCB_DCRSR_REGSEL_Pos*/) /*!< DCB DCRSR: Register selector Mask */ + +/* DCRDR, Debug Core Register Data Register Definitions */ +#define DCB_DCRDR_DBGTMP_Pos 0U /*!< DCB DCRDR: Data temporary buffer Position */ +#define DCB_DCRDR_DBGTMP_Msk (0xFFFFFFFFUL /*<< DCB_DCRDR_DBGTMP_Pos*/) /*!< DCB DCRDR: Data temporary buffer Mask */ + +/* DEMCR, Debug Exception and Monitor Control Register Definitions */ +#define DCB_DEMCR_TRCENA_Pos 24U /*!< DCB DEMCR: Trace enable Position */ +#define DCB_DEMCR_TRCENA_Msk (0x1UL << DCB_DEMCR_TRCENA_Pos) /*!< DCB DEMCR: Trace enable Mask */ + +#define DCB_DEMCR_MONPRKEY_Pos 23U /*!< DCB DEMCR: Monitor pend req key Position */ +#define DCB_DEMCR_MONPRKEY_Msk (0x1UL << DCB_DEMCR_MONPRKEY_Pos) /*!< DCB DEMCR: Monitor pend req key Mask */ + +#define DCB_DEMCR_UMON_EN_Pos 21U /*!< DCB DEMCR: Unprivileged monitor enable Position */ +#define DCB_DEMCR_UMON_EN_Msk (0x1UL << DCB_DEMCR_UMON_EN_Pos) /*!< DCB DEMCR: Unprivileged monitor enable Mask */ + +#define DCB_DEMCR_SDME_Pos 20U /*!< DCB DEMCR: Secure DebugMonitor enable Position */ +#define DCB_DEMCR_SDME_Msk (0x1UL << DCB_DEMCR_SDME_Pos) /*!< DCB DEMCR: Secure DebugMonitor enable Mask */ + +#define DCB_DEMCR_MON_REQ_Pos 19U /*!< DCB DEMCR: Monitor request Position */ +#define DCB_DEMCR_MON_REQ_Msk (0x1UL << DCB_DEMCR_MON_REQ_Pos) /*!< DCB DEMCR: Monitor request Mask */ + +#define DCB_DEMCR_MON_STEP_Pos 18U /*!< DCB DEMCR: Monitor step Position */ +#define DCB_DEMCR_MON_STEP_Msk (0x1UL << DCB_DEMCR_MON_STEP_Pos) /*!< DCB DEMCR: Monitor step Mask */ + +#define DCB_DEMCR_MON_PEND_Pos 17U /*!< DCB DEMCR: Monitor pend Position */ +#define DCB_DEMCR_MON_PEND_Msk (0x1UL << DCB_DEMCR_MON_PEND_Pos) /*!< DCB DEMCR: Monitor pend Mask */ + +#define DCB_DEMCR_MON_EN_Pos 16U /*!< DCB DEMCR: Monitor enable Position */ +#define DCB_DEMCR_MON_EN_Msk (0x1UL << DCB_DEMCR_MON_EN_Pos) /*!< DCB DEMCR: Monitor enable Mask */ + +#define DCB_DEMCR_VC_SFERR_Pos 11U /*!< DCB DEMCR: Vector Catch SecureFault Position */ +#define DCB_DEMCR_VC_SFERR_Msk (0x1UL << DCB_DEMCR_VC_SFERR_Pos) /*!< DCB DEMCR: Vector Catch SecureFault Mask */ + +#define DCB_DEMCR_VC_HARDERR_Pos 10U /*!< DCB DEMCR: Vector Catch HardFault errors Position */ +#define DCB_DEMCR_VC_HARDERR_Msk (0x1UL << DCB_DEMCR_VC_HARDERR_Pos) /*!< DCB DEMCR: Vector Catch HardFault errors Mask */ + +#define DCB_DEMCR_VC_INTERR_Pos 9U /*!< DCB DEMCR: Vector Catch interrupt errors Position */ +#define DCB_DEMCR_VC_INTERR_Msk (0x1UL << DCB_DEMCR_VC_INTERR_Pos) /*!< DCB DEMCR: Vector Catch interrupt errors Mask */ + +#define DCB_DEMCR_VC_BUSERR_Pos 8U /*!< DCB DEMCR: Vector Catch BusFault errors Position */ +#define DCB_DEMCR_VC_BUSERR_Msk (0x1UL << DCB_DEMCR_VC_BUSERR_Pos) /*!< DCB DEMCR: Vector Catch BusFault errors Mask */ + +#define DCB_DEMCR_VC_STATERR_Pos 7U /*!< DCB DEMCR: Vector Catch state errors Position */ +#define DCB_DEMCR_VC_STATERR_Msk (0x1UL << DCB_DEMCR_VC_STATERR_Pos) /*!< DCB DEMCR: Vector Catch state errors Mask */ + +#define DCB_DEMCR_VC_CHKERR_Pos 6U /*!< DCB DEMCR: Vector Catch check errors Position */ +#define DCB_DEMCR_VC_CHKERR_Msk (0x1UL << DCB_DEMCR_VC_CHKERR_Pos) /*!< DCB DEMCR: Vector Catch check errors Mask */ + +#define DCB_DEMCR_VC_NOCPERR_Pos 5U /*!< DCB DEMCR: Vector Catch NOCP errors Position */ +#define DCB_DEMCR_VC_NOCPERR_Msk (0x1UL << DCB_DEMCR_VC_NOCPERR_Pos) /*!< DCB DEMCR: Vector Catch NOCP errors Mask */ + +#define DCB_DEMCR_VC_MMERR_Pos 4U /*!< DCB DEMCR: Vector Catch MemManage errors Position */ +#define DCB_DEMCR_VC_MMERR_Msk (0x1UL << DCB_DEMCR_VC_MMERR_Pos) /*!< DCB DEMCR: Vector Catch MemManage errors Mask */ + +#define DCB_DEMCR_VC_CORERESET_Pos 0U /*!< DCB DEMCR: Vector Catch Core reset Position */ +#define DCB_DEMCR_VC_CORERESET_Msk (0x1UL /*<< DCB_DEMCR_VC_CORERESET_Pos*/) /*!< DCB DEMCR: Vector Catch Core reset Mask */ + +/* DSCEMCR, Debug Set Clear Exception and Monitor Control Register Definitions */ +#define DCB_DSCEMCR_CLR_MON_REQ_Pos 19U /*!< DCB DSCEMCR: Clear monitor request Position */ +#define DCB_DSCEMCR_CLR_MON_REQ_Msk (0x1UL << DCB_DSCEMCR_CLR_MON_REQ_Pos) /*!< DCB DSCEMCR: Clear monitor request Mask */ + +#define DCB_DSCEMCR_CLR_MON_PEND_Pos 17U /*!< DCB DSCEMCR: Clear monitor pend Position */ +#define DCB_DSCEMCR_CLR_MON_PEND_Msk (0x1UL << DCB_DSCEMCR_CLR_MON_PEND_Pos) /*!< DCB DSCEMCR: Clear monitor pend Mask */ + +#define DCB_DSCEMCR_SET_MON_REQ_Pos 3U /*!< DCB DSCEMCR: Set monitor request Position */ +#define DCB_DSCEMCR_SET_MON_REQ_Msk (0x1UL << DCB_DSCEMCR_SET_MON_REQ_Pos) /*!< DCB DSCEMCR: Set monitor request Mask */ + +#define DCB_DSCEMCR_SET_MON_PEND_Pos 1U /*!< DCB DSCEMCR: Set monitor pend Position */ +#define DCB_DSCEMCR_SET_MON_PEND_Msk (0x1UL << DCB_DSCEMCR_SET_MON_PEND_Pos) /*!< DCB DSCEMCR: Set monitor pend Mask */ + +/* DAUTHCTRL, Debug Authentication Control Register Definitions */ +#define DCB_DAUTHCTRL_UIDEN_Pos 10U /*!< DCB DAUTHCTRL: Unprivileged Invasive Debug Enable Position */ +#define DCB_DAUTHCTRL_UIDEN_Msk (0x1UL << DCB_DAUTHCTRL_UIDEN_Pos) /*!< DCB DAUTHCTRL: Unprivileged Invasive Debug Enable Mask */ + +#define DCB_DAUTHCTRL_UIDAPEN_Pos 9U /*!< DCB DAUTHCTRL: Unprivileged Invasive DAP Access Enable Position */ +#define DCB_DAUTHCTRL_UIDAPEN_Msk (0x1UL << DCB_DAUTHCTRL_UIDAPEN_Pos) /*!< DCB DAUTHCTRL: Unprivileged Invasive DAP Access Enable Mask */ + +#define DCB_DAUTHCTRL_FSDMA_Pos 8U /*!< DCB DAUTHCTRL: Force Secure DebugMonitor Allowed Position */ +#define DCB_DAUTHCTRL_FSDMA_Msk (0x1UL << DCB_DAUTHCTRL_FSDMA_Pos) /*!< DCB DAUTHCTRL: Force Secure DebugMonitor Allowed Mask */ + +#define DCB_DAUTHCTRL_INTSPNIDEN_Pos 3U /*!< DCB DAUTHCTRL: Internal Secure non-invasive debug enable Position */ +#define DCB_DAUTHCTRL_INTSPNIDEN_Msk (0x1UL << DCB_DAUTHCTRL_INTSPNIDEN_Pos) /*!< DCB DAUTHCTRL: Internal Secure non-invasive debug enable Mask */ + +#define DCB_DAUTHCTRL_SPNIDENSEL_Pos 2U /*!< DCB DAUTHCTRL: Secure non-invasive debug enable select Position */ +#define DCB_DAUTHCTRL_SPNIDENSEL_Msk (0x1UL << DCB_DAUTHCTRL_SPNIDENSEL_Pos) /*!< DCB DAUTHCTRL: Secure non-invasive debug enable select Mask */ + +#define DCB_DAUTHCTRL_INTSPIDEN_Pos 1U /*!< DCB DAUTHCTRL: Internal Secure invasive debug enable Position */ +#define DCB_DAUTHCTRL_INTSPIDEN_Msk (0x1UL << DCB_DAUTHCTRL_INTSPIDEN_Pos) /*!< DCB DAUTHCTRL: Internal Secure invasive debug enable Mask */ + +#define DCB_DAUTHCTRL_SPIDENSEL_Pos 0U /*!< DCB DAUTHCTRL: Secure invasive debug enable select Position */ +#define DCB_DAUTHCTRL_SPIDENSEL_Msk (0x1UL /*<< DCB_DAUTHCTRL_SPIDENSEL_Pos*/) /*!< DCB DAUTHCTRL: Secure invasive debug enable select Mask */ + +/* DSCSR, Debug Security Control and Status Register Definitions */ +#define DCB_DSCSR_CDSKEY_Pos 17U /*!< DCB DSCSR: CDS write-enable key Position */ +#define DCB_DSCSR_CDSKEY_Msk (0x1UL << DCB_DSCSR_CDSKEY_Pos) /*!< DCB DSCSR: CDS write-enable key Mask */ + +#define DCB_DSCSR_CDS_Pos 16U /*!< DCB DSCSR: Current domain Secure Position */ +#define DCB_DSCSR_CDS_Msk (0x1UL << DCB_DSCSR_CDS_Pos) /*!< DCB DSCSR: Current domain Secure Mask */ + +#define DCB_DSCSR_SBRSEL_Pos 1U /*!< DCB DSCSR: Secure banked register select Position */ +#define DCB_DSCSR_SBRSEL_Msk (0x1UL << DCB_DSCSR_SBRSEL_Pos) /*!< DCB DSCSR: Secure banked register select Mask */ + +#define DCB_DSCSR_SBRSELEN_Pos 0U /*!< DCB DSCSR: Secure banked register select enable Position */ +#define DCB_DSCSR_SBRSELEN_Msk (0x1UL /*<< DCB_DSCSR_SBRSELEN_Pos*/) /*!< DCB DSCSR: Secure banked register select enable Mask */ + +/*@} end of group CMSIS_DCB */ + + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_DIB Debug Identification Block + \brief Type definitions for the Debug Identification Block Registers + @{ + */ + +/** + \brief Structure type to access the Debug Identification Block Registers (DIB). + */ +typedef struct +{ + __OM uint32_t DLAR; /*!< Offset: 0x000 ( /W) SCS Software Lock Access Register */ + __IM uint32_t DLSR; /*!< Offset: 0x004 (R/ ) SCS Software Lock Status Register */ + __IM uint32_t DAUTHSTATUS; /*!< Offset: 0x008 (R/ ) Debug Authentication Status Register */ + __IM uint32_t DDEVARCH; /*!< Offset: 0x00C (R/ ) SCS Device Architecture Register */ + __IM uint32_t DDEVTYPE; /*!< Offset: 0x010 (R/ ) SCS Device Type Register */ +} DIB_Type; + +/* DLAR, SCS Software Lock Access Register Definitions */ +#define DIB_DLAR_KEY_Pos 0U /*!< DIB DLAR: KEY Position */ +#define DIB_DLAR_KEY_Msk (0xFFFFFFFFUL /*<< DIB_DLAR_KEY_Pos */) /*!< DIB DLAR: KEY Mask */ + +/* DLSR, SCS Software Lock Status Register Definitions */ +#define DIB_DLSR_nTT_Pos 2U /*!< DIB DLSR: Not thirty-two bit Position */ +#define DIB_DLSR_nTT_Msk (0x1UL << DIB_DLSR_nTT_Pos ) /*!< DIB DLSR: Not thirty-two bit Mask */ + +#define DIB_DLSR_SLK_Pos 1U /*!< DIB DLSR: Software Lock status Position */ +#define DIB_DLSR_SLK_Msk (0x1UL << DIB_DLSR_SLK_Pos ) /*!< DIB DLSR: Software Lock status Mask */ + +#define DIB_DLSR_SLI_Pos 0U /*!< DIB DLSR: Software Lock implemented Position */ +#define DIB_DLSR_SLI_Msk (0x1UL /*<< DIB_DLSR_SLI_Pos*/) /*!< DIB DLSR: Software Lock implemented Mask */ + +/* DAUTHSTATUS, Debug Authentication Status Register Definitions */ +#define DIB_DAUTHSTATUS_SUNID_Pos 22U /*!< DIB DAUTHSTATUS: Secure Unprivileged Non-invasive Debug Allowed Position */ +#define DIB_DAUTHSTATUS_SUNID_Msk (0x3UL << DIB_DAUTHSTATUS_SUNID_Pos ) /*!< DIB DAUTHSTATUS: Secure Unprivileged Non-invasive Debug Allowed Mask */ + +#define DIB_DAUTHSTATUS_SUID_Pos 20U /*!< DIB DAUTHSTATUS: Secure Unprivileged Invasive Debug Allowed Position */ +#define DIB_DAUTHSTATUS_SUID_Msk (0x3UL << DIB_DAUTHSTATUS_SUID_Pos ) /*!< DIB DAUTHSTATUS: Secure Unprivileged Invasive Debug Allowed Mask */ + +#define DIB_DAUTHSTATUS_NSUNID_Pos 18U /*!< DIB DAUTHSTATUS: Non-secure Unprivileged Non-invasive Debug Allo Position */ +#define DIB_DAUTHSTATUS_NSUNID_Msk (0x3UL << DIB_DAUTHSTATUS_NSUNID_Pos ) /*!< DIB DAUTHSTATUS: Non-secure Unprivileged Non-invasive Debug Allo Mask */ + +#define DIB_DAUTHSTATUS_NSUID_Pos 16U /*!< DIB DAUTHSTATUS: Non-secure Unprivileged Invasive Debug Allowed Position */ +#define DIB_DAUTHSTATUS_NSUID_Msk (0x3UL << DIB_DAUTHSTATUS_NSUID_Pos ) /*!< DIB DAUTHSTATUS: Non-secure Unprivileged Invasive Debug Allowed Mask */ + +#define DIB_DAUTHSTATUS_SNID_Pos 6U /*!< DIB DAUTHSTATUS: Secure Non-invasive Debug Position */ +#define DIB_DAUTHSTATUS_SNID_Msk (0x3UL << DIB_DAUTHSTATUS_SNID_Pos ) /*!< DIB DAUTHSTATUS: Secure Non-invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_SID_Pos 4U /*!< DIB DAUTHSTATUS: Secure Invasive Debug Position */ +#define DIB_DAUTHSTATUS_SID_Msk (0x3UL << DIB_DAUTHSTATUS_SID_Pos ) /*!< DIB DAUTHSTATUS: Secure Invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_NSNID_Pos 2U /*!< DIB DAUTHSTATUS: Non-secure Non-invasive Debug Position */ +#define DIB_DAUTHSTATUS_NSNID_Msk (0x3UL << DIB_DAUTHSTATUS_NSNID_Pos ) /*!< DIB DAUTHSTATUS: Non-secure Non-invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_NSID_Pos 0U /*!< DIB DAUTHSTATUS: Non-secure Invasive Debug Position */ +#define DIB_DAUTHSTATUS_NSID_Msk (0x3UL /*<< DIB_DAUTHSTATUS_NSID_Pos*/) /*!< DIB DAUTHSTATUS: Non-secure Invasive Debug Mask */ + +/* DDEVARCH, SCS Device Architecture Register Definitions */ +#define DIB_DDEVARCH_ARCHITECT_Pos 21U /*!< DIB DDEVARCH: Architect Position */ +#define DIB_DDEVARCH_ARCHITECT_Msk (0x7FFUL << DIB_DDEVARCH_ARCHITECT_Pos ) /*!< DIB DDEVARCH: Architect Mask */ + +#define DIB_DDEVARCH_PRESENT_Pos 20U /*!< DIB DDEVARCH: DEVARCH Present Position */ +#define DIB_DDEVARCH_PRESENT_Msk (0x1FUL << DIB_DDEVARCH_PRESENT_Pos ) /*!< DIB DDEVARCH: DEVARCH Present Mask */ + +#define DIB_DDEVARCH_REVISION_Pos 16U /*!< DIB DDEVARCH: Revision Position */ +#define DIB_DDEVARCH_REVISION_Msk (0xFUL << DIB_DDEVARCH_REVISION_Pos ) /*!< DIB DDEVARCH: Revision Mask */ + +#define DIB_DDEVARCH_ARCHVER_Pos 12U /*!< DIB DDEVARCH: Architecture Version Position */ +#define DIB_DDEVARCH_ARCHVER_Msk (0xFUL << DIB_DDEVARCH_ARCHVER_Pos ) /*!< DIB DDEVARCH: Architecture Version Mask */ + +#define DIB_DDEVARCH_ARCHPART_Pos 0U /*!< DIB DDEVARCH: Architecture Part Position */ +#define DIB_DDEVARCH_ARCHPART_Msk (0xFFFUL /*<< DIB_DDEVARCH_ARCHPART_Pos*/) /*!< DIB DDEVARCH: Architecture Part Mask */ + +/* DDEVTYPE, SCS Device Type Register Definitions */ +#define DIB_DDEVTYPE_SUB_Pos 4U /*!< DIB DDEVTYPE: Sub-type Position */ +#define DIB_DDEVTYPE_SUB_Msk (0xFUL << DIB_DDEVTYPE_SUB_Pos ) /*!< DIB DDEVTYPE: Sub-type Mask */ + +#define DIB_DDEVTYPE_MAJOR_Pos 0U /*!< DIB DDEVTYPE: Major type Position */ +#define DIB_DDEVTYPE_MAJOR_Msk (0xFUL /*<< DIB_DDEVTYPE_MAJOR_Pos*/) /*!< DIB DDEVTYPE: Major type Mask */ + + +/*@} end of group CMSIS_DIB */ + + /** \ingroup CMSIS_core_register \defgroup CMSIS_core_bitfield Core register bit field macros @@ -2035,7 +3095,9 @@ typedef struct #define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */ #define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */ #define TPI_BASE (0xE0040000UL) /*!< TPI Base Address */ - #define CoreDebug_BASE (0xE000EDF0UL) /*!< Core Debug Base Address */ + #define CoreDebug_BASE (0xE000EDF0UL) /*!< \deprecated Core Debug Base Address */ + #define DCB_BASE (0xE000EDF0UL) /*!< DCB Base Address */ + #define DIB_BASE (0xE000EFB0UL) /*!< DIB Base Address */ #define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */ #define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */ #define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */ @@ -2047,13 +3109,20 @@ typedef struct #define ITM ((ITM_Type *) ITM_BASE ) /*!< ITM configuration struct */ #define DWT ((DWT_Type *) DWT_BASE ) /*!< DWT configuration struct */ #define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct */ - #define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE ) /*!< Core Debug configuration struct */ + #define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE ) /*!< \deprecated Core Debug configuration struct */ + #define DCB ((DCB_Type *) DCB_BASE ) /*!< DCB configuration struct */ + #define DIB ((DIB_Type *) DIB_BASE ) /*!< DIB configuration struct */ #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */ #define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */ #endif + #if defined (__PMU_PRESENT) && (__PMU_PRESENT == 1U) + #define PMU_BASE (0xE0003000UL) /*!< PMU Base Address */ + #define PMU ((PMU_Type *) PMU_BASE ) /*!< PMU configuration struct */ + #endif + #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) #define SAU_BASE (SCS_BASE + 0x0DD0UL) /*!< Security Attribution Unit */ #define SAU ((SAU_Type *) SAU_BASE ) /*!< Security Attribution Unit */ @@ -2064,7 +3133,9 @@ typedef struct #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) #define SCS_BASE_NS (0xE002E000UL) /*!< System Control Space Base Address (non-secure address space) */ - #define CoreDebug_BASE_NS (0xE002EDF0UL) /*!< Core Debug Base Address (non-secure address space) */ + #define CoreDebug_BASE_NS (0xE002EDF0UL) /*!< \deprecated Core Debug Base Address (non-secure address space) */ + #define DCB_BASE_NS (0xE002EDF0UL) /*!< DCB Base Address (non-secure address space) */ + #define DIB_BASE_NS (0xE002EFB0UL) /*!< DIB Base Address (non-secure address space) */ #define SysTick_BASE_NS (SCS_BASE_NS + 0x0010UL) /*!< SysTick Base Address (non-secure address space) */ #define NVIC_BASE_NS (SCS_BASE_NS + 0x0100UL) /*!< NVIC Base Address (non-secure address space) */ #define SCB_BASE_NS (SCS_BASE_NS + 0x0D00UL) /*!< System Control Block Base Address (non-secure address space) */ @@ -2073,7 +3144,9 @@ typedef struct #define SCB_NS ((SCB_Type *) SCB_BASE_NS ) /*!< SCB configuration struct (non-secure address space) */ #define SysTick_NS ((SysTick_Type *) SysTick_BASE_NS ) /*!< SysTick configuration struct (non-secure address space) */ #define NVIC_NS ((NVIC_Type *) NVIC_BASE_NS ) /*!< NVIC configuration struct (non-secure address space) */ - #define CoreDebug_NS ((CoreDebug_Type *) CoreDebug_BASE_NS) /*!< Core Debug configuration struct (non-secure address space) */ + #define CoreDebug_NS ((CoreDebug_Type *) CoreDebug_BASE_NS) /*!< \deprecated Core Debug configuration struct (non-secure address space) */ + #define DCB_NS ((DCB_Type *) DCB_BASE_NS ) /*!< DCB configuration struct (non-secure address space) */ + #define DIB_NS ((DIB_Type *) DIB_BASE_NS ) /*!< DIB configuration struct (non-secure address space) */ #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) #define MPU_BASE_NS (SCS_BASE_NS + 0x0D90UL) /*!< Memory Protection Unit (non-secure address space) */ @@ -2087,6 +3160,15 @@ typedef struct /*@} */ +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_register_aliases Backwards Compatibility Aliases + \brief Register alias definitions for backwards compatibility. + @{ + */ +#define ID_ADR (ID_AFR) /*!< SCB Auxiliary Feature Register */ +/*@} */ + /******************************************************************************* * Hardware Abstraction Layer @@ -2143,6 +3225,27 @@ typedef struct #define NVIC_USER_IRQ_OFFSET 16 +/* Special LR values for Secure/Non-Secure call handling and exception handling */ + +/* Function Return Payload (from ARMv8-M Architecture Reference Manual) LR value on entry from Secure BLXNS */ +#define FNC_RETURN (0xFEFFFFFFUL) /* bit [0] ignored when processing a branch */ + +/* The following EXC_RETURN mask values are used to evaluate the LR on exception entry */ +#define EXC_RETURN_PREFIX (0xFF000000UL) /* bits [31:24] set to indicate an EXC_RETURN value */ +#define EXC_RETURN_S (0x00000040UL) /* bit [6] stack used to push registers: 0=Non-secure 1=Secure */ +#define EXC_RETURN_DCRS (0x00000020UL) /* bit [5] stacking rules for called registers: 0=skipped 1=saved */ +#define EXC_RETURN_FTYPE (0x00000010UL) /* bit [4] allocate stack for floating-point context: 0=done 1=skipped */ +#define EXC_RETURN_MODE (0x00000008UL) /* bit [3] processor mode for return: 0=Handler mode 1=Thread mode */ +#define EXC_RETURN_SPSEL (0x00000004UL) /* bit [2] stack pointer used to restore context: 0=MSP 1=PSP */ +#define EXC_RETURN_ES (0x00000001UL) /* bit [0] security state exception was taken to: 0=Non-secure 1=Secure */ + +/* Integrity Signature (from ARMv8-M Architecture Reference Manual) for exception context stacking */ +#if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) /* Value for processors with floating-point extension: */ +#define EXC_INTEGRITY_SIGNATURE (0xFEFA125AUL) /* bit [0] SFTC must match LR bit[4] EXC_RETURN_FTYPE */ +#else +#define EXC_INTEGRITY_SIGNATURE (0xFEFA125BUL) /* Value for processors without floating-point extension */ +#endif + /** \brief Set Priority Grouping @@ -2162,7 +3265,7 @@ __STATIC_INLINE void __NVIC_SetPriorityGrouping(uint32_t PriorityGroup) reg_value &= ~((uint32_t)(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk)); /* clear bits to change */ reg_value = (reg_value | ((uint32_t)0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | - (PriorityGroupTmp << 8U) ); /* Insert write key and priorty group */ + (PriorityGroupTmp << SCB_AIRCR_PRIGROUP_Pos) ); /* Insert write key and priority group */ SCB->AIRCR = reg_value; } @@ -2188,7 +3291,9 @@ __STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) { if ((int32_t)(IRQn) >= 0) { + __COMPILER_BARRIER(); NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __COMPILER_BARRIER(); } } @@ -2480,6 +3585,7 @@ __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) { uint32_t *vectors = (uint32_t *)SCB->VTOR; vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector; + __DSB(); } @@ -2536,7 +3642,7 @@ __STATIC_INLINE void TZ_NVIC_SetPriorityGrouping_NS(uint32_t PriorityGroup) reg_value &= ~((uint32_t)(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk)); /* clear bits to change */ reg_value = (reg_value | ((uint32_t)0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | - (PriorityGroupTmp << 8U) ); /* Insert write key and priorty group */ + (PriorityGroupTmp << SCB_AIRCR_PRIGROUP_Pos) ); /* Insert write key and priority group */ SCB_NS->AIRCR = reg_value; } @@ -2729,6 +3835,14 @@ __STATIC_INLINE uint32_t TZ_NVIC_GetPriority_NS(IRQn_Type IRQn) #endif +/* ########################## PMU functions and events #################################### */ + +#if defined (__PMU_PRESENT) && (__PMU_PRESENT == 1U) + +#include "pmu_armv8.h" + +#endif + /* ########################## FPU functions #################################### */ /** \ingroup CMSIS_Core_FunctionInterface @@ -2750,11 +3864,11 @@ __STATIC_INLINE uint32_t SCB_GetFPUType(void) uint32_t mvfr0; mvfr0 = FPU->MVFR0; - if ((mvfr0 & (FPU_MVFR0_Single_precision_Msk | FPU_MVFR0_Double_precision_Msk)) == 0x220U) + if ((mvfr0 & (FPU_MVFR0_FPSP_Msk | FPU_MVFR0_FPDP_Msk)) == 0x220U) { return 2U; /* Double + Single precision FPU */ } - else if ((mvfr0 & (FPU_MVFR0_Single_precision_Msk | FPU_MVFR0_Double_precision_Msk)) == 0x020U) + else if ((mvfr0 & (FPU_MVFR0_FPSP_Msk | FPU_MVFR0_FPDP_Msk)) == 0x020U) { return 1U; /* Single precision FPU */ } @@ -2767,6 +3881,49 @@ __STATIC_INLINE uint32_t SCB_GetFPUType(void) /*@} end of CMSIS_Core_FpuFunctions */ +/* ########################## MVE functions #################################### */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_MveFunctions MVE Functions + \brief Function that provides MVE type. + @{ + */ + +/** + \brief get MVE type + \details returns the MVE type + \returns + - \b 0: No Vector Extension (MVE) + - \b 1: Integer Vector Extension (MVE-I) + - \b 2: Floating-point Vector Extension (MVE-F) + */ +__STATIC_INLINE uint32_t SCB_GetMVEType(void) +{ + const uint32_t mvfr1 = FPU->MVFR1; + if ((mvfr1 & FPU_MVFR1_MVE_Msk) == (0x2U << FPU_MVFR1_MVE_Pos)) + { + return 2U; + } + else if ((mvfr1 & FPU_MVFR1_MVE_Msk) == (0x1U << FPU_MVFR1_MVE_Pos)) + { + return 1U; + } + else + { + return 0U; + } +} + + +/*@} end of CMSIS_Core_MveFunctions */ + + +/* ########################## Cache functions #################################### */ + +#if ((defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U)) || \ + (defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U))) +#include "cachel1_armv7.h" +#endif /* ########################## SAU functions #################################### */ @@ -2806,6 +3963,110 @@ __STATIC_INLINE void TZ_SAU_Disable(void) +/* ################################## Debug Control function ############################################ */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_DCBFunctions Debug Control Functions + \brief Functions that access the Debug Control Block. + @{ + */ + + +/** + \brief Set Debug Authentication Control Register + \details writes to Debug Authentication Control register. + \param [in] value value to be writen. + */ +__STATIC_INLINE void DCB_SetAuthCtrl(uint32_t value) +{ + __DSB(); + __ISB(); + DCB->DAUTHCTRL = value; + __DSB(); + __ISB(); +} + + +/** + \brief Get Debug Authentication Control Register + \details Reads Debug Authentication Control register. + \return Debug Authentication Control Register. + */ +__STATIC_INLINE uint32_t DCB_GetAuthCtrl(void) +{ + return (DCB->DAUTHCTRL); +} + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief Set Debug Authentication Control Register (non-secure) + \details writes to non-secure Debug Authentication Control register when in secure state. + \param [in] value value to be writen + */ +__STATIC_INLINE void TZ_DCB_SetAuthCtrl_NS(uint32_t value) +{ + __DSB(); + __ISB(); + DCB_NS->DAUTHCTRL = value; + __DSB(); + __ISB(); +} + + +/** + \brief Get Debug Authentication Control Register (non-secure) + \details Reads non-secure Debug Authentication Control register when in secure state. + \return Debug Authentication Control Register. + */ +__STATIC_INLINE uint32_t TZ_DCB_GetAuthCtrl_NS(void) +{ + return (DCB_NS->DAUTHCTRL); +} +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + +/*@} end of CMSIS_Core_DCBFunctions */ + + + + +/* ################################## Debug Identification function ############################################ */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_DIBFunctions Debug Identification Functions + \brief Functions that access the Debug Identification Block. + @{ + */ + + +/** + \brief Get Debug Authentication Status Register + \details Reads Debug Authentication Status register. + \return Debug Authentication Status Register. + */ +__STATIC_INLINE uint32_t DIB_GetAuthStatus(void) +{ + return (DIB->DAUTHSTATUS); +} + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief Get Debug Authentication Status Register (non-secure) + \details Reads non-secure Debug Authentication Status register when in secure state. + \return Debug Authentication Status Register. + */ +__STATIC_INLINE uint32_t TZ_DIB_GetAuthStatus_NS(void) +{ + return (DIB_NS->DAUTHSTATUS); +} +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + +/*@} end of CMSIS_Core_DCBFunctions */ + + + + /* ################################## SysTick function ############################################ */ /** \ingroup CMSIS_Core_FunctionInterface diff --git a/lib/cmsis/inc/core_armv8mbl.h b/lib/cmsis/inc/core_armv8mbl.h index 57d9f663fd3ed..932d3d188bfa0 100644 --- a/lib/cmsis/inc/core_armv8mbl.h +++ b/lib/cmsis/inc/core_armv8mbl.h @@ -1,11 +1,11 @@ /**************************************************************************//** * @file core_armv8mbl.h * @brief CMSIS Armv8-M Baseline Core Peripheral Access Layer Header File - * @version V5.0.8 - * @date 12. November 2018 + * @version V5.1.0 + * @date 27. March 2020 ******************************************************************************/ /* - * Copyright (c) 2009-2018 Arm Limited. All rights reserved. + * Copyright (c) 2009-2020 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -23,9 +23,11 @@ */ #if defined ( __ICCARM__ ) - #pragma system_include /* treat file as system include file for MISRA check */ + #pragma system_include /* treat file as system include file for MISRA check */ #elif defined (__clang__) - #pragma clang system_header /* treat file as system include file */ + #pragma clang system_header /* treat file as system include file */ +#elif defined ( __GNUC__ ) + #pragma GCC diagnostic ignored "-Wpedantic" /* disable pedantic warning due to unnamed structs/unions */ #endif #ifndef __CORE_ARMV8MBL_H_GENERIC @@ -68,7 +70,7 @@ #define __ARMv8MBL_CMSIS_VERSION ((__ARMv8MBL_CMSIS_VERSION_MAIN << 16U) | \ __ARMv8MBL_CMSIS_VERSION_SUB ) /*!< \deprecated CMSIS HAL version number */ -#define __CORTEX_M ( 2U) /*!< Cortex-M Core */ +#define __CORTEX_M (2U) /*!< Cortex-M Core */ /** __FPU_USED indicates whether an FPU is used or not. This core does not support an FPU at all @@ -975,6 +977,7 @@ typedef struct #endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ +/* CoreDebug is deprecated. replaced by DCB (Debug Control Block) */ /** \ingroup CMSIS_core_register \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug) @@ -983,7 +986,7 @@ typedef struct */ /** - \brief Structure type to access the Core Debug Register (CoreDebug). + \brief \deprecated Structure type to access the Core Debug Register (CoreDebug). */ typedef struct { @@ -991,91 +994,276 @@ typedef struct __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ - uint32_t RESERVED4[1U]; + uint32_t RESERVED0[1U]; __IOM uint32_t DAUTHCTRL; /*!< Offset: 0x014 (R/W) Debug Authentication Control Register */ __IOM uint32_t DSCSR; /*!< Offset: 0x018 (R/W) Debug Security Control and Status Register */ } CoreDebug_Type; /* Debug Halting Control and Status Register Definitions */ -#define CoreDebug_DHCSR_DBGKEY_Pos 16U /*!< CoreDebug DHCSR: DBGKEY Position */ -#define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos) /*!< CoreDebug DHCSR: DBGKEY Mask */ +#define CoreDebug_DHCSR_DBGKEY_Pos 16U /*!< \deprecated CoreDebug DHCSR: DBGKEY Position */ +#define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos) /*!< \deprecated CoreDebug DHCSR: DBGKEY Mask */ -#define CoreDebug_DHCSR_S_RESTART_ST_Pos 26U /*!< CoreDebug DHCSR: S_RESTART_ST Position */ -#define CoreDebug_DHCSR_S_RESTART_ST_Msk (1UL << CoreDebug_DHCSR_S_RESTART_ST_Pos) /*!< CoreDebug DHCSR: S_RESTART_ST Mask */ +#define CoreDebug_DHCSR_S_RESTART_ST_Pos 26U /*!< \deprecated CoreDebug DHCSR: S_RESTART_ST Position */ +#define CoreDebug_DHCSR_S_RESTART_ST_Msk (1UL << CoreDebug_DHCSR_S_RESTART_ST_Pos) /*!< \deprecated CoreDebug DHCSR: S_RESTART_ST Mask */ -#define CoreDebug_DHCSR_S_RESET_ST_Pos 25U /*!< CoreDebug DHCSR: S_RESET_ST Position */ -#define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< CoreDebug DHCSR: S_RESET_ST Mask */ +#define CoreDebug_DHCSR_S_RESET_ST_Pos 25U /*!< \deprecated CoreDebug DHCSR: S_RESET_ST Position */ +#define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< \deprecated CoreDebug DHCSR: S_RESET_ST Mask */ -#define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24U /*!< CoreDebug DHCSR: S_RETIRE_ST Position */ -#define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< CoreDebug DHCSR: S_RETIRE_ST Mask */ +#define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24U /*!< \deprecated CoreDebug DHCSR: S_RETIRE_ST Position */ +#define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< \deprecated CoreDebug DHCSR: S_RETIRE_ST Mask */ -#define CoreDebug_DHCSR_S_LOCKUP_Pos 19U /*!< CoreDebug DHCSR: S_LOCKUP Position */ -#define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< CoreDebug DHCSR: S_LOCKUP Mask */ +#define CoreDebug_DHCSR_S_LOCKUP_Pos 19U /*!< \deprecated CoreDebug DHCSR: S_LOCKUP Position */ +#define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< \deprecated CoreDebug DHCSR: S_LOCKUP Mask */ -#define CoreDebug_DHCSR_S_SLEEP_Pos 18U /*!< CoreDebug DHCSR: S_SLEEP Position */ -#define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< CoreDebug DHCSR: S_SLEEP Mask */ +#define CoreDebug_DHCSR_S_SLEEP_Pos 18U /*!< \deprecated CoreDebug DHCSR: S_SLEEP Position */ +#define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< \deprecated CoreDebug DHCSR: S_SLEEP Mask */ -#define CoreDebug_DHCSR_S_HALT_Pos 17U /*!< CoreDebug DHCSR: S_HALT Position */ -#define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos) /*!< CoreDebug DHCSR: S_HALT Mask */ +#define CoreDebug_DHCSR_S_HALT_Pos 17U /*!< \deprecated CoreDebug DHCSR: S_HALT Position */ +#define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos) /*!< \deprecated CoreDebug DHCSR: S_HALT Mask */ -#define CoreDebug_DHCSR_S_REGRDY_Pos 16U /*!< CoreDebug DHCSR: S_REGRDY Position */ -#define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< CoreDebug DHCSR: S_REGRDY Mask */ +#define CoreDebug_DHCSR_S_REGRDY_Pos 16U /*!< \deprecated CoreDebug DHCSR: S_REGRDY Position */ +#define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< \deprecated CoreDebug DHCSR: S_REGRDY Mask */ -#define CoreDebug_DHCSR_C_MASKINTS_Pos 3U /*!< CoreDebug DHCSR: C_MASKINTS Position */ -#define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< CoreDebug DHCSR: C_MASKINTS Mask */ +#define CoreDebug_DHCSR_C_MASKINTS_Pos 3U /*!< \deprecated CoreDebug DHCSR: C_MASKINTS Position */ +#define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< \deprecated CoreDebug DHCSR: C_MASKINTS Mask */ -#define CoreDebug_DHCSR_C_STEP_Pos 2U /*!< CoreDebug DHCSR: C_STEP Position */ -#define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos) /*!< CoreDebug DHCSR: C_STEP Mask */ +#define CoreDebug_DHCSR_C_STEP_Pos 2U /*!< \deprecated CoreDebug DHCSR: C_STEP Position */ +#define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos) /*!< \deprecated CoreDebug DHCSR: C_STEP Mask */ -#define CoreDebug_DHCSR_C_HALT_Pos 1U /*!< CoreDebug DHCSR: C_HALT Position */ -#define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos) /*!< CoreDebug DHCSR: C_HALT Mask */ +#define CoreDebug_DHCSR_C_HALT_Pos 1U /*!< \deprecated CoreDebug DHCSR: C_HALT Position */ +#define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos) /*!< \deprecated CoreDebug DHCSR: C_HALT Mask */ -#define CoreDebug_DHCSR_C_DEBUGEN_Pos 0U /*!< CoreDebug DHCSR: C_DEBUGEN Position */ -#define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL /*<< CoreDebug_DHCSR_C_DEBUGEN_Pos*/) /*!< CoreDebug DHCSR: C_DEBUGEN Mask */ +#define CoreDebug_DHCSR_C_DEBUGEN_Pos 0U /*!< \deprecated CoreDebug DHCSR: C_DEBUGEN Position */ +#define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL /*<< CoreDebug_DHCSR_C_DEBUGEN_Pos*/) /*!< \deprecated CoreDebug DHCSR: C_DEBUGEN Mask */ /* Debug Core Register Selector Register Definitions */ -#define CoreDebug_DCRSR_REGWnR_Pos 16U /*!< CoreDebug DCRSR: REGWnR Position */ -#define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos) /*!< CoreDebug DCRSR: REGWnR Mask */ +#define CoreDebug_DCRSR_REGWnR_Pos 16U /*!< \deprecated CoreDebug DCRSR: REGWnR Position */ +#define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos) /*!< \deprecated CoreDebug DCRSR: REGWnR Mask */ -#define CoreDebug_DCRSR_REGSEL_Pos 0U /*!< CoreDebug DCRSR: REGSEL Position */ -#define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL /*<< CoreDebug_DCRSR_REGSEL_Pos*/) /*!< CoreDebug DCRSR: REGSEL Mask */ +#define CoreDebug_DCRSR_REGSEL_Pos 0U /*!< \deprecated CoreDebug DCRSR: REGSEL Position */ +#define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL /*<< CoreDebug_DCRSR_REGSEL_Pos*/) /*!< \deprecated CoreDebug DCRSR: REGSEL Mask */ -/* Debug Exception and Monitor Control Register */ -#define CoreDebug_DEMCR_DWTENA_Pos 24U /*!< CoreDebug DEMCR: DWTENA Position */ -#define CoreDebug_DEMCR_DWTENA_Msk (1UL << CoreDebug_DEMCR_DWTENA_Pos) /*!< CoreDebug DEMCR: DWTENA Mask */ +/* Debug Exception and Monitor Control Register Definitions */ +#define CoreDebug_DEMCR_DWTENA_Pos 24U /*!< \deprecated CoreDebug DEMCR: DWTENA Position */ +#define CoreDebug_DEMCR_DWTENA_Msk (1UL << CoreDebug_DEMCR_DWTENA_Pos) /*!< \deprecated CoreDebug DEMCR: DWTENA Mask */ -#define CoreDebug_DEMCR_VC_HARDERR_Pos 10U /*!< CoreDebug DEMCR: VC_HARDERR Position */ -#define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< CoreDebug DEMCR: VC_HARDERR Mask */ +#define CoreDebug_DEMCR_VC_HARDERR_Pos 10U /*!< \deprecated CoreDebug DEMCR: VC_HARDERR Position */ +#define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_HARDERR Mask */ -#define CoreDebug_DEMCR_VC_CORERESET_Pos 0U /*!< CoreDebug DEMCR: VC_CORERESET Position */ -#define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL /*<< CoreDebug_DEMCR_VC_CORERESET_Pos*/) /*!< CoreDebug DEMCR: VC_CORERESET Mask */ +#define CoreDebug_DEMCR_VC_CORERESET_Pos 0U /*!< \deprecated CoreDebug DEMCR: VC_CORERESET Position */ +#define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL /*<< CoreDebug_DEMCR_VC_CORERESET_Pos*/) /*!< \deprecated CoreDebug DEMCR: VC_CORERESET Mask */ /* Debug Authentication Control Register Definitions */ -#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos 3U /*!< CoreDebug DAUTHCTRL: INTSPNIDEN, Position */ -#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos) /*!< CoreDebug DAUTHCTRL: INTSPNIDEN, Mask */ +#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos 3U /*!< \deprecated CoreDebug DAUTHCTRL: INTSPNIDEN, Position */ +#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: INTSPNIDEN, Mask */ -#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos 2U /*!< CoreDebug DAUTHCTRL: SPNIDENSEL Position */ -#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Msk (1UL << CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos) /*!< CoreDebug DAUTHCTRL: SPNIDENSEL Mask */ +#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos 2U /*!< \deprecated CoreDebug DAUTHCTRL: SPNIDENSEL Position */ +#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Msk (1UL << CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: SPNIDENSEL Mask */ -#define CoreDebug_DAUTHCTRL_INTSPIDEN_Pos 1U /*!< CoreDebug DAUTHCTRL: INTSPIDEN Position */ -#define CoreDebug_DAUTHCTRL_INTSPIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPIDEN_Pos) /*!< CoreDebug DAUTHCTRL: INTSPIDEN Mask */ +#define CoreDebug_DAUTHCTRL_INTSPIDEN_Pos 1U /*!< \deprecated CoreDebug DAUTHCTRL: INTSPIDEN Position */ +#define CoreDebug_DAUTHCTRL_INTSPIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPIDEN_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: INTSPIDEN Mask */ -#define CoreDebug_DAUTHCTRL_SPIDENSEL_Pos 0U /*!< CoreDebug DAUTHCTRL: SPIDENSEL Position */ -#define CoreDebug_DAUTHCTRL_SPIDENSEL_Msk (1UL /*<< CoreDebug_DAUTHCTRL_SPIDENSEL_Pos*/) /*!< CoreDebug DAUTHCTRL: SPIDENSEL Mask */ +#define CoreDebug_DAUTHCTRL_SPIDENSEL_Pos 0U /*!< \deprecated CoreDebug DAUTHCTRL: SPIDENSEL Position */ +#define CoreDebug_DAUTHCTRL_SPIDENSEL_Msk (1UL /*<< CoreDebug_DAUTHCTRL_SPIDENSEL_Pos*/) /*!< \deprecated CoreDebug DAUTHCTRL: SPIDENSEL Mask */ /* Debug Security Control and Status Register Definitions */ -#define CoreDebug_DSCSR_CDS_Pos 16U /*!< CoreDebug DSCSR: CDS Position */ -#define CoreDebug_DSCSR_CDS_Msk (1UL << CoreDebug_DSCSR_CDS_Pos) /*!< CoreDebug DSCSR: CDS Mask */ +#define CoreDebug_DSCSR_CDS_Pos 16U /*!< \deprecated CoreDebug DSCSR: CDS Position */ +#define CoreDebug_DSCSR_CDS_Msk (1UL << CoreDebug_DSCSR_CDS_Pos) /*!< \deprecated CoreDebug DSCSR: CDS Mask */ -#define CoreDebug_DSCSR_SBRSEL_Pos 1U /*!< CoreDebug DSCSR: SBRSEL Position */ -#define CoreDebug_DSCSR_SBRSEL_Msk (1UL << CoreDebug_DSCSR_SBRSEL_Pos) /*!< CoreDebug DSCSR: SBRSEL Mask */ +#define CoreDebug_DSCSR_SBRSEL_Pos 1U /*!< \deprecated CoreDebug DSCSR: SBRSEL Position */ +#define CoreDebug_DSCSR_SBRSEL_Msk (1UL << CoreDebug_DSCSR_SBRSEL_Pos) /*!< \deprecated CoreDebug DSCSR: SBRSEL Mask */ -#define CoreDebug_DSCSR_SBRSELEN_Pos 0U /*!< CoreDebug DSCSR: SBRSELEN Position */ -#define CoreDebug_DSCSR_SBRSELEN_Msk (1UL /*<< CoreDebug_DSCSR_SBRSELEN_Pos*/) /*!< CoreDebug DSCSR: SBRSELEN Mask */ +#define CoreDebug_DSCSR_SBRSELEN_Pos 0U /*!< \deprecated CoreDebug DSCSR: SBRSELEN Position */ +#define CoreDebug_DSCSR_SBRSELEN_Msk (1UL /*<< CoreDebug_DSCSR_SBRSELEN_Pos*/) /*!< \deprecated CoreDebug DSCSR: SBRSELEN Mask */ /*@} end of group CMSIS_CoreDebug */ +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_DCB Debug Control Block + \brief Type definitions for the Debug Control Block Registers + @{ + */ + +/** + \brief Structure type to access the Debug Control Block Registers (DCB). + */ +typedef struct +{ + __IOM uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */ + __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ + __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ + __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ + uint32_t RESERVED0[1U]; + __IOM uint32_t DAUTHCTRL; /*!< Offset: 0x014 (R/W) Debug Authentication Control Register */ + __IOM uint32_t DSCSR; /*!< Offset: 0x018 (R/W) Debug Security Control and Status Register */ +} DCB_Type; + +/* DHCSR, Debug Halting Control and Status Register Definitions */ +#define DCB_DHCSR_DBGKEY_Pos 16U /*!< DCB DHCSR: Debug key Position */ +#define DCB_DHCSR_DBGKEY_Msk (0xFFFFUL << DCB_DHCSR_DBGKEY_Pos) /*!< DCB DHCSR: Debug key Mask */ + +#define DCB_DHCSR_S_RESTART_ST_Pos 26U /*!< DCB DHCSR: Restart sticky status Position */ +#define DCB_DHCSR_S_RESTART_ST_Msk (0x1UL << DCB_DHCSR_S_RESTART_ST_Pos) /*!< DCB DHCSR: Restart sticky status Mask */ + +#define DCB_DHCSR_S_RESET_ST_Pos 25U /*!< DCB DHCSR: Reset sticky status Position */ +#define DCB_DHCSR_S_RESET_ST_Msk (0x1UL << DCB_DHCSR_S_RESET_ST_Pos) /*!< DCB DHCSR: Reset sticky status Mask */ + +#define DCB_DHCSR_S_RETIRE_ST_Pos 24U /*!< DCB DHCSR: Retire sticky status Position */ +#define DCB_DHCSR_S_RETIRE_ST_Msk (0x1UL << DCB_DHCSR_S_RETIRE_ST_Pos) /*!< DCB DHCSR: Retire sticky status Mask */ + +#define DCB_DHCSR_S_SDE_Pos 20U /*!< DCB DHCSR: Secure debug enabled Position */ +#define DCB_DHCSR_S_SDE_Msk (0x1UL << DCB_DHCSR_S_SDE_Pos) /*!< DCB DHCSR: Secure debug enabled Mask */ + +#define DCB_DHCSR_S_LOCKUP_Pos 19U /*!< DCB DHCSR: Lockup status Position */ +#define DCB_DHCSR_S_LOCKUP_Msk (0x1UL << DCB_DHCSR_S_LOCKUP_Pos) /*!< DCB DHCSR: Lockup status Mask */ + +#define DCB_DHCSR_S_SLEEP_Pos 18U /*!< DCB DHCSR: Sleeping status Position */ +#define DCB_DHCSR_S_SLEEP_Msk (0x1UL << DCB_DHCSR_S_SLEEP_Pos) /*!< DCB DHCSR: Sleeping status Mask */ + +#define DCB_DHCSR_S_HALT_Pos 17U /*!< DCB DHCSR: Halted status Position */ +#define DCB_DHCSR_S_HALT_Msk (0x1UL << DCB_DHCSR_S_HALT_Pos) /*!< DCB DHCSR: Halted status Mask */ + +#define DCB_DHCSR_S_REGRDY_Pos 16U /*!< DCB DHCSR: Register ready status Position */ +#define DCB_DHCSR_S_REGRDY_Msk (0x1UL << DCB_DHCSR_S_REGRDY_Pos) /*!< DCB DHCSR: Register ready status Mask */ + +#define DCB_DHCSR_C_MASKINTS_Pos 3U /*!< DCB DHCSR: Mask interrupts control Position */ +#define DCB_DHCSR_C_MASKINTS_Msk (0x1UL << DCB_DHCSR_C_MASKINTS_Pos) /*!< DCB DHCSR: Mask interrupts control Mask */ + +#define DCB_DHCSR_C_STEP_Pos 2U /*!< DCB DHCSR: Step control Position */ +#define DCB_DHCSR_C_STEP_Msk (0x1UL << DCB_DHCSR_C_STEP_Pos) /*!< DCB DHCSR: Step control Mask */ + +#define DCB_DHCSR_C_HALT_Pos 1U /*!< DCB DHCSR: Halt control Position */ +#define DCB_DHCSR_C_HALT_Msk (0x1UL << DCB_DHCSR_C_HALT_Pos) /*!< DCB DHCSR: Halt control Mask */ + +#define DCB_DHCSR_C_DEBUGEN_Pos 0U /*!< DCB DHCSR: Debug enable control Position */ +#define DCB_DHCSR_C_DEBUGEN_Msk (0x1UL /*<< DCB_DHCSR_C_DEBUGEN_Pos*/) /*!< DCB DHCSR: Debug enable control Mask */ + +/* DCRSR, Debug Core Register Select Register Definitions */ +#define DCB_DCRSR_REGWnR_Pos 16U /*!< DCB DCRSR: Register write/not-read Position */ +#define DCB_DCRSR_REGWnR_Msk (0x1UL << DCB_DCRSR_REGWnR_Pos) /*!< DCB DCRSR: Register write/not-read Mask */ + +#define DCB_DCRSR_REGSEL_Pos 0U /*!< DCB DCRSR: Register selector Position */ +#define DCB_DCRSR_REGSEL_Msk (0x7FUL /*<< DCB_DCRSR_REGSEL_Pos*/) /*!< DCB DCRSR: Register selector Mask */ + +/* DCRDR, Debug Core Register Data Register Definitions */ +#define DCB_DCRDR_DBGTMP_Pos 0U /*!< DCB DCRDR: Data temporary buffer Position */ +#define DCB_DCRDR_DBGTMP_Msk (0xFFFFFFFFUL /*<< DCB_DCRDR_DBGTMP_Pos*/) /*!< DCB DCRDR: Data temporary buffer Mask */ + +/* DEMCR, Debug Exception and Monitor Control Register Definitions */ +#define DCB_DEMCR_TRCENA_Pos 24U /*!< DCB DEMCR: Trace enable Position */ +#define DCB_DEMCR_TRCENA_Msk (0x1UL << DCB_DEMCR_TRCENA_Pos) /*!< DCB DEMCR: Trace enable Mask */ + +#define DCB_DEMCR_VC_HARDERR_Pos 10U /*!< DCB DEMCR: Vector Catch HardFault errors Position */ +#define DCB_DEMCR_VC_HARDERR_Msk (0x1UL << DCB_DEMCR_VC_HARDERR_Pos) /*!< DCB DEMCR: Vector Catch HardFault errors Mask */ + +#define DCB_DEMCR_VC_CORERESET_Pos 0U /*!< DCB DEMCR: Vector Catch Core reset Position */ +#define DCB_DEMCR_VC_CORERESET_Msk (0x1UL /*<< DCB_DEMCR_VC_CORERESET_Pos*/) /*!< DCB DEMCR: Vector Catch Core reset Mask */ + +/* DAUTHCTRL, Debug Authentication Control Register Definitions */ +#define DCB_DAUTHCTRL_INTSPNIDEN_Pos 3U /*!< DCB DAUTHCTRL: Internal Secure non-invasive debug enable Position */ +#define DCB_DAUTHCTRL_INTSPNIDEN_Msk (0x1UL << DCB_DAUTHCTRL_INTSPNIDEN_Pos) /*!< DCB DAUTHCTRL: Internal Secure non-invasive debug enable Mask */ + +#define DCB_DAUTHCTRL_SPNIDENSEL_Pos 2U /*!< DCB DAUTHCTRL: Secure non-invasive debug enable select Position */ +#define DCB_DAUTHCTRL_SPNIDENSEL_Msk (0x1UL << DCB_DAUTHCTRL_SPNIDENSEL_Pos) /*!< DCB DAUTHCTRL: Secure non-invasive debug enable select Mask */ + +#define DCB_DAUTHCTRL_INTSPIDEN_Pos 1U /*!< DCB DAUTHCTRL: Internal Secure invasive debug enable Position */ +#define DCB_DAUTHCTRL_INTSPIDEN_Msk (0x1UL << DCB_DAUTHCTRL_INTSPIDEN_Pos) /*!< DCB DAUTHCTRL: Internal Secure invasive debug enable Mask */ + +#define DCB_DAUTHCTRL_SPIDENSEL_Pos 0U /*!< DCB DAUTHCTRL: Secure invasive debug enable select Position */ +#define DCB_DAUTHCTRL_SPIDENSEL_Msk (0x1UL /*<< DCB_DAUTHCTRL_SPIDENSEL_Pos*/) /*!< DCB DAUTHCTRL: Secure invasive debug enable select Mask */ + +/* DSCSR, Debug Security Control and Status Register Definitions */ +#define DCB_DSCSR_CDSKEY_Pos 17U /*!< DCB DSCSR: CDS write-enable key Position */ +#define DCB_DSCSR_CDSKEY_Msk (0x1UL << DCB_DSCSR_CDSKEY_Pos) /*!< DCB DSCSR: CDS write-enable key Mask */ + +#define DCB_DSCSR_CDS_Pos 16U /*!< DCB DSCSR: Current domain Secure Position */ +#define DCB_DSCSR_CDS_Msk (0x1UL << DCB_DSCSR_CDS_Pos) /*!< DCB DSCSR: Current domain Secure Mask */ + +#define DCB_DSCSR_SBRSEL_Pos 1U /*!< DCB DSCSR: Secure banked register select Position */ +#define DCB_DSCSR_SBRSEL_Msk (0x1UL << DCB_DSCSR_SBRSEL_Pos) /*!< DCB DSCSR: Secure banked register select Mask */ + +#define DCB_DSCSR_SBRSELEN_Pos 0U /*!< DCB DSCSR: Secure banked register select enable Position */ +#define DCB_DSCSR_SBRSELEN_Msk (0x1UL /*<< DCB_DSCSR_SBRSELEN_Pos*/) /*!< DCB DSCSR: Secure banked register select enable Mask */ + +/*@} end of group CMSIS_DCB */ + + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_DIB Debug Identification Block + \brief Type definitions for the Debug Identification Block Registers + @{ + */ + +/** + \brief Structure type to access the Debug Identification Block Registers (DIB). + */ +typedef struct +{ + __OM uint32_t DLAR; /*!< Offset: 0x000 ( /W) SCS Software Lock Access Register */ + __IM uint32_t DLSR; /*!< Offset: 0x004 (R/ ) SCS Software Lock Status Register */ + __IM uint32_t DAUTHSTATUS; /*!< Offset: 0x008 (R/ ) Debug Authentication Status Register */ + __IM uint32_t DDEVARCH; /*!< Offset: 0x00C (R/ ) SCS Device Architecture Register */ + __IM uint32_t DDEVTYPE; /*!< Offset: 0x010 (R/ ) SCS Device Type Register */ +} DIB_Type; + +/* DLAR, SCS Software Lock Access Register Definitions */ +#define DIB_DLAR_KEY_Pos 0U /*!< DIB DLAR: KEY Position */ +#define DIB_DLAR_KEY_Msk (0xFFFFFFFFUL /*<< DIB_DLAR_KEY_Pos */) /*!< DIB DLAR: KEY Mask */ + +/* DLSR, SCS Software Lock Status Register Definitions */ +#define DIB_DLSR_nTT_Pos 2U /*!< DIB DLSR: Not thirty-two bit Position */ +#define DIB_DLSR_nTT_Msk (0x1UL << DIB_DLSR_nTT_Pos ) /*!< DIB DLSR: Not thirty-two bit Mask */ + +#define DIB_DLSR_SLK_Pos 1U /*!< DIB DLSR: Software Lock status Position */ +#define DIB_DLSR_SLK_Msk (0x1UL << DIB_DLSR_SLK_Pos ) /*!< DIB DLSR: Software Lock status Mask */ + +#define DIB_DLSR_SLI_Pos 0U /*!< DIB DLSR: Software Lock implemented Position */ +#define DIB_DLSR_SLI_Msk (0x1UL /*<< DIB_DLSR_SLI_Pos*/) /*!< DIB DLSR: Software Lock implemented Mask */ + +/* DAUTHSTATUS, Debug Authentication Status Register Definitions */ +#define DIB_DAUTHSTATUS_SNID_Pos 6U /*!< DIB DAUTHSTATUS: Secure Non-invasive Debug Position */ +#define DIB_DAUTHSTATUS_SNID_Msk (0x3UL << DIB_DAUTHSTATUS_SNID_Pos ) /*!< DIB DAUTHSTATUS: Secure Non-invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_SID_Pos 4U /*!< DIB DAUTHSTATUS: Secure Invasive Debug Position */ +#define DIB_DAUTHSTATUS_SID_Msk (0x3UL << DIB_DAUTHSTATUS_SID_Pos ) /*!< DIB DAUTHSTATUS: Secure Invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_NSNID_Pos 2U /*!< DIB DAUTHSTATUS: Non-secure Non-invasive Debug Position */ +#define DIB_DAUTHSTATUS_NSNID_Msk (0x3UL << DIB_DAUTHSTATUS_NSNID_Pos ) /*!< DIB DAUTHSTATUS: Non-secure Non-invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_NSID_Pos 0U /*!< DIB DAUTHSTATUS: Non-secure Invasive Debug Position */ +#define DIB_DAUTHSTATUS_NSID_Msk (0x3UL /*<< DIB_DAUTHSTATUS_NSID_Pos*/) /*!< DIB DAUTHSTATUS: Non-secure Invasive Debug Mask */ + +/* DDEVARCH, SCS Device Architecture Register Definitions */ +#define DIB_DDEVARCH_ARCHITECT_Pos 21U /*!< DIB DDEVARCH: Architect Position */ +#define DIB_DDEVARCH_ARCHITECT_Msk (0x7FFUL << DIB_DDEVARCH_ARCHITECT_Pos ) /*!< DIB DDEVARCH: Architect Mask */ + +#define DIB_DDEVARCH_PRESENT_Pos 20U /*!< DIB DDEVARCH: DEVARCH Present Position */ +#define DIB_DDEVARCH_PRESENT_Msk (0x1FUL << DIB_DDEVARCH_PRESENT_Pos ) /*!< DIB DDEVARCH: DEVARCH Present Mask */ + +#define DIB_DDEVARCH_REVISION_Pos 16U /*!< DIB DDEVARCH: Revision Position */ +#define DIB_DDEVARCH_REVISION_Msk (0xFUL << DIB_DDEVARCH_REVISION_Pos ) /*!< DIB DDEVARCH: Revision Mask */ + +#define DIB_DDEVARCH_ARCHVER_Pos 12U /*!< DIB DDEVARCH: Architecture Version Position */ +#define DIB_DDEVARCH_ARCHVER_Msk (0xFUL << DIB_DDEVARCH_ARCHVER_Pos ) /*!< DIB DDEVARCH: Architecture Version Mask */ + +#define DIB_DDEVARCH_ARCHPART_Pos 0U /*!< DIB DDEVARCH: Architecture Part Position */ +#define DIB_DDEVARCH_ARCHPART_Msk (0xFFFUL /*<< DIB_DDEVARCH_ARCHPART_Pos*/) /*!< DIB DDEVARCH: Architecture Part Mask */ + +/* DDEVTYPE, SCS Device Type Register Definitions */ +#define DIB_DDEVTYPE_SUB_Pos 4U /*!< DIB DDEVTYPE: Sub-type Position */ +#define DIB_DDEVTYPE_SUB_Msk (0xFUL << DIB_DDEVTYPE_SUB_Pos ) /*!< DIB DDEVTYPE: Sub-type Mask */ + +#define DIB_DDEVTYPE_MAJOR_Pos 0U /*!< DIB DDEVTYPE: Major type Position */ +#define DIB_DDEVTYPE_MAJOR_Msk (0xFUL /*<< DIB_DDEVTYPE_MAJOR_Pos*/) /*!< DIB DDEVTYPE: Major type Mask */ + + +/*@} end of group CMSIS_DIB */ + + /** \ingroup CMSIS_core_register \defgroup CMSIS_core_bitfield Core register bit field macros @@ -1113,7 +1301,9 @@ typedef struct #define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */ #define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */ #define TPI_BASE (0xE0040000UL) /*!< TPI Base Address */ - #define CoreDebug_BASE (0xE000EDF0UL) /*!< Core Debug Base Address */ + #define CoreDebug_BASE (0xE000EDF0UL) /*!< \deprecated Core Debug Base Address */ + #define DCB_BASE (0xE000EDF0UL) /*!< DCB Base Address */ + #define DIB_BASE (0xE000EFB0UL) /*!< DIB Base Address */ #define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */ #define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */ #define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */ @@ -1124,7 +1314,9 @@ typedef struct #define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */ #define DWT ((DWT_Type *) DWT_BASE ) /*!< DWT configuration struct */ #define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct */ - #define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE ) /*!< Core Debug configuration struct */ + #define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE ) /*!< \deprecated Core Debug configuration struct */ + #define DCB ((DCB_Type *) DCB_BASE ) /*!< DCB configuration struct */ + #define DIB ((DIB_Type *) DIB_BASE ) /*!< DIB configuration struct */ #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */ @@ -1138,7 +1330,9 @@ typedef struct #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) #define SCS_BASE_NS (0xE002E000UL) /*!< System Control Space Base Address (non-secure address space) */ - #define CoreDebug_BASE_NS (0xE002EDF0UL) /*!< Core Debug Base Address (non-secure address space) */ + #define CoreDebug_BASE_NS (0xE002EDF0UL) /*!< \deprecated Core Debug Base Address (non-secure address space) */ + #define DCB_BASE_NS (0xE002EDF0UL) /*!< DCB Base Address (non-secure address space) */ + #define DIB_BASE_NS (0xE002EFB0UL) /*!< DIB Base Address (non-secure address space) */ #define SysTick_BASE_NS (SCS_BASE_NS + 0x0010UL) /*!< SysTick Base Address (non-secure address space) */ #define NVIC_BASE_NS (SCS_BASE_NS + 0x0100UL) /*!< NVIC Base Address (non-secure address space) */ #define SCB_BASE_NS (SCS_BASE_NS + 0x0D00UL) /*!< System Control Block Base Address (non-secure address space) */ @@ -1146,7 +1340,9 @@ typedef struct #define SCB_NS ((SCB_Type *) SCB_BASE_NS ) /*!< SCB configuration struct (non-secure address space) */ #define SysTick_NS ((SysTick_Type *) SysTick_BASE_NS ) /*!< SysTick configuration struct (non-secure address space) */ #define NVIC_NS ((NVIC_Type *) NVIC_BASE_NS ) /*!< NVIC configuration struct (non-secure address space) */ - #define CoreDebug_NS ((CoreDebug_Type *) CoreDebug_BASE_NS) /*!< Core Debug configuration struct (non-secure address space) */ + #define CoreDebug_NS ((CoreDebug_Type *) CoreDebug_BASE_NS) /*!< \deprecated Core Debug configuration struct (non-secure address space) */ + #define DCB_NS ((DCB_Type *) DCB_BASE_NS ) /*!< DCB configuration struct (non-secure address space) */ + #define DIB_NS ((DIB_Type *) DIB_BASE_NS ) /*!< DIB configuration struct (non-secure address space) */ #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) #define MPU_BASE_NS (SCS_BASE_NS + 0x0D90UL) /*!< Memory Protection Unit (non-secure address space) */ @@ -1163,6 +1359,7 @@ typedef struct Core Function Interface contains: - Core NVIC Functions - Core SysTick Functions + - Core Debug Functions - Core Register Access Functions ******************************************************************************/ /** @@ -1253,7 +1450,9 @@ __STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) { if ((int32_t)(IRQn) >= 0) { + __COMPILER_BARRIER(); NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __COMPILER_BARRIER(); } } @@ -1552,6 +1751,7 @@ __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) uint32_t *vectors = (uint32_t *)0x0U; #endif vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector; + __DSB(); } @@ -1835,6 +2035,110 @@ __STATIC_INLINE void TZ_SAU_Disable(void) +/* ################################## Debug Control function ############################################ */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_DCBFunctions Debug Control Functions + \brief Functions that access the Debug Control Block. + @{ + */ + + +/** + \brief Set Debug Authentication Control Register + \details writes to Debug Authentication Control register. + \param [in] value value to be writen. + */ +__STATIC_INLINE void DCB_SetAuthCtrl(uint32_t value) +{ + __DSB(); + __ISB(); + DCB->DAUTHCTRL = value; + __DSB(); + __ISB(); +} + + +/** + \brief Get Debug Authentication Control Register + \details Reads Debug Authentication Control register. + \return Debug Authentication Control Register. + */ +__STATIC_INLINE uint32_t DCB_GetAuthCtrl(void) +{ + return (DCB->DAUTHCTRL); +} + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief Set Debug Authentication Control Register (non-secure) + \details writes to non-secure Debug Authentication Control register when in secure state. + \param [in] value value to be writen + */ +__STATIC_INLINE void TZ_DCB_SetAuthCtrl_NS(uint32_t value) +{ + __DSB(); + __ISB(); + DCB_NS->DAUTHCTRL = value; + __DSB(); + __ISB(); +} + + +/** + \brief Get Debug Authentication Control Register (non-secure) + \details Reads non-secure Debug Authentication Control register when in secure state. + \return Debug Authentication Control Register. + */ +__STATIC_INLINE uint32_t TZ_DCB_GetAuthCtrl_NS(void) +{ + return (DCB_NS->DAUTHCTRL); +} +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + +/*@} end of CMSIS_Core_DCBFunctions */ + + + + +/* ################################## Debug Identification function ############################################ */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_DIBFunctions Debug Identification Functions + \brief Functions that access the Debug Identification Block. + @{ + */ + + +/** + \brief Get Debug Authentication Status Register + \details Reads Debug Authentication Status register. + \return Debug Authentication Status Register. + */ +__STATIC_INLINE uint32_t DIB_GetAuthStatus(void) +{ + return (DIB->DAUTHSTATUS); +} + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief Get Debug Authentication Status Register (non-secure) + \details Reads non-secure Debug Authentication Status register when in secure state. + \return Debug Authentication Status Register. + */ +__STATIC_INLINE uint32_t TZ_DIB_GetAuthStatus_NS(void) +{ + return (DIB_NS->DAUTHSTATUS); +} +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + +/*@} end of CMSIS_Core_DCBFunctions */ + + + + /* ################################## SysTick function ############################################ */ /** \ingroup CMSIS_Core_FunctionInterface diff --git a/lib/cmsis/inc/core_armv8mml.h b/lib/cmsis/inc/core_armv8mml.h index 30aab58722fc8..c119fbf242467 100644 --- a/lib/cmsis/inc/core_armv8mml.h +++ b/lib/cmsis/inc/core_armv8mml.h @@ -1,11 +1,11 @@ /**************************************************************************//** * @file core_armv8mml.h * @brief CMSIS Armv8-M Mainline Core Peripheral Access Layer Header File - * @version V5.1.0 - * @date 12. September 2018 + * @version V5.2.3 + * @date 13. October 2021 ******************************************************************************/ /* - * Copyright (c) 2009-2018 Arm Limited. All rights reserved. + * Copyright (c) 2009-2021 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -23,9 +23,11 @@ */ #if defined ( __ICCARM__ ) - #pragma system_include /* treat file as system include file for MISRA check */ + #pragma system_include /* treat file as system include file for MISRA check */ #elif defined (__clang__) - #pragma clang system_header /* treat file as system include file */ + #pragma clang system_header /* treat file as system include file */ +#elif defined ( __GNUC__ ) + #pragma GCC diagnostic ignored "-Wpedantic" /* disable pedantic warning due to unnamed structs/unions */ #endif #ifndef __CORE_ARMV8MML_H_GENERIC @@ -68,7 +70,7 @@ #define __ARMv8MML_CMSIS_VERSION ((__ARMv8MML_CMSIS_VERSION_MAIN << 16U) | \ __ARMv8MML_CMSIS_VERSION_SUB ) /*!< \deprecated CMSIS HAL version number */ -#define __CORTEX_M (81U) /*!< Cortex-M Core */ +#define __CORTEX_M (80U) /*!< Cortex-M Core */ /** __FPU_USED indicates whether an FPU is used or not. For this, __FPU_PRESENT has to be checked prior to making use of FPU specific registers and functions. @@ -248,6 +250,11 @@ #warning "__DSP_PRESENT not defined in device header file; using default!" #endif + #ifndef __VTOR_PRESENT + #define __VTOR_PRESENT 1U + #warning "__VTOR_PRESENT not defined in device header file; using default!" + #endif + #ifndef __NVIC_PRIO_BITS #define __NVIC_PRIO_BITS 3U #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" @@ -512,7 +519,7 @@ typedef struct __IOM uint32_t AFSR; /*!< Offset: 0x03C (R/W) Auxiliary Fault Status Register */ __IM uint32_t ID_PFR[2U]; /*!< Offset: 0x040 (R/ ) Processor Feature Register */ __IM uint32_t ID_DFR; /*!< Offset: 0x048 (R/ ) Debug Feature Register */ - __IM uint32_t ID_ADR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */ + __IM uint32_t ID_AFR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */ __IM uint32_t ID_MMFR[4U]; /*!< Offset: 0x050 (R/ ) Memory Model Feature Register */ __IM uint32_t ID_ISAR[6U]; /*!< Offset: 0x060 (R/ ) Instruction Set Attributes Register */ __IM uint32_t CLIDR; /*!< Offset: 0x078 (R/ ) Cache Level ID register */ @@ -521,7 +528,10 @@ typedef struct __IOM uint32_t CSSELR; /*!< Offset: 0x084 (R/W) Cache Size Selection Register */ __IOM uint32_t CPACR; /*!< Offset: 0x088 (R/W) Coprocessor Access Control Register */ __IOM uint32_t NSACR; /*!< Offset: 0x08C (R/W) Non-Secure Access Control Register */ - uint32_t RESERVED3[92U]; + uint32_t RESERVED7[21U]; + __IOM uint32_t SFSR; /*!< Offset: 0x0E4 (R/W) Secure Fault Status Register */ + __IOM uint32_t SFAR; /*!< Offset: 0x0E8 (R/W) Secure Fault Address Register */ + uint32_t RESERVED3[69U]; __OM uint32_t STIR; /*!< Offset: 0x200 ( /W) Software Triggered Interrupt Register */ uint32_t RESERVED4[15U]; __IM uint32_t MVFR0; /*!< Offset: 0x240 (R/ ) Media and VFP Feature Register 0 */ @@ -538,6 +548,7 @@ typedef struct __OM uint32_t DCCSW; /*!< Offset: 0x26C ( /W) D-Cache Clean by Set-way */ __OM uint32_t DCCIMVAC; /*!< Offset: 0x270 ( /W) D-Cache Clean and Invalidate by MVA to PoC */ __OM uint32_t DCCISW; /*!< Offset: 0x274 ( /W) D-Cache Clean and Invalidate by Set-way */ + __OM uint32_t BPIALL; /*!< Offset: 0x278 ( /W) Branch Predictor Invalidate All */ } SCB_Type; /* SCB CPUID Register Definitions */ @@ -738,22 +749,22 @@ typedef struct #define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */ /* MemManage Fault Status Register (part of SCB Configurable Fault Status Register) */ -#define SCB_CFSR_MMARVALID_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */ +#define SCB_CFSR_MMARVALID_Pos (SCB_CFSR_MEMFAULTSR_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */ #define SCB_CFSR_MMARVALID_Msk (1UL << SCB_CFSR_MMARVALID_Pos) /*!< SCB CFSR (MMFSR): MMARVALID Mask */ -#define SCB_CFSR_MLSPERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 5U) /*!< SCB CFSR (MMFSR): MLSPERR Position */ +#define SCB_CFSR_MLSPERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 5U) /*!< SCB CFSR (MMFSR): MLSPERR Position */ #define SCB_CFSR_MLSPERR_Msk (1UL << SCB_CFSR_MLSPERR_Pos) /*!< SCB CFSR (MMFSR): MLSPERR Mask */ -#define SCB_CFSR_MSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */ +#define SCB_CFSR_MSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */ #define SCB_CFSR_MSTKERR_Msk (1UL << SCB_CFSR_MSTKERR_Pos) /*!< SCB CFSR (MMFSR): MSTKERR Mask */ -#define SCB_CFSR_MUNSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */ +#define SCB_CFSR_MUNSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */ #define SCB_CFSR_MUNSTKERR_Msk (1UL << SCB_CFSR_MUNSTKERR_Pos) /*!< SCB CFSR (MMFSR): MUNSTKERR Mask */ -#define SCB_CFSR_DACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */ +#define SCB_CFSR_DACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */ #define SCB_CFSR_DACCVIOL_Msk (1UL << SCB_CFSR_DACCVIOL_Pos) /*!< SCB CFSR (MMFSR): DACCVIOL Mask */ -#define SCB_CFSR_IACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */ +#define SCB_CFSR_IACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */ #define SCB_CFSR_IACCVIOL_Msk (1UL /*<< SCB_CFSR_IACCVIOL_Pos*/) /*!< SCB CFSR (MMFSR): IACCVIOL Mask */ /* BusFault Status Register (part of SCB Configurable Fault Status Register) */ @@ -1593,8 +1604,9 @@ typedef struct __IOM uint32_t FPCCR; /*!< Offset: 0x004 (R/W) Floating-Point Context Control Register */ __IOM uint32_t FPCAR; /*!< Offset: 0x008 (R/W) Floating-Point Context Address Register */ __IOM uint32_t FPDSCR; /*!< Offset: 0x00C (R/W) Floating-Point Default Status Control Register */ - __IM uint32_t MVFR0; /*!< Offset: 0x010 (R/ ) Media and FP Feature Register 0 */ - __IM uint32_t MVFR1; /*!< Offset: 0x014 (R/ ) Media and FP Feature Register 1 */ + __IM uint32_t MVFR0; /*!< Offset: 0x010 (R/ ) Media and VFP Feature Register 0 */ + __IM uint32_t MVFR1; /*!< Offset: 0x014 (R/ ) Media and VFP Feature Register 1 */ + __IM uint32_t MVFR2; /*!< Offset: 0x018 (R/ ) Media and VFP Feature Register 2 */ } FPU_Type; /* Floating-Point Context Control Register Definitions */ @@ -1666,7 +1678,7 @@ typedef struct #define FPU_FPDSCR_RMode_Pos 22U /*!< FPDSCR: RMode bit Position */ #define FPU_FPDSCR_RMode_Msk (3UL << FPU_FPDSCR_RMode_Pos) /*!< FPDSCR: RMode bit Mask */ -/* Media and FP Feature Register 0 Definitions */ +/* Media and VFP Feature Register 0 Definitions */ #define FPU_MVFR0_FP_rounding_modes_Pos 28U /*!< MVFR0: FP rounding modes bits Position */ #define FPU_MVFR0_FP_rounding_modes_Msk (0xFUL << FPU_MVFR0_FP_rounding_modes_Pos) /*!< MVFR0: FP rounding modes bits Mask */ @@ -1691,7 +1703,7 @@ typedef struct #define FPU_MVFR0_A_SIMD_registers_Pos 0U /*!< MVFR0: A_SIMD registers bits Position */ #define FPU_MVFR0_A_SIMD_registers_Msk (0xFUL /*<< FPU_MVFR0_A_SIMD_registers_Pos*/) /*!< MVFR0: A_SIMD registers bits Mask */ -/* Media and FP Feature Register 1 Definitions */ +/* Media and VFP Feature Register 1 Definitions */ #define FPU_MVFR1_FP_fused_MAC_Pos 28U /*!< MVFR1: FP fused MAC bits Position */ #define FPU_MVFR1_FP_fused_MAC_Msk (0xFUL << FPU_MVFR1_FP_fused_MAC_Pos) /*!< MVFR1: FP fused MAC bits Mask */ @@ -1704,9 +1716,13 @@ typedef struct #define FPU_MVFR1_FtZ_mode_Pos 0U /*!< MVFR1: FtZ mode bits Position */ #define FPU_MVFR1_FtZ_mode_Msk (0xFUL /*<< FPU_MVFR1_FtZ_mode_Pos*/) /*!< MVFR1: FtZ mode bits Mask */ -/*@} end of group CMSIS_FPU */ +/* Media and VFP Feature Register 2 Definitions */ +#define FPU_MVFR2_FPMisc_Pos 4U /*!< MVFR2: FPMisc bits Position */ +#define FPU_MVFR2_FPMisc_Msk (0xFUL << FPU_MVFR2_FPMisc_Pos) /*!< MVFR2: FPMisc bits Mask */ +/*@} end of group CMSIS_FPU */ +/* CoreDebug is deprecated. replaced by DCB (Debug Control Block) */ /** \ingroup CMSIS_core_register \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug) @@ -1715,7 +1731,7 @@ typedef struct */ /** - \brief Structure type to access the Core Debug Register (CoreDebug). + \brief \deprecated Structure type to access the Core Debug Register (CoreDebug). */ typedef struct { @@ -1723,124 +1739,354 @@ typedef struct __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ - uint32_t RESERVED4[1U]; + uint32_t RESERVED0[1U]; __IOM uint32_t DAUTHCTRL; /*!< Offset: 0x014 (R/W) Debug Authentication Control Register */ __IOM uint32_t DSCSR; /*!< Offset: 0x018 (R/W) Debug Security Control and Status Register */ } CoreDebug_Type; /* Debug Halting Control and Status Register Definitions */ -#define CoreDebug_DHCSR_DBGKEY_Pos 16U /*!< CoreDebug DHCSR: DBGKEY Position */ -#define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos) /*!< CoreDebug DHCSR: DBGKEY Mask */ +#define CoreDebug_DHCSR_DBGKEY_Pos 16U /*!< \deprecated CoreDebug DHCSR: DBGKEY Position */ +#define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos) /*!< \deprecated CoreDebug DHCSR: DBGKEY Mask */ -#define CoreDebug_DHCSR_S_RESTART_ST_Pos 26U /*!< CoreDebug DHCSR: S_RESTART_ST Position */ -#define CoreDebug_DHCSR_S_RESTART_ST_Msk (1UL << CoreDebug_DHCSR_S_RESTART_ST_Pos) /*!< CoreDebug DHCSR: S_RESTART_ST Mask */ +#define CoreDebug_DHCSR_S_RESTART_ST_Pos 26U /*!< \deprecated CoreDebug DHCSR: S_RESTART_ST Position */ +#define CoreDebug_DHCSR_S_RESTART_ST_Msk (1UL << CoreDebug_DHCSR_S_RESTART_ST_Pos) /*!< \deprecated CoreDebug DHCSR: S_RESTART_ST Mask */ -#define CoreDebug_DHCSR_S_RESET_ST_Pos 25U /*!< CoreDebug DHCSR: S_RESET_ST Position */ -#define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< CoreDebug DHCSR: S_RESET_ST Mask */ +#define CoreDebug_DHCSR_S_RESET_ST_Pos 25U /*!< \deprecated CoreDebug DHCSR: S_RESET_ST Position */ +#define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< \deprecated CoreDebug DHCSR: S_RESET_ST Mask */ -#define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24U /*!< CoreDebug DHCSR: S_RETIRE_ST Position */ -#define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< CoreDebug DHCSR: S_RETIRE_ST Mask */ +#define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24U /*!< \deprecated CoreDebug DHCSR: S_RETIRE_ST Position */ +#define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< \deprecated CoreDebug DHCSR: S_RETIRE_ST Mask */ -#define CoreDebug_DHCSR_S_LOCKUP_Pos 19U /*!< CoreDebug DHCSR: S_LOCKUP Position */ -#define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< CoreDebug DHCSR: S_LOCKUP Mask */ +#define CoreDebug_DHCSR_S_LOCKUP_Pos 19U /*!< \deprecated CoreDebug DHCSR: S_LOCKUP Position */ +#define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< \deprecated CoreDebug DHCSR: S_LOCKUP Mask */ -#define CoreDebug_DHCSR_S_SLEEP_Pos 18U /*!< CoreDebug DHCSR: S_SLEEP Position */ -#define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< CoreDebug DHCSR: S_SLEEP Mask */ +#define CoreDebug_DHCSR_S_SLEEP_Pos 18U /*!< \deprecated CoreDebug DHCSR: S_SLEEP Position */ +#define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< \deprecated CoreDebug DHCSR: S_SLEEP Mask */ -#define CoreDebug_DHCSR_S_HALT_Pos 17U /*!< CoreDebug DHCSR: S_HALT Position */ -#define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos) /*!< CoreDebug DHCSR: S_HALT Mask */ +#define CoreDebug_DHCSR_S_HALT_Pos 17U /*!< \deprecated CoreDebug DHCSR: S_HALT Position */ +#define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos) /*!< \deprecated CoreDebug DHCSR: S_HALT Mask */ -#define CoreDebug_DHCSR_S_REGRDY_Pos 16U /*!< CoreDebug DHCSR: S_REGRDY Position */ -#define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< CoreDebug DHCSR: S_REGRDY Mask */ +#define CoreDebug_DHCSR_S_REGRDY_Pos 16U /*!< \deprecated CoreDebug DHCSR: S_REGRDY Position */ +#define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< \deprecated CoreDebug DHCSR: S_REGRDY Mask */ -#define CoreDebug_DHCSR_C_SNAPSTALL_Pos 5U /*!< CoreDebug DHCSR: C_SNAPSTALL Position */ -#define CoreDebug_DHCSR_C_SNAPSTALL_Msk (1UL << CoreDebug_DHCSR_C_SNAPSTALL_Pos) /*!< CoreDebug DHCSR: C_SNAPSTALL Mask */ +#define CoreDebug_DHCSR_C_SNAPSTALL_Pos 5U /*!< \deprecated CoreDebug DHCSR: C_SNAPSTALL Position */ +#define CoreDebug_DHCSR_C_SNAPSTALL_Msk (1UL << CoreDebug_DHCSR_C_SNAPSTALL_Pos) /*!< \deprecated CoreDebug DHCSR: C_SNAPSTALL Mask */ -#define CoreDebug_DHCSR_C_MASKINTS_Pos 3U /*!< CoreDebug DHCSR: C_MASKINTS Position */ -#define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< CoreDebug DHCSR: C_MASKINTS Mask */ +#define CoreDebug_DHCSR_C_MASKINTS_Pos 3U /*!< \deprecated CoreDebug DHCSR: C_MASKINTS Position */ +#define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< \deprecated CoreDebug DHCSR: C_MASKINTS Mask */ -#define CoreDebug_DHCSR_C_STEP_Pos 2U /*!< CoreDebug DHCSR: C_STEP Position */ -#define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos) /*!< CoreDebug DHCSR: C_STEP Mask */ +#define CoreDebug_DHCSR_C_STEP_Pos 2U /*!< \deprecated CoreDebug DHCSR: C_STEP Position */ +#define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos) /*!< \deprecated CoreDebug DHCSR: C_STEP Mask */ -#define CoreDebug_DHCSR_C_HALT_Pos 1U /*!< CoreDebug DHCSR: C_HALT Position */ -#define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos) /*!< CoreDebug DHCSR: C_HALT Mask */ +#define CoreDebug_DHCSR_C_HALT_Pos 1U /*!< \deprecated CoreDebug DHCSR: C_HALT Position */ +#define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos) /*!< \deprecated CoreDebug DHCSR: C_HALT Mask */ -#define CoreDebug_DHCSR_C_DEBUGEN_Pos 0U /*!< CoreDebug DHCSR: C_DEBUGEN Position */ -#define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL /*<< CoreDebug_DHCSR_C_DEBUGEN_Pos*/) /*!< CoreDebug DHCSR: C_DEBUGEN Mask */ +#define CoreDebug_DHCSR_C_DEBUGEN_Pos 0U /*!< \deprecated CoreDebug DHCSR: C_DEBUGEN Position */ +#define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL /*<< CoreDebug_DHCSR_C_DEBUGEN_Pos*/) /*!< \deprecated CoreDebug DHCSR: C_DEBUGEN Mask */ /* Debug Core Register Selector Register Definitions */ -#define CoreDebug_DCRSR_REGWnR_Pos 16U /*!< CoreDebug DCRSR: REGWnR Position */ -#define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos) /*!< CoreDebug DCRSR: REGWnR Mask */ +#define CoreDebug_DCRSR_REGWnR_Pos 16U /*!< \deprecated CoreDebug DCRSR: REGWnR Position */ +#define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos) /*!< \deprecated CoreDebug DCRSR: REGWnR Mask */ -#define CoreDebug_DCRSR_REGSEL_Pos 0U /*!< CoreDebug DCRSR: REGSEL Position */ -#define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL /*<< CoreDebug_DCRSR_REGSEL_Pos*/) /*!< CoreDebug DCRSR: REGSEL Mask */ +#define CoreDebug_DCRSR_REGSEL_Pos 0U /*!< \deprecated CoreDebug DCRSR: REGSEL Position */ +#define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL /*<< CoreDebug_DCRSR_REGSEL_Pos*/) /*!< \deprecated CoreDebug DCRSR: REGSEL Mask */ /* Debug Exception and Monitor Control Register Definitions */ -#define CoreDebug_DEMCR_TRCENA_Pos 24U /*!< CoreDebug DEMCR: TRCENA Position */ -#define CoreDebug_DEMCR_TRCENA_Msk (1UL << CoreDebug_DEMCR_TRCENA_Pos) /*!< CoreDebug DEMCR: TRCENA Mask */ +#define CoreDebug_DEMCR_TRCENA_Pos 24U /*!< \deprecated CoreDebug DEMCR: TRCENA Position */ +#define CoreDebug_DEMCR_TRCENA_Msk (1UL << CoreDebug_DEMCR_TRCENA_Pos) /*!< \deprecated CoreDebug DEMCR: TRCENA Mask */ -#define CoreDebug_DEMCR_MON_REQ_Pos 19U /*!< CoreDebug DEMCR: MON_REQ Position */ -#define CoreDebug_DEMCR_MON_REQ_Msk (1UL << CoreDebug_DEMCR_MON_REQ_Pos) /*!< CoreDebug DEMCR: MON_REQ Mask */ +#define CoreDebug_DEMCR_MON_REQ_Pos 19U /*!< \deprecated CoreDebug DEMCR: MON_REQ Position */ +#define CoreDebug_DEMCR_MON_REQ_Msk (1UL << CoreDebug_DEMCR_MON_REQ_Pos) /*!< \deprecated CoreDebug DEMCR: MON_REQ Mask */ -#define CoreDebug_DEMCR_MON_STEP_Pos 18U /*!< CoreDebug DEMCR: MON_STEP Position */ -#define CoreDebug_DEMCR_MON_STEP_Msk (1UL << CoreDebug_DEMCR_MON_STEP_Pos) /*!< CoreDebug DEMCR: MON_STEP Mask */ +#define CoreDebug_DEMCR_MON_STEP_Pos 18U /*!< \deprecated CoreDebug DEMCR: MON_STEP Position */ +#define CoreDebug_DEMCR_MON_STEP_Msk (1UL << CoreDebug_DEMCR_MON_STEP_Pos) /*!< \deprecated CoreDebug DEMCR: MON_STEP Mask */ -#define CoreDebug_DEMCR_MON_PEND_Pos 17U /*!< CoreDebug DEMCR: MON_PEND Position */ -#define CoreDebug_DEMCR_MON_PEND_Msk (1UL << CoreDebug_DEMCR_MON_PEND_Pos) /*!< CoreDebug DEMCR: MON_PEND Mask */ +#define CoreDebug_DEMCR_MON_PEND_Pos 17U /*!< \deprecated CoreDebug DEMCR: MON_PEND Position */ +#define CoreDebug_DEMCR_MON_PEND_Msk (1UL << CoreDebug_DEMCR_MON_PEND_Pos) /*!< \deprecated CoreDebug DEMCR: MON_PEND Mask */ -#define CoreDebug_DEMCR_MON_EN_Pos 16U /*!< CoreDebug DEMCR: MON_EN Position */ -#define CoreDebug_DEMCR_MON_EN_Msk (1UL << CoreDebug_DEMCR_MON_EN_Pos) /*!< CoreDebug DEMCR: MON_EN Mask */ +#define CoreDebug_DEMCR_MON_EN_Pos 16U /*!< \deprecated CoreDebug DEMCR: MON_EN Position */ +#define CoreDebug_DEMCR_MON_EN_Msk (1UL << CoreDebug_DEMCR_MON_EN_Pos) /*!< \deprecated CoreDebug DEMCR: MON_EN Mask */ -#define CoreDebug_DEMCR_VC_HARDERR_Pos 10U /*!< CoreDebug DEMCR: VC_HARDERR Position */ -#define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< CoreDebug DEMCR: VC_HARDERR Mask */ +#define CoreDebug_DEMCR_VC_HARDERR_Pos 10U /*!< \deprecated CoreDebug DEMCR: VC_HARDERR Position */ +#define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_HARDERR Mask */ -#define CoreDebug_DEMCR_VC_INTERR_Pos 9U /*!< CoreDebug DEMCR: VC_INTERR Position */ -#define CoreDebug_DEMCR_VC_INTERR_Msk (1UL << CoreDebug_DEMCR_VC_INTERR_Pos) /*!< CoreDebug DEMCR: VC_INTERR Mask */ +#define CoreDebug_DEMCR_VC_INTERR_Pos 9U /*!< \deprecated CoreDebug DEMCR: VC_INTERR Position */ +#define CoreDebug_DEMCR_VC_INTERR_Msk (1UL << CoreDebug_DEMCR_VC_INTERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_INTERR Mask */ -#define CoreDebug_DEMCR_VC_BUSERR_Pos 8U /*!< CoreDebug DEMCR: VC_BUSERR Position */ -#define CoreDebug_DEMCR_VC_BUSERR_Msk (1UL << CoreDebug_DEMCR_VC_BUSERR_Pos) /*!< CoreDebug DEMCR: VC_BUSERR Mask */ +#define CoreDebug_DEMCR_VC_BUSERR_Pos 8U /*!< \deprecated CoreDebug DEMCR: VC_BUSERR Position */ +#define CoreDebug_DEMCR_VC_BUSERR_Msk (1UL << CoreDebug_DEMCR_VC_BUSERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_BUSERR Mask */ -#define CoreDebug_DEMCR_VC_STATERR_Pos 7U /*!< CoreDebug DEMCR: VC_STATERR Position */ -#define CoreDebug_DEMCR_VC_STATERR_Msk (1UL << CoreDebug_DEMCR_VC_STATERR_Pos) /*!< CoreDebug DEMCR: VC_STATERR Mask */ +#define CoreDebug_DEMCR_VC_STATERR_Pos 7U /*!< \deprecated CoreDebug DEMCR: VC_STATERR Position */ +#define CoreDebug_DEMCR_VC_STATERR_Msk (1UL << CoreDebug_DEMCR_VC_STATERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_STATERR Mask */ -#define CoreDebug_DEMCR_VC_CHKERR_Pos 6U /*!< CoreDebug DEMCR: VC_CHKERR Position */ -#define CoreDebug_DEMCR_VC_CHKERR_Msk (1UL << CoreDebug_DEMCR_VC_CHKERR_Pos) /*!< CoreDebug DEMCR: VC_CHKERR Mask */ +#define CoreDebug_DEMCR_VC_CHKERR_Pos 6U /*!< \deprecated CoreDebug DEMCR: VC_CHKERR Position */ +#define CoreDebug_DEMCR_VC_CHKERR_Msk (1UL << CoreDebug_DEMCR_VC_CHKERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_CHKERR Mask */ -#define CoreDebug_DEMCR_VC_NOCPERR_Pos 5U /*!< CoreDebug DEMCR: VC_NOCPERR Position */ -#define CoreDebug_DEMCR_VC_NOCPERR_Msk (1UL << CoreDebug_DEMCR_VC_NOCPERR_Pos) /*!< CoreDebug DEMCR: VC_NOCPERR Mask */ +#define CoreDebug_DEMCR_VC_NOCPERR_Pos 5U /*!< \deprecated CoreDebug DEMCR: VC_NOCPERR Position */ +#define CoreDebug_DEMCR_VC_NOCPERR_Msk (1UL << CoreDebug_DEMCR_VC_NOCPERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_NOCPERR Mask */ -#define CoreDebug_DEMCR_VC_MMERR_Pos 4U /*!< CoreDebug DEMCR: VC_MMERR Position */ -#define CoreDebug_DEMCR_VC_MMERR_Msk (1UL << CoreDebug_DEMCR_VC_MMERR_Pos) /*!< CoreDebug DEMCR: VC_MMERR Mask */ +#define CoreDebug_DEMCR_VC_MMERR_Pos 4U /*!< \deprecated CoreDebug DEMCR: VC_MMERR Position */ +#define CoreDebug_DEMCR_VC_MMERR_Msk (1UL << CoreDebug_DEMCR_VC_MMERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_MMERR Mask */ -#define CoreDebug_DEMCR_VC_CORERESET_Pos 0U /*!< CoreDebug DEMCR: VC_CORERESET Position */ -#define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL /*<< CoreDebug_DEMCR_VC_CORERESET_Pos*/) /*!< CoreDebug DEMCR: VC_CORERESET Mask */ +#define CoreDebug_DEMCR_VC_CORERESET_Pos 0U /*!< \deprecated CoreDebug DEMCR: VC_CORERESET Position */ +#define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL /*<< CoreDebug_DEMCR_VC_CORERESET_Pos*/) /*!< \deprecated CoreDebug DEMCR: VC_CORERESET Mask */ /* Debug Authentication Control Register Definitions */ -#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos 3U /*!< CoreDebug DAUTHCTRL: INTSPNIDEN, Position */ -#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos) /*!< CoreDebug DAUTHCTRL: INTSPNIDEN, Mask */ +#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos 3U /*!< \deprecated CoreDebug DAUTHCTRL: INTSPNIDEN, Position */ +#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: INTSPNIDEN, Mask */ -#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos 2U /*!< CoreDebug DAUTHCTRL: SPNIDENSEL Position */ -#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Msk (1UL << CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos) /*!< CoreDebug DAUTHCTRL: SPNIDENSEL Mask */ +#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos 2U /*!< \deprecated CoreDebug DAUTHCTRL: SPNIDENSEL Position */ +#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Msk (1UL << CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: SPNIDENSEL Mask */ -#define CoreDebug_DAUTHCTRL_INTSPIDEN_Pos 1U /*!< CoreDebug DAUTHCTRL: INTSPIDEN Position */ -#define CoreDebug_DAUTHCTRL_INTSPIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPIDEN_Pos) /*!< CoreDebug DAUTHCTRL: INTSPIDEN Mask */ +#define CoreDebug_DAUTHCTRL_INTSPIDEN_Pos 1U /*!< \deprecated CoreDebug DAUTHCTRL: INTSPIDEN Position */ +#define CoreDebug_DAUTHCTRL_INTSPIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPIDEN_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: INTSPIDEN Mask */ -#define CoreDebug_DAUTHCTRL_SPIDENSEL_Pos 0U /*!< CoreDebug DAUTHCTRL: SPIDENSEL Position */ -#define CoreDebug_DAUTHCTRL_SPIDENSEL_Msk (1UL /*<< CoreDebug_DAUTHCTRL_SPIDENSEL_Pos*/) /*!< CoreDebug DAUTHCTRL: SPIDENSEL Mask */ +#define CoreDebug_DAUTHCTRL_SPIDENSEL_Pos 0U /*!< \deprecated CoreDebug DAUTHCTRL: SPIDENSEL Position */ +#define CoreDebug_DAUTHCTRL_SPIDENSEL_Msk (1UL /*<< CoreDebug_DAUTHCTRL_SPIDENSEL_Pos*/) /*!< \deprecated CoreDebug DAUTHCTRL: SPIDENSEL Mask */ /* Debug Security Control and Status Register Definitions */ -#define CoreDebug_DSCSR_CDS_Pos 16U /*!< CoreDebug DSCSR: CDS Position */ -#define CoreDebug_DSCSR_CDS_Msk (1UL << CoreDebug_DSCSR_CDS_Pos) /*!< CoreDebug DSCSR: CDS Mask */ +#define CoreDebug_DSCSR_CDS_Pos 16U /*!< \deprecated CoreDebug DSCSR: CDS Position */ +#define CoreDebug_DSCSR_CDS_Msk (1UL << CoreDebug_DSCSR_CDS_Pos) /*!< \deprecated CoreDebug DSCSR: CDS Mask */ -#define CoreDebug_DSCSR_SBRSEL_Pos 1U /*!< CoreDebug DSCSR: SBRSEL Position */ -#define CoreDebug_DSCSR_SBRSEL_Msk (1UL << CoreDebug_DSCSR_SBRSEL_Pos) /*!< CoreDebug DSCSR: SBRSEL Mask */ +#define CoreDebug_DSCSR_SBRSEL_Pos 1U /*!< \deprecated CoreDebug DSCSR: SBRSEL Position */ +#define CoreDebug_DSCSR_SBRSEL_Msk (1UL << CoreDebug_DSCSR_SBRSEL_Pos) /*!< \deprecated CoreDebug DSCSR: SBRSEL Mask */ -#define CoreDebug_DSCSR_SBRSELEN_Pos 0U /*!< CoreDebug DSCSR: SBRSELEN Position */ -#define CoreDebug_DSCSR_SBRSELEN_Msk (1UL /*<< CoreDebug_DSCSR_SBRSELEN_Pos*/) /*!< CoreDebug DSCSR: SBRSELEN Mask */ +#define CoreDebug_DSCSR_SBRSELEN_Pos 0U /*!< \deprecated CoreDebug DSCSR: SBRSELEN Position */ +#define CoreDebug_DSCSR_SBRSELEN_Msk (1UL /*<< CoreDebug_DSCSR_SBRSELEN_Pos*/) /*!< \deprecated CoreDebug DSCSR: SBRSELEN Mask */ /*@} end of group CMSIS_CoreDebug */ +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_DCB Debug Control Block + \brief Type definitions for the Debug Control Block Registers + @{ + */ + +/** + \brief Structure type to access the Debug Control Block Registers (DCB). + */ +typedef struct +{ + __IOM uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */ + __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ + __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ + __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ + uint32_t RESERVED0[1U]; + __IOM uint32_t DAUTHCTRL; /*!< Offset: 0x014 (R/W) Debug Authentication Control Register */ + __IOM uint32_t DSCSR; /*!< Offset: 0x018 (R/W) Debug Security Control and Status Register */ +} DCB_Type; + +/* DHCSR, Debug Halting Control and Status Register Definitions */ +#define DCB_DHCSR_DBGKEY_Pos 16U /*!< DCB DHCSR: Debug key Position */ +#define DCB_DHCSR_DBGKEY_Msk (0xFFFFUL << DCB_DHCSR_DBGKEY_Pos) /*!< DCB DHCSR: Debug key Mask */ + +#define DCB_DHCSR_S_RESTART_ST_Pos 26U /*!< DCB DHCSR: Restart sticky status Position */ +#define DCB_DHCSR_S_RESTART_ST_Msk (0x1UL << DCB_DHCSR_S_RESTART_ST_Pos) /*!< DCB DHCSR: Restart sticky status Mask */ + +#define DCB_DHCSR_S_RESET_ST_Pos 25U /*!< DCB DHCSR: Reset sticky status Position */ +#define DCB_DHCSR_S_RESET_ST_Msk (0x1UL << DCB_DHCSR_S_RESET_ST_Pos) /*!< DCB DHCSR: Reset sticky status Mask */ + +#define DCB_DHCSR_S_RETIRE_ST_Pos 24U /*!< DCB DHCSR: Retire sticky status Position */ +#define DCB_DHCSR_S_RETIRE_ST_Msk (0x1UL << DCB_DHCSR_S_RETIRE_ST_Pos) /*!< DCB DHCSR: Retire sticky status Mask */ + +#define DCB_DHCSR_S_SDE_Pos 20U /*!< DCB DHCSR: Secure debug enabled Position */ +#define DCB_DHCSR_S_SDE_Msk (0x1UL << DCB_DHCSR_S_SDE_Pos) /*!< DCB DHCSR: Secure debug enabled Mask */ + +#define DCB_DHCSR_S_LOCKUP_Pos 19U /*!< DCB DHCSR: Lockup status Position */ +#define DCB_DHCSR_S_LOCKUP_Msk (0x1UL << DCB_DHCSR_S_LOCKUP_Pos) /*!< DCB DHCSR: Lockup status Mask */ + +#define DCB_DHCSR_S_SLEEP_Pos 18U /*!< DCB DHCSR: Sleeping status Position */ +#define DCB_DHCSR_S_SLEEP_Msk (0x1UL << DCB_DHCSR_S_SLEEP_Pos) /*!< DCB DHCSR: Sleeping status Mask */ + +#define DCB_DHCSR_S_HALT_Pos 17U /*!< DCB DHCSR: Halted status Position */ +#define DCB_DHCSR_S_HALT_Msk (0x1UL << DCB_DHCSR_S_HALT_Pos) /*!< DCB DHCSR: Halted status Mask */ + +#define DCB_DHCSR_S_REGRDY_Pos 16U /*!< DCB DHCSR: Register ready status Position */ +#define DCB_DHCSR_S_REGRDY_Msk (0x1UL << DCB_DHCSR_S_REGRDY_Pos) /*!< DCB DHCSR: Register ready status Mask */ + +#define DCB_DHCSR_C_SNAPSTALL_Pos 5U /*!< DCB DHCSR: Snap stall control Position */ +#define DCB_DHCSR_C_SNAPSTALL_Msk (0x1UL << DCB_DHCSR_C_SNAPSTALL_Pos) /*!< DCB DHCSR: Snap stall control Mask */ + +#define DCB_DHCSR_C_MASKINTS_Pos 3U /*!< DCB DHCSR: Mask interrupts control Position */ +#define DCB_DHCSR_C_MASKINTS_Msk (0x1UL << DCB_DHCSR_C_MASKINTS_Pos) /*!< DCB DHCSR: Mask interrupts control Mask */ + +#define DCB_DHCSR_C_STEP_Pos 2U /*!< DCB DHCSR: Step control Position */ +#define DCB_DHCSR_C_STEP_Msk (0x1UL << DCB_DHCSR_C_STEP_Pos) /*!< DCB DHCSR: Step control Mask */ + +#define DCB_DHCSR_C_HALT_Pos 1U /*!< DCB DHCSR: Halt control Position */ +#define DCB_DHCSR_C_HALT_Msk (0x1UL << DCB_DHCSR_C_HALT_Pos) /*!< DCB DHCSR: Halt control Mask */ + +#define DCB_DHCSR_C_DEBUGEN_Pos 0U /*!< DCB DHCSR: Debug enable control Position */ +#define DCB_DHCSR_C_DEBUGEN_Msk (0x1UL /*<< DCB_DHCSR_C_DEBUGEN_Pos*/) /*!< DCB DHCSR: Debug enable control Mask */ + +/* DCRSR, Debug Core Register Select Register Definitions */ +#define DCB_DCRSR_REGWnR_Pos 16U /*!< DCB DCRSR: Register write/not-read Position */ +#define DCB_DCRSR_REGWnR_Msk (0x1UL << DCB_DCRSR_REGWnR_Pos) /*!< DCB DCRSR: Register write/not-read Mask */ + +#define DCB_DCRSR_REGSEL_Pos 0U /*!< DCB DCRSR: Register selector Position */ +#define DCB_DCRSR_REGSEL_Msk (0x7FUL /*<< DCB_DCRSR_REGSEL_Pos*/) /*!< DCB DCRSR: Register selector Mask */ + +/* DCRDR, Debug Core Register Data Register Definitions */ +#define DCB_DCRDR_DBGTMP_Pos 0U /*!< DCB DCRDR: Data temporary buffer Position */ +#define DCB_DCRDR_DBGTMP_Msk (0xFFFFFFFFUL /*<< DCB_DCRDR_DBGTMP_Pos*/) /*!< DCB DCRDR: Data temporary buffer Mask */ + +/* DEMCR, Debug Exception and Monitor Control Register Definitions */ +#define DCB_DEMCR_TRCENA_Pos 24U /*!< DCB DEMCR: Trace enable Position */ +#define DCB_DEMCR_TRCENA_Msk (0x1UL << DCB_DEMCR_TRCENA_Pos) /*!< DCB DEMCR: Trace enable Mask */ + +#define DCB_DEMCR_MONPRKEY_Pos 23U /*!< DCB DEMCR: Monitor pend req key Position */ +#define DCB_DEMCR_MONPRKEY_Msk (0x1UL << DCB_DEMCR_MONPRKEY_Pos) /*!< DCB DEMCR: Monitor pend req key Mask */ + +#define DCB_DEMCR_UMON_EN_Pos 21U /*!< DCB DEMCR: Unprivileged monitor enable Position */ +#define DCB_DEMCR_UMON_EN_Msk (0x1UL << DCB_DEMCR_UMON_EN_Pos) /*!< DCB DEMCR: Unprivileged monitor enable Mask */ + +#define DCB_DEMCR_SDME_Pos 20U /*!< DCB DEMCR: Secure DebugMonitor enable Position */ +#define DCB_DEMCR_SDME_Msk (0x1UL << DCB_DEMCR_SDME_Pos) /*!< DCB DEMCR: Secure DebugMonitor enable Mask */ + +#define DCB_DEMCR_MON_REQ_Pos 19U /*!< DCB DEMCR: Monitor request Position */ +#define DCB_DEMCR_MON_REQ_Msk (0x1UL << DCB_DEMCR_MON_REQ_Pos) /*!< DCB DEMCR: Monitor request Mask */ + +#define DCB_DEMCR_MON_STEP_Pos 18U /*!< DCB DEMCR: Monitor step Position */ +#define DCB_DEMCR_MON_STEP_Msk (0x1UL << DCB_DEMCR_MON_STEP_Pos) /*!< DCB DEMCR: Monitor step Mask */ + +#define DCB_DEMCR_MON_PEND_Pos 17U /*!< DCB DEMCR: Monitor pend Position */ +#define DCB_DEMCR_MON_PEND_Msk (0x1UL << DCB_DEMCR_MON_PEND_Pos) /*!< DCB DEMCR: Monitor pend Mask */ + +#define DCB_DEMCR_MON_EN_Pos 16U /*!< DCB DEMCR: Monitor enable Position */ +#define DCB_DEMCR_MON_EN_Msk (0x1UL << DCB_DEMCR_MON_EN_Pos) /*!< DCB DEMCR: Monitor enable Mask */ + +#define DCB_DEMCR_VC_SFERR_Pos 11U /*!< DCB DEMCR: Vector Catch SecureFault Position */ +#define DCB_DEMCR_VC_SFERR_Msk (0x1UL << DCB_DEMCR_VC_SFERR_Pos) /*!< DCB DEMCR: Vector Catch SecureFault Mask */ + +#define DCB_DEMCR_VC_HARDERR_Pos 10U /*!< DCB DEMCR: Vector Catch HardFault errors Position */ +#define DCB_DEMCR_VC_HARDERR_Msk (0x1UL << DCB_DEMCR_VC_HARDERR_Pos) /*!< DCB DEMCR: Vector Catch HardFault errors Mask */ + +#define DCB_DEMCR_VC_INTERR_Pos 9U /*!< DCB DEMCR: Vector Catch interrupt errors Position */ +#define DCB_DEMCR_VC_INTERR_Msk (0x1UL << DCB_DEMCR_VC_INTERR_Pos) /*!< DCB DEMCR: Vector Catch interrupt errors Mask */ + +#define DCB_DEMCR_VC_BUSERR_Pos 8U /*!< DCB DEMCR: Vector Catch BusFault errors Position */ +#define DCB_DEMCR_VC_BUSERR_Msk (0x1UL << DCB_DEMCR_VC_BUSERR_Pos) /*!< DCB DEMCR: Vector Catch BusFault errors Mask */ + +#define DCB_DEMCR_VC_STATERR_Pos 7U /*!< DCB DEMCR: Vector Catch state errors Position */ +#define DCB_DEMCR_VC_STATERR_Msk (0x1UL << DCB_DEMCR_VC_STATERR_Pos) /*!< DCB DEMCR: Vector Catch state errors Mask */ + +#define DCB_DEMCR_VC_CHKERR_Pos 6U /*!< DCB DEMCR: Vector Catch check errors Position */ +#define DCB_DEMCR_VC_CHKERR_Msk (0x1UL << DCB_DEMCR_VC_CHKERR_Pos) /*!< DCB DEMCR: Vector Catch check errors Mask */ + +#define DCB_DEMCR_VC_NOCPERR_Pos 5U /*!< DCB DEMCR: Vector Catch NOCP errors Position */ +#define DCB_DEMCR_VC_NOCPERR_Msk (0x1UL << DCB_DEMCR_VC_NOCPERR_Pos) /*!< DCB DEMCR: Vector Catch NOCP errors Mask */ + +#define DCB_DEMCR_VC_MMERR_Pos 4U /*!< DCB DEMCR: Vector Catch MemManage errors Position */ +#define DCB_DEMCR_VC_MMERR_Msk (0x1UL << DCB_DEMCR_VC_MMERR_Pos) /*!< DCB DEMCR: Vector Catch MemManage errors Mask */ + +#define DCB_DEMCR_VC_CORERESET_Pos 0U /*!< DCB DEMCR: Vector Catch Core reset Position */ +#define DCB_DEMCR_VC_CORERESET_Msk (0x1UL /*<< DCB_DEMCR_VC_CORERESET_Pos*/) /*!< DCB DEMCR: Vector Catch Core reset Mask */ + +/* DAUTHCTRL, Debug Authentication Control Register Definitions */ +#define DCB_DAUTHCTRL_INTSPNIDEN_Pos 3U /*!< DCB DAUTHCTRL: Internal Secure non-invasive debug enable Position */ +#define DCB_DAUTHCTRL_INTSPNIDEN_Msk (0x1UL << DCB_DAUTHCTRL_INTSPNIDEN_Pos) /*!< DCB DAUTHCTRL: Internal Secure non-invasive debug enable Mask */ + +#define DCB_DAUTHCTRL_SPNIDENSEL_Pos 2U /*!< DCB DAUTHCTRL: Secure non-invasive debug enable select Position */ +#define DCB_DAUTHCTRL_SPNIDENSEL_Msk (0x1UL << DCB_DAUTHCTRL_SPNIDENSEL_Pos) /*!< DCB DAUTHCTRL: Secure non-invasive debug enable select Mask */ + +#define DCB_DAUTHCTRL_INTSPIDEN_Pos 1U /*!< DCB DAUTHCTRL: Internal Secure invasive debug enable Position */ +#define DCB_DAUTHCTRL_INTSPIDEN_Msk (0x1UL << DCB_DAUTHCTRL_INTSPIDEN_Pos) /*!< DCB DAUTHCTRL: Internal Secure invasive debug enable Mask */ + +#define DCB_DAUTHCTRL_SPIDENSEL_Pos 0U /*!< DCB DAUTHCTRL: Secure invasive debug enable select Position */ +#define DCB_DAUTHCTRL_SPIDENSEL_Msk (0x1UL /*<< DCB_DAUTHCTRL_SPIDENSEL_Pos*/) /*!< DCB DAUTHCTRL: Secure invasive debug enable select Mask */ + +/* DSCSR, Debug Security Control and Status Register Definitions */ +#define DCB_DSCSR_CDSKEY_Pos 17U /*!< DCB DSCSR: CDS write-enable key Position */ +#define DCB_DSCSR_CDSKEY_Msk (0x1UL << DCB_DSCSR_CDSKEY_Pos) /*!< DCB DSCSR: CDS write-enable key Mask */ + +#define DCB_DSCSR_CDS_Pos 16U /*!< DCB DSCSR: Current domain Secure Position */ +#define DCB_DSCSR_CDS_Msk (0x1UL << DCB_DSCSR_CDS_Pos) /*!< DCB DSCSR: Current domain Secure Mask */ + +#define DCB_DSCSR_SBRSEL_Pos 1U /*!< DCB DSCSR: Secure banked register select Position */ +#define DCB_DSCSR_SBRSEL_Msk (0x1UL << DCB_DSCSR_SBRSEL_Pos) /*!< DCB DSCSR: Secure banked register select Mask */ + +#define DCB_DSCSR_SBRSELEN_Pos 0U /*!< DCB DSCSR: Secure banked register select enable Position */ +#define DCB_DSCSR_SBRSELEN_Msk (0x1UL /*<< DCB_DSCSR_SBRSELEN_Pos*/) /*!< DCB DSCSR: Secure banked register select enable Mask */ + +/*@} end of group CMSIS_DCB */ + + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_DIB Debug Identification Block + \brief Type definitions for the Debug Identification Block Registers + @{ + */ + +/** + \brief Structure type to access the Debug Identification Block Registers (DIB). + */ +typedef struct +{ + __OM uint32_t DLAR; /*!< Offset: 0x000 ( /W) SCS Software Lock Access Register */ + __IM uint32_t DLSR; /*!< Offset: 0x004 (R/ ) SCS Software Lock Status Register */ + __IM uint32_t DAUTHSTATUS; /*!< Offset: 0x008 (R/ ) Debug Authentication Status Register */ + __IM uint32_t DDEVARCH; /*!< Offset: 0x00C (R/ ) SCS Device Architecture Register */ + __IM uint32_t DDEVTYPE; /*!< Offset: 0x010 (R/ ) SCS Device Type Register */ +} DIB_Type; + +/* DLAR, SCS Software Lock Access Register Definitions */ +#define DIB_DLAR_KEY_Pos 0U /*!< DIB DLAR: KEY Position */ +#define DIB_DLAR_KEY_Msk (0xFFFFFFFFUL /*<< DIB_DLAR_KEY_Pos */) /*!< DIB DLAR: KEY Mask */ + +/* DLSR, SCS Software Lock Status Register Definitions */ +#define DIB_DLSR_nTT_Pos 2U /*!< DIB DLSR: Not thirty-two bit Position */ +#define DIB_DLSR_nTT_Msk (0x1UL << DIB_DLSR_nTT_Pos ) /*!< DIB DLSR: Not thirty-two bit Mask */ + +#define DIB_DLSR_SLK_Pos 1U /*!< DIB DLSR: Software Lock status Position */ +#define DIB_DLSR_SLK_Msk (0x1UL << DIB_DLSR_SLK_Pos ) /*!< DIB DLSR: Software Lock status Mask */ + +#define DIB_DLSR_SLI_Pos 0U /*!< DIB DLSR: Software Lock implemented Position */ +#define DIB_DLSR_SLI_Msk (0x1UL /*<< DIB_DLSR_SLI_Pos*/) /*!< DIB DLSR: Software Lock implemented Mask */ + +/* DAUTHSTATUS, Debug Authentication Status Register Definitions */ +#define DIB_DAUTHSTATUS_SNID_Pos 6U /*!< DIB DAUTHSTATUS: Secure Non-invasive Debug Position */ +#define DIB_DAUTHSTATUS_SNID_Msk (0x3UL << DIB_DAUTHSTATUS_SNID_Pos ) /*!< DIB DAUTHSTATUS: Secure Non-invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_SID_Pos 4U /*!< DIB DAUTHSTATUS: Secure Invasive Debug Position */ +#define DIB_DAUTHSTATUS_SID_Msk (0x3UL << DIB_DAUTHSTATUS_SID_Pos ) /*!< DIB DAUTHSTATUS: Secure Invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_NSNID_Pos 2U /*!< DIB DAUTHSTATUS: Non-secure Non-invasive Debug Position */ +#define DIB_DAUTHSTATUS_NSNID_Msk (0x3UL << DIB_DAUTHSTATUS_NSNID_Pos ) /*!< DIB DAUTHSTATUS: Non-secure Non-invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_NSID_Pos 0U /*!< DIB DAUTHSTATUS: Non-secure Invasive Debug Position */ +#define DIB_DAUTHSTATUS_NSID_Msk (0x3UL /*<< DIB_DAUTHSTATUS_NSID_Pos*/) /*!< DIB DAUTHSTATUS: Non-secure Invasive Debug Mask */ + +/* DDEVARCH, SCS Device Architecture Register Definitions */ +#define DIB_DDEVARCH_ARCHITECT_Pos 21U /*!< DIB DDEVARCH: Architect Position */ +#define DIB_DDEVARCH_ARCHITECT_Msk (0x7FFUL << DIB_DDEVARCH_ARCHITECT_Pos ) /*!< DIB DDEVARCH: Architect Mask */ + +#define DIB_DDEVARCH_PRESENT_Pos 20U /*!< DIB DDEVARCH: DEVARCH Present Position */ +#define DIB_DDEVARCH_PRESENT_Msk (0x1FUL << DIB_DDEVARCH_PRESENT_Pos ) /*!< DIB DDEVARCH: DEVARCH Present Mask */ + +#define DIB_DDEVARCH_REVISION_Pos 16U /*!< DIB DDEVARCH: Revision Position */ +#define DIB_DDEVARCH_REVISION_Msk (0xFUL << DIB_DDEVARCH_REVISION_Pos ) /*!< DIB DDEVARCH: Revision Mask */ + +#define DIB_DDEVARCH_ARCHVER_Pos 12U /*!< DIB DDEVARCH: Architecture Version Position */ +#define DIB_DDEVARCH_ARCHVER_Msk (0xFUL << DIB_DDEVARCH_ARCHVER_Pos ) /*!< DIB DDEVARCH: Architecture Version Mask */ + +#define DIB_DDEVARCH_ARCHPART_Pos 0U /*!< DIB DDEVARCH: Architecture Part Position */ +#define DIB_DDEVARCH_ARCHPART_Msk (0xFFFUL /*<< DIB_DDEVARCH_ARCHPART_Pos*/) /*!< DIB DDEVARCH: Architecture Part Mask */ + +/* DDEVTYPE, SCS Device Type Register Definitions */ +#define DIB_DDEVTYPE_SUB_Pos 4U /*!< DIB DDEVTYPE: Sub-type Position */ +#define DIB_DDEVTYPE_SUB_Msk (0xFUL << DIB_DDEVTYPE_SUB_Pos ) /*!< DIB DDEVTYPE: Sub-type Mask */ + +#define DIB_DDEVTYPE_MAJOR_Pos 0U /*!< DIB DDEVTYPE: Major type Position */ +#define DIB_DDEVTYPE_MAJOR_Msk (0xFUL /*<< DIB_DDEVTYPE_MAJOR_Pos*/) /*!< DIB DDEVTYPE: Major type Mask */ + + +/*@} end of group CMSIS_DIB */ + + /** \ingroup CMSIS_core_register \defgroup CMSIS_core_bitfield Core register bit field macros @@ -1879,7 +2125,9 @@ typedef struct #define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */ #define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */ #define TPI_BASE (0xE0040000UL) /*!< TPI Base Address */ - #define CoreDebug_BASE (0xE000EDF0UL) /*!< Core Debug Base Address */ + #define CoreDebug_BASE (0xE000EDF0UL) /*!< \deprecated Core Debug Base Address */ + #define DCB_BASE (0xE000EDF0UL) /*!< DCB Base Address */ + #define DIB_BASE (0xE000EFB0UL) /*!< DIB Base Address */ #define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */ #define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */ #define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */ @@ -1891,7 +2139,9 @@ typedef struct #define ITM ((ITM_Type *) ITM_BASE ) /*!< ITM configuration struct */ #define DWT ((DWT_Type *) DWT_BASE ) /*!< DWT configuration struct */ #define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct */ - #define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE ) /*!< Core Debug configuration struct */ + #define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE ) /*!< \deprecated Core Debug configuration struct */ + #define DCB ((DCB_Type *) DCB_BASE ) /*!< DCB configuration struct */ + #define DIB ((DIB_Type *) DIB_BASE ) /*!< DIB configuration struct */ #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */ @@ -1908,7 +2158,9 @@ typedef struct #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) #define SCS_BASE_NS (0xE002E000UL) /*!< System Control Space Base Address (non-secure address space) */ - #define CoreDebug_BASE_NS (0xE002EDF0UL) /*!< Core Debug Base Address (non-secure address space) */ + #define CoreDebug_BASE_NS (0xE002EDF0UL) /*!< \deprecated Core Debug Base Address (non-secure address space) */ + #define DCB_BASE_NS (0xE002EDF0UL) /*!< DCB Base Address (non-secure address space) */ + #define DIB_BASE_NS (0xE002EFB0UL) /*!< DIB Base Address (non-secure address space) */ #define SysTick_BASE_NS (SCS_BASE_NS + 0x0010UL) /*!< SysTick Base Address (non-secure address space) */ #define NVIC_BASE_NS (SCS_BASE_NS + 0x0100UL) /*!< NVIC Base Address (non-secure address space) */ #define SCB_BASE_NS (SCS_BASE_NS + 0x0D00UL) /*!< System Control Block Base Address (non-secure address space) */ @@ -1917,7 +2169,9 @@ typedef struct #define SCB_NS ((SCB_Type *) SCB_BASE_NS ) /*!< SCB configuration struct (non-secure address space) */ #define SysTick_NS ((SysTick_Type *) SysTick_BASE_NS ) /*!< SysTick configuration struct (non-secure address space) */ #define NVIC_NS ((NVIC_Type *) NVIC_BASE_NS ) /*!< NVIC configuration struct (non-secure address space) */ - #define CoreDebug_NS ((CoreDebug_Type *) CoreDebug_BASE_NS) /*!< Core Debug configuration struct (non-secure address space) */ + #define CoreDebug_NS ((CoreDebug_Type *) CoreDebug_BASE_NS) /*!< \deprecated Core Debug configuration struct (non-secure address space) */ + #define DCB_NS ((DCB_Type *) DCB_BASE_NS ) /*!< DCB configuration struct (non-secure address space) */ + #define DIB_NS ((DIB_Type *) DIB_BASE_NS ) /*!< DIB configuration struct (non-secure address space) */ #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) #define MPU_BASE_NS (SCS_BASE_NS + 0x0D90UL) /*!< Memory Protection Unit (non-secure address space) */ @@ -1931,6 +2185,15 @@ typedef struct /*@} */ +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_register_aliases Backwards Compatibility Aliases + \brief Register alias definitions for backwards compatibility. + @{ + */ +#define ID_ADR (ID_AFR) /*!< SCB Auxiliary Feature Register */ +/*@} */ + /******************************************************************************* * Hardware Abstraction Layer @@ -2053,7 +2316,9 @@ __STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) { if ((int32_t)(IRQn) >= 0) { + __COMPILER_BARRIER(); NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __COMPILER_BARRIER(); } } @@ -2345,6 +2610,7 @@ __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) { uint32_t *vectors = (uint32_t *)SCB->VTOR; vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector; + __DSB(); } @@ -2633,6 +2899,13 @@ __STATIC_INLINE uint32_t SCB_GetFPUType(void) /*@} end of CMSIS_Core_FpuFunctions */ +/* ########################## Cache functions #################################### */ + +#if ((defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U)) || \ + (defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U))) +#include "cachel1_armv7.h" +#endif + /* ########################## SAU functions #################################### */ /** @@ -2671,6 +2944,110 @@ __STATIC_INLINE void TZ_SAU_Disable(void) +/* ################################## Debug Control function ############################################ */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_DCBFunctions Debug Control Functions + \brief Functions that access the Debug Control Block. + @{ + */ + + +/** + \brief Set Debug Authentication Control Register + \details writes to Debug Authentication Control register. + \param [in] value value to be writen. + */ +__STATIC_INLINE void DCB_SetAuthCtrl(uint32_t value) +{ + __DSB(); + __ISB(); + DCB->DAUTHCTRL = value; + __DSB(); + __ISB(); +} + + +/** + \brief Get Debug Authentication Control Register + \details Reads Debug Authentication Control register. + \return Debug Authentication Control Register. + */ +__STATIC_INLINE uint32_t DCB_GetAuthCtrl(void) +{ + return (DCB->DAUTHCTRL); +} + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief Set Debug Authentication Control Register (non-secure) + \details writes to non-secure Debug Authentication Control register when in secure state. + \param [in] value value to be writen + */ +__STATIC_INLINE void TZ_DCB_SetAuthCtrl_NS(uint32_t value) +{ + __DSB(); + __ISB(); + DCB_NS->DAUTHCTRL = value; + __DSB(); + __ISB(); +} + + +/** + \brief Get Debug Authentication Control Register (non-secure) + \details Reads non-secure Debug Authentication Control register when in secure state. + \return Debug Authentication Control Register. + */ +__STATIC_INLINE uint32_t TZ_DCB_GetAuthCtrl_NS(void) +{ + return (DCB_NS->DAUTHCTRL); +} +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + +/*@} end of CMSIS_Core_DCBFunctions */ + + + + +/* ################################## Debug Identification function ############################################ */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_DIBFunctions Debug Identification Functions + \brief Functions that access the Debug Identification Block. + @{ + */ + + +/** + \brief Get Debug Authentication Status Register + \details Reads Debug Authentication Status register. + \return Debug Authentication Status Register. + */ +__STATIC_INLINE uint32_t DIB_GetAuthStatus(void) +{ + return (DIB->DAUTHSTATUS); +} + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief Get Debug Authentication Status Register (non-secure) + \details Reads non-secure Debug Authentication Status register when in secure state. + \return Debug Authentication Status Register. + */ +__STATIC_INLINE uint32_t TZ_DIB_GetAuthStatus_NS(void) +{ + return (DIB_NS->DAUTHSTATUS); +} +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + +/*@} end of CMSIS_Core_DCBFunctions */ + + + + /* ################################## SysTick function ############################################ */ /** \ingroup CMSIS_Core_FunctionInterface diff --git a/lib/cmsis/inc/core_cm0.h b/lib/cmsis/inc/core_cm0.h index fcf27578ccf59..6441ff34190a9 100644 --- a/lib/cmsis/inc/core_cm0.h +++ b/lib/cmsis/inc/core_cm0.h @@ -1,8 +1,8 @@ /**************************************************************************//** * @file core_cm0.h * @brief CMSIS Cortex-M0 Core Peripheral Access Layer Header File - * @version V5.0.6 - * @date 13. March 2019 + * @version V5.0.8 + * @date 21. August 2019 ******************************************************************************/ /* * Copyright (c) 2009-2019 Arm Limited. All rights reserved. @@ -624,7 +624,9 @@ __STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) { if ((int32_t)(IRQn) >= 0) { + __COMPILER_BARRIER(); NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __COMPILER_BARRIER(); } } @@ -829,8 +831,9 @@ __STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGr */ __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) { - uint32_t vectors = 0x0U; - (* (int *) (vectors + ((int32_t)IRQn + NVIC_USER_IRQ_OFFSET) * 4)) = vector; + uint32_t *vectors = (uint32_t *)(NVIC_USER_IRQ_OFFSET << 2); /* point to 1st user interrupt */ + *(vectors + (int32_t)IRQn) = vector; /* use pointer arithmetic to access vector */ + /* ARM Application Note 321 states that the M0 does not require the architectural barrier */ } @@ -844,8 +847,8 @@ __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) */ __STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn) { - uint32_t vectors = 0x0U; - return (uint32_t)(* (int *) (vectors + ((int32_t)IRQn + NVIC_USER_IRQ_OFFSET) * 4)); + uint32_t *vectors = (uint32_t *)(NVIC_USER_IRQ_OFFSET << 2); /* point to 1st user interrupt */ + return *(vectors + (int32_t)IRQn); /* use pointer arithmetic to access vector */ } diff --git a/lib/cmsis/inc/core_cm0plus.h b/lib/cmsis/inc/core_cm0plus.h index 65ea443095f08..4e7179a6146cd 100644 --- a/lib/cmsis/inc/core_cm0plus.h +++ b/lib/cmsis/inc/core_cm0plus.h @@ -1,11 +1,11 @@ /**************************************************************************//** * @file core_cm0plus.h * @brief CMSIS Cortex-M0+ Core Peripheral Access Layer Header File - * @version V5.0.7 - * @date 13. March 2019 + * @version V5.0.9 + * @date 21. August 2019 ******************************************************************************/ /* - * Copyright (c) 2009-2018 Arm Limited. All rights reserved. + * Copyright (c) 2009-2019 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -742,7 +742,9 @@ __STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) { if ((int32_t)(IRQn) >= 0) { + __COMPILER_BARRIER(); NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __COMPILER_BARRIER(); } } @@ -948,11 +950,13 @@ __STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGr __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) { #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) - uint32_t vectors = SCB->VTOR; + uint32_t *vectors = (uint32_t *)SCB->VTOR; + vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector; #else - uint32_t vectors = 0x0U; + uint32_t *vectors = (uint32_t *)(NVIC_USER_IRQ_OFFSET << 2); /* point to 1st user interrupt */ + *(vectors + (int32_t)IRQn) = vector; /* use pointer arithmetic to access vector */ #endif - (* (int *) (vectors + ((int32_t)IRQn + NVIC_USER_IRQ_OFFSET) * 4)) = vector; + /* ARM Application Note 321 states that the M0+ does not require the architectural barrier */ } @@ -967,11 +971,12 @@ __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) __STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn) { #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) - uint32_t vectors = SCB->VTOR; + uint32_t *vectors = (uint32_t *)SCB->VTOR; + return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET]; #else - uint32_t vectors = 0x0U; + uint32_t *vectors = (uint32_t *)(NVIC_USER_IRQ_OFFSET << 2); /* point to 1st user interrupt */ + return *(vectors + (int32_t)IRQn); /* use pointer arithmetic to access vector */ #endif - return (uint32_t)(* (int *) (vectors + ((int32_t)IRQn + NVIC_USER_IRQ_OFFSET) * 4)); } diff --git a/lib/cmsis/inc/core_cm1.h b/lib/cmsis/inc/core_cm1.h index 72c515cb092e0..76b4569743a65 100644 --- a/lib/cmsis/inc/core_cm1.h +++ b/lib/cmsis/inc/core_cm1.h @@ -651,7 +651,9 @@ __STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) { if ((int32_t)(IRQn) >= 0) { + __COMPILER_BARRIER(); NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __COMPILER_BARRIER(); } } @@ -858,6 +860,7 @@ __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) { uint32_t *vectors = (uint32_t *)0x0U; vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector; + /* ARM Application Note 321 states that the M1 does not require the architectural barrier */ } diff --git a/lib/cmsis/inc/core_cm23.h b/lib/cmsis/inc/core_cm23.h index 26fe163a0e82c..55fff99509653 100644 --- a/lib/cmsis/inc/core_cm23.h +++ b/lib/cmsis/inc/core_cm23.h @@ -1,11 +1,11 @@ /**************************************************************************//** * @file core_cm23.h * @brief CMSIS Cortex-M23 Core Peripheral Access Layer Header File - * @version V5.0.8 - * @date 12. November 2018 + * @version V5.1.0 + * @date 11. February 2020 ******************************************************************************/ /* - * Copyright (c) 2009-2018 Arm Limited. All rights reserved. + * Copyright (c) 2009-2020 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -23,9 +23,11 @@ */ #if defined ( __ICCARM__ ) - #pragma system_include /* treat file as system include file for MISRA check */ + #pragma system_include /* treat file as system include file for MISRA check */ #elif defined (__clang__) - #pragma clang system_header /* treat file as system include file */ + #pragma clang system_header /* treat file as system include file */ +#elif defined ( __GNUC__ ) + #pragma GCC diagnostic ignored "-Wpedantic" /* disable pedantic warning due to unnamed structs/unions */ #endif #ifndef __CORE_CM23_H_GENERIC @@ -1050,6 +1052,7 @@ typedef struct #endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ +/* CoreDebug is deprecated. replaced by DCB (Debug Control Block) */ /** \ingroup CMSIS_core_register \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug) @@ -1058,7 +1061,7 @@ typedef struct */ /** - \brief Structure type to access the Core Debug Register (CoreDebug). + \brief \deprecated Structure type to access the Core Debug Register (CoreDebug). */ typedef struct { @@ -1066,91 +1069,276 @@ typedef struct __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ - uint32_t RESERVED4[1U]; + uint32_t RESERVED0[1U]; __IOM uint32_t DAUTHCTRL; /*!< Offset: 0x014 (R/W) Debug Authentication Control Register */ __IOM uint32_t DSCSR; /*!< Offset: 0x018 (R/W) Debug Security Control and Status Register */ } CoreDebug_Type; /* Debug Halting Control and Status Register Definitions */ -#define CoreDebug_DHCSR_DBGKEY_Pos 16U /*!< CoreDebug DHCSR: DBGKEY Position */ -#define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos) /*!< CoreDebug DHCSR: DBGKEY Mask */ +#define CoreDebug_DHCSR_DBGKEY_Pos 16U /*!< \deprecated CoreDebug DHCSR: DBGKEY Position */ +#define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos) /*!< \deprecated CoreDebug DHCSR: DBGKEY Mask */ -#define CoreDebug_DHCSR_S_RESTART_ST_Pos 26U /*!< CoreDebug DHCSR: S_RESTART_ST Position */ -#define CoreDebug_DHCSR_S_RESTART_ST_Msk (1UL << CoreDebug_DHCSR_S_RESTART_ST_Pos) /*!< CoreDebug DHCSR: S_RESTART_ST Mask */ +#define CoreDebug_DHCSR_S_RESTART_ST_Pos 26U /*!< \deprecated CoreDebug DHCSR: S_RESTART_ST Position */ +#define CoreDebug_DHCSR_S_RESTART_ST_Msk (1UL << CoreDebug_DHCSR_S_RESTART_ST_Pos) /*!< \deprecated CoreDebug DHCSR: S_RESTART_ST Mask */ -#define CoreDebug_DHCSR_S_RESET_ST_Pos 25U /*!< CoreDebug DHCSR: S_RESET_ST Position */ -#define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< CoreDebug DHCSR: S_RESET_ST Mask */ +#define CoreDebug_DHCSR_S_RESET_ST_Pos 25U /*!< \deprecated CoreDebug DHCSR: S_RESET_ST Position */ +#define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< \deprecated CoreDebug DHCSR: S_RESET_ST Mask */ -#define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24U /*!< CoreDebug DHCSR: S_RETIRE_ST Position */ -#define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< CoreDebug DHCSR: S_RETIRE_ST Mask */ +#define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24U /*!< \deprecated CoreDebug DHCSR: S_RETIRE_ST Position */ +#define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< \deprecated CoreDebug DHCSR: S_RETIRE_ST Mask */ -#define CoreDebug_DHCSR_S_LOCKUP_Pos 19U /*!< CoreDebug DHCSR: S_LOCKUP Position */ -#define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< CoreDebug DHCSR: S_LOCKUP Mask */ +#define CoreDebug_DHCSR_S_LOCKUP_Pos 19U /*!< \deprecated CoreDebug DHCSR: S_LOCKUP Position */ +#define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< \deprecated CoreDebug DHCSR: S_LOCKUP Mask */ -#define CoreDebug_DHCSR_S_SLEEP_Pos 18U /*!< CoreDebug DHCSR: S_SLEEP Position */ -#define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< CoreDebug DHCSR: S_SLEEP Mask */ +#define CoreDebug_DHCSR_S_SLEEP_Pos 18U /*!< \deprecated CoreDebug DHCSR: S_SLEEP Position */ +#define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< \deprecated CoreDebug DHCSR: S_SLEEP Mask */ -#define CoreDebug_DHCSR_S_HALT_Pos 17U /*!< CoreDebug DHCSR: S_HALT Position */ -#define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos) /*!< CoreDebug DHCSR: S_HALT Mask */ +#define CoreDebug_DHCSR_S_HALT_Pos 17U /*!< \deprecated CoreDebug DHCSR: S_HALT Position */ +#define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos) /*!< \deprecated CoreDebug DHCSR: S_HALT Mask */ -#define CoreDebug_DHCSR_S_REGRDY_Pos 16U /*!< CoreDebug DHCSR: S_REGRDY Position */ -#define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< CoreDebug DHCSR: S_REGRDY Mask */ +#define CoreDebug_DHCSR_S_REGRDY_Pos 16U /*!< \deprecated CoreDebug DHCSR: S_REGRDY Position */ +#define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< \deprecated CoreDebug DHCSR: S_REGRDY Mask */ -#define CoreDebug_DHCSR_C_MASKINTS_Pos 3U /*!< CoreDebug DHCSR: C_MASKINTS Position */ -#define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< CoreDebug DHCSR: C_MASKINTS Mask */ +#define CoreDebug_DHCSR_C_MASKINTS_Pos 3U /*!< \deprecated CoreDebug DHCSR: C_MASKINTS Position */ +#define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< \deprecated CoreDebug DHCSR: C_MASKINTS Mask */ -#define CoreDebug_DHCSR_C_STEP_Pos 2U /*!< CoreDebug DHCSR: C_STEP Position */ -#define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos) /*!< CoreDebug DHCSR: C_STEP Mask */ +#define CoreDebug_DHCSR_C_STEP_Pos 2U /*!< \deprecated CoreDebug DHCSR: C_STEP Position */ +#define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos) /*!< \deprecated CoreDebug DHCSR: C_STEP Mask */ -#define CoreDebug_DHCSR_C_HALT_Pos 1U /*!< CoreDebug DHCSR: C_HALT Position */ -#define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos) /*!< CoreDebug DHCSR: C_HALT Mask */ +#define CoreDebug_DHCSR_C_HALT_Pos 1U /*!< \deprecated CoreDebug DHCSR: C_HALT Position */ +#define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos) /*!< \deprecated CoreDebug DHCSR: C_HALT Mask */ -#define CoreDebug_DHCSR_C_DEBUGEN_Pos 0U /*!< CoreDebug DHCSR: C_DEBUGEN Position */ -#define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL /*<< CoreDebug_DHCSR_C_DEBUGEN_Pos*/) /*!< CoreDebug DHCSR: C_DEBUGEN Mask */ +#define CoreDebug_DHCSR_C_DEBUGEN_Pos 0U /*!< \deprecated CoreDebug DHCSR: C_DEBUGEN Position */ +#define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL /*<< CoreDebug_DHCSR_C_DEBUGEN_Pos*/) /*!< \deprecated CoreDebug DHCSR: C_DEBUGEN Mask */ /* Debug Core Register Selector Register Definitions */ -#define CoreDebug_DCRSR_REGWnR_Pos 16U /*!< CoreDebug DCRSR: REGWnR Position */ -#define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos) /*!< CoreDebug DCRSR: REGWnR Mask */ +#define CoreDebug_DCRSR_REGWnR_Pos 16U /*!< \deprecated CoreDebug DCRSR: REGWnR Position */ +#define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos) /*!< \deprecated CoreDebug DCRSR: REGWnR Mask */ -#define CoreDebug_DCRSR_REGSEL_Pos 0U /*!< CoreDebug DCRSR: REGSEL Position */ -#define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL /*<< CoreDebug_DCRSR_REGSEL_Pos*/) /*!< CoreDebug DCRSR: REGSEL Mask */ +#define CoreDebug_DCRSR_REGSEL_Pos 0U /*!< \deprecated CoreDebug DCRSR: REGSEL Position */ +#define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL /*<< CoreDebug_DCRSR_REGSEL_Pos*/) /*!< \deprecated CoreDebug DCRSR: REGSEL Mask */ /* Debug Exception and Monitor Control Register */ -#define CoreDebug_DEMCR_DWTENA_Pos 24U /*!< CoreDebug DEMCR: DWTENA Position */ -#define CoreDebug_DEMCR_DWTENA_Msk (1UL << CoreDebug_DEMCR_DWTENA_Pos) /*!< CoreDebug DEMCR: DWTENA Mask */ +#define CoreDebug_DEMCR_DWTENA_Pos 24U /*!< \deprecated CoreDebug DEMCR: DWTENA Position */ +#define CoreDebug_DEMCR_DWTENA_Msk (1UL << CoreDebug_DEMCR_DWTENA_Pos) /*!< \deprecated CoreDebug DEMCR: DWTENA Mask */ -#define CoreDebug_DEMCR_VC_HARDERR_Pos 10U /*!< CoreDebug DEMCR: VC_HARDERR Position */ -#define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< CoreDebug DEMCR: VC_HARDERR Mask */ +#define CoreDebug_DEMCR_VC_HARDERR_Pos 10U /*!< \deprecated CoreDebug DEMCR: VC_HARDERR Position */ +#define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_HARDERR Mask */ -#define CoreDebug_DEMCR_VC_CORERESET_Pos 0U /*!< CoreDebug DEMCR: VC_CORERESET Position */ -#define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL /*<< CoreDebug_DEMCR_VC_CORERESET_Pos*/) /*!< CoreDebug DEMCR: VC_CORERESET Mask */ +#define CoreDebug_DEMCR_VC_CORERESET_Pos 0U /*!< \deprecated CoreDebug DEMCR: VC_CORERESET Position */ +#define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL /*<< CoreDebug_DEMCR_VC_CORERESET_Pos*/) /*!< \deprecated CoreDebug DEMCR: VC_CORERESET Mask */ /* Debug Authentication Control Register Definitions */ -#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos 3U /*!< CoreDebug DAUTHCTRL: INTSPNIDEN, Position */ -#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos) /*!< CoreDebug DAUTHCTRL: INTSPNIDEN, Mask */ +#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos 3U /*!< \deprecated CoreDebug DAUTHCTRL: INTSPNIDEN, Position */ +#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: INTSPNIDEN, Mask */ -#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos 2U /*!< CoreDebug DAUTHCTRL: SPNIDENSEL Position */ -#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Msk (1UL << CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos) /*!< CoreDebug DAUTHCTRL: SPNIDENSEL Mask */ +#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos 2U /*!< \deprecated CoreDebug DAUTHCTRL: SPNIDENSEL Position */ +#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Msk (1UL << CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: SPNIDENSEL Mask */ -#define CoreDebug_DAUTHCTRL_INTSPIDEN_Pos 1U /*!< CoreDebug DAUTHCTRL: INTSPIDEN Position */ -#define CoreDebug_DAUTHCTRL_INTSPIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPIDEN_Pos) /*!< CoreDebug DAUTHCTRL: INTSPIDEN Mask */ +#define CoreDebug_DAUTHCTRL_INTSPIDEN_Pos 1U /*!< \deprecated CoreDebug DAUTHCTRL: INTSPIDEN Position */ +#define CoreDebug_DAUTHCTRL_INTSPIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPIDEN_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: INTSPIDEN Mask */ -#define CoreDebug_DAUTHCTRL_SPIDENSEL_Pos 0U /*!< CoreDebug DAUTHCTRL: SPIDENSEL Position */ -#define CoreDebug_DAUTHCTRL_SPIDENSEL_Msk (1UL /*<< CoreDebug_DAUTHCTRL_SPIDENSEL_Pos*/) /*!< CoreDebug DAUTHCTRL: SPIDENSEL Mask */ +#define CoreDebug_DAUTHCTRL_SPIDENSEL_Pos 0U /*!< \deprecated CoreDebug DAUTHCTRL: SPIDENSEL Position */ +#define CoreDebug_DAUTHCTRL_SPIDENSEL_Msk (1UL /*<< CoreDebug_DAUTHCTRL_SPIDENSEL_Pos*/) /*!< \deprecated CoreDebug DAUTHCTRL: SPIDENSEL Mask */ /* Debug Security Control and Status Register Definitions */ -#define CoreDebug_DSCSR_CDS_Pos 16U /*!< CoreDebug DSCSR: CDS Position */ -#define CoreDebug_DSCSR_CDS_Msk (1UL << CoreDebug_DSCSR_CDS_Pos) /*!< CoreDebug DSCSR: CDS Mask */ +#define CoreDebug_DSCSR_CDS_Pos 16U /*!< \deprecated CoreDebug DSCSR: CDS Position */ +#define CoreDebug_DSCSR_CDS_Msk (1UL << CoreDebug_DSCSR_CDS_Pos) /*!< \deprecated CoreDebug DSCSR: CDS Mask */ -#define CoreDebug_DSCSR_SBRSEL_Pos 1U /*!< CoreDebug DSCSR: SBRSEL Position */ -#define CoreDebug_DSCSR_SBRSEL_Msk (1UL << CoreDebug_DSCSR_SBRSEL_Pos) /*!< CoreDebug DSCSR: SBRSEL Mask */ +#define CoreDebug_DSCSR_SBRSEL_Pos 1U /*!< \deprecated CoreDebug DSCSR: SBRSEL Position */ +#define CoreDebug_DSCSR_SBRSEL_Msk (1UL << CoreDebug_DSCSR_SBRSEL_Pos) /*!< \deprecated CoreDebug DSCSR: SBRSEL Mask */ -#define CoreDebug_DSCSR_SBRSELEN_Pos 0U /*!< CoreDebug DSCSR: SBRSELEN Position */ -#define CoreDebug_DSCSR_SBRSELEN_Msk (1UL /*<< CoreDebug_DSCSR_SBRSELEN_Pos*/) /*!< CoreDebug DSCSR: SBRSELEN Mask */ +#define CoreDebug_DSCSR_SBRSELEN_Pos 0U /*!< \deprecated CoreDebug DSCSR: SBRSELEN Position */ +#define CoreDebug_DSCSR_SBRSELEN_Msk (1UL /*<< CoreDebug_DSCSR_SBRSELEN_Pos*/) /*!< \deprecated CoreDebug DSCSR: SBRSELEN Mask */ /*@} end of group CMSIS_CoreDebug */ +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_DCB Debug Control Block + \brief Type definitions for the Debug Control Block Registers + @{ + */ + +/** + \brief Structure type to access the Debug Control Block Registers (DCB). + */ +typedef struct +{ + __IOM uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */ + __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ + __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ + __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ + uint32_t RESERVED0[1U]; + __IOM uint32_t DAUTHCTRL; /*!< Offset: 0x014 (R/W) Debug Authentication Control Register */ + __IOM uint32_t DSCSR; /*!< Offset: 0x018 (R/W) Debug Security Control and Status Register */ +} DCB_Type; + +/* DHCSR, Debug Halting Control and Status Register Definitions */ +#define DCB_DHCSR_DBGKEY_Pos 16U /*!< DCB DHCSR: Debug key Position */ +#define DCB_DHCSR_DBGKEY_Msk (0xFFFFUL << DCB_DHCSR_DBGKEY_Pos) /*!< DCB DHCSR: Debug key Mask */ + +#define DCB_DHCSR_S_RESTART_ST_Pos 26U /*!< DCB DHCSR: Restart sticky status Position */ +#define DCB_DHCSR_S_RESTART_ST_Msk (0x1UL << DCB_DHCSR_S_RESTART_ST_Pos) /*!< DCB DHCSR: Restart sticky status Mask */ + +#define DCB_DHCSR_S_RESET_ST_Pos 25U /*!< DCB DHCSR: Reset sticky status Position */ +#define DCB_DHCSR_S_RESET_ST_Msk (0x1UL << DCB_DHCSR_S_RESET_ST_Pos) /*!< DCB DHCSR: Reset sticky status Mask */ + +#define DCB_DHCSR_S_RETIRE_ST_Pos 24U /*!< DCB DHCSR: Retire sticky status Position */ +#define DCB_DHCSR_S_RETIRE_ST_Msk (0x1UL << DCB_DHCSR_S_RETIRE_ST_Pos) /*!< DCB DHCSR: Retire sticky status Mask */ + +#define DCB_DHCSR_S_SDE_Pos 20U /*!< DCB DHCSR: Secure debug enabled Position */ +#define DCB_DHCSR_S_SDE_Msk (0x1UL << DCB_DHCSR_S_SDE_Pos) /*!< DCB DHCSR: Secure debug enabled Mask */ + +#define DCB_DHCSR_S_LOCKUP_Pos 19U /*!< DCB DHCSR: Lockup status Position */ +#define DCB_DHCSR_S_LOCKUP_Msk (0x1UL << DCB_DHCSR_S_LOCKUP_Pos) /*!< DCB DHCSR: Lockup status Mask */ + +#define DCB_DHCSR_S_SLEEP_Pos 18U /*!< DCB DHCSR: Sleeping status Position */ +#define DCB_DHCSR_S_SLEEP_Msk (0x1UL << DCB_DHCSR_S_SLEEP_Pos) /*!< DCB DHCSR: Sleeping status Mask */ + +#define DCB_DHCSR_S_HALT_Pos 17U /*!< DCB DHCSR: Halted status Position */ +#define DCB_DHCSR_S_HALT_Msk (0x1UL << DCB_DHCSR_S_HALT_Pos) /*!< DCB DHCSR: Halted status Mask */ + +#define DCB_DHCSR_S_REGRDY_Pos 16U /*!< DCB DHCSR: Register ready status Position */ +#define DCB_DHCSR_S_REGRDY_Msk (0x1UL << DCB_DHCSR_S_REGRDY_Pos) /*!< DCB DHCSR: Register ready status Mask */ + +#define DCB_DHCSR_C_MASKINTS_Pos 3U /*!< DCB DHCSR: Mask interrupts control Position */ +#define DCB_DHCSR_C_MASKINTS_Msk (0x1UL << DCB_DHCSR_C_MASKINTS_Pos) /*!< DCB DHCSR: Mask interrupts control Mask */ + +#define DCB_DHCSR_C_STEP_Pos 2U /*!< DCB DHCSR: Step control Position */ +#define DCB_DHCSR_C_STEP_Msk (0x1UL << DCB_DHCSR_C_STEP_Pos) /*!< DCB DHCSR: Step control Mask */ + +#define DCB_DHCSR_C_HALT_Pos 1U /*!< DCB DHCSR: Halt control Position */ +#define DCB_DHCSR_C_HALT_Msk (0x1UL << DCB_DHCSR_C_HALT_Pos) /*!< DCB DHCSR: Halt control Mask */ + +#define DCB_DHCSR_C_DEBUGEN_Pos 0U /*!< DCB DHCSR: Debug enable control Position */ +#define DCB_DHCSR_C_DEBUGEN_Msk (0x1UL /*<< DCB_DHCSR_C_DEBUGEN_Pos*/) /*!< DCB DHCSR: Debug enable control Mask */ + +/* DCRSR, Debug Core Register Select Register Definitions */ +#define DCB_DCRSR_REGWnR_Pos 16U /*!< DCB DCRSR: Register write/not-read Position */ +#define DCB_DCRSR_REGWnR_Msk (0x1UL << DCB_DCRSR_REGWnR_Pos) /*!< DCB DCRSR: Register write/not-read Mask */ + +#define DCB_DCRSR_REGSEL_Pos 0U /*!< DCB DCRSR: Register selector Position */ +#define DCB_DCRSR_REGSEL_Msk (0x7FUL /*<< DCB_DCRSR_REGSEL_Pos*/) /*!< DCB DCRSR: Register selector Mask */ + +/* DCRDR, Debug Core Register Data Register Definitions */ +#define DCB_DCRDR_DBGTMP_Pos 0U /*!< DCB DCRDR: Data temporary buffer Position */ +#define DCB_DCRDR_DBGTMP_Msk (0xFFFFFFFFUL /*<< DCB_DCRDR_DBGTMP_Pos*/) /*!< DCB DCRDR: Data temporary buffer Mask */ + +/* DEMCR, Debug Exception and Monitor Control Register Definitions */ +#define DCB_DEMCR_TRCENA_Pos 24U /*!< DCB DEMCR: Trace enable Position */ +#define DCB_DEMCR_TRCENA_Msk (0x1UL << DCB_DEMCR_TRCENA_Pos) /*!< DCB DEMCR: Trace enable Mask */ + +#define DCB_DEMCR_VC_HARDERR_Pos 10U /*!< DCB DEMCR: Vector Catch HardFault errors Position */ +#define DCB_DEMCR_VC_HARDERR_Msk (0x1UL << DCB_DEMCR_VC_HARDERR_Pos) /*!< DCB DEMCR: Vector Catch HardFault errors Mask */ + +#define DCB_DEMCR_VC_CORERESET_Pos 0U /*!< DCB DEMCR: Vector Catch Core reset Position */ +#define DCB_DEMCR_VC_CORERESET_Msk (0x1UL /*<< DCB_DEMCR_VC_CORERESET_Pos*/) /*!< DCB DEMCR: Vector Catch Core reset Mask */ + +/* DAUTHCTRL, Debug Authentication Control Register Definitions */ +#define DCB_DAUTHCTRL_INTSPNIDEN_Pos 3U /*!< DCB DAUTHCTRL: Internal Secure non-invasive debug enable Position */ +#define DCB_DAUTHCTRL_INTSPNIDEN_Msk (0x1UL << DCB_DAUTHCTRL_INTSPNIDEN_Pos) /*!< DCB DAUTHCTRL: Internal Secure non-invasive debug enable Mask */ + +#define DCB_DAUTHCTRL_SPNIDENSEL_Pos 2U /*!< DCB DAUTHCTRL: Secure non-invasive debug enable select Position */ +#define DCB_DAUTHCTRL_SPNIDENSEL_Msk (0x1UL << DCB_DAUTHCTRL_SPNIDENSEL_Pos) /*!< DCB DAUTHCTRL: Secure non-invasive debug enable select Mask */ + +#define DCB_DAUTHCTRL_INTSPIDEN_Pos 1U /*!< DCB DAUTHCTRL: Internal Secure invasive debug enable Position */ +#define DCB_DAUTHCTRL_INTSPIDEN_Msk (0x1UL << DCB_DAUTHCTRL_INTSPIDEN_Pos) /*!< DCB DAUTHCTRL: Internal Secure invasive debug enable Mask */ + +#define DCB_DAUTHCTRL_SPIDENSEL_Pos 0U /*!< DCB DAUTHCTRL: Secure invasive debug enable select Position */ +#define DCB_DAUTHCTRL_SPIDENSEL_Msk (0x1UL /*<< DCB_DAUTHCTRL_SPIDENSEL_Pos*/) /*!< DCB DAUTHCTRL: Secure invasive debug enable select Mask */ + +/* DSCSR, Debug Security Control and Status Register Definitions */ +#define DCB_DSCSR_CDSKEY_Pos 17U /*!< DCB DSCSR: CDS write-enable key Position */ +#define DCB_DSCSR_CDSKEY_Msk (0x1UL << DCB_DSCSR_CDSKEY_Pos) /*!< DCB DSCSR: CDS write-enable key Mask */ + +#define DCB_DSCSR_CDS_Pos 16U /*!< DCB DSCSR: Current domain Secure Position */ +#define DCB_DSCSR_CDS_Msk (0x1UL << DCB_DSCSR_CDS_Pos) /*!< DCB DSCSR: Current domain Secure Mask */ + +#define DCB_DSCSR_SBRSEL_Pos 1U /*!< DCB DSCSR: Secure banked register select Position */ +#define DCB_DSCSR_SBRSEL_Msk (0x1UL << DCB_DSCSR_SBRSEL_Pos) /*!< DCB DSCSR: Secure banked register select Mask */ + +#define DCB_DSCSR_SBRSELEN_Pos 0U /*!< DCB DSCSR: Secure banked register select enable Position */ +#define DCB_DSCSR_SBRSELEN_Msk (0x1UL /*<< DCB_DSCSR_SBRSELEN_Pos*/) /*!< DCB DSCSR: Secure banked register select enable Mask */ + +/*@} end of group CMSIS_DCB */ + + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_DIB Debug Identification Block + \brief Type definitions for the Debug Identification Block Registers + @{ + */ + +/** + \brief Structure type to access the Debug Identification Block Registers (DIB). + */ +typedef struct +{ + __OM uint32_t DLAR; /*!< Offset: 0x000 ( /W) SCS Software Lock Access Register */ + __IM uint32_t DLSR; /*!< Offset: 0x004 (R/ ) SCS Software Lock Status Register */ + __IM uint32_t DAUTHSTATUS; /*!< Offset: 0x008 (R/ ) Debug Authentication Status Register */ + __IM uint32_t DDEVARCH; /*!< Offset: 0x00C (R/ ) SCS Device Architecture Register */ + __IM uint32_t DDEVTYPE; /*!< Offset: 0x010 (R/ ) SCS Device Type Register */ +} DIB_Type; + +/* DLAR, SCS Software Lock Access Register Definitions */ +#define DIB_DLAR_KEY_Pos 0U /*!< DIB DLAR: KEY Position */ +#define DIB_DLAR_KEY_Msk (0xFFFFFFFFUL /*<< DIB_DLAR_KEY_Pos */) /*!< DIB DLAR: KEY Mask */ + +/* DLSR, SCS Software Lock Status Register Definitions */ +#define DIB_DLSR_nTT_Pos 2U /*!< DIB DLSR: Not thirty-two bit Position */ +#define DIB_DLSR_nTT_Msk (0x1UL << DIB_DLSR_nTT_Pos ) /*!< DIB DLSR: Not thirty-two bit Mask */ + +#define DIB_DLSR_SLK_Pos 1U /*!< DIB DLSR: Software Lock status Position */ +#define DIB_DLSR_SLK_Msk (0x1UL << DIB_DLSR_SLK_Pos ) /*!< DIB DLSR: Software Lock status Mask */ + +#define DIB_DLSR_SLI_Pos 0U /*!< DIB DLSR: Software Lock implemented Position */ +#define DIB_DLSR_SLI_Msk (0x1UL /*<< DIB_DLSR_SLI_Pos*/) /*!< DIB DLSR: Software Lock implemented Mask */ + +/* DAUTHSTATUS, Debug Authentication Status Register Definitions */ +#define DIB_DAUTHSTATUS_SNID_Pos 6U /*!< DIB DAUTHSTATUS: Secure Non-invasive Debug Position */ +#define DIB_DAUTHSTATUS_SNID_Msk (0x3UL << DIB_DAUTHSTATUS_SNID_Pos ) /*!< DIB DAUTHSTATUS: Secure Non-invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_SID_Pos 4U /*!< DIB DAUTHSTATUS: Secure Invasive Debug Position */ +#define DIB_DAUTHSTATUS_SID_Msk (0x3UL << DIB_DAUTHSTATUS_SID_Pos ) /*!< DIB DAUTHSTATUS: Secure Invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_NSNID_Pos 2U /*!< DIB DAUTHSTATUS: Non-secure Non-invasive Debug Position */ +#define DIB_DAUTHSTATUS_NSNID_Msk (0x3UL << DIB_DAUTHSTATUS_NSNID_Pos ) /*!< DIB DAUTHSTATUS: Non-secure Non-invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_NSID_Pos 0U /*!< DIB DAUTHSTATUS: Non-secure Invasive Debug Position */ +#define DIB_DAUTHSTATUS_NSID_Msk (0x3UL /*<< DIB_DAUTHSTATUS_NSID_Pos*/) /*!< DIB DAUTHSTATUS: Non-secure Invasive Debug Mask */ + +/* DDEVARCH, SCS Device Architecture Register Definitions */ +#define DIB_DDEVARCH_ARCHITECT_Pos 21U /*!< DIB DDEVARCH: Architect Position */ +#define DIB_DDEVARCH_ARCHITECT_Msk (0x7FFUL << DIB_DDEVARCH_ARCHITECT_Pos ) /*!< DIB DDEVARCH: Architect Mask */ + +#define DIB_DDEVARCH_PRESENT_Pos 20U /*!< DIB DDEVARCH: DEVARCH Present Position */ +#define DIB_DDEVARCH_PRESENT_Msk (0x1FUL << DIB_DDEVARCH_PRESENT_Pos ) /*!< DIB DDEVARCH: DEVARCH Present Mask */ + +#define DIB_DDEVARCH_REVISION_Pos 16U /*!< DIB DDEVARCH: Revision Position */ +#define DIB_DDEVARCH_REVISION_Msk (0xFUL << DIB_DDEVARCH_REVISION_Pos ) /*!< DIB DDEVARCH: Revision Mask */ + +#define DIB_DDEVARCH_ARCHVER_Pos 12U /*!< DIB DDEVARCH: Architecture Version Position */ +#define DIB_DDEVARCH_ARCHVER_Msk (0xFUL << DIB_DDEVARCH_ARCHVER_Pos ) /*!< DIB DDEVARCH: Architecture Version Mask */ + +#define DIB_DDEVARCH_ARCHPART_Pos 0U /*!< DIB DDEVARCH: Architecture Part Position */ +#define DIB_DDEVARCH_ARCHPART_Msk (0xFFFUL /*<< DIB_DDEVARCH_ARCHPART_Pos*/) /*!< DIB DDEVARCH: Architecture Part Mask */ + +/* DDEVTYPE, SCS Device Type Register Definitions */ +#define DIB_DDEVTYPE_SUB_Pos 4U /*!< DIB DDEVTYPE: Sub-type Position */ +#define DIB_DDEVTYPE_SUB_Msk (0xFUL << DIB_DDEVTYPE_SUB_Pos ) /*!< DIB DDEVTYPE: Sub-type Mask */ + +#define DIB_DDEVTYPE_MAJOR_Pos 0U /*!< DIB DDEVTYPE: Major type Position */ +#define DIB_DDEVTYPE_MAJOR_Msk (0xFUL /*<< DIB_DDEVTYPE_MAJOR_Pos*/) /*!< DIB DDEVTYPE: Major type Mask */ + + +/*@} end of group CMSIS_DIB */ + + /** \ingroup CMSIS_core_register \defgroup CMSIS_core_bitfield Core register bit field macros @@ -1188,7 +1376,9 @@ typedef struct #define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */ #define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */ #define TPI_BASE (0xE0040000UL) /*!< TPI Base Address */ - #define CoreDebug_BASE (0xE000EDF0UL) /*!< Core Debug Base Address */ + #define CoreDebug_BASE (0xE000EDF0UL) /*!< \deprecated Core Debug Base Address */ + #define DCB_BASE (0xE000EDF0UL) /*!< DCB Base Address */ + #define DIB_BASE (0xE000EFB0UL) /*!< DIB Base Address */ #define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */ #define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */ #define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */ @@ -1199,7 +1389,9 @@ typedef struct #define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */ #define DWT ((DWT_Type *) DWT_BASE ) /*!< DWT configuration struct */ #define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct */ - #define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE ) /*!< Core Debug configuration struct */ + #define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE ) /*!< \deprecated Core Debug configuration struct */ + #define DCB ((DCB_Type *) DCB_BASE ) /*!< DCB configuration struct */ + #define DIB ((DIB_Type *) DIB_BASE ) /*!< DIB configuration struct */ #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */ @@ -1213,7 +1405,9 @@ typedef struct #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) #define SCS_BASE_NS (0xE002E000UL) /*!< System Control Space Base Address (non-secure address space) */ - #define CoreDebug_BASE_NS (0xE002EDF0UL) /*!< Core Debug Base Address (non-secure address space) */ + #define CoreDebug_BASE_NS (0xE002EDF0UL) /*!< \deprecated Core Debug Base Address (non-secure address space) */ + #define DCB_BASE_NS (0xE002EDF0UL) /*!< DCB Base Address (non-secure address space) */ + #define DIB_BASE_NS (0xE002EFB0UL) /*!< DIB Base Address (non-secure address space) */ #define SysTick_BASE_NS (SCS_BASE_NS + 0x0010UL) /*!< SysTick Base Address (non-secure address space) */ #define NVIC_BASE_NS (SCS_BASE_NS + 0x0100UL) /*!< NVIC Base Address (non-secure address space) */ #define SCB_BASE_NS (SCS_BASE_NS + 0x0D00UL) /*!< System Control Block Base Address (non-secure address space) */ @@ -1221,7 +1415,9 @@ typedef struct #define SCB_NS ((SCB_Type *) SCB_BASE_NS ) /*!< SCB configuration struct (non-secure address space) */ #define SysTick_NS ((SysTick_Type *) SysTick_BASE_NS ) /*!< SysTick configuration struct (non-secure address space) */ #define NVIC_NS ((NVIC_Type *) NVIC_BASE_NS ) /*!< NVIC configuration struct (non-secure address space) */ - #define CoreDebug_NS ((CoreDebug_Type *) CoreDebug_BASE_NS) /*!< Core Debug configuration struct (non-secure address space) */ + #define CoreDebug_NS ((CoreDebug_Type *) CoreDebug_BASE_NS) /*!< \deprecated Core Debug configuration struct (non-secure address space) */ + #define DCB_NS ((DCB_Type *) DCB_BASE_NS ) /*!< DCB configuration struct (non-secure address space) */ + #define DIB_NS ((DIB_Type *) DIB_BASE_NS ) /*!< DIB configuration struct (non-secure address space) */ #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) #define MPU_BASE_NS (SCS_BASE_NS + 0x0D90UL) /*!< Memory Protection Unit (non-secure address space) */ @@ -1238,6 +1434,7 @@ typedef struct Core Function Interface contains: - Core NVIC Functions - Core SysTick Functions + - Core Debug Functions - Core Register Access Functions ******************************************************************************/ /** @@ -1304,11 +1501,11 @@ typedef struct /* Integrity Signature (from ARMv8-M Architecture Reference Manual) for exception context stacking */ #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) /* Value for processors with floating-point extension: */ #define EXC_INTEGRITY_SIGNATURE (0xFEFA125AUL) /* bit [0] SFTC must match LR bit[4] EXC_RETURN_FTYPE */ -#else +#else #define EXC_INTEGRITY_SIGNATURE (0xFEFA125BUL) /* Value for processors without floating-point extension */ #endif - + /* Interrupt Priorities are WORD accessible only under Armv6-M */ /* The following MACROS handle generation of the register offset and byte masks */ #define _BIT_SHIFT(IRQn) ( ((((uint32_t)(int32_t)(IRQn)) ) & 0x03UL) * 8UL) @@ -1328,7 +1525,9 @@ __STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) { if ((int32_t)(IRQn) >= 0) { + __COMPILER_BARRIER(); NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __COMPILER_BARRIER(); } } @@ -1627,6 +1826,7 @@ __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) uint32_t *vectors = (uint32_t *)0x0U; #endif vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector; + __DSB(); } @@ -1910,6 +2110,110 @@ __STATIC_INLINE void TZ_SAU_Disable(void) +/* ################################## Debug Control function ############################################ */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_DCBFunctions Debug Control Functions + \brief Functions that access the Debug Control Block. + @{ + */ + + +/** + \brief Set Debug Authentication Control Register + \details writes to Debug Authentication Control register. + \param [in] value value to be writen. + */ +__STATIC_INLINE void DCB_SetAuthCtrl(uint32_t value) +{ + __DSB(); + __ISB(); + DCB->DAUTHCTRL = value; + __DSB(); + __ISB(); +} + + +/** + \brief Get Debug Authentication Control Register + \details Reads Debug Authentication Control register. + \return Debug Authentication Control Register. + */ +__STATIC_INLINE uint32_t DCB_GetAuthCtrl(void) +{ + return (DCB->DAUTHCTRL); +} + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief Set Debug Authentication Control Register (non-secure) + \details writes to non-secure Debug Authentication Control register when in secure state. + \param [in] value value to be writen + */ +__STATIC_INLINE void TZ_DCB_SetAuthCtrl_NS(uint32_t value) +{ + __DSB(); + __ISB(); + DCB_NS->DAUTHCTRL = value; + __DSB(); + __ISB(); +} + + +/** + \brief Get Debug Authentication Control Register (non-secure) + \details Reads non-secure Debug Authentication Control register when in secure state. + \return Debug Authentication Control Register. + */ +__STATIC_INLINE uint32_t TZ_DCB_GetAuthCtrl_NS(void) +{ + return (DCB_NS->DAUTHCTRL); +} +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + +/*@} end of CMSIS_Core_DCBFunctions */ + + + + +/* ################################## Debug Identification function ############################################ */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_DIBFunctions Debug Identification Functions + \brief Functions that access the Debug Identification Block. + @{ + */ + + +/** + \brief Get Debug Authentication Status Register + \details Reads Debug Authentication Status register. + \return Debug Authentication Status Register. + */ +__STATIC_INLINE uint32_t DIB_GetAuthStatus(void) +{ + return (DIB->DAUTHSTATUS); +} + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief Get Debug Authentication Status Register (non-secure) + \details Reads non-secure Debug Authentication Status register when in secure state. + \return Debug Authentication Status Register. + */ +__STATIC_INLINE uint32_t TZ_DIB_GetAuthStatus_NS(void) +{ + return (DIB_NS->DAUTHSTATUS); +} +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + +/*@} end of CMSIS_Core_DCBFunctions */ + + + + /* ################################## SysTick function ############################################ */ /** \ingroup CMSIS_Core_FunctionInterface diff --git a/lib/cmsis/inc/core_cm3.h b/lib/cmsis/inc/core_cm3.h index ea5405088c3ef..74fb87e5c561f 100644 --- a/lib/cmsis/inc/core_cm3.h +++ b/lib/cmsis/inc/core_cm3.h @@ -1,11 +1,11 @@ /**************************************************************************//** * @file core_cm3.h * @brief CMSIS Cortex-M3 Core Peripheral Access Layer Header File - * @version V5.1.0 - * @date 13. March 2019 + * @version V5.1.2 + * @date 04. June 2021 ******************************************************************************/ /* - * Copyright (c) 2009-2019 Arm Limited. All rights reserved. + * Copyright (c) 2009-2021 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -62,7 +62,7 @@ #include "cmsis_version.h" -/* CMSIS CM3 definitions */ +/* CMSIS CM3 definitions */ #define __CM3_CMSIS_VERSION_MAIN (__CM_CMSIS_VERSION_MAIN) /*!< \deprecated [31:16] CMSIS HAL main version */ #define __CM3_CMSIS_VERSION_SUB (__CM_CMSIS_VERSION_SUB) /*!< \deprecated [15:0] CMSIS HAL sub version */ #define __CM3_CMSIS_VERSION ((__CM3_CMSIS_VERSION_MAIN << 16U) | \ @@ -142,6 +142,11 @@ #warning "__MPU_PRESENT not defined in device header file; using default!" #endif + #ifndef __VTOR_PRESENT + #define __VTOR_PRESENT 1U + #warning "__VTOR_PRESENT not defined in device header file; using default!" + #endif + #ifndef __NVIC_PRIO_BITS #define __NVIC_PRIO_BITS 3U #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" @@ -560,19 +565,19 @@ typedef struct #define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */ /* MemManage Fault Status Register (part of SCB Configurable Fault Status Register) */ -#define SCB_CFSR_MMARVALID_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */ +#define SCB_CFSR_MMARVALID_Pos (SCB_CFSR_MEMFAULTSR_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */ #define SCB_CFSR_MMARVALID_Msk (1UL << SCB_CFSR_MMARVALID_Pos) /*!< SCB CFSR (MMFSR): MMARVALID Mask */ -#define SCB_CFSR_MSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */ +#define SCB_CFSR_MSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */ #define SCB_CFSR_MSTKERR_Msk (1UL << SCB_CFSR_MSTKERR_Pos) /*!< SCB CFSR (MMFSR): MSTKERR Mask */ -#define SCB_CFSR_MUNSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */ +#define SCB_CFSR_MUNSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */ #define SCB_CFSR_MUNSTKERR_Msk (1UL << SCB_CFSR_MUNSTKERR_Pos) /*!< SCB CFSR (MMFSR): MUNSTKERR Mask */ -#define SCB_CFSR_DACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */ +#define SCB_CFSR_DACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */ #define SCB_CFSR_DACCVIOL_Msk (1UL << SCB_CFSR_DACCVIOL_Pos) /*!< SCB CFSR (MMFSR): DACCVIOL Mask */ -#define SCB_CFSR_IACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */ +#define SCB_CFSR_IACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */ #define SCB_CFSR_IACCVIOL_Msk (1UL /*<< SCB_CFSR_IACCVIOL_Pos*/) /*!< SCB CFSR (MMFSR): IACCVIOL Mask */ /* BusFault Status Register (part of SCB Configurable Fault Status Register) */ @@ -1443,7 +1448,7 @@ typedef struct #ifdef CMSIS_VECTAB_VIRTUAL #ifndef CMSIS_VECTAB_VIRTUAL_HEADER_FILE - #define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h" + #define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h" #endif #include CMSIS_VECTAB_VIRTUAL_HEADER_FILE #else @@ -1478,7 +1483,7 @@ __STATIC_INLINE void __NVIC_SetPriorityGrouping(uint32_t PriorityGroup) reg_value &= ~((uint32_t)(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk)); /* clear bits to change */ reg_value = (reg_value | ((uint32_t)0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | - (PriorityGroupTmp << SCB_AIRCR_PRIGROUP_Pos) ); /* Insert write key and priority group */ + (PriorityGroupTmp << SCB_AIRCR_PRIGROUP_Pos) ); /* Insert write key and priority group */ SCB->AIRCR = reg_value; } @@ -1504,7 +1509,9 @@ __STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) { if ((int32_t)(IRQn) >= 0) { + __COMPILER_BARRIER(); NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __COMPILER_BARRIER(); } } @@ -1727,8 +1734,9 @@ __STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGr */ __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) { - uint32_t vectors = (uint32_t )SCB->VTOR; - (* (int *) (vectors + ((int32_t)IRQn + NVIC_USER_IRQ_OFFSET) * 4)) = vector; + uint32_t *vectors = (uint32_t *)SCB->VTOR; + vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector; + /* ARM Application Note 321 states that the M3 does not require the architectural barrier */ } @@ -1742,8 +1750,8 @@ __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) */ __STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn) { - uint32_t vectors = (uint32_t )SCB->VTOR; - return (uint32_t)(* (int *) (vectors + ((int32_t)IRQn + NVIC_USER_IRQ_OFFSET) * 4)); + uint32_t *vectors = (uint32_t *)SCB->VTOR; + return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET]; } @@ -1768,6 +1776,7 @@ __NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void) /*@} end of CMSIS_Core_NVICFunctions */ + /* ########################## MPU functions #################################### */ #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) diff --git a/lib/cmsis/inc/core_cm33.h b/lib/cmsis/inc/core_cm33.h index d5d97a96f2d6b..18a2e6fb0343a 100644 --- a/lib/cmsis/inc/core_cm33.h +++ b/lib/cmsis/inc/core_cm33.h @@ -1,11 +1,11 @@ /**************************************************************************//** * @file core_cm33.h * @brief CMSIS Cortex-M33 Core Peripheral Access Layer Header File - * @version V5.1.0 - * @date 12. November 2018 + * @version V5.2.3 + * @date 13. October 2021 ******************************************************************************/ /* - * Copyright (c) 2009-2018 Arm Limited. All rights reserved. + * Copyright (c) 2009-2021 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -23,9 +23,11 @@ */ #if defined ( __ICCARM__ ) - #pragma system_include /* treat file as system include file for MISRA check */ + #pragma system_include /* treat file as system include file for MISRA check */ #elif defined (__clang__) - #pragma clang system_header /* treat file as system include file */ + #pragma clang system_header /* treat file as system include file */ +#elif defined ( __GNUC__ ) + #pragma GCC diagnostic ignored "-Wpedantic" /* disable pedantic warning due to unnamed structs/unions */ #endif #ifndef __CORE_CM33_H_GENERIC @@ -248,6 +250,11 @@ #warning "__DSP_PRESENT not defined in device header file; using default!" #endif + #ifndef __VTOR_PRESENT + #define __VTOR_PRESENT 1U + #warning "__VTOR_PRESENT not defined in device header file; using default!" + #endif + #ifndef __NVIC_PRIO_BITS #define __NVIC_PRIO_BITS 3U #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" @@ -512,7 +519,7 @@ typedef struct __IOM uint32_t AFSR; /*!< Offset: 0x03C (R/W) Auxiliary Fault Status Register */ __IM uint32_t ID_PFR[2U]; /*!< Offset: 0x040 (R/ ) Processor Feature Register */ __IM uint32_t ID_DFR; /*!< Offset: 0x048 (R/ ) Debug Feature Register */ - __IM uint32_t ID_ADR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */ + __IM uint32_t ID_AFR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */ __IM uint32_t ID_MMFR[4U]; /*!< Offset: 0x050 (R/ ) Memory Model Feature Register */ __IM uint32_t ID_ISAR[6U]; /*!< Offset: 0x060 (R/ ) Instruction Set Attributes Register */ __IM uint32_t CLIDR; /*!< Offset: 0x078 (R/ ) Cache Level ID register */ @@ -521,7 +528,10 @@ typedef struct __IOM uint32_t CSSELR; /*!< Offset: 0x084 (R/W) Cache Size Selection Register */ __IOM uint32_t CPACR; /*!< Offset: 0x088 (R/W) Coprocessor Access Control Register */ __IOM uint32_t NSACR; /*!< Offset: 0x08C (R/W) Non-Secure Access Control Register */ - uint32_t RESERVED3[92U]; + uint32_t RESERVED7[21U]; + __IOM uint32_t SFSR; /*!< Offset: 0x0E4 (R/W) Secure Fault Status Register */ + __IOM uint32_t SFAR; /*!< Offset: 0x0E8 (R/W) Secure Fault Address Register */ + uint32_t RESERVED3[69U]; __OM uint32_t STIR; /*!< Offset: 0x200 ( /W) Software Triggered Interrupt Register */ uint32_t RESERVED4[15U]; __IM uint32_t MVFR0; /*!< Offset: 0x240 (R/ ) Media and VFP Feature Register 0 */ @@ -538,6 +548,7 @@ typedef struct __OM uint32_t DCCSW; /*!< Offset: 0x26C ( /W) D-Cache Clean by Set-way */ __OM uint32_t DCCIMVAC; /*!< Offset: 0x270 ( /W) D-Cache Clean and Invalidate by MVA to PoC */ __OM uint32_t DCCISW; /*!< Offset: 0x274 ( /W) D-Cache Clean and Invalidate by Set-way */ + __OM uint32_t BPIALL; /*!< Offset: 0x278 ( /W) Branch Predictor Invalidate All */ } SCB_Type; /* SCB CPUID Register Definitions */ @@ -738,22 +749,22 @@ typedef struct #define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */ /* MemManage Fault Status Register (part of SCB Configurable Fault Status Register) */ -#define SCB_CFSR_MMARVALID_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */ +#define SCB_CFSR_MMARVALID_Pos (SCB_CFSR_MEMFAULTSR_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */ #define SCB_CFSR_MMARVALID_Msk (1UL << SCB_CFSR_MMARVALID_Pos) /*!< SCB CFSR (MMFSR): MMARVALID Mask */ -#define SCB_CFSR_MLSPERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 5U) /*!< SCB CFSR (MMFSR): MLSPERR Position */ +#define SCB_CFSR_MLSPERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 5U) /*!< SCB CFSR (MMFSR): MLSPERR Position */ #define SCB_CFSR_MLSPERR_Msk (1UL << SCB_CFSR_MLSPERR_Pos) /*!< SCB CFSR (MMFSR): MLSPERR Mask */ -#define SCB_CFSR_MSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */ +#define SCB_CFSR_MSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */ #define SCB_CFSR_MSTKERR_Msk (1UL << SCB_CFSR_MSTKERR_Pos) /*!< SCB CFSR (MMFSR): MSTKERR Mask */ -#define SCB_CFSR_MUNSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */ +#define SCB_CFSR_MUNSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */ #define SCB_CFSR_MUNSTKERR_Msk (1UL << SCB_CFSR_MUNSTKERR_Pos) /*!< SCB CFSR (MMFSR): MUNSTKERR Mask */ -#define SCB_CFSR_DACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */ +#define SCB_CFSR_DACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */ #define SCB_CFSR_DACCVIOL_Msk (1UL << SCB_CFSR_DACCVIOL_Pos) /*!< SCB CFSR (MMFSR): DACCVIOL Mask */ -#define SCB_CFSR_IACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */ +#define SCB_CFSR_IACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */ #define SCB_CFSR_IACCVIOL_Msk (1UL /*<< SCB_CFSR_IACCVIOL_Pos*/) /*!< SCB CFSR (MMFSR): IACCVIOL Mask */ /* BusFault Status Register (part of SCB Configurable Fault Status Register) */ @@ -1668,8 +1679,9 @@ typedef struct __IOM uint32_t FPCCR; /*!< Offset: 0x004 (R/W) Floating-Point Context Control Register */ __IOM uint32_t FPCAR; /*!< Offset: 0x008 (R/W) Floating-Point Context Address Register */ __IOM uint32_t FPDSCR; /*!< Offset: 0x00C (R/W) Floating-Point Default Status Control Register */ - __IM uint32_t MVFR0; /*!< Offset: 0x010 (R/ ) Media and FP Feature Register 0 */ - __IM uint32_t MVFR1; /*!< Offset: 0x014 (R/ ) Media and FP Feature Register 1 */ + __IM uint32_t MVFR0; /*!< Offset: 0x010 (R/ ) Media and VFP Feature Register 0 */ + __IM uint32_t MVFR1; /*!< Offset: 0x014 (R/ ) Media and VFP Feature Register 1 */ + __IM uint32_t MVFR2; /*!< Offset: 0x018 (R/ ) Media and VFP Feature Register 2 */ } FPU_Type; /* Floating-Point Context Control Register Definitions */ @@ -1741,7 +1753,7 @@ typedef struct #define FPU_FPDSCR_RMode_Pos 22U /*!< FPDSCR: RMode bit Position */ #define FPU_FPDSCR_RMode_Msk (3UL << FPU_FPDSCR_RMode_Pos) /*!< FPDSCR: RMode bit Mask */ -/* Media and FP Feature Register 0 Definitions */ +/* Media and VFP Feature Register 0 Definitions */ #define FPU_MVFR0_FP_rounding_modes_Pos 28U /*!< MVFR0: FP rounding modes bits Position */ #define FPU_MVFR0_FP_rounding_modes_Msk (0xFUL << FPU_MVFR0_FP_rounding_modes_Pos) /*!< MVFR0: FP rounding modes bits Mask */ @@ -1766,7 +1778,7 @@ typedef struct #define FPU_MVFR0_A_SIMD_registers_Pos 0U /*!< MVFR0: A_SIMD registers bits Position */ #define FPU_MVFR0_A_SIMD_registers_Msk (0xFUL /*<< FPU_MVFR0_A_SIMD_registers_Pos*/) /*!< MVFR0: A_SIMD registers bits Mask */ -/* Media and FP Feature Register 1 Definitions */ +/* Media and VFP Feature Register 1 Definitions */ #define FPU_MVFR1_FP_fused_MAC_Pos 28U /*!< MVFR1: FP fused MAC bits Position */ #define FPU_MVFR1_FP_fused_MAC_Msk (0xFUL << FPU_MVFR1_FP_fused_MAC_Pos) /*!< MVFR1: FP fused MAC bits Mask */ @@ -1779,9 +1791,13 @@ typedef struct #define FPU_MVFR1_FtZ_mode_Pos 0U /*!< MVFR1: FtZ mode bits Position */ #define FPU_MVFR1_FtZ_mode_Msk (0xFUL /*<< FPU_MVFR1_FtZ_mode_Pos*/) /*!< MVFR1: FtZ mode bits Mask */ -/*@} end of group CMSIS_FPU */ +/* Media and VFP Feature Register 2 Definitions */ +#define FPU_MVFR2_FPMisc_Pos 4U /*!< MVFR2: FPMisc bits Position */ +#define FPU_MVFR2_FPMisc_Msk (0xFUL << FPU_MVFR2_FPMisc_Pos) /*!< MVFR2: FPMisc bits Mask */ +/*@} end of group CMSIS_FPU */ +/* CoreDebug is deprecated. replaced by DCB (Debug Control Block) */ /** \ingroup CMSIS_core_register \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug) @@ -1790,7 +1806,7 @@ typedef struct */ /** - \brief Structure type to access the Core Debug Register (CoreDebug). + \brief \deprecated Structure type to access the Core Debug Register (CoreDebug). */ typedef struct { @@ -1798,124 +1814,354 @@ typedef struct __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ - uint32_t RESERVED4[1U]; + uint32_t RESERVED0[1U]; __IOM uint32_t DAUTHCTRL; /*!< Offset: 0x014 (R/W) Debug Authentication Control Register */ __IOM uint32_t DSCSR; /*!< Offset: 0x018 (R/W) Debug Security Control and Status Register */ } CoreDebug_Type; /* Debug Halting Control and Status Register Definitions */ -#define CoreDebug_DHCSR_DBGKEY_Pos 16U /*!< CoreDebug DHCSR: DBGKEY Position */ -#define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos) /*!< CoreDebug DHCSR: DBGKEY Mask */ +#define CoreDebug_DHCSR_DBGKEY_Pos 16U /*!< \deprecated CoreDebug DHCSR: DBGKEY Position */ +#define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos) /*!< \deprecated CoreDebug DHCSR: DBGKEY Mask */ -#define CoreDebug_DHCSR_S_RESTART_ST_Pos 26U /*!< CoreDebug DHCSR: S_RESTART_ST Position */ -#define CoreDebug_DHCSR_S_RESTART_ST_Msk (1UL << CoreDebug_DHCSR_S_RESTART_ST_Pos) /*!< CoreDebug DHCSR: S_RESTART_ST Mask */ +#define CoreDebug_DHCSR_S_RESTART_ST_Pos 26U /*!< \deprecated CoreDebug DHCSR: S_RESTART_ST Position */ +#define CoreDebug_DHCSR_S_RESTART_ST_Msk (1UL << CoreDebug_DHCSR_S_RESTART_ST_Pos) /*!< \deprecated CoreDebug DHCSR: S_RESTART_ST Mask */ -#define CoreDebug_DHCSR_S_RESET_ST_Pos 25U /*!< CoreDebug DHCSR: S_RESET_ST Position */ -#define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< CoreDebug DHCSR: S_RESET_ST Mask */ +#define CoreDebug_DHCSR_S_RESET_ST_Pos 25U /*!< \deprecated CoreDebug DHCSR: S_RESET_ST Position */ +#define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< \deprecated CoreDebug DHCSR: S_RESET_ST Mask */ -#define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24U /*!< CoreDebug DHCSR: S_RETIRE_ST Position */ -#define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< CoreDebug DHCSR: S_RETIRE_ST Mask */ +#define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24U /*!< \deprecated CoreDebug DHCSR: S_RETIRE_ST Position */ +#define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< \deprecated CoreDebug DHCSR: S_RETIRE_ST Mask */ -#define CoreDebug_DHCSR_S_LOCKUP_Pos 19U /*!< CoreDebug DHCSR: S_LOCKUP Position */ -#define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< CoreDebug DHCSR: S_LOCKUP Mask */ +#define CoreDebug_DHCSR_S_LOCKUP_Pos 19U /*!< \deprecated CoreDebug DHCSR: S_LOCKUP Position */ +#define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< \deprecated CoreDebug DHCSR: S_LOCKUP Mask */ -#define CoreDebug_DHCSR_S_SLEEP_Pos 18U /*!< CoreDebug DHCSR: S_SLEEP Position */ -#define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< CoreDebug DHCSR: S_SLEEP Mask */ +#define CoreDebug_DHCSR_S_SLEEP_Pos 18U /*!< \deprecated CoreDebug DHCSR: S_SLEEP Position */ +#define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< \deprecated CoreDebug DHCSR: S_SLEEP Mask */ -#define CoreDebug_DHCSR_S_HALT_Pos 17U /*!< CoreDebug DHCSR: S_HALT Position */ -#define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos) /*!< CoreDebug DHCSR: S_HALT Mask */ +#define CoreDebug_DHCSR_S_HALT_Pos 17U /*!< \deprecated CoreDebug DHCSR: S_HALT Position */ +#define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos) /*!< \deprecated CoreDebug DHCSR: S_HALT Mask */ -#define CoreDebug_DHCSR_S_REGRDY_Pos 16U /*!< CoreDebug DHCSR: S_REGRDY Position */ -#define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< CoreDebug DHCSR: S_REGRDY Mask */ +#define CoreDebug_DHCSR_S_REGRDY_Pos 16U /*!< \deprecated CoreDebug DHCSR: S_REGRDY Position */ +#define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< \deprecated CoreDebug DHCSR: S_REGRDY Mask */ -#define CoreDebug_DHCSR_C_SNAPSTALL_Pos 5U /*!< CoreDebug DHCSR: C_SNAPSTALL Position */ -#define CoreDebug_DHCSR_C_SNAPSTALL_Msk (1UL << CoreDebug_DHCSR_C_SNAPSTALL_Pos) /*!< CoreDebug DHCSR: C_SNAPSTALL Mask */ +#define CoreDebug_DHCSR_C_SNAPSTALL_Pos 5U /*!< \deprecated CoreDebug DHCSR: C_SNAPSTALL Position */ +#define CoreDebug_DHCSR_C_SNAPSTALL_Msk (1UL << CoreDebug_DHCSR_C_SNAPSTALL_Pos) /*!< \deprecated CoreDebug DHCSR: C_SNAPSTALL Mask */ -#define CoreDebug_DHCSR_C_MASKINTS_Pos 3U /*!< CoreDebug DHCSR: C_MASKINTS Position */ -#define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< CoreDebug DHCSR: C_MASKINTS Mask */ +#define CoreDebug_DHCSR_C_MASKINTS_Pos 3U /*!< \deprecated CoreDebug DHCSR: C_MASKINTS Position */ +#define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< \deprecated CoreDebug DHCSR: C_MASKINTS Mask */ -#define CoreDebug_DHCSR_C_STEP_Pos 2U /*!< CoreDebug DHCSR: C_STEP Position */ -#define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos) /*!< CoreDebug DHCSR: C_STEP Mask */ +#define CoreDebug_DHCSR_C_STEP_Pos 2U /*!< \deprecated CoreDebug DHCSR: C_STEP Position */ +#define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos) /*!< \deprecated CoreDebug DHCSR: C_STEP Mask */ -#define CoreDebug_DHCSR_C_HALT_Pos 1U /*!< CoreDebug DHCSR: C_HALT Position */ -#define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos) /*!< CoreDebug DHCSR: C_HALT Mask */ +#define CoreDebug_DHCSR_C_HALT_Pos 1U /*!< \deprecated CoreDebug DHCSR: C_HALT Position */ +#define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos) /*!< \deprecated CoreDebug DHCSR: C_HALT Mask */ -#define CoreDebug_DHCSR_C_DEBUGEN_Pos 0U /*!< CoreDebug DHCSR: C_DEBUGEN Position */ -#define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL /*<< CoreDebug_DHCSR_C_DEBUGEN_Pos*/) /*!< CoreDebug DHCSR: C_DEBUGEN Mask */ +#define CoreDebug_DHCSR_C_DEBUGEN_Pos 0U /*!< \deprecated CoreDebug DHCSR: C_DEBUGEN Position */ +#define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL /*<< CoreDebug_DHCSR_C_DEBUGEN_Pos*/) /*!< \deprecated CoreDebug DHCSR: C_DEBUGEN Mask */ /* Debug Core Register Selector Register Definitions */ -#define CoreDebug_DCRSR_REGWnR_Pos 16U /*!< CoreDebug DCRSR: REGWnR Position */ -#define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos) /*!< CoreDebug DCRSR: REGWnR Mask */ +#define CoreDebug_DCRSR_REGWnR_Pos 16U /*!< \deprecated CoreDebug DCRSR: REGWnR Position */ +#define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos) /*!< \deprecated CoreDebug DCRSR: REGWnR Mask */ -#define CoreDebug_DCRSR_REGSEL_Pos 0U /*!< CoreDebug DCRSR: REGSEL Position */ -#define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL /*<< CoreDebug_DCRSR_REGSEL_Pos*/) /*!< CoreDebug DCRSR: REGSEL Mask */ +#define CoreDebug_DCRSR_REGSEL_Pos 0U /*!< \deprecated CoreDebug DCRSR: REGSEL Position */ +#define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL /*<< CoreDebug_DCRSR_REGSEL_Pos*/) /*!< \deprecated CoreDebug DCRSR: REGSEL Mask */ /* Debug Exception and Monitor Control Register Definitions */ -#define CoreDebug_DEMCR_TRCENA_Pos 24U /*!< CoreDebug DEMCR: TRCENA Position */ -#define CoreDebug_DEMCR_TRCENA_Msk (1UL << CoreDebug_DEMCR_TRCENA_Pos) /*!< CoreDebug DEMCR: TRCENA Mask */ +#define CoreDebug_DEMCR_TRCENA_Pos 24U /*!< \deprecated CoreDebug DEMCR: TRCENA Position */ +#define CoreDebug_DEMCR_TRCENA_Msk (1UL << CoreDebug_DEMCR_TRCENA_Pos) /*!< \deprecated CoreDebug DEMCR: TRCENA Mask */ -#define CoreDebug_DEMCR_MON_REQ_Pos 19U /*!< CoreDebug DEMCR: MON_REQ Position */ -#define CoreDebug_DEMCR_MON_REQ_Msk (1UL << CoreDebug_DEMCR_MON_REQ_Pos) /*!< CoreDebug DEMCR: MON_REQ Mask */ +#define CoreDebug_DEMCR_MON_REQ_Pos 19U /*!< \deprecated CoreDebug DEMCR: MON_REQ Position */ +#define CoreDebug_DEMCR_MON_REQ_Msk (1UL << CoreDebug_DEMCR_MON_REQ_Pos) /*!< \deprecated CoreDebug DEMCR: MON_REQ Mask */ -#define CoreDebug_DEMCR_MON_STEP_Pos 18U /*!< CoreDebug DEMCR: MON_STEP Position */ -#define CoreDebug_DEMCR_MON_STEP_Msk (1UL << CoreDebug_DEMCR_MON_STEP_Pos) /*!< CoreDebug DEMCR: MON_STEP Mask */ +#define CoreDebug_DEMCR_MON_STEP_Pos 18U /*!< \deprecated CoreDebug DEMCR: MON_STEP Position */ +#define CoreDebug_DEMCR_MON_STEP_Msk (1UL << CoreDebug_DEMCR_MON_STEP_Pos) /*!< \deprecated CoreDebug DEMCR: MON_STEP Mask */ -#define CoreDebug_DEMCR_MON_PEND_Pos 17U /*!< CoreDebug DEMCR: MON_PEND Position */ -#define CoreDebug_DEMCR_MON_PEND_Msk (1UL << CoreDebug_DEMCR_MON_PEND_Pos) /*!< CoreDebug DEMCR: MON_PEND Mask */ +#define CoreDebug_DEMCR_MON_PEND_Pos 17U /*!< \deprecated CoreDebug DEMCR: MON_PEND Position */ +#define CoreDebug_DEMCR_MON_PEND_Msk (1UL << CoreDebug_DEMCR_MON_PEND_Pos) /*!< \deprecated CoreDebug DEMCR: MON_PEND Mask */ -#define CoreDebug_DEMCR_MON_EN_Pos 16U /*!< CoreDebug DEMCR: MON_EN Position */ -#define CoreDebug_DEMCR_MON_EN_Msk (1UL << CoreDebug_DEMCR_MON_EN_Pos) /*!< CoreDebug DEMCR: MON_EN Mask */ +#define CoreDebug_DEMCR_MON_EN_Pos 16U /*!< \deprecated CoreDebug DEMCR: MON_EN Position */ +#define CoreDebug_DEMCR_MON_EN_Msk (1UL << CoreDebug_DEMCR_MON_EN_Pos) /*!< \deprecated CoreDebug DEMCR: MON_EN Mask */ -#define CoreDebug_DEMCR_VC_HARDERR_Pos 10U /*!< CoreDebug DEMCR: VC_HARDERR Position */ -#define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< CoreDebug DEMCR: VC_HARDERR Mask */ +#define CoreDebug_DEMCR_VC_HARDERR_Pos 10U /*!< \deprecated CoreDebug DEMCR: VC_HARDERR Position */ +#define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_HARDERR Mask */ -#define CoreDebug_DEMCR_VC_INTERR_Pos 9U /*!< CoreDebug DEMCR: VC_INTERR Position */ -#define CoreDebug_DEMCR_VC_INTERR_Msk (1UL << CoreDebug_DEMCR_VC_INTERR_Pos) /*!< CoreDebug DEMCR: VC_INTERR Mask */ +#define CoreDebug_DEMCR_VC_INTERR_Pos 9U /*!< \deprecated CoreDebug DEMCR: VC_INTERR Position */ +#define CoreDebug_DEMCR_VC_INTERR_Msk (1UL << CoreDebug_DEMCR_VC_INTERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_INTERR Mask */ -#define CoreDebug_DEMCR_VC_BUSERR_Pos 8U /*!< CoreDebug DEMCR: VC_BUSERR Position */ -#define CoreDebug_DEMCR_VC_BUSERR_Msk (1UL << CoreDebug_DEMCR_VC_BUSERR_Pos) /*!< CoreDebug DEMCR: VC_BUSERR Mask */ +#define CoreDebug_DEMCR_VC_BUSERR_Pos 8U /*!< \deprecated CoreDebug DEMCR: VC_BUSERR Position */ +#define CoreDebug_DEMCR_VC_BUSERR_Msk (1UL << CoreDebug_DEMCR_VC_BUSERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_BUSERR Mask */ -#define CoreDebug_DEMCR_VC_STATERR_Pos 7U /*!< CoreDebug DEMCR: VC_STATERR Position */ -#define CoreDebug_DEMCR_VC_STATERR_Msk (1UL << CoreDebug_DEMCR_VC_STATERR_Pos) /*!< CoreDebug DEMCR: VC_STATERR Mask */ +#define CoreDebug_DEMCR_VC_STATERR_Pos 7U /*!< \deprecated CoreDebug DEMCR: VC_STATERR Position */ +#define CoreDebug_DEMCR_VC_STATERR_Msk (1UL << CoreDebug_DEMCR_VC_STATERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_STATERR Mask */ -#define CoreDebug_DEMCR_VC_CHKERR_Pos 6U /*!< CoreDebug DEMCR: VC_CHKERR Position */ -#define CoreDebug_DEMCR_VC_CHKERR_Msk (1UL << CoreDebug_DEMCR_VC_CHKERR_Pos) /*!< CoreDebug DEMCR: VC_CHKERR Mask */ +#define CoreDebug_DEMCR_VC_CHKERR_Pos 6U /*!< \deprecated CoreDebug DEMCR: VC_CHKERR Position */ +#define CoreDebug_DEMCR_VC_CHKERR_Msk (1UL << CoreDebug_DEMCR_VC_CHKERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_CHKERR Mask */ -#define CoreDebug_DEMCR_VC_NOCPERR_Pos 5U /*!< CoreDebug DEMCR: VC_NOCPERR Position */ -#define CoreDebug_DEMCR_VC_NOCPERR_Msk (1UL << CoreDebug_DEMCR_VC_NOCPERR_Pos) /*!< CoreDebug DEMCR: VC_NOCPERR Mask */ +#define CoreDebug_DEMCR_VC_NOCPERR_Pos 5U /*!< \deprecated CoreDebug DEMCR: VC_NOCPERR Position */ +#define CoreDebug_DEMCR_VC_NOCPERR_Msk (1UL << CoreDebug_DEMCR_VC_NOCPERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_NOCPERR Mask */ -#define CoreDebug_DEMCR_VC_MMERR_Pos 4U /*!< CoreDebug DEMCR: VC_MMERR Position */ -#define CoreDebug_DEMCR_VC_MMERR_Msk (1UL << CoreDebug_DEMCR_VC_MMERR_Pos) /*!< CoreDebug DEMCR: VC_MMERR Mask */ +#define CoreDebug_DEMCR_VC_MMERR_Pos 4U /*!< \deprecated CoreDebug DEMCR: VC_MMERR Position */ +#define CoreDebug_DEMCR_VC_MMERR_Msk (1UL << CoreDebug_DEMCR_VC_MMERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_MMERR Mask */ -#define CoreDebug_DEMCR_VC_CORERESET_Pos 0U /*!< CoreDebug DEMCR: VC_CORERESET Position */ -#define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL /*<< CoreDebug_DEMCR_VC_CORERESET_Pos*/) /*!< CoreDebug DEMCR: VC_CORERESET Mask */ +#define CoreDebug_DEMCR_VC_CORERESET_Pos 0U /*!< \deprecated CoreDebug DEMCR: VC_CORERESET Position */ +#define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL /*<< CoreDebug_DEMCR_VC_CORERESET_Pos*/) /*!< \deprecated CoreDebug DEMCR: VC_CORERESET Mask */ /* Debug Authentication Control Register Definitions */ -#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos 3U /*!< CoreDebug DAUTHCTRL: INTSPNIDEN, Position */ -#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos) /*!< CoreDebug DAUTHCTRL: INTSPNIDEN, Mask */ +#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos 3U /*!< \deprecated CoreDebug DAUTHCTRL: INTSPNIDEN, Position */ +#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: INTSPNIDEN, Mask */ -#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos 2U /*!< CoreDebug DAUTHCTRL: SPNIDENSEL Position */ -#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Msk (1UL << CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos) /*!< CoreDebug DAUTHCTRL: SPNIDENSEL Mask */ +#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos 2U /*!< \deprecated CoreDebug DAUTHCTRL: SPNIDENSEL Position */ +#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Msk (1UL << CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: SPNIDENSEL Mask */ -#define CoreDebug_DAUTHCTRL_INTSPIDEN_Pos 1U /*!< CoreDebug DAUTHCTRL: INTSPIDEN Position */ -#define CoreDebug_DAUTHCTRL_INTSPIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPIDEN_Pos) /*!< CoreDebug DAUTHCTRL: INTSPIDEN Mask */ +#define CoreDebug_DAUTHCTRL_INTSPIDEN_Pos 1U /*!< \deprecated CoreDebug DAUTHCTRL: INTSPIDEN Position */ +#define CoreDebug_DAUTHCTRL_INTSPIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPIDEN_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: INTSPIDEN Mask */ -#define CoreDebug_DAUTHCTRL_SPIDENSEL_Pos 0U /*!< CoreDebug DAUTHCTRL: SPIDENSEL Position */ -#define CoreDebug_DAUTHCTRL_SPIDENSEL_Msk (1UL /*<< CoreDebug_DAUTHCTRL_SPIDENSEL_Pos*/) /*!< CoreDebug DAUTHCTRL: SPIDENSEL Mask */ +#define CoreDebug_DAUTHCTRL_SPIDENSEL_Pos 0U /*!< \deprecated CoreDebug DAUTHCTRL: SPIDENSEL Position */ +#define CoreDebug_DAUTHCTRL_SPIDENSEL_Msk (1UL /*<< CoreDebug_DAUTHCTRL_SPIDENSEL_Pos*/) /*!< \deprecated CoreDebug DAUTHCTRL: SPIDENSEL Mask */ /* Debug Security Control and Status Register Definitions */ -#define CoreDebug_DSCSR_CDS_Pos 16U /*!< CoreDebug DSCSR: CDS Position */ -#define CoreDebug_DSCSR_CDS_Msk (1UL << CoreDebug_DSCSR_CDS_Pos) /*!< CoreDebug DSCSR: CDS Mask */ +#define CoreDebug_DSCSR_CDS_Pos 16U /*!< \deprecated CoreDebug DSCSR: CDS Position */ +#define CoreDebug_DSCSR_CDS_Msk (1UL << CoreDebug_DSCSR_CDS_Pos) /*!< \deprecated CoreDebug DSCSR: CDS Mask */ -#define CoreDebug_DSCSR_SBRSEL_Pos 1U /*!< CoreDebug DSCSR: SBRSEL Position */ -#define CoreDebug_DSCSR_SBRSEL_Msk (1UL << CoreDebug_DSCSR_SBRSEL_Pos) /*!< CoreDebug DSCSR: SBRSEL Mask */ +#define CoreDebug_DSCSR_SBRSEL_Pos 1U /*!< \deprecated CoreDebug DSCSR: SBRSEL Position */ +#define CoreDebug_DSCSR_SBRSEL_Msk (1UL << CoreDebug_DSCSR_SBRSEL_Pos) /*!< \deprecated CoreDebug DSCSR: SBRSEL Mask */ -#define CoreDebug_DSCSR_SBRSELEN_Pos 0U /*!< CoreDebug DSCSR: SBRSELEN Position */ -#define CoreDebug_DSCSR_SBRSELEN_Msk (1UL /*<< CoreDebug_DSCSR_SBRSELEN_Pos*/) /*!< CoreDebug DSCSR: SBRSELEN Mask */ +#define CoreDebug_DSCSR_SBRSELEN_Pos 0U /*!< \deprecated CoreDebug DSCSR: SBRSELEN Position */ +#define CoreDebug_DSCSR_SBRSELEN_Msk (1UL /*<< CoreDebug_DSCSR_SBRSELEN_Pos*/) /*!< \deprecated CoreDebug DSCSR: SBRSELEN Mask */ /*@} end of group CMSIS_CoreDebug */ +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_DCB Debug Control Block + \brief Type definitions for the Debug Control Block Registers + @{ + */ + +/** + \brief Structure type to access the Debug Control Block Registers (DCB). + */ +typedef struct +{ + __IOM uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */ + __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ + __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ + __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ + uint32_t RESERVED0[1U]; + __IOM uint32_t DAUTHCTRL; /*!< Offset: 0x014 (R/W) Debug Authentication Control Register */ + __IOM uint32_t DSCSR; /*!< Offset: 0x018 (R/W) Debug Security Control and Status Register */ +} DCB_Type; + +/* DHCSR, Debug Halting Control and Status Register Definitions */ +#define DCB_DHCSR_DBGKEY_Pos 16U /*!< DCB DHCSR: Debug key Position */ +#define DCB_DHCSR_DBGKEY_Msk (0xFFFFUL << DCB_DHCSR_DBGKEY_Pos) /*!< DCB DHCSR: Debug key Mask */ + +#define DCB_DHCSR_S_RESTART_ST_Pos 26U /*!< DCB DHCSR: Restart sticky status Position */ +#define DCB_DHCSR_S_RESTART_ST_Msk (0x1UL << DCB_DHCSR_S_RESTART_ST_Pos) /*!< DCB DHCSR: Restart sticky status Mask */ + +#define DCB_DHCSR_S_RESET_ST_Pos 25U /*!< DCB DHCSR: Reset sticky status Position */ +#define DCB_DHCSR_S_RESET_ST_Msk (0x1UL << DCB_DHCSR_S_RESET_ST_Pos) /*!< DCB DHCSR: Reset sticky status Mask */ + +#define DCB_DHCSR_S_RETIRE_ST_Pos 24U /*!< DCB DHCSR: Retire sticky status Position */ +#define DCB_DHCSR_S_RETIRE_ST_Msk (0x1UL << DCB_DHCSR_S_RETIRE_ST_Pos) /*!< DCB DHCSR: Retire sticky status Mask */ + +#define DCB_DHCSR_S_SDE_Pos 20U /*!< DCB DHCSR: Secure debug enabled Position */ +#define DCB_DHCSR_S_SDE_Msk (0x1UL << DCB_DHCSR_S_SDE_Pos) /*!< DCB DHCSR: Secure debug enabled Mask */ + +#define DCB_DHCSR_S_LOCKUP_Pos 19U /*!< DCB DHCSR: Lockup status Position */ +#define DCB_DHCSR_S_LOCKUP_Msk (0x1UL << DCB_DHCSR_S_LOCKUP_Pos) /*!< DCB DHCSR: Lockup status Mask */ + +#define DCB_DHCSR_S_SLEEP_Pos 18U /*!< DCB DHCSR: Sleeping status Position */ +#define DCB_DHCSR_S_SLEEP_Msk (0x1UL << DCB_DHCSR_S_SLEEP_Pos) /*!< DCB DHCSR: Sleeping status Mask */ + +#define DCB_DHCSR_S_HALT_Pos 17U /*!< DCB DHCSR: Halted status Position */ +#define DCB_DHCSR_S_HALT_Msk (0x1UL << DCB_DHCSR_S_HALT_Pos) /*!< DCB DHCSR: Halted status Mask */ + +#define DCB_DHCSR_S_REGRDY_Pos 16U /*!< DCB DHCSR: Register ready status Position */ +#define DCB_DHCSR_S_REGRDY_Msk (0x1UL << DCB_DHCSR_S_REGRDY_Pos) /*!< DCB DHCSR: Register ready status Mask */ + +#define DCB_DHCSR_C_SNAPSTALL_Pos 5U /*!< DCB DHCSR: Snap stall control Position */ +#define DCB_DHCSR_C_SNAPSTALL_Msk (0x1UL << DCB_DHCSR_C_SNAPSTALL_Pos) /*!< DCB DHCSR: Snap stall control Mask */ + +#define DCB_DHCSR_C_MASKINTS_Pos 3U /*!< DCB DHCSR: Mask interrupts control Position */ +#define DCB_DHCSR_C_MASKINTS_Msk (0x1UL << DCB_DHCSR_C_MASKINTS_Pos) /*!< DCB DHCSR: Mask interrupts control Mask */ + +#define DCB_DHCSR_C_STEP_Pos 2U /*!< DCB DHCSR: Step control Position */ +#define DCB_DHCSR_C_STEP_Msk (0x1UL << DCB_DHCSR_C_STEP_Pos) /*!< DCB DHCSR: Step control Mask */ + +#define DCB_DHCSR_C_HALT_Pos 1U /*!< DCB DHCSR: Halt control Position */ +#define DCB_DHCSR_C_HALT_Msk (0x1UL << DCB_DHCSR_C_HALT_Pos) /*!< DCB DHCSR: Halt control Mask */ + +#define DCB_DHCSR_C_DEBUGEN_Pos 0U /*!< DCB DHCSR: Debug enable control Position */ +#define DCB_DHCSR_C_DEBUGEN_Msk (0x1UL /*<< DCB_DHCSR_C_DEBUGEN_Pos*/) /*!< DCB DHCSR: Debug enable control Mask */ + +/* DCRSR, Debug Core Register Select Register Definitions */ +#define DCB_DCRSR_REGWnR_Pos 16U /*!< DCB DCRSR: Register write/not-read Position */ +#define DCB_DCRSR_REGWnR_Msk (0x1UL << DCB_DCRSR_REGWnR_Pos) /*!< DCB DCRSR: Register write/not-read Mask */ + +#define DCB_DCRSR_REGSEL_Pos 0U /*!< DCB DCRSR: Register selector Position */ +#define DCB_DCRSR_REGSEL_Msk (0x7FUL /*<< DCB_DCRSR_REGSEL_Pos*/) /*!< DCB DCRSR: Register selector Mask */ + +/* DCRDR, Debug Core Register Data Register Definitions */ +#define DCB_DCRDR_DBGTMP_Pos 0U /*!< DCB DCRDR: Data temporary buffer Position */ +#define DCB_DCRDR_DBGTMP_Msk (0xFFFFFFFFUL /*<< DCB_DCRDR_DBGTMP_Pos*/) /*!< DCB DCRDR: Data temporary buffer Mask */ + +/* DEMCR, Debug Exception and Monitor Control Register Definitions */ +#define DCB_DEMCR_TRCENA_Pos 24U /*!< DCB DEMCR: Trace enable Position */ +#define DCB_DEMCR_TRCENA_Msk (0x1UL << DCB_DEMCR_TRCENA_Pos) /*!< DCB DEMCR: Trace enable Mask */ + +#define DCB_DEMCR_MONPRKEY_Pos 23U /*!< DCB DEMCR: Monitor pend req key Position */ +#define DCB_DEMCR_MONPRKEY_Msk (0x1UL << DCB_DEMCR_MONPRKEY_Pos) /*!< DCB DEMCR: Monitor pend req key Mask */ + +#define DCB_DEMCR_UMON_EN_Pos 21U /*!< DCB DEMCR: Unprivileged monitor enable Position */ +#define DCB_DEMCR_UMON_EN_Msk (0x1UL << DCB_DEMCR_UMON_EN_Pos) /*!< DCB DEMCR: Unprivileged monitor enable Mask */ + +#define DCB_DEMCR_SDME_Pos 20U /*!< DCB DEMCR: Secure DebugMonitor enable Position */ +#define DCB_DEMCR_SDME_Msk (0x1UL << DCB_DEMCR_SDME_Pos) /*!< DCB DEMCR: Secure DebugMonitor enable Mask */ + +#define DCB_DEMCR_MON_REQ_Pos 19U /*!< DCB DEMCR: Monitor request Position */ +#define DCB_DEMCR_MON_REQ_Msk (0x1UL << DCB_DEMCR_MON_REQ_Pos) /*!< DCB DEMCR: Monitor request Mask */ + +#define DCB_DEMCR_MON_STEP_Pos 18U /*!< DCB DEMCR: Monitor step Position */ +#define DCB_DEMCR_MON_STEP_Msk (0x1UL << DCB_DEMCR_MON_STEP_Pos) /*!< DCB DEMCR: Monitor step Mask */ + +#define DCB_DEMCR_MON_PEND_Pos 17U /*!< DCB DEMCR: Monitor pend Position */ +#define DCB_DEMCR_MON_PEND_Msk (0x1UL << DCB_DEMCR_MON_PEND_Pos) /*!< DCB DEMCR: Monitor pend Mask */ + +#define DCB_DEMCR_MON_EN_Pos 16U /*!< DCB DEMCR: Monitor enable Position */ +#define DCB_DEMCR_MON_EN_Msk (0x1UL << DCB_DEMCR_MON_EN_Pos) /*!< DCB DEMCR: Monitor enable Mask */ + +#define DCB_DEMCR_VC_SFERR_Pos 11U /*!< DCB DEMCR: Vector Catch SecureFault Position */ +#define DCB_DEMCR_VC_SFERR_Msk (0x1UL << DCB_DEMCR_VC_SFERR_Pos) /*!< DCB DEMCR: Vector Catch SecureFault Mask */ + +#define DCB_DEMCR_VC_HARDERR_Pos 10U /*!< DCB DEMCR: Vector Catch HardFault errors Position */ +#define DCB_DEMCR_VC_HARDERR_Msk (0x1UL << DCB_DEMCR_VC_HARDERR_Pos) /*!< DCB DEMCR: Vector Catch HardFault errors Mask */ + +#define DCB_DEMCR_VC_INTERR_Pos 9U /*!< DCB DEMCR: Vector Catch interrupt errors Position */ +#define DCB_DEMCR_VC_INTERR_Msk (0x1UL << DCB_DEMCR_VC_INTERR_Pos) /*!< DCB DEMCR: Vector Catch interrupt errors Mask */ + +#define DCB_DEMCR_VC_BUSERR_Pos 8U /*!< DCB DEMCR: Vector Catch BusFault errors Position */ +#define DCB_DEMCR_VC_BUSERR_Msk (0x1UL << DCB_DEMCR_VC_BUSERR_Pos) /*!< DCB DEMCR: Vector Catch BusFault errors Mask */ + +#define DCB_DEMCR_VC_STATERR_Pos 7U /*!< DCB DEMCR: Vector Catch state errors Position */ +#define DCB_DEMCR_VC_STATERR_Msk (0x1UL << DCB_DEMCR_VC_STATERR_Pos) /*!< DCB DEMCR: Vector Catch state errors Mask */ + +#define DCB_DEMCR_VC_CHKERR_Pos 6U /*!< DCB DEMCR: Vector Catch check errors Position */ +#define DCB_DEMCR_VC_CHKERR_Msk (0x1UL << DCB_DEMCR_VC_CHKERR_Pos) /*!< DCB DEMCR: Vector Catch check errors Mask */ + +#define DCB_DEMCR_VC_NOCPERR_Pos 5U /*!< DCB DEMCR: Vector Catch NOCP errors Position */ +#define DCB_DEMCR_VC_NOCPERR_Msk (0x1UL << DCB_DEMCR_VC_NOCPERR_Pos) /*!< DCB DEMCR: Vector Catch NOCP errors Mask */ + +#define DCB_DEMCR_VC_MMERR_Pos 4U /*!< DCB DEMCR: Vector Catch MemManage errors Position */ +#define DCB_DEMCR_VC_MMERR_Msk (0x1UL << DCB_DEMCR_VC_MMERR_Pos) /*!< DCB DEMCR: Vector Catch MemManage errors Mask */ + +#define DCB_DEMCR_VC_CORERESET_Pos 0U /*!< DCB DEMCR: Vector Catch Core reset Position */ +#define DCB_DEMCR_VC_CORERESET_Msk (0x1UL /*<< DCB_DEMCR_VC_CORERESET_Pos*/) /*!< DCB DEMCR: Vector Catch Core reset Mask */ + +/* DAUTHCTRL, Debug Authentication Control Register Definitions */ +#define DCB_DAUTHCTRL_INTSPNIDEN_Pos 3U /*!< DCB DAUTHCTRL: Internal Secure non-invasive debug enable Position */ +#define DCB_DAUTHCTRL_INTSPNIDEN_Msk (0x1UL << DCB_DAUTHCTRL_INTSPNIDEN_Pos) /*!< DCB DAUTHCTRL: Internal Secure non-invasive debug enable Mask */ + +#define DCB_DAUTHCTRL_SPNIDENSEL_Pos 2U /*!< DCB DAUTHCTRL: Secure non-invasive debug enable select Position */ +#define DCB_DAUTHCTRL_SPNIDENSEL_Msk (0x1UL << DCB_DAUTHCTRL_SPNIDENSEL_Pos) /*!< DCB DAUTHCTRL: Secure non-invasive debug enable select Mask */ + +#define DCB_DAUTHCTRL_INTSPIDEN_Pos 1U /*!< DCB DAUTHCTRL: Internal Secure invasive debug enable Position */ +#define DCB_DAUTHCTRL_INTSPIDEN_Msk (0x1UL << DCB_DAUTHCTRL_INTSPIDEN_Pos) /*!< DCB DAUTHCTRL: Internal Secure invasive debug enable Mask */ + +#define DCB_DAUTHCTRL_SPIDENSEL_Pos 0U /*!< DCB DAUTHCTRL: Secure invasive debug enable select Position */ +#define DCB_DAUTHCTRL_SPIDENSEL_Msk (0x1UL /*<< DCB_DAUTHCTRL_SPIDENSEL_Pos*/) /*!< DCB DAUTHCTRL: Secure invasive debug enable select Mask */ + +/* DSCSR, Debug Security Control and Status Register Definitions */ +#define DCB_DSCSR_CDSKEY_Pos 17U /*!< DCB DSCSR: CDS write-enable key Position */ +#define DCB_DSCSR_CDSKEY_Msk (0x1UL << DCB_DSCSR_CDSKEY_Pos) /*!< DCB DSCSR: CDS write-enable key Mask */ + +#define DCB_DSCSR_CDS_Pos 16U /*!< DCB DSCSR: Current domain Secure Position */ +#define DCB_DSCSR_CDS_Msk (0x1UL << DCB_DSCSR_CDS_Pos) /*!< DCB DSCSR: Current domain Secure Mask */ + +#define DCB_DSCSR_SBRSEL_Pos 1U /*!< DCB DSCSR: Secure banked register select Position */ +#define DCB_DSCSR_SBRSEL_Msk (0x1UL << DCB_DSCSR_SBRSEL_Pos) /*!< DCB DSCSR: Secure banked register select Mask */ + +#define DCB_DSCSR_SBRSELEN_Pos 0U /*!< DCB DSCSR: Secure banked register select enable Position */ +#define DCB_DSCSR_SBRSELEN_Msk (0x1UL /*<< DCB_DSCSR_SBRSELEN_Pos*/) /*!< DCB DSCSR: Secure banked register select enable Mask */ + +/*@} end of group CMSIS_DCB */ + + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_DIB Debug Identification Block + \brief Type definitions for the Debug Identification Block Registers + @{ + */ + +/** + \brief Structure type to access the Debug Identification Block Registers (DIB). + */ +typedef struct +{ + __OM uint32_t DLAR; /*!< Offset: 0x000 ( /W) SCS Software Lock Access Register */ + __IM uint32_t DLSR; /*!< Offset: 0x004 (R/ ) SCS Software Lock Status Register */ + __IM uint32_t DAUTHSTATUS; /*!< Offset: 0x008 (R/ ) Debug Authentication Status Register */ + __IM uint32_t DDEVARCH; /*!< Offset: 0x00C (R/ ) SCS Device Architecture Register */ + __IM uint32_t DDEVTYPE; /*!< Offset: 0x010 (R/ ) SCS Device Type Register */ +} DIB_Type; + +/* DLAR, SCS Software Lock Access Register Definitions */ +#define DIB_DLAR_KEY_Pos 0U /*!< DIB DLAR: KEY Position */ +#define DIB_DLAR_KEY_Msk (0xFFFFFFFFUL /*<< DIB_DLAR_KEY_Pos */) /*!< DIB DLAR: KEY Mask */ + +/* DLSR, SCS Software Lock Status Register Definitions */ +#define DIB_DLSR_nTT_Pos 2U /*!< DIB DLSR: Not thirty-two bit Position */ +#define DIB_DLSR_nTT_Msk (0x1UL << DIB_DLSR_nTT_Pos ) /*!< DIB DLSR: Not thirty-two bit Mask */ + +#define DIB_DLSR_SLK_Pos 1U /*!< DIB DLSR: Software Lock status Position */ +#define DIB_DLSR_SLK_Msk (0x1UL << DIB_DLSR_SLK_Pos ) /*!< DIB DLSR: Software Lock status Mask */ + +#define DIB_DLSR_SLI_Pos 0U /*!< DIB DLSR: Software Lock implemented Position */ +#define DIB_DLSR_SLI_Msk (0x1UL /*<< DIB_DLSR_SLI_Pos*/) /*!< DIB DLSR: Software Lock implemented Mask */ + +/* DAUTHSTATUS, Debug Authentication Status Register Definitions */ +#define DIB_DAUTHSTATUS_SNID_Pos 6U /*!< DIB DAUTHSTATUS: Secure Non-invasive Debug Position */ +#define DIB_DAUTHSTATUS_SNID_Msk (0x3UL << DIB_DAUTHSTATUS_SNID_Pos ) /*!< DIB DAUTHSTATUS: Secure Non-invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_SID_Pos 4U /*!< DIB DAUTHSTATUS: Secure Invasive Debug Position */ +#define DIB_DAUTHSTATUS_SID_Msk (0x3UL << DIB_DAUTHSTATUS_SID_Pos ) /*!< DIB DAUTHSTATUS: Secure Invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_NSNID_Pos 2U /*!< DIB DAUTHSTATUS: Non-secure Non-invasive Debug Position */ +#define DIB_DAUTHSTATUS_NSNID_Msk (0x3UL << DIB_DAUTHSTATUS_NSNID_Pos ) /*!< DIB DAUTHSTATUS: Non-secure Non-invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_NSID_Pos 0U /*!< DIB DAUTHSTATUS: Non-secure Invasive Debug Position */ +#define DIB_DAUTHSTATUS_NSID_Msk (0x3UL /*<< DIB_DAUTHSTATUS_NSID_Pos*/) /*!< DIB DAUTHSTATUS: Non-secure Invasive Debug Mask */ + +/* DDEVARCH, SCS Device Architecture Register Definitions */ +#define DIB_DDEVARCH_ARCHITECT_Pos 21U /*!< DIB DDEVARCH: Architect Position */ +#define DIB_DDEVARCH_ARCHITECT_Msk (0x7FFUL << DIB_DDEVARCH_ARCHITECT_Pos ) /*!< DIB DDEVARCH: Architect Mask */ + +#define DIB_DDEVARCH_PRESENT_Pos 20U /*!< DIB DDEVARCH: DEVARCH Present Position */ +#define DIB_DDEVARCH_PRESENT_Msk (0x1FUL << DIB_DDEVARCH_PRESENT_Pos ) /*!< DIB DDEVARCH: DEVARCH Present Mask */ + +#define DIB_DDEVARCH_REVISION_Pos 16U /*!< DIB DDEVARCH: Revision Position */ +#define DIB_DDEVARCH_REVISION_Msk (0xFUL << DIB_DDEVARCH_REVISION_Pos ) /*!< DIB DDEVARCH: Revision Mask */ + +#define DIB_DDEVARCH_ARCHVER_Pos 12U /*!< DIB DDEVARCH: Architecture Version Position */ +#define DIB_DDEVARCH_ARCHVER_Msk (0xFUL << DIB_DDEVARCH_ARCHVER_Pos ) /*!< DIB DDEVARCH: Architecture Version Mask */ + +#define DIB_DDEVARCH_ARCHPART_Pos 0U /*!< DIB DDEVARCH: Architecture Part Position */ +#define DIB_DDEVARCH_ARCHPART_Msk (0xFFFUL /*<< DIB_DDEVARCH_ARCHPART_Pos*/) /*!< DIB DDEVARCH: Architecture Part Mask */ + +/* DDEVTYPE, SCS Device Type Register Definitions */ +#define DIB_DDEVTYPE_SUB_Pos 4U /*!< DIB DDEVTYPE: Sub-type Position */ +#define DIB_DDEVTYPE_SUB_Msk (0xFUL << DIB_DDEVTYPE_SUB_Pos ) /*!< DIB DDEVTYPE: Sub-type Mask */ + +#define DIB_DDEVTYPE_MAJOR_Pos 0U /*!< DIB DDEVTYPE: Major type Position */ +#define DIB_DDEVTYPE_MAJOR_Msk (0xFUL /*<< DIB_DDEVTYPE_MAJOR_Pos*/) /*!< DIB DDEVTYPE: Major type Mask */ + + +/*@} end of group CMSIS_DIB */ + + /** \ingroup CMSIS_core_register \defgroup CMSIS_core_bitfield Core register bit field macros @@ -1954,7 +2200,9 @@ typedef struct #define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */ #define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */ #define TPI_BASE (0xE0040000UL) /*!< TPI Base Address */ - #define CoreDebug_BASE (0xE000EDF0UL) /*!< Core Debug Base Address */ + #define CoreDebug_BASE (0xE000EDF0UL) /*!< \deprecated Core Debug Base Address */ + #define DCB_BASE (0xE000EDF0UL) /*!< DCB Base Address */ + #define DIB_BASE (0xE000EFB0UL) /*!< DIB Base Address */ #define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */ #define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */ #define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */ @@ -1966,7 +2214,9 @@ typedef struct #define ITM ((ITM_Type *) ITM_BASE ) /*!< ITM configuration struct */ #define DWT ((DWT_Type *) DWT_BASE ) /*!< DWT configuration struct */ #define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct */ - #define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE ) /*!< Core Debug configuration struct */ + #define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE ) /*!< \deprecated Core Debug configuration struct */ + #define DCB ((DCB_Type *) DCB_BASE ) /*!< DCB configuration struct */ + #define DIB ((DIB_Type *) DIB_BASE ) /*!< DIB configuration struct */ #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */ @@ -1983,7 +2233,9 @@ typedef struct #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) #define SCS_BASE_NS (0xE002E000UL) /*!< System Control Space Base Address (non-secure address space) */ - #define CoreDebug_BASE_NS (0xE002EDF0UL) /*!< Core Debug Base Address (non-secure address space) */ + #define CoreDebug_BASE_NS (0xE002EDF0UL) /*!< \deprecated Core Debug Base Address (non-secure address space) */ + #define DCB_BASE_NS (0xE002EDF0UL) /*!< DCB Base Address (non-secure address space) */ + #define DIB_BASE_NS (0xE002EFB0UL) /*!< DIB Base Address (non-secure address space) */ #define SysTick_BASE_NS (SCS_BASE_NS + 0x0010UL) /*!< SysTick Base Address (non-secure address space) */ #define NVIC_BASE_NS (SCS_BASE_NS + 0x0100UL) /*!< NVIC Base Address (non-secure address space) */ #define SCB_BASE_NS (SCS_BASE_NS + 0x0D00UL) /*!< System Control Block Base Address (non-secure address space) */ @@ -1992,7 +2244,9 @@ typedef struct #define SCB_NS ((SCB_Type *) SCB_BASE_NS ) /*!< SCB configuration struct (non-secure address space) */ #define SysTick_NS ((SysTick_Type *) SysTick_BASE_NS ) /*!< SysTick configuration struct (non-secure address space) */ #define NVIC_NS ((NVIC_Type *) NVIC_BASE_NS ) /*!< NVIC configuration struct (non-secure address space) */ - #define CoreDebug_NS ((CoreDebug_Type *) CoreDebug_BASE_NS) /*!< Core Debug configuration struct (non-secure address space) */ + #define CoreDebug_NS ((CoreDebug_Type *) CoreDebug_BASE_NS) /*!< \deprecated Core Debug configuration struct (non-secure address space) */ + #define DCB_NS ((DCB_Type *) DCB_BASE_NS ) /*!< DCB configuration struct (non-secure address space) */ + #define DIB_NS ((DIB_Type *) DIB_BASE_NS ) /*!< DIB configuration struct (non-secure address space) */ #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) #define MPU_BASE_NS (SCS_BASE_NS + 0x0D90UL) /*!< Memory Protection Unit (non-secure address space) */ @@ -2006,6 +2260,15 @@ typedef struct /*@} */ +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_register_aliases Backwards Compatibility Aliases + \brief Register alias definitions for backwards compatibility. + @{ + */ +#define ID_ADR (ID_AFR) /*!< SCB Auxiliary Feature Register */ +/*@} */ + /******************************************************************************* * Hardware Abstraction Layer @@ -2064,7 +2327,7 @@ typedef struct /* Special LR values for Secure/Non-Secure call handling and exception handling */ -/* Function Return Payload (from ARMv8-M Architecture Reference Manual) LR value on entry from Secure BLXNS */ +/* Function Return Payload (from ARMv8-M Architecture Reference Manual) LR value on entry from Secure BLXNS */ #define FNC_RETURN (0xFEFFFFFFUL) /* bit [0] ignored when processing a branch */ /* The following EXC_RETURN mask values are used to evaluate the LR on exception entry */ @@ -2079,7 +2342,7 @@ typedef struct /* Integrity Signature (from ARMv8-M Architecture Reference Manual) for exception context stacking */ #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) /* Value for processors with floating-point extension: */ #define EXC_INTEGRITY_SIGNATURE (0xFEFA125AUL) /* bit [0] SFTC must match LR bit[4] EXC_RETURN_FTYPE */ -#else +#else #define EXC_INTEGRITY_SIGNATURE (0xFEFA125BUL) /* Value for processors without floating-point extension */ #endif @@ -2128,7 +2391,9 @@ __STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) { if ((int32_t)(IRQn) >= 0) { + __COMPILER_BARRIER(); NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __COMPILER_BARRIER(); } } @@ -2420,6 +2685,7 @@ __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) { uint32_t *vectors = (uint32_t *)SCB->VTOR; vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector; + __DSB(); } @@ -2746,6 +3012,110 @@ __STATIC_INLINE void TZ_SAU_Disable(void) +/* ################################## Debug Control function ############################################ */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_DCBFunctions Debug Control Functions + \brief Functions that access the Debug Control Block. + @{ + */ + + +/** + \brief Set Debug Authentication Control Register + \details writes to Debug Authentication Control register. + \param [in] value value to be writen. + */ +__STATIC_INLINE void DCB_SetAuthCtrl(uint32_t value) +{ + __DSB(); + __ISB(); + DCB->DAUTHCTRL = value; + __DSB(); + __ISB(); +} + + +/** + \brief Get Debug Authentication Control Register + \details Reads Debug Authentication Control register. + \return Debug Authentication Control Register. + */ +__STATIC_INLINE uint32_t DCB_GetAuthCtrl(void) +{ + return (DCB->DAUTHCTRL); +} + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief Set Debug Authentication Control Register (non-secure) + \details writes to non-secure Debug Authentication Control register when in secure state. + \param [in] value value to be writen + */ +__STATIC_INLINE void TZ_DCB_SetAuthCtrl_NS(uint32_t value) +{ + __DSB(); + __ISB(); + DCB_NS->DAUTHCTRL = value; + __DSB(); + __ISB(); +} + + +/** + \brief Get Debug Authentication Control Register (non-secure) + \details Reads non-secure Debug Authentication Control register when in secure state. + \return Debug Authentication Control Register. + */ +__STATIC_INLINE uint32_t TZ_DCB_GetAuthCtrl_NS(void) +{ + return (DCB_NS->DAUTHCTRL); +} +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + +/*@} end of CMSIS_Core_DCBFunctions */ + + + + +/* ################################## Debug Identification function ############################################ */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_DIBFunctions Debug Identification Functions + \brief Functions that access the Debug Identification Block. + @{ + */ + + +/** + \brief Get Debug Authentication Status Register + \details Reads Debug Authentication Status register. + \return Debug Authentication Status Register. + */ +__STATIC_INLINE uint32_t DIB_GetAuthStatus(void) +{ + return (DIB->DAUTHSTATUS); +} + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief Get Debug Authentication Status Register (non-secure) + \details Reads non-secure Debug Authentication Status register when in secure state. + \return Debug Authentication Status Register. + */ +__STATIC_INLINE uint32_t TZ_DIB_GetAuthStatus_NS(void) +{ + return (DIB_NS->DAUTHSTATUS); +} +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + +/*@} end of CMSIS_Core_DCBFunctions */ + + + + /* ################################## SysTick function ############################################ */ /** \ingroup CMSIS_Core_FunctionInterface diff --git a/lib/cmsis/inc/core_cm35p.h b/lib/cmsis/inc/core_cm35p.h index c00e54ca7a984..3843d9542c5ab 100644 --- a/lib/cmsis/inc/core_cm35p.h +++ b/lib/cmsis/inc/core_cm35p.h @@ -1,11 +1,11 @@ /**************************************************************************//** * @file core_cm35p.h * @brief CMSIS Cortex-M35P Core Peripheral Access Layer Header File - * @version V1.0.0 - * @date 12. November 2018 + * @version V1.1.3 + * @date 13. October 2021 ******************************************************************************/ /* - * Copyright (c) 2018 Arm Limited. All rights reserved. + * Copyright (c) 2018-2021 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -23,9 +23,11 @@ */ #if defined ( __ICCARM__ ) - #pragma system_include /* treat file as system include file for MISRA check */ + #pragma system_include /* treat file as system include file for MISRA check */ #elif defined (__clang__) - #pragma clang system_header /* treat file as system include file */ + #pragma clang system_header /* treat file as system include file */ +#elif defined ( __GNUC__ ) + #pragma GCC diagnostic ignored "-Wpedantic" /* disable pedantic warning due to unnamed structs/unions */ #endif #ifndef __CORE_CM35P_H_GENERIC @@ -248,6 +250,11 @@ #warning "__DSP_PRESENT not defined in device header file; using default!" #endif + #ifndef __VTOR_PRESENT + #define __VTOR_PRESENT 1U + #warning "__VTOR_PRESENT not defined in device header file; using default!" + #endif + #ifndef __NVIC_PRIO_BITS #define __NVIC_PRIO_BITS 3U #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" @@ -512,7 +519,7 @@ typedef struct __IOM uint32_t AFSR; /*!< Offset: 0x03C (R/W) Auxiliary Fault Status Register */ __IM uint32_t ID_PFR[2U]; /*!< Offset: 0x040 (R/ ) Processor Feature Register */ __IM uint32_t ID_DFR; /*!< Offset: 0x048 (R/ ) Debug Feature Register */ - __IM uint32_t ID_ADR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */ + __IM uint32_t ID_AFR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */ __IM uint32_t ID_MMFR[4U]; /*!< Offset: 0x050 (R/ ) Memory Model Feature Register */ __IM uint32_t ID_ISAR[6U]; /*!< Offset: 0x060 (R/ ) Instruction Set Attributes Register */ __IM uint32_t CLIDR; /*!< Offset: 0x078 (R/ ) Cache Level ID register */ @@ -521,7 +528,10 @@ typedef struct __IOM uint32_t CSSELR; /*!< Offset: 0x084 (R/W) Cache Size Selection Register */ __IOM uint32_t CPACR; /*!< Offset: 0x088 (R/W) Coprocessor Access Control Register */ __IOM uint32_t NSACR; /*!< Offset: 0x08C (R/W) Non-Secure Access Control Register */ - uint32_t RESERVED3[92U]; + uint32_t RESERVED7[21U]; + __IOM uint32_t SFSR; /*!< Offset: 0x0E4 (R/W) Secure Fault Status Register */ + __IOM uint32_t SFAR; /*!< Offset: 0x0E8 (R/W) Secure Fault Address Register */ + uint32_t RESERVED3[69U]; __OM uint32_t STIR; /*!< Offset: 0x200 ( /W) Software Triggered Interrupt Register */ uint32_t RESERVED4[15U]; __IM uint32_t MVFR0; /*!< Offset: 0x240 (R/ ) Media and VFP Feature Register 0 */ @@ -538,6 +548,7 @@ typedef struct __OM uint32_t DCCSW; /*!< Offset: 0x26C ( /W) D-Cache Clean by Set-way */ __OM uint32_t DCCIMVAC; /*!< Offset: 0x270 ( /W) D-Cache Clean and Invalidate by MVA to PoC */ __OM uint32_t DCCISW; /*!< Offset: 0x274 ( /W) D-Cache Clean and Invalidate by Set-way */ + __OM uint32_t BPIALL; /*!< Offset: 0x278 ( /W) Branch Predictor Invalidate All */ } SCB_Type; /* SCB CPUID Register Definitions */ @@ -738,22 +749,22 @@ typedef struct #define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */ /* MemManage Fault Status Register (part of SCB Configurable Fault Status Register) */ -#define SCB_CFSR_MMARVALID_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */ +#define SCB_CFSR_MMARVALID_Pos (SCB_CFSR_MEMFAULTSR_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */ #define SCB_CFSR_MMARVALID_Msk (1UL << SCB_CFSR_MMARVALID_Pos) /*!< SCB CFSR (MMFSR): MMARVALID Mask */ -#define SCB_CFSR_MLSPERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 5U) /*!< SCB CFSR (MMFSR): MLSPERR Position */ +#define SCB_CFSR_MLSPERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 5U) /*!< SCB CFSR (MMFSR): MLSPERR Position */ #define SCB_CFSR_MLSPERR_Msk (1UL << SCB_CFSR_MLSPERR_Pos) /*!< SCB CFSR (MMFSR): MLSPERR Mask */ -#define SCB_CFSR_MSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */ +#define SCB_CFSR_MSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */ #define SCB_CFSR_MSTKERR_Msk (1UL << SCB_CFSR_MSTKERR_Pos) /*!< SCB CFSR (MMFSR): MSTKERR Mask */ -#define SCB_CFSR_MUNSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */ +#define SCB_CFSR_MUNSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */ #define SCB_CFSR_MUNSTKERR_Msk (1UL << SCB_CFSR_MUNSTKERR_Pos) /*!< SCB CFSR (MMFSR): MUNSTKERR Mask */ -#define SCB_CFSR_DACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */ +#define SCB_CFSR_DACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */ #define SCB_CFSR_DACCVIOL_Msk (1UL << SCB_CFSR_DACCVIOL_Pos) /*!< SCB CFSR (MMFSR): DACCVIOL Mask */ -#define SCB_CFSR_IACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */ +#define SCB_CFSR_IACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */ #define SCB_CFSR_IACCVIOL_Msk (1UL /*<< SCB_CFSR_IACCVIOL_Pos*/) /*!< SCB CFSR (MMFSR): IACCVIOL Mask */ /* BusFault Status Register (part of SCB Configurable Fault Status Register) */ @@ -1668,8 +1679,9 @@ typedef struct __IOM uint32_t FPCCR; /*!< Offset: 0x004 (R/W) Floating-Point Context Control Register */ __IOM uint32_t FPCAR; /*!< Offset: 0x008 (R/W) Floating-Point Context Address Register */ __IOM uint32_t FPDSCR; /*!< Offset: 0x00C (R/W) Floating-Point Default Status Control Register */ - __IM uint32_t MVFR0; /*!< Offset: 0x010 (R/ ) Media and FP Feature Register 0 */ - __IM uint32_t MVFR1; /*!< Offset: 0x014 (R/ ) Media and FP Feature Register 1 */ + __IM uint32_t MVFR0; /*!< Offset: 0x010 (R/ ) Media and VFP Feature Register 0 */ + __IM uint32_t MVFR1; /*!< Offset: 0x014 (R/ ) Media and VFP Feature Register 1 */ + __IM uint32_t MVFR2; /*!< Offset: 0x018 (R/ ) Media and VFP Feature Register 2 */ } FPU_Type; /* Floating-Point Context Control Register Definitions */ @@ -1741,7 +1753,7 @@ typedef struct #define FPU_FPDSCR_RMode_Pos 22U /*!< FPDSCR: RMode bit Position */ #define FPU_FPDSCR_RMode_Msk (3UL << FPU_FPDSCR_RMode_Pos) /*!< FPDSCR: RMode bit Mask */ -/* Media and FP Feature Register 0 Definitions */ +/* Media and VFP Feature Register 0 Definitions */ #define FPU_MVFR0_FP_rounding_modes_Pos 28U /*!< MVFR0: FP rounding modes bits Position */ #define FPU_MVFR0_FP_rounding_modes_Msk (0xFUL << FPU_MVFR0_FP_rounding_modes_Pos) /*!< MVFR0: FP rounding modes bits Mask */ @@ -1766,7 +1778,7 @@ typedef struct #define FPU_MVFR0_A_SIMD_registers_Pos 0U /*!< MVFR0: A_SIMD registers bits Position */ #define FPU_MVFR0_A_SIMD_registers_Msk (0xFUL /*<< FPU_MVFR0_A_SIMD_registers_Pos*/) /*!< MVFR0: A_SIMD registers bits Mask */ -/* Media and FP Feature Register 1 Definitions */ +/* Media and VFP Feature Register 1 Definitions */ #define FPU_MVFR1_FP_fused_MAC_Pos 28U /*!< MVFR1: FP fused MAC bits Position */ #define FPU_MVFR1_FP_fused_MAC_Msk (0xFUL << FPU_MVFR1_FP_fused_MAC_Pos) /*!< MVFR1: FP fused MAC bits Mask */ @@ -1779,9 +1791,13 @@ typedef struct #define FPU_MVFR1_FtZ_mode_Pos 0U /*!< MVFR1: FtZ mode bits Position */ #define FPU_MVFR1_FtZ_mode_Msk (0xFUL /*<< FPU_MVFR1_FtZ_mode_Pos*/) /*!< MVFR1: FtZ mode bits Mask */ -/*@} end of group CMSIS_FPU */ +/* Media and VFP Feature Register 2 Definitions */ +#define FPU_MVFR2_FPMisc_Pos 4U /*!< MVFR2: FPMisc bits Position */ +#define FPU_MVFR2_FPMisc_Msk (0xFUL << FPU_MVFR2_FPMisc_Pos) /*!< MVFR2: FPMisc bits Mask */ +/*@} end of group CMSIS_FPU */ +/* CoreDebug is deprecated. replaced by DCB (Debug Control Block) */ /** \ingroup CMSIS_core_register \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug) @@ -1790,7 +1806,7 @@ typedef struct */ /** - \brief Structure type to access the Core Debug Register (CoreDebug). + \brief \deprecated Structure type to access the Core Debug Register (CoreDebug). */ typedef struct { @@ -1798,124 +1814,354 @@ typedef struct __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ - uint32_t RESERVED4[1U]; + uint32_t RESERVED0[1U]; __IOM uint32_t DAUTHCTRL; /*!< Offset: 0x014 (R/W) Debug Authentication Control Register */ __IOM uint32_t DSCSR; /*!< Offset: 0x018 (R/W) Debug Security Control and Status Register */ } CoreDebug_Type; /* Debug Halting Control and Status Register Definitions */ -#define CoreDebug_DHCSR_DBGKEY_Pos 16U /*!< CoreDebug DHCSR: DBGKEY Position */ -#define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos) /*!< CoreDebug DHCSR: DBGKEY Mask */ +#define CoreDebug_DHCSR_DBGKEY_Pos 16U /*!< \deprecated CoreDebug DHCSR: DBGKEY Position */ +#define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos) /*!< \deprecated CoreDebug DHCSR: DBGKEY Mask */ -#define CoreDebug_DHCSR_S_RESTART_ST_Pos 26U /*!< CoreDebug DHCSR: S_RESTART_ST Position */ -#define CoreDebug_DHCSR_S_RESTART_ST_Msk (1UL << CoreDebug_DHCSR_S_RESTART_ST_Pos) /*!< CoreDebug DHCSR: S_RESTART_ST Mask */ +#define CoreDebug_DHCSR_S_RESTART_ST_Pos 26U /*!< \deprecated CoreDebug DHCSR: S_RESTART_ST Position */ +#define CoreDebug_DHCSR_S_RESTART_ST_Msk (1UL << CoreDebug_DHCSR_S_RESTART_ST_Pos) /*!< \deprecated CoreDebug DHCSR: S_RESTART_ST Mask */ -#define CoreDebug_DHCSR_S_RESET_ST_Pos 25U /*!< CoreDebug DHCSR: S_RESET_ST Position */ -#define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< CoreDebug DHCSR: S_RESET_ST Mask */ +#define CoreDebug_DHCSR_S_RESET_ST_Pos 25U /*!< \deprecated CoreDebug DHCSR: S_RESET_ST Position */ +#define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< \deprecated CoreDebug DHCSR: S_RESET_ST Mask */ -#define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24U /*!< CoreDebug DHCSR: S_RETIRE_ST Position */ -#define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< CoreDebug DHCSR: S_RETIRE_ST Mask */ +#define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24U /*!< \deprecated CoreDebug DHCSR: S_RETIRE_ST Position */ +#define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< \deprecated CoreDebug DHCSR: S_RETIRE_ST Mask */ -#define CoreDebug_DHCSR_S_LOCKUP_Pos 19U /*!< CoreDebug DHCSR: S_LOCKUP Position */ -#define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< CoreDebug DHCSR: S_LOCKUP Mask */ +#define CoreDebug_DHCSR_S_LOCKUP_Pos 19U /*!< \deprecated CoreDebug DHCSR: S_LOCKUP Position */ +#define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< \deprecated CoreDebug DHCSR: S_LOCKUP Mask */ -#define CoreDebug_DHCSR_S_SLEEP_Pos 18U /*!< CoreDebug DHCSR: S_SLEEP Position */ -#define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< CoreDebug DHCSR: S_SLEEP Mask */ +#define CoreDebug_DHCSR_S_SLEEP_Pos 18U /*!< \deprecated CoreDebug DHCSR: S_SLEEP Position */ +#define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< \deprecated CoreDebug DHCSR: S_SLEEP Mask */ -#define CoreDebug_DHCSR_S_HALT_Pos 17U /*!< CoreDebug DHCSR: S_HALT Position */ -#define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos) /*!< CoreDebug DHCSR: S_HALT Mask */ +#define CoreDebug_DHCSR_S_HALT_Pos 17U /*!< \deprecated CoreDebug DHCSR: S_HALT Position */ +#define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos) /*!< \deprecated CoreDebug DHCSR: S_HALT Mask */ -#define CoreDebug_DHCSR_S_REGRDY_Pos 16U /*!< CoreDebug DHCSR: S_REGRDY Position */ -#define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< CoreDebug DHCSR: S_REGRDY Mask */ +#define CoreDebug_DHCSR_S_REGRDY_Pos 16U /*!< \deprecated CoreDebug DHCSR: S_REGRDY Position */ +#define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< \deprecated CoreDebug DHCSR: S_REGRDY Mask */ -#define CoreDebug_DHCSR_C_SNAPSTALL_Pos 5U /*!< CoreDebug DHCSR: C_SNAPSTALL Position */ -#define CoreDebug_DHCSR_C_SNAPSTALL_Msk (1UL << CoreDebug_DHCSR_C_SNAPSTALL_Pos) /*!< CoreDebug DHCSR: C_SNAPSTALL Mask */ +#define CoreDebug_DHCSR_C_SNAPSTALL_Pos 5U /*!< \deprecated CoreDebug DHCSR: C_SNAPSTALL Position */ +#define CoreDebug_DHCSR_C_SNAPSTALL_Msk (1UL << CoreDebug_DHCSR_C_SNAPSTALL_Pos) /*!< \deprecated CoreDebug DHCSR: C_SNAPSTALL Mask */ -#define CoreDebug_DHCSR_C_MASKINTS_Pos 3U /*!< CoreDebug DHCSR: C_MASKINTS Position */ -#define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< CoreDebug DHCSR: C_MASKINTS Mask */ +#define CoreDebug_DHCSR_C_MASKINTS_Pos 3U /*!< \deprecated CoreDebug DHCSR: C_MASKINTS Position */ +#define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< \deprecated CoreDebug DHCSR: C_MASKINTS Mask */ -#define CoreDebug_DHCSR_C_STEP_Pos 2U /*!< CoreDebug DHCSR: C_STEP Position */ -#define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos) /*!< CoreDebug DHCSR: C_STEP Mask */ +#define CoreDebug_DHCSR_C_STEP_Pos 2U /*!< \deprecated CoreDebug DHCSR: C_STEP Position */ +#define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos) /*!< \deprecated CoreDebug DHCSR: C_STEP Mask */ -#define CoreDebug_DHCSR_C_HALT_Pos 1U /*!< CoreDebug DHCSR: C_HALT Position */ -#define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos) /*!< CoreDebug DHCSR: C_HALT Mask */ +#define CoreDebug_DHCSR_C_HALT_Pos 1U /*!< \deprecated CoreDebug DHCSR: C_HALT Position */ +#define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos) /*!< \deprecated CoreDebug DHCSR: C_HALT Mask */ -#define CoreDebug_DHCSR_C_DEBUGEN_Pos 0U /*!< CoreDebug DHCSR: C_DEBUGEN Position */ -#define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL /*<< CoreDebug_DHCSR_C_DEBUGEN_Pos*/) /*!< CoreDebug DHCSR: C_DEBUGEN Mask */ +#define CoreDebug_DHCSR_C_DEBUGEN_Pos 0U /*!< \deprecated CoreDebug DHCSR: C_DEBUGEN Position */ +#define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL /*<< CoreDebug_DHCSR_C_DEBUGEN_Pos*/) /*!< \deprecated CoreDebug DHCSR: C_DEBUGEN Mask */ /* Debug Core Register Selector Register Definitions */ -#define CoreDebug_DCRSR_REGWnR_Pos 16U /*!< CoreDebug DCRSR: REGWnR Position */ -#define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos) /*!< CoreDebug DCRSR: REGWnR Mask */ +#define CoreDebug_DCRSR_REGWnR_Pos 16U /*!< \deprecated CoreDebug DCRSR: REGWnR Position */ +#define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos) /*!< \deprecated CoreDebug DCRSR: REGWnR Mask */ -#define CoreDebug_DCRSR_REGSEL_Pos 0U /*!< CoreDebug DCRSR: REGSEL Position */ -#define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL /*<< CoreDebug_DCRSR_REGSEL_Pos*/) /*!< CoreDebug DCRSR: REGSEL Mask */ +#define CoreDebug_DCRSR_REGSEL_Pos 0U /*!< \deprecated CoreDebug DCRSR: REGSEL Position */ +#define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL /*<< CoreDebug_DCRSR_REGSEL_Pos*/) /*!< \deprecated CoreDebug DCRSR: REGSEL Mask */ /* Debug Exception and Monitor Control Register Definitions */ -#define CoreDebug_DEMCR_TRCENA_Pos 24U /*!< CoreDebug DEMCR: TRCENA Position */ -#define CoreDebug_DEMCR_TRCENA_Msk (1UL << CoreDebug_DEMCR_TRCENA_Pos) /*!< CoreDebug DEMCR: TRCENA Mask */ +#define CoreDebug_DEMCR_TRCENA_Pos 24U /*!< \deprecated CoreDebug DEMCR: TRCENA Position */ +#define CoreDebug_DEMCR_TRCENA_Msk (1UL << CoreDebug_DEMCR_TRCENA_Pos) /*!< \deprecated CoreDebug DEMCR: TRCENA Mask */ -#define CoreDebug_DEMCR_MON_REQ_Pos 19U /*!< CoreDebug DEMCR: MON_REQ Position */ -#define CoreDebug_DEMCR_MON_REQ_Msk (1UL << CoreDebug_DEMCR_MON_REQ_Pos) /*!< CoreDebug DEMCR: MON_REQ Mask */ +#define CoreDebug_DEMCR_MON_REQ_Pos 19U /*!< \deprecated CoreDebug DEMCR: MON_REQ Position */ +#define CoreDebug_DEMCR_MON_REQ_Msk (1UL << CoreDebug_DEMCR_MON_REQ_Pos) /*!< \deprecated CoreDebug DEMCR: MON_REQ Mask */ -#define CoreDebug_DEMCR_MON_STEP_Pos 18U /*!< CoreDebug DEMCR: MON_STEP Position */ -#define CoreDebug_DEMCR_MON_STEP_Msk (1UL << CoreDebug_DEMCR_MON_STEP_Pos) /*!< CoreDebug DEMCR: MON_STEP Mask */ +#define CoreDebug_DEMCR_MON_STEP_Pos 18U /*!< \deprecated CoreDebug DEMCR: MON_STEP Position */ +#define CoreDebug_DEMCR_MON_STEP_Msk (1UL << CoreDebug_DEMCR_MON_STEP_Pos) /*!< \deprecated CoreDebug DEMCR: MON_STEP Mask */ -#define CoreDebug_DEMCR_MON_PEND_Pos 17U /*!< CoreDebug DEMCR: MON_PEND Position */ -#define CoreDebug_DEMCR_MON_PEND_Msk (1UL << CoreDebug_DEMCR_MON_PEND_Pos) /*!< CoreDebug DEMCR: MON_PEND Mask */ +#define CoreDebug_DEMCR_MON_PEND_Pos 17U /*!< \deprecated CoreDebug DEMCR: MON_PEND Position */ +#define CoreDebug_DEMCR_MON_PEND_Msk (1UL << CoreDebug_DEMCR_MON_PEND_Pos) /*!< \deprecated CoreDebug DEMCR: MON_PEND Mask */ -#define CoreDebug_DEMCR_MON_EN_Pos 16U /*!< CoreDebug DEMCR: MON_EN Position */ -#define CoreDebug_DEMCR_MON_EN_Msk (1UL << CoreDebug_DEMCR_MON_EN_Pos) /*!< CoreDebug DEMCR: MON_EN Mask */ +#define CoreDebug_DEMCR_MON_EN_Pos 16U /*!< \deprecated CoreDebug DEMCR: MON_EN Position */ +#define CoreDebug_DEMCR_MON_EN_Msk (1UL << CoreDebug_DEMCR_MON_EN_Pos) /*!< \deprecated CoreDebug DEMCR: MON_EN Mask */ -#define CoreDebug_DEMCR_VC_HARDERR_Pos 10U /*!< CoreDebug DEMCR: VC_HARDERR Position */ -#define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< CoreDebug DEMCR: VC_HARDERR Mask */ +#define CoreDebug_DEMCR_VC_HARDERR_Pos 10U /*!< \deprecated CoreDebug DEMCR: VC_HARDERR Position */ +#define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_HARDERR Mask */ -#define CoreDebug_DEMCR_VC_INTERR_Pos 9U /*!< CoreDebug DEMCR: VC_INTERR Position */ -#define CoreDebug_DEMCR_VC_INTERR_Msk (1UL << CoreDebug_DEMCR_VC_INTERR_Pos) /*!< CoreDebug DEMCR: VC_INTERR Mask */ +#define CoreDebug_DEMCR_VC_INTERR_Pos 9U /*!< \deprecated CoreDebug DEMCR: VC_INTERR Position */ +#define CoreDebug_DEMCR_VC_INTERR_Msk (1UL << CoreDebug_DEMCR_VC_INTERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_INTERR Mask */ -#define CoreDebug_DEMCR_VC_BUSERR_Pos 8U /*!< CoreDebug DEMCR: VC_BUSERR Position */ -#define CoreDebug_DEMCR_VC_BUSERR_Msk (1UL << CoreDebug_DEMCR_VC_BUSERR_Pos) /*!< CoreDebug DEMCR: VC_BUSERR Mask */ +#define CoreDebug_DEMCR_VC_BUSERR_Pos 8U /*!< \deprecated CoreDebug DEMCR: VC_BUSERR Position */ +#define CoreDebug_DEMCR_VC_BUSERR_Msk (1UL << CoreDebug_DEMCR_VC_BUSERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_BUSERR Mask */ -#define CoreDebug_DEMCR_VC_STATERR_Pos 7U /*!< CoreDebug DEMCR: VC_STATERR Position */ -#define CoreDebug_DEMCR_VC_STATERR_Msk (1UL << CoreDebug_DEMCR_VC_STATERR_Pos) /*!< CoreDebug DEMCR: VC_STATERR Mask */ +#define CoreDebug_DEMCR_VC_STATERR_Pos 7U /*!< \deprecated CoreDebug DEMCR: VC_STATERR Position */ +#define CoreDebug_DEMCR_VC_STATERR_Msk (1UL << CoreDebug_DEMCR_VC_STATERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_STATERR Mask */ -#define CoreDebug_DEMCR_VC_CHKERR_Pos 6U /*!< CoreDebug DEMCR: VC_CHKERR Position */ -#define CoreDebug_DEMCR_VC_CHKERR_Msk (1UL << CoreDebug_DEMCR_VC_CHKERR_Pos) /*!< CoreDebug DEMCR: VC_CHKERR Mask */ +#define CoreDebug_DEMCR_VC_CHKERR_Pos 6U /*!< \deprecated CoreDebug DEMCR: VC_CHKERR Position */ +#define CoreDebug_DEMCR_VC_CHKERR_Msk (1UL << CoreDebug_DEMCR_VC_CHKERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_CHKERR Mask */ -#define CoreDebug_DEMCR_VC_NOCPERR_Pos 5U /*!< CoreDebug DEMCR: VC_NOCPERR Position */ -#define CoreDebug_DEMCR_VC_NOCPERR_Msk (1UL << CoreDebug_DEMCR_VC_NOCPERR_Pos) /*!< CoreDebug DEMCR: VC_NOCPERR Mask */ +#define CoreDebug_DEMCR_VC_NOCPERR_Pos 5U /*!< \deprecated CoreDebug DEMCR: VC_NOCPERR Position */ +#define CoreDebug_DEMCR_VC_NOCPERR_Msk (1UL << CoreDebug_DEMCR_VC_NOCPERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_NOCPERR Mask */ -#define CoreDebug_DEMCR_VC_MMERR_Pos 4U /*!< CoreDebug DEMCR: VC_MMERR Position */ -#define CoreDebug_DEMCR_VC_MMERR_Msk (1UL << CoreDebug_DEMCR_VC_MMERR_Pos) /*!< CoreDebug DEMCR: VC_MMERR Mask */ +#define CoreDebug_DEMCR_VC_MMERR_Pos 4U /*!< \deprecated CoreDebug DEMCR: VC_MMERR Position */ +#define CoreDebug_DEMCR_VC_MMERR_Msk (1UL << CoreDebug_DEMCR_VC_MMERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_MMERR Mask */ -#define CoreDebug_DEMCR_VC_CORERESET_Pos 0U /*!< CoreDebug DEMCR: VC_CORERESET Position */ -#define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL /*<< CoreDebug_DEMCR_VC_CORERESET_Pos*/) /*!< CoreDebug DEMCR: VC_CORERESET Mask */ +#define CoreDebug_DEMCR_VC_CORERESET_Pos 0U /*!< \deprecated CoreDebug DEMCR: VC_CORERESET Position */ +#define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL /*<< CoreDebug_DEMCR_VC_CORERESET_Pos*/) /*!< \deprecated CoreDebug DEMCR: VC_CORERESET Mask */ /* Debug Authentication Control Register Definitions */ -#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos 3U /*!< CoreDebug DAUTHCTRL: INTSPNIDEN, Position */ -#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos) /*!< CoreDebug DAUTHCTRL: INTSPNIDEN, Mask */ +#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos 3U /*!< \deprecated CoreDebug DAUTHCTRL: INTSPNIDEN, Position */ +#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: INTSPNIDEN, Mask */ -#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos 2U /*!< CoreDebug DAUTHCTRL: SPNIDENSEL Position */ -#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Msk (1UL << CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos) /*!< CoreDebug DAUTHCTRL: SPNIDENSEL Mask */ +#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos 2U /*!< \deprecated CoreDebug DAUTHCTRL: SPNIDENSEL Position */ +#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Msk (1UL << CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: SPNIDENSEL Mask */ -#define CoreDebug_DAUTHCTRL_INTSPIDEN_Pos 1U /*!< CoreDebug DAUTHCTRL: INTSPIDEN Position */ -#define CoreDebug_DAUTHCTRL_INTSPIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPIDEN_Pos) /*!< CoreDebug DAUTHCTRL: INTSPIDEN Mask */ +#define CoreDebug_DAUTHCTRL_INTSPIDEN_Pos 1U /*!< \deprecated CoreDebug DAUTHCTRL: INTSPIDEN Position */ +#define CoreDebug_DAUTHCTRL_INTSPIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPIDEN_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: INTSPIDEN Mask */ -#define CoreDebug_DAUTHCTRL_SPIDENSEL_Pos 0U /*!< CoreDebug DAUTHCTRL: SPIDENSEL Position */ -#define CoreDebug_DAUTHCTRL_SPIDENSEL_Msk (1UL /*<< CoreDebug_DAUTHCTRL_SPIDENSEL_Pos*/) /*!< CoreDebug DAUTHCTRL: SPIDENSEL Mask */ +#define CoreDebug_DAUTHCTRL_SPIDENSEL_Pos 0U /*!< \deprecated CoreDebug DAUTHCTRL: SPIDENSEL Position */ +#define CoreDebug_DAUTHCTRL_SPIDENSEL_Msk (1UL /*<< CoreDebug_DAUTHCTRL_SPIDENSEL_Pos*/) /*!< \deprecated CoreDebug DAUTHCTRL: SPIDENSEL Mask */ /* Debug Security Control and Status Register Definitions */ -#define CoreDebug_DSCSR_CDS_Pos 16U /*!< CoreDebug DSCSR: CDS Position */ -#define CoreDebug_DSCSR_CDS_Msk (1UL << CoreDebug_DSCSR_CDS_Pos) /*!< CoreDebug DSCSR: CDS Mask */ +#define CoreDebug_DSCSR_CDS_Pos 16U /*!< \deprecated CoreDebug DSCSR: CDS Position */ +#define CoreDebug_DSCSR_CDS_Msk (1UL << CoreDebug_DSCSR_CDS_Pos) /*!< \deprecated CoreDebug DSCSR: CDS Mask */ -#define CoreDebug_DSCSR_SBRSEL_Pos 1U /*!< CoreDebug DSCSR: SBRSEL Position */ -#define CoreDebug_DSCSR_SBRSEL_Msk (1UL << CoreDebug_DSCSR_SBRSEL_Pos) /*!< CoreDebug DSCSR: SBRSEL Mask */ +#define CoreDebug_DSCSR_SBRSEL_Pos 1U /*!< \deprecated CoreDebug DSCSR: SBRSEL Position */ +#define CoreDebug_DSCSR_SBRSEL_Msk (1UL << CoreDebug_DSCSR_SBRSEL_Pos) /*!< \deprecated CoreDebug DSCSR: SBRSEL Mask */ -#define CoreDebug_DSCSR_SBRSELEN_Pos 0U /*!< CoreDebug DSCSR: SBRSELEN Position */ -#define CoreDebug_DSCSR_SBRSELEN_Msk (1UL /*<< CoreDebug_DSCSR_SBRSELEN_Pos*/) /*!< CoreDebug DSCSR: SBRSELEN Mask */ +#define CoreDebug_DSCSR_SBRSELEN_Pos 0U /*!< \deprecated CoreDebug DSCSR: SBRSELEN Position */ +#define CoreDebug_DSCSR_SBRSELEN_Msk (1UL /*<< CoreDebug_DSCSR_SBRSELEN_Pos*/) /*!< \deprecated CoreDebug DSCSR: SBRSELEN Mask */ /*@} end of group CMSIS_CoreDebug */ +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_DCB Debug Control Block + \brief Type definitions for the Debug Control Block Registers + @{ + */ + +/** + \brief Structure type to access the Debug Control Block Registers (DCB). + */ +typedef struct +{ + __IOM uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */ + __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ + __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ + __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ + uint32_t RESERVED0[1U]; + __IOM uint32_t DAUTHCTRL; /*!< Offset: 0x014 (R/W) Debug Authentication Control Register */ + __IOM uint32_t DSCSR; /*!< Offset: 0x018 (R/W) Debug Security Control and Status Register */ +} DCB_Type; + +/* DHCSR, Debug Halting Control and Status Register Definitions */ +#define DCB_DHCSR_DBGKEY_Pos 16U /*!< DCB DHCSR: Debug key Position */ +#define DCB_DHCSR_DBGKEY_Msk (0xFFFFUL << DCB_DHCSR_DBGKEY_Pos) /*!< DCB DHCSR: Debug key Mask */ + +#define DCB_DHCSR_S_RESTART_ST_Pos 26U /*!< DCB DHCSR: Restart sticky status Position */ +#define DCB_DHCSR_S_RESTART_ST_Msk (0x1UL << DCB_DHCSR_S_RESTART_ST_Pos) /*!< DCB DHCSR: Restart sticky status Mask */ + +#define DCB_DHCSR_S_RESET_ST_Pos 25U /*!< DCB DHCSR: Reset sticky status Position */ +#define DCB_DHCSR_S_RESET_ST_Msk (0x1UL << DCB_DHCSR_S_RESET_ST_Pos) /*!< DCB DHCSR: Reset sticky status Mask */ + +#define DCB_DHCSR_S_RETIRE_ST_Pos 24U /*!< DCB DHCSR: Retire sticky status Position */ +#define DCB_DHCSR_S_RETIRE_ST_Msk (0x1UL << DCB_DHCSR_S_RETIRE_ST_Pos) /*!< DCB DHCSR: Retire sticky status Mask */ + +#define DCB_DHCSR_S_SDE_Pos 20U /*!< DCB DHCSR: Secure debug enabled Position */ +#define DCB_DHCSR_S_SDE_Msk (0x1UL << DCB_DHCSR_S_SDE_Pos) /*!< DCB DHCSR: Secure debug enabled Mask */ + +#define DCB_DHCSR_S_LOCKUP_Pos 19U /*!< DCB DHCSR: Lockup status Position */ +#define DCB_DHCSR_S_LOCKUP_Msk (0x1UL << DCB_DHCSR_S_LOCKUP_Pos) /*!< DCB DHCSR: Lockup status Mask */ + +#define DCB_DHCSR_S_SLEEP_Pos 18U /*!< DCB DHCSR: Sleeping status Position */ +#define DCB_DHCSR_S_SLEEP_Msk (0x1UL << DCB_DHCSR_S_SLEEP_Pos) /*!< DCB DHCSR: Sleeping status Mask */ + +#define DCB_DHCSR_S_HALT_Pos 17U /*!< DCB DHCSR: Halted status Position */ +#define DCB_DHCSR_S_HALT_Msk (0x1UL << DCB_DHCSR_S_HALT_Pos) /*!< DCB DHCSR: Halted status Mask */ + +#define DCB_DHCSR_S_REGRDY_Pos 16U /*!< DCB DHCSR: Register ready status Position */ +#define DCB_DHCSR_S_REGRDY_Msk (0x1UL << DCB_DHCSR_S_REGRDY_Pos) /*!< DCB DHCSR: Register ready status Mask */ + +#define DCB_DHCSR_C_SNAPSTALL_Pos 5U /*!< DCB DHCSR: Snap stall control Position */ +#define DCB_DHCSR_C_SNAPSTALL_Msk (0x1UL << DCB_DHCSR_C_SNAPSTALL_Pos) /*!< DCB DHCSR: Snap stall control Mask */ + +#define DCB_DHCSR_C_MASKINTS_Pos 3U /*!< DCB DHCSR: Mask interrupts control Position */ +#define DCB_DHCSR_C_MASKINTS_Msk (0x1UL << DCB_DHCSR_C_MASKINTS_Pos) /*!< DCB DHCSR: Mask interrupts control Mask */ + +#define DCB_DHCSR_C_STEP_Pos 2U /*!< DCB DHCSR: Step control Position */ +#define DCB_DHCSR_C_STEP_Msk (0x1UL << DCB_DHCSR_C_STEP_Pos) /*!< DCB DHCSR: Step control Mask */ + +#define DCB_DHCSR_C_HALT_Pos 1U /*!< DCB DHCSR: Halt control Position */ +#define DCB_DHCSR_C_HALT_Msk (0x1UL << DCB_DHCSR_C_HALT_Pos) /*!< DCB DHCSR: Halt control Mask */ + +#define DCB_DHCSR_C_DEBUGEN_Pos 0U /*!< DCB DHCSR: Debug enable control Position */ +#define DCB_DHCSR_C_DEBUGEN_Msk (0x1UL /*<< DCB_DHCSR_C_DEBUGEN_Pos*/) /*!< DCB DHCSR: Debug enable control Mask */ + +/* DCRSR, Debug Core Register Select Register Definitions */ +#define DCB_DCRSR_REGWnR_Pos 16U /*!< DCB DCRSR: Register write/not-read Position */ +#define DCB_DCRSR_REGWnR_Msk (0x1UL << DCB_DCRSR_REGWnR_Pos) /*!< DCB DCRSR: Register write/not-read Mask */ + +#define DCB_DCRSR_REGSEL_Pos 0U /*!< DCB DCRSR: Register selector Position */ +#define DCB_DCRSR_REGSEL_Msk (0x7FUL /*<< DCB_DCRSR_REGSEL_Pos*/) /*!< DCB DCRSR: Register selector Mask */ + +/* DCRDR, Debug Core Register Data Register Definitions */ +#define DCB_DCRDR_DBGTMP_Pos 0U /*!< DCB DCRDR: Data temporary buffer Position */ +#define DCB_DCRDR_DBGTMP_Msk (0xFFFFFFFFUL /*<< DCB_DCRDR_DBGTMP_Pos*/) /*!< DCB DCRDR: Data temporary buffer Mask */ + +/* DEMCR, Debug Exception and Monitor Control Register Definitions */ +#define DCB_DEMCR_TRCENA_Pos 24U /*!< DCB DEMCR: Trace enable Position */ +#define DCB_DEMCR_TRCENA_Msk (0x1UL << DCB_DEMCR_TRCENA_Pos) /*!< DCB DEMCR: Trace enable Mask */ + +#define DCB_DEMCR_MONPRKEY_Pos 23U /*!< DCB DEMCR: Monitor pend req key Position */ +#define DCB_DEMCR_MONPRKEY_Msk (0x1UL << DCB_DEMCR_MONPRKEY_Pos) /*!< DCB DEMCR: Monitor pend req key Mask */ + +#define DCB_DEMCR_UMON_EN_Pos 21U /*!< DCB DEMCR: Unprivileged monitor enable Position */ +#define DCB_DEMCR_UMON_EN_Msk (0x1UL << DCB_DEMCR_UMON_EN_Pos) /*!< DCB DEMCR: Unprivileged monitor enable Mask */ + +#define DCB_DEMCR_SDME_Pos 20U /*!< DCB DEMCR: Secure DebugMonitor enable Position */ +#define DCB_DEMCR_SDME_Msk (0x1UL << DCB_DEMCR_SDME_Pos) /*!< DCB DEMCR: Secure DebugMonitor enable Mask */ + +#define DCB_DEMCR_MON_REQ_Pos 19U /*!< DCB DEMCR: Monitor request Position */ +#define DCB_DEMCR_MON_REQ_Msk (0x1UL << DCB_DEMCR_MON_REQ_Pos) /*!< DCB DEMCR: Monitor request Mask */ + +#define DCB_DEMCR_MON_STEP_Pos 18U /*!< DCB DEMCR: Monitor step Position */ +#define DCB_DEMCR_MON_STEP_Msk (0x1UL << DCB_DEMCR_MON_STEP_Pos) /*!< DCB DEMCR: Monitor step Mask */ + +#define DCB_DEMCR_MON_PEND_Pos 17U /*!< DCB DEMCR: Monitor pend Position */ +#define DCB_DEMCR_MON_PEND_Msk (0x1UL << DCB_DEMCR_MON_PEND_Pos) /*!< DCB DEMCR: Monitor pend Mask */ + +#define DCB_DEMCR_MON_EN_Pos 16U /*!< DCB DEMCR: Monitor enable Position */ +#define DCB_DEMCR_MON_EN_Msk (0x1UL << DCB_DEMCR_MON_EN_Pos) /*!< DCB DEMCR: Monitor enable Mask */ + +#define DCB_DEMCR_VC_SFERR_Pos 11U /*!< DCB DEMCR: Vector Catch SecureFault Position */ +#define DCB_DEMCR_VC_SFERR_Msk (0x1UL << DCB_DEMCR_VC_SFERR_Pos) /*!< DCB DEMCR: Vector Catch SecureFault Mask */ + +#define DCB_DEMCR_VC_HARDERR_Pos 10U /*!< DCB DEMCR: Vector Catch HardFault errors Position */ +#define DCB_DEMCR_VC_HARDERR_Msk (0x1UL << DCB_DEMCR_VC_HARDERR_Pos) /*!< DCB DEMCR: Vector Catch HardFault errors Mask */ + +#define DCB_DEMCR_VC_INTERR_Pos 9U /*!< DCB DEMCR: Vector Catch interrupt errors Position */ +#define DCB_DEMCR_VC_INTERR_Msk (0x1UL << DCB_DEMCR_VC_INTERR_Pos) /*!< DCB DEMCR: Vector Catch interrupt errors Mask */ + +#define DCB_DEMCR_VC_BUSERR_Pos 8U /*!< DCB DEMCR: Vector Catch BusFault errors Position */ +#define DCB_DEMCR_VC_BUSERR_Msk (0x1UL << DCB_DEMCR_VC_BUSERR_Pos) /*!< DCB DEMCR: Vector Catch BusFault errors Mask */ + +#define DCB_DEMCR_VC_STATERR_Pos 7U /*!< DCB DEMCR: Vector Catch state errors Position */ +#define DCB_DEMCR_VC_STATERR_Msk (0x1UL << DCB_DEMCR_VC_STATERR_Pos) /*!< DCB DEMCR: Vector Catch state errors Mask */ + +#define DCB_DEMCR_VC_CHKERR_Pos 6U /*!< DCB DEMCR: Vector Catch check errors Position */ +#define DCB_DEMCR_VC_CHKERR_Msk (0x1UL << DCB_DEMCR_VC_CHKERR_Pos) /*!< DCB DEMCR: Vector Catch check errors Mask */ + +#define DCB_DEMCR_VC_NOCPERR_Pos 5U /*!< DCB DEMCR: Vector Catch NOCP errors Position */ +#define DCB_DEMCR_VC_NOCPERR_Msk (0x1UL << DCB_DEMCR_VC_NOCPERR_Pos) /*!< DCB DEMCR: Vector Catch NOCP errors Mask */ + +#define DCB_DEMCR_VC_MMERR_Pos 4U /*!< DCB DEMCR: Vector Catch MemManage errors Position */ +#define DCB_DEMCR_VC_MMERR_Msk (0x1UL << DCB_DEMCR_VC_MMERR_Pos) /*!< DCB DEMCR: Vector Catch MemManage errors Mask */ + +#define DCB_DEMCR_VC_CORERESET_Pos 0U /*!< DCB DEMCR: Vector Catch Core reset Position */ +#define DCB_DEMCR_VC_CORERESET_Msk (0x1UL /*<< DCB_DEMCR_VC_CORERESET_Pos*/) /*!< DCB DEMCR: Vector Catch Core reset Mask */ + +/* DAUTHCTRL, Debug Authentication Control Register Definitions */ +#define DCB_DAUTHCTRL_INTSPNIDEN_Pos 3U /*!< DCB DAUTHCTRL: Internal Secure non-invasive debug enable Position */ +#define DCB_DAUTHCTRL_INTSPNIDEN_Msk (0x1UL << DCB_DAUTHCTRL_INTSPNIDEN_Pos) /*!< DCB DAUTHCTRL: Internal Secure non-invasive debug enable Mask */ + +#define DCB_DAUTHCTRL_SPNIDENSEL_Pos 2U /*!< DCB DAUTHCTRL: Secure non-invasive debug enable select Position */ +#define DCB_DAUTHCTRL_SPNIDENSEL_Msk (0x1UL << DCB_DAUTHCTRL_SPNIDENSEL_Pos) /*!< DCB DAUTHCTRL: Secure non-invasive debug enable select Mask */ + +#define DCB_DAUTHCTRL_INTSPIDEN_Pos 1U /*!< DCB DAUTHCTRL: Internal Secure invasive debug enable Position */ +#define DCB_DAUTHCTRL_INTSPIDEN_Msk (0x1UL << DCB_DAUTHCTRL_INTSPIDEN_Pos) /*!< DCB DAUTHCTRL: Internal Secure invasive debug enable Mask */ + +#define DCB_DAUTHCTRL_SPIDENSEL_Pos 0U /*!< DCB DAUTHCTRL: Secure invasive debug enable select Position */ +#define DCB_DAUTHCTRL_SPIDENSEL_Msk (0x1UL /*<< DCB_DAUTHCTRL_SPIDENSEL_Pos*/) /*!< DCB DAUTHCTRL: Secure invasive debug enable select Mask */ + +/* DSCSR, Debug Security Control and Status Register Definitions */ +#define DCB_DSCSR_CDSKEY_Pos 17U /*!< DCB DSCSR: CDS write-enable key Position */ +#define DCB_DSCSR_CDSKEY_Msk (0x1UL << DCB_DSCSR_CDSKEY_Pos) /*!< DCB DSCSR: CDS write-enable key Mask */ + +#define DCB_DSCSR_CDS_Pos 16U /*!< DCB DSCSR: Current domain Secure Position */ +#define DCB_DSCSR_CDS_Msk (0x1UL << DCB_DSCSR_CDS_Pos) /*!< DCB DSCSR: Current domain Secure Mask */ + +#define DCB_DSCSR_SBRSEL_Pos 1U /*!< DCB DSCSR: Secure banked register select Position */ +#define DCB_DSCSR_SBRSEL_Msk (0x1UL << DCB_DSCSR_SBRSEL_Pos) /*!< DCB DSCSR: Secure banked register select Mask */ + +#define DCB_DSCSR_SBRSELEN_Pos 0U /*!< DCB DSCSR: Secure banked register select enable Position */ +#define DCB_DSCSR_SBRSELEN_Msk (0x1UL /*<< DCB_DSCSR_SBRSELEN_Pos*/) /*!< DCB DSCSR: Secure banked register select enable Mask */ + +/*@} end of group CMSIS_DCB */ + + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_DIB Debug Identification Block + \brief Type definitions for the Debug Identification Block Registers + @{ + */ + +/** + \brief Structure type to access the Debug Identification Block Registers (DIB). + */ +typedef struct +{ + __OM uint32_t DLAR; /*!< Offset: 0x000 ( /W) SCS Software Lock Access Register */ + __IM uint32_t DLSR; /*!< Offset: 0x004 (R/ ) SCS Software Lock Status Register */ + __IM uint32_t DAUTHSTATUS; /*!< Offset: 0x008 (R/ ) Debug Authentication Status Register */ + __IM uint32_t DDEVARCH; /*!< Offset: 0x00C (R/ ) SCS Device Architecture Register */ + __IM uint32_t DDEVTYPE; /*!< Offset: 0x010 (R/ ) SCS Device Type Register */ +} DIB_Type; + +/* DLAR, SCS Software Lock Access Register Definitions */ +#define DIB_DLAR_KEY_Pos 0U /*!< DIB DLAR: KEY Position */ +#define DIB_DLAR_KEY_Msk (0xFFFFFFFFUL /*<< DIB_DLAR_KEY_Pos */) /*!< DIB DLAR: KEY Mask */ + +/* DLSR, SCS Software Lock Status Register Definitions */ +#define DIB_DLSR_nTT_Pos 2U /*!< DIB DLSR: Not thirty-two bit Position */ +#define DIB_DLSR_nTT_Msk (0x1UL << DIB_DLSR_nTT_Pos ) /*!< DIB DLSR: Not thirty-two bit Mask */ + +#define DIB_DLSR_SLK_Pos 1U /*!< DIB DLSR: Software Lock status Position */ +#define DIB_DLSR_SLK_Msk (0x1UL << DIB_DLSR_SLK_Pos ) /*!< DIB DLSR: Software Lock status Mask */ + +#define DIB_DLSR_SLI_Pos 0U /*!< DIB DLSR: Software Lock implemented Position */ +#define DIB_DLSR_SLI_Msk (0x1UL /*<< DIB_DLSR_SLI_Pos*/) /*!< DIB DLSR: Software Lock implemented Mask */ + +/* DAUTHSTATUS, Debug Authentication Status Register Definitions */ +#define DIB_DAUTHSTATUS_SNID_Pos 6U /*!< DIB DAUTHSTATUS: Secure Non-invasive Debug Position */ +#define DIB_DAUTHSTATUS_SNID_Msk (0x3UL << DIB_DAUTHSTATUS_SNID_Pos ) /*!< DIB DAUTHSTATUS: Secure Non-invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_SID_Pos 4U /*!< DIB DAUTHSTATUS: Secure Invasive Debug Position */ +#define DIB_DAUTHSTATUS_SID_Msk (0x3UL << DIB_DAUTHSTATUS_SID_Pos ) /*!< DIB DAUTHSTATUS: Secure Invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_NSNID_Pos 2U /*!< DIB DAUTHSTATUS: Non-secure Non-invasive Debug Position */ +#define DIB_DAUTHSTATUS_NSNID_Msk (0x3UL << DIB_DAUTHSTATUS_NSNID_Pos ) /*!< DIB DAUTHSTATUS: Non-secure Non-invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_NSID_Pos 0U /*!< DIB DAUTHSTATUS: Non-secure Invasive Debug Position */ +#define DIB_DAUTHSTATUS_NSID_Msk (0x3UL /*<< DIB_DAUTHSTATUS_NSID_Pos*/) /*!< DIB DAUTHSTATUS: Non-secure Invasive Debug Mask */ + +/* DDEVARCH, SCS Device Architecture Register Definitions */ +#define DIB_DDEVARCH_ARCHITECT_Pos 21U /*!< DIB DDEVARCH: Architect Position */ +#define DIB_DDEVARCH_ARCHITECT_Msk (0x7FFUL << DIB_DDEVARCH_ARCHITECT_Pos ) /*!< DIB DDEVARCH: Architect Mask */ + +#define DIB_DDEVARCH_PRESENT_Pos 20U /*!< DIB DDEVARCH: DEVARCH Present Position */ +#define DIB_DDEVARCH_PRESENT_Msk (0x1FUL << DIB_DDEVARCH_PRESENT_Pos ) /*!< DIB DDEVARCH: DEVARCH Present Mask */ + +#define DIB_DDEVARCH_REVISION_Pos 16U /*!< DIB DDEVARCH: Revision Position */ +#define DIB_DDEVARCH_REVISION_Msk (0xFUL << DIB_DDEVARCH_REVISION_Pos ) /*!< DIB DDEVARCH: Revision Mask */ + +#define DIB_DDEVARCH_ARCHVER_Pos 12U /*!< DIB DDEVARCH: Architecture Version Position */ +#define DIB_DDEVARCH_ARCHVER_Msk (0xFUL << DIB_DDEVARCH_ARCHVER_Pos ) /*!< DIB DDEVARCH: Architecture Version Mask */ + +#define DIB_DDEVARCH_ARCHPART_Pos 0U /*!< DIB DDEVARCH: Architecture Part Position */ +#define DIB_DDEVARCH_ARCHPART_Msk (0xFFFUL /*<< DIB_DDEVARCH_ARCHPART_Pos*/) /*!< DIB DDEVARCH: Architecture Part Mask */ + +/* DDEVTYPE, SCS Device Type Register Definitions */ +#define DIB_DDEVTYPE_SUB_Pos 4U /*!< DIB DDEVTYPE: Sub-type Position */ +#define DIB_DDEVTYPE_SUB_Msk (0xFUL << DIB_DDEVTYPE_SUB_Pos ) /*!< DIB DDEVTYPE: Sub-type Mask */ + +#define DIB_DDEVTYPE_MAJOR_Pos 0U /*!< DIB DDEVTYPE: Major type Position */ +#define DIB_DDEVTYPE_MAJOR_Msk (0xFUL /*<< DIB_DDEVTYPE_MAJOR_Pos*/) /*!< DIB DDEVTYPE: Major type Mask */ + + +/*@} end of group CMSIS_DIB */ + + /** \ingroup CMSIS_core_register \defgroup CMSIS_core_bitfield Core register bit field macros @@ -1954,7 +2200,9 @@ typedef struct #define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */ #define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */ #define TPI_BASE (0xE0040000UL) /*!< TPI Base Address */ - #define CoreDebug_BASE (0xE000EDF0UL) /*!< Core Debug Base Address */ + #define CoreDebug_BASE (0xE000EDF0UL) /*!< \deprecated Core Debug Base Address */ + #define DCB_BASE (0xE000EDF0UL) /*!< DCB Base Address */ + #define DIB_BASE (0xE000EFB0UL) /*!< DIB Base Address */ #define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */ #define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */ #define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */ @@ -1966,7 +2214,9 @@ typedef struct #define ITM ((ITM_Type *) ITM_BASE ) /*!< ITM configuration struct */ #define DWT ((DWT_Type *) DWT_BASE ) /*!< DWT configuration struct */ #define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct */ - #define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE ) /*!< Core Debug configuration struct */ + #define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE ) /*!< \deprecated Core Debug configuration struct */ + #define DCB ((DCB_Type *) DCB_BASE ) /*!< DCB configuration struct */ + #define DIB ((DIB_Type *) DIB_BASE ) /*!< DIB configuration struct */ #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */ @@ -1983,7 +2233,9 @@ typedef struct #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) #define SCS_BASE_NS (0xE002E000UL) /*!< System Control Space Base Address (non-secure address space) */ - #define CoreDebug_BASE_NS (0xE002EDF0UL) /*!< Core Debug Base Address (non-secure address space) */ + #define CoreDebug_BASE_NS (0xE002EDF0UL) /*!< \deprecated Core Debug Base Address (non-secure address space) */ + #define DCB_BASE_NS (0xE002EDF0UL) /*!< DCB Base Address (non-secure address space) */ + #define DIB_BASE_NS (0xE002EFB0UL) /*!< DIB Base Address (non-secure address space) */ #define SysTick_BASE_NS (SCS_BASE_NS + 0x0010UL) /*!< SysTick Base Address (non-secure address space) */ #define NVIC_BASE_NS (SCS_BASE_NS + 0x0100UL) /*!< NVIC Base Address (non-secure address space) */ #define SCB_BASE_NS (SCS_BASE_NS + 0x0D00UL) /*!< System Control Block Base Address (non-secure address space) */ @@ -1992,7 +2244,9 @@ typedef struct #define SCB_NS ((SCB_Type *) SCB_BASE_NS ) /*!< SCB configuration struct (non-secure address space) */ #define SysTick_NS ((SysTick_Type *) SysTick_BASE_NS ) /*!< SysTick configuration struct (non-secure address space) */ #define NVIC_NS ((NVIC_Type *) NVIC_BASE_NS ) /*!< NVIC configuration struct (non-secure address space) */ - #define CoreDebug_NS ((CoreDebug_Type *) CoreDebug_BASE_NS) /*!< Core Debug configuration struct (non-secure address space) */ + #define CoreDebug_NS ((CoreDebug_Type *) CoreDebug_BASE_NS) /*!< \deprecated Core Debug configuration struct (non-secure address space) */ + #define DCB_NS ((DCB_Type *) DCB_BASE_NS ) /*!< DCB configuration struct (non-secure address space) */ + #define DIB_NS ((DIB_Type *) DIB_BASE_NS ) /*!< DIB configuration struct (non-secure address space) */ #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) #define MPU_BASE_NS (SCS_BASE_NS + 0x0D90UL) /*!< Memory Protection Unit (non-secure address space) */ @@ -2006,6 +2260,15 @@ typedef struct /*@} */ +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_register_aliases Backwards Compatibility Aliases + \brief Register alias definitions for backwards compatibility. + @{ + */ +#define ID_ADR (ID_AFR) /*!< SCB Auxiliary Feature Register */ +/*@} */ + /******************************************************************************* * Hardware Abstraction Layer @@ -2064,7 +2327,7 @@ typedef struct /* Special LR values for Secure/Non-Secure call handling and exception handling */ -/* Function Return Payload (from ARMv8-M Architecture Reference Manual) LR value on entry from Secure BLXNS */ +/* Function Return Payload (from ARMv8-M Architecture Reference Manual) LR value on entry from Secure BLXNS */ #define FNC_RETURN (0xFEFFFFFFUL) /* bit [0] ignored when processing a branch */ /* The following EXC_RETURN mask values are used to evaluate the LR on exception entry */ @@ -2079,7 +2342,7 @@ typedef struct /* Integrity Signature (from ARMv8-M Architecture Reference Manual) for exception context stacking */ #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) /* Value for processors with floating-point extension: */ #define EXC_INTEGRITY_SIGNATURE (0xFEFA125AUL) /* bit [0] SFTC must match LR bit[4] EXC_RETURN_FTYPE */ -#else +#else #define EXC_INTEGRITY_SIGNATURE (0xFEFA125BUL) /* Value for processors without floating-point extension */ #endif @@ -2128,7 +2391,9 @@ __STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) { if ((int32_t)(IRQn) >= 0) { + __COMPILER_BARRIER(); NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __COMPILER_BARRIER(); } } @@ -2420,6 +2685,7 @@ __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) { uint32_t *vectors = (uint32_t *)SCB->VTOR; vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector; + __DSB(); } @@ -2746,6 +3012,110 @@ __STATIC_INLINE void TZ_SAU_Disable(void) +/* ################################## Debug Control function ############################################ */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_DCBFunctions Debug Control Functions + \brief Functions that access the Debug Control Block. + @{ + */ + + +/** + \brief Set Debug Authentication Control Register + \details writes to Debug Authentication Control register. + \param [in] value value to be writen. + */ +__STATIC_INLINE void DCB_SetAuthCtrl(uint32_t value) +{ + __DSB(); + __ISB(); + DCB->DAUTHCTRL = value; + __DSB(); + __ISB(); +} + + +/** + \brief Get Debug Authentication Control Register + \details Reads Debug Authentication Control register. + \return Debug Authentication Control Register. + */ +__STATIC_INLINE uint32_t DCB_GetAuthCtrl(void) +{ + return (DCB->DAUTHCTRL); +} + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief Set Debug Authentication Control Register (non-secure) + \details writes to non-secure Debug Authentication Control register when in secure state. + \param [in] value value to be writen + */ +__STATIC_INLINE void TZ_DCB_SetAuthCtrl_NS(uint32_t value) +{ + __DSB(); + __ISB(); + DCB_NS->DAUTHCTRL = value; + __DSB(); + __ISB(); +} + + +/** + \brief Get Debug Authentication Control Register (non-secure) + \details Reads non-secure Debug Authentication Control register when in secure state. + \return Debug Authentication Control Register. + */ +__STATIC_INLINE uint32_t TZ_DCB_GetAuthCtrl_NS(void) +{ + return (DCB_NS->DAUTHCTRL); +} +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + +/*@} end of CMSIS_Core_DCBFunctions */ + + + + +/* ################################## Debug Identification function ############################################ */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_DIBFunctions Debug Identification Functions + \brief Functions that access the Debug Identification Block. + @{ + */ + + +/** + \brief Get Debug Authentication Status Register + \details Reads Debug Authentication Status register. + \return Debug Authentication Status Register. + */ +__STATIC_INLINE uint32_t DIB_GetAuthStatus(void) +{ + return (DIB->DAUTHSTATUS); +} + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief Get Debug Authentication Status Register (non-secure) + \details Reads non-secure Debug Authentication Status register when in secure state. + \return Debug Authentication Status Register. + */ +__STATIC_INLINE uint32_t TZ_DIB_GetAuthStatus_NS(void) +{ + return (DIB_NS->DAUTHSTATUS); +} +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + +/*@} end of CMSIS_Core_DCBFunctions */ + + + + /* ################################## SysTick function ############################################ */ /** \ingroup CMSIS_Core_FunctionInterface diff --git a/lib/cmsis/inc/core_cm4.h b/lib/cmsis/inc/core_cm4.h index f205b333f321c..e21cd14925603 100644 --- a/lib/cmsis/inc/core_cm4.h +++ b/lib/cmsis/inc/core_cm4.h @@ -1,11 +1,11 @@ /**************************************************************************//** * @file core_cm4.h * @brief CMSIS Cortex-M4 Core Peripheral Access Layer Header File - * @version V5.1.0 - * @date 13. March 2019 + * @version V5.1.2 + * @date 04. June 2021 ******************************************************************************/ /* - * Copyright (c) 2009-2019 Arm Limited. All rights reserved. + * Copyright (c) 2009-2020 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -194,6 +194,11 @@ #warning "__MPU_PRESENT not defined in device header file; using default!" #endif + #ifndef __VTOR_PRESENT + #define __VTOR_PRESENT 1U + #warning "__VTOR_PRESENT not defined in device header file; using default!" + #endif + #ifndef __NVIC_PRIO_BITS #define __NVIC_PRIO_BITS 3U #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" @@ -618,22 +623,22 @@ typedef struct #define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */ /* MemManage Fault Status Register (part of SCB Configurable Fault Status Register) */ -#define SCB_CFSR_MMARVALID_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */ +#define SCB_CFSR_MMARVALID_Pos (SCB_CFSR_MEMFAULTSR_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */ #define SCB_CFSR_MMARVALID_Msk (1UL << SCB_CFSR_MMARVALID_Pos) /*!< SCB CFSR (MMFSR): MMARVALID Mask */ -#define SCB_CFSR_MLSPERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 5U) /*!< SCB CFSR (MMFSR): MLSPERR Position */ +#define SCB_CFSR_MLSPERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 5U) /*!< SCB CFSR (MMFSR): MLSPERR Position */ #define SCB_CFSR_MLSPERR_Msk (1UL << SCB_CFSR_MLSPERR_Pos) /*!< SCB CFSR (MMFSR): MLSPERR Mask */ -#define SCB_CFSR_MSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */ +#define SCB_CFSR_MSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */ #define SCB_CFSR_MSTKERR_Msk (1UL << SCB_CFSR_MSTKERR_Pos) /*!< SCB CFSR (MMFSR): MSTKERR Mask */ -#define SCB_CFSR_MUNSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */ +#define SCB_CFSR_MUNSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */ #define SCB_CFSR_MUNSTKERR_Msk (1UL << SCB_CFSR_MUNSTKERR_Pos) /*!< SCB CFSR (MMFSR): MUNSTKERR Mask */ -#define SCB_CFSR_DACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */ +#define SCB_CFSR_DACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */ #define SCB_CFSR_DACCVIOL_Msk (1UL << SCB_CFSR_DACCVIOL_Pos) /*!< SCB CFSR (MMFSR): DACCVIOL Mask */ -#define SCB_CFSR_IACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */ +#define SCB_CFSR_IACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */ #define SCB_CFSR_IACCVIOL_Msk (1UL /*<< SCB_CFSR_IACCVIOL_Pos*/) /*!< SCB CFSR (MMFSR): IACCVIOL Mask */ /* BusFault Status Register (part of SCB Configurable Fault Status Register) */ @@ -1680,7 +1685,9 @@ __STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) { if ((int32_t)(IRQn) >= 0) { + __COMPILER_BARRIER(); NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __COMPILER_BARRIER(); } } @@ -1903,8 +1910,9 @@ __STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGr */ __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) { - uint32_t vectors = (uint32_t )SCB->VTOR; - (* (int *) (vectors + ((int32_t)IRQn + NVIC_USER_IRQ_OFFSET) * 4)) = vector; + uint32_t *vectors = (uint32_t *)SCB->VTOR; + vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector; + /* ARM Application Note 321 states that the M4 does not require the architectural barrier */ } @@ -1918,8 +1926,8 @@ __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) */ __STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn) { - uint32_t vectors = (uint32_t )SCB->VTOR; - return (uint32_t)(* (int *) (vectors + ((int32_t)IRQn + NVIC_USER_IRQ_OFFSET) * 4)); + uint32_t *vectors = (uint32_t *)SCB->VTOR; + return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET]; } diff --git a/lib/cmsis/inc/core_cm55.h b/lib/cmsis/inc/core_cm55.h new file mode 100644 index 0000000000000..faa30ce36a98b --- /dev/null +++ b/lib/cmsis/inc/core_cm55.h @@ -0,0 +1,4817 @@ +/**************************************************************************//** + * @file core_cm55.h + * @brief CMSIS Cortex-M55 Core Peripheral Access Layer Header File + * @version V1.2.4 + * @date 21. April 2022 + ******************************************************************************/ +/* + * Copyright (c) 2018-2022 Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 + * + * 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. + */ + +#if defined ( __ICCARM__ ) + #pragma system_include /* treat file as system include file for MISRA check */ +#elif defined (__clang__) + #pragma clang system_header /* treat file as system include file */ +#elif defined ( __GNUC__ ) + #pragma GCC diagnostic ignored "-Wpedantic" /* disable pedantic warning due to unnamed structs/unions */ +#endif + +#ifndef __CORE_CM55_H_GENERIC +#define __CORE_CM55_H_GENERIC + +#include + +#ifdef __cplusplus + extern "C" { +#endif + +/** + \page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions + CMSIS violates the following MISRA-C:2004 rules: + + \li Required Rule 8.5, object/function definition in header file.
+ Function definitions in header files are used to allow 'inlining'. + + \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.
+ Unions are used for effective representation of core registers. + + \li Advisory Rule 19.7, Function-like macro defined.
+ Function-like macros are used to allow more efficient code. + */ + + +/******************************************************************************* + * CMSIS definitions + ******************************************************************************/ +/** + \ingroup Cortex_M55 + @{ + */ + +#include "cmsis_version.h" + +/* CMSIS CM55 definitions */ +#define __CM55_CMSIS_VERSION_MAIN (__CM_CMSIS_VERSION_MAIN) /*!< \deprecated [31:16] CMSIS HAL main version */ +#define __CM55_CMSIS_VERSION_SUB (__CM_CMSIS_VERSION_SUB) /*!< \deprecated [15:0] CMSIS HAL sub version */ +#define __CM55_CMSIS_VERSION ((__CM55_CMSIS_VERSION_MAIN << 16U) | \ + __CM55_CMSIS_VERSION_SUB ) /*!< \deprecated CMSIS HAL version number */ + +#define __CORTEX_M (55U) /*!< Cortex-M Core */ + +#if defined ( __CC_ARM ) + #error Legacy Arm Compiler does not support Armv8.1-M target architecture. +#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) + #if defined __ARM_FP + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) + #define __FPU_USED 1U + #else + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #define __FPU_USED 0U + #endif + #else + #define __FPU_USED 0U + #endif + + #if defined(__ARM_FEATURE_DSP) + #if defined(__DSP_PRESENT) && (__DSP_PRESENT == 1U) + #define __DSP_USED 1U + #else + #error "Compiler generates DSP (SIMD) instructions for a devices without DSP extensions (check __DSP_PRESENT)" + #define __DSP_USED 0U + #endif + #else + #define __DSP_USED 0U + #endif + +#elif defined ( __GNUC__ ) + #if defined (__VFP_FP__) && !defined(__SOFTFP__) + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) + #define __FPU_USED 1U + #else + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #define __FPU_USED 0U + #endif + #else + #define __FPU_USED 0U + #endif + + #if defined(__ARM_FEATURE_DSP) + #if defined(__DSP_PRESENT) && (__DSP_PRESENT == 1U) + #define __DSP_USED 1U + #else + #error "Compiler generates DSP (SIMD) instructions for a devices without DSP extensions (check __DSP_PRESENT)" + #define __DSP_USED 0U + #endif + #else + #define __DSP_USED 0U + #endif + +#elif defined ( __ICCARM__ ) + #if defined __ARMVFP__ + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) + #define __FPU_USED 1U + #else + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #define __FPU_USED 0U + #endif + #else + #define __FPU_USED 0U + #endif + + #if defined(__ARM_FEATURE_DSP) + #if defined(__DSP_PRESENT) && (__DSP_PRESENT == 1U) + #define __DSP_USED 1U + #else + #error "Compiler generates DSP (SIMD) instructions for a devices without DSP extensions (check __DSP_PRESENT)" + #define __DSP_USED 0U + #endif + #else + #define __DSP_USED 0U + #endif + +#elif defined ( __TI_ARM__ ) + #if defined __TI_VFP_SUPPORT__ + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) + #define __FPU_USED 1U + #else + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #define __FPU_USED 0U + #endif + #else + #define __FPU_USED 0U + #endif + +#elif defined ( __TASKING__ ) + #if defined __FPU_VFP__ + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) + #define __FPU_USED 1U + #else + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #define __FPU_USED 0U + #endif + #else + #define __FPU_USED 0U + #endif + +#elif defined ( __CSMC__ ) + #if ( __CSMC__ & 0x400U) + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) + #define __FPU_USED 1U + #else + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #define __FPU_USED 0U + #endif + #else + #define __FPU_USED 0U + #endif + +#endif + +#include "cmsis_compiler.h" /* CMSIS compiler specific defines */ + + +#ifdef __cplusplus +} +#endif + +#endif /* __CORE_CM55_H_GENERIC */ + +#ifndef __CMSIS_GENERIC + +#ifndef __CORE_CM55_H_DEPENDANT +#define __CORE_CM55_H_DEPENDANT + +#ifdef __cplusplus + extern "C" { +#endif + +/* check device defines and use defaults */ +#if defined __CHECK_DEVICE_DEFINES + #ifndef __CM55_REV + #define __CM55_REV 0x0000U + #warning "__CM55_REV not defined in device header file; using default!" + #endif + + #ifndef __FPU_PRESENT + #define __FPU_PRESENT 0U + #warning "__FPU_PRESENT not defined in device header file; using default!" + #endif + + #if __FPU_PRESENT != 0U + #ifndef __FPU_DP + #define __FPU_DP 0U + #warning "__FPU_DP not defined in device header file; using default!" + #endif + #endif + + #ifndef __MPU_PRESENT + #define __MPU_PRESENT 0U + #warning "__MPU_PRESENT not defined in device header file; using default!" + #endif + + #ifndef __ICACHE_PRESENT + #define __ICACHE_PRESENT 0U + #warning "__ICACHE_PRESENT not defined in device header file; using default!" + #endif + + #ifndef __DCACHE_PRESENT + #define __DCACHE_PRESENT 0U + #warning "__DCACHE_PRESENT not defined in device header file; using default!" + #endif + + #ifndef __VTOR_PRESENT + #define __VTOR_PRESENT 1U + #warning "__VTOR_PRESENT not defined in device header file; using default!" + #endif + + #ifndef __PMU_PRESENT + #define __PMU_PRESENT 0U + #warning "__PMU_PRESENT not defined in device header file; using default!" + #endif + + #if __PMU_PRESENT != 0U + #ifndef __PMU_NUM_EVENTCNT + #define __PMU_NUM_EVENTCNT 8U + #warning "__PMU_NUM_EVENTCNT not defined in device header file; using default!" + #elif (__PMU_NUM_EVENTCNT > 8 || __PMU_NUM_EVENTCNT < 2) + #error "__PMU_NUM_EVENTCNT is out of range in device header file!" */ + #endif + #endif + + #ifndef __SAUREGION_PRESENT + #define __SAUREGION_PRESENT 0U + #warning "__SAUREGION_PRESENT not defined in device header file; using default!" + #endif + + #ifndef __DSP_PRESENT + #define __DSP_PRESENT 0U + #warning "__DSP_PRESENT not defined in device header file; using default!" + #endif + + #ifndef __NVIC_PRIO_BITS + #define __NVIC_PRIO_BITS 3U + #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" + #endif + + #ifndef __Vendor_SysTickConfig + #define __Vendor_SysTickConfig 0U + #warning "__Vendor_SysTickConfig not defined in device header file; using default!" + #endif +#endif + +/* IO definitions (access restrictions to peripheral registers) */ +/** + \defgroup CMSIS_glob_defs CMSIS Global Defines + + IO Type Qualifiers are used + \li to specify the access to peripheral variables. + \li for automatic generation of peripheral register debug information. +*/ +#ifdef __cplusplus + #define __I volatile /*!< Defines 'read only' permissions */ +#else + #define __I volatile const /*!< Defines 'read only' permissions */ +#endif +#define __O volatile /*!< Defines 'write only' permissions */ +#define __IO volatile /*!< Defines 'read / write' permissions */ + +/* following defines should be used for structure members */ +#define __IM volatile const /*! Defines 'read only' structure member permissions */ +#define __OM volatile /*! Defines 'write only' structure member permissions */ +#define __IOM volatile /*! Defines 'read / write' structure member permissions */ + +/*@} end of group Cortex_M55 */ + + + +/******************************************************************************* + * Register Abstraction + Core Register contain: + - Core Register + - Core NVIC Register + - Core EWIC Register + - Core SCB Register + - Core SysTick Register + - Core Debug Register + - Core PMU Register + - Core MPU Register + - Core SAU Register + - Core FPU Register + ******************************************************************************/ +/** + \defgroup CMSIS_core_register Defines and Type Definitions + \brief Type definitions and defines for Cortex-M processor based devices. +*/ + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_CORE Status and Control Registers + \brief Core Register type definitions. + @{ + */ + +/** + \brief Union type to access the Application Program Status Register (APSR). + */ +typedef union +{ + struct + { + uint32_t _reserved0:16; /*!< bit: 0..15 Reserved */ + uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */ + uint32_t _reserved1:7; /*!< bit: 20..26 Reserved */ + uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ + uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ + uint32_t C:1; /*!< bit: 29 Carry condition code flag */ + uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ + uint32_t N:1; /*!< bit: 31 Negative condition code flag */ + } b; /*!< Structure used for bit access */ + uint32_t w; /*!< Type used for word access */ +} APSR_Type; + +/* APSR Register Definitions */ +#define APSR_N_Pos 31U /*!< APSR: N Position */ +#define APSR_N_Msk (1UL << APSR_N_Pos) /*!< APSR: N Mask */ + +#define APSR_Z_Pos 30U /*!< APSR: Z Position */ +#define APSR_Z_Msk (1UL << APSR_Z_Pos) /*!< APSR: Z Mask */ + +#define APSR_C_Pos 29U /*!< APSR: C Position */ +#define APSR_C_Msk (1UL << APSR_C_Pos) /*!< APSR: C Mask */ + +#define APSR_V_Pos 28U /*!< APSR: V Position */ +#define APSR_V_Msk (1UL << APSR_V_Pos) /*!< APSR: V Mask */ + +#define APSR_Q_Pos 27U /*!< APSR: Q Position */ +#define APSR_Q_Msk (1UL << APSR_Q_Pos) /*!< APSR: Q Mask */ + +#define APSR_GE_Pos 16U /*!< APSR: GE Position */ +#define APSR_GE_Msk (0xFUL << APSR_GE_Pos) /*!< APSR: GE Mask */ + + +/** + \brief Union type to access the Interrupt Program Status Register (IPSR). + */ +typedef union +{ + struct + { + uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ + uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */ + } b; /*!< Structure used for bit access */ + uint32_t w; /*!< Type used for word access */ +} IPSR_Type; + +/* IPSR Register Definitions */ +#define IPSR_ISR_Pos 0U /*!< IPSR: ISR Position */ +#define IPSR_ISR_Msk (0x1FFUL /*<< IPSR_ISR_Pos*/) /*!< IPSR: ISR Mask */ + + +/** + \brief Union type to access the Special-Purpose Program Status Registers (xPSR). + */ +typedef union +{ + struct + { + uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ + uint32_t _reserved0:7; /*!< bit: 9..15 Reserved */ + uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */ + uint32_t _reserved1:4; /*!< bit: 20..23 Reserved */ + uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */ + uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */ + uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ + uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ + uint32_t C:1; /*!< bit: 29 Carry condition code flag */ + uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ + uint32_t N:1; /*!< bit: 31 Negative condition code flag */ + } b; /*!< Structure used for bit access */ + uint32_t w; /*!< Type used for word access */ +} xPSR_Type; + +/* xPSR Register Definitions */ +#define xPSR_N_Pos 31U /*!< xPSR: N Position */ +#define xPSR_N_Msk (1UL << xPSR_N_Pos) /*!< xPSR: N Mask */ + +#define xPSR_Z_Pos 30U /*!< xPSR: Z Position */ +#define xPSR_Z_Msk (1UL << xPSR_Z_Pos) /*!< xPSR: Z Mask */ + +#define xPSR_C_Pos 29U /*!< xPSR: C Position */ +#define xPSR_C_Msk (1UL << xPSR_C_Pos) /*!< xPSR: C Mask */ + +#define xPSR_V_Pos 28U /*!< xPSR: V Position */ +#define xPSR_V_Msk (1UL << xPSR_V_Pos) /*!< xPSR: V Mask */ + +#define xPSR_Q_Pos 27U /*!< xPSR: Q Position */ +#define xPSR_Q_Msk (1UL << xPSR_Q_Pos) /*!< xPSR: Q Mask */ + +#define xPSR_IT_Pos 25U /*!< xPSR: IT Position */ +#define xPSR_IT_Msk (3UL << xPSR_IT_Pos) /*!< xPSR: IT Mask */ + +#define xPSR_T_Pos 24U /*!< xPSR: T Position */ +#define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */ + +#define xPSR_GE_Pos 16U /*!< xPSR: GE Position */ +#define xPSR_GE_Msk (0xFUL << xPSR_GE_Pos) /*!< xPSR: GE Mask */ + +#define xPSR_ISR_Pos 0U /*!< xPSR: ISR Position */ +#define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */ + + +/** + \brief Union type to access the Control Registers (CONTROL). + */ +typedef union +{ + struct + { + uint32_t nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */ + uint32_t SPSEL:1; /*!< bit: 1 Stack-pointer select */ + uint32_t FPCA:1; /*!< bit: 2 Floating-point context active */ + uint32_t SFPA:1; /*!< bit: 3 Secure floating-point active */ + uint32_t _reserved1:28; /*!< bit: 4..31 Reserved */ + } b; /*!< Structure used for bit access */ + uint32_t w; /*!< Type used for word access */ +} CONTROL_Type; + +/* CONTROL Register Definitions */ +#define CONTROL_SFPA_Pos 3U /*!< CONTROL: SFPA Position */ +#define CONTROL_SFPA_Msk (1UL << CONTROL_SFPA_Pos) /*!< CONTROL: SFPA Mask */ + +#define CONTROL_FPCA_Pos 2U /*!< CONTROL: FPCA Position */ +#define CONTROL_FPCA_Msk (1UL << CONTROL_FPCA_Pos) /*!< CONTROL: FPCA Mask */ + +#define CONTROL_SPSEL_Pos 1U /*!< CONTROL: SPSEL Position */ +#define CONTROL_SPSEL_Msk (1UL << CONTROL_SPSEL_Pos) /*!< CONTROL: SPSEL Mask */ + +#define CONTROL_nPRIV_Pos 0U /*!< CONTROL: nPRIV Position */ +#define CONTROL_nPRIV_Msk (1UL /*<< CONTROL_nPRIV_Pos*/) /*!< CONTROL: nPRIV Mask */ + +/*@} end of group CMSIS_CORE */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC) + \brief Type definitions for the NVIC Registers + @{ + */ + +/** + \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC). + */ +typedef struct +{ + __IOM uint32_t ISER[16U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */ + uint32_t RESERVED0[16U]; + __IOM uint32_t ICER[16U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */ + uint32_t RSERVED1[16U]; + __IOM uint32_t ISPR[16U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */ + uint32_t RESERVED2[16U]; + __IOM uint32_t ICPR[16U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */ + uint32_t RESERVED3[16U]; + __IOM uint32_t IABR[16U]; /*!< Offset: 0x200 (R/W) Interrupt Active bit Register */ + uint32_t RESERVED4[16U]; + __IOM uint32_t ITNS[16U]; /*!< Offset: 0x280 (R/W) Interrupt Non-Secure State Register */ + uint32_t RESERVED5[16U]; + __IOM uint8_t IPR[496U]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register (8Bit wide) */ + uint32_t RESERVED6[580U]; + __OM uint32_t STIR; /*!< Offset: 0xE00 ( /W) Software Trigger Interrupt Register */ +} NVIC_Type; + +/* Software Triggered Interrupt Register Definitions */ +#define NVIC_STIR_INTID_Pos 0U /*!< STIR: INTLINESNUM Position */ +#define NVIC_STIR_INTID_Msk (0x1FFUL /*<< NVIC_STIR_INTID_Pos*/) /*!< STIR: INTLINESNUM Mask */ + +/*@} end of group CMSIS_NVIC */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_SCB System Control Block (SCB) + \brief Type definitions for the System Control Block Registers + @{ + */ + +/** + \brief Structure type to access the System Control Block (SCB). + */ +typedef struct +{ + __IM uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */ + __IOM uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */ + __IOM uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */ + __IOM uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */ + __IOM uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */ + __IOM uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */ + __IOM uint8_t SHPR[12U]; /*!< Offset: 0x018 (R/W) System Handlers Priority Registers (4-7, 8-11, 12-15) */ + __IOM uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */ + __IOM uint32_t CFSR; /*!< Offset: 0x028 (R/W) Configurable Fault Status Register */ + __IOM uint32_t HFSR; /*!< Offset: 0x02C (R/W) HardFault Status Register */ + __IOM uint32_t DFSR; /*!< Offset: 0x030 (R/W) Debug Fault Status Register */ + __IOM uint32_t MMFAR; /*!< Offset: 0x034 (R/W) MemManage Fault Address Register */ + __IOM uint32_t BFAR; /*!< Offset: 0x038 (R/W) BusFault Address Register */ + __IOM uint32_t AFSR; /*!< Offset: 0x03C (R/W) Auxiliary Fault Status Register */ + __IM uint32_t ID_PFR[2U]; /*!< Offset: 0x040 (R/ ) Processor Feature Register */ + __IM uint32_t ID_DFR; /*!< Offset: 0x048 (R/ ) Debug Feature Register */ + __IM uint32_t ID_AFR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */ + __IM uint32_t ID_MMFR[4U]; /*!< Offset: 0x050 (R/ ) Memory Model Feature Register */ + __IM uint32_t ID_ISAR[6U]; /*!< Offset: 0x060 (R/ ) Instruction Set Attributes Register */ + __IM uint32_t CLIDR; /*!< Offset: 0x078 (R/ ) Cache Level ID register */ + __IM uint32_t CTR; /*!< Offset: 0x07C (R/ ) Cache Type register */ + __IM uint32_t CCSIDR; /*!< Offset: 0x080 (R/ ) Cache Size ID Register */ + __IOM uint32_t CSSELR; /*!< Offset: 0x084 (R/W) Cache Size Selection Register */ + __IOM uint32_t CPACR; /*!< Offset: 0x088 (R/W) Coprocessor Access Control Register */ + __IOM uint32_t NSACR; /*!< Offset: 0x08C (R/W) Non-Secure Access Control Register */ + uint32_t RESERVED7[21U]; + __IOM uint32_t SFSR; /*!< Offset: 0x0E4 (R/W) Secure Fault Status Register */ + __IOM uint32_t SFAR; /*!< Offset: 0x0E8 (R/W) Secure Fault Address Register */ + uint32_t RESERVED3[69U]; + __OM uint32_t STIR; /*!< Offset: 0x200 ( /W) Software Triggered Interrupt Register */ + __IOM uint32_t RFSR; /*!< Offset: 0x204 (R/W) RAS Fault Status Register */ + uint32_t RESERVED4[14U]; + __IM uint32_t MVFR0; /*!< Offset: 0x240 (R/ ) Media and VFP Feature Register 0 */ + __IM uint32_t MVFR1; /*!< Offset: 0x244 (R/ ) Media and VFP Feature Register 1 */ + __IM uint32_t MVFR2; /*!< Offset: 0x248 (R/ ) Media and VFP Feature Register 2 */ + uint32_t RESERVED5[1U]; + __OM uint32_t ICIALLU; /*!< Offset: 0x250 ( /W) I-Cache Invalidate All to PoU */ + uint32_t RESERVED6[1U]; + __OM uint32_t ICIMVAU; /*!< Offset: 0x258 ( /W) I-Cache Invalidate by MVA to PoU */ + __OM uint32_t DCIMVAC; /*!< Offset: 0x25C ( /W) D-Cache Invalidate by MVA to PoC */ + __OM uint32_t DCISW; /*!< Offset: 0x260 ( /W) D-Cache Invalidate by Set-way */ + __OM uint32_t DCCMVAU; /*!< Offset: 0x264 ( /W) D-Cache Clean by MVA to PoU */ + __OM uint32_t DCCMVAC; /*!< Offset: 0x268 ( /W) D-Cache Clean by MVA to PoC */ + __OM uint32_t DCCSW; /*!< Offset: 0x26C ( /W) D-Cache Clean by Set-way */ + __OM uint32_t DCCIMVAC; /*!< Offset: 0x270 ( /W) D-Cache Clean and Invalidate by MVA to PoC */ + __OM uint32_t DCCISW; /*!< Offset: 0x274 ( /W) D-Cache Clean and Invalidate by Set-way */ + __OM uint32_t BPIALL; /*!< Offset: 0x278 ( /W) Branch Predictor Invalidate All */ +} SCB_Type; + +/* SCB CPUID Register Definitions */ +#define SCB_CPUID_IMPLEMENTER_Pos 24U /*!< SCB CPUID: IMPLEMENTER Position */ +#define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */ + +#define SCB_CPUID_VARIANT_Pos 20U /*!< SCB CPUID: VARIANT Position */ +#define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */ + +#define SCB_CPUID_ARCHITECTURE_Pos 16U /*!< SCB CPUID: ARCHITECTURE Position */ +#define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */ + +#define SCB_CPUID_PARTNO_Pos 4U /*!< SCB CPUID: PARTNO Position */ +#define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */ + +#define SCB_CPUID_REVISION_Pos 0U /*!< SCB CPUID: REVISION Position */ +#define SCB_CPUID_REVISION_Msk (0xFUL /*<< SCB_CPUID_REVISION_Pos*/) /*!< SCB CPUID: REVISION Mask */ + +/* SCB Interrupt Control State Register Definitions */ +#define SCB_ICSR_PENDNMISET_Pos 31U /*!< SCB ICSR: PENDNMISET Position */ +#define SCB_ICSR_PENDNMISET_Msk (1UL << SCB_ICSR_PENDNMISET_Pos) /*!< SCB ICSR: PENDNMISET Mask */ + +#define SCB_ICSR_NMIPENDSET_Pos SCB_ICSR_PENDNMISET_Pos /*!< SCB ICSR: NMIPENDSET Position, backward compatibility */ +#define SCB_ICSR_NMIPENDSET_Msk SCB_ICSR_PENDNMISET_Msk /*!< SCB ICSR: NMIPENDSET Mask, backward compatibility */ + +#define SCB_ICSR_PENDNMICLR_Pos 30U /*!< SCB ICSR: PENDNMICLR Position */ +#define SCB_ICSR_PENDNMICLR_Msk (1UL << SCB_ICSR_PENDNMICLR_Pos) /*!< SCB ICSR: PENDNMICLR Mask */ + +#define SCB_ICSR_PENDSVSET_Pos 28U /*!< SCB ICSR: PENDSVSET Position */ +#define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */ + +#define SCB_ICSR_PENDSVCLR_Pos 27U /*!< SCB ICSR: PENDSVCLR Position */ +#define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */ + +#define SCB_ICSR_PENDSTSET_Pos 26U /*!< SCB ICSR: PENDSTSET Position */ +#define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */ + +#define SCB_ICSR_PENDSTCLR_Pos 25U /*!< SCB ICSR: PENDSTCLR Position */ +#define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */ + +#define SCB_ICSR_STTNS_Pos 24U /*!< SCB ICSR: STTNS Position (Security Extension) */ +#define SCB_ICSR_STTNS_Msk (1UL << SCB_ICSR_STTNS_Pos) /*!< SCB ICSR: STTNS Mask (Security Extension) */ + +#define SCB_ICSR_ISRPREEMPT_Pos 23U /*!< SCB ICSR: ISRPREEMPT Position */ +#define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */ + +#define SCB_ICSR_ISRPENDING_Pos 22U /*!< SCB ICSR: ISRPENDING Position */ +#define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */ + +#define SCB_ICSR_VECTPENDING_Pos 12U /*!< SCB ICSR: VECTPENDING Position */ +#define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */ + +#define SCB_ICSR_RETTOBASE_Pos 11U /*!< SCB ICSR: RETTOBASE Position */ +#define SCB_ICSR_RETTOBASE_Msk (1UL << SCB_ICSR_RETTOBASE_Pos) /*!< SCB ICSR: RETTOBASE Mask */ + +#define SCB_ICSR_VECTACTIVE_Pos 0U /*!< SCB ICSR: VECTACTIVE Position */ +#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/) /*!< SCB ICSR: VECTACTIVE Mask */ + +/* SCB Vector Table Offset Register Definitions */ +#define SCB_VTOR_TBLOFF_Pos 7U /*!< SCB VTOR: TBLOFF Position */ +#define SCB_VTOR_TBLOFF_Msk (0x1FFFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF Mask */ + +/* SCB Application Interrupt and Reset Control Register Definitions */ +#define SCB_AIRCR_VECTKEY_Pos 16U /*!< SCB AIRCR: VECTKEY Position */ +#define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */ + +#define SCB_AIRCR_VECTKEYSTAT_Pos 16U /*!< SCB AIRCR: VECTKEYSTAT Position */ +#define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */ + +#define SCB_AIRCR_ENDIANESS_Pos 15U /*!< SCB AIRCR: ENDIANESS Position */ +#define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */ + +#define SCB_AIRCR_PRIS_Pos 14U /*!< SCB AIRCR: PRIS Position */ +#define SCB_AIRCR_PRIS_Msk (1UL << SCB_AIRCR_PRIS_Pos) /*!< SCB AIRCR: PRIS Mask */ + +#define SCB_AIRCR_BFHFNMINS_Pos 13U /*!< SCB AIRCR: BFHFNMINS Position */ +#define SCB_AIRCR_BFHFNMINS_Msk (1UL << SCB_AIRCR_BFHFNMINS_Pos) /*!< SCB AIRCR: BFHFNMINS Mask */ + +#define SCB_AIRCR_PRIGROUP_Pos 8U /*!< SCB AIRCR: PRIGROUP Position */ +#define SCB_AIRCR_PRIGROUP_Msk (7UL << SCB_AIRCR_PRIGROUP_Pos) /*!< SCB AIRCR: PRIGROUP Mask */ + +#define SCB_AIRCR_IESB_Pos 5U /*!< SCB AIRCR: Implicit ESB Enable Position */ +#define SCB_AIRCR_IESB_Msk (1UL << SCB_AIRCR_IESB_Pos) /*!< SCB AIRCR: Implicit ESB Enable Mask */ + +#define SCB_AIRCR_DIT_Pos 4U /*!< SCB AIRCR: Data Independent Timing Position */ +#define SCB_AIRCR_DIT_Msk (1UL << SCB_AIRCR_DIT_Pos) /*!< SCB AIRCR: Data Independent Timing Mask */ + +#define SCB_AIRCR_SYSRESETREQS_Pos 3U /*!< SCB AIRCR: SYSRESETREQS Position */ +#define SCB_AIRCR_SYSRESETREQS_Msk (1UL << SCB_AIRCR_SYSRESETREQS_Pos) /*!< SCB AIRCR: SYSRESETREQS Mask */ + +#define SCB_AIRCR_SYSRESETREQ_Pos 2U /*!< SCB AIRCR: SYSRESETREQ Position */ +#define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */ + +#define SCB_AIRCR_VECTCLRACTIVE_Pos 1U /*!< SCB AIRCR: VECTCLRACTIVE Position */ +#define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */ + +/* SCB System Control Register Definitions */ +#define SCB_SCR_SEVONPEND_Pos 4U /*!< SCB SCR: SEVONPEND Position */ +#define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */ + +#define SCB_SCR_SLEEPDEEPS_Pos 3U /*!< SCB SCR: SLEEPDEEPS Position */ +#define SCB_SCR_SLEEPDEEPS_Msk (1UL << SCB_SCR_SLEEPDEEPS_Pos) /*!< SCB SCR: SLEEPDEEPS Mask */ + +#define SCB_SCR_SLEEPDEEP_Pos 2U /*!< SCB SCR: SLEEPDEEP Position */ +#define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */ + +#define SCB_SCR_SLEEPONEXIT_Pos 1U /*!< SCB SCR: SLEEPONEXIT Position */ +#define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */ + +/* SCB Configuration Control Register Definitions */ +#define SCB_CCR_TRD_Pos 20U /*!< SCB CCR: TRD Position */ +#define SCB_CCR_TRD_Msk (1UL << SCB_CCR_TRD_Pos) /*!< SCB CCR: TRD Mask */ + +#define SCB_CCR_LOB_Pos 19U /*!< SCB CCR: LOB Position */ +#define SCB_CCR_LOB_Msk (1UL << SCB_CCR_LOB_Pos) /*!< SCB CCR: LOB Mask */ + +#define SCB_CCR_BP_Pos 18U /*!< SCB CCR: BP Position */ +#define SCB_CCR_BP_Msk (1UL << SCB_CCR_BP_Pos) /*!< SCB CCR: BP Mask */ + +#define SCB_CCR_IC_Pos 17U /*!< SCB CCR: IC Position */ +#define SCB_CCR_IC_Msk (1UL << SCB_CCR_IC_Pos) /*!< SCB CCR: IC Mask */ + +#define SCB_CCR_DC_Pos 16U /*!< SCB CCR: DC Position */ +#define SCB_CCR_DC_Msk (1UL << SCB_CCR_DC_Pos) /*!< SCB CCR: DC Mask */ + +#define SCB_CCR_STKOFHFNMIGN_Pos 10U /*!< SCB CCR: STKOFHFNMIGN Position */ +#define SCB_CCR_STKOFHFNMIGN_Msk (1UL << SCB_CCR_STKOFHFNMIGN_Pos) /*!< SCB CCR: STKOFHFNMIGN Mask */ + +#define SCB_CCR_BFHFNMIGN_Pos 8U /*!< SCB CCR: BFHFNMIGN Position */ +#define SCB_CCR_BFHFNMIGN_Msk (1UL << SCB_CCR_BFHFNMIGN_Pos) /*!< SCB CCR: BFHFNMIGN Mask */ + +#define SCB_CCR_DIV_0_TRP_Pos 4U /*!< SCB CCR: DIV_0_TRP Position */ +#define SCB_CCR_DIV_0_TRP_Msk (1UL << SCB_CCR_DIV_0_TRP_Pos) /*!< SCB CCR: DIV_0_TRP Mask */ + +#define SCB_CCR_UNALIGN_TRP_Pos 3U /*!< SCB CCR: UNALIGN_TRP Position */ +#define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */ + +#define SCB_CCR_USERSETMPEND_Pos 1U /*!< SCB CCR: USERSETMPEND Position */ +#define SCB_CCR_USERSETMPEND_Msk (1UL << SCB_CCR_USERSETMPEND_Pos) /*!< SCB CCR: USERSETMPEND Mask */ + +/* SCB System Handler Control and State Register Definitions */ +#define SCB_SHCSR_HARDFAULTPENDED_Pos 21U /*!< SCB SHCSR: HARDFAULTPENDED Position */ +#define SCB_SHCSR_HARDFAULTPENDED_Msk (1UL << SCB_SHCSR_HARDFAULTPENDED_Pos) /*!< SCB SHCSR: HARDFAULTPENDED Mask */ + +#define SCB_SHCSR_SECUREFAULTPENDED_Pos 20U /*!< SCB SHCSR: SECUREFAULTPENDED Position */ +#define SCB_SHCSR_SECUREFAULTPENDED_Msk (1UL << SCB_SHCSR_SECUREFAULTPENDED_Pos) /*!< SCB SHCSR: SECUREFAULTPENDED Mask */ + +#define SCB_SHCSR_SECUREFAULTENA_Pos 19U /*!< SCB SHCSR: SECUREFAULTENA Position */ +#define SCB_SHCSR_SECUREFAULTENA_Msk (1UL << SCB_SHCSR_SECUREFAULTENA_Pos) /*!< SCB SHCSR: SECUREFAULTENA Mask */ + +#define SCB_SHCSR_USGFAULTENA_Pos 18U /*!< SCB SHCSR: USGFAULTENA Position */ +#define SCB_SHCSR_USGFAULTENA_Msk (1UL << SCB_SHCSR_USGFAULTENA_Pos) /*!< SCB SHCSR: USGFAULTENA Mask */ + +#define SCB_SHCSR_BUSFAULTENA_Pos 17U /*!< SCB SHCSR: BUSFAULTENA Position */ +#define SCB_SHCSR_BUSFAULTENA_Msk (1UL << SCB_SHCSR_BUSFAULTENA_Pos) /*!< SCB SHCSR: BUSFAULTENA Mask */ + +#define SCB_SHCSR_MEMFAULTENA_Pos 16U /*!< SCB SHCSR: MEMFAULTENA Position */ +#define SCB_SHCSR_MEMFAULTENA_Msk (1UL << SCB_SHCSR_MEMFAULTENA_Pos) /*!< SCB SHCSR: MEMFAULTENA Mask */ + +#define SCB_SHCSR_SVCALLPENDED_Pos 15U /*!< SCB SHCSR: SVCALLPENDED Position */ +#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */ + +#define SCB_SHCSR_BUSFAULTPENDED_Pos 14U /*!< SCB SHCSR: BUSFAULTPENDED Position */ +#define SCB_SHCSR_BUSFAULTPENDED_Msk (1UL << SCB_SHCSR_BUSFAULTPENDED_Pos) /*!< SCB SHCSR: BUSFAULTPENDED Mask */ + +#define SCB_SHCSR_MEMFAULTPENDED_Pos 13U /*!< SCB SHCSR: MEMFAULTPENDED Position */ +#define SCB_SHCSR_MEMFAULTPENDED_Msk (1UL << SCB_SHCSR_MEMFAULTPENDED_Pos) /*!< SCB SHCSR: MEMFAULTPENDED Mask */ + +#define SCB_SHCSR_USGFAULTPENDED_Pos 12U /*!< SCB SHCSR: USGFAULTPENDED Position */ +#define SCB_SHCSR_USGFAULTPENDED_Msk (1UL << SCB_SHCSR_USGFAULTPENDED_Pos) /*!< SCB SHCSR: USGFAULTPENDED Mask */ + +#define SCB_SHCSR_SYSTICKACT_Pos 11U /*!< SCB SHCSR: SYSTICKACT Position */ +#define SCB_SHCSR_SYSTICKACT_Msk (1UL << SCB_SHCSR_SYSTICKACT_Pos) /*!< SCB SHCSR: SYSTICKACT Mask */ + +#define SCB_SHCSR_PENDSVACT_Pos 10U /*!< SCB SHCSR: PENDSVACT Position */ +#define SCB_SHCSR_PENDSVACT_Msk (1UL << SCB_SHCSR_PENDSVACT_Pos) /*!< SCB SHCSR: PENDSVACT Mask */ + +#define SCB_SHCSR_MONITORACT_Pos 8U /*!< SCB SHCSR: MONITORACT Position */ +#define SCB_SHCSR_MONITORACT_Msk (1UL << SCB_SHCSR_MONITORACT_Pos) /*!< SCB SHCSR: MONITORACT Mask */ + +#define SCB_SHCSR_SVCALLACT_Pos 7U /*!< SCB SHCSR: SVCALLACT Position */ +#define SCB_SHCSR_SVCALLACT_Msk (1UL << SCB_SHCSR_SVCALLACT_Pos) /*!< SCB SHCSR: SVCALLACT Mask */ + +#define SCB_SHCSR_NMIACT_Pos 5U /*!< SCB SHCSR: NMIACT Position */ +#define SCB_SHCSR_NMIACT_Msk (1UL << SCB_SHCSR_NMIACT_Pos) /*!< SCB SHCSR: NMIACT Mask */ + +#define SCB_SHCSR_SECUREFAULTACT_Pos 4U /*!< SCB SHCSR: SECUREFAULTACT Position */ +#define SCB_SHCSR_SECUREFAULTACT_Msk (1UL << SCB_SHCSR_SECUREFAULTACT_Pos) /*!< SCB SHCSR: SECUREFAULTACT Mask */ + +#define SCB_SHCSR_USGFAULTACT_Pos 3U /*!< SCB SHCSR: USGFAULTACT Position */ +#define SCB_SHCSR_USGFAULTACT_Msk (1UL << SCB_SHCSR_USGFAULTACT_Pos) /*!< SCB SHCSR: USGFAULTACT Mask */ + +#define SCB_SHCSR_HARDFAULTACT_Pos 2U /*!< SCB SHCSR: HARDFAULTACT Position */ +#define SCB_SHCSR_HARDFAULTACT_Msk (1UL << SCB_SHCSR_HARDFAULTACT_Pos) /*!< SCB SHCSR: HARDFAULTACT Mask */ + +#define SCB_SHCSR_BUSFAULTACT_Pos 1U /*!< SCB SHCSR: BUSFAULTACT Position */ +#define SCB_SHCSR_BUSFAULTACT_Msk (1UL << SCB_SHCSR_BUSFAULTACT_Pos) /*!< SCB SHCSR: BUSFAULTACT Mask */ + +#define SCB_SHCSR_MEMFAULTACT_Pos 0U /*!< SCB SHCSR: MEMFAULTACT Position */ +#define SCB_SHCSR_MEMFAULTACT_Msk (1UL /*<< SCB_SHCSR_MEMFAULTACT_Pos*/) /*!< SCB SHCSR: MEMFAULTACT Mask */ + +/* SCB Configurable Fault Status Register Definitions */ +#define SCB_CFSR_USGFAULTSR_Pos 16U /*!< SCB CFSR: Usage Fault Status Register Position */ +#define SCB_CFSR_USGFAULTSR_Msk (0xFFFFUL << SCB_CFSR_USGFAULTSR_Pos) /*!< SCB CFSR: Usage Fault Status Register Mask */ + +#define SCB_CFSR_BUSFAULTSR_Pos 8U /*!< SCB CFSR: Bus Fault Status Register Position */ +#define SCB_CFSR_BUSFAULTSR_Msk (0xFFUL << SCB_CFSR_BUSFAULTSR_Pos) /*!< SCB CFSR: Bus Fault Status Register Mask */ + +#define SCB_CFSR_MEMFAULTSR_Pos 0U /*!< SCB CFSR: Memory Manage Fault Status Register Position */ +#define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */ + +/* MemManage Fault Status Register (part of SCB Configurable Fault Status Register) */ +#define SCB_CFSR_MMARVALID_Pos (SCB_CFSR_MEMFAULTSR_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */ +#define SCB_CFSR_MMARVALID_Msk (1UL << SCB_CFSR_MMARVALID_Pos) /*!< SCB CFSR (MMFSR): MMARVALID Mask */ + +#define SCB_CFSR_MLSPERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 5U) /*!< SCB CFSR (MMFSR): MLSPERR Position */ +#define SCB_CFSR_MLSPERR_Msk (1UL << SCB_CFSR_MLSPERR_Pos) /*!< SCB CFSR (MMFSR): MLSPERR Mask */ + +#define SCB_CFSR_MSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */ +#define SCB_CFSR_MSTKERR_Msk (1UL << SCB_CFSR_MSTKERR_Pos) /*!< SCB CFSR (MMFSR): MSTKERR Mask */ + +#define SCB_CFSR_MUNSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */ +#define SCB_CFSR_MUNSTKERR_Msk (1UL << SCB_CFSR_MUNSTKERR_Pos) /*!< SCB CFSR (MMFSR): MUNSTKERR Mask */ + +#define SCB_CFSR_DACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */ +#define SCB_CFSR_DACCVIOL_Msk (1UL << SCB_CFSR_DACCVIOL_Pos) /*!< SCB CFSR (MMFSR): DACCVIOL Mask */ + +#define SCB_CFSR_IACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */ +#define SCB_CFSR_IACCVIOL_Msk (1UL /*<< SCB_CFSR_IACCVIOL_Pos*/) /*!< SCB CFSR (MMFSR): IACCVIOL Mask */ + +/* BusFault Status Register (part of SCB Configurable Fault Status Register) */ +#define SCB_CFSR_BFARVALID_Pos (SCB_CFSR_BUSFAULTSR_Pos + 7U) /*!< SCB CFSR (BFSR): BFARVALID Position */ +#define SCB_CFSR_BFARVALID_Msk (1UL << SCB_CFSR_BFARVALID_Pos) /*!< SCB CFSR (BFSR): BFARVALID Mask */ + +#define SCB_CFSR_LSPERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 5U) /*!< SCB CFSR (BFSR): LSPERR Position */ +#define SCB_CFSR_LSPERR_Msk (1UL << SCB_CFSR_LSPERR_Pos) /*!< SCB CFSR (BFSR): LSPERR Mask */ + +#define SCB_CFSR_STKERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 4U) /*!< SCB CFSR (BFSR): STKERR Position */ +#define SCB_CFSR_STKERR_Msk (1UL << SCB_CFSR_STKERR_Pos) /*!< SCB CFSR (BFSR): STKERR Mask */ + +#define SCB_CFSR_UNSTKERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 3U) /*!< SCB CFSR (BFSR): UNSTKERR Position */ +#define SCB_CFSR_UNSTKERR_Msk (1UL << SCB_CFSR_UNSTKERR_Pos) /*!< SCB CFSR (BFSR): UNSTKERR Mask */ + +#define SCB_CFSR_IMPRECISERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 2U) /*!< SCB CFSR (BFSR): IMPRECISERR Position */ +#define SCB_CFSR_IMPRECISERR_Msk (1UL << SCB_CFSR_IMPRECISERR_Pos) /*!< SCB CFSR (BFSR): IMPRECISERR Mask */ + +#define SCB_CFSR_PRECISERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 1U) /*!< SCB CFSR (BFSR): PRECISERR Position */ +#define SCB_CFSR_PRECISERR_Msk (1UL << SCB_CFSR_PRECISERR_Pos) /*!< SCB CFSR (BFSR): PRECISERR Mask */ + +#define SCB_CFSR_IBUSERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 0U) /*!< SCB CFSR (BFSR): IBUSERR Position */ +#define SCB_CFSR_IBUSERR_Msk (1UL << SCB_CFSR_IBUSERR_Pos) /*!< SCB CFSR (BFSR): IBUSERR Mask */ + +/* UsageFault Status Register (part of SCB Configurable Fault Status Register) */ +#define SCB_CFSR_DIVBYZERO_Pos (SCB_CFSR_USGFAULTSR_Pos + 9U) /*!< SCB CFSR (UFSR): DIVBYZERO Position */ +#define SCB_CFSR_DIVBYZERO_Msk (1UL << SCB_CFSR_DIVBYZERO_Pos) /*!< SCB CFSR (UFSR): DIVBYZERO Mask */ + +#define SCB_CFSR_UNALIGNED_Pos (SCB_CFSR_USGFAULTSR_Pos + 8U) /*!< SCB CFSR (UFSR): UNALIGNED Position */ +#define SCB_CFSR_UNALIGNED_Msk (1UL << SCB_CFSR_UNALIGNED_Pos) /*!< SCB CFSR (UFSR): UNALIGNED Mask */ + +#define SCB_CFSR_STKOF_Pos (SCB_CFSR_USGFAULTSR_Pos + 4U) /*!< SCB CFSR (UFSR): STKOF Position */ +#define SCB_CFSR_STKOF_Msk (1UL << SCB_CFSR_STKOF_Pos) /*!< SCB CFSR (UFSR): STKOF Mask */ + +#define SCB_CFSR_NOCP_Pos (SCB_CFSR_USGFAULTSR_Pos + 3U) /*!< SCB CFSR (UFSR): NOCP Position */ +#define SCB_CFSR_NOCP_Msk (1UL << SCB_CFSR_NOCP_Pos) /*!< SCB CFSR (UFSR): NOCP Mask */ + +#define SCB_CFSR_INVPC_Pos (SCB_CFSR_USGFAULTSR_Pos + 2U) /*!< SCB CFSR (UFSR): INVPC Position */ +#define SCB_CFSR_INVPC_Msk (1UL << SCB_CFSR_INVPC_Pos) /*!< SCB CFSR (UFSR): INVPC Mask */ + +#define SCB_CFSR_INVSTATE_Pos (SCB_CFSR_USGFAULTSR_Pos + 1U) /*!< SCB CFSR (UFSR): INVSTATE Position */ +#define SCB_CFSR_INVSTATE_Msk (1UL << SCB_CFSR_INVSTATE_Pos) /*!< SCB CFSR (UFSR): INVSTATE Mask */ + +#define SCB_CFSR_UNDEFINSTR_Pos (SCB_CFSR_USGFAULTSR_Pos + 0U) /*!< SCB CFSR (UFSR): UNDEFINSTR Position */ +#define SCB_CFSR_UNDEFINSTR_Msk (1UL << SCB_CFSR_UNDEFINSTR_Pos) /*!< SCB CFSR (UFSR): UNDEFINSTR Mask */ + +/* SCB Hard Fault Status Register Definitions */ +#define SCB_HFSR_DEBUGEVT_Pos 31U /*!< SCB HFSR: DEBUGEVT Position */ +#define SCB_HFSR_DEBUGEVT_Msk (1UL << SCB_HFSR_DEBUGEVT_Pos) /*!< SCB HFSR: DEBUGEVT Mask */ + +#define SCB_HFSR_FORCED_Pos 30U /*!< SCB HFSR: FORCED Position */ +#define SCB_HFSR_FORCED_Msk (1UL << SCB_HFSR_FORCED_Pos) /*!< SCB HFSR: FORCED Mask */ + +#define SCB_HFSR_VECTTBL_Pos 1U /*!< SCB HFSR: VECTTBL Position */ +#define SCB_HFSR_VECTTBL_Msk (1UL << SCB_HFSR_VECTTBL_Pos) /*!< SCB HFSR: VECTTBL Mask */ + +/* SCB Debug Fault Status Register Definitions */ +#define SCB_DFSR_PMU_Pos 5U /*!< SCB DFSR: PMU Position */ +#define SCB_DFSR_PMU_Msk (1UL << SCB_DFSR_PMU_Pos) /*!< SCB DFSR: PMU Mask */ + +#define SCB_DFSR_EXTERNAL_Pos 4U /*!< SCB DFSR: EXTERNAL Position */ +#define SCB_DFSR_EXTERNAL_Msk (1UL << SCB_DFSR_EXTERNAL_Pos) /*!< SCB DFSR: EXTERNAL Mask */ + +#define SCB_DFSR_VCATCH_Pos 3U /*!< SCB DFSR: VCATCH Position */ +#define SCB_DFSR_VCATCH_Msk (1UL << SCB_DFSR_VCATCH_Pos) /*!< SCB DFSR: VCATCH Mask */ + +#define SCB_DFSR_DWTTRAP_Pos 2U /*!< SCB DFSR: DWTTRAP Position */ +#define SCB_DFSR_DWTTRAP_Msk (1UL << SCB_DFSR_DWTTRAP_Pos) /*!< SCB DFSR: DWTTRAP Mask */ + +#define SCB_DFSR_BKPT_Pos 1U /*!< SCB DFSR: BKPT Position */ +#define SCB_DFSR_BKPT_Msk (1UL << SCB_DFSR_BKPT_Pos) /*!< SCB DFSR: BKPT Mask */ + +#define SCB_DFSR_HALTED_Pos 0U /*!< SCB DFSR: HALTED Position */ +#define SCB_DFSR_HALTED_Msk (1UL /*<< SCB_DFSR_HALTED_Pos*/) /*!< SCB DFSR: HALTED Mask */ + +/* SCB Non-Secure Access Control Register Definitions */ +#define SCB_NSACR_CP11_Pos 11U /*!< SCB NSACR: CP11 Position */ +#define SCB_NSACR_CP11_Msk (1UL << SCB_NSACR_CP11_Pos) /*!< SCB NSACR: CP11 Mask */ + +#define SCB_NSACR_CP10_Pos 10U /*!< SCB NSACR: CP10 Position */ +#define SCB_NSACR_CP10_Msk (1UL << SCB_NSACR_CP10_Pos) /*!< SCB NSACR: CP10 Mask */ + +#define SCB_NSACR_CP7_Pos 7U /*!< SCB NSACR: CP7 Position */ +#define SCB_NSACR_CP7_Msk (1UL << SCB_NSACR_CP7_Pos) /*!< SCB NSACR: CP7 Mask */ + +#define SCB_NSACR_CP6_Pos 6U /*!< SCB NSACR: CP6 Position */ +#define SCB_NSACR_CP6_Msk (1UL << SCB_NSACR_CP6_Pos) /*!< SCB NSACR: CP6 Mask */ + +#define SCB_NSACR_CP5_Pos 5U /*!< SCB NSACR: CP5 Position */ +#define SCB_NSACR_CP5_Msk (1UL << SCB_NSACR_CP5_Pos) /*!< SCB NSACR: CP5 Mask */ + +#define SCB_NSACR_CP4_Pos 4U /*!< SCB NSACR: CP4 Position */ +#define SCB_NSACR_CP4_Msk (1UL << SCB_NSACR_CP4_Pos) /*!< SCB NSACR: CP4 Mask */ + +#define SCB_NSACR_CP3_Pos 3U /*!< SCB NSACR: CP3 Position */ +#define SCB_NSACR_CP3_Msk (1UL << SCB_NSACR_CP3_Pos) /*!< SCB NSACR: CP3 Mask */ + +#define SCB_NSACR_CP2_Pos 2U /*!< SCB NSACR: CP2 Position */ +#define SCB_NSACR_CP2_Msk (1UL << SCB_NSACR_CP2_Pos) /*!< SCB NSACR: CP2 Mask */ + +#define SCB_NSACR_CP1_Pos 1U /*!< SCB NSACR: CP1 Position */ +#define SCB_NSACR_CP1_Msk (1UL << SCB_NSACR_CP1_Pos) /*!< SCB NSACR: CP1 Mask */ + +#define SCB_NSACR_CP0_Pos 0U /*!< SCB NSACR: CP0 Position */ +#define SCB_NSACR_CP0_Msk (1UL /*<< SCB_NSACR_CP0_Pos*/) /*!< SCB NSACR: CP0 Mask */ + +/* SCB Debug Feature Register 0 Definitions */ +#define SCB_ID_DFR_UDE_Pos 28U /*!< SCB ID_DFR: UDE Position */ +#define SCB_ID_DFR_UDE_Msk (0xFUL << SCB_ID_DFR_UDE_Pos) /*!< SCB ID_DFR: UDE Mask */ + +#define SCB_ID_DFR_MProfDbg_Pos 20U /*!< SCB ID_DFR: MProfDbg Position */ +#define SCB_ID_DFR_MProfDbg_Msk (0xFUL << SCB_ID_DFR_MProfDbg_Pos) /*!< SCB ID_DFR: MProfDbg Mask */ + +/* SCB Cache Level ID Register Definitions */ +#define SCB_CLIDR_LOUU_Pos 27U /*!< SCB CLIDR: LoUU Position */ +#define SCB_CLIDR_LOUU_Msk (7UL << SCB_CLIDR_LOUU_Pos) /*!< SCB CLIDR: LoUU Mask */ + +#define SCB_CLIDR_LOC_Pos 24U /*!< SCB CLIDR: LoC Position */ +#define SCB_CLIDR_LOC_Msk (7UL << SCB_CLIDR_LOC_Pos) /*!< SCB CLIDR: LoC Mask */ + +/* SCB Cache Type Register Definitions */ +#define SCB_CTR_FORMAT_Pos 29U /*!< SCB CTR: Format Position */ +#define SCB_CTR_FORMAT_Msk (7UL << SCB_CTR_FORMAT_Pos) /*!< SCB CTR: Format Mask */ + +#define SCB_CTR_CWG_Pos 24U /*!< SCB CTR: CWG Position */ +#define SCB_CTR_CWG_Msk (0xFUL << SCB_CTR_CWG_Pos) /*!< SCB CTR: CWG Mask */ + +#define SCB_CTR_ERG_Pos 20U /*!< SCB CTR: ERG Position */ +#define SCB_CTR_ERG_Msk (0xFUL << SCB_CTR_ERG_Pos) /*!< SCB CTR: ERG Mask */ + +#define SCB_CTR_DMINLINE_Pos 16U /*!< SCB CTR: DminLine Position */ +#define SCB_CTR_DMINLINE_Msk (0xFUL << SCB_CTR_DMINLINE_Pos) /*!< SCB CTR: DminLine Mask */ + +#define SCB_CTR_IMINLINE_Pos 0U /*!< SCB CTR: ImInLine Position */ +#define SCB_CTR_IMINLINE_Msk (0xFUL /*<< SCB_CTR_IMINLINE_Pos*/) /*!< SCB CTR: ImInLine Mask */ + +/* SCB Cache Size ID Register Definitions */ +#define SCB_CCSIDR_WT_Pos 31U /*!< SCB CCSIDR: WT Position */ +#define SCB_CCSIDR_WT_Msk (1UL << SCB_CCSIDR_WT_Pos) /*!< SCB CCSIDR: WT Mask */ + +#define SCB_CCSIDR_WB_Pos 30U /*!< SCB CCSIDR: WB Position */ +#define SCB_CCSIDR_WB_Msk (1UL << SCB_CCSIDR_WB_Pos) /*!< SCB CCSIDR: WB Mask */ + +#define SCB_CCSIDR_RA_Pos 29U /*!< SCB CCSIDR: RA Position */ +#define SCB_CCSIDR_RA_Msk (1UL << SCB_CCSIDR_RA_Pos) /*!< SCB CCSIDR: RA Mask */ + +#define SCB_CCSIDR_WA_Pos 28U /*!< SCB CCSIDR: WA Position */ +#define SCB_CCSIDR_WA_Msk (1UL << SCB_CCSIDR_WA_Pos) /*!< SCB CCSIDR: WA Mask */ + +#define SCB_CCSIDR_NUMSETS_Pos 13U /*!< SCB CCSIDR: NumSets Position */ +#define SCB_CCSIDR_NUMSETS_Msk (0x7FFFUL << SCB_CCSIDR_NUMSETS_Pos) /*!< SCB CCSIDR: NumSets Mask */ + +#define SCB_CCSIDR_ASSOCIATIVITY_Pos 3U /*!< SCB CCSIDR: Associativity Position */ +#define SCB_CCSIDR_ASSOCIATIVITY_Msk (0x3FFUL << SCB_CCSIDR_ASSOCIATIVITY_Pos) /*!< SCB CCSIDR: Associativity Mask */ + +#define SCB_CCSIDR_LINESIZE_Pos 0U /*!< SCB CCSIDR: LineSize Position */ +#define SCB_CCSIDR_LINESIZE_Msk (7UL /*<< SCB_CCSIDR_LINESIZE_Pos*/) /*!< SCB CCSIDR: LineSize Mask */ + +/* SCB Cache Size Selection Register Definitions */ +#define SCB_CSSELR_LEVEL_Pos 1U /*!< SCB CSSELR: Level Position */ +#define SCB_CSSELR_LEVEL_Msk (7UL << SCB_CSSELR_LEVEL_Pos) /*!< SCB CSSELR: Level Mask */ + +#define SCB_CSSELR_IND_Pos 0U /*!< SCB CSSELR: InD Position */ +#define SCB_CSSELR_IND_Msk (1UL /*<< SCB_CSSELR_IND_Pos*/) /*!< SCB CSSELR: InD Mask */ + +/* SCB Software Triggered Interrupt Register Definitions */ +#define SCB_STIR_INTID_Pos 0U /*!< SCB STIR: INTID Position */ +#define SCB_STIR_INTID_Msk (0x1FFUL /*<< SCB_STIR_INTID_Pos*/) /*!< SCB STIR: INTID Mask */ + +/* SCB RAS Fault Status Register Definitions */ +#define SCB_RFSR_V_Pos 31U /*!< SCB RFSR: V Position */ +#define SCB_RFSR_V_Msk (1UL << SCB_RFSR_V_Pos) /*!< SCB RFSR: V Mask */ + +#define SCB_RFSR_IS_Pos 16U /*!< SCB RFSR: IS Position */ +#define SCB_RFSR_IS_Msk (0x7FFFUL << SCB_RFSR_IS_Pos) /*!< SCB RFSR: IS Mask */ + +#define SCB_RFSR_UET_Pos 0U /*!< SCB RFSR: UET Position */ +#define SCB_RFSR_UET_Msk (3UL /*<< SCB_RFSR_UET_Pos*/) /*!< SCB RFSR: UET Mask */ + +/* SCB D-Cache Invalidate by Set-way Register Definitions */ +#define SCB_DCISW_WAY_Pos 30U /*!< SCB DCISW: Way Position */ +#define SCB_DCISW_WAY_Msk (3UL << SCB_DCISW_WAY_Pos) /*!< SCB DCISW: Way Mask */ + +#define SCB_DCISW_SET_Pos 5U /*!< SCB DCISW: Set Position */ +#define SCB_DCISW_SET_Msk (0x1FFUL << SCB_DCISW_SET_Pos) /*!< SCB DCISW: Set Mask */ + +/* SCB D-Cache Clean by Set-way Register Definitions */ +#define SCB_DCCSW_WAY_Pos 30U /*!< SCB DCCSW: Way Position */ +#define SCB_DCCSW_WAY_Msk (3UL << SCB_DCCSW_WAY_Pos) /*!< SCB DCCSW: Way Mask */ + +#define SCB_DCCSW_SET_Pos 5U /*!< SCB DCCSW: Set Position */ +#define SCB_DCCSW_SET_Msk (0x1FFUL << SCB_DCCSW_SET_Pos) /*!< SCB DCCSW: Set Mask */ + +/* SCB D-Cache Clean and Invalidate by Set-way Register Definitions */ +#define SCB_DCCISW_WAY_Pos 30U /*!< SCB DCCISW: Way Position */ +#define SCB_DCCISW_WAY_Msk (3UL << SCB_DCCISW_WAY_Pos) /*!< SCB DCCISW: Way Mask */ + +#define SCB_DCCISW_SET_Pos 5U /*!< SCB DCCISW: Set Position */ +#define SCB_DCCISW_SET_Msk (0x1FFUL << SCB_DCCISW_SET_Pos) /*!< SCB DCCISW: Set Mask */ + +/*@} end of group CMSIS_SCB */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_ICB Implementation Control Block register (ICB) + \brief Type definitions for the Implementation Control Block Register + @{ + */ + +/** + \brief Structure type to access the Implementation Control Block (ICB). + */ +typedef struct +{ + uint32_t RESERVED0[1U]; + __IM uint32_t ICTR; /*!< Offset: 0x004 (R/ ) Interrupt Controller Type Register */ + __IOM uint32_t ACTLR; /*!< Offset: 0x008 (R/W) Auxiliary Control Register */ + __IOM uint32_t CPPWR; /*!< Offset: 0x00C (R/W) Coprocessor Power Control Register */ +} ICB_Type; + +/* Auxiliary Control Register Definitions */ +#define ICB_ACTLR_DISCRITAXIRUW_Pos 27U /*!< ACTLR: DISCRITAXIRUW Position */ +#define ICB_ACTLR_DISCRITAXIRUW_Msk (1UL << ICB_ACTLR_DISCRITAXIRUW_Pos) /*!< ACTLR: DISCRITAXIRUW Mask */ + +#define ICB_ACTLR_DISDI_Pos 16U /*!< ACTLR: DISDI Position */ +#define ICB_ACTLR_DISDI_Msk (3UL << ICB_ACTLR_DISDI_Pos) /*!< ACTLR: DISDI Mask */ + +#define ICB_ACTLR_DISCRITAXIRUR_Pos 15U /*!< ACTLR: DISCRITAXIRUR Position */ +#define ICB_ACTLR_DISCRITAXIRUR_Msk (1UL << ICB_ACTLR_DISCRITAXIRUR_Pos) /*!< ACTLR: DISCRITAXIRUR Mask */ + +#define ICB_ACTLR_EVENTBUSEN_Pos 14U /*!< ACTLR: EVENTBUSEN Position */ +#define ICB_ACTLR_EVENTBUSEN_Msk (1UL << ICB_ACTLR_EVENTBUSEN_Pos) /*!< ACTLR: EVENTBUSEN Mask */ + +#define ICB_ACTLR_EVENTBUSEN_S_Pos 13U /*!< ACTLR: EVENTBUSEN_S Position */ +#define ICB_ACTLR_EVENTBUSEN_S_Msk (1UL << ICB_ACTLR_EVENTBUSEN_S_Pos) /*!< ACTLR: EVENTBUSEN_S Mask */ + +#define ICB_ACTLR_DISITMATBFLUSH_Pos 12U /*!< ACTLR: DISITMATBFLUSH Position */ +#define ICB_ACTLR_DISITMATBFLUSH_Msk (1UL << ICB_ACTLR_DISITMATBFLUSH_Pos) /*!< ACTLR: DISITMATBFLUSH Mask */ + +#define ICB_ACTLR_DISNWAMODE_Pos 11U /*!< ACTLR: DISNWAMODE Position */ +#define ICB_ACTLR_DISNWAMODE_Msk (1UL << ICB_ACTLR_DISNWAMODE_Pos) /*!< ACTLR: DISNWAMODE Mask */ + +#define ICB_ACTLR_FPEXCODIS_Pos 10U /*!< ACTLR: FPEXCODIS Position */ +#define ICB_ACTLR_FPEXCODIS_Msk (1UL << ICB_ACTLR_FPEXCODIS_Pos) /*!< ACTLR: FPEXCODIS Mask */ + +#define ICB_ACTLR_DISOLAP_Pos 7U /*!< ACTLR: DISOLAP Position */ +#define ICB_ACTLR_DISOLAP_Msk (1UL << ICB_ACTLR_DISOLAP_Pos) /*!< ACTLR: DISOLAP Mask */ + +#define ICB_ACTLR_DISOLAPS_Pos 6U /*!< ACTLR: DISOLAPS Position */ +#define ICB_ACTLR_DISOLAPS_Msk (1UL << ICB_ACTLR_DISOLAPS_Pos) /*!< ACTLR: DISOLAPS Mask */ + +#define ICB_ACTLR_DISLOBR_Pos 5U /*!< ACTLR: DISLOBR Position */ +#define ICB_ACTLR_DISLOBR_Msk (1UL << ICB_ACTLR_DISLOBR_Pos) /*!< ACTLR: DISLOBR Mask */ + +#define ICB_ACTLR_DISLO_Pos 4U /*!< ACTLR: DISLO Position */ +#define ICB_ACTLR_DISLO_Msk (1UL << ICB_ACTLR_DISLO_Pos) /*!< ACTLR: DISLO Mask */ + +#define ICB_ACTLR_DISLOLEP_Pos 3U /*!< ACTLR: DISLOLEP Position */ +#define ICB_ACTLR_DISLOLEP_Msk (1UL << ICB_ACTLR_DISLOLEP_Pos) /*!< ACTLR: DISLOLEP Mask */ + +#define ICB_ACTLR_DISFOLD_Pos 2U /*!< ACTLR: DISFOLD Position */ +#define ICB_ACTLR_DISFOLD_Msk (1UL << ICB_ACTLR_DISFOLD_Pos) /*!< ACTLR: DISFOLD Mask */ + +/* Interrupt Controller Type Register Definitions */ +#define ICB_ICTR_INTLINESNUM_Pos 0U /*!< ICTR: INTLINESNUM Position */ +#define ICB_ICTR_INTLINESNUM_Msk (0xFUL /*<< ICB_ICTR_INTLINESNUM_Pos*/) /*!< ICTR: INTLINESNUM Mask */ + +/*@} end of group CMSIS_ICB */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_SysTick System Tick Timer (SysTick) + \brief Type definitions for the System Timer Registers. + @{ + */ + +/** + \brief Structure type to access the System Timer (SysTick). + */ +typedef struct +{ + __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */ + __IOM uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */ + __IOM uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */ + __IM uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */ +} SysTick_Type; + +/* SysTick Control / Status Register Definitions */ +#define SysTick_CTRL_COUNTFLAG_Pos 16U /*!< SysTick CTRL: COUNTFLAG Position */ +#define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */ + +#define SysTick_CTRL_CLKSOURCE_Pos 2U /*!< SysTick CTRL: CLKSOURCE Position */ +#define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */ + +#define SysTick_CTRL_TICKINT_Pos 1U /*!< SysTick CTRL: TICKINT Position */ +#define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */ + +#define SysTick_CTRL_ENABLE_Pos 0U /*!< SysTick CTRL: ENABLE Position */ +#define SysTick_CTRL_ENABLE_Msk (1UL /*<< SysTick_CTRL_ENABLE_Pos*/) /*!< SysTick CTRL: ENABLE Mask */ + +/* SysTick Reload Register Definitions */ +#define SysTick_LOAD_RELOAD_Pos 0U /*!< SysTick LOAD: RELOAD Position */ +#define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL /*<< SysTick_LOAD_RELOAD_Pos*/) /*!< SysTick LOAD: RELOAD Mask */ + +/* SysTick Current Register Definitions */ +#define SysTick_VAL_CURRENT_Pos 0U /*!< SysTick VAL: CURRENT Position */ +#define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL /*<< SysTick_VAL_CURRENT_Pos*/) /*!< SysTick VAL: CURRENT Mask */ + +/* SysTick Calibration Register Definitions */ +#define SysTick_CALIB_NOREF_Pos 31U /*!< SysTick CALIB: NOREF Position */ +#define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */ + +#define SysTick_CALIB_SKEW_Pos 30U /*!< SysTick CALIB: SKEW Position */ +#define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */ + +#define SysTick_CALIB_TENMS_Pos 0U /*!< SysTick CALIB: TENMS Position */ +#define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL /*<< SysTick_CALIB_TENMS_Pos*/) /*!< SysTick CALIB: TENMS Mask */ + +/*@} end of group CMSIS_SysTick */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_ITM Instrumentation Trace Macrocell (ITM) + \brief Type definitions for the Instrumentation Trace Macrocell (ITM) + @{ + */ + +/** + \brief Structure type to access the Instrumentation Trace Macrocell Register (ITM). + */ +typedef struct +{ + __OM union + { + __OM uint8_t u8; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 8-bit */ + __OM uint16_t u16; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 16-bit */ + __OM uint32_t u32; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 32-bit */ + } PORT [32U]; /*!< Offset: 0x000 ( /W) ITM Stimulus Port Registers */ + uint32_t RESERVED0[864U]; + __IOM uint32_t TER; /*!< Offset: 0xE00 (R/W) ITM Trace Enable Register */ + uint32_t RESERVED1[15U]; + __IOM uint32_t TPR; /*!< Offset: 0xE40 (R/W) ITM Trace Privilege Register */ + uint32_t RESERVED2[15U]; + __IOM uint32_t TCR; /*!< Offset: 0xE80 (R/W) ITM Trace Control Register */ + uint32_t RESERVED3[32U]; + uint32_t RESERVED4[43U]; + __OM uint32_t LAR; /*!< Offset: 0xFB0 ( /W) ITM Lock Access Register */ + __IM uint32_t LSR; /*!< Offset: 0xFB4 (R/ ) ITM Lock Status Register */ + uint32_t RESERVED5[1U]; + __IM uint32_t DEVARCH; /*!< Offset: 0xFBC (R/ ) ITM Device Architecture Register */ + uint32_t RESERVED6[3U]; + __IM uint32_t DEVTYPE; /*!< Offset: 0xFCC (R/ ) ITM Device Type Register */ + __IM uint32_t PID4; /*!< Offset: 0xFD0 (R/ ) ITM Peripheral Identification Register #4 */ + __IM uint32_t PID5; /*!< Offset: 0xFD4 (R/ ) ITM Peripheral Identification Register #5 */ + __IM uint32_t PID6; /*!< Offset: 0xFD8 (R/ ) ITM Peripheral Identification Register #6 */ + __IM uint32_t PID7; /*!< Offset: 0xFDC (R/ ) ITM Peripheral Identification Register #7 */ + __IM uint32_t PID0; /*!< Offset: 0xFE0 (R/ ) ITM Peripheral Identification Register #0 */ + __IM uint32_t PID1; /*!< Offset: 0xFE4 (R/ ) ITM Peripheral Identification Register #1 */ + __IM uint32_t PID2; /*!< Offset: 0xFE8 (R/ ) ITM Peripheral Identification Register #2 */ + __IM uint32_t PID3; /*!< Offset: 0xFEC (R/ ) ITM Peripheral Identification Register #3 */ + __IM uint32_t CID0; /*!< Offset: 0xFF0 (R/ ) ITM Component Identification Register #0 */ + __IM uint32_t CID1; /*!< Offset: 0xFF4 (R/ ) ITM Component Identification Register #1 */ + __IM uint32_t CID2; /*!< Offset: 0xFF8 (R/ ) ITM Component Identification Register #2 */ + __IM uint32_t CID3; /*!< Offset: 0xFFC (R/ ) ITM Component Identification Register #3 */ +} ITM_Type; + +/* ITM Stimulus Port Register Definitions */ +#define ITM_STIM_DISABLED_Pos 1U /*!< ITM STIM: DISABLED Position */ +#define ITM_STIM_DISABLED_Msk (0x1UL << ITM_STIM_DISABLED_Pos) /*!< ITM STIM: DISABLED Mask */ + +#define ITM_STIM_FIFOREADY_Pos 0U /*!< ITM STIM: FIFOREADY Position */ +#define ITM_STIM_FIFOREADY_Msk (0x1UL /*<< ITM_STIM_FIFOREADY_Pos*/) /*!< ITM STIM: FIFOREADY Mask */ + +/* ITM Trace Privilege Register Definitions */ +#define ITM_TPR_PRIVMASK_Pos 0U /*!< ITM TPR: PRIVMASK Position */ +#define ITM_TPR_PRIVMASK_Msk (0xFUL /*<< ITM_TPR_PRIVMASK_Pos*/) /*!< ITM TPR: PRIVMASK Mask */ + +/* ITM Trace Control Register Definitions */ +#define ITM_TCR_BUSY_Pos 23U /*!< ITM TCR: BUSY Position */ +#define ITM_TCR_BUSY_Msk (1UL << ITM_TCR_BUSY_Pos) /*!< ITM TCR: BUSY Mask */ + +#define ITM_TCR_TRACEBUSID_Pos 16U /*!< ITM TCR: ATBID Position */ +#define ITM_TCR_TRACEBUSID_Msk (0x7FUL << ITM_TCR_TRACEBUSID_Pos) /*!< ITM TCR: ATBID Mask */ + +#define ITM_TCR_GTSFREQ_Pos 10U /*!< ITM TCR: Global timestamp frequency Position */ +#define ITM_TCR_GTSFREQ_Msk (3UL << ITM_TCR_GTSFREQ_Pos) /*!< ITM TCR: Global timestamp frequency Mask */ + +#define ITM_TCR_TSPRESCALE_Pos 8U /*!< ITM TCR: TSPRESCALE Position */ +#define ITM_TCR_TSPRESCALE_Msk (3UL << ITM_TCR_TSPRESCALE_Pos) /*!< ITM TCR: TSPRESCALE Mask */ + +#define ITM_TCR_STALLENA_Pos 5U /*!< ITM TCR: STALLENA Position */ +#define ITM_TCR_STALLENA_Msk (1UL << ITM_TCR_STALLENA_Pos) /*!< ITM TCR: STALLENA Mask */ + +#define ITM_TCR_SWOENA_Pos 4U /*!< ITM TCR: SWOENA Position */ +#define ITM_TCR_SWOENA_Msk (1UL << ITM_TCR_SWOENA_Pos) /*!< ITM TCR: SWOENA Mask */ + +#define ITM_TCR_DWTENA_Pos 3U /*!< ITM TCR: DWTENA Position */ +#define ITM_TCR_DWTENA_Msk (1UL << ITM_TCR_DWTENA_Pos) /*!< ITM TCR: DWTENA Mask */ + +#define ITM_TCR_SYNCENA_Pos 2U /*!< ITM TCR: SYNCENA Position */ +#define ITM_TCR_SYNCENA_Msk (1UL << ITM_TCR_SYNCENA_Pos) /*!< ITM TCR: SYNCENA Mask */ + +#define ITM_TCR_TSENA_Pos 1U /*!< ITM TCR: TSENA Position */ +#define ITM_TCR_TSENA_Msk (1UL << ITM_TCR_TSENA_Pos) /*!< ITM TCR: TSENA Mask */ + +#define ITM_TCR_ITMENA_Pos 0U /*!< ITM TCR: ITM Enable bit Position */ +#define ITM_TCR_ITMENA_Msk (1UL /*<< ITM_TCR_ITMENA_Pos*/) /*!< ITM TCR: ITM Enable bit Mask */ + +/* ITM Lock Status Register Definitions */ +#define ITM_LSR_ByteAcc_Pos 2U /*!< ITM LSR: ByteAcc Position */ +#define ITM_LSR_ByteAcc_Msk (1UL << ITM_LSR_ByteAcc_Pos) /*!< ITM LSR: ByteAcc Mask */ + +#define ITM_LSR_Access_Pos 1U /*!< ITM LSR: Access Position */ +#define ITM_LSR_Access_Msk (1UL << ITM_LSR_Access_Pos) /*!< ITM LSR: Access Mask */ + +#define ITM_LSR_Present_Pos 0U /*!< ITM LSR: Present Position */ +#define ITM_LSR_Present_Msk (1UL /*<< ITM_LSR_Present_Pos*/) /*!< ITM LSR: Present Mask */ + +/*@}*/ /* end of group CMSIS_ITM */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_DWT Data Watchpoint and Trace (DWT) + \brief Type definitions for the Data Watchpoint and Trace (DWT) + @{ + */ + +/** + \brief Structure type to access the Data Watchpoint and Trace Register (DWT). + */ +typedef struct +{ + __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control Register */ + __IOM uint32_t CYCCNT; /*!< Offset: 0x004 (R/W) Cycle Count Register */ + __IOM uint32_t CPICNT; /*!< Offset: 0x008 (R/W) CPI Count Register */ + __IOM uint32_t EXCCNT; /*!< Offset: 0x00C (R/W) Exception Overhead Count Register */ + __IOM uint32_t SLEEPCNT; /*!< Offset: 0x010 (R/W) Sleep Count Register */ + __IOM uint32_t LSUCNT; /*!< Offset: 0x014 (R/W) LSU Count Register */ + __IOM uint32_t FOLDCNT; /*!< Offset: 0x018 (R/W) Folded-instruction Count Register */ + __IM uint32_t PCSR; /*!< Offset: 0x01C (R/ ) Program Counter Sample Register */ + __IOM uint32_t COMP0; /*!< Offset: 0x020 (R/W) Comparator Register 0 */ + uint32_t RESERVED1[1U]; + __IOM uint32_t FUNCTION0; /*!< Offset: 0x028 (R/W) Function Register 0 */ + uint32_t RESERVED2[1U]; + __IOM uint32_t COMP1; /*!< Offset: 0x030 (R/W) Comparator Register 1 */ + uint32_t RESERVED3[1U]; + __IOM uint32_t FUNCTION1; /*!< Offset: 0x038 (R/W) Function Register 1 */ + uint32_t RESERVED4[1U]; + __IOM uint32_t COMP2; /*!< Offset: 0x040 (R/W) Comparator Register 2 */ + uint32_t RESERVED5[1U]; + __IOM uint32_t FUNCTION2; /*!< Offset: 0x048 (R/W) Function Register 2 */ + uint32_t RESERVED6[1U]; + __IOM uint32_t COMP3; /*!< Offset: 0x050 (R/W) Comparator Register 3 */ + uint32_t RESERVED7[1U]; + __IOM uint32_t FUNCTION3; /*!< Offset: 0x058 (R/W) Function Register 3 */ + uint32_t RESERVED8[1U]; + __IOM uint32_t COMP4; /*!< Offset: 0x060 (R/W) Comparator Register 4 */ + uint32_t RESERVED9[1U]; + __IOM uint32_t FUNCTION4; /*!< Offset: 0x068 (R/W) Function Register 4 */ + uint32_t RESERVED10[1U]; + __IOM uint32_t COMP5; /*!< Offset: 0x070 (R/W) Comparator Register 5 */ + uint32_t RESERVED11[1U]; + __IOM uint32_t FUNCTION5; /*!< Offset: 0x078 (R/W) Function Register 5 */ + uint32_t RESERVED12[1U]; + __IOM uint32_t COMP6; /*!< Offset: 0x080 (R/W) Comparator Register 6 */ + uint32_t RESERVED13[1U]; + __IOM uint32_t FUNCTION6; /*!< Offset: 0x088 (R/W) Function Register 6 */ + uint32_t RESERVED14[1U]; + __IOM uint32_t COMP7; /*!< Offset: 0x090 (R/W) Comparator Register 7 */ + uint32_t RESERVED15[1U]; + __IOM uint32_t FUNCTION7; /*!< Offset: 0x098 (R/W) Function Register 7 */ + uint32_t RESERVED16[1U]; + __IOM uint32_t COMP8; /*!< Offset: 0x0A0 (R/W) Comparator Register 8 */ + uint32_t RESERVED17[1U]; + __IOM uint32_t FUNCTION8; /*!< Offset: 0x0A8 (R/W) Function Register 8 */ + uint32_t RESERVED18[1U]; + __IOM uint32_t COMP9; /*!< Offset: 0x0B0 (R/W) Comparator Register 9 */ + uint32_t RESERVED19[1U]; + __IOM uint32_t FUNCTION9; /*!< Offset: 0x0B8 (R/W) Function Register 9 */ + uint32_t RESERVED20[1U]; + __IOM uint32_t COMP10; /*!< Offset: 0x0C0 (R/W) Comparator Register 10 */ + uint32_t RESERVED21[1U]; + __IOM uint32_t FUNCTION10; /*!< Offset: 0x0C8 (R/W) Function Register 10 */ + uint32_t RESERVED22[1U]; + __IOM uint32_t COMP11; /*!< Offset: 0x0D0 (R/W) Comparator Register 11 */ + uint32_t RESERVED23[1U]; + __IOM uint32_t FUNCTION11; /*!< Offset: 0x0D8 (R/W) Function Register 11 */ + uint32_t RESERVED24[1U]; + __IOM uint32_t COMP12; /*!< Offset: 0x0E0 (R/W) Comparator Register 12 */ + uint32_t RESERVED25[1U]; + __IOM uint32_t FUNCTION12; /*!< Offset: 0x0E8 (R/W) Function Register 12 */ + uint32_t RESERVED26[1U]; + __IOM uint32_t COMP13; /*!< Offset: 0x0F0 (R/W) Comparator Register 13 */ + uint32_t RESERVED27[1U]; + __IOM uint32_t FUNCTION13; /*!< Offset: 0x0F8 (R/W) Function Register 13 */ + uint32_t RESERVED28[1U]; + __IOM uint32_t COMP14; /*!< Offset: 0x100 (R/W) Comparator Register 14 */ + uint32_t RESERVED29[1U]; + __IOM uint32_t FUNCTION14; /*!< Offset: 0x108 (R/W) Function Register 14 */ + uint32_t RESERVED30[1U]; + __IOM uint32_t COMP15; /*!< Offset: 0x110 (R/W) Comparator Register 15 */ + uint32_t RESERVED31[1U]; + __IOM uint32_t FUNCTION15; /*!< Offset: 0x118 (R/W) Function Register 15 */ + uint32_t RESERVED32[934U]; + __IM uint32_t LSR; /*!< Offset: 0xFB4 (R ) Lock Status Register */ + uint32_t RESERVED33[1U]; + __IM uint32_t DEVARCH; /*!< Offset: 0xFBC (R/ ) Device Architecture Register */ +} DWT_Type; + +/* DWT Control Register Definitions */ +#define DWT_CTRL_NUMCOMP_Pos 28U /*!< DWT CTRL: NUMCOMP Position */ +#define DWT_CTRL_NUMCOMP_Msk (0xFUL << DWT_CTRL_NUMCOMP_Pos) /*!< DWT CTRL: NUMCOMP Mask */ + +#define DWT_CTRL_NOTRCPKT_Pos 27U /*!< DWT CTRL: NOTRCPKT Position */ +#define DWT_CTRL_NOTRCPKT_Msk (0x1UL << DWT_CTRL_NOTRCPKT_Pos) /*!< DWT CTRL: NOTRCPKT Mask */ + +#define DWT_CTRL_NOEXTTRIG_Pos 26U /*!< DWT CTRL: NOEXTTRIG Position */ +#define DWT_CTRL_NOEXTTRIG_Msk (0x1UL << DWT_CTRL_NOEXTTRIG_Pos) /*!< DWT CTRL: NOEXTTRIG Mask */ + +#define DWT_CTRL_NOCYCCNT_Pos 25U /*!< DWT CTRL: NOCYCCNT Position */ +#define DWT_CTRL_NOCYCCNT_Msk (0x1UL << DWT_CTRL_NOCYCCNT_Pos) /*!< DWT CTRL: NOCYCCNT Mask */ + +#define DWT_CTRL_NOPRFCNT_Pos 24U /*!< DWT CTRL: NOPRFCNT Position */ +#define DWT_CTRL_NOPRFCNT_Msk (0x1UL << DWT_CTRL_NOPRFCNT_Pos) /*!< DWT CTRL: NOPRFCNT Mask */ + +#define DWT_CTRL_CYCDISS_Pos 23U /*!< DWT CTRL: CYCDISS Position */ +#define DWT_CTRL_CYCDISS_Msk (0x1UL << DWT_CTRL_CYCDISS_Pos) /*!< DWT CTRL: CYCDISS Mask */ + +#define DWT_CTRL_CYCEVTENA_Pos 22U /*!< DWT CTRL: CYCEVTENA Position */ +#define DWT_CTRL_CYCEVTENA_Msk (0x1UL << DWT_CTRL_CYCEVTENA_Pos) /*!< DWT CTRL: CYCEVTENA Mask */ + +#define DWT_CTRL_FOLDEVTENA_Pos 21U /*!< DWT CTRL: FOLDEVTENA Position */ +#define DWT_CTRL_FOLDEVTENA_Msk (0x1UL << DWT_CTRL_FOLDEVTENA_Pos) /*!< DWT CTRL: FOLDEVTENA Mask */ + +#define DWT_CTRL_LSUEVTENA_Pos 20U /*!< DWT CTRL: LSUEVTENA Position */ +#define DWT_CTRL_LSUEVTENA_Msk (0x1UL << DWT_CTRL_LSUEVTENA_Pos) /*!< DWT CTRL: LSUEVTENA Mask */ + +#define DWT_CTRL_SLEEPEVTENA_Pos 19U /*!< DWT CTRL: SLEEPEVTENA Position */ +#define DWT_CTRL_SLEEPEVTENA_Msk (0x1UL << DWT_CTRL_SLEEPEVTENA_Pos) /*!< DWT CTRL: SLEEPEVTENA Mask */ + +#define DWT_CTRL_EXCEVTENA_Pos 18U /*!< DWT CTRL: EXCEVTENA Position */ +#define DWT_CTRL_EXCEVTENA_Msk (0x1UL << DWT_CTRL_EXCEVTENA_Pos) /*!< DWT CTRL: EXCEVTENA Mask */ + +#define DWT_CTRL_CPIEVTENA_Pos 17U /*!< DWT CTRL: CPIEVTENA Position */ +#define DWT_CTRL_CPIEVTENA_Msk (0x1UL << DWT_CTRL_CPIEVTENA_Pos) /*!< DWT CTRL: CPIEVTENA Mask */ + +#define DWT_CTRL_EXCTRCENA_Pos 16U /*!< DWT CTRL: EXCTRCENA Position */ +#define DWT_CTRL_EXCTRCENA_Msk (0x1UL << DWT_CTRL_EXCTRCENA_Pos) /*!< DWT CTRL: EXCTRCENA Mask */ + +#define DWT_CTRL_PCSAMPLENA_Pos 12U /*!< DWT CTRL: PCSAMPLENA Position */ +#define DWT_CTRL_PCSAMPLENA_Msk (0x1UL << DWT_CTRL_PCSAMPLENA_Pos) /*!< DWT CTRL: PCSAMPLENA Mask */ + +#define DWT_CTRL_SYNCTAP_Pos 10U /*!< DWT CTRL: SYNCTAP Position */ +#define DWT_CTRL_SYNCTAP_Msk (0x3UL << DWT_CTRL_SYNCTAP_Pos) /*!< DWT CTRL: SYNCTAP Mask */ + +#define DWT_CTRL_CYCTAP_Pos 9U /*!< DWT CTRL: CYCTAP Position */ +#define DWT_CTRL_CYCTAP_Msk (0x1UL << DWT_CTRL_CYCTAP_Pos) /*!< DWT CTRL: CYCTAP Mask */ + +#define DWT_CTRL_POSTINIT_Pos 5U /*!< DWT CTRL: POSTINIT Position */ +#define DWT_CTRL_POSTINIT_Msk (0xFUL << DWT_CTRL_POSTINIT_Pos) /*!< DWT CTRL: POSTINIT Mask */ + +#define DWT_CTRL_POSTPRESET_Pos 1U /*!< DWT CTRL: POSTPRESET Position */ +#define DWT_CTRL_POSTPRESET_Msk (0xFUL << DWT_CTRL_POSTPRESET_Pos) /*!< DWT CTRL: POSTPRESET Mask */ + +#define DWT_CTRL_CYCCNTENA_Pos 0U /*!< DWT CTRL: CYCCNTENA Position */ +#define DWT_CTRL_CYCCNTENA_Msk (0x1UL /*<< DWT_CTRL_CYCCNTENA_Pos*/) /*!< DWT CTRL: CYCCNTENA Mask */ + +/* DWT CPI Count Register Definitions */ +#define DWT_CPICNT_CPICNT_Pos 0U /*!< DWT CPICNT: CPICNT Position */ +#define DWT_CPICNT_CPICNT_Msk (0xFFUL /*<< DWT_CPICNT_CPICNT_Pos*/) /*!< DWT CPICNT: CPICNT Mask */ + +/* DWT Exception Overhead Count Register Definitions */ +#define DWT_EXCCNT_EXCCNT_Pos 0U /*!< DWT EXCCNT: EXCCNT Position */ +#define DWT_EXCCNT_EXCCNT_Msk (0xFFUL /*<< DWT_EXCCNT_EXCCNT_Pos*/) /*!< DWT EXCCNT: EXCCNT Mask */ + +/* DWT Sleep Count Register Definitions */ +#define DWT_SLEEPCNT_SLEEPCNT_Pos 0U /*!< DWT SLEEPCNT: SLEEPCNT Position */ +#define DWT_SLEEPCNT_SLEEPCNT_Msk (0xFFUL /*<< DWT_SLEEPCNT_SLEEPCNT_Pos*/) /*!< DWT SLEEPCNT: SLEEPCNT Mask */ + +/* DWT LSU Count Register Definitions */ +#define DWT_LSUCNT_LSUCNT_Pos 0U /*!< DWT LSUCNT: LSUCNT Position */ +#define DWT_LSUCNT_LSUCNT_Msk (0xFFUL /*<< DWT_LSUCNT_LSUCNT_Pos*/) /*!< DWT LSUCNT: LSUCNT Mask */ + +/* DWT Folded-instruction Count Register Definitions */ +#define DWT_FOLDCNT_FOLDCNT_Pos 0U /*!< DWT FOLDCNT: FOLDCNT Position */ +#define DWT_FOLDCNT_FOLDCNT_Msk (0xFFUL /*<< DWT_FOLDCNT_FOLDCNT_Pos*/) /*!< DWT FOLDCNT: FOLDCNT Mask */ + +/* DWT Comparator Function Register Definitions */ +#define DWT_FUNCTION_ID_Pos 27U /*!< DWT FUNCTION: ID Position */ +#define DWT_FUNCTION_ID_Msk (0x1FUL << DWT_FUNCTION_ID_Pos) /*!< DWT FUNCTION: ID Mask */ + +#define DWT_FUNCTION_MATCHED_Pos 24U /*!< DWT FUNCTION: MATCHED Position */ +#define DWT_FUNCTION_MATCHED_Msk (0x1UL << DWT_FUNCTION_MATCHED_Pos) /*!< DWT FUNCTION: MATCHED Mask */ + +#define DWT_FUNCTION_DATAVSIZE_Pos 10U /*!< DWT FUNCTION: DATAVSIZE Position */ +#define DWT_FUNCTION_DATAVSIZE_Msk (0x3UL << DWT_FUNCTION_DATAVSIZE_Pos) /*!< DWT FUNCTION: DATAVSIZE Mask */ + +#define DWT_FUNCTION_ACTION_Pos 4U /*!< DWT FUNCTION: ACTION Position */ +#define DWT_FUNCTION_ACTION_Msk (0x1UL << DWT_FUNCTION_ACTION_Pos) /*!< DWT FUNCTION: ACTION Mask */ + +#define DWT_FUNCTION_MATCH_Pos 0U /*!< DWT FUNCTION: MATCH Position */ +#define DWT_FUNCTION_MATCH_Msk (0xFUL /*<< DWT_FUNCTION_MATCH_Pos*/) /*!< DWT FUNCTION: MATCH Mask */ + +/*@}*/ /* end of group CMSIS_DWT */ + + +/** + \ingroup CMSIS_core_register + \defgroup MemSysCtl_Type Memory System Control Registers (IMPLEMENTATION DEFINED) + \brief Type definitions for the Memory System Control Registers (MEMSYSCTL) + @{ + */ + +/** + \brief Structure type to access the Memory System Control Registers (MEMSYSCTL). + */ +typedef struct +{ + __IOM uint32_t MSCR; /*!< Offset: 0x000 (R/W) Memory System Control Register */ + __IOM uint32_t PFCR; /*!< Offset: 0x004 (R/W) Prefetcher Control Register */ + uint32_t RESERVED1[2U]; + __IOM uint32_t ITCMCR; /*!< Offset: 0x010 (R/W) ITCM Control Register */ + __IOM uint32_t DTCMCR; /*!< Offset: 0x014 (R/W) DTCM Control Register */ + __IOM uint32_t PAHBCR; /*!< Offset: 0x018 (R/W) P-AHB Control Register */ + uint32_t RESERVED2[313U]; + __IOM uint32_t ITGU_CTRL; /*!< Offset: 0x500 (R/W) ITGU Control Register */ + __IOM uint32_t ITGU_CFG; /*!< Offset: 0x504 (R/W) ITGU Configuration Register */ + uint32_t RESERVED3[2U]; + __IOM uint32_t ITGU_LUT[16U]; /*!< Offset: 0x510 (R/W) ITGU Look Up Table Register */ + uint32_t RESERVED4[44U]; + __IOM uint32_t DTGU_CTRL; /*!< Offset: 0x600 (R/W) DTGU Control Registers */ + __IOM uint32_t DTGU_CFG; /*!< Offset: 0x604 (R/W) DTGU Configuration Register */ + uint32_t RESERVED5[2U]; + __IOM uint32_t DTGU_LUT[16U]; /*!< Offset: 0x610 (R/W) DTGU Look Up Table Register */ +} MemSysCtl_Type; + +/* MEMSYSCTL Memory System Control Register (MSCR) Register Definitions */ +#define MEMSYSCTL_MSCR_CPWRDN_Pos 17U /*!< MEMSYSCTL MSCR: CPWRDN Position */ +#define MEMSYSCTL_MSCR_CPWRDN_Msk (0x1UL << MEMSYSCTL_MSCR_CPWRDN_Pos) /*!< MEMSYSCTL MSCR: CPWRDN Mask */ + +#define MEMSYSCTL_MSCR_DCCLEAN_Pos 16U /*!< MEMSYSCTL MSCR: DCCLEAN Position */ +#define MEMSYSCTL_MSCR_DCCLEAN_Msk (0x1UL << MEMSYSCTL_MSCR_DCCLEAN_Pos) /*!< MEMSYSCTL MSCR: DCCLEAN Mask */ + +#define MEMSYSCTL_MSCR_ICACTIVE_Pos 13U /*!< MEMSYSCTL MSCR: ICACTIVE Position */ +#define MEMSYSCTL_MSCR_ICACTIVE_Msk (0x1UL << MEMSYSCTL_MSCR_ICACTIVE_Pos) /*!< MEMSYSCTL MSCR: ICACTIVE Mask */ + +#define MEMSYSCTL_MSCR_DCACTIVE_Pos 12U /*!< MEMSYSCTL MSCR: DCACTIVE Position */ +#define MEMSYSCTL_MSCR_DCACTIVE_Msk (0x1UL << MEMSYSCTL_MSCR_DCACTIVE_Pos) /*!< MEMSYSCTL MSCR: DCACTIVE Mask */ + +#define MEMSYSCTL_MSCR_TECCCHKDIS_Pos 4U /*!< MEMSYSCTL MSCR: TECCCHKDIS Position */ +#define MEMSYSCTL_MSCR_TECCCHKDIS_Msk (0x1UL << MEMSYSCTL_MSCR_TECCCHKDIS_Pos) /*!< MEMSYSCTL MSCR: TECCCHKDIS Mask */ + +#define MEMSYSCTL_MSCR_EVECCFAULT_Pos 3U /*!< MEMSYSCTL MSCR: EVECCFAULT Position */ +#define MEMSYSCTL_MSCR_EVECCFAULT_Msk (0x1UL << MEMSYSCTL_MSCR_EVECCFAULT_Pos) /*!< MEMSYSCTL MSCR: EVECCFAULT Mask */ + +#define MEMSYSCTL_MSCR_FORCEWT_Pos 2U /*!< MEMSYSCTL MSCR: FORCEWT Position */ +#define MEMSYSCTL_MSCR_FORCEWT_Msk (0x1UL << MEMSYSCTL_MSCR_FORCEWT_Pos) /*!< MEMSYSCTL MSCR: FORCEWT Mask */ + +#define MEMSYSCTL_MSCR_ECCEN_Pos 1U /*!< MEMSYSCTL MSCR: ECCEN Position */ +#define MEMSYSCTL_MSCR_ECCEN_Msk (0x1UL << MEMSYSCTL_MSCR_ECCEN_Pos) /*!< MEMSYSCTL MSCR: ECCEN Mask */ + +/* MEMSYSCTL Prefetcher Control Register (PFCR) Register Definitions */ +#define MEMSYSCTL_PFCR_MAX_OS_Pos 7U /*!< MEMSYSCTL PFCR: MAX_OS Position */ +#define MEMSYSCTL_PFCR_MAX_OS_Msk (0x7UL << MEMSYSCTL_PFCR_MAX_OS_Pos) /*!< MEMSYSCTL PFCR: MAX_OS Mask */ + +#define MEMSYSCTL_PFCR_MAX_LA_Pos 4U /*!< MEMSYSCTL PFCR: MAX_LA Position */ +#define MEMSYSCTL_PFCR_MAX_LA_Msk (0x7UL << MEMSYSCTL_PFCR_MAX_LA_Pos) /*!< MEMSYSCTL PFCR: MAX_LA Mask */ + +#define MEMSYSCTL_PFCR_MIN_LA_Pos 1U /*!< MEMSYSCTL PFCR: MIN_LA Position */ +#define MEMSYSCTL_PFCR_MIN_LA_Msk (0x7UL << MEMSYSCTL_PFCR_MIN_LA_Pos) /*!< MEMSYSCTL PFCR: MIN_LA Mask */ + +#define MEMSYSCTL_PFCR_ENABLE_Pos 0U /*!< MEMSYSCTL PFCR: ENABLE Position */ +#define MEMSYSCTL_PFCR_ENABLE_Msk (0x1UL /*<< MEMSYSCTL_PFCR_ENABLE_Pos*/) /*!< MEMSYSCTL PFCR: ENABLE Mask */ + +/* MEMSYSCTL ITCM Control Register (ITCMCR) Register Definitions */ +#define MEMSYSCTL_ITCMCR_SZ_Pos 3U /*!< MEMSYSCTL ITCMCR: SZ Position */ +#define MEMSYSCTL_ITCMCR_SZ_Msk (0xFUL << MEMSYSCTL_ITCMCR_SZ_Pos) /*!< MEMSYSCTL ITCMCR: SZ Mask */ + +#define MEMSYSCTL_ITCMCR_EN_Pos 0U /*!< MEMSYSCTL ITCMCR: EN Position */ +#define MEMSYSCTL_ITCMCR_EN_Msk (0x1UL /*<< MEMSYSCTL_ITCMCR_EN_Pos*/) /*!< MEMSYSCTL ITCMCR: EN Mask */ + +/* MEMSYSCTL DTCM Control Register (DTCMCR) Register Definitions */ +#define MEMSYSCTL_DTCMCR_SZ_Pos 3U /*!< MEMSYSCTL DTCMCR: SZ Position */ +#define MEMSYSCTL_DTCMCR_SZ_Msk (0xFUL << MEMSYSCTL_DTCMCR_SZ_Pos) /*!< MEMSYSCTL DTCMCR: SZ Mask */ + +#define MEMSYSCTL_DTCMCR_EN_Pos 0U /*!< MEMSYSCTL DTCMCR: EN Position */ +#define MEMSYSCTL_DTCMCR_EN_Msk (0x1UL /*<< MEMSYSCTL_DTCMCR_EN_Pos*/) /*!< MEMSYSCTL DTCMCR: EN Mask */ + +/* MEMSYSCTL P-AHB Control Register (PAHBCR) Register Definitions */ +#define MEMSYSCTL_PAHBCR_SZ_Pos 1U /*!< MEMSYSCTL PAHBCR: SZ Position */ +#define MEMSYSCTL_PAHBCR_SZ_Msk (0x7UL << MEMSYSCTL_PAHBCR_SZ_Pos) /*!< MEMSYSCTL PAHBCR: SZ Mask */ + +#define MEMSYSCTL_PAHBCR_EN_Pos 0U /*!< MEMSYSCTL PAHBCR: EN Position */ +#define MEMSYSCTL_PAHBCR_EN_Msk (0x1UL /*<< MEMSYSCTL_PAHBCR_EN_Pos*/) /*!< MEMSYSCTL PAHBCR: EN Mask */ + +/* MEMSYSCTL ITGU Control Register (ITGU_CTRL) Register Definitions */ +#define MEMSYSCTL_ITGU_CTRL_DEREN_Pos 1U /*!< MEMSYSCTL ITGU_CTRL: DEREN Position */ +#define MEMSYSCTL_ITGU_CTRL_DEREN_Msk (0x1UL << MEMSYSCTL_ITGU_CTRL_DEREN_Pos) /*!< MEMSYSCTL ITGU_CTRL: DEREN Mask */ + +#define MEMSYSCTL_ITGU_CTRL_DBFEN_Pos 0U /*!< MEMSYSCTL ITGU_CTRL: DBFEN Position */ +#define MEMSYSCTL_ITGU_CTRL_DBFEN_Msk (0x1UL /*<< MEMSYSCTL_ITGU_CTRL_DBFEN_Pos*/) /*!< MEMSYSCTL ITGU_CTRL: DBFEN Mask */ + +/* MEMSYSCTL ITGU Configuration Register (ITGU_CFG) Register Definitions */ +#define MEMSYSCTL_ITGU_CFG_PRESENT_Pos 31U /*!< MEMSYSCTL ITGU_CFG: PRESENT Position */ +#define MEMSYSCTL_ITGU_CFG_PRESENT_Msk (0x1UL << MEMSYSCTL_ITGU_CFG_PRESENT_Pos) /*!< MEMSYSCTL ITGU_CFG: PRESENT Mask */ + +#define MEMSYSCTL_ITGU_CFG_NUMBLKS_Pos 8U /*!< MEMSYSCTL ITGU_CFG: NUMBLKS Position */ +#define MEMSYSCTL_ITGU_CFG_NUMBLKS_Msk (0xFUL << MEMSYSCTL_ITGU_CFG_NUMBLKS_Pos) /*!< MEMSYSCTL ITGU_CFG: NUMBLKS Mask */ + +#define MEMSYSCTL_ITGU_CFG_BLKSZ_Pos 0U /*!< MEMSYSCTL ITGU_CFG: BLKSZ Position */ +#define MEMSYSCTL_ITGU_CFG_BLKSZ_Msk (0xFUL /*<< MEMSYSCTL_ITGU_CFG_BLKSZ_Pos*/) /*!< MEMSYSCTL ITGU_CFG: BLKSZ Mask */ + +/* MEMSYSCTL DTGU Control Registers (DTGU_CTRL) Register Definitions */ +#define MEMSYSCTL_DTGU_CTRL_DEREN_Pos 1U /*!< MEMSYSCTL DTGU_CTRL: DEREN Position */ +#define MEMSYSCTL_DTGU_CTRL_DEREN_Msk (0x1UL << MEMSYSCTL_DTGU_CTRL_DEREN_Pos) /*!< MEMSYSCTL DTGU_CTRL: DEREN Mask */ + +#define MEMSYSCTL_DTGU_CTRL_DBFEN_Pos 0U /*!< MEMSYSCTL DTGU_CTRL: DBFEN Position */ +#define MEMSYSCTL_DTGU_CTRL_DBFEN_Msk (0x1UL /*<< MEMSYSCTL_DTGU_CTRL_DBFEN_Pos*/) /*!< MEMSYSCTL DTGU_CTRL: DBFEN Mask */ + +/* MEMSYSCTL DTGU Configuration Register (DTGU_CFG) Register Definitions */ +#define MEMSYSCTL_DTGU_CFG_PRESENT_Pos 31U /*!< MEMSYSCTL DTGU_CFG: PRESENT Position */ +#define MEMSYSCTL_DTGU_CFG_PRESENT_Msk (0x1UL << MEMSYSCTL_DTGU_CFG_PRESENT_Pos) /*!< MEMSYSCTL DTGU_CFG: PRESENT Mask */ + +#define MEMSYSCTL_DTGU_CFG_NUMBLKS_Pos 8U /*!< MEMSYSCTL DTGU_CFG: NUMBLKS Position */ +#define MEMSYSCTL_DTGU_CFG_NUMBLKS_Msk (0xFUL << MEMSYSCTL_DTGU_CFG_NUMBLKS_Pos) /*!< MEMSYSCTL DTGU_CFG: NUMBLKS Mask */ + +#define MEMSYSCTL_DTGU_CFG_BLKSZ_Pos 0U /*!< MEMSYSCTL DTGU_CFG: BLKSZ Position */ +#define MEMSYSCTL_DTGU_CFG_BLKSZ_Msk (0xFUL /*<< MEMSYSCTL_DTGU_CFG_BLKSZ_Pos*/) /*!< MEMSYSCTL DTGU_CFG: BLKSZ Mask */ + + +/*@}*/ /* end of group MemSysCtl_Type */ + + +/** + \ingroup CMSIS_core_register + \defgroup PwrModCtl_Type Power Mode Control Registers + \brief Type definitions for the Power Mode Control Registers (PWRMODCTL) + @{ + */ + +/** + \brief Structure type to access the Power Mode Control Registers (PWRMODCTL). + */ +typedef struct +{ + __IOM uint32_t CPDLPSTATE; /*!< Offset: 0x000 (R/W) Core Power Domain Low Power State Register */ + __IOM uint32_t DPDLPSTATE; /*!< Offset: 0x004 (R/W) Debug Power Domain Low Power State Register */ +} PwrModCtl_Type; + +/* PWRMODCTL Core Power Domain Low Power State (CPDLPSTATE) Register Definitions */ +#define PWRMODCTL_CPDLPSTATE_RLPSTATE_Pos 8U /*!< PWRMODCTL CPDLPSTATE: RLPSTATE Position */ +#define PWRMODCTL_CPDLPSTATE_RLPSTATE_Msk (0x3UL << PWRMODCTL_CPDLPSTATE_RLPSTATE_Pos) /*!< PWRMODCTL CPDLPSTATE: RLPSTATE Mask */ + +#define PWRMODCTL_CPDLPSTATE_ELPSTATE_Pos 4U /*!< PWRMODCTL CPDLPSTATE: ELPSTATE Position */ +#define PWRMODCTL_CPDLPSTATE_ELPSTATE_Msk (0x3UL << PWRMODCTL_CPDLPSTATE_ELPSTATE_Pos) /*!< PWRMODCTL CPDLPSTATE: ELPSTATE Mask */ + +#define PWRMODCTL_CPDLPSTATE_CLPSTATE_Pos 0U /*!< PWRMODCTL CPDLPSTATE: CLPSTATE Position */ +#define PWRMODCTL_CPDLPSTATE_CLPSTATE_Msk (0x3UL /*<< PWRMODCTL_CPDLPSTATE_CLPSTATE_Pos*/) /*!< PWRMODCTL CPDLPSTATE: CLPSTATE Mask */ + +/* PWRMODCTL Debug Power Domain Low Power State (DPDLPSTATE) Register Definitions */ +#define PWRMODCTL_DPDLPSTATE_DLPSTATE_Pos 0U /*!< PWRMODCTL DPDLPSTATE: DLPSTATE Position */ +#define PWRMODCTL_DPDLPSTATE_DLPSTATE_Msk (0x3UL /*<< PWRMODCTL_DPDLPSTATE_DLPSTATE_Pos*/) /*!< PWRMODCTL DPDLPSTATE: DLPSTATE Mask */ + +/*@}*/ /* end of group PwrModCtl_Type */ + + +/** + \ingroup CMSIS_core_register + \defgroup EWIC_Type External Wakeup Interrupt Controller Registers + \brief Type definitions for the External Wakeup Interrupt Controller Registers (EWIC) + @{ + */ + +/** + \brief Structure type to access the External Wakeup Interrupt Controller Registers (EWIC). + */ +typedef struct +{ + __OM uint32_t EVENTSPR; /*!< Offset: 0x000 ( /W) Event Set Pending Register */ + uint32_t RESERVED0[31U]; + __IM uint32_t EVENTMASKA; /*!< Offset: 0x080 (R/W) Event Mask A Register */ + __IM uint32_t EVENTMASK[15]; /*!< Offset: 0x084 (R/W) Event Mask Register */ +} EWIC_Type; + +/* EWIC External Wakeup Interrupt Controller (EVENTSPR) Register Definitions */ +#define EWIC_EVENTSPR_EDBGREQ_Pos 2U /*!< EWIC EVENTSPR: EDBGREQ Position */ +#define EWIC_EVENTSPR_EDBGREQ_Msk (0x1UL << EWIC_EVENTSPR_EDBGREQ_Pos) /*!< EWIC EVENTSPR: EDBGREQ Mask */ + +#define EWIC_EVENTSPR_NMI_Pos 1U /*!< EWIC EVENTSPR: NMI Position */ +#define EWIC_EVENTSPR_NMI_Msk (0x1UL << EWIC_EVENTSPR_NMI_Pos) /*!< EWIC EVENTSPR: NMI Mask */ + +#define EWIC_EVENTSPR_EVENT_Pos 0U /*!< EWIC EVENTSPR: EVENT Position */ +#define EWIC_EVENTSPR_EVENT_Msk (0x1UL /*<< EWIC_EVENTSPR_EVENT_Pos*/) /*!< EWIC EVENTSPR: EVENT Mask */ + +/* EWIC External Wakeup Interrupt Controller (EVENTMASKA) Register Definitions */ +#define EWIC_EVENTMASKA_EDBGREQ_Pos 2U /*!< EWIC EVENTMASKA: EDBGREQ Position */ +#define EWIC_EVENTMASKA_EDBGREQ_Msk (0x1UL << EWIC_EVENTMASKA_EDBGREQ_Pos) /*!< EWIC EVENTMASKA: EDBGREQ Mask */ + +#define EWIC_EVENTMASKA_NMI_Pos 1U /*!< EWIC EVENTMASKA: NMI Position */ +#define EWIC_EVENTMASKA_NMI_Msk (0x1UL << EWIC_EVENTMASKA_NMI_Pos) /*!< EWIC EVENTMASKA: NMI Mask */ + +#define EWIC_EVENTMASKA_EVENT_Pos 0U /*!< EWIC EVENTMASKA: EVENT Position */ +#define EWIC_EVENTMASKA_EVENT_Msk (0x1UL /*<< EWIC_EVENTMASKA_EVENT_Pos*/) /*!< EWIC EVENTMASKA: EVENT Mask */ + +/* EWIC External Wakeup Interrupt Controller (EVENTMASK) Register Definitions */ +#define EWIC_EVENTMASK_IRQ_Pos 0U /*!< EWIC EVENTMASKA: IRQ Position */ +#define EWIC_EVENTMASK_IRQ_Msk (0xFFFFFFFFUL /*<< EWIC_EVENTMASKA_IRQ_Pos*/) /*!< EWIC EVENTMASKA: IRQ Mask */ + +/*@}*/ /* end of group EWIC_Type */ + + +/** + \ingroup CMSIS_core_register + \defgroup ErrBnk_Type Error Banking Registers (IMPLEMENTATION DEFINED) + \brief Type definitions for the Error Banking Registers (ERRBNK) + @{ + */ + +/** + \brief Structure type to access the Error Banking Registers (ERRBNK). + */ +typedef struct +{ + __IOM uint32_t IEBR0; /*!< Offset: 0x000 (R/W) Instruction Cache Error Bank Register 0 */ + __IOM uint32_t IEBR1; /*!< Offset: 0x004 (R/W) Instruction Cache Error Bank Register 1 */ + uint32_t RESERVED0[2U]; + __IOM uint32_t DEBR0; /*!< Offset: 0x010 (R/W) Data Cache Error Bank Register 0 */ + __IOM uint32_t DEBR1; /*!< Offset: 0x014 (R/W) Data Cache Error Bank Register 1 */ + uint32_t RESERVED1[2U]; + __IOM uint32_t TEBR0; /*!< Offset: 0x020 (R/W) TCM Error Bank Register 0 */ + uint32_t RESERVED2[1U]; + __IOM uint32_t TEBR1; /*!< Offset: 0x028 (R/W) TCM Error Bank Register 1 */ +} ErrBnk_Type; + +/* ERRBNK Instruction Cache Error Bank Register 0 (IEBR0) Register Definitions */ +#define ERRBNK_IEBR0_SWDEF_Pos 30U /*!< ERRBNK IEBR0: SWDEF Position */ +#define ERRBNK_IEBR0_SWDEF_Msk (0x3UL << ERRBNK_IEBR0_SWDEF_Pos) /*!< ERRBNK IEBR0: SWDEF Mask */ + +#define ERRBNK_IEBR0_BANK_Pos 16U /*!< ERRBNK IEBR0: BANK Position */ +#define ERRBNK_IEBR0_BANK_Msk (0x1UL << ERRBNK_IEBR0_BANK_Pos) /*!< ERRBNK IEBR0: BANK Mask */ + +#define ERRBNK_IEBR0_LOCATION_Pos 2U /*!< ERRBNK IEBR0: LOCATION Position */ +#define ERRBNK_IEBR0_LOCATION_Msk (0x3FFFUL << ERRBNK_IEBR0_LOCATION_Pos) /*!< ERRBNK IEBR0: LOCATION Mask */ + +#define ERRBNK_IEBR0_LOCKED_Pos 1U /*!< ERRBNK IEBR0: LOCKED Position */ +#define ERRBNK_IEBR0_LOCKED_Msk (0x1UL << ERRBNK_IEBR0_LOCKED_Pos) /*!< ERRBNK IEBR0: LOCKED Mask */ + +#define ERRBNK_IEBR0_VALID_Pos 0U /*!< ERRBNK IEBR0: VALID Position */ +#define ERRBNK_IEBR0_VALID_Msk (0x1UL << /*ERRBNK_IEBR0_VALID_Pos*/) /*!< ERRBNK IEBR0: VALID Mask */ + +/* ERRBNK Instruction Cache Error Bank Register 1 (IEBR1) Register Definitions */ +#define ERRBNK_IEBR1_SWDEF_Pos 30U /*!< ERRBNK IEBR1: SWDEF Position */ +#define ERRBNK_IEBR1_SWDEF_Msk (0x3UL << ERRBNK_IEBR1_SWDEF_Pos) /*!< ERRBNK IEBR1: SWDEF Mask */ + +#define ERRBNK_IEBR1_BANK_Pos 16U /*!< ERRBNK IEBR1: BANK Position */ +#define ERRBNK_IEBR1_BANK_Msk (0x1UL << ERRBNK_IEBR1_BANK_Pos) /*!< ERRBNK IEBR1: BANK Mask */ + +#define ERRBNK_IEBR1_LOCATION_Pos 2U /*!< ERRBNK IEBR1: LOCATION Position */ +#define ERRBNK_IEBR1_LOCATION_Msk (0x3FFFUL << ERRBNK_IEBR1_LOCATION_Pos) /*!< ERRBNK IEBR1: LOCATION Mask */ + +#define ERRBNK_IEBR1_LOCKED_Pos 1U /*!< ERRBNK IEBR1: LOCKED Position */ +#define ERRBNK_IEBR1_LOCKED_Msk (0x1UL << ERRBNK_IEBR1_LOCKED_Pos) /*!< ERRBNK IEBR1: LOCKED Mask */ + +#define ERRBNK_IEBR1_VALID_Pos 0U /*!< ERRBNK IEBR1: VALID Position */ +#define ERRBNK_IEBR1_VALID_Msk (0x1UL << /*ERRBNK_IEBR1_VALID_Pos*/) /*!< ERRBNK IEBR1: VALID Mask */ + +/* ERRBNK Data Cache Error Bank Register 0 (DEBR0) Register Definitions */ +#define ERRBNK_DEBR0_SWDEF_Pos 30U /*!< ERRBNK DEBR0: SWDEF Position */ +#define ERRBNK_DEBR0_SWDEF_Msk (0x3UL << ERRBNK_DEBR0_SWDEF_Pos) /*!< ERRBNK DEBR0: SWDEF Mask */ + +#define ERRBNK_DEBR0_TYPE_Pos 17U /*!< ERRBNK DEBR0: TYPE Position */ +#define ERRBNK_DEBR0_TYPE_Msk (0x1UL << ERRBNK_DEBR0_TYPE_Pos) /*!< ERRBNK DEBR0: TYPE Mask */ + +#define ERRBNK_DEBR0_BANK_Pos 16U /*!< ERRBNK DEBR0: BANK Position */ +#define ERRBNK_DEBR0_BANK_Msk (0x1UL << ERRBNK_DEBR0_BANK_Pos) /*!< ERRBNK DEBR0: BANK Mask */ + +#define ERRBNK_DEBR0_LOCATION_Pos 2U /*!< ERRBNK DEBR0: LOCATION Position */ +#define ERRBNK_DEBR0_LOCATION_Msk (0x3FFFUL << ERRBNK_DEBR0_LOCATION_Pos) /*!< ERRBNK DEBR0: LOCATION Mask */ + +#define ERRBNK_DEBR0_LOCKED_Pos 1U /*!< ERRBNK DEBR0: LOCKED Position */ +#define ERRBNK_DEBR0_LOCKED_Msk (0x1UL << ERRBNK_DEBR0_LOCKED_Pos) /*!< ERRBNK DEBR0: LOCKED Mask */ + +#define ERRBNK_DEBR0_VALID_Pos 0U /*!< ERRBNK DEBR0: VALID Position */ +#define ERRBNK_DEBR0_VALID_Msk (0x1UL << /*ERRBNK_DEBR0_VALID_Pos*/) /*!< ERRBNK DEBR0: VALID Mask */ + +/* ERRBNK Data Cache Error Bank Register 1 (DEBR1) Register Definitions */ +#define ERRBNK_DEBR1_SWDEF_Pos 30U /*!< ERRBNK DEBR1: SWDEF Position */ +#define ERRBNK_DEBR1_SWDEF_Msk (0x3UL << ERRBNK_DEBR1_SWDEF_Pos) /*!< ERRBNK DEBR1: SWDEF Mask */ + +#define ERRBNK_DEBR1_TYPE_Pos 17U /*!< ERRBNK DEBR1: TYPE Position */ +#define ERRBNK_DEBR1_TYPE_Msk (0x1UL << ERRBNK_DEBR1_TYPE_Pos) /*!< ERRBNK DEBR1: TYPE Mask */ + +#define ERRBNK_DEBR1_BANK_Pos 16U /*!< ERRBNK DEBR1: BANK Position */ +#define ERRBNK_DEBR1_BANK_Msk (0x1UL << ERRBNK_DEBR1_BANK_Pos) /*!< ERRBNK DEBR1: BANK Mask */ + +#define ERRBNK_DEBR1_LOCATION_Pos 2U /*!< ERRBNK DEBR1: LOCATION Position */ +#define ERRBNK_DEBR1_LOCATION_Msk (0x3FFFUL << ERRBNK_DEBR1_LOCATION_Pos) /*!< ERRBNK DEBR1: LOCATION Mask */ + +#define ERRBNK_DEBR1_LOCKED_Pos 1U /*!< ERRBNK DEBR1: LOCKED Position */ +#define ERRBNK_DEBR1_LOCKED_Msk (0x1UL << ERRBNK_DEBR1_LOCKED_Pos) /*!< ERRBNK DEBR1: LOCKED Mask */ + +#define ERRBNK_DEBR1_VALID_Pos 0U /*!< ERRBNK DEBR1: VALID Position */ +#define ERRBNK_DEBR1_VALID_Msk (0x1UL << /*ERRBNK_DEBR1_VALID_Pos*/) /*!< ERRBNK DEBR1: VALID Mask */ + +/* ERRBNK TCM Error Bank Register 0 (TEBR0) Register Definitions */ +#define ERRBNK_TEBR0_SWDEF_Pos 30U /*!< ERRBNK TEBR0: SWDEF Position */ +#define ERRBNK_TEBR0_SWDEF_Msk (0x3UL << ERRBNK_TEBR0_SWDEF_Pos) /*!< ERRBNK TEBR0: SWDEF Mask */ + +#define ERRBNK_TEBR0_POISON_Pos 28U /*!< ERRBNK TEBR0: POISON Position */ +#define ERRBNK_TEBR0_POISON_Msk (0x1UL << ERRBNK_TEBR0_POISON_Pos) /*!< ERRBNK TEBR0: POISON Mask */ + +#define ERRBNK_TEBR0_TYPE_Pos 27U /*!< ERRBNK TEBR0: TYPE Position */ +#define ERRBNK_TEBR0_TYPE_Msk (0x1UL << ERRBNK_TEBR0_TYPE_Pos) /*!< ERRBNK TEBR0: TYPE Mask */ + +#define ERRBNK_TEBR0_BANK_Pos 24U /*!< ERRBNK TEBR0: BANK Position */ +#define ERRBNK_TEBR0_BANK_Msk (0x3UL << ERRBNK_TEBR0_BANK_Pos) /*!< ERRBNK TEBR0: BANK Mask */ + +#define ERRBNK_TEBR0_LOCATION_Pos 2U /*!< ERRBNK TEBR0: LOCATION Position */ +#define ERRBNK_TEBR0_LOCATION_Msk (0x3FFFFFUL << ERRBNK_TEBR0_LOCATION_Pos) /*!< ERRBNK TEBR0: LOCATION Mask */ + +#define ERRBNK_TEBR0_LOCKED_Pos 1U /*!< ERRBNK TEBR0: LOCKED Position */ +#define ERRBNK_TEBR0_LOCKED_Msk (0x1UL << ERRBNK_TEBR0_LOCKED_Pos) /*!< ERRBNK TEBR0: LOCKED Mask */ + +#define ERRBNK_TEBR0_VALID_Pos 0U /*!< ERRBNK TEBR0: VALID Position */ +#define ERRBNK_TEBR0_VALID_Msk (0x1UL << /*ERRBNK_TEBR0_VALID_Pos*/) /*!< ERRBNK TEBR0: VALID Mask */ + +/* ERRBNK TCM Error Bank Register 1 (TEBR1) Register Definitions */ +#define ERRBNK_TEBR1_SWDEF_Pos 30U /*!< ERRBNK TEBR1: SWDEF Position */ +#define ERRBNK_TEBR1_SWDEF_Msk (0x3UL << ERRBNK_TEBR1_SWDEF_Pos) /*!< ERRBNK TEBR1: SWDEF Mask */ + +#define ERRBNK_TEBR1_POISON_Pos 28U /*!< ERRBNK TEBR1: POISON Position */ +#define ERRBNK_TEBR1_POISON_Msk (0x1UL << ERRBNK_TEBR1_POISON_Pos) /*!< ERRBNK TEBR1: POISON Mask */ + +#define ERRBNK_TEBR1_TYPE_Pos 27U /*!< ERRBNK TEBR1: TYPE Position */ +#define ERRBNK_TEBR1_TYPE_Msk (0x1UL << ERRBNK_TEBR1_TYPE_Pos) /*!< ERRBNK TEBR1: TYPE Mask */ + +#define ERRBNK_TEBR1_BANK_Pos 24U /*!< ERRBNK TEBR1: BANK Position */ +#define ERRBNK_TEBR1_BANK_Msk (0x3UL << ERRBNK_TEBR1_BANK_Pos) /*!< ERRBNK TEBR1: BANK Mask */ + +#define ERRBNK_TEBR1_LOCATION_Pos 2U /*!< ERRBNK TEBR1: LOCATION Position */ +#define ERRBNK_TEBR1_LOCATION_Msk (0x3FFFFFUL << ERRBNK_TEBR1_LOCATION_Pos) /*!< ERRBNK TEBR1: LOCATION Mask */ + +#define ERRBNK_TEBR1_LOCKED_Pos 1U /*!< ERRBNK TEBR1: LOCKED Position */ +#define ERRBNK_TEBR1_LOCKED_Msk (0x1UL << ERRBNK_TEBR1_LOCKED_Pos) /*!< ERRBNK TEBR1: LOCKED Mask */ + +#define ERRBNK_TEBR1_VALID_Pos 0U /*!< ERRBNK TEBR1: VALID Position */ +#define ERRBNK_TEBR1_VALID_Msk (0x1UL << /*ERRBNK_TEBR1_VALID_Pos*/) /*!< ERRBNK TEBR1: VALID Mask */ + +/*@}*/ /* end of group ErrBnk_Type */ + + +/** + \ingroup CMSIS_core_register + \defgroup PrcCfgInf_Type Processor Configuration Information Registers (IMPLEMENTATION DEFINED) + \brief Type definitions for the Processor Configuration Information Registerss (PRCCFGINF) + @{ + */ + +/** + \brief Structure type to access the Processor Configuration Information Registerss (PRCCFGINF). + */ +typedef struct +{ + __OM uint32_t CFGINFOSEL; /*!< Offset: 0x000 ( /W) Processor Configuration Information Selection Register */ + __IM uint32_t CFGINFORD; /*!< Offset: 0x004 (R/ ) Processor Configuration Information Read Data Register */ +} PrcCfgInf_Type; + +/* PRCCFGINF Processor Configuration Information Selection Register (CFGINFOSEL) Definitions */ + +/* PRCCFGINF Processor Configuration Information Read Data Register (CFGINFORD) Definitions */ + +/*@}*/ /* end of group PrcCfgInf_Type */ + + +/** + \ingroup CMSIS_core_register + \defgroup STL_Type Software Test Library Observation Registers + \brief Type definitions for the Software Test Library Observation Registerss (STL) + @{ + */ + +/** + \brief Structure type to access the Software Test Library Observation Registerss (STL). + */ +typedef struct +{ + __IM uint32_t STLNVICPENDOR; /*!< Offset: 0x000 (R/ ) NVIC Pending Priority Tree Register */ + __IM uint32_t STLNVICACTVOR; /*!< Offset: 0x004 (R/ ) NVIC Active Priority Tree Register */ + uint32_t RESERVED0[2U]; + __OM uint32_t STLIDMPUSR; /*!< Offset: 0x010 ( /W) MPU Sanple Register */ + __IM uint32_t STLIMPUOR; /*!< Offset: 0x014 (R/ ) MPU Region Hit Register */ + __IM uint32_t STLD0MPUOR; /*!< Offset: 0x018 (R/ ) MPU Memory Attributes Register 0 */ + __IM uint32_t STLD1MPUOR; /*!< Offset: 0x01C (R/ ) MPU Memory Attributes Register 1 */ + +} STL_Type; + +/* STL Software Test Library Observation Register (STLNVICPENDOR) Definitions */ +#define STL_STLNVICPENDOR_VALID_Pos 18U /*!< STL STLNVICPENDOR: VALID Position */ +#define STL_STLNVICPENDOR_VALID_Msk (0x1UL << STL_STLNVICPENDOR_VALID_Pos) /*!< STL STLNVICPENDOR: VALID Mask */ + +#define STL_STLNVICPENDOR_TARGET_Pos 17U /*!< STL STLNVICPENDOR: TARGET Position */ +#define STL_STLNVICPENDOR_TARGET_Msk (0x1UL << STL_STLNVICPENDOR_TARGET_Pos) /*!< STL STLNVICPENDOR: TARGET Mask */ + +#define STL_STLNVICPENDOR_PRIORITY_Pos 9U /*!< STL STLNVICPENDOR: PRIORITY Position */ +#define STL_STLNVICPENDOR_PRIORITY_Msk (0xFFUL << STL_STLNVICPENDOR_PRIORITY_Pos) /*!< STL STLNVICPENDOR: PRIORITY Mask */ + +#define STL_STLNVICPENDOR_INTNUM_Pos 0U /*!< STL STLNVICPENDOR: INTNUM Position */ +#define STL_STLNVICPENDOR_INTNUM_Msk (0x1FFUL /*<< STL_STLNVICPENDOR_INTNUM_Pos*/) /*!< STL STLNVICPENDOR: INTNUM Mask */ + +/* STL Software Test Library Observation Register (STLNVICACTVOR) Definitions */ +#define STL_STLNVICACTVOR_VALID_Pos 18U /*!< STL STLNVICACTVOR: VALID Position */ +#define STL_STLNVICACTVOR_VALID_Msk (0x1UL << STL_STLNVICACTVOR_VALID_Pos) /*!< STL STLNVICACTVOR: VALID Mask */ + +#define STL_STLNVICACTVOR_TARGET_Pos 17U /*!< STL STLNVICACTVOR: TARGET Position */ +#define STL_STLNVICACTVOR_TARGET_Msk (0x1UL << STL_STLNVICACTVOR_TARGET_Pos) /*!< STL STLNVICACTVOR: TARGET Mask */ + +#define STL_STLNVICACTVOR_PRIORITY_Pos 9U /*!< STL STLNVICACTVOR: PRIORITY Position */ +#define STL_STLNVICACTVOR_PRIORITY_Msk (0xFFUL << STL_STLNVICACTVOR_PRIORITY_Pos) /*!< STL STLNVICACTVOR: PRIORITY Mask */ + +#define STL_STLNVICACTVOR_INTNUM_Pos 0U /*!< STL STLNVICACTVOR: INTNUM Position */ +#define STL_STLNVICACTVOR_INTNUM_Msk (0x1FFUL /*<< STL_STLNVICACTVOR_INTNUM_Pos*/) /*!< STL STLNVICACTVOR: INTNUM Mask */ + +/* STL Software Test Library Observation Register (STLIDMPUSR) Definitions */ +#define STL_STLIDMPUSR_ADDR_Pos 5U /*!< STL STLIDMPUSR: ADDR Position */ +#define STL_STLIDMPUSR_ADDR_Msk (0x7FFFFFFUL << STL_STLIDMPUSR_ADDR_Pos) /*!< STL STLIDMPUSR: ADDR Mask */ + +#define STL_STLIDMPUSR_INSTR_Pos 2U /*!< STL STLIDMPUSR: INSTR Position */ +#define STL_STLIDMPUSR_INSTR_Msk (0x1UL << STL_STLIDMPUSR_INSTR_Pos) /*!< STL STLIDMPUSR: INSTR Mask */ + +#define STL_STLIDMPUSR_DATA_Pos 1U /*!< STL STLIDMPUSR: DATA Position */ +#define STL_STLIDMPUSR_DATA_Msk (0x1UL << STL_STLIDMPUSR_DATA_Pos) /*!< STL STLIDMPUSR: DATA Mask */ + +/* STL Software Test Library Observation Register (STLIMPUOR) Definitions */ +#define STL_STLIMPUOR_HITREGION_Pos 9U /*!< STL STLIMPUOR: HITREGION Position */ +#define STL_STLIMPUOR_HITREGION_Msk (0xFFUL << STL_STLIMPUOR_HITREGION_Pos) /*!< STL STLIMPUOR: HITREGION Mask */ + +#define STL_STLIMPUOR_ATTR_Pos 0U /*!< STL STLIMPUOR: ATTR Position */ +#define STL_STLIMPUOR_ATTR_Msk (0x1FFUL /*<< STL_STLIMPUOR_ATTR_Pos*/) /*!< STL STLIMPUOR: ATTR Mask */ + +/* STL Software Test Library Observation Register (STLD0MPUOR) Definitions */ +#define STL_STLD0MPUOR_HITREGION_Pos 9U /*!< STL STLD0MPUOR: HITREGION Position */ +#define STL_STLD0MPUOR_HITREGION_Msk (0xFFUL << STL_STLD0MPUOR_HITREGION_Pos) /*!< STL STLD0MPUOR: HITREGION Mask */ + +#define STL_STLD0MPUOR_ATTR_Pos 0U /*!< STL STLD0MPUOR: ATTR Position */ +#define STL_STLD0MPUOR_ATTR_Msk (0x1FFUL /*<< STL_STLD0MPUOR_ATTR_Pos*/) /*!< STL STLD0MPUOR: ATTR Mask */ + +/* STL Software Test Library Observation Register (STLD1MPUOR) Definitions */ +#define STL_STLD1MPUOR_HITREGION_Pos 9U /*!< STL STLD1MPUOR: HITREGION Position */ +#define STL_STLD1MPUOR_HITREGION_Msk (0xFFUL << STL_STLD1MPUOR_HITREGION_Pos) /*!< STL STLD1MPUOR: HITREGION Mask */ + +#define STL_STLD1MPUOR_ATTR_Pos 0U /*!< STL STLD1MPUOR: ATTR Position */ +#define STL_STLD1MPUOR_ATTR_Msk (0x1FFUL /*<< STL_STLD1MPUOR_ATTR_Pos*/) /*!< STL STLD1MPUOR: ATTR Mask */ + +/*@}*/ /* end of group STL_Type */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_TPI Trace Port Interface (TPI) + \brief Type definitions for the Trace Port Interface (TPI) + @{ + */ + +/** + \brief Structure type to access the Trace Port Interface Register (TPI). + */ +typedef struct +{ + __IM uint32_t SSPSR; /*!< Offset: 0x000 (R/ ) Supported Parallel Port Sizes Register */ + __IOM uint32_t CSPSR; /*!< Offset: 0x004 (R/W) Current Parallel Port Sizes Register */ + uint32_t RESERVED0[2U]; + __IOM uint32_t ACPR; /*!< Offset: 0x010 (R/W) Asynchronous Clock Prescaler Register */ + uint32_t RESERVED1[55U]; + __IOM uint32_t SPPR; /*!< Offset: 0x0F0 (R/W) Selected Pin Protocol Register */ + uint32_t RESERVED2[131U]; + __IM uint32_t FFSR; /*!< Offset: 0x300 (R/ ) Formatter and Flush Status Register */ + __IOM uint32_t FFCR; /*!< Offset: 0x304 (R/W) Formatter and Flush Control Register */ + __IOM uint32_t PSCR; /*!< Offset: 0x308 (R/W) Periodic Synchronization Control Register */ + uint32_t RESERVED3[809U]; + __OM uint32_t LAR; /*!< Offset: 0xFB0 ( /W) Software Lock Access Register */ + __IM uint32_t LSR; /*!< Offset: 0xFB4 (R/ ) Software Lock Status Register */ + uint32_t RESERVED4[4U]; + __IM uint32_t TYPE; /*!< Offset: 0xFC8 (R/ ) Device Identifier Register */ + __IM uint32_t DEVTYPE; /*!< Offset: 0xFCC (R/ ) Device Type Register */ +} TPI_Type; + +/* TPI Asynchronous Clock Prescaler Register Definitions */ +#define TPI_ACPR_SWOSCALER_Pos 0U /*!< TPI ACPR: SWOSCALER Position */ +#define TPI_ACPR_SWOSCALER_Msk (0xFFFFUL /*<< TPI_ACPR_SWOSCALER_Pos*/) /*!< TPI ACPR: SWOSCALER Mask */ + +/* TPI Selected Pin Protocol Register Definitions */ +#define TPI_SPPR_TXMODE_Pos 0U /*!< TPI SPPR: TXMODE Position */ +#define TPI_SPPR_TXMODE_Msk (0x3UL /*<< TPI_SPPR_TXMODE_Pos*/) /*!< TPI SPPR: TXMODE Mask */ + +/* TPI Formatter and Flush Status Register Definitions */ +#define TPI_FFSR_FtNonStop_Pos 3U /*!< TPI FFSR: FtNonStop Position */ +#define TPI_FFSR_FtNonStop_Msk (0x1UL << TPI_FFSR_FtNonStop_Pos) /*!< TPI FFSR: FtNonStop Mask */ + +#define TPI_FFSR_TCPresent_Pos 2U /*!< TPI FFSR: TCPresent Position */ +#define TPI_FFSR_TCPresent_Msk (0x1UL << TPI_FFSR_TCPresent_Pos) /*!< TPI FFSR: TCPresent Mask */ + +#define TPI_FFSR_FtStopped_Pos 1U /*!< TPI FFSR: FtStopped Position */ +#define TPI_FFSR_FtStopped_Msk (0x1UL << TPI_FFSR_FtStopped_Pos) /*!< TPI FFSR: FtStopped Mask */ + +#define TPI_FFSR_FlInProg_Pos 0U /*!< TPI FFSR: FlInProg Position */ +#define TPI_FFSR_FlInProg_Msk (0x1UL /*<< TPI_FFSR_FlInProg_Pos*/) /*!< TPI FFSR: FlInProg Mask */ + +/* TPI Formatter and Flush Control Register Definitions */ +#define TPI_FFCR_TrigIn_Pos 8U /*!< TPI FFCR: TrigIn Position */ +#define TPI_FFCR_TrigIn_Msk (0x1UL << TPI_FFCR_TrigIn_Pos) /*!< TPI FFCR: TrigIn Mask */ + +#define TPI_FFCR_FOnMan_Pos 6U /*!< TPI FFCR: FOnMan Position */ +#define TPI_FFCR_FOnMan_Msk (0x1UL << TPI_FFCR_FOnMan_Pos) /*!< TPI FFCR: FOnMan Mask */ + +#define TPI_FFCR_EnFmt_Pos 0U /*!< TPI FFCR: EnFmt Position */ +#define TPI_FFCR_EnFmt_Msk (0x3UL << /*TPI_FFCR_EnFmt_Pos*/) /*!< TPI FFCR: EnFmt Mask */ + +/* TPI Periodic Synchronization Control Register Definitions */ +#define TPI_PSCR_PSCount_Pos 0U /*!< TPI PSCR: PSCount Position */ +#define TPI_PSCR_PSCount_Msk (0x1FUL /*<< TPI_PSCR_PSCount_Pos*/) /*!< TPI PSCR: TPSCount Mask */ + +/* TPI Software Lock Status Register Definitions */ +#define TPI_LSR_nTT_Pos 1U /*!< TPI LSR: Not thirty-two bit. Position */ +#define TPI_LSR_nTT_Msk (0x1UL << TPI_LSR_nTT_Pos) /*!< TPI LSR: Not thirty-two bit. Mask */ + +#define TPI_LSR_SLK_Pos 1U /*!< TPI LSR: Software Lock status Position */ +#define TPI_LSR_SLK_Msk (0x1UL << TPI_LSR_SLK_Pos) /*!< TPI LSR: Software Lock status Mask */ + +#define TPI_LSR_SLI_Pos 0U /*!< TPI LSR: Software Lock implemented Position */ +#define TPI_LSR_SLI_Msk (0x1UL /*<< TPI_LSR_SLI_Pos*/) /*!< TPI LSR: Software Lock implemented Mask */ + +/* TPI DEVID Register Definitions */ +#define TPI_DEVID_NRZVALID_Pos 11U /*!< TPI DEVID: NRZVALID Position */ +#define TPI_DEVID_NRZVALID_Msk (0x1UL << TPI_DEVID_NRZVALID_Pos) /*!< TPI DEVID: NRZVALID Mask */ + +#define TPI_DEVID_MANCVALID_Pos 10U /*!< TPI DEVID: MANCVALID Position */ +#define TPI_DEVID_MANCVALID_Msk (0x1UL << TPI_DEVID_MANCVALID_Pos) /*!< TPI DEVID: MANCVALID Mask */ + +#define TPI_DEVID_PTINVALID_Pos 9U /*!< TPI DEVID: PTINVALID Position */ +#define TPI_DEVID_PTINVALID_Msk (0x1UL << TPI_DEVID_PTINVALID_Pos) /*!< TPI DEVID: PTINVALID Mask */ + +#define TPI_DEVID_FIFOSZ_Pos 6U /*!< TPI DEVID: FIFO depth Position */ +#define TPI_DEVID_FIFOSZ_Msk (0x7UL << TPI_DEVID_FIFOSZ_Pos) /*!< TPI DEVID: FIFO depth Mask */ + +/* TPI DEVTYPE Register Definitions */ +#define TPI_DEVTYPE_SubType_Pos 4U /*!< TPI DEVTYPE: SubType Position */ +#define TPI_DEVTYPE_SubType_Msk (0xFUL /*<< TPI_DEVTYPE_SubType_Pos*/) /*!< TPI DEVTYPE: SubType Mask */ + +#define TPI_DEVTYPE_MajorType_Pos 0U /*!< TPI DEVTYPE: MajorType Position */ +#define TPI_DEVTYPE_MajorType_Msk (0xFUL << TPI_DEVTYPE_MajorType_Pos) /*!< TPI DEVTYPE: MajorType Mask */ + +/*@}*/ /* end of group CMSIS_TPI */ + +#if defined (__PMU_PRESENT) && (__PMU_PRESENT == 1U) +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_PMU Performance Monitoring Unit (PMU) + \brief Type definitions for the Performance Monitoring Unit (PMU) + @{ + */ + +/** + \brief Structure type to access the Performance Monitoring Unit (PMU). + */ +typedef struct +{ + __IOM uint32_t EVCNTR[__PMU_NUM_EVENTCNT]; /*!< Offset: 0x0 (R/W) PMU Event Counter Registers */ +#if __PMU_NUM_EVENTCNT<31 + uint32_t RESERVED0[31U-__PMU_NUM_EVENTCNT]; +#endif + __IOM uint32_t CCNTR; /*!< Offset: 0x7C (R/W) PMU Cycle Counter Register */ + uint32_t RESERVED1[224]; + __IOM uint32_t EVTYPER[__PMU_NUM_EVENTCNT]; /*!< Offset: 0x400 (R/W) PMU Event Type and Filter Registers */ +#if __PMU_NUM_EVENTCNT<31 + uint32_t RESERVED2[31U-__PMU_NUM_EVENTCNT]; +#endif + __IOM uint32_t CCFILTR; /*!< Offset: 0x47C (R/W) PMU Cycle Counter Filter Register */ + uint32_t RESERVED3[480]; + __IOM uint32_t CNTENSET; /*!< Offset: 0xC00 (R/W) PMU Count Enable Set Register */ + uint32_t RESERVED4[7]; + __IOM uint32_t CNTENCLR; /*!< Offset: 0xC20 (R/W) PMU Count Enable Clear Register */ + uint32_t RESERVED5[7]; + __IOM uint32_t INTENSET; /*!< Offset: 0xC40 (R/W) PMU Interrupt Enable Set Register */ + uint32_t RESERVED6[7]; + __IOM uint32_t INTENCLR; /*!< Offset: 0xC60 (R/W) PMU Interrupt Enable Clear Register */ + uint32_t RESERVED7[7]; + __IOM uint32_t OVSCLR; /*!< Offset: 0xC80 (R/W) PMU Overflow Flag Status Clear Register */ + uint32_t RESERVED8[7]; + __IOM uint32_t SWINC; /*!< Offset: 0xCA0 (R/W) PMU Software Increment Register */ + uint32_t RESERVED9[7]; + __IOM uint32_t OVSSET; /*!< Offset: 0xCC0 (R/W) PMU Overflow Flag Status Set Register */ + uint32_t RESERVED10[79]; + __IOM uint32_t TYPE; /*!< Offset: 0xE00 (R/W) PMU Type Register */ + __IOM uint32_t CTRL; /*!< Offset: 0xE04 (R/W) PMU Control Register */ + uint32_t RESERVED11[108]; + __IOM uint32_t AUTHSTATUS; /*!< Offset: 0xFB8 (R/W) PMU Authentication Status Register */ + __IOM uint32_t DEVARCH; /*!< Offset: 0xFBC (R/W) PMU Device Architecture Register */ + uint32_t RESERVED12[3]; + __IOM uint32_t DEVTYPE; /*!< Offset: 0xFCC (R/W) PMU Device Type Register */ + __IOM uint32_t PIDR4; /*!< Offset: 0xFD0 (R/W) PMU Peripheral Identification Register 4 */ + uint32_t RESERVED13[3]; + __IOM uint32_t PIDR0; /*!< Offset: 0xFE0 (R/W) PMU Peripheral Identification Register 0 */ + __IOM uint32_t PIDR1; /*!< Offset: 0xFE4 (R/W) PMU Peripheral Identification Register 1 */ + __IOM uint32_t PIDR2; /*!< Offset: 0xFE8 (R/W) PMU Peripheral Identification Register 2 */ + __IOM uint32_t PIDR3; /*!< Offset: 0xFEC (R/W) PMU Peripheral Identification Register 3 */ + __IOM uint32_t CIDR0; /*!< Offset: 0xFF0 (R/W) PMU Component Identification Register 0 */ + __IOM uint32_t CIDR1; /*!< Offset: 0xFF4 (R/W) PMU Component Identification Register 1 */ + __IOM uint32_t CIDR2; /*!< Offset: 0xFF8 (R/W) PMU Component Identification Register 2 */ + __IOM uint32_t CIDR3; /*!< Offset: 0xFFC (R/W) PMU Component Identification Register 3 */ +} PMU_Type; + +/** \brief PMU Event Counter Registers (0-30) Definitions */ + +#define PMU_EVCNTR_CNT_Pos 0U /*!< PMU EVCNTR: Counter Position */ +#define PMU_EVCNTR_CNT_Msk (0xFFFFUL /*<< PMU_EVCNTRx_CNT_Pos*/) /*!< PMU EVCNTR: Counter Mask */ + +/** \brief PMU Event Type and Filter Registers (0-30) Definitions */ + +#define PMU_EVTYPER_EVENTTOCNT_Pos 0U /*!< PMU EVTYPER: Event to Count Position */ +#define PMU_EVTYPER_EVENTTOCNT_Msk (0xFFFFUL /*<< EVTYPERx_EVENTTOCNT_Pos*/) /*!< PMU EVTYPER: Event to Count Mask */ + +/** \brief PMU Count Enable Set Register Definitions */ + +#define PMU_CNTENSET_CNT0_ENABLE_Pos 0U /*!< PMU CNTENSET: Event Counter 0 Enable Set Position */ +#define PMU_CNTENSET_CNT0_ENABLE_Msk (1UL /*<< PMU_CNTENSET_CNT0_ENABLE_Pos*/) /*!< PMU CNTENSET: Event Counter 0 Enable Set Mask */ + +#define PMU_CNTENSET_CNT1_ENABLE_Pos 1U /*!< PMU CNTENSET: Event Counter 1 Enable Set Position */ +#define PMU_CNTENSET_CNT1_ENABLE_Msk (1UL << PMU_CNTENSET_CNT1_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 1 Enable Set Mask */ + +#define PMU_CNTENSET_CNT2_ENABLE_Pos 2U /*!< PMU CNTENSET: Event Counter 2 Enable Set Position */ +#define PMU_CNTENSET_CNT2_ENABLE_Msk (1UL << PMU_CNTENSET_CNT2_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 2 Enable Set Mask */ + +#define PMU_CNTENSET_CNT3_ENABLE_Pos 3U /*!< PMU CNTENSET: Event Counter 3 Enable Set Position */ +#define PMU_CNTENSET_CNT3_ENABLE_Msk (1UL << PMU_CNTENSET_CNT3_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 3 Enable Set Mask */ + +#define PMU_CNTENSET_CNT4_ENABLE_Pos 4U /*!< PMU CNTENSET: Event Counter 4 Enable Set Position */ +#define PMU_CNTENSET_CNT4_ENABLE_Msk (1UL << PMU_CNTENSET_CNT4_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 4 Enable Set Mask */ + +#define PMU_CNTENSET_CNT5_ENABLE_Pos 5U /*!< PMU CNTENSET: Event Counter 5 Enable Set Position */ +#define PMU_CNTENSET_CNT5_ENABLE_Msk (1UL << PMU_CNTENSET_CNT5_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 5 Enable Set Mask */ + +#define PMU_CNTENSET_CNT6_ENABLE_Pos 6U /*!< PMU CNTENSET: Event Counter 6 Enable Set Position */ +#define PMU_CNTENSET_CNT6_ENABLE_Msk (1UL << PMU_CNTENSET_CNT6_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 6 Enable Set Mask */ + +#define PMU_CNTENSET_CNT7_ENABLE_Pos 7U /*!< PMU CNTENSET: Event Counter 7 Enable Set Position */ +#define PMU_CNTENSET_CNT7_ENABLE_Msk (1UL << PMU_CNTENSET_CNT7_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 7 Enable Set Mask */ + +#define PMU_CNTENSET_CNT8_ENABLE_Pos 8U /*!< PMU CNTENSET: Event Counter 8 Enable Set Position */ +#define PMU_CNTENSET_CNT8_ENABLE_Msk (1UL << PMU_CNTENSET_CNT8_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 8 Enable Set Mask */ + +#define PMU_CNTENSET_CNT9_ENABLE_Pos 9U /*!< PMU CNTENSET: Event Counter 9 Enable Set Position */ +#define PMU_CNTENSET_CNT9_ENABLE_Msk (1UL << PMU_CNTENSET_CNT9_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 9 Enable Set Mask */ + +#define PMU_CNTENSET_CNT10_ENABLE_Pos 10U /*!< PMU CNTENSET: Event Counter 10 Enable Set Position */ +#define PMU_CNTENSET_CNT10_ENABLE_Msk (1UL << PMU_CNTENSET_CNT10_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 10 Enable Set Mask */ + +#define PMU_CNTENSET_CNT11_ENABLE_Pos 11U /*!< PMU CNTENSET: Event Counter 11 Enable Set Position */ +#define PMU_CNTENSET_CNT11_ENABLE_Msk (1UL << PMU_CNTENSET_CNT11_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 11 Enable Set Mask */ + +#define PMU_CNTENSET_CNT12_ENABLE_Pos 12U /*!< PMU CNTENSET: Event Counter 12 Enable Set Position */ +#define PMU_CNTENSET_CNT12_ENABLE_Msk (1UL << PMU_CNTENSET_CNT12_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 12 Enable Set Mask */ + +#define PMU_CNTENSET_CNT13_ENABLE_Pos 13U /*!< PMU CNTENSET: Event Counter 13 Enable Set Position */ +#define PMU_CNTENSET_CNT13_ENABLE_Msk (1UL << PMU_CNTENSET_CNT13_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 13 Enable Set Mask */ + +#define PMU_CNTENSET_CNT14_ENABLE_Pos 14U /*!< PMU CNTENSET: Event Counter 14 Enable Set Position */ +#define PMU_CNTENSET_CNT14_ENABLE_Msk (1UL << PMU_CNTENSET_CNT14_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 14 Enable Set Mask */ + +#define PMU_CNTENSET_CNT15_ENABLE_Pos 15U /*!< PMU CNTENSET: Event Counter 15 Enable Set Position */ +#define PMU_CNTENSET_CNT15_ENABLE_Msk (1UL << PMU_CNTENSET_CNT15_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 15 Enable Set Mask */ + +#define PMU_CNTENSET_CNT16_ENABLE_Pos 16U /*!< PMU CNTENSET: Event Counter 16 Enable Set Position */ +#define PMU_CNTENSET_CNT16_ENABLE_Msk (1UL << PMU_CNTENSET_CNT16_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 16 Enable Set Mask */ + +#define PMU_CNTENSET_CNT17_ENABLE_Pos 17U /*!< PMU CNTENSET: Event Counter 17 Enable Set Position */ +#define PMU_CNTENSET_CNT17_ENABLE_Msk (1UL << PMU_CNTENSET_CNT17_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 17 Enable Set Mask */ + +#define PMU_CNTENSET_CNT18_ENABLE_Pos 18U /*!< PMU CNTENSET: Event Counter 18 Enable Set Position */ +#define PMU_CNTENSET_CNT18_ENABLE_Msk (1UL << PMU_CNTENSET_CNT18_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 18 Enable Set Mask */ + +#define PMU_CNTENSET_CNT19_ENABLE_Pos 19U /*!< PMU CNTENSET: Event Counter 19 Enable Set Position */ +#define PMU_CNTENSET_CNT19_ENABLE_Msk (1UL << PMU_CNTENSET_CNT19_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 19 Enable Set Mask */ + +#define PMU_CNTENSET_CNT20_ENABLE_Pos 20U /*!< PMU CNTENSET: Event Counter 20 Enable Set Position */ +#define PMU_CNTENSET_CNT20_ENABLE_Msk (1UL << PMU_CNTENSET_CNT20_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 20 Enable Set Mask */ + +#define PMU_CNTENSET_CNT21_ENABLE_Pos 21U /*!< PMU CNTENSET: Event Counter 21 Enable Set Position */ +#define PMU_CNTENSET_CNT21_ENABLE_Msk (1UL << PMU_CNTENSET_CNT21_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 21 Enable Set Mask */ + +#define PMU_CNTENSET_CNT22_ENABLE_Pos 22U /*!< PMU CNTENSET: Event Counter 22 Enable Set Position */ +#define PMU_CNTENSET_CNT22_ENABLE_Msk (1UL << PMU_CNTENSET_CNT22_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 22 Enable Set Mask */ + +#define PMU_CNTENSET_CNT23_ENABLE_Pos 23U /*!< PMU CNTENSET: Event Counter 23 Enable Set Position */ +#define PMU_CNTENSET_CNT23_ENABLE_Msk (1UL << PMU_CNTENSET_CNT23_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 23 Enable Set Mask */ + +#define PMU_CNTENSET_CNT24_ENABLE_Pos 24U /*!< PMU CNTENSET: Event Counter 24 Enable Set Position */ +#define PMU_CNTENSET_CNT24_ENABLE_Msk (1UL << PMU_CNTENSET_CNT24_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 24 Enable Set Mask */ + +#define PMU_CNTENSET_CNT25_ENABLE_Pos 25U /*!< PMU CNTENSET: Event Counter 25 Enable Set Position */ +#define PMU_CNTENSET_CNT25_ENABLE_Msk (1UL << PMU_CNTENSET_CNT25_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 25 Enable Set Mask */ + +#define PMU_CNTENSET_CNT26_ENABLE_Pos 26U /*!< PMU CNTENSET: Event Counter 26 Enable Set Position */ +#define PMU_CNTENSET_CNT26_ENABLE_Msk (1UL << PMU_CNTENSET_CNT26_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 26 Enable Set Mask */ + +#define PMU_CNTENSET_CNT27_ENABLE_Pos 27U /*!< PMU CNTENSET: Event Counter 27 Enable Set Position */ +#define PMU_CNTENSET_CNT27_ENABLE_Msk (1UL << PMU_CNTENSET_CNT27_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 27 Enable Set Mask */ + +#define PMU_CNTENSET_CNT28_ENABLE_Pos 28U /*!< PMU CNTENSET: Event Counter 28 Enable Set Position */ +#define PMU_CNTENSET_CNT28_ENABLE_Msk (1UL << PMU_CNTENSET_CNT28_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 28 Enable Set Mask */ + +#define PMU_CNTENSET_CNT29_ENABLE_Pos 29U /*!< PMU CNTENSET: Event Counter 29 Enable Set Position */ +#define PMU_CNTENSET_CNT29_ENABLE_Msk (1UL << PMU_CNTENSET_CNT29_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 29 Enable Set Mask */ + +#define PMU_CNTENSET_CNT30_ENABLE_Pos 30U /*!< PMU CNTENSET: Event Counter 30 Enable Set Position */ +#define PMU_CNTENSET_CNT30_ENABLE_Msk (1UL << PMU_CNTENSET_CNT30_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 30 Enable Set Mask */ + +#define PMU_CNTENSET_CCNTR_ENABLE_Pos 31U /*!< PMU CNTENSET: Cycle Counter Enable Set Position */ +#define PMU_CNTENSET_CCNTR_ENABLE_Msk (1UL << PMU_CNTENSET_CCNTR_ENABLE_Pos) /*!< PMU CNTENSET: Cycle Counter Enable Set Mask */ + +/** \brief PMU Count Enable Clear Register Definitions */ + +#define PMU_CNTENSET_CNT0_ENABLE_Pos 0U /*!< PMU CNTENCLR: Event Counter 0 Enable Clear Position */ +#define PMU_CNTENCLR_CNT0_ENABLE_Msk (1UL /*<< PMU_CNTENCLR_CNT0_ENABLE_Pos*/) /*!< PMU CNTENCLR: Event Counter 0 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT1_ENABLE_Pos 1U /*!< PMU CNTENCLR: Event Counter 1 Enable Clear Position */ +#define PMU_CNTENCLR_CNT1_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT1_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 1 Enable Clear */ + +#define PMU_CNTENCLR_CNT2_ENABLE_Pos 2U /*!< PMU CNTENCLR: Event Counter 2 Enable Clear Position */ +#define PMU_CNTENCLR_CNT2_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT2_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 2 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT3_ENABLE_Pos 3U /*!< PMU CNTENCLR: Event Counter 3 Enable Clear Position */ +#define PMU_CNTENCLR_CNT3_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT3_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 3 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT4_ENABLE_Pos 4U /*!< PMU CNTENCLR: Event Counter 4 Enable Clear Position */ +#define PMU_CNTENCLR_CNT4_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT4_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 4 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT5_ENABLE_Pos 5U /*!< PMU CNTENCLR: Event Counter 5 Enable Clear Position */ +#define PMU_CNTENCLR_CNT5_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT5_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 5 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT6_ENABLE_Pos 6U /*!< PMU CNTENCLR: Event Counter 6 Enable Clear Position */ +#define PMU_CNTENCLR_CNT6_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT6_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 6 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT7_ENABLE_Pos 7U /*!< PMU CNTENCLR: Event Counter 7 Enable Clear Position */ +#define PMU_CNTENCLR_CNT7_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT7_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 7 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT8_ENABLE_Pos 8U /*!< PMU CNTENCLR: Event Counter 8 Enable Clear Position */ +#define PMU_CNTENCLR_CNT8_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT8_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 8 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT9_ENABLE_Pos 9U /*!< PMU CNTENCLR: Event Counter 9 Enable Clear Position */ +#define PMU_CNTENCLR_CNT9_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT9_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 9 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT10_ENABLE_Pos 10U /*!< PMU CNTENCLR: Event Counter 10 Enable Clear Position */ +#define PMU_CNTENCLR_CNT10_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT10_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 10 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT11_ENABLE_Pos 11U /*!< PMU CNTENCLR: Event Counter 11 Enable Clear Position */ +#define PMU_CNTENCLR_CNT11_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT11_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 11 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT12_ENABLE_Pos 12U /*!< PMU CNTENCLR: Event Counter 12 Enable Clear Position */ +#define PMU_CNTENCLR_CNT12_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT12_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 12 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT13_ENABLE_Pos 13U /*!< PMU CNTENCLR: Event Counter 13 Enable Clear Position */ +#define PMU_CNTENCLR_CNT13_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT13_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 13 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT14_ENABLE_Pos 14U /*!< PMU CNTENCLR: Event Counter 14 Enable Clear Position */ +#define PMU_CNTENCLR_CNT14_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT14_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 14 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT15_ENABLE_Pos 15U /*!< PMU CNTENCLR: Event Counter 15 Enable Clear Position */ +#define PMU_CNTENCLR_CNT15_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT15_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 15 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT16_ENABLE_Pos 16U /*!< PMU CNTENCLR: Event Counter 16 Enable Clear Position */ +#define PMU_CNTENCLR_CNT16_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT16_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 16 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT17_ENABLE_Pos 17U /*!< PMU CNTENCLR: Event Counter 17 Enable Clear Position */ +#define PMU_CNTENCLR_CNT17_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT17_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 17 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT18_ENABLE_Pos 18U /*!< PMU CNTENCLR: Event Counter 18 Enable Clear Position */ +#define PMU_CNTENCLR_CNT18_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT18_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 18 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT19_ENABLE_Pos 19U /*!< PMU CNTENCLR: Event Counter 19 Enable Clear Position */ +#define PMU_CNTENCLR_CNT19_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT19_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 19 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT20_ENABLE_Pos 20U /*!< PMU CNTENCLR: Event Counter 20 Enable Clear Position */ +#define PMU_CNTENCLR_CNT20_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT20_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 20 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT21_ENABLE_Pos 21U /*!< PMU CNTENCLR: Event Counter 21 Enable Clear Position */ +#define PMU_CNTENCLR_CNT21_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT21_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 21 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT22_ENABLE_Pos 22U /*!< PMU CNTENCLR: Event Counter 22 Enable Clear Position */ +#define PMU_CNTENCLR_CNT22_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT22_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 22 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT23_ENABLE_Pos 23U /*!< PMU CNTENCLR: Event Counter 23 Enable Clear Position */ +#define PMU_CNTENCLR_CNT23_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT23_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 23 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT24_ENABLE_Pos 24U /*!< PMU CNTENCLR: Event Counter 24 Enable Clear Position */ +#define PMU_CNTENCLR_CNT24_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT24_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 24 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT25_ENABLE_Pos 25U /*!< PMU CNTENCLR: Event Counter 25 Enable Clear Position */ +#define PMU_CNTENCLR_CNT25_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT25_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 25 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT26_ENABLE_Pos 26U /*!< PMU CNTENCLR: Event Counter 26 Enable Clear Position */ +#define PMU_CNTENCLR_CNT26_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT26_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 26 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT27_ENABLE_Pos 27U /*!< PMU CNTENCLR: Event Counter 27 Enable Clear Position */ +#define PMU_CNTENCLR_CNT27_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT27_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 27 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT28_ENABLE_Pos 28U /*!< PMU CNTENCLR: Event Counter 28 Enable Clear Position */ +#define PMU_CNTENCLR_CNT28_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT28_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 28 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT29_ENABLE_Pos 29U /*!< PMU CNTENCLR: Event Counter 29 Enable Clear Position */ +#define PMU_CNTENCLR_CNT29_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT29_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 29 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT30_ENABLE_Pos 30U /*!< PMU CNTENCLR: Event Counter 30 Enable Clear Position */ +#define PMU_CNTENCLR_CNT30_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT30_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 30 Enable Clear Mask */ + +#define PMU_CNTENCLR_CCNTR_ENABLE_Pos 31U /*!< PMU CNTENCLR: Cycle Counter Enable Clear Position */ +#define PMU_CNTENCLR_CCNTR_ENABLE_Msk (1UL << PMU_CNTENCLR_CCNTR_ENABLE_Pos) /*!< PMU CNTENCLR: Cycle Counter Enable Clear Mask */ + +/** \brief PMU Interrupt Enable Set Register Definitions */ + +#define PMU_INTENSET_CNT0_ENABLE_Pos 0U /*!< PMU INTENSET: Event Counter 0 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT0_ENABLE_Msk (1UL /*<< PMU_INTENSET_CNT0_ENABLE_Pos*/) /*!< PMU INTENSET: Event Counter 0 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT1_ENABLE_Pos 1U /*!< PMU INTENSET: Event Counter 1 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT1_ENABLE_Msk (1UL << PMU_INTENSET_CNT1_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 1 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT2_ENABLE_Pos 2U /*!< PMU INTENSET: Event Counter 2 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT2_ENABLE_Msk (1UL << PMU_INTENSET_CNT2_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 2 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT3_ENABLE_Pos 3U /*!< PMU INTENSET: Event Counter 3 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT3_ENABLE_Msk (1UL << PMU_INTENSET_CNT3_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 3 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT4_ENABLE_Pos 4U /*!< PMU INTENSET: Event Counter 4 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT4_ENABLE_Msk (1UL << PMU_INTENSET_CNT4_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 4 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT5_ENABLE_Pos 5U /*!< PMU INTENSET: Event Counter 5 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT5_ENABLE_Msk (1UL << PMU_INTENSET_CNT5_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 5 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT6_ENABLE_Pos 6U /*!< PMU INTENSET: Event Counter 6 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT6_ENABLE_Msk (1UL << PMU_INTENSET_CNT6_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 6 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT7_ENABLE_Pos 7U /*!< PMU INTENSET: Event Counter 7 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT7_ENABLE_Msk (1UL << PMU_INTENSET_CNT7_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 7 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT8_ENABLE_Pos 8U /*!< PMU INTENSET: Event Counter 8 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT8_ENABLE_Msk (1UL << PMU_INTENSET_CNT8_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 8 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT9_ENABLE_Pos 9U /*!< PMU INTENSET: Event Counter 9 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT9_ENABLE_Msk (1UL << PMU_INTENSET_CNT9_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 9 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT10_ENABLE_Pos 10U /*!< PMU INTENSET: Event Counter 10 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT10_ENABLE_Msk (1UL << PMU_INTENSET_CNT10_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 10 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT11_ENABLE_Pos 11U /*!< PMU INTENSET: Event Counter 11 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT11_ENABLE_Msk (1UL << PMU_INTENSET_CNT11_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 11 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT12_ENABLE_Pos 12U /*!< PMU INTENSET: Event Counter 12 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT12_ENABLE_Msk (1UL << PMU_INTENSET_CNT12_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 12 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT13_ENABLE_Pos 13U /*!< PMU INTENSET: Event Counter 13 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT13_ENABLE_Msk (1UL << PMU_INTENSET_CNT13_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 13 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT14_ENABLE_Pos 14U /*!< PMU INTENSET: Event Counter 14 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT14_ENABLE_Msk (1UL << PMU_INTENSET_CNT14_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 14 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT15_ENABLE_Pos 15U /*!< PMU INTENSET: Event Counter 15 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT15_ENABLE_Msk (1UL << PMU_INTENSET_CNT15_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 15 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT16_ENABLE_Pos 16U /*!< PMU INTENSET: Event Counter 16 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT16_ENABLE_Msk (1UL << PMU_INTENSET_CNT16_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 16 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT17_ENABLE_Pos 17U /*!< PMU INTENSET: Event Counter 17 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT17_ENABLE_Msk (1UL << PMU_INTENSET_CNT17_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 17 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT18_ENABLE_Pos 18U /*!< PMU INTENSET: Event Counter 18 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT18_ENABLE_Msk (1UL << PMU_INTENSET_CNT18_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 18 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT19_ENABLE_Pos 19U /*!< PMU INTENSET: Event Counter 19 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT19_ENABLE_Msk (1UL << PMU_INTENSET_CNT19_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 19 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT20_ENABLE_Pos 20U /*!< PMU INTENSET: Event Counter 20 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT20_ENABLE_Msk (1UL << PMU_INTENSET_CNT20_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 20 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT21_ENABLE_Pos 21U /*!< PMU INTENSET: Event Counter 21 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT21_ENABLE_Msk (1UL << PMU_INTENSET_CNT21_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 21 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT22_ENABLE_Pos 22U /*!< PMU INTENSET: Event Counter 22 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT22_ENABLE_Msk (1UL << PMU_INTENSET_CNT22_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 22 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT23_ENABLE_Pos 23U /*!< PMU INTENSET: Event Counter 23 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT23_ENABLE_Msk (1UL << PMU_INTENSET_CNT23_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 23 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT24_ENABLE_Pos 24U /*!< PMU INTENSET: Event Counter 24 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT24_ENABLE_Msk (1UL << PMU_INTENSET_CNT24_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 24 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT25_ENABLE_Pos 25U /*!< PMU INTENSET: Event Counter 25 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT25_ENABLE_Msk (1UL << PMU_INTENSET_CNT25_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 25 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT26_ENABLE_Pos 26U /*!< PMU INTENSET: Event Counter 26 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT26_ENABLE_Msk (1UL << PMU_INTENSET_CNT26_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 26 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT27_ENABLE_Pos 27U /*!< PMU INTENSET: Event Counter 27 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT27_ENABLE_Msk (1UL << PMU_INTENSET_CNT27_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 27 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT28_ENABLE_Pos 28U /*!< PMU INTENSET: Event Counter 28 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT28_ENABLE_Msk (1UL << PMU_INTENSET_CNT28_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 28 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT29_ENABLE_Pos 29U /*!< PMU INTENSET: Event Counter 29 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT29_ENABLE_Msk (1UL << PMU_INTENSET_CNT29_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 29 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT30_ENABLE_Pos 30U /*!< PMU INTENSET: Event Counter 30 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT30_ENABLE_Msk (1UL << PMU_INTENSET_CNT30_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 30 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CYCCNT_ENABLE_Pos 31U /*!< PMU INTENSET: Cycle Counter Interrupt Enable Set Position */ +#define PMU_INTENSET_CCYCNT_ENABLE_Msk (1UL << PMU_INTENSET_CYCCNT_ENABLE_Pos) /*!< PMU INTENSET: Cycle Counter Interrupt Enable Set Mask */ + +/** \brief PMU Interrupt Enable Clear Register Definitions */ + +#define PMU_INTENSET_CNT0_ENABLE_Pos 0U /*!< PMU INTENCLR: Event Counter 0 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT0_ENABLE_Msk (1UL /*<< PMU_INTENCLR_CNT0_ENABLE_Pos*/) /*!< PMU INTENCLR: Event Counter 0 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT1_ENABLE_Pos 1U /*!< PMU INTENCLR: Event Counter 1 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT1_ENABLE_Msk (1UL << PMU_INTENCLR_CNT1_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 1 Interrupt Enable Clear */ + +#define PMU_INTENCLR_CNT2_ENABLE_Pos 2U /*!< PMU INTENCLR: Event Counter 2 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT2_ENABLE_Msk (1UL << PMU_INTENCLR_CNT2_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 2 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT3_ENABLE_Pos 3U /*!< PMU INTENCLR: Event Counter 3 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT3_ENABLE_Msk (1UL << PMU_INTENCLR_CNT3_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 3 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT4_ENABLE_Pos 4U /*!< PMU INTENCLR: Event Counter 4 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT4_ENABLE_Msk (1UL << PMU_INTENCLR_CNT4_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 4 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT5_ENABLE_Pos 5U /*!< PMU INTENCLR: Event Counter 5 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT5_ENABLE_Msk (1UL << PMU_INTENCLR_CNT5_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 5 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT6_ENABLE_Pos 6U /*!< PMU INTENCLR: Event Counter 6 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT6_ENABLE_Msk (1UL << PMU_INTENCLR_CNT6_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 6 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT7_ENABLE_Pos 7U /*!< PMU INTENCLR: Event Counter 7 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT7_ENABLE_Msk (1UL << PMU_INTENCLR_CNT7_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 7 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT8_ENABLE_Pos 8U /*!< PMU INTENCLR: Event Counter 8 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT8_ENABLE_Msk (1UL << PMU_INTENCLR_CNT8_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 8 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT9_ENABLE_Pos 9U /*!< PMU INTENCLR: Event Counter 9 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT9_ENABLE_Msk (1UL << PMU_INTENCLR_CNT9_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 9 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT10_ENABLE_Pos 10U /*!< PMU INTENCLR: Event Counter 10 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT10_ENABLE_Msk (1UL << PMU_INTENCLR_CNT10_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 10 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT11_ENABLE_Pos 11U /*!< PMU INTENCLR: Event Counter 11 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT11_ENABLE_Msk (1UL << PMU_INTENCLR_CNT11_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 11 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT12_ENABLE_Pos 12U /*!< PMU INTENCLR: Event Counter 12 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT12_ENABLE_Msk (1UL << PMU_INTENCLR_CNT12_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 12 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT13_ENABLE_Pos 13U /*!< PMU INTENCLR: Event Counter 13 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT13_ENABLE_Msk (1UL << PMU_INTENCLR_CNT13_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 13 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT14_ENABLE_Pos 14U /*!< PMU INTENCLR: Event Counter 14 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT14_ENABLE_Msk (1UL << PMU_INTENCLR_CNT14_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 14 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT15_ENABLE_Pos 15U /*!< PMU INTENCLR: Event Counter 15 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT15_ENABLE_Msk (1UL << PMU_INTENCLR_CNT15_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 15 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT16_ENABLE_Pos 16U /*!< PMU INTENCLR: Event Counter 16 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT16_ENABLE_Msk (1UL << PMU_INTENCLR_CNT16_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 16 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT17_ENABLE_Pos 17U /*!< PMU INTENCLR: Event Counter 17 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT17_ENABLE_Msk (1UL << PMU_INTENCLR_CNT17_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 17 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT18_ENABLE_Pos 18U /*!< PMU INTENCLR: Event Counter 18 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT18_ENABLE_Msk (1UL << PMU_INTENCLR_CNT18_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 18 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT19_ENABLE_Pos 19U /*!< PMU INTENCLR: Event Counter 19 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT19_ENABLE_Msk (1UL << PMU_INTENCLR_CNT19_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 19 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT20_ENABLE_Pos 20U /*!< PMU INTENCLR: Event Counter 20 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT20_ENABLE_Msk (1UL << PMU_INTENCLR_CNT20_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 20 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT21_ENABLE_Pos 21U /*!< PMU INTENCLR: Event Counter 21 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT21_ENABLE_Msk (1UL << PMU_INTENCLR_CNT21_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 21 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT22_ENABLE_Pos 22U /*!< PMU INTENCLR: Event Counter 22 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT22_ENABLE_Msk (1UL << PMU_INTENCLR_CNT22_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 22 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT23_ENABLE_Pos 23U /*!< PMU INTENCLR: Event Counter 23 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT23_ENABLE_Msk (1UL << PMU_INTENCLR_CNT23_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 23 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT24_ENABLE_Pos 24U /*!< PMU INTENCLR: Event Counter 24 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT24_ENABLE_Msk (1UL << PMU_INTENCLR_CNT24_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 24 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT25_ENABLE_Pos 25U /*!< PMU INTENCLR: Event Counter 25 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT25_ENABLE_Msk (1UL << PMU_INTENCLR_CNT25_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 25 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT26_ENABLE_Pos 26U /*!< PMU INTENCLR: Event Counter 26 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT26_ENABLE_Msk (1UL << PMU_INTENCLR_CNT26_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 26 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT27_ENABLE_Pos 27U /*!< PMU INTENCLR: Event Counter 27 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT27_ENABLE_Msk (1UL << PMU_INTENCLR_CNT27_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 27 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT28_ENABLE_Pos 28U /*!< PMU INTENCLR: Event Counter 28 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT28_ENABLE_Msk (1UL << PMU_INTENCLR_CNT28_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 28 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT29_ENABLE_Pos 29U /*!< PMU INTENCLR: Event Counter 29 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT29_ENABLE_Msk (1UL << PMU_INTENCLR_CNT29_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 29 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT30_ENABLE_Pos 30U /*!< PMU INTENCLR: Event Counter 30 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT30_ENABLE_Msk (1UL << PMU_INTENCLR_CNT30_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 30 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CYCCNT_ENABLE_Pos 31U /*!< PMU INTENCLR: Cycle Counter Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CYCCNT_ENABLE_Msk (1UL << PMU_INTENCLR_CYCCNT_ENABLE_Pos) /*!< PMU INTENCLR: Cycle Counter Interrupt Enable Clear Mask */ + +/** \brief PMU Overflow Flag Status Set Register Definitions */ + +#define PMU_OVSSET_CNT0_STATUS_Pos 0U /*!< PMU OVSSET: Event Counter 0 Overflow Set Position */ +#define PMU_OVSSET_CNT0_STATUS_Msk (1UL /*<< PMU_OVSSET_CNT0_STATUS_Pos*/) /*!< PMU OVSSET: Event Counter 0 Overflow Set Mask */ + +#define PMU_OVSSET_CNT1_STATUS_Pos 1U /*!< PMU OVSSET: Event Counter 1 Overflow Set Position */ +#define PMU_OVSSET_CNT1_STATUS_Msk (1UL << PMU_OVSSET_CNT1_STATUS_Pos) /*!< PMU OVSSET: Event Counter 1 Overflow Set Mask */ + +#define PMU_OVSSET_CNT2_STATUS_Pos 2U /*!< PMU OVSSET: Event Counter 2 Overflow Set Position */ +#define PMU_OVSSET_CNT2_STATUS_Msk (1UL << PMU_OVSSET_CNT2_STATUS_Pos) /*!< PMU OVSSET: Event Counter 2 Overflow Set Mask */ + +#define PMU_OVSSET_CNT3_STATUS_Pos 3U /*!< PMU OVSSET: Event Counter 3 Overflow Set Position */ +#define PMU_OVSSET_CNT3_STATUS_Msk (1UL << PMU_OVSSET_CNT3_STATUS_Pos) /*!< PMU OVSSET: Event Counter 3 Overflow Set Mask */ + +#define PMU_OVSSET_CNT4_STATUS_Pos 4U /*!< PMU OVSSET: Event Counter 4 Overflow Set Position */ +#define PMU_OVSSET_CNT4_STATUS_Msk (1UL << PMU_OVSSET_CNT4_STATUS_Pos) /*!< PMU OVSSET: Event Counter 4 Overflow Set Mask */ + +#define PMU_OVSSET_CNT5_STATUS_Pos 5U /*!< PMU OVSSET: Event Counter 5 Overflow Set Position */ +#define PMU_OVSSET_CNT5_STATUS_Msk (1UL << PMU_OVSSET_CNT5_STATUS_Pos) /*!< PMU OVSSET: Event Counter 5 Overflow Set Mask */ + +#define PMU_OVSSET_CNT6_STATUS_Pos 6U /*!< PMU OVSSET: Event Counter 6 Overflow Set Position */ +#define PMU_OVSSET_CNT6_STATUS_Msk (1UL << PMU_OVSSET_CNT6_STATUS_Pos) /*!< PMU OVSSET: Event Counter 6 Overflow Set Mask */ + +#define PMU_OVSSET_CNT7_STATUS_Pos 7U /*!< PMU OVSSET: Event Counter 7 Overflow Set Position */ +#define PMU_OVSSET_CNT7_STATUS_Msk (1UL << PMU_OVSSET_CNT7_STATUS_Pos) /*!< PMU OVSSET: Event Counter 7 Overflow Set Mask */ + +#define PMU_OVSSET_CNT8_STATUS_Pos 8U /*!< PMU OVSSET: Event Counter 8 Overflow Set Position */ +#define PMU_OVSSET_CNT8_STATUS_Msk (1UL << PMU_OVSSET_CNT8_STATUS_Pos) /*!< PMU OVSSET: Event Counter 8 Overflow Set Mask */ + +#define PMU_OVSSET_CNT9_STATUS_Pos 9U /*!< PMU OVSSET: Event Counter 9 Overflow Set Position */ +#define PMU_OVSSET_CNT9_STATUS_Msk (1UL << PMU_OVSSET_CNT9_STATUS_Pos) /*!< PMU OVSSET: Event Counter 9 Overflow Set Mask */ + +#define PMU_OVSSET_CNT10_STATUS_Pos 10U /*!< PMU OVSSET: Event Counter 10 Overflow Set Position */ +#define PMU_OVSSET_CNT10_STATUS_Msk (1UL << PMU_OVSSET_CNT10_STATUS_Pos) /*!< PMU OVSSET: Event Counter 10 Overflow Set Mask */ + +#define PMU_OVSSET_CNT11_STATUS_Pos 11U /*!< PMU OVSSET: Event Counter 11 Overflow Set Position */ +#define PMU_OVSSET_CNT11_STATUS_Msk (1UL << PMU_OVSSET_CNT11_STATUS_Pos) /*!< PMU OVSSET: Event Counter 11 Overflow Set Mask */ + +#define PMU_OVSSET_CNT12_STATUS_Pos 12U /*!< PMU OVSSET: Event Counter 12 Overflow Set Position */ +#define PMU_OVSSET_CNT12_STATUS_Msk (1UL << PMU_OVSSET_CNT12_STATUS_Pos) /*!< PMU OVSSET: Event Counter 12 Overflow Set Mask */ + +#define PMU_OVSSET_CNT13_STATUS_Pos 13U /*!< PMU OVSSET: Event Counter 13 Overflow Set Position */ +#define PMU_OVSSET_CNT13_STATUS_Msk (1UL << PMU_OVSSET_CNT13_STATUS_Pos) /*!< PMU OVSSET: Event Counter 13 Overflow Set Mask */ + +#define PMU_OVSSET_CNT14_STATUS_Pos 14U /*!< PMU OVSSET: Event Counter 14 Overflow Set Position */ +#define PMU_OVSSET_CNT14_STATUS_Msk (1UL << PMU_OVSSET_CNT14_STATUS_Pos) /*!< PMU OVSSET: Event Counter 14 Overflow Set Mask */ + +#define PMU_OVSSET_CNT15_STATUS_Pos 15U /*!< PMU OVSSET: Event Counter 15 Overflow Set Position */ +#define PMU_OVSSET_CNT15_STATUS_Msk (1UL << PMU_OVSSET_CNT15_STATUS_Pos) /*!< PMU OVSSET: Event Counter 15 Overflow Set Mask */ + +#define PMU_OVSSET_CNT16_STATUS_Pos 16U /*!< PMU OVSSET: Event Counter 16 Overflow Set Position */ +#define PMU_OVSSET_CNT16_STATUS_Msk (1UL << PMU_OVSSET_CNT16_STATUS_Pos) /*!< PMU OVSSET: Event Counter 16 Overflow Set Mask */ + +#define PMU_OVSSET_CNT17_STATUS_Pos 17U /*!< PMU OVSSET: Event Counter 17 Overflow Set Position */ +#define PMU_OVSSET_CNT17_STATUS_Msk (1UL << PMU_OVSSET_CNT17_STATUS_Pos) /*!< PMU OVSSET: Event Counter 17 Overflow Set Mask */ + +#define PMU_OVSSET_CNT18_STATUS_Pos 18U /*!< PMU OVSSET: Event Counter 18 Overflow Set Position */ +#define PMU_OVSSET_CNT18_STATUS_Msk (1UL << PMU_OVSSET_CNT18_STATUS_Pos) /*!< PMU OVSSET: Event Counter 18 Overflow Set Mask */ + +#define PMU_OVSSET_CNT19_STATUS_Pos 19U /*!< PMU OVSSET: Event Counter 19 Overflow Set Position */ +#define PMU_OVSSET_CNT19_STATUS_Msk (1UL << PMU_OVSSET_CNT19_STATUS_Pos) /*!< PMU OVSSET: Event Counter 19 Overflow Set Mask */ + +#define PMU_OVSSET_CNT20_STATUS_Pos 20U /*!< PMU OVSSET: Event Counter 20 Overflow Set Position */ +#define PMU_OVSSET_CNT20_STATUS_Msk (1UL << PMU_OVSSET_CNT20_STATUS_Pos) /*!< PMU OVSSET: Event Counter 20 Overflow Set Mask */ + +#define PMU_OVSSET_CNT21_STATUS_Pos 21U /*!< PMU OVSSET: Event Counter 21 Overflow Set Position */ +#define PMU_OVSSET_CNT21_STATUS_Msk (1UL << PMU_OVSSET_CNT21_STATUS_Pos) /*!< PMU OVSSET: Event Counter 21 Overflow Set Mask */ + +#define PMU_OVSSET_CNT22_STATUS_Pos 22U /*!< PMU OVSSET: Event Counter 22 Overflow Set Position */ +#define PMU_OVSSET_CNT22_STATUS_Msk (1UL << PMU_OVSSET_CNT22_STATUS_Pos) /*!< PMU OVSSET: Event Counter 22 Overflow Set Mask */ + +#define PMU_OVSSET_CNT23_STATUS_Pos 23U /*!< PMU OVSSET: Event Counter 23 Overflow Set Position */ +#define PMU_OVSSET_CNT23_STATUS_Msk (1UL << PMU_OVSSET_CNT23_STATUS_Pos) /*!< PMU OVSSET: Event Counter 23 Overflow Set Mask */ + +#define PMU_OVSSET_CNT24_STATUS_Pos 24U /*!< PMU OVSSET: Event Counter 24 Overflow Set Position */ +#define PMU_OVSSET_CNT24_STATUS_Msk (1UL << PMU_OVSSET_CNT24_STATUS_Pos) /*!< PMU OVSSET: Event Counter 24 Overflow Set Mask */ + +#define PMU_OVSSET_CNT25_STATUS_Pos 25U /*!< PMU OVSSET: Event Counter 25 Overflow Set Position */ +#define PMU_OVSSET_CNT25_STATUS_Msk (1UL << PMU_OVSSET_CNT25_STATUS_Pos) /*!< PMU OVSSET: Event Counter 25 Overflow Set Mask */ + +#define PMU_OVSSET_CNT26_STATUS_Pos 26U /*!< PMU OVSSET: Event Counter 26 Overflow Set Position */ +#define PMU_OVSSET_CNT26_STATUS_Msk (1UL << PMU_OVSSET_CNT26_STATUS_Pos) /*!< PMU OVSSET: Event Counter 26 Overflow Set Mask */ + +#define PMU_OVSSET_CNT27_STATUS_Pos 27U /*!< PMU OVSSET: Event Counter 27 Overflow Set Position */ +#define PMU_OVSSET_CNT27_STATUS_Msk (1UL << PMU_OVSSET_CNT27_STATUS_Pos) /*!< PMU OVSSET: Event Counter 27 Overflow Set Mask */ + +#define PMU_OVSSET_CNT28_STATUS_Pos 28U /*!< PMU OVSSET: Event Counter 28 Overflow Set Position */ +#define PMU_OVSSET_CNT28_STATUS_Msk (1UL << PMU_OVSSET_CNT28_STATUS_Pos) /*!< PMU OVSSET: Event Counter 28 Overflow Set Mask */ + +#define PMU_OVSSET_CNT29_STATUS_Pos 29U /*!< PMU OVSSET: Event Counter 29 Overflow Set Position */ +#define PMU_OVSSET_CNT29_STATUS_Msk (1UL << PMU_OVSSET_CNT29_STATUS_Pos) /*!< PMU OVSSET: Event Counter 29 Overflow Set Mask */ + +#define PMU_OVSSET_CNT30_STATUS_Pos 30U /*!< PMU OVSSET: Event Counter 30 Overflow Set Position */ +#define PMU_OVSSET_CNT30_STATUS_Msk (1UL << PMU_OVSSET_CNT30_STATUS_Pos) /*!< PMU OVSSET: Event Counter 30 Overflow Set Mask */ + +#define PMU_OVSSET_CYCCNT_STATUS_Pos 31U /*!< PMU OVSSET: Cycle Counter Overflow Set Position */ +#define PMU_OVSSET_CYCCNT_STATUS_Msk (1UL << PMU_OVSSET_CYCCNT_STATUS_Pos) /*!< PMU OVSSET: Cycle Counter Overflow Set Mask */ + +/** \brief PMU Overflow Flag Status Clear Register Definitions */ + +#define PMU_OVSCLR_CNT0_STATUS_Pos 0U /*!< PMU OVSCLR: Event Counter 0 Overflow Clear Position */ +#define PMU_OVSCLR_CNT0_STATUS_Msk (1UL /*<< PMU_OVSCLR_CNT0_STATUS_Pos*/) /*!< PMU OVSCLR: Event Counter 0 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT1_STATUS_Pos 1U /*!< PMU OVSCLR: Event Counter 1 Overflow Clear Position */ +#define PMU_OVSCLR_CNT1_STATUS_Msk (1UL << PMU_OVSCLR_CNT1_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 1 Overflow Clear */ + +#define PMU_OVSCLR_CNT2_STATUS_Pos 2U /*!< PMU OVSCLR: Event Counter 2 Overflow Clear Position */ +#define PMU_OVSCLR_CNT2_STATUS_Msk (1UL << PMU_OVSCLR_CNT2_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 2 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT3_STATUS_Pos 3U /*!< PMU OVSCLR: Event Counter 3 Overflow Clear Position */ +#define PMU_OVSCLR_CNT3_STATUS_Msk (1UL << PMU_OVSCLR_CNT3_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 3 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT4_STATUS_Pos 4U /*!< PMU OVSCLR: Event Counter 4 Overflow Clear Position */ +#define PMU_OVSCLR_CNT4_STATUS_Msk (1UL << PMU_OVSCLR_CNT4_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 4 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT5_STATUS_Pos 5U /*!< PMU OVSCLR: Event Counter 5 Overflow Clear Position */ +#define PMU_OVSCLR_CNT5_STATUS_Msk (1UL << PMU_OVSCLR_CNT5_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 5 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT6_STATUS_Pos 6U /*!< PMU OVSCLR: Event Counter 6 Overflow Clear Position */ +#define PMU_OVSCLR_CNT6_STATUS_Msk (1UL << PMU_OVSCLR_CNT6_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 6 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT7_STATUS_Pos 7U /*!< PMU OVSCLR: Event Counter 7 Overflow Clear Position */ +#define PMU_OVSCLR_CNT7_STATUS_Msk (1UL << PMU_OVSCLR_CNT7_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 7 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT8_STATUS_Pos 8U /*!< PMU OVSCLR: Event Counter 8 Overflow Clear Position */ +#define PMU_OVSCLR_CNT8_STATUS_Msk (1UL << PMU_OVSCLR_CNT8_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 8 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT9_STATUS_Pos 9U /*!< PMU OVSCLR: Event Counter 9 Overflow Clear Position */ +#define PMU_OVSCLR_CNT9_STATUS_Msk (1UL << PMU_OVSCLR_CNT9_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 9 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT10_STATUS_Pos 10U /*!< PMU OVSCLR: Event Counter 10 Overflow Clear Position */ +#define PMU_OVSCLR_CNT10_STATUS_Msk (1UL << PMU_OVSCLR_CNT10_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 10 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT11_STATUS_Pos 11U /*!< PMU OVSCLR: Event Counter 11 Overflow Clear Position */ +#define PMU_OVSCLR_CNT11_STATUS_Msk (1UL << PMU_OVSCLR_CNT11_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 11 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT12_STATUS_Pos 12U /*!< PMU OVSCLR: Event Counter 12 Overflow Clear Position */ +#define PMU_OVSCLR_CNT12_STATUS_Msk (1UL << PMU_OVSCLR_CNT12_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 12 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT13_STATUS_Pos 13U /*!< PMU OVSCLR: Event Counter 13 Overflow Clear Position */ +#define PMU_OVSCLR_CNT13_STATUS_Msk (1UL << PMU_OVSCLR_CNT13_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 13 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT14_STATUS_Pos 14U /*!< PMU OVSCLR: Event Counter 14 Overflow Clear Position */ +#define PMU_OVSCLR_CNT14_STATUS_Msk (1UL << PMU_OVSCLR_CNT14_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 14 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT15_STATUS_Pos 15U /*!< PMU OVSCLR: Event Counter 15 Overflow Clear Position */ +#define PMU_OVSCLR_CNT15_STATUS_Msk (1UL << PMU_OVSCLR_CNT15_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 15 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT16_STATUS_Pos 16U /*!< PMU OVSCLR: Event Counter 16 Overflow Clear Position */ +#define PMU_OVSCLR_CNT16_STATUS_Msk (1UL << PMU_OVSCLR_CNT16_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 16 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT17_STATUS_Pos 17U /*!< PMU OVSCLR: Event Counter 17 Overflow Clear Position */ +#define PMU_OVSCLR_CNT17_STATUS_Msk (1UL << PMU_OVSCLR_CNT17_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 17 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT18_STATUS_Pos 18U /*!< PMU OVSCLR: Event Counter 18 Overflow Clear Position */ +#define PMU_OVSCLR_CNT18_STATUS_Msk (1UL << PMU_OVSCLR_CNT18_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 18 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT19_STATUS_Pos 19U /*!< PMU OVSCLR: Event Counter 19 Overflow Clear Position */ +#define PMU_OVSCLR_CNT19_STATUS_Msk (1UL << PMU_OVSCLR_CNT19_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 19 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT20_STATUS_Pos 20U /*!< PMU OVSCLR: Event Counter 20 Overflow Clear Position */ +#define PMU_OVSCLR_CNT20_STATUS_Msk (1UL << PMU_OVSCLR_CNT20_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 20 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT21_STATUS_Pos 21U /*!< PMU OVSCLR: Event Counter 21 Overflow Clear Position */ +#define PMU_OVSCLR_CNT21_STATUS_Msk (1UL << PMU_OVSCLR_CNT21_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 21 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT22_STATUS_Pos 22U /*!< PMU OVSCLR: Event Counter 22 Overflow Clear Position */ +#define PMU_OVSCLR_CNT22_STATUS_Msk (1UL << PMU_OVSCLR_CNT22_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 22 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT23_STATUS_Pos 23U /*!< PMU OVSCLR: Event Counter 23 Overflow Clear Position */ +#define PMU_OVSCLR_CNT23_STATUS_Msk (1UL << PMU_OVSCLR_CNT23_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 23 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT24_STATUS_Pos 24U /*!< PMU OVSCLR: Event Counter 24 Overflow Clear Position */ +#define PMU_OVSCLR_CNT24_STATUS_Msk (1UL << PMU_OVSCLR_CNT24_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 24 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT25_STATUS_Pos 25U /*!< PMU OVSCLR: Event Counter 25 Overflow Clear Position */ +#define PMU_OVSCLR_CNT25_STATUS_Msk (1UL << PMU_OVSCLR_CNT25_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 25 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT26_STATUS_Pos 26U /*!< PMU OVSCLR: Event Counter 26 Overflow Clear Position */ +#define PMU_OVSCLR_CNT26_STATUS_Msk (1UL << PMU_OVSCLR_CNT26_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 26 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT27_STATUS_Pos 27U /*!< PMU OVSCLR: Event Counter 27 Overflow Clear Position */ +#define PMU_OVSCLR_CNT27_STATUS_Msk (1UL << PMU_OVSCLR_CNT27_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 27 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT28_STATUS_Pos 28U /*!< PMU OVSCLR: Event Counter 28 Overflow Clear Position */ +#define PMU_OVSCLR_CNT28_STATUS_Msk (1UL << PMU_OVSCLR_CNT28_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 28 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT29_STATUS_Pos 29U /*!< PMU OVSCLR: Event Counter 29 Overflow Clear Position */ +#define PMU_OVSCLR_CNT29_STATUS_Msk (1UL << PMU_OVSCLR_CNT29_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 29 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT30_STATUS_Pos 30U /*!< PMU OVSCLR: Event Counter 30 Overflow Clear Position */ +#define PMU_OVSCLR_CNT30_STATUS_Msk (1UL << PMU_OVSCLR_CNT30_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 30 Overflow Clear Mask */ + +#define PMU_OVSCLR_CYCCNT_STATUS_Pos 31U /*!< PMU OVSCLR: Cycle Counter Overflow Clear Position */ +#define PMU_OVSCLR_CYCCNT_STATUS_Msk (1UL << PMU_OVSCLR_CYCCNT_STATUS_Pos) /*!< PMU OVSCLR: Cycle Counter Overflow Clear Mask */ + +/** \brief PMU Software Increment Counter */ + +#define PMU_SWINC_CNT0_Pos 0U /*!< PMU SWINC: Event Counter 0 Software Increment Position */ +#define PMU_SWINC_CNT0_Msk (1UL /*<< PMU_SWINC_CNT0_Pos */) /*!< PMU SWINC: Event Counter 0 Software Increment Mask */ + +#define PMU_SWINC_CNT1_Pos 1U /*!< PMU SWINC: Event Counter 1 Software Increment Position */ +#define PMU_SWINC_CNT1_Msk (1UL << PMU_SWINC_CNT1_Pos) /*!< PMU SWINC: Event Counter 1 Software Increment Mask */ + +#define PMU_SWINC_CNT2_Pos 2U /*!< PMU SWINC: Event Counter 2 Software Increment Position */ +#define PMU_SWINC_CNT2_Msk (1UL << PMU_SWINC_CNT2_Pos) /*!< PMU SWINC: Event Counter 2 Software Increment Mask */ + +#define PMU_SWINC_CNT3_Pos 3U /*!< PMU SWINC: Event Counter 3 Software Increment Position */ +#define PMU_SWINC_CNT3_Msk (1UL << PMU_SWINC_CNT3_Pos) /*!< PMU SWINC: Event Counter 3 Software Increment Mask */ + +#define PMU_SWINC_CNT4_Pos 4U /*!< PMU SWINC: Event Counter 4 Software Increment Position */ +#define PMU_SWINC_CNT4_Msk (1UL << PMU_SWINC_CNT4_Pos) /*!< PMU SWINC: Event Counter 4 Software Increment Mask */ + +#define PMU_SWINC_CNT5_Pos 5U /*!< PMU SWINC: Event Counter 5 Software Increment Position */ +#define PMU_SWINC_CNT5_Msk (1UL << PMU_SWINC_CNT5_Pos) /*!< PMU SWINC: Event Counter 5 Software Increment Mask */ + +#define PMU_SWINC_CNT6_Pos 6U /*!< PMU SWINC: Event Counter 6 Software Increment Position */ +#define PMU_SWINC_CNT6_Msk (1UL << PMU_SWINC_CNT6_Pos) /*!< PMU SWINC: Event Counter 6 Software Increment Mask */ + +#define PMU_SWINC_CNT7_Pos 7U /*!< PMU SWINC: Event Counter 7 Software Increment Position */ +#define PMU_SWINC_CNT7_Msk (1UL << PMU_SWINC_CNT7_Pos) /*!< PMU SWINC: Event Counter 7 Software Increment Mask */ + +#define PMU_SWINC_CNT8_Pos 8U /*!< PMU SWINC: Event Counter 8 Software Increment Position */ +#define PMU_SWINC_CNT8_Msk (1UL << PMU_SWINC_CNT8_Pos) /*!< PMU SWINC: Event Counter 8 Software Increment Mask */ + +#define PMU_SWINC_CNT9_Pos 9U /*!< PMU SWINC: Event Counter 9 Software Increment Position */ +#define PMU_SWINC_CNT9_Msk (1UL << PMU_SWINC_CNT9_Pos) /*!< PMU SWINC: Event Counter 9 Software Increment Mask */ + +#define PMU_SWINC_CNT10_Pos 10U /*!< PMU SWINC: Event Counter 10 Software Increment Position */ +#define PMU_SWINC_CNT10_Msk (1UL << PMU_SWINC_CNT10_Pos) /*!< PMU SWINC: Event Counter 10 Software Increment Mask */ + +#define PMU_SWINC_CNT11_Pos 11U /*!< PMU SWINC: Event Counter 11 Software Increment Position */ +#define PMU_SWINC_CNT11_Msk (1UL << PMU_SWINC_CNT11_Pos) /*!< PMU SWINC: Event Counter 11 Software Increment Mask */ + +#define PMU_SWINC_CNT12_Pos 12U /*!< PMU SWINC: Event Counter 12 Software Increment Position */ +#define PMU_SWINC_CNT12_Msk (1UL << PMU_SWINC_CNT12_Pos) /*!< PMU SWINC: Event Counter 12 Software Increment Mask */ + +#define PMU_SWINC_CNT13_Pos 13U /*!< PMU SWINC: Event Counter 13 Software Increment Position */ +#define PMU_SWINC_CNT13_Msk (1UL << PMU_SWINC_CNT13_Pos) /*!< PMU SWINC: Event Counter 13 Software Increment Mask */ + +#define PMU_SWINC_CNT14_Pos 14U /*!< PMU SWINC: Event Counter 14 Software Increment Position */ +#define PMU_SWINC_CNT14_Msk (1UL << PMU_SWINC_CNT14_Pos) /*!< PMU SWINC: Event Counter 14 Software Increment Mask */ + +#define PMU_SWINC_CNT15_Pos 15U /*!< PMU SWINC: Event Counter 15 Software Increment Position */ +#define PMU_SWINC_CNT15_Msk (1UL << PMU_SWINC_CNT15_Pos) /*!< PMU SWINC: Event Counter 15 Software Increment Mask */ + +#define PMU_SWINC_CNT16_Pos 16U /*!< PMU SWINC: Event Counter 16 Software Increment Position */ +#define PMU_SWINC_CNT16_Msk (1UL << PMU_SWINC_CNT16_Pos) /*!< PMU SWINC: Event Counter 16 Software Increment Mask */ + +#define PMU_SWINC_CNT17_Pos 17U /*!< PMU SWINC: Event Counter 17 Software Increment Position */ +#define PMU_SWINC_CNT17_Msk (1UL << PMU_SWINC_CNT17_Pos) /*!< PMU SWINC: Event Counter 17 Software Increment Mask */ + +#define PMU_SWINC_CNT18_Pos 18U /*!< PMU SWINC: Event Counter 18 Software Increment Position */ +#define PMU_SWINC_CNT18_Msk (1UL << PMU_SWINC_CNT18_Pos) /*!< PMU SWINC: Event Counter 18 Software Increment Mask */ + +#define PMU_SWINC_CNT19_Pos 19U /*!< PMU SWINC: Event Counter 19 Software Increment Position */ +#define PMU_SWINC_CNT19_Msk (1UL << PMU_SWINC_CNT19_Pos) /*!< PMU SWINC: Event Counter 19 Software Increment Mask */ + +#define PMU_SWINC_CNT20_Pos 20U /*!< PMU SWINC: Event Counter 20 Software Increment Position */ +#define PMU_SWINC_CNT20_Msk (1UL << PMU_SWINC_CNT20_Pos) /*!< PMU SWINC: Event Counter 20 Software Increment Mask */ + +#define PMU_SWINC_CNT21_Pos 21U /*!< PMU SWINC: Event Counter 21 Software Increment Position */ +#define PMU_SWINC_CNT21_Msk (1UL << PMU_SWINC_CNT21_Pos) /*!< PMU SWINC: Event Counter 21 Software Increment Mask */ + +#define PMU_SWINC_CNT22_Pos 22U /*!< PMU SWINC: Event Counter 22 Software Increment Position */ +#define PMU_SWINC_CNT22_Msk (1UL << PMU_SWINC_CNT22_Pos) /*!< PMU SWINC: Event Counter 22 Software Increment Mask */ + +#define PMU_SWINC_CNT23_Pos 23U /*!< PMU SWINC: Event Counter 23 Software Increment Position */ +#define PMU_SWINC_CNT23_Msk (1UL << PMU_SWINC_CNT23_Pos) /*!< PMU SWINC: Event Counter 23 Software Increment Mask */ + +#define PMU_SWINC_CNT24_Pos 24U /*!< PMU SWINC: Event Counter 24 Software Increment Position */ +#define PMU_SWINC_CNT24_Msk (1UL << PMU_SWINC_CNT24_Pos) /*!< PMU SWINC: Event Counter 24 Software Increment Mask */ + +#define PMU_SWINC_CNT25_Pos 25U /*!< PMU SWINC: Event Counter 25 Software Increment Position */ +#define PMU_SWINC_CNT25_Msk (1UL << PMU_SWINC_CNT25_Pos) /*!< PMU SWINC: Event Counter 25 Software Increment Mask */ + +#define PMU_SWINC_CNT26_Pos 26U /*!< PMU SWINC: Event Counter 26 Software Increment Position */ +#define PMU_SWINC_CNT26_Msk (1UL << PMU_SWINC_CNT26_Pos) /*!< PMU SWINC: Event Counter 26 Software Increment Mask */ + +#define PMU_SWINC_CNT27_Pos 27U /*!< PMU SWINC: Event Counter 27 Software Increment Position */ +#define PMU_SWINC_CNT27_Msk (1UL << PMU_SWINC_CNT27_Pos) /*!< PMU SWINC: Event Counter 27 Software Increment Mask */ + +#define PMU_SWINC_CNT28_Pos 28U /*!< PMU SWINC: Event Counter 28 Software Increment Position */ +#define PMU_SWINC_CNT28_Msk (1UL << PMU_SWINC_CNT28_Pos) /*!< PMU SWINC: Event Counter 28 Software Increment Mask */ + +#define PMU_SWINC_CNT29_Pos 29U /*!< PMU SWINC: Event Counter 29 Software Increment Position */ +#define PMU_SWINC_CNT29_Msk (1UL << PMU_SWINC_CNT29_Pos) /*!< PMU SWINC: Event Counter 29 Software Increment Mask */ + +#define PMU_SWINC_CNT30_Pos 30U /*!< PMU SWINC: Event Counter 30 Software Increment Position */ +#define PMU_SWINC_CNT30_Msk (1UL << PMU_SWINC_CNT30_Pos) /*!< PMU SWINC: Event Counter 30 Software Increment Mask */ + +/** \brief PMU Control Register Definitions */ + +#define PMU_CTRL_ENABLE_Pos 0U /*!< PMU CTRL: ENABLE Position */ +#define PMU_CTRL_ENABLE_Msk (1UL /*<< PMU_CTRL_ENABLE_Pos*/) /*!< PMU CTRL: ENABLE Mask */ + +#define PMU_CTRL_EVENTCNT_RESET_Pos 1U /*!< PMU CTRL: Event Counter Reset Position */ +#define PMU_CTRL_EVENTCNT_RESET_Msk (1UL << PMU_CTRL_EVENTCNT_RESET_Pos) /*!< PMU CTRL: Event Counter Reset Mask */ + +#define PMU_CTRL_CYCCNT_RESET_Pos 2U /*!< PMU CTRL: Cycle Counter Reset Position */ +#define PMU_CTRL_CYCCNT_RESET_Msk (1UL << PMU_CTRL_CYCCNT_RESET_Pos) /*!< PMU CTRL: Cycle Counter Reset Mask */ + +#define PMU_CTRL_CYCCNT_DISABLE_Pos 5U /*!< PMU CTRL: Disable Cycle Counter Position */ +#define PMU_CTRL_CYCCNT_DISABLE_Msk (1UL << PMU_CTRL_CYCCNT_DISABLE_Pos) /*!< PMU CTRL: Disable Cycle Counter Mask */ + +#define PMU_CTRL_FRZ_ON_OV_Pos 9U /*!< PMU CTRL: Freeze-on-overflow Position */ +#define PMU_CTRL_FRZ_ON_OV_Msk (1UL << PMU_CTRL_FRZ_ON_OVERFLOW_Pos) /*!< PMU CTRL: Freeze-on-overflow Mask */ + +#define PMU_CTRL_TRACE_ON_OV_Pos 11U /*!< PMU CTRL: Trace-on-overflow Position */ +#define PMU_CTRL_TRACE_ON_OV_Msk (1UL << PMU_CTRL_TRACE_ON_OVERFLOW_Pos) /*!< PMU CTRL: Trace-on-overflow Mask */ + +/** \brief PMU Type Register Definitions */ + +#define PMU_TYPE_NUM_CNTS_Pos 0U /*!< PMU TYPE: Number of Counters Position */ +#define PMU_TYPE_NUM_CNTS_Msk (0xFFUL /*<< PMU_TYPE_NUM_CNTS_Pos*/) /*!< PMU TYPE: Number of Counters Mask */ + +#define PMU_TYPE_SIZE_CNTS_Pos 8U /*!< PMU TYPE: Size of Counters Position */ +#define PMU_TYPE_SIZE_CNTS_Msk (0x3FUL << PMU_TYPE_SIZE_CNTS_Pos) /*!< PMU TYPE: Size of Counters Mask */ + +#define PMU_TYPE_CYCCNT_PRESENT_Pos 14U /*!< PMU TYPE: Cycle Counter Present Position */ +#define PMU_TYPE_CYCCNT_PRESENT_Msk (1UL << PMU_TYPE_CYCCNT_PRESENT_Pos) /*!< PMU TYPE: Cycle Counter Present Mask */ + +#define PMU_TYPE_FRZ_OV_SUPPORT_Pos 21U /*!< PMU TYPE: Freeze-on-overflow Support Position */ +#define PMU_TYPE_FRZ_OV_SUPPORT_Msk (1UL << PMU_TYPE_FRZ_OV_SUPPORT_Pos) /*!< PMU TYPE: Freeze-on-overflow Support Mask */ + +#define PMU_TYPE_TRACE_ON_OV_SUPPORT_Pos 23U /*!< PMU TYPE: Trace-on-overflow Support Position */ +#define PMU_TYPE_TRACE_ON_OV_SUPPORT_Msk (1UL << PMU_TYPE_FRZ_OV_SUPPORT_Pos) /*!< PMU TYPE: Trace-on-overflow Support Mask */ + +/** \brief PMU Authentication Status Register Definitions */ + +#define PMU_AUTHSTATUS_NSID_Pos 0U /*!< PMU AUTHSTATUS: Non-secure Invasive Debug Position */ +#define PMU_AUTHSTATUS_NSID_Msk (0x3UL /*<< PMU_AUTHSTATUS_NSID_Pos*/) /*!< PMU AUTHSTATUS: Non-secure Invasive Debug Mask */ + +#define PMU_AUTHSTATUS_NSNID_Pos 2U /*!< PMU AUTHSTATUS: Non-secure Non-invasive Debug Position */ +#define PMU_AUTHSTATUS_NSNID_Msk (0x3UL << PMU_AUTHSTATUS_NSNID_Pos) /*!< PMU AUTHSTATUS: Non-secure Non-invasive Debug Mask */ + +#define PMU_AUTHSTATUS_SID_Pos 4U /*!< PMU AUTHSTATUS: Secure Invasive Debug Position */ +#define PMU_AUTHSTATUS_SID_Msk (0x3UL << PMU_AUTHSTATUS_SID_Pos) /*!< PMU AUTHSTATUS: Secure Invasive Debug Mask */ + +#define PMU_AUTHSTATUS_SNID_Pos 6U /*!< PMU AUTHSTATUS: Secure Non-invasive Debug Position */ +#define PMU_AUTHSTATUS_SNID_Msk (0x3UL << PMU_AUTHSTATUS_SNID_Pos) /*!< PMU AUTHSTATUS: Secure Non-invasive Debug Mask */ + +#define PMU_AUTHSTATUS_NSUID_Pos 16U /*!< PMU AUTHSTATUS: Non-secure Unprivileged Invasive Debug Position */ +#define PMU_AUTHSTATUS_NSUID_Msk (0x3UL << PMU_AUTHSTATUS_NSUID_Pos) /*!< PMU AUTHSTATUS: Non-secure Unprivileged Invasive Debug Mask */ + +#define PMU_AUTHSTATUS_NSUNID_Pos 18U /*!< PMU AUTHSTATUS: Non-secure Unprivileged Non-invasive Debug Position */ +#define PMU_AUTHSTATUS_NSUNID_Msk (0x3UL << PMU_AUTHSTATUS_NSUNID_Pos) /*!< PMU AUTHSTATUS: Non-secure Unprivileged Non-invasive Debug Mask */ + +#define PMU_AUTHSTATUS_SUID_Pos 20U /*!< PMU AUTHSTATUS: Secure Unprivileged Invasive Debug Position */ +#define PMU_AUTHSTATUS_SUID_Msk (0x3UL << PMU_AUTHSTATUS_SUID_Pos) /*!< PMU AUTHSTATUS: Secure Unprivileged Invasive Debug Mask */ + +#define PMU_AUTHSTATUS_SUNID_Pos 22U /*!< PMU AUTHSTATUS: Secure Unprivileged Non-invasive Debug Position */ +#define PMU_AUTHSTATUS_SUNID_Msk (0x3UL << PMU_AUTHSTATUS_SUNID_Pos) /*!< PMU AUTHSTATUS: Secure Unprivileged Non-invasive Debug Mask */ + + +/*@} end of group CMSIS_PMU */ +#endif + +#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_MPU Memory Protection Unit (MPU) + \brief Type definitions for the Memory Protection Unit (MPU) + @{ + */ + +/** + \brief Structure type to access the Memory Protection Unit (MPU). + */ +typedef struct +{ + __IM uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */ + __IOM uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */ + __IOM uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region Number Register */ + __IOM uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */ + __IOM uint32_t RLAR; /*!< Offset: 0x010 (R/W) MPU Region Limit Address Register */ + __IOM uint32_t RBAR_A1; /*!< Offset: 0x014 (R/W) MPU Region Base Address Register Alias 1 */ + __IOM uint32_t RLAR_A1; /*!< Offset: 0x018 (R/W) MPU Region Limit Address Register Alias 1 */ + __IOM uint32_t RBAR_A2; /*!< Offset: 0x01C (R/W) MPU Region Base Address Register Alias 2 */ + __IOM uint32_t RLAR_A2; /*!< Offset: 0x020 (R/W) MPU Region Limit Address Register Alias 2 */ + __IOM uint32_t RBAR_A3; /*!< Offset: 0x024 (R/W) MPU Region Base Address Register Alias 3 */ + __IOM uint32_t RLAR_A3; /*!< Offset: 0x028 (R/W) MPU Region Limit Address Register Alias 3 */ + uint32_t RESERVED0[1]; + union { + __IOM uint32_t MAIR[2]; + struct { + __IOM uint32_t MAIR0; /*!< Offset: 0x030 (R/W) MPU Memory Attribute Indirection Register 0 */ + __IOM uint32_t MAIR1; /*!< Offset: 0x034 (R/W) MPU Memory Attribute Indirection Register 1 */ + }; + }; +} MPU_Type; + +#define MPU_TYPE_RALIASES 4U + +/* MPU Type Register Definitions */ +#define MPU_TYPE_IREGION_Pos 16U /*!< MPU TYPE: IREGION Position */ +#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */ + +#define MPU_TYPE_DREGION_Pos 8U /*!< MPU TYPE: DREGION Position */ +#define MPU_TYPE_DREGION_Msk (0xFFUL << MPU_TYPE_DREGION_Pos) /*!< MPU TYPE: DREGION Mask */ + +#define MPU_TYPE_SEPARATE_Pos 0U /*!< MPU TYPE: SEPARATE Position */ +#define MPU_TYPE_SEPARATE_Msk (1UL /*<< MPU_TYPE_SEPARATE_Pos*/) /*!< MPU TYPE: SEPARATE Mask */ + +/* MPU Control Register Definitions */ +#define MPU_CTRL_PRIVDEFENA_Pos 2U /*!< MPU CTRL: PRIVDEFENA Position */ +#define MPU_CTRL_PRIVDEFENA_Msk (1UL << MPU_CTRL_PRIVDEFENA_Pos) /*!< MPU CTRL: PRIVDEFENA Mask */ + +#define MPU_CTRL_HFNMIENA_Pos 1U /*!< MPU CTRL: HFNMIENA Position */ +#define MPU_CTRL_HFNMIENA_Msk (1UL << MPU_CTRL_HFNMIENA_Pos) /*!< MPU CTRL: HFNMIENA Mask */ + +#define MPU_CTRL_ENABLE_Pos 0U /*!< MPU CTRL: ENABLE Position */ +#define MPU_CTRL_ENABLE_Msk (1UL /*<< MPU_CTRL_ENABLE_Pos*/) /*!< MPU CTRL: ENABLE Mask */ + +/* MPU Region Number Register Definitions */ +#define MPU_RNR_REGION_Pos 0U /*!< MPU RNR: REGION Position */ +#define MPU_RNR_REGION_Msk (0xFFUL /*<< MPU_RNR_REGION_Pos*/) /*!< MPU RNR: REGION Mask */ + +/* MPU Region Base Address Register Definitions */ +#define MPU_RBAR_BASE_Pos 5U /*!< MPU RBAR: BASE Position */ +#define MPU_RBAR_BASE_Msk (0x7FFFFFFUL << MPU_RBAR_BASE_Pos) /*!< MPU RBAR: BASE Mask */ + +#define MPU_RBAR_SH_Pos 3U /*!< MPU RBAR: SH Position */ +#define MPU_RBAR_SH_Msk (0x3UL << MPU_RBAR_SH_Pos) /*!< MPU RBAR: SH Mask */ + +#define MPU_RBAR_AP_Pos 1U /*!< MPU RBAR: AP Position */ +#define MPU_RBAR_AP_Msk (0x3UL << MPU_RBAR_AP_Pos) /*!< MPU RBAR: AP Mask */ + +#define MPU_RBAR_XN_Pos 0U /*!< MPU RBAR: XN Position */ +#define MPU_RBAR_XN_Msk (01UL /*<< MPU_RBAR_XN_Pos*/) /*!< MPU RBAR: XN Mask */ + +/* MPU Region Limit Address Register Definitions */ +#define MPU_RLAR_LIMIT_Pos 5U /*!< MPU RLAR: LIMIT Position */ +#define MPU_RLAR_LIMIT_Msk (0x7FFFFFFUL << MPU_RLAR_LIMIT_Pos) /*!< MPU RLAR: LIMIT Mask */ + +#define MPU_RLAR_PXN_Pos 4U /*!< MPU RLAR: PXN Position */ +#define MPU_RLAR_PXN_Msk (1UL << MPU_RLAR_PXN_Pos) /*!< MPU RLAR: PXN Mask */ + +#define MPU_RLAR_AttrIndx_Pos 1U /*!< MPU RLAR: AttrIndx Position */ +#define MPU_RLAR_AttrIndx_Msk (7UL << MPU_RLAR_AttrIndx_Pos) /*!< MPU RLAR: AttrIndx Mask */ + +#define MPU_RLAR_EN_Pos 0U /*!< MPU RLAR: Region enable bit Position */ +#define MPU_RLAR_EN_Msk (1UL /*<< MPU_RLAR_EN_Pos*/) /*!< MPU RLAR: Region enable bit Disable Mask */ + +/* MPU Memory Attribute Indirection Register 0 Definitions */ +#define MPU_MAIR0_Attr3_Pos 24U /*!< MPU MAIR0: Attr3 Position */ +#define MPU_MAIR0_Attr3_Msk (0xFFUL << MPU_MAIR0_Attr3_Pos) /*!< MPU MAIR0: Attr3 Mask */ + +#define MPU_MAIR0_Attr2_Pos 16U /*!< MPU MAIR0: Attr2 Position */ +#define MPU_MAIR0_Attr2_Msk (0xFFUL << MPU_MAIR0_Attr2_Pos) /*!< MPU MAIR0: Attr2 Mask */ + +#define MPU_MAIR0_Attr1_Pos 8U /*!< MPU MAIR0: Attr1 Position */ +#define MPU_MAIR0_Attr1_Msk (0xFFUL << MPU_MAIR0_Attr1_Pos) /*!< MPU MAIR0: Attr1 Mask */ + +#define MPU_MAIR0_Attr0_Pos 0U /*!< MPU MAIR0: Attr0 Position */ +#define MPU_MAIR0_Attr0_Msk (0xFFUL /*<< MPU_MAIR0_Attr0_Pos*/) /*!< MPU MAIR0: Attr0 Mask */ + +/* MPU Memory Attribute Indirection Register 1 Definitions */ +#define MPU_MAIR1_Attr7_Pos 24U /*!< MPU MAIR1: Attr7 Position */ +#define MPU_MAIR1_Attr7_Msk (0xFFUL << MPU_MAIR1_Attr7_Pos) /*!< MPU MAIR1: Attr7 Mask */ + +#define MPU_MAIR1_Attr6_Pos 16U /*!< MPU MAIR1: Attr6 Position */ +#define MPU_MAIR1_Attr6_Msk (0xFFUL << MPU_MAIR1_Attr6_Pos) /*!< MPU MAIR1: Attr6 Mask */ + +#define MPU_MAIR1_Attr5_Pos 8U /*!< MPU MAIR1: Attr5 Position */ +#define MPU_MAIR1_Attr5_Msk (0xFFUL << MPU_MAIR1_Attr5_Pos) /*!< MPU MAIR1: Attr5 Mask */ + +#define MPU_MAIR1_Attr4_Pos 0U /*!< MPU MAIR1: Attr4 Position */ +#define MPU_MAIR1_Attr4_Msk (0xFFUL /*<< MPU_MAIR1_Attr4_Pos*/) /*!< MPU MAIR1: Attr4 Mask */ + +/*@} end of group CMSIS_MPU */ +#endif + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_SAU Security Attribution Unit (SAU) + \brief Type definitions for the Security Attribution Unit (SAU) + @{ + */ + +/** + \brief Structure type to access the Security Attribution Unit (SAU). + */ +typedef struct +{ + __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) SAU Control Register */ + __IM uint32_t TYPE; /*!< Offset: 0x004 (R/ ) SAU Type Register */ +#if defined (__SAUREGION_PRESENT) && (__SAUREGION_PRESENT == 1U) + __IOM uint32_t RNR; /*!< Offset: 0x008 (R/W) SAU Region Number Register */ + __IOM uint32_t RBAR; /*!< Offset: 0x00C (R/W) SAU Region Base Address Register */ + __IOM uint32_t RLAR; /*!< Offset: 0x010 (R/W) SAU Region Limit Address Register */ +#else + uint32_t RESERVED0[3]; +#endif + __IOM uint32_t SFSR; /*!< Offset: 0x014 (R/W) Secure Fault Status Register */ + __IOM uint32_t SFAR; /*!< Offset: 0x018 (R/W) Secure Fault Address Register */ +} SAU_Type; + +/* SAU Control Register Definitions */ +#define SAU_CTRL_ALLNS_Pos 1U /*!< SAU CTRL: ALLNS Position */ +#define SAU_CTRL_ALLNS_Msk (1UL << SAU_CTRL_ALLNS_Pos) /*!< SAU CTRL: ALLNS Mask */ + +#define SAU_CTRL_ENABLE_Pos 0U /*!< SAU CTRL: ENABLE Position */ +#define SAU_CTRL_ENABLE_Msk (1UL /*<< SAU_CTRL_ENABLE_Pos*/) /*!< SAU CTRL: ENABLE Mask */ + +/* SAU Type Register Definitions */ +#define SAU_TYPE_SREGION_Pos 0U /*!< SAU TYPE: SREGION Position */ +#define SAU_TYPE_SREGION_Msk (0xFFUL /*<< SAU_TYPE_SREGION_Pos*/) /*!< SAU TYPE: SREGION Mask */ + +#if defined (__SAUREGION_PRESENT) && (__SAUREGION_PRESENT == 1U) +/* SAU Region Number Register Definitions */ +#define SAU_RNR_REGION_Pos 0U /*!< SAU RNR: REGION Position */ +#define SAU_RNR_REGION_Msk (0xFFUL /*<< SAU_RNR_REGION_Pos*/) /*!< SAU RNR: REGION Mask */ + +/* SAU Region Base Address Register Definitions */ +#define SAU_RBAR_BADDR_Pos 5U /*!< SAU RBAR: BADDR Position */ +#define SAU_RBAR_BADDR_Msk (0x7FFFFFFUL << SAU_RBAR_BADDR_Pos) /*!< SAU RBAR: BADDR Mask */ + +/* SAU Region Limit Address Register Definitions */ +#define SAU_RLAR_LADDR_Pos 5U /*!< SAU RLAR: LADDR Position */ +#define SAU_RLAR_LADDR_Msk (0x7FFFFFFUL << SAU_RLAR_LADDR_Pos) /*!< SAU RLAR: LADDR Mask */ + +#define SAU_RLAR_NSC_Pos 1U /*!< SAU RLAR: NSC Position */ +#define SAU_RLAR_NSC_Msk (1UL << SAU_RLAR_NSC_Pos) /*!< SAU RLAR: NSC Mask */ + +#define SAU_RLAR_ENABLE_Pos 0U /*!< SAU RLAR: ENABLE Position */ +#define SAU_RLAR_ENABLE_Msk (1UL /*<< SAU_RLAR_ENABLE_Pos*/) /*!< SAU RLAR: ENABLE Mask */ + +#endif /* defined (__SAUREGION_PRESENT) && (__SAUREGION_PRESENT == 1U) */ + +/* Secure Fault Status Register Definitions */ +#define SAU_SFSR_LSERR_Pos 7U /*!< SAU SFSR: LSERR Position */ +#define SAU_SFSR_LSERR_Msk (1UL << SAU_SFSR_LSERR_Pos) /*!< SAU SFSR: LSERR Mask */ + +#define SAU_SFSR_SFARVALID_Pos 6U /*!< SAU SFSR: SFARVALID Position */ +#define SAU_SFSR_SFARVALID_Msk (1UL << SAU_SFSR_SFARVALID_Pos) /*!< SAU SFSR: SFARVALID Mask */ + +#define SAU_SFSR_LSPERR_Pos 5U /*!< SAU SFSR: LSPERR Position */ +#define SAU_SFSR_LSPERR_Msk (1UL << SAU_SFSR_LSPERR_Pos) /*!< SAU SFSR: LSPERR Mask */ + +#define SAU_SFSR_INVTRAN_Pos 4U /*!< SAU SFSR: INVTRAN Position */ +#define SAU_SFSR_INVTRAN_Msk (1UL << SAU_SFSR_INVTRAN_Pos) /*!< SAU SFSR: INVTRAN Mask */ + +#define SAU_SFSR_AUVIOL_Pos 3U /*!< SAU SFSR: AUVIOL Position */ +#define SAU_SFSR_AUVIOL_Msk (1UL << SAU_SFSR_AUVIOL_Pos) /*!< SAU SFSR: AUVIOL Mask */ + +#define SAU_SFSR_INVER_Pos 2U /*!< SAU SFSR: INVER Position */ +#define SAU_SFSR_INVER_Msk (1UL << SAU_SFSR_INVER_Pos) /*!< SAU SFSR: INVER Mask */ + +#define SAU_SFSR_INVIS_Pos 1U /*!< SAU SFSR: INVIS Position */ +#define SAU_SFSR_INVIS_Msk (1UL << SAU_SFSR_INVIS_Pos) /*!< SAU SFSR: INVIS Mask */ + +#define SAU_SFSR_INVEP_Pos 0U /*!< SAU SFSR: INVEP Position */ +#define SAU_SFSR_INVEP_Msk (1UL /*<< SAU_SFSR_INVEP_Pos*/) /*!< SAU SFSR: INVEP Mask */ + +/*@} end of group CMSIS_SAU */ +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_FPU Floating Point Unit (FPU) + \brief Type definitions for the Floating Point Unit (FPU) + @{ + */ + +/** + \brief Structure type to access the Floating Point Unit (FPU). + */ +typedef struct +{ + uint32_t RESERVED0[1U]; + __IOM uint32_t FPCCR; /*!< Offset: 0x004 (R/W) Floating-Point Context Control Register */ + __IOM uint32_t FPCAR; /*!< Offset: 0x008 (R/W) Floating-Point Context Address Register */ + __IOM uint32_t FPDSCR; /*!< Offset: 0x00C (R/W) Floating-Point Default Status Control Register */ + __IM uint32_t MVFR0; /*!< Offset: 0x010 (R/ ) Media and VFP Feature Register 0 */ + __IM uint32_t MVFR1; /*!< Offset: 0x014 (R/ ) Media and VFP Feature Register 1 */ + __IM uint32_t MVFR2; /*!< Offset: 0x018 (R/ ) Media and VFP Feature Register 2 */ +} FPU_Type; + +/* Floating-Point Context Control Register Definitions */ +#define FPU_FPCCR_ASPEN_Pos 31U /*!< FPCCR: ASPEN bit Position */ +#define FPU_FPCCR_ASPEN_Msk (1UL << FPU_FPCCR_ASPEN_Pos) /*!< FPCCR: ASPEN bit Mask */ + +#define FPU_FPCCR_LSPEN_Pos 30U /*!< FPCCR: LSPEN Position */ +#define FPU_FPCCR_LSPEN_Msk (1UL << FPU_FPCCR_LSPEN_Pos) /*!< FPCCR: LSPEN bit Mask */ + +#define FPU_FPCCR_LSPENS_Pos 29U /*!< FPCCR: LSPENS Position */ +#define FPU_FPCCR_LSPENS_Msk (1UL << FPU_FPCCR_LSPENS_Pos) /*!< FPCCR: LSPENS bit Mask */ + +#define FPU_FPCCR_CLRONRET_Pos 28U /*!< FPCCR: CLRONRET Position */ +#define FPU_FPCCR_CLRONRET_Msk (1UL << FPU_FPCCR_CLRONRET_Pos) /*!< FPCCR: CLRONRET bit Mask */ + +#define FPU_FPCCR_CLRONRETS_Pos 27U /*!< FPCCR: CLRONRETS Position */ +#define FPU_FPCCR_CLRONRETS_Msk (1UL << FPU_FPCCR_CLRONRETS_Pos) /*!< FPCCR: CLRONRETS bit Mask */ + +#define FPU_FPCCR_TS_Pos 26U /*!< FPCCR: TS Position */ +#define FPU_FPCCR_TS_Msk (1UL << FPU_FPCCR_TS_Pos) /*!< FPCCR: TS bit Mask */ + +#define FPU_FPCCR_UFRDY_Pos 10U /*!< FPCCR: UFRDY Position */ +#define FPU_FPCCR_UFRDY_Msk (1UL << FPU_FPCCR_UFRDY_Pos) /*!< FPCCR: UFRDY bit Mask */ + +#define FPU_FPCCR_SPLIMVIOL_Pos 9U /*!< FPCCR: SPLIMVIOL Position */ +#define FPU_FPCCR_SPLIMVIOL_Msk (1UL << FPU_FPCCR_SPLIMVIOL_Pos) /*!< FPCCR: SPLIMVIOL bit Mask */ + +#define FPU_FPCCR_MONRDY_Pos 8U /*!< FPCCR: MONRDY Position */ +#define FPU_FPCCR_MONRDY_Msk (1UL << FPU_FPCCR_MONRDY_Pos) /*!< FPCCR: MONRDY bit Mask */ + +#define FPU_FPCCR_SFRDY_Pos 7U /*!< FPCCR: SFRDY Position */ +#define FPU_FPCCR_SFRDY_Msk (1UL << FPU_FPCCR_SFRDY_Pos) /*!< FPCCR: SFRDY bit Mask */ + +#define FPU_FPCCR_BFRDY_Pos 6U /*!< FPCCR: BFRDY Position */ +#define FPU_FPCCR_BFRDY_Msk (1UL << FPU_FPCCR_BFRDY_Pos) /*!< FPCCR: BFRDY bit Mask */ + +#define FPU_FPCCR_MMRDY_Pos 5U /*!< FPCCR: MMRDY Position */ +#define FPU_FPCCR_MMRDY_Msk (1UL << FPU_FPCCR_MMRDY_Pos) /*!< FPCCR: MMRDY bit Mask */ + +#define FPU_FPCCR_HFRDY_Pos 4U /*!< FPCCR: HFRDY Position */ +#define FPU_FPCCR_HFRDY_Msk (1UL << FPU_FPCCR_HFRDY_Pos) /*!< FPCCR: HFRDY bit Mask */ + +#define FPU_FPCCR_THREAD_Pos 3U /*!< FPCCR: processor mode bit Position */ +#define FPU_FPCCR_THREAD_Msk (1UL << FPU_FPCCR_THREAD_Pos) /*!< FPCCR: processor mode active bit Mask */ + +#define FPU_FPCCR_S_Pos 2U /*!< FPCCR: Security status of the FP context bit Position */ +#define FPU_FPCCR_S_Msk (1UL << FPU_FPCCR_S_Pos) /*!< FPCCR: Security status of the FP context bit Mask */ + +#define FPU_FPCCR_USER_Pos 1U /*!< FPCCR: privilege level bit Position */ +#define FPU_FPCCR_USER_Msk (1UL << FPU_FPCCR_USER_Pos) /*!< FPCCR: privilege level bit Mask */ + +#define FPU_FPCCR_LSPACT_Pos 0U /*!< FPCCR: Lazy state preservation active bit Position */ +#define FPU_FPCCR_LSPACT_Msk (1UL /*<< FPU_FPCCR_LSPACT_Pos*/) /*!< FPCCR: Lazy state preservation active bit Mask */ + +/* Floating-Point Context Address Register Definitions */ +#define FPU_FPCAR_ADDRESS_Pos 3U /*!< FPCAR: ADDRESS bit Position */ +#define FPU_FPCAR_ADDRESS_Msk (0x1FFFFFFFUL << FPU_FPCAR_ADDRESS_Pos) /*!< FPCAR: ADDRESS bit Mask */ + +/* Floating-Point Default Status Control Register Definitions */ +#define FPU_FPDSCR_AHP_Pos 26U /*!< FPDSCR: AHP bit Position */ +#define FPU_FPDSCR_AHP_Msk (1UL << FPU_FPDSCR_AHP_Pos) /*!< FPDSCR: AHP bit Mask */ + +#define FPU_FPDSCR_DN_Pos 25U /*!< FPDSCR: DN bit Position */ +#define FPU_FPDSCR_DN_Msk (1UL << FPU_FPDSCR_DN_Pos) /*!< FPDSCR: DN bit Mask */ + +#define FPU_FPDSCR_FZ_Pos 24U /*!< FPDSCR: FZ bit Position */ +#define FPU_FPDSCR_FZ_Msk (1UL << FPU_FPDSCR_FZ_Pos) /*!< FPDSCR: FZ bit Mask */ + +#define FPU_FPDSCR_RMode_Pos 22U /*!< FPDSCR: RMode bit Position */ +#define FPU_FPDSCR_RMode_Msk (3UL << FPU_FPDSCR_RMode_Pos) /*!< FPDSCR: RMode bit Mask */ + +#define FPU_FPDSCR_FZ16_Pos 19U /*!< FPDSCR: FZ16 bit Position */ +#define FPU_FPDSCR_FZ16_Msk (1UL << FPU_FPDSCR_FZ16_Pos) /*!< FPDSCR: FZ16 bit Mask */ + +#define FPU_FPDSCR_LTPSIZE_Pos 16U /*!< FPDSCR: LTPSIZE bit Position */ +#define FPU_FPDSCR_LTPSIZE_Msk (7UL << FPU_FPDSCR_LTPSIZE_Pos) /*!< FPDSCR: LTPSIZE bit Mask */ + +/* Media and VFP Feature Register 0 Definitions */ +#define FPU_MVFR0_FPRound_Pos 28U /*!< MVFR0: FPRound bits Position */ +#define FPU_MVFR0_FPRound_Msk (0xFUL << FPU_MVFR0_FPRound_Pos) /*!< MVFR0: FPRound bits Mask */ + +#define FPU_MVFR0_FPSqrt_Pos 20U /*!< MVFR0: FPSqrt bits Position */ +#define FPU_MVFR0_FPSqrt_Msk (0xFUL << FPU_MVFR0_FPSqrt_Pos) /*!< MVFR0: FPSqrt bits Mask */ + +#define FPU_MVFR0_FPDivide_Pos 16U /*!< MVFR0: FPDivide bits Position */ +#define FPU_MVFR0_FPDivide_Msk (0xFUL << FPU_MVFR0_FPDivide_Pos) /*!< MVFR0: Divide bits Mask */ + +#define FPU_MVFR0_FPDP_Pos 8U /*!< MVFR0: FPDP bits Position */ +#define FPU_MVFR0_FPDP_Msk (0xFUL << FPU_MVFR0_FPDP_Pos) /*!< MVFR0: FPDP bits Mask */ + +#define FPU_MVFR0_FPSP_Pos 4U /*!< MVFR0: FPSP bits Position */ +#define FPU_MVFR0_FPSP_Msk (0xFUL << FPU_MVFR0_FPSP_Pos) /*!< MVFR0: FPSP bits Mask */ + +#define FPU_MVFR0_SIMDReg_Pos 0U /*!< MVFR0: SIMDReg bits Position */ +#define FPU_MVFR0_SIMDReg_Msk (0xFUL /*<< FPU_MVFR0_SIMDReg_Pos*/) /*!< MVFR0: SIMDReg bits Mask */ + +/* Media and VFP Feature Register 1 Definitions */ +#define FPU_MVFR1_FMAC_Pos 28U /*!< MVFR1: FMAC bits Position */ +#define FPU_MVFR1_FMAC_Msk (0xFUL << FPU_MVFR1_FMAC_Pos) /*!< MVFR1: FMAC bits Mask */ + +#define FPU_MVFR1_FPHP_Pos 24U /*!< MVFR1: FPHP bits Position */ +#define FPU_MVFR1_FPHP_Msk (0xFUL << FPU_MVFR1_FPHP_Pos) /*!< MVFR1: FPHP bits Mask */ + +#define FPU_MVFR1_FP16_Pos 20U /*!< MVFR1: FP16 bits Position */ +#define FPU_MVFR1_FP16_Msk (0xFUL << FPU_MVFR1_FP16_Pos) /*!< MVFR1: FP16 bits Mask */ + +#define FPU_MVFR1_MVE_Pos 8U /*!< MVFR1: MVE bits Position */ +#define FPU_MVFR1_MVE_Msk (0xFUL << FPU_MVFR1_MVE_Pos) /*!< MVFR1: MVE bits Mask */ + +#define FPU_MVFR1_FPDNaN_Pos 4U /*!< MVFR1: FPDNaN bits Position */ +#define FPU_MVFR1_FPDNaN_Msk (0xFUL << FPU_MVFR1_FPDNaN_Pos) /*!< MVFR1: FPDNaN bits Mask */ + +#define FPU_MVFR1_FPFtZ_Pos 0U /*!< MVFR1: FPFtZ bits Position */ +#define FPU_MVFR1_FPFtZ_Msk (0xFUL /*<< FPU_MVFR1_FPFtZ_Pos*/) /*!< MVFR1: FPFtZ bits Mask */ + +/* Media and VFP Feature Register 2 Definitions */ +#define FPU_MVFR2_FPMisc_Pos 4U /*!< MVFR2: FPMisc bits Position */ +#define FPU_MVFR2_FPMisc_Msk (0xFUL << FPU_MVFR2_FPMisc_Pos) /*!< MVFR2: FPMisc bits Mask */ + +/*@} end of group CMSIS_FPU */ + +/* CoreDebug is deprecated. replaced by DCB (Debug Control Block) */ +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug) + \brief Type definitions for the Core Debug Registers + @{ + */ + +/** + \brief \deprecated Structure type to access the Core Debug Register (CoreDebug). + */ +typedef struct +{ + __IOM uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */ + __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ + __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ + __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ + __OM uint32_t DSCEMCR; /*!< Offset: 0x010 ( /W) Debug Set Clear Exception and Monitor Control Register */ + __IOM uint32_t DAUTHCTRL; /*!< Offset: 0x014 (R/W) Debug Authentication Control Register */ + __IOM uint32_t DSCSR; /*!< Offset: 0x018 (R/W) Debug Security Control and Status Register */ +} CoreDebug_Type; + +/* Debug Halting Control and Status Register Definitions */ +#define CoreDebug_DHCSR_DBGKEY_Pos 16U /*!< \deprecated CoreDebug DHCSR: DBGKEY Position */ +#define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos) /*!< \deprecated CoreDebug DHCSR: DBGKEY Mask */ + +#define CoreDebug_DHCSR_S_RESTART_ST_Pos 26U /*!< \deprecated CoreDebug DHCSR: S_RESTART_ST Position */ +#define CoreDebug_DHCSR_S_RESTART_ST_Msk (1UL << CoreDebug_DHCSR_S_RESTART_ST_Pos) /*!< \deprecated CoreDebug DHCSR: S_RESTART_ST Mask */ + +#define CoreDebug_DHCSR_S_RESET_ST_Pos 25U /*!< \deprecated CoreDebug DHCSR: S_RESET_ST Position */ +#define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< \deprecated CoreDebug DHCSR: S_RESET_ST Mask */ + +#define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24U /*!< \deprecated CoreDebug DHCSR: S_RETIRE_ST Position */ +#define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< \deprecated CoreDebug DHCSR: S_RETIRE_ST Mask */ + +#define CoreDebug_DHCSR_S_FPD_Pos 23U /*!< \deprecated CoreDebug DHCSR: S_FPD Position */ +#define CoreDebug_DHCSR_S_FPD_Msk (1UL << CoreDebug_DHCSR_S_FPD_Pos) /*!< \deprecated CoreDebug DHCSR: S_FPD Mask */ + +#define CoreDebug_DHCSR_S_SUIDE_Pos 22U /*!< \deprecated CoreDebug DHCSR: S_SUIDE Position */ +#define CoreDebug_DHCSR_S_SUIDE_Msk (1UL << CoreDebug_DHCSR_S_SUIDE_Pos) /*!< \deprecated CoreDebug DHCSR: S_SUIDE Mask */ + +#define CoreDebug_DHCSR_S_NSUIDE_Pos 21U /*!< \deprecated CoreDebug DHCSR: S_NSUIDE Position */ +#define CoreDebug_DHCSR_S_NSUIDE_Msk (1UL << CoreDebug_DHCSR_S_NSUIDE_Pos) /*!< \deprecated CoreDebug DHCSR: S_NSUIDE Mask */ + +#define CoreDebug_DHCSR_S_SDE_Pos 20U /*!< \deprecated CoreDebug DHCSR: S_SDE Position */ +#define CoreDebug_DHCSR_S_SDE_Msk (1UL << CoreDebug_DHCSR_S_SDE_Pos) /*!< \deprecated CoreDebug DHCSR: S_SDE Mask */ + +#define CoreDebug_DHCSR_S_LOCKUP_Pos 19U /*!< \deprecated CoreDebug DHCSR: S_LOCKUP Position */ +#define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< \deprecated CoreDebug DHCSR: S_LOCKUP Mask */ + +#define CoreDebug_DHCSR_S_SLEEP_Pos 18U /*!< \deprecated CoreDebug DHCSR: S_SLEEP Position */ +#define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< \deprecated CoreDebug DHCSR: S_SLEEP Mask */ + +#define CoreDebug_DHCSR_S_HALT_Pos 17U /*!< \deprecated CoreDebug DHCSR: S_HALT Position */ +#define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos) /*!< \deprecated CoreDebug DHCSR: S_HALT Mask */ + +#define CoreDebug_DHCSR_S_REGRDY_Pos 16U /*!< \deprecated CoreDebug DHCSR: S_REGRDY Position */ +#define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< \deprecated CoreDebug DHCSR: S_REGRDY Mask */ + +#define CoreDebug_DHCSR_C_PMOV_Pos 6U /*!< \deprecated CoreDebug DHCSR: C_PMOV Position */ +#define CoreDebug_DHCSR_C_PMOV_Msk (1UL << CoreDebug_DHCSR_C_PMOV_Pos) /*!< \deprecated CoreDebug DHCSR: C_PMOV Mask */ + +#define CoreDebug_DHCSR_C_SNAPSTALL_Pos 5U /*!< \deprecated CoreDebug DHCSR: C_SNAPSTALL Position */ +#define CoreDebug_DHCSR_C_SNAPSTALL_Msk (1UL << CoreDebug_DHCSR_C_SNAPSTALL_Pos) /*!< \deprecated CoreDebug DHCSR: C_SNAPSTALL Mask */ + +#define CoreDebug_DHCSR_C_MASKINTS_Pos 3U /*!< \deprecated CoreDebug DHCSR: C_MASKINTS Position */ +#define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< \deprecated CoreDebug DHCSR: C_MASKINTS Mask */ + +#define CoreDebug_DHCSR_C_STEP_Pos 2U /*!< \deprecated CoreDebug DHCSR: C_STEP Position */ +#define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos) /*!< \deprecated CoreDebug DHCSR: C_STEP Mask */ + +#define CoreDebug_DHCSR_C_HALT_Pos 1U /*!< \deprecated CoreDebug DHCSR: C_HALT Position */ +#define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos) /*!< \deprecated CoreDebug DHCSR: C_HALT Mask */ + +#define CoreDebug_DHCSR_C_DEBUGEN_Pos 0U /*!< \deprecated CoreDebug DHCSR: C_DEBUGEN Position */ +#define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL /*<< CoreDebug_DHCSR_C_DEBUGEN_Pos*/) /*!< \deprecated CoreDebug DHCSR: C_DEBUGEN Mask */ + +/* Debug Core Register Selector Register Definitions */ +#define CoreDebug_DCRSR_REGWnR_Pos 16U /*!< \deprecated CoreDebug DCRSR: REGWnR Position */ +#define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos) /*!< \deprecated CoreDebug DCRSR: REGWnR Mask */ + +#define CoreDebug_DCRSR_REGSEL_Pos 0U /*!< \deprecated CoreDebug DCRSR: REGSEL Position */ +#define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL /*<< CoreDebug_DCRSR_REGSEL_Pos*/) /*!< \deprecated CoreDebug DCRSR: REGSEL Mask */ + +/* Debug Exception and Monitor Control Register Definitions */ +#define CoreDebug_DEMCR_TRCENA_Pos 24U /*!< \deprecated CoreDebug DEMCR: TRCENA Position */ +#define CoreDebug_DEMCR_TRCENA_Msk (1UL << CoreDebug_DEMCR_TRCENA_Pos) /*!< \deprecated CoreDebug DEMCR: TRCENA Mask */ + +#define CoreDebug_DEMCR_MON_REQ_Pos 19U /*!< \deprecated CoreDebug DEMCR: MON_REQ Position */ +#define CoreDebug_DEMCR_MON_REQ_Msk (1UL << CoreDebug_DEMCR_MON_REQ_Pos) /*!< \deprecated CoreDebug DEMCR: MON_REQ Mask */ + +#define CoreDebug_DEMCR_MON_STEP_Pos 18U /*!< \deprecated CoreDebug DEMCR: MON_STEP Position */ +#define CoreDebug_DEMCR_MON_STEP_Msk (1UL << CoreDebug_DEMCR_MON_STEP_Pos) /*!< \deprecated CoreDebug DEMCR: MON_STEP Mask */ + +#define CoreDebug_DEMCR_MON_PEND_Pos 17U /*!< \deprecated CoreDebug DEMCR: MON_PEND Position */ +#define CoreDebug_DEMCR_MON_PEND_Msk (1UL << CoreDebug_DEMCR_MON_PEND_Pos) /*!< \deprecated CoreDebug DEMCR: MON_PEND Mask */ + +#define CoreDebug_DEMCR_MON_EN_Pos 16U /*!< \deprecated CoreDebug DEMCR: MON_EN Position */ +#define CoreDebug_DEMCR_MON_EN_Msk (1UL << CoreDebug_DEMCR_MON_EN_Pos) /*!< \deprecated CoreDebug DEMCR: MON_EN Mask */ + +#define CoreDebug_DEMCR_VC_HARDERR_Pos 10U /*!< \deprecated CoreDebug DEMCR: VC_HARDERR Position */ +#define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_HARDERR Mask */ + +#define CoreDebug_DEMCR_VC_INTERR_Pos 9U /*!< \deprecated CoreDebug DEMCR: VC_INTERR Position */ +#define CoreDebug_DEMCR_VC_INTERR_Msk (1UL << CoreDebug_DEMCR_VC_INTERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_INTERR Mask */ + +#define CoreDebug_DEMCR_VC_BUSERR_Pos 8U /*!< \deprecated CoreDebug DEMCR: VC_BUSERR Position */ +#define CoreDebug_DEMCR_VC_BUSERR_Msk (1UL << CoreDebug_DEMCR_VC_BUSERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_BUSERR Mask */ + +#define CoreDebug_DEMCR_VC_STATERR_Pos 7U /*!< \deprecated CoreDebug DEMCR: VC_STATERR Position */ +#define CoreDebug_DEMCR_VC_STATERR_Msk (1UL << CoreDebug_DEMCR_VC_STATERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_STATERR Mask */ + +#define CoreDebug_DEMCR_VC_CHKERR_Pos 6U /*!< \deprecated CoreDebug DEMCR: VC_CHKERR Position */ +#define CoreDebug_DEMCR_VC_CHKERR_Msk (1UL << CoreDebug_DEMCR_VC_CHKERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_CHKERR Mask */ + +#define CoreDebug_DEMCR_VC_NOCPERR_Pos 5U /*!< \deprecated CoreDebug DEMCR: VC_NOCPERR Position */ +#define CoreDebug_DEMCR_VC_NOCPERR_Msk (1UL << CoreDebug_DEMCR_VC_NOCPERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_NOCPERR Mask */ + +#define CoreDebug_DEMCR_VC_MMERR_Pos 4U /*!< \deprecated CoreDebug DEMCR: VC_MMERR Position */ +#define CoreDebug_DEMCR_VC_MMERR_Msk (1UL << CoreDebug_DEMCR_VC_MMERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_MMERR Mask */ + +#define CoreDebug_DEMCR_VC_CORERESET_Pos 0U /*!< \deprecated CoreDebug DEMCR: VC_CORERESET Position */ +#define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL /*<< CoreDebug_DEMCR_VC_CORERESET_Pos*/) /*!< \deprecated CoreDebug DEMCR: VC_CORERESET Mask */ + +/* Debug Set Clear Exception and Monitor Control Register Definitions */ +#define CoreDebug_DSCEMCR_CLR_MON_REQ_Pos 19U /*!< \deprecated CoreDebug DSCEMCR: CLR_MON_REQ, Position */ +#define CoreDebug_DSCEMCR_CLR_MON_REQ_Msk (1UL << CoreDebug_DSCEMCR_CLR_MON_REQ_Pos) /*!< \deprecated CoreDebug DSCEMCR: CLR_MON_REQ, Mask */ + +#define CoreDebug_DSCEMCR_CLR_MON_PEND_Pos 17U /*!< \deprecated CoreDebug DSCEMCR: CLR_MON_PEND, Position */ +#define CoreDebug_DSCEMCR_CLR_MON_PEND_Msk (1UL << CoreDebug_DSCEMCR_CLR_MON_PEND_Pos) /*!< \deprecated CoreDebug DSCEMCR: CLR_MON_PEND, Mask */ + +#define CoreDebug_DSCEMCR_SET_MON_REQ_Pos 3U /*!< \deprecated CoreDebug DSCEMCR: SET_MON_REQ, Position */ +#define CoreDebug_DSCEMCR_SET_MON_REQ_Msk (1UL << CoreDebug_DSCEMCR_SET_MON_REQ_Pos) /*!< \deprecated CoreDebug DSCEMCR: SET_MON_REQ, Mask */ + +#define CoreDebug_DSCEMCR_SET_MON_PEND_Pos 1U /*!< \deprecated CoreDebug DSCEMCR: SET_MON_PEND, Position */ +#define CoreDebug_DSCEMCR_SET_MON_PEND_Msk (1UL << CoreDebug_DSCEMCR_SET_MON_PEND_Pos) /*!< \deprecated CoreDebug DSCEMCR: SET_MON_PEND, Mask */ + +/* Debug Authentication Control Register Definitions */ +#define CoreDebug_DAUTHCTRL_UIDEN_Pos 10U /*!< \deprecated CoreDebug DAUTHCTRL: UIDEN, Position */ +#define CoreDebug_DAUTHCTRL_UIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_UIDEN_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: UIDEN, Mask */ + +#define CoreDebug_DAUTHCTRL_UIDAPEN_Pos 9U /*!< \deprecated CoreDebug DAUTHCTRL: UIDAPEN, Position */ +#define CoreDebug_DAUTHCTRL_UIDAPEN_Msk (1UL << CoreDebug_DAUTHCTRL_UIDAPEN_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: UIDAPEN, Mask */ + +#define CoreDebug_DAUTHCTRL_FSDMA_Pos 8U /*!< \deprecated CoreDebug DAUTHCTRL: FSDMA, Position */ +#define CoreDebug_DAUTHCTRL_FSDMA_Msk (1UL << CoreDebug_DAUTHCTRL_FSDMA_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: FSDMA, Mask */ + +#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos 3U /*!< \deprecated CoreDebug DAUTHCTRL: INTSPNIDEN, Position */ +#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: INTSPNIDEN, Mask */ + +#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos 2U /*!< \deprecated CoreDebug DAUTHCTRL: SPNIDENSEL Position */ +#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Msk (1UL << CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: SPNIDENSEL Mask */ + +#define CoreDebug_DAUTHCTRL_INTSPIDEN_Pos 1U /*!< \deprecated CoreDebug DAUTHCTRL: INTSPIDEN Position */ +#define CoreDebug_DAUTHCTRL_INTSPIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPIDEN_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: INTSPIDEN Mask */ + +#define CoreDebug_DAUTHCTRL_SPIDENSEL_Pos 0U /*!< \deprecated CoreDebug DAUTHCTRL: SPIDENSEL Position */ +#define CoreDebug_DAUTHCTRL_SPIDENSEL_Msk (1UL /*<< CoreDebug_DAUTHCTRL_SPIDENSEL_Pos*/) /*!< \deprecated CoreDebug DAUTHCTRL: SPIDENSEL Mask */ + +/* Debug Security Control and Status Register Definitions */ +#define CoreDebug_DSCSR_CDS_Pos 16U /*!< \deprecated CoreDebug DSCSR: CDS Position */ +#define CoreDebug_DSCSR_CDS_Msk (1UL << CoreDebug_DSCSR_CDS_Pos) /*!< \deprecated CoreDebug DSCSR: CDS Mask */ + +#define CoreDebug_DSCSR_SBRSEL_Pos 1U /*!< \deprecated CoreDebug DSCSR: SBRSEL Position */ +#define CoreDebug_DSCSR_SBRSEL_Msk (1UL << CoreDebug_DSCSR_SBRSEL_Pos) /*!< \deprecated CoreDebug DSCSR: SBRSEL Mask */ + +#define CoreDebug_DSCSR_SBRSELEN_Pos 0U /*!< \deprecated CoreDebug DSCSR: SBRSELEN Position */ +#define CoreDebug_DSCSR_SBRSELEN_Msk (1UL /*<< CoreDebug_DSCSR_SBRSELEN_Pos*/) /*!< \deprecated CoreDebug DSCSR: SBRSELEN Mask */ + +/*@} end of group CMSIS_CoreDebug */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_DCB Debug Control Block + \brief Type definitions for the Debug Control Block Registers + @{ + */ + +/** + \brief Structure type to access the Debug Control Block Registers (DCB). + */ +typedef struct +{ + __IOM uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */ + __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ + __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ + __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ + __OM uint32_t DSCEMCR; /*!< Offset: 0x010 ( /W) Debug Set Clear Exception and Monitor Control Register */ + __IOM uint32_t DAUTHCTRL; /*!< Offset: 0x014 (R/W) Debug Authentication Control Register */ + __IOM uint32_t DSCSR; /*!< Offset: 0x018 (R/W) Debug Security Control and Status Register */ +} DCB_Type; + +/* DHCSR, Debug Halting Control and Status Register Definitions */ +#define DCB_DHCSR_DBGKEY_Pos 16U /*!< DCB DHCSR: Debug key Position */ +#define DCB_DHCSR_DBGKEY_Msk (0xFFFFUL << DCB_DHCSR_DBGKEY_Pos) /*!< DCB DHCSR: Debug key Mask */ + +#define DCB_DHCSR_S_RESTART_ST_Pos 26U /*!< DCB DHCSR: Restart sticky status Position */ +#define DCB_DHCSR_S_RESTART_ST_Msk (0x1UL << DCB_DHCSR_S_RESTART_ST_Pos) /*!< DCB DHCSR: Restart sticky status Mask */ + +#define DCB_DHCSR_S_RESET_ST_Pos 25U /*!< DCB DHCSR: Reset sticky status Position */ +#define DCB_DHCSR_S_RESET_ST_Msk (0x1UL << DCB_DHCSR_S_RESET_ST_Pos) /*!< DCB DHCSR: Reset sticky status Mask */ + +#define DCB_DHCSR_S_RETIRE_ST_Pos 24U /*!< DCB DHCSR: Retire sticky status Position */ +#define DCB_DHCSR_S_RETIRE_ST_Msk (0x1UL << DCB_DHCSR_S_RETIRE_ST_Pos) /*!< DCB DHCSR: Retire sticky status Mask */ + +#define DCB_DHCSR_S_FPD_Pos 23U /*!< DCB DHCSR: Floating-point registers Debuggable Position */ +#define DCB_DHCSR_S_FPD_Msk (0x1UL << DCB_DHCSR_S_FPD_Pos) /*!< DCB DHCSR: Floating-point registers Debuggable Mask */ + +#define DCB_DHCSR_S_SUIDE_Pos 22U /*!< DCB DHCSR: Secure unprivileged halting debug enabled Position */ +#define DCB_DHCSR_S_SUIDE_Msk (0x1UL << DCB_DHCSR_S_SUIDE_Pos) /*!< DCB DHCSR: Secure unprivileged halting debug enabled Mask */ + +#define DCB_DHCSR_S_NSUIDE_Pos 21U /*!< DCB DHCSR: Non-secure unprivileged halting debug enabled Position */ +#define DCB_DHCSR_S_NSUIDE_Msk (0x1UL << DCB_DHCSR_S_NSUIDE_Pos) /*!< DCB DHCSR: Non-secure unprivileged halting debug enabled Mask */ + +#define DCB_DHCSR_S_SDE_Pos 20U /*!< DCB DHCSR: Secure debug enabled Position */ +#define DCB_DHCSR_S_SDE_Msk (0x1UL << DCB_DHCSR_S_SDE_Pos) /*!< DCB DHCSR: Secure debug enabled Mask */ + +#define DCB_DHCSR_S_LOCKUP_Pos 19U /*!< DCB DHCSR: Lockup status Position */ +#define DCB_DHCSR_S_LOCKUP_Msk (0x1UL << DCB_DHCSR_S_LOCKUP_Pos) /*!< DCB DHCSR: Lockup status Mask */ + +#define DCB_DHCSR_S_SLEEP_Pos 18U /*!< DCB DHCSR: Sleeping status Position */ +#define DCB_DHCSR_S_SLEEP_Msk (0x1UL << DCB_DHCSR_S_SLEEP_Pos) /*!< DCB DHCSR: Sleeping status Mask */ + +#define DCB_DHCSR_S_HALT_Pos 17U /*!< DCB DHCSR: Halted status Position */ +#define DCB_DHCSR_S_HALT_Msk (0x1UL << DCB_DHCSR_S_HALT_Pos) /*!< DCB DHCSR: Halted status Mask */ + +#define DCB_DHCSR_S_REGRDY_Pos 16U /*!< DCB DHCSR: Register ready status Position */ +#define DCB_DHCSR_S_REGRDY_Msk (0x1UL << DCB_DHCSR_S_REGRDY_Pos) /*!< DCB DHCSR: Register ready status Mask */ + +#define DCB_DHCSR_C_PMOV_Pos 6U /*!< DCB DHCSR: Halt on PMU overflow control Position */ +#define DCB_DHCSR_C_PMOV_Msk (0x1UL << DCB_DHCSR_C_PMOV_Pos) /*!< DCB DHCSR: Halt on PMU overflow control Mask */ + +#define DCB_DHCSR_C_SNAPSTALL_Pos 5U /*!< DCB DHCSR: Snap stall control Position */ +#define DCB_DHCSR_C_SNAPSTALL_Msk (0x1UL << DCB_DHCSR_C_SNAPSTALL_Pos) /*!< DCB DHCSR: Snap stall control Mask */ + +#define DCB_DHCSR_C_MASKINTS_Pos 3U /*!< DCB DHCSR: Mask interrupts control Position */ +#define DCB_DHCSR_C_MASKINTS_Msk (0x1UL << DCB_DHCSR_C_MASKINTS_Pos) /*!< DCB DHCSR: Mask interrupts control Mask */ + +#define DCB_DHCSR_C_STEP_Pos 2U /*!< DCB DHCSR: Step control Position */ +#define DCB_DHCSR_C_STEP_Msk (0x1UL << DCB_DHCSR_C_STEP_Pos) /*!< DCB DHCSR: Step control Mask */ + +#define DCB_DHCSR_C_HALT_Pos 1U /*!< DCB DHCSR: Halt control Position */ +#define DCB_DHCSR_C_HALT_Msk (0x1UL << DCB_DHCSR_C_HALT_Pos) /*!< DCB DHCSR: Halt control Mask */ + +#define DCB_DHCSR_C_DEBUGEN_Pos 0U /*!< DCB DHCSR: Debug enable control Position */ +#define DCB_DHCSR_C_DEBUGEN_Msk (0x1UL /*<< DCB_DHCSR_C_DEBUGEN_Pos*/) /*!< DCB DHCSR: Debug enable control Mask */ + +/* DCRSR, Debug Core Register Select Register Definitions */ +#define DCB_DCRSR_REGWnR_Pos 16U /*!< DCB DCRSR: Register write/not-read Position */ +#define DCB_DCRSR_REGWnR_Msk (0x1UL << DCB_DCRSR_REGWnR_Pos) /*!< DCB DCRSR: Register write/not-read Mask */ + +#define DCB_DCRSR_REGSEL_Pos 0U /*!< DCB DCRSR: Register selector Position */ +#define DCB_DCRSR_REGSEL_Msk (0x7FUL /*<< DCB_DCRSR_REGSEL_Pos*/) /*!< DCB DCRSR: Register selector Mask */ + +/* DCRDR, Debug Core Register Data Register Definitions */ +#define DCB_DCRDR_DBGTMP_Pos 0U /*!< DCB DCRDR: Data temporary buffer Position */ +#define DCB_DCRDR_DBGTMP_Msk (0xFFFFFFFFUL /*<< DCB_DCRDR_DBGTMP_Pos*/) /*!< DCB DCRDR: Data temporary buffer Mask */ + +/* DEMCR, Debug Exception and Monitor Control Register Definitions */ +#define DCB_DEMCR_TRCENA_Pos 24U /*!< DCB DEMCR: Trace enable Position */ +#define DCB_DEMCR_TRCENA_Msk (0x1UL << DCB_DEMCR_TRCENA_Pos) /*!< DCB DEMCR: Trace enable Mask */ + +#define DCB_DEMCR_MONPRKEY_Pos 23U /*!< DCB DEMCR: Monitor pend req key Position */ +#define DCB_DEMCR_MONPRKEY_Msk (0x1UL << DCB_DEMCR_MONPRKEY_Pos) /*!< DCB DEMCR: Monitor pend req key Mask */ + +#define DCB_DEMCR_UMON_EN_Pos 21U /*!< DCB DEMCR: Unprivileged monitor enable Position */ +#define DCB_DEMCR_UMON_EN_Msk (0x1UL << DCB_DEMCR_UMON_EN_Pos) /*!< DCB DEMCR: Unprivileged monitor enable Mask */ + +#define DCB_DEMCR_SDME_Pos 20U /*!< DCB DEMCR: Secure DebugMonitor enable Position */ +#define DCB_DEMCR_SDME_Msk (0x1UL << DCB_DEMCR_SDME_Pos) /*!< DCB DEMCR: Secure DebugMonitor enable Mask */ + +#define DCB_DEMCR_MON_REQ_Pos 19U /*!< DCB DEMCR: Monitor request Position */ +#define DCB_DEMCR_MON_REQ_Msk (0x1UL << DCB_DEMCR_MON_REQ_Pos) /*!< DCB DEMCR: Monitor request Mask */ + +#define DCB_DEMCR_MON_STEP_Pos 18U /*!< DCB DEMCR: Monitor step Position */ +#define DCB_DEMCR_MON_STEP_Msk (0x1UL << DCB_DEMCR_MON_STEP_Pos) /*!< DCB DEMCR: Monitor step Mask */ + +#define DCB_DEMCR_MON_PEND_Pos 17U /*!< DCB DEMCR: Monitor pend Position */ +#define DCB_DEMCR_MON_PEND_Msk (0x1UL << DCB_DEMCR_MON_PEND_Pos) /*!< DCB DEMCR: Monitor pend Mask */ + +#define DCB_DEMCR_MON_EN_Pos 16U /*!< DCB DEMCR: Monitor enable Position */ +#define DCB_DEMCR_MON_EN_Msk (0x1UL << DCB_DEMCR_MON_EN_Pos) /*!< DCB DEMCR: Monitor enable Mask */ + +#define DCB_DEMCR_VC_SFERR_Pos 11U /*!< DCB DEMCR: Vector Catch SecureFault Position */ +#define DCB_DEMCR_VC_SFERR_Msk (0x1UL << DCB_DEMCR_VC_SFERR_Pos) /*!< DCB DEMCR: Vector Catch SecureFault Mask */ + +#define DCB_DEMCR_VC_HARDERR_Pos 10U /*!< DCB DEMCR: Vector Catch HardFault errors Position */ +#define DCB_DEMCR_VC_HARDERR_Msk (0x1UL << DCB_DEMCR_VC_HARDERR_Pos) /*!< DCB DEMCR: Vector Catch HardFault errors Mask */ + +#define DCB_DEMCR_VC_INTERR_Pos 9U /*!< DCB DEMCR: Vector Catch interrupt errors Position */ +#define DCB_DEMCR_VC_INTERR_Msk (0x1UL << DCB_DEMCR_VC_INTERR_Pos) /*!< DCB DEMCR: Vector Catch interrupt errors Mask */ + +#define DCB_DEMCR_VC_BUSERR_Pos 8U /*!< DCB DEMCR: Vector Catch BusFault errors Position */ +#define DCB_DEMCR_VC_BUSERR_Msk (0x1UL << DCB_DEMCR_VC_BUSERR_Pos) /*!< DCB DEMCR: Vector Catch BusFault errors Mask */ + +#define DCB_DEMCR_VC_STATERR_Pos 7U /*!< DCB DEMCR: Vector Catch state errors Position */ +#define DCB_DEMCR_VC_STATERR_Msk (0x1UL << DCB_DEMCR_VC_STATERR_Pos) /*!< DCB DEMCR: Vector Catch state errors Mask */ + +#define DCB_DEMCR_VC_CHKERR_Pos 6U /*!< DCB DEMCR: Vector Catch check errors Position */ +#define DCB_DEMCR_VC_CHKERR_Msk (0x1UL << DCB_DEMCR_VC_CHKERR_Pos) /*!< DCB DEMCR: Vector Catch check errors Mask */ + +#define DCB_DEMCR_VC_NOCPERR_Pos 5U /*!< DCB DEMCR: Vector Catch NOCP errors Position */ +#define DCB_DEMCR_VC_NOCPERR_Msk (0x1UL << DCB_DEMCR_VC_NOCPERR_Pos) /*!< DCB DEMCR: Vector Catch NOCP errors Mask */ + +#define DCB_DEMCR_VC_MMERR_Pos 4U /*!< DCB DEMCR: Vector Catch MemManage errors Position */ +#define DCB_DEMCR_VC_MMERR_Msk (0x1UL << DCB_DEMCR_VC_MMERR_Pos) /*!< DCB DEMCR: Vector Catch MemManage errors Mask */ + +#define DCB_DEMCR_VC_CORERESET_Pos 0U /*!< DCB DEMCR: Vector Catch Core reset Position */ +#define DCB_DEMCR_VC_CORERESET_Msk (0x1UL /*<< DCB_DEMCR_VC_CORERESET_Pos*/) /*!< DCB DEMCR: Vector Catch Core reset Mask */ + +/* DSCEMCR, Debug Set Clear Exception and Monitor Control Register Definitions */ +#define DCB_DSCEMCR_CLR_MON_REQ_Pos 19U /*!< DCB DSCEMCR: Clear monitor request Position */ +#define DCB_DSCEMCR_CLR_MON_REQ_Msk (0x1UL << DCB_DSCEMCR_CLR_MON_REQ_Pos) /*!< DCB DSCEMCR: Clear monitor request Mask */ + +#define DCB_DSCEMCR_CLR_MON_PEND_Pos 17U /*!< DCB DSCEMCR: Clear monitor pend Position */ +#define DCB_DSCEMCR_CLR_MON_PEND_Msk (0x1UL << DCB_DSCEMCR_CLR_MON_PEND_Pos) /*!< DCB DSCEMCR: Clear monitor pend Mask */ + +#define DCB_DSCEMCR_SET_MON_REQ_Pos 3U /*!< DCB DSCEMCR: Set monitor request Position */ +#define DCB_DSCEMCR_SET_MON_REQ_Msk (0x1UL << DCB_DSCEMCR_SET_MON_REQ_Pos) /*!< DCB DSCEMCR: Set monitor request Mask */ + +#define DCB_DSCEMCR_SET_MON_PEND_Pos 1U /*!< DCB DSCEMCR: Set monitor pend Position */ +#define DCB_DSCEMCR_SET_MON_PEND_Msk (0x1UL << DCB_DSCEMCR_SET_MON_PEND_Pos) /*!< DCB DSCEMCR: Set monitor pend Mask */ + +/* DAUTHCTRL, Debug Authentication Control Register Definitions */ +#define DCB_DAUTHCTRL_UIDEN_Pos 10U /*!< DCB DAUTHCTRL: Unprivileged Invasive Debug Enable Position */ +#define DCB_DAUTHCTRL_UIDEN_Msk (0x1UL << DCB_DAUTHCTRL_UIDEN_Pos) /*!< DCB DAUTHCTRL: Unprivileged Invasive Debug Enable Mask */ + +#define DCB_DAUTHCTRL_UIDAPEN_Pos 9U /*!< DCB DAUTHCTRL: Unprivileged Invasive DAP Access Enable Position */ +#define DCB_DAUTHCTRL_UIDAPEN_Msk (0x1UL << DCB_DAUTHCTRL_UIDAPEN_Pos) /*!< DCB DAUTHCTRL: Unprivileged Invasive DAP Access Enable Mask */ + +#define DCB_DAUTHCTRL_FSDMA_Pos 8U /*!< DCB DAUTHCTRL: Force Secure DebugMonitor Allowed Position */ +#define DCB_DAUTHCTRL_FSDMA_Msk (0x1UL << DCB_DAUTHCTRL_FSDMA_Pos) /*!< DCB DAUTHCTRL: Force Secure DebugMonitor Allowed Mask */ + +#define DCB_DAUTHCTRL_INTSPNIDEN_Pos 3U /*!< DCB DAUTHCTRL: Internal Secure non-invasive debug enable Position */ +#define DCB_DAUTHCTRL_INTSPNIDEN_Msk (0x1UL << DCB_DAUTHCTRL_INTSPNIDEN_Pos) /*!< DCB DAUTHCTRL: Internal Secure non-invasive debug enable Mask */ + +#define DCB_DAUTHCTRL_SPNIDENSEL_Pos 2U /*!< DCB DAUTHCTRL: Secure non-invasive debug enable select Position */ +#define DCB_DAUTHCTRL_SPNIDENSEL_Msk (0x1UL << DCB_DAUTHCTRL_SPNIDENSEL_Pos) /*!< DCB DAUTHCTRL: Secure non-invasive debug enable select Mask */ + +#define DCB_DAUTHCTRL_INTSPIDEN_Pos 1U /*!< DCB DAUTHCTRL: Internal Secure invasive debug enable Position */ +#define DCB_DAUTHCTRL_INTSPIDEN_Msk (0x1UL << DCB_DAUTHCTRL_INTSPIDEN_Pos) /*!< DCB DAUTHCTRL: Internal Secure invasive debug enable Mask */ + +#define DCB_DAUTHCTRL_SPIDENSEL_Pos 0U /*!< DCB DAUTHCTRL: Secure invasive debug enable select Position */ +#define DCB_DAUTHCTRL_SPIDENSEL_Msk (0x1UL /*<< DCB_DAUTHCTRL_SPIDENSEL_Pos*/) /*!< DCB DAUTHCTRL: Secure invasive debug enable select Mask */ + +/* DSCSR, Debug Security Control and Status Register Definitions */ +#define DCB_DSCSR_CDSKEY_Pos 17U /*!< DCB DSCSR: CDS write-enable key Position */ +#define DCB_DSCSR_CDSKEY_Msk (0x1UL << DCB_DSCSR_CDSKEY_Pos) /*!< DCB DSCSR: CDS write-enable key Mask */ + +#define DCB_DSCSR_CDS_Pos 16U /*!< DCB DSCSR: Current domain Secure Position */ +#define DCB_DSCSR_CDS_Msk (0x1UL << DCB_DSCSR_CDS_Pos) /*!< DCB DSCSR: Current domain Secure Mask */ + +#define DCB_DSCSR_SBRSEL_Pos 1U /*!< DCB DSCSR: Secure banked register select Position */ +#define DCB_DSCSR_SBRSEL_Msk (0x1UL << DCB_DSCSR_SBRSEL_Pos) /*!< DCB DSCSR: Secure banked register select Mask */ + +#define DCB_DSCSR_SBRSELEN_Pos 0U /*!< DCB DSCSR: Secure banked register select enable Position */ +#define DCB_DSCSR_SBRSELEN_Msk (0x1UL /*<< DCB_DSCSR_SBRSELEN_Pos*/) /*!< DCB DSCSR: Secure banked register select enable Mask */ + +/*@} end of group CMSIS_DCB */ + + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_DIB Debug Identification Block + \brief Type definitions for the Debug Identification Block Registers + @{ + */ + +/** + \brief Structure type to access the Debug Identification Block Registers (DIB). + */ +typedef struct +{ + __OM uint32_t DLAR; /*!< Offset: 0x000 ( /W) SCS Software Lock Access Register */ + __IM uint32_t DLSR; /*!< Offset: 0x004 (R/ ) SCS Software Lock Status Register */ + __IM uint32_t DAUTHSTATUS; /*!< Offset: 0x008 (R/ ) Debug Authentication Status Register */ + __IM uint32_t DDEVARCH; /*!< Offset: 0x00C (R/ ) SCS Device Architecture Register */ + __IM uint32_t DDEVTYPE; /*!< Offset: 0x010 (R/ ) SCS Device Type Register */ +} DIB_Type; + +/* DLAR, SCS Software Lock Access Register Definitions */ +#define DIB_DLAR_KEY_Pos 0U /*!< DIB DLAR: KEY Position */ +#define DIB_DLAR_KEY_Msk (0xFFFFFFFFUL /*<< DIB_DLAR_KEY_Pos */) /*!< DIB DLAR: KEY Mask */ + +/* DLSR, SCS Software Lock Status Register Definitions */ +#define DIB_DLSR_nTT_Pos 2U /*!< DIB DLSR: Not thirty-two bit Position */ +#define DIB_DLSR_nTT_Msk (0x1UL << DIB_DLSR_nTT_Pos ) /*!< DIB DLSR: Not thirty-two bit Mask */ + +#define DIB_DLSR_SLK_Pos 1U /*!< DIB DLSR: Software Lock status Position */ +#define DIB_DLSR_SLK_Msk (0x1UL << DIB_DLSR_SLK_Pos ) /*!< DIB DLSR: Software Lock status Mask */ + +#define DIB_DLSR_SLI_Pos 0U /*!< DIB DLSR: Software Lock implemented Position */ +#define DIB_DLSR_SLI_Msk (0x1UL /*<< DIB_DLSR_SLI_Pos*/) /*!< DIB DLSR: Software Lock implemented Mask */ + +/* DAUTHSTATUS, Debug Authentication Status Register Definitions */ +#define DIB_DAUTHSTATUS_SUNID_Pos 22U /*!< DIB DAUTHSTATUS: Secure Unprivileged Non-invasive Debug Allowed Position */ +#define DIB_DAUTHSTATUS_SUNID_Msk (0x3UL << DIB_DAUTHSTATUS_SUNID_Pos ) /*!< DIB DAUTHSTATUS: Secure Unprivileged Non-invasive Debug Allowed Mask */ + +#define DIB_DAUTHSTATUS_SUID_Pos 20U /*!< DIB DAUTHSTATUS: Secure Unprivileged Invasive Debug Allowed Position */ +#define DIB_DAUTHSTATUS_SUID_Msk (0x3UL << DIB_DAUTHSTATUS_SUID_Pos ) /*!< DIB DAUTHSTATUS: Secure Unprivileged Invasive Debug Allowed Mask */ + +#define DIB_DAUTHSTATUS_NSUNID_Pos 18U /*!< DIB DAUTHSTATUS: Non-secure Unprivileged Non-invasive Debug Allo Position */ +#define DIB_DAUTHSTATUS_NSUNID_Msk (0x3UL << DIB_DAUTHSTATUS_NSUNID_Pos ) /*!< DIB DAUTHSTATUS: Non-secure Unprivileged Non-invasive Debug Allo Mask */ + +#define DIB_DAUTHSTATUS_NSUID_Pos 16U /*!< DIB DAUTHSTATUS: Non-secure Unprivileged Invasive Debug Allowed Position */ +#define DIB_DAUTHSTATUS_NSUID_Msk (0x3UL << DIB_DAUTHSTATUS_NSUID_Pos ) /*!< DIB DAUTHSTATUS: Non-secure Unprivileged Invasive Debug Allowed Mask */ + +#define DIB_DAUTHSTATUS_SNID_Pos 6U /*!< DIB DAUTHSTATUS: Secure Non-invasive Debug Position */ +#define DIB_DAUTHSTATUS_SNID_Msk (0x3UL << DIB_DAUTHSTATUS_SNID_Pos ) /*!< DIB DAUTHSTATUS: Secure Non-invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_SID_Pos 4U /*!< DIB DAUTHSTATUS: Secure Invasive Debug Position */ +#define DIB_DAUTHSTATUS_SID_Msk (0x3UL << DIB_DAUTHSTATUS_SID_Pos ) /*!< DIB DAUTHSTATUS: Secure Invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_NSNID_Pos 2U /*!< DIB DAUTHSTATUS: Non-secure Non-invasive Debug Position */ +#define DIB_DAUTHSTATUS_NSNID_Msk (0x3UL << DIB_DAUTHSTATUS_NSNID_Pos ) /*!< DIB DAUTHSTATUS: Non-secure Non-invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_NSID_Pos 0U /*!< DIB DAUTHSTATUS: Non-secure Invasive Debug Position */ +#define DIB_DAUTHSTATUS_NSID_Msk (0x3UL /*<< DIB_DAUTHSTATUS_NSID_Pos*/) /*!< DIB DAUTHSTATUS: Non-secure Invasive Debug Mask */ + +/* DDEVARCH, SCS Device Architecture Register Definitions */ +#define DIB_DDEVARCH_ARCHITECT_Pos 21U /*!< DIB DDEVARCH: Architect Position */ +#define DIB_DDEVARCH_ARCHITECT_Msk (0x7FFUL << DIB_DDEVARCH_ARCHITECT_Pos ) /*!< DIB DDEVARCH: Architect Mask */ + +#define DIB_DDEVARCH_PRESENT_Pos 20U /*!< DIB DDEVARCH: DEVARCH Present Position */ +#define DIB_DDEVARCH_PRESENT_Msk (0x1FUL << DIB_DDEVARCH_PRESENT_Pos ) /*!< DIB DDEVARCH: DEVARCH Present Mask */ + +#define DIB_DDEVARCH_REVISION_Pos 16U /*!< DIB DDEVARCH: Revision Position */ +#define DIB_DDEVARCH_REVISION_Msk (0xFUL << DIB_DDEVARCH_REVISION_Pos ) /*!< DIB DDEVARCH: Revision Mask */ + +#define DIB_DDEVARCH_ARCHVER_Pos 12U /*!< DIB DDEVARCH: Architecture Version Position */ +#define DIB_DDEVARCH_ARCHVER_Msk (0xFUL << DIB_DDEVARCH_ARCHVER_Pos ) /*!< DIB DDEVARCH: Architecture Version Mask */ + +#define DIB_DDEVARCH_ARCHPART_Pos 0U /*!< DIB DDEVARCH: Architecture Part Position */ +#define DIB_DDEVARCH_ARCHPART_Msk (0xFFFUL /*<< DIB_DDEVARCH_ARCHPART_Pos*/) /*!< DIB DDEVARCH: Architecture Part Mask */ + +/* DDEVTYPE, SCS Device Type Register Definitions */ +#define DIB_DDEVTYPE_SUB_Pos 4U /*!< DIB DDEVTYPE: Sub-type Position */ +#define DIB_DDEVTYPE_SUB_Msk (0xFUL << DIB_DDEVTYPE_SUB_Pos ) /*!< DIB DDEVTYPE: Sub-type Mask */ + +#define DIB_DDEVTYPE_MAJOR_Pos 0U /*!< DIB DDEVTYPE: Major type Position */ +#define DIB_DDEVTYPE_MAJOR_Msk (0xFUL /*<< DIB_DDEVTYPE_MAJOR_Pos*/) /*!< DIB DDEVTYPE: Major type Mask */ + + +/*@} end of group CMSIS_DIB */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_core_bitfield Core register bit field macros + \brief Macros for use with bit field definitions (xxx_Pos, xxx_Msk). + @{ + */ + +/** + \brief Mask and shift a bit field value for use in a register bit range. + \param[in] field Name of the register bit field. + \param[in] value Value of the bit field. This parameter is interpreted as an uint32_t type. + \return Masked and shifted value. +*/ +#define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk) + +/** + \brief Mask and shift a register value to extract a bit filed value. + \param[in] field Name of the register bit field. + \param[in] value Value of register. This parameter is interpreted as an uint32_t type. + \return Masked and shifted bit field value. +*/ +#define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos) + +/*@} end of group CMSIS_core_bitfield */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_core_base Core Definitions + \brief Definitions for base addresses, unions, and structures. + @{ + */ + +/* Memory mapping of Core Hardware */ + #define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */ + #define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */ + #define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */ + #define MEMSYSCTL_BASE (0xE001E000UL) /*!< Memory System Control Base Address */ + #define ERRBNK_BASE (0xE001E100UL) /*!< Error Banking Base Address */ + #define PWRMODCTL_BASE (0xE001E300UL) /*!< Power Mode Control Base Address */ + #define EWIC_BASE (0xE001E400UL) /*!< External Wakeup Interrupt Controller Base Address */ + #define PRCCFGINF_BASE (0xE001E700UL) /*!< Processor Configuration Information Base Address */ + #define STL_BASE (0xE001E800UL) /*!< Software Test Library Base Address */ + #define TPI_BASE (0xE0040000UL) /*!< TPI Base Address */ + #define CoreDebug_BASE (0xE000EDF0UL) /*!< \deprecated Core Debug Base Address */ + #define DCB_BASE (0xE000EDF0UL) /*!< DCB Base Address */ + #define DIB_BASE (0xE000EFB0UL) /*!< DIB Base Address */ + #define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */ + #define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */ + #define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */ + + #define ICB ((ICB_Type *) SCS_BASE ) /*!< System control Register not in SCB */ + #define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */ + #define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */ + #define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */ + #define ITM ((ITM_Type *) ITM_BASE ) /*!< ITM configuration struct */ + #define DWT ((DWT_Type *) DWT_BASE ) /*!< DWT configuration struct */ + #define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct */ + #define MEMSYSCTL ((MemSysCtl_Type *) MEMSYSCTL_BASE ) /*!< Memory System Control configuration struct */ + #define ERRBNK ((ErrBnk_Type *) ERRBNK_BASE ) /*!< Error Banking configuration struct */ + #define PWRMODCTL ((PwrModCtl_Type *) PWRMODCTL_BASE ) /*!< Power Mode Control configuration struct */ + #define EWIC ((EWIC_Type *) EWIC_BASE ) /*!< EWIC configuration struct */ + #define PRCCFGINF ((PrcCfgInf_Type *) PRCCFGINF_BASE ) /*!< Processor Configuration Information configuration struct */ + #define STL ((STL_Type *) STL_BASE ) /*!< Software Test Library configuration struct */ + #define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE ) /*!< \deprecated Core Debug configuration struct */ + #define DCB ((DCB_Type *) DCB_BASE ) /*!< DCB configuration struct */ + #define DIB ((DIB_Type *) DIB_BASE ) /*!< DIB configuration struct */ + + #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) + #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */ + #define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */ + #endif + + #if defined (__PMU_PRESENT) && (__PMU_PRESENT == 1U) + #define PMU_BASE (0xE0003000UL) /*!< PMU Base Address */ + #define PMU ((PMU_Type *) PMU_BASE ) /*!< PMU configuration struct */ + #endif + + #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) + #define SAU_BASE (SCS_BASE + 0x0DD0UL) /*!< Security Attribution Unit */ + #define SAU ((SAU_Type *) SAU_BASE ) /*!< Security Attribution Unit */ + #endif + + #define FPU_BASE (SCS_BASE + 0x0F30UL) /*!< Floating Point Unit */ + #define FPU ((FPU_Type *) FPU_BASE ) /*!< Floating Point Unit */ + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) + #define SCS_BASE_NS (0xE002E000UL) /*!< System Control Space Base Address (non-secure address space) */ + #define CoreDebug_BASE_NS (0xE002EDF0UL) /*!< \deprecated Core Debug Base Address (non-secure address space) */ + #define DCB_BASE_NS (0xE002EDF0UL) /*!< DCB Base Address (non-secure address space) */ + #define DIB_BASE_NS (0xE002EFB0UL) /*!< DIB Base Address (non-secure address space) */ + #define SysTick_BASE_NS (SCS_BASE_NS + 0x0010UL) /*!< SysTick Base Address (non-secure address space) */ + #define NVIC_BASE_NS (SCS_BASE_NS + 0x0100UL) /*!< NVIC Base Address (non-secure address space) */ + #define SCB_BASE_NS (SCS_BASE_NS + 0x0D00UL) /*!< System Control Block Base Address (non-secure address space) */ + + #define ICB_NS ((ICB_Type *) SCS_BASE_NS ) /*!< System control Register not in SCB(non-secure address space) */ + #define SCB_NS ((SCB_Type *) SCB_BASE_NS ) /*!< SCB configuration struct (non-secure address space) */ + #define SysTick_NS ((SysTick_Type *) SysTick_BASE_NS ) /*!< SysTick configuration struct (non-secure address space) */ + #define NVIC_NS ((NVIC_Type *) NVIC_BASE_NS ) /*!< NVIC configuration struct (non-secure address space) */ + #define CoreDebug_NS ((CoreDebug_Type *) CoreDebug_BASE_NS) /*!< \deprecated Core Debug configuration struct (non-secure address space) */ + #define DCB_NS ((DCB_Type *) DCB_BASE_NS ) /*!< DCB configuration struct (non-secure address space) */ + #define DIB_NS ((DIB_Type *) DIB_BASE_NS ) /*!< DIB configuration struct (non-secure address space) */ + + #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) + #define MPU_BASE_NS (SCS_BASE_NS + 0x0D90UL) /*!< Memory Protection Unit (non-secure address space) */ + #define MPU_NS ((MPU_Type *) MPU_BASE_NS ) /*!< Memory Protection Unit (non-secure address space) */ + #endif + + #define FPU_BASE_NS (SCS_BASE_NS + 0x0F30UL) /*!< Floating Point Unit (non-secure address space) */ + #define FPU_NS ((FPU_Type *) FPU_BASE_NS ) /*!< Floating Point Unit (non-secure address space) */ + +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ +/*@} */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_register_aliases Backwards Compatibility Aliases + \brief Register alias definitions for backwards compatibility. + @{ + */ +#define ID_ADR (ID_AFR) /*!< SCB Auxiliary Feature Register */ + +/* 'SCnSCB' is deprecated and replaced by 'ICB' */ +typedef ICB_Type SCnSCB_Type; + +/* Auxiliary Control Register Definitions */ +#define SCnSCB_ACTLR_DISCRITAXIRUW_Pos (ICB_ACTLR_DISCRITAXIRUW_Pos) +#define SCnSCB_ACTLR_DISCRITAXIRUW_Msk (ICB_ACTLR_DISCRITAXIRUW_Msk) + +#define SCnSCB_ACTLR_DISDI_Pos (ICB_ACTLR_DISDI_Pos) +#define SCnSCB_ACTLR_DISDI_Msk (ICB_ACTLR_DISDI_Msk) + +#define SCnSCB_ACTLR_DISCRITAXIRUR_Pos (ICB_ACTLR_DISCRITAXIRUR_Pos) +#define SCnSCB_ACTLR_DISCRITAXIRUR_Msk (ICB_ACTLR_DISCRITAXIRUR_Msk) + +#define SCnSCB_ACTLR_EVENTBUSEN_Pos (ICB_ACTLR_EVENTBUSEN_Pos) +#define SCnSCB_ACTLR_EVENTBUSEN_Msk (ICB_ACTLR_EVENTBUSEN_Msk) + +#define SCnSCB_ACTLR_EVENTBUSEN_S_Pos (ICB_ACTLR_EVENTBUSEN_S_Pos) +#define SCnSCB_ACTLR_EVENTBUSEN_S_Msk (ICB_ACTLR_EVENTBUSEN_S_Msk) + +#define SCnSCB_ACTLR_DISITMATBFLUSH_Pos (ICB_ACTLR_DISITMATBFLUSH_Pos) +#define SCnSCB_ACTLR_DISITMATBFLUSH_Msk (ICB_ACTLR_DISITMATBFLUSH_Msk) + +#define SCnSCB_ACTLR_DISNWAMODE_Pos (ICB_ACTLR_DISNWAMODE_Pos) +#define SCnSCB_ACTLR_DISNWAMODE_Msk (ICB_ACTLR_DISNWAMODE_Msk) + +#define SCnSCB_ACTLR_FPEXCODIS_Pos (ICB_ACTLR_FPEXCODIS_Pos) +#define SCnSCB_ACTLR_FPEXCODIS_Msk (ICB_ACTLR_FPEXCODIS_Msk) + +#define SCnSCB_ACTLR_DISOLAP_Pos (ICB_ACTLR_DISOLAP_Pos) +#define SCnSCB_ACTLR_DISOLAP_Msk (ICB_ACTLR_DISOLAP_Msk) + +#define SCnSCB_ACTLR_DISOLAPS_Pos (ICB_ACTLR_DISOLAPS_Pos) +#define SCnSCB_ACTLR_DISOLAPS_Msk (ICB_ACTLR_DISOLAPS_Msk) + +#define SCnSCB_ACTLR_DISLOBR_Pos (ICB_ACTLR_DISLOBR_Pos) +#define SCnSCB_ACTLR_DISLOBR_Msk (ICB_ACTLR_DISLOBR_Msk) + +#define SCnSCB_ACTLR_DISLO_Pos (ICB_ACTLR_DISLO_Pos) +#define SCnSCB_ACTLR_DISLO_Msk (ICB_ACTLR_DISLO_Msk) + +#define SCnSCB_ACTLR_DISLOLEP_Pos (ICB_ACTLR_DISLOLEP_Pos) +#define SCnSCB_ACTLR_DISLOLEP_Msk (ICB_ACTLR_DISLOLEP_Msk) + +#define SCnSCB_ACTLR_DISFOLD_Pos (ICB_ACTLR_DISFOLD_Pos) +#define SCnSCB_ACTLR_DISFOLD_Msk (ICB_ACTLR_DISFOLD_Msk) + +/* Interrupt Controller Type Register Definitions */ +#define SCnSCB_ICTR_INTLINESNUM_Pos (ICB_ICTR_INTLINESNUM_Pos) +#define SCnSCB_ICTR_INTLINESNUM_Msk (ICB_ICTR_INTLINESNUM_Msk) + +#define SCnSCB (ICB) +#define SCnSCB_NS (ICB_NS) + +/*@} */ + + +/******************************************************************************* + * Hardware Abstraction Layer + Core Function Interface contains: + - Core NVIC Functions + - Core SysTick Functions + - Core Debug Functions + - Core Register Access Functions + ******************************************************************************/ +/** + \defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference +*/ + + + +/* ########################## NVIC functions #################################### */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_NVICFunctions NVIC Functions + \brief Functions that manage interrupts and exceptions via the NVIC. + @{ + */ + +#ifdef CMSIS_NVIC_VIRTUAL + #ifndef CMSIS_NVIC_VIRTUAL_HEADER_FILE + #define CMSIS_NVIC_VIRTUAL_HEADER_FILE "cmsis_nvic_virtual.h" + #endif + #include CMSIS_NVIC_VIRTUAL_HEADER_FILE +#else + #define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping + #define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping + #define NVIC_EnableIRQ __NVIC_EnableIRQ + #define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ + #define NVIC_DisableIRQ __NVIC_DisableIRQ + #define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ + #define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ + #define NVIC_ClearPendingIRQ __NVIC_ClearPendingIRQ + #define NVIC_GetActive __NVIC_GetActive + #define NVIC_SetPriority __NVIC_SetPriority + #define NVIC_GetPriority __NVIC_GetPriority + #define NVIC_SystemReset __NVIC_SystemReset +#endif /* CMSIS_NVIC_VIRTUAL */ + +#ifdef CMSIS_VECTAB_VIRTUAL + #ifndef CMSIS_VECTAB_VIRTUAL_HEADER_FILE + #define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h" + #endif + #include CMSIS_VECTAB_VIRTUAL_HEADER_FILE +#else + #define NVIC_SetVector __NVIC_SetVector + #define NVIC_GetVector __NVIC_GetVector +#endif /* (CMSIS_VECTAB_VIRTUAL) */ + +#define NVIC_USER_IRQ_OFFSET 16 + + +/* Special LR values for Secure/Non-Secure call handling and exception handling */ + +/* Function Return Payload (from ARMv8-M Architecture Reference Manual) LR value on entry from Secure BLXNS */ +#define FNC_RETURN (0xFEFFFFFFUL) /* bit [0] ignored when processing a branch */ + +/* The following EXC_RETURN mask values are used to evaluate the LR on exception entry */ +#define EXC_RETURN_PREFIX (0xFF000000UL) /* bits [31:24] set to indicate an EXC_RETURN value */ +#define EXC_RETURN_S (0x00000040UL) /* bit [6] stack used to push registers: 0=Non-secure 1=Secure */ +#define EXC_RETURN_DCRS (0x00000020UL) /* bit [5] stacking rules for called registers: 0=skipped 1=saved */ +#define EXC_RETURN_FTYPE (0x00000010UL) /* bit [4] allocate stack for floating-point context: 0=done 1=skipped */ +#define EXC_RETURN_MODE (0x00000008UL) /* bit [3] processor mode for return: 0=Handler mode 1=Thread mode */ +#define EXC_RETURN_SPSEL (0x00000004UL) /* bit [2] stack pointer used to restore context: 0=MSP 1=PSP */ +#define EXC_RETURN_ES (0x00000001UL) /* bit [0] security state exception was taken to: 0=Non-secure 1=Secure */ + +/* Integrity Signature (from ARMv8-M Architecture Reference Manual) for exception context stacking */ +#if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) /* Value for processors with floating-point extension: */ +#define EXC_INTEGRITY_SIGNATURE (0xFEFA125AUL) /* bit [0] SFTC must match LR bit[4] EXC_RETURN_FTYPE */ +#else +#define EXC_INTEGRITY_SIGNATURE (0xFEFA125BUL) /* Value for processors without floating-point extension */ +#endif + + +/** + \brief Set Priority Grouping + \details Sets the priority grouping field using the required unlock sequence. + The parameter PriorityGroup is assigned to the field SCB->AIRCR [10:8] PRIGROUP field. + Only values from 0..7 are used. + In case of a conflict between priority grouping and available + priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set. + \param [in] PriorityGroup Priority grouping field. + */ +__STATIC_INLINE void __NVIC_SetPriorityGrouping(uint32_t PriorityGroup) +{ + uint32_t reg_value; + uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ + + reg_value = SCB->AIRCR; /* read old register configuration */ + reg_value &= ~((uint32_t)(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk)); /* clear bits to change */ + reg_value = (reg_value | + ((uint32_t)0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | + (PriorityGroupTmp << SCB_AIRCR_PRIGROUP_Pos) ); /* Insert write key and priority group */ + SCB->AIRCR = reg_value; +} + + +/** + \brief Get Priority Grouping + \details Reads the priority grouping field from the NVIC Interrupt Controller. + \return Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field). + */ +__STATIC_INLINE uint32_t __NVIC_GetPriorityGrouping(void) +{ + return ((uint32_t)((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos)); +} + + +/** + \brief Enable Interrupt + \details Enables a device specific interrupt in the NVIC interrupt controller. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + __COMPILER_BARRIER(); + NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __COMPILER_BARRIER(); + } +} + + +/** + \brief Get Interrupt Enable status + \details Returns a device specific interrupt enable status from the NVIC interrupt controller. + \param [in] IRQn Device specific interrupt number. + \return 0 Interrupt is not enabled. + \return 1 Interrupt is enabled. + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +/** + \brief Disable Interrupt + \details Disables a device specific interrupt in the NVIC interrupt controller. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC->ICER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __DSB(); + __ISB(); + } +} + + +/** + \brief Get Pending Interrupt + \details Reads the NVIC pending register and returns the pending bit for the specified device specific interrupt. + \param [in] IRQn Device specific interrupt number. + \return 0 Interrupt status is not pending. + \return 1 Interrupt status is pending. + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +/** + \brief Set Pending Interrupt + \details Sets the pending bit of a device specific interrupt in the NVIC pending register. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } +} + + +/** + \brief Clear Pending Interrupt + \details Clears the pending bit of a device specific interrupt in the NVIC pending register. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC->ICPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } +} + + +/** + \brief Get Active Interrupt + \details Reads the active register in the NVIC and returns the active bit for the device specific interrupt. + \param [in] IRQn Device specific interrupt number. + \return 0 Interrupt status is not active. + \return 1 Interrupt status is active. + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t __NVIC_GetActive(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC->IABR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief Get Interrupt Target State + \details Reads the interrupt target field in the NVIC and returns the interrupt target bit for the device specific interrupt. + \param [in] IRQn Device specific interrupt number. + \return 0 if interrupt is assigned to Secure + \return 1 if interrupt is assigned to Non Secure + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t NVIC_GetTargetState(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC->ITNS[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +/** + \brief Set Interrupt Target State + \details Sets the interrupt target field in the NVIC and returns the interrupt target bit for the device specific interrupt. + \param [in] IRQn Device specific interrupt number. + \return 0 if interrupt is assigned to Secure + 1 if interrupt is assigned to Non Secure + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t NVIC_SetTargetState(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC->ITNS[(((uint32_t)IRQn) >> 5UL)] |= ((uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL))); + return((uint32_t)(((NVIC->ITNS[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +/** + \brief Clear Interrupt Target State + \details Clears the interrupt target field in the NVIC and returns the interrupt target bit for the device specific interrupt. + \param [in] IRQn Device specific interrupt number. + \return 0 if interrupt is assigned to Secure + 1 if interrupt is assigned to Non Secure + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t NVIC_ClearTargetState(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC->ITNS[(((uint32_t)IRQn) >> 5UL)] &= ~((uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL))); + return((uint32_t)(((NVIC->ITNS[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + + +/** + \brief Set Interrupt Priority + \details Sets the priority of a device specific interrupt or a processor exception. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + \param [in] IRQn Interrupt number. + \param [in] priority Priority to set. + \note The priority cannot be set for every processor exception. + */ +__STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC->IPR[((uint32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); + } + else + { + SCB->SHPR[(((uint32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); + } +} + + +/** + \brief Get Interrupt Priority + \details Reads the priority of a device specific interrupt or a processor exception. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + \param [in] IRQn Interrupt number. + \return Interrupt Priority. + Value is aligned automatically to the implemented priority bits of the microcontroller. + */ +__STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn) +{ + + if ((int32_t)(IRQn) >= 0) + { + return(((uint32_t)NVIC->IPR[((uint32_t)IRQn)] >> (8U - __NVIC_PRIO_BITS))); + } + else + { + return(((uint32_t)SCB->SHPR[(((uint32_t)IRQn) & 0xFUL)-4UL] >> (8U - __NVIC_PRIO_BITS))); + } +} + + +/** + \brief Encode Priority + \details Encodes the priority for an interrupt with the given priority group, + preemptive priority value, and subpriority value. + In case of a conflict between priority grouping and available + priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set. + \param [in] PriorityGroup Used priority group. + \param [in] PreemptPriority Preemptive priority value (starting from 0). + \param [in] SubPriority Subpriority value (starting from 0). + \return Encoded priority. Value can be used in the function \ref NVIC_SetPriority(). + */ +__STATIC_INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority) +{ + uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ + uint32_t PreemptPriorityBits; + uint32_t SubPriorityBits; + + PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp); + SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS)); + + return ( + ((PreemptPriority & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL)) << SubPriorityBits) | + ((SubPriority & (uint32_t)((1UL << (SubPriorityBits )) - 1UL))) + ); +} + + +/** + \brief Decode Priority + \details Decodes an interrupt priority value with a given priority group to + preemptive priority value and subpriority value. + In case of a conflict between priority grouping and available + priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set. + \param [in] Priority Priority value, which can be retrieved with the function \ref NVIC_GetPriority(). + \param [in] PriorityGroup Used priority group. + \param [out] pPreemptPriority Preemptive priority value (starting from 0). + \param [out] pSubPriority Subpriority value (starting from 0). + */ +__STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* const pPreemptPriority, uint32_t* const pSubPriority) +{ + uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ + uint32_t PreemptPriorityBits; + uint32_t SubPriorityBits; + + PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp); + SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS)); + + *pPreemptPriority = (Priority >> SubPriorityBits) & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL); + *pSubPriority = (Priority ) & (uint32_t)((1UL << (SubPriorityBits )) - 1UL); +} + + +/** + \brief Set Interrupt Vector + \details Sets an interrupt vector in SRAM based interrupt vector table. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + VTOR must been relocated to SRAM before. + \param [in] IRQn Interrupt number + \param [in] vector Address of interrupt handler function + */ +__STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) +{ + uint32_t *vectors = (uint32_t *)SCB->VTOR; + vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector; + __DSB(); +} + + +/** + \brief Get Interrupt Vector + \details Reads an interrupt vector from interrupt vector table. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + \param [in] IRQn Interrupt number. + \return Address of interrupt handler function + */ +__STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn) +{ + uint32_t *vectors = (uint32_t *)SCB->VTOR; + return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET]; +} + + +/** + \brief System Reset + \details Initiates a system reset request to reset the MCU. + */ +__NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void) +{ + __DSB(); /* Ensure all outstanding memory accesses included + buffered write are completed before reset */ + SCB->AIRCR = (uint32_t)((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | + (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) | + SCB_AIRCR_SYSRESETREQ_Msk ); /* Keep priority group unchanged */ + __DSB(); /* Ensure completion of memory access */ + + for(;;) /* wait until reset */ + { + __NOP(); + } +} + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief Set Priority Grouping (non-secure) + \details Sets the non-secure priority grouping field when in secure state using the required unlock sequence. + The parameter PriorityGroup is assigned to the field SCB->AIRCR [10:8] PRIGROUP field. + Only values from 0..7 are used. + In case of a conflict between priority grouping and available + priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set. + \param [in] PriorityGroup Priority grouping field. + */ +__STATIC_INLINE void TZ_NVIC_SetPriorityGrouping_NS(uint32_t PriorityGroup) +{ + uint32_t reg_value; + uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ + + reg_value = SCB_NS->AIRCR; /* read old register configuration */ + reg_value &= ~((uint32_t)(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk)); /* clear bits to change */ + reg_value = (reg_value | + ((uint32_t)0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | + (PriorityGroupTmp << SCB_AIRCR_PRIGROUP_Pos) ); /* Insert write key and priority group */ + SCB_NS->AIRCR = reg_value; +} + + +/** + \brief Get Priority Grouping (non-secure) + \details Reads the priority grouping field from the non-secure NVIC when in secure state. + \return Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field). + */ +__STATIC_INLINE uint32_t TZ_NVIC_GetPriorityGrouping_NS(void) +{ + return ((uint32_t)((SCB_NS->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos)); +} + + +/** + \brief Enable Interrupt (non-secure) + \details Enables a device specific interrupt in the non-secure NVIC interrupt controller when in secure state. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void TZ_NVIC_EnableIRQ_NS(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC_NS->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } +} + + +/** + \brief Get Interrupt Enable status (non-secure) + \details Returns a device specific interrupt enable status from the non-secure NVIC interrupt controller when in secure state. + \param [in] IRQn Device specific interrupt number. + \return 0 Interrupt is not enabled. + \return 1 Interrupt is enabled. + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t TZ_NVIC_GetEnableIRQ_NS(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC_NS->ISER[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +/** + \brief Disable Interrupt (non-secure) + \details Disables a device specific interrupt in the non-secure NVIC interrupt controller when in secure state. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void TZ_NVIC_DisableIRQ_NS(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC_NS->ICER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } +} + + +/** + \brief Get Pending Interrupt (non-secure) + \details Reads the NVIC pending register in the non-secure NVIC when in secure state and returns the pending bit for the specified device specific interrupt. + \param [in] IRQn Device specific interrupt number. + \return 0 Interrupt status is not pending. + \return 1 Interrupt status is pending. + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t TZ_NVIC_GetPendingIRQ_NS(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC_NS->ISPR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +/** + \brief Set Pending Interrupt (non-secure) + \details Sets the pending bit of a device specific interrupt in the non-secure NVIC pending register when in secure state. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void TZ_NVIC_SetPendingIRQ_NS(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC_NS->ISPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } +} + + +/** + \brief Clear Pending Interrupt (non-secure) + \details Clears the pending bit of a device specific interrupt in the non-secure NVIC pending register when in secure state. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void TZ_NVIC_ClearPendingIRQ_NS(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC_NS->ICPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } +} + + +/** + \brief Get Active Interrupt (non-secure) + \details Reads the active register in non-secure NVIC when in secure state and returns the active bit for the device specific interrupt. + \param [in] IRQn Device specific interrupt number. + \return 0 Interrupt status is not active. + \return 1 Interrupt status is active. + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t TZ_NVIC_GetActive_NS(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC_NS->IABR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +/** + \brief Set Interrupt Priority (non-secure) + \details Sets the priority of a non-secure device specific interrupt or a non-secure processor exception when in secure state. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + \param [in] IRQn Interrupt number. + \param [in] priority Priority to set. + \note The priority cannot be set for every non-secure processor exception. + */ +__STATIC_INLINE void TZ_NVIC_SetPriority_NS(IRQn_Type IRQn, uint32_t priority) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC_NS->IPR[((uint32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); + } + else + { + SCB_NS->SHPR[(((uint32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); + } +} + + +/** + \brief Get Interrupt Priority (non-secure) + \details Reads the priority of a non-secure device specific interrupt or a non-secure processor exception when in secure state. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + \param [in] IRQn Interrupt number. + \return Interrupt Priority. Value is aligned automatically to the implemented priority bits of the microcontroller. + */ +__STATIC_INLINE uint32_t TZ_NVIC_GetPriority_NS(IRQn_Type IRQn) +{ + + if ((int32_t)(IRQn) >= 0) + { + return(((uint32_t)NVIC_NS->IPR[((uint32_t)IRQn)] >> (8U - __NVIC_PRIO_BITS))); + } + else + { + return(((uint32_t)SCB_NS->SHPR[(((uint32_t)IRQn) & 0xFUL)-4UL] >> (8U - __NVIC_PRIO_BITS))); + } +} +#endif /* defined (__ARM_FEATURE_CMSE) &&(__ARM_FEATURE_CMSE == 3U) */ + +/*@} end of CMSIS_Core_NVICFunctions */ + +/* ########################## MPU functions #################################### */ + +#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) + +#include "mpu_armv8.h" + +#endif + +/* ########################## PMU functions and events #################################### */ + +#if defined (__PMU_PRESENT) && (__PMU_PRESENT == 1U) + +#include "pmu_armv8.h" + +/** + \brief Cortex-M55 PMU events + \note Architectural PMU events can be found in pmu_armv8.h +*/ + +#define ARMCM55_PMU_ECC_ERR 0xC000 /*!< Any ECC error */ +#define ARMCM55_PMU_ECC_ERR_FATAL 0xC001 /*!< Any fatal ECC error */ +#define ARMCM55_PMU_ECC_ERR_DCACHE 0xC010 /*!< Any ECC error in the data cache */ +#define ARMCM55_PMU_ECC_ERR_ICACHE 0xC011 /*!< Any ECC error in the instruction cache */ +#define ARMCM55_PMU_ECC_ERR_FATAL_DCACHE 0xC012 /*!< Any fatal ECC error in the data cache */ +#define ARMCM55_PMU_ECC_ERR_FATAL_ICACHE 0xC013 /*!< Any fatal ECC error in the instruction cache*/ +#define ARMCM55_PMU_ECC_ERR_DTCM 0xC020 /*!< Any ECC error in the DTCM */ +#define ARMCM55_PMU_ECC_ERR_ITCM 0xC021 /*!< Any ECC error in the ITCM */ +#define ARMCM55_PMU_ECC_ERR_FATAL_DTCM 0xC022 /*!< Any fatal ECC error in the DTCM */ +#define ARMCM55_PMU_ECC_ERR_FATAL_ITCM 0xC023 /*!< Any fatal ECC error in the ITCM */ +#define ARMCM55_PMU_PF_LINEFILL 0xC100 /*!< A prefetcher starts a line-fill */ +#define ARMCM55_PMU_PF_CANCEL 0xC101 /*!< A prefetcher stops prefetching */ +#define ARMCM55_PMU_PF_DROP_LINEFILL 0xC102 /*!< A linefill triggered by a prefetcher has been dropped because of lack of buffering */ +#define ARMCM55_PMU_NWAMODE_ENTER 0xC200 /*!< No write-allocate mode entry */ +#define ARMCM55_PMU_NWAMODE 0xC201 /*!< Write-allocate store is not allocated into the data cache due to no-write-allocate mode */ +#define ARMCM55_PMU_SAHB_ACCESS 0xC300 /*!< Read or write access on the S-AHB interface to the TCM */ +#define ARMCM55_PMU_PAHB_ACCESS 0xC301 /*!< Read or write access to the P-AHB write interface */ +#define ARMCM55_PMU_AXI_WRITE_ACCESS 0xC302 /*!< Any beat access to M-AXI write interface */ +#define ARMCM55_PMU_AXI_READ_ACCESS 0xC303 /*!< Any beat access to M-AXI read interface */ +#define ARMCM55_PMU_DOSTIMEOUT_DOUBLE 0xC400 /*!< Denial of Service timeout has fired twice and caused buffers to drain to allow forward progress */ +#define ARMCM55_PMU_DOSTIMEOUT_TRIPLE 0xC401 /*!< Denial of Service timeout has fired three times and blocked the LSU to force forward progress */ + +#endif + +/* ########################## FPU functions #################################### */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_FpuFunctions FPU Functions + \brief Function that provides FPU type. + @{ + */ + +/** + \brief get FPU type + \details returns the FPU type + \returns + - \b 0: No FPU + - \b 1: Single precision FPU + - \b 2: Double + Single precision FPU + */ +__STATIC_INLINE uint32_t SCB_GetFPUType(void) +{ + uint32_t mvfr0; + + mvfr0 = FPU->MVFR0; + if ((mvfr0 & (FPU_MVFR0_FPSP_Msk | FPU_MVFR0_FPDP_Msk)) == 0x220U) + { + return 2U; /* Double + Single precision FPU */ + } + else if ((mvfr0 & (FPU_MVFR0_FPSP_Msk | FPU_MVFR0_FPDP_Msk)) == 0x020U) + { + return 1U; /* Single precision FPU */ + } + else + { + return 0U; /* No FPU */ + } +} + + +/*@} end of CMSIS_Core_FpuFunctions */ + +/* ########################## MVE functions #################################### */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_MveFunctions MVE Functions + \brief Function that provides MVE type. + @{ + */ + +/** + \brief get MVE type + \details returns the MVE type + \returns + - \b 0: No Vector Extension (MVE) + - \b 1: Integer Vector Extension (MVE-I) + - \b 2: Floating-point Vector Extension (MVE-F) + */ +__STATIC_INLINE uint32_t SCB_GetMVEType(void) +{ + const uint32_t mvfr1 = FPU->MVFR1; + if ((mvfr1 & FPU_MVFR1_MVE_Msk) == (0x2U << FPU_MVFR1_MVE_Pos)) + { + return 2U; + } + else if ((mvfr1 & FPU_MVFR1_MVE_Msk) == (0x1U << FPU_MVFR1_MVE_Pos)) + { + return 1U; + } + else + { + return 0U; + } +} + + +/*@} end of CMSIS_Core_MveFunctions */ + + +/* ########################## Cache functions #################################### */ + +#if ((defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U)) || \ + (defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U))) +#include "cachel1_armv7.h" +#endif + + +/* ########################## SAU functions #################################### */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_SAUFunctions SAU Functions + \brief Functions that configure the SAU. + @{ + */ + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) + +/** + \brief Enable SAU + \details Enables the Security Attribution Unit (SAU). + */ +__STATIC_INLINE void TZ_SAU_Enable(void) +{ + SAU->CTRL |= (SAU_CTRL_ENABLE_Msk); +} + + + +/** + \brief Disable SAU + \details Disables the Security Attribution Unit (SAU). + */ +__STATIC_INLINE void TZ_SAU_Disable(void) +{ + SAU->CTRL &= ~(SAU_CTRL_ENABLE_Msk); +} + +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + +/*@} end of CMSIS_Core_SAUFunctions */ + + + + +/* ################################## Debug Control function ############################################ */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_DCBFunctions Debug Control Functions + \brief Functions that access the Debug Control Block. + @{ + */ + + +/** + \brief Set Debug Authentication Control Register + \details writes to Debug Authentication Control register. + \param [in] value value to be writen. + */ +__STATIC_INLINE void DCB_SetAuthCtrl(uint32_t value) +{ + __DSB(); + __ISB(); + DCB->DAUTHCTRL = value; + __DSB(); + __ISB(); +} + + +/** + \brief Get Debug Authentication Control Register + \details Reads Debug Authentication Control register. + \return Debug Authentication Control Register. + */ +__STATIC_INLINE uint32_t DCB_GetAuthCtrl(void) +{ + return (DCB->DAUTHCTRL); +} + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief Set Debug Authentication Control Register (non-secure) + \details writes to non-secure Debug Authentication Control register when in secure state. + \param [in] value value to be writen + */ +__STATIC_INLINE void TZ_DCB_SetAuthCtrl_NS(uint32_t value) +{ + __DSB(); + __ISB(); + DCB_NS->DAUTHCTRL = value; + __DSB(); + __ISB(); +} + + +/** + \brief Get Debug Authentication Control Register (non-secure) + \details Reads non-secure Debug Authentication Control register when in secure state. + \return Debug Authentication Control Register. + */ +__STATIC_INLINE uint32_t TZ_DCB_GetAuthCtrl_NS(void) +{ + return (DCB_NS->DAUTHCTRL); +} +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + +/*@} end of CMSIS_Core_DCBFunctions */ + + + + +/* ################################## Debug Identification function ############################################ */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_DIBFunctions Debug Identification Functions + \brief Functions that access the Debug Identification Block. + @{ + */ + + +/** + \brief Get Debug Authentication Status Register + \details Reads Debug Authentication Status register. + \return Debug Authentication Status Register. + */ +__STATIC_INLINE uint32_t DIB_GetAuthStatus(void) +{ + return (DIB->DAUTHSTATUS); +} + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief Get Debug Authentication Status Register (non-secure) + \details Reads non-secure Debug Authentication Status register when in secure state. + \return Debug Authentication Status Register. + */ +__STATIC_INLINE uint32_t TZ_DIB_GetAuthStatus_NS(void) +{ + return (DIB_NS->DAUTHSTATUS); +} +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + +/*@} end of CMSIS_Core_DCBFunctions */ + + + + +/* ################################## SysTick function ############################################ */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_SysTickFunctions SysTick Functions + \brief Functions that configure the System. + @{ + */ + +#if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U) + +/** + \brief System Tick Configuration + \details Initializes the System Timer and its interrupt, and starts the System Tick Timer. + Counter is in free running mode to generate periodic interrupts. + \param [in] ticks Number of ticks between two interrupts. + \return 0 Function succeeded. + \return 1 Function failed. + \note When the variable __Vendor_SysTickConfig is set to 1, then the + function SysTick_Config is not included. In this case, the file device.h + must contain a vendor-specific implementation of this function. + */ +__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks) +{ + if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk) + { + return (1UL); /* Reload value impossible */ + } + + SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */ + NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */ + SysTick->VAL = 0UL; /* Load the SysTick Counter Value */ + SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | + SysTick_CTRL_TICKINT_Msk | + SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */ + return (0UL); /* Function successful */ +} + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief System Tick Configuration (non-secure) + \details Initializes the non-secure System Timer and its interrupt when in secure state, and starts the System Tick Timer. + Counter is in free running mode to generate periodic interrupts. + \param [in] ticks Number of ticks between two interrupts. + \return 0 Function succeeded. + \return 1 Function failed. + \note When the variable __Vendor_SysTickConfig is set to 1, then the + function TZ_SysTick_Config_NS is not included. In this case, the file device.h + must contain a vendor-specific implementation of this function. + + */ +__STATIC_INLINE uint32_t TZ_SysTick_Config_NS(uint32_t ticks) +{ + if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk) + { + return (1UL); /* Reload value impossible */ + } + + SysTick_NS->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */ + TZ_NVIC_SetPriority_NS (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */ + SysTick_NS->VAL = 0UL; /* Load the SysTick Counter Value */ + SysTick_NS->CTRL = SysTick_CTRL_CLKSOURCE_Msk | + SysTick_CTRL_TICKINT_Msk | + SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */ + return (0UL); /* Function successful */ +} +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + +#endif + +/*@} end of CMSIS_Core_SysTickFunctions */ + + + +/* ##################################### Debug In/Output function ########################################### */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_core_DebugFunctions ITM Functions + \brief Functions that access the ITM debug interface. + @{ + */ + +extern volatile int32_t ITM_RxBuffer; /*!< External variable to receive characters. */ +#define ITM_RXBUFFER_EMPTY ((int32_t)0x5AA55AA5U) /*!< Value identifying \ref ITM_RxBuffer is ready for next character. */ + + +/** + \brief ITM Send Character + \details Transmits a character via the ITM channel 0, and + \li Just returns when no debugger is connected that has booked the output. + \li Is blocking when a debugger is connected, but the previous character sent has not been transmitted. + \param [in] ch Character to transmit. + \returns Character to transmit. + */ +__STATIC_INLINE uint32_t ITM_SendChar (uint32_t ch) +{ + if (((ITM->TCR & ITM_TCR_ITMENA_Msk) != 0UL) && /* ITM enabled */ + ((ITM->TER & 1UL ) != 0UL) ) /* ITM Port #0 enabled */ + { + while (ITM->PORT[0U].u32 == 0UL) + { + __NOP(); + } + ITM->PORT[0U].u8 = (uint8_t)ch; + } + return (ch); +} + + +/** + \brief ITM Receive Character + \details Inputs a character via the external variable \ref ITM_RxBuffer. + \return Received character. + \return -1 No character pending. + */ +__STATIC_INLINE int32_t ITM_ReceiveChar (void) +{ + int32_t ch = -1; /* no character available */ + + if (ITM_RxBuffer != ITM_RXBUFFER_EMPTY) + { + ch = ITM_RxBuffer; + ITM_RxBuffer = ITM_RXBUFFER_EMPTY; /* ready for next character */ + } + + return (ch); +} + + +/** + \brief ITM Check Character + \details Checks whether a character is pending for reading in the variable \ref ITM_RxBuffer. + \return 0 No character available. + \return 1 Character available. + */ +__STATIC_INLINE int32_t ITM_CheckChar (void) +{ + + if (ITM_RxBuffer == ITM_RXBUFFER_EMPTY) + { + return (0); /* no character available */ + } + else + { + return (1); /* character available */ + } +} + +/*@} end of CMSIS_core_DebugFunctions */ + + + + +#ifdef __cplusplus +} +#endif + +#endif /* __CORE_CM55_H_DEPENDANT */ + +#endif /* __CMSIS_GENERIC */ diff --git a/lib/cmsis/inc/core_cm7.h b/lib/cmsis/inc/core_cm7.h index 41f9afb64daff..010506e9fa430 100644 --- a/lib/cmsis/inc/core_cm7.h +++ b/lib/cmsis/inc/core_cm7.h @@ -1,11 +1,11 @@ /**************************************************************************//** * @file core_cm7.h * @brief CMSIS Cortex-M7 Core Peripheral Access Layer Header File - * @version V5.1.0 - * @date 13. March 2019 + * @version V5.1.6 + * @date 04. June 2021 ******************************************************************************/ /* - * Copyright (c) 2009-2019 Arm Limited. All rights reserved. + * Copyright (c) 2009-2021 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -209,6 +209,11 @@ #warning "__DTCM_PRESENT not defined in device header file; using default!" #endif + #ifndef __VTOR_PRESENT + #define __VTOR_PRESENT 1U + #warning "__VTOR_PRESENT not defined in device header file; using default!" + #endif + #ifndef __NVIC_PRIO_BITS #define __NVIC_PRIO_BITS 3U #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" @@ -496,7 +501,8 @@ typedef struct __OM uint32_t DCCSW; /*!< Offset: 0x26C ( /W) D-Cache Clean by Set-way */ __OM uint32_t DCCIMVAC; /*!< Offset: 0x270 ( /W) D-Cache Clean and Invalidate by MVA to PoC */ __OM uint32_t DCCISW; /*!< Offset: 0x274 ( /W) D-Cache Clean and Invalidate by Set-way */ - uint32_t RESERVED7[6U]; + __OM uint32_t BPIALL; /*!< Offset: 0x278 ( /W) Branch Predictor Invalidate All */ + uint32_t RESERVED7[5U]; __IOM uint32_t ITCMCR; /*!< Offset: 0x290 (R/W) Instruction Tightly-Coupled Memory Control Register */ __IOM uint32_t DTCMCR; /*!< Offset: 0x294 (R/W) Data Tightly-Coupled Memory Control Registers */ __IOM uint32_t AHBPCR; /*!< Offset: 0x298 (R/W) AHBP Control Register */ @@ -671,22 +677,22 @@ typedef struct #define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */ /* MemManage Fault Status Register (part of SCB Configurable Fault Status Register) */ -#define SCB_CFSR_MMARVALID_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */ +#define SCB_CFSR_MMARVALID_Pos (SCB_CFSR_MEMFAULTSR_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */ #define SCB_CFSR_MMARVALID_Msk (1UL << SCB_CFSR_MMARVALID_Pos) /*!< SCB CFSR (MMFSR): MMARVALID Mask */ -#define SCB_CFSR_MLSPERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 5U) /*!< SCB CFSR (MMFSR): MLSPERR Position */ +#define SCB_CFSR_MLSPERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 5U) /*!< SCB CFSR (MMFSR): MLSPERR Position */ #define SCB_CFSR_MLSPERR_Msk (1UL << SCB_CFSR_MLSPERR_Pos) /*!< SCB CFSR (MMFSR): MLSPERR Mask */ -#define SCB_CFSR_MSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */ +#define SCB_CFSR_MSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */ #define SCB_CFSR_MSTKERR_Msk (1UL << SCB_CFSR_MSTKERR_Pos) /*!< SCB CFSR (MMFSR): MSTKERR Mask */ -#define SCB_CFSR_MUNSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */ +#define SCB_CFSR_MUNSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */ #define SCB_CFSR_MUNSTKERR_Msk (1UL << SCB_CFSR_MUNSTKERR_Pos) /*!< SCB CFSR (MMFSR): MUNSTKERR Mask */ -#define SCB_CFSR_DACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */ +#define SCB_CFSR_DACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */ #define SCB_CFSR_DACCVIOL_Msk (1UL << SCB_CFSR_DACCVIOL_Pos) /*!< SCB CFSR (MMFSR): DACCVIOL Mask */ -#define SCB_CFSR_IACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */ +#define SCB_CFSR_IACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */ #define SCB_CFSR_IACCVIOL_Msk (1UL /*<< SCB_CFSR_IACCVIOL_Pos*/) /*!< SCB CFSR (MMFSR): IACCVIOL Mask */ /* BusFault Status Register (part of SCB Configurable Fault Status Register) */ @@ -870,21 +876,24 @@ typedef struct #define SCB_CACR_FORCEWT_Pos 2U /*!< SCB CACR: FORCEWT Position */ #define SCB_CACR_FORCEWT_Msk (1UL << SCB_CACR_FORCEWT_Pos) /*!< SCB CACR: FORCEWT Mask */ -#define SCB_CACR_ECCEN_Pos 1U /*!< SCB CACR: ECCEN Position */ -#define SCB_CACR_ECCEN_Msk (1UL << SCB_CACR_ECCEN_Pos) /*!< SCB CACR: ECCEN Mask */ +#define SCB_CACR_ECCEN_Pos 1U /*!< \deprecated SCB CACR: ECCEN Position */ +#define SCB_CACR_ECCEN_Msk (1UL << SCB_CACR_ECCEN_Pos) /*!< \deprecated SCB CACR: ECCEN Mask */ + +#define SCB_CACR_ECCDIS_Pos 1U /*!< SCB CACR: ECCDIS Position */ +#define SCB_CACR_ECCDIS_Msk (1UL << SCB_CACR_ECCDIS_Pos) /*!< SCB CACR: ECCDIS Mask */ #define SCB_CACR_SIWT_Pos 0U /*!< SCB CACR: SIWT Position */ #define SCB_CACR_SIWT_Msk (1UL /*<< SCB_CACR_SIWT_Pos*/) /*!< SCB CACR: SIWT Mask */ /* AHBS Control Register Definitions */ #define SCB_AHBSCR_INITCOUNT_Pos 11U /*!< SCB AHBSCR: INITCOUNT Position */ -#define SCB_AHBSCR_INITCOUNT_Msk (0x1FUL << SCB_AHBPCR_INITCOUNT_Pos) /*!< SCB AHBSCR: INITCOUNT Mask */ +#define SCB_AHBSCR_INITCOUNT_Msk (0x1FUL << SCB_AHBSCR_INITCOUNT_Pos) /*!< SCB AHBSCR: INITCOUNT Mask */ #define SCB_AHBSCR_TPRI_Pos 2U /*!< SCB AHBSCR: TPRI Position */ -#define SCB_AHBSCR_TPRI_Msk (0x1FFUL << SCB_AHBPCR_TPRI_Pos) /*!< SCB AHBSCR: TPRI Mask */ +#define SCB_AHBSCR_TPRI_Msk (0x1FFUL << SCB_AHBSCR_TPRI_Pos) /*!< SCB AHBSCR: TPRI Mask */ #define SCB_AHBSCR_CTL_Pos 0U /*!< SCB AHBSCR: CTL Position*/ -#define SCB_AHBSCR_CTL_Msk (3UL /*<< SCB_AHBPCR_CTL_Pos*/) /*!< SCB AHBSCR: CTL Mask */ +#define SCB_AHBSCR_CTL_Msk (3UL /*<< SCB_AHBSCR_CTL_Pos*/) /*!< SCB AHBSCR: CTL Mask */ /* Auxiliary Bus Fault Status Register Definitions */ #define SCB_ABFSR_AXIMTYPE_Pos 8U /*!< SCB ABFSR: AXIMTYPE Position*/ @@ -1903,7 +1912,9 @@ __STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) { if ((int32_t)(IRQn) >= 0) { + __COMPILER_BARRIER(); NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __COMPILER_BARRIER(); } } @@ -2126,8 +2137,9 @@ __STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGr */ __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) { - uint32_t vectors = (uint32_t )SCB->VTOR; - (* (int *) (vectors + ((int32_t)IRQn + NVIC_USER_IRQ_OFFSET) * 4)) = vector; + uint32_t *vectors = (uint32_t *)SCB->VTOR; + vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector; + __DSB(); } @@ -2141,8 +2153,8 @@ __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) */ __STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn) { - uint32_t vectors = (uint32_t )SCB->VTOR; - return (uint32_t)(* (int *) (vectors + ((int32_t)IRQn + NVIC_USER_IRQ_OFFSET) * 4)); + uint32_t *vectors = (uint32_t *)SCB->VTOR; + return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET]; } @@ -2215,349 +2227,12 @@ __STATIC_INLINE uint32_t SCB_GetFPUType(void) /*@} end of CMSIS_Core_FpuFunctions */ - /* ########################## Cache functions #################################### */ -/** - \ingroup CMSIS_Core_FunctionInterface - \defgroup CMSIS_Core_CacheFunctions Cache Functions - \brief Functions that configure Instruction and Data cache. - @{ - */ - -/* Cache Size ID Register Macros */ -#define CCSIDR_WAYS(x) (((x) & SCB_CCSIDR_ASSOCIATIVITY_Msk) >> SCB_CCSIDR_ASSOCIATIVITY_Pos) -#define CCSIDR_SETS(x) (((x) & SCB_CCSIDR_NUMSETS_Msk ) >> SCB_CCSIDR_NUMSETS_Pos ) - -#define __SCB_DCACHE_LINE_SIZE 32U /*!< Cortex-M7 cache line size is fixed to 32 bytes (8 words). See also register SCB_CCSIDR */ - -/** - \brief Enable I-Cache - \details Turns on I-Cache - */ -__STATIC_FORCEINLINE void SCB_EnableICache (void) -{ - #if defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U) - if (SCB->CCR & SCB_CCR_IC_Msk) return; /* return if ICache is already enabled */ - - __DSB(); - __ISB(); - SCB->ICIALLU = 0UL; /* invalidate I-Cache */ - __DSB(); - __ISB(); - SCB->CCR |= (uint32_t)SCB_CCR_IC_Msk; /* enable I-Cache */ - __DSB(); - __ISB(); - #endif -} - - -/** - \brief Disable I-Cache - \details Turns off I-Cache - */ -__STATIC_FORCEINLINE void SCB_DisableICache (void) -{ - #if defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U) - __DSB(); - __ISB(); - SCB->CCR &= ~(uint32_t)SCB_CCR_IC_Msk; /* disable I-Cache */ - SCB->ICIALLU = 0UL; /* invalidate I-Cache */ - __DSB(); - __ISB(); - #endif -} - - -/** - \brief Invalidate I-Cache - \details Invalidates I-Cache - */ -__STATIC_FORCEINLINE void SCB_InvalidateICache (void) -{ - #if defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U) - __DSB(); - __ISB(); - SCB->ICIALLU = 0UL; - __DSB(); - __ISB(); - #endif -} - - -/** - \brief Enable D-Cache - \details Turns on D-Cache - */ -__STATIC_FORCEINLINE void SCB_EnableDCache (void) -{ - #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) - uint32_t ccsidr; - uint32_t sets; - uint32_t ways; - - if (SCB->CCR & SCB_CCR_DC_Msk) return; /* return if DCache is already enabled */ - - SCB->CSSELR = 0U; /* select Level 1 data cache */ - __DSB(); - - ccsidr = SCB->CCSIDR; - - /* invalidate D-Cache */ - sets = (uint32_t)(CCSIDR_SETS(ccsidr)); - do { - ways = (uint32_t)(CCSIDR_WAYS(ccsidr)); - do { - SCB->DCISW = (((sets << SCB_DCISW_SET_Pos) & SCB_DCISW_SET_Msk) | - ((ways << SCB_DCISW_WAY_Pos) & SCB_DCISW_WAY_Msk) ); - #if defined ( __CC_ARM ) - __schedule_barrier(); - #endif - } while (ways-- != 0U); - } while(sets-- != 0U); - __DSB(); - - SCB->CCR |= (uint32_t)SCB_CCR_DC_Msk; /* enable D-Cache */ - - __DSB(); - __ISB(); - #endif -} - - -/** - \brief Disable D-Cache - \details Turns off D-Cache - */ -__STATIC_FORCEINLINE void SCB_DisableDCache (void) -{ - #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) - uint32_t ccsidr; - uint32_t sets; - uint32_t ways; - - SCB->CSSELR = 0U; /* select Level 1 data cache */ - __DSB(); - - SCB->CCR &= ~(uint32_t)SCB_CCR_DC_Msk; /* disable D-Cache */ - __DSB(); - - ccsidr = SCB->CCSIDR; - - /* clean & invalidate D-Cache */ - sets = (uint32_t)(CCSIDR_SETS(ccsidr)); - do { - ways = (uint32_t)(CCSIDR_WAYS(ccsidr)); - do { - SCB->DCCISW = (((sets << SCB_DCCISW_SET_Pos) & SCB_DCCISW_SET_Msk) | - ((ways << SCB_DCCISW_WAY_Pos) & SCB_DCCISW_WAY_Msk) ); - #if defined ( __CC_ARM ) - __schedule_barrier(); - #endif - } while (ways-- != 0U); - } while(sets-- != 0U); - - __DSB(); - __ISB(); - #endif -} - - -/** - \brief Invalidate D-Cache - \details Invalidates D-Cache - */ -__STATIC_FORCEINLINE void SCB_InvalidateDCache (void) -{ - #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) - uint32_t ccsidr; - uint32_t sets; - uint32_t ways; - - SCB->CSSELR = 0U; /* select Level 1 data cache */ - __DSB(); - - ccsidr = SCB->CCSIDR; - - /* invalidate D-Cache */ - sets = (uint32_t)(CCSIDR_SETS(ccsidr)); - do { - ways = (uint32_t)(CCSIDR_WAYS(ccsidr)); - do { - SCB->DCISW = (((sets << SCB_DCISW_SET_Pos) & SCB_DCISW_SET_Msk) | - ((ways << SCB_DCISW_WAY_Pos) & SCB_DCISW_WAY_Msk) ); - #if defined ( __CC_ARM ) - __schedule_barrier(); - #endif - } while (ways-- != 0U); - } while(sets-- != 0U); - - __DSB(); - __ISB(); - #endif -} - - -/** - \brief Clean D-Cache - \details Cleans D-Cache - */ -__STATIC_FORCEINLINE void SCB_CleanDCache (void) -{ - #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) - uint32_t ccsidr; - uint32_t sets; - uint32_t ways; - - SCB->CSSELR = 0U; /* select Level 1 data cache */ - __DSB(); - - ccsidr = SCB->CCSIDR; - - /* clean D-Cache */ - sets = (uint32_t)(CCSIDR_SETS(ccsidr)); - do { - ways = (uint32_t)(CCSIDR_WAYS(ccsidr)); - do { - SCB->DCCSW = (((sets << SCB_DCCSW_SET_Pos) & SCB_DCCSW_SET_Msk) | - ((ways << SCB_DCCSW_WAY_Pos) & SCB_DCCSW_WAY_Msk) ); - #if defined ( __CC_ARM ) - __schedule_barrier(); - #endif - } while (ways-- != 0U); - } while(sets-- != 0U); - - __DSB(); - __ISB(); - #endif -} - - -/** - \brief Clean & Invalidate D-Cache - \details Cleans and Invalidates D-Cache - */ -__STATIC_FORCEINLINE void SCB_CleanInvalidateDCache (void) -{ - #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) - uint32_t ccsidr; - uint32_t sets; - uint32_t ways; - - SCB->CSSELR = 0U; /* select Level 1 data cache */ - __DSB(); - - ccsidr = SCB->CCSIDR; - - /* clean & invalidate D-Cache */ - sets = (uint32_t)(CCSIDR_SETS(ccsidr)); - do { - ways = (uint32_t)(CCSIDR_WAYS(ccsidr)); - do { - SCB->DCCISW = (((sets << SCB_DCCISW_SET_Pos) & SCB_DCCISW_SET_Msk) | - ((ways << SCB_DCCISW_WAY_Pos) & SCB_DCCISW_WAY_Msk) ); - #if defined ( __CC_ARM ) - __schedule_barrier(); - #endif - } while (ways-- != 0U); - } while(sets-- != 0U); - - __DSB(); - __ISB(); - #endif -} - - -/** - \brief D-Cache Invalidate by address - \details Invalidates D-Cache for the given address. - D-Cache is invalidated starting from a 32 byte aligned address in 32 byte granularity. - D-Cache memory blocks which are part of given address + given size are invalidated. - \param[in] addr address - \param[in] dsize size of memory block (in number of bytes) -*/ -__STATIC_FORCEINLINE void SCB_InvalidateDCache_by_Addr (void *addr, int32_t dsize) -{ - #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) - if ( dsize > 0 ) { - int32_t op_size = dsize + (((uint32_t)addr) & (__SCB_DCACHE_LINE_SIZE - 1U)); - uint32_t op_addr = (uint32_t)addr /* & ~(__SCB_DCACHE_LINE_SIZE - 1U) */; - - __DSB(); - - do { - SCB->DCIMVAC = op_addr; /* register accepts only 32byte aligned values, only bits 31..5 are valid */ - op_addr += __SCB_DCACHE_LINE_SIZE; - op_size -= __SCB_DCACHE_LINE_SIZE; - } while ( op_size > 0 ); - - __DSB(); - __ISB(); - } - #endif -} - - -/** - \brief D-Cache Clean by address - \details Cleans D-Cache for the given address - D-Cache is cleaned starting from a 32 byte aligned address in 32 byte granularity. - D-Cache memory blocks which are part of given address + given size are cleaned. - \param[in] addr address - \param[in] dsize size of memory block (in number of bytes) -*/ -__STATIC_FORCEINLINE void SCB_CleanDCache_by_Addr (uint32_t *addr, int32_t dsize) -{ - #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) - if ( dsize > 0 ) { - int32_t op_size = dsize + (((uint32_t)addr) & (__SCB_DCACHE_LINE_SIZE - 1U)); - uint32_t op_addr = (uint32_t)addr /* & ~(__SCB_DCACHE_LINE_SIZE - 1U) */; - - __DSB(); - - do { - SCB->DCCMVAC = op_addr; /* register accepts only 32byte aligned values, only bits 31..5 are valid */ - op_addr += __SCB_DCACHE_LINE_SIZE; - op_size -= __SCB_DCACHE_LINE_SIZE; - } while ( op_size > 0 ); - - __DSB(); - __ISB(); - } - #endif -} - - -/** - \brief D-Cache Clean and Invalidate by address - \details Cleans and invalidates D_Cache for the given address - D-Cache is cleaned and invalidated starting from a 32 byte aligned address in 32 byte granularity. - D-Cache memory blocks which are part of given address + given size are cleaned and invalidated. - \param[in] addr address (aligned to 32-byte boundary) - \param[in] dsize size of memory block (in number of bytes) -*/ -__STATIC_FORCEINLINE void SCB_CleanInvalidateDCache_by_Addr (uint32_t *addr, int32_t dsize) -{ - #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) - if ( dsize > 0 ) { - int32_t op_size = dsize + (((uint32_t)addr) & (__SCB_DCACHE_LINE_SIZE - 1U)); - uint32_t op_addr = (uint32_t)addr /* & ~(__SCB_DCACHE_LINE_SIZE - 1U) */; - - __DSB(); - - do { - SCB->DCCIMVAC = op_addr; /* register accepts only 32byte aligned values, only bits 31..5 are valid */ - op_addr += __SCB_DCACHE_LINE_SIZE; - op_size -= __SCB_DCACHE_LINE_SIZE; - } while ( op_size > 0 ); - - __DSB(); - __ISB(); - } - #endif -} - -/*@} end of CMSIS_Core_CacheFunctions */ +#if ((defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U)) || \ + (defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U))) +#include "cachel1_armv7.h" +#endif /* ################################## SysTick function ############################################ */ diff --git a/lib/cmsis/inc/core_cm85.h b/lib/cmsis/inc/core_cm85.h new file mode 100644 index 0000000000000..60463111897f8 --- /dev/null +++ b/lib/cmsis/inc/core_cm85.h @@ -0,0 +1,4672 @@ +/**************************************************************************//** + * @file core_cm85.h + * @brief CMSIS Cortex-M85 Core Peripheral Access Layer Header File + * @version V1.0.4 + * @date 21. April 2022 + ******************************************************************************/ +/* + * Copyright (c) 2022 Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 + * + * 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. + */ + +#if defined ( __ICCARM__ ) + #pragma system_include /* treat file as system include file for MISRA check */ +#elif defined (__clang__) + #pragma clang system_header /* treat file as system include file */ +#elif defined ( __GNUC__ ) + #pragma GCC diagnostic ignored "-Wpedantic" /* disable pedantic warning due to unnamed structs/unions */ +#endif + +#ifndef __CORE_CM85_H_GENERIC +#define __CORE_CM85_H_GENERIC + +#include + +#ifdef __cplusplus + extern "C" { +#endif + +/** + \page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions + CMSIS violates the following MISRA-C:2004 rules: + + \li Required Rule 8.5, object/function definition in header file.
+ Function definitions in header files are used to allow 'inlining'. + + \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.
+ Unions are used for effective representation of core registers. + + \li Advisory Rule 19.7, Function-like macro defined.
+ Function-like macros are used to allow more efficient code. + */ + + +/******************************************************************************* + * CMSIS definitions + ******************************************************************************/ +/** + \ingroup Cortex_M85 + @{ + */ + +#include "cmsis_version.h" + +/* CMSIS CM85 definitions */ + +#define __CORTEX_M (85U) /*!< Cortex-M Core */ + +#if defined ( __CC_ARM ) + #error Legacy Arm Compiler does not support Armv8.1-M target architecture. +#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) + #if defined __ARM_FP + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) + #define __FPU_USED 1U + #else + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #define __FPU_USED 0U + #endif + #else + #define __FPU_USED 0U + #endif + + #if defined(__ARM_FEATURE_DSP) + #if defined(__DSP_PRESENT) && (__DSP_PRESENT == 1U) + #define __DSP_USED 1U + #else + #error "Compiler generates DSP (SIMD) instructions for a devices without DSP extensions (check __DSP_PRESENT)" + #define __DSP_USED 0U + #endif + #else + #define __DSP_USED 0U + #endif + +#elif defined ( __GNUC__ ) + #if defined (__VFP_FP__) && !defined(__SOFTFP__) + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) + #define __FPU_USED 1U + #else + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #define __FPU_USED 0U + #endif + #else + #define __FPU_USED 0U + #endif + + #if defined(__ARM_FEATURE_DSP) + #if defined(__DSP_PRESENT) && (__DSP_PRESENT == 1U) + #define __DSP_USED 1U + #else + #error "Compiler generates DSP (SIMD) instructions for a devices without DSP extensions (check __DSP_PRESENT)" + #define __DSP_USED 0U + #endif + #else + #define __DSP_USED 0U + #endif + +#elif defined ( __ICCARM__ ) + #if defined __ARMVFP__ + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) + #define __FPU_USED 1U + #else + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #define __FPU_USED 0U + #endif + #else + #define __FPU_USED 0U + #endif + + #if defined(__ARM_FEATURE_DSP) + #if defined(__DSP_PRESENT) && (__DSP_PRESENT == 1U) + #define __DSP_USED 1U + #else + #error "Compiler generates DSP (SIMD) instructions for a devices without DSP extensions (check __DSP_PRESENT)" + #define __DSP_USED 0U + #endif + #else + #define __DSP_USED 0U + #endif + +#elif defined ( __TI_ARM__ ) + #if defined __TI_VFP_SUPPORT__ + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) + #define __FPU_USED 1U + #else + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #define __FPU_USED 0U + #endif + #else + #define __FPU_USED 0U + #endif + +#elif defined ( __TASKING__ ) + #if defined __FPU_VFP__ + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) + #define __FPU_USED 1U + #else + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #define __FPU_USED 0U + #endif + #else + #define __FPU_USED 0U + #endif + +#elif defined ( __CSMC__ ) + #if ( __CSMC__ & 0x400U) + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) + #define __FPU_USED 1U + #else + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #define __FPU_USED 0U + #endif + #else + #define __FPU_USED 0U + #endif + +#endif + +#include "cmsis_compiler.h" /* CMSIS compiler specific defines */ + + +#ifdef __cplusplus +} +#endif + +#endif /* __CORE_CM85_H_GENERIC */ + +#ifndef __CMSIS_GENERIC + +#ifndef __CORE_CM85_H_DEPENDANT +#define __CORE_CM85_H_DEPENDANT + +#ifdef __cplusplus + extern "C" { +#endif + +/* check device defines and use defaults */ +#if defined __CHECK_DEVICE_DEFINES + #ifndef __CM85_REV + #define __CM85_REV 0x0001U + #warning "__CM85_REV not defined in device header file; using default!" + #endif + + #ifndef __FPU_PRESENT + #define __FPU_PRESENT 0U + #warning "__FPU_PRESENT not defined in device header file; using default!" + #endif + + #if __FPU_PRESENT != 0U + #ifndef __FPU_DP + #define __FPU_DP 0U + #warning "__FPU_DP not defined in device header file; using default!" + #endif + #endif + + #ifndef __MPU_PRESENT + #define __MPU_PRESENT 0U + #warning "__MPU_PRESENT not defined in device header file; using default!" + #endif + + #ifndef __ICACHE_PRESENT + #define __ICACHE_PRESENT 0U + #warning "__ICACHE_PRESENT not defined in device header file; using default!" + #endif + + #ifndef __DCACHE_PRESENT + #define __DCACHE_PRESENT 0U + #warning "__DCACHE_PRESENT not defined in device header file; using default!" + #endif + + #ifndef __VTOR_PRESENT + #define __VTOR_PRESENT 1U + #warning "__VTOR_PRESENT not defined in device header file; using default!" + #endif + + #ifndef __PMU_PRESENT + #define __PMU_PRESENT 0U + #warning "__PMU_PRESENT not defined in device header file; using default!" + #endif + + #if __PMU_PRESENT != 0U + #ifndef __PMU_NUM_EVENTCNT + #define __PMU_NUM_EVENTCNT 8U + #warning "__PMU_NUM_EVENTCNT not defined in device header file; using default!" + #elif (__PMU_NUM_EVENTCNT > 8 || __PMU_NUM_EVENTCNT < 2) + #error "__PMU_NUM_EVENTCNT is out of range in device header file!" */ + #endif + #endif + + #ifndef __SAUREGION_PRESENT + #define __SAUREGION_PRESENT 0U + #warning "__SAUREGION_PRESENT not defined in device header file; using default!" + #endif + + #ifndef __DSP_PRESENT + #define __DSP_PRESENT 0U + #warning "__DSP_PRESENT not defined in device header file; using default!" + #endif + + #ifndef __NVIC_PRIO_BITS + #define __NVIC_PRIO_BITS 3U + #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" + #endif + + #ifndef __Vendor_SysTickConfig + #define __Vendor_SysTickConfig 0U + #warning "__Vendor_SysTickConfig not defined in device header file; using default!" + #endif +#endif + +/* IO definitions (access restrictions to peripheral registers) */ +/** + \defgroup CMSIS_glob_defs CMSIS Global Defines + + IO Type Qualifiers are used + \li to specify the access to peripheral variables. + \li for automatic generation of peripheral register debug information. +*/ +#ifdef __cplusplus + #define __I volatile /*!< Defines 'read only' permissions */ +#else + #define __I volatile const /*!< Defines 'read only' permissions */ +#endif +#define __O volatile /*!< Defines 'write only' permissions */ +#define __IO volatile /*!< Defines 'read / write' permissions */ + +/* following defines should be used for structure members */ +#define __IM volatile const /*! Defines 'read only' structure member permissions */ +#define __OM volatile /*! Defines 'write only' structure member permissions */ +#define __IOM volatile /*! Defines 'read / write' structure member permissions */ + +/*@} end of group Cortex_M85 */ + + + +/******************************************************************************* + * Register Abstraction + Core Register contain: + - Core Register + - Core NVIC Register + - Core EWIC Register + - Core SCB Register + - Core SysTick Register + - Core Debug Register + - Core PMU Register + - Core MPU Register + - Core SAU Register + - Core FPU Register + ******************************************************************************/ +/** + \defgroup CMSIS_core_register Defines and Type Definitions + \brief Type definitions and defines for Cortex-M processor based devices. +*/ + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_CORE Status and Control Registers + \brief Core Register type definitions. + @{ + */ + +/** + \brief Union type to access the Application Program Status Register (APSR). + */ +typedef union +{ + struct + { + uint32_t _reserved0:16; /*!< bit: 0..15 Reserved */ + uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */ + uint32_t _reserved1:7; /*!< bit: 20..26 Reserved */ + uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ + uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ + uint32_t C:1; /*!< bit: 29 Carry condition code flag */ + uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ + uint32_t N:1; /*!< bit: 31 Negative condition code flag */ + } b; /*!< Structure used for bit access */ + uint32_t w; /*!< Type used for word access */ +} APSR_Type; + +/* APSR Register Definitions */ +#define APSR_N_Pos 31U /*!< APSR: N Position */ +#define APSR_N_Msk (1UL << APSR_N_Pos) /*!< APSR: N Mask */ + +#define APSR_Z_Pos 30U /*!< APSR: Z Position */ +#define APSR_Z_Msk (1UL << APSR_Z_Pos) /*!< APSR: Z Mask */ + +#define APSR_C_Pos 29U /*!< APSR: C Position */ +#define APSR_C_Msk (1UL << APSR_C_Pos) /*!< APSR: C Mask */ + +#define APSR_V_Pos 28U /*!< APSR: V Position */ +#define APSR_V_Msk (1UL << APSR_V_Pos) /*!< APSR: V Mask */ + +#define APSR_Q_Pos 27U /*!< APSR: Q Position */ +#define APSR_Q_Msk (1UL << APSR_Q_Pos) /*!< APSR: Q Mask */ + +#define APSR_GE_Pos 16U /*!< APSR: GE Position */ +#define APSR_GE_Msk (0xFUL << APSR_GE_Pos) /*!< APSR: GE Mask */ + + +/** + \brief Union type to access the Interrupt Program Status Register (IPSR). + */ +typedef union +{ + struct + { + uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ + uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */ + } b; /*!< Structure used for bit access */ + uint32_t w; /*!< Type used for word access */ +} IPSR_Type; + +/* IPSR Register Definitions */ +#define IPSR_ISR_Pos 0U /*!< IPSR: ISR Position */ +#define IPSR_ISR_Msk (0x1FFUL /*<< IPSR_ISR_Pos*/) /*!< IPSR: ISR Mask */ + + +/** + \brief Union type to access the Special-Purpose Program Status Registers (xPSR). + */ +typedef union +{ + struct + { + uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ + uint32_t _reserved0:7; /*!< bit: 9..15 Reserved */ + uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */ + uint32_t _reserved1:1; /*!< bit: 20 Reserved */ + uint32_t B:1; /*!< bit: 21 BTI active (read 0) */ + uint32_t _reserved2:2; /*!< bit: 22..23 Reserved */ + uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */ + uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */ + uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ + uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ + uint32_t C:1; /*!< bit: 29 Carry condition code flag */ + uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ + uint32_t N:1; /*!< bit: 31 Negative condition code flag */ + } b; /*!< Structure used for bit access */ + uint32_t w; /*!< Type used for word access */ +} xPSR_Type; + +/* xPSR Register Definitions */ +#define xPSR_N_Pos 31U /*!< xPSR: N Position */ +#define xPSR_N_Msk (1UL << xPSR_N_Pos) /*!< xPSR: N Mask */ + +#define xPSR_Z_Pos 30U /*!< xPSR: Z Position */ +#define xPSR_Z_Msk (1UL << xPSR_Z_Pos) /*!< xPSR: Z Mask */ + +#define xPSR_C_Pos 29U /*!< xPSR: C Position */ +#define xPSR_C_Msk (1UL << xPSR_C_Pos) /*!< xPSR: C Mask */ + +#define xPSR_V_Pos 28U /*!< xPSR: V Position */ +#define xPSR_V_Msk (1UL << xPSR_V_Pos) /*!< xPSR: V Mask */ + +#define xPSR_Q_Pos 27U /*!< xPSR: Q Position */ +#define xPSR_Q_Msk (1UL << xPSR_Q_Pos) /*!< xPSR: Q Mask */ + +#define xPSR_IT_Pos 25U /*!< xPSR: IT Position */ +#define xPSR_IT_Msk (3UL << xPSR_IT_Pos) /*!< xPSR: IT Mask */ + +#define xPSR_T_Pos 24U /*!< xPSR: T Position */ +#define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */ + +#define xPSR_B_Pos 21U /*!< xPSR: B Position */ +#define xPSR_B_Msk (1UL << xPSR_B_Pos) /*!< xPSR: B Mask */ + +#define xPSR_GE_Pos 16U /*!< xPSR: GE Position */ +#define xPSR_GE_Msk (0xFUL << xPSR_GE_Pos) /*!< xPSR: GE Mask */ + +#define xPSR_ISR_Pos 0U /*!< xPSR: ISR Position */ +#define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */ + + +/** + \brief Union type to access the Control Registers (CONTROL). + */ +typedef union +{ + struct + { + uint32_t nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */ + uint32_t SPSEL:1; /*!< bit: 1 Stack-pointer select */ + uint32_t FPCA:1; /*!< bit: 2 Floating-point context active */ + uint32_t SFPA:1; /*!< bit: 3 Secure floating-point active */ + uint32_t BTI_EN:1; /*!< bit: 4 Privileged branch target identification enable */ + uint32_t UBTI_EN:1; /*!< bit: 5 Unprivileged branch target identification enable */ + uint32_t PAC_EN:1; /*!< bit: 6 Privileged pointer authentication enable */ + uint32_t UPAC_EN:1; /*!< bit: 7 Unprivileged pointer authentication enable */ + uint32_t _reserved1:24; /*!< bit: 8..31 Reserved */ + } b; /*!< Structure used for bit access */ + uint32_t w; /*!< Type used for word access */ +} CONTROL_Type; + +/* CONTROL Register Definitions */ +#define CONTROL_UPAC_EN_Pos 7U /*!< CONTROL: UPAC_EN Position */ +#define CONTROL_UPAC_EN_Msk (1UL << CONTROL_UPAC_EN_Pos) /*!< CONTROL: UPAC_EN Mask */ + +#define CONTROL_PAC_EN_Pos 6U /*!< CONTROL: PAC_EN Position */ +#define CONTROL_PAC_EN_Msk (1UL << CONTROL_PAC_EN_Pos) /*!< CONTROL: PAC_EN Mask */ + +#define CONTROL_UBTI_EN_Pos 5U /*!< CONTROL: UBTI_EN Position */ +#define CONTROL_UBTI_EN_Msk (1UL << CONTROL_UBTI_EN_Pos) /*!< CONTROL: UBTI_EN Mask */ + +#define CONTROL_BTI_EN_Pos 4U /*!< CONTROL: BTI_EN Position */ +#define CONTROL_BTI_EN_Msk (1UL << CONTROL_BTI_EN_Pos) /*!< CONTROL: BTI_EN Mask */ + +#define CONTROL_SFPA_Pos 3U /*!< CONTROL: SFPA Position */ +#define CONTROL_SFPA_Msk (1UL << CONTROL_SFPA_Pos) /*!< CONTROL: SFPA Mask */ + +#define CONTROL_FPCA_Pos 2U /*!< CONTROL: FPCA Position */ +#define CONTROL_FPCA_Msk (1UL << CONTROL_FPCA_Pos) /*!< CONTROL: FPCA Mask */ + +#define CONTROL_SPSEL_Pos 1U /*!< CONTROL: SPSEL Position */ +#define CONTROL_SPSEL_Msk (1UL << CONTROL_SPSEL_Pos) /*!< CONTROL: SPSEL Mask */ + +#define CONTROL_nPRIV_Pos 0U /*!< CONTROL: nPRIV Position */ +#define CONTROL_nPRIV_Msk (1UL /*<< CONTROL_nPRIV_Pos*/) /*!< CONTROL: nPRIV Mask */ + +/*@} end of group CMSIS_CORE */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC) + \brief Type definitions for the NVIC Registers + @{ + */ + +/** + \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC). + */ +typedef struct +{ + __IOM uint32_t ISER[16U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */ + uint32_t RESERVED0[16U]; + __IOM uint32_t ICER[16U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */ + uint32_t RSERVED1[16U]; + __IOM uint32_t ISPR[16U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */ + uint32_t RESERVED2[16U]; + __IOM uint32_t ICPR[16U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */ + uint32_t RESERVED3[16U]; + __IOM uint32_t IABR[16U]; /*!< Offset: 0x200 (R/W) Interrupt Active bit Register */ + uint32_t RESERVED4[16U]; + __IOM uint32_t ITNS[16U]; /*!< Offset: 0x280 (R/W) Interrupt Non-Secure State Register */ + uint32_t RESERVED5[16U]; + __IOM uint8_t IPR[496U]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register (8Bit wide) */ + uint32_t RESERVED6[580U]; + __OM uint32_t STIR; /*!< Offset: 0xE00 ( /W) Software Trigger Interrupt Register */ +} NVIC_Type; + +/* Software Triggered Interrupt Register Definitions */ +#define NVIC_STIR_INTID_Pos 0U /*!< STIR: INTLINESNUM Position */ +#define NVIC_STIR_INTID_Msk (0x1FFUL /*<< NVIC_STIR_INTID_Pos*/) /*!< STIR: INTLINESNUM Mask */ + +/*@} end of group CMSIS_NVIC */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_SCB System Control Block (SCB) + \brief Type definitions for the System Control Block Registers + @{ + */ + +/** + \brief Structure type to access the System Control Block (SCB). + */ +typedef struct +{ + __IM uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */ + __IOM uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */ + __IOM uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */ + __IOM uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */ + __IOM uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */ + __IOM uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */ + __IOM uint8_t SHPR[12U]; /*!< Offset: 0x018 (R/W) System Handlers Priority Registers (4-7, 8-11, 12-15) */ + __IOM uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */ + __IOM uint32_t CFSR; /*!< Offset: 0x028 (R/W) Configurable Fault Status Register */ + __IOM uint32_t HFSR; /*!< Offset: 0x02C (R/W) HardFault Status Register */ + __IOM uint32_t DFSR; /*!< Offset: 0x030 (R/W) Debug Fault Status Register */ + __IOM uint32_t MMFAR; /*!< Offset: 0x034 (R/W) MemManage Fault Address Register */ + __IOM uint32_t BFAR; /*!< Offset: 0x038 (R/W) BusFault Address Register */ + __IOM uint32_t AFSR; /*!< Offset: 0x03C (R/W) Auxiliary Fault Status Register */ + __IM uint32_t ID_PFR[2U]; /*!< Offset: 0x040 (R/ ) Processor Feature Register */ + __IM uint32_t ID_DFR; /*!< Offset: 0x048 (R/ ) Debug Feature Register */ + __IM uint32_t ID_AFR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */ + __IM uint32_t ID_MMFR[4U]; /*!< Offset: 0x050 (R/ ) Memory Model Feature Register */ + __IM uint32_t ID_ISAR[6U]; /*!< Offset: 0x060 (R/ ) Instruction Set Attributes Register */ + __IM uint32_t CLIDR; /*!< Offset: 0x078 (R/ ) Cache Level ID register */ + __IM uint32_t CTR; /*!< Offset: 0x07C (R/ ) Cache Type register */ + __IM uint32_t CCSIDR; /*!< Offset: 0x080 (R/ ) Cache Size ID Register */ + __IOM uint32_t CSSELR; /*!< Offset: 0x084 (R/W) Cache Size Selection Register */ + __IOM uint32_t CPACR; /*!< Offset: 0x088 (R/W) Coprocessor Access Control Register */ + __IOM uint32_t NSACR; /*!< Offset: 0x08C (R/W) Non-Secure Access Control Register */ + uint32_t RESERVED7[21U]; + __IOM uint32_t SFSR; /*!< Offset: 0x0E4 (R/W) Secure Fault Status Register */ + __IOM uint32_t SFAR; /*!< Offset: 0x0E8 (R/W) Secure Fault Address Register */ + uint32_t RESERVED3[69U]; + __OM uint32_t STIR; /*!< Offset: 0x200 ( /W) Software Triggered Interrupt Register */ + __IOM uint32_t RFSR; /*!< Offset: 0x204 (R/W) RAS Fault Status Register */ + uint32_t RESERVED4[14U]; + __IM uint32_t MVFR0; /*!< Offset: 0x240 (R/ ) Media and VFP Feature Register 0 */ + __IM uint32_t MVFR1; /*!< Offset: 0x244 (R/ ) Media and VFP Feature Register 1 */ + __IM uint32_t MVFR2; /*!< Offset: 0x248 (R/ ) Media and VFP Feature Register 2 */ + uint32_t RESERVED5[1U]; + __OM uint32_t ICIALLU; /*!< Offset: 0x250 ( /W) I-Cache Invalidate All to PoU */ + uint32_t RESERVED6[1U]; + __OM uint32_t ICIMVAU; /*!< Offset: 0x258 ( /W) I-Cache Invalidate by MVA to PoU */ + __OM uint32_t DCIMVAC; /*!< Offset: 0x25C ( /W) D-Cache Invalidate by MVA to PoC */ + __OM uint32_t DCISW; /*!< Offset: 0x260 ( /W) D-Cache Invalidate by Set-way */ + __OM uint32_t DCCMVAU; /*!< Offset: 0x264 ( /W) D-Cache Clean by MVA to PoU */ + __OM uint32_t DCCMVAC; /*!< Offset: 0x268 ( /W) D-Cache Clean by MVA to PoC */ + __OM uint32_t DCCSW; /*!< Offset: 0x26C ( /W) D-Cache Clean by Set-way */ + __OM uint32_t DCCIMVAC; /*!< Offset: 0x270 ( /W) D-Cache Clean and Invalidate by MVA to PoC */ + __OM uint32_t DCCISW; /*!< Offset: 0x274 ( /W) D-Cache Clean and Invalidate by Set-way */ + __OM uint32_t BPIALL; /*!< Offset: 0x278 ( /W) Branch Predictor Invalidate All */ +} SCB_Type; + +/* SCB CPUID Register Definitions */ +#define SCB_CPUID_IMPLEMENTER_Pos 24U /*!< SCB CPUID: IMPLEMENTER Position */ +#define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */ + +#define SCB_CPUID_VARIANT_Pos 20U /*!< SCB CPUID: VARIANT Position */ +#define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */ + +#define SCB_CPUID_ARCHITECTURE_Pos 16U /*!< SCB CPUID: ARCHITECTURE Position */ +#define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */ + +#define SCB_CPUID_PARTNO_Pos 4U /*!< SCB CPUID: PARTNO Position */ +#define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */ + +#define SCB_CPUID_REVISION_Pos 0U /*!< SCB CPUID: REVISION Position */ +#define SCB_CPUID_REVISION_Msk (0xFUL /*<< SCB_CPUID_REVISION_Pos*/) /*!< SCB CPUID: REVISION Mask */ + +/* SCB Interrupt Control State Register Definitions */ +#define SCB_ICSR_PENDNMISET_Pos 31U /*!< SCB ICSR: PENDNMISET Position */ +#define SCB_ICSR_PENDNMISET_Msk (1UL << SCB_ICSR_PENDNMISET_Pos) /*!< SCB ICSR: PENDNMISET Mask */ + +#define SCB_ICSR_NMIPENDSET_Pos SCB_ICSR_PENDNMISET_Pos /*!< SCB ICSR: NMIPENDSET Position, backward compatibility */ +#define SCB_ICSR_NMIPENDSET_Msk SCB_ICSR_PENDNMISET_Msk /*!< SCB ICSR: NMIPENDSET Mask, backward compatibility */ + +#define SCB_ICSR_PENDNMICLR_Pos 30U /*!< SCB ICSR: PENDNMICLR Position */ +#define SCB_ICSR_PENDNMICLR_Msk (1UL << SCB_ICSR_PENDNMICLR_Pos) /*!< SCB ICSR: PENDNMICLR Mask */ + +#define SCB_ICSR_PENDSVSET_Pos 28U /*!< SCB ICSR: PENDSVSET Position */ +#define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */ + +#define SCB_ICSR_PENDSVCLR_Pos 27U /*!< SCB ICSR: PENDSVCLR Position */ +#define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */ + +#define SCB_ICSR_PENDSTSET_Pos 26U /*!< SCB ICSR: PENDSTSET Position */ +#define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */ + +#define SCB_ICSR_PENDSTCLR_Pos 25U /*!< SCB ICSR: PENDSTCLR Position */ +#define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */ + +#define SCB_ICSR_STTNS_Pos 24U /*!< SCB ICSR: STTNS Position (Security Extension) */ +#define SCB_ICSR_STTNS_Msk (1UL << SCB_ICSR_STTNS_Pos) /*!< SCB ICSR: STTNS Mask (Security Extension) */ + +#define SCB_ICSR_ISRPREEMPT_Pos 23U /*!< SCB ICSR: ISRPREEMPT Position */ +#define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */ + +#define SCB_ICSR_ISRPENDING_Pos 22U /*!< SCB ICSR: ISRPENDING Position */ +#define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */ + +#define SCB_ICSR_VECTPENDING_Pos 12U /*!< SCB ICSR: VECTPENDING Position */ +#define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */ + +#define SCB_ICSR_RETTOBASE_Pos 11U /*!< SCB ICSR: RETTOBASE Position */ +#define SCB_ICSR_RETTOBASE_Msk (1UL << SCB_ICSR_RETTOBASE_Pos) /*!< SCB ICSR: RETTOBASE Mask */ + +#define SCB_ICSR_VECTACTIVE_Pos 0U /*!< SCB ICSR: VECTACTIVE Position */ +#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/) /*!< SCB ICSR: VECTACTIVE Mask */ + +/* SCB Vector Table Offset Register Definitions */ +#define SCB_VTOR_TBLOFF_Pos 7U /*!< SCB VTOR: TBLOFF Position */ +#define SCB_VTOR_TBLOFF_Msk (0x1FFFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF Mask */ + +/* SCB Application Interrupt and Reset Control Register Definitions */ +#define SCB_AIRCR_VECTKEY_Pos 16U /*!< SCB AIRCR: VECTKEY Position */ +#define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */ + +#define SCB_AIRCR_VECTKEYSTAT_Pos 16U /*!< SCB AIRCR: VECTKEYSTAT Position */ +#define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */ + +#define SCB_AIRCR_ENDIANESS_Pos 15U /*!< SCB AIRCR: ENDIANESS Position */ +#define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */ + +#define SCB_AIRCR_PRIS_Pos 14U /*!< SCB AIRCR: PRIS Position */ +#define SCB_AIRCR_PRIS_Msk (1UL << SCB_AIRCR_PRIS_Pos) /*!< SCB AIRCR: PRIS Mask */ + +#define SCB_AIRCR_BFHFNMINS_Pos 13U /*!< SCB AIRCR: BFHFNMINS Position */ +#define SCB_AIRCR_BFHFNMINS_Msk (1UL << SCB_AIRCR_BFHFNMINS_Pos) /*!< SCB AIRCR: BFHFNMINS Mask */ + +#define SCB_AIRCR_PRIGROUP_Pos 8U /*!< SCB AIRCR: PRIGROUP Position */ +#define SCB_AIRCR_PRIGROUP_Msk (7UL << SCB_AIRCR_PRIGROUP_Pos) /*!< SCB AIRCR: PRIGROUP Mask */ + +#define SCB_AIRCR_IESB_Pos 5U /*!< SCB AIRCR: Implicit ESB Enable Position */ +#define SCB_AIRCR_IESB_Msk (1UL << SCB_AIRCR_IESB_Pos) /*!< SCB AIRCR: Implicit ESB Enable Mask */ + +#define SCB_AIRCR_DIT_Pos 4U /*!< SCB AIRCR: Data Independent Timing Position */ +#define SCB_AIRCR_DIT_Msk (1UL << SCB_AIRCR_DIT_Pos) /*!< SCB AIRCR: Data Independent Timing Mask */ + +#define SCB_AIRCR_SYSRESETREQS_Pos 3U /*!< SCB AIRCR: SYSRESETREQS Position */ +#define SCB_AIRCR_SYSRESETREQS_Msk (1UL << SCB_AIRCR_SYSRESETREQS_Pos) /*!< SCB AIRCR: SYSRESETREQS Mask */ + +#define SCB_AIRCR_SYSRESETREQ_Pos 2U /*!< SCB AIRCR: SYSRESETREQ Position */ +#define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */ + +#define SCB_AIRCR_VECTCLRACTIVE_Pos 1U /*!< SCB AIRCR: VECTCLRACTIVE Position */ +#define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */ + +/* SCB System Control Register Definitions */ +#define SCB_SCR_SEVONPEND_Pos 4U /*!< SCB SCR: SEVONPEND Position */ +#define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */ + +#define SCB_SCR_SLEEPDEEPS_Pos 3U /*!< SCB SCR: SLEEPDEEPS Position */ +#define SCB_SCR_SLEEPDEEPS_Msk (1UL << SCB_SCR_SLEEPDEEPS_Pos) /*!< SCB SCR: SLEEPDEEPS Mask */ + +#define SCB_SCR_SLEEPDEEP_Pos 2U /*!< SCB SCR: SLEEPDEEP Position */ +#define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */ + +#define SCB_SCR_SLEEPONEXIT_Pos 1U /*!< SCB SCR: SLEEPONEXIT Position */ +#define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */ + +/* SCB Configuration Control Register Definitions */ +#define SCB_CCR_TRD_Pos 20U /*!< SCB CCR: TRD Position */ +#define SCB_CCR_TRD_Msk (1UL << SCB_CCR_TRD_Pos) /*!< SCB CCR: TRD Mask */ + +#define SCB_CCR_LOB_Pos 19U /*!< SCB CCR: LOB Position */ +#define SCB_CCR_LOB_Msk (1UL << SCB_CCR_LOB_Pos) /*!< SCB CCR: LOB Mask */ + +#define SCB_CCR_BP_Pos 18U /*!< SCB CCR: BP Position */ +#define SCB_CCR_BP_Msk (1UL << SCB_CCR_BP_Pos) /*!< SCB CCR: BP Mask */ + +#define SCB_CCR_IC_Pos 17U /*!< SCB CCR: IC Position */ +#define SCB_CCR_IC_Msk (1UL << SCB_CCR_IC_Pos) /*!< SCB CCR: IC Mask */ + +#define SCB_CCR_DC_Pos 16U /*!< SCB CCR: DC Position */ +#define SCB_CCR_DC_Msk (1UL << SCB_CCR_DC_Pos) /*!< SCB CCR: DC Mask */ + +#define SCB_CCR_STKOFHFNMIGN_Pos 10U /*!< SCB CCR: STKOFHFNMIGN Position */ +#define SCB_CCR_STKOFHFNMIGN_Msk (1UL << SCB_CCR_STKOFHFNMIGN_Pos) /*!< SCB CCR: STKOFHFNMIGN Mask */ + +#define SCB_CCR_BFHFNMIGN_Pos 8U /*!< SCB CCR: BFHFNMIGN Position */ +#define SCB_CCR_BFHFNMIGN_Msk (1UL << SCB_CCR_BFHFNMIGN_Pos) /*!< SCB CCR: BFHFNMIGN Mask */ + +#define SCB_CCR_DIV_0_TRP_Pos 4U /*!< SCB CCR: DIV_0_TRP Position */ +#define SCB_CCR_DIV_0_TRP_Msk (1UL << SCB_CCR_DIV_0_TRP_Pos) /*!< SCB CCR: DIV_0_TRP Mask */ + +#define SCB_CCR_UNALIGN_TRP_Pos 3U /*!< SCB CCR: UNALIGN_TRP Position */ +#define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */ + +#define SCB_CCR_USERSETMPEND_Pos 1U /*!< SCB CCR: USERSETMPEND Position */ +#define SCB_CCR_USERSETMPEND_Msk (1UL << SCB_CCR_USERSETMPEND_Pos) /*!< SCB CCR: USERSETMPEND Mask */ + +/* SCB System Handler Control and State Register Definitions */ +#define SCB_SHCSR_HARDFAULTPENDED_Pos 21U /*!< SCB SHCSR: HARDFAULTPENDED Position */ +#define SCB_SHCSR_HARDFAULTPENDED_Msk (1UL << SCB_SHCSR_HARDFAULTPENDED_Pos) /*!< SCB SHCSR: HARDFAULTPENDED Mask */ + +#define SCB_SHCSR_SECUREFAULTPENDED_Pos 20U /*!< SCB SHCSR: SECUREFAULTPENDED Position */ +#define SCB_SHCSR_SECUREFAULTPENDED_Msk (1UL << SCB_SHCSR_SECUREFAULTPENDED_Pos) /*!< SCB SHCSR: SECUREFAULTPENDED Mask */ + +#define SCB_SHCSR_SECUREFAULTENA_Pos 19U /*!< SCB SHCSR: SECUREFAULTENA Position */ +#define SCB_SHCSR_SECUREFAULTENA_Msk (1UL << SCB_SHCSR_SECUREFAULTENA_Pos) /*!< SCB SHCSR: SECUREFAULTENA Mask */ + +#define SCB_SHCSR_USGFAULTENA_Pos 18U /*!< SCB SHCSR: USGFAULTENA Position */ +#define SCB_SHCSR_USGFAULTENA_Msk (1UL << SCB_SHCSR_USGFAULTENA_Pos) /*!< SCB SHCSR: USGFAULTENA Mask */ + +#define SCB_SHCSR_BUSFAULTENA_Pos 17U /*!< SCB SHCSR: BUSFAULTENA Position */ +#define SCB_SHCSR_BUSFAULTENA_Msk (1UL << SCB_SHCSR_BUSFAULTENA_Pos) /*!< SCB SHCSR: BUSFAULTENA Mask */ + +#define SCB_SHCSR_MEMFAULTENA_Pos 16U /*!< SCB SHCSR: MEMFAULTENA Position */ +#define SCB_SHCSR_MEMFAULTENA_Msk (1UL << SCB_SHCSR_MEMFAULTENA_Pos) /*!< SCB SHCSR: MEMFAULTENA Mask */ + +#define SCB_SHCSR_SVCALLPENDED_Pos 15U /*!< SCB SHCSR: SVCALLPENDED Position */ +#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */ + +#define SCB_SHCSR_BUSFAULTPENDED_Pos 14U /*!< SCB SHCSR: BUSFAULTPENDED Position */ +#define SCB_SHCSR_BUSFAULTPENDED_Msk (1UL << SCB_SHCSR_BUSFAULTPENDED_Pos) /*!< SCB SHCSR: BUSFAULTPENDED Mask */ + +#define SCB_SHCSR_MEMFAULTPENDED_Pos 13U /*!< SCB SHCSR: MEMFAULTPENDED Position */ +#define SCB_SHCSR_MEMFAULTPENDED_Msk (1UL << SCB_SHCSR_MEMFAULTPENDED_Pos) /*!< SCB SHCSR: MEMFAULTPENDED Mask */ + +#define SCB_SHCSR_USGFAULTPENDED_Pos 12U /*!< SCB SHCSR: USGFAULTPENDED Position */ +#define SCB_SHCSR_USGFAULTPENDED_Msk (1UL << SCB_SHCSR_USGFAULTPENDED_Pos) /*!< SCB SHCSR: USGFAULTPENDED Mask */ + +#define SCB_SHCSR_SYSTICKACT_Pos 11U /*!< SCB SHCSR: SYSTICKACT Position */ +#define SCB_SHCSR_SYSTICKACT_Msk (1UL << SCB_SHCSR_SYSTICKACT_Pos) /*!< SCB SHCSR: SYSTICKACT Mask */ + +#define SCB_SHCSR_PENDSVACT_Pos 10U /*!< SCB SHCSR: PENDSVACT Position */ +#define SCB_SHCSR_PENDSVACT_Msk (1UL << SCB_SHCSR_PENDSVACT_Pos) /*!< SCB SHCSR: PENDSVACT Mask */ + +#define SCB_SHCSR_MONITORACT_Pos 8U /*!< SCB SHCSR: MONITORACT Position */ +#define SCB_SHCSR_MONITORACT_Msk (1UL << SCB_SHCSR_MONITORACT_Pos) /*!< SCB SHCSR: MONITORACT Mask */ + +#define SCB_SHCSR_SVCALLACT_Pos 7U /*!< SCB SHCSR: SVCALLACT Position */ +#define SCB_SHCSR_SVCALLACT_Msk (1UL << SCB_SHCSR_SVCALLACT_Pos) /*!< SCB SHCSR: SVCALLACT Mask */ + +#define SCB_SHCSR_NMIACT_Pos 5U /*!< SCB SHCSR: NMIACT Position */ +#define SCB_SHCSR_NMIACT_Msk (1UL << SCB_SHCSR_NMIACT_Pos) /*!< SCB SHCSR: NMIACT Mask */ + +#define SCB_SHCSR_SECUREFAULTACT_Pos 4U /*!< SCB SHCSR: SECUREFAULTACT Position */ +#define SCB_SHCSR_SECUREFAULTACT_Msk (1UL << SCB_SHCSR_SECUREFAULTACT_Pos) /*!< SCB SHCSR: SECUREFAULTACT Mask */ + +#define SCB_SHCSR_USGFAULTACT_Pos 3U /*!< SCB SHCSR: USGFAULTACT Position */ +#define SCB_SHCSR_USGFAULTACT_Msk (1UL << SCB_SHCSR_USGFAULTACT_Pos) /*!< SCB SHCSR: USGFAULTACT Mask */ + +#define SCB_SHCSR_HARDFAULTACT_Pos 2U /*!< SCB SHCSR: HARDFAULTACT Position */ +#define SCB_SHCSR_HARDFAULTACT_Msk (1UL << SCB_SHCSR_HARDFAULTACT_Pos) /*!< SCB SHCSR: HARDFAULTACT Mask */ + +#define SCB_SHCSR_BUSFAULTACT_Pos 1U /*!< SCB SHCSR: BUSFAULTACT Position */ +#define SCB_SHCSR_BUSFAULTACT_Msk (1UL << SCB_SHCSR_BUSFAULTACT_Pos) /*!< SCB SHCSR: BUSFAULTACT Mask */ + +#define SCB_SHCSR_MEMFAULTACT_Pos 0U /*!< SCB SHCSR: MEMFAULTACT Position */ +#define SCB_SHCSR_MEMFAULTACT_Msk (1UL /*<< SCB_SHCSR_MEMFAULTACT_Pos*/) /*!< SCB SHCSR: MEMFAULTACT Mask */ + +/* SCB Configurable Fault Status Register Definitions */ +#define SCB_CFSR_USGFAULTSR_Pos 16U /*!< SCB CFSR: Usage Fault Status Register Position */ +#define SCB_CFSR_USGFAULTSR_Msk (0xFFFFUL << SCB_CFSR_USGFAULTSR_Pos) /*!< SCB CFSR: Usage Fault Status Register Mask */ + +#define SCB_CFSR_BUSFAULTSR_Pos 8U /*!< SCB CFSR: Bus Fault Status Register Position */ +#define SCB_CFSR_BUSFAULTSR_Msk (0xFFUL << SCB_CFSR_BUSFAULTSR_Pos) /*!< SCB CFSR: Bus Fault Status Register Mask */ + +#define SCB_CFSR_MEMFAULTSR_Pos 0U /*!< SCB CFSR: Memory Manage Fault Status Register Position */ +#define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */ + +/* MemManage Fault Status Register (part of SCB Configurable Fault Status Register) */ +#define SCB_CFSR_MMARVALID_Pos (SCB_CFSR_MEMFAULTSR_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */ +#define SCB_CFSR_MMARVALID_Msk (1UL << SCB_CFSR_MMARVALID_Pos) /*!< SCB CFSR (MMFSR): MMARVALID Mask */ + +#define SCB_CFSR_MLSPERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 5U) /*!< SCB CFSR (MMFSR): MLSPERR Position */ +#define SCB_CFSR_MLSPERR_Msk (1UL << SCB_CFSR_MLSPERR_Pos) /*!< SCB CFSR (MMFSR): MLSPERR Mask */ + +#define SCB_CFSR_MSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */ +#define SCB_CFSR_MSTKERR_Msk (1UL << SCB_CFSR_MSTKERR_Pos) /*!< SCB CFSR (MMFSR): MSTKERR Mask */ + +#define SCB_CFSR_MUNSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */ +#define SCB_CFSR_MUNSTKERR_Msk (1UL << SCB_CFSR_MUNSTKERR_Pos) /*!< SCB CFSR (MMFSR): MUNSTKERR Mask */ + +#define SCB_CFSR_DACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */ +#define SCB_CFSR_DACCVIOL_Msk (1UL << SCB_CFSR_DACCVIOL_Pos) /*!< SCB CFSR (MMFSR): DACCVIOL Mask */ + +#define SCB_CFSR_IACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */ +#define SCB_CFSR_IACCVIOL_Msk (1UL /*<< SCB_CFSR_IACCVIOL_Pos*/) /*!< SCB CFSR (MMFSR): IACCVIOL Mask */ + +/* BusFault Status Register (part of SCB Configurable Fault Status Register) */ +#define SCB_CFSR_BFARVALID_Pos (SCB_CFSR_BUSFAULTSR_Pos + 7U) /*!< SCB CFSR (BFSR): BFARVALID Position */ +#define SCB_CFSR_BFARVALID_Msk (1UL << SCB_CFSR_BFARVALID_Pos) /*!< SCB CFSR (BFSR): BFARVALID Mask */ + +#define SCB_CFSR_LSPERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 5U) /*!< SCB CFSR (BFSR): LSPERR Position */ +#define SCB_CFSR_LSPERR_Msk (1UL << SCB_CFSR_LSPERR_Pos) /*!< SCB CFSR (BFSR): LSPERR Mask */ + +#define SCB_CFSR_STKERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 4U) /*!< SCB CFSR (BFSR): STKERR Position */ +#define SCB_CFSR_STKERR_Msk (1UL << SCB_CFSR_STKERR_Pos) /*!< SCB CFSR (BFSR): STKERR Mask */ + +#define SCB_CFSR_UNSTKERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 3U) /*!< SCB CFSR (BFSR): UNSTKERR Position */ +#define SCB_CFSR_UNSTKERR_Msk (1UL << SCB_CFSR_UNSTKERR_Pos) /*!< SCB CFSR (BFSR): UNSTKERR Mask */ + +#define SCB_CFSR_IMPRECISERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 2U) /*!< SCB CFSR (BFSR): IMPRECISERR Position */ +#define SCB_CFSR_IMPRECISERR_Msk (1UL << SCB_CFSR_IMPRECISERR_Pos) /*!< SCB CFSR (BFSR): IMPRECISERR Mask */ + +#define SCB_CFSR_PRECISERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 1U) /*!< SCB CFSR (BFSR): PRECISERR Position */ +#define SCB_CFSR_PRECISERR_Msk (1UL << SCB_CFSR_PRECISERR_Pos) /*!< SCB CFSR (BFSR): PRECISERR Mask */ + +#define SCB_CFSR_IBUSERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 0U) /*!< SCB CFSR (BFSR): IBUSERR Position */ +#define SCB_CFSR_IBUSERR_Msk (1UL << SCB_CFSR_IBUSERR_Pos) /*!< SCB CFSR (BFSR): IBUSERR Mask */ + +/* UsageFault Status Register (part of SCB Configurable Fault Status Register) */ +#define SCB_CFSR_DIVBYZERO_Pos (SCB_CFSR_USGFAULTSR_Pos + 9U) /*!< SCB CFSR (UFSR): DIVBYZERO Position */ +#define SCB_CFSR_DIVBYZERO_Msk (1UL << SCB_CFSR_DIVBYZERO_Pos) /*!< SCB CFSR (UFSR): DIVBYZERO Mask */ + +#define SCB_CFSR_UNALIGNED_Pos (SCB_CFSR_USGFAULTSR_Pos + 8U) /*!< SCB CFSR (UFSR): UNALIGNED Position */ +#define SCB_CFSR_UNALIGNED_Msk (1UL << SCB_CFSR_UNALIGNED_Pos) /*!< SCB CFSR (UFSR): UNALIGNED Mask */ + +#define SCB_CFSR_STKOF_Pos (SCB_CFSR_USGFAULTSR_Pos + 4U) /*!< SCB CFSR (UFSR): STKOF Position */ +#define SCB_CFSR_STKOF_Msk (1UL << SCB_CFSR_STKOF_Pos) /*!< SCB CFSR (UFSR): STKOF Mask */ + +#define SCB_CFSR_NOCP_Pos (SCB_CFSR_USGFAULTSR_Pos + 3U) /*!< SCB CFSR (UFSR): NOCP Position */ +#define SCB_CFSR_NOCP_Msk (1UL << SCB_CFSR_NOCP_Pos) /*!< SCB CFSR (UFSR): NOCP Mask */ + +#define SCB_CFSR_INVPC_Pos (SCB_CFSR_USGFAULTSR_Pos + 2U) /*!< SCB CFSR (UFSR): INVPC Position */ +#define SCB_CFSR_INVPC_Msk (1UL << SCB_CFSR_INVPC_Pos) /*!< SCB CFSR (UFSR): INVPC Mask */ + +#define SCB_CFSR_INVSTATE_Pos (SCB_CFSR_USGFAULTSR_Pos + 1U) /*!< SCB CFSR (UFSR): INVSTATE Position */ +#define SCB_CFSR_INVSTATE_Msk (1UL << SCB_CFSR_INVSTATE_Pos) /*!< SCB CFSR (UFSR): INVSTATE Mask */ + +#define SCB_CFSR_UNDEFINSTR_Pos (SCB_CFSR_USGFAULTSR_Pos + 0U) /*!< SCB CFSR (UFSR): UNDEFINSTR Position */ +#define SCB_CFSR_UNDEFINSTR_Msk (1UL << SCB_CFSR_UNDEFINSTR_Pos) /*!< SCB CFSR (UFSR): UNDEFINSTR Mask */ + +/* SCB Hard Fault Status Register Definitions */ +#define SCB_HFSR_DEBUGEVT_Pos 31U /*!< SCB HFSR: DEBUGEVT Position */ +#define SCB_HFSR_DEBUGEVT_Msk (1UL << SCB_HFSR_DEBUGEVT_Pos) /*!< SCB HFSR: DEBUGEVT Mask */ + +#define SCB_HFSR_FORCED_Pos 30U /*!< SCB HFSR: FORCED Position */ +#define SCB_HFSR_FORCED_Msk (1UL << SCB_HFSR_FORCED_Pos) /*!< SCB HFSR: FORCED Mask */ + +#define SCB_HFSR_VECTTBL_Pos 1U /*!< SCB HFSR: VECTTBL Position */ +#define SCB_HFSR_VECTTBL_Msk (1UL << SCB_HFSR_VECTTBL_Pos) /*!< SCB HFSR: VECTTBL Mask */ + +/* SCB Debug Fault Status Register Definitions */ +#define SCB_DFSR_PMU_Pos 5U /*!< SCB DFSR: PMU Position */ +#define SCB_DFSR_PMU_Msk (1UL << SCB_DFSR_PMU_Pos) /*!< SCB DFSR: PMU Mask */ + +#define SCB_DFSR_EXTERNAL_Pos 4U /*!< SCB DFSR: EXTERNAL Position */ +#define SCB_DFSR_EXTERNAL_Msk (1UL << SCB_DFSR_EXTERNAL_Pos) /*!< SCB DFSR: EXTERNAL Mask */ + +#define SCB_DFSR_VCATCH_Pos 3U /*!< SCB DFSR: VCATCH Position */ +#define SCB_DFSR_VCATCH_Msk (1UL << SCB_DFSR_VCATCH_Pos) /*!< SCB DFSR: VCATCH Mask */ + +#define SCB_DFSR_DWTTRAP_Pos 2U /*!< SCB DFSR: DWTTRAP Position */ +#define SCB_DFSR_DWTTRAP_Msk (1UL << SCB_DFSR_DWTTRAP_Pos) /*!< SCB DFSR: DWTTRAP Mask */ + +#define SCB_DFSR_BKPT_Pos 1U /*!< SCB DFSR: BKPT Position */ +#define SCB_DFSR_BKPT_Msk (1UL << SCB_DFSR_BKPT_Pos) /*!< SCB DFSR: BKPT Mask */ + +#define SCB_DFSR_HALTED_Pos 0U /*!< SCB DFSR: HALTED Position */ +#define SCB_DFSR_HALTED_Msk (1UL /*<< SCB_DFSR_HALTED_Pos*/) /*!< SCB DFSR: HALTED Mask */ + +/* SCB Non-Secure Access Control Register Definitions */ +#define SCB_NSACR_CP11_Pos 11U /*!< SCB NSACR: CP11 Position */ +#define SCB_NSACR_CP11_Msk (1UL << SCB_NSACR_CP11_Pos) /*!< SCB NSACR: CP11 Mask */ + +#define SCB_NSACR_CP10_Pos 10U /*!< SCB NSACR: CP10 Position */ +#define SCB_NSACR_CP10_Msk (1UL << SCB_NSACR_CP10_Pos) /*!< SCB NSACR: CP10 Mask */ + +#define SCB_NSACR_CP7_Pos 7U /*!< SCB NSACR: CP7 Position */ +#define SCB_NSACR_CP7_Msk (1UL << SCB_NSACR_CP7_Pos) /*!< SCB NSACR: CP7 Mask */ + +#define SCB_NSACR_CP6_Pos 6U /*!< SCB NSACR: CP6 Position */ +#define SCB_NSACR_CP6_Msk (1UL << SCB_NSACR_CP6_Pos) /*!< SCB NSACR: CP6 Mask */ + +#define SCB_NSACR_CP5_Pos 5U /*!< SCB NSACR: CP5 Position */ +#define SCB_NSACR_CP5_Msk (1UL << SCB_NSACR_CP5_Pos) /*!< SCB NSACR: CP5 Mask */ + +#define SCB_NSACR_CP4_Pos 4U /*!< SCB NSACR: CP4 Position */ +#define SCB_NSACR_CP4_Msk (1UL << SCB_NSACR_CP4_Pos) /*!< SCB NSACR: CP4 Mask */ + +#define SCB_NSACR_CP3_Pos 3U /*!< SCB NSACR: CP3 Position */ +#define SCB_NSACR_CP3_Msk (1UL << SCB_NSACR_CP3_Pos) /*!< SCB NSACR: CP3 Mask */ + +#define SCB_NSACR_CP2_Pos 2U /*!< SCB NSACR: CP2 Position */ +#define SCB_NSACR_CP2_Msk (1UL << SCB_NSACR_CP2_Pos) /*!< SCB NSACR: CP2 Mask */ + +#define SCB_NSACR_CP1_Pos 1U /*!< SCB NSACR: CP1 Position */ +#define SCB_NSACR_CP1_Msk (1UL << SCB_NSACR_CP1_Pos) /*!< SCB NSACR: CP1 Mask */ + +#define SCB_NSACR_CP0_Pos 0U /*!< SCB NSACR: CP0 Position */ +#define SCB_NSACR_CP0_Msk (1UL /*<< SCB_NSACR_CP0_Pos*/) /*!< SCB NSACR: CP0 Mask */ + +/* SCB Debug Feature Register 0 Definitions */ +#define SCB_ID_DFR_UDE_Pos 28U /*!< SCB ID_DFR: UDE Position */ +#define SCB_ID_DFR_UDE_Msk (0xFUL << SCB_ID_DFR_UDE_Pos) /*!< SCB ID_DFR: UDE Mask */ + +#define SCB_ID_DFR_MProfDbg_Pos 20U /*!< SCB ID_DFR: MProfDbg Position */ +#define SCB_ID_DFR_MProfDbg_Msk (0xFUL << SCB_ID_DFR_MProfDbg_Pos) /*!< SCB ID_DFR: MProfDbg Mask */ + +/* SCB Cache Level ID Register Definitions */ +#define SCB_CLIDR_LOUU_Pos 27U /*!< SCB CLIDR: LoUU Position */ +#define SCB_CLIDR_LOUU_Msk (7UL << SCB_CLIDR_LOUU_Pos) /*!< SCB CLIDR: LoUU Mask */ + +#define SCB_CLIDR_LOC_Pos 24U /*!< SCB CLIDR: LoC Position */ +#define SCB_CLIDR_LOC_Msk (7UL << SCB_CLIDR_LOC_Pos) /*!< SCB CLIDR: LoC Mask */ + +/* SCB Cache Type Register Definitions */ +#define SCB_CTR_FORMAT_Pos 29U /*!< SCB CTR: Format Position */ +#define SCB_CTR_FORMAT_Msk (7UL << SCB_CTR_FORMAT_Pos) /*!< SCB CTR: Format Mask */ + +#define SCB_CTR_CWG_Pos 24U /*!< SCB CTR: CWG Position */ +#define SCB_CTR_CWG_Msk (0xFUL << SCB_CTR_CWG_Pos) /*!< SCB CTR: CWG Mask */ + +#define SCB_CTR_ERG_Pos 20U /*!< SCB CTR: ERG Position */ +#define SCB_CTR_ERG_Msk (0xFUL << SCB_CTR_ERG_Pos) /*!< SCB CTR: ERG Mask */ + +#define SCB_CTR_DMINLINE_Pos 16U /*!< SCB CTR: DminLine Position */ +#define SCB_CTR_DMINLINE_Msk (0xFUL << SCB_CTR_DMINLINE_Pos) /*!< SCB CTR: DminLine Mask */ + +#define SCB_CTR_IMINLINE_Pos 0U /*!< SCB CTR: ImInLine Position */ +#define SCB_CTR_IMINLINE_Msk (0xFUL /*<< SCB_CTR_IMINLINE_Pos*/) /*!< SCB CTR: ImInLine Mask */ + +/* SCB Cache Size ID Register Definitions */ +#define SCB_CCSIDR_WT_Pos 31U /*!< SCB CCSIDR: WT Position */ +#define SCB_CCSIDR_WT_Msk (1UL << SCB_CCSIDR_WT_Pos) /*!< SCB CCSIDR: WT Mask */ + +#define SCB_CCSIDR_WB_Pos 30U /*!< SCB CCSIDR: WB Position */ +#define SCB_CCSIDR_WB_Msk (1UL << SCB_CCSIDR_WB_Pos) /*!< SCB CCSIDR: WB Mask */ + +#define SCB_CCSIDR_RA_Pos 29U /*!< SCB CCSIDR: RA Position */ +#define SCB_CCSIDR_RA_Msk (1UL << SCB_CCSIDR_RA_Pos) /*!< SCB CCSIDR: RA Mask */ + +#define SCB_CCSIDR_WA_Pos 28U /*!< SCB CCSIDR: WA Position */ +#define SCB_CCSIDR_WA_Msk (1UL << SCB_CCSIDR_WA_Pos) /*!< SCB CCSIDR: WA Mask */ + +#define SCB_CCSIDR_NUMSETS_Pos 13U /*!< SCB CCSIDR: NumSets Position */ +#define SCB_CCSIDR_NUMSETS_Msk (0x7FFFUL << SCB_CCSIDR_NUMSETS_Pos) /*!< SCB CCSIDR: NumSets Mask */ + +#define SCB_CCSIDR_ASSOCIATIVITY_Pos 3U /*!< SCB CCSIDR: Associativity Position */ +#define SCB_CCSIDR_ASSOCIATIVITY_Msk (0x3FFUL << SCB_CCSIDR_ASSOCIATIVITY_Pos) /*!< SCB CCSIDR: Associativity Mask */ + +#define SCB_CCSIDR_LINESIZE_Pos 0U /*!< SCB CCSIDR: LineSize Position */ +#define SCB_CCSIDR_LINESIZE_Msk (7UL /*<< SCB_CCSIDR_LINESIZE_Pos*/) /*!< SCB CCSIDR: LineSize Mask */ + +/* SCB Cache Size Selection Register Definitions */ +#define SCB_CSSELR_LEVEL_Pos 1U /*!< SCB CSSELR: Level Position */ +#define SCB_CSSELR_LEVEL_Msk (7UL << SCB_CSSELR_LEVEL_Pos) /*!< SCB CSSELR: Level Mask */ + +#define SCB_CSSELR_IND_Pos 0U /*!< SCB CSSELR: InD Position */ +#define SCB_CSSELR_IND_Msk (1UL /*<< SCB_CSSELR_IND_Pos*/) /*!< SCB CSSELR: InD Mask */ + +/* SCB Software Triggered Interrupt Register Definitions */ +#define SCB_STIR_INTID_Pos 0U /*!< SCB STIR: INTID Position */ +#define SCB_STIR_INTID_Msk (0x1FFUL /*<< SCB_STIR_INTID_Pos*/) /*!< SCB STIR: INTID Mask */ + +/* SCB RAS Fault Status Register Definitions */ +#define SCB_RFSR_V_Pos 31U /*!< SCB RFSR: V Position */ +#define SCB_RFSR_V_Msk (1UL << SCB_RFSR_V_Pos) /*!< SCB RFSR: V Mask */ + +#define SCB_RFSR_IS_Pos 16U /*!< SCB RFSR: IS Position */ +#define SCB_RFSR_IS_Msk (0x7FFFUL << SCB_RFSR_IS_Pos) /*!< SCB RFSR: IS Mask */ + +#define SCB_RFSR_UET_Pos 0U /*!< SCB RFSR: UET Position */ +#define SCB_RFSR_UET_Msk (3UL /*<< SCB_RFSR_UET_Pos*/) /*!< SCB RFSR: UET Mask */ + +/* SCB D-Cache Invalidate by Set-way Register Definitions */ +#define SCB_DCISW_WAY_Pos 30U /*!< SCB DCISW: Way Position */ +#define SCB_DCISW_WAY_Msk (3UL << SCB_DCISW_WAY_Pos) /*!< SCB DCISW: Way Mask */ + +#define SCB_DCISW_SET_Pos 5U /*!< SCB DCISW: Set Position */ +#define SCB_DCISW_SET_Msk (0x1FFUL << SCB_DCISW_SET_Pos) /*!< SCB DCISW: Set Mask */ + +/* SCB D-Cache Clean by Set-way Register Definitions */ +#define SCB_DCCSW_WAY_Pos 30U /*!< SCB DCCSW: Way Position */ +#define SCB_DCCSW_WAY_Msk (3UL << SCB_DCCSW_WAY_Pos) /*!< SCB DCCSW: Way Mask */ + +#define SCB_DCCSW_SET_Pos 5U /*!< SCB DCCSW: Set Position */ +#define SCB_DCCSW_SET_Msk (0x1FFUL << SCB_DCCSW_SET_Pos) /*!< SCB DCCSW: Set Mask */ + +/* SCB D-Cache Clean and Invalidate by Set-way Register Definitions */ +#define SCB_DCCISW_WAY_Pos 30U /*!< SCB DCCISW: Way Position */ +#define SCB_DCCISW_WAY_Msk (3UL << SCB_DCCISW_WAY_Pos) /*!< SCB DCCISW: Way Mask */ + +#define SCB_DCCISW_SET_Pos 5U /*!< SCB DCCISW: Set Position */ +#define SCB_DCCISW_SET_Msk (0x1FFUL << SCB_DCCISW_SET_Pos) /*!< SCB DCCISW: Set Mask */ + +/*@} end of group CMSIS_SCB */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_ICB Implementation Control Block register (ICB) + \brief Type definitions for the Implementation Control Block Register + @{ + */ + +/** + \brief Structure type to access the Implementation Control Block (ICB). + */ +typedef struct +{ + uint32_t RESERVED0[1U]; + __IM uint32_t ICTR; /*!< Offset: 0x004 (R/ ) Interrupt Controller Type Register */ + __IOM uint32_t ACTLR; /*!< Offset: 0x008 (R/W) Auxiliary Control Register */ + __IOM uint32_t CPPWR; /*!< Offset: 0x00C (R/W) Coprocessor Power Control Register */ +} ICB_Type; + +/* Auxiliary Control Register Definitions */ +#define ICB_ACTLR_DISCRITAXIRUW_Pos 27U /*!< ACTLR: DISCRITAXIRUW Position */ +#define ICB_ACTLR_DISCRITAXIRUW_Msk (1UL << ICB_ACTLR_DISCRITAXIRUW_Pos) /*!< ACTLR: DISCRITAXIRUW Mask */ + +#define ICB_ACTLR_DISCRITAXIRUR_Pos 15U /*!< ACTLR: DISCRITAXIRUR Position */ +#define ICB_ACTLR_DISCRITAXIRUR_Msk (1UL << ICB_ACTLR_DISCRITAXIRUR_Pos) /*!< ACTLR: DISCRITAXIRUR Mask */ + +#define ICB_ACTLR_EVENTBUSEN_Pos 14U /*!< ACTLR: EVENTBUSEN Position */ +#define ICB_ACTLR_EVENTBUSEN_Msk (1UL << ICB_ACTLR_EVENTBUSEN_Pos) /*!< ACTLR: EVENTBUSEN Mask */ + +#define ICB_ACTLR_EVENTBUSEN_S_Pos 13U /*!< ACTLR: EVENTBUSEN_S Position */ +#define ICB_ACTLR_EVENTBUSEN_S_Msk (1UL << ICB_ACTLR_EVENTBUSEN_S_Pos) /*!< ACTLR: EVENTBUSEN_S Mask */ + +#define ICB_ACTLR_DISITMATBFLUSH_Pos 12U /*!< ACTLR: DISITMATBFLUSH Position */ +#define ICB_ACTLR_DISITMATBFLUSH_Msk (1UL << ICB_ACTLR_DISITMATBFLUSH_Pos) /*!< ACTLR: DISITMATBFLUSH Mask */ + +#define ICB_ACTLR_DISNWAMODE_Pos 11U /*!< ACTLR: DISNWAMODE Position */ +#define ICB_ACTLR_DISNWAMODE_Msk (1UL << ICB_ACTLR_DISNWAMODE_Pos) /*!< ACTLR: DISNWAMODE Mask */ + +#define ICB_ACTLR_FPEXCODIS_Pos 10U /*!< ACTLR: FPEXCODIS Position */ +#define ICB_ACTLR_FPEXCODIS_Msk (1UL << ICB_ACTLR_FPEXCODIS_Pos) /*!< ACTLR: FPEXCODIS Mask */ + +/* Interrupt Controller Type Register Definitions */ +#define ICB_ICTR_INTLINESNUM_Pos 0U /*!< ICTR: INTLINESNUM Position */ +#define ICB_ICTR_INTLINESNUM_Msk (0xFUL /*<< ICB_ICTR_INTLINESNUM_Pos*/) /*!< ICTR: INTLINESNUM Mask */ + +/*@} end of group CMSIS_ICB */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_SysTick System Tick Timer (SysTick) + \brief Type definitions for the System Timer Registers. + @{ + */ + +/** + \brief Structure type to access the System Timer (SysTick). + */ +typedef struct +{ + __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */ + __IOM uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */ + __IOM uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */ + __IM uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */ +} SysTick_Type; + +/* SysTick Control / Status Register Definitions */ +#define SysTick_CTRL_COUNTFLAG_Pos 16U /*!< SysTick CTRL: COUNTFLAG Position */ +#define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */ + +#define SysTick_CTRL_CLKSOURCE_Pos 2U /*!< SysTick CTRL: CLKSOURCE Position */ +#define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */ + +#define SysTick_CTRL_TICKINT_Pos 1U /*!< SysTick CTRL: TICKINT Position */ +#define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */ + +#define SysTick_CTRL_ENABLE_Pos 0U /*!< SysTick CTRL: ENABLE Position */ +#define SysTick_CTRL_ENABLE_Msk (1UL /*<< SysTick_CTRL_ENABLE_Pos*/) /*!< SysTick CTRL: ENABLE Mask */ + +/* SysTick Reload Register Definitions */ +#define SysTick_LOAD_RELOAD_Pos 0U /*!< SysTick LOAD: RELOAD Position */ +#define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL /*<< SysTick_LOAD_RELOAD_Pos*/) /*!< SysTick LOAD: RELOAD Mask */ + +/* SysTick Current Register Definitions */ +#define SysTick_VAL_CURRENT_Pos 0U /*!< SysTick VAL: CURRENT Position */ +#define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL /*<< SysTick_VAL_CURRENT_Pos*/) /*!< SysTick VAL: CURRENT Mask */ + +/* SysTick Calibration Register Definitions */ +#define SysTick_CALIB_NOREF_Pos 31U /*!< SysTick CALIB: NOREF Position */ +#define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */ + +#define SysTick_CALIB_SKEW_Pos 30U /*!< SysTick CALIB: SKEW Position */ +#define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */ + +#define SysTick_CALIB_TENMS_Pos 0U /*!< SysTick CALIB: TENMS Position */ +#define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL /*<< SysTick_CALIB_TENMS_Pos*/) /*!< SysTick CALIB: TENMS Mask */ + +/*@} end of group CMSIS_SysTick */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_ITM Instrumentation Trace Macrocell (ITM) + \brief Type definitions for the Instrumentation Trace Macrocell (ITM) + @{ + */ + +/** + \brief Structure type to access the Instrumentation Trace Macrocell Register (ITM). + */ +typedef struct +{ + __OM union + { + __OM uint8_t u8; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 8-bit */ + __OM uint16_t u16; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 16-bit */ + __OM uint32_t u32; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 32-bit */ + } PORT [32U]; /*!< Offset: 0x000 ( /W) ITM Stimulus Port Registers */ + uint32_t RESERVED0[864U]; + __IOM uint32_t TER; /*!< Offset: 0xE00 (R/W) ITM Trace Enable Register */ + uint32_t RESERVED1[15U]; + __IOM uint32_t TPR; /*!< Offset: 0xE40 (R/W) ITM Trace Privilege Register */ + uint32_t RESERVED2[15U]; + __IOM uint32_t TCR; /*!< Offset: 0xE80 (R/W) ITM Trace Control Register */ + uint32_t RESERVED3[32U]; + uint32_t RESERVED4[43U]; + __OM uint32_t LAR; /*!< Offset: 0xFB0 ( /W) ITM Lock Access Register */ + __IM uint32_t LSR; /*!< Offset: 0xFB4 (R/ ) ITM Lock Status Register */ + uint32_t RESERVED5[1U]; + __IM uint32_t DEVARCH; /*!< Offset: 0xFBC (R/ ) ITM Device Architecture Register */ + uint32_t RESERVED6[3U]; + __IM uint32_t DEVTYPE; /*!< Offset: 0xFCC (R/ ) ITM Device Type Register */ + __IM uint32_t PID4; /*!< Offset: 0xFD0 (R/ ) ITM Peripheral Identification Register #4 */ + __IM uint32_t PID5; /*!< Offset: 0xFD4 (R/ ) ITM Peripheral Identification Register #5 */ + __IM uint32_t PID6; /*!< Offset: 0xFD8 (R/ ) ITM Peripheral Identification Register #6 */ + __IM uint32_t PID7; /*!< Offset: 0xFDC (R/ ) ITM Peripheral Identification Register #7 */ + __IM uint32_t PID0; /*!< Offset: 0xFE0 (R/ ) ITM Peripheral Identification Register #0 */ + __IM uint32_t PID1; /*!< Offset: 0xFE4 (R/ ) ITM Peripheral Identification Register #1 */ + __IM uint32_t PID2; /*!< Offset: 0xFE8 (R/ ) ITM Peripheral Identification Register #2 */ + __IM uint32_t PID3; /*!< Offset: 0xFEC (R/ ) ITM Peripheral Identification Register #3 */ + __IM uint32_t CID0; /*!< Offset: 0xFF0 (R/ ) ITM Component Identification Register #0 */ + __IM uint32_t CID1; /*!< Offset: 0xFF4 (R/ ) ITM Component Identification Register #1 */ + __IM uint32_t CID2; /*!< Offset: 0xFF8 (R/ ) ITM Component Identification Register #2 */ + __IM uint32_t CID3; /*!< Offset: 0xFFC (R/ ) ITM Component Identification Register #3 */ +} ITM_Type; + +/* ITM Stimulus Port Register Definitions */ +#define ITM_STIM_DISABLED_Pos 1U /*!< ITM STIM: DISABLED Position */ +#define ITM_STIM_DISABLED_Msk (0x1UL << ITM_STIM_DISABLED_Pos) /*!< ITM STIM: DISABLED Mask */ + +#define ITM_STIM_FIFOREADY_Pos 0U /*!< ITM STIM: FIFOREADY Position */ +#define ITM_STIM_FIFOREADY_Msk (0x1UL /*<< ITM_STIM_FIFOREADY_Pos*/) /*!< ITM STIM: FIFOREADY Mask */ + +/* ITM Trace Privilege Register Definitions */ +#define ITM_TPR_PRIVMASK_Pos 0U /*!< ITM TPR: PRIVMASK Position */ +#define ITM_TPR_PRIVMASK_Msk (0xFUL /*<< ITM_TPR_PRIVMASK_Pos*/) /*!< ITM TPR: PRIVMASK Mask */ + +/* ITM Trace Control Register Definitions */ +#define ITM_TCR_BUSY_Pos 23U /*!< ITM TCR: BUSY Position */ +#define ITM_TCR_BUSY_Msk (1UL << ITM_TCR_BUSY_Pos) /*!< ITM TCR: BUSY Mask */ + +#define ITM_TCR_TRACEBUSID_Pos 16U /*!< ITM TCR: ATBID Position */ +#define ITM_TCR_TRACEBUSID_Msk (0x7FUL << ITM_TCR_TRACEBUSID_Pos) /*!< ITM TCR: ATBID Mask */ + +#define ITM_TCR_GTSFREQ_Pos 10U /*!< ITM TCR: Global timestamp frequency Position */ +#define ITM_TCR_GTSFREQ_Msk (3UL << ITM_TCR_GTSFREQ_Pos) /*!< ITM TCR: Global timestamp frequency Mask */ + +#define ITM_TCR_TSPRESCALE_Pos 8U /*!< ITM TCR: TSPRESCALE Position */ +#define ITM_TCR_TSPRESCALE_Msk (3UL << ITM_TCR_TSPRESCALE_Pos) /*!< ITM TCR: TSPRESCALE Mask */ + +#define ITM_TCR_STALLENA_Pos 5U /*!< ITM TCR: STALLENA Position */ +#define ITM_TCR_STALLENA_Msk (1UL << ITM_TCR_STALLENA_Pos) /*!< ITM TCR: STALLENA Mask */ + +#define ITM_TCR_SWOENA_Pos 4U /*!< ITM TCR: SWOENA Position */ +#define ITM_TCR_SWOENA_Msk (1UL << ITM_TCR_SWOENA_Pos) /*!< ITM TCR: SWOENA Mask */ + +#define ITM_TCR_DWTENA_Pos 3U /*!< ITM TCR: DWTENA Position */ +#define ITM_TCR_DWTENA_Msk (1UL << ITM_TCR_DWTENA_Pos) /*!< ITM TCR: DWTENA Mask */ + +#define ITM_TCR_SYNCENA_Pos 2U /*!< ITM TCR: SYNCENA Position */ +#define ITM_TCR_SYNCENA_Msk (1UL << ITM_TCR_SYNCENA_Pos) /*!< ITM TCR: SYNCENA Mask */ + +#define ITM_TCR_TSENA_Pos 1U /*!< ITM TCR: TSENA Position */ +#define ITM_TCR_TSENA_Msk (1UL << ITM_TCR_TSENA_Pos) /*!< ITM TCR: TSENA Mask */ + +#define ITM_TCR_ITMENA_Pos 0U /*!< ITM TCR: ITM Enable bit Position */ +#define ITM_TCR_ITMENA_Msk (1UL /*<< ITM_TCR_ITMENA_Pos*/) /*!< ITM TCR: ITM Enable bit Mask */ + +/* ITM Lock Status Register Definitions */ +#define ITM_LSR_ByteAcc_Pos 2U /*!< ITM LSR: ByteAcc Position */ +#define ITM_LSR_ByteAcc_Msk (1UL << ITM_LSR_ByteAcc_Pos) /*!< ITM LSR: ByteAcc Mask */ + +#define ITM_LSR_Access_Pos 1U /*!< ITM LSR: Access Position */ +#define ITM_LSR_Access_Msk (1UL << ITM_LSR_Access_Pos) /*!< ITM LSR: Access Mask */ + +#define ITM_LSR_Present_Pos 0U /*!< ITM LSR: Present Position */ +#define ITM_LSR_Present_Msk (1UL /*<< ITM_LSR_Present_Pos*/) /*!< ITM LSR: Present Mask */ + +/*@}*/ /* end of group CMSIS_ITM */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_DWT Data Watchpoint and Trace (DWT) + \brief Type definitions for the Data Watchpoint and Trace (DWT) + @{ + */ + +/** + \brief Structure type to access the Data Watchpoint and Trace Register (DWT). + */ +typedef struct +{ + __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control Register */ + __IOM uint32_t CYCCNT; /*!< Offset: 0x004 (R/W) Cycle Count Register */ + __IOM uint32_t CPICNT; /*!< Offset: 0x008 (R/W) CPI Count Register */ + __IOM uint32_t EXCCNT; /*!< Offset: 0x00C (R/W) Exception Overhead Count Register */ + __IOM uint32_t SLEEPCNT; /*!< Offset: 0x010 (R/W) Sleep Count Register */ + __IOM uint32_t LSUCNT; /*!< Offset: 0x014 (R/W) LSU Count Register */ + __IOM uint32_t FOLDCNT; /*!< Offset: 0x018 (R/W) Folded-instruction Count Register */ + __IM uint32_t PCSR; /*!< Offset: 0x01C (R/ ) Program Counter Sample Register */ + __IOM uint32_t COMP0; /*!< Offset: 0x020 (R/W) Comparator Register 0 */ + uint32_t RESERVED1[1U]; + __IOM uint32_t FUNCTION0; /*!< Offset: 0x028 (R/W) Function Register 0 */ + uint32_t RESERVED2[1U]; + __IOM uint32_t COMP1; /*!< Offset: 0x030 (R/W) Comparator Register 1 */ + uint32_t RESERVED3[1U]; + __IOM uint32_t FUNCTION1; /*!< Offset: 0x038 (R/W) Function Register 1 */ + uint32_t RESERVED4[1U]; + __IOM uint32_t COMP2; /*!< Offset: 0x040 (R/W) Comparator Register 2 */ + uint32_t RESERVED5[1U]; + __IOM uint32_t FUNCTION2; /*!< Offset: 0x048 (R/W) Function Register 2 */ + uint32_t RESERVED6[1U]; + __IOM uint32_t COMP3; /*!< Offset: 0x050 (R/W) Comparator Register 3 */ + uint32_t RESERVED7[1U]; + __IOM uint32_t FUNCTION3; /*!< Offset: 0x058 (R/W) Function Register 3 */ + uint32_t RESERVED8[1U]; + __IOM uint32_t COMP4; /*!< Offset: 0x060 (R/W) Comparator Register 4 */ + uint32_t RESERVED9[1U]; + __IOM uint32_t FUNCTION4; /*!< Offset: 0x068 (R/W) Function Register 4 */ + uint32_t RESERVED10[1U]; + __IOM uint32_t COMP5; /*!< Offset: 0x070 (R/W) Comparator Register 5 */ + uint32_t RESERVED11[1U]; + __IOM uint32_t FUNCTION5; /*!< Offset: 0x078 (R/W) Function Register 5 */ + uint32_t RESERVED12[1U]; + __IOM uint32_t COMP6; /*!< Offset: 0x080 (R/W) Comparator Register 6 */ + uint32_t RESERVED13[1U]; + __IOM uint32_t FUNCTION6; /*!< Offset: 0x088 (R/W) Function Register 6 */ + uint32_t RESERVED14[1U]; + __IOM uint32_t COMP7; /*!< Offset: 0x090 (R/W) Comparator Register 7 */ + uint32_t RESERVED15[1U]; + __IOM uint32_t FUNCTION7; /*!< Offset: 0x098 (R/W) Function Register 7 */ + uint32_t RESERVED16[1U]; + __IOM uint32_t COMP8; /*!< Offset: 0x0A0 (R/W) Comparator Register 8 */ + uint32_t RESERVED17[1U]; + __IOM uint32_t FUNCTION8; /*!< Offset: 0x0A8 (R/W) Function Register 8 */ + uint32_t RESERVED18[1U]; + __IOM uint32_t COMP9; /*!< Offset: 0x0B0 (R/W) Comparator Register 9 */ + uint32_t RESERVED19[1U]; + __IOM uint32_t FUNCTION9; /*!< Offset: 0x0B8 (R/W) Function Register 9 */ + uint32_t RESERVED20[1U]; + __IOM uint32_t COMP10; /*!< Offset: 0x0C0 (R/W) Comparator Register 10 */ + uint32_t RESERVED21[1U]; + __IOM uint32_t FUNCTION10; /*!< Offset: 0x0C8 (R/W) Function Register 10 */ + uint32_t RESERVED22[1U]; + __IOM uint32_t COMP11; /*!< Offset: 0x0D0 (R/W) Comparator Register 11 */ + uint32_t RESERVED23[1U]; + __IOM uint32_t FUNCTION11; /*!< Offset: 0x0D8 (R/W) Function Register 11 */ + uint32_t RESERVED24[1U]; + __IOM uint32_t COMP12; /*!< Offset: 0x0E0 (R/W) Comparator Register 12 */ + uint32_t RESERVED25[1U]; + __IOM uint32_t FUNCTION12; /*!< Offset: 0x0E8 (R/W) Function Register 12 */ + uint32_t RESERVED26[1U]; + __IOM uint32_t COMP13; /*!< Offset: 0x0F0 (R/W) Comparator Register 13 */ + uint32_t RESERVED27[1U]; + __IOM uint32_t FUNCTION13; /*!< Offset: 0x0F8 (R/W) Function Register 13 */ + uint32_t RESERVED28[1U]; + __IOM uint32_t COMP14; /*!< Offset: 0x100 (R/W) Comparator Register 14 */ + uint32_t RESERVED29[1U]; + __IOM uint32_t FUNCTION14; /*!< Offset: 0x108 (R/W) Function Register 14 */ + uint32_t RESERVED30[1U]; + __IOM uint32_t COMP15; /*!< Offset: 0x110 (R/W) Comparator Register 15 */ + uint32_t RESERVED31[1U]; + __IOM uint32_t FUNCTION15; /*!< Offset: 0x118 (R/W) Function Register 15 */ + uint32_t RESERVED32[934U]; + __IM uint32_t LSR; /*!< Offset: 0xFB4 (R ) Lock Status Register */ + uint32_t RESERVED33[1U]; + __IM uint32_t DEVARCH; /*!< Offset: 0xFBC (R/ ) Device Architecture Register */ +} DWT_Type; + +/* DWT Control Register Definitions */ +#define DWT_CTRL_NUMCOMP_Pos 28U /*!< DWT CTRL: NUMCOMP Position */ +#define DWT_CTRL_NUMCOMP_Msk (0xFUL << DWT_CTRL_NUMCOMP_Pos) /*!< DWT CTRL: NUMCOMP Mask */ + +#define DWT_CTRL_NOTRCPKT_Pos 27U /*!< DWT CTRL: NOTRCPKT Position */ +#define DWT_CTRL_NOTRCPKT_Msk (0x1UL << DWT_CTRL_NOTRCPKT_Pos) /*!< DWT CTRL: NOTRCPKT Mask */ + +#define DWT_CTRL_NOEXTTRIG_Pos 26U /*!< DWT CTRL: NOEXTTRIG Position */ +#define DWT_CTRL_NOEXTTRIG_Msk (0x1UL << DWT_CTRL_NOEXTTRIG_Pos) /*!< DWT CTRL: NOEXTTRIG Mask */ + +#define DWT_CTRL_NOCYCCNT_Pos 25U /*!< DWT CTRL: NOCYCCNT Position */ +#define DWT_CTRL_NOCYCCNT_Msk (0x1UL << DWT_CTRL_NOCYCCNT_Pos) /*!< DWT CTRL: NOCYCCNT Mask */ + +#define DWT_CTRL_NOPRFCNT_Pos 24U /*!< DWT CTRL: NOPRFCNT Position */ +#define DWT_CTRL_NOPRFCNT_Msk (0x1UL << DWT_CTRL_NOPRFCNT_Pos) /*!< DWT CTRL: NOPRFCNT Mask */ + +#define DWT_CTRL_CYCDISS_Pos 23U /*!< DWT CTRL: CYCDISS Position */ +#define DWT_CTRL_CYCDISS_Msk (0x1UL << DWT_CTRL_CYCDISS_Pos) /*!< DWT CTRL: CYCDISS Mask */ + +#define DWT_CTRL_CYCEVTENA_Pos 22U /*!< DWT CTRL: CYCEVTENA Position */ +#define DWT_CTRL_CYCEVTENA_Msk (0x1UL << DWT_CTRL_CYCEVTENA_Pos) /*!< DWT CTRL: CYCEVTENA Mask */ + +#define DWT_CTRL_FOLDEVTENA_Pos 21U /*!< DWT CTRL: FOLDEVTENA Position */ +#define DWT_CTRL_FOLDEVTENA_Msk (0x1UL << DWT_CTRL_FOLDEVTENA_Pos) /*!< DWT CTRL: FOLDEVTENA Mask */ + +#define DWT_CTRL_LSUEVTENA_Pos 20U /*!< DWT CTRL: LSUEVTENA Position */ +#define DWT_CTRL_LSUEVTENA_Msk (0x1UL << DWT_CTRL_LSUEVTENA_Pos) /*!< DWT CTRL: LSUEVTENA Mask */ + +#define DWT_CTRL_SLEEPEVTENA_Pos 19U /*!< DWT CTRL: SLEEPEVTENA Position */ +#define DWT_CTRL_SLEEPEVTENA_Msk (0x1UL << DWT_CTRL_SLEEPEVTENA_Pos) /*!< DWT CTRL: SLEEPEVTENA Mask */ + +#define DWT_CTRL_EXCEVTENA_Pos 18U /*!< DWT CTRL: EXCEVTENA Position */ +#define DWT_CTRL_EXCEVTENA_Msk (0x1UL << DWT_CTRL_EXCEVTENA_Pos) /*!< DWT CTRL: EXCEVTENA Mask */ + +#define DWT_CTRL_CPIEVTENA_Pos 17U /*!< DWT CTRL: CPIEVTENA Position */ +#define DWT_CTRL_CPIEVTENA_Msk (0x1UL << DWT_CTRL_CPIEVTENA_Pos) /*!< DWT CTRL: CPIEVTENA Mask */ + +#define DWT_CTRL_EXCTRCENA_Pos 16U /*!< DWT CTRL: EXCTRCENA Position */ +#define DWT_CTRL_EXCTRCENA_Msk (0x1UL << DWT_CTRL_EXCTRCENA_Pos) /*!< DWT CTRL: EXCTRCENA Mask */ + +#define DWT_CTRL_PCSAMPLENA_Pos 12U /*!< DWT CTRL: PCSAMPLENA Position */ +#define DWT_CTRL_PCSAMPLENA_Msk (0x1UL << DWT_CTRL_PCSAMPLENA_Pos) /*!< DWT CTRL: PCSAMPLENA Mask */ + +#define DWT_CTRL_SYNCTAP_Pos 10U /*!< DWT CTRL: SYNCTAP Position */ +#define DWT_CTRL_SYNCTAP_Msk (0x3UL << DWT_CTRL_SYNCTAP_Pos) /*!< DWT CTRL: SYNCTAP Mask */ + +#define DWT_CTRL_CYCTAP_Pos 9U /*!< DWT CTRL: CYCTAP Position */ +#define DWT_CTRL_CYCTAP_Msk (0x1UL << DWT_CTRL_CYCTAP_Pos) /*!< DWT CTRL: CYCTAP Mask */ + +#define DWT_CTRL_POSTINIT_Pos 5U /*!< DWT CTRL: POSTINIT Position */ +#define DWT_CTRL_POSTINIT_Msk (0xFUL << DWT_CTRL_POSTINIT_Pos) /*!< DWT CTRL: POSTINIT Mask */ + +#define DWT_CTRL_POSTPRESET_Pos 1U /*!< DWT CTRL: POSTPRESET Position */ +#define DWT_CTRL_POSTPRESET_Msk (0xFUL << DWT_CTRL_POSTPRESET_Pos) /*!< DWT CTRL: POSTPRESET Mask */ + +#define DWT_CTRL_CYCCNTENA_Pos 0U /*!< DWT CTRL: CYCCNTENA Position */ +#define DWT_CTRL_CYCCNTENA_Msk (0x1UL /*<< DWT_CTRL_CYCCNTENA_Pos*/) /*!< DWT CTRL: CYCCNTENA Mask */ + +/* DWT CPI Count Register Definitions */ +#define DWT_CPICNT_CPICNT_Pos 0U /*!< DWT CPICNT: CPICNT Position */ +#define DWT_CPICNT_CPICNT_Msk (0xFFUL /*<< DWT_CPICNT_CPICNT_Pos*/) /*!< DWT CPICNT: CPICNT Mask */ + +/* DWT Exception Overhead Count Register Definitions */ +#define DWT_EXCCNT_EXCCNT_Pos 0U /*!< DWT EXCCNT: EXCCNT Position */ +#define DWT_EXCCNT_EXCCNT_Msk (0xFFUL /*<< DWT_EXCCNT_EXCCNT_Pos*/) /*!< DWT EXCCNT: EXCCNT Mask */ + +/* DWT Sleep Count Register Definitions */ +#define DWT_SLEEPCNT_SLEEPCNT_Pos 0U /*!< DWT SLEEPCNT: SLEEPCNT Position */ +#define DWT_SLEEPCNT_SLEEPCNT_Msk (0xFFUL /*<< DWT_SLEEPCNT_SLEEPCNT_Pos*/) /*!< DWT SLEEPCNT: SLEEPCNT Mask */ + +/* DWT LSU Count Register Definitions */ +#define DWT_LSUCNT_LSUCNT_Pos 0U /*!< DWT LSUCNT: LSUCNT Position */ +#define DWT_LSUCNT_LSUCNT_Msk (0xFFUL /*<< DWT_LSUCNT_LSUCNT_Pos*/) /*!< DWT LSUCNT: LSUCNT Mask */ + +/* DWT Folded-instruction Count Register Definitions */ +#define DWT_FOLDCNT_FOLDCNT_Pos 0U /*!< DWT FOLDCNT: FOLDCNT Position */ +#define DWT_FOLDCNT_FOLDCNT_Msk (0xFFUL /*<< DWT_FOLDCNT_FOLDCNT_Pos*/) /*!< DWT FOLDCNT: FOLDCNT Mask */ + +/* DWT Comparator Function Register Definitions */ +#define DWT_FUNCTION_ID_Pos 27U /*!< DWT FUNCTION: ID Position */ +#define DWT_FUNCTION_ID_Msk (0x1FUL << DWT_FUNCTION_ID_Pos) /*!< DWT FUNCTION: ID Mask */ + +#define DWT_FUNCTION_MATCHED_Pos 24U /*!< DWT FUNCTION: MATCHED Position */ +#define DWT_FUNCTION_MATCHED_Msk (0x1UL << DWT_FUNCTION_MATCHED_Pos) /*!< DWT FUNCTION: MATCHED Mask */ + +#define DWT_FUNCTION_DATAVSIZE_Pos 10U /*!< DWT FUNCTION: DATAVSIZE Position */ +#define DWT_FUNCTION_DATAVSIZE_Msk (0x3UL << DWT_FUNCTION_DATAVSIZE_Pos) /*!< DWT FUNCTION: DATAVSIZE Mask */ + +#define DWT_FUNCTION_ACTION_Pos 4U /*!< DWT FUNCTION: ACTION Position */ +#define DWT_FUNCTION_ACTION_Msk (0x1UL << DWT_FUNCTION_ACTION_Pos) /*!< DWT FUNCTION: ACTION Mask */ + +#define DWT_FUNCTION_MATCH_Pos 0U /*!< DWT FUNCTION: MATCH Position */ +#define DWT_FUNCTION_MATCH_Msk (0xFUL /*<< DWT_FUNCTION_MATCH_Pos*/) /*!< DWT FUNCTION: MATCH Mask */ + +/*@}*/ /* end of group CMSIS_DWT */ + + +/** + \ingroup CMSIS_core_register + \defgroup MemSysCtl_Type Memory System Control Registers (IMPLEMENTATION DEFINED) + \brief Type definitions for the Memory System Control Registers (MEMSYSCTL) + @{ + */ + +/** + \brief Structure type to access the Memory System Control Registers (MEMSYSCTL). + */ +typedef struct +{ + __IOM uint32_t MSCR; /*!< Offset: 0x000 (R/W) Memory System Control Register */ + __IOM uint32_t PFCR; /*!< Offset: 0x004 (R/W) Prefetcher Control Register */ + uint32_t RESERVED1[2U]; + __IOM uint32_t ITCMCR; /*!< Offset: 0x010 (R/W) ITCM Control Register */ + __IOM uint32_t DTCMCR; /*!< Offset: 0x014 (R/W) DTCM Control Register */ + __IOM uint32_t PAHBCR; /*!< Offset: 0x018 (R/W) P-AHB Control Register */ + uint32_t RESERVED2[313U]; + __IOM uint32_t ITGU_CTRL; /*!< Offset: 0x500 (R/W) ITGU Control Register */ + __IOM uint32_t ITGU_CFG; /*!< Offset: 0x504 (R/W) ITGU Configuration Register */ + uint32_t RESERVED3[2U]; + __IOM uint32_t ITGU_LUT[16U]; /*!< Offset: 0x510 (R/W) ITGU Look Up Table Register */ + uint32_t RESERVED4[44U]; + __IOM uint32_t DTGU_CTRL; /*!< Offset: 0x600 (R/W) DTGU Control Registers */ + __IOM uint32_t DTGU_CFG; /*!< Offset: 0x604 (R/W) DTGU Configuration Register */ + uint32_t RESERVED5[2U]; + __IOM uint32_t DTGU_LUT[16U]; /*!< Offset: 0x610 (R/W) DTGU Look Up Table Register */ +} MemSysCtl_Type; + +/* MEMSYSCTL Memory System Control Register (MSCR) Register Definitions */ +#define MEMSYSCTL_MSCR_CPWRDN_Pos 17U /*!< MEMSYSCTL MSCR: CPWRDN Position */ +#define MEMSYSCTL_MSCR_CPWRDN_Msk (0x1UL << MEMSYSCTL_MSCR_CPWRDN_Pos) /*!< MEMSYSCTL MSCR: CPWRDN Mask */ + +#define MEMSYSCTL_MSCR_DCCLEAN_Pos 16U /*!< MEMSYSCTL MSCR: DCCLEAN Position */ +#define MEMSYSCTL_MSCR_DCCLEAN_Msk (0x1UL << MEMSYSCTL_MSCR_DCCLEAN_Pos) /*!< MEMSYSCTL MSCR: DCCLEAN Mask */ + +#define MEMSYSCTL_MSCR_ICACTIVE_Pos 13U /*!< MEMSYSCTL MSCR: ICACTIVE Position */ +#define MEMSYSCTL_MSCR_ICACTIVE_Msk (0x1UL << MEMSYSCTL_MSCR_ICACTIVE_Pos) /*!< MEMSYSCTL MSCR: ICACTIVE Mask */ + +#define MEMSYSCTL_MSCR_DCACTIVE_Pos 12U /*!< MEMSYSCTL MSCR: DCACTIVE Position */ +#define MEMSYSCTL_MSCR_DCACTIVE_Msk (0x1UL << MEMSYSCTL_MSCR_DCACTIVE_Pos) /*!< MEMSYSCTL MSCR: DCACTIVE Mask */ + +#define MEMSYSCTL_MSCR_EVECCFAULT_Pos 3U /*!< MEMSYSCTL MSCR: EVECCFAULT Position */ +#define MEMSYSCTL_MSCR_EVECCFAULT_Msk (0x1UL << MEMSYSCTL_MSCR_EVECCFAULT_Pos) /*!< MEMSYSCTL MSCR: EVECCFAULT Mask */ + +#define MEMSYSCTL_MSCR_FORCEWT_Pos 2U /*!< MEMSYSCTL MSCR: FORCEWT Position */ +#define MEMSYSCTL_MSCR_FORCEWT_Msk (0x1UL << MEMSYSCTL_MSCR_FORCEWT_Pos) /*!< MEMSYSCTL MSCR: FORCEWT Mask */ + +#define MEMSYSCTL_MSCR_ECCEN_Pos 1U /*!< MEMSYSCTL MSCR: ECCEN Position */ +#define MEMSYSCTL_MSCR_ECCEN_Msk (0x1UL << MEMSYSCTL_MSCR_ECCEN_Pos) /*!< MEMSYSCTL MSCR: ECCEN Mask */ + +/* MEMSYSCTL Prefetcher Control Register (PFCR) Register Definitions */ +#define MEMSYSCTL_PFCR_DIS_NLP_Pos 7U /*!< MEMSYSCTL PFCR: DIS_NLP Position */ +#define MEMSYSCTL_PFCR_DIS_NLP_Msk (0x1UL << MEMSYSCTL_PFCR_DIS_NLP_Pos) /*!< MEMSYSCTL PFCR: DIS_NLP Mask */ + +#define MEMSYSCTL_PFCR_ENABLE_Pos 0U /*!< MEMSYSCTL PFCR: ENABLE Position */ +#define MEMSYSCTL_PFCR_ENABLE_Msk (0x1UL /*<< MEMSYSCTL_PFCR_ENABLE_Pos*/) /*!< MEMSYSCTL PFCR: ENABLE Mask */ + +/* MEMSYSCTL ITCM Control Register (ITCMCR) Register Definitions */ +#define MEMSYSCTL_ITCMCR_SZ_Pos 3U /*!< MEMSYSCTL ITCMCR: SZ Position */ +#define MEMSYSCTL_ITCMCR_SZ_Msk (0xFUL << MEMSYSCTL_ITCMCR_SZ_Pos) /*!< MEMSYSCTL ITCMCR: SZ Mask */ + +#define MEMSYSCTL_ITCMCR_EN_Pos 0U /*!< MEMSYSCTL ITCMCR: EN Position */ +#define MEMSYSCTL_ITCMCR_EN_Msk (0x1UL /*<< MEMSYSCTL_ITCMCR_EN_Pos*/) /*!< MEMSYSCTL ITCMCR: EN Mask */ + +/* MEMSYSCTL DTCM Control Register (DTCMCR) Register Definitions */ +#define MEMSYSCTL_DTCMCR_SZ_Pos 3U /*!< MEMSYSCTL DTCMCR: SZ Position */ +#define MEMSYSCTL_DTCMCR_SZ_Msk (0xFUL << MEMSYSCTL_DTCMCR_SZ_Pos) /*!< MEMSYSCTL DTCMCR: SZ Mask */ + +#define MEMSYSCTL_DTCMCR_EN_Pos 0U /*!< MEMSYSCTL DTCMCR: EN Position */ +#define MEMSYSCTL_DTCMCR_EN_Msk (0x1UL /*<< MEMSYSCTL_DTCMCR_EN_Pos*/) /*!< MEMSYSCTL DTCMCR: EN Mask */ + +/* MEMSYSCTL P-AHB Control Register (PAHBCR) Register Definitions */ +#define MEMSYSCTL_PAHBCR_SZ_Pos 1U /*!< MEMSYSCTL PAHBCR: SZ Position */ +#define MEMSYSCTL_PAHBCR_SZ_Msk (0x7UL << MEMSYSCTL_PAHBCR_SZ_Pos) /*!< MEMSYSCTL PAHBCR: SZ Mask */ + +#define MEMSYSCTL_PAHBCR_EN_Pos 0U /*!< MEMSYSCTL PAHBCR: EN Position */ +#define MEMSYSCTL_PAHBCR_EN_Msk (0x1UL /*<< MEMSYSCTL_PAHBCR_EN_Pos*/) /*!< MEMSYSCTL PAHBCR: EN Mask */ + +/* MEMSYSCTL ITGU Control Register (ITGU_CTRL) Register Definitions */ +#define MEMSYSCTL_ITGU_CTRL_DEREN_Pos 1U /*!< MEMSYSCTL ITGU_CTRL: DEREN Position */ +#define MEMSYSCTL_ITGU_CTRL_DEREN_Msk (0x1UL << MEMSYSCTL_ITGU_CTRL_DEREN_Pos) /*!< MEMSYSCTL ITGU_CTRL: DEREN Mask */ + +#define MEMSYSCTL_ITGU_CTRL_DBFEN_Pos 0U /*!< MEMSYSCTL ITGU_CTRL: DBFEN Position */ +#define MEMSYSCTL_ITGU_CTRL_DBFEN_Msk (0x1UL /*<< MEMSYSCTL_ITGU_CTRL_DBFEN_Pos*/) /*!< MEMSYSCTL ITGU_CTRL: DBFEN Mask */ + +/* MEMSYSCTL ITGU Configuration Register (ITGU_CFG) Register Definitions */ +#define MEMSYSCTL_ITGU_CFG_PRESENT_Pos 31U /*!< MEMSYSCTL ITGU_CFG: PRESENT Position */ +#define MEMSYSCTL_ITGU_CFG_PRESENT_Msk (0x1UL << MEMSYSCTL_ITGU_CFG_PRESENT_Pos) /*!< MEMSYSCTL ITGU_CFG: PRESENT Mask */ + +#define MEMSYSCTL_ITGU_CFG_NUMBLKS_Pos 8U /*!< MEMSYSCTL ITGU_CFG: NUMBLKS Position */ +#define MEMSYSCTL_ITGU_CFG_NUMBLKS_Msk (0xFUL << MEMSYSCTL_ITGU_CFG_NUMBLKS_Pos) /*!< MEMSYSCTL ITGU_CFG: NUMBLKS Mask */ + +#define MEMSYSCTL_ITGU_CFG_BLKSZ_Pos 0U /*!< MEMSYSCTL ITGU_CFG: BLKSZ Position */ +#define MEMSYSCTL_ITGU_CFG_BLKSZ_Msk (0xFUL /*<< MEMSYSCTL_ITGU_CFG_BLKSZ_Pos*/) /*!< MEMSYSCTL ITGU_CFG: BLKSZ Mask */ + +/* MEMSYSCTL DTGU Control Registers (DTGU_CTRL) Register Definitions */ +#define MEMSYSCTL_DTGU_CTRL_DEREN_Pos 1U /*!< MEMSYSCTL DTGU_CTRL: DEREN Position */ +#define MEMSYSCTL_DTGU_CTRL_DEREN_Msk (0x1UL << MEMSYSCTL_DTGU_CTRL_DEREN_Pos) /*!< MEMSYSCTL DTGU_CTRL: DEREN Mask */ + +#define MEMSYSCTL_DTGU_CTRL_DBFEN_Pos 0U /*!< MEMSYSCTL DTGU_CTRL: DBFEN Position */ +#define MEMSYSCTL_DTGU_CTRL_DBFEN_Msk (0x1UL /*<< MEMSYSCTL_DTGU_CTRL_DBFEN_Pos*/) /*!< MEMSYSCTL DTGU_CTRL: DBFEN Mask */ + +/* MEMSYSCTL DTGU Configuration Register (DTGU_CFG) Register Definitions */ +#define MEMSYSCTL_DTGU_CFG_PRESENT_Pos 31U /*!< MEMSYSCTL DTGU_CFG: PRESENT Position */ +#define MEMSYSCTL_DTGU_CFG_PRESENT_Msk (0x1UL << MEMSYSCTL_DTGU_CFG_PRESENT_Pos) /*!< MEMSYSCTL DTGU_CFG: PRESENT Mask */ + +#define MEMSYSCTL_DTGU_CFG_NUMBLKS_Pos 8U /*!< MEMSYSCTL DTGU_CFG: NUMBLKS Position */ +#define MEMSYSCTL_DTGU_CFG_NUMBLKS_Msk (0xFUL << MEMSYSCTL_DTGU_CFG_NUMBLKS_Pos) /*!< MEMSYSCTL DTGU_CFG: NUMBLKS Mask */ + +#define MEMSYSCTL_DTGU_CFG_BLKSZ_Pos 0U /*!< MEMSYSCTL DTGU_CFG: BLKSZ Position */ +#define MEMSYSCTL_DTGU_CFG_BLKSZ_Msk (0xFUL /*<< MEMSYSCTL_DTGU_CFG_BLKSZ_Pos*/) /*!< MEMSYSCTL DTGU_CFG: BLKSZ Mask */ + + +/*@}*/ /* end of group MemSysCtl_Type */ + + +/** + \ingroup CMSIS_core_register + \defgroup PwrModCtl_Type Power Mode Control Registers + \brief Type definitions for the Power Mode Control Registers (PWRMODCTL) + @{ + */ + +/** + \brief Structure type to access the Power Mode Control Registers (PWRMODCTL). + */ +typedef struct +{ + __IOM uint32_t CPDLPSTATE; /*!< Offset: 0x000 (R/W) Core Power Domain Low Power State Register */ + __IOM uint32_t DPDLPSTATE; /*!< Offset: 0x004 (R/W) Debug Power Domain Low Power State Register */ +} PwrModCtl_Type; + +/* PWRMODCTL Core Power Domain Low Power State (CPDLPSTATE) Register Definitions */ +#define PWRMODCTL_CPDLPSTATE_RLPSTATE_Pos 8U /*!< PWRMODCTL CPDLPSTATE: RLPSTATE Position */ +#define PWRMODCTL_CPDLPSTATE_RLPSTATE_Msk (0x3UL << PWRMODCTL_CPDLPSTATE_RLPSTATE_Pos) /*!< PWRMODCTL CPDLPSTATE: RLPSTATE Mask */ + +#define PWRMODCTL_CPDLPSTATE_ELPSTATE_Pos 4U /*!< PWRMODCTL CPDLPSTATE: ELPSTATE Position */ +#define PWRMODCTL_CPDLPSTATE_ELPSTATE_Msk (0x3UL << PWRMODCTL_CPDLPSTATE_ELPSTATE_Pos) /*!< PWRMODCTL CPDLPSTATE: ELPSTATE Mask */ + +#define PWRMODCTL_CPDLPSTATE_CLPSTATE_Pos 0U /*!< PWRMODCTL CPDLPSTATE: CLPSTATE Position */ +#define PWRMODCTL_CPDLPSTATE_CLPSTATE_Msk (0x3UL /*<< PWRMODCTL_CPDLPSTATE_CLPSTATE_Pos*/) /*!< PWRMODCTL CPDLPSTATE: CLPSTATE Mask */ + +/* PWRMODCTL Debug Power Domain Low Power State (DPDLPSTATE) Register Definitions */ +#define PWRMODCTL_DPDLPSTATE_DLPSTATE_Pos 0U /*!< PWRMODCTL DPDLPSTATE: DLPSTATE Position */ +#define PWRMODCTL_DPDLPSTATE_DLPSTATE_Msk (0x3UL /*<< PWRMODCTL_DPDLPSTATE_DLPSTATE_Pos*/) /*!< PWRMODCTL DPDLPSTATE: DLPSTATE Mask */ + +/*@}*/ /* end of group PwrModCtl_Type */ + + +/** + \ingroup CMSIS_core_register + \defgroup EWIC_Type External Wakeup Interrupt Controller Registers + \brief Type definitions for the External Wakeup Interrupt Controller Registers (EWIC) + @{ + */ + +/** + \brief Structure type to access the External Wakeup Interrupt Controller Registers (EWIC). + */ +typedef struct +{ + __OM uint32_t EVENTSPR; /*!< Offset: 0x000 ( /W) Event Set Pending Register */ + uint32_t RESERVED0[31U]; + __IM uint32_t EVENTMASKA; /*!< Offset: 0x080 (R/W) Event Mask A Register */ + __IM uint32_t EVENTMASK[15]; /*!< Offset: 0x084 (R/W) Event Mask Register */ +} EWIC_Type; + +/* EWIC External Wakeup Interrupt Controller (EVENTSPR) Register Definitions */ +#define EWIC_EVENTSPR_EDBGREQ_Pos 2U /*!< EWIC EVENTSPR: EDBGREQ Position */ +#define EWIC_EVENTSPR_EDBGREQ_Msk (0x1UL << EWIC_EVENTSPR_EDBGREQ_Pos) /*!< EWIC EVENTSPR: EDBGREQ Mask */ + +#define EWIC_EVENTSPR_NMI_Pos 1U /*!< EWIC EVENTSPR: NMI Position */ +#define EWIC_EVENTSPR_NMI_Msk (0x1UL << EWIC_EVENTSPR_NMI_Pos) /*!< EWIC EVENTSPR: NMI Mask */ + +#define EWIC_EVENTSPR_EVENT_Pos 0U /*!< EWIC EVENTSPR: EVENT Position */ +#define EWIC_EVENTSPR_EVENT_Msk (0x1UL /*<< EWIC_EVENTSPR_EVENT_Pos*/) /*!< EWIC EVENTSPR: EVENT Mask */ + +/* EWIC External Wakeup Interrupt Controller (EVENTMASKA) Register Definitions */ +#define EWIC_EVENTMASKA_EDBGREQ_Pos 2U /*!< EWIC EVENTMASKA: EDBGREQ Position */ +#define EWIC_EVENTMASKA_EDBGREQ_Msk (0x1UL << EWIC_EVENTMASKA_EDBGREQ_Pos) /*!< EWIC EVENTMASKA: EDBGREQ Mask */ + +#define EWIC_EVENTMASKA_NMI_Pos 1U /*!< EWIC EVENTMASKA: NMI Position */ +#define EWIC_EVENTMASKA_NMI_Msk (0x1UL << EWIC_EVENTMASKA_NMI_Pos) /*!< EWIC EVENTMASKA: NMI Mask */ + +#define EWIC_EVENTMASKA_EVENT_Pos 0U /*!< EWIC EVENTMASKA: EVENT Position */ +#define EWIC_EVENTMASKA_EVENT_Msk (0x1UL /*<< EWIC_EVENTMASKA_EVENT_Pos*/) /*!< EWIC EVENTMASKA: EVENT Mask */ + +/* EWIC External Wakeup Interrupt Controller (EVENTMASK) Register Definitions */ +#define EWIC_EVENTMASK_IRQ_Pos 0U /*!< EWIC EVENTMASKA: IRQ Position */ +#define EWIC_EVENTMASK_IRQ_Msk (0xFFFFFFFFUL /*<< EWIC_EVENTMASKA_IRQ_Pos*/) /*!< EWIC EVENTMASKA: IRQ Mask */ + +/*@}*/ /* end of group EWIC_Type */ + + +/** + \ingroup CMSIS_core_register + \defgroup ErrBnk_Type Error Banking Registers (IMPLEMENTATION DEFINED) + \brief Type definitions for the Error Banking Registers (ERRBNK) + @{ + */ + +/** + \brief Structure type to access the Error Banking Registers (ERRBNK). + */ +typedef struct +{ + __IOM uint32_t IEBR0; /*!< Offset: 0x000 (R/W) Instruction Cache Error Bank Register 0 */ + __IOM uint32_t IEBR1; /*!< Offset: 0x004 (R/W) Instruction Cache Error Bank Register 1 */ + uint32_t RESERVED0[2U]; + __IOM uint32_t DEBR0; /*!< Offset: 0x010 (R/W) Data Cache Error Bank Register 0 */ + __IOM uint32_t DEBR1; /*!< Offset: 0x014 (R/W) Data Cache Error Bank Register 1 */ + uint32_t RESERVED1[2U]; + __IOM uint32_t TEBR0; /*!< Offset: 0x020 (R/W) TCM Error Bank Register 0 */ + uint32_t RESERVED2[1U]; + __IOM uint32_t TEBR1; /*!< Offset: 0x028 (R/W) TCM Error Bank Register 1 */ +} ErrBnk_Type; + +/* ERRBNK Instruction Cache Error Bank Register 0 (IEBR0) Register Definitions */ +#define ERRBNK_IEBR0_SWDEF_Pos 30U /*!< ERRBNK IEBR0: SWDEF Position */ +#define ERRBNK_IEBR0_SWDEF_Msk (0x3UL << ERRBNK_IEBR0_SWDEF_Pos) /*!< ERRBNK IEBR0: SWDEF Mask */ + +#define ERRBNK_IEBR0_BANK_Pos 16U /*!< ERRBNK IEBR0: BANK Position */ +#define ERRBNK_IEBR0_BANK_Msk (0x1UL << ERRBNK_IEBR0_BANK_Pos) /*!< ERRBNK IEBR0: BANK Mask */ + +#define ERRBNK_IEBR0_LOCATION_Pos 2U /*!< ERRBNK IEBR0: LOCATION Position */ +#define ERRBNK_IEBR0_LOCATION_Msk (0x3FFFUL << ERRBNK_IEBR0_LOCATION_Pos) /*!< ERRBNK IEBR0: LOCATION Mask */ + +#define ERRBNK_IEBR0_LOCKED_Pos 1U /*!< ERRBNK IEBR0: LOCKED Position */ +#define ERRBNK_IEBR0_LOCKED_Msk (0x1UL << ERRBNK_IEBR0_LOCKED_Pos) /*!< ERRBNK IEBR0: LOCKED Mask */ + +#define ERRBNK_IEBR0_VALID_Pos 0U /*!< ERRBNK IEBR0: VALID Position */ +#define ERRBNK_IEBR0_VALID_Msk (0x1UL << /*ERRBNK_IEBR0_VALID_Pos*/) /*!< ERRBNK IEBR0: VALID Mask */ + +/* ERRBNK Instruction Cache Error Bank Register 1 (IEBR1) Register Definitions */ +#define ERRBNK_IEBR1_SWDEF_Pos 30U /*!< ERRBNK IEBR1: SWDEF Position */ +#define ERRBNK_IEBR1_SWDEF_Msk (0x3UL << ERRBNK_IEBR1_SWDEF_Pos) /*!< ERRBNK IEBR1: SWDEF Mask */ + +#define ERRBNK_IEBR1_BANK_Pos 16U /*!< ERRBNK IEBR1: BANK Position */ +#define ERRBNK_IEBR1_BANK_Msk (0x1UL << ERRBNK_IEBR1_BANK_Pos) /*!< ERRBNK IEBR1: BANK Mask */ + +#define ERRBNK_IEBR1_LOCATION_Pos 2U /*!< ERRBNK IEBR1: LOCATION Position */ +#define ERRBNK_IEBR1_LOCATION_Msk (0x3FFFUL << ERRBNK_IEBR1_LOCATION_Pos) /*!< ERRBNK IEBR1: LOCATION Mask */ + +#define ERRBNK_IEBR1_LOCKED_Pos 1U /*!< ERRBNK IEBR1: LOCKED Position */ +#define ERRBNK_IEBR1_LOCKED_Msk (0x1UL << ERRBNK_IEBR1_LOCKED_Pos) /*!< ERRBNK IEBR1: LOCKED Mask */ + +#define ERRBNK_IEBR1_VALID_Pos 0U /*!< ERRBNK IEBR1: VALID Position */ +#define ERRBNK_IEBR1_VALID_Msk (0x1UL << /*ERRBNK_IEBR1_VALID_Pos*/) /*!< ERRBNK IEBR1: VALID Mask */ + +/* ERRBNK Data Cache Error Bank Register 0 (DEBR0) Register Definitions */ +#define ERRBNK_DEBR0_SWDEF_Pos 30U /*!< ERRBNK DEBR0: SWDEF Position */ +#define ERRBNK_DEBR0_SWDEF_Msk (0x3UL << ERRBNK_DEBR0_SWDEF_Pos) /*!< ERRBNK DEBR0: SWDEF Mask */ + +#define ERRBNK_DEBR0_TYPE_Pos 17U /*!< ERRBNK DEBR0: TYPE Position */ +#define ERRBNK_DEBR0_TYPE_Msk (0x1UL << ERRBNK_DEBR0_TYPE_Pos) /*!< ERRBNK DEBR0: TYPE Mask */ + +#define ERRBNK_DEBR0_BANK_Pos 16U /*!< ERRBNK DEBR0: BANK Position */ +#define ERRBNK_DEBR0_BANK_Msk (0x1UL << ERRBNK_DEBR0_BANK_Pos) /*!< ERRBNK DEBR0: BANK Mask */ + +#define ERRBNK_DEBR0_LOCATION_Pos 2U /*!< ERRBNK DEBR0: LOCATION Position */ +#define ERRBNK_DEBR0_LOCATION_Msk (0x3FFFUL << ERRBNK_DEBR0_LOCATION_Pos) /*!< ERRBNK DEBR0: LOCATION Mask */ + +#define ERRBNK_DEBR0_LOCKED_Pos 1U /*!< ERRBNK DEBR0: LOCKED Position */ +#define ERRBNK_DEBR0_LOCKED_Msk (0x1UL << ERRBNK_DEBR0_LOCKED_Pos) /*!< ERRBNK DEBR0: LOCKED Mask */ + +#define ERRBNK_DEBR0_VALID_Pos 0U /*!< ERRBNK DEBR0: VALID Position */ +#define ERRBNK_DEBR0_VALID_Msk (0x1UL << /*ERRBNK_DEBR0_VALID_Pos*/) /*!< ERRBNK DEBR0: VALID Mask */ + +/* ERRBNK Data Cache Error Bank Register 1 (DEBR1) Register Definitions */ +#define ERRBNK_DEBR1_SWDEF_Pos 30U /*!< ERRBNK DEBR1: SWDEF Position */ +#define ERRBNK_DEBR1_SWDEF_Msk (0x3UL << ERRBNK_DEBR1_SWDEF_Pos) /*!< ERRBNK DEBR1: SWDEF Mask */ + +#define ERRBNK_DEBR1_TYPE_Pos 17U /*!< ERRBNK DEBR1: TYPE Position */ +#define ERRBNK_DEBR1_TYPE_Msk (0x1UL << ERRBNK_DEBR1_TYPE_Pos) /*!< ERRBNK DEBR1: TYPE Mask */ + +#define ERRBNK_DEBR1_BANK_Pos 16U /*!< ERRBNK DEBR1: BANK Position */ +#define ERRBNK_DEBR1_BANK_Msk (0x1UL << ERRBNK_DEBR1_BANK_Pos) /*!< ERRBNK DEBR1: BANK Mask */ + +#define ERRBNK_DEBR1_LOCATION_Pos 2U /*!< ERRBNK DEBR1: LOCATION Position */ +#define ERRBNK_DEBR1_LOCATION_Msk (0x3FFFUL << ERRBNK_DEBR1_LOCATION_Pos) /*!< ERRBNK DEBR1: LOCATION Mask */ + +#define ERRBNK_DEBR1_LOCKED_Pos 1U /*!< ERRBNK DEBR1: LOCKED Position */ +#define ERRBNK_DEBR1_LOCKED_Msk (0x1UL << ERRBNK_DEBR1_LOCKED_Pos) /*!< ERRBNK DEBR1: LOCKED Mask */ + +#define ERRBNK_DEBR1_VALID_Pos 0U /*!< ERRBNK DEBR1: VALID Position */ +#define ERRBNK_DEBR1_VALID_Msk (0x1UL << /*ERRBNK_DEBR1_VALID_Pos*/) /*!< ERRBNK DEBR1: VALID Mask */ + +/* ERRBNK TCM Error Bank Register 0 (TEBR0) Register Definitions */ +#define ERRBNK_TEBR0_SWDEF_Pos 30U /*!< ERRBNK TEBR0: SWDEF Position */ +#define ERRBNK_TEBR0_SWDEF_Msk (0x3UL << ERRBNK_TEBR0_SWDEF_Pos) /*!< ERRBNK TEBR0: SWDEF Mask */ + +#define ERRBNK_TEBR0_POISON_Pos 28U /*!< ERRBNK TEBR0: POISON Position */ +#define ERRBNK_TEBR0_POISON_Msk (0x1UL << ERRBNK_TEBR0_POISON_Pos) /*!< ERRBNK TEBR0: POISON Mask */ + +#define ERRBNK_TEBR0_TYPE_Pos 27U /*!< ERRBNK TEBR0: TYPE Position */ +#define ERRBNK_TEBR0_TYPE_Msk (0x1UL << ERRBNK_TEBR0_TYPE_Pos) /*!< ERRBNK TEBR0: TYPE Mask */ + +#define ERRBNK_TEBR0_BANK_Pos 24U /*!< ERRBNK TEBR0: BANK Position */ +#define ERRBNK_TEBR0_BANK_Msk (0x3UL << ERRBNK_TEBR0_BANK_Pos) /*!< ERRBNK TEBR0: BANK Mask */ + +#define ERRBNK_TEBR0_LOCATION_Pos 2U /*!< ERRBNK TEBR0: LOCATION Position */ +#define ERRBNK_TEBR0_LOCATION_Msk (0x3FFFFFUL << ERRBNK_TEBR0_LOCATION_Pos) /*!< ERRBNK TEBR0: LOCATION Mask */ + +#define ERRBNK_TEBR0_LOCKED_Pos 1U /*!< ERRBNK TEBR0: LOCKED Position */ +#define ERRBNK_TEBR0_LOCKED_Msk (0x1UL << ERRBNK_TEBR0_LOCKED_Pos) /*!< ERRBNK TEBR0: LOCKED Mask */ + +#define ERRBNK_TEBR0_VALID_Pos 0U /*!< ERRBNK TEBR0: VALID Position */ +#define ERRBNK_TEBR0_VALID_Msk (0x1UL << /*ERRBNK_TEBR0_VALID_Pos*/) /*!< ERRBNK TEBR0: VALID Mask */ + +/* ERRBNK TCM Error Bank Register 1 (TEBR1) Register Definitions */ +#define ERRBNK_TEBR1_SWDEF_Pos 30U /*!< ERRBNK TEBR1: SWDEF Position */ +#define ERRBNK_TEBR1_SWDEF_Msk (0x3UL << ERRBNK_TEBR1_SWDEF_Pos) /*!< ERRBNK TEBR1: SWDEF Mask */ + +#define ERRBNK_TEBR1_POISON_Pos 28U /*!< ERRBNK TEBR1: POISON Position */ +#define ERRBNK_TEBR1_POISON_Msk (0x1UL << ERRBNK_TEBR1_POISON_Pos) /*!< ERRBNK TEBR1: POISON Mask */ + +#define ERRBNK_TEBR1_TYPE_Pos 27U /*!< ERRBNK TEBR1: TYPE Position */ +#define ERRBNK_TEBR1_TYPE_Msk (0x1UL << ERRBNK_TEBR1_TYPE_Pos) /*!< ERRBNK TEBR1: TYPE Mask */ + +#define ERRBNK_TEBR1_BANK_Pos 24U /*!< ERRBNK TEBR1: BANK Position */ +#define ERRBNK_TEBR1_BANK_Msk (0x3UL << ERRBNK_TEBR1_BANK_Pos) /*!< ERRBNK TEBR1: BANK Mask */ + +#define ERRBNK_TEBR1_LOCATION_Pos 2U /*!< ERRBNK TEBR1: LOCATION Position */ +#define ERRBNK_TEBR1_LOCATION_Msk (0x3FFFFFUL << ERRBNK_TEBR1_LOCATION_Pos) /*!< ERRBNK TEBR1: LOCATION Mask */ + +#define ERRBNK_TEBR1_LOCKED_Pos 1U /*!< ERRBNK TEBR1: LOCKED Position */ +#define ERRBNK_TEBR1_LOCKED_Msk (0x1UL << ERRBNK_TEBR1_LOCKED_Pos) /*!< ERRBNK TEBR1: LOCKED Mask */ + +#define ERRBNK_TEBR1_VALID_Pos 0U /*!< ERRBNK TEBR1: VALID Position */ +#define ERRBNK_TEBR1_VALID_Msk (0x1UL << /*ERRBNK_TEBR1_VALID_Pos*/) /*!< ERRBNK TEBR1: VALID Mask */ + +/*@}*/ /* end of group ErrBnk_Type */ + + +/** + \ingroup CMSIS_core_register + \defgroup PrcCfgInf_Type Processor Configuration Information Registers (IMPLEMENTATION DEFINED) + \brief Type definitions for the Processor Configuration Information Registerss (PRCCFGINF) + @{ + */ + +/** + \brief Structure type to access the Processor Configuration Information Registerss (PRCCFGINF). + */ +typedef struct +{ + __OM uint32_t CFGINFOSEL; /*!< Offset: 0x000 ( /W) Processor Configuration Information Selection Register */ + __IM uint32_t CFGINFORD; /*!< Offset: 0x004 (R/ ) Processor Configuration Information Read Data Register */ +} PrcCfgInf_Type; + +/* PRCCFGINF Processor Configuration Information Selection Register (CFGINFOSEL) Definitions */ + +/* PRCCFGINF Processor Configuration Information Read Data Register (CFGINFORD) Definitions */ + +/*@}*/ /* end of group PrcCfgInf_Type */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_TPI Trace Port Interface (TPI) + \brief Type definitions for the Trace Port Interface (TPI) + @{ + */ + +/** + \brief Structure type to access the Trace Port Interface Register (TPI). + */ +typedef struct +{ + __IM uint32_t SSPSR; /*!< Offset: 0x000 (R/ ) Supported Parallel Port Sizes Register */ + __IOM uint32_t CSPSR; /*!< Offset: 0x004 (R/W) Current Parallel Port Sizes Register */ + uint32_t RESERVED0[2U]; + __IOM uint32_t ACPR; /*!< Offset: 0x010 (R/W) Asynchronous Clock Prescaler Register */ + uint32_t RESERVED1[55U]; + __IOM uint32_t SPPR; /*!< Offset: 0x0F0 (R/W) Selected Pin Protocol Register */ + uint32_t RESERVED2[131U]; + __IM uint32_t FFSR; /*!< Offset: 0x300 (R/ ) Formatter and Flush Status Register */ + __IOM uint32_t FFCR; /*!< Offset: 0x304 (R/W) Formatter and Flush Control Register */ + __IOM uint32_t PSCR; /*!< Offset: 0x308 (R/W) Periodic Synchronization Control Register */ + uint32_t RESERVED3[809U]; + __OM uint32_t LAR; /*!< Offset: 0xFB0 ( /W) Software Lock Access Register */ + __IM uint32_t LSR; /*!< Offset: 0xFB4 (R/ ) Software Lock Status Register */ + uint32_t RESERVED4[4U]; + __IM uint32_t TYPE; /*!< Offset: 0xFC8 (R/ ) Device Identifier Register */ + __IM uint32_t DEVTYPE; /*!< Offset: 0xFCC (R/ ) Device Type Register */ +} TPI_Type; + +/* TPI Asynchronous Clock Prescaler Register Definitions */ +#define TPI_ACPR_SWOSCALER_Pos 0U /*!< TPI ACPR: SWOSCALER Position */ +#define TPI_ACPR_SWOSCALER_Msk (0xFFFFUL /*<< TPI_ACPR_SWOSCALER_Pos*/) /*!< TPI ACPR: SWOSCALER Mask */ + +/* TPI Selected Pin Protocol Register Definitions */ +#define TPI_SPPR_TXMODE_Pos 0U /*!< TPI SPPR: TXMODE Position */ +#define TPI_SPPR_TXMODE_Msk (0x3UL /*<< TPI_SPPR_TXMODE_Pos*/) /*!< TPI SPPR: TXMODE Mask */ + +/* TPI Formatter and Flush Status Register Definitions */ +#define TPI_FFSR_FtNonStop_Pos 3U /*!< TPI FFSR: FtNonStop Position */ +#define TPI_FFSR_FtNonStop_Msk (0x1UL << TPI_FFSR_FtNonStop_Pos) /*!< TPI FFSR: FtNonStop Mask */ + +#define TPI_FFSR_TCPresent_Pos 2U /*!< TPI FFSR: TCPresent Position */ +#define TPI_FFSR_TCPresent_Msk (0x1UL << TPI_FFSR_TCPresent_Pos) /*!< TPI FFSR: TCPresent Mask */ + +#define TPI_FFSR_FtStopped_Pos 1U /*!< TPI FFSR: FtStopped Position */ +#define TPI_FFSR_FtStopped_Msk (0x1UL << TPI_FFSR_FtStopped_Pos) /*!< TPI FFSR: FtStopped Mask */ + +#define TPI_FFSR_FlInProg_Pos 0U /*!< TPI FFSR: FlInProg Position */ +#define TPI_FFSR_FlInProg_Msk (0x1UL /*<< TPI_FFSR_FlInProg_Pos*/) /*!< TPI FFSR: FlInProg Mask */ + +/* TPI Formatter and Flush Control Register Definitions */ +#define TPI_FFCR_TrigIn_Pos 8U /*!< TPI FFCR: TrigIn Position */ +#define TPI_FFCR_TrigIn_Msk (0x1UL << TPI_FFCR_TrigIn_Pos) /*!< TPI FFCR: TrigIn Mask */ + +#define TPI_FFCR_FOnMan_Pos 6U /*!< TPI FFCR: FOnMan Position */ +#define TPI_FFCR_FOnMan_Msk (0x1UL << TPI_FFCR_FOnMan_Pos) /*!< TPI FFCR: FOnMan Mask */ + +#define TPI_FFCR_EnFmt_Pos 0U /*!< TPI FFCR: EnFmt Position */ +#define TPI_FFCR_EnFmt_Msk (0x3UL << /*TPI_FFCR_EnFmt_Pos*/) /*!< TPI FFCR: EnFmt Mask */ + +/* TPI Periodic Synchronization Control Register Definitions */ +#define TPI_PSCR_PSCount_Pos 0U /*!< TPI PSCR: PSCount Position */ +#define TPI_PSCR_PSCount_Msk (0x1FUL /*<< TPI_PSCR_PSCount_Pos*/) /*!< TPI PSCR: TPSCount Mask */ + +/* TPI Software Lock Status Register Definitions */ +#define TPI_LSR_nTT_Pos 1U /*!< TPI LSR: Not thirty-two bit. Position */ +#define TPI_LSR_nTT_Msk (0x1UL << TPI_LSR_nTT_Pos) /*!< TPI LSR: Not thirty-two bit. Mask */ + +#define TPI_LSR_SLK_Pos 1U /*!< TPI LSR: Software Lock status Position */ +#define TPI_LSR_SLK_Msk (0x1UL << TPI_LSR_SLK_Pos) /*!< TPI LSR: Software Lock status Mask */ + +#define TPI_LSR_SLI_Pos 0U /*!< TPI LSR: Software Lock implemented Position */ +#define TPI_LSR_SLI_Msk (0x1UL /*<< TPI_LSR_SLI_Pos*/) /*!< TPI LSR: Software Lock implemented Mask */ + +/* TPI DEVID Register Definitions */ +#define TPI_DEVID_NRZVALID_Pos 11U /*!< TPI DEVID: NRZVALID Position */ +#define TPI_DEVID_NRZVALID_Msk (0x1UL << TPI_DEVID_NRZVALID_Pos) /*!< TPI DEVID: NRZVALID Mask */ + +#define TPI_DEVID_MANCVALID_Pos 10U /*!< TPI DEVID: MANCVALID Position */ +#define TPI_DEVID_MANCVALID_Msk (0x1UL << TPI_DEVID_MANCVALID_Pos) /*!< TPI DEVID: MANCVALID Mask */ + +#define TPI_DEVID_PTINVALID_Pos 9U /*!< TPI DEVID: PTINVALID Position */ +#define TPI_DEVID_PTINVALID_Msk (0x1UL << TPI_DEVID_PTINVALID_Pos) /*!< TPI DEVID: PTINVALID Mask */ + +#define TPI_DEVID_FIFOSZ_Pos 6U /*!< TPI DEVID: FIFO depth Position */ +#define TPI_DEVID_FIFOSZ_Msk (0x7UL << TPI_DEVID_FIFOSZ_Pos) /*!< TPI DEVID: FIFO depth Mask */ + +/* TPI DEVTYPE Register Definitions */ +#define TPI_DEVTYPE_SubType_Pos 4U /*!< TPI DEVTYPE: SubType Position */ +#define TPI_DEVTYPE_SubType_Msk (0xFUL /*<< TPI_DEVTYPE_SubType_Pos*/) /*!< TPI DEVTYPE: SubType Mask */ + +#define TPI_DEVTYPE_MajorType_Pos 0U /*!< TPI DEVTYPE: MajorType Position */ +#define TPI_DEVTYPE_MajorType_Msk (0xFUL << TPI_DEVTYPE_MajorType_Pos) /*!< TPI DEVTYPE: MajorType Mask */ + +/*@}*/ /* end of group CMSIS_TPI */ + +#if defined (__PMU_PRESENT) && (__PMU_PRESENT == 1U) +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_PMU Performance Monitoring Unit (PMU) + \brief Type definitions for the Performance Monitoring Unit (PMU) + @{ + */ + +/** + \brief Structure type to access the Performance Monitoring Unit (PMU). + */ +typedef struct +{ + __IOM uint32_t EVCNTR[__PMU_NUM_EVENTCNT]; /*!< Offset: 0x0 (R/W) PMU Event Counter Registers */ +#if __PMU_NUM_EVENTCNT<31 + uint32_t RESERVED0[31U-__PMU_NUM_EVENTCNT]; +#endif + __IOM uint32_t CCNTR; /*!< Offset: 0x7C (R/W) PMU Cycle Counter Register */ + uint32_t RESERVED1[224]; + __IOM uint32_t EVTYPER[__PMU_NUM_EVENTCNT]; /*!< Offset: 0x400 (R/W) PMU Event Type and Filter Registers */ +#if __PMU_NUM_EVENTCNT<31 + uint32_t RESERVED2[31U-__PMU_NUM_EVENTCNT]; +#endif + __IOM uint32_t CCFILTR; /*!< Offset: 0x47C (R/W) PMU Cycle Counter Filter Register */ + uint32_t RESERVED3[480]; + __IOM uint32_t CNTENSET; /*!< Offset: 0xC00 (R/W) PMU Count Enable Set Register */ + uint32_t RESERVED4[7]; + __IOM uint32_t CNTENCLR; /*!< Offset: 0xC20 (R/W) PMU Count Enable Clear Register */ + uint32_t RESERVED5[7]; + __IOM uint32_t INTENSET; /*!< Offset: 0xC40 (R/W) PMU Interrupt Enable Set Register */ + uint32_t RESERVED6[7]; + __IOM uint32_t INTENCLR; /*!< Offset: 0xC60 (R/W) PMU Interrupt Enable Clear Register */ + uint32_t RESERVED7[7]; + __IOM uint32_t OVSCLR; /*!< Offset: 0xC80 (R/W) PMU Overflow Flag Status Clear Register */ + uint32_t RESERVED8[7]; + __IOM uint32_t SWINC; /*!< Offset: 0xCA0 (R/W) PMU Software Increment Register */ + uint32_t RESERVED9[7]; + __IOM uint32_t OVSSET; /*!< Offset: 0xCC0 (R/W) PMU Overflow Flag Status Set Register */ + uint32_t RESERVED10[79]; + __IOM uint32_t TYPE; /*!< Offset: 0xE00 (R/W) PMU Type Register */ + __IOM uint32_t CTRL; /*!< Offset: 0xE04 (R/W) PMU Control Register */ + uint32_t RESERVED11[108]; + __IOM uint32_t AUTHSTATUS; /*!< Offset: 0xFB8 (R/W) PMU Authentication Status Register */ + __IOM uint32_t DEVARCH; /*!< Offset: 0xFBC (R/W) PMU Device Architecture Register */ + uint32_t RESERVED12[3]; + __IOM uint32_t DEVTYPE; /*!< Offset: 0xFCC (R/W) PMU Device Type Register */ + __IOM uint32_t PIDR4; /*!< Offset: 0xFD0 (R/W) PMU Peripheral Identification Register 4 */ + uint32_t RESERVED13[3]; + __IOM uint32_t PIDR0; /*!< Offset: 0xFE0 (R/W) PMU Peripheral Identification Register 0 */ + __IOM uint32_t PIDR1; /*!< Offset: 0xFE4 (R/W) PMU Peripheral Identification Register 1 */ + __IOM uint32_t PIDR2; /*!< Offset: 0xFE8 (R/W) PMU Peripheral Identification Register 2 */ + __IOM uint32_t PIDR3; /*!< Offset: 0xFEC (R/W) PMU Peripheral Identification Register 3 */ + __IOM uint32_t CIDR0; /*!< Offset: 0xFF0 (R/W) PMU Component Identification Register 0 */ + __IOM uint32_t CIDR1; /*!< Offset: 0xFF4 (R/W) PMU Component Identification Register 1 */ + __IOM uint32_t CIDR2; /*!< Offset: 0xFF8 (R/W) PMU Component Identification Register 2 */ + __IOM uint32_t CIDR3; /*!< Offset: 0xFFC (R/W) PMU Component Identification Register 3 */ +} PMU_Type; + +/** \brief PMU Event Counter Registers (0-30) Definitions */ + +#define PMU_EVCNTR_CNT_Pos 0U /*!< PMU EVCNTR: Counter Position */ +#define PMU_EVCNTR_CNT_Msk (0xFFFFUL /*<< PMU_EVCNTRx_CNT_Pos*/) /*!< PMU EVCNTR: Counter Mask */ + +/** \brief PMU Event Type and Filter Registers (0-30) Definitions */ + +#define PMU_EVTYPER_EVENTTOCNT_Pos 0U /*!< PMU EVTYPER: Event to Count Position */ +#define PMU_EVTYPER_EVENTTOCNT_Msk (0xFFFFUL /*<< EVTYPERx_EVENTTOCNT_Pos*/) /*!< PMU EVTYPER: Event to Count Mask */ + +/** \brief PMU Count Enable Set Register Definitions */ + +#define PMU_CNTENSET_CNT0_ENABLE_Pos 0U /*!< PMU CNTENSET: Event Counter 0 Enable Set Position */ +#define PMU_CNTENSET_CNT0_ENABLE_Msk (1UL /*<< PMU_CNTENSET_CNT0_ENABLE_Pos*/) /*!< PMU CNTENSET: Event Counter 0 Enable Set Mask */ + +#define PMU_CNTENSET_CNT1_ENABLE_Pos 1U /*!< PMU CNTENSET: Event Counter 1 Enable Set Position */ +#define PMU_CNTENSET_CNT1_ENABLE_Msk (1UL << PMU_CNTENSET_CNT1_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 1 Enable Set Mask */ + +#define PMU_CNTENSET_CNT2_ENABLE_Pos 2U /*!< PMU CNTENSET: Event Counter 2 Enable Set Position */ +#define PMU_CNTENSET_CNT2_ENABLE_Msk (1UL << PMU_CNTENSET_CNT2_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 2 Enable Set Mask */ + +#define PMU_CNTENSET_CNT3_ENABLE_Pos 3U /*!< PMU CNTENSET: Event Counter 3 Enable Set Position */ +#define PMU_CNTENSET_CNT3_ENABLE_Msk (1UL << PMU_CNTENSET_CNT3_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 3 Enable Set Mask */ + +#define PMU_CNTENSET_CNT4_ENABLE_Pos 4U /*!< PMU CNTENSET: Event Counter 4 Enable Set Position */ +#define PMU_CNTENSET_CNT4_ENABLE_Msk (1UL << PMU_CNTENSET_CNT4_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 4 Enable Set Mask */ + +#define PMU_CNTENSET_CNT5_ENABLE_Pos 5U /*!< PMU CNTENSET: Event Counter 5 Enable Set Position */ +#define PMU_CNTENSET_CNT5_ENABLE_Msk (1UL << PMU_CNTENSET_CNT5_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 5 Enable Set Mask */ + +#define PMU_CNTENSET_CNT6_ENABLE_Pos 6U /*!< PMU CNTENSET: Event Counter 6 Enable Set Position */ +#define PMU_CNTENSET_CNT6_ENABLE_Msk (1UL << PMU_CNTENSET_CNT6_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 6 Enable Set Mask */ + +#define PMU_CNTENSET_CNT7_ENABLE_Pos 7U /*!< PMU CNTENSET: Event Counter 7 Enable Set Position */ +#define PMU_CNTENSET_CNT7_ENABLE_Msk (1UL << PMU_CNTENSET_CNT7_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 7 Enable Set Mask */ + +#define PMU_CNTENSET_CNT8_ENABLE_Pos 8U /*!< PMU CNTENSET: Event Counter 8 Enable Set Position */ +#define PMU_CNTENSET_CNT8_ENABLE_Msk (1UL << PMU_CNTENSET_CNT8_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 8 Enable Set Mask */ + +#define PMU_CNTENSET_CNT9_ENABLE_Pos 9U /*!< PMU CNTENSET: Event Counter 9 Enable Set Position */ +#define PMU_CNTENSET_CNT9_ENABLE_Msk (1UL << PMU_CNTENSET_CNT9_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 9 Enable Set Mask */ + +#define PMU_CNTENSET_CNT10_ENABLE_Pos 10U /*!< PMU CNTENSET: Event Counter 10 Enable Set Position */ +#define PMU_CNTENSET_CNT10_ENABLE_Msk (1UL << PMU_CNTENSET_CNT10_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 10 Enable Set Mask */ + +#define PMU_CNTENSET_CNT11_ENABLE_Pos 11U /*!< PMU CNTENSET: Event Counter 11 Enable Set Position */ +#define PMU_CNTENSET_CNT11_ENABLE_Msk (1UL << PMU_CNTENSET_CNT11_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 11 Enable Set Mask */ + +#define PMU_CNTENSET_CNT12_ENABLE_Pos 12U /*!< PMU CNTENSET: Event Counter 12 Enable Set Position */ +#define PMU_CNTENSET_CNT12_ENABLE_Msk (1UL << PMU_CNTENSET_CNT12_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 12 Enable Set Mask */ + +#define PMU_CNTENSET_CNT13_ENABLE_Pos 13U /*!< PMU CNTENSET: Event Counter 13 Enable Set Position */ +#define PMU_CNTENSET_CNT13_ENABLE_Msk (1UL << PMU_CNTENSET_CNT13_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 13 Enable Set Mask */ + +#define PMU_CNTENSET_CNT14_ENABLE_Pos 14U /*!< PMU CNTENSET: Event Counter 14 Enable Set Position */ +#define PMU_CNTENSET_CNT14_ENABLE_Msk (1UL << PMU_CNTENSET_CNT14_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 14 Enable Set Mask */ + +#define PMU_CNTENSET_CNT15_ENABLE_Pos 15U /*!< PMU CNTENSET: Event Counter 15 Enable Set Position */ +#define PMU_CNTENSET_CNT15_ENABLE_Msk (1UL << PMU_CNTENSET_CNT15_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 15 Enable Set Mask */ + +#define PMU_CNTENSET_CNT16_ENABLE_Pos 16U /*!< PMU CNTENSET: Event Counter 16 Enable Set Position */ +#define PMU_CNTENSET_CNT16_ENABLE_Msk (1UL << PMU_CNTENSET_CNT16_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 16 Enable Set Mask */ + +#define PMU_CNTENSET_CNT17_ENABLE_Pos 17U /*!< PMU CNTENSET: Event Counter 17 Enable Set Position */ +#define PMU_CNTENSET_CNT17_ENABLE_Msk (1UL << PMU_CNTENSET_CNT17_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 17 Enable Set Mask */ + +#define PMU_CNTENSET_CNT18_ENABLE_Pos 18U /*!< PMU CNTENSET: Event Counter 18 Enable Set Position */ +#define PMU_CNTENSET_CNT18_ENABLE_Msk (1UL << PMU_CNTENSET_CNT18_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 18 Enable Set Mask */ + +#define PMU_CNTENSET_CNT19_ENABLE_Pos 19U /*!< PMU CNTENSET: Event Counter 19 Enable Set Position */ +#define PMU_CNTENSET_CNT19_ENABLE_Msk (1UL << PMU_CNTENSET_CNT19_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 19 Enable Set Mask */ + +#define PMU_CNTENSET_CNT20_ENABLE_Pos 20U /*!< PMU CNTENSET: Event Counter 20 Enable Set Position */ +#define PMU_CNTENSET_CNT20_ENABLE_Msk (1UL << PMU_CNTENSET_CNT20_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 20 Enable Set Mask */ + +#define PMU_CNTENSET_CNT21_ENABLE_Pos 21U /*!< PMU CNTENSET: Event Counter 21 Enable Set Position */ +#define PMU_CNTENSET_CNT21_ENABLE_Msk (1UL << PMU_CNTENSET_CNT21_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 21 Enable Set Mask */ + +#define PMU_CNTENSET_CNT22_ENABLE_Pos 22U /*!< PMU CNTENSET: Event Counter 22 Enable Set Position */ +#define PMU_CNTENSET_CNT22_ENABLE_Msk (1UL << PMU_CNTENSET_CNT22_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 22 Enable Set Mask */ + +#define PMU_CNTENSET_CNT23_ENABLE_Pos 23U /*!< PMU CNTENSET: Event Counter 23 Enable Set Position */ +#define PMU_CNTENSET_CNT23_ENABLE_Msk (1UL << PMU_CNTENSET_CNT23_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 23 Enable Set Mask */ + +#define PMU_CNTENSET_CNT24_ENABLE_Pos 24U /*!< PMU CNTENSET: Event Counter 24 Enable Set Position */ +#define PMU_CNTENSET_CNT24_ENABLE_Msk (1UL << PMU_CNTENSET_CNT24_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 24 Enable Set Mask */ + +#define PMU_CNTENSET_CNT25_ENABLE_Pos 25U /*!< PMU CNTENSET: Event Counter 25 Enable Set Position */ +#define PMU_CNTENSET_CNT25_ENABLE_Msk (1UL << PMU_CNTENSET_CNT25_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 25 Enable Set Mask */ + +#define PMU_CNTENSET_CNT26_ENABLE_Pos 26U /*!< PMU CNTENSET: Event Counter 26 Enable Set Position */ +#define PMU_CNTENSET_CNT26_ENABLE_Msk (1UL << PMU_CNTENSET_CNT26_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 26 Enable Set Mask */ + +#define PMU_CNTENSET_CNT27_ENABLE_Pos 27U /*!< PMU CNTENSET: Event Counter 27 Enable Set Position */ +#define PMU_CNTENSET_CNT27_ENABLE_Msk (1UL << PMU_CNTENSET_CNT27_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 27 Enable Set Mask */ + +#define PMU_CNTENSET_CNT28_ENABLE_Pos 28U /*!< PMU CNTENSET: Event Counter 28 Enable Set Position */ +#define PMU_CNTENSET_CNT28_ENABLE_Msk (1UL << PMU_CNTENSET_CNT28_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 28 Enable Set Mask */ + +#define PMU_CNTENSET_CNT29_ENABLE_Pos 29U /*!< PMU CNTENSET: Event Counter 29 Enable Set Position */ +#define PMU_CNTENSET_CNT29_ENABLE_Msk (1UL << PMU_CNTENSET_CNT29_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 29 Enable Set Mask */ + +#define PMU_CNTENSET_CNT30_ENABLE_Pos 30U /*!< PMU CNTENSET: Event Counter 30 Enable Set Position */ +#define PMU_CNTENSET_CNT30_ENABLE_Msk (1UL << PMU_CNTENSET_CNT30_ENABLE_Pos) /*!< PMU CNTENSET: Event Counter 30 Enable Set Mask */ + +#define PMU_CNTENSET_CCNTR_ENABLE_Pos 31U /*!< PMU CNTENSET: Cycle Counter Enable Set Position */ +#define PMU_CNTENSET_CCNTR_ENABLE_Msk (1UL << PMU_CNTENSET_CCNTR_ENABLE_Pos) /*!< PMU CNTENSET: Cycle Counter Enable Set Mask */ + +/** \brief PMU Count Enable Clear Register Definitions */ + +#define PMU_CNTENSET_CNT0_ENABLE_Pos 0U /*!< PMU CNTENCLR: Event Counter 0 Enable Clear Position */ +#define PMU_CNTENCLR_CNT0_ENABLE_Msk (1UL /*<< PMU_CNTENCLR_CNT0_ENABLE_Pos*/) /*!< PMU CNTENCLR: Event Counter 0 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT1_ENABLE_Pos 1U /*!< PMU CNTENCLR: Event Counter 1 Enable Clear Position */ +#define PMU_CNTENCLR_CNT1_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT1_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 1 Enable Clear */ + +#define PMU_CNTENCLR_CNT2_ENABLE_Pos 2U /*!< PMU CNTENCLR: Event Counter 2 Enable Clear Position */ +#define PMU_CNTENCLR_CNT2_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT2_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 2 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT3_ENABLE_Pos 3U /*!< PMU CNTENCLR: Event Counter 3 Enable Clear Position */ +#define PMU_CNTENCLR_CNT3_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT3_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 3 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT4_ENABLE_Pos 4U /*!< PMU CNTENCLR: Event Counter 4 Enable Clear Position */ +#define PMU_CNTENCLR_CNT4_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT4_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 4 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT5_ENABLE_Pos 5U /*!< PMU CNTENCLR: Event Counter 5 Enable Clear Position */ +#define PMU_CNTENCLR_CNT5_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT5_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 5 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT6_ENABLE_Pos 6U /*!< PMU CNTENCLR: Event Counter 6 Enable Clear Position */ +#define PMU_CNTENCLR_CNT6_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT6_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 6 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT7_ENABLE_Pos 7U /*!< PMU CNTENCLR: Event Counter 7 Enable Clear Position */ +#define PMU_CNTENCLR_CNT7_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT7_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 7 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT8_ENABLE_Pos 8U /*!< PMU CNTENCLR: Event Counter 8 Enable Clear Position */ +#define PMU_CNTENCLR_CNT8_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT8_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 8 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT9_ENABLE_Pos 9U /*!< PMU CNTENCLR: Event Counter 9 Enable Clear Position */ +#define PMU_CNTENCLR_CNT9_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT9_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 9 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT10_ENABLE_Pos 10U /*!< PMU CNTENCLR: Event Counter 10 Enable Clear Position */ +#define PMU_CNTENCLR_CNT10_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT10_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 10 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT11_ENABLE_Pos 11U /*!< PMU CNTENCLR: Event Counter 11 Enable Clear Position */ +#define PMU_CNTENCLR_CNT11_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT11_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 11 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT12_ENABLE_Pos 12U /*!< PMU CNTENCLR: Event Counter 12 Enable Clear Position */ +#define PMU_CNTENCLR_CNT12_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT12_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 12 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT13_ENABLE_Pos 13U /*!< PMU CNTENCLR: Event Counter 13 Enable Clear Position */ +#define PMU_CNTENCLR_CNT13_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT13_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 13 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT14_ENABLE_Pos 14U /*!< PMU CNTENCLR: Event Counter 14 Enable Clear Position */ +#define PMU_CNTENCLR_CNT14_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT14_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 14 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT15_ENABLE_Pos 15U /*!< PMU CNTENCLR: Event Counter 15 Enable Clear Position */ +#define PMU_CNTENCLR_CNT15_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT15_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 15 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT16_ENABLE_Pos 16U /*!< PMU CNTENCLR: Event Counter 16 Enable Clear Position */ +#define PMU_CNTENCLR_CNT16_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT16_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 16 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT17_ENABLE_Pos 17U /*!< PMU CNTENCLR: Event Counter 17 Enable Clear Position */ +#define PMU_CNTENCLR_CNT17_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT17_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 17 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT18_ENABLE_Pos 18U /*!< PMU CNTENCLR: Event Counter 18 Enable Clear Position */ +#define PMU_CNTENCLR_CNT18_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT18_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 18 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT19_ENABLE_Pos 19U /*!< PMU CNTENCLR: Event Counter 19 Enable Clear Position */ +#define PMU_CNTENCLR_CNT19_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT19_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 19 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT20_ENABLE_Pos 20U /*!< PMU CNTENCLR: Event Counter 20 Enable Clear Position */ +#define PMU_CNTENCLR_CNT20_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT20_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 20 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT21_ENABLE_Pos 21U /*!< PMU CNTENCLR: Event Counter 21 Enable Clear Position */ +#define PMU_CNTENCLR_CNT21_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT21_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 21 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT22_ENABLE_Pos 22U /*!< PMU CNTENCLR: Event Counter 22 Enable Clear Position */ +#define PMU_CNTENCLR_CNT22_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT22_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 22 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT23_ENABLE_Pos 23U /*!< PMU CNTENCLR: Event Counter 23 Enable Clear Position */ +#define PMU_CNTENCLR_CNT23_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT23_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 23 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT24_ENABLE_Pos 24U /*!< PMU CNTENCLR: Event Counter 24 Enable Clear Position */ +#define PMU_CNTENCLR_CNT24_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT24_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 24 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT25_ENABLE_Pos 25U /*!< PMU CNTENCLR: Event Counter 25 Enable Clear Position */ +#define PMU_CNTENCLR_CNT25_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT25_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 25 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT26_ENABLE_Pos 26U /*!< PMU CNTENCLR: Event Counter 26 Enable Clear Position */ +#define PMU_CNTENCLR_CNT26_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT26_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 26 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT27_ENABLE_Pos 27U /*!< PMU CNTENCLR: Event Counter 27 Enable Clear Position */ +#define PMU_CNTENCLR_CNT27_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT27_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 27 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT28_ENABLE_Pos 28U /*!< PMU CNTENCLR: Event Counter 28 Enable Clear Position */ +#define PMU_CNTENCLR_CNT28_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT28_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 28 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT29_ENABLE_Pos 29U /*!< PMU CNTENCLR: Event Counter 29 Enable Clear Position */ +#define PMU_CNTENCLR_CNT29_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT29_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 29 Enable Clear Mask */ + +#define PMU_CNTENCLR_CNT30_ENABLE_Pos 30U /*!< PMU CNTENCLR: Event Counter 30 Enable Clear Position */ +#define PMU_CNTENCLR_CNT30_ENABLE_Msk (1UL << PMU_CNTENCLR_CNT30_ENABLE_Pos) /*!< PMU CNTENCLR: Event Counter 30 Enable Clear Mask */ + +#define PMU_CNTENCLR_CCNTR_ENABLE_Pos 31U /*!< PMU CNTENCLR: Cycle Counter Enable Clear Position */ +#define PMU_CNTENCLR_CCNTR_ENABLE_Msk (1UL << PMU_CNTENCLR_CCNTR_ENABLE_Pos) /*!< PMU CNTENCLR: Cycle Counter Enable Clear Mask */ + +/** \brief PMU Interrupt Enable Set Register Definitions */ + +#define PMU_INTENSET_CNT0_ENABLE_Pos 0U /*!< PMU INTENSET: Event Counter 0 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT0_ENABLE_Msk (1UL /*<< PMU_INTENSET_CNT0_ENABLE_Pos*/) /*!< PMU INTENSET: Event Counter 0 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT1_ENABLE_Pos 1U /*!< PMU INTENSET: Event Counter 1 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT1_ENABLE_Msk (1UL << PMU_INTENSET_CNT1_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 1 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT2_ENABLE_Pos 2U /*!< PMU INTENSET: Event Counter 2 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT2_ENABLE_Msk (1UL << PMU_INTENSET_CNT2_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 2 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT3_ENABLE_Pos 3U /*!< PMU INTENSET: Event Counter 3 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT3_ENABLE_Msk (1UL << PMU_INTENSET_CNT3_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 3 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT4_ENABLE_Pos 4U /*!< PMU INTENSET: Event Counter 4 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT4_ENABLE_Msk (1UL << PMU_INTENSET_CNT4_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 4 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT5_ENABLE_Pos 5U /*!< PMU INTENSET: Event Counter 5 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT5_ENABLE_Msk (1UL << PMU_INTENSET_CNT5_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 5 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT6_ENABLE_Pos 6U /*!< PMU INTENSET: Event Counter 6 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT6_ENABLE_Msk (1UL << PMU_INTENSET_CNT6_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 6 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT7_ENABLE_Pos 7U /*!< PMU INTENSET: Event Counter 7 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT7_ENABLE_Msk (1UL << PMU_INTENSET_CNT7_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 7 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT8_ENABLE_Pos 8U /*!< PMU INTENSET: Event Counter 8 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT8_ENABLE_Msk (1UL << PMU_INTENSET_CNT8_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 8 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT9_ENABLE_Pos 9U /*!< PMU INTENSET: Event Counter 9 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT9_ENABLE_Msk (1UL << PMU_INTENSET_CNT9_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 9 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT10_ENABLE_Pos 10U /*!< PMU INTENSET: Event Counter 10 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT10_ENABLE_Msk (1UL << PMU_INTENSET_CNT10_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 10 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT11_ENABLE_Pos 11U /*!< PMU INTENSET: Event Counter 11 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT11_ENABLE_Msk (1UL << PMU_INTENSET_CNT11_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 11 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT12_ENABLE_Pos 12U /*!< PMU INTENSET: Event Counter 12 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT12_ENABLE_Msk (1UL << PMU_INTENSET_CNT12_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 12 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT13_ENABLE_Pos 13U /*!< PMU INTENSET: Event Counter 13 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT13_ENABLE_Msk (1UL << PMU_INTENSET_CNT13_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 13 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT14_ENABLE_Pos 14U /*!< PMU INTENSET: Event Counter 14 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT14_ENABLE_Msk (1UL << PMU_INTENSET_CNT14_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 14 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT15_ENABLE_Pos 15U /*!< PMU INTENSET: Event Counter 15 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT15_ENABLE_Msk (1UL << PMU_INTENSET_CNT15_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 15 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT16_ENABLE_Pos 16U /*!< PMU INTENSET: Event Counter 16 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT16_ENABLE_Msk (1UL << PMU_INTENSET_CNT16_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 16 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT17_ENABLE_Pos 17U /*!< PMU INTENSET: Event Counter 17 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT17_ENABLE_Msk (1UL << PMU_INTENSET_CNT17_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 17 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT18_ENABLE_Pos 18U /*!< PMU INTENSET: Event Counter 18 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT18_ENABLE_Msk (1UL << PMU_INTENSET_CNT18_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 18 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT19_ENABLE_Pos 19U /*!< PMU INTENSET: Event Counter 19 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT19_ENABLE_Msk (1UL << PMU_INTENSET_CNT19_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 19 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT20_ENABLE_Pos 20U /*!< PMU INTENSET: Event Counter 20 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT20_ENABLE_Msk (1UL << PMU_INTENSET_CNT20_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 20 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT21_ENABLE_Pos 21U /*!< PMU INTENSET: Event Counter 21 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT21_ENABLE_Msk (1UL << PMU_INTENSET_CNT21_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 21 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT22_ENABLE_Pos 22U /*!< PMU INTENSET: Event Counter 22 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT22_ENABLE_Msk (1UL << PMU_INTENSET_CNT22_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 22 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT23_ENABLE_Pos 23U /*!< PMU INTENSET: Event Counter 23 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT23_ENABLE_Msk (1UL << PMU_INTENSET_CNT23_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 23 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT24_ENABLE_Pos 24U /*!< PMU INTENSET: Event Counter 24 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT24_ENABLE_Msk (1UL << PMU_INTENSET_CNT24_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 24 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT25_ENABLE_Pos 25U /*!< PMU INTENSET: Event Counter 25 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT25_ENABLE_Msk (1UL << PMU_INTENSET_CNT25_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 25 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT26_ENABLE_Pos 26U /*!< PMU INTENSET: Event Counter 26 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT26_ENABLE_Msk (1UL << PMU_INTENSET_CNT26_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 26 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT27_ENABLE_Pos 27U /*!< PMU INTENSET: Event Counter 27 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT27_ENABLE_Msk (1UL << PMU_INTENSET_CNT27_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 27 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT28_ENABLE_Pos 28U /*!< PMU INTENSET: Event Counter 28 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT28_ENABLE_Msk (1UL << PMU_INTENSET_CNT28_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 28 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT29_ENABLE_Pos 29U /*!< PMU INTENSET: Event Counter 29 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT29_ENABLE_Msk (1UL << PMU_INTENSET_CNT29_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 29 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CNT30_ENABLE_Pos 30U /*!< PMU INTENSET: Event Counter 30 Interrupt Enable Set Position */ +#define PMU_INTENSET_CNT30_ENABLE_Msk (1UL << PMU_INTENSET_CNT30_ENABLE_Pos) /*!< PMU INTENSET: Event Counter 30 Interrupt Enable Set Mask */ + +#define PMU_INTENSET_CYCCNT_ENABLE_Pos 31U /*!< PMU INTENSET: Cycle Counter Interrupt Enable Set Position */ +#define PMU_INTENSET_CCYCNT_ENABLE_Msk (1UL << PMU_INTENSET_CYCCNT_ENABLE_Pos) /*!< PMU INTENSET: Cycle Counter Interrupt Enable Set Mask */ + +/** \brief PMU Interrupt Enable Clear Register Definitions */ + +#define PMU_INTENSET_CNT0_ENABLE_Pos 0U /*!< PMU INTENCLR: Event Counter 0 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT0_ENABLE_Msk (1UL /*<< PMU_INTENCLR_CNT0_ENABLE_Pos*/) /*!< PMU INTENCLR: Event Counter 0 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT1_ENABLE_Pos 1U /*!< PMU INTENCLR: Event Counter 1 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT1_ENABLE_Msk (1UL << PMU_INTENCLR_CNT1_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 1 Interrupt Enable Clear */ + +#define PMU_INTENCLR_CNT2_ENABLE_Pos 2U /*!< PMU INTENCLR: Event Counter 2 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT2_ENABLE_Msk (1UL << PMU_INTENCLR_CNT2_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 2 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT3_ENABLE_Pos 3U /*!< PMU INTENCLR: Event Counter 3 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT3_ENABLE_Msk (1UL << PMU_INTENCLR_CNT3_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 3 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT4_ENABLE_Pos 4U /*!< PMU INTENCLR: Event Counter 4 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT4_ENABLE_Msk (1UL << PMU_INTENCLR_CNT4_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 4 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT5_ENABLE_Pos 5U /*!< PMU INTENCLR: Event Counter 5 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT5_ENABLE_Msk (1UL << PMU_INTENCLR_CNT5_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 5 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT6_ENABLE_Pos 6U /*!< PMU INTENCLR: Event Counter 6 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT6_ENABLE_Msk (1UL << PMU_INTENCLR_CNT6_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 6 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT7_ENABLE_Pos 7U /*!< PMU INTENCLR: Event Counter 7 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT7_ENABLE_Msk (1UL << PMU_INTENCLR_CNT7_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 7 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT8_ENABLE_Pos 8U /*!< PMU INTENCLR: Event Counter 8 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT8_ENABLE_Msk (1UL << PMU_INTENCLR_CNT8_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 8 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT9_ENABLE_Pos 9U /*!< PMU INTENCLR: Event Counter 9 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT9_ENABLE_Msk (1UL << PMU_INTENCLR_CNT9_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 9 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT10_ENABLE_Pos 10U /*!< PMU INTENCLR: Event Counter 10 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT10_ENABLE_Msk (1UL << PMU_INTENCLR_CNT10_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 10 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT11_ENABLE_Pos 11U /*!< PMU INTENCLR: Event Counter 11 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT11_ENABLE_Msk (1UL << PMU_INTENCLR_CNT11_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 11 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT12_ENABLE_Pos 12U /*!< PMU INTENCLR: Event Counter 12 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT12_ENABLE_Msk (1UL << PMU_INTENCLR_CNT12_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 12 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT13_ENABLE_Pos 13U /*!< PMU INTENCLR: Event Counter 13 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT13_ENABLE_Msk (1UL << PMU_INTENCLR_CNT13_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 13 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT14_ENABLE_Pos 14U /*!< PMU INTENCLR: Event Counter 14 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT14_ENABLE_Msk (1UL << PMU_INTENCLR_CNT14_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 14 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT15_ENABLE_Pos 15U /*!< PMU INTENCLR: Event Counter 15 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT15_ENABLE_Msk (1UL << PMU_INTENCLR_CNT15_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 15 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT16_ENABLE_Pos 16U /*!< PMU INTENCLR: Event Counter 16 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT16_ENABLE_Msk (1UL << PMU_INTENCLR_CNT16_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 16 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT17_ENABLE_Pos 17U /*!< PMU INTENCLR: Event Counter 17 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT17_ENABLE_Msk (1UL << PMU_INTENCLR_CNT17_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 17 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT18_ENABLE_Pos 18U /*!< PMU INTENCLR: Event Counter 18 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT18_ENABLE_Msk (1UL << PMU_INTENCLR_CNT18_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 18 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT19_ENABLE_Pos 19U /*!< PMU INTENCLR: Event Counter 19 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT19_ENABLE_Msk (1UL << PMU_INTENCLR_CNT19_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 19 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT20_ENABLE_Pos 20U /*!< PMU INTENCLR: Event Counter 20 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT20_ENABLE_Msk (1UL << PMU_INTENCLR_CNT20_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 20 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT21_ENABLE_Pos 21U /*!< PMU INTENCLR: Event Counter 21 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT21_ENABLE_Msk (1UL << PMU_INTENCLR_CNT21_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 21 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT22_ENABLE_Pos 22U /*!< PMU INTENCLR: Event Counter 22 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT22_ENABLE_Msk (1UL << PMU_INTENCLR_CNT22_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 22 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT23_ENABLE_Pos 23U /*!< PMU INTENCLR: Event Counter 23 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT23_ENABLE_Msk (1UL << PMU_INTENCLR_CNT23_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 23 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT24_ENABLE_Pos 24U /*!< PMU INTENCLR: Event Counter 24 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT24_ENABLE_Msk (1UL << PMU_INTENCLR_CNT24_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 24 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT25_ENABLE_Pos 25U /*!< PMU INTENCLR: Event Counter 25 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT25_ENABLE_Msk (1UL << PMU_INTENCLR_CNT25_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 25 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT26_ENABLE_Pos 26U /*!< PMU INTENCLR: Event Counter 26 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT26_ENABLE_Msk (1UL << PMU_INTENCLR_CNT26_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 26 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT27_ENABLE_Pos 27U /*!< PMU INTENCLR: Event Counter 27 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT27_ENABLE_Msk (1UL << PMU_INTENCLR_CNT27_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 27 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT28_ENABLE_Pos 28U /*!< PMU INTENCLR: Event Counter 28 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT28_ENABLE_Msk (1UL << PMU_INTENCLR_CNT28_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 28 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT29_ENABLE_Pos 29U /*!< PMU INTENCLR: Event Counter 29 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT29_ENABLE_Msk (1UL << PMU_INTENCLR_CNT29_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 29 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CNT30_ENABLE_Pos 30U /*!< PMU INTENCLR: Event Counter 30 Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CNT30_ENABLE_Msk (1UL << PMU_INTENCLR_CNT30_ENABLE_Pos) /*!< PMU INTENCLR: Event Counter 30 Interrupt Enable Clear Mask */ + +#define PMU_INTENCLR_CYCCNT_ENABLE_Pos 31U /*!< PMU INTENCLR: Cycle Counter Interrupt Enable Clear Position */ +#define PMU_INTENCLR_CYCCNT_ENABLE_Msk (1UL << PMU_INTENCLR_CYCCNT_ENABLE_Pos) /*!< PMU INTENCLR: Cycle Counter Interrupt Enable Clear Mask */ + +/** \brief PMU Overflow Flag Status Set Register Definitions */ + +#define PMU_OVSSET_CNT0_STATUS_Pos 0U /*!< PMU OVSSET: Event Counter 0 Overflow Set Position */ +#define PMU_OVSSET_CNT0_STATUS_Msk (1UL /*<< PMU_OVSSET_CNT0_STATUS_Pos*/) /*!< PMU OVSSET: Event Counter 0 Overflow Set Mask */ + +#define PMU_OVSSET_CNT1_STATUS_Pos 1U /*!< PMU OVSSET: Event Counter 1 Overflow Set Position */ +#define PMU_OVSSET_CNT1_STATUS_Msk (1UL << PMU_OVSSET_CNT1_STATUS_Pos) /*!< PMU OVSSET: Event Counter 1 Overflow Set Mask */ + +#define PMU_OVSSET_CNT2_STATUS_Pos 2U /*!< PMU OVSSET: Event Counter 2 Overflow Set Position */ +#define PMU_OVSSET_CNT2_STATUS_Msk (1UL << PMU_OVSSET_CNT2_STATUS_Pos) /*!< PMU OVSSET: Event Counter 2 Overflow Set Mask */ + +#define PMU_OVSSET_CNT3_STATUS_Pos 3U /*!< PMU OVSSET: Event Counter 3 Overflow Set Position */ +#define PMU_OVSSET_CNT3_STATUS_Msk (1UL << PMU_OVSSET_CNT3_STATUS_Pos) /*!< PMU OVSSET: Event Counter 3 Overflow Set Mask */ + +#define PMU_OVSSET_CNT4_STATUS_Pos 4U /*!< PMU OVSSET: Event Counter 4 Overflow Set Position */ +#define PMU_OVSSET_CNT4_STATUS_Msk (1UL << PMU_OVSSET_CNT4_STATUS_Pos) /*!< PMU OVSSET: Event Counter 4 Overflow Set Mask */ + +#define PMU_OVSSET_CNT5_STATUS_Pos 5U /*!< PMU OVSSET: Event Counter 5 Overflow Set Position */ +#define PMU_OVSSET_CNT5_STATUS_Msk (1UL << PMU_OVSSET_CNT5_STATUS_Pos) /*!< PMU OVSSET: Event Counter 5 Overflow Set Mask */ + +#define PMU_OVSSET_CNT6_STATUS_Pos 6U /*!< PMU OVSSET: Event Counter 6 Overflow Set Position */ +#define PMU_OVSSET_CNT6_STATUS_Msk (1UL << PMU_OVSSET_CNT6_STATUS_Pos) /*!< PMU OVSSET: Event Counter 6 Overflow Set Mask */ + +#define PMU_OVSSET_CNT7_STATUS_Pos 7U /*!< PMU OVSSET: Event Counter 7 Overflow Set Position */ +#define PMU_OVSSET_CNT7_STATUS_Msk (1UL << PMU_OVSSET_CNT7_STATUS_Pos) /*!< PMU OVSSET: Event Counter 7 Overflow Set Mask */ + +#define PMU_OVSSET_CNT8_STATUS_Pos 8U /*!< PMU OVSSET: Event Counter 8 Overflow Set Position */ +#define PMU_OVSSET_CNT8_STATUS_Msk (1UL << PMU_OVSSET_CNT8_STATUS_Pos) /*!< PMU OVSSET: Event Counter 8 Overflow Set Mask */ + +#define PMU_OVSSET_CNT9_STATUS_Pos 9U /*!< PMU OVSSET: Event Counter 9 Overflow Set Position */ +#define PMU_OVSSET_CNT9_STATUS_Msk (1UL << PMU_OVSSET_CNT9_STATUS_Pos) /*!< PMU OVSSET: Event Counter 9 Overflow Set Mask */ + +#define PMU_OVSSET_CNT10_STATUS_Pos 10U /*!< PMU OVSSET: Event Counter 10 Overflow Set Position */ +#define PMU_OVSSET_CNT10_STATUS_Msk (1UL << PMU_OVSSET_CNT10_STATUS_Pos) /*!< PMU OVSSET: Event Counter 10 Overflow Set Mask */ + +#define PMU_OVSSET_CNT11_STATUS_Pos 11U /*!< PMU OVSSET: Event Counter 11 Overflow Set Position */ +#define PMU_OVSSET_CNT11_STATUS_Msk (1UL << PMU_OVSSET_CNT11_STATUS_Pos) /*!< PMU OVSSET: Event Counter 11 Overflow Set Mask */ + +#define PMU_OVSSET_CNT12_STATUS_Pos 12U /*!< PMU OVSSET: Event Counter 12 Overflow Set Position */ +#define PMU_OVSSET_CNT12_STATUS_Msk (1UL << PMU_OVSSET_CNT12_STATUS_Pos) /*!< PMU OVSSET: Event Counter 12 Overflow Set Mask */ + +#define PMU_OVSSET_CNT13_STATUS_Pos 13U /*!< PMU OVSSET: Event Counter 13 Overflow Set Position */ +#define PMU_OVSSET_CNT13_STATUS_Msk (1UL << PMU_OVSSET_CNT13_STATUS_Pos) /*!< PMU OVSSET: Event Counter 13 Overflow Set Mask */ + +#define PMU_OVSSET_CNT14_STATUS_Pos 14U /*!< PMU OVSSET: Event Counter 14 Overflow Set Position */ +#define PMU_OVSSET_CNT14_STATUS_Msk (1UL << PMU_OVSSET_CNT14_STATUS_Pos) /*!< PMU OVSSET: Event Counter 14 Overflow Set Mask */ + +#define PMU_OVSSET_CNT15_STATUS_Pos 15U /*!< PMU OVSSET: Event Counter 15 Overflow Set Position */ +#define PMU_OVSSET_CNT15_STATUS_Msk (1UL << PMU_OVSSET_CNT15_STATUS_Pos) /*!< PMU OVSSET: Event Counter 15 Overflow Set Mask */ + +#define PMU_OVSSET_CNT16_STATUS_Pos 16U /*!< PMU OVSSET: Event Counter 16 Overflow Set Position */ +#define PMU_OVSSET_CNT16_STATUS_Msk (1UL << PMU_OVSSET_CNT16_STATUS_Pos) /*!< PMU OVSSET: Event Counter 16 Overflow Set Mask */ + +#define PMU_OVSSET_CNT17_STATUS_Pos 17U /*!< PMU OVSSET: Event Counter 17 Overflow Set Position */ +#define PMU_OVSSET_CNT17_STATUS_Msk (1UL << PMU_OVSSET_CNT17_STATUS_Pos) /*!< PMU OVSSET: Event Counter 17 Overflow Set Mask */ + +#define PMU_OVSSET_CNT18_STATUS_Pos 18U /*!< PMU OVSSET: Event Counter 18 Overflow Set Position */ +#define PMU_OVSSET_CNT18_STATUS_Msk (1UL << PMU_OVSSET_CNT18_STATUS_Pos) /*!< PMU OVSSET: Event Counter 18 Overflow Set Mask */ + +#define PMU_OVSSET_CNT19_STATUS_Pos 19U /*!< PMU OVSSET: Event Counter 19 Overflow Set Position */ +#define PMU_OVSSET_CNT19_STATUS_Msk (1UL << PMU_OVSSET_CNT19_STATUS_Pos) /*!< PMU OVSSET: Event Counter 19 Overflow Set Mask */ + +#define PMU_OVSSET_CNT20_STATUS_Pos 20U /*!< PMU OVSSET: Event Counter 20 Overflow Set Position */ +#define PMU_OVSSET_CNT20_STATUS_Msk (1UL << PMU_OVSSET_CNT20_STATUS_Pos) /*!< PMU OVSSET: Event Counter 20 Overflow Set Mask */ + +#define PMU_OVSSET_CNT21_STATUS_Pos 21U /*!< PMU OVSSET: Event Counter 21 Overflow Set Position */ +#define PMU_OVSSET_CNT21_STATUS_Msk (1UL << PMU_OVSSET_CNT21_STATUS_Pos) /*!< PMU OVSSET: Event Counter 21 Overflow Set Mask */ + +#define PMU_OVSSET_CNT22_STATUS_Pos 22U /*!< PMU OVSSET: Event Counter 22 Overflow Set Position */ +#define PMU_OVSSET_CNT22_STATUS_Msk (1UL << PMU_OVSSET_CNT22_STATUS_Pos) /*!< PMU OVSSET: Event Counter 22 Overflow Set Mask */ + +#define PMU_OVSSET_CNT23_STATUS_Pos 23U /*!< PMU OVSSET: Event Counter 23 Overflow Set Position */ +#define PMU_OVSSET_CNT23_STATUS_Msk (1UL << PMU_OVSSET_CNT23_STATUS_Pos) /*!< PMU OVSSET: Event Counter 23 Overflow Set Mask */ + +#define PMU_OVSSET_CNT24_STATUS_Pos 24U /*!< PMU OVSSET: Event Counter 24 Overflow Set Position */ +#define PMU_OVSSET_CNT24_STATUS_Msk (1UL << PMU_OVSSET_CNT24_STATUS_Pos) /*!< PMU OVSSET: Event Counter 24 Overflow Set Mask */ + +#define PMU_OVSSET_CNT25_STATUS_Pos 25U /*!< PMU OVSSET: Event Counter 25 Overflow Set Position */ +#define PMU_OVSSET_CNT25_STATUS_Msk (1UL << PMU_OVSSET_CNT25_STATUS_Pos) /*!< PMU OVSSET: Event Counter 25 Overflow Set Mask */ + +#define PMU_OVSSET_CNT26_STATUS_Pos 26U /*!< PMU OVSSET: Event Counter 26 Overflow Set Position */ +#define PMU_OVSSET_CNT26_STATUS_Msk (1UL << PMU_OVSSET_CNT26_STATUS_Pos) /*!< PMU OVSSET: Event Counter 26 Overflow Set Mask */ + +#define PMU_OVSSET_CNT27_STATUS_Pos 27U /*!< PMU OVSSET: Event Counter 27 Overflow Set Position */ +#define PMU_OVSSET_CNT27_STATUS_Msk (1UL << PMU_OVSSET_CNT27_STATUS_Pos) /*!< PMU OVSSET: Event Counter 27 Overflow Set Mask */ + +#define PMU_OVSSET_CNT28_STATUS_Pos 28U /*!< PMU OVSSET: Event Counter 28 Overflow Set Position */ +#define PMU_OVSSET_CNT28_STATUS_Msk (1UL << PMU_OVSSET_CNT28_STATUS_Pos) /*!< PMU OVSSET: Event Counter 28 Overflow Set Mask */ + +#define PMU_OVSSET_CNT29_STATUS_Pos 29U /*!< PMU OVSSET: Event Counter 29 Overflow Set Position */ +#define PMU_OVSSET_CNT29_STATUS_Msk (1UL << PMU_OVSSET_CNT29_STATUS_Pos) /*!< PMU OVSSET: Event Counter 29 Overflow Set Mask */ + +#define PMU_OVSSET_CNT30_STATUS_Pos 30U /*!< PMU OVSSET: Event Counter 30 Overflow Set Position */ +#define PMU_OVSSET_CNT30_STATUS_Msk (1UL << PMU_OVSSET_CNT30_STATUS_Pos) /*!< PMU OVSSET: Event Counter 30 Overflow Set Mask */ + +#define PMU_OVSSET_CYCCNT_STATUS_Pos 31U /*!< PMU OVSSET: Cycle Counter Overflow Set Position */ +#define PMU_OVSSET_CYCCNT_STATUS_Msk (1UL << PMU_OVSSET_CYCCNT_STATUS_Pos) /*!< PMU OVSSET: Cycle Counter Overflow Set Mask */ + +/** \brief PMU Overflow Flag Status Clear Register Definitions */ + +#define PMU_OVSCLR_CNT0_STATUS_Pos 0U /*!< PMU OVSCLR: Event Counter 0 Overflow Clear Position */ +#define PMU_OVSCLR_CNT0_STATUS_Msk (1UL /*<< PMU_OVSCLR_CNT0_STATUS_Pos*/) /*!< PMU OVSCLR: Event Counter 0 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT1_STATUS_Pos 1U /*!< PMU OVSCLR: Event Counter 1 Overflow Clear Position */ +#define PMU_OVSCLR_CNT1_STATUS_Msk (1UL << PMU_OVSCLR_CNT1_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 1 Overflow Clear */ + +#define PMU_OVSCLR_CNT2_STATUS_Pos 2U /*!< PMU OVSCLR: Event Counter 2 Overflow Clear Position */ +#define PMU_OVSCLR_CNT2_STATUS_Msk (1UL << PMU_OVSCLR_CNT2_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 2 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT3_STATUS_Pos 3U /*!< PMU OVSCLR: Event Counter 3 Overflow Clear Position */ +#define PMU_OVSCLR_CNT3_STATUS_Msk (1UL << PMU_OVSCLR_CNT3_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 3 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT4_STATUS_Pos 4U /*!< PMU OVSCLR: Event Counter 4 Overflow Clear Position */ +#define PMU_OVSCLR_CNT4_STATUS_Msk (1UL << PMU_OVSCLR_CNT4_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 4 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT5_STATUS_Pos 5U /*!< PMU OVSCLR: Event Counter 5 Overflow Clear Position */ +#define PMU_OVSCLR_CNT5_STATUS_Msk (1UL << PMU_OVSCLR_CNT5_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 5 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT6_STATUS_Pos 6U /*!< PMU OVSCLR: Event Counter 6 Overflow Clear Position */ +#define PMU_OVSCLR_CNT6_STATUS_Msk (1UL << PMU_OVSCLR_CNT6_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 6 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT7_STATUS_Pos 7U /*!< PMU OVSCLR: Event Counter 7 Overflow Clear Position */ +#define PMU_OVSCLR_CNT7_STATUS_Msk (1UL << PMU_OVSCLR_CNT7_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 7 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT8_STATUS_Pos 8U /*!< PMU OVSCLR: Event Counter 8 Overflow Clear Position */ +#define PMU_OVSCLR_CNT8_STATUS_Msk (1UL << PMU_OVSCLR_CNT8_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 8 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT9_STATUS_Pos 9U /*!< PMU OVSCLR: Event Counter 9 Overflow Clear Position */ +#define PMU_OVSCLR_CNT9_STATUS_Msk (1UL << PMU_OVSCLR_CNT9_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 9 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT10_STATUS_Pos 10U /*!< PMU OVSCLR: Event Counter 10 Overflow Clear Position */ +#define PMU_OVSCLR_CNT10_STATUS_Msk (1UL << PMU_OVSCLR_CNT10_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 10 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT11_STATUS_Pos 11U /*!< PMU OVSCLR: Event Counter 11 Overflow Clear Position */ +#define PMU_OVSCLR_CNT11_STATUS_Msk (1UL << PMU_OVSCLR_CNT11_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 11 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT12_STATUS_Pos 12U /*!< PMU OVSCLR: Event Counter 12 Overflow Clear Position */ +#define PMU_OVSCLR_CNT12_STATUS_Msk (1UL << PMU_OVSCLR_CNT12_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 12 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT13_STATUS_Pos 13U /*!< PMU OVSCLR: Event Counter 13 Overflow Clear Position */ +#define PMU_OVSCLR_CNT13_STATUS_Msk (1UL << PMU_OVSCLR_CNT13_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 13 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT14_STATUS_Pos 14U /*!< PMU OVSCLR: Event Counter 14 Overflow Clear Position */ +#define PMU_OVSCLR_CNT14_STATUS_Msk (1UL << PMU_OVSCLR_CNT14_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 14 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT15_STATUS_Pos 15U /*!< PMU OVSCLR: Event Counter 15 Overflow Clear Position */ +#define PMU_OVSCLR_CNT15_STATUS_Msk (1UL << PMU_OVSCLR_CNT15_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 15 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT16_STATUS_Pos 16U /*!< PMU OVSCLR: Event Counter 16 Overflow Clear Position */ +#define PMU_OVSCLR_CNT16_STATUS_Msk (1UL << PMU_OVSCLR_CNT16_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 16 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT17_STATUS_Pos 17U /*!< PMU OVSCLR: Event Counter 17 Overflow Clear Position */ +#define PMU_OVSCLR_CNT17_STATUS_Msk (1UL << PMU_OVSCLR_CNT17_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 17 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT18_STATUS_Pos 18U /*!< PMU OVSCLR: Event Counter 18 Overflow Clear Position */ +#define PMU_OVSCLR_CNT18_STATUS_Msk (1UL << PMU_OVSCLR_CNT18_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 18 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT19_STATUS_Pos 19U /*!< PMU OVSCLR: Event Counter 19 Overflow Clear Position */ +#define PMU_OVSCLR_CNT19_STATUS_Msk (1UL << PMU_OVSCLR_CNT19_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 19 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT20_STATUS_Pos 20U /*!< PMU OVSCLR: Event Counter 20 Overflow Clear Position */ +#define PMU_OVSCLR_CNT20_STATUS_Msk (1UL << PMU_OVSCLR_CNT20_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 20 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT21_STATUS_Pos 21U /*!< PMU OVSCLR: Event Counter 21 Overflow Clear Position */ +#define PMU_OVSCLR_CNT21_STATUS_Msk (1UL << PMU_OVSCLR_CNT21_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 21 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT22_STATUS_Pos 22U /*!< PMU OVSCLR: Event Counter 22 Overflow Clear Position */ +#define PMU_OVSCLR_CNT22_STATUS_Msk (1UL << PMU_OVSCLR_CNT22_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 22 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT23_STATUS_Pos 23U /*!< PMU OVSCLR: Event Counter 23 Overflow Clear Position */ +#define PMU_OVSCLR_CNT23_STATUS_Msk (1UL << PMU_OVSCLR_CNT23_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 23 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT24_STATUS_Pos 24U /*!< PMU OVSCLR: Event Counter 24 Overflow Clear Position */ +#define PMU_OVSCLR_CNT24_STATUS_Msk (1UL << PMU_OVSCLR_CNT24_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 24 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT25_STATUS_Pos 25U /*!< PMU OVSCLR: Event Counter 25 Overflow Clear Position */ +#define PMU_OVSCLR_CNT25_STATUS_Msk (1UL << PMU_OVSCLR_CNT25_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 25 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT26_STATUS_Pos 26U /*!< PMU OVSCLR: Event Counter 26 Overflow Clear Position */ +#define PMU_OVSCLR_CNT26_STATUS_Msk (1UL << PMU_OVSCLR_CNT26_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 26 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT27_STATUS_Pos 27U /*!< PMU OVSCLR: Event Counter 27 Overflow Clear Position */ +#define PMU_OVSCLR_CNT27_STATUS_Msk (1UL << PMU_OVSCLR_CNT27_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 27 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT28_STATUS_Pos 28U /*!< PMU OVSCLR: Event Counter 28 Overflow Clear Position */ +#define PMU_OVSCLR_CNT28_STATUS_Msk (1UL << PMU_OVSCLR_CNT28_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 28 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT29_STATUS_Pos 29U /*!< PMU OVSCLR: Event Counter 29 Overflow Clear Position */ +#define PMU_OVSCLR_CNT29_STATUS_Msk (1UL << PMU_OVSCLR_CNT29_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 29 Overflow Clear Mask */ + +#define PMU_OVSCLR_CNT30_STATUS_Pos 30U /*!< PMU OVSCLR: Event Counter 30 Overflow Clear Position */ +#define PMU_OVSCLR_CNT30_STATUS_Msk (1UL << PMU_OVSCLR_CNT30_STATUS_Pos) /*!< PMU OVSCLR: Event Counter 30 Overflow Clear Mask */ + +#define PMU_OVSCLR_CYCCNT_STATUS_Pos 31U /*!< PMU OVSCLR: Cycle Counter Overflow Clear Position */ +#define PMU_OVSCLR_CYCCNT_STATUS_Msk (1UL << PMU_OVSCLR_CYCCNT_STATUS_Pos) /*!< PMU OVSCLR: Cycle Counter Overflow Clear Mask */ + +/** \brief PMU Software Increment Counter */ + +#define PMU_SWINC_CNT0_Pos 0U /*!< PMU SWINC: Event Counter 0 Software Increment Position */ +#define PMU_SWINC_CNT0_Msk (1UL /*<< PMU_SWINC_CNT0_Pos */) /*!< PMU SWINC: Event Counter 0 Software Increment Mask */ + +#define PMU_SWINC_CNT1_Pos 1U /*!< PMU SWINC: Event Counter 1 Software Increment Position */ +#define PMU_SWINC_CNT1_Msk (1UL << PMU_SWINC_CNT1_Pos) /*!< PMU SWINC: Event Counter 1 Software Increment Mask */ + +#define PMU_SWINC_CNT2_Pos 2U /*!< PMU SWINC: Event Counter 2 Software Increment Position */ +#define PMU_SWINC_CNT2_Msk (1UL << PMU_SWINC_CNT2_Pos) /*!< PMU SWINC: Event Counter 2 Software Increment Mask */ + +#define PMU_SWINC_CNT3_Pos 3U /*!< PMU SWINC: Event Counter 3 Software Increment Position */ +#define PMU_SWINC_CNT3_Msk (1UL << PMU_SWINC_CNT3_Pos) /*!< PMU SWINC: Event Counter 3 Software Increment Mask */ + +#define PMU_SWINC_CNT4_Pos 4U /*!< PMU SWINC: Event Counter 4 Software Increment Position */ +#define PMU_SWINC_CNT4_Msk (1UL << PMU_SWINC_CNT4_Pos) /*!< PMU SWINC: Event Counter 4 Software Increment Mask */ + +#define PMU_SWINC_CNT5_Pos 5U /*!< PMU SWINC: Event Counter 5 Software Increment Position */ +#define PMU_SWINC_CNT5_Msk (1UL << PMU_SWINC_CNT5_Pos) /*!< PMU SWINC: Event Counter 5 Software Increment Mask */ + +#define PMU_SWINC_CNT6_Pos 6U /*!< PMU SWINC: Event Counter 6 Software Increment Position */ +#define PMU_SWINC_CNT6_Msk (1UL << PMU_SWINC_CNT6_Pos) /*!< PMU SWINC: Event Counter 6 Software Increment Mask */ + +#define PMU_SWINC_CNT7_Pos 7U /*!< PMU SWINC: Event Counter 7 Software Increment Position */ +#define PMU_SWINC_CNT7_Msk (1UL << PMU_SWINC_CNT7_Pos) /*!< PMU SWINC: Event Counter 7 Software Increment Mask */ + +#define PMU_SWINC_CNT8_Pos 8U /*!< PMU SWINC: Event Counter 8 Software Increment Position */ +#define PMU_SWINC_CNT8_Msk (1UL << PMU_SWINC_CNT8_Pos) /*!< PMU SWINC: Event Counter 8 Software Increment Mask */ + +#define PMU_SWINC_CNT9_Pos 9U /*!< PMU SWINC: Event Counter 9 Software Increment Position */ +#define PMU_SWINC_CNT9_Msk (1UL << PMU_SWINC_CNT9_Pos) /*!< PMU SWINC: Event Counter 9 Software Increment Mask */ + +#define PMU_SWINC_CNT10_Pos 10U /*!< PMU SWINC: Event Counter 10 Software Increment Position */ +#define PMU_SWINC_CNT10_Msk (1UL << PMU_SWINC_CNT10_Pos) /*!< PMU SWINC: Event Counter 10 Software Increment Mask */ + +#define PMU_SWINC_CNT11_Pos 11U /*!< PMU SWINC: Event Counter 11 Software Increment Position */ +#define PMU_SWINC_CNT11_Msk (1UL << PMU_SWINC_CNT11_Pos) /*!< PMU SWINC: Event Counter 11 Software Increment Mask */ + +#define PMU_SWINC_CNT12_Pos 12U /*!< PMU SWINC: Event Counter 12 Software Increment Position */ +#define PMU_SWINC_CNT12_Msk (1UL << PMU_SWINC_CNT12_Pos) /*!< PMU SWINC: Event Counter 12 Software Increment Mask */ + +#define PMU_SWINC_CNT13_Pos 13U /*!< PMU SWINC: Event Counter 13 Software Increment Position */ +#define PMU_SWINC_CNT13_Msk (1UL << PMU_SWINC_CNT13_Pos) /*!< PMU SWINC: Event Counter 13 Software Increment Mask */ + +#define PMU_SWINC_CNT14_Pos 14U /*!< PMU SWINC: Event Counter 14 Software Increment Position */ +#define PMU_SWINC_CNT14_Msk (1UL << PMU_SWINC_CNT14_Pos) /*!< PMU SWINC: Event Counter 14 Software Increment Mask */ + +#define PMU_SWINC_CNT15_Pos 15U /*!< PMU SWINC: Event Counter 15 Software Increment Position */ +#define PMU_SWINC_CNT15_Msk (1UL << PMU_SWINC_CNT15_Pos) /*!< PMU SWINC: Event Counter 15 Software Increment Mask */ + +#define PMU_SWINC_CNT16_Pos 16U /*!< PMU SWINC: Event Counter 16 Software Increment Position */ +#define PMU_SWINC_CNT16_Msk (1UL << PMU_SWINC_CNT16_Pos) /*!< PMU SWINC: Event Counter 16 Software Increment Mask */ + +#define PMU_SWINC_CNT17_Pos 17U /*!< PMU SWINC: Event Counter 17 Software Increment Position */ +#define PMU_SWINC_CNT17_Msk (1UL << PMU_SWINC_CNT17_Pos) /*!< PMU SWINC: Event Counter 17 Software Increment Mask */ + +#define PMU_SWINC_CNT18_Pos 18U /*!< PMU SWINC: Event Counter 18 Software Increment Position */ +#define PMU_SWINC_CNT18_Msk (1UL << PMU_SWINC_CNT18_Pos) /*!< PMU SWINC: Event Counter 18 Software Increment Mask */ + +#define PMU_SWINC_CNT19_Pos 19U /*!< PMU SWINC: Event Counter 19 Software Increment Position */ +#define PMU_SWINC_CNT19_Msk (1UL << PMU_SWINC_CNT19_Pos) /*!< PMU SWINC: Event Counter 19 Software Increment Mask */ + +#define PMU_SWINC_CNT20_Pos 20U /*!< PMU SWINC: Event Counter 20 Software Increment Position */ +#define PMU_SWINC_CNT20_Msk (1UL << PMU_SWINC_CNT20_Pos) /*!< PMU SWINC: Event Counter 20 Software Increment Mask */ + +#define PMU_SWINC_CNT21_Pos 21U /*!< PMU SWINC: Event Counter 21 Software Increment Position */ +#define PMU_SWINC_CNT21_Msk (1UL << PMU_SWINC_CNT21_Pos) /*!< PMU SWINC: Event Counter 21 Software Increment Mask */ + +#define PMU_SWINC_CNT22_Pos 22U /*!< PMU SWINC: Event Counter 22 Software Increment Position */ +#define PMU_SWINC_CNT22_Msk (1UL << PMU_SWINC_CNT22_Pos) /*!< PMU SWINC: Event Counter 22 Software Increment Mask */ + +#define PMU_SWINC_CNT23_Pos 23U /*!< PMU SWINC: Event Counter 23 Software Increment Position */ +#define PMU_SWINC_CNT23_Msk (1UL << PMU_SWINC_CNT23_Pos) /*!< PMU SWINC: Event Counter 23 Software Increment Mask */ + +#define PMU_SWINC_CNT24_Pos 24U /*!< PMU SWINC: Event Counter 24 Software Increment Position */ +#define PMU_SWINC_CNT24_Msk (1UL << PMU_SWINC_CNT24_Pos) /*!< PMU SWINC: Event Counter 24 Software Increment Mask */ + +#define PMU_SWINC_CNT25_Pos 25U /*!< PMU SWINC: Event Counter 25 Software Increment Position */ +#define PMU_SWINC_CNT25_Msk (1UL << PMU_SWINC_CNT25_Pos) /*!< PMU SWINC: Event Counter 25 Software Increment Mask */ + +#define PMU_SWINC_CNT26_Pos 26U /*!< PMU SWINC: Event Counter 26 Software Increment Position */ +#define PMU_SWINC_CNT26_Msk (1UL << PMU_SWINC_CNT26_Pos) /*!< PMU SWINC: Event Counter 26 Software Increment Mask */ + +#define PMU_SWINC_CNT27_Pos 27U /*!< PMU SWINC: Event Counter 27 Software Increment Position */ +#define PMU_SWINC_CNT27_Msk (1UL << PMU_SWINC_CNT27_Pos) /*!< PMU SWINC: Event Counter 27 Software Increment Mask */ + +#define PMU_SWINC_CNT28_Pos 28U /*!< PMU SWINC: Event Counter 28 Software Increment Position */ +#define PMU_SWINC_CNT28_Msk (1UL << PMU_SWINC_CNT28_Pos) /*!< PMU SWINC: Event Counter 28 Software Increment Mask */ + +#define PMU_SWINC_CNT29_Pos 29U /*!< PMU SWINC: Event Counter 29 Software Increment Position */ +#define PMU_SWINC_CNT29_Msk (1UL << PMU_SWINC_CNT29_Pos) /*!< PMU SWINC: Event Counter 29 Software Increment Mask */ + +#define PMU_SWINC_CNT30_Pos 30U /*!< PMU SWINC: Event Counter 30 Software Increment Position */ +#define PMU_SWINC_CNT30_Msk (1UL << PMU_SWINC_CNT30_Pos) /*!< PMU SWINC: Event Counter 30 Software Increment Mask */ + +/** \brief PMU Control Register Definitions */ + +#define PMU_CTRL_ENABLE_Pos 0U /*!< PMU CTRL: ENABLE Position */ +#define PMU_CTRL_ENABLE_Msk (1UL /*<< PMU_CTRL_ENABLE_Pos*/) /*!< PMU CTRL: ENABLE Mask */ + +#define PMU_CTRL_EVENTCNT_RESET_Pos 1U /*!< PMU CTRL: Event Counter Reset Position */ +#define PMU_CTRL_EVENTCNT_RESET_Msk (1UL << PMU_CTRL_EVENTCNT_RESET_Pos) /*!< PMU CTRL: Event Counter Reset Mask */ + +#define PMU_CTRL_CYCCNT_RESET_Pos 2U /*!< PMU CTRL: Cycle Counter Reset Position */ +#define PMU_CTRL_CYCCNT_RESET_Msk (1UL << PMU_CTRL_CYCCNT_RESET_Pos) /*!< PMU CTRL: Cycle Counter Reset Mask */ + +#define PMU_CTRL_CYCCNT_DISABLE_Pos 5U /*!< PMU CTRL: Disable Cycle Counter Position */ +#define PMU_CTRL_CYCCNT_DISABLE_Msk (1UL << PMU_CTRL_CYCCNT_DISABLE_Pos) /*!< PMU CTRL: Disable Cycle Counter Mask */ + +#define PMU_CTRL_FRZ_ON_OV_Pos 9U /*!< PMU CTRL: Freeze-on-overflow Position */ +#define PMU_CTRL_FRZ_ON_OV_Msk (1UL << PMU_CTRL_FRZ_ON_OVERFLOW_Pos) /*!< PMU CTRL: Freeze-on-overflow Mask */ + +#define PMU_CTRL_TRACE_ON_OV_Pos 11U /*!< PMU CTRL: Trace-on-overflow Position */ +#define PMU_CTRL_TRACE_ON_OV_Msk (1UL << PMU_CTRL_TRACE_ON_OVERFLOW_Pos) /*!< PMU CTRL: Trace-on-overflow Mask */ + +/** \brief PMU Type Register Definitions */ + +#define PMU_TYPE_NUM_CNTS_Pos 0U /*!< PMU TYPE: Number of Counters Position */ +#define PMU_TYPE_NUM_CNTS_Msk (0xFFUL /*<< PMU_TYPE_NUM_CNTS_Pos*/) /*!< PMU TYPE: Number of Counters Mask */ + +#define PMU_TYPE_SIZE_CNTS_Pos 8U /*!< PMU TYPE: Size of Counters Position */ +#define PMU_TYPE_SIZE_CNTS_Msk (0x3FUL << PMU_TYPE_SIZE_CNTS_Pos) /*!< PMU TYPE: Size of Counters Mask */ + +#define PMU_TYPE_CYCCNT_PRESENT_Pos 14U /*!< PMU TYPE: Cycle Counter Present Position */ +#define PMU_TYPE_CYCCNT_PRESENT_Msk (1UL << PMU_TYPE_CYCCNT_PRESENT_Pos) /*!< PMU TYPE: Cycle Counter Present Mask */ + +#define PMU_TYPE_FRZ_OV_SUPPORT_Pos 21U /*!< PMU TYPE: Freeze-on-overflow Support Position */ +#define PMU_TYPE_FRZ_OV_SUPPORT_Msk (1UL << PMU_TYPE_FRZ_OV_SUPPORT_Pos) /*!< PMU TYPE: Freeze-on-overflow Support Mask */ + +#define PMU_TYPE_TRACE_ON_OV_SUPPORT_Pos 23U /*!< PMU TYPE: Trace-on-overflow Support Position */ +#define PMU_TYPE_TRACE_ON_OV_SUPPORT_Msk (1UL << PMU_TYPE_FRZ_OV_SUPPORT_Pos) /*!< PMU TYPE: Trace-on-overflow Support Mask */ + +/** \brief PMU Authentication Status Register Definitions */ + +#define PMU_AUTHSTATUS_NSID_Pos 0U /*!< PMU AUTHSTATUS: Non-secure Invasive Debug Position */ +#define PMU_AUTHSTATUS_NSID_Msk (0x3UL /*<< PMU_AUTHSTATUS_NSID_Pos*/) /*!< PMU AUTHSTATUS: Non-secure Invasive Debug Mask */ + +#define PMU_AUTHSTATUS_NSNID_Pos 2U /*!< PMU AUTHSTATUS: Non-secure Non-invasive Debug Position */ +#define PMU_AUTHSTATUS_NSNID_Msk (0x3UL << PMU_AUTHSTATUS_NSNID_Pos) /*!< PMU AUTHSTATUS: Non-secure Non-invasive Debug Mask */ + +#define PMU_AUTHSTATUS_SID_Pos 4U /*!< PMU AUTHSTATUS: Secure Invasive Debug Position */ +#define PMU_AUTHSTATUS_SID_Msk (0x3UL << PMU_AUTHSTATUS_SID_Pos) /*!< PMU AUTHSTATUS: Secure Invasive Debug Mask */ + +#define PMU_AUTHSTATUS_SNID_Pos 6U /*!< PMU AUTHSTATUS: Secure Non-invasive Debug Position */ +#define PMU_AUTHSTATUS_SNID_Msk (0x3UL << PMU_AUTHSTATUS_SNID_Pos) /*!< PMU AUTHSTATUS: Secure Non-invasive Debug Mask */ + +#define PMU_AUTHSTATUS_NSUID_Pos 16U /*!< PMU AUTHSTATUS: Non-secure Unprivileged Invasive Debug Position */ +#define PMU_AUTHSTATUS_NSUID_Msk (0x3UL << PMU_AUTHSTATUS_NSUID_Pos) /*!< PMU AUTHSTATUS: Non-secure Unprivileged Invasive Debug Mask */ + +#define PMU_AUTHSTATUS_NSUNID_Pos 18U /*!< PMU AUTHSTATUS: Non-secure Unprivileged Non-invasive Debug Position */ +#define PMU_AUTHSTATUS_NSUNID_Msk (0x3UL << PMU_AUTHSTATUS_NSUNID_Pos) /*!< PMU AUTHSTATUS: Non-secure Unprivileged Non-invasive Debug Mask */ + +#define PMU_AUTHSTATUS_SUID_Pos 20U /*!< PMU AUTHSTATUS: Secure Unprivileged Invasive Debug Position */ +#define PMU_AUTHSTATUS_SUID_Msk (0x3UL << PMU_AUTHSTATUS_SUID_Pos) /*!< PMU AUTHSTATUS: Secure Unprivileged Invasive Debug Mask */ + +#define PMU_AUTHSTATUS_SUNID_Pos 22U /*!< PMU AUTHSTATUS: Secure Unprivileged Non-invasive Debug Position */ +#define PMU_AUTHSTATUS_SUNID_Msk (0x3UL << PMU_AUTHSTATUS_SUNID_Pos) /*!< PMU AUTHSTATUS: Secure Unprivileged Non-invasive Debug Mask */ + + +/*@} end of group CMSIS_PMU */ +#endif + +#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_MPU Memory Protection Unit (MPU) + \brief Type definitions for the Memory Protection Unit (MPU) + @{ + */ + +/** + \brief Structure type to access the Memory Protection Unit (MPU). + */ +typedef struct +{ + __IM uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */ + __IOM uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */ + __IOM uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region Number Register */ + __IOM uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */ + __IOM uint32_t RLAR; /*!< Offset: 0x010 (R/W) MPU Region Limit Address Register */ + __IOM uint32_t RBAR_A1; /*!< Offset: 0x014 (R/W) MPU Region Base Address Register Alias 1 */ + __IOM uint32_t RLAR_A1; /*!< Offset: 0x018 (R/W) MPU Region Limit Address Register Alias 1 */ + __IOM uint32_t RBAR_A2; /*!< Offset: 0x01C (R/W) MPU Region Base Address Register Alias 2 */ + __IOM uint32_t RLAR_A2; /*!< Offset: 0x020 (R/W) MPU Region Limit Address Register Alias 2 */ + __IOM uint32_t RBAR_A3; /*!< Offset: 0x024 (R/W) MPU Region Base Address Register Alias 3 */ + __IOM uint32_t RLAR_A3; /*!< Offset: 0x028 (R/W) MPU Region Limit Address Register Alias 3 */ + uint32_t RESERVED0[1]; + union { + __IOM uint32_t MAIR[2]; + struct { + __IOM uint32_t MAIR0; /*!< Offset: 0x030 (R/W) MPU Memory Attribute Indirection Register 0 */ + __IOM uint32_t MAIR1; /*!< Offset: 0x034 (R/W) MPU Memory Attribute Indirection Register 1 */ + }; + }; +} MPU_Type; + +#define MPU_TYPE_RALIASES 4U + +/* MPU Type Register Definitions */ +#define MPU_TYPE_IREGION_Pos 16U /*!< MPU TYPE: IREGION Position */ +#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */ + +#define MPU_TYPE_DREGION_Pos 8U /*!< MPU TYPE: DREGION Position */ +#define MPU_TYPE_DREGION_Msk (0xFFUL << MPU_TYPE_DREGION_Pos) /*!< MPU TYPE: DREGION Mask */ + +#define MPU_TYPE_SEPARATE_Pos 0U /*!< MPU TYPE: SEPARATE Position */ +#define MPU_TYPE_SEPARATE_Msk (1UL /*<< MPU_TYPE_SEPARATE_Pos*/) /*!< MPU TYPE: SEPARATE Mask */ + +/* MPU Control Register Definitions */ +#define MPU_CTRL_PRIVDEFENA_Pos 2U /*!< MPU CTRL: PRIVDEFENA Position */ +#define MPU_CTRL_PRIVDEFENA_Msk (1UL << MPU_CTRL_PRIVDEFENA_Pos) /*!< MPU CTRL: PRIVDEFENA Mask */ + +#define MPU_CTRL_HFNMIENA_Pos 1U /*!< MPU CTRL: HFNMIENA Position */ +#define MPU_CTRL_HFNMIENA_Msk (1UL << MPU_CTRL_HFNMIENA_Pos) /*!< MPU CTRL: HFNMIENA Mask */ + +#define MPU_CTRL_ENABLE_Pos 0U /*!< MPU CTRL: ENABLE Position */ +#define MPU_CTRL_ENABLE_Msk (1UL /*<< MPU_CTRL_ENABLE_Pos*/) /*!< MPU CTRL: ENABLE Mask */ + +/* MPU Region Number Register Definitions */ +#define MPU_RNR_REGION_Pos 0U /*!< MPU RNR: REGION Position */ +#define MPU_RNR_REGION_Msk (0xFFUL /*<< MPU_RNR_REGION_Pos*/) /*!< MPU RNR: REGION Mask */ + +/* MPU Region Base Address Register Definitions */ +#define MPU_RBAR_BASE_Pos 5U /*!< MPU RBAR: BASE Position */ +#define MPU_RBAR_BASE_Msk (0x7FFFFFFUL << MPU_RBAR_BASE_Pos) /*!< MPU RBAR: BASE Mask */ + +#define MPU_RBAR_SH_Pos 3U /*!< MPU RBAR: SH Position */ +#define MPU_RBAR_SH_Msk (0x3UL << MPU_RBAR_SH_Pos) /*!< MPU RBAR: SH Mask */ + +#define MPU_RBAR_AP_Pos 1U /*!< MPU RBAR: AP Position */ +#define MPU_RBAR_AP_Msk (0x3UL << MPU_RBAR_AP_Pos) /*!< MPU RBAR: AP Mask */ + +#define MPU_RBAR_XN_Pos 0U /*!< MPU RBAR: XN Position */ +#define MPU_RBAR_XN_Msk (01UL /*<< MPU_RBAR_XN_Pos*/) /*!< MPU RBAR: XN Mask */ + +/* MPU Region Limit Address Register Definitions */ +#define MPU_RLAR_LIMIT_Pos 5U /*!< MPU RLAR: LIMIT Position */ +#define MPU_RLAR_LIMIT_Msk (0x7FFFFFFUL << MPU_RLAR_LIMIT_Pos) /*!< MPU RLAR: LIMIT Mask */ + +#define MPU_RLAR_PXN_Pos 4U /*!< MPU RLAR: PXN Position */ +#define MPU_RLAR_PXN_Msk (1UL << MPU_RLAR_PXN_Pos) /*!< MPU RLAR: PXN Mask */ + +#define MPU_RLAR_AttrIndx_Pos 1U /*!< MPU RLAR: AttrIndx Position */ +#define MPU_RLAR_AttrIndx_Msk (7UL << MPU_RLAR_AttrIndx_Pos) /*!< MPU RLAR: AttrIndx Mask */ + +#define MPU_RLAR_EN_Pos 0U /*!< MPU RLAR: Region enable bit Position */ +#define MPU_RLAR_EN_Msk (1UL /*<< MPU_RLAR_EN_Pos*/) /*!< MPU RLAR: Region enable bit Disable Mask */ + +/* MPU Memory Attribute Indirection Register 0 Definitions */ +#define MPU_MAIR0_Attr3_Pos 24U /*!< MPU MAIR0: Attr3 Position */ +#define MPU_MAIR0_Attr3_Msk (0xFFUL << MPU_MAIR0_Attr3_Pos) /*!< MPU MAIR0: Attr3 Mask */ + +#define MPU_MAIR0_Attr2_Pos 16U /*!< MPU MAIR0: Attr2 Position */ +#define MPU_MAIR0_Attr2_Msk (0xFFUL << MPU_MAIR0_Attr2_Pos) /*!< MPU MAIR0: Attr2 Mask */ + +#define MPU_MAIR0_Attr1_Pos 8U /*!< MPU MAIR0: Attr1 Position */ +#define MPU_MAIR0_Attr1_Msk (0xFFUL << MPU_MAIR0_Attr1_Pos) /*!< MPU MAIR0: Attr1 Mask */ + +#define MPU_MAIR0_Attr0_Pos 0U /*!< MPU MAIR0: Attr0 Position */ +#define MPU_MAIR0_Attr0_Msk (0xFFUL /*<< MPU_MAIR0_Attr0_Pos*/) /*!< MPU MAIR0: Attr0 Mask */ + +/* MPU Memory Attribute Indirection Register 1 Definitions */ +#define MPU_MAIR1_Attr7_Pos 24U /*!< MPU MAIR1: Attr7 Position */ +#define MPU_MAIR1_Attr7_Msk (0xFFUL << MPU_MAIR1_Attr7_Pos) /*!< MPU MAIR1: Attr7 Mask */ + +#define MPU_MAIR1_Attr6_Pos 16U /*!< MPU MAIR1: Attr6 Position */ +#define MPU_MAIR1_Attr6_Msk (0xFFUL << MPU_MAIR1_Attr6_Pos) /*!< MPU MAIR1: Attr6 Mask */ + +#define MPU_MAIR1_Attr5_Pos 8U /*!< MPU MAIR1: Attr5 Position */ +#define MPU_MAIR1_Attr5_Msk (0xFFUL << MPU_MAIR1_Attr5_Pos) /*!< MPU MAIR1: Attr5 Mask */ + +#define MPU_MAIR1_Attr4_Pos 0U /*!< MPU MAIR1: Attr4 Position */ +#define MPU_MAIR1_Attr4_Msk (0xFFUL /*<< MPU_MAIR1_Attr4_Pos*/) /*!< MPU MAIR1: Attr4 Mask */ + +/*@} end of group CMSIS_MPU */ +#endif + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_SAU Security Attribution Unit (SAU) + \brief Type definitions for the Security Attribution Unit (SAU) + @{ + */ + +/** + \brief Structure type to access the Security Attribution Unit (SAU). + */ +typedef struct +{ + __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) SAU Control Register */ + __IM uint32_t TYPE; /*!< Offset: 0x004 (R/ ) SAU Type Register */ +#if defined (__SAUREGION_PRESENT) && (__SAUREGION_PRESENT == 1U) + __IOM uint32_t RNR; /*!< Offset: 0x008 (R/W) SAU Region Number Register */ + __IOM uint32_t RBAR; /*!< Offset: 0x00C (R/W) SAU Region Base Address Register */ + __IOM uint32_t RLAR; /*!< Offset: 0x010 (R/W) SAU Region Limit Address Register */ +#else + uint32_t RESERVED0[3]; +#endif + __IOM uint32_t SFSR; /*!< Offset: 0x014 (R/W) Secure Fault Status Register */ + __IOM uint32_t SFAR; /*!< Offset: 0x018 (R/W) Secure Fault Address Register */ +} SAU_Type; + +/* SAU Control Register Definitions */ +#define SAU_CTRL_ALLNS_Pos 1U /*!< SAU CTRL: ALLNS Position */ +#define SAU_CTRL_ALLNS_Msk (1UL << SAU_CTRL_ALLNS_Pos) /*!< SAU CTRL: ALLNS Mask */ + +#define SAU_CTRL_ENABLE_Pos 0U /*!< SAU CTRL: ENABLE Position */ +#define SAU_CTRL_ENABLE_Msk (1UL /*<< SAU_CTRL_ENABLE_Pos*/) /*!< SAU CTRL: ENABLE Mask */ + +/* SAU Type Register Definitions */ +#define SAU_TYPE_SREGION_Pos 0U /*!< SAU TYPE: SREGION Position */ +#define SAU_TYPE_SREGION_Msk (0xFFUL /*<< SAU_TYPE_SREGION_Pos*/) /*!< SAU TYPE: SREGION Mask */ + +#if defined (__SAUREGION_PRESENT) && (__SAUREGION_PRESENT == 1U) +/* SAU Region Number Register Definitions */ +#define SAU_RNR_REGION_Pos 0U /*!< SAU RNR: REGION Position */ +#define SAU_RNR_REGION_Msk (0xFFUL /*<< SAU_RNR_REGION_Pos*/) /*!< SAU RNR: REGION Mask */ + +/* SAU Region Base Address Register Definitions */ +#define SAU_RBAR_BADDR_Pos 5U /*!< SAU RBAR: BADDR Position */ +#define SAU_RBAR_BADDR_Msk (0x7FFFFFFUL << SAU_RBAR_BADDR_Pos) /*!< SAU RBAR: BADDR Mask */ + +/* SAU Region Limit Address Register Definitions */ +#define SAU_RLAR_LADDR_Pos 5U /*!< SAU RLAR: LADDR Position */ +#define SAU_RLAR_LADDR_Msk (0x7FFFFFFUL << SAU_RLAR_LADDR_Pos) /*!< SAU RLAR: LADDR Mask */ + +#define SAU_RLAR_NSC_Pos 1U /*!< SAU RLAR: NSC Position */ +#define SAU_RLAR_NSC_Msk (1UL << SAU_RLAR_NSC_Pos) /*!< SAU RLAR: NSC Mask */ + +#define SAU_RLAR_ENABLE_Pos 0U /*!< SAU RLAR: ENABLE Position */ +#define SAU_RLAR_ENABLE_Msk (1UL /*<< SAU_RLAR_ENABLE_Pos*/) /*!< SAU RLAR: ENABLE Mask */ + +#endif /* defined (__SAUREGION_PRESENT) && (__SAUREGION_PRESENT == 1U) */ + +/* Secure Fault Status Register Definitions */ +#define SAU_SFSR_LSERR_Pos 7U /*!< SAU SFSR: LSERR Position */ +#define SAU_SFSR_LSERR_Msk (1UL << SAU_SFSR_LSERR_Pos) /*!< SAU SFSR: LSERR Mask */ + +#define SAU_SFSR_SFARVALID_Pos 6U /*!< SAU SFSR: SFARVALID Position */ +#define SAU_SFSR_SFARVALID_Msk (1UL << SAU_SFSR_SFARVALID_Pos) /*!< SAU SFSR: SFARVALID Mask */ + +#define SAU_SFSR_LSPERR_Pos 5U /*!< SAU SFSR: LSPERR Position */ +#define SAU_SFSR_LSPERR_Msk (1UL << SAU_SFSR_LSPERR_Pos) /*!< SAU SFSR: LSPERR Mask */ + +#define SAU_SFSR_INVTRAN_Pos 4U /*!< SAU SFSR: INVTRAN Position */ +#define SAU_SFSR_INVTRAN_Msk (1UL << SAU_SFSR_INVTRAN_Pos) /*!< SAU SFSR: INVTRAN Mask */ + +#define SAU_SFSR_AUVIOL_Pos 3U /*!< SAU SFSR: AUVIOL Position */ +#define SAU_SFSR_AUVIOL_Msk (1UL << SAU_SFSR_AUVIOL_Pos) /*!< SAU SFSR: AUVIOL Mask */ + +#define SAU_SFSR_INVER_Pos 2U /*!< SAU SFSR: INVER Position */ +#define SAU_SFSR_INVER_Msk (1UL << SAU_SFSR_INVER_Pos) /*!< SAU SFSR: INVER Mask */ + +#define SAU_SFSR_INVIS_Pos 1U /*!< SAU SFSR: INVIS Position */ +#define SAU_SFSR_INVIS_Msk (1UL << SAU_SFSR_INVIS_Pos) /*!< SAU SFSR: INVIS Mask */ + +#define SAU_SFSR_INVEP_Pos 0U /*!< SAU SFSR: INVEP Position */ +#define SAU_SFSR_INVEP_Msk (1UL /*<< SAU_SFSR_INVEP_Pos*/) /*!< SAU SFSR: INVEP Mask */ + +/*@} end of group CMSIS_SAU */ +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_FPU Floating Point Unit (FPU) + \brief Type definitions for the Floating Point Unit (FPU) + @{ + */ + +/** + \brief Structure type to access the Floating Point Unit (FPU). + */ +typedef struct +{ + uint32_t RESERVED0[1U]; + __IOM uint32_t FPCCR; /*!< Offset: 0x004 (R/W) Floating-Point Context Control Register */ + __IOM uint32_t FPCAR; /*!< Offset: 0x008 (R/W) Floating-Point Context Address Register */ + __IOM uint32_t FPDSCR; /*!< Offset: 0x00C (R/W) Floating-Point Default Status Control Register */ + __IM uint32_t MVFR0; /*!< Offset: 0x010 (R/ ) Media and VFP Feature Register 0 */ + __IM uint32_t MVFR1; /*!< Offset: 0x014 (R/ ) Media and VFP Feature Register 1 */ + __IM uint32_t MVFR2; /*!< Offset: 0x018 (R/ ) Media and VFP Feature Register 2 */ +} FPU_Type; + +/* Floating-Point Context Control Register Definitions */ +#define FPU_FPCCR_ASPEN_Pos 31U /*!< FPCCR: ASPEN bit Position */ +#define FPU_FPCCR_ASPEN_Msk (1UL << FPU_FPCCR_ASPEN_Pos) /*!< FPCCR: ASPEN bit Mask */ + +#define FPU_FPCCR_LSPEN_Pos 30U /*!< FPCCR: LSPEN Position */ +#define FPU_FPCCR_LSPEN_Msk (1UL << FPU_FPCCR_LSPEN_Pos) /*!< FPCCR: LSPEN bit Mask */ + +#define FPU_FPCCR_LSPENS_Pos 29U /*!< FPCCR: LSPENS Position */ +#define FPU_FPCCR_LSPENS_Msk (1UL << FPU_FPCCR_LSPENS_Pos) /*!< FPCCR: LSPENS bit Mask */ + +#define FPU_FPCCR_CLRONRET_Pos 28U /*!< FPCCR: CLRONRET Position */ +#define FPU_FPCCR_CLRONRET_Msk (1UL << FPU_FPCCR_CLRONRET_Pos) /*!< FPCCR: CLRONRET bit Mask */ + +#define FPU_FPCCR_CLRONRETS_Pos 27U /*!< FPCCR: CLRONRETS Position */ +#define FPU_FPCCR_CLRONRETS_Msk (1UL << FPU_FPCCR_CLRONRETS_Pos) /*!< FPCCR: CLRONRETS bit Mask */ + +#define FPU_FPCCR_TS_Pos 26U /*!< FPCCR: TS Position */ +#define FPU_FPCCR_TS_Msk (1UL << FPU_FPCCR_TS_Pos) /*!< FPCCR: TS bit Mask */ + +#define FPU_FPCCR_UFRDY_Pos 10U /*!< FPCCR: UFRDY Position */ +#define FPU_FPCCR_UFRDY_Msk (1UL << FPU_FPCCR_UFRDY_Pos) /*!< FPCCR: UFRDY bit Mask */ + +#define FPU_FPCCR_SPLIMVIOL_Pos 9U /*!< FPCCR: SPLIMVIOL Position */ +#define FPU_FPCCR_SPLIMVIOL_Msk (1UL << FPU_FPCCR_SPLIMVIOL_Pos) /*!< FPCCR: SPLIMVIOL bit Mask */ + +#define FPU_FPCCR_MONRDY_Pos 8U /*!< FPCCR: MONRDY Position */ +#define FPU_FPCCR_MONRDY_Msk (1UL << FPU_FPCCR_MONRDY_Pos) /*!< FPCCR: MONRDY bit Mask */ + +#define FPU_FPCCR_SFRDY_Pos 7U /*!< FPCCR: SFRDY Position */ +#define FPU_FPCCR_SFRDY_Msk (1UL << FPU_FPCCR_SFRDY_Pos) /*!< FPCCR: SFRDY bit Mask */ + +#define FPU_FPCCR_BFRDY_Pos 6U /*!< FPCCR: BFRDY Position */ +#define FPU_FPCCR_BFRDY_Msk (1UL << FPU_FPCCR_BFRDY_Pos) /*!< FPCCR: BFRDY bit Mask */ + +#define FPU_FPCCR_MMRDY_Pos 5U /*!< FPCCR: MMRDY Position */ +#define FPU_FPCCR_MMRDY_Msk (1UL << FPU_FPCCR_MMRDY_Pos) /*!< FPCCR: MMRDY bit Mask */ + +#define FPU_FPCCR_HFRDY_Pos 4U /*!< FPCCR: HFRDY Position */ +#define FPU_FPCCR_HFRDY_Msk (1UL << FPU_FPCCR_HFRDY_Pos) /*!< FPCCR: HFRDY bit Mask */ + +#define FPU_FPCCR_THREAD_Pos 3U /*!< FPCCR: processor mode bit Position */ +#define FPU_FPCCR_THREAD_Msk (1UL << FPU_FPCCR_THREAD_Pos) /*!< FPCCR: processor mode active bit Mask */ + +#define FPU_FPCCR_S_Pos 2U /*!< FPCCR: Security status of the FP context bit Position */ +#define FPU_FPCCR_S_Msk (1UL << FPU_FPCCR_S_Pos) /*!< FPCCR: Security status of the FP context bit Mask */ + +#define FPU_FPCCR_USER_Pos 1U /*!< FPCCR: privilege level bit Position */ +#define FPU_FPCCR_USER_Msk (1UL << FPU_FPCCR_USER_Pos) /*!< FPCCR: privilege level bit Mask */ + +#define FPU_FPCCR_LSPACT_Pos 0U /*!< FPCCR: Lazy state preservation active bit Position */ +#define FPU_FPCCR_LSPACT_Msk (1UL /*<< FPU_FPCCR_LSPACT_Pos*/) /*!< FPCCR: Lazy state preservation active bit Mask */ + +/* Floating-Point Context Address Register Definitions */ +#define FPU_FPCAR_ADDRESS_Pos 3U /*!< FPCAR: ADDRESS bit Position */ +#define FPU_FPCAR_ADDRESS_Msk (0x1FFFFFFFUL << FPU_FPCAR_ADDRESS_Pos) /*!< FPCAR: ADDRESS bit Mask */ + +/* Floating-Point Default Status Control Register Definitions */ +#define FPU_FPDSCR_AHP_Pos 26U /*!< FPDSCR: AHP bit Position */ +#define FPU_FPDSCR_AHP_Msk (1UL << FPU_FPDSCR_AHP_Pos) /*!< FPDSCR: AHP bit Mask */ + +#define FPU_FPDSCR_DN_Pos 25U /*!< FPDSCR: DN bit Position */ +#define FPU_FPDSCR_DN_Msk (1UL << FPU_FPDSCR_DN_Pos) /*!< FPDSCR: DN bit Mask */ + +#define FPU_FPDSCR_FZ_Pos 24U /*!< FPDSCR: FZ bit Position */ +#define FPU_FPDSCR_FZ_Msk (1UL << FPU_FPDSCR_FZ_Pos) /*!< FPDSCR: FZ bit Mask */ + +#define FPU_FPDSCR_RMode_Pos 22U /*!< FPDSCR: RMode bit Position */ +#define FPU_FPDSCR_RMode_Msk (3UL << FPU_FPDSCR_RMode_Pos) /*!< FPDSCR: RMode bit Mask */ + +#define FPU_FPDSCR_FZ16_Pos 19U /*!< FPDSCR: FZ16 bit Position */ +#define FPU_FPDSCR_FZ16_Msk (1UL << FPU_FPDSCR_FZ16_Pos) /*!< FPDSCR: FZ16 bit Mask */ + +#define FPU_FPDSCR_LTPSIZE_Pos 16U /*!< FPDSCR: LTPSIZE bit Position */ +#define FPU_FPDSCR_LTPSIZE_Msk (7UL << FPU_FPDSCR_LTPSIZE_Pos) /*!< FPDSCR: LTPSIZE bit Mask */ + +/* Media and VFP Feature Register 0 Definitions */ +#define FPU_MVFR0_FPRound_Pos 28U /*!< MVFR0: FPRound bits Position */ +#define FPU_MVFR0_FPRound_Msk (0xFUL << FPU_MVFR0_FPRound_Pos) /*!< MVFR0: FPRound bits Mask */ + +#define FPU_MVFR0_FPSqrt_Pos 20U /*!< MVFR0: FPSqrt bits Position */ +#define FPU_MVFR0_FPSqrt_Msk (0xFUL << FPU_MVFR0_FPSqrt_Pos) /*!< MVFR0: FPSqrt bits Mask */ + +#define FPU_MVFR0_FPDivide_Pos 16U /*!< MVFR0: FPDivide bits Position */ +#define FPU_MVFR0_FPDivide_Msk (0xFUL << FPU_MVFR0_FPDivide_Pos) /*!< MVFR0: Divide bits Mask */ + +#define FPU_MVFR0_FPDP_Pos 8U /*!< MVFR0: FPDP bits Position */ +#define FPU_MVFR0_FPDP_Msk (0xFUL << FPU_MVFR0_FPDP_Pos) /*!< MVFR0: FPDP bits Mask */ + +#define FPU_MVFR0_FPSP_Pos 4U /*!< MVFR0: FPSP bits Position */ +#define FPU_MVFR0_FPSP_Msk (0xFUL << FPU_MVFR0_FPSP_Pos) /*!< MVFR0: FPSP bits Mask */ + +#define FPU_MVFR0_SIMDReg_Pos 0U /*!< MVFR0: SIMDReg bits Position */ +#define FPU_MVFR0_SIMDReg_Msk (0xFUL /*<< FPU_MVFR0_SIMDReg_Pos*/) /*!< MVFR0: SIMDReg bits Mask */ + +/* Media and VFP Feature Register 1 Definitions */ +#define FPU_MVFR1_FMAC_Pos 28U /*!< MVFR1: FMAC bits Position */ +#define FPU_MVFR1_FMAC_Msk (0xFUL << FPU_MVFR1_FMAC_Pos) /*!< MVFR1: FMAC bits Mask */ + +#define FPU_MVFR1_FPHP_Pos 24U /*!< MVFR1: FPHP bits Position */ +#define FPU_MVFR1_FPHP_Msk (0xFUL << FPU_MVFR1_FPHP_Pos) /*!< MVFR1: FPHP bits Mask */ + +#define FPU_MVFR1_FP16_Pos 20U /*!< MVFR1: FP16 bits Position */ +#define FPU_MVFR1_FP16_Msk (0xFUL << FPU_MVFR1_FP16_Pos) /*!< MVFR1: FP16 bits Mask */ + +#define FPU_MVFR1_MVE_Pos 8U /*!< MVFR1: MVE bits Position */ +#define FPU_MVFR1_MVE_Msk (0xFUL << FPU_MVFR1_MVE_Pos) /*!< MVFR1: MVE bits Mask */ + +#define FPU_MVFR1_FPDNaN_Pos 4U /*!< MVFR1: FPDNaN bits Position */ +#define FPU_MVFR1_FPDNaN_Msk (0xFUL << FPU_MVFR1_FPDNaN_Pos) /*!< MVFR1: FPDNaN bits Mask */ + +#define FPU_MVFR1_FPFtZ_Pos 0U /*!< MVFR1: FPFtZ bits Position */ +#define FPU_MVFR1_FPFtZ_Msk (0xFUL /*<< FPU_MVFR1_FPFtZ_Pos*/) /*!< MVFR1: FPFtZ bits Mask */ + +/* Media and VFP Feature Register 2 Definitions */ +#define FPU_MVFR2_FPMisc_Pos 4U /*!< MVFR2: FPMisc bits Position */ +#define FPU_MVFR2_FPMisc_Msk (0xFUL << FPU_MVFR2_FPMisc_Pos) /*!< MVFR2: FPMisc bits Mask */ + +/*@} end of group CMSIS_FPU */ + +/* CoreDebug is deprecated. replaced by DCB (Debug Control Block) */ +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug) + \brief Type definitions for the Core Debug Registers + @{ + */ + +/** + \brief \deprecated Structure type to access the Core Debug Register (CoreDebug). + */ +typedef struct +{ + __IOM uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */ + __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ + __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ + __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ + __OM uint32_t DSCEMCR; /*!< Offset: 0x010 ( /W) Debug Set Clear Exception and Monitor Control Register */ + __IOM uint32_t DAUTHCTRL; /*!< Offset: 0x014 (R/W) Debug Authentication Control Register */ + __IOM uint32_t DSCSR; /*!< Offset: 0x018 (R/W) Debug Security Control and Status Register */ +} CoreDebug_Type; + +/* Debug Halting Control and Status Register Definitions */ +#define CoreDebug_DHCSR_DBGKEY_Pos 16U /*!< \deprecated CoreDebug DHCSR: DBGKEY Position */ +#define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos) /*!< \deprecated CoreDebug DHCSR: DBGKEY Mask */ + +#define CoreDebug_DHCSR_S_RESTART_ST_Pos 26U /*!< \deprecated CoreDebug DHCSR: S_RESTART_ST Position */ +#define CoreDebug_DHCSR_S_RESTART_ST_Msk (1UL << CoreDebug_DHCSR_S_RESTART_ST_Pos) /*!< \deprecated CoreDebug DHCSR: S_RESTART_ST Mask */ + +#define CoreDebug_DHCSR_S_RESET_ST_Pos 25U /*!< \deprecated CoreDebug DHCSR: S_RESET_ST Position */ +#define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< \deprecated CoreDebug DHCSR: S_RESET_ST Mask */ + +#define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24U /*!< \deprecated CoreDebug DHCSR: S_RETIRE_ST Position */ +#define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< \deprecated CoreDebug DHCSR: S_RETIRE_ST Mask */ + +#define CoreDebug_DHCSR_S_FPD_Pos 23U /*!< \deprecated CoreDebug DHCSR: S_FPD Position */ +#define CoreDebug_DHCSR_S_FPD_Msk (1UL << CoreDebug_DHCSR_S_FPD_Pos) /*!< \deprecated CoreDebug DHCSR: S_FPD Mask */ + +#define CoreDebug_DHCSR_S_SUIDE_Pos 22U /*!< \deprecated CoreDebug DHCSR: S_SUIDE Position */ +#define CoreDebug_DHCSR_S_SUIDE_Msk (1UL << CoreDebug_DHCSR_S_SUIDE_Pos) /*!< \deprecated CoreDebug DHCSR: S_SUIDE Mask */ + +#define CoreDebug_DHCSR_S_NSUIDE_Pos 21U /*!< \deprecated CoreDebug DHCSR: S_NSUIDE Position */ +#define CoreDebug_DHCSR_S_NSUIDE_Msk (1UL << CoreDebug_DHCSR_S_NSUIDE_Pos) /*!< \deprecated CoreDebug DHCSR: S_NSUIDE Mask */ + +#define CoreDebug_DHCSR_S_SDE_Pos 20U /*!< \deprecated CoreDebug DHCSR: S_SDE Position */ +#define CoreDebug_DHCSR_S_SDE_Msk (1UL << CoreDebug_DHCSR_S_SDE_Pos) /*!< \deprecated CoreDebug DHCSR: S_SDE Mask */ + +#define CoreDebug_DHCSR_S_LOCKUP_Pos 19U /*!< \deprecated CoreDebug DHCSR: S_LOCKUP Position */ +#define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< \deprecated CoreDebug DHCSR: S_LOCKUP Mask */ + +#define CoreDebug_DHCSR_S_SLEEP_Pos 18U /*!< \deprecated CoreDebug DHCSR: S_SLEEP Position */ +#define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< \deprecated CoreDebug DHCSR: S_SLEEP Mask */ + +#define CoreDebug_DHCSR_S_HALT_Pos 17U /*!< \deprecated CoreDebug DHCSR: S_HALT Position */ +#define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos) /*!< \deprecated CoreDebug DHCSR: S_HALT Mask */ + +#define CoreDebug_DHCSR_S_REGRDY_Pos 16U /*!< \deprecated CoreDebug DHCSR: S_REGRDY Position */ +#define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< \deprecated CoreDebug DHCSR: S_REGRDY Mask */ + +#define CoreDebug_DHCSR_C_PMOV_Pos 6U /*!< \deprecated CoreDebug DHCSR: C_PMOV Position */ +#define CoreDebug_DHCSR_C_PMOV_Msk (1UL << CoreDebug_DHCSR_C_PMOV_Pos) /*!< \deprecated CoreDebug DHCSR: C_PMOV Mask */ + +#define CoreDebug_DHCSR_C_SNAPSTALL_Pos 5U /*!< \deprecated CoreDebug DHCSR: C_SNAPSTALL Position */ +#define CoreDebug_DHCSR_C_SNAPSTALL_Msk (1UL << CoreDebug_DHCSR_C_SNAPSTALL_Pos) /*!< \deprecated CoreDebug DHCSR: C_SNAPSTALL Mask */ + +#define CoreDebug_DHCSR_C_MASKINTS_Pos 3U /*!< \deprecated CoreDebug DHCSR: C_MASKINTS Position */ +#define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< \deprecated CoreDebug DHCSR: C_MASKINTS Mask */ + +#define CoreDebug_DHCSR_C_STEP_Pos 2U /*!< \deprecated CoreDebug DHCSR: C_STEP Position */ +#define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos) /*!< \deprecated CoreDebug DHCSR: C_STEP Mask */ + +#define CoreDebug_DHCSR_C_HALT_Pos 1U /*!< \deprecated CoreDebug DHCSR: C_HALT Position */ +#define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos) /*!< \deprecated CoreDebug DHCSR: C_HALT Mask */ + +#define CoreDebug_DHCSR_C_DEBUGEN_Pos 0U /*!< \deprecated CoreDebug DHCSR: C_DEBUGEN Position */ +#define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL /*<< CoreDebug_DHCSR_C_DEBUGEN_Pos*/) /*!< \deprecated CoreDebug DHCSR: C_DEBUGEN Mask */ + +/* Debug Core Register Selector Register Definitions */ +#define CoreDebug_DCRSR_REGWnR_Pos 16U /*!< \deprecated CoreDebug DCRSR: REGWnR Position */ +#define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos) /*!< \deprecated CoreDebug DCRSR: REGWnR Mask */ + +#define CoreDebug_DCRSR_REGSEL_Pos 0U /*!< \deprecated CoreDebug DCRSR: REGSEL Position */ +#define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL /*<< CoreDebug_DCRSR_REGSEL_Pos*/) /*!< \deprecated CoreDebug DCRSR: REGSEL Mask */ + +/* Debug Exception and Monitor Control Register Definitions */ +#define CoreDebug_DEMCR_TRCENA_Pos 24U /*!< \deprecated CoreDebug DEMCR: TRCENA Position */ +#define CoreDebug_DEMCR_TRCENA_Msk (1UL << CoreDebug_DEMCR_TRCENA_Pos) /*!< \deprecated CoreDebug DEMCR: TRCENA Mask */ + +#define CoreDebug_DEMCR_MON_REQ_Pos 19U /*!< \deprecated CoreDebug DEMCR: MON_REQ Position */ +#define CoreDebug_DEMCR_MON_REQ_Msk (1UL << CoreDebug_DEMCR_MON_REQ_Pos) /*!< \deprecated CoreDebug DEMCR: MON_REQ Mask */ + +#define CoreDebug_DEMCR_MON_STEP_Pos 18U /*!< \deprecated CoreDebug DEMCR: MON_STEP Position */ +#define CoreDebug_DEMCR_MON_STEP_Msk (1UL << CoreDebug_DEMCR_MON_STEP_Pos) /*!< \deprecated CoreDebug DEMCR: MON_STEP Mask */ + +#define CoreDebug_DEMCR_MON_PEND_Pos 17U /*!< \deprecated CoreDebug DEMCR: MON_PEND Position */ +#define CoreDebug_DEMCR_MON_PEND_Msk (1UL << CoreDebug_DEMCR_MON_PEND_Pos) /*!< \deprecated CoreDebug DEMCR: MON_PEND Mask */ + +#define CoreDebug_DEMCR_MON_EN_Pos 16U /*!< \deprecated CoreDebug DEMCR: MON_EN Position */ +#define CoreDebug_DEMCR_MON_EN_Msk (1UL << CoreDebug_DEMCR_MON_EN_Pos) /*!< \deprecated CoreDebug DEMCR: MON_EN Mask */ + +#define CoreDebug_DEMCR_VC_HARDERR_Pos 10U /*!< \deprecated CoreDebug DEMCR: VC_HARDERR Position */ +#define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_HARDERR Mask */ + +#define CoreDebug_DEMCR_VC_INTERR_Pos 9U /*!< \deprecated CoreDebug DEMCR: VC_INTERR Position */ +#define CoreDebug_DEMCR_VC_INTERR_Msk (1UL << CoreDebug_DEMCR_VC_INTERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_INTERR Mask */ + +#define CoreDebug_DEMCR_VC_BUSERR_Pos 8U /*!< \deprecated CoreDebug DEMCR: VC_BUSERR Position */ +#define CoreDebug_DEMCR_VC_BUSERR_Msk (1UL << CoreDebug_DEMCR_VC_BUSERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_BUSERR Mask */ + +#define CoreDebug_DEMCR_VC_STATERR_Pos 7U /*!< \deprecated CoreDebug DEMCR: VC_STATERR Position */ +#define CoreDebug_DEMCR_VC_STATERR_Msk (1UL << CoreDebug_DEMCR_VC_STATERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_STATERR Mask */ + +#define CoreDebug_DEMCR_VC_CHKERR_Pos 6U /*!< \deprecated CoreDebug DEMCR: VC_CHKERR Position */ +#define CoreDebug_DEMCR_VC_CHKERR_Msk (1UL << CoreDebug_DEMCR_VC_CHKERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_CHKERR Mask */ + +#define CoreDebug_DEMCR_VC_NOCPERR_Pos 5U /*!< \deprecated CoreDebug DEMCR: VC_NOCPERR Position */ +#define CoreDebug_DEMCR_VC_NOCPERR_Msk (1UL << CoreDebug_DEMCR_VC_NOCPERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_NOCPERR Mask */ + +#define CoreDebug_DEMCR_VC_MMERR_Pos 4U /*!< \deprecated CoreDebug DEMCR: VC_MMERR Position */ +#define CoreDebug_DEMCR_VC_MMERR_Msk (1UL << CoreDebug_DEMCR_VC_MMERR_Pos) /*!< \deprecated CoreDebug DEMCR: VC_MMERR Mask */ + +#define CoreDebug_DEMCR_VC_CORERESET_Pos 0U /*!< \deprecated CoreDebug DEMCR: VC_CORERESET Position */ +#define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL /*<< CoreDebug_DEMCR_VC_CORERESET_Pos*/) /*!< \deprecated CoreDebug DEMCR: VC_CORERESET Mask */ + +/* Debug Set Clear Exception and Monitor Control Register Definitions */ +#define CoreDebug_DSCEMCR_CLR_MON_REQ_Pos 19U /*!< \deprecated CoreDebug DSCEMCR: CLR_MON_REQ, Position */ +#define CoreDebug_DSCEMCR_CLR_MON_REQ_Msk (1UL << CoreDebug_DSCEMCR_CLR_MON_REQ_Pos) /*!< \deprecated CoreDebug DSCEMCR: CLR_MON_REQ, Mask */ + +#define CoreDebug_DSCEMCR_CLR_MON_PEND_Pos 17U /*!< \deprecated CoreDebug DSCEMCR: CLR_MON_PEND, Position */ +#define CoreDebug_DSCEMCR_CLR_MON_PEND_Msk (1UL << CoreDebug_DSCEMCR_CLR_MON_PEND_Pos) /*!< \deprecated CoreDebug DSCEMCR: CLR_MON_PEND, Mask */ + +#define CoreDebug_DSCEMCR_SET_MON_REQ_Pos 3U /*!< \deprecated CoreDebug DSCEMCR: SET_MON_REQ, Position */ +#define CoreDebug_DSCEMCR_SET_MON_REQ_Msk (1UL << CoreDebug_DSCEMCR_SET_MON_REQ_Pos) /*!< \deprecated CoreDebug DSCEMCR: SET_MON_REQ, Mask */ + +#define CoreDebug_DSCEMCR_SET_MON_PEND_Pos 1U /*!< \deprecated CoreDebug DSCEMCR: SET_MON_PEND, Position */ +#define CoreDebug_DSCEMCR_SET_MON_PEND_Msk (1UL << CoreDebug_DSCEMCR_SET_MON_PEND_Pos) /*!< \deprecated CoreDebug DSCEMCR: SET_MON_PEND, Mask */ + +/* Debug Authentication Control Register Definitions */ +#define CoreDebug_DAUTHCTRL_UIDEN_Pos 10U /*!< \deprecated CoreDebug DAUTHCTRL: UIDEN, Position */ +#define CoreDebug_DAUTHCTRL_UIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_UIDEN_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: UIDEN, Mask */ + +#define CoreDebug_DAUTHCTRL_UIDAPEN_Pos 9U /*!< \deprecated CoreDebug DAUTHCTRL: UIDAPEN, Position */ +#define CoreDebug_DAUTHCTRL_UIDAPEN_Msk (1UL << CoreDebug_DAUTHCTRL_UIDAPEN_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: UIDAPEN, Mask */ + +#define CoreDebug_DAUTHCTRL_FSDMA_Pos 8U /*!< \deprecated CoreDebug DAUTHCTRL: FSDMA, Position */ +#define CoreDebug_DAUTHCTRL_FSDMA_Msk (1UL << CoreDebug_DAUTHCTRL_FSDMA_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: FSDMA, Mask */ + +#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos 3U /*!< \deprecated CoreDebug DAUTHCTRL: INTSPNIDEN, Position */ +#define CoreDebug_DAUTHCTRL_INTSPNIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPNIDEN_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: INTSPNIDEN, Mask */ + +#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos 2U /*!< \deprecated CoreDebug DAUTHCTRL: SPNIDENSEL Position */ +#define CoreDebug_DAUTHCTRL_SPNIDENSEL_Msk (1UL << CoreDebug_DAUTHCTRL_SPNIDENSEL_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: SPNIDENSEL Mask */ + +#define CoreDebug_DAUTHCTRL_INTSPIDEN_Pos 1U /*!< \deprecated CoreDebug DAUTHCTRL: INTSPIDEN Position */ +#define CoreDebug_DAUTHCTRL_INTSPIDEN_Msk (1UL << CoreDebug_DAUTHCTRL_INTSPIDEN_Pos) /*!< \deprecated CoreDebug DAUTHCTRL: INTSPIDEN Mask */ + +#define CoreDebug_DAUTHCTRL_SPIDENSEL_Pos 0U /*!< \deprecated CoreDebug DAUTHCTRL: SPIDENSEL Position */ +#define CoreDebug_DAUTHCTRL_SPIDENSEL_Msk (1UL /*<< CoreDebug_DAUTHCTRL_SPIDENSEL_Pos*/) /*!< \deprecated CoreDebug DAUTHCTRL: SPIDENSEL Mask */ + +/* Debug Security Control and Status Register Definitions */ +#define CoreDebug_DSCSR_CDS_Pos 16U /*!< \deprecated CoreDebug DSCSR: CDS Position */ +#define CoreDebug_DSCSR_CDS_Msk (1UL << CoreDebug_DSCSR_CDS_Pos) /*!< \deprecated CoreDebug DSCSR: CDS Mask */ + +#define CoreDebug_DSCSR_SBRSEL_Pos 1U /*!< \deprecated CoreDebug DSCSR: SBRSEL Position */ +#define CoreDebug_DSCSR_SBRSEL_Msk (1UL << CoreDebug_DSCSR_SBRSEL_Pos) /*!< \deprecated CoreDebug DSCSR: SBRSEL Mask */ + +#define CoreDebug_DSCSR_SBRSELEN_Pos 0U /*!< \deprecated CoreDebug DSCSR: SBRSELEN Position */ +#define CoreDebug_DSCSR_SBRSELEN_Msk (1UL /*<< CoreDebug_DSCSR_SBRSELEN_Pos*/) /*!< \deprecated CoreDebug DSCSR: SBRSELEN Mask */ + +/*@} end of group CMSIS_CoreDebug */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_DCB Debug Control Block + \brief Type definitions for the Debug Control Block Registers + @{ + */ + +/** + \brief Structure type to access the Debug Control Block Registers (DCB). + */ +typedef struct +{ + __IOM uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */ + __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ + __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ + __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ + __OM uint32_t DSCEMCR; /*!< Offset: 0x010 ( /W) Debug Set Clear Exception and Monitor Control Register */ + __IOM uint32_t DAUTHCTRL; /*!< Offset: 0x014 (R/W) Debug Authentication Control Register */ + __IOM uint32_t DSCSR; /*!< Offset: 0x018 (R/W) Debug Security Control and Status Register */ +} DCB_Type; + +/* DHCSR, Debug Halting Control and Status Register Definitions */ +#define DCB_DHCSR_DBGKEY_Pos 16U /*!< DCB DHCSR: Debug key Position */ +#define DCB_DHCSR_DBGKEY_Msk (0xFFFFUL << DCB_DHCSR_DBGKEY_Pos) /*!< DCB DHCSR: Debug key Mask */ + +#define DCB_DHCSR_S_RESTART_ST_Pos 26U /*!< DCB DHCSR: Restart sticky status Position */ +#define DCB_DHCSR_S_RESTART_ST_Msk (0x1UL << DCB_DHCSR_S_RESTART_ST_Pos) /*!< DCB DHCSR: Restart sticky status Mask */ + +#define DCB_DHCSR_S_RESET_ST_Pos 25U /*!< DCB DHCSR: Reset sticky status Position */ +#define DCB_DHCSR_S_RESET_ST_Msk (0x1UL << DCB_DHCSR_S_RESET_ST_Pos) /*!< DCB DHCSR: Reset sticky status Mask */ + +#define DCB_DHCSR_S_RETIRE_ST_Pos 24U /*!< DCB DHCSR: Retire sticky status Position */ +#define DCB_DHCSR_S_RETIRE_ST_Msk (0x1UL << DCB_DHCSR_S_RETIRE_ST_Pos) /*!< DCB DHCSR: Retire sticky status Mask */ + +#define DCB_DHCSR_S_FPD_Pos 23U /*!< DCB DHCSR: Floating-point registers Debuggable Position */ +#define DCB_DHCSR_S_FPD_Msk (0x1UL << DCB_DHCSR_S_FPD_Pos) /*!< DCB DHCSR: Floating-point registers Debuggable Mask */ + +#define DCB_DHCSR_S_SUIDE_Pos 22U /*!< DCB DHCSR: Secure unprivileged halting debug enabled Position */ +#define DCB_DHCSR_S_SUIDE_Msk (0x1UL << DCB_DHCSR_S_SUIDE_Pos) /*!< DCB DHCSR: Secure unprivileged halting debug enabled Mask */ + +#define DCB_DHCSR_S_NSUIDE_Pos 21U /*!< DCB DHCSR: Non-secure unprivileged halting debug enabled Position */ +#define DCB_DHCSR_S_NSUIDE_Msk (0x1UL << DCB_DHCSR_S_NSUIDE_Pos) /*!< DCB DHCSR: Non-secure unprivileged halting debug enabled Mask */ + +#define DCB_DHCSR_S_SDE_Pos 20U /*!< DCB DHCSR: Secure debug enabled Position */ +#define DCB_DHCSR_S_SDE_Msk (0x1UL << DCB_DHCSR_S_SDE_Pos) /*!< DCB DHCSR: Secure debug enabled Mask */ + +#define DCB_DHCSR_S_LOCKUP_Pos 19U /*!< DCB DHCSR: Lockup status Position */ +#define DCB_DHCSR_S_LOCKUP_Msk (0x1UL << DCB_DHCSR_S_LOCKUP_Pos) /*!< DCB DHCSR: Lockup status Mask */ + +#define DCB_DHCSR_S_SLEEP_Pos 18U /*!< DCB DHCSR: Sleeping status Position */ +#define DCB_DHCSR_S_SLEEP_Msk (0x1UL << DCB_DHCSR_S_SLEEP_Pos) /*!< DCB DHCSR: Sleeping status Mask */ + +#define DCB_DHCSR_S_HALT_Pos 17U /*!< DCB DHCSR: Halted status Position */ +#define DCB_DHCSR_S_HALT_Msk (0x1UL << DCB_DHCSR_S_HALT_Pos) /*!< DCB DHCSR: Halted status Mask */ + +#define DCB_DHCSR_S_REGRDY_Pos 16U /*!< DCB DHCSR: Register ready status Position */ +#define DCB_DHCSR_S_REGRDY_Msk (0x1UL << DCB_DHCSR_S_REGRDY_Pos) /*!< DCB DHCSR: Register ready status Mask */ + +#define DCB_DHCSR_C_PMOV_Pos 6U /*!< DCB DHCSR: Halt on PMU overflow control Position */ +#define DCB_DHCSR_C_PMOV_Msk (0x1UL << DCB_DHCSR_C_PMOV_Pos) /*!< DCB DHCSR: Halt on PMU overflow control Mask */ + +#define DCB_DHCSR_C_SNAPSTALL_Pos 5U /*!< DCB DHCSR: Snap stall control Position */ +#define DCB_DHCSR_C_SNAPSTALL_Msk (0x1UL << DCB_DHCSR_C_SNAPSTALL_Pos) /*!< DCB DHCSR: Snap stall control Mask */ + +#define DCB_DHCSR_C_MASKINTS_Pos 3U /*!< DCB DHCSR: Mask interrupts control Position */ +#define DCB_DHCSR_C_MASKINTS_Msk (0x1UL << DCB_DHCSR_C_MASKINTS_Pos) /*!< DCB DHCSR: Mask interrupts control Mask */ + +#define DCB_DHCSR_C_STEP_Pos 2U /*!< DCB DHCSR: Step control Position */ +#define DCB_DHCSR_C_STEP_Msk (0x1UL << DCB_DHCSR_C_STEP_Pos) /*!< DCB DHCSR: Step control Mask */ + +#define DCB_DHCSR_C_HALT_Pos 1U /*!< DCB DHCSR: Halt control Position */ +#define DCB_DHCSR_C_HALT_Msk (0x1UL << DCB_DHCSR_C_HALT_Pos) /*!< DCB DHCSR: Halt control Mask */ + +#define DCB_DHCSR_C_DEBUGEN_Pos 0U /*!< DCB DHCSR: Debug enable control Position */ +#define DCB_DHCSR_C_DEBUGEN_Msk (0x1UL /*<< DCB_DHCSR_C_DEBUGEN_Pos*/) /*!< DCB DHCSR: Debug enable control Mask */ + +/* DCRSR, Debug Core Register Select Register Definitions */ +#define DCB_DCRSR_REGWnR_Pos 16U /*!< DCB DCRSR: Register write/not-read Position */ +#define DCB_DCRSR_REGWnR_Msk (0x1UL << DCB_DCRSR_REGWnR_Pos) /*!< DCB DCRSR: Register write/not-read Mask */ + +#define DCB_DCRSR_REGSEL_Pos 0U /*!< DCB DCRSR: Register selector Position */ +#define DCB_DCRSR_REGSEL_Msk (0x7FUL /*<< DCB_DCRSR_REGSEL_Pos*/) /*!< DCB DCRSR: Register selector Mask */ + +/* DCRDR, Debug Core Register Data Register Definitions */ +#define DCB_DCRDR_DBGTMP_Pos 0U /*!< DCB DCRDR: Data temporary buffer Position */ +#define DCB_DCRDR_DBGTMP_Msk (0xFFFFFFFFUL /*<< DCB_DCRDR_DBGTMP_Pos*/) /*!< DCB DCRDR: Data temporary buffer Mask */ + +/* DEMCR, Debug Exception and Monitor Control Register Definitions */ +#define DCB_DEMCR_TRCENA_Pos 24U /*!< DCB DEMCR: Trace enable Position */ +#define DCB_DEMCR_TRCENA_Msk (0x1UL << DCB_DEMCR_TRCENA_Pos) /*!< DCB DEMCR: Trace enable Mask */ + +#define DCB_DEMCR_MONPRKEY_Pos 23U /*!< DCB DEMCR: Monitor pend req key Position */ +#define DCB_DEMCR_MONPRKEY_Msk (0x1UL << DCB_DEMCR_MONPRKEY_Pos) /*!< DCB DEMCR: Monitor pend req key Mask */ + +#define DCB_DEMCR_UMON_EN_Pos 21U /*!< DCB DEMCR: Unprivileged monitor enable Position */ +#define DCB_DEMCR_UMON_EN_Msk (0x1UL << DCB_DEMCR_UMON_EN_Pos) /*!< DCB DEMCR: Unprivileged monitor enable Mask */ + +#define DCB_DEMCR_SDME_Pos 20U /*!< DCB DEMCR: Secure DebugMonitor enable Position */ +#define DCB_DEMCR_SDME_Msk (0x1UL << DCB_DEMCR_SDME_Pos) /*!< DCB DEMCR: Secure DebugMonitor enable Mask */ + +#define DCB_DEMCR_MON_REQ_Pos 19U /*!< DCB DEMCR: Monitor request Position */ +#define DCB_DEMCR_MON_REQ_Msk (0x1UL << DCB_DEMCR_MON_REQ_Pos) /*!< DCB DEMCR: Monitor request Mask */ + +#define DCB_DEMCR_MON_STEP_Pos 18U /*!< DCB DEMCR: Monitor step Position */ +#define DCB_DEMCR_MON_STEP_Msk (0x1UL << DCB_DEMCR_MON_STEP_Pos) /*!< DCB DEMCR: Monitor step Mask */ + +#define DCB_DEMCR_MON_PEND_Pos 17U /*!< DCB DEMCR: Monitor pend Position */ +#define DCB_DEMCR_MON_PEND_Msk (0x1UL << DCB_DEMCR_MON_PEND_Pos) /*!< DCB DEMCR: Monitor pend Mask */ + +#define DCB_DEMCR_MON_EN_Pos 16U /*!< DCB DEMCR: Monitor enable Position */ +#define DCB_DEMCR_MON_EN_Msk (0x1UL << DCB_DEMCR_MON_EN_Pos) /*!< DCB DEMCR: Monitor enable Mask */ + +#define DCB_DEMCR_VC_SFERR_Pos 11U /*!< DCB DEMCR: Vector Catch SecureFault Position */ +#define DCB_DEMCR_VC_SFERR_Msk (0x1UL << DCB_DEMCR_VC_SFERR_Pos) /*!< DCB DEMCR: Vector Catch SecureFault Mask */ + +#define DCB_DEMCR_VC_HARDERR_Pos 10U /*!< DCB DEMCR: Vector Catch HardFault errors Position */ +#define DCB_DEMCR_VC_HARDERR_Msk (0x1UL << DCB_DEMCR_VC_HARDERR_Pos) /*!< DCB DEMCR: Vector Catch HardFault errors Mask */ + +#define DCB_DEMCR_VC_INTERR_Pos 9U /*!< DCB DEMCR: Vector Catch interrupt errors Position */ +#define DCB_DEMCR_VC_INTERR_Msk (0x1UL << DCB_DEMCR_VC_INTERR_Pos) /*!< DCB DEMCR: Vector Catch interrupt errors Mask */ + +#define DCB_DEMCR_VC_BUSERR_Pos 8U /*!< DCB DEMCR: Vector Catch BusFault errors Position */ +#define DCB_DEMCR_VC_BUSERR_Msk (0x1UL << DCB_DEMCR_VC_BUSERR_Pos) /*!< DCB DEMCR: Vector Catch BusFault errors Mask */ + +#define DCB_DEMCR_VC_STATERR_Pos 7U /*!< DCB DEMCR: Vector Catch state errors Position */ +#define DCB_DEMCR_VC_STATERR_Msk (0x1UL << DCB_DEMCR_VC_STATERR_Pos) /*!< DCB DEMCR: Vector Catch state errors Mask */ + +#define DCB_DEMCR_VC_CHKERR_Pos 6U /*!< DCB DEMCR: Vector Catch check errors Position */ +#define DCB_DEMCR_VC_CHKERR_Msk (0x1UL << DCB_DEMCR_VC_CHKERR_Pos) /*!< DCB DEMCR: Vector Catch check errors Mask */ + +#define DCB_DEMCR_VC_NOCPERR_Pos 5U /*!< DCB DEMCR: Vector Catch NOCP errors Position */ +#define DCB_DEMCR_VC_NOCPERR_Msk (0x1UL << DCB_DEMCR_VC_NOCPERR_Pos) /*!< DCB DEMCR: Vector Catch NOCP errors Mask */ + +#define DCB_DEMCR_VC_MMERR_Pos 4U /*!< DCB DEMCR: Vector Catch MemManage errors Position */ +#define DCB_DEMCR_VC_MMERR_Msk (0x1UL << DCB_DEMCR_VC_MMERR_Pos) /*!< DCB DEMCR: Vector Catch MemManage errors Mask */ + +#define DCB_DEMCR_VC_CORERESET_Pos 0U /*!< DCB DEMCR: Vector Catch Core reset Position */ +#define DCB_DEMCR_VC_CORERESET_Msk (0x1UL /*<< DCB_DEMCR_VC_CORERESET_Pos*/) /*!< DCB DEMCR: Vector Catch Core reset Mask */ + +/* DSCEMCR, Debug Set Clear Exception and Monitor Control Register Definitions */ +#define DCB_DSCEMCR_CLR_MON_REQ_Pos 19U /*!< DCB DSCEMCR: Clear monitor request Position */ +#define DCB_DSCEMCR_CLR_MON_REQ_Msk (0x1UL << DCB_DSCEMCR_CLR_MON_REQ_Pos) /*!< DCB DSCEMCR: Clear monitor request Mask */ + +#define DCB_DSCEMCR_CLR_MON_PEND_Pos 17U /*!< DCB DSCEMCR: Clear monitor pend Position */ +#define DCB_DSCEMCR_CLR_MON_PEND_Msk (0x1UL << DCB_DSCEMCR_CLR_MON_PEND_Pos) /*!< DCB DSCEMCR: Clear monitor pend Mask */ + +#define DCB_DSCEMCR_SET_MON_REQ_Pos 3U /*!< DCB DSCEMCR: Set monitor request Position */ +#define DCB_DSCEMCR_SET_MON_REQ_Msk (0x1UL << DCB_DSCEMCR_SET_MON_REQ_Pos) /*!< DCB DSCEMCR: Set monitor request Mask */ + +#define DCB_DSCEMCR_SET_MON_PEND_Pos 1U /*!< DCB DSCEMCR: Set monitor pend Position */ +#define DCB_DSCEMCR_SET_MON_PEND_Msk (0x1UL << DCB_DSCEMCR_SET_MON_PEND_Pos) /*!< DCB DSCEMCR: Set monitor pend Mask */ + +/* DAUTHCTRL, Debug Authentication Control Register Definitions */ +#define DCB_DAUTHCTRL_UIDEN_Pos 10U /*!< DCB DAUTHCTRL: Unprivileged Invasive Debug Enable Position */ +#define DCB_DAUTHCTRL_UIDEN_Msk (0x1UL << DCB_DAUTHCTRL_UIDEN_Pos) /*!< DCB DAUTHCTRL: Unprivileged Invasive Debug Enable Mask */ + +#define DCB_DAUTHCTRL_UIDAPEN_Pos 9U /*!< DCB DAUTHCTRL: Unprivileged Invasive DAP Access Enable Position */ +#define DCB_DAUTHCTRL_UIDAPEN_Msk (0x1UL << DCB_DAUTHCTRL_UIDAPEN_Pos) /*!< DCB DAUTHCTRL: Unprivileged Invasive DAP Access Enable Mask */ + +#define DCB_DAUTHCTRL_FSDMA_Pos 8U /*!< DCB DAUTHCTRL: Force Secure DebugMonitor Allowed Position */ +#define DCB_DAUTHCTRL_FSDMA_Msk (0x1UL << DCB_DAUTHCTRL_FSDMA_Pos) /*!< DCB DAUTHCTRL: Force Secure DebugMonitor Allowed Mask */ + +#define DCB_DAUTHCTRL_INTSPNIDEN_Pos 3U /*!< DCB DAUTHCTRL: Internal Secure non-invasive debug enable Position */ +#define DCB_DAUTHCTRL_INTSPNIDEN_Msk (0x1UL << DCB_DAUTHCTRL_INTSPNIDEN_Pos) /*!< DCB DAUTHCTRL: Internal Secure non-invasive debug enable Mask */ + +#define DCB_DAUTHCTRL_SPNIDENSEL_Pos 2U /*!< DCB DAUTHCTRL: Secure non-invasive debug enable select Position */ +#define DCB_DAUTHCTRL_SPNIDENSEL_Msk (0x1UL << DCB_DAUTHCTRL_SPNIDENSEL_Pos) /*!< DCB DAUTHCTRL: Secure non-invasive debug enable select Mask */ + +#define DCB_DAUTHCTRL_INTSPIDEN_Pos 1U /*!< DCB DAUTHCTRL: Internal Secure invasive debug enable Position */ +#define DCB_DAUTHCTRL_INTSPIDEN_Msk (0x1UL << DCB_DAUTHCTRL_INTSPIDEN_Pos) /*!< DCB DAUTHCTRL: Internal Secure invasive debug enable Mask */ + +#define DCB_DAUTHCTRL_SPIDENSEL_Pos 0U /*!< DCB DAUTHCTRL: Secure invasive debug enable select Position */ +#define DCB_DAUTHCTRL_SPIDENSEL_Msk (0x1UL /*<< DCB_DAUTHCTRL_SPIDENSEL_Pos*/) /*!< DCB DAUTHCTRL: Secure invasive debug enable select Mask */ + +/* DSCSR, Debug Security Control and Status Register Definitions */ +#define DCB_DSCSR_CDSKEY_Pos 17U /*!< DCB DSCSR: CDS write-enable key Position */ +#define DCB_DSCSR_CDSKEY_Msk (0x1UL << DCB_DSCSR_CDSKEY_Pos) /*!< DCB DSCSR: CDS write-enable key Mask */ + +#define DCB_DSCSR_CDS_Pos 16U /*!< DCB DSCSR: Current domain Secure Position */ +#define DCB_DSCSR_CDS_Msk (0x1UL << DCB_DSCSR_CDS_Pos) /*!< DCB DSCSR: Current domain Secure Mask */ + +#define DCB_DSCSR_SBRSEL_Pos 1U /*!< DCB DSCSR: Secure banked register select Position */ +#define DCB_DSCSR_SBRSEL_Msk (0x1UL << DCB_DSCSR_SBRSEL_Pos) /*!< DCB DSCSR: Secure banked register select Mask */ + +#define DCB_DSCSR_SBRSELEN_Pos 0U /*!< DCB DSCSR: Secure banked register select enable Position */ +#define DCB_DSCSR_SBRSELEN_Msk (0x1UL /*<< DCB_DSCSR_SBRSELEN_Pos*/) /*!< DCB DSCSR: Secure banked register select enable Mask */ + +/*@} end of group CMSIS_DCB */ + + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_DIB Debug Identification Block + \brief Type definitions for the Debug Identification Block Registers + @{ + */ + +/** + \brief Structure type to access the Debug Identification Block Registers (DIB). + */ +typedef struct +{ + __OM uint32_t DLAR; /*!< Offset: 0x000 ( /W) SCS Software Lock Access Register */ + __IM uint32_t DLSR; /*!< Offset: 0x004 (R/ ) SCS Software Lock Status Register */ + __IM uint32_t DAUTHSTATUS; /*!< Offset: 0x008 (R/ ) Debug Authentication Status Register */ + __IM uint32_t DDEVARCH; /*!< Offset: 0x00C (R/ ) SCS Device Architecture Register */ + __IM uint32_t DDEVTYPE; /*!< Offset: 0x010 (R/ ) SCS Device Type Register */ +} DIB_Type; + +/* DLAR, SCS Software Lock Access Register Definitions */ +#define DIB_DLAR_KEY_Pos 0U /*!< DIB DLAR: KEY Position */ +#define DIB_DLAR_KEY_Msk (0xFFFFFFFFUL /*<< DIB_DLAR_KEY_Pos */) /*!< DIB DLAR: KEY Mask */ + +/* DLSR, SCS Software Lock Status Register Definitions */ +#define DIB_DLSR_nTT_Pos 2U /*!< DIB DLSR: Not thirty-two bit Position */ +#define DIB_DLSR_nTT_Msk (0x1UL << DIB_DLSR_nTT_Pos ) /*!< DIB DLSR: Not thirty-two bit Mask */ + +#define DIB_DLSR_SLK_Pos 1U /*!< DIB DLSR: Software Lock status Position */ +#define DIB_DLSR_SLK_Msk (0x1UL << DIB_DLSR_SLK_Pos ) /*!< DIB DLSR: Software Lock status Mask */ + +#define DIB_DLSR_SLI_Pos 0U /*!< DIB DLSR: Software Lock implemented Position */ +#define DIB_DLSR_SLI_Msk (0x1UL /*<< DIB_DLSR_SLI_Pos*/) /*!< DIB DLSR: Software Lock implemented Mask */ + +/* DAUTHSTATUS, Debug Authentication Status Register Definitions */ +#define DIB_DAUTHSTATUS_SUNID_Pos 22U /*!< DIB DAUTHSTATUS: Secure Unprivileged Non-invasive Debug Allowed Position */ +#define DIB_DAUTHSTATUS_SUNID_Msk (0x3UL << DIB_DAUTHSTATUS_SUNID_Pos ) /*!< DIB DAUTHSTATUS: Secure Unprivileged Non-invasive Debug Allowed Mask */ + +#define DIB_DAUTHSTATUS_SUID_Pos 20U /*!< DIB DAUTHSTATUS: Secure Unprivileged Invasive Debug Allowed Position */ +#define DIB_DAUTHSTATUS_SUID_Msk (0x3UL << DIB_DAUTHSTATUS_SUID_Pos ) /*!< DIB DAUTHSTATUS: Secure Unprivileged Invasive Debug Allowed Mask */ + +#define DIB_DAUTHSTATUS_NSUNID_Pos 18U /*!< DIB DAUTHSTATUS: Non-secure Unprivileged Non-invasive Debug Allo Position */ +#define DIB_DAUTHSTATUS_NSUNID_Msk (0x3UL << DIB_DAUTHSTATUS_NSUNID_Pos ) /*!< DIB DAUTHSTATUS: Non-secure Unprivileged Non-invasive Debug Allo Mask */ + +#define DIB_DAUTHSTATUS_NSUID_Pos 16U /*!< DIB DAUTHSTATUS: Non-secure Unprivileged Invasive Debug Allowed Position */ +#define DIB_DAUTHSTATUS_NSUID_Msk (0x3UL << DIB_DAUTHSTATUS_NSUID_Pos ) /*!< DIB DAUTHSTATUS: Non-secure Unprivileged Invasive Debug Allowed Mask */ + +#define DIB_DAUTHSTATUS_SNID_Pos 6U /*!< DIB DAUTHSTATUS: Secure Non-invasive Debug Position */ +#define DIB_DAUTHSTATUS_SNID_Msk (0x3UL << DIB_DAUTHSTATUS_SNID_Pos ) /*!< DIB DAUTHSTATUS: Secure Non-invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_SID_Pos 4U /*!< DIB DAUTHSTATUS: Secure Invasive Debug Position */ +#define DIB_DAUTHSTATUS_SID_Msk (0x3UL << DIB_DAUTHSTATUS_SID_Pos ) /*!< DIB DAUTHSTATUS: Secure Invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_NSNID_Pos 2U /*!< DIB DAUTHSTATUS: Non-secure Non-invasive Debug Position */ +#define DIB_DAUTHSTATUS_NSNID_Msk (0x3UL << DIB_DAUTHSTATUS_NSNID_Pos ) /*!< DIB DAUTHSTATUS: Non-secure Non-invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_NSID_Pos 0U /*!< DIB DAUTHSTATUS: Non-secure Invasive Debug Position */ +#define DIB_DAUTHSTATUS_NSID_Msk (0x3UL /*<< DIB_DAUTHSTATUS_NSID_Pos*/) /*!< DIB DAUTHSTATUS: Non-secure Invasive Debug Mask */ + +/* DDEVARCH, SCS Device Architecture Register Definitions */ +#define DIB_DDEVARCH_ARCHITECT_Pos 21U /*!< DIB DDEVARCH: Architect Position */ +#define DIB_DDEVARCH_ARCHITECT_Msk (0x7FFUL << DIB_DDEVARCH_ARCHITECT_Pos ) /*!< DIB DDEVARCH: Architect Mask */ + +#define DIB_DDEVARCH_PRESENT_Pos 20U /*!< DIB DDEVARCH: DEVARCH Present Position */ +#define DIB_DDEVARCH_PRESENT_Msk (0x1FUL << DIB_DDEVARCH_PRESENT_Pos ) /*!< DIB DDEVARCH: DEVARCH Present Mask */ + +#define DIB_DDEVARCH_REVISION_Pos 16U /*!< DIB DDEVARCH: Revision Position */ +#define DIB_DDEVARCH_REVISION_Msk (0xFUL << DIB_DDEVARCH_REVISION_Pos ) /*!< DIB DDEVARCH: Revision Mask */ + +#define DIB_DDEVARCH_ARCHVER_Pos 12U /*!< DIB DDEVARCH: Architecture Version Position */ +#define DIB_DDEVARCH_ARCHVER_Msk (0xFUL << DIB_DDEVARCH_ARCHVER_Pos ) /*!< DIB DDEVARCH: Architecture Version Mask */ + +#define DIB_DDEVARCH_ARCHPART_Pos 0U /*!< DIB DDEVARCH: Architecture Part Position */ +#define DIB_DDEVARCH_ARCHPART_Msk (0xFFFUL /*<< DIB_DDEVARCH_ARCHPART_Pos*/) /*!< DIB DDEVARCH: Architecture Part Mask */ + +/* DDEVTYPE, SCS Device Type Register Definitions */ +#define DIB_DDEVTYPE_SUB_Pos 4U /*!< DIB DDEVTYPE: Sub-type Position */ +#define DIB_DDEVTYPE_SUB_Msk (0xFUL << DIB_DDEVTYPE_SUB_Pos ) /*!< DIB DDEVTYPE: Sub-type Mask */ + +#define DIB_DDEVTYPE_MAJOR_Pos 0U /*!< DIB DDEVTYPE: Major type Position */ +#define DIB_DDEVTYPE_MAJOR_Msk (0xFUL /*<< DIB_DDEVTYPE_MAJOR_Pos*/) /*!< DIB DDEVTYPE: Major type Mask */ + + +/*@} end of group CMSIS_DIB */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_core_bitfield Core register bit field macros + \brief Macros for use with bit field definitions (xxx_Pos, xxx_Msk). + @{ + */ + +/** + \brief Mask and shift a bit field value for use in a register bit range. + \param[in] field Name of the register bit field. + \param[in] value Value of the bit field. This parameter is interpreted as an uint32_t type. + \return Masked and shifted value. +*/ +#define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk) + +/** + \brief Mask and shift a register value to extract a bit filed value. + \param[in] field Name of the register bit field. + \param[in] value Value of register. This parameter is interpreted as an uint32_t type. + \return Masked and shifted bit field value. +*/ +#define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos) + +/*@} end of group CMSIS_core_bitfield */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_core_base Core Definitions + \brief Definitions for base addresses, unions, and structures. + @{ + */ + +/* Memory mapping of Core Hardware */ + #define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */ + #define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */ + #define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */ + #define MEMSYSCTL_BASE (0xE001E000UL) /*!< Memory System Control Base Address */ + #define ERRBNK_BASE (0xE001E100UL) /*!< Error Banking Base Address */ + #define PWRMODCTL_BASE (0xE001E300UL) /*!< Power Mode Control Base Address */ + #define EWIC_BASE (0xE001E400UL) /*!< External Wakeup Interrupt Controller Base Address */ + #define PRCCFGINF_BASE (0xE001E700UL) /*!< Processor Configuration Information Base Address */ + #define TPI_BASE (0xE0040000UL) /*!< TPI Base Address */ + #define CoreDebug_BASE (0xE000EDF0UL) /*!< \deprecated Core Debug Base Address */ + #define DCB_BASE (0xE000EDF0UL) /*!< DCB Base Address */ + #define DIB_BASE (0xE000EFB0UL) /*!< DIB Base Address */ + #define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */ + #define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */ + #define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */ + + #define ICB ((ICB_Type *) SCS_BASE ) /*!< System control Register not in SCB */ + #define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */ + #define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */ + #define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */ + #define ITM ((ITM_Type *) ITM_BASE ) /*!< ITM configuration struct */ + #define DWT ((DWT_Type *) DWT_BASE ) /*!< DWT configuration struct */ + #define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct */ + #define MEMSYSCTL ((MemSysCtl_Type *) MEMSYSCTL_BASE ) /*!< Memory System Control configuration struct */ + #define ERRBNK ((ErrBnk_Type *) ERRBNK_BASE ) /*!< Error Banking configuration struct */ + #define PWRMODCTL ((PwrModCtl_Type *) PWRMODCTL_BASE ) /*!< Power Mode Control configuration struct */ + #define EWIC ((EWIC_Type *) EWIC_BASE ) /*!< EWIC configuration struct */ + #define PRCCFGINF ((PrcCfgInf_Type *) PRCCFGINF_BASE ) /*!< Processor Configuration Information configuration struct */ + #define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE ) /*!< \deprecated Core Debug configuration struct */ + #define DCB ((DCB_Type *) DCB_BASE ) /*!< DCB configuration struct */ + #define DIB ((DIB_Type *) DIB_BASE ) /*!< DIB configuration struct */ + + #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) + #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */ + #define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */ + #endif + + #if defined (__PMU_PRESENT) && (__PMU_PRESENT == 1U) + #define PMU_BASE (0xE0003000UL) /*!< PMU Base Address */ + #define PMU ((PMU_Type *) PMU_BASE ) /*!< PMU configuration struct */ + #endif + + #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) + #define SAU_BASE (SCS_BASE + 0x0DD0UL) /*!< Security Attribution Unit */ + #define SAU ((SAU_Type *) SAU_BASE ) /*!< Security Attribution Unit */ + #endif + + #define FPU_BASE (SCS_BASE + 0x0F30UL) /*!< Floating Point Unit */ + #define FPU ((FPU_Type *) FPU_BASE ) /*!< Floating Point Unit */ + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) + #define SCS_BASE_NS (0xE002E000UL) /*!< System Control Space Base Address (non-secure address space) */ + #define CoreDebug_BASE_NS (0xE002EDF0UL) /*!< \deprecated Core Debug Base Address (non-secure address space) */ + #define DCB_BASE_NS (0xE002EDF0UL) /*!< DCB Base Address (non-secure address space) */ + #define DIB_BASE_NS (0xE002EFB0UL) /*!< DIB Base Address (non-secure address space) */ + #define SysTick_BASE_NS (SCS_BASE_NS + 0x0010UL) /*!< SysTick Base Address (non-secure address space) */ + #define NVIC_BASE_NS (SCS_BASE_NS + 0x0100UL) /*!< NVIC Base Address (non-secure address space) */ + #define SCB_BASE_NS (SCS_BASE_NS + 0x0D00UL) /*!< System Control Block Base Address (non-secure address space) */ + + #define ICB_NS ((ICB_Type *) SCS_BASE_NS ) /*!< System control Register not in SCB(non-secure address space) */ + #define SCB_NS ((SCB_Type *) SCB_BASE_NS ) /*!< SCB configuration struct (non-secure address space) */ + #define SysTick_NS ((SysTick_Type *) SysTick_BASE_NS ) /*!< SysTick configuration struct (non-secure address space) */ + #define NVIC_NS ((NVIC_Type *) NVIC_BASE_NS ) /*!< NVIC configuration struct (non-secure address space) */ + #define CoreDebug_NS ((CoreDebug_Type *) CoreDebug_BASE_NS) /*!< \deprecated Core Debug configuration struct (non-secure address space) */ + #define DCB_NS ((DCB_Type *) DCB_BASE_NS ) /*!< DCB configuration struct (non-secure address space) */ + #define DIB_NS ((DIB_Type *) DIB_BASE_NS ) /*!< DIB configuration struct (non-secure address space) */ + + #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) + #define MPU_BASE_NS (SCS_BASE_NS + 0x0D90UL) /*!< Memory Protection Unit (non-secure address space) */ + #define MPU_NS ((MPU_Type *) MPU_BASE_NS ) /*!< Memory Protection Unit (non-secure address space) */ + #endif + + #define FPU_BASE_NS (SCS_BASE_NS + 0x0F30UL) /*!< Floating Point Unit (non-secure address space) */ + #define FPU_NS ((FPU_Type *) FPU_BASE_NS ) /*!< Floating Point Unit (non-secure address space) */ + +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ +/*@} */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_register_aliases Backwards Compatibility Aliases + \brief Register alias definitions for backwards compatibility. + @{ + */ + +/*@} */ + + +/******************************************************************************* + * Hardware Abstraction Layer + Core Function Interface contains: + - Core NVIC Functions + - Core SysTick Functions + - Core Debug Functions + - Core Register Access Functions + ******************************************************************************/ +/** + \defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference +*/ + + + +/* ########################## NVIC functions #################################### */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_NVICFunctions NVIC Functions + \brief Functions that manage interrupts and exceptions via the NVIC. + @{ + */ + +#ifdef CMSIS_NVIC_VIRTUAL + #ifndef CMSIS_NVIC_VIRTUAL_HEADER_FILE + #define CMSIS_NVIC_VIRTUAL_HEADER_FILE "cmsis_nvic_virtual.h" + #endif + #include CMSIS_NVIC_VIRTUAL_HEADER_FILE +#else + #define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping + #define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping + #define NVIC_EnableIRQ __NVIC_EnableIRQ + #define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ + #define NVIC_DisableIRQ __NVIC_DisableIRQ + #define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ + #define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ + #define NVIC_ClearPendingIRQ __NVIC_ClearPendingIRQ + #define NVIC_GetActive __NVIC_GetActive + #define NVIC_SetPriority __NVIC_SetPriority + #define NVIC_GetPriority __NVIC_GetPriority + #define NVIC_SystemReset __NVIC_SystemReset +#endif /* CMSIS_NVIC_VIRTUAL */ + +#ifdef CMSIS_VECTAB_VIRTUAL + #ifndef CMSIS_VECTAB_VIRTUAL_HEADER_FILE + #define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h" + #endif + #include CMSIS_VECTAB_VIRTUAL_HEADER_FILE +#else + #define NVIC_SetVector __NVIC_SetVector + #define NVIC_GetVector __NVIC_GetVector +#endif /* (CMSIS_VECTAB_VIRTUAL) */ + +#define NVIC_USER_IRQ_OFFSET 16 + + +/* Special LR values for Secure/Non-Secure call handling and exception handling */ + +/* Function Return Payload (from ARMv8-M Architecture Reference Manual) LR value on entry from Secure BLXNS */ +#define FNC_RETURN (0xFEFFFFFFUL) /* bit [0] ignored when processing a branch */ + +/* The following EXC_RETURN mask values are used to evaluate the LR on exception entry */ +#define EXC_RETURN_PREFIX (0xFF000000UL) /* bits [31:24] set to indicate an EXC_RETURN value */ +#define EXC_RETURN_S (0x00000040UL) /* bit [6] stack used to push registers: 0=Non-secure 1=Secure */ +#define EXC_RETURN_DCRS (0x00000020UL) /* bit [5] stacking rules for called registers: 0=skipped 1=saved */ +#define EXC_RETURN_FTYPE (0x00000010UL) /* bit [4] allocate stack for floating-point context: 0=done 1=skipped */ +#define EXC_RETURN_MODE (0x00000008UL) /* bit [3] processor mode for return: 0=Handler mode 1=Thread mode */ +#define EXC_RETURN_SPSEL (0x00000004UL) /* bit [2] stack pointer used to restore context: 0=MSP 1=PSP */ +#define EXC_RETURN_ES (0x00000001UL) /* bit [0] security state exception was taken to: 0=Non-secure 1=Secure */ + +/* Integrity Signature (from ARMv8-M Architecture Reference Manual) for exception context stacking */ +#if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) /* Value for processors with floating-point extension: */ +#define EXC_INTEGRITY_SIGNATURE (0xFEFA125AUL) /* bit [0] SFTC must match LR bit[4] EXC_RETURN_FTYPE */ +#else +#define EXC_INTEGRITY_SIGNATURE (0xFEFA125BUL) /* Value for processors without floating-point extension */ +#endif + + +/** + \brief Set Priority Grouping + \details Sets the priority grouping field using the required unlock sequence. + The parameter PriorityGroup is assigned to the field SCB->AIRCR [10:8] PRIGROUP field. + Only values from 0..7 are used. + In case of a conflict between priority grouping and available + priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set. + \param [in] PriorityGroup Priority grouping field. + */ +__STATIC_INLINE void __NVIC_SetPriorityGrouping(uint32_t PriorityGroup) +{ + uint32_t reg_value; + uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ + + reg_value = SCB->AIRCR; /* read old register configuration */ + reg_value &= ~((uint32_t)(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk)); /* clear bits to change */ + reg_value = (reg_value | + ((uint32_t)0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | + (PriorityGroupTmp << SCB_AIRCR_PRIGROUP_Pos) ); /* Insert write key and priority group */ + SCB->AIRCR = reg_value; +} + + +/** + \brief Get Priority Grouping + \details Reads the priority grouping field from the NVIC Interrupt Controller. + \return Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field). + */ +__STATIC_INLINE uint32_t __NVIC_GetPriorityGrouping(void) +{ + return ((uint32_t)((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos)); +} + + +/** + \brief Enable Interrupt + \details Enables a device specific interrupt in the NVIC interrupt controller. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + __COMPILER_BARRIER(); + NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __COMPILER_BARRIER(); + } +} + + +/** + \brief Get Interrupt Enable status + \details Returns a device specific interrupt enable status from the NVIC interrupt controller. + \param [in] IRQn Device specific interrupt number. + \return 0 Interrupt is not enabled. + \return 1 Interrupt is enabled. + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +/** + \brief Disable Interrupt + \details Disables a device specific interrupt in the NVIC interrupt controller. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC->ICER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __DSB(); + __ISB(); + } +} + + +/** + \brief Get Pending Interrupt + \details Reads the NVIC pending register and returns the pending bit for the specified device specific interrupt. + \param [in] IRQn Device specific interrupt number. + \return 0 Interrupt status is not pending. + \return 1 Interrupt status is pending. + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +/** + \brief Set Pending Interrupt + \details Sets the pending bit of a device specific interrupt in the NVIC pending register. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } +} + + +/** + \brief Clear Pending Interrupt + \details Clears the pending bit of a device specific interrupt in the NVIC pending register. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC->ICPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } +} + + +/** + \brief Get Active Interrupt + \details Reads the active register in the NVIC and returns the active bit for the device specific interrupt. + \param [in] IRQn Device specific interrupt number. + \return 0 Interrupt status is not active. + \return 1 Interrupt status is active. + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t __NVIC_GetActive(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC->IABR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief Get Interrupt Target State + \details Reads the interrupt target field in the NVIC and returns the interrupt target bit for the device specific interrupt. + \param [in] IRQn Device specific interrupt number. + \return 0 if interrupt is assigned to Secure + \return 1 if interrupt is assigned to Non Secure + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t NVIC_GetTargetState(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC->ITNS[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +/** + \brief Set Interrupt Target State + \details Sets the interrupt target field in the NVIC and returns the interrupt target bit for the device specific interrupt. + \param [in] IRQn Device specific interrupt number. + \return 0 if interrupt is assigned to Secure + 1 if interrupt is assigned to Non Secure + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t NVIC_SetTargetState(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC->ITNS[(((uint32_t)IRQn) >> 5UL)] |= ((uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL))); + return((uint32_t)(((NVIC->ITNS[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +/** + \brief Clear Interrupt Target State + \details Clears the interrupt target field in the NVIC and returns the interrupt target bit for the device specific interrupt. + \param [in] IRQn Device specific interrupt number. + \return 0 if interrupt is assigned to Secure + 1 if interrupt is assigned to Non Secure + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t NVIC_ClearTargetState(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC->ITNS[(((uint32_t)IRQn) >> 5UL)] &= ~((uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL))); + return((uint32_t)(((NVIC->ITNS[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + + +/** + \brief Set Interrupt Priority + \details Sets the priority of a device specific interrupt or a processor exception. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + \param [in] IRQn Interrupt number. + \param [in] priority Priority to set. + \note The priority cannot be set for every processor exception. + */ +__STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC->IPR[((uint32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); + } + else + { + SCB->SHPR[(((uint32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); + } +} + + +/** + \brief Get Interrupt Priority + \details Reads the priority of a device specific interrupt or a processor exception. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + \param [in] IRQn Interrupt number. + \return Interrupt Priority. + Value is aligned automatically to the implemented priority bits of the microcontroller. + */ +__STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn) +{ + + if ((int32_t)(IRQn) >= 0) + { + return(((uint32_t)NVIC->IPR[((uint32_t)IRQn)] >> (8U - __NVIC_PRIO_BITS))); + } + else + { + return(((uint32_t)SCB->SHPR[(((uint32_t)IRQn) & 0xFUL)-4UL] >> (8U - __NVIC_PRIO_BITS))); + } +} + + +/** + \brief Encode Priority + \details Encodes the priority for an interrupt with the given priority group, + preemptive priority value, and subpriority value. + In case of a conflict between priority grouping and available + priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set. + \param [in] PriorityGroup Used priority group. + \param [in] PreemptPriority Preemptive priority value (starting from 0). + \param [in] SubPriority Subpriority value (starting from 0). + \return Encoded priority. Value can be used in the function \ref NVIC_SetPriority(). + */ +__STATIC_INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority) +{ + uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ + uint32_t PreemptPriorityBits; + uint32_t SubPriorityBits; + + PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp); + SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS)); + + return ( + ((PreemptPriority & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL)) << SubPriorityBits) | + ((SubPriority & (uint32_t)((1UL << (SubPriorityBits )) - 1UL))) + ); +} + + +/** + \brief Decode Priority + \details Decodes an interrupt priority value with a given priority group to + preemptive priority value and subpriority value. + In case of a conflict between priority grouping and available + priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set. + \param [in] Priority Priority value, which can be retrieved with the function \ref NVIC_GetPriority(). + \param [in] PriorityGroup Used priority group. + \param [out] pPreemptPriority Preemptive priority value (starting from 0). + \param [out] pSubPriority Subpriority value (starting from 0). + */ +__STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* const pPreemptPriority, uint32_t* const pSubPriority) +{ + uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ + uint32_t PreemptPriorityBits; + uint32_t SubPriorityBits; + + PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp); + SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS)); + + *pPreemptPriority = (Priority >> SubPriorityBits) & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL); + *pSubPriority = (Priority ) & (uint32_t)((1UL << (SubPriorityBits )) - 1UL); +} + + +/** + \brief Set Interrupt Vector + \details Sets an interrupt vector in SRAM based interrupt vector table. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + VTOR must been relocated to SRAM before. + \param [in] IRQn Interrupt number + \param [in] vector Address of interrupt handler function + */ +__STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) +{ + uint32_t *vectors = (uint32_t *)SCB->VTOR; + vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector; + __DSB(); +} + + +/** + \brief Get Interrupt Vector + \details Reads an interrupt vector from interrupt vector table. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + \param [in] IRQn Interrupt number. + \return Address of interrupt handler function + */ +__STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn) +{ + uint32_t *vectors = (uint32_t *)SCB->VTOR; + return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET]; +} + + +/** + \brief System Reset + \details Initiates a system reset request to reset the MCU. + */ +__NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void) +{ + __DSB(); /* Ensure all outstanding memory accesses included + buffered write are completed before reset */ + SCB->AIRCR = (uint32_t)((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | + (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) | + SCB_AIRCR_SYSRESETREQ_Msk ); /* Keep priority group unchanged */ + __DSB(); /* Ensure completion of memory access */ + + for(;;) /* wait until reset */ + { + __NOP(); + } +} + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief Set Priority Grouping (non-secure) + \details Sets the non-secure priority grouping field when in secure state using the required unlock sequence. + The parameter PriorityGroup is assigned to the field SCB->AIRCR [10:8] PRIGROUP field. + Only values from 0..7 are used. + In case of a conflict between priority grouping and available + priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set. + \param [in] PriorityGroup Priority grouping field. + */ +__STATIC_INLINE void TZ_NVIC_SetPriorityGrouping_NS(uint32_t PriorityGroup) +{ + uint32_t reg_value; + uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ + + reg_value = SCB_NS->AIRCR; /* read old register configuration */ + reg_value &= ~((uint32_t)(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk)); /* clear bits to change */ + reg_value = (reg_value | + ((uint32_t)0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | + (PriorityGroupTmp << SCB_AIRCR_PRIGROUP_Pos) ); /* Insert write key and priority group */ + SCB_NS->AIRCR = reg_value; +} + + +/** + \brief Get Priority Grouping (non-secure) + \details Reads the priority grouping field from the non-secure NVIC when in secure state. + \return Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field). + */ +__STATIC_INLINE uint32_t TZ_NVIC_GetPriorityGrouping_NS(void) +{ + return ((uint32_t)((SCB_NS->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos)); +} + + +/** + \brief Enable Interrupt (non-secure) + \details Enables a device specific interrupt in the non-secure NVIC interrupt controller when in secure state. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void TZ_NVIC_EnableIRQ_NS(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC_NS->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } +} + + +/** + \brief Get Interrupt Enable status (non-secure) + \details Returns a device specific interrupt enable status from the non-secure NVIC interrupt controller when in secure state. + \param [in] IRQn Device specific interrupt number. + \return 0 Interrupt is not enabled. + \return 1 Interrupt is enabled. + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t TZ_NVIC_GetEnableIRQ_NS(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC_NS->ISER[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +/** + \brief Disable Interrupt (non-secure) + \details Disables a device specific interrupt in the non-secure NVIC interrupt controller when in secure state. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void TZ_NVIC_DisableIRQ_NS(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC_NS->ICER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } +} + + +/** + \brief Get Pending Interrupt (non-secure) + \details Reads the NVIC pending register in the non-secure NVIC when in secure state and returns the pending bit for the specified device specific interrupt. + \param [in] IRQn Device specific interrupt number. + \return 0 Interrupt status is not pending. + \return 1 Interrupt status is pending. + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t TZ_NVIC_GetPendingIRQ_NS(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC_NS->ISPR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +/** + \brief Set Pending Interrupt (non-secure) + \details Sets the pending bit of a device specific interrupt in the non-secure NVIC pending register when in secure state. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void TZ_NVIC_SetPendingIRQ_NS(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC_NS->ISPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } +} + + +/** + \brief Clear Pending Interrupt (non-secure) + \details Clears the pending bit of a device specific interrupt in the non-secure NVIC pending register when in secure state. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void TZ_NVIC_ClearPendingIRQ_NS(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC_NS->ICPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } +} + + +/** + \brief Get Active Interrupt (non-secure) + \details Reads the active register in non-secure NVIC when in secure state and returns the active bit for the device specific interrupt. + \param [in] IRQn Device specific interrupt number. + \return 0 Interrupt status is not active. + \return 1 Interrupt status is active. + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t TZ_NVIC_GetActive_NS(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC_NS->IABR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +/** + \brief Set Interrupt Priority (non-secure) + \details Sets the priority of a non-secure device specific interrupt or a non-secure processor exception when in secure state. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + \param [in] IRQn Interrupt number. + \param [in] priority Priority to set. + \note The priority cannot be set for every non-secure processor exception. + */ +__STATIC_INLINE void TZ_NVIC_SetPriority_NS(IRQn_Type IRQn, uint32_t priority) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC_NS->IPR[((uint32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); + } + else + { + SCB_NS->SHPR[(((uint32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); + } +} + + +/** + \brief Get Interrupt Priority (non-secure) + \details Reads the priority of a non-secure device specific interrupt or a non-secure processor exception when in secure state. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + \param [in] IRQn Interrupt number. + \return Interrupt Priority. Value is aligned automatically to the implemented priority bits of the microcontroller. + */ +__STATIC_INLINE uint32_t TZ_NVIC_GetPriority_NS(IRQn_Type IRQn) +{ + + if ((int32_t)(IRQn) >= 0) + { + return(((uint32_t)NVIC_NS->IPR[((uint32_t)IRQn)] >> (8U - __NVIC_PRIO_BITS))); + } + else + { + return(((uint32_t)SCB_NS->SHPR[(((uint32_t)IRQn) & 0xFUL)-4UL] >> (8U - __NVIC_PRIO_BITS))); + } +} +#endif /* defined (__ARM_FEATURE_CMSE) &&(__ARM_FEATURE_CMSE == 3U) */ + +/*@} end of CMSIS_Core_NVICFunctions */ + +/* ########################## MPU functions #################################### */ + +#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) + +#include "mpu_armv8.h" + +#endif + +/* ########################## PMU functions and events #################################### */ + +#if defined (__PMU_PRESENT) && (__PMU_PRESENT == 1U) + +#include "pmu_armv8.h" + +/** + \brief Cortex-M85 PMU events + \note Architectural PMU events can be found in pmu_armv8.h +*/ + +#define ARMCM85_PMU_ECC_ERR 0xC000 /*!< One or more Error Correcting Code (ECC) errors detected */ +#define ARMCM85_PMU_ECC_ERR_MBIT 0xC001 /*!< One or more multi-bit ECC errors detected */ +#define ARMCM85_PMU_ECC_ERR_DCACHE 0xC010 /*!< One or more ECC errors in the data cache */ +#define ARMCM85_PMU_ECC_ERR_ICACHE 0xC011 /*!< One or more ECC errors in the instruction cache */ +#define ARMCM85_PMU_ECC_ERR_MBIT_DCACHE 0xC012 /*!< One or more multi-bit ECC errors in the data cache */ +#define ARMCM85_PMU_ECC_ERR_MBIT_ICACHE 0xC013 /*!< One or more multi-bit ECC errors in the instruction cache */ +#define ARMCM85_PMU_ECC_ERR_DTCM 0xC020 /*!< One or more ECC errors in the Data Tightly Coupled Memory (DTCM) */ +#define ARMCM85_PMU_ECC_ERR_ITCM 0xC021 /*!< One or more ECC errors in the Instruction Tightly Coupled Memory (ITCM) */ +#define ARMCM85_PMU_ECC_ERR_MBIT_DTCM 0xC022 /*!< One or more multi-bit ECC errors in the DTCM */ +#define ARMCM85_PMU_ECC_ERR_MBIT_ITCM 0xC023 /*!< One or more multi-bit ECC errors in the ITCM */ +#define ARMCM85_PMU_PF_LINEFILL 0xC100 /*!< The prefetcher starts a line-fill */ +#define ARMCM85_PMU_PF_CANCEL 0xC101 /*!< The prefetcher stops prefetching */ +#define ARMCM85_PMU_PF_DROP_LINEFILL 0xC102 /*!< A linefill triggered by a prefetcher has been dropped because of lack of buffering */ +#define ARMCM85_PMU_NWAMODE_ENTER 0xC200 /*!< No write-allocate mode entry */ +#define ARMCM85_PMU_NWAMODE 0xC201 /*!< Write-allocate store is not allocated into the data cache due to no-write-allocate mode */ +#define ARMCM85_PMU_SAHB_ACCESS 0xC300 /*!< Read or write access on the S-AHB interface to the TCM */ +#define ARMCM85_PMU_PAHB_ACCESS 0xC301 /*!< Read or write access on the P-AHB write interface */ +#define ARMCM85_PMU_AXI_WRITE_ACCESS 0xC302 /*!< Any beat access to M-AXI write interface */ +#define ARMCM85_PMU_AXI_READ_ACCESS 0xC303 /*!< Any beat access to M-AXI read interface */ +#define ARMCM85_PMU_DOSTIMEOUT_DOUBLE 0xC400 /*!< Denial of Service timeout has fired twice and caused buffers to drain to allow forward progress */ +#define ARMCM85_PMU_DOSTIMEOUT_TRIPLE 0xC401 /*!< Denial of Service timeout has fired three times and blocked the LSU to force forward progress */ + +#endif + +/* ########################## FPU functions #################################### */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_FpuFunctions FPU Functions + \brief Function that provides FPU type. + @{ + */ + +/** + \brief get FPU type + \details returns the FPU type + \returns + - \b 0: No FPU + - \b 1: Single precision FPU + - \b 2: Double + Single precision FPU + */ +__STATIC_INLINE uint32_t SCB_GetFPUType(void) +{ + uint32_t mvfr0; + + mvfr0 = FPU->MVFR0; + if ((mvfr0 & (FPU_MVFR0_FPSP_Msk | FPU_MVFR0_FPDP_Msk)) == 0x220U) + { + return 2U; /* Double + Single precision FPU */ + } + else if ((mvfr0 & (FPU_MVFR0_FPSP_Msk | FPU_MVFR0_FPDP_Msk)) == 0x020U) + { + return 1U; /* Single precision FPU */ + } + else + { + return 0U; /* No FPU */ + } +} + + +/*@} end of CMSIS_Core_FpuFunctions */ + +/* ########################## MVE functions #################################### */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_MveFunctions MVE Functions + \brief Function that provides MVE type. + @{ + */ + +/** + \brief get MVE type + \details returns the MVE type + \returns + - \b 0: No Vector Extension (MVE) + - \b 1: Integer Vector Extension (MVE-I) + - \b 2: Floating-point Vector Extension (MVE-F) + */ +__STATIC_INLINE uint32_t SCB_GetMVEType(void) +{ + const uint32_t mvfr1 = FPU->MVFR1; + if ((mvfr1 & FPU_MVFR1_MVE_Msk) == (0x2U << FPU_MVFR1_MVE_Pos)) + { + return 2U; + } + else if ((mvfr1 & FPU_MVFR1_MVE_Msk) == (0x1U << FPU_MVFR1_MVE_Pos)) + { + return 1U; + } + else + { + return 0U; + } +} + + +/*@} end of CMSIS_Core_MveFunctions */ + + +/* ########################## Cache functions #################################### */ + +#if ((defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U)) || \ + (defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U))) +#include "cachel1_armv7.h" +#endif + + +/* ########################## SAU functions #################################### */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_SAUFunctions SAU Functions + \brief Functions that configure the SAU. + @{ + */ + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) + +/** + \brief Enable SAU + \details Enables the Security Attribution Unit (SAU). + */ +__STATIC_INLINE void TZ_SAU_Enable(void) +{ + SAU->CTRL |= (SAU_CTRL_ENABLE_Msk); +} + + + +/** + \brief Disable SAU + \details Disables the Security Attribution Unit (SAU). + */ +__STATIC_INLINE void TZ_SAU_Disable(void) +{ + SAU->CTRL &= ~(SAU_CTRL_ENABLE_Msk); +} + +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + +/*@} end of CMSIS_Core_SAUFunctions */ + + + +/* ################### PAC Key functions ########################### */ + +#if (defined (__ARM_FEATURE_PAUTH) && (__ARM_FEATURE_PAUTH == 1)) +#include "pac_armv81.h" +#endif + + +/* ################################## Debug Control function ############################################ */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_DCBFunctions Debug Control Functions + \brief Functions that access the Debug Control Block. + @{ + */ + + +/** + \brief Set Debug Authentication Control Register + \details writes to Debug Authentication Control register. + \param [in] value value to be writen. + */ +__STATIC_INLINE void DCB_SetAuthCtrl(uint32_t value) +{ + __DSB(); + __ISB(); + DCB->DAUTHCTRL = value; + __DSB(); + __ISB(); +} + + +/** + \brief Get Debug Authentication Control Register + \details Reads Debug Authentication Control register. + \return Debug Authentication Control Register. + */ +__STATIC_INLINE uint32_t DCB_GetAuthCtrl(void) +{ + return (DCB->DAUTHCTRL); +} + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief Set Debug Authentication Control Register (non-secure) + \details writes to non-secure Debug Authentication Control register when in secure state. + \param [in] value value to be writen + */ +__STATIC_INLINE void TZ_DCB_SetAuthCtrl_NS(uint32_t value) +{ + __DSB(); + __ISB(); + DCB_NS->DAUTHCTRL = value; + __DSB(); + __ISB(); +} + + +/** + \brief Get Debug Authentication Control Register (non-secure) + \details Reads non-secure Debug Authentication Control register when in secure state. + \return Debug Authentication Control Register. + */ +__STATIC_INLINE uint32_t TZ_DCB_GetAuthCtrl_NS(void) +{ + return (DCB_NS->DAUTHCTRL); +} +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + +/*@} end of CMSIS_Core_DCBFunctions */ + + + + +/* ################################## Debug Identification function ############################################ */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_DIBFunctions Debug Identification Functions + \brief Functions that access the Debug Identification Block. + @{ + */ + + +/** + \brief Get Debug Authentication Status Register + \details Reads Debug Authentication Status register. + \return Debug Authentication Status Register. + */ +__STATIC_INLINE uint32_t DIB_GetAuthStatus(void) +{ + return (DIB->DAUTHSTATUS); +} + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief Get Debug Authentication Status Register (non-secure) + \details Reads non-secure Debug Authentication Status register when in secure state. + \return Debug Authentication Status Register. + */ +__STATIC_INLINE uint32_t TZ_DIB_GetAuthStatus_NS(void) +{ + return (DIB_NS->DAUTHSTATUS); +} +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + +/*@} end of CMSIS_Core_DCBFunctions */ + + + + +/* ################################## SysTick function ############################################ */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_SysTickFunctions SysTick Functions + \brief Functions that configure the System. + @{ + */ + +#if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U) + +/** + \brief System Tick Configuration + \details Initializes the System Timer and its interrupt, and starts the System Tick Timer. + Counter is in free running mode to generate periodic interrupts. + \param [in] ticks Number of ticks between two interrupts. + \return 0 Function succeeded. + \return 1 Function failed. + \note When the variable __Vendor_SysTickConfig is set to 1, then the + function SysTick_Config is not included. In this case, the file device.h + must contain a vendor-specific implementation of this function. + */ +__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks) +{ + if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk) + { + return (1UL); /* Reload value impossible */ + } + + SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */ + NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */ + SysTick->VAL = 0UL; /* Load the SysTick Counter Value */ + SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | + SysTick_CTRL_TICKINT_Msk | + SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */ + return (0UL); /* Function successful */ +} + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief System Tick Configuration (non-secure) + \details Initializes the non-secure System Timer and its interrupt when in secure state, and starts the System Tick Timer. + Counter is in free running mode to generate periodic interrupts. + \param [in] ticks Number of ticks between two interrupts. + \return 0 Function succeeded. + \return 1 Function failed. + \note When the variable __Vendor_SysTickConfig is set to 1, then the + function TZ_SysTick_Config_NS is not included. In this case, the file device.h + must contain a vendor-specific implementation of this function. + + */ +__STATIC_INLINE uint32_t TZ_SysTick_Config_NS(uint32_t ticks) +{ + if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk) + { + return (1UL); /* Reload value impossible */ + } + + SysTick_NS->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */ + TZ_NVIC_SetPriority_NS (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */ + SysTick_NS->VAL = 0UL; /* Load the SysTick Counter Value */ + SysTick_NS->CTRL = SysTick_CTRL_CLKSOURCE_Msk | + SysTick_CTRL_TICKINT_Msk | + SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */ + return (0UL); /* Function successful */ +} +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + +#endif + +/*@} end of CMSIS_Core_SysTickFunctions */ + + + +/* ##################################### Debug In/Output function ########################################### */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_core_DebugFunctions ITM Functions + \brief Functions that access the ITM debug interface. + @{ + */ + +extern volatile int32_t ITM_RxBuffer; /*!< External variable to receive characters. */ +#define ITM_RXBUFFER_EMPTY ((int32_t)0x5AA55AA5U) /*!< Value identifying \ref ITM_RxBuffer is ready for next character. */ + + +/** + \brief ITM Send Character + \details Transmits a character via the ITM channel 0, and + \li Just returns when no debugger is connected that has booked the output. + \li Is blocking when a debugger is connected, but the previous character sent has not been transmitted. + \param [in] ch Character to transmit. + \returns Character to transmit. + */ +__STATIC_INLINE uint32_t ITM_SendChar (uint32_t ch) +{ + if (((ITM->TCR & ITM_TCR_ITMENA_Msk) != 0UL) && /* ITM enabled */ + ((ITM->TER & 1UL ) != 0UL) ) /* ITM Port #0 enabled */ + { + while (ITM->PORT[0U].u32 == 0UL) + { + __NOP(); + } + ITM->PORT[0U].u8 = (uint8_t)ch; + } + return (ch); +} + + +/** + \brief ITM Receive Character + \details Inputs a character via the external variable \ref ITM_RxBuffer. + \return Received character. + \return -1 No character pending. + */ +__STATIC_INLINE int32_t ITM_ReceiveChar (void) +{ + int32_t ch = -1; /* no character available */ + + if (ITM_RxBuffer != ITM_RXBUFFER_EMPTY) + { + ch = ITM_RxBuffer; + ITM_RxBuffer = ITM_RXBUFFER_EMPTY; /* ready for next character */ + } + + return (ch); +} + + +/** + \brief ITM Check Character + \details Checks whether a character is pending for reading in the variable \ref ITM_RxBuffer. + \return 0 No character available. + \return 1 Character available. + */ +__STATIC_INLINE int32_t ITM_CheckChar (void) +{ + + if (ITM_RxBuffer == ITM_RXBUFFER_EMPTY) + { + return (0); /* no character available */ + } + else + { + return (1); /* character available */ + } +} + +/*@} end of CMSIS_core_DebugFunctions */ + + + + +#ifdef __cplusplus +} +#endif + +#endif /* __CORE_CM85_H_DEPENDANT */ + +#endif /* __CMSIS_GENERIC */ diff --git a/lib/cmsis/inc/core_sc000.h b/lib/cmsis/inc/core_sc000.h index 389535a7cf2c1..dbc755fff39b9 100644 --- a/lib/cmsis/inc/core_sc000.h +++ b/lib/cmsis/inc/core_sc000.h @@ -1,11 +1,11 @@ /**************************************************************************//** * @file core_sc000.h * @brief CMSIS SC000 Core Peripheral Access Layer Header File - * @version V5.0.6 - * @date 12. November 2018 + * @version V5.0.7 + * @date 27. March 2020 ******************************************************************************/ /* - * Copyright (c) 2009-2018 Arm Limited. All rights reserved. + * Copyright (c) 2009-2020 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -62,7 +62,7 @@ #include "cmsis_version.h" -/* CMSIS SC000 definitions */ +/* CMSIS SC000 definitions */ #define __SC000_CMSIS_VERSION_MAIN (__CM_CMSIS_VERSION_MAIN) /*!< \deprecated [31:16] CMSIS HAL main version */ #define __SC000_CMSIS_VERSION_SUB (__CM_CMSIS_VERSION_SUB) /*!< \deprecated [15:0] CMSIS HAL sub version */ #define __SC000_CMSIS_VERSION ((__SC000_CMSIS_VERSION_MAIN << 16U) | \ @@ -142,6 +142,11 @@ #warning "__MPU_PRESENT not defined in device header file; using default!" #endif + #ifndef __VTOR_PRESENT + #define __VTOR_PRESENT 0U + #warning "__VTOR_PRESENT not defined in device header file; using default!" + #endif + #ifndef __NVIC_PRIO_BITS #define __NVIC_PRIO_BITS 2U #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" @@ -750,7 +755,9 @@ __STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) { if ((int32_t)(IRQn) >= 0) { + __COMPILER_BARRIER(); NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __COMPILER_BARRIER(); } } @@ -904,6 +911,7 @@ __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) { uint32_t *vectors = (uint32_t *)SCB->VTOR; vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector; + /* ARM Application Note 321 states that the M0 and M0+ do not require the architectural barrier - assume SC000 is the same */ } diff --git a/lib/cmsis/inc/core_sc300.h b/lib/cmsis/inc/core_sc300.h index 5478ea74a5cfb..d66621031e09b 100644 --- a/lib/cmsis/inc/core_sc300.h +++ b/lib/cmsis/inc/core_sc300.h @@ -1,11 +1,11 @@ /**************************************************************************//** * @file core_sc300.h * @brief CMSIS SC300 Core Peripheral Access Layer Header File - * @version V5.0.7 - * @date 12. November 2018 + * @version V5.0.10 + * @date 04. June 2021 ******************************************************************************/ /* - * Copyright (c) 2009-2018 Arm Limited. All rights reserved. + * Copyright (c) 2009-2021 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -62,7 +62,7 @@ #include "cmsis_version.h" -/* CMSIS SC300 definitions */ +/* CMSIS SC300 definitions */ #define __SC300_CMSIS_VERSION_MAIN (__CM_CMSIS_VERSION_MAIN) /*!< \deprecated [31:16] CMSIS HAL main version */ #define __SC300_CMSIS_VERSION_SUB (__CM_CMSIS_VERSION_SUB) /*!< \deprecated [15:0] CMSIS HAL sub version */ #define __SC300_CMSIS_VERSION ((__SC300_CMSIS_VERSION_MAIN << 16U) | \ @@ -142,6 +142,11 @@ #warning "__MPU_PRESENT not defined in device header file; using default!" #endif + #ifndef __VTOR_PRESENT + #define __VTOR_PRESENT 1U + #warning "__VTOR_PRESENT not defined in device header file; using default!" + #endif + #ifndef __NVIC_PRIO_BITS #define __NVIC_PRIO_BITS 3U #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" @@ -342,7 +347,7 @@ typedef struct __IOM uint32_t ISER[8U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */ uint32_t RESERVED0[24U]; __IOM uint32_t ICER[8U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */ - uint32_t RSERVED1[24U]; + uint32_t RESERVED1[24U]; __IOM uint32_t ISPR[8U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */ uint32_t RESERVED2[24U]; __IOM uint32_t ICPR[8U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */ @@ -557,19 +562,19 @@ typedef struct #define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */ /* MemManage Fault Status Register (part of SCB Configurable Fault Status Register) */ -#define SCB_CFSR_MMARVALID_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */ +#define SCB_CFSR_MMARVALID_Pos (SCB_CFSR_MEMFAULTSR_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */ #define SCB_CFSR_MMARVALID_Msk (1UL << SCB_CFSR_MMARVALID_Pos) /*!< SCB CFSR (MMFSR): MMARVALID Mask */ -#define SCB_CFSR_MSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */ +#define SCB_CFSR_MSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */ #define SCB_CFSR_MSTKERR_Msk (1UL << SCB_CFSR_MSTKERR_Pos) /*!< SCB CFSR (MMFSR): MSTKERR Mask */ -#define SCB_CFSR_MUNSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */ +#define SCB_CFSR_MUNSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */ #define SCB_CFSR_MUNSTKERR_Msk (1UL << SCB_CFSR_MUNSTKERR_Pos) /*!< SCB CFSR (MMFSR): MUNSTKERR Mask */ -#define SCB_CFSR_DACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */ +#define SCB_CFSR_DACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */ #define SCB_CFSR_DACCVIOL_Msk (1UL << SCB_CFSR_DACCVIOL_Pos) /*!< SCB CFSR (MMFSR): DACCVIOL Mask */ -#define SCB_CFSR_IACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */ +#define SCB_CFSR_IACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */ #define SCB_CFSR_IACCVIOL_Msk (1UL /*<< SCB_CFSR_IACCVIOL_Pos*/) /*!< SCB CFSR (MMFSR): IACCVIOL Mask */ /* BusFault Status Register (part of SCB Configurable Fault Status Register) */ @@ -653,13 +658,23 @@ typedef struct { uint32_t RESERVED0[1U]; __IM uint32_t ICTR; /*!< Offset: 0x004 (R/ ) Interrupt Controller Type Register */ - uint32_t RESERVED1[1U]; + __IOM uint32_t ACTLR; /*!< Offset: 0x008 (R/W) Auxiliary Control Register */ } SCnSCB_Type; /* Interrupt Controller Type Register Definitions */ #define SCnSCB_ICTR_INTLINESNUM_Pos 0U /*!< ICTR: INTLINESNUM Position */ #define SCnSCB_ICTR_INTLINESNUM_Msk (0xFUL /*<< SCnSCB_ICTR_INTLINESNUM_Pos*/) /*!< ICTR: INTLINESNUM Mask */ +/* Auxiliary Control Register Definitions */ +#define SCnSCB_ACTLR_DISFOLD_Pos 2U /*!< ACTLR: DISFOLD Position */ +#define SCnSCB_ACTLR_DISFOLD_Msk (1UL << SCnSCB_ACTLR_DISFOLD_Pos) /*!< ACTLR: DISFOLD Mask */ + +#define SCnSCB_ACTLR_DISDEFWBUF_Pos 1U /*!< ACTLR: DISDEFWBUF Position */ +#define SCnSCB_ACTLR_DISDEFWBUF_Msk (1UL << SCnSCB_ACTLR_DISDEFWBUF_Pos) /*!< ACTLR: DISDEFWBUF Mask */ + +#define SCnSCB_ACTLR_DISMCYCINT_Pos 0U /*!< ACTLR: DISMCYCINT Position */ +#define SCnSCB_ACTLR_DISMCYCINT_Msk (1UL /*<< SCnSCB_ACTLR_DISMCYCINT_Pos*/) /*!< ACTLR: DISMCYCINT Mask */ + /*@} end of group CMSIS_SCnotSCB */ @@ -739,10 +754,7 @@ typedef struct __IOM uint32_t TPR; /*!< Offset: 0xE40 (R/W) ITM Trace Privilege Register */ uint32_t RESERVED2[15U]; __IOM uint32_t TCR; /*!< Offset: 0xE80 (R/W) ITM Trace Control Register */ - uint32_t RESERVED3[29U]; - __OM uint32_t IWR; /*!< Offset: 0xEF8 ( /W) ITM Integration Write Register */ - __IM uint32_t IRR; /*!< Offset: 0xEFC (R/ ) ITM Integration Read Register */ - __IOM uint32_t IMCR; /*!< Offset: 0xF00 (R/W) ITM Integration Mode Control Register */ + uint32_t RESERVED3[32U]; uint32_t RESERVED4[43U]; __OM uint32_t LAR; /*!< Offset: 0xFB0 ( /W) ITM Lock Access Register */ __IM uint32_t LSR; /*!< Offset: 0xFB4 (R/ ) ITM Lock Status Register */ @@ -793,18 +805,6 @@ typedef struct #define ITM_TCR_ITMENA_Pos 0U /*!< ITM TCR: ITM Enable bit Position */ #define ITM_TCR_ITMENA_Msk (1UL /*<< ITM_TCR_ITMENA_Pos*/) /*!< ITM TCR: ITM Enable bit Mask */ -/* ITM Integration Write Register Definitions */ -#define ITM_IWR_ATVALIDM_Pos 0U /*!< ITM IWR: ATVALIDM Position */ -#define ITM_IWR_ATVALIDM_Msk (1UL /*<< ITM_IWR_ATVALIDM_Pos*/) /*!< ITM IWR: ATVALIDM Mask */ - -/* ITM Integration Read Register Definitions */ -#define ITM_IRR_ATREADYM_Pos 0U /*!< ITM IRR: ATREADYM Position */ -#define ITM_IRR_ATREADYM_Msk (1UL /*<< ITM_IRR_ATREADYM_Pos*/) /*!< ITM IRR: ATREADYM Mask */ - -/* ITM Integration Mode Control Register Definitions */ -#define ITM_IMCR_INTEGRATION_Pos 0U /*!< ITM IMCR: INTEGRATION Position */ -#define ITM_IMCR_INTEGRATION_Msk (1UL /*<< ITM_IMCR_INTEGRATION_Pos*/) /*!< ITM IMCR: INTEGRATION Mask */ - /* ITM Lock Status Register Definitions */ #define ITM_LSR_ByteAcc_Pos 2U /*!< ITM LSR: ByteAcc Position */ #define ITM_LSR_ByteAcc_Msk (1UL << ITM_LSR_ByteAcc_Pos) /*!< ITM LSR: ByteAcc Mask */ @@ -1037,13 +1037,13 @@ typedef struct /* TPI Integration ETM Data Register Definitions (FIFO0) */ #define TPI_FIFO0_ITM_ATVALID_Pos 29U /*!< TPI FIFO0: ITM_ATVALID Position */ -#define TPI_FIFO0_ITM_ATVALID_Msk (0x3UL << TPI_FIFO0_ITM_ATVALID_Pos) /*!< TPI FIFO0: ITM_ATVALID Mask */ +#define TPI_FIFO0_ITM_ATVALID_Msk (0x1UL << TPI_FIFO0_ITM_ATVALID_Pos) /*!< TPI FIFO0: ITM_ATVALID Mask */ #define TPI_FIFO0_ITM_bytecount_Pos 27U /*!< TPI FIFO0: ITM_bytecount Position */ #define TPI_FIFO0_ITM_bytecount_Msk (0x3UL << TPI_FIFO0_ITM_bytecount_Pos) /*!< TPI FIFO0: ITM_bytecount Mask */ #define TPI_FIFO0_ETM_ATVALID_Pos 26U /*!< TPI FIFO0: ETM_ATVALID Position */ -#define TPI_FIFO0_ETM_ATVALID_Msk (0x3UL << TPI_FIFO0_ETM_ATVALID_Pos) /*!< TPI FIFO0: ETM_ATVALID Mask */ +#define TPI_FIFO0_ETM_ATVALID_Msk (0x1UL << TPI_FIFO0_ETM_ATVALID_Pos) /*!< TPI FIFO0: ETM_ATVALID Mask */ #define TPI_FIFO0_ETM_bytecount_Pos 24U /*!< TPI FIFO0: ETM_bytecount Position */ #define TPI_FIFO0_ETM_bytecount_Msk (0x3UL << TPI_FIFO0_ETM_bytecount_Pos) /*!< TPI FIFO0: ETM_bytecount Mask */ @@ -1066,13 +1066,13 @@ typedef struct /* TPI Integration ITM Data Register Definitions (FIFO1) */ #define TPI_FIFO1_ITM_ATVALID_Pos 29U /*!< TPI FIFO1: ITM_ATVALID Position */ -#define TPI_FIFO1_ITM_ATVALID_Msk (0x3UL << TPI_FIFO1_ITM_ATVALID_Pos) /*!< TPI FIFO1: ITM_ATVALID Mask */ +#define TPI_FIFO1_ITM_ATVALID_Msk (0x1UL << TPI_FIFO1_ITM_ATVALID_Pos) /*!< TPI FIFO1: ITM_ATVALID Mask */ #define TPI_FIFO1_ITM_bytecount_Pos 27U /*!< TPI FIFO1: ITM_bytecount Position */ #define TPI_FIFO1_ITM_bytecount_Msk (0x3UL << TPI_FIFO1_ITM_bytecount_Pos) /*!< TPI FIFO1: ITM_bytecount Mask */ #define TPI_FIFO1_ETM_ATVALID_Pos 26U /*!< TPI FIFO1: ETM_ATVALID Position */ -#define TPI_FIFO1_ETM_ATVALID_Msk (0x3UL << TPI_FIFO1_ETM_ATVALID_Pos) /*!< TPI FIFO1: ETM_ATVALID Mask */ +#define TPI_FIFO1_ETM_ATVALID_Msk (0x1UL << TPI_FIFO1_ETM_ATVALID_Pos) /*!< TPI FIFO1: ETM_ATVALID Mask */ #define TPI_FIFO1_ETM_bytecount_Pos 24U /*!< TPI FIFO1: ETM_bytecount Position */ #define TPI_FIFO1_ETM_bytecount_Msk (0x3UL << TPI_FIFO1_ETM_bytecount_Pos) /*!< TPI FIFO1: ETM_bytecount Mask */ @@ -1448,7 +1448,6 @@ typedef struct #define EXC_RETURN_THREAD_PSP (0xFFFFFFFDUL) /* return to Thread mode, uses PSP after return */ - /** \brief Set Priority Grouping \details Sets the priority grouping field using the required unlock sequence. @@ -1467,7 +1466,7 @@ __STATIC_INLINE void __NVIC_SetPriorityGrouping(uint32_t PriorityGroup) reg_value &= ~((uint32_t)(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk)); /* clear bits to change */ reg_value = (reg_value | ((uint32_t)0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | - (PriorityGroupTmp << 8U) ); /* Insert write key and priorty group */ + (PriorityGroupTmp << SCB_AIRCR_PRIGROUP_Pos) ); /* Insert write key and priority group */ SCB->AIRCR = reg_value; } @@ -1493,7 +1492,9 @@ __STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) { if ((int32_t)(IRQn) >= 0) { + __COMPILER_BARRIER(); NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __COMPILER_BARRIER(); } } @@ -1718,6 +1719,7 @@ __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) { uint32_t *vectors = (uint32_t *)SCB->VTOR; vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector; + /* ARM Application Note 321 states that the M3 does not require the architectural barrier */ } diff --git a/lib/cmsis/inc/core_starmc1.h b/lib/cmsis/inc/core_starmc1.h new file mode 100644 index 0000000000000..d86c8d3857ff3 --- /dev/null +++ b/lib/cmsis/inc/core_starmc1.h @@ -0,0 +1,3592 @@ +/**************************************************************************//** + * @file core_starmc1.h + * @brief CMSIS ArmChina STAR-MC1 Core Peripheral Access Layer Header File + * @version V1.0.2 + * @date 07. April 2022 + ******************************************************************************/ +/* + * Copyright (c) 2009-2018 Arm Limited. + * Copyright (c) 2018-2022 Arm China. + * All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * + * 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 + * + * 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. + */ + +#if defined ( __ICCARM__ ) + #pragma system_include /* treat file as system include file for MISRA check */ +#elif defined (__clang__) + #pragma clang system_header /* treat file as system include file */ +#elif defined ( __GNUC__ ) + #pragma GCC diagnostic ignored "-Wpedantic" /* disable pedantic warning due to unnamed structs/unions */ +#endif + +#ifndef __CORE_STAR_H_GENERIC +#define __CORE_STAR_H_GENERIC + +#include + +#ifdef __cplusplus + extern "C" { +#endif + +/** + \page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions + CMSIS violates the following MISRA-C:2004 rules: + + \li Required Rule 8.5, object/function definition in header file.
+ Function definitions in header files are used to allow 'inlining'. + + \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.
+ Unions are used for effective representation of core registers. + + \li Advisory Rule 19.7, Function-like macro defined.
+ Function-like macros are used to allow more efficient code. + */ + + +/******************************************************************************* + * CMSIS definitions + ******************************************************************************/ +/** + \ingroup STAR-MC1 + @{ + */ + +#include "cmsis_version.h" + +/* Macro Define for STAR-MC1 */ +#define __STAR_MC (1U) /*!< STAR-MC Core */ + +/** __FPU_USED indicates whether an FPU is used or not. + For this, __FPU_PRESENT has to be checked prior to making use of FPU specific registers and functions. +*/ +#if defined ( __CC_ARM ) + #if defined (__TARGET_FPU_VFP) + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) + #define __FPU_USED 1U + #else + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #define __FPU_USED 0U + #endif + #else + #define __FPU_USED 0U + #endif + + #if defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1U) + #if defined (__DSP_PRESENT) && (__DSP_PRESENT == 1U) + #define __DSP_USED 1U + #else + #error "Compiler generates DSP (SIMD) instructions for a devices without DSP extensions (check __DSP_PRESENT)" + #define __DSP_USED 0U + #endif + #else + #define __DSP_USED 0U + #endif + +#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) + #if defined (__ARM_FP) + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) + #define __FPU_USED 1U + #else + #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #define __FPU_USED 0U + #endif + #else + #define __FPU_USED 0U + #endif + + #if defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1U) + #if defined (__DSP_PRESENT) && (__DSP_PRESENT == 1U) + #define __DSP_USED 1U + #else + #error "Compiler generates DSP (SIMD) instructions for a devices without DSP extensions (check __DSP_PRESENT)" + #define __DSP_USED 0U + #endif + #else + #define __DSP_USED 0U + #endif + +#elif defined ( __GNUC__ ) + #if defined (__VFP_FP__) && !defined(__SOFTFP__) + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) + #define __FPU_USED 1U + #else + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #define __FPU_USED 0U + #endif + #else + #define __FPU_USED 0U + #endif + + #if defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1U) + #if defined (__DSP_PRESENT) && (__DSP_PRESENT == 1U) + #define __DSP_USED 1U + #else + #error "Compiler generates DSP (SIMD) instructions for a devices without DSP extensions (check __DSP_PRESENT)" + #define __DSP_USED 0U + #endif + #else + #define __DSP_USED 0U + #endif + +#elif defined ( __ICCARM__ ) + #if defined (__ARMVFP__) + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) + #define __FPU_USED 1U + #else + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #define __FPU_USED 0U + #endif + #else + #define __FPU_USED 0U + #endif + + #if defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1U) + #if defined (__DSP_PRESENT) && (__DSP_PRESENT == 1U) + #define __DSP_USED 1U + #else + #error "Compiler generates DSP (SIMD) instructions for a devices without DSP extensions (check __DSP_PRESENT)" + #define __DSP_USED 0U + #endif + #else + #define __DSP_USED 0U + #endif + +#elif defined ( __TI_ARM__ ) + #if defined (__TI_VFP_SUPPORT__) + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) + #define __FPU_USED 1U + #else + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #define __FPU_USED 0U + #endif + #else + #define __FPU_USED 0U + #endif + +#elif defined ( __TASKING__ ) + #if defined (__FPU_VFP__) + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) + #define __FPU_USED 1U + #else + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #define __FPU_USED 0U + #endif + #else + #define __FPU_USED 0U + #endif + +#elif defined ( __CSMC__ ) + #if ( __CSMC__ & 0x400U) + #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) + #define __FPU_USED 1U + #else + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #define __FPU_USED 0U + #endif + #else + #define __FPU_USED 0U + #endif + +#endif + +#include "cmsis_compiler.h" /* CMSIS compiler specific defines */ + + +#ifdef __cplusplus +} +#endif + +#endif /* __CORE_STAR_H_GENERIC */ + +#ifndef __CMSIS_GENERIC + +#ifndef __CORE_STAR_H_DEPENDANT +#define __CORE_STAR_H_DEPENDANT + +#ifdef __cplusplus + extern "C" { +#endif + +/* check device defines and use defaults */ +#if defined __CHECK_DEVICE_DEFINES + #ifndef __STAR_REV + #define __STAR_REV 0x0000U + #warning "__STAR_REV not defined in device header file; using default!" + #endif + + #ifndef __FPU_PRESENT + #define __FPU_PRESENT 0U + #warning "__FPU_PRESENT not defined in device header file; using default!" + #endif + + #ifndef __MPU_PRESENT + #define __MPU_PRESENT 0U + #warning "__MPU_PRESENT not defined in device header file; using default!" + #endif + + #ifndef __SAUREGION_PRESENT + #define __SAUREGION_PRESENT 0U + #warning "__SAUREGION_PRESENT not defined in device header file; using default!" + #endif + + #ifndef __DSP_PRESENT + #define __DSP_PRESENT 0U + #warning "__DSP_PRESENT not defined in device header file; using default!" + #endif + + #ifndef __ICACHE_PRESENT + #define __ICACHE_PRESENT 0U + #warning "__ICACHE_PRESENT not defined in device header file; using default!" + #endif + + #ifndef __DCACHE_PRESENT + #define __DCACHE_PRESENT 0U + #warning "__DCACHE_PRESENT not defined in device header file; using default!" + #endif + + #ifndef __DTCM_PRESENT + #define __DTCM_PRESENT 0U + #warning "__DTCM_PRESENT not defined in device header file; using default!" + #endif + + #ifndef __NVIC_PRIO_BITS + #define __NVIC_PRIO_BITS 3U + #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" + #endif + + #ifndef __Vendor_SysTickConfig + #define __Vendor_SysTickConfig 0U + #warning "__Vendor_SysTickConfig not defined in device header file; using default!" + #endif +#endif + +/* IO definitions (access restrictions to peripheral registers) */ +/** + \defgroup CMSIS_glob_defs CMSIS Global Defines + + IO Type Qualifiers are used + \li to specify the access to peripheral variables. + \li for automatic generation of peripheral register debug information. +*/ +#ifdef __cplusplus + #define __I volatile /*!< Defines 'read only' permissions */ +#else + #define __I volatile const /*!< Defines 'read only' permissions */ +#endif +#define __O volatile /*!< Defines 'write only' permissions */ +#define __IO volatile /*!< Defines 'read / write' permissions */ + +/* following defines should be used for structure members */ +#define __IM volatile const /*! Defines 'read only' structure member permissions */ +#define __OM volatile /*! Defines 'write only' structure member permissions */ +#define __IOM volatile /*! Defines 'read / write' structure member permissions */ + +/*@} end of group STAR-MC1 */ + + + +/******************************************************************************* + * Register Abstraction + Core Register contain: + - Core Register + - Core NVIC Register + - Core SCB Register + - Core SysTick Register + - Core Debug Register + - Core MPU Register + - Core SAU Register + - Core FPU Register + ******************************************************************************/ +/** + \defgroup CMSIS_core_register Defines and Type Definitions + \brief Type definitions and defines for STAR-MC1 processor based devices. +*/ + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_CORE Status and Control Registers + \brief Core Register type definitions. + @{ + */ + +/** + \brief Union type to access the Application Program Status Register (APSR). + */ +typedef union +{ + struct + { + uint32_t _reserved0:16; /*!< bit: 0..15 Reserved */ + uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */ + uint32_t _reserved1:7; /*!< bit: 20..26 Reserved */ + uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ + uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ + uint32_t C:1; /*!< bit: 29 Carry condition code flag */ + uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ + uint32_t N:1; /*!< bit: 31 Negative condition code flag */ + } b; /*!< Structure used for bit access */ + uint32_t w; /*!< Type used for word access */ +} APSR_Type; + +/* APSR Register Definitions */ +#define APSR_N_Pos 31U /*!< APSR: N Position */ +#define APSR_N_Msk (1UL << APSR_N_Pos) /*!< APSR: N Mask */ + +#define APSR_Z_Pos 30U /*!< APSR: Z Position */ +#define APSR_Z_Msk (1UL << APSR_Z_Pos) /*!< APSR: Z Mask */ + +#define APSR_C_Pos 29U /*!< APSR: C Position */ +#define APSR_C_Msk (1UL << APSR_C_Pos) /*!< APSR: C Mask */ + +#define APSR_V_Pos 28U /*!< APSR: V Position */ +#define APSR_V_Msk (1UL << APSR_V_Pos) /*!< APSR: V Mask */ + +#define APSR_Q_Pos 27U /*!< APSR: Q Position */ +#define APSR_Q_Msk (1UL << APSR_Q_Pos) /*!< APSR: Q Mask */ + +#define APSR_GE_Pos 16U /*!< APSR: GE Position */ +#define APSR_GE_Msk (0xFUL << APSR_GE_Pos) /*!< APSR: GE Mask */ + + +/** + \brief Union type to access the Interrupt Program Status Register (IPSR). + */ +typedef union +{ + struct + { + uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ + uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */ + } b; /*!< Structure used for bit access */ + uint32_t w; /*!< Type used for word access */ +} IPSR_Type; + +/* IPSR Register Definitions */ +#define IPSR_ISR_Pos 0U /*!< IPSR: ISR Position */ +#define IPSR_ISR_Msk (0x1FFUL /*<< IPSR_ISR_Pos*/) /*!< IPSR: ISR Mask */ + + +/** + \brief Union type to access the Special-Purpose Program Status Registers (xPSR). + */ +typedef union +{ + struct + { + uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ + uint32_t _reserved0:7; /*!< bit: 9..15 Reserved */ + uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */ + uint32_t _reserved1:4; /*!< bit: 20..23 Reserved */ + uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */ + uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */ + uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ + uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ + uint32_t C:1; /*!< bit: 29 Carry condition code flag */ + uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ + uint32_t N:1; /*!< bit: 31 Negative condition code flag */ + } b; /*!< Structure used for bit access */ + uint32_t w; /*!< Type used for word access */ +} xPSR_Type; + +/* xPSR Register Definitions */ +#define xPSR_N_Pos 31U /*!< xPSR: N Position */ +#define xPSR_N_Msk (1UL << xPSR_N_Pos) /*!< xPSR: N Mask */ + +#define xPSR_Z_Pos 30U /*!< xPSR: Z Position */ +#define xPSR_Z_Msk (1UL << xPSR_Z_Pos) /*!< xPSR: Z Mask */ + +#define xPSR_C_Pos 29U /*!< xPSR: C Position */ +#define xPSR_C_Msk (1UL << xPSR_C_Pos) /*!< xPSR: C Mask */ + +#define xPSR_V_Pos 28U /*!< xPSR: V Position */ +#define xPSR_V_Msk (1UL << xPSR_V_Pos) /*!< xPSR: V Mask */ + +#define xPSR_Q_Pos 27U /*!< xPSR: Q Position */ +#define xPSR_Q_Msk (1UL << xPSR_Q_Pos) /*!< xPSR: Q Mask */ + +#define xPSR_IT_Pos 25U /*!< xPSR: IT Position */ +#define xPSR_IT_Msk (3UL << xPSR_IT_Pos) /*!< xPSR: IT Mask */ + +#define xPSR_T_Pos 24U /*!< xPSR: T Position */ +#define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */ + +#define xPSR_GE_Pos 16U /*!< xPSR: GE Position */ +#define xPSR_GE_Msk (0xFUL << xPSR_GE_Pos) /*!< xPSR: GE Mask */ + +#define xPSR_ISR_Pos 0U /*!< xPSR: ISR Position */ +#define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */ + + +/** + \brief Union type to access the Control Registers (CONTROL). + */ +typedef union +{ + struct + { + uint32_t nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */ + uint32_t SPSEL:1; /*!< bit: 1 Stack-pointer select */ + uint32_t FPCA:1; /*!< bit: 2 Floating-point context active */ + uint32_t SFPA:1; /*!< bit: 3 Secure floating-point active */ + uint32_t _reserved1:28; /*!< bit: 4..31 Reserved */ + } b; /*!< Structure used for bit access */ + uint32_t w; /*!< Type used for word access */ +} CONTROL_Type; + +/* CONTROL Register Definitions */ +#define CONTROL_SFPA_Pos 3U /*!< CONTROL: SFPA Position */ +#define CONTROL_SFPA_Msk (1UL << CONTROL_SFPA_Pos) /*!< CONTROL: SFPA Mask */ + +#define CONTROL_FPCA_Pos 2U /*!< CONTROL: FPCA Position */ +#define CONTROL_FPCA_Msk (1UL << CONTROL_FPCA_Pos) /*!< CONTROL: FPCA Mask */ + +#define CONTROL_SPSEL_Pos 1U /*!< CONTROL: SPSEL Position */ +#define CONTROL_SPSEL_Msk (1UL << CONTROL_SPSEL_Pos) /*!< CONTROL: SPSEL Mask */ + +#define CONTROL_nPRIV_Pos 0U /*!< CONTROL: nPRIV Position */ +#define CONTROL_nPRIV_Msk (1UL /*<< CONTROL_nPRIV_Pos*/) /*!< CONTROL: nPRIV Mask */ + +/*@} end of group CMSIS_CORE */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC) + \brief Type definitions for the NVIC Registers + @{ + */ + +/** + \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC). + */ +typedef struct +{ + __IOM uint32_t ISER[16U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */ + uint32_t RESERVED0[16U]; + __IOM uint32_t ICER[16U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */ + uint32_t RSERVED1[16U]; + __IOM uint32_t ISPR[16U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */ + uint32_t RESERVED2[16U]; + __IOM uint32_t ICPR[16U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */ + uint32_t RESERVED3[16U]; + __IOM uint32_t IABR[16U]; /*!< Offset: 0x200 (R/W) Interrupt Active bit Register */ + uint32_t RESERVED4[16U]; + __IOM uint32_t ITNS[16U]; /*!< Offset: 0x280 (R/W) Interrupt Non-Secure State Register */ + uint32_t RESERVED5[16U]; + __IOM uint8_t IPR[496U]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register (8Bit wide) */ + uint32_t RESERVED6[580U]; + __OM uint32_t STIR; /*!< Offset: 0xE00 ( /W) Software Trigger Interrupt Register */ +} NVIC_Type; + +/* Software Triggered Interrupt Register Definitions */ +#define NVIC_STIR_INTID_Pos 0U /*!< STIR: INTLINESNUM Position */ +#define NVIC_STIR_INTID_Msk (0x1FFUL /*<< NVIC_STIR_INTID_Pos*/) /*!< STIR: INTLINESNUM Mask */ + +/*@} end of group CMSIS_NVIC */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_SCB System Control Block (SCB) + \brief Type definitions for the System Control Block Registers + @{ + */ + +/** + \brief Structure type to access the System Control Block (SCB). + */ +typedef struct +{ + __IM uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */ + __IOM uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */ + __IOM uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */ + __IOM uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */ + __IOM uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */ + __IOM uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */ + __IOM uint8_t SHPR[12U]; /*!< Offset: 0x018 (R/W) System Handlers Priority Registers (4-7, 8-11, 12-15) */ + __IOM uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */ + __IOM uint32_t CFSR; /*!< Offset: 0x028 (R/W) Configurable Fault Status Register */ + __IOM uint32_t HFSR; /*!< Offset: 0x02C (R/W) HardFault Status Register */ + __IOM uint32_t DFSR; /*!< Offset: 0x030 (R/W) Debug Fault Status Register */ + __IOM uint32_t MMFAR; /*!< Offset: 0x034 (R/W) MemManage Fault Address Register */ + __IOM uint32_t BFAR; /*!< Offset: 0x038 (R/W) BusFault Address Register */ + __IOM uint32_t AFSR; /*!< Offset: 0x03C (R/W) Auxiliary Fault Status Register */ + __IM uint32_t ID_PFR[2U]; /*!< Offset: 0x040 (R/ ) Processor Feature Register */ + __IM uint32_t ID_DFR; /*!< Offset: 0x048 (R/ ) Debug Feature Register */ + __IM uint32_t ID_AFR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */ + __IM uint32_t ID_MMFR[4U]; /*!< Offset: 0x050 (R/ ) Memory Model Feature Register */ + __IM uint32_t ID_ISAR[5U]; /*!< Offset: 0x060 (R/ ) Instruction Set Attributes Register */ + uint32_t RESERVED0[1U]; + __IM uint32_t CLIDR; /*!< Offset: 0x078 (R/ ) Cache Level ID register */ + __IM uint32_t CTR; /*!< Offset: 0x07C (R/ ) Cache Type register */ + __IM uint32_t CCSIDR; /*!< Offset: 0x080 (R/ ) Cache Size ID Register */ + __IOM uint32_t CSSELR; /*!< Offset: 0x084 (R/W) Cache Size Selection Register */ + __IOM uint32_t CPACR; /*!< Offset: 0x088 (R/W) Coprocessor Access Control Register */ + __IOM uint32_t NSACR; /*!< Offset: 0x08C (R/W) Non-Secure Access Control Register */ + uint32_t RESERVED_ADD1[21U]; + __IOM uint32_t SFSR; /*!< Offset: 0x0E4 (R/W) Secure Fault Status Register */ + __IOM uint32_t SFAR; /*!< Offset: 0x0E8 (R/W) Secure Fault Address Register */ + uint32_t RESERVED3[69U]; + __OM uint32_t STIR; /*!< Offset: F00-D00=0x200 ( /W) Software Triggered Interrupt Register */ + uint32_t RESERVED4[15U]; + __IM uint32_t MVFR0; /*!< Offset: 0x240 (R/ ) Media and VFP Feature Register 0 */ + __IM uint32_t MVFR1; /*!< Offset: 0x244 (R/ ) Media and VFP Feature Register 1 */ + __IM uint32_t MVFR2; /*!< Offset: 0x248 (R/ ) Media and VFP Feature Register 2 */ + uint32_t RESERVED5[1U]; + __OM uint32_t ICIALLU; /*!< Offset: 0x250 ( /W) I-Cache Invalidate All to PoU */ + uint32_t RESERVED6[1U]; + __OM uint32_t ICIMVAU; /*!< Offset: 0x258 ( /W) I-Cache Invalidate by MVA to PoU */ + __OM uint32_t DCIMVAC; /*!< Offset: 0x25C ( /W) D-Cache Invalidate by MVA to PoC */ + __OM uint32_t DCISW; /*!< Offset: 0x260 ( /W) D-Cache Invalidate by Set-way */ + __OM uint32_t DCCMVAU; /*!< Offset: 0x264 ( /W) D-Cache Clean by MVA to PoU */ + __OM uint32_t DCCMVAC; /*!< Offset: 0x268 ( /W) D-Cache Clean by MVA to PoC */ + __OM uint32_t DCCSW; /*!< Offset: 0x26C ( /W) D-Cache Clean by Set-way */ + __OM uint32_t DCCIMVAC; /*!< Offset: 0x270 ( /W) D-Cache Clean and Invalidate by MVA to PoC */ + __OM uint32_t DCCISW; /*!< Offset: 0x274 ( /W) D-Cache Clean and Invalidate by Set-way */ +} SCB_Type; + +typedef struct +{ + __IOM uint32_t CACR; /*!< Offset: 0x0 (R/W) L1 Cache Control Register */ + __IOM uint32_t ITCMCR; /*!< Offset: 0x10 (R/W) Instruction Tightly-Coupled Memory Control Register */ + __IOM uint32_t DTCMCR; /*!< Offset: 0x14 (R/W) Data Tightly-Coupled Memory Control Registers */ +}EMSS_Type; + +/* SCB CPUID Register Definitions */ +#define SCB_CPUID_IMPLEMENTER_Pos 24U /*!< SCB CPUID: IMPLEMENTER Position */ +#define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */ + +#define SCB_CPUID_VARIANT_Pos 20U /*!< SCB CPUID: VARIANT Position */ +#define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */ + +#define SCB_CPUID_ARCHITECTURE_Pos 16U /*!< SCB CPUID: ARCHITECTURE Position */ +#define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */ + +#define SCB_CPUID_PARTNO_Pos 4U /*!< SCB CPUID: PARTNO Position */ +#define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */ + +#define SCB_CPUID_REVISION_Pos 0U /*!< SCB CPUID: REVISION Position */ +#define SCB_CPUID_REVISION_Msk (0xFUL /*<< SCB_CPUID_REVISION_Pos*/) /*!< SCB CPUID: REVISION Mask */ + +/* SCB Interrupt Control State Register Definitions */ +#define SCB_ICSR_PENDNMISET_Pos 31U /*!< SCB ICSR: PENDNMISET Position */ +#define SCB_ICSR_PENDNMISET_Msk (1UL << SCB_ICSR_PENDNMISET_Pos) /*!< SCB ICSR: PENDNMISET Mask */ + +#define SCB_ICSR_NMIPENDSET_Pos SCB_ICSR_PENDNMISET_Pos /*!< SCB ICSR: NMIPENDSET Position, backward compatibility */ +#define SCB_ICSR_NMIPENDSET_Msk SCB_ICSR_PENDNMISET_Msk /*!< SCB ICSR: NMIPENDSET Mask, backward compatibility */ + +#define SCB_ICSR_PENDNMICLR_Pos 30U /*!< SCB ICSR: PENDNMICLR Position */ +#define SCB_ICSR_PENDNMICLR_Msk (1UL << SCB_ICSR_PENDNMICLR_Pos) /*!< SCB ICSR: PENDNMICLR Mask */ + +#define SCB_ICSR_PENDSVSET_Pos 28U /*!< SCB ICSR: PENDSVSET Position */ +#define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */ + +#define SCB_ICSR_PENDSVCLR_Pos 27U /*!< SCB ICSR: PENDSVCLR Position */ +#define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */ + +#define SCB_ICSR_PENDSTSET_Pos 26U /*!< SCB ICSR: PENDSTSET Position */ +#define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */ + +#define SCB_ICSR_PENDSTCLR_Pos 25U /*!< SCB ICSR: PENDSTCLR Position */ +#define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */ + +#define SCB_ICSR_STTNS_Pos 24U /*!< SCB ICSR: STTNS Position (Security Extension) */ +#define SCB_ICSR_STTNS_Msk (1UL << SCB_ICSR_STTNS_Pos) /*!< SCB ICSR: STTNS Mask (Security Extension) */ + +#define SCB_ICSR_ISRPREEMPT_Pos 23U /*!< SCB ICSR: ISRPREEMPT Position */ +#define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */ + +#define SCB_ICSR_ISRPENDING_Pos 22U /*!< SCB ICSR: ISRPENDING Position */ +#define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */ + +#define SCB_ICSR_VECTPENDING_Pos 12U /*!< SCB ICSR: VECTPENDING Position */ +#define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */ + +#define SCB_ICSR_RETTOBASE_Pos 11U /*!< SCB ICSR: RETTOBASE Position */ +#define SCB_ICSR_RETTOBASE_Msk (1UL << SCB_ICSR_RETTOBASE_Pos) /*!< SCB ICSR: RETTOBASE Mask */ + +#define SCB_ICSR_VECTACTIVE_Pos 0U /*!< SCB ICSR: VECTACTIVE Position */ +#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/) /*!< SCB ICSR: VECTACTIVE Mask */ + +/* SCB Vector Table Offset Register Definitions */ +#define SCB_VTOR_TBLOFF_Pos 7U /*!< SCB VTOR: TBLOFF Position */ +#define SCB_VTOR_TBLOFF_Msk (0x1FFFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF Mask */ + +/* SCB Application Interrupt and Reset Control Register Definitions */ +#define SCB_AIRCR_VECTKEY_Pos 16U /*!< SCB AIRCR: VECTKEY Position */ +#define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */ + +#define SCB_AIRCR_VECTKEYSTAT_Pos 16U /*!< SCB AIRCR: VECTKEYSTAT Position */ +#define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */ + +#define SCB_AIRCR_ENDIANESS_Pos 15U /*!< SCB AIRCR: ENDIANESS Position */ +#define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */ + +#define SCB_AIRCR_PRIS_Pos 14U /*!< SCB AIRCR: PRIS Position */ +#define SCB_AIRCR_PRIS_Msk (1UL << SCB_AIRCR_PRIS_Pos) /*!< SCB AIRCR: PRIS Mask */ + +#define SCB_AIRCR_BFHFNMINS_Pos 13U /*!< SCB AIRCR: BFHFNMINS Position */ +#define SCB_AIRCR_BFHFNMINS_Msk (1UL << SCB_AIRCR_BFHFNMINS_Pos) /*!< SCB AIRCR: BFHFNMINS Mask */ + +#define SCB_AIRCR_PRIGROUP_Pos 8U /*!< SCB AIRCR: PRIGROUP Position */ +#define SCB_AIRCR_PRIGROUP_Msk (7UL << SCB_AIRCR_PRIGROUP_Pos) /*!< SCB AIRCR: PRIGROUP Mask */ + +#define SCB_AIRCR_SYSRESETREQS_Pos 3U /*!< SCB AIRCR: SYSRESETREQS Position */ +#define SCB_AIRCR_SYSRESETREQS_Msk (1UL << SCB_AIRCR_SYSRESETREQS_Pos) /*!< SCB AIRCR: SYSRESETREQS Mask */ + +#define SCB_AIRCR_SYSRESETREQ_Pos 2U /*!< SCB AIRCR: SYSRESETREQ Position */ +#define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */ + +#define SCB_AIRCR_VECTCLRACTIVE_Pos 1U /*!< SCB AIRCR: VECTCLRACTIVE Position */ +#define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */ + +/* SCB System Control Register Definitions */ +#define SCB_SCR_SEVONPEND_Pos 4U /*!< SCB SCR: SEVONPEND Position */ +#define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */ + +#define SCB_SCR_SLEEPDEEPS_Pos 3U /*!< SCB SCR: SLEEPDEEPS Position */ +#define SCB_SCR_SLEEPDEEPS_Msk (1UL << SCB_SCR_SLEEPDEEPS_Pos) /*!< SCB SCR: SLEEPDEEPS Mask */ + +#define SCB_SCR_SLEEPDEEP_Pos 2U /*!< SCB SCR: SLEEPDEEP Position */ +#define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */ + +#define SCB_SCR_SLEEPONEXIT_Pos 1U /*!< SCB SCR: SLEEPONEXIT Position */ +#define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */ + +/* SCB Configuration Control Register Definitions */ +#define SCB_CCR_BP_Pos 18U /*!< SCB CCR: BP Position */ +#define SCB_CCR_BP_Msk (1UL << SCB_CCR_BP_Pos) /*!< SCB CCR: BP Mask */ + +#define SCB_CCR_IC_Pos 17U /*!< SCB CCR: IC Position */ +#define SCB_CCR_IC_Msk (1UL << SCB_CCR_IC_Pos) /*!< SCB CCR: IC Mask */ + +#define SCB_CCR_DC_Pos 16U /*!< SCB CCR: DC Position */ +#define SCB_CCR_DC_Msk (1UL << SCB_CCR_DC_Pos) /*!< SCB CCR: DC Mask */ + +#define SCB_CCR_STKOFHFNMIGN_Pos 10U /*!< SCB CCR: STKOFHFNMIGN Position */ +#define SCB_CCR_STKOFHFNMIGN_Msk (1UL << SCB_CCR_STKOFHFNMIGN_Pos) /*!< SCB CCR: STKOFHFNMIGN Mask */ + +#define SCB_CCR_BFHFNMIGN_Pos 8U /*!< SCB CCR: BFHFNMIGN Position */ +#define SCB_CCR_BFHFNMIGN_Msk (1UL << SCB_CCR_BFHFNMIGN_Pos) /*!< SCB CCR: BFHFNMIGN Mask */ + +#define SCB_CCR_DIV_0_TRP_Pos 4U /*!< SCB CCR: DIV_0_TRP Position */ +#define SCB_CCR_DIV_0_TRP_Msk (1UL << SCB_CCR_DIV_0_TRP_Pos) /*!< SCB CCR: DIV_0_TRP Mask */ + +#define SCB_CCR_UNALIGN_TRP_Pos 3U /*!< SCB CCR: UNALIGN_TRP Position */ +#define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */ + +#define SCB_CCR_USERSETMPEND_Pos 1U /*!< SCB CCR: USERSETMPEND Position */ +#define SCB_CCR_USERSETMPEND_Msk (1UL << SCB_CCR_USERSETMPEND_Pos) /*!< SCB CCR: USERSETMPEND Mask */ + +/* SCB System Handler Control and State Register Definitions */ +#define SCB_SHCSR_HARDFAULTPENDED_Pos 21U /*!< SCB SHCSR: HARDFAULTPENDED Position */ +#define SCB_SHCSR_HARDFAULTPENDED_Msk (1UL << SCB_SHCSR_HARDFAULTPENDED_Pos) /*!< SCB SHCSR: HARDFAULTPENDED Mask */ + +#define SCB_SHCSR_SECUREFAULTPENDED_Pos 20U /*!< SCB SHCSR: SECUREFAULTPENDED Position */ +#define SCB_SHCSR_SECUREFAULTPENDED_Msk (1UL << SCB_SHCSR_SECUREFAULTPENDED_Pos) /*!< SCB SHCSR: SECUREFAULTPENDED Mask */ + +#define SCB_SHCSR_SECUREFAULTENA_Pos 19U /*!< SCB SHCSR: SECUREFAULTENA Position */ +#define SCB_SHCSR_SECUREFAULTENA_Msk (1UL << SCB_SHCSR_SECUREFAULTENA_Pos) /*!< SCB SHCSR: SECUREFAULTENA Mask */ + +#define SCB_SHCSR_USGFAULTENA_Pos 18U /*!< SCB SHCSR: USGFAULTENA Position */ +#define SCB_SHCSR_USGFAULTENA_Msk (1UL << SCB_SHCSR_USGFAULTENA_Pos) /*!< SCB SHCSR: USGFAULTENA Mask */ + +#define SCB_SHCSR_BUSFAULTENA_Pos 17U /*!< SCB SHCSR: BUSFAULTENA Position */ +#define SCB_SHCSR_BUSFAULTENA_Msk (1UL << SCB_SHCSR_BUSFAULTENA_Pos) /*!< SCB SHCSR: BUSFAULTENA Mask */ + +#define SCB_SHCSR_MEMFAULTENA_Pos 16U /*!< SCB SHCSR: MEMFAULTENA Position */ +#define SCB_SHCSR_MEMFAULTENA_Msk (1UL << SCB_SHCSR_MEMFAULTENA_Pos) /*!< SCB SHCSR: MEMFAULTENA Mask */ + +#define SCB_SHCSR_SVCALLPENDED_Pos 15U /*!< SCB SHCSR: SVCALLPENDED Position */ +#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */ + +#define SCB_SHCSR_BUSFAULTPENDED_Pos 14U /*!< SCB SHCSR: BUSFAULTPENDED Position */ +#define SCB_SHCSR_BUSFAULTPENDED_Msk (1UL << SCB_SHCSR_BUSFAULTPENDED_Pos) /*!< SCB SHCSR: BUSFAULTPENDED Mask */ + +#define SCB_SHCSR_MEMFAULTPENDED_Pos 13U /*!< SCB SHCSR: MEMFAULTPENDED Position */ +#define SCB_SHCSR_MEMFAULTPENDED_Msk (1UL << SCB_SHCSR_MEMFAULTPENDED_Pos) /*!< SCB SHCSR: MEMFAULTPENDED Mask */ + +#define SCB_SHCSR_USGFAULTPENDED_Pos 12U /*!< SCB SHCSR: USGFAULTPENDED Position */ +#define SCB_SHCSR_USGFAULTPENDED_Msk (1UL << SCB_SHCSR_USGFAULTPENDED_Pos) /*!< SCB SHCSR: USGFAULTPENDED Mask */ + +#define SCB_SHCSR_SYSTICKACT_Pos 11U /*!< SCB SHCSR: SYSTICKACT Position */ +#define SCB_SHCSR_SYSTICKACT_Msk (1UL << SCB_SHCSR_SYSTICKACT_Pos) /*!< SCB SHCSR: SYSTICKACT Mask */ + +#define SCB_SHCSR_PENDSVACT_Pos 10U /*!< SCB SHCSR: PENDSVACT Position */ +#define SCB_SHCSR_PENDSVACT_Msk (1UL << SCB_SHCSR_PENDSVACT_Pos) /*!< SCB SHCSR: PENDSVACT Mask */ + +#define SCB_SHCSR_MONITORACT_Pos 8U /*!< SCB SHCSR: MONITORACT Position */ +#define SCB_SHCSR_MONITORACT_Msk (1UL << SCB_SHCSR_MONITORACT_Pos) /*!< SCB SHCSR: MONITORACT Mask */ + +#define SCB_SHCSR_SVCALLACT_Pos 7U /*!< SCB SHCSR: SVCALLACT Position */ +#define SCB_SHCSR_SVCALLACT_Msk (1UL << SCB_SHCSR_SVCALLACT_Pos) /*!< SCB SHCSR: SVCALLACT Mask */ + +#define SCB_SHCSR_NMIACT_Pos 5U /*!< SCB SHCSR: NMIACT Position */ +#define SCB_SHCSR_NMIACT_Msk (1UL << SCB_SHCSR_NMIACT_Pos) /*!< SCB SHCSR: NMIACT Mask */ + +#define SCB_SHCSR_SECUREFAULTACT_Pos 4U /*!< SCB SHCSR: SECUREFAULTACT Position */ +#define SCB_SHCSR_SECUREFAULTACT_Msk (1UL << SCB_SHCSR_SECUREFAULTACT_Pos) /*!< SCB SHCSR: SECUREFAULTACT Mask */ + +#define SCB_SHCSR_USGFAULTACT_Pos 3U /*!< SCB SHCSR: USGFAULTACT Position */ +#define SCB_SHCSR_USGFAULTACT_Msk (1UL << SCB_SHCSR_USGFAULTACT_Pos) /*!< SCB SHCSR: USGFAULTACT Mask */ + +#define SCB_SHCSR_HARDFAULTACT_Pos 2U /*!< SCB SHCSR: HARDFAULTACT Position */ +#define SCB_SHCSR_HARDFAULTACT_Msk (1UL << SCB_SHCSR_HARDFAULTACT_Pos) /*!< SCB SHCSR: HARDFAULTACT Mask */ + +#define SCB_SHCSR_BUSFAULTACT_Pos 1U /*!< SCB SHCSR: BUSFAULTACT Position */ +#define SCB_SHCSR_BUSFAULTACT_Msk (1UL << SCB_SHCSR_BUSFAULTACT_Pos) /*!< SCB SHCSR: BUSFAULTACT Mask */ + +#define SCB_SHCSR_MEMFAULTACT_Pos 0U /*!< SCB SHCSR: MEMFAULTACT Position */ +#define SCB_SHCSR_MEMFAULTACT_Msk (1UL /*<< SCB_SHCSR_MEMFAULTACT_Pos*/) /*!< SCB SHCSR: MEMFAULTACT Mask */ + +/* SCB Configurable Fault Status Register Definitions */ +#define SCB_CFSR_USGFAULTSR_Pos 16U /*!< SCB CFSR: Usage Fault Status Register Position */ +#define SCB_CFSR_USGFAULTSR_Msk (0xFFFFUL << SCB_CFSR_USGFAULTSR_Pos) /*!< SCB CFSR: Usage Fault Status Register Mask */ + +#define SCB_CFSR_BUSFAULTSR_Pos 8U /*!< SCB CFSR: Bus Fault Status Register Position */ +#define SCB_CFSR_BUSFAULTSR_Msk (0xFFUL << SCB_CFSR_BUSFAULTSR_Pos) /*!< SCB CFSR: Bus Fault Status Register Mask */ + +#define SCB_CFSR_MEMFAULTSR_Pos 0U /*!< SCB CFSR: Memory Manage Fault Status Register Position */ +#define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */ + +/* MemManage Fault Status Register (part of SCB Configurable Fault Status Register) */ +#define SCB_CFSR_MMARVALID_Pos (SCB_CFSR_MEMFAULTSR_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */ +#define SCB_CFSR_MMARVALID_Msk (1UL << SCB_CFSR_MMARVALID_Pos) /*!< SCB CFSR (MMFSR): MMARVALID Mask */ + +#define SCB_CFSR_MLSPERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 5U) /*!< SCB CFSR (MMFSR): MLSPERR Position */ +#define SCB_CFSR_MLSPERR_Msk (1UL << SCB_CFSR_MLSPERR_Pos) /*!< SCB CFSR (MMFSR): MLSPERR Mask */ + +#define SCB_CFSR_MSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */ +#define SCB_CFSR_MSTKERR_Msk (1UL << SCB_CFSR_MSTKERR_Pos) /*!< SCB CFSR (MMFSR): MSTKERR Mask */ + +#define SCB_CFSR_MUNSTKERR_Pos (SCB_CFSR_MEMFAULTSR_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */ +#define SCB_CFSR_MUNSTKERR_Msk (1UL << SCB_CFSR_MUNSTKERR_Pos) /*!< SCB CFSR (MMFSR): MUNSTKERR Mask */ + +#define SCB_CFSR_DACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */ +#define SCB_CFSR_DACCVIOL_Msk (1UL << SCB_CFSR_DACCVIOL_Pos) /*!< SCB CFSR (MMFSR): DACCVIOL Mask */ + +#define SCB_CFSR_IACCVIOL_Pos (SCB_CFSR_MEMFAULTSR_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */ +#define SCB_CFSR_IACCVIOL_Msk (1UL /*<< SCB_CFSR_IACCVIOL_Pos*/) /*!< SCB CFSR (MMFSR): IACCVIOL Mask */ + +/* BusFault Status Register (part of SCB Configurable Fault Status Register) */ +#define SCB_CFSR_BFARVALID_Pos (SCB_CFSR_BUSFAULTSR_Pos + 7U) /*!< SCB CFSR (BFSR): BFARVALID Position */ +#define SCB_CFSR_BFARVALID_Msk (1UL << SCB_CFSR_BFARVALID_Pos) /*!< SCB CFSR (BFSR): BFARVALID Mask */ + +#define SCB_CFSR_LSPERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 5U) /*!< SCB CFSR (BFSR): LSPERR Position */ +#define SCB_CFSR_LSPERR_Msk (1UL << SCB_CFSR_LSPERR_Pos) /*!< SCB CFSR (BFSR): LSPERR Mask */ + +#define SCB_CFSR_STKERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 4U) /*!< SCB CFSR (BFSR): STKERR Position */ +#define SCB_CFSR_STKERR_Msk (1UL << SCB_CFSR_STKERR_Pos) /*!< SCB CFSR (BFSR): STKERR Mask */ + +#define SCB_CFSR_UNSTKERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 3U) /*!< SCB CFSR (BFSR): UNSTKERR Position */ +#define SCB_CFSR_UNSTKERR_Msk (1UL << SCB_CFSR_UNSTKERR_Pos) /*!< SCB CFSR (BFSR): UNSTKERR Mask */ + +#define SCB_CFSR_IMPRECISERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 2U) /*!< SCB CFSR (BFSR): IMPRECISERR Position */ +#define SCB_CFSR_IMPRECISERR_Msk (1UL << SCB_CFSR_IMPRECISERR_Pos) /*!< SCB CFSR (BFSR): IMPRECISERR Mask */ + +#define SCB_CFSR_PRECISERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 1U) /*!< SCB CFSR (BFSR): PRECISERR Position */ +#define SCB_CFSR_PRECISERR_Msk (1UL << SCB_CFSR_PRECISERR_Pos) /*!< SCB CFSR (BFSR): PRECISERR Mask */ + +#define SCB_CFSR_IBUSERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 0U) /*!< SCB CFSR (BFSR): IBUSERR Position */ +#define SCB_CFSR_IBUSERR_Msk (1UL << SCB_CFSR_IBUSERR_Pos) /*!< SCB CFSR (BFSR): IBUSERR Mask */ + +/* UsageFault Status Register (part of SCB Configurable Fault Status Register) */ +#define SCB_CFSR_DIVBYZERO_Pos (SCB_CFSR_USGFAULTSR_Pos + 9U) /*!< SCB CFSR (UFSR): DIVBYZERO Position */ +#define SCB_CFSR_DIVBYZERO_Msk (1UL << SCB_CFSR_DIVBYZERO_Pos) /*!< SCB CFSR (UFSR): DIVBYZERO Mask */ + +#define SCB_CFSR_UNALIGNED_Pos (SCB_CFSR_USGFAULTSR_Pos + 8U) /*!< SCB CFSR (UFSR): UNALIGNED Position */ +#define SCB_CFSR_UNALIGNED_Msk (1UL << SCB_CFSR_UNALIGNED_Pos) /*!< SCB CFSR (UFSR): UNALIGNED Mask */ + +#define SCB_CFSR_STKOF_Pos (SCB_CFSR_USGFAULTSR_Pos + 4U) /*!< SCB CFSR (UFSR): STKOF Position */ +#define SCB_CFSR_STKOF_Msk (1UL << SCB_CFSR_STKOF_Pos) /*!< SCB CFSR (UFSR): STKOF Mask */ + +#define SCB_CFSR_NOCP_Pos (SCB_CFSR_USGFAULTSR_Pos + 3U) /*!< SCB CFSR (UFSR): NOCP Position */ +#define SCB_CFSR_NOCP_Msk (1UL << SCB_CFSR_NOCP_Pos) /*!< SCB CFSR (UFSR): NOCP Mask */ + +#define SCB_CFSR_INVPC_Pos (SCB_CFSR_USGFAULTSR_Pos + 2U) /*!< SCB CFSR (UFSR): INVPC Position */ +#define SCB_CFSR_INVPC_Msk (1UL << SCB_CFSR_INVPC_Pos) /*!< SCB CFSR (UFSR): INVPC Mask */ + +#define SCB_CFSR_INVSTATE_Pos (SCB_CFSR_USGFAULTSR_Pos + 1U) /*!< SCB CFSR (UFSR): INVSTATE Position */ +#define SCB_CFSR_INVSTATE_Msk (1UL << SCB_CFSR_INVSTATE_Pos) /*!< SCB CFSR (UFSR): INVSTATE Mask */ + +#define SCB_CFSR_UNDEFINSTR_Pos (SCB_CFSR_USGFAULTSR_Pos + 0U) /*!< SCB CFSR (UFSR): UNDEFINSTR Position */ +#define SCB_CFSR_UNDEFINSTR_Msk (1UL << SCB_CFSR_UNDEFINSTR_Pos) /*!< SCB CFSR (UFSR): UNDEFINSTR Mask */ + +/* SCB Hard Fault Status Register Definitions */ +#define SCB_HFSR_DEBUGEVT_Pos 31U /*!< SCB HFSR: DEBUGEVT Position */ +#define SCB_HFSR_DEBUGEVT_Msk (1UL << SCB_HFSR_DEBUGEVT_Pos) /*!< SCB HFSR: DEBUGEVT Mask */ + +#define SCB_HFSR_FORCED_Pos 30U /*!< SCB HFSR: FORCED Position */ +#define SCB_HFSR_FORCED_Msk (1UL << SCB_HFSR_FORCED_Pos) /*!< SCB HFSR: FORCED Mask */ + +#define SCB_HFSR_VECTTBL_Pos 1U /*!< SCB HFSR: VECTTBL Position */ +#define SCB_HFSR_VECTTBL_Msk (1UL << SCB_HFSR_VECTTBL_Pos) /*!< SCB HFSR: VECTTBL Mask */ + +/* SCB Debug Fault Status Register Definitions */ +#define SCB_DFSR_EXTERNAL_Pos 4U /*!< SCB DFSR: EXTERNAL Position */ +#define SCB_DFSR_EXTERNAL_Msk (1UL << SCB_DFSR_EXTERNAL_Pos) /*!< SCB DFSR: EXTERNAL Mask */ + +#define SCB_DFSR_VCATCH_Pos 3U /*!< SCB DFSR: VCATCH Position */ +#define SCB_DFSR_VCATCH_Msk (1UL << SCB_DFSR_VCATCH_Pos) /*!< SCB DFSR: VCATCH Mask */ + +#define SCB_DFSR_DWTTRAP_Pos 2U /*!< SCB DFSR: DWTTRAP Position */ +#define SCB_DFSR_DWTTRAP_Msk (1UL << SCB_DFSR_DWTTRAP_Pos) /*!< SCB DFSR: DWTTRAP Mask */ + +#define SCB_DFSR_BKPT_Pos 1U /*!< SCB DFSR: BKPT Position */ +#define SCB_DFSR_BKPT_Msk (1UL << SCB_DFSR_BKPT_Pos) /*!< SCB DFSR: BKPT Mask */ + +#define SCB_DFSR_HALTED_Pos 0U /*!< SCB DFSR: HALTED Position */ +#define SCB_DFSR_HALTED_Msk (1UL /*<< SCB_DFSR_HALTED_Pos*/) /*!< SCB DFSR: HALTED Mask */ + +/* SCB Non-Secure Access Control Register Definitions */ +#define SCB_NSACR_CP11_Pos 11U /*!< SCB NSACR: CP11 Position */ +#define SCB_NSACR_CP11_Msk (1UL << SCB_NSACR_CP11_Pos) /*!< SCB NSACR: CP11 Mask */ + +#define SCB_NSACR_CP10_Pos 10U /*!< SCB NSACR: CP10 Position */ +#define SCB_NSACR_CP10_Msk (1UL << SCB_NSACR_CP10_Pos) /*!< SCB NSACR: CP10 Mask */ + +#define SCB_NSACR_CPn_Pos 0U /*!< SCB NSACR: CPn Position */ +#define SCB_NSACR_CPn_Msk (1UL /*<< SCB_NSACR_CPn_Pos*/) /*!< SCB NSACR: CPn Mask */ + +/* SCB Cache Level ID Register Definitions */ +#define SCB_CLIDR_LOUU_Pos 27U /*!< SCB CLIDR: LoUU Position */ +#define SCB_CLIDR_LOUU_Msk (7UL << SCB_CLIDR_LOUU_Pos) /*!< SCB CLIDR: LoUU Mask */ + +#define SCB_CLIDR_LOC_Pos 24U /*!< SCB CLIDR: LoC Position */ +#define SCB_CLIDR_LOC_Msk (7UL << SCB_CLIDR_LOC_Pos) /*!< SCB CLIDR: LoC Mask */ + +#define SCB_CLIDR_IC_Pos 0U /*!< SCB CLIDR: IC Position */ +#define SCB_CLIDR_IC_Msk (1UL << SCB_CLIDR_IC_Pos) /*!< SCB CLIDR: IC Mask */ + +#define SCB_CLIDR_DC_Pos 1U /*!< SCB CLIDR: DC Position */ +#define SCB_CLIDR_DC_Msk (1UL << SCB_CLIDR_DC_Pos) /*!< SCB CLIDR: DC Mask */ + + + +/* SCB Cache Type Register Definitions */ +#define SCB_CTR_FORMAT_Pos 29U /*!< SCB CTR: Format Position */ +#define SCB_CTR_FORMAT_Msk (7UL << SCB_CTR_FORMAT_Pos) /*!< SCB CTR: Format Mask */ + +#define SCB_CTR_CWG_Pos 24U /*!< SCB CTR: CWG Position */ +#define SCB_CTR_CWG_Msk (0xFUL << SCB_CTR_CWG_Pos) /*!< SCB CTR: CWG Mask */ + +#define SCB_CTR_ERG_Pos 20U /*!< SCB CTR: ERG Position */ +#define SCB_CTR_ERG_Msk (0xFUL << SCB_CTR_ERG_Pos) /*!< SCB CTR: ERG Mask */ + +#define SCB_CTR_DMINLINE_Pos 16U /*!< SCB CTR: DminLine Position */ +#define SCB_CTR_DMINLINE_Msk (0xFUL << SCB_CTR_DMINLINE_Pos) /*!< SCB CTR: DminLine Mask */ + +#define SCB_CTR_IMINLINE_Pos 0U /*!< SCB CTR: ImInLine Position */ +#define SCB_CTR_IMINLINE_Msk (0xFUL /*<< SCB_CTR_IMINLINE_Pos*/) /*!< SCB CTR: ImInLine Mask */ + +/* SCB Cache Size ID Register Definitions */ +#define SCB_CCSIDR_WT_Pos 31U /*!< SCB CCSIDR: WT Position */ +#define SCB_CCSIDR_WT_Msk (1UL << SCB_CCSIDR_WT_Pos) /*!< SCB CCSIDR: WT Mask */ + +#define SCB_CCSIDR_WB_Pos 30U /*!< SCB CCSIDR: WB Position */ +#define SCB_CCSIDR_WB_Msk (1UL << SCB_CCSIDR_WB_Pos) /*!< SCB CCSIDR: WB Mask */ + +#define SCB_CCSIDR_RA_Pos 29U /*!< SCB CCSIDR: RA Position */ +#define SCB_CCSIDR_RA_Msk (1UL << SCB_CCSIDR_RA_Pos) /*!< SCB CCSIDR: RA Mask */ + +#define SCB_CCSIDR_WA_Pos 28U /*!< SCB CCSIDR: WA Position */ +#define SCB_CCSIDR_WA_Msk (1UL << SCB_CCSIDR_WA_Pos) /*!< SCB CCSIDR: WA Mask */ + +#define SCB_CCSIDR_NUMSETS_Pos 13U /*!< SCB CCSIDR: NumSets Position */ +#define SCB_CCSIDR_NUMSETS_Msk (0x7FFFUL << SCB_CCSIDR_NUMSETS_Pos) /*!< SCB CCSIDR: NumSets Mask */ + +#define SCB_CCSIDR_ASSOCIATIVITY_Pos 3U /*!< SCB CCSIDR: Associativity Position */ +#define SCB_CCSIDR_ASSOCIATIVITY_Msk (0x3FFUL << SCB_CCSIDR_ASSOCIATIVITY_Pos) /*!< SCB CCSIDR: Associativity Mask */ + +#define SCB_CCSIDR_LINESIZE_Pos 0U /*!< SCB CCSIDR: LineSize Position */ +#define SCB_CCSIDR_LINESIZE_Msk (7UL /*<< SCB_CCSIDR_LINESIZE_Pos*/) /*!< SCB CCSIDR: LineSize Mask */ + +/* SCB Cache Size Selection Register Definitions */ +#define SCB_CSSELR_LEVEL_Pos 1U /*!< SCB CSSELR: Level Position */ +#define SCB_CSSELR_LEVEL_Msk (7UL << SCB_CSSELR_LEVEL_Pos) /*!< SCB CSSELR: Level Mask */ + +#define SCB_CSSELR_IND_Pos 0U /*!< SCB CSSELR: InD Position */ +#define SCB_CSSELR_IND_Msk (1UL /*<< SCB_CSSELR_IND_Pos*/) /*!< SCB CSSELR: InD Mask */ + +/* SCB Software Triggered Interrupt Register Definitions */ +#define SCB_STIR_INTID_Pos 0U /*!< SCB STIR: INTID Position */ +#define SCB_STIR_INTID_Msk (0x1FFUL /*<< SCB_STIR_INTID_Pos*/) /*!< SCB STIR: INTID Mask */ + +/* SCB D-Cache line Invalidate by Set-way Register Definitions */ +#define SCB_DCISW_LEVEL_Pos 1U /*!< SCB DCISW: Level Position */ +#define SCB_DCISW_LEVEL_Msk (7UL << SCB_DCISW_LEVEL_Pos) /*!< SCB DCISW: Level Mask */ + +#define SCB_DCISW_WAY_Pos 30U /*!< SCB DCISW: Way Position */ +#define SCB_DCISW_WAY_Msk (3UL << SCB_DCISW_WAY_Pos) /*!< SCB DCISW: Way Mask */ + +#define SCB_DCISW_SET_Pos 5U /*!< SCB DCISW: Set Position */ +#define SCB_DCISW_SET_Msk (0xFFUL << SCB_DCISW_SET_Pos) /*!< SCB DCISW: Set Mask */ + +/* SCB D-Cache Clean line by Set-way Register Definitions */ +#define SCB_DCCSW_LEVEL_Pos 1U /*!< SCB DCCSW: Level Position */ +#define SCB_DCCSW_LEVEL_Msk (7UL << SCB_DCCSW_LEVEL_Pos) /*!< SCB DCCSW: Level Mask */ + +#define SCB_DCCSW_WAY_Pos 30U /*!< SCB DCCSW: Way Position */ +#define SCB_DCCSW_WAY_Msk (3UL << SCB_DCCSW_WAY_Pos) /*!< SCB DCCSW: Way Mask */ + +#define SCB_DCCSW_SET_Pos 5U /*!< SCB DCCSW: Set Position */ +#define SCB_DCCSW_SET_Msk (0xFFUL << SCB_DCCSW_SET_Pos) /*!< SCB DCCSW: Set Mask */ + +/* SCB D-Cache Clean and Invalidate by Set-way Register Definitions */ +#define SCB_DCCISW_LEVEL_Pos 1U /*!< SCB DCCISW: Level Position */ +#define SCB_DCCISW_LEVEL_Msk (7UL << SCB_DCCISW_LEVEL_Pos) /*!< SCB DCCISW: Level Mask */ + +#define SCB_DCCISW_WAY_Pos 30U /*!< SCB DCCISW: Way Position */ +#define SCB_DCCISW_WAY_Msk (3UL << SCB_DCCISW_WAY_Pos) /*!< SCB DCCISW: Way Mask */ + +#define SCB_DCCISW_SET_Pos 5U /*!< SCB DCCISW: Set Position */ +#define SCB_DCCISW_SET_Msk (0xFFUL << SCB_DCCISW_SET_Pos) /*!< SCB DCCISW: Set Mask */ + +/* ArmChina: Implementation Defined */ +/* Instruction Tightly-Coupled Memory Control Register Definitions */ +#define SCB_ITCMCR_SZ_Pos 3U /*!< SCB ITCMCR: SZ Position */ +#define SCB_ITCMCR_SZ_Msk (0xFUL << SCB_ITCMCR_SZ_Pos) /*!< SCB ITCMCR: SZ Mask */ + +#define SCB_ITCMCR_EN_Pos 0U /*!< SCB ITCMCR: EN Position */ +#define SCB_ITCMCR_EN_Msk (1UL /*<< SCB_ITCMCR_EN_Pos*/) /*!< SCB ITCMCR: EN Mask */ + +/* Data Tightly-Coupled Memory Control Register Definitions */ +#define SCB_DTCMCR_SZ_Pos 3U /*!< SCB DTCMCR: SZ Position */ +#define SCB_DTCMCR_SZ_Msk (0xFUL << SCB_DTCMCR_SZ_Pos) /*!< SCB DTCMCR: SZ Mask */ + +#define SCB_DTCMCR_EN_Pos 0U /*!< SCB DTCMCR: EN Position */ +#define SCB_DTCMCR_EN_Msk (1UL /*<< SCB_DTCMCR_EN_Pos*/) /*!< SCB DTCMCR: EN Mask */ + +/* L1 Cache Control Register Definitions */ +#define SCB_CACR_DCCLEAN_Pos 16U /*!< SCB CACR: DCCLEAN Position */ +#define SCB_CACR_DCCLEAN_Msk (1UL << SCB_CACR_FORCEWT_Pos) /*!< SCB CACR: DCCLEAN Mask */ + +#define SCB_CACR_ICACTIVE_Pos 13U /*!< SCB CACR: ICACTIVE Position */ +#define SCB_CACR_ICACTIVE_Msk (1UL << SCB_CACR_FORCEWT_Pos) /*!< SCB CACR: ICACTIVE Mask */ + +#define SCB_CACR_DCACTIVE_Pos 12U /*!< SCB CACR: DCACTIVE Position */ +#define SCB_CACR_DCACTIVE_Msk (1UL << SCB_CACR_FORCEWT_Pos) /*!< SCB CACR: DCACTIVE Mask */ + +#define SCB_CACR_FORCEWT_Pos 2U /*!< SCB CACR: FORCEWT Position */ +#define SCB_CACR_FORCEWT_Msk (1UL << SCB_CACR_FORCEWT_Pos) /*!< SCB CACR: FORCEWT Mask */ + +/*@} end of group CMSIS_SCB */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_SCnSCB System Controls not in SCB (SCnSCB) + \brief Type definitions for the System Control and ID Register not in the SCB + @{ + */ + +/** + \brief Structure type to access the System Control and ID Register not in the SCB. + */ +typedef struct +{ + uint32_t RESERVED0[1U]; + __IM uint32_t ICTR; /*!< Offset: 0x004 (R/ ) Interrupt Controller Type Register */ + __IOM uint32_t ACTLR; /*!< Offset: 0x008 (R/W) Auxiliary Control Register */ + __IOM uint32_t CPPWR; /*!< Offset: 0x00C (R/W) Coprocessor Power Control Register */ +} SCnSCB_Type; + +/* Interrupt Controller Type Register Definitions */ +#define SCnSCB_ICTR_INTLINESNUM_Pos 0U /*!< ICTR: INTLINESNUM Position */ +#define SCnSCB_ICTR_INTLINESNUM_Msk (0xFUL /*<< SCnSCB_ICTR_INTLINESNUM_Pos*/) /*!< ICTR: INTLINESNUM Mask */ + +/*@} end of group CMSIS_SCnotSCB */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_SysTick System Tick Timer (SysTick) + \brief Type definitions for the System Timer Registers. + @{ + */ + +/** + \brief Structure type to access the System Timer (SysTick). + */ +typedef struct +{ + __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */ + __IOM uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */ + __IOM uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */ + __IM uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */ +} SysTick_Type; + +/* SysTick Control / Status Register Definitions */ +#define SysTick_CTRL_COUNTFLAG_Pos 16U /*!< SysTick CTRL: COUNTFLAG Position */ +#define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */ + +#define SysTick_CTRL_CLKSOURCE_Pos 2U /*!< SysTick CTRL: CLKSOURCE Position */ +#define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */ + +#define SysTick_CTRL_TICKINT_Pos 1U /*!< SysTick CTRL: TICKINT Position */ +#define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */ + +#define SysTick_CTRL_ENABLE_Pos 0U /*!< SysTick CTRL: ENABLE Position */ +#define SysTick_CTRL_ENABLE_Msk (1UL /*<< SysTick_CTRL_ENABLE_Pos*/) /*!< SysTick CTRL: ENABLE Mask */ + +/* SysTick Reload Register Definitions */ +#define SysTick_LOAD_RELOAD_Pos 0U /*!< SysTick LOAD: RELOAD Position */ +#define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL /*<< SysTick_LOAD_RELOAD_Pos*/) /*!< SysTick LOAD: RELOAD Mask */ + +/* SysTick Current Register Definitions */ +#define SysTick_VAL_CURRENT_Pos 0U /*!< SysTick VAL: CURRENT Position */ +#define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL /*<< SysTick_VAL_CURRENT_Pos*/) /*!< SysTick VAL: CURRENT Mask */ + +/* SysTick Calibration Register Definitions */ +#define SysTick_CALIB_NOREF_Pos 31U /*!< SysTick CALIB: NOREF Position */ +#define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */ + +#define SysTick_CALIB_SKEW_Pos 30U /*!< SysTick CALIB: SKEW Position */ +#define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */ + +#define SysTick_CALIB_TENMS_Pos 0U /*!< SysTick CALIB: TENMS Position */ +#define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL /*<< SysTick_CALIB_TENMS_Pos*/) /*!< SysTick CALIB: TENMS Mask */ + +/*@} end of group CMSIS_SysTick */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_ITM Instrumentation Trace Macrocell (ITM) + \brief Type definitions for the Instrumentation Trace Macrocell (ITM) + @{ + */ + +/** + \brief Structure type to access the Instrumentation Trace Macrocell Register (ITM). + */ +typedef struct +{ + __OM union + { + __OM uint8_t u8; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 8-bit */ + __OM uint16_t u16; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 16-bit */ + __OM uint32_t u32; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 32-bit */ + } PORT [32U]; /*!< Offset: 0x000 ( /W) ITM Stimulus Port Registers */ + uint32_t RESERVED0[864U]; + __IOM uint32_t TER; /*!< Offset: 0xE00 (R/W) ITM Trace Enable Register */ + uint32_t RESERVED1[15U]; + __IOM uint32_t TPR; /*!< Offset: 0xE40 (R/W) ITM Trace Privilege Register */ + uint32_t RESERVED2[15U]; + __IOM uint32_t TCR; /*!< Offset: 0xE80 (R/W) ITM Trace Control Register */ + uint32_t RESERVED3[32U]; + uint32_t RESERVED4[43U]; + __OM uint32_t LAR; /*!< Offset: 0xFB0 ( /W) ITM Lock Access Register */ + __IM uint32_t LSR; /*!< Offset: 0xFB4 (R/ ) ITM Lock Status Register */ + uint32_t RESERVED5[1U]; + __IM uint32_t DEVARCH; /*!< Offset: 0xFBC (R/ ) ITM Device Architecture Register */ + uint32_t RESERVED6[4U]; + __IM uint32_t PID4; /*!< Offset: 0xFD0 (R/ ) ITM Peripheral Identification Register #4 */ + __IM uint32_t PID5; /*!< Offset: 0xFD4 (R/ ) ITM Peripheral Identification Register #5 */ + __IM uint32_t PID6; /*!< Offset: 0xFD8 (R/ ) ITM Peripheral Identification Register #6 */ + __IM uint32_t PID7; /*!< Offset: 0xFDC (R/ ) ITM Peripheral Identification Register #7 */ + __IM uint32_t PID0; /*!< Offset: 0xFE0 (R/ ) ITM Peripheral Identification Register #0 */ + __IM uint32_t PID1; /*!< Offset: 0xFE4 (R/ ) ITM Peripheral Identification Register #1 */ + __IM uint32_t PID2; /*!< Offset: 0xFE8 (R/ ) ITM Peripheral Identification Register #2 */ + __IM uint32_t PID3; /*!< Offset: 0xFEC (R/ ) ITM Peripheral Identification Register #3 */ + __IM uint32_t CID0; /*!< Offset: 0xFF0 (R/ ) ITM Component Identification Register #0 */ + __IM uint32_t CID1; /*!< Offset: 0xFF4 (R/ ) ITM Component Identification Register #1 */ + __IM uint32_t CID2; /*!< Offset: 0xFF8 (R/ ) ITM Component Identification Register #2 */ + __IM uint32_t CID3; /*!< Offset: 0xFFC (R/ ) ITM Component Identification Register #3 */ +} ITM_Type; + +/* ITM Stimulus Port Register Definitions */ +#define ITM_STIM_DISABLED_Pos 1U /*!< ITM STIM: DISABLED Position */ +#define ITM_STIM_DISABLED_Msk (0x1UL << ITM_STIM_DISABLED_Pos) /*!< ITM STIM: DISABLED Mask */ + +#define ITM_STIM_FIFOREADY_Pos 0U /*!< ITM STIM: FIFOREADY Position */ +#define ITM_STIM_FIFOREADY_Msk (0x1UL /*<< ITM_STIM_FIFOREADY_Pos*/) /*!< ITM STIM: FIFOREADY Mask */ + +/* ITM Trace Privilege Register Definitions */ +#define ITM_TPR_PRIVMASK_Pos 0U /*!< ITM TPR: PRIVMASK Position */ +#define ITM_TPR_PRIVMASK_Msk (0xFFFFFFFFUL /*<< ITM_TPR_PRIVMASK_Pos*/) /*!< ITM TPR: PRIVMASK Mask */ + +/* ITM Trace Control Register Definitions */ +#define ITM_TCR_BUSY_Pos 23U /*!< ITM TCR: BUSY Position */ +#define ITM_TCR_BUSY_Msk (1UL << ITM_TCR_BUSY_Pos) /*!< ITM TCR: BUSY Mask */ + +#define ITM_TCR_TRACEBUSID_Pos 16U /*!< ITM TCR: ATBID Position */ +#define ITM_TCR_TRACEBUSID_Msk (0x7FUL << ITM_TCR_TRACEBUSID_Pos) /*!< ITM TCR: ATBID Mask */ + +#define ITM_TCR_GTSFREQ_Pos 10U /*!< ITM TCR: Global timestamp frequency Position */ +#define ITM_TCR_GTSFREQ_Msk (3UL << ITM_TCR_GTSFREQ_Pos) /*!< ITM TCR: Global timestamp frequency Mask */ + +#define ITM_TCR_TSPRESCALE_Pos 8U /*!< ITM TCR: TSPRESCALE Position */ +#define ITM_TCR_TSPRESCALE_Msk (3UL << ITM_TCR_TSPRESCALE_Pos) /*!< ITM TCR: TSPRESCALE Mask */ + +#define ITM_TCR_STALLENA_Pos 5U /*!< ITM TCR: STALLENA Position */ +#define ITM_TCR_STALLENA_Msk (1UL << ITM_TCR_STALLENA_Pos) /*!< ITM TCR: STALLENA Mask */ + +#define ITM_TCR_SWOENA_Pos 4U /*!< ITM TCR: SWOENA Position */ +#define ITM_TCR_SWOENA_Msk (1UL << ITM_TCR_SWOENA_Pos) /*!< ITM TCR: SWOENA Mask */ + +#define ITM_TCR_DWTENA_Pos 3U /*!< ITM TCR: DWTENA Position */ +#define ITM_TCR_DWTENA_Msk (1UL << ITM_TCR_DWTENA_Pos) /*!< ITM TCR: DWTENA Mask */ + +#define ITM_TCR_SYNCENA_Pos 2U /*!< ITM TCR: SYNCENA Position */ +#define ITM_TCR_SYNCENA_Msk (1UL << ITM_TCR_SYNCENA_Pos) /*!< ITM TCR: SYNCENA Mask */ + +#define ITM_TCR_TSENA_Pos 1U /*!< ITM TCR: TSENA Position */ +#define ITM_TCR_TSENA_Msk (1UL << ITM_TCR_TSENA_Pos) /*!< ITM TCR: TSENA Mask */ + +#define ITM_TCR_ITMENA_Pos 0U /*!< ITM TCR: ITM Enable bit Position */ +#define ITM_TCR_ITMENA_Msk (1UL /*<< ITM_TCR_ITMENA_Pos*/) /*!< ITM TCR: ITM Enable bit Mask */ + +/* ITM Lock Status Register Definitions */ +#define ITM_LSR_ByteAcc_Pos 2U /*!< ITM LSR: ByteAcc Position */ +#define ITM_LSR_ByteAcc_Msk (1UL << ITM_LSR_ByteAcc_Pos) /*!< ITM LSR: ByteAcc Mask */ + +#define ITM_LSR_Access_Pos 1U /*!< ITM LSR: Access Position */ +#define ITM_LSR_Access_Msk (1UL << ITM_LSR_Access_Pos) /*!< ITM LSR: Access Mask */ + +#define ITM_LSR_Present_Pos 0U /*!< ITM LSR: Present Position */ +#define ITM_LSR_Present_Msk (1UL /*<< ITM_LSR_Present_Pos*/) /*!< ITM LSR: Present Mask */ + +/*@}*/ /* end of group CMSIS_ITM */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_DWT Data Watchpoint and Trace (DWT) + \brief Type definitions for the Data Watchpoint and Trace (DWT) + @{ + */ + +/** + \brief Structure type to access the Data Watchpoint and Trace Register (DWT). + */ +typedef struct +{ + __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control Register */ + __IOM uint32_t CYCCNT; /*!< Offset: 0x004 (R/W) Cycle Count Register */ + __IOM uint32_t CPICNT; /*!< Offset: 0x008 (R/W) CPI Count Register */ + __IOM uint32_t EXCCNT; /*!< Offset: 0x00C (R/W) Exception Overhead Count Register */ + __IOM uint32_t SLEEPCNT; /*!< Offset: 0x010 (R/W) Sleep Count Register */ + __IOM uint32_t LSUCNT; /*!< Offset: 0x014 (R/W) LSU Count Register */ + __IOM uint32_t FOLDCNT; /*!< Offset: 0x018 (R/W) Folded-instruction Count Register */ + __IM uint32_t PCSR; /*!< Offset: 0x01C (R/ ) Program Counter Sample Register */ + __IOM uint32_t COMP0; /*!< Offset: 0x020 (R/W) Comparator Register 0 */ + uint32_t RESERVED1[1U]; + __IOM uint32_t FUNCTION0; /*!< Offset: 0x028 (R/W) Function Register 0 */ + uint32_t RESERVED2[1U]; + __IOM uint32_t COMP1; /*!< Offset: 0x030 (R/W) Comparator Register 1 */ + uint32_t RESERVED3[1U]; + __IOM uint32_t FUNCTION1; /*!< Offset: 0x038 (R/W) Function Register 1 */ + uint32_t RESERVED4[1U]; + __IOM uint32_t COMP2; /*!< Offset: 0x040 (R/W) Comparator Register 2 */ + uint32_t RESERVED5[1U]; + __IOM uint32_t FUNCTION2; /*!< Offset: 0x048 (R/W) Function Register 2 */ + uint32_t RESERVED6[1U]; + __IOM uint32_t COMP3; /*!< Offset: 0x050 (R/W) Comparator Register 3 */ + uint32_t RESERVED7[1U]; + __IOM uint32_t FUNCTION3; /*!< Offset: 0x058 (R/W) Function Register 3 */ + uint32_t RESERVED8[1U]; + __IOM uint32_t COMP4; /*!< Offset: 0x060 (R/W) Comparator Register 4 */ + uint32_t RESERVED9[1U]; + __IOM uint32_t FUNCTION4; /*!< Offset: 0x068 (R/W) Function Register 4 */ + uint32_t RESERVED10[1U]; + __IOM uint32_t COMP5; /*!< Offset: 0x070 (R/W) Comparator Register 5 */ + uint32_t RESERVED11[1U]; + __IOM uint32_t FUNCTION5; /*!< Offset: 0x078 (R/W) Function Register 5 */ + uint32_t RESERVED12[1U]; + __IOM uint32_t COMP6; /*!< Offset: 0x080 (R/W) Comparator Register 6 */ + uint32_t RESERVED13[1U]; + __IOM uint32_t FUNCTION6; /*!< Offset: 0x088 (R/W) Function Register 6 */ + uint32_t RESERVED14[1U]; + __IOM uint32_t COMP7; /*!< Offset: 0x090 (R/W) Comparator Register 7 */ + uint32_t RESERVED15[1U]; + __IOM uint32_t FUNCTION7; /*!< Offset: 0x098 (R/W) Function Register 7 */ + uint32_t RESERVED16[1U]; + __IOM uint32_t COMP8; /*!< Offset: 0x0A0 (R/W) Comparator Register 8 */ + uint32_t RESERVED17[1U]; + __IOM uint32_t FUNCTION8; /*!< Offset: 0x0A8 (R/W) Function Register 8 */ + uint32_t RESERVED18[1U]; + __IOM uint32_t COMP9; /*!< Offset: 0x0B0 (R/W) Comparator Register 9 */ + uint32_t RESERVED19[1U]; + __IOM uint32_t FUNCTION9; /*!< Offset: 0x0B8 (R/W) Function Register 9 */ + uint32_t RESERVED20[1U]; + __IOM uint32_t COMP10; /*!< Offset: 0x0C0 (R/W) Comparator Register 10 */ + uint32_t RESERVED21[1U]; + __IOM uint32_t FUNCTION10; /*!< Offset: 0x0C8 (R/W) Function Register 10 */ + uint32_t RESERVED22[1U]; + __IOM uint32_t COMP11; /*!< Offset: 0x0D0 (R/W) Comparator Register 11 */ + uint32_t RESERVED23[1U]; + __IOM uint32_t FUNCTION11; /*!< Offset: 0x0D8 (R/W) Function Register 11 */ + uint32_t RESERVED24[1U]; + __IOM uint32_t COMP12; /*!< Offset: 0x0E0 (R/W) Comparator Register 12 */ + uint32_t RESERVED25[1U]; + __IOM uint32_t FUNCTION12; /*!< Offset: 0x0E8 (R/W) Function Register 12 */ + uint32_t RESERVED26[1U]; + __IOM uint32_t COMP13; /*!< Offset: 0x0F0 (R/W) Comparator Register 13 */ + uint32_t RESERVED27[1U]; + __IOM uint32_t FUNCTION13; /*!< Offset: 0x0F8 (R/W) Function Register 13 */ + uint32_t RESERVED28[1U]; + __IOM uint32_t COMP14; /*!< Offset: 0x100 (R/W) Comparator Register 14 */ + uint32_t RESERVED29[1U]; + __IOM uint32_t FUNCTION14; /*!< Offset: 0x108 (R/W) Function Register 14 */ + uint32_t RESERVED30[1U]; + __IOM uint32_t COMP15; /*!< Offset: 0x110 (R/W) Comparator Register 15 */ + uint32_t RESERVED31[1U]; + __IOM uint32_t FUNCTION15; /*!< Offset: 0x118 (R/W) Function Register 15 */ + uint32_t RESERVED32[934U]; + __IM uint32_t LSR; /*!< Offset: 0xFB4 (R ) Lock Status Register */ + uint32_t RESERVED33[1U]; + __IM uint32_t DEVARCH; /*!< Offset: 0xFBC (R/ ) Device Architecture Register */ +} DWT_Type; + +/* DWT Control Register Definitions */ +#define DWT_CTRL_NUMCOMP_Pos 28U /*!< DWT CTRL: NUMCOMP Position */ +#define DWT_CTRL_NUMCOMP_Msk (0xFUL << DWT_CTRL_NUMCOMP_Pos) /*!< DWT CTRL: NUMCOMP Mask */ + +#define DWT_CTRL_NOTRCPKT_Pos 27U /*!< DWT CTRL: NOTRCPKT Position */ +#define DWT_CTRL_NOTRCPKT_Msk (0x1UL << DWT_CTRL_NOTRCPKT_Pos) /*!< DWT CTRL: NOTRCPKT Mask */ + +#define DWT_CTRL_NOEXTTRIG_Pos 26U /*!< DWT CTRL: NOEXTTRIG Position */ +#define DWT_CTRL_NOEXTTRIG_Msk (0x1UL << DWT_CTRL_NOEXTTRIG_Pos) /*!< DWT CTRL: NOEXTTRIG Mask */ + +#define DWT_CTRL_NOCYCCNT_Pos 25U /*!< DWT CTRL: NOCYCCNT Position */ +#define DWT_CTRL_NOCYCCNT_Msk (0x1UL << DWT_CTRL_NOCYCCNT_Pos) /*!< DWT CTRL: NOCYCCNT Mask */ + +#define DWT_CTRL_NOPRFCNT_Pos 24U /*!< DWT CTRL: NOPRFCNT Position */ +#define DWT_CTRL_NOPRFCNT_Msk (0x1UL << DWT_CTRL_NOPRFCNT_Pos) /*!< DWT CTRL: NOPRFCNT Mask */ + +#define DWT_CTRL_CYCDISS_Pos 23U /*!< DWT CTRL: CYCDISS Position */ +#define DWT_CTRL_CYCDISS_Msk (0x1UL << DWT_CTRL_CYCDISS_Pos) /*!< DWT CTRL: CYCDISS Mask */ + +#define DWT_CTRL_CYCEVTENA_Pos 22U /*!< DWT CTRL: CYCEVTENA Position */ +#define DWT_CTRL_CYCEVTENA_Msk (0x1UL << DWT_CTRL_CYCEVTENA_Pos) /*!< DWT CTRL: CYCEVTENA Mask */ + +#define DWT_CTRL_FOLDEVTENA_Pos 21U /*!< DWT CTRL: FOLDEVTENA Position */ +#define DWT_CTRL_FOLDEVTENA_Msk (0x1UL << DWT_CTRL_FOLDEVTENA_Pos) /*!< DWT CTRL: FOLDEVTENA Mask */ + +#define DWT_CTRL_LSUEVTENA_Pos 20U /*!< DWT CTRL: LSUEVTENA Position */ +#define DWT_CTRL_LSUEVTENA_Msk (0x1UL << DWT_CTRL_LSUEVTENA_Pos) /*!< DWT CTRL: LSUEVTENA Mask */ + +#define DWT_CTRL_SLEEPEVTENA_Pos 19U /*!< DWT CTRL: SLEEPEVTENA Position */ +#define DWT_CTRL_SLEEPEVTENA_Msk (0x1UL << DWT_CTRL_SLEEPEVTENA_Pos) /*!< DWT CTRL: SLEEPEVTENA Mask */ + +#define DWT_CTRL_EXCEVTENA_Pos 18U /*!< DWT CTRL: EXCEVTENA Position */ +#define DWT_CTRL_EXCEVTENA_Msk (0x1UL << DWT_CTRL_EXCEVTENA_Pos) /*!< DWT CTRL: EXCEVTENA Mask */ + +#define DWT_CTRL_CPIEVTENA_Pos 17U /*!< DWT CTRL: CPIEVTENA Position */ +#define DWT_CTRL_CPIEVTENA_Msk (0x1UL << DWT_CTRL_CPIEVTENA_Pos) /*!< DWT CTRL: CPIEVTENA Mask */ + +#define DWT_CTRL_EXCTRCENA_Pos 16U /*!< DWT CTRL: EXCTRCENA Position */ +#define DWT_CTRL_EXCTRCENA_Msk (0x1UL << DWT_CTRL_EXCTRCENA_Pos) /*!< DWT CTRL: EXCTRCENA Mask */ + +#define DWT_CTRL_PCSAMPLENA_Pos 12U /*!< DWT CTRL: PCSAMPLENA Position */ +#define DWT_CTRL_PCSAMPLENA_Msk (0x1UL << DWT_CTRL_PCSAMPLENA_Pos) /*!< DWT CTRL: PCSAMPLENA Mask */ + +#define DWT_CTRL_SYNCTAP_Pos 10U /*!< DWT CTRL: SYNCTAP Position */ +#define DWT_CTRL_SYNCTAP_Msk (0x3UL << DWT_CTRL_SYNCTAP_Pos) /*!< DWT CTRL: SYNCTAP Mask */ + +#define DWT_CTRL_CYCTAP_Pos 9U /*!< DWT CTRL: CYCTAP Position */ +#define DWT_CTRL_CYCTAP_Msk (0x1UL << DWT_CTRL_CYCTAP_Pos) /*!< DWT CTRL: CYCTAP Mask */ + +#define DWT_CTRL_POSTINIT_Pos 5U /*!< DWT CTRL: POSTINIT Position */ +#define DWT_CTRL_POSTINIT_Msk (0xFUL << DWT_CTRL_POSTINIT_Pos) /*!< DWT CTRL: POSTINIT Mask */ + +#define DWT_CTRL_POSTPRESET_Pos 1U /*!< DWT CTRL: POSTPRESET Position */ +#define DWT_CTRL_POSTPRESET_Msk (0xFUL << DWT_CTRL_POSTPRESET_Pos) /*!< DWT CTRL: POSTPRESET Mask */ + +#define DWT_CTRL_CYCCNTENA_Pos 0U /*!< DWT CTRL: CYCCNTENA Position */ +#define DWT_CTRL_CYCCNTENA_Msk (0x1UL /*<< DWT_CTRL_CYCCNTENA_Pos*/) /*!< DWT CTRL: CYCCNTENA Mask */ + +/* DWT CPI Count Register Definitions */ +#define DWT_CPICNT_CPICNT_Pos 0U /*!< DWT CPICNT: CPICNT Position */ +#define DWT_CPICNT_CPICNT_Msk (0xFFUL /*<< DWT_CPICNT_CPICNT_Pos*/) /*!< DWT CPICNT: CPICNT Mask */ + +/* DWT Exception Overhead Count Register Definitions */ +#define DWT_EXCCNT_EXCCNT_Pos 0U /*!< DWT EXCCNT: EXCCNT Position */ +#define DWT_EXCCNT_EXCCNT_Msk (0xFFUL /*<< DWT_EXCCNT_EXCCNT_Pos*/) /*!< DWT EXCCNT: EXCCNT Mask */ + +/* DWT Sleep Count Register Definitions */ +#define DWT_SLEEPCNT_SLEEPCNT_Pos 0U /*!< DWT SLEEPCNT: SLEEPCNT Position */ +#define DWT_SLEEPCNT_SLEEPCNT_Msk (0xFFUL /*<< DWT_SLEEPCNT_SLEEPCNT_Pos*/) /*!< DWT SLEEPCNT: SLEEPCNT Mask */ + +/* DWT LSU Count Register Definitions */ +#define DWT_LSUCNT_LSUCNT_Pos 0U /*!< DWT LSUCNT: LSUCNT Position */ +#define DWT_LSUCNT_LSUCNT_Msk (0xFFUL /*<< DWT_LSUCNT_LSUCNT_Pos*/) /*!< DWT LSUCNT: LSUCNT Mask */ + +/* DWT Folded-instruction Count Register Definitions */ +#define DWT_FOLDCNT_FOLDCNT_Pos 0U /*!< DWT FOLDCNT: FOLDCNT Position */ +#define DWT_FOLDCNT_FOLDCNT_Msk (0xFFUL /*<< DWT_FOLDCNT_FOLDCNT_Pos*/) /*!< DWT FOLDCNT: FOLDCNT Mask */ + +/* DWT Comparator Function Register Definitions */ +#define DWT_FUNCTION_ID_Pos 27U /*!< DWT FUNCTION: ID Position */ +#define DWT_FUNCTION_ID_Msk (0x1FUL << DWT_FUNCTION_ID_Pos) /*!< DWT FUNCTION: ID Mask */ + +#define DWT_FUNCTION_MATCHED_Pos 24U /*!< DWT FUNCTION: MATCHED Position */ +#define DWT_FUNCTION_MATCHED_Msk (0x1UL << DWT_FUNCTION_MATCHED_Pos) /*!< DWT FUNCTION: MATCHED Mask */ + +#define DWT_FUNCTION_DATAVSIZE_Pos 10U /*!< DWT FUNCTION: DATAVSIZE Position */ +#define DWT_FUNCTION_DATAVSIZE_Msk (0x3UL << DWT_FUNCTION_DATAVSIZE_Pos) /*!< DWT FUNCTION: DATAVSIZE Mask */ + +#define DWT_FUNCTION_ACTION_Pos 4U /*!< DWT FUNCTION: ACTION Position */ +#define DWT_FUNCTION_ACTION_Msk (0x1UL << DWT_FUNCTION_ACTION_Pos) /*!< DWT FUNCTION: ACTION Mask */ + +#define DWT_FUNCTION_MATCH_Pos 0U /*!< DWT FUNCTION: MATCH Position */ +#define DWT_FUNCTION_MATCH_Msk (0xFUL /*<< DWT_FUNCTION_MATCH_Pos*/) /*!< DWT FUNCTION: MATCH Mask */ + +/*@}*/ /* end of group CMSIS_DWT */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_TPI Trace Port Interface (TPI) + \brief Type definitions for the Trace Port Interface (TPI) + @{ + */ + +/** + \brief Structure type to access the Trace Port Interface Register (TPI). + */ +typedef struct +{ + __IM uint32_t SSPSR; /*!< Offset: 0x000 (R/ ) Supported Parallel Port Size Register */ + __IOM uint32_t CSPSR; /*!< Offset: 0x004 (R/W) Current Parallel Port Size Register */ + uint32_t RESERVED0[2U]; + __IOM uint32_t ACPR; /*!< Offset: 0x010 (R/W) Asynchronous Clock Prescaler Register */ + uint32_t RESERVED1[55U]; + __IOM uint32_t SPPR; /*!< Offset: 0x0F0 (R/W) Selected Pin Protocol Register */ + uint32_t RESERVED2[131U]; + __IM uint32_t FFSR; /*!< Offset: 0x300 (R/ ) Formatter and Flush Status Register */ + __IOM uint32_t FFCR; /*!< Offset: 0x304 (R/W) Formatter and Flush Control Register */ + __IOM uint32_t PSCR; /*!< Offset: 0x308 (R/W) Periodic Synchronization Control Register */ + uint32_t RESERVED3[759U]; + __IM uint32_t TRIGGER; /*!< Offset: 0xEE8 (R/ ) TRIGGER Register */ + __IM uint32_t ITFTTD0; /*!< Offset: 0xEEC (R/ ) Integration Test FIFO Test Data 0 Register */ + __IOM uint32_t ITATBCTR2; /*!< Offset: 0xEF0 (R/W) Integration Test ATB Control Register 2 */ + uint32_t RESERVED4[1U]; + __IM uint32_t ITATBCTR0; /*!< Offset: 0xEF8 (R/ ) Integration Test ATB Control Register 0 */ + __IM uint32_t ITFTTD1; /*!< Offset: 0xEFC (R/ ) Integration Test FIFO Test Data 1 Register */ + __IOM uint32_t ITCTRL; /*!< Offset: 0xF00 (R/W) Integration Mode Control */ + uint32_t RESERVED5[39U]; + __IOM uint32_t CLAIMSET; /*!< Offset: 0xFA0 (R/W) Claim tag set */ + __IOM uint32_t CLAIMCLR; /*!< Offset: 0xFA4 (R/W) Claim tag clear */ + uint32_t RESERVED7[8U]; + __IM uint32_t DEVID; /*!< Offset: 0xFC8 (R/ ) Device Configuration Register */ + __IM uint32_t DEVTYPE; /*!< Offset: 0xFCC (R/ ) Device Type Identifier Register */ +} TPI_Type; + +/* TPI Asynchronous Clock Prescaler Register Definitions */ +#define TPI_ACPR_PRESCALER_Pos 0U /*!< TPI ACPR: PRESCALER Position */ +#define TPI_ACPR_PRESCALER_Msk (0x1FFFUL /*<< TPI_ACPR_PRESCALER_Pos*/) /*!< TPI ACPR: PRESCALER Mask */ + +/* TPI Selected Pin Protocol Register Definitions */ +#define TPI_SPPR_TXMODE_Pos 0U /*!< TPI SPPR: TXMODE Position */ +#define TPI_SPPR_TXMODE_Msk (0x3UL /*<< TPI_SPPR_TXMODE_Pos*/) /*!< TPI SPPR: TXMODE Mask */ + +/* TPI Formatter and Flush Status Register Definitions */ +#define TPI_FFSR_FtNonStop_Pos 3U /*!< TPI FFSR: FtNonStop Position */ +#define TPI_FFSR_FtNonStop_Msk (0x1UL << TPI_FFSR_FtNonStop_Pos) /*!< TPI FFSR: FtNonStop Mask */ + +#define TPI_FFSR_TCPresent_Pos 2U /*!< TPI FFSR: TCPresent Position */ +#define TPI_FFSR_TCPresent_Msk (0x1UL << TPI_FFSR_TCPresent_Pos) /*!< TPI FFSR: TCPresent Mask */ + +#define TPI_FFSR_FtStopped_Pos 1U /*!< TPI FFSR: FtStopped Position */ +#define TPI_FFSR_FtStopped_Msk (0x1UL << TPI_FFSR_FtStopped_Pos) /*!< TPI FFSR: FtStopped Mask */ + +#define TPI_FFSR_FlInProg_Pos 0U /*!< TPI FFSR: FlInProg Position */ +#define TPI_FFSR_FlInProg_Msk (0x1UL /*<< TPI_FFSR_FlInProg_Pos*/) /*!< TPI FFSR: FlInProg Mask */ + +/* TPI Formatter and Flush Control Register Definitions */ +#define TPI_FFCR_TrigIn_Pos 8U /*!< TPI FFCR: TrigIn Position */ +#define TPI_FFCR_TrigIn_Msk (0x1UL << TPI_FFCR_TrigIn_Pos) /*!< TPI FFCR: TrigIn Mask */ + +#define TPI_FFCR_FOnMan_Pos 6U /*!< TPI FFCR: FOnMan Position */ +#define TPI_FFCR_FOnMan_Msk (0x1UL << TPI_FFCR_FOnMan_Pos) /*!< TPI FFCR: FOnMan Mask */ + +#define TPI_FFCR_EnFCont_Pos 1U /*!< TPI FFCR: EnFCont Position */ +#define TPI_FFCR_EnFCont_Msk (0x1UL << TPI_FFCR_EnFCont_Pos) /*!< TPI FFCR: EnFCont Mask */ + +/* TPI TRIGGER Register Definitions */ +#define TPI_TRIGGER_TRIGGER_Pos 0U /*!< TPI TRIGGER: TRIGGER Position */ +#define TPI_TRIGGER_TRIGGER_Msk (0x1UL /*<< TPI_TRIGGER_TRIGGER_Pos*/) /*!< TPI TRIGGER: TRIGGER Mask */ + +/* TPI Integration Test FIFO Test Data 0 Register Definitions */ +#define TPI_ITFTTD0_ATB_IF2_ATVALID_Pos 29U /*!< TPI ITFTTD0: ATB Interface 2 ATVALIDPosition */ +#define TPI_ITFTTD0_ATB_IF2_ATVALID_Msk (0x3UL << TPI_ITFTTD0_ATB_IF2_ATVALID_Pos) /*!< TPI ITFTTD0: ATB Interface 2 ATVALID Mask */ + +#define TPI_ITFTTD0_ATB_IF2_bytecount_Pos 27U /*!< TPI ITFTTD0: ATB Interface 2 byte count Position */ +#define TPI_ITFTTD0_ATB_IF2_bytecount_Msk (0x3UL << TPI_ITFTTD0_ATB_IF2_bytecount_Pos) /*!< TPI ITFTTD0: ATB Interface 2 byte count Mask */ + +#define TPI_ITFTTD0_ATB_IF1_ATVALID_Pos 26U /*!< TPI ITFTTD0: ATB Interface 1 ATVALID Position */ +#define TPI_ITFTTD0_ATB_IF1_ATVALID_Msk (0x3UL << TPI_ITFTTD0_ATB_IF1_ATVALID_Pos) /*!< TPI ITFTTD0: ATB Interface 1 ATVALID Mask */ + +#define TPI_ITFTTD0_ATB_IF1_bytecount_Pos 24U /*!< TPI ITFTTD0: ATB Interface 1 byte count Position */ +#define TPI_ITFTTD0_ATB_IF1_bytecount_Msk (0x3UL << TPI_ITFTTD0_ATB_IF1_bytecount_Pos) /*!< TPI ITFTTD0: ATB Interface 1 byte countt Mask */ + +#define TPI_ITFTTD0_ATB_IF1_data2_Pos 16U /*!< TPI ITFTTD0: ATB Interface 1 data2 Position */ +#define TPI_ITFTTD0_ATB_IF1_data2_Msk (0xFFUL << TPI_ITFTTD0_ATB_IF1_data1_Pos) /*!< TPI ITFTTD0: ATB Interface 1 data2 Mask */ + +#define TPI_ITFTTD0_ATB_IF1_data1_Pos 8U /*!< TPI ITFTTD0: ATB Interface 1 data1 Position */ +#define TPI_ITFTTD0_ATB_IF1_data1_Msk (0xFFUL << TPI_ITFTTD0_ATB_IF1_data1_Pos) /*!< TPI ITFTTD0: ATB Interface 1 data1 Mask */ + +#define TPI_ITFTTD0_ATB_IF1_data0_Pos 0U /*!< TPI ITFTTD0: ATB Interface 1 data0 Position */ +#define TPI_ITFTTD0_ATB_IF1_data0_Msk (0xFFUL /*<< TPI_ITFTTD0_ATB_IF1_data0_Pos*/) /*!< TPI ITFTTD0: ATB Interface 1 data0 Mask */ + +/* TPI Integration Test ATB Control Register 2 Register Definitions */ +#define TPI_ITATBCTR2_AFVALID2S_Pos 1U /*!< TPI ITATBCTR2: AFVALID2S Position */ +#define TPI_ITATBCTR2_AFVALID2S_Msk (0x1UL << TPI_ITATBCTR2_AFVALID2S_Pos) /*!< TPI ITATBCTR2: AFVALID2SS Mask */ + +#define TPI_ITATBCTR2_AFVALID1S_Pos 1U /*!< TPI ITATBCTR2: AFVALID1S Position */ +#define TPI_ITATBCTR2_AFVALID1S_Msk (0x1UL << TPI_ITATBCTR2_AFVALID1S_Pos) /*!< TPI ITATBCTR2: AFVALID1SS Mask */ + +#define TPI_ITATBCTR2_ATREADY2S_Pos 0U /*!< TPI ITATBCTR2: ATREADY2S Position */ +#define TPI_ITATBCTR2_ATREADY2S_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY2S_Pos*/) /*!< TPI ITATBCTR2: ATREADY2S Mask */ + +#define TPI_ITATBCTR2_ATREADY1S_Pos 0U /*!< TPI ITATBCTR2: ATREADY1S Position */ +#define TPI_ITATBCTR2_ATREADY1S_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY1S_Pos*/) /*!< TPI ITATBCTR2: ATREADY1S Mask */ + +/* TPI Integration Test FIFO Test Data 1 Register Definitions */ +#define TPI_ITFTTD1_ATB_IF2_ATVALID_Pos 29U /*!< TPI ITFTTD1: ATB Interface 2 ATVALID Position */ +#define TPI_ITFTTD1_ATB_IF2_ATVALID_Msk (0x3UL << TPI_ITFTTD1_ATB_IF2_ATVALID_Pos) /*!< TPI ITFTTD1: ATB Interface 2 ATVALID Mask */ + +#define TPI_ITFTTD1_ATB_IF2_bytecount_Pos 27U /*!< TPI ITFTTD1: ATB Interface 2 byte count Position */ +#define TPI_ITFTTD1_ATB_IF2_bytecount_Msk (0x3UL << TPI_ITFTTD1_ATB_IF2_bytecount_Pos) /*!< TPI ITFTTD1: ATB Interface 2 byte count Mask */ + +#define TPI_ITFTTD1_ATB_IF1_ATVALID_Pos 26U /*!< TPI ITFTTD1: ATB Interface 1 ATVALID Position */ +#define TPI_ITFTTD1_ATB_IF1_ATVALID_Msk (0x3UL << TPI_ITFTTD1_ATB_IF1_ATVALID_Pos) /*!< TPI ITFTTD1: ATB Interface 1 ATVALID Mask */ + +#define TPI_ITFTTD1_ATB_IF1_bytecount_Pos 24U /*!< TPI ITFTTD1: ATB Interface 1 byte count Position */ +#define TPI_ITFTTD1_ATB_IF1_bytecount_Msk (0x3UL << TPI_ITFTTD1_ATB_IF1_bytecount_Pos) /*!< TPI ITFTTD1: ATB Interface 1 byte countt Mask */ + +#define TPI_ITFTTD1_ATB_IF2_data2_Pos 16U /*!< TPI ITFTTD1: ATB Interface 2 data2 Position */ +#define TPI_ITFTTD1_ATB_IF2_data2_Msk (0xFFUL << TPI_ITFTTD1_ATB_IF2_data1_Pos) /*!< TPI ITFTTD1: ATB Interface 2 data2 Mask */ + +#define TPI_ITFTTD1_ATB_IF2_data1_Pos 8U /*!< TPI ITFTTD1: ATB Interface 2 data1 Position */ +#define TPI_ITFTTD1_ATB_IF2_data1_Msk (0xFFUL << TPI_ITFTTD1_ATB_IF2_data1_Pos) /*!< TPI ITFTTD1: ATB Interface 2 data1 Mask */ + +#define TPI_ITFTTD1_ATB_IF2_data0_Pos 0U /*!< TPI ITFTTD1: ATB Interface 2 data0 Position */ +#define TPI_ITFTTD1_ATB_IF2_data0_Msk (0xFFUL /*<< TPI_ITFTTD1_ATB_IF2_data0_Pos*/) /*!< TPI ITFTTD1: ATB Interface 2 data0 Mask */ + +/* TPI Integration Test ATB Control Register 0 Definitions */ +#define TPI_ITATBCTR0_AFVALID2S_Pos 1U /*!< TPI ITATBCTR0: AFVALID2S Position */ +#define TPI_ITATBCTR0_AFVALID2S_Msk (0x1UL << TPI_ITATBCTR0_AFVALID2S_Pos) /*!< TPI ITATBCTR0: AFVALID2SS Mask */ + +#define TPI_ITATBCTR0_AFVALID1S_Pos 1U /*!< TPI ITATBCTR0: AFVALID1S Position */ +#define TPI_ITATBCTR0_AFVALID1S_Msk (0x1UL << TPI_ITATBCTR0_AFVALID1S_Pos) /*!< TPI ITATBCTR0: AFVALID1SS Mask */ + +#define TPI_ITATBCTR0_ATREADY2S_Pos 0U /*!< TPI ITATBCTR0: ATREADY2S Position */ +#define TPI_ITATBCTR0_ATREADY2S_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY2S_Pos*/) /*!< TPI ITATBCTR0: ATREADY2S Mask */ + +#define TPI_ITATBCTR0_ATREADY1S_Pos 0U /*!< TPI ITATBCTR0: ATREADY1S Position */ +#define TPI_ITATBCTR0_ATREADY1S_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY1S_Pos*/) /*!< TPI ITATBCTR0: ATREADY1S Mask */ + +/* TPI Integration Mode Control Register Definitions */ +#define TPI_ITCTRL_Mode_Pos 0U /*!< TPI ITCTRL: Mode Position */ +#define TPI_ITCTRL_Mode_Msk (0x3UL /*<< TPI_ITCTRL_Mode_Pos*/) /*!< TPI ITCTRL: Mode Mask */ + +/* TPI DEVID Register Definitions */ +#define TPI_DEVID_NRZVALID_Pos 11U /*!< TPI DEVID: NRZVALID Position */ +#define TPI_DEVID_NRZVALID_Msk (0x1UL << TPI_DEVID_NRZVALID_Pos) /*!< TPI DEVID: NRZVALID Mask */ + +#define TPI_DEVID_MANCVALID_Pos 10U /*!< TPI DEVID: MANCVALID Position */ +#define TPI_DEVID_MANCVALID_Msk (0x1UL << TPI_DEVID_MANCVALID_Pos) /*!< TPI DEVID: MANCVALID Mask */ + +#define TPI_DEVID_PTINVALID_Pos 9U /*!< TPI DEVID: PTINVALID Position */ +#define TPI_DEVID_PTINVALID_Msk (0x1UL << TPI_DEVID_PTINVALID_Pos) /*!< TPI DEVID: PTINVALID Mask */ + +#define TPI_DEVID_FIFOSZ_Pos 6U /*!< TPI DEVID: FIFOSZ Position */ +#define TPI_DEVID_FIFOSZ_Msk (0x7UL << TPI_DEVID_FIFOSZ_Pos) /*!< TPI DEVID: FIFOSZ Mask */ + +#define TPI_DEVID_NrTraceInput_Pos 0U /*!< TPI DEVID: NrTraceInput Position */ +#define TPI_DEVID_NrTraceInput_Msk (0x3FUL /*<< TPI_DEVID_NrTraceInput_Pos*/) /*!< TPI DEVID: NrTraceInput Mask */ + +/* TPI DEVTYPE Register Definitions */ +#define TPI_DEVTYPE_SubType_Pos 4U /*!< TPI DEVTYPE: SubType Position */ +#define TPI_DEVTYPE_SubType_Msk (0xFUL /*<< TPI_DEVTYPE_SubType_Pos*/) /*!< TPI DEVTYPE: SubType Mask */ + +#define TPI_DEVTYPE_MajorType_Pos 0U /*!< TPI DEVTYPE: MajorType Position */ +#define TPI_DEVTYPE_MajorType_Msk (0xFUL << TPI_DEVTYPE_MajorType_Pos) /*!< TPI DEVTYPE: MajorType Mask */ + +/*@}*/ /* end of group CMSIS_TPI */ + + +#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_MPU Memory Protection Unit (MPU) + \brief Type definitions for the Memory Protection Unit (MPU) + @{ + */ + +/** + \brief Structure type to access the Memory Protection Unit (MPU). + */ +typedef struct +{ + __IM uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */ + __IOM uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */ + __IOM uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region Number Register */ + __IOM uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */ + __IOM uint32_t RLAR; /*!< Offset: 0x010 (R/W) MPU Region Limit Address Register */ + __IOM uint32_t RBAR_A1; /*!< Offset: 0x014 (R/W) MPU Region Base Address Register Alias 1 */ + __IOM uint32_t RLAR_A1; /*!< Offset: 0x018 (R/W) MPU Region Limit Address Register Alias 1 */ + __IOM uint32_t RBAR_A2; /*!< Offset: 0x01C (R/W) MPU Region Base Address Register Alias 2 */ + __IOM uint32_t RLAR_A2; /*!< Offset: 0x020 (R/W) MPU Region Limit Address Register Alias 2 */ + __IOM uint32_t RBAR_A3; /*!< Offset: 0x024 (R/W) MPU Region Base Address Register Alias 3 */ + __IOM uint32_t RLAR_A3; /*!< Offset: 0x028 (R/W) MPU Region Limit Address Register Alias 3 */ + uint32_t RESERVED0[1]; + union { + __IOM uint32_t MAIR[2]; + struct { + __IOM uint32_t MAIR0; /*!< Offset: 0x030 (R/W) MPU Memory Attribute Indirection Register 0 */ + __IOM uint32_t MAIR1; /*!< Offset: 0x034 (R/W) MPU Memory Attribute Indirection Register 1 */ + }; + }; +} MPU_Type; + +#define MPU_TYPE_RALIASES 4U + +/* MPU Type Register Definitions */ +#define MPU_TYPE_IREGION_Pos 16U /*!< MPU TYPE: IREGION Position */ +#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */ + +#define MPU_TYPE_DREGION_Pos 8U /*!< MPU TYPE: DREGION Position */ +#define MPU_TYPE_DREGION_Msk (0xFFUL << MPU_TYPE_DREGION_Pos) /*!< MPU TYPE: DREGION Mask */ + +#define MPU_TYPE_SEPARATE_Pos 0U /*!< MPU TYPE: SEPARATE Position */ +#define MPU_TYPE_SEPARATE_Msk (1UL /*<< MPU_TYPE_SEPARATE_Pos*/) /*!< MPU TYPE: SEPARATE Mask */ + +/* MPU Control Register Definitions */ +#define MPU_CTRL_PRIVDEFENA_Pos 2U /*!< MPU CTRL: PRIVDEFENA Position */ +#define MPU_CTRL_PRIVDEFENA_Msk (1UL << MPU_CTRL_PRIVDEFENA_Pos) /*!< MPU CTRL: PRIVDEFENA Mask */ + +#define MPU_CTRL_HFNMIENA_Pos 1U /*!< MPU CTRL: HFNMIENA Position */ +#define MPU_CTRL_HFNMIENA_Msk (1UL << MPU_CTRL_HFNMIENA_Pos) /*!< MPU CTRL: HFNMIENA Mask */ + +#define MPU_CTRL_ENABLE_Pos 0U /*!< MPU CTRL: ENABLE Position */ +#define MPU_CTRL_ENABLE_Msk (1UL /*<< MPU_CTRL_ENABLE_Pos*/) /*!< MPU CTRL: ENABLE Mask */ + +/* MPU Region Number Register Definitions */ +#define MPU_RNR_REGION_Pos 0U /*!< MPU RNR: REGION Position */ +#define MPU_RNR_REGION_Msk (0xFFUL /*<< MPU_RNR_REGION_Pos*/) /*!< MPU RNR: REGION Mask */ + +/* MPU Region Base Address Register Definitions */ +#define MPU_RBAR_BASE_Pos 5U /*!< MPU RBAR: BASE Position */ +#define MPU_RBAR_BASE_Msk (0x7FFFFFFUL << MPU_RBAR_BASE_Pos) /*!< MPU RBAR: BASE Mask */ + +#define MPU_RBAR_SH_Pos 3U /*!< MPU RBAR: SH Position */ +#define MPU_RBAR_SH_Msk (0x3UL << MPU_RBAR_SH_Pos) /*!< MPU RBAR: SH Mask */ + +#define MPU_RBAR_AP_Pos 1U /*!< MPU RBAR: AP Position */ +#define MPU_RBAR_AP_Msk (0x3UL << MPU_RBAR_AP_Pos) /*!< MPU RBAR: AP Mask */ + +#define MPU_RBAR_XN_Pos 0U /*!< MPU RBAR: XN Position */ +#define MPU_RBAR_XN_Msk (01UL /*<< MPU_RBAR_XN_Pos*/) /*!< MPU RBAR: XN Mask */ + +/* MPU Region Limit Address Register Definitions */ +#define MPU_RLAR_LIMIT_Pos 5U /*!< MPU RLAR: LIMIT Position */ +#define MPU_RLAR_LIMIT_Msk (0x7FFFFFFUL << MPU_RLAR_LIMIT_Pos) /*!< MPU RLAR: LIMIT Mask */ + +#define MPU_RLAR_AttrIndx_Pos 1U /*!< MPU RLAR: AttrIndx Position */ +#define MPU_RLAR_AttrIndx_Msk (0x7UL << MPU_RLAR_AttrIndx_Pos) /*!< MPU RLAR: AttrIndx Mask */ + +#define MPU_RLAR_EN_Pos 0U /*!< MPU RLAR: Region enable bit Position */ +#define MPU_RLAR_EN_Msk (1UL /*<< MPU_RLAR_EN_Pos*/) /*!< MPU RLAR: Region enable bit Disable Mask */ + +/* MPU Memory Attribute Indirection Register 0 Definitions */ +#define MPU_MAIR0_Attr3_Pos 24U /*!< MPU MAIR0: Attr3 Position */ +#define MPU_MAIR0_Attr3_Msk (0xFFUL << MPU_MAIR0_Attr3_Pos) /*!< MPU MAIR0: Attr3 Mask */ + +#define MPU_MAIR0_Attr2_Pos 16U /*!< MPU MAIR0: Attr2 Position */ +#define MPU_MAIR0_Attr2_Msk (0xFFUL << MPU_MAIR0_Attr2_Pos) /*!< MPU MAIR0: Attr2 Mask */ + +#define MPU_MAIR0_Attr1_Pos 8U /*!< MPU MAIR0: Attr1 Position */ +#define MPU_MAIR0_Attr1_Msk (0xFFUL << MPU_MAIR0_Attr1_Pos) /*!< MPU MAIR0: Attr1 Mask */ + +#define MPU_MAIR0_Attr0_Pos 0U /*!< MPU MAIR0: Attr0 Position */ +#define MPU_MAIR0_Attr0_Msk (0xFFUL /*<< MPU_MAIR0_Attr0_Pos*/) /*!< MPU MAIR0: Attr0 Mask */ + +/* MPU Memory Attribute Indirection Register 1 Definitions */ +#define MPU_MAIR1_Attr7_Pos 24U /*!< MPU MAIR1: Attr7 Position */ +#define MPU_MAIR1_Attr7_Msk (0xFFUL << MPU_MAIR1_Attr7_Pos) /*!< MPU MAIR1: Attr7 Mask */ + +#define MPU_MAIR1_Attr6_Pos 16U /*!< MPU MAIR1: Attr6 Position */ +#define MPU_MAIR1_Attr6_Msk (0xFFUL << MPU_MAIR1_Attr6_Pos) /*!< MPU MAIR1: Attr6 Mask */ + +#define MPU_MAIR1_Attr5_Pos 8U /*!< MPU MAIR1: Attr5 Position */ +#define MPU_MAIR1_Attr5_Msk (0xFFUL << MPU_MAIR1_Attr5_Pos) /*!< MPU MAIR1: Attr5 Mask */ + +#define MPU_MAIR1_Attr4_Pos 0U /*!< MPU MAIR1: Attr4 Position */ +#define MPU_MAIR1_Attr4_Msk (0xFFUL /*<< MPU_MAIR1_Attr4_Pos*/) /*!< MPU MAIR1: Attr4 Mask */ + +/*@} end of group CMSIS_MPU */ +#endif + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_SAU Security Attribution Unit (SAU) + \brief Type definitions for the Security Attribution Unit (SAU) + @{ + */ + +/** + \brief Structure type to access the Security Attribution Unit (SAU). + */ +typedef struct +{ + __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) SAU Control Register */ + __IM uint32_t TYPE; /*!< Offset: 0x004 (R/ ) SAU Type Register */ +#if defined (__SAUREGION_PRESENT) && (__SAUREGION_PRESENT == 1U) + __IOM uint32_t RNR; /*!< Offset: 0x008 (R/W) SAU Region Number Register */ + __IOM uint32_t RBAR; /*!< Offset: 0x00C (R/W) SAU Region Base Address Register */ + __IOM uint32_t RLAR; /*!< Offset: 0x010 (R/W) SAU Region Limit Address Register */ +#else + uint32_t RESERVED0[3]; +#endif + __IOM uint32_t SFSR; /*!< Offset: 0x014 (R/W) Secure Fault Status Register */ + __IOM uint32_t SFAR; /*!< Offset: 0x018 (R/W) Secure Fault Address Register */ +} SAU_Type; + +/* SAU Control Register Definitions */ +#define SAU_CTRL_ALLNS_Pos 1U /*!< SAU CTRL: ALLNS Position */ +#define SAU_CTRL_ALLNS_Msk (1UL << SAU_CTRL_ALLNS_Pos) /*!< SAU CTRL: ALLNS Mask */ + +#define SAU_CTRL_ENABLE_Pos 0U /*!< SAU CTRL: ENABLE Position */ +#define SAU_CTRL_ENABLE_Msk (1UL /*<< SAU_CTRL_ENABLE_Pos*/) /*!< SAU CTRL: ENABLE Mask */ + +/* SAU Type Register Definitions */ +#define SAU_TYPE_SREGION_Pos 0U /*!< SAU TYPE: SREGION Position */ +#define SAU_TYPE_SREGION_Msk (0xFFUL /*<< SAU_TYPE_SREGION_Pos*/) /*!< SAU TYPE: SREGION Mask */ + +#if defined (__SAUREGION_PRESENT) && (__SAUREGION_PRESENT == 1U) +/* SAU Region Number Register Definitions */ +#define SAU_RNR_REGION_Pos 0U /*!< SAU RNR: REGION Position */ +#define SAU_RNR_REGION_Msk (0xFFUL /*<< SAU_RNR_REGION_Pos*/) /*!< SAU RNR: REGION Mask */ + +/* SAU Region Base Address Register Definitions */ +#define SAU_RBAR_BADDR_Pos 5U /*!< SAU RBAR: BADDR Position */ +#define SAU_RBAR_BADDR_Msk (0x7FFFFFFUL << SAU_RBAR_BADDR_Pos) /*!< SAU RBAR: BADDR Mask */ + +/* SAU Region Limit Address Register Definitions */ +#define SAU_RLAR_LADDR_Pos 5U /*!< SAU RLAR: LADDR Position */ +#define SAU_RLAR_LADDR_Msk (0x7FFFFFFUL << SAU_RLAR_LADDR_Pos) /*!< SAU RLAR: LADDR Mask */ + +#define SAU_RLAR_NSC_Pos 1U /*!< SAU RLAR: NSC Position */ +#define SAU_RLAR_NSC_Msk (1UL << SAU_RLAR_NSC_Pos) /*!< SAU RLAR: NSC Mask */ + +#define SAU_RLAR_ENABLE_Pos 0U /*!< SAU RLAR: ENABLE Position */ +#define SAU_RLAR_ENABLE_Msk (1UL /*<< SAU_RLAR_ENABLE_Pos*/) /*!< SAU RLAR: ENABLE Mask */ + +#endif /* defined (__SAUREGION_PRESENT) && (__SAUREGION_PRESENT == 1U) */ + +/* Secure Fault Status Register Definitions */ +#define SAU_SFSR_LSERR_Pos 7U /*!< SAU SFSR: LSERR Position */ +#define SAU_SFSR_LSERR_Msk (1UL << SAU_SFSR_LSERR_Pos) /*!< SAU SFSR: LSERR Mask */ + +#define SAU_SFSR_SFARVALID_Pos 6U /*!< SAU SFSR: SFARVALID Position */ +#define SAU_SFSR_SFARVALID_Msk (1UL << SAU_SFSR_SFARVALID_Pos) /*!< SAU SFSR: SFARVALID Mask */ + +#define SAU_SFSR_LSPERR_Pos 5U /*!< SAU SFSR: LSPERR Position */ +#define SAU_SFSR_LSPERR_Msk (1UL << SAU_SFSR_LSPERR_Pos) /*!< SAU SFSR: LSPERR Mask */ + +#define SAU_SFSR_INVTRAN_Pos 4U /*!< SAU SFSR: INVTRAN Position */ +#define SAU_SFSR_INVTRAN_Msk (1UL << SAU_SFSR_INVTRAN_Pos) /*!< SAU SFSR: INVTRAN Mask */ + +#define SAU_SFSR_AUVIOL_Pos 3U /*!< SAU SFSR: AUVIOL Position */ +#define SAU_SFSR_AUVIOL_Msk (1UL << SAU_SFSR_AUVIOL_Pos) /*!< SAU SFSR: AUVIOL Mask */ + +#define SAU_SFSR_INVER_Pos 2U /*!< SAU SFSR: INVER Position */ +#define SAU_SFSR_INVER_Msk (1UL << SAU_SFSR_INVER_Pos) /*!< SAU SFSR: INVER Mask */ + +#define SAU_SFSR_INVIS_Pos 1U /*!< SAU SFSR: INVIS Position */ +#define SAU_SFSR_INVIS_Msk (1UL << SAU_SFSR_INVIS_Pos) /*!< SAU SFSR: INVIS Mask */ + +#define SAU_SFSR_INVEP_Pos 0U /*!< SAU SFSR: INVEP Position */ +#define SAU_SFSR_INVEP_Msk (1UL /*<< SAU_SFSR_INVEP_Pos*/) /*!< SAU SFSR: INVEP Mask */ + +/*@} end of group CMSIS_SAU */ +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_FPU Floating Point Unit (FPU) + \brief Type definitions for the Floating Point Unit (FPU) + @{ + */ + +/** + \brief Structure type to access the Floating Point Unit (FPU). + */ +typedef struct +{ + uint32_t RESERVED0[1U]; + __IOM uint32_t FPCCR; /*!< Offset: 0x004 (R/W) Floating-Point Context Control Register */ + __IOM uint32_t FPCAR; /*!< Offset: 0x008 (R/W) Floating-Point Context Address Register */ + __IOM uint32_t FPDSCR; /*!< Offset: 0x00C (R/W) Floating-Point Default Status Control Register */ + __IM uint32_t MVFR0; /*!< Offset: 0x010 (R/ ) Media and VFP Feature Register 0 */ + __IM uint32_t MVFR1; /*!< Offset: 0x014 (R/ ) Media and VFP Feature Register 1 */ + __IM uint32_t MVFR2; /*!< Offset: 0x018 (R/ ) Media and VFP Feature Register 2 */ +} FPU_Type; + +/* Floating-Point Context Control Register Definitions */ +#define FPU_FPCCR_ASPEN_Pos 31U /*!< FPCCR: ASPEN bit Position */ +#define FPU_FPCCR_ASPEN_Msk (1UL << FPU_FPCCR_ASPEN_Pos) /*!< FPCCR: ASPEN bit Mask */ + +#define FPU_FPCCR_LSPEN_Pos 30U /*!< FPCCR: LSPEN Position */ +#define FPU_FPCCR_LSPEN_Msk (1UL << FPU_FPCCR_LSPEN_Pos) /*!< FPCCR: LSPEN bit Mask */ + +#define FPU_FPCCR_LSPENS_Pos 29U /*!< FPCCR: LSPENS Position */ +#define FPU_FPCCR_LSPENS_Msk (1UL << FPU_FPCCR_LSPENS_Pos) /*!< FPCCR: LSPENS bit Mask */ + +#define FPU_FPCCR_CLRONRET_Pos 28U /*!< FPCCR: CLRONRET Position */ +#define FPU_FPCCR_CLRONRET_Msk (1UL << FPU_FPCCR_CLRONRET_Pos) /*!< FPCCR: CLRONRET bit Mask */ + +#define FPU_FPCCR_CLRONRETS_Pos 27U /*!< FPCCR: CLRONRETS Position */ +#define FPU_FPCCR_CLRONRETS_Msk (1UL << FPU_FPCCR_CLRONRETS_Pos) /*!< FPCCR: CLRONRETS bit Mask */ + +#define FPU_FPCCR_TS_Pos 26U /*!< FPCCR: TS Position */ +#define FPU_FPCCR_TS_Msk (1UL << FPU_FPCCR_TS_Pos) /*!< FPCCR: TS bit Mask */ + +#define FPU_FPCCR_UFRDY_Pos 10U /*!< FPCCR: UFRDY Position */ +#define FPU_FPCCR_UFRDY_Msk (1UL << FPU_FPCCR_UFRDY_Pos) /*!< FPCCR: UFRDY bit Mask */ + +#define FPU_FPCCR_SPLIMVIOL_Pos 9U /*!< FPCCR: SPLIMVIOL Position */ +#define FPU_FPCCR_SPLIMVIOL_Msk (1UL << FPU_FPCCR_SPLIMVIOL_Pos) /*!< FPCCR: SPLIMVIOL bit Mask */ + +#define FPU_FPCCR_MONRDY_Pos 8U /*!< FPCCR: MONRDY Position */ +#define FPU_FPCCR_MONRDY_Msk (1UL << FPU_FPCCR_MONRDY_Pos) /*!< FPCCR: MONRDY bit Mask */ + +#define FPU_FPCCR_SFRDY_Pos 7U /*!< FPCCR: SFRDY Position */ +#define FPU_FPCCR_SFRDY_Msk (1UL << FPU_FPCCR_SFRDY_Pos) /*!< FPCCR: SFRDY bit Mask */ + +#define FPU_FPCCR_BFRDY_Pos 6U /*!< FPCCR: BFRDY Position */ +#define FPU_FPCCR_BFRDY_Msk (1UL << FPU_FPCCR_BFRDY_Pos) /*!< FPCCR: BFRDY bit Mask */ + +#define FPU_FPCCR_MMRDY_Pos 5U /*!< FPCCR: MMRDY Position */ +#define FPU_FPCCR_MMRDY_Msk (1UL << FPU_FPCCR_MMRDY_Pos) /*!< FPCCR: MMRDY bit Mask */ + +#define FPU_FPCCR_HFRDY_Pos 4U /*!< FPCCR: HFRDY Position */ +#define FPU_FPCCR_HFRDY_Msk (1UL << FPU_FPCCR_HFRDY_Pos) /*!< FPCCR: HFRDY bit Mask */ + +#define FPU_FPCCR_THREAD_Pos 3U /*!< FPCCR: processor mode bit Position */ +#define FPU_FPCCR_THREAD_Msk (1UL << FPU_FPCCR_THREAD_Pos) /*!< FPCCR: processor mode active bit Mask */ + +#define FPU_FPCCR_S_Pos 2U /*!< FPCCR: Security status of the FP context bit Position */ +#define FPU_FPCCR_S_Msk (1UL << FPU_FPCCR_S_Pos) /*!< FPCCR: Security status of the FP context bit Mask */ + +#define FPU_FPCCR_USER_Pos 1U /*!< FPCCR: privilege level bit Position */ +#define FPU_FPCCR_USER_Msk (1UL << FPU_FPCCR_USER_Pos) /*!< FPCCR: privilege level bit Mask */ + +#define FPU_FPCCR_LSPACT_Pos 0U /*!< FPCCR: Lazy state preservation active bit Position */ +#define FPU_FPCCR_LSPACT_Msk (1UL /*<< FPU_FPCCR_LSPACT_Pos*/) /*!< FPCCR: Lazy state preservation active bit Mask */ + +/* Floating-Point Context Address Register Definitions */ +#define FPU_FPCAR_ADDRESS_Pos 3U /*!< FPCAR: ADDRESS bit Position */ +#define FPU_FPCAR_ADDRESS_Msk (0x1FFFFFFFUL << FPU_FPCAR_ADDRESS_Pos) /*!< FPCAR: ADDRESS bit Mask */ + +/* Floating-Point Default Status Control Register Definitions */ +#define FPU_FPDSCR_AHP_Pos 26U /*!< FPDSCR: AHP bit Position */ +#define FPU_FPDSCR_AHP_Msk (1UL << FPU_FPDSCR_AHP_Pos) /*!< FPDSCR: AHP bit Mask */ + +#define FPU_FPDSCR_DN_Pos 25U /*!< FPDSCR: DN bit Position */ +#define FPU_FPDSCR_DN_Msk (1UL << FPU_FPDSCR_DN_Pos) /*!< FPDSCR: DN bit Mask */ + +#define FPU_FPDSCR_FZ_Pos 24U /*!< FPDSCR: FZ bit Position */ +#define FPU_FPDSCR_FZ_Msk (1UL << FPU_FPDSCR_FZ_Pos) /*!< FPDSCR: FZ bit Mask */ + +#define FPU_FPDSCR_RMode_Pos 22U /*!< FPDSCR: RMode bit Position */ +#define FPU_FPDSCR_RMode_Msk (3UL << FPU_FPDSCR_RMode_Pos) /*!< FPDSCR: RMode bit Mask */ + +/* Media and VFP Feature Register 0 Definitions */ +#define FPU_MVFR0_FP_rounding_modes_Pos 28U /*!< MVFR0: FP rounding modes bits Position */ +#define FPU_MVFR0_FP_rounding_modes_Msk (0xFUL << FPU_MVFR0_FP_rounding_modes_Pos) /*!< MVFR0: FP rounding modes bits Mask */ + +#define FPU_MVFR0_Short_vectors_Pos 24U /*!< MVFR0: Short vectors bits Position */ +#define FPU_MVFR0_Short_vectors_Msk (0xFUL << FPU_MVFR0_Short_vectors_Pos) /*!< MVFR0: Short vectors bits Mask */ + +#define FPU_MVFR0_Square_root_Pos 20U /*!< MVFR0: Square root bits Position */ +#define FPU_MVFR0_Square_root_Msk (0xFUL << FPU_MVFR0_Square_root_Pos) /*!< MVFR0: Square root bits Mask */ + +#define FPU_MVFR0_Divide_Pos 16U /*!< MVFR0: Divide bits Position */ +#define FPU_MVFR0_Divide_Msk (0xFUL << FPU_MVFR0_Divide_Pos) /*!< MVFR0: Divide bits Mask */ + +#define FPU_MVFR0_FP_excep_trapping_Pos 12U /*!< MVFR0: FP exception trapping bits Position */ +#define FPU_MVFR0_FP_excep_trapping_Msk (0xFUL << FPU_MVFR0_FP_excep_trapping_Pos) /*!< MVFR0: FP exception trapping bits Mask */ + +#define FPU_MVFR0_Double_precision_Pos 8U /*!< MVFR0: Double-precision bits Position */ +#define FPU_MVFR0_Double_precision_Msk (0xFUL << FPU_MVFR0_Double_precision_Pos) /*!< MVFR0: Double-precision bits Mask */ + +#define FPU_MVFR0_Single_precision_Pos 4U /*!< MVFR0: Single-precision bits Position */ +#define FPU_MVFR0_Single_precision_Msk (0xFUL << FPU_MVFR0_Single_precision_Pos) /*!< MVFR0: Single-precision bits Mask */ + +#define FPU_MVFR0_A_SIMD_registers_Pos 0U /*!< MVFR0: A_SIMD registers bits Position */ +#define FPU_MVFR0_A_SIMD_registers_Msk (0xFUL /*<< FPU_MVFR0_A_SIMD_registers_Pos*/) /*!< MVFR0: A_SIMD registers bits Mask */ + +/* Media and VFP Feature Register 1 Definitions */ +#define FPU_MVFR1_FP_fused_MAC_Pos 28U /*!< MVFR1: FP fused MAC bits Position */ +#define FPU_MVFR1_FP_fused_MAC_Msk (0xFUL << FPU_MVFR1_FP_fused_MAC_Pos) /*!< MVFR1: FP fused MAC bits Mask */ + +#define FPU_MVFR1_FP_HPFP_Pos 24U /*!< MVFR1: FP HPFP bits Position */ +#define FPU_MVFR1_FP_HPFP_Msk (0xFUL << FPU_MVFR1_FP_HPFP_Pos) /*!< MVFR1: FP HPFP bits Mask */ + +#define FPU_MVFR1_D_NaN_mode_Pos 4U /*!< MVFR1: D_NaN mode bits Position */ +#define FPU_MVFR1_D_NaN_mode_Msk (0xFUL << FPU_MVFR1_D_NaN_mode_Pos) /*!< MVFR1: D_NaN mode bits Mask */ + +#define FPU_MVFR1_FtZ_mode_Pos 0U /*!< MVFR1: FtZ mode bits Position */ +#define FPU_MVFR1_FtZ_mode_Msk (0xFUL /*<< FPU_MVFR1_FtZ_mode_Pos*/) /*!< MVFR1: FtZ mode bits Mask */ + +/* Media and VFP Feature Register 2 Definitions */ +#define FPU_MVFR2_FPMisc_Pos 4U /*!< MVFR2: FPMisc bits Position */ +#define FPU_MVFR2_FPMisc_Msk (0xFUL << FPU_MVFR2_FPMisc_Pos) /*!< MVFR2: FPMisc bits Mask */ + +/*@} end of group CMSIS_FPU */ + + + + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_DCB Debug Control Block + \brief Type definitions for the Debug Control Block Registers + @{ + */ + +/** + \brief Structure type to access the Debug Control Block Registers (DCB). + */ +typedef struct +{ + __IOM uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */ + __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ + __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ + __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ + uint32_t RESERVED0[1U]; + __IOM uint32_t DAUTHCTRL; /*!< Offset: 0x014 (R/W) Debug Authentication Control Register */ + __IOM uint32_t DSCSR; /*!< Offset: 0x018 (R/W) Debug Security Control and Status Register */ +} DCB_Type; + +/* DHCSR, Debug Halting Control and Status Register Definitions */ +#define DCB_DHCSR_DBGKEY_Pos 16U /*!< DCB DHCSR: Debug key Position */ +#define DCB_DHCSR_DBGKEY_Msk (0xFFFFUL << DCB_DHCSR_DBGKEY_Pos) /*!< DCB DHCSR: Debug key Mask */ + +#define DCB_DHCSR_S_RESTART_ST_Pos 26U /*!< DCB DHCSR: Restart sticky status Position */ +#define DCB_DHCSR_S_RESTART_ST_Msk (0x1UL << DCB_DHCSR_S_RESTART_ST_Pos) /*!< DCB DHCSR: Restart sticky status Mask */ + +#define DCB_DHCSR_S_RESET_ST_Pos 25U /*!< DCB DHCSR: Reset sticky status Position */ +#define DCB_DHCSR_S_RESET_ST_Msk (0x1UL << DCB_DHCSR_S_RESET_ST_Pos) /*!< DCB DHCSR: Reset sticky status Mask */ + +#define DCB_DHCSR_S_RETIRE_ST_Pos 24U /*!< DCB DHCSR: Retire sticky status Position */ +#define DCB_DHCSR_S_RETIRE_ST_Msk (0x1UL << DCB_DHCSR_S_RETIRE_ST_Pos) /*!< DCB DHCSR: Retire sticky status Mask */ + +#define DCB_DHCSR_S_SDE_Pos 20U /*!< DCB DHCSR: Secure debug enabled Position */ +#define DCB_DHCSR_S_SDE_Msk (0x1UL << DCB_DHCSR_S_SDE_Pos) /*!< DCB DHCSR: Secure debug enabled Mask */ + +#define DCB_DHCSR_S_LOCKUP_Pos 19U /*!< DCB DHCSR: Lockup status Position */ +#define DCB_DHCSR_S_LOCKUP_Msk (0x1UL << DCB_DHCSR_S_LOCKUP_Pos) /*!< DCB DHCSR: Lockup status Mask */ + +#define DCB_DHCSR_S_SLEEP_Pos 18U /*!< DCB DHCSR: Sleeping status Position */ +#define DCB_DHCSR_S_SLEEP_Msk (0x1UL << DCB_DHCSR_S_SLEEP_Pos) /*!< DCB DHCSR: Sleeping status Mask */ + +#define DCB_DHCSR_S_HALT_Pos 17U /*!< DCB DHCSR: Halted status Position */ +#define DCB_DHCSR_S_HALT_Msk (0x1UL << DCB_DHCSR_S_HALT_Pos) /*!< DCB DHCSR: Halted status Mask */ + +#define DCB_DHCSR_S_REGRDY_Pos 16U /*!< DCB DHCSR: Register ready status Position */ +#define DCB_DHCSR_S_REGRDY_Msk (0x1UL << DCB_DHCSR_S_REGRDY_Pos) /*!< DCB DHCSR: Register ready status Mask */ + +#define DCB_DHCSR_C_SNAPSTALL_Pos 5U /*!< DCB DHCSR: Snap stall control Position */ +#define DCB_DHCSR_C_SNAPSTALL_Msk (0x1UL << DCB_DHCSR_C_SNAPSTALL_Pos) /*!< DCB DHCSR: Snap stall control Mask */ + +#define DCB_DHCSR_C_MASKINTS_Pos 3U /*!< DCB DHCSR: Mask interrupts control Position */ +#define DCB_DHCSR_C_MASKINTS_Msk (0x1UL << DCB_DHCSR_C_MASKINTS_Pos) /*!< DCB DHCSR: Mask interrupts control Mask */ + +#define DCB_DHCSR_C_STEP_Pos 2U /*!< DCB DHCSR: Step control Position */ +#define DCB_DHCSR_C_STEP_Msk (0x1UL << DCB_DHCSR_C_STEP_Pos) /*!< DCB DHCSR: Step control Mask */ + +#define DCB_DHCSR_C_HALT_Pos 1U /*!< DCB DHCSR: Halt control Position */ +#define DCB_DHCSR_C_HALT_Msk (0x1UL << DCB_DHCSR_C_HALT_Pos) /*!< DCB DHCSR: Halt control Mask */ + +#define DCB_DHCSR_C_DEBUGEN_Pos 0U /*!< DCB DHCSR: Debug enable control Position */ +#define DCB_DHCSR_C_DEBUGEN_Msk (0x1UL /*<< DCB_DHCSR_C_DEBUGEN_Pos*/) /*!< DCB DHCSR: Debug enable control Mask */ + +/* DCRSR, Debug Core Register Select Register Definitions */ +#define DCB_DCRSR_REGWnR_Pos 16U /*!< DCB DCRSR: Register write/not-read Position */ +#define DCB_DCRSR_REGWnR_Msk (0x1UL << DCB_DCRSR_REGWnR_Pos) /*!< DCB DCRSR: Register write/not-read Mask */ + +#define DCB_DCRSR_REGSEL_Pos 0U /*!< DCB DCRSR: Register selector Position */ +#define DCB_DCRSR_REGSEL_Msk (0x7FUL /*<< DCB_DCRSR_REGSEL_Pos*/) /*!< DCB DCRSR: Register selector Mask */ + +/* DCRDR, Debug Core Register Data Register Definitions */ +#define DCB_DCRDR_DBGTMP_Pos 0U /*!< DCB DCRDR: Data temporary buffer Position */ +#define DCB_DCRDR_DBGTMP_Msk (0xFFFFFFFFUL /*<< DCB_DCRDR_DBGTMP_Pos*/) /*!< DCB DCRDR: Data temporary buffer Mask */ + +/* DEMCR, Debug Exception and Monitor Control Register Definitions */ +#define DCB_DEMCR_TRCENA_Pos 24U /*!< DCB DEMCR: Trace enable Position */ +#define DCB_DEMCR_TRCENA_Msk (0x1UL << DCB_DEMCR_TRCENA_Pos) /*!< DCB DEMCR: Trace enable Mask */ + +#define DCB_DEMCR_MONPRKEY_Pos 23U /*!< DCB DEMCR: Monitor pend req key Position */ +#define DCB_DEMCR_MONPRKEY_Msk (0x1UL << DCB_DEMCR_MONPRKEY_Pos) /*!< DCB DEMCR: Monitor pend req key Mask */ + +#define DCB_DEMCR_UMON_EN_Pos 21U /*!< DCB DEMCR: Unprivileged monitor enable Position */ +#define DCB_DEMCR_UMON_EN_Msk (0x1UL << DCB_DEMCR_UMON_EN_Pos) /*!< DCB DEMCR: Unprivileged monitor enable Mask */ + +#define DCB_DEMCR_SDME_Pos 20U /*!< DCB DEMCR: Secure DebugMonitor enable Position */ +#define DCB_DEMCR_SDME_Msk (0x1UL << DCB_DEMCR_SDME_Pos) /*!< DCB DEMCR: Secure DebugMonitor enable Mask */ + +#define DCB_DEMCR_MON_REQ_Pos 19U /*!< DCB DEMCR: Monitor request Position */ +#define DCB_DEMCR_MON_REQ_Msk (0x1UL << DCB_DEMCR_MON_REQ_Pos) /*!< DCB DEMCR: Monitor request Mask */ + +#define DCB_DEMCR_MON_STEP_Pos 18U /*!< DCB DEMCR: Monitor step Position */ +#define DCB_DEMCR_MON_STEP_Msk (0x1UL << DCB_DEMCR_MON_STEP_Pos) /*!< DCB DEMCR: Monitor step Mask */ + +#define DCB_DEMCR_MON_PEND_Pos 17U /*!< DCB DEMCR: Monitor pend Position */ +#define DCB_DEMCR_MON_PEND_Msk (0x1UL << DCB_DEMCR_MON_PEND_Pos) /*!< DCB DEMCR: Monitor pend Mask */ + +#define DCB_DEMCR_MON_EN_Pos 16U /*!< DCB DEMCR: Monitor enable Position */ +#define DCB_DEMCR_MON_EN_Msk (0x1UL << DCB_DEMCR_MON_EN_Pos) /*!< DCB DEMCR: Monitor enable Mask */ + +#define DCB_DEMCR_VC_SFERR_Pos 11U /*!< DCB DEMCR: Vector Catch SecureFault Position */ +#define DCB_DEMCR_VC_SFERR_Msk (0x1UL << DCB_DEMCR_VC_SFERR_Pos) /*!< DCB DEMCR: Vector Catch SecureFault Mask */ + +#define DCB_DEMCR_VC_HARDERR_Pos 10U /*!< DCB DEMCR: Vector Catch HardFault errors Position */ +#define DCB_DEMCR_VC_HARDERR_Msk (0x1UL << DCB_DEMCR_VC_HARDERR_Pos) /*!< DCB DEMCR: Vector Catch HardFault errors Mask */ + +#define DCB_DEMCR_VC_INTERR_Pos 9U /*!< DCB DEMCR: Vector Catch interrupt errors Position */ +#define DCB_DEMCR_VC_INTERR_Msk (0x1UL << DCB_DEMCR_VC_INTERR_Pos) /*!< DCB DEMCR: Vector Catch interrupt errors Mask */ + +#define DCB_DEMCR_VC_BUSERR_Pos 8U /*!< DCB DEMCR: Vector Catch BusFault errors Position */ +#define DCB_DEMCR_VC_BUSERR_Msk (0x1UL << DCB_DEMCR_VC_BUSERR_Pos) /*!< DCB DEMCR: Vector Catch BusFault errors Mask */ + +#define DCB_DEMCR_VC_STATERR_Pos 7U /*!< DCB DEMCR: Vector Catch state errors Position */ +#define DCB_DEMCR_VC_STATERR_Msk (0x1UL << DCB_DEMCR_VC_STATERR_Pos) /*!< DCB DEMCR: Vector Catch state errors Mask */ + +#define DCB_DEMCR_VC_CHKERR_Pos 6U /*!< DCB DEMCR: Vector Catch check errors Position */ +#define DCB_DEMCR_VC_CHKERR_Msk (0x1UL << DCB_DEMCR_VC_CHKERR_Pos) /*!< DCB DEMCR: Vector Catch check errors Mask */ + +#define DCB_DEMCR_VC_NOCPERR_Pos 5U /*!< DCB DEMCR: Vector Catch NOCP errors Position */ +#define DCB_DEMCR_VC_NOCPERR_Msk (0x1UL << DCB_DEMCR_VC_NOCPERR_Pos) /*!< DCB DEMCR: Vector Catch NOCP errors Mask */ + +#define DCB_DEMCR_VC_MMERR_Pos 4U /*!< DCB DEMCR: Vector Catch MemManage errors Position */ +#define DCB_DEMCR_VC_MMERR_Msk (0x1UL << DCB_DEMCR_VC_MMERR_Pos) /*!< DCB DEMCR: Vector Catch MemManage errors Mask */ + +#define DCB_DEMCR_VC_CORERESET_Pos 0U /*!< DCB DEMCR: Vector Catch Core reset Position */ +#define DCB_DEMCR_VC_CORERESET_Msk (0x1UL /*<< DCB_DEMCR_VC_CORERESET_Pos*/) /*!< DCB DEMCR: Vector Catch Core reset Mask */ + +/* DAUTHCTRL, Debug Authentication Control Register Definitions */ +#define DCB_DAUTHCTRL_INTSPNIDEN_Pos 3U /*!< DCB DAUTHCTRL: Internal Secure non-invasive debug enable Position */ +#define DCB_DAUTHCTRL_INTSPNIDEN_Msk (0x1UL << DCB_DAUTHCTRL_INTSPNIDEN_Pos) /*!< DCB DAUTHCTRL: Internal Secure non-invasive debug enable Mask */ + +#define DCB_DAUTHCTRL_SPNIDENSEL_Pos 2U /*!< DCB DAUTHCTRL: Secure non-invasive debug enable select Position */ +#define DCB_DAUTHCTRL_SPNIDENSEL_Msk (0x1UL << DCB_DAUTHCTRL_SPNIDENSEL_Pos) /*!< DCB DAUTHCTRL: Secure non-invasive debug enable select Mask */ + +#define DCB_DAUTHCTRL_INTSPIDEN_Pos 1U /*!< DCB DAUTHCTRL: Internal Secure invasive debug enable Position */ +#define DCB_DAUTHCTRL_INTSPIDEN_Msk (0x1UL << DCB_DAUTHCTRL_INTSPIDEN_Pos) /*!< DCB DAUTHCTRL: Internal Secure invasive debug enable Mask */ + +#define DCB_DAUTHCTRL_SPIDENSEL_Pos 0U /*!< DCB DAUTHCTRL: Secure invasive debug enable select Position */ +#define DCB_DAUTHCTRL_SPIDENSEL_Msk (0x1UL /*<< DCB_DAUTHCTRL_SPIDENSEL_Pos*/) /*!< DCB DAUTHCTRL: Secure invasive debug enable select Mask */ + +/* DSCSR, Debug Security Control and Status Register Definitions */ +#define DCB_DSCSR_CDSKEY_Pos 17U /*!< DCB DSCSR: CDS write-enable key Position */ +#define DCB_DSCSR_CDSKEY_Msk (0x1UL << DCB_DSCSR_CDSKEY_Pos) /*!< DCB DSCSR: CDS write-enable key Mask */ + +#define DCB_DSCSR_CDS_Pos 16U /*!< DCB DSCSR: Current domain Secure Position */ +#define DCB_DSCSR_CDS_Msk (0x1UL << DCB_DSCSR_CDS_Pos) /*!< DCB DSCSR: Current domain Secure Mask */ + +#define DCB_DSCSR_SBRSEL_Pos 1U /*!< DCB DSCSR: Secure banked register select Position */ +#define DCB_DSCSR_SBRSEL_Msk (0x1UL << DCB_DSCSR_SBRSEL_Pos) /*!< DCB DSCSR: Secure banked register select Mask */ + +#define DCB_DSCSR_SBRSELEN_Pos 0U /*!< DCB DSCSR: Secure banked register select enable Position */ +#define DCB_DSCSR_SBRSELEN_Msk (0x1UL /*<< DCB_DSCSR_SBRSELEN_Pos*/) /*!< DCB DSCSR: Secure banked register select enable Mask */ + +/*@} end of group CMSIS_DCB */ + + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_DIB Debug Identification Block + \brief Type definitions for the Debug Identification Block Registers + @{ + */ + +/** + \brief Structure type to access the Debug Identification Block Registers (DIB). + */ +typedef struct +{ + __OM uint32_t DLAR; /*!< Offset: 0x000 ( /W) SCS Software Lock Access Register */ + __IM uint32_t DLSR; /*!< Offset: 0x004 (R/ ) SCS Software Lock Status Register */ + __IM uint32_t DAUTHSTATUS; /*!< Offset: 0x008 (R/ ) Debug Authentication Status Register */ + __IM uint32_t DDEVARCH; /*!< Offset: 0x00C (R/ ) SCS Device Architecture Register */ + __IM uint32_t DDEVTYPE; /*!< Offset: 0x010 (R/ ) SCS Device Type Register */ +} DIB_Type; + +/* DLAR, SCS Software Lock Access Register Definitions */ +#define DIB_DLAR_KEY_Pos 0U /*!< DIB DLAR: KEY Position */ +#define DIB_DLAR_KEY_Msk (0xFFFFFFFFUL /*<< DIB_DLAR_KEY_Pos */) /*!< DIB DLAR: KEY Mask */ + +/* DLSR, SCS Software Lock Status Register Definitions */ +#define DIB_DLSR_nTT_Pos 2U /*!< DIB DLSR: Not thirty-two bit Position */ +#define DIB_DLSR_nTT_Msk (0x1UL << DIB_DLSR_nTT_Pos ) /*!< DIB DLSR: Not thirty-two bit Mask */ + +#define DIB_DLSR_SLK_Pos 1U /*!< DIB DLSR: Software Lock status Position */ +#define DIB_DLSR_SLK_Msk (0x1UL << DIB_DLSR_SLK_Pos ) /*!< DIB DLSR: Software Lock status Mask */ + +#define DIB_DLSR_SLI_Pos 0U /*!< DIB DLSR: Software Lock implemented Position */ +#define DIB_DLSR_SLI_Msk (0x1UL /*<< DIB_DLSR_SLI_Pos*/) /*!< DIB DLSR: Software Lock implemented Mask */ + +/* DAUTHSTATUS, Debug Authentication Status Register Definitions */ +#define DIB_DAUTHSTATUS_SNID_Pos 6U /*!< DIB DAUTHSTATUS: Secure Non-invasive Debug Position */ +#define DIB_DAUTHSTATUS_SNID_Msk (0x3UL << DIB_DAUTHSTATUS_SNID_Pos ) /*!< DIB DAUTHSTATUS: Secure Non-invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_SID_Pos 4U /*!< DIB DAUTHSTATUS: Secure Invasive Debug Position */ +#define DIB_DAUTHSTATUS_SID_Msk (0x3UL << DIB_DAUTHSTATUS_SID_Pos ) /*!< DIB DAUTHSTATUS: Secure Invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_NSNID_Pos 2U /*!< DIB DAUTHSTATUS: Non-secure Non-invasive Debug Position */ +#define DIB_DAUTHSTATUS_NSNID_Msk (0x3UL << DIB_DAUTHSTATUS_NSNID_Pos ) /*!< DIB DAUTHSTATUS: Non-secure Non-invasive Debug Mask */ + +#define DIB_DAUTHSTATUS_NSID_Pos 0U /*!< DIB DAUTHSTATUS: Non-secure Invasive Debug Position */ +#define DIB_DAUTHSTATUS_NSID_Msk (0x3UL /*<< DIB_DAUTHSTATUS_NSID_Pos*/) /*!< DIB DAUTHSTATUS: Non-secure Invasive Debug Mask */ + +/* DDEVARCH, SCS Device Architecture Register Definitions */ +#define DIB_DDEVARCH_ARCHITECT_Pos 21U /*!< DIB DDEVARCH: Architect Position */ +#define DIB_DDEVARCH_ARCHITECT_Msk (0x7FFUL << DIB_DDEVARCH_ARCHITECT_Pos ) /*!< DIB DDEVARCH: Architect Mask */ + +#define DIB_DDEVARCH_PRESENT_Pos 20U /*!< DIB DDEVARCH: DEVARCH Present Position */ +#define DIB_DDEVARCH_PRESENT_Msk (0x1FUL << DIB_DDEVARCH_PRESENT_Pos ) /*!< DIB DDEVARCH: DEVARCH Present Mask */ + +#define DIB_DDEVARCH_REVISION_Pos 16U /*!< DIB DDEVARCH: Revision Position */ +#define DIB_DDEVARCH_REVISION_Msk (0xFUL << DIB_DDEVARCH_REVISION_Pos ) /*!< DIB DDEVARCH: Revision Mask */ + +#define DIB_DDEVARCH_ARCHVER_Pos 12U /*!< DIB DDEVARCH: Architecture Version Position */ +#define DIB_DDEVARCH_ARCHVER_Msk (0xFUL << DIB_DDEVARCH_ARCHVER_Pos ) /*!< DIB DDEVARCH: Architecture Version Mask */ + +#define DIB_DDEVARCH_ARCHPART_Pos 0U /*!< DIB DDEVARCH: Architecture Part Position */ +#define DIB_DDEVARCH_ARCHPART_Msk (0xFFFUL /*<< DIB_DDEVARCH_ARCHPART_Pos*/) /*!< DIB DDEVARCH: Architecture Part Mask */ + +/* DDEVTYPE, SCS Device Type Register Definitions */ +#define DIB_DDEVTYPE_SUB_Pos 4U /*!< DIB DDEVTYPE: Sub-type Position */ +#define DIB_DDEVTYPE_SUB_Msk (0xFUL << DIB_DDEVTYPE_SUB_Pos ) /*!< DIB DDEVTYPE: Sub-type Mask */ + +#define DIB_DDEVTYPE_MAJOR_Pos 0U /*!< DIB DDEVTYPE: Major type Position */ +#define DIB_DDEVTYPE_MAJOR_Msk (0xFUL /*<< DIB_DDEVTYPE_MAJOR_Pos*/) /*!< DIB DDEVTYPE: Major type Mask */ + + +/*@} end of group CMSIS_DIB */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_core_bitfield Core register bit field macros + \brief Macros for use with bit field definitions (xxx_Pos, xxx_Msk). + @{ + */ + +/** + \brief Mask and shift a bit field value for use in a register bit range. + \param[in] field Name of the register bit field. + \param[in] value Value of the bit field. This parameter is interpreted as an uint32_t type. + \return Masked and shifted value. +*/ +#define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk) + +/** + \brief Mask and shift a register value to extract a bit filed value. + \param[in] field Name of the register bit field. + \param[in] value Value of register. This parameter is interpreted as an uint32_t type. + \return Masked and shifted bit field value. +*/ +#define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos) + +/*@} end of group CMSIS_core_bitfield */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_core_base Core Definitions + \brief Definitions for base addresses, unions, and structures. + @{ + */ + +/* Memory mapping of Core Hardware */ + #define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */ + #define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */ + #define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */ + #define TPI_BASE (0xE0040000UL) /*!< TPI Base Address */ + #define DCB_BASE (0xE000EDF0UL) /*!< DCB Base Address */ + #define DIB_BASE (0xE000EFB0UL) /*!< DIB Base Address */ + #define EMSS_BASE (0xE001E000UL) /*!AIRCR [10:8] PRIGROUP field. + Only values from 0..7 are used. + In case of a conflict between priority grouping and available + priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set. + \param [in] PriorityGroup Priority grouping field. + */ +__STATIC_INLINE void __NVIC_SetPriorityGrouping(uint32_t PriorityGroup) +{ + uint32_t reg_value; + uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ + + reg_value = SCB->AIRCR; /* read old register configuration */ + reg_value &= ~((uint32_t)(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk)); /* clear bits to change */ + reg_value = (reg_value | + ((uint32_t)0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | + (PriorityGroupTmp << SCB_AIRCR_PRIGROUP_Pos) ); /* Insert write key and priority group */ + SCB->AIRCR = reg_value; +} + + +/** + \brief Get Priority Grouping + \details Reads the priority grouping field from the NVIC Interrupt Controller. + \return Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field). + */ +__STATIC_INLINE uint32_t __NVIC_GetPriorityGrouping(void) +{ + return ((uint32_t)((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos)); +} + + +/** + \brief Enable Interrupt + \details Enables a device specific interrupt in the NVIC interrupt controller. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + __COMPILER_BARRIER(); + NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __COMPILER_BARRIER(); + } +} + + +/** + \brief Get Interrupt Enable status + \details Returns a device specific interrupt enable status from the NVIC interrupt controller. + \param [in] IRQn Device specific interrupt number. + \return 0 Interrupt is not enabled. + \return 1 Interrupt is enabled. + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +/** + \brief Disable Interrupt + \details Disables a device specific interrupt in the NVIC interrupt controller. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC->ICER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __DSB(); + __ISB(); + } +} + + +/** + \brief Get Pending Interrupt + \details Reads the NVIC pending register and returns the pending bit for the specified device specific interrupt. + \param [in] IRQn Device specific interrupt number. + \return 0 Interrupt status is not pending. + \return 1 Interrupt status is pending. + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +/** + \brief Set Pending Interrupt + \details Sets the pending bit of a device specific interrupt in the NVIC pending register. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } +} + + +/** + \brief Clear Pending Interrupt + \details Clears the pending bit of a device specific interrupt in the NVIC pending register. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC->ICPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } +} + + +/** + \brief Get Active Interrupt + \details Reads the active register in the NVIC and returns the active bit for the device specific interrupt. + \param [in] IRQn Device specific interrupt number. + \return 0 Interrupt status is not active. + \return 1 Interrupt status is active. + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t __NVIC_GetActive(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC->IABR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief Get Interrupt Target State + \details Reads the interrupt target field in the NVIC and returns the interrupt target bit for the device specific interrupt. + \param [in] IRQn Device specific interrupt number. + \return 0 if interrupt is assigned to Secure + \return 1 if interrupt is assigned to Non Secure + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t NVIC_GetTargetState(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC->ITNS[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +/** + \brief Set Interrupt Target State + \details Sets the interrupt target field in the NVIC and returns the interrupt target bit for the device specific interrupt. + \param [in] IRQn Device specific interrupt number. + \return 0 if interrupt is assigned to Secure + 1 if interrupt is assigned to Non Secure + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t NVIC_SetTargetState(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC->ITNS[(((uint32_t)IRQn) >> 5UL)] |= ((uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL))); + return((uint32_t)(((NVIC->ITNS[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +/** + \brief Clear Interrupt Target State + \details Clears the interrupt target field in the NVIC and returns the interrupt target bit for the device specific interrupt. + \param [in] IRQn Device specific interrupt number. + \return 0 if interrupt is assigned to Secure + 1 if interrupt is assigned to Non Secure + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t NVIC_ClearTargetState(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC->ITNS[(((uint32_t)IRQn) >> 5UL)] &= ~((uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL))); + return((uint32_t)(((NVIC->ITNS[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + + +/** + \brief Set Interrupt Priority + \details Sets the priority of a device specific interrupt or a processor exception. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + \param [in] IRQn Interrupt number. + \param [in] priority Priority to set. + \note The priority cannot be set for every processor exception. + */ +__STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC->IPR[((uint32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); + } + else + { + SCB->SHPR[(((uint32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); + } +} + + +/** + \brief Get Interrupt Priority + \details Reads the priority of a device specific interrupt or a processor exception. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + \param [in] IRQn Interrupt number. + \return Interrupt Priority. + Value is aligned automatically to the implemented priority bits of the microcontroller. + */ +__STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn) +{ + + if ((int32_t)(IRQn) >= 0) + { + return(((uint32_t)NVIC->IPR[((uint32_t)IRQn)] >> (8U - __NVIC_PRIO_BITS))); + } + else + { + return(((uint32_t)SCB->SHPR[(((uint32_t)IRQn) & 0xFUL)-4UL] >> (8U - __NVIC_PRIO_BITS))); + } +} + + +/** + \brief Encode Priority + \details Encodes the priority for an interrupt with the given priority group, + preemptive priority value, and subpriority value. + In case of a conflict between priority grouping and available + priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set. + \param [in] PriorityGroup Used priority group. + \param [in] PreemptPriority Preemptive priority value (starting from 0). + \param [in] SubPriority Subpriority value (starting from 0). + \return Encoded priority. Value can be used in the function \ref NVIC_SetPriority(). + */ +__STATIC_INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority) +{ + uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ + uint32_t PreemptPriorityBits; + uint32_t SubPriorityBits; + + PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp); + SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS)); + + return ( + ((PreemptPriority & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL)) << SubPriorityBits) | + ((SubPriority & (uint32_t)((1UL << (SubPriorityBits )) - 1UL))) + ); +} + + +/** + \brief Decode Priority + \details Decodes an interrupt priority value with a given priority group to + preemptive priority value and subpriority value. + In case of a conflict between priority grouping and available + priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set. + \param [in] Priority Priority value, which can be retrieved with the function \ref NVIC_GetPriority(). + \param [in] PriorityGroup Used priority group. + \param [out] pPreemptPriority Preemptive priority value (starting from 0). + \param [out] pSubPriority Subpriority value (starting from 0). + */ +__STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* const pPreemptPriority, uint32_t* const pSubPriority) +{ + uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ + uint32_t PreemptPriorityBits; + uint32_t SubPriorityBits; + + PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp); + SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS)); + + *pPreemptPriority = (Priority >> SubPriorityBits) & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL); + *pSubPriority = (Priority ) & (uint32_t)((1UL << (SubPriorityBits )) - 1UL); +} + + +/** + \brief Set Interrupt Vector + \details Sets an interrupt vector in SRAM based interrupt vector table. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + VTOR must been relocated to SRAM before. + \param [in] IRQn Interrupt number + \param [in] vector Address of interrupt handler function + */ +__STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) +{ + uint32_t *vectors = (uint32_t *)SCB->VTOR; + vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector; + __DSB(); +} + + +/** + \brief Get Interrupt Vector + \details Reads an interrupt vector from interrupt vector table. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + \param [in] IRQn Interrupt number. + \return Address of interrupt handler function + */ +__STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn) +{ + uint32_t *vectors = (uint32_t *)SCB->VTOR; + return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET]; +} + + +/** + \brief System Reset + \details Initiates a system reset request to reset the MCU. + */ +__NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void) +{ + __DSB(); /* Ensure all outstanding memory accesses including + buffered write are completed before reset */ + SCB->AIRCR = (uint32_t)((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | + (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) | + SCB_AIRCR_SYSRESETREQ_Msk ); /* Keep priority group unchanged */ + __DSB(); /* Ensure completion of memory access */ + + for(;;) /* wait until reset */ + { + __NOP(); + } +} + +/** + \brief Software Reset + \details Initiates a system reset request to reset the CPU. + */ +__NO_RETURN __STATIC_INLINE void __SW_SystemReset(void) +{ + __DSB(); /* Ensure all outstanding memory accesses including + buffered write are completed before reset */ + SCB->AIRCR = (uint32_t)((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | + (SCB->AIRCR & SCB_AIRCR_BFHFNMINS_Msk) | /* Keep BFHFNMINS unchanged. Use this Reset function in case your case need to keep it */ + (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) | /* Keep priority group unchanged */ + SCB_AIRCR_SYSRESETREQ_Msk ); + __DSB(); /* Ensure completion of memory access */ + + for(;;) /* wait until reset */ + { + __NOP(); + } +} + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief Set Priority Grouping (non-secure) + \details Sets the non-secure priority grouping field when in secure state using the required unlock sequence. + The parameter PriorityGroup is assigned to the field SCB->AIRCR [10:8] PRIGROUP field. + Only values from 0..7 are used. + In case of a conflict between priority grouping and available + priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set. + \param [in] PriorityGroup Priority grouping field. + */ +__STATIC_INLINE void TZ_NVIC_SetPriorityGrouping_NS(uint32_t PriorityGroup) +{ + uint32_t reg_value; + uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ + + reg_value = SCB_NS->AIRCR; /* read old register configuration */ + reg_value &= ~((uint32_t)(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk)); /* clear bits to change */ + reg_value = (reg_value | + ((uint32_t)0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | + (PriorityGroupTmp << SCB_AIRCR_PRIGROUP_Pos) ); /* Insert write key and priority group */ + SCB_NS->AIRCR = reg_value; +} + + +/** + \brief Get Priority Grouping (non-secure) + \details Reads the priority grouping field from the non-secure NVIC when in secure state. + \return Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field). + */ +__STATIC_INLINE uint32_t TZ_NVIC_GetPriorityGrouping_NS(void) +{ + return ((uint32_t)((SCB_NS->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos)); +} + + +/** + \brief Enable Interrupt (non-secure) + \details Enables a device specific interrupt in the non-secure NVIC interrupt controller when in secure state. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void TZ_NVIC_EnableIRQ_NS(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC_NS->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } +} + + +/** + \brief Get Interrupt Enable status (non-secure) + \details Returns a device specific interrupt enable status from the non-secure NVIC interrupt controller when in secure state. + \param [in] IRQn Device specific interrupt number. + \return 0 Interrupt is not enabled. + \return 1 Interrupt is enabled. + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t TZ_NVIC_GetEnableIRQ_NS(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC_NS->ISER[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +/** + \brief Disable Interrupt (non-secure) + \details Disables a device specific interrupt in the non-secure NVIC interrupt controller when in secure state. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void TZ_NVIC_DisableIRQ_NS(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC_NS->ICER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } +} + + +/** + \brief Get Pending Interrupt (non-secure) + \details Reads the NVIC pending register in the non-secure NVIC when in secure state and returns the pending bit for the specified device specific interrupt. + \param [in] IRQn Device specific interrupt number. + \return 0 Interrupt status is not pending. + \return 1 Interrupt status is pending. + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t TZ_NVIC_GetPendingIRQ_NS(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC_NS->ISPR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +/** + \brief Set Pending Interrupt (non-secure) + \details Sets the pending bit of a device specific interrupt in the non-secure NVIC pending register when in secure state. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void TZ_NVIC_SetPendingIRQ_NS(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC_NS->ISPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } +} + + +/** + \brief Clear Pending Interrupt (non-secure) + \details Clears the pending bit of a device specific interrupt in the non-secure NVIC pending register when in secure state. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void TZ_NVIC_ClearPendingIRQ_NS(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC_NS->ICPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } +} + + +/** + \brief Get Active Interrupt (non-secure) + \details Reads the active register in non-secure NVIC when in secure state and returns the active bit for the device specific interrupt. + \param [in] IRQn Device specific interrupt number. + \return 0 Interrupt status is not active. + \return 1 Interrupt status is active. + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t TZ_NVIC_GetActive_NS(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC_NS->IABR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +/** + \brief Set Interrupt Priority (non-secure) + \details Sets the priority of a non-secure device specific interrupt or a non-secure processor exception when in secure state. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + \param [in] IRQn Interrupt number. + \param [in] priority Priority to set. + \note The priority cannot be set for every non-secure processor exception. + */ +__STATIC_INLINE void TZ_NVIC_SetPriority_NS(IRQn_Type IRQn, uint32_t priority) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC_NS->IPR[((uint32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); + } + else + { + SCB_NS->SHPR[(((uint32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); + } +} + + +/** + \brief Get Interrupt Priority (non-secure) + \details Reads the priority of a non-secure device specific interrupt or a non-secure processor exception when in secure state. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + \param [in] IRQn Interrupt number. + \return Interrupt Priority. Value is aligned automatically to the implemented priority bits of the microcontroller. + */ +__STATIC_INLINE uint32_t TZ_NVIC_GetPriority_NS(IRQn_Type IRQn) +{ + + if ((int32_t)(IRQn) >= 0) + { + return(((uint32_t)NVIC_NS->IPR[((uint32_t)IRQn)] >> (8U - __NVIC_PRIO_BITS))); + } + else + { + return(((uint32_t)SCB_NS->SHPR[(((uint32_t)IRQn) & 0xFUL)-4UL] >> (8U - __NVIC_PRIO_BITS))); + } +} +#endif /* defined (__ARM_FEATURE_CMSE) &&(__ARM_FEATURE_CMSE == 3U) */ + +/*@} end of CMSIS_Core_NVICFunctions */ + +/* ########################## MPU functions #################################### */ + +#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) + +#include "mpu_armv8.h" + +#endif + +/* ########################## FPU functions #################################### */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_FpuFunctions FPU Functions + \brief Function that provides FPU type. + @{ + */ + +/** + \brief get FPU type + \details returns the FPU type + \returns + - \b 0: No FPU + - \b 1: Single precision FPU + - \b 2: Double + Single precision FPU + */ +__STATIC_INLINE uint32_t SCB_GetFPUType(void) +{ + uint32_t mvfr0; + + mvfr0 = FPU->MVFR0; + if ((mvfr0 & (FPU_MVFR0_Single_precision_Msk | FPU_MVFR0_Double_precision_Msk)) == 0x220U) + { + return 2U; /* Double + Single precision FPU */ + } + else if ((mvfr0 & (FPU_MVFR0_Single_precision_Msk | FPU_MVFR0_Double_precision_Msk)) == 0x020U) + { + return 1U; /* Single precision FPU */ + } + else + { + return 0U; /* No FPU */ + } +} + + +/*@} end of CMSIS_Core_FpuFunctions */ + + + +/* ########################## SAU functions #################################### */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_SAUFunctions SAU Functions + \brief Functions that configure the SAU. + @{ + */ + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) + +/** + \brief Enable SAU + \details Enables the Security Attribution Unit (SAU). + */ +__STATIC_INLINE void TZ_SAU_Enable(void) +{ + SAU->CTRL |= (SAU_CTRL_ENABLE_Msk); +} + + + +/** + \brief Disable SAU + \details Disables the Security Attribution Unit (SAU). + */ +__STATIC_INLINE void TZ_SAU_Disable(void) +{ + SAU->CTRL &= ~(SAU_CTRL_ENABLE_Msk); +} + +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + +/*@} end of CMSIS_Core_SAUFunctions */ + + + +/* ################################## Debug Control function ############################################ */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_DCBFunctions Debug Control Functions + \brief Functions that access the Debug Control Block. + @{ + */ + + +/** + \brief Set Debug Authentication Control Register + \details writes to Debug Authentication Control register. + \param [in] value value to be writen. + */ +__STATIC_INLINE void DCB_SetAuthCtrl(uint32_t value) +{ + __DSB(); + __ISB(); + DCB->DAUTHCTRL = value; + __DSB(); + __ISB(); +} + + +/** + \brief Get Debug Authentication Control Register + \details Reads Debug Authentication Control register. + \return Debug Authentication Control Register. + */ +__STATIC_INLINE uint32_t DCB_GetAuthCtrl(void) +{ + return (DCB->DAUTHCTRL); +} + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief Set Debug Authentication Control Register (non-secure) + \details writes to non-secure Debug Authentication Control register when in secure state. + \param [in] value value to be writen + */ +__STATIC_INLINE void TZ_DCB_SetAuthCtrl_NS(uint32_t value) +{ + __DSB(); + __ISB(); + DCB_NS->DAUTHCTRL = value; + __DSB(); + __ISB(); +} + + +/** + \brief Get Debug Authentication Control Register (non-secure) + \details Reads non-secure Debug Authentication Control register when in secure state. + \return Debug Authentication Control Register. + */ +__STATIC_INLINE uint32_t TZ_DCB_GetAuthCtrl_NS(void) +{ + return (DCB_NS->DAUTHCTRL); +} +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + +/*@} end of CMSIS_Core_DCBFunctions */ + + + + +/* ################################## Debug Identification function ############################################ */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_DIBFunctions Debug Identification Functions + \brief Functions that access the Debug Identification Block. + @{ + */ + + +/** + \brief Get Debug Authentication Status Register + \details Reads Debug Authentication Status register. + \return Debug Authentication Status Register. + */ +__STATIC_INLINE uint32_t DIB_GetAuthStatus(void) +{ + return (DIB->DAUTHSTATUS); +} + + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief Get Debug Authentication Status Register (non-secure) + \details Reads non-secure Debug Authentication Status register when in secure state. + \return Debug Authentication Status Register. + */ +__STATIC_INLINE uint32_t TZ_DIB_GetAuthStatus_NS(void) +{ + return (DIB_NS->DAUTHSTATUS); +} +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + +/*@} end of CMSIS_Core_DCBFunctions */ + + +#if ((defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U)) || \ + (defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U))) + +/* ########################## Cache functions #################################### */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_CacheFunctions Cache Functions + \brief Functions that configure Instruction and Data cache. + @{ + */ + +/* Cache Size ID Register Macros */ +#define CCSIDR_WAYS(x) (((x) & SCB_CCSIDR_ASSOCIATIVITY_Msk) >> SCB_CCSIDR_ASSOCIATIVITY_Pos) +#define CCSIDR_SETS(x) (((x) & SCB_CCSIDR_NUMSETS_Msk ) >> SCB_CCSIDR_NUMSETS_Pos ) + +#define __SCB_DCACHE_LINE_SIZE 32U /*!< STAR-MC1 cache line size is fixed to 32 bytes (8 words). See also register SCB_CCSIDR */ +#define __SCB_ICACHE_LINE_SIZE 32U /*!< STAR-MC1 cache line size is fixed to 32 bytes (8 words). See also register SCB_CCSIDR */ + +/** + \brief Enable I-Cache + \details Turns on I-Cache + */ +__STATIC_FORCEINLINE void SCB_EnableICache (void) +{ + #if defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U) + if (SCB->CCR & SCB_CCR_IC_Msk) return; /* return if ICache is already enabled */ + + __DSB(); + __ISB(); + SCB->ICIALLU = 0UL; /* invalidate I-Cache */ + __DSB(); + __ISB(); + SCB->CCR |= (uint32_t)SCB_CCR_IC_Msk; /* enable I-Cache */ + __DSB(); + __ISB(); + #endif +} + + +/** + \brief Disable I-Cache + \details Turns off I-Cache + */ +__STATIC_FORCEINLINE void SCB_DisableICache (void) +{ + #if defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U) + __DSB(); + __ISB(); + SCB->CCR &= ~(uint32_t)SCB_CCR_IC_Msk; /* disable I-Cache */ + SCB->ICIALLU = 0UL; /* invalidate I-Cache */ + __DSB(); + __ISB(); + #endif +} + + +/** + \brief Invalidate I-Cache + \details Invalidates I-Cache + */ +__STATIC_FORCEINLINE void SCB_InvalidateICache (void) +{ + #if defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U) + __DSB(); + __ISB(); + SCB->ICIALLU = 0UL; + __DSB(); + __ISB(); + #endif +} + + +/** + \brief I-Cache Invalidate by address + \details Invalidates I-Cache for the given address. + I-Cache is invalidated starting from a 32 byte aligned address in 32 byte granularity. + I-Cache memory blocks which are part of given address + given size are invalidated. + \param[in] addr address + \param[in] isize size of memory block (in number of bytes) +*/ +__STATIC_FORCEINLINE void SCB_InvalidateICache_by_Addr (void *addr, int32_t isize) +{ + #if defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U) + if ( isize > 0 ) { + int32_t op_size = isize + (((uint32_t)addr) & (__SCB_ICACHE_LINE_SIZE - 1U)); + uint32_t op_addr = (uint32_t)addr /* & ~(__SCB_ICACHE_LINE_SIZE - 1U) */; + + __DSB(); + + do { + SCB->ICIMVAU = op_addr; /* register accepts only 32byte aligned values, only bits 31..5 are valid */ + op_addr += __SCB_ICACHE_LINE_SIZE; + op_size -= __SCB_ICACHE_LINE_SIZE; + } while ( op_size > 0 ); + + __DSB(); + __ISB(); + } + #endif +} + + +/** + \brief Enable D-Cache + \details Turns on D-Cache + */ +__STATIC_FORCEINLINE void SCB_EnableDCache (void) +{ + #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) + uint32_t ccsidr; + uint32_t sets; + uint32_t ways; + + if (SCB->CCR & SCB_CCR_DC_Msk) return; /* return if DCache is already enabled */ + + SCB->CSSELR = 0U; /* select Level 1 data cache */ + __DSB(); + + ccsidr = SCB->CCSIDR; + + /* invalidate D-Cache */ + sets = (uint32_t)(CCSIDR_SETS(ccsidr)); + do { + ways = (uint32_t)(CCSIDR_WAYS(ccsidr)); + do { + SCB->DCISW = (((sets << SCB_DCISW_SET_Pos) & SCB_DCISW_SET_Msk) | + ((ways << SCB_DCISW_WAY_Pos) & SCB_DCISW_WAY_Msk) ); + #if defined ( __CC_ARM ) + __schedule_barrier(); + #endif + } while (ways-- != 0U); + } while(sets-- != 0U); + __DSB(); + + SCB->CCR |= (uint32_t)SCB_CCR_DC_Msk; /* enable D-Cache */ + + __DSB(); + __ISB(); + #endif +} + + +/** + \brief Disable D-Cache + \details Turns off D-Cache + */ +__STATIC_FORCEINLINE void SCB_DisableDCache (void) +{ + #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) + uint32_t ccsidr; + uint32_t sets; + uint32_t ways; + + SCB->CSSELR = 0U; /* select Level 1 data cache */ + __DSB(); + + SCB->CCR &= ~(uint32_t)SCB_CCR_DC_Msk; /* disable D-Cache */ + __DSB(); + + ccsidr = SCB->CCSIDR; + + /* clean & invalidate D-Cache */ + sets = (uint32_t)(CCSIDR_SETS(ccsidr)); + do { + ways = (uint32_t)(CCSIDR_WAYS(ccsidr)); + do { + SCB->DCCISW = (((sets << SCB_DCCISW_SET_Pos) & SCB_DCCISW_SET_Msk) | + ((ways << SCB_DCCISW_WAY_Pos) & SCB_DCCISW_WAY_Msk) ); + #if defined ( __CC_ARM ) + __schedule_barrier(); + #endif + } while (ways-- != 0U); + } while(sets-- != 0U); + + __DSB(); + __ISB(); + #endif +} + + +/** + \brief Invalidate D-Cache + \details Invalidates D-Cache + */ +__STATIC_FORCEINLINE void SCB_InvalidateDCache (void) +{ + #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) + uint32_t ccsidr; + uint32_t sets; + uint32_t ways; + + SCB->CSSELR = 0U; /* select Level 1 data cache */ + __DSB(); + + ccsidr = SCB->CCSIDR; + + /* invalidate D-Cache */ + sets = (uint32_t)(CCSIDR_SETS(ccsidr)); + do { + ways = (uint32_t)(CCSIDR_WAYS(ccsidr)); + do { + SCB->DCISW = (((sets << SCB_DCISW_SET_Pos) & SCB_DCISW_SET_Msk) | + ((ways << SCB_DCISW_WAY_Pos) & SCB_DCISW_WAY_Msk) ); + #if defined ( __CC_ARM ) + __schedule_barrier(); + #endif + } while (ways-- != 0U); + } while(sets-- != 0U); + + __DSB(); + __ISB(); + #endif +} + + +/** + \brief Clean D-Cache + \details Cleans D-Cache + */ +__STATIC_FORCEINLINE void SCB_CleanDCache (void) +{ + #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) + uint32_t ccsidr; + uint32_t sets; + uint32_t ways; + + SCB->CSSELR = 0U; /* select Level 1 data cache */ + __DSB(); + + ccsidr = SCB->CCSIDR; + + /* clean D-Cache */ + sets = (uint32_t)(CCSIDR_SETS(ccsidr)); + do { + ways = (uint32_t)(CCSIDR_WAYS(ccsidr)); + do { + SCB->DCCSW = (((sets << SCB_DCCSW_SET_Pos) & SCB_DCCSW_SET_Msk) | + ((ways << SCB_DCCSW_WAY_Pos) & SCB_DCCSW_WAY_Msk) ); + #if defined ( __CC_ARM ) + __schedule_barrier(); + #endif + } while (ways-- != 0U); + } while(sets-- != 0U); + + __DSB(); + __ISB(); + #endif +} + + +/** + \brief Clean & Invalidate D-Cache + \details Cleans and Invalidates D-Cache + */ +__STATIC_FORCEINLINE void SCB_CleanInvalidateDCache (void) +{ + #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) + uint32_t ccsidr; + uint32_t sets; + uint32_t ways; + + SCB->CSSELR = 0U; /* select Level 1 data cache */ + __DSB(); + + ccsidr = SCB->CCSIDR; + + /* clean & invalidate D-Cache */ + sets = (uint32_t)(CCSIDR_SETS(ccsidr)); + do { + ways = (uint32_t)(CCSIDR_WAYS(ccsidr)); + do { + SCB->DCCISW = (((sets << SCB_DCCISW_SET_Pos) & SCB_DCCISW_SET_Msk) | + ((ways << SCB_DCCISW_WAY_Pos) & SCB_DCCISW_WAY_Msk) ); + #if defined ( __CC_ARM ) + __schedule_barrier(); + #endif + } while (ways-- != 0U); + } while(sets-- != 0U); + + __DSB(); + __ISB(); + #endif +} + + +/** + \brief D-Cache Invalidate by address + \details Invalidates D-Cache for the given address. + D-Cache is invalidated starting from a 32 byte aligned address in 32 byte granularity. + D-Cache memory blocks which are part of given address + given size are invalidated. + \param[in] addr address + \param[in] dsize size of memory block (in number of bytes) +*/ +__STATIC_FORCEINLINE void SCB_InvalidateDCache_by_Addr (void *addr, int32_t dsize) +{ + #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) + if ( dsize > 0 ) { + int32_t op_size = dsize + (((uint32_t)addr) & (__SCB_DCACHE_LINE_SIZE - 1U)); + uint32_t op_addr = (uint32_t)addr /* & ~(__SCB_DCACHE_LINE_SIZE - 1U) */; + + __DSB(); + + do { + SCB->DCIMVAC = op_addr; /* register accepts only 32byte aligned values, only bits 31..5 are valid */ + op_addr += __SCB_DCACHE_LINE_SIZE; + op_size -= __SCB_DCACHE_LINE_SIZE; + } while ( op_size > 0 ); + + __DSB(); + __ISB(); + } + #endif +} + + +/** + \brief D-Cache Clean by address + \details Cleans D-Cache for the given address + D-Cache is cleaned starting from a 32 byte aligned address in 32 byte granularity. + D-Cache memory blocks which are part of given address + given size are cleaned. + \param[in] addr address + \param[in] dsize size of memory block (in number of bytes) +*/ +__STATIC_FORCEINLINE void SCB_CleanDCache_by_Addr (uint32_t *addr, int32_t dsize) +{ + #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) + if ( dsize > 0 ) { + int32_t op_size = dsize + (((uint32_t)addr) & (__SCB_DCACHE_LINE_SIZE - 1U)); + uint32_t op_addr = (uint32_t)addr /* & ~(__SCB_DCACHE_LINE_SIZE - 1U) */; + + __DSB(); + + do { + SCB->DCCMVAC = op_addr; /* register accepts only 32byte aligned values, only bits 31..5 are valid */ + op_addr += __SCB_DCACHE_LINE_SIZE; + op_size -= __SCB_DCACHE_LINE_SIZE; + } while ( op_size > 0 ); + + __DSB(); + __ISB(); + } + #endif +} + + +/** + \brief D-Cache Clean and Invalidate by address + \details Cleans and invalidates D_Cache for the given address + D-Cache is cleaned and invalidated starting from a 32 byte aligned address in 32 byte granularity. + D-Cache memory blocks which are part of given address + given size are cleaned and invalidated. + \param[in] addr address (aligned to 32-byte boundary) + \param[in] dsize size of memory block (in number of bytes) +*/ +__STATIC_FORCEINLINE void SCB_CleanInvalidateDCache_by_Addr (uint32_t *addr, int32_t dsize) +{ + #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) + if ( dsize > 0 ) { + int32_t op_size = dsize + (((uint32_t)addr) & (__SCB_DCACHE_LINE_SIZE - 1U)); + uint32_t op_addr = (uint32_t)addr /* & ~(__SCB_DCACHE_LINE_SIZE - 1U) */; + + __DSB(); + + do { + SCB->DCCIMVAC = op_addr; /* register accepts only 32byte aligned values, only bits 31..5 are valid */ + op_addr += __SCB_DCACHE_LINE_SIZE; + op_size -= __SCB_DCACHE_LINE_SIZE; + } while ( op_size > 0 ); + + __DSB(); + __ISB(); + } + #endif +} + +/*@} end of CMSIS_Core_CacheFunctions */ +#endif + + +/* ################################## SysTick function ############################################ */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_SysTickFunctions SysTick Functions + \brief Functions that configure the System. + @{ + */ + +#if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U) + +/** + \brief System Tick Configuration + \details Initializes the System Timer and its interrupt, and starts the System Tick Timer. + Counter is in free running mode to generate periodic interrupts. + \param [in] ticks Number of ticks between two interrupts. + \return 0 Function succeeded. + \return 1 Function failed. + \note When the variable __Vendor_SysTickConfig is set to 1, then the + function SysTick_Config is not included. In this case, the file device.h + must contain a vendor-specific implementation of this function. + */ +__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks) +{ + if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk) + { + return (1UL); /* Reload value impossible */ + } + + SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */ + NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */ + SysTick->VAL = 0UL; /* Load the SysTick Counter Value */ + SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | + SysTick_CTRL_TICKINT_Msk | + SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */ + return (0UL); /* Function successful */ +} + +#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) +/** + \brief System Tick Configuration (non-secure) + \details Initializes the non-secure System Timer and its interrupt when in secure state, and starts the System Tick Timer. + Counter is in free running mode to generate periodic interrupts. + \param [in] ticks Number of ticks between two interrupts. + \return 0 Function succeeded. + \return 1 Function failed. + \note When the variable __Vendor_SysTickConfig is set to 1, then the + function TZ_SysTick_Config_NS is not included. In this case, the file device.h + must contain a vendor-specific implementation of this function. + + */ +__STATIC_INLINE uint32_t TZ_SysTick_Config_NS(uint32_t ticks) +{ + if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk) + { + return (1UL); /* Reload value impossible */ + } + + SysTick_NS->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */ + TZ_NVIC_SetPriority_NS (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */ + SysTick_NS->VAL = 0UL; /* Load the SysTick Counter Value */ + SysTick_NS->CTRL = SysTick_CTRL_CLKSOURCE_Msk | + SysTick_CTRL_TICKINT_Msk | + SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */ + return (0UL); /* Function successful */ +} +#endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ + +#endif + +/*@} end of CMSIS_Core_SysTickFunctions */ + + + +/* ##################################### Debug In/Output function ########################################### */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_core_DebugFunctions ITM Functions + \brief Functions that access the ITM debug interface. + @{ + */ + +extern volatile int32_t ITM_RxBuffer; /*!< External variable to receive characters. */ +#define ITM_RXBUFFER_EMPTY ((int32_t)0x5AA55AA5U) /*!< Value identifying \ref ITM_RxBuffer is ready for next character. */ + + +/** + \brief ITM Send Character + \details Transmits a character via the ITM channel 0, and + \li Just returns when no debugger is connected that has booked the output. + \li Is blocking when a debugger is connected, but the previous character sent has not been transmitted. + \param [in] ch Character to transmit. + \returns Character to transmit. + */ +__STATIC_INLINE uint32_t ITM_SendChar (uint32_t ch) +{ + if (((ITM->TCR & ITM_TCR_ITMENA_Msk) != 0UL) && /* ITM enabled */ + ((ITM->TER & 1UL ) != 0UL) ) /* ITM Port #0 enabled */ + { + while (ITM->PORT[0U].u32 == 0UL) + { + __NOP(); + } + ITM->PORT[0U].u8 = (uint8_t)ch; + } + return (ch); +} + + +/** + \brief ITM Receive Character + \details Inputs a character via the external variable \ref ITM_RxBuffer. + \return Received character. + \return -1 No character pending. + */ +__STATIC_INLINE int32_t ITM_ReceiveChar (void) +{ + int32_t ch = -1; /* no character available */ + + if (ITM_RxBuffer != ITM_RXBUFFER_EMPTY) + { + ch = ITM_RxBuffer; + ITM_RxBuffer = ITM_RXBUFFER_EMPTY; /* ready for next character */ + } + + return (ch); +} + + +/** + \brief ITM Check Character + \details Checks whether a character is pending for reading in the variable \ref ITM_RxBuffer. + \return 0 No character available. + \return 1 Character available. + */ +__STATIC_INLINE int32_t ITM_CheckChar (void) +{ + + if (ITM_RxBuffer == ITM_RXBUFFER_EMPTY) + { + return (0); /* no character available */ + } + else + { + return (1); /* character available */ + } +} + +/*@} end of CMSIS_core_DebugFunctions */ + + + + +#ifdef __cplusplus +} +#endif + +#endif /* __CORE_STAR_H_DEPENDANT */ + +#endif /* __CMSIS_GENERIC */ diff --git a/lib/cmsis/inc/mpu_armv7.h b/lib/cmsis/inc/mpu_armv7.h index 66ef59b4a0bff..d9eedf81a64c3 100644 --- a/lib/cmsis/inc/mpu_armv7.h +++ b/lib/cmsis/inc/mpu_armv7.h @@ -1,11 +1,11 @@ /****************************************************************************** * @file mpu_armv7.h * @brief CMSIS MPU API for Armv7-M MPU - * @version V5.1.0 - * @date 08. March 2019 + * @version V5.1.2 + * @date 25. May 2020 ******************************************************************************/ /* - * Copyright (c) 2017-2019 Arm Limited. All rights reserved. + * Copyright (c) 2017-2020 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -154,7 +154,7 @@ * \param InnerCp Configures the inner cache policy. * \param IsShareable Configures the memory as shareable or non-shareable. */ -#define ARM_MPU_ACCESS_NORMAL(OuterCp, InnerCp, IsShareable) ARM_MPU_ACCESS_((4U | (OuterCp)), IsShareable, ((InnerCp) & 2U), ((InnerCp) & 1U)) +#define ARM_MPU_ACCESS_NORMAL(OuterCp, InnerCp, IsShareable) ARM_MPU_ACCESS_((4U | (OuterCp)), IsShareable, ((InnerCp) >> 1U), ((InnerCp) & 1U)) /** * MPU Memory Access Attribute non-cacheable policy. @@ -190,6 +190,7 @@ typedef struct { */ __STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control) { + __DMB(); MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk; #ifdef SCB_SHCSR_MEMFAULTENA_Msk SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk; @@ -207,6 +208,8 @@ __STATIC_INLINE void ARM_MPU_Disable(void) SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk; #endif MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk; + __DSB(); + __ISB(); } /** Clear and disable the given MPU region. @@ -220,7 +223,7 @@ __STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr) /** Configure an MPU region. * \param rbar Value for RBAR register. -* \param rsar Value for RSAR register. +* \param rasr Value for RASR register. */ __STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rbar, uint32_t rasr) { @@ -231,7 +234,7 @@ __STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rbar, uint32_t rasr) /** Configure the given MPU region. * \param rnr Region number to be configured. * \param rbar Value for RBAR register. -* \param rsar Value for RSAR register. +* \param rasr Value for RASR register. */ __STATIC_INLINE void ARM_MPU_SetRegionEx(uint32_t rnr, uint32_t rbar, uint32_t rasr) { @@ -240,7 +243,7 @@ __STATIC_INLINE void ARM_MPU_SetRegionEx(uint32_t rnr, uint32_t rbar, uint32_t r MPU->RASR = rasr; } -/** Memcopy with strictly ordered memory access, e.g. for register targets. +/** Memcpy with strictly ordered memory access, e.g. used by code in ARM_MPU_Load(). * \param dst Destination data is copied to. * \param src Source data is copied from. * \param len Amount of data words to be copied. diff --git a/lib/cmsis/inc/mpu_armv8.h b/lib/cmsis/inc/mpu_armv8.h index 0041d4dc6ff53..3de16efc86a6f 100644 --- a/lib/cmsis/inc/mpu_armv8.h +++ b/lib/cmsis/inc/mpu_armv8.h @@ -1,11 +1,11 @@ /****************************************************************************** * @file mpu_armv8.h * @brief CMSIS MPU API for Armv8-M and Armv8.1-M MPU - * @version V5.1.0 - * @date 08. March 2019 + * @version V5.1.3 + * @date 03. February 2021 ******************************************************************************/ /* - * Copyright (c) 2017-2019 Arm Limited. All rights reserved. + * Copyright (c) 2017-2021 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -44,7 +44,7 @@ * \param WA Write Allocation: Set to 1 to use cache allocation on write miss. */ #define ARM_MPU_ATTR_MEMORY_(NT, WB, RA, WA) \ - (((NT & 1U) << 3U) | ((WB & 1U) << 2U) | ((RA & 1U) << 1U) | (WA & 1U)) + ((((NT) & 1U) << 3U) | (((WB) & 1U) << 2U) | (((RA) & 1U) << 1U) | ((WA) & 1U)) /** \brief Device memory type non Gathering, non Re-ordering, non Early Write Acknowledgement */ #define ARM_MPU_ATTR_DEVICE_nGnRnE (0U) @@ -62,7 +62,7 @@ * \param O Outer memory attributes * \param I O == ARM_MPU_ATTR_DEVICE: Device memory attributes, else: Inner memory attributes */ -#define ARM_MPU_ATTR(O, I) (((O & 0xFU) << 4U) | (((O & 0xFU) != 0U) ? (I & 0xFU) : ((I & 0x3U) << 2U))) +#define ARM_MPU_ATTR(O, I) ((((O) & 0xFU) << 4U) | ((((O) & 0xFU) != 0U) ? ((I) & 0xFU) : (((I) & 0x3U) << 2U))) /** \brief Normal memory non-shareable */ #define ARM_MPU_SH_NON (0U) @@ -77,7 +77,7 @@ * \param RO Read-Only: Set to 1 for read-only memory. * \param NP Non-Privileged: Set to 1 for non-privileged memory. */ -#define ARM_MPU_AP_(RO, NP) (((RO & 1U) << 1U) | (NP & 1U)) +#define ARM_MPU_AP_(RO, NP) ((((RO) & 1U) << 1U) | ((NP) & 1U)) /** \brief Region Base Address Register value * \param BASE The base address bits [31:5] of a memory region. The value is zero extended. Effective address gets 32 byte aligned. @@ -87,18 +87,18 @@ * \oaram XN eXecute Never: Set to 1 for a non-executable memory region. */ #define ARM_MPU_RBAR(BASE, SH, RO, NP, XN) \ - ((BASE & MPU_RBAR_BASE_Msk) | \ - ((SH << MPU_RBAR_SH_Pos) & MPU_RBAR_SH_Msk) | \ + (((BASE) & MPU_RBAR_BASE_Msk) | \ + (((SH) << MPU_RBAR_SH_Pos) & MPU_RBAR_SH_Msk) | \ ((ARM_MPU_AP_(RO, NP) << MPU_RBAR_AP_Pos) & MPU_RBAR_AP_Msk) | \ - ((XN << MPU_RBAR_XN_Pos) & MPU_RBAR_XN_Msk)) + (((XN) << MPU_RBAR_XN_Pos) & MPU_RBAR_XN_Msk)) /** \brief Region Limit Address Register value * \param LIMIT The limit address bits [31:5] for this memory region. The value is one extended. * \param IDX The attribute index to be associated with this memory region. */ #define ARM_MPU_RLAR(LIMIT, IDX) \ - ((LIMIT & MPU_RLAR_LIMIT_Msk) | \ - ((IDX << MPU_RLAR_AttrIndx_Pos) & MPU_RLAR_AttrIndx_Msk) | \ + (((LIMIT) & MPU_RLAR_LIMIT_Msk) | \ + (((IDX) << MPU_RLAR_AttrIndx_Pos) & MPU_RLAR_AttrIndx_Msk) | \ (MPU_RLAR_EN_Msk)) #if defined(MPU_RLAR_PXN_Pos) @@ -109,9 +109,9 @@ * \param IDX The attribute index to be associated with this memory region. */ #define ARM_MPU_RLAR_PXN(LIMIT, PXN, IDX) \ - ((LIMIT & MPU_RLAR_LIMIT_Msk) | \ - ((PXN << MPU_RLAR_PXN_Pos) & MPU_RLAR_PXN_Msk) | \ - ((IDX << MPU_RLAR_AttrIndx_Pos) & MPU_RLAR_AttrIndx_Msk) | \ + (((LIMIT) & MPU_RLAR_LIMIT_Msk) | \ + (((PXN) << MPU_RLAR_PXN_Pos) & MPU_RLAR_PXN_Msk) | \ + (((IDX) << MPU_RLAR_AttrIndx_Pos) & MPU_RLAR_AttrIndx_Msk) | \ (MPU_RLAR_EN_Msk)) #endif @@ -129,6 +129,7 @@ typedef struct { */ __STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control) { + __DMB(); MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk; #ifdef SCB_SHCSR_MEMFAULTENA_Msk SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk; @@ -146,6 +147,8 @@ __STATIC_INLINE void ARM_MPU_Disable(void) SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk; #endif MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk; + __DSB(); + __ISB(); } #ifdef MPU_NS @@ -154,6 +157,7 @@ __STATIC_INLINE void ARM_MPU_Disable(void) */ __STATIC_INLINE void ARM_MPU_Enable_NS(uint32_t MPU_Control) { + __DMB(); MPU_NS->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk; #ifdef SCB_SHCSR_MEMFAULTENA_Msk SCB_NS->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk; @@ -171,6 +175,8 @@ __STATIC_INLINE void ARM_MPU_Disable_NS(void) SCB_NS->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk; #endif MPU_NS->CTRL &= ~MPU_CTRL_ENABLE_Msk; + __DSB(); + __ISB(); } #endif @@ -275,7 +281,7 @@ __STATIC_INLINE void ARM_MPU_SetRegion_NS(uint32_t rnr, uint32_t rbar, uint32_t } #endif -/** Memcopy with strictly ordered memory access, e.g. for register targets. +/** Memcpy with strictly ordered memory access, e.g. used by code in ARM_MPU_LoadEx() * \param dst Destination data is copied to. * \param src Source data is copied from. * \param len Amount of data words to be copied. diff --git a/lib/cmsis/inc/pac_armv81.h b/lib/cmsis/inc/pac_armv81.h new file mode 100644 index 0000000000000..854b60a204cc9 --- /dev/null +++ b/lib/cmsis/inc/pac_armv81.h @@ -0,0 +1,206 @@ +/****************************************************************************** + * @file pac_armv81.h + * @brief CMSIS PAC key functions for Armv8.1-M PAC extension + * @version V1.0.0 + * @date 23. March 2022 + ******************************************************************************/ +/* + * Copyright (c) 2022 Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 + * + * 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. + */ + +#if defined ( __ICCARM__ ) + #pragma system_include /* treat file as system include file for MISRA check */ +#elif defined (__clang__) + #pragma clang system_header /* treat file as system include file */ +#endif + +#ifndef PAC_ARMV81_H +#define PAC_ARMV81_H + + +/* ################### PAC Key functions ########################### */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_PacKeyFunctions PAC Key functions + \brief Functions that access the PAC keys. + @{ + */ + +#if (defined (__ARM_FEATURE_PAUTH) && (__ARM_FEATURE_PAUTH == 1)) + +/** + \brief read the PAC key used for privileged mode + \details Reads the PAC key stored in the PAC_KEY_P registers. + \param [out] pPacKey 128bit PAC key + */ +__STATIC_FORCEINLINE void __get_PAC_KEY_P (uint32_t* pPacKey) { + __ASM volatile ( + "mrs r1, pac_key_p_0\n" + "str r1,[%0,#0]\n" + "mrs r1, pac_key_p_1\n" + "str r1,[%0,#4]\n" + "mrs r1, pac_key_p_2\n" + "str r1,[%0,#8]\n" + "mrs r1, pac_key_p_3\n" + "str r1,[%0,#12]\n" + : : "r" (pPacKey) : "memory", "r1" + ); +} + +/** + \brief write the PAC key used for privileged mode + \details writes the given PAC key to the PAC_KEY_P registers. + \param [in] pPacKey 128bit PAC key + */ +__STATIC_FORCEINLINE void __set_PAC_KEY_P (uint32_t* pPacKey) { + __ASM volatile ( + "ldr r1,[%0,#0]\n" + "msr pac_key_p_0, r1\n" + "ldr r1,[%0,#4]\n" + "msr pac_key_p_1, r1\n" + "ldr r1,[%0,#8]\n" + "msr pac_key_p_2, r1\n" + "ldr r1,[%0,#12]\n" + "msr pac_key_p_3, r1\n" + : : "r" (pPacKey) : "memory", "r1" + ); +} + +/** + \brief read the PAC key used for unprivileged mode + \details Reads the PAC key stored in the PAC_KEY_U registers. + \param [out] pPacKey 128bit PAC key + */ +__STATIC_FORCEINLINE void __get_PAC_KEY_U (uint32_t* pPacKey) { + __ASM volatile ( + "mrs r1, pac_key_u_0\n" + "str r1,[%0,#0]\n" + "mrs r1, pac_key_u_1\n" + "str r1,[%0,#4]\n" + "mrs r1, pac_key_u_2\n" + "str r1,[%0,#8]\n" + "mrs r1, pac_key_u_3\n" + "str r1,[%0,#12]\n" + : : "r" (pPacKey) : "memory", "r1" + ); +} + +/** + \brief write the PAC key used for unprivileged mode + \details writes the given PAC key to the PAC_KEY_U registers. + \param [in] pPacKey 128bit PAC key + */ +__STATIC_FORCEINLINE void __set_PAC_KEY_U (uint32_t* pPacKey) { + __ASM volatile ( + "ldr r1,[%0,#0]\n" + "msr pac_key_u_0, r1\n" + "ldr r1,[%0,#4]\n" + "msr pac_key_u_1, r1\n" + "ldr r1,[%0,#8]\n" + "msr pac_key_u_2, r1\n" + "ldr r1,[%0,#12]\n" + "msr pac_key_u_3, r1\n" + : : "r" (pPacKey) : "memory", "r1" + ); +} + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) + +/** + \brief read the PAC key used for privileged mode (non-secure) + \details Reads the PAC key stored in the non-secure PAC_KEY_P registers when in secure mode. + \param [out] pPacKey 128bit PAC key + */ +__STATIC_FORCEINLINE void __TZ_get_PAC_KEY_P_NS (uint32_t* pPacKey) { + __ASM volatile ( + "mrs r1, pac_key_p_0_ns\n" + "str r1,[%0,#0]\n" + "mrs r1, pac_key_p_1_ns\n" + "str r1,[%0,#4]\n" + "mrs r1, pac_key_p_2_ns\n" + "str r1,[%0,#8]\n" + "mrs r1, pac_key_p_3_ns\n" + "str r1,[%0,#12]\n" + : : "r" (pPacKey) : "memory", "r1" + ); +} + +/** + \brief write the PAC key used for privileged mode (non-secure) + \details writes the given PAC key to the non-secure PAC_KEY_P registers when in secure mode. + \param [in] pPacKey 128bit PAC key + */ +__STATIC_FORCEINLINE void __TZ_set_PAC_KEY_P_NS (uint32_t* pPacKey) { + __ASM volatile ( + "ldr r1,[%0,#0]\n" + "msr pac_key_p_0_ns, r1\n" + "ldr r1,[%0,#4]\n" + "msr pac_key_p_1_ns, r1\n" + "ldr r1,[%0,#8]\n" + "msr pac_key_p_2_ns, r1\n" + "ldr r1,[%0,#12]\n" + "msr pac_key_p_3_ns, r1\n" + : : "r" (pPacKey) : "memory", "r1" + ); +} + +/** + \brief read the PAC key used for unprivileged mode (non-secure) + \details Reads the PAC key stored in the non-secure PAC_KEY_U registers when in secure mode. + \param [out] pPacKey 128bit PAC key + */ +__STATIC_FORCEINLINE void __TZ_get_PAC_KEY_U_NS (uint32_t* pPacKey) { + __ASM volatile ( + "mrs r1, pac_key_u_0_ns\n" + "str r1,[%0,#0]\n" + "mrs r1, pac_key_u_1_ns\n" + "str r1,[%0,#4]\n" + "mrs r1, pac_key_u_2_ns\n" + "str r1,[%0,#8]\n" + "mrs r1, pac_key_u_3_ns\n" + "str r1,[%0,#12]\n" + : : "r" (pPacKey) : "memory", "r1" + ); +} + +/** + \brief write the PAC key used for unprivileged mode (non-secure) + \details writes the given PAC key to the non-secure PAC_KEY_U registers when in secure mode. + \param [in] pPacKey 128bit PAC key + */ +__STATIC_FORCEINLINE void __TZ_set_PAC_KEY_U_NS (uint32_t* pPacKey) { + __ASM volatile ( + "ldr r1,[%0,#0]\n" + "msr pac_key_u_0_ns, r1\n" + "ldr r1,[%0,#4]\n" + "msr pac_key_u_1_ns, r1\n" + "ldr r1,[%0,#8]\n" + "msr pac_key_u_2_ns, r1\n" + "ldr r1,[%0,#12]\n" + "msr pac_key_u_3_ns, r1\n" + : : "r" (pPacKey) : "memory", "r1" + ); +} + +#endif /* (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) */ + +#endif /* (defined (__ARM_FEATURE_PAUTH) && (__ARM_FEATURE_PAUTH == 1)) */ + +/*@} end of CMSIS_Core_PacKeyFunctions */ + + +#endif /* PAC_ARMV81_H */ diff --git a/lib/cmsis/inc/pmu_armv8.h b/lib/cmsis/inc/pmu_armv8.h new file mode 100644 index 0000000000000..f8f3d8935b824 --- /dev/null +++ b/lib/cmsis/inc/pmu_armv8.h @@ -0,0 +1,337 @@ +/****************************************************************************** + * @file pmu_armv8.h + * @brief CMSIS PMU API for Armv8.1-M PMU + * @version V1.0.1 + * @date 15. April 2020 + ******************************************************************************/ +/* + * Copyright (c) 2020 Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 + * + * 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. + */ + +#if defined ( __ICCARM__ ) + #pragma system_include /* treat file as system include file for MISRA check */ +#elif defined (__clang__) + #pragma clang system_header /* treat file as system include file */ +#endif + +#ifndef ARM_PMU_ARMV8_H +#define ARM_PMU_ARMV8_H + +/** + * \brief PMU Events + * \note See the Armv8.1-M Architecture Reference Manual for full details on these PMU events. + * */ + +#define ARM_PMU_SW_INCR 0x0000 /*!< Software update to the PMU_SWINC register, architecturally executed and condition code check pass */ +#define ARM_PMU_L1I_CACHE_REFILL 0x0001 /*!< L1 I-Cache refill */ +#define ARM_PMU_L1D_CACHE_REFILL 0x0003 /*!< L1 D-Cache refill */ +#define ARM_PMU_L1D_CACHE 0x0004 /*!< L1 D-Cache access */ +#define ARM_PMU_LD_RETIRED 0x0006 /*!< Memory-reading instruction architecturally executed and condition code check pass */ +#define ARM_PMU_ST_RETIRED 0x0007 /*!< Memory-writing instruction architecturally executed and condition code check pass */ +#define ARM_PMU_INST_RETIRED 0x0008 /*!< Instruction architecturally executed */ +#define ARM_PMU_EXC_TAKEN 0x0009 /*!< Exception entry */ +#define ARM_PMU_EXC_RETURN 0x000A /*!< Exception return instruction architecturally executed and the condition code check pass */ +#define ARM_PMU_PC_WRITE_RETIRED 0x000C /*!< Software change to the Program Counter (PC). Instruction is architecturally executed and condition code check pass */ +#define ARM_PMU_BR_IMMED_RETIRED 0x000D /*!< Immediate branch architecturally executed */ +#define ARM_PMU_BR_RETURN_RETIRED 0x000E /*!< Function return instruction architecturally executed and the condition code check pass */ +#define ARM_PMU_UNALIGNED_LDST_RETIRED 0x000F /*!< Unaligned memory memory-reading or memory-writing instruction architecturally executed and condition code check pass */ +#define ARM_PMU_BR_MIS_PRED 0x0010 /*!< Mispredicted or not predicted branch speculatively executed */ +#define ARM_PMU_CPU_CYCLES 0x0011 /*!< Cycle */ +#define ARM_PMU_BR_PRED 0x0012 /*!< Predictable branch speculatively executed */ +#define ARM_PMU_MEM_ACCESS 0x0013 /*!< Data memory access */ +#define ARM_PMU_L1I_CACHE 0x0014 /*!< Level 1 instruction cache access */ +#define ARM_PMU_L1D_CACHE_WB 0x0015 /*!< Level 1 data cache write-back */ +#define ARM_PMU_L2D_CACHE 0x0016 /*!< Level 2 data cache access */ +#define ARM_PMU_L2D_CACHE_REFILL 0x0017 /*!< Level 2 data cache refill */ +#define ARM_PMU_L2D_CACHE_WB 0x0018 /*!< Level 2 data cache write-back */ +#define ARM_PMU_BUS_ACCESS 0x0019 /*!< Bus access */ +#define ARM_PMU_MEMORY_ERROR 0x001A /*!< Local memory error */ +#define ARM_PMU_INST_SPEC 0x001B /*!< Instruction speculatively executed */ +#define ARM_PMU_BUS_CYCLES 0x001D /*!< Bus cycles */ +#define ARM_PMU_CHAIN 0x001E /*!< For an odd numbered counter, increment when an overflow occurs on the preceding even-numbered counter on the same PE */ +#define ARM_PMU_L1D_CACHE_ALLOCATE 0x001F /*!< Level 1 data cache allocation without refill */ +#define ARM_PMU_L2D_CACHE_ALLOCATE 0x0020 /*!< Level 2 data cache allocation without refill */ +#define ARM_PMU_BR_RETIRED 0x0021 /*!< Branch instruction architecturally executed */ +#define ARM_PMU_BR_MIS_PRED_RETIRED 0x0022 /*!< Mispredicted branch instruction architecturally executed */ +#define ARM_PMU_STALL_FRONTEND 0x0023 /*!< No operation issued because of the frontend */ +#define ARM_PMU_STALL_BACKEND 0x0024 /*!< No operation issued because of the backend */ +#define ARM_PMU_L2I_CACHE 0x0027 /*!< Level 2 instruction cache access */ +#define ARM_PMU_L2I_CACHE_REFILL 0x0028 /*!< Level 2 instruction cache refill */ +#define ARM_PMU_L3D_CACHE_ALLOCATE 0x0029 /*!< Level 3 data cache allocation without refill */ +#define ARM_PMU_L3D_CACHE_REFILL 0x002A /*!< Level 3 data cache refill */ +#define ARM_PMU_L3D_CACHE 0x002B /*!< Level 3 data cache access */ +#define ARM_PMU_L3D_CACHE_WB 0x002C /*!< Level 3 data cache write-back */ +#define ARM_PMU_LL_CACHE_RD 0x0036 /*!< Last level data cache read */ +#define ARM_PMU_LL_CACHE_MISS_RD 0x0037 /*!< Last level data cache read miss */ +#define ARM_PMU_L1D_CACHE_MISS_RD 0x0039 /*!< Level 1 data cache read miss */ +#define ARM_PMU_OP_COMPLETE 0x003A /*!< Operation retired */ +#define ARM_PMU_OP_SPEC 0x003B /*!< Operation speculatively executed */ +#define ARM_PMU_STALL 0x003C /*!< Stall cycle for instruction or operation not sent for execution */ +#define ARM_PMU_STALL_OP_BACKEND 0x003D /*!< Stall cycle for instruction or operation not sent for execution due to pipeline backend */ +#define ARM_PMU_STALL_OP_FRONTEND 0x003E /*!< Stall cycle for instruction or operation not sent for execution due to pipeline frontend */ +#define ARM_PMU_STALL_OP 0x003F /*!< Instruction or operation slots not occupied each cycle */ +#define ARM_PMU_L1D_CACHE_RD 0x0040 /*!< Level 1 data cache read */ +#define ARM_PMU_LE_RETIRED 0x0100 /*!< Loop end instruction executed */ +#define ARM_PMU_LE_SPEC 0x0101 /*!< Loop end instruction speculatively executed */ +#define ARM_PMU_BF_RETIRED 0x0104 /*!< Branch future instruction architecturally executed and condition code check pass */ +#define ARM_PMU_BF_SPEC 0x0105 /*!< Branch future instruction speculatively executed and condition code check pass */ +#define ARM_PMU_LE_CANCEL 0x0108 /*!< Loop end instruction not taken */ +#define ARM_PMU_BF_CANCEL 0x0109 /*!< Branch future instruction not taken */ +#define ARM_PMU_SE_CALL_S 0x0114 /*!< Call to secure function, resulting in Security state change */ +#define ARM_PMU_SE_CALL_NS 0x0115 /*!< Call to non-secure function, resulting in Security state change */ +#define ARM_PMU_DWT_CMPMATCH0 0x0118 /*!< DWT comparator 0 match */ +#define ARM_PMU_DWT_CMPMATCH1 0x0119 /*!< DWT comparator 1 match */ +#define ARM_PMU_DWT_CMPMATCH2 0x011A /*!< DWT comparator 2 match */ +#define ARM_PMU_DWT_CMPMATCH3 0x011B /*!< DWT comparator 3 match */ +#define ARM_PMU_MVE_INST_RETIRED 0x0200 /*!< MVE instruction architecturally executed */ +#define ARM_PMU_MVE_INST_SPEC 0x0201 /*!< MVE instruction speculatively executed */ +#define ARM_PMU_MVE_FP_RETIRED 0x0204 /*!< MVE floating-point instruction architecturally executed */ +#define ARM_PMU_MVE_FP_SPEC 0x0205 /*!< MVE floating-point instruction speculatively executed */ +#define ARM_PMU_MVE_FP_HP_RETIRED 0x0208 /*!< MVE half-precision floating-point instruction architecturally executed */ +#define ARM_PMU_MVE_FP_HP_SPEC 0x0209 /*!< MVE half-precision floating-point instruction speculatively executed */ +#define ARM_PMU_MVE_FP_SP_RETIRED 0x020C /*!< MVE single-precision floating-point instruction architecturally executed */ +#define ARM_PMU_MVE_FP_SP_SPEC 0x020D /*!< MVE single-precision floating-point instruction speculatively executed */ +#define ARM_PMU_MVE_FP_MAC_RETIRED 0x0214 /*!< MVE floating-point multiply or multiply-accumulate instruction architecturally executed */ +#define ARM_PMU_MVE_FP_MAC_SPEC 0x0215 /*!< MVE floating-point multiply or multiply-accumulate instruction speculatively executed */ +#define ARM_PMU_MVE_INT_RETIRED 0x0224 /*!< MVE integer instruction architecturally executed */ +#define ARM_PMU_MVE_INT_SPEC 0x0225 /*!< MVE integer instruction speculatively executed */ +#define ARM_PMU_MVE_INT_MAC_RETIRED 0x0228 /*!< MVE multiply or multiply-accumulate instruction architecturally executed */ +#define ARM_PMU_MVE_INT_MAC_SPEC 0x0229 /*!< MVE multiply or multiply-accumulate instruction speculatively executed */ +#define ARM_PMU_MVE_LDST_RETIRED 0x0238 /*!< MVE load or store instruction architecturally executed */ +#define ARM_PMU_MVE_LDST_SPEC 0x0239 /*!< MVE load or store instruction speculatively executed */ +#define ARM_PMU_MVE_LD_RETIRED 0x023C /*!< MVE load instruction architecturally executed */ +#define ARM_PMU_MVE_LD_SPEC 0x023D /*!< MVE load instruction speculatively executed */ +#define ARM_PMU_MVE_ST_RETIRED 0x0240 /*!< MVE store instruction architecturally executed */ +#define ARM_PMU_MVE_ST_SPEC 0x0241 /*!< MVE store instruction speculatively executed */ +#define ARM_PMU_MVE_LDST_CONTIG_RETIRED 0x0244 /*!< MVE contiguous load or store instruction architecturally executed */ +#define ARM_PMU_MVE_LDST_CONTIG_SPEC 0x0245 /*!< MVE contiguous load or store instruction speculatively executed */ +#define ARM_PMU_MVE_LD_CONTIG_RETIRED 0x0248 /*!< MVE contiguous load instruction architecturally executed */ +#define ARM_PMU_MVE_LD_CONTIG_SPEC 0x0249 /*!< MVE contiguous load instruction speculatively executed */ +#define ARM_PMU_MVE_ST_CONTIG_RETIRED 0x024C /*!< MVE contiguous store instruction architecturally executed */ +#define ARM_PMU_MVE_ST_CONTIG_SPEC 0x024D /*!< MVE contiguous store instruction speculatively executed */ +#define ARM_PMU_MVE_LDST_NONCONTIG_RETIRED 0x0250 /*!< MVE non-contiguous load or store instruction architecturally executed */ +#define ARM_PMU_MVE_LDST_NONCONTIG_SPEC 0x0251 /*!< MVE non-contiguous load or store instruction speculatively executed */ +#define ARM_PMU_MVE_LD_NONCONTIG_RETIRED 0x0254 /*!< MVE non-contiguous load instruction architecturally executed */ +#define ARM_PMU_MVE_LD_NONCONTIG_SPEC 0x0255 /*!< MVE non-contiguous load instruction speculatively executed */ +#define ARM_PMU_MVE_ST_NONCONTIG_RETIRED 0x0258 /*!< MVE non-contiguous store instruction architecturally executed */ +#define ARM_PMU_MVE_ST_NONCONTIG_SPEC 0x0259 /*!< MVE non-contiguous store instruction speculatively executed */ +#define ARM_PMU_MVE_LDST_MULTI_RETIRED 0x025C /*!< MVE memory instruction targeting multiple registers architecturally executed */ +#define ARM_PMU_MVE_LDST_MULTI_SPEC 0x025D /*!< MVE memory instruction targeting multiple registers speculatively executed */ +#define ARM_PMU_MVE_LD_MULTI_RETIRED 0x0260 /*!< MVE memory load instruction targeting multiple registers architecturally executed */ +#define ARM_PMU_MVE_LD_MULTI_SPEC 0x0261 /*!< MVE memory load instruction targeting multiple registers speculatively executed */ +#define ARM_PMU_MVE_ST_MULTI_RETIRED 0x0261 /*!< MVE memory store instruction targeting multiple registers architecturally executed */ +#define ARM_PMU_MVE_ST_MULTI_SPEC 0x0265 /*!< MVE memory store instruction targeting multiple registers speculatively executed */ +#define ARM_PMU_MVE_LDST_UNALIGNED_RETIRED 0x028C /*!< MVE unaligned memory load or store instruction architecturally executed */ +#define ARM_PMU_MVE_LDST_UNALIGNED_SPEC 0x028D /*!< MVE unaligned memory load or store instruction speculatively executed */ +#define ARM_PMU_MVE_LD_UNALIGNED_RETIRED 0x0290 /*!< MVE unaligned load instruction architecturally executed */ +#define ARM_PMU_MVE_LD_UNALIGNED_SPEC 0x0291 /*!< MVE unaligned load instruction speculatively executed */ +#define ARM_PMU_MVE_ST_UNALIGNED_RETIRED 0x0294 /*!< MVE unaligned store instruction architecturally executed */ +#define ARM_PMU_MVE_ST_UNALIGNED_SPEC 0x0295 /*!< MVE unaligned store instruction speculatively executed */ +#define ARM_PMU_MVE_LDST_UNALIGNED_NONCONTIG_RETIRED 0x0298 /*!< MVE unaligned noncontiguous load or store instruction architecturally executed */ +#define ARM_PMU_MVE_LDST_UNALIGNED_NONCONTIG_SPEC 0x0299 /*!< MVE unaligned noncontiguous load or store instruction speculatively executed */ +#define ARM_PMU_MVE_VREDUCE_RETIRED 0x02A0 /*!< MVE vector reduction instruction architecturally executed */ +#define ARM_PMU_MVE_VREDUCE_SPEC 0x02A1 /*!< MVE vector reduction instruction speculatively executed */ +#define ARM_PMU_MVE_VREDUCE_FP_RETIRED 0x02A4 /*!< MVE floating-point vector reduction instruction architecturally executed */ +#define ARM_PMU_MVE_VREDUCE_FP_SPEC 0x02A5 /*!< MVE floating-point vector reduction instruction speculatively executed */ +#define ARM_PMU_MVE_VREDUCE_INT_RETIRED 0x02A8 /*!< MVE integer vector reduction instruction architecturally executed */ +#define ARM_PMU_MVE_VREDUCE_INT_SPEC 0x02A9 /*!< MVE integer vector reduction instruction speculatively executed */ +#define ARM_PMU_MVE_PRED 0x02B8 /*!< Cycles where one or more predicated beats architecturally executed */ +#define ARM_PMU_MVE_STALL 0x02CC /*!< Stall cycles caused by an MVE instruction */ +#define ARM_PMU_MVE_STALL_RESOURCE 0x02CD /*!< Stall cycles caused by an MVE instruction because of resource conflicts */ +#define ARM_PMU_MVE_STALL_RESOURCE_MEM 0x02CE /*!< Stall cycles caused by an MVE instruction because of memory resource conflicts */ +#define ARM_PMU_MVE_STALL_RESOURCE_FP 0x02CF /*!< Stall cycles caused by an MVE instruction because of floating-point resource conflicts */ +#define ARM_PMU_MVE_STALL_RESOURCE_INT 0x02D0 /*!< Stall cycles caused by an MVE instruction because of integer resource conflicts */ +#define ARM_PMU_MVE_STALL_BREAK 0x02D3 /*!< Stall cycles caused by an MVE chain break */ +#define ARM_PMU_MVE_STALL_DEPENDENCY 0x02D4 /*!< Stall cycles caused by MVE register dependency */ +#define ARM_PMU_ITCM_ACCESS 0x4007 /*!< Instruction TCM access */ +#define ARM_PMU_DTCM_ACCESS 0x4008 /*!< Data TCM access */ +#define ARM_PMU_TRCEXTOUT0 0x4010 /*!< ETM external output 0 */ +#define ARM_PMU_TRCEXTOUT1 0x4011 /*!< ETM external output 1 */ +#define ARM_PMU_TRCEXTOUT2 0x4012 /*!< ETM external output 2 */ +#define ARM_PMU_TRCEXTOUT3 0x4013 /*!< ETM external output 3 */ +#define ARM_PMU_CTI_TRIGOUT4 0x4018 /*!< Cross-trigger Interface output trigger 4 */ +#define ARM_PMU_CTI_TRIGOUT5 0x4019 /*!< Cross-trigger Interface output trigger 5 */ +#define ARM_PMU_CTI_TRIGOUT6 0x401A /*!< Cross-trigger Interface output trigger 6 */ +#define ARM_PMU_CTI_TRIGOUT7 0x401B /*!< Cross-trigger Interface output trigger 7 */ + +/** \brief PMU Functions */ + +__STATIC_INLINE void ARM_PMU_Enable(void); +__STATIC_INLINE void ARM_PMU_Disable(void); + +__STATIC_INLINE void ARM_PMU_Set_EVTYPER(uint32_t num, uint32_t type); + +__STATIC_INLINE void ARM_PMU_CYCCNT_Reset(void); +__STATIC_INLINE void ARM_PMU_EVCNTR_ALL_Reset(void); + +__STATIC_INLINE void ARM_PMU_CNTR_Enable(uint32_t mask); +__STATIC_INLINE void ARM_PMU_CNTR_Disable(uint32_t mask); + +__STATIC_INLINE uint32_t ARM_PMU_Get_CCNTR(void); +__STATIC_INLINE uint32_t ARM_PMU_Get_EVCNTR(uint32_t num); + +__STATIC_INLINE uint32_t ARM_PMU_Get_CNTR_OVS(void); +__STATIC_INLINE void ARM_PMU_Set_CNTR_OVS(uint32_t mask); + +__STATIC_INLINE void ARM_PMU_Set_CNTR_IRQ_Enable(uint32_t mask); +__STATIC_INLINE void ARM_PMU_Set_CNTR_IRQ_Disable(uint32_t mask); + +__STATIC_INLINE void ARM_PMU_CNTR_Increment(uint32_t mask); + +/** + \brief Enable the PMU +*/ +__STATIC_INLINE void ARM_PMU_Enable(void) +{ + PMU->CTRL |= PMU_CTRL_ENABLE_Msk; +} + +/** + \brief Disable the PMU +*/ +__STATIC_INLINE void ARM_PMU_Disable(void) +{ + PMU->CTRL &= ~PMU_CTRL_ENABLE_Msk; +} + +/** + \brief Set event to count for PMU eventer counter + \param [in] num Event counter (0-30) to configure + \param [in] type Event to count +*/ +__STATIC_INLINE void ARM_PMU_Set_EVTYPER(uint32_t num, uint32_t type) +{ + PMU->EVTYPER[num] = type; +} + +/** + \brief Reset cycle counter +*/ +__STATIC_INLINE void ARM_PMU_CYCCNT_Reset(void) +{ + PMU->CTRL |= PMU_CTRL_CYCCNT_RESET_Msk; +} + +/** + \brief Reset all event counters +*/ +__STATIC_INLINE void ARM_PMU_EVCNTR_ALL_Reset(void) +{ + PMU->CTRL |= PMU_CTRL_EVENTCNT_RESET_Msk; +} + +/** + \brief Enable counters + \param [in] mask Counters to enable + \note Enables one or more of the following: + - event counters (0-30) + - cycle counter +*/ +__STATIC_INLINE void ARM_PMU_CNTR_Enable(uint32_t mask) +{ + PMU->CNTENSET = mask; +} + +/** + \brief Disable counters + \param [in] mask Counters to enable + \note Disables one or more of the following: + - event counters (0-30) + - cycle counter +*/ +__STATIC_INLINE void ARM_PMU_CNTR_Disable(uint32_t mask) +{ + PMU->CNTENCLR = mask; +} + +/** + \brief Read cycle counter + \return Cycle count +*/ +__STATIC_INLINE uint32_t ARM_PMU_Get_CCNTR(void) +{ + return PMU->CCNTR; +} + +/** + \brief Read event counter + \param [in] num Event counter (0-30) to read + \return Event count +*/ +__STATIC_INLINE uint32_t ARM_PMU_Get_EVCNTR(uint32_t num) +{ + return PMU_EVCNTR_CNT_Msk & PMU->EVCNTR[num]; +} + +/** + \brief Read counter overflow status + \return Counter overflow status bits for the following: + - event counters (0-30) + - cycle counter +*/ +__STATIC_INLINE uint32_t ARM_PMU_Get_CNTR_OVS(void) +{ + return PMU->OVSSET; +} + +/** + \brief Clear counter overflow status + \param [in] mask Counter overflow status bits to clear + \note Clears overflow status bits for one or more of the following: + - event counters (0-30) + - cycle counter +*/ +__STATIC_INLINE void ARM_PMU_Set_CNTR_OVS(uint32_t mask) +{ + PMU->OVSCLR = mask; +} + +/** + \brief Enable counter overflow interrupt request + \param [in] mask Counter overflow interrupt request bits to set + \note Sets overflow interrupt request bits for one or more of the following: + - event counters (0-30) + - cycle counter +*/ +__STATIC_INLINE void ARM_PMU_Set_CNTR_IRQ_Enable(uint32_t mask) +{ + PMU->INTENSET = mask; +} + +/** + \brief Disable counter overflow interrupt request + \param [in] mask Counter overflow interrupt request bits to clear + \note Clears overflow interrupt request bits for one or more of the following: + - event counters (0-30) + - cycle counter +*/ +__STATIC_INLINE void ARM_PMU_Set_CNTR_IRQ_Disable(uint32_t mask) +{ + PMU->INTENCLR = mask; +} + +/** + \brief Software increment event counter + \param [in] mask Counters to increment + \note Software increment bits for one or more event counters (0-30) +*/ +__STATIC_INLINE void ARM_PMU_CNTR_Increment(uint32_t mask) +{ + PMU->SWINC = mask; +} + +#endif From beb44597841805a85d31326b375669b6a1251c02 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Fri, 19 Jan 2024 10:49:58 +0200 Subject: [PATCH 057/408] mimxrt/boards: Fix __VECTOR_TABLE link issue with CMSIS 5.9.0. In CMSIS 5.9.0, the compiler headers define `__VECTOR_TABLE`, which will be substituted with its corresponding value (e.g., `__Vectors` for gcc). However, the linker script in this port can't include compiler headers when it's processed, so `__VECTOR_TABLE` is used as the literal variable name, which results in an undefined linker error. To fix this, the two possible values of `__VECTOR_TABLE` are both defined in the linker script. Signed-off-by: iabdalkader --- ports/mimxrt/boards/common.ld | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ports/mimxrt/boards/common.ld b/ports/mimxrt/boards/common.ld index c2aa369f66b3a..6c78fea319f96 100644 --- a/ports/mimxrt/boards/common.ld +++ b/ports/mimxrt/boards/common.ld @@ -83,13 +83,14 @@ SECTIONS /* The startup code goes first into internal RAM */ .interrupts : { - __VECTOR_TABLE = .; + __Vectors = .; + __vector_table = .; . = ALIGN(4); KEEP(*(.isr_vector)) /* Startup code */ . = ALIGN(4); } > m_interrupts - __VECTOR_RAM = __VECTOR_TABLE; + __VECTOR_RAM = __Vectors; __RAM_VECTOR_TABLE_SIZE_BYTES = 0x0; /* The program code and other data goes into internal RAM */ From e111793d8d6a0b921f47c7396b70a0aca1edaea5 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Fri, 19 Jan 2024 11:12:13 +0200 Subject: [PATCH 058/408] nrf: Fix _start() build issue with CMSIS 5.9.0. The `_start` function prototype is now declared as no-return, so `main()` can't return. To fix this, `main()` is replaced with `_start`. Signed-off-by: iabdalkader --- ports/nrf/drivers/secureboot/secureboot_main.c | 7 +------ ports/nrf/main.c | 8 +------- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/ports/nrf/drivers/secureboot/secureboot_main.c b/ports/nrf/drivers/secureboot/secureboot_main.c index 748e080a24fe2..8362852cd7983 100644 --- a/ports/nrf/drivers/secureboot/secureboot_main.c +++ b/ports/nrf/drivers/secureboot/secureboot_main.c @@ -176,7 +176,7 @@ static void jump_to_non_secure(void) } } -int main(void) { +void _start(void) { configure_flash(); configure_ram(); configure_peripherals(); @@ -186,9 +186,4 @@ int main(void) { while (1) { ; } - - return 0; } - -void _start(void) {main();} - diff --git a/ports/nrf/main.c b/ports/nrf/main.c index 0e5a26c487e43..9809ba0e23fc0 100644 --- a/ports/nrf/main.c +++ b/ports/nrf/main.c @@ -107,7 +107,7 @@ void do_str(const char *src, mp_parse_input_kind_t input_kind) { extern uint32_t _heap_start; extern uint32_t _heap_end; -int main(int argc, char **argv) { +void NORETURN _start(void) { // Hook for a board to run code at start up, for example check if a // bootloader should be entered instead of the main application. MICROPY_BOARD_STARTUP(); @@ -299,8 +299,6 @@ int main(int argc, char **argv) { #endif goto soft_reset; - - return 0; } #if !MICROPY_VFS @@ -369,7 +367,3 @@ void MP_WEAK __assert_func(const char *file, int line, const char *func, const c printf("Assertion '%s' failed, at file %s:%d\n", expr, file, line); __fatal_error("Assertion failed"); } - -void _start(void) { - main(0, NULL); -} From c3ca3612d1ef5e490045c3d4038b1362993c0f26 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 23 Jan 2024 11:11:25 +1100 Subject: [PATCH 059/408] tests/extmod/asyncio_wait_task.py: Add test for raise and delayed wait. This case was fixed in 2ecbad4e91192c88f831d8690dbad31ddba72135, which stored the exception in the task object. Signed-off-by: Damien George --- tests/extmod/asyncio_wait_task.py | 11 +++++++++++ tests/extmod/asyncio_wait_task.py.exp | 2 ++ 2 files changed, 13 insertions(+) diff --git a/tests/extmod/asyncio_wait_task.py b/tests/extmod/asyncio_wait_task.py index bce426d971046..7d79104f8cf8f 100644 --- a/tests/extmod/asyncio_wait_task.py +++ b/tests/extmod/asyncio_wait_task.py @@ -68,5 +68,16 @@ async def main(): except ValueError: print("ValueError") + # Wait on a task that raises, but the waiting is done some time later. + # Need to suppress the "Task exception wasn't retrieved" message. + asyncio.get_event_loop().set_exception_handler(lambda loop, context: None) + t = asyncio.create_task(task_raise()) + for _ in range(5): + await asyncio.sleep(0) + try: + await t + except ValueError: + print("ValueError") + asyncio.run(main()) diff --git a/tests/extmod/asyncio_wait_task.py.exp b/tests/extmod/asyncio_wait_task.py.exp index 04be37f48406d..514a434223315 100644 --- a/tests/extmod/asyncio_wait_task.py.exp +++ b/tests/extmod/asyncio_wait_task.py.exp @@ -8,3 +8,5 @@ world took 200 200 task_raise ValueError +task_raise +ValueError From 057701a7708ca6ca96aaf3784c0ef72d22424df8 Mon Sep 17 00:00:00 2001 From: Maarten van der Schrieck Date: Thu, 22 Jun 2023 15:52:10 +0200 Subject: [PATCH 060/408] rp2/machine_uart: Fix potential race condition in interrupt handling. The irq service routine cleared the RT interrupt bit on TX interrupt. This opens the possibility that an RT interrupt is missed. Signed-off-by: Maarten van der Schrieck --- ports/rp2/machine_uart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/rp2/machine_uart.c b/ports/rp2/machine_uart.c index bca07cebfcbf3..72e68a6fb6b61 100644 --- a/ports/rp2/machine_uart.c +++ b/ports/rp2/machine_uart.c @@ -194,7 +194,7 @@ STATIC inline void uart_service_interrupt(machine_uart_obj_t *self) { } if (uart_get_hw(self->uart)->mis & UART_UARTMIS_TXMIS_BITS) { // tx interrupt? // clear all interrupt bits but rx - uart_get_hw(self->uart)->icr = UART_UARTICR_BITS & (~UART_UARTICR_RXIC_BITS); + uart_get_hw(self->uart)->icr = UART_UARTICR_BITS & ~(UART_UARTICR_RXIC_BITS | UART_UARTICR_RTIC_BITS); uart_fill_tx_fifo(self); } } From ce2058685b9ca2278849b3117c2461f6b6fc727f Mon Sep 17 00:00:00 2001 From: Iksas Date: Fri, 12 May 2023 19:08:26 +0200 Subject: [PATCH 061/408] ports: Fix handling of paths containing spaces in Makefiles. Make can't handle paths with spaces, see https://savannah.gnu.org/bugs/?712 The following workarounds exist: - When using make's built-in functions: - Use relative paths wherever possible to avoid spaces in the first place. - All spaces in paths can be escaped with backslashes; quotes don't work. - Some users use the shell to temporarily rename directories, or to create symlinks without spaces. - When using make to pass commands to the system's shell, enclose paths in quotes. While make will still interpret quoted strings with spaces as multiple words, the system's shell will correctly parse the resulting command. This commit contains the following fixes: - In ports/stm32/mboot/Makefile: Use relative paths to avoid spaces when using built-in functions. - In all other files: Use quotes to enclose paths when make is used to call shell functions. All changes have been tested with a directory containing spaces. Signed-off-by: Iksas --- ports/esp32/Makefile | 2 +- ports/mimxrt/Makefile | 2 +- ports/rp2/Makefile | 2 +- ports/stm32/mboot/Makefile | 2 +- py/mkrules.mk | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ports/esp32/Makefile b/ports/esp32/Makefile index ce574ce799ad7..3df2af4716fd9 100644 --- a/ports/esp32/Makefile +++ b/ports/esp32/Makefile @@ -42,7 +42,7 @@ ifdef USER_C_MODULES CMAKE_ARGS += -DUSER_C_MODULES=${USER_C_MODULES} endif -IDFPY_FLAGS += -D MICROPY_BOARD=$(BOARD) -D MICROPY_BOARD_DIR=$(abspath $(BOARD_DIR)) $(CMAKE_ARGS) +IDFPY_FLAGS += -D MICROPY_BOARD=$(BOARD) -D MICROPY_BOARD_DIR="$(abspath $(BOARD_DIR))" $(CMAKE_ARGS) ifdef FROZEN_MANIFEST IDFPY_FLAGS += -D MICROPY_FROZEN_MANIFEST=$(FROZEN_MANIFEST) diff --git a/ports/mimxrt/Makefile b/ports/mimxrt/Makefile index f514b773fd495..dd1f5aa7c6ca5 100644 --- a/ports/mimxrt/Makefile +++ b/ports/mimxrt/Makefile @@ -491,7 +491,7 @@ $(GEN_FLEXRAM_CONFIG_SRC): $(BUILD)/%_gen.c $(HEADER_BUILD)/%.h: $(BOARD_PINS) $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD) $(ECHO) "Create $@" $(Q)$(PYTHON) $(MAKE_PINS) --board-csv $(BOARD_PINS) --af-csv $(AF_FILE) \ - --prefix $(PREFIX_FILE) --iomux $(abspath $(TOP)/$(MCU_DIR)/drivers/fsl_iomuxc.h) \ + --prefix $(PREFIX_FILE) --iomux "$(abspath $(TOP)/$(MCU_DIR)/drivers/fsl_iomuxc.h)" \ --output-source $(GEN_PINS_SRC) --output-header $(GEN_PINS_HDR) include $(TOP)/py/mkrules.mk diff --git a/ports/rp2/Makefile b/ports/rp2/Makefile index 11d2115a2fd21..b6e8852169217 100644 --- a/ports/rp2/Makefile +++ b/ports/rp2/Makefile @@ -30,7 +30,7 @@ endif $(VERBOSE)MAKESILENT = -s -CMAKE_ARGS = -DMICROPY_BOARD=$(BOARD) -DMICROPY_BOARD_DIR=$(abspath $(BOARD_DIR)) +CMAKE_ARGS = -DMICROPY_BOARD=$(BOARD) -DMICROPY_BOARD_DIR="$(abspath $(BOARD_DIR))" ifdef USER_C_MODULES CMAKE_ARGS += -DUSER_C_MODULES=${USER_C_MODULES} diff --git a/ports/stm32/mboot/Makefile b/ports/stm32/mboot/Makefile index 389f9f5d0f4ad..9908194237efd 100755 --- a/ports/stm32/mboot/Makefile +++ b/ports/stm32/mboot/Makefile @@ -6,7 +6,7 @@ BOARD ?= $(notdir $(BOARD_DIR:/=)) else # If not given on the command line, then default to PYBV10. BOARD ?= PYBV10 -BOARD_DIR ?= $(abspath ../boards/$(BOARD)) +BOARD_DIR ?= ../boards/$(BOARD) endif # If the build directory is not given, make it reflect the board name. diff --git a/py/mkrules.mk b/py/mkrules.mk index 30483feb5c47e..5050935873aff 100644 --- a/py/mkrules.mk +++ b/py/mkrules.mk @@ -176,7 +176,7 @@ $(HEADER_BUILD): ifneq ($(MICROPY_MPYCROSS_DEPENDENCY),) # to automatically build mpy-cross, if needed $(MICROPY_MPYCROSS_DEPENDENCY): - $(MAKE) -C $(abspath $(dir $@)..) + $(MAKE) -C "$(abspath $(dir $@)..)" endif ifneq ($(FROZEN_DIR),) From 8eb658f654de345c935886b47e2e31b1dafeb862 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 23 Jan 2024 17:18:27 +1100 Subject: [PATCH 062/408] github/workflows: Run mimxrt and rp2 CI with space in repository path. To test building with make and cmake when there is a space in the path. Signed-off-by: Damien George --- .github/workflows/ports_mimxrt.yml | 5 +++++ .github/workflows/ports_rp2.yml | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/.github/workflows/ports_mimxrt.yml b/.github/workflows/ports_mimxrt.yml index 614d7458079e8..9e782bf63b31c 100644 --- a/.github/workflows/ports_mimxrt.yml +++ b/.github/workflows/ports_mimxrt.yml @@ -20,8 +20,13 @@ concurrency: jobs: build: runs-on: ubuntu-20.04 + defaults: + run: + working-directory: 'micropython repo' # test build with space in path steps: - uses: actions/checkout@v4 + with: + path: 'micropython repo' - name: Install packages run: source tools/ci.sh && ci_mimxrt_setup - name: Build diff --git a/.github/workflows/ports_rp2.yml b/.github/workflows/ports_rp2.yml index 5741b75d2aa79..748f38e143893 100644 --- a/.github/workflows/ports_rp2.yml +++ b/.github/workflows/ports_rp2.yml @@ -20,8 +20,13 @@ concurrency: jobs: build: runs-on: ubuntu-latest + defaults: + run: + working-directory: 'micropython repo' # test build with space in path steps: - uses: actions/checkout@v4 + with: + path: 'micropython repo' - name: Install packages run: source tools/ci.sh && ci_rp2_setup - name: Build From 6bb446b7ff62af6d3b6b10f2da0f6d107f97e00e Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 23 Jan 2024 11:11:25 +1100 Subject: [PATCH 063/408] tests/extmod: Remove asyncio .exp files that match CPython output. These were added back in commit c4935f30490d0446e16a51dbf7a6397b771cf804 because the tests required CPython 3.8, which was quite new at the time. But CPython 3.8 was released over 4 years ago (October 2019) and the CI test runners, and developers, have this (or a more recent) CPython version. Removing the .exp files also helps keep MicroPython semantics the same as CPython. The asyncio_fair.py test it adjusted slightly to have more deterministic timing and output. Signed-off-by: Damien George --- tests/extmod/asyncio_await_return.py.exp | 2 -- tests/extmod/asyncio_basic2.py.exp | 4 --- tests/extmod/asyncio_cancel_fair.py.exp | 24 -------------- tests/extmod/asyncio_cancel_fair2.py.exp | 8 ----- tests/extmod/asyncio_cancel_task.py.exp | 31 ----------------- .../asyncio_cancel_wait_on_finished.py.exp | 7 ---- tests/extmod/asyncio_current_task.py.exp | 1 - tests/extmod/asyncio_event.py.exp | 33 ------------------- tests/extmod/asyncio_event_fair.py.exp | 16 --------- tests/extmod/asyncio_exception.py.exp | 7 ---- tests/extmod/asyncio_fair.py | 2 +- tests/extmod/asyncio_fair.py.exp | 13 -------- tests/extmod/asyncio_lock.py | 4 +++ tests/extmod/asyncio_lock_cancel.py.exp | 11 ------- tests/extmod/asyncio_loop_stop.py.exp | 7 ---- tests/extmod/asyncio_new_event_loop.py.exp | 6 ---- .../asyncio_set_exception_handler.py.exp | 9 ----- tests/extmod/asyncio_task_done.py.exp | 24 -------------- 18 files changed, 5 insertions(+), 204 deletions(-) delete mode 100644 tests/extmod/asyncio_await_return.py.exp delete mode 100644 tests/extmod/asyncio_basic2.py.exp delete mode 100644 tests/extmod/asyncio_cancel_fair.py.exp delete mode 100644 tests/extmod/asyncio_cancel_fair2.py.exp delete mode 100644 tests/extmod/asyncio_cancel_task.py.exp delete mode 100644 tests/extmod/asyncio_cancel_wait_on_finished.py.exp delete mode 100644 tests/extmod/asyncio_current_task.py.exp delete mode 100644 tests/extmod/asyncio_event.py.exp delete mode 100644 tests/extmod/asyncio_event_fair.py.exp delete mode 100644 tests/extmod/asyncio_exception.py.exp delete mode 100644 tests/extmod/asyncio_fair.py.exp delete mode 100644 tests/extmod/asyncio_lock_cancel.py.exp delete mode 100644 tests/extmod/asyncio_loop_stop.py.exp delete mode 100644 tests/extmod/asyncio_new_event_loop.py.exp delete mode 100644 tests/extmod/asyncio_set_exception_handler.py.exp delete mode 100644 tests/extmod/asyncio_task_done.py.exp diff --git a/tests/extmod/asyncio_await_return.py.exp b/tests/extmod/asyncio_await_return.py.exp deleted file mode 100644 index daaac9e303029..0000000000000 --- a/tests/extmod/asyncio_await_return.py.exp +++ /dev/null @@ -1,2 +0,0 @@ -42 -42 diff --git a/tests/extmod/asyncio_basic2.py.exp b/tests/extmod/asyncio_basic2.py.exp deleted file mode 100644 index 3ca3521728d44..0000000000000 --- a/tests/extmod/asyncio_basic2.py.exp +++ /dev/null @@ -1,4 +0,0 @@ -main start -forever start -main done -42 diff --git a/tests/extmod/asyncio_cancel_fair.py.exp b/tests/extmod/asyncio_cancel_fair.py.exp deleted file mode 100644 index 8f5da08e4ced4..0000000000000 --- a/tests/extmod/asyncio_cancel_fair.py.exp +++ /dev/null @@ -1,24 +0,0 @@ -start 0 -start 1 -start 2 -done 0 -0 cancels 1 -start 0 -cancelled 1 -1 cancels 0 -start 1 -done 2 -start 2 -cancelled 0 -0 cancels 1 -start 0 -cancelled 1 -1 cancels 0 -start 1 -done 2 -start 2 -cancelled 0 -0 cancels 1 -cancelled 1 -1 cancels 0 -done 2 diff --git a/tests/extmod/asyncio_cancel_fair2.py.exp b/tests/extmod/asyncio_cancel_fair2.py.exp deleted file mode 100644 index e9dd649b453f9..0000000000000 --- a/tests/extmod/asyncio_cancel_fair2.py.exp +++ /dev/null @@ -1,8 +0,0 @@ -sleep a -sleep b 0 -sleep b 1 -sleep b 2 -cancelled a -done b 0 -done b 1 -done b 2 diff --git a/tests/extmod/asyncio_cancel_task.py.exp b/tests/extmod/asyncio_cancel_task.py.exp deleted file mode 100644 index 031b94023fd03..0000000000000 --- a/tests/extmod/asyncio_cancel_task.py.exp +++ /dev/null @@ -1,31 +0,0 @@ -True -task start -True -main sleep -task cancel -task start -True -True -True -True -main sleep -task cancel -main wait -main got CancelledError -task start -task done -False ----- -task 2 -task start -main cancel -main sleep -task cancel -task 2 cancel ----- -task 2 -task start -main cancel -main sleep -task cancel -task 2 done diff --git a/tests/extmod/asyncio_cancel_wait_on_finished.py.exp b/tests/extmod/asyncio_cancel_wait_on_finished.py.exp deleted file mode 100644 index 60e871bfe56f0..0000000000000 --- a/tests/extmod/asyncio_cancel_wait_on_finished.py.exp +++ /dev/null @@ -1,7 +0,0 @@ -main sleep -sleep_task sleep -wait_task wait -main sleep -sleep_task wake -main wait -CancelledError() diff --git a/tests/extmod/asyncio_current_task.py.exp b/tests/extmod/asyncio_current_task.py.exp deleted file mode 100644 index 0ca95142bb715..0000000000000 --- a/tests/extmod/asyncio_current_task.py.exp +++ /dev/null @@ -1 +0,0 @@ -True diff --git a/tests/extmod/asyncio_event.py.exp b/tests/extmod/asyncio_event.py.exp deleted file mode 100644 index 3188f291e584d..0000000000000 --- a/tests/extmod/asyncio_event.py.exp +++ /dev/null @@ -1,33 +0,0 @@ -False -True -False ----- -yield -start 1 -start 2 -set event -yield -True -end 1 -True -end 2 ----- -yield -start 3 -True -end 3 ----- -clear event -start 4 -set event -True -end 4 ----- -start 5 ----- -start 6 ----- -set event ----- -TimeoutError -set event diff --git a/tests/extmod/asyncio_event_fair.py.exp b/tests/extmod/asyncio_event_fair.py.exp deleted file mode 100644 index fe2e3d6e47a63..0000000000000 --- a/tests/extmod/asyncio_event_fair.py.exp +++ /dev/null @@ -1,16 +0,0 @@ -sleep 0 -wait 2 -sleep 1 -wait 3 -sleep 0 -sleep 1 -wait 2 -sleep 0 -sleep 1 -wait 3 -sleep 0 -sleep 1 -wait 2 -wait 3 -wait 2 -wait 3 diff --git a/tests/extmod/asyncio_exception.py.exp b/tests/extmod/asyncio_exception.py.exp deleted file mode 100644 index b2ee860170ece..0000000000000 --- a/tests/extmod/asyncio_exception.py.exp +++ /dev/null @@ -1,7 +0,0 @@ -main start -ValueError 1 -main start -task start -ValueError 2 -main start -ValueError 3 diff --git a/tests/extmod/asyncio_fair.py b/tests/extmod/asyncio_fair.py index 43076fef1d707..3e3ac04735898 100644 --- a/tests/extmod/asyncio_fair.py +++ b/tests/extmod/asyncio_fair.py @@ -20,7 +20,7 @@ async def main(): t2 = asyncio.create_task(task(2, 0.1)) t3 = asyncio.create_task(task(3, 0.18)) t4 = asyncio.create_task(task(4, -100)) - await asyncio.sleep(0.5) + await asyncio.sleep(0.45) # t2 prints 5 times, t3 prints 3 times t1.cancel() t2.cancel() t3.cancel() diff --git a/tests/extmod/asyncio_fair.py.exp b/tests/extmod/asyncio_fair.py.exp deleted file mode 100644 index b4b6481db019f..0000000000000 --- a/tests/extmod/asyncio_fair.py.exp +++ /dev/null @@ -1,13 +0,0 @@ -task start 1 -task start 2 -task work 2 -task start 3 -task work 3 -task start 4 -task work 2 -task work 3 -task work 2 -task work 2 -task work 3 -task work 2 -finish diff --git a/tests/extmod/asyncio_lock.py b/tests/extmod/asyncio_lock.py index f565adb03fc39..10d3285be0f86 100644 --- a/tests/extmod/asyncio_lock.py +++ b/tests/extmod/asyncio_lock.py @@ -1,4 +1,8 @@ # Test Lock class +# +# This test has a corresponding .exp file because it tests a very specific ordering of +# events when cancelling a task waiting on a lock, and that ordering should not change +# (even though it does match CPython's output). try: import asyncio diff --git a/tests/extmod/asyncio_lock_cancel.py.exp b/tests/extmod/asyncio_lock_cancel.py.exp deleted file mode 100644 index 49ae253887436..0000000000000 --- a/tests/extmod/asyncio_lock_cancel.py.exp +++ /dev/null @@ -1,11 +0,0 @@ -task 0 start -task 1 start -task 2 start -task 3 start -task 1 cancel -task 2 cancel -task 0 lock_flag False -task 0 done -task 3 lock_flag False -task 3 done -False diff --git a/tests/extmod/asyncio_loop_stop.py.exp b/tests/extmod/asyncio_loop_stop.py.exp deleted file mode 100644 index bada5f0d8412c..0000000000000 --- a/tests/extmod/asyncio_loop_stop.py.exp +++ /dev/null @@ -1,7 +0,0 @@ -run 0 -start -sleep -run 1 -run 2 -task -end diff --git a/tests/extmod/asyncio_new_event_loop.py.exp b/tests/extmod/asyncio_new_event_loop.py.exp deleted file mode 100644 index 9e104fda39c94..0000000000000 --- a/tests/extmod/asyncio_new_event_loop.py.exp +++ /dev/null @@ -1,6 +0,0 @@ -start -task 0 -stop -start -task 0 -stop diff --git a/tests/extmod/asyncio_set_exception_handler.py.exp b/tests/extmod/asyncio_set_exception_handler.py.exp deleted file mode 100644 index fb4711469dc5b..0000000000000 --- a/tests/extmod/asyncio_set_exception_handler.py.exp +++ /dev/null @@ -1,9 +0,0 @@ -None -True -sleep -custom_handler ValueError(0, 1) -sleep -custom_handler ValueError(1, 2) -custom_handler ValueError(2, 3) -ValueError(3, 4) -done diff --git a/tests/extmod/asyncio_task_done.py.exp b/tests/extmod/asyncio_task_done.py.exp deleted file mode 100644 index ddda04c5ec43b..0000000000000 --- a/tests/extmod/asyncio_task_done.py.exp +++ /dev/null @@ -1,24 +0,0 @@ -========== -False -task start -task done -True -True -========== -False -task start -False -task done -True -========== -False -task start -True -ValueError() -True -========== -False -task start -False -ValueError() -True From 982ffdee7e5a5054d81fdef713da31615a3cf80d Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 25 Jan 2024 11:30:14 +1100 Subject: [PATCH 064/408] stm32/mboot/Makefile: Revert change to BOARD_DIR that removed abspath. This reverts the change from ce2058685b9ca2278849b3117c2461f6b6fc727f. Without abspath, the build artefacts (object files) for boards with source files are placed outside the build directory, because the BOARD_DIR variable starts with "..". For the list of source files added to SRC_C, none of them can start with "..". The usual fix for that would be to make the files relative to the top of the MicroPython repo (because of the vpath rule), eg ports/stm32/boards/$(BOARD). But then the $(wildcard ...) pattern won't find files in this directory. So abspath is necessary, although it will prevent building when there is a space in the path. A better solution for spaces needs to be found. Signed-off-by: Damien George --- ports/stm32/mboot/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/stm32/mboot/Makefile b/ports/stm32/mboot/Makefile index 9908194237efd..389f9f5d0f4ad 100755 --- a/ports/stm32/mboot/Makefile +++ b/ports/stm32/mboot/Makefile @@ -6,7 +6,7 @@ BOARD ?= $(notdir $(BOARD_DIR:/=)) else # If not given on the command line, then default to PYBV10. BOARD ?= PYBV10 -BOARD_DIR ?= ../boards/$(BOARD) +BOARD_DIR ?= $(abspath ../boards/$(BOARD)) endif # If the build directory is not given, make it reflect the board name. From a166d805f437e9f4bb81be1dd9d880bd8fb4b0ed Mon Sep 17 00:00:00 2001 From: Jos Verlinde Date: Thu, 3 Aug 2023 22:20:51 +0200 Subject: [PATCH 065/408] top: Add pre-commit hook for codespell. Signed-off-by: Jos Verlinde --- .pre-commit-config.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3004bc5677214..0576a158b4f1a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,3 +16,10 @@ repos: hooks: - id: ruff - id: ruff-format + - repo: https://github.com/codespell-project/codespell + rev: v2.2.6 + hooks: + - id: codespell + name: Spellcheck for changed files (codespell) + additional_dependencies: + - tomli From c8772b7baa972f17c08f82af584ac2b13f4c1737 Mon Sep 17 00:00:00 2001 From: Jos Verlinde Date: Thu, 3 Aug 2023 22:22:02 +0200 Subject: [PATCH 066/408] CODECONVENTIONS: Update docs for codespell and pre-commit hook. Signed-off-by: Jos Verlinde --- CODECONVENTIONS.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CODECONVENTIONS.md b/CODECONVENTIONS.md index d6b0a5926bf4b..d6af0418e42ef 100644 --- a/CODECONVENTIONS.md +++ b/CODECONVENTIONS.md @@ -104,6 +104,22 @@ This command may work, please raise a new Issue if it doesn't: curl -L https://github.com/Homebrew/homebrew-core/raw/2b07d8192623365078a8b855a164ebcdf81494a6/Formula/uncrustify.rb > uncrustify.rb && brew install uncrustify.rb && rm uncrustify.rb ``` +Code spell checking +=================== + +Code spell checking is done using [codespell](https://github.com/codespell-project/codespell#codespell) +and runs in a GitHub action in CI. Codespell is configured via `pyproject.toml` +to avoid false positives. It is recommended run codespell before submitting a +PR. To simplify this, codespell is configured as a pre-commit hook and will be +installed if you run `pre-commit install` (see below). + +If you want to install and run codespell manually, you can do so by running: + +``` +$ pip install codespell tomli +$ codespell +``` + Automatic Pre-Commit Hooks ========================== From 307ecc5707e78c62b0b9fb1c0ba8dcb9c4cc5559 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 17 Jan 2024 11:55:20 +1100 Subject: [PATCH 067/408] docs: Add note about position-only arguments in CPython vs MicroPython. Required modifying the gen-cpydiff.py code to allow a "preamble" section to be inserted at the top of any of the generated files. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- docs/differences/modules_preamble.txt | 33 +++++++++++++++++++++++++++ tools/gen-cpydiff.py | 11 ++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 docs/differences/modules_preamble.txt diff --git a/docs/differences/modules_preamble.txt b/docs/differences/modules_preamble.txt new file mode 100644 index 0000000000000..1958f0084d2db --- /dev/null +++ b/docs/differences/modules_preamble.txt @@ -0,0 +1,33 @@ +.. Preamble section inserted into generated output + +Positional-only Parameters +-------------------------- + +To save code size, many functions that accept keyword arguments in CPython only accept positional arguments in MicroPython. + +MicroPython marks positional-only parameters in the same way as CPython, by inserting a ``/`` to mark the end of the positional parameters. Any function whose signature ends in ``/`` takes *only* positional arguments. For more details, see `PEP 570 `_. + +Example +~~~~~~~ + +For example, in CPython 3.4 this is the signature of the constructor ``socket.socket``:: + + socket.socket(family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None) + +However, the signature documented in :func:`MicroPython` is:: + + socket(af=AF_INET, type=SOCK_STREAM, proto=IPPROTO_TCP, /) + +The ``/`` at the end of the parameters indicates that they are all positional-only in MicroPython. The following code works in CPython but not in most MicroPython ports:: + + import socket + s = socket.socket(type=socket.SOCK_DGRAM) + +MicroPython will raise an exception:: + + TypeError: function doesn't take keyword arguments + +The following code will work in both CPython and MicroPython:: + + import socket + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) diff --git a/tools/gen-cpydiff.py b/tools/gen-cpydiff.py index 29545bad0b479..578b6c136f568 100644 --- a/tools/gen-cpydiff.py +++ b/tools/gen-cpydiff.py @@ -47,7 +47,8 @@ TESTPATH = "../tests/cpydiff" DOCPATH = "../docs/genrst" -INDEXTEMPLATE = "../docs/differences/index_template.txt" +SRCDIR = "../docs/differences" +INDEXTEMPLATE = os.path.join(SRCDIR, "index_template.txt") INDEX = "index.rst" HEADER = ".. This document was generated by tools/gen-cpydiff.py\n\n" @@ -219,6 +220,14 @@ def gen_rst(results): rst.write(section[i] + "\n") rst.write(RSTCHARS[0] * len(section[i])) rst.write(time.strftime("\nGenerated %a %d %b %Y %X UTC\n\n", time.gmtime())) + # If a file docs/differences/_preamble.txt exists + # then its output is inserted after the top-level heading, + # but before any of the generated sections. + preamble_path = os.path.join(SRCDIR, filename + "_preamble.txt") + if os.path.exists(preamble_path): + with open(preamble_path, "r") as f: + rst.write(f.read()) + rst.write("\n") toctree.append(filename) else: rst.write(section[i] + "\n") From 7ea503929a494a2622d933d3497b393ae14a1550 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Fri, 3 Feb 2023 16:42:03 +1100 Subject: [PATCH 068/408] py/qstr: Add support for MICROPY_QSTR_BYTES_IN_HASH=0. This disables using qstr hashes altogether, which saves RAM and flash (two bytes per interned string on a typical build) as well as code size. On PYBV11 this is worth over 3k flash. qstr comparison will now be done just by length then data. This affects qstr_find_strn although this has a negligible performance impact as, for a given comparison, the length and first character will ~usually be different anyway. String hashing (e.g. builtin `hash()` and map.c) now need to compute the hash dynamically, and for the map case this does come at a performance cost. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- py/makeqstrdata.py | 3 ++- py/qstr.c | 52 ++++++++++++++++++++++++++++++++++++++++------ py/qstr.h | 7 ++++++- tools/mpy-tool.py | 27 +++++++++++------------- 4 files changed, 66 insertions(+), 23 deletions(-) diff --git a/py/makeqstrdata.py b/py/makeqstrdata.py index 2350fe04d29a6..3e5e7930a5b88 100644 --- a/py/makeqstrdata.py +++ b/py/makeqstrdata.py @@ -295,7 +295,8 @@ def compute_hash(qstr, bytes_hash): for b in qstr: hash = (hash * 33) ^ b # Make sure that valid hash is never zero, zero means "hash not computed" - return (hash & ((1 << (8 * bytes_hash)) - 1)) or 1 + # if bytes_hash is zero, assume a 16-bit mask (to match qstr.c) + return (hash & ((1 << (8 * (bytes_hash or 2))) - 1)) or 1 def qstr_escape(qst): diff --git a/py/qstr.c b/py/qstr.c index dc89013f86f86..204becd2136e0 100644 --- a/py/qstr.c +++ b/py/qstr.c @@ -42,7 +42,11 @@ // A qstr is an index into the qstr pool. // The data for a qstr is \0 terminated (so they can be printed using printf) +#if MICROPY_QSTR_BYTES_IN_HASH #define Q_HASH_MASK ((1 << (8 * MICROPY_QSTR_BYTES_IN_HASH)) - 1) +#else +#define Q_HASH_MASK (0xffff) +#endif #if MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL #define QSTR_ENTER() mp_thread_mutex_lock(&MP_STATE_VM(qstr_mutex), 1) @@ -77,6 +81,7 @@ size_t qstr_compute_hash(const byte *data, size_t len) { // future .mpy version we could re-order them and make it sorted). It also // contains additional qstrs that must have IDs <256, see operator_qstr_list // in makeqstrdata.py. +#if MICROPY_QSTR_BYTES_IN_HASH const qstr_hash_t mp_qstr_const_hashes_static[] = { #ifndef NO_QSTR #define QDEF0(id, hash, len, str) hash, @@ -86,6 +91,7 @@ const qstr_hash_t mp_qstr_const_hashes_static[] = { #undef QDEF1 #endif }; +#endif const qstr_len_t mp_qstr_const_lengths_static[] = { #ifndef NO_QSTR @@ -103,7 +109,9 @@ const qstr_pool_t mp_qstr_const_pool_static = { false, // is_sorted MICROPY_ALLOC_QSTR_ENTRIES_INIT, MP_QSTRnumber_of_static, // corresponds to number of strings in array just below + #if MICROPY_QSTR_BYTES_IN_HASH (qstr_hash_t *)mp_qstr_const_hashes_static, + #endif (qstr_len_t *)mp_qstr_const_lengths_static, { #ifndef NO_QSTR @@ -118,6 +126,7 @@ const qstr_pool_t mp_qstr_const_pool_static = { // The next pool is the remainder of the qstrs defined in the firmware. This // is sorted. +#if MICROPY_QSTR_BYTES_IN_HASH const qstr_hash_t mp_qstr_const_hashes[] = { #ifndef NO_QSTR #define QDEF0(id, hash, len, str) @@ -127,6 +136,7 @@ const qstr_hash_t mp_qstr_const_hashes[] = { #undef QDEF1 #endif }; +#endif const qstr_len_t mp_qstr_const_lengths[] = { #ifndef NO_QSTR @@ -144,7 +154,9 @@ const qstr_pool_t mp_qstr_const_pool = { true, // is_sorted MICROPY_ALLOC_QSTR_ENTRIES_INIT, MP_QSTRnumber_of - MP_QSTRnumber_of_static, // corresponds to number of strings in array just below + #if MICROPY_QSTR_BYTES_IN_HASH (qstr_hash_t *)mp_qstr_const_hashes, + #endif (qstr_len_t *)mp_qstr_const_lengths, { #ifndef NO_QSTR @@ -188,8 +200,13 @@ STATIC const qstr_pool_t *find_qstr(qstr *q) { } // qstr_mutex must be taken while in this function -STATIC qstr qstr_add(mp_uint_t hash, mp_uint_t len, const char *q_ptr) { +STATIC qstr qstr_add(mp_uint_t len, const char *q_ptr) { + #if MICROPY_QSTR_BYTES_IN_HASH + mp_uint_t hash = qstr_compute_hash((const byte *)q_ptr, len); DEBUG_printf("QSTR: add hash=%d len=%d data=%.*s\n", hash, len, len, q_ptr); + #else + DEBUG_printf("QSTR: add len=%d data=%.*s\n", len, len, q_ptr); + #endif // make sure we have room in the pool for a new qstr if (MP_STATE_VM(last_pool)->len >= MP_STATE_VM(last_pool)->alloc) { @@ -199,7 +216,11 @@ STATIC qstr qstr_add(mp_uint_t hash, mp_uint_t len, const char *q_ptr) { new_alloc = MAX(MICROPY_ALLOC_QSTR_ENTRIES_INIT, new_alloc); #endif mp_uint_t pool_size = sizeof(qstr_pool_t) - + (sizeof(const char *) + sizeof(qstr_hash_t) + sizeof(qstr_len_t)) * new_alloc; + + (sizeof(const char *) + #if MICROPY_QSTR_BYTES_IN_HASH + + sizeof(qstr_hash_t) + #endif + + sizeof(qstr_len_t)) * new_alloc; qstr_pool_t *pool = (qstr_pool_t *)m_malloc_maybe(pool_size); if (pool == NULL) { // Keep qstr_last_chunk consistent with qstr_pool_t: qstr_last_chunk is not scanned @@ -211,8 +232,12 @@ STATIC qstr qstr_add(mp_uint_t hash, mp_uint_t len, const char *q_ptr) { QSTR_EXIT(); m_malloc_fail(new_alloc); } + #if MICROPY_QSTR_BYTES_IN_HASH pool->hashes = (qstr_hash_t *)(pool->qstrs + new_alloc); pool->lengths = (qstr_len_t *)(pool->hashes + new_alloc); + #else + pool->lengths = (qstr_len_t *)(pool->qstrs + new_alloc); + #endif pool->prev = MP_STATE_VM(last_pool); pool->total_prev_len = MP_STATE_VM(last_pool)->total_prev_len + MP_STATE_VM(last_pool)->len; pool->alloc = new_alloc; @@ -223,7 +248,9 @@ STATIC qstr qstr_add(mp_uint_t hash, mp_uint_t len, const char *q_ptr) { // add the new qstr mp_uint_t at = MP_STATE_VM(last_pool)->len; + #if MICROPY_QSTR_BYTES_IN_HASH MP_STATE_VM(last_pool)->hashes[at] = hash; + #endif MP_STATE_VM(last_pool)->lengths[at] = len; MP_STATE_VM(last_pool)->qstrs[at] = q_ptr; MP_STATE_VM(last_pool)->len++; @@ -238,8 +265,10 @@ qstr qstr_find_strn(const char *str, size_t str_len) { return MP_QSTR_; } + #if MICROPY_QSTR_BYTES_IN_HASH // work out hash of str size_t str_hash = qstr_compute_hash((const byte *)str, str_len); + #endif // search pools for the data for (const qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL; pool = pool->prev) { @@ -261,7 +290,11 @@ qstr qstr_find_strn(const char *str, size_t str_len) { // sequential search for the remaining strings for (mp_uint_t at = low; at < high + 1; at++) { - if (pool->hashes[at] == str_hash && pool->lengths[at] == str_len + if ( + #if MICROPY_QSTR_BYTES_IN_HASH + pool->hashes[at] == str_hash && + #endif + pool->lengths[at] == str_len && memcmp(pool->qstrs[at], str, str_len) == 0) { return pool->total_prev_len + at; } @@ -329,10 +362,9 @@ qstr qstr_from_strn(const char *str, size_t len) { MP_STATE_VM(qstr_last_used) += n_bytes; // store the interned strings' data - size_t hash = qstr_compute_hash((const byte *)str, len); memcpy(q_ptr, str, len); q_ptr[len] = '\0'; - q = qstr_add(hash, len, q_ptr); + q = qstr_add(len, q_ptr); } QSTR_EXIT(); return q; @@ -340,7 +372,11 @@ qstr qstr_from_strn(const char *str, size_t len) { mp_uint_t qstr_hash(qstr q) { const qstr_pool_t *pool = find_qstr(&q); + #if MICROPY_QSTR_BYTES_IN_HASH return pool->hashes[q]; + #else + return qstr_compute_hash((byte *)pool->qstrs[q], pool->lengths[q]); + #endif } size_t qstr_len(qstr q) { @@ -375,7 +411,11 @@ void qstr_pool_info(size_t *n_pool, size_t *n_qstr, size_t *n_str_data_bytes, si *n_total_bytes += gc_nbytes(pool); // this counts actual bytes used in heap #else *n_total_bytes += sizeof(qstr_pool_t) - + (sizeof(const char *) + sizeof(qstr_hash_t) + sizeof(qstr_len_t)) * pool->alloc; + + (sizeof(const char *) + #if MICROPY_QSTR_BYTES_IN_HASH + + sizeof(qstr_hash_t) + #endif + + sizeof(qstr_len_t)) * pool->alloc; #endif } *n_total_bytes += *n_str_data_bytes; diff --git a/py/qstr.h b/py/qstr.h index 0c4fc4632cd53..58ce285fd2c8a 100644 --- a/py/qstr.h +++ b/py/qstr.h @@ -60,7 +60,9 @@ enum { typedef size_t qstr; typedef uint16_t qstr_short_t; -#if MICROPY_QSTR_BYTES_IN_HASH == 1 +#if MICROPY_QSTR_BYTES_IN_HASH == 0 +// No qstr_hash_t type needed. +#elif MICROPY_QSTR_BYTES_IN_HASH == 1 typedef uint8_t qstr_hash_t; #elif MICROPY_QSTR_BYTES_IN_HASH == 2 typedef uint16_t qstr_hash_t; @@ -82,7 +84,9 @@ typedef struct _qstr_pool_t { size_t is_sorted : 1; size_t alloc; size_t len; + #if MICROPY_QSTR_BYTES_IN_HASH qstr_hash_t *hashes; + #endif qstr_len_t *lengths; const char *qstrs[]; } qstr_pool_t; @@ -92,6 +96,7 @@ typedef struct _qstr_pool_t { void qstr_init(void); size_t qstr_compute_hash(const byte *data, size_t len); + qstr qstr_find_strn(const char *str, size_t str_len); // returns MP_QSTRnull if not found qstr qstr_from_str(const char *str); diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py index 8d86c10173c82..519462ec80157 100755 --- a/tools/mpy-tool.py +++ b/tools/mpy-tool.py @@ -1473,21 +1473,20 @@ def freeze_mpy(firmware_qstr_idents, compiled_modules): raw_code_count = 0 raw_code_content = 0 - print() - print("const qstr_hash_t mp_qstr_frozen_const_hashes[] = {") - qstr_size = {"metadata": 0, "data": 0} - for _, _, _, qbytes in new: - qhash = qstrutil.compute_hash(qbytes, config.MICROPY_QSTR_BYTES_IN_HASH) - print(" %d," % qhash) - print("};") + if config.MICROPY_QSTR_BYTES_IN_HASH: + print() + print("const qstr_hash_t mp_qstr_frozen_const_hashes[] = {") + for _, _, _, qbytes in new: + qhash = qstrutil.compute_hash(qbytes, config.MICROPY_QSTR_BYTES_IN_HASH) + print(" %d," % qhash) + qstr_content += config.MICROPY_QSTR_BYTES_IN_HASH + print("};") print() print("const qstr_len_t mp_qstr_frozen_const_lengths[] = {") for _, _, _, qbytes in new: print(" %d," % len(qbytes)) - qstr_size["metadata"] += ( - config.MICROPY_QSTR_BYTES_IN_LEN + config.MICROPY_QSTR_BYTES_IN_HASH - ) - qstr_size["data"] += len(qbytes) + qstr_content += config.MICROPY_QSTR_BYTES_IN_LEN + qstr_content += len(qbytes) + 1 # include NUL print("};") print() print("extern const qstr_pool_t mp_qstr_const_pool;") @@ -1497,14 +1496,12 @@ def freeze_mpy(firmware_qstr_idents, compiled_modules): print(" true, // is_sorted") print(" %u, // allocated entries" % qstr_pool_alloc) print(" %u, // used entries" % len(new)) - print(" (qstr_hash_t *)mp_qstr_frozen_const_hashes,") + if config.MICROPY_QSTR_BYTES_IN_HASH: + print(" (qstr_hash_t *)mp_qstr_frozen_const_hashes,") print(" (qstr_len_t *)mp_qstr_frozen_const_lengths,") print(" {") for _, _, qstr, qbytes in new: print(' "%s",' % qstrutil.escape_bytes(qstr, qbytes)) - qstr_content += ( - config.MICROPY_QSTR_BYTES_IN_LEN + config.MICROPY_QSTR_BYTES_IN_HASH + len(qbytes) + 1 - ) print(" },") print("};") From 8486e28b1704ab2029d24476d78118bdfd56de1b Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Tue, 31 Oct 2023 10:33:15 +1100 Subject: [PATCH 069/408] stm32: Disable qstr hashing on small boards. Sets MICROPY_QSTR_BYTES_IN_HASH==0 on stm32x0 boards. This saves e.g. 2kiB on NUCLEO_F091. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- ports/stm32/boards/B_L072Z_LRWAN1/mpconfigboard.h | 2 ++ ports/stm32/boards/NUCLEO_F091RC/mpconfigboard.h | 2 ++ ports/stm32/boards/NUCLEO_L073RZ/mpconfigboard.h | 2 ++ 3 files changed, 6 insertions(+) diff --git a/ports/stm32/boards/B_L072Z_LRWAN1/mpconfigboard.h b/ports/stm32/boards/B_L072Z_LRWAN1/mpconfigboard.h index c2a0ba4f44cd3..df781a756717b 100644 --- a/ports/stm32/boards/B_L072Z_LRWAN1/mpconfigboard.h +++ b/ports/stm32/boards/B_L072Z_LRWAN1/mpconfigboard.h @@ -7,6 +7,8 @@ #define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_CORE_FEATURES) +#define MICROPY_QSTR_BYTES_IN_HASH (0) + #define MICROPY_HELPER_REPL (1) #define MICROPY_KBD_EXCEPTION (1) #define MICROPY_EMIT_THUMB (0) diff --git a/ports/stm32/boards/NUCLEO_F091RC/mpconfigboard.h b/ports/stm32/boards/NUCLEO_F091RC/mpconfigboard.h index e28bb51f609db..6a9ac02714fb7 100644 --- a/ports/stm32/boards/NUCLEO_F091RC/mpconfigboard.h +++ b/ports/stm32/boards/NUCLEO_F091RC/mpconfigboard.h @@ -1,6 +1,8 @@ #define MICROPY_HW_BOARD_NAME "NUCLEO-F091RC" #define MICROPY_HW_MCU_NAME "STM32F091RCT6" +#define MICROPY_QSTR_BYTES_IN_HASH (0) + #define MICROPY_EMIT_THUMB (0) #define MICROPY_EMIT_INLINE_THUMB (0) #define MICROPY_OPT_COMPUTED_GOTO (0) diff --git a/ports/stm32/boards/NUCLEO_L073RZ/mpconfigboard.h b/ports/stm32/boards/NUCLEO_L073RZ/mpconfigboard.h index 7ec295e44d74b..83fd99fc5f971 100644 --- a/ports/stm32/boards/NUCLEO_L073RZ/mpconfigboard.h +++ b/ports/stm32/boards/NUCLEO_L073RZ/mpconfigboard.h @@ -5,6 +5,8 @@ #define MICROPY_HW_BOARD_NAME "NUCLEO-L073RZ" #define MICROPY_HW_MCU_NAME "STM32L073RZT6" +#define MICROPY_QSTR_BYTES_IN_HASH (0) + #define MICROPY_EMIT_THUMB (0) #define MICROPY_EMIT_INLINE_THUMB (0) #define MICROPY_OPT_COMPUTED_GOTO (0) From d4190815a3f0a3fd31c056db46cac3970395c586 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Tue, 31 Oct 2023 10:47:45 +1100 Subject: [PATCH 070/408] py/mpconfig: Disable qstr hashing at minimum feature level. This will apply to bare-arm and minimal, as well as the minimal unix variant. Change the default to MICROPY_QSTR_BYTES_IN_HASH=1 for the CORE,BASIC levels, 2 for >=EXTRA. Removes explicit setting of MICROPY_QSTR_BYTES_IN_HASH==1 in ports that don't set the feature level (because 1 is implied by the default level, CORE). Applies to cc3200, pic16bt, powerpc. Removes explicit setting for nRF (which sets feature level). Also for samd, which sets CORE for d21 and FULL for d51. This means that d21 is unchanged with MICROPY_QSTR_BYTES_IN_HASH==1, but d51 now moves from 1 to 2 (roughly adds 1kiB). The only remaining port which explicitly set bytes-in-hash is rp2 because it's high-flash (hence CORE level) but lowish-SRAM, so it's worthwhile saving the RAM for runtime qstrs. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- ports/cc3200/mpconfigport.h | 1 - ports/nrf/mpconfigport.h | 1 - ports/pic16bit/mpconfigport.h | 1 - ports/powerpc/mpconfigport.h | 1 - ports/samd/mpconfigport.h | 1 - ports/unix/variants/minimal/mpconfigvariant.h | 3 --- py/mpconfig.h | 6 ++++-- 7 files changed, 4 insertions(+), 10 deletions(-) diff --git a/ports/cc3200/mpconfigport.h b/ports/cc3200/mpconfigport.h index fe579c08747b9..d472d29f70242 100644 --- a/ports/cc3200/mpconfigport.h +++ b/ports/cc3200/mpconfigport.h @@ -59,7 +59,6 @@ #else #define MICROPY_CPYTHON_COMPAT (0) #endif -#define MICROPY_QSTR_BYTES_IN_HASH (1) // fatfs configuration used in ffconf.h #define MICROPY_FATFS_ENABLE_LFN (2) diff --git a/ports/nrf/mpconfigport.h b/ports/nrf/mpconfigport.h index f3c08059a06eb..30625382e43c2 100644 --- a/ports/nrf/mpconfigport.h +++ b/ports/nrf/mpconfigport.h @@ -281,7 +281,6 @@ #define MICROPY_PY_SYS (1) #define MICROPY_PY_SYS_PATH_ARGV_DEFAULTS (1) #define MICROPY_PY___FILE__ (1) -#define MICROPY_QSTR_BYTES_IN_HASH (2) #endif #ifndef MICROPY_PY_UBLUEPY diff --git a/ports/pic16bit/mpconfigport.h b/ports/pic16bit/mpconfigport.h index f1bfa4cd6f16d..a2d607fb29325 100644 --- a/ports/pic16bit/mpconfigport.h +++ b/ports/pic16bit/mpconfigport.h @@ -29,7 +29,6 @@ // options to control how MicroPython is built #define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_B) #define MICROPY_ALLOC_PATH_MAX (64) -#define MICROPY_QSTR_BYTES_IN_HASH (1) #define MICROPY_EMIT_X64 (0) #define MICROPY_EMIT_THUMB (0) #define MICROPY_EMIT_INLINE_THUMB (0) diff --git a/ports/powerpc/mpconfigport.h b/ports/powerpc/mpconfigport.h index 06200a9969017..b74f374e7f9f5 100644 --- a/ports/powerpc/mpconfigport.h +++ b/ports/powerpc/mpconfigport.h @@ -35,7 +35,6 @@ // #define MICROPY_DEBUG_VERBOSE (1) -#define MICROPY_QSTR_BYTES_IN_HASH (1) #define MICROPY_QSTR_EXTRA_POOL mp_qstr_frozen_const_pool #define MICROPY_ALLOC_PATH_MAX (256) #define MICROPY_EMIT_X64 (0) diff --git a/ports/samd/mpconfigport.h b/ports/samd/mpconfigport.h index 218e4bb96ab3d..160442a4006b8 100644 --- a/ports/samd/mpconfigport.h +++ b/ports/samd/mpconfigport.h @@ -35,7 +35,6 @@ #define MICROPY_GC_STACK_ENTRY_TYPE uint16_t #define MICROPY_GC_ALLOC_THRESHOLD (0) #define MICROPY_ALLOC_PATH_MAX (256) -#define MICROPY_QSTR_BYTES_IN_HASH (1) // MicroPython emitters #define MICROPY_PERSISTENT_CODE_LOAD (1) diff --git a/ports/unix/variants/minimal/mpconfigvariant.h b/ports/unix/variants/minimal/mpconfigvariant.h index 0dbfbb3d1cd43..97ed786b8f409 100644 --- a/ports/unix/variants/minimal/mpconfigvariant.h +++ b/ports/unix/variants/minimal/mpconfigvariant.h @@ -64,6 +64,3 @@ // Enable just the sys and os built-in modules. #define MICROPY_PY_SYS (1) #define MICROPY_PY_OS (1) - -// The minimum sets this to 1 to save flash. -#define MICROPY_QSTR_BYTES_IN_HASH (2) diff --git a/py/mpconfig.h b/py/mpconfig.h index a1e9660bf46a6..9a1f04568e0fa 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -290,10 +290,12 @@ // Number of bytes used to store qstr hash #ifndef MICROPY_QSTR_BYTES_IN_HASH -#if MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES +#if MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES #define MICROPY_QSTR_BYTES_IN_HASH (2) -#else +#elif MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES #define MICROPY_QSTR_BYTES_IN_HASH (1) +#else +#define MICROPY_QSTR_BYTES_IN_HASH (0) #endif #endif From bf6214505fb477890416f4c5ec5912611fc361d6 Mon Sep 17 00:00:00 2001 From: "Kwabena W. Agyeman" Date: Mon, 22 Jan 2024 14:01:02 -0800 Subject: [PATCH 071/408] mimxrt/modmachine: Fix deepsleep wakeup pin ifdef. Signed-off-by: Kwabena W. Agyeman --- ports/mimxrt/modmachine.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/mimxrt/modmachine.c b/ports/mimxrt/modmachine.c index b87747b409c9f..e01703af8cd4b 100644 --- a/ports/mimxrt/modmachine.c +++ b/ports/mimxrt/modmachine.c @@ -139,10 +139,10 @@ NORETURN STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) { } } - #ifdef MIMXRT117x_SERIES + #if defined(MIMXRT117x_SERIES) machine_pin_config(pin_WAKEUP_DIG, PIN_MODE_IT_RISING, PIN_PULL_DISABLED, PIN_DRIVE_OFF, 0, PIN_AF_MODE_ALT5); GPC_CM_EnableIrqWakeup(GPC_CPU_MODE_CTRL_0, GPIO13_Combined_0_31_IRQn, true); - #elif defined IOMUXC_SNVS_WAKEUP_GPIO5_IO00 + #elif defined(pin_WAKEUP) machine_pin_config(pin_WAKEUP, PIN_MODE_IT_RISING, PIN_PULL_DISABLED, PIN_DRIVE_OFF, 0, PIN_AF_MODE_ALT5); GPC_EnableIRQ(GPC, GPIO5_Combined_0_15_IRQn); #endif From 8d9d74b6dff56a6f9b846a776c618977d3c7aa8f Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Thu, 25 Jan 2024 12:02:30 +0200 Subject: [PATCH 072/408] rp2/boards/ARDUINO_NANO_RP2040_CONNECT: Increase flash storage space. Fixes issue #13512. Signed-off-by: iabdalkader --- ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/mpconfigboard.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/mpconfigboard.h b/ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/mpconfigboard.h index b969341a7fe1e..7783c0a17c64d 100644 --- a/ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/mpconfigboard.h +++ b/ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/mpconfigboard.h @@ -2,7 +2,7 @@ // Board and hardware specific configuration #define MICROPY_HW_BOARD_NAME "Arduino Nano RP2040 Connect" -#define MICROPY_HW_FLASH_STORAGE_BYTES (8 * 1024 * 1024) +#define MICROPY_HW_FLASH_STORAGE_BYTES (14 * 1024 * 1024) // Network config #define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-nano-rp2040-connect" From 4a2e510a877fc5b9256b2717acba8ac772e04a6e Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Thu, 25 Jan 2024 14:30:51 +0200 Subject: [PATCH 073/408] ports: Add LED pin aliases for all Arduino boards. The standard Arduino pinout uses LEDR/G/B and LED_BUILTIN (if available). This patch adds aliases to match the standard pinout, while retaining LED_RED/GREEN/BLUE for compatibility with existing scripts and examples. Signed-off-by: iabdalkader --- ports/esp32/boards/ARDUINO_NANO_ESP32/pins.csv | 3 +++ ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/pins.csv | 3 +++ ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/pins.csv | 4 ++++ ports/stm32/boards/ARDUINO_GIGA/pins.csv | 3 +++ ports/stm32/boards/ARDUINO_NICLA_VISION/pins.csv | 3 +++ ports/stm32/boards/ARDUINO_PORTENTA_H7/pins.csv | 3 +++ 6 files changed, 19 insertions(+) diff --git a/ports/esp32/boards/ARDUINO_NANO_ESP32/pins.csv b/ports/esp32/boards/ARDUINO_NANO_ESP32/pins.csv index b891608d5d89c..5934ae7bf2a0c 100644 --- a/ports/esp32/boards/ARDUINO_NANO_ESP32/pins.csv +++ b/ports/esp32/boards/ARDUINO_NANO_ESP32/pins.csv @@ -12,6 +12,9 @@ D10,GPIO21 D11,GPIO38 D12,GPIO47 D13,GPIO48 +LEDR,GPIO46 +LEDG,GPIO0 +LEDB,GPIO45 LED_RED,GPIO46 LED_GREEN,GPIO0 LED_BLUE,GPIO45 diff --git a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/pins.csv b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/pins.csv index 1e6379a07b8ba..77b5c3de52820 100644 --- a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/pins.csv +++ b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/pins.csv @@ -147,6 +147,9 @@ D5,P210 LED1,P107 LED2,P400 LED3,P800 +LEDR,P107 +LEDG,P400 +LEDB,P800 LED_RED,P107 LED_GREEN,P400 LED_BLUE,P800 diff --git a/ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/pins.csv b/ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/pins.csv index 0b1566cacf7f6..5f8aeaf447f77 100644 --- a/ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/pins.csv +++ b/ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/pins.csv @@ -13,12 +13,16 @@ D11,GPIO7 D12,GPIO4 D13,GPIO6 LED,GPIO6 +LED_BUILTIN,GPIO6 A0,GPIO26 A1,GPIO27 A2,GPIO28 A3,GPIO29 SDA,GPIO12 SCL,GPIO13 +LEDR,EXT_GPIO0 +LEDG,EXT_GPIO1 +LEDB,EXT_GPIO2 LED_RED,EXT_GPIO0 LED_GREEN,EXT_GPIO1 LED_BLUE,EXT_GPIO2 diff --git a/ports/stm32/boards/ARDUINO_GIGA/pins.csv b/ports/stm32/boards/ARDUINO_GIGA/pins.csv index 56e63232908ce..9de1a316d1cd4 100644 --- a/ports/stm32/boards/ARDUINO_GIGA/pins.csv +++ b/ports/stm32/boards/ARDUINO_GIGA/pins.csv @@ -179,6 +179,9 @@ UART6_RX,PC7 #BOOT0,BOOT0 DAC1,PA4 DAC2,PA5 +LEDR,PI12 +LEDG,PJ13 +LEDB,PE3 LED_RED,PI12 LED_GREEN,PJ13 LED_BLUE,PE3 diff --git a/ports/stm32/boards/ARDUINO_NICLA_VISION/pins.csv b/ports/stm32/boards/ARDUINO_NICLA_VISION/pins.csv index 2838510ee3126..72f57adf74234 100644 --- a/ports/stm32/boards/ARDUINO_NICLA_VISION/pins.csv +++ b/ports/stm32/boards/ARDUINO_NICLA_VISION/pins.csv @@ -180,6 +180,9 @@ USB_DP,PA12 OSCEN,PH1 DAC1,-PA4 DAC2,-PA5 +LEDR,PE3 +LEDG,PC13 +LEDB,-PF4 LED_RED,PE3 LED_GREEN,PC13 LED_BLUE,-PF4 diff --git a/ports/stm32/boards/ARDUINO_PORTENTA_H7/pins.csv b/ports/stm32/boards/ARDUINO_PORTENTA_H7/pins.csv index 4ac406fe3a743..3b93dcba73f91 100644 --- a/ports/stm32/boards/ARDUINO_PORTENTA_H7/pins.csv +++ b/ports/stm32/boards/ARDUINO_PORTENTA_H7/pins.csv @@ -203,6 +203,9 @@ UART8_RX,PJ9 OSCEN,PH1 DAC1,PA4 DAC2,-PA5 +LEDR,PK5 +LEDG,PK6 +LEDB,PK7 LED_RED,PK5 LED_GREEN,PK6 LED_BLUE,PK7 From 7211bafb336b0a22746481489c3252085e78b42a Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 29 Jan 2024 12:19:06 +1100 Subject: [PATCH 074/408] esp8266/boards/ESP8266_GENERIC: Disable MICROPY_DEBUG_PRINTERS. This is not enabled on any other MCU port, and is essentially unused on esp8266 because mp_verbose_flag is always 0. Disabling saves ~7k of flash. Signed-off-by: Damien George --- ports/esp8266/boards/ESP8266_GENERIC/mpconfigboard.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/ports/esp8266/boards/ESP8266_GENERIC/mpconfigboard.h b/ports/esp8266/boards/ESP8266_GENERIC/mpconfigboard.h index 3a9c40e79503c..1f679961e8786 100644 --- a/ports/esp8266/boards/ESP8266_GENERIC/mpconfigboard.h +++ b/ports/esp8266/boards/ESP8266_GENERIC/mpconfigboard.h @@ -7,7 +7,6 @@ #define MICROPY_EMIT_XTENSA (1) #define MICROPY_EMIT_INLINE_XTENSA (1) -#define MICROPY_DEBUG_PRINTERS (1) #define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_NORMAL) #define MICROPY_READER_VFS (MICROPY_VFS) @@ -24,7 +23,6 @@ #define MICROPY_EMIT_XTENSA (1) #define MICROPY_EMIT_INLINE_XTENSA (1) -#define MICROPY_DEBUG_PRINTERS (1) #define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_NORMAL) #define MICROPY_READER_VFS (MICROPY_VFS) From 40687451bbad09386aa64d03d4aab18da8e01706 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 29 Jan 2024 13:04:20 +1100 Subject: [PATCH 075/408] tests/extmod/framebuf_polygon.py: Replace sys.stdout.write with print. So the test doesn't depend on the `sys` module. Signed-off-by: Damien George --- tests/extmod/framebuf_polygon.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/extmod/framebuf_polygon.py b/tests/extmod/framebuf_polygon.py index 03130b3bf0fab..da05be2c4db52 100644 --- a/tests/extmod/framebuf_polygon.py +++ b/tests/extmod/framebuf_polygon.py @@ -1,5 +1,3 @@ -import sys - try: import framebuf from array import array @@ -18,8 +16,8 @@ def print_buffer(buffer, width, height): for row in range(height): for col in range(width): val = buffer[(row * width) + col] - sys.stdout.write(" {:02x}".format(val) if val else " ··") - sys.stdout.write("\n") + print(" {:02x}".format(val) if val else " ··", end="") + print() buf = bytearray(70 * 70) From 46e833b071174ca18fbeae993a725d8c57da88a6 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 29 Jan 2024 12:46:03 +1100 Subject: [PATCH 076/408] qemu-arm/mpconfigport: Use MICROPY_CONFIG_ROM_LEVEL_EXTRA_FEATURES. This simplifes the port configuration. It enables quite a few new features, including the `math` and `cmath` modules, adding about 20k to the firmware size. Signed-off-by: Damien George --- ports/qemu-arm/mpconfigport.h | 41 +++++++++++------------------------ 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/ports/qemu-arm/mpconfigport.h b/ports/qemu-arm/mpconfigport.h index 3efa1412df1ae..ccee777752bdf 100644 --- a/ports/qemu-arm/mpconfigport.h +++ b/ports/qemu-arm/mpconfigport.h @@ -2,7 +2,7 @@ // options to control how MicroPython is built -#define MICROPY_ALLOC_PATH_MAX (512) +#define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_EXTRA_FEATURES) #if defined(__ARM_ARCH_ISA_ARM) #define MICROPY_EMIT_ARM (1) @@ -15,42 +15,24 @@ #define MICROPY_MALLOC_USES_ALLOCATED_SIZE (1) #define MICROPY_MEM_STATS (1) -#define MICROPY_DEBUG_PRINTERS (0) #define MICROPY_ENABLE_GC (1) -#define MICROPY_STACK_CHECK (1) +#define MICROPY_KBD_EXCEPTION (0) #define MICROPY_HELPER_REPL (0) -#define MICROPY_HELPER_LEXER_UNIX (0) -#define MICROPY_ENABLE_SOURCE_LINE (1) #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ) #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT) -#define MICROPY_CAN_OVERRIDE_BUILTINS (1) #define MICROPY_WARNINGS (1) -#define MICROPY_PY_ALL_SPECIAL_METHODS (1) -#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) -#define MICROPY_PY_ARRAY_SLICE_ASSIGN (1) -#define MICROPY_PY_BUILTINS_BYTES_HEX (1) -#define MICROPY_PY_BUILTINS_FROZENSET (1) -#define MICROPY_PY_BUILTINS_MEMORYVIEW (1) -#define MICROPY_PY_BUILTINS_POW3 (1) -#define MICROPY_PY_IO (1) -#define MICROPY_PY_SYS_EXIT (1) -#define MICROPY_PY_SYS_MAXSIZE (1) +#define MICROPY_PY_BUILTINS_INPUT (0) +#define MICROPY_PY_BUILTINS_HELP (0) +#define MICROPY_PY_IO_IOBASE (0) #define MICROPY_PY_SYS_PLATFORM "qemu-arm" -#define MICROPY_PY_ERRNO (1) -#define MICROPY_PY_BINASCII (1) -#define MICROPY_PY_RANDOM (1) -#define MICROPY_PY_UCTYPES (1) -#define MICROPY_PY_DEFLATE (1) -#define MICROPY_PY_JSON (1) -#define MICROPY_PY_OS (1) -#define MICROPY_PY_RE (1) -#define MICROPY_PY_HEAPQ (1) -#define MICROPY_PY_HASHLIB (1) +#define MICROPY_PY_SYS_STDFILES (0) +#define MICROPY_PY_SYS_STDIO_BUFFER (0) +#define MICROPY_PY_SELECT (0) +#define MICROPY_PY_TIME (0) +#define MICROPY_PY_ASYNCIO (0) #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MACHINE_INCLUDEFILE "ports/qemu-arm/modmachine.c" #define MICROPY_PY_MACHINE_PIN_BASE (1) -#define MICROPY_PY_MICROPYTHON_MEM_INFO (1) -#define MICROPY_USE_INTERNAL_PRINTF (1) #define MICROPY_VFS (1) // type definitions for the specific machine @@ -67,6 +49,9 @@ typedef long mp_off_t; // We need to provide a declaration/definition of alloca() #include +// We need an implementation of the log2 function which is not a macro. +#define MP_NEED_LOG2 (1) + #ifdef TEST #include "shared/upytesthelper/upytesthelper.h" #undef MP_PLAT_PRINT_STRN From d5b96813dcdd40e19a59e220d73a4fba5ab85fbe Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 29 Jan 2024 15:11:46 +1100 Subject: [PATCH 077/408] extmod/modssl_mbedtls: Fix cipher iteration in SSLContext.get_ciphers. Prior to this commit it would skip every second cipher returned from mbedtls. The corresponding test is also updated and now passes on esp32, rp2, stm32 and unix. Signed-off-by: Damien George --- extmod/modssl_mbedtls.c | 4 ---- tests/extmod/ssl_sslcontext_ciphers.py | 4 +++- tests/extmod/ssl_sslcontext_ciphers.py.exp | 4 ++++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/extmod/modssl_mbedtls.c b/extmod/modssl_mbedtls.c index 0190c96a9ab19..b6275d8d88fb7 100644 --- a/extmod/modssl_mbedtls.c +++ b/extmod/modssl_mbedtls.c @@ -311,10 +311,6 @@ STATIC mp_obj_t ssl_context_get_ciphers(mp_obj_t self_in) { for (const int *cipher_list = mbedtls_ssl_list_ciphersuites(); *cipher_list; ++cipher_list) { const char *cipher_name = mbedtls_ssl_get_ciphersuite_name(*cipher_list); mp_obj_list_append(list, MP_OBJ_FROM_PTR(mp_obj_new_str(cipher_name, strlen(cipher_name)))); - cipher_list++; - if (!*cipher_list) { - break; - } } return list; } diff --git a/tests/extmod/ssl_sslcontext_ciphers.py b/tests/extmod/ssl_sslcontext_ciphers.py index d87e96afdf337..20c00b917623c 100644 --- a/tests/extmod/ssl_sslcontext_ciphers.py +++ b/tests/extmod/ssl_sslcontext_ciphers.py @@ -12,7 +12,9 @@ ciphers = ctx.get_ciphers() for ci in ciphers: - print(ci) + # Only print those ciphers know to exist on all ports. + if ("TLS-ECDHE-ECDSA-WITH-AES" in ci or "TLS-RSA-WITH-AES" in ci) and "CBC" in ci: + print(ci) ctx.set_ciphers(ciphers[:1]) diff --git a/tests/extmod/ssl_sslcontext_ciphers.py.exp b/tests/extmod/ssl_sslcontext_ciphers.py.exp index 4d243a7883b7c..0d21a3bd253e7 100644 --- a/tests/extmod/ssl_sslcontext_ciphers.py.exp +++ b/tests/extmod/ssl_sslcontext_ciphers.py.exp @@ -1,6 +1,10 @@ TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA384 +TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256 +TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA TLS-RSA-WITH-AES-256-CBC-SHA256 +TLS-RSA-WITH-AES-256-CBC-SHA TLS-RSA-WITH-AES-128-CBC-SHA256 +TLS-RSA-WITH-AES-128-CBC-SHA object 'str' isn't a tuple or list (-24192, 'MBEDTLS_ERR_SSL_BAD_CONFIG') From 3f217e413d257b472aaf2f74b6b6d4ed9cb83f35 Mon Sep 17 00:00:00 2001 From: Carlosgg Date: Sat, 30 Jul 2022 17:01:56 +0100 Subject: [PATCH 078/408] lib/mbedtls: Update to mbedtls v3.5.1. Signed-off-by: Carlos Gil --- lib/mbedtls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mbedtls b/lib/mbedtls index 981743de6fcdb..edb8fec988208 160000 --- a/lib/mbedtls +++ b/lib/mbedtls @@ -1 +1 @@ -Subproject commit 981743de6fcdbe672e482b6fd724d31d0a0d2476 +Subproject commit edb8fec9882084344a314368ac7fd957a187519c From 92136cbe674a7f7adfb4b9a8e4622692c7ced9a1 Mon Sep 17 00:00:00 2001 From: Carlosgg Date: Sat, 30 Jul 2022 17:01:56 +0100 Subject: [PATCH 079/408] lib/mbedtls_errors: Update error list for latest mbedtls. Running `./do-mp.sh` now generates this `mp_mbedtls_errors.c` file. The `esp32_mbedtls_errors.c` file is already up-to-date. Signed-off-by: Carlos Gil --- lib/mbedtls_errors/mp_mbedtls_errors.c | 187 ++++++++----------------- 1 file changed, 60 insertions(+), 127 deletions(-) diff --git a/lib/mbedtls_errors/mp_mbedtls_errors.c b/lib/mbedtls_errors/mp_mbedtls_errors.c index fabbb15e4eb6f..0b16ba74246e6 100644 --- a/lib/mbedtls_errors/mp_mbedtls_errors.c +++ b/lib/mbedtls_errors/mp_mbedtls_errors.c @@ -45,10 +45,6 @@ #include "mbedtls/aes.h" #endif -#if defined(MBEDTLS_ARC4_C) -#include "mbedtls/arc4.h" -#endif - #if defined(MBEDTLS_ARIA_C) #include "mbedtls/aria.h" #endif @@ -65,10 +61,6 @@ #include "mbedtls/bignum.h" #endif -#if defined(MBEDTLS_BLOWFISH_C) -#include "mbedtls/blowfish.h" -#endif - #if defined(MBEDTLS_CAMELLIA_C) #include "mbedtls/camellia.h" #endif @@ -89,10 +81,6 @@ #include "mbedtls/cipher.h" #endif -#if defined(MBEDTLS_CMAC_C) -#include "mbedtls/cmac.h" -#endif - #if defined(MBEDTLS_CTR_DRBG_C) #include "mbedtls/ctr_drbg.h" #endif @@ -117,6 +105,10 @@ #include "mbedtls/error.h" #endif +#if defined(MBEDTLS_PLATFORM_C) +#include "mbedtls/platform.h" +#endif + #if defined(MBEDTLS_GCM_C) #include "mbedtls/gcm.h" #endif @@ -129,20 +121,12 @@ #include "mbedtls/hmac_drbg.h" #endif -#if defined(MBEDTLS_MD_C) -#include "mbedtls/md.h" +#if defined(MBEDTLS_LMS_C) +#include "mbedtls/lms.h" #endif -#if defined(MBEDTLS_MD2_C) -#include "mbedtls/md2.h" -#endif - -#if defined(MBEDTLS_MD4_C) -#include "mbedtls/md4.h" -#endif - -#if defined(MBEDTLS_MD5_C) -#include "mbedtls/md5.h" +#if defined(MBEDTLS_MD_C) +#include "mbedtls/md.h" #endif #if defined(MBEDTLS_NET_C) @@ -153,10 +137,6 @@ #include "mbedtls/oid.h" #endif -#if defined(MBEDTLS_PADLOCK_C) -#include "mbedtls/padlock.h" -#endif - #if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C) #include "mbedtls/pem.h" #endif @@ -173,18 +153,14 @@ #include "mbedtls/pkcs5.h" #endif -#if defined(MBEDTLS_PLATFORM_C) -#include "mbedtls/platform.h" +#if defined(MBEDTLS_PKCS7_C) +#include "mbedtls/pkcs7.h" #endif #if defined(MBEDTLS_POLY1305_C) #include "mbedtls/poly1305.h" #endif -#if defined(MBEDTLS_RIPEMD160_C) -#include "mbedtls/ripemd160.h" -#endif - #if defined(MBEDTLS_RSA_C) #include "mbedtls/rsa.h" #endif @@ -197,6 +173,10 @@ #include "mbedtls/sha256.h" #endif +#if defined(MBEDTLS_SHA3_C) +#include "mbedtls/sha3.h" +#endif + #if defined(MBEDTLS_SHA512_C) #include "mbedtls/sha512.h" #endif @@ -213,10 +193,6 @@ #include "mbedtls/x509.h" #endif -#if defined(MBEDTLS_XTEA_C) -#include "mbedtls/xtea.h" -#endif - // Error code table type struct ssl_errs { @@ -235,7 +211,6 @@ static const struct ssl_errs mbedtls_high_level_error_tab[] = { { -(MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED), "CIPHER_FULL_BLOCK_EXPECTED" }, { -(MBEDTLS_ERR_CIPHER_AUTH_FAILED), "CIPHER_AUTH_FAILED" }, { -(MBEDTLS_ERR_CIPHER_INVALID_CONTEXT), "CIPHER_INVALID_CONTEXT" }, - { -(MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED), "CIPHER_HW_ACCEL_FAILED" }, #endif /* MBEDTLS_CIPHER_C */ #if defined(MBEDTLS_DHM_C) @@ -248,7 +223,6 @@ static const struct ssl_errs mbedtls_high_level_error_tab[] = { { -(MBEDTLS_ERR_DHM_INVALID_FORMAT), "DHM_INVALID_FORMAT" }, { -(MBEDTLS_ERR_DHM_ALLOC_FAILED), "DHM_ALLOC_FAILED" }, { -(MBEDTLS_ERR_DHM_FILE_IO_ERROR), "DHM_FILE_IO_ERROR" }, - { -(MBEDTLS_ERR_DHM_HW_ACCEL_FAILED), "DHM_HW_ACCEL_FAILED" }, { -(MBEDTLS_ERR_DHM_SET_GROUP_FAILED), "DHM_SET_GROUP_FAILED" }, #endif /* MBEDTLS_DHM_C */ @@ -261,7 +235,6 @@ static const struct ssl_errs mbedtls_high_level_error_tab[] = { { -(MBEDTLS_ERR_ECP_RANDOM_FAILED), "ECP_RANDOM_FAILED" }, { -(MBEDTLS_ERR_ECP_INVALID_KEY), "ECP_INVALID_KEY" }, { -(MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH), "ECP_SIG_LEN_MISMATCH" }, - { -(MBEDTLS_ERR_ECP_HW_ACCEL_FAILED), "ECP_HW_ACCEL_FAILED" }, { -(MBEDTLS_ERR_ECP_IN_PROGRESS), "ECP_IN_PROGRESS" }, #endif /* MBEDTLS_ECP_C */ @@ -270,7 +243,6 @@ static const struct ssl_errs mbedtls_high_level_error_tab[] = { { -(MBEDTLS_ERR_MD_BAD_INPUT_DATA), "MD_BAD_INPUT_DATA" }, { -(MBEDTLS_ERR_MD_ALLOC_FAILED), "MD_ALLOC_FAILED" }, { -(MBEDTLS_ERR_MD_FILE_IO_ERROR), "MD_FILE_IO_ERROR" }, - { -(MBEDTLS_ERR_MD_HW_ACCEL_FAILED), "MD_HW_ACCEL_FAILED" }, #endif /* MBEDTLS_MD_C */ #if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C) @@ -300,7 +272,7 @@ static const struct ssl_errs mbedtls_high_level_error_tab[] = { { -(MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE), "PK_UNKNOWN_NAMED_CURVE" }, { -(MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE), "PK_FEATURE_UNAVAILABLE" }, { -(MBEDTLS_ERR_PK_SIG_LEN_MISMATCH), "PK_SIG_LEN_MISMATCH" }, - { -(MBEDTLS_ERR_PK_HW_ACCEL_FAILED), "PK_HW_ACCEL_FAILED" }, + { -(MBEDTLS_ERR_PK_BUFFER_TOO_SMALL), "PK_BUFFER_TOO_SMALL" }, #endif /* MBEDTLS_PK_C */ #if defined(MBEDTLS_PKCS12_C) @@ -317,6 +289,21 @@ static const struct ssl_errs mbedtls_high_level_error_tab[] = { { -(MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH), "PKCS5_PASSWORD_MISMATCH" }, #endif /* MBEDTLS_PKCS5_C */ +#if defined(MBEDTLS_PKCS7_C) + { -(MBEDTLS_ERR_PKCS7_INVALID_FORMAT), "PKCS7_INVALID_FORMAT" }, + { -(MBEDTLS_ERR_PKCS7_FEATURE_UNAVAILABLE), "PKCS7_FEATURE_UNAVAILABLE" }, + { -(MBEDTLS_ERR_PKCS7_INVALID_VERSION), "PKCS7_INVALID_VERSION" }, + { -(MBEDTLS_ERR_PKCS7_INVALID_CONTENT_INFO), "PKCS7_INVALID_CONTENT_INFO" }, + { -(MBEDTLS_ERR_PKCS7_INVALID_ALG), "PKCS7_INVALID_ALG" }, + { -(MBEDTLS_ERR_PKCS7_INVALID_CERT), "PKCS7_INVALID_CERT" }, + { -(MBEDTLS_ERR_PKCS7_INVALID_SIGNATURE), "PKCS7_INVALID_SIGNATURE" }, + { -(MBEDTLS_ERR_PKCS7_INVALID_SIGNER_INFO), "PKCS7_INVALID_SIGNER_INFO" }, + { -(MBEDTLS_ERR_PKCS7_BAD_INPUT_DATA), "PKCS7_BAD_INPUT_DATA" }, + { -(MBEDTLS_ERR_PKCS7_ALLOC_FAILED), "PKCS7_ALLOC_FAILED" }, + { -(MBEDTLS_ERR_PKCS7_VERIFY_FAIL), "PKCS7_VERIFY_FAIL" }, + { -(MBEDTLS_ERR_PKCS7_CERT_DATE_INVALID), "PKCS7_CERT_DATE_INVALID" }, +#endif /* MBEDTLS_PKCS7_C */ + #if defined(MBEDTLS_RSA_C) { -(MBEDTLS_ERR_RSA_BAD_INPUT_DATA), "RSA_BAD_INPUT_DATA" }, { -(MBEDTLS_ERR_RSA_INVALID_PADDING), "RSA_INVALID_PADDING" }, @@ -327,45 +314,35 @@ static const struct ssl_errs mbedtls_high_level_error_tab[] = { { -(MBEDTLS_ERR_RSA_VERIFY_FAILED), "RSA_VERIFY_FAILED" }, { -(MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE), "RSA_OUTPUT_TOO_LARGE" }, { -(MBEDTLS_ERR_RSA_RNG_FAILED), "RSA_RNG_FAILED" }, - { -(MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION), "RSA_UNSUPPORTED_OPERATION" }, - { -(MBEDTLS_ERR_RSA_HW_ACCEL_FAILED), "RSA_HW_ACCEL_FAILED" }, #endif /* MBEDTLS_RSA_C */ #if defined(MBEDTLS_SSL_TLS_C) + { -(MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS), "SSL_CRYPTO_IN_PROGRESS" }, { -(MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE), "SSL_FEATURE_UNAVAILABLE" }, { -(MBEDTLS_ERR_SSL_BAD_INPUT_DATA), "SSL_BAD_INPUT_DATA" }, { -(MBEDTLS_ERR_SSL_INVALID_MAC), "SSL_INVALID_MAC" }, { -(MBEDTLS_ERR_SSL_INVALID_RECORD), "SSL_INVALID_RECORD" }, { -(MBEDTLS_ERR_SSL_CONN_EOF), "SSL_CONN_EOF" }, - { -(MBEDTLS_ERR_SSL_UNKNOWN_CIPHER), "SSL_UNKNOWN_CIPHER" }, - { -(MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN), "SSL_NO_CIPHER_CHOSEN" }, + { -(MBEDTLS_ERR_SSL_DECODE_ERROR), "SSL_DECODE_ERROR" }, { -(MBEDTLS_ERR_SSL_NO_RNG), "SSL_NO_RNG" }, { -(MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE), "SSL_NO_CLIENT_CERTIFICATE" }, - { -(MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE), "SSL_CERTIFICATE_TOO_LARGE" }, - { -(MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED), "SSL_CERTIFICATE_REQUIRED" }, + { -(MBEDTLS_ERR_SSL_UNSUPPORTED_EXTENSION), "SSL_UNSUPPORTED_EXTENSION" }, + { -(MBEDTLS_ERR_SSL_NO_APPLICATION_PROTOCOL), "SSL_NO_APPLICATION_PROTOCOL" }, { -(MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED), "SSL_PRIVATE_KEY_REQUIRED" }, { -(MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED), "SSL_CA_CHAIN_REQUIRED" }, { -(MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE), "SSL_UNEXPECTED_MESSAGE" }, - { -(MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED), "SSL_PEER_VERIFY_FAILED" }, + { -(MBEDTLS_ERR_SSL_UNRECOGNIZED_NAME), "SSL_UNRECOGNIZED_NAME" }, { -(MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY), "SSL_PEER_CLOSE_NOTIFY" }, - { -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO), "SSL_BAD_HS_CLIENT_HELLO" }, - { -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO), "SSL_BAD_HS_SERVER_HELLO" }, - { -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE), "SSL_BAD_HS_CERTIFICATE" }, - { -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST), "SSL_BAD_HS_CERTIFICATE_REQUEST" }, - { -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE), "SSL_BAD_HS_SERVER_KEY_EXCHANGE" }, - { -(MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE), "SSL_BAD_HS_SERVER_HELLO_DONE" }, - { -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE), "SSL_BAD_HS_CLIENT_KEY_EXCHANGE" }, - { -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP), "SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP" }, - { -(MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS), "SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS" }, - { -(MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY), "SSL_BAD_HS_CERTIFICATE_VERIFY" }, - { -(MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC), "SSL_BAD_HS_CHANGE_CIPHER_SPEC" }, - { -(MBEDTLS_ERR_SSL_BAD_HS_FINISHED), "SSL_BAD_HS_FINISHED" }, + { -(MBEDTLS_ERR_SSL_BAD_CERTIFICATE), "SSL_BAD_CERTIFICATE" }, + { -(MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET), "SSL_RECEIVED_NEW_SESSION_TICKET" }, + { -(MBEDTLS_ERR_SSL_CANNOT_READ_EARLY_DATA), "SSL_CANNOT_READ_EARLY_DATA" }, + { -(MBEDTLS_ERR_SSL_CANNOT_WRITE_EARLY_DATA), "SSL_CANNOT_WRITE_EARLY_DATA" }, + { -(MBEDTLS_ERR_SSL_CACHE_ENTRY_NOT_FOUND), "SSL_CACHE_ENTRY_NOT_FOUND" }, { -(MBEDTLS_ERR_SSL_ALLOC_FAILED), "SSL_ALLOC_FAILED" }, { -(MBEDTLS_ERR_SSL_HW_ACCEL_FAILED), "SSL_HW_ACCEL_FAILED" }, { -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH), "SSL_HW_ACCEL_FALLTHROUGH" }, - { -(MBEDTLS_ERR_SSL_COMPRESSION_FAILED), "SSL_COMPRESSION_FAILED" }, - { -(MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION), "SSL_BAD_HS_PROTOCOL_VERSION" }, - { -(MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET), "SSL_BAD_HS_NEW_SESSION_TICKET" }, + { -(MBEDTLS_ERR_SSL_BAD_PROTOCOL_VERSION), "SSL_BAD_PROTOCOL_VERSION" }, + { -(MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE), "SSL_HANDSHAKE_FAILURE" }, { -(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED), "SSL_SESSION_TICKET_EXPIRED" }, { -(MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH), "SSL_PK_TYPE_MISMATCH" }, { -(MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY), "SSL_UNKNOWN_IDENTITY" }, @@ -374,20 +351,18 @@ static const struct ssl_errs mbedtls_high_level_error_tab[] = { { -(MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO), "SSL_WAITING_SERVER_HELLO_RENEGO" }, { -(MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED), "SSL_HELLO_VERIFY_REQUIRED" }, { -(MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL), "SSL_BUFFER_TOO_SMALL" }, - { -(MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE), "SSL_NO_USABLE_CIPHERSUITE" }, { -(MBEDTLS_ERR_SSL_WANT_READ), "SSL_WANT_READ" }, { -(MBEDTLS_ERR_SSL_WANT_WRITE), "SSL_WANT_WRITE" }, { -(MBEDTLS_ERR_SSL_TIMEOUT), "SSL_TIMEOUT" }, { -(MBEDTLS_ERR_SSL_CLIENT_RECONNECT), "SSL_CLIENT_RECONNECT" }, { -(MBEDTLS_ERR_SSL_UNEXPECTED_RECORD), "SSL_UNEXPECTED_RECORD" }, { -(MBEDTLS_ERR_SSL_NON_FATAL), "SSL_NON_FATAL" }, - { -(MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH), "SSL_INVALID_VERIFY_HASH" }, + { -(MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER), "SSL_ILLEGAL_PARAMETER" }, { -(MBEDTLS_ERR_SSL_CONTINUE_PROCESSING), "SSL_CONTINUE_PROCESSING" }, { -(MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS), "SSL_ASYNC_IN_PROGRESS" }, { -(MBEDTLS_ERR_SSL_EARLY_MESSAGE), "SSL_EARLY_MESSAGE" }, { -(MBEDTLS_ERR_SSL_UNEXPECTED_CID), "SSL_UNEXPECTED_CID" }, { -(MBEDTLS_ERR_SSL_VERSION_MISMATCH), "SSL_VERSION_MISMATCH" }, - { -(MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS), "SSL_CRYPTO_IN_PROGRESS" }, { -(MBEDTLS_ERR_SSL_BAD_CONFIG), "SSL_BAD_CONFIG" }, #endif /* MBEDTLS_SSL_TLS_C */ @@ -424,19 +399,11 @@ static const struct ssl_errs mbedtls_low_level_error_tab[] = { { -(MBEDTLS_ERR_AES_INVALID_KEY_LENGTH), "AES_INVALID_KEY_LENGTH" }, { -(MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH), "AES_INVALID_INPUT_LENGTH" }, { -(MBEDTLS_ERR_AES_BAD_INPUT_DATA), "AES_BAD_INPUT_DATA" }, - { -(MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE), "AES_FEATURE_UNAVAILABLE" }, - { -(MBEDTLS_ERR_AES_HW_ACCEL_FAILED), "AES_HW_ACCEL_FAILED" }, #endif /* MBEDTLS_AES_C */ -#if defined(MBEDTLS_ARC4_C) - { -(MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED), "ARC4_HW_ACCEL_FAILED" }, -#endif /* MBEDTLS_ARC4_C */ - #if defined(MBEDTLS_ARIA_C) { -(MBEDTLS_ERR_ARIA_BAD_INPUT_DATA), "ARIA_BAD_INPUT_DATA" }, { -(MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH), "ARIA_INVALID_INPUT_LENGTH" }, - { -(MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE), "ARIA_FEATURE_UNAVAILABLE" }, - { -(MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED), "ARIA_HW_ACCEL_FAILED" }, #endif /* MBEDTLS_ARIA_C */ #if defined(MBEDTLS_ASN1_PARSE_C) @@ -465,28 +432,18 @@ static const struct ssl_errs mbedtls_low_level_error_tab[] = { { -(MBEDTLS_ERR_MPI_ALLOC_FAILED), "MPI_ALLOC_FAILED" }, #endif /* MBEDTLS_BIGNUM_C */ -#if defined(MBEDTLS_BLOWFISH_C) - { -(MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA), "BLOWFISH_BAD_INPUT_DATA" }, - { -(MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH), "BLOWFISH_INVALID_INPUT_LENGTH" }, - { -(MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED), "BLOWFISH_HW_ACCEL_FAILED" }, -#endif /* MBEDTLS_BLOWFISH_C */ - #if defined(MBEDTLS_CAMELLIA_C) { -(MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA), "CAMELLIA_BAD_INPUT_DATA" }, { -(MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH), "CAMELLIA_INVALID_INPUT_LENGTH" }, - { -(MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED), "CAMELLIA_HW_ACCEL_FAILED" }, #endif /* MBEDTLS_CAMELLIA_C */ #if defined(MBEDTLS_CCM_C) { -(MBEDTLS_ERR_CCM_BAD_INPUT), "CCM_BAD_INPUT" }, { -(MBEDTLS_ERR_CCM_AUTH_FAILED), "CCM_AUTH_FAILED" }, - { -(MBEDTLS_ERR_CCM_HW_ACCEL_FAILED), "CCM_HW_ACCEL_FAILED" }, #endif /* MBEDTLS_CCM_C */ #if defined(MBEDTLS_CHACHA20_C) { -(MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA), "CHACHA20_BAD_INPUT_DATA" }, - { -(MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE), "CHACHA20_FEATURE_UNAVAILABLE" }, - { -(MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED), "CHACHA20_HW_ACCEL_FAILED" }, #endif /* MBEDTLS_CHACHA20_C */ #if defined(MBEDTLS_CHACHAPOLY_C) @@ -494,10 +451,6 @@ static const struct ssl_errs mbedtls_low_level_error_tab[] = { { -(MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED), "CHACHAPOLY_AUTH_FAILED" }, #endif /* MBEDTLS_CHACHAPOLY_C */ -#if defined(MBEDTLS_CMAC_C) - { -(MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED), "CMAC_HW_ACCEL_FAILED" }, -#endif /* MBEDTLS_CMAC_C */ - #if defined(MBEDTLS_CTR_DRBG_C) { -(MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED), "CTR_DRBG_ENTROPY_SOURCE_FAILED" }, { -(MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG), "CTR_DRBG_REQUEST_TOO_BIG" }, @@ -507,7 +460,6 @@ static const struct ssl_errs mbedtls_low_level_error_tab[] = { #if defined(MBEDTLS_DES_C) { -(MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH), "DES_INVALID_INPUT_LENGTH" }, - { -(MBEDTLS_ERR_DES_HW_ACCEL_FAILED), "DES_HW_ACCEL_FAILED" }, #endif /* MBEDTLS_DES_C */ #if defined(MBEDTLS_ENTROPY_C) @@ -523,10 +475,15 @@ static const struct ssl_errs mbedtls_low_level_error_tab[] = { { -(MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED), "ERROR_CORRUPTION_DETECTED" }, #endif /* MBEDTLS_ERROR_C */ +#if defined(MBEDTLS_PLATFORM_C) + { -(MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED), "PLATFORM_HW_ACCEL_FAILED" }, + { -(MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED), "PLATFORM_FEATURE_UNSUPPORTED" }, +#endif /* MBEDTLS_PLATFORM_C */ + #if defined(MBEDTLS_GCM_C) { -(MBEDTLS_ERR_GCM_AUTH_FAILED), "GCM_AUTH_FAILED" }, - { -(MBEDTLS_ERR_GCM_HW_ACCEL_FAILED), "GCM_HW_ACCEL_FAILED" }, { -(MBEDTLS_ERR_GCM_BAD_INPUT), "GCM_BAD_INPUT" }, + { -(MBEDTLS_ERR_GCM_BUFFER_TOO_SMALL), "GCM_BUFFER_TOO_SMALL" }, #endif /* MBEDTLS_GCM_C */ #if defined(MBEDTLS_HKDF_C) @@ -540,17 +497,13 @@ static const struct ssl_errs mbedtls_low_level_error_tab[] = { { -(MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED), "HMAC_DRBG_ENTROPY_SOURCE_FAILED" }, #endif /* MBEDTLS_HMAC_DRBG_C */ -#if defined(MBEDTLS_MD2_C) - { -(MBEDTLS_ERR_MD2_HW_ACCEL_FAILED), "MD2_HW_ACCEL_FAILED" }, -#endif /* MBEDTLS_MD2_C */ - -#if defined(MBEDTLS_MD4_C) - { -(MBEDTLS_ERR_MD4_HW_ACCEL_FAILED), "MD4_HW_ACCEL_FAILED" }, -#endif /* MBEDTLS_MD4_C */ - -#if defined(MBEDTLS_MD5_C) - { -(MBEDTLS_ERR_MD5_HW_ACCEL_FAILED), "MD5_HW_ACCEL_FAILED" }, -#endif /* MBEDTLS_MD5_C */ +#if defined(MBEDTLS_LMS_C) + { -(MBEDTLS_ERR_LMS_BAD_INPUT_DATA), "LMS_BAD_INPUT_DATA" }, + { -(MBEDTLS_ERR_LMS_OUT_OF_PRIVATE_KEYS), "LMS_OUT_OF_PRIVATE_KEYS" }, + { -(MBEDTLS_ERR_LMS_VERIFY_FAILED), "LMS_VERIFY_FAILED" }, + { -(MBEDTLS_ERR_LMS_ALLOC_FAILED), "LMS_ALLOC_FAILED" }, + { -(MBEDTLS_ERR_LMS_BUFFER_TOO_SMALL), "LMS_BUFFER_TOO_SMALL" }, +#endif /* MBEDTLS_LMS_C */ #if defined(MBEDTLS_NET_C) { -(MBEDTLS_ERR_NET_SOCKET_FAILED), "NET_SOCKET_FAILED" }, @@ -573,50 +526,30 @@ static const struct ssl_errs mbedtls_low_level_error_tab[] = { { -(MBEDTLS_ERR_OID_BUF_TOO_SMALL), "OID_BUF_TOO_SMALL" }, #endif /* MBEDTLS_OID_C */ -#if defined(MBEDTLS_PADLOCK_C) - { -(MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED), "PADLOCK_DATA_MISALIGNED" }, -#endif /* MBEDTLS_PADLOCK_C */ - -#if defined(MBEDTLS_PLATFORM_C) - { -(MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED), "PLATFORM_HW_ACCEL_FAILED" }, - { -(MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED), "PLATFORM_FEATURE_UNSUPPORTED" }, -#endif /* MBEDTLS_PLATFORM_C */ - #if defined(MBEDTLS_POLY1305_C) { -(MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA), "POLY1305_BAD_INPUT_DATA" }, - { -(MBEDTLS_ERR_POLY1305_FEATURE_UNAVAILABLE), "POLY1305_FEATURE_UNAVAILABLE" }, - { -(MBEDTLS_ERR_POLY1305_HW_ACCEL_FAILED), "POLY1305_HW_ACCEL_FAILED" }, #endif /* MBEDTLS_POLY1305_C */ -#if defined(MBEDTLS_RIPEMD160_C) - { -(MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED), "RIPEMD160_HW_ACCEL_FAILED" }, -#endif /* MBEDTLS_RIPEMD160_C */ - #if defined(MBEDTLS_SHA1_C) - { -(MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED), "SHA1_HW_ACCEL_FAILED" }, { -(MBEDTLS_ERR_SHA1_BAD_INPUT_DATA), "SHA1_BAD_INPUT_DATA" }, #endif /* MBEDTLS_SHA1_C */ #if defined(MBEDTLS_SHA256_C) - { -(MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED), "SHA256_HW_ACCEL_FAILED" }, { -(MBEDTLS_ERR_SHA256_BAD_INPUT_DATA), "SHA256_BAD_INPUT_DATA" }, #endif /* MBEDTLS_SHA256_C */ +#if defined(MBEDTLS_SHA3_C) + { -(MBEDTLS_ERR_SHA3_BAD_INPUT_DATA), "SHA3_BAD_INPUT_DATA" }, +#endif /* MBEDTLS_SHA3_C */ + #if defined(MBEDTLS_SHA512_C) - { -(MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED), "SHA512_HW_ACCEL_FAILED" }, { -(MBEDTLS_ERR_SHA512_BAD_INPUT_DATA), "SHA512_BAD_INPUT_DATA" }, #endif /* MBEDTLS_SHA512_C */ #if defined(MBEDTLS_THREADING_C) - { -(MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE), "THREADING_FEATURE_UNAVAILABLE" }, { -(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA), "THREADING_BAD_INPUT_DATA" }, { -(MBEDTLS_ERR_THREADING_MUTEX_ERROR), "THREADING_MUTEX_ERROR" }, #endif /* MBEDTLS_THREADING_C */ - -#if defined(MBEDTLS_XTEA_C) - { -(MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH), "XTEA_INVALID_INPUT_LENGTH" }, - { -(MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED), "XTEA_HW_ACCEL_FAILED" }, -#endif /* MBEDTLS_XTEA_C */ // END generated code }; From f3d1495fd3da2c737a043cfc65d5a4f5c6155ad5 Mon Sep 17 00:00:00 2001 From: Carlosgg Date: Sat, 30 Jul 2022 17:01:56 +0100 Subject: [PATCH 080/408] all: Update bindings, ports and tests for mbedtls v3.5.1. Changes include: - Some mbedtls source files renamed or deprecated. - Our `mbedtls_config.h` files are renamed to `mbedtls_config_port.h`, so they don't clash with mbedtls's new default configuration file named `mbedtls_config.h`. - MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE is deprecated. - MBEDTLS_HAVE_TIME now requires an `mbedtls_ms_time` function to be defined but it's only used for TLSv1.3 (currently not enabled in MicroPython so there is a lazy implementation, i.e. seconds * 1000). - `tests/multi_net/ssl_data.py` is removed (due to deprecation of MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE), there are the existing `ssl_cert_rsa.py` and `sslcontext_server_client.py` tests which do very similar, simple SSL data transfer. - Tests now use an EC key by default (they are smaller and faster), and the RSA key has been regenerated due to the old PKCS encoding used by openssl rsa command, see https://stackoverflow.com/questions/40822328/openssl-rsa-key-pem-and-der-conversion-does-not-match (and `tests/README.md` has been updated accordingly). Signed-off-by: Carlos Gil --- extmod/extmod.cmake | 25 +++---- extmod/extmod.mk | 27 +++---- extmod/mbedtls/mbedtls_config_common.h | 11 ++- ...mbedtls_config.h => mbedtls_config_port.h} | 1 + ports/mimxrt/mbedtls/mbedtls_port.c | 10 ++- .../mbedtls_config_board.h | 2 +- ...mbedtls_config.h => mbedtls_config_port.h} | 1 + ports/renesas-ra/mbedtls/mbedtls_port.c | 10 ++- ...mbedtls_config.h => mbedtls_config_port.h} | 1 + ports/rp2/mbedtls/mbedtls_port.c | 9 ++- .../ARDUINO_GIGA/mbedtls_config_board.h | 2 +- .../mbedtls_config_board.h | 2 +- .../mbedtls_config_board.h | 2 +- ...mbedtls_config.h => mbedtls_config_port.h} | 1 + ports/stm32/mbedtls/mbedtls_port.c | 10 ++- ...mbedtls_config.h => mbedtls_config_port.h} | 1 - tests/README.md | 2 +- tests/multi_net/asyncio_tls_server_client.py | 4 +- ...o_tls_server_client_cert_required_error.py | 4 +- .../asyncio_tls_server_client_readline.py | 4 +- .../asyncio_tls_server_client_verify_error.py | 4 +- tests/multi_net/ec_cert.der | Bin 0 -> 471 bytes tests/multi_net/ec_key.der | Bin 0 -> 121 bytes tests/multi_net/expired_cert.der | Bin 1331 -> 471 bytes tests/multi_net/rsa_cert.der | Bin 867 -> 867 bytes tests/multi_net/rsa_key.der | Bin 1217 -> 1193 bytes tests/multi_net/ssl_cert_ec.py | 56 +++++++++++++++ .../{ssl_data.py.exp => ssl_cert_ec.py.exp} | 0 tests/multi_net/ssl_data.py | 67 ------------------ .../sslcontext_check_hostname_error.py | 4 +- tests/multi_net/sslcontext_getpeercert.py | 4 +- tests/multi_net/sslcontext_getpeercert.py.exp | 2 +- tests/multi_net/sslcontext_server_client.py | 4 +- .../sslcontext_server_client_ciphers.py | 8 +-- .../sslcontext_server_client_files.py | 4 +- tests/multi_net/sslcontext_verify_error.py | 4 +- .../multi_net/sslcontext_verify_time_error.py | 2 +- 37 files changed, 156 insertions(+), 132 deletions(-) rename ports/mimxrt/mbedtls/{mbedtls_config.h => mbedtls_config_port.h} (96%) rename ports/renesas-ra/mbedtls/{mbedtls_config.h => mbedtls_config_port.h} (96%) rename ports/rp2/mbedtls/{mbedtls_config.h => mbedtls_config_port.h} (97%) rename ports/stm32/mbedtls/{mbedtls_config.h => mbedtls_config_port.h} (96%) rename ports/unix/mbedtls/{mbedtls_config.h => mbedtls_config_port.h} (98%) create mode 100644 tests/multi_net/ec_cert.der create mode 100644 tests/multi_net/ec_key.der create mode 100644 tests/multi_net/ssl_cert_ec.py rename tests/multi_net/{ssl_data.py.exp => ssl_cert_ec.py.exp} (100%) delete mode 100644 tests/multi_net/ssl_data.py diff --git a/extmod/extmod.cmake b/extmod/extmod.cmake index ac10faa86541c..a55cd76f88bc9 100644 --- a/extmod/extmod.cmake +++ b/extmod/extmod.cmake @@ -174,20 +174,24 @@ if(MICROPY_SSL_MBEDTLS) ${MICROPY_DIR}/lib/mbedtls_errors/mp_mbedtls_errors.c ${MICROPY_LIB_MBEDTLS_DIR}/library/aes.c ${MICROPY_LIB_MBEDTLS_DIR}/library/aesni.c - ${MICROPY_LIB_MBEDTLS_DIR}/library/arc4.c ${MICROPY_LIB_MBEDTLS_DIR}/library/asn1parse.c ${MICROPY_LIB_MBEDTLS_DIR}/library/asn1write.c ${MICROPY_LIB_MBEDTLS_DIR}/library/base64.c + ${MICROPY_LIB_MBEDTLS_DIR}/library/bignum_core.c + ${MICROPY_LIB_MBEDTLS_DIR}/library/bignum_mod.c + ${MICROPY_LIB_MBEDTLS_DIR}/library/bignum_mod_raw.c ${MICROPY_LIB_MBEDTLS_DIR}/library/bignum.c - ${MICROPY_LIB_MBEDTLS_DIR}/library/blowfish.c ${MICROPY_LIB_MBEDTLS_DIR}/library/camellia.c ${MICROPY_LIB_MBEDTLS_DIR}/library/ccm.c - ${MICROPY_LIB_MBEDTLS_DIR}/library/certs.c ${MICROPY_LIB_MBEDTLS_DIR}/library/chacha20.c ${MICROPY_LIB_MBEDTLS_DIR}/library/chachapoly.c ${MICROPY_LIB_MBEDTLS_DIR}/library/cipher.c ${MICROPY_LIB_MBEDTLS_DIR}/library/cipher_wrap.c + ${MICROPY_LIB_MBEDTLS_DIR}/library/nist_kw.c + ${MICROPY_LIB_MBEDTLS_DIR}/library/aria.c ${MICROPY_LIB_MBEDTLS_DIR}/library/cmac.c + ${MICROPY_LIB_MBEDTLS_DIR}/library/mps_reader.c + ${MICROPY_LIB_MBEDTLS_DIR}/library/mps_trace.c ${MICROPY_LIB_MBEDTLS_DIR}/library/ctr_drbg.c ${MICROPY_LIB_MBEDTLS_DIR}/library/debug.c ${MICROPY_LIB_MBEDTLS_DIR}/library/des.c @@ -200,17 +204,13 @@ if(MICROPY_SSL_MBEDTLS) ${MICROPY_LIB_MBEDTLS_DIR}/library/entropy.c ${MICROPY_LIB_MBEDTLS_DIR}/library/entropy_poll.c ${MICROPY_LIB_MBEDTLS_DIR}/library/gcm.c - ${MICROPY_LIB_MBEDTLS_DIR}/library/havege.c ${MICROPY_LIB_MBEDTLS_DIR}/library/hmac_drbg.c - ${MICROPY_LIB_MBEDTLS_DIR}/library/md2.c - ${MICROPY_LIB_MBEDTLS_DIR}/library/md4.c ${MICROPY_LIB_MBEDTLS_DIR}/library/md5.c ${MICROPY_LIB_MBEDTLS_DIR}/library/md.c ${MICROPY_LIB_MBEDTLS_DIR}/library/oid.c ${MICROPY_LIB_MBEDTLS_DIR}/library/padlock.c ${MICROPY_LIB_MBEDTLS_DIR}/library/pem.c ${MICROPY_LIB_MBEDTLS_DIR}/library/pk.c - ${MICROPY_LIB_MBEDTLS_DIR}/library/pkcs11.c ${MICROPY_LIB_MBEDTLS_DIR}/library/pkcs12.c ${MICROPY_LIB_MBEDTLS_DIR}/library/pkcs5.c ${MICROPY_LIB_MBEDTLS_DIR}/library/pkparse.c @@ -221,15 +221,17 @@ if(MICROPY_SSL_MBEDTLS) ${MICROPY_LIB_MBEDTLS_DIR}/library/poly1305.c ${MICROPY_LIB_MBEDTLS_DIR}/library/ripemd160.c ${MICROPY_LIB_MBEDTLS_DIR}/library/rsa.c - ${MICROPY_LIB_MBEDTLS_DIR}/library/rsa_internal.c + ${MICROPY_LIB_MBEDTLS_DIR}/library/rsa_alt_helpers.c ${MICROPY_LIB_MBEDTLS_DIR}/library/sha1.c ${MICROPY_LIB_MBEDTLS_DIR}/library/sha256.c ${MICROPY_LIB_MBEDTLS_DIR}/library/sha512.c ${MICROPY_LIB_MBEDTLS_DIR}/library/ssl_cache.c ${MICROPY_LIB_MBEDTLS_DIR}/library/ssl_ciphersuites.c - ${MICROPY_LIB_MBEDTLS_DIR}/library/ssl_cli.c + ${MICROPY_LIB_MBEDTLS_DIR}/library/ssl_tls12_client.c + ${MICROPY_LIB_MBEDTLS_DIR}/library/ssl_tls12_server.c + ${MICROPY_LIB_MBEDTLS_DIR}/library/ssl_client.c ${MICROPY_LIB_MBEDTLS_DIR}/library/ssl_cookie.c - ${MICROPY_LIB_MBEDTLS_DIR}/library/ssl_srv.c + ${MICROPY_LIB_MBEDTLS_DIR}/library/ssl_debug_helpers_generated.c ${MICROPY_LIB_MBEDTLS_DIR}/library/ssl_msg.c ${MICROPY_LIB_MBEDTLS_DIR}/library/ssl_ticket.c ${MICROPY_LIB_MBEDTLS_DIR}/library/ssl_tls.c @@ -242,11 +244,10 @@ if(MICROPY_SSL_MBEDTLS) ${MICROPY_LIB_MBEDTLS_DIR}/library/x509_csr.c ${MICROPY_LIB_MBEDTLS_DIR}/library/x509write_crt.c ${MICROPY_LIB_MBEDTLS_DIR}/library/x509write_csr.c - ${MICROPY_LIB_MBEDTLS_DIR}/library/xtea.c ) if(NOT MBEDTLS_CONFIG_FILE) - set(MBEDTLS_CONFIG_FILE "${MICROPY_PORT_DIR}/mbedtls/mbedtls_config.h") + set(MBEDTLS_CONFIG_FILE "${MICROPY_PORT_DIR}/mbedtls/mbedtls_config_port.h") endif() target_compile_definitions(micropy_lib_mbedtls INTERFACE diff --git a/extmod/extmod.mk b/extmod/extmod.mk index 59e530d3476b0..fdaa3d930588c 100644 --- a/extmod/extmod.mk +++ b/extmod/extmod.mk @@ -231,7 +231,7 @@ SRC_THIRDPARTY_C += $(addprefix $(AXTLS_DIR)/,\ ) else ifeq ($(MICROPY_SSL_MBEDTLS),1) MBEDTLS_DIR = lib/mbedtls -MBEDTLS_CONFIG_FILE ?= \"mbedtls/mbedtls_config.h\" +MBEDTLS_CONFIG_FILE ?= \"mbedtls/mbedtls_config_port.h\" GIT_SUBMODULES += $(MBEDTLS_DIR) CFLAGS_EXTMOD += -DMBEDTLS_CONFIG_FILE=$(MBEDTLS_CONFIG_FILE) CFLAGS_EXTMOD += -DMICROPY_SSL_MBEDTLS=1 -I$(TOP)/$(MBEDTLS_DIR)/include @@ -239,20 +239,25 @@ SRC_THIRDPARTY_C += lib/mbedtls_errors/mp_mbedtls_errors.c SRC_THIRDPARTY_C += $(addprefix $(MBEDTLS_DIR)/library/,\ aes.c \ aesni.c \ - arc4.c \ asn1parse.c \ asn1write.c \ base64.c \ + bignum_core.c \ + bignum_mod.c \ + bignum_mod_raw.c \ bignum.c \ - blowfish.c \ camellia.c \ ccm.c \ - certs.c \ chacha20.c \ chachapoly.c \ cipher.c \ cipher_wrap.c \ + nist_kw.c \ + aria.c \ cmac.c \ + constant_time.c \ + mps_reader.c \ + mps_trace.c \ ctr_drbg.c \ debug.c \ des.c \ @@ -265,17 +270,13 @@ SRC_THIRDPARTY_C += $(addprefix $(MBEDTLS_DIR)/library/,\ entropy.c \ entropy_poll.c \ gcm.c \ - havege.c \ hmac_drbg.c \ - md2.c \ - md4.c \ md5.c \ md.c \ oid.c \ padlock.c \ pem.c \ pk.c \ - pkcs11.c \ pkcs12.c \ pkcs5.c \ pkparse.c \ @@ -286,20 +287,21 @@ SRC_THIRDPARTY_C += $(addprefix $(MBEDTLS_DIR)/library/,\ poly1305.c \ ripemd160.c \ rsa.c \ - rsa_internal.c \ + rsa_alt_helpers.c \ sha1.c \ sha256.c \ sha512.c \ ssl_cache.c \ ssl_ciphersuites.c \ - ssl_cli.c \ + ssl_client.c \ ssl_cookie.c \ - ssl_srv.c \ + ssl_debug_helpers_generated.c \ ssl_msg.c \ ssl_ticket.c \ ssl_tls.c \ + ssl_tls12_client.c \ + ssl_tls12_server.c \ timing.c \ - constant_time.c \ x509.c \ x509_create.c \ x509_crl.c \ @@ -307,7 +309,6 @@ SRC_THIRDPARTY_C += $(addprefix $(MBEDTLS_DIR)/library/,\ x509_csr.c \ x509write_crt.c \ x509write_csr.c \ - xtea.c \ ) endif endif diff --git a/extmod/mbedtls/mbedtls_config_common.h b/extmod/mbedtls/mbedtls_config_common.h index 95458f18daa31..db1562f279732 100644 --- a/extmod/mbedtls/mbedtls_config_common.h +++ b/extmod/mbedtls/mbedtls_config_common.h @@ -45,9 +45,9 @@ #define MBEDTLS_ECP_DP_SECP224K1_ENABLED #define MBEDTLS_ECP_DP_SECP256K1_ENABLED #define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED -// #define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED // enabling this currently breaks ssl_data.py test #define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED -#define MBEDTLS_NO_PLATFORM_ENTROPY +#define MBEDTLS_CAN_ECDH +#define MBEDTLS_PK_CAN_ECDSA_SIGN #define MBEDTLS_PKCS1_V15 #define MBEDTLS_SHA256_SMALLER #define MBEDTLS_SSL_PROTO_TLS1 @@ -81,12 +81,13 @@ #define MBEDTLS_PLATFORM_C #define MBEDTLS_RSA_C #define MBEDTLS_SHA1_C +#define MBEDTLS_SHA224_C #define MBEDTLS_SHA256_C +#define MBEDTLS_SHA384_C #define MBEDTLS_SHA512_C #define MBEDTLS_SSL_CLI_C #define MBEDTLS_SSL_SRV_C #define MBEDTLS_SSL_TLS_C -#define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE #define MBEDTLS_X509_CRT_PARSE_C #define MBEDTLS_X509_USE_C @@ -97,6 +98,7 @@ #define MBEDTLS_PLATFORM_MEMORY #define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS #define MBEDTLS_ENTROPY_HARDWARE_ALT +#define MBEDTLS_NO_PLATFORM_ENTROPY // Bare-metal memory allocation hooks. #include @@ -109,7 +111,4 @@ void m_tracked_free(void *ptr); #endif -// Include mbedtls configuration checker. -#include "mbedtls/check_config.h" - #endif // MICROPY_INCLUDED_MBEDTLS_CONFIG_COMMON_H diff --git a/ports/mimxrt/mbedtls/mbedtls_config.h b/ports/mimxrt/mbedtls/mbedtls_config_port.h similarity index 96% rename from ports/mimxrt/mbedtls/mbedtls_config.h rename to ports/mimxrt/mbedtls/mbedtls_config_port.h index f264ed4ad2eb0..414f30527852a 100644 --- a/ports/mimxrt/mbedtls/mbedtls_config.h +++ b/ports/mimxrt/mbedtls/mbedtls_config_port.h @@ -30,6 +30,7 @@ #include extern time_t mimxrt_rtctime_seconds(time_t *timer); #define MBEDTLS_PLATFORM_TIME_MACRO mimxrt_rtctime_seconds +#define MBEDTLS_PLATFORM_MS_TIME_ALT mbedtls_ms_time // Set MicroPython-specific options. #define MICROPY_MBEDTLS_CONFIG_BARE_METAL (1) diff --git a/ports/mimxrt/mbedtls/mbedtls_port.c b/ports/mimxrt/mbedtls/mbedtls_port.c index 044de317f5260..230e264bf9806 100644 --- a/ports/mimxrt/mbedtls/mbedtls_port.c +++ b/ports/mimxrt/mbedtls/mbedtls_port.c @@ -28,10 +28,11 @@ #ifdef MICROPY_SSL_MBEDTLS -#include "mbedtls_config.h" +#include "mbedtls_config_port.h" #if defined(MBEDTLS_HAVE_TIME) || defined(MBEDTLS_HAVE_TIME_DATE) #include "fsl_snvs_lp.h" #include "shared/timeutils/timeutils.h" +#include "mbedtls/platform_time.h" #endif void trng_random_data(unsigned char *output, size_t len); @@ -52,6 +53,13 @@ time_t mimxrt_rtctime_seconds(time_t *timer) { SNVS_LP_SRTC_GetDatetime(SNVS, &date); return timeutils_seconds_since_epoch(date.year, date.month, date.day, date.hour, date.minute, date.second); } + +mbedtls_ms_time_t mbedtls_ms_time(void) { + time_t *tv = NULL; + mbedtls_ms_time_t current_ms; + current_ms = mimxrt_rtctime_seconds(tv) * 1000; + return current_ms; +} #endif #if defined(MBEDTLS_HAVE_TIME_DATE) diff --git a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/mbedtls_config_board.h b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/mbedtls_config_board.h index 63c1b284fb6be..ef264a46b4052 100644 --- a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/mbedtls_config_board.h +++ b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/mbedtls_config_board.h @@ -3,6 +3,6 @@ #define MBEDTLS_ECP_NIST_OPTIM -#include "ports/renesas-ra/mbedtls/mbedtls_config.h" +#include "ports/renesas-ra/mbedtls/mbedtls_config_port.h" #endif /* MICROPY_INCLUDED_MBEDTLS_CONFIG_BOARD_H */ diff --git a/ports/renesas-ra/mbedtls/mbedtls_config.h b/ports/renesas-ra/mbedtls/mbedtls_config_port.h similarity index 96% rename from ports/renesas-ra/mbedtls/mbedtls_config.h rename to ports/renesas-ra/mbedtls/mbedtls_config_port.h index f036f536c2ad3..5660566ffff4e 100644 --- a/ports/renesas-ra/mbedtls/mbedtls_config.h +++ b/ports/renesas-ra/mbedtls/mbedtls_config_port.h @@ -30,6 +30,7 @@ #include extern time_t ra_rtctime_seconds(time_t *timer); #define MBEDTLS_PLATFORM_TIME_MACRO ra_rtctime_seconds +#define MBEDTLS_PLATFORM_MS_TIME_ALT mbedtls_ms_time // Set MicroPython-specific options. #define MICROPY_MBEDTLS_CONFIG_BARE_METAL (1) diff --git a/ports/renesas-ra/mbedtls/mbedtls_port.c b/ports/renesas-ra/mbedtls/mbedtls_port.c index 10c89bbcf0f5a..feeefa9c04561 100644 --- a/ports/renesas-ra/mbedtls/mbedtls_port.c +++ b/ports/renesas-ra/mbedtls/mbedtls_port.c @@ -25,11 +25,12 @@ */ #include "rng.h" -#include "mbedtls_config.h" +#include "mbedtls_config_port.h" #if defined(MBEDTLS_HAVE_TIME) || defined(MBEDTLS_HAVE_TIME_DATE) #include "rtc.h" #include "shared/timeutils/timeutils.h" +#include "mbedtls/platform_time.h" #endif int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len, size_t *olen) { @@ -57,6 +58,13 @@ time_t ra_rtctime_seconds(time_t *timer) { rtc_get_date(&date); return timeutils_seconds_since_epoch(2000 + date.Year, date.Month, date.Date, time.Hours, time.Minutes, time.Seconds); } + +mbedtls_ms_time_t mbedtls_ms_time(void) { + time_t *tv = NULL; + mbedtls_ms_time_t current_ms; + current_ms = ra_rtctime_seconds(tv) * 1000; + return current_ms; +} #endif #if defined(MBEDTLS_HAVE_TIME_DATE) diff --git a/ports/rp2/mbedtls/mbedtls_config.h b/ports/rp2/mbedtls/mbedtls_config_port.h similarity index 97% rename from ports/rp2/mbedtls/mbedtls_config.h rename to ports/rp2/mbedtls/mbedtls_config_port.h index 81be6c111b8dd..4e4c6e263fa59 100644 --- a/ports/rp2/mbedtls/mbedtls_config.h +++ b/ports/rp2/mbedtls/mbedtls_config_port.h @@ -37,6 +37,7 @@ #include time_t rp2_rtctime_seconds(time_t *timer); #define MBEDTLS_PLATFORM_TIME_MACRO rp2_rtctime_seconds +#define MBEDTLS_PLATFORM_MS_TIME_ALT mbedtls_ms_time // Set MicroPython-specific options. #define MICROPY_MBEDTLS_CONFIG_BARE_METAL (1) diff --git a/ports/rp2/mbedtls/mbedtls_port.c b/ports/rp2/mbedtls/mbedtls_port.c index 9067eca90ee55..9b1e0d20e1700 100644 --- a/ports/rp2/mbedtls/mbedtls_port.c +++ b/ports/rp2/mbedtls/mbedtls_port.c @@ -27,10 +27,11 @@ #ifdef MICROPY_SSL_MBEDTLS -#include "mbedtls_config.h" +#include "mbedtls_config_port.h" #include "hardware/rtc.h" #include "shared/timeutils/timeutils.h" +#include "mbedtls/platform_time.h" extern uint8_t rosc_random_u8(size_t cycles); @@ -48,4 +49,10 @@ time_t rp2_rtctime_seconds(time_t *timer) { return timeutils_seconds_since_epoch(t.year, t.month, t.day, t.hour, t.min, t.sec); } +mbedtls_ms_time_t mbedtls_ms_time(void) { + time_t *tv = NULL; + mbedtls_ms_time_t current_ms; + current_ms = rp2_rtctime_seconds(tv) * 1000; + return current_ms; +} #endif diff --git a/ports/stm32/boards/ARDUINO_GIGA/mbedtls_config_board.h b/ports/stm32/boards/ARDUINO_GIGA/mbedtls_config_board.h index 0e1703f1bf962..07aef794692ec 100644 --- a/ports/stm32/boards/ARDUINO_GIGA/mbedtls_config_board.h +++ b/ports/stm32/boards/ARDUINO_GIGA/mbedtls_config_board.h @@ -3,6 +3,6 @@ #define MBEDTLS_ECP_NIST_OPTIM -#include "ports/stm32/mbedtls/mbedtls_config.h" +#include "ports/stm32/mbedtls/mbedtls_config_port.h" #endif /* MICROPY_INCLUDED_MBEDTLS_CONFIG_BOARD_H */ diff --git a/ports/stm32/boards/ARDUINO_NICLA_VISION/mbedtls_config_board.h b/ports/stm32/boards/ARDUINO_NICLA_VISION/mbedtls_config_board.h index 0e1703f1bf962..07aef794692ec 100644 --- a/ports/stm32/boards/ARDUINO_NICLA_VISION/mbedtls_config_board.h +++ b/ports/stm32/boards/ARDUINO_NICLA_VISION/mbedtls_config_board.h @@ -3,6 +3,6 @@ #define MBEDTLS_ECP_NIST_OPTIM -#include "ports/stm32/mbedtls/mbedtls_config.h" +#include "ports/stm32/mbedtls/mbedtls_config_port.h" #endif /* MICROPY_INCLUDED_MBEDTLS_CONFIG_BOARD_H */ diff --git a/ports/stm32/boards/ARDUINO_PORTENTA_H7/mbedtls_config_board.h b/ports/stm32/boards/ARDUINO_PORTENTA_H7/mbedtls_config_board.h index 0e1703f1bf962..07aef794692ec 100644 --- a/ports/stm32/boards/ARDUINO_PORTENTA_H7/mbedtls_config_board.h +++ b/ports/stm32/boards/ARDUINO_PORTENTA_H7/mbedtls_config_board.h @@ -3,6 +3,6 @@ #define MBEDTLS_ECP_NIST_OPTIM -#include "ports/stm32/mbedtls/mbedtls_config.h" +#include "ports/stm32/mbedtls/mbedtls_config_port.h" #endif /* MICROPY_INCLUDED_MBEDTLS_CONFIG_BOARD_H */ diff --git a/ports/stm32/mbedtls/mbedtls_config.h b/ports/stm32/mbedtls/mbedtls_config_port.h similarity index 96% rename from ports/stm32/mbedtls/mbedtls_config.h rename to ports/stm32/mbedtls/mbedtls_config_port.h index 336fee0a199c0..5f8bb1cfd1b7a 100644 --- a/ports/stm32/mbedtls/mbedtls_config.h +++ b/ports/stm32/mbedtls/mbedtls_config_port.h @@ -30,6 +30,7 @@ #include extern time_t stm32_rtctime_seconds(time_t *timer); #define MBEDTLS_PLATFORM_TIME_MACRO stm32_rtctime_seconds +#define MBEDTLS_PLATFORM_MS_TIME_ALT mbedtls_ms_time // Set MicroPython-specific options. #define MICROPY_MBEDTLS_CONFIG_BARE_METAL (1) diff --git a/ports/stm32/mbedtls/mbedtls_port.c b/ports/stm32/mbedtls/mbedtls_port.c index cdfcd172a819d..a51144871ae7e 100644 --- a/ports/stm32/mbedtls/mbedtls_port.c +++ b/ports/stm32/mbedtls/mbedtls_port.c @@ -25,11 +25,12 @@ */ #include "rng.h" -#include "mbedtls_config.h" +#include "mbedtls_config_port.h" #if defined(MBEDTLS_HAVE_TIME) || defined(MBEDTLS_HAVE_TIME_DATE) #include "rtc.h" #include "shared/timeutils/timeutils.h" +#include "mbedtls/platform_time.h" #endif int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len, size_t *olen) { @@ -57,6 +58,13 @@ time_t stm32_rtctime_seconds(time_t *timer) { HAL_RTC_GetDate(&RTCHandle, &date, RTC_FORMAT_BIN); return timeutils_seconds_since_epoch(2000 + date.Year, date.Month, date.Date, time.Hours, time.Minutes, time.Seconds); } + +mbedtls_ms_time_t mbedtls_ms_time(void) { + time_t *tv = NULL; + mbedtls_ms_time_t current_ms; + current_ms = stm32_rtctime_seconds(tv) * 1000; + return current_ms; +} #endif #if defined(MBEDTLS_HAVE_TIME_DATE) diff --git a/ports/unix/mbedtls/mbedtls_config.h b/ports/unix/mbedtls/mbedtls_config_port.h similarity index 98% rename from ports/unix/mbedtls/mbedtls_config.h rename to ports/unix/mbedtls/mbedtls_config_port.h index 629064abcf297..c619de9b8b1b9 100644 --- a/ports/unix/mbedtls/mbedtls_config.h +++ b/ports/unix/mbedtls/mbedtls_config_port.h @@ -30,7 +30,6 @@ #define MBEDTLS_CIPHER_MODE_CTR // needed for MICROPY_PY_CRYPTOLIB_CTR // Enable mbedtls modules -#define MBEDTLS_HAVEGE_C #define MBEDTLS_TIMING_C // Include common mbedtls configuration. diff --git a/tests/README.md b/tests/README.md index 47fcacf409743..3bc626bf9e416 100644 --- a/tests/README.md +++ b/tests/README.md @@ -189,7 +189,7 @@ In this case CN is: micropython.local Convert them to DER format: ``` -$ openssl rsa -in rsa_key.pem -out rsa_key.der -outform DER +$ openssl pkey -in rsa_key.pem -out rsa_key.der -outform DER $ openssl x509 -in rsa_cert.pem -out rsa_cert.der -outform DER ``` diff --git a/tests/multi_net/asyncio_tls_server_client.py b/tests/multi_net/asyncio_tls_server_client.py index 59e13ec45d1dd..98f15c6625f0e 100644 --- a/tests/multi_net/asyncio_tls_server_client.py +++ b/tests/multi_net/asyncio_tls_server_client.py @@ -11,8 +11,8 @@ PORT = 8000 # These are test certificates. See tests/README.md for details. -cert = cafile = "rsa_cert.der" -key = "rsa_key.der" +cert = cafile = "ec_cert.der" +key = "ec_key.der" try: os.stat(cafile) diff --git a/tests/multi_net/asyncio_tls_server_client_cert_required_error.py b/tests/multi_net/asyncio_tls_server_client_cert_required_error.py index 8607e4ff10a9d..178ad39274032 100644 --- a/tests/multi_net/asyncio_tls_server_client_cert_required_error.py +++ b/tests/multi_net/asyncio_tls_server_client_cert_required_error.py @@ -11,8 +11,8 @@ PORT = 8000 # These are test certificates. See tests/README.md for details. -cert = cafile = "rsa_cert.der" -key = "rsa_key.der" +cert = cafile = "ec_cert.der" +key = "ec_key.der" try: os.stat(cafile) diff --git a/tests/multi_net/asyncio_tls_server_client_readline.py b/tests/multi_net/asyncio_tls_server_client_readline.py index fd8685f5af878..da5f1afee2ad6 100644 --- a/tests/multi_net/asyncio_tls_server_client_readline.py +++ b/tests/multi_net/asyncio_tls_server_client_readline.py @@ -11,8 +11,8 @@ PORT = 8000 # These are test certificates. See tests/README.md for details. -cert = cafile = "rsa_cert.der" -key = "rsa_key.der" +cert = cafile = "ec_cert.der" +key = "ec_key.der" try: os.stat(cafile) diff --git a/tests/multi_net/asyncio_tls_server_client_verify_error.py b/tests/multi_net/asyncio_tls_server_client_verify_error.py index c600dcc2c8b6f..362f0fc8ecf72 100644 --- a/tests/multi_net/asyncio_tls_server_client_verify_error.py +++ b/tests/multi_net/asyncio_tls_server_client_verify_error.py @@ -11,8 +11,8 @@ PORT = 8000 # These are test certificates. See tests/README.md for details. -cert = cafile = "rsa_cert.der" -key = "rsa_key.der" +cert = cafile = "ec_cert.der" +key = "ec_key.der" try: os.stat(cafile) diff --git a/tests/multi_net/ec_cert.der b/tests/multi_net/ec_cert.der new file mode 100644 index 0000000000000000000000000000000000000000..a503a39dfe49443dfdecfd79af0eab9f7cc2337d GIT binary patch literal 471 zcmXqLV!Uk7#8|n2nTe5!NyJ%n`Pu%=fBV!N4E<`RU*l3$UMp(A#m1r4=5fxJg_+5~ z-cZUwf{i(pg_%b%H#4~?zo4=tBR@|sCqFqc$56yT2qeeF!|e-_3joU*avN}hMA?Ly z977G{#CeTO3=9oT3`|UoO^u^~TvH&|7|NyGf=B~lHg>RknHZrCXJ%w)c4A=h-2U}f zM$M+EDJh4i2Q+%l)OU$#<33-&G_`Mwahch%^({PCPMo)%_Q}E{;l?_<$G?PQcd^Q~ zu|CtjQJ66&>x<3eV1qydS)f;B`B=nQL>xD-6PKO%*uYV?)p?iegHKmCO_er~2T3cl zNEnDUU{}BoQXtI8_@9Nef_u8yt6&GhJf9#m1r4=5fxJg_+5~ z-cZUwf{i(pg_%b%H#4~?zo4=tBR@|sCqFqc$56yT2qeeF!|e-_3joU*avN}hMA?Ly z977G{#CeTO3=9p83`|W;jm@K=Tw^Ggatk62gxT1^?qy>mFTj@`v7*T(ux z`$l2LoUAW4i-QdU4P=2{k>z6%V-a!OyiQzp;$s6x*;eOWt`9z4-85C&KprHm%pzeR z)_`3BKS+TvBjbM-Rs&`rg&exf9t;MqOo|LICr=KWmT9*jwDd8b&GN&}KaSm=T>2t4 y?r0-xoayo}tC$oR|2~Q8KYq|<|5Xp)IegZtfBv0#ckD{-B&OFcSJ{uPPzL}=8=4vb delta 1258 zcmcc4yqPP|povxApov+WNyO^r?ch+qmHZ}^=~qu3PTlb3%f{OVylk9WZ60mkc^MhG zSs4sM47m+B*_cCF*o2uJLk)!u1VJ1Q9^(op}Y{o+Wksj@}E5 zUq734X^*)V-^MShVf)pxuCpjKioN6Q*1xb-g5B%F3>p86M!GM=rk#1!+|jZjKkV}B zCv!f82?TumaqjB(FCT3=vNg(QO>^J<>)GMYYcrN^>U&YY@Z6?^8+D5r3{z(wxjR3h z>Bq#BtrPCIOHM$tQDt;{rzHpIz_JTiz z>#p6zvu-n)U!L2xS6jyT)Y4g}L&eT@9pEdzzBF)m>gCzj*0VUuH6G&2zEVp6dYZ27fMaiULU`2=et+_ z^F2??r_K(OV7nwXci)8?=g^)BJyRa0O#COMbav8?&o+WBrq*|6#B>ztr#@*=naE#c zV0z%Pb;V2#&HRm%&mA-6Xi>3d*dOSmb)kO#c1G=+r>+!cFgs~KxF~pU%}e25Cr)cW ze3`$(WkQBCUx>-TQ)5sLCUtovov$~XDPE}wOu#WB0ax;9y$ z@XX0gu51}sH!MzBGi#2Pa4PRn)w6e&eOPQS{Zl}5`BS}4V;lX;y~|AYo_NW+c5>UU zHvOmx|9RzDCx<>g&#Sp@?@_;>ugbMwM7S~euKw+AEFC3zzcNznNd0Q5@(pied<}2> zSfgcBpDGe^xjlnt*9Pl{Q7yu6vrk?=lt1(DgrhGe{oHf%3$OjKPD?o0`qTzKQ|?S`WbqJgqpP2q?4z4L2k6v`J)@s9BKJ@56u zyYz*ES>Meg?^W0`k5=eR3GvR`s=iI>pFzBBMZ^*3Uye@Q)k_iu4H|2&W=a0;J|!#7 z+UoGCrR2R+S^egBZx;NQ)$06bnzr!3m6O{7IpcdZ=U+B{dNF+d$z_#ST)4eId_LLK F4gijKKdb-% diff --git a/tests/multi_net/rsa_cert.der b/tests/multi_net/rsa_cert.der index 8fae71d4baa8cd3e2be3f3d2bedb62ebb33e371c..d0ea34bf4d63e2b84bbf19da64d0a98f4af8a9f5 100644 GIT binary patch delta 665 zcmV;K0%rZ=2IB@JFoFYLFoFU{paTK{0s<5wuk(~YwW*=sF0&t&g6?5ev6!}zBUl$P zH83~n(-~B>m8NtJ@P)w=k;z7H~BZDBCUpB+9;^>h6MH8}Ga~8vldteb$NpznL0Dn{% zCE!HpWMd+HmqgEzI>d^wrK$Gt8E=lU1?~MLOMAX;eyY8>*9M~gtF4&OyIORggw2og zTl5C5%vA;jf7?)gKYoC()^HO_P(@37TSaQ3@_Nw!v1W}hJqbGm4LYeBKEo{H*;m@( zK5Rr9p44n~`<|q72dsN@Hp_dFs7sqw0s{d60i#neQ7|0_163Uk1QrAo7;&25ymyP} zpp3dN8Zw9saXEX?Fdqg3RUIP)7%&!q6c}-u;JkN>=%9?cFB&q43~@Po(33s_C4ZzS z8WNT@%AM*xlN9rE^88fp0JFN6)na<5h)xI<) zOpw}m%r^H)vrFQjDJEr4(C8w}kYfkx&Rj20xS1-0Y^O+@R+C)1-CH7F0-z~bCTRLb z1?zpyZ=W}6aHuIspl;*x`Z4a^$bVjL@OYAu#662If--{;=3H{A8VH+Kxkck-52Z+> zp*xqR5Iqb4MO;P}Qw)lEDIZz(8tvTQhdg2PI7?kE;7PC-)Pt9*M5#p0-Gie?P3t6B zSaptjPPz#Nkn?7rYT`&E2#cPo+L8$q5qs=iyZoi4of<8HuT()FX7*IJ^#YrQIJz(- delta 665 zcmV;K0%rZ=2IB@JFoFYLFoFU{paTK{0s<6J0J0h?GD>%Ez0s|59Ejj-UIm?zBUl$O zGcYwXGchz;7Y#BsFflMPFf}tXF*K2qV}HoC3RHxqbshyHD~&AWjI=0;s1j0L*e~~z zL^m(ZIj$0x9CQ*ch)BQf@in2UhmM(%7<4|j5_G5vCzLRn}c7dh;xUk=}d?K;3gC4WRp zs3_^3zKR`w+dbY)1_mCp&qhyBZ>Hadu z7gh8tp|d)4@PFn#e=SthjK>9V;y5C_LHyrnfV2S#sR>h1fMC{ApaYR_O2uiC1OJg| zfaKozGeLUR@7{*GxA&(b^Y~qys$bl))&e^VaT``uYO-(&&%Lq&AYkPKI0BDexBV;% diff --git a/tests/multi_net/rsa_key.der b/tests/multi_net/rsa_key.der index c2cfb76d207e7afb33394bbcaf5525d7382dc2b6..c9c535ae639557e4e0023490a8f491a8ebf8985d 100644 GIT binary patch literal 1193 zcmV;a1XlYnf&`@k0RRGm0RaHcHA#8tD#$+6Jr!l6keA;P+b`4E2bpr*i#&OwdE7C> z8zHJUfGxM9d}-LU(sRIJY@2t@!SCGcY}`Wfcp3fK_=%b4iOr1NTt|Jc6iQeQlHdJ8 zWf{T4u24*==i))T$s>axnqM}d^wrK$Gt8E=lU1?~MLOMAX;eyY8>*9M~gtF4&OyIORggw2ogTl5C5%vA;j zf7?)gKYoC()^HO_P(@37TSaQ3@_Nw!v1W}hJqbGm4LYeBKEo{H*;m@(K5Rr9p44n~ z`<|q72dsN@Hp_dFsGC&+0|5X50)hbmJHn%_st#2IC|n(U88#6q^z+{lg8A_8DqM zM9TUR8ky8G9CW)L%&Nd1j=qNlEP$|)U3%`uxu%BvV^-xowxm+&4}4UxaGS#U7Uimh z3Qj$y>E+E`?pGOWI19{1fg*x~LZsS-li6Vjd!SOf$?%fxLE*Ur4}R;11W>?`_D&Wm zR1{Gf)N1K#^D#3p^RU`kI*3;Xt)j&8;P8I(Td0h#3R;SeIhat1+Q=%?RQnRwDTn%C z&W>s?JM{}k2Z!{{b=YJKF!R7o0)c@5>hgq)q8a96ry81^*EVOYrOU6BaXowMHDP@n zUdk|WHeLHi+ENYyvaob_#M4-My~dV5W!@VZf)t5i#E;s;uq5tSZJI zjPERM%2Q*UQwB;t!VjUk_LQ-sM1Qi#cJb6qThdD#7+()3p_k@;6g-;tb&5M@0)c@5 z;ID+9HImxTl$yoIaK;Vb&W-^p_&mUT--XY)t2;BBI}dc-;70)c@5(+c;WulSwl1M#%dkINDRmWD}qh~w7H zC=DYj-@COL?B-UF6u)w>$UJH3iOv+WuVJSqMhgl49CgQiv){ux&BPV05N`nKCB))q z8w%|n=p^fY&yZ?Zz=u@l+`rf2E}qbqJn)P%;0;JiGV98PQ#J@u>?oUL-D$Tq4bB#y z0)c@5ti=jD1%n9^Ie5{)Ol@A;k>S~%AvXZPexb=Rt?|ME^e literal 1217 zcmV;y1U~yPf&{$+0RS)!1_>&LNQUrr!ay9qXGc{0)hbn0LZlpRD`B= z9t9&SjV$Giv?z(F5>j2*FZYr}H!saOt`e3UbP_IzNWbmzHKD49j+v1dbUwEdbf^j^ zlrWm)&s>>O{1#~830zcx*6GlfNp!&A^&rcKCef|sUuZ>>e$^!hXNN<%`3xC2e~1EQ68WdaUJHGH6KNdf}_009Dm0RSW} zE{uuQ59_yeU6yxmaqG|;@P|zO$;j){93}3e3Ng(4?rA0!=}%+%+OL*V4Op>iEQDAA z+uBBMa|DdLj^L zh2>yytH@+-8JoegV^T#X1+$KCb{_(PfdJW>=*RfG!M;vGYUSVov*B)gB2e0lZJ`Ot z{m-JTH`87cEMkJFkmPGH8{9`dhN8^bciA$-J=V6fn#a~2FJRRUe}rMH$}fUo9PtXs zP@5c3YA(E?dApGqU>9Vw|Ii<8LgQ%}$MtF_7}?!8LBAO-^`8Z&-xqhL{)rW4K$il6 zfHW#`SlXmXKSpq(1GJX?`k09(o_0b?5Ih;PkL=P9OV3+=Kqp=SX|q8D{;-r)F9^ zopAt`tYM8J_NVcODA_lcw&Gq79%ojH!vcYT3@6|#6O{pctq5>^NartdKW4Xs2Et=` zWPh0>88$zp8Wb`b8s@|osShE~L|i?ZuYf|E6!)=&%1lFFNN1Ps06N8gqwCa? z4uvEmmJn0!Dsg7Wc#(kwt%h`(-nNd;|5pZCibaOl+{eJYc^;i2_5ka!cIl`*W-6f{ z0)c@5#<6P*4-tn^u^N#BUGa_+Bhj_x8=HnWhab^MWBD<g_) zfWDZ7Aax0^@U*8#QrcEUcV8%n1x#c*n>Jm diff --git a/tests/multi_net/ssl_cert_ec.py b/tests/multi_net/ssl_cert_ec.py new file mode 100644 index 0000000000000..2c5734e052661 --- /dev/null +++ b/tests/multi_net/ssl_cert_ec.py @@ -0,0 +1,56 @@ +# Simple test creating an SSL connection and transferring some data +# This test won't run under CPython because CPython doesn't have key/cert + +try: + import binascii, os, socket, ssl +except ImportError: + print("SKIP") + raise SystemExit + +PORT = 8000 + +# These are test certificates. See tests/README.md for details. +certfile = "ec_cert.der" +keyfile = "ec_key.der" + +try: + os.stat(certfile) + os.stat(keyfile) +except OSError: + print("SKIP") + raise SystemExit + +with open(certfile, "rb") as cf: + cert = cadata = cf.read() + +with open(keyfile, "rb") as kf: + key = kf.read() + + +# Server +def instance0(): + multitest.globals(IP=multitest.get_network_ip()) + s = socket.socket() + s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + s.bind(socket.getaddrinfo("0.0.0.0", PORT)[0][-1]) + s.listen(1) + multitest.next() + s2, _ = s.accept() + s2 = ssl.wrap_socket(s2, server_side=True, key=key, cert=cert) + print(s2.read(16)) + s2.write(b"server to client") + s2.close() + s.close() + + +# Client +def instance1(): + multitest.next() + s = socket.socket() + s.connect(socket.getaddrinfo(IP, PORT)[0][-1]) + s = ssl.wrap_socket( + s, cert_reqs=ssl.CERT_REQUIRED, server_hostname="micropython.local", cadata=cadata + ) + s.write(b"client to server") + print(s.read(16)) + s.close() diff --git a/tests/multi_net/ssl_data.py.exp b/tests/multi_net/ssl_cert_ec.py.exp similarity index 100% rename from tests/multi_net/ssl_data.py.exp rename to tests/multi_net/ssl_cert_ec.py.exp diff --git a/tests/multi_net/ssl_data.py b/tests/multi_net/ssl_data.py deleted file mode 100644 index a21c8c6589377..0000000000000 --- a/tests/multi_net/ssl_data.py +++ /dev/null @@ -1,67 +0,0 @@ -# Simple test creating an SSL connection and transferring some data -# This test won't run under CPython because it requires key/cert - -try: - import binascii, socket, ssl -except ImportError: - print("SKIP") - raise SystemExit - -PORT = 8000 - -# This self-signed key/cert pair is randomly generated and to be used for -# testing/demonstration only. You should always generate your own key/cert. -key = binascii.unhexlify( - b"3082013b020100024100cc20643fd3d9c21a0acba4f48f61aadd675f52175a9dcf07fbef" - b"610a6a6ba14abb891745cd18a1d4c056580d8ff1a639460f867013c8391cdc9f2e573b0f" - b"872d0203010001024100bb17a54aeb3dd7ae4edec05e775ca9632cf02d29c2a089b563b0" - b"d05cdf95aeca507de674553f28b4eadaca82d5549a86058f9996b07768686a5b02cb240d" - b"d9f1022100f4a63f5549e817547dca97b5c658038e8593cb78c5aba3c4642cc4cd031d86" - b"8f022100d598d870ffe4a34df8de57047a50b97b71f4d23e323f527837c9edae88c79483" - b"02210098560c89a70385c36eb07fd7083235c4c1184e525d838aedf7128958bedfdbb102" - b"2051c0dab7057a8176ca966f3feb81123d4974a733df0f958525f547dfd1c271f9022044" - b"6c2cafad455a671a8cf398e642e1be3b18a3d3aec2e67a9478f83c964c4f1f" -) -cert = binascii.unhexlify( - b"308201d53082017f020203e8300d06092a864886f70d01010505003075310b3009060355" - b"0406130258583114301206035504080c0b54686550726f76696e63653110300e06035504" - b"070c075468654369747931133011060355040a0c0a436f6d70616e7958595a3113301106" - b"0355040b0c0a436f6d70616e7958595a3114301206035504030c0b546865486f73744e61" - b"6d65301e170d3139313231383033333935355a170d3239313231353033333935355a3075" - b"310b30090603550406130258583114301206035504080c0b54686550726f76696e636531" - b"10300e06035504070c075468654369747931133011060355040a0c0a436f6d70616e7958" - b"595a31133011060355040b0c0a436f6d70616e7958595a3114301206035504030c0b5468" - b"65486f73744e616d65305c300d06092a864886f70d0101010500034b003048024100cc20" - b"643fd3d9c21a0acba4f48f61aadd675f52175a9dcf07fbef610a6a6ba14abb891745cd18" - b"a1d4c056580d8ff1a639460f867013c8391cdc9f2e573b0f872d0203010001300d06092a" - b"864886f70d0101050500034100b0513fe2829e9ecbe55b6dd14c0ede7502bde5d46153c8" - b"e960ae3ebc247371b525caeb41bbcf34686015a44c50d226e66aef0a97a63874ca5944ef" - b"979b57f0b3" -) - - -# Server -def instance0(): - multitest.globals(IP=multitest.get_network_ip()) - s = socket.socket() - s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - s.bind(socket.getaddrinfo("0.0.0.0", PORT)[0][-1]) - s.listen(1) - multitest.next() - s2, _ = s.accept() - s2 = ssl.wrap_socket(s2, server_side=True, key=key, cert=cert) - print(s2.read(16)) - s2.write(b"server to client") - s2.close() - s.close() - - -# Client -def instance1(): - multitest.next() - s = socket.socket() - s.connect(socket.getaddrinfo(IP, PORT)[0][-1]) - s = ssl.wrap_socket(s) - s.write(b"client to server") - print(s.read(16)) - s.close() diff --git a/tests/multi_net/sslcontext_check_hostname_error.py b/tests/multi_net/sslcontext_check_hostname_error.py index ac39211b092f0..d85363f00bd63 100644 --- a/tests/multi_net/sslcontext_check_hostname_error.py +++ b/tests/multi_net/sslcontext_check_hostname_error.py @@ -11,8 +11,8 @@ PORT = 8000 # These are test certificates. See tests/README.md for details. -cert = cafile = "rsa_cert.der" -key = "rsa_key.der" +cert = cafile = "ec_cert.der" +key = "ec_key.der" try: os.stat(cafile) diff --git a/tests/multi_net/sslcontext_getpeercert.py b/tests/multi_net/sslcontext_getpeercert.py index 8748c1f78e8fc..e9d96be248c70 100644 --- a/tests/multi_net/sslcontext_getpeercert.py +++ b/tests/multi_net/sslcontext_getpeercert.py @@ -12,8 +12,8 @@ PORT = 8000 # These are test certificates. See tests/README.md for details. -cert = cafile = "rsa_cert.der" -key = "rsa_key.der" +cert = cafile = "ec_cert.der" +key = "ec_key.der" try: os.stat(cafile) diff --git a/tests/multi_net/sslcontext_getpeercert.py.exp b/tests/multi_net/sslcontext_getpeercert.py.exp index 7b0e9d40a64c7..e7a0ab0b4622c 100644 --- a/tests/multi_net/sslcontext_getpeercert.py.exp +++ b/tests/multi_net/sslcontext_getpeercert.py.exp @@ -1,5 +1,5 @@ --- instance0 --- b'client to server' --- instance1 --- -3082058930820371a00302010202141b3da08b15005eea265d0b57b8ba99812ab274cb300d06092a864886f70d01010b05003054310b30090603550406130241553113301106035504080c0a536f6d652d537461746531143012060355040a0c0b4d6963726f507974686f6e311a301806035504030c116d6963726f707974686f6e2e6c6f63616c301e170d3233313131393032323932375a170d3238313131373032323932375a3054310b30090603550406130241553113301106035504080c0a536f6d652d537461746531143012060355040a0c0b4d6963726f507974686f6e311a301806035504030c116d6963726f707974686f6e2e6c6f63616c30820222300d06092a864886f70d01010105000382020f003082020a0282020100deee37780ebca47e0f414ba033ebe692d2bc374a0eb1f42556bf266ad704208116ee0d8b2fd0b518074ad0981c4fd1322de81696ccea838884b06f56d3ebe49cf0561050f6f8ced5f7f4f13d086b28779a9647bbfae6c3f3ad68a5b28ee8a1ceb260d87ea300316599c4dd9f6082f89164b590df8695add518339f6730dec4f05b1ef63548329b0a48823035b23737f3303b56aa251dd8dcf0c20e6c1d291374c185ae657b349c20721c7c01a1b393c96d4c5f2bc8e2dfca7dab896e2fa84dee53d2bb6dbd1056970fa1812315e8ee9d92b3cb93e0b563d274bf07dd79600ef403b91d4ce814418b28cfaeb2b7d8401e64f6d4f39283df3204f2fe01f2fd289f5d2078d9ee2f96b6de1fd4284d9274fa38b0ad9ffcce8ffe66673be2cf304ee1b27c7cacaaf4ca76f1e84419e6e80f540add3e91cd469903e9ceb6bd2b1c33caa59acb5516ce8ac00e73d7a551bb65d39bd6af04411e81c20e6bd474d797a0bcd498e26720bd60ae4f900bb1afa59c7ac7a336273c7734ca5874ea63fb8ec787ab702041442da11a922baf5fbeb9eeea4f9f49cb1f659b561806d2169dbed07c43558c908c94e16491fe1a22cd92b8f33c1184353bdc985c88722f65e48024910f723035c0d33b789928296fb193cec6350884243b00bf51422ad09fb7012bd9cad4716803422be0d111deace913fac8cb2be1e96fa8449068430e5424bd0bd10203010001a3533051301d0603551d0e041604147d392a82ab464936fd7d74226694556a2945fd8d301f0603551d230418301680147d392a82ab464936fd7d74226694556a2945fd8d300f0603551d130101ff040530030101ff300d06092a864886f70d01010b05000382020100ae40c015e3eade8dabc84ee357ac9d694e7cd69ce4a1b265880273d16257119aa72fb2aa8b841e2899bea3e8690146f24d963a37825c93bf745447dc6ab09b5f2947671dca13b1e71f5c3e43011d74cdc688ed1215b3016071ae7235d77f79d7bb81f097bb04a08ccf400717721b29e2ea913eb23614610597deee477ed716db7e8ebe11aed39c7035f48259dfa54d88871c1f67159d52ce11eb111fa00708a7d7081c07fd92d54abbaec7ff1b50ce2f6f358857d2f55d1c7b5aa6dd66b9c3c2e654397e2d5330aca9834ff8fd749ce968c706fe3bb1b8510a379ec1910d7ece0212c34d56a2073fb7f25c88fe298568e448d03ec30b348f7d9a8836390216a6da7a8efed50dfb8c21a8531efc158e7f4398f87af18d1bd2926d08d34364bf5d85e88040dff3d3f1da6268dbc0cafa64f544c065380fa695a8d015b385aed0a1fd9ff1d7c2b28a549e04c1132b421f85a85640acac11c69416859fb9b461eeddffa92ae303b35c7233537077068de558dd02715e25aee976a97879038d2952be0d327892ab2fc78716b0d7aab4b923d5d79905f7f8b6a18c42e466fec62f84b6e5957deae0964dab8436b0e0cd4e08012661bafb9588fbfd7068fd6c08ab79101a4bdfe21d95cd0ee0aad7dd8a3ed128071c0ec2d063dc6dfa63189e51bf5d9259e776d7623f745a73f4e12e5c2b90493de1c6436b339e1400891e3e35c31057 +308201d330820179a00302010202144315a7cd8f69febe2640314e7c97d60a2523ad15300a06082a8648ce3d040302303f311a301806035504030c116d6963726f707974686f6e2e6c6f63616c31143012060355040a0c0b4d6963726f507974686f6e310b3009060355040613024155301e170d3234303131343034353335335a170d3235303131333034353335335a303f311a301806035504030c116d6963726f707974686f6e2e6c6f63616c31143012060355040a0c0b4d6963726f507974686f6e310b30090603550406130241553059301306072a8648ce3d020106082a8648ce3d0301070342000449b7f5fa687cb25a9464c397508149992f445c860bcf7002958eb4337636c6af840cd4c8cf3b96f2384860d8ae3ee3fa135dba051e8605e62bd871689c6af43ca3533051301d0603551d0e0416041441b3ae171d91e330411d8543ba45e0f2d5b2951b301f0603551d2304183016801441b3ae171d91e330411d8543ba45e0f2d5b2951b300f0603551d130101ff040530030101ff300a06082a8648ce3d04030203480030450220587f61c34739d6fab5802a674dcc54443ae9c87da374078c4ee1cd83f4ad1694022100cfc45dcf264888c6ba2c36e78bd27bb67856d7879a052dd7aa7ecf7215f7b992 b'server to client' diff --git a/tests/multi_net/sslcontext_server_client.py b/tests/multi_net/sslcontext_server_client.py index c263ae31bb4e8..473c9c376e38a 100644 --- a/tests/multi_net/sslcontext_server_client.py +++ b/tests/multi_net/sslcontext_server_client.py @@ -11,8 +11,8 @@ PORT = 8000 # These are test certificates. See tests/README.md for details. -certfile = "rsa_cert.der" -keyfile = "rsa_key.der" +certfile = "ec_cert.der" +keyfile = "ec_key.der" try: os.stat(certfile) diff --git a/tests/multi_net/sslcontext_server_client_ciphers.py b/tests/multi_net/sslcontext_server_client_ciphers.py index be7c332b4c747..d65d860fb2745 100644 --- a/tests/multi_net/sslcontext_server_client_ciphers.py +++ b/tests/multi_net/sslcontext_server_client_ciphers.py @@ -11,8 +11,8 @@ PORT = 8000 # These are test certificates. See tests/README.md for details. -cert = cafile = "rsa_cert.der" -key = "rsa_key.der" +cert = cafile = "ec_cert.der" +key = "ec_key.der" try: os.stat(cafile) @@ -48,8 +48,8 @@ def instance1(): s.connect(socket.getaddrinfo(IP, PORT)[0][-1]) client_ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) ciphers = client_ctx.get_ciphers() - assert "TLS-RSA-WITH-AES-256-CBC-SHA256" in ciphers - client_ctx.set_ciphers(["TLS-RSA-WITH-AES-256-CBC-SHA256"]) + assert "TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" in ciphers + client_ctx.set_ciphers(["TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256"]) client_ctx.verify_mode = ssl.CERT_REQUIRED client_ctx.load_verify_locations(cafile=cafile) s = client_ctx.wrap_socket(s, server_hostname="micropython.local") diff --git a/tests/multi_net/sslcontext_server_client_files.py b/tests/multi_net/sslcontext_server_client_files.py index e1ea1b3aa8b32..64a4215c75b44 100644 --- a/tests/multi_net/sslcontext_server_client_files.py +++ b/tests/multi_net/sslcontext_server_client_files.py @@ -11,8 +11,8 @@ PORT = 8000 # These are test certificates. See tests/README.md for details. -cert = cafile = "rsa_cert.der" -key = "rsa_key.der" +cert = cafile = "ec_cert.der" +key = "ec_key.der" try: os.stat(cafile) diff --git a/tests/multi_net/sslcontext_verify_error.py b/tests/multi_net/sslcontext_verify_error.py index 4a7a6cfcc14c2..5dc461e7708a8 100644 --- a/tests/multi_net/sslcontext_verify_error.py +++ b/tests/multi_net/sslcontext_verify_error.py @@ -11,8 +11,8 @@ PORT = 8000 # These are test certificates. See tests/README.md for details. -cert = cafile = "rsa_cert.der" -key = "rsa_key.der" +cert = cafile = "ec_cert.der" +key = "ec_key.der" try: os.stat(cafile) diff --git a/tests/multi_net/sslcontext_verify_time_error.py b/tests/multi_net/sslcontext_verify_time_error.py index e5dc496451649..fbefdecf9f430 100644 --- a/tests/multi_net/sslcontext_verify_time_error.py +++ b/tests/multi_net/sslcontext_verify_time_error.py @@ -12,7 +12,7 @@ # These are test certificates. See tests/README.md for details. cert = cafile = "expired_cert.der" -key = "rsa_key.der" +key = "ec_key.der" try: os.stat(cafile) From d19371cb23b58151f27695a445f33505af6bdb1e Mon Sep 17 00:00:00 2001 From: Matthias Urlichs Date: Thu, 25 Jan 2024 18:11:31 +0100 Subject: [PATCH 081/408] py/builtinimport: Simplify calls to stat_path(). stat_path is only called with stringified vstr_t objects. Thus, pulling the stringification into the function replaces three function calls with one, saving a few bytes. Signed-off-by: Matthias Urlichs --- py/builtinimport.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/py/builtinimport.c b/py/builtinimport.c index 009885498ca75..3cc117befaad6 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -57,16 +57,17 @@ // uses mp_vfs_import_stat) to also search frozen modules. Given an exact // path to a file or directory (e.g. "foo/bar", foo/bar.py" or "foo/bar.mpy"), // will return whether the path is a file, directory, or doesn't exist. -STATIC mp_import_stat_t stat_path(const char *path) { +STATIC mp_import_stat_t stat_path(vstr_t *path) { + const char *str = vstr_null_terminated_str(path); #if MICROPY_MODULE_FROZEN // Only try and load as a frozen module if it starts with .frozen/. const int frozen_path_prefix_len = strlen(MP_FROZEN_PATH_PREFIX); - if (strncmp(path, MP_FROZEN_PATH_PREFIX, frozen_path_prefix_len) == 0) { + if (strncmp(str, MP_FROZEN_PATH_PREFIX, frozen_path_prefix_len) == 0) { // Just stat (which is the return value), don't get the data. - return mp_find_frozen_module(path + frozen_path_prefix_len, NULL, NULL); + return mp_find_frozen_module(str + frozen_path_prefix_len, NULL, NULL); } #endif - return mp_import_stat(path); + return mp_import_stat(str); } // Stat a given filesystem path to a .py file. If the file does not exist, @@ -75,7 +76,7 @@ STATIC mp_import_stat_t stat_path(const char *path) { // files. This uses stat_path above, rather than mp_import_stat directly, so // that the .frozen path prefix is handled. STATIC mp_import_stat_t stat_file_py_or_mpy(vstr_t *path) { - mp_import_stat_t stat = stat_path(vstr_null_terminated_str(path)); + mp_import_stat_t stat = stat_path(path); if (stat == MP_IMPORT_STAT_FILE) { return stat; } @@ -85,7 +86,7 @@ STATIC mp_import_stat_t stat_file_py_or_mpy(vstr_t *path) { // Note: There's no point doing this if it's a frozen path, but adding the check // would be extra code, and no harm letting mp_find_frozen_module fail instead. vstr_ins_byte(path, path->len - 2, 'm'); - stat = stat_path(vstr_null_terminated_str(path)); + stat = stat_path(path); if (stat == MP_IMPORT_STAT_FILE) { return stat; } @@ -99,7 +100,7 @@ STATIC mp_import_stat_t stat_file_py_or_mpy(vstr_t *path) { // result is a file, the path argument will be updated to include the file // extension. STATIC mp_import_stat_t stat_module(vstr_t *path) { - mp_import_stat_t stat = stat_path(vstr_null_terminated_str(path)); + mp_import_stat_t stat = stat_path(path); DEBUG_printf("stat %s: %d\n", vstr_str(path), stat); if (stat == MP_IMPORT_STAT_DIR) { return stat; From 807c25d05a81feed1dd0cbc5fde5e0d1ef45c967 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 30 Jan 2024 12:28:30 +1100 Subject: [PATCH 082/408] rp2: Change machine.I2S and rp2.DMA to use shared DMA IRQ handlers. These separate drivers must share the DMA resource with each other. Fixes issue #13380. Signed-off-by: Damien George --- ports/rp2/CMakeLists.txt | 1 + ports/rp2/machine_i2s.c | 6 ++---- ports/rp2/rp2_dma.c | 14 +++++++------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt index 281b0c3bc2846..3a46fdaa7f47b 100644 --- a/ports/rp2/CMakeLists.txt +++ b/ports/rp2/CMakeLists.txt @@ -474,6 +474,7 @@ target_compile_definitions(${MICROPY_TARGET} PRIVATE PICO_FLOAT_PROPAGATE_NANS=1 PICO_STACK_SIZE=0x2000 PICO_CORE1_STACK_SIZE=0 + PICO_MAX_SHARED_IRQ_HANDLERS=8 # we need more than the default PICO_PROGRAM_NAME="MicroPython" PICO_NO_PROGRAM_VERSION_STRING=1 # do it ourselves in main.c MICROPY_BUILD_TYPE="${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION} ${CMAKE_BUILD_TYPE}" diff --git a/ports/rp2/machine_i2s.c b/ports/rp2/machine_i2s.c index 68a0f296a01fe..ae8026a4af662 100644 --- a/ports/rp2/machine_i2s.c +++ b/ports/rp2/machine_i2s.c @@ -232,20 +232,18 @@ STATIC void feed_dma(machine_i2s_obj_t *self, uint8_t *dma_buffer_p) { STATIC void irq_configure(machine_i2s_obj_t *self) { if (self->i2s_id == 0) { - irq_set_exclusive_handler(DMA_IRQ_0, dma_irq0_handler); + irq_add_shared_handler(DMA_IRQ_0, dma_irq0_handler, PICO_SHARED_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY); irq_set_enabled(DMA_IRQ_0, true); } else { - irq_set_exclusive_handler(DMA_IRQ_1, dma_irq1_handler); + irq_add_shared_handler(DMA_IRQ_1, dma_irq1_handler, PICO_SHARED_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY); irq_set_enabled(DMA_IRQ_1, true); } } STATIC void irq_deinit(machine_i2s_obj_t *self) { if (self->i2s_id == 0) { - irq_set_enabled(DMA_IRQ_0, false); irq_remove_handler(DMA_IRQ_0, dma_irq0_handler); } else { - irq_set_enabled(DMA_IRQ_1, false); irq_remove_handler(DMA_IRQ_1, dma_irq1_handler); } } diff --git a/ports/rp2/rp2_dma.c b/ports/rp2/rp2_dma.c index 893498265aa41..425fb417fa5ec 100644 --- a/ports/rp2/rp2_dma.c +++ b/ports/rp2/rp2_dma.c @@ -98,18 +98,16 @@ STATIC uint32_t rp2_dma_register_value_from_obj(mp_obj_t o, int reg_type) { STATIC void rp2_dma_irq_handler(void) { // Main IRQ handler uint32_t irq_bits = dma_hw->ints0; - dma_hw->ints0 = 0xffff; for (int i = 0; i < NUM_DMA_CHANNELS; i++) { if (irq_bits & (1u << i)) { mp_irq_obj_t *handler = MP_STATE_PORT(rp2_dma_irq_obj[i]); if (handler) { + // An rp2.DMA IRQ handler is registered for this channel, so handle it. + dma_channel_acknowledge_irq0(i); rp2_dma_obj_t *self = (rp2_dma_obj_t *)handler->parent; self->irq_flag = 1; mp_irq_handler(handler); - } else { - // We got an interrupt with no handler. Disable the channel - dma_channel_set_irq0_enabled(i, false); } } } @@ -389,6 +387,9 @@ STATIC mp_obj_t rp2_dma_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k if (irq == NULL) { irq = mp_irq_new(&rp2_dma_irq_methods, MP_OBJ_FROM_PTR(self)); MP_STATE_PORT(rp2_dma_irq_obj[self->channel]) = irq; + + // Clear any existing IRQs on this DMA channel, they are not for us. + dma_channel_acknowledge_irq0(self->channel); } if (n_args > 1 || kw_args->used != 0) { @@ -457,12 +458,11 @@ MP_DEFINE_CONST_OBJ_TYPE( void rp2_dma_init(void) { // Set up interrupts. memset(MP_STATE_PORT(rp2_dma_irq_obj), 0, sizeof(MP_STATE_PORT(rp2_dma_irq_obj))); - irq_set_exclusive_handler(DMA_IRQ_0, rp2_dma_irq_handler); + irq_add_shared_handler(DMA_IRQ_0, rp2_dma_irq_handler, PICO_SHARED_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY); } void rp2_dma_deinit(void) { - // Disable and clear interrupts. - irq_set_mask_enabled(1u << DMA_IRQ_0, false); + // Remove our interrupt handler. irq_remove_handler(DMA_IRQ_0, rp2_dma_irq_handler); } From 2d7fb9a715d8c9f1f7ba73a62cfd587fa6ffc24a Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 30 Jan 2024 12:44:25 +1100 Subject: [PATCH 083/408] tests/ports/rp2/rp2_dma.py: Tweak test to be more reliable. The timing of the DMA transfer can vary a bit, so tweak the allowed values. Also test the return value of `rp2.DMA.irq.flags()` to make sure the IRQ is correctly signalled. Signed-off-by: Damien George --- tests/ports/rp2/rp2_dma.py | 4 ++-- tests/ports/rp2/rp2_dma.py.exp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ports/rp2/rp2_dma.py b/tests/ports/rp2/rp2_dma.py index cd97f0357b788..2459213f4c014 100644 --- a/tests/ports/rp2/rp2_dma.py +++ b/tests/ports/rp2/rp2_dma.py @@ -62,7 +62,7 @@ def run_and_time_dma(dma): dma.count = len(dest) // 4 dma.ctrl = dma.pack_ctrl() dt = run_and_time_dma(dma) -print(60 <= dt <= 90) +print(70 <= dt <= 110) print(dest[:8], dest[-8:]) dma.close() @@ -80,7 +80,7 @@ def run_and_time_dma(dma): print("# test irq") dest = bytearray(1024) dma = rp2.DMA() -dma.irq(lambda _: print("irq fired")) +dma.irq(lambda dma: print("irq fired", dma.irq().flags())) dma.config( read=src, write=dest, count=len(dest) // 4, ctrl=dma.pack_ctrl(irq_quiet=0), trigger=True ) diff --git a/tests/ports/rp2/rp2_dma.py.exp b/tests/ports/rp2/rp2_dma.py.exp index 956aee4e34c1f..79f17626ace2a 100644 --- a/tests/ports/rp2/rp2_dma.py.exp +++ b/tests/ports/rp2/rp2_dma.py.exp @@ -12,5 +12,5 @@ bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07') bytearray(b'\xf8\xf9\xfa\xfb\xfc\ # test immediate trigger bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07') bytearray(b'\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff') # test irq -irq fired +irq fired 1 bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07') bytearray(b'\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff') From 28b18c43fefe6236f899eba79f9a1b2bad134d0f Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 31 Jan 2024 12:56:29 +1100 Subject: [PATCH 084/408] py/compile: Fix potential Py-stack overflow in try-finally with return. If a return is executed within the try block of a try-finally then the return value is stored on the top of the Python stack during the execution of the finally block. In this case the Python stack is one larger than it normally would be in the finally block. Prior to this commit, the compiler was not taking this case into account and could have a Python stack overflow if the Python stack used by the finally block was more than that used elsewhere in the function. In such a scenario the last argument of the function would be clobbered by the top-most temporary value used in the deepest Python expression/statement. This commit fixes that case by making sure enough Python stack is allocated to the function. Fixes issue #13562. Signed-off-by: Damien George --- py/compile.c | 11 +++++++++++ tests/basics/try_finally_return.py | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/py/compile.c b/py/compile.c index 4f91ca49b903a..a9b34ce5d91bd 100644 --- a/py/compile.c +++ b/py/compile.c @@ -1650,9 +1650,11 @@ STATIC void compile_try_except(compiler_t *comp, mp_parse_node_t pn_body, int n_ if (qstr_exception_local != 0) { EMIT_ARG(load_const_tok, MP_TOKEN_KW_NONE); EMIT_ARG(label_assign, l3); + EMIT_ARG(adjust_stack_size, 1); // stack adjust for possible return value EMIT_ARG(load_const_tok, MP_TOKEN_KW_NONE); compile_store_id(comp, qstr_exception_local); compile_delete_id(comp, qstr_exception_local); + EMIT_ARG(adjust_stack_size, -1); compile_decrease_except_level(comp); } @@ -1682,9 +1684,18 @@ STATIC void compile_try_finally(compiler_t *comp, mp_parse_node_t pn_body, int n } else { compile_try_except(comp, pn_body, n_except, pn_except, pn_else); } + + // If the code reaches this point then the try part of the try-finally exited normally. + // This is indicated to the runtime by None sitting on the stack. EMIT_ARG(load_const_tok, MP_TOKEN_KW_NONE); + + // Compile the finally block. + // The stack needs to be adjusted by 1 to account for the possibility that the finally is + // being executed as part of a return, and the return value is on the top of the stack. EMIT_ARG(label_assign, l_finally_block); + EMIT_ARG(adjust_stack_size, 1); compile_node(comp, pn_finally); + EMIT_ARG(adjust_stack_size, -1); compile_decrease_except_level(comp); } diff --git a/tests/basics/try_finally_return.py b/tests/basics/try_finally_return.py index 31a507e8d0753..21e01ea21bf22 100644 --- a/tests/basics/try_finally_return.py +++ b/tests/basics/try_finally_return.py @@ -70,3 +70,13 @@ def f(): finally: print('finally 1') print(f()) + +# the finally block uses a lot of Python stack and then a local is accessed +# (tests that the use of the stack doesn't clobber the local) +def f(x): + try: + return x + finally: + print(2, 3, 4, 5, 6) + print(x) +print(f(1)) From 81049edf7c67413527ba58a96a3ecfb963addbf9 Mon Sep 17 00:00:00 2001 From: Takeo Takahashi Date: Mon, 29 Jan 2024 23:52:11 +0900 Subject: [PATCH 085/408] renesas-ra/ra/ra_i2c: Fix 1 byte and 2 bytes read issue. Tested on Portenta C33 with AT24256B (addrsize=16) and SSD1306. Fixes issue #13280. Signed-off-by: Takeo Takahashi --- ports/renesas-ra/ra/ra_i2c.c | 36 +++++++++++++++++++++++++++++++++++- ports/renesas-ra/ra/ra_i2c.h | 9 +++++---- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/ports/renesas-ra/ra/ra_i2c.c b/ports/renesas-ra/ra/ra_i2c.c index 783c0c921543b..701f4d6aa8386 100644 --- a/ports/renesas-ra/ra/ra_i2c.c +++ b/ports/renesas-ra/ra/ra_i2c.c @@ -426,7 +426,7 @@ void ra_i2c_init(R_IIC0_Type *i2c_inst, uint32_t scl, uint32_t sda, uint32_t bau i2c_inst->ICCR1_b.ICE = 1; // I2C enable ra_i2c_set_baudrate(i2c_inst, baudrate); i2c_inst->ICSER = 0x00; // I2C reset bus status enable register - i2c_inst->ICMR3_b.ACKWP = 0x01; // I2C allow to write ACKBT (transfer acknowledge bit) + i2c_inst->ICMR3_b.ACKWP = 0x00; // I2C not allow to write ACKBT (transfer acknowledge bit) i2c_inst->ICIER = 0xFF; // Enable all interrupts i2c_inst->ICCR1_b.IICRST = 0; // I2C internal reset ra_i2c_irq_enable(i2c_inst); @@ -480,6 +480,7 @@ void ra_i2c_xunit_read_byte(R_IIC0_Type *i2c_inst, xaction_unit_t *unit) { void ra_i2c_xunit_init(xaction_unit_t *unit, uint8_t *buf, uint32_t size, bool fread, void *next) { unit->m_bytes_transferred = 0; unit->m_bytes_transfer = size; + unit->m_bytes_total = size; unit->m_fread = fread; unit->buf = buf; unit->next = (void *)next; @@ -531,6 +532,37 @@ static void ra_i2c_iceri_isr(R_IIC0_Type *i2c_inst) { static void ra_i2c_icrxi_isr(R_IIC0_Type *i2c_inst) { xaction_unit_t *unit = current_xaction_unit; xaction_t *action = current_xaction; + // 1 byte or 2 bytes + if (unit->m_bytes_total <= 2) { + if (action->m_status == RA_I2C_STATUS_AddrWriteCompleted) { + action->m_status = RA_I2C_STATUS_FirstReceiveCompleted; + i2c_inst->ICMR3_b.WAIT = 1; + // need dummy read processes for 1 byte and 2 bytes receive + if (unit->m_bytes_total == 2) { + (void)i2c_inst->ICDRR; // dummy read for 2 bytes receive + } else { // m_bytes_total == 1 + i2c_inst->ICMR3_b.ACKWP = 0x01; // enable write ACKBT (transfer acknowledge bit) + i2c_inst->ICMR3_b.ACKBT = 1; + i2c_inst->ICMR3_b.ACKWP = 0x00; // disable write ACKBT (transfer acknowledge bit) + (void)i2c_inst->ICDRR; // dummy read for 1 byte receive + } + return; + } + if (unit->m_bytes_transfer == 2) { // last two data + i2c_inst->ICMR3_b.ACKWP = 0x01; // enable write ACKBT (transfer acknowledge bit) + i2c_inst->ICMR3_b.ACKBT = 1; + i2c_inst->ICMR3_b.ACKWP = 0x00; // disable write ACKBT (transfer acknowledge bit) + ra_i2c_xunit_read_byte(i2c_inst, unit); + } else { // last data + action->m_status = RA_I2C_STATUS_LastReceiveCompleted; + if (action->m_stop == true) { + i2c_inst->ICCR2_b.SP = 1; // request top condition + } + ra_i2c_xunit_read_byte(i2c_inst, unit); + } + return; + } + // 3 bytes or more if (action->m_status == RA_I2C_STATUS_AddrWriteCompleted) { (void)i2c_inst->ICDRR; // dummy read action->m_status = RA_I2C_STATUS_FirstReceiveCompleted; @@ -542,7 +574,9 @@ static void ra_i2c_icrxi_isr(R_IIC0_Type *i2c_inst) { } ra_i2c_xunit_read_byte(i2c_inst, unit); } else if (unit->m_bytes_transfer == 2) { + i2c_inst->ICMR3_b.ACKWP = 0x01; // enable write ACKBT (transfer acknowledge bit) i2c_inst->ICMR3_b.ACKBT = 1; + i2c_inst->ICMR3_b.ACKWP = 0x00; // disable write ACKBT (transfer acknowledge bit) ra_i2c_xunit_read_byte(i2c_inst, unit); } else { // last data diff --git a/ports/renesas-ra/ra/ra_i2c.h b/ports/renesas-ra/ra/ra_i2c.h index e2432675a001e..fc172a3e956aa 100644 --- a/ports/renesas-ra/ra/ra_i2c.h +++ b/ports/renesas-ra/ra/ra_i2c.h @@ -47,9 +47,9 @@ typedef enum RA_I2C_STATUS_AddrWriteCompleted = 3, RA_I2C_STATUS_DataWriteCompleted = 4, RA_I2C_STATUS_DataSendCompleted = 5, - RA_I2C_STATUS_FirstReceiveCompleted = 5, - RA_I2C_STATUS_LastReceiveCompleted = 6, - RA_I2C_STATUS_Stopped = 7, + RA_I2C_STATUS_FirstReceiveCompleted = 6, + RA_I2C_STATUS_LastReceiveCompleted = 7, + RA_I2C_STATUS_Stopped = 8, } xaction_status_t; typedef enum @@ -64,6 +64,7 @@ typedef enum typedef struct { volatile uint32_t m_bytes_transferred; volatile uint32_t m_bytes_transfer; + uint32_t m_bytes_total; bool m_fread; uint8_t *buf; void *next; @@ -75,7 +76,7 @@ typedef struct { uint32_t m_current; uint32_t m_address; volatile xaction_status_t m_status; - xaction_error_t m_error; + volatile xaction_error_t m_error; bool m_stop; } xaction_t; From 3e48d24576f8a44a20e65a5782204944de2467b3 Mon Sep 17 00:00:00 2001 From: Joey232 Date: Sat, 20 Jan 2024 17:32:37 -0500 Subject: [PATCH 086/408] esp32/boards/UM_FEATHERS3: Use read_uv() for accurate battery voltage. Use read_uv() to get the battery voltage because it uses the on-chip calibraton values. Signed-off-by: Joey232 --- ports/esp32/boards/UM_FEATHERS3/modules/feathers3.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ports/esp32/boards/UM_FEATHERS3/modules/feathers3.py b/ports/esp32/boards/UM_FEATHERS3/modules/feathers3.py index b6f486f3d811b..57b15f9c01c29 100644 --- a/ports/esp32/boards/UM_FEATHERS3/modules/feathers3.py +++ b/ports/esp32/boards/UM_FEATHERS3/modules/feathers3.py @@ -65,10 +65,11 @@ def get_battery_voltage(): This is an approximation only, but useful to detect if the charge state of the battery is getting low. """ adc = ADC(Pin(VBAT_SENSE)) # Assign the ADC pin to read - adc.atten(ADC.ATTN_2_5DB) # Needs 2.5DB attenuation for max voltage of 1.116V w/batt of 4.2V - measuredvbat = adc.read() - measuredvbat /= 3657 # Divide by 3657 as we are using 2.5dB attenuation, which is max input of 1.25V = 4095 counts - measuredvbat *= 4.2 # Multiply by 4.2V, our max charge voltage for a 1S LiPo + # Max voltage on ADC input will be 4.2V divided by R2 (442K) & R5 (160K), 4.2 / (160+442) * 160 = 1.1163V + adc.atten(ADC.ATTN_2_5DB) # Needs 2.5DB attenuation to read a max voltage of 1.1163V + # Use read_uv() to get ADC reading as this will use the on-chip calibration data + measuredvbat = adc.read_uv() / 1000000 # Read micovolts and convert to volts + measuredvbat *= 3.7624 # Multiply by ratio of battery voltage to ADC pin voltage: 4.2/1.1163 return round(measuredvbat, 2) From 457f2ccf804dd0e9a770984ed11f2568c2fcd958 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 31 Jan 2024 11:18:05 +1100 Subject: [PATCH 087/408] examples/embedding: Add -fno-common to the sample compiler flags. This makes no difference when files are linked directly into a target application, but on macOS additional steps are needed to index common symbols in static libraries. See https://stackoverflow.com/a/26581710 By not creating any common symbols, this problem is bypassed. This will also trigger linker errors if there are cases where the same symbol is defined in the host application. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- examples/embedding/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/embedding/Makefile b/examples/embedding/Makefile index 13bfdf12395d8..c3ca14836f1d3 100644 --- a/examples/embedding/Makefile +++ b/examples/embedding/Makefile @@ -12,7 +12,7 @@ PROG = embed CFLAGS += -I. CFLAGS += -I$(EMBED_DIR) CFLAGS += -I$(EMBED_DIR)/port -CFLAGS += -Wall -Og +CFLAGS += -Wall -Og -fno-common SRC += main.c SRC += $(wildcard $(EMBED_DIR)/*/*.c) $(wildcard $(EMBED_DIR)/*/*/*.c) From 0285cb2bf4a317490364b9249f25ca0eaa6af3ef Mon Sep 17 00:00:00 2001 From: Jim Lipsey Date: Thu, 12 Oct 2023 17:14:52 -0500 Subject: [PATCH 088/408] stm32/boards/ARDUINO_PORTENTA_H7: Add pin configuration for SPI1. Currently, only the processor's SPI2 bus is enabled (though the related pins are labeled SPI1 in the Portenta H7 documentation). This commit enables the processor's SPI1 bus, which is accessible via the board's high-density connectors. Signed-off-by: Jim Lipsey --- ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h b/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h index e2e6956a47d68..ace63e016b189 100644 --- a/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h +++ b/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h @@ -170,7 +170,12 @@ extern struct _spi_bdev_t spi_bdev; #define MICROPY_HW_I2C3_SCL (pin_H7) #define MICROPY_HW_I2C3_SDA (pin_H8) -// SPI +// SPI buses +#define MICROPY_HW_SPI1_NSS (pin_C13) +#define MICROPY_HW_SPI1_SCK (pin_B3) +#define MICROPY_HW_SPI1_MISO (pin_B4) +#define MICROPY_HW_SPI1_MOSI (pin_D7) + #define MICROPY_HW_SPI2_NSS (pin_I0) #define MICROPY_HW_SPI2_SCK (pin_I1) #define MICROPY_HW_SPI2_MISO (pin_C2) From ac8e7f7b67ea13e7e9f816d3cfd4ddae4782db8d Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 5 Feb 2024 13:05:29 +1100 Subject: [PATCH 089/408] docs/library/ssl: Change wrap_socket args keyfile/certfile to key/cert. So they match the code in extmod/modssl_*.c. Signed-off-by: Damien George --- docs/library/ssl.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/library/ssl.rst b/docs/library/ssl.rst index f9be27745379b..dff90b8da58b9 100644 --- a/docs/library/ssl.rst +++ b/docs/library/ssl.rst @@ -13,7 +13,7 @@ facilities for network sockets, both client-side and server-side. Functions --------- -.. function:: ssl.wrap_socket(sock, server_side=False, keyfile=None, certfile=None, cert_reqs=CERT_NONE, cadata=None, server_hostname=None, do_handshake=True) +.. function:: ssl.wrap_socket(sock, server_side=False, key=None, cert=None, cert_reqs=CERT_NONE, cadata=None, server_hostname=None, do_handshake=True) Wrap the given *sock* and return a new wrapped-socket object. The implementation of this function is to first create an `SSLContext` and then call the `SSLContext.wrap_socket` From 23342eff906a99fc0a006916d350c86426fd9204 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Sun, 18 Dec 2022 18:26:32 -0600 Subject: [PATCH 090/408] windows/Makefile: Fix float exact int formatting on 32-bit mingw. When compiler optimizations are enabled on the mingw version of gcc, we are getting failing tests because of rounding issues, for example: print(float("1e24")) would print 9.999999999999999e+23 instead of 1e+24 It turns out special compiler options are needed to get GCC to use the SSE instruction set instead of the 387 coprocessor (which uses 80-bit precision internall). Signed-off-by: David Lechner --- ports/windows/Makefile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ports/windows/Makefile b/ports/windows/Makefile index 94bd3f99f9415..bb635167da349 100644 --- a/ports/windows/Makefile +++ b/ports/windows/Makefile @@ -86,6 +86,15 @@ ifneq ($(FROZEN_MANIFEST),) CFLAGS += -DMPZ_DIG_SIZE=16 endif +ifeq ($(shell $(CC) -dumpmachine),i686-w64-mingw32) +# GCC disables the SSE instruction set by default on i366 targets and we have +# to specify all three of these options to enable it. +# https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html (see -mfpmath=unit section) +# Enabling the SSE instruction set is necessary to get correct rounding of floating points. +# https://lemire.me/blog/2020/06/26/gcc-not-nearest +CFLAGS += -msse -mfpmath=sse -march=pentium4 +endif + CXXFLAGS += $(filter-out -std=gnu99,$(CFLAGS)) include $(TOP)/py/mkrules.mk From ed15b3c6c67f4626dde1ac4281978b3bef1c72ce Mon Sep 17 00:00:00 2001 From: David Lechner Date: Sat, 17 Dec 2022 15:09:37 -0600 Subject: [PATCH 091/408] github/workflows: Move Windows CI from AppVeyor to GitHub Actions. By moving to GitHub actions, all MicroPython CI builds are now on GitHub actions. This allows faster parallel builds and saves time by not building when no relevant files changed. This reveals a few failing tests, so those are temporarily disabled until they can be fixed. Signed-off-by: David Lechner Signed-off-by: Damien George --- .github/workflows/ports_windows.yml | 127 +++++++++++++++++++++++++++- ports/windows/.appveyor.yml | 90 -------------------- tests/run-tests.py | 8 ++ 3 files changed, 134 insertions(+), 91 deletions(-) delete mode 100644 ports/windows/.appveyor.yml diff --git a/.github/workflows/ports_windows.yml b/.github/workflows/ports_windows.yml index 4b1f4ea791e20..6858a146c42d1 100644 --- a/.github/workflows/ports_windows.yml +++ b/.github/workflows/ports_windows.yml @@ -18,7 +18,132 @@ concurrency: cancel-in-progress: true jobs: - build: + build-vs: + strategy: + fail-fast: false + matrix: + platform: [x86, x64] + configuration: [Debug, Release] + variant: [dev, standard] + visualstudio: ['2017', '2019', '2022'] + include: + - visualstudio: '2017' + runner: windows-latest + vs_version: '[15, 16)' + - visualstudio: '2019' + runner: windows-2019 + vs_version: '[16, 17)' + - visualstudio: '2022' + runner: windows-2022 + vs_version: '[17, 18)' + # trim down the number of jobs in the matrix + exclude: + - variant: standard + configuration: Debug + - visualstudio: '2019' + configuration: Debug + runs-on: ${{ matrix.runner }} + steps: + - name: Install Visual Studio 2017 + if: matrix.visualstudio == '2017' + run: | + choco install visualstudio2017buildtools + choco install visualstudio2017-workload-vctools + choco install windows-sdk-8.1 + - uses: microsoft/setup-msbuild@v1 + with: + vs-version: ${{ matrix.vs_version }} + - uses: actions/setup-python@v4 + if: matrix.runner == 'windows-2019' + with: + python-version: '3.9' + - uses: actions/checkout@v3 + - name: Build mpy-cross.exe + run: msbuild mpy-cross\mpy-cross.vcxproj -maxcpucount -property:Configuration=${{ matrix.configuration }} -property:Platform=${{ matrix.platform }} + - name: Build micropython.exe + run: msbuild ports\windows\micropython.vcxproj -maxcpucount -property:Configuration=${{ matrix.configuration }} -property:Platform=${{ matrix.platform }} -property:PyVariant=${{ matrix.variant }} + - name: Get micropython.exe path + id: get_path + run: | + $exePath="$(msbuild ports\windows\micropython.vcxproj -nologo -v:m -t:ShowTargetPath -property:Configuration=${{ matrix.configuration }} -property:Platform=${{ matrix.platform }} -property:PyVariant=${{ matrix.variant }})" + echo ("micropython=" + $exePath.Trim()) >> $env:GITHUB_OUTPUT + - name: Run tests + id: test + env: + MICROPY_MICROPYTHON: ${{ steps.get_path.outputs.micropython }} + working-directory: tests + run: python run-tests.py + - name: Print failures + if: failure() && steps.test.conclusion == 'failure' + working-directory: tests + run: python run-tests.py --print-failures + - name: Run mpy tests + id: test_mpy + env: + MICROPY_MICROPYTHON: ${{ steps.get_path.outputs.micropython }} + working-directory: tests + run: python run-tests.py --via-mpy -d basics float micropython + - name: Print mpy failures + if: failure() && steps.test_mpy.conclusion == 'failure' + working-directory: tests + run: python run-tests.py --print-failures + + build-mingw: + strategy: + fail-fast: false + matrix: + variant: [dev, standard] + sys: [mingw32, mingw64] + include: + - sys: mingw32 + env: i686 + - sys: mingw64 + env: x86_64 + runs-on: windows-2022 + env: + CHERE_INVOKING: enabled_from_arguments + defaults: + run: + shell: msys2 {0} + steps: + - name: Get Python path + id: python_path + shell: python + run: | + import os + import sys + output = f"python={os.fspath(sys.executable)}" + print(output) + with open(os.environ["GITHUB_OUTPUT"], "w") as f: + f.write(output) + - uses: msys2/setup-msys2@v2 + with: + msystem: ${{ matrix.sys }} + update: true + install: >- + make + mingw-w64-${{ matrix.env }}-gcc + pkg-config + python3 + git + diffutils + - uses: actions/checkout@v3 + - name: Build mpy-cross.exe + run: make -C mpy-cross -j2 + - name: Update submodules + run: make -C ports/windows VARIANT=${{ matrix.variant }} submodules + - name: Build micropython.exe + run: make -C ports/windows -j2 VARIANT=${{ matrix.variant }} + - name: Run tests + id: test + # msys python breaks tests so we need to use "real" windows python + run: MICROPY_CPYTHON3=$(cygpath "${{ steps.python_path.outputs.python }}") make -C ports/windows test_full VARIANT=${{ matrix.variant }} + - name: Print failures + if: failure() && steps.test.conclusion == 'failure' + working-directory: tests + run: python run-tests.py --print-failures + + cross-build-on-linux: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/ports/windows/.appveyor.yml b/ports/windows/.appveyor.yml deleted file mode 100644 index c1a114a0f8978..0000000000000 --- a/ports/windows/.appveyor.yml +++ /dev/null @@ -1,90 +0,0 @@ -image: Visual Studio 2017 -clone_depth: 1 -skip_tags: true - -environment: - # Python version used - MICROPY_CPYTHON3: c:/python38/python.exe - # The variants. - matrix: - - PyVariant: dev - - PyVariant: standard - -init: - # Set build version number to commit to be travis-like -- ps: Update-AppveyorBuild -Version $env:appveyor_repo_commit.substring(0,8) - -configuration: -- Debug -- Release - -platform: -- x86 -- x64 - -matrix: - # One debug build is enough. - exclude: - - configuration: Debug - PyVariant: dev - -before_build: -- ps: | - @" - - - - - - - "@ | Set-Content build.proj - -build: - project: build.proj - parallel: true - verbosity: normal - -test_script: -- ps: | - $env:MICROPY_MICROPYTHON=(msbuild ports\windows\micropython.vcxproj /nologo /v:m /t:ShowTargetPath).Trim() - cd (Join-Path $env:APPVEYOR_BUILD_FOLDER 'tests') - & $env:MICROPY_CPYTHON3 run-tests.py - if ($LASTEXITCODE -ne 0) { - & $env:MICROPY_CPYTHON3 run-tests.py --print-failures - throw "Test failure" - } - & $env:MICROPY_CPYTHON3 run-tests.py --via-mpy -d basics float micropython - if ($LASTEXITCODE -ne 0) { - & $env:MICROPY_CPYTHON3 run-tests.py --print-failures - throw "Test failure" - } - -# After the build/test phase for the MSVC build completes, -# build and test with mingw-w64, release versions only. -after_test: -- ps: | - if ($env:configuration -eq 'Debug') { - return - } - $env:MSYSTEM = if ($platform -eq 'x86') {'MINGW32'} else {'MINGW64'} - $env:CHERE_INVOKING = 'enabled_from_arguments' - cd (Join-Path $env:APPVEYOR_BUILD_FOLDER 'mpy-cross') - C:\msys64\usr\bin\bash.exe -l -c "make -B -j4 V=1" - if ($LASTEXITCODE -ne 0) { - throw "$env:MSYSTEM mpy_cross build exited with code $LASTEXITCODE" - } - cd (Join-Path $env:APPVEYOR_BUILD_FOLDER 'ports/windows') - C:\msys64\usr\bin\bash.exe -l -c "make -B VARIANT=$($env:PyVariant) submodules" - if ($LASTEXITCODE -ne 0) { - throw "$env:MSYSTEM build exited with code $LASTEXITCODE" - } - C:\msys64\usr\bin\bash.exe -l -c "make -B -j4 V=1 MICROPY_MPYCROSS=../../mpy-cross/build/mpy-cross.exe VARIANT=$($env:PyVariant)" - if ($LASTEXITCODE -ne 0) { - throw "$env:MSYSTEM build exited with code $LASTEXITCODE" - } - C:\msys64\usr\bin\bash.exe -l -c "make V=1 test_full VARIANT=$($env:PyVariant)" - if ($LASTEXITCODE -ne 0) { - cd (Join-Path $env:APPVEYOR_BUILD_FOLDER 'tests') - & $env:MICROPY_CPYTHON3 run-tests.py --print-failures - throw "Test failure" - } diff --git a/tests/run-tests.py b/tests/run-tests.py index ecd49a7d75fea..c912f9d5424df 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -532,6 +532,14 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): if os.getenv("GITHUB_ACTIONS") == "true": skip_tests.add("thread/stress_schedule.py") # has reliability issues + if os.getenv("RUNNER_OS") == "Windows": + # fails with stack overflow on Debug builds + skip_tests.add("misc/sys_settrace_features.py") + + if os.getenv("MSYSTEM") is not None: + # fails due to wrong path separator + skip_tests.add("import/import_file.py") + if upy_float_precision == 0: skip_tests.add("extmod/uctypes_le_float.py") skip_tests.add("extmod/uctypes_native_float.py") From 5a68e82d1729db0a372b5fa20030a2a7b1a6e788 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 7 Feb 2024 11:28:52 +1100 Subject: [PATCH 092/408] github/workflows: Bump setup-msbuild, setup-python, checkout versions. Signed-off-by: Damien George --- .github/workflows/ports_windows.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ports_windows.yml b/.github/workflows/ports_windows.yml index 6858a146c42d1..cb125cc6d21a5 100644 --- a/.github/workflows/ports_windows.yml +++ b/.github/workflows/ports_windows.yml @@ -50,14 +50,14 @@ jobs: choco install visualstudio2017buildtools choco install visualstudio2017-workload-vctools choco install windows-sdk-8.1 - - uses: microsoft/setup-msbuild@v1 + - uses: microsoft/setup-msbuild@v2 with: vs-version: ${{ matrix.vs_version }} - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 if: matrix.runner == 'windows-2019' with: python-version: '3.9' - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build mpy-cross.exe run: msbuild mpy-cross\mpy-cross.vcxproj -maxcpucount -property:Configuration=${{ matrix.configuration }} -property:Platform=${{ matrix.platform }} - name: Build micropython.exe @@ -127,7 +127,7 @@ jobs: python3 git diffutils - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build mpy-cross.exe run: make -C mpy-cross -j2 - name: Update submodules From ff736830773371c4f616a1b5aa423a7ba4a57191 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 7 Feb 2024 12:50:34 +1100 Subject: [PATCH 093/408] github/workflows: Initialise micropython-lib submodule for windows CI. Signed-off-by: Damien George --- .github/workflows/ports_windows.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ports_windows.yml b/.github/workflows/ports_windows.yml index cb125cc6d21a5..a2759880a2f65 100644 --- a/.github/workflows/ports_windows.yml +++ b/.github/workflows/ports_windows.yml @@ -60,6 +60,8 @@ jobs: - uses: actions/checkout@v4 - name: Build mpy-cross.exe run: msbuild mpy-cross\mpy-cross.vcxproj -maxcpucount -property:Configuration=${{ matrix.configuration }} -property:Platform=${{ matrix.platform }} + - name: Update submodules + run: git submodule update --init lib/micropython-lib - name: Build micropython.exe run: msbuild ports\windows\micropython.vcxproj -maxcpucount -property:Configuration=${{ matrix.configuration }} -property:Platform=${{ matrix.platform }} -property:PyVariant=${{ matrix.variant }} - name: Get micropython.exe path From c68462d9967aec0c36345b54ebd22b559aa55ca0 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 7 Feb 2024 12:20:13 +1100 Subject: [PATCH 094/408] lib/micropython-lib: Update submodule to latest. Signed-off-by: Damien George --- lib/micropython-lib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/micropython-lib b/lib/micropython-lib index 7cdf70881519c..ddb1a279578bf 160000 --- a/lib/micropython-lib +++ b/lib/micropython-lib @@ -1 +1 @@ -Subproject commit 7cdf70881519c73667efbc4a61a04d9c1a49babb +Subproject commit ddb1a279578bfff8c1b18aff3baa668620684f64 From f8f1f29ac0b5ef837e7c277b2777080c1d82e080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20D=C3=B6rre?= Date: Thu, 1 Feb 2024 12:07:06 +0000 Subject: [PATCH 095/408] extmod/modssl_axtls: Add SSLContext.load_cert_chain(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To match the mbedtls implementation. Signed-off-by: Felix Dörre --- extmod/modssl_axtls.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/extmod/modssl_axtls.c b/extmod/modssl_axtls.c index 6cb999c13b69f..0368cb93051cc 100644 --- a/extmod/modssl_axtls.c +++ b/extmod/modssl_axtls.c @@ -161,6 +161,14 @@ STATIC void ssl_context_load_key(mp_obj_ssl_context_t *self, mp_obj_t key_obj, m self->cert = cert_obj; } +// SSLContext.load_cert_chain(certfile, keyfile) +STATIC mp_obj_t ssl_context_load_cert_chain(mp_obj_t self_in, mp_obj_t cert, mp_obj_t pkey) { + mp_obj_ssl_context_t *self = MP_OBJ_TO_PTR(self_in); + ssl_context_load_key(self, pkey, cert); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_3(ssl_context_load_cert_chain_obj, ssl_context_load_cert_chain); + STATIC mp_obj_t ssl_context_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_server_side, ARG_do_handshake_on_connect, ARG_server_hostname }; static const mp_arg_t allowed_args[] = { @@ -182,6 +190,7 @@ STATIC mp_obj_t ssl_context_wrap_socket(size_t n_args, const mp_obj_t *pos_args, STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ssl_context_wrap_socket_obj, 2, ssl_context_wrap_socket); STATIC const mp_rom_map_elem_t ssl_context_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_load_cert_chain), MP_ROM_PTR(&ssl_context_load_cert_chain_obj)}, { MP_ROM_QSTR(MP_QSTR_wrap_socket), MP_ROM_PTR(&ssl_context_wrap_socket_obj) }, }; STATIC MP_DEFINE_CONST_DICT(ssl_context_locals_dict, ssl_context_locals_dict_table); From b802f0f8abf3c198d4d373d934f4ab13ec1552f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20D=C3=B6rre?= Date: Thu, 1 Feb 2024 12:07:06 +0000 Subject: [PATCH 096/408] extmod/modtls: Move the native ssl module to tls. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current `ssl` module has quite a few differences to the CPython implementation. This change moves the MicroPython variant to a new `tls` module and provides a wrapper module for `ssl` (in micropython-lib). Users who only rely on implemented comparible behavior can continue to use `ssl`, while users that rely on non-compatible behavior should switch to `tls`. Then we can make the facade in `ssl` more strictly adhere to CPython. Signed-off-by: Felix Dörre --- extmod/extmod.cmake | 4 +- extmod/extmod.mk | 4 +- extmod/{modssl_axtls.c => modtls_axtls.c} | 52 +------ extmod/{modssl_mbedtls.c => modtls_mbedtls.c} | 132 ++---------------- ports/unix/variants/coverage/manifest.py | 1 + ports/unix/variants/manifest.py | 1 + ports/windows/variants/manifest.py | 1 + .../variants/standard/mpconfigvariant.props | 3 + ...t_ciphers.py => tls_sslcontext_ciphers.py} | 6 +- ...s.py.exp => tls_sslcontext_ciphers.py.exp} | 0 ...ython.py => tls_sslcontext_micropython.py} | 8 +- ....exp => tls_sslcontext_micropython.py.exp} | 0 .../sslcontext_server_client_ciphers.py | 16 ++- tests/ports/unix/extra_coverage.py.exp | 4 +- 14 files changed, 49 insertions(+), 183 deletions(-) rename extmod/{modssl_axtls.c => modtls_axtls.c} (87%) rename extmod/{modssl_mbedtls.c => modtls_mbedtls.c} (85%) rename tests/extmod/{ssl_sslcontext_ciphers.py => tls_sslcontext_ciphers.py} (79%) rename tests/extmod/{ssl_sslcontext_ciphers.py.exp => tls_sslcontext_ciphers.py.exp} (100%) rename tests/extmod/{ssl_sslcontext_micropython.py => tls_sslcontext_micropython.py} (82%) rename tests/extmod/{ssl_sslcontext_micropython.py.exp => tls_sslcontext_micropython.py.exp} (100%) diff --git a/extmod/extmod.cmake b/extmod/extmod.cmake index a55cd76f88bc9..d73ff258ffd9f 100644 --- a/extmod/extmod.cmake +++ b/extmod/extmod.cmake @@ -39,8 +39,8 @@ set(MICROPY_SOURCE_EXTMOD ${MICROPY_EXTMOD_DIR}/modre.c ${MICROPY_EXTMOD_DIR}/modselect.c ${MICROPY_EXTMOD_DIR}/modsocket.c - ${MICROPY_EXTMOD_DIR}/modssl_axtls.c - ${MICROPY_EXTMOD_DIR}/modssl_mbedtls.c + ${MICROPY_EXTMOD_DIR}/modtls_axtls.c + ${MICROPY_EXTMOD_DIR}/modtls_mbedtls.c ${MICROPY_EXTMOD_DIR}/modtime.c ${MICROPY_EXTMOD_DIR}/modwebsocket.c ${MICROPY_EXTMOD_DIR}/modwebrepl.c diff --git a/extmod/extmod.mk b/extmod/extmod.mk index fdaa3d930588c..b3246bc0d9546 100644 --- a/extmod/extmod.mk +++ b/extmod/extmod.mk @@ -36,8 +36,8 @@ SRC_EXTMOD_C += \ extmod/modre.c \ extmod/modselect.c \ extmod/modsocket.c \ - extmod/modssl_axtls.c \ - extmod/modssl_mbedtls.c \ + extmod/modtls_axtls.c \ + extmod/modtls_mbedtls.c \ extmod/modtime.c \ extmod/moductypes.c \ extmod/modwebrepl.c \ diff --git a/extmod/modssl_axtls.c b/extmod/modtls_axtls.c similarity index 87% rename from extmod/modssl_axtls.c rename to extmod/modtls_axtls.c index 0368cb93051cc..1ac40208db003 100644 --- a/extmod/modssl_axtls.c +++ b/extmod/modtls_axtls.c @@ -422,48 +422,8 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( /******************************************************************************/ // ssl module. -STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { - ARG_key, - ARG_cert, - ARG_server_side, - ARG_server_hostname, - ARG_do_handshake, - }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_key, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, - { MP_QSTR_cert, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, - { MP_QSTR_server_side, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, - { MP_QSTR_server_hostname, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, - { MP_QSTR_do_handshake, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} }, - }; - - // Parse arguments. - mp_obj_t sock = pos_args[0]; - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - // Create SSLContext. - mp_int_t protocol = args[ARG_server_side].u_bool ? PROTOCOL_TLS_SERVER : PROTOCOL_TLS_CLIENT; - mp_obj_t ssl_context_args[1] = { MP_OBJ_NEW_SMALL_INT(protocol) }; - mp_obj_ssl_context_t *ssl_context = MP_OBJ_TO_PTR(ssl_context_make_new(&ssl_context_type, 1, 0, ssl_context_args)); - - // Load key and cert if given. - if (args[ARG_key].u_obj != mp_const_none) { - ssl_context_load_key(ssl_context, args[ARG_key].u_obj, args[ARG_cert].u_obj); - } - - // Create and return the new SSLSocket object. - return ssl_socket_make_new(ssl_context, sock, args[ARG_server_side].u_bool, - args[ARG_do_handshake].u_bool, args[ARG_server_hostname].u_obj); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_ssl_wrap_socket_obj, 1, mod_ssl_wrap_socket); - -STATIC const mp_rom_map_elem_t mp_module_ssl_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ssl) }, - - // Functions. - { MP_ROM_QSTR(MP_QSTR_wrap_socket), MP_ROM_PTR(&mod_ssl_wrap_socket_obj) }, +STATIC const mp_rom_map_elem_t mp_module_tls_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_tls) }, // Classes. { MP_ROM_QSTR(MP_QSTR_SSLContext), MP_ROM_PTR(&ssl_context_type) }, @@ -472,13 +432,13 @@ STATIC const mp_rom_map_elem_t mp_module_ssl_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_PROTOCOL_TLS_CLIENT), MP_ROM_INT(PROTOCOL_TLS_CLIENT) }, { MP_ROM_QSTR(MP_QSTR_PROTOCOL_TLS_SERVER), MP_ROM_INT(PROTOCOL_TLS_SERVER) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_ssl_globals, mp_module_ssl_globals_table); +STATIC MP_DEFINE_CONST_DICT(mp_module_tls_globals, mp_module_tls_globals_table); -const mp_obj_module_t mp_module_ssl = { +const mp_obj_module_t mp_module_tls = { .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&mp_module_ssl_globals, + .globals = (mp_obj_dict_t *)&mp_module_tls_globals, }; -MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_ssl, mp_module_ssl); +MP_REGISTER_MODULE(MP_QSTR_tls, mp_module_tls); #endif // MICROPY_PY_SSL && MICROPY_SSL_AXTLS diff --git a/extmod/modssl_mbedtls.c b/extmod/modtls_mbedtls.c similarity index 85% rename from extmod/modssl_mbedtls.c rename to extmod/modtls_mbedtls.c index b6275d8d88fb7..a0f2cd1699486 100644 --- a/extmod/modssl_mbedtls.c +++ b/extmod/modtls_mbedtls.c @@ -91,24 +91,6 @@ STATIC mp_obj_t ssl_socket_make_new(mp_obj_ssl_context_t *ssl_context, mp_obj_t /******************************************************************************/ // Helper functions. -STATIC mp_obj_t read_file(mp_obj_t self_in) { - // file = open(args[0], "rb") - mp_obj_t f_args[2] = { - self_in, - MP_OBJ_NEW_QSTR(MP_QSTR_rb), - }; - mp_obj_t file = mp_vfs_open(2, &f_args[0], (mp_map_t *)&mp_const_empty_map); - - // data = file.read() - mp_obj_t dest[2]; - mp_load_method(file, MP_QSTR_read, dest); - mp_obj_t data = mp_call_method_n_kw(0, 0, dest); - - // file.close() - mp_stream_close(file); - return data; -} - #ifdef MBEDTLS_DEBUG_C STATIC void mbedtls_debug(void *ctx, int level, const char *file, int line, const char *str) { (void)ctx; @@ -256,9 +238,7 @@ STATIC mp_obj_t ssl_context_make_new(const mp_obj_type_t *type_in, size_t n_args } if (endpoint == MBEDTLS_SSL_IS_CLIENT) { - // The CPython default is MBEDTLS_SSL_VERIFY_REQUIRED, but to maintain - // backwards compatibility we use MBEDTLS_SSL_VERIFY_NONE for now. - self->authmode = MBEDTLS_SSL_VERIFY_NONE; + self->authmode = MBEDTLS_SSL_VERIFY_REQUIRED; } else { self->authmode = MBEDTLS_SSL_VERIFY_NONE; } @@ -376,25 +356,9 @@ STATIC void ssl_context_load_key(mp_obj_ssl_context_t *self, mp_obj_t key_obj, m } // SSLContext.load_cert_chain(certfile, keyfile) -STATIC mp_obj_t ssl_context_load_cert_chain(mp_obj_t self_in, mp_obj_t certfile, mp_obj_t keyfile) { +STATIC mp_obj_t ssl_context_load_cert_chain(mp_obj_t self_in, mp_obj_t cert, mp_obj_t pkey) { mp_obj_ssl_context_t *self = MP_OBJ_TO_PTR(self_in); - mp_obj_t pkey; - mp_obj_t cert; - if (certfile != mp_const_none) { - // check if key is a string/path - if (!(mp_obj_is_type(keyfile, &mp_type_bytes))) { - pkey = read_file(keyfile); - } else { - pkey = keyfile; - } - // check if cert is a string/path - if (!(mp_obj_is_type(certfile, &mp_type_bytes))) { - cert = read_file(certfile); - } else { - cert = certfile; - } - ssl_context_load_key(self, pkey, cert); - } + ssl_context_load_key(self, pkey, cert); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_3(ssl_context_load_cert_chain_obj, ssl_context_load_cert_chain); @@ -411,29 +375,14 @@ STATIC void ssl_context_load_cadata(mp_obj_ssl_context_t *self, mp_obj_t cadata_ mbedtls_ssl_conf_ca_chain(&self->conf, &self->cacert, NULL); } -// SSLContext.load_verify_locations(cafile=None, *, cadata=None) -STATIC mp_obj_t ssl_context_load_verify_locations(size_t n_args, const mp_obj_t *pos_args, - mp_map_t *kw_args) { +// SSLContext.load_verify_locations(cadata) +STATIC mp_obj_t ssl_context_load_verify_locations(mp_obj_t self_in, mp_obj_t cadata) { - static const mp_arg_t allowed_args[] = { - { MP_QSTR_cafile, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, - { MP_QSTR_cadata, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, - }; - - mp_obj_ssl_context_t *self = MP_OBJ_TO_PTR(pos_args[0]); - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - // cafile - if (args[0].u_obj != mp_const_none) { - ssl_context_load_cadata(self, read_file(args[0].u_obj)); - } - // cadata - if (args[1].u_obj != mp_const_none) { - ssl_context_load_cadata(self, args[1].u_obj); - } + mp_obj_ssl_context_t *self = MP_OBJ_TO_PTR(self_in); + ssl_context_load_cadata(self, cadata); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ssl_context_load_verify_locations_obj, 1, ssl_context_load_verify_locations); +STATIC MP_DEFINE_CONST_FUN_OBJ_2(ssl_context_load_verify_locations_obj, ssl_context_load_verify_locations); STATIC mp_obj_t ssl_context_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_server_side, ARG_do_handshake_on_connect, ARG_server_hostname }; @@ -788,61 +737,8 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( /******************************************************************************/ // ssl module. -STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { - ARG_key, - ARG_cert, - ARG_server_side, - ARG_server_hostname, - ARG_cert_reqs, - ARG_cadata, - ARG_do_handshake, - }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_key, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, - { MP_QSTR_cert, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, - { MP_QSTR_server_side, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, - { MP_QSTR_server_hostname, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, - { MP_QSTR_cert_reqs, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = MBEDTLS_SSL_VERIFY_NONE}}, - { MP_QSTR_cadata, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, - { MP_QSTR_do_handshake, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} }, - }; - - // Parse arguments. - mp_obj_t sock = pos_args[0]; - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - // Create SSLContext. - mp_int_t protocol = args[ARG_server_side].u_bool ? MBEDTLS_SSL_IS_SERVER : MBEDTLS_SSL_IS_CLIENT; - mp_obj_t ssl_context_args[1] = { MP_OBJ_NEW_SMALL_INT(protocol) }; - mp_obj_ssl_context_t *ssl_context = MP_OBJ_TO_PTR(ssl_context_make_new(&ssl_context_type, 1, 0, ssl_context_args)); - - // Load key and cert if given. - if (args[ARG_key].u_obj != mp_const_none) { - ssl_context_load_key(ssl_context, args[ARG_key].u_obj, args[ARG_cert].u_obj); - } - - // Set the verify_mode. - mp_obj_t dest[2] = { MP_OBJ_SENTINEL, MP_OBJ_NEW_SMALL_INT(args[ARG_cert_reqs].u_int) }; - ssl_context_attr(MP_OBJ_FROM_PTR(ssl_context), MP_QSTR_verify_mode, dest); - - // Load cadata if given. - if (args[ARG_cadata].u_obj != mp_const_none) { - ssl_context_load_cadata(ssl_context, args[ARG_cadata].u_obj); - } - - // Create and return the new SSLSocket object. - return ssl_socket_make_new(ssl_context, sock, args[ARG_server_side].u_bool, - args[ARG_do_handshake].u_bool, args[ARG_server_hostname].u_obj); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_ssl_wrap_socket_obj, 1, mod_ssl_wrap_socket); - -STATIC const mp_rom_map_elem_t mp_module_ssl_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ssl) }, - - // Functions. - { MP_ROM_QSTR(MP_QSTR_wrap_socket), MP_ROM_PTR(&mod_ssl_wrap_socket_obj) }, +STATIC const mp_rom_map_elem_t mp_module_tls_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_tls) }, // Classes. { MP_ROM_QSTR(MP_QSTR_SSLContext), MP_ROM_PTR(&ssl_context_type) }, @@ -855,13 +751,13 @@ STATIC const mp_rom_map_elem_t mp_module_ssl_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_CERT_OPTIONAL), MP_ROM_INT(MBEDTLS_SSL_VERIFY_OPTIONAL) }, { MP_ROM_QSTR(MP_QSTR_CERT_REQUIRED), MP_ROM_INT(MBEDTLS_SSL_VERIFY_REQUIRED) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_ssl_globals, mp_module_ssl_globals_table); +STATIC MP_DEFINE_CONST_DICT(mp_module_tls_globals, mp_module_tls_globals_table); -const mp_obj_module_t mp_module_ssl = { +const mp_obj_module_t mp_module_tls = { .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&mp_module_ssl_globals, + .globals = (mp_obj_dict_t *)&mp_module_tls_globals, }; -MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_ssl, mp_module_ssl); +MP_REGISTER_MODULE(MP_QSTR_tls, mp_module_tls); #endif // MICROPY_PY_SSL && MICROPY_SSL_MBEDTLS diff --git a/ports/unix/variants/coverage/manifest.py b/ports/unix/variants/coverage/manifest.py index 7c3d9a6b64d69..556d445d752ea 100644 --- a/ports/unix/variants/coverage/manifest.py +++ b/ports/unix/variants/coverage/manifest.py @@ -1,3 +1,4 @@ freeze_as_str("frzstr") freeze_as_mpy("frzmpy") freeze_mpy("$(MPY_DIR)/tests/frozen") +require("ssl") diff --git a/ports/unix/variants/manifest.py b/ports/unix/variants/manifest.py index f8e8f250ac653..88cc1ad8e50ef 100644 --- a/ports/unix/variants/manifest.py +++ b/ports/unix/variants/manifest.py @@ -1 +1,2 @@ require("mip-cmdline") +require("ssl") diff --git a/ports/windows/variants/manifest.py b/ports/windows/variants/manifest.py index e69de29bb2d1d..dab999e40ebda 100644 --- a/ports/windows/variants/manifest.py +++ b/ports/windows/variants/manifest.py @@ -0,0 +1 @@ +require("ssl") diff --git a/ports/windows/variants/standard/mpconfigvariant.props b/ports/windows/variants/standard/mpconfigvariant.props index 9296da44bc263..ea8bf0bc827bb 100644 --- a/ports/windows/variants/standard/mpconfigvariant.props +++ b/ports/windows/variants/standard/mpconfigvariant.props @@ -1,3 +1,6 @@ + + $(PyWinDir)\variants\manifest.py + diff --git a/tests/extmod/ssl_sslcontext_ciphers.py b/tests/extmod/tls_sslcontext_ciphers.py similarity index 79% rename from tests/extmod/ssl_sslcontext_ciphers.py rename to tests/extmod/tls_sslcontext_ciphers.py index 20c00b917623c..43f94fb19a559 100644 --- a/tests/extmod/ssl_sslcontext_ciphers.py +++ b/tests/extmod/tls_sslcontext_ciphers.py @@ -1,13 +1,13 @@ -# Basic test of ssl.SSLContext get_ciphers() and set_ciphers() methods. +# Basic test of tls.SSLContext get_ciphers() and set_ciphers() methods. try: - import ssl + import tls except ImportError: print("SKIP") raise SystemExit -ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) +ctx = tls.SSLContext(tls.PROTOCOL_TLS_CLIENT) ciphers = ctx.get_ciphers() diff --git a/tests/extmod/ssl_sslcontext_ciphers.py.exp b/tests/extmod/tls_sslcontext_ciphers.py.exp similarity index 100% rename from tests/extmod/ssl_sslcontext_ciphers.py.exp rename to tests/extmod/tls_sslcontext_ciphers.py.exp diff --git a/tests/extmod/ssl_sslcontext_micropython.py b/tests/extmod/tls_sslcontext_micropython.py similarity index 82% rename from tests/extmod/ssl_sslcontext_micropython.py rename to tests/extmod/tls_sslcontext_micropython.py index 136fb8a054ed7..e188f89b8d337 100644 --- a/tests/extmod/ssl_sslcontext_micropython.py +++ b/tests/extmod/tls_sslcontext_micropython.py @@ -1,20 +1,20 @@ -# Test MicroPython-specific behaviour of ssl.SSLContext. +# Test MicroPython-specific behaviour of tls.SSLContext. try: - import ssl + import tls except ImportError: print("SKIP") raise SystemExit # Test constructing without any arguments (in CPython it's a DeprecationWarning). try: - ssl.SSLContext() + tls.SSLContext() except TypeError: print("TypeError") # Test attributes that don't exist (in CPython new attributes can be added). # This test is needed for coverage because SSLContext implements a custom attr handler. -ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) +ctx = tls.SSLContext(tls.PROTOCOL_TLS_CLIENT) try: ctx.does_not_exist except AttributeError: diff --git a/tests/extmod/ssl_sslcontext_micropython.py.exp b/tests/extmod/tls_sslcontext_micropython.py.exp similarity index 100% rename from tests/extmod/ssl_sslcontext_micropython.py.exp rename to tests/extmod/tls_sslcontext_micropython.py.exp diff --git a/tests/multi_net/sslcontext_server_client_ciphers.py b/tests/multi_net/sslcontext_server_client_ciphers.py index d65d860fb2745..c168b444a992b 100644 --- a/tests/multi_net/sslcontext_server_client_ciphers.py +++ b/tests/multi_net/sslcontext_server_client_ciphers.py @@ -3,7 +3,7 @@ try: import os import socket - import ssl + import tls except ImportError: print("SKIP") raise SystemExit @@ -13,6 +13,10 @@ # These are test certificates. See tests/README.md for details. cert = cafile = "ec_cert.der" key = "ec_key.der" +with open(cafile, "rb") as f: + cadata = f.read() +with open(key, "rb") as f: + keydata = f.read() try: os.stat(cafile) @@ -31,8 +35,8 @@ def instance0(): s.listen(1) multitest.next() s2, _ = s.accept() - server_ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) - server_ctx.load_cert_chain(cert, key) + server_ctx = tls.SSLContext(tls.PROTOCOL_TLS_SERVER) + server_ctx.load_cert_chain(cadata, keydata) s2 = server_ctx.wrap_socket(s2, server_side=True) assert isinstance(s2.cipher(), tuple) print(s2.read(16)) @@ -46,12 +50,12 @@ def instance1(): multitest.next() s = socket.socket() s.connect(socket.getaddrinfo(IP, PORT)[0][-1]) - client_ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) + client_ctx = tls.SSLContext(tls.PROTOCOL_TLS_CLIENT) ciphers = client_ctx.get_ciphers() assert "TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" in ciphers client_ctx.set_ciphers(["TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256"]) - client_ctx.verify_mode = ssl.CERT_REQUIRED - client_ctx.load_verify_locations(cafile=cafile) + client_ctx.verify_mode = tls.CERT_REQUIRED + client_ctx.load_verify_locations(cadata) s = client_ctx.wrap_socket(s, server_hostname="micropython.local") s.write(b"client to server") print(s.read(16)) diff --git a/tests/ports/unix/extra_coverage.py.exp b/tests/ports/unix/extra_coverage.py.exp index b7e4c0d76008e..75c7c32df1284 100644 --- a/tests/ports/unix/extra_coverage.py.exp +++ b/tests/ports/unix/extra_coverage.py.exp @@ -57,8 +57,8 @@ deflate errno example_package ffi framebuf gc hashlib heapq io json machine math os platform random -re select socket ssl -struct sys termios time +re select socket struct +sys termios time tls uctypes websocket me From aaba1d8a6c8ee6edae0025df56055e309dd05234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20D=C3=B6rre?= Date: Thu, 1 Feb 2024 09:22:56 +0000 Subject: [PATCH 097/408] extmod/modtls_mbedtls: Implement cert verification callback for mbedtls. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a useful alternative to .getpeercert() when the certificate is not stored to reduce RAM usage. Signed-off-by: Felix Dörre --- extmod/modtls_mbedtls.c | 18 +++++ tests/multi_net/sslcontext_verify_callback.py | 68 +++++++++++++++++++ .../sslcontext_verify_callback.py.exp | 5 ++ tests/net_hosted/ssl_verify_callback.py | 37 ++++++++++ tests/net_hosted/ssl_verify_callback.py.exp | 5 ++ 5 files changed, 133 insertions(+) create mode 100644 tests/multi_net/sslcontext_verify_callback.py create mode 100644 tests/multi_net/sslcontext_verify_callback.py.exp create mode 100644 tests/net_hosted/ssl_verify_callback.py create mode 100644 tests/net_hosted/ssl_verify_callback.py.exp diff --git a/extmod/modtls_mbedtls.c b/extmod/modtls_mbedtls.c index a0f2cd1699486..6cb4f002051b4 100644 --- a/extmod/modtls_mbedtls.c +++ b/extmod/modtls_mbedtls.c @@ -67,6 +67,7 @@ typedef struct _mp_obj_ssl_context_t { mbedtls_pk_context pkey; int authmode; int *ciphersuites; + mp_obj_t handler; } mp_obj_ssl_context_t; // This corresponds to an SSLSocket object. @@ -188,6 +189,16 @@ STATIC void ssl_check_async_handshake_failure(mp_obj_ssl_socket_t *sslsock, int } } +STATIC int ssl_sock_cert_verify(void *ptr, mbedtls_x509_crt *crt, int depth, uint32_t *flags) { + mp_obj_ssl_context_t *o = ptr; + if (o->handler == mp_const_none) { + return 0; + } + mp_obj_array_t cert; + mp_obj_memoryview_init(&cert, 'B', 0, crt->raw.len, crt->raw.p); + return mp_obj_get_int(mp_call_function_2(o->handler, MP_OBJ_FROM_PTR(&cert), MP_OBJ_NEW_SMALL_INT(depth))); +} + /******************************************************************************/ // SSLContext type. @@ -213,6 +224,7 @@ STATIC mp_obj_t ssl_context_make_new(const mp_obj_type_t *type_in, size_t n_args mbedtls_x509_crt_init(&self->cert); mbedtls_pk_init(&self->pkey); self->ciphersuites = NULL; + self->handler = mp_const_none; #ifdef MBEDTLS_DEBUG_C // Debug level (0-4) 1=warning, 2=info, 3=debug, 4=verbose @@ -243,6 +255,7 @@ STATIC mp_obj_t ssl_context_make_new(const mp_obj_type_t *type_in, size_t n_args self->authmode = MBEDTLS_SSL_VERIFY_NONE; } mbedtls_ssl_conf_authmode(&self->conf, self->authmode); + mbedtls_ssl_conf_verify(&self->conf, &ssl_sock_cert_verify, self); mbedtls_ssl_conf_rng(&self->conf, mbedtls_ctr_drbg_random, &self->ctr_drbg); #ifdef MBEDTLS_DEBUG_C mbedtls_ssl_conf_dbg(&self->conf, mbedtls_debug, NULL); @@ -257,6 +270,8 @@ STATIC void ssl_context_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { // Load attribute. if (attr == MP_QSTR_verify_mode) { dest[0] = MP_OBJ_NEW_SMALL_INT(self->authmode); + } else if (attr == MP_QSTR_verify_callback) { + dest[0] = self->handler; } else { // Continue lookup in locals_dict. dest[1] = MP_OBJ_SENTINEL; @@ -267,6 +282,9 @@ STATIC void ssl_context_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { self->authmode = mp_obj_get_int(dest[1]); dest[0] = MP_OBJ_NULL; mbedtls_ssl_conf_authmode(&self->conf, self->authmode); + } else if (attr == MP_QSTR_verify_callback) { + dest[0] = MP_OBJ_NULL; + self->handler = dest[1]; } } } diff --git a/tests/multi_net/sslcontext_verify_callback.py b/tests/multi_net/sslcontext_verify_callback.py new file mode 100644 index 0000000000000..74b97382453bd --- /dev/null +++ b/tests/multi_net/sslcontext_verify_callback.py @@ -0,0 +1,68 @@ +# Test creating an SSL connection and getting the peer certificate. + +try: + import io + import os + import socket + import tls +except ImportError: + print("SKIP") + raise SystemExit + +PORT = 8000 + +# These are test certificates. See tests/README.md for details. +cert = cafile = "ec_cert.der" +key = "ec_key.der" + +try: + with open(cafile, "rb") as f: + cadata = f.read() + with open(key, "rb") as f: + key = f.read() +except OSError: + print("SKIP") + raise SystemExit + + +def verify_callback(cert, depth): + print(cert.hex()) + return 0 + + +# Server +def instance0(): + multitest.globals(IP=multitest.get_network_ip()) + s = socket.socket() + s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + s.bind(socket.getaddrinfo("0.0.0.0", PORT)[0][-1]) + s.listen(1) + multitest.next() + s2, _ = s.accept() + server_ctx = tls.SSLContext(tls.PROTOCOL_TLS_SERVER) + server_ctx.load_cert_chain(cadata, key) + s2 = server_ctx.wrap_socket(s2, server_side=True) + print(s2.read(16)) + s2.write(b"server to client") + s2.close() + s.close() + + +# Client +def instance1(): + s_test = tls.SSLContext(tls.PROTOCOL_TLS_CLIENT) + if not hasattr(s_test, "verify_callback"): + print("SKIP") + raise SystemExit + + multitest.next() + s = socket.socket() + s.connect(socket.getaddrinfo(IP, PORT)[0][-1]) + client_ctx = tls.SSLContext(tls.PROTOCOL_TLS_CLIENT) + client_ctx.verify_mode = tls.CERT_REQUIRED + client_ctx.verify_callback = verify_callback + client_ctx.load_verify_locations(cadata) + s = client_ctx.wrap_socket(s, server_hostname="micropython.local") + s.write(b"client to server") + print(s.read(16)) + s.close() diff --git a/tests/multi_net/sslcontext_verify_callback.py.exp b/tests/multi_net/sslcontext_verify_callback.py.exp new file mode 100644 index 0000000000000..e7a0ab0b4622c --- /dev/null +++ b/tests/multi_net/sslcontext_verify_callback.py.exp @@ -0,0 +1,5 @@ +--- instance0 --- +b'client to server' +--- instance1 --- +308201d330820179a00302010202144315a7cd8f69febe2640314e7c97d60a2523ad15300a06082a8648ce3d040302303f311a301806035504030c116d6963726f707974686f6e2e6c6f63616c31143012060355040a0c0b4d6963726f507974686f6e310b3009060355040613024155301e170d3234303131343034353335335a170d3235303131333034353335335a303f311a301806035504030c116d6963726f707974686f6e2e6c6f63616c31143012060355040a0c0b4d6963726f507974686f6e310b30090603550406130241553059301306072a8648ce3d020106082a8648ce3d0301070342000449b7f5fa687cb25a9464c397508149992f445c860bcf7002958eb4337636c6af840cd4c8cf3b96f2384860d8ae3ee3fa135dba051e8605e62bd871689c6af43ca3533051301d0603551d0e0416041441b3ae171d91e330411d8543ba45e0f2d5b2951b301f0603551d2304183016801441b3ae171d91e330411d8543ba45e0f2d5b2951b300f0603551d130101ff040530030101ff300a06082a8648ce3d04030203480030450220587f61c34739d6fab5802a674dcc54443ae9c87da374078c4ee1cd83f4ad1694022100cfc45dcf264888c6ba2c36e78bd27bb67856d7879a052dd7aa7ecf7215f7b992 +b'server to client' diff --git a/tests/net_hosted/ssl_verify_callback.py b/tests/net_hosted/ssl_verify_callback.py new file mode 100644 index 0000000000000..0dba4e4fddcf6 --- /dev/null +++ b/tests/net_hosted/ssl_verify_callback.py @@ -0,0 +1,37 @@ +# test ssl verify_callback + +import io +import socket +import tls + + +def verify_callback(cert, depth): + print("verify_callback:", type(cert), len(cert) > 100, depth) + return 0 + + +def verify_callback_fail(cert, depth): + print("verify_callback_fail:", type(cert), len(cert) > 100, depth) + return 1 + + +def test(peer_addr): + context = tls.SSLContext(tls.PROTOCOL_TLS_CLIENT) + context.verify_mode = tls.CERT_OPTIONAL + context.verify_callback = verify_callback + s = socket.socket() + s.connect(peer_addr) + s = context.wrap_socket(s) + s.close() + + context.verify_callback = verify_callback_fail + s = socket.socket() + s.connect(peer_addr) + try: + s = context.wrap_socket(s) + except OSError as e: + print(e.args[1]) + + +if __name__ == "__main__": + test(socket.getaddrinfo("micropython.org", 443)[0][-1]) diff --git a/tests/net_hosted/ssl_verify_callback.py.exp b/tests/net_hosted/ssl_verify_callback.py.exp new file mode 100644 index 0000000000000..e27dcbb9d5f70 --- /dev/null +++ b/tests/net_hosted/ssl_verify_callback.py.exp @@ -0,0 +1,5 @@ +verify_callback: True 2 +verify_callback: True 1 +verify_callback: True 0 +verify_callback_fail: True 2 +MBEDTLS_ERR_ERROR_GENERIC_ERROR From e7020463f1114317988ffef21663df5cc8c62ba9 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 13 Oct 2023 14:53:02 +1100 Subject: [PATCH 098/408] extmod/modvfs: Add new "vfs" module with mount/umount and Vfs classes. They have been moved from the "os" module. Signed-off-by: Damien George --- extmod/extmod.cmake | 1 + extmod/extmod.mk | 1 + extmod/modos.c | 4 ++ extmod/modvfs.c | 67 ++++++++++++++++++++++++++ ports/cc3200/mpconfigport.h | 1 + py/mpconfig.h | 5 ++ tests/ports/unix/extra_coverage.py.exp | 2 +- 7 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 extmod/modvfs.c diff --git a/extmod/extmod.cmake b/extmod/extmod.cmake index d73ff258ffd9f..53c774013236a 100644 --- a/extmod/extmod.cmake +++ b/extmod/extmod.cmake @@ -42,6 +42,7 @@ set(MICROPY_SOURCE_EXTMOD ${MICROPY_EXTMOD_DIR}/modtls_axtls.c ${MICROPY_EXTMOD_DIR}/modtls_mbedtls.c ${MICROPY_EXTMOD_DIR}/modtime.c + ${MICROPY_EXTMOD_DIR}/modvfs.c ${MICROPY_EXTMOD_DIR}/modwebsocket.c ${MICROPY_EXTMOD_DIR}/modwebrepl.c ${MICROPY_EXTMOD_DIR}/network_cyw43.c diff --git a/extmod/extmod.mk b/extmod/extmod.mk index b3246bc0d9546..f0428bcd05650 100644 --- a/extmod/extmod.mk +++ b/extmod/extmod.mk @@ -40,6 +40,7 @@ SRC_EXTMOD_C += \ extmod/modtls_mbedtls.c \ extmod/modtime.c \ extmod/moductypes.c \ + extmod/modvfs.c \ extmod/modwebrepl.c \ extmod/modwebsocket.c \ extmod/network_cyw43.c \ diff --git a/extmod/modos.c b/extmod/modos.c index 5a088b5202989..24a36cb8ce961 100644 --- a/extmod/modos.c +++ b/extmod/modos.c @@ -195,6 +195,10 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = { #if MICROPY_VFS { MP_ROM_QSTR(MP_QSTR_ilistdir), MP_ROM_PTR(&mp_vfs_ilistdir_obj) }, + #endif + + // The following MicroPython extensions are deprecated. Use the `vfs` module instead. + #if !MICROPY_PREVIEW_VERSION_2 && MICROPY_VFS { MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&mp_vfs_mount_obj) }, { MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&mp_vfs_umount_obj) }, #if MICROPY_VFS_FAT diff --git a/extmod/modvfs.c b/extmod/modvfs.c new file mode 100644 index 0000000000000..02dc67d0730a4 --- /dev/null +++ b/extmod/modvfs.c @@ -0,0 +1,67 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023 Damien P. George + * + * 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/runtime.h" + +#if MICROPY_PY_VFS + +#include "extmod/vfs.h" +#include "extmod/vfs_fat.h" +#include "extmod/vfs_lfs.h" +#include "extmod/vfs_posix.h" + +#if !MICROPY_VFS +#error "MICROPY_PY_VFS requires MICROPY_VFS" +#endif + +STATIC const mp_rom_map_elem_t vfs_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_vfs) }, + + { MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&mp_vfs_mount_obj) }, + { MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&mp_vfs_umount_obj) }, + #if MICROPY_VFS_FAT + { MP_ROM_QSTR(MP_QSTR_VfsFat), MP_ROM_PTR(&mp_fat_vfs_type) }, + #endif + #if MICROPY_VFS_LFS1 + { MP_ROM_QSTR(MP_QSTR_VfsLfs1), MP_ROM_PTR(&mp_type_vfs_lfs1) }, + #endif + #if MICROPY_VFS_LFS2 + { MP_ROM_QSTR(MP_QSTR_VfsLfs2), MP_ROM_PTR(&mp_type_vfs_lfs2) }, + #endif + #if MICROPY_VFS_POSIX + { MP_ROM_QSTR(MP_QSTR_VfsPosix), MP_ROM_PTR(&mp_type_vfs_posix) }, + #endif +}; +STATIC MP_DEFINE_CONST_DICT(vfs_module_globals, vfs_module_globals_table); + +const mp_obj_module_t mp_module_vfs = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&vfs_module_globals, +}; + +MP_REGISTER_MODULE(MP_QSTR_vfs, mp_module_vfs); + +#endif // MICROPY_PY_VFS diff --git a/ports/cc3200/mpconfigport.h b/ports/cc3200/mpconfigport.h index d472d29f70242..9cbc1afc0b092 100644 --- a/ports/cc3200/mpconfigport.h +++ b/ports/cc3200/mpconfigport.h @@ -124,6 +124,7 @@ #define MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME (1) #define MICROPY_PY_TIME_TIME_TIME_NS (1) #define MICROPY_PY_TIME_INCLUDEFILE "ports/cc3200/mods/modtime.c" +#define MICROPY_PY_VFS (1) #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MACHINE_INCLUDEFILE "ports/cc3200/mods/modmachine.c" #define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1) diff --git a/py/mpconfig.h b/py/mpconfig.h index 9a1f04568e0fa..837115ab59f99 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1744,6 +1744,11 @@ typedef double mp_float_t; #define MICROPY_PY_SSL_FINALISER (MICROPY_ENABLE_FINALISER) #endif +// Whether to provide the "vfs" module +#ifndef MICROPY_PY_VFS +#define MICROPY_PY_VFS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES && MICROPY_VFS) +#endif + #ifndef MICROPY_PY_WEBSOCKET #define MICROPY_PY_WEBSOCKET (0) #endif diff --git a/tests/ports/unix/extra_coverage.py.exp b/tests/ports/unix/extra_coverage.py.exp index 75c7c32df1284..3db1c5a63e54e 100644 --- a/tests/ports/unix/extra_coverage.py.exp +++ b/tests/ports/unix/extra_coverage.py.exp @@ -59,7 +59,7 @@ heapq io json machine math os platform random re select socket struct sys termios time tls -uctypes websocket +uctypes vfs websocket me micropython machine math From 45f99cb4459248116396773a72cc122edbe14a00 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 20 Nov 2023 19:12:02 +1100 Subject: [PATCH 099/408] docs/library: Move vfs functions and classes from os to vfs module docs. Signed-off-by: Damien George --- docs/library/esp32.rst | 2 +- docs/library/index.rst | 1 + docs/library/machine.SDCard.rst | 2 +- docs/library/os.rst | 184 ++----------------------- docs/library/pyb.Flash.rst | 2 +- docs/library/pyb.rst | 2 +- docs/library/rp2.Flash.rst | 2 +- docs/library/vfs.rst | 208 +++++++++++++++++++++++++++++ docs/library/zephyr.DiskAccess.rst | 2 +- docs/library/zephyr.FlashArea.rst | 2 +- docs/reference/filesystem.rst | 12 +- docs/zephyr/tutorial/storage.rst | 6 +- 12 files changed, 236 insertions(+), 189 deletions(-) create mode 100644 docs/library/vfs.rst diff --git a/docs/library/esp32.rst b/docs/library/esp32.rst index 422329bf1e801..dc35e7905e162 100644 --- a/docs/library/esp32.rst +++ b/docs/library/esp32.rst @@ -114,7 +114,7 @@ methods to enable over-the-air (OTA) updates. These methods implement the simple and :ref:`extended ` block protocol defined by - :class:`os.AbstractBlockDev`. + :class:`vfs.AbstractBlockDev`. .. method:: Partition.set_boot() diff --git a/docs/library/index.rst b/docs/library/index.rst index 4a7f78ecf3184..eb29b7680542e 100644 --- a/docs/library/index.rst +++ b/docs/library/index.rst @@ -104,6 +104,7 @@ the following libraries. neopixel.rst network.rst uctypes.rst + vfs.rst The following libraries provide drivers for hardware components. diff --git a/docs/library/machine.SDCard.rst b/docs/library/machine.SDCard.rst index cde0bd1d145d9..4faa7a5557723 100644 --- a/docs/library/machine.SDCard.rst +++ b/docs/library/machine.SDCard.rst @@ -27,7 +27,7 @@ vary from platform to platform. This class provides access to SD or MMC storage cards using either a dedicated SD/MMC interface hardware or through an SPI channel. - The class implements the block protocol defined by :class:`os.AbstractBlockDev`. + The class implements the block protocol defined by :class:`vfs.AbstractBlockDev`. This allows the mounting of an SD card to be as simple as:: os.mount(machine.SDCard(), "/sd") diff --git a/docs/library/os.rst b/docs/library/os.rst index 27a7d2d44a05b..710875e34c39b 100644 --- a/docs/library/os.rst +++ b/docs/library/os.rst @@ -136,192 +136,30 @@ Terminal redirection and duplication Filesystem mounting ------------------- -Some ports provide a Virtual Filesystem (VFS) and the ability to mount multiple -"real" filesystems within this VFS. Filesystem objects can be mounted at either -the root of the VFS, or at a subdirectory that lives in the root. This allows -dynamic and flexible configuration of the filesystem that is seen by Python -programs. Ports that have this functionality provide the :func:`mount` and -:func:`umount` functions, and possibly various filesystem implementations -represented by VFS classes. +The following functions and classes have been moved to the :mod:`vfs` module. +They are provided in this module only for backwards compatibility and will be +removed in version 2 of MicroPython. .. function:: mount(fsobj, mount_point, *, readonly) - Mount the filesystem object *fsobj* at the location in the VFS given by the - *mount_point* string. *fsobj* can be a a VFS object that has a ``mount()`` - method, or a block device. If it's a block device then the filesystem type - is automatically detected (an exception is raised if no filesystem was - recognised). *mount_point* may be ``'/'`` to mount *fsobj* at the root, - or ``'/'`` to mount it at a subdirectory under the root. - - If *readonly* is ``True`` then the filesystem is mounted read-only. - - During the mount process the method ``mount()`` is called on the filesystem - object. - - Will raise ``OSError(EPERM)`` if *mount_point* is already mounted. + See `vfs.mount`. .. function:: umount(mount_point) - Unmount a filesystem. *mount_point* can be a string naming the mount location, - or a previously-mounted filesystem object. During the unmount process the - method ``umount()`` is called on the filesystem object. - - Will raise ``OSError(EINVAL)`` if *mount_point* is not found. + See `vfs.umount`. .. class:: VfsFat(block_dev) - Create a filesystem object that uses the FAT filesystem format. Storage of - the FAT filesystem is provided by *block_dev*. - Objects created by this constructor can be mounted using :func:`mount`. - - .. staticmethod:: mkfs(block_dev) - - Build a FAT filesystem on *block_dev*. + See `vfs.VfsFat`. .. class:: VfsLfs1(block_dev, readsize=32, progsize=32, lookahead=32) - Create a filesystem object that uses the `littlefs v1 filesystem format`_. - Storage of the littlefs filesystem is provided by *block_dev*, which must - support the :ref:`extended interface `. - Objects created by this constructor can be mounted using :func:`mount`. - - See :ref:`filesystem` for more information. - - .. staticmethod:: mkfs(block_dev, readsize=32, progsize=32, lookahead=32) - - Build a Lfs1 filesystem on *block_dev*. - - .. note:: There are reports of littlefs v1 failing in certain situations, - for details see `littlefs issue 347`_. + See `vfs.VfsLfs1`. .. class:: VfsLfs2(block_dev, readsize=32, progsize=32, lookahead=32, mtime=True) - Create a filesystem object that uses the `littlefs v2 filesystem format`_. - Storage of the littlefs filesystem is provided by *block_dev*, which must - support the :ref:`extended interface `. - Objects created by this constructor can be mounted using :func:`mount`. + See `vfs.VfsLfs2`. + +.. class:: VfsPosix(root=None) - The *mtime* argument enables modification timestamps for files, stored using - littlefs attributes. This option can be disabled or enabled differently each - mount time and timestamps will only be added or updated if *mtime* is enabled, - otherwise the timestamps will remain untouched. Littlefs v2 filesystems without - timestamps will work without reformatting and timestamps will be added - transparently to existing files once they are opened for writing. When *mtime* - is enabled `os.stat` on files without timestamps will return 0 for the timestamp. - - See :ref:`filesystem` for more information. - - .. staticmethod:: mkfs(block_dev, readsize=32, progsize=32, lookahead=32) - - Build a Lfs2 filesystem on *block_dev*. - - .. note:: There are reports of littlefs v2 failing in certain situations, - for details see `littlefs issue 295`_. - -.. _littlefs v1 filesystem format: https://github.com/ARMmbed/littlefs/tree/v1 -.. _littlefs v2 filesystem format: https://github.com/ARMmbed/littlefs -.. _littlefs issue 295: https://github.com/ARMmbed/littlefs/issues/295 -.. _littlefs issue 347: https://github.com/ARMmbed/littlefs/issues/347 - -Block devices -------------- - -A block device is an object which implements the block protocol. This enables a -device to support MicroPython filesystems. The physical hardware is represented -by a user defined class. The :class:`AbstractBlockDev` class is a template for -the design of such a class: MicroPython does not actually provide that class, -but an actual block device class must implement the methods described below. - -A concrete implementation of this class will usually allow access to the -memory-like functionality of a piece of hardware (like flash memory). A block -device can be formatted to any supported filesystem and mounted using ``os`` -methods. - -See :ref:`filesystem` for example implementations of block devices using the -two variants of the block protocol described below. - -.. _block-device-interface: - -Simple and extended interface -............................. - -There are two compatible signatures for the ``readblocks`` and ``writeblocks`` -methods (see below), in order to support a variety of use cases. A given block -device may implement one form or the other, or both at the same time. The second -form (with the offset parameter) is referred to as the "extended interface". - -Some filesystems (such as littlefs) that require more control over write -operations, for example writing to sub-block regions without erasing, may require -that the block device supports the extended interface. - -.. class:: AbstractBlockDev(...) - - Construct a block device object. The parameters to the constructor are - dependent on the specific block device. - - .. method:: readblocks(block_num, buf) - readblocks(block_num, buf, offset) - - The first form reads aligned, multiples of blocks. - Starting at the block given by the index *block_num*, read blocks from - the device into *buf* (an array of bytes). - The number of blocks to read is given by the length of *buf*, - which will be a multiple of the block size. - - The second form allows reading at arbitrary locations within a block, - and arbitrary lengths. - Starting at block index *block_num*, and byte offset within that block - of *offset*, read bytes from the device into *buf* (an array of bytes). - The number of bytes to read is given by the length of *buf*. - - .. method:: writeblocks(block_num, buf) - writeblocks(block_num, buf, offset) - - The first form writes aligned, multiples of blocks, and requires that the - blocks that are written to be first erased (if necessary) by this method. - Starting at the block given by the index *block_num*, write blocks from - *buf* (an array of bytes) to the device. - The number of blocks to write is given by the length of *buf*, - which will be a multiple of the block size. - - The second form allows writing at arbitrary locations within a block, - and arbitrary lengths. Only the bytes being written should be changed, - and the caller of this method must ensure that the relevant blocks are - erased via a prior ``ioctl`` call. - Starting at block index *block_num*, and byte offset within that block - of *offset*, write bytes from *buf* (an array of bytes) to the device. - The number of bytes to write is given by the length of *buf*. - - Note that implementations must never implicitly erase blocks if the offset - argument is specified, even if it is zero. - - .. method:: ioctl(op, arg) - - Control the block device and query its parameters. The operation to - perform is given by *op* which is one of the following integers: - - - 1 -- initialise the device (*arg* is unused) - - 2 -- shutdown the device (*arg* is unused) - - 3 -- sync the device (*arg* is unused) - - 4 -- get a count of the number of blocks, should return an integer - (*arg* is unused) - - 5 -- get the number of bytes in a block, should return an integer, - or ``None`` in which case the default value of 512 is used - (*arg* is unused) - - 6 -- erase a block, *arg* is the block number to erase - - As a minimum ``ioctl(4, ...)`` must be intercepted; for littlefs - ``ioctl(6, ...)`` must also be intercepted. The need for others is - hardware dependent. - - Prior to any call to ``writeblocks(block, ...)`` littlefs issues - ``ioctl(6, block)``. This enables a device driver to erase the block - prior to a write if the hardware requires it. Alternatively a driver - might intercept ``ioctl(6, block)`` and return 0 (success). In this case - the driver assumes responsibility for detecting the need for erasure. - - Unless otherwise stated ``ioctl(op, arg)`` can return ``None``. - Consequently an implementation can ignore unused values of ``op``. Where - ``op`` is intercepted, the return value for operations 4 and 5 are as - detailed above. Other operations should return 0 on success and non-zero - for failure, with the value returned being an ``OSError`` errno code. + See `vfs.VfsPosix`. diff --git a/docs/library/pyb.Flash.rst b/docs/library/pyb.Flash.rst index 984e13f4583a4..562bcf1e2466e 100644 --- a/docs/library/pyb.Flash.rst +++ b/docs/library/pyb.Flash.rst @@ -43,7 +43,7 @@ Methods These methods implement the simple and :ref:`extended ` block protocol defined by - :class:`os.AbstractBlockDev`. + :class:`vfs.AbstractBlockDev`. Hardware Note ------------- diff --git a/docs/library/pyb.rst b/docs/library/pyb.rst index c8ef2c531542f..869e2f8f3bd9b 100644 --- a/docs/library/pyb.rst +++ b/docs/library/pyb.rst @@ -217,7 +217,7 @@ Miscellaneous functions Mount a block device and make it available as part of the filesystem. ``device`` must be an object that provides the block protocol. (The - following is also deprecated. See :class:`os.AbstractBlockDev` for the + following is also deprecated. See :class:`vfs.AbstractBlockDev` for the correct way to create a block device.) - ``readblocks(self, blocknum, buf)`` diff --git a/docs/library/rp2.Flash.rst b/docs/library/rp2.Flash.rst index 1e94cf519c844..70cb127a192da 100644 --- a/docs/library/rp2.Flash.rst +++ b/docs/library/rp2.Flash.rst @@ -32,5 +32,5 @@ Methods These methods implement the simple and extended :ref:`block protocol ` defined by - :class:`os.AbstractBlockDev`. + :class:`vfs.AbstractBlockDev`. diff --git a/docs/library/vfs.rst b/docs/library/vfs.rst new file mode 100644 index 0000000000000..fcd06eb4353b1 --- /dev/null +++ b/docs/library/vfs.rst @@ -0,0 +1,208 @@ +:mod:`vfs` -- virtual filesystem control +======================================== + +.. module:: vfs + :synopsis: virtual filesystem control + +The ``vfs`` module contains functions for creating filesystem objects and +mounting/unmounting them in the Virtual Filesystem. + +Filesystem mounting +------------------- + +Some ports provide a Virtual Filesystem (VFS) and the ability to mount multiple +"real" filesystems within this VFS. Filesystem objects can be mounted at either +the root of the VFS, or at a subdirectory that lives in the root. This allows +dynamic and flexible configuration of the filesystem that is seen by Python +programs. Ports that have this functionality provide the :func:`mount` and +:func:`umount` functions, and possibly various filesystem implementations +represented by VFS classes. + +.. function:: mount(fsobj, mount_point, *, readonly) + + Mount the filesystem object *fsobj* at the location in the VFS given by the + *mount_point* string. *fsobj* can be a a VFS object that has a ``mount()`` + method, or a block device. If it's a block device then the filesystem type + is automatically detected (an exception is raised if no filesystem was + recognised). *mount_point* may be ``'/'`` to mount *fsobj* at the root, + or ``'/'`` to mount it at a subdirectory under the root. + + If *readonly* is ``True`` then the filesystem is mounted read-only. + + During the mount process the method ``mount()`` is called on the filesystem + object. + + Will raise ``OSError(EPERM)`` if *mount_point* is already mounted. + +.. function:: umount(mount_point) + + Unmount a filesystem. *mount_point* can be a string naming the mount location, + or a previously-mounted filesystem object. During the unmount process the + method ``umount()`` is called on the filesystem object. + + Will raise ``OSError(EINVAL)`` if *mount_point* is not found. + +.. class:: VfsFat(block_dev) + + Create a filesystem object that uses the FAT filesystem format. Storage of + the FAT filesystem is provided by *block_dev*. + Objects created by this constructor can be mounted using :func:`mount`. + + .. staticmethod:: mkfs(block_dev) + + Build a FAT filesystem on *block_dev*. + +.. class:: VfsLfs1(block_dev, readsize=32, progsize=32, lookahead=32) + + Create a filesystem object that uses the `littlefs v1 filesystem format`_. + Storage of the littlefs filesystem is provided by *block_dev*, which must + support the :ref:`extended interface `. + Objects created by this constructor can be mounted using :func:`mount`. + + See :ref:`filesystem` for more information. + + .. staticmethod:: mkfs(block_dev, readsize=32, progsize=32, lookahead=32) + + Build a Lfs1 filesystem on *block_dev*. + + .. note:: There are reports of littlefs v1 failing in certain situations, + for details see `littlefs issue 347`_. + +.. class:: VfsLfs2(block_dev, readsize=32, progsize=32, lookahead=32, mtime=True) + + Create a filesystem object that uses the `littlefs v2 filesystem format`_. + Storage of the littlefs filesystem is provided by *block_dev*, which must + support the :ref:`extended interface `. + Objects created by this constructor can be mounted using :func:`mount`. + + The *mtime* argument enables modification timestamps for files, stored using + littlefs attributes. This option can be disabled or enabled differently each + mount time and timestamps will only be added or updated if *mtime* is enabled, + otherwise the timestamps will remain untouched. Littlefs v2 filesystems without + timestamps will work without reformatting and timestamps will be added + transparently to existing files once they are opened for writing. When *mtime* + is enabled `os.stat` on files without timestamps will return 0 for the timestamp. + + See :ref:`filesystem` for more information. + + .. staticmethod:: mkfs(block_dev, readsize=32, progsize=32, lookahead=32) + + Build a Lfs2 filesystem on *block_dev*. + + .. note:: There are reports of littlefs v2 failing in certain situations, + for details see `littlefs issue 295`_. + +.. class:: VfsPosix(root=None) + + Create a filesystem object that accesses the host POSIX filesystem. + If *root* is specified then it should be a path in the host filesystem to use + as the root of the ``VfsPosix`` object. Otherwise the current directory of + the host filesystem is used. + +.. _littlefs v1 filesystem format: https://github.com/ARMmbed/littlefs/tree/v1 +.. _littlefs v2 filesystem format: https://github.com/ARMmbed/littlefs +.. _littlefs issue 295: https://github.com/ARMmbed/littlefs/issues/295 +.. _littlefs issue 347: https://github.com/ARMmbed/littlefs/issues/347 + +Block devices +------------- + +A block device is an object which implements the block protocol. This enables a +device to support MicroPython filesystems. The physical hardware is represented +by a user defined class. The :class:`AbstractBlockDev` class is a template for +the design of such a class: MicroPython does not actually provide that class, +but an actual block device class must implement the methods described below. + +A concrete implementation of this class will usually allow access to the +memory-like functionality of a piece of hardware (like flash memory). A block +device can be formatted to any supported filesystem and mounted using ``os`` +methods. + +See :ref:`filesystem` for example implementations of block devices using the +two variants of the block protocol described below. + +.. _block-device-interface: + +Simple and extended interface +............................. + +There are two compatible signatures for the ``readblocks`` and ``writeblocks`` +methods (see below), in order to support a variety of use cases. A given block +device may implement one form or the other, or both at the same time. The second +form (with the offset parameter) is referred to as the "extended interface". + +Some filesystems (such as littlefs) that require more control over write +operations, for example writing to sub-block regions without erasing, may require +that the block device supports the extended interface. + +.. class:: AbstractBlockDev(...) + + Construct a block device object. The parameters to the constructor are + dependent on the specific block device. + + .. method:: readblocks(block_num, buf) + readblocks(block_num, buf, offset) + + The first form reads aligned, multiples of blocks. + Starting at the block given by the index *block_num*, read blocks from + the device into *buf* (an array of bytes). + The number of blocks to read is given by the length of *buf*, + which will be a multiple of the block size. + + The second form allows reading at arbitrary locations within a block, + and arbitrary lengths. + Starting at block index *block_num*, and byte offset within that block + of *offset*, read bytes from the device into *buf* (an array of bytes). + The number of bytes to read is given by the length of *buf*. + + .. method:: writeblocks(block_num, buf) + writeblocks(block_num, buf, offset) + + The first form writes aligned, multiples of blocks, and requires that the + blocks that are written to be first erased (if necessary) by this method. + Starting at the block given by the index *block_num*, write blocks from + *buf* (an array of bytes) to the device. + The number of blocks to write is given by the length of *buf*, + which will be a multiple of the block size. + + The second form allows writing at arbitrary locations within a block, + and arbitrary lengths. Only the bytes being written should be changed, + and the caller of this method must ensure that the relevant blocks are + erased via a prior ``ioctl`` call. + Starting at block index *block_num*, and byte offset within that block + of *offset*, write bytes from *buf* (an array of bytes) to the device. + The number of bytes to write is given by the length of *buf*. + + Note that implementations must never implicitly erase blocks if the offset + argument is specified, even if it is zero. + + .. method:: ioctl(op, arg) + + Control the block device and query its parameters. The operation to + perform is given by *op* which is one of the following integers: + + - 1 -- initialise the device (*arg* is unused) + - 2 -- shutdown the device (*arg* is unused) + - 3 -- sync the device (*arg* is unused) + - 4 -- get a count of the number of blocks, should return an integer + (*arg* is unused) + - 5 -- get the number of bytes in a block, should return an integer, + or ``None`` in which case the default value of 512 is used + (*arg* is unused) + - 6 -- erase a block, *arg* is the block number to erase + + As a minimum ``ioctl(4, ...)`` must be intercepted; for littlefs + ``ioctl(6, ...)`` must also be intercepted. The need for others is + hardware dependent. + + Prior to any call to ``writeblocks(block, ...)`` littlefs issues + ``ioctl(6, block)``. This enables a device driver to erase the block + prior to a write if the hardware requires it. Alternatively a driver + might intercept ``ioctl(6, block)`` and return 0 (success). In this case + the driver assumes responsibility for detecting the need for erasure. + + Unless otherwise stated ``ioctl(op, arg)`` can return ``None``. + Consequently an implementation can ignore unused values of ``op``. Where + ``op`` is intercepted, the return value for operations 4 and 5 are as + detailed above. Other operations should return 0 on success and non-zero + for failure, with the value returned being an ``OSError`` errno code. diff --git a/docs/library/zephyr.DiskAccess.rst b/docs/library/zephyr.DiskAccess.rst index 3e5fa9a3575a0..e5eac8ca4988b 100644 --- a/docs/library/zephyr.DiskAccess.rst +++ b/docs/library/zephyr.DiskAccess.rst @@ -34,5 +34,5 @@ Methods These methods implement the simple and extended :ref:`block protocol ` defined by - :class:`os.AbstractBlockDev`. + :class:`vfs.AbstractBlockDev`. diff --git a/docs/library/zephyr.FlashArea.rst b/docs/library/zephyr.FlashArea.rst index 9cd4dd59d6852..749b90a3b43c5 100644 --- a/docs/library/zephyr.FlashArea.rst +++ b/docs/library/zephyr.FlashArea.rst @@ -37,4 +37,4 @@ Methods These methods implement the simple and extended :ref:`block protocol ` defined by - :class:`os.AbstractBlockDev`. + :class:`vfs.AbstractBlockDev`. diff --git a/docs/reference/filesystem.rst b/docs/reference/filesystem.rst index ca9e56344ed4c..d8092c58dd7ce 100644 --- a/docs/reference/filesystem.rst +++ b/docs/reference/filesystem.rst @@ -40,7 +40,7 @@ Block devices ------------- A block device is an instance of a class that implements the -:class:`os.AbstractBlockDev` protocol. +:class:`vfs.AbstractBlockDev` protocol. Built-in block devices ~~~~~~~~~~~~~~~~~~~~~~ @@ -116,8 +116,8 @@ It can be used as follows:: An example of a block device that supports both the simple and extended interface (i.e. both signatures and behaviours of the -:meth:`os.AbstractBlockDev.readblocks` and -:meth:`os.AbstractBlockDev.writeblocks` methods) is:: +:meth:`vfs.AbstractBlockDev.readblocks` and +:meth:`vfs.AbstractBlockDev.writeblocks` methods) is:: class RAMBlockDev: def __init__(self, block_size, num_blocks): @@ -148,7 +148,7 @@ interface (i.e. both signatures and behaviours of the return 0 As it supports the extended interface, it can be used with :class:`littlefs -`:: +`:: import os @@ -166,8 +166,8 @@ normally would be used from Python code, for example:: Filesystems ----------- -MicroPython ports can provide implementations of :class:`FAT `, -:class:`littlefs v1 ` and :class:`littlefs v2 `. +MicroPython ports can provide implementations of :class:`FAT `, +:class:`littlefs v1 ` and :class:`littlefs v2 `. The following table shows which filesystems are included in the firmware by default for given port/board combinations, however they can be optionally diff --git a/docs/zephyr/tutorial/storage.rst b/docs/zephyr/tutorial/storage.rst index 12bd0d0d351b4..e8dcbbd39a4aa 100644 --- a/docs/zephyr/tutorial/storage.rst +++ b/docs/zephyr/tutorial/storage.rst @@ -6,14 +6,14 @@ Filesystems and Storage Storage modules support virtual filesystem with FAT and littlefs formats, backed by either Zephyr DiskAccess or FlashArea (flash map) APIs depending on which the board supports. -See `os Filesystem Mounting `_. +See `vfs Filesystem Mounting `_. Disk Access ----------- The :ref:`zephyr.DiskAccess ` class can be used to access storage devices, such as SD cards. This class uses `Zephyr Disk Access API `_ and -implements the `os.AbstractBlockDev` protocol. +implements the `vfs.AbstractBlockDev` protocol. For use with SD card controllers, SD cards must be present at boot & not removed; they will be auto detected and initialized by filesystem at boot. Use the disk driver interface and a @@ -39,7 +39,7 @@ customize filesystem configurations. To store persistent data on the device, usi API is recommended (see below). This class uses `Zephyr Flash map API `_ and -implements the `os.AbstractBlockDev` protocol. +implements the `vfs.AbstractBlockDev` protocol. Example usage with the internal flash on the reel_board or the rv32m1_vega_ri5cy board:: From 5804aa020452c9fe115c53ce9514b442945832bb Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 23 Nov 2023 13:47:08 +1100 Subject: [PATCH 100/408] docs/reference/micropython2_migration.rst: Add info about os and vfs. Signed-off-by: Damien George --- docs/reference/micropython2_migration.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/reference/micropython2_migration.rst b/docs/reference/micropython2_migration.rst index 954488b8cdf4b..3a114711406fd 100644 --- a/docs/reference/micropython2_migration.rst +++ b/docs/reference/micropython2_migration.rst @@ -71,4 +71,11 @@ which is useful for development and testing. Changes ~~~~~~~ -*None yet* +Introduction of a new module :mod:`vfs`. The following functions and +classes have moved out of :mod:`os` to :mod:`vfs`: +- `os.mount` +- `os.umount` +- `os.VfsFat` +- `os.VfsLfs1` +- `os.VfsLfs2` +- `os.VfsPosix` From b87bbaeb43ddbd603b6ac3266ccc15815198b5a7 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 20 Nov 2023 23:04:55 +1100 Subject: [PATCH 101/408] tests: Use vfs module instead of os. Signed-off-by: Damien George --- tests/extmod/vfs_basic.py | 32 +++-- tests/extmod/vfs_blockdev.py | 12 +- tests/extmod/vfs_fat_fileio1.py | 25 ++-- tests/extmod/vfs_fat_fileio2.py | 49 ++++---- tests/extmod/vfs_fat_finaliser.py | 14 +-- tests/extmod/vfs_fat_ilistdir_del.py | 26 ++-- tests/extmod/vfs_fat_more.py | 24 ++-- tests/extmod/vfs_fat_mtime.py | 18 +-- tests/extmod/vfs_fat_oldproto.py | 27 ++--- tests/extmod/vfs_fat_ramdisk.py | 55 ++++----- tests/extmod/vfs_fat_ramdisklarge.py | 22 ++-- tests/extmod/vfs_lfs.py | 134 ++++++++++----------- tests/extmod/vfs_lfs_corrupt.py | 36 +++--- tests/extmod/vfs_lfs_error.py | 38 +++--- tests/extmod/vfs_lfs_file.py | 40 +++--- tests/extmod/vfs_lfs_ilistdir_del.py | 26 ++-- tests/extmod/vfs_lfs_mount.py | 28 ++--- tests/extmod/vfs_lfs_mtime.py | 46 +++---- tests/extmod/vfs_lfs_superblock.py | 12 +- tests/extmod/vfs_posix.py | 41 +++---- tests/extmod/vfs_posix_enoent.py | 7 +- tests/extmod/vfs_posix_ilistdir_del.py | 32 ++--- tests/extmod/vfs_posix_ilistdir_filter.py | 14 +-- tests/extmod/vfs_posix_paths.py | 52 ++++---- tests/extmod/vfs_userfs.py | 9 +- tests/micropython/builtin_execfile.py | 15 +-- tests/micropython/import_mpy_invalid.py | 7 +- tests/micropython/import_mpy_native.py | 7 +- tests/micropython/import_mpy_native_gc.py | 7 +- tests/perf_bench/core_import_mpy_multi.py | 6 +- tests/perf_bench/core_import_mpy_single.py | 6 +- tests/ports/cc3200/os.py | 12 +- tests/run-natmodtests.py | 4 +- tests/run-tests.py | 4 +- 34 files changed, 419 insertions(+), 468 deletions(-) diff --git a/tests/extmod/vfs_basic.py b/tests/extmod/vfs_basic.py index 028846406a145..2c0ce8f5295ad 100644 --- a/tests/extmod/vfs_basic.py +++ b/tests/extmod/vfs_basic.py @@ -1,10 +1,8 @@ # test VFS functionality without any particular filesystem type try: - import os - - os.mount -except (ImportError, AttributeError): + import os, vfs +except ImportError: print("SKIP") raise SystemExit @@ -59,11 +57,11 @@ def open(self, file, mode): # first we umount any existing mount points the target may have try: - os.umount("/") + vfs.umount("/") except OSError: pass for path in os.listdir("/"): - os.umount("/" + path) + vfs.umount("/" + path) # stat root dir print(os.stat("/")) @@ -83,7 +81,7 @@ def open(self, file, mode): print(func, arg, "OSError") # basic mounting and listdir -os.mount(Filesystem(1), "/test_mnt") +vfs.mount(Filesystem(1), "/test_mnt") print(os.listdir()) # ilistdir @@ -103,13 +101,13 @@ def open(self, file, mode): print(os.listdir("/test_mnt")) # mounting another filesystem -os.mount(Filesystem(2), "/test_mnt2", readonly=True) +vfs.mount(Filesystem(2), "/test_mnt2", readonly=True) print(os.listdir()) print(os.listdir("/test_mnt2")) # mounting over an existing mount point try: - os.mount(Filesystem(3), "/test_mnt2") + vfs.mount(Filesystem(3), "/test_mnt2") except OSError: print("OSError") @@ -139,23 +137,23 @@ def open(self, file, mode): open("test_file", "wb") # umount -os.umount("/test_mnt") -os.umount("/test_mnt2") +vfs.umount("/test_mnt") +vfs.umount("/test_mnt2") # umount a non-existent mount point try: - os.umount("/test_mnt") + vfs.umount("/test_mnt") except OSError: print("OSError") # root dir -os.mount(Filesystem(3), "/") +vfs.mount(Filesystem(3), "/") print(os.stat("/")) print(os.statvfs("/")) print(os.listdir()) open("test") -os.mount(Filesystem(4), "/mnt") +vfs.mount(Filesystem(4), "/mnt") print(os.listdir()) print(os.listdir("/mnt")) os.chdir("/mnt") @@ -166,9 +164,9 @@ def open(self, file, mode): print(os.listdir()) os.chdir("/") -os.umount("/") +vfs.umount("/") print(os.listdir("/")) -os.umount("/mnt") +vfs.umount("/mnt") # chdir to a non-existent mount point (current directory should remain unchanged) try: @@ -178,7 +176,7 @@ def open(self, file, mode): print(os.getcwd()) # chdir to a non-existent subdirectory in a mounted filesystem -os.mount(Filesystem(5, 1), "/mnt") +vfs.mount(Filesystem(5, 1), "/mnt") try: os.chdir("/mnt/subdir") except OSError: diff --git a/tests/extmod/vfs_blockdev.py b/tests/extmod/vfs_blockdev.py index f4c84ea9213c2..a1f0749962745 100644 --- a/tests/extmod/vfs_blockdev.py +++ b/tests/extmod/vfs_blockdev.py @@ -1,10 +1,10 @@ # Test for behaviour of combined standard and extended block device try: - import os + import vfs - os.VfsFat - os.VfsLfs2 + vfs.VfsFat + vfs.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -65,12 +65,10 @@ def test(bdev, vfs_class): try: - import os - bdev = RAMBlockDevice(50) except MemoryError: print("SKIP") raise SystemExit -test(bdev, os.VfsFat) -test(bdev, os.VfsLfs2) +test(bdev, vfs.VfsFat) +test(bdev, vfs.VfsLfs2) diff --git a/tests/extmod/vfs_fat_fileio1.py b/tests/extmod/vfs_fat_fileio1.py index f4db5ac8ddea8..5221d405323fa 100644 --- a/tests/extmod/vfs_fat_fileio1.py +++ b/tests/extmod/vfs_fat_fileio1.py @@ -1,13 +1,8 @@ try: - import errno - import os -except ImportError: - print("SKIP") - raise SystemExit + import errno, os, vfs -try: - os.VfsFat -except AttributeError: + vfs.VfsFat +except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -38,13 +33,13 @@ def ioctl(self, op, arg): try: bdev = RAMFS(50) - os.VfsFat.mkfs(bdev) + vfs.VfsFat.mkfs(bdev) except MemoryError: print("SKIP") raise SystemExit -vfs = os.VfsFat(bdev) -os.mount(vfs, "/ramdisk") +fs = vfs.VfsFat(bdev) +vfs.mount(fs, "/ramdisk") os.chdir("/ramdisk") # file IO @@ -99,12 +94,12 @@ def ioctl(self, op, arg): # print(f.read()) # dirs -vfs.mkdir("foo_dir") +fs.mkdir("foo_dir") try: - vfs.rmdir("foo_file.txt") + fs.rmdir("foo_file.txt") except OSError as e: print(e.errno == 20) # errno.ENOTDIR -vfs.remove("foo_file.txt") -print(list(vfs.ilistdir())) +fs.remove("foo_file.txt") +print(list(fs.ilistdir())) diff --git a/tests/extmod/vfs_fat_fileio2.py b/tests/extmod/vfs_fat_fileio2.py index 353b997e5c827..bbd6298c496f7 100644 --- a/tests/extmod/vfs_fat_fileio2.py +++ b/tests/extmod/vfs_fat_fileio2.py @@ -1,13 +1,8 @@ try: - import errno - import os -except ImportError: - print("SKIP") - raise SystemExit + import errno, os, vfs -try: - os.VfsFat -except AttributeError: + vfs.VfsFat +except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -38,32 +33,32 @@ def ioctl(self, op, arg): try: bdev = RAMFS(50) - os.VfsFat.mkfs(bdev) + vfs.VfsFat.mkfs(bdev) except MemoryError: print("SKIP") raise SystemExit -vfs = os.VfsFat(bdev) -os.mount(vfs, "/ramdisk") +fs = vfs.VfsFat(bdev) +vfs.mount(fs, "/ramdisk") os.chdir("/ramdisk") try: - vfs.mkdir("foo_dir") + fs.mkdir("foo_dir") except OSError as e: print(e.errno == errno.EEXIST) try: - vfs.remove("foo_dir") + fs.remove("foo_dir") except OSError as e: print(e.errno == errno.EISDIR) try: - vfs.remove("no_file.txt") + fs.remove("no_file.txt") except OSError as e: print(e.errno == errno.ENOENT) try: - vfs.rename("foo_dir", "/null/file") + fs.rename("foo_dir", "/null/file") except OSError as e: print(e.errno == errno.ENOENT) @@ -79,34 +74,34 @@ def ioctl(self, op, arg): # directory not empty try: - vfs.rmdir("foo_dir") + fs.rmdir("foo_dir") except OSError as e: print(e.errno == errno.EACCES) # trim full path -vfs.rename("foo_dir/file-in-dir.txt", "foo_dir/file.txt") -print(list(vfs.ilistdir("foo_dir"))) +fs.rename("foo_dir/file-in-dir.txt", "foo_dir/file.txt") +print(list(fs.ilistdir("foo_dir"))) -vfs.rename("foo_dir/file.txt", "moved-to-root.txt") -print(list(vfs.ilistdir())) +fs.rename("foo_dir/file.txt", "moved-to-root.txt") +print(list(fs.ilistdir())) # check that renaming to existing file will overwrite it with open("temp", "w") as f: f.write("new text") -vfs.rename("temp", "moved-to-root.txt") -print(list(vfs.ilistdir())) +fs.rename("temp", "moved-to-root.txt") +print(list(fs.ilistdir())) with open("moved-to-root.txt") as f: print(f.read()) # valid removes -vfs.remove("foo_dir/sub_file.txt") -vfs.rmdir("foo_dir") -print(list(vfs.ilistdir())) +fs.remove("foo_dir/sub_file.txt") +fs.rmdir("foo_dir") +print(list(fs.ilistdir())) # disk full try: - bsize = vfs.statvfs("/ramdisk")[0] - free = vfs.statvfs("/ramdisk")[2] + 1 + bsize = fs.statvfs("/ramdisk")[0] + free = fs.statvfs("/ramdisk")[2] + 1 f = open("large_file.txt", "wb") f.write(bytearray(bsize * free)) except OSError as e: diff --git a/tests/extmod/vfs_fat_finaliser.py b/tests/extmod/vfs_fat_finaliser.py index a2cce7846c22b..7be3cda1a353a 100644 --- a/tests/extmod/vfs_fat_finaliser.py +++ b/tests/extmod/vfs_fat_finaliser.py @@ -1,9 +1,9 @@ # Test VfsFat class and its finaliser try: - import errno, os + import errno, os, vfs - os.VfsFat + vfs.VfsFat except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -39,8 +39,8 @@ def ioctl(self, op, arg): raise SystemExit # Format block device and create VFS object -os.VfsFat.mkfs(bdev) -vfs = os.VfsFat(bdev) +vfs.VfsFat.mkfs(bdev) +fs = vfs.VfsFat(bdev) # Here we test that opening a file with the heap locked fails correctly. This # is a special case because file objects use a finaliser and allocating with a @@ -52,7 +52,7 @@ def ioctl(self, op, arg): try: import errno, os - vfs.open("x", "r") + fs.open("x", "r") except MemoryError: print("MemoryError") micropython.heap_unlock() @@ -77,10 +77,10 @@ def ioctl(self, op, arg): # Only read back N-1 files because the last one may not be finalised due to # references to it being left on the C stack. for n in names: - f = vfs.open(n, "w") + f = fs.open(n, "w") f.write(n) f = None # release f without closing gc.collect() # should finalise at least the first N-1 files by closing them for n in names[:-1]: - with vfs.open(n, "r") as f: + with fs.open(n, "r") as f: print(f.read()) diff --git a/tests/extmod/vfs_fat_ilistdir_del.py b/tests/extmod/vfs_fat_ilistdir_del.py index ed3ca3df670bc..a6e24ec92f3b5 100644 --- a/tests/extmod/vfs_fat_ilistdir_del.py +++ b/tests/extmod/vfs_fat_ilistdir_del.py @@ -2,9 +2,9 @@ import gc try: - import os + import os, vfs - os.VfsFat + vfs.VfsFat except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -37,29 +37,29 @@ def ioctl(self, op, arg): def test(bdev, vfs_class): vfs_class.mkfs(bdev) - vfs = vfs_class(bdev) - vfs.mkdir("/test_d1") - vfs.mkdir("/test_d2") - vfs.mkdir("/test_d3") + fs = vfs_class(bdev) + fs.mkdir("/test_d1") + fs.mkdir("/test_d2") + fs.mkdir("/test_d3") for i in range(10): print(i) # We want to partially iterate the ilistdir iterator to leave it in an # open state, which will then test the finaliser when it's garbage collected. - idir = vfs.ilistdir("/") + idir = fs.ilistdir("/") print(any(idir)) # Alternate way of partially iterating the ilistdir object, modifying the # filesystem while it's open. - for dname, *_ in vfs.ilistdir("/"): - vfs.rmdir(dname) + for dname, *_ in fs.ilistdir("/"): + fs.rmdir(dname) break - vfs.mkdir(dname) + fs.mkdir(dname) # Also create a fully drained iterator and ensure trying to reuse it # throws the correct exception. - idir_emptied = vfs.ilistdir("/") + idir_emptied = fs.ilistdir("/") l = list(idir_emptied) print(len(l)) try: @@ -68,7 +68,7 @@ def test(bdev, vfs_class): pass gc.collect() - vfs.open("/test", "w").close() + fs.open("/test", "w").close() try: @@ -77,4 +77,4 @@ def test(bdev, vfs_class): print("SKIP") raise SystemExit -test(bdev, os.VfsFat) +test(bdev, vfs.VfsFat) diff --git a/tests/extmod/vfs_fat_more.py b/tests/extmod/vfs_fat_more.py index 7074221a326d4..1d755f9c55c0b 100644 --- a/tests/extmod/vfs_fat_more.py +++ b/tests/extmod/vfs_fat_more.py @@ -1,12 +1,8 @@ try: - import os -except ImportError: - print("SKIP") - raise SystemExit + import os, vfs -try: - os.VfsFat -except AttributeError: + vfs.VfsFat +except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -44,14 +40,14 @@ def ioctl(self, op, arg): # first we umount any existing mount points the target may have try: - os.umount("/") + vfs.umount("/") except OSError: pass for path in os.listdir("/"): - os.umount("/" + path) + vfs.umount("/" + path) -os.VfsFat.mkfs(bdev) -os.mount(bdev, "/") +vfs.VfsFat.mkfs(bdev) +vfs.mount(bdev, "/") print(os.getcwd()) @@ -94,8 +90,8 @@ def ioctl(self, op, arg): os.chdir("/") print(os.stat("test5.txt")[:-3]) -os.VfsFat.mkfs(bdev2) -os.mount(bdev2, "/sys") +vfs.VfsFat.mkfs(bdev2) +vfs.mount(bdev2, "/sys") print(os.listdir()) print(os.listdir("sys")) print(os.listdir("/sys")) @@ -104,7 +100,7 @@ def ioctl(self, op, arg): os.remove("test5.txt") print(os.listdir()) -os.umount("/") +vfs.umount("/") print(os.getcwd()) print(os.listdir()) print(os.listdir("sys")) diff --git a/tests/extmod/vfs_fat_mtime.py b/tests/extmod/vfs_fat_mtime.py index 1ceb611364a18..0c7e10a54869d 100644 --- a/tests/extmod/vfs_fat_mtime.py +++ b/tests/extmod/vfs_fat_mtime.py @@ -1,11 +1,11 @@ # Test for VfsFat using a RAM device, mtime feature try: - import time, os + import time, os, vfs time.time time.sleep - os.VfsFat + vfs.VfsFat except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -41,21 +41,21 @@ def test(bdev, vfs_class): vfs_class.mkfs(bdev) # construction - vfs = vfs_class(bdev) + fs = vfs_class(bdev) # Create an empty file, should have a timestamp. current_time = int(time.time()) - vfs.open("test1", "wt").close() + fs.open("test1", "wt").close() # Wait 2 seconds so mtime will increase (FAT has 2 second resolution). time.sleep(2) # Create another empty file, should have a timestamp. - vfs.open("test2", "wt").close() + fs.open("test2", "wt").close() # Stat the files and check mtime is non-zero. - stat1 = vfs.stat("test1") - stat2 = vfs.stat("test2") + stat1 = fs.stat("test1") + stat2 = fs.stat("test2") print(stat1[8] != 0, stat2[8] != 0) # Check that test1 has mtime which matches time.time() at point of creation. @@ -67,8 +67,8 @@ def test(bdev, vfs_class): print(stat1[8] < stat2[8]) # Unmount. - vfs.umount() + fs.umount() bdev = RAMBlockDevice(50) -test(bdev, os.VfsFat) +test(bdev, vfs.VfsFat) diff --git a/tests/extmod/vfs_fat_oldproto.py b/tests/extmod/vfs_fat_oldproto.py index f5336ba916fa9..2b5e4d00828c0 100644 --- a/tests/extmod/vfs_fat_oldproto.py +++ b/tests/extmod/vfs_fat_oldproto.py @@ -1,13 +1,8 @@ try: - import errno - import os -except ImportError: - print("SKIP") - raise SystemExit + import errno, os, vfs -try: - os.VfsFat -except AttributeError: + vfs.VfsFat +except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -41,18 +36,18 @@ def count(self): print("SKIP") raise SystemExit -os.VfsFat.mkfs(bdev) -vfs = os.VfsFat(bdev) -os.mount(vfs, "/ramdisk") +vfs.VfsFat.mkfs(bdev) +fs = vfs.VfsFat(bdev) +vfs.mount(fs, "/ramdisk") # file io -with vfs.open("file.txt", "w") as f: +with fs.open("file.txt", "w") as f: f.write("hello!") -print(list(vfs.ilistdir())) +print(list(fs.ilistdir())) -with vfs.open("file.txt", "r") as f: +with fs.open("file.txt", "r") as f: print(f.read()) -vfs.remove("file.txt") -print(list(vfs.ilistdir())) +fs.remove("file.txt") +print(list(fs.ilistdir())) diff --git a/tests/extmod/vfs_fat_ramdisk.py b/tests/extmod/vfs_fat_ramdisk.py index 1693359d49d56..05c45e96b06df 100644 --- a/tests/extmod/vfs_fat_ramdisk.py +++ b/tests/extmod/vfs_fat_ramdisk.py @@ -1,13 +1,8 @@ try: - import errno - import os -except ImportError: - print("SKIP") - raise SystemExit + import errno, os, vfs -try: - os.VfsFat -except AttributeError: + vfs.VfsFat +except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -38,7 +33,7 @@ def ioctl(self, op, arg): try: bdev = RAMFS(50) - os.VfsFat.mkfs(bdev) + vfs.VfsFat.mkfs(bdev) except MemoryError: print("SKIP") raise SystemExit @@ -46,50 +41,50 @@ def ioctl(self, op, arg): print(b"FOO_FILETXT" not in bdev.data) print(b"hello!" not in bdev.data) -vfs = os.VfsFat(bdev) -os.mount(vfs, "/ramdisk") +fs = vfs.VfsFat(bdev) +vfs.mount(fs, "/ramdisk") -print("statvfs:", vfs.statvfs("/ramdisk")) -print("getcwd:", vfs.getcwd()) +print("statvfs:", fs.statvfs("/ramdisk")) +print("getcwd:", fs.getcwd()) try: - vfs.stat("no_file.txt") + fs.stat("no_file.txt") except OSError as e: print(e.errno == errno.ENOENT) -with vfs.open("foo_file.txt", "w") as f: +with fs.open("foo_file.txt", "w") as f: f.write("hello!") -print(list(vfs.ilistdir())) +print(list(fs.ilistdir())) -print("stat root:", vfs.stat("/")[:-3]) # timestamps differ across runs -print("stat file:", vfs.stat("foo_file.txt")[:-3]) # timestamps differ across runs +print("stat root:", fs.stat("/")[:-3]) # timestamps differ across runs +print("stat file:", fs.stat("foo_file.txt")[:-3]) # timestamps differ across runs print(b"FOO_FILETXT" in bdev.data) print(b"hello!" in bdev.data) -vfs.mkdir("foo_dir") -vfs.chdir("foo_dir") -print("getcwd:", vfs.getcwd()) -print(list(vfs.ilistdir())) +fs.mkdir("foo_dir") +fs.chdir("foo_dir") +print("getcwd:", fs.getcwd()) +print(list(fs.ilistdir())) -with vfs.open("sub_file.txt", "w") as f: +with fs.open("sub_file.txt", "w") as f: f.write("subdir file") try: - vfs.chdir("sub_file.txt") + fs.chdir("sub_file.txt") except OSError as e: print(e.errno == errno.ENOENT) -vfs.chdir("..") -print("getcwd:", vfs.getcwd()) +fs.chdir("..") +print("getcwd:", fs.getcwd()) -os.umount(vfs) +vfs.umount(fs) -vfs = os.VfsFat(bdev) -print(list(vfs.ilistdir(b""))) +fs = vfs.VfsFat(bdev) +print(list(fs.ilistdir(b""))) # list a non-existent directory try: - vfs.ilistdir(b"no_exist") + fs.ilistdir(b"no_exist") except OSError as e: print("ENOENT:", e.errno == errno.ENOENT) diff --git a/tests/extmod/vfs_fat_ramdisklarge.py b/tests/extmod/vfs_fat_ramdisklarge.py index 40cba9ee430a1..38ad772b44397 100644 --- a/tests/extmod/vfs_fat_ramdisklarge.py +++ b/tests/extmod/vfs_fat_ramdisklarge.py @@ -1,14 +1,10 @@ # test making a FAT filesystem on a very large block device try: - import os -except ImportError: - print("SKIP") - raise SystemExit + import os, vfs -try: - os.VfsFat -except AttributeError: + vfs.VfsFat +except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -46,24 +42,24 @@ def ioctl(self, op, arg): try: bdev = RAMBDevSparse(4 * 1024 * 1024 * 1024 // RAMBDevSparse.SEC_SIZE) - os.VfsFat.mkfs(bdev) + vfs.VfsFat.mkfs(bdev) except MemoryError: print("SKIP") raise SystemExit -vfs = os.VfsFat(bdev) -os.mount(vfs, "/ramdisk") +fs = vfs.VfsFat(bdev) +vfs.mount(fs, "/ramdisk") -print("statvfs:", vfs.statvfs("/ramdisk")) +print("statvfs:", fs.statvfs("/ramdisk")) f = open("/ramdisk/test.txt", "w") f.write("test file") f.close() -print("statvfs:", vfs.statvfs("/ramdisk")) +print("statvfs:", fs.statvfs("/ramdisk")) f = open("/ramdisk/test.txt") print(f.read()) f.close() -os.umount(vfs) +vfs.umount(fs) diff --git a/tests/extmod/vfs_lfs.py b/tests/extmod/vfs_lfs.py index 83377653b2cfb..3ad57fd9c38f1 100644 --- a/tests/extmod/vfs_lfs.py +++ b/tests/extmod/vfs_lfs.py @@ -1,10 +1,10 @@ # Test for VfsLittle using a RAM device try: - import os + import os, vfs - os.VfsLfs1 - os.VfsLfs2 + vfs.VfsLfs1 + vfs.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -47,44 +47,44 @@ def test(bdev, vfs_class): vfs_class.mkfs(bdev) # construction - vfs = vfs_class(bdev) + fs = vfs_class(bdev) # statvfs - print(vfs.statvfs("/")) + print(fs.statvfs("/")) # open, write close - f = vfs.open("test", "w") + f = fs.open("test", "w") f.write("littlefs") f.close() # statvfs after creating a file - print(vfs.statvfs("/")) + print(fs.statvfs("/")) # ilistdir - print(list(vfs.ilistdir())) - print(list(vfs.ilistdir("/"))) - print(list(vfs.ilistdir(b"/"))) + print(list(fs.ilistdir())) + print(list(fs.ilistdir("/"))) + print(list(fs.ilistdir(b"/"))) # mkdir, rmdir - vfs.mkdir("testdir") - print(list(vfs.ilistdir())) - print(sorted(list(vfs.ilistdir("testdir")))) - vfs.rmdir("testdir") - print(list(vfs.ilistdir())) - vfs.mkdir("testdir") + fs.mkdir("testdir") + print(list(fs.ilistdir())) + print(sorted(list(fs.ilistdir("testdir")))) + fs.rmdir("testdir") + print(list(fs.ilistdir())) + fs.mkdir("testdir") # stat a file - print_stat(vfs.stat("test")) + print_stat(fs.stat("test")) # stat a dir (size seems to vary on LFS2 so don't print that) - print_stat(vfs.stat("testdir"), False) + print_stat(fs.stat("testdir"), False) # read - with vfs.open("test", "r") as f: + with fs.open("test", "r") as f: print(f.read()) # create large file - with vfs.open("testbig", "w") as f: + with fs.open("testbig", "w") as f: data = "large012" * 32 * 16 print("data length:", len(data)) for i in range(4): @@ -92,63 +92,63 @@ def test(bdev, vfs_class): f.write(data) # stat after creating large file - print(vfs.statvfs("/")) + print(fs.statvfs("/")) # rename - vfs.rename("testbig", "testbig2") - print(sorted(list(vfs.ilistdir()))) - vfs.chdir("testdir") - vfs.rename("/testbig2", "testbig2") - print(sorted(list(vfs.ilistdir()))) - vfs.rename("testbig2", "/testbig2") - vfs.chdir("/") - print(sorted(list(vfs.ilistdir()))) + fs.rename("testbig", "testbig2") + print(sorted(list(fs.ilistdir()))) + fs.chdir("testdir") + fs.rename("/testbig2", "testbig2") + print(sorted(list(fs.ilistdir()))) + fs.rename("testbig2", "/testbig2") + fs.chdir("/") + print(sorted(list(fs.ilistdir()))) # remove - vfs.remove("testbig2") - print(sorted(list(vfs.ilistdir()))) + fs.remove("testbig2") + print(sorted(list(fs.ilistdir()))) # getcwd, chdir - vfs.mkdir("/testdir2") - vfs.mkdir("/testdir/subdir") - print(vfs.getcwd()) - vfs.chdir("/testdir") - print(vfs.getcwd()) + fs.mkdir("/testdir2") + fs.mkdir("/testdir/subdir") + print(fs.getcwd()) + fs.chdir("/testdir") + print(fs.getcwd()) # create file in directory to make sure paths are relative - vfs.open("test2", "w").close() - print_stat(vfs.stat("test2")) - print_stat(vfs.stat("/testdir/test2")) - vfs.remove("test2") + fs.open("test2", "w").close() + print_stat(fs.stat("test2")) + print_stat(fs.stat("/testdir/test2")) + fs.remove("test2") # chdir back to root and remove testdir - vfs.chdir("/") - print(vfs.getcwd()) - vfs.chdir("testdir") - print(vfs.getcwd()) - vfs.chdir("..") - print(vfs.getcwd()) - vfs.chdir("testdir/subdir") - print(vfs.getcwd()) - vfs.chdir("../..") - print(vfs.getcwd()) - vfs.chdir("/./testdir2") - print(vfs.getcwd()) - vfs.chdir("../testdir") - print(vfs.getcwd()) - vfs.chdir("../..") - print(vfs.getcwd()) - vfs.chdir(".//testdir") - print(vfs.getcwd()) - vfs.chdir("subdir/./") - print(vfs.getcwd()) - vfs.chdir("/") - print(vfs.getcwd()) - vfs.rmdir("testdir/subdir") - vfs.rmdir("testdir") - vfs.rmdir("testdir2") + fs.chdir("/") + print(fs.getcwd()) + fs.chdir("testdir") + print(fs.getcwd()) + fs.chdir("..") + print(fs.getcwd()) + fs.chdir("testdir/subdir") + print(fs.getcwd()) + fs.chdir("../..") + print(fs.getcwd()) + fs.chdir("/./testdir2") + print(fs.getcwd()) + fs.chdir("../testdir") + print(fs.getcwd()) + fs.chdir("../..") + print(fs.getcwd()) + fs.chdir(".//testdir") + print(fs.getcwd()) + fs.chdir("subdir/./") + print(fs.getcwd()) + fs.chdir("/") + print(fs.getcwd()) + fs.rmdir("testdir/subdir") + fs.rmdir("testdir") + fs.rmdir("testdir2") bdev = RAMBlockDevice(30) -test(bdev, os.VfsLfs1) -test(bdev, os.VfsLfs2) +test(bdev, vfs.VfsLfs1) +test(bdev, vfs.VfsLfs2) diff --git a/tests/extmod/vfs_lfs_corrupt.py b/tests/extmod/vfs_lfs_corrupt.py index c49dcad92b441..0365c0c23f3c8 100644 --- a/tests/extmod/vfs_lfs_corrupt.py +++ b/tests/extmod/vfs_lfs_corrupt.py @@ -1,10 +1,10 @@ # Test for VfsLittle using a RAM device, testing error handling from corrupt block device try: - import os + import vfs - os.VfsLfs1 - os.VfsLfs2 + vfs.VfsLfs1 + vfs.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -47,28 +47,28 @@ def corrupt(bdev, block): def create_vfs(bdev, vfs_class): bdev.ret = 0 vfs_class.mkfs(bdev) - vfs = vfs_class(bdev) - with vfs.open("f", "w") as f: + fs = vfs_class(bdev) + with fs.open("f", "w") as f: for i in range(100): f.write("test") - return vfs + return fs def test(bdev, vfs_class): print("test", vfs_class) # statvfs - vfs = create_vfs(bdev, vfs_class) + fs = create_vfs(bdev, vfs_class) corrupt(bdev, 0) corrupt(bdev, 1) try: - print(vfs.statvfs("")) + print(fs.statvfs("")) except OSError: print("statvfs OSError") # error during read - vfs = create_vfs(bdev, vfs_class) - f = vfs.open("f", "r") + fs = create_vfs(bdev, vfs_class) + f = fs.open("f", "r") bdev.ret = -5 # EIO try: f.read(10) @@ -76,8 +76,8 @@ def test(bdev, vfs_class): print("read OSError") # error during write - vfs = create_vfs(bdev, vfs_class) - f = vfs.open("f", "a") + fs = create_vfs(bdev, vfs_class) + f = fs.open("f", "a") bdev.ret = -5 # EIO try: f.write("test") @@ -85,8 +85,8 @@ def test(bdev, vfs_class): print("write OSError") # error during close - vfs = create_vfs(bdev, vfs_class) - f = vfs.open("f", "w") + fs = create_vfs(bdev, vfs_class) + f = fs.open("f", "w") f.write("test") bdev.ret = -5 # EIO try: @@ -95,8 +95,8 @@ def test(bdev, vfs_class): print("close OSError") # error during flush - vfs = create_vfs(bdev, vfs_class) - f = vfs.open("f", "w") + fs = create_vfs(bdev, vfs_class) + f = fs.open("f", "w") f.write("test") bdev.ret = -5 # EIO try: @@ -108,5 +108,5 @@ def test(bdev, vfs_class): bdev = RAMBlockDevice(30) -test(bdev, os.VfsLfs1) -test(bdev, os.VfsLfs2) +test(bdev, vfs.VfsLfs1) +test(bdev, vfs.VfsLfs2) diff --git a/tests/extmod/vfs_lfs_error.py b/tests/extmod/vfs_lfs_error.py index 32b76b2821258..2ac7629bfa8fc 100644 --- a/tests/extmod/vfs_lfs_error.py +++ b/tests/extmod/vfs_lfs_error.py @@ -1,10 +1,10 @@ # Test for VfsLittle using a RAM device, testing error handling try: - import os + import vfs - os.VfsLfs1 - os.VfsLfs2 + vfs.VfsLfs1 + vfs.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -52,63 +52,63 @@ def test(bdev, vfs_class): # set up for following tests vfs_class.mkfs(bdev) - vfs = vfs_class(bdev) - with vfs.open("testfile", "w") as f: + fs = vfs_class(bdev) + with fs.open("testfile", "w") as f: f.write("test") - vfs.mkdir("testdir") + fs.mkdir("testdir") # ilistdir try: - vfs.ilistdir("noexist") + fs.ilistdir("noexist") except OSError: print("ilistdir OSError") # remove try: - vfs.remove("noexist") + fs.remove("noexist") except OSError: print("remove OSError") # rmdir try: - vfs.rmdir("noexist") + fs.rmdir("noexist") except OSError: print("rmdir OSError") # rename try: - vfs.rename("noexist", "somethingelse") + fs.rename("noexist", "somethingelse") except OSError: print("rename OSError") # mkdir try: - vfs.mkdir("testdir") + fs.mkdir("testdir") except OSError: print("mkdir OSError") # chdir to nonexistent try: - vfs.chdir("noexist") + fs.chdir("noexist") except OSError: print("chdir OSError") - print(vfs.getcwd()) # check still at root + print(fs.getcwd()) # check still at root # chdir to file try: - vfs.chdir("testfile") + fs.chdir("testfile") except OSError: print("chdir OSError") - print(vfs.getcwd()) # check still at root + print(fs.getcwd()) # check still at root # stat try: - vfs.stat("noexist") + fs.stat("noexist") except OSError: print("stat OSError") # error during seek - with vfs.open("testfile", "r") as f: + with fs.open("testfile", "r") as f: f.seek(1 << 30) # SEEK_SET try: f.seek(1 << 30, 1) # SEEK_CUR @@ -117,5 +117,5 @@ def test(bdev, vfs_class): bdev = RAMBlockDevice(30) -test(bdev, os.VfsLfs1) -test(bdev, os.VfsLfs2) +test(bdev, vfs.VfsLfs1) +test(bdev, vfs.VfsLfs2) diff --git a/tests/extmod/vfs_lfs_file.py b/tests/extmod/vfs_lfs_file.py index b4a3e6b22367a..0e1797714d346 100644 --- a/tests/extmod/vfs_lfs_file.py +++ b/tests/extmod/vfs_lfs_file.py @@ -1,10 +1,10 @@ # Test for VfsLittle using a RAM device, file IO try: - import os + import vfs - os.VfsLfs1 - os.VfsLfs2 + vfs.VfsLfs1 + vfs.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -42,10 +42,10 @@ def test(bdev, vfs_class): vfs_class.mkfs(bdev) # construction - vfs = vfs_class(bdev) + fs = vfs_class(bdev) # create text, print, write, close - f = vfs.open("test.txt", "wt") + f = fs.open("test.txt", "wt") print(f) f.write("littlefs") f.close() @@ -54,48 +54,48 @@ def test(bdev, vfs_class): f.close() # create binary, print, write, flush, close - f = vfs.open("test.bin", "wb") + f = fs.open("test.bin", "wb") print(f) f.write("littlefs") f.flush() f.close() # create for append - f = vfs.open("test.bin", "ab") + f = fs.open("test.bin", "ab") f.write("more") f.close() # create exclusive - f = vfs.open("test2.bin", "xb") + f = fs.open("test2.bin", "xb") f.close() # create exclusive with error try: - vfs.open("test2.bin", "x") + fs.open("test2.bin", "x") except OSError: print("open OSError") # read default - with vfs.open("test.txt", "") as f: + with fs.open("test.txt", "") as f: print(f.read()) # read text - with vfs.open("test.txt", "rt") as f: + with fs.open("test.txt", "rt") as f: print(f.read()) # read binary - with vfs.open("test.bin", "rb") as f: + with fs.open("test.bin", "rb") as f: print(f.read()) # create read and write - with vfs.open("test.bin", "r+b") as f: + with fs.open("test.bin", "r+b") as f: print(f.read(8)) f.write("MORE") - with vfs.open("test.bin", "rb") as f: + with fs.open("test.bin", "rb") as f: print(f.read()) # seek and tell - f = vfs.open("test.txt", "r") + f = fs.open("test.txt", "r") print(f.tell()) f.seek(3, 0) print(f.tell()) @@ -103,13 +103,13 @@ def test(bdev, vfs_class): # open nonexistent try: - vfs.open("noexist", "r") + fs.open("noexist", "r") except OSError: print("open OSError") # open multiple files at the same time - f1 = vfs.open("test.txt", "") - f2 = vfs.open("test.bin", "b") + f1 = fs.open("test.txt", "") + f2 = fs.open("test.bin", "b") print(f1.read()) print(f2.read()) f1.close() @@ -117,5 +117,5 @@ def test(bdev, vfs_class): bdev = RAMBlockDevice(30) -test(bdev, os.VfsLfs1) -test(bdev, os.VfsLfs2) +test(bdev, vfs.VfsLfs1) +test(bdev, vfs.VfsLfs2) diff --git a/tests/extmod/vfs_lfs_ilistdir_del.py b/tests/extmod/vfs_lfs_ilistdir_del.py index c183118fe0022..7b59bc412d983 100644 --- a/tests/extmod/vfs_lfs_ilistdir_del.py +++ b/tests/extmod/vfs_lfs_ilistdir_del.py @@ -2,9 +2,9 @@ import gc try: - import os + import vfs - os.VfsLfs2 + vfs.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -37,29 +37,29 @@ def ioctl(self, op, arg): def test(bdev, vfs_class): vfs_class.mkfs(bdev) - vfs = vfs_class(bdev) - vfs.mkdir("/test_d1") - vfs.mkdir("/test_d2") - vfs.mkdir("/test_d3") + fs = vfs_class(bdev) + fs.mkdir("/test_d1") + fs.mkdir("/test_d2") + fs.mkdir("/test_d3") for i in range(10): print(i) # We want to partially iterate the ilistdir iterator to leave it in an # open state, which will then test the finaliser when it's garbage collected. - idir = vfs.ilistdir("/") + idir = fs.ilistdir("/") print(any(idir)) # Alternate way of partially iterating the ilistdir object, modifying the # filesystem while it's open. - for dname, *_ in vfs.ilistdir("/"): - vfs.rmdir(dname) + for dname, *_ in fs.ilistdir("/"): + fs.rmdir(dname) break - vfs.mkdir(dname) + fs.mkdir(dname) # Also create a fully drained iterator and ensure trying to reuse it # throws the correct exception. - idir_emptied = vfs.ilistdir("/") + idir_emptied = fs.ilistdir("/") l = list(idir_emptied) print(len(l)) try: @@ -68,8 +68,8 @@ def test(bdev, vfs_class): pass gc.collect() - vfs.open("/test", "w").close() + fs.open("/test", "w").close() bdev = RAMBlockDevice(30) -test(bdev, os.VfsLfs2) +test(bdev, vfs.VfsLfs2) diff --git a/tests/extmod/vfs_lfs_mount.py b/tests/extmod/vfs_lfs_mount.py index 4ebd9ac6233f8..4887ddcec0085 100644 --- a/tests/extmod/vfs_lfs_mount.py +++ b/tests/extmod/vfs_lfs_mount.py @@ -1,10 +1,10 @@ # Test for VfsLittle using a RAM device, with mount/umount try: - import os + import os, vfs - os.VfsLfs1 - os.VfsLfs2 + vfs.VfsLfs1 + vfs.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -42,7 +42,7 @@ def test(vfs_class): # mount bdev unformatted try: - os.mount(bdev, "/lfs") + vfs.mount(bdev, "/lfs") except Exception as er: print(repr(er)) @@ -50,10 +50,10 @@ def test(vfs_class): vfs_class.mkfs(bdev) # construction - vfs = vfs_class(bdev) + fs = vfs_class(bdev) # mount - os.mount(vfs, "/lfs") + vfs.mount(fs, "/lfs") # import with open("/lfs/lfsmod.py", "w") as f: @@ -73,11 +73,11 @@ def test(vfs_class): import lfsmod2 # umount - os.umount("/lfs") + vfs.umount("/lfs") # mount read-only - vfs = vfs_class(bdev) - os.mount(vfs, "/lfs", readonly=True) + fs = vfs_class(bdev) + vfs.mount(fs, "/lfs", readonly=True) # test reading works with open("/lfs/subdir/lfsmod2.py") as f: @@ -90,13 +90,13 @@ def test(vfs_class): print(repr(er)) # umount - os.umount("/lfs") + vfs.umount("/lfs") # mount bdev again - os.mount(bdev, "/lfs") + vfs.mount(bdev, "/lfs") # umount - os.umount("/lfs") + vfs.umount("/lfs") # clear imported modules sys.modules.clear() @@ -110,5 +110,5 @@ def test(vfs_class): sys.path.append("") # run tests -test(os.VfsLfs1) -test(os.VfsLfs2) +test(vfs.VfsLfs1) +test(vfs.VfsLfs2) diff --git a/tests/extmod/vfs_lfs_mtime.py b/tests/extmod/vfs_lfs_mtime.py index ade02fa144987..3d163dc2687f0 100644 --- a/tests/extmod/vfs_lfs_mtime.py +++ b/tests/extmod/vfs_lfs_mtime.py @@ -1,11 +1,11 @@ # Test for VfsLfs using a RAM device, mtime feature try: - import time, os + import time, vfs time.time time.sleep - os.VfsLfs2 + vfs.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -44,21 +44,21 @@ def test(bdev, vfs_class): # construction print("mtime=True") - vfs = vfs_class(bdev, mtime=True) + fs = vfs_class(bdev, mtime=True) # Create an empty file, should have a timestamp. current_time = int(time.time()) - vfs.open("test1", "wt").close() + fs.open("test1", "wt").close() # Wait 1 second so mtime will increase by at least 1. time.sleep(1) # Create another empty file, should have a timestamp. - vfs.open("test2", "wt").close() + fs.open("test2", "wt").close() # Stat the files and check mtime is non-zero. - stat1 = vfs.stat("test1") - stat2 = vfs.stat("test2") + stat1 = fs.stat("test1") + stat2 = fs.stat("test2") print(stat1[8] != 0, stat2[8] != 0) # Check that test1 has mtime which matches time.time() at point of creation. @@ -71,34 +71,34 @@ def test(bdev, vfs_class): time.sleep(1) # Open test1 for reading and ensure mtime did not change. - vfs.open("test1", "rt").close() - print(vfs.stat("test1") == stat1) + fs.open("test1", "rt").close() + print(fs.stat("test1") == stat1) # Open test1 for writing and ensure mtime increased from the previous value. - vfs.open("test1", "wt").close() + fs.open("test1", "wt").close() stat1_old = stat1 - stat1 = vfs.stat("test1") + stat1 = fs.stat("test1") print(stat1_old[8] < stat1[8]) # Unmount. - vfs.umount() + fs.umount() # Check that remounting with mtime=False can read the timestamps. print("mtime=False") - vfs = vfs_class(bdev, mtime=False) - print(vfs.stat("test1") == stat1) - print(vfs.stat("test2") == stat2) - f = vfs.open("test1", "wt") + fs = vfs_class(bdev, mtime=False) + print(fs.stat("test1") == stat1) + print(fs.stat("test2") == stat2) + f = fs.open("test1", "wt") f.close() - print(vfs.stat("test1") == stat1) - vfs.umount() + print(fs.stat("test1") == stat1) + fs.umount() # Check that remounting with mtime=True still has the timestamps. print("mtime=True") - vfs = vfs_class(bdev, mtime=True) - print(vfs.stat("test1") == stat1) - print(vfs.stat("test2") == stat2) - vfs.umount() + fs = vfs_class(bdev, mtime=True) + print(fs.stat("test1") == stat1) + print(fs.stat("test2") == stat2) + fs.umount() try: @@ -107,4 +107,4 @@ def test(bdev, vfs_class): print("SKIP") raise SystemExit -test(bdev, os.VfsLfs2) +test(bdev, vfs.VfsLfs2) diff --git a/tests/extmod/vfs_lfs_superblock.py b/tests/extmod/vfs_lfs_superblock.py index b8a8ec60b967a..74b6004e991c0 100644 --- a/tests/extmod/vfs_lfs_superblock.py +++ b/tests/extmod/vfs_lfs_superblock.py @@ -1,9 +1,9 @@ # Test for VfsLfs using a RAM device, when the first superblock does not exist try: - import os + import os, vfs - os.VfsLfs2 + vfs.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -36,12 +36,12 @@ def ioctl(self, op, arg): bdev = RAMBlockDevice(64, lfs2_data) # Create the VFS explicitly, no auto-detection is needed for this. -vfs = os.VfsLfs2(bdev) -print(list(vfs.ilistdir())) +fs = vfs.VfsLfs2(bdev) +print(list(fs.ilistdir())) # Mount the block device directly; this relies on auto-detection. -os.mount(bdev, "/userfs") +vfs.mount(bdev, "/userfs") print(os.listdir("/userfs")) # Clean up. -os.umount("/userfs") +vfs.umount("/userfs") diff --git a/tests/extmod/vfs_posix.py b/tests/extmod/vfs_posix.py index bc4c7c2014b6c..d060c0b9c84f3 100644 --- a/tests/extmod/vfs_posix.py +++ b/tests/extmod/vfs_posix.py @@ -1,10 +1,9 @@ # Test for VfsPosix try: - import gc - import os + import gc, os, vfs - os.VfsPosix + vfs.VfsPosix except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -13,8 +12,6 @@ # Skip the test if it does exist. temp_dir = "micropy_test_dir" try: - import os - os.stat(temp_dir) print("SKIP") raise SystemExit @@ -87,35 +84,35 @@ def write_files_without_closing(): print(os.listdir(temp_dir)) # construct new VfsPosix with path argument -vfs = os.VfsPosix(temp_dir) -# when VfsPosix is used the intended way via os.mount(), it can only be called +fs = vfs.VfsPosix(temp_dir) +# when VfsPosix is used the intended way via vfs.mount(), it can only be called # with relative paths when the CWD is inside or at its root, so simulate that os.chdir(temp_dir) -print(list(i[0] for i in vfs.ilistdir("."))) +print(list(i[0] for i in fs.ilistdir("."))) # stat, statvfs (statvfs may not exist) -print(type(vfs.stat("."))) -if hasattr(vfs, "statvfs"): - assert type(vfs.statvfs(".")) is tuple +print(type(fs.stat("."))) +if hasattr(fs, "statvfs"): + assert type(fs.statvfs(".")) is tuple # check types of ilistdir with str/bytes arguments -print(type(list(vfs.ilistdir("."))[0][0])) -print(type(list(vfs.ilistdir(b"."))[0][0])) +print(type(list(fs.ilistdir("."))[0][0])) +print(type(list(fs.ilistdir(b"."))[0][0])) # chdir should not affect absolute paths (regression test) -vfs.mkdir("/subdir") -vfs.mkdir("/subdir/micropy_test_dir") -with vfs.open("/subdir/micropy_test_dir/test2", "w") as f: +fs.mkdir("/subdir") +fs.mkdir("/subdir/micropy_test_dir") +with fs.open("/subdir/micropy_test_dir/test2", "w") as f: f.write("wrong") -vfs.chdir("/subdir") -with vfs.open("/test2", "r") as f: +fs.chdir("/subdir") +with fs.open("/test2", "r") as f: print(f.read()) os.chdir(curdir) -vfs.remove("/subdir/micropy_test_dir/test2") -vfs.rmdir("/subdir/micropy_test_dir") -vfs.rmdir("/subdir") +fs.remove("/subdir/micropy_test_dir/test2") +fs.rmdir("/subdir/micropy_test_dir") +fs.rmdir("/subdir") -# done with vfs, restore CWD +# done with fs, restore CWD os.chdir(curdir) # remove diff --git a/tests/extmod/vfs_posix_enoent.py b/tests/extmod/vfs_posix_enoent.py index e6010d79d58f0..7b00388da539a 100644 --- a/tests/extmod/vfs_posix_enoent.py +++ b/tests/extmod/vfs_posix_enoent.py @@ -1,10 +1,9 @@ # Test for VfsPosix error conditions try: - import os - import sys + import os, sys, vfs - os.VfsPosix + vfs.VfsPosix except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -36,7 +35,7 @@ print("getcwd():", repr(e)) try: - print("VfsPosix():", os.VfsPosix("something")) + print("VfsPosix():", vfs.VfsPosix("something")) except OSError as e: # expecting ENOENT = 2 print("VfsPosix():", repr(e)) diff --git a/tests/extmod/vfs_posix_ilistdir_del.py b/tests/extmod/vfs_posix_ilistdir_del.py index 11b45e619781e..78d7c854c543c 100644 --- a/tests/extmod/vfs_posix_ilistdir_del.py +++ b/tests/extmod/vfs_posix_ilistdir_del.py @@ -2,9 +2,9 @@ import gc try: - import os + import os, vfs - os.VfsPosix + vfs.VfsPosix except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -12,34 +12,34 @@ def test(testdir): curdir = os.getcwd() - vfs = os.VfsPosix(testdir) - # When VfsPosix is used the intended way via os.mount(), it can only be called + fs = vfs.VfsPosix(testdir) + # When VfsPosix is used the intended way via vfs.mount(), it can only be called # with relative paths when the CWD is inside or at its root, so simulate that. # (Although perhaps calling with a relative path was an oversight in this case - # and the respective line below was meant to read `vfs.rmdir("/" + dname)`.) + # and the respective line below was meant to read `fs.rmdir("/" + dname)`.) os.chdir(testdir) - vfs.mkdir("/test_d1") - vfs.mkdir("/test_d2") - vfs.mkdir("/test_d3") + fs.mkdir("/test_d1") + fs.mkdir("/test_d2") + fs.mkdir("/test_d3") for i in range(10): print(i) # We want to partially iterate the ilistdir iterator to leave it in an # open state, which will then test the finaliser when it's garbage collected. - idir = vfs.ilistdir("/") + idir = fs.ilistdir("/") print(any(idir)) # Alternate way of partially iterating the ilistdir object, modifying the # filesystem while it's open. - for dname, *_ in vfs.ilistdir("/"): - vfs.rmdir(dname) + for dname, *_ in fs.ilistdir("/"): + fs.rmdir(dname) break - vfs.mkdir(dname) + fs.mkdir(dname) # Also create a fully drained iterator and ensure trying to reuse it # throws the correct exception. - idir_emptied = vfs.ilistdir("/") + idir_emptied = fs.ilistdir("/") l = list(idir_emptied) print(len(l)) try: @@ -51,10 +51,10 @@ def test(testdir): # Create and delete a file, try to flush out any filesystem # corruption that may be caused over the loops. - vfs.open("/test", "w").close() - vfs.remove("/test") + fs.open("/test", "w").close() + fs.remove("/test") - # Done with vfs, restore CWD. + # Done with fs, restore CWD. os.chdir(curdir) diff --git a/tests/extmod/vfs_posix_ilistdir_filter.py b/tests/extmod/vfs_posix_ilistdir_filter.py index 54012746057a8..6df9542045935 100644 --- a/tests/extmod/vfs_posix_ilistdir_filter.py +++ b/tests/extmod/vfs_posix_ilistdir_filter.py @@ -1,9 +1,9 @@ # Test ilistdir filter of . and .. for VfsPosix. try: - import os + import os, vfs - os.VfsPosix + vfs.VfsPosix except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -11,24 +11,24 @@ def test(testdir): curdir = os.getcwd() - vfs = os.VfsPosix(testdir) - # When VfsPosix is used the intended way via os.mount(), it can only be called + fs = vfs.VfsPosix(testdir) + # When VfsPosix is used the intended way via vfs.mount(), it can only be called # with relative paths when the CWD is inside or at its root, so simulate that. os.chdir(testdir) dirs = [".a", "..a", "...a", "a.b", "a..b"] for dir in dirs: - vfs.mkdir(dir) + fs.mkdir(dir) dirs = [] - for entry in vfs.ilistdir("/"): + for entry in fs.ilistdir("/"): dirs.append(entry[0]) dirs.sort() print(dirs) - # Done with vfs, restore CWD. + # Done with fs, restore CWD. os.chdir(curdir) diff --git a/tests/extmod/vfs_posix_paths.py b/tests/extmod/vfs_posix_paths.py index 5806a34521a23..b4fedc6716f01 100644 --- a/tests/extmod/vfs_posix_paths.py +++ b/tests/extmod/vfs_posix_paths.py @@ -1,9 +1,9 @@ # Test for VfsPosix with relative paths try: - import os + import os, vfs - os.VfsPosix + vfs.VfsPosix except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -12,8 +12,6 @@ # Skip the test if it does exist. temp_dir = "vfs_posix_paths_test_dir" try: - import os - os.stat(temp_dir) print("SKIP") raise SystemExit @@ -25,26 +23,26 @@ # construct new VfsPosix with absolute path argument temp_dir_abs = os.getcwd() + os.sep + temp_dir -vfs = os.VfsPosix(temp_dir_abs) -# when VfsPosix is used the intended way via os.mount(), it can only be called +fs = vfs.VfsPosix(temp_dir_abs) +# when VfsPosix is used the intended way via vfs.mount(), it can only be called # with relative paths when the CWD is inside or at its root, so simulate that os.chdir(temp_dir_abs) -vfs.mkdir("subdir") -vfs.mkdir("subdir/one") -print('listdir("/"):', sorted(i[0] for i in vfs.ilistdir("/"))) -print('listdir("."):', sorted(i[0] for i in vfs.ilistdir("."))) -print('getcwd() in {"", "/"}:', vfs.getcwd() in {"", "/"}) -print('chdir("subdir"):', vfs.chdir("subdir")) -print("getcwd():", vfs.getcwd()) -print('mkdir("two"):', vfs.mkdir("two")) -f = vfs.open("file.py", "w") +fs.mkdir("subdir") +fs.mkdir("subdir/one") +print('listdir("/"):', sorted(i[0] for i in fs.ilistdir("/"))) +print('listdir("."):', sorted(i[0] for i in fs.ilistdir("."))) +print('getcwd() in {"", "/"}:', fs.getcwd() in {"", "/"}) +print('chdir("subdir"):', fs.chdir("subdir")) +print("getcwd():", fs.getcwd()) +print('mkdir("two"):', fs.mkdir("two")) +f = fs.open("file.py", "w") f.write("print('hello')") f.close() -print('listdir("/"):', sorted(i[0] for i in vfs.ilistdir("/"))) -print('listdir("/subdir"):', sorted(i[0] for i in vfs.ilistdir("/subdir"))) -print('listdir("."):', sorted(i[0] for i in vfs.ilistdir("."))) +print('listdir("/"):', sorted(i[0] for i in fs.ilistdir("/"))) +print('listdir("/subdir"):', sorted(i[0] for i in fs.ilistdir("/subdir"))) +print('listdir("."):', sorted(i[0] for i in fs.ilistdir("."))) try: - f = vfs.open("/subdir/file.py", "r") + f = fs.open("/subdir/file.py", "r") print(f.read()) f.close() except Exception as e: @@ -59,17 +57,17 @@ except Exception as e: print(e) del sys.path[0] -vfs.remove("file.py") -vfs.rmdir("two") -vfs.rmdir("/subdir/one") -vfs.chdir("/") -vfs.rmdir("/subdir") +fs.remove("file.py") +fs.rmdir("two") +fs.rmdir("/subdir/one") +fs.chdir("/") +fs.rmdir("/subdir") -# done with vfs, restore CWD +# done with fs, restore CWD os.chdir(curdir) # some integration tests with a mounted VFS -os.mount(os.VfsPosix(temp_dir_abs), "/mnt") +vfs.mount(vfs.VfsPosix(temp_dir_abs), "/mnt") os.mkdir("/mnt/dir") print('chdir("/mnt/dir"):', os.chdir("/mnt/dir")) print("getcwd():", os.getcwd()) @@ -82,7 +80,7 @@ print('chdir(".."):', os.chdir("..")) print("getcwd():", os.getcwd()) os.rmdir("/mnt/dir") -os.umount("/mnt") +vfs.umount("/mnt") # restore CWD os.chdir(curdir) diff --git a/tests/extmod/vfs_userfs.py b/tests/extmod/vfs_userfs.py index 5c487315eb5eb..a7b87ec0b0d0c 100644 --- a/tests/extmod/vfs_userfs.py +++ b/tests/extmod/vfs_userfs.py @@ -4,12 +4,9 @@ import sys try: - import io + import io, vfs io.IOBase - import os - - os.mount except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -79,7 +76,7 @@ def open(self, path, mode): "/usermod5.py": b"print('in usermod5')", "/usermod6.py": b"print('in usermod6')", } -os.mount(UserFS(user_files), "/userfs") +vfs.mount(UserFS(user_files), "/userfs") # open and read a file f = open("/userfs/data.txt") @@ -110,5 +107,5 @@ def open(self, path, mode): import usermod6 # unmount and undo path addition -os.umount("/userfs") +vfs.umount("/userfs") sys.path.pop() diff --git a/tests/micropython/builtin_execfile.py b/tests/micropython/builtin_execfile.py index 9b6d6a0aa00bc..a905521c662d3 100644 --- a/tests/micropython/builtin_execfile.py +++ b/tests/micropython/builtin_execfile.py @@ -1,11 +1,10 @@ # Test builtin execfile function using VFS. try: - import io, os + import io, os, vfs execfile io.IOBase - os.mount except (ImportError, NameError, AttributeError): print("SKIP") raise SystemExit @@ -44,25 +43,21 @@ def open(self, file, mode): # First umount any existing mount points the target may have. try: - import io, os - - os.umount("/") + vfs.umount("/") except OSError: pass for path in os.listdir("/"): - os.umount("/" + path) + vfs.umount("/" + path) # Create and mount the VFS object. files = { "/test.py": "print(123)", } fs = Filesystem(files) -os.mount(fs, "/test_mnt") +vfs.mount(fs, "/test_mnt") # Test execfile with a file that doesn't exist. try: - import io, os - execfile("/test_mnt/noexist.py") except OSError: print("OSError") @@ -77,4 +72,4 @@ def open(self, file, mode): print("TypeError") # Unmount the VFS object. -os.umount(fs) +vfs.umount(fs) diff --git a/tests/micropython/import_mpy_invalid.py b/tests/micropython/import_mpy_invalid.py index 36db102e9d6f3..c7f0a2c1a1c61 100644 --- a/tests/micropython/import_mpy_invalid.py +++ b/tests/micropython/import_mpy_invalid.py @@ -1,10 +1,9 @@ # test importing of invalid .mpy files try: - import sys, io, os + import sys, io, vfs io.IOBase - os.mount except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -52,7 +51,7 @@ def open(self, path, mode): } # create and mount a user filesystem -os.mount(UserFS(user_files), "/userfs") +vfs.mount(UserFS(user_files), "/userfs") sys.path.append("/userfs") # import .mpy files from the user filesystem @@ -64,5 +63,5 @@ def open(self, path, mode): print(mod, "ValueError", er) # unmount and undo path addition -os.umount("/userfs") +vfs.umount("/userfs") sys.path.pop() diff --git a/tests/micropython/import_mpy_native.py b/tests/micropython/import_mpy_native.py index da20746b225de..8f5de25a0b2c1 100644 --- a/tests/micropython/import_mpy_native.py +++ b/tests/micropython/import_mpy_native.py @@ -1,11 +1,10 @@ # test importing of .mpy files with native code try: - import sys, io, os + import sys, io, vfs sys.implementation._mpy io.IOBase - os.mount except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -110,7 +109,7 @@ def open(self, path, mode): # fmt: on # create and mount a user filesystem -os.mount(UserFS(user_files), "/userfs") +vfs.mount(UserFS(user_files), "/userfs") sys.path.append("/userfs") # import .mpy files from the user filesystem @@ -123,5 +122,5 @@ def open(self, path, mode): print(mod, "ValueError", er) # unmount and undo path addition -os.umount("/userfs") +vfs.umount("/userfs") sys.path.pop() diff --git a/tests/micropython/import_mpy_native_gc.py b/tests/micropython/import_mpy_native_gc.py index e0da8d2c37e4c..6b8d7ddd632e2 100644 --- a/tests/micropython/import_mpy_native_gc.py +++ b/tests/micropython/import_mpy_native_gc.py @@ -1,11 +1,10 @@ # Test that native code loaded from a .mpy file is retained after a GC. try: - import gc, sys, io, os + import gc, sys, io, vfs sys.implementation._mpy io.IOBase - os.mount except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -72,7 +71,7 @@ def open(self, path, mode): user_files = {"/features0.mpy": features0_file_contents[sys_implementation_mpy]} # Create and mount a user filesystem. -os.mount(UserFS(user_files), "/userfs") +vfs.mount(UserFS(user_files), "/userfs") sys.path.append("/userfs") # Import the native function. @@ -93,5 +92,5 @@ def open(self, path, mode): print(factorial(10)) # Unmount and undo path addition. -os.umount("/userfs") +vfs.umount("/userfs") sys.path.pop() diff --git a/tests/perf_bench/core_import_mpy_multi.py b/tests/perf_bench/core_import_mpy_multi.py index 364c325042843..33437f9da801e 100644 --- a/tests/perf_bench/core_import_mpy_multi.py +++ b/tests/perf_bench/core_import_mpy_multi.py @@ -1,8 +1,8 @@ # Test performance of importing an .mpy file many times. -import sys, io, os +import sys, io, vfs -if not (hasattr(io, "IOBase") and hasattr(os, "mount")): +if not hasattr(io, "IOBase"): print("SKIP") raise SystemExit @@ -57,7 +57,7 @@ def open(self, path, mode): def mount(): - os.mount(FS(), "/__remote") + vfs.mount(FS(), "/__remote") sys.path.insert(0, "/__remote") diff --git a/tests/perf_bench/core_import_mpy_single.py b/tests/perf_bench/core_import_mpy_single.py index 5757c3eaf1fdf..18454b8fd5eb2 100644 --- a/tests/perf_bench/core_import_mpy_single.py +++ b/tests/perf_bench/core_import_mpy_single.py @@ -2,9 +2,9 @@ # The first import of a module will intern strings that don't already exist, and # this test should be representative of what happens in a real application. -import io, os, sys +import sys, io, vfs -if not (hasattr(io, "IOBase") and hasattr(os, "mount")): +if not hasattr(io, "IOBase"): print("SKIP") raise SystemExit @@ -112,7 +112,7 @@ def open(self, path, mode): def mount(): - os.mount(FS(), "/__remote") + vfs.mount(FS(), "/__remote") sys.path.insert(0, "/__remote") diff --git a/tests/ports/cc3200/os.py b/tests/ports/cc3200/os.py index 1f4debcade55c..c126dcffc4e3d 100644 --- a/tests/ports/cc3200/os.py +++ b/tests/ports/cc3200/os.py @@ -3,7 +3,7 @@ """ from machine import SD -import os +import os, vfs mch = os.uname().machine if "LaunchPad" in mch: @@ -15,7 +15,7 @@ sd = SD(pins=sd_pins) -os.mount(sd, "/sd") +vfs.mount(sd, "/sd") os.mkfs("/sd") os.chdir("/flash") print(os.listdir()) @@ -88,7 +88,7 @@ os.unmount("/sd") print(os.listdir("/")) os.mkfs(sd) -os.mount(sd, "/sd") +vfs.mount(sd, "/sd") print(os.listdir("/")) os.chdir("/flash") @@ -104,12 +104,12 @@ print(os.listdir("/sd")) try: - os.mount(sd, "/sd") + vfs.mount(sd, "/sd") except: print("Exception") try: - os.mount(sd, "/sd2") + vfs.mount(sd, "/sd2") except: print("Exception") @@ -159,6 +159,6 @@ except: print("Exception") -os.mount(sd, "/sd") +vfs.mount(sd, "/sd") print(os.listdir("/")) os.unmount("/sd") diff --git a/tests/run-natmodtests.py b/tests/run-natmodtests.py index 5764021472144..e61cf09933f0c 100755 --- a/tests/run-natmodtests.py +++ b/tests/run-natmodtests.py @@ -30,7 +30,7 @@ # Code to allow a target MicroPython to import an .mpy from RAM injected_import_hook_code = """\ -import sys, os, io +import sys, io, vfs class __File(io.IOBase): def __init__(self): self.off = 0 @@ -52,7 +52,7 @@ def stat(self, path): raise OSError(-2) # ENOENT def open(self, path, mode): return __File() -os.mount(__FS(), '/__remote') +vfs.mount(__FS(), '/__remote') sys.path.insert(0, '/__remote') sys.modules['{}'] = __import__('__injected') """ diff --git a/tests/run-tests.py b/tests/run-tests.py index c912f9d5424df..ba66eced41aff 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -59,7 +59,7 @@ def base_path(*p): # Code to allow a target MicroPython to import an .mpy from RAM injected_import_hook_code = """\ -import sys, os, io +import sys, os, io, vfs class __File(io.IOBase): def __init__(self): self.off = 0 @@ -83,7 +83,7 @@ def stat(self, path): raise OSError(-2) # ENOENT def open(self, path, mode): return __File() -os.mount(__FS(), '/__vfstest') +vfs.mount(__FS(), '/__vfstest') os.chdir('/__vfstest') __import__('__injected_test') """ From 7d28789544e4e35d8c931b41765dd64a53c506f1 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 22 Nov 2023 16:24:10 +1100 Subject: [PATCH 102/408] ports: Use vfs module instead of os. Signed-off-by: Damien George --- ports/esp32/modules/_boot.py | 6 +++--- ports/esp32/modules/inisetup.py | 14 +++++++------- ports/esp8266/boards/ESP8266_GENERIC/board.md | 2 +- ports/esp8266/modules/_boot.py | 4 ++-- ports/esp8266/modules/inisetup.py | 10 +++++----- ports/mimxrt/boards/TEENSY40/format.py | 8 ++++---- ports/mimxrt/modules/_boot.py | 13 +++++++------ ports/nrf/examples/mountsd.py | 4 ++-- ports/nrf/examples/seeed_tft.py | 4 ++-- ports/nrf/modules/scripts/_mkfs.py | 14 +++++++------- ports/rp2/modules/_boot.py | 12 ++++++------ ports/rp2/modules/_boot_fat.py | 13 ++++++------- ports/samd/modules/_boot.py | 12 ++++++------ 13 files changed, 58 insertions(+), 58 deletions(-) diff --git a/ports/esp32/modules/_boot.py b/ports/esp32/modules/_boot.py index 651fc7b10cdd8..96af581f38a5c 100644 --- a/ports/esp32/modules/_boot.py +++ b/ports/esp32/modules/_boot.py @@ -1,13 +1,13 @@ import gc -import os +import vfs from flashbdev import bdev try: if bdev: - os.mount(bdev, "/") + vfs.mount(bdev, "/") except OSError: import inisetup - vfs = inisetup.setup() + inisetup.setup() gc.collect() diff --git a/ports/esp32/modules/inisetup.py b/ports/esp32/modules/inisetup.py index 2003864e9f3e8..4e9b462fb3c3a 100644 --- a/ports/esp32/modules/inisetup.py +++ b/ports/esp32/modules/inisetup.py @@ -1,4 +1,4 @@ -import os +import vfs from flashbdev import bdev @@ -38,12 +38,12 @@ def setup(): check_bootsec() print("Performing initial setup") if bdev.info()[4] == "vfs": - os.VfsLfs2.mkfs(bdev) - vfs = os.VfsLfs2(bdev) + vfs.VfsLfs2.mkfs(bdev) + fs = vfs.VfsLfs2(bdev) elif bdev.info()[4] == "ffat": - os.VfsFat.mkfs(bdev) - vfs = os.VfsFat(bdev) - os.mount(vfs, "/") + vfs.VfsFat.mkfs(bdev) + fs = vfs.VfsFat(bdev) + vfs.mount(fs, "/") with open("boot.py", "w") as f: f.write( """\ @@ -54,4 +54,4 @@ def setup(): #webrepl.start() """ ) - return vfs + return fs diff --git a/ports/esp8266/boards/ESP8266_GENERIC/board.md b/ports/esp8266/boards/ESP8266_GENERIC/board.md index 96fbab617a8f6..e8d63fcead0c4 100644 --- a/ports/esp8266/boards/ESP8266_GENERIC/board.md +++ b/ports/esp8266/boards/ESP8266_GENERIC/board.md @@ -13,7 +13,7 @@ Note: v1.12-334 and newer (including v1.13) require an ESP8266 module with 2MiB of flash or more, and use littlefs as the filesystem by default. When upgrading from older firmware please backup your files first, and either erase all flash before upgrading, or after upgrading execute -`os.VfsLfs2.mkfs(bdev)`. +`vfs.VfsLfs2.mkfs(bdev)`. ### OTA builds Over-The-Air (OTA) builds of the ESP8266 firmware are also provided. diff --git a/ports/esp8266/modules/_boot.py b/ports/esp8266/modules/_boot.py index 06b372990a52d..00a0d6550f945 100644 --- a/ports/esp8266/modules/_boot.py +++ b/ports/esp8266/modules/_boot.py @@ -1,12 +1,12 @@ import gc gc.threshold((gc.mem_free() + gc.mem_alloc()) // 4) -import os +import vfs from flashbdev import bdev if bdev: try: - os.mount(bdev, "/") + vfs.mount(bdev, "/") except: import inisetup diff --git a/ports/esp8266/modules/inisetup.py b/ports/esp8266/modules/inisetup.py index 3f3edcf6d0af0..20bb28e80b064 100644 --- a/ports/esp8266/modules/inisetup.py +++ b/ports/esp8266/modules/inisetup.py @@ -1,4 +1,4 @@ -import os +import vfs import network from flashbdev import bdev @@ -36,7 +36,7 @@ def fs_corrupted(): """\ The filesystem starting at sector %d with size %d sectors looks corrupt. You may want to make a flash snapshot and try to recover it. Otherwise, -format it with os.VfsLfs2.mkfs(bdev), or completely erase the flash and +format it with vfs.VfsLfs2.mkfs(bdev), or completely erase the flash and reprogram MicroPython. """ % (bdev.start_sec, bdev.blocks) @@ -48,9 +48,9 @@ def setup(): check_bootsec() print("Performing initial setup") wifi() - os.VfsLfs2.mkfs(bdev) - vfs = os.VfsLfs2(bdev) - os.mount(vfs, "/") + vfs.VfsLfs2.mkfs(bdev) + fs = vfs.VfsLfs2(bdev) + vfs.mount(fs, "/") with open("boot.py", "w") as f: f.write( """\ diff --git a/ports/mimxrt/boards/TEENSY40/format.py b/ports/mimxrt/boards/TEENSY40/format.py index 75e5aa95caef0..1204ac240ccd3 100644 --- a/ports/mimxrt/boards/TEENSY40/format.py +++ b/ports/mimxrt/boards/TEENSY40/format.py @@ -1,11 +1,11 @@ # format.py # Re-create the file system -import os +import vfs import mimxrt bdev = mimxrt.Flash() -os.VfsLfs2.mkfs(bdev, progsize=256) -vfs = os.VfsLfs2(bdev, progsize=256) -os.mount(vfs, "/") +vfs.VfsLfs2.mkfs(bdev, progsize=256) +fs = vfs.VfsLfs2(bdev, progsize=256) +vfs.mount(fs, "/") diff --git a/ports/mimxrt/modules/_boot.py b/ports/mimxrt/modules/_boot.py index 56f12a4ce1590..fa3b780434a43 100644 --- a/ports/mimxrt/modules/_boot.py +++ b/ports/mimxrt/modules/_boot.py @@ -3,17 +3,18 @@ # Note: the flash requires the programming size to be aligned to 256 bytes. import os +import vfs import sys import mimxrt from machine import Pin bdev = mimxrt.Flash() try: - vfs = os.VfsLfs2(bdev, progsize=256) + fs = vfs.VfsLfs2(bdev, progsize=256) except: - os.VfsLfs2.mkfs(bdev, progsize=256) - vfs = os.VfsLfs2(bdev, progsize=256) -os.mount(vfs, "/flash") + vfs.VfsLfs2.mkfs(bdev, progsize=256) + fs = vfs.VfsLfs2(bdev, progsize=256) +vfs.mount(fs, "/flash") os.chdir("/flash") sys.path.append("/flash") sys.path.append("/flash/lib") @@ -27,8 +28,8 @@ sdcard = SDCard(1) - fat = os.VfsFat(sdcard) - os.mount(fat, "/sdcard") + fat = vfs.VfsFat(sdcard) + vfs.mount(fat, "/sdcard") os.chdir("/sdcard") sys.path.append("/sdcard") except: diff --git a/ports/nrf/examples/mountsd.py b/ports/nrf/examples/mountsd.py index 315205c6959b0..37522596150ab 100644 --- a/ports/nrf/examples/mountsd.py +++ b/ports/nrf/examples/mountsd.py @@ -20,7 +20,7 @@ --------------------------------- """ -import os +import os, vfs from machine import SPI, Pin from sdcard import SDCard @@ -28,7 +28,7 @@ def mnt(): cs = Pin("P22", mode=Pin.OUT) sd = SDCard(SPI(0), cs) - os.mount(sd, "/") + vfs.mount(sd, "/") def list(): diff --git a/ports/nrf/examples/seeed_tft.py b/ports/nrf/examples/seeed_tft.py index fc0617f20b2d7..f53b560226363 100644 --- a/ports/nrf/examples/seeed_tft.py +++ b/ports/nrf/examples/seeed_tft.py @@ -44,7 +44,7 @@ tf = mount_tf() os.listdir() """ -import os +import vfs import time import framebuf @@ -54,7 +54,7 @@ def mount_tf(self, mount_point="/"): sd = SDCard(SPI(0), Pin("P15", mode=Pin.OUT)) - os.mount(sd, mount_point) + vfs.mount(sd, mount_point) class ILI9341: diff --git a/ports/nrf/modules/scripts/_mkfs.py b/ports/nrf/modules/scripts/_mkfs.py index 02e8dabce285f..601f9558eb7b5 100644 --- a/ports/nrf/modules/scripts/_mkfs.py +++ b/ports/nrf/modules/scripts/_mkfs.py @@ -1,19 +1,19 @@ -import os, nrf +import vfs, nrf try: - from os import VfsLfs1 + from vfs import VfsLfs1 - os.VfsLfs1.mkfs(nrf.Flash()) + vfs.VfsLfs1.mkfs(nrf.Flash()) except ImportError: try: - from os import VfsLfs2 + from vfs import VfsLfs2 - os.VfsLfs2.mkfs(nrf.Flash()) + vfs.VfsLfs2.mkfs(nrf.Flash()) except ImportError: try: - from os import VfsFat + from vfs import VfsFat - os.VfsFat.mkfs(nrf.Flash()) + vfs.VfsFat.mkfs(nrf.Flash()) except ImportError: pass except OSError as e: diff --git a/ports/rp2/modules/_boot.py b/ports/rp2/modules/_boot.py index 099e5aba05907..71cb28d6823bb 100644 --- a/ports/rp2/modules/_boot.py +++ b/ports/rp2/modules/_boot.py @@ -1,4 +1,4 @@ -import os +import vfs import machine, rp2 @@ -6,10 +6,10 @@ # Note: the flash requires the programming size to be aligned to 256 bytes. bdev = rp2.Flash() try: - vfs = os.VfsLfs2(bdev, progsize=256) + fs = vfs.VfsLfs2(bdev, progsize=256) except: - os.VfsLfs2.mkfs(bdev, progsize=256) - vfs = os.VfsLfs2(bdev, progsize=256) -os.mount(vfs, "/") + vfs.VfsLfs2.mkfs(bdev, progsize=256) + fs = vfs.VfsLfs2(bdev, progsize=256) +vfs.mount(fs, "/") -del os, bdev, vfs +del vfs, bdev, fs diff --git a/ports/rp2/modules/_boot_fat.py b/ports/rp2/modules/_boot_fat.py index 02a2df9babee5..5220584455dca 100644 --- a/ports/rp2/modules/_boot_fat.py +++ b/ports/rp2/modules/_boot_fat.py @@ -1,15 +1,14 @@ -import os +import vfs import machine, rp2 # Try to mount the filesystem, and format the flash if it doesn't exist. bdev = rp2.Flash() try: - vfs = os.VfsFat(bdev) - os.mount(vfs, "/") + fs = vfs.VfsFat(bdev) except: - os.VfsFat.mkfs(bdev) - vfs = os.VfsFat(bdev) -os.mount(vfs, "/") + vfs.VfsFat.mkfs(bdev) + fs = vfs.VfsFat(bdev) +vfs.mount(fs, "/") -del os, bdev, vfs +del vfs, bdev, fs diff --git a/ports/samd/modules/_boot.py b/ports/samd/modules/_boot.py index 93522e2ea32b4..f4053e2cddf00 100644 --- a/ports/samd/modules/_boot.py +++ b/ports/samd/modules/_boot.py @@ -1,21 +1,21 @@ import gc -import os +import vfs import samd import sys bdev = samd.Flash() # Try to mount the filesystem, and format the flash if it doesn't exist. -fs_type = os.VfsLfs2 if hasattr(os, "VfsLfs2") else os.VfsLfs1 +fs_type = vfs.VfsLfs2 if hasattr(vfs, "VfsLfs2") else vfs.VfsLfs1 try: - vfs = fs_type(bdev, progsize=256) + fs = fs_type(bdev, progsize=256) except: fs_type.mkfs(bdev, progsize=256) - vfs = fs_type(bdev, progsize=256) -os.mount(vfs, "/") + fs = fs_type(bdev, progsize=256) +vfs.mount(fs, "/") sys.path.append("/lib") -del vfs, fs_type, bdev, os, samd, sys +del fs, fs_type, bdev, vfs, samd, sys gc.collect() del gc From 4c56b39051b4a992d8691aa504cd2e76b958bf26 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 2 Feb 2024 13:51:18 +1100 Subject: [PATCH 103/408] docs: Use vfs module instead of os. Signed-off-by: Damien George --- docs/esp32/quickref.rst | 6 +-- docs/library/machine.SD.rst | 4 +- docs/library/machine.SDCard.rst | 2 +- docs/library/pyb.rst | 2 +- docs/mimxrt/quickref.rst | 14 +++---- docs/pyboard/general.rst | 2 +- docs/reference/filesystem.rst | 64 ++++++++++++++++---------------- docs/renesas-ra/quickref.rst | 6 +-- docs/wipy/general.rst | 2 +- docs/wipy/quickref.rst | 4 +- docs/zephyr/quickref.rst | 12 +++--- docs/zephyr/tutorial/storage.rst | 12 +++--- 12 files changed, 65 insertions(+), 65 deletions(-) diff --git a/docs/esp32/quickref.rst b/docs/esp32/quickref.rst index 08df25b0554d0..9c77dc402ebef 100644 --- a/docs/esp32/quickref.rst +++ b/docs/esp32/quickref.rst @@ -650,15 +650,15 @@ SD card See :ref:`machine.SDCard `. :: - import machine, os + import machine, os, vfs # Slot 2 uses pins sck=18, cs=5, miso=19, mosi=23 sd = machine.SDCard(slot=2) - os.mount(sd, '/sd') # mount + vfs.mount(sd, '/sd') # mount os.listdir('/sd') # list directory contents - os.umount('/sd') # eject + vfs.umount('/sd') # eject RMT --- diff --git a/docs/library/machine.SD.rst b/docs/library/machine.SD.rst index c736dc4d2836e..b10b407a2f65e 100644 --- a/docs/library/machine.SD.rst +++ b/docs/library/machine.SD.rst @@ -20,11 +20,11 @@ more info regarding the pins which can be remapped to be used with a SD card. Example usage:: from machine import SD - import os + import vfs # clk cmd and dat0 pins must be passed along with # their respective alternate functions sd = machine.SD(pins=('GP10', 'GP11', 'GP15')) - os.mount(sd, '/sd') + vfs.mount(sd, '/sd') # do normal file operations Constructors diff --git a/docs/library/machine.SDCard.rst b/docs/library/machine.SDCard.rst index 4faa7a5557723..e4bb25dfc0377 100644 --- a/docs/library/machine.SDCard.rst +++ b/docs/library/machine.SDCard.rst @@ -30,7 +30,7 @@ vary from platform to platform. The class implements the block protocol defined by :class:`vfs.AbstractBlockDev`. This allows the mounting of an SD card to be as simple as:: - os.mount(machine.SDCard(), "/sd") + vfs.mount(machine.SDCard(), "/sd") The constructor takes the following parameters: diff --git a/docs/library/pyb.rst b/docs/library/pyb.rst index 869e2f8f3bd9b..f169a77f3a6ca 100644 --- a/docs/library/pyb.rst +++ b/docs/library/pyb.rst @@ -213,7 +213,7 @@ Miscellaneous functions .. function:: mount(device, mountpoint, *, readonly=False, mkfs=False) .. note:: This function is deprecated. Mounting and unmounting devices should - be performed by :meth:`os.mount` and :meth:`os.umount` instead. + be performed by :meth:`vfs.mount` and :meth:`vfs.umount` instead. Mount a block device and make it available as part of the filesystem. ``device`` must be an object that provides the block protocol. (The diff --git a/docs/mimxrt/quickref.rst b/docs/mimxrt/quickref.rst index 578364c55a4ce..519313438321c 100644 --- a/docs/mimxrt/quickref.rst +++ b/docs/mimxrt/quickref.rst @@ -443,27 +443,27 @@ SD card See :ref:`machine.SDCard `:: - import machine, os + import machine, os, vfs sd = machine.SDCard() - fs = os.VfsFat(sd) - os.mount(fs, "/sd") # mount + fs = vfs.VfsFat(sd) + vfs.mount(fs, "/sd") # mount os.listdir('/sd') # list directory contents - os.umount('/sd') # eject + vfs.umount('/sd') # eject Note: The i.mx-rt 1011 and 1015 based boards do not support the ``machine.SDCard`` class. For these, the SPI based driver ``sdcard.py`` from the MicroPython drivers can be used. When using it, you have to overdrive the CS pin of the SPI hardware module. Example:: - import os, sdcard, machine + import vfs, sdcard, machine cs_pin = "D10" spi = machine.SPI(0) # SPI0 with cs at Pin "D10" used for SDCARD cs = machine.Pin(cs_pin, machine.Pin.OUT, value=1) sd = sdcard.SDCard(spi, cs) - vfs = os.VfsFat(sd) - os.mount(vfs, "/sdcard") + fs = vfs.VfsFat(sd) + vfs.mount(fs, "/sdcard") OneWire driver -------------- diff --git a/docs/pyboard/general.rst b/docs/pyboard/general.rst index 0fc7332dedf4f..d1bf3829bec18 100644 --- a/docs/pyboard/general.rst +++ b/docs/pyboard/general.rst @@ -21,7 +21,7 @@ If needed, you can prevent the use of the SD card by creating an empty file called ``/flash/SKIPSD``. If this file exists when the pyboard boots up then the SD card will be skipped and the pyboard will always boot from the internal filesystem (in this case the SD card won't be mounted but you can still -mount and use it later in your program using ``os.mount``). +mount and use it later in your program using ``vfs.mount``). (Note that on older versions of the board, ``/flash`` is called ``0:/`` and ``/sd`` is called ``1:/``). diff --git a/docs/reference/filesystem.rst b/docs/reference/filesystem.rst index d8092c58dd7ce..48a465856027d 100644 --- a/docs/reference/filesystem.rst +++ b/docs/reference/filesystem.rst @@ -108,11 +108,11 @@ RAM using a ``bytearray``:: It can be used as follows:: - import os + import vfs bdev = RAMBlockDev(512, 50) - os.VfsFat.mkfs(bdev) - os.mount(bdev, '/ramdisk') + vfs.VfsFat.mkfs(bdev) + vfs.mount(bdev, '/ramdisk') An example of a block device that supports both the simple and extended interface (i.e. both signatures and behaviours of the @@ -150,11 +150,11 @@ interface (i.e. both signatures and behaviours of the As it supports the extended interface, it can be used with :class:`littlefs `:: - import os + import vfs bdev = RAMBlockDev(512, 50) - os.VfsLfs2.mkfs(bdev) - os.mount(bdev, '/ramdisk') + vfs.VfsLfs2.mkfs(bdev) + vfs.mount(bdev, '/ramdisk') Once mounted, the filesystem (regardless of its type) can be used as it normally would be used from Python code, for example:: @@ -197,16 +197,16 @@ recommended to use littlefs instead. To format the entire flash using FAT:: # ESP8266 and ESP32 - import os - os.umount('/') - os.VfsFat.mkfs(bdev) - os.mount(bdev, '/') + import vfs + vfs.umount('/') + vfs.VfsFat.mkfs(bdev) + vfs.mount(bdev, '/') # STM32 - import os, pyb - os.umount('/flash') - os.VfsFat.mkfs(pyb.Flash(start=0)) - os.mount(pyb.Flash(start=0), '/flash') + import os, vfs, pyb + vfs.umount('/flash') + vfs.VfsFat.mkfs(pyb.Flash(start=0)) + vfs.mount(pyb.Flash(start=0), '/flash') os.chdir('/flash') Littlefs @@ -222,16 +222,16 @@ resistant to filesystem corruption. To format the entire flash using littlefs v2:: # ESP8266 and ESP32 - import os - os.umount('/') - os.VfsLfs2.mkfs(bdev) - os.mount(bdev, '/') + import vfs + vfs.umount('/') + vfs.VfsLfs2.mkfs(bdev) + vfs.mount(bdev, '/') # STM32 - import os, pyb - os.umount('/flash') - os.VfsLfs2.mkfs(pyb.Flash(start=0)) - os.mount(pyb.Flash(start=0), '/flash') + import os, vfs, pyb + vfs.umount('/flash') + vfs.VfsLfs2.mkfs(pyb.Flash(start=0)) + vfs.mount(pyb.Flash(start=0), '/flash') os.chdir('/flash') A littlefs filesystem can be still be accessed on a PC over USB MSC using the @@ -264,14 +264,14 @@ block devices spanning a subset of the flash device. For example, to configure the first 256kiB as FAT (and available over USB MSC), and the remainder as littlefs:: - import os, pyb - os.umount('/flash') + import os, vfs, pyb + vfs.umount('/flash') p1 = pyb.Flash(start=0, len=256*1024) p2 = pyb.Flash(start=256*1024) - os.VfsFat.mkfs(p1) - os.VfsLfs2.mkfs(p2) - os.mount(p1, '/flash') - os.mount(p2, '/data') + vfs.VfsFat.mkfs(p1) + vfs.VfsLfs2.mkfs(p2) + vfs.mount(p1, '/flash') + vfs.mount(p2, '/data') os.chdir('/flash') This might be useful to make your Python files, configuration and other @@ -282,9 +282,9 @@ failure, etc. The partition at offset ``0`` will be mounted automatically (and the filesystem type automatically detected), but you can add:: - import os, pyb + import vfs, pyb p2 = pyb.Flash(start=256*1024) - os.mount(p2, '/data') + vfs.mount(p2, '/data') to ``boot.py`` to mount the data partition. @@ -297,7 +297,7 @@ define an arbitrary partition layout. At boot, the partition named "vfs" will be mounted at ``/`` by default, but any additional partitions can be mounted in your ``boot.py`` using:: - import esp32, os + import esp32, vfs p = esp32.Partition.find(esp32.Partition.TYPE_DATA, label='foo') - os.mount(p, '/foo') + vfs.mount(p, '/foo') diff --git a/docs/renesas-ra/quickref.rst b/docs/renesas-ra/quickref.rst index 47b49575bd5be..ea9a38db15fcb 100644 --- a/docs/renesas-ra/quickref.rst +++ b/docs/renesas-ra/quickref.rst @@ -387,15 +387,15 @@ SDCard The frozen sdcard driver (drivers/sdcard/sdcard.py) is available by connecting microSD card device to hardware SPI0 pins.:: from machine import Pin, SPI - import os, sdcard + import os, vfs, sdcard spi = SPI(0, baudrate=500000) cs = Pin.cpu.P103 sd = sdcard.SDCard(spi, cs) - os.mount(sd, '/sd') + vfs.mount(sd, '/sd') os.listdir('/') os.chdir('/sd') - os.umount('/sd') + vfs.umount('/sd') OneWire driver -------------- diff --git a/docs/wipy/general.rst b/docs/wipy/general.rst index a1c8df8ef46ae..bb7e592153f27 100644 --- a/docs/wipy/general.rst +++ b/docs/wipy/general.rst @@ -373,7 +373,7 @@ functions are defined in ``os`` module: Mounts a block device (like an ``SD`` object) in the specified mount point. Example:: - os.mount(sd, '/sd') + vfs.mount(sd, '/sd') .. function:: unmount(path) diff --git a/docs/wipy/quickref.rst b/docs/wipy/quickref.rst index 4c3b969bd1cda..d6abb8d1c7552 100644 --- a/docs/wipy/quickref.rst +++ b/docs/wipy/quickref.rst @@ -171,13 +171,13 @@ SD card See :ref:`machine.SD `. :: from machine import SD - import os + import vfs # clock pin, cmd pin, data0 pin sd = SD(pins=('GP10', 'GP11', 'GP15')) # or use default ones for the expansion board sd = SD() - os.mount(sd, '/sd') + vfs.mount(sd, '/sd') WLAN (WiFi) ----------- diff --git a/docs/zephyr/quickref.rst b/docs/zephyr/quickref.rst index 57262ffb5c632..d8b1f8768d028 100644 --- a/docs/zephyr/quickref.rst +++ b/docs/zephyr/quickref.rst @@ -109,12 +109,12 @@ Disk Access Use the :ref:`zephyr.DiskAccess ` class to support filesystem:: - import os + import vfs from zephyr import DiskAccess block_dev = DiskAccess('SDHC') # create a block device object for an SD card - os.VfsFat.mkfs(block_dev) # create FAT filesystem object using the disk storage block - os.mount(block_dev, '/sd') # mount the filesystem at the SD card subdirectory + vfs.VfsFat.mkfs(block_dev) # create FAT filesystem object using the disk storage block + vfs.mount(block_dev, '/sd') # mount the filesystem at the SD card subdirectory # with the filesystem mounted, files can be manipulated as normal with open('/sd/hello.txt','w') as f: # open a new file in the directory @@ -126,12 +126,12 @@ Flash Area Use the :ref:`zephyr.FlashArea ` class to support filesystem:: - import os + import vfs from zephyr import FlashArea block_dev = FlashArea(4, 4096) # creates a block device object in the frdm-k64f flash scratch partition - os.VfsLfs2.mkfs(block_dev) # create filesystem in lfs2 format using the flash block device - os.mount(block_dev, '/flash') # mount the filesystem at the flash subdirectory + vfs.VfsLfs2.mkfs(block_dev) # create filesystem in lfs2 format using the flash block device + vfs.mount(block_dev, '/flash') # mount the filesystem at the flash subdirectory # with the filesystem mounted, files can be manipulated as normal with open('/flash/hello.txt','w') as f: # open a new file in the directory diff --git a/docs/zephyr/tutorial/storage.rst b/docs/zephyr/tutorial/storage.rst index e8dcbbd39a4aa..7fd449226fbff 100644 --- a/docs/zephyr/tutorial/storage.rst +++ b/docs/zephyr/tutorial/storage.rst @@ -21,11 +21,11 @@ file system to access SD cards via disk access (see below). Example usage of FatFS with an SD card on the mimxrt1050_evk board:: - import os + import vfs from zephyr import DiskAccess bdev = zephyr.DiskAccess('SDHC') # create block device object using DiskAccess - os.VfsFat.mkfs(bdev) # create FAT filesystem object using the disk storage block - os.mount(bdev, '/sd') # mount the filesystem at the SD card subdirectory + vfs.VfsFat.mkfs(bdev) # create FAT filesystem object using the disk storage block + vfs.mount(bdev, '/sd') # mount the filesystem at the SD card subdirectory with open('/sd/hello.txt','w') as f: # open a new file in the directory f.write('Hello world') # write to the file print(open('/sd/hello.txt').read()) # print contents of the file @@ -43,11 +43,11 @@ implements the `vfs.AbstractBlockDev` protocol. Example usage with the internal flash on the reel_board or the rv32m1_vega_ri5cy board:: - import os + import vfs from zephyr import FlashArea bdev = FlashArea(FlashArea.STORAGE, 4096) # create block device object using FlashArea - os.VfsLfs2.mkfs(bdev) # create Little filesystem object using the flash area block - os.mount(bdev, '/flash') # mount the filesystem at the flash storage subdirectory + vfs.VfsLfs2.mkfs(bdev) # create Little filesystem object using the flash area block + vfs.mount(bdev, '/flash') # mount the filesystem at the flash storage subdirectory with open('/flash/hello.txt','w') as f: # open a new file in the directory f.write('Hello world') # write to the file print(open('/flash/hello.txt').read()) # print contents of the file From 1c7afa923b416f51d1c43417e32fd958da2f0c67 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 7 Feb 2024 13:34:54 +1100 Subject: [PATCH 104/408] drivers/dht: Only build DHT driver if MICROPY_PY_MACHINE_PULSE enabled. Because this driver calls `machine_time_pulse_us()`. Signed-off-by: Damien George --- drivers/dht/dht.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/dht/dht.c b/drivers/dht/dht.c index 73afdee581758..7e9b897825791 100644 --- a/drivers/dht/dht.c +++ b/drivers/dht/dht.c @@ -29,6 +29,9 @@ #include "py/runtime.h" #include "py/mperrno.h" #include "py/mphal.h" + +#if MICROPY_PY_MACHINE_PULSE + #include "extmod/modmachine.h" #include "drivers/dht/dht.h" @@ -92,3 +95,5 @@ STATIC mp_obj_t dht_readinto(mp_obj_t pin_in, mp_obj_t buf_in) { mp_raise_OSError(MP_ETIMEDOUT); } MP_DEFINE_CONST_FUN_OBJ_2(dht_readinto_obj, dht_readinto); + +#endif // MICROPY_PY_MACHINE_PULSE From 2158da213e49f40e74780ca9d5a07ce146d39281 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 26 Jan 2024 20:06:54 +1100 Subject: [PATCH 105/408] stm32/modos: Allow disabling MICROPY_PY_MACHINE_UART. Signed-off-by: Damien George --- ports/stm32/modos.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ports/stm32/modos.c b/ports/stm32/modos.c index bd0101cab9c73..6f3577f44a2ed 100644 --- a/ports/stm32/modos.c +++ b/ports/stm32/modos.c @@ -48,7 +48,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); bool mp_os_dupterm_is_builtin_stream(mp_const_obj_t stream) { const mp_obj_type_t *type = mp_obj_get_type(stream); - return type == &machine_uart_type + return false + #if MICROPY_PY_MACHINE_UART + || type == &machine_uart_type + #endif #if MICROPY_HW_ENABLE_USB || type == &pyb_usb_vcp_type #endif @@ -56,18 +59,22 @@ bool mp_os_dupterm_is_builtin_stream(mp_const_obj_t stream) { } void mp_os_dupterm_stream_detached_attached(mp_obj_t stream_detached, mp_obj_t stream_attached) { + #if MICROPY_PY_MACHINE_UART if (mp_obj_get_type(stream_detached) == &machine_uart_type) { uart_attach_to_repl(MP_OBJ_TO_PTR(stream_detached), false); } + #endif #if MICROPY_HW_ENABLE_USB if (mp_obj_get_type(stream_detached) == &pyb_usb_vcp_type) { usb_vcp_attach_to_repl(MP_OBJ_TO_PTR(stream_detached), false); } #endif + #if MICROPY_PY_MACHINE_UART if (mp_obj_get_type(stream_attached) == &machine_uart_type) { uart_attach_to_repl(MP_OBJ_TO_PTR(stream_attached), true); } + #endif #if MICROPY_HW_ENABLE_USB if (mp_obj_get_type(stream_attached) == &pyb_usb_vcp_type) { usb_vcp_attach_to_repl(MP_OBJ_TO_PTR(stream_attached), true); From 4e6436d4cffc7198f6d79431bb76eaf71d3e2ec1 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 7 Feb 2024 13:13:03 +1100 Subject: [PATCH 106/408] stm32/spi: Allow disabling MICROPY_PY_MACHINE_SPI. This requires that MICROPY_PY_PYB is also disabled. Signed-off-by: Damien George --- ports/stm32/machine_spi.c | 4 ++++ ports/stm32/pyb_spi.c | 4 ++++ ports/stm32/spi.c | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/ports/stm32/machine_spi.c b/ports/stm32/machine_spi.c index b916252da35ef..0a5a67ef2ed9b 100644 --- a/ports/stm32/machine_spi.c +++ b/ports/stm32/machine_spi.c @@ -28,6 +28,8 @@ #include "extmod/modmachine.h" #include "spi.h" +#if MICROPY_PY_MACHINE_SPI + /******************************************************************************/ // Implementation of hard SPI for machine module @@ -150,3 +152,5 @@ MP_DEFINE_CONST_OBJ_TYPE( protocol, &machine_hard_spi_p, locals_dict, &mp_machine_spi_locals_dict ); + +#endif // MICROPY_PY_MACHINE_SPI diff --git a/ports/stm32/pyb_spi.c b/ports/stm32/pyb_spi.c index f36c048747f9d..f92642dddcd88 100644 --- a/ports/stm32/pyb_spi.c +++ b/ports/stm32/pyb_spi.c @@ -29,6 +29,8 @@ #include "bufhelper.h" #include "spi.h" +#if MICROPY_PY_PYB + /******************************************************************************/ // MicroPython bindings for legacy pyb API @@ -362,3 +364,5 @@ MP_DEFINE_CONST_OBJ_TYPE( protocol, &pyb_spi_p, locals_dict, &pyb_spi_locals_dict ); + +#endif // MICROPY_PY_PYB diff --git a/ports/stm32/spi.c b/ports/stm32/spi.c index ee2301c803b8a..df71efd3fe11a 100644 --- a/ports/stm32/spi.c +++ b/ports/stm32/spi.c @@ -735,6 +735,8 @@ void spi_print(const mp_print_t *print, const spi_t *spi_obj, bool legacy) { mp_print_str(print, ")"); } +#if MICROPY_PY_MACHINE_SPI + const spi_t *spi_from_mp_obj(mp_obj_t o) { if (mp_obj_is_type(o, &pyb_spi_type)) { pyb_spi_obj_t *self = MP_OBJ_TO_PTR(o); @@ -761,6 +763,8 @@ mp_obj_base_t *mp_hal_get_spi_obj(mp_obj_t o) { } } +#endif + /******************************************************************************/ // Implementation of low-level SPI C protocol From 657faee7e5c44552ba39dea00d4c0d12ef09ca30 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 7 Feb 2024 13:34:12 +1100 Subject: [PATCH 107/408] stm32/main: Allow disabling MICROPY_PY_MACHINE. Disabling this requires also disabling: MICROPY_PY_PYB and MICROPY_PY_STM. Signed-off-by: Damien George --- ports/stm32/main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ports/stm32/main.c b/ports/stm32/main.c index 06ba74f759677..3279770ea03ce 100644 --- a/ports/stm32/main.c +++ b/ports/stm32/main.c @@ -424,7 +424,9 @@ void stm32_main(uint32_t reset_mode) { #if MICROPY_HW_HAS_SWITCH switch_init0(); #endif + #if MICROPY_PY_MACHINE machine_init(); + #endif #if MICROPY_HW_ENABLE_RTC rtc_init_start(false); #endif @@ -670,7 +672,9 @@ void stm32_main(uint32_t reset_mode) { #if MICROPY_HW_ENABLE_DAC dac_deinit_all(); #endif + #if MICROPY_PY_MACHINE machine_deinit(); + #endif #if MICROPY_PY_THREAD pyb_thread_deinit(); From b038d070116ccfb1ec785cd6207006783841bccc Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 7 Feb 2024 14:55:07 +1100 Subject: [PATCH 108/408] stm32/Makefile: Ignore uninitialised variable warning in H5 HAL SD code. This warning appears when using an MCU like H562 that only has one SDMMC. Signed-off-by: Damien George --- ports/stm32/Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile index e44a542395182..2947e4119beac 100644 --- a/ports/stm32/Makefile +++ b/ports/stm32/Makefile @@ -338,6 +338,10 @@ HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\ ll_sdmmc.c \ ll_fmc.c \ ) +ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),h5)) +# HAL H5-1.0.0 has a bug with uninitialised variable in HAL_SD_ConfigWideBusOperation. +$(BUILD)/$(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_hal_sd.o: CFLAGS += -Wno-error=maybe-uninitialized +endif endif ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f4 f7 h7)) From 84e90639fa47a6830b53138d546dd8694549be36 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 31 Jan 2024 10:55:17 +1100 Subject: [PATCH 109/408] github/workflows: Move codespell to a GitHub workflow, version it. Similar to ruff.yaml, it's simpler to run the codespell command directly from a workflow file. And developers can run codespell directly from the command line without the need for options, or just use pre-commit. This commit also applies a specific version to codespell, same as pre-commit (introduced in a166d805f43). This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- .github/workflows/code_formatting.yml | 10 ---------- .github/workflows/codespell.yml | 12 ++++++++++++ tools/ci.sh | 11 ----------- 3 files changed, 12 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/codespell.yml diff --git a/.github/workflows/code_formatting.yml b/.github/workflows/code_formatting.yml index 5cd7984f7ac15..9f30f048cfdbe 100644 --- a/.github/workflows/code_formatting.yml +++ b/.github/workflows/code_formatting.yml @@ -18,13 +18,3 @@ jobs: run: source tools/ci.sh && ci_c_code_formatting_run - name: Check code formatting run: git diff --exit-code - - code-spelling: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - - name: Install packages - run: source tools/ci.sh && ci_code_spell_setup - - name: Run spell checker - run: source tools/ci.sh && ci_code_spell_run diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml new file mode 100644 index 0000000000000..47b12051e726f --- /dev/null +++ b/.github/workflows/codespell.yml @@ -0,0 +1,12 @@ +name: Check spelling with codespell + +on: [push, pull_request] + +jobs: + codespell: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: pip install --user codespell==2.2.6 tomli + - run: codespell + diff --git a/tools/ci.sh b/tools/ci.sh index e18027ae5addb..3cbc51cfad625 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -30,17 +30,6 @@ function ci_c_code_formatting_run { tools/codeformat.py -v -c } -######################################################################################## -# code spelling - -function ci_code_spell_setup { - pip3 install codespell tomli -} - -function ci_code_spell_run { - codespell -} - ######################################################################################## # commit formatting From 6f0aa275f85dbdc3e36f6bfd94d678f70203939d Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 31 Jan 2024 11:09:52 +1100 Subject: [PATCH 110/408] github/workflows: Add comments where tool versions need to be in sync. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- .github/workflows/codespell.yml | 1 + .github/workflows/ruff.yml | 1 + .pre-commit-config.yaml | 2 ++ 3 files changed, 4 insertions(+) diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml index 47b12051e726f..2d8b4627aac2d 100644 --- a/.github/workflows/codespell.yml +++ b/.github/workflows/codespell.yml @@ -7,6 +7,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + # codespell version should be kept in sync with .pre-commit-config.yml - run: pip install --user codespell==2.2.6 tomli - run: codespell diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml index 1159a1882d60e..77a8bd1e9fb9b 100644 --- a/.github/workflows/ruff.yml +++ b/.github/workflows/ruff.yml @@ -6,6 +6,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + # ruff version should be kept in sync with .pre-commit-config.yaml - run: pip install --user ruff==0.1.3 - run: ruff check --output-format=github . - run: ruff format --diff . diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0576a158b4f1a..a1c811339adcc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,11 +12,13 @@ repos: verbose: true stages: [commit-msg] - repo: https://github.com/charliermarsh/ruff-pre-commit + # Version should be kept in sync with .github/workflows/ruff.yml rev: v0.1.3 hooks: - id: ruff - id: ruff-format - repo: https://github.com/codespell-project/codespell + # Version should be kept in sync with .github/workflows/codespell.yml rev: v2.2.6 hooks: - id: codespell From 781366e476af599a5b9038970bc19137ab40e766 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 31 Jan 2024 15:07:15 +1100 Subject: [PATCH 111/408] github/workflows: Standardise formatting of ruff.yml. All the other workflow YAML files use vertical whitespace around top-level items. Also remove spurious comment, the features in the linked doc aren't actually used in this workflow (any more?). This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- .github/workflows/ruff.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml index 77a8bd1e9fb9b..29e9ddbf8b61a 100644 --- a/.github/workflows/ruff.yml +++ b/.github/workflows/ruff.yml @@ -1,6 +1,7 @@ -# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python name: Python code lint and formatting with ruff + on: [push, pull_request] + jobs: ruff: runs-on: ubuntu-latest From 2bdaa1bedede63ee2380aa5de67802cb5d2cfcd1 Mon Sep 17 00:00:00 2001 From: Jos Verlinde Date: Thu, 11 Jan 2024 22:43:41 +0100 Subject: [PATCH 112/408] docs/library/sys.rst: Document implementation.version.releaselevel. Signed-off-by: Jos Verlinde --- docs/library/sys.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/library/sys.rst b/docs/library/sys.rst index c8eb4b5c502b9..7b34a0e31c6bf 100644 --- a/docs/library/sys.rst +++ b/docs/library/sys.rst @@ -69,7 +69,7 @@ Constants MicroPython, it has following attributes: * *name* - string "micropython" - * *version* - tuple (major, minor, micro), e.g. (1, 7, 0) + * *version* - tuple (major, minor, micro, releaselevel), e.g. (1, 22, 0, '') * *_machine* - string describing the underlying machine * *_mpy* - supported mpy file-format version (optional attribute) @@ -77,6 +77,9 @@ Constants Python implementations (note that it still may not exist in the very minimal ports). + Starting with version 1.22.0-preview, the fourth node *releaselevel* in + *implementation.version* is either an empty string or ``"preview"``. + .. admonition:: Difference to CPython :class: attention From 35dd959133fb233d75e9b3cddbf98b2ed01c6594 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 8 Feb 2024 17:03:43 +1100 Subject: [PATCH 113/408] tools/manifestfile.py: Change library search to use a list of paths. This commit changes how library packages are searched for when a manifest file is loaded: there is now simply a list of library paths that is searched in order for the given package. This list defaults to the main directories in micropython-lib, but can be added to -- either appended or prepended -- by using `add_library()`. In particular the way unix-ffi library packages are searched has changed, because the `unix_ffi` argument to `require()` is now removed. Instead, if a build wants to include packages from micropython-lib/unix-ffi, then it must explicitly add this to the list of paths to search using: add_library("unix-ffi", "$(MPY_LIB_DIR)/unix-ffi") Work done in collaboration with Jim Mussared. Signed-off-by: Damien George --- docs/reference/manifest.rst | 17 ++++++++-- tools/manifestfile.py | 65 +++++++++++++++++++------------------ 2 files changed, 49 insertions(+), 33 deletions(-) diff --git a/docs/reference/manifest.rst b/docs/reference/manifest.rst index 9bcafd5839cab..1a80b1259e39f 100644 --- a/docs/reference/manifest.rst +++ b/docs/reference/manifest.rst @@ -95,6 +95,17 @@ Note: The ``opt`` keyword argument can be set on the various functions, this con the optimisation level used by the cross-compiler. See :func:`micropython.opt_level`. +.. function:: add_library(library, library_path, prepend=False) + + Register the path to an external named *library*. + + The path *library_path* will be automatically searched when using `require`. + By default the added library is added to the end of the list of libraries to + search. Pass ``True`` to *prepend* to add it to the start of the list. + + Additionally, the added library can be explicitly requested by using + ``require("name", library="library")``. + .. function:: package(package_path, files=None, base_path=".", opt=None) This is equivalent to copying the "package_path" directory to the device @@ -138,11 +149,13 @@ See :func:`micropython.opt_level`. You can use the variables above, such as ``$(PORT_DIR)`` in ``base_path``. -.. function:: require(name, unix_ffi=False) +.. function:: require(name, library=None) Require a package by name (and its dependencies) from :term:`micropython-lib`. - Optionally specify unix_ffi=True to use a module from the unix-ffi directory. + Optionally specify *library* (a string) to reference a package from a + library that has been previously registered with `add_library`. Otherwise + the list of library paths will be used. .. function:: include(manifest_path) diff --git a/tools/manifestfile.py b/tools/manifestfile.py index aa85c4650f2a6..47403d4e3bc18 100644 --- a/tools/manifestfile.py +++ b/tools/manifestfile.py @@ -62,6 +62,9 @@ # URL to file. (TODO) FILE_TYPE_HTTP = 2 +# Default list of libraries in micropython-lib to search for library packages. +BASE_LIBRARY_NAMES = ("micropython", "python-stdlib", "python-ecosys") + class ManifestFileError(Exception): pass @@ -196,6 +199,12 @@ def __init__(self, mode, path_vars=None): self._metadata = [ManifestPackageMetadata()] # Registered external libraries. self._libraries = {} + # List of directories to search for packages. + self._library_dirs = [] + # Add default micropython-lib libraries if $(MPY_LIB_DIR) has been specified. + if self._path_vars["MPY_LIB_DIR"]: + for lib in BASE_LIBRARY_NAMES: + self.add_library(lib, os.path.join("$(MPY_LIB_DIR)", lib)) def _resolve_path(self, path): # Convert path to an absolute path, applying variable substitutions. @@ -398,18 +407,16 @@ def _require_from_path(self, library_path, name, version, extra_kwargs): return True return False - def require(self, name, version=None, unix_ffi=False, pypi=None, library=None, **kwargs): + def require(self, name, version=None, pypi=None, library=None, **kwargs): """ Require a package by name from micropython-lib. - Optionally specify unix_ffi=True to use a module from the unix-ffi directory. - Optionally specify pipy="package-name" to indicate that this should use the named package from PyPI when building for CPython. Optionally specify library="name" to reference a package from a library that has been previously registered with add_library(). Otherwise - micropython-lib will be used. + the list of library paths will be used. """ self._metadata[-1].check_initialised(self._mode) @@ -426,39 +433,35 @@ def require(self, name, version=None, unix_ffi=False, pypi=None, library=None, * raise ValueError("Unknown library '{}' for require('{}').".format(library, name)) library_path = self._libraries[library] # Search for {library_path}/**/{name}/manifest.py. - if not self._require_from_path(library_path, name, version, kwargs): - raise ValueError( - "Package '{}' not found in external library '{}' ({}).".format( - name, library, library_path - ) + if self._require_from_path(library_path, name, version, kwargs): + return + raise ValueError( + "Package '{}' not found in external library '{}' ({}).".format( + name, library, library_path ) - elif self._path_vars["MPY_LIB_DIR"]: - # Find package in micropython-lib, in one of the three top-level directories. - lib_dirs = ["micropython", "python-stdlib", "python-ecosys"] - if unix_ffi: - # Additionally search unix-ffi only if unix_ffi=True, and make unix-ffi modules - # take precedence. - lib_dirs = ["unix-ffi"] + lib_dirs - - for lib_dir in lib_dirs: - # Search for {lib_dir}/**/{name}/manifest.py. - if self._require_from_path( - os.path.join(self._path_vars["MPY_LIB_DIR"], lib_dir), name, version, kwargs - ): - return - - raise ValueError("Package '{}' not found in local micropython-lib.".format(name)) - else: - # TODO: HTTP request to obtain URLs from manifest.json. - raise ValueError("micropython-lib not available for require('{}').", name) + ) - def add_library(self, library, library_path): + for lib_dir in self._library_dirs: + # Search for {lib_dir}/**/{name}/manifest.py. + if self._require_from_path(lib_dir, name, version, kwargs): + return + + raise ValueError("Package '{}' not found in any known library.".format(name)) + + def add_library(self, library, library_path, prepend=False): """ Register the path to an external named library. - This allows require("name", library="library") to find packages in that library. + The path will be automatically searched when using require(). By default the + added library is added to the end of the list of libraries to search. Pass + `prepend=True` to add it to the start of the list. + + Additionally, the added library can be explicitly requested by using + `require("name", library="library")`. """ - self._libraries[library] = self._resolve_path(library_path) + library_path = self._resolve_path(library_path) + self._libraries[library] = library_path + self._library_dirs.insert(0 if prepend else len(self._library_dirs), library_path) def package(self, package_path, files=None, base_path=".", opt=None): """ From 8cbae12d0d84ebce76b305d2f5535f327d5d44be Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 8 Feb 2024 17:08:32 +1100 Subject: [PATCH 114/408] unix/variants: Prefer unix-ffi packages when loading the manifest. Signed-off-by: Damien George --- ports/unix/variants/coverage/manifest.py | 1 + ports/unix/variants/manifest.py | 1 + 2 files changed, 2 insertions(+) diff --git a/ports/unix/variants/coverage/manifest.py b/ports/unix/variants/coverage/manifest.py index 556d445d752ea..37f2531a842f8 100644 --- a/ports/unix/variants/coverage/manifest.py +++ b/ports/unix/variants/coverage/manifest.py @@ -1,3 +1,4 @@ +add_library("unix-ffi", "$(MPY_LIB_DIR)/unix-ffi") freeze_as_str("frzstr") freeze_as_mpy("frzmpy") freeze_mpy("$(MPY_DIR)/tests/frozen") diff --git a/ports/unix/variants/manifest.py b/ports/unix/variants/manifest.py index 88cc1ad8e50ef..649b1e4c464fb 100644 --- a/ports/unix/variants/manifest.py +++ b/ports/unix/variants/manifest.py @@ -1,2 +1,3 @@ +add_library("unix-ffi", "$(MPY_LIB_DIR)/unix-ffi") require("mip-cmdline") require("ssl") From b4f59984f7668db457280c1f4007618fd1d235f6 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 8 Feb 2024 16:52:01 +1100 Subject: [PATCH 115/408] extmod/btstack: Reset pending_value_handle before calling write-done cb. The pending_value_handle needs to be freed and reset before calling mp_bluetooth_gattc_on_read_write_status(), which will call the Python IRQ handler, which may in turn call back into BTstack to perform an action like a write. In that case the pending_value_handle will need to be available for the write/read/etc to proceed. Fixes issue #13611. Signed-off-by: Damien George --- extmod/btstack/modbluetooth_btstack.c | 3 +- tests/multi_bluetooth/ble_irq_calls.py | 200 +++++++++++++++++++++ tests/multi_bluetooth/ble_irq_calls.py.exp | 31 ++++ 3 files changed, 233 insertions(+), 1 deletion(-) create mode 100644 tests/multi_bluetooth/ble_irq_calls.py create mode 100644 tests/multi_bluetooth/ble_irq_calls.py.exp diff --git a/extmod/btstack/modbluetooth_btstack.c b/extmod/btstack/modbluetooth_btstack.c index 211214768f7eb..08d64ab0123ce 100644 --- a/extmod/btstack/modbluetooth_btstack.c +++ b/extmod/btstack/modbluetooth_btstack.c @@ -490,11 +490,12 @@ STATIC void btstack_packet_handler_write_with_response(uint8_t packet_type, uint if (!conn) { return; } - mp_bluetooth_gattc_on_read_write_status(MP_BLUETOOTH_IRQ_GATTC_WRITE_DONE, conn_handle, conn->pending_value_handle, status); + uint16_t value_handle = conn->pending_value_handle; conn->pending_value_handle = 0xffff; m_del(uint8_t, conn->pending_write_value, conn->pending_write_value_len); conn->pending_write_value = NULL; conn->pending_write_value_len = 0; + mp_bluetooth_gattc_on_read_write_status(MP_BLUETOOTH_IRQ_GATTC_WRITE_DONE, conn_handle, value_handle, status); } } #endif // MICROPY_PY_BLUETOOTH_ENABLE_GATT_CLIENT diff --git a/tests/multi_bluetooth/ble_irq_calls.py b/tests/multi_bluetooth/ble_irq_calls.py new file mode 100644 index 0000000000000..131ea909295db --- /dev/null +++ b/tests/multi_bluetooth/ble_irq_calls.py @@ -0,0 +1,200 @@ +# Test calling BLE methods from within the BLE.irq event handler. + +from micropython import const +import struct +import time +import bluetooth + +_IRQ_CENTRAL_CONNECT = const(1) +_IRQ_CENTRAL_DISCONNECT = const(2) +_IRQ_PERIPHERAL_CONNECT = const(7) +_IRQ_PERIPHERAL_DISCONNECT = const(8) +_IRQ_GATTC_SERVICE_RESULT = const(9) +_IRQ_GATTC_SERVICE_DONE = const(10) +_IRQ_GATTC_CHARACTERISTIC_RESULT = const(11) +_IRQ_GATTC_CHARACTERISTIC_DONE = const(12) +_IRQ_GATTC_DESCRIPTOR_RESULT = const(13) +_IRQ_GATTC_DESCRIPTOR_DONE = const(14) +_IRQ_GATTC_READ_RESULT = const(15) +_IRQ_GATTC_READ_DONE = const(16) +_IRQ_GATTC_WRITE_DONE = const(17) +_IRQ_MTU_EXCHANGED = const(21) +_IRQ_GET_SECRET = const(29) +_IRQ_SET_SECRET = const(30) + +EVENT_NAMES = { + 1: "_IRQ_CENTRAL_CONNECT", + 2: "_IRQ_CENTRAL_DISCONNECT", + 3: "_IRQ_GATTS_WRITE", + 4: "_IRQ_GATTS_READ_REQUEST", + 7: "_IRQ_PERIPHERAL_CONNECT", + 8: "_IRQ_PERIPHERAL_DISCONNECT", + 9: "_IRQ_GATTC_SERVICE_RESULT", + 10: "_IRQ_GATTC_SERVICE_DONE", + 11: "_IRQ_GATTC_CHARACTERISTIC_RESULT", + 12: "_IRQ_GATTC_CHARACTERISTIC_DONE", + 13: "_IRQ_GATTC_DESCRIPTOR_RESULT", + 14: "_IRQ_GATTC_DESCRIPTOR_DONE", + 15: "_IRQ_GATTC_READ_RESULT", + 16: "_IRQ_GATTC_READ_DONE", + 17: "_IRQ_GATTC_WRITE_DONE", + 18: "_IRQ_GATTC_NOTIFY", + 21: "_IRQ_MTU_EXCHANGED", +} + +_ADV_TYPE_FLAGS = const(0x01) +_ADV_TYPE_NAME = const(0x09) +_ADV_TYPE_UUID128_COMPLETE = const(0x7) + +_NOTIFY_ENABLE = const(1) + +ACCESSORY_UUID = bluetooth.UUID("a5a5a5a5-ffff-9999-1111-5a5a5a5a5a5a") +STATE_UUID = bluetooth.UUID("a5a5a5a5-eeee-9999-1111-5a5a5a5a5a5a") +CCC_UUID = bluetooth.UUID(0x2902) + +STATE_CHARACTERISTIC = ( + STATE_UUID, + bluetooth.FLAG_READ | bluetooth.FLAG_NOTIFY, +) + +ACCESSORY_SERVICE = (ACCESSORY_UUID, (STATE_CHARACTERISTIC,)) + + +class Central: + def __init__(self): + self.done = False + self._conn_handle = None + self._service = None + self._characteristic = None + self._cccd_handle = None + ble.active(1) + ble.irq(self._ble_event_handler) + ble.gap_connect(*BDADDR) + + def _ble_event_handler(self, event, data): + print(EVENT_NAMES[event]) + + if event == _IRQ_PERIPHERAL_CONNECT: + conn_handle, _, _ = data + self._conn_handle = conn_handle + ble.gattc_discover_services(self._conn_handle, ACCESSORY_UUID) + + elif event == _IRQ_PERIPHERAL_DISCONNECT: + conn_handle, _, addr = data + assert self._conn_handle == conn_handle + self._conn_handle = None + print("connection closed") + + elif event == _IRQ_GATTC_SERVICE_RESULT: + _, first_handle, last_handle, uuid = data + print("service found:", last_handle - first_handle, uuid) + if uuid == ACCESSORY_UUID: + assert self._service is None + self._service = (first_handle, last_handle) + + elif event == _IRQ_GATTC_SERVICE_DONE: + print("service handle range:", self._service[1] - self._service[0]) + start_handle, end_handle = self._service + ble.gattc_discover_characteristics(self._conn_handle, start_handle, end_handle) + + elif event == _IRQ_GATTC_CHARACTERISTIC_RESULT: + _, end_handle, value_handle, properties, uuid = data + assert uuid == STATE_UUID + print("characteristic found:", uuid) + self._characteristic = (end_handle, value_handle, properties) + + elif event == _IRQ_GATTC_CHARACTERISTIC_DONE: + start_handle, end_handle = self._service + ble.gattc_discover_descriptors(self._conn_handle, start_handle, end_handle) + + elif event == _IRQ_GATTC_DESCRIPTOR_RESULT: + _, dsc_handle, uuid = data + if uuid == CCC_UUID: + print("CCCD found:", uuid) + assert self._cccd_handle is None + self._cccd_handle = dsc_handle + + elif event == _IRQ_GATTC_DESCRIPTOR_DONE: + # Discovery complete, proceed to MTU exchange. + ble.gattc_exchange_mtu(self._conn_handle) + + elif event == _IRQ_MTU_EXCHANGED: + # MTU exchanged, proceed to enable CCCD. + print("CCCD write") + ble.gattc_write( + self._conn_handle, self._cccd_handle, struct.pack(" Date: Sun, 11 Feb 2024 15:08:08 +1100 Subject: [PATCH 116/408] extmod/btstack: Reset pending_value_handle before calling read-done cb. Similar to the previous commit but for MP_BLUETOOTH_IRQ_GATTC_READ_DONE: the pending_value_handle needs to be reset before calling mp_bluetooth_gattc_on_read_write_status(), which will call the Python IRQ handler, which may in turn call back into BTstack to perform an action like a write. In that case the pending_value_handle will need to be available for the write/read/etc to proceed. Fixes issue #13634. Signed-off-by: Damien George --- extmod/btstack/modbluetooth_btstack.c | 3 ++- tests/multi_bluetooth/ble_irq_calls.py | 18 ++++++++++++------ tests/multi_bluetooth/ble_irq_calls.py.exp | 4 ++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/extmod/btstack/modbluetooth_btstack.c b/extmod/btstack/modbluetooth_btstack.c index 08d64ab0123ce..b3d349c2dc947 100644 --- a/extmod/btstack/modbluetooth_btstack.c +++ b/extmod/btstack/modbluetooth_btstack.c @@ -462,8 +462,9 @@ STATIC void btstack_packet_handler_read(uint8_t packet_type, uint16_t channel, u if (!conn) { return; } - mp_bluetooth_gattc_on_read_write_status(MP_BLUETOOTH_IRQ_GATTC_READ_DONE, conn_handle, conn->pending_value_handle, status); + uint16_t value_handle = conn->pending_value_handle; conn->pending_value_handle = 0xffff; + mp_bluetooth_gattc_on_read_write_status(MP_BLUETOOTH_IRQ_GATTC_READ_DONE, conn_handle, value_handle, status); } else if (event_type == GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT) { DEBUG_printf(" --> gatt characteristic value query result\n"); uint16_t conn_handle = gatt_event_characteristic_value_query_result_get_handle(packet); diff --git a/tests/multi_bluetooth/ble_irq_calls.py b/tests/multi_bluetooth/ble_irq_calls.py index 131ea909295db..c8c673daab31d 100644 --- a/tests/multi_bluetooth/ble_irq_calls.py +++ b/tests/multi_bluetooth/ble_irq_calls.py @@ -65,8 +65,9 @@ def __init__(self): self.done = False self._conn_handle = None self._service = None - self._characteristic = None + self._characteristic_handle = None self._cccd_handle = None + self._reads_remaining = None ble.active(1) ble.irq(self._ble_event_handler) ble.gap_connect(*BDADDR) @@ -101,7 +102,8 @@ def _ble_event_handler(self, event, data): _, end_handle, value_handle, properties, uuid = data assert uuid == STATE_UUID print("characteristic found:", uuid) - self._characteristic = (end_handle, value_handle, properties) + assert self._characteristic_handle is None + self._characteristic_handle = value_handle elif event == _IRQ_GATTC_CHARACTERISTIC_DONE: start_handle, end_handle = self._service @@ -128,17 +130,21 @@ def _ble_event_handler(self, event, data): elif event == _IRQ_GATTC_WRITE_DONE: conn_handle, _, result = data print("CCCD write result:", result) - _, state_handle, _ = self._characteristic print("issue gattc_read") - ble.gattc_read(self._conn_handle, state_handle) + self._reads_remaining = 2 + ble.gattc_read(self._conn_handle, self._characteristic_handle) elif event == _IRQ_GATTC_READ_RESULT: _, _, char_data = data print("gattc_read result:", bytes(char_data)) elif event == _IRQ_GATTC_READ_DONE: - self.done = True - ble.gap_disconnect(self._conn_handle) + self._reads_remaining -= 1 + if self._reads_remaining > 0: + ble.gattc_read(self._conn_handle, self._characteristic_handle) + else: + self.done = True + ble.gap_disconnect(self._conn_handle) class Peripheral: diff --git a/tests/multi_bluetooth/ble_irq_calls.py.exp b/tests/multi_bluetooth/ble_irq_calls.py.exp index 85d2f585adbb4..d655c507d34f1 100644 --- a/tests/multi_bluetooth/ble_irq_calls.py.exp +++ b/tests/multi_bluetooth/ble_irq_calls.py.exp @@ -3,6 +3,7 @@ peripheral start _IRQ_CENTRAL_CONNECT _IRQ_MTU_EXCHANGED _IRQ_GATTS_READ_REQUEST +_IRQ_GATTS_READ_REQUEST _IRQ_CENTRAL_DISCONNECT --- instance1 --- central start @@ -27,5 +28,8 @@ issue gattc_read _IRQ_GATTC_READ_RESULT gattc_read result: b'' _IRQ_GATTC_READ_DONE +_IRQ_GATTC_READ_RESULT +gattc_read result: b'' +_IRQ_GATTC_READ_DONE _IRQ_PERIPHERAL_DISCONNECT connection closed From 0432f73206a0d0ff5cef5dc6146f18439079f6f3 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 12 Feb 2024 11:56:24 +1100 Subject: [PATCH 117/408] tools/mpy-tool.py: Fix static qstrs when freezing without qstr header. It's rare to freeze .mpy files without specifying a qstr header from a firmware build, but it can be useful for testing, eg `mpy-tool.py -f test.mpy`. Fix this case so static qstrs are properly excluded from the frozen qstr list. Signed-off-by: Damien George --- tools/mpy-tool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py index 519462ec80157..a656cccd69d0f 100755 --- a/tools/mpy-tool.py +++ b/tools/mpy-tool.py @@ -1795,7 +1795,7 @@ def main(): else: config.MICROPY_QSTR_BYTES_IN_LEN = 1 config.MICROPY_QSTR_BYTES_IN_HASH = 1 - firmware_qstr_idents = set(qstrutil.static_qstr_list) + firmware_qstr_idents = set(qstrutil.static_qstr_list_ident) # Create initial list of global qstrs. global_qstrs = GlobalQStrList() From be8d660fc24c3390aedd156b796a3a88ae737ae9 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Tue, 13 Feb 2024 08:33:45 +0100 Subject: [PATCH 118/408] mimxrt: Fix header include guard names. Signed-off-by: iabdalkader --- ports/mimxrt/cyw43_configport.h | 6 +++--- ports/mimxrt/pendsv.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ports/mimxrt/cyw43_configport.h b/ports/mimxrt/cyw43_configport.h index f1cfc86cb067b..619db24b1b579 100644 --- a/ports/mimxrt/cyw43_configport.h +++ b/ports/mimxrt/cyw43_configport.h @@ -24,8 +24,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_STM32_CYW43_CONFIGPORT_H -#define MICROPY_INCLUDED_STM32_CYW43_CONFIGPORT_H +#ifndef MICROPY_INCLUDED_MIMXRT_CYW43_CONFIGPORT_H +#define MICROPY_INCLUDED_MIMXRT_CYW43_CONFIGPORT_H // The board-level config will be included here, so it can set some CYW43 values. #include "py/mpconfig.h" @@ -152,4 +152,4 @@ static inline int cyw43_sdio_transfer_cmd53(bool write, uint32_t block_size, uin #define CYW43_EVENT_POLL_HOOK MICROPY_EVENT_POLL_HOOK -#endif // MICROPY_INCLUDED_STM32_CYW43_CONFIGPORT_H +#endif // MICROPY_INCLUDED_MIMXRT_CYW43_CONFIGPORT_H diff --git a/ports/mimxrt/pendsv.h b/ports/mimxrt/pendsv.h index f3369b07fefdc..d68c5aa2d5d58 100644 --- a/ports/mimxrt/pendsv.h +++ b/ports/mimxrt/pendsv.h @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_STM32_PENDSV_H -#define MICROPY_INCLUDED_STM32_PENDSV_H +#ifndef MICROPY_INCLUDED_MIMXRT_PENDSV_H +#define MICROPY_INCLUDED_MIMXRT_PENDSV_H enum { PENDSV_DISPATCH_SOFT_TIMER, // For later & for having at least one entry @@ -45,4 +45,4 @@ typedef void (*pendsv_dispatch_t)(void); void pendsv_init(void); void pendsv_schedule_dispatch(size_t slot, pendsv_dispatch_t f); -#endif // MICROPY_INCLUDED_STM32_PENDSV_H +#endif // MICROPY_INCLUDED_MIMXRT_PENDSV_H From d2a3cd7ac4283045b3692ae8d83afe833fbe65e6 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 9 Feb 2024 14:03:00 +0900 Subject: [PATCH 119/408] embed: Improve stack top estimation. Obtaining the stack-top via a few function calls may yield a pointer which is too deep within the stack. So require the user to obtain it from a higher level (or via some other means). Fixes issue #11781. Signed-off-by: YAMAMOTO Takashi --- examples/embedding/main.c | 9 ++++++++- ports/embed/port/embed_util.c | 4 ++-- ports/embed/port/micropython_embed.h | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/examples/embedding/main.c b/examples/embedding/main.c index ee673fc93a687..7530580369ad4 100644 --- a/examples/embedding/main.c +++ b/examples/embedding/main.c @@ -31,7 +31,14 @@ static char heap[8 * 1024]; int main() { // Initialise MicroPython. - mp_embed_init(&heap[0], sizeof(heap)); + // + // Note: &stack_top below should be good enough for many cases. + // However, depending on environment, there might be more appropriate + // ways to get the stack top value. + // eg. pthread_get_stackaddr_np, pthread_getattr_np, + // __builtin_frame_address/__builtin_stack_address, etc. + int stack_top; + mp_embed_init(&heap[0], sizeof(heap), &stack_top); // Run the example scripts (they will be compiled first). mp_embed_exec_str(example_1); diff --git a/ports/embed/port/embed_util.c b/ports/embed/port/embed_util.c index 14f50897705e8..c5bc8c973bb02 100644 --- a/ports/embed/port/embed_util.c +++ b/ports/embed/port/embed_util.c @@ -34,8 +34,8 @@ #include "port/micropython_embed.h" // Initialise the runtime. -void mp_embed_init(void *gc_heap, size_t gc_heap_size) { - mp_stack_ctrl_init(); +void mp_embed_init(void *gc_heap, size_t gc_heap_size, void *stack_top) { + mp_stack_set_top(stack_top); gc_init(gc_heap, (uint8_t *)gc_heap + gc_heap_size); mp_init(); } diff --git a/ports/embed/port/micropython_embed.h b/ports/embed/port/micropython_embed.h index bf55d9b2b4454..09341c93e4e98 100644 --- a/ports/embed/port/micropython_embed.h +++ b/ports/embed/port/micropython_embed.h @@ -29,7 +29,7 @@ #include #include -void mp_embed_init(void *gc_heap, size_t gc_heap_size); +void mp_embed_init(void *gc_heap, size_t gc_heap_size, void *stack_top); void mp_embed_deinit(void); // Only available if MICROPY_ENABLE_COMPILER is enabled. From 587b6f2e346eb0ab4c330f27fb144d9025ac9426 Mon Sep 17 00:00:00 2001 From: Yoctopuce Date: Tue, 30 Jan 2024 09:37:10 +0100 Subject: [PATCH 120/408] extmod/modrandom: Add integer type casts where appropriate. To prevent compiler warnings when `mp_int_t` is 64-bits. Signed-off-by: Yoctopuce --- extmod/modrandom.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/extmod/modrandom.c b/extmod/modrandom.c index e65f31488bfeb..d66f1c9c46dce 100644 --- a/extmod/modrandom.c +++ b/extmod/modrandom.c @@ -86,7 +86,7 @@ STATIC uint32_t yasmarang_randbelow(uint32_t n) { #endif STATIC mp_obj_t mod_random_getrandbits(mp_obj_t num_in) { - int n = mp_obj_get_int(num_in); + mp_int_t n = mp_obj_get_int(num_in); if (n > 32 || n < 0) { mp_raise_ValueError(MP_ERROR_TEXT("bits must be 32 or less")); } @@ -111,7 +111,7 @@ STATIC mp_obj_t mod_random_seed(size_t n_args, const mp_obj_t *args) { } else { seed = mp_obj_get_int_truncated(args[0]); } - yasmarang_pad = seed; + yasmarang_pad = (uint32_t)seed; yasmarang_n = 69; yasmarang_d = 233; yasmarang_dat = 0; @@ -126,7 +126,7 @@ STATIC mp_obj_t mod_random_randrange(size_t n_args, const mp_obj_t *args) { if (n_args == 1) { // range(stop) if (start > 0) { - return mp_obj_new_int(yasmarang_randbelow(start)); + return mp_obj_new_int(yasmarang_randbelow((uint32_t)start)); } else { goto error; } @@ -135,7 +135,7 @@ STATIC mp_obj_t mod_random_randrange(size_t n_args, const mp_obj_t *args) { if (n_args == 2) { // range(start, stop) if (start < stop) { - return mp_obj_new_int(start + yasmarang_randbelow(stop - start)); + return mp_obj_new_int(start + yasmarang_randbelow((uint32_t)(stop - start))); } else { goto error; } @@ -151,7 +151,7 @@ STATIC mp_obj_t mod_random_randrange(size_t n_args, const mp_obj_t *args) { goto error; } if (n > 0) { - return mp_obj_new_int(start + step * yasmarang_randbelow(n)); + return mp_obj_new_int(start + step * yasmarang_randbelow((uint32_t)n)); } else { goto error; } @@ -167,7 +167,7 @@ STATIC mp_obj_t mod_random_randint(mp_obj_t a_in, mp_obj_t b_in) { mp_int_t a = mp_obj_get_int(a_in); mp_int_t b = mp_obj_get_int(b_in); if (a <= b) { - return mp_obj_new_int(a + yasmarang_randbelow(b - a + 1)); + return mp_obj_new_int(a + yasmarang_randbelow((uint32_t)(b - a + 1))); } else { mp_raise_ValueError(NULL); } @@ -177,7 +177,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_random_randint_obj, mod_random_randint); STATIC mp_obj_t mod_random_choice(mp_obj_t seq) { mp_int_t len = mp_obj_get_int(mp_obj_len(seq)); if (len > 0) { - return mp_obj_subscr(seq, mp_obj_new_int(yasmarang_randbelow(len)), MP_OBJ_SENTINEL); + return mp_obj_subscr(seq, mp_obj_new_int(yasmarang_randbelow((uint32_t)len)), MP_OBJ_SENTINEL); } else { mp_raise_type(&mp_type_IndexError); } From 5d83bbca60ea3f4071b9245daf8a41296072f918 Mon Sep 17 00:00:00 2001 From: Yoctopuce Date: Tue, 30 Jan 2024 09:46:17 +0100 Subject: [PATCH 121/408] shared/timeutils: Remove useless void-return. The C99 standard states: 6.8.6.4 The return statement Constraints A return statement with an expression shall not appear in a function whose return type is void. A return statement without an expression shall only appear in a function whose return type is void. And when `-pedantic` is enabled the compiler gives an error. Signed-off-by: Yoctopuce --- shared/timeutils/timeutils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/timeutils/timeutils.h b/shared/timeutils/timeutils.h index 9f4b500caa7b6..69cbd95df53a6 100644 --- a/shared/timeutils/timeutils.h +++ b/shared/timeutils/timeutils.h @@ -60,7 +60,7 @@ mp_uint_t timeutils_mktime_2000(mp_uint_t year, mp_int_t month, mp_int_t mday, static inline void timeutils_seconds_since_epoch_to_struct_time(uint64_t t, timeutils_struct_time_t *tm) { // TODO this will give incorrect results for dates before 2000/1/1 - return timeutils_seconds_since_2000_to_struct_time(t - TIMEUTILS_SECONDS_1970_TO_2000, tm); + timeutils_seconds_since_2000_to_struct_time(t - TIMEUTILS_SECONDS_1970_TO_2000, tm); } static inline uint64_t timeutils_mktime(mp_uint_t year, mp_int_t month, mp_int_t mday, mp_int_t hours, mp_int_t minutes, mp_int_t seconds) { From 00ba6aaae4c815fc9685defc37a5df1424180c0e Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 18 Jan 2024 08:52:16 +1100 Subject: [PATCH 122/408] ports: On cold boot, enable USB after boot.py completes. For mimxrt, nrf, renesas-ra, rp2 and samd ports, this commit implements similar behaviour to the stm32 port, where USB is only brought up after boot.py completes execution. Currently this doesn't add any useful functionality (and may break workflows that depend on USB-CDC being live in boot.py), however it's a precondition for more usable workflows with USB devices defined in Python (allows setting up USB interfaces in boot.py before the device enumerates for the first time). This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- ports/mimxrt/main.c | 6 ++++-- ports/nrf/drivers/usb/usb_cdc.c | 4 ++-- ports/nrf/main.c | 6 ++++-- ports/renesas-ra/main.c | 18 ++++++++++-------- ports/rp2/main.c | 12 +++++++----- ports/samd/main.c | 4 ++++ ports/samd/samd_soc.c | 2 -- shared/tinyusb/mp_usbd.h | 7 +++++++ 8 files changed, 38 insertions(+), 21 deletions(-) diff --git a/ports/mimxrt/main.c b/ports/mimxrt/main.c index 376d72f197f30..761c491742bcf 100644 --- a/ports/mimxrt/main.c +++ b/ports/mimxrt/main.c @@ -34,8 +34,8 @@ #include "shared/runtime/gchelper.h" #include "shared/runtime/pyexec.h" #include "shared/runtime/softtimer.h" +#include "shared/tinyusb/mp_usbd.h" #include "ticks.h" -#include "tusb.h" #include "led.h" #include "pendsv.h" #include "modmachine.h" @@ -63,7 +63,6 @@ void board_init(void); int main(void) { board_init(); ticks_init(); - tusb_init(); pendsv_init(); #if MICROPY_PY_LWIP @@ -115,6 +114,9 @@ int main(void) { // Execute user scripts. int ret = pyexec_file_if_exists("boot.py"); + + mp_usbd_init(); + if (ret & PYEXEC_FORCED_EXIT) { goto soft_reset_exit; } diff --git a/ports/nrf/drivers/usb/usb_cdc.c b/ports/nrf/drivers/usb/usb_cdc.c index 3ca2acbf3dba2..aef7354972722 100644 --- a/ports/nrf/drivers/usb/usb_cdc.c +++ b/ports/nrf/drivers/usb/usb_cdc.c @@ -29,7 +29,6 @@ #if MICROPY_HW_USB_CDC -#include "tusb.h" #include "nrfx.h" #include "nrfx_power.h" #include "nrfx_uart.h" @@ -37,6 +36,7 @@ #include "py/stream.h" #include "py/runtime.h" #include "shared/runtime/interrupt_char.h" +#include "shared/tinyusb/mp_usbd.h" #ifdef BLUETOOTH_SD #include "nrf_sdm.h" @@ -186,7 +186,7 @@ int usb_cdc_init(void) tx_ringbuf.iget = 0; tx_ringbuf.iput = 0; - tusb_init(); + mp_usbd_init(); return 0; } diff --git a/ports/nrf/main.c b/ports/nrf/main.c index 9809ba0e23fc0..dd9f232b80c55 100644 --- a/ports/nrf/main.c +++ b/ports/nrf/main.c @@ -261,13 +261,15 @@ void NORETURN _start(void) { led_state(1, 0); + #if MICROPY_VFS || MICROPY_MBFS || MICROPY_MODULE_FROZEN + ret = pyexec_file_if_exists("boot.py"); + #endif + #if MICROPY_HW_USB_CDC usb_cdc_init(); #endif #if MICROPY_VFS || MICROPY_MBFS || MICROPY_MODULE_FROZEN - // run boot.py and main.py if they exist. - ret = pyexec_file_if_exists("boot.py"); if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL && ret != 0) { pyexec_file_if_exists("main.py"); } diff --git a/ports/renesas-ra/main.c b/ports/renesas-ra/main.c index 761420423e2cf..5925606f9c770 100644 --- a/ports/renesas-ra/main.c +++ b/ports/renesas-ra/main.c @@ -36,6 +36,7 @@ #include "shared/readline/readline.h" #include "shared/runtime/pyexec.h" #include "shared/runtime/softtimer.h" +#include "shared/tinyusb/mp_usbd.h" #include "lib/oofatfs/ff.h" #include "lib/littlefs/lfs1.h" #include "lib/littlefs/lfs1_util.h" @@ -63,7 +64,6 @@ #include "usrsw.h" #include "rtc.h" #include "storage.h" -#include "tusb.h" #if MICROPY_PY_LWIP #include "lwip/init.h" #include "lwip/apps/mdns.h" @@ -270,10 +270,6 @@ int main(void) { state.reset_mode = 1; state.log_soft_reset = false; - #if MICROPY_HW_ENABLE_USBDEV - tusb_init(); - #endif - #if MICROPY_PY_BLUETOOTH mp_bluetooth_hci_init(); #endif @@ -366,14 +362,20 @@ int main(void) { #endif // Run boot.py (or whatever else a board configures at this stage). - if (MICROPY_BOARD_RUN_BOOT_PY(&state) == BOARDCTRL_GOTO_SOFT_RESET_EXIT) { - goto soft_reset_exit; - } + int boot_res = MICROPY_BOARD_RUN_BOOT_PY(&state); // Now we initialise sub-systems that need configuration from boot.py, // or whose initialisation can be safely deferred until after running // boot.py. + #if MICROPY_HW_ENABLE_USBDEV + mp_usbd_init(); + #endif + + if (boot_res == BOARDCTRL_GOTO_SOFT_RESET_EXIT) { + goto soft_reset_exit; + } + // At this point everything is fully configured and initialised. // Run main.py (or whatever else a board configures at this stage). diff --git a/ports/rp2/main.c b/ports/rp2/main.c index e63b8c03f07fc..70a67066fc9d7 100644 --- a/ports/rp2/main.c +++ b/ports/rp2/main.c @@ -38,7 +38,7 @@ #include "shared/runtime/gchelper.h" #include "shared/runtime/pyexec.h" #include "shared/runtime/softtimer.h" -#include "tusb.h" +#include "shared/tinyusb/mp_usbd.h" #include "uart.h" #include "modmachine.h" #include "modrp2.h" @@ -86,12 +86,9 @@ int main(int argc, char **argv) { #endif #endif - #if MICROPY_HW_ENABLE_USBDEV - #if MICROPY_HW_USB_CDC + #if MICROPY_HW_ENABLE_USBDEV && MICROPY_HW_USB_CDC bi_decl(bi_program_feature("USB REPL")) #endif - tusb_init(); - #endif #if MICROPY_PY_THREAD bi_decl(bi_program_feature("thread support")) @@ -181,6 +178,11 @@ int main(int argc, char **argv) { // Execute user scripts. int ret = pyexec_file_if_exists("boot.py"); + + #if MICROPY_HW_ENABLE_USBDEV + mp_usbd_init(); + #endif + if (ret & PYEXEC_FORCED_EXIT) { goto soft_reset_exit; } diff --git a/ports/samd/main.c b/ports/samd/main.c index 74eb5e328526b..f051e961ffa24 100644 --- a/ports/samd/main.c +++ b/ports/samd/main.c @@ -33,6 +33,7 @@ #include "shared/runtime/gchelper.h" #include "shared/runtime/pyexec.h" #include "shared/runtime/softtimer.h" +#include "shared/tinyusb/mp_usbd.h" extern uint8_t _sstack, _estack, _sheap, _eheap; extern void adc_deinit_all(void); @@ -56,6 +57,9 @@ void samd_main(void) { // Execute user scripts. int ret = pyexec_file_if_exists("boot.py"); + + mp_usbd_init(); + if (ret & PYEXEC_FORCED_EXIT) { goto soft_reset_exit; } diff --git a/ports/samd/samd_soc.c b/ports/samd/samd_soc.c index 259640e93db0d..5e6c5c4fc2407 100644 --- a/ports/samd/samd_soc.c +++ b/ports/samd/samd_soc.c @@ -62,8 +62,6 @@ static void usb_init(void) { PORT->Group[0].PMUX[12].reg = alt << 4 | alt; PORT->Group[0].PINCFG[24].reg = PORT_PINCFG_PMUXEN; PORT->Group[0].PINCFG[25].reg = PORT_PINCFG_PMUXEN; - - tusb_init(); } // Initialize the µs counter on TC 0/1 or TC4/5 diff --git a/shared/tinyusb/mp_usbd.h b/shared/tinyusb/mp_usbd.h index 83a8f8617c08d..89f8bf0ee953b 100644 --- a/shared/tinyusb/mp_usbd.h +++ b/shared/tinyusb/mp_usbd.h @@ -28,6 +28,13 @@ #define MICROPY_INCLUDED_SHARED_TINYUSB_MP_USBD_H #include "py/obj.h" +#include "tusb.h" + +static inline void mp_usbd_init(void) { + // Currently this is a thin wrapper around tusb_init(), however + // runtime USB support will require this to be extended. + tusb_init(); +} // Call this to explicitly run the TinyUSB device task. void mp_usbd_task(void); From 34097b776e00e81bcf2fdd3a2b13472a6085dee9 Mon Sep 17 00:00:00 2001 From: Trent Piepho Date: Sat, 10 Feb 2024 14:59:26 -0800 Subject: [PATCH 123/408] esp32/network_ppp: Make PPP support optional. PPP is not that commonly used, let it be turned off in the board config to save space. It is still on by default. On an basic ESP32-S3 build, turning off PPP with LWIP still on saves ~35 kB of codend 4 kB of data. text data bss dec hex filename 1321257 304296 2941433 4566986 45afca before-ppp-off.elf 1285101 299920 2810305 4395326 43113e after-ppp-off.elf ------------------------------- -36156 -4376 -56 Note that the BSS segment size includes all NOBITS sections in ELF file. Some of these are aligned to 64kB chunk sized dummy blocks, I think for alignment to MMU boundaries, and these went down by 1 block each, so 128 kiB of BSS is not really part of the binary size reduction. Signed-off-by: Trent Piepho --- ports/esp32/modnetwork_globals.h | 2 ++ ports/esp32/network_ppp.c | 4 ++++ ports/esp32/ppp_set_auth.c | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ports/esp32/modnetwork_globals.h b/ports/esp32/modnetwork_globals.h index c6369ab9a79aa..56e5341915bfc 100644 --- a/ports/esp32/modnetwork_globals.h +++ b/ports/esp32/modnetwork_globals.h @@ -7,7 +7,9 @@ #if MICROPY_PY_NETWORK_LAN { MP_ROM_QSTR(MP_QSTR_LAN), MP_ROM_PTR(&esp_network_get_lan_obj) }, #endif +#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP) && defined(CONFIG_LWIP_PPP_SUPPORT) { MP_ROM_QSTR(MP_QSTR_PPP), MP_ROM_PTR(&esp_network_ppp_make_new_obj) }, +#endif { MP_ROM_QSTR(MP_QSTR_phy_mode), MP_ROM_PTR(&esp_network_phy_mode_obj) }, #if MICROPY_PY_NETWORK_WLAN diff --git a/ports/esp32/network_ppp.c b/ports/esp32/network_ppp.c index 0d8046c97df82..08443752cc26c 100644 --- a/ports/esp32/network_ppp.c +++ b/ports/esp32/network_ppp.c @@ -43,6 +43,8 @@ #include "lwip/dns.h" #include "netif/ppp/pppapi.h" +#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP) && defined(CONFIG_LWIP_PPP_SUPPORT) + #define PPP_CLOSE_TIMEOUT_MS (4000) typedef struct _ppp_if_obj_t { @@ -341,3 +343,5 @@ MP_DEFINE_CONST_OBJ_TYPE( MP_TYPE_FLAG_NONE, locals_dict, &ppp_if_locals_dict ); + +#endif diff --git a/ports/esp32/ppp_set_auth.c b/ports/esp32/ppp_set_auth.c index 88ab668d48d3a..dc2a3dcd78660 100644 --- a/ports/esp32/ppp_set_auth.c +++ b/ports/esp32/ppp_set_auth.c @@ -9,7 +9,7 @@ #include "ppp_set_auth.h" -#ifdef CONFIG_ESP_NETIF_TCPIP_LWIP +#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP) && defined(CONFIG_LWIP_PPP_SUPPORT) #include "netif/ppp/pppapi.h" From c27d304bed737ef0315ca695323f7adc42e61ba9 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 14 Feb 2024 12:39:27 +1100 Subject: [PATCH 124/408] esp32/mpnimbleport: Release the GIL while doing NimBLE port deinit. In case callbacks must run (eg a disconnect event happens during the deinit) and the GIL must be obtained to run the callback. Fixes part of issue #12349. Signed-off-by: Damien George --- ports/esp32/mpnimbleport.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ports/esp32/mpnimbleport.c b/ports/esp32/mpnimbleport.c index 8235275be6fd6..5b57edf3c1c19 100644 --- a/ports/esp32/mpnimbleport.c +++ b/ports/esp32/mpnimbleport.c @@ -63,6 +63,11 @@ void mp_bluetooth_nimble_port_start(void) { void mp_bluetooth_nimble_port_shutdown(void) { DEBUG_printf("mp_bluetooth_nimble_port_shutdown\n"); + #if MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS_WITH_INTERLOCK + // Release the GIL so any callbacks can run during the shutdown calls below. + MP_THREAD_GIL_EXIT(); + #endif + // Despite the name, these is an ESP32-specific (no other NimBLE ports have these functions). // Calls ble_hs_stop() and waits for stack shutdown. nimble_port_stop(); @@ -70,6 +75,10 @@ void mp_bluetooth_nimble_port_shutdown(void) { // Shuts down the event queue. nimble_port_deinit(); + #if MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS_WITH_INTERLOCK + MP_THREAD_GIL_ENTER(); + #endif + // Mark stack as shutdown. mp_bluetooth_nimble_ble_state = MP_BLUETOOTH_NIMBLE_BLE_STATE_OFF; } From e3be70b5e8a4b6f80426f967c467f9f765f92c26 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 13 Feb 2024 14:53:58 +0900 Subject: [PATCH 125/408] minimal: Allow compiling on macOS. Signed-off-by: YAMAMOTO Takashi --- ports/minimal/Makefile | 5 +++++ ports/minimal/mpconfigport.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ports/minimal/Makefile b/ports/minimal/Makefile index 050c4ddf526a5..824e54205bb0b 100644 --- a/ports/minimal/Makefile +++ b/ports/minimal/Makefile @@ -26,9 +26,14 @@ CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mcpu=cortex-m4 -msoft-float -fsingl CFLAGS += $(INC) -Wall -Werror -std=c99 -nostdlib $(CFLAGS_CORTEX_M4) $(COPT) LDFLAGS += -nostdlib -T stm32f405.ld -Map=$@.map --cref --gc-sections else +UNAME_S := $(shell uname -s) LD = $(CC) CFLAGS += $(INC) -Wall -Werror -Wdouble-promotion -Wfloat-conversion -std=c99 $(COPT) +ifeq ($(UNAME_S),Linux) LDFLAGS += -Wl,-Map=$@.map,--cref -Wl,--gc-sections +else ifeq ($(UNAME_S),Darwin) +LDFLAGS += -Wl,-map,$@.map -Wl,-dead_strip +endif endif CSUPEROPT = -Os # save some code space diff --git a/ports/minimal/mpconfigport.h b/ports/minimal/mpconfigport.h index 56bef165facda..87287cbc6f359 100644 --- a/ports/minimal/mpconfigport.h +++ b/ports/minimal/mpconfigport.h @@ -33,7 +33,7 @@ typedef long mp_off_t; #define MICROPY_HW_BOARD_NAME "minimal" #define MICROPY_HW_MCU_NAME "unknown-cpu" -#ifdef __linux__ +#if defined(__linux__) || defined(__APPLE__) #define MICROPY_MIN_USE_STDOUT (1) #define MICROPY_HEAP_SIZE (25600) // heap size 25 kilobytes #endif From 06cb6b1e9fe8e4f965f14843be5a4ffe676c7f90 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 15 Feb 2024 12:15:02 +0900 Subject: [PATCH 126/408] minimal: Use printf instead of echo -e. macOS's echo doesn't have -e option. printf is in POSIX and more widely available these days. Signed-off-by: YAMAMOTO Takashi --- ports/minimal/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/minimal/Makefile b/ports/minimal/Makefile index 824e54205bb0b..9bdc06fc97501 100644 --- a/ports/minimal/Makefile +++ b/ports/minimal/Makefile @@ -106,6 +106,6 @@ run: stty $$saved_ test: $(BUILD)/firmware.elf - $(Q)/bin/echo -e "print('hello world!', list(x+1 for x in range(10)), end='eol\\\\n')\\r\\n\\x04" | $(BUILD)/firmware.elf | tail -n2 | grep "^hello world! \\[1, 2, 3, 4, 5, 6, 7, 8, 9, 10\\]eol" + $(Q)/usr/bin/printf "print('hello world!', list(x+1 for x in range(10)), end='eol\\\\n')\\r\\n\\004" | $(BUILD)/firmware.elf | tail -n2 | grep "^hello world! \\[1, 2, 3, 4, 5, 6, 7, 8, 9, 10\\]eol" include $(TOP)/py/mkrules.mk From f9704ce36e2396001b34d86a01b75af607901f94 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 13 Feb 2024 18:46:17 +0900 Subject: [PATCH 127/408] unix/input: Flush the prompt after writing it to stdout. Depending on your setup, stdout might be buffered/line-buffered. Signed-off-by: YAMAMOTO Takashi --- ports/unix/input.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/unix/input.c b/ports/unix/input.c index c5bf7197388cc..31926a5a8e1af 100644 --- a/ports/unix/input.c +++ b/ports/unix/input.c @@ -43,6 +43,7 @@ char *prompt(char *p) { // simple read string static char buf[256]; fputs(p, stdout); + fflush(stdout); char *s = fgets(buf, sizeof(buf), stdin); if (!s) { return NULL; From 809d113dbc37a032e87accc95c140f189733e0c4 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 13 Feb 2024 16:31:40 +0900 Subject: [PATCH 128/408] unix: Don't include system headers when features are disabled. Because the target system may not have these headers at all. Signed-off-by: YAMAMOTO Takashi --- ports/unix/modsocket.c | 6 ++++-- ports/unix/modtermios.c | 4 ++-- ports/unix/mpbtstackport_h4.c | 6 ++++-- ports/unix/mpbtstackport_usb.c | 6 ++++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/ports/unix/modsocket.c b/ports/unix/modsocket.c index 737550b428de3..5c935d2299bae 100644 --- a/ports/unix/modsocket.c +++ b/ports/unix/modsocket.c @@ -25,6 +25,10 @@ * THE SOFTWARE. */ +#include "py/mpconfig.h" + +#if MICROPY_PY_SOCKET + #include #include #include @@ -49,8 +53,6 @@ #include "extmod/vfs.h" #include -#if MICROPY_PY_SOCKET - /* The idea of this module is to implement reasonable minimum of socket-related functions to write typical clients and servers. diff --git a/ports/unix/modtermios.c b/ports/unix/modtermios.c index 4f9751e274378..8a79bc3a5943d 100644 --- a/ports/unix/modtermios.c +++ b/ports/unix/modtermios.c @@ -24,6 +24,8 @@ * THE SOFTWARE. */ +#if MICROPY_PY_TERMIOS + #include #include #include @@ -33,8 +35,6 @@ #include "py/runtime.h" #include "py/mphal.h" -#if MICROPY_PY_TERMIOS - STATIC mp_obj_t mod_termios_tcgetattr(mp_obj_t fd_in) { struct termios term; int fd = mp_obj_get_int(fd_in); diff --git a/ports/unix/mpbtstackport_h4.c b/ports/unix/mpbtstackport_h4.c index dacfff9a498af..a2038c16a90a8 100644 --- a/ports/unix/mpbtstackport_h4.c +++ b/ports/unix/mpbtstackport_h4.c @@ -24,14 +24,16 @@ * THE SOFTWARE. */ +#include "py/mpconfig.h" + +#if MICROPY_PY_BLUETOOTH && MICROPY_BLUETOOTH_BTSTACK && MICROPY_BLUETOOTH_BTSTACK_H4 + #include #include "py/runtime.h" #include "py/mperrno.h" #include "py/mphal.h" -#if MICROPY_PY_BLUETOOTH && MICROPY_BLUETOOTH_BTSTACK && MICROPY_BLUETOOTH_BTSTACK_H4 - #include "lib/btstack/src/hci_transport_h4.h" #include "lib/btstack/chipset/zephyr/btstack_chipset_zephyr.h" diff --git a/ports/unix/mpbtstackport_usb.c b/ports/unix/mpbtstackport_usb.c index b8c7b758d93e6..1793e2bacd21e 100644 --- a/ports/unix/mpbtstackport_usb.c +++ b/ports/unix/mpbtstackport_usb.c @@ -24,6 +24,10 @@ * THE SOFTWARE. */ +#include "py/mpconfig.h" + +#if MICROPY_PY_BLUETOOTH && MICROPY_BLUETOOTH_BTSTACK && MICROPY_BLUETOOTH_BTSTACK_USB + #include #include @@ -31,8 +35,6 @@ #include "py/mperrno.h" #include "py/mphal.h" -#if MICROPY_PY_BLUETOOTH && MICROPY_BLUETOOTH_BTSTACK && MICROPY_BLUETOOTH_BTSTACK_USB - #include "lib/btstack/src/btstack.h" #include "lib/btstack/src/hci_transport_usb.h" #include "lib/btstack/platform/embedded/btstack_run_loop_embedded.h" From cd66aa05cf2d11401876a342fad2425e766bd921 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 15 Feb 2024 23:03:29 +1100 Subject: [PATCH 129/408] esp32: Increase NimBLE task stack size and overflow detection headroom. The Python BLE IRQ handler will most likely run on the NimBLE task, so its C stack must be large enough to accommodate reasonably complicated Python code (eg a few call depths). So increase this stack size. Also increase the headroom from 1024 to 2048 bytes. This is needed because (1) the esp32 architecture uses a fair amount of stack in general; and (2) by the time execution gets to setting the Python stack top via `mp_stack_set_top()` in this interlock code, about 600 bytes of stack are already used, which reduces the amount available for Python. Fixes issue #12349. Signed-off-by: Damien George --- extmod/modbluetooth.c | 2 +- ports/esp32/boards/sdkconfig.ble | 4 ++++ ports/esp32/mpconfigport.h | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/extmod/modbluetooth.c b/extmod/modbluetooth.c index cef5151cc9ddc..32a15bf511acb 100644 --- a/extmod/modbluetooth.c +++ b/extmod/modbluetooth.c @@ -1274,7 +1274,7 @@ STATIC mp_obj_t invoke_irq_handler(uint16_t event, if (ts_orig == NULL) { mp_thread_set_state(&ts); mp_stack_set_top(&ts + 1); // need to include ts in root-pointer scan - mp_stack_set_limit(MICROPY_PY_BLUETOOTH_SYNC_EVENT_STACK_SIZE - 1024); + mp_stack_set_limit(MICROPY_PY_BLUETOOTH_SYNC_EVENT_STACK_SIZE); ts.gc_lock_depth = 0; ts.nlr_jump_callback_top = NULL; ts.mp_pending_exception = MP_OBJ_NULL; diff --git a/ports/esp32/boards/sdkconfig.ble b/ports/esp32/boards/sdkconfig.ble index 7fa08fe286d7f..af2d4b133ec7b 100644 --- a/ports/esp32/boards/sdkconfig.ble +++ b/ports/esp32/boards/sdkconfig.ble @@ -14,3 +14,7 @@ CONFIG_BT_NIMBLE_MAX_CONNECTIONS=4 CONFIG_BT_NIMBLE_PINNED_TO_CORE_0=n CONFIG_BT_NIMBLE_PINNED_TO_CORE_1=y CONFIG_BT_NIMBLE_PINNED_TO_CORE=1 + +# Increase NimBLE task stack size from the default, because Python code +# (BLE IRQ handlers) will most likely run on this task. +CONFIG_BT_NIMBLE_TASK_STACK_SIZE=6144 diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h index 5dc4a9c758790..acf065384b7da 100644 --- a/ports/esp32/mpconfigport.h +++ b/ports/esp32/mpconfigport.h @@ -95,7 +95,7 @@ #define MICROPY_PY_BLUETOOTH (1) #define MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS (1) #define MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS_WITH_INTERLOCK (1) -#define MICROPY_PY_BLUETOOTH_SYNC_EVENT_STACK_SIZE (CONFIG_BT_NIMBLE_TASK_STACK_SIZE) +#define MICROPY_PY_BLUETOOTH_SYNC_EVENT_STACK_SIZE (CONFIG_BT_NIMBLE_TASK_STACK_SIZE - 2048) #define MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE (1) #define MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING (1) #define MICROPY_BLUETOOTH_NIMBLE (1) From 866fc3447c7a685c6c04d6a03ee94083b8d0dd72 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 16 Feb 2024 10:16:18 +1100 Subject: [PATCH 130/408] tests/multi_bluetooth/ble_irq_calls.py: Enhance test to test recursion. Signed-off-by: Damien George --- tests/multi_bluetooth/ble_irq_calls.py | 18 ++++++++++++++++++ tests/multi_bluetooth/ble_irq_calls.py.exp | 1 + 2 files changed, 19 insertions(+) diff --git a/tests/multi_bluetooth/ble_irq_calls.py b/tests/multi_bluetooth/ble_irq_calls.py index c8c673daab31d..2717bd5f3da5a 100644 --- a/tests/multi_bluetooth/ble_irq_calls.py +++ b/tests/multi_bluetooth/ble_irq_calls.py @@ -60,6 +60,22 @@ ACCESSORY_SERVICE = (ACCESSORY_UUID, (STATE_CHARACTERISTIC,)) +def recursive_function(): + recursive_function() + + +def test_deep_calls(n): + if n > 0: + # Test that a few nested calls will succeed. + test_deep_calls(n - 1) + else: + # Test that a Python stack overflow is detected. + try: + recursive_function() + except RuntimeError: + print("test_deep_calls finished") + + class Central: def __init__(self): self.done = False @@ -79,6 +95,8 @@ def _ble_event_handler(self, event, data): conn_handle, _, _ = data self._conn_handle = conn_handle ble.gattc_discover_services(self._conn_handle, ACCESSORY_UUID) + # Test deep Python calls from within this BLE IRQ handler. + test_deep_calls(5) elif event == _IRQ_PERIPHERAL_DISCONNECT: conn_handle, _, addr = data diff --git a/tests/multi_bluetooth/ble_irq_calls.py.exp b/tests/multi_bluetooth/ble_irq_calls.py.exp index d655c507d34f1..993e6f79e8a87 100644 --- a/tests/multi_bluetooth/ble_irq_calls.py.exp +++ b/tests/multi_bluetooth/ble_irq_calls.py.exp @@ -8,6 +8,7 @@ _IRQ_CENTRAL_DISCONNECT --- instance1 --- central start _IRQ_PERIPHERAL_CONNECT +test_deep_calls finished _IRQ_GATTC_SERVICE_RESULT service found: 3 UUID('a5a5a5a5-ffff-9999-1111-5a5a5a5a5a5a') _IRQ_GATTC_SERVICE_DONE From 628abf8f25a7705a2810fffe2ca6ae652c532896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20D=C3=B6rre?= Date: Thu, 25 Aug 2022 17:25:08 +0000 Subject: [PATCH 131/408] extmod/modlwip: Support IPv6. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With these changes IPv6 works on the rp2 port (and possibly others that use the lwIP socket implementation). Things that have been tested and work: - Neighbour solicitation for v6 link local address. - Ping of v6 link-local address. - Receiving a SLAAC address via router advertisement. - Ping a v6 address allocated via SLAAC. - Perform an outgoing connection to a routed v6-address (via default gateway). - Create a listening IPv6 wildcard socked bound to ::, and trying to access it via link-local, SLAAC, and IPv4 (to ensure the dual-stack binding works). Things that could be improved: - socket.socket().getaddrinfo only returns the v4 address. It could also return v6 addresses (getaddrinfo is actively programmed to only return a single address, and this is the v4-address by default, with fallback to the v6 address if both are enabled). Signed-off-by: Felix Dörre --- extmod/modlwip.c | 70 ++++++++++++++++++++++++------------ extmod/network_cyw43.c | 9 ++--- shared/netutils/dhcpserver.c | 14 ++++---- 3 files changed, 60 insertions(+), 33 deletions(-) diff --git a/extmod/modlwip.c b/extmod/modlwip.c index 6f8703d5a71a9..8ccc388913f42 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -353,6 +353,26 @@ STATIC void lwip_socket_free_incoming(lwip_socket_obj_t *socket) { } } +mp_obj_t lwip_format_inet_addr(const ip_addr_t *ip, mp_uint_t port) { + char *ipstr = ipaddr_ntoa(ip); + mp_obj_t tuple[2] = { + tuple[0] = mp_obj_new_str(ipstr, strlen(ipstr)), + tuple[1] = mp_obj_new_int(port), + }; + return mp_obj_new_tuple(2, tuple); +} + +mp_uint_t lwip_parse_inet_addr(mp_obj_t addr_in, ip_addr_t *out_ip) { + mp_obj_t *addr_items; + mp_obj_get_array_fixed_n(addr_in, 2, &addr_items); + size_t addr_len; + const char *addr_str = mp_obj_str_get_data(addr_items[0], &addr_len); + if (!ipaddr_aton(addr_str, out_ip)) { + mp_raise_ValueError(MP_ERROR_TEXT("invalid arguments")); + } + return mp_obj_get_int(addr_items[1]); +} + /*******************************************************************************/ // Callback functions for the lwIP raw API. @@ -538,7 +558,7 @@ STATIC err_t _lwip_tcp_recv(void *arg, struct tcp_pcb *tcpb, struct pbuf *p, err // these to do the work. // Helper function for send/sendto to handle raw/UDP packets. -STATIC mp_uint_t lwip_raw_udp_send(lwip_socket_obj_t *socket, const byte *buf, mp_uint_t len, byte *ip, mp_uint_t port, int *_errno) { +STATIC mp_uint_t lwip_raw_udp_send(lwip_socket_obj_t *socket, const byte *buf, mp_uint_t len, ip_addr_t *ip, mp_uint_t port, int *_errno) { if (len > 0xffff) { // Any packet that big is probably going to fail the pbuf_alloc anyway, but may as well try len = 0xffff; @@ -567,15 +587,13 @@ STATIC mp_uint_t lwip_raw_udp_send(lwip_socket_obj_t *socket, const byte *buf, m err = udp_send(socket->pcb.udp, p); } } else { - ip_addr_t dest; - IP4_ADDR(&dest, ip[0], ip[1], ip[2], ip[3]); #if MICROPY_PY_LWIP_SOCK_RAW if (socket->type == MOD_NETWORK_SOCK_RAW) { - err = raw_sendto(socket->pcb.raw, p, &dest); + err = raw_sendto(socket->pcb.raw, p, ip); } else #endif { - err = udp_sendto(socket->pcb.udp, p, &dest, port); + err = udp_sendto(socket->pcb.udp, p, ip, port); } } @@ -885,11 +903,8 @@ STATIC mp_obj_t lwip_socket_make_new(const mp_obj_type_t *type, size_t n_args, s STATIC mp_obj_t lwip_socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { lwip_socket_obj_t *socket = MP_OBJ_TO_PTR(self_in); - uint8_t ip[NETUTILS_IPV4ADDR_BUFSIZE]; - mp_uint_t port = netutils_parse_inet_addr(addr_in, ip, NETUTILS_BIG); - ip_addr_t bind_addr; - IP4_ADDR(&bind_addr, ip[0], ip[1], ip[2], ip[3]); + mp_uint_t port = lwip_parse_inet_addr(addr_in, &bind_addr); err_t err = ERR_ARG; switch (socket->type) { @@ -926,6 +941,12 @@ STATIC mp_obj_t lwip_socket_listen(size_t n_args, const mp_obj_t *args) { if (socket->type != MOD_NETWORK_SOCK_STREAM) { mp_raise_OSError(MP_EOPNOTSUPP); } + #if LWIP_IPV6 + if (ip_addr_cmp(&socket->pcb.tcp->local_ip, IP6_ADDR_ANY)) { + IP_SET_TYPE_VAL(socket->pcb.tcp->local_ip, IPADDR_TYPE_ANY); + IP_SET_TYPE_VAL(socket->pcb.tcp->remote_ip, IPADDR_TYPE_ANY); + } + #endif struct tcp_pcb *new_pcb; #if LWIP_VERSION_MACRO < 0x02000100 @@ -1043,12 +1064,10 @@ STATIC mp_obj_t lwip_socket_accept(mp_obj_t self_in) { MICROPY_PY_LWIP_EXIT // make the return value - uint8_t ip[NETUTILS_IPV4ADDR_BUFSIZE]; - memcpy(ip, &(socket2->pcb.tcp->remote_ip), sizeof(ip)); mp_uint_t port = (mp_uint_t)socket2->pcb.tcp->remote_port; mp_obj_tuple_t *client = MP_OBJ_TO_PTR(mp_obj_new_tuple(2, NULL)); client->items[0] = MP_OBJ_FROM_PTR(socket2); - client->items[1] = netutils_format_inet_addr(ip, port, NETUTILS_BIG); + client->items[1] = lwip_format_inet_addr(&socket2->pcb.tcp->remote_ip, port); return MP_OBJ_FROM_PTR(client); } @@ -1062,11 +1081,8 @@ STATIC mp_obj_t lwip_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { } // get address - uint8_t ip[NETUTILS_IPV4ADDR_BUFSIZE]; - mp_uint_t port = netutils_parse_inet_addr(addr_in, ip, NETUTILS_BIG); - ip_addr_t dest; - IP4_ADDR(&dest, ip[0], ip[1], ip[2], ip[3]); + mp_uint_t port = lwip_parse_inet_addr(addr_in, &dest); err_t err = ERR_ARG; switch (socket->type) { @@ -1219,8 +1235,8 @@ STATIC mp_obj_t lwip_socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t mp_buffer_info_t bufinfo; mp_get_buffer_raise(data_in, &bufinfo, MP_BUFFER_READ); - uint8_t ip[NETUTILS_IPV4ADDR_BUFSIZE]; - mp_uint_t port = netutils_parse_inet_addr(addr_in, ip, NETUTILS_BIG); + ip_addr_t ip; + mp_uint_t port = lwip_parse_inet_addr(addr_in, &ip); mp_uint_t ret = 0; switch (socket->type) { @@ -1232,7 +1248,7 @@ STATIC mp_obj_t lwip_socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t #if MICROPY_PY_LWIP_SOCK_RAW case MOD_NETWORK_SOCK_RAW: #endif - ret = lwip_raw_udp_send(socket, bufinfo.buf, bufinfo.len, ip, port, &_errno); + ret = lwip_raw_udp_send(socket, bufinfo.buf, bufinfo.len, &ip, port, &_errno); break; } if (ret == -1) { @@ -1357,6 +1373,12 @@ STATIC mp_obj_t lwip_socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_setblocking_obj, lwip_socket_setblocking); +#if LWIP_VERSION_MAJOR < 2 +#define MP_IGMP_IP_ADDR_TYPE ip_addr_t +#else +#define MP_IGMP_IP_ADDR_TYPE ip4_addr_t +#endif + STATIC mp_obj_t lwip_socket_setsockopt(size_t n_args, const mp_obj_t *args) { (void)n_args; // always 4 lwip_socket_obj_t *socket = MP_OBJ_TO_PTR(args[0]); @@ -1397,9 +1419,9 @@ STATIC mp_obj_t lwip_socket_setsockopt(size_t n_args, const mp_obj_t *args) { // POSIX setsockopt has order: group addr, if addr, lwIP has it vice-versa err_t err; if (opt == IP_ADD_MEMBERSHIP) { - err = igmp_joingroup((ip_addr_t *)bufinfo.buf + 1, bufinfo.buf); + err = igmp_joingroup((MP_IGMP_IP_ADDR_TYPE *)bufinfo.buf + 1, bufinfo.buf); } else { - err = igmp_leavegroup((ip_addr_t *)bufinfo.buf + 1, bufinfo.buf); + err = igmp_leavegroup((MP_IGMP_IP_ADDR_TYPE *)bufinfo.buf + 1, bufinfo.buf); } if (err != ERR_OK) { mp_raise_OSError(error_lookup_table[-err]); @@ -1412,6 +1434,9 @@ STATIC mp_obj_t lwip_socket_setsockopt(size_t n_args, const mp_obj_t *args) { } return mp_const_none; } + +#undef MP_IGMP_IP_ADDR_TYPE + STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lwip_socket_setsockopt_obj, 4, 4, lwip_socket_setsockopt); STATIC mp_obj_t lwip_socket_makefile(size_t n_args, const mp_obj_t *args) { @@ -1742,12 +1767,13 @@ STATIC mp_obj_t lwip_getaddrinfo(size_t n_args, const mp_obj_t *args) { mp_raise_OSError(state.status); } + ip_addr_t ipcopy = state.ipaddr; mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(5, NULL)); tuple->items[0] = MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_AF_INET); tuple->items[1] = MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_SOCK_STREAM); tuple->items[2] = MP_OBJ_NEW_SMALL_INT(0); tuple->items[3] = MP_OBJ_NEW_QSTR(MP_QSTR_); - tuple->items[4] = netutils_format_inet_addr((uint8_t *)&state.ipaddr, port, NETUTILS_BIG); + tuple->items[4] = lwip_format_inet_addr(&ipcopy, port); return mp_obj_new_list(1, (mp_obj_t *)&tuple); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lwip_getaddrinfo_obj, 2, 6, lwip_getaddrinfo); diff --git a/extmod/network_cyw43.c b/extmod/network_cyw43.c index f8490d6b9a9cd..2f188dbad4cee 100644 --- a/extmod/network_cyw43.c +++ b/extmod/network_cyw43.c @@ -78,13 +78,14 @@ STATIC void network_cyw43_print(const mp_print_t *print, mp_obj_t self_in, mp_pr } else { status_str = "fail"; } + ip4_addr_t *addr = ip_2_ip4(&netif->ip_addr); mp_printf(print, "", self->itf == CYW43_ITF_STA ? "STA" : "AP", status_str, - netif->ip_addr.addr & 0xff, - netif->ip_addr.addr >> 8 & 0xff, - netif->ip_addr.addr >> 16 & 0xff, - netif->ip_addr.addr >> 24 + addr->addr & 0xff, + addr->addr >> 8 & 0xff, + addr->addr >> 16 & 0xff, + addr->addr >> 24 ); } diff --git a/shared/netutils/dhcpserver.c b/shared/netutils/dhcpserver.c index dca95507d3f01..9a4d461a93f55 100644 --- a/shared/netutils/dhcpserver.c +++ b/shared/netutils/dhcpserver.c @@ -113,7 +113,7 @@ static void dhcp_socket_free(struct udp_pcb **udp) { static int dhcp_socket_bind(struct udp_pcb **udp, uint32_t ip, uint16_t port) { ip_addr_t addr; - IP4_ADDR(&addr, ip >> 24 & 0xff, ip >> 16 & 0xff, ip >> 8 & 0xff, ip & 0xff); + IP_ADDR4(&addr, ip >> 24 & 0xff, ip >> 16 & 0xff, ip >> 8 & 0xff, ip & 0xff); // TODO convert lwIP errors to errno return udp_bind(*udp, &addr, port); } @@ -131,7 +131,7 @@ static int dhcp_socket_sendto(struct udp_pcb **udp, struct netif *netif, const v memcpy(p->payload, buf, len); ip_addr_t dest; - IP4_ADDR(&dest, ip >> 24 & 0xff, ip >> 16 & 0xff, ip >> 8 & 0xff, ip & 0xff); + IP_ADDR4(&dest, ip >> 24 & 0xff, ip >> 16 & 0xff, ip >> 8 & 0xff, ip & 0xff); err_t err; if (netif != NULL) { err = udp_sendto_if(*udp, p, &dest, port, netif); @@ -205,7 +205,7 @@ static void dhcp_server_process(void *arg, struct udp_pcb *upcb, struct pbuf *p, } dhcp_msg.op = DHCPOFFER; - memcpy(&dhcp_msg.yiaddr, &d->ip.addr, 4); + memcpy(&dhcp_msg.yiaddr, &ip_2_ip4(&d->ip)->addr, 4); uint8_t *opt = (uint8_t *)&dhcp_msg.options; opt += 4; // assume magic cookie: 99, 130, 83, 99 @@ -248,7 +248,7 @@ static void dhcp_server_process(void *arg, struct udp_pcb *upcb, struct pbuf *p, // Should be NACK goto ignore_request; } - if (memcmp(o + 2, &d->ip.addr, 3) != 0) { + if (memcmp(o + 2, &ip_2_ip4(&d->ip)->addr, 3) != 0) { // Should be NACK goto ignore_request; } @@ -280,9 +280,9 @@ static void dhcp_server_process(void *arg, struct udp_pcb *upcb, struct pbuf *p, goto ignore_request; } - opt_write_n(&opt, DHCP_OPT_SERVER_ID, 4, &d->ip.addr); - opt_write_n(&opt, DHCP_OPT_SUBNET_MASK, 4, &d->nm.addr); - opt_write_n(&opt, DHCP_OPT_ROUTER, 4, &d->ip.addr); // aka gateway; can have multiple addresses + opt_write_n(&opt, DHCP_OPT_SERVER_ID, 4, &ip_2_ip4(&d->ip)->addr); + opt_write_n(&opt, DHCP_OPT_SUBNET_MASK, 4, &ip_2_ip4(&d->nm)->addr); + opt_write_n(&opt, DHCP_OPT_ROUTER, 4, &ip_2_ip4(&d->ip)->addr); // aka gateway; can have multiple addresses opt_write_u32(&opt, DHCP_OPT_DNS, DEFAULT_DNS); // can have multiple addresses opt_write_u32(&opt, DHCP_OPT_IP_LEASE_TIME, DEFAULT_LEASE_TIME_S); *opt++ = DHCP_OPT_END; From 223e0d9a5b116246bda1621201e77945ac5746fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20D=C3=B6rre?= Date: Thu, 25 Aug 2022 18:02:43 +0000 Subject: [PATCH 132/408] extmod/network_wiznet5k: Adjust IP types for IPv6. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Felix Dörre --- extmod/network_wiznet5k.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/extmod/network_wiznet5k.c b/extmod/network_wiznet5k.c index d49ee8614e710..d4841e0176dcb 100644 --- a/extmod/network_wiznet5k.c +++ b/extmod/network_wiznet5k.c @@ -305,11 +305,11 @@ STATIC err_t wiznet5k_netif_init(struct netif *netif) { STATIC void wiznet5k_lwip_init(wiznet5k_obj_t *self) { ip_addr_t ipconfig[4]; - ipconfig[0].addr = 0; - ipconfig[1].addr = 0; - ipconfig[2].addr = 0; - ipconfig[3].addr = 0; - netif_add(&self->netif, &ipconfig[0], &ipconfig[1], &ipconfig[2], self, wiznet5k_netif_init, ethernet_input); + IP_ADDR4(&ipconfig[0], 0, 0, 0, 0); + IP_ADDR4(&ipconfig[1], 0, 0, 0, 0); + IP_ADDR4(&ipconfig[2], 0, 0, 0, 0); + IP_ADDR4(&ipconfig[3], 0, 0, 0, 0); + netif_add(&self->netif, ip_2_ip4(&ipconfig[0]), ip_2_ip4(&ipconfig[1]), ip_2_ip4(&ipconfig[2]), self, wiznet5k_netif_init, ethernet_input); self->netif.name[0] = 'e'; self->netif.name[1] = '0'; netif_set_default(&self->netif); @@ -802,7 +802,7 @@ STATIC mp_obj_t wiznet5k_isconnected(mp_obj_t self_in) { wizphy_getphylink() == PHY_LINK_ON && IS_ACTIVE(self) #if WIZNET5K_WITH_LWIP_STACK - && self->netif.ip_addr.addr != 0 + && ip_2_ip4(&self->netif.ip_addr)->addr != 0 #endif ); } From 39bf055d23be4b0f761af115773c3db1074fc2dd Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 9 Feb 2024 13:25:58 +1100 Subject: [PATCH 133/408] py/emitglue: Reorder and resize members of mp_raw_code_t. The mp_raw_code_t struct has been reordered and some members resized. The `n_pos_args` member is renamed to `asm_n_pos_args`, and `type_sig` renamed to `asm_type_sig` to indicate that these are used only for the inline-asm emitters. These two members are also grouped together in the struct. The justifications for resizing the members are: - `fun_data_len` can be 32-bits without issue - `n_children` is already limited to 16-bits by `mp_emit_common_t::ct_cur_child` - `scope_flags` is already limited to 16-bits by `scope_t::scope_flags` - `prelude_offset` is already limited to 16-bits by the argument to `mp_emit_glue_assign_native()` - it's reasonable to limit the maximim number of inline-asm arguments to 12 (24 bits for `asm_type_sig` divided by 2) This change helps to reduce frozen code size (and in some cases RAM usage) in the following cases: - 64-bit targets - builds with MICROPY_PY_SYS_SETTRACE enabled - builds with MICROPY_EMIT_MACHINE_CODE enabled but MICROPY_EMIT_INLINE_ASM disabled With this change, unix 64-bit builds are -4080 bytes in size. Bare-metal ports like rp2 are unchanged (because mp_raw_code_t is still 32 bytes on those 32-bit targets). Signed-off-by: Damien George --- py/emitglue.c | 17 ++++++++++------- py/emitglue.h | 38 +++++++++++++++++++++----------------- py/persistentcode.c | 6 ++++-- tools/mpy-tool.py | 20 ++++++++++---------- 4 files changed, 45 insertions(+), 36 deletions(-) diff --git a/py/emitglue.c b/py/emitglue.c index 6ec6d6b885d4d..0ec126fe94608 100644 --- a/py/emitglue.c +++ b/py/emitglue.c @@ -66,9 +66,9 @@ void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code, #endif mp_raw_code_t **children, #if MICROPY_PERSISTENT_CODE_SAVE - size_t n_children, + uint16_t n_children, #endif - mp_uint_t scope_flags) { + uint16_t scope_flags) { rc->kind = MP_CODE_BYTECODE; rc->scope_flags = scope_flags; @@ -99,10 +99,11 @@ void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code, void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void *fun_data, mp_uint_t fun_len, mp_raw_code_t **children, #if MICROPY_PERSISTENT_CODE_SAVE - size_t n_children, + uint16_t n_children, uint16_t prelude_offset, #endif - mp_uint_t scope_flags, mp_uint_t n_pos_args, mp_uint_t type_sig) { + uint16_t scope_flags, uint32_t asm_n_pos_args, uint32_t asm_type_sig + ) { assert(kind == MP_CODE_NATIVE_PY || kind == MP_CODE_NATIVE_VIPER || kind == MP_CODE_NATIVE_ASM); @@ -145,9 +146,11 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void rc->prelude_offset = prelude_offset; #endif + #if MICROPY_EMIT_INLINE_ASM // These two entries are only needed for MP_CODE_NATIVE_ASM. - rc->n_pos_args = n_pos_args; - rc->type_sig = type_sig; + rc->asm_n_pos_args = asm_n_pos_args; + rc->asm_type_sig = asm_type_sig; + #endif #if DEBUG_PRINT DEBUG_printf("assign native: kind=%d fun=%p len=" UINT_FMT " n_pos_args=" UINT_FMT " flags=%x\n", kind, fun_data, fun_len, n_pos_args, (uint)scope_flags); @@ -195,7 +198,7 @@ mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, const mp_module #endif #if MICROPY_EMIT_INLINE_ASM case MP_CODE_NATIVE_ASM: - fun = mp_obj_new_fun_asm(rc->n_pos_args, rc->fun_data, rc->type_sig); + fun = mp_obj_new_fun_asm(rc->asm_n_pos_args, rc->fun_data, rc->asm_type_sig); break; #endif default: diff --git a/py/emitglue.h b/py/emitglue.h index 4ddf74011fa70..c9c6c8ba1de93 100644 --- a/py/emitglue.h +++ b/py/emitglue.h @@ -49,34 +49,38 @@ typedef enum { MP_CODE_NATIVE_ASM, } mp_raw_code_kind_t; +// This mp_raw_code_t struct holds static information about a non-instantiated function. +// A function object is created from this information, and that object can then be executed. +// +// This struct appears in the following places: // compiled bytecode: instance in RAM, referenced by outer scope, usually freed after first (and only) use // mpy file: instance in RAM, created when .mpy file is loaded (same comments as above) // frozen: instance in ROM typedef struct _mp_raw_code_t { - mp_uint_t kind : 3; // of type mp_raw_code_kind_t - mp_uint_t scope_flags : 7; - mp_uint_t n_pos_args : 11; + uint32_t kind : 3; // of type mp_raw_code_kind_t + uint32_t scope_flags : 7; const void *fun_data; + struct _mp_raw_code_t **children; #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS - size_t fun_data_len; // so mp_raw_code_save and mp_bytecode_print work + uint32_t fun_data_len; // so mp_raw_code_save and mp_bytecode_print work #endif - struct _mp_raw_code_t **children; #if MICROPY_PERSISTENT_CODE_SAVE - size_t n_children; + uint16_t n_children; + #if MICROPY_EMIT_MACHINE_CODE + uint16_t prelude_offset; + #endif #if MICROPY_PY_SYS_SETTRACE - mp_bytecode_prelude_t prelude; // line_of_definition is a Python source line where the raw_code was // created e.g. MP_BC_MAKE_FUNCTION. This is different from lineno info // stored in prelude, which provides line number for first statement of // a function. Required to properly implement "call" trace event. - mp_uint_t line_of_definition; - #endif - #if MICROPY_EMIT_MACHINE_CODE - uint16_t prelude_offset; + uint32_t line_of_definition; + mp_bytecode_prelude_t prelude; #endif #endif - #if MICROPY_EMIT_MACHINE_CODE - mp_uint_t type_sig; // for viper, compressed as 2-bit types; ret is MSB, then arg0, arg1, etc + #if MICROPY_EMIT_INLINE_ASM + uint32_t asm_n_pos_args : 8; + uint32_t asm_type_sig : 24; // compressed as 2-bit types; ret is MSB, then arg0, arg1, etc #endif } mp_raw_code_t; @@ -88,17 +92,17 @@ void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code, #endif mp_raw_code_t **children, #if MICROPY_PERSISTENT_CODE_SAVE - size_t n_children, + uint16_t n_children, #endif - mp_uint_t scope_flags); + uint16_t scope_flags); void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void *fun_data, mp_uint_t fun_len, mp_raw_code_t **children, #if MICROPY_PERSISTENT_CODE_SAVE - size_t n_children, + uint16_t n_children, uint16_t prelude_offset, #endif - mp_uint_t scope_flags, mp_uint_t n_pos_args, mp_uint_t type_sig); + uint16_t scope_flags, uint32_t asm_n_pos_args, uint32_t asm_type_sig); mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, const mp_module_context_t *context, const mp_obj_t *def_args); mp_obj_t mp_make_closure_from_raw_code(const mp_raw_code_t *rc, const mp_module_context_t *context, mp_uint_t n_closed_over, const mp_obj_t *args); diff --git a/py/persistentcode.c b/py/persistentcode.c index df1003babfa1d..83806febb3650 100644 --- a/py/persistentcode.c +++ b/py/persistentcode.c @@ -578,10 +578,12 @@ STATIC void save_raw_code(mp_print_t *print, const mp_raw_code_t *rc) { } else if (rc->kind == MP_CODE_NATIVE_VIPER || rc->kind == MP_CODE_NATIVE_ASM) { // Save basic scope info for viper and asm mp_print_uint(print, rc->scope_flags & MP_SCOPE_FLAG_ALL_SIG); + #if MICROPY_EMIT_INLINE_ASM if (rc->kind == MP_CODE_NATIVE_ASM) { - mp_print_uint(print, rc->n_pos_args); - mp_print_uint(print, rc->type_sig); + mp_print_uint(print, rc->asm_n_pos_args); + mp_print_uint(print, rc->asm_type_sig); } + #endif } #endif diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py index a656cccd69d0f..57411c3fbcdbc 100755 --- a/tools/mpy-tool.py +++ b/tools/mpy-tool.py @@ -909,21 +909,24 @@ def freeze_raw_code(self, prelude_ptr=None, type_sig=0): print("static const mp_raw_code_t raw_code_%s = {" % self.escaped_name) print(" .kind = %s," % RawCode.code_kind_str[self.code_kind]) print(" .scope_flags = 0x%02x," % self.scope_flags) - print(" .n_pos_args = %u," % self.n_pos_args) print(" .fun_data = fun_data_%s," % self.escaped_name) - print(" #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS") - print(" .fun_data_len = %u," % len(self.fun_data)) - print(" #endif") if len(self.children): print(" .children = (void *)&children_%s," % self.escaped_name) elif prelude_ptr: print(" .children = (void *)%s," % prelude_ptr) else: print(" .children = NULL,") + print(" #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS") + print(" .fun_data_len = %u," % len(self.fun_data)) + print(" #endif") print(" #if MICROPY_PERSISTENT_CODE_SAVE") print(" .n_children = %u," % len(self.children)) + print(" #if MICROPY_EMIT_MACHINE_CODE") + print(" .prelude_offset = %u," % self.prelude_offset) + print(" #endif") if self.code_kind == MP_CODE_BYTECODE: print(" #if MICROPY_PY_SYS_SETTRACE") + print(" .line_of_definition = %u," % 0) # TODO print(" .prelude = {") print(" .n_state = %u," % self.prelude_signature[0]) print(" .n_exc_stack = %u," % self.prelude_signature[1]) @@ -944,14 +947,11 @@ def freeze_raw_code(self, prelude_ptr=None, type_sig=0): " .opcodes = fun_data_%s + %u," % (self.escaped_name, self.offset_opcodes) ) print(" },") - print(" .line_of_definition = %u," % 0) # TODO print(" #endif") - print(" #if MICROPY_EMIT_MACHINE_CODE") - print(" .prelude_offset = %u," % self.prelude_offset) - print(" #endif") print(" #endif") - print(" #if MICROPY_EMIT_MACHINE_CODE") - print(" .type_sig = %u," % type_sig) + print(" #if MICROPY_EMIT_INLINE_ASM") + print(" .asm_n_pos_args = %u," % self.n_pos_args) + print(" .asm_type_sig = %u," % type_sig) print(" #endif") print("};") From 416465d81e911b088836f4e7c37fac2bc0f67917 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 9 Feb 2024 13:25:58 +1100 Subject: [PATCH 134/408] py/emitglue: Provide a truncated mp_raw_code_t for non-asm code. The `asm_n_pos_args` and `asm_type_sig` members of `mp_raw_code_t` are only used for raw codes of type MP_CODE_NATIVE_ASM, which are rare, for example in frozen code. So using a truncated `mp_raw_code_t` in these cases helps to reduce frozen code size on targets that have MICROPY_EMIT_INLINE_ASM enabled. With this, change in firmware size of RPI_PICO builds is -648. Signed-off-by: Damien George --- py/dynruntime.h | 4 ++-- py/emitglue.h | 23 +++++++++++++++++++++++ tools/mpy-tool.py | 17 ++++++++++------- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/py/dynruntime.h b/py/dynruntime.h index de9c93c65924b..435b85622a981 100644 --- a/py/dynruntime.h +++ b/py/dynruntime.h @@ -207,7 +207,7 @@ static inline void *mp_obj_malloc_helper_dyn(size_t num_bytes, const mp_obj_type #define MP_DYNRUNTIME_INIT_ENTRY \ mp_obj_t old_globals = mp_fun_table.swap_globals(self->context->module.globals); \ - mp_raw_code_t rc; \ + mp_raw_code_truncated_t rc; \ rc.kind = MP_CODE_NATIVE_VIPER; \ rc.scope_flags = 0; \ (void)rc; @@ -217,7 +217,7 @@ static inline void *mp_obj_malloc_helper_dyn(size_t num_bytes, const mp_obj_type return mp_const_none; #define MP_DYNRUNTIME_MAKE_FUNCTION(f) \ - (mp_make_function_from_raw_code((rc.fun_data = (f), &rc), self->context, NULL)) + (mp_make_function_from_raw_code((rc.fun_data = (f), (const mp_raw_code_t *)&rc), self->context, NULL)) #define mp_import_name(name, fromlist, level) \ (mp_fun_table.import_name((name), (fromlist), (level))) diff --git a/py/emitglue.h b/py/emitglue.h index c9c6c8ba1de93..b79283541bf04 100644 --- a/py/emitglue.h +++ b/py/emitglue.h @@ -84,6 +84,29 @@ typedef struct _mp_raw_code_t { #endif } mp_raw_code_t; +// Version of mp_raw_code_t but without the asm_n_pos_args/asm_type_sig entries, which are +// only needed when the kind is MP_CODE_NATIVE_ASM. So this struct can be used when the +// kind is MP_CODE_BYTECODE, MP_CODE_NATIVE_PY or MP_CODE_NATIVE_VIPER, to reduce its size. +typedef struct _mp_raw_code_truncated_t { + uint32_t kind : 3; + uint32_t scope_flags : 7; + const void *fun_data; + struct _mp_raw_code_t **children; + #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS + uint32_t fun_data_len; + #endif + #if MICROPY_PERSISTENT_CODE_SAVE + uint16_t n_children; + #if MICROPY_EMIT_MACHINE_CODE + uint16_t prelude_offset; + #endif + #if MICROPY_PY_SYS_SETTRACE + uint32_t line_of_definition; + mp_bytecode_prelude_t prelude; + #endif + #endif +} mp_raw_code_truncated_t; + mp_raw_code_t *mp_emit_glue_new_raw_code(void); void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code, diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py index 57411c3fbcdbc..9b824099ea18c 100755 --- a/tools/mpy-tool.py +++ b/tools/mpy-tool.py @@ -683,7 +683,7 @@ def freeze(self, compiled_module_index): else: print(" .obj_table = NULL,") print(" },") - print(" .rc = &raw_code_%s," % self.raw_code.escaped_name) + print(" .rc = (const mp_raw_code_t *)&raw_code_%s," % self.raw_code.escaped_name) print("};") def freeze_constant_obj(self, obj_name, obj): @@ -898,7 +898,7 @@ def freeze_children(self, prelude_ptr=None): print() print("static const mp_raw_code_t *const children_%s[] = {" % self.escaped_name) for rc in self.children: - print(" &raw_code_%s," % rc.escaped_name) + print(" (const mp_raw_code_t *)&raw_code_%s," % rc.escaped_name) if prelude_ptr: print(" (void *)%s," % prelude_ptr) print("};") @@ -906,7 +906,11 @@ def freeze_children(self, prelude_ptr=None): def freeze_raw_code(self, prelude_ptr=None, type_sig=0): # Generate mp_raw_code_t. - print("static const mp_raw_code_t raw_code_%s = {" % self.escaped_name) + if self.code_kind == MP_CODE_NATIVE_ASM: + raw_code_type = "mp_raw_code_t" + else: + raw_code_type = "mp_raw_code_truncated_t" + print("static const %s raw_code_%s = {" % (raw_code_type, self.escaped_name)) print(" .kind = %s," % RawCode.code_kind_str[self.code_kind]) print(" .scope_flags = 0x%02x," % self.scope_flags) print(" .fun_data = fun_data_%s," % self.escaped_name) @@ -949,10 +953,9 @@ def freeze_raw_code(self, prelude_ptr=None, type_sig=0): print(" },") print(" #endif") print(" #endif") - print(" #if MICROPY_EMIT_INLINE_ASM") - print(" .asm_n_pos_args = %u," % self.n_pos_args) - print(" .asm_type_sig = %u," % type_sig) - print(" #endif") + if self.code_kind == MP_CODE_NATIVE_ASM: + print(" .asm_n_pos_args = %u," % self.n_pos_args) + print(" .asm_type_sig = %u," % type_sig) print("};") global raw_code_count, raw_code_content From 5e3006f1172d0eabbbefeb3268dfb942ec7cf9cd Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 9 Feb 2024 17:38:25 +1100 Subject: [PATCH 135/408] py/emitglue: Simplify mp_raw_code_t's kind and scope_flags members. To simplify their access and reduce code size. The `scope_flags` member is only ever used to determine if a function is a generator or not, so make it reflect that fact as a bool type. Signed-off-by: Damien George --- py/dynruntime.h | 2 +- py/emitglue.c | 8 ++++---- py/emitglue.h | 8 ++++---- py/persistentcode.c | 4 +++- py/runtime0.h | 7 +++++-- tools/mpy-tool.py | 3 ++- 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/py/dynruntime.h b/py/dynruntime.h index 435b85622a981..3e660f19fda02 100644 --- a/py/dynruntime.h +++ b/py/dynruntime.h @@ -209,7 +209,7 @@ static inline void *mp_obj_malloc_helper_dyn(size_t num_bytes, const mp_obj_type mp_obj_t old_globals = mp_fun_table.swap_globals(self->context->module.globals); \ mp_raw_code_truncated_t rc; \ rc.kind = MP_CODE_NATIVE_VIPER; \ - rc.scope_flags = 0; \ + rc.is_generator = 0; \ (void)rc; #define MP_DYNRUNTIME_INIT_EXIT \ diff --git a/py/emitglue.c b/py/emitglue.c index 0ec126fe94608..c0003c5cd5563 100644 --- a/py/emitglue.c +++ b/py/emitglue.c @@ -71,7 +71,7 @@ void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code, uint16_t scope_flags) { rc->kind = MP_CODE_BYTECODE; - rc->scope_flags = scope_flags; + rc->is_generator = (scope_flags & MP_SCOPE_FLAG_GENERATOR) != 0; rc->fun_data = code; #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS rc->fun_data_len = len; @@ -133,7 +133,7 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void #endif rc->kind = kind; - rc->scope_flags = scope_flags; + rc->is_generator = (scope_flags & MP_SCOPE_FLAG_GENERATOR) != 0; rc->fun_data = fun_data; #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS @@ -191,7 +191,7 @@ mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, const mp_module case MP_CODE_NATIVE_VIPER: fun = mp_obj_new_fun_native(def_args, rc->fun_data, context, rc->children); // Check for a generator function, and if so change the type of the object - if ((rc->scope_flags & MP_SCOPE_FLAG_GENERATOR) != 0) { + if (rc->is_generator) { ((mp_obj_base_t *)MP_OBJ_TO_PTR(fun))->type = &mp_type_native_gen_wrap; } break; @@ -206,7 +206,7 @@ mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, const mp_module assert(rc->kind == MP_CODE_BYTECODE); fun = mp_obj_new_fun_bc(def_args, rc->fun_data, context, rc->children); // check for generator functions and if so change the type of the object - if ((rc->scope_flags & MP_SCOPE_FLAG_GENERATOR) != 0) { + if (rc->is_generator) { ((mp_obj_base_t *)MP_OBJ_TO_PTR(fun))->type = &mp_type_gen_wrap; } diff --git a/py/emitglue.h b/py/emitglue.h index b79283541bf04..125ab2ccd5322 100644 --- a/py/emitglue.h +++ b/py/emitglue.h @@ -57,8 +57,8 @@ typedef enum { // mpy file: instance in RAM, created when .mpy file is loaded (same comments as above) // frozen: instance in ROM typedef struct _mp_raw_code_t { - uint32_t kind : 3; // of type mp_raw_code_kind_t - uint32_t scope_flags : 7; + uint8_t kind; // of type mp_raw_code_kind_t; only 3 bits used + bool is_generator; const void *fun_data; struct _mp_raw_code_t **children; #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS @@ -88,8 +88,8 @@ typedef struct _mp_raw_code_t { // only needed when the kind is MP_CODE_NATIVE_ASM. So this struct can be used when the // kind is MP_CODE_BYTECODE, MP_CODE_NATIVE_PY or MP_CODE_NATIVE_VIPER, to reduce its size. typedef struct _mp_raw_code_truncated_t { - uint32_t kind : 3; - uint32_t scope_flags : 7; + uint8_t kind; + bool is_generator; const void *fun_data; struct _mp_raw_code_t **children; #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS diff --git a/py/persistentcode.c b/py/persistentcode.c index 83806febb3650..7b002e7fcfc2f 100644 --- a/py/persistentcode.c +++ b/py/persistentcode.c @@ -577,7 +577,9 @@ STATIC void save_raw_code(mp_print_t *print, const mp_raw_code_t *rc) { mp_print_uint(print, rc->prelude_offset); } else if (rc->kind == MP_CODE_NATIVE_VIPER || rc->kind == MP_CODE_NATIVE_ASM) { // Save basic scope info for viper and asm - mp_print_uint(print, rc->scope_flags & MP_SCOPE_FLAG_ALL_SIG); + // Viper/asm functions don't support generator, variable args, or default keyword args + // so (scope_flags & MP_SCOPE_FLAG_ALL_SIG) for these functions is always 0. + mp_print_uint(print, 0); #if MICROPY_EMIT_INLINE_ASM if (rc->kind == MP_CODE_NATIVE_ASM) { mp_print_uint(print, rc->asm_n_pos_args); diff --git a/py/runtime0.h b/py/runtime0.h index 69af38ddcb88e..9c6f0e079fb5a 100644 --- a/py/runtime0.h +++ b/py/runtime0.h @@ -26,8 +26,11 @@ #ifndef MICROPY_INCLUDED_PY_RUNTIME0_H #define MICROPY_INCLUDED_PY_RUNTIME0_H -// The first four must fit in 8 bits, see emitbc.c -// The remaining must fit in 16 bits, see scope.h +// These constants are used by: +// - mp_raw_code_t::is_generator (only MP_SCOPE_FLAG_GENERATOR) +// - scope_t::scope_flags (16 bits) +// - MP_BC_PRELUDE_SIG_ENCODE macro, masked by MP_SCOPE_FLAG_ALL_SIG (4 bits) +// - tools/mpy_ld.py, when generating mpy files (maximum 7 bits) #define MP_SCOPE_FLAG_ALL_SIG (0x0f) #define MP_SCOPE_FLAG_GENERATOR (0x01) #define MP_SCOPE_FLAG_VARKEYWORDS (0x02) diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py index 9b824099ea18c..744800c6704ca 100755 --- a/tools/mpy-tool.py +++ b/tools/mpy-tool.py @@ -126,6 +126,7 @@ class Config: MP_PERSISTENT_OBJ_COMPLEX = 9 MP_PERSISTENT_OBJ_TUPLE = 10 +MP_SCOPE_FLAG_GENERATOR = 0x01 MP_SCOPE_FLAG_VIPERRELOC = 0x10 MP_SCOPE_FLAG_VIPERRODATA = 0x20 MP_SCOPE_FLAG_VIPERBSS = 0x40 @@ -912,7 +913,7 @@ def freeze_raw_code(self, prelude_ptr=None, type_sig=0): raw_code_type = "mp_raw_code_truncated_t" print("static const %s raw_code_%s = {" % (raw_code_type, self.escaped_name)) print(" .kind = %s," % RawCode.code_kind_str[self.code_kind]) - print(" .scope_flags = 0x%02x," % self.scope_flags) + print(" .is_generator = %d," % bool(self.scope_flags & MP_SCOPE_FLAG_GENERATOR)) print(" .fun_data = fun_data_%s," % self.escaped_name) if len(self.children): print(" .children = (void *)&children_%s," % self.escaped_name) From e2ff00e81113d7a3f32f860652017644b5d68bf1 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 9 Feb 2024 17:41:48 +1100 Subject: [PATCH 136/408] py/emitglue: Introduce mp_proto_fun_t as a more general mp_raw_code_t. Allows bytecode itself to be used instead of an mp_raw_code_t in the simple and common cases of a bytecode function without any children. This can be used to further reduce frozen code size, and has the potential to optimise other areas like importing. Signed-off-by: Damien George --- docs/develop/compiler.rst | 2 +- ports/embed/port/embed_util.c | 2 +- py/bc.h | 6 +++--- py/builtinimport.c | 8 ++++---- py/compile.c | 2 +- py/dynruntime.h | 8 +++++--- py/emitglue.c | 17 ++++++++++------- py/emitglue.h | 27 ++++++++++++++++++++++----- py/emitnative.c | 4 ++-- py/emitnx86.c | 2 +- py/nativeglue.c | 2 +- py/nativeglue.h | 4 ++-- py/vm.c | 8 ++++---- shared/runtime/pyexec.c | 2 +- tools/mpy-tool.py | 8 +++++--- 15 files changed, 63 insertions(+), 39 deletions(-) diff --git a/docs/develop/compiler.rst b/docs/develop/compiler.rst index cac92585ff4ee..00cc90f8163a1 100644 --- a/docs/develop/compiler.rst +++ b/docs/develop/compiler.rst @@ -157,7 +157,7 @@ The most relevant method you should know about is this: mp_compile_to_raw_code(parse_tree, source_file, is_repl, &cm); // Create and return a function object that executes the outer module. - return mp_make_function_from_raw_code(cm.rc, cm.context, NULL); + return mp_make_function_from_proto_fun(cm.rc, cm.context, NULL); } The compiler compiles the code in four passes: scope, stack size, code size and emit. diff --git a/ports/embed/port/embed_util.c b/ports/embed/port/embed_util.c index c5bc8c973bb02..70a07dc4297f2 100644 --- a/ports/embed/port/embed_util.c +++ b/ports/embed/port/embed_util.c @@ -69,7 +69,7 @@ void mp_embed_exec_mpy(const uint8_t *mpy, size_t len) { mp_compiled_module_t cm; cm.context = ctx; mp_raw_code_load_mem(mpy, len, &cm); - mp_obj_t f = mp_make_function_from_raw_code(cm.rc, ctx, MP_OBJ_NULL); + mp_obj_t f = mp_make_function_from_proto_fun(cm.rc, ctx, MP_OBJ_NULL); mp_call_function_0(f); nlr_pop(); } else { diff --git a/py/bc.h b/py/bc.h index 0e23255f764f4..a1ab7918f2e02 100644 --- a/py/bc.h +++ b/py/bc.h @@ -44,11 +44,11 @@ // prelude size : var uint // contains two values interleaved bit-wise as: xIIIIIIC repeated // x = extension another byte follows -// I = n_info number of bytes in source info section +// I = n_info number of bytes in source info section (always > 0) // C = n_cells number of bytes/cells in closure section // // source info section: -// simple_name : var qstr +// simple_name : var qstr always exists // argname0 : var qstr // ... : var qstr // argnameN : var qstr N = num_pos_args + num_kwonly_args - 1 @@ -226,7 +226,7 @@ typedef struct _mp_compiled_module_t { // Outer level struct defining a frozen module. typedef struct _mp_frozen_module_t { const mp_module_constants_t constants; - const struct _mp_raw_code_t *rc; + const void *proto_fun; } mp_frozen_module_t; // State for an executing function. diff --git a/py/builtinimport.c b/py/builtinimport.c index 3cc117befaad6..002a5cb853529 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -165,7 +165,7 @@ STATIC void do_load_from_lexer(mp_module_context_t *context, mp_lexer_t *lex) { #endif #if (MICROPY_HAS_FILE_READER && MICROPY_PERSISTENT_CODE_LOAD) || MICROPY_MODULE_FROZEN_MPY -STATIC void do_execute_raw_code(const mp_module_context_t *context, const mp_raw_code_t *rc, qstr source_name) { +STATIC void do_execute_proto_fun(const mp_module_context_t *context, mp_proto_fun_t proto_fun, qstr source_name) { #if MICROPY_PY___FILE__ mp_store_attr(MP_OBJ_FROM_PTR(&context->module), MP_QSTR___file__, MP_OBJ_NEW_QSTR(source_name)); #else @@ -188,7 +188,7 @@ STATIC void do_execute_raw_code(const mp_module_context_t *context, const mp_raw nlr_push_jump_callback(&ctx.callback, mp_globals_locals_set_from_nlr_jump_callback); // make and execute the function - mp_obj_t module_fun = mp_make_function_from_raw_code(rc, context, NULL); + mp_obj_t module_fun = mp_make_function_from_proto_fun(proto_fun, context, NULL); mp_call_function_0(module_fun); // deregister exception handler and restore context @@ -230,7 +230,7 @@ STATIC void do_load(mp_module_context_t *module_obj, vstr_t *file) { #else qstr frozen_file_qstr = MP_QSTRnull; #endif - do_execute_raw_code(module_obj, frozen->rc, frozen_file_qstr); + do_execute_proto_fun(module_obj, frozen->proto_fun, frozen_file_qstr); return; } #endif @@ -247,7 +247,7 @@ STATIC void do_load(mp_module_context_t *module_obj, vstr_t *file) { mp_compiled_module_t cm; cm.context = module_obj; mp_raw_code_load_file(file_qstr, &cm); - do_execute_raw_code(cm.context, cm.rc, file_qstr); + do_execute_proto_fun(cm.context, cm.rc, file_qstr); return; } #endif diff --git a/py/compile.c b/py/compile.c index a9b34ce5d91bd..ad8cffc9d5d7c 100644 --- a/py/compile.c +++ b/py/compile.c @@ -3667,7 +3667,7 @@ mp_obj_t mp_compile(mp_parse_tree_t *parse_tree, qstr source_file, bool is_repl) cm.context->module.globals = mp_globals_get(); mp_compile_to_raw_code(parse_tree, source_file, is_repl, &cm); // return function that executes the outer module - return mp_make_function_from_raw_code(cm.rc, cm.context, NULL); + return mp_make_function_from_proto_fun(cm.rc, cm.context, NULL); } #endif // MICROPY_ENABLE_COMPILER diff --git a/py/dynruntime.h b/py/dynruntime.h index 3e660f19fda02..7765fca40d598 100644 --- a/py/dynruntime.h +++ b/py/dynruntime.h @@ -196,8 +196,8 @@ static inline void *mp_obj_malloc_helper_dyn(size_t num_bytes, const mp_obj_type #define mp_unary_op(op, obj) (mp_fun_table.unary_op((op), (obj))) #define mp_binary_op(op, lhs, rhs) (mp_fun_table.binary_op((op), (lhs), (rhs))) -#define mp_make_function_from_raw_code(rc, context, def_args) \ - (mp_fun_table.make_function_from_raw_code((rc), (context), (def_args))) +#define mp_make_function_from_proto_fun(rc, context, def_args) \ + (mp_fun_table.make_function_from_proto_fun((rc), (context), (def_args))) #define mp_call_function_n_kw(fun, n_args, n_kw, args) \ (mp_fun_table.call_function_n_kw((fun), (n_args) | ((n_kw) << 8), args)) @@ -208,6 +208,8 @@ static inline void *mp_obj_malloc_helper_dyn(size_t num_bytes, const mp_obj_type #define MP_DYNRUNTIME_INIT_ENTRY \ mp_obj_t old_globals = mp_fun_table.swap_globals(self->context->module.globals); \ mp_raw_code_truncated_t rc; \ + rc.proto_fun_indicator[0] = MP_PROTO_FUN_INDICATOR_RAW_CODE_0; \ + rc.proto_fun_indicator[1] = MP_PROTO_FUN_INDICATOR_RAW_CODE_1; \ rc.kind = MP_CODE_NATIVE_VIPER; \ rc.is_generator = 0; \ (void)rc; @@ -217,7 +219,7 @@ static inline void *mp_obj_malloc_helper_dyn(size_t num_bytes, const mp_obj_type return mp_const_none; #define MP_DYNRUNTIME_MAKE_FUNCTION(f) \ - (mp_make_function_from_raw_code((rc.fun_data = (f), (const mp_raw_code_t *)&rc), self->context, NULL)) + (mp_make_function_from_proto_fun((rc.fun_data = (f), (const mp_raw_code_t *)&rc), self->context, NULL)) #define mp_import_name(name, fromlist, level) \ (mp_fun_table.import_name((name), (fromlist), (level))) diff --git a/py/emitglue.c b/py/emitglue.c index c0003c5cd5563..1c7e013294b1f 100644 --- a/py/emitglue.c +++ b/py/emitglue.c @@ -173,9 +173,9 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void } #endif -mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, const mp_module_context_t *context, const mp_obj_t *def_args) { - DEBUG_OP_printf("make_function_from_raw_code %p\n", rc); - assert(rc != NULL); +mp_obj_t mp_make_function_from_proto_fun(mp_proto_fun_t proto_fun, const mp_module_context_t *context, const mp_obj_t *def_args) { + DEBUG_OP_printf("make_function_from_proto_fun %p\n", proto_fun); + assert(proto_fun != NULL); // def_args must be MP_OBJ_NULL or a tuple assert(def_args == NULL || def_args[0] == MP_OBJ_NULL || mp_obj_is_type(def_args[0], &mp_type_tuple)); @@ -183,6 +183,9 @@ mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, const mp_module // def_kw_args must be MP_OBJ_NULL or a dict assert(def_args == NULL || def_args[1] == MP_OBJ_NULL || mp_obj_is_type(def_args[1], &mp_type_dict)); + // the proto-function is a mp_raw_code_t + const mp_raw_code_t *rc = proto_fun; + // make the function, depending on the raw code kind mp_obj_t fun; switch (rc->kind) { @@ -221,16 +224,16 @@ mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, const mp_module return fun; } -mp_obj_t mp_make_closure_from_raw_code(const mp_raw_code_t *rc, const mp_module_context_t *context, mp_uint_t n_closed_over, const mp_obj_t *args) { - DEBUG_OP_printf("make_closure_from_raw_code %p " UINT_FMT " %p\n", rc, n_closed_over, args); +mp_obj_t mp_make_closure_from_proto_fun(mp_proto_fun_t proto_fun, const mp_module_context_t *context, mp_uint_t n_closed_over, const mp_obj_t *args) { + DEBUG_OP_printf("make_closure_from_proto_fun %p " UINT_FMT " %p\n", proto_fun, n_closed_over, args); // make function object mp_obj_t ffun; if (n_closed_over & 0x100) { // default positional and keyword args given - ffun = mp_make_function_from_raw_code(rc, context, args); + ffun = mp_make_function_from_proto_fun(proto_fun, context, args); } else { // default positional and keyword args not given - ffun = mp_make_function_from_raw_code(rc, context, NULL); + ffun = mp_make_function_from_proto_fun(proto_fun, context, NULL); } // wrap function in closure object return mp_obj_new_closure(ffun, n_closed_over & 0xff, args + ((n_closed_over >> 7) & 2)); diff --git a/py/emitglue.h b/py/emitglue.h index 125ab2ccd5322..b1c10a1ee4f07 100644 --- a/py/emitglue.h +++ b/py/emitglue.h @@ -31,6 +31,11 @@ // These variables and functions glue the code emitters to the runtime. +// Used with mp_raw_code_t::proto_fun_indicator to detect if a mp_proto_fun_t is a +// mp_raw_code_t struct or a direct pointer to bytecode. +#define MP_PROTO_FUN_INDICATOR_RAW_CODE_0 (0) +#define MP_PROTO_FUN_INDICATOR_RAW_CODE_1 (0) + // These must fit in 8 bits; see scope.h enum { MP_EMIT_OPT_NONE, @@ -49,14 +54,25 @@ typedef enum { MP_CODE_NATIVE_ASM, } mp_raw_code_kind_t; -// This mp_raw_code_t struct holds static information about a non-instantiated function. +// An mp_proto_fun_t points to static information about a non-instantiated function. // A function object is created from this information, and that object can then be executed. -// -// This struct appears in the following places: +// It points either to bytecode, or an mp_raw_code_t struct. +typedef const void *mp_proto_fun_t; + +// Bytecode is distinguished from an mp_raw_code_t struct by the first two bytes: bytecode +// is guaranteed to have either its first or second byte non-zero. So if both bytes are +// zero then the mp_proto_fun_t pointer must be an mp_raw_code_t. +static inline bool mp_proto_fun_is_bytecode(mp_proto_fun_t proto_fun) { + const uint8_t *header = proto_fun; + return (header[0] | (header[1] << 8)) != (MP_PROTO_FUN_INDICATOR_RAW_CODE_0 | (MP_PROTO_FUN_INDICATOR_RAW_CODE_1 << 8)); +} + +// The mp_raw_code_t struct appears in the following places: // compiled bytecode: instance in RAM, referenced by outer scope, usually freed after first (and only) use // mpy file: instance in RAM, created when .mpy file is loaded (same comments as above) // frozen: instance in ROM typedef struct _mp_raw_code_t { + uint8_t proto_fun_indicator[2]; uint8_t kind; // of type mp_raw_code_kind_t; only 3 bits used bool is_generator; const void *fun_data; @@ -88,6 +104,7 @@ typedef struct _mp_raw_code_t { // only needed when the kind is MP_CODE_NATIVE_ASM. So this struct can be used when the // kind is MP_CODE_BYTECODE, MP_CODE_NATIVE_PY or MP_CODE_NATIVE_VIPER, to reduce its size. typedef struct _mp_raw_code_truncated_t { + uint8_t proto_fun_indicator[2]; uint8_t kind; bool is_generator; const void *fun_data; @@ -127,7 +144,7 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void #endif uint16_t scope_flags, uint32_t asm_n_pos_args, uint32_t asm_type_sig); -mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, const mp_module_context_t *context, const mp_obj_t *def_args); -mp_obj_t mp_make_closure_from_raw_code(const mp_raw_code_t *rc, const mp_module_context_t *context, mp_uint_t n_closed_over, const mp_obj_t *args); +mp_obj_t mp_make_function_from_proto_fun(mp_proto_fun_t proto_fun, const mp_module_context_t *context, const mp_obj_t *def_args); +mp_obj_t mp_make_closure_from_proto_fun(mp_proto_fun_t proto_fun, const mp_module_context_t *context, mp_uint_t n_closed_over, const mp_obj_t *args); #endif // MICROPY_INCLUDED_PY_EMITGLUE_H diff --git a/py/emitnative.c b/py/emitnative.c index e6357b3f9f4a8..5f347799e1d9f 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -2657,7 +2657,7 @@ STATIC void emit_native_make_function(emit_t *emit, scope_t *scope, mp_uint_t n_ need_reg_all(emit); } emit_load_reg_with_child(emit, REG_ARG_1, scope->raw_code); - ASM_CALL_IND(emit->as, MP_F_MAKE_FUNCTION_FROM_RAW_CODE); + ASM_CALL_IND(emit->as, MP_F_MAKE_FUNCTION_FROM_PROTO_FUN); emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } @@ -2675,7 +2675,7 @@ STATIC void emit_native_make_closure(emit_t *emit, scope_t *scope, mp_uint_t n_c need_reg_all(emit); } emit_load_reg_with_child(emit, REG_ARG_1, scope->raw_code); - ASM_CALL_IND(emit->as, MP_F_MAKE_FUNCTION_FROM_RAW_CODE); + ASM_CALL_IND(emit->as, MP_F_MAKE_FUNCTION_FROM_PROTO_FUN); // make closure #if REG_ARG_1 != REG_RET diff --git a/py/emitnx86.c b/py/emitnx86.c index a9050c65d4036..cb2b7f19eac73 100644 --- a/py/emitnx86.c +++ b/py/emitnx86.c @@ -37,7 +37,7 @@ STATIC byte mp_f_n_args[MP_F_NUMBER_OF] = { [MP_F_STORE_SET] = 2, [MP_F_LIST_APPEND] = 2, [MP_F_STORE_MAP] = 3, - [MP_F_MAKE_FUNCTION_FROM_RAW_CODE] = 3, + [MP_F_MAKE_FUNCTION_FROM_PROTO_FUN] = 3, [MP_F_NATIVE_CALL_FUNCTION_N_KW] = 3, [MP_F_CALL_METHOD_N_KW] = 3, [MP_F_CALL_METHOD_N_KW_VAR] = 3, diff --git a/py/nativeglue.c b/py/nativeglue.c index 217c6b3df3b71..074b1206ee5f5 100644 --- a/py/nativeglue.c +++ b/py/nativeglue.c @@ -281,7 +281,7 @@ const mp_fun_table_t mp_fun_table = { mp_obj_set_store, mp_obj_list_append, mp_obj_dict_store, - mp_make_function_from_raw_code, + mp_make_function_from_proto_fun, mp_native_call_function_n_kw, mp_call_method_n_kw, mp_call_method_n_kw_var, diff --git a/py/nativeglue.h b/py/nativeglue.h index cf73ffbfc398e..113f5fde6528f 100644 --- a/py/nativeglue.h +++ b/py/nativeglue.h @@ -58,7 +58,7 @@ typedef enum { MP_F_STORE_SET, MP_F_LIST_APPEND, MP_F_STORE_MAP, - MP_F_MAKE_FUNCTION_FROM_RAW_CODE, + MP_F_MAKE_FUNCTION_FROM_PROTO_FUN, MP_F_NATIVE_CALL_FUNCTION_N_KW, MP_F_CALL_METHOD_N_KW, MP_F_CALL_METHOD_N_KW_VAR, @@ -112,7 +112,7 @@ typedef struct _mp_fun_table_t { void (*set_store)(mp_obj_t self_in, mp_obj_t item); mp_obj_t (*list_append)(mp_obj_t self_in, mp_obj_t arg); mp_obj_t (*dict_store)(mp_obj_t self_in, mp_obj_t key, mp_obj_t value); - mp_obj_t (*make_function_from_raw_code)(const mp_raw_code_t *rc, const mp_module_context_t *cm, const mp_obj_t *def_args); + mp_obj_t (*make_function_from_proto_fun)(mp_proto_fun_t proto_fun, const mp_module_context_t *cm, const mp_obj_t *def_args); mp_obj_t (*call_function_n_kw)(mp_obj_t fun_in, size_t n_args_kw, const mp_obj_t *args); mp_obj_t (*call_method_n_kw)(size_t n_args, size_t n_kw, const mp_obj_t *args); mp_obj_t (*call_method_n_kw_var)(bool have_self, size_t n_args_n_kw, const mp_obj_t *args); diff --git a/py/vm.c b/py/vm.c index a7902d9276732..f87e52c929845 100644 --- a/py/vm.c +++ b/py/vm.c @@ -893,7 +893,7 @@ unwind_jump:; ENTRY(MP_BC_MAKE_FUNCTION): { DECODE_PTR; - PUSH(mp_make_function_from_raw_code(ptr, code_state->fun_bc->context, NULL)); + PUSH(mp_make_function_from_proto_fun(ptr, code_state->fun_bc->context, NULL)); DISPATCH(); } @@ -901,7 +901,7 @@ unwind_jump:; DECODE_PTR; // Stack layout: def_tuple def_dict <- TOS sp -= 1; - SET_TOP(mp_make_function_from_raw_code(ptr, code_state->fun_bc->context, sp)); + SET_TOP(mp_make_function_from_proto_fun(ptr, code_state->fun_bc->context, sp)); DISPATCH(); } @@ -910,7 +910,7 @@ unwind_jump:; size_t n_closed_over = *ip++; // Stack layout: closed_overs <- TOS sp -= n_closed_over - 1; - SET_TOP(mp_make_closure_from_raw_code(ptr, code_state->fun_bc->context, n_closed_over, sp)); + SET_TOP(mp_make_closure_from_proto_fun(ptr, code_state->fun_bc->context, n_closed_over, sp)); DISPATCH(); } @@ -919,7 +919,7 @@ unwind_jump:; size_t n_closed_over = *ip++; // Stack layout: def_tuple def_dict closed_overs <- TOS sp -= 2 + n_closed_over - 1; - SET_TOP(mp_make_closure_from_raw_code(ptr, code_state->fun_bc->context, 0x100 | n_closed_over, sp)); + SET_TOP(mp_make_closure_from_proto_fun(ptr, code_state->fun_bc->context, 0x100 | n_closed_over, sp)); DISPATCH(); } diff --git a/shared/runtime/pyexec.c b/shared/runtime/pyexec.c index 9f6d9a100206e..cc2aa535042c8 100644 --- a/shared/runtime/pyexec.c +++ b/shared/runtime/pyexec.c @@ -88,7 +88,7 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input mp_module_context_t *ctx = m_new_obj(mp_module_context_t); ctx->module.globals = mp_globals_get(); ctx->constants = frozen->constants; - module_fun = mp_make_function_from_raw_code(frozen->rc, ctx, NULL); + module_fun = mp_make_function_from_proto_fun(frozen->proto_fun, ctx, NULL); } else #endif { diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py index 744800c6704ca..33e59c807a37e 100755 --- a/tools/mpy-tool.py +++ b/tools/mpy-tool.py @@ -684,7 +684,7 @@ def freeze(self, compiled_module_index): else: print(" .obj_table = NULL,") print(" },") - print(" .rc = (const mp_raw_code_t *)&raw_code_%s," % self.raw_code.escaped_name) + print(" .proto_fun = &proto_fun_%s," % self.raw_code.escaped_name) print("};") def freeze_constant_obj(self, obj_name, obj): @@ -899,7 +899,7 @@ def freeze_children(self, prelude_ptr=None): print() print("static const mp_raw_code_t *const children_%s[] = {" % self.escaped_name) for rc in self.children: - print(" (const mp_raw_code_t *)&raw_code_%s," % rc.escaped_name) + print(" (const mp_raw_code_t *)&proto_fun_%s," % rc.escaped_name) if prelude_ptr: print(" (void *)%s," % prelude_ptr) print("};") @@ -911,7 +911,9 @@ def freeze_raw_code(self, prelude_ptr=None, type_sig=0): raw_code_type = "mp_raw_code_t" else: raw_code_type = "mp_raw_code_truncated_t" - print("static const %s raw_code_%s = {" % (raw_code_type, self.escaped_name)) + print("static const %s proto_fun_%s = {" % (raw_code_type, self.escaped_name)) + print(" .proto_fun_indicator[0] = MP_PROTO_FUN_INDICATOR_RAW_CODE_0,") + print(" .proto_fun_indicator[1] = MP_PROTO_FUN_INDICATOR_RAW_CODE_1,") print(" .kind = %s," % RawCode.code_kind_str[self.code_kind]) print(" .is_generator = %d," % bool(self.scope_flags & MP_SCOPE_FLAG_GENERATOR)) print(" .fun_data = fun_data_%s," % self.escaped_name) From a3a73b64a3be5b5cc2b50444c819d81f8347d52f Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 9 Feb 2024 17:41:48 +1100 Subject: [PATCH 137/408] tools/mpy-tool.py: Skip generating frozen mp_raw_code_t when possible. This reduces frozen code size by using the bytecode directly as the `mp_proto_fun_t`. Signed-off-by: Damien George --- py/emitglue.c | 12 ++++++++++++ tools/mpy-tool.py | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/py/emitglue.c b/py/emitglue.c index 1c7e013294b1f..9d671b710ed3b 100644 --- a/py/emitglue.c +++ b/py/emitglue.c @@ -183,6 +183,18 @@ mp_obj_t mp_make_function_from_proto_fun(mp_proto_fun_t proto_fun, const mp_modu // def_kw_args must be MP_OBJ_NULL or a dict assert(def_args == NULL || def_args[1] == MP_OBJ_NULL || mp_obj_is_type(def_args[1], &mp_type_dict)); + #if MICROPY_MODULE_FROZEN_MPY + if (mp_proto_fun_is_bytecode(proto_fun)) { + const uint8_t *bc = proto_fun; + mp_obj_t fun = mp_obj_new_fun_bc(def_args, bc, context, NULL); + MP_BC_PRELUDE_SIG_DECODE(bc); + if (scope_flags & MP_SCOPE_FLAG_GENERATOR) { + ((mp_obj_base_t *)MP_OBJ_TO_PTR(fun))->type = &mp_type_gen_wrap; + } + return fun; + } + #endif + // the proto-function is a mp_raw_code_t const mp_raw_code_t *rc = proto_fun; diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py index 33e59c807a37e..38567b37e58e8 100755 --- a/tools/mpy-tool.py +++ b/tools/mpy-tool.py @@ -911,6 +911,13 @@ def freeze_raw_code(self, prelude_ptr=None, type_sig=0): raw_code_type = "mp_raw_code_t" else: raw_code_type = "mp_raw_code_truncated_t" + + empty_children = len(self.children) == 0 and prelude_ptr is None + generate_minimal = self.code_kind == MP_CODE_BYTECODE and empty_children + + if generate_minimal: + print("#if MICROPY_PERSISTENT_CODE_SAVE") + print("static const %s proto_fun_%s = {" % (raw_code_type, self.escaped_name)) print(" .proto_fun_indicator[0] = MP_PROTO_FUN_INDICATOR_RAW_CODE_0,") print(" .proto_fun_indicator[1] = MP_PROTO_FUN_INDICATOR_RAW_CODE_1,") @@ -961,6 +968,11 @@ def freeze_raw_code(self, prelude_ptr=None, type_sig=0): print(" .asm_type_sig = %u," % type_sig) print("};") + if generate_minimal: + print("#else") + print("#define proto_fun_%s fun_data_%s[0]" % (self.escaped_name, self.escaped_name)) + print("#endif") + global raw_code_count, raw_code_content raw_code_count += 1 raw_code_content += 4 * 4 From 5a3dd8c79185be07b7bf68d51ccc8f98ced59182 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 12 Feb 2024 23:07:48 +1100 Subject: [PATCH 138/408] tests/ports/unix: Add coverage test for frozen functions and generators. Signed-off-by: Damien George --- ports/unix/variants/coverage/frzmpy/frzmpy4.py | 16 ++++++++++++++++ tests/ports/unix/extra_coverage.py | 3 +++ tests/ports/unix/extra_coverage.py.exp | 2 ++ 3 files changed, 21 insertions(+) create mode 100644 ports/unix/variants/coverage/frzmpy/frzmpy4.py diff --git a/ports/unix/variants/coverage/frzmpy/frzmpy4.py b/ports/unix/variants/coverage/frzmpy/frzmpy4.py new file mode 100644 index 0000000000000..669b37535b0f7 --- /dev/null +++ b/ports/unix/variants/coverage/frzmpy/frzmpy4.py @@ -0,0 +1,16 @@ +# Test importing frozen functions. + +# A simple bytecode function with no children. +def f(): + return 1 + + +print(__name__, f()) + + +# A simple bytecode generator with no children. +def g(): + yield 2 + + +print(__name__, next(g())) diff --git a/tests/ports/unix/extra_coverage.py b/tests/ports/unix/extra_coverage.py index 0ea8f7886bfff..ec68a55508132 100644 --- a/tests/ports/unix/extra_coverage.py +++ b/tests/ports/unix/extra_coverage.py @@ -87,6 +87,9 @@ # test importing various objects import frzmpy3 +# test importing other things +import frzmpy4 + # test for MP_QSTR_NULL regression from frzqstr import returns_NULL diff --git a/tests/ports/unix/extra_coverage.py.exp b/tests/ports/unix/extra_coverage.py.exp index 3db1c5a63e54e..adffc2d5824a4 100644 --- a/tests/ports/unix/extra_coverage.py.exp +++ b/tests/ports/unix/extra_coverage.py.exp @@ -201,6 +201,8 @@ ZeroDivisionError X '\x1b' b'\x00\xff' +frzmpy4 1 +frzmpy4 2 NULL uPy a long string that is not interned From def6ad474264a677d22f62c741ef422321a4a41a Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 13 Feb 2024 10:46:11 +1100 Subject: [PATCH 139/408] py/emitglue: Include fun_data_len in mp_raw_code_t only when saving. Reduces the size of mp_raw_code_t in the case when MICROPY_DEBUG_PRINTERS is enabled. Signed-off-by: Damien George --- py/bc.h | 2 +- py/compile.c | 2 +- py/emitbc.c | 11 ++++++++--- py/emitglue.c | 12 ++++-------- py/emitglue.h | 12 +++--------- py/persistentcode.c | 4 +--- py/scope.h | 3 +++ py/showbc.c | 10 +++++----- tools/mpy-tool.py | 4 +--- 9 files changed, 27 insertions(+), 33 deletions(-) diff --git a/py/bc.h b/py/bc.h index a1ab7918f2e02..718ba4a684617 100644 --- a/py/bc.h +++ b/py/bc.h @@ -281,7 +281,7 @@ mp_vm_return_kind_t mp_execute_bytecode(mp_code_state_t *code_state, mp_code_state_t *mp_obj_fun_bc_prepare_codestate(mp_obj_t func, size_t n_args, size_t n_kw, const mp_obj_t *args); void mp_setup_code_state(mp_code_state_t *code_state, size_t n_args, size_t n_kw, const mp_obj_t *args); void mp_setup_code_state_native(mp_code_state_native_t *code_state, size_t n_args, size_t n_kw, const mp_obj_t *args); -void mp_bytecode_print(const mp_print_t *print, const struct _mp_raw_code_t *rc, const mp_module_constants_t *cm); +void mp_bytecode_print(const mp_print_t *print, const struct _mp_raw_code_t *rc, size_t fun_data_len, const mp_module_constants_t *cm); void mp_bytecode_print2(const mp_print_t *print, const byte *ip, size_t len, struct _mp_raw_code_t *const *child_table, const mp_module_constants_t *cm); const byte *mp_bytecode_print_str(const mp_print_t *print, const byte *ip_start, const byte *ip, struct _mp_raw_code_t *const *child_table, const mp_module_constants_t *cm); #define mp_bytecode_print_inst(print, code, x_table) mp_bytecode_print2(print, code, 1, x_table) diff --git a/py/compile.c b/py/compile.c index ad8cffc9d5d7c..8246a9241cad9 100644 --- a/py/compile.c +++ b/py/compile.c @@ -3625,7 +3625,7 @@ void mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr source_file, bool for (scope_t *s = comp->scope_head; s != NULL; s = s->next) { mp_raw_code_t *rc = s->raw_code; if (rc->kind == MP_CODE_BYTECODE) { - mp_bytecode_print(&mp_plat_print, rc, &cm->context->constants); + mp_bytecode_print(&mp_plat_print, rc, s->raw_code_data_len, &cm->context->constants); } } } diff --git a/py/emitbc.c b/py/emitbc.c index a07657408fabe..ca5f07085b84d 100644 --- a/py/emitbc.c +++ b/py/emitbc.c @@ -393,13 +393,18 @@ bool mp_emit_bc_end_pass(emit_t *emit) { mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("bytecode overflow")); } + #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS + size_t bytecode_len = emit->code_info_size + emit->bytecode_size; + #if MICROPY_DEBUG_PRINTERS + emit->scope->raw_code_data_len = bytecode_len; + #endif + #endif + // Bytecode is finalised, assign it to the raw code object. mp_emit_glue_assign_bytecode(emit->scope->raw_code, emit->code_base, - #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS - emit->code_info_size + emit->bytecode_size, - #endif emit->emit_common->children, #if MICROPY_PERSISTENT_CODE_SAVE + bytecode_len, emit->emit_common->ct_cur_child, #endif emit->scope->scope_flags); diff --git a/py/emitglue.c b/py/emitglue.c index 9d671b710ed3b..7dc3080870182 100644 --- a/py/emitglue.c +++ b/py/emitglue.c @@ -61,11 +61,9 @@ mp_raw_code_t *mp_emit_glue_new_raw_code(void) { } void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code, - #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS - size_t len, - #endif mp_raw_code_t **children, #if MICROPY_PERSISTENT_CODE_SAVE + size_t len, uint16_t n_children, #endif uint16_t scope_flags) { @@ -73,12 +71,10 @@ void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code, rc->kind = MP_CODE_BYTECODE; rc->is_generator = (scope_flags & MP_SCOPE_FLAG_GENERATOR) != 0; rc->fun_data = code; - #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS - rc->fun_data_len = len; - #endif rc->children = children; #if MICROPY_PERSISTENT_CODE_SAVE + rc->fun_data_len = len; rc->n_children = n_children; #endif @@ -88,7 +84,7 @@ void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code, #endif #if DEBUG_PRINT - #if !(MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS) + #if !MICROPY_PERSISTENT_CODE_SAVE const size_t len = 0; #endif DEBUG_printf("assign byte code: code=%p len=" UINT_FMT " flags=%x\n", code, len, (uint)scope_flags); @@ -136,7 +132,7 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void rc->is_generator = (scope_flags & MP_SCOPE_FLAG_GENERATOR) != 0; rc->fun_data = fun_data; - #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS + #if MICROPY_PERSISTENT_CODE_SAVE rc->fun_data_len = fun_len; #endif rc->children = children; diff --git a/py/emitglue.h b/py/emitglue.h index b1c10a1ee4f07..b7368d697ddf7 100644 --- a/py/emitglue.h +++ b/py/emitglue.h @@ -77,10 +77,8 @@ typedef struct _mp_raw_code_t { bool is_generator; const void *fun_data; struct _mp_raw_code_t **children; - #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS - uint32_t fun_data_len; // so mp_raw_code_save and mp_bytecode_print work - #endif #if MICROPY_PERSISTENT_CODE_SAVE + uint32_t fun_data_len; // for mp_raw_code_save uint16_t n_children; #if MICROPY_EMIT_MACHINE_CODE uint16_t prelude_offset; @@ -109,10 +107,8 @@ typedef struct _mp_raw_code_truncated_t { bool is_generator; const void *fun_data; struct _mp_raw_code_t **children; - #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS - uint32_t fun_data_len; - #endif #if MICROPY_PERSISTENT_CODE_SAVE + uint32_t fun_data_len; uint16_t n_children; #if MICROPY_EMIT_MACHINE_CODE uint16_t prelude_offset; @@ -127,11 +123,9 @@ typedef struct _mp_raw_code_truncated_t { mp_raw_code_t *mp_emit_glue_new_raw_code(void); void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code, - #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS - size_t len, - #endif mp_raw_code_t **children, #if MICROPY_PERSISTENT_CODE_SAVE + size_t len, uint16_t n_children, #endif uint16_t scope_flags); diff --git a/py/persistentcode.c b/py/persistentcode.c index 7b002e7fcfc2f..1fe9a9a23fde8 100644 --- a/py/persistentcode.c +++ b/py/persistentcode.c @@ -324,11 +324,9 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader, mp_module_context_t *co MP_BC_PRELUDE_SIG_DECODE(ip); // Assign bytecode to raw code object mp_emit_glue_assign_bytecode(rc, fun_data, - #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS - fun_data_len, - #endif children, #if MICROPY_PERSISTENT_CODE_SAVE + fun_data_len, n_children, #endif scope_flags); diff --git a/py/scope.h b/py/scope.h index e7d2a304f79f3..927c4a7b93e2b 100644 --- a/py/scope.h +++ b/py/scope.h @@ -76,6 +76,9 @@ typedef struct _scope_t { struct _scope_t *next; mp_parse_node_t pn; mp_raw_code_t *raw_code; + #if MICROPY_DEBUG_PRINTERS + size_t raw_code_data_len; // for mp_bytecode_print + #endif uint16_t simple_name; // a qstr uint16_t scope_flags; // see runtime0.h uint16_t emit_options; // see emitglue.h diff --git a/py/showbc.c b/py/showbc.c index f9c334b93bbbb..6913d18c1ca82 100644 --- a/py/showbc.c +++ b/py/showbc.c @@ -83,7 +83,7 @@ DECODE_UINT; \ unum = (mp_uint_t)obj_table[unum] -void mp_bytecode_print(const mp_print_t *print, const mp_raw_code_t *rc, const mp_module_constants_t *cm) { +void mp_bytecode_print(const mp_print_t *print, const mp_raw_code_t *rc, size_t fun_data_len, const mp_module_constants_t *cm) { const byte *ip_start = rc->fun_data; const byte *ip = rc->fun_data; @@ -100,13 +100,13 @@ void mp_bytecode_print(const mp_print_t *print, const mp_raw_code_t *rc, const m qstr source_file = cm->source_file; #endif mp_printf(print, "File %s, code block '%s' (descriptor: %p, bytecode @%p %u bytes)\n", - qstr_str(source_file), qstr_str(block_name), rc, ip_start, (unsigned)rc->fun_data_len); + qstr_str(source_file), qstr_str(block_name), rc, ip_start, (unsigned)fun_data_len); // raw bytecode dump size_t prelude_size = ip - ip_start + n_info + n_cell; mp_printf(print, "Raw bytecode (code_info_size=%u, bytecode_size=%u):\n", - (unsigned)prelude_size, (unsigned)(rc->fun_data_len - prelude_size)); - for (size_t i = 0; i < rc->fun_data_len; i++) { + (unsigned)prelude_size, (unsigned)(fun_data_len - prelude_size)); + for (size_t i = 0; i < fun_data_len; i++) { if (i > 0 && i % 16 == 0) { mp_printf(print, "\n"); } @@ -158,7 +158,7 @@ void mp_bytecode_print(const mp_print_t *print, const mp_raw_code_t *rc, const m mp_printf(print, " bc=" INT_FMT " line=" UINT_FMT "\n", bc, source_line); } } - mp_bytecode_print2(print, ip, rc->fun_data_len - prelude_size, rc->children, cm); + mp_bytecode_print2(print, ip, fun_data_len - prelude_size, rc->children, cm); } const byte *mp_bytecode_print_str(const mp_print_t *print, const byte *ip_start, const byte *ip, mp_raw_code_t *const *child_table, const mp_module_constants_t *cm) { diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py index 38567b37e58e8..35c06a30282e0 100755 --- a/tools/mpy-tool.py +++ b/tools/mpy-tool.py @@ -930,10 +930,8 @@ def freeze_raw_code(self, prelude_ptr=None, type_sig=0): print(" .children = (void *)%s," % prelude_ptr) else: print(" .children = NULL,") - print(" #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS") - print(" .fun_data_len = %u," % len(self.fun_data)) - print(" #endif") print(" #if MICROPY_PERSISTENT_CODE_SAVE") + print(" .fun_data_len = %u," % len(self.fun_data)) print(" .n_children = %u," % len(self.children)) print(" #if MICROPY_EMIT_MACHINE_CODE") print(" .prelude_offset = %u," % self.prelude_offset) From 1ef2944b984545cd9c25a3a16c4fd80c97754eeb Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Tue, 13 Feb 2024 17:18:18 +1100 Subject: [PATCH 140/408] tools/manifestfile.py: Add --unix-ffi option. Follow up to 35dd959133fb233d75e9b3cddbf98b2ed01c6594, allows explicitly adding the unix-ffi library path from the command line. This option is needed when building unix-ffi manifests in micropython-lib CI. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- tools/manifestfile.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/manifestfile.py b/tools/manifestfile.py index 47403d4e3bc18..c1fc836585fb9 100644 --- a/tools/manifestfile.py +++ b/tools/manifestfile.py @@ -603,6 +603,9 @@ def main(): default=os.path.join(os.path.dirname(__file__), "../lib/micropython-lib"), help="path to micropython-lib repo", ) + cmd_parser.add_argument( + "--unix-ffi", action="store_true", help="prepend unix-ffi to the library path" + ) cmd_parser.add_argument("--port", default=None, help="path to port dir") cmd_parser.add_argument("--board", default=None, help="path to board dir") cmd_parser.add_argument( @@ -632,6 +635,8 @@ def main(): exit(1) m = ManifestFile(mode, path_vars) + if args.unix_ffi: + m.add_library("unix-ffi", os.path.join("$(MPY_LIB_DIR)", "unix-ffi"), prepend=True) for manifest_file in args.files: try: m.execute(manifest_file) From 9242e3d16d34dd15f1cd868681be45432b443c5a Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 14 Feb 2024 13:08:23 +1100 Subject: [PATCH 141/408] py/makeversionhdr.py: Reinstate MICROPY_GIT_HASH in mpversion.h. MICROPY_GIT_HASH was removed in 69e34b6b6bdf45bc1111777c46839a8b5fcb30bd but it is useful for, and used by, third-party code to tell which hash of MicroPython is used. Signed-off-by: Damien George --- py/makeversionhdr.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/py/makeversionhdr.py b/py/makeversionhdr.py index 2030bb02c4cdc..cb7325e416cb4 100644 --- a/py/makeversionhdr.py +++ b/py/makeversionhdr.py @@ -25,7 +25,6 @@ def get_version_info_from_git(repo_path): # Python 2.6 doesn't have check_output, so check for that try: subprocess.check_output - subprocess.check_call except AttributeError: return None @@ -44,9 +43,25 @@ def get_version_info_from_git(repo_path): return git_tag[0] else: return git_tag[0] + "-" + git_tag[1].replace("-", ".") - except subprocess.CalledProcessError: + except (subprocess.CalledProcessError, OSError): return None - except OSError: + + +def get_hash_from_git(repo_path): + # Python 2.6 doesn't have check_output, so check for that. + try: + subprocess.check_output + except AttributeError: + return None + + try: + return subprocess.check_output( + ["git", "rev-parse", "--short", "HEAD"], + cwd=repo_path, + stderr=subprocess.STDOUT, + universal_newlines=True, + ).strip() + except (subprocess.CalledProcessError, OSError): return None @@ -86,10 +101,13 @@ def get_version_info_from_mpconfig(repo_path): def make_version_header(repo_path, filename): git_tag = None + git_hash = None if "MICROPY_GIT_TAG" in os.environ: git_tag = os.environ["MICROPY_GIT_TAG"] + git_hash = os.environ.get("MICROPY_GIT_HASH") if git_tag is None: git_tag = get_version_info_from_git(repo_path) + git_hash = get_hash_from_git(repo_path) if git_tag is None: git_tag = get_version_info_from_mpconfig(repo_path) @@ -104,12 +122,15 @@ def make_version_header(repo_path, filename): ).date() # Generate the file with the git and version info + # Note: MICROPY_GIT_HASH may be used by third-party code. file_data = """\ // This file was generated by py/makeversionhdr.py #define MICROPY_GIT_TAG "%s" +#define MICROPY_GIT_HASH "%s" #define MICROPY_BUILD_DATE "%s" """ % ( git_tag, + git_hash or "", build_date.strftime("%Y-%m-%d"), ) From 24234937747e6d7fd920d21358fb26b826398e1a Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 16 Feb 2024 11:41:28 +1100 Subject: [PATCH 142/408] py/obj: Change sizeof to offsetof in mp_obj_malloc_var macro. Following b6a977848407a4ced45d118cf926bd915cc89dfb, to properly calculate the size of the variable-length allocation. Signed-off-by: Damien George --- extmod/modcryptolib.c | 6 +++--- extmod/modhashlib.c | 12 ++++++------ extmod/modre.c | 2 +- ports/nrf/boards/MICROBIT/modules/microbitimage.c | 2 +- ports/unix/modffi.c | 4 ++-- py/modio.c | 2 +- py/obj.h | 2 +- py/objattrtuple.c | 2 +- py/objclosure.c | 2 +- py/objfun.c | 2 +- py/objgenerator.c | 4 ++-- py/objmap.c | 2 +- py/objnamedtuple.c | 2 +- py/objtuple.c | 2 +- py/objtype.c | 2 +- py/objzip.c | 2 +- 16 files changed, 25 insertions(+), 25 deletions(-) diff --git a/extmod/modcryptolib.c b/extmod/modcryptolib.c index b33d8533fc5e6..66511b0f75ee4 100644 --- a/extmod/modcryptolib.c +++ b/extmod/modcryptolib.c @@ -87,6 +87,7 @@ typedef struct _mp_obj_aes_t { #define AES_KEYTYPE_ENC 1 #define AES_KEYTYPE_DEC 2 uint8_t key_type : 2; + struct ctr_params ctr_params[]; // optional } mp_obj_aes_t; static inline bool is_ctr_mode(int block_mode) { @@ -98,8 +99,7 @@ static inline bool is_ctr_mode(int block_mode) { } static inline struct ctr_params *ctr_params_from_aes(mp_obj_aes_t *o) { - // ctr_params follows aes object struct - return (struct ctr_params *)&o[1]; + return &o->ctr_params[0]; } #if MICROPY_SSL_AXTLS @@ -228,7 +228,7 @@ STATIC mp_obj_t cryptolib_aes_make_new(const mp_obj_type_t *type, size_t n_args, mp_raise_ValueError(MP_ERROR_TEXT("mode")); } - mp_obj_aes_t *o = mp_obj_malloc_var(mp_obj_aes_t, struct ctr_params, !!is_ctr_mode(block_mode), type); + mp_obj_aes_t *o = mp_obj_malloc_var(mp_obj_aes_t, ctr_params, struct ctr_params, !!is_ctr_mode(block_mode), type); o->block_mode = block_mode; o->key_type = AES_KEYTYPE_NONE; diff --git a/extmod/modhashlib.c b/extmod/modhashlib.c index 263144a5c9d32..dbebd78667646 100644 --- a/extmod/modhashlib.c +++ b/extmod/modhashlib.c @@ -83,7 +83,7 @@ STATIC mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg); STATIC mp_obj_t hashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); - mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(mbedtls_sha256_context), type); + mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, state, char, sizeof(mbedtls_sha256_context), type); o->final = false; mbedtls_sha256_init((mbedtls_sha256_context *)&o->state); mbedtls_sha256_starts_ret((mbedtls_sha256_context *)&o->state, 0); @@ -118,7 +118,7 @@ STATIC mp_obj_t hashlib_sha256_digest(mp_obj_t self_in) { STATIC mp_obj_t hashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); - mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(CRYAL_SHA256_CTX), type); + mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, state, char, sizeof(CRYAL_SHA256_CTX), type); o->final = false; sha256_init((CRYAL_SHA256_CTX *)o->state); if (n_args == 1) { @@ -172,7 +172,7 @@ STATIC mp_obj_t hashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg); #if MICROPY_SSL_AXTLS STATIC mp_obj_t hashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); - mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(SHA1_CTX), type); + mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, state, char, sizeof(SHA1_CTX), type); o->final = false; SHA1_Init((SHA1_CTX *)o->state); if (n_args == 1) { @@ -211,7 +211,7 @@ STATIC mp_obj_t hashlib_sha1_digest(mp_obj_t self_in) { STATIC mp_obj_t hashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); - mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(mbedtls_sha1_context), type); + mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, state, char, sizeof(mbedtls_sha1_context), type); o->final = false; mbedtls_sha1_init((mbedtls_sha1_context *)o->state); mbedtls_sha1_starts_ret((mbedtls_sha1_context *)o->state); @@ -266,7 +266,7 @@ STATIC mp_obj_t hashlib_md5_update(mp_obj_t self_in, mp_obj_t arg); #if MICROPY_SSL_AXTLS STATIC mp_obj_t hashlib_md5_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); - mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(MD5_CTX), type); + mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, state, char, sizeof(MD5_CTX), type); o->final = false; MD5_Init((MD5_CTX *)o->state); if (n_args == 1) { @@ -305,7 +305,7 @@ STATIC mp_obj_t hashlib_md5_digest(mp_obj_t self_in) { STATIC mp_obj_t hashlib_md5_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); - mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(mbedtls_md5_context), type); + mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, state, char, sizeof(mbedtls_md5_context), type); o->final = false; mbedtls_md5_init((mbedtls_md5_context *)o->state); mbedtls_md5_starts_ret((mbedtls_md5_context *)o->state); diff --git a/extmod/modre.c b/extmod/modre.c index c24c07d0951b5..9d5d7178728ed 100644 --- a/extmod/modre.c +++ b/extmod/modre.c @@ -428,7 +428,7 @@ STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) { if (size == -1) { goto error; } - mp_obj_re_t *o = mp_obj_malloc_var(mp_obj_re_t, char, size, (mp_obj_type_t *)&re_type); + mp_obj_re_t *o = mp_obj_malloc_var(mp_obj_re_t, re.insts, char, size, (mp_obj_type_t *)&re_type); #if MICROPY_PY_RE_DEBUG int flags = 0; if (n_args > 1) { diff --git a/ports/nrf/boards/MICROBIT/modules/microbitimage.c b/ports/nrf/boards/MICROBIT/modules/microbitimage.c index 08ef4babcf464..b3505c20a394d 100644 --- a/ports/nrf/boards/MICROBIT/modules/microbitimage.c +++ b/ports/nrf/boards/MICROBIT/modules/microbitimage.c @@ -113,7 +113,7 @@ mp_int_t imageHeight(microbit_image_obj_t * p_image) { } STATIC greyscale_t *greyscale_new(mp_int_t w, mp_int_t h) { - greyscale_t *result = mp_obj_malloc_var(greyscale_t, uint8_t, (w*h+1)>>1, µbit_image_type); + greyscale_t *result = mp_obj_malloc_var(greyscale_t, byte_data, uint8_t, (w*h+1)>>1, µbit_image_type); result->five = 0; result->width = w; result->height = h; diff --git a/ports/unix/modffi.c b/ports/unix/modffi.c index bc585f8647bc6..897fa07ace1f3 100644 --- a/ports/unix/modffi.c +++ b/ports/unix/modffi.c @@ -227,7 +227,7 @@ STATIC mp_obj_t make_func(mp_obj_t rettype_in, void *func, mp_obj_t argtypes_in) const char *argtypes = mp_obj_str_get_str(argtypes_in); mp_int_t nparams = MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(argtypes_in)); - mp_obj_ffifunc_t *o = mp_obj_malloc_var(mp_obj_ffifunc_t, ffi_type *, nparams, &ffifunc_type); + mp_obj_ffifunc_t *o = mp_obj_malloc_var(mp_obj_ffifunc_t, params, ffi_type *, nparams, &ffifunc_type); o->func = func; o->rettype = *rettype; @@ -334,7 +334,7 @@ STATIC mp_obj_t mod_ffi_callback(size_t n_args, const mp_obj_t *pos_args, mp_map const char *rettype = mp_obj_str_get_str(rettype_in); mp_int_t nparams = MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(paramtypes_in)); - mp_obj_fficallback_t *o = mp_obj_malloc_var(mp_obj_fficallback_t, ffi_type *, nparams, &fficallback_type); + mp_obj_fficallback_t *o = mp_obj_malloc_var(mp_obj_fficallback_t, params, ffi_type *, nparams, &fficallback_type); o->clo = ffi_closure_alloc(sizeof(ffi_closure), &o->func); diff --git a/py/modio.c b/py/modio.c index 39317c52d545f..37eff3c41c4a0 100644 --- a/py/modio.c +++ b/py/modio.c @@ -119,7 +119,7 @@ typedef struct _mp_obj_bufwriter_t { STATIC mp_obj_t bufwriter_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 2, 2, false); size_t alloc = mp_obj_get_int(args[1]); - mp_obj_bufwriter_t *o = mp_obj_malloc_var(mp_obj_bufwriter_t, byte, alloc, type); + mp_obj_bufwriter_t *o = mp_obj_malloc_var(mp_obj_bufwriter_t, buf, byte, alloc, type); o->stream = args[0]; o->alloc = alloc; o->len = 0; diff --git a/py/obj.h b/py/obj.h index c7b7db0c38346..5d49873ff91c9 100644 --- a/py/obj.h +++ b/py/obj.h @@ -913,7 +913,7 @@ extern const struct _mp_obj_exception_t mp_const_GeneratorExit_obj; // Helper versions of m_new_obj when you need to immediately set base.type. // Implementing this as a call rather than inline saves 8 bytes per usage. #define mp_obj_malloc(struct_type, obj_type) ((struct_type *)mp_obj_malloc_helper(sizeof(struct_type), obj_type)) -#define mp_obj_malloc_var(struct_type, var_type, var_num, obj_type) ((struct_type *)mp_obj_malloc_helper(sizeof(struct_type) + sizeof(var_type) * (var_num), obj_type)) +#define mp_obj_malloc_var(struct_type, var_field, var_type, var_num, obj_type) ((struct_type *)mp_obj_malloc_helper(offsetof(struct_type, var_field) + sizeof(var_type) * (var_num), obj_type)) void *mp_obj_malloc_helper(size_t num_bytes, const mp_obj_type_t *type); // These macros are derived from more primitive ones and are used to diff --git a/py/objattrtuple.c b/py/objattrtuple.c index fbe04bedb877a..1ec9499893236 100644 --- a/py/objattrtuple.c +++ b/py/objattrtuple.c @@ -71,7 +71,7 @@ STATIC void mp_obj_attrtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } mp_obj_t mp_obj_new_attrtuple(const qstr *fields, size_t n, const mp_obj_t *items) { - mp_obj_tuple_t *o = mp_obj_malloc_var(mp_obj_tuple_t, mp_obj_t, n + 1, &mp_type_attrtuple); + mp_obj_tuple_t *o = mp_obj_malloc_var(mp_obj_tuple_t, items, mp_obj_t, n + 1, &mp_type_attrtuple); o->len = n; for (size_t i = 0; i < n; i++) { o->items[i] = items[i]; diff --git a/py/objclosure.c b/py/objclosure.c index 6059d18100e03..88109cc919642 100644 --- a/py/objclosure.c +++ b/py/objclosure.c @@ -105,7 +105,7 @@ MP_DEFINE_CONST_OBJ_TYPE( ); mp_obj_t mp_obj_new_closure(mp_obj_t fun, size_t n_closed_over, const mp_obj_t *closed) { - mp_obj_closure_t *o = mp_obj_malloc_var(mp_obj_closure_t, mp_obj_t, n_closed_over, &mp_type_closure); + mp_obj_closure_t *o = mp_obj_malloc_var(mp_obj_closure_t, closed, mp_obj_t, n_closed_over, &mp_type_closure); o->fun = fun; o->n_closed = n_closed_over; memcpy(o->closed, closed, n_closed_over * sizeof(mp_obj_t)); diff --git a/py/objfun.c b/py/objfun.c index e2136968b621f..930d0ccdf4f51 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -384,7 +384,7 @@ mp_obj_t mp_obj_new_fun_bc(const mp_obj_t *def_args, const byte *code, const mp_ def_kw_args = def_args[1]; n_extra_args += 1; } - mp_obj_fun_bc_t *o = mp_obj_malloc_var(mp_obj_fun_bc_t, mp_obj_t, n_extra_args, &mp_type_fun_bc); + mp_obj_fun_bc_t *o = mp_obj_malloc_var(mp_obj_fun_bc_t, extra_args, mp_obj_t, n_extra_args, &mp_type_fun_bc); o->bytecode = code; o->context = context; o->child_table = child_table; diff --git a/py/objgenerator.c b/py/objgenerator.c index ecd1f583ea012..7786b1fc81b08 100644 --- a/py/objgenerator.c +++ b/py/objgenerator.c @@ -59,7 +59,7 @@ STATIC mp_obj_t gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_kw, cons MP_BC_PRELUDE_SIG_DECODE(ip); // allocate the generator object, with room for local stack and exception stack - mp_obj_gen_instance_t *o = mp_obj_malloc_var(mp_obj_gen_instance_t, byte, + mp_obj_gen_instance_t *o = mp_obj_malloc_var(mp_obj_gen_instance_t, code_state.state, byte, n_state * sizeof(mp_obj_t) + n_exc_stack * sizeof(mp_exc_stack_t), &mp_type_gen_instance); @@ -114,7 +114,7 @@ STATIC mp_obj_t native_gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_k MP_BC_PRELUDE_SIG_DECODE(ip); // Allocate the generator object, with room for local stack (exception stack not needed). - mp_obj_gen_instance_native_t *o = mp_obj_malloc_var(mp_obj_gen_instance_native_t, byte, n_state * sizeof(mp_obj_t), &mp_type_gen_instance); + mp_obj_gen_instance_native_t *o = mp_obj_malloc_var(mp_obj_gen_instance_native_t, code_state.state, byte, n_state * sizeof(mp_obj_t), &mp_type_gen_instance); // Parse the input arguments and set up the code state o->pend_exc = mp_const_none; diff --git a/py/objmap.c b/py/objmap.c index e7e594cd2c54b..98ff19bb7bb6f 100644 --- a/py/objmap.c +++ b/py/objmap.c @@ -38,7 +38,7 @@ typedef struct _mp_obj_map_t { STATIC mp_obj_t map_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 2, MP_OBJ_FUN_ARGS_MAX, false); - mp_obj_map_t *o = mp_obj_malloc_var(mp_obj_map_t, mp_obj_t, n_args - 1, type); + mp_obj_map_t *o = mp_obj_malloc_var(mp_obj_map_t, iters, mp_obj_t, n_args - 1, type); o->n_iters = n_args - 1; o->fun = args[0]; for (size_t i = 0; i < n_args - 1; i++) { diff --git a/py/objnamedtuple.c b/py/objnamedtuple.c index e586f089458d8..0adf83fe96bcd 100644 --- a/py/objnamedtuple.c +++ b/py/objnamedtuple.c @@ -110,7 +110,7 @@ STATIC mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, // Create a namedtuple with explicit malloc. Calling mp_obj_new_tuple // with num_fields=0 returns a read-only object. - mp_obj_tuple_t *tuple = mp_obj_malloc_var(mp_obj_tuple_t, mp_obj_t, num_fields, type_in); + mp_obj_tuple_t *tuple = mp_obj_malloc_var(mp_obj_tuple_t, items, mp_obj_t, num_fields, type_in); tuple->len = num_fields; // Copy the positional args into the first slots of the namedtuple diff --git a/py/objtuple.c b/py/objtuple.c index 969c488ee2318..cb1d7cd388a91 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -244,7 +244,7 @@ mp_obj_t mp_obj_new_tuple(size_t n, const mp_obj_t *items) { if (n == 0) { return mp_const_empty_tuple; } - mp_obj_tuple_t *o = mp_obj_malloc_var(mp_obj_tuple_t, mp_obj_t, n, &mp_type_tuple); + mp_obj_tuple_t *o = mp_obj_malloc_var(mp_obj_tuple_t, items, mp_obj_t, n, &mp_type_tuple); o->len = n; if (items) { for (size_t i = 0; i < n; i++) { diff --git a/py/objtype.c b/py/objtype.c index d21c2a4b5b509..694db3008f6f2 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -99,7 +99,7 @@ STATIC mp_obj_instance_t *mp_obj_new_instance(const mp_obj_type_t *class, const mp_obj_type_t **native_base) { size_t num_native_bases = instance_count_native_bases(class, native_base); assert(num_native_bases < 2); - mp_obj_instance_t *o = mp_obj_malloc_var(mp_obj_instance_t, mp_obj_t, num_native_bases, class); + mp_obj_instance_t *o = mp_obj_malloc_var(mp_obj_instance_t, subobj, mp_obj_t, num_native_bases, class); mp_map_init(&o->members, 0); // Initialise the native base-class slot (should be 1 at most) with a valid // object. It doesn't matter which object, so long as it can be uniquely diff --git a/py/objzip.c b/py/objzip.c index 3c3138180a28f..7b4ae7548e8a5 100644 --- a/py/objzip.c +++ b/py/objzip.c @@ -39,7 +39,7 @@ typedef struct _mp_obj_zip_t { STATIC mp_obj_t zip_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, false); - mp_obj_zip_t *o = mp_obj_malloc_var(mp_obj_zip_t, mp_obj_t, n_args, type); + mp_obj_zip_t *o = mp_obj_malloc_var(mp_obj_zip_t, iters, mp_obj_t, n_args, type); o->n_iters = n_args; for (size_t i = 0; i < n_args; i++) { o->iters[i] = mp_getiter(args[i], NULL); From 4133c0304011ff7be23f47516aac20ed54505e7a Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 16 Feb 2024 10:58:36 +1100 Subject: [PATCH 143/408] py/obj: Introduce mp_obj_malloc_with_finaliser to allocate and set type. Following 709e8328d9812a2e02da6fba65a03f9a873d60a2. Using this helps to reduce code size. And it ensure that the type is always set as soon as the object is allocated, which is important for the GC to function correctly. Signed-off-by: Damien George --- py/obj.c | 9 +++++++++ py/obj.h | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/py/obj.c b/py/obj.c index 5e01198b6fb4c..e43451dadd512 100644 --- a/py/obj.c +++ b/py/obj.c @@ -44,6 +44,15 @@ MP_NOINLINE void *mp_obj_malloc_helper(size_t num_bytes, const mp_obj_type_t *ty return base; } +#if MICROPY_ENABLE_FINALISER +// Allocates an object and also sets type, for mp_obj_malloc{,_var}_with_finaliser macros. +MP_NOINLINE void *mp_obj_malloc_with_finaliser_helper(size_t num_bytes, const mp_obj_type_t *type) { + mp_obj_base_t *base = (mp_obj_base_t *)m_malloc_with_finaliser(num_bytes); + base->type = type; + return base; +} +#endif + const mp_obj_type_t *MICROPY_WRAP_MP_OBJ_GET_TYPE(mp_obj_get_type)(mp_const_obj_t o_in) { #if MICROPY_OBJ_IMMEDIATE_OBJS && MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_A diff --git a/py/obj.h b/py/obj.h index 5d49873ff91c9..bd0df3fd682cf 100644 --- a/py/obj.h +++ b/py/obj.h @@ -916,6 +916,16 @@ extern const struct _mp_obj_exception_t mp_const_GeneratorExit_obj; #define mp_obj_malloc_var(struct_type, var_field, var_type, var_num, obj_type) ((struct_type *)mp_obj_malloc_helper(offsetof(struct_type, var_field) + sizeof(var_type) * (var_num), obj_type)) void *mp_obj_malloc_helper(size_t num_bytes, const mp_obj_type_t *type); +// Object allocation macros for allocating objects that have a finaliser. +#if MICROPY_ENABLE_FINALISER +#define mp_obj_malloc_with_finaliser(struct_type, obj_type) ((struct_type *)mp_obj_malloc_with_finaliser_helper(sizeof(struct_type), obj_type)) +#define mp_obj_malloc_var_with_finaliser(struct_type, var_type, var_num, obj_type) ((struct_type *)mp_obj_malloc_with_finaliser_helper(sizeof(struct_type) + sizeof(var_type) * (var_num), obj_type)) +void *mp_obj_malloc_with_finaliser_helper(size_t num_bytes, const mp_obj_type_t *type); +#else +#define mp_obj_malloc_with_finaliser(struct_type, obj_type) mp_obj_malloc(struct_type, obj_type) +#define mp_obj_malloc_var_with_finaliser(struct_type, var_type, var_num, obj_type) mp_obj_malloc_var(struct_type, var_type, var_num, obj_type) +#endif + // These macros are derived from more primitive ones and are used to // check for more specific object types. // Note: these are kept as macros because inline functions sometimes use much From cae690d047900b842beaa7798b5362b5646130af Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 16 Feb 2024 11:02:58 +1100 Subject: [PATCH 144/408] all: Use mp_obj_malloc_with_finaliser everywhere it's applicable. Signed-off-by: Damien George --- extmod/modlwip.c | 6 ++---- extmod/modsocket.c | 6 ++---- extmod/modtls_axtls.c | 10 ++++------ extmod/modtls_mbedtls.c | 10 ++++------ extmod/vfs_fat.c | 3 +-- extmod/vfs_fat_file.c | 3 +-- extmod/vfs_lfsx.c | 3 +-- extmod/vfs_lfsx_file.c | 5 ++--- extmod/vfs_posix.c | 3 +-- extmod/vfs_posix_file.c | 3 +-- ports/cc3200/mods/modsocket.c | 5 ++--- ports/esp32/esp32_rmt.c | 3 +-- ports/esp32/machine_i2s.c | 3 +-- ports/esp32/machine_sdcard.c | 3 +-- ports/esp32/modsocket.c | 6 ++---- ports/esp32/network_ppp.c | 4 +--- ports/rp2/machine_timer.c | 3 +-- ports/rp2/rp2_dma.c | 3 +-- ports/zephyr/modsocket.c | 3 +-- 19 files changed, 30 insertions(+), 55 deletions(-) diff --git a/extmod/modlwip.c b/extmod/modlwip.c index 8ccc388913f42..a6630c693cad5 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -831,8 +831,7 @@ STATIC void lwip_socket_print(const mp_print_t *print, mp_obj_t self_in, mp_prin STATIC mp_obj_t lwip_socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 4, false); - lwip_socket_obj_t *socket = m_new_obj_with_finaliser(lwip_socket_obj_t); - socket->base.type = &lwip_socket_type; + lwip_socket_obj_t *socket = mp_obj_malloc_with_finaliser(lwip_socket_obj_t, &lwip_socket_type); socket->timeout = -1; socket->recv_offset = 0; socket->domain = MOD_NETWORK_AF_INET; @@ -994,8 +993,7 @@ STATIC mp_obj_t lwip_socket_accept(mp_obj_t self_in) { // Create new socket object, do it here because we must not raise an out-of-memory // exception when the LWIP concurrency lock is held - lwip_socket_obj_t *socket2 = m_new_obj_with_finaliser(lwip_socket_obj_t); - socket2->base.type = &lwip_socket_type; + lwip_socket_obj_t *socket2 = mp_obj_malloc_with_finaliser(lwip_socket_obj_t, &lwip_socket_type); MICROPY_PY_LWIP_ENTER diff --git a/extmod/modsocket.c b/extmod/modsocket.c index 72a32e3cba4eb..4a857fb62e6ff 100644 --- a/extmod/modsocket.c +++ b/extmod/modsocket.c @@ -54,8 +54,7 @@ STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t mp_arg_check_num(n_args, n_kw, 0, 3, false); // create socket object (not bound to any NIC yet) - mod_network_socket_obj_t *s = m_new_obj_with_finaliser(mod_network_socket_obj_t); - s->base.type = &socket_type; + mod_network_socket_obj_t *s = mp_obj_malloc_with_finaliser(mod_network_socket_obj_t, &socket_type); s->nic = MP_OBJ_NULL; s->nic_protocol = NULL; s->domain = MOD_NETWORK_AF_INET; @@ -163,8 +162,7 @@ STATIC mp_obj_t socket_accept(mp_obj_t self_in) { // create new socket object // starts with empty NIC so that finaliser doesn't run close() method if accept() fails - mod_network_socket_obj_t *socket2 = m_new_obj_with_finaliser(mod_network_socket_obj_t); - socket2->base.type = &socket_type; + mod_network_socket_obj_t *socket2 = mp_obj_malloc_with_finaliser(mod_network_socket_obj_t, &socket_type); socket2->nic = MP_OBJ_NULL; socket2->nic_protocol = NULL; diff --git a/extmod/modtls_axtls.c b/extmod/modtls_axtls.c index 1ac40208db003..4f6b06f66d6e2 100644 --- a/extmod/modtls_axtls.c +++ b/extmod/modtls_axtls.c @@ -145,11 +145,10 @@ STATIC mp_obj_t ssl_context_make_new(const mp_obj_type_t *type_in, size_t n_args // Create SSLContext object. #if MICROPY_PY_SSL_FINALISER - mp_obj_ssl_context_t *self = m_new_obj_with_finaliser(mp_obj_ssl_context_t); + mp_obj_ssl_context_t *self = mp_obj_malloc_with_finaliser(mp_obj_ssl_context_t, type_in); #else - mp_obj_ssl_context_t *self = m_new_obj(mp_obj_ssl_context_t); + mp_obj_ssl_context_t *self = mp_obj_malloc(mp_obj_ssl_context_t, type_in); #endif - self->base.type = type_in; self->key = mp_const_none; self->cert = mp_const_none; @@ -210,11 +209,10 @@ STATIC mp_obj_t ssl_socket_make_new(mp_obj_ssl_context_t *ssl_context, mp_obj_t bool server_side, bool do_handshake_on_connect, mp_obj_t server_hostname) { #if MICROPY_PY_SSL_FINALISER - mp_obj_ssl_socket_t *o = m_new_obj_with_finaliser(mp_obj_ssl_socket_t); + mp_obj_ssl_socket_t *o = mp_obj_malloc_with_finaliser(mp_obj_ssl_socket_t, &ssl_socket_type); #else - mp_obj_ssl_socket_t *o = m_new_obj(mp_obj_ssl_socket_t); + mp_obj_ssl_socket_t *o = mp_obj_malloc(mp_obj_ssl_socket_t, &ssl_socket_type); #endif - o->base.type = &ssl_socket_type; o->buf = NULL; o->bytes_left = 0; o->sock = MP_OBJ_NULL; diff --git a/extmod/modtls_mbedtls.c b/extmod/modtls_mbedtls.c index 6cb4f002051b4..4d0ccd2c0e794 100644 --- a/extmod/modtls_mbedtls.c +++ b/extmod/modtls_mbedtls.c @@ -210,11 +210,10 @@ STATIC mp_obj_t ssl_context_make_new(const mp_obj_type_t *type_in, size_t n_args // Create SSLContext object. #if MICROPY_PY_SSL_FINALISER - mp_obj_ssl_context_t *self = m_new_obj_with_finaliser(mp_obj_ssl_context_t); + mp_obj_ssl_context_t *self = mp_obj_malloc_with_finaliser(mp_obj_ssl_context_t, type_in); #else - mp_obj_ssl_context_t *self = m_new_obj(mp_obj_ssl_context_t); + mp_obj_ssl_context_t *self = mp_obj_malloc(mp_obj_ssl_context_t, type_in); #endif - self->base.type = type_in; // Initialise mbedTLS state. mbedtls_ssl_config_init(&self->conf); @@ -488,11 +487,10 @@ STATIC mp_obj_t ssl_socket_make_new(mp_obj_ssl_context_t *ssl_context, mp_obj_t mp_get_stream_raise(sock, MP_STREAM_OP_READ | MP_STREAM_OP_WRITE | MP_STREAM_OP_IOCTL); #if MICROPY_PY_SSL_FINALISER - mp_obj_ssl_socket_t *o = m_new_obj_with_finaliser(mp_obj_ssl_socket_t); + mp_obj_ssl_socket_t *o = mp_obj_malloc_with_finaliser(mp_obj_ssl_socket_t, &ssl_socket_type); #else - mp_obj_ssl_socket_t *o = m_new_obj(mp_obj_ssl_socket_t); + mp_obj_ssl_socket_t *o = mp_obj_malloc(mp_obj_ssl_socket_t, &ssl_socket_type); #endif - o->base.type = &ssl_socket_type; o->ssl_context = ssl_context; o->sock = sock; o->poll_mask = 0; diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index efb6bf7e9815d..67c95d9a1712b 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -188,8 +188,7 @@ STATIC mp_obj_t fat_vfs_ilistdir_func(size_t n_args, const mp_obj_t *args) { } // Create a new iterator object to list the dir - mp_vfs_fat_ilistdir_it_t *iter = m_new_obj_with_finaliser(mp_vfs_fat_ilistdir_it_t); - iter->base.type = &mp_type_polymorph_iter_with_finaliser; + mp_vfs_fat_ilistdir_it_t *iter = mp_obj_malloc_with_finaliser(mp_vfs_fat_ilistdir_it_t, &mp_type_polymorph_iter_with_finaliser); iter->iternext = mp_vfs_fat_ilistdir_it_iternext; iter->finaliser = mp_vfs_fat_ilistdir_it_del; iter->is_str = is_str_type; diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c index f82fe4aaae7e2..e2f6937694256 100644 --- a/extmod/vfs_fat_file.c +++ b/extmod/vfs_fat_file.c @@ -228,8 +228,7 @@ STATIC mp_obj_t fat_vfs_open(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mode_i } } - pyb_file_obj_t *o = m_new_obj_with_finaliser(pyb_file_obj_t); - o->base.type = type; + pyb_file_obj_t *o = mp_obj_malloc_with_finaliser(pyb_file_obj_t, type); const char *fname = mp_obj_str_get_str(path_in); FRESULT res = f_open(&self->fatfs, &o->fp, fname, mode); diff --git a/extmod/vfs_lfsx.c b/extmod/vfs_lfsx.c index e78c154d1fe8d..ddcbdf3ac4d75 100644 --- a/extmod/vfs_lfsx.c +++ b/extmod/vfs_lfsx.c @@ -224,8 +224,7 @@ STATIC mp_obj_t MP_VFS_LFSx(ilistdir_func)(size_t n_args, const mp_obj_t *args) path = vstr_null_terminated_str(&self->cur_dir); } - MP_VFS_LFSx(ilistdir_it_t) * iter = m_new_obj_with_finaliser(MP_VFS_LFSx(ilistdir_it_t)); - iter->base.type = &mp_type_polymorph_iter_with_finaliser; + MP_VFS_LFSx(ilistdir_it_t) * iter = mp_obj_malloc_with_finaliser(MP_VFS_LFSx(ilistdir_it_t), &mp_type_polymorph_iter_with_finaliser); iter->iternext = MP_VFS_LFSx(ilistdir_it_iternext); iter->finaliser = MP_VFS_LFSx(ilistdir_it_del); diff --git a/extmod/vfs_lfsx_file.c b/extmod/vfs_lfsx_file.c index b9f332339733e..04058506441b5 100644 --- a/extmod/vfs_lfsx_file.c +++ b/extmod/vfs_lfsx_file.c @@ -90,11 +90,10 @@ mp_obj_t MP_VFS_LFSx(file_open)(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mod } #if LFS_BUILD_VERSION == 1 - MP_OBJ_VFS_LFSx_FILE *o = m_new_obj_var_with_finaliser(MP_OBJ_VFS_LFSx_FILE, file_buffer, uint8_t, self->lfs.cfg->prog_size); + MP_OBJ_VFS_LFSx_FILE *o = mp_obj_malloc_var_with_finaliser(MP_OBJ_VFS_LFSx_FILE, uint8_t, self->lfs.cfg->prog_size, type); #else - MP_OBJ_VFS_LFSx_FILE *o = m_new_obj_var_with_finaliser(MP_OBJ_VFS_LFSx_FILE, file_buffer, uint8_t, self->lfs.cfg->cache_size); + MP_OBJ_VFS_LFSx_FILE *o = mp_obj_malloc_var_with_finaliser(MP_OBJ_VFS_LFSx_FILE, uint8_t, self->lfs.cfg->cache_size, type); #endif - o->base.type = type; o->vfs = self; #if !MICROPY_GC_CONSERVATIVE_CLEAR memset(&o->file, 0, sizeof(o->file)); diff --git a/extmod/vfs_posix.c b/extmod/vfs_posix.c index e29b47cccda83..2e0f712e25ede 100644 --- a/extmod/vfs_posix.c +++ b/extmod/vfs_posix.c @@ -278,8 +278,7 @@ STATIC mp_obj_t vfs_posix_ilistdir_it_del(mp_obj_t self_in) { STATIC mp_obj_t vfs_posix_ilistdir(mp_obj_t self_in, mp_obj_t path_in) { mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in); - vfs_posix_ilistdir_it_t *iter = m_new_obj_with_finaliser(vfs_posix_ilistdir_it_t); - iter->base.type = &mp_type_polymorph_iter_with_finaliser; + vfs_posix_ilistdir_it_t *iter = mp_obj_malloc_with_finaliser(vfs_posix_ilistdir_it_t, &mp_type_polymorph_iter_with_finaliser); iter->iternext = vfs_posix_ilistdir_it_iternext; iter->finaliser = vfs_posix_ilistdir_it_del; iter->is_str = mp_obj_get_type(path_in) == &mp_type_str; diff --git a/extmod/vfs_posix_file.c b/extmod/vfs_posix_file.c index 2f70789543911..46a866a78aff1 100644 --- a/extmod/vfs_posix_file.c +++ b/extmod/vfs_posix_file.c @@ -63,7 +63,6 @@ STATIC void vfs_posix_file_print(const mp_print_t *print, mp_obj_t self_in, mp_p } mp_obj_t mp_vfs_posix_file_open(const mp_obj_type_t *type, mp_obj_t file_in, mp_obj_t mode_in) { - mp_obj_vfs_posix_file_t *o = m_new_obj_with_finaliser(mp_obj_vfs_posix_file_t); const char *mode_s = mp_obj_str_get_str(mode_in); int mode_rw = 0, mode_x = 0; @@ -92,7 +91,7 @@ mp_obj_t mp_vfs_posix_file_open(const mp_obj_type_t *type, mp_obj_t file_in, mp_ } } - o->base.type = type; + mp_obj_vfs_posix_file_t *o = mp_obj_malloc_with_finaliser(mp_obj_vfs_posix_file_t, type); mp_obj_t fid = file_in; diff --git a/ports/cc3200/mods/modsocket.c b/ports/cc3200/mods/modsocket.c index a107fa7120736..0f56c15e821fe 100644 --- a/ports/cc3200/mods/modsocket.c +++ b/ports/cc3200/mods/modsocket.c @@ -436,8 +436,7 @@ STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t mp_arg_check_num(n_args, n_kw, 0, 4, false); // create socket object - mod_network_socket_obj_t *s = m_new_obj_with_finaliser(mod_network_socket_obj_t); - s->base.type = (mp_obj_t)&socket_type; + mod_network_socket_obj_t *s = mp_obj_malloc_with_finaliser(mod_network_socket_obj_t, &socket_type); s->sock_base.u_param.domain = SL_AF_INET; s->sock_base.u_param.type = SL_SOCK_STREAM; s->sock_base.u_param.proto = SL_IPPROTO_TCP; @@ -508,7 +507,7 @@ STATIC mp_obj_t socket_accept(mp_obj_t self_in) { mod_network_socket_obj_t *self = self_in; // create new socket object - mod_network_socket_obj_t *socket2 = m_new_obj_with_finaliser(mod_network_socket_obj_t); + mod_network_socket_obj_t *socket2 = mp_obj_malloc_with_finaliser(mod_network_socket_obj_t, self->base.type); // the new socket inherits all properties from its parent memcpy (socket2, self, sizeof(mod_network_socket_obj_t)); diff --git a/ports/esp32/esp32_rmt.c b/ports/esp32/esp32_rmt.c index 77a31ebc0f66e..494ae48f46cfe 100644 --- a/ports/esp32/esp32_rmt.c +++ b/ports/esp32/esp32_rmt.c @@ -131,8 +131,7 @@ STATIC mp_obj_t esp32_rmt_make_new(const mp_obj_type_t *type, size_t n_args, siz mp_raise_ValueError(MP_ERROR_TEXT("clock_div must be between 1 and 255")); } - esp32_rmt_obj_t *self = m_new_obj_with_finaliser(esp32_rmt_obj_t); - self->base.type = &esp32_rmt_type; + esp32_rmt_obj_t *self = mp_obj_malloc_with_finaliser(esp32_rmt_obj_t, &esp32_rmt_type); self->channel_id = channel_id; self->pin = pin_id; self->clock_div = clock_div; diff --git a/ports/esp32/machine_i2s.c b/ports/esp32/machine_i2s.c index 8a9787c34e859..3b7bcfeffc673 100644 --- a/ports/esp32/machine_i2s.c +++ b/ports/esp32/machine_i2s.c @@ -405,8 +405,7 @@ STATIC machine_i2s_obj_t *mp_machine_i2s_make_new_instance(mp_int_t i2s_id) { machine_i2s_obj_t *self; if (MP_STATE_PORT(machine_i2s_obj)[i2s_id] == NULL) { - self = m_new_obj_with_finaliser(machine_i2s_obj_t); - self->base.type = &machine_i2s_type; + self = mp_obj_malloc_with_finaliser(machine_i2s_obj_t, &machine_i2s_type); MP_STATE_PORT(machine_i2s_obj)[i2s_id] = self; self->i2s_id = i2s_id; } else { diff --git a/ports/esp32/machine_sdcard.c b/ports/esp32/machine_sdcard.c index bc4aaf30c6f2b..8cc6452ddc503 100644 --- a/ports/esp32/machine_sdcard.c +++ b/ports/esp32/machine_sdcard.c @@ -224,8 +224,7 @@ STATIC mp_obj_t machine_sdcard_make_new(const mp_obj_type_t *type, size_t n_args DEBUG_printf(" Setting up host configuration"); - sdcard_card_obj_t *self = m_new_obj_with_finaliser(sdcard_card_obj_t); - self->base.type = &machine_sdcard_type; + sdcard_card_obj_t *self = mp_obj_malloc_with_finaliser(sdcard_card_obj_t, &machine_sdcard_type); self->flags = 0; // Note that these defaults are macros that expand to structure // constants so we can't directly assign them to fields. diff --git a/ports/esp32/modsocket.c b/ports/esp32/modsocket.c index af949401569cd..9280ab203d25b 100644 --- a/ports/esp32/modsocket.c +++ b/ports/esp32/modsocket.c @@ -270,8 +270,7 @@ STATIC void _socket_getaddrinfo(const mp_obj_t addrtuple, struct addrinfo **resp STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 3, false); - socket_obj_t *sock = m_new_obj_with_finaliser(socket_obj_t); - sock->base.type = type_in; + socket_obj_t *sock = mp_obj_malloc_with_finaliser(socket_obj_t, type_in); sock->domain = AF_INET; sock->type = SOCK_STREAM; sock->proto = 0; @@ -364,8 +363,7 @@ STATIC mp_obj_t socket_accept(const mp_obj_t arg0) { } // create new socket object - socket_obj_t *sock = m_new_obj_with_finaliser(socket_obj_t); - sock->base.type = self->base.type; + socket_obj_t *sock = mp_obj_malloc_with_finaliser(socket_obj_t, self->base.type); sock->fd = new_fd; sock->domain = self->domain; sock->type = self->type; diff --git a/ports/esp32/network_ppp.c b/ports/esp32/network_ppp.c index 08443752cc26c..cf644a6bd7319 100644 --- a/ports/esp32/network_ppp.c +++ b/ports/esp32/network_ppp.c @@ -87,9 +87,7 @@ static void ppp_status_cb(ppp_pcb *pcb, int err_code, void *ctx) { STATIC mp_obj_t ppp_make_new(mp_obj_t stream) { mp_get_stream_raise(stream, MP_STREAM_OP_READ | MP_STREAM_OP_WRITE); - ppp_if_obj_t *self = m_new_obj_with_finaliser(ppp_if_obj_t); - - self->base.type = &ppp_if_type; + ppp_if_obj_t *self = mp_obj_malloc_with_finaliser(ppp_if_obj_t, &ppp_if_type); self->stream = stream; self->active = false; self->connected = false; diff --git a/ports/rp2/machine_timer.c b/ports/rp2/machine_timer.c index f0df541e6bde8..f154507141a1f 100644 --- a/ports/rp2/machine_timer.c +++ b/ports/rp2/machine_timer.c @@ -105,8 +105,7 @@ STATIC mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, size_t n_ar } STATIC mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { - machine_timer_obj_t *self = m_new_obj_with_finaliser(machine_timer_obj_t); - self->base.type = &machine_timer_type; + machine_timer_obj_t *self = mp_obj_malloc_with_finaliser(machine_timer_obj_t, &machine_timer_type); self->pool = alarm_pool_get_default(); self->alarm_id = ALARM_ID_INVALID; diff --git a/ports/rp2/rp2_dma.c b/ports/rp2/rp2_dma.c index 425fb417fa5ec..27624ea8bfe12 100644 --- a/ports/rp2/rp2_dma.c +++ b/ports/rp2/rp2_dma.c @@ -145,8 +145,7 @@ STATIC mp_obj_t rp2_dma_make_new(const mp_obj_type_t *type, size_t n_args, size_ mp_raise_OSError(MP_EBUSY); } - rp2_dma_obj_t *self = m_new_obj_with_finaliser(rp2_dma_obj_t); - self->base.type = &rp2_dma_type; + rp2_dma_obj_t *self = mp_obj_malloc_with_finaliser(rp2_dma_obj_t, &rp2_dma_type); self->channel = dma_channel; // Return the DMA object. diff --git a/ports/zephyr/modsocket.c b/ports/zephyr/modsocket.c index eacdb049da495..3d91fa976930d 100644 --- a/ports/zephyr/modsocket.c +++ b/ports/zephyr/modsocket.c @@ -107,8 +107,7 @@ STATIC mp_obj_t format_inet_addr(struct sockaddr *addr, mp_obj_t port) { } socket_obj_t *socket_new(void) { - socket_obj_t *socket = m_new_obj_with_finaliser(socket_obj_t); - socket->base.type = (mp_obj_t)&socket_type; + socket_obj_t *socket = mp_obj_malloc_with_finaliser(socket_obj_t, &socket_type); socket->state = STATE_NEW; return socket; } From 971617196644775905fd821c39c6a7771b63dbaf Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 16 Feb 2024 11:04:08 +1100 Subject: [PATCH 145/408] py/misc: Remove m_new_obj[_var]_with_finaliser macros. They are no longer used. The new `mp_obj_malloc_with_finaliser()` macros should be used instead, which force the setting of the `base.type` field. And there's always `m_malloc_with_finaliser()` if needed. Signed-off-by: Damien George --- py/misc.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/py/misc.h b/py/misc.h index e19a535720fb1..eea3e8b0fe7f5 100644 --- a/py/misc.h +++ b/py/misc.h @@ -79,13 +79,6 @@ typedef unsigned int uint; #define m_new_obj_var(obj_type, var_field, var_type, var_num) ((obj_type *)m_malloc(offsetof(obj_type, var_field) + sizeof(var_type) * (var_num))) #define m_new_obj_var0(obj_type, var_field, var_type, var_num) ((obj_type *)m_malloc0(offsetof(obj_type, var_field) + sizeof(var_type) * (var_num))) #define m_new_obj_var_maybe(obj_type, var_field, var_type, var_num) ((obj_type *)m_malloc_maybe(offsetof(obj_type, var_field) + sizeof(var_type) * (var_num))) -#if MICROPY_ENABLE_FINALISER -#define m_new_obj_with_finaliser(type) ((type *)(m_malloc_with_finaliser(sizeof(type)))) -#define m_new_obj_var_with_finaliser(type, var_field, var_type, var_num) ((type *)m_malloc_with_finaliser(offsetof(type, var_field) + sizeof(var_type) * (var_num))) -#else -#define m_new_obj_with_finaliser(type) m_new_obj(type) -#define m_new_obj_var_with_finaliser(type, var_field, var_type, var_num) m_new_obj_var(type, var_field, var_type, var_num) -#endif #if MICROPY_MALLOC_USES_ALLOCATED_SIZE #define m_renew(type, ptr, old_num, new_num) ((type *)(m_realloc((ptr), sizeof(type) * (old_num), sizeof(type) * (new_num)))) #define m_renew_maybe(type, ptr, old_num, new_num, allow_move) ((type *)(m_realloc_maybe((ptr), sizeof(type) * (old_num), sizeof(type) * (new_num), (allow_move)))) From 648a7578da21cc7ddb4046fc59891144e797b983 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 16 Feb 2024 17:09:41 +1100 Subject: [PATCH 146/408] py/objfun: Make mp_obj_new_fun_native/mp_obj_new_fun_asm static-inline. To reduce code size, since they are only used once by py/emitglue.c. Signed-off-by: Damien George --- py/obj.h | 2 ++ py/objfun.c | 29 ++--------------------------- py/objfun.h | 27 +++++++++++++++++++++++++-- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/py/obj.h b/py/obj.h index bd0df3fd682cf..f686fa44ca214 100644 --- a/py/obj.h +++ b/py/obj.h @@ -833,6 +833,8 @@ extern const mp_obj_type_t mp_type_fun_builtin_2; extern const mp_obj_type_t mp_type_fun_builtin_3; extern const mp_obj_type_t mp_type_fun_builtin_var; extern const mp_obj_type_t mp_type_fun_bc; +extern const mp_obj_type_t mp_type_fun_native; +extern const mp_obj_type_t mp_type_fun_asm; extern const mp_obj_type_t mp_type_module; extern const mp_obj_type_t mp_type_staticmethod; extern const mp_obj_type_t mp_type_classmethod; diff --git a/py/objfun.c b/py/objfun.c index 930d0ccdf4f51..ba0ba37068f20 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -137,10 +137,6 @@ STATIC qstr mp_obj_code_get_name(const mp_obj_fun_bc_t *fun, const byte *code_in return name; } -#if MICROPY_EMIT_NATIVE -STATIC const mp_obj_type_t mp_type_fun_native; -#endif - qstr mp_obj_fun_get_name(mp_const_obj_t fun_in) { const mp_obj_fun_bc_t *fun = MP_OBJ_TO_PTR(fun_in); #if MICROPY_EMIT_NATIVE @@ -420,7 +416,7 @@ STATIC mp_obj_t fun_native_call(mp_obj_t self_in, size_t n_args, size_t n_kw, co #define FUN_BC_TYPE_ATTR #endif -STATIC MP_DEFINE_CONST_OBJ_TYPE( +MP_DEFINE_CONST_OBJ_TYPE( mp_type_fun_native, MP_QSTR_function, MP_TYPE_FLAG_BINDS_SELF, @@ -429,12 +425,6 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( call, fun_native_call ); -mp_obj_t mp_obj_new_fun_native(const mp_obj_t *def_args, const void *fun_data, const mp_module_context_t *mc, struct _mp_raw_code_t *const *child_table) { - mp_obj_fun_bc_t *o = MP_OBJ_TO_PTR(mp_obj_new_fun_bc(def_args, (const byte *)fun_data, mc, child_table)); - o->base.type = &mp_type_fun_native; - return MP_OBJ_FROM_PTR(o); -} - #endif // MICROPY_EMIT_NATIVE /******************************************************************************/ @@ -442,13 +432,6 @@ mp_obj_t mp_obj_new_fun_native(const mp_obj_t *def_args, const void *fun_data, c #if MICROPY_EMIT_INLINE_ASM -typedef struct _mp_obj_fun_asm_t { - mp_obj_base_t base; - size_t n_args; - const void *fun_data; // GC must be able to trace this pointer - mp_uint_t type_sig; -} mp_obj_fun_asm_t; - typedef mp_uint_t (*inline_asm_fun_0_t)(void); typedef mp_uint_t (*inline_asm_fun_1_t)(mp_uint_t); typedef mp_uint_t (*inline_asm_fun_2_t)(mp_uint_t, mp_uint_t); @@ -529,19 +512,11 @@ STATIC mp_obj_t fun_asm_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const return mp_native_to_obj(ret, self->type_sig); } -STATIC MP_DEFINE_CONST_OBJ_TYPE( +MP_DEFINE_CONST_OBJ_TYPE( mp_type_fun_asm, MP_QSTR_function, MP_TYPE_FLAG_BINDS_SELF, call, fun_asm_call ); -mp_obj_t mp_obj_new_fun_asm(size_t n_args, const void *fun_data, mp_uint_t type_sig) { - mp_obj_fun_asm_t *o = mp_obj_malloc(mp_obj_fun_asm_t, &mp_type_fun_asm); - o->n_args = n_args; - o->fun_data = fun_data; - o->type_sig = type_sig; - return MP_OBJ_FROM_PTR(o); -} - #endif // MICROPY_EMIT_INLINE_ASM diff --git a/py/objfun.h b/py/objfun.h index 9de15b8841553..b6350d7b67eb5 100644 --- a/py/objfun.h +++ b/py/objfun.h @@ -43,9 +43,32 @@ typedef struct _mp_obj_fun_bc_t { mp_obj_t extra_args[]; } mp_obj_fun_bc_t; +typedef struct _mp_obj_fun_asm_t { + mp_obj_base_t base; + size_t n_args; + const void *fun_data; // GC must be able to trace this pointer + mp_uint_t type_sig; +} mp_obj_fun_asm_t; + mp_obj_t mp_obj_new_fun_bc(const mp_obj_t *def_args, const byte *code, const mp_module_context_t *cm, struct _mp_raw_code_t *const *raw_code_table); -mp_obj_t mp_obj_new_fun_native(const mp_obj_t *def_args, const void *fun_data, const mp_module_context_t *cm, struct _mp_raw_code_t *const *raw_code_table); -mp_obj_t mp_obj_new_fun_asm(size_t n_args, const void *fun_data, mp_uint_t type_sig); void mp_obj_fun_bc_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest); +#if MICROPY_EMIT_NATIVE +static inline mp_obj_t mp_obj_new_fun_native(const mp_obj_t *def_args, const void *fun_data, const mp_module_context_t *mc, struct _mp_raw_code_t *const *child_table) { + mp_obj_fun_bc_t *o = MP_OBJ_TO_PTR(mp_obj_new_fun_bc(def_args, (const byte *)fun_data, mc, child_table)); + o->base.type = &mp_type_fun_native; + return MP_OBJ_FROM_PTR(o); +} +#endif + +#if MICROPY_EMIT_INLINE_ASM +static inline mp_obj_t mp_obj_new_fun_asm(size_t n_args, const void *fun_data, mp_uint_t type_sig) { + mp_obj_fun_asm_t *o = mp_obj_malloc(mp_obj_fun_asm_t, &mp_type_fun_asm); + o->n_args = n_args; + o->fun_data = fun_data; + o->type_sig = type_sig; + return MP_OBJ_FROM_PTR(o); +} +#endif + #endif // MICROPY_INCLUDED_PY_OBJFUN_H From 9400229766624e80db6a6f95af287a5542dc1b43 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 16 Feb 2024 16:52:38 +1100 Subject: [PATCH 147/408] py/objfun: Split viper fun type out to separate mp_type_fun_viper type. Viper functions are quite different to native functions and benefit from being a separate type. For example, viper functions don't have a bytecode- style prelude, and don't support generators or default arguments. Signed-off-by: Damien George --- py/emitglue.c | 4 +++- py/obj.h | 1 + py/objfun.c | 21 +++++++++++++++++++++ py/objfun.h | 10 ++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/py/emitglue.c b/py/emitglue.c index 7dc3080870182..415aa3a3d38de 100644 --- a/py/emitglue.c +++ b/py/emitglue.c @@ -199,13 +199,15 @@ mp_obj_t mp_make_function_from_proto_fun(mp_proto_fun_t proto_fun, const mp_modu switch (rc->kind) { #if MICROPY_EMIT_NATIVE case MP_CODE_NATIVE_PY: - case MP_CODE_NATIVE_VIPER: fun = mp_obj_new_fun_native(def_args, rc->fun_data, context, rc->children); // Check for a generator function, and if so change the type of the object if (rc->is_generator) { ((mp_obj_base_t *)MP_OBJ_TO_PTR(fun))->type = &mp_type_native_gen_wrap; } break; + case MP_CODE_NATIVE_VIPER: + fun = mp_obj_new_fun_viper(rc->fun_data, context, rc->children); + break; #endif #if MICROPY_EMIT_INLINE_ASM case MP_CODE_NATIVE_ASM: diff --git a/py/obj.h b/py/obj.h index f686fa44ca214..9f2bb46e41d74 100644 --- a/py/obj.h +++ b/py/obj.h @@ -834,6 +834,7 @@ extern const mp_obj_type_t mp_type_fun_builtin_3; extern const mp_obj_type_t mp_type_fun_builtin_var; extern const mp_obj_type_t mp_type_fun_bc; extern const mp_obj_type_t mp_type_fun_native; +extern const mp_obj_type_t mp_type_fun_viper; extern const mp_obj_type_t mp_type_fun_asm; extern const mp_obj_type_t mp_type_module; extern const mp_obj_type_t mp_type_staticmethod; diff --git a/py/objfun.c b/py/objfun.c index ba0ba37068f20..1bdbb39166b8d 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -427,6 +427,27 @@ MP_DEFINE_CONST_OBJ_TYPE( #endif // MICROPY_EMIT_NATIVE +/******************************************************************************/ +/* viper functions */ + +#if MICROPY_EMIT_NATIVE + +STATIC mp_obj_t fun_viper_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { + MP_STACK_CHECK(); + mp_obj_fun_bc_t *self = MP_OBJ_TO_PTR(self_in); + mp_call_fun_t fun = MICROPY_MAKE_POINTER_CALLABLE((void *)self->bytecode); + return fun(self_in, n_args, n_kw, args); +} + +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_fun_viper, + MP_QSTR_function, + MP_TYPE_FLAG_BINDS_SELF, + call, fun_viper_call + ); + +#endif // MICROPY_EMIT_NATIVE + /******************************************************************************/ /* inline assembler functions */ diff --git a/py/objfun.h b/py/objfun.h index b6350d7b67eb5..ddb148dd19089 100644 --- a/py/objfun.h +++ b/py/objfun.h @@ -54,11 +54,21 @@ mp_obj_t mp_obj_new_fun_bc(const mp_obj_t *def_args, const byte *code, const mp_ void mp_obj_fun_bc_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest); #if MICROPY_EMIT_NATIVE + static inline mp_obj_t mp_obj_new_fun_native(const mp_obj_t *def_args, const void *fun_data, const mp_module_context_t *mc, struct _mp_raw_code_t *const *child_table) { mp_obj_fun_bc_t *o = MP_OBJ_TO_PTR(mp_obj_new_fun_bc(def_args, (const byte *)fun_data, mc, child_table)); o->base.type = &mp_type_fun_native; return MP_OBJ_FROM_PTR(o); } + +static inline mp_obj_t mp_obj_new_fun_viper(const void *fun_data, const mp_module_context_t *mc, struct _mp_raw_code_t *const *child_table) { + mp_obj_fun_bc_t *o = mp_obj_malloc(mp_obj_fun_bc_t, &mp_type_fun_viper); + o->bytecode = fun_data; + o->context = mc; + o->child_table = child_table; + return MP_OBJ_FROM_PTR(o); +} + #endif #if MICROPY_EMIT_INLINE_ASM From 6d403eb6972b7f6137838d89dba1ae3f76846c8b Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 16 Feb 2024 16:53:47 +1100 Subject: [PATCH 148/408] py/emitnative: Simplify layout and loading of native function prelude. Now native functions and native generators have similar behaviour: the first machine-word of their code is an index to get to the prelude. This simplifies the handling of these types of functions, and also reduces the size of the emitted native machine code by no longer requiring special code at the start of the function to load a pointer to the prelude. Signed-off-by: Damien George --- py/bc.c | 2 +- py/emitnative.c | 15 ++++----------- py/objfun.c | 2 +- py/objfun.h | 28 ++++++++++++++++++++++++++++ py/objgenerator.c | 17 ++++------------- 5 files changed, 38 insertions(+), 26 deletions(-) diff --git a/py/bc.c b/py/bc.c index e1795ce410653..dc70fddf2bca7 100644 --- a/py/bc.c +++ b/py/bc.c @@ -336,9 +336,9 @@ void mp_setup_code_state(mp_code_state_t *code_state, size_t n_args, size_t n_kw // On entry code_state should be allocated somewhere (stack/heap) and // contain the following valid entries: // - code_state->fun_bc should contain a pointer to the function object -// - code_state->ip should contain a pointer to the beginning of the prelude // - code_state->n_state should be the number of objects in the local state void mp_setup_code_state_native(mp_code_state_native_t *code_state, size_t n_args, size_t n_kw, const mp_obj_t *args) { + code_state->ip = mp_obj_fun_native_get_prelude_ptr(code_state->fun_bc); code_state->sp = &code_state->state[0] - 1; mp_setup_code_state_helper((mp_code_state_t *)code_state, n_args, n_kw, args); } diff --git a/py/emitnative.c b/py/emitnative.c index 5f347799e1d9f..6b5c9452ae6aa 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -253,7 +253,6 @@ struct _emit_t { int pass; bool do_viper_types; - bool prelude_offset_uses_u16_encoding; mp_uint_t local_vtype_alloc; vtype_kind_t *local_vtype; @@ -519,8 +518,11 @@ STATIC void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scop // work out size of state (locals plus stack) emit->n_state = scope->num_locals + scope->stack_size; + // Store in the first machine-word an index used to the function's prelude. + // This is used at runtime by mp_obj_fun_native_get_prelude_ptr(). + mp_asm_base_data(&emit->as->base, ASM_WORD_SIZE, (uintptr_t)emit->prelude_ptr_index); + if (emit->scope->scope_flags & MP_SCOPE_FLAG_GENERATOR) { - mp_asm_base_data(&emit->as->base, ASM_WORD_SIZE, (uintptr_t)emit->prelude_ptr_index); mp_asm_base_data(&emit->as->base, ASM_WORD_SIZE, (uintptr_t)emit->start_offset); ASM_ENTRY(emit->as, emit->code_state_start); @@ -576,15 +578,6 @@ STATIC void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scop // Set code_state.fun_bc ASM_MOV_LOCAL_REG(emit->as, LOCAL_IDX_FUN_OBJ(emit), REG_PARENT_ARG_1); - // Set code_state.ip, a pointer to the beginning of the prelude. This pointer is found - // either directly in mp_obj_fun_bc_t.child_table (if there are no children), or in - // mp_obj_fun_bc_t.child_table[num_children] (if num_children > 0). - ASM_LOAD_REG_REG_OFFSET(emit->as, REG_PARENT_ARG_1, REG_PARENT_ARG_1, OFFSETOF_OBJ_FUN_BC_CHILD_TABLE); - if (emit->prelude_ptr_index != 0) { - ASM_LOAD_REG_REG_OFFSET(emit->as, REG_PARENT_ARG_1, REG_PARENT_ARG_1, emit->prelude_ptr_index); - } - emit_native_mov_state_reg(emit, emit->code_state_start + OFFSETOF_CODE_STATE_IP, REG_PARENT_ARG_1); - // Set code_state.n_state (only works on little endian targets due to n_state being uint16_t) emit_native_mov_state_imm_via(emit, emit->code_state_start + OFFSETOF_CODE_STATE_N_STATE, emit->n_state, REG_ARG_1); diff --git a/py/objfun.c b/py/objfun.c index 1bdbb39166b8d..31f4a1f83b148 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -401,7 +401,7 @@ mp_obj_t mp_obj_new_fun_bc(const mp_obj_t *def_args, const byte *code, const mp_ STATIC mp_obj_t fun_native_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { MP_STACK_CHECK(); mp_obj_fun_bc_t *self = MP_OBJ_TO_PTR(self_in); - mp_call_fun_t fun = MICROPY_MAKE_POINTER_CALLABLE((void *)self->bytecode); + mp_call_fun_t fun = mp_obj_fun_native_get_function_start(self); return fun(self_in, n_args, n_kw, args); } diff --git a/py/objfun.h b/py/objfun.h index ddb148dd19089..af7c334858836 100644 --- a/py/objfun.h +++ b/py/objfun.h @@ -69,6 +69,34 @@ static inline mp_obj_t mp_obj_new_fun_viper(const void *fun_data, const mp_modul return MP_OBJ_FROM_PTR(o); } +static inline const uint8_t *mp_obj_fun_native_get_prelude_ptr(const mp_obj_fun_bc_t *fun_native) { + // Obtain a pointer to the start of the function prelude, based on prelude_ptr_index. + uintptr_t prelude_ptr_index = ((uintptr_t *)fun_native->bytecode)[0]; + const uint8_t *prelude_ptr; + if (prelude_ptr_index == 0) { + prelude_ptr = (const uint8_t *)fun_native->child_table; + } else { + prelude_ptr = (const uint8_t *)fun_native->child_table[prelude_ptr_index]; + } + return prelude_ptr; +} + +static inline void *mp_obj_fun_native_get_function_start(const mp_obj_fun_bc_t *fun_native) { + // Obtain a pointer to the start of the function executable machine code. + return MICROPY_MAKE_POINTER_CALLABLE((void *)(fun_native->bytecode + sizeof(uintptr_t))); +} + +static inline void *mp_obj_fun_native_get_generator_start(const mp_obj_fun_bc_t *fun_native) { + // Obtain a pointer to the start of the generator executable machine code. + uintptr_t start_offset = ((uintptr_t *)fun_native->bytecode)[1]; + return MICROPY_MAKE_POINTER_CALLABLE((void *)(fun_native->bytecode + start_offset)); +} + +static inline void *mp_obj_fun_native_get_generator_resume(const mp_obj_fun_bc_t *fun_native) { + // Obtain a pointer to the resume location of the generator executable machine code. + return MICROPY_MAKE_POINTER_CALLABLE((void *)&((uintptr_t *)fun_native->bytecode)[2]); +} + #endif #if MICROPY_EMIT_INLINE_ASM diff --git a/py/objgenerator.c b/py/objgenerator.c index 7786b1fc81b08..e4acd5e49b9cc 100644 --- a/py/objgenerator.c +++ b/py/objgenerator.c @@ -101,13 +101,7 @@ STATIC mp_obj_t native_gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_k mp_obj_fun_bc_t *self_fun = MP_OBJ_TO_PTR(self_in); // Determine start of prelude. - uintptr_t prelude_ptr_index = ((uintptr_t *)self_fun->bytecode)[0]; - const uint8_t *prelude_ptr; - if (prelude_ptr_index == 0) { - prelude_ptr = (void *)self_fun->child_table; - } else { - prelude_ptr = (void *)self_fun->child_table[prelude_ptr_index]; - } + const uint8_t *prelude_ptr = mp_obj_fun_native_get_prelude_ptr(self_fun); // Extract n_state from the prelude. const uint8_t *ip = prelude_ptr; @@ -119,17 +113,14 @@ STATIC mp_obj_t native_gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_k // Parse the input arguments and set up the code state o->pend_exc = mp_const_none; o->code_state.fun_bc = self_fun; - o->code_state.ip = prelude_ptr; o->code_state.n_state = n_state; - o->code_state.sp = &o->code_state.state[0] - 1; mp_setup_code_state_native(&o->code_state, n_args, n_kw, args); // Indicate we are a native function, which doesn't use this variable o->code_state.exc_sp_idx = MP_CODE_STATE_EXC_SP_IDX_SENTINEL; // Prepare the generator instance for execution - uintptr_t start_offset = ((uintptr_t *)self_fun->bytecode)[1]; - o->code_state.ip = MICROPY_MAKE_POINTER_CALLABLE((void *)(self_fun->bytecode + start_offset)); + o->code_state.ip = mp_obj_fun_native_get_generator_start(self_fun); return MP_OBJ_FROM_PTR(o); } @@ -208,9 +199,9 @@ mp_vm_return_kind_t mp_obj_gen_resume(mp_obj_t self_in, mp_obj_t send_value, mp_ #if MICROPY_EMIT_NATIVE if (self->code_state.exc_sp_idx == MP_CODE_STATE_EXC_SP_IDX_SENTINEL) { - // A native generator, with entry point 2 words into the "bytecode" pointer + // A native generator. typedef uintptr_t (*mp_fun_native_gen_t)(void *, mp_obj_t); - mp_fun_native_gen_t fun = MICROPY_MAKE_POINTER_CALLABLE((const void *)(self->code_state.fun_bc->bytecode + 2 * sizeof(uintptr_t))); + mp_fun_native_gen_t fun = mp_obj_fun_native_get_generator_resume(self->code_state.fun_bc); ret_kind = fun((void *)&self->code_state, throw_value); } else #endif From 0c7ccb8807581f3654f70ee9ea86d3ca017f7ea2 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 16 Feb 2024 16:55:39 +1100 Subject: [PATCH 149/408] py/objfun: Support __name__ on native functions and generators. This is now easy to support, since the first machine-word of a native function tells how to find the prelude, from which the function name can be extracted in the same way as for bytecode. Signed-off-by: Damien George --- py/objfun.c | 6 +++--- tests/run-tests.py | 5 +---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/py/objfun.c b/py/objfun.c index 31f4a1f83b148..992c8c784129a 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -139,14 +139,14 @@ STATIC qstr mp_obj_code_get_name(const mp_obj_fun_bc_t *fun, const byte *code_in qstr mp_obj_fun_get_name(mp_const_obj_t fun_in) { const mp_obj_fun_bc_t *fun = MP_OBJ_TO_PTR(fun_in); + const byte *bc = fun->bytecode; + #if MICROPY_EMIT_NATIVE if (fun->base.type == &mp_type_fun_native || fun->base.type == &mp_type_native_gen_wrap) { - // TODO native functions don't have name stored - return MP_QSTR_; + bc = mp_obj_fun_native_get_prelude_ptr(fun); } #endif - const byte *bc = fun->bytecode; MP_BC_PRELUDE_SIG_DECODE(bc); return mp_obj_code_get_name(fun, bc); } diff --git a/tests/run-tests.py b/tests/run-tests.py index ba66eced41aff..70279d379df60 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -643,9 +643,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): # Some tests are known to fail with native emitter # Remove them from the below when they work if args.emit == "native": - skip_tests.update( - {"basics/%s.py" % t for t in "gen_yield_from_close generator_name".split()} - ) # require raise_varargs, generator name + skip_tests.add("basics/gen_yield_from_close.py") # require raise_varargs skip_tests.update( {"basics/async_%s.py" % t for t in "with with2 with_break with_return".split()} ) # require async_with @@ -656,7 +654,6 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): skip_tests.add("basics/del_deref.py") # requires checking for unbound local skip_tests.add("basics/del_local.py") # requires checking for unbound local skip_tests.add("basics/exception_chain.py") # raise from is not supported - skip_tests.add("basics/fun_name.py") # requires proper names for native functions skip_tests.add("basics/scope_implicit.py") # requires checking for unbound local skip_tests.add("basics/sys_tracebacklimit.py") # requires traceback info skip_tests.add("basics/try_finally_return2.py") # requires raise_varargs From 717e3dca1b3ae736a683f8455a23c21192d6de69 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 20 Feb 2024 11:29:46 +1100 Subject: [PATCH 150/408] py/objfun: Inline mp_obj_code_get_name() into mp_obj_fun_get_name(). The former is static and does not need to be a separate function. Signed-off-by: Damien George --- py/objfun.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/py/objfun.c b/py/objfun.c index 992c8c784129a..2e86aaa14d594 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -128,15 +128,6 @@ MP_DEFINE_CONST_OBJ_TYPE( /******************************************************************************/ /* byte code functions */ -STATIC qstr mp_obj_code_get_name(const mp_obj_fun_bc_t *fun, const byte *code_info) { - MP_BC_PRELUDE_SIZE_DECODE(code_info); - mp_uint_t name = mp_decode_uint_value(code_info); - #if MICROPY_EMIT_BYTECODE_USES_QSTR_TABLE - name = fun->context->constants.qstr_table[name]; - #endif - return name; -} - qstr mp_obj_fun_get_name(mp_const_obj_t fun_in) { const mp_obj_fun_bc_t *fun = MP_OBJ_TO_PTR(fun_in); const byte *bc = fun->bytecode; @@ -148,7 +139,14 @@ qstr mp_obj_fun_get_name(mp_const_obj_t fun_in) { #endif MP_BC_PRELUDE_SIG_DECODE(bc); - return mp_obj_code_get_name(fun, bc); + MP_BC_PRELUDE_SIZE_DECODE(bc); + + mp_uint_t name = mp_decode_uint_value(bc); + #if MICROPY_EMIT_BYTECODE_USES_QSTR_TABLE + name = fun->context->constants.qstr_table[name]; + #endif + + return name; } #if MICROPY_CPYTHON_COMPAT From 916ceecaef18ab427bc35158a2281988df2c494c Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 20 Feb 2024 11:31:34 +1100 Subject: [PATCH 151/408] py/emitglue: Remove n_pos_args from DEBUG_printf. This argument was renamed in 39bf055d23be4b0f761af115773c3db1074fc2dd. Signed-off-by: Damien George --- py/emitglue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/emitglue.c b/py/emitglue.c index 415aa3a3d38de..258322724b4a0 100644 --- a/py/emitglue.c +++ b/py/emitglue.c @@ -149,7 +149,7 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void #endif #if DEBUG_PRINT - DEBUG_printf("assign native: kind=%d fun=%p len=" UINT_FMT " n_pos_args=" UINT_FMT " flags=%x\n", kind, fun_data, fun_len, n_pos_args, (uint)scope_flags); + DEBUG_printf("assign native: kind=%d fun=%p len=" UINT_FMT " flags=%x\n", kind, fun_data, fun_len, (uint)scope_flags); for (mp_uint_t i = 0; i < fun_len; i++) { if (i > 0 && i % 16 == 0) { DEBUG_printf("\n"); From 3db29103a4be941293e796da0019178fcd986d36 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 20 Feb 2024 11:41:04 +1100 Subject: [PATCH 152/408] py/builtinevex: Fix setting globals for native functions in compile(). Signed-off-by: Damien George --- py/builtinevex.c | 10 +++++++--- tests/basics/builtin_compile.py | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/py/builtinevex.c b/py/builtinevex.c index 73fca5d39bf52..7737e67f2cd22 100644 --- a/py/builtinevex.c +++ b/py/builtinevex.c @@ -57,9 +57,13 @@ STATIC mp_obj_t code_execute(mp_obj_code_t *self, mp_obj_dict_t *globals, mp_obj // set exception handler to restore context if an exception is raised nlr_push_jump_callback(&ctx.callback, mp_globals_locals_set_from_nlr_jump_callback); - // a bit of a hack: fun_bc will re-set globals, so need to make sure it's - // the correct one - if (mp_obj_is_type(self->module_fun, &mp_type_fun_bc)) { + // The call to mp_parse_compile_execute() in mp_builtin_compile() below passes + // NULL for the globals, so repopulate that entry now with the correct globals. + if (mp_obj_is_type(self->module_fun, &mp_type_fun_bc) + #if MICROPY_EMIT_NATIVE + || mp_obj_is_type(self->module_fun, &mp_type_fun_native) + #endif + ) { mp_obj_fun_bc_t *fun_bc = MP_OBJ_TO_PTR(self->module_fun); ((mp_module_context_t *)fun_bc->context)->module.globals = globals; } diff --git a/tests/basics/builtin_compile.py b/tests/basics/builtin_compile.py index 41dc746ad163c..361d7ec53a729 100644 --- a/tests/basics/builtin_compile.py +++ b/tests/basics/builtin_compile.py @@ -29,6 +29,9 @@ def test(): exec(compile("print(10 + 2)", "file", "single")) print(eval(compile("10 + 3", "file", "eval"))) + # test accessing a function's globals from within a compile + exec(compile("def func():pass\nprint('x', func.__globals__['x'])", "file", "exec")) + # bad mode try: compile('1', 'file', '') From 802a88c3b1599777d53cadb0e4439348fe298a8e Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 14 Feb 2024 16:51:02 +1100 Subject: [PATCH 153/408] stm32/mboot: Generate FLASH_LAYOUT_STR at runtime on H5 MCUs. The size of the flash varies among MCU variants. Instead of requiring a build-time variable to configure this, compute it at runtime using the special device information word accessible through the FLASH_SIZE macro. This feature is currently only implemented for H5 MCUs, but can be extended to others. Signed-off-by: Damien George --- ports/stm32/mboot/main.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/ports/stm32/mboot/main.c b/ports/stm32/mboot/main.c index 2424b37da3a8b..39492b4e5474e 100644 --- a/ports/stm32/mboot/main.c +++ b/ports/stm32/mboot/main.c @@ -435,7 +435,7 @@ void mp_hal_pin_config_speed(uint32_t port_pin, uint32_t speed) { #elif defined(STM32G0) #define FLASH_LAYOUT_STR "@Internal Flash /0x08000000/256*02Kg" MBOOT_SPIFLASH_LAYOUT MBOOT_SPIFLASH2_LAYOUT #elif defined(STM32H5) -#define FLASH_LAYOUT_STR "@Internal Flash /0x08000000/256*08Kg" MBOOT_SPIFLASH_LAYOUT MBOOT_SPIFLASH2_LAYOUT +#define FLASH_LAYOUT_TEMPLATE "@Internal Flash /0x08000000/???*08Kg" MBOOT_SPIFLASH_LAYOUT MBOOT_SPIFLASH2_LAYOUT #elif defined(STM32H743xx) #define FLASH_LAYOUT_STR "@Internal Flash /0x08000000/16*128Kg" MBOOT_SPIFLASH_LAYOUT MBOOT_SPIFLASH2_LAYOUT #elif defined(STM32H750xx) @@ -444,6 +444,25 @@ void mp_hal_pin_config_speed(uint32_t port_pin, uint32_t speed) { #define FLASH_LAYOUT_STR "@Internal Flash /0x08000000/256*04Kg" MBOOT_SPIFLASH_LAYOUT MBOOT_SPIFLASH2_LAYOUT #endif +#if !defined(FLASH_LAYOUT_STR) + +#define FLASH_LAYOUT_STR_ALLOC (sizeof(FLASH_LAYOUT_TEMPLATE)) + +// Build the flash layout string from a template with total flash size inserted. +static size_t build_flash_layout_str(char *buf) { + size_t len = FLASH_LAYOUT_STR_ALLOC - 1; + memcpy(buf, FLASH_LAYOUT_TEMPLATE, len + 1); + unsigned int num_sectors = FLASH_SIZE / FLASH_SECTOR_SIZE; + buf += 31; // location of "???" in FLASH_LAYOUT_TEMPLATE + for (unsigned int i = 0; i < 3; ++i) { + *buf-- = '0' + num_sectors % 10; + num_sectors /= 10; + } + return len; +} + +#endif + static bool flash_is_modifiable_addr_range(uint32_t addr, uint32_t len) { return addr + len < (uint32_t)&_mboot_protected_flash_start || addr >= (uint32_t)&_mboot_protected_flash_end_exclusive; @@ -756,8 +775,12 @@ void i2c_slave_process_rx_end(i2c_slave_t *i2c) { } else if (buf[0] == I2C_CMD_RESET && len == 0) { dfu_context.leave_dfu = true; } else if (buf[0] == I2C_CMD_GETLAYOUT && len == 0) { + #if defined(FLASH_LAYOUT_STR) len = strlen(FLASH_LAYOUT_STR); memcpy(buf, FLASH_LAYOUT_STR, len); + #else + len = build_flash_layout_str(buf); + #endif } else if (buf[0] == I2C_CMD_MASSERASE && len == 0) { len = do_mass_erase(); } else if (buf[0] == I2C_CMD_PAGEERASE && len == 4) { @@ -1161,7 +1184,15 @@ static uint8_t *pyb_usbdd_StrDescriptor(USBD_HandleTypeDef *pdev, uint8_t idx, u } case USBD_IDX_CONFIG_STR: + #if defined(FLASH_LAYOUT_STR) USBD_GetString((uint8_t *)FLASH_LAYOUT_STR, str_desc, length); + #else + { + char buf[FLASH_LAYOUT_STR_ALLOC]; + build_flash_layout_str(buf); + USBD_GetString((uint8_t *)buf, str_desc, length); + } + #endif return str_desc; case MBOOT_ERROR_STR_OVERWRITE_BOOTLOADER_IDX: From d9944983cbc2994a36c47b15595a76a01bed7ecf Mon Sep 17 00:00:00 2001 From: IhorNehrutsa Date: Tue, 30 Jan 2024 15:58:22 +0200 Subject: [PATCH 154/408] esp32/machine_i2c: Fix build warnings when I2C is disabled. Signed-off-by: IhorNehrutsa --- ports/esp32/machine_i2c.c | 4 ++++ 1 file changed, 4 insertions(+) mode change 100644 => 100755 ports/esp32/machine_i2c.c diff --git a/ports/esp32/machine_i2c.c b/ports/esp32/machine_i2c.c old mode 100644 new mode 100755 index eefdeaaf96583..f4cfa58166e06 --- a/ports/esp32/machine_i2c.c +++ b/ports/esp32/machine_i2c.c @@ -32,6 +32,8 @@ #include "driver/i2c.h" #include "hal/i2c_ll.h" +#if MICROPY_PY_MACHINE_I2C || MICROPY_PY_MACHINE_SOFTI2C + #ifndef MICROPY_HW_I2C0_SCL #define MICROPY_HW_I2C0_SCL (GPIO_NUM_18) #define MICROPY_HW_I2C0_SDA (GPIO_NUM_19) @@ -210,3 +212,5 @@ MP_DEFINE_CONST_OBJ_TYPE( protocol, &machine_hw_i2c_p, locals_dict, &mp_machine_i2c_locals_dict ); + +#endif From 31e131bd712ac118074052689e3976aed3564586 Mon Sep 17 00:00:00 2001 From: Trent Piepho Date: Sat, 10 Feb 2024 12:07:46 -0800 Subject: [PATCH 155/408] esp32/machine_hw_spi: Combine argument parsing for constructor and init. This combines the argument parsing and checking for the machine.SPI.init() and machine.SPI() interfaces. The only real difference was unspecified arguments in init() mean to keep the same value, while in new they get default values. Behavior has changed for passing the "id" argument to init(). On other ports this isn't allowed. But on esp32 it would change the SPI controller of the static SPI instance to the new id. This results in multiple static spi objects for the same controller and they would fight over which one has inconsistent mpy vs esp-idf state. This has been changed to not allow "id" with init(), like other ports. In a few causes, a loop is used over arguments that are handled the same way instead of cut & pasting the same stanza of code for each argument. The init_internal function had a lot of arguments, which is not efficient to pass. Pass the args mp_arg_val_t array instead as a single argument. This reduced both the number of C lines and the compiled code size. Summary of code size change: Two argument lists of 72 bytes are replaced by a single shared 72 byte list. New shared argument parsing code is small enough to be inlined, but is still efficient enough to shrink the overall code size by 349 bytes of the three argument handlering functions. add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-349 (-349) Function old new delta machine_hw_spi_make_new 255 203 -52 machine_hw_spi_init 122 67 -55 machine_hw_spi_init_internal 698 456 -242 Total: Before=1227667, After=1227318, chg -0.03% add/remove: 2/0 grow/shrink: 0/2 up/down: 92/-144 (-52) Data old new delta spi_allowed_args - 72 +72 defaults$0 - 20 +20 allowed_args$1 240 168 -72 allowed_args$0 1080 1008 -72 Total: Before=165430, After=165378, chg -0.03% add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0 (0) Signed-off-by: Trent Piepho --- ports/esp32/machine_hw_spi.c | 216 +++++++++++++---------------------- 1 file changed, 80 insertions(+), 136 deletions(-) diff --git a/ports/esp32/machine_hw_spi.c b/ports/esp32/machine_hw_spi.c index 399cb902e8cc6..06e9ec3c8291c 100644 --- a/ports/esp32/machine_hw_spi.c +++ b/ports/esp32/machine_hw_spi.c @@ -80,9 +80,15 @@ #define MP_HW_SPI_MAX_XFER_BITS (MP_HW_SPI_MAX_XFER_BYTES * 8) // Has to be an even multiple of 8 typedef struct _machine_hw_spi_default_pins_t { - int8_t sck; - int8_t mosi; - int8_t miso; + union { + int8_t array[3]; + struct { + // Must be in enum's ARG_sck, ARG_mosi, ARG_miso, etc. order + int8_t sck; + int8_t mosi; + int8_t miso; + } pins; + }; } machine_hw_spi_default_pins_t; typedef struct _machine_hw_spi_obj_t { @@ -106,12 +112,26 @@ typedef struct _machine_hw_spi_obj_t { // Default pin mappings for the hardware SPI instances STATIC const machine_hw_spi_default_pins_t machine_hw_spi_default_pins[MICROPY_HW_SPI_MAX] = { - { .sck = MICROPY_HW_SPI1_SCK, .mosi = MICROPY_HW_SPI1_MOSI, .miso = MICROPY_HW_SPI1_MISO }, + { .pins = { .sck = MICROPY_HW_SPI1_SCK, .mosi = MICROPY_HW_SPI1_MOSI, .miso = MICROPY_HW_SPI1_MISO }}, #ifdef MICROPY_HW_SPI2_SCK - { .sck = MICROPY_HW_SPI2_SCK, .mosi = MICROPY_HW_SPI2_MOSI, .miso = MICROPY_HW_SPI2_MISO }, + { .pins = { .sck = MICROPY_HW_SPI2_SCK, .mosi = MICROPY_HW_SPI2_MOSI, .miso = MICROPY_HW_SPI2_MISO }}, #endif }; +// Common arguments for init() and make new +enum { ARG_id, ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits, ARG_firstbit, ARG_sck, ARG_mosi, ARG_miso }; +static const mp_arg_t spi_allowed_args[] = { + { MP_QSTR_id, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = -1} }, + { MP_QSTR_baudrate, MP_ARG_INT, {.u_int = -1} }, + { MP_QSTR_polarity, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, + { MP_QSTR_phase, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, + { MP_QSTR_bits, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, + { MP_QSTR_firstbit, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, + { MP_QSTR_sck, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_mosi, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_miso, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, +}; + // Static objects mapping to SPI2 (and SPI3 if available) hardware peripherals. STATIC machine_hw_spi_obj_t machine_hw_spi_obj[MICROPY_HW_SPI_MAX]; @@ -147,17 +167,7 @@ STATIC void machine_hw_spi_deinit_internal(machine_hw_spi_obj_t *self) { } } -STATIC void machine_hw_spi_init_internal( - machine_hw_spi_obj_t *self, - int8_t host, - int32_t baudrate, - int8_t polarity, - int8_t phase, - int8_t bits, - int8_t firstbit, - int8_t sck, - int8_t mosi, - int8_t miso) { +STATIC void machine_hw_spi_init_internal(machine_hw_spi_obj_t *self, mp_arg_val_t args[]) { // if we're not initialized, then we're // implicitly 'changed', since this is the init routine @@ -167,52 +177,47 @@ STATIC void machine_hw_spi_init_internal( machine_hw_spi_obj_t old_self = *self; - if (host != -1 && host != self->host) { - self->host = host; - changed = true; - } - - if (baudrate != -1) { + if (args[ARG_baudrate].u_int != -1) { // calculate the actual clock frequency that the SPI peripheral can produce - baudrate = spi_get_actual_clock(APB_CLK_FREQ, baudrate, 0); + uint32_t baudrate = spi_get_actual_clock(APB_CLK_FREQ, args[ARG_baudrate].u_int, 0); if (baudrate != self->baudrate) { self->baudrate = baudrate; changed = true; } } - if (polarity != -1 && polarity != self->polarity) { - self->polarity = polarity; + if (args[ARG_polarity].u_int != -1 && args[ARG_polarity].u_int != self->polarity) { + self->polarity = args[ARG_polarity].u_int; changed = true; } - if (phase != -1 && phase != self->phase) { - self->phase = phase; + if (args[ARG_phase].u_int != -1 && args[ARG_phase].u_int != self->phase) { + self->phase = args[ARG_phase].u_int; changed = true; } - if (bits != -1 && bits != self->bits) { - self->bits = bits; + if (args[ARG_bits].u_int != -1 && args[ARG_bits].u_int != self->bits) { + self->bits = args[ARG_bits].u_int; changed = true; } - if (firstbit != -1 && firstbit != self->firstbit) { - self->firstbit = firstbit; + if (args[ARG_firstbit].u_int != -1 && args[ARG_firstbit].u_int != self->firstbit) { + self->firstbit = args[ARG_firstbit].u_int; changed = true; } - if (sck != -2 && sck != self->sck) { - self->sck = sck; + if (args[ARG_sck].u_int != -2 && args[ARG_sck].u_int != self->sck) { + self->sck = args[ARG_sck].u_int; changed = true; } - if (mosi != -2 && mosi != self->mosi) { - self->mosi = mosi; + if (args[ARG_mosi].u_int != -2 && args[ARG_mosi].u_int != self->mosi) { + self->mosi = args[ARG_mosi].u_int; changed = true; } - if (miso != -2 && miso != self->miso) { - self->miso = miso; + if (args[ARG_miso].u_int != -2 && args[ARG_miso].u_int != self->miso) { + self->miso = args[ARG_miso].u_int; changed = true; } @@ -392,123 +397,62 @@ STATIC void machine_hw_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_p self->sck, self->mosi, self->miso); } -STATIC void machine_hw_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - machine_hw_spi_obj_t *self = (machine_hw_spi_obj_t *)self_in; - - enum { ARG_id, ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits, ARG_firstbit, ARG_sck, ARG_mosi, ARG_miso }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_id, MP_ARG_INT, {.u_int = -1} }, - { MP_QSTR_baudrate, MP_ARG_INT, {.u_int = -1} }, - { MP_QSTR_polarity, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, - { MP_QSTR_phase, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, - { MP_QSTR_bits, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, - { MP_QSTR_firstbit, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, - { MP_QSTR_sck, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { MP_QSTR_mosi, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { MP_QSTR_miso, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - }; - - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), - allowed_args, args); - int8_t sck, mosi, miso; - - if (args[ARG_sck].u_obj == MP_OBJ_NULL) { - sck = -2; - } else if (args[ARG_sck].u_obj == mp_const_none) { - sck = -1; - } else { - sck = machine_pin_get_id(args[ARG_sck].u_obj); +// Take an arg list made from spi_allowed_args, and put in default or "keep same" values +// into all the u_int fields. +// The behavior is slightly different for a new call vs an init method on an existing object. +// Unspecified arguments for new will use defaults, for init they keep the existing value. +STATIC void machine_hw_spi_argcheck(mp_arg_val_t args[], const machine_hw_spi_default_pins_t *default_pins) { +// A non-NULL default_pins argument will trigger the "use default" behavior. + // Replace pin args with default/current values for new vs init call, respectively + for (int i = ARG_sck; i <= ARG_miso; i++) { + if (args[i].u_obj == MP_OBJ_NULL) { + args[i].u_int = default_pins ? default_pins->array[i - ARG_sck] : -2; + } else if (args[i].u_obj == mp_const_none) { + args[i].u_int = -1; + } else { + args[i].u_int = machine_pin_get_id(args[i].u_obj); + } } +} - if (args[ARG_miso].u_obj == MP_OBJ_NULL) { - miso = -2; - } else if (args[ARG_miso].u_obj == mp_const_none) { - miso = -1; - } else { - miso = machine_pin_get_id(args[ARG_miso].u_obj); - } +STATIC void machine_hw_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + machine_hw_spi_obj_t *self = (machine_hw_spi_obj_t *)self_in; - if (args[ARG_mosi].u_obj == MP_OBJ_NULL) { - mosi = -2; - } else if (args[ARG_mosi].u_obj == mp_const_none) { - mosi = -1; - } else { - mosi = machine_pin_get_id(args[ARG_mosi].u_obj); - } + mp_arg_val_t args[MP_ARRAY_SIZE(spi_allowed_args)]; + // offset arg lists by 1 to skip first arg, id, which is not valid for init() + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(spi_allowed_args) - 1, + spi_allowed_args + 1, args + 1); - machine_hw_spi_init_internal(self, args[ARG_id].u_int, args[ARG_baudrate].u_int, - args[ARG_polarity].u_int, args[ARG_phase].u_int, args[ARG_bits].u_int, - args[ARG_firstbit].u_int, sck, mosi, miso); + machine_hw_spi_argcheck(args, NULL); + machine_hw_spi_init_internal(self, args); } mp_obj_t machine_hw_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { MP_MACHINE_SPI_CHECK_FOR_LEGACY_SOFTSPI_CONSTRUCTION(n_args, n_kw, all_args); - enum { ARG_id, ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits, ARG_firstbit, ARG_sck, ARG_mosi, ARG_miso }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_id, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = -1} }, - { MP_QSTR_baudrate, MP_ARG_INT, {.u_int = 500000} }, - { MP_QSTR_polarity, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, - { MP_QSTR_phase, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, - { MP_QSTR_bits, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 8} }, - { MP_QSTR_firstbit, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = MICROPY_PY_MACHINE_SPI_MSB} }, - { MP_QSTR_sck, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { MP_QSTR_mosi, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { MP_QSTR_miso, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - }; - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_val_t args[MP_ARRAY_SIZE(spi_allowed_args)]; + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(spi_allowed_args), spi_allowed_args, args); - machine_hw_spi_obj_t *self; - const machine_hw_spi_default_pins_t *default_pins; - mp_int_t spi_id = args[ARG_id].u_int; + const mp_int_t spi_id = args[ARG_id].u_int; if (1 <= spi_id && spi_id <= MICROPY_HW_SPI_MAX) { - self = &machine_hw_spi_obj[spi_id - 1]; - default_pins = &machine_hw_spi_default_pins[spi_id - 1]; + machine_hw_spi_argcheck(args, &machine_hw_spi_default_pins[spi_id - 1]); } else { mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("SPI(%d) doesn't exist"), spi_id); } - - self->base.type = &machine_spi_type; - - int8_t sck, mosi, miso; - - if (args[ARG_sck].u_obj == MP_OBJ_NULL) { - sck = default_pins->sck; - } else if (args[ARG_sck].u_obj == mp_const_none) { - sck = -1; - } else { - sck = machine_pin_get_id(args[ARG_sck].u_obj); + // Replace -1 non-pin args with default values + static const mp_int_t defaults[] = { 500000, 0, 0, 8, MICROPY_PY_MACHINE_SPI_MSB }; + for (int i = ARG_baudrate; i <= ARG_firstbit; i++) { + if (args[i].u_int == -1) { + args[i].u_int = defaults[i - ARG_baudrate]; + } } - if (args[ARG_mosi].u_obj == MP_OBJ_NULL) { - mosi = default_pins->mosi; - } else if (args[ARG_mosi].u_obj == mp_const_none) { - mosi = -1; - } else { - mosi = machine_pin_get_id(args[ARG_mosi].u_obj); - } + machine_hw_spi_obj_t *self = &machine_hw_spi_obj[spi_id - 1]; + self->host = spi_id; - if (args[ARG_miso].u_obj == MP_OBJ_NULL) { - miso = default_pins->miso; - } else if (args[ARG_miso].u_obj == mp_const_none) { - miso = -1; - } else { - miso = machine_pin_get_id(args[ARG_miso].u_obj); - } + self->base.type = &machine_spi_type; - machine_hw_spi_init_internal( - self, - args[ARG_id].u_int, - args[ARG_baudrate].u_int, - args[ARG_polarity].u_int, - args[ARG_phase].u_int, - args[ARG_bits].u_int, - args[ARG_firstbit].u_int, - sck, - mosi, - miso); + machine_hw_spi_init_internal(self, args); return MP_OBJ_FROM_PTR(self); } From 2962e24167a7416d4caf8d25f463e67b46c3a40a Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Fri, 16 Feb 2024 13:02:28 +1100 Subject: [PATCH 156/408] extmod/vfs_posix_file: Ensure file object has safe default fd. With this commit, if file open fails, the object will have fd = -1 (closed) and the finaliser will not attempt to close anything. Fixes issue #13672. Signed-off-by: Andrew Leech --- extmod/vfs_posix_file.c | 1 + 1 file changed, 1 insertion(+) diff --git a/extmod/vfs_posix_file.c b/extmod/vfs_posix_file.c index 46a866a78aff1..eb9146d47b034 100644 --- a/extmod/vfs_posix_file.c +++ b/extmod/vfs_posix_file.c @@ -92,6 +92,7 @@ mp_obj_t mp_vfs_posix_file_open(const mp_obj_type_t *type, mp_obj_t file_in, mp_ } mp_obj_vfs_posix_file_t *o = mp_obj_malloc_with_finaliser(mp_obj_vfs_posix_file_t, type); + o->fd = -1; // In case open() fails below, initialise this as a "closed" file object. mp_obj_t fid = file_in; From 3deeabe6e87d893196227b41ca997d78783ab14c Mon Sep 17 00:00:00 2001 From: Trent Warlaven Date: Sun, 6 Aug 2023 12:03:47 -0500 Subject: [PATCH 157/408] tests/cpydiff: Add new CPy diff test for class name mangling. Adds new tests/documentation for missing name mangling for private class members. Signed-off-by: Trent Warlaven --- tests/cpydiff/core_class_name_mangling.py | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/cpydiff/core_class_name_mangling.py diff --git a/tests/cpydiff/core_class_name_mangling.py b/tests/cpydiff/core_class_name_mangling.py new file mode 100644 index 0000000000000..39153209debe8 --- /dev/null +++ b/tests/cpydiff/core_class_name_mangling.py @@ -0,0 +1,26 @@ +""" +categories: Core,Classes +description: Private Class Members name mangling is not implemented +cause: The MicroPython compiler does not implement name mangling for private class members. +workaround: Avoid using or having a collision with global names, by adding a unique prefix to the private class member name manually. +""" + + +def __print_string(string): + print(string) + + +class Foo: + def __init__(self, string): + self.string = string + + def do_print(self): + __print_string(self.string) + + +example_string = "Example String to print." + +class_item = Foo(example_string) +print(class_item.string) + +class_item.do_print() From 27670729a5ef341a75d90e34b6979e6b0671e0f3 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 21 Feb 2024 11:36:53 +1100 Subject: [PATCH 158/408] py/compile: Remove TODO about name mangling. This TODO is now covered by the tests/cpydiff/core_class_name_mangling.py test. Signed-off-by: Damien George --- py/compile.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/py/compile.c b/py/compile.c index 8246a9241cad9..fe7ad6e13c307 100644 --- a/py/compile.c +++ b/py/compile.c @@ -41,8 +41,6 @@ #if MICROPY_ENABLE_COMPILER -// TODO need to mangle __attr names - #define INVALID_LABEL (0xffff) typedef enum { From 31e718a6acd03f0cc3db5bc56e465bee933c1edb Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 21 Feb 2024 11:49:06 +1100 Subject: [PATCH 159/408] stm32/mpbthciport: Allow building with MICROPY_PY_MACHINE_UART disabled. Signed-off-by: Damien George --- ports/stm32/mpbthciport.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ports/stm32/mpbthciport.c b/ports/stm32/mpbthciport.c index e764c69844891..06ff8a7faa658 100644 --- a/ports/stm32/mpbthciport.c +++ b/ports/stm32/mpbthciport.c @@ -170,7 +170,12 @@ int mp_bluetooth_hci_uart_init(uint32_t port, uint32_t baudrate) { DEBUG_printf("mp_bluetooth_hci_uart_init (stm32)\n"); // bits (8), stop (1), parity (none) and flow (rts/cts) are assumed to match MYNEWT_VAL_BLE_HCI_UART_ constants in syscfg.h. + #if MICROPY_PY_MACHINE_UART mp_bluetooth_hci_uart_obj.base.type = &machine_uart_type; + #else + // With machine.UART disabled this object is not user-accessible so doesn't need a type. + mp_bluetooth_hci_uart_obj.base.type = NULL; + #endif mp_bluetooth_hci_uart_obj.uart_id = port; mp_bluetooth_hci_uart_obj.is_static = true; // We don't want to block indefinitely, but expect flow control is doing its job. From 01f4e85f1b360d40f8db99aa0db158fa5c2d796e Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 21 Feb 2024 12:00:41 +1100 Subject: [PATCH 160/408] extmod/modmachine: Remove MICROPY_PY_MACHINE guard from header. So this header file can expose declarations for contents of the `machine` module even if that module is disabled. Other parts of the system -- or third-party code -- may need these declarations, for example when a single component like MICROPY_PY_MACHINE_UART is enabled with MICROPY_PY_MACHINE disabled. Signed-off-by: Damien George --- extmod/modmachine.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/extmod/modmachine.h b/extmod/modmachine.h index d186ce661510c..e6b08b3fc9650 100644 --- a/extmod/modmachine.h +++ b/extmod/modmachine.h @@ -30,9 +30,9 @@ #include "py/mphal.h" #include "py/obj.h" -#if MICROPY_PY_MACHINE - +#if MICROPY_PY_MACHINE_SPI || MICROPY_PY_MACHINE_SOFTSPI #include "drivers/bus/spi.h" +#endif // Whether to enable the ADC.init() method. // Requires a port to implement mp_machine_adc_init_helper(). @@ -264,6 +264,4 @@ MP_DECLARE_CONST_FUN_OBJ_2(mp_machine_spi_write_obj); MP_DECLARE_CONST_FUN_OBJ_3(mp_machine_spi_write_readinto_obj); #endif -#endif // MICROPY_PY_MACHINE - #endif // MICROPY_INCLUDED_EXTMOD_MODMACHINE_H From 9e5b6972c767448fb67fa8f13e20b5d3ec2a8673 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 22 Feb 2024 10:49:03 +1100 Subject: [PATCH 161/408] py/emitglue: Make mp_emit_glue_assign_native's fun_data arg a const ptr. It will only ever be read from, and in some cases (eg on esp8266) can actually be in ROM. Signed-off-by: Damien George --- py/emitglue.c | 6 +++--- py/emitglue.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/py/emitglue.c b/py/emitglue.c index 258322724b4a0..6b6d5ccba2195 100644 --- a/py/emitglue.c +++ b/py/emitglue.c @@ -92,7 +92,7 @@ void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code, } #if MICROPY_EMIT_MACHINE_CODE -void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void *fun_data, mp_uint_t fun_len, +void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, const void *fun_data, mp_uint_t fun_len, mp_raw_code_t **children, #if MICROPY_PERSISTENT_CODE_SAVE uint16_t n_children, @@ -115,7 +115,7 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void #endif #elif MICROPY_EMIT_ARM #if (defined(__linux__) && defined(__GNUC__)) || __ARM_ARCH == 7 - __builtin___clear_cache(fun_data, (uint8_t *)fun_data + fun_len); + __builtin___clear_cache((void *)fun_data, (uint8_t *)fun_data + fun_len); #elif defined(__arm__) // Flush I-cache and D-cache. asm volatile ( @@ -154,7 +154,7 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void if (i > 0 && i % 16 == 0) { DEBUG_printf("\n"); } - DEBUG_printf(" %02x", ((byte *)fun_data)[i]); + DEBUG_printf(" %02x", ((const byte *)fun_data)[i]); } DEBUG_printf("\n"); diff --git a/py/emitglue.h b/py/emitglue.h index b7368d697ddf7..0960ee22daec1 100644 --- a/py/emitglue.h +++ b/py/emitglue.h @@ -130,7 +130,7 @@ void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code, #endif uint16_t scope_flags); -void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void *fun_data, mp_uint_t fun_len, +void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, const void *fun_data, mp_uint_t fun_len, mp_raw_code_t **children, #if MICROPY_PERSISTENT_CODE_SAVE uint16_t n_children, From 4f7d0df9bc45ac94f300b84df52b4605bf4609d0 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Tue, 23 Jan 2024 11:53:34 +1100 Subject: [PATCH 162/408] github/ISSUE_TEMPLATE: Convert issue templates to forms. Allows giving more specific advice, provides more links to other places to ask questions, check details, etc. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- .github/ISSUE_TEMPLATE/bug_report.md | 25 ----- .github/ISSUE_TEMPLATE/bug_report.yml | 107 +++++++++++++++++++++ .github/ISSUE_TEMPLATE/documentation.md | 16 --- .github/ISSUE_TEMPLATE/documentation.yml | 44 +++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 24 ----- .github/ISSUE_TEMPLATE/feature_request.yml | 65 +++++++++++++ .github/ISSUE_TEMPLATE/security.md | 16 --- .github/ISSUE_TEMPLATE/security.yml | 59 ++++++++++++ 8 files changed, 275 insertions(+), 81 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml delete mode 100644 .github/ISSUE_TEMPLATE/documentation.md create mode 100644 .github/ISSUE_TEMPLATE/documentation.yml delete mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.yml delete mode 100644 .github/ISSUE_TEMPLATE/security.md create mode 100644 .github/ISSUE_TEMPLATE/security.yml diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index 7bad9562964af..0000000000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,25 +0,0 @@ ---- -name: Bug report -about: Report an issue -title: '' -labels: bug -assignees: '' - ---- - -* Please search existing issues before raising a new issue. For questions about MicroPython or for help using MicroPython, or any sort of "how do I?" requests, please use the Discussions tab or raise a documentation request instead. - -* In your issue, please include a clear and concise description of what the bug is, the expected output, and how to replicate it. - -* If this issue involves external hardware, please include links to relevant datasheets and schematics. - -* If you are seeing code being executed incorrectly, please provide a minimal example and expected output (e.g. comparison to CPython). - -* For build issues, please include full details of your environment, compiler versions, command lines, and build output. - -* Please provide as much information as possible about the version of MicroPython you're running, such as: - - firmware file name - - git commit hash and port/board - - version information shown in the REPL (hit Ctrl-B to see the startup message) - -* Remove all placeholder text above before submitting. diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000000000..c44a140faf0ff --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,107 @@ +name: Bug report +description: Report a bug or unexpected behaviour +labels: ["bug"] +body: + - type: markdown + attributes: + value: | + Please provide as much detail as you can, it really helps us find and fix bugs faster. + + #### Not a bug report? + + * If you have a question \"How Do I ...?\", please post it on [GitHub Discussions](https://github.com/orgs/micropython/discussions/) or [Discord](https://discord.gg/RB8HZSAExQ) instead of here. + * For missing or incorrect documentation, or feature requests, then please [choose a different issue type](https://github.com/micropython/micropython/issues/new/choose). + - type: checkboxes + id: terms + attributes: + label: Checks + description: | + Before submitting your bug report, please go over these check points: + options: + - label: | + I agree to follow the MicroPython [Code of Conduct](https://github.com/micropython/micropython/blob/master/CODEOFCONDUCT.md) to ensure a safe and respectful space for everyone. + required: true + - label: | + I've searched for [existing issues](https://github.com/micropython/micropython/issues) matching this bug, and didn't find any. + required: true + - type: input + id: port-board-hw + attributes: + label: Port, board and/or hardware + description: | + Which MicroPython port(s) and board(s) are you using? + placeholder: | + esp32 port, ESP32-Fantastic board. + validations: + required: true + - type: textarea + id: version + attributes: + label: MicroPython version + description: | + To find the version: + + 1. Open a serial REPL. + 2. Type Ctrl-B to see the startup message. + 3. Copy-paste that output here. + + If the issue is about building MicroPython, please provide output of `git describe --dirty` and as much information as possible about the build environment. + + If the version or configuration is modified from the official MicroPython releases or the master branch, please tell us the details of this as well. + placeholder: | + MicroPython v6.28.3 on 2029-01-23; PyBoard 9 with STM32F9 + validations: + required: true + - type: textarea + id: steps-reproduce + attributes: + label: Reproduction + description: | + What steps will reproduce the problem? Please include all details that could be relevant about the environment, configuration, etc. + + If there is Python code to reproduce this issue then please either: + a. Type it into a code block below ([code block guide](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks)), or + b. Post longer code to a [GitHub gist](https://gist.github.com/), or + c. Create a sample project on GitHub. + + For build issues, please provide the exact build commands that you ran. + placeholder: | + 1. Copy paste the code provided below into a new file + 2. Use `mpremote run` to execute it on the board. + validations: + required: true + - type: textarea + id: expected + attributes: + label: Expected behaviour + description: | + What did you expect MicroPython to do? If comparing output with CPython or a different MicroPython port/version then please provide that output here. + placeholder: | + Expected to print "Hello World". + + Here is the correct output, seen with previous MicroPython version v3.14.159: + + > [...] + - type: textarea + id: what-happened + attributes: + label: Observed behaviour + description: | + What actually happened? Where possible please paste exact output, or the complete build log, etc. Very long output can be linked in a [GitHub gist](https://gist.github.com/). + placeholder: | + This unexpected exception appears: + + > [...] + validations: + required: true + - type: textarea + id: additional + attributes: + label: Additional Information + description: | + Is there anything else that might help to resolve this issue? + value: No, I've provided everything above. + - type: markdown + attributes: + value: | + Thanks for taking the time to help improve MicroPython. diff --git a/.github/ISSUE_TEMPLATE/documentation.md b/.github/ISSUE_TEMPLATE/documentation.md deleted file mode 100644 index e36fa62ac29a4..0000000000000 --- a/.github/ISSUE_TEMPLATE/documentation.md +++ /dev/null @@ -1,16 +0,0 @@ ---- -name: Documentation issue -about: Report areas of the documentation or examples that need improvement -title: 'docs: ' -labels: documentation -assignees: '' - ---- - -* Please search existing issues before raising a new issue. For questions about MicroPython or for help using MicroPython, or any sort of "how do I?" requests, please use the Discussions tab instead. - -* Describe what was missing from the documentation and/or what was incorrect/incomplete. - -* If possible, please link to the relevant page on https://docs.micropython.org/ - -* Remove all placeholder text above before submitting. diff --git a/.github/ISSUE_TEMPLATE/documentation.yml b/.github/ISSUE_TEMPLATE/documentation.yml new file mode 100644 index 0000000000000..5be0241701747 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/documentation.yml @@ -0,0 +1,44 @@ +name: Documentation issue +description: Report areas of the documentation or examples that need improvement +title: "docs: " +labels: ["documentation"] +body: + - type: markdown + attributes: + value: | + This form is for reporting issues with the documentation or examples provided with MicroPython. + + If you have a general question \"How Do I ...?\", please post it on [GitHub Discussions](https://github.com/orgs/micropython/discussions/) or [Discord](https://discord.gg/RB8HZSAExQ) instead of here. + - type: checkboxes + id: terms + attributes: + label: Checks + description: | + Before submitting your bug report, please go over these check points: + options: + - label: | + I agree to follow the MicroPython [Code of Conduct](https://github.com/micropython/micropython/blob/master/CODEOFCONDUCT.md) to ensure a safe and respectful space for everyone. + required: true + - label: | + I've searched for [existing issues](https://github.com/micropython/micropython/issues) and didn't find any that matched. + required: true + - type: input + id: page + attributes: + label: Documentation URL + description: | + Does this issue relate to a particular page in the [online documentation](https://docs.micropython.org/en/latest/)? If yes, please paste the URL of the page: + placeholder: | + https://docs.micropython.org/en/latest/ + - type: textarea + id: version + attributes: + label: Description + description: | + Please describe what was missing from the documentation and/or what was incorrect/incomplete. + validations: + required: true + - type: markdown + attributes: + value: | + Thanks for taking the time to help improve MicroPython. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index 81b55d98e0da8..0000000000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -name: Feature request -about: Request a feature or improvement -title: '' -labels: enhancement -assignees: '' - ---- - -* Please search existing issues before raising a new issue. For questions about MicroPython or for help using MicroPython, or any sort of "how do I?" requests, please use the Discussions tab or raise a documentation request instead. - -* Describe the feature you'd like to see added to MicroPython. In particular, what does this feature enable and why is it useful. MicroPython aims to strike a balance between functionality and code size, so please consider whether this feature can be optionally enabled and whether it can be provided in other ways (e.g. pure-Python library). - -* For core Python features, where possible please include a link to the relevant PEP. - -* For new architectures / ports / boards, please provide links to relevant documentation, specifications, and toolchains. Any information about the popularity and unique features about this hardware would also be useful. - -* For features for existing ports (e.g. new peripherals or microcontroller features), please describe which port(s) it applies too, and whether this is could be an extension to the machine API or a port-specific module? - -* For drivers (e.g. for external hardware), please link to datasheets and/or existing drivers from other sources. - -* Who do you expect will implement the feature you are requesting? Would you be willing to sponsor this work? - -* Remove all placeholder text above before submitting. diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000000000..845fbed810ef9 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,65 @@ +name: Feature request +description: Request a feature or improvement +labels: ['enhancement'] +body: + - type: markdown + attributes: + value: | + This form is for requesting features or improvements in MicroPython. + + #### Get feedback first + + Before submitting a new feature idea here, suggest starting a discussion on [Discord](https://discord.gg/RB8HZSAExQ) or [GitHub Discussions](https://github.com/orgs/micropython/discussions/) to get early feedback from the community and maintainers. + + #### Not a MicroPython core feature? + + * If you have a question \"How Do I ...?\", please post it on GitHub Discussions or Discord instead of here. + * Could this feature be implemented as a pure Python library? If so, please open the request on the [micropython-lib repository](https://github.com/micropython/micropython-lib/issues) instead. + - type: checkboxes + id: terms + attributes: + label: Checks + description: | + Before submitting your feature request, please go over these check points: + options: + - label: | + I agree to follow the MicroPython [Code of Conduct](https://github.com/micropython/micropython/blob/master/CODEOFCONDUCT.md) to ensure a safe and respectful space for everyone. + required: true + - label: | + I've searched for [existing issues](https://github.com/micropython/micropython/issues) regarding this feature, and didn't find any. + required: true + - type: textarea + id: feature + attributes: + label: Description + description: | + Describe the feature you'd like to see added to MicroPython. What does this feature enable and why is it useful? + + * For core Python features, where possible please include a link to the relevant PEP or CPython documentation. + * For new architectures / ports / boards, please provide links to relevant documentation, specifications, and toolchains. Any information about the popularity and unique features about this hardware would also be useful. + * For features for existing ports (e.g. new peripherals or microcontroller features), please describe which port(s) it applies to, and whether this is could be an extension to the machine API or a port-specific module? + * For drivers (e.g. for external hardware), please link to datasheets and/or existing drivers from other sources. + + If there is an existing discussion somewhere about this feature, please add a link to it as well. + validations: + required: true + - type: textarea + id: size + attributes: + label: Code Size + description: | + MicroPython aims to strike a balance between functionality and code size. Can this feature be optionally enabled? + + If you believe the usefulness of this feature would outweigh the additional code size, please explain. (It's OK to say you're unsure here, we're happy to discuss this with you.) + - type: checkboxes + id: implementation + attributes: + label: Implementation + options: + - label: I intend to implement this feature and would submit a Pull Request if desirable. + - label: I hope the MicroPython maintainers or community will implement this feature. + - label: I would like to [Sponsor](https://github.com/sponsors/micropython#sponsors) development of this feature. + - type: markdown + attributes: + value: | + Thanks for taking the time to suggest improvements for MicroPython. diff --git a/.github/ISSUE_TEMPLATE/security.md b/.github/ISSUE_TEMPLATE/security.md deleted file mode 100644 index cfe4a4befdb14..0000000000000 --- a/.github/ISSUE_TEMPLATE/security.md +++ /dev/null @@ -1,16 +0,0 @@ ---- -name: Security report -about: Report a security issue or vulnerability in MicroPython -title: '' -labels: security -assignees: '' - ---- - -* If you need to raise this issue privately with the MicroPython team, please email contact@micropython.org instead. - -* Include a clear and concise description of what the security issue is. - -* What does this issue allow an attacker to do? - -* Remove all placeholder text above before submitting. diff --git a/.github/ISSUE_TEMPLATE/security.yml b/.github/ISSUE_TEMPLATE/security.yml new file mode 100644 index 0000000000000..7d66a72f64120 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/security.yml @@ -0,0 +1,59 @@ +name: Security report +description: Report a security issue or vulnerability in MicroPython +labels: ["security"] +body: + - type: markdown + attributes: + value: | + This form is for reporting security issues in MicroPython that are not readily exploitable. + + 1. For issues that are readily exploitable or have high impact, please email contact@micropython.org instead. + 1. If this is a question about security, please ask it in [Discussions](https://github.com/orgs/micropython/discussions/) or [Discord](https://discord.gg/RB8HZSAExQ) instead. + - type: checkboxes + id: terms + attributes: + label: Checks + description: | + Before submitting your bug report, please go over these check points: + options: + - label: | + I agree to follow the MicroPython [Code of Conduct](https://github.com/micropython/micropython/blob/master/CODEOFCONDUCT.md) to ensure a safe and respectful space for everyone. + required: true + - label: I wish to report a specific security issue that is **not readily exploitable and does not have high impact** for MicroPython developers or users. + required: true + - label: | + I've searched for [existing issues](https://github.com/micropython/micropython/issues) and didn't find any that matched. + required: true + - type: input + id: port-board-hw + attributes: + label: Port, board and/or hardware + description: | + Which MicroPython port(s) and board(s) are you using? + placeholder: | + esp32 port, ESP32-Duper board. + - type: textarea + id: version + attributes: + label: MicroPython version + description: | + To find the version: + + 1. Open a serial REPL. + 2. Type Ctrl-B to see the startup message. + 3. Copy-paste that output here. + + If the version or configuration is modified from the official MicroPython releases or the master branch, please tell us the details of this as well. + placeholder: | + MicroPython v6.28.3 on 2029-01-23; PyBoard 9 with STM32F9 + - type: textarea + id: report + attributes: + label: Issue Report + description: | + Please provide a clear and concise description of the security issue. + + * What does this issue allow an attacker to do? + * How does the attacker exploit this issue? + validations: + required: true From b5edaf68cd2f8bad2dbb3293038a11a9c2108a82 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Tue, 13 Feb 2024 08:52:26 +0100 Subject: [PATCH 163/408] stm32/sdram: Support remapping FMC memory banks. The patch enables SDRAM banks 1 and 2 to be accessible at 0xC0000000 and 0xD0000000 respectively (default mapping) or remapped to addresses 0x60000000 and 0x70000000. Signed-off-by: iabdalkader --- ports/stm32/sdram.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ports/stm32/sdram.c b/ports/stm32/sdram.c index b0a3ef2157139..1e1a08e4c63bd 100644 --- a/ports/stm32/sdram.c +++ b/ports/stm32/sdram.c @@ -34,12 +34,20 @@ #if defined(MICROPY_HW_FMC_SDCKE0) && defined(MICROPY_HW_FMC_SDNE0) #define FMC_SDRAM_BANK FMC_SDRAM_BANK1 #define FMC_SDRAM_CMD_TARGET_BANK FMC_SDRAM_CMD_TARGET_BANK1 +#if MICROPY_HW_FMC_SWAP_BANKS +#define SDRAM_START_ADDRESS 0x60000000 +#else #define SDRAM_START_ADDRESS 0xC0000000 +#endif #elif defined(MICROPY_HW_FMC_SDCKE1) && defined(MICROPY_HW_FMC_SDNE1) #define FMC_SDRAM_BANK FMC_SDRAM_BANK2 #define FMC_SDRAM_CMD_TARGET_BANK FMC_SDRAM_CMD_TARGET_BANK2 +#if MICROPY_HW_FMC_SWAP_BANKS +#define SDRAM_START_ADDRESS 0x70000000 +#else #define SDRAM_START_ADDRESS 0xD0000000 #endif +#endif // Provides the MPU_REGION_SIZE_X value when passed the size of region in bytes // "m" must be a power of 2 between 32 and 4G (2**5 and 2**32) and this formula @@ -59,6 +67,10 @@ bool sdram_init(void) { __HAL_RCC_FMC_CLK_ENABLE(); + #if MICROPY_HW_FMC_SWAP_BANKS + HAL_SetFMCMemorySwappingConfig(FMC_SWAPBMAP_SDRAM_SRAM); + #endif + #if defined(MICROPY_HW_FMC_SDCKE0) mp_hal_pin_config_alt_static_speed(MICROPY_HW_FMC_SDCKE0, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_NONE, MP_HAL_PIN_SPEED_VERY_HIGH, STATIC_AF_FMC_SDCKE0); mp_hal_pin_config_alt_static_speed(MICROPY_HW_FMC_SDNE0, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_NONE, MP_HAL_PIN_SPEED_VERY_HIGH, STATIC_AF_FMC_SDNE0); From 8547a782750c12a163e0cd022fefc2aaaa4b1bb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20D=C3=B6rre?= Date: Wed, 28 Jun 2023 21:46:37 +0000 Subject: [PATCH 164/408] extmod/modwebsocket: Fix websocket to send correct close frame. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the websocket closes currently, it does not send a proper "close"-frame, but rather encodes the 0x8800-sequence inside a binary packet, which is wrong. The close packet is a different kind of websocket frame, according to https://www.rfc-editor.org/rfc/rfc6455. This change resolves an error in Firefox when the websocket closes. Signed-off-by: Felix Dörre --- extmod/modwebsocket.c | 10 ++++++++-- tests/extmod/websocket_basic.py.exp | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/extmod/modwebsocket.c b/extmod/modwebsocket.c index d2cb72039621b..3645b771a5319 100644 --- a/extmod/modwebsocket.c +++ b/extmod/modwebsocket.c @@ -56,6 +56,7 @@ typedef struct _mp_obj_websocket_t { } mp_obj_websocket_t; STATIC mp_uint_t websocket_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode); +STATIC mp_uint_t websocket_write_raw(mp_obj_t self_in, const byte *header, int hdr_sz, const void *buf, mp_uint_t size, int *errcode); STATIC mp_obj_t websocket_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 2, false); @@ -193,9 +194,9 @@ STATIC mp_uint_t websocket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int if (last_state == CONTROL) { byte frame_type = self->last_flags & FRAME_OPCODE_MASK; if (frame_type == FRAME_CLOSE) { - static const char close_resp[2] = {0x88, 0}; + static const byte close_resp[2] = {0x88, 0}; int err; - websocket_write(self_in, close_resp, sizeof(close_resp), &err); + websocket_write_raw(self_in, close_resp, sizeof(close_resp), close_resp, 0, &err); return 0; } @@ -230,6 +231,11 @@ STATIC mp_uint_t websocket_write(mp_obj_t self_in, const void *buf, mp_uint_t si hdr_sz = 4; } + return websocket_write_raw(self_in, header, hdr_sz, buf, size, errcode); +} +STATIC mp_uint_t websocket_write_raw(mp_obj_t self_in, const byte *header, int hdr_sz, const void *buf, mp_uint_t size, int *errcode) { + mp_obj_websocket_t *self = MP_OBJ_TO_PTR(self_in); + mp_obj_t dest[3]; if (self->opts & BLOCKING_WRITE) { mp_load_method(self->sock, MP_QSTR_setblocking, dest); diff --git a/tests/extmod/websocket_basic.py.exp b/tests/extmod/websocket_basic.py.exp index 2d7657b535407..152aae836d6a0 100644 --- a/tests/extmod/websocket_basic.py.exp +++ b/tests/extmod/websocket_basic.py.exp @@ -5,7 +5,7 @@ b'pingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpingpi b'\x81~\x00\x80pongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpongpong' b'\x00\x00\x00\x00' b'' -b'\x81\x02\x88\x00' +b'\x88\x00' b'ping' b'pong' 0 From d2bcb8597e88fccd496b6b0e358347f4bf6a15da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20D=C3=B6rre?= Date: Thu, 22 Feb 2024 01:09:05 +0000 Subject: [PATCH 165/408] extmod/modlwip: Add back support for empty IP addresses. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prior to commit 628abf8f25a7705a2810fffe2ca6ae652c532896 which added IPv6 support, binding a socket with s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(("", PORT)) was possible. But, the empty string is not regarded as a valid IP address by lwip. This commit adds a special case for the empty IP string, restoring the previous CPython-compatible behaviour. Signed-off-by: Felix Dörre --- extmod/modlwip.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/extmod/modlwip.c b/extmod/modlwip.c index a6630c693cad5..f1242b046186f 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -367,8 +367,16 @@ mp_uint_t lwip_parse_inet_addr(mp_obj_t addr_in, ip_addr_t *out_ip) { mp_obj_get_array_fixed_n(addr_in, 2, &addr_items); size_t addr_len; const char *addr_str = mp_obj_str_get_data(addr_items[0], &addr_len); - if (!ipaddr_aton(addr_str, out_ip)) { - mp_raise_ValueError(MP_ERROR_TEXT("invalid arguments")); + if (*addr_str == 0) { + #if LWIP_IPV6 + *out_ip = *IP6_ADDR_ANY; + #else + *out_ip = *IP_ADDR_ANY; + #endif + } else { + if (!ipaddr_aton(addr_str, out_ip)) { + mp_raise_ValueError(MP_ERROR_TEXT("invalid arguments")); + } } return mp_obj_get_int(addr_items[1]); } From 8fdcc25eb07731a64077b7576c5d477cf81e2dd5 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Thu, 22 Feb 2024 20:50:03 +0100 Subject: [PATCH 166/408] py/mpconfig: Change the default enable level for the vfs module. For boards with MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES and up. This gets samd21 boards working (which need the vfs module in _boot.py), B_L072Z_LRWAN1, and nrf boards with smaller MCUs that use CORE or BASIC feature levels. Signed-off-by: robert-hh --- py/mpconfig.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/mpconfig.h b/py/mpconfig.h index 837115ab59f99..e7b72c642274f 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1746,7 +1746,7 @@ typedef double mp_float_t; // Whether to provide the "vfs" module #ifndef MICROPY_PY_VFS -#define MICROPY_PY_VFS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES && MICROPY_VFS) +#define MICROPY_PY_VFS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES && MICROPY_VFS) #endif #ifndef MICROPY_PY_WEBSOCKET From 8692d2602a7775fea22d75ebf5b50971dc2b968f Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 26 Feb 2024 10:52:12 +1100 Subject: [PATCH 167/408] extmod/asyncio: Make current_task raise exception when there is no task. Matches CPython behaviour. Fixes issue #11530. Signed-off-by: Damien George --- extmod/asyncio/core.py | 5 +++++ tests/extmod/asyncio_current_task.py | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/extmod/asyncio/core.py b/extmod/asyncio/core.py index e5af3038f77bb..8aad234514b0c 100644 --- a/extmod/asyncio/core.py +++ b/extmod/asyncio/core.py @@ -164,6 +164,7 @@ def run_until_complete(main_task=None): dt = max(0, ticks_diff(t.ph_key, ticks())) elif not _io_queue.map: # No tasks can be woken so finished running + cur_task = None return # print('(poll {})'.format(dt), len(_io_queue.map)) _io_queue.wait_io_event(dt) @@ -188,6 +189,7 @@ def run_until_complete(main_task=None): assert t.data is None # This task is done, check if it's the main task and then loop should stop if t is main_task: + cur_task = None if isinstance(er, StopIteration): return er.value raise er @@ -242,6 +244,7 @@ async def _stopper(): pass +cur_task = None _stop_task = None @@ -291,6 +294,8 @@ def get_event_loop(runq_len=0, waitq_len=0): def current_task(): + if cur_task is None: + raise RuntimeError("no running event loop") return cur_task diff --git a/tests/extmod/asyncio_current_task.py b/tests/extmod/asyncio_current_task.py index 18058230f2d90..a25e543d0c5b1 100644 --- a/tests/extmod/asyncio_current_task.py +++ b/tests/extmod/asyncio_current_task.py @@ -19,4 +19,15 @@ async def main(): print(t is result[0]) +try: + print(asyncio.current_task()) +except RuntimeError: + print("RuntimeError") + + asyncio.run(main()) + +try: + print(asyncio.current_task()) +except RuntimeError: + print("RuntimeError") From 9a4be7d7b36b55fba5584d0ffb751e6b431324cc Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 29 Feb 2024 11:15:37 +1100 Subject: [PATCH 168/408] py/emitbc: Remove call to adjust Python stack by 0 entries. This call used to be needed when there was an `emit_bc_pre()` function that needed to be called at the start of each emitted bytecode. But in 8e7745eb315cdaf7dec033891f88e091ab4e016e that function was removed and now the call to `mp_emit_bc_adjust_stack_size()` does nothing when adjusting by 0 entries, so it can be removed. Signed-off-by: Damien George --- py/emitbc.c | 1 - 1 file changed, 1 deletion(-) diff --git a/py/emitbc.c b/py/emitbc.c index ca5f07085b84d..85fc5f218b0af 100644 --- a/py/emitbc.c +++ b/py/emitbc.c @@ -448,7 +448,6 @@ void mp_emit_bc_label_assign(emit_t *emit, mp_uint_t l) { // should be emitted (until another unconditional flow control). emit->suppress = false; - mp_emit_bc_adjust_stack_size(emit, 0); if (emit->pass == MP_PASS_SCOPE) { return; } From b91b2a7fe912944b74ff7e7b3e38611ea0fe78ee Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 29 Feb 2024 13:33:51 +1100 Subject: [PATCH 169/408] py/mpstate: Don't declare mp_thread_get_state(). It's instead declared by the include of `py/mpthread.h`. Signed-off-by: Damien George --- py/mpstate.h | 1 - 1 file changed, 1 deletion(-) diff --git a/py/mpstate.h b/py/mpstate.h index 0e0388e410ac9..af55e764f6cdc 100644 --- a/py/mpstate.h +++ b/py/mpstate.h @@ -310,7 +310,6 @@ extern mp_state_ctx_t mp_state_ctx; #define MP_STATE_MAIN_THREAD(x) (mp_state_ctx.thread.x) #if MICROPY_PY_THREAD -extern mp_state_thread_t *mp_thread_get_state(void); #define MP_STATE_THREAD(x) (mp_thread_get_state()->x) #define mp_thread_is_main_thread() (mp_thread_get_state() == &mp_state_ctx.thread) #else From a30c29398a6f38ae7ba3964841892e3e9b60aa0c Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 29 Feb 2024 13:35:36 +1100 Subject: [PATCH 170/408] ports: Don't include mpthread.h in mpthreadport.h. Because `mpthreadport.h` is included by `mpthread.h`. Also remove unnecessary include of `mpthreadport.h` in esp32's `main.c`. Signed-off-by: Damien George --- ports/esp32/main.c | 1 - ports/renesas-ra/mpthreadport.h | 1 - ports/rp2/mpthreadport.h | 1 - ports/stm32/mpthreadport.h | 1 - 4 files changed, 4 deletions(-) diff --git a/ports/esp32/main.c b/ports/esp32/main.c index 6f51b7236bce9..6fb15d3cc8906 100644 --- a/ports/esp32/main.c +++ b/ports/esp32/main.c @@ -59,7 +59,6 @@ #include "usb_serial_jtag.h" #include "modmachine.h" #include "modnetwork.h" -#include "mpthreadport.h" #if MICROPY_BLUETOOTH_NIMBLE #include "extmod/modbluetooth.h" diff --git a/ports/renesas-ra/mpthreadport.h b/ports/renesas-ra/mpthreadport.h index e2b39979fb4c8..a68c00e1f838b 100644 --- a/ports/renesas-ra/mpthreadport.h +++ b/ports/renesas-ra/mpthreadport.h @@ -24,7 +24,6 @@ * THE SOFTWARE. */ -#include "py/mpthread.h" #include "pybthread.h" typedef pyb_mutex_t mp_thread_mutex_t; diff --git a/ports/rp2/mpthreadport.h b/ports/rp2/mpthreadport.h index 868f8d14118dd..7982de96a8deb 100644 --- a/ports/rp2/mpthreadport.h +++ b/ports/rp2/mpthreadport.h @@ -26,7 +26,6 @@ #ifndef MICROPY_INCLUDED_RP2_MPTHREADPORT_H #define MICROPY_INCLUDED_RP2_MPTHREADPORT_H -#include "py/mpthread.h" #include "pico/mutex.h" typedef struct mutex mp_thread_mutex_t; diff --git a/ports/stm32/mpthreadport.h b/ports/stm32/mpthreadport.h index e2b39979fb4c8..a68c00e1f838b 100644 --- a/ports/stm32/mpthreadport.h +++ b/ports/stm32/mpthreadport.h @@ -24,7 +24,6 @@ * THE SOFTWARE. */ -#include "py/mpthread.h" #include "pybthread.h" typedef pyb_mutex_t mp_thread_mutex_t; From 56f9dcb580a6ee6c10f6db59a72e3b216e4e4dfc Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 29 Feb 2024 14:16:05 +1100 Subject: [PATCH 171/408] tests/multi_bluetooth: Move ble_deepsleep to stress_deepsleep_reconnect. This test cannot run on boards that have a native USB REPL, so rename it to indicate that its "special". This makes it easier to run a subset of tests, for example: ./run-multitests.py multi_bluetooth/ble*.py ./run-multitests.py multi_bluetooth/perf*.py ./run-multitests.py multi_bluetooth/stress*.py Signed-off-by: Damien George --- .../{ble_deepsleep.py => stress_deepsleep_reconnect.py} | 0 .../{ble_deepsleep.py.exp => stress_deepsleep_reconnect.py.exp} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/multi_bluetooth/{ble_deepsleep.py => stress_deepsleep_reconnect.py} (100%) rename tests/multi_bluetooth/{ble_deepsleep.py.exp => stress_deepsleep_reconnect.py.exp} (100%) diff --git a/tests/multi_bluetooth/ble_deepsleep.py b/tests/multi_bluetooth/stress_deepsleep_reconnect.py similarity index 100% rename from tests/multi_bluetooth/ble_deepsleep.py rename to tests/multi_bluetooth/stress_deepsleep_reconnect.py diff --git a/tests/multi_bluetooth/ble_deepsleep.py.exp b/tests/multi_bluetooth/stress_deepsleep_reconnect.py.exp similarity index 100% rename from tests/multi_bluetooth/ble_deepsleep.py.exp rename to tests/multi_bluetooth/stress_deepsleep_reconnect.py.exp From 3460b48a6d3af423e8592add99432172523639ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20de=20Giessen?= Date: Fri, 8 Dec 2023 18:57:07 +0100 Subject: [PATCH 172/408] extmod/nimble: Override configuration options set in nimble_port_init. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This moves the runtime initialisation of `ble_hs_cfg` to happen after `nimble_port_init()`. That is consistent with the order used in NimBLE examples. On the ESP32 port this is needed because the ESP-IDF sets up the default RAM secret store callbacks in its implementation of `nimble_port_init()` (specifically, it calls `esp_nimble_init()` which in turn calls `ble_store_ram_init()`). We want to override those with our own callbacks to implement the `IRQ_[GS]ET_SECRET` events in Python. Signed-off-by: Daniël van de Giessen --- extmod/nimble/modbluetooth_nimble.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/extmod/nimble/modbluetooth_nimble.c b/extmod/nimble/modbluetooth_nimble.c index c053ac56cf2ba..b4610564cd33c 100644 --- a/extmod/nimble/modbluetooth_nimble.c +++ b/extmod/nimble/modbluetooth_nimble.c @@ -592,17 +592,6 @@ int mp_bluetooth_init(void) { mp_bluetooth_nimble_ble_state = MP_BLUETOOTH_NIMBLE_BLE_STATE_STARTING; - ble_hs_cfg.reset_cb = reset_cb; - ble_hs_cfg.sync_cb = sync_cb; - ble_hs_cfg.gatts_register_cb = gatts_register_cb; - ble_hs_cfg.store_status_cb = ble_store_util_status_rr; - - #if MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING - ble_hs_cfg.store_read_cb = ble_secret_store_read; - ble_hs_cfg.store_write_cb = ble_secret_store_write; - ble_hs_cfg.store_delete_cb = ble_secret_store_delete; - #endif // MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING - MP_STATE_PORT(bluetooth_nimble_root_pointers) = m_new0(mp_bluetooth_nimble_root_pointers_t, 1); mp_bluetooth_gatts_db_create(&MP_STATE_PORT(bluetooth_nimble_root_pointers)->gatts_db); @@ -622,6 +611,17 @@ int mp_bluetooth_init(void) { DEBUG_printf("mp_bluetooth_init: nimble_port_init\n"); nimble_port_init(); + ble_hs_cfg.reset_cb = reset_cb; + ble_hs_cfg.sync_cb = sync_cb; + ble_hs_cfg.gatts_register_cb = gatts_register_cb; + ble_hs_cfg.store_status_cb = ble_store_util_status_rr; + + #if MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING + ble_hs_cfg.store_read_cb = ble_secret_store_read; + ble_hs_cfg.store_write_cb = ble_secret_store_write; + ble_hs_cfg.store_delete_cb = ble_secret_store_delete; + #endif // MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING + // Make sure that the HCI UART and event handling task is running. mp_bluetooth_nimble_port_start(); From d1e15b928107e2459b65c7a2484517e9e2a830cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20de=20Giessen?= Date: Tue, 12 Dec 2023 15:56:13 +0100 Subject: [PATCH 173/408] extmod/nimble: Enable key distribution to support bonding. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This sets the BLE key distribution parameters at runtime. This isn't needed in most ports since we already set the default values in `extmod/nimble/syscfg/syscfg.h`; however in the ESP32 port that headerfile is not used, and the default values in the ESP-IDF don't enable key distribution nor can we change those defaults via `sdkconfig`. Thus we're setting these values explicitly at runtime. Signed-off-by: Daniël van de Giessen --- extmod/nimble/modbluetooth_nimble.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extmod/nimble/modbluetooth_nimble.c b/extmod/nimble/modbluetooth_nimble.c index b4610564cd33c..5bab43a0ccea0 100644 --- a/extmod/nimble/modbluetooth_nimble.c +++ b/extmod/nimble/modbluetooth_nimble.c @@ -617,6 +617,8 @@ int mp_bluetooth_init(void) { ble_hs_cfg.store_status_cb = ble_store_util_status_rr; #if MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING + ble_hs_cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID | BLE_SM_PAIR_KEY_DIST_SIGN; + ble_hs_cfg.sm_their_key_dist = BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID | BLE_SM_PAIR_KEY_DIST_SIGN; ble_hs_cfg.store_read_cb = ble_secret_store_read; ble_hs_cfg.store_write_cb = ble_secret_store_write; ble_hs_cfg.store_delete_cb = ble_secret_store_delete; From 678707c8b07323c5b914778708a2858387c3b60c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20de=20Giessen?= Date: Fri, 22 Dec 2023 16:30:04 +0100 Subject: [PATCH 174/408] docs/library/bluetooth: Add note that ESP32 supports pairing/bonding. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pairing and bonding was fixed for the ESP32 in the two previous commits. Signed-off-by: Daniël van de Giessen --- docs/library/bluetooth.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/library/bluetooth.rst b/docs/library/bluetooth.rst index fb3c23400e51d..f8b154dd11448 100644 --- a/docs/library/bluetooth.rst +++ b/docs/library/bluetooth.rst @@ -722,7 +722,7 @@ Pairing and bonding and ``_IRQ_SET_SECRET`` events. **Note:** This is currently only supported when using the NimBLE stack on - STM32 and Unix (not ESP32). + ESP32, STM32 and Unix. .. method:: BLE.gap_pair(conn_handle, /) From bc424ddc4165ffd8203b4e781f7c686598601e15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20de=20Giessen?= Date: Wed, 28 Feb 2024 12:41:41 +0100 Subject: [PATCH 175/408] py/modthread: Move thread state initialisation to shared function. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniël van de Giessen --- extmod/modbluetooth.c | 10 +--------- py/modthread.c | 15 +-------------- py/runtime.h | 27 +++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/extmod/modbluetooth.c b/extmod/modbluetooth.c index 32a15bf511acb..91e4e622132d5 100644 --- a/extmod/modbluetooth.c +++ b/extmod/modbluetooth.c @@ -34,7 +34,6 @@ #include "py/objarray.h" #include "py/qstr.h" #include "py/runtime.h" -#include "py/stackctrl.h" #include "extmod/modbluetooth.h" #include @@ -1272,14 +1271,7 @@ STATIC mp_obj_t invoke_irq_handler(uint16_t event, mp_state_thread_t ts; if (ts_orig == NULL) { - mp_thread_set_state(&ts); - mp_stack_set_top(&ts + 1); // need to include ts in root-pointer scan - mp_stack_set_limit(MICROPY_PY_BLUETOOTH_SYNC_EVENT_STACK_SIZE); - ts.gc_lock_depth = 0; - ts.nlr_jump_callback_top = NULL; - ts.mp_pending_exception = MP_OBJ_NULL; - mp_locals_set(mp_state_ctx.thread.dict_locals); // set from the outer context - mp_globals_set(mp_state_ctx.thread.dict_globals); // set from the outer context + mp_thread_init_state(&ts, MICROPY_PY_BLUETOOTH_SYNC_EVENT_STACK_SIZE, NULL, NULL); MP_THREAD_GIL_ENTER(); } diff --git a/py/modthread.c b/py/modthread.c index 3a8a1e03ce12b..9fc20570be1f0 100644 --- a/py/modthread.c +++ b/py/modthread.c @@ -160,10 +160,7 @@ STATIC void *thread_entry(void *args_in) { thread_entry_args_t *args = (thread_entry_args_t *)args_in; mp_state_thread_t ts; - mp_thread_set_state(&ts); - - mp_stack_set_top(&ts + 1); // need to include ts in root-pointer scan - mp_stack_set_limit(args->stack_size); + mp_thread_init_state(&ts, args->stack_size, args->dict_locals, args->dict_globals); #if MICROPY_ENABLE_PYSTACK // TODO threading and pystack is not fully supported, for now just make a small stack @@ -171,16 +168,6 @@ STATIC void *thread_entry(void *args_in) { mp_pystack_init(mini_pystack, &mini_pystack[128]); #endif - // The GC starts off unlocked on this thread. - ts.gc_lock_depth = 0; - - ts.nlr_jump_callback_top = NULL; - ts.mp_pending_exception = MP_OBJ_NULL; - - // set locals and globals from the calling context - mp_locals_set(args->dict_locals); - mp_globals_set(args->dict_globals); - MP_THREAD_GIL_ENTER(); // signal that we are set up and running diff --git a/py/runtime.h b/py/runtime.h index a04d4584f804c..5465c06d8aee9 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -28,6 +28,7 @@ #include "py/mpstate.h" #include "py/pystack.h" +#include "py/stackctrl.h" // For use with mp_call_function_1_from_nlr_jump_callback. #define MP_DEFINE_NLR_JUMP_CALLBACK_FUNCTION_1(ctx, f, a) \ @@ -154,6 +155,32 @@ static inline void mp_globals_set(mp_obj_dict_t *d) { void mp_globals_locals_set_from_nlr_jump_callback(void *ctx_in); void mp_call_function_1_from_nlr_jump_callback(void *ctx_in); +#if MICROPY_PY_THREAD +static inline void mp_thread_init_state(mp_state_thread_t *ts, size_t stack_size, mp_obj_dict_t *locals, mp_obj_dict_t *globals) { + mp_thread_set_state(ts); + + mp_stack_set_top(ts + 1); // need to include ts in root-pointer scan + mp_stack_set_limit(stack_size); + + // GC starts off unlocked + ts->gc_lock_depth = 0; + + // There are no pending jump callbacks or exceptions yet + ts->nlr_jump_callback_top = NULL; + ts->mp_pending_exception = MP_OBJ_NULL; + + // If locals/globals are not given, inherit from main thread + if (locals == NULL) { + locals = mp_state_ctx.thread.dict_locals; + } + if (globals == NULL) { + globals = mp_state_ctx.thread.dict_globals; + } + mp_locals_set(locals); + mp_globals_set(globals); +} +#endif + mp_obj_t mp_load_name(qstr qst); mp_obj_t mp_load_global(qstr qst); mp_obj_t mp_load_build_class(void); From 7d5f697c38629ceee5aa169f5b776de40c37a244 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 4 Mar 2024 10:27:07 +1100 Subject: [PATCH 176/408] py/emitglue: Add explicit cast of proto_fun to uint8_t pointer. Otherwise C++ compilers may complain when this header is included in an extern "C" block. Signed-off-by: Damien George --- py/emitglue.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/emitglue.h b/py/emitglue.h index 0960ee22daec1..126462671b003 100644 --- a/py/emitglue.h +++ b/py/emitglue.h @@ -63,7 +63,7 @@ typedef const void *mp_proto_fun_t; // is guaranteed to have either its first or second byte non-zero. So if both bytes are // zero then the mp_proto_fun_t pointer must be an mp_raw_code_t. static inline bool mp_proto_fun_is_bytecode(mp_proto_fun_t proto_fun) { - const uint8_t *header = proto_fun; + const uint8_t *header = (const uint8_t *)proto_fun; return (header[0] | (header[1] << 8)) != (MP_PROTO_FUN_INDICATOR_RAW_CODE_0 | (MP_PROTO_FUN_INDICATOR_RAW_CODE_1 << 8)); } From 90e517862d055b8ec95a0c7067052c0ba6cd0df1 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 4 Mar 2024 11:33:00 +1100 Subject: [PATCH 177/408] webassembly/Makefile: Remove --memory-init-file from linker options. It's no longer supported by Emscripten (at least at 3.1.55). And it's not needed when the output is WASM, which it is by default. Signed-off-by: Damien George --- ports/webassembly/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/ports/webassembly/Makefile b/ports/webassembly/Makefile index 450ef87680775..c5ee80fe0046f 100644 --- a/ports/webassembly/Makefile +++ b/ports/webassembly/Makefile @@ -38,7 +38,6 @@ OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) JSFLAGS += -s ASYNCIFY JSFLAGS += -s EXPORTED_FUNCTIONS="['_mp_js_init', '_mp_js_init_repl', '_mp_js_do_str', '_mp_js_process_char', '_mp_hal_get_interrupt_char', '_mp_sched_keyboard_interrupt']" JSFLAGS += -s EXPORTED_RUNTIME_METHODS="['ccall', 'cwrap', 'FS']" -JSFLAGS += -s --memory-init-file 0 JSFLAGS += --js-library library.js all: $(BUILD)/micropython.js From ab6d59d7bd2cee972afd917e41347f269693fed9 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 7 Mar 2024 14:07:00 +1100 Subject: [PATCH 178/408] lib/cyw43-driver: Update driver to latest version v1.0.3. Includes various bug fixes. Signed-off-by: Damien George --- lib/cyw43-driver | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cyw43-driver b/lib/cyw43-driver index 2ab0db6e1fe92..9f6405f0b3260 160000 --- a/lib/cyw43-driver +++ b/lib/cyw43-driver @@ -1 +1 @@ -Subproject commit 2ab0db6e1fe9265fa9802a95f7f4d60b7f0d655a +Subproject commit 9f6405f0b3260968306d782e1c5ac275a46dc65d From b3f2f18f927fa2fad10daf63d8c391331f5edf58 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 7 Mar 2024 14:12:15 +1100 Subject: [PATCH 179/408] renesas-ra: Fix spelling mistakes found by codespell. And enable codespell for this port in `pyproject.toml`. Signed-off-by: Damien George --- ports/renesas-ra/Makefile | 2 +- ports/renesas-ra/README.md | 2 +- ports/renesas-ra/boards/EK_RA4M1/mpconfigboard.h | 2 +- ports/renesas-ra/fsp_cfg/r_sci_uart_cfg.h | 2 +- ports/renesas-ra/machine_dac.c | 2 +- ports/renesas-ra/machine_pwm.c | 2 +- ports/renesas-ra/pendsv.c | 2 +- ports/renesas-ra/ra/ra_i2c.c | 2 +- ports/renesas-ra/ra/ra_icu.c | 2 +- ports/renesas-ra/ra/ra_sci.c | 10 +++++----- ports/renesas-ra/systick.c | 2 +- ports/renesas-ra/timer.c | 4 ++-- pyproject.toml | 1 - 13 files changed, 17 insertions(+), 18 deletions(-) diff --git a/ports/renesas-ra/Makefile b/ports/renesas-ra/Makefile index 1e9cd2db5ba19..f8b46fe453902 100644 --- a/ports/renesas-ra/Makefile +++ b/ports/renesas-ra/Makefile @@ -484,7 +484,7 @@ FILE2H = $(TOP)/tools/file2h.py # List of sources for qstr extraction SRC_QSTR += $(SRC_C) $(SRC_CXX) $(SHARED_SRC_C) $(GEN_PINS_SRC) -# Making OBJ use an order-only depenedency on the generated pins.h file +# Making OBJ use an order-only dependency on the generated pins.h file # has the side effect of making the pins.h file before we actually compile # any of the objects. The normal dependency generation will deal with the # case when pins.h is modified. But when it doesn't exist, we don't know diff --git a/ports/renesas-ra/README.md b/ports/renesas-ra/README.md index 77b952178d61f..4b3a7696faeb3 100644 --- a/ports/renesas-ra/README.md +++ b/ports/renesas-ra/README.md @@ -63,7 +63,7 @@ passed as the argument to `BOARD=`; for example `RA4M1_CLICKER`, `EK_RA4M1`, The above command should produce binary images `firmware.hex` in the build-EK_RA6M2/` subdirectory (or the equivalent directory for the board specified). -## Supported/Unsupprted funtions +## Supported/Unsupported functions Please refer to the `renesas-ra` quick reference. ## Known issues diff --git a/ports/renesas-ra/boards/EK_RA4M1/mpconfigboard.h b/ports/renesas-ra/boards/EK_RA4M1/mpconfigboard.h index e7cce5e24a7fa..db4d2d9d63d0f 100644 --- a/ports/renesas-ra/boards/EK_RA4M1/mpconfigboard.h +++ b/ports/renesas-ra/boards/EK_RA4M1/mpconfigboard.h @@ -40,7 +40,7 @@ // I2C (not supported) // #define MICROPY_HW_I2C0_SCL (pin_P204) // Conflict with SPI1 // #define MICROPY_HW_I2C0_SDA (pin_P407) // Conflict with USB_VBUS -// #define MICROPY_HW_I2C0_SCL (pin_P400) // Conflict wiht PMOD B (GPIO) +// #define MICROPY_HW_I2C0_SCL (pin_P400) // Conflict with PMOD B (GPIO) // #define MICROPY_HW_I2C0_SDA (pin_P401) // Conflict with PMOD B (TXD1) // #define MICROPY_HW_I2C1_SCL (pin_P100) // Conflict with PMOD A (MISOA_A) // #define MICROPY_HW_I2C1_SDA (pin_P101) // Conflict with PMOD A (MOSIA_A) diff --git a/ports/renesas-ra/fsp_cfg/r_sci_uart_cfg.h b/ports/renesas-ra/fsp_cfg/r_sci_uart_cfg.h index bbc6dc5522c60..578025041e202 100644 --- a/ports/renesas-ra/fsp_cfg/r_sci_uart_cfg.h +++ b/ports/renesas-ra/fsp_cfg/r_sci_uart_cfg.h @@ -11,7 +11,7 @@ extern "C" { #define SCI_UART_CFG_RS485_SUPPORT (0) /* - * Disable r_sci_uart.c's interrupt handlers by defining followings + * Disable r_sci_uart.c's interrupt handlers by defining following * because the renesas-ra has own interrupt handlers for SCI and * symbol conflict happens. */ diff --git a/ports/renesas-ra/machine_dac.c b/ports/renesas-ra/machine_dac.c index 6fd23c23889db..0d9c779497588 100644 --- a/ports/renesas-ra/machine_dac.c +++ b/ports/renesas-ra/machine_dac.c @@ -54,7 +54,7 @@ STATIC machine_dac_obj_t machine_dac_obj[] = { STATIC void machine_dac_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_dac_obj_t *self = MP_OBJ_TO_PTR(self_in); // const char *qstr_str(qstr q); - mp_printf(print, "DAC(DA%d [#%d], runing=%u, out=%u mV)", self->ch, self->dac->pin, self->active, self->mv); + mp_printf(print, "DAC(DA%d [#%d], active=%u, out=%u mV)", self->ch, self->dac->pin, self->active, self->mv); } STATIC mp_obj_t machine_dac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { diff --git a/ports/renesas-ra/machine_pwm.c b/ports/renesas-ra/machine_pwm.c index 936f698e3398c..69dc5bad59932 100644 --- a/ports/renesas-ra/machine_pwm.c +++ b/ports/renesas-ra/machine_pwm.c @@ -136,7 +136,7 @@ STATIC machine_pwm_obj_t machine_pwm_obj[] = { STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_pwm_obj_t *self = MP_OBJ_TO_PTR(self_in); - mp_printf(print, "PWM(GTIOC %d%c[#%d], runing=%u, freq=%u, duty=%u)", self->ch, self->id, self->pwm->pin, self->active, self->freq, self->duty); + mp_printf(print, "PWM(GTIOC %d%c[#%d], active=%u, freq=%u, duty=%u)", self->ch, self->id, self->pwm->pin, self->active, self->freq, self->duty); } STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { diff --git a/ports/renesas-ra/pendsv.c b/ports/renesas-ra/pendsv.c index d4c4496f1b33c..9c908addb58cb 100644 --- a/ports/renesas-ra/pendsv.c +++ b/ports/renesas-ra/pendsv.c @@ -164,7 +164,7 @@ __attribute__((naked)) void PendSV_Handler(void) { "bl pyb_thread_next\n" // get next thread to execute "mov lr, r4\n" // restore lr "mov sp, r0\n" // switch stacks - "msr primask, r5\n" // reenable interrupts + "msr primask, r5\n" // re-enable interrupts "vpop {s16-s31}\n" "pop {r4-r11, lr}\n" "bx lr\n" // return from interrupt; will return to new thread diff --git a/ports/renesas-ra/ra/ra_i2c.c b/ports/renesas-ra/ra/ra_i2c.c index 701f4d6aa8386..ba2fa72653358 100644 --- a/ports/renesas-ra/ra/ra_i2c.c +++ b/ports/renesas-ra/ra/ra_i2c.c @@ -625,7 +625,7 @@ static void ra_i2c_ictei_isr(R_IIC0_Type *i2c_inst) { action->m_status = RA_I2C_STATUS_DataSendCompleted; i2c_inst->ICCR2_b.SP = 1; } else { - action->m_status = RA_I2C_STATUS_Stopped; // set Stopped status insted STOP condition + action->m_status = RA_I2C_STATUS_Stopped; // set Stopped status instead STOP condition } } else { ra_i2c_xaction_start(i2c_inst, action, true); diff --git a/ports/renesas-ra/ra/ra_icu.c b/ports/renesas-ra/ra/ra_icu.c index caac8bfe221e2..633c3c3de03e6 100644 --- a/ports/renesas-ra/ra/ra_icu.c +++ b/ports/renesas-ra/ra/ra_icu.c @@ -520,7 +520,7 @@ static const ra_icu_pin_t ra_irq_pins[] = { #endif #else - #error "CMSIS MCU Series is not speficied." + #error "CMSIS MCU Series is not specified." #endif }; #define ICU_PINS_SIZE (sizeof(ra_irq_pins) / sizeof(ra_icu_pin_t)) diff --git a/ports/renesas-ra/ra/ra_sci.c b/ports/renesas-ra/ra/ra_sci.c index 81f3ff9675b5e..9fb44090d3723 100644 --- a/ports/renesas-ra/ra/ra_sci.c +++ b/ports/renesas-ra/ra/ra_sci.c @@ -1210,7 +1210,7 @@ void ra_sci_tx_ch(uint32_t ch, int c) { if ((scr & 0xa0) != 0) { sci_regs[idx]->SCR &= ~0xa0; } - sci_regs[idx]->SCR |= 0xa0; /* TIE and TE enable */ + sci_regs[idx]->SCR |= 0xa0; /* TIE- and TE-interrupt enable */ } ra_enable_irq(state); } @@ -1412,28 +1412,28 @@ void ra_sci_deinit(uint32_t ch) { } } -/* rx interrupt */ +/* rx-interrupt */ void sci_uart_rxi_isr(void) { IRQn_Type irq = R_FSP_CurrentIrqGet(); uint32_t ch = irq_to_ch[(uint32_t)irq]; ra_sci_isr_rx(ch); } -/* tx interrupt */ +/* tx-interrupt */ void sci_uart_txi_isr(void) { IRQn_Type irq = R_FSP_CurrentIrqGet(); uint32_t ch = irq_to_ch[(uint32_t)irq]; ra_sci_isr_tx(ch); } -/* er interrupt */ +/* er-interrupt */ void sci_uart_eri_isr(void) { IRQn_Type irq = R_FSP_CurrentIrqGet(); uint32_t ch = irq_to_ch[(uint32_t)irq]; ra_sci_isr_er(ch); } -/* te interrupt */ +/* te-interrupt */ void sci_uart_tei_isr(void) { IRQn_Type irq = R_FSP_CurrentIrqGet(); uint32_t ch = irq_to_ch[(uint32_t)irq]; diff --git a/ports/renesas-ra/systick.c b/ports/renesas-ra/systick.c index 95ca8083011ad..6fa02a2b6ec0a 100644 --- a/ports/renesas-ra/systick.c +++ b/ports/renesas-ra/systick.c @@ -49,7 +49,7 @@ void SysTick_Handler(void) { uint32_t uw_tick = uwTick + 1; uwTick = uw_tick; - // Read the systick control regster. This has the side effect of clearing + // Read the systick control register. This has the side effect of clearing // the COUNTFLAG bit, which makes the logic in mp_hal_ticks_us // work properly. SysTick->CTRL; diff --git a/ports/renesas-ra/timer.c b/ports/renesas-ra/timer.c index 04bd752b98cc7..1b32bc1eee29e 100644 --- a/ports/renesas-ra/timer.c +++ b/ports/renesas-ra/timer.c @@ -99,7 +99,7 @@ STATIC void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ /// /// Keyword arguments: /// -/// - `freq` - specifies the periodic frequency of the timer. You migh also +/// - `freq` - specifies the periodic frequency of the timer. You might also /// view this as the frequency with which the timer goes through /// one complete cycle. ////// @@ -215,7 +215,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj, pyb_timer_deinit); /// If only a channel number is passed, then a previously initialized channel /// object is returned (or `None` if there is no previous channel). /// -/// Othwerwise, a TimerChannel object is initialized and returned. +/// Otherwise, a TimerChannel object is initialized and returned. /// /// Each channel can be configured to perform pwm, output compare, or /// input capture. All channels share the same underlying timer, which means diff --git a/pyproject.toml b/pyproject.toml index 6c813f5a1ff40..0b3a40d9c95f7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,6 @@ skip = """ ./ports/cc3200/simplelink,\ ./ports/cc3200/telnet,\ ./ports/nrf/drivers/bluetooth/s1*,\ -./ports/renesas-ra,\ ./ports/stm32/usbhost,\ ./tests,\ ACKNOWLEDGEMENTS,\ From decf8e6a8bb940d5829ca3296790631fcece7b21 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Tue, 27 Feb 2024 15:32:29 +1100 Subject: [PATCH 180/408] all: Remove the "STATIC" macro and just use "static" instead. The STATIC macro was introduced a very long time ago in commit d5df6cd44a433d6253a61cb0f987835fbc06b2de. The original reason for this was to have the option to define it to nothing so that all static functions become global functions and therefore visible to certain debug tools, so one could do function size comparison and other things. This STATIC feature is rarely (if ever) used. And with the use of LTO and heavy inline optimisation, analysing the size of individual functions when they are not static is not a good representation of the size of code when fully optimised. So the macro does not have much use and it's simpler to just remove it. Then you know exactly what it's doing. For example, newcomers don't have to learn what the STATIC macro is and why it exists. Reading the code is also less "loud" with a lowercase static. One other minor point in favour of removing it, is that it stops bugs with `STATIC inline`, which should always be `static inline`. Methodology for this commit was: 1) git ls-files | egrep '\.[ch]$' | \ xargs sed -Ei "s/(^| )STATIC($| )/\1static\2/" 2) Do some manual cleanup in the diff by searching for the word STATIC in comments and changing those back. 3) "git-grep STATIC docs/", manually fixed those cases. 4) "rg -t python STATIC", manually fixed codegen lines that used STATIC. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- docs/develop/compiler.rst | 4 +- docs/develop/library.rst | 6 +- docs/develop/natmod.rst | 6 +- docs/develop/porting.rst | 8 +- drivers/bus/softqspi.c | 18 +- drivers/cyw43/cywbt.c | 16 +- drivers/dht/dht.c | 2 +- drivers/esp-hosted/esp_hosted_hal.c | 4 +- drivers/memory/spiflash.c | 28 +- examples/natmod/btree/btree_c.c | 6 +- examples/natmod/deflate/deflate.c | 4 +- examples/natmod/features0/features0.c | 6 +- examples/natmod/features1/features1.c | 18 +- examples/natmod/features2/main.c | 14 +- examples/natmod/features3/features3.c | 12 +- examples/natmod/features4/features4.c | 10 +- examples/natmod/framebuf/framebuf.c | 2 +- examples/natmod/re/re.c | 4 +- examples/usercmodule/cexample/examplemodule.c | 18 +- .../usercmodule/cppexample/examplemodule.c | 6 +- .../subpackage/modexamplepackage.c | 28 +- extmod/btstack/btstack_hci_uart.c | 40 +-- extmod/btstack/modbluetooth_btstack.c | 64 ++--- extmod/machine_adc.c | 56 ++-- extmod/machine_adc_block.c | 26 +- extmod/machine_bitstream.c | 2 +- extmod/machine_i2c.c | 76 +++--- extmod/machine_i2s.c | 78 +++--- extmod/machine_mem.c | 6 +- extmod/machine_pinbase.c | 6 +- extmod/machine_pulse.c | 2 +- extmod/machine_pwm.c | 52 ++-- extmod/machine_signal.c | 24 +- extmod/machine_spi.c | 32 +-- extmod/machine_timer.c | 18 +- extmod/machine_uart.c | 62 ++--- extmod/machine_wdt.c | 20 +- extmod/modasyncio.c | 62 ++--- extmod/modbinascii.c | 24 +- extmod/modbluetooth.c | 160 ++++++------ extmod/modbluetooth.h | 4 +- extmod/modbtree.c | 68 ++--- extmod/modcryptolib.c | 42 +-- extmod/moddeflate.c | 28 +- extmod/modframebuf.c | 122 ++++----- extmod/modhashlib.c | 76 +++--- extmod/modheapq.c | 22 +- extmod/modjson.c | 32 +-- extmod/modlwip.c | 144 +++++------ extmod/modmachine.c | 48 ++-- extmod/modnetwork.c | 12 +- extmod/modonewire.c | 34 +-- extmod/modos.c | 28 +- extmod/modplatform.c | 26 +- extmod/modrandom.c | 50 ++-- extmod/modre.c | 48 ++-- extmod/modselect.c | 48 ++-- extmod/modsocket.c | 76 +++--- extmod/modtime.c | 30 +-- extmod/modtls_axtls.c | 54 ++-- extmod/modtls_mbedtls.c | 90 +++---- extmod/moductypes.c | 44 ++-- extmod/modvfs.c | 4 +- extmod/modwebrepl.c | 48 ++-- extmod/modwebsocket.c | 26 +- extmod/network_cyw43.c | 56 ++-- extmod/network_esp_hosted.c | 40 +-- extmod/network_ninaw10.c | 98 +++---- extmod/network_wiznet5k.c | 116 ++++----- extmod/nimble/hal/hal_uart.c | 2 +- extmod/nimble/modbluetooth_nimble.c | 128 +++++----- extmod/nimble/nimble/nimble_npl_os.c | 8 +- extmod/os_dupterm.c | 2 +- extmod/vfs.c | 8 +- extmod/vfs_fat.c | 70 ++--- extmod/vfs_fat_diskio.c | 2 +- extmod/vfs_fat_file.c | 18 +- extmod/vfs_lfs.c | 2 +- extmod/vfs_lfsx.c | 80 +++--- extmod/vfs_lfsx_file.c | 18 +- extmod/vfs_posix.c | 68 ++--- extmod/vfs_posix_file.c | 24 +- extmod/vfs_reader.c | 4 +- mpy-cross/main.c | 18 +- ports/cc3200/boards/make-pins.py | 2 +- ports/cc3200/ftp/ftp.c | 14 +- ports/cc3200/misc/mpirq.c | 22 +- ports/cc3200/mods/machine_wdt.c | 6 +- ports/cc3200/mods/modhashlib.c | 26 +- ports/cc3200/mods/modmachine.c | 26 +- ports/cc3200/mods/modnetwork.c | 36 +-- ports/cc3200/mods/modos.c | 4 +- ports/cc3200/mods/modsocket.c | 104 ++++---- ports/cc3200/mods/modssl.c | 14 +- ports/cc3200/mods/modtime.c | 4 +- ports/cc3200/mods/modwipy.c | 8 +- ports/cc3200/mods/modwlan.c | 170 ++++++------- ports/cc3200/mods/pybadc.c | 62 ++--- ports/cc3200/mods/pybflash.c | 20 +- ports/cc3200/mods/pybi2c.c | 80 +++--- ports/cc3200/mods/pybpin.c | 134 +++++----- ports/cc3200/mods/pybrtc.c | 84 +++--- ports/cc3200/mods/pybsd.c | 40 +-- ports/cc3200/mods/pybsleep.c | 42 +-- ports/cc3200/mods/pybspi.c | 46 ++-- ports/cc3200/mods/pybtimer.c | 116 ++++----- ports/cc3200/mods/pybuart.c | 90 +++---- ports/cc3200/mptask.c | 16 +- ports/cc3200/mpthreadport.c | 10 +- ports/cc3200/util/random.c | 6 +- ports/esp32/esp32_nvs.c | 34 +-- ports/esp32/esp32_partition.c | 46 ++-- ports/esp32/esp32_rmt.c | 42 +-- ports/esp32/esp32_ulp.c | 20 +- ports/esp32/machine_adc.c | 24 +- ports/esp32/machine_adc_block.c | 8 +- ports/esp32/machine_bitstream.c | 10 +- ports/esp32/machine_dac.c | 12 +- ports/esp32/machine_hw_spi.c | 22 +- ports/esp32/machine_i2c.c | 8 +- ports/esp32/machine_i2s.c | 28 +- ports/esp32/machine_pin.c | 48 ++-- ports/esp32/machine_pwm.c | 70 ++--- ports/esp32/machine_rtc.c | 22 +- ports/esp32/machine_sdcard.c | 30 +-- ports/esp32/machine_timer.c | 32 +-- ports/esp32/machine_touchpad.c | 12 +- ports/esp32/machine_uart.c | 22 +- ports/esp32/machine_wdt.c | 6 +- ports/esp32/modesp.c | 36 +-- ports/esp32/modesp32.c | 32 +-- ports/esp32/modespnow.c | 86 +++---- ports/esp32/modmachine.c | 24 +- ports/esp32/modos.c | 4 +- ports/esp32/modsocket.c | 100 ++++---- ports/esp32/modtime.c | 4 +- ports/esp32/mphalport.c | 2 +- ports/esp32/mpnimbleport.c | 2 +- ports/esp32/mpthreadport.c | 10 +- ports/esp32/network_common.c | 6 +- ports/esp32/network_lan.c | 26 +- ports/esp32/network_ppp.c | 28 +- ports/esp32/network_wlan.c | 38 +-- ports/esp32/uart.c | 4 +- ports/esp8266/esp_mphal.c | 2 +- ports/esp8266/esppwm.c | 32 +-- ports/esp8266/lexerstr32.c | 4 +- ports/esp8266/machine_adc.c | 14 +- ports/esp8266/machine_pin.c | 56 ++-- ports/esp8266/machine_pwm.c | 30 +-- ports/esp8266/machine_rtc.c | 30 +-- ports/esp8266/machine_spi.c | 8 +- ports/esp8266/machine_uart.c | 20 +- ports/esp8266/machine_wdt.c | 6 +- ports/esp8266/main.c | 4 +- ports/esp8266/modesp.c | 82 +++--- ports/esp8266/modespnow.c | 52 ++-- ports/esp8266/modmachine.c | 40 +-- ports/esp8266/modos.c | 6 +- ports/esp8266/modtime.c | 4 +- ports/esp8266/network_wlan.c | 48 ++-- ports/mimxrt/dma_manager.c | 2 +- ports/mimxrt/eth.c | 24 +- ports/mimxrt/machine_adc.c | 10 +- ports/mimxrt/machine_i2c.c | 10 +- ports/mimxrt/machine_i2s.c | 64 ++--- ports/mimxrt/machine_led.c | 20 +- ports/mimxrt/machine_pin.c | 64 ++--- ports/mimxrt/machine_pwm.c | 34 +-- ports/mimxrt/machine_rtc.c | 52 ++-- ports/mimxrt/machine_sdcard.c | 38 +-- ports/mimxrt/machine_spi.c | 12 +- ports/mimxrt/machine_uart.c | 30 +-- ports/mimxrt/machine_wdt.c | 8 +- ports/mimxrt/mimxrt_flash.c | 20 +- ports/mimxrt/modmachine.c | 16 +- ports/mimxrt/modmimxrt.c | 4 +- ports/mimxrt/modos.c | 12 +- ports/mimxrt/modtime.c | 4 +- ports/mimxrt/mpbthciport.c | 10 +- ports/mimxrt/mphalport.c | 2 +- ports/mimxrt/mpnetworkport.c | 2 +- ports/mimxrt/network_lan.c | 30 +-- .../boards/MICROBIT/modules/microbitdisplay.c | 12 +- .../boards/MICROBIT/modules/microbitimage.c | 30 +-- .../nrf/boards/MICROBIT/modules/modmicrobit.c | 14 +- ports/nrf/boards/make-pins.py | 2 +- ports/nrf/drivers/bluetooth/ble_uart.c | 4 +- ports/nrf/drivers/flash.c | 8 +- ports/nrf/modules/ble/modble.c | 12 +- ports/nrf/modules/board/led.c | 12 +- ports/nrf/modules/board/modboard.c | 4 +- ports/nrf/modules/machine/adc.c | 14 +- ports/nrf/modules/machine/i2c.c | 8 +- ports/nrf/modules/machine/modmachine.c | 26 +- ports/nrf/modules/machine/pin.c | 112 ++++---- ports/nrf/modules/machine/pwm.c | 36 +-- ports/nrf/modules/machine/rtcounter.c | 46 ++-- ports/nrf/modules/machine/soft_pwm.c | 28 +- ports/nrf/modules/machine/spi.c | 24 +- ports/nrf/modules/machine/temp.c | 12 +- ports/nrf/modules/machine/timer.c | 32 +-- ports/nrf/modules/machine/uart.c | 30 +-- ports/nrf/modules/music/modmusic.c | 26 +- ports/nrf/modules/nrf/flashbdev.c | 14 +- ports/nrf/modules/nrf/modnrf.c | 12 +- ports/nrf/modules/os/microbitfs.c | 92 +++---- ports/nrf/modules/os/modos.c | 4 +- ports/nrf/modules/ubluepy/modubluepy.c | 4 +- .../modules/ubluepy/ubluepy_characteristic.c | 24 +- ports/nrf/modules/ubluepy/ubluepy_constants.c | 8 +- ports/nrf/modules/ubluepy/ubluepy_delegate.c | 16 +- .../nrf/modules/ubluepy/ubluepy_descriptor.c | 8 +- .../nrf/modules/ubluepy/ubluepy_peripheral.c | 50 ++-- .../nrf/modules/ubluepy/ubluepy_scan_entry.c | 22 +- ports/nrf/modules/ubluepy/ubluepy_scanner.c | 14 +- ports/nrf/modules/ubluepy/ubluepy_service.c | 24 +- ports/nrf/modules/ubluepy/ubluepy_uuid.c | 12 +- ports/nrf/mphalport.c | 2 +- ports/nrf/pin_named_pins.c | 2 +- ports/pic16bit/modpyb.c | 16 +- ports/pic16bit/modpybled.c | 14 +- ports/pic16bit/modpybswitch.c | 10 +- ports/qemu-arm/modmachine.c | 2 +- ports/renesas-ra/boardctrl.c | 4 +- ports/renesas-ra/extint.c | 36 +-- ports/renesas-ra/flashbdev.c | 2 +- ports/renesas-ra/irq.c | 6 +- ports/renesas-ra/led.c | 14 +- ports/renesas-ra/machine_adc.c | 8 +- ports/renesas-ra/machine_dac.c | 30 +-- ports/renesas-ra/machine_i2c.c | 20 +- ports/renesas-ra/machine_pin.c | 32 +-- ports/renesas-ra/machine_pwm.c | 26 +- ports/renesas-ra/machine_rtc.c | 16 +- ports/renesas-ra/machine_sdcard.c | 36 +-- ports/renesas-ra/machine_spi.c | 14 +- ports/renesas-ra/machine_uart.c | 28 +- ports/renesas-ra/main.c | 10 +- ports/renesas-ra/modmachine.c | 20 +- ports/renesas-ra/modos.c | 4 +- ports/renesas-ra/modtime.c | 4 +- ports/renesas-ra/mpbthciport.c | 10 +- ports/renesas-ra/mphalport.c | 2 +- ports/renesas-ra/mpthreadport.c | 2 +- ports/renesas-ra/pybthread.c | 2 +- ports/renesas-ra/ra_it.c | 6 +- ports/renesas-ra/storage.c | 20 +- ports/renesas-ra/timer.c | 64 ++--- ports/renesas-ra/uart.c | 4 +- ports/renesas-ra/usrsw.c | 16 +- ports/rp2/machine_adc.c | 8 +- ports/rp2/machine_i2c.c | 8 +- ports/rp2/machine_i2s.c | 66 ++--- ports/rp2/machine_pin.c | 50 ++-- ports/rp2/machine_pwm.c | 32 +-- ports/rp2/machine_rtc.c | 12 +- ports/rp2/machine_spi.c | 12 +- ports/rp2/machine_timer.c | 20 +- ports/rp2/machine_uart.c | 44 ++-- ports/rp2/machine_wdt.c | 6 +- ports/rp2/modmachine.c | 16 +- ports/rp2/modos.c | 4 +- ports/rp2/modrp2.c | 8 +- ports/rp2/modtime.c | 4 +- ports/rp2/mpbthciport.c | 4 +- ports/rp2/mphalport.c | 4 +- ports/rp2/mpthreadport.c | 12 +- ports/rp2/rp2_dma.c | 52 ++-- ports/rp2/rp2_flash.c | 20 +- ports/rp2/rp2_pio.c | 126 ++++----- ports/samd/machine_adc.c | 8 +- ports/samd/machine_dac.c | 12 +- ports/samd/machine_i2c.c | 8 +- ports/samd/machine_pin.c | 44 ++-- ports/samd/machine_pwm.c | 36 +-- ports/samd/machine_rtc.c | 22 +- ports/samd/machine_spi.c | 12 +- ports/samd/machine_uart.c | 26 +- ports/samd/machine_wdt.c | 10 +- ports/samd/modmachine.c | 16 +- ports/samd/modos.c | 6 +- ports/samd/modsamd.c | 8 +- ports/samd/modtime.c | 4 +- ports/samd/mphalport.c | 2 +- ports/samd/pin_af.c | 2 +- ports/samd/samd_flash.c | 30 +-- ports/samd/samd_qspiflash.c | 24 +- ports/samd/samd_spiflash.c | 24 +- ports/stm32/accel.c | 36 +-- ports/stm32/adc.c | 68 ++--- ports/stm32/boardctrl.c | 4 +- .../stm32/boards/ADAFRUIT_F405_EXPRESS/bdev.c | 4 +- ports/stm32/boards/ARDUINO_GIGA/bdev.c | 2 +- .../stm32/boards/ARDUINO_NICLA_VISION/bdev.c | 2 +- ports/stm32/boards/ARDUINO_PORTENTA_H7/bdev.c | 2 +- ports/stm32/boards/LEGO_HUB_NO6/bdev.c | 6 +- ports/stm32/boards/LEGO_HUB_NO6/cc2564.c | 2 +- ports/stm32/boards/MIKROE_QUAIL/bdev.c | 4 +- ports/stm32/boards/PYBD_SF2/bdev.c | 4 +- .../boards/SPARKFUN_MICROMOD_STM32/bdev.c | 4 +- ports/stm32/boards/STM32F769DISC/board_init.c | 2 +- ports/stm32/boards/STM32L476DISC/bdev.c | 4 +- ports/stm32/boards/VCC_GND_F407VE/bdev.c | 4 +- ports/stm32/boards/VCC_GND_F407ZG/bdev.c | 4 +- ports/stm32/can.c | 4 +- ports/stm32/dac.c | 50 ++-- ports/stm32/eth.c | 30 +-- ports/stm32/extint.c | 40 +-- ports/stm32/fdcan.c | 2 +- ports/stm32/i2c.c | 16 +- ports/stm32/irq.c | 6 +- ports/stm32/lcd.c | 48 ++-- ports/stm32/led.c | 26 +- ports/stm32/machine_adc.c | 20 +- ports/stm32/machine_i2c.c | 12 +- ports/stm32/machine_i2s.c | 28 +- ports/stm32/machine_spi.c | 12 +- ports/stm32/machine_uart.c | 26 +- ports/stm32/machine_wdt.c | 6 +- ports/stm32/main.c | 12 +- ports/stm32/make-stmconst.py | 6 +- ports/stm32/mboot/main.c | 2 +- ports/stm32/modmachine.c | 20 +- ports/stm32/modos.c | 4 +- ports/stm32/modpyb.c | 28 +- ports/stm32/modstm.c | 4 +- ports/stm32/modtime.c | 4 +- ports/stm32/mpbthciport.c | 12 +- ports/stm32/mpbtstackport.c | 2 +- ports/stm32/mpnetworkport.c | 2 +- ports/stm32/mpthreadport.c | 2 +- ports/stm32/network_lan.c | 28 +- ports/stm32/octospi.c | 10 +- ports/stm32/pin.c | 108 ++++---- ports/stm32/powerctrl.c | 14 +- ports/stm32/pyb_can.c | 64 ++--- ports/stm32/pyb_i2c.c | 56 ++-- ports/stm32/pyb_spi.c | 36 +-- ports/stm32/pybthread.c | 2 +- ports/stm32/qspi.c | 10 +- ports/stm32/rfcore.c | 62 ++--- ports/stm32/rng.c | 4 +- ports/stm32/rtc.c | 34 +-- ports/stm32/sdcard.c | 52 ++-- ports/stm32/servo.c | 32 +-- ports/stm32/spi.c | 20 +- ports/stm32/stm32_it.c | 8 +- ports/stm32/storage.c | 20 +- ports/stm32/subghz.c | 8 +- ports/stm32/timer.c | 96 +++---- ports/stm32/uart.c | 8 +- ports/stm32/usb.c | 106 ++++---- ports/stm32/usbd_cdc_interface.c | 2 +- ports/stm32/usbd_desc.c | 4 +- ports/stm32/usbd_msc_interface.c | 34 +-- ports/stm32/usrsw.c | 16 +- ports/unix/coverage.c | 42 +-- ports/unix/coveragecpp.cpp | 2 +- ports/unix/main.c | 30 +-- ports/unix/modffi.c | 90 +++---- ports/unix/modjni.c | 76 +++--- ports/unix/modmachine.c | 2 +- ports/unix/modos.c | 24 +- ports/unix/modsocket.c | 90 +++---- ports/unix/modtermios.c | 16 +- ports/unix/modtime.c | 20 +- ports/unix/mpbthciport.c | 16 +- ports/unix/mpbtstackport_h4.c | 2 +- ports/unix/mpbtstackport_usb.c | 6 +- ports/unix/mpthreadport.c | 14 +- ports/unix/unix_mphal.c | 2 +- ports/webassembly/main.c | 2 +- ports/windows/fmode.c | 2 +- ports/windows/windows_mphal.c | 14 +- ports/zephyr/machine_i2c.c | 6 +- ports/zephyr/machine_pin.c | 42 +-- ports/zephyr/machine_spi.c | 8 +- ports/zephyr/machine_uart.c | 26 +- ports/zephyr/main.c | 2 +- ports/zephyr/modbluetooth_zephyr.c | 18 +- ports/zephyr/modmachine.c | 6 +- ports/zephyr/modsocket.c | 70 ++--- ports/zephyr/modtime.c | 2 +- ports/zephyr/modzephyr.c | 20 +- ports/zephyr/modzsensor.c | 24 +- ports/zephyr/zephyr_storage.c | 40 +-- py/asmarm.c | 30 +-- py/asmthumb.c | 6 +- py/asmx64.c | 26 +- py/asmx86.c | 32 +-- py/asmxtensa.c | 2 +- py/bc.c | 6 +- py/builtinevex.c | 14 +- py/builtinhelp.c | 12 +- py/builtinimport.c | 20 +- py/compile.c | 214 ++++++++-------- py/emitbc.c | 30 +-- py/emitinlinethumb.c | 42 +-- py/emitinlinextensa.c | 26 +- py/emitnative.c | 240 +++++++++--------- py/emitnx86.c | 2 +- py/gc.c | 14 +- py/lexer.c | 58 ++--- py/malloc.c | 4 +- py/map.c | 8 +- py/modarray.c | 4 +- py/modbuiltins.c | 68 ++--- py/modcmath.c | 40 +-- py/modcollections.c | 4 +- py/moderrno.c | 8 +- py/modgc.c | 18 +- py/modio.c | 38 +-- py/modmath.c | 64 ++--- py/modmicropython.c | 56 ++-- py/modstruct.c | 20 +- py/modsys.c | 38 +-- py/modthread.c | 54 ++-- py/mpconfig.h | 6 - py/mpprint.c | 4 +- py/mpz.c | 38 +-- py/nativeglue.c | 20 +- py/objarray.c | 42 +-- py/objattrtuple.c | 6 +- py/objbool.c | 8 +- py/objboundmeth.c | 10 +- py/objcell.c | 4 +- py/objclosure.c | 6 +- py/objcomplex.c | 10 +- py/objdeque.c | 20 +- py/objdict.c | 90 +++---- py/objenumerate.c | 6 +- py/objexcept.c | 6 +- py/objfilter.c | 4 +- py/objfloat.c | 10 +- py/objfun.c | 24 +- py/objgenerator.c | 30 +-- py/objgetitemiter.c | 4 +- py/objint.c | 20 +- py/objint_mpz.c | 4 +- py/objlist.c | 70 ++--- py/objmap.c | 4 +- py/objmodule.c | 14 +- py/objnamedtuple.c | 12 +- py/objnone.c | 2 +- py/objobject.c | 24 +- py/objpolyiter.c | 10 +- py/objproperty.c | 18 +- py/objrange.c | 22 +- py/objreversed.c | 4 +- py/objset.c | 104 ++++---- py/objsingleton.c | 2 +- py/objslice.c | 14 +- py/objstr.c | 120 ++++----- py/objstringio.c | 28 +- py/objstrunicode.c | 14 +- py/objtuple.c | 18 +- py/objtype.c | 56 ++-- py/objzip.c | 4 +- py/opmethods.c | 8 +- py/parse.c | 58 ++--- py/parsenum.c | 2 +- py/persistentcode.c | 28 +- py/profile.c | 18 +- py/qstr.c | 8 +- py/reader.c | 8 +- py/repl.c | 8 +- py/runtime.c | 10 +- py/scope.c | 4 +- py/stream.c | 30 +-- py/unicode.c | 2 +- py/vstr.c | 4 +- shared/libc/printf.c | 2 +- shared/readline/readline.c | 12 +- shared/runtime/gchelper_generic.c | 10 +- shared/runtime/mpirq.c | 14 +- shared/runtime/pyexec.c | 20 +- shared/runtime/softtimer.c | 4 +- shared/runtime/sys_stdio_mphal.c | 26 +- shared/timeutils/timeutils.c | 4 +- shared/tinyusb/mp_cdc_common.c | 2 +- tools/boardgen.py | 4 +- 482 files changed, 6288 insertions(+), 6294 deletions(-) diff --git a/docs/develop/compiler.rst b/docs/develop/compiler.rst index 00cc90f8163a1..0c25ad3a01ef1 100644 --- a/docs/develop/compiler.rst +++ b/docs/develop/compiler.rst @@ -98,7 +98,7 @@ Then also edit ``py/lexer.c`` to add the new keyword literal text: .. code-block:: c :emphasize-lines: 12 - STATIC const char *const tok_kw[] = { + static const char *const tok_kw[] = { ... "or", "pass", @@ -301,7 +301,7 @@ code statement: .. code-block:: c - STATIC void emit_native_unary_op(emit_t *emit, mp_unary_op_t op) { + static void emit_native_unary_op(emit_t *emit, mp_unary_op_t op) { vtype_kind_t vtype; emit_pre_pop_reg(emit, &vtype, REG_ARG_2); if (vtype == VTYPE_PYOBJ) { diff --git a/docs/develop/library.rst b/docs/develop/library.rst index c2a86ea1699bc..830211d81c862 100644 --- a/docs/develop/library.rst +++ b/docs/develop/library.rst @@ -48,16 +48,16 @@ hypothetical new module ``subsystem`` in the file ``modsubsystem.c``: #if MICROPY_PY_SUBSYSTEM // info() - STATIC mp_obj_t py_subsystem_info(void) { + static mp_obj_t py_subsystem_info(void) { return MP_OBJ_NEW_SMALL_INT(42); } MP_DEFINE_CONST_FUN_OBJ_0(subsystem_info_obj, py_subsystem_info); - STATIC const mp_rom_map_elem_t mp_module_subsystem_globals_table[] = { + static const mp_rom_map_elem_t mp_module_subsystem_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_subsystem) }, { MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&subsystem_info_obj) }, }; - STATIC MP_DEFINE_CONST_DICT(mp_module_subsystem_globals, mp_module_subsystem_globals_table); + static MP_DEFINE_CONST_DICT(mp_module_subsystem_globals, mp_module_subsystem_globals_table); const mp_obj_module_t mp_module_subsystem = { .base = { &mp_type_module }, diff --git a/docs/develop/natmod.rst b/docs/develop/natmod.rst index 6d15f867bcfe8..502ea1c4c6873 100644 --- a/docs/develop/natmod.rst +++ b/docs/develop/natmod.rst @@ -128,7 +128,7 @@ The file ``factorial.c`` contains: #include "py/dynruntime.h" // Helper function to compute factorial - STATIC mp_int_t factorial_helper(mp_int_t x) { + static mp_int_t factorial_helper(mp_int_t x) { if (x == 0) { return 1; } @@ -136,7 +136,7 @@ The file ``factorial.c`` contains: } // This is the function which will be called from Python, as factorial(x) - STATIC mp_obj_t factorial(mp_obj_t x_obj) { + static mp_obj_t factorial(mp_obj_t x_obj) { // Extract the integer from the MicroPython input object mp_int_t x = mp_obj_get_int(x_obj); // Calculate the factorial @@ -145,7 +145,7 @@ The file ``factorial.c`` contains: return mp_obj_new_int(result); } // Define a Python reference to the function above - STATIC MP_DEFINE_CONST_FUN_OBJ_1(factorial_obj, factorial); + static MP_DEFINE_CONST_FUN_OBJ_1(factorial_obj, factorial); // This is the entry point and is called when the module is imported mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) { diff --git a/docs/develop/porting.rst b/docs/develop/porting.rst index 09e61d5d9bfe0..99725e1000bef 100644 --- a/docs/develop/porting.rst +++ b/docs/develop/porting.rst @@ -262,17 +262,17 @@ To add a custom module like ``myport``, first add the module definition in a fil #include "py/runtime.h" - STATIC mp_obj_t myport_info(void) { + static mp_obj_t myport_info(void) { mp_printf(&mp_plat_print, "info about my port\n"); return mp_const_none; } - STATIC MP_DEFINE_CONST_FUN_OBJ_0(myport_info_obj, myport_info); + static MP_DEFINE_CONST_FUN_OBJ_0(myport_info_obj, myport_info); - STATIC const mp_rom_map_elem_t myport_module_globals_table[] = { + static const mp_rom_map_elem_t myport_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_myport) }, { MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&myport_info_obj) }, }; - STATIC MP_DEFINE_CONST_DICT(myport_module_globals, myport_module_globals_table); + static MP_DEFINE_CONST_DICT(myport_module_globals, myport_module_globals_table); const mp_obj_module_t myport_module = { .base = { &mp_type_module }, diff --git a/drivers/bus/softqspi.c b/drivers/bus/softqspi.c index dc205da3a7c40..65a504a739d25 100644 --- a/drivers/bus/softqspi.c +++ b/drivers/bus/softqspi.c @@ -49,14 +49,14 @@ #endif -STATIC void nibble_write(mp_soft_qspi_obj_t *self, uint8_t v) { +static void nibble_write(mp_soft_qspi_obj_t *self, uint8_t v) { mp_hal_pin_write(self->io0, v & 1); mp_hal_pin_write(self->io1, (v >> 1) & 1); mp_hal_pin_write(self->io2, (v >> 2) & 1); mp_hal_pin_write(self->io3, (v >> 3) & 1); } -STATIC int mp_soft_qspi_ioctl(void *self_in, uint32_t cmd) { +static int mp_soft_qspi_ioctl(void *self_in, uint32_t cmd) { mp_soft_qspi_obj_t *self = (mp_soft_qspi_obj_t*)self_in; switch (cmd) { @@ -80,7 +80,7 @@ STATIC int mp_soft_qspi_ioctl(void *self_in, uint32_t cmd) { return 0; // success } -STATIC void mp_soft_qspi_transfer(mp_soft_qspi_obj_t *self, size_t len, const uint8_t *src, uint8_t *dest) { +static void mp_soft_qspi_transfer(mp_soft_qspi_obj_t *self, size_t len, const uint8_t *src, uint8_t *dest) { // Will run as fast as possible, limited only by CPU speed and GPIO time mp_hal_pin_input(self->io1); mp_hal_pin_output(self->io0); @@ -119,7 +119,7 @@ STATIC void mp_soft_qspi_transfer(mp_soft_qspi_obj_t *self, size_t len, const ui } } -STATIC void mp_soft_qspi_qread(mp_soft_qspi_obj_t *self, size_t len, uint8_t *buf) { +static void mp_soft_qspi_qread(mp_soft_qspi_obj_t *self, size_t len, uint8_t *buf) { // Make all IO lines input mp_hal_pin_input(self->io2); mp_hal_pin_input(self->io3); @@ -137,7 +137,7 @@ STATIC void mp_soft_qspi_qread(mp_soft_qspi_obj_t *self, size_t len, uint8_t *bu } } -STATIC void mp_soft_qspi_qwrite(mp_soft_qspi_obj_t *self, size_t len, const uint8_t *buf) { +static void mp_soft_qspi_qwrite(mp_soft_qspi_obj_t *self, size_t len, const uint8_t *buf) { // Make all IO lines output mp_hal_pin_output(self->io2); mp_hal_pin_output(self->io3); @@ -158,7 +158,7 @@ STATIC void mp_soft_qspi_qwrite(mp_soft_qspi_obj_t *self, size_t len, const uint //mp_hal_pin_input(self->io1); } -STATIC int mp_soft_qspi_write_cmd_data(void *self_in, uint8_t cmd, size_t len, uint32_t data) { +static int mp_soft_qspi_write_cmd_data(void *self_in, uint8_t cmd, size_t len, uint32_t data) { mp_soft_qspi_obj_t *self = (mp_soft_qspi_obj_t*)self_in; uint32_t cmd_buf = cmd | data << 8; CS_LOW(self); @@ -167,7 +167,7 @@ STATIC int mp_soft_qspi_write_cmd_data(void *self_in, uint8_t cmd, size_t len, u return 0; } -STATIC int mp_soft_qspi_write_cmd_addr_data(void *self_in, uint8_t cmd, uint32_t addr, size_t len, const uint8_t *src) { +static int mp_soft_qspi_write_cmd_addr_data(void *self_in, uint8_t cmd, uint32_t addr, size_t len, const uint8_t *src) { mp_soft_qspi_obj_t *self = (mp_soft_qspi_obj_t*)self_in; uint8_t cmd_buf[5] = {cmd}; uint8_t addr_len = mp_spi_set_addr_buff(&cmd_buf[1], addr); @@ -178,7 +178,7 @@ STATIC int mp_soft_qspi_write_cmd_addr_data(void *self_in, uint8_t cmd, uint32_t return 0; } -STATIC int mp_soft_qspi_read_cmd(void *self_in, uint8_t cmd, size_t len, uint32_t *dest) { +static int mp_soft_qspi_read_cmd(void *self_in, uint8_t cmd, size_t len, uint32_t *dest) { mp_soft_qspi_obj_t *self = (mp_soft_qspi_obj_t*)self_in; uint32_t cmd_buf = cmd; CS_LOW(self); @@ -188,7 +188,7 @@ STATIC int mp_soft_qspi_read_cmd(void *self_in, uint8_t cmd, size_t len, uint32_ return 0; } -STATIC int mp_soft_qspi_read_cmd_qaddr_qdata(void *self_in, uint8_t cmd, uint32_t addr, size_t len, uint8_t *dest) { +static int mp_soft_qspi_read_cmd_qaddr_qdata(void *self_in, uint8_t cmd, uint32_t addr, size_t len, uint8_t *dest) { mp_soft_qspi_obj_t *self = (mp_soft_qspi_obj_t*)self_in; uint8_t cmd_buf[7] = {cmd}; uint8_t addr_len = mp_spi_set_addr_buff(&cmd_buf[1], addr); diff --git a/drivers/cyw43/cywbt.c b/drivers/cyw43/cywbt.c index 3f454485ab2bc..0ee69a07ecd2c 100644 --- a/drivers/cyw43/cywbt.c +++ b/drivers/cyw43/cywbt.c @@ -51,7 +51,7 @@ extern uint8_t mp_bluetooth_hci_cmd_buf[4 + 256]; // Provided by the port. extern machine_uart_obj_t mp_bluetooth_hci_uart_obj; -STATIC void cywbt_wait_cts_low(void) { +static void cywbt_wait_cts_low(void) { mp_hal_pin_config(CYW43_PIN_BT_CTS, MP_HAL_PIN_MODE_INPUT, MP_HAL_PIN_PULL_UP, 0); for (int i = 0; i < 200; ++i) { if (mp_hal_pin_read(CYW43_PIN_BT_CTS) == 0) { @@ -64,7 +64,7 @@ STATIC void cywbt_wait_cts_low(void) { } #endif -STATIC int cywbt_hci_cmd_raw(size_t len, uint8_t *buf) { +static int cywbt_hci_cmd_raw(size_t len, uint8_t *buf) { mp_bluetooth_hci_uart_write((void *)buf, len); for (int c, i = 0; i < 6; ++i) { while ((c = mp_bluetooth_hci_uart_readchar()) == -1) { @@ -96,7 +96,7 @@ STATIC int cywbt_hci_cmd_raw(size_t len, uint8_t *buf) { return 0; } -STATIC int cywbt_hci_cmd(int ogf, int ocf, size_t param_len, const uint8_t *param_buf) { +static int cywbt_hci_cmd(int ogf, int ocf, size_t param_len, const uint8_t *param_buf) { uint8_t *buf = mp_bluetooth_hci_cmd_buf; buf[0] = 0x01; buf[1] = ocf; @@ -108,19 +108,19 @@ STATIC int cywbt_hci_cmd(int ogf, int ocf, size_t param_len, const uint8_t *para return cywbt_hci_cmd_raw(4 + param_len, buf); } -STATIC void put_le16(uint8_t *buf, uint16_t val) { +static void put_le16(uint8_t *buf, uint16_t val) { buf[0] = val; buf[1] = val >> 8; } -STATIC void put_le32(uint8_t *buf, uint32_t val) { +static void put_le32(uint8_t *buf, uint32_t val) { buf[0] = val; buf[1] = val >> 8; buf[2] = val >> 16; buf[3] = val >> 24; } -STATIC int cywbt_set_baudrate(uint32_t baudrate) { +static int cywbt_set_baudrate(uint32_t baudrate) { uint8_t buf[6]; put_le16(buf, 0); put_le32(buf + 2, baudrate); @@ -128,7 +128,7 @@ STATIC int cywbt_set_baudrate(uint32_t baudrate) { } // download firmware -STATIC int cywbt_download_firmware(const uint8_t *firmware) { +static int cywbt_download_firmware(const uint8_t *firmware) { cywbt_hci_cmd(0x3f, 0x2e, 0, NULL); bool last_packet = false; @@ -255,7 +255,7 @@ int mp_bluetooth_hci_controller_deinit(void) { } #ifdef CYW43_PIN_BT_DEV_WAKE -STATIC uint32_t bt_sleep_ticks; +static uint32_t bt_sleep_ticks; #endif int mp_bluetooth_hci_controller_sleep_maybe(void) { diff --git a/drivers/dht/dht.c b/drivers/dht/dht.c index 7e9b897825791..e6b71542dabc9 100644 --- a/drivers/dht/dht.c +++ b/drivers/dht/dht.c @@ -40,7 +40,7 @@ #define mp_hal_pin_od_high_dht mp_hal_pin_od_high #endif -STATIC mp_obj_t dht_readinto(mp_obj_t pin_in, mp_obj_t buf_in) { +static mp_obj_t dht_readinto(mp_obj_t pin_in, mp_obj_t buf_in) { mp_hal_pin_obj_t pin = mp_hal_get_pin_obj(pin_in); mp_hal_pin_open_drain(pin); diff --git a/drivers/esp-hosted/esp_hosted_hal.c b/drivers/esp-hosted/esp_hosted_hal.c index bac8a89bd0941..c98eb5031aa4b 100644 --- a/drivers/esp-hosted/esp_hosted_hal.c +++ b/drivers/esp-hosted/esp_hosted_hal.c @@ -44,14 +44,14 @@ extern void mod_network_poll_events(void); -STATIC mp_obj_t esp_hosted_pin_irq_callback(mp_obj_t self_in) { +static mp_obj_t esp_hosted_pin_irq_callback(mp_obj_t self_in) { #ifdef MICROPY_HW_WIFI_LED led_toggle(MICROPY_HW_WIFI_LED); #endif mod_network_poll_events(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_hosted_pin_irq_callback_obj, esp_hosted_pin_irq_callback); +static MP_DEFINE_CONST_FUN_OBJ_1(esp_hosted_pin_irq_callback_obj, esp_hosted_pin_irq_callback); MP_WEAK int esp_hosted_hal_init(uint32_t mode) { // Perform a hard reset and set pins to their defaults. diff --git a/drivers/memory/spiflash.c b/drivers/memory/spiflash.c index 52739b1d8bdf7..e66153636b1fd 100644 --- a/drivers/memory/spiflash.c +++ b/drivers/memory/spiflash.c @@ -56,21 +56,21 @@ #define PAGE_SIZE (256) // maximum bytes we can write in one SPI transfer #define SECTOR_SIZE MP_SPIFLASH_ERASE_BLOCK_SIZE -STATIC void mp_spiflash_acquire_bus(mp_spiflash_t *self) { +static void mp_spiflash_acquire_bus(mp_spiflash_t *self) { const mp_spiflash_config_t *c = self->config; if (c->bus_kind == MP_SPIFLASH_BUS_QSPI) { c->bus.u_qspi.proto->ioctl(c->bus.u_qspi.data, MP_QSPI_IOCTL_BUS_ACQUIRE); } } -STATIC void mp_spiflash_release_bus(mp_spiflash_t *self) { +static void mp_spiflash_release_bus(mp_spiflash_t *self) { const mp_spiflash_config_t *c = self->config; if (c->bus_kind == MP_SPIFLASH_BUS_QSPI) { c->bus.u_qspi.proto->ioctl(c->bus.u_qspi.data, MP_QSPI_IOCTL_BUS_RELEASE); } } -STATIC int mp_spiflash_write_cmd_data(mp_spiflash_t *self, uint8_t cmd, size_t len, uint32_t data) { +static int mp_spiflash_write_cmd_data(mp_spiflash_t *self, uint8_t cmd, size_t len, uint32_t data) { int ret = 0; const mp_spiflash_config_t *c = self->config; if (c->bus_kind == MP_SPIFLASH_BUS_SPI) { @@ -84,7 +84,7 @@ STATIC int mp_spiflash_write_cmd_data(mp_spiflash_t *self, uint8_t cmd, size_t l return ret; } -STATIC int mp_spiflash_transfer_cmd_addr_data(mp_spiflash_t *self, uint8_t cmd, uint32_t addr, size_t len, const uint8_t *src, uint8_t *dest) { +static int mp_spiflash_transfer_cmd_addr_data(mp_spiflash_t *self, uint8_t cmd, uint32_t addr, size_t len, const uint8_t *src, uint8_t *dest) { int ret = 0; const mp_spiflash_config_t *c = self->config; if (c->bus_kind == MP_SPIFLASH_BUS_SPI) { @@ -109,7 +109,7 @@ STATIC int mp_spiflash_transfer_cmd_addr_data(mp_spiflash_t *self, uint8_t cmd, return ret; } -STATIC int mp_spiflash_read_cmd(mp_spiflash_t *self, uint8_t cmd, size_t len, uint32_t *dest) { +static int mp_spiflash_read_cmd(mp_spiflash_t *self, uint8_t cmd, size_t len, uint32_t *dest) { const mp_spiflash_config_t *c = self->config; if (c->bus_kind == MP_SPIFLASH_BUS_SPI) { mp_hal_pin_write(c->bus.u_spi.cs, 0); @@ -122,7 +122,7 @@ STATIC int mp_spiflash_read_cmd(mp_spiflash_t *self, uint8_t cmd, size_t len, ui } } -STATIC int mp_spiflash_read_data(mp_spiflash_t *self, uint32_t addr, size_t len, uint8_t *dest) { +static int mp_spiflash_read_data(mp_spiflash_t *self, uint32_t addr, size_t len, uint8_t *dest) { const mp_spiflash_config_t *c = self->config; uint8_t cmd; if (c->bus_kind == MP_SPIFLASH_BUS_SPI) { @@ -133,11 +133,11 @@ STATIC int mp_spiflash_read_data(mp_spiflash_t *self, uint32_t addr, size_t len, return mp_spiflash_transfer_cmd_addr_data(self, cmd, addr, len, NULL, dest); } -STATIC int mp_spiflash_write_cmd(mp_spiflash_t *self, uint8_t cmd) { +static int mp_spiflash_write_cmd(mp_spiflash_t *self, uint8_t cmd) { return mp_spiflash_write_cmd_data(self, cmd, 0, 0); } -STATIC int mp_spiflash_wait_sr(mp_spiflash_t *self, uint8_t mask, uint8_t val, uint32_t timeout) { +static int mp_spiflash_wait_sr(mp_spiflash_t *self, uint8_t mask, uint8_t val, uint32_t timeout) { do { uint32_t sr; int ret = mp_spiflash_read_cmd(self, CMD_RDSR, 1, &sr); @@ -152,11 +152,11 @@ STATIC int mp_spiflash_wait_sr(mp_spiflash_t *self, uint8_t mask, uint8_t val, u return -MP_ETIMEDOUT; } -STATIC int mp_spiflash_wait_wel1(mp_spiflash_t *self) { +static int mp_spiflash_wait_wel1(mp_spiflash_t *self) { return mp_spiflash_wait_sr(self, 2, 2, WAIT_SR_TIMEOUT); } -STATIC int mp_spiflash_wait_wip0(mp_spiflash_t *self) { +static int mp_spiflash_wait_wip0(mp_spiflash_t *self) { return mp_spiflash_wait_sr(self, 1, 0, WAIT_SR_TIMEOUT); } @@ -219,7 +219,7 @@ void mp_spiflash_deepsleep(mp_spiflash_t *self, int value) { } } -STATIC int mp_spiflash_erase_block_internal(mp_spiflash_t *self, uint32_t addr) { +static int mp_spiflash_erase_block_internal(mp_spiflash_t *self, uint32_t addr) { int ret = 0; // enable writes ret = mp_spiflash_write_cmd(self, CMD_WREN); @@ -244,7 +244,7 @@ STATIC int mp_spiflash_erase_block_internal(mp_spiflash_t *self, uint32_t addr) return mp_spiflash_wait_wip0(self); } -STATIC int mp_spiflash_write_page(mp_spiflash_t *self, uint32_t addr, size_t len, const uint8_t *src) { +static int mp_spiflash_write_page(mp_spiflash_t *self, uint32_t addr, size_t len, const uint8_t *src) { int ret = 0; // enable writes ret = mp_spiflash_write_cmd(self, CMD_WREN); @@ -361,7 +361,7 @@ int mp_spiflash_cached_read(mp_spiflash_t *self, uint32_t addr, size_t len, uint return ret; } -STATIC int mp_spiflash_cache_flush_internal(mp_spiflash_t *self) { +static int mp_spiflash_cache_flush_internal(mp_spiflash_t *self) { #if USE_WR_DELAY if (!(self->flags & 1)) { return 0; @@ -396,7 +396,7 @@ int mp_spiflash_cache_flush(mp_spiflash_t *self) { return ret; } -STATIC int mp_spiflash_cached_write_part(mp_spiflash_t *self, uint32_t addr, size_t len, const uint8_t *src) { +static int mp_spiflash_cached_write_part(mp_spiflash_t *self, uint32_t addr, size_t len, const uint8_t *src) { // Align to 4096 sector uint32_t offset = addr & 0xfff; uint32_t sec = addr >> 12; diff --git a/examples/natmod/btree/btree_c.c b/examples/natmod/btree/btree_c.c index c897f2e9a3859..3c60e41b2d663 100644 --- a/examples/natmod/btree/btree_c.c +++ b/examples/natmod/btree/btree_c.c @@ -100,9 +100,9 @@ mp_getiter_iternext_custom_t btree_getiter_iternext; #include "extmod/modbtree.c" mp_map_elem_t btree_locals_dict_table[8]; -STATIC MP_DEFINE_CONST_DICT(btree_locals_dict, btree_locals_dict_table); +static MP_DEFINE_CONST_DICT(btree_locals_dict, btree_locals_dict_table); -STATIC mp_obj_t btree_open(size_t n_args, const mp_obj_t *args) { +static mp_obj_t btree_open(size_t n_args, const mp_obj_t *args) { // Make sure we got a stream object mp_get_stream_raise(args[0], MP_STREAM_OP_READ | MP_STREAM_OP_WRITE | MP_STREAM_OP_IOCTL); @@ -118,7 +118,7 @@ STATIC mp_obj_t btree_open(size_t n_args, const mp_obj_t *args) { return MP_OBJ_FROM_PTR(btree_new(db, args[0])); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(btree_open_obj, 5, 5, btree_open); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(btree_open_obj, 5, 5, btree_open); mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) { MP_DYNRUNTIME_INIT_ENTRY diff --git a/examples/natmod/deflate/deflate.c b/examples/natmod/deflate/deflate.c index fa475bd067240..9de7e101a7689 100644 --- a/examples/natmod/deflate/deflate.c +++ b/examples/natmod/deflate/deflate.c @@ -29,7 +29,7 @@ mp_obj_t mp_stream_close(mp_obj_t stream) { MP_DEFINE_CONST_FUN_OBJ_1(mp_stream_close_obj, mp_stream_close); // Re-implemented from py/stream.c, not yet available in dynruntime.h. -STATIC mp_obj_t mp_stream___exit__(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_stream___exit__(size_t n_args, const mp_obj_t *args) { (void)n_args; return mp_stream_close(args[0]); } @@ -42,7 +42,7 @@ mp_obj_t mp_identity(mp_obj_t self) { MP_DEFINE_CONST_FUN_OBJ_1(mp_identity_obj, mp_identity); mp_map_elem_t deflateio_locals_dict_table[7]; -STATIC MP_DEFINE_CONST_DICT(deflateio_locals_dict, deflateio_locals_dict_table); +static MP_DEFINE_CONST_DICT(deflateio_locals_dict, deflateio_locals_dict_table); mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) { MP_DYNRUNTIME_INIT_ENTRY diff --git a/examples/natmod/features0/features0.c b/examples/natmod/features0/features0.c index 1b1867a3bc935..c3d31afb79cb8 100644 --- a/examples/natmod/features0/features0.c +++ b/examples/natmod/features0/features0.c @@ -8,7 +8,7 @@ #include "py/dynruntime.h" // Helper function to compute factorial -STATIC mp_int_t factorial_helper(mp_int_t x) { +static mp_int_t factorial_helper(mp_int_t x) { if (x == 0) { return 1; } @@ -16,7 +16,7 @@ STATIC mp_int_t factorial_helper(mp_int_t x) { } // This is the function which will be called from Python, as factorial(x) -STATIC mp_obj_t factorial(mp_obj_t x_obj) { +static mp_obj_t factorial(mp_obj_t x_obj) { // Extract the integer from the MicroPython input object mp_int_t x = mp_obj_get_int(x_obj); // Calculate the factorial @@ -25,7 +25,7 @@ STATIC mp_obj_t factorial(mp_obj_t x_obj) { return mp_obj_new_int(result); } // Define a Python reference to the function above -STATIC MP_DEFINE_CONST_FUN_OBJ_1(factorial_obj, factorial); +static MP_DEFINE_CONST_FUN_OBJ_1(factorial_obj, factorial); // This is the entry point and is called when the module is imported mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) { diff --git a/examples/natmod/features1/features1.c b/examples/natmod/features1/features1.c index d2494b2138865..92b96dbb18351 100644 --- a/examples/natmod/features1/features1.c +++ b/examples/natmod/features1/features1.c @@ -25,15 +25,15 @@ uint16_t *const table_ptr16a[] = { &data16[0], &data16[1], &data16[2], &data16[3 const uint16_t *const table_ptr16b[] = { &table16[0], &table16[1] }; // A simple function that adds its 2 arguments (must be integers) -STATIC mp_obj_t add(mp_obj_t x_in, mp_obj_t y_in) { +static mp_obj_t add(mp_obj_t x_in, mp_obj_t y_in) { mp_int_t x = mp_obj_get_int(x_in); mp_int_t y = mp_obj_get_int(y_in); return mp_obj_new_int(x + y); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(add_obj, add); +static MP_DEFINE_CONST_FUN_OBJ_2(add_obj, add); // A local helper function (not exposed to Python) -STATIC mp_int_t fibonacci_helper(mp_int_t x) { +static mp_int_t fibonacci_helper(mp_int_t x) { if (x < MP_ARRAY_SIZE(table8)) { return table8[x]; } else { @@ -42,17 +42,17 @@ STATIC mp_int_t fibonacci_helper(mp_int_t x) { } // A function which computes Fibonacci numbers -STATIC mp_obj_t fibonacci(mp_obj_t x_in) { +static mp_obj_t fibonacci(mp_obj_t x_in) { mp_int_t x = mp_obj_get_int(x_in); if (x < 0) { mp_raise_ValueError(MP_ERROR_TEXT("can't compute negative Fibonacci number")); } return mp_obj_new_int(fibonacci_helper(x)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(fibonacci_obj, fibonacci); +static MP_DEFINE_CONST_FUN_OBJ_1(fibonacci_obj, fibonacci); // A function that accesses the BSS data -STATIC mp_obj_t access(size_t n_args, const mp_obj_t *args) { +static mp_obj_t access(size_t n_args, const mp_obj_t *args) { if (n_args == 0) { // Create a list holding all items from data16 mp_obj_list_t *lst = MP_OBJ_TO_PTR(mp_obj_new_list(MP_ARRAY_SIZE(data16), NULL)); @@ -71,17 +71,17 @@ STATIC mp_obj_t access(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(access_obj, 0, 2, access); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(access_obj, 0, 2, access); // A function that allocates memory and creates a bytearray -STATIC mp_obj_t make_array(void) { +static mp_obj_t make_array(void) { uint16_t *ptr = m_new(uint16_t, MP_ARRAY_SIZE(table_ptr16b)); for (int i = 0; i < MP_ARRAY_SIZE(table_ptr16b); ++i) { ptr[i] = *table_ptr16b[i]; } return mp_obj_new_bytearray_by_ref(sizeof(uint16_t) * MP_ARRAY_SIZE(table_ptr16b), ptr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(make_array_obj, make_array); +static MP_DEFINE_CONST_FUN_OBJ_0(make_array_obj, make_array); // This is the entry point and is called when the module is imported mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) { diff --git a/examples/natmod/features2/main.c b/examples/natmod/features2/main.c index 1a39700dc4b71..22961aa494f5f 100644 --- a/examples/natmod/features2/main.c +++ b/examples/natmod/features2/main.c @@ -22,29 +22,29 @@ // A function that uses the default float type configured for the current target // This default can be overridden by specifying MICROPY_FLOAT_IMPL at the make level -STATIC mp_obj_t add(mp_obj_t x, mp_obj_t y) { +static mp_obj_t add(mp_obj_t x, mp_obj_t y) { return mp_obj_new_float(mp_obj_get_float(x) + mp_obj_get_float(y)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(add_obj, add); +static MP_DEFINE_CONST_FUN_OBJ_2(add_obj, add); // A function that explicitly uses single precision floats -STATIC mp_obj_t add_f(mp_obj_t x, mp_obj_t y) { +static mp_obj_t add_f(mp_obj_t x, mp_obj_t y) { return mp_obj_new_float_from_f(mp_obj_get_float_to_f(x) + mp_obj_get_float_to_f(y)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(add_f_obj, add_f); +static MP_DEFINE_CONST_FUN_OBJ_2(add_f_obj, add_f); #if USE_DOUBLE // A function that explicitly uses double precision floats -STATIC mp_obj_t add_d(mp_obj_t x, mp_obj_t y) { +static mp_obj_t add_d(mp_obj_t x, mp_obj_t y) { return mp_obj_new_float_from_d(mp_obj_get_float_to_d(x) + mp_obj_get_float_to_d(y)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(add_d_obj, add_d); +static MP_DEFINE_CONST_FUN_OBJ_2(add_d_obj, add_d); #endif // A function that computes the product of floats in an array. // This function uses the most general C argument interface, which is more difficult // to use but has access to the globals dict of the module via self->globals. -STATIC mp_obj_t productf(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) { +static mp_obj_t productf(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) { // Check number of arguments is valid mp_arg_check_num(n_args, n_kw, 1, 1, false); diff --git a/examples/natmod/features3/features3.c b/examples/natmod/features3/features3.c index 20efd67cdcefd..1d3bc51e609d1 100644 --- a/examples/natmod/features3/features3.c +++ b/examples/natmod/features3/features3.c @@ -8,7 +8,7 @@ #include "py/dynruntime.h" // A function that returns a tuple of object types. -STATIC mp_obj_t get_types(void) { +static mp_obj_t get_types(void) { return mp_obj_new_tuple(9, ((mp_obj_t []) { MP_OBJ_FROM_PTR(&mp_type_type), MP_OBJ_FROM_PTR(&mp_type_NoneType), @@ -21,10 +21,10 @@ STATIC mp_obj_t get_types(void) { MP_OBJ_FROM_PTR(&mp_type_dict), })); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(get_types_obj, get_types); +static MP_DEFINE_CONST_FUN_OBJ_0(get_types_obj, get_types); // A function that returns a tuple of constant objects. -STATIC mp_obj_t get_const_objects(void) { +static mp_obj_t get_const_objects(void) { return mp_obj_new_tuple(5, ((mp_obj_t []) { mp_const_none, mp_const_false, @@ -33,17 +33,17 @@ STATIC mp_obj_t get_const_objects(void) { mp_const_empty_tuple, })); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(get_const_objects_obj, get_const_objects); +static MP_DEFINE_CONST_FUN_OBJ_0(get_const_objects_obj, get_const_objects); // A function that creates a dictionary from the given arguments. -STATIC mp_obj_t make_dict(size_t n_args, const mp_obj_t *args) { +static mp_obj_t make_dict(size_t n_args, const mp_obj_t *args) { mp_obj_t dict = mp_obj_new_dict(n_args / 2); for (; n_args >= 2; n_args -= 2, args += 2) { mp_obj_dict_store(dict, args[0], args[1]); } return dict; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(make_dict_obj, 0, MP_OBJ_FUN_ARGS_MAX, make_dict); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(make_dict_obj, 0, MP_OBJ_FUN_ARGS_MAX, make_dict); // This is the entry point and is called when the module is imported. mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) { diff --git a/examples/natmod/features4/features4.c b/examples/natmod/features4/features4.c index 336f4ecf64080..a52e9e45662aa 100644 --- a/examples/natmod/features4/features4.c +++ b/examples/natmod/features4/features4.c @@ -24,7 +24,7 @@ typedef struct { // Essentially Factorial.__new__ (but also kind of __init__). // Takes a single argument (the number to find the factorial of) -STATIC mp_obj_t factorial_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args_in) { +static mp_obj_t factorial_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args_in) { mp_arg_check_num(n_args, n_kw, 1, 1, false); mp_obj_factorial_t *o = mp_obj_malloc(mp_obj_factorial_t, type); @@ -33,7 +33,7 @@ STATIC mp_obj_t factorial_make_new(const mp_obj_type_t *type, size_t n_args, siz return MP_OBJ_FROM_PTR(o); } -STATIC mp_int_t factorial_helper(mp_int_t x) { +static mp_int_t factorial_helper(mp_int_t x) { if (x == 0) { return 1; } @@ -41,16 +41,16 @@ STATIC mp_int_t factorial_helper(mp_int_t x) { } // Implements Factorial.calculate() -STATIC mp_obj_t factorial_calculate(mp_obj_t self_in) { +static mp_obj_t factorial_calculate(mp_obj_t self_in) { mp_obj_factorial_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_int(factorial_helper(self->n)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(factorial_calculate_obj, factorial_calculate); +static MP_DEFINE_CONST_FUN_OBJ_1(factorial_calculate_obj, factorial_calculate); // Locals dict for the Factorial type (will have a single method, calculate, // added in mpy_init). mp_map_elem_t factorial_locals_dict_table[1]; -STATIC MP_DEFINE_CONST_DICT(factorial_locals_dict, factorial_locals_dict_table); +static MP_DEFINE_CONST_DICT(factorial_locals_dict, factorial_locals_dict_table); // This is the entry point and is called when the module is imported mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) { diff --git a/examples/natmod/framebuf/framebuf.c b/examples/natmod/framebuf/framebuf.c index badc7ab46d7fa..e8f99b3b20cdd 100644 --- a/examples/natmod/framebuf/framebuf.c +++ b/examples/natmod/framebuf/framebuf.c @@ -13,7 +13,7 @@ mp_obj_full_type_t mp_type_framebuf; #include "extmod/modframebuf.c" mp_map_elem_t framebuf_locals_dict_table[11]; -STATIC MP_DEFINE_CONST_DICT(framebuf_locals_dict, framebuf_locals_dict_table); +static MP_DEFINE_CONST_DICT(framebuf_locals_dict, framebuf_locals_dict_table); mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) { MP_DYNRUNTIME_INIT_ENTRY diff --git a/examples/natmod/re/re.c b/examples/natmod/re/re.c index df89ea83530ec..7ae72a578f4e3 100644 --- a/examples/natmod/re/re.c +++ b/examples/natmod/re/re.c @@ -38,10 +38,10 @@ mp_obj_full_type_t re_type; #include "extmod/modre.c" mp_map_elem_t match_locals_dict_table[5]; -STATIC MP_DEFINE_CONST_DICT(match_locals_dict, match_locals_dict_table); +static MP_DEFINE_CONST_DICT(match_locals_dict, match_locals_dict_table); mp_map_elem_t re_locals_dict_table[3]; -STATIC MP_DEFINE_CONST_DICT(re_locals_dict, re_locals_dict_table); +static MP_DEFINE_CONST_DICT(re_locals_dict, re_locals_dict_table); mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) { MP_DYNRUNTIME_INIT_ENTRY diff --git a/examples/usercmodule/cexample/examplemodule.c b/examples/usercmodule/cexample/examplemodule.c index 9416613ba9520..2988fbd565f08 100644 --- a/examples/usercmodule/cexample/examplemodule.c +++ b/examples/usercmodule/cexample/examplemodule.c @@ -5,7 +5,7 @@ #include "py/mphal.h" // This is the function which will be called from Python as cexample.add_ints(a, b). -STATIC mp_obj_t example_add_ints(mp_obj_t a_obj, mp_obj_t b_obj) { +static mp_obj_t example_add_ints(mp_obj_t a_obj, mp_obj_t b_obj) { // Extract the ints from the micropython input objects. int a = mp_obj_get_int(a_obj); int b = mp_obj_get_int(b_obj); @@ -14,7 +14,7 @@ STATIC mp_obj_t example_add_ints(mp_obj_t a_obj, mp_obj_t b_obj) { return mp_obj_new_int(a + b); } // Define a Python reference to the function above. -STATIC MP_DEFINE_CONST_FUN_OBJ_2(example_add_ints_obj, example_add_ints); +static MP_DEFINE_CONST_FUN_OBJ_2(example_add_ints_obj, example_add_ints); // This structure represents Timer instance objects. typedef struct _example_Timer_obj_t { @@ -28,7 +28,7 @@ typedef struct _example_Timer_obj_t { // This is the Timer.time() method. After creating a Timer object, this // can be called to get the time elapsed since creating the Timer. -STATIC mp_obj_t example_Timer_time(mp_obj_t self_in) { +static mp_obj_t example_Timer_time(mp_obj_t self_in) { // The first argument is self. It is cast to the *example_Timer_obj_t // type so we can read its attributes. example_Timer_obj_t *self = MP_OBJ_TO_PTR(self_in); @@ -37,11 +37,11 @@ STATIC mp_obj_t example_Timer_time(mp_obj_t self_in) { mp_uint_t elapsed = mp_hal_ticks_ms() - self->start_time; return mp_obj_new_int_from_uint(elapsed); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(example_Timer_time_obj, example_Timer_time); +static MP_DEFINE_CONST_FUN_OBJ_1(example_Timer_time_obj, example_Timer_time); // This represents Timer.__new__ and Timer.__init__, which is called when // the user instantiates a Timer object. -STATIC mp_obj_t example_Timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t example_Timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // Allocates the new object and sets the type. example_Timer_obj_t *self = mp_obj_malloc(example_Timer_obj_t, type); @@ -54,10 +54,10 @@ STATIC mp_obj_t example_Timer_make_new(const mp_obj_type_t *type, size_t n_args, // This collects all methods and other static class attributes of the Timer. // The table structure is similar to the module table, as detailed below. -STATIC const mp_rom_map_elem_t example_Timer_locals_dict_table[] = { +static const mp_rom_map_elem_t example_Timer_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&example_Timer_time_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(example_Timer_locals_dict, example_Timer_locals_dict_table); +static MP_DEFINE_CONST_DICT(example_Timer_locals_dict, example_Timer_locals_dict_table); // This defines the type(Timer) object. MP_DEFINE_CONST_OBJ_TYPE( @@ -73,12 +73,12 @@ MP_DEFINE_CONST_OBJ_TYPE( // and the MicroPython object reference. // All identifiers and strings are written as MP_QSTR_xxx and will be // optimized to word-sized integers by the build system (interned strings). -STATIC const mp_rom_map_elem_t example_module_globals_table[] = { +static const mp_rom_map_elem_t example_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_cexample) }, { MP_ROM_QSTR(MP_QSTR_add_ints), MP_ROM_PTR(&example_add_ints_obj) }, { MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&example_type_Timer) }, }; -STATIC MP_DEFINE_CONST_DICT(example_module_globals, example_module_globals_table); +static MP_DEFINE_CONST_DICT(example_module_globals, example_module_globals_table); // Define module object. const mp_obj_module_t example_user_cmodule = { diff --git a/examples/usercmodule/cppexample/examplemodule.c b/examples/usercmodule/cppexample/examplemodule.c index 96a1a74438845..5d4637b89782d 100644 --- a/examples/usercmodule/cppexample/examplemodule.c +++ b/examples/usercmodule/cppexample/examplemodule.c @@ -2,18 +2,18 @@ // Define a Python reference to the function we'll make available. // See example.cpp for the definition. -STATIC MP_DEFINE_CONST_FUN_OBJ_2(cppfunc_obj, cppfunc); +static MP_DEFINE_CONST_FUN_OBJ_2(cppfunc_obj, cppfunc); // Define all attributes of the module. // Table entries are key/value pairs of the attribute name (a string) // and the MicroPython object reference. // All identifiers and strings are written as MP_QSTR_xxx and will be // optimized to word-sized integers by the build system (interned strings). -STATIC const mp_rom_map_elem_t cppexample_module_globals_table[] = { +static const mp_rom_map_elem_t cppexample_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_cppexample) }, { MP_ROM_QSTR(MP_QSTR_cppfunc), MP_ROM_PTR(&cppfunc_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(cppexample_module_globals, cppexample_module_globals_table); +static MP_DEFINE_CONST_DICT(cppexample_module_globals, cppexample_module_globals_table); // Define module object. const mp_obj_module_t cppexample_user_cmodule = { diff --git a/examples/usercmodule/subpackage/modexamplepackage.c b/examples/usercmodule/subpackage/modexamplepackage.c index 70e1e4005b30d..d68d0528398c4 100644 --- a/examples/usercmodule/subpackage/modexamplepackage.c +++ b/examples/usercmodule/subpackage/modexamplepackage.c @@ -2,18 +2,18 @@ #include "py/runtime.h" // Define example_package.foo.bar.f() -STATIC mp_obj_t example_package_foo_bar_f(void) { +static mp_obj_t example_package_foo_bar_f(void) { mp_printf(&mp_plat_print, "example_package.foo.bar.f\n"); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(example_package_foo_bar_f_obj, example_package_foo_bar_f); +static MP_DEFINE_CONST_FUN_OBJ_0(example_package_foo_bar_f_obj, example_package_foo_bar_f); // Define all attributes of the second-level sub-package (example_package.foo.bar). -STATIC const mp_rom_map_elem_t example_package_foo_bar_globals_table[] = { +static const mp_rom_map_elem_t example_package_foo_bar_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_example_package_dot_foo_dot_bar) }, { MP_ROM_QSTR(MP_QSTR_f), MP_ROM_PTR(&example_package_foo_bar_f_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(example_package_foo_bar_globals, example_package_foo_bar_globals_table); +static MP_DEFINE_CONST_DICT(example_package_foo_bar_globals, example_package_foo_bar_globals_table); // Define example_package.foo.bar module object. const mp_obj_module_t example_package_foo_bar_user_cmodule = { @@ -22,19 +22,19 @@ const mp_obj_module_t example_package_foo_bar_user_cmodule = { }; // Define example_package.foo.f() -STATIC mp_obj_t example_package_foo_f(void) { +static mp_obj_t example_package_foo_f(void) { mp_printf(&mp_plat_print, "example_package.foo.f\n"); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(example_package_foo_f_obj, example_package_foo_f); +static MP_DEFINE_CONST_FUN_OBJ_0(example_package_foo_f_obj, example_package_foo_f); // Define all attributes of the first-level sub-package (example_package.foo). -STATIC const mp_rom_map_elem_t example_package_foo_globals_table[] = { +static const mp_rom_map_elem_t example_package_foo_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_example_package_dot_foo) }, { MP_ROM_QSTR(MP_QSTR_bar), MP_ROM_PTR(&example_package_foo_bar_user_cmodule) }, { MP_ROM_QSTR(MP_QSTR_f), MP_ROM_PTR(&example_package_foo_f_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(example_package_foo_globals, example_package_foo_globals_table); +static MP_DEFINE_CONST_DICT(example_package_foo_globals, example_package_foo_globals_table); // Define example_package.foo module object. const mp_obj_module_t example_package_foo_user_cmodule = { @@ -43,13 +43,13 @@ const mp_obj_module_t example_package_foo_user_cmodule = { }; // Define example_package.f() -STATIC mp_obj_t example_package_f(void) { +static mp_obj_t example_package_f(void) { mp_printf(&mp_plat_print, "example_package.f\n"); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(example_package_f_obj, example_package_f); +static MP_DEFINE_CONST_FUN_OBJ_0(example_package_f_obj, example_package_f); -STATIC mp_obj_t example_package___init__(void) { +static mp_obj_t example_package___init__(void) { if (!MP_STATE_VM(example_package_initialised)) { // __init__ for builtins is called each time the module is imported, // so ensure that initialisation only happens once. @@ -58,20 +58,20 @@ STATIC mp_obj_t example_package___init__(void) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(example_package___init___obj, example_package___init__); +static MP_DEFINE_CONST_FUN_OBJ_0(example_package___init___obj, example_package___init__); // The "initialised" state is stored on mp_state so that it is cleared on soft // reset. MP_REGISTER_ROOT_POINTER(int example_package_initialised); // Define all attributes of the top-level package (example_package). -STATIC const mp_rom_map_elem_t example_package_globals_table[] = { +static const mp_rom_map_elem_t example_package_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_example_package) }, { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&example_package___init___obj) }, { MP_ROM_QSTR(MP_QSTR_foo), MP_ROM_PTR(&example_package_foo_user_cmodule) }, { MP_ROM_QSTR(MP_QSTR_f), MP_ROM_PTR(&example_package_f_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(example_package_globals, example_package_globals_table); +static MP_DEFINE_CONST_DICT(example_package_globals, example_package_globals_table); // Define module object. const mp_obj_module_t example_package_user_cmodule = { diff --git a/extmod/btstack/btstack_hci_uart.c b/extmod/btstack/btstack_hci_uart.c index 19cdfc4b9dae7..fb90f550cb126 100644 --- a/extmod/btstack/btstack_hci_uart.c +++ b/extmod/btstack/btstack_hci_uart.c @@ -48,17 +48,17 @@ // interface to an HCI UART provided by the port. // We pass the bytes directly to the UART during a send, but then notify btstack in the next poll. -STATIC bool send_done; -STATIC void (*send_handler)(void); +static bool send_done; +static void (*send_handler)(void); // btstack issues a read of len bytes, and gives us a buffer to asynchronously fill up. -STATIC uint8_t *recv_buf; -STATIC size_t recv_len; -STATIC size_t recv_idx; -STATIC void (*recv_handler)(void); -STATIC bool init_success = false; +static uint8_t *recv_buf; +static size_t recv_len; +static size_t recv_idx; +static void (*recv_handler)(void); +static bool init_success = false; -STATIC int btstack_uart_init(const btstack_uart_config_t *uart_config) { +static int btstack_uart_init(const btstack_uart_config_t *uart_config) { (void)uart_config; send_done = false; @@ -81,45 +81,45 @@ STATIC int btstack_uart_init(const btstack_uart_config_t *uart_config) { return 0; } -STATIC int btstack_uart_open(void) { +static int btstack_uart_open(void) { return init_success ? 0 : 1; } -STATIC int btstack_uart_close(void) { +static int btstack_uart_close(void) { mp_bluetooth_hci_controller_deinit(); mp_bluetooth_hci_uart_deinit(); return 0; } -STATIC void btstack_uart_set_block_received(void (*block_handler)(void)) { +static void btstack_uart_set_block_received(void (*block_handler)(void)) { recv_handler = block_handler; } -STATIC void btstack_uart_set_block_sent(void (*block_handler)(void)) { +static void btstack_uart_set_block_sent(void (*block_handler)(void)) { send_handler = block_handler; } -STATIC int btstack_uart_set_baudrate(uint32_t baudrate) { +static int btstack_uart_set_baudrate(uint32_t baudrate) { mp_bluetooth_hci_uart_set_baudrate(baudrate); return 0; } -STATIC int btstack_uart_set_parity(int parity) { +static int btstack_uart_set_parity(int parity) { (void)parity; return 0; } -STATIC int btstack_uart_set_flowcontrol(int flowcontrol) { +static int btstack_uart_set_flowcontrol(int flowcontrol) { (void)flowcontrol; return 0; } -STATIC void btstack_uart_receive_block(uint8_t *buf, uint16_t len) { +static void btstack_uart_receive_block(uint8_t *buf, uint16_t len) { recv_buf = buf; recv_len = len; } -STATIC void btstack_uart_send_block(const uint8_t *buf, uint16_t len) { +static void btstack_uart_send_block(const uint8_t *buf, uint16_t len) { #if HCI_TRACE printf(COL_GREEN "< [% 8d] %02x", (int)mp_hal_ticks_ms(), buf[0]); for (size_t i = 1; i < len; ++i) { @@ -136,16 +136,16 @@ STATIC void btstack_uart_send_block(const uint8_t *buf, uint16_t len) { mp_bluetooth_hci_poll_now(); } -STATIC int btstack_uart_get_supported_sleep_modes(void) { +static int btstack_uart_get_supported_sleep_modes(void) { return 0; } -STATIC void btstack_uart_set_sleep(btstack_uart_sleep_mode_t sleep_mode) { +static void btstack_uart_set_sleep(btstack_uart_sleep_mode_t sleep_mode) { (void)sleep_mode; // printf("btstack_uart_set_sleep %u\n", sleep_mode); } -STATIC void btstack_uart_set_wakeup_handler(void (*wakeup_handler)(void)) { +static void btstack_uart_set_wakeup_handler(void (*wakeup_handler)(void)) { (void)wakeup_handler; // printf("btstack_uart_set_wakeup_handler\n"); } diff --git a/extmod/btstack/modbluetooth_btstack.c b/extmod/btstack/modbluetooth_btstack.c index b3d349c2dc947..b29970842ceb9 100644 --- a/extmod/btstack/modbluetooth_btstack.c +++ b/extmod/btstack/modbluetooth_btstack.c @@ -43,24 +43,24 @@ // How long to wait for a controller to init/deinit. // Some controllers can take up to 5-6 seconds in normal operation. -STATIC const uint32_t BTSTACK_INIT_DEINIT_TIMEOUT_MS = 15000; +static const uint32_t BTSTACK_INIT_DEINIT_TIMEOUT_MS = 15000; // We need to know the attribute handle for the GAP device name (see GAP_DEVICE_NAME_UUID) // so it can be put into the gatts_db before registering the services, and accessed // efficiently when requesting an attribute in att_read_callback. Because this is the // first characteristic of the first service, it always has a handle value of 3. -STATIC const uint16_t BTSTACK_GAP_DEVICE_NAME_HANDLE = 3; +static const uint16_t BTSTACK_GAP_DEVICE_NAME_HANDLE = 3; volatile int mp_bluetooth_btstack_state = MP_BLUETOOTH_BTSTACK_STATE_OFF; // sm_set_authentication_requirements is set-only, so cache current value. #if MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING -STATIC uint8_t mp_bluetooth_btstack_sm_auth_req = 0; +static uint8_t mp_bluetooth_btstack_sm_auth_req = 0; #endif #define ERRNO_BLUETOOTH_NOT_ACTIVE MP_ENODEV -STATIC int btstack_error_to_errno(int err) { +static int btstack_error_to_errno(int err) { DEBUG_printf(" --> btstack error: %d\n", err); if (err == ERROR_CODE_SUCCESS) { return 0; @@ -78,7 +78,7 @@ STATIC int btstack_error_to_errno(int err) { } #if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE -STATIC mp_obj_bluetooth_uuid_t create_mp_uuid(uint16_t uuid16, const uint8_t *uuid128) { +static mp_obj_bluetooth_uuid_t create_mp_uuid(uint16_t uuid16, const uint8_t *uuid128) { mp_obj_bluetooth_uuid_t result; result.base.type = &mp_type_bluetooth_uuid; if (uuid16 != 0) { @@ -107,7 +107,7 @@ typedef struct _mp_btstack_active_connection_t { size_t pending_write_value_len; } mp_btstack_active_connection_t; -STATIC mp_btstack_active_connection_t *create_active_connection(uint16_t conn_handle) { +static mp_btstack_active_connection_t *create_active_connection(uint16_t conn_handle) { DEBUG_printf("create_active_connection: conn_handle=%d\n", conn_handle); mp_btstack_active_connection_t *conn = m_new(mp_btstack_active_connection_t, 1); conn->conn_handle = conn_handle; @@ -120,7 +120,7 @@ STATIC mp_btstack_active_connection_t *create_active_connection(uint16_t conn_ha return conn; } -STATIC mp_btstack_active_connection_t *find_active_connection(uint16_t conn_handle) { +static mp_btstack_active_connection_t *find_active_connection(uint16_t conn_handle) { DEBUG_printf("find_active_connection: conn_handle=%d\n", conn_handle); btstack_linked_list_iterator_t it; btstack_linked_list_iterator_init(&it, &MP_STATE_PORT(bluetooth_btstack_root_pointers)->active_connections); @@ -135,7 +135,7 @@ STATIC mp_btstack_active_connection_t *find_active_connection(uint16_t conn_hand return conn; } -STATIC void remove_active_connection(uint16_t conn_handle) { +static void remove_active_connection(uint16_t conn_handle) { DEBUG_printf("remove_active_connection: conn_handle=%d\n", conn_handle); mp_btstack_active_connection_t *conn = find_active_connection(conn_handle); if (conn) { @@ -149,7 +149,7 @@ STATIC void remove_active_connection(uint16_t conn_handle) { // This needs to be separate to btstack_packet_handler otherwise we get // dual-delivery of the HCI_EVENT_LE_META event. -STATIC void btstack_packet_handler_att_server(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) { +static void btstack_packet_handler_att_server(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) { (void)channel; (void)size; DEBUG_printf("btstack_packet_handler_att_server(packet_type=%u, packet=%p)\n", packet_type, packet); @@ -187,13 +187,13 @@ STATIC void btstack_packet_handler_att_server(uint8_t packet_type, uint16_t chan #if MICROPY_BLUETOOTH_USE_ZEPHYR_STATIC_ADDRESS // During startup, the controller (e.g. Zephyr) might give us a static address that we can use. -STATIC uint8_t controller_static_addr[6] = {0}; -STATIC bool controller_static_addr_available = false; +static uint8_t controller_static_addr[6] = {0}; +static bool controller_static_addr_available = false; -STATIC const uint8_t read_static_address_command_complete_prefix[] = { 0x0e, 0x1b, 0x01, 0x09, 0xfc }; +static const uint8_t read_static_address_command_complete_prefix[] = { 0x0e, 0x1b, 0x01, 0x09, 0xfc }; #endif -STATIC void btstack_packet_handler_generic(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) { +static void btstack_packet_handler_generic(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) { (void)channel; (void)size; DEBUG_printf("btstack_packet_handler_generic(packet_type=%u, packet=%p)\n", packet_type, packet); @@ -372,13 +372,13 @@ STATIC void btstack_packet_handler_generic(uint8_t packet_type, uint16_t channel } } -STATIC btstack_packet_callback_registration_t hci_event_callback_registration = { +static btstack_packet_callback_registration_t hci_event_callback_registration = { .callback = &btstack_packet_handler_generic }; #if MICROPY_PY_BLUETOOTH_ENABLE_GATT_CLIENT // For when the handler is being used for service discovery. -STATIC void btstack_packet_handler_discover_services(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) { +static void btstack_packet_handler_discover_services(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) { (void)channel; (void)size; if (packet_type != HCI_EVENT_PACKET) { @@ -401,7 +401,7 @@ STATIC void btstack_packet_handler_discover_services(uint8_t packet_type, uint16 } // For when the handler is being used for characteristic discovery. -STATIC void btstack_packet_handler_discover_characteristics(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) { +static void btstack_packet_handler_discover_characteristics(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) { (void)channel; (void)size; if (packet_type != HCI_EVENT_PACKET) { @@ -424,7 +424,7 @@ STATIC void btstack_packet_handler_discover_characteristics(uint8_t packet_type, } // For when the handler is being used for descriptor discovery. -STATIC void btstack_packet_handler_discover_descriptors(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) { +static void btstack_packet_handler_discover_descriptors(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) { (void)channel; (void)size; if (packet_type != HCI_EVENT_PACKET) { @@ -447,7 +447,7 @@ STATIC void btstack_packet_handler_discover_descriptors(uint8_t packet_type, uin } // For when the handler is being used for a read query. -STATIC void btstack_packet_handler_read(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) { +static void btstack_packet_handler_read(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) { (void)channel; (void)size; if (packet_type != HCI_EVENT_PACKET) { @@ -476,7 +476,7 @@ STATIC void btstack_packet_handler_read(uint8_t packet_type, uint16_t channel, u } // For when the handler is being used for write-with-response. -STATIC void btstack_packet_handler_write_with_response(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) { +static void btstack_packet_handler_write_with_response(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) { (void)channel; (void)size; if (packet_type != HCI_EVENT_PACKET) { @@ -501,9 +501,9 @@ STATIC void btstack_packet_handler_write_with_response(uint8_t packet_type, uint } #endif // MICROPY_PY_BLUETOOTH_ENABLE_GATT_CLIENT -STATIC btstack_timer_source_t btstack_init_deinit_timeout; +static btstack_timer_source_t btstack_init_deinit_timeout; -STATIC void btstack_init_deinit_timeout_handler(btstack_timer_source_t *ds) { +static void btstack_init_deinit_timeout_handler(btstack_timer_source_t *ds) { (void)ds; // Stop waiting for initialisation. @@ -513,13 +513,13 @@ STATIC void btstack_init_deinit_timeout_handler(btstack_timer_source_t *ds) { } #if !MICROPY_BLUETOOTH_USE_MP_HAL_GET_MAC_STATIC_ADDRESS -STATIC void btstack_static_address_ready(void *arg) { +static void btstack_static_address_ready(void *arg) { DEBUG_printf("btstack_static_address_ready.\n"); *(volatile bool *)arg = true; } #endif -STATIC bool set_public_address(void) { +static bool set_public_address(void) { bd_addr_t local_addr; gap_local_bd_addr(local_addr); bd_addr_t null_addr = {0}; @@ -532,7 +532,7 @@ STATIC bool set_public_address(void) { return true; } -STATIC void set_random_address(void) { +static void set_random_address(void) { #if MICROPY_BLUETOOTH_USE_ZEPHYR_STATIC_ADDRESS if (controller_static_addr_available) { DEBUG_printf("set_random_address: Using static address supplied by controller.\n"); @@ -581,7 +581,7 @@ STATIC void set_random_address(void) { DEBUG_printf("set_random_address: Address loaded by controller\n"); } -STATIC void deinit_stack(void) { +static void deinit_stack(void) { mp_bluetooth_btstack_state = MP_BLUETOOTH_BTSTACK_STATE_OFF; // Deinitialise BTstack components. @@ -901,7 +901,7 @@ int mp_bluetooth_gatts_register_service_begin(bool append) { return 0; } -STATIC uint16_t att_read_callback(hci_con_handle_t connection_handle, uint16_t att_handle, uint16_t offset, uint8_t *buffer, uint16_t buffer_size) { +static uint16_t att_read_callback(hci_con_handle_t connection_handle, uint16_t att_handle, uint16_t offset, uint8_t *buffer, uint16_t buffer_size) { // Should return data length, 0 for error, or -1 for delayed response. // For more details search "*att_read_callback*" in micropython/lib/btstack/doc/manual/docs/profiles.md (void)connection_handle; @@ -926,7 +926,7 @@ STATIC uint16_t att_read_callback(hci_con_handle_t connection_handle, uint16_t a return ret; } -STATIC int att_write_callback(hci_con_handle_t connection_handle, uint16_t att_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size) { +static int att_write_callback(hci_con_handle_t connection_handle, uint16_t att_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size) { (void)offset; (void)transaction_mode; DEBUG_printf("att_write_callback (handle: %u, mode: %u, offset: %u, buffer: %p, size: %u)\n", att_handle, transaction_mode, offset, buffer, buffer_size); @@ -953,12 +953,12 @@ STATIC int att_write_callback(hci_con_handle_t connection_handle, uint16_t att_h return 0; } -STATIC inline uint16_t get_uuid16(const mp_obj_bluetooth_uuid_t *uuid) { +static inline uint16_t get_uuid16(const mp_obj_bluetooth_uuid_t *uuid) { return (uuid->data[1] << 8) | uuid->data[0]; } // Map MP_BLUETOOTH_CHARACTERISTIC_FLAG_ values to btstack read/write permission values. -STATIC void get_characteristic_permissions(uint16_t flags, uint16_t *read_permission, uint16_t *write_permission) { +static void get_characteristic_permissions(uint16_t flags, uint16_t *read_permission, uint16_t *write_permission) { if (flags & MP_BLUETOOTH_CHARACTERISTIC_FLAG_READ_ENCRYPTED) { *read_permission = ATT_SECURITY_ENCRYPTED; } else if (flags & MP_BLUETOOTH_CHARACTERISTIC_FLAG_READ_AUTHENTICATED) { @@ -1130,7 +1130,7 @@ typedef struct { // Called in response to a gatts_notify/indicate being unable to complete, which then calls // att_server_request_to_send_notification. -STATIC void btstack_notify_indicate_ready_handler(void *context) { +static void btstack_notify_indicate_ready_handler(void *context) { MICROPY_PY_BLUETOOTH_ENTER notify_indicate_pending_op_t *pending_op = (notify_indicate_pending_op_t *)context; DEBUG_printf("btstack_notify_indicate_ready_handler gatts_op=%d conn_handle=%d value_handle=%d len=%lu\n", pending_op->gatts_op, pending_op->conn_handle, pending_op->value_handle, pending_op->value_len); @@ -1270,9 +1270,9 @@ int mp_bluetooth_gap_passkey(uint16_t conn_handle, uint8_t action, mp_int_t pass #endif // MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING #if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE -STATIC btstack_timer_source_t scan_duration_timeout; +static btstack_timer_source_t scan_duration_timeout; -STATIC void scan_duration_timeout_handler(btstack_timer_source_t *ds) { +static void scan_duration_timeout_handler(btstack_timer_source_t *ds) { (void)ds; mp_bluetooth_gap_scan_stop(); } diff --git a/extmod/machine_adc.c b/extmod/machine_adc.c index 9849163de875b..11f1123dc794f 100644 --- a/extmod/machine_adc.c +++ b/extmod/machine_adc.c @@ -32,33 +32,33 @@ // The port must provide implementations of these low-level ADC functions. -STATIC void mp_machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind); -STATIC mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args); -STATIC mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self); +static void mp_machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind); +static mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args); +static mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self); #if MICROPY_PY_MACHINE_ADC_INIT -STATIC void mp_machine_adc_init_helper(machine_adc_obj_t *self, size_t n_pos_args, const mp_obj_t *pos_args, mp_map_t *kw_args); +static void mp_machine_adc_init_helper(machine_adc_obj_t *self, size_t n_pos_args, const mp_obj_t *pos_args, mp_map_t *kw_args); #endif #if MICROPY_PY_MACHINE_ADC_DEINIT -STATIC void mp_machine_adc_deinit(machine_adc_obj_t *self); +static void mp_machine_adc_deinit(machine_adc_obj_t *self); #endif #if MICROPY_PY_MACHINE_ADC_BLOCK -STATIC mp_obj_t mp_machine_adc_block(machine_adc_obj_t *self); +static mp_obj_t mp_machine_adc_block(machine_adc_obj_t *self); #endif #if MICROPY_PY_MACHINE_ADC_READ_UV -STATIC mp_int_t mp_machine_adc_read_uv(machine_adc_obj_t *self); +static mp_int_t mp_machine_adc_read_uv(machine_adc_obj_t *self); #endif #if MICROPY_PY_MACHINE_ADC_ATTEN_WIDTH -STATIC void mp_machine_adc_atten_set(machine_adc_obj_t *self, mp_int_t atten); -STATIC void mp_machine_adc_width_set(machine_adc_obj_t *self, mp_int_t width); +static void mp_machine_adc_atten_set(machine_adc_obj_t *self, mp_int_t atten); +static void mp_machine_adc_width_set(machine_adc_obj_t *self, mp_int_t width); #endif #if MICROPY_PY_MACHINE_ADC_READ -STATIC mp_int_t mp_machine_adc_read(machine_adc_obj_t *self); +static mp_int_t mp_machine_adc_read(machine_adc_obj_t *self); #endif // The port provides implementations of the above in this file. @@ -66,81 +66,81 @@ STATIC mp_int_t mp_machine_adc_read(machine_adc_obj_t *self); #if MICROPY_PY_MACHINE_ADC_INIT // ADC.init(...) -STATIC mp_obj_t machine_adc_init(size_t n_pos_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_adc_init(size_t n_pos_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { machine_adc_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); mp_machine_adc_init_helper(self, n_pos_args - 1, pos_args + 1, kw_args); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_adc_init_obj, 1, machine_adc_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(machine_adc_init_obj, 1, machine_adc_init); #endif #if MICROPY_PY_MACHINE_ADC_DEINIT // ADC.deinit() -STATIC mp_obj_t machine_adc_deinit(mp_obj_t self_in) { +static mp_obj_t machine_adc_deinit(mp_obj_t self_in) { machine_adc_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_machine_adc_deinit(self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_adc_deinit_obj, machine_adc_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_adc_deinit_obj, machine_adc_deinit); #endif #if MICROPY_PY_MACHINE_ADC_BLOCK // ADC.block() -STATIC mp_obj_t machine_adc_block(mp_obj_t self_in) { +static mp_obj_t machine_adc_block(mp_obj_t self_in) { machine_adc_obj_t *self = MP_OBJ_TO_PTR(self_in); return mp_machine_adc_block(self); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_adc_block_obj, machine_adc_block); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_adc_block_obj, machine_adc_block); #endif // ADC.read_u16() -STATIC mp_obj_t machine_adc_read_u16(mp_obj_t self_in) { +static mp_obj_t machine_adc_read_u16(mp_obj_t self_in) { machine_adc_obj_t *self = MP_OBJ_TO_PTR(self_in); return MP_OBJ_NEW_SMALL_INT(mp_machine_adc_read_u16(self)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_adc_read_u16_obj, machine_adc_read_u16); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_adc_read_u16_obj, machine_adc_read_u16); #if MICROPY_PY_MACHINE_ADC_READ_UV // ADC.read_uv() -STATIC mp_obj_t machine_adc_read_uv(mp_obj_t self_in) { +static mp_obj_t machine_adc_read_uv(mp_obj_t self_in) { machine_adc_obj_t *self = MP_OBJ_TO_PTR(self_in); return MP_OBJ_NEW_SMALL_INT(mp_machine_adc_read_uv(self)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_adc_read_uv_obj, machine_adc_read_uv); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_adc_read_uv_obj, machine_adc_read_uv); #endif #if MICROPY_PY_MACHINE_ADC_ATTEN_WIDTH // ADC.atten(value) -- this is a legacy method. -STATIC mp_obj_t machine_adc_atten(mp_obj_t self_in, mp_obj_t atten_in) { +static mp_obj_t machine_adc_atten(mp_obj_t self_in, mp_obj_t atten_in) { machine_adc_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t atten = mp_obj_get_int(atten_in); mp_machine_adc_atten_set(self, atten); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_adc_atten_obj, machine_adc_atten); +static MP_DEFINE_CONST_FUN_OBJ_2(machine_adc_atten_obj, machine_adc_atten); // ADC.width(value) -- this is a legacy method. -STATIC mp_obj_t machine_adc_width(mp_obj_t self_in, mp_obj_t width_in) { +static mp_obj_t machine_adc_width(mp_obj_t self_in, mp_obj_t width_in) { machine_adc_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t width = mp_obj_get_int(width_in); mp_machine_adc_width_set(self, width); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_adc_width_obj, machine_adc_width); +static MP_DEFINE_CONST_FUN_OBJ_2(machine_adc_width_obj, machine_adc_width); #endif #if MICROPY_PY_MACHINE_ADC_READ // ADC.read() -- this is a legacy method. -STATIC mp_obj_t machine_adc_read(mp_obj_t self_in) { +static mp_obj_t machine_adc_read(mp_obj_t self_in) { machine_adc_obj_t *self = MP_OBJ_TO_PTR(self_in); return MP_OBJ_NEW_SMALL_INT(mp_machine_adc_read(self)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_adc_read_obj, machine_adc_read); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_adc_read_obj, machine_adc_read); #endif -STATIC const mp_rom_map_elem_t machine_adc_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_adc_locals_dict_table[] = { #if MICROPY_PY_MACHINE_ADC_INIT { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_adc_init_obj) }, #endif @@ -169,7 +169,7 @@ STATIC const mp_rom_map_elem_t machine_adc_locals_dict_table[] = { // It can be defined to nothing if there are no constants. MICROPY_PY_MACHINE_ADC_CLASS_CONSTANTS }; -STATIC MP_DEFINE_CONST_DICT(machine_adc_locals_dict, machine_adc_locals_dict_table); +static MP_DEFINE_CONST_DICT(machine_adc_locals_dict, machine_adc_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( machine_adc_type, diff --git a/extmod/machine_adc_block.c b/extmod/machine_adc_block.c index f80e2dae4cc75..b1e35a1eb6766 100644 --- a/extmod/machine_adc_block.c +++ b/extmod/machine_adc_block.c @@ -33,20 +33,20 @@ #include "extmod/modmachine.h" // The port must provide implementations of these low-level ADCBlock functions. -STATIC void mp_machine_adc_block_print(const mp_print_t *print, machine_adc_block_obj_t *self); -STATIC machine_adc_block_obj_t *mp_machine_adc_block_get(mp_int_t unit); -STATIC void mp_machine_adc_block_bits_set(machine_adc_block_obj_t *self, mp_int_t bits); -STATIC machine_adc_obj_t *mp_machine_adc_block_connect(machine_adc_block_obj_t *self, mp_int_t channel_id, mp_hal_pin_obj_t pin, mp_map_t *kw_args); +static void mp_machine_adc_block_print(const mp_print_t *print, machine_adc_block_obj_t *self); +static machine_adc_block_obj_t *mp_machine_adc_block_get(mp_int_t unit); +static void mp_machine_adc_block_bits_set(machine_adc_block_obj_t *self, mp_int_t bits); +static machine_adc_obj_t *mp_machine_adc_block_connect(machine_adc_block_obj_t *self, mp_int_t channel_id, mp_hal_pin_obj_t pin, mp_map_t *kw_args); // The port provides implementations of the above in this file. #include MICROPY_PY_MACHINE_ADC_BLOCK_INCLUDEFILE -STATIC void machine_adc_block_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_adc_block_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_adc_block_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_machine_adc_block_print(print, self); } -STATIC void machine_adc_block_init_helper(machine_adc_block_obj_t *self, size_t n_pos_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void machine_adc_block_init_helper(machine_adc_block_obj_t *self, size_t n_pos_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_bits, }; @@ -62,7 +62,7 @@ STATIC void machine_adc_block_init_helper(machine_adc_block_obj_t *self, size_t mp_machine_adc_block_bits_set(self, bits); } -STATIC mp_obj_t machine_adc_block_make_new(const mp_obj_type_t *type, size_t n_pos_args, size_t n_kw_args, const mp_obj_t *args) { +static mp_obj_t machine_adc_block_make_new(const mp_obj_type_t *type, size_t n_pos_args, size_t n_kw_args, const mp_obj_t *args) { mp_arg_check_num(n_pos_args, n_kw_args, 1, MP_OBJ_FUN_ARGS_MAX, true); mp_int_t unit = mp_obj_get_int(args[0]); machine_adc_block_obj_t *self = mp_machine_adc_block_get(unit); @@ -77,14 +77,14 @@ STATIC mp_obj_t machine_adc_block_make_new(const mp_obj_type_t *type, size_t n_p return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t machine_adc_block_init(size_t n_pos_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_adc_block_init(size_t n_pos_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { machine_adc_block_obj_t *self = pos_args[0]; machine_adc_block_init_helper(self, n_pos_args - 1, pos_args + 1, kw_args); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_adc_block_init_obj, 1, machine_adc_block_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(machine_adc_block_init_obj, 1, machine_adc_block_init); -STATIC mp_obj_t machine_adc_block_connect(size_t n_pos_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_adc_block_connect(size_t n_pos_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { machine_adc_block_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); mp_int_t channel_id = -1; mp_hal_pin_obj_t pin = -1; @@ -108,13 +108,13 @@ STATIC mp_obj_t machine_adc_block_connect(size_t n_pos_args, const mp_obj_t *pos return MP_OBJ_FROM_PTR(adc); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_adc_block_connect_obj, 2, machine_adc_block_connect); +static MP_DEFINE_CONST_FUN_OBJ_KW(machine_adc_block_connect_obj, 2, machine_adc_block_connect); -STATIC const mp_rom_map_elem_t machine_adc_block_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_adc_block_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_adc_block_init_obj) }, { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&machine_adc_block_connect_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(machine_adc_block_locals_dict, machine_adc_block_locals_dict_table); +static MP_DEFINE_CONST_DICT(machine_adc_block_locals_dict, machine_adc_block_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( machine_adc_block_type, diff --git a/extmod/machine_bitstream.c b/extmod/machine_bitstream.c index af093a4b5483d..134961427407a 100644 --- a/extmod/machine_bitstream.c +++ b/extmod/machine_bitstream.c @@ -36,7 +36,7 @@ #define MICROPY_MACHINE_BITSTREAM_TYPE_HIGH_LOW (0) // machine.bitstream(pin, encoding, (timing), bytes) -STATIC mp_obj_t machine_bitstream_(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_bitstream_(size_t n_args, const mp_obj_t *args) { mp_hal_pin_obj_t pin = mp_hal_get_pin_obj(args[0]); int encoding = mp_obj_get_int(args[1]); diff --git a/extmod/machine_i2c.c b/extmod/machine_i2c.c index 1964284ec837d..bddf77529996d 100644 --- a/extmod/machine_i2c.c +++ b/extmod/machine_i2c.c @@ -39,17 +39,17 @@ typedef mp_machine_soft_i2c_obj_t machine_i2c_obj_t; -STATIC void mp_hal_i2c_delay(machine_i2c_obj_t *self) { +static void mp_hal_i2c_delay(machine_i2c_obj_t *self) { // We need to use an accurate delay to get acceptable I2C // speeds (eg 1us should be not much more than 1us). mp_hal_delay_us_fast(self->us_delay); } -STATIC void mp_hal_i2c_scl_low(machine_i2c_obj_t *self) { +static void mp_hal_i2c_scl_low(machine_i2c_obj_t *self) { mp_hal_pin_od_low(self->scl); } -STATIC int mp_hal_i2c_scl_release(machine_i2c_obj_t *self) { +static int mp_hal_i2c_scl_release(machine_i2c_obj_t *self) { uint32_t count = self->us_timeout; mp_hal_pin_od_high(self->scl); @@ -64,19 +64,19 @@ STATIC int mp_hal_i2c_scl_release(machine_i2c_obj_t *self) { return 0; // success } -STATIC void mp_hal_i2c_sda_low(machine_i2c_obj_t *self) { +static void mp_hal_i2c_sda_low(machine_i2c_obj_t *self) { mp_hal_pin_od_low(self->sda); } -STATIC void mp_hal_i2c_sda_release(machine_i2c_obj_t *self) { +static void mp_hal_i2c_sda_release(machine_i2c_obj_t *self) { mp_hal_pin_od_high(self->sda); } -STATIC int mp_hal_i2c_sda_read(machine_i2c_obj_t *self) { +static int mp_hal_i2c_sda_read(machine_i2c_obj_t *self) { return mp_hal_pin_read(self->sda); } -STATIC int mp_hal_i2c_start(machine_i2c_obj_t *self) { +static int mp_hal_i2c_start(machine_i2c_obj_t *self) { mp_hal_i2c_sda_release(self); mp_hal_i2c_delay(self); int ret = mp_hal_i2c_scl_release(self); @@ -88,7 +88,7 @@ STATIC int mp_hal_i2c_start(machine_i2c_obj_t *self) { return 0; // success } -STATIC int mp_hal_i2c_stop(machine_i2c_obj_t *self) { +static int mp_hal_i2c_stop(machine_i2c_obj_t *self) { mp_hal_i2c_delay(self); mp_hal_i2c_sda_low(self); mp_hal_i2c_delay(self); @@ -98,7 +98,7 @@ STATIC int mp_hal_i2c_stop(machine_i2c_obj_t *self) { return ret; } -STATIC void mp_hal_i2c_init(machine_i2c_obj_t *self, uint32_t freq) { +static void mp_hal_i2c_init(machine_i2c_obj_t *self, uint32_t freq) { self->us_delay = 500000 / freq; if (self->us_delay == 0) { self->us_delay = 1; @@ -112,7 +112,7 @@ STATIC void mp_hal_i2c_init(machine_i2c_obj_t *self, uint32_t freq) { // 0 - byte written and ack received // 1 - byte written and nack received // <0 - error, with errno being the negative of the return value -STATIC int mp_hal_i2c_write_byte(machine_i2c_obj_t *self, uint8_t val) { +static int mp_hal_i2c_write_byte(machine_i2c_obj_t *self, uint8_t val) { mp_hal_i2c_delay(self); mp_hal_i2c_scl_low(self); @@ -148,7 +148,7 @@ STATIC int mp_hal_i2c_write_byte(machine_i2c_obj_t *self, uint8_t val) { // return value: // 0 - success // <0 - error, with errno being the negative of the return value -STATIC int mp_hal_i2c_read_byte(machine_i2c_obj_t *self, uint8_t *val, int nack) { +static int mp_hal_i2c_read_byte(machine_i2c_obj_t *self, uint8_t *val, int nack) { mp_hal_i2c_delay(self); mp_hal_i2c_scl_low(self); mp_hal_i2c_delay(self); @@ -291,14 +291,14 @@ int mp_machine_i2c_transfer_adaptor(mp_obj_base_t *self, uint16_t addr, size_t n return ret; } -STATIC int mp_machine_i2c_readfrom(mp_obj_base_t *self, uint16_t addr, uint8_t *dest, size_t len, bool stop) { +static int mp_machine_i2c_readfrom(mp_obj_base_t *self, uint16_t addr, uint8_t *dest, size_t len, bool stop) { mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t *)MP_OBJ_TYPE_GET_SLOT(self->type, protocol); mp_machine_i2c_buf_t buf = {.len = len, .buf = dest}; unsigned int flags = MP_MACHINE_I2C_FLAG_READ | (stop ? MP_MACHINE_I2C_FLAG_STOP : 0); return i2c_p->transfer(self, addr, 1, &buf, flags); } -STATIC int mp_machine_i2c_writeto(mp_obj_base_t *self, uint16_t addr, const uint8_t *src, size_t len, bool stop) { +static int mp_machine_i2c_writeto(mp_obj_base_t *self, uint16_t addr, const uint8_t *src, size_t len, bool stop) { mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t *)MP_OBJ_TYPE_GET_SLOT(self->type, protocol); mp_machine_i2c_buf_t buf = {.len = len, .buf = (uint8_t *)src}; unsigned int flags = stop ? MP_MACHINE_I2C_FLAG_STOP : 0; @@ -308,7 +308,7 @@ STATIC int mp_machine_i2c_writeto(mp_obj_base_t *self, uint16_t addr, const uint /******************************************************************************/ // MicroPython bindings for generic machine.I2C -STATIC mp_obj_t machine_i2c_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t machine_i2c_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]); mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t *)MP_OBJ_TYPE_GET_SLOT(self->type, protocol); if (i2c_p->init == NULL) { @@ -319,7 +319,7 @@ STATIC mp_obj_t machine_i2c_init(size_t n_args, const mp_obj_t *args, mp_map_t * } MP_DEFINE_CONST_FUN_OBJ_KW(machine_i2c_init_obj, 1, machine_i2c_init); -STATIC mp_obj_t machine_i2c_scan(mp_obj_t self_in) { +static mp_obj_t machine_i2c_scan(mp_obj_t self_in) { mp_obj_base_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_t list = mp_obj_new_list(0, NULL); // 7-bit addresses 0b0000xxx and 0b1111xxx are reserved @@ -337,7 +337,7 @@ STATIC mp_obj_t machine_i2c_scan(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(machine_i2c_scan_obj, machine_i2c_scan); -STATIC mp_obj_t machine_i2c_start(mp_obj_t self_in) { +static mp_obj_t machine_i2c_start(mp_obj_t self_in) { mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(self_in); mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t *)MP_OBJ_TYPE_GET_SLOT(self->type, protocol); if (i2c_p->start == NULL) { @@ -351,7 +351,7 @@ STATIC mp_obj_t machine_i2c_start(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(machine_i2c_start_obj, machine_i2c_start); -STATIC mp_obj_t machine_i2c_stop(mp_obj_t self_in) { +static mp_obj_t machine_i2c_stop(mp_obj_t self_in) { mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(self_in); mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t *)MP_OBJ_TYPE_GET_SLOT(self->type, protocol); if (i2c_p->stop == NULL) { @@ -365,7 +365,7 @@ STATIC mp_obj_t machine_i2c_stop(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(machine_i2c_stop_obj, machine_i2c_stop); -STATIC mp_obj_t machine_i2c_readinto(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_i2c_readinto(size_t n_args, const mp_obj_t *args) { mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]); mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t *)MP_OBJ_TYPE_GET_SLOT(self->type, protocol); if (i2c_p->read == NULL) { @@ -389,7 +389,7 @@ STATIC mp_obj_t machine_i2c_readinto(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_readinto_obj, 2, 3, machine_i2c_readinto); -STATIC mp_obj_t machine_i2c_write(mp_obj_t self_in, mp_obj_t buf_in) { +static mp_obj_t machine_i2c_write(mp_obj_t self_in, mp_obj_t buf_in) { mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(self_in); mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t *)MP_OBJ_TYPE_GET_SLOT(self->type, protocol); if (i2c_p->write == NULL) { @@ -411,7 +411,7 @@ STATIC mp_obj_t machine_i2c_write(mp_obj_t self_in, mp_obj_t buf_in) { } MP_DEFINE_CONST_FUN_OBJ_2(machine_i2c_write_obj, machine_i2c_write); -STATIC mp_obj_t machine_i2c_readfrom(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_i2c_readfrom(size_t n_args, const mp_obj_t *args) { mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]); mp_int_t addr = mp_obj_get_int(args[1]); vstr_t vstr; @@ -425,7 +425,7 @@ STATIC mp_obj_t machine_i2c_readfrom(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_readfrom_obj, 3, 4, machine_i2c_readfrom); -STATIC mp_obj_t machine_i2c_readfrom_into(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_i2c_readfrom_into(size_t n_args, const mp_obj_t *args) { mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]); mp_int_t addr = mp_obj_get_int(args[1]); mp_buffer_info_t bufinfo; @@ -439,7 +439,7 @@ STATIC mp_obj_t machine_i2c_readfrom_into(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_readfrom_into_obj, 3, 4, machine_i2c_readfrom_into); -STATIC mp_obj_t machine_i2c_writeto(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_i2c_writeto(size_t n_args, const mp_obj_t *args) { mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]); mp_int_t addr = mp_obj_get_int(args[1]); mp_buffer_info_t bufinfo; @@ -452,9 +452,9 @@ STATIC mp_obj_t machine_i2c_writeto(size_t n_args, const mp_obj_t *args) { // return number of acks received return MP_OBJ_NEW_SMALL_INT(ret); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_writeto_obj, 3, 4, machine_i2c_writeto); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_writeto_obj, 3, 4, machine_i2c_writeto); -STATIC mp_obj_t machine_i2c_writevto(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_i2c_writevto(size_t n_args, const mp_obj_t *args) { mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]); mp_int_t addr = mp_obj_get_int(args[1]); @@ -498,9 +498,9 @@ STATIC mp_obj_t machine_i2c_writevto(size_t n_args, const mp_obj_t *args) { // Return number of acks received return MP_OBJ_NEW_SMALL_INT(ret); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_writevto_obj, 3, 4, machine_i2c_writevto); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_writevto_obj, 3, 4, machine_i2c_writevto); -STATIC size_t fill_memaddr_buf(uint8_t *memaddr_buf, uint32_t memaddr, uint8_t addrsize) { +static size_t fill_memaddr_buf(uint8_t *memaddr_buf, uint32_t memaddr, uint8_t addrsize) { size_t memaddr_len = 0; if ((addrsize & 7) != 0 || addrsize > 32) { mp_raise_ValueError(MP_ERROR_TEXT("invalid addrsize")); @@ -511,7 +511,7 @@ STATIC size_t fill_memaddr_buf(uint8_t *memaddr_buf, uint32_t memaddr, uint8_t a return memaddr_len; } -STATIC int read_mem(mp_obj_t self_in, uint16_t addr, uint32_t memaddr, uint8_t addrsize, uint8_t *buf, size_t len) { +static int read_mem(mp_obj_t self_in, uint16_t addr, uint32_t memaddr, uint8_t addrsize, uint8_t *buf, size_t len) { mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(self_in); // Create buffer with memory address @@ -543,7 +543,7 @@ STATIC int read_mem(mp_obj_t self_in, uint16_t addr, uint32_t memaddr, uint8_t a return mp_machine_i2c_readfrom(self, addr, buf, len, true); } -STATIC int write_mem(mp_obj_t self_in, uint16_t addr, uint32_t memaddr, uint8_t addrsize, const uint8_t *buf, size_t len) { +static int write_mem(mp_obj_t self_in, uint16_t addr, uint32_t memaddr, uint8_t addrsize, const uint8_t *buf, size_t len) { mp_obj_base_t *self = (mp_obj_base_t *)MP_OBJ_TO_PTR(self_in); // Create buffer with memory address @@ -561,14 +561,14 @@ STATIC int write_mem(mp_obj_t self_in, uint16_t addr, uint32_t memaddr, uint8_t return i2c_p->transfer(self, addr, 2, bufs, MP_MACHINE_I2C_FLAG_STOP); } -STATIC const mp_arg_t machine_i2c_mem_allowed_args[] = { +static const mp_arg_t machine_i2c_mem_allowed_args[] = { { MP_QSTR_addr, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_memaddr, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_arg, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_addrsize, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 8} }, }; -STATIC mp_obj_t machine_i2c_readfrom_mem(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_i2c_readfrom_mem(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_addr, ARG_memaddr, ARG_n, ARG_addrsize }; mp_arg_val_t args[MP_ARRAY_SIZE(machine_i2c_mem_allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, @@ -590,7 +590,7 @@ STATIC mp_obj_t machine_i2c_readfrom_mem(size_t n_args, const mp_obj_t *pos_args MP_DEFINE_CONST_FUN_OBJ_KW(machine_i2c_readfrom_mem_obj, 1, machine_i2c_readfrom_mem); -STATIC mp_obj_t machine_i2c_readfrom_mem_into(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_i2c_readfrom_mem_into(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_addr, ARG_memaddr, ARG_buf, ARG_addrsize }; mp_arg_val_t args[MP_ARRAY_SIZE(machine_i2c_mem_allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, @@ -610,7 +610,7 @@ STATIC mp_obj_t machine_i2c_readfrom_mem_into(size_t n_args, const mp_obj_t *pos } MP_DEFINE_CONST_FUN_OBJ_KW(machine_i2c_readfrom_mem_into_obj, 1, machine_i2c_readfrom_mem_into); -STATIC mp_obj_t machine_i2c_writeto_mem(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_i2c_writeto_mem(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_addr, ARG_memaddr, ARG_buf, ARG_addrsize }; mp_arg_val_t args[MP_ARRAY_SIZE(machine_i2c_mem_allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, @@ -629,9 +629,9 @@ STATIC mp_obj_t machine_i2c_writeto_mem(size_t n_args, const mp_obj_t *pos_args, return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_i2c_writeto_mem_obj, 1, machine_i2c_writeto_mem); +static MP_DEFINE_CONST_FUN_OBJ_KW(machine_i2c_writeto_mem_obj, 1, machine_i2c_writeto_mem); -STATIC const mp_rom_map_elem_t machine_i2c_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_i2c_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_i2c_init_obj) }, { MP_ROM_QSTR(MP_QSTR_scan), MP_ROM_PTR(&machine_i2c_scan_obj) }, @@ -661,13 +661,13 @@ MP_DEFINE_CONST_DICT(mp_machine_i2c_locals_dict, machine_i2c_locals_dict_table); #if MICROPY_PY_MACHINE_SOFTI2C -STATIC void mp_machine_soft_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_soft_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { mp_machine_soft_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "SoftI2C(scl=" MP_HAL_PIN_FMT ", sda=" MP_HAL_PIN_FMT ", freq=%u)", mp_hal_pin_name(self->scl), mp_hal_pin_name(self->sda), 500000 / self->us_delay); } -STATIC void mp_machine_soft_i2c_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void mp_machine_soft_i2c_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_scl, ARG_sda, ARG_freq, ARG_timeout }; static const mp_arg_t allowed_args[] = { { MP_QSTR_scl, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, @@ -686,7 +686,7 @@ STATIC void mp_machine_soft_i2c_init(mp_obj_base_t *self_in, size_t n_args, cons mp_hal_i2c_init(self, args[ARG_freq].u_int); } -STATIC mp_obj_t mp_machine_soft_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t mp_machine_soft_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // create new soft I2C object machine_i2c_obj_t *self = mp_obj_malloc(machine_i2c_obj_t, &mp_machine_soft_i2c_type); mp_map_t kw_args; @@ -722,7 +722,7 @@ int mp_machine_soft_i2c_write(mp_obj_base_t *self_in, const uint8_t *src, size_t return num_acks; } -STATIC const mp_machine_i2c_p_t mp_machine_soft_i2c_p = { +static const mp_machine_i2c_p_t mp_machine_soft_i2c_p = { .init = mp_machine_soft_i2c_init, .start = (int (*)(mp_obj_base_t *))mp_hal_i2c_start, .stop = (int (*)(mp_obj_base_t *))mp_hal_i2c_stop, diff --git a/extmod/machine_i2s.c b/extmod/machine_i2s.c index cc97f011a6d42..7e069c5d76cbf 100644 --- a/extmod/machine_i2s.c +++ b/extmod/machine_i2s.c @@ -108,21 +108,21 @@ typedef struct _non_blocking_descriptor_t { bool copy_in_progress; } non_blocking_descriptor_t; -STATIC void ringbuf_init(ring_buf_t *rbuf, uint8_t *buffer, size_t size); -STATIC bool ringbuf_push(ring_buf_t *rbuf, uint8_t data); -STATIC bool ringbuf_pop(ring_buf_t *rbuf, uint8_t *data); -STATIC size_t ringbuf_available_data(ring_buf_t *rbuf); -STATIC size_t ringbuf_available_space(ring_buf_t *rbuf); -STATIC void fill_appbuf_from_ringbuf_non_blocking(machine_i2s_obj_t *self); -STATIC void copy_appbuf_to_ringbuf_non_blocking(machine_i2s_obj_t *self); +static void ringbuf_init(ring_buf_t *rbuf, uint8_t *buffer, size_t size); +static bool ringbuf_push(ring_buf_t *rbuf, uint8_t data); +static bool ringbuf_pop(ring_buf_t *rbuf, uint8_t *data); +static size_t ringbuf_available_data(ring_buf_t *rbuf); +static size_t ringbuf_available_space(ring_buf_t *rbuf); +static void fill_appbuf_from_ringbuf_non_blocking(machine_i2s_obj_t *self); +static void copy_appbuf_to_ringbuf_non_blocking(machine_i2s_obj_t *self); #endif // MICROPY_PY_MACHINE_I2S_RING_BUF // The port must provide implementations of these low-level I2S functions. -STATIC void mp_machine_i2s_init_helper(machine_i2s_obj_t *self, mp_arg_val_t *args); -STATIC machine_i2s_obj_t *mp_machine_i2s_make_new_instance(mp_int_t i2s_id); -STATIC void mp_machine_i2s_deinit(machine_i2s_obj_t *self); -STATIC void mp_machine_i2s_irq_update(machine_i2s_obj_t *self); +static void mp_machine_i2s_init_helper(machine_i2s_obj_t *self, mp_arg_val_t *args); +static machine_i2s_obj_t *mp_machine_i2s_make_new_instance(mp_int_t i2s_id); +static void mp_machine_i2s_deinit(machine_i2s_obj_t *self); +static void mp_machine_i2s_irq_update(machine_i2s_obj_t *self); // The port provides implementations of the above in this file. #include MICROPY_PY_MACHINE_I2S_INCLUDEFILE @@ -135,14 +135,14 @@ STATIC void mp_machine_i2s_irq_update(machine_i2s_obj_t *self); // - Sequential atomic operations // One byte of capacity is used to detect buffer empty/full -STATIC void ringbuf_init(ring_buf_t *rbuf, uint8_t *buffer, size_t size) { +static void ringbuf_init(ring_buf_t *rbuf, uint8_t *buffer, size_t size) { rbuf->buffer = buffer; rbuf->size = size; rbuf->head = 0; rbuf->tail = 0; } -STATIC bool ringbuf_push(ring_buf_t *rbuf, uint8_t data) { +static bool ringbuf_push(ring_buf_t *rbuf, uint8_t data) { size_t next_tail = (rbuf->tail + 1) % rbuf->size; if (next_tail != rbuf->head) { @@ -155,7 +155,7 @@ STATIC bool ringbuf_push(ring_buf_t *rbuf, uint8_t data) { return false; } -STATIC bool ringbuf_pop(ring_buf_t *rbuf, uint8_t *data) { +static bool ringbuf_pop(ring_buf_t *rbuf, uint8_t *data) { if (rbuf->head == rbuf->tail) { // empty return false; @@ -166,23 +166,23 @@ STATIC bool ringbuf_pop(ring_buf_t *rbuf, uint8_t *data) { return true; } -STATIC bool ringbuf_is_empty(ring_buf_t *rbuf) { +static bool ringbuf_is_empty(ring_buf_t *rbuf) { return rbuf->head == rbuf->tail; } -STATIC bool ringbuf_is_full(ring_buf_t *rbuf) { +static bool ringbuf_is_full(ring_buf_t *rbuf) { return ((rbuf->tail + 1) % rbuf->size) == rbuf->head; } -STATIC size_t ringbuf_available_data(ring_buf_t *rbuf) { +static size_t ringbuf_available_data(ring_buf_t *rbuf) { return (rbuf->tail - rbuf->head + rbuf->size) % rbuf->size; } -STATIC size_t ringbuf_available_space(ring_buf_t *rbuf) { +static size_t ringbuf_available_space(ring_buf_t *rbuf) { return rbuf->size - ringbuf_available_data(rbuf) - 1; } -STATIC uint32_t fill_appbuf_from_ringbuf(machine_i2s_obj_t *self, mp_buffer_info_t *appbuf) { +static uint32_t fill_appbuf_from_ringbuf(machine_i2s_obj_t *self, mp_buffer_info_t *appbuf) { // copy audio samples from the ring buffer to the app buffer // loop, copying samples until the app buffer is filled @@ -247,7 +247,7 @@ STATIC uint32_t fill_appbuf_from_ringbuf(machine_i2s_obj_t *self, mp_buffer_info } // function is used in IRQ context -STATIC void fill_appbuf_from_ringbuf_non_blocking(machine_i2s_obj_t *self) { +static void fill_appbuf_from_ringbuf_non_blocking(machine_i2s_obj_t *self) { // attempt to copy a block of audio samples from the ring buffer to the supplied app buffer. // audio samples will be formatted as part of the copy operation @@ -288,7 +288,7 @@ STATIC void fill_appbuf_from_ringbuf_non_blocking(machine_i2s_obj_t *self) { } } -STATIC uint32_t copy_appbuf_to_ringbuf(machine_i2s_obj_t *self, mp_buffer_info_t *appbuf) { +static uint32_t copy_appbuf_to_ringbuf(machine_i2s_obj_t *self, mp_buffer_info_t *appbuf) { // copy audio samples from the app buffer to the ring buffer // loop, reading samples until the app buffer is emptied @@ -319,7 +319,7 @@ STATIC uint32_t copy_appbuf_to_ringbuf(machine_i2s_obj_t *self, mp_buffer_info_t } // function is used in IRQ context -STATIC void copy_appbuf_to_ringbuf_non_blocking(machine_i2s_obj_t *self) { +static void copy_appbuf_to_ringbuf_non_blocking(machine_i2s_obj_t *self) { // copy audio samples from app buffer into ring buffer uint32_t num_bytes_remaining_to_copy = self->non_blocking_descriptor.appbuf.len - self->non_blocking_descriptor.index; @@ -341,7 +341,7 @@ STATIC void copy_appbuf_to_ringbuf_non_blocking(machine_i2s_obj_t *self) { #endif // MICROPY_PY_MACHINE_I2S_RING_BUF -MP_NOINLINE STATIC void machine_i2s_init_helper(machine_i2s_obj_t *self, size_t n_pos_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +MP_NOINLINE static void machine_i2s_init_helper(machine_i2s_obj_t *self, size_t n_pos_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_sck, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_ws, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, @@ -362,7 +362,7 @@ MP_NOINLINE STATIC void machine_i2s_init_helper(machine_i2s_obj_t *self, size_t mp_machine_i2s_init_helper(self, args); } -STATIC void machine_i2s_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_i2s_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_i2s_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "I2S(id=%u,\n" "sck="MP_HAL_PIN_FMT ",\n" @@ -387,7 +387,7 @@ STATIC void machine_i2s_print(const mp_print_t *print, mp_obj_t self_in, mp_prin ); } -STATIC mp_obj_t machine_i2s_make_new(const mp_obj_type_t *type, size_t n_pos_args, size_t n_kw_args, const mp_obj_t *args) { +static mp_obj_t machine_i2s_make_new(const mp_obj_type_t *type, size_t n_pos_args, size_t n_kw_args, const mp_obj_t *args) { mp_arg_check_num(n_pos_args, n_kw_args, 1, MP_OBJ_FUN_ARGS_MAX, true); mp_int_t i2s_id = mp_obj_get_int(args[0]); @@ -401,24 +401,24 @@ STATIC mp_obj_t machine_i2s_make_new(const mp_obj_type_t *type, size_t n_pos_arg } // I2S.init(...) -STATIC mp_obj_t machine_i2s_init(size_t n_pos_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_i2s_init(size_t n_pos_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { machine_i2s_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); mp_machine_i2s_deinit(self); machine_i2s_init_helper(self, n_pos_args - 1, pos_args + 1, kw_args); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_i2s_init_obj, 1, machine_i2s_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(machine_i2s_init_obj, 1, machine_i2s_init); // I2S.deinit() -STATIC mp_obj_t machine_i2s_deinit(mp_obj_t self_in) { +static mp_obj_t machine_i2s_deinit(mp_obj_t self_in) { machine_i2s_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_machine_i2s_deinit(self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_i2s_deinit_obj, machine_i2s_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_i2s_deinit_obj, machine_i2s_deinit); // I2S.irq(handler) -STATIC mp_obj_t machine_i2s_irq(mp_obj_t self_in, mp_obj_t handler) { +static mp_obj_t machine_i2s_irq(mp_obj_t self_in, mp_obj_t handler) { machine_i2s_obj_t *self = MP_OBJ_TO_PTR(self_in); if (handler != mp_const_none && !mp_obj_is_callable(handler)) { mp_raise_ValueError(MP_ERROR_TEXT("invalid callback")); @@ -436,11 +436,11 @@ STATIC mp_obj_t machine_i2s_irq(mp_obj_t self_in, mp_obj_t handler) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_i2s_irq_obj, machine_i2s_irq); +static MP_DEFINE_CONST_FUN_OBJ_2(machine_i2s_irq_obj, machine_i2s_irq); // Shift() is typically used as a volume control. // shift=1 increases volume by 6dB, shift=-1 decreases volume by 6dB -STATIC mp_obj_t machine_i2s_shift(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_i2s_shift(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_buf, ARG_bits, ARG_shift}; static const mp_arg_t allowed_args[] = { { MP_QSTR_buf, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, @@ -497,10 +497,10 @@ STATIC mp_obj_t machine_i2s_shift(size_t n_args, const mp_obj_t *pos_args, mp_ma return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_i2s_shift_fun_obj, 0, machine_i2s_shift); -STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(machine_i2s_shift_obj, MP_ROM_PTR(&machine_i2s_shift_fun_obj)); +static MP_DEFINE_CONST_FUN_OBJ_KW(machine_i2s_shift_fun_obj, 0, machine_i2s_shift); +static MP_DEFINE_CONST_STATICMETHOD_OBJ(machine_i2s_shift_obj, MP_ROM_PTR(&machine_i2s_shift_fun_obj)); -STATIC const mp_rom_map_elem_t machine_i2s_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_i2s_locals_dict_table[] = { // Methods { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_i2s_init_obj) }, { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) }, @@ -522,7 +522,7 @@ STATIC const mp_rom_map_elem_t machine_i2s_locals_dict_table[] = { }; MP_DEFINE_CONST_DICT(machine_i2s_locals_dict, machine_i2s_locals_dict_table); -STATIC mp_uint_t machine_i2s_stream_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { +static mp_uint_t machine_i2s_stream_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { machine_i2s_obj_t *self = MP_OBJ_TO_PTR(self_in); if (self->mode != MICROPY_PY_MACHINE_I2S_CONSTANT_RX) { @@ -570,7 +570,7 @@ STATIC mp_uint_t machine_i2s_stream_read(mp_obj_t self_in, void *buf_in, mp_uint } } -STATIC mp_uint_t machine_i2s_stream_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { +static mp_uint_t machine_i2s_stream_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { machine_i2s_obj_t *self = MP_OBJ_TO_PTR(self_in); if (self->mode != MICROPY_PY_MACHINE_I2S_CONSTANT_TX) { @@ -612,7 +612,7 @@ STATIC mp_uint_t machine_i2s_stream_write(mp_obj_t self_in, const void *buf_in, } } -STATIC mp_uint_t machine_i2s_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t machine_i2s_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { machine_i2s_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_uint_t ret; uintptr_t flags = arg; @@ -678,7 +678,7 @@ STATIC mp_uint_t machine_i2s_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_ return ret; } -STATIC const mp_stream_p_t i2s_stream_p = { +static const mp_stream_p_t i2s_stream_p = { .read = machine_i2s_stream_read, .write = machine_i2s_stream_write, .ioctl = machine_i2s_ioctl, diff --git a/extmod/machine_mem.c b/extmod/machine_mem.c index 217c7ca0882b3..c8f0889b9a728 100644 --- a/extmod/machine_mem.c +++ b/extmod/machine_mem.c @@ -39,7 +39,7 @@ // implementations, if the default implementation isn't used. #if !defined(MICROPY_MACHINE_MEM_GET_READ_ADDR) || !defined(MICROPY_MACHINE_MEM_GET_WRITE_ADDR) -STATIC uintptr_t machine_mem_get_addr(mp_obj_t addr_o, uint align) { +static uintptr_t machine_mem_get_addr(mp_obj_t addr_o, uint align) { uintptr_t addr = mp_obj_get_int_truncated(addr_o); if ((addr & (align - 1)) != 0) { mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("address %08x is not aligned to %d bytes"), addr, align); @@ -54,13 +54,13 @@ STATIC uintptr_t machine_mem_get_addr(mp_obj_t addr_o, uint align) { #endif #endif -STATIC void machine_mem_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_mem_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; machine_mem_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "<%u-bit memory>", 8 * self->elem_size); } -STATIC mp_obj_t machine_mem_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { +static mp_obj_t machine_mem_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { // TODO support slice index to read/write multiple values at once machine_mem_obj_t *self = MP_OBJ_TO_PTR(self_in); if (value == MP_OBJ_NULL) { diff --git a/extmod/machine_pinbase.c b/extmod/machine_pinbase.c index 981dadf0f5e73..6b3b362317560 100644 --- a/extmod/machine_pinbase.c +++ b/extmod/machine_pinbase.c @@ -40,11 +40,11 @@ typedef struct _mp_pinbase_t { mp_obj_base_t base; } mp_pinbase_t; -STATIC const mp_pinbase_t pinbase_singleton = { +static const mp_pinbase_t pinbase_singleton = { .base = { &machine_pinbase_type }, }; -STATIC mp_obj_t pinbase_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pinbase_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type; (void)n_args; (void)n_kw; @@ -72,7 +72,7 @@ mp_uint_t pinbase_ioctl(mp_obj_t obj, mp_uint_t request, uintptr_t arg, int *err return -1; } -STATIC const mp_pin_p_t pinbase_pin_p = { +static const mp_pin_p_t pinbase_pin_p = { .ioctl = pinbase_ioctl, }; diff --git a/extmod/machine_pulse.c b/extmod/machine_pulse.c index 157566d9842fb..85dba86d9b5ad 100644 --- a/extmod/machine_pulse.c +++ b/extmod/machine_pulse.c @@ -46,7 +46,7 @@ MP_WEAK mp_uint_t machine_time_pulse_us(mp_hal_pin_obj_t pin, int pulse_level, m return mp_hal_ticks_us() - start; } -STATIC mp_obj_t machine_time_pulse_us_(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_time_pulse_us_(size_t n_args, const mp_obj_t *args) { mp_hal_pin_obj_t pin = mp_hal_get_pin_obj(args[0]); int level = 0; if (mp_obj_is_true(args[1])) { diff --git a/extmod/machine_pwm.c b/extmod/machine_pwm.c index 13b96eb5d4ec7..0c1834886c4df 100644 --- a/extmod/machine_pwm.c +++ b/extmod/machine_pwm.c @@ -31,40 +31,40 @@ #include "extmod/modmachine.h" // The port must provide implementations of these low-level PWM functions. -STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind); -STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args); -STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args); -STATIC void mp_machine_pwm_deinit(machine_pwm_obj_t *self); -STATIC mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self); -STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq); +static void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind); +static mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args); +static void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args); +static void mp_machine_pwm_deinit(machine_pwm_obj_t *self); +static mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self); +static void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq); #if MICROPY_PY_MACHINE_PWM_DUTY -STATIC mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self); -STATIC void mp_machine_pwm_duty_set(machine_pwm_obj_t *self, mp_int_t duty); +static mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self); +static void mp_machine_pwm_duty_set(machine_pwm_obj_t *self, mp_int_t duty); #endif -STATIC mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self); -STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16); -STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self); -STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns); +static mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self); +static void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16); +static mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self); +static void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns); // The port provides implementations of the above in this file. #include MICROPY_PY_MACHINE_PWM_INCLUDEFILE -STATIC mp_obj_t machine_pwm_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t machine_pwm_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { mp_machine_pwm_init_helper(args[0], n_args - 1, args + 1, kw_args); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_pwm_init_obj, 1, machine_pwm_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(machine_pwm_init_obj, 1, machine_pwm_init); // PWM.deinit() -STATIC mp_obj_t machine_pwm_deinit(mp_obj_t self_in) { +static mp_obj_t machine_pwm_deinit(mp_obj_t self_in) { machine_pwm_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_machine_pwm_deinit(self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pwm_deinit_obj, machine_pwm_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_pwm_deinit_obj, machine_pwm_deinit); // PWM.freq([value]) -STATIC mp_obj_t machine_pwm_freq(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_pwm_freq(size_t n_args, const mp_obj_t *args) { machine_pwm_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 1) { // Get frequency. @@ -76,11 +76,11 @@ STATIC mp_obj_t machine_pwm_freq(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pwm_freq_obj, 1, 2, machine_pwm_freq); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pwm_freq_obj, 1, 2, machine_pwm_freq); #if MICROPY_PY_MACHINE_PWM_DUTY // PWM.duty([duty]) -STATIC mp_obj_t machine_pwm_duty(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_pwm_duty(size_t n_args, const mp_obj_t *args) { machine_pwm_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 1) { // Get duty cycle. @@ -92,11 +92,11 @@ STATIC mp_obj_t machine_pwm_duty(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pwm_duty_obj, 1, 2, machine_pwm_duty); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pwm_duty_obj, 1, 2, machine_pwm_duty); #endif // PWM.duty_u16([value]) -STATIC mp_obj_t machine_pwm_duty_u16(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_pwm_duty_u16(size_t n_args, const mp_obj_t *args) { machine_pwm_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 1) { // Get duty cycle. @@ -108,10 +108,10 @@ STATIC mp_obj_t machine_pwm_duty_u16(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pwm_duty_u16_obj, 1, 2, machine_pwm_duty_u16); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pwm_duty_u16_obj, 1, 2, machine_pwm_duty_u16); // PWM.duty_ns([value]) -STATIC mp_obj_t machine_pwm_duty_ns(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_pwm_duty_ns(size_t n_args, const mp_obj_t *args) { machine_pwm_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 1) { // Get duty cycle. @@ -123,9 +123,9 @@ STATIC mp_obj_t machine_pwm_duty_ns(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pwm_duty_ns_obj, 1, 2, machine_pwm_duty_ns); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pwm_duty_ns_obj, 1, 2, machine_pwm_duty_ns); -STATIC const mp_rom_map_elem_t machine_pwm_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_pwm_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_pwm_init_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&machine_pwm_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&machine_pwm_freq_obj) }, @@ -135,7 +135,7 @@ STATIC const mp_rom_map_elem_t machine_pwm_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_duty_u16), MP_ROM_PTR(&machine_pwm_duty_u16_obj) }, { MP_ROM_QSTR(MP_QSTR_duty_ns), MP_ROM_PTR(&machine_pwm_duty_ns_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(machine_pwm_locals_dict, machine_pwm_locals_dict_table); +static MP_DEFINE_CONST_DICT(machine_pwm_locals_dict, machine_pwm_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( machine_pwm_type, diff --git a/extmod/machine_signal.c b/extmod/machine_signal.c index 63fd0fe479a2b..6295a496b3654 100644 --- a/extmod/machine_signal.c +++ b/extmod/machine_signal.c @@ -41,7 +41,7 @@ typedef struct _machine_signal_t { bool invert; } machine_signal_t; -STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_obj_t pin; bool invert = false; @@ -113,7 +113,7 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t return MP_OBJ_FROM_PTR(o); } -STATIC mp_uint_t signal_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t signal_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { (void)errcode; machine_signal_t *self = MP_OBJ_TO_PTR(self_in); @@ -130,7 +130,7 @@ STATIC mp_uint_t signal_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg } // fast method for getting/setting signal value -STATIC mp_obj_t signal_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t signal_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); if (n_args == 0) { // get pin @@ -142,32 +142,32 @@ STATIC mp_obj_t signal_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const } } -STATIC mp_obj_t signal_value(size_t n_args, const mp_obj_t *args) { +static mp_obj_t signal_value(size_t n_args, const mp_obj_t *args) { return signal_call(args[0], n_args - 1, 0, args + 1); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(signal_value_obj, 1, 2, signal_value); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(signal_value_obj, 1, 2, signal_value); -STATIC mp_obj_t signal_on(mp_obj_t self_in) { +static mp_obj_t signal_on(mp_obj_t self_in) { mp_virtual_pin_write(self_in, 1); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(signal_on_obj, signal_on); +static MP_DEFINE_CONST_FUN_OBJ_1(signal_on_obj, signal_on); -STATIC mp_obj_t signal_off(mp_obj_t self_in) { +static mp_obj_t signal_off(mp_obj_t self_in) { mp_virtual_pin_write(self_in, 0); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(signal_off_obj, signal_off); +static MP_DEFINE_CONST_FUN_OBJ_1(signal_off_obj, signal_off); -STATIC const mp_rom_map_elem_t signal_locals_dict_table[] = { +static const mp_rom_map_elem_t signal_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&signal_value_obj) }, { MP_ROM_QSTR(MP_QSTR_on), MP_ROM_PTR(&signal_on_obj) }, { MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(&signal_off_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(signal_locals_dict, signal_locals_dict_table); +static MP_DEFINE_CONST_DICT(signal_locals_dict, signal_locals_dict_table); -STATIC const mp_pin_p_t signal_pin_p = { +static const mp_pin_p_t signal_pin_p = { .ioctl = signal_ioctl, }; diff --git a/extmod/machine_spi.c b/extmod/machine_spi.c index e35e8b7fcc1ea..a1d18c905247a 100644 --- a/extmod/machine_spi.c +++ b/extmod/machine_spi.c @@ -42,15 +42,15 @@ /******************************************************************************/ // MicroPython bindings for generic machine.SPI -STATIC mp_obj_t machine_spi_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t machine_spi_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { mp_obj_base_t *s = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]); mp_machine_spi_p_t *spi_p = (mp_machine_spi_p_t *)MP_OBJ_TYPE_GET_SLOT(s->type, protocol); spi_p->init(s, n_args - 1, args + 1, kw_args); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_spi_init_obj, 1, machine_spi_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(machine_spi_init_obj, 1, machine_spi_init); -STATIC mp_obj_t machine_spi_deinit(mp_obj_t self) { +static mp_obj_t machine_spi_deinit(mp_obj_t self) { mp_obj_base_t *s = (mp_obj_base_t *)MP_OBJ_TO_PTR(self); mp_machine_spi_p_t *spi_p = (mp_machine_spi_p_t *)MP_OBJ_TYPE_GET_SLOT(s->type, protocol); if (spi_p->deinit != NULL) { @@ -58,15 +58,15 @@ STATIC mp_obj_t machine_spi_deinit(mp_obj_t self) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_spi_deinit_obj, machine_spi_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_spi_deinit_obj, machine_spi_deinit); -STATIC void mp_machine_spi_transfer(mp_obj_t self, size_t len, const void *src, void *dest) { +static void mp_machine_spi_transfer(mp_obj_t self, size_t len, const void *src, void *dest) { mp_obj_base_t *s = (mp_obj_base_t *)MP_OBJ_TO_PTR(self); mp_machine_spi_p_t *spi_p = (mp_machine_spi_p_t *)MP_OBJ_TYPE_GET_SLOT(s->type, protocol); spi_p->transfer(s, len, src, dest); } -STATIC mp_obj_t mp_machine_spi_read(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_machine_spi_read(size_t n_args, const mp_obj_t *args) { vstr_t vstr; vstr_init_len(&vstr, mp_obj_get_int(args[1])); memset(vstr.buf, n_args == 3 ? mp_obj_get_int(args[2]) : 0, vstr.len); @@ -75,7 +75,7 @@ STATIC mp_obj_t mp_machine_spi_read(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_machine_spi_read_obj, 2, 3, mp_machine_spi_read); -STATIC mp_obj_t mp_machine_spi_readinto(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_machine_spi_readinto(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_WRITE); memset(bufinfo.buf, n_args == 3 ? mp_obj_get_int(args[2]) : 0, bufinfo.len); @@ -84,7 +84,7 @@ STATIC mp_obj_t mp_machine_spi_readinto(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_machine_spi_readinto_obj, 2, 3, mp_machine_spi_readinto); -STATIC mp_obj_t mp_machine_spi_write(mp_obj_t self, mp_obj_t wr_buf) { +static mp_obj_t mp_machine_spi_write(mp_obj_t self, mp_obj_t wr_buf) { mp_buffer_info_t src; mp_get_buffer_raise(wr_buf, &src, MP_BUFFER_READ); mp_machine_spi_transfer(self, src.len, (const uint8_t *)src.buf, NULL); @@ -92,7 +92,7 @@ STATIC mp_obj_t mp_machine_spi_write(mp_obj_t self, mp_obj_t wr_buf) { } MP_DEFINE_CONST_FUN_OBJ_2(mp_machine_spi_write_obj, mp_machine_spi_write); -STATIC mp_obj_t mp_machine_spi_write_readinto(mp_obj_t self, mp_obj_t wr_buf, mp_obj_t rd_buf) { +static mp_obj_t mp_machine_spi_write_readinto(mp_obj_t self, mp_obj_t wr_buf, mp_obj_t rd_buf) { mp_buffer_info_t src; mp_get_buffer_raise(wr_buf, &src, MP_BUFFER_READ); mp_buffer_info_t dest; @@ -105,7 +105,7 @@ STATIC mp_obj_t mp_machine_spi_write_readinto(mp_obj_t self, mp_obj_t wr_buf, mp } MP_DEFINE_CONST_FUN_OBJ_3(mp_machine_spi_write_readinto_obj, mp_machine_spi_write_readinto); -STATIC const mp_rom_map_elem_t machine_spi_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_spi_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_spi_init_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&machine_spi_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_machine_spi_read_obj) }, @@ -125,7 +125,7 @@ MP_DEFINE_CONST_DICT(mp_machine_spi_locals_dict, machine_spi_locals_dict_table); #if MICROPY_PY_MACHINE_SOFTSPI -STATIC uint32_t baudrate_from_delay_half(uint32_t delay_half) { +static uint32_t baudrate_from_delay_half(uint32_t delay_half) { #ifdef MICROPY_HW_SOFTSPI_MIN_DELAY if (delay_half == MICROPY_HW_SOFTSPI_MIN_DELAY) { return MICROPY_HW_SOFTSPI_MAX_BAUDRATE; @@ -136,7 +136,7 @@ STATIC uint32_t baudrate_from_delay_half(uint32_t delay_half) { } } -STATIC uint32_t baudrate_to_delay_half(uint32_t baudrate) { +static uint32_t baudrate_to_delay_half(uint32_t baudrate) { #ifdef MICROPY_HW_SOFTSPI_MIN_DELAY if (baudrate >= MICROPY_HW_SOFTSPI_MAX_BAUDRATE) { return MICROPY_HW_SOFTSPI_MIN_DELAY; @@ -152,7 +152,7 @@ STATIC uint32_t baudrate_to_delay_half(uint32_t baudrate) { } } -STATIC void mp_machine_soft_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_soft_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { mp_machine_soft_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "SoftSPI(baudrate=%u, polarity=%u, phase=%u," " sck=" MP_HAL_PIN_FMT ", mosi=" MP_HAL_PIN_FMT ", miso=" MP_HAL_PIN_FMT ")", @@ -160,7 +160,7 @@ STATIC void mp_machine_soft_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_hal_pin_name(self->spi.sck), mp_hal_pin_name(self->spi.mosi), mp_hal_pin_name(self->spi.miso)); } -STATIC mp_obj_t mp_machine_soft_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t mp_machine_soft_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits, ARG_firstbit, ARG_sck, ARG_mosi, ARG_miso }; static const mp_arg_t allowed_args[] = { { MP_QSTR_baudrate, MP_ARG_INT, {.u_int = 500000} }, @@ -203,7 +203,7 @@ STATIC mp_obj_t mp_machine_soft_spi_make_new(const mp_obj_type_t *type, size_t n return MP_OBJ_FROM_PTR(self); } -STATIC void mp_machine_soft_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void mp_machine_soft_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_machine_soft_spi_obj_t *self = (mp_machine_soft_spi_obj_t *)self_in; enum { ARG_baudrate, ARG_polarity, ARG_phase, ARG_sck, ARG_mosi, ARG_miso }; @@ -241,7 +241,7 @@ STATIC void mp_machine_soft_spi_init(mp_obj_base_t *self_in, size_t n_args, cons mp_soft_spi_ioctl(&self->spi, MP_SPI_IOCTL_INIT); } -STATIC void mp_machine_soft_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) { +static void mp_machine_soft_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) { mp_machine_soft_spi_obj_t *self = (mp_machine_soft_spi_obj_t *)self_in; mp_soft_spi_transfer(&self->spi, len, src, dest); } diff --git a/extmod/machine_timer.c b/extmod/machine_timer.c index 68702cb74f605..665be82ce1211 100644 --- a/extmod/machine_timer.c +++ b/extmod/machine_timer.c @@ -35,13 +35,13 @@ typedef soft_timer_entry_t machine_timer_obj_t; const mp_obj_type_t machine_timer_type; -STATIC void machine_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_timer_obj_t *self = MP_OBJ_TO_PTR(self_in); qstr mode = self->mode == SOFT_TIMER_MODE_ONE_SHOT ? MP_QSTR_ONE_SHOT : MP_QSTR_PERIODIC; mp_printf(print, "Timer(mode=%q, period=%u)", mode, self->delta_ms); } -STATIC mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_mode, ARG_callback, ARG_period, ARG_tick_hz, ARG_freq, }; static const mp_arg_t allowed_args[] = { { MP_QSTR_mode, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = SOFT_TIMER_MODE_PERIODIC} }, @@ -88,7 +88,7 @@ STATIC mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, size_t n_ar return mp_const_none; } -STATIC mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { machine_timer_obj_t *self = m_new_obj(machine_timer_obj_t); self->pairheap.base.type = &machine_timer_type; self->flags = SOFT_TIMER_FLAG_PY_CALLBACK | SOFT_TIMER_FLAG_GC_ALLOCATED; @@ -116,28 +116,28 @@ STATIC mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args, return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t machine_timer_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t machine_timer_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { machine_timer_obj_t *self = MP_OBJ_TO_PTR(args[0]); soft_timer_remove(self); return machine_timer_init_helper(self, n_args - 1, args + 1, kw_args); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_timer_init_obj, 1, machine_timer_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(machine_timer_init_obj, 1, machine_timer_init); -STATIC mp_obj_t machine_timer_deinit(mp_obj_t self_in) { +static mp_obj_t machine_timer_deinit(mp_obj_t self_in) { machine_timer_obj_t *self = MP_OBJ_TO_PTR(self_in); soft_timer_remove(self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_deinit_obj, machine_timer_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_deinit_obj, machine_timer_deinit); -STATIC const mp_rom_map_elem_t machine_timer_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_timer_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_timer_init_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&machine_timer_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR_ONE_SHOT), MP_ROM_INT(SOFT_TIMER_MODE_ONE_SHOT) }, { MP_ROM_QSTR(MP_QSTR_PERIODIC), MP_ROM_INT(SOFT_TIMER_MODE_PERIODIC) }, }; -STATIC MP_DEFINE_CONST_DICT(machine_timer_locals_dict, machine_timer_locals_dict_table); +static MP_DEFINE_CONST_DICT(machine_timer_locals_dict, machine_timer_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( machine_timer_type, diff --git a/extmod/machine_uart.c b/extmod/machine_uart.c index dd556bbbbfafa..b62f5a49c465f 100644 --- a/extmod/machine_uart.c +++ b/extmod/machine_uart.c @@ -34,108 +34,108 @@ // The port must provide implementations of these low-level UART functions. -STATIC void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind); -STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args); -STATIC mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args); -STATIC void mp_machine_uart_deinit(machine_uart_obj_t *self); -STATIC mp_int_t mp_machine_uart_any(machine_uart_obj_t *self); -STATIC bool mp_machine_uart_txdone(machine_uart_obj_t *self); +static void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind); +static void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args); +static mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args); +static void mp_machine_uart_deinit(machine_uart_obj_t *self); +static mp_int_t mp_machine_uart_any(machine_uart_obj_t *self); +static bool mp_machine_uart_txdone(machine_uart_obj_t *self); #if MICROPY_PY_MACHINE_UART_SENDBREAK -STATIC void mp_machine_uart_sendbreak(machine_uart_obj_t *self); +static void mp_machine_uart_sendbreak(machine_uart_obj_t *self); #endif #if MICROPY_PY_MACHINE_UART_READCHAR_WRITECHAR -STATIC mp_int_t mp_machine_uart_readchar(machine_uart_obj_t *self); -STATIC void mp_machine_uart_writechar(machine_uart_obj_t *self, uint16_t data); +static mp_int_t mp_machine_uart_readchar(machine_uart_obj_t *self); +static void mp_machine_uart_writechar(machine_uart_obj_t *self, uint16_t data); #endif #if MICROPY_PY_MACHINE_UART_IRQ -STATIC mp_irq_obj_t *mp_machine_uart_irq(machine_uart_obj_t *self, bool any_args, mp_arg_val_t *args); +static mp_irq_obj_t *mp_machine_uart_irq(machine_uart_obj_t *self, bool any_args, mp_arg_val_t *args); #endif -STATIC mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode); -STATIC mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode); -STATIC mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode); +static mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode); +static mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode); +static mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode); // The port provides implementations of the above in this file. #include MICROPY_PY_MACHINE_UART_INCLUDEFILE // UART.init(...) -STATIC mp_obj_t machine_uart_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t machine_uart_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { mp_machine_uart_init_helper(MP_OBJ_TO_PTR(args[0]), n_args - 1, args + 1, kw_args); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_KW(machine_uart_init_obj, 1, machine_uart_init); // UART.deinit() -STATIC mp_obj_t machine_uart_deinit(mp_obj_t self_in) { +static mp_obj_t machine_uart_deinit(mp_obj_t self_in) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_machine_uart_deinit(self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_deinit_obj, machine_uart_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_deinit_obj, machine_uart_deinit); // UART.any() -STATIC mp_obj_t machine_uart_any(mp_obj_t self_in) { +static mp_obj_t machine_uart_any(mp_obj_t self_in) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); return MP_OBJ_NEW_SMALL_INT(mp_machine_uart_any(self)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_any_obj, machine_uart_any); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_any_obj, machine_uart_any); // UART.txdone() -STATIC mp_obj_t machine_uart_txdone(mp_obj_t self_in) { +static mp_obj_t machine_uart_txdone(mp_obj_t self_in) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_bool(mp_machine_uart_txdone(self)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_txdone_obj, machine_uart_txdone); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_txdone_obj, machine_uart_txdone); #if MICROPY_PY_MACHINE_UART_SENDBREAK // UART.sendbreak() -STATIC mp_obj_t machine_uart_sendbreak(mp_obj_t self_in) { +static mp_obj_t machine_uart_sendbreak(mp_obj_t self_in) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_machine_uart_sendbreak(self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_sendbreak_obj, machine_uart_sendbreak); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_sendbreak_obj, machine_uart_sendbreak); #endif #if MICROPY_PY_MACHINE_UART_READCHAR_WRITECHAR // UART.readchar() -STATIC mp_obj_t machine_uart_readchar(mp_obj_t self_in) { +static mp_obj_t machine_uart_readchar(mp_obj_t self_in) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); return MP_OBJ_NEW_SMALL_INT(mp_machine_uart_readchar(self)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_readchar_obj, machine_uart_readchar); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_readchar_obj, machine_uart_readchar); // UART.writechar(char) -STATIC mp_obj_t machine_uart_writechar(mp_obj_t self_in, mp_obj_t char_in) { +static mp_obj_t machine_uart_writechar(mp_obj_t self_in, mp_obj_t char_in) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_machine_uart_writechar(self, mp_obj_get_int(char_in)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_uart_writechar_obj, machine_uart_writechar); +static MP_DEFINE_CONST_FUN_OBJ_2(machine_uart_writechar_obj, machine_uart_writechar); #endif #if MICROPY_PY_MACHINE_UART_IRQ // UART.irq(handler, trigger, hard) -STATIC mp_obj_t machine_uart_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_uart_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_arg_val_t args[MP_IRQ_ARG_INIT_NUM_ARGS]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_IRQ_ARG_INIT_NUM_ARGS, mp_irq_init_args, args); machine_uart_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); bool any_args = n_args > 1 || kw_args->used != 0; return MP_OBJ_FROM_PTR(mp_machine_uart_irq(self, any_args, args)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_uart_irq_obj, 1, machine_uart_irq); +static MP_DEFINE_CONST_FUN_OBJ_KW(machine_uart_irq_obj, 1, machine_uart_irq); #endif -STATIC const mp_rom_map_elem_t machine_uart_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_uart_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_uart_init_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&machine_uart_deinit_obj) }, @@ -165,9 +165,9 @@ STATIC const mp_rom_map_elem_t machine_uart_locals_dict_table[] = { // It can be defined to nothing if there are no constants. MICROPY_PY_MACHINE_UART_CLASS_CONSTANTS }; -STATIC MP_DEFINE_CONST_DICT(machine_uart_locals_dict, machine_uart_locals_dict_table); +static MP_DEFINE_CONST_DICT(machine_uart_locals_dict, machine_uart_locals_dict_table); -STATIC const mp_stream_p_t uart_stream_p = { +static const mp_stream_p_t uart_stream_p = { .read = mp_machine_uart_read, .write = mp_machine_uart_write, .ioctl = mp_machine_uart_ioctl, diff --git a/extmod/machine_wdt.c b/extmod/machine_wdt.c index a49484ed80095..fcef1bda25040 100644 --- a/extmod/machine_wdt.c +++ b/extmod/machine_wdt.c @@ -31,16 +31,16 @@ #include "extmod/modmachine.h" // The port must provide implementations of these low-level WDT functions. -STATIC machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t timeout_ms); -STATIC void mp_machine_wdt_feed(machine_wdt_obj_t *self); +static machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t timeout_ms); +static void mp_machine_wdt_feed(machine_wdt_obj_t *self); #if MICROPY_PY_MACHINE_WDT_TIMEOUT_MS -STATIC void mp_machine_wdt_timeout_ms_set(machine_wdt_obj_t *self_in, mp_int_t timeout_ms); +static void mp_machine_wdt_timeout_ms_set(machine_wdt_obj_t *self_in, mp_int_t timeout_ms); #endif // The port provides implementations of the above in this file. #include MICROPY_PY_MACHINE_WDT_INCLUDEFILE -STATIC mp_obj_t machine_wdt_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t machine_wdt_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_id, ARG_timeout }; static const mp_arg_t allowed_args[] = { { MP_QSTR_id, MP_ARG_INT, {.u_int = 0} }, @@ -58,31 +58,31 @@ STATIC mp_obj_t machine_wdt_make_new(const mp_obj_type_t *type, size_t n_args, s } // WDT.feed() -STATIC mp_obj_t machine_wdt_feed(mp_obj_t self_in) { +static mp_obj_t machine_wdt_feed(mp_obj_t self_in) { machine_wdt_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_machine_wdt_feed(self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_wdt_feed_obj, machine_wdt_feed); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_wdt_feed_obj, machine_wdt_feed); #if MICROPY_PY_MACHINE_WDT_TIMEOUT_MS // WDT.timeout_ms(timeout) -STATIC mp_obj_t machine_wdt_timeout_ms(mp_obj_t self_in, mp_obj_t timeout_in) { +static mp_obj_t machine_wdt_timeout_ms(mp_obj_t self_in, mp_obj_t timeout_in) { machine_wdt_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t timeout_ms = mp_obj_get_int(timeout_in); mp_machine_wdt_timeout_ms_set(self, timeout_ms); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_wdt_timeout_ms_obj, machine_wdt_timeout_ms); +static MP_DEFINE_CONST_FUN_OBJ_2(machine_wdt_timeout_ms_obj, machine_wdt_timeout_ms); #endif -STATIC const mp_rom_map_elem_t machine_wdt_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_wdt_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_feed), MP_ROM_PTR(&machine_wdt_feed_obj) }, #if MICROPY_PY_MACHINE_WDT_TIMEOUT_MS { MP_ROM_QSTR(MP_QSTR_timeout_ms), MP_ROM_PTR(&machine_wdt_timeout_ms_obj) }, #endif }; -STATIC MP_DEFINE_CONST_DICT(machine_wdt_locals_dict, machine_wdt_locals_dict_table); +static MP_DEFINE_CONST_DICT(machine_wdt_locals_dict, machine_wdt_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( machine_wdt_type, diff --git a/extmod/modasyncio.c b/extmod/modasyncio.c index a6a54eba8765a..61dd707223ff1 100644 --- a/extmod/modasyncio.c +++ b/extmod/modasyncio.c @@ -55,19 +55,19 @@ typedef struct _mp_obj_task_queue_t { mp_obj_task_t *heap; } mp_obj_task_queue_t; -STATIC const mp_obj_type_t task_queue_type; -STATIC const mp_obj_type_t task_type; +static const mp_obj_type_t task_queue_type; +static const mp_obj_type_t task_type; -STATIC mp_obj_t task_queue_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args); +static mp_obj_t task_queue_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args); /******************************************************************************/ // Ticks for task ordering in pairing heap -STATIC mp_obj_t ticks(void) { +static mp_obj_t ticks(void) { return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & (MICROPY_PY_TIME_TICKS_PERIOD - 1)); } -STATIC mp_int_t ticks_diff(mp_obj_t t1_in, mp_obj_t t0_in) { +static mp_int_t ticks_diff(mp_obj_t t1_in, mp_obj_t t0_in) { mp_uint_t t0 = MP_OBJ_SMALL_INT_VALUE(t0_in); mp_uint_t t1 = MP_OBJ_SMALL_INT_VALUE(t1_in); mp_int_t diff = ((t1 - t0 + MICROPY_PY_TIME_TICKS_PERIOD / 2) & (MICROPY_PY_TIME_TICKS_PERIOD - 1)) @@ -75,7 +75,7 @@ STATIC mp_int_t ticks_diff(mp_obj_t t1_in, mp_obj_t t0_in) { return diff; } -STATIC int task_lt(mp_pairheap_t *n1, mp_pairheap_t *n2) { +static int task_lt(mp_pairheap_t *n1, mp_pairheap_t *n2) { mp_obj_task_t *t1 = (mp_obj_task_t *)n1; mp_obj_task_t *t2 = (mp_obj_task_t *)n2; return MP_OBJ_SMALL_INT_VALUE(ticks_diff(t1->ph_key, t2->ph_key)) < 0; @@ -84,7 +84,7 @@ STATIC int task_lt(mp_pairheap_t *n1, mp_pairheap_t *n2) { /******************************************************************************/ // TaskQueue class -STATIC mp_obj_t task_queue_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t task_queue_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)args; mp_arg_check_num(n_args, n_kw, 0, 0, false); mp_obj_task_queue_t *self = mp_obj_malloc(mp_obj_task_queue_t, type); @@ -92,7 +92,7 @@ STATIC mp_obj_t task_queue_make_new(const mp_obj_type_t *type, size_t n_args, si return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t task_queue_peek(mp_obj_t self_in) { +static mp_obj_t task_queue_peek(mp_obj_t self_in) { mp_obj_task_queue_t *self = MP_OBJ_TO_PTR(self_in); if (self->heap == NULL) { return mp_const_none; @@ -100,9 +100,9 @@ STATIC mp_obj_t task_queue_peek(mp_obj_t self_in) { return MP_OBJ_FROM_PTR(self->heap); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(task_queue_peek_obj, task_queue_peek); +static MP_DEFINE_CONST_FUN_OBJ_1(task_queue_peek_obj, task_queue_peek); -STATIC mp_obj_t task_queue_push(size_t n_args, const mp_obj_t *args) { +static mp_obj_t task_queue_push(size_t n_args, const mp_obj_t *args) { mp_obj_task_queue_t *self = MP_OBJ_TO_PTR(args[0]); mp_obj_task_t *task = MP_OBJ_TO_PTR(args[1]); task->data = mp_const_none; @@ -115,9 +115,9 @@ STATIC mp_obj_t task_queue_push(size_t n_args, const mp_obj_t *args) { self->heap = (mp_obj_task_t *)mp_pairheap_push(task_lt, TASK_PAIRHEAP(self->heap), TASK_PAIRHEAP(task)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(task_queue_push_obj, 2, 3, task_queue_push); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(task_queue_push_obj, 2, 3, task_queue_push); -STATIC mp_obj_t task_queue_pop(mp_obj_t self_in) { +static mp_obj_t task_queue_pop(mp_obj_t self_in) { mp_obj_task_queue_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_task_t *head = (mp_obj_task_t *)mp_pairheap_peek(task_lt, &self->heap->pairheap); if (head == NULL) { @@ -126,25 +126,25 @@ STATIC mp_obj_t task_queue_pop(mp_obj_t self_in) { self->heap = (mp_obj_task_t *)mp_pairheap_pop(task_lt, &self->heap->pairheap); return MP_OBJ_FROM_PTR(head); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(task_queue_pop_obj, task_queue_pop); +static MP_DEFINE_CONST_FUN_OBJ_1(task_queue_pop_obj, task_queue_pop); -STATIC mp_obj_t task_queue_remove(mp_obj_t self_in, mp_obj_t task_in) { +static mp_obj_t task_queue_remove(mp_obj_t self_in, mp_obj_t task_in) { mp_obj_task_queue_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_task_t *task = MP_OBJ_TO_PTR(task_in); self->heap = (mp_obj_task_t *)mp_pairheap_delete(task_lt, &self->heap->pairheap, &task->pairheap); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(task_queue_remove_obj, task_queue_remove); +static MP_DEFINE_CONST_FUN_OBJ_2(task_queue_remove_obj, task_queue_remove); -STATIC const mp_rom_map_elem_t task_queue_locals_dict_table[] = { +static const mp_rom_map_elem_t task_queue_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_peek), MP_ROM_PTR(&task_queue_peek_obj) }, { MP_ROM_QSTR(MP_QSTR_push), MP_ROM_PTR(&task_queue_push_obj) }, { MP_ROM_QSTR(MP_QSTR_pop), MP_ROM_PTR(&task_queue_pop_obj) }, { MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&task_queue_remove_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(task_queue_locals_dict, task_queue_locals_dict_table); +static MP_DEFINE_CONST_DICT(task_queue_locals_dict, task_queue_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( task_queue_type, MP_QSTR_TaskQueue, MP_TYPE_FLAG_NONE, @@ -156,9 +156,9 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( // Task class // This is the core asyncio context with cur_task, _task_queue and CancelledError. -STATIC mp_obj_t asyncio_context = MP_OBJ_NULL; +static mp_obj_t asyncio_context = MP_OBJ_NULL; -STATIC mp_obj_t task_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t task_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 2, false); mp_obj_task_t *self = m_new_obj(mp_obj_task_t); self->pairheap.base.type = type; @@ -173,13 +173,13 @@ STATIC mp_obj_t task_make_new(const mp_obj_type_t *type, size_t n_args, size_t n return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t task_done(mp_obj_t self_in) { +static mp_obj_t task_done(mp_obj_t self_in) { mp_obj_task_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_bool(TASK_IS_DONE(self)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(task_done_obj, task_done); +static MP_DEFINE_CONST_FUN_OBJ_1(task_done_obj, task_done); -STATIC mp_obj_t task_cancel(mp_obj_t self_in) { +static mp_obj_t task_cancel(mp_obj_t self_in) { mp_obj_task_t *self = MP_OBJ_TO_PTR(self_in); // Check if task is already finished. if (TASK_IS_DONE(self)) { @@ -222,9 +222,9 @@ STATIC mp_obj_t task_cancel(mp_obj_t self_in) { return mp_const_true; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(task_cancel_obj, task_cancel); +static MP_DEFINE_CONST_FUN_OBJ_1(task_cancel_obj, task_cancel); -STATIC void task_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void task_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { mp_obj_task_t *self = MP_OBJ_TO_PTR(self_in); if (dest[0] == MP_OBJ_NULL) { // Load @@ -255,7 +255,7 @@ STATIC void task_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } } -STATIC mp_obj_t task_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t task_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { (void)iter_buf; mp_obj_task_t *self = MP_OBJ_TO_PTR(self_in); if (TASK_IS_DONE(self)) { @@ -271,7 +271,7 @@ STATIC mp_obj_t task_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { return self_in; } -STATIC mp_obj_t task_iternext(mp_obj_t self_in) { +static mp_obj_t task_iternext(mp_obj_t self_in) { mp_obj_task_t *self = MP_OBJ_TO_PTR(self_in); if (TASK_IS_DONE(self)) { // Task finished, raise return value to caller so it can continue. @@ -287,12 +287,12 @@ STATIC mp_obj_t task_iternext(mp_obj_t self_in) { return mp_const_none; } -STATIC const mp_getiter_iternext_custom_t task_getiter_iternext = { +static const mp_getiter_iternext_custom_t task_getiter_iternext = { .getiter = task_getiter, .iternext = task_iternext, }; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( task_type, MP_QSTR_Task, MP_TYPE_FLAG_ITER_IS_CUSTOM, @@ -304,12 +304,12 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( /******************************************************************************/ // C-level asyncio module -STATIC const mp_rom_map_elem_t mp_module_asyncio_globals_table[] = { +static const mp_rom_map_elem_t mp_module_asyncio_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__asyncio) }, { MP_ROM_QSTR(MP_QSTR_TaskQueue), MP_ROM_PTR(&task_queue_type) }, { MP_ROM_QSTR(MP_QSTR_Task), MP_ROM_PTR(&task_type) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_asyncio_globals, mp_module_asyncio_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_asyncio_globals, mp_module_asyncio_globals_table); const mp_obj_module_t mp_module_asyncio = { .base = { &mp_type_module }, diff --git a/extmod/modbinascii.c b/extmod/modbinascii.c index ed39960180ae3..786226ebc07ae 100644 --- a/extmod/modbinascii.c +++ b/extmod/modbinascii.c @@ -35,15 +35,15 @@ #if MICROPY_PY_BINASCII #if MICROPY_PY_BUILTINS_BYTES_HEX -STATIC mp_obj_t bytes_hex_as_bytes(size_t n_args, const mp_obj_t *args) { +static mp_obj_t bytes_hex_as_bytes(size_t n_args, const mp_obj_t *args) { return mp_obj_bytes_hex(n_args, args, &mp_type_bytes); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bytes_hex_as_bytes_obj, 1, 2, bytes_hex_as_bytes); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bytes_hex_as_bytes_obj, 1, 2, bytes_hex_as_bytes); -STATIC mp_obj_t bytes_fromhex_bytes(mp_obj_t data) { +static mp_obj_t bytes_fromhex_bytes(mp_obj_t data) { return mp_obj_bytes_fromhex(MP_OBJ_FROM_PTR(&mp_type_bytes), data); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bytes_fromhex_obj, bytes_fromhex_bytes); +static MP_DEFINE_CONST_FUN_OBJ_1(bytes_fromhex_obj, bytes_fromhex_bytes); #endif // If ch is a character in the base64 alphabet, and is not a pad character, then @@ -65,7 +65,7 @@ static int mod_binascii_sextet(byte ch) { } } -STATIC mp_obj_t mod_binascii_a2b_base64(mp_obj_t data) { +static mp_obj_t mod_binascii_a2b_base64(mp_obj_t data) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ); byte *in = bufinfo.buf; @@ -106,9 +106,9 @@ STATIC mp_obj_t mod_binascii_a2b_base64(mp_obj_t data) { return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_binascii_a2b_base64_obj, mod_binascii_a2b_base64); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_binascii_a2b_base64_obj, mod_binascii_a2b_base64); -STATIC mp_obj_t mod_binascii_b2a_base64(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t mod_binascii_b2a_base64(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_newline }; static const mp_arg_t allowed_args[] = { { MP_QSTR_newline, MP_ARG_BOOL, {.u_bool = true} }, @@ -168,22 +168,22 @@ STATIC mp_obj_t mod_binascii_b2a_base64(size_t n_args, const mp_obj_t *pos_args, } return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_binascii_b2a_base64_obj, 1, mod_binascii_b2a_base64); +static MP_DEFINE_CONST_FUN_OBJ_KW(mod_binascii_b2a_base64_obj, 1, mod_binascii_b2a_base64); #if MICROPY_PY_BINASCII_CRC32 && MICROPY_PY_DEFLATE #include "lib/uzlib/uzlib.h" -STATIC mp_obj_t mod_binascii_crc32(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_binascii_crc32(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_READ); uint32_t crc = (n_args > 1) ? mp_obj_get_int_truncated(args[1]) : 0; crc = uzlib_crc32(bufinfo.buf, bufinfo.len, crc ^ 0xffffffff); return mp_obj_new_int_from_uint(crc ^ 0xffffffff); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_binascii_crc32_obj, 1, 2, mod_binascii_crc32); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_binascii_crc32_obj, 1, 2, mod_binascii_crc32); #endif -STATIC const mp_rom_map_elem_t mp_module_binascii_globals_table[] = { +static const mp_rom_map_elem_t mp_module_binascii_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_binascii) }, #if MICROPY_PY_BUILTINS_BYTES_HEX { MP_ROM_QSTR(MP_QSTR_hexlify), MP_ROM_PTR(&bytes_hex_as_bytes_obj) }, @@ -196,7 +196,7 @@ STATIC const mp_rom_map_elem_t mp_module_binascii_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_binascii_globals, mp_module_binascii_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_binascii_globals, mp_module_binascii_globals_table); const mp_obj_module_t mp_module_binascii = { .base = { &mp_type_module }, diff --git a/extmod/modbluetooth.c b/extmod/modbluetooth.c index 91e4e622132d5..7049c35dfdf56 100644 --- a/extmod/modbluetooth.c +++ b/extmod/modbluetooth.c @@ -81,10 +81,10 @@ typedef struct { #endif } mp_obj_bluetooth_ble_t; -STATIC const mp_obj_type_t mp_type_bluetooth_ble; +static const mp_obj_type_t mp_type_bluetooth_ble; // TODO: this seems like it could be generic? -STATIC mp_obj_t bluetooth_handle_errno(int err) { +static mp_obj_t bluetooth_handle_errno(int err) { if (err != 0) { mp_raise_OSError(err); } @@ -95,7 +95,7 @@ STATIC mp_obj_t bluetooth_handle_errno(int err) { // UUID object // ---------------------------------------------------------------------------- -STATIC mp_obj_t bluetooth_uuid_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t bluetooth_uuid_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { (void)type; mp_arg_check_num(n_args, n_kw, 1, 1, false); @@ -151,7 +151,7 @@ STATIC mp_obj_t bluetooth_uuid_make_new(const mp_obj_type_t *type, size_t n_args return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t bluetooth_uuid_unary_op(mp_unary_op_t op, mp_obj_t self_in) { +static mp_obj_t bluetooth_uuid_unary_op(mp_unary_op_t op, mp_obj_t self_in) { mp_obj_bluetooth_uuid_t *self = MP_OBJ_TO_PTR(self_in); switch (op) { case MP_UNARY_OP_HASH: { @@ -163,7 +163,7 @@ STATIC mp_obj_t bluetooth_uuid_unary_op(mp_unary_op_t op, mp_obj_t self_in) { } } -STATIC mp_obj_t bluetooth_uuid_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { +static mp_obj_t bluetooth_uuid_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { if (!mp_obj_is_type(rhs_in, &mp_type_bluetooth_uuid)) { return MP_OBJ_NULL; } @@ -187,7 +187,7 @@ STATIC mp_obj_t bluetooth_uuid_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_ } } -STATIC void bluetooth_uuid_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void bluetooth_uuid_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_bluetooth_uuid_t *self = MP_OBJ_TO_PTR(self_in); @@ -204,7 +204,7 @@ STATIC void bluetooth_uuid_print(const mp_print_t *print, mp_obj_t self_in, mp_p mp_printf(print, ")"); } -STATIC mp_int_t bluetooth_uuid_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { +static mp_int_t bluetooth_uuid_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { mp_obj_bluetooth_uuid_t *self = MP_OBJ_TO_PTR(self_in); if (flags != MP_BUFFER_READ) { @@ -220,7 +220,7 @@ STATIC mp_int_t bluetooth_uuid_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bu #if !MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS #if MICROPY_PY_BLUETOOTH_ENABLE_GATT_CLIENT -STATIC void ringbuf_put_uuid(ringbuf_t *ringbuf, mp_obj_bluetooth_uuid_t *uuid) { +static void ringbuf_put_uuid(ringbuf_t *ringbuf, mp_obj_bluetooth_uuid_t *uuid) { assert(ringbuf_free(ringbuf) >= (size_t)uuid->type + 1); ringbuf_put(ringbuf, uuid->type); for (int i = 0; i < uuid->type; ++i) { @@ -230,7 +230,7 @@ STATIC void ringbuf_put_uuid(ringbuf_t *ringbuf, mp_obj_bluetooth_uuid_t *uuid) #endif #if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE -STATIC void ringbuf_get_uuid(ringbuf_t *ringbuf, mp_obj_bluetooth_uuid_t *uuid) { +static void ringbuf_get_uuid(ringbuf_t *ringbuf, mp_obj_bluetooth_uuid_t *uuid) { assert(ringbuf_avail(ringbuf) >= 1); uuid->type = ringbuf_get(ringbuf); assert(ringbuf_avail(ringbuf) >= uuid->type); @@ -257,7 +257,7 @@ MP_DEFINE_CONST_OBJ_TYPE( // Bluetooth object: General // ---------------------------------------------------------------------------- -STATIC mp_obj_t bluetooth_ble_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t bluetooth_ble_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { (void)type; (void)n_args; (void)n_kw; @@ -287,7 +287,7 @@ STATIC mp_obj_t bluetooth_ble_make_new(const mp_obj_type_t *type, size_t n_args, return MP_STATE_VM(bluetooth); } -STATIC mp_obj_t bluetooth_ble_active(size_t n_args, const mp_obj_t *args) { +static mp_obj_t bluetooth_ble_active(size_t n_args, const mp_obj_t *args) { if (n_args == 2) { // Boolean enable/disable argument supplied, set current state. if (mp_obj_is_true(args[1])) { @@ -300,9 +300,9 @@ STATIC mp_obj_t bluetooth_ble_active(size_t n_args, const mp_obj_t *args) { // Return current state. return mp_obj_new_bool(mp_bluetooth_is_active()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_active_obj, 1, 2, bluetooth_ble_active); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_active_obj, 1, 2, bluetooth_ble_active); -STATIC mp_obj_t bluetooth_ble_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { +static mp_obj_t bluetooth_ble_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { if (kwargs->used == 0) { // Get config value if (n_args != 2) { @@ -426,9 +426,9 @@ STATIC mp_obj_t bluetooth_ble_config(size_t n_args, const mp_obj_t *args, mp_map return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bluetooth_ble_config_obj, 1, bluetooth_ble_config); +static MP_DEFINE_CONST_FUN_OBJ_KW(bluetooth_ble_config_obj, 1, bluetooth_ble_config); -STATIC mp_obj_t bluetooth_ble_irq(mp_obj_t self_in, mp_obj_t handler_in) { +static mp_obj_t bluetooth_ble_irq(mp_obj_t self_in, mp_obj_t handler_in) { (void)self_in; if (handler_in != mp_const_none && !mp_obj_is_callable(handler_in)) { mp_raise_ValueError(MP_ERROR_TEXT("invalid handler")); @@ -442,13 +442,13 @@ STATIC mp_obj_t bluetooth_ble_irq(mp_obj_t self_in, mp_obj_t handler_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(bluetooth_ble_irq_obj, bluetooth_ble_irq); +static MP_DEFINE_CONST_FUN_OBJ_2(bluetooth_ble_irq_obj, bluetooth_ble_irq); // ---------------------------------------------------------------------------- // Bluetooth object: GAP // ---------------------------------------------------------------------------- -STATIC mp_obj_t bluetooth_ble_gap_advertise(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t bluetooth_ble_gap_advertise(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_interval_us, ARG_adv_data, ARG_resp_data, ARG_connectable }; static const mp_arg_t allowed_args[] = { { MP_QSTR_interval_us, MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_SMALL_INT(500000)} }, @@ -479,9 +479,9 @@ STATIC mp_obj_t bluetooth_ble_gap_advertise(size_t n_args, const mp_obj_t *pos_a return bluetooth_handle_errno(mp_bluetooth_gap_advertise_start(connectable, interval_us, adv_bufinfo.buf, adv_bufinfo.len, resp_bufinfo.buf, resp_bufinfo.len)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bluetooth_ble_gap_advertise_obj, 1, bluetooth_ble_gap_advertise); +static MP_DEFINE_CONST_FUN_OBJ_KW(bluetooth_ble_gap_advertise_obj, 1, bluetooth_ble_gap_advertise); -STATIC int bluetooth_gatts_register_service(mp_obj_t uuid_in, mp_obj_t characteristics_in, uint16_t **handles, size_t *num_handles) { +static int bluetooth_gatts_register_service(mp_obj_t uuid_in, mp_obj_t characteristics_in, uint16_t **handles, size_t *num_handles) { if (!mp_obj_is_type(uuid_in, &mp_type_bluetooth_uuid)) { mp_raise_ValueError(MP_ERROR_TEXT("invalid service UUID")); } @@ -577,7 +577,7 @@ STATIC int bluetooth_gatts_register_service(mp_obj_t uuid_in, mp_obj_t character return mp_bluetooth_gatts_register_service(service_uuid, characteristic_uuids, characteristic_flags, descriptor_uuids, descriptor_flags, num_descriptors, *handles, len); } -STATIC mp_obj_t bluetooth_ble_gatts_register_services(mp_obj_t self_in, mp_obj_t services_in) { +static mp_obj_t bluetooth_ble_gatts_register_services(mp_obj_t self_in, mp_obj_t services_in) { (void)self_in; mp_obj_t len_in = mp_obj_len(services_in); size_t len = mp_obj_get_int(len_in); @@ -632,10 +632,10 @@ STATIC mp_obj_t bluetooth_ble_gatts_register_services(mp_obj_t self_in, mp_obj_t return MP_OBJ_FROM_PTR(result); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(bluetooth_ble_gatts_register_services_obj, bluetooth_ble_gatts_register_services); +static MP_DEFINE_CONST_FUN_OBJ_2(bluetooth_ble_gatts_register_services_obj, bluetooth_ble_gatts_register_services); #if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE -STATIC mp_obj_t bluetooth_ble_gap_connect(size_t n_args, const mp_obj_t *args) { +static mp_obj_t bluetooth_ble_gap_connect(size_t n_args, const mp_obj_t *args) { if (n_args == 2) { if (args[1] == mp_const_none) { int err = mp_bluetooth_gap_peripheral_connect_cancel(); @@ -665,9 +665,9 @@ STATIC mp_obj_t bluetooth_ble_gap_connect(size_t n_args, const mp_obj_t *args) { int err = mp_bluetooth_gap_peripheral_connect(addr_type, bufinfo.buf, scan_duration_ms, min_conn_interval_us, max_conn_interval_us); return bluetooth_handle_errno(err); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gap_connect_obj, 2, 6, bluetooth_ble_gap_connect); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gap_connect_obj, 2, 6, bluetooth_ble_gap_connect); -STATIC mp_obj_t bluetooth_ble_gap_scan(size_t n_args, const mp_obj_t *args) { +static mp_obj_t bluetooth_ble_gap_scan(size_t n_args, const mp_obj_t *args) { // Default is indefinite scan, with the NimBLE "background scan" interval and window. mp_int_t duration_ms = 0; mp_int_t interval_us = 1280000; @@ -691,10 +691,10 @@ STATIC mp_obj_t bluetooth_ble_gap_scan(size_t n_args, const mp_obj_t *args) { } return bluetooth_handle_errno(mp_bluetooth_gap_scan_start(duration_ms, interval_us, window_us, active_scan)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gap_scan_obj, 1, 5, bluetooth_ble_gap_scan); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gap_scan_obj, 1, 5, bluetooth_ble_gap_scan); #endif // MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE -STATIC mp_obj_t bluetooth_ble_gap_disconnect(mp_obj_t self_in, mp_obj_t conn_handle_in) { +static mp_obj_t bluetooth_ble_gap_disconnect(mp_obj_t self_in, mp_obj_t conn_handle_in) { (void)self_in; uint16_t conn_handle = mp_obj_get_int(conn_handle_in); int err = mp_bluetooth_gap_disconnect(conn_handle); @@ -706,39 +706,39 @@ STATIC mp_obj_t bluetooth_ble_gap_disconnect(mp_obj_t self_in, mp_obj_t conn_han return bluetooth_handle_errno(err); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(bluetooth_ble_gap_disconnect_obj, bluetooth_ble_gap_disconnect); +static MP_DEFINE_CONST_FUN_OBJ_2(bluetooth_ble_gap_disconnect_obj, bluetooth_ble_gap_disconnect); #if MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING -STATIC mp_obj_t bluetooth_ble_gap_pair(mp_obj_t self_in, mp_obj_t conn_handle_in) { +static mp_obj_t bluetooth_ble_gap_pair(mp_obj_t self_in, mp_obj_t conn_handle_in) { (void)self_in; uint16_t conn_handle = mp_obj_get_int(conn_handle_in); return bluetooth_handle_errno(mp_bluetooth_gap_pair(conn_handle)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(bluetooth_ble_gap_pair_obj, bluetooth_ble_gap_pair); +static MP_DEFINE_CONST_FUN_OBJ_2(bluetooth_ble_gap_pair_obj, bluetooth_ble_gap_pair); -STATIC mp_obj_t bluetooth_ble_gap_passkey(size_t n_args, const mp_obj_t *args) { +static mp_obj_t bluetooth_ble_gap_passkey(size_t n_args, const mp_obj_t *args) { uint16_t conn_handle = mp_obj_get_int(args[1]); uint8_t action = mp_obj_get_int(args[2]); mp_int_t passkey = mp_obj_get_int(args[3]); return bluetooth_handle_errno(mp_bluetooth_gap_passkey(conn_handle, action, passkey)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gap_passkey_obj, 4, 4, bluetooth_ble_gap_passkey); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gap_passkey_obj, 4, 4, bluetooth_ble_gap_passkey); #endif // MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING // ---------------------------------------------------------------------------- // Bluetooth object: GATTS (Peripheral/Advertiser role) // ---------------------------------------------------------------------------- -STATIC mp_obj_t bluetooth_ble_gatts_read(mp_obj_t self_in, mp_obj_t value_handle_in) { +static mp_obj_t bluetooth_ble_gatts_read(mp_obj_t self_in, mp_obj_t value_handle_in) { (void)self_in; size_t len = 0; const uint8_t *buf; mp_bluetooth_gatts_read(mp_obj_get_int(value_handle_in), &buf, &len); return mp_obj_new_bytes(buf, len); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(bluetooth_ble_gatts_read_obj, bluetooth_ble_gatts_read); +static MP_DEFINE_CONST_FUN_OBJ_2(bluetooth_ble_gatts_read_obj, bluetooth_ble_gatts_read); -STATIC mp_obj_t bluetooth_ble_gatts_write(size_t n_args, const mp_obj_t *args) { +static mp_obj_t bluetooth_ble_gatts_write(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t bufinfo = {0}; mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_READ); bool send_update = false; @@ -748,9 +748,9 @@ STATIC mp_obj_t bluetooth_ble_gatts_write(size_t n_args, const mp_obj_t *args) { bluetooth_handle_errno(mp_bluetooth_gatts_write(mp_obj_get_int(args[1]), bufinfo.buf, bufinfo.len, send_update)); return MP_OBJ_NEW_SMALL_INT(bufinfo.len); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gatts_write_obj, 3, 4, bluetooth_ble_gatts_write); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gatts_write_obj, 3, 4, bluetooth_ble_gatts_write); -STATIC mp_obj_t bluetooth_ble_gatts_notify_indicate(size_t n_args, const mp_obj_t *args, int gatts_op) { +static mp_obj_t bluetooth_ble_gatts_notify_indicate(size_t n_args, const mp_obj_t *args, int gatts_op) { mp_int_t conn_handle = mp_obj_get_int(args[1]); mp_int_t value_handle = mp_obj_get_int(args[2]); @@ -765,23 +765,23 @@ STATIC mp_obj_t bluetooth_ble_gatts_notify_indicate(size_t n_args, const mp_obj_ return bluetooth_handle_errno(mp_bluetooth_gatts_notify_indicate(conn_handle, value_handle, gatts_op, value, value_len)); } -STATIC mp_obj_t bluetooth_ble_gatts_notify(size_t n_args, const mp_obj_t *args) { +static mp_obj_t bluetooth_ble_gatts_notify(size_t n_args, const mp_obj_t *args) { return bluetooth_ble_gatts_notify_indicate(n_args, args, MP_BLUETOOTH_GATTS_OP_NOTIFY); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gatts_notify_obj, 3, 4, bluetooth_ble_gatts_notify); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gatts_notify_obj, 3, 4, bluetooth_ble_gatts_notify); -STATIC mp_obj_t bluetooth_ble_gatts_indicate(size_t n_args, const mp_obj_t *args) { +static mp_obj_t bluetooth_ble_gatts_indicate(size_t n_args, const mp_obj_t *args) { return bluetooth_ble_gatts_notify_indicate(n_args, args, MP_BLUETOOTH_GATTS_OP_INDICATE); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gatts_indicate_obj, 3, 4, bluetooth_ble_gatts_indicate); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gatts_indicate_obj, 3, 4, bluetooth_ble_gatts_indicate); -STATIC mp_obj_t bluetooth_ble_gatts_set_buffer(size_t n_args, const mp_obj_t *args) { +static mp_obj_t bluetooth_ble_gatts_set_buffer(size_t n_args, const mp_obj_t *args) { mp_int_t value_handle = mp_obj_get_int(args[1]); mp_int_t len = mp_obj_get_int(args[2]); bool append = n_args >= 4 && mp_obj_is_true(args[3]); return bluetooth_handle_errno(mp_bluetooth_gatts_set_buffer(value_handle, len, append)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gatts_set_buffer_obj, 3, 4, bluetooth_ble_gatts_set_buffer); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gatts_set_buffer_obj, 3, 4, bluetooth_ble_gatts_set_buffer); // ---------------------------------------------------------------------------- // Bluetooth object: GATTC (Central/Scanner role) @@ -789,7 +789,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gatts_set_buffer_obj, 3 #if MICROPY_PY_BLUETOOTH_ENABLE_GATT_CLIENT -STATIC mp_obj_t bluetooth_ble_gattc_discover_services(size_t n_args, const mp_obj_t *args) { +static mp_obj_t bluetooth_ble_gattc_discover_services(size_t n_args, const mp_obj_t *args) { mp_int_t conn_handle = mp_obj_get_int(args[1]); mp_obj_bluetooth_uuid_t *uuid = NULL; if (n_args == 3 && args[2] != mp_const_none) { @@ -800,9 +800,9 @@ STATIC mp_obj_t bluetooth_ble_gattc_discover_services(size_t n_args, const mp_ob } return bluetooth_handle_errno(mp_bluetooth_gattc_discover_primary_services(conn_handle, uuid)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gattc_discover_services_obj, 2, 3, bluetooth_ble_gattc_discover_services); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gattc_discover_services_obj, 2, 3, bluetooth_ble_gattc_discover_services); -STATIC mp_obj_t bluetooth_ble_gattc_discover_characteristics(size_t n_args, const mp_obj_t *args) { +static mp_obj_t bluetooth_ble_gattc_discover_characteristics(size_t n_args, const mp_obj_t *args) { mp_int_t conn_handle = mp_obj_get_int(args[1]); mp_int_t start_handle = mp_obj_get_int(args[2]); mp_int_t end_handle = mp_obj_get_int(args[3]); @@ -815,26 +815,26 @@ STATIC mp_obj_t bluetooth_ble_gattc_discover_characteristics(size_t n_args, cons } return bluetooth_handle_errno(mp_bluetooth_gattc_discover_characteristics(conn_handle, start_handle, end_handle, uuid)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gattc_discover_characteristics_obj, 4, 5, bluetooth_ble_gattc_discover_characteristics); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gattc_discover_characteristics_obj, 4, 5, bluetooth_ble_gattc_discover_characteristics); -STATIC mp_obj_t bluetooth_ble_gattc_discover_descriptors(size_t n_args, const mp_obj_t *args) { +static mp_obj_t bluetooth_ble_gattc_discover_descriptors(size_t n_args, const mp_obj_t *args) { (void)n_args; mp_int_t conn_handle = mp_obj_get_int(args[1]); mp_int_t start_handle = mp_obj_get_int(args[2]); mp_int_t end_handle = mp_obj_get_int(args[3]); return bluetooth_handle_errno(mp_bluetooth_gattc_discover_descriptors(conn_handle, start_handle, end_handle)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gattc_discover_descriptors_obj, 4, 4, bluetooth_ble_gattc_discover_descriptors); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gattc_discover_descriptors_obj, 4, 4, bluetooth_ble_gattc_discover_descriptors); -STATIC mp_obj_t bluetooth_ble_gattc_read(mp_obj_t self_in, mp_obj_t conn_handle_in, mp_obj_t value_handle_in) { +static mp_obj_t bluetooth_ble_gattc_read(mp_obj_t self_in, mp_obj_t conn_handle_in, mp_obj_t value_handle_in) { (void)self_in; mp_int_t conn_handle = mp_obj_get_int(conn_handle_in); mp_int_t value_handle = mp_obj_get_int(value_handle_in); return bluetooth_handle_errno(mp_bluetooth_gattc_read(conn_handle, value_handle)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(bluetooth_ble_gattc_read_obj, bluetooth_ble_gattc_read); +static MP_DEFINE_CONST_FUN_OBJ_3(bluetooth_ble_gattc_read_obj, bluetooth_ble_gattc_read); -STATIC mp_obj_t bluetooth_ble_gattc_write(size_t n_args, const mp_obj_t *args) { +static mp_obj_t bluetooth_ble_gattc_write(size_t n_args, const mp_obj_t *args) { mp_int_t conn_handle = mp_obj_get_int(args[1]); mp_int_t value_handle = mp_obj_get_int(args[2]); mp_obj_t data = args[3]; @@ -846,44 +846,44 @@ STATIC mp_obj_t bluetooth_ble_gattc_write(size_t n_args, const mp_obj_t *args) { } return bluetooth_handle_errno(mp_bluetooth_gattc_write(conn_handle, value_handle, bufinfo.buf, bufinfo.len, mode)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gattc_write_obj, 4, 5, bluetooth_ble_gattc_write); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gattc_write_obj, 4, 5, bluetooth_ble_gattc_write); -STATIC mp_obj_t bluetooth_ble_gattc_exchange_mtu(mp_obj_t self_in, mp_obj_t conn_handle_in) { +static mp_obj_t bluetooth_ble_gattc_exchange_mtu(mp_obj_t self_in, mp_obj_t conn_handle_in) { (void)self_in; uint16_t conn_handle = mp_obj_get_int(conn_handle_in); return bluetooth_handle_errno(mp_bluetooth_gattc_exchange_mtu(conn_handle)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(bluetooth_ble_gattc_exchange_mtu_obj, bluetooth_ble_gattc_exchange_mtu); +static MP_DEFINE_CONST_FUN_OBJ_2(bluetooth_ble_gattc_exchange_mtu_obj, bluetooth_ble_gattc_exchange_mtu); #endif // MICROPY_PY_BLUETOOTH_ENABLE_GATT_CLIENT #if MICROPY_PY_BLUETOOTH_ENABLE_L2CAP_CHANNELS -STATIC mp_obj_t bluetooth_ble_l2cap_listen(mp_obj_t self_in, mp_obj_t psm_in, mp_obj_t mtu_in) { +static mp_obj_t bluetooth_ble_l2cap_listen(mp_obj_t self_in, mp_obj_t psm_in, mp_obj_t mtu_in) { (void)self_in; mp_int_t psm = mp_obj_get_int(psm_in); mp_int_t mtu = MAX(32, MIN(UINT16_MAX, mp_obj_get_int(mtu_in))); return bluetooth_handle_errno(mp_bluetooth_l2cap_listen(psm, mtu)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(bluetooth_ble_l2cap_listen_obj, bluetooth_ble_l2cap_listen); +static MP_DEFINE_CONST_FUN_OBJ_3(bluetooth_ble_l2cap_listen_obj, bluetooth_ble_l2cap_listen); -STATIC mp_obj_t bluetooth_ble_l2cap_connect(size_t n_args, const mp_obj_t *args) { +static mp_obj_t bluetooth_ble_l2cap_connect(size_t n_args, const mp_obj_t *args) { mp_int_t conn_handle = mp_obj_get_int(args[1]); mp_int_t psm = mp_obj_get_int(args[2]); mp_int_t mtu = MAX(32, MIN(UINT16_MAX, mp_obj_get_int(args[3]))); return bluetooth_handle_errno(mp_bluetooth_l2cap_connect(conn_handle, psm, mtu)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_l2cap_connect_obj, 4, 4, bluetooth_ble_l2cap_connect); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_l2cap_connect_obj, 4, 4, bluetooth_ble_l2cap_connect); -STATIC mp_obj_t bluetooth_ble_l2cap_disconnect(mp_obj_t self_in, mp_obj_t conn_handle_in, mp_obj_t cid_in) { +static mp_obj_t bluetooth_ble_l2cap_disconnect(mp_obj_t self_in, mp_obj_t conn_handle_in, mp_obj_t cid_in) { (void)self_in; mp_int_t conn_handle = mp_obj_get_int(conn_handle_in); mp_int_t cid = mp_obj_get_int(cid_in); return bluetooth_handle_errno(mp_bluetooth_l2cap_disconnect(conn_handle, cid)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(bluetooth_ble_l2cap_disconnect_obj, bluetooth_ble_l2cap_disconnect); +static MP_DEFINE_CONST_FUN_OBJ_3(bluetooth_ble_l2cap_disconnect_obj, bluetooth_ble_l2cap_disconnect); -STATIC mp_obj_t bluetooth_ble_l2cap_send(size_t n_args, const mp_obj_t *args) { +static mp_obj_t bluetooth_ble_l2cap_send(size_t n_args, const mp_obj_t *args) { mp_int_t conn_handle = mp_obj_get_int(args[1]); mp_int_t cid = mp_obj_get_int(args[2]); mp_buffer_info_t bufinfo; @@ -893,9 +893,9 @@ STATIC mp_obj_t bluetooth_ble_l2cap_send(size_t n_args, const mp_obj_t *args) { // Return True if the channel is still ready to send. return mp_obj_new_bool(!stalled); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_l2cap_send_obj, 4, 4, bluetooth_ble_l2cap_send); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_l2cap_send_obj, 4, 4, bluetooth_ble_l2cap_send); -STATIC mp_obj_t bluetooth_ble_l2cap_recvinto(size_t n_args, const mp_obj_t *args) { +static mp_obj_t bluetooth_ble_l2cap_recvinto(size_t n_args, const mp_obj_t *args) { mp_int_t conn_handle = mp_obj_get_int(args[1]); mp_int_t cid = mp_obj_get_int(args[2]); mp_buffer_info_t bufinfo = {0}; @@ -905,13 +905,13 @@ STATIC mp_obj_t bluetooth_ble_l2cap_recvinto(size_t n_args, const mp_obj_t *args bluetooth_handle_errno(mp_bluetooth_l2cap_recvinto(conn_handle, cid, bufinfo.buf, &bufinfo.len)); return MP_OBJ_NEW_SMALL_INT(bufinfo.len); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_l2cap_recvinto_obj, 4, 4, bluetooth_ble_l2cap_recvinto); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_l2cap_recvinto_obj, 4, 4, bluetooth_ble_l2cap_recvinto); #endif // MICROPY_PY_BLUETOOTH_ENABLE_L2CAP_CHANNELS #if MICROPY_PY_BLUETOOTH_ENABLE_HCI_CMD -STATIC mp_obj_t bluetooth_ble_hci_cmd(size_t n_args, const mp_obj_t *args) { +static mp_obj_t bluetooth_ble_hci_cmd(size_t n_args, const mp_obj_t *args) { mp_int_t ogf = mp_obj_get_int(args[1]); mp_int_t ocf = mp_obj_get_int(args[2]); mp_buffer_info_t bufinfo_request = {0}; @@ -922,7 +922,7 @@ STATIC mp_obj_t bluetooth_ble_hci_cmd(size_t n_args, const mp_obj_t *args) { bluetooth_handle_errno(mp_bluetooth_hci_cmd(ogf, ocf, bufinfo_request.buf, bufinfo_request.len, bufinfo_response.buf, bufinfo_response.len, &status)); return MP_OBJ_NEW_SMALL_INT(status); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_hci_cmd_obj, 5, 5, bluetooth_ble_hci_cmd); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_hci_cmd_obj, 5, 5, bluetooth_ble_hci_cmd); #endif // MICROPY_PY_BLUETOOTH_ENABLE_HCI_CMD @@ -930,7 +930,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_hci_cmd_obj, 5, 5, blue // Bluetooth object: Definition // ---------------------------------------------------------------------------- -STATIC const mp_rom_map_elem_t bluetooth_ble_locals_dict_table[] = { +static const mp_rom_map_elem_t bluetooth_ble_locals_dict_table[] = { // General { MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&bluetooth_ble_active_obj) }, { MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&bluetooth_ble_config_obj) }, @@ -973,9 +973,9 @@ STATIC const mp_rom_map_elem_t bluetooth_ble_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_hci_cmd), MP_ROM_PTR(&bluetooth_ble_hci_cmd_obj) }, #endif }; -STATIC MP_DEFINE_CONST_DICT(bluetooth_ble_locals_dict, bluetooth_ble_locals_dict_table); +static MP_DEFINE_CONST_DICT(bluetooth_ble_locals_dict, bluetooth_ble_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_bluetooth_ble, MP_QSTR_BLE, MP_TYPE_FLAG_NONE, @@ -983,7 +983,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &bluetooth_ble_locals_dict ); -STATIC const mp_rom_map_elem_t mp_module_bluetooth_globals_table[] = { +static const mp_rom_map_elem_t mp_module_bluetooth_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_bluetooth) }, { MP_ROM_QSTR(MP_QSTR_BLE), MP_ROM_PTR(&mp_type_bluetooth_ble) }, { MP_ROM_QSTR(MP_QSTR_UUID), MP_ROM_PTR(&mp_type_bluetooth_uuid) }, @@ -996,7 +996,7 @@ STATIC const mp_rom_map_elem_t mp_module_bluetooth_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_FLAG_WRITE_NO_RESPONSE), MP_ROM_INT(MP_BLUETOOTH_CHARACTERISTIC_FLAG_WRITE_NO_RESPONSE) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_bluetooth_globals, mp_module_bluetooth_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_bluetooth_globals, mp_module_bluetooth_globals_table); const mp_obj_module_t mp_module_bluetooth = { .base = { &mp_type_module }, @@ -1012,7 +1012,7 @@ MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_bluetooth, mp_module_bluetooth); // Helpers #if !MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS -STATIC void ringbuf_extract(ringbuf_t *ringbuf, mp_obj_tuple_t *data_tuple, size_t n_u16, size_t n_u8, mp_obj_array_t *bytes_addr, size_t n_i8, mp_obj_bluetooth_uuid_t *uuid, mp_obj_array_t *bytes_data) { +static void ringbuf_extract(ringbuf_t *ringbuf, mp_obj_tuple_t *data_tuple, size_t n_u16, size_t n_u8, mp_obj_array_t *bytes_addr, size_t n_i8, mp_obj_bluetooth_uuid_t *uuid, mp_obj_array_t *bytes_data) { assert(ringbuf_avail(ringbuf) >= n_u16 * 2 + n_u8 + (bytes_addr ? 6 : 0) + n_i8 + (uuid ? 1 : 0) + (bytes_data ? 1 : 0)); size_t j = 0; @@ -1053,7 +1053,7 @@ STATIC void ringbuf_extract(ringbuf_t *ringbuf, mp_obj_tuple_t *data_tuple, size data_tuple->len = j; } -STATIC mp_obj_t bluetooth_ble_invoke_irq(mp_obj_t none_in) { +static mp_obj_t bluetooth_ble_invoke_irq(mp_obj_t none_in) { (void)none_in; // This is always executing in schedule context. @@ -1129,7 +1129,7 @@ STATIC mp_obj_t bluetooth_ble_invoke_irq(mp_obj_t none_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bluetooth_ble_invoke_irq_obj, bluetooth_ble_invoke_irq); +static MP_DEFINE_CONST_FUN_OBJ_1(bluetooth_ble_invoke_irq_obj, bluetooth_ble_invoke_irq); #endif // !MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS // ---------------------------------------------------------------------------- @@ -1138,7 +1138,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(bluetooth_ble_invoke_irq_obj, bluetooth_ble_inv #if MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS -STATIC mp_obj_t invoke_irq_handler_run(uint16_t event, +static mp_obj_t invoke_irq_handler_run(uint16_t event, const mp_int_t *numeric, size_t n_unsigned, size_t n_signed, const uint8_t *addr, const mp_obj_bluetooth_uuid_t *uuid, @@ -1220,7 +1220,7 @@ STATIC mp_obj_t invoke_irq_handler_run(uint16_t event, return result; } -STATIC mp_obj_t invoke_irq_handler_run_protected(uint16_t event, +static mp_obj_t invoke_irq_handler_run_protected(uint16_t event, const mp_int_t *numeric, size_t n_unsigned, size_t n_signed, const uint8_t *addr, const mp_obj_bluetooth_uuid_t *uuid, @@ -1258,7 +1258,7 @@ STATIC mp_obj_t invoke_irq_handler_run_protected(uint16_t event, #error not supported #endif -STATIC mp_obj_t invoke_irq_handler(uint16_t event, +static mp_obj_t invoke_irq_handler(uint16_t event, const mp_int_t *numeric, size_t n_unsigned, size_t n_signed, const uint8_t *addr, const mp_obj_bluetooth_uuid_t *uuid, @@ -1292,7 +1292,7 @@ STATIC mp_obj_t invoke_irq_handler(uint16_t event, // BLE event callbacks are called directly from the MicroPython runtime, so additional // synchronisation is not needed, and BLE event handlers can be called directly. -STATIC mp_obj_t invoke_irq_handler(uint16_t event, +static mp_obj_t invoke_irq_handler(uint16_t event, const mp_int_t *numeric, size_t n_unsigned, size_t n_signed, const uint8_t *addr, const mp_obj_bluetooth_uuid_t *uuid, @@ -1455,7 +1455,7 @@ void mp_bluetooth_gattc_on_read_write_status(uint8_t event, uint16_t conn_handle // Callbacks are called in interrupt context (i.e. can't allocate), so we need to push the data // into the ringbuf and schedule the callback via mp_sched_schedule. -STATIC bool enqueue_irq(mp_obj_bluetooth_ble_t *o, size_t len, uint8_t event) { +static bool enqueue_irq(mp_obj_bluetooth_ble_t *o, size_t len, uint8_t event) { if (!o || o->irq_handler == mp_const_none) { return false; } @@ -1489,7 +1489,7 @@ STATIC bool enqueue_irq(mp_obj_bluetooth_ble_t *o, size_t len, uint8_t event) { } // Must hold the atomic section before calling this (MICROPY_PY_BLUETOOTH_ENTER). -STATIC void schedule_ringbuf(mp_uint_t atomic_state) { +static void schedule_ringbuf(mp_uint_t atomic_state) { mp_obj_bluetooth_ble_t *o = MP_OBJ_TO_PTR(MP_STATE_VM(bluetooth)); if (!o->irq_scheduled) { o->irq_scheduled = true; diff --git a/extmod/modbluetooth.h b/extmod/modbluetooth.h index 630a2705231e2..6a087c8e256cc 100644 --- a/extmod/modbluetooth.h +++ b/extmod/modbluetooth.h @@ -498,11 +498,11 @@ typedef struct { typedef mp_map_t *mp_gatts_db_t; -STATIC inline void mp_bluetooth_gatts_db_create(mp_gatts_db_t *db) { +static inline void mp_bluetooth_gatts_db_create(mp_gatts_db_t *db) { *db = m_new(mp_map_t, 1); } -STATIC inline void mp_bluetooth_gatts_db_reset(mp_gatts_db_t db) { +static inline void mp_bluetooth_gatts_db_reset(mp_gatts_db_t db) { mp_map_init(db, 0); } diff --git a/extmod/modbtree.c b/extmod/modbtree.c index 9b2d184a1ee79..f8c38e0ad4306 100644 --- a/extmod/modbtree.c +++ b/extmod/modbtree.c @@ -77,7 +77,7 @@ typedef struct _mp_obj_btree_t { } mp_obj_btree_t; #if !MICROPY_ENABLE_DYNRUNTIME -STATIC const mp_obj_type_t btree_type; +static const mp_obj_type_t btree_type; #endif #define CHECK_ERROR(res) \ @@ -89,7 +89,7 @@ void __dbpanic(DB *db) { mp_printf(&mp_plat_print, "__dbpanic(%p)\n", db); } -STATIC mp_obj_btree_t *btree_new(DB *db, mp_obj_t stream) { +static mp_obj_btree_t *btree_new(DB *db, mp_obj_t stream) { mp_obj_btree_t *o = mp_obj_malloc(mp_obj_btree_t, (mp_obj_type_t *)&btree_type); o->stream = stream; o->db = db; @@ -99,32 +99,32 @@ STATIC mp_obj_btree_t *btree_new(DB *db, mp_obj_t stream) { return o; } -STATIC void buf_to_dbt(mp_obj_t obj, DBT *dbt) { +static void buf_to_dbt(mp_obj_t obj, DBT *dbt) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(obj, &bufinfo, MP_BUFFER_READ); dbt->data = bufinfo.buf; dbt->size = bufinfo.len; } -STATIC void btree_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void btree_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_btree_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", self->db); } -STATIC mp_obj_t btree_flush(mp_obj_t self_in) { +static mp_obj_t btree_flush(mp_obj_t self_in) { mp_obj_btree_t *self = MP_OBJ_TO_PTR(self_in); return MP_OBJ_NEW_SMALL_INT(__bt_sync(self->db, 0)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(btree_flush_obj, btree_flush); +static MP_DEFINE_CONST_FUN_OBJ_1(btree_flush_obj, btree_flush); -STATIC mp_obj_t btree_close(mp_obj_t self_in) { +static mp_obj_t btree_close(mp_obj_t self_in) { mp_obj_btree_t *self = MP_OBJ_TO_PTR(self_in); return MP_OBJ_NEW_SMALL_INT(__bt_close(self->db)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(btree_close_obj, btree_close); +static MP_DEFINE_CONST_FUN_OBJ_1(btree_close_obj, btree_close); -STATIC mp_obj_t btree_put(size_t n_args, const mp_obj_t *args) { +static mp_obj_t btree_put(size_t n_args, const mp_obj_t *args) { (void)n_args; mp_obj_btree_t *self = MP_OBJ_TO_PTR(args[0]); DBT key, val; @@ -132,9 +132,9 @@ STATIC mp_obj_t btree_put(size_t n_args, const mp_obj_t *args) { buf_to_dbt(args[2], &val); return MP_OBJ_NEW_SMALL_INT(__bt_put(self->db, &key, &val, 0)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(btree_put_obj, 3, 4, btree_put); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(btree_put_obj, 3, 4, btree_put); -STATIC mp_obj_t btree_get(size_t n_args, const mp_obj_t *args) { +static mp_obj_t btree_get(size_t n_args, const mp_obj_t *args) { mp_obj_btree_t *self = MP_OBJ_TO_PTR(args[0]); DBT key, val; buf_to_dbt(args[1], &key); @@ -149,9 +149,9 @@ STATIC mp_obj_t btree_get(size_t n_args, const mp_obj_t *args) { CHECK_ERROR(res); return mp_obj_new_bytes(val.data, val.size); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(btree_get_obj, 2, 3, btree_get); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(btree_get_obj, 2, 3, btree_get); -STATIC mp_obj_t btree_seq(size_t n_args, const mp_obj_t *args) { +static mp_obj_t btree_seq(size_t n_args, const mp_obj_t *args) { mp_obj_btree_t *self = MP_OBJ_TO_PTR(args[0]); int flags = MP_OBJ_SMALL_INT_VALUE(args[1]); DBT key, val; @@ -171,9 +171,9 @@ STATIC mp_obj_t btree_seq(size_t n_args, const mp_obj_t *args) { pair->items[1] = mp_obj_new_bytes(val.data, val.size); return pair_o; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(btree_seq_obj, 2, 4, btree_seq); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(btree_seq_obj, 2, 4, btree_seq); -STATIC mp_obj_t btree_init_iter(size_t n_args, const mp_obj_t *args, byte type) { +static mp_obj_t btree_init_iter(size_t n_args, const mp_obj_t *args, byte type) { mp_obj_btree_t *self = MP_OBJ_TO_PTR(args[0]); self->next_flags = type; self->start_key = mp_const_none; @@ -190,22 +190,22 @@ STATIC mp_obj_t btree_init_iter(size_t n_args, const mp_obj_t *args, byte type) return args[0]; } -STATIC mp_obj_t btree_keys(size_t n_args, const mp_obj_t *args) { +static mp_obj_t btree_keys(size_t n_args, const mp_obj_t *args) { return btree_init_iter(n_args, args, FLAG_ITER_KEYS); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(btree_keys_obj, 1, 4, btree_keys); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(btree_keys_obj, 1, 4, btree_keys); -STATIC mp_obj_t btree_values(size_t n_args, const mp_obj_t *args) { +static mp_obj_t btree_values(size_t n_args, const mp_obj_t *args) { return btree_init_iter(n_args, args, FLAG_ITER_VALUES); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(btree_values_obj, 1, 4, btree_values); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(btree_values_obj, 1, 4, btree_values); -STATIC mp_obj_t btree_items(size_t n_args, const mp_obj_t *args) { +static mp_obj_t btree_items(size_t n_args, const mp_obj_t *args) { return btree_init_iter(n_args, args, FLAG_ITER_ITEMS); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(btree_items_obj, 1, 4, btree_items); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(btree_items_obj, 1, 4, btree_items); -STATIC mp_obj_t btree_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t btree_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { (void)iter_buf; mp_obj_btree_t *self = MP_OBJ_TO_PTR(self_in); if (self->next_flags != 0) { @@ -223,7 +223,7 @@ STATIC mp_obj_t btree_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { return self_in; } -STATIC mp_obj_t btree_iternext(mp_obj_t self_in) { +static mp_obj_t btree_iternext(mp_obj_t self_in) { mp_obj_btree_t *self = MP_OBJ_TO_PTR(self_in); DBT key, val; int res; @@ -279,7 +279,7 @@ STATIC mp_obj_t btree_iternext(mp_obj_t self_in) { } } -STATIC mp_obj_t btree_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { +static mp_obj_t btree_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { mp_obj_btree_t *self = MP_OBJ_TO_PTR(self_in); if (value == MP_OBJ_NULL) { // delete @@ -312,7 +312,7 @@ STATIC mp_obj_t btree_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { } } -STATIC mp_obj_t btree_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { +static mp_obj_t btree_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { mp_obj_btree_t *self = MP_OBJ_TO_PTR(lhs_in); switch (op) { case MP_BINARY_OP_CONTAINS: { @@ -329,7 +329,7 @@ STATIC mp_obj_t btree_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs } #if !MICROPY_ENABLE_DYNRUNTIME -STATIC const mp_rom_map_elem_t btree_locals_dict_table[] = { +static const mp_rom_map_elem_t btree_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&btree_close_obj) }, { MP_ROM_QSTR(MP_QSTR_flush), MP_ROM_PTR(&btree_flush_obj) }, { MP_ROM_QSTR(MP_QSTR_get), MP_ROM_PTR(&btree_get_obj) }, @@ -340,14 +340,14 @@ STATIC const mp_rom_map_elem_t btree_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_items), MP_ROM_PTR(&btree_items_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(btree_locals_dict, btree_locals_dict_table); +static MP_DEFINE_CONST_DICT(btree_locals_dict, btree_locals_dict_table); -STATIC const mp_getiter_iternext_custom_t btree_getiter_iternext = { +static const mp_getiter_iternext_custom_t btree_getiter_iternext = { .getiter = btree_getiter, .iternext = btree_iternext, }; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( btree_type, MP_QSTR_btree, MP_TYPE_FLAG_ITER_IS_CUSTOM, @@ -360,7 +360,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); #endif -STATIC const FILEVTABLE btree_stream_fvtable = { +static const FILEVTABLE btree_stream_fvtable = { mp_stream_posix_read, mp_stream_posix_write, mp_stream_posix_lseek, @@ -368,7 +368,7 @@ STATIC const FILEVTABLE btree_stream_fvtable = { }; #if !MICROPY_ENABLE_DYNRUNTIME -STATIC mp_obj_t mod_btree_open(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t mod_btree_open(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_flags, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_cachesize, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, @@ -399,16 +399,16 @@ STATIC mp_obj_t mod_btree_open(size_t n_args, const mp_obj_t *pos_args, mp_map_t } return MP_OBJ_FROM_PTR(btree_new(db, pos_args[0])); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_btree_open_obj, 1, mod_btree_open); +static MP_DEFINE_CONST_FUN_OBJ_KW(mod_btree_open_obj, 1, mod_btree_open); -STATIC const mp_rom_map_elem_t mp_module_btree_globals_table[] = { +static const mp_rom_map_elem_t mp_module_btree_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_btree) }, { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mod_btree_open_obj) }, { MP_ROM_QSTR(MP_QSTR_INCL), MP_ROM_INT(FLAG_END_KEY_INCL) }, { MP_ROM_QSTR(MP_QSTR_DESC), MP_ROM_INT(FLAG_DESC) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_btree_globals, mp_module_btree_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_btree_globals, mp_module_btree_globals_table); const mp_obj_module_t mp_module_btree = { .base = { &mp_type_module }, diff --git a/extmod/modcryptolib.c b/extmod/modcryptolib.c index 66511b0f75ee4..bf72f4f4686c7 100644 --- a/extmod/modcryptolib.c +++ b/extmod/modcryptolib.c @@ -103,18 +103,18 @@ static inline struct ctr_params *ctr_params_from_aes(mp_obj_aes_t *o) { } #if MICROPY_SSL_AXTLS -STATIC void aes_initial_set_key_impl(AES_CTX_IMPL *ctx, const uint8_t *key, size_t keysize, const uint8_t iv[16]) { +static void aes_initial_set_key_impl(AES_CTX_IMPL *ctx, const uint8_t *key, size_t keysize, const uint8_t iv[16]) { assert(16 == keysize || 32 == keysize); AES_set_key(ctx, key, iv, (16 == keysize) ? AES_MODE_128 : AES_MODE_256); } -STATIC void aes_final_set_key_impl(AES_CTX_IMPL *ctx, bool encrypt) { +static void aes_final_set_key_impl(AES_CTX_IMPL *ctx, bool encrypt) { if (!encrypt) { AES_convert_key(ctx); } } -STATIC void aes_process_ecb_impl(AES_CTX_IMPL *ctx, const uint8_t in[16], uint8_t out[16], bool encrypt) { +static void aes_process_ecb_impl(AES_CTX_IMPL *ctx, const uint8_t in[16], uint8_t out[16], bool encrypt) { memcpy(out, in, 16); // We assume that out (vstr.buf or given output buffer) is uint32_t aligned uint32_t *p = (uint32_t *)out; @@ -132,7 +132,7 @@ STATIC void aes_process_ecb_impl(AES_CTX_IMPL *ctx, const uint8_t in[16], uint8_ } } -STATIC void aes_process_cbc_impl(AES_CTX_IMPL *ctx, const uint8_t *in, uint8_t *out, size_t in_len, bool encrypt) { +static void aes_process_cbc_impl(AES_CTX_IMPL *ctx, const uint8_t *in, uint8_t *out, size_t in_len, bool encrypt) { if (encrypt) { AES_cbc_encrypt(ctx, in, out, in_len); } else { @@ -142,7 +142,7 @@ STATIC void aes_process_cbc_impl(AES_CTX_IMPL *ctx, const uint8_t *in, uint8_t * #if MICROPY_PY_CRYPTOLIB_CTR // axTLS doesn't have CTR support out of the box. This implements the counter part using the ECB primitive. -STATIC void aes_process_ctr_impl(AES_CTX_IMPL *ctx, const uint8_t *in, uint8_t *out, size_t in_len, struct ctr_params *ctr_params) { +static void aes_process_ctr_impl(AES_CTX_IMPL *ctx, const uint8_t *in, uint8_t *out, size_t in_len, struct ctr_params *ctr_params) { size_t n = ctr_params->offset; uint8_t *const counter = ctx->iv; @@ -169,7 +169,7 @@ STATIC void aes_process_ctr_impl(AES_CTX_IMPL *ctx, const uint8_t *in, uint8_t * #endif #if MICROPY_SSL_MBEDTLS -STATIC void aes_initial_set_key_impl(AES_CTX_IMPL *ctx, const uint8_t *key, size_t keysize, const uint8_t iv[16]) { +static void aes_initial_set_key_impl(AES_CTX_IMPL *ctx, const uint8_t *key, size_t keysize, const uint8_t iv[16]) { ctx->u.init_data.keysize = keysize; memcpy(ctx->u.init_data.key, key, keysize); @@ -178,7 +178,7 @@ STATIC void aes_initial_set_key_impl(AES_CTX_IMPL *ctx, const uint8_t *key, size } } -STATIC void aes_final_set_key_impl(AES_CTX_IMPL *ctx, bool encrypt) { +static void aes_final_set_key_impl(AES_CTX_IMPL *ctx, bool encrypt) { // first, copy key aside uint8_t key[32]; uint8_t keysize = ctx->u.init_data.keysize; @@ -195,23 +195,23 @@ STATIC void aes_final_set_key_impl(AES_CTX_IMPL *ctx, bool encrypt) { } } -STATIC void aes_process_ecb_impl(AES_CTX_IMPL *ctx, const uint8_t in[16], uint8_t out[16], bool encrypt) { +static void aes_process_ecb_impl(AES_CTX_IMPL *ctx, const uint8_t in[16], uint8_t out[16], bool encrypt) { mbedtls_aes_crypt_ecb(&ctx->u.mbedtls_ctx, encrypt ? MBEDTLS_AES_ENCRYPT : MBEDTLS_AES_DECRYPT, in, out); } -STATIC void aes_process_cbc_impl(AES_CTX_IMPL *ctx, const uint8_t *in, uint8_t *out, size_t in_len, bool encrypt) { +static void aes_process_cbc_impl(AES_CTX_IMPL *ctx, const uint8_t *in, uint8_t *out, size_t in_len, bool encrypt) { mbedtls_aes_crypt_cbc(&ctx->u.mbedtls_ctx, encrypt ? MBEDTLS_AES_ENCRYPT : MBEDTLS_AES_DECRYPT, in_len, ctx->iv, in, out); } #if MICROPY_PY_CRYPTOLIB_CTR -STATIC void aes_process_ctr_impl(AES_CTX_IMPL *ctx, const uint8_t *in, uint8_t *out, size_t in_len, struct ctr_params *ctr_params) { +static void aes_process_ctr_impl(AES_CTX_IMPL *ctx, const uint8_t *in, uint8_t *out, size_t in_len, struct ctr_params *ctr_params) { mbedtls_aes_crypt_ctr(&ctx->u.mbedtls_ctx, in_len, &ctr_params->offset, ctx->iv, ctr_params->encrypted_counter, in, out); } #endif #endif -STATIC mp_obj_t cryptolib_aes_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t cryptolib_aes_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 2, 3, false); const mp_int_t block_mode = mp_obj_get_int(args[1]); @@ -260,7 +260,7 @@ STATIC mp_obj_t cryptolib_aes_make_new(const mp_obj_type_t *type, size_t n_args, return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t aes_process(size_t n_args, const mp_obj_t *args, bool encrypt) { +static mp_obj_t aes_process(size_t n_args, const mp_obj_t *args, bool encrypt) { mp_obj_aes_t *self = MP_OBJ_TO_PTR(args[0]); mp_obj_t in_buf = args[1]; @@ -332,23 +332,23 @@ STATIC mp_obj_t aes_process(size_t n_args, const mp_obj_t *args, bool encrypt) { return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC mp_obj_t cryptolib_aes_encrypt(size_t n_args, const mp_obj_t *args) { +static mp_obj_t cryptolib_aes_encrypt(size_t n_args, const mp_obj_t *args) { return aes_process(n_args, args, true); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(cryptolib_aes_encrypt_obj, 2, 3, cryptolib_aes_encrypt); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(cryptolib_aes_encrypt_obj, 2, 3, cryptolib_aes_encrypt); -STATIC mp_obj_t cryptolib_aes_decrypt(size_t n_args, const mp_obj_t *args) { +static mp_obj_t cryptolib_aes_decrypt(size_t n_args, const mp_obj_t *args) { return aes_process(n_args, args, false); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(cryptolib_aes_decrypt_obj, 2, 3, cryptolib_aes_decrypt); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(cryptolib_aes_decrypt_obj, 2, 3, cryptolib_aes_decrypt); -STATIC const mp_rom_map_elem_t cryptolib_aes_locals_dict_table[] = { +static const mp_rom_map_elem_t cryptolib_aes_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_encrypt), MP_ROM_PTR(&cryptolib_aes_encrypt_obj) }, { MP_ROM_QSTR(MP_QSTR_decrypt), MP_ROM_PTR(&cryptolib_aes_decrypt_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(cryptolib_aes_locals_dict, cryptolib_aes_locals_dict_table); +static MP_DEFINE_CONST_DICT(cryptolib_aes_locals_dict, cryptolib_aes_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( cryptolib_aes_type, MP_QSTR_aes, MP_TYPE_FLAG_NONE, @@ -356,7 +356,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &cryptolib_aes_locals_dict ); -STATIC const mp_rom_map_elem_t mp_module_cryptolib_globals_table[] = { +static const mp_rom_map_elem_t mp_module_cryptolib_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_cryptolib) }, { MP_ROM_QSTR(MP_QSTR_aes), MP_ROM_PTR(&cryptolib_aes_type) }, #if MICROPY_PY_CRYPTOLIB_CONSTS @@ -368,7 +368,7 @@ STATIC const mp_rom_map_elem_t mp_module_cryptolib_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_cryptolib_globals, mp_module_cryptolib_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_cryptolib_globals, mp_module_cryptolib_globals_table); const mp_obj_module_t mp_module_cryptolib = { .base = { &mp_type_module }, diff --git a/extmod/moddeflate.c b/extmod/moddeflate.c index 560ee3f0abce9..c0c3bb26a8b12 100644 --- a/extmod/moddeflate.c +++ b/extmod/moddeflate.c @@ -85,7 +85,7 @@ typedef struct { #endif } mp_obj_deflateio_t; -STATIC int deflateio_read_stream(void *data) { +static int deflateio_read_stream(void *data) { mp_obj_deflateio_t *self = data; const mp_stream_p_t *stream = mp_get_stream(self->stream); int err; @@ -100,7 +100,7 @@ STATIC int deflateio_read_stream(void *data) { return c; } -STATIC bool deflateio_init_read(mp_obj_deflateio_t *self) { +static bool deflateio_init_read(mp_obj_deflateio_t *self) { if (self->read) { return true; } @@ -151,7 +151,7 @@ STATIC bool deflateio_init_read(mp_obj_deflateio_t *self) { } #if MICROPY_PY_DEFLATE_COMPRESS -STATIC void deflateio_out_byte(void *data, uint8_t b) { +static void deflateio_out_byte(void *data, uint8_t b) { mp_obj_deflateio_t *self = data; const mp_stream_p_t *stream = mp_get_stream(self->stream); int err; @@ -161,7 +161,7 @@ STATIC void deflateio_out_byte(void *data, uint8_t b) { } } -STATIC bool deflateio_init_write(mp_obj_deflateio_t *self) { +static bool deflateio_init_write(mp_obj_deflateio_t *self) { if (self->write) { return true; } @@ -214,7 +214,7 @@ STATIC bool deflateio_init_write(mp_obj_deflateio_t *self) { } #endif -STATIC mp_obj_t deflateio_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args_in) { +static mp_obj_t deflateio_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args_in) { // args: stream, format=NONE, wbits=0, close=False mp_arg_check_num(n_args, n_kw, 1, 4, false); @@ -241,7 +241,7 @@ STATIC mp_obj_t deflateio_make_new(const mp_obj_type_t *type, size_t n_args, siz return MP_OBJ_FROM_PTR(self); } -STATIC mp_uint_t deflateio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t deflateio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { mp_obj_deflateio_t *self = MP_OBJ_TO_PTR(o_in); if (self->stream == MP_OBJ_NULL || !deflateio_init_read(self)) { @@ -268,7 +268,7 @@ STATIC mp_uint_t deflateio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *e } #if MICROPY_PY_DEFLATE_COMPRESS -STATIC mp_uint_t deflateio_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t deflateio_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { mp_obj_deflateio_t *self = MP_OBJ_TO_PTR(self_in); if (self->stream == MP_OBJ_NULL || !deflateio_init_write(self)) { @@ -302,7 +302,7 @@ static inline void put_be32(char *buf, uint32_t value) { } #endif -STATIC mp_uint_t deflateio_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t deflateio_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { if (request == MP_STREAM_CLOSE) { mp_obj_deflateio_t *self = MP_OBJ_TO_PTR(self_in); @@ -351,7 +351,7 @@ STATIC mp_uint_t deflateio_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t } } -STATIC const mp_stream_p_t deflateio_stream_p = { +static const mp_stream_p_t deflateio_stream_p = { .read = deflateio_read, #if MICROPY_PY_DEFLATE_COMPRESS .write = deflateio_write, @@ -360,7 +360,7 @@ STATIC const mp_stream_p_t deflateio_stream_p = { }; #if !MICROPY_ENABLE_DYNRUNTIME -STATIC const mp_rom_map_elem_t deflateio_locals_dict_table[] = { +static const mp_rom_map_elem_t deflateio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) }, { MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) }, @@ -371,9 +371,9 @@ STATIC const mp_rom_map_elem_t deflateio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&mp_identity_obj) }, { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&mp_stream___exit___obj) }, }; -STATIC MP_DEFINE_CONST_DICT(deflateio_locals_dict, deflateio_locals_dict_table); +static MP_DEFINE_CONST_DICT(deflateio_locals_dict, deflateio_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( deflateio_type, MP_QSTR_DeflateIO, MP_TYPE_FLAG_NONE, @@ -382,7 +382,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &deflateio_locals_dict ); -STATIC const mp_rom_map_elem_t mp_module_deflate_globals_table[] = { +static const mp_rom_map_elem_t mp_module_deflate_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_deflate) }, { MP_ROM_QSTR(MP_QSTR_DeflateIO), MP_ROM_PTR(&deflateio_type) }, { MP_ROM_QSTR(MP_QSTR_AUTO), MP_ROM_INT(DEFLATEIO_FORMAT_AUTO) }, @@ -390,7 +390,7 @@ STATIC const mp_rom_map_elem_t mp_module_deflate_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_ZLIB), MP_ROM_INT(DEFLATEIO_FORMAT_ZLIB) }, { MP_ROM_QSTR(MP_QSTR_GZIP), MP_ROM_INT(DEFLATEIO_FORMAT_GZIP) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_deflate_globals, mp_module_deflate_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_deflate_globals, mp_module_deflate_globals_table); const mp_obj_module_t mp_module_deflate = { .base = { &mp_type_module }, diff --git a/extmod/modframebuf.c b/extmod/modframebuf.c index 92313bd4bbe83..693e837f786a0 100644 --- a/extmod/modframebuf.c +++ b/extmod/modframebuf.c @@ -43,7 +43,7 @@ typedef struct _mp_obj_framebuf_t { } mp_obj_framebuf_t; #if !MICROPY_ENABLE_DYNRUNTIME -STATIC const mp_obj_type_t mp_type_framebuf; +static const mp_obj_type_t mp_type_framebuf; #endif typedef void (*setpixel_t)(const mp_obj_framebuf_t *, unsigned int, unsigned int, uint32_t); @@ -67,19 +67,19 @@ typedef struct _mp_framebuf_p_t { // Functions for MHLSB and MHMSB -STATIC void mono_horiz_setpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, uint32_t col) { +static void mono_horiz_setpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, uint32_t col) { size_t index = (x + y * fb->stride) >> 3; unsigned int offset = fb->format == FRAMEBUF_MHMSB ? x & 0x07 : 7 - (x & 0x07); ((uint8_t *)fb->buf)[index] = (((uint8_t *)fb->buf)[index] & ~(0x01 << offset)) | ((col != 0) << offset); } -STATIC uint32_t mono_horiz_getpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y) { +static uint32_t mono_horiz_getpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y) { size_t index = (x + y * fb->stride) >> 3; unsigned int offset = fb->format == FRAMEBUF_MHMSB ? x & 0x07 : 7 - (x & 0x07); return (((uint8_t *)fb->buf)[index] >> (offset)) & 0x01; } -STATIC void mono_horiz_fill_rect(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, unsigned int w, unsigned int h, uint32_t col) { +static void mono_horiz_fill_rect(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, unsigned int w, unsigned int h, uint32_t col) { unsigned int reverse = fb->format == FRAMEBUF_MHMSB; unsigned int advance = fb->stride >> 3; while (w--) { @@ -95,17 +95,17 @@ STATIC void mono_horiz_fill_rect(const mp_obj_framebuf_t *fb, unsigned int x, un // Functions for MVLSB format -STATIC void mvlsb_setpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, uint32_t col) { +static void mvlsb_setpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, uint32_t col) { size_t index = (y >> 3) * fb->stride + x; uint8_t offset = y & 0x07; ((uint8_t *)fb->buf)[index] = (((uint8_t *)fb->buf)[index] & ~(0x01 << offset)) | ((col != 0) << offset); } -STATIC uint32_t mvlsb_getpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y) { +static uint32_t mvlsb_getpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y) { return (((uint8_t *)fb->buf)[(y >> 3) * fb->stride + x] >> (y & 0x07)) & 0x01; } -STATIC void mvlsb_fill_rect(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, unsigned int w, unsigned int h, uint32_t col) { +static void mvlsb_fill_rect(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, unsigned int w, unsigned int h, uint32_t col) { while (h--) { uint8_t *b = &((uint8_t *)fb->buf)[(y >> 3) * fb->stride + x]; uint8_t offset = y & 0x07; @@ -119,15 +119,15 @@ STATIC void mvlsb_fill_rect(const mp_obj_framebuf_t *fb, unsigned int x, unsigne // Functions for RGB565 format -STATIC void rgb565_setpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, uint32_t col) { +static void rgb565_setpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, uint32_t col) { ((uint16_t *)fb->buf)[x + y * fb->stride] = col; } -STATIC uint32_t rgb565_getpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y) { +static uint32_t rgb565_getpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y) { return ((uint16_t *)fb->buf)[x + y * fb->stride]; } -STATIC void rgb565_fill_rect(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, unsigned int w, unsigned int h, uint32_t col) { +static void rgb565_fill_rect(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, unsigned int w, unsigned int h, uint32_t col) { uint16_t *b = &((uint16_t *)fb->buf)[x + y * fb->stride]; while (h--) { for (unsigned int ww = w; ww; --ww) { @@ -139,7 +139,7 @@ STATIC void rgb565_fill_rect(const mp_obj_framebuf_t *fb, unsigned int x, unsign // Functions for GS2_HMSB format -STATIC void gs2_hmsb_setpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, uint32_t col) { +static void gs2_hmsb_setpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, uint32_t col) { uint8_t *pixel = &((uint8_t *)fb->buf)[(x + y * fb->stride) >> 2]; uint8_t shift = (x & 0x3) << 1; uint8_t mask = 0x3 << shift; @@ -147,13 +147,13 @@ STATIC void gs2_hmsb_setpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsig *pixel = color | (*pixel & (~mask)); } -STATIC uint32_t gs2_hmsb_getpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y) { +static uint32_t gs2_hmsb_getpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y) { uint8_t pixel = ((uint8_t *)fb->buf)[(x + y * fb->stride) >> 2]; uint8_t shift = (x & 0x3) << 1; return (pixel >> shift) & 0x3; } -STATIC void gs2_hmsb_fill_rect(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, unsigned int w, unsigned int h, uint32_t col) { +static void gs2_hmsb_fill_rect(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, unsigned int w, unsigned int h, uint32_t col) { for (unsigned int xx = x; xx < x + w; xx++) { for (unsigned int yy = y; yy < y + h; yy++) { gs2_hmsb_setpixel(fb, xx, yy, col); @@ -163,7 +163,7 @@ STATIC void gs2_hmsb_fill_rect(const mp_obj_framebuf_t *fb, unsigned int x, unsi // Functions for GS4_HMSB format -STATIC void gs4_hmsb_setpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, uint32_t col) { +static void gs4_hmsb_setpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, uint32_t col) { uint8_t *pixel = &((uint8_t *)fb->buf)[(x + y * fb->stride) >> 1]; if (x % 2) { @@ -173,7 +173,7 @@ STATIC void gs4_hmsb_setpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsig } } -STATIC uint32_t gs4_hmsb_getpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y) { +static uint32_t gs4_hmsb_getpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y) { if (x % 2) { return ((uint8_t *)fb->buf)[(x + y * fb->stride) >> 1] & 0x0f; } @@ -181,7 +181,7 @@ STATIC uint32_t gs4_hmsb_getpixel(const mp_obj_framebuf_t *fb, unsigned int x, u return ((uint8_t *)fb->buf)[(x + y * fb->stride) >> 1] >> 4; } -STATIC void gs4_hmsb_fill_rect(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, unsigned int w, unsigned int h, uint32_t col) { +static void gs4_hmsb_fill_rect(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, unsigned int w, unsigned int h, uint32_t col) { col &= 0x0f; uint8_t *pixel_pair = &((uint8_t *)fb->buf)[(x + y * fb->stride) >> 1]; uint8_t col_shifted_left = col << 4; @@ -214,16 +214,16 @@ STATIC void gs4_hmsb_fill_rect(const mp_obj_framebuf_t *fb, unsigned int x, unsi // Functions for GS8 format -STATIC void gs8_setpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, uint32_t col) { +static void gs8_setpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, uint32_t col) { uint8_t *pixel = &((uint8_t *)fb->buf)[(x + y * fb->stride)]; *pixel = col & 0xff; } -STATIC uint32_t gs8_getpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y) { +static uint32_t gs8_getpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y) { return ((uint8_t *)fb->buf)[(x + y * fb->stride)]; } -STATIC void gs8_fill_rect(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, unsigned int w, unsigned int h, uint32_t col) { +static void gs8_fill_rect(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, unsigned int w, unsigned int h, uint32_t col) { uint8_t *pixel = &((uint8_t *)fb->buf)[(x + y * fb->stride)]; while (h--) { memset(pixel, col, w); @@ -231,7 +231,7 @@ STATIC void gs8_fill_rect(const mp_obj_framebuf_t *fb, unsigned int x, unsigned } } -STATIC mp_framebuf_p_t formats[] = { +static mp_framebuf_p_t formats[] = { [FRAMEBUF_MVLSB] = {mvlsb_setpixel, mvlsb_getpixel, mvlsb_fill_rect}, [FRAMEBUF_RGB565] = {rgb565_setpixel, rgb565_getpixel, rgb565_fill_rect}, [FRAMEBUF_GS2_HMSB] = {gs2_hmsb_setpixel, gs2_hmsb_getpixel, gs2_hmsb_fill_rect}, @@ -241,21 +241,21 @@ STATIC mp_framebuf_p_t formats[] = { [FRAMEBUF_MHMSB] = {mono_horiz_setpixel, mono_horiz_getpixel, mono_horiz_fill_rect}, }; -STATIC inline void setpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, uint32_t col) { +static inline void setpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y, uint32_t col) { formats[fb->format].setpixel(fb, x, y, col); } -STATIC void setpixel_checked(const mp_obj_framebuf_t *fb, mp_int_t x, mp_int_t y, mp_int_t col, mp_int_t mask) { +static void setpixel_checked(const mp_obj_framebuf_t *fb, mp_int_t x, mp_int_t y, mp_int_t col, mp_int_t mask) { if (mask && 0 <= x && x < fb->width && 0 <= y && y < fb->height) { setpixel(fb, x, y, col); } } -STATIC inline uint32_t getpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y) { +static inline uint32_t getpixel(const mp_obj_framebuf_t *fb, unsigned int x, unsigned int y) { return formats[fb->format].getpixel(fb, x, y); } -STATIC void fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) { +static void fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) { if (h < 1 || w < 1 || x + w <= 0 || y + h <= 0 || y >= fb->height || x >= fb->width) { // No operation needed. return; @@ -270,7 +270,7 @@ STATIC void fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, u formats[fb->format].fill_rect(fb, x, y, xend - x, yend - y, col); } -STATIC mp_obj_t framebuf_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args_in) { +static mp_obj_t framebuf_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args_in) { mp_arg_check_num(n_args, n_kw, 4, 5, false); mp_int_t width = mp_obj_get_int(args_in[1]); @@ -329,35 +329,35 @@ STATIC mp_obj_t framebuf_make_new(const mp_obj_type_t *type, size_t n_args, size return MP_OBJ_FROM_PTR(o); } -STATIC void framebuf_args(const mp_obj_t *args_in, mp_int_t *args_out, int n) { +static void framebuf_args(const mp_obj_t *args_in, mp_int_t *args_out, int n) { for (int i = 0; i < n; ++i) { args_out[i] = mp_obj_get_int(args_in[i + 1]); } } -STATIC mp_int_t framebuf_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { +static mp_int_t framebuf_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(self_in); return mp_get_buffer(self->buf_obj, bufinfo, flags) ? 0 : 1; } -STATIC mp_obj_t framebuf_fill(mp_obj_t self_in, mp_obj_t col_in) { +static mp_obj_t framebuf_fill(mp_obj_t self_in, mp_obj_t col_in) { mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t col = mp_obj_get_int(col_in); formats[self->format].fill_rect(self, 0, 0, self->width, self->height, col); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(framebuf_fill_obj, framebuf_fill); +static MP_DEFINE_CONST_FUN_OBJ_2(framebuf_fill_obj, framebuf_fill); -STATIC mp_obj_t framebuf_fill_rect(size_t n_args, const mp_obj_t *args_in) { +static mp_obj_t framebuf_fill_rect(size_t n_args, const mp_obj_t *args_in) { mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args_in[0]); mp_int_t args[5]; // x, y, w, h, col framebuf_args(args_in, args, 5); fill_rect(self, args[0], args[1], args[2], args[3], args[4]); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_fill_rect_obj, 6, 6, framebuf_fill_rect); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_fill_rect_obj, 6, 6, framebuf_fill_rect); -STATIC mp_obj_t framebuf_pixel(size_t n_args, const mp_obj_t *args_in) { +static mp_obj_t framebuf_pixel(size_t n_args, const mp_obj_t *args_in) { mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args_in[0]); mp_int_t x = mp_obj_get_int(args_in[1]); mp_int_t y = mp_obj_get_int(args_in[2]); @@ -372,9 +372,9 @@ STATIC mp_obj_t framebuf_pixel(size_t n_args, const mp_obj_t *args_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_pixel_obj, 3, 4, framebuf_pixel); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_pixel_obj, 3, 4, framebuf_pixel); -STATIC mp_obj_t framebuf_hline(size_t n_args, const mp_obj_t *args_in) { +static mp_obj_t framebuf_hline(size_t n_args, const mp_obj_t *args_in) { (void)n_args; mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args_in[0]); @@ -385,9 +385,9 @@ STATIC mp_obj_t framebuf_hline(size_t n_args, const mp_obj_t *args_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_hline_obj, 5, 5, framebuf_hline); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_hline_obj, 5, 5, framebuf_hline); -STATIC mp_obj_t framebuf_vline(size_t n_args, const mp_obj_t *args_in) { +static mp_obj_t framebuf_vline(size_t n_args, const mp_obj_t *args_in) { (void)n_args; mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args_in[0]); @@ -398,9 +398,9 @@ STATIC mp_obj_t framebuf_vline(size_t n_args, const mp_obj_t *args_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_vline_obj, 5, 5, framebuf_vline); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_vline_obj, 5, 5, framebuf_vline); -STATIC mp_obj_t framebuf_rect(size_t n_args, const mp_obj_t *args_in) { +static mp_obj_t framebuf_rect(size_t n_args, const mp_obj_t *args_in) { mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args_in[0]); mp_int_t args[5]; // x, y, w, h, col framebuf_args(args_in, args, 5); @@ -414,9 +414,9 @@ STATIC mp_obj_t framebuf_rect(size_t n_args, const mp_obj_t *args_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_rect_obj, 6, 7, framebuf_rect); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_rect_obj, 6, 7, framebuf_rect); -STATIC void line(const mp_obj_framebuf_t *fb, mp_int_t x1, mp_int_t y1, mp_int_t x2, mp_int_t y2, mp_int_t col) { +static void line(const mp_obj_framebuf_t *fb, mp_int_t x1, mp_int_t y1, mp_int_t x2, mp_int_t y2, mp_int_t col) { mp_int_t dx = x2 - x1; mp_int_t sx; if (dx > 0) { @@ -476,7 +476,7 @@ STATIC void line(const mp_obj_framebuf_t *fb, mp_int_t x1, mp_int_t y1, mp_int_t } } -STATIC mp_obj_t framebuf_line(size_t n_args, const mp_obj_t *args_in) { +static mp_obj_t framebuf_line(size_t n_args, const mp_obj_t *args_in) { (void)n_args; mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args_in[0]); @@ -487,7 +487,7 @@ STATIC mp_obj_t framebuf_line(size_t n_args, const mp_obj_t *args_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_line_obj, 6, 6, framebuf_line); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_line_obj, 6, 6, framebuf_line); // Q2 Q1 // Q3 Q4 @@ -498,7 +498,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_line_obj, 6, 6, framebuf_lin #define ELLIPSE_MASK_Q3 (0x04) #define ELLIPSE_MASK_Q4 (0x08) -STATIC void draw_ellipse_points(const mp_obj_framebuf_t *fb, mp_int_t cx, mp_int_t cy, mp_int_t x, mp_int_t y, mp_int_t col, mp_int_t mask) { +static void draw_ellipse_points(const mp_obj_framebuf_t *fb, mp_int_t cx, mp_int_t cy, mp_int_t x, mp_int_t y, mp_int_t col, mp_int_t mask) { if (mask & ELLIPSE_MASK_FILL) { if (mask & ELLIPSE_MASK_Q1) { fill_rect(fb, cx, cy - y, x + 1, 1, col); @@ -520,7 +520,7 @@ STATIC void draw_ellipse_points(const mp_obj_framebuf_t *fb, mp_int_t cx, mp_int } } -STATIC mp_obj_t framebuf_ellipse(size_t n_args, const mp_obj_t *args_in) { +static mp_obj_t framebuf_ellipse(size_t n_args, const mp_obj_t *args_in) { mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args_in[0]); mp_int_t args[5]; framebuf_args(args_in, args, 5); // cx, cy, xradius, yradius, col @@ -575,17 +575,17 @@ STATIC mp_obj_t framebuf_ellipse(size_t n_args, const mp_obj_t *args_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_ellipse_obj, 6, 8, framebuf_ellipse); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_ellipse_obj, 6, 8, framebuf_ellipse); #if MICROPY_PY_ARRAY && !MICROPY_ENABLE_DYNRUNTIME // TODO: poly needs mp_binary_get_size & mp_binary_get_val_array which aren't // available in dynruntime.h yet. -STATIC mp_int_t poly_int(mp_buffer_info_t *bufinfo, size_t index) { +static mp_int_t poly_int(mp_buffer_info_t *bufinfo, size_t index) { return mp_obj_get_int(mp_binary_get_val_array(bufinfo->typecode, bufinfo->buf, index)); } -STATIC mp_obj_t framebuf_poly(size_t n_args, const mp_obj_t *args_in) { +static mp_obj_t framebuf_poly(size_t n_args, const mp_obj_t *args_in) { mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args_in[0]); mp_int_t x = mp_obj_get_int(args_in[1]); @@ -695,10 +695,10 @@ STATIC mp_obj_t framebuf_poly(size_t n_args, const mp_obj_t *args_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_poly_obj, 5, 6, framebuf_poly); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_poly_obj, 5, 6, framebuf_poly); #endif // MICROPY_PY_ARRAY && !MICROPY_ENABLE_DYNRUNTIME -STATIC mp_obj_t framebuf_blit(size_t n_args, const mp_obj_t *args_in) { +static mp_obj_t framebuf_blit(size_t n_args, const mp_obj_t *args_in) { mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args_in[0]); mp_obj_t source_in = mp_obj_cast_to_native_base(args_in[1], MP_OBJ_FROM_PTR(&mp_type_framebuf)); if (source_in == MP_OBJ_NULL) { @@ -751,9 +751,9 @@ STATIC mp_obj_t framebuf_blit(size_t n_args, const mp_obj_t *args_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_blit_obj, 4, 6, framebuf_blit); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_blit_obj, 4, 6, framebuf_blit); -STATIC mp_obj_t framebuf_scroll(mp_obj_t self_in, mp_obj_t xstep_in, mp_obj_t ystep_in) { +static mp_obj_t framebuf_scroll(mp_obj_t self_in, mp_obj_t xstep_in, mp_obj_t ystep_in) { mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t xstep = mp_obj_get_int(xstep_in); mp_int_t ystep = mp_obj_get_int(ystep_in); @@ -795,9 +795,9 @@ STATIC mp_obj_t framebuf_scroll(mp_obj_t self_in, mp_obj_t xstep_in, mp_obj_t ys } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(framebuf_scroll_obj, framebuf_scroll); +static MP_DEFINE_CONST_FUN_OBJ_3(framebuf_scroll_obj, framebuf_scroll); -STATIC mp_obj_t framebuf_text(size_t n_args, const mp_obj_t *args_in) { +static mp_obj_t framebuf_text(size_t n_args, const mp_obj_t *args_in) { // extract arguments mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args_in[0]); const char *str = mp_obj_str_get_str(args_in[1]); @@ -833,10 +833,10 @@ STATIC mp_obj_t framebuf_text(size_t n_args, const mp_obj_t *args_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_text_obj, 4, 5, framebuf_text); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_text_obj, 4, 5, framebuf_text); #if !MICROPY_ENABLE_DYNRUNTIME -STATIC const mp_rom_map_elem_t framebuf_locals_dict_table[] = { +static const mp_rom_map_elem_t framebuf_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_fill), MP_ROM_PTR(&framebuf_fill_obj) }, { MP_ROM_QSTR(MP_QSTR_fill_rect), MP_ROM_PTR(&framebuf_fill_rect_obj) }, { MP_ROM_QSTR(MP_QSTR_pixel), MP_ROM_PTR(&framebuf_pixel_obj) }, @@ -852,9 +852,9 @@ STATIC const mp_rom_map_elem_t framebuf_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_scroll), MP_ROM_PTR(&framebuf_scroll_obj) }, { MP_ROM_QSTR(MP_QSTR_text), MP_ROM_PTR(&framebuf_text_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(framebuf_locals_dict, framebuf_locals_dict_table); +static MP_DEFINE_CONST_DICT(framebuf_locals_dict, framebuf_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_framebuf, MP_QSTR_FrameBuffer, MP_TYPE_FLAG_NONE, @@ -867,13 +867,13 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( #if !MICROPY_ENABLE_DYNRUNTIME // This factory function is provided for backwards compatibility with the old // FrameBuffer1 class which did not support a format argument. -STATIC mp_obj_t legacy_framebuffer1(size_t n_args, const mp_obj_t *args_in) { +static mp_obj_t legacy_framebuffer1(size_t n_args, const mp_obj_t *args_in) { mp_obj_t args[] = {args_in[0], args_in[1], args_in[2], MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MVLSB), n_args >= 4 ? args_in[3] : args_in[1] }; return framebuf_make_new(&mp_type_framebuf, 5, 0, args); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(legacy_framebuffer1_obj, 3, 4, legacy_framebuffer1); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(legacy_framebuffer1_obj, 3, 4, legacy_framebuffer1); -STATIC const mp_rom_map_elem_t framebuf_module_globals_table[] = { +static const mp_rom_map_elem_t framebuf_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_framebuf) }, { MP_ROM_QSTR(MP_QSTR_FrameBuffer), MP_ROM_PTR(&mp_type_framebuf) }, { MP_ROM_QSTR(MP_QSTR_FrameBuffer1), MP_ROM_PTR(&legacy_framebuffer1_obj) }, @@ -887,7 +887,7 @@ STATIC const mp_rom_map_elem_t framebuf_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_MONO_HMSB), MP_ROM_INT(FRAMEBUF_MHMSB) }, }; -STATIC MP_DEFINE_CONST_DICT(framebuf_module_globals, framebuf_module_globals_table); +static MP_DEFINE_CONST_DICT(framebuf_module_globals, framebuf_module_globals_table); const mp_obj_module_t mp_module_framebuf = { .base = { &mp_type_module }, diff --git a/extmod/modhashlib.c b/extmod/modhashlib.c index dbebd78667646..4754e44463019 100644 --- a/extmod/modhashlib.c +++ b/extmod/modhashlib.c @@ -71,7 +71,7 @@ static void hashlib_ensure_not_final(mp_obj_hash_t *self) { } #if MICROPY_PY_HASHLIB_SHA256 -STATIC mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg); +static mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg); #if MICROPY_SSL_MBEDTLS @@ -81,7 +81,7 @@ STATIC mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg); #define mbedtls_sha256_finish_ret mbedtls_sha256_finish #endif -STATIC mp_obj_t hashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t hashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, state, char, sizeof(mbedtls_sha256_context), type); o->final = false; @@ -93,7 +93,7 @@ STATIC mp_obj_t hashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); hashlib_ensure_not_final(self); mp_buffer_info_t bufinfo; @@ -102,7 +102,7 @@ STATIC mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) { return mp_const_none; } -STATIC mp_obj_t hashlib_sha256_digest(mp_obj_t self_in) { +static mp_obj_t hashlib_sha256_digest(mp_obj_t self_in) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); hashlib_ensure_not_final(self); self->final = true; @@ -116,7 +116,7 @@ STATIC mp_obj_t hashlib_sha256_digest(mp_obj_t self_in) { #include "lib/crypto-algorithms/sha256.c" -STATIC mp_obj_t hashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t hashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, state, char, sizeof(CRYAL_SHA256_CTX), type); o->final = false; @@ -127,7 +127,7 @@ STATIC mp_obj_t hashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); hashlib_ensure_not_final(self); mp_buffer_info_t bufinfo; @@ -136,7 +136,7 @@ STATIC mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) { return mp_const_none; } -STATIC mp_obj_t hashlib_sha256_digest(mp_obj_t self_in) { +static mp_obj_t hashlib_sha256_digest(mp_obj_t self_in) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); hashlib_ensure_not_final(self); self->final = true; @@ -147,17 +147,17 @@ STATIC mp_obj_t hashlib_sha256_digest(mp_obj_t self_in) { } #endif -STATIC MP_DEFINE_CONST_FUN_OBJ_2(hashlib_sha256_update_obj, hashlib_sha256_update); -STATIC MP_DEFINE_CONST_FUN_OBJ_1(hashlib_sha256_digest_obj, hashlib_sha256_digest); +static MP_DEFINE_CONST_FUN_OBJ_2(hashlib_sha256_update_obj, hashlib_sha256_update); +static MP_DEFINE_CONST_FUN_OBJ_1(hashlib_sha256_digest_obj, hashlib_sha256_digest); -STATIC const mp_rom_map_elem_t hashlib_sha256_locals_dict_table[] = { +static const mp_rom_map_elem_t hashlib_sha256_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&hashlib_sha256_update_obj) }, { MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&hashlib_sha256_digest_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(hashlib_sha256_locals_dict, hashlib_sha256_locals_dict_table); +static MP_DEFINE_CONST_DICT(hashlib_sha256_locals_dict, hashlib_sha256_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( hashlib_sha256_type, MP_QSTR_sha256, MP_TYPE_FLAG_NONE, @@ -167,10 +167,10 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( #endif #if MICROPY_PY_HASHLIB_SHA1 -STATIC mp_obj_t hashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg); +static mp_obj_t hashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg); #if MICROPY_SSL_AXTLS -STATIC mp_obj_t hashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t hashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, state, char, sizeof(SHA1_CTX), type); o->final = false; @@ -181,7 +181,7 @@ STATIC mp_obj_t hashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args, return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t hashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t hashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); hashlib_ensure_not_final(self); mp_buffer_info_t bufinfo; @@ -190,7 +190,7 @@ STATIC mp_obj_t hashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) { return mp_const_none; } -STATIC mp_obj_t hashlib_sha1_digest(mp_obj_t self_in) { +static mp_obj_t hashlib_sha1_digest(mp_obj_t self_in) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); hashlib_ensure_not_final(self); self->final = true; @@ -209,7 +209,7 @@ STATIC mp_obj_t hashlib_sha1_digest(mp_obj_t self_in) { #define mbedtls_sha1_finish_ret mbedtls_sha1_finish #endif -STATIC mp_obj_t hashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t hashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, state, char, sizeof(mbedtls_sha1_context), type); o->final = false; @@ -221,7 +221,7 @@ STATIC mp_obj_t hashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args, return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t hashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t hashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); hashlib_ensure_not_final(self); mp_buffer_info_t bufinfo; @@ -230,7 +230,7 @@ STATIC mp_obj_t hashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) { return mp_const_none; } -STATIC mp_obj_t hashlib_sha1_digest(mp_obj_t self_in) { +static mp_obj_t hashlib_sha1_digest(mp_obj_t self_in) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); hashlib_ensure_not_final(self); self->final = true; @@ -242,16 +242,16 @@ STATIC mp_obj_t hashlib_sha1_digest(mp_obj_t self_in) { } #endif -STATIC MP_DEFINE_CONST_FUN_OBJ_2(hashlib_sha1_update_obj, hashlib_sha1_update); -STATIC MP_DEFINE_CONST_FUN_OBJ_1(hashlib_sha1_digest_obj, hashlib_sha1_digest); +static MP_DEFINE_CONST_FUN_OBJ_2(hashlib_sha1_update_obj, hashlib_sha1_update); +static MP_DEFINE_CONST_FUN_OBJ_1(hashlib_sha1_digest_obj, hashlib_sha1_digest); -STATIC const mp_rom_map_elem_t hashlib_sha1_locals_dict_table[] = { +static const mp_rom_map_elem_t hashlib_sha1_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&hashlib_sha1_update_obj) }, { MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&hashlib_sha1_digest_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(hashlib_sha1_locals_dict, hashlib_sha1_locals_dict_table); +static MP_DEFINE_CONST_DICT(hashlib_sha1_locals_dict, hashlib_sha1_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( hashlib_sha1_type, MP_QSTR_sha1, MP_TYPE_FLAG_NONE, @@ -261,10 +261,10 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( #endif #if MICROPY_PY_HASHLIB_MD5 -STATIC mp_obj_t hashlib_md5_update(mp_obj_t self_in, mp_obj_t arg); +static mp_obj_t hashlib_md5_update(mp_obj_t self_in, mp_obj_t arg); #if MICROPY_SSL_AXTLS -STATIC mp_obj_t hashlib_md5_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t hashlib_md5_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, state, char, sizeof(MD5_CTX), type); o->final = false; @@ -275,7 +275,7 @@ STATIC mp_obj_t hashlib_md5_make_new(const mp_obj_type_t *type, size_t n_args, s return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t hashlib_md5_update(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t hashlib_md5_update(mp_obj_t self_in, mp_obj_t arg) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); hashlib_ensure_not_final(self); mp_buffer_info_t bufinfo; @@ -284,7 +284,7 @@ STATIC mp_obj_t hashlib_md5_update(mp_obj_t self_in, mp_obj_t arg) { return mp_const_none; } -STATIC mp_obj_t hashlib_md5_digest(mp_obj_t self_in) { +static mp_obj_t hashlib_md5_digest(mp_obj_t self_in) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); hashlib_ensure_not_final(self); self->final = true; @@ -303,7 +303,7 @@ STATIC mp_obj_t hashlib_md5_digest(mp_obj_t self_in) { #define mbedtls_md5_finish_ret mbedtls_md5_finish #endif -STATIC mp_obj_t hashlib_md5_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t hashlib_md5_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, state, char, sizeof(mbedtls_md5_context), type); o->final = false; @@ -315,7 +315,7 @@ STATIC mp_obj_t hashlib_md5_make_new(const mp_obj_type_t *type, size_t n_args, s return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t hashlib_md5_update(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t hashlib_md5_update(mp_obj_t self_in, mp_obj_t arg) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); hashlib_ensure_not_final(self); mp_buffer_info_t bufinfo; @@ -324,7 +324,7 @@ STATIC mp_obj_t hashlib_md5_update(mp_obj_t self_in, mp_obj_t arg) { return mp_const_none; } -STATIC mp_obj_t hashlib_md5_digest(mp_obj_t self_in) { +static mp_obj_t hashlib_md5_digest(mp_obj_t self_in) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); hashlib_ensure_not_final(self); self->final = true; @@ -336,16 +336,16 @@ STATIC mp_obj_t hashlib_md5_digest(mp_obj_t self_in) { } #endif // MICROPY_SSL_MBEDTLS -STATIC MP_DEFINE_CONST_FUN_OBJ_2(hashlib_md5_update_obj, hashlib_md5_update); -STATIC MP_DEFINE_CONST_FUN_OBJ_1(hashlib_md5_digest_obj, hashlib_md5_digest); +static MP_DEFINE_CONST_FUN_OBJ_2(hashlib_md5_update_obj, hashlib_md5_update); +static MP_DEFINE_CONST_FUN_OBJ_1(hashlib_md5_digest_obj, hashlib_md5_digest); -STATIC const mp_rom_map_elem_t hashlib_md5_locals_dict_table[] = { +static const mp_rom_map_elem_t hashlib_md5_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&hashlib_md5_update_obj) }, { MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&hashlib_md5_digest_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(hashlib_md5_locals_dict, hashlib_md5_locals_dict_table); +static MP_DEFINE_CONST_DICT(hashlib_md5_locals_dict, hashlib_md5_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( hashlib_md5_type, MP_QSTR_md5, MP_TYPE_FLAG_NONE, @@ -354,7 +354,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); #endif // MICROPY_PY_HASHLIB_MD5 -STATIC const mp_rom_map_elem_t mp_module_hashlib_globals_table[] = { +static const mp_rom_map_elem_t mp_module_hashlib_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_hashlib) }, #if MICROPY_PY_HASHLIB_SHA256 { MP_ROM_QSTR(MP_QSTR_sha256), MP_ROM_PTR(&hashlib_sha256_type) }, @@ -367,7 +367,7 @@ STATIC const mp_rom_map_elem_t mp_module_hashlib_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_hashlib_globals, mp_module_hashlib_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_hashlib_globals, mp_module_hashlib_globals_table); const mp_obj_module_t mp_module_hashlib = { .base = { &mp_type_module }, diff --git a/extmod/modheapq.c b/extmod/modheapq.c index db1e35bac2830..bb8c7d2bf175e 100644 --- a/extmod/modheapq.c +++ b/extmod/modheapq.c @@ -31,14 +31,14 @@ // the algorithm here is modelled on CPython's heapq.py -STATIC mp_obj_list_t *heapq_get_heap(mp_obj_t heap_in) { +static mp_obj_list_t *heapq_get_heap(mp_obj_t heap_in) { if (!mp_obj_is_type(heap_in, &mp_type_list)) { mp_raise_TypeError(MP_ERROR_TEXT("heap must be a list")); } return MP_OBJ_TO_PTR(heap_in); } -STATIC void heapq_heap_siftdown(mp_obj_list_t *heap, mp_uint_t start_pos, mp_uint_t pos) { +static void heapq_heap_siftdown(mp_obj_list_t *heap, mp_uint_t start_pos, mp_uint_t pos) { mp_obj_t item = heap->items[pos]; while (pos > start_pos) { mp_uint_t parent_pos = (pos - 1) >> 1; @@ -53,7 +53,7 @@ STATIC void heapq_heap_siftdown(mp_obj_list_t *heap, mp_uint_t start_pos, mp_uin heap->items[pos] = item; } -STATIC void heapq_heap_siftup(mp_obj_list_t *heap, mp_uint_t pos) { +static void heapq_heap_siftup(mp_obj_list_t *heap, mp_uint_t pos) { mp_uint_t start_pos = pos; mp_uint_t end_pos = heap->len; mp_obj_t item = heap->items[pos]; @@ -70,15 +70,15 @@ STATIC void heapq_heap_siftup(mp_obj_list_t *heap, mp_uint_t pos) { heapq_heap_siftdown(heap, start_pos, pos); } -STATIC mp_obj_t mod_heapq_heappush(mp_obj_t heap_in, mp_obj_t item) { +static mp_obj_t mod_heapq_heappush(mp_obj_t heap_in, mp_obj_t item) { mp_obj_list_t *heap = heapq_get_heap(heap_in); mp_obj_list_append(heap_in, item); heapq_heap_siftdown(heap, 0, heap->len - 1); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_heapq_heappush_obj, mod_heapq_heappush); +static MP_DEFINE_CONST_FUN_OBJ_2(mod_heapq_heappush_obj, mod_heapq_heappush); -STATIC mp_obj_t mod_heapq_heappop(mp_obj_t heap_in) { +static mp_obj_t mod_heapq_heappop(mp_obj_t heap_in) { mp_obj_list_t *heap = heapq_get_heap(heap_in); if (heap->len == 0) { mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("empty heap")); @@ -92,26 +92,26 @@ STATIC mp_obj_t mod_heapq_heappop(mp_obj_t heap_in) { } return item; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_heapq_heappop_obj, mod_heapq_heappop); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_heapq_heappop_obj, mod_heapq_heappop); -STATIC mp_obj_t mod_heapq_heapify(mp_obj_t heap_in) { +static mp_obj_t mod_heapq_heapify(mp_obj_t heap_in) { mp_obj_list_t *heap = heapq_get_heap(heap_in); for (mp_uint_t i = heap->len / 2; i > 0;) { heapq_heap_siftup(heap, --i); } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_heapq_heapify_obj, mod_heapq_heapify); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_heapq_heapify_obj, mod_heapq_heapify); #if !MICROPY_ENABLE_DYNRUNTIME -STATIC const mp_rom_map_elem_t mp_module_heapq_globals_table[] = { +static const mp_rom_map_elem_t mp_module_heapq_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_heapq) }, { MP_ROM_QSTR(MP_QSTR_heappush), MP_ROM_PTR(&mod_heapq_heappush_obj) }, { MP_ROM_QSTR(MP_QSTR_heappop), MP_ROM_PTR(&mod_heapq_heappop_obj) }, { MP_ROM_QSTR(MP_QSTR_heapify), MP_ROM_PTR(&mod_heapq_heapify_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_heapq_globals, mp_module_heapq_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_heapq_globals, mp_module_heapq_globals_table); const mp_obj_module_t mp_module_heapq = { .base = { &mp_type_module }, diff --git a/extmod/modjson.c b/extmod/modjson.c index 1772b7299886e..e655a02bc00ef 100644 --- a/extmod/modjson.c +++ b/extmod/modjson.c @@ -41,7 +41,7 @@ enum { DUMP_MODE_TO_STREAM = 2, }; -STATIC mp_obj_t mod_json_dump_helper(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args, unsigned int mode) { +static mp_obj_t mod_json_dump_helper(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args, unsigned int mode) { enum { ARG_separators }; static const mp_arg_t allowed_args[] = { { MP_QSTR_separators, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, @@ -78,34 +78,34 @@ STATIC mp_obj_t mod_json_dump_helper(size_t n_args, const mp_obj_t *pos_args, mp } } -STATIC mp_obj_t mod_json_dump(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t mod_json_dump(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { return mod_json_dump_helper(n_args, pos_args, kw_args, DUMP_MODE_TO_STREAM); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_json_dump_obj, 2, mod_json_dump); +static MP_DEFINE_CONST_FUN_OBJ_KW(mod_json_dump_obj, 2, mod_json_dump); -STATIC mp_obj_t mod_json_dumps(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t mod_json_dumps(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { return mod_json_dump_helper(n_args, pos_args, kw_args, DUMP_MODE_TO_STRING); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_json_dumps_obj, 1, mod_json_dumps); +static MP_DEFINE_CONST_FUN_OBJ_KW(mod_json_dumps_obj, 1, mod_json_dumps); #else -STATIC mp_obj_t mod_json_dump(mp_obj_t obj, mp_obj_t stream) { +static mp_obj_t mod_json_dump(mp_obj_t obj, mp_obj_t stream) { mp_get_stream_raise(stream, MP_STREAM_OP_WRITE); mp_print_t print = {MP_OBJ_TO_PTR(stream), mp_stream_write_adaptor}; mp_obj_print_helper(&print, obj, PRINT_JSON); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_json_dump_obj, mod_json_dump); +static MP_DEFINE_CONST_FUN_OBJ_2(mod_json_dump_obj, mod_json_dump); -STATIC mp_obj_t mod_json_dumps(mp_obj_t obj) { +static mp_obj_t mod_json_dumps(mp_obj_t obj) { vstr_t vstr; mp_print_t print; vstr_init_print(&vstr, 8, &print); mp_obj_print_helper(&print, obj, PRINT_JSON); return mp_obj_new_str_from_utf8_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_json_dumps_obj, mod_json_dumps); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_json_dumps_obj, mod_json_dumps); #endif @@ -134,7 +134,7 @@ typedef struct _json_stream_t { #define S_CUR(s) ((s).cur) #define S_NEXT(s) (json_stream_next(&(s))) -STATIC byte json_stream_next(json_stream_t *s) { +static byte json_stream_next(json_stream_t *s) { mp_uint_t ret = s->read(s->stream_obj, &s->cur, 1, &s->errcode); if (s->errcode != 0) { mp_raise_OSError(s->errcode); @@ -145,7 +145,7 @@ STATIC byte json_stream_next(json_stream_t *s) { return s->cur; } -STATIC mp_obj_t mod_json_load(mp_obj_t stream_obj) { +static mp_obj_t mod_json_load(mp_obj_t stream_obj) { const mp_stream_p_t *stream_p = mp_get_stream_raise(stream_obj, MP_STREAM_OP_READ); json_stream_t s = {stream_obj, stream_p->read, 0, 0}; vstr_t vstr; @@ -355,18 +355,18 @@ STATIC mp_obj_t mod_json_load(mp_obj_t stream_obj) { fail: mp_raise_ValueError(MP_ERROR_TEXT("syntax error in JSON")); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_json_load_obj, mod_json_load); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_json_load_obj, mod_json_load); -STATIC mp_obj_t mod_json_loads(mp_obj_t obj) { +static mp_obj_t mod_json_loads(mp_obj_t obj) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(obj, &bufinfo, MP_BUFFER_READ); vstr_t vstr = {bufinfo.len, bufinfo.len, (char *)bufinfo.buf, true}; mp_obj_stringio_t sio = {{&mp_type_stringio}, &vstr, 0, MP_OBJ_NULL}; return mod_json_load(MP_OBJ_FROM_PTR(&sio)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_json_loads_obj, mod_json_loads); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_json_loads_obj, mod_json_loads); -STATIC const mp_rom_map_elem_t mp_module_json_globals_table[] = { +static const mp_rom_map_elem_t mp_module_json_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_json) }, { MP_ROM_QSTR(MP_QSTR_dump), MP_ROM_PTR(&mod_json_dump_obj) }, { MP_ROM_QSTR(MP_QSTR_dumps), MP_ROM_PTR(&mod_json_dumps_obj) }, @@ -374,7 +374,7 @@ STATIC const mp_rom_map_elem_t mp_module_json_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_loads), MP_ROM_PTR(&mod_json_loads_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_json_globals, mp_module_json_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_json_globals, mp_module_json_globals_table); const mp_obj_module_t mp_module_json = { .base = { &mp_type_module }, diff --git a/extmod/modlwip.c b/extmod/modlwip.c index f1242b046186f..607143bb7e4c6 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -99,17 +99,17 @@ typedef struct _lwip_slip_obj_t { } lwip_slip_obj_t; // Slip object is unique for now. Possibly can fix this later. FIXME -STATIC lwip_slip_obj_t lwip_slip_obj; +static lwip_slip_obj_t lwip_slip_obj; // Declare these early. void mod_lwip_register_poll(void (*poll)(void *arg), void *poll_arg); void mod_lwip_deregister_poll(void (*poll)(void *arg), void *poll_arg); -STATIC void slip_lwip_poll(void *netif) { +static void slip_lwip_poll(void *netif) { slipif_poll((struct netif *)netif); } -STATIC const mp_obj_type_t lwip_slip_type; +static const mp_obj_type_t lwip_slip_type; // lwIP SLIP callback functions sio_fd_t sio_open(u8_t dvnum) { @@ -138,7 +138,7 @@ u32_t sio_tryread(sio_fd_t fd, u8_t *data, u32_t len) { } // constructor lwip.slip(device=integer, iplocal=string, ipremote=string) -STATIC mp_obj_t lwip_slip_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t lwip_slip_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 3, 3, false); lwip_slip_obj.base.type = &lwip_slip_type; @@ -164,20 +164,20 @@ STATIC mp_obj_t lwip_slip_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, return (mp_obj_t)&lwip_slip_obj; } -STATIC mp_obj_t lwip_slip_status(mp_obj_t self_in) { +static mp_obj_t lwip_slip_status(mp_obj_t self_in) { // Null function for now. return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(lwip_slip_status_obj, lwip_slip_status); +static MP_DEFINE_CONST_FUN_OBJ_1(lwip_slip_status_obj, lwip_slip_status); -STATIC const mp_rom_map_elem_t lwip_slip_locals_dict_table[] = { +static const mp_rom_map_elem_t lwip_slip_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_status), MP_ROM_PTR(&lwip_slip_status_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(lwip_slip_locals_dict, lwip_slip_locals_dict_table); +static MP_DEFINE_CONST_DICT(lwip_slip_locals_dict, lwip_slip_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( lwip_slip_type, MP_QSTR_slip, MP_TYPE_FLAG_NONE, @@ -321,7 +321,7 @@ static inline void poll_sockets(void) { mp_event_wait_ms(1); } -STATIC struct tcp_pcb *volatile *lwip_socket_incoming_array(lwip_socket_obj_t *socket) { +static struct tcp_pcb *volatile *lwip_socket_incoming_array(lwip_socket_obj_t *socket) { if (socket->incoming.connection.alloc == 0) { return &socket->incoming.connection.tcp.item; } else { @@ -329,7 +329,7 @@ STATIC struct tcp_pcb *volatile *lwip_socket_incoming_array(lwip_socket_obj_t *s } } -STATIC void lwip_socket_free_incoming(lwip_socket_obj_t *socket) { +static void lwip_socket_free_incoming(lwip_socket_obj_t *socket) { bool socket_is_listener = socket->type == MOD_NETWORK_SOCK_STREAM && socket->pcb.tcp->state == LISTEN; @@ -394,9 +394,9 @@ static inline void exec_user_callback(lwip_socket_obj_t *socket) { #if MICROPY_PY_LWIP_SOCK_RAW // Callback for incoming raw packets. #if LWIP_VERSION_MAJOR < 2 -STATIC u8_t _lwip_raw_incoming(void *arg, struct raw_pcb *pcb, struct pbuf *p, ip_addr_t *addr) +static u8_t _lwip_raw_incoming(void *arg, struct raw_pcb *pcb, struct pbuf *p, ip_addr_t *addr) #else -STATIC u8_t _lwip_raw_incoming(void *arg, struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *addr) +static u8_t _lwip_raw_incoming(void *arg, struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *addr) #endif { lwip_socket_obj_t *socket = (lwip_socket_obj_t *)arg; @@ -414,9 +414,9 @@ STATIC u8_t _lwip_raw_incoming(void *arg, struct raw_pcb *pcb, struct pbuf *p, c // Callback for incoming UDP packets. We simply stash the packet and the source address, // in case we need it for recvfrom. #if LWIP_VERSION_MAJOR < 2 -STATIC void _lwip_udp_incoming(void *arg, struct udp_pcb *upcb, struct pbuf *p, ip_addr_t *addr, u16_t port) +static void _lwip_udp_incoming(void *arg, struct udp_pcb *upcb, struct pbuf *p, ip_addr_t *addr, u16_t port) #else -STATIC void _lwip_udp_incoming(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port) +static void _lwip_udp_incoming(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port) #endif { lwip_socket_obj_t *socket = (lwip_socket_obj_t *)arg; @@ -432,7 +432,7 @@ STATIC void _lwip_udp_incoming(void *arg, struct udp_pcb *upcb, struct pbuf *p, } // Callback for general tcp errors. -STATIC void _lwip_tcp_error(void *arg, err_t err) { +static void _lwip_tcp_error(void *arg, err_t err) { lwip_socket_obj_t *socket = (lwip_socket_obj_t *)arg; // Free any incoming buffers or connections that are stored @@ -444,7 +444,7 @@ STATIC void _lwip_tcp_error(void *arg, err_t err) { } // Callback for tcp connection requests. Error code err is unused. (See tcp.h) -STATIC err_t _lwip_tcp_connected(void *arg, struct tcp_pcb *tpcb, err_t err) { +static err_t _lwip_tcp_connected(void *arg, struct tcp_pcb *tpcb, err_t err) { lwip_socket_obj_t *socket = (lwip_socket_obj_t *)arg; socket->state = STATE_CONNECTED; @@ -453,7 +453,7 @@ STATIC err_t _lwip_tcp_connected(void *arg, struct tcp_pcb *tpcb, err_t err) { // Handle errors (eg connection aborted) on TCP PCBs that have been put on the // accept queue but are not yet actually accepted. -STATIC void _lwip_tcp_err_unaccepted(void *arg, err_t err) { +static void _lwip_tcp_err_unaccepted(void *arg, err_t err) { struct tcp_pcb *pcb = (struct tcp_pcb *)arg; // The ->connected entry is repurposed to store the parent socket; this is safe @@ -493,12 +493,12 @@ STATIC void _lwip_tcp_err_unaccepted(void *arg, err_t err) { // so set this handler which requests lwIP to keep pbuf's and deliver // them later. We cannot cache pbufs in child socket on Python side, // until it is created in accept(). -STATIC err_t _lwip_tcp_recv_unaccepted(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) { +static err_t _lwip_tcp_recv_unaccepted(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) { return ERR_BUF; } // Callback for incoming tcp connections. -STATIC err_t _lwip_tcp_accept(void *arg, struct tcp_pcb *newpcb, err_t err) { +static err_t _lwip_tcp_accept(void *arg, struct tcp_pcb *newpcb, err_t err) { // err can be ERR_MEM to notify us that there was no memory for an incoming connection if (err != ERR_OK) { return ERR_OK; @@ -535,7 +535,7 @@ STATIC err_t _lwip_tcp_accept(void *arg, struct tcp_pcb *newpcb, err_t err) { } // Callback for inbound tcp packets. -STATIC err_t _lwip_tcp_recv(void *arg, struct tcp_pcb *tcpb, struct pbuf *p, err_t err) { +static err_t _lwip_tcp_recv(void *arg, struct tcp_pcb *tcpb, struct pbuf *p, err_t err) { lwip_socket_obj_t *socket = (lwip_socket_obj_t *)arg; if (p == NULL) { @@ -566,7 +566,7 @@ STATIC err_t _lwip_tcp_recv(void *arg, struct tcp_pcb *tcpb, struct pbuf *p, err // these to do the work. // Helper function for send/sendto to handle raw/UDP packets. -STATIC mp_uint_t lwip_raw_udp_send(lwip_socket_obj_t *socket, const byte *buf, mp_uint_t len, ip_addr_t *ip, mp_uint_t port, int *_errno) { +static mp_uint_t lwip_raw_udp_send(lwip_socket_obj_t *socket, const byte *buf, mp_uint_t len, ip_addr_t *ip, mp_uint_t port, int *_errno) { if (len > 0xffff) { // Any packet that big is probably going to fail the pbuf_alloc anyway, but may as well try len = 0xffff; @@ -621,7 +621,7 @@ STATIC mp_uint_t lwip_raw_udp_send(lwip_socket_obj_t *socket, const byte *buf, m } // Helper function for recv/recvfrom to handle raw/UDP packets -STATIC mp_uint_t lwip_raw_udp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno) { +static mp_uint_t lwip_raw_udp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno) { if (socket->incoming.pbuf == NULL) { if (socket->timeout == 0) { @@ -678,7 +678,7 @@ STATIC mp_uint_t lwip_raw_udp_receive(lwip_socket_obj_t *socket, byte *buf, mp_u // Helper function for send/sendto to handle TCP packets -STATIC mp_uint_t lwip_tcp_send(lwip_socket_obj_t *socket, const byte *buf, mp_uint_t len, int *_errno) { +static mp_uint_t lwip_tcp_send(lwip_socket_obj_t *socket, const byte *buf, mp_uint_t len, int *_errno) { // Check for any pending errors STREAM_ERROR_CHECK(socket); @@ -753,7 +753,7 @@ STATIC mp_uint_t lwip_tcp_send(lwip_socket_obj_t *socket, const byte *buf, mp_ui } // Helper function for recv/recvfrom to handle TCP packets -STATIC mp_uint_t lwip_tcp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_t len, int *_errno) { +static mp_uint_t lwip_tcp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_t len, int *_errno) { // Check for any pending errors STREAM_ERROR_CHECK(socket); @@ -827,16 +827,16 @@ STATIC mp_uint_t lwip_tcp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_ /*******************************************************************************/ // The socket functions provided by lwip.socket. -STATIC const mp_obj_type_t lwip_socket_type; +static const mp_obj_type_t lwip_socket_type; -STATIC void lwip_socket_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void lwip_socket_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { lwip_socket_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", self->state, self->timeout, self->incoming.pbuf, self->recv_offset); } // FIXME: Only supports two arguments at present -STATIC mp_obj_t lwip_socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t lwip_socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 4, false); lwip_socket_obj_t *socket = mp_obj_malloc_with_finaliser(lwip_socket_obj_t, &lwip_socket_type); @@ -907,7 +907,7 @@ STATIC mp_obj_t lwip_socket_make_new(const mp_obj_type_t *type, size_t n_args, s return MP_OBJ_FROM_PTR(socket); } -STATIC mp_obj_t lwip_socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { +static mp_obj_t lwip_socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { lwip_socket_obj_t *socket = MP_OBJ_TO_PTR(self_in); ip_addr_t bind_addr; @@ -931,9 +931,9 @@ STATIC mp_obj_t lwip_socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_bind_obj, lwip_socket_bind); +static MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_bind_obj, lwip_socket_bind); -STATIC mp_obj_t lwip_socket_listen(size_t n_args, const mp_obj_t *args) { +static mp_obj_t lwip_socket_listen(size_t n_args, const mp_obj_t *args) { lwip_socket_obj_t *socket = MP_OBJ_TO_PTR(args[0]); mp_int_t backlog = MICROPY_PY_SOCKET_LISTEN_BACKLOG_DEFAULT; @@ -990,9 +990,9 @@ STATIC mp_obj_t lwip_socket_listen(size_t n_args, const mp_obj_t *args) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lwip_socket_listen_obj, 1, 2, lwip_socket_listen); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lwip_socket_listen_obj, 1, 2, lwip_socket_listen); -STATIC mp_obj_t lwip_socket_accept(mp_obj_t self_in) { +static mp_obj_t lwip_socket_accept(mp_obj_t self_in) { lwip_socket_obj_t *socket = MP_OBJ_TO_PTR(self_in); if (socket->type != MOD_NETWORK_SOCK_STREAM) { @@ -1077,9 +1077,9 @@ STATIC mp_obj_t lwip_socket_accept(mp_obj_t self_in) { return MP_OBJ_FROM_PTR(client); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(lwip_socket_accept_obj, lwip_socket_accept); +static MP_DEFINE_CONST_FUN_OBJ_1(lwip_socket_accept_obj, lwip_socket_accept); -STATIC mp_obj_t lwip_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { +static mp_obj_t lwip_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { lwip_socket_obj_t *socket = MP_OBJ_TO_PTR(self_in); if (socket->pcb.tcp == NULL) { @@ -1156,9 +1156,9 @@ STATIC mp_obj_t lwip_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_connect_obj, lwip_socket_connect); +static MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_connect_obj, lwip_socket_connect); -STATIC void lwip_socket_check_connected(lwip_socket_obj_t *socket) { +static void lwip_socket_check_connected(lwip_socket_obj_t *socket) { if (socket->pcb.tcp == NULL) { // not connected int _errno = error_lookup_table[-socket->state]; @@ -1167,7 +1167,7 @@ STATIC void lwip_socket_check_connected(lwip_socket_obj_t *socket) { } } -STATIC mp_obj_t lwip_socket_send(mp_obj_t self_in, mp_obj_t buf_in) { +static mp_obj_t lwip_socket_send(mp_obj_t self_in, mp_obj_t buf_in) { lwip_socket_obj_t *socket = MP_OBJ_TO_PTR(self_in); int _errno; @@ -1195,9 +1195,9 @@ STATIC mp_obj_t lwip_socket_send(mp_obj_t self_in, mp_obj_t buf_in) { return mp_obj_new_int_from_uint(ret); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_send_obj, lwip_socket_send); +static MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_send_obj, lwip_socket_send); -STATIC mp_obj_t lwip_socket_recv(mp_obj_t self_in, mp_obj_t len_in) { +static mp_obj_t lwip_socket_recv(mp_obj_t self_in, mp_obj_t len_in) { lwip_socket_obj_t *socket = MP_OBJ_TO_PTR(self_in); int _errno; @@ -1230,9 +1230,9 @@ STATIC mp_obj_t lwip_socket_recv(mp_obj_t self_in, mp_obj_t len_in) { vstr.len = ret; return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_recv_obj, lwip_socket_recv); +static MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_recv_obj, lwip_socket_recv); -STATIC mp_obj_t lwip_socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_in) { +static mp_obj_t lwip_socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_in) { lwip_socket_obj_t *socket = MP_OBJ_TO_PTR(self_in); int _errno; @@ -1263,9 +1263,9 @@ STATIC mp_obj_t lwip_socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t return mp_obj_new_int_from_uint(ret); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(lwip_socket_sendto_obj, lwip_socket_sendto); +static MP_DEFINE_CONST_FUN_OBJ_3(lwip_socket_sendto_obj, lwip_socket_sendto); -STATIC mp_obj_t lwip_socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) { +static mp_obj_t lwip_socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) { lwip_socket_obj_t *socket = MP_OBJ_TO_PTR(self_in); int _errno; @@ -1306,9 +1306,9 @@ STATIC mp_obj_t lwip_socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) { tuple[1] = netutils_format_inet_addr(ip, port, NETUTILS_BIG); return mp_obj_new_tuple(2, tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_recvfrom_obj, lwip_socket_recvfrom); +static MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_recvfrom_obj, lwip_socket_recvfrom); -STATIC mp_obj_t lwip_socket_sendall(mp_obj_t self_in, mp_obj_t buf_in) { +static mp_obj_t lwip_socket_sendall(mp_obj_t self_in, mp_obj_t buf_in) { lwip_socket_obj_t *socket = MP_OBJ_TO_PTR(self_in); lwip_socket_check_connected(socket); @@ -1348,9 +1348,9 @@ STATIC mp_obj_t lwip_socket_sendall(mp_obj_t self_in, mp_obj_t buf_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_sendall_obj, lwip_socket_sendall); +static MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_sendall_obj, lwip_socket_sendall); -STATIC mp_obj_t lwip_socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) { +static mp_obj_t lwip_socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) { lwip_socket_obj_t *socket = MP_OBJ_TO_PTR(self_in); mp_uint_t timeout; if (timeout_in == mp_const_none) { @@ -1365,9 +1365,9 @@ STATIC mp_obj_t lwip_socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) { socket->timeout = timeout; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_settimeout_obj, lwip_socket_settimeout); +static MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_settimeout_obj, lwip_socket_settimeout); -STATIC mp_obj_t lwip_socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) { +static mp_obj_t lwip_socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) { lwip_socket_obj_t *socket = MP_OBJ_TO_PTR(self_in); bool val = mp_obj_is_true(flag_in); if (val) { @@ -1377,7 +1377,7 @@ STATIC mp_obj_t lwip_socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_setblocking_obj, lwip_socket_setblocking); +static MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_setblocking_obj, lwip_socket_setblocking); #if LWIP_VERSION_MAJOR < 2 #define MP_IGMP_IP_ADDR_TYPE ip_addr_t @@ -1385,7 +1385,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_setblocking_obj, lwip_socket_setblo #define MP_IGMP_IP_ADDR_TYPE ip4_addr_t #endif -STATIC mp_obj_t lwip_socket_setsockopt(size_t n_args, const mp_obj_t *args) { +static mp_obj_t lwip_socket_setsockopt(size_t n_args, const mp_obj_t *args) { (void)n_args; // always 4 lwip_socket_obj_t *socket = MP_OBJ_TO_PTR(args[0]); @@ -1443,15 +1443,15 @@ STATIC mp_obj_t lwip_socket_setsockopt(size_t n_args, const mp_obj_t *args) { #undef MP_IGMP_IP_ADDR_TYPE -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lwip_socket_setsockopt_obj, 4, 4, lwip_socket_setsockopt); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lwip_socket_setsockopt_obj, 4, 4, lwip_socket_setsockopt); -STATIC mp_obj_t lwip_socket_makefile(size_t n_args, const mp_obj_t *args) { +static mp_obj_t lwip_socket_makefile(size_t n_args, const mp_obj_t *args) { (void)n_args; return args[0]; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lwip_socket_makefile_obj, 1, 3, lwip_socket_makefile); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lwip_socket_makefile_obj, 1, 3, lwip_socket_makefile); -STATIC mp_uint_t lwip_socket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t lwip_socket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { lwip_socket_obj_t *socket = MP_OBJ_TO_PTR(self_in); switch (socket->type) { @@ -1467,7 +1467,7 @@ STATIC mp_uint_t lwip_socket_read(mp_obj_t self_in, void *buf, mp_uint_t size, i return MP_STREAM_ERROR; } -STATIC mp_uint_t lwip_socket_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t lwip_socket_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { lwip_socket_obj_t *socket = MP_OBJ_TO_PTR(self_in); switch (socket->type) { @@ -1483,14 +1483,14 @@ STATIC mp_uint_t lwip_socket_write(mp_obj_t self_in, const void *buf, mp_uint_t return MP_STREAM_ERROR; } -STATIC err_t _lwip_tcp_close_poll(void *arg, struct tcp_pcb *pcb) { +static err_t _lwip_tcp_close_poll(void *arg, struct tcp_pcb *pcb) { // Connection has not been cleanly closed so just abort it to free up memory tcp_poll(pcb, NULL, 0); tcp_abort(pcb); return ERR_OK; } -STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { lwip_socket_obj_t *socket = MP_OBJ_TO_PTR(self_in); mp_uint_t ret; @@ -1604,7 +1604,7 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_ return ret; } -STATIC const mp_rom_map_elem_t lwip_socket_locals_dict_table[] = { +static const mp_rom_map_elem_t lwip_socket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_stream_close_obj) }, { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) }, { MP_ROM_QSTR(MP_QSTR_bind), MP_ROM_PTR(&lwip_socket_bind_obj) }, @@ -1626,15 +1626,15 @@ STATIC const mp_rom_map_elem_t lwip_socket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) }, { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(lwip_socket_locals_dict, lwip_socket_locals_dict_table); +static MP_DEFINE_CONST_DICT(lwip_socket_locals_dict, lwip_socket_locals_dict_table); -STATIC const mp_stream_p_t lwip_socket_stream_p = { +static const mp_stream_p_t lwip_socket_stream_p = { .read = lwip_socket_read, .write = lwip_socket_write, .ioctl = lwip_socket_ioctl, }; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( lwip_socket_type, MP_QSTR_socket, MP_TYPE_FLAG_NONE, @@ -1665,7 +1665,7 @@ typedef struct nic_poll { void *poll_arg; } nic_poll_t; -STATIC nic_poll_t lwip_poll_list; +static nic_poll_t lwip_poll_list; void mod_lwip_register_poll(void (*poll)(void *arg), void *poll_arg) { lwip_poll_list.poll = poll; @@ -1679,14 +1679,14 @@ void mod_lwip_deregister_poll(void (*poll)(void *arg), void *poll_arg) { /******************************************************************************/ // The lwip global functions. -STATIC mp_obj_t mod_lwip_reset() { +static mp_obj_t mod_lwip_reset() { lwip_init(); lwip_poll_list.poll = NULL; return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_0(mod_lwip_reset_obj, mod_lwip_reset); -STATIC mp_obj_t mod_lwip_callback() { +static mp_obj_t mod_lwip_callback() { if (lwip_poll_list.poll != NULL) { lwip_poll_list.poll(lwip_poll_list.poll_arg); } @@ -1702,9 +1702,9 @@ typedef struct _getaddrinfo_state_t { // Callback for incoming DNS requests. #if LWIP_VERSION_MAJOR < 2 -STATIC void lwip_getaddrinfo_cb(const char *name, ip_addr_t *ipaddr, void *arg) +static void lwip_getaddrinfo_cb(const char *name, ip_addr_t *ipaddr, void *arg) #else -STATIC void lwip_getaddrinfo_cb(const char *name, const ip_addr_t *ipaddr, void *arg) +static void lwip_getaddrinfo_cb(const char *name, const ip_addr_t *ipaddr, void *arg) #endif { getaddrinfo_state_t *state = arg; @@ -1718,7 +1718,7 @@ STATIC void lwip_getaddrinfo_cb(const char *name, const ip_addr_t *ipaddr, void } // lwip.getaddrinfo -STATIC mp_obj_t lwip_getaddrinfo(size_t n_args, const mp_obj_t *args) { +static mp_obj_t lwip_getaddrinfo(size_t n_args, const mp_obj_t *args) { mp_obj_t host_in = args[0], port_in = args[1]; const char *host = mp_obj_str_get_str(host_in); mp_int_t port = mp_obj_get_int(port_in); @@ -1786,13 +1786,13 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lwip_getaddrinfo_obj, 2, 6, lwip_getaddrinfo // Debug functions -STATIC mp_obj_t lwip_print_pcbs() { +static mp_obj_t lwip_print_pcbs() { tcp_debug_print_pcbs(); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_0(lwip_print_pcbs_obj, lwip_print_pcbs); -STATIC const mp_rom_map_elem_t mp_module_lwip_globals_table[] = { +static const mp_rom_map_elem_t mp_module_lwip_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_lwip) }, { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&mod_lwip_reset_obj) }, { MP_ROM_QSTR(MP_QSTR_callback), MP_ROM_PTR(&mod_lwip_callback_obj) }, @@ -1822,7 +1822,7 @@ STATIC const mp_rom_map_elem_t mp_module_lwip_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_IP_DROP_MEMBERSHIP), MP_ROM_INT(IP_DROP_MEMBERSHIP) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_lwip_globals, mp_module_lwip_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_lwip_globals, mp_module_lwip_globals_table); const mp_obj_module_t mp_module_lwip = { .base = { &mp_type_module }, diff --git a/extmod/modmachine.c b/extmod/modmachine.c index a64b8ba79d43a..90e2a38a73cfc 100644 --- a/extmod/modmachine.c +++ b/extmod/modmachine.c @@ -37,20 +37,20 @@ // The port must provide implementations of these low-level machine functions. -STATIC void mp_machine_idle(void); +static void mp_machine_idle(void); #if MICROPY_PY_MACHINE_BOOTLOADER NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args); #endif #if MICROPY_PY_MACHINE_BARE_METAL_FUNCS -STATIC mp_obj_t mp_machine_unique_id(void); -NORETURN STATIC void mp_machine_reset(void); -STATIC mp_int_t mp_machine_reset_cause(void); -STATIC mp_obj_t mp_machine_get_freq(void); -STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args); -STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args); -NORETURN STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args); +static mp_obj_t mp_machine_unique_id(void); +NORETURN static void mp_machine_reset(void); +static mp_int_t mp_machine_reset_cause(void); +static mp_obj_t mp_machine_get_freq(void); +static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args); +static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args); +NORETURN static void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args); #endif // The port can provide additional machine-module implementation in this file. @@ -58,11 +58,11 @@ NORETURN STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args); #include MICROPY_PY_MACHINE_INCLUDEFILE #endif -STATIC mp_obj_t machine_soft_reset(void) { +static mp_obj_t machine_soft_reset(void) { pyexec_system_exit = PYEXEC_FORCED_EXIT; mp_raise_type(&mp_type_SystemExit); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_soft_reset_obj, machine_soft_reset); +static MP_DEFINE_CONST_FUN_OBJ_0(machine_soft_reset_obj, machine_soft_reset); #if MICROPY_PY_MACHINE_BOOTLOADER NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) { @@ -71,30 +71,30 @@ NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bootloader_obj, 0, 1, machine_bootloader); #endif -STATIC mp_obj_t machine_idle(void) { +static mp_obj_t machine_idle(void) { mp_machine_idle(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_idle_obj, machine_idle); +static MP_DEFINE_CONST_FUN_OBJ_0(machine_idle_obj, machine_idle); #if MICROPY_PY_MACHINE_BARE_METAL_FUNCS -STATIC mp_obj_t machine_unique_id(void) { +static mp_obj_t machine_unique_id(void) { return mp_machine_unique_id(); } MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id); -NORETURN STATIC mp_obj_t machine_reset(void) { +NORETURN static mp_obj_t machine_reset(void) { mp_machine_reset(); } MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset); -STATIC mp_obj_t machine_reset_cause(void) { +static mp_obj_t machine_reset_cause(void) { return MP_OBJ_NEW_SMALL_INT(mp_machine_reset_cause()); } MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause); -STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) { if (n_args == 0) { return mp_machine_get_freq(); } else { @@ -104,13 +104,13 @@ STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj, 0, 1, machine_freq); -STATIC mp_obj_t machine_lightsleep(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_lightsleep(size_t n_args, const mp_obj_t *args) { mp_machine_lightsleep(n_args, args); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_lightsleep_obj, 0, 1, machine_lightsleep); -NORETURN STATIC mp_obj_t machine_deepsleep(size_t n_args, const mp_obj_t *args) { +NORETURN static mp_obj_t machine_deepsleep(size_t n_args, const mp_obj_t *args) { mp_machine_deepsleep(n_args, args); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_deepsleep_obj, 0, 1, machine_deepsleep); @@ -119,22 +119,22 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_deepsleep_obj, 0, 1, machine_deepsle #if MICROPY_PY_MACHINE_DISABLE_IRQ_ENABLE_IRQ -STATIC mp_obj_t machine_disable_irq(void) { +static mp_obj_t machine_disable_irq(void) { uint32_t state = MICROPY_BEGIN_ATOMIC_SECTION(); return mp_obj_new_int(state); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_disable_irq_obj, machine_disable_irq); +static MP_DEFINE_CONST_FUN_OBJ_0(machine_disable_irq_obj, machine_disable_irq); -STATIC mp_obj_t machine_enable_irq(mp_obj_t state_in) { +static mp_obj_t machine_enable_irq(mp_obj_t state_in) { uint32_t state = mp_obj_get_int(state_in); MICROPY_END_ATOMIC_SECTION(state); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_enable_irq_obj, machine_enable_irq); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_enable_irq_obj, machine_enable_irq); #endif -STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { +static const mp_rom_map_elem_t machine_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_machine) }, // Memory access objects. @@ -230,7 +230,7 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { MICROPY_PY_MACHINE_EXTRA_GLOBALS #endif }; -STATIC MP_DEFINE_CONST_DICT(machine_module_globals, machine_module_globals_table); +static MP_DEFINE_CONST_DICT(machine_module_globals, machine_module_globals_table); const mp_obj_module_t mp_module_machine = { .base = { &mp_type_module }, diff --git a/extmod/modnetwork.c b/extmod/modnetwork.c index 527d1729e66c7..c8d2b9e3ff40a 100644 --- a/extmod/modnetwork.c +++ b/extmod/modnetwork.c @@ -99,16 +99,16 @@ mp_obj_t mod_network_find_nic(const uint8_t *ip) { mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("no available NIC")); } -STATIC mp_obj_t network_route(void) { +static mp_obj_t network_route(void) { return MP_OBJ_FROM_PTR(&MP_STATE_PORT(mod_network_nic_list)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(network_route_obj, network_route); +static MP_DEFINE_CONST_FUN_OBJ_0(network_route_obj, network_route); MP_REGISTER_ROOT_POINTER(mp_obj_list_t mod_network_nic_list); #endif // MICROPY_PORT_NETWORK_INTERFACES -STATIC mp_obj_t network_country(size_t n_args, const mp_obj_t *args) { +static mp_obj_t network_country(size_t n_args, const mp_obj_t *args) { if (n_args == 0) { return mp_obj_new_str(mod_network_country_code, 2); } else { @@ -139,9 +139,9 @@ mp_obj_t mod_network_hostname(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_network_hostname_obj, 0, 1, mod_network_hostname); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_network_hostname_obj, 0, 1, mod_network_hostname); -STATIC const mp_rom_map_elem_t mp_module_network_globals_table[] = { +static const mp_rom_map_elem_t mp_module_network_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_network) }, { MP_ROM_QSTR(MP_QSTR_country), MP_ROM_PTR(&mod_network_country_obj) }, { MP_ROM_QSTR(MP_QSTR_hostname), MP_ROM_PTR(&mod_network_hostname_obj) }, @@ -162,7 +162,7 @@ STATIC const mp_rom_map_elem_t mp_module_network_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_network_globals, mp_module_network_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_network_globals, mp_module_network_globals_table); const mp_obj_module_t mp_module_network = { .base = { &mp_type_module }, diff --git a/extmod/modonewire.c b/extmod/modonewire.c index 8444181810c27..6bef83d03e0fa 100644 --- a/extmod/modonewire.c +++ b/extmod/modonewire.c @@ -45,7 +45,7 @@ #define TIMING_WRITE2 (54) #define TIMING_WRITE3 (10) -STATIC int onewire_bus_reset(mp_hal_pin_obj_t pin) { +static int onewire_bus_reset(mp_hal_pin_obj_t pin) { mp_hal_pin_od_low(pin); mp_hal_delay_us(TIMING_RESET1); uint32_t i = mp_hal_quiet_timing_enter(); @@ -57,7 +57,7 @@ STATIC int onewire_bus_reset(mp_hal_pin_obj_t pin) { return status; } -STATIC int onewire_bus_readbit(mp_hal_pin_obj_t pin) { +static int onewire_bus_readbit(mp_hal_pin_obj_t pin) { mp_hal_pin_od_high(pin); uint32_t i = mp_hal_quiet_timing_enter(); mp_hal_pin_od_low(pin); @@ -70,7 +70,7 @@ STATIC int onewire_bus_readbit(mp_hal_pin_obj_t pin) { return value; } -STATIC void onewire_bus_writebit(mp_hal_pin_obj_t pin, int value) { +static void onewire_bus_writebit(mp_hal_pin_obj_t pin, int value) { uint32_t i = mp_hal_quiet_timing_enter(); mp_hal_pin_od_low(pin); mp_hal_delay_us_fast(TIMING_WRITE1); @@ -86,17 +86,17 @@ STATIC void onewire_bus_writebit(mp_hal_pin_obj_t pin, int value) { /******************************************************************************/ // MicroPython bindings -STATIC mp_obj_t onewire_reset(mp_obj_t pin_in) { +static mp_obj_t onewire_reset(mp_obj_t pin_in) { return mp_obj_new_bool(onewire_bus_reset(mp_hal_get_pin_obj(pin_in))); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(onewire_reset_obj, onewire_reset); +static MP_DEFINE_CONST_FUN_OBJ_1(onewire_reset_obj, onewire_reset); -STATIC mp_obj_t onewire_readbit(mp_obj_t pin_in) { +static mp_obj_t onewire_readbit(mp_obj_t pin_in) { return MP_OBJ_NEW_SMALL_INT(onewire_bus_readbit(mp_hal_get_pin_obj(pin_in))); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(onewire_readbit_obj, onewire_readbit); +static MP_DEFINE_CONST_FUN_OBJ_1(onewire_readbit_obj, onewire_readbit); -STATIC mp_obj_t onewire_readbyte(mp_obj_t pin_in) { +static mp_obj_t onewire_readbyte(mp_obj_t pin_in) { mp_hal_pin_obj_t pin = mp_hal_get_pin_obj(pin_in); uint8_t value = 0; for (int i = 0; i < 8; ++i) { @@ -104,15 +104,15 @@ STATIC mp_obj_t onewire_readbyte(mp_obj_t pin_in) { } return MP_OBJ_NEW_SMALL_INT(value); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(onewire_readbyte_obj, onewire_readbyte); +static MP_DEFINE_CONST_FUN_OBJ_1(onewire_readbyte_obj, onewire_readbyte); -STATIC mp_obj_t onewire_writebit(mp_obj_t pin_in, mp_obj_t value_in) { +static mp_obj_t onewire_writebit(mp_obj_t pin_in, mp_obj_t value_in) { onewire_bus_writebit(mp_hal_get_pin_obj(pin_in), mp_obj_get_int(value_in)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(onewire_writebit_obj, onewire_writebit); +static MP_DEFINE_CONST_FUN_OBJ_2(onewire_writebit_obj, onewire_writebit); -STATIC mp_obj_t onewire_writebyte(mp_obj_t pin_in, mp_obj_t value_in) { +static mp_obj_t onewire_writebyte(mp_obj_t pin_in, mp_obj_t value_in) { mp_hal_pin_obj_t pin = mp_hal_get_pin_obj(pin_in); int value = mp_obj_get_int(value_in); for (int i = 0; i < 8; ++i) { @@ -121,9 +121,9 @@ STATIC mp_obj_t onewire_writebyte(mp_obj_t pin_in, mp_obj_t value_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(onewire_writebyte_obj, onewire_writebyte); +static MP_DEFINE_CONST_FUN_OBJ_2(onewire_writebyte_obj, onewire_writebyte); -STATIC mp_obj_t onewire_crc8(mp_obj_t data) { +static mp_obj_t onewire_crc8(mp_obj_t data) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ); uint8_t crc = 0; @@ -143,9 +143,9 @@ STATIC mp_obj_t onewire_crc8(mp_obj_t data) { } return MP_OBJ_NEW_SMALL_INT(crc); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(onewire_crc8_obj, onewire_crc8); +static MP_DEFINE_CONST_FUN_OBJ_1(onewire_crc8_obj, onewire_crc8); -STATIC const mp_rom_map_elem_t onewire_module_globals_table[] = { +static const mp_rom_map_elem_t onewire_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_onewire) }, { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&onewire_reset_obj) }, @@ -156,7 +156,7 @@ STATIC const mp_rom_map_elem_t onewire_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_crc8), MP_ROM_PTR(&onewire_crc8_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(onewire_module_globals, onewire_module_globals_table); +static MP_DEFINE_CONST_DICT(onewire_module_globals, onewire_module_globals_table); const mp_obj_module_t mp_module_onewire = { .base = { &mp_type_module }, diff --git a/extmod/modos.c b/extmod/modos.c index 24a36cb8ce961..eda359b97b1b0 100644 --- a/extmod/modos.c +++ b/extmod/modos.c @@ -73,7 +73,7 @@ #if MICROPY_PY_OS_SYNC // sync() // Sync all filesystems. -STATIC mp_obj_t mp_os_sync(void) { +static mp_obj_t mp_os_sync(void) { #if MICROPY_VFS_FAT for (mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table); vfs != NULL; vfs = vfs->next) { // this assumes that vfs->obj is fs_user_mount_t with block device functions @@ -93,20 +93,20 @@ MP_DEFINE_CONST_FUN_OBJ_0(mp_os_sync_obj, mp_os_sync); #define CONST_RELEASE const #endif -STATIC const qstr mp_os_uname_info_fields[] = { +static const qstr mp_os_uname_info_fields[] = { MP_QSTR_sysname, MP_QSTR_nodename, MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine }; -STATIC const MP_DEFINE_STR_OBJ(mp_os_uname_info_sysname_obj, MICROPY_PY_SYS_PLATFORM); -STATIC const MP_DEFINE_STR_OBJ(mp_os_uname_info_nodename_obj, MICROPY_PY_SYS_PLATFORM); -STATIC CONST_RELEASE MP_DEFINE_STR_OBJ(mp_os_uname_info_release_obj, MICROPY_VERSION_STRING); -STATIC const MP_DEFINE_STR_OBJ(mp_os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE MICROPY_BUILD_TYPE_PAREN); -STATIC const MP_DEFINE_STR_OBJ(mp_os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); +static const MP_DEFINE_STR_OBJ(mp_os_uname_info_sysname_obj, MICROPY_PY_SYS_PLATFORM); +static const MP_DEFINE_STR_OBJ(mp_os_uname_info_nodename_obj, MICROPY_PY_SYS_PLATFORM); +static CONST_RELEASE MP_DEFINE_STR_OBJ(mp_os_uname_info_release_obj, MICROPY_VERSION_STRING); +static const MP_DEFINE_STR_OBJ(mp_os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE MICROPY_BUILD_TYPE_PAREN); +static const MP_DEFINE_STR_OBJ(mp_os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); -STATIC MP_DEFINE_ATTRTUPLE( +static MP_DEFINE_ATTRTUPLE( mp_os_uname_info_obj, mp_os_uname_info_fields, 5, @@ -117,7 +117,7 @@ STATIC MP_DEFINE_ATTRTUPLE( MP_ROM_PTR(&mp_os_uname_info_machine_obj) ); -STATIC mp_obj_t mp_os_uname(void) { +static mp_obj_t mp_os_uname(void) { #if MICROPY_PY_OS_UNAME_RELEASE_DYNAMIC const char *release = mp_os_uname_release(); mp_os_uname_info_release_obj.len = strlen(release); @@ -125,12 +125,12 @@ STATIC mp_obj_t mp_os_uname(void) { #endif return MP_OBJ_FROM_PTR(&mp_os_uname_info_obj); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_os_uname_obj, mp_os_uname); +static MP_DEFINE_CONST_FUN_OBJ_0(mp_os_uname_obj, mp_os_uname); #endif #if MICROPY_PY_OS_DUPTERM_NOTIFY -STATIC mp_obj_t mp_os_dupterm_notify(mp_obj_t obj_in) { +static mp_obj_t mp_os_dupterm_notify(mp_obj_t obj_in) { (void)obj_in; for (;;) { int c = mp_os_dupterm_rx_chr(); @@ -141,10 +141,10 @@ STATIC mp_obj_t mp_os_dupterm_notify(mp_obj_t obj_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_dupterm_notify_obj, mp_os_dupterm_notify); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_os_dupterm_notify_obj, mp_os_dupterm_notify); #endif -STATIC const mp_rom_map_elem_t os_module_globals_table[] = { +static const mp_rom_map_elem_t os_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_os) }, #if MICROPY_PY_OS_GETENV_PUTENV_UNSETENV @@ -223,7 +223,7 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&os_mbfs_remove_obj) }, #endif }; -STATIC MP_DEFINE_CONST_DICT(os_module_globals, os_module_globals_table); +static MP_DEFINE_CONST_DICT(os_module_globals, os_module_globals_table); const mp_obj_module_t mp_module_os = { .base = { &mp_type_module }, diff --git a/extmod/modplatform.c b/extmod/modplatform.c index 73846f946d0ed..c6d4d31b97ec1 100644 --- a/extmod/modplatform.c +++ b/extmod/modplatform.c @@ -36,39 +36,39 @@ // platform - Access to underlying platform's identifying data -STATIC const MP_DEFINE_STR_OBJ(info_platform_obj, MICROPY_PLATFORM_SYSTEM "-" \ +static const MP_DEFINE_STR_OBJ(info_platform_obj, MICROPY_PLATFORM_SYSTEM "-" \ MICROPY_VERSION_STRING "-" MICROPY_PLATFORM_ARCH "-" MICROPY_PLATFORM_VERSION "-with-" \ MICROPY_PLATFORM_LIBC_LIB "" MICROPY_PLATFORM_LIBC_VER); -STATIC const MP_DEFINE_STR_OBJ(info_python_compiler_obj, MICROPY_PLATFORM_COMPILER); -STATIC const MP_DEFINE_STR_OBJ(info_libc_lib_obj, MICROPY_PLATFORM_LIBC_LIB); -STATIC const MP_DEFINE_STR_OBJ(info_libc_ver_obj, MICROPY_PLATFORM_LIBC_VER); -STATIC const mp_rom_obj_tuple_t info_libc_tuple_obj = { +static const MP_DEFINE_STR_OBJ(info_python_compiler_obj, MICROPY_PLATFORM_COMPILER); +static const MP_DEFINE_STR_OBJ(info_libc_lib_obj, MICROPY_PLATFORM_LIBC_LIB); +static const MP_DEFINE_STR_OBJ(info_libc_ver_obj, MICROPY_PLATFORM_LIBC_VER); +static const mp_rom_obj_tuple_t info_libc_tuple_obj = { {&mp_type_tuple}, 2, {MP_ROM_PTR(&info_libc_lib_obj), MP_ROM_PTR(&info_libc_ver_obj)} }; -STATIC mp_obj_t platform_platform(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t platform_platform(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { return MP_OBJ_FROM_PTR(&info_platform_obj); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(platform_platform_obj, 0, platform_platform); +static MP_DEFINE_CONST_FUN_OBJ_KW(platform_platform_obj, 0, platform_platform); -STATIC mp_obj_t platform_python_compiler(void) { +static mp_obj_t platform_python_compiler(void) { return MP_OBJ_FROM_PTR(&info_python_compiler_obj); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(platform_python_compiler_obj, platform_python_compiler); +static MP_DEFINE_CONST_FUN_OBJ_0(platform_python_compiler_obj, platform_python_compiler); -STATIC mp_obj_t platform_libc_ver(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t platform_libc_ver(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { return MP_OBJ_FROM_PTR(&info_libc_tuple_obj); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(platform_libc_ver_obj, 0, platform_libc_ver); +static MP_DEFINE_CONST_FUN_OBJ_KW(platform_libc_ver_obj, 0, platform_libc_ver); -STATIC const mp_rom_map_elem_t modplatform_globals_table[] = { +static const mp_rom_map_elem_t modplatform_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_platform) }, { MP_ROM_QSTR(MP_QSTR_platform), MP_ROM_PTR(&platform_platform_obj) }, { MP_ROM_QSTR(MP_QSTR_python_compiler), MP_ROM_PTR(&platform_python_compiler_obj) }, { MP_ROM_QSTR(MP_QSTR_libc_ver), MP_ROM_PTR(&platform_libc_ver_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(modplatform_globals, modplatform_globals_table); +static MP_DEFINE_CONST_DICT(modplatform_globals, modplatform_globals_table); const mp_obj_module_t mp_module_platform = { .base = { &mp_type_module }, diff --git a/extmod/modrandom.c b/extmod/modrandom.c index d66f1c9c46dce..79a1b18baac2d 100644 --- a/extmod/modrandom.c +++ b/extmod/modrandom.c @@ -46,16 +46,16 @@ #if !MICROPY_ENABLE_DYNRUNTIME #if SEED_ON_IMPORT // If the state is seeded on import then keep these variables in the BSS. -STATIC uint32_t yasmarang_pad, yasmarang_n, yasmarang_d; -STATIC uint8_t yasmarang_dat; +static uint32_t yasmarang_pad, yasmarang_n, yasmarang_d; +static uint8_t yasmarang_dat; #else // Without seed-on-import these variables must be initialised via the data section. -STATIC uint32_t yasmarang_pad = 0xeda4baba, yasmarang_n = 69, yasmarang_d = 233; -STATIC uint8_t yasmarang_dat = 0; +static uint32_t yasmarang_pad = 0xeda4baba, yasmarang_n = 69, yasmarang_d = 233; +static uint8_t yasmarang_dat = 0; #endif #endif -STATIC uint32_t yasmarang(void) { +static uint32_t yasmarang(void) { yasmarang_pad += yasmarang_dat + yasmarang_d * yasmarang_n; yasmarang_pad = (yasmarang_pad << 3) + (yasmarang_pad >> 29); yasmarang_n = yasmarang_pad | 2; @@ -71,7 +71,7 @@ STATIC uint32_t yasmarang(void) { // returns an unsigned integer below the given argument // n must not be zero -STATIC uint32_t yasmarang_randbelow(uint32_t n) { +static uint32_t yasmarang_randbelow(uint32_t n) { uint32_t mask = 1; while ((n & mask) < n) { mask = (mask << 1) | 1; @@ -85,7 +85,7 @@ STATIC uint32_t yasmarang_randbelow(uint32_t n) { #endif -STATIC mp_obj_t mod_random_getrandbits(mp_obj_t num_in) { +static mp_obj_t mod_random_getrandbits(mp_obj_t num_in) { mp_int_t n = mp_obj_get_int(num_in); if (n > 32 || n < 0) { mp_raise_ValueError(MP_ERROR_TEXT("bits must be 32 or less")); @@ -98,9 +98,9 @@ STATIC mp_obj_t mod_random_getrandbits(mp_obj_t num_in) { mask >>= (32 - n); return mp_obj_new_int_from_uint(yasmarang() & mask); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_random_getrandbits_obj, mod_random_getrandbits); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_random_getrandbits_obj, mod_random_getrandbits); -STATIC mp_obj_t mod_random_seed(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_random_seed(size_t n_args, const mp_obj_t *args) { mp_uint_t seed; if (n_args == 0 || args[0] == mp_const_none) { #ifdef MICROPY_PY_RANDOM_SEED_INIT_FUNC @@ -117,11 +117,11 @@ STATIC mp_obj_t mod_random_seed(size_t n_args, const mp_obj_t *args) { yasmarang_dat = 0; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_random_seed_obj, 0, 1, mod_random_seed); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_random_seed_obj, 0, 1, mod_random_seed); #if MICROPY_PY_RANDOM_EXTRA_FUNCS -STATIC mp_obj_t mod_random_randrange(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_random_randrange(size_t n_args, const mp_obj_t *args) { mp_int_t start = mp_obj_get_int(args[0]); if (n_args == 1) { // range(stop) @@ -161,9 +161,9 @@ STATIC mp_obj_t mod_random_randrange(size_t n_args, const mp_obj_t *args) { error: mp_raise_ValueError(NULL); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_random_randrange_obj, 1, 3, mod_random_randrange); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_random_randrange_obj, 1, 3, mod_random_randrange); -STATIC mp_obj_t mod_random_randint(mp_obj_t a_in, mp_obj_t b_in) { +static mp_obj_t mod_random_randint(mp_obj_t a_in, mp_obj_t b_in) { mp_int_t a = mp_obj_get_int(a_in); mp_int_t b = mp_obj_get_int(b_in); if (a <= b) { @@ -172,9 +172,9 @@ STATIC mp_obj_t mod_random_randint(mp_obj_t a_in, mp_obj_t b_in) { mp_raise_ValueError(NULL); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_random_randint_obj, mod_random_randint); +static MP_DEFINE_CONST_FUN_OBJ_2(mod_random_randint_obj, mod_random_randint); -STATIC mp_obj_t mod_random_choice(mp_obj_t seq) { +static mp_obj_t mod_random_choice(mp_obj_t seq) { mp_int_t len = mp_obj_get_int(mp_obj_len(seq)); if (len > 0) { return mp_obj_subscr(seq, mp_obj_new_int(yasmarang_randbelow((uint32_t)len)), MP_OBJ_SENTINEL); @@ -182,12 +182,12 @@ STATIC mp_obj_t mod_random_choice(mp_obj_t seq) { mp_raise_type(&mp_type_IndexError); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_random_choice_obj, mod_random_choice); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_random_choice_obj, mod_random_choice); #if MICROPY_PY_BUILTINS_FLOAT // returns a number in the range [0..1) using Yasmarang to fill in the fraction bits -STATIC mp_float_t yasmarang_float(void) { +static mp_float_t yasmarang_float(void) { mp_float_union_t u; u.p.sgn = 0; u.p.exp = (1 << (MP_FLOAT_EXP_BITS - 1)) - 1; @@ -199,24 +199,24 @@ STATIC mp_float_t yasmarang_float(void) { return u.f - 1; } -STATIC mp_obj_t mod_random_random(void) { +static mp_obj_t mod_random_random(void) { return mp_obj_new_float(yasmarang_float()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_random_random_obj, mod_random_random); +static MP_DEFINE_CONST_FUN_OBJ_0(mod_random_random_obj, mod_random_random); -STATIC mp_obj_t mod_random_uniform(mp_obj_t a_in, mp_obj_t b_in) { +static mp_obj_t mod_random_uniform(mp_obj_t a_in, mp_obj_t b_in) { mp_float_t a = mp_obj_get_float(a_in); mp_float_t b = mp_obj_get_float(b_in); return mp_obj_new_float(a + (b - a) * yasmarang_float()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_random_uniform_obj, mod_random_uniform); +static MP_DEFINE_CONST_FUN_OBJ_2(mod_random_uniform_obj, mod_random_uniform); #endif #endif // MICROPY_PY_RANDOM_EXTRA_FUNCS #if SEED_ON_IMPORT -STATIC mp_obj_t mod_random___init__(void) { +static mp_obj_t mod_random___init__(void) { // This module may be imported by more than one name so need to ensure // that it's only ever seeded once. static bool seeded = false; @@ -226,11 +226,11 @@ STATIC mp_obj_t mod_random___init__(void) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_random___init___obj, mod_random___init__); +static MP_DEFINE_CONST_FUN_OBJ_0(mod_random___init___obj, mod_random___init__); #endif #if !MICROPY_ENABLE_DYNRUNTIME -STATIC const mp_rom_map_elem_t mp_module_random_globals_table[] = { +static const mp_rom_map_elem_t mp_module_random_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_random) }, #if SEED_ON_IMPORT { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&mod_random___init___obj) }, @@ -248,7 +248,7 @@ STATIC const mp_rom_map_elem_t mp_module_random_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_random_globals, mp_module_random_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_random_globals, mp_module_random_globals_table); const mp_obj_module_t mp_module_random = { .base = { &mp_type_module }, diff --git a/extmod/modre.c b/extmod/modre.c index 9d5d7178728ed..2a3fdfd3505f3 100644 --- a/extmod/modre.c +++ b/extmod/modre.c @@ -57,18 +57,18 @@ typedef struct _mp_obj_match_t { const char *caps[0]; } mp_obj_match_t; -STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args); +static mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args); #if !MICROPY_ENABLE_DYNRUNTIME -STATIC const mp_obj_type_t re_type; +static const mp_obj_type_t re_type; #endif -STATIC void match_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void match_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_match_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", self->num_matches); } -STATIC mp_obj_t match_group(mp_obj_t self_in, mp_obj_t no_in) { +static mp_obj_t match_group(mp_obj_t self_in, mp_obj_t no_in) { mp_obj_match_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t no = mp_obj_get_int(no_in); if (no < 0 || no >= self->num_matches) { @@ -87,7 +87,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(match_group_obj, match_group); #if MICROPY_PY_RE_MATCH_GROUPS -STATIC mp_obj_t match_groups(mp_obj_t self_in) { +static mp_obj_t match_groups(mp_obj_t self_in) { mp_obj_match_t *self = MP_OBJ_TO_PTR(self_in); if (self->num_matches <= 1) { return mp_const_empty_tuple; @@ -104,7 +104,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(match_groups_obj, match_groups); #if MICROPY_PY_RE_MATCH_SPAN_START_END -STATIC void match_span_helper(size_t n_args, const mp_obj_t *args, mp_obj_t span[2]) { +static void match_span_helper(size_t n_args, const mp_obj_t *args, mp_obj_t span[2]) { mp_obj_match_t *self = MP_OBJ_TO_PTR(args[0]); mp_int_t no = 0; @@ -141,21 +141,21 @@ STATIC void match_span_helper(size_t n_args, const mp_obj_t *args, mp_obj_t span span[1] = mp_obj_new_int(e); } -STATIC mp_obj_t match_span(size_t n_args, const mp_obj_t *args) { +static mp_obj_t match_span(size_t n_args, const mp_obj_t *args) { mp_obj_t span[2]; match_span_helper(n_args, args, span); return mp_obj_new_tuple(2, span); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(match_span_obj, 1, 2, match_span); -STATIC mp_obj_t match_start(size_t n_args, const mp_obj_t *args) { +static mp_obj_t match_start(size_t n_args, const mp_obj_t *args) { mp_obj_t span[2]; match_span_helper(n_args, args, span); return span[0]; } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(match_start_obj, 1, 2, match_start); -STATIC mp_obj_t match_end(size_t n_args, const mp_obj_t *args) { +static mp_obj_t match_end(size_t n_args, const mp_obj_t *args) { mp_obj_t span[2]; match_span_helper(n_args, args, span); return span[1]; @@ -165,7 +165,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(match_end_obj, 1, 2, match_end); #endif #if !MICROPY_ENABLE_DYNRUNTIME -STATIC const mp_rom_map_elem_t match_locals_dict_table[] = { +static const mp_rom_map_elem_t match_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_group), MP_ROM_PTR(&match_group_obj) }, #if MICROPY_PY_RE_MATCH_GROUPS { MP_ROM_QSTR(MP_QSTR_groups), MP_ROM_PTR(&match_groups_obj) }, @@ -177,9 +177,9 @@ STATIC const mp_rom_map_elem_t match_locals_dict_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(match_locals_dict, match_locals_dict_table); +static MP_DEFINE_CONST_DICT(match_locals_dict, match_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( match_type, MP_QSTR_match, MP_TYPE_FLAG_NONE, @@ -188,13 +188,13 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); #endif -STATIC void re_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void re_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_re_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", self); } -STATIC mp_obj_t re_exec(bool is_anchored, uint n_args, const mp_obj_t *args) { +static mp_obj_t re_exec(bool is_anchored, uint n_args, const mp_obj_t *args) { (void)n_args; mp_obj_re_t *self; if (mp_obj_is_type(args[0], (mp_obj_type_t *)&re_type)) { @@ -222,17 +222,17 @@ STATIC mp_obj_t re_exec(bool is_anchored, uint n_args, const mp_obj_t *args) { return MP_OBJ_FROM_PTR(match); } -STATIC mp_obj_t re_match(size_t n_args, const mp_obj_t *args) { +static mp_obj_t re_match(size_t n_args, const mp_obj_t *args) { return re_exec(true, n_args, args); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(re_match_obj, 2, 4, re_match); -STATIC mp_obj_t re_search(size_t n_args, const mp_obj_t *args) { +static mp_obj_t re_search(size_t n_args, const mp_obj_t *args) { return re_exec(false, n_args, args); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(re_search_obj, 2, 4, re_search); -STATIC mp_obj_t re_split(size_t n_args, const mp_obj_t *args) { +static mp_obj_t re_split(size_t n_args, const mp_obj_t *args) { mp_obj_re_t *self = MP_OBJ_TO_PTR(args[0]); Subject subj; size_t len; @@ -279,7 +279,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(re_split_obj, 2, 3, re_split); #if MICROPY_PY_RE_SUB -STATIC mp_obj_t re_sub_helper(size_t n_args, const mp_obj_t *args) { +static mp_obj_t re_sub_helper(size_t n_args, const mp_obj_t *args) { mp_obj_re_t *self; if (mp_obj_is_type(args[0], (mp_obj_type_t *)&re_type)) { self = MP_OBJ_TO_PTR(args[0]); @@ -401,7 +401,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(re_sub_obj, 3, 5, re_sub_helper); #endif #if !MICROPY_ENABLE_DYNRUNTIME -STATIC const mp_rom_map_elem_t re_locals_dict_table[] = { +static const mp_rom_map_elem_t re_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_match), MP_ROM_PTR(&re_match_obj) }, { MP_ROM_QSTR(MP_QSTR_search), MP_ROM_PTR(&re_search_obj) }, { MP_ROM_QSTR(MP_QSTR_split), MP_ROM_PTR(&re_split_obj) }, @@ -410,9 +410,9 @@ STATIC const mp_rom_map_elem_t re_locals_dict_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(re_locals_dict, re_locals_dict_table); +static MP_DEFINE_CONST_DICT(re_locals_dict, re_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( re_type, MP_QSTR_re, MP_TYPE_FLAG_NONE, @@ -421,7 +421,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); #endif -STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) { (void)n_args; const char *re_str = mp_obj_str_get_str(args[0]); int size = re1_5_sizecode(re_str); @@ -450,7 +450,7 @@ STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_re_compile_obj, 1, 2, mod_re_compile); #if !MICROPY_ENABLE_DYNRUNTIME -STATIC const mp_rom_map_elem_t mp_module_re_globals_table[] = { +static const mp_rom_map_elem_t mp_module_re_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_re) }, { MP_ROM_QSTR(MP_QSTR_compile), MP_ROM_PTR(&mod_re_compile_obj) }, { MP_ROM_QSTR(MP_QSTR_match), MP_ROM_PTR(&re_match_obj) }, @@ -463,7 +463,7 @@ STATIC const mp_rom_map_elem_t mp_module_re_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_re_globals, mp_module_re_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_re_globals, mp_module_re_globals_table); const mp_obj_module_t mp_module_re = { .base = { &mp_type_module }, diff --git a/extmod/modselect.c b/extmod/modselect.c index 9b81ba509f5d5..d06157e585ae1 100644 --- a/extmod/modselect.c +++ b/extmod/modselect.c @@ -96,7 +96,7 @@ typedef struct _poll_set_t { #endif } poll_set_t; -STATIC void poll_set_init(poll_set_t *poll_set, size_t n) { +static void poll_set_init(poll_set_t *poll_set, size_t n) { mp_map_init(&poll_set->map, n); #if MICROPY_PY_SELECT_POSIX_OPTIMISATIONS poll_set->alloc = 0; @@ -107,19 +107,19 @@ STATIC void poll_set_init(poll_set_t *poll_set, size_t n) { } #if MICROPY_PY_SELECT_SELECT -STATIC void poll_set_deinit(poll_set_t *poll_set) { +static void poll_set_deinit(poll_set_t *poll_set) { mp_map_deinit(&poll_set->map); } #endif #if MICROPY_PY_SELECT_POSIX_OPTIMISATIONS -STATIC mp_uint_t poll_obj_get_events(poll_obj_t *poll_obj) { +static mp_uint_t poll_obj_get_events(poll_obj_t *poll_obj) { assert(poll_obj->pollfd == NULL); return poll_obj->nonfd_events; } -STATIC void poll_obj_set_events(poll_obj_t *poll_obj, mp_uint_t events) { +static void poll_obj_set_events(poll_obj_t *poll_obj, mp_uint_t events) { if (poll_obj->pollfd != NULL) { poll_obj->pollfd->events = events; } else { @@ -127,7 +127,7 @@ STATIC void poll_obj_set_events(poll_obj_t *poll_obj, mp_uint_t events) { } } -STATIC mp_uint_t poll_obj_get_revents(poll_obj_t *poll_obj) { +static mp_uint_t poll_obj_get_revents(poll_obj_t *poll_obj) { if (poll_obj->pollfd != NULL) { return poll_obj->pollfd->revents; } else { @@ -135,7 +135,7 @@ STATIC mp_uint_t poll_obj_get_revents(poll_obj_t *poll_obj) { } } -STATIC void poll_obj_set_revents(poll_obj_t *poll_obj, mp_uint_t revents) { +static void poll_obj_set_revents(poll_obj_t *poll_obj, mp_uint_t revents) { if (poll_obj->pollfd != NULL) { poll_obj->pollfd->revents = revents; } else { @@ -146,7 +146,7 @@ STATIC void poll_obj_set_revents(poll_obj_t *poll_obj, mp_uint_t revents) { // How much (in pollfds) to grow the allocation for poll_set->pollfds by. #define POLL_SET_ALLOC_INCREMENT (4) -STATIC struct pollfd *poll_set_add_fd(poll_set_t *poll_set, int fd) { +static struct pollfd *poll_set_add_fd(poll_set_t *poll_set, int fd) { struct pollfd *free_slot = NULL; if (poll_set->used == poll_set->max_used) { @@ -228,7 +228,7 @@ static inline void poll_obj_set_revents(poll_obj_t *poll_obj, mp_uint_t revents) #endif -STATIC void poll_set_add_obj(poll_set_t *poll_set, const mp_obj_t *obj, mp_uint_t obj_len, mp_uint_t events, bool or_events) { +static void poll_set_add_obj(poll_set_t *poll_set, const mp_obj_t *obj, mp_uint_t obj_len, mp_uint_t events, bool or_events) { for (mp_uint_t i = 0; i < obj_len; i++) { mp_map_elem_t *elem = mp_map_lookup(&poll_set->map, mp_obj_id(obj[i]), MP_MAP_LOOKUP_ADD_IF_NOT_FOUND); if (elem->value == MP_OBJ_NULL) { @@ -290,7 +290,7 @@ STATIC void poll_set_add_obj(poll_set_t *poll_set, const mp_obj_t *obj, mp_uint_ } // For each object in the poll set, poll it once. -STATIC mp_uint_t poll_set_poll_once(poll_set_t *poll_set, size_t *rwx_num) { +static mp_uint_t poll_set_poll_once(poll_set_t *poll_set, size_t *rwx_num) { mp_uint_t n_ready = 0; for (mp_uint_t i = 0; i < poll_set->map.alloc; ++i) { if (!mp_map_slot_is_filled(&poll_set->map, i)) { @@ -338,7 +338,7 @@ STATIC mp_uint_t poll_set_poll_once(poll_set_t *poll_set, size_t *rwx_num) { return n_ready; } -STATIC mp_uint_t poll_set_poll_until_ready_or_timeout(poll_set_t *poll_set, size_t *rwx_num, mp_uint_t timeout) { +static mp_uint_t poll_set_poll_until_ready_or_timeout(poll_set_t *poll_set, size_t *rwx_num, mp_uint_t timeout) { mp_uint_t start_ticks = mp_hal_ticks_ms(); bool has_timeout = timeout != (mp_uint_t)-1; @@ -414,7 +414,7 @@ STATIC mp_uint_t poll_set_poll_until_ready_or_timeout(poll_set_t *poll_set, size #if MICROPY_PY_SELECT_SELECT // select(rlist, wlist, xlist[, timeout]) -STATIC mp_obj_t select_select(size_t n_args, const mp_obj_t *args) { +static mp_obj_t select_select(size_t n_args, const mp_obj_t *args) { // get array data from tuple/list arguments size_t rwx_len[3]; mp_obj_t *r_array, *w_array, *x_array; @@ -486,7 +486,7 @@ typedef struct _mp_obj_poll_t { } mp_obj_poll_t; // register(obj[, eventmask]) -STATIC mp_obj_t poll_register(size_t n_args, const mp_obj_t *args) { +static mp_obj_t poll_register(size_t n_args, const mp_obj_t *args) { mp_obj_poll_t *self = MP_OBJ_TO_PTR(args[0]); mp_uint_t events; if (n_args == 3) { @@ -500,7 +500,7 @@ STATIC mp_obj_t poll_register(size_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(poll_register_obj, 2, 3, poll_register); // unregister(obj) -STATIC mp_obj_t poll_unregister(mp_obj_t self_in, mp_obj_t obj_in) { +static mp_obj_t poll_unregister(mp_obj_t self_in, mp_obj_t obj_in) { mp_obj_poll_t *self = MP_OBJ_TO_PTR(self_in); mp_map_elem_t *elem = mp_map_lookup(&self->poll_set.map, mp_obj_id(obj_in), MP_MAP_LOOKUP_REMOVE_IF_FOUND); @@ -523,7 +523,7 @@ STATIC mp_obj_t poll_unregister(mp_obj_t self_in, mp_obj_t obj_in) { MP_DEFINE_CONST_FUN_OBJ_2(poll_unregister_obj, poll_unregister); // modify(obj, eventmask) -STATIC mp_obj_t poll_modify(mp_obj_t self_in, mp_obj_t obj_in, mp_obj_t eventmask_in) { +static mp_obj_t poll_modify(mp_obj_t self_in, mp_obj_t obj_in, mp_obj_t eventmask_in) { mp_obj_poll_t *self = MP_OBJ_TO_PTR(self_in); mp_map_elem_t *elem = mp_map_lookup(&self->poll_set.map, mp_obj_id(obj_in), MP_MAP_LOOKUP); if (elem == NULL) { @@ -534,7 +534,7 @@ STATIC mp_obj_t poll_modify(mp_obj_t self_in, mp_obj_t obj_in, mp_obj_t eventmas } MP_DEFINE_CONST_FUN_OBJ_3(poll_modify_obj, poll_modify); -STATIC mp_uint_t poll_poll_internal(uint n_args, const mp_obj_t *args) { +static mp_uint_t poll_poll_internal(uint n_args, const mp_obj_t *args) { mp_obj_poll_t *self = MP_OBJ_TO_PTR(args[0]); // work out timeout (its given already in ms) @@ -557,7 +557,7 @@ STATIC mp_uint_t poll_poll_internal(uint n_args, const mp_obj_t *args) { return poll_set_poll_until_ready_or_timeout(&self->poll_set, NULL, timeout); } -STATIC mp_obj_t poll_poll(size_t n_args, const mp_obj_t *args) { +static mp_obj_t poll_poll(size_t n_args, const mp_obj_t *args) { mp_obj_poll_t *self = MP_OBJ_TO_PTR(args[0]); mp_uint_t n_ready = poll_poll_internal(n_args, args); @@ -578,7 +578,7 @@ STATIC mp_obj_t poll_poll(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(poll_poll_obj, 1, 2, poll_poll); -STATIC mp_obj_t poll_ipoll(size_t n_args, const mp_obj_t *args) { +static mp_obj_t poll_ipoll(size_t n_args, const mp_obj_t *args) { mp_obj_poll_t *self = MP_OBJ_TO_PTR(args[0]); if (self->ret_tuple == MP_OBJ_NULL) { @@ -593,7 +593,7 @@ STATIC mp_obj_t poll_ipoll(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(poll_ipoll_obj, 1, 3, poll_ipoll); -STATIC mp_obj_t poll_iternext(mp_obj_t self_in) { +static mp_obj_t poll_iternext(mp_obj_t self_in) { mp_obj_poll_t *self = MP_OBJ_TO_PTR(self_in); if (self->iter_cnt == 0) { @@ -625,16 +625,16 @@ STATIC mp_obj_t poll_iternext(mp_obj_t self_in) { return MP_OBJ_STOP_ITERATION; } -STATIC const mp_rom_map_elem_t poll_locals_dict_table[] = { +static const mp_rom_map_elem_t poll_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_register), MP_ROM_PTR(&poll_register_obj) }, { MP_ROM_QSTR(MP_QSTR_unregister), MP_ROM_PTR(&poll_unregister_obj) }, { MP_ROM_QSTR(MP_QSTR_modify), MP_ROM_PTR(&poll_modify_obj) }, { MP_ROM_QSTR(MP_QSTR_poll), MP_ROM_PTR(&poll_poll_obj) }, { MP_ROM_QSTR(MP_QSTR_ipoll), MP_ROM_PTR(&poll_ipoll_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(poll_locals_dict, poll_locals_dict_table); +static MP_DEFINE_CONST_DICT(poll_locals_dict, poll_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_poll, MP_QSTR_poll, MP_TYPE_FLAG_ITER_IS_ITERNEXT, @@ -643,7 +643,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); // poll() -STATIC mp_obj_t select_poll(void) { +static mp_obj_t select_poll(void) { mp_obj_poll_t *poll = mp_obj_malloc(mp_obj_poll_t, &mp_type_poll); poll_set_init(&poll->poll_set, 0); poll->iter_cnt = 0; @@ -652,7 +652,7 @@ STATIC mp_obj_t select_poll(void) { } MP_DEFINE_CONST_FUN_OBJ_0(mp_select_poll_obj, select_poll); -STATIC const mp_rom_map_elem_t mp_module_select_globals_table[] = { +static const mp_rom_map_elem_t mp_module_select_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_select) }, #if MICROPY_PY_SELECT_SELECT { MP_ROM_QSTR(MP_QSTR_select), MP_ROM_PTR(&mp_select_select_obj) }, @@ -664,7 +664,7 @@ STATIC const mp_rom_map_elem_t mp_module_select_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_POLLHUP), MP_ROM_INT(MP_STREAM_POLL_HUP) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_select_globals, mp_module_select_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_select_globals, mp_module_select_globals_table); const mp_obj_module_t mp_module_select = { .base = { &mp_type_module }, diff --git a/extmod/modsocket.c b/extmod/modsocket.c index 4a857fb62e6ff..eedc17b2ffcb6 100644 --- a/extmod/modsocket.c +++ b/extmod/modsocket.c @@ -41,16 +41,16 @@ /******************************************************************************/ // socket class -STATIC const mp_obj_type_t socket_type; +static const mp_obj_type_t socket_type; -STATIC void socket_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void socket_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", self->fileno, self->timeout, self->domain, self->type, self->proto, self->bound); } // constructor socket(domain=AF_INET, type=SOCK_STREAM, proto=0) -STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 3, false); // create socket object (not bound to any NIC yet) @@ -81,7 +81,7 @@ STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t return MP_OBJ_FROM_PTR(s); } -STATIC void socket_select_nic(mod_network_socket_obj_t *self, const byte *ip) { +static void socket_select_nic(mod_network_socket_obj_t *self, const byte *ip) { if (self->nic == MP_OBJ_NULL) { // select NIC based on IP self->nic = mod_network_find_nic(ip); @@ -103,7 +103,7 @@ STATIC void socket_select_nic(mod_network_socket_obj_t *self, const byte *ip) { } // method socket.bind(address) -STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { +static mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in); // get address @@ -121,10 +121,10 @@ STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind); // method socket.listen([backlog]) -STATIC mp_obj_t socket_listen(size_t n_args, const mp_obj_t *args) { +static mp_obj_t socket_listen(size_t n_args, const mp_obj_t *args) { mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (self->nic == MP_OBJ_NULL) { @@ -149,10 +149,10 @@ STATIC mp_obj_t socket_listen(size_t n_args, const mp_obj_t *args) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_listen_obj, 1, 2, socket_listen); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_listen_obj, 1, 2, socket_listen); // method socket.accept() -STATIC mp_obj_t socket_accept(mp_obj_t self_in) { +static mp_obj_t socket_accept(mp_obj_t self_in) { mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in); if (self->nic == MP_OBJ_NULL) { @@ -198,10 +198,10 @@ STATIC mp_obj_t socket_accept(mp_obj_t self_in) { return MP_OBJ_FROM_PTR(client); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_accept_obj, socket_accept); +static MP_DEFINE_CONST_FUN_OBJ_1(socket_accept_obj, socket_accept); // method socket.connect(address) -STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { +static mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in); // get address @@ -222,10 +222,10 @@ STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect); // method socket.send(bytes) -STATIC mp_obj_t socket_send(mp_obj_t self_in, mp_obj_t buf_in) { +static mp_obj_t socket_send(mp_obj_t self_in, mp_obj_t buf_in) { mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in); if (self->nic == MP_OBJ_NULL) { // not connected @@ -240,9 +240,9 @@ STATIC mp_obj_t socket_send(mp_obj_t self_in, mp_obj_t buf_in) { } return mp_obj_new_int_from_uint(ret); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_send_obj, socket_send); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_send_obj, socket_send); -STATIC mp_obj_t socket_sendall(mp_obj_t self_in, mp_obj_t buf_in) { +static mp_obj_t socket_sendall(mp_obj_t self_in, mp_obj_t buf_in) { mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in); if (self->nic == MP_OBJ_NULL) { // not connected @@ -274,10 +274,10 @@ STATIC mp_obj_t socket_sendall(mp_obj_t self_in, mp_obj_t buf_in) { } return mp_obj_new_int_from_uint(ret); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_sendall_obj, socket_sendall); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_sendall_obj, socket_sendall); // method socket.recv(bufsize) -STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) { +static mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) { mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in); if (self->nic == MP_OBJ_NULL) { // not connected @@ -297,10 +297,10 @@ STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) { vstr.len = ret; return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_recv_obj, socket_recv); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_recv_obj, socket_recv); // method socket.sendto(bytes, address) -STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_in) { +static mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_in) { mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in); // get the data @@ -323,10 +323,10 @@ STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_ return mp_obj_new_int(ret); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(socket_sendto_obj, socket_sendto); +static MP_DEFINE_CONST_FUN_OBJ_3(socket_sendto_obj, socket_sendto); // method socket.recvfrom(bufsize) -STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) { +static mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) { mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in); if (self->nic == MP_OBJ_NULL) { // not connected @@ -351,10 +351,10 @@ STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) { tuple[1] = netutils_format_inet_addr(ip, port, NETUTILS_BIG); return mp_obj_new_tuple(2, tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_recvfrom_obj, socket_recvfrom); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_recvfrom_obj, socket_recvfrom); // method socket.setsockopt(level, optname, value) -STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) { +static mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) { mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (self->nic == MP_OBJ_NULL) { @@ -393,19 +393,19 @@ STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_setsockopt_obj, 4, 4, socket_setsockopt); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_setsockopt_obj, 4, 4, socket_setsockopt); -STATIC mp_obj_t socket_makefile(size_t n_args, const mp_obj_t *args) { +static mp_obj_t socket_makefile(size_t n_args, const mp_obj_t *args) { (void)n_args; return args[0]; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_makefile_obj, 1, 3, socket_makefile); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_makefile_obj, 1, 3, socket_makefile); // method socket.settimeout(value) // timeout=0 means non-blocking // timeout=None means blocking // otherwise, timeout is in seconds -STATIC mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) { +static mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) { mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_uint_t timeout; if (timeout_in == mp_const_none) { @@ -433,19 +433,19 @@ STATIC mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_settimeout_obj, socket_settimeout); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_settimeout_obj, socket_settimeout); // method socket.setblocking(flag) -STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t blocking) { +static mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t blocking) { if (mp_obj_is_true(blocking)) { return socket_settimeout(self_in, mp_const_none); } else { return socket_settimeout(self_in, MP_OBJ_NEW_SMALL_INT(0)); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking); -STATIC const mp_rom_map_elem_t socket_locals_dict_table[] = { +static const mp_rom_map_elem_t socket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_stream_close_obj) }, { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) }, { MP_ROM_QSTR(MP_QSTR_bind), MP_ROM_PTR(&socket_bind_obj) }, @@ -468,7 +468,7 @@ STATIC const mp_rom_map_elem_t socket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(socket_locals_dict, socket_locals_dict_table); +static MP_DEFINE_CONST_DICT(socket_locals_dict, socket_locals_dict_table); mp_uint_t socket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in); @@ -520,14 +520,14 @@ mp_uint_t socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int * return self->nic_protocol->ioctl(self, request, arg, errcode); } -STATIC const mp_stream_p_t socket_stream_p = { +static const mp_stream_p_t socket_stream_p = { .read = socket_read, .write = socket_write, .ioctl = socket_ioctl, .is_text = false, }; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( socket_type, MP_QSTR_socket, MP_TYPE_FLAG_NONE, @@ -541,7 +541,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( // socket module // function socket.getaddrinfo(host, port) -STATIC mp_obj_t mod_socket_getaddrinfo(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_socket_getaddrinfo(size_t n_args, const mp_obj_t *args) { size_t hlen; const char *host = mp_obj_str_get_data(args[0], &hlen); mp_int_t port = mp_obj_get_int(args[1]); @@ -611,9 +611,9 @@ STATIC mp_obj_t mod_socket_getaddrinfo(size_t n_args, const mp_obj_t *args) { tuple->items[4] = netutils_format_inet_addr(out_ip, port, NETUTILS_BIG); return mp_obj_new_list(1, (mp_obj_t *)&tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_socket_getaddrinfo_obj, 2, 6, mod_socket_getaddrinfo); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_socket_getaddrinfo_obj, 2, 6, mod_socket_getaddrinfo); -STATIC const mp_rom_map_elem_t mp_module_socket_globals_table[] = { +static const mp_rom_map_elem_t mp_module_socket_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_socket) }, { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&socket_type) }, @@ -645,7 +645,7 @@ STATIC const mp_rom_map_elem_t mp_module_socket_globals_table[] = { */ }; -STATIC MP_DEFINE_CONST_DICT(mp_module_socket_globals, mp_module_socket_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_socket_globals, mp_module_socket_globals_table); const mp_obj_module_t mp_module_socket = { .base = { &mp_type_module }, diff --git a/extmod/modtime.c b/extmod/modtime.c index 805c2621c0b67..deb4bb4c9ace7 100644 --- a/extmod/modtime.c +++ b/extmod/modtime.c @@ -52,7 +52,7 @@ // - second is 0-59 // - weekday is 0-6 for Mon-Sun // - yearday is 1-366 -STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { +static mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { if (n_args == 0 || args[0] == mp_const_none) { // Get current date and time. return mp_time_localtime_get(); @@ -80,7 +80,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_time_localtime_obj, 0, 1, time_localtime) // This is the inverse function of localtime. Its argument is a full 8-tuple // which expresses a time as per localtime. It returns an integer which is // the number of seconds since the Epoch (eg 1st Jan 1970, or 1st Jan 2000). -STATIC mp_obj_t time_mktime(mp_obj_t tuple) { +static mp_obj_t time_mktime(mp_obj_t tuple) { size_t len; mp_obj_t *elem; mp_obj_get_array(tuple, &len, &elem); @@ -102,21 +102,21 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_time_mktime_obj, time_mktime); // time() // Return the number of seconds since the Epoch. -STATIC mp_obj_t time_time(void) { +static mp_obj_t time_time(void) { return mp_time_time_get(); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_time_time_obj, time_time); +static MP_DEFINE_CONST_FUN_OBJ_0(mp_time_time_obj, time_time); // time_ns() // Returns the number of nanoseconds since the Epoch, as an integer. -STATIC mp_obj_t time_time_ns(void) { +static mp_obj_t time_time_ns(void) { return mp_obj_new_int_from_ull(mp_hal_time_ns()); } MP_DEFINE_CONST_FUN_OBJ_0(mp_time_time_ns_obj, time_time_ns); #endif // MICROPY_PY_TIME_TIME_TIME_NS -STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) { +static mp_obj_t time_sleep(mp_obj_t seconds_o) { #ifdef MICROPY_PY_TIME_CUSTOM_SLEEP mp_time_sleep(seconds_o); #else @@ -130,7 +130,7 @@ STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_time_sleep_obj, time_sleep); -STATIC mp_obj_t time_sleep_ms(mp_obj_t arg) { +static mp_obj_t time_sleep_ms(mp_obj_t arg) { mp_int_t ms = mp_obj_get_int(arg); if (ms >= 0) { mp_hal_delay_ms(ms); @@ -139,7 +139,7 @@ STATIC mp_obj_t time_sleep_ms(mp_obj_t arg) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_time_sleep_ms_obj, time_sleep_ms); -STATIC mp_obj_t time_sleep_us(mp_obj_t arg) { +static mp_obj_t time_sleep_us(mp_obj_t arg) { mp_int_t us = mp_obj_get_int(arg); if (us > 0) { mp_hal_delay_us(us); @@ -148,22 +148,22 @@ STATIC mp_obj_t time_sleep_us(mp_obj_t arg) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_time_sleep_us_obj, time_sleep_us); -STATIC mp_obj_t time_ticks_ms(void) { +static mp_obj_t time_ticks_ms(void) { return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & (MICROPY_PY_TIME_TICKS_PERIOD - 1)); } MP_DEFINE_CONST_FUN_OBJ_0(mp_time_ticks_ms_obj, time_ticks_ms); -STATIC mp_obj_t time_ticks_us(void) { +static mp_obj_t time_ticks_us(void) { return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_us() & (MICROPY_PY_TIME_TICKS_PERIOD - 1)); } MP_DEFINE_CONST_FUN_OBJ_0(mp_time_ticks_us_obj, time_ticks_us); -STATIC mp_obj_t time_ticks_cpu(void) { +static mp_obj_t time_ticks_cpu(void) { return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_cpu() & (MICROPY_PY_TIME_TICKS_PERIOD - 1)); } MP_DEFINE_CONST_FUN_OBJ_0(mp_time_ticks_cpu_obj, time_ticks_cpu); -STATIC mp_obj_t time_ticks_diff(mp_obj_t end_in, mp_obj_t start_in) { +static mp_obj_t time_ticks_diff(mp_obj_t end_in, mp_obj_t start_in) { // we assume that the arguments come from ticks_xx so are small ints mp_uint_t start = MP_OBJ_SMALL_INT_VALUE(start_in); mp_uint_t end = MP_OBJ_SMALL_INT_VALUE(end_in); @@ -175,7 +175,7 @@ STATIC mp_obj_t time_ticks_diff(mp_obj_t end_in, mp_obj_t start_in) { } MP_DEFINE_CONST_FUN_OBJ_2(mp_time_ticks_diff_obj, time_ticks_diff); -STATIC mp_obj_t time_ticks_add(mp_obj_t ticks_in, mp_obj_t delta_in) { +static mp_obj_t time_ticks_add(mp_obj_t ticks_in, mp_obj_t delta_in) { // we assume that first argument come from ticks_xx so is small int mp_uint_t ticks = MP_OBJ_SMALL_INT_VALUE(ticks_in); mp_uint_t delta = mp_obj_get_int(delta_in); @@ -196,7 +196,7 @@ STATIC mp_obj_t time_ticks_add(mp_obj_t ticks_in, mp_obj_t delta_in) { } MP_DEFINE_CONST_FUN_OBJ_2(mp_time_ticks_add_obj, time_ticks_add); -STATIC const mp_rom_map_elem_t mp_module_time_globals_table[] = { +static const mp_rom_map_elem_t mp_module_time_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_time) }, #if MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME @@ -224,7 +224,7 @@ STATIC const mp_rom_map_elem_t mp_module_time_globals_table[] = { MICROPY_PY_TIME_EXTRA_GLOBALS #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_time_globals, mp_module_time_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_time_globals, mp_module_time_globals_table); const mp_obj_module_t mp_module_time = { .base = { &mp_type_module }, diff --git a/extmod/modtls_axtls.c b/extmod/modtls_axtls.c index 4f6b06f66d6e2..08a355cddb605 100644 --- a/extmod/modtls_axtls.c +++ b/extmod/modtls_axtls.c @@ -65,23 +65,23 @@ struct ssl_args { mp_arg_val_t do_handshake; }; -STATIC const mp_obj_type_t ssl_context_type; -STATIC const mp_obj_type_t ssl_socket_type; +static const mp_obj_type_t ssl_context_type; +static const mp_obj_type_t ssl_socket_type; -STATIC mp_obj_t ssl_socket_make_new(mp_obj_ssl_context_t *ssl_context, mp_obj_t sock, +static mp_obj_t ssl_socket_make_new(mp_obj_ssl_context_t *ssl_context, mp_obj_t sock, bool server_side, bool do_handshake_on_connect, mp_obj_t server_hostname); /******************************************************************************/ // Helper functions. // Table of error strings corresponding to SSL_xxx error codes. -STATIC const char *const ssl_error_tab1[] = { +static const char *const ssl_error_tab1[] = { "NOT_OK", "DEAD", "CLOSE_NOTIFY", "EAGAIN", }; -STATIC const char *const ssl_error_tab2[] = { +static const char *const ssl_error_tab2[] = { "CONN_LOST", "RECORD_OVERFLOW", "SOCK_SETUP_FAILURE", @@ -103,7 +103,7 @@ STATIC const char *const ssl_error_tab2[] = { "NOT_SUPPORTED", }; -STATIC NORETURN void ssl_raise_error(int err) { +static NORETURN void ssl_raise_error(int err) { MP_STATIC_ASSERT(SSL_NOT_OK - 3 == SSL_EAGAIN); MP_STATIC_ASSERT(SSL_ERROR_CONN_LOST - 18 == SSL_ERROR_NOT_SUPPORTED); @@ -138,7 +138,7 @@ STATIC NORETURN void ssl_raise_error(int err) { /******************************************************************************/ // SSLContext type. -STATIC mp_obj_t ssl_context_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t ssl_context_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 1, false); // The "protocol" argument is ignored in this implementation. @@ -155,20 +155,20 @@ STATIC mp_obj_t ssl_context_make_new(const mp_obj_type_t *type_in, size_t n_args return MP_OBJ_FROM_PTR(self); } -STATIC void ssl_context_load_key(mp_obj_ssl_context_t *self, mp_obj_t key_obj, mp_obj_t cert_obj) { +static void ssl_context_load_key(mp_obj_ssl_context_t *self, mp_obj_t key_obj, mp_obj_t cert_obj) { self->key = key_obj; self->cert = cert_obj; } // SSLContext.load_cert_chain(certfile, keyfile) -STATIC mp_obj_t ssl_context_load_cert_chain(mp_obj_t self_in, mp_obj_t cert, mp_obj_t pkey) { +static mp_obj_t ssl_context_load_cert_chain(mp_obj_t self_in, mp_obj_t cert, mp_obj_t pkey) { mp_obj_ssl_context_t *self = MP_OBJ_TO_PTR(self_in); ssl_context_load_key(self, pkey, cert); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(ssl_context_load_cert_chain_obj, ssl_context_load_cert_chain); +static MP_DEFINE_CONST_FUN_OBJ_3(ssl_context_load_cert_chain_obj, ssl_context_load_cert_chain); -STATIC mp_obj_t ssl_context_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t ssl_context_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_server_side, ARG_do_handshake_on_connect, ARG_server_hostname }; static const mp_arg_t allowed_args[] = { { MP_QSTR_server_side, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, @@ -186,15 +186,15 @@ STATIC mp_obj_t ssl_context_wrap_socket(size_t n_args, const mp_obj_t *pos_args, return ssl_socket_make_new(self, sock, args[ARG_server_side].u_bool, args[ARG_do_handshake_on_connect].u_bool, args[ARG_server_hostname].u_obj); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ssl_context_wrap_socket_obj, 2, ssl_context_wrap_socket); +static MP_DEFINE_CONST_FUN_OBJ_KW(ssl_context_wrap_socket_obj, 2, ssl_context_wrap_socket); -STATIC const mp_rom_map_elem_t ssl_context_locals_dict_table[] = { +static const mp_rom_map_elem_t ssl_context_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_load_cert_chain), MP_ROM_PTR(&ssl_context_load_cert_chain_obj)}, { MP_ROM_QSTR(MP_QSTR_wrap_socket), MP_ROM_PTR(&ssl_context_wrap_socket_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(ssl_context_locals_dict, ssl_context_locals_dict_table); +static MP_DEFINE_CONST_DICT(ssl_context_locals_dict, ssl_context_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( ssl_context_type, MP_QSTR_SSLContext, MP_TYPE_FLAG_NONE, @@ -205,7 +205,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( /******************************************************************************/ // SSLSocket type. -STATIC mp_obj_t ssl_socket_make_new(mp_obj_ssl_context_t *ssl_context, mp_obj_t sock, +static mp_obj_t ssl_socket_make_new(mp_obj_ssl_context_t *ssl_context, mp_obj_t sock, bool server_side, bool do_handshake_on_connect, mp_obj_t server_hostname) { #if MICROPY_PY_SSL_FINALISER @@ -276,7 +276,7 @@ STATIC mp_obj_t ssl_socket_make_new(mp_obj_ssl_context_t *ssl_context, mp_obj_t return o; } -STATIC mp_uint_t ssl_socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t ssl_socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(o_in); if (o->ssl_sock == NULL) { @@ -325,7 +325,7 @@ STATIC mp_uint_t ssl_socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int * return size; } -STATIC mp_uint_t ssl_socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t ssl_socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) { mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(o_in); if (o->ssl_sock == NULL) { @@ -357,7 +357,7 @@ STATIC mp_uint_t ssl_socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size return r; } -STATIC mp_uint_t ssl_socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t ssl_socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { mp_obj_ssl_socket_t *self = MP_OBJ_TO_PTR(o_in); if (request == MP_STREAM_CLOSE) { if (self->ssl_sock == NULL) { @@ -378,7 +378,7 @@ STATIC mp_uint_t ssl_socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t ar return mp_get_stream(self->sock)->ioctl(self->sock, request, arg, errcode); } -STATIC mp_obj_t ssl_socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) { +static mp_obj_t ssl_socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) { mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(self_in); mp_obj_t sock = o->sock; mp_obj_t dest[3]; @@ -388,9 +388,9 @@ STATIC mp_obj_t ssl_socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) { o->blocking = mp_obj_is_true(flag_in); return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(ssl_socket_setblocking_obj, ssl_socket_setblocking); +static MP_DEFINE_CONST_FUN_OBJ_2(ssl_socket_setblocking_obj, ssl_socket_setblocking); -STATIC const mp_rom_map_elem_t ssl_socket_locals_dict_table[] = { +static const mp_rom_map_elem_t ssl_socket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) }, { MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) }, @@ -401,15 +401,15 @@ STATIC const mp_rom_map_elem_t ssl_socket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_stream_close_obj) }, #endif }; -STATIC MP_DEFINE_CONST_DICT(ssl_socket_locals_dict, ssl_socket_locals_dict_table); +static MP_DEFINE_CONST_DICT(ssl_socket_locals_dict, ssl_socket_locals_dict_table); -STATIC const mp_stream_p_t ssl_socket_stream_p = { +static const mp_stream_p_t ssl_socket_stream_p = { .read = ssl_socket_read, .write = ssl_socket_write, .ioctl = ssl_socket_ioctl, }; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( ssl_socket_type, MP_QSTR_SSLSocket, MP_TYPE_FLAG_NONE, @@ -420,7 +420,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( /******************************************************************************/ // ssl module. -STATIC const mp_rom_map_elem_t mp_module_tls_globals_table[] = { +static const mp_rom_map_elem_t mp_module_tls_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_tls) }, // Classes. @@ -430,7 +430,7 @@ STATIC const mp_rom_map_elem_t mp_module_tls_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_PROTOCOL_TLS_CLIENT), MP_ROM_INT(PROTOCOL_TLS_CLIENT) }, { MP_ROM_QSTR(MP_QSTR_PROTOCOL_TLS_SERVER), MP_ROM_INT(PROTOCOL_TLS_SERVER) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_tls_globals, mp_module_tls_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_tls_globals, mp_module_tls_globals_table); const mp_obj_module_t mp_module_tls = { .base = { &mp_type_module }, diff --git a/extmod/modtls_mbedtls.c b/extmod/modtls_mbedtls.c index 4d0ccd2c0e794..6db6ac1958dd2 100644 --- a/extmod/modtls_mbedtls.c +++ b/extmod/modtls_mbedtls.c @@ -81,26 +81,26 @@ typedef struct _mp_obj_ssl_socket_t { int last_error; // The last error code, if any } mp_obj_ssl_socket_t; -STATIC const mp_obj_type_t ssl_context_type; -STATIC const mp_obj_type_t ssl_socket_type; +static const mp_obj_type_t ssl_context_type; +static const mp_obj_type_t ssl_socket_type; -STATIC const MP_DEFINE_STR_OBJ(mbedtls_version_obj, MBEDTLS_VERSION_STRING_FULL); +static const MP_DEFINE_STR_OBJ(mbedtls_version_obj, MBEDTLS_VERSION_STRING_FULL); -STATIC mp_obj_t ssl_socket_make_new(mp_obj_ssl_context_t *ssl_context, mp_obj_t sock, +static mp_obj_t ssl_socket_make_new(mp_obj_ssl_context_t *ssl_context, mp_obj_t sock, bool server_side, bool do_handshake_on_connect, mp_obj_t server_hostname); /******************************************************************************/ // Helper functions. #ifdef MBEDTLS_DEBUG_C -STATIC void mbedtls_debug(void *ctx, int level, const char *file, int line, const char *str) { +static void mbedtls_debug(void *ctx, int level, const char *file, int line, const char *str) { (void)ctx; (void)level; mp_printf(&mp_plat_print, "DBG:%s:%04d: %s\n", file, line, str); } #endif -STATIC NORETURN void mbedtls_raise_error(int err) { +static NORETURN void mbedtls_raise_error(int err) { // Handle special cases. if (err == MBEDTLS_ERR_SSL_ALLOC_FAILED) { mp_raise_OSError(MP_ENOMEM); @@ -149,7 +149,7 @@ STATIC NORETURN void mbedtls_raise_error(int err) { #endif } -STATIC void ssl_check_async_handshake_failure(mp_obj_ssl_socket_t *sslsock, int *errcode) { +static void ssl_check_async_handshake_failure(mp_obj_ssl_socket_t *sslsock, int *errcode) { if ( #if MBEDTLS_VERSION_NUMBER >= 0x03000000 (*errcode < 0) && (mbedtls_ssl_is_handshake_over(&sslsock->ssl) == 0) && (*errcode != MBEDTLS_ERR_SSL_CONN_EOF) @@ -189,7 +189,7 @@ STATIC void ssl_check_async_handshake_failure(mp_obj_ssl_socket_t *sslsock, int } } -STATIC int ssl_sock_cert_verify(void *ptr, mbedtls_x509_crt *crt, int depth, uint32_t *flags) { +static int ssl_sock_cert_verify(void *ptr, mbedtls_x509_crt *crt, int depth, uint32_t *flags) { mp_obj_ssl_context_t *o = ptr; if (o->handler == mp_const_none) { return 0; @@ -202,7 +202,7 @@ STATIC int ssl_sock_cert_verify(void *ptr, mbedtls_x509_crt *crt, int depth, uin /******************************************************************************/ // SSLContext type. -STATIC mp_obj_t ssl_context_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t ssl_context_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 1, false); // This is the "protocol" argument. @@ -263,7 +263,7 @@ STATIC mp_obj_t ssl_context_make_new(const mp_obj_type_t *type_in, size_t n_args return MP_OBJ_FROM_PTR(self); } -STATIC void ssl_context_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void ssl_context_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { mp_obj_ssl_context_t *self = MP_OBJ_TO_PTR(self_in); if (dest[0] == MP_OBJ_NULL) { // Load attribute. @@ -289,7 +289,7 @@ STATIC void ssl_context_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } #if MICROPY_PY_SSL_FINALISER -STATIC mp_obj_t ssl_context___del__(mp_obj_t self_in) { +static mp_obj_t ssl_context___del__(mp_obj_t self_in) { mp_obj_ssl_context_t *self = MP_OBJ_TO_PTR(self_in); mbedtls_pk_free(&self->pkey); mbedtls_x509_crt_free(&self->cert); @@ -299,11 +299,11 @@ STATIC mp_obj_t ssl_context___del__(mp_obj_t self_in) { mbedtls_ssl_config_free(&self->conf); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(ssl_context___del___obj, ssl_context___del__); +static MP_DEFINE_CONST_FUN_OBJ_1(ssl_context___del___obj, ssl_context___del__); #endif // SSLContext.get_ciphers() -STATIC mp_obj_t ssl_context_get_ciphers(mp_obj_t self_in) { +static mp_obj_t ssl_context_get_ciphers(mp_obj_t self_in) { mp_obj_t list = mp_obj_new_list(0, NULL); for (const int *cipher_list = mbedtls_ssl_list_ciphersuites(); *cipher_list; ++cipher_list) { const char *cipher_name = mbedtls_ssl_get_ciphersuite_name(*cipher_list); @@ -311,10 +311,10 @@ STATIC mp_obj_t ssl_context_get_ciphers(mp_obj_t self_in) { } return list; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(ssl_context_get_ciphers_obj, ssl_context_get_ciphers); +static MP_DEFINE_CONST_FUN_OBJ_1(ssl_context_get_ciphers_obj, ssl_context_get_ciphers); // SSLContext.set_ciphers(ciphersuite) -STATIC mp_obj_t ssl_context_set_ciphers(mp_obj_t self_in, mp_obj_t ciphersuite) { +static mp_obj_t ssl_context_set_ciphers(mp_obj_t self_in, mp_obj_t ciphersuite) { mp_obj_ssl_context_t *ssl_context = MP_OBJ_TO_PTR(self_in); // Check that ciphersuite is a list or tuple. @@ -342,9 +342,9 @@ STATIC mp_obj_t ssl_context_set_ciphers(mp_obj_t self_in, mp_obj_t ciphersuite) return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(ssl_context_set_ciphers_obj, ssl_context_set_ciphers); +static MP_DEFINE_CONST_FUN_OBJ_2(ssl_context_set_ciphers_obj, ssl_context_set_ciphers); -STATIC void ssl_context_load_key(mp_obj_ssl_context_t *self, mp_obj_t key_obj, mp_obj_t cert_obj) { +static void ssl_context_load_key(mp_obj_ssl_context_t *self, mp_obj_t key_obj, mp_obj_t cert_obj) { size_t key_len; const byte *key = (const byte *)mp_obj_str_get_data(key_obj, &key_len); // len should include terminating null @@ -373,14 +373,14 @@ STATIC void ssl_context_load_key(mp_obj_ssl_context_t *self, mp_obj_t key_obj, m } // SSLContext.load_cert_chain(certfile, keyfile) -STATIC mp_obj_t ssl_context_load_cert_chain(mp_obj_t self_in, mp_obj_t cert, mp_obj_t pkey) { +static mp_obj_t ssl_context_load_cert_chain(mp_obj_t self_in, mp_obj_t cert, mp_obj_t pkey) { mp_obj_ssl_context_t *self = MP_OBJ_TO_PTR(self_in); ssl_context_load_key(self, pkey, cert); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(ssl_context_load_cert_chain_obj, ssl_context_load_cert_chain); +static MP_DEFINE_CONST_FUN_OBJ_3(ssl_context_load_cert_chain_obj, ssl_context_load_cert_chain); -STATIC void ssl_context_load_cadata(mp_obj_ssl_context_t *self, mp_obj_t cadata_obj) { +static void ssl_context_load_cadata(mp_obj_ssl_context_t *self, mp_obj_t cadata_obj) { size_t cacert_len; const byte *cacert = (const byte *)mp_obj_str_get_data(cadata_obj, &cacert_len); // len should include terminating null @@ -393,15 +393,15 @@ STATIC void ssl_context_load_cadata(mp_obj_ssl_context_t *self, mp_obj_t cadata_ } // SSLContext.load_verify_locations(cadata) -STATIC mp_obj_t ssl_context_load_verify_locations(mp_obj_t self_in, mp_obj_t cadata) { +static mp_obj_t ssl_context_load_verify_locations(mp_obj_t self_in, mp_obj_t cadata) { mp_obj_ssl_context_t *self = MP_OBJ_TO_PTR(self_in); ssl_context_load_cadata(self, cadata); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(ssl_context_load_verify_locations_obj, ssl_context_load_verify_locations); +static MP_DEFINE_CONST_FUN_OBJ_2(ssl_context_load_verify_locations_obj, ssl_context_load_verify_locations); -STATIC mp_obj_t ssl_context_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t ssl_context_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_server_side, ARG_do_handshake_on_connect, ARG_server_hostname }; static const mp_arg_t allowed_args[] = { { MP_QSTR_server_side, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, @@ -419,9 +419,9 @@ STATIC mp_obj_t ssl_context_wrap_socket(size_t n_args, const mp_obj_t *pos_args, return ssl_socket_make_new(self, sock, args[ARG_server_side].u_bool, args[ARG_do_handshake_on_connect].u_bool, args[ARG_server_hostname].u_obj); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ssl_context_wrap_socket_obj, 2, ssl_context_wrap_socket); +static MP_DEFINE_CONST_FUN_OBJ_KW(ssl_context_wrap_socket_obj, 2, ssl_context_wrap_socket); -STATIC const mp_rom_map_elem_t ssl_context_locals_dict_table[] = { +static const mp_rom_map_elem_t ssl_context_locals_dict_table[] = { #if MICROPY_PY_SSL_FINALISER { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&ssl_context___del___obj) }, #endif @@ -431,9 +431,9 @@ STATIC const mp_rom_map_elem_t ssl_context_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_load_verify_locations), MP_ROM_PTR(&ssl_context_load_verify_locations_obj)}, { MP_ROM_QSTR(MP_QSTR_wrap_socket), MP_ROM_PTR(&ssl_context_wrap_socket_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(ssl_context_locals_dict, ssl_context_locals_dict_table); +static MP_DEFINE_CONST_DICT(ssl_context_locals_dict, ssl_context_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( ssl_context_type, MP_QSTR_SSLContext, MP_TYPE_FLAG_NONE, @@ -445,7 +445,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( /******************************************************************************/ // SSLSocket type. -STATIC int _mbedtls_ssl_send(void *ctx, const byte *buf, size_t len) { +static int _mbedtls_ssl_send(void *ctx, const byte *buf, size_t len) { mp_obj_t sock = *(mp_obj_t *)ctx; const mp_stream_p_t *sock_stream = mp_get_stream(sock); @@ -463,7 +463,7 @@ STATIC int _mbedtls_ssl_send(void *ctx, const byte *buf, size_t len) { } // _mbedtls_ssl_recv is called by mbedtls to receive bytes from the underlying socket -STATIC int _mbedtls_ssl_recv(void *ctx, byte *buf, size_t len) { +static int _mbedtls_ssl_recv(void *ctx, byte *buf, size_t len) { mp_obj_t sock = *(mp_obj_t *)ctx; const mp_stream_p_t *sock_stream = mp_get_stream(sock); @@ -480,7 +480,7 @@ STATIC int _mbedtls_ssl_recv(void *ctx, byte *buf, size_t len) { } } -STATIC mp_obj_t ssl_socket_make_new(mp_obj_ssl_context_t *ssl_context, mp_obj_t sock, +static mp_obj_t ssl_socket_make_new(mp_obj_ssl_context_t *ssl_context, mp_obj_t sock, bool server_side, bool do_handshake_on_connect, mp_obj_t server_hostname) { // Verify the socket object has the full stream protocol @@ -554,7 +554,7 @@ STATIC mp_obj_t ssl_socket_make_new(mp_obj_ssl_context_t *ssl_context, mp_obj_t } #if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE) -STATIC mp_obj_t mod_ssl_getpeercert(mp_obj_t o_in, mp_obj_t binary_form) { +static mp_obj_t mod_ssl_getpeercert(mp_obj_t o_in, mp_obj_t binary_form) { mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(o_in); if (!mp_obj_is_true(binary_form)) { mp_raise_NotImplementedError(NULL); @@ -565,10 +565,10 @@ STATIC mp_obj_t mod_ssl_getpeercert(mp_obj_t o_in, mp_obj_t binary_form) { } return mp_obj_new_bytes(peer_cert->raw.p, peer_cert->raw.len); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_ssl_getpeercert_obj, mod_ssl_getpeercert); +static MP_DEFINE_CONST_FUN_OBJ_2(mod_ssl_getpeercert_obj, mod_ssl_getpeercert); #endif -STATIC mp_obj_t mod_ssl_cipher(mp_obj_t o_in) { +static mp_obj_t mod_ssl_cipher(mp_obj_t o_in) { mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(o_in); const char *cipher_suite = mbedtls_ssl_get_ciphersuite(&o->ssl); const char *tls_version = mbedtls_ssl_get_version(&o->ssl); @@ -577,9 +577,9 @@ STATIC mp_obj_t mod_ssl_cipher(mp_obj_t o_in) { return mp_obj_new_tuple(2, tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ssl_cipher_obj, mod_ssl_cipher); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_ssl_cipher_obj, mod_ssl_cipher); -STATIC mp_uint_t socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(o_in); o->poll_mask = 0; @@ -620,7 +620,7 @@ STATIC mp_uint_t socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errc return MP_STREAM_ERROR; } -STATIC mp_uint_t socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) { mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(o_in); o->poll_mask = 0; @@ -649,7 +649,7 @@ STATIC mp_uint_t socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, in return MP_STREAM_ERROR; } -STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) { +static mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) { mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(self_in); mp_obj_t sock = o->sock; mp_obj_t dest[3]; @@ -657,9 +657,9 @@ STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) { dest[2] = flag_in; return mp_call_method_n_kw(1, 0, dest); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking); -STATIC mp_uint_t socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { mp_obj_ssl_socket_t *self = MP_OBJ_TO_PTR(o_in); mp_uint_t ret = 0; uintptr_t saved_arg = 0; @@ -716,7 +716,7 @@ STATIC mp_uint_t socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, i return ret; } -STATIC const mp_rom_map_elem_t ssl_socket_locals_dict_table[] = { +static const mp_rom_map_elem_t ssl_socket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) }, { MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) }, @@ -734,15 +734,15 @@ STATIC const mp_rom_map_elem_t ssl_socket_locals_dict_table[] = { #endif { MP_ROM_QSTR(MP_QSTR_cipher), MP_ROM_PTR(&mod_ssl_cipher_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(ssl_socket_locals_dict, ssl_socket_locals_dict_table); +static MP_DEFINE_CONST_DICT(ssl_socket_locals_dict, ssl_socket_locals_dict_table); -STATIC const mp_stream_p_t ssl_socket_stream_p = { +static const mp_stream_p_t ssl_socket_stream_p = { .read = socket_read, .write = socket_write, .ioctl = socket_ioctl, }; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( ssl_socket_type, MP_QSTR_SSLSocket, MP_TYPE_FLAG_NONE, @@ -753,7 +753,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( /******************************************************************************/ // ssl module. -STATIC const mp_rom_map_elem_t mp_module_tls_globals_table[] = { +static const mp_rom_map_elem_t mp_module_tls_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_tls) }, // Classes. @@ -767,7 +767,7 @@ STATIC const mp_rom_map_elem_t mp_module_tls_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_CERT_OPTIONAL), MP_ROM_INT(MBEDTLS_SSL_VERIFY_OPTIONAL) }, { MP_ROM_QSTR(MP_QSTR_CERT_REQUIRED), MP_ROM_INT(MBEDTLS_SSL_VERIFY_REQUIRED) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_tls_globals, mp_module_tls_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_tls_globals, mp_module_tls_globals_table); const mp_obj_module_t mp_module_tls = { .base = { &mp_type_module }, diff --git a/extmod/moductypes.c b/extmod/moductypes.c index f56567107df7e..fa743eb637374 100644 --- a/extmod/moductypes.c +++ b/extmod/moductypes.c @@ -80,7 +80,7 @@ enum { #define IS_SCALAR_ARRAY_OF_BYTES(tuple_desc) (GET_TYPE(MP_OBJ_SMALL_INT_VALUE((tuple_desc)->items[1]), VAL_TYPE_BITS) == UINT8) // "struct" in uctypes context means "structural", i.e. aggregate, type. -STATIC const mp_obj_type_t uctypes_struct_type; +static const mp_obj_type_t uctypes_struct_type; typedef struct _mp_obj_uctypes_struct_t { mp_obj_base_t base; @@ -89,11 +89,11 @@ typedef struct _mp_obj_uctypes_struct_t { uint32_t flags; } mp_obj_uctypes_struct_t; -STATIC NORETURN void syntax_error(void) { +static NORETURN void syntax_error(void) { mp_raise_TypeError(MP_ERROR_TEXT("syntax error in uctypes descriptor")); } -STATIC mp_obj_t uctypes_struct_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t uctypes_struct_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 2, 3, false); mp_obj_uctypes_struct_t *o = mp_obj_malloc(mp_obj_uctypes_struct_t, type); o->addr = (void *)(uintptr_t)mp_obj_get_int_truncated(args[0]); @@ -105,7 +105,7 @@ STATIC mp_obj_t uctypes_struct_make_new(const mp_obj_type_t *type, size_t n_args return MP_OBJ_FROM_PTR(o); } -STATIC void uctypes_struct_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void uctypes_struct_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in); const char *typen = "unk"; @@ -130,7 +130,7 @@ STATIC void uctypes_struct_print(const mp_print_t *print, mp_obj_t self_in, mp_p } // Get size of any type descriptor -STATIC mp_uint_t uctypes_struct_size(mp_obj_t desc_in, int layout_type, mp_uint_t *max_field_size); +static mp_uint_t uctypes_struct_size(mp_obj_t desc_in, int layout_type, mp_uint_t *max_field_size); // Get size of scalar type descriptor static inline mp_uint_t uctypes_struct_scalar_size(int val_type) { @@ -142,7 +142,7 @@ static inline mp_uint_t uctypes_struct_scalar_size(int val_type) { } // Get size of aggregate type descriptor -STATIC mp_uint_t uctypes_struct_agg_size(mp_obj_tuple_t *t, int layout_type, mp_uint_t *max_field_size) { +static mp_uint_t uctypes_struct_agg_size(mp_obj_tuple_t *t, int layout_type, mp_uint_t *max_field_size) { mp_uint_t total_size = 0; mp_int_t offset_ = MP_OBJ_SMALL_INT_VALUE(t->items[0]); @@ -181,7 +181,7 @@ STATIC mp_uint_t uctypes_struct_agg_size(mp_obj_tuple_t *t, int layout_type, mp_ return total_size; } -STATIC mp_uint_t uctypes_struct_size(mp_obj_t desc_in, int layout_type, mp_uint_t *max_field_size) { +static mp_uint_t uctypes_struct_size(mp_obj_t desc_in, int layout_type, mp_uint_t *max_field_size) { if (!mp_obj_is_dict_or_ordereddict(desc_in)) { if (mp_obj_is_type(desc_in, &mp_type_tuple)) { return uctypes_struct_agg_size((mp_obj_tuple_t *)MP_OBJ_TO_PTR(desc_in), layout_type, max_field_size); @@ -237,7 +237,7 @@ STATIC mp_uint_t uctypes_struct_size(mp_obj_t desc_in, int layout_type, mp_uint_ return total_size; } -STATIC mp_obj_t uctypes_struct_sizeof(size_t n_args, const mp_obj_t *args) { +static mp_obj_t uctypes_struct_sizeof(size_t n_args, const mp_obj_t *args) { mp_obj_t obj_in = args[0]; mp_uint_t max_field_size = 0; if (mp_obj_is_type(obj_in, &mp_type_bytearray)) { @@ -262,7 +262,7 @@ STATIC mp_obj_t uctypes_struct_sizeof(size_t n_args, const mp_obj_t *args) { mp_uint_t size = uctypes_struct_size(obj_in, layout_type, &max_field_size); return MP_OBJ_NEW_SMALL_INT(size); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(uctypes_struct_sizeof_obj, 1, 2, uctypes_struct_sizeof); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(uctypes_struct_sizeof_obj, 1, 2, uctypes_struct_sizeof); static inline mp_obj_t get_unaligned(uint val_type, byte *p, int big_endian) { char struct_type = big_endian ? '>' : '<'; @@ -304,7 +304,7 @@ static inline void set_aligned_basic(uint val_type, void *p, mp_uint_t v) { assert(0); } -STATIC mp_obj_t get_aligned(uint val_type, void *p, mp_int_t index) { +static mp_obj_t get_aligned(uint val_type, void *p, mp_int_t index) { switch (val_type) { case UINT8: return MP_OBJ_NEW_SMALL_INT(((uint8_t *)p)[index]); @@ -334,7 +334,7 @@ STATIC mp_obj_t get_aligned(uint val_type, void *p, mp_int_t index) { } } -STATIC void set_aligned(uint val_type, void *p, mp_int_t index, mp_obj_t val) { +static void set_aligned(uint val_type, void *p, mp_int_t index, mp_obj_t val) { #if MICROPY_PY_BUILTINS_FLOAT if (val_type == FLOAT32 || val_type == FLOAT64) { if (val_type == FLOAT32) { @@ -379,7 +379,7 @@ STATIC void set_aligned(uint val_type, void *p, mp_int_t index, mp_obj_t val) { } } -STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set_val) { +static mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set_val) { mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in); if (!mp_obj_is_dict_or_ordereddict(self->desc)) { @@ -489,7 +489,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set return MP_OBJ_NULL; } -STATIC void uctypes_struct_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void uctypes_struct_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] == MP_OBJ_NULL) { // load attribute mp_obj_t val = uctypes_struct_attr_op(self_in, attr, MP_OBJ_NULL); @@ -502,7 +502,7 @@ STATIC void uctypes_struct_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } } -STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) { +static mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) { mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in); if (value == MP_OBJ_NULL) { @@ -579,7 +579,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_ob } } -STATIC mp_obj_t uctypes_struct_unary_op(mp_unary_op_t op, mp_obj_t self_in) { +static mp_obj_t uctypes_struct_unary_op(mp_unary_op_t op, mp_obj_t self_in) { mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in); switch (op) { case MP_UNARY_OP_INT_MAYBE: @@ -599,7 +599,7 @@ STATIC mp_obj_t uctypes_struct_unary_op(mp_unary_op_t op, mp_obj_t self_in) { } } -STATIC mp_int_t uctypes_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { +static mp_int_t uctypes_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { (void)flags; mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in); mp_uint_t max_field_size = 0; @@ -613,7 +613,7 @@ STATIC mp_int_t uctypes_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, // addressof() // Return address of object's data (applies to objects providing the buffer interface). -STATIC mp_obj_t uctypes_struct_addressof(mp_obj_t buf) { +static mp_obj_t uctypes_struct_addressof(mp_obj_t buf) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ); return mp_obj_new_int((mp_int_t)(uintptr_t)bufinfo.buf); @@ -622,19 +622,19 @@ MP_DEFINE_CONST_FUN_OBJ_1(uctypes_struct_addressof_obj, uctypes_struct_addressof // bytearray_at() // Capture memory at given address of given size as bytearray. -STATIC mp_obj_t uctypes_struct_bytearray_at(mp_obj_t ptr, mp_obj_t size) { +static mp_obj_t uctypes_struct_bytearray_at(mp_obj_t ptr, mp_obj_t size) { return mp_obj_new_bytearray_by_ref(mp_obj_int_get_truncated(size), (void *)(uintptr_t)mp_obj_int_get_truncated(ptr)); } MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytearray_at_obj, uctypes_struct_bytearray_at); // bytes_at() // Capture memory at given address of given size as bytes. -STATIC mp_obj_t uctypes_struct_bytes_at(mp_obj_t ptr, mp_obj_t size) { +static mp_obj_t uctypes_struct_bytes_at(mp_obj_t ptr, mp_obj_t size) { return mp_obj_new_bytes((void *)(uintptr_t)mp_obj_int_get_truncated(ptr), mp_obj_int_get_truncated(size)); } MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytes_at_obj, uctypes_struct_bytes_at); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( uctypes_struct_type, MP_QSTR_struct, MP_TYPE_FLAG_NONE, @@ -646,7 +646,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( buffer, uctypes_get_buffer ); -STATIC const mp_rom_map_elem_t mp_module_uctypes_globals_table[] = { +static const mp_rom_map_elem_t mp_module_uctypes_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uctypes) }, { MP_ROM_QSTR(MP_QSTR_struct), MP_ROM_PTR(&uctypes_struct_type) }, { MP_ROM_QSTR(MP_QSTR_sizeof), MP_ROM_PTR(&uctypes_struct_sizeof_obj) }, @@ -711,7 +711,7 @@ STATIC const mp_rom_map_elem_t mp_module_uctypes_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_PTR), MP_ROM_INT(TYPE2SMALLINT(PTR, AGG_TYPE_BITS)) }, { MP_ROM_QSTR(MP_QSTR_ARRAY), MP_ROM_INT(TYPE2SMALLINT(ARRAY, AGG_TYPE_BITS)) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_uctypes_globals, mp_module_uctypes_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_uctypes_globals, mp_module_uctypes_globals_table); const mp_obj_module_t mp_module_uctypes = { .base = { &mp_type_module }, diff --git a/extmod/modvfs.c b/extmod/modvfs.c index 02dc67d0730a4..32dc0e5d08b0d 100644 --- a/extmod/modvfs.c +++ b/extmod/modvfs.c @@ -37,7 +37,7 @@ #error "MICROPY_PY_VFS requires MICROPY_VFS" #endif -STATIC const mp_rom_map_elem_t vfs_module_globals_table[] = { +static const mp_rom_map_elem_t vfs_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_vfs) }, { MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&mp_vfs_mount_obj) }, @@ -55,7 +55,7 @@ STATIC const mp_rom_map_elem_t vfs_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_VfsPosix), MP_ROM_PTR(&mp_type_vfs_posix) }, #endif }; -STATIC MP_DEFINE_CONST_DICT(vfs_module_globals, vfs_module_globals_table); +static MP_DEFINE_CONST_DICT(vfs_module_globals, vfs_module_globals_table); const mp_obj_module_t mp_module_vfs = { .base = { &mp_type_module }, diff --git a/extmod/modwebrepl.c b/extmod/modwebrepl.c index 64276b5a8f3bd..9d09f65a37c1b 100644 --- a/extmod/modwebrepl.c +++ b/extmod/modwebrepl.c @@ -67,13 +67,13 @@ typedef struct _mp_obj_webrepl_t { mp_obj_t cur_file; } mp_obj_webrepl_t; -STATIC const char passwd_prompt[] = "Password: "; -STATIC const char connected_prompt[] = "\r\nWebREPL connected\r\n>>> "; -STATIC const char denied_prompt[] = "\r\nAccess denied\r\n"; +static const char passwd_prompt[] = "Password: "; +static const char connected_prompt[] = "\r\nWebREPL connected\r\n>>> "; +static const char denied_prompt[] = "\r\nAccess denied\r\n"; -STATIC char webrepl_passwd[10]; +static char webrepl_passwd[10]; -STATIC void write_webrepl(mp_obj_t websock, const void *buf, size_t len) { +static void write_webrepl(mp_obj_t websock, const void *buf, size_t len) { const mp_stream_p_t *sock_stream = mp_get_stream(websock); int err; int old_opts = sock_stream->ioctl(websock, MP_STREAM_SET_DATA_OPTS, FRAME_BIN, &err); @@ -82,18 +82,18 @@ STATIC void write_webrepl(mp_obj_t websock, const void *buf, size_t len) { } #define SSTR(s) s, sizeof(s) - 1 -STATIC void write_webrepl_str(mp_obj_t websock, const char *str, int sz) { +static void write_webrepl_str(mp_obj_t websock, const char *str, int sz) { int err; const mp_stream_p_t *sock_stream = mp_get_stream(websock); sock_stream->write(websock, str, sz, &err); } -STATIC void write_webrepl_resp(mp_obj_t websock, uint16_t code) { +static void write_webrepl_resp(mp_obj_t websock, uint16_t code) { char buf[4] = {'W', 'B', code & 0xff, code >> 8}; write_webrepl(websock, buf, sizeof(buf)); } -STATIC mp_obj_t webrepl_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t webrepl_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 2, false); mp_get_stream_raise(args[0], MP_STREAM_OP_READ | MP_STREAM_OP_WRITE | MP_STREAM_OP_IOCTL); DEBUG_printf("sizeof(struct webrepl_file) = %lu\n", sizeof(struct webrepl_file)); @@ -106,7 +106,7 @@ STATIC mp_obj_t webrepl_make_new(const mp_obj_type_t *type, size_t n_args, size_ return MP_OBJ_FROM_PTR(o); } -STATIC void check_file_op_finished(mp_obj_webrepl_t *self) { +static void check_file_op_finished(mp_obj_webrepl_t *self) { if (self->data_to_recv == 0) { mp_stream_close(self->cur_file); self->hdr_to_recv = sizeof(struct webrepl_file); @@ -115,7 +115,7 @@ STATIC void check_file_op_finished(mp_obj_webrepl_t *self) { } } -STATIC int write_file_chunk(mp_obj_webrepl_t *self) { +static int write_file_chunk(mp_obj_webrepl_t *self) { const mp_stream_p_t *file_stream = mp_get_stream(self->cur_file); byte readbuf[2 + 256]; int err; @@ -130,7 +130,7 @@ STATIC int write_file_chunk(mp_obj_webrepl_t *self) { return out_sz; } -STATIC void handle_op(mp_obj_webrepl_t *self) { +static void handle_op(mp_obj_webrepl_t *self) { // Handle operations not requiring opened file @@ -173,9 +173,9 @@ STATIC void handle_op(mp_obj_webrepl_t *self) { } } -STATIC mp_uint_t _webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode); +static mp_uint_t _webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode); -STATIC mp_uint_t webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { mp_uint_t out_sz; do { out_sz = _webrepl_read(self_in, buf, size, errcode); @@ -183,7 +183,7 @@ STATIC mp_uint_t webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int * return out_sz; } -STATIC mp_uint_t _webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t _webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { // We know that os.dupterm always calls with size = 1 assert(size == 1); mp_obj_webrepl_t *self = MP_OBJ_TO_PTR(self_in); @@ -292,7 +292,7 @@ STATIC mp_uint_t _webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int return -2; } -STATIC mp_uint_t webrepl_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t webrepl_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { mp_obj_webrepl_t *self = MP_OBJ_TO_PTR(self_in); if (self->state == STATE_PASSWD) { // Don't forward output until passwd is entered @@ -302,7 +302,7 @@ STATIC mp_uint_t webrepl_write(mp_obj_t self_in, const void *buf, mp_uint_t size return stream_p->write(self->sock, buf, size, errcode); } -STATIC mp_uint_t webrepl_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t webrepl_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { mp_obj_webrepl_t *self = MP_OBJ_TO_PTR(o_in); (void)arg; switch (request) { @@ -317,7 +317,7 @@ STATIC mp_uint_t webrepl_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, } } -STATIC mp_obj_t webrepl_set_password(mp_obj_t passwd_in) { +static mp_obj_t webrepl_set_password(mp_obj_t passwd_in) { size_t len; const char *passwd = mp_obj_str_get_data(passwd_in, &len); if (len > sizeof(webrepl_passwd) - 1) { @@ -326,23 +326,23 @@ STATIC mp_obj_t webrepl_set_password(mp_obj_t passwd_in) { strcpy(webrepl_passwd, passwd); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(webrepl_set_password_obj, webrepl_set_password); +static MP_DEFINE_CONST_FUN_OBJ_1(webrepl_set_password_obj, webrepl_set_password); -STATIC const mp_rom_map_elem_t webrepl_locals_dict_table[] = { +static const mp_rom_map_elem_t webrepl_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) }, { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) }, { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(webrepl_locals_dict, webrepl_locals_dict_table); +static MP_DEFINE_CONST_DICT(webrepl_locals_dict, webrepl_locals_dict_table); -STATIC const mp_stream_p_t webrepl_stream_p = { +static const mp_stream_p_t webrepl_stream_p = { .read = webrepl_read, .write = webrepl_write, .ioctl = webrepl_ioctl, }; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( webrepl_type, MP_QSTR__webrepl, MP_TYPE_FLAG_NONE, @@ -351,13 +351,13 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &webrepl_locals_dict ); -STATIC const mp_rom_map_elem_t webrepl_module_globals_table[] = { +static const mp_rom_map_elem_t webrepl_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__webrepl) }, { MP_ROM_QSTR(MP_QSTR__webrepl), MP_ROM_PTR(&webrepl_type) }, { MP_ROM_QSTR(MP_QSTR_password), MP_ROM_PTR(&webrepl_set_password_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(webrepl_module_globals, webrepl_module_globals_table); +static MP_DEFINE_CONST_DICT(webrepl_module_globals, webrepl_module_globals_table); const mp_obj_module_t mp_module_webrepl = { .base = { &mp_type_module }, diff --git a/extmod/modwebsocket.c b/extmod/modwebsocket.c index 3645b771a5319..d31d00160b23b 100644 --- a/extmod/modwebsocket.c +++ b/extmod/modwebsocket.c @@ -55,10 +55,10 @@ typedef struct _mp_obj_websocket_t { byte last_flags; } mp_obj_websocket_t; -STATIC mp_uint_t websocket_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode); -STATIC mp_uint_t websocket_write_raw(mp_obj_t self_in, const byte *header, int hdr_sz, const void *buf, mp_uint_t size, int *errcode); +static mp_uint_t websocket_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode); +static mp_uint_t websocket_write_raw(mp_obj_t self_in, const byte *header, int hdr_sz, const void *buf, mp_uint_t size, int *errcode); -STATIC mp_obj_t websocket_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t websocket_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 2, false); mp_get_stream_raise(args[0], MP_STREAM_OP_READ | MP_STREAM_OP_WRITE | MP_STREAM_OP_IOCTL); mp_obj_websocket_t *o = mp_obj_malloc(mp_obj_websocket_t, type); @@ -74,7 +74,7 @@ STATIC mp_obj_t websocket_make_new(const mp_obj_type_t *type, size_t n_args, siz return MP_OBJ_FROM_PTR(o); } -STATIC mp_uint_t websocket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t websocket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { mp_obj_websocket_t *self = MP_OBJ_TO_PTR(self_in); const mp_stream_p_t *stream_p = mp_get_stream(self->sock); while (1) { @@ -216,7 +216,7 @@ STATIC mp_uint_t websocket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int } } -STATIC mp_uint_t websocket_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t websocket_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { mp_obj_websocket_t *self = MP_OBJ_TO_PTR(self_in); assert(size < 0x10000); byte header[4] = {0x80 | (self->opts & FRAME_OPCODE_MASK)}; @@ -233,7 +233,7 @@ STATIC mp_uint_t websocket_write(mp_obj_t self_in, const void *buf, mp_uint_t si return websocket_write_raw(self_in, header, hdr_sz, buf, size, errcode); } -STATIC mp_uint_t websocket_write_raw(mp_obj_t self_in, const byte *header, int hdr_sz, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t websocket_write_raw(mp_obj_t self_in, const byte *header, int hdr_sz, const void *buf, mp_uint_t size, int *errcode) { mp_obj_websocket_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_t dest[3]; @@ -259,7 +259,7 @@ STATIC mp_uint_t websocket_write_raw(mp_obj_t self_in, const byte *header, int h return out_sz; } -STATIC mp_uint_t websocket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t websocket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { mp_obj_websocket_t *self = MP_OBJ_TO_PTR(self_in); switch (request) { case MP_STREAM_CLOSE: @@ -280,7 +280,7 @@ STATIC mp_uint_t websocket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t } } -STATIC const mp_rom_map_elem_t websocket_locals_dict_table[] = { +static const mp_rom_map_elem_t websocket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) }, { MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) }, @@ -288,15 +288,15 @@ STATIC const mp_rom_map_elem_t websocket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&mp_stream_ioctl_obj) }, { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(websocket_locals_dict, websocket_locals_dict_table); +static MP_DEFINE_CONST_DICT(websocket_locals_dict, websocket_locals_dict_table); -STATIC const mp_stream_p_t websocket_stream_p = { +static const mp_stream_p_t websocket_stream_p = { .read = websocket_read, .write = websocket_write, .ioctl = websocket_ioctl, }; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( websocket_type, MP_QSTR_websocket, MP_TYPE_FLAG_NONE, @@ -305,12 +305,12 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &websocket_locals_dict ); -STATIC const mp_rom_map_elem_t websocket_module_globals_table[] = { +static const mp_rom_map_elem_t websocket_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_websocket) }, { MP_ROM_QSTR(MP_QSTR_websocket), MP_ROM_PTR(&websocket_type) }, }; -STATIC MP_DEFINE_CONST_DICT(websocket_module_globals, websocket_module_globals_table); +static MP_DEFINE_CONST_DICT(websocket_module_globals, websocket_module_globals_table); const mp_obj_module_t mp_module_websocket = { .base = { &mp_type_module }, diff --git a/extmod/network_cyw43.c b/extmod/network_cyw43.c index 2f188dbad4cee..89e68e248836e 100644 --- a/extmod/network_cyw43.c +++ b/extmod/network_cyw43.c @@ -57,10 +57,10 @@ typedef struct _network_cyw43_obj_t { int itf; } network_cyw43_obj_t; -STATIC const network_cyw43_obj_t network_cyw43_wl_sta = { { &mp_network_cyw43_type }, &cyw43_state, CYW43_ITF_STA }; -STATIC const network_cyw43_obj_t network_cyw43_wl_ap = { { &mp_network_cyw43_type }, &cyw43_state, CYW43_ITF_AP }; +static const network_cyw43_obj_t network_cyw43_wl_sta = { { &mp_network_cyw43_type }, &cyw43_state, CYW43_ITF_STA }; +static const network_cyw43_obj_t network_cyw43_wl_ap = { { &mp_network_cyw43_type }, &cyw43_state, CYW43_ITF_AP }; -STATIC void network_cyw43_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void network_cyw43_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { network_cyw43_obj_t *self = MP_OBJ_TO_PTR(self_in); struct netif *netif = &self->cyw->netif[self->itf]; int status = cyw43_tcpip_link_status(self->cyw, self->itf); @@ -89,7 +89,7 @@ STATIC void network_cyw43_print(const mp_print_t *print, mp_obj_t self_in, mp_pr ); } -STATIC mp_obj_t network_cyw43_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t network_cyw43_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); if (n_args == 0 || mp_obj_get_int(args[0]) == MOD_NETWORK_STA_IF) { return MP_OBJ_FROM_PTR(&network_cyw43_wl_sta); @@ -98,7 +98,7 @@ STATIC mp_obj_t network_cyw43_make_new(const mp_obj_type_t *type, size_t n_args, } } -STATIC mp_obj_t network_cyw43_send_ethernet(mp_obj_t self_in, mp_obj_t buf_in) { +static mp_obj_t network_cyw43_send_ethernet(mp_obj_t self_in, mp_obj_t buf_in) { network_cyw43_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_buffer_info_t buf; mp_get_buffer_raise(buf_in, &buf, MP_BUFFER_READ); @@ -108,28 +108,28 @@ STATIC mp_obj_t network_cyw43_send_ethernet(mp_obj_t self_in, mp_obj_t buf_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(network_cyw43_send_ethernet_obj, network_cyw43_send_ethernet); +static MP_DEFINE_CONST_FUN_OBJ_2(network_cyw43_send_ethernet_obj, network_cyw43_send_ethernet); -STATIC mp_obj_t network_cyw43_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t buf_in) { +static mp_obj_t network_cyw43_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t buf_in) { network_cyw43_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_buffer_info_t buf; mp_get_buffer_raise(buf_in, &buf, MP_BUFFER_READ | MP_BUFFER_WRITE); cyw43_ioctl(self->cyw, mp_obj_get_int(cmd_in), buf.len, buf.buf, self->itf); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(network_cyw43_ioctl_obj, network_cyw43_ioctl); +static MP_DEFINE_CONST_FUN_OBJ_3(network_cyw43_ioctl_obj, network_cyw43_ioctl); /*******************************************************************************/ // network API -STATIC mp_obj_t network_cyw43_deinit(mp_obj_t self_in) { +static mp_obj_t network_cyw43_deinit(mp_obj_t self_in) { network_cyw43_obj_t *self = MP_OBJ_TO_PTR(self_in); cyw43_deinit(self->cyw); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_cyw43_deinit_obj, network_cyw43_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(network_cyw43_deinit_obj, network_cyw43_deinit); -STATIC mp_obj_t network_cyw43_active(size_t n_args, const mp_obj_t *args) { +static mp_obj_t network_cyw43_active(size_t n_args, const mp_obj_t *args) { network_cyw43_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 1) { return mp_obj_new_bool(cyw43_tcpip_link_status(self->cyw, self->itf)); @@ -139,9 +139,9 @@ STATIC mp_obj_t network_cyw43_active(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_cyw43_active_obj, 1, 2, network_cyw43_active); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_cyw43_active_obj, 1, 2, network_cyw43_active); -STATIC int network_cyw43_scan_cb(void *env, const cyw43_ev_scan_result_t *res) { +static int network_cyw43_scan_cb(void *env, const cyw43_ev_scan_result_t *res) { mp_obj_t list = MP_OBJ_FROM_PTR(env); // Search for existing BSSID to remove duplicates @@ -178,7 +178,7 @@ STATIC int network_cyw43_scan_cb(void *env, const cyw43_ev_scan_result_t *res) { return 0; // continue scan } -STATIC mp_obj_t network_cyw43_scan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t network_cyw43_scan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_passive, ARG_ssid, ARG_essid, ARG_bssid }; static const mp_arg_t allowed_args[] = { { MP_QSTR_passive, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, @@ -234,9 +234,9 @@ STATIC mp_obj_t network_cyw43_scan(size_t n_args, const mp_obj_t *pos_args, mp_m return res; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(network_cyw43_scan_obj, 1, network_cyw43_scan); +static MP_DEFINE_CONST_FUN_OBJ_KW(network_cyw43_scan_obj, 1, network_cyw43_scan); -STATIC mp_obj_t network_cyw43_connect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t network_cyw43_connect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_ssid, ARG_key, ARG_auth, ARG_security, ARG_bssid, ARG_channel }; static const mp_arg_t allowed_args[] = { { MP_QSTR_ssid, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, @@ -300,28 +300,28 @@ STATIC mp_obj_t network_cyw43_connect(size_t n_args, const mp_obj_t *pos_args, m } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(network_cyw43_connect_obj, 1, network_cyw43_connect); +static MP_DEFINE_CONST_FUN_OBJ_KW(network_cyw43_connect_obj, 1, network_cyw43_connect); -STATIC mp_obj_t network_cyw43_disconnect(mp_obj_t self_in) { +static mp_obj_t network_cyw43_disconnect(mp_obj_t self_in) { network_cyw43_obj_t *self = MP_OBJ_TO_PTR(self_in); cyw43_wifi_leave(self->cyw, self->itf); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_cyw43_disconnect_obj, network_cyw43_disconnect); +static MP_DEFINE_CONST_FUN_OBJ_1(network_cyw43_disconnect_obj, network_cyw43_disconnect); -STATIC mp_obj_t network_cyw43_isconnected(mp_obj_t self_in) { +static mp_obj_t network_cyw43_isconnected(mp_obj_t self_in) { network_cyw43_obj_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_bool(cyw43_tcpip_link_status(self->cyw, self->itf) == 3); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_cyw43_isconnected_obj, network_cyw43_isconnected); +static MP_DEFINE_CONST_FUN_OBJ_1(network_cyw43_isconnected_obj, network_cyw43_isconnected); -STATIC mp_obj_t network_cyw43_ifconfig(size_t n_args, const mp_obj_t *args) { +static mp_obj_t network_cyw43_ifconfig(size_t n_args, const mp_obj_t *args) { network_cyw43_obj_t *self = MP_OBJ_TO_PTR(args[0]); return mod_network_nic_ifconfig(&self->cyw->netif[self->itf], n_args - 1, args + 1); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_cyw43_ifconfig_obj, 1, 2, network_cyw43_ifconfig); -STATIC mp_obj_t network_cyw43_status(size_t n_args, const mp_obj_t *args) { +static mp_obj_t network_cyw43_status(size_t n_args, const mp_obj_t *args) { network_cyw43_obj_t *self = MP_OBJ_TO_PTR(args[0]); (void)self; @@ -361,7 +361,7 @@ STATIC mp_obj_t network_cyw43_status(size_t n_args, const mp_obj_t *args) { mp_raise_ValueError(MP_ERROR_TEXT("unknown status param")); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_cyw43_status_obj, 1, 2, network_cyw43_status); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_cyw43_status_obj, 1, 2, network_cyw43_status); static inline uint32_t nw_get_le32(const uint8_t *buf) { return buf[0] | buf[1] << 8 | buf[2] << 16 | buf[3] << 24; @@ -374,7 +374,7 @@ static inline void nw_put_le32(uint8_t *buf, uint32_t x) { buf[3] = x >> 24; } -STATIC mp_obj_t network_cyw43_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { +static mp_obj_t network_cyw43_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { network_cyw43_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (kwargs->used == 0) { @@ -516,12 +516,12 @@ STATIC mp_obj_t network_cyw43_config(size_t n_args, const mp_obj_t *args, mp_map return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(network_cyw43_config_obj, 1, network_cyw43_config); +static MP_DEFINE_CONST_FUN_OBJ_KW(network_cyw43_config_obj, 1, network_cyw43_config); /*******************************************************************************/ // class bindings -STATIC const mp_rom_map_elem_t network_cyw43_locals_dict_table[] = { +static const mp_rom_map_elem_t network_cyw43_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_send_ethernet), MP_ROM_PTR(&network_cyw43_send_ethernet_obj) }, { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&network_cyw43_ioctl_obj) }, @@ -540,7 +540,7 @@ STATIC const mp_rom_map_elem_t network_cyw43_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_PM_PERFORMANCE), MP_ROM_INT(PM_PERFORMANCE) }, { MP_ROM_QSTR(MP_QSTR_PM_POWERSAVE), MP_ROM_INT(PM_POWERSAVE) }, }; -STATIC MP_DEFINE_CONST_DICT(network_cyw43_locals_dict, network_cyw43_locals_dict_table); +static MP_DEFINE_CONST_DICT(network_cyw43_locals_dict, network_cyw43_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mp_network_cyw43_type, diff --git a/extmod/network_esp_hosted.c b/extmod/network_esp_hosted.c index 1a3be3f39a1a1..14e8be8b6a4e4 100644 --- a/extmod/network_esp_hosted.c +++ b/extmod/network_esp_hosted.c @@ -56,7 +56,7 @@ typedef struct _esp_hosted_obj_t { static esp_hosted_obj_t esp_hosted_sta_if = {{(mp_obj_type_t *)&mod_network_esp_hosted_type}, ESP_HOSTED_STA_IF}; static esp_hosted_obj_t esp_hosted_ap_if = {{(mp_obj_type_t *)&mod_network_esp_hosted_type}, ESP_HOSTED_AP_IF}; -STATIC mp_obj_t network_esp_hosted_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t network_esp_hosted_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); mp_obj_t esp_hosted_obj; // TODO fix @@ -70,7 +70,7 @@ STATIC mp_obj_t network_esp_hosted_make_new(const mp_obj_type_t *type, size_t n_ return esp_hosted_obj; } -STATIC mp_obj_t network_esp_hosted_active(size_t n_args, const mp_obj_t *args) { +static mp_obj_t network_esp_hosted_active(size_t n_args, const mp_obj_t *args) { esp_hosted_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 2) { @@ -95,9 +95,9 @@ STATIC mp_obj_t network_esp_hosted_active(size_t n_args, const mp_obj_t *args) { } return mp_obj_new_bool(esp_hosted_wifi_link_status(self->itf)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_esp_hosted_active_obj, 1, 2, network_esp_hosted_active); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_esp_hosted_active_obj, 1, 2, network_esp_hosted_active); -STATIC int esp_hosted_scan_callback(esp_hosted_scan_result_t *scan_result, void *arg) { +static int esp_hosted_scan_callback(esp_hosted_scan_result_t *scan_result, void *arg) { mp_obj_t scan_list = (mp_obj_t)arg; mp_obj_t ap[6] = { mp_obj_new_bytes((uint8_t *)scan_result->ssid, strlen(scan_result->ssid)), @@ -111,15 +111,15 @@ STATIC int esp_hosted_scan_callback(esp_hosted_scan_result_t *scan_result, void return 0; } -STATIC mp_obj_t network_esp_hosted_scan(mp_obj_t self_in) { +static mp_obj_t network_esp_hosted_scan(mp_obj_t self_in) { mp_obj_t scan_list; scan_list = mp_obj_new_list(0, NULL); esp_hosted_wifi_scan(esp_hosted_scan_callback, scan_list, 10000); return scan_list; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_esp_hosted_scan_obj, network_esp_hosted_scan); +static MP_DEFINE_CONST_FUN_OBJ_1(network_esp_hosted_scan_obj, network_esp_hosted_scan); -STATIC mp_obj_t network_esp_hosted_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t network_esp_hosted_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_ssid, ARG_key, ARG_security, ARG_bssid, ARG_channel }; static const mp_arg_t allowed_args[] = { { MP_QSTR_ssid, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, @@ -182,29 +182,29 @@ STATIC mp_obj_t network_esp_hosted_connect(mp_uint_t n_args, const mp_obj_t *pos return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(network_esp_hosted_connect_obj, 1, network_esp_hosted_connect); +static MP_DEFINE_CONST_FUN_OBJ_KW(network_esp_hosted_connect_obj, 1, network_esp_hosted_connect); -STATIC mp_obj_t network_esp_hosted_disconnect(mp_obj_t self_in) { +static mp_obj_t network_esp_hosted_disconnect(mp_obj_t self_in) { esp_hosted_obj_t *self = self_in; esp_hosted_wifi_disconnect(self->itf); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_esp_hosted_disconnect_obj, network_esp_hosted_disconnect); +static MP_DEFINE_CONST_FUN_OBJ_1(network_esp_hosted_disconnect_obj, network_esp_hosted_disconnect); -STATIC mp_obj_t network_esp_hosted_isconnected(mp_obj_t self_in) { +static mp_obj_t network_esp_hosted_isconnected(mp_obj_t self_in) { esp_hosted_obj_t *self = self_in; return mp_obj_new_bool(esp_hosted_wifi_is_connected(self->itf)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_esp_hosted_isconnected_obj, network_esp_hosted_isconnected); +static MP_DEFINE_CONST_FUN_OBJ_1(network_esp_hosted_isconnected_obj, network_esp_hosted_isconnected); -STATIC mp_obj_t network_esp_hosted_ifconfig(size_t n_args, const mp_obj_t *args) { +static mp_obj_t network_esp_hosted_ifconfig(size_t n_args, const mp_obj_t *args) { esp_hosted_obj_t *self = MP_OBJ_TO_PTR(args[0]); void *netif = esp_hosted_wifi_get_netif(self->itf); return mod_network_nic_ifconfig(netif, n_args - 1, args + 1); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_esp_hosted_ifconfig_obj, 1, 2, network_esp_hosted_ifconfig); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_esp_hosted_ifconfig_obj, 1, 2, network_esp_hosted_ifconfig); -STATIC mp_obj_t network_esp_hosted_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { +static mp_obj_t network_esp_hosted_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { esp_hosted_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (kwargs->used == 0) { @@ -253,9 +253,9 @@ STATIC mp_obj_t network_esp_hosted_config(size_t n_args, const mp_obj_t *args, m return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(network_esp_hosted_config_obj, 1, network_esp_hosted_config); +static MP_DEFINE_CONST_FUN_OBJ_KW(network_esp_hosted_config_obj, 1, network_esp_hosted_config); -STATIC mp_obj_t network_esp_hosted_status(size_t n_args, const mp_obj_t *args) { +static mp_obj_t network_esp_hosted_status(size_t n_args, const mp_obj_t *args) { esp_hosted_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 1) { @@ -290,9 +290,9 @@ STATIC mp_obj_t network_esp_hosted_status(size_t n_args, const mp_obj_t *args) { mp_raise_ValueError(MP_ERROR_TEXT("unknown status param")); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_esp_hosted_status_obj, 1, 2, network_esp_hosted_status); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_esp_hosted_status_obj, 1, 2, network_esp_hosted_status); -STATIC const mp_rom_map_elem_t network_esp_hosted_locals_dict_table[] = { +static const mp_rom_map_elem_t network_esp_hosted_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&network_esp_hosted_active_obj) }, { MP_ROM_QSTR(MP_QSTR_scan), MP_ROM_PTR(&network_esp_hosted_scan_obj) }, { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&network_esp_hosted_connect_obj) }, @@ -305,7 +305,7 @@ STATIC const mp_rom_map_elem_t network_esp_hosted_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_WEP), MP_ROM_INT(ESP_HOSTED_SEC_WEP) }, { MP_ROM_QSTR(MP_QSTR_WPA_PSK), MP_ROM_INT(ESP_HOSTED_SEC_WPA_WPA2_PSK) }, }; -STATIC MP_DEFINE_CONST_DICT(network_esp_hosted_locals_dict, network_esp_hosted_locals_dict_table); +static MP_DEFINE_CONST_DICT(network_esp_hosted_locals_dict, network_esp_hosted_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mod_network_esp_hosted_type, diff --git a/extmod/network_ninaw10.c b/extmod/network_ninaw10.c index 1deb117e70689..e68a7a66e27d2 100644 --- a/extmod/network_ninaw10.c +++ b/extmod/network_ninaw10.c @@ -85,21 +85,21 @@ static nina_obj_t network_nina_wl_sta = {{(mp_obj_type_t *)&mod_network_nic_type static nina_obj_t network_nina_wl_ap = {{(mp_obj_type_t *)&mod_network_nic_type_nina}, false, false, MOD_NETWORK_AP_IF}; static mp_sched_node_t mp_wifi_poll_node; static soft_timer_entry_t mp_wifi_poll_timer; -STATIC void network_ninaw10_deinit(void); +static void network_ninaw10_deinit(void); -STATIC bool network_ninaw10_poll_list_is_empty(void) { +static bool network_ninaw10_poll_list_is_empty(void) { return MP_STATE_PORT(mp_wifi_poll_list) == NULL || MP_STATE_PORT(mp_wifi_poll_list)->len == 0; } -STATIC void network_ninaw10_poll_list_insert(mp_obj_t socket) { +static void network_ninaw10_poll_list_insert(mp_obj_t socket) { if (MP_STATE_PORT(mp_wifi_poll_list) == NULL) { MP_STATE_PORT(mp_wifi_poll_list) = mp_obj_new_list(0, NULL); } mp_obj_list_append(MP_STATE_PORT(mp_wifi_poll_list), socket); } -STATIC void network_ninaw10_poll_list_remove(mp_obj_t socket) { +static void network_ninaw10_poll_list_remove(mp_obj_t socket) { if (MP_STATE_PORT(mp_wifi_poll_list) == NULL) { return; } @@ -109,7 +109,7 @@ STATIC void network_ninaw10_poll_list_remove(mp_obj_t socket) { } } -STATIC void network_ninaw10_poll_sockets(mp_sched_node_t *node) { +static void network_ninaw10_poll_sockets(mp_sched_node_t *node) { (void)node; for (mp_uint_t i = 0; MP_STATE_PORT(mp_wifi_poll_list) && i < MP_STATE_PORT(mp_wifi_poll_list)->len;) { mod_network_socket_obj_t *socket = MP_STATE_PORT(mp_wifi_poll_list)->items[i]; @@ -134,7 +134,7 @@ STATIC void network_ninaw10_poll_sockets(mp_sched_node_t *node) { } } -STATIC void network_ninaw10_poll_connect(mp_sched_node_t *node) { +static void network_ninaw10_poll_connect(mp_sched_node_t *node) { nina_obj_t *self = &network_nina_wl_sta; int status = nina_connection_status(); @@ -166,7 +166,7 @@ STATIC void network_ninaw10_poll_connect(mp_sched_node_t *node) { soft_timer_reinsert(&mp_wifi_poll_timer, NINAW10_POLL_INTERVAL); } -STATIC void network_ninaw10_timer_callback(soft_timer_entry_t *self) { +static void network_ninaw10_timer_callback(soft_timer_entry_t *self) { debug_printf("timer_callback() poll status STA: %d AP: %d SOCKETS: %d\n", network_nina_wl_sta.poll_enable, network_nina_wl_ap.poll_enable, !network_ninaw10_poll_list_is_empty()); if (network_nina_wl_sta.poll_enable) { @@ -176,7 +176,7 @@ STATIC void network_ninaw10_timer_callback(soft_timer_entry_t *self) { } } -STATIC mp_obj_t network_ninaw10_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t network_ninaw10_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); mp_obj_t nina_obj; if (n_args == 0 || mp_obj_get_int(args[0]) == MOD_NETWORK_STA_IF) { @@ -189,7 +189,7 @@ STATIC mp_obj_t network_ninaw10_make_new(const mp_obj_type_t *type, size_t n_arg return nina_obj; } -STATIC mp_obj_t network_ninaw10_active(size_t n_args, const mp_obj_t *args) { +static mp_obj_t network_ninaw10_active(size_t n_args, const mp_obj_t *args) { nina_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 2) { bool active = mp_obj_is_true(args[1]); @@ -231,9 +231,9 @@ STATIC mp_obj_t network_ninaw10_active(size_t n_args, const mp_obj_t *args) { } return mp_obj_new_bool(self->active); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_ninaw10_active_obj, 1, 2, network_ninaw10_active); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_ninaw10_active_obj, 1, 2, network_ninaw10_active); -STATIC int nina_scan_callback(nina_scan_result_t *scan_result, void *arg) { +static int nina_scan_callback(nina_scan_result_t *scan_result, void *arg) { mp_obj_t scan_list = (mp_obj_t)arg; mp_obj_t ap[6] = { mp_obj_new_bytes((uint8_t *)scan_result->ssid, strlen(scan_result->ssid)), @@ -247,15 +247,15 @@ STATIC int nina_scan_callback(nina_scan_result_t *scan_result, void *arg) { return 0; } -STATIC mp_obj_t network_ninaw10_scan(mp_obj_t self_in) { +static mp_obj_t network_ninaw10_scan(mp_obj_t self_in) { mp_obj_t scan_list; scan_list = mp_obj_new_list(0, NULL); nina_scan(nina_scan_callback, scan_list, 10000); return scan_list; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_ninaw10_scan_obj, network_ninaw10_scan); +static MP_DEFINE_CONST_FUN_OBJ_1(network_ninaw10_scan_obj, network_ninaw10_scan); -STATIC mp_obj_t network_ninaw10_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t network_ninaw10_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_ssid, ARG_key, ARG_security, ARG_channel }; static const mp_arg_t allowed_args[] = { { MP_QSTR_ssid, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, @@ -322,20 +322,20 @@ STATIC mp_obj_t network_ninaw10_connect(mp_uint_t n_args, const mp_obj_t *pos_ar return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(network_ninaw10_connect_obj, 1, network_ninaw10_connect); +static MP_DEFINE_CONST_FUN_OBJ_KW(network_ninaw10_connect_obj, 1, network_ninaw10_connect); -STATIC mp_obj_t network_ninaw10_disconnect(mp_obj_t self_in) { +static mp_obj_t network_ninaw10_disconnect(mp_obj_t self_in) { nina_disconnect(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_ninaw10_disconnect_obj, network_ninaw10_disconnect); +static MP_DEFINE_CONST_FUN_OBJ_1(network_ninaw10_disconnect_obj, network_ninaw10_disconnect); -STATIC mp_obj_t network_ninaw10_isconnected(mp_obj_t self_in) { +static mp_obj_t network_ninaw10_isconnected(mp_obj_t self_in) { return mp_obj_new_bool(nina_isconnected()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_ninaw10_isconnected_obj, network_ninaw10_isconnected); +static MP_DEFINE_CONST_FUN_OBJ_1(network_ninaw10_isconnected_obj, network_ninaw10_isconnected); -STATIC mp_obj_t network_ninaw10_ifconfig(size_t n_args, const mp_obj_t *args) { +static mp_obj_t network_ninaw10_ifconfig(size_t n_args, const mp_obj_t *args) { nina_ifconfig_t ifconfig; if (n_args == 1) { // get ifconfig info @@ -359,9 +359,9 @@ STATIC mp_obj_t network_ninaw10_ifconfig(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_ninaw10_ifconfig_obj, 1, 2, network_ninaw10_ifconfig); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_ninaw10_ifconfig_obj, 1, 2, network_ninaw10_ifconfig); -STATIC mp_obj_t network_ninaw10_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { +static mp_obj_t network_ninaw10_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { nina_obj_t *self = MP_OBJ_TO_PTR(args[0]); (void)self; @@ -410,9 +410,9 @@ STATIC mp_obj_t network_ninaw10_config(size_t n_args, const mp_obj_t *args, mp_m return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(network_ninaw10_config_obj, 1, network_ninaw10_config); +static MP_DEFINE_CONST_FUN_OBJ_KW(network_ninaw10_config_obj, 1, network_ninaw10_config); -STATIC mp_obj_t network_ninaw10_status(size_t n_args, const mp_obj_t *args) { +static mp_obj_t network_ninaw10_status(size_t n_args, const mp_obj_t *args) { nina_obj_t *self = MP_OBJ_TO_PTR(args[0]); (void)self; @@ -444,9 +444,9 @@ STATIC mp_obj_t network_ninaw10_status(size_t n_args, const mp_obj_t *args) { mp_raise_ValueError(MP_ERROR_TEXT("unknown status param")); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_ninaw10_status_obj, 1, 2, network_ninaw10_status); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_ninaw10_status_obj, 1, 2, network_ninaw10_status); -STATIC mp_obj_t network_ninaw10_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t buf_in) { +static mp_obj_t network_ninaw10_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t buf_in) { debug_printf("ioctl(%d)\n", mp_obj_get_int(cmd_in)); nina_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_buffer_info_t buf; @@ -458,14 +458,14 @@ STATIC mp_obj_t network_ninaw10_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_ } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(network_ninaw10_ioctl_obj, network_ninaw10_ioctl); +static MP_DEFINE_CONST_FUN_OBJ_3(network_ninaw10_ioctl_obj, network_ninaw10_ioctl); -STATIC int network_ninaw10_gethostbyname(mp_obj_t nic, const char *name, mp_uint_t len, uint8_t *out_ip) { +static int network_ninaw10_gethostbyname(mp_obj_t nic, const char *name, mp_uint_t len, uint8_t *out_ip) { debug_printf("gethostbyname(%s)\n", name); return nina_gethostbyname(name, out_ip); } -STATIC int network_ninaw10_socket_poll(mod_network_socket_obj_t *socket, uint32_t rwf, int *_errno) { +static int network_ninaw10_socket_poll(mod_network_socket_obj_t *socket, uint32_t rwf, int *_errno) { uint8_t flags = 0; debug_printf("socket_polling_rw(%d, %d, %d)\n", socket->fileno, socket->timeout, rwf); if (socket->timeout == 0) { @@ -488,7 +488,7 @@ STATIC int network_ninaw10_socket_poll(mod_network_socket_obj_t *socket, uint32_ return 0; } -STATIC int network_ninaw10_socket_setblocking(mod_network_socket_obj_t *socket, bool blocking, int *_errno) { +static int network_ninaw10_socket_setblocking(mod_network_socket_obj_t *socket, bool blocking, int *_errno) { uint32_t nonblocking = !blocking; // set socket in non-blocking mode if (nina_socket_ioctl(socket->fileno, SOCKET_IOCTL_FIONBIO, &nonblocking, sizeof(nonblocking)) < 0) { @@ -499,7 +499,7 @@ STATIC int network_ninaw10_socket_setblocking(mod_network_socket_obj_t *socket, return 0; } -STATIC int network_ninaw10_socket_listening(mod_network_socket_obj_t *socket, int *_errno) { +static int network_ninaw10_socket_listening(mod_network_socket_obj_t *socket, int *_errno) { int listening = 0; if (nina_socket_getsockopt(socket->fileno, MOD_NETWORK_SOL_SOCKET, SO_ACCEPTCONN, &listening, sizeof(listening)) < 0) { @@ -510,7 +510,7 @@ STATIC int network_ninaw10_socket_listening(mod_network_socket_obj_t *socket, in return listening; } -STATIC int network_ninaw10_socket_socket(mod_network_socket_obj_t *socket, int *_errno) { +static int network_ninaw10_socket_socket(mod_network_socket_obj_t *socket, int *_errno) { debug_printf("socket_socket(%d %d %d)\n", socket->domain, socket->type, socket->proto); uint8_t socket_type; @@ -553,7 +553,7 @@ STATIC int network_ninaw10_socket_socket(mod_network_socket_obj_t *socket, int * return network_ninaw10_socket_setblocking(socket, false, _errno); } -STATIC void network_ninaw10_socket_close(mod_network_socket_obj_t *socket) { +static void network_ninaw10_socket_close(mod_network_socket_obj_t *socket) { debug_printf("socket_close(%d)\n", socket->fileno); if (socket->callback != MP_OBJ_NULL) { socket->callback = MP_OBJ_NULL; @@ -565,7 +565,7 @@ STATIC void network_ninaw10_socket_close(mod_network_socket_obj_t *socket) { } } -STATIC int network_ninaw10_socket_bind(mod_network_socket_obj_t *socket, byte *ip, mp_uint_t port, int *_errno) { +static int network_ninaw10_socket_bind(mod_network_socket_obj_t *socket, byte *ip, mp_uint_t port, int *_errno) { debug_printf("socket_bind(%d, %d)\n", socket->fileno, port); int ret = nina_socket_bind(socket->fileno, ip, port); @@ -581,7 +581,7 @@ STATIC int network_ninaw10_socket_bind(mod_network_socket_obj_t *socket, byte *i return 0; } -STATIC int network_ninaw10_socket_listen(mod_network_socket_obj_t *socket, mp_int_t backlog, int *_errno) { +static int network_ninaw10_socket_listen(mod_network_socket_obj_t *socket, mp_int_t backlog, int *_errno) { debug_printf("socket_listen(%d, %d)\n", socket->fileno, backlog); int ret = nina_socket_listen(socket->fileno, backlog); if (ret < 0) { @@ -593,7 +593,7 @@ STATIC int network_ninaw10_socket_listen(mod_network_socket_obj_t *socket, mp_in return 0; } -STATIC int network_ninaw10_socket_accept(mod_network_socket_obj_t *socket, +static int network_ninaw10_socket_accept(mod_network_socket_obj_t *socket, mod_network_socket_obj_t *socket2, byte *ip, mp_uint_t *port, int *_errno) { debug_printf("socket_accept(%d)\n", socket->fileno); @@ -622,7 +622,7 @@ STATIC int network_ninaw10_socket_accept(mod_network_socket_obj_t *socket, return network_ninaw10_socket_setblocking(socket2, false, _errno); } -STATIC int network_ninaw10_socket_connect(mod_network_socket_obj_t *socket, byte *ip, mp_uint_t port, int *_errno) { +static int network_ninaw10_socket_connect(mod_network_socket_obj_t *socket, byte *ip, mp_uint_t port, int *_errno) { debug_printf("socket_connect(%d)\n", socket->fileno); int ret = nina_socket_connect(socket->fileno, ip, port); @@ -645,7 +645,7 @@ STATIC int network_ninaw10_socket_connect(mod_network_socket_obj_t *socket, byte return 0; } -STATIC mp_uint_t network_ninaw10_socket_send(mod_network_socket_obj_t *socket, const byte *buf, mp_uint_t len, int *_errno) { +static mp_uint_t network_ninaw10_socket_send(mod_network_socket_obj_t *socket, const byte *buf, mp_uint_t len, int *_errno) { debug_printf("socket_send(%d, %d)\n", socket->fileno, len); if (network_ninaw10_socket_poll(socket, SOCKET_POLL_WR, _errno) != 0) { @@ -665,7 +665,7 @@ STATIC mp_uint_t network_ninaw10_socket_send(mod_network_socket_obj_t *socket, c return ret; } -STATIC mp_uint_t network_ninaw10_socket_recv(mod_network_socket_obj_t *socket, byte *buf, mp_uint_t len, int *_errno) { +static mp_uint_t network_ninaw10_socket_recv(mod_network_socket_obj_t *socket, byte *buf, mp_uint_t len, int *_errno) { debug_printf("socket_recv(%d)\n", socket->fileno); // check if socket in listening state. if (network_ninaw10_socket_listening(socket, _errno) == 1) { @@ -694,7 +694,7 @@ STATIC mp_uint_t network_ninaw10_socket_recv(mod_network_socket_obj_t *socket, b return ret; } -STATIC mp_uint_t network_ninaw10_socket_auto_bind(mod_network_socket_obj_t *socket, int *_errno) { +static mp_uint_t network_ninaw10_socket_auto_bind(mod_network_socket_obj_t *socket, int *_errno) { debug_printf("socket_autobind(%d)\n", socket->fileno); if (socket->bound == false && socket->type != MOD_NETWORK_SOCK_RAW) { if (network_ninaw10_socket_bind(socket, NULL, bind_port, _errno) != 0) { @@ -708,7 +708,7 @@ STATIC mp_uint_t network_ninaw10_socket_auto_bind(mod_network_socket_obj_t *sock return 0; } -STATIC mp_uint_t network_ninaw10_socket_sendto(mod_network_socket_obj_t *socket, +static mp_uint_t network_ninaw10_socket_sendto(mod_network_socket_obj_t *socket, const byte *buf, mp_uint_t len, byte *ip, mp_uint_t port, int *_errno) { debug_printf("socket_sendto(%d)\n", socket->fileno); // Auto-bind the socket first if the socket is unbound. @@ -732,7 +732,7 @@ STATIC mp_uint_t network_ninaw10_socket_sendto(mod_network_socket_obj_t *socket, return ret; } -STATIC mp_uint_t network_ninaw10_socket_recvfrom(mod_network_socket_obj_t *socket, +static mp_uint_t network_ninaw10_socket_recvfrom(mod_network_socket_obj_t *socket, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno) { debug_printf("socket_recvfrom(%d)\n", socket->fileno); // Auto-bind the socket first if the socket is unbound. @@ -758,7 +758,7 @@ STATIC mp_uint_t network_ninaw10_socket_recvfrom(mod_network_socket_obj_t *socke return ret; } -STATIC int network_ninaw10_socket_setsockopt(mod_network_socket_obj_t *socket, mp_uint_t +static int network_ninaw10_socket_setsockopt(mod_network_socket_obj_t *socket, mp_uint_t level, mp_uint_t opt, const void *optval, mp_uint_t optlen, int *_errno) { debug_printf("socket_setsockopt(%d, %d)\n", socket->fileno, opt); if (opt == 20) { @@ -781,7 +781,7 @@ STATIC int network_ninaw10_socket_setsockopt(mod_network_socket_obj_t *socket, m return 0; } -STATIC int network_ninaw10_socket_settimeout(mod_network_socket_obj_t *socket, mp_uint_t timeout_ms, int *_errno) { +static int network_ninaw10_socket_settimeout(mod_network_socket_obj_t *socket, mp_uint_t timeout_ms, int *_errno) { debug_printf("socket_settimeout(%d, %d)\n", socket->fileno, timeout_ms); #if 0 if (timeout_ms == 0 || timeout_ms == UINT32_MAX) { @@ -806,7 +806,7 @@ STATIC int network_ninaw10_socket_settimeout(mod_network_socket_obj_t *socket, m return 0; } -STATIC int network_ninaw10_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request, mp_uint_t arg, int *_errno) { +static int network_ninaw10_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request, mp_uint_t arg, int *_errno) { mp_uint_t ret = 0; debug_printf("socket_ioctl(%d, %d)\n", socket->fileno, request); if (request == MP_STREAM_POLL) { @@ -830,7 +830,7 @@ STATIC int network_ninaw10_socket_ioctl(mod_network_socket_obj_t *socket, mp_uin return ret; } -STATIC void network_ninaw10_deinit(void) { +static void network_ninaw10_deinit(void) { // On soft-reboot, gc_sweep_all is called and all open sockets are closed // and collected. Make sure that the driver is not keeping any references // to collected sockets in the poll list. @@ -838,7 +838,7 @@ STATIC void network_ninaw10_deinit(void) { MP_STATE_PORT(mp_wifi_poll_list) = NULL; } -STATIC const mp_rom_map_elem_t nina_locals_dict_table[] = { +static const mp_rom_map_elem_t nina_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&network_ninaw10_active_obj) }, { MP_ROM_QSTR(MP_QSTR_scan), MP_ROM_PTR(&network_ninaw10_scan_obj) }, { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&network_ninaw10_connect_obj) }, @@ -857,9 +857,9 @@ STATIC const mp_rom_map_elem_t nina_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_WPA_PSK), MP_ROM_INT(NINA_SEC_WPA_PSK) }, }; -STATIC MP_DEFINE_CONST_DICT(nina_locals_dict, nina_locals_dict_table); +static MP_DEFINE_CONST_DICT(nina_locals_dict, nina_locals_dict_table); -STATIC const mod_network_nic_protocol_t mod_network_nic_protocol_nina = { +static const mod_network_nic_protocol_t mod_network_nic_protocol_nina = { .gethostbyname = network_ninaw10_gethostbyname, .deinit = network_ninaw10_deinit, .socket = network_ninaw10_socket_socket, diff --git a/extmod/network_wiznet5k.c b/extmod/network_wiznet5k.c index d4841e0176dcb..d1aadc3e15584 100644 --- a/extmod/network_wiznet5k.c +++ b/extmod/network_wiznet5k.c @@ -120,21 +120,21 @@ typedef struct _wiznet5k_obj_t { #endif // Global object holding the Wiznet5k state -STATIC wiznet5k_obj_t wiznet5k_obj; +static wiznet5k_obj_t wiznet5k_obj; -STATIC void wiz_cris_enter(void) { +static void wiz_cris_enter(void) { wiznet5k_obj.cris_state = MICROPY_BEGIN_ATOMIC_SECTION(); } -STATIC void wiz_cris_exit(void) { +static void wiz_cris_exit(void) { MICROPY_END_ATOMIC_SECTION(wiznet5k_obj.cris_state); } -STATIC void wiz_cs_select(void) { +static void wiz_cs_select(void) { mp_hal_pin_low(wiznet5k_obj.cs); } -STATIC void wiz_cs_deselect(void) { +static void wiz_cs_deselect(void) { mp_hal_pin_high(wiznet5k_obj.cs); } @@ -147,25 +147,25 @@ void mpy_wiznet_yield(void) { #endif } -STATIC void wiz_spi_read(uint8_t *buf, uint16_t len) { +static void wiz_spi_read(uint8_t *buf, uint16_t len) { wiznet5k_obj.spi_transfer(wiznet5k_obj.spi, len, buf, buf); } -STATIC void wiz_spi_write(const uint8_t *buf, uint16_t len) { +static void wiz_spi_write(const uint8_t *buf, uint16_t len) { wiznet5k_obj.spi_transfer(wiznet5k_obj.spi, len, buf, NULL); } -STATIC uint8_t wiz_spi_readbyte() { +static uint8_t wiz_spi_readbyte() { uint8_t buf = 0; wiznet5k_obj.spi_transfer(wiznet5k_obj.spi, 1, &buf, &buf); return buf; } -STATIC void wiz_spi_writebyte(const uint8_t buf) { +static void wiz_spi_writebyte(const uint8_t buf) { wiznet5k_obj.spi_transfer(wiznet5k_obj.spi, 1, &buf, NULL); } -STATIC void wiznet5k_get_mac_address(wiznet5k_obj_t *self, uint8_t mac[6]) { +static void wiznet5k_get_mac_address(wiznet5k_obj_t *self, uint8_t mac[6]) { (void)self; getSHAR(mac); } @@ -173,9 +173,9 @@ STATIC void wiznet5k_get_mac_address(wiznet5k_obj_t *self, uint8_t mac[6]) { #if WIZNET5K_WITH_LWIP_STACK void wiznet5k_try_poll(void); -STATIC void wiznet5k_lwip_init(wiznet5k_obj_t *self); +static void wiznet5k_lwip_init(wiznet5k_obj_t *self); -STATIC mp_obj_t mpy_wiznet_read_int(mp_obj_t none_in) { +static mp_obj_t mpy_wiznet_read_int(mp_obj_t none_in) { (void)none_in; // Handle incoming data, unless the SPI bus is busy if (mp_hal_pin_read(wiznet5k_obj.cs)) { @@ -183,9 +183,9 @@ STATIC mp_obj_t mpy_wiznet_read_int(mp_obj_t none_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mpy_wiznet_read_int_obj, mpy_wiznet_read_int); +static MP_DEFINE_CONST_FUN_OBJ_1(mpy_wiznet_read_int_obj, mpy_wiznet_read_int); -STATIC void wiznet5k_config_interrupt(bool enabled) { +static void wiznet5k_config_interrupt(bool enabled) { if (!wiznet5k_obj.use_interrupt) { return; } @@ -207,7 +207,7 @@ void wiznet5k_deinit(void) { } } -STATIC void wiznet5k_init(void) { +static void wiznet5k_init(void) { // Configure wiznet for raw ethernet frame usage. // Configure 16k buffers for fast MACRAW @@ -241,7 +241,7 @@ STATIC void wiznet5k_init(void) { mod_network_register_nic(&wiznet5k_obj); } -STATIC void wiznet5k_send_ethernet(wiznet5k_obj_t *self, size_t len, const uint8_t *buf) { +static void wiznet5k_send_ethernet(wiznet5k_obj_t *self, size_t len, const uint8_t *buf) { uint8_t ip[4] = {1, 1, 1, 1}; // dummy int ret = WIZCHIP_EXPORT(sendto)(0, (byte *)buf, len, ip, 11); // dummy port if (ret != len) { @@ -252,7 +252,7 @@ STATIC void wiznet5k_send_ethernet(wiznet5k_obj_t *self, size_t len, const uint8 } // Stores the frame in self->eth_frame and returns number of bytes in the frame, 0 for no frame -STATIC uint16_t wiznet5k_recv_ethernet(wiznet5k_obj_t *self) { +static uint16_t wiznet5k_recv_ethernet(wiznet5k_obj_t *self) { uint16_t len = getSn_RX_RSR(0); if (len == 0) { return 0; @@ -274,7 +274,7 @@ STATIC uint16_t wiznet5k_recv_ethernet(wiznet5k_obj_t *self) { /*******************************************************************************/ // Wiznet5k lwIP interface -STATIC err_t wiznet5k_netif_output(struct netif *netif, struct pbuf *p) { +static err_t wiznet5k_netif_output(struct netif *netif, struct pbuf *p) { wiznet5k_obj_t *self = netif->state; pbuf_copy_partial(p, self->eth_frame, p->tot_len, 0); if (self->trace_flags & TRACE_ETH_TX) { @@ -284,7 +284,7 @@ STATIC err_t wiznet5k_netif_output(struct netif *netif, struct pbuf *p) { return ERR_OK; } -STATIC err_t wiznet5k_netif_init(struct netif *netif) { +static err_t wiznet5k_netif_init(struct netif *netif) { netif->linkoutput = wiznet5k_netif_output; netif->output = etharp_output; netif->mtu = 1500; @@ -303,7 +303,7 @@ STATIC err_t wiznet5k_netif_init(struct netif *netif) { return ERR_OK; } -STATIC void wiznet5k_lwip_init(wiznet5k_obj_t *self) { +static void wiznet5k_lwip_init(wiznet5k_obj_t *self) { ip_addr_t ipconfig[4]; IP_ADDR4(&ipconfig[0], 0, 0, 0, 0); IP_ADDR4(&ipconfig[1], 0, 0, 0, 0); @@ -350,7 +350,7 @@ void wiznet5k_poll(void) { #if WIZNET5K_PROVIDED_STACK -STATIC void wiz_dhcp_assign(void) { +static void wiz_dhcp_assign(void) { getIPfromDHCP(wiznet5k_obj.netinfo.ip); getGWfromDHCP(wiznet5k_obj.netinfo.gw); getSNfromDHCP(wiznet5k_obj.netinfo.sn); @@ -358,16 +358,16 @@ STATIC void wiz_dhcp_assign(void) { ctlnetwork(CN_SET_NETINFO, (void *)&wiznet5k_obj.netinfo); } -STATIC void wiz_dhcp_update(void) { +static void wiz_dhcp_update(void) { ; } -STATIC void wiz_dhcp_conflict(void) { +static void wiz_dhcp_conflict(void) { ; } -STATIC void wiznet5k_init(void) { +static void wiznet5k_init(void) { // Configure wiznet provided TCP / socket interface reg_dhcp_cbfunc(wiz_dhcp_assign, wiz_dhcp_update, wiz_dhcp_conflict); @@ -394,7 +394,7 @@ STATIC void wiznet5k_init(void) { wiznet5k_obj.active = true; } -STATIC int wiznet5k_gethostbyname(mp_obj_t nic, const char *name, mp_uint_t len, uint8_t *out_ip) { +static int wiznet5k_gethostbyname(mp_obj_t nic, const char *name, mp_uint_t len, uint8_t *out_ip) { uint8_t dns_ip[MOD_NETWORK_IPADDR_BUF_SIZE] = {8, 8, 8, 8}; uint8_t *buf = m_new(uint8_t, MAX_DNS_BUF_SIZE); DNS_init(2, buf); @@ -412,7 +412,7 @@ STATIC int wiznet5k_gethostbyname(mp_obj_t nic, const char *name, mp_uint_t len, } } -STATIC int wiznet5k_socket_socket(mod_network_socket_obj_t *socket, int *_errno) { +static int wiznet5k_socket_socket(mod_network_socket_obj_t *socket, int *_errno) { if (socket->domain != MOD_NETWORK_AF_INET) { *_errno = MP_EAFNOSUPPORT; return -1; @@ -456,7 +456,7 @@ STATIC int wiznet5k_socket_socket(mod_network_socket_obj_t *socket, int *_errno) return 0; } -STATIC void wiznet5k_socket_close(mod_network_socket_obj_t *socket) { +static void wiznet5k_socket_close(mod_network_socket_obj_t *socket) { uint8_t sn = (uint8_t)socket->fileno; if (sn < _WIZCHIP_SOCK_NUM_) { wiznet5k_obj.socket_used &= ~(1 << sn); @@ -464,7 +464,7 @@ STATIC void wiznet5k_socket_close(mod_network_socket_obj_t *socket) { } } -STATIC int wiznet5k_socket_bind(mod_network_socket_obj_t *socket, byte *ip, mp_uint_t port, int *_errno) { +static int wiznet5k_socket_bind(mod_network_socket_obj_t *socket, byte *ip, mp_uint_t port, int *_errno) { // open the socket in server mode (if port != 0) mp_int_t ret = WIZCHIP_EXPORT(socket)(socket->fileno, socket->type, port, 0); if (ret < 0) { @@ -480,7 +480,7 @@ STATIC int wiznet5k_socket_bind(mod_network_socket_obj_t *socket, byte *ip, mp_u return 0; } -STATIC int wiznet5k_socket_listen(mod_network_socket_obj_t *socket, mp_int_t backlog, int *_errno) { +static int wiznet5k_socket_listen(mod_network_socket_obj_t *socket, mp_int_t backlog, int *_errno) { mp_int_t ret = WIZCHIP_EXPORT(listen)(socket->fileno); if (ret < 0) { wiznet5k_socket_close(socket); @@ -490,7 +490,7 @@ STATIC int wiznet5k_socket_listen(mod_network_socket_obj_t *socket, mp_int_t bac return 0; } -STATIC int wiznet5k_socket_accept(mod_network_socket_obj_t *socket, mod_network_socket_obj_t *socket2, byte *ip, mp_uint_t *port, int *_errno) { +static int wiznet5k_socket_accept(mod_network_socket_obj_t *socket, mod_network_socket_obj_t *socket2, byte *ip, mp_uint_t *port, int *_errno) { for (;;) { int sr = getSn_SR((uint8_t)socket->fileno); if (sr == SOCK_ESTABLISHED) { @@ -525,7 +525,7 @@ STATIC int wiznet5k_socket_accept(mod_network_socket_obj_t *socket, mod_network_ } } -STATIC int wiznet5k_socket_connect(mod_network_socket_obj_t *socket, byte *ip, mp_uint_t port, int *_errno) { +static int wiznet5k_socket_connect(mod_network_socket_obj_t *socket, byte *ip, mp_uint_t port, int *_errno) { // use "bind" function to open the socket in client mode if (wiznet5k_socket_bind(socket, ip, 0, _errno) != 0) { return -1; @@ -546,7 +546,7 @@ STATIC int wiznet5k_socket_connect(mod_network_socket_obj_t *socket, byte *ip, m return 0; } -STATIC mp_uint_t wiznet5k_socket_send(mod_network_socket_obj_t *socket, const byte *buf, mp_uint_t len, int *_errno) { +static mp_uint_t wiznet5k_socket_send(mod_network_socket_obj_t *socket, const byte *buf, mp_uint_t len, int *_errno) { MP_THREAD_GIL_EXIT(); mp_int_t ret = WIZCHIP_EXPORT(send)(socket->fileno, (byte *)buf, len); MP_THREAD_GIL_ENTER(); @@ -560,7 +560,7 @@ STATIC mp_uint_t wiznet5k_socket_send(mod_network_socket_obj_t *socket, const by return ret; } -STATIC mp_uint_t wiznet5k_socket_recv(mod_network_socket_obj_t *socket, byte *buf, mp_uint_t len, int *_errno) { +static mp_uint_t wiznet5k_socket_recv(mod_network_socket_obj_t *socket, byte *buf, mp_uint_t len, int *_errno) { MP_THREAD_GIL_EXIT(); mp_int_t ret = WIZCHIP_EXPORT(recv)(socket->fileno, buf, len); MP_THREAD_GIL_ENTER(); @@ -574,7 +574,7 @@ STATIC mp_uint_t wiznet5k_socket_recv(mod_network_socket_obj_t *socket, byte *bu return ret; } -STATIC mp_uint_t wiznet5k_socket_sendto(mod_network_socket_obj_t *socket, const byte *buf, mp_uint_t len, byte *ip, mp_uint_t port, int *_errno) { +static mp_uint_t wiznet5k_socket_sendto(mod_network_socket_obj_t *socket, const byte *buf, mp_uint_t len, byte *ip, mp_uint_t port, int *_errno) { if (socket->domain == 0) { // socket not opened; use "bind" function to open the socket in client mode if (wiznet5k_socket_bind(socket, ip, 0, _errno) != 0) { @@ -594,7 +594,7 @@ STATIC mp_uint_t wiznet5k_socket_sendto(mod_network_socket_obj_t *socket, const return ret; } -STATIC mp_uint_t wiznet5k_socket_recvfrom(mod_network_socket_obj_t *socket, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno) { +static mp_uint_t wiznet5k_socket_recvfrom(mod_network_socket_obj_t *socket, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno) { uint16_t port2; MP_THREAD_GIL_EXIT(); mp_int_t ret = WIZCHIP_EXPORT(recvfrom)(socket->fileno, buf, len, ip, &port2); @@ -608,13 +608,13 @@ STATIC mp_uint_t wiznet5k_socket_recvfrom(mod_network_socket_obj_t *socket, byte return ret; } -STATIC int wiznet5k_socket_setsockopt(mod_network_socket_obj_t *socket, mp_uint_t level, mp_uint_t opt, const void *optval, mp_uint_t optlen, int *_errno) { +static int wiznet5k_socket_setsockopt(mod_network_socket_obj_t *socket, mp_uint_t level, mp_uint_t opt, const void *optval, mp_uint_t optlen, int *_errno) { // TODO *_errno = MP_EINVAL; return -1; } -STATIC int wiznet5k_socket_settimeout(mod_network_socket_obj_t *socket, mp_uint_t timeout_ms, int *_errno) { +static int wiznet5k_socket_settimeout(mod_network_socket_obj_t *socket, mp_uint_t timeout_ms, int *_errno) { // TODO *_errno = MP_EINVAL; return -1; @@ -628,7 +628,7 @@ STATIC int wiznet5k_socket_settimeout(mod_network_socket_obj_t *socket, mp_uint_ */ } -STATIC int wiznet5k_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request, mp_uint_t arg, int *_errno) { +static int wiznet5k_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request, mp_uint_t arg, int *_errno) { if (request == MP_STREAM_POLL) { int ret = 0; if (arg & MP_STREAM_POLL_RD && getSn_RX_RSR(socket->fileno) != 0) { @@ -644,7 +644,7 @@ STATIC int wiznet5k_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t req } } -STATIC void wiznet5k_dhcp_init(wiznet5k_obj_t *self) { +static void wiznet5k_dhcp_init(wiznet5k_obj_t *self) { uint8_t test_buf[2048]; uint8_t ret = 0; uint8_t dhcp_retry = 0; @@ -682,7 +682,7 @@ STATIC void wiznet5k_dhcp_init(wiznet5k_obj_t *self) { // WIZNET5K(spi, pin_cs, pin_rst[, pin_intn]) // Create and return a WIZNET5K object. -STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_obj_base_t *spi; mp_hal_pin_obj_t cs; mp_hal_pin_obj_t rst; @@ -763,7 +763,7 @@ STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, size_t n_args, size // regs() // Dump WIZNET5K registers. -STATIC mp_obj_t wiznet5k_regs(mp_obj_t self_in) { +static mp_obj_t wiznet5k_regs(mp_obj_t self_in) { (void)self_in; printf("Wiz CREG:"); for (int i = 0; i < 0x50; ++i) { @@ -794,9 +794,9 @@ STATIC mp_obj_t wiznet5k_regs(mp_obj_t self_in) { printf("\n"); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(wiznet5k_regs_obj, wiznet5k_regs); +static MP_DEFINE_CONST_FUN_OBJ_1(wiznet5k_regs_obj, wiznet5k_regs); -STATIC mp_obj_t wiznet5k_isconnected(mp_obj_t self_in) { +static mp_obj_t wiznet5k_isconnected(mp_obj_t self_in) { wiznet5k_obj_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_bool( wizphy_getphylink() == PHY_LINK_ON @@ -806,9 +806,9 @@ STATIC mp_obj_t wiznet5k_isconnected(mp_obj_t self_in) { #endif ); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(wiznet5k_isconnected_obj, wiznet5k_isconnected); +static MP_DEFINE_CONST_FUN_OBJ_1(wiznet5k_isconnected_obj, wiznet5k_isconnected); -STATIC mp_obj_t wiznet5k_active(size_t n_args, const mp_obj_t *args) { +static mp_obj_t wiznet5k_active(size_t n_args, const mp_obj_t *args) { wiznet5k_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 1) { return mp_obj_new_bool(IS_ACTIVE(self)); @@ -860,12 +860,12 @@ STATIC mp_obj_t wiznet5k_active(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wiznet5k_active_obj, 1, 2, wiznet5k_active); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wiznet5k_active_obj, 1, 2, wiznet5k_active); #if WIZNET5K_PROVIDED_STACK // ifconfig([(ip, subnet, gateway, dns)]) // Get/set IP address, subnet mask, gateway and DNS. -STATIC mp_obj_t wiznet5k_ifconfig(size_t n_args, const mp_obj_t *args) { +static mp_obj_t wiznet5k_ifconfig(size_t n_args, const mp_obj_t *args) { wiz_NetInfo netinfo; wiznet5k_obj_t *self = MP_OBJ_TO_PTR(args[0]); ctlnetwork(CN_GET_NETINFO, &netinfo); @@ -904,29 +904,29 @@ STATIC mp_obj_t wiznet5k_ifconfig(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wiznet5k_ifconfig_obj, 1, 2, wiznet5k_ifconfig); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wiznet5k_ifconfig_obj, 1, 2, wiznet5k_ifconfig); #endif // WIZNET5K_PROVIDED_STACK #if WIZNET5K_WITH_LWIP_STACK -STATIC mp_obj_t wiznet5k_ifconfig(size_t n_args, const mp_obj_t *args) { +static mp_obj_t wiznet5k_ifconfig(size_t n_args, const mp_obj_t *args) { wiznet5k_obj_t *self = MP_OBJ_TO_PTR(args[0]); return mod_network_nic_ifconfig(&self->netif, n_args - 1, args + 1); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wiznet5k_ifconfig_obj, 1, 2, wiznet5k_ifconfig); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wiznet5k_ifconfig_obj, 1, 2, wiznet5k_ifconfig); -STATIC mp_obj_t send_ethernet_wrapper(mp_obj_t self_in, mp_obj_t buf_in) { +static mp_obj_t send_ethernet_wrapper(mp_obj_t self_in, mp_obj_t buf_in) { wiznet5k_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_buffer_info_t buf; mp_get_buffer_raise(buf_in, &buf, MP_BUFFER_READ); wiznet5k_send_ethernet(self, buf.len, buf.buf); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(send_ethernet_obj, send_ethernet_wrapper); +static MP_DEFINE_CONST_FUN_OBJ_2(send_ethernet_obj, send_ethernet_wrapper); #endif // MICROPY_PY_LWIP -STATIC mp_obj_t wiznet5k_status(size_t n_args, const mp_obj_t *args) { +static mp_obj_t wiznet5k_status(size_t n_args, const mp_obj_t *args) { wiznet5k_obj_t *self = MP_OBJ_TO_PTR(args[0]); (void)self; @@ -944,9 +944,9 @@ STATIC mp_obj_t wiznet5k_status(size_t n_args, const mp_obj_t *args) { } mp_raise_ValueError(MP_ERROR_TEXT("unknown status param")); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wiznet5k_status_obj, 1, 2, wiznet5k_status); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wiznet5k_status_obj, 1, 2, wiznet5k_status); -STATIC mp_obj_t wiznet5k_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { +static mp_obj_t wiznet5k_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { wiznet5k_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (kwargs->used == 0) { @@ -1001,9 +1001,9 @@ STATIC mp_obj_t wiznet5k_config(size_t n_args, const mp_obj_t *args, mp_map_t *k return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wiznet5k_config_obj, 1, wiznet5k_config); +static MP_DEFINE_CONST_FUN_OBJ_KW(wiznet5k_config_obj, 1, wiznet5k_config); -STATIC const mp_rom_map_elem_t wiznet5k_locals_dict_table[] = { +static const mp_rom_map_elem_t wiznet5k_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_regs), MP_ROM_PTR(&wiznet5k_regs_obj) }, { MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&wiznet5k_isconnected_obj) }, { MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&wiznet5k_active_obj) }, @@ -1014,7 +1014,7 @@ STATIC const mp_rom_map_elem_t wiznet5k_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_send_ethernet), MP_ROM_PTR(&send_ethernet_obj) }, #endif }; -STATIC MP_DEFINE_CONST_DICT(wiznet5k_locals_dict, wiznet5k_locals_dict_table); +static MP_DEFINE_CONST_DICT(wiznet5k_locals_dict, wiznet5k_locals_dict_table); #if WIZNET5K_WITH_LWIP_STACK #define NIC_TYPE_WIZNET_PROTOCOL diff --git a/extmod/nimble/hal/hal_uart.c b/extmod/nimble/hal/hal_uart.c index f4a9319c8b5fa..b57117878400c 100644 --- a/extmod/nimble/hal/hal_uart.c +++ b/extmod/nimble/hal/hal_uart.c @@ -93,7 +93,7 @@ int hal_uart_close(uint32_t port) { return 0; // success } -STATIC void mp_bluetooth_hci_uart_char_cb(uint8_t chr) { +static void mp_bluetooth_hci_uart_char_cb(uint8_t chr) { #if HCI_TRACE printf(COL_BLUE "> [% 8d] %02x" COL_OFF "\n", (int)mp_hal_ticks_ms(), chr); #endif diff --git a/extmod/nimble/modbluetooth_nimble.c b/extmod/nimble/modbluetooth_nimble.c index 5bab43a0ccea0..92bc6764edc63 100644 --- a/extmod/nimble/modbluetooth_nimble.c +++ b/extmod/nimble/modbluetooth_nimble.c @@ -57,12 +57,12 @@ #define ERRNO_BLUETOOTH_NOT_ACTIVE MP_ENODEV -STATIC uint8_t nimble_address_mode = BLE_OWN_ADDR_RANDOM; +static uint8_t nimble_address_mode = BLE_OWN_ADDR_RANDOM; #define NIMBLE_STARTUP_TIMEOUT 2000 // Any BLE_HS_xxx code not in this table will default to MP_EIO. -STATIC int8_t ble_hs_err_to_errno_table[] = { +static int8_t ble_hs_err_to_errno_table[] = { [BLE_HS_EAGAIN] = MP_EAGAIN, [BLE_HS_EALREADY] = MP_EALREADY, [BLE_HS_EINVAL] = MP_EINVAL, @@ -76,70 +76,70 @@ STATIC int8_t ble_hs_err_to_errno_table[] = { [BLE_HS_EBADDATA] = MP_EINVAL, }; -STATIC int ble_hs_err_to_errno(int err); +static int ble_hs_err_to_errno(int err); -STATIC ble_uuid_t *create_nimble_uuid(const mp_obj_bluetooth_uuid_t *uuid, ble_uuid_any_t *storage); -STATIC void reverse_addr_byte_order(uint8_t *addr_out, const uint8_t *addr_in); +static ble_uuid_t *create_nimble_uuid(const mp_obj_bluetooth_uuid_t *uuid, ble_uuid_any_t *storage); +static void reverse_addr_byte_order(uint8_t *addr_out, const uint8_t *addr_in); #if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE -STATIC mp_obj_bluetooth_uuid_t create_mp_uuid(const ble_uuid_any_t *uuid); -STATIC ble_addr_t create_nimble_addr(uint8_t addr_type, const uint8_t *addr); +static mp_obj_bluetooth_uuid_t create_mp_uuid(const ble_uuid_any_t *uuid); +static ble_addr_t create_nimble_addr(uint8_t addr_type, const uint8_t *addr); #endif -STATIC void reset_cb(int reason); +static void reset_cb(int reason); -STATIC bool has_public_address(void); -STATIC void set_random_address(bool nrpa); +static bool has_public_address(void); +static void set_random_address(bool nrpa); #if MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING -STATIC int load_irk(void); +static int load_irk(void); #endif -STATIC void sync_cb(void); +static void sync_cb(void); #if !MICROPY_BLUETOOTH_NIMBLE_BINDINGS_ONLY -STATIC void ble_hs_shutdown_stop_cb(int status, void *arg); +static void ble_hs_shutdown_stop_cb(int status, void *arg); #endif // Successfully registered service/char/desc handles. -STATIC void gatts_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg); +static void gatts_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg); // Events about a connected central (we're in peripheral role). -STATIC int central_gap_event_cb(struct ble_gap_event *event, void *arg); +static int central_gap_event_cb(struct ble_gap_event *event, void *arg); #if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE // Events about a connected peripheral (we're in central role). -STATIC int peripheral_gap_event_cb(struct ble_gap_event *event, void *arg); +static int peripheral_gap_event_cb(struct ble_gap_event *event, void *arg); #endif // Used by both of the above. -STATIC int commmon_gap_event_cb(struct ble_gap_event *event, void *arg); +static int commmon_gap_event_cb(struct ble_gap_event *event, void *arg); #if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE // Scan results. -STATIC int gap_scan_cb(struct ble_gap_event *event, void *arg); +static int gap_scan_cb(struct ble_gap_event *event, void *arg); #endif #if MICROPY_PY_BLUETOOTH_ENABLE_GATT_CLIENT // Data available (either due to notify/indicate or successful read). -STATIC void gattc_on_data_available(uint8_t event, uint16_t conn_handle, uint16_t value_handle, const struct os_mbuf *om); +static void gattc_on_data_available(uint8_t event, uint16_t conn_handle, uint16_t value_handle, const struct os_mbuf *om); // Client discovery callbacks. -STATIC int ble_gattc_service_cb(uint16_t conn_handle, const struct ble_gatt_error *error, const struct ble_gatt_svc *service, void *arg); -STATIC int ble_gattc_characteristic_cb(uint16_t conn_handle, const struct ble_gatt_error *error, const struct ble_gatt_chr *characteristic, void *arg); -STATIC int ble_gattc_descriptor_cb(uint16_t conn_handle, const struct ble_gatt_error *error, uint16_t characteristic_val_handle, const struct ble_gatt_dsc *descriptor, void *arg); +static int ble_gattc_service_cb(uint16_t conn_handle, const struct ble_gatt_error *error, const struct ble_gatt_svc *service, void *arg); +static int ble_gattc_characteristic_cb(uint16_t conn_handle, const struct ble_gatt_error *error, const struct ble_gatt_chr *characteristic, void *arg); +static int ble_gattc_descriptor_cb(uint16_t conn_handle, const struct ble_gatt_error *error, uint16_t characteristic_val_handle, const struct ble_gatt_dsc *descriptor, void *arg); // Client read/write handlers. -STATIC int ble_gattc_attr_read_cb(uint16_t conn_handle, const struct ble_gatt_error *error, struct ble_gatt_attr *attr, void *arg); -STATIC int ble_gattc_attr_write_cb(uint16_t conn_handle, const struct ble_gatt_error *error, struct ble_gatt_attr *attr, void *arg); +static int ble_gattc_attr_read_cb(uint16_t conn_handle, const struct ble_gatt_error *error, struct ble_gatt_attr *attr, void *arg); +static int ble_gattc_attr_write_cb(uint16_t conn_handle, const struct ble_gatt_error *error, struct ble_gatt_attr *attr, void *arg); #endif #if MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING // Bonding store. -STATIC int ble_secret_store_read(int obj_type, const union ble_store_key *key, union ble_store_value *value); -STATIC int ble_secret_store_write(int obj_type, const union ble_store_value *val); -STATIC int ble_secret_store_delete(int obj_type, const union ble_store_key *key); +static int ble_secret_store_read(int obj_type, const union ble_store_key *key, union ble_store_value *value); +static int ble_secret_store_write(int obj_type, const union ble_store_value *val); +static int ble_secret_store_delete(int obj_type, const union ble_store_key *key); #endif -STATIC int ble_hs_err_to_errno(int err) { +static int ble_hs_err_to_errno(int err) { DEBUG_printf("ble_hs_err_to_errno: %d\n", err); if (!err) { return 0; @@ -154,7 +154,7 @@ STATIC int ble_hs_err_to_errno(int err) { } // Note: modbluetooth UUIDs store their data in LE. -STATIC ble_uuid_t *create_nimble_uuid(const mp_obj_bluetooth_uuid_t *uuid, ble_uuid_any_t *storage) { +static ble_uuid_t *create_nimble_uuid(const mp_obj_bluetooth_uuid_t *uuid, ble_uuid_any_t *storage) { if (uuid->type == MP_BLUETOOTH_UUID_TYPE_16) { ble_uuid16_t *result = storage ? &storage->u16 : m_new(ble_uuid16_t, 1); result->u.type = BLE_UUID_TYPE_16; @@ -176,7 +176,7 @@ STATIC ble_uuid_t *create_nimble_uuid(const mp_obj_bluetooth_uuid_t *uuid, ble_u } // modbluetooth (and the layers above it) work in BE for addresses, Nimble works in LE. -STATIC void reverse_addr_byte_order(uint8_t *addr_out, const uint8_t *addr_in) { +static void reverse_addr_byte_order(uint8_t *addr_out, const uint8_t *addr_in) { for (int i = 0; i < 6; ++i) { addr_out[i] = addr_in[5 - i]; } @@ -184,7 +184,7 @@ STATIC void reverse_addr_byte_order(uint8_t *addr_out, const uint8_t *addr_in) { #if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE -STATIC mp_obj_bluetooth_uuid_t create_mp_uuid(const ble_uuid_any_t *uuid) { +static mp_obj_bluetooth_uuid_t create_mp_uuid(const ble_uuid_any_t *uuid) { mp_obj_bluetooth_uuid_t result; result.base.type = &mp_type_bluetooth_uuid; switch (uuid->u.type) { @@ -210,7 +210,7 @@ STATIC mp_obj_bluetooth_uuid_t create_mp_uuid(const ble_uuid_any_t *uuid) { return result; } -STATIC ble_addr_t create_nimble_addr(uint8_t addr_type, const uint8_t *addr) { +static ble_addr_t create_nimble_addr(uint8_t addr_type, const uint8_t *addr) { ble_addr_t addr_nimble; addr_nimble.type = addr_type; // Incoming addr is from modbluetooth (BE), so copy and convert to LE for Nimble. @@ -222,15 +222,15 @@ STATIC ble_addr_t create_nimble_addr(uint8_t addr_type, const uint8_t *addr) { volatile int mp_bluetooth_nimble_ble_state = MP_BLUETOOTH_NIMBLE_BLE_STATE_OFF; -STATIC void reset_cb(int reason) { +static void reset_cb(int reason) { (void)reason; } -STATIC bool has_public_address(void) { +static bool has_public_address(void) { return ble_hs_id_copy_addr(BLE_ADDR_PUBLIC, NULL, NULL) == 0; } -STATIC void set_random_address(bool nrpa) { +static void set_random_address(bool nrpa) { int rc; (void)rc; ble_addr_t addr; @@ -274,7 +274,7 @@ STATIC void set_random_address(bool nrpa) { // Must be distinct to BLE_STORE_OBJ_TYPE_ in ble_store.h. #define SECRET_TYPE_OUR_IRK 10 -STATIC int load_irk(void) { +static int load_irk(void) { // NimBLE unconditionally loads a fixed IRK on startup. // See https://github.com/apache/mynewt-nimble/issues/887 @@ -318,7 +318,7 @@ STATIC int load_irk(void) { } #endif -STATIC void sync_cb(void) { +static void sync_cb(void) { int rc; (void)rc; @@ -349,7 +349,7 @@ STATIC void sync_cb(void) { mp_bluetooth_nimble_ble_state = MP_BLUETOOTH_NIMBLE_BLE_STATE_ACTIVE; } -STATIC void gatts_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg) { +static void gatts_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg) { if (!mp_bluetooth_is_active()) { return; } @@ -390,7 +390,7 @@ STATIC void gatts_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg) { } } -STATIC int commmon_gap_event_cb(struct ble_gap_event *event, void *arg) { +static int commmon_gap_event_cb(struct ble_gap_event *event, void *arg) { struct ble_gap_conn_desc desc; switch (event->type) { @@ -436,7 +436,7 @@ STATIC int commmon_gap_event_cb(struct ble_gap_event *event, void *arg) { } } -STATIC int central_gap_event_cb(struct ble_gap_event *event, void *arg) { +static int central_gap_event_cb(struct ble_gap_event *event, void *arg) { DEBUG_printf("central_gap_event_cb: type=%d\n", event->type); if (!mp_bluetooth_is_active()) { return 0; @@ -546,13 +546,13 @@ void mp_bluetooth_nimble_port_start(void) { } // Called when the host stop procedure has completed. -STATIC void ble_hs_shutdown_stop_cb(int status, void *arg) { +static void ble_hs_shutdown_stop_cb(int status, void *arg) { (void)status; (void)arg; mp_bluetooth_nimble_ble_state = MP_BLUETOOTH_NIMBLE_BLE_STATE_OFF; } -STATIC struct ble_hs_stop_listener ble_hs_shutdown_stop_listener; +static struct ble_hs_stop_listener ble_hs_shutdown_stop_listener; void mp_bluetooth_nimble_port_shutdown(void) { DEBUG_printf("mp_bluetooth_nimble_port_shutdown (nimble default)\n"); @@ -1127,7 +1127,7 @@ int mp_bluetooth_gap_passkey(uint16_t conn_handle, uint8_t action, mp_int_t pass #if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE -STATIC int gap_scan_cb(struct ble_gap_event *event, void *arg) { +static int gap_scan_cb(struct ble_gap_event *event, void *arg) { DEBUG_printf("gap_scan_cb: event=%d type=%d\n", event->type, event->type == BLE_GAP_EVENT_DISC ? event->disc.event_type : -1); if (!mp_bluetooth_is_active()) { return 0; @@ -1185,7 +1185,7 @@ int mp_bluetooth_gap_scan_stop(void) { } // Central role: GAP events for a connected peripheral. -STATIC int peripheral_gap_event_cb(struct ble_gap_event *event, void *arg) { +static int peripheral_gap_event_cb(struct ble_gap_event *event, void *arg) { DEBUG_printf("peripheral_gap_event_cb: event=%d\n", event->type); if (!mp_bluetooth_is_active()) { return 0; @@ -1255,7 +1255,7 @@ int mp_bluetooth_gap_peripheral_connect_cancel(void) { return ble_hs_err_to_errno(err); } -STATIC int ble_gattc_service_cb(uint16_t conn_handle, const struct ble_gatt_error *error, const struct ble_gatt_svc *service, void *arg) { +static int ble_gattc_service_cb(uint16_t conn_handle, const struct ble_gatt_error *error, const struct ble_gatt_svc *service, void *arg) { DEBUG_printf("ble_gattc_service_cb: conn_handle=%d status=%d start_handle=%d\n", conn_handle, error->status, service ? service->start_handle : -1); if (!mp_bluetooth_is_active()) { return 0; @@ -1273,7 +1273,7 @@ STATIC int ble_gattc_service_cb(uint16_t conn_handle, const struct ble_gatt_erro #if MICROPY_PY_BLUETOOTH_ENABLE_GATT_CLIENT -STATIC void gattc_on_data_available(uint8_t event, uint16_t conn_handle, uint16_t value_handle, const struct os_mbuf *om) { +static void gattc_on_data_available(uint8_t event, uint16_t conn_handle, uint16_t value_handle, const struct os_mbuf *om) { // When the HCI data for an ATT payload arrives, the L2CAP channel will // buffer it into its receive buffer. We set BLE_L2CAP_JOIN_RX_FRAGS=1 in // syscfg.h so it should be rare that the mbuf is fragmented, but we do need @@ -1320,7 +1320,7 @@ int mp_bluetooth_gattc_discover_primary_services(uint16_t conn_handle, const mp_ return ble_hs_err_to_errno(err); } -STATIC bool match_char_uuid(const mp_obj_bluetooth_uuid_t *filter_uuid, const ble_uuid_any_t *result_uuid) { +static bool match_char_uuid(const mp_obj_bluetooth_uuid_t *filter_uuid, const ble_uuid_any_t *result_uuid) { if (!filter_uuid) { return true; } @@ -1329,7 +1329,7 @@ STATIC bool match_char_uuid(const mp_obj_bluetooth_uuid_t *filter_uuid, const bl return ble_uuid_cmp(&result_uuid->u, &filter_uuid_nimble.u) == 0; } -STATIC int ble_gattc_characteristic_cb(uint16_t conn_handle, const struct ble_gatt_error *error, const struct ble_gatt_chr *characteristic, void *arg) { +static int ble_gattc_characteristic_cb(uint16_t conn_handle, const struct ble_gatt_error *error, const struct ble_gatt_chr *characteristic, void *arg) { DEBUG_printf("ble_gattc_characteristic_cb: conn_handle=%d status=%d def_handle=%d val_handle=%d\n", conn_handle, error->status, characteristic ? characteristic->def_handle : -1, characteristic ? characteristic->val_handle : -1); if (!mp_bluetooth_is_active()) { return 0; @@ -1401,7 +1401,7 @@ int mp_bluetooth_gattc_discover_characteristics(uint16_t conn_handle, uint16_t s return ble_hs_err_to_errno(err); } -STATIC int ble_gattc_descriptor_cb(uint16_t conn_handle, const struct ble_gatt_error *error, uint16_t characteristic_val_handle, const struct ble_gatt_dsc *descriptor, void *arg) { +static int ble_gattc_descriptor_cb(uint16_t conn_handle, const struct ble_gatt_error *error, uint16_t characteristic_val_handle, const struct ble_gatt_dsc *descriptor, void *arg) { DEBUG_printf("ble_gattc_descriptor_cb: conn_handle=%d status=%d chr_handle=%d dsc_handle=%d\n", conn_handle, error->status, characteristic_val_handle, descriptor ? descriptor->handle : -1); if (!mp_bluetooth_is_active()) { return 0; @@ -1423,7 +1423,7 @@ int mp_bluetooth_gattc_discover_descriptors(uint16_t conn_handle, uint16_t start return ble_hs_err_to_errno(err); } -STATIC int ble_gattc_attr_read_cb(uint16_t conn_handle, const struct ble_gatt_error *error, struct ble_gatt_attr *attr, void *arg) { +static int ble_gattc_attr_read_cb(uint16_t conn_handle, const struct ble_gatt_error *error, struct ble_gatt_attr *attr, void *arg) { uint16_t handle = attr ? attr->handle : (error ? error->att_handle : 0xffff); DEBUG_printf("ble_gattc_attr_read_cb: conn_handle=%d status=%d handle=%d\n", conn_handle, error->status, handle); if (!mp_bluetooth_is_active()) { @@ -1445,7 +1445,7 @@ int mp_bluetooth_gattc_read(uint16_t conn_handle, uint16_t value_handle) { return ble_hs_err_to_errno(err); } -STATIC int ble_gattc_attr_write_cb(uint16_t conn_handle, const struct ble_gatt_error *error, struct ble_gatt_attr *attr, void *arg) { +static int ble_gattc_attr_write_cb(uint16_t conn_handle, const struct ble_gatt_error *error, struct ble_gatt_attr *attr, void *arg) { uint16_t handle = attr ? attr->handle : (error ? error->att_handle : 0xffff); DEBUG_printf("ble_gattc_attr_write_cb: conn_handle=%d status=%d handle=%d\n", conn_handle, error->status, handle); if (!mp_bluetooth_is_active()) { @@ -1481,7 +1481,7 @@ int mp_bluetooth_gattc_exchange_mtu(uint16_t conn_handle) { #endif // MICROPY_PY_BLUETOOTH_ENABLE_GATT_CLIENT #if MICROPY_PY_BLUETOOTH_ENABLE_L2CAP_CHANNELS -STATIC void unstall_l2cap_channel(void); +static void unstall_l2cap_channel(void); #endif void mp_bluetooth_nimble_sent_hci_packet(void) { @@ -1518,12 +1518,12 @@ typedef struct _mp_bluetooth_nimble_l2cap_channel_t { os_membuf_t sdu_mem[]; } mp_bluetooth_nimble_l2cap_channel_t; -STATIC void destroy_l2cap_channel(); -STATIC int l2cap_channel_event(struct ble_l2cap_event *event, void *arg); -STATIC mp_bluetooth_nimble_l2cap_channel_t *get_l2cap_channel_for_conn_cid(uint16_t conn_handle, uint16_t cid); -STATIC int create_l2cap_channel(uint16_t mtu, mp_bluetooth_nimble_l2cap_channel_t **out); +static void destroy_l2cap_channel(); +static int l2cap_channel_event(struct ble_l2cap_event *event, void *arg); +static mp_bluetooth_nimble_l2cap_channel_t *get_l2cap_channel_for_conn_cid(uint16_t conn_handle, uint16_t cid); +static int create_l2cap_channel(uint16_t mtu, mp_bluetooth_nimble_l2cap_channel_t **out); -STATIC void destroy_l2cap_channel() { +static void destroy_l2cap_channel() { // Only free the l2cap channel if we're the one that initiated the connection. // Listeners continue listening on the same channel. if (!MP_STATE_PORT(bluetooth_nimble_root_pointers)->l2cap_listening) { @@ -1531,7 +1531,7 @@ STATIC void destroy_l2cap_channel() { } } -STATIC void unstall_l2cap_channel(void) { +static void unstall_l2cap_channel(void) { // Whenever we send an HCI packet and the sys mempool is now less than 1/4 full, // we can un-stall the L2CAP channel if it was marked as "mem_stalled" by // mp_bluetooth_l2cap_send. (This happens if the pool is half-empty). @@ -1544,7 +1544,7 @@ STATIC void unstall_l2cap_channel(void) { mp_bluetooth_on_l2cap_send_ready(chan->chan->conn_handle, chan->chan->scid, 0); } -STATIC int l2cap_channel_event(struct ble_l2cap_event *event, void *arg) { +static int l2cap_channel_event(struct ble_l2cap_event *event, void *arg) { DEBUG_printf("l2cap_channel_event: type=%d\n", event->type); mp_bluetooth_nimble_l2cap_channel_t *chan = (mp_bluetooth_nimble_l2cap_channel_t *)arg; struct ble_l2cap_chan_info info; @@ -1665,7 +1665,7 @@ STATIC int l2cap_channel_event(struct ble_l2cap_event *event, void *arg) { return 0; } -STATIC mp_bluetooth_nimble_l2cap_channel_t *get_l2cap_channel_for_conn_cid(uint16_t conn_handle, uint16_t cid) { +static mp_bluetooth_nimble_l2cap_channel_t *get_l2cap_channel_for_conn_cid(uint16_t conn_handle, uint16_t cid) { // TODO: Support more than one concurrent L2CAP channel. At the moment we // just verify that the cid refers to the current channel. mp_bluetooth_nimble_l2cap_channel_t *chan = MP_STATE_PORT(bluetooth_nimble_root_pointers)->l2cap_chan; @@ -1684,7 +1684,7 @@ STATIC mp_bluetooth_nimble_l2cap_channel_t *get_l2cap_channel_for_conn_cid(uint1 return chan; } -STATIC int create_l2cap_channel(uint16_t mtu, mp_bluetooth_nimble_l2cap_channel_t **out) { +static int create_l2cap_channel(uint16_t mtu, mp_bluetooth_nimble_l2cap_channel_t **out) { if (MP_STATE_PORT(bluetooth_nimble_root_pointers)->l2cap_chan) { // Only one L2CAP channel allowed. // Additionally, if we're listening, then no connections may be initiated. @@ -1897,7 +1897,7 @@ int mp_bluetooth_hci_cmd(uint16_t ogf, uint16_t ocf, const uint8_t *req, size_t #if MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING -STATIC int ble_secret_store_read(int obj_type, const union ble_store_key *key, union ble_store_value *value) { +static int ble_secret_store_read(int obj_type, const union ble_store_key *key, union ble_store_value *value) { DEBUG_printf("ble_secret_store_read: %d\n", obj_type); const uint8_t *key_data; size_t key_data_len; @@ -1962,7 +1962,7 @@ STATIC int ble_secret_store_read(int obj_type, const union ble_store_key *key, u return 0; } -STATIC int ble_secret_store_write(int obj_type, const union ble_store_value *val) { +static int ble_secret_store_write(int obj_type, const union ble_store_value *val) { DEBUG_printf("ble_secret_store_write: %d\n", obj_type); switch (obj_type) { case BLE_STORE_OBJ_TYPE_PEER_SEC: @@ -1996,7 +1996,7 @@ STATIC int ble_secret_store_write(int obj_type, const union ble_store_value *val } } -STATIC int ble_secret_store_delete(int obj_type, const union ble_store_key *key) { +static int ble_secret_store_delete(int obj_type, const union ble_store_key *key) { DEBUG_printf("ble_secret_store_delete: %d\n", obj_type); switch (obj_type) { case BLE_STORE_OBJ_TYPE_PEER_SEC: diff --git a/extmod/nimble/nimble/nimble_npl_os.c b/extmod/nimble/nimble/nimble_npl_os.c index b68957fabf385..0dc80482c42cc 100644 --- a/extmod/nimble/nimble/nimble_npl_os.c +++ b/extmod/nimble/nimble/nimble_npl_os.c @@ -67,7 +67,7 @@ typedef struct _mp_bluetooth_nimble_malloc_t { } mp_bluetooth_nimble_malloc_t; // TODO: This is duplicated from mbedtls. Perhaps make this a generic feature? -STATIC void *m_malloc_bluetooth(size_t size) { +static void *m_malloc_bluetooth(size_t size) { size += sizeof(mp_bluetooth_nimble_malloc_t); mp_bluetooth_nimble_malloc_t *alloc = m_malloc0(size); alloc->size = size; @@ -79,11 +79,11 @@ STATIC void *m_malloc_bluetooth(size_t size) { return alloc->data; } -STATIC mp_bluetooth_nimble_malloc_t* get_nimble_malloc(void *ptr) { +static mp_bluetooth_nimble_malloc_t* get_nimble_malloc(void *ptr) { return (mp_bluetooth_nimble_malloc_t*)((uintptr_t)ptr - sizeof(mp_bluetooth_nimble_malloc_t)); } -STATIC void m_free_bluetooth(void *ptr) { +static void m_free_bluetooth(void *ptr) { mp_bluetooth_nimble_malloc_t *alloc = get_nimble_malloc(ptr); if (alloc->next) { alloc->next->prev = alloc->prev; @@ -102,7 +102,7 @@ STATIC void m_free_bluetooth(void *ptr) { // Check if a nimble ptr is tracked. // If it isn't, that means that it's from a previous soft-reset cycle. -STATIC bool is_valid_nimble_malloc(void *ptr) { +static bool is_valid_nimble_malloc(void *ptr) { DEBUG_MALLOC_printf("NIMBLE is_valid_nimble_malloc(%p)\n", ptr); mp_bluetooth_nimble_malloc_t *alloc = MP_STATE_PORT(bluetooth_nimble_memory); while (alloc) { diff --git a/extmod/os_dupterm.c b/extmod/os_dupterm.c index dcd9c54b998e1..156766a43c508 100644 --- a/extmod/os_dupterm.c +++ b/extmod/os_dupterm.c @@ -208,7 +208,7 @@ int mp_os_dupterm_tx_strn(const char *str, size_t len) { return did_write ? ret : -1; } -STATIC mp_obj_t mp_os_dupterm(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_os_dupterm(size_t n_args, const mp_obj_t *args) { mp_int_t idx = 0; if (n_args == 2) { idx = mp_obj_get_int(args[1]); diff --git a/extmod/vfs.c b/extmod/vfs.c index af63ceb37eb19..ae09b8afe8d08 100644 --- a/extmod/vfs.c +++ b/extmod/vfs.c @@ -93,7 +93,7 @@ mp_vfs_mount_t *mp_vfs_lookup_path(const char *path, const char **path_out) { } // Version of mp_vfs_lookup_path that takes and returns uPy string objects. -STATIC mp_vfs_mount_t *lookup_path(mp_obj_t path_in, mp_obj_t *path_out) { +static mp_vfs_mount_t *lookup_path(mp_obj_t path_in, mp_obj_t *path_out) { const char *path = mp_obj_str_get_str(path_in); const char *p_out; mp_vfs_mount_t *vfs = mp_vfs_lookup_path(path, &p_out); @@ -106,7 +106,7 @@ STATIC mp_vfs_mount_t *lookup_path(mp_obj_t path_in, mp_obj_t *path_out) { return vfs; } -STATIC mp_obj_t mp_vfs_proxy_call(mp_vfs_mount_t *vfs, qstr meth_name, size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_vfs_proxy_call(mp_vfs_mount_t *vfs, qstr meth_name, size_t n_args, const mp_obj_t *args) { assert(n_args <= PROXY_MAX_ARGS); if (vfs == MP_VFS_NONE) { // mount point not found @@ -159,7 +159,7 @@ mp_import_stat_t mp_vfs_import_stat(const char *path) { } } -STATIC mp_obj_t mp_vfs_autodetect(mp_obj_t bdev_obj) { +static mp_obj_t mp_vfs_autodetect(mp_obj_t bdev_obj) { #if MICROPY_VFS_LFS1 || MICROPY_VFS_LFS2 nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { @@ -376,7 +376,7 @@ typedef struct _mp_vfs_ilistdir_it_t { bool is_iter; } mp_vfs_ilistdir_it_t; -STATIC mp_obj_t mp_vfs_ilistdir_it_iternext(mp_obj_t self_in) { +static mp_obj_t mp_vfs_ilistdir_it_iternext(mp_obj_t self_in) { mp_vfs_ilistdir_it_t *self = MP_OBJ_TO_PTR(self_in); if (self->is_iter) { // continue delegating to root dir diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index 67c95d9a1712b..38c16633630e5 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -51,7 +51,7 @@ #define mp_obj_fat_vfs_t fs_user_mount_t -STATIC mp_import_stat_t fat_vfs_import_stat(void *vfs_in, const char *path) { +static mp_import_stat_t fat_vfs_import_stat(void *vfs_in, const char *path) { fs_user_mount_t *vfs = vfs_in; FILINFO fno; assert(vfs != NULL); @@ -66,7 +66,7 @@ STATIC mp_import_stat_t fat_vfs_import_stat(void *vfs_in, const char *path) { return MP_IMPORT_STAT_NO_EXIST; } -STATIC mp_obj_t fat_vfs_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t fat_vfs_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 1, false); // create new object @@ -91,16 +91,16 @@ STATIC mp_obj_t fat_vfs_make_new(const mp_obj_type_t *type, size_t n_args, size_ } #if _FS_REENTRANT -STATIC mp_obj_t fat_vfs_del(mp_obj_t self_in) { +static mp_obj_t fat_vfs_del(mp_obj_t self_in) { mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(self_in); // f_umount only needs to be called to release the sync object f_umount(&self->fatfs); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_del_obj, fat_vfs_del); +static MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_del_obj, fat_vfs_del); #endif -STATIC mp_obj_t fat_vfs_mkfs(mp_obj_t bdev_in) { +static mp_obj_t fat_vfs_mkfs(mp_obj_t bdev_in) { // create new object fs_user_mount_t *vfs = MP_OBJ_TO_PTR(fat_vfs_make_new(&mp_fat_vfs_type, 1, 0, &bdev_in)); @@ -116,8 +116,8 @@ STATIC mp_obj_t fat_vfs_mkfs(mp_obj_t bdev_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_mkfs_fun_obj, fat_vfs_mkfs); -STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(fat_vfs_mkfs_obj, MP_ROM_PTR(&fat_vfs_mkfs_fun_obj)); +static MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_mkfs_fun_obj, fat_vfs_mkfs); +static MP_DEFINE_CONST_STATICMETHOD_OBJ(fat_vfs_mkfs_obj, MP_ROM_PTR(&fat_vfs_mkfs_fun_obj)); typedef struct _mp_vfs_fat_ilistdir_it_t { mp_obj_base_t base; @@ -127,7 +127,7 @@ typedef struct _mp_vfs_fat_ilistdir_it_t { FF_DIR dir; } mp_vfs_fat_ilistdir_it_t; -STATIC mp_obj_t mp_vfs_fat_ilistdir_it_iternext(mp_obj_t self_in) { +static mp_obj_t mp_vfs_fat_ilistdir_it_iternext(mp_obj_t self_in) { mp_vfs_fat_ilistdir_it_t *self = MP_OBJ_TO_PTR(self_in); for (;;) { @@ -167,14 +167,14 @@ STATIC mp_obj_t mp_vfs_fat_ilistdir_it_iternext(mp_obj_t self_in) { return MP_OBJ_STOP_ITERATION; } -STATIC mp_obj_t mp_vfs_fat_ilistdir_it_del(mp_obj_t self_in) { +static mp_obj_t mp_vfs_fat_ilistdir_it_del(mp_obj_t self_in) { mp_vfs_fat_ilistdir_it_t *self = MP_OBJ_TO_PTR(self_in); // ignore result / error because we may be closing a second time. f_closedir(&self->dir); return mp_const_none; } -STATIC mp_obj_t fat_vfs_ilistdir_func(size_t n_args, const mp_obj_t *args) { +static mp_obj_t fat_vfs_ilistdir_func(size_t n_args, const mp_obj_t *args) { mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(args[0]); bool is_str_type = true; const char *path; @@ -199,9 +199,9 @@ STATIC mp_obj_t fat_vfs_ilistdir_func(size_t n_args, const mp_obj_t *args) { return MP_OBJ_FROM_PTR(iter); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fat_vfs_ilistdir_obj, 1, 2, fat_vfs_ilistdir_func); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fat_vfs_ilistdir_obj, 1, 2, fat_vfs_ilistdir_func); -STATIC mp_obj_t fat_vfs_remove_internal(mp_obj_t vfs_in, mp_obj_t path_in, mp_int_t attr) { +static mp_obj_t fat_vfs_remove_internal(mp_obj_t vfs_in, mp_obj_t path_in, mp_int_t attr) { mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(vfs_in); const char *path = mp_obj_str_get_str(path_in); @@ -225,17 +225,17 @@ STATIC mp_obj_t fat_vfs_remove_internal(mp_obj_t vfs_in, mp_obj_t path_in, mp_in } } -STATIC mp_obj_t fat_vfs_remove(mp_obj_t vfs_in, mp_obj_t path_in) { +static mp_obj_t fat_vfs_remove(mp_obj_t vfs_in, mp_obj_t path_in) { return fat_vfs_remove_internal(vfs_in, path_in, 0); // 0 == file attribute } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_remove_obj, fat_vfs_remove); +static MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_remove_obj, fat_vfs_remove); -STATIC mp_obj_t fat_vfs_rmdir(mp_obj_t vfs_in, mp_obj_t path_in) { +static mp_obj_t fat_vfs_rmdir(mp_obj_t vfs_in, mp_obj_t path_in) { return fat_vfs_remove_internal(vfs_in, path_in, AM_DIR); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_rmdir_obj, fat_vfs_rmdir); +static MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_rmdir_obj, fat_vfs_rmdir); -STATIC mp_obj_t fat_vfs_rename(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t path_out) { +static mp_obj_t fat_vfs_rename(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t path_out) { mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(vfs_in); const char *old_path = mp_obj_str_get_str(path_in); const char *new_path = mp_obj_str_get_str(path_out); @@ -253,9 +253,9 @@ STATIC mp_obj_t fat_vfs_rename(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t path_ } } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(fat_vfs_rename_obj, fat_vfs_rename); +static MP_DEFINE_CONST_FUN_OBJ_3(fat_vfs_rename_obj, fat_vfs_rename); -STATIC mp_obj_t fat_vfs_mkdir(mp_obj_t vfs_in, mp_obj_t path_o) { +static mp_obj_t fat_vfs_mkdir(mp_obj_t vfs_in, mp_obj_t path_o) { mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(vfs_in); const char *path = mp_obj_str_get_str(path_o); FRESULT res = f_mkdir(&self->fatfs, path); @@ -265,10 +265,10 @@ STATIC mp_obj_t fat_vfs_mkdir(mp_obj_t vfs_in, mp_obj_t path_o) { mp_raise_OSError(fresult_to_errno_table[res]); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_mkdir_obj, fat_vfs_mkdir); +static MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_mkdir_obj, fat_vfs_mkdir); // Change current directory. -STATIC mp_obj_t fat_vfs_chdir(mp_obj_t vfs_in, mp_obj_t path_in) { +static mp_obj_t fat_vfs_chdir(mp_obj_t vfs_in, mp_obj_t path_in) { mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(vfs_in); const char *path; path = mp_obj_str_get_str(path_in); @@ -281,10 +281,10 @@ STATIC mp_obj_t fat_vfs_chdir(mp_obj_t vfs_in, mp_obj_t path_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_chdir_obj, fat_vfs_chdir); +static MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_chdir_obj, fat_vfs_chdir); // Get the current directory. -STATIC mp_obj_t fat_vfs_getcwd(mp_obj_t vfs_in) { +static mp_obj_t fat_vfs_getcwd(mp_obj_t vfs_in) { mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(vfs_in); char buf[MICROPY_ALLOC_PATH_MAX + 1]; FRESULT res = f_getcwd(&self->fatfs, buf, sizeof(buf)); @@ -293,10 +293,10 @@ STATIC mp_obj_t fat_vfs_getcwd(mp_obj_t vfs_in) { } return mp_obj_new_str(buf, strlen(buf)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_getcwd_obj, fat_vfs_getcwd); +static MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_getcwd_obj, fat_vfs_getcwd); // Get the status of a file or directory. -STATIC mp_obj_t fat_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_in) { +static mp_obj_t fat_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_in) { mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(vfs_in); const char *path = mp_obj_str_get_str(path_in); @@ -342,10 +342,10 @@ STATIC mp_obj_t fat_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_in) { return MP_OBJ_FROM_PTR(t); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_stat_obj, fat_vfs_stat); +static MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_stat_obj, fat_vfs_stat); // Get the status of a VFS. -STATIC mp_obj_t fat_vfs_statvfs(mp_obj_t vfs_in, mp_obj_t path_in) { +static mp_obj_t fat_vfs_statvfs(mp_obj_t vfs_in, mp_obj_t path_in) { mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(vfs_in); (void)path_in; @@ -371,9 +371,9 @@ STATIC mp_obj_t fat_vfs_statvfs(mp_obj_t vfs_in, mp_obj_t path_in) { return MP_OBJ_FROM_PTR(t); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_statvfs_obj, fat_vfs_statvfs); +static MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_statvfs_obj, fat_vfs_statvfs); -STATIC mp_obj_t vfs_fat_mount(mp_obj_t self_in, mp_obj_t readonly, mp_obj_t mkfs) { +static mp_obj_t vfs_fat_mount(mp_obj_t self_in, mp_obj_t readonly, mp_obj_t mkfs) { fs_user_mount_t *self = MP_OBJ_TO_PTR(self_in); // Read-only device indicated by writeblocks[0] == MP_OBJ_NULL. @@ -397,16 +397,16 @@ STATIC mp_obj_t vfs_fat_mount(mp_obj_t self_in, mp_obj_t readonly, mp_obj_t mkfs return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(vfs_fat_mount_obj, vfs_fat_mount); +static MP_DEFINE_CONST_FUN_OBJ_3(vfs_fat_mount_obj, vfs_fat_mount); -STATIC mp_obj_t vfs_fat_umount(mp_obj_t self_in) { +static mp_obj_t vfs_fat_umount(mp_obj_t self_in) { (void)self_in; // keep the FAT filesystem mounted internally so the VFS methods can still be used return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_umount_obj, vfs_fat_umount); +static MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_umount_obj, vfs_fat_umount); -STATIC const mp_rom_map_elem_t fat_vfs_locals_dict_table[] = { +static const mp_rom_map_elem_t fat_vfs_locals_dict_table[] = { #if _FS_REENTRANT { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&fat_vfs_del_obj) }, #endif @@ -424,9 +424,9 @@ STATIC const mp_rom_map_elem_t fat_vfs_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&vfs_fat_mount_obj) }, { MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&fat_vfs_umount_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(fat_vfs_locals_dict, fat_vfs_locals_dict_table); +static MP_DEFINE_CONST_DICT(fat_vfs_locals_dict, fat_vfs_locals_dict_table); -STATIC const mp_vfs_proto_t fat_vfs_proto = { +static const mp_vfs_proto_t fat_vfs_proto = { .import_stat = fat_vfs_import_stat, }; diff --git a/extmod/vfs_fat_diskio.c b/extmod/vfs_fat_diskio.c index 1bcd471f2162e..6f500104d1e86 100644 --- a/extmod/vfs_fat_diskio.c +++ b/extmod/vfs_fat_diskio.c @@ -44,7 +44,7 @@ #include "extmod/vfs_fat.h" typedef void *bdev_t; -STATIC fs_user_mount_t *disk_get_device(void *bdev) { +static fs_user_mount_t *disk_get_device(void *bdev) { return (fs_user_mount_t *)bdev; } diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c index e2f6937694256..887249b663c78 100644 --- a/extmod/vfs_fat_file.c +++ b/extmod/vfs_fat_file.c @@ -64,12 +64,12 @@ typedef struct _pyb_file_obj_t { FIL fp; } pyb_file_obj_t; -STATIC void file_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void file_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_printf(print, "", mp_obj_get_type_str(self_in), MP_OBJ_TO_PTR(self_in)); } -STATIC mp_uint_t file_obj_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t file_obj_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { pyb_file_obj_t *self = MP_OBJ_TO_PTR(self_in); UINT sz_out; FRESULT res = f_read(&self->fp, buf, size, &sz_out); @@ -80,7 +80,7 @@ STATIC mp_uint_t file_obj_read(mp_obj_t self_in, void *buf, mp_uint_t size, int return sz_out; } -STATIC mp_uint_t file_obj_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t file_obj_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { pyb_file_obj_t *self = MP_OBJ_TO_PTR(self_in); UINT sz_out; FRESULT res = f_write(&self->fp, buf, size, &sz_out); @@ -96,7 +96,7 @@ STATIC mp_uint_t file_obj_write(mp_obj_t self_in, const void *buf, mp_uint_t siz return sz_out; } -STATIC mp_uint_t file_obj_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t file_obj_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { pyb_file_obj_t *self = MP_OBJ_TO_PTR(o_in); if (request == MP_STREAM_SEEK) { @@ -146,7 +146,7 @@ STATIC mp_uint_t file_obj_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, // TODO gc hook to close the file if not already closed -STATIC const mp_rom_map_elem_t vfs_fat_rawfile_locals_dict_table[] = { +static const mp_rom_map_elem_t vfs_fat_rawfile_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) }, { MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) }, @@ -161,9 +161,9 @@ STATIC const mp_rom_map_elem_t vfs_fat_rawfile_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&mp_stream___exit___obj) }, }; -STATIC MP_DEFINE_CONST_DICT(vfs_fat_rawfile_locals_dict, vfs_fat_rawfile_locals_dict_table); +static MP_DEFINE_CONST_DICT(vfs_fat_rawfile_locals_dict, vfs_fat_rawfile_locals_dict_table); -STATIC const mp_stream_p_t vfs_fat_fileio_stream_p = { +static const mp_stream_p_t vfs_fat_fileio_stream_p = { .read = file_obj_read, .write = file_obj_write, .ioctl = file_obj_ioctl, @@ -178,7 +178,7 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &vfs_fat_rawfile_locals_dict ); -STATIC const mp_stream_p_t vfs_fat_textio_stream_p = { +static const mp_stream_p_t vfs_fat_textio_stream_p = { .read = file_obj_read, .write = file_obj_write, .ioctl = file_obj_ioctl, @@ -195,7 +195,7 @@ MP_DEFINE_CONST_OBJ_TYPE( ); // Factory function for I/O stream classes -STATIC mp_obj_t fat_vfs_open(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mode_in) { +static mp_obj_t fat_vfs_open(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mode_in) { fs_user_mount_t *self = MP_OBJ_TO_PTR(self_in); const mp_obj_type_t *type = &mp_type_vfs_fat_textio; diff --git a/extmod/vfs_lfs.c b/extmod/vfs_lfs.c index 4fb86b89b76c3..19063d6306604 100644 --- a/extmod/vfs_lfs.c +++ b/extmod/vfs_lfs.c @@ -127,7 +127,7 @@ typedef struct _mp_obj_vfs_lfs2_file_t { const char *mp_vfs_lfs2_make_path(mp_obj_vfs_lfs2_t *self, mp_obj_t path_in); mp_obj_t mp_vfs_lfs2_file_open(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mode_in); -STATIC void lfs_get_mtime(uint8_t buf[8]) { +static void lfs_get_mtime(uint8_t buf[8]) { // On-disk storage of timestamps uses 1970 as the Epoch, so convert from host's Epoch. uint64_t ns = timeutils_nanoseconds_since_epoch_to_nanoseconds_since_1970(mp_hal_time_ns()); // Store "ns" to "buf" in little-endian format (essentially htole64). diff --git a/extmod/vfs_lfsx.c b/extmod/vfs_lfsx.c index ddcbdf3ac4d75..19da4417e6d00 100644 --- a/extmod/vfs_lfsx.c +++ b/extmod/vfs_lfsx.c @@ -43,7 +43,7 @@ #error "MICROPY_VFS_LFS requires MICROPY_ENABLE_FINALISER" #endif -STATIC int MP_VFS_LFSx(dev_ioctl)(const struct LFSx_API (config) * c, int cmd, int arg, bool must_return_int) { +static int MP_VFS_LFSx(dev_ioctl)(const struct LFSx_API (config) * c, int cmd, int arg, bool must_return_int) { mp_obj_t ret = mp_vfs_blockdev_ioctl(c->context, cmd, arg); int ret_i = 0; if (must_return_int || ret != mp_const_none) { @@ -52,23 +52,23 @@ STATIC int MP_VFS_LFSx(dev_ioctl)(const struct LFSx_API (config) * c, int cmd, i return ret_i; } -STATIC int MP_VFS_LFSx(dev_read)(const struct LFSx_API (config) * c, LFSx_API(block_t) block, LFSx_API(off_t) off, void *buffer, LFSx_API(size_t) size) { +static int MP_VFS_LFSx(dev_read)(const struct LFSx_API (config) * c, LFSx_API(block_t) block, LFSx_API(off_t) off, void *buffer, LFSx_API(size_t) size) { return mp_vfs_blockdev_read_ext(c->context, block, off, size, buffer); } -STATIC int MP_VFS_LFSx(dev_prog)(const struct LFSx_API (config) * c, LFSx_API(block_t) block, LFSx_API(off_t) off, const void *buffer, LFSx_API(size_t) size) { +static int MP_VFS_LFSx(dev_prog)(const struct LFSx_API (config) * c, LFSx_API(block_t) block, LFSx_API(off_t) off, const void *buffer, LFSx_API(size_t) size) { return mp_vfs_blockdev_write_ext(c->context, block, off, size, buffer); } -STATIC int MP_VFS_LFSx(dev_erase)(const struct LFSx_API (config) * c, LFSx_API(block_t) block) { +static int MP_VFS_LFSx(dev_erase)(const struct LFSx_API (config) * c, LFSx_API(block_t) block) { return MP_VFS_LFSx(dev_ioctl)(c, MP_BLOCKDEV_IOCTL_BLOCK_ERASE, block, true); } -STATIC int MP_VFS_LFSx(dev_sync)(const struct LFSx_API (config) * c) { +static int MP_VFS_LFSx(dev_sync)(const struct LFSx_API (config) * c) { return MP_VFS_LFSx(dev_ioctl)(c, MP_BLOCKDEV_IOCTL_SYNC, 0, false); } -STATIC void MP_VFS_LFSx(init_config)(MP_OBJ_VFS_LFSx * self, mp_obj_t bdev, size_t read_size, size_t prog_size, size_t lookahead) { +static void MP_VFS_LFSx(init_config)(MP_OBJ_VFS_LFSx * self, mp_obj_t bdev, size_t read_size, size_t prog_size, size_t lookahead) { self->blockdev.flags = MP_BLOCKDEV_FLAG_FREE_OBJ; mp_vfs_blockdev_init(&self->blockdev, bdev); @@ -120,7 +120,7 @@ const char *MP_VFS_LFSx(make_path)(MP_OBJ_VFS_LFSx * self, mp_obj_t path_in) { return path; } -STATIC mp_obj_t MP_VFS_LFSx(make_new)(const mp_obj_type_t * type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t MP_VFS_LFSx(make_new)(const mp_obj_type_t * type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { mp_arg_val_t args[MP_ARRAY_SIZE(lfs_make_allowed_args)]; mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(lfs_make_allowed_args), lfs_make_allowed_args, args); @@ -140,7 +140,7 @@ STATIC mp_obj_t MP_VFS_LFSx(make_new)(const mp_obj_type_t * type, size_t n_args, return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t MP_VFS_LFSx(mkfs)(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t MP_VFS_LFSx(mkfs)(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_arg_val_t args[MP_ARRAY_SIZE(lfs_make_allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(lfs_make_allowed_args), lfs_make_allowed_args, args); @@ -153,11 +153,11 @@ STATIC mp_obj_t MP_VFS_LFSx(mkfs)(size_t n_args, const mp_obj_t *pos_args, mp_ma } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(MP_VFS_LFSx(mkfs_fun_obj), 0, MP_VFS_LFSx(mkfs)); -STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(MP_VFS_LFSx(mkfs_obj), MP_ROM_PTR(&MP_VFS_LFSx(mkfs_fun_obj))); +static MP_DEFINE_CONST_FUN_OBJ_KW(MP_VFS_LFSx(mkfs_fun_obj), 0, MP_VFS_LFSx(mkfs)); +static MP_DEFINE_CONST_STATICMETHOD_OBJ(MP_VFS_LFSx(mkfs_obj), MP_ROM_PTR(&MP_VFS_LFSx(mkfs_fun_obj))); // Implementation of mp_vfs_lfs_file_open is provided in vfs_lfsx_file.c -STATIC MP_DEFINE_CONST_FUN_OBJ_3(MP_VFS_LFSx(open_obj), MP_VFS_LFSx(file_open)); +static MP_DEFINE_CONST_FUN_OBJ_3(MP_VFS_LFSx(open_obj), MP_VFS_LFSx(file_open)); typedef struct MP_VFS_LFSx (_ilistdir_it_t) { mp_obj_base_t base; @@ -168,7 +168,7 @@ typedef struct MP_VFS_LFSx (_ilistdir_it_t) { LFSx_API(dir_t) dir; } MP_VFS_LFSx(ilistdir_it_t); -STATIC mp_obj_t MP_VFS_LFSx(ilistdir_it_iternext)(mp_obj_t self_in) { +static mp_obj_t MP_VFS_LFSx(ilistdir_it_iternext)(mp_obj_t self_in) { MP_VFS_LFSx(ilistdir_it_t) * self = MP_OBJ_TO_PTR(self_in); if (self->vfs == NULL) { @@ -203,7 +203,7 @@ STATIC mp_obj_t MP_VFS_LFSx(ilistdir_it_iternext)(mp_obj_t self_in) { return MP_OBJ_FROM_PTR(t); } -STATIC mp_obj_t MP_VFS_LFSx(ilistdir_it_del)(mp_obj_t self_in) { +static mp_obj_t MP_VFS_LFSx(ilistdir_it_del)(mp_obj_t self_in) { MP_VFS_LFSx(ilistdir_it_t) * self = MP_OBJ_TO_PTR(self_in); if (self->vfs != NULL) { LFSx_API(dir_close)(&self->vfs->lfs, &self->dir); @@ -211,7 +211,7 @@ STATIC mp_obj_t MP_VFS_LFSx(ilistdir_it_del)(mp_obj_t self_in) { return mp_const_none; } -STATIC mp_obj_t MP_VFS_LFSx(ilistdir_func)(size_t n_args, const mp_obj_t *args) { +static mp_obj_t MP_VFS_LFSx(ilistdir_func)(size_t n_args, const mp_obj_t *args) { MP_OBJ_VFS_LFSx *self = MP_OBJ_TO_PTR(args[0]); bool is_str_type = true; const char *path; @@ -236,9 +236,9 @@ STATIC mp_obj_t MP_VFS_LFSx(ilistdir_func)(size_t n_args, const mp_obj_t *args) iter->vfs = self; return MP_OBJ_FROM_PTR(iter); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(MP_VFS_LFSx(ilistdir_obj), 1, 2, MP_VFS_LFSx(ilistdir_func)); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(MP_VFS_LFSx(ilistdir_obj), 1, 2, MP_VFS_LFSx(ilistdir_func)); -STATIC mp_obj_t MP_VFS_LFSx(remove)(mp_obj_t self_in, mp_obj_t path_in) { +static mp_obj_t MP_VFS_LFSx(remove)(mp_obj_t self_in, mp_obj_t path_in) { MP_OBJ_VFS_LFSx *self = MP_OBJ_TO_PTR(self_in); const char *path = MP_VFS_LFSx(make_path)(self, path_in); int ret = LFSx_API(remove)(&self->lfs, path); @@ -247,9 +247,9 @@ STATIC mp_obj_t MP_VFS_LFSx(remove)(mp_obj_t self_in, mp_obj_t path_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(MP_VFS_LFSx(remove_obj), MP_VFS_LFSx(remove)); +static MP_DEFINE_CONST_FUN_OBJ_2(MP_VFS_LFSx(remove_obj), MP_VFS_LFSx(remove)); -STATIC mp_obj_t MP_VFS_LFSx(rmdir)(mp_obj_t self_in, mp_obj_t path_in) { +static mp_obj_t MP_VFS_LFSx(rmdir)(mp_obj_t self_in, mp_obj_t path_in) { MP_OBJ_VFS_LFSx *self = MP_OBJ_TO_PTR(self_in); const char *path = MP_VFS_LFSx(make_path)(self, path_in); int ret = LFSx_API(remove)(&self->lfs, path); @@ -258,9 +258,9 @@ STATIC mp_obj_t MP_VFS_LFSx(rmdir)(mp_obj_t self_in, mp_obj_t path_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(MP_VFS_LFSx(rmdir_obj), MP_VFS_LFSx(rmdir)); +static MP_DEFINE_CONST_FUN_OBJ_2(MP_VFS_LFSx(rmdir_obj), MP_VFS_LFSx(rmdir)); -STATIC mp_obj_t MP_VFS_LFSx(rename)(mp_obj_t self_in, mp_obj_t path_old_in, mp_obj_t path_new_in) { +static mp_obj_t MP_VFS_LFSx(rename)(mp_obj_t self_in, mp_obj_t path_old_in, mp_obj_t path_new_in) { MP_OBJ_VFS_LFSx *self = MP_OBJ_TO_PTR(self_in); const char *path_old = MP_VFS_LFSx(make_path)(self, path_old_in); const char *path = mp_obj_str_get_str(path_new_in); @@ -277,9 +277,9 @@ STATIC mp_obj_t MP_VFS_LFSx(rename)(mp_obj_t self_in, mp_obj_t path_old_in, mp_o } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(MP_VFS_LFSx(rename_obj), MP_VFS_LFSx(rename)); +static MP_DEFINE_CONST_FUN_OBJ_3(MP_VFS_LFSx(rename_obj), MP_VFS_LFSx(rename)); -STATIC mp_obj_t MP_VFS_LFSx(mkdir)(mp_obj_t self_in, mp_obj_t path_o) { +static mp_obj_t MP_VFS_LFSx(mkdir)(mp_obj_t self_in, mp_obj_t path_o) { MP_OBJ_VFS_LFSx *self = MP_OBJ_TO_PTR(self_in); const char *path = MP_VFS_LFSx(make_path)(self, path_o); int ret = LFSx_API(mkdir)(&self->lfs, path); @@ -288,9 +288,9 @@ STATIC mp_obj_t MP_VFS_LFSx(mkdir)(mp_obj_t self_in, mp_obj_t path_o) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(MP_VFS_LFSx(mkdir_obj), MP_VFS_LFSx(mkdir)); +static MP_DEFINE_CONST_FUN_OBJ_2(MP_VFS_LFSx(mkdir_obj), MP_VFS_LFSx(mkdir)); -STATIC mp_obj_t MP_VFS_LFSx(chdir)(mp_obj_t self_in, mp_obj_t path_in) { +static mp_obj_t MP_VFS_LFSx(chdir)(mp_obj_t self_in, mp_obj_t path_in) { MP_OBJ_VFS_LFSx *self = MP_OBJ_TO_PTR(self_in); // Check path exists @@ -356,9 +356,9 @@ STATIC mp_obj_t MP_VFS_LFSx(chdir)(mp_obj_t self_in, mp_obj_t path_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(MP_VFS_LFSx(chdir_obj), MP_VFS_LFSx(chdir)); +static MP_DEFINE_CONST_FUN_OBJ_2(MP_VFS_LFSx(chdir_obj), MP_VFS_LFSx(chdir)); -STATIC mp_obj_t MP_VFS_LFSx(getcwd)(mp_obj_t self_in) { +static mp_obj_t MP_VFS_LFSx(getcwd)(mp_obj_t self_in) { MP_OBJ_VFS_LFSx *self = MP_OBJ_TO_PTR(self_in); if (vstr_len(&self->cur_dir) == 1) { return MP_OBJ_NEW_QSTR(MP_QSTR__slash_); @@ -367,9 +367,9 @@ STATIC mp_obj_t MP_VFS_LFSx(getcwd)(mp_obj_t self_in) { return mp_obj_new_str(self->cur_dir.buf, self->cur_dir.len - 1); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(MP_VFS_LFSx(getcwd_obj), MP_VFS_LFSx(getcwd)); +static MP_DEFINE_CONST_FUN_OBJ_1(MP_VFS_LFSx(getcwd_obj), MP_VFS_LFSx(getcwd)); -STATIC mp_obj_t MP_VFS_LFSx(stat)(mp_obj_t self_in, mp_obj_t path_in) { +static mp_obj_t MP_VFS_LFSx(stat)(mp_obj_t self_in, mp_obj_t path_in) { MP_OBJ_VFS_LFSx *self = MP_OBJ_TO_PTR(self_in); const char *path = MP_VFS_LFSx(make_path)(self, path_in); struct LFSx_API (info) info; @@ -406,16 +406,16 @@ STATIC mp_obj_t MP_VFS_LFSx(stat)(mp_obj_t self_in, mp_obj_t path_in) { return MP_OBJ_FROM_PTR(t); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(MP_VFS_LFSx(stat_obj), MP_VFS_LFSx(stat)); +static MP_DEFINE_CONST_FUN_OBJ_2(MP_VFS_LFSx(stat_obj), MP_VFS_LFSx(stat)); -STATIC int LFSx_API(traverse_cb)(void *data, LFSx_API(block_t) bl) { +static int LFSx_API(traverse_cb)(void *data, LFSx_API(block_t) bl) { (void)bl; uint32_t *n = (uint32_t *)data; *n += 1; return LFSx_MACRO(_ERR_OK); } -STATIC mp_obj_t MP_VFS_LFSx(statvfs)(mp_obj_t self_in, mp_obj_t path_in) { +static mp_obj_t MP_VFS_LFSx(statvfs)(mp_obj_t self_in, mp_obj_t path_in) { (void)path_in; MP_OBJ_VFS_LFSx *self = MP_OBJ_TO_PTR(self_in); uint32_t n_used_blocks = 0; @@ -442,9 +442,9 @@ STATIC mp_obj_t MP_VFS_LFSx(statvfs)(mp_obj_t self_in, mp_obj_t path_in) { return MP_OBJ_FROM_PTR(t); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(MP_VFS_LFSx(statvfs_obj), MP_VFS_LFSx(statvfs)); +static MP_DEFINE_CONST_FUN_OBJ_2(MP_VFS_LFSx(statvfs_obj), MP_VFS_LFSx(statvfs)); -STATIC mp_obj_t MP_VFS_LFSx(mount)(mp_obj_t self_in, mp_obj_t readonly, mp_obj_t mkfs) { +static mp_obj_t MP_VFS_LFSx(mount)(mp_obj_t self_in, mp_obj_t readonly, mp_obj_t mkfs) { MP_OBJ_VFS_LFSx *self = MP_OBJ_TO_PTR(self_in); (void)mkfs; @@ -457,17 +457,17 @@ STATIC mp_obj_t MP_VFS_LFSx(mount)(mp_obj_t self_in, mp_obj_t readonly, mp_obj_t return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(MP_VFS_LFSx(mount_obj), MP_VFS_LFSx(mount)); +static MP_DEFINE_CONST_FUN_OBJ_3(MP_VFS_LFSx(mount_obj), MP_VFS_LFSx(mount)); -STATIC mp_obj_t MP_VFS_LFSx(umount)(mp_obj_t self_in) { +static mp_obj_t MP_VFS_LFSx(umount)(mp_obj_t self_in) { MP_OBJ_VFS_LFSx *self = MP_OBJ_TO_PTR(self_in); // LFS unmount never fails LFSx_API(unmount)(&self->lfs); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(MP_VFS_LFSx(umount_obj), MP_VFS_LFSx(umount)); +static MP_DEFINE_CONST_FUN_OBJ_1(MP_VFS_LFSx(umount_obj), MP_VFS_LFSx(umount)); -STATIC const mp_rom_map_elem_t MP_VFS_LFSx(locals_dict_table)[] = { +static const mp_rom_map_elem_t MP_VFS_LFSx(locals_dict_table)[] = { { MP_ROM_QSTR(MP_QSTR_mkfs), MP_ROM_PTR(&MP_VFS_LFSx(mkfs_obj)) }, { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&MP_VFS_LFSx(open_obj)) }, { MP_ROM_QSTR(MP_QSTR_ilistdir), MP_ROM_PTR(&MP_VFS_LFSx(ilistdir_obj)) }, @@ -482,9 +482,9 @@ STATIC const mp_rom_map_elem_t MP_VFS_LFSx(locals_dict_table)[] = { { MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&MP_VFS_LFSx(mount_obj)) }, { MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&MP_VFS_LFSx(umount_obj)) }, }; -STATIC MP_DEFINE_CONST_DICT(MP_VFS_LFSx(locals_dict), MP_VFS_LFSx(locals_dict_table)); +static MP_DEFINE_CONST_DICT(MP_VFS_LFSx(locals_dict), MP_VFS_LFSx(locals_dict_table)); -STATIC mp_import_stat_t MP_VFS_LFSx(import_stat)(void *self_in, const char *path) { +static mp_import_stat_t MP_VFS_LFSx(import_stat)(void *self_in, const char *path) { MP_OBJ_VFS_LFSx *self = self_in; struct LFSx_API (info) info; mp_obj_str_t path_obj = { { &mp_type_str }, 0, 0, (const byte *)path }; @@ -500,7 +500,7 @@ STATIC mp_import_stat_t MP_VFS_LFSx(import_stat)(void *self_in, const char *path return MP_IMPORT_STAT_NO_EXIST; } -STATIC const mp_vfs_proto_t MP_VFS_LFSx(proto) = { +static const mp_vfs_proto_t MP_VFS_LFSx(proto) = { .import_stat = MP_VFS_LFSx(import_stat), }; diff --git a/extmod/vfs_lfsx_file.c b/extmod/vfs_lfsx_file.c index 04058506441b5..ab5cce50088b9 100644 --- a/extmod/vfs_lfsx_file.c +++ b/extmod/vfs_lfsx_file.c @@ -35,13 +35,13 @@ #include "py/mperrno.h" #include "extmod/vfs.h" -STATIC void MP_VFS_LFSx(check_open)(MP_OBJ_VFS_LFSx_FILE * self) { +static void MP_VFS_LFSx(check_open)(MP_OBJ_VFS_LFSx_FILE * self) { if (self->vfs == NULL) { mp_raise_ValueError(NULL); } } -STATIC void MP_VFS_LFSx(file_print)(const mp_print_t * print, mp_obj_t self_in, mp_print_kind_t kind) { +static void MP_VFS_LFSx(file_print)(const mp_print_t * print, mp_obj_t self_in, mp_print_kind_t kind) { (void)self_in; (void)kind; mp_printf(print, "", mp_obj_get_type_str(self_in)); @@ -122,7 +122,7 @@ mp_obj_t MP_VFS_LFSx(file_open)(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mod return MP_OBJ_FROM_PTR(o); } -STATIC mp_uint_t MP_VFS_LFSx(file_read)(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t MP_VFS_LFSx(file_read)(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { MP_OBJ_VFS_LFSx_FILE *self = MP_OBJ_TO_PTR(self_in); MP_VFS_LFSx(check_open)(self); LFSx_API(ssize_t) sz = LFSx_API(file_read)(&self->vfs->lfs, &self->file, buf, size); @@ -133,7 +133,7 @@ STATIC mp_uint_t MP_VFS_LFSx(file_read)(mp_obj_t self_in, void *buf, mp_uint_t s return sz; } -STATIC mp_uint_t MP_VFS_LFSx(file_write)(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t MP_VFS_LFSx(file_write)(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { MP_OBJ_VFS_LFSx_FILE *self = MP_OBJ_TO_PTR(self_in); MP_VFS_LFSx(check_open)(self); #if LFS_BUILD_VERSION == 2 @@ -149,7 +149,7 @@ STATIC mp_uint_t MP_VFS_LFSx(file_write)(mp_obj_t self_in, const void *buf, mp_u return sz; } -STATIC mp_uint_t MP_VFS_LFSx(file_ioctl)(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t MP_VFS_LFSx(file_ioctl)(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { MP_OBJ_VFS_LFSx_FILE *self = MP_OBJ_TO_PTR(self_in); if (request != MP_STREAM_CLOSE) { @@ -194,7 +194,7 @@ STATIC mp_uint_t MP_VFS_LFSx(file_ioctl)(mp_obj_t self_in, mp_uint_t request, ui } } -STATIC const mp_rom_map_elem_t MP_VFS_LFSx(file_locals_dict_table)[] = { +static const mp_rom_map_elem_t MP_VFS_LFSx(file_locals_dict_table)[] = { { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) }, { MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) }, @@ -208,9 +208,9 @@ STATIC const mp_rom_map_elem_t MP_VFS_LFSx(file_locals_dict_table)[] = { { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&mp_identity_obj) }, { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&mp_stream___exit___obj) }, }; -STATIC MP_DEFINE_CONST_DICT(MP_VFS_LFSx(file_locals_dict), MP_VFS_LFSx(file_locals_dict_table)); +static MP_DEFINE_CONST_DICT(MP_VFS_LFSx(file_locals_dict), MP_VFS_LFSx(file_locals_dict_table)); -STATIC const mp_stream_p_t MP_VFS_LFSx(fileio_stream_p) = { +static const mp_stream_p_t MP_VFS_LFSx(fileio_stream_p) = { .read = MP_VFS_LFSx(file_read), .write = MP_VFS_LFSx(file_write), .ioctl = MP_VFS_LFSx(file_ioctl), @@ -225,7 +225,7 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &MP_VFS_LFSx(file_locals_dict) ); -STATIC const mp_stream_p_t MP_VFS_LFSx(textio_stream_p) = { +static const mp_stream_p_t MP_VFS_LFSx(textio_stream_p) = { .read = MP_VFS_LFSx(file_read), .write = MP_VFS_LFSx(file_write), .ioctl = MP_VFS_LFSx(file_ioctl), diff --git a/extmod/vfs_posix.c b/extmod/vfs_posix.c index 2e0f712e25ede..ed4c06e36731e 100644 --- a/extmod/vfs_posix.c +++ b/extmod/vfs_posix.c @@ -57,7 +57,7 @@ typedef struct _mp_obj_vfs_posix_t { bool readonly; } mp_obj_vfs_posix_t; -STATIC const char *vfs_posix_get_path_str(mp_obj_vfs_posix_t *self, mp_obj_t path) { +static const char *vfs_posix_get_path_str(mp_obj_vfs_posix_t *self, mp_obj_t path) { const char *path_str = mp_obj_str_get_str(path); if (self->root_len == 0 || path_str[0] != '/') { return path_str; @@ -68,7 +68,7 @@ STATIC const char *vfs_posix_get_path_str(mp_obj_vfs_posix_t *self, mp_obj_t pat } } -STATIC mp_obj_t vfs_posix_get_path_obj(mp_obj_vfs_posix_t *self, mp_obj_t path) { +static mp_obj_t vfs_posix_get_path_obj(mp_obj_vfs_posix_t *self, mp_obj_t path) { const char *path_str = mp_obj_str_get_str(path); if (self->root_len == 0 || path_str[0] != '/') { return path; @@ -79,7 +79,7 @@ STATIC mp_obj_t vfs_posix_get_path_obj(mp_obj_vfs_posix_t *self, mp_obj_t path) } } -STATIC mp_obj_t vfs_posix_fun1_helper(mp_obj_t self_in, mp_obj_t path_in, int (*f)(const char *)) { +static mp_obj_t vfs_posix_fun1_helper(mp_obj_t self_in, mp_obj_t path_in, int (*f)(const char *)) { mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in); int ret = f(vfs_posix_get_path_str(self, path_in)); if (ret != 0) { @@ -88,7 +88,7 @@ STATIC mp_obj_t vfs_posix_fun1_helper(mp_obj_t self_in, mp_obj_t path_in, int (* return mp_const_none; } -STATIC mp_import_stat_t mp_vfs_posix_import_stat(void *self_in, const char *path) { +static mp_import_stat_t mp_vfs_posix_import_stat(void *self_in, const char *path) { mp_obj_vfs_posix_t *self = self_in; if (self->root_len != 0) { self->root.len = self->root_len; @@ -106,7 +106,7 @@ STATIC mp_import_stat_t mp_vfs_posix_import_stat(void *self_in, const char *path return MP_IMPORT_STAT_NO_EXIST; } -STATIC mp_obj_t vfs_posix_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t vfs_posix_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); mp_obj_vfs_posix_t *vfs = mp_obj_malloc(mp_obj_vfs_posix_t, type); @@ -142,7 +142,7 @@ STATIC mp_obj_t vfs_posix_make_new(const mp_obj_type_t *type, size_t n_args, siz return MP_OBJ_FROM_PTR(vfs); } -STATIC mp_obj_t vfs_posix_mount(mp_obj_t self_in, mp_obj_t readonly, mp_obj_t mkfs) { +static mp_obj_t vfs_posix_mount(mp_obj_t self_in, mp_obj_t readonly, mp_obj_t mkfs) { mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in); if (mp_obj_is_true(readonly)) { self->readonly = true; @@ -152,15 +152,15 @@ STATIC mp_obj_t vfs_posix_mount(mp_obj_t self_in, mp_obj_t readonly, mp_obj_t mk } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(vfs_posix_mount_obj, vfs_posix_mount); +static MP_DEFINE_CONST_FUN_OBJ_3(vfs_posix_mount_obj, vfs_posix_mount); -STATIC mp_obj_t vfs_posix_umount(mp_obj_t self_in) { +static mp_obj_t vfs_posix_umount(mp_obj_t self_in) { (void)self_in; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(vfs_posix_umount_obj, vfs_posix_umount); +static MP_DEFINE_CONST_FUN_OBJ_1(vfs_posix_umount_obj, vfs_posix_umount); -STATIC mp_obj_t vfs_posix_open(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mode_in) { +static mp_obj_t vfs_posix_open(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mode_in) { mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in); const char *mode = mp_obj_str_get_str(mode_in); if (self->readonly @@ -172,14 +172,14 @@ STATIC mp_obj_t vfs_posix_open(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mode } return mp_vfs_posix_file_open(&mp_type_vfs_posix_textio, path_in, mode_in); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(vfs_posix_open_obj, vfs_posix_open); +static MP_DEFINE_CONST_FUN_OBJ_3(vfs_posix_open_obj, vfs_posix_open); -STATIC mp_obj_t vfs_posix_chdir(mp_obj_t self_in, mp_obj_t path_in) { +static mp_obj_t vfs_posix_chdir(mp_obj_t self_in, mp_obj_t path_in) { return vfs_posix_fun1_helper(self_in, path_in, chdir); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_chdir_obj, vfs_posix_chdir); +static MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_chdir_obj, vfs_posix_chdir); -STATIC mp_obj_t vfs_posix_getcwd(mp_obj_t self_in) { +static mp_obj_t vfs_posix_getcwd(mp_obj_t self_in) { mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in); char buf[MICROPY_ALLOC_PATH_MAX + 1]; const char *ret = getcwd(buf, sizeof(buf)); @@ -196,7 +196,7 @@ STATIC mp_obj_t vfs_posix_getcwd(mp_obj_t self_in) { } return mp_obj_new_str(ret, strlen(ret)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(vfs_posix_getcwd_obj, vfs_posix_getcwd); +static MP_DEFINE_CONST_FUN_OBJ_1(vfs_posix_getcwd_obj, vfs_posix_getcwd); typedef struct _vfs_posix_ilistdir_it_t { mp_obj_base_t base; @@ -206,7 +206,7 @@ typedef struct _vfs_posix_ilistdir_it_t { DIR *dir; } vfs_posix_ilistdir_it_t; -STATIC mp_obj_t vfs_posix_ilistdir_it_iternext(mp_obj_t self_in) { +static mp_obj_t vfs_posix_ilistdir_it_iternext(mp_obj_t self_in) { vfs_posix_ilistdir_it_t *self = MP_OBJ_TO_PTR(self_in); if (self->dir == NULL) { @@ -266,7 +266,7 @@ STATIC mp_obj_t vfs_posix_ilistdir_it_iternext(mp_obj_t self_in) { } } -STATIC mp_obj_t vfs_posix_ilistdir_it_del(mp_obj_t self_in) { +static mp_obj_t vfs_posix_ilistdir_it_del(mp_obj_t self_in) { vfs_posix_ilistdir_it_t *self = MP_OBJ_TO_PTR(self_in); if (self->dir != NULL) { MP_THREAD_GIL_EXIT(); @@ -276,7 +276,7 @@ STATIC mp_obj_t vfs_posix_ilistdir_it_del(mp_obj_t self_in) { return mp_const_none; } -STATIC mp_obj_t vfs_posix_ilistdir(mp_obj_t self_in, mp_obj_t path_in) { +static mp_obj_t vfs_posix_ilistdir(mp_obj_t self_in, mp_obj_t path_in) { mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in); vfs_posix_ilistdir_it_t *iter = mp_obj_malloc_with_finaliser(vfs_posix_ilistdir_it_t, &mp_type_polymorph_iter_with_finaliser); iter->iternext = vfs_posix_ilistdir_it_iternext; @@ -294,7 +294,7 @@ STATIC mp_obj_t vfs_posix_ilistdir(mp_obj_t self_in, mp_obj_t path_in) { } return MP_OBJ_FROM_PTR(iter); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_ilistdir_obj, vfs_posix_ilistdir); +static MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_ilistdir_obj, vfs_posix_ilistdir); typedef struct _mp_obj_listdir_t { mp_obj_base_t base; @@ -302,7 +302,7 @@ typedef struct _mp_obj_listdir_t { DIR *dir; } mp_obj_listdir_t; -STATIC mp_obj_t vfs_posix_mkdir(mp_obj_t self_in, mp_obj_t path_in) { +static mp_obj_t vfs_posix_mkdir(mp_obj_t self_in, mp_obj_t path_in) { mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in); const char *path = vfs_posix_get_path_str(self, path_in); MP_THREAD_GIL_EXIT(); @@ -317,14 +317,14 @@ STATIC mp_obj_t vfs_posix_mkdir(mp_obj_t self_in, mp_obj_t path_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_mkdir_obj, vfs_posix_mkdir); +static MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_mkdir_obj, vfs_posix_mkdir); -STATIC mp_obj_t vfs_posix_remove(mp_obj_t self_in, mp_obj_t path_in) { +static mp_obj_t vfs_posix_remove(mp_obj_t self_in, mp_obj_t path_in) { return vfs_posix_fun1_helper(self_in, path_in, unlink); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_remove_obj, vfs_posix_remove); +static MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_remove_obj, vfs_posix_remove); -STATIC mp_obj_t vfs_posix_rename(mp_obj_t self_in, mp_obj_t old_path_in, mp_obj_t new_path_in) { +static mp_obj_t vfs_posix_rename(mp_obj_t self_in, mp_obj_t old_path_in, mp_obj_t new_path_in) { mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in); const char *old_path = vfs_posix_get_path_str(self, old_path_in); const char *new_path = vfs_posix_get_path_str(self, new_path_in); @@ -336,14 +336,14 @@ STATIC mp_obj_t vfs_posix_rename(mp_obj_t self_in, mp_obj_t old_path_in, mp_obj_ } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(vfs_posix_rename_obj, vfs_posix_rename); +static MP_DEFINE_CONST_FUN_OBJ_3(vfs_posix_rename_obj, vfs_posix_rename); -STATIC mp_obj_t vfs_posix_rmdir(mp_obj_t self_in, mp_obj_t path_in) { +static mp_obj_t vfs_posix_rmdir(mp_obj_t self_in, mp_obj_t path_in) { return vfs_posix_fun1_helper(self_in, path_in, rmdir); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_rmdir_obj, vfs_posix_rmdir); +static MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_rmdir_obj, vfs_posix_rmdir); -STATIC mp_obj_t vfs_posix_stat(mp_obj_t self_in, mp_obj_t path_in) { +static mp_obj_t vfs_posix_stat(mp_obj_t self_in, mp_obj_t path_in) { mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in); struct stat sb; const char *path = vfs_posix_get_path_str(self, path_in); @@ -362,7 +362,7 @@ STATIC mp_obj_t vfs_posix_stat(mp_obj_t self_in, mp_obj_t path_in) { t->items[9] = mp_obj_new_int_from_uint(sb.st_ctime); return MP_OBJ_FROM_PTR(t); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_stat_obj, vfs_posix_stat); +static MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_stat_obj, vfs_posix_stat); #if MICROPY_PY_OS_STATVFS @@ -386,7 +386,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_stat_obj, vfs_posix_stat); #define F_FLAG sb.f_flag #endif -STATIC mp_obj_t vfs_posix_statvfs(mp_obj_t self_in, mp_obj_t path_in) { +static mp_obj_t vfs_posix_statvfs(mp_obj_t self_in, mp_obj_t path_in) { mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in); STRUCT_STATVFS sb; const char *path = vfs_posix_get_path_str(self, path_in); @@ -405,11 +405,11 @@ STATIC mp_obj_t vfs_posix_statvfs(mp_obj_t self_in, mp_obj_t path_in) { t->items[9] = MP_OBJ_NEW_SMALL_INT(F_NAMEMAX); return MP_OBJ_FROM_PTR(t); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_statvfs_obj, vfs_posix_statvfs); +static MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_statvfs_obj, vfs_posix_statvfs); #endif -STATIC const mp_rom_map_elem_t vfs_posix_locals_dict_table[] = { +static const mp_rom_map_elem_t vfs_posix_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&vfs_posix_mount_obj) }, { MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&vfs_posix_umount_obj) }, { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&vfs_posix_open_obj) }, @@ -426,9 +426,9 @@ STATIC const mp_rom_map_elem_t vfs_posix_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_statvfs), MP_ROM_PTR(&vfs_posix_statvfs_obj) }, #endif }; -STATIC MP_DEFINE_CONST_DICT(vfs_posix_locals_dict, vfs_posix_locals_dict_table); +static MP_DEFINE_CONST_DICT(vfs_posix_locals_dict, vfs_posix_locals_dict_table); -STATIC const mp_vfs_proto_t vfs_posix_proto = { +static const mp_vfs_proto_t vfs_posix_proto = { .import_stat = mp_vfs_posix_import_stat, }; diff --git a/extmod/vfs_posix_file.c b/extmod/vfs_posix_file.c index eb9146d47b034..bc06bc74db1cb 100644 --- a/extmod/vfs_posix_file.c +++ b/extmod/vfs_posix_file.c @@ -47,7 +47,7 @@ typedef struct _mp_obj_vfs_posix_file_t { } mp_obj_vfs_posix_file_t; #if MICROPY_CPYTHON_COMPAT -STATIC void check_fd_is_open(const mp_obj_vfs_posix_file_t *o) { +static void check_fd_is_open(const mp_obj_vfs_posix_file_t *o) { if (o->fd < 0) { mp_raise_ValueError(MP_ERROR_TEXT("I/O operation on closed file")); } @@ -56,7 +56,7 @@ STATIC void check_fd_is_open(const mp_obj_vfs_posix_file_t *o) { #define check_fd_is_open(o) #endif -STATIC void vfs_posix_file_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void vfs_posix_file_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_vfs_posix_file_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", mp_obj_get_type_str(self_in), self->fd); @@ -108,14 +108,14 @@ mp_obj_t mp_vfs_posix_file_open(const mp_obj_type_t *type, mp_obj_t file_in, mp_ return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t vfs_posix_file_fileno(mp_obj_t self_in) { +static mp_obj_t vfs_posix_file_fileno(mp_obj_t self_in) { mp_obj_vfs_posix_file_t *self = MP_OBJ_TO_PTR(self_in); check_fd_is_open(self); return MP_OBJ_NEW_SMALL_INT(self->fd); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(vfs_posix_file_fileno_obj, vfs_posix_file_fileno); +static MP_DEFINE_CONST_FUN_OBJ_1(vfs_posix_file_fileno_obj, vfs_posix_file_fileno); -STATIC mp_uint_t vfs_posix_file_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t vfs_posix_file_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { mp_obj_vfs_posix_file_t *o = MP_OBJ_TO_PTR(o_in); check_fd_is_open(o); ssize_t r; @@ -126,7 +126,7 @@ STATIC mp_uint_t vfs_posix_file_read(mp_obj_t o_in, void *buf, mp_uint_t size, i return (mp_uint_t)r; } -STATIC mp_uint_t vfs_posix_file_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t vfs_posix_file_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) { mp_obj_vfs_posix_file_t *o = MP_OBJ_TO_PTR(o_in); check_fd_is_open(o); #if MICROPY_PY_OS_DUPTERM @@ -143,7 +143,7 @@ STATIC mp_uint_t vfs_posix_file_write(mp_obj_t o_in, const void *buf, mp_uint_t return (mp_uint_t)r; } -STATIC mp_uint_t vfs_posix_file_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t vfs_posix_file_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { mp_obj_vfs_posix_file_t *o = MP_OBJ_TO_PTR(o_in); if (request != MP_STREAM_CLOSE) { @@ -237,7 +237,7 @@ STATIC mp_uint_t vfs_posix_file_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_ } } -STATIC const mp_rom_map_elem_t vfs_posix_rawfile_locals_dict_table[] = { +static const mp_rom_map_elem_t vfs_posix_rawfile_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_fileno), MP_ROM_PTR(&vfs_posix_file_fileno_obj) }, { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) }, @@ -253,9 +253,9 @@ STATIC const mp_rom_map_elem_t vfs_posix_rawfile_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&mp_stream___exit___obj) }, }; -STATIC MP_DEFINE_CONST_DICT(vfs_posix_rawfile_locals_dict, vfs_posix_rawfile_locals_dict_table); +static MP_DEFINE_CONST_DICT(vfs_posix_rawfile_locals_dict, vfs_posix_rawfile_locals_dict_table); -STATIC const mp_stream_p_t vfs_posix_fileio_stream_p = { +static const mp_stream_p_t vfs_posix_fileio_stream_p = { .read = vfs_posix_file_read, .write = vfs_posix_file_write, .ioctl = vfs_posix_file_ioctl, @@ -270,7 +270,7 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &vfs_posix_rawfile_locals_dict ); -STATIC const mp_stream_p_t vfs_posix_textio_stream_p = { +static const mp_stream_p_t vfs_posix_textio_stream_p = { .read = vfs_posix_file_read, .write = vfs_posix_file_write, .ioctl = vfs_posix_file_ioctl, @@ -288,7 +288,7 @@ mp_obj_vfs_posix_file_t mp_sys_stdin_obj; mp_obj_vfs_posix_file_t mp_sys_stdout_obj; mp_obj_vfs_posix_file_t mp_sys_stderr_obj; -STATIC void vfs_posix_textio_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void vfs_posix_textio_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] != MP_OBJ_NULL) { // These objects are read-only. return; diff --git a/extmod/vfs_reader.c b/extmod/vfs_reader.c index 13fc31bee5080..80d0fa6344aa1 100644 --- a/extmod/vfs_reader.c +++ b/extmod/vfs_reader.c @@ -49,7 +49,7 @@ typedef struct _mp_reader_vfs_t { byte buf[]; } mp_reader_vfs_t; -STATIC mp_uint_t mp_reader_vfs_readbyte(void *data) { +static mp_uint_t mp_reader_vfs_readbyte(void *data) { mp_reader_vfs_t *reader = (mp_reader_vfs_t *)data; if (reader->bufpos >= reader->buflen) { if (reader->buflen < reader->bufsize) { @@ -70,7 +70,7 @@ STATIC mp_uint_t mp_reader_vfs_readbyte(void *data) { return reader->buf[reader->bufpos++]; } -STATIC void mp_reader_vfs_close(void *data) { +static void mp_reader_vfs_close(void *data) { mp_reader_vfs_t *reader = (mp_reader_vfs_t *)data; mp_stream_close(reader->file); m_del_obj(mp_reader_vfs_t, reader); diff --git a/mpy-cross/main.c b/mpy-cross/main.c index f05aef5dd8f44..0ac2e891d6dea 100644 --- a/mpy-cross/main.c +++ b/mpy-cross/main.c @@ -41,30 +41,30 @@ #endif // Command line options, with their defaults -STATIC uint emit_opt = MP_EMIT_OPT_NONE; +static uint emit_opt = MP_EMIT_OPT_NONE; mp_uint_t mp_verbose_flag = 0; // Heap size of GC heap (if enabled) // Make it larger on a 64 bit machine, because pointers are larger. long heap_size = 1024 * 1024 * (sizeof(mp_uint_t) / 4); -STATIC void stdout_print_strn(void *env, const char *str, size_t len) { +static void stdout_print_strn(void *env, const char *str, size_t len) { (void)env; ssize_t dummy = write(STDOUT_FILENO, str, len); (void)dummy; } -STATIC const mp_print_t mp_stdout_print = {NULL, stdout_print_strn}; +static const mp_print_t mp_stdout_print = {NULL, stdout_print_strn}; -STATIC void stderr_print_strn(void *env, const char *str, size_t len) { +static void stderr_print_strn(void *env, const char *str, size_t len) { (void)env; ssize_t dummy = write(STDERR_FILENO, str, len); (void)dummy; } -STATIC const mp_print_t mp_stderr_print = {NULL, stderr_print_strn}; +static const mp_print_t mp_stderr_print = {NULL, stderr_print_strn}; -STATIC int compile_and_save(const char *file, const char *output_file, const char *source_file) { +static int compile_and_save(const char *file, const char *output_file, const char *source_file) { nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { mp_lexer_t *lex; @@ -117,7 +117,7 @@ STATIC int compile_and_save(const char *file, const char *output_file, const cha } } -STATIC int usage(char **argv) { +static int usage(char **argv) { printf( "usage: %s [] [-X ] [--] \n" "Options:\n" @@ -155,7 +155,7 @@ STATIC int usage(char **argv) { } // Process options which set interpreter init options -STATIC void pre_process_options(int argc, char **argv) { +static void pre_process_options(int argc, char **argv) { for (int a = 1; a < argc; a++) { if (argv[a][0] == '-') { if (strcmp(argv[a], "-X") == 0) { @@ -201,7 +201,7 @@ STATIC void pre_process_options(int argc, char **argv) { } } -STATIC char *backslash_to_forwardslash(char *path) { +static char *backslash_to_forwardslash(char *path) { for (char *p = path; p != NULL && *p != '\0'; ++p) { if (*p == '\\') { *p = '/'; diff --git a/ports/cc3200/boards/make-pins.py b/ports/cc3200/boards/make-pins.py index f1bdf15a301a0..e30c02ce94a59 100644 --- a/ports/cc3200/boards/make-pins.py +++ b/ports/cc3200/boards/make-pins.py @@ -162,7 +162,7 @@ def parse_board_file(self, filename, cpu_pin_col): def print_named(self, label, pins, out_source): print("", file=out_source) print( - "STATIC const mp_rom_map_elem_t pin_{:s}_pins_locals_dict_table[] = {{".format(label), + "static const mp_rom_map_elem_t pin_{:s}_pins_locals_dict_table[] = {{".format(label), file=out_source, ) for pin in pins: diff --git a/ports/cc3200/ftp/ftp.c b/ports/cc3200/ftp/ftp.c index fc071fc9513d4..3f1099518fe57 100644 --- a/ports/cc3200/ftp/ftp.c +++ b/ports/cc3200/ftp/ftp.c @@ -201,7 +201,7 @@ static FIFO_t ftp_socketfifo; // all calls in an nlr handler. The wrapper functions below assume that there // are only FATFS filesystems mounted. -STATIC FATFS *lookup_path(const TCHAR **path) { +static FATFS *lookup_path(const TCHAR **path) { mp_vfs_mount_t *fs = mp_vfs_lookup_path(*path, path); if (fs == MP_VFS_NONE || fs == MP_VFS_ROOT) { return NULL; @@ -210,7 +210,7 @@ STATIC FATFS *lookup_path(const TCHAR **path) { return &((fs_user_mount_t*)MP_OBJ_TO_PTR(fs->obj))->fatfs; } -STATIC FRESULT f_open_helper(FIL *fp, const TCHAR *path, BYTE mode) { +static FRESULT f_open_helper(FIL *fp, const TCHAR *path, BYTE mode) { FATFS *fs = lookup_path(&path); if (fs == NULL) { return FR_NO_PATH; @@ -218,7 +218,7 @@ STATIC FRESULT f_open_helper(FIL *fp, const TCHAR *path, BYTE mode) { return f_open(fs, fp, path, mode); } -STATIC FRESULT f_opendir_helper(FF_DIR *dp, const TCHAR *path) { +static FRESULT f_opendir_helper(FF_DIR *dp, const TCHAR *path) { FATFS *fs = lookup_path(&path); if (fs == NULL) { return FR_NO_PATH; @@ -226,7 +226,7 @@ STATIC FRESULT f_opendir_helper(FF_DIR *dp, const TCHAR *path) { return f_opendir(fs, dp, path); } -STATIC FRESULT f_stat_helper(const TCHAR *path, FILINFO *fno) { +static FRESULT f_stat_helper(const TCHAR *path, FILINFO *fno) { FATFS *fs = lookup_path(&path); if (fs == NULL) { return FR_NO_PATH; @@ -234,7 +234,7 @@ STATIC FRESULT f_stat_helper(const TCHAR *path, FILINFO *fno) { return f_stat(fs, path, fno); } -STATIC FRESULT f_mkdir_helper(const TCHAR *path) { +static FRESULT f_mkdir_helper(const TCHAR *path) { FATFS *fs = lookup_path(&path); if (fs == NULL) { return FR_NO_PATH; @@ -242,7 +242,7 @@ STATIC FRESULT f_mkdir_helper(const TCHAR *path) { return f_mkdir(fs, path); } -STATIC FRESULT f_unlink_helper(const TCHAR *path) { +static FRESULT f_unlink_helper(const TCHAR *path) { FATFS *fs = lookup_path(&path); if (fs == NULL) { return FR_NO_PATH; @@ -250,7 +250,7 @@ STATIC FRESULT f_unlink_helper(const TCHAR *path) { return f_unlink(fs, path); } -STATIC FRESULT f_rename_helper(const TCHAR *path_old, const TCHAR *path_new) { +static FRESULT f_rename_helper(const TCHAR *path_old, const TCHAR *path_new) { FATFS *fs_old = lookup_path(&path_old); if (fs_old == NULL) { return FR_NO_PATH; diff --git a/ports/cc3200/misc/mpirq.c b/ports/cc3200/misc/mpirq.c index eb813fa4c6f2a..e371366b110b3 100644 --- a/ports/cc3200/misc/mpirq.c +++ b/ports/cc3200/misc/mpirq.c @@ -50,7 +50,7 @@ const mp_arg_t mp_irq_init_args[] = { /****************************************************************************** DECLARE PRIVATE DATA ******************************************************************************/ -STATIC uint8_t mp_irq_priorities[] = { INT_PRIORITY_LVL_7, INT_PRIORITY_LVL_6, INT_PRIORITY_LVL_5, INT_PRIORITY_LVL_4, +static uint8_t mp_irq_priorities[] = { INT_PRIORITY_LVL_7, INT_PRIORITY_LVL_6, INT_PRIORITY_LVL_5, INT_PRIORITY_LVL_4, INT_PRIORITY_LVL_3, INT_PRIORITY_LVL_2, INT_PRIORITY_LVL_1 }; /****************************************************************************** @@ -143,7 +143,7 @@ void mp_irq_handler (mp_obj_t self_in) { /******************************************************************************/ // MicroPython bindings -STATIC mp_obj_t mp_irq_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t mp_irq_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_irq_obj_t *self = pos_args[0]; // this is a bit of a hack, but it let us reuse the callback_create method from our parent ((mp_obj_t *)pos_args)[0] = self->parent; @@ -152,35 +152,35 @@ STATIC mp_obj_t mp_irq_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k } MP_DEFINE_CONST_FUN_OBJ_KW(mp_irq_init_obj, 1, mp_irq_init); -STATIC mp_obj_t mp_irq_enable (mp_obj_t self_in) { +static mp_obj_t mp_irq_enable (mp_obj_t self_in) { mp_irq_obj_t *self = self_in; self->methods->enable(self->parent); self->isenabled = true; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_irq_enable_obj, mp_irq_enable); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_irq_enable_obj, mp_irq_enable); -STATIC mp_obj_t mp_irq_disable (mp_obj_t self_in) { +static mp_obj_t mp_irq_disable (mp_obj_t self_in) { mp_irq_obj_t *self = self_in; self->methods->disable(self->parent); self->isenabled = false; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_irq_disable_obj, mp_irq_disable); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_irq_disable_obj, mp_irq_disable); -STATIC mp_obj_t mp_irq_flags (mp_obj_t self_in) { +static mp_obj_t mp_irq_flags (mp_obj_t self_in) { mp_irq_obj_t *self = self_in; return mp_obj_new_int(self->methods->flags(self->parent)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_irq_flags_obj, mp_irq_flags); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_irq_flags_obj, mp_irq_flags); -STATIC mp_obj_t mp_irq_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t mp_irq_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 0, false); mp_irq_handler (self_in); return mp_const_none; } -STATIC const mp_rom_map_elem_t mp_irq_locals_dict_table[] = { +static const mp_rom_map_elem_t mp_irq_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&mp_irq_init_obj) }, { MP_ROM_QSTR(MP_QSTR_enable), MP_ROM_PTR(&mp_irq_enable_obj) }, @@ -188,7 +188,7 @@ STATIC const mp_rom_map_elem_t mp_irq_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_flags), MP_ROM_PTR(&mp_irq_flags_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_irq_locals_dict, mp_irq_locals_dict_table); +static MP_DEFINE_CONST_DICT(mp_irq_locals_dict, mp_irq_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mp_irq_type, diff --git a/ports/cc3200/mods/machine_wdt.c b/ports/cc3200/mods/machine_wdt.c index b20ef7eb93cd5..58ecc1b5334c4 100644 --- a/ports/cc3200/mods/machine_wdt.c +++ b/ports/cc3200/mods/machine_wdt.c @@ -59,7 +59,7 @@ typedef struct _machine_wdt_obj_t { /****************************************************************************** DECLARE PRIVATE DATA ******************************************************************************/ -STATIC machine_wdt_obj_t machine_wdt_obj = {.servers = false, .servers_sleeping = false, .simplelink = false, .running = false}; +static machine_wdt_obj_t machine_wdt_obj = {.servers = false, .servers_sleeping = false, .simplelink = false, .running = false}; /****************************************************************************** DEFINE PUBLIC FUNCTIONS @@ -84,7 +84,7 @@ void pybwdt_sl_alive (void) { /******************************************************************************/ // MicroPython bindings -STATIC machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t timeout_ms) { +static machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t timeout_ms) { if (id != 0) { mp_raise_OSError(MP_ENODEV); } @@ -119,7 +119,7 @@ STATIC machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t return &machine_wdt_obj; } -STATIC void mp_machine_wdt_feed(machine_wdt_obj_t *self) { +static void mp_machine_wdt_feed(machine_wdt_obj_t *self) { if ((self->servers || self->servers_sleeping) && self->simplelink && self->running) { self->servers = false; self->simplelink = false; diff --git a/ports/cc3200/mods/modhashlib.c b/ports/cc3200/mods/modhashlib.c index de56e114af796..528ceeb2ee969 100644 --- a/ports/cc3200/mods/modhashlib.c +++ b/ports/cc3200/mods/modhashlib.c @@ -61,13 +61,13 @@ typedef struct _mp_obj_hash_t { /****************************************************************************** DECLARE PRIVATE FUNCTIONS ******************************************************************************/ -STATIC void hash_update_internal(mp_obj_t self_in, mp_obj_t data, bool digest); -STATIC mp_obj_t hash_read (mp_obj_t self_in); +static void hash_update_internal(mp_obj_t self_in, mp_obj_t data, bool digest); +static mp_obj_t hash_read (mp_obj_t self_in); /****************************************************************************** DEFINE PRIVATE FUNCTIONS ******************************************************************************/ -STATIC void hash_update_internal(mp_obj_t self_in, mp_obj_t data, bool digest) { +static void hash_update_internal(mp_obj_t self_in, mp_obj_t data, bool digest) { mp_obj_hash_t *self = self_in; mp_buffer_info_t bufinfo; @@ -95,7 +95,7 @@ STATIC void hash_update_internal(mp_obj_t self_in, mp_obj_t data, bool digest) { } } -STATIC mp_obj_t hash_read (mp_obj_t self_in) { +static mp_obj_t hash_read (mp_obj_t self_in) { mp_obj_hash_t *self = self_in; if (!self->fixedlen) { @@ -119,7 +119,7 @@ STATIC mp_obj_t hash_read (mp_obj_t self_in) { /// \classmethod \constructor([data[, block_size]]) /// initial data must be given if block_size wants to be passed -STATIC mp_obj_t hash_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t hash_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 2, false); mp_obj_hash_t *self = m_new0(mp_obj_hash_t, 1); self->base.type = type_in; @@ -151,24 +151,24 @@ STATIC mp_obj_t hash_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, cons return self; } -STATIC mp_obj_t hash_update(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t hash_update(mp_obj_t self_in, mp_obj_t arg) { mp_obj_hash_t *self = self_in; hash_update_internal(self, arg, false); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_2(hash_update_obj, hash_update); -STATIC mp_obj_t hash_digest(mp_obj_t self_in) { +static mp_obj_t hash_digest(mp_obj_t self_in) { return hash_read(self_in); } MP_DEFINE_CONST_FUN_OBJ_1(hash_digest_obj, hash_digest); -STATIC const mp_rom_map_elem_t hash_locals_dict_table[] = { +static const mp_rom_map_elem_t hash_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&hash_update_obj) }, { MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&hash_digest_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(hash_locals_dict, hash_locals_dict_table); +static MP_DEFINE_CONST_DICT(hash_locals_dict, hash_locals_dict_table); //STATIC const mp_obj_type_t md5_type = { // { &mp_type_type }, @@ -177,7 +177,7 @@ STATIC MP_DEFINE_CONST_DICT(hash_locals_dict, hash_locals_dict_table); // .locals_dict = (mp_obj_t)&hash_locals_dict, //}; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( sha1_type, MP_QSTR_sha1, MP_TYPE_FLAG_NONE, @@ -185,7 +185,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &hash_locals_dict ); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( sha256_type, MP_QSTR_sha256, MP_TYPE_FLAG_NONE, @@ -193,14 +193,14 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &hash_locals_dict ); -STATIC const mp_rom_map_elem_t mp_module_hashlib_globals_table[] = { +static const mp_rom_map_elem_t mp_module_hashlib_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_hashlib) }, //{ MP_ROM_QSTR(MP_QSTR_md5), MP_ROM_PTR(&md5_type) }, { MP_ROM_QSTR(MP_QSTR_sha1), MP_ROM_PTR(&sha1_type) }, { MP_ROM_QSTR(MP_QSTR_sha256), MP_ROM_PTR(&sha256_type) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_hashlib_globals, mp_module_hashlib_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_hashlib_globals, mp_module_hashlib_globals_table); const mp_obj_module_t mp_module_hashlib = { .base = { &mp_type_module }, diff --git a/ports/cc3200/mods/modmachine.c b/ports/cc3200/mods/modmachine.c index 6e50553365887..f7184df442736 100644 --- a/ports/cc3200/mods/modmachine.c +++ b/ports/cc3200/mods/modmachine.c @@ -93,7 +93,7 @@ extern OsiTaskHandle xSimpleLinkSpawnTaskHndl; /******************************************************************************/ // MicroPython bindings; -NORETURN STATIC void mp_machine_reset(void) { +NORETURN static void mp_machine_reset(void) { // disable wlan wlan_stop(SL_STOP_TIMEOUT_LONG); // reset the cpu and it's peripherals @@ -103,7 +103,7 @@ NORETURN STATIC void mp_machine_reset(void) { } #ifdef DEBUG -STATIC mp_obj_t machine_info(uint n_args, const mp_obj_t *args) { +static mp_obj_t machine_info(uint n_args, const mp_obj_t *args) { // FreeRTOS info { printf("---------------------------------------------\n"); @@ -126,24 +126,24 @@ STATIC mp_obj_t machine_info(uint n_args, const mp_obj_t *args) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj, 0, 1, machine_info); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj, 0, 1, machine_info); #endif -STATIC mp_obj_t mp_machine_get_freq(void) { +static mp_obj_t mp_machine_get_freq(void) { return mp_obj_new_int(HAL_FCPU_HZ); } -STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) { +static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) { mp_raise_NotImplementedError(NULL); } -STATIC mp_obj_t mp_machine_unique_id(void) { +static mp_obj_t mp_machine_unique_id(void) { uint8_t mac[SL_BSSID_LENGTH]; wlan_get_mac (mac); return mp_obj_new_bytes(mac, SL_BSSID_LENGTH); } -STATIC mp_obj_t machine_main(mp_obj_t main) { +static mp_obj_t machine_main(mp_obj_t main) { if (mp_obj_is_str(main)) { MP_STATE_PORT(machine_config_main) = main; } else { @@ -153,27 +153,27 @@ STATIC mp_obj_t machine_main(mp_obj_t main) { } MP_DEFINE_CONST_FUN_OBJ_1(machine_main_obj, machine_main); -STATIC void mp_machine_idle(void) { +static void mp_machine_idle(void) { __WFI(); } -STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) { +static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) { pyb_sleep_sleep(); } -NORETURN STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) { +NORETURN static void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) { pyb_sleep_deepsleep(); for (;;) { } } -STATIC mp_int_t mp_machine_reset_cause(void) { +static mp_int_t mp_machine_reset_cause(void) { return pyb_sleep_get_reset_cause(); } -STATIC mp_obj_t machine_wake_reason (void) { +static mp_obj_t machine_wake_reason (void) { return mp_obj_new_int(pyb_sleep_get_wake_reason()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_wake_reason_obj, machine_wake_reason); +static MP_DEFINE_CONST_FUN_OBJ_0(machine_wake_reason_obj, machine_wake_reason); MP_REGISTER_ROOT_POINTER(mp_obj_t machine_config_main); diff --git a/ports/cc3200/mods/modnetwork.c b/ports/cc3200/mods/modnetwork.c index 590e872683930..3a949136dcfdd 100644 --- a/ports/cc3200/mods/modnetwork.c +++ b/ports/cc3200/mods/modnetwork.c @@ -43,8 +43,8 @@ typedef struct { /****************************************************************************** DECLARE PRIVATE DATA ******************************************************************************/ -STATIC network_server_obj_t network_server_obj; -STATIC const mp_obj_type_t network_server_type; +static network_server_obj_t network_server_obj; +static const mp_obj_type_t network_server_type; /// \module network - network configuration /// @@ -54,7 +54,7 @@ void mod_network_init0(void) { } #if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP) -STATIC mp_obj_t network_server_init_helper(mp_obj_t self, const mp_arg_val_t *args) { +static mp_obj_t network_server_init_helper(mp_obj_t self, const mp_arg_val_t *args) { const char *user = SERVERS_DEF_USER; const char *pass = SERVERS_DEF_PASS; if (args[0].u_obj != MP_OBJ_NULL) { @@ -81,12 +81,12 @@ STATIC mp_obj_t network_server_init_helper(mp_obj_t self, const mp_arg_val_t *ar return mp_const_none; } -STATIC const mp_arg_t network_server_args[] = { +static const mp_arg_t network_server_args[] = { { MP_QSTR_id, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_login, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, }; -STATIC mp_obj_t network_server_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t network_server_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // parse args mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); @@ -108,16 +108,16 @@ STATIC mp_obj_t network_server_make_new(const mp_obj_type_t *type, size_t n_args return (mp_obj_t)self; } -STATIC mp_obj_t network_server_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t network_server_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // parse args mp_arg_val_t args[MP_ARRAY_SIZE(network_server_args) - 1]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &network_server_args[1], args); return network_server_init_helper(pos_args[0], args); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(network_server_init_obj, 1, network_server_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(network_server_init_obj, 1, network_server_init); // timeout value given in seconds -STATIC mp_obj_t network_server_timeout(size_t n_args, const mp_obj_t *args) { +static mp_obj_t network_server_timeout(size_t n_args, const mp_obj_t *args) { if (n_args > 1) { uint32_t timeout = mp_obj_get_int(args[1]); servers_set_timeout(timeout * 1000); @@ -127,23 +127,23 @@ STATIC mp_obj_t network_server_timeout(size_t n_args, const mp_obj_t *args) { return mp_obj_new_int(servers_get_timeout() / 1000); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_server_timeout_obj, 1, 2, network_server_timeout); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_server_timeout_obj, 1, 2, network_server_timeout); -STATIC mp_obj_t network_server_running(mp_obj_t self_in) { +static mp_obj_t network_server_running(mp_obj_t self_in) { // get return mp_obj_new_bool(servers_are_enabled()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_server_running_obj, network_server_running); +static MP_DEFINE_CONST_FUN_OBJ_1(network_server_running_obj, network_server_running); -STATIC mp_obj_t network_server_deinit(mp_obj_t self_in) { +static mp_obj_t network_server_deinit(mp_obj_t self_in) { // simply stop the servers servers_stop(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_server_deinit_obj, network_server_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(network_server_deinit_obj, network_server_deinit); #endif -STATIC const mp_rom_map_elem_t mp_module_network_globals_table[] = { +static const mp_rom_map_elem_t mp_module_network_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_network) }, { MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&mod_network_nic_type_wlan) }, @@ -152,7 +152,7 @@ STATIC const mp_rom_map_elem_t mp_module_network_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_network_globals, mp_module_network_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_network_globals, mp_module_network_globals_table); const mp_obj_module_t mp_module_network = { .base = { &mp_type_module }, @@ -162,16 +162,16 @@ const mp_obj_module_t mp_module_network = { MP_REGISTER_MODULE(MP_QSTR_network, mp_module_network); #if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP) -STATIC const mp_rom_map_elem_t network_server_locals_dict_table[] = { +static const mp_rom_map_elem_t network_server_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&network_server_init_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&network_server_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR_timeout), MP_ROM_PTR(&network_server_timeout_obj) }, { MP_ROM_QSTR(MP_QSTR_isrunning), MP_ROM_PTR(&network_server_running_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(network_server_locals_dict, network_server_locals_dict_table); +static MP_DEFINE_CONST_DICT(network_server_locals_dict, network_server_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( network_server_type, MP_QSTR_Server, MP_TYPE_FLAG_NONE, diff --git a/ports/cc3200/mods/modos.c b/ports/cc3200/mods/modos.c index c62c5e22c45b4..8c22ad8dafed6 100644 --- a/ports/cc3200/mods/modos.c +++ b/ports/cc3200/mods/modos.c @@ -31,7 +31,7 @@ #include "py/runtime.h" #include "random.h" -STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { +static mp_obj_t mp_os_urandom(mp_obj_t num) { mp_int_t n = mp_obj_get_int(num); vstr_t vstr; vstr_init_len(&vstr, n); @@ -40,4 +40,4 @@ STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { } return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); diff --git a/ports/cc3200/mods/modsocket.c b/ports/cc3200/mods/modsocket.c index 0f56c15e821fe..c9065d488d194 100644 --- a/ports/cc3200/mods/modsocket.c +++ b/ports/cc3200/mods/modsocket.c @@ -70,7 +70,7 @@ #define SOCKET_TIMEOUT_QUANTA_MS (20) -STATIC int convert_sl_errno(int sl_errno) { +static int convert_sl_errno(int sl_errno) { return -sl_errno; } @@ -93,7 +93,7 @@ int check_timedout(mod_network_socket_obj_t *s, int ret, uint32_t *timeout_ms, i return 0; } -STATIC int wlan_gethostbyname(const char *name, mp_uint_t len, uint8_t *out_ip, uint8_t family) { +static int wlan_gethostbyname(const char *name, mp_uint_t len, uint8_t *out_ip, uint8_t family) { uint32_t ip; int result = sl_NetAppDnsGetHostByName((_i8 *)name, (_u16)len, (_u32*)&ip, (_u8)family); out_ip[0] = ip; @@ -103,7 +103,7 @@ STATIC int wlan_gethostbyname(const char *name, mp_uint_t len, uint8_t *out_ip, return result; } -STATIC int wlan_socket_socket(mod_network_socket_obj_t *s, int *_errno) { +static int wlan_socket_socket(mod_network_socket_obj_t *s, int *_errno) { int16_t sd = sl_Socket(s->sock_base.u_param.domain, s->sock_base.u_param.type, s->sock_base.u_param.proto); if (sd < 0) { *_errno = sd; @@ -113,7 +113,7 @@ STATIC int wlan_socket_socket(mod_network_socket_obj_t *s, int *_errno) { return 0; } -STATIC void wlan_socket_close(mod_network_socket_obj_t *s) { +static void wlan_socket_close(mod_network_socket_obj_t *s) { // this is to prevent the finalizer to close a socket that failed when being created if (s->sock_base.sd >= 0) { modusocket_socket_delete(s->sock_base.sd); @@ -122,7 +122,7 @@ STATIC void wlan_socket_close(mod_network_socket_obj_t *s) { } } -STATIC int wlan_socket_bind(mod_network_socket_obj_t *s, byte *ip, mp_uint_t port, int *_errno) { +static int wlan_socket_bind(mod_network_socket_obj_t *s, byte *ip, mp_uint_t port, int *_errno) { MAKE_SOCKADDR(addr, ip, port) int ret = sl_Bind(s->sock_base.sd, &addr, sizeof(addr)); if (ret != 0) { @@ -132,7 +132,7 @@ STATIC int wlan_socket_bind(mod_network_socket_obj_t *s, byte *ip, mp_uint_t por return 0; } -STATIC int wlan_socket_listen(mod_network_socket_obj_t *s, mp_int_t backlog, int *_errno) { +static int wlan_socket_listen(mod_network_socket_obj_t *s, mp_int_t backlog, int *_errno) { int ret = sl_Listen(s->sock_base.sd, backlog); if (ret != 0) { *_errno = ret; @@ -141,7 +141,7 @@ STATIC int wlan_socket_listen(mod_network_socket_obj_t *s, mp_int_t backlog, int return 0; } -STATIC int wlan_socket_accept(mod_network_socket_obj_t *s, mod_network_socket_obj_t *s2, byte *ip, mp_uint_t *port, int *_errno) { +static int wlan_socket_accept(mod_network_socket_obj_t *s, mod_network_socket_obj_t *s2, byte *ip, mp_uint_t *port, int *_errno) { // accept incoming connection int16_t sd; SlSockAddr_t addr; @@ -163,7 +163,7 @@ STATIC int wlan_socket_accept(mod_network_socket_obj_t *s, mod_network_socket_ob } } -STATIC int wlan_socket_connect(mod_network_socket_obj_t *s, byte *ip, mp_uint_t port, int *_errno) { +static int wlan_socket_connect(mod_network_socket_obj_t *s, byte *ip, mp_uint_t port, int *_errno) { MAKE_SOCKADDR(addr, ip, port) uint32_t timeout_ms = s->sock_base.timeout_ms; @@ -195,7 +195,7 @@ STATIC int wlan_socket_connect(mod_network_socket_obj_t *s, byte *ip, mp_uint_t } } -STATIC int wlan_socket_send(mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, int *_errno) { +static int wlan_socket_send(mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, int *_errno) { if (len == 0) { return 0; } @@ -211,7 +211,7 @@ STATIC int wlan_socket_send(mod_network_socket_obj_t *s, const byte *buf, mp_uin } } -STATIC int wlan_socket_recv(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, int *_errno) { +static int wlan_socket_recv(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, int *_errno) { uint32_t timeout_ms = s->sock_base.timeout_ms; for (;;) { int ret = sl_Recv(s->sock_base.sd, buf, MIN(len, WLAN_MAX_RX_SIZE), 0); @@ -224,7 +224,7 @@ STATIC int wlan_socket_recv(mod_network_socket_obj_t *s, byte *buf, mp_uint_t le } } -STATIC int wlan_socket_sendto( mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, byte *ip, mp_uint_t port, int *_errno) { +static int wlan_socket_sendto( mod_network_socket_obj_t *s, const byte *buf, mp_uint_t len, byte *ip, mp_uint_t port, int *_errno) { MAKE_SOCKADDR(addr, ip, port) uint32_t timeout_ms = s->sock_base.timeout_ms; for (;;) { @@ -238,7 +238,7 @@ STATIC int wlan_socket_sendto( mod_network_socket_obj_t *s, const byte *buf, mp_ } } -STATIC int wlan_socket_recvfrom(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno) { +static int wlan_socket_recvfrom(mod_network_socket_obj_t *s, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno) { SlSockAddr_t addr; SlSocklen_t addr_len = sizeof(addr); uint32_t timeout_ms = s->sock_base.timeout_ms; @@ -254,7 +254,7 @@ STATIC int wlan_socket_recvfrom(mod_network_socket_obj_t *s, byte *buf, mp_uint_ } } -STATIC int wlan_socket_setsockopt(mod_network_socket_obj_t *s, mp_uint_t level, mp_uint_t opt, const void *optval, mp_uint_t optlen, int *_errno) { +static int wlan_socket_setsockopt(mod_network_socket_obj_t *s, mp_uint_t level, mp_uint_t opt, const void *optval, mp_uint_t optlen, int *_errno) { int ret = sl_SetSockOpt(s->sock_base.sd, level, opt, optval, optlen); if (ret < 0) { *_errno = ret; @@ -263,7 +263,7 @@ STATIC int wlan_socket_setsockopt(mod_network_socket_obj_t *s, mp_uint_t level, return 0; } -STATIC int wlan_socket_settimeout(mod_network_socket_obj_t *s, mp_uint_t timeout_s, int *_errno) { +static int wlan_socket_settimeout(mod_network_socket_obj_t *s, mp_uint_t timeout_s, int *_errno) { SlSockNonblocking_t option; if (timeout_s == 0 || timeout_s == -1) { if (timeout_s == 0) { @@ -289,7 +289,7 @@ STATIC int wlan_socket_settimeout(mod_network_socket_obj_t *s, mp_uint_t timeout return 0; } -STATIC int wlan_socket_ioctl (mod_network_socket_obj_t *s, mp_uint_t request, mp_uint_t arg, int *_errno) { +static int wlan_socket_ioctl (mod_network_socket_obj_t *s, mp_uint_t request, mp_uint_t arg, int *_errno) { mp_int_t ret; if (request == MP_STREAM_POLL) { mp_uint_t flags = arg; @@ -361,9 +361,9 @@ typedef struct { /****************************************************************************** DEFINE PRIVATE DATA ******************************************************************************/ -STATIC const mp_obj_type_t socket_type; -STATIC OsiLockObj_t modusocket_LockObj; -STATIC modusocket_sock_t modusocket_sockets[MOD_NETWORK_MAX_SOCKETS] = {{.sd = -1}, {.sd = -1}, {.sd = -1}, {.sd = -1}, {.sd = -1}, +static const mp_obj_type_t socket_type; +static OsiLockObj_t modusocket_LockObj; +static modusocket_sock_t modusocket_sockets[MOD_NETWORK_MAX_SOCKETS] = {{.sd = -1}, {.sd = -1}, {.sd = -1}, {.sd = -1}, {.sd = -1}, {.sd = -1}, {.sd = -1}, {.sd = -1}, {.sd = -1}, {.sd = -1}}; /****************************************************************************** @@ -432,7 +432,7 @@ void modusocket_close_all_user_sockets (void) { // socket class // constructor socket(family=AF_INET, type=SOCK_STREAM, proto=IPPROTO_TCP, fileno=None) -STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 4, false); // create socket object @@ -468,7 +468,7 @@ STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t } // method socket.bind(address) -STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { +static mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { mod_network_socket_obj_t *self = self_in; // get address @@ -482,10 +482,10 @@ STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind); // method socket.listen([backlog]) -STATIC mp_obj_t socket_listen(size_t n_args, const mp_obj_t *args) { +static mp_obj_t socket_listen(size_t n_args, const mp_obj_t *args) { mod_network_socket_obj_t *self = args[0]; int32_t backlog = MICROPY_PY_SOCKET_LISTEN_BACKLOG_DEFAULT; @@ -500,10 +500,10 @@ STATIC mp_obj_t socket_listen(size_t n_args, const mp_obj_t *args) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_listen_obj, 1, 2, socket_listen); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_listen_obj, 1, 2, socket_listen); // method socket.accept() -STATIC mp_obj_t socket_accept(mp_obj_t self_in) { +static mp_obj_t socket_accept(mp_obj_t self_in) { mod_network_socket_obj_t *self = self_in; // create new socket object @@ -528,10 +528,10 @@ STATIC mp_obj_t socket_accept(mp_obj_t self_in) { client->items[1] = netutils_format_inet_addr(ip, port, NETUTILS_LITTLE); return client; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_accept_obj, socket_accept); +static MP_DEFINE_CONST_FUN_OBJ_1(socket_accept_obj, socket_accept); // method socket.connect(address) -STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { +static mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { mod_network_socket_obj_t *self = self_in; // get address @@ -548,10 +548,10 @@ STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect); // method socket.send(bytes) -STATIC mp_obj_t socket_send(mp_obj_t self_in, mp_obj_t buf_in) { +static mp_obj_t socket_send(mp_obj_t self_in, mp_obj_t buf_in) { mod_network_socket_obj_t *self = self_in; mp_buffer_info_t bufinfo; mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ); @@ -562,10 +562,10 @@ STATIC mp_obj_t socket_send(mp_obj_t self_in, mp_obj_t buf_in) { } return mp_obj_new_int_from_uint(ret); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_send_obj, socket_send); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_send_obj, socket_send); // method socket.recv(bufsize) -STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) { +static mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) { mod_network_socket_obj_t *self = self_in; mp_int_t len = mp_obj_get_int(len_in); vstr_t vstr; @@ -582,10 +582,10 @@ STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) { vstr.buf[vstr.len] = '\0'; return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_recv_obj, socket_recv); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_recv_obj, socket_recv); // method socket.sendto(bytes, address) -STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_in) { +static mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_in) { mod_network_socket_obj_t *self = self_in; // get the data @@ -604,10 +604,10 @@ STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_ } return mp_obj_new_int(ret); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(socket_sendto_obj, socket_sendto); +static MP_DEFINE_CONST_FUN_OBJ_3(socket_sendto_obj, socket_sendto); // method socket.recvfrom(bufsize) -STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) { +static mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) { mod_network_socket_obj_t *self = self_in; vstr_t vstr; vstr_init_len(&vstr, mp_obj_get_int(len_in)); @@ -629,10 +629,10 @@ STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) { tuple[1] = netutils_format_inet_addr(ip, port, NETUTILS_LITTLE); return mp_obj_new_tuple(2, tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_recvfrom_obj, socket_recvfrom); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_recvfrom_obj, socket_recvfrom); // method socket.setsockopt(level, optname, value) -STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) { +static mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) { mod_network_socket_obj_t *self = args[0]; mp_int_t level = mp_obj_get_int(args[1]); @@ -658,13 +658,13 @@ STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_setsockopt_obj, 4, 4, socket_setsockopt); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_setsockopt_obj, 4, 4, socket_setsockopt); // method socket.settimeout(value) // timeout=0 means non-blocking // timeout=None means blocking // otherwise, timeout is in seconds -STATIC mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) { +static mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) { mod_network_socket_obj_t *self = self_in; mp_uint_t timeout; if (timeout_in == mp_const_none) { @@ -678,25 +678,25 @@ STATIC mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_settimeout_obj, socket_settimeout); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_settimeout_obj, socket_settimeout); // method socket.setblocking(flag) -STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t blocking) { +static mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t blocking) { if (mp_obj_is_true(blocking)) { return socket_settimeout(self_in, mp_const_none); } else { return socket_settimeout(self_in, MP_OBJ_NEW_SMALL_INT(0)); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking); -STATIC mp_obj_t socket_makefile(size_t n_args, const mp_obj_t *args) { +static mp_obj_t socket_makefile(size_t n_args, const mp_obj_t *args) { (void)n_args; return args[0]; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_makefile_obj, 1, 6, socket_makefile); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_makefile_obj, 1, 6, socket_makefile); -STATIC const mp_rom_map_elem_t socket_locals_dict_table[] = { +static const mp_rom_map_elem_t socket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_stream_close_obj) }, { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) }, { MP_ROM_QSTR(MP_QSTR_bind), MP_ROM_PTR(&socket_bind_obj) }, @@ -722,7 +722,7 @@ STATIC const mp_rom_map_elem_t socket_locals_dict_table[] = { MP_DEFINE_CONST_DICT(socket_locals_dict, socket_locals_dict_table); -STATIC mp_uint_t socket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t socket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { mod_network_socket_obj_t *self = self_in; mp_int_t ret = wlan_socket_recv(self, buf, size, errcode); if (ret < 0) { @@ -737,7 +737,7 @@ STATIC mp_uint_t socket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *e return ret; } -STATIC mp_uint_t socket_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t socket_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { mod_network_socket_obj_t *self = self_in; mp_int_t ret = wlan_socket_send(self, buf, size, errcode); if (ret < 0) { @@ -746,7 +746,7 @@ STATIC mp_uint_t socket_write(mp_obj_t self_in, const void *buf, mp_uint_t size, return ret; } -STATIC mp_uint_t socket_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) { +static mp_uint_t socket_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) { mod_network_socket_obj_t *self = self_in; return wlan_socket_ioctl(self, request, arg, errcode); } @@ -758,7 +758,7 @@ const mp_stream_p_t socket_stream_p = { .is_text = false, }; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( socket_type, MP_QSTR_socket, MP_TYPE_FLAG_NONE, @@ -772,7 +772,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( // function socket.getaddrinfo(host, port) /// \function getaddrinfo(host, port) -STATIC mp_obj_t mod_socket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) { +static mp_obj_t mod_socket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) { size_t hlen; const char *host = mp_obj_str_get_data(host_in, &hlen); mp_int_t port = mp_obj_get_int(port_in); @@ -791,9 +791,9 @@ STATIC mp_obj_t mod_socket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) { tuple->items[4] = netutils_format_inet_addr(out_ip, port, NETUTILS_LITTLE); return mp_obj_new_list(1, (mp_obj_t*)&tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_socket_getaddrinfo_obj, mod_socket_getaddrinfo); +static MP_DEFINE_CONST_FUN_OBJ_2(mod_socket_getaddrinfo_obj, mod_socket_getaddrinfo); -STATIC const mp_rom_map_elem_t mp_module_socket_globals_table[] = { +static const mp_rom_map_elem_t mp_module_socket_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_socket) }, { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&socket_type) }, @@ -810,7 +810,7 @@ STATIC const mp_rom_map_elem_t mp_module_socket_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_IPPROTO_UDP), MP_ROM_INT(SL_IPPROTO_UDP) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_socket_globals, mp_module_socket_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_socket_globals, mp_module_socket_globals_table); const mp_obj_module_t mp_module_socket = { .base = { &mp_type_module }, diff --git a/ports/cc3200/mods/modssl.c b/ports/cc3200/mods/modssl.c index 15c825fcf4dcb..62067d3f32273 100644 --- a/ports/cc3200/mods/modssl.c +++ b/ports/cc3200/mods/modssl.c @@ -53,14 +53,14 @@ typedef struct _mp_obj_ssl_socket_t { /****************************************************************************** DECLARE PRIVATE DATA ******************************************************************************/ -STATIC const mp_obj_type_t ssl_socket_type; +static const mp_obj_type_t ssl_socket_type; /******************************************************************************/ // MicroPython bindings; SSL class // ssl sockets inherit from normal socket, so we take its // locals and stream methods -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( ssl_socket_type, MP_QSTR_ssl, MP_TYPE_FLAG_NONE, @@ -68,8 +68,8 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &socket_locals_dict ); -STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - STATIC const mp_arg_t allowed_args[] = { +static mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + static const mp_arg_t allowed_args[] = { { MP_QSTR_sock, MP_ARG_REQUIRED | MP_ARG_OBJ, }, { MP_QSTR_keyfile, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_certfile, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, @@ -133,9 +133,9 @@ STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_ arg_error: mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value")); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_ssl_wrap_socket_obj, 0, mod_ssl_wrap_socket); +static MP_DEFINE_CONST_FUN_OBJ_KW(mod_ssl_wrap_socket_obj, 0, mod_ssl_wrap_socket); -STATIC const mp_rom_map_elem_t mp_module_ssl_globals_table[] = { +static const mp_rom_map_elem_t mp_module_ssl_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ssl) }, { MP_ROM_QSTR(MP_QSTR_wrap_socket), MP_ROM_PTR(&mod_ssl_wrap_socket_obj) }, @@ -153,7 +153,7 @@ STATIC const mp_rom_map_elem_t mp_module_ssl_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_PROTOCOL_TLSv1_2), MP_ROM_INT(SL_SO_SEC_METHOD_TLSV1_2) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_ssl_globals, mp_module_ssl_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_ssl_globals, mp_module_ssl_globals_table); const mp_obj_module_t mp_module_ssl = { .base = { &mp_type_module }, diff --git a/ports/cc3200/mods/modtime.c b/ports/cc3200/mods/modtime.c index 6fa98296d2fbd..21388568ab8e8 100644 --- a/ports/cc3200/mods/modtime.c +++ b/ports/cc3200/mods/modtime.c @@ -30,7 +30,7 @@ #include "pybrtc.h" // Return the localtime as an 8-tuple. -STATIC mp_obj_t mp_time_localtime_get(void) { +static mp_obj_t mp_time_localtime_get(void) { timeutils_struct_time_t tm; // get the seconds from the RTC @@ -49,6 +49,6 @@ STATIC mp_obj_t mp_time_localtime_get(void) { } // Returns the number of seconds, as an integer, since the Epoch. -STATIC mp_obj_t mp_time_time_get(void) { +static mp_obj_t mp_time_time_get(void) { return mp_obj_new_int(pyb_rtc_get_seconds()); } diff --git a/ports/cc3200/mods/modwipy.c b/ports/cc3200/mods/modwipy.c index 110c3cfd3622f..bb0ac4978df06 100644 --- a/ports/cc3200/mods/modwipy.c +++ b/ports/cc3200/mods/modwipy.c @@ -7,7 +7,7 @@ /******************************************************************************/ // MicroPython bindings -STATIC mp_obj_t mod_wipy_heartbeat(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_wipy_heartbeat(size_t n_args, const mp_obj_t *args) { if (n_args) { mperror_enable_heartbeat (mp_obj_is_true(args[0])); return mp_const_none; @@ -15,14 +15,14 @@ STATIC mp_obj_t mod_wipy_heartbeat(size_t n_args, const mp_obj_t *args) { return mp_obj_new_bool(mperror_is_heartbeat_enabled()); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_wipy_heartbeat_obj, 0, 1, mod_wipy_heartbeat); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_wipy_heartbeat_obj, 0, 1, mod_wipy_heartbeat); -STATIC const mp_rom_map_elem_t wipy_module_globals_table[] = { +static const mp_rom_map_elem_t wipy_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_wipy) }, { MP_ROM_QSTR(MP_QSTR_heartbeat), MP_ROM_PTR(&mod_wipy_heartbeat_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(wipy_module_globals, wipy_module_globals_table); +static MP_DEFINE_CONST_DICT(wipy_module_globals, wipy_module_globals_table); const mp_obj_module_t wipy_module = { .base = { &mp_type_module }, diff --git a/ports/cc3200/mods/modwlan.c b/ports/cc3200/mods/modwlan.c index 8d98dd0421de2..fc55201eaa3c0 100644 --- a/ports/cc3200/mods/modwlan.c +++ b/ports/cc3200/mods/modwlan.c @@ -114,7 +114,7 @@ typedef enum{ /****************************************************************************** DECLARE PRIVATE DATA ******************************************************************************/ -STATIC wlan_obj_t wlan_obj = { +static wlan_obj_t wlan_obj = { .mode = -1, .status = 0, .ip = 0, @@ -130,7 +130,7 @@ STATIC wlan_obj_t wlan_obj = { #endif }; -STATIC const mp_irq_methods_t wlan_irq_methods; +static const mp_irq_methods_t wlan_irq_methods; /****************************************************************************** DECLARE PUBLIC DATA @@ -142,31 +142,31 @@ OsiLockObj_t wlan_LockObj; /****************************************************************************** DECLARE PRIVATE FUNCTIONS ******************************************************************************/ -STATIC void wlan_clear_data (void); -STATIC void wlan_reenable (SlWlanMode_t mode); -STATIC void wlan_servers_start (void); -STATIC void wlan_servers_stop (void); -STATIC void wlan_reset (void); -STATIC void wlan_validate_mode (uint mode); -STATIC void wlan_set_mode (uint mode); -STATIC void wlan_validate_ssid_len (uint32_t len); -STATIC void wlan_set_ssid (const char *ssid, uint8_t len, bool add_mac); -STATIC void wlan_validate_security (uint8_t auth, const char *key, uint8_t len); -STATIC void wlan_set_security (uint8_t auth, const char *key, uint8_t len); -STATIC void wlan_validate_channel (uint8_t channel); -STATIC void wlan_set_channel (uint8_t channel); +static void wlan_clear_data (void); +static void wlan_reenable (SlWlanMode_t mode); +static void wlan_servers_start (void); +static void wlan_servers_stop (void); +static void wlan_reset (void); +static void wlan_validate_mode (uint mode); +static void wlan_set_mode (uint mode); +static void wlan_validate_ssid_len (uint32_t len); +static void wlan_set_ssid (const char *ssid, uint8_t len, bool add_mac); +static void wlan_validate_security (uint8_t auth, const char *key, uint8_t len); +static void wlan_set_security (uint8_t auth, const char *key, uint8_t len); +static void wlan_validate_channel (uint8_t channel); +static void wlan_set_channel (uint8_t channel); #if MICROPY_HW_ANTENNA_DIVERSITY -STATIC void wlan_validate_antenna (uint8_t antenna); -STATIC void wlan_set_antenna (uint8_t antenna); +static void wlan_validate_antenna (uint8_t antenna); +static void wlan_set_antenna (uint8_t antenna); #endif -STATIC void wlan_sl_disconnect (void); -STATIC modwlan_Status_t wlan_do_connect (const char* ssid, uint32_t ssid_len, const char* bssid, uint8_t sec, +static void wlan_sl_disconnect (void); +static modwlan_Status_t wlan_do_connect (const char* ssid, uint32_t ssid_len, const char* bssid, uint8_t sec, const char* key, uint32_t key_len, int32_t timeout); -STATIC void wlan_get_sl_mac (void); -STATIC void wlan_wep_key_unhexlify (const char *key, char *key_out); -STATIC void wlan_lpds_irq_enable (mp_obj_t self_in); -STATIC void wlan_lpds_irq_disable (mp_obj_t self_in); -STATIC bool wlan_scan_result_is_unique (const mp_obj_list_t *nets, _u8 *bssid); +static void wlan_get_sl_mac (void); +static void wlan_wep_key_unhexlify (const char *key, char *key_out); +static void wlan_lpds_irq_enable (mp_obj_t self_in); +static void wlan_lpds_irq_disable (mp_obj_t self_in); +static bool wlan_scan_result_is_unique (const mp_obj_list_t *nets, _u8 *bssid); //***************************************************************************** // @@ -541,14 +541,14 @@ void wlan_off_on (void) { // DEFINE STATIC FUNCTIONS //***************************************************************************** -STATIC void wlan_clear_data (void) { +static void wlan_clear_data (void) { CLR_STATUS_BIT_ALL(wlan_obj.status); wlan_obj.ip = 0; //memset(wlan_obj.ssid_o, 0, sizeof(wlan_obj.ssid)); //memset(wlan_obj.bssid, 0, sizeof(wlan_obj.bssid)); } -STATIC void wlan_reenable (SlWlanMode_t mode) { +static void wlan_reenable (SlWlanMode_t mode) { // stop and start again #ifdef SL_PLATFORM_MULTI_THREADED sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER); @@ -562,7 +562,7 @@ STATIC void wlan_reenable (SlWlanMode_t mode) { ASSERT (wlan_obj.mode == mode); } -STATIC void wlan_servers_start (void) { +static void wlan_servers_start (void) { #if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP) // start the servers if they were enabled before if (wlan_obj.servers_enabled) { @@ -571,7 +571,7 @@ STATIC void wlan_servers_start (void) { #endif } -STATIC void wlan_servers_stop (void) { +static void wlan_servers_stop (void) { #if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP) // Stop all other processes using the wlan engine if ((wlan_obj.servers_enabled = servers_are_enabled())) { @@ -580,30 +580,30 @@ STATIC void wlan_servers_stop (void) { #endif } -STATIC void wlan_reset (void) { +static void wlan_reset (void) { wlan_servers_stop(); wlan_reenable (wlan_obj.mode); wlan_servers_start(); } -STATIC void wlan_validate_mode (uint mode) { +static void wlan_validate_mode (uint mode) { if (mode != ROLE_STA && mode != ROLE_AP) { mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value")); } } -STATIC void wlan_set_mode (uint mode) { +static void wlan_set_mode (uint mode) { wlan_obj.mode = mode; ASSERT_ON_ERROR(sl_WlanSetMode(mode)); } -STATIC void wlan_validate_ssid_len (uint32_t len) { +static void wlan_validate_ssid_len (uint32_t len) { if (len > MODWLAN_SSID_LEN_MAX) { mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value")); } } -STATIC void wlan_set_ssid (const char *ssid, uint8_t len, bool add_mac) { +static void wlan_set_ssid (const char *ssid, uint8_t len, bool add_mac) { if (ssid != NULL) { // save the ssid memcpy(&wlan_obj.ssid, ssid, len); @@ -618,7 +618,7 @@ STATIC void wlan_set_ssid (const char *ssid, uint8_t len, bool add_mac) { } } -STATIC void wlan_validate_security (uint8_t auth, const char *key, uint8_t len) { +static void wlan_validate_security (uint8_t auth, const char *key, uint8_t len) { if (auth != SL_SEC_TYPE_WEP && auth != SL_SEC_TYPE_WPA_WPA2) { goto invalid_args; } @@ -635,7 +635,7 @@ STATIC void wlan_validate_security (uint8_t auth, const char *key, uint8_t len) mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value")); } -STATIC void wlan_set_security (uint8_t auth, const char *key, uint8_t len) { +static void wlan_set_security (uint8_t auth, const char *key, uint8_t len) { wlan_obj.auth = auth; ASSERT_ON_ERROR(sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SECURITY_TYPE, sizeof(uint8_t), &auth)); if (key != NULL) { @@ -653,31 +653,31 @@ STATIC void wlan_set_security (uint8_t auth, const char *key, uint8_t len) { } } -STATIC void wlan_validate_channel (uint8_t channel) { +static void wlan_validate_channel (uint8_t channel) { if (channel < 1 || channel > 11) { mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value")); } } -STATIC void wlan_set_channel (uint8_t channel) { +static void wlan_set_channel (uint8_t channel) { wlan_obj.channel = channel; ASSERT_ON_ERROR(sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_CHANNEL, 1, &channel)); } #if MICROPY_HW_ANTENNA_DIVERSITY -STATIC void wlan_validate_antenna (uint8_t antenna) { +static void wlan_validate_antenna (uint8_t antenna) { if (antenna != ANTENNA_TYPE_INTERNAL && antenna != ANTENNA_TYPE_EXTERNAL) { mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value")); } } -STATIC void wlan_set_antenna (uint8_t antenna) { +static void wlan_set_antenna (uint8_t antenna) { wlan_obj.antenna = antenna; antenna_select(antenna); } #endif -STATIC void wlan_sl_disconnect (void) { +static void wlan_sl_disconnect (void) { // Device in station-mode. Disconnect previous connection if any // The function returns 0 if 'Disconnected done', negative number if already // disconnected Wait for 'disconnection' event if 0 is returned, Ignore @@ -690,7 +690,7 @@ STATIC void wlan_sl_disconnect (void) { } } -STATIC modwlan_Status_t wlan_do_connect (const char* ssid, uint32_t ssid_len, const char* bssid, uint8_t sec, +static modwlan_Status_t wlan_do_connect (const char* ssid, uint32_t ssid_len, const char* bssid, uint8_t sec, const char* key, uint32_t key_len, int32_t timeout) { SlSecParams_t secParams; secParams.Key = (_i8*)key; @@ -716,13 +716,13 @@ STATIC modwlan_Status_t wlan_do_connect (const char* ssid, uint32_t ssid_len, co return MODWLAN_ERROR_INVALID_PARAMS; } -STATIC void wlan_get_sl_mac (void) { +static void wlan_get_sl_mac (void) { // Get the MAC address uint8_t macAddrLen = SL_MAC_ADDR_LEN; sl_NetCfgGet(SL_MAC_ADDRESS_GET, NULL, &macAddrLen, wlan_obj.mac); } -STATIC void wlan_wep_key_unhexlify (const char *key, char *key_out) { +static void wlan_wep_key_unhexlify (const char *key, char *key_out) { byte hex_byte = 0; for (mp_uint_t i = strlen(key); i > 0 ; i--) { hex_byte += unichar_xdigit_value(*key++); @@ -735,22 +735,22 @@ STATIC void wlan_wep_key_unhexlify (const char *key, char *key_out) { } } -STATIC void wlan_lpds_irq_enable (mp_obj_t self_in) { +static void wlan_lpds_irq_enable (mp_obj_t self_in) { wlan_obj_t *self = self_in; self->irq_enabled = true; } -STATIC void wlan_lpds_irq_disable (mp_obj_t self_in) { +static void wlan_lpds_irq_disable (mp_obj_t self_in) { wlan_obj_t *self = self_in; self->irq_enabled = false; } -STATIC int wlan_irq_flags (mp_obj_t self_in) { +static int wlan_irq_flags (mp_obj_t self_in) { wlan_obj_t *self = self_in; return self->irq_flags; } -STATIC bool wlan_scan_result_is_unique (const mp_obj_list_t *nets, _u8 *bssid) { +static bool wlan_scan_result_is_unique (const mp_obj_list_t *nets, _u8 *bssid) { for (int i = 0; i < nets->len; i++) { // index 1 in the list is the bssid mp_obj_str_t *_bssid = (mp_obj_str_t *)((mp_obj_tuple_t *)nets->items[i])->items[1]; @@ -766,7 +766,7 @@ STATIC bool wlan_scan_result_is_unique (const mp_obj_list_t *nets, _u8 *bssid) { /// \class WLAN - WiFi driver -STATIC mp_obj_t wlan_init_helper(wlan_obj_t *self, const mp_arg_val_t *args) { +static mp_obj_t wlan_init_helper(wlan_obj_t *self, const mp_arg_val_t *args) { // get the mode int8_t mode = args[0].u_int; wlan_validate_mode(mode); @@ -808,7 +808,7 @@ STATIC mp_obj_t wlan_init_helper(wlan_obj_t *self, const mp_arg_val_t *args) { return mp_const_none; } -STATIC const mp_arg_t wlan_init_args[] = { +static const mp_arg_t wlan_init_args[] = { { MP_QSTR_id, MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_mode, MP_ARG_INT, {.u_int = ROLE_STA} }, { MP_QSTR_ssid, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, @@ -818,7 +818,7 @@ STATIC const mp_arg_t wlan_init_args[] = { { MP_QSTR_antenna, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = ANTENNA_TYPE_INTERNAL} }, #endif }; -STATIC mp_obj_t wlan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t wlan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // parse args mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); @@ -844,16 +844,16 @@ STATIC mp_obj_t wlan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n return (mp_obj_t)self; } -STATIC mp_obj_t wlan_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t wlan_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // parse args mp_arg_val_t args[MP_ARRAY_SIZE(wlan_init_args) - 1]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &wlan_init_args[1], args); return wlan_init_helper(pos_args[0], args); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_init_obj, 1, wlan_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(wlan_init_obj, 1, wlan_init); -STATIC mp_obj_t wlan_scan(mp_obj_t self_in) { - STATIC const qstr wlan_scan_info_fields[] = { +static mp_obj_t wlan_scan(mp_obj_t self_in) { + static const qstr wlan_scan_info_fields[] = { MP_QSTR_ssid, MP_QSTR_bssid, MP_QSTR_sec, MP_QSTR_channel, MP_QSTR_rssi }; @@ -901,10 +901,10 @@ STATIC mp_obj_t wlan_scan(mp_obj_t self_in) { return nets; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_scan_obj, wlan_scan); +static MP_DEFINE_CONST_FUN_OBJ_1(wlan_scan_obj, wlan_scan); -STATIC mp_obj_t wlan_connect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - STATIC const mp_arg_t allowed_args[] = { +static mp_obj_t wlan_connect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + static const mp_arg_t allowed_args[] = { { MP_QSTR_ssid, MP_ARG_REQUIRED | MP_ARG_OBJ, }, { MP_QSTR_auth, MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_bssid, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, @@ -967,21 +967,21 @@ STATIC mp_obj_t wlan_connect(size_t n_args, const mp_obj_t *pos_args, mp_map_t * } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_connect_obj, 1, wlan_connect); +static MP_DEFINE_CONST_FUN_OBJ_KW(wlan_connect_obj, 1, wlan_connect); -STATIC mp_obj_t wlan_disconnect(mp_obj_t self_in) { +static mp_obj_t wlan_disconnect(mp_obj_t self_in) { wlan_sl_disconnect(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_disconnect_obj, wlan_disconnect); +static MP_DEFINE_CONST_FUN_OBJ_1(wlan_disconnect_obj, wlan_disconnect); -STATIC mp_obj_t wlan_isconnected(mp_obj_t self_in) { +static mp_obj_t wlan_isconnected(mp_obj_t self_in) { return wlan_is_connected() ? mp_const_true : mp_const_false; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_isconnected_obj, wlan_isconnected); +static MP_DEFINE_CONST_FUN_OBJ_1(wlan_isconnected_obj, wlan_isconnected); -STATIC mp_obj_t wlan_ifconfig(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - STATIC const mp_arg_t wlan_ifconfig_args[] = { +static mp_obj_t wlan_ifconfig(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + static const mp_arg_t wlan_ifconfig_args[] = { { MP_QSTR_id, MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_config, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, }; @@ -1055,9 +1055,9 @@ STATIC mp_obj_t wlan_ifconfig(size_t n_args, const mp_obj_t *pos_args, mp_map_t return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_ifconfig_obj, 1, wlan_ifconfig); +static MP_DEFINE_CONST_FUN_OBJ_KW(wlan_ifconfig_obj, 1, wlan_ifconfig); -STATIC mp_obj_t wlan_mode(size_t n_args, const mp_obj_t *args) { +static mp_obj_t wlan_mode(size_t n_args, const mp_obj_t *args) { wlan_obj_t *self = args[0]; if (n_args == 1) { return mp_obj_new_int(self->mode); @@ -1069,9 +1069,9 @@ STATIC mp_obj_t wlan_mode(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_mode_obj, 1, 2, wlan_mode); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_mode_obj, 1, 2, wlan_mode); -STATIC mp_obj_t wlan_ssid(size_t n_args, const mp_obj_t *args) { +static mp_obj_t wlan_ssid(size_t n_args, const mp_obj_t *args) { wlan_obj_t *self = args[0]; if (n_args == 1) { return mp_obj_new_str((const char *)self->ssid, strlen((const char *)self->ssid)); @@ -1084,9 +1084,9 @@ STATIC mp_obj_t wlan_ssid(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_ssid_obj, 1, 2, wlan_ssid); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_ssid_obj, 1, 2, wlan_ssid); -STATIC mp_obj_t wlan_auth(size_t n_args, const mp_obj_t *args) { +static mp_obj_t wlan_auth(size_t n_args, const mp_obj_t *args) { wlan_obj_t *self = args[0]; if (n_args == 1) { if (self->auth == SL_SEC_TYPE_OPEN) { @@ -1114,9 +1114,9 @@ STATIC mp_obj_t wlan_auth(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_auth_obj, 1, 2, wlan_auth); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_auth_obj, 1, 2, wlan_auth); -STATIC mp_obj_t wlan_channel(size_t n_args, const mp_obj_t *args) { +static mp_obj_t wlan_channel(size_t n_args, const mp_obj_t *args) { wlan_obj_t *self = args[0]; if (n_args == 1) { return mp_obj_new_int(self->channel); @@ -1128,9 +1128,9 @@ STATIC mp_obj_t wlan_channel(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_channel_obj, 1, 2, wlan_channel); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_channel_obj, 1, 2, wlan_channel); -STATIC mp_obj_t wlan_antenna(size_t n_args, const mp_obj_t *args) { +static mp_obj_t wlan_antenna(size_t n_args, const mp_obj_t *args) { wlan_obj_t *self = args[0]; if (n_args == 1) { return mp_obj_new_int(self->antenna); @@ -1143,9 +1143,9 @@ STATIC mp_obj_t wlan_antenna(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_antenna_obj, 1, 2, wlan_antenna); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_antenna_obj, 1, 2, wlan_antenna); -STATIC mp_obj_t wlan_mac(size_t n_args, const mp_obj_t *args) { +static mp_obj_t wlan_mac(size_t n_args, const mp_obj_t *args) { wlan_obj_t *self = args[0]; if (n_args == 1) { return mp_obj_new_bytes((const byte *)self->mac, SL_BSSID_LENGTH); @@ -1161,9 +1161,9 @@ STATIC mp_obj_t wlan_mac(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_mac_obj, 1, 2, wlan_mac); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_mac_obj, 1, 2, wlan_mac); -STATIC mp_obj_t wlan_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t wlan_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_arg_val_t args[mp_irq_INIT_NUM_ARGS]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mp_irq_INIT_NUM_ARGS, mp_irq_init_args, args); @@ -1191,7 +1191,7 @@ STATIC mp_obj_t wlan_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a invalid_args: mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value")); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_irq_obj, 1, wlan_irq); +static MP_DEFINE_CONST_FUN_OBJ_KW(wlan_irq_obj, 1, wlan_irq); //STATIC mp_obj_t wlan_connections (mp_obj_t self_in) { // mp_obj_t device[2]; @@ -1238,7 +1238,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_irq_obj, 1, wlan_irq); //} //STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_urn_obj, 1, 2, wlan_urn); -STATIC mp_obj_t wlan_print_ver(void) { +static mp_obj_t wlan_print_ver(void) { SlVersionFull ver; byte config_opt = SL_DEVICE_GENERAL_VERSION; byte config_len = sizeof(ver); @@ -1250,10 +1250,10 @@ STATIC mp_obj_t wlan_print_ver(void) { ver.ChipFwAndPhyVersion.PhyVersion[2], ver.ChipFwAndPhyVersion.PhyVersion[3]); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(wlan_print_ver_fun_obj, wlan_print_ver); -STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(wlan_print_ver_obj, MP_ROM_PTR(&wlan_print_ver_fun_obj)); +static MP_DEFINE_CONST_FUN_OBJ_0(wlan_print_ver_fun_obj, wlan_print_ver); +static MP_DEFINE_CONST_STATICMETHOD_OBJ(wlan_print_ver_obj, MP_ROM_PTR(&wlan_print_ver_fun_obj)); -STATIC const mp_rom_map_elem_t wlan_locals_dict_table[] = { +static const mp_rom_map_elem_t wlan_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&wlan_init_obj) }, { MP_ROM_QSTR(MP_QSTR_scan), MP_ROM_PTR(&wlan_scan_obj) }, { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&wlan_connect_obj) }, @@ -1283,7 +1283,7 @@ STATIC const mp_rom_map_elem_t wlan_locals_dict_table[] = { #endif { MP_ROM_QSTR(MP_QSTR_ANY_EVENT), MP_ROM_INT(MODWLAN_WIFI_EVENT_ANY) }, }; -STATIC MP_DEFINE_CONST_DICT(wlan_locals_dict, wlan_locals_dict_table); +static MP_DEFINE_CONST_DICT(wlan_locals_dict, wlan_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mod_network_nic_type_wlan, @@ -1293,7 +1293,7 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &wlan_locals_dict ); -STATIC const mp_irq_methods_t wlan_irq_methods = { +static const mp_irq_methods_t wlan_irq_methods = { .init = wlan_irq, .enable = wlan_lpds_irq_enable, .disable = wlan_lpds_irq_disable, diff --git a/ports/cc3200/mods/pybadc.c b/ports/cc3200/mods/pybadc.c index 6f9f1f19ae47d..cfa19a408e012 100644 --- a/ports/cc3200/mods/pybadc.c +++ b/ports/cc3200/mods/pybadc.c @@ -74,23 +74,23 @@ typedef struct { /****************************************************************************** DECLARE PRIVATE DATA ******************************************************************************/ -STATIC pyb_adc_channel_obj_t pyb_adc_channel_obj[PYB_ADC_NUM_CHANNELS] = { {.pin = &pin_GP2, .channel = ADC_CH_0, .id = 0, .enabled = false}, +static pyb_adc_channel_obj_t pyb_adc_channel_obj[PYB_ADC_NUM_CHANNELS] = { {.pin = &pin_GP2, .channel = ADC_CH_0, .id = 0, .enabled = false}, {.pin = &pin_GP3, .channel = ADC_CH_1, .id = 1, .enabled = false}, {.pin = &pin_GP4, .channel = ADC_CH_2, .id = 2, .enabled = false}, {.pin = &pin_GP5, .channel = ADC_CH_3, .id = 3, .enabled = false} }; -STATIC pyb_adc_obj_t pyb_adc_obj = {.enabled = false}; +static pyb_adc_obj_t pyb_adc_obj = {.enabled = false}; -STATIC const mp_obj_type_t pyb_adc_channel_type; +static const mp_obj_type_t pyb_adc_channel_type; /****************************************************************************** DECLARE PRIVATE FUNCTIONS ******************************************************************************/ -STATIC mp_obj_t adc_channel_deinit(mp_obj_t self_in); +static mp_obj_t adc_channel_deinit(mp_obj_t self_in); /****************************************************************************** DEFINE PUBLIC FUNCTIONS ******************************************************************************/ -STATIC void pyb_adc_init (pyb_adc_obj_t *self) { +static void pyb_adc_init (pyb_adc_obj_t *self) { // enable and configure the timer MAP_ADCTimerConfig(ADC_BASE, (1 << 17) - 1); MAP_ADCTimerEnable(ADC_BASE); @@ -99,14 +99,14 @@ STATIC void pyb_adc_init (pyb_adc_obj_t *self) { self->enabled = true; } -STATIC void pyb_adc_check_init(void) { +static void pyb_adc_check_init(void) { // not initialized if (!pyb_adc_obj.enabled) { mp_raise_OSError(MP_EPERM); } } -STATIC void pyb_adc_channel_init (pyb_adc_channel_obj_t *self) { +static void pyb_adc_channel_init (pyb_adc_channel_obj_t *self) { // the ADC block must be enabled first pyb_adc_check_init(); // configure the pin in analog mode @@ -116,7 +116,7 @@ STATIC void pyb_adc_channel_init (pyb_adc_channel_obj_t *self) { self->enabled = true; } -STATIC void pyb_adc_deinit_all_channels (void) { +static void pyb_adc_deinit_all_channels (void) { for (int i = 0; i < PYB_ADC_NUM_CHANNELS; i++) { adc_channel_deinit(&pyb_adc_channel_obj[i]); } @@ -125,7 +125,7 @@ STATIC void pyb_adc_deinit_all_channels (void) { /******************************************************************************/ /* MicroPython bindings : adc object */ -STATIC void adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_adc_obj_t *self = self_in; if (self->enabled) { mp_printf(print, "ADC(0, bits=12)"); @@ -134,11 +134,11 @@ STATIC void adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t } } -STATIC const mp_arg_t pyb_adc_init_args[] = { +static const mp_arg_t pyb_adc_init_args[] = { { MP_QSTR_id, MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_bits, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 12} }, }; -STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // parse args mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); @@ -165,7 +165,7 @@ STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ return self; } -STATIC mp_obj_t adc_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t adc_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // parse args mp_arg_val_t args[MP_ARRAY_SIZE(pyb_adc_init_args) - 1]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &pyb_adc_init_args[1], args); @@ -176,9 +176,9 @@ STATIC mp_obj_t adc_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a pyb_adc_init(pos_args[0]); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(adc_init_obj, 1, adc_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(adc_init_obj, 1, adc_init); -STATIC mp_obj_t adc_deinit(mp_obj_t self_in) { +static mp_obj_t adc_deinit(mp_obj_t self_in) { pyb_adc_obj_t *self = self_in; // first deinit all channels pyb_adc_deinit_all_channels(); @@ -188,10 +188,10 @@ STATIC mp_obj_t adc_deinit(mp_obj_t self_in) { pyb_sleep_remove ((const mp_obj_t)self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_deinit_obj, adc_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(adc_deinit_obj, adc_deinit); -STATIC mp_obj_t adc_channel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - STATIC const mp_arg_t pyb_adc_channel_args[] = { +static mp_obj_t adc_channel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + static const mp_arg_t pyb_adc_channel_args[] = { { MP_QSTR_id, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_pin, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, }; @@ -223,15 +223,15 @@ STATIC mp_obj_t adc_channel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k pyb_sleep_add ((const mp_obj_t)self, (WakeUpCB_t)pyb_adc_channel_init); return self; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(adc_channel_obj, 1, adc_channel); +static MP_DEFINE_CONST_FUN_OBJ_KW(adc_channel_obj, 1, adc_channel); -STATIC const mp_rom_map_elem_t adc_locals_dict_table[] = { +static const mp_rom_map_elem_t adc_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&adc_init_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&adc_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR_channel), MP_ROM_PTR(&adc_channel_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(adc_locals_dict, adc_locals_dict_table); +static MP_DEFINE_CONST_DICT(adc_locals_dict, adc_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pyb_adc_type, @@ -242,7 +242,7 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &adc_locals_dict ); -STATIC void adc_channel_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void adc_channel_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_adc_channel_obj_t *self = self_in; if (self->enabled) { mp_printf(print, "ADCChannel(%u, pin=%q)", self->id, self->pin->name); @@ -251,15 +251,15 @@ STATIC void adc_channel_print(const mp_print_t *print, mp_obj_t self_in, mp_prin } } -STATIC mp_obj_t adc_channel_init(mp_obj_t self_in) { +static mp_obj_t adc_channel_init(mp_obj_t self_in) { pyb_adc_channel_obj_t *self = self_in; // re-enable it pyb_adc_channel_init(self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_channel_init_obj, adc_channel_init); +static MP_DEFINE_CONST_FUN_OBJ_1(adc_channel_init_obj, adc_channel_init); -STATIC mp_obj_t adc_channel_deinit(mp_obj_t self_in) { +static mp_obj_t adc_channel_deinit(mp_obj_t self_in) { pyb_adc_channel_obj_t *self = self_in; MAP_ADCChannelDisable(ADC_BASE, self->channel); @@ -268,9 +268,9 @@ STATIC mp_obj_t adc_channel_deinit(mp_obj_t self_in) { self->enabled = false; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_channel_deinit_obj, adc_channel_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(adc_channel_deinit_obj, adc_channel_deinit); -STATIC mp_obj_t adc_channel_value(mp_obj_t self_in) { +static mp_obj_t adc_channel_value(mp_obj_t self_in) { pyb_adc_channel_obj_t *self = self_in; uint32_t value; @@ -286,22 +286,22 @@ STATIC mp_obj_t adc_channel_value(mp_obj_t self_in) { // the 12 bit sampled value is stored in bits [13:2] return MP_OBJ_NEW_SMALL_INT((value & 0x3FFF) >> 2); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_channel_value_obj, adc_channel_value); +static MP_DEFINE_CONST_FUN_OBJ_1(adc_channel_value_obj, adc_channel_value); -STATIC mp_obj_t adc_channel_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t adc_channel_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 0, false); return adc_channel_value (self_in); } -STATIC const mp_rom_map_elem_t adc_channel_locals_dict_table[] = { +static const mp_rom_map_elem_t adc_channel_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&adc_channel_init_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&adc_channel_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&adc_channel_value_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(adc_channel_locals_dict, adc_channel_locals_dict_table); +static MP_DEFINE_CONST_DICT(adc_channel_locals_dict, adc_channel_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( pyb_adc_channel_type, MP_QSTR_ADCChannel, MP_TYPE_FLAG_NONE, diff --git a/ports/cc3200/mods/pybflash.c b/ports/cc3200/mods/pybflash.c index 46b7be234f9cb..671b5137e275c 100644 --- a/ports/cc3200/mods/pybflash.c +++ b/ports/cc3200/mods/pybflash.c @@ -37,9 +37,9 @@ // block protocol. // there is a singleton Flash object -STATIC const mp_obj_base_t pyb_flash_obj = {&pyb_flash_type}; +static const mp_obj_base_t pyb_flash_obj = {&pyb_flash_type}; -STATIC mp_obj_t pyb_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pyb_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 0, 0, false); @@ -47,23 +47,23 @@ STATIC mp_obj_t pyb_flash_make_new(const mp_obj_type_t *type, size_t n_args, siz return (mp_obj_t)&pyb_flash_obj; } -STATIC mp_obj_t pyb_flash_readblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) { +static mp_obj_t pyb_flash_readblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_WRITE); DRESULT res = sflash_disk_read(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SFLASH_SECTOR_SIZE); return MP_OBJ_NEW_SMALL_INT(res != RES_OK); // return of 0 means success } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_readblocks_obj, pyb_flash_readblocks); +static MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_readblocks_obj, pyb_flash_readblocks); -STATIC mp_obj_t pyb_flash_writeblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) { +static mp_obj_t pyb_flash_writeblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ); DRESULT res = sflash_disk_write(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SFLASH_SECTOR_SIZE); return MP_OBJ_NEW_SMALL_INT(res != RES_OK); // return of 0 means success } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_writeblocks_obj, pyb_flash_writeblocks); +static MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_writeblocks_obj, pyb_flash_writeblocks); -STATIC mp_obj_t pyb_flash_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) { +static mp_obj_t pyb_flash_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) { mp_int_t cmd = mp_obj_get_int(cmd_in); switch (cmd) { case MP_BLOCKDEV_IOCTL_INIT: return MP_OBJ_NEW_SMALL_INT(sflash_disk_init() != RES_OK); @@ -74,15 +74,15 @@ STATIC mp_obj_t pyb_flash_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) default: return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_ioctl_obj, pyb_flash_ioctl); +static MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_ioctl_obj, pyb_flash_ioctl); -STATIC const mp_rom_map_elem_t pyb_flash_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_flash_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&pyb_flash_readblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&pyb_flash_writeblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&pyb_flash_ioctl_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_flash_locals_dict, pyb_flash_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_flash_locals_dict, pyb_flash_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pyb_flash_type, diff --git a/ports/cc3200/mods/pybi2c.c b/ports/cc3200/mods/pybi2c.c index a413eddeb2e3c..0a9e778081c3f 100644 --- a/ports/cc3200/mods/pybi2c.c +++ b/ports/cc3200/mods/pybi2c.c @@ -74,18 +74,18 @@ typedef struct _pyb_i2c_obj_t { /****************************************************************************** DECLARE PRIVATE DATA ******************************************************************************/ -STATIC pyb_i2c_obj_t pyb_i2c_obj = {.baudrate = 0}; +static pyb_i2c_obj_t pyb_i2c_obj = {.baudrate = 0}; /****************************************************************************** DECLARE PRIVATE FUNCTIONS ******************************************************************************/ -STATIC bool pyb_i2c_write(byte addr, byte *data, uint len, bool stop); +static bool pyb_i2c_write(byte addr, byte *data, uint len, bool stop); /****************************************************************************** DEFINE PRIVATE FUNCTIONS ******************************************************************************/ // only master mode is available for the moment -STATIC void i2c_init (pyb_i2c_obj_t *self) { +static void i2c_init (pyb_i2c_obj_t *self) { // Enable the I2C Peripheral MAP_PRCMPeripheralClkEnable(PRCM_I2CA0, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK); MAP_PRCMPeripheralReset(PRCM_I2CA0); @@ -93,7 +93,7 @@ STATIC void i2c_init (pyb_i2c_obj_t *self) { MAP_I2CMasterInitExpClk(I2CA0_BASE, self->baudrate); } -STATIC bool pyb_i2c_transaction(uint cmd) { +static bool pyb_i2c_transaction(uint cmd) { // Convert the timeout to microseconds int32_t timeout = PYBI2C_TRANSC_TIMEOUT_MS * 1000; // Sanity check, t_timeout must be between 1 and 255 @@ -137,14 +137,14 @@ STATIC bool pyb_i2c_transaction(uint cmd) { return true; } -STATIC void pyb_i2c_check_init(pyb_i2c_obj_t *self) { +static void pyb_i2c_check_init(pyb_i2c_obj_t *self) { // not initialized if (!self->baudrate) { mp_raise_OSError(MP_EPERM); } } -STATIC bool pyb_i2c_scan_device(byte devAddr) { +static bool pyb_i2c_scan_device(byte devAddr) { bool ret = false; // Set the I2C slave address MAP_I2CMasterSlaveAddrSet(I2CA0_BASE, devAddr, true); @@ -163,7 +163,7 @@ STATIC bool pyb_i2c_scan_device(byte devAddr) { return ret; } -STATIC bool pyb_i2c_mem_addr_write (byte addr, byte *mem_addr, uint mem_addr_len) { +static bool pyb_i2c_mem_addr_write (byte addr, byte *mem_addr, uint mem_addr_len) { // Set I2C codec slave address MAP_I2CMasterSlaveAddrSet(I2CA0_BASE, addr, false); // Write the first byte to the controller. @@ -181,7 +181,7 @@ STATIC bool pyb_i2c_mem_addr_write (byte addr, byte *mem_addr, uint mem_addr_len return true; } -STATIC bool pyb_i2c_mem_write (byte addr, byte *mem_addr, uint mem_addr_len, byte *data, uint data_len) { +static bool pyb_i2c_mem_write (byte addr, byte *mem_addr, uint mem_addr_len, byte *data, uint data_len) { if (pyb_i2c_mem_addr_write (addr, mem_addr, mem_addr_len)) { // Loop until the completion of transfer or error while (data_len--) { @@ -197,7 +197,7 @@ STATIC bool pyb_i2c_mem_write (byte addr, byte *mem_addr, uint mem_addr_len, byt return false; } -STATIC bool pyb_i2c_write(byte addr, byte *data, uint len, bool stop) { +static bool pyb_i2c_write(byte addr, byte *data, uint len, bool stop) { // Set I2C codec slave address MAP_I2CMasterSlaveAddrSet(I2CA0_BASE, addr, false); // Write the first byte to the controller. @@ -220,7 +220,7 @@ STATIC bool pyb_i2c_write(byte addr, byte *data, uint len, bool stop) { return true; } -STATIC bool pyb_i2c_read(byte addr, byte *data, uint len) { +static bool pyb_i2c_read(byte addr, byte *data, uint len) { // Initiate a burst or single receive sequence uint cmd = --len > 0 ? I2C_MASTER_CMD_BURST_RECEIVE_START : I2C_MASTER_CMD_SINGLE_RECEIVE; // Set I2C codec slave address @@ -245,7 +245,7 @@ STATIC bool pyb_i2c_read(byte addr, byte *data, uint len) { return true; } -STATIC void pyb_i2c_read_into (mp_arg_val_t *args, vstr_t *vstr) { +static void pyb_i2c_read_into (mp_arg_val_t *args, vstr_t *vstr) { pyb_i2c_check_init(&pyb_i2c_obj); // get the buffer to receive into pyb_buf_get_for_recv(args[1].u_obj, vstr); @@ -256,7 +256,7 @@ STATIC void pyb_i2c_read_into (mp_arg_val_t *args, vstr_t *vstr) { } } -STATIC void pyb_i2c_readmem_into (mp_arg_val_t *args, vstr_t *vstr) { +static void pyb_i2c_readmem_into (mp_arg_val_t *args, vstr_t *vstr) { pyb_i2c_check_init(&pyb_i2c_obj); // get the buffer to receive into pyb_buf_get_for_recv(args[2].u_obj, vstr); @@ -281,7 +281,7 @@ STATIC void pyb_i2c_readmem_into (mp_arg_val_t *args, vstr_t *vstr) { /******************************************************************************/ /* MicroPython bindings */ /******************************************************************************/ -STATIC void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_i2c_obj_t *self = self_in; if (self->baudrate > 0) { mp_printf(print, "I2C(0, baudrate=%u)", self->baudrate); @@ -290,7 +290,7 @@ STATIC void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki } } -STATIC mp_obj_t pyb_i2c_init_helper(pyb_i2c_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_i2c_init_helper(pyb_i2c_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_scl, ARG_sda, ARG_freq }; static const mp_arg_t allowed_args[] = { { MP_QSTR_scl, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, @@ -322,7 +322,7 @@ STATIC mp_obj_t pyb_i2c_init_helper(pyb_i2c_obj_t *self, size_t n_args, const mp return mp_const_none; } -STATIC mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // check the id argument, if given if (n_args > 0) { if (all_args[0] != MP_OBJ_NEW_SMALL_INT(0)) { @@ -346,12 +346,12 @@ STATIC mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_ return (mp_obj_t)self; } -STATIC mp_obj_t pyb_i2c_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_i2c_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { return pyb_i2c_init_helper(pos_args[0], n_args - 1, pos_args + 1, kw_args); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_init_obj, 1, pyb_i2c_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_init_obj, 1, pyb_i2c_init); -STATIC mp_obj_t pyb_i2c_deinit(mp_obj_t self_in) { +static mp_obj_t pyb_i2c_deinit(mp_obj_t self_in) { // disable the peripheral MAP_I2CMasterDisable(I2CA0_BASE); MAP_PRCMPeripheralClkDisable(PRCM_I2CA0, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK); @@ -361,9 +361,9 @@ STATIC mp_obj_t pyb_i2c_deinit(mp_obj_t self_in) { pyb_sleep_remove ((const mp_obj_t)self_in); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_deinit_obj, pyb_i2c_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_deinit_obj, pyb_i2c_deinit); -STATIC mp_obj_t pyb_i2c_scan(mp_obj_t self_in) { +static mp_obj_t pyb_i2c_scan(mp_obj_t self_in) { pyb_i2c_check_init(&pyb_i2c_obj); mp_obj_t list = mp_obj_new_list(0, NULL); for (uint addr = 0x08; addr <= 0x77; addr++) { @@ -376,10 +376,10 @@ STATIC mp_obj_t pyb_i2c_scan(mp_obj_t self_in) { } return list; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_scan_obj, pyb_i2c_scan); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_scan_obj, pyb_i2c_scan); -STATIC mp_obj_t pyb_i2c_readfrom(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - STATIC const mp_arg_t pyb_i2c_readfrom_args[] = { +static mp_obj_t pyb_i2c_readfrom(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + static const mp_arg_t pyb_i2c_readfrom_args[] = { { MP_QSTR_addr, MP_ARG_REQUIRED | MP_ARG_INT, }, { MP_QSTR_nbytes, MP_ARG_REQUIRED | MP_ARG_OBJ, }, }; @@ -394,10 +394,10 @@ STATIC mp_obj_t pyb_i2c_readfrom(size_t n_args, const mp_obj_t *pos_args, mp_map // return the received data return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_obj, 3, pyb_i2c_readfrom); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_obj, 3, pyb_i2c_readfrom); -STATIC mp_obj_t pyb_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - STATIC const mp_arg_t pyb_i2c_readfrom_into_args[] = { +static mp_obj_t pyb_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + static const mp_arg_t pyb_i2c_readfrom_into_args[] = { { MP_QSTR_addr, MP_ARG_REQUIRED | MP_ARG_INT, }, { MP_QSTR_buf, MP_ARG_REQUIRED | MP_ARG_OBJ, }, }; @@ -412,10 +412,10 @@ STATIC mp_obj_t pyb_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_args, m // return the number of bytes received return mp_obj_new_int(vstr.len); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_into_obj, 1, pyb_i2c_readfrom_into); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_into_obj, 1, pyb_i2c_readfrom_into); -STATIC mp_obj_t pyb_i2c_writeto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - STATIC const mp_arg_t pyb_i2c_writeto_args[] = { +static mp_obj_t pyb_i2c_writeto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + static const mp_arg_t pyb_i2c_writeto_args[] = { { MP_QSTR_addr, MP_ARG_REQUIRED | MP_ARG_INT, }, { MP_QSTR_buf, MP_ARG_REQUIRED | MP_ARG_OBJ, }, { MP_QSTR_stop, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} }, @@ -440,10 +440,10 @@ STATIC mp_obj_t pyb_i2c_writeto(size_t n_args, const mp_obj_t *pos_args, mp_map_ // return the number of bytes written return mp_obj_new_int(bufinfo.len); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_writeto_obj, 1, pyb_i2c_writeto); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_writeto_obj, 1, pyb_i2c_writeto); -STATIC mp_obj_t pyb_i2c_readfrom_mem(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - STATIC const mp_arg_t pyb_i2c_readfrom_mem_args[] = { +static mp_obj_t pyb_i2c_readfrom_mem(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + static const mp_arg_t pyb_i2c_readfrom_mem_args[] = { { MP_QSTR_addr, MP_ARG_REQUIRED | MP_ARG_INT, }, { MP_QSTR_memaddr, MP_ARG_REQUIRED | MP_ARG_INT, }, { MP_QSTR_nbytes, MP_ARG_REQUIRED | MP_ARG_OBJ, }, @@ -458,16 +458,16 @@ STATIC mp_obj_t pyb_i2c_readfrom_mem(size_t n_args, const mp_obj_t *pos_args, mp pyb_i2c_readmem_into (args, &vstr); return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_mem_obj, 1, pyb_i2c_readfrom_mem); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_mem_obj, 1, pyb_i2c_readfrom_mem); -STATIC const mp_arg_t pyb_i2c_readfrom_mem_into_args[] = { +static const mp_arg_t pyb_i2c_readfrom_mem_into_args[] = { { MP_QSTR_addr, MP_ARG_REQUIRED | MP_ARG_INT, }, { MP_QSTR_memaddr, MP_ARG_REQUIRED | MP_ARG_INT, }, { MP_QSTR_buf, MP_ARG_REQUIRED | MP_ARG_OBJ, }, { MP_QSTR_addrsize, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 8} }, }; -STATIC mp_obj_t pyb_i2c_readfrom_mem_into(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_i2c_readfrom_mem_into(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // parse args mp_arg_val_t args[MP_ARRAY_SIZE(pyb_i2c_readfrom_mem_into_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), pyb_i2c_readfrom_mem_into_args, args); @@ -477,9 +477,9 @@ STATIC mp_obj_t pyb_i2c_readfrom_mem_into(size_t n_args, const mp_obj_t *pos_arg pyb_i2c_readmem_into (args, &vstr); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_mem_into_obj, 1, pyb_i2c_readfrom_mem_into); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_readfrom_mem_into_obj, 1, pyb_i2c_readfrom_mem_into); -STATIC mp_obj_t pyb_i2c_writeto_mem(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_i2c_writeto_mem(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // parse args mp_arg_val_t args[MP_ARRAY_SIZE(pyb_i2c_readfrom_mem_into_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(pyb_i2c_readfrom_mem_into_args), pyb_i2c_readfrom_mem_into_args, args); @@ -504,9 +504,9 @@ STATIC mp_obj_t pyb_i2c_writeto_mem(size_t n_args, const mp_obj_t *pos_args, mp_ mp_raise_OSError(MP_EIO); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_writeto_mem_obj, 1, pyb_i2c_writeto_mem); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_writeto_mem_obj, 1, pyb_i2c_writeto_mem); -STATIC const mp_rom_map_elem_t pyb_i2c_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_i2c_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_i2c_init_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_i2c_deinit_obj) }, @@ -519,7 +519,7 @@ STATIC const mp_rom_map_elem_t pyb_i2c_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_writeto_mem), MP_ROM_PTR(&pyb_i2c_writeto_mem_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_i2c_locals_dict, pyb_i2c_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_i2c_locals_dict, pyb_i2c_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pyb_i2c_type, diff --git a/ports/cc3200/mods/pybpin.c b/ports/cc3200/mods/pybpin.c index 6d10abab570f1..037c78a32cbf2 100644 --- a/ports/cc3200/mods/pybpin.c +++ b/ports/cc3200/mods/pybpin.c @@ -53,26 +53,26 @@ /****************************************************************************** DECLARE PRIVATE FUNCTIONS ******************************************************************************/ -STATIC pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name); -STATIC pin_obj_t *pin_find_pin_by_port_bit (const mp_obj_dict_t *named_pins, uint port, uint bit); -STATIC int8_t pin_obj_find_af (const pin_obj_t* pin, uint8_t fn, uint8_t unit, uint8_t type); -STATIC void pin_free_af_from_pins (uint8_t fn, uint8_t unit, uint8_t type); -STATIC void pin_deassign (pin_obj_t* pin); -STATIC void pin_obj_configure (const pin_obj_t *self); -STATIC void pin_get_hibernate_pin_and_idx (const pin_obj_t *self, uint *wake_pin, uint *idx); -STATIC void pin_irq_enable (mp_obj_t self_in); -STATIC void pin_irq_disable (mp_obj_t self_in); -STATIC void pin_extint_register(pin_obj_t *self, uint32_t intmode, uint32_t priority); -STATIC void pin_validate_mode (uint mode); -STATIC void pin_validate_pull (uint pull); -STATIC void pin_validate_drive (uint strength); -STATIC void pin_validate_af(const pin_obj_t* pin, int8_t idx, uint8_t *fn, uint8_t *unit, uint8_t *type); -STATIC uint8_t pin_get_value(const pin_obj_t* self); -STATIC void GPIOA0IntHandler (void); -STATIC void GPIOA1IntHandler (void); -STATIC void GPIOA2IntHandler (void); -STATIC void GPIOA3IntHandler (void); -STATIC void EXTI_Handler(uint port); +static pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name); +static pin_obj_t *pin_find_pin_by_port_bit (const mp_obj_dict_t *named_pins, uint port, uint bit); +static int8_t pin_obj_find_af (const pin_obj_t* pin, uint8_t fn, uint8_t unit, uint8_t type); +static void pin_free_af_from_pins (uint8_t fn, uint8_t unit, uint8_t type); +static void pin_deassign (pin_obj_t* pin); +static void pin_obj_configure (const pin_obj_t *self); +static void pin_get_hibernate_pin_and_idx (const pin_obj_t *self, uint *wake_pin, uint *idx); +static void pin_irq_enable (mp_obj_t self_in); +static void pin_irq_disable (mp_obj_t self_in); +static void pin_extint_register(pin_obj_t *self, uint32_t intmode, uint32_t priority); +static void pin_validate_mode (uint mode); +static void pin_validate_pull (uint pull); +static void pin_validate_drive (uint strength); +static void pin_validate_af(const pin_obj_t* pin, int8_t idx, uint8_t *fn, uint8_t *unit, uint8_t *type); +static uint8_t pin_get_value(const pin_obj_t* self); +static void GPIOA0IntHandler (void); +static void GPIOA1IntHandler (void); +static void GPIOA2IntHandler (void); +static void GPIOA3IntHandler (void); +static void EXTI_Handler(uint port); /****************************************************************************** DEFINE CONSTANTS @@ -100,8 +100,8 @@ typedef struct { /****************************************************************************** DECLARE PRIVATE DATA ******************************************************************************/ -STATIC const mp_irq_methods_t pin_irq_methods; -STATIC pybpin_wake_pin_t pybpin_wake_pin[PYBPIN_NUM_WAKE_PINS] = +static const mp_irq_methods_t pin_irq_methods; +static pybpin_wake_pin_t pybpin_wake_pin[PYBPIN_NUM_WAKE_PINS] = { {.active = false, .lpds = PYBPIN_WAKES_NOT, .hib = PYBPIN_WAKES_NOT}, {.active = false, .lpds = PYBPIN_WAKES_NOT, .hib = PYBPIN_WAKES_NOT}, {.active = false, .lpds = PYBPIN_WAKES_NOT, .hib = PYBPIN_WAKES_NOT}, @@ -205,7 +205,7 @@ int8_t pin_find_af_index (const pin_obj_t* pin, uint8_t fn, uint8_t unit, uint8_ /****************************************************************************** DEFINE PRIVATE FUNCTIONS ******************************************************************************/ -STATIC pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name) { +static pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name) { const mp_map_t *named_map = &named_pins->map; mp_map_elem_t *named_elem = mp_map_lookup((mp_map_t*)named_map, name, MP_MAP_LOOKUP); if (named_elem != NULL && named_elem->value != NULL) { @@ -214,7 +214,7 @@ STATIC pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t n return NULL; } -STATIC pin_obj_t *pin_find_pin_by_port_bit (const mp_obj_dict_t *named_pins, uint port, uint bit) { +static pin_obj_t *pin_find_pin_by_port_bit (const mp_obj_dict_t *named_pins, uint port, uint bit) { const mp_map_t *named_map = &named_pins->map; for (uint i = 0; i < named_map->used; i++) { if ((((pin_obj_t *)named_map->table[i].value)->port == port) && @@ -225,7 +225,7 @@ STATIC pin_obj_t *pin_find_pin_by_port_bit (const mp_obj_dict_t *named_pins, uin return NULL; } -STATIC int8_t pin_obj_find_af (const pin_obj_t* pin, uint8_t fn, uint8_t unit, uint8_t type) { +static int8_t pin_obj_find_af (const pin_obj_t* pin, uint8_t fn, uint8_t unit, uint8_t type) { for (int i = 0; i < pin->num_afs; i++) { if (pin->af_list[i].fn == fn && pin->af_list[i].unit == unit && pin->af_list[i].type == type) { return pin->af_list[i].idx; @@ -234,7 +234,7 @@ STATIC int8_t pin_obj_find_af (const pin_obj_t* pin, uint8_t fn, uint8_t unit, u return -1; } -STATIC void pin_free_af_from_pins (uint8_t fn, uint8_t unit, uint8_t type) { +static void pin_free_af_from_pins (uint8_t fn, uint8_t unit, uint8_t type) { const mp_map_t *named_map = &pin_board_pins_locals_dict.map; for (uint i = 0; i < named_map->used - 1; i++) { pin_obj_t * pin = (pin_obj_t *)named_map->table[i].value; @@ -250,12 +250,12 @@ STATIC void pin_free_af_from_pins (uint8_t fn, uint8_t unit, uint8_t type) { } } -STATIC void pin_deassign (pin_obj_t* pin) { +static void pin_deassign (pin_obj_t* pin) { pin_config (pin, PIN_MODE_0, GPIO_DIR_MODE_IN, PIN_TYPE_STD, -1, PIN_STRENGTH_4MA); pin->used = false; } -STATIC void pin_obj_configure (const pin_obj_t *self) { +static void pin_obj_configure (const pin_obj_t *self) { uint32_t type; if (self->mode == PIN_TYPE_ANALOG) { type = PIN_TYPE_ANALOG; @@ -299,7 +299,7 @@ STATIC void pin_obj_configure (const pin_obj_t *self) { MAP_PinConfigSet(self->pin_num, self->strength, type); } -STATIC void pin_get_hibernate_pin_and_idx (const pin_obj_t *self, uint *hib_pin, uint *idx) { +static void pin_get_hibernate_pin_and_idx (const pin_obj_t *self, uint *hib_pin, uint *idx) { // pin_num is actually : (package_pin - 1) switch (self->pin_num) { case 56: // GP2 @@ -332,7 +332,7 @@ STATIC void pin_get_hibernate_pin_and_idx (const pin_obj_t *self, uint *hib_pin, } } -STATIC void pin_irq_enable (mp_obj_t self_in) { +static void pin_irq_enable (mp_obj_t self_in) { const pin_obj_t *self = self_in; uint hib_pin, idx; @@ -364,7 +364,7 @@ STATIC void pin_irq_enable (mp_obj_t self_in) { } } -STATIC void pin_irq_disable (mp_obj_t self_in) { +static void pin_irq_disable (mp_obj_t self_in) { const pin_obj_t *self = self_in; uint hib_pin, idx; @@ -383,12 +383,12 @@ STATIC void pin_irq_disable (mp_obj_t self_in) { MAP_GPIOIntDisable(self->port, self->bit); } -STATIC int pin_irq_flags (mp_obj_t self_in) { +static int pin_irq_flags (mp_obj_t self_in) { const pin_obj_t *self = self_in; return self->irq_flags; } -STATIC void pin_extint_register(pin_obj_t *self, uint32_t intmode, uint32_t priority) { +static void pin_extint_register(pin_obj_t *self, uint32_t intmode, uint32_t priority) { void *handler; uint32_t intnum; @@ -419,25 +419,25 @@ STATIC void pin_extint_register(pin_obj_t *self, uint32_t intmode, uint32_t prio MAP_IntPrioritySet(intnum, priority); } -STATIC void pin_validate_mode (uint mode) { +static void pin_validate_mode (uint mode) { if (mode != GPIO_DIR_MODE_IN && mode != GPIO_DIR_MODE_OUT && mode != PIN_TYPE_OD && mode != GPIO_DIR_MODE_ALT && mode != GPIO_DIR_MODE_ALT_OD) { mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value")); } } -STATIC void pin_validate_pull (uint pull) { +static void pin_validate_pull (uint pull) { if (pull != PIN_TYPE_STD && pull != PIN_TYPE_STD_PU && pull != PIN_TYPE_STD_PD) { mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value")); } } -STATIC void pin_validate_drive(uint strength) { +static void pin_validate_drive(uint strength) { if (strength != PIN_STRENGTH_2MA && strength != PIN_STRENGTH_4MA && strength != PIN_STRENGTH_6MA) { mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value")); } } -STATIC void pin_validate_af(const pin_obj_t* pin, int8_t idx, uint8_t *fn, uint8_t *unit, uint8_t *type) { +static void pin_validate_af(const pin_obj_t* pin, int8_t idx, uint8_t *fn, uint8_t *unit, uint8_t *type) { for (int i = 0; i < pin->num_afs; i++) { if (pin->af_list[i].idx == idx) { *fn = pin->af_list[i].fn; @@ -449,7 +449,7 @@ STATIC void pin_validate_af(const pin_obj_t* pin, int8_t idx, uint8_t *fn, uint8 mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value")); } -STATIC uint8_t pin_get_value (const pin_obj_t* self) { +static uint8_t pin_get_value (const pin_obj_t* self) { uint32_t value; bool setdir = false; if (self->mode == PIN_TYPE_OD || self->mode == GPIO_DIR_MODE_ALT_OD) { @@ -472,24 +472,24 @@ STATIC uint8_t pin_get_value (const pin_obj_t* self) { return value ? 1 : 0; } -STATIC void GPIOA0IntHandler (void) { +static void GPIOA0IntHandler (void) { EXTI_Handler(GPIOA0_BASE); } -STATIC void GPIOA1IntHandler (void) { +static void GPIOA1IntHandler (void) { EXTI_Handler(GPIOA1_BASE); } -STATIC void GPIOA2IntHandler (void) { +static void GPIOA2IntHandler (void) { EXTI_Handler(GPIOA2_BASE); } -STATIC void GPIOA3IntHandler (void) { +static void GPIOA3IntHandler (void) { EXTI_Handler(GPIOA3_BASE); } // common interrupt handler -STATIC void EXTI_Handler(uint port) { +static void EXTI_Handler(uint port) { uint32_t bits = MAP_GPIOIntStatus(port, true); MAP_GPIOIntClear(port, bits); @@ -517,7 +517,7 @@ STATIC void EXTI_Handler(uint port) { /******************************************************************************/ // MicroPython bindings -STATIC const mp_arg_t pin_init_args[] = { +static const mp_arg_t pin_init_args[] = { { MP_QSTR_mode, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_pull, MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_value, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, @@ -526,7 +526,7 @@ STATIC const mp_arg_t pin_init_args[] = { }; #define pin_INIT_NUM_ARGS MP_ARRAY_SIZE(pin_init_args) -STATIC mp_obj_t pin_obj_init_helper(pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pin_obj_init_helper(pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // parse args mp_arg_val_t args[pin_INIT_NUM_ARGS]; mp_arg_parse_all(n_args, pos_args, kw_args, pin_INIT_NUM_ARGS, pin_init_args, args); @@ -590,7 +590,7 @@ STATIC mp_obj_t pin_obj_init_helper(pin_obj_t *self, size_t n_args, const mp_obj mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value")); } -STATIC void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pin_obj_t *self = self_in; uint32_t pull = self->pull; uint32_t drive = self->strength; @@ -643,7 +643,7 @@ STATIC void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t mp_printf(print, ", alt=%d)", alt); } -STATIC mp_obj_t pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); // Run an argument through the mapper and return the result. @@ -656,12 +656,12 @@ STATIC mp_obj_t pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ return (mp_obj_t)pin; } -STATIC mp_obj_t pin_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t pin_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { return pin_obj_init_helper(args[0], n_args - 1, args + 1, kw_args); } MP_DEFINE_CONST_FUN_OBJ_KW(pin_init_obj, 1, pin_obj_init); -STATIC mp_obj_t pin_value(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pin_value(size_t n_args, const mp_obj_t *args) { pin_obj_t *self = args[0]; if (n_args == 1) { // get the value @@ -678,15 +678,15 @@ STATIC mp_obj_t pin_value(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_value_obj, 1, 2, pin_value); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_value_obj, 1, 2, pin_value); -STATIC mp_obj_t pin_id(mp_obj_t self_in) { +static mp_obj_t pin_id(mp_obj_t self_in) { pin_obj_t *self = self_in; return MP_OBJ_NEW_QSTR(self->name); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_id_obj, pin_id); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_id_obj, pin_id); -STATIC mp_obj_t pin_mode(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pin_mode(size_t n_args, const mp_obj_t *args) { pin_obj_t *self = args[0]; if (n_args == 1) { return mp_obj_new_int(self->mode); @@ -698,9 +698,9 @@ STATIC mp_obj_t pin_mode(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_mode_obj, 1, 2, pin_mode); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_mode_obj, 1, 2, pin_mode); -STATIC mp_obj_t pin_pull(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pin_pull(size_t n_args, const mp_obj_t *args) { pin_obj_t *self = args[0]; if (n_args == 1) { if (self->pull == PIN_TYPE_STD) { @@ -720,9 +720,9 @@ STATIC mp_obj_t pin_pull(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_pull_obj, 1, 2, pin_pull); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_pull_obj, 1, 2, pin_pull); -STATIC mp_obj_t pin_drive(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pin_drive(size_t n_args, const mp_obj_t *args) { pin_obj_t *self = args[0]; if (n_args == 1) { return mp_obj_new_int(self->strength); @@ -734,15 +734,15 @@ STATIC mp_obj_t pin_drive(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_drive_obj, 1, 2, pin_drive); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_drive_obj, 1, 2, pin_drive); -STATIC mp_obj_t pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); mp_obj_t _args[2] = {self_in, *args}; return pin_value (n_args + 1, _args); } -STATIC mp_obj_t pin_alt_list(mp_obj_t self_in) { +static mp_obj_t pin_alt_list(mp_obj_t self_in) { pin_obj_t *self = self_in; mp_obj_t af[2]; mp_obj_t afs = mp_obj_new_list(0, NULL); @@ -754,10 +754,10 @@ STATIC mp_obj_t pin_alt_list(mp_obj_t self_in) { } return afs; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_alt_list_obj, pin_alt_list); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_alt_list_obj, pin_alt_list); /// \method irq(trigger, priority, handler, wake) -STATIC mp_obj_t pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_arg_val_t args[mp_irq_INIT_NUM_ARGS]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mp_irq_INIT_NUM_ARGS, mp_irq_init_args, args); pin_obj_t *self = pos_args[0]; @@ -896,9 +896,9 @@ STATIC mp_obj_t pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar invalid_args: mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value")); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pin_irq_obj, 1, pin_irq); +static MP_DEFINE_CONST_FUN_OBJ_KW(pin_irq_obj, 1, pin_irq); -STATIC const mp_rom_map_elem_t pin_locals_dict_table[] = { +static const mp_rom_map_elem_t pin_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pin_init_obj) }, { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&pin_value_obj) }, @@ -929,7 +929,7 @@ STATIC const mp_rom_map_elem_t pin_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_IRQ_HIGH_LEVEL), MP_ROM_INT(PYB_PIN_HIGH_LEVEL) }, }; -STATIC MP_DEFINE_CONST_DICT(pin_locals_dict, pin_locals_dict_table); +static MP_DEFINE_CONST_DICT(pin_locals_dict, pin_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pin_type, @@ -941,14 +941,14 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &pin_locals_dict ); -STATIC const mp_irq_methods_t pin_irq_methods = { +static const mp_irq_methods_t pin_irq_methods = { .init = pin_irq, .enable = pin_irq_enable, .disable = pin_irq_disable, .flags = pin_irq_flags, }; -STATIC void pin_named_pins_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void pin_named_pins_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pin_named_pins_obj_t *self = self_in; mp_printf(print, "", self->name); } diff --git a/ports/cc3200/mods/pybrtc.c b/ports/cc3200/mods/pybrtc.c index 340e86e158883..243fe999312ec 100644 --- a/ports/cc3200/mods/pybrtc.c +++ b/ports/cc3200/mods/pybrtc.c @@ -48,8 +48,8 @@ /****************************************************************************** DECLARE PRIVATE DATA ******************************************************************************/ -STATIC const mp_irq_methods_t pyb_rtc_irq_methods; -STATIC pyb_rtc_obj_t pyb_rtc_obj; +static const mp_irq_methods_t pyb_rtc_irq_methods; +static pyb_rtc_obj_t pyb_rtc_obj; /****************************************************************************** FUNCTION-LIKE MACROS @@ -60,16 +60,16 @@ STATIC pyb_rtc_obj_t pyb_rtc_obj; /****************************************************************************** DECLARE PRIVATE FUNCTIONS ******************************************************************************/ -STATIC void pyb_rtc_set_time (uint32_t secs, uint16_t msecs); -STATIC uint32_t pyb_rtc_reset (void); -STATIC void pyb_rtc_disable_interupt (void); -STATIC void pyb_rtc_irq_enable (mp_obj_t self_in); -STATIC void pyb_rtc_irq_disable (mp_obj_t self_in); -STATIC int pyb_rtc_irq_flags (mp_obj_t self_in); -STATIC uint pyb_rtc_datetime_s_us(const mp_obj_t datetime, uint32_t *seconds); -STATIC mp_obj_t pyb_rtc_datetime(mp_obj_t self, const mp_obj_t datetime); -STATIC void pyb_rtc_set_alarm (pyb_rtc_obj_t *self, uint32_t seconds, uint16_t mseconds); -STATIC void rtc_msec_add(uint16_t msecs_1, uint32_t *secs, uint16_t *msecs_2); +static void pyb_rtc_set_time (uint32_t secs, uint16_t msecs); +static uint32_t pyb_rtc_reset (void); +static void pyb_rtc_disable_interupt (void); +static void pyb_rtc_irq_enable (mp_obj_t self_in); +static void pyb_rtc_irq_disable (mp_obj_t self_in); +static int pyb_rtc_irq_flags (mp_obj_t self_in); +static uint pyb_rtc_datetime_s_us(const mp_obj_t datetime, uint32_t *seconds); +static mp_obj_t pyb_rtc_datetime(mp_obj_t self, const mp_obj_t datetime); +static void pyb_rtc_set_alarm (pyb_rtc_obj_t *self, uint32_t seconds, uint16_t mseconds); +static void rtc_msec_add(uint16_t msecs_1, uint32_t *secs, uint16_t *msecs_2); /****************************************************************************** DECLARE PUBLIC FUNCTIONS @@ -137,7 +137,7 @@ void pyb_rtc_disable_alarm (void) { /****************************************************************************** DECLARE PRIVATE FUNCTIONS ******************************************************************************/ -STATIC void pyb_rtc_set_time (uint32_t secs, uint16_t msecs) { +static void pyb_rtc_set_time (uint32_t secs, uint16_t msecs) { // add the RTC access time rtc_msec_add(RTC_ACCESS_TIME_MSEC, &secs, &msecs); // convert from mseconds to cycles @@ -146,7 +146,7 @@ STATIC void pyb_rtc_set_time (uint32_t secs, uint16_t msecs) { MAP_PRCMRTCSet(secs, msecs); } -STATIC uint32_t pyb_rtc_reset (void) { +static uint32_t pyb_rtc_reset (void) { // fresh reset; configure the RTC Calendar // set the date to 1st Jan 2015 // set the time to 00:00:00 @@ -158,14 +158,14 @@ STATIC uint32_t pyb_rtc_reset (void) { return seconds; } -STATIC void pyb_rtc_disable_interupt (void) { +static void pyb_rtc_disable_interupt (void) { uint primsk = disable_irq(); MAP_PRCMIntDisable(PRCM_INT_SLOW_CLK_CTR); (void)MAP_PRCMIntStatus(); enable_irq(primsk); } -STATIC void pyb_rtc_irq_enable (mp_obj_t self_in) { +static void pyb_rtc_irq_enable (mp_obj_t self_in) { pyb_rtc_obj_t *self = self_in; // we always need interrupts if repeat is enabled if ((self->pwrmode & PYB_PWR_MODE_ACTIVE) || self->repeat) { @@ -176,7 +176,7 @@ STATIC void pyb_rtc_irq_enable (mp_obj_t self_in) { self->irq_enabled = true; } -STATIC void pyb_rtc_irq_disable (mp_obj_t self_in) { +static void pyb_rtc_irq_disable (mp_obj_t self_in) { pyb_rtc_obj_t *self = self_in; self->irq_enabled = false; if (!self->repeat) { // we always need interrupts if repeat is enabled @@ -184,12 +184,12 @@ STATIC void pyb_rtc_irq_disable (mp_obj_t self_in) { } } -STATIC int pyb_rtc_irq_flags (mp_obj_t self_in) { +static int pyb_rtc_irq_flags (mp_obj_t self_in) { pyb_rtc_obj_t *self = self_in; return self->irq_flags; } -STATIC uint pyb_rtc_datetime_s_us(const mp_obj_t datetime, uint32_t *seconds) { +static uint pyb_rtc_datetime_s_us(const mp_obj_t datetime, uint32_t *seconds) { timeutils_struct_time_t tm; uint32_t useconds; @@ -234,7 +234,7 @@ STATIC uint pyb_rtc_datetime_s_us(const mp_obj_t datetime, uint32_t *seconds) { /// /// (year, month, day, hours, minutes, seconds, milliseconds, tzinfo=None) /// -STATIC mp_obj_t pyb_rtc_datetime(mp_obj_t self_in, const mp_obj_t datetime) { +static mp_obj_t pyb_rtc_datetime(mp_obj_t self_in, const mp_obj_t datetime) { uint32_t seconds; uint32_t useconds; @@ -250,7 +250,7 @@ STATIC mp_obj_t pyb_rtc_datetime(mp_obj_t self_in, const mp_obj_t datetime) { return mp_const_none; } -STATIC void pyb_rtc_set_alarm (pyb_rtc_obj_t *self, uint32_t seconds, uint16_t mseconds) { +static void pyb_rtc_set_alarm (pyb_rtc_obj_t *self, uint32_t seconds, uint16_t mseconds) { // disable the interrupt before updating anything if (self->irq_enabled) { MAP_PRCMIntDisable(PRCM_INT_SLOW_CLK_CTR); @@ -266,7 +266,7 @@ STATIC void pyb_rtc_set_alarm (pyb_rtc_obj_t *self, uint32_t seconds, uint16_t m } } -STATIC void rtc_msec_add (uint16_t msecs_1, uint32_t *secs, uint16_t *msecs_2) { +static void rtc_msec_add (uint16_t msecs_1, uint32_t *secs, uint16_t *msecs_2) { if (msecs_1 + *msecs_2 >= 1000) { // larger than one second *msecs_2 = (msecs_1 + *msecs_2) - 1000; *secs += 1; // carry flag @@ -279,11 +279,11 @@ STATIC void rtc_msec_add (uint16_t msecs_1, uint32_t *secs, uint16_t *msecs_2) { /******************************************************************************/ // MicroPython bindings -STATIC const mp_arg_t pyb_rtc_init_args[] = { +static const mp_arg_t pyb_rtc_init_args[] = { { MP_QSTR_id, MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_datetime, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, }; -STATIC mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // parse args mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); @@ -309,15 +309,15 @@ STATIC mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_ return (mp_obj_t)&pyb_rtc_obj; } -STATIC mp_obj_t pyb_rtc_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_rtc_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // parse args mp_arg_val_t args[MP_ARRAY_SIZE(pyb_rtc_init_args) - 1]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &pyb_rtc_init_args[1], args); return pyb_rtc_datetime(pos_args[0], args[0].u_obj); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_init_obj, 1, pyb_rtc_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_init_obj, 1, pyb_rtc_init); -STATIC mp_obj_t pyb_rtc_now (mp_obj_t self_in) { +static mp_obj_t pyb_rtc_now (mp_obj_t self_in) { timeutils_struct_time_t tm; uint32_t seconds; uint16_t mseconds; @@ -338,16 +338,16 @@ STATIC mp_obj_t pyb_rtc_now (mp_obj_t self_in) { }; return mp_obj_new_tuple(8, tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_rtc_now_obj, pyb_rtc_now); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_rtc_now_obj, pyb_rtc_now); -STATIC mp_obj_t pyb_rtc_deinit (mp_obj_t self_in) { +static mp_obj_t pyb_rtc_deinit (mp_obj_t self_in) { pyb_rtc_reset(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_rtc_deinit_obj, pyb_rtc_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_rtc_deinit_obj, pyb_rtc_deinit); -STATIC mp_obj_t pyb_rtc_alarm(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - STATIC const mp_arg_t allowed_args[] = { +static mp_obj_t pyb_rtc_alarm(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + static const mp_arg_t allowed_args[] = { { MP_QSTR_id, MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_time, MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_repeat, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, @@ -385,9 +385,9 @@ STATIC mp_obj_t pyb_rtc_alarm(size_t n_args, const mp_obj_t *pos_args, mp_map_t return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_alarm_obj, 1, pyb_rtc_alarm); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_alarm_obj, 1, pyb_rtc_alarm); -STATIC mp_obj_t pyb_rtc_alarm_left(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_rtc_alarm_left(size_t n_args, const mp_obj_t *args) { pyb_rtc_obj_t *self = args[0]; int32_t ms_left; uint32_t c_seconds; @@ -408,9 +408,9 @@ STATIC mp_obj_t pyb_rtc_alarm_left(size_t n_args, const mp_obj_t *args) { } return mp_obj_new_int(ms_left); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_alarm_left_obj, 1, 2, pyb_rtc_alarm_left); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_alarm_left_obj, 1, 2, pyb_rtc_alarm_left); -STATIC mp_obj_t pyb_rtc_alarm_cancel(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_rtc_alarm_cancel(size_t n_args, const mp_obj_t *args) { // only alarm id 0 is available if (n_args > 1 && mp_obj_get_int(args[1]) != 0) { mp_raise_OSError(MP_ENODEV); @@ -419,10 +419,10 @@ STATIC mp_obj_t pyb_rtc_alarm_cancel(size_t n_args, const mp_obj_t *args) { pyb_rtc_disable_alarm(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_alarm_cancel_obj, 1, 2, pyb_rtc_alarm_cancel); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_alarm_cancel_obj, 1, 2, pyb_rtc_alarm_cancel); /// \method irq(trigger, priority, handler, wake) -STATIC mp_obj_t pyb_rtc_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_rtc_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_arg_val_t args[mp_irq_INIT_NUM_ARGS]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mp_irq_INIT_NUM_ARGS, mp_irq_init_args, args); pyb_rtc_obj_t *self = pos_args[0]; @@ -453,9 +453,9 @@ STATIC mp_obj_t pyb_rtc_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k invalid_args: mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value")); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_irq_obj, 1, pyb_rtc_irq); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_irq_obj, 1, pyb_rtc_irq); -STATIC const mp_rom_map_elem_t pyb_rtc_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_rtc_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_rtc_init_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_rtc_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR_now), MP_ROM_PTR(&pyb_rtc_now_obj) }, @@ -467,7 +467,7 @@ STATIC const mp_rom_map_elem_t pyb_rtc_locals_dict_table[] = { // class constants { MP_ROM_QSTR(MP_QSTR_ALARM0), MP_ROM_INT(PYB_RTC_ALARM0) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_rtc_locals_dict, pyb_rtc_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_rtc_locals_dict, pyb_rtc_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pyb_rtc_type, @@ -477,7 +477,7 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &pyb_rtc_locals_dict ); -STATIC const mp_irq_methods_t pyb_rtc_irq_methods = { +static const mp_irq_methods_t pyb_rtc_irq_methods = { .init = pyb_rtc_irq, .enable = pyb_rtc_irq_enable, .disable = pyb_rtc_irq_disable, diff --git a/ports/cc3200/mods/pybsd.c b/ports/cc3200/mods/pybsd.c index 952a117c4580a..98972ce3a5dda 100644 --- a/ports/cc3200/mods/pybsd.c +++ b/ports/cc3200/mods/pybsd.c @@ -59,20 +59,20 @@ pybsd_obj_t pybsd_obj; /****************************************************************************** DECLARE PRIVATE DATA ******************************************************************************/ -STATIC const mp_obj_t pyb_sd_def_pin[3] = {&pin_GP10, &pin_GP11, &pin_GP15}; +static const mp_obj_t pyb_sd_def_pin[3] = {&pin_GP10, &pin_GP11, &pin_GP15}; /****************************************************************************** DECLARE PRIVATE FUNCTIONS ******************************************************************************/ -STATIC void pyb_sd_hw_init (pybsd_obj_t *self); -STATIC mp_obj_t pyb_sd_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args); -STATIC mp_obj_t pyb_sd_deinit (mp_obj_t self_in); +static void pyb_sd_hw_init (pybsd_obj_t *self); +static mp_obj_t pyb_sd_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args); +static mp_obj_t pyb_sd_deinit (mp_obj_t self_in); /****************************************************************************** DEFINE PRIVATE FUNCTIONS ******************************************************************************/ /// Initializes the sd card hardware driver -STATIC void pyb_sd_hw_init (pybsd_obj_t *self) { +static void pyb_sd_hw_init (pybsd_obj_t *self) { if (self->pin_clk) { // Configure the clock pin as output only MAP_PinDirModeSet(((pin_obj_t *)(self->pin_clk))->pin_num, PIN_DIR_MODE_OUT); @@ -90,7 +90,7 @@ STATIC void pyb_sd_hw_init (pybsd_obj_t *self) { self->enabled = true; } -STATIC mp_obj_t pyb_sd_init_helper (pybsd_obj_t *self, const mp_arg_val_t *args) { +static mp_obj_t pyb_sd_init_helper (pybsd_obj_t *self, const mp_arg_val_t *args) { // assign the pins mp_obj_t pins_o = args[0].u_obj; if (pins_o != mp_const_none) { @@ -120,11 +120,11 @@ STATIC mp_obj_t pyb_sd_init_helper (pybsd_obj_t *self, const mp_arg_val_t *args) // MicroPython bindings // -STATIC const mp_arg_t pyb_sd_init_args[] = { +static const mp_arg_t pyb_sd_init_args[] = { { MP_QSTR_id, MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_pins, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, }; -STATIC mp_obj_t pyb_sd_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t pyb_sd_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // parse args mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); @@ -143,15 +143,15 @@ STATIC mp_obj_t pyb_sd_make_new(const mp_obj_type_t *type, size_t n_args, size_t return self; } -STATIC mp_obj_t pyb_sd_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_sd_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // parse args mp_arg_val_t args[MP_ARRAY_SIZE(pyb_sd_init_args) - 1]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &pyb_sd_init_args[1], args); return pyb_sd_init_helper(pos_args[0], args); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_sd_init_obj, 1, pyb_sd_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_sd_init_obj, 1, pyb_sd_init); -STATIC mp_obj_t pyb_sd_deinit (mp_obj_t self_in) { +static mp_obj_t pyb_sd_deinit (mp_obj_t self_in) { pybsd_obj_t *self = self_in; // disable the peripheral self->enabled = false; @@ -162,25 +162,25 @@ STATIC mp_obj_t pyb_sd_deinit (mp_obj_t self_in) { pyb_sleep_remove (self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_sd_deinit_obj, pyb_sd_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_sd_deinit_obj, pyb_sd_deinit); -STATIC mp_obj_t pyb_sd_readblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) { +static mp_obj_t pyb_sd_readblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_WRITE); DRESULT res = sd_disk_read(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SD_SECTOR_SIZE); return MP_OBJ_NEW_SMALL_INT(res != RES_OK); // return of 0 means success } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_sd_readblocks_obj, pyb_sd_readblocks); +static MP_DEFINE_CONST_FUN_OBJ_3(pyb_sd_readblocks_obj, pyb_sd_readblocks); -STATIC mp_obj_t pyb_sd_writeblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) { +static mp_obj_t pyb_sd_writeblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ); DRESULT res = sd_disk_write(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SD_SECTOR_SIZE); return MP_OBJ_NEW_SMALL_INT(res != RES_OK); // return of 0 means success } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_sd_writeblocks_obj, pyb_sd_writeblocks); +static MP_DEFINE_CONST_FUN_OBJ_3(pyb_sd_writeblocks_obj, pyb_sd_writeblocks); -STATIC mp_obj_t pyb_sd_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) { +static mp_obj_t pyb_sd_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) { mp_int_t cmd = mp_obj_get_int(cmd_in); switch (cmd) { case MP_BLOCKDEV_IOCTL_INIT: @@ -199,9 +199,9 @@ STATIC mp_obj_t pyb_sd_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) { return MP_OBJ_NEW_SMALL_INT(-1); // error } } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_sd_ioctl_obj, pyb_sd_ioctl); +static MP_DEFINE_CONST_FUN_OBJ_3(pyb_sd_ioctl_obj, pyb_sd_ioctl); -STATIC const mp_rom_map_elem_t pyb_sd_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_sd_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_sd_init_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_sd_deinit_obj) }, // block device protocol @@ -210,7 +210,7 @@ STATIC const mp_rom_map_elem_t pyb_sd_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&pyb_sd_ioctl_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_sd_locals_dict, pyb_sd_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_sd_locals_dict, pyb_sd_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pyb_sd_type, diff --git a/ports/cc3200/mods/pybsleep.c b/ports/cc3200/mods/pybsleep.c index ea2642c260942..9d04dd411ddcd 100644 --- a/ports/cc3200/mods/pybsleep.c +++ b/ports/cc3200/mods/pybsleep.c @@ -120,12 +120,12 @@ typedef struct { /****************************************************************************** DECLARE PRIVATE DATA ******************************************************************************/ -STATIC nvic_reg_store_t *nvic_reg_store; -STATIC pybsleep_data_t pybsleep_data = {NULL, NULL, NULL}; +static nvic_reg_store_t *nvic_reg_store; +static pybsleep_data_t pybsleep_data = {NULL, NULL, NULL}; volatile arm_cm4_core_regs_t vault_arm_registers; -STATIC pybsleep_reset_cause_t pybsleep_reset_cause = PYB_SLP_PWRON_RESET; -STATIC pybsleep_wake_reason_t pybsleep_wake_reason = PYB_SLP_WAKED_PWRON; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static pybsleep_reset_cause_t pybsleep_reset_cause = PYB_SLP_PWRON_RESET; +static pybsleep_wake_reason_t pybsleep_wake_reason = PYB_SLP_WAKED_PWRON; +static MP_DEFINE_CONST_OBJ_TYPE( pyb_sleep_type, MP_QSTR_sleep, MP_TYPE_FLAG_NONE @@ -134,15 +134,15 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( /****************************************************************************** DECLARE PRIVATE FUNCTIONS ******************************************************************************/ -STATIC pyb_sleep_obj_t *pyb_sleep_find (mp_obj_t obj); -STATIC void pyb_sleep_flash_powerdown (void); -STATIC NORETURN void pyb_sleep_suspend_enter (void); +static pyb_sleep_obj_t *pyb_sleep_find (mp_obj_t obj); +static void pyb_sleep_flash_powerdown (void); +static NORETURN void pyb_sleep_suspend_enter (void); void pyb_sleep_suspend_exit (void); -STATIC void pyb_sleep_obj_wakeup (void); -STATIC void PRCMInterruptHandler (void); -STATIC void pyb_sleep_iopark (bool hibernate); -STATIC bool setup_timer_lpds_wake (void); -STATIC bool setup_timer_hibernate_wake (void); +static void pyb_sleep_obj_wakeup (void); +static void PRCMInterruptHandler (void); +static void pyb_sleep_iopark (bool hibernate); +static bool setup_timer_lpds_wake (void); +static bool setup_timer_hibernate_wake (void); /****************************************************************************** DEFINE PUBLIC FUNCTIONS @@ -304,7 +304,7 @@ pybsleep_wake_reason_t pyb_sleep_get_wake_reason (void) { /****************************************************************************** DEFINE PRIVATE FUNCTIONS ******************************************************************************/ -STATIC pyb_sleep_obj_t *pyb_sleep_find (mp_obj_t obj) { +static pyb_sleep_obj_t *pyb_sleep_find (mp_obj_t obj) { for (mp_uint_t i = 0; i < MP_STATE_PORT(pyb_sleep_obj_list).len; i++) { // search for the object and then remove it pyb_sleep_obj_t *sleep_obj = ((pyb_sleep_obj_t *)(MP_STATE_PORT(pyb_sleep_obj_list).items[i])); @@ -315,7 +315,7 @@ STATIC pyb_sleep_obj_t *pyb_sleep_find (mp_obj_t obj) { return NULL; } -STATIC void pyb_sleep_flash_powerdown (void) { +static void pyb_sleep_flash_powerdown (void) { uint32_t status; // Enable clock for SSPI module @@ -360,7 +360,7 @@ STATIC void pyb_sleep_flash_powerdown (void) { MAP_SPICSDisable(SSPI_BASE); } -STATIC NORETURN void pyb_sleep_suspend_enter (void) { +static NORETURN void pyb_sleep_suspend_enter (void) { // enable full RAM retention MAP_PRCMSRAMRetentionEnable(PRCM_SRAM_COL_1 | PRCM_SRAM_COL_2 | PRCM_SRAM_COL_3 | PRCM_SRAM_COL_4, PRCM_SRAM_LPDS_RET); @@ -479,7 +479,7 @@ void pyb_sleep_suspend_exit (void) { mp_raise_type(&mp_type_SystemExit); } -STATIC void PRCMInterruptHandler (void) { +static void PRCMInterruptHandler (void) { // reading the interrupt status automatically clears the interrupt if (PRCM_INT_SLOW_CLK_CTR == MAP_PRCMIntStatus()) { // reconfigure it again (if repeat is true) @@ -519,14 +519,14 @@ STATIC void PRCMInterruptHandler (void) { } } -STATIC void pyb_sleep_obj_wakeup (void) { +static void pyb_sleep_obj_wakeup (void) { for (mp_uint_t i = 0; i < MP_STATE_PORT(pyb_sleep_obj_list).len; i++) { pyb_sleep_obj_t *sleep_obj = ((pyb_sleep_obj_t *)MP_STATE_PORT(pyb_sleep_obj_list).items[i]); sleep_obj->wakeup(sleep_obj->obj); } } -STATIC void pyb_sleep_iopark (bool hibernate) { +static void pyb_sleep_iopark (bool hibernate) { const mp_map_t *named_map = &pin_board_pins_locals_dict.map; for (uint i = 0; i < named_map->used; i++) { pin_obj_t * pin = (pin_obj_t *)named_map->table[i].value; @@ -583,7 +583,7 @@ STATIC void pyb_sleep_iopark (bool hibernate) { #endif } -STATIC bool setup_timer_lpds_wake (void) { +static bool setup_timer_lpds_wake (void) { uint64_t t_match, t_curr; int64_t t_remaining; @@ -618,7 +618,7 @@ STATIC bool setup_timer_lpds_wake (void) { return false; } -STATIC bool setup_timer_hibernate_wake (void) { +static bool setup_timer_hibernate_wake (void) { uint64_t t_match, t_curr; int64_t t_remaining; diff --git a/ports/cc3200/mods/pybspi.c b/ports/cc3200/mods/pybspi.c index fa38f0c6576c7..e49bb14b475f8 100644 --- a/ports/cc3200/mods/pybspi.c +++ b/ports/cc3200/mods/pybspi.c @@ -68,15 +68,15 @@ typedef struct _pyb_spi_obj_t { /****************************************************************************** DECLARE PRIVATE DATA ******************************************************************************/ -STATIC pyb_spi_obj_t pyb_spi_obj = {.baudrate = 0}; +static pyb_spi_obj_t pyb_spi_obj = {.baudrate = 0}; -STATIC const mp_obj_t pyb_spi_def_pin[3] = {&pin_GP14, &pin_GP16, &pin_GP30}; +static const mp_obj_t pyb_spi_def_pin[3] = {&pin_GP14, &pin_GP16, &pin_GP30}; /****************************************************************************** DEFINE PRIVATE FUNCTIONS ******************************************************************************/ // only master mode is available for the moment -STATIC void pybspi_init (const pyb_spi_obj_t *self) { +static void pybspi_init (const pyb_spi_obj_t *self) { // enable the peripheral clock MAP_PRCMPeripheralClkEnable(PRCM_GSPI, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK); MAP_PRCMPeripheralReset(PRCM_GSPI); @@ -90,7 +90,7 @@ STATIC void pybspi_init (const pyb_spi_obj_t *self) { MAP_SPIEnable(GSPI_BASE); } -STATIC void pybspi_tx (pyb_spi_obj_t *self, const void *data) { +static void pybspi_tx (pyb_spi_obj_t *self, const void *data) { uint32_t txdata; switch (self->wlen) { case 1: @@ -108,7 +108,7 @@ STATIC void pybspi_tx (pyb_spi_obj_t *self, const void *data) { MAP_SPIDataPut (GSPI_BASE, txdata); } -STATIC void pybspi_rx (pyb_spi_obj_t *self, void *data) { +static void pybspi_rx (pyb_spi_obj_t *self, void *data) { uint32_t rxdata; MAP_SPIDataGet (GSPI_BASE, &rxdata); if (data) { @@ -128,7 +128,7 @@ STATIC void pybspi_rx (pyb_spi_obj_t *self, void *data) { } } -STATIC void pybspi_transfer (pyb_spi_obj_t *self, const char *txdata, char *rxdata, uint32_t len, uint32_t *txchar) { +static void pybspi_transfer (pyb_spi_obj_t *self, const char *txdata, char *rxdata, uint32_t len, uint32_t *txchar) { if (!self->baudrate) { mp_raise_OSError(MP_EPERM); } @@ -144,7 +144,7 @@ STATIC void pybspi_transfer (pyb_spi_obj_t *self, const char *txdata, char *rxda /******************************************************************************/ /* MicroPython bindings */ /******************************************************************************/ -STATIC void pyb_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void pyb_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_spi_obj_t *self = self_in; if (self->baudrate > 0) { mp_printf(print, "SPI(0, baudrate=%u, bits=%u, polarity=%u, phase=%u, firstbit=SPI.MSB)", @@ -154,7 +154,7 @@ STATIC void pyb_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki } } -STATIC mp_obj_t pyb_spi_init_helper(pyb_spi_obj_t *self, const mp_arg_val_t *args) { +static mp_obj_t pyb_spi_init_helper(pyb_spi_obj_t *self, const mp_arg_val_t *args) { uint bits; switch (args[1].u_int) { case 8: @@ -224,7 +224,7 @@ static const mp_arg_t pyb_spi_init_args[] = { { MP_QSTR_firstbit, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = PYBSPI_FIRST_BIT_MSB} }, { MP_QSTR_pins, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, }; -STATIC mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // parse args mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); @@ -246,17 +246,17 @@ STATIC mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_ return self; } -STATIC mp_obj_t pyb_spi_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_spi_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // parse args mp_arg_val_t args[MP_ARRAY_SIZE(pyb_spi_init_args) - 1]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &pyb_spi_init_args[1], args); return pyb_spi_init_helper(pos_args[0], args); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_init_obj, 1, pyb_spi_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_init_obj, 1, pyb_spi_init); /// \method deinit() /// Turn off the spi bus. -STATIC mp_obj_t pyb_spi_deinit(mp_obj_t self_in) { +static mp_obj_t pyb_spi_deinit(mp_obj_t self_in) { // disable the peripheral MAP_SPIDisable(GSPI_BASE); MAP_PRCMPeripheralClkDisable(PRCM_GSPI, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK); @@ -266,9 +266,9 @@ STATIC mp_obj_t pyb_spi_deinit(mp_obj_t self_in) { pyb_sleep_remove((const mp_obj_t)self_in); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_spi_deinit_obj, pyb_spi_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_spi_deinit_obj, pyb_spi_deinit); -STATIC mp_obj_t pyb_spi_write (mp_obj_t self_in, mp_obj_t buf) { +static mp_obj_t pyb_spi_write (mp_obj_t self_in, mp_obj_t buf) { // parse args pyb_spi_obj_t *self = self_in; @@ -283,9 +283,9 @@ STATIC mp_obj_t pyb_spi_write (mp_obj_t self_in, mp_obj_t buf) { // return the number of bytes written return mp_obj_new_int(bufinfo.len); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_spi_write_obj, pyb_spi_write); +static MP_DEFINE_CONST_FUN_OBJ_2(pyb_spi_write_obj, pyb_spi_write); -STATIC mp_obj_t pyb_spi_read(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_spi_read(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_nbytes, MP_ARG_REQUIRED | MP_ARG_OBJ, }, { MP_QSTR_write, MP_ARG_INT, {.u_int = 0x00} }, @@ -307,9 +307,9 @@ STATIC mp_obj_t pyb_spi_read(size_t n_args, const mp_obj_t *pos_args, mp_map_t * // return the received data return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_read_obj, 1, pyb_spi_read); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_read_obj, 1, pyb_spi_read); -STATIC mp_obj_t pyb_spi_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_spi_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_buf, MP_ARG_REQUIRED | MP_ARG_OBJ, }, { MP_QSTR_write, MP_ARG_INT, {.u_int = 0x00} }, @@ -331,9 +331,9 @@ STATIC mp_obj_t pyb_spi_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map // return the number of bytes received return mp_obj_new_int(vstr.len); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_readinto_obj, 1, pyb_spi_readinto); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_readinto_obj, 1, pyb_spi_readinto); -STATIC mp_obj_t pyb_spi_write_readinto (mp_obj_t self, mp_obj_t writebuf, mp_obj_t readbuf) { +static mp_obj_t pyb_spi_write_readinto (mp_obj_t self, mp_obj_t writebuf, mp_obj_t readbuf) { // get buffers to write from/read to mp_buffer_info_t bufinfo_write; uint8_t data_send[1]; @@ -360,9 +360,9 @@ STATIC mp_obj_t pyb_spi_write_readinto (mp_obj_t self, mp_obj_t writebuf, mp_obj // return the number of transferred bytes return mp_obj_new_int(bufinfo_write.len); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_spi_write_readinto_obj, pyb_spi_write_readinto); +static MP_DEFINE_CONST_FUN_OBJ_3(pyb_spi_write_readinto_obj, pyb_spi_write_readinto); -STATIC const mp_rom_map_elem_t pyb_spi_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_spi_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_spi_init_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_spi_deinit_obj) }, @@ -375,7 +375,7 @@ STATIC const mp_rom_map_elem_t pyb_spi_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_MSB), MP_ROM_INT(PYBSPI_FIRST_BIT_MSB) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_spi_locals_dict, pyb_spi_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_spi_locals_dict, pyb_spi_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pyb_spi_type, diff --git a/ports/cc3200/mods/pybtimer.c b/ports/cc3200/mods/pybtimer.c index be365f3c92b26..a9a154308e43b 100644 --- a/ports/cc3200/mods/pybtimer.c +++ b/ports/cc3200/mods/pybtimer.c @@ -96,28 +96,28 @@ typedef struct _pyb_timer_channel_obj_t { /****************************************************************************** DEFINE PRIVATE DATA ******************************************************************************/ -STATIC const mp_irq_methods_t pyb_timer_channel_irq_methods; -STATIC pyb_timer_obj_t pyb_timer_obj[PYBTIMER_NUM_TIMERS] = {{.timer = TIMERA0_BASE, .peripheral = PRCM_TIMERA0}, +static const mp_irq_methods_t pyb_timer_channel_irq_methods; +static pyb_timer_obj_t pyb_timer_obj[PYBTIMER_NUM_TIMERS] = {{.timer = TIMERA0_BASE, .peripheral = PRCM_TIMERA0}, {.timer = TIMERA1_BASE, .peripheral = PRCM_TIMERA1}, {.timer = TIMERA2_BASE, .peripheral = PRCM_TIMERA2}, {.timer = TIMERA3_BASE, .peripheral = PRCM_TIMERA3}}; -STATIC const mp_obj_type_t pyb_timer_channel_type; -STATIC const mp_obj_t pyb_timer_pwm_pin[8] = {&pin_GP24, MP_OBJ_NULL, &pin_GP25, MP_OBJ_NULL, MP_OBJ_NULL, &pin_GP9, &pin_GP10, &pin_GP11}; +static const mp_obj_type_t pyb_timer_channel_type; +static const mp_obj_t pyb_timer_pwm_pin[8] = {&pin_GP24, MP_OBJ_NULL, &pin_GP25, MP_OBJ_NULL, MP_OBJ_NULL, &pin_GP9, &pin_GP10, &pin_GP11}; /****************************************************************************** DECLARE PRIVATE FUNCTIONS ******************************************************************************/ -STATIC mp_obj_t pyb_timer_channel_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args); -STATIC void timer_disable (pyb_timer_obj_t *tim); -STATIC void timer_channel_init (pyb_timer_channel_obj_t *ch); -STATIC void TIMER0AIntHandler(void); -STATIC void TIMER0BIntHandler(void); -STATIC void TIMER1AIntHandler(void); -STATIC void TIMER1BIntHandler(void); -STATIC void TIMER2AIntHandler(void); -STATIC void TIMER2BIntHandler(void); -STATIC void TIMER3AIntHandler(void); -STATIC void TIMER3BIntHandler(void); +static mp_obj_t pyb_timer_channel_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args); +static void timer_disable (pyb_timer_obj_t *tim); +static void timer_channel_init (pyb_timer_channel_obj_t *ch); +static void TIMER0AIntHandler(void); +static void TIMER0BIntHandler(void); +static void TIMER1AIntHandler(void); +static void TIMER1BIntHandler(void); +static void TIMER2AIntHandler(void); +static void TIMER2BIntHandler(void); +static void TIMER3AIntHandler(void); +static void TIMER3BIntHandler(void); /****************************************************************************** DEFINE PUBLIC FUNCTIONS @@ -129,23 +129,23 @@ void timer_init0 (void) { /****************************************************************************** DEFINE PRIVATE FUNCTIONS ******************************************************************************/ -STATIC void pyb_timer_channel_irq_enable (mp_obj_t self_in) { +static void pyb_timer_channel_irq_enable (mp_obj_t self_in) { pyb_timer_channel_obj_t *self = self_in; MAP_TimerIntClear(self->timer->timer, self->timer->irq_trigger & self->channel); MAP_TimerIntEnable(self->timer->timer, self->timer->irq_trigger & self->channel); } -STATIC void pyb_timer_channel_irq_disable (mp_obj_t self_in) { +static void pyb_timer_channel_irq_disable (mp_obj_t self_in) { pyb_timer_channel_obj_t *self = self_in; MAP_TimerIntDisable(self->timer->timer, self->timer->irq_trigger & self->channel); } -STATIC int pyb_timer_channel_irq_flags (mp_obj_t self_in) { +static int pyb_timer_channel_irq_flags (mp_obj_t self_in) { pyb_timer_channel_obj_t *self = self_in; return self->timer->irq_flags; } -STATIC pyb_timer_channel_obj_t *pyb_timer_channel_find (uint32_t timer, uint16_t channel_n) { +static pyb_timer_channel_obj_t *pyb_timer_channel_find (uint32_t timer, uint16_t channel_n) { for (mp_uint_t i = 0; i < MP_STATE_PORT(pyb_timer_channel_obj_list).len; i++) { pyb_timer_channel_obj_t *ch = ((pyb_timer_channel_obj_t *)(MP_STATE_PORT(pyb_timer_channel_obj_list).items[i])); // any 32-bit timer must be matched by any of its 16-bit versions @@ -156,7 +156,7 @@ STATIC pyb_timer_channel_obj_t *pyb_timer_channel_find (uint32_t timer, uint16_t return MP_OBJ_NULL; } -STATIC void pyb_timer_channel_remove (pyb_timer_channel_obj_t *ch) { +static void pyb_timer_channel_remove (pyb_timer_channel_obj_t *ch) { pyb_timer_channel_obj_t *channel; if ((channel = pyb_timer_channel_find(ch->timer->timer, ch->channel))) { mp_obj_list_remove(&MP_STATE_PORT(pyb_timer_channel_obj_list), channel); @@ -165,7 +165,7 @@ STATIC void pyb_timer_channel_remove (pyb_timer_channel_obj_t *ch) { } } -STATIC void pyb_timer_channel_add (pyb_timer_channel_obj_t *ch) { +static void pyb_timer_channel_add (pyb_timer_channel_obj_t *ch) { // remove it in case it already exists pyb_timer_channel_remove(ch); mp_obj_list_append(&MP_STATE_PORT(pyb_timer_channel_obj_list), ch); @@ -173,7 +173,7 @@ STATIC void pyb_timer_channel_add (pyb_timer_channel_obj_t *ch) { pyb_sleep_add((const mp_obj_t)ch, (WakeUpCB_t)timer_channel_init); } -STATIC void timer_disable (pyb_timer_obj_t *tim) { +static void timer_disable (pyb_timer_obj_t *tim) { // disable all timers and it's interrupts MAP_TimerDisable(tim->timer, TIMER_A | TIMER_B); MAP_TimerIntDisable(tim->timer, tim->irq_trigger); @@ -190,7 +190,7 @@ STATIC void timer_disable (pyb_timer_obj_t *tim) { } // computes prescaler period and match value so timer triggers at freq-Hz -STATIC uint32_t compute_prescaler_period_and_match_value(pyb_timer_channel_obj_t *ch, uint32_t *period_out, uint32_t *match_out) { +static uint32_t compute_prescaler_period_and_match_value(pyb_timer_channel_obj_t *ch, uint32_t *period_out, uint32_t *match_out) { uint32_t maxcount = (ch->channel == (TIMER_A | TIMER_B)) ? 0xFFFFFFFF : 0xFFFF; uint32_t prescaler; uint32_t period_c = (ch->frequency > 0) ? PYBTIMER_SRC_FREQ_HZ / ch->frequency : ((PYBTIMER_SRC_FREQ_HZ / 1000000) * ch->period); @@ -223,13 +223,13 @@ STATIC uint32_t compute_prescaler_period_and_match_value(pyb_timer_channel_obj_t mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value")); } -STATIC void timer_init (pyb_timer_obj_t *tim) { +static void timer_init (pyb_timer_obj_t *tim) { MAP_PRCMPeripheralClkEnable(tim->peripheral, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK); MAP_PRCMPeripheralReset(tim->peripheral); MAP_TimerConfigure(tim->timer, tim->config); } -STATIC void timer_channel_init (pyb_timer_channel_obj_t *ch) { +static void timer_channel_init (pyb_timer_channel_obj_t *ch) { // calculate the period, the prescaler and the match value uint32_t period_c; uint32_t match; @@ -262,7 +262,7 @@ STATIC void timer_channel_init (pyb_timer_channel_obj_t *ch) { /******************************************************************************/ /* MicroPython bindings */ -STATIC void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_timer_obj_t *tim = self_in; uint32_t mode = tim->config & 0xFF; @@ -281,7 +281,7 @@ STATIC void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ mp_printf(print, "Timer(%u, mode=Timer.%q)", tim->id, mode_qst); } -STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *tim, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *tim, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT, }, { MP_QSTR_width, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 16} }, @@ -319,7 +319,7 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *tim, size_t n_args, const mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value")); } -STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); @@ -342,19 +342,19 @@ STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, siz return (mp_obj_t)tim; } -STATIC mp_obj_t pyb_timer_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t pyb_timer_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { return pyb_timer_init_helper(args[0], n_args - 1, args + 1, kw_args); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_init_obj, 1, pyb_timer_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_init_obj, 1, pyb_timer_init); -STATIC mp_obj_t pyb_timer_deinit(mp_obj_t self_in) { +static mp_obj_t pyb_timer_deinit(mp_obj_t self_in) { pyb_timer_obj_t *self = self_in; timer_disable(self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj, pyb_timer_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj, pyb_timer_deinit); -STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_freq, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_period, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, @@ -438,9 +438,9 @@ STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_ma error: mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value")); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_channel_obj, 2, pyb_timer_channel); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_channel_obj, 2, pyb_timer_channel); -STATIC const mp_rom_map_elem_t pyb_timer_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_timer_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_timer_init_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_timer_deinit_obj) }, @@ -457,7 +457,7 @@ STATIC const mp_rom_map_elem_t pyb_timer_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_TIMEOUT), MP_ROM_INT(PYBTIMER_TIMEOUT_TRIGGER) }, { MP_ROM_QSTR(MP_QSTR_MATCH), MP_ROM_INT(PYBTIMER_MATCH_TRIGGER) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_timer_locals_dict, pyb_timer_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_timer_locals_dict, pyb_timer_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pyb_timer_type, @@ -468,14 +468,14 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &pyb_timer_locals_dict ); -STATIC const mp_irq_methods_t pyb_timer_channel_irq_methods = { +static const mp_irq_methods_t pyb_timer_channel_irq_methods = { .init = pyb_timer_channel_irq, .enable = pyb_timer_channel_irq_enable, .disable = pyb_timer_channel_irq_disable, .flags = pyb_timer_channel_irq_flags, }; -STATIC void TIMERGenericIntHandler(uint32_t timer, uint16_t channel) { +static void TIMERGenericIntHandler(uint32_t timer, uint16_t channel) { pyb_timer_channel_obj_t *self; uint32_t status; if ((self = pyb_timer_channel_find(timer, channel))) { @@ -485,39 +485,39 @@ STATIC void TIMERGenericIntHandler(uint32_t timer, uint16_t channel) { } } -STATIC void TIMER0AIntHandler(void) { +static void TIMER0AIntHandler(void) { TIMERGenericIntHandler(TIMERA0_BASE, TIMER_A); } -STATIC void TIMER0BIntHandler(void) { +static void TIMER0BIntHandler(void) { TIMERGenericIntHandler(TIMERA0_BASE, TIMER_B); } -STATIC void TIMER1AIntHandler(void) { +static void TIMER1AIntHandler(void) { TIMERGenericIntHandler(TIMERA1_BASE, TIMER_A); } -STATIC void TIMER1BIntHandler(void) { +static void TIMER1BIntHandler(void) { TIMERGenericIntHandler(TIMERA1_BASE, TIMER_B); } -STATIC void TIMER2AIntHandler(void) { +static void TIMER2AIntHandler(void) { TIMERGenericIntHandler(TIMERA2_BASE, TIMER_A); } -STATIC void TIMER2BIntHandler(void) { +static void TIMER2BIntHandler(void) { TIMERGenericIntHandler(TIMERA2_BASE, TIMER_B); } -STATIC void TIMER3AIntHandler(void) { +static void TIMER3AIntHandler(void) { TIMERGenericIntHandler(TIMERA3_BASE, TIMER_A); } -STATIC void TIMER3BIntHandler(void) { +static void TIMER3BIntHandler(void) { TIMERGenericIntHandler(TIMERA3_BASE, TIMER_B); } -STATIC void pyb_timer_channel_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void pyb_timer_channel_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_timer_channel_obj_t *ch = self_in; char *ch_id = "AB"; // timer channel @@ -548,7 +548,7 @@ STATIC void pyb_timer_channel_print(const mp_print_t *print, mp_obj_t self_in, m mp_printf(print, ")"); } -STATIC mp_obj_t pyb_timer_channel_freq(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_timer_channel_freq(size_t n_args, const mp_obj_t *args) { pyb_timer_channel_obj_t *ch = args[0]; if (n_args == 1) { // get @@ -565,9 +565,9 @@ STATIC mp_obj_t pyb_timer_channel_freq(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_freq_obj, 1, 2, pyb_timer_channel_freq); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_freq_obj, 1, 2, pyb_timer_channel_freq); -STATIC mp_obj_t pyb_timer_channel_period(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_timer_channel_period(size_t n_args, const mp_obj_t *args) { pyb_timer_channel_obj_t *ch = args[0]; if (n_args == 1) { // get @@ -584,9 +584,9 @@ STATIC mp_obj_t pyb_timer_channel_period(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_period_obj, 1, 2, pyb_timer_channel_period); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_period_obj, 1, 2, pyb_timer_channel_period); -STATIC mp_obj_t pyb_timer_channel_duty_cycle(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_timer_channel_duty_cycle(size_t n_args, const mp_obj_t *args) { pyb_timer_channel_obj_t *ch = args[0]; if (n_args == 1) { // get @@ -608,9 +608,9 @@ STATIC mp_obj_t pyb_timer_channel_duty_cycle(size_t n_args, const mp_obj_t *args return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_duty_cycle_obj, 1, 3, pyb_timer_channel_duty_cycle); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_duty_cycle_obj, 1, 3, pyb_timer_channel_duty_cycle); -STATIC mp_obj_t pyb_timer_channel_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_timer_channel_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_arg_val_t args[mp_irq_INIT_NUM_ARGS]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mp_irq_INIT_NUM_ARGS, mp_irq_init_args, args); pyb_timer_channel_obj_t *ch = pos_args[0]; @@ -711,18 +711,18 @@ STATIC mp_obj_t pyb_timer_channel_irq(size_t n_args, const mp_obj_t *pos_args, m invalid_args: mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value")); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_channel_irq_obj, 1, pyb_timer_channel_irq); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_channel_irq_obj, 1, pyb_timer_channel_irq); -STATIC const mp_rom_map_elem_t pyb_timer_channel_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_timer_channel_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&pyb_timer_channel_freq_obj) }, { MP_ROM_QSTR(MP_QSTR_period), MP_ROM_PTR(&pyb_timer_channel_period_obj) }, { MP_ROM_QSTR(MP_QSTR_duty_cycle), MP_ROM_PTR(&pyb_timer_channel_duty_cycle_obj) }, { MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&pyb_timer_channel_irq_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_timer_channel_locals_dict, pyb_timer_channel_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_timer_channel_locals_dict, pyb_timer_channel_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( pyb_timer_channel_type, MP_QSTR_TimerChannel, MP_TYPE_FLAG_NONE, diff --git a/ports/cc3200/mods/pybuart.c b/ports/cc3200/mods/pybuart.c index c9a753da04853..6ab2371ba708f 100644 --- a/ports/cc3200/mods/pybuart.c +++ b/ports/cc3200/mods/pybuart.c @@ -76,15 +76,15 @@ /****************************************************************************** DECLARE PRIVATE FUNCTIONS ******************************************************************************/ -STATIC void uart_init (pyb_uart_obj_t *self); -STATIC bool uart_rx_wait (pyb_uart_obj_t *self); -STATIC void uart_check_init(pyb_uart_obj_t *self); -STATIC mp_obj_t uart_irq_new (pyb_uart_obj_t *self, byte trigger, mp_int_t priority, mp_obj_t handler); -STATIC void UARTGenericIntHandler(uint32_t uart_id); -STATIC void UART0IntHandler(void); -STATIC void UART1IntHandler(void); -STATIC void uart_irq_enable (mp_obj_t self_in); -STATIC void uart_irq_disable (mp_obj_t self_in); +static void uart_init (pyb_uart_obj_t *self); +static bool uart_rx_wait (pyb_uart_obj_t *self); +static void uart_check_init(pyb_uart_obj_t *self); +static mp_obj_t uart_irq_new (pyb_uart_obj_t *self, byte trigger, mp_int_t priority, mp_obj_t handler); +static void UARTGenericIntHandler(uint32_t uart_id); +static void UART0IntHandler(void); +static void UART1IntHandler(void); +static void uart_irq_enable (mp_obj_t self_in); +static void uart_irq_disable (mp_obj_t self_in); /****************************************************************************** DEFINE PRIVATE TYPES @@ -108,11 +108,11 @@ struct _pyb_uart_obj_t { /****************************************************************************** DECLARE PRIVATE DATA ******************************************************************************/ -STATIC pyb_uart_obj_t pyb_uart_obj[PYB_NUM_UARTS] = { {.reg = UARTA0_BASE, .baudrate = 0, .read_buf = NULL, .peripheral = PRCM_UARTA0}, +static pyb_uart_obj_t pyb_uart_obj[PYB_NUM_UARTS] = { {.reg = UARTA0_BASE, .baudrate = 0, .read_buf = NULL, .peripheral = PRCM_UARTA0}, {.reg = UARTA1_BASE, .baudrate = 0, .read_buf = NULL, .peripheral = PRCM_UARTA1} }; -STATIC const mp_irq_methods_t uart_irq_methods; +static const mp_irq_methods_t uart_irq_methods; -STATIC const mp_obj_t pyb_uart_def_pin[PYB_NUM_UARTS][2] = { {&pin_GP1, &pin_GP2}, {&pin_GP3, &pin_GP4} }; +static const mp_obj_t pyb_uart_def_pin[PYB_NUM_UARTS][2] = { {&pin_GP1, &pin_GP2}, {&pin_GP3, &pin_GP4} }; /****************************************************************************** DEFINE PUBLIC FUNCTIONS @@ -168,7 +168,7 @@ bool uart_tx_strn(pyb_uart_obj_t *self, const char *str, uint len) { DEFINE PRIVATE FUNCTIONS ******************************************************************************/ // assumes init parameters have been set up correctly -STATIC void uart_init (pyb_uart_obj_t *self) { +static void uart_init (pyb_uart_obj_t *self) { // Enable the peripheral clock MAP_PRCMPeripheralClkEnable(self->peripheral, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK); @@ -198,7 +198,7 @@ STATIC void uart_init (pyb_uart_obj_t *self) { // Waits at most timeout microseconds for at least 1 char to become ready for // reading (from buf or for direct reading). // Returns true if something available, false if not. -STATIC bool uart_rx_wait (pyb_uart_obj_t *self) { +static bool uart_rx_wait (pyb_uart_obj_t *self) { int timeout = PYBUART_RX_TIMEOUT_US(self->baudrate); for ( ; ; ) { if (uart_rx_any(self)) { @@ -214,7 +214,7 @@ STATIC bool uart_rx_wait (pyb_uart_obj_t *self) { } } -STATIC mp_obj_t uart_irq_new (pyb_uart_obj_t *self, byte trigger, mp_int_t priority, mp_obj_t handler) { +static mp_obj_t uart_irq_new (pyb_uart_obj_t *self, byte trigger, mp_int_t priority, mp_obj_t handler) { // disable the uart interrupts before updating anything uart_irq_disable (self); @@ -235,7 +235,7 @@ STATIC mp_obj_t uart_irq_new (pyb_uart_obj_t *self, byte trigger, mp_int_t prior return _irq; } -STATIC void UARTGenericIntHandler(uint32_t uart_id) { +static void UARTGenericIntHandler(uint32_t uart_id) { pyb_uart_obj_t *self; uint32_t status; @@ -272,22 +272,22 @@ STATIC void UARTGenericIntHandler(uint32_t uart_id) { self->irq_flags = 0; } -STATIC void uart_check_init(pyb_uart_obj_t *self) { +static void uart_check_init(pyb_uart_obj_t *self) { // not initialized if (!self->baudrate) { mp_raise_OSError(MP_EPERM); } } -STATIC void UART0IntHandler(void) { +static void UART0IntHandler(void) { UARTGenericIntHandler(0); } -STATIC void UART1IntHandler(void) { +static void UART1IntHandler(void) { UARTGenericIntHandler(1); } -STATIC void uart_irq_enable (mp_obj_t self_in) { +static void uart_irq_enable (mp_obj_t self_in) { pyb_uart_obj_t *self = self_in; // check for any of the rx interrupt types if (self->irq_trigger & (UART_TRIGGER_RX_ANY | UART_TRIGGER_RX_HALF | UART_TRIGGER_RX_FULL)) { @@ -297,12 +297,12 @@ STATIC void uart_irq_enable (mp_obj_t self_in) { self->irq_enabled = true; } -STATIC void uart_irq_disable (mp_obj_t self_in) { +static void uart_irq_disable (mp_obj_t self_in) { pyb_uart_obj_t *self = self_in; self->irq_enabled = false; } -STATIC int uart_irq_flags (mp_obj_t self_in) { +static int uart_irq_flags (mp_obj_t self_in) { pyb_uart_obj_t *self = self_in; return self->irq_flags; } @@ -310,7 +310,7 @@ STATIC int uart_irq_flags (mp_obj_t self_in) { /******************************************************************************/ /* MicroPython bindings */ -STATIC void pyb_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void pyb_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_uart_obj_t *self = self_in; if (self->baudrate > 0) { mp_printf(print, "UART(%u, baudrate=%u, bits=", self->uart_id, self->baudrate); @@ -342,7 +342,7 @@ STATIC void pyb_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_k } } -STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, const mp_arg_val_t *args) { +static mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, const mp_arg_val_t *args) { // get the baudrate if (args[0].u_int <= 0) { goto error; @@ -433,7 +433,7 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, const mp_arg_val_t *a mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value")); } -STATIC const mp_arg_t pyb_uart_init_args[] = { +static const mp_arg_t pyb_uart_init_args[] = { { MP_QSTR_id, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_baudrate, MP_ARG_INT, {.u_int = 9600} }, { MP_QSTR_bits, MP_ARG_INT, {.u_int = 8} }, @@ -441,7 +441,7 @@ STATIC const mp_arg_t pyb_uart_init_args[] = { { MP_QSTR_stop, MP_ARG_INT, {.u_int = 1} }, { MP_QSTR_pins, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, }; -STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // parse args mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); @@ -484,15 +484,15 @@ STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, size_t n_args, size return self; } -STATIC mp_obj_t pyb_uart_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_uart_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // parse args mp_arg_val_t args[MP_ARRAY_SIZE(pyb_uart_init_args) - 1]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &pyb_uart_init_args[1], args); return pyb_uart_init_helper(pos_args[0], args); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_uart_init_obj, 1, pyb_uart_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_uart_init_obj, 1, pyb_uart_init); -STATIC mp_obj_t pyb_uart_deinit(mp_obj_t self_in) { +static mp_obj_t pyb_uart_deinit(mp_obj_t self_in) { pyb_uart_obj_t *self = self_in; // unregister it with the sleep module @@ -506,16 +506,16 @@ STATIC mp_obj_t pyb_uart_deinit(mp_obj_t self_in) { MAP_PRCMPeripheralClkDisable(self->peripheral, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_deinit_obj, pyb_uart_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_deinit_obj, pyb_uart_deinit); -STATIC mp_obj_t pyb_uart_any(mp_obj_t self_in) { +static mp_obj_t pyb_uart_any(mp_obj_t self_in) { pyb_uart_obj_t *self = self_in; uart_check_init(self); return mp_obj_new_int(uart_rx_any(self)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_any_obj, pyb_uart_any); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_any_obj, pyb_uart_any); -STATIC mp_obj_t pyb_uart_sendbreak(mp_obj_t self_in) { +static mp_obj_t pyb_uart_sendbreak(mp_obj_t self_in) { pyb_uart_obj_t *self = self_in; uart_check_init(self); // send a break signal for at least 2 complete frames @@ -524,10 +524,10 @@ STATIC mp_obj_t pyb_uart_sendbreak(mp_obj_t self_in) { MAP_UARTBreakCtl(self->reg, false); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_sendbreak_obj, pyb_uart_sendbreak); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_sendbreak_obj, pyb_uart_sendbreak); /// \method irq(trigger, priority, handler, wake) -STATIC mp_obj_t pyb_uart_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_uart_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_arg_val_t args[mp_irq_INIT_NUM_ARGS]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mp_irq_INIT_NUM_ARGS, mp_irq_init_args, args); @@ -556,9 +556,9 @@ STATIC mp_obj_t pyb_uart_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t * invalid_args: mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value")); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_uart_irq_obj, 1, pyb_uart_irq); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_uart_irq_obj, 1, pyb_uart_irq); -STATIC mp_obj_t machine_uart_txdone(mp_obj_t self_in) { +static mp_obj_t machine_uart_txdone(mp_obj_t self_in) { pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); if (MAP_UARTBusy(self->reg) == false) { @@ -567,9 +567,9 @@ STATIC mp_obj_t machine_uart_txdone(mp_obj_t self_in) { return mp_const_false; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_txdone_obj, machine_uart_txdone); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_uart_txdone_obj, machine_uart_txdone); -STATIC const mp_rom_map_elem_t pyb_uart_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_uart_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_uart_init_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_uart_deinit_obj) }, @@ -592,9 +592,9 @@ STATIC const mp_rom_map_elem_t pyb_uart_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_RX_ANY), MP_ROM_INT(UART_TRIGGER_RX_ANY) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_uart_locals_dict, pyb_uart_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_uart_locals_dict, pyb_uart_locals_dict_table); -STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { +static mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { pyb_uart_obj_t *self = self_in; byte *buf = buf_in; uart_check_init(self); @@ -622,7 +622,7 @@ STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, i } } -STATIC mp_uint_t pyb_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { +static mp_uint_t pyb_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { pyb_uart_obj_t *self = self_in; const char *buf = buf_in; uart_check_init(self); @@ -634,7 +634,7 @@ STATIC mp_uint_t pyb_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t return size; } -STATIC mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) { +static mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) { pyb_uart_obj_t *self = self_in; mp_uint_t ret; uart_check_init(self); @@ -670,14 +670,14 @@ STATIC mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t a return ret; } -STATIC const mp_stream_p_t uart_stream_p = { +static const mp_stream_p_t uart_stream_p = { .read = pyb_uart_read, .write = pyb_uart_write, .ioctl = pyb_uart_ioctl, .is_text = false, }; -STATIC const mp_irq_methods_t uart_irq_methods = { +static const mp_irq_methods_t uart_irq_methods = { .init = pyb_uart_irq, .enable = uart_irq_enable, .disable = uart_irq_disable, diff --git a/ports/cc3200/mptask.c b/ports/cc3200/mptask.c index 83b5c091b80e3..656a8fb8721b1 100644 --- a/ports/cc3200/mptask.c +++ b/ports/cc3200/mptask.c @@ -80,10 +80,10 @@ /****************************************************************************** DECLARE PRIVATE FUNCTIONS ******************************************************************************/ -STATIC void mptask_pre_init(void); -STATIC void mptask_init_sflash_filesystem(void); -STATIC void mptask_enter_ap_mode(void); -STATIC void mptask_create_main_py(void); +static void mptask_pre_init(void); +static void mptask_init_sflash_filesystem(void); +static void mptask_enter_ap_mode(void); +static void mptask_create_main_py(void); /****************************************************************************** DECLARE PUBLIC DATA @@ -256,7 +256,7 @@ void TASK_MicroPython(void *pvParameters) { DEFINE PRIVATE FUNCTIONS ******************************************************************************/ __attribute__ ((section(".boot"))) -STATIC void mptask_pre_init(void) { +static void mptask_pre_init(void) { // this one only makes sense after a poweron reset pyb_rtc_pre_init(); @@ -288,7 +288,7 @@ STATIC void mptask_pre_init(void) { ASSERT(svTaskHandle != NULL); } -STATIC void mptask_init_sflash_filesystem(void) { +static void mptask_init_sflash_filesystem(void) { FILINFO fno; // Initialise the local flash filesystem. @@ -371,7 +371,7 @@ STATIC void mptask_init_sflash_filesystem(void) { } } -STATIC void mptask_enter_ap_mode(void) { +static void mptask_enter_ap_mode(void) { // append the mac only if it's not the first boot bool add_mac = !PRCMGetSpecialBit(PRCM_FIRST_BOOT_BIT); // enable simplelink in ap mode (use the MAC address to make the ssid unique) @@ -380,7 +380,7 @@ STATIC void mptask_enter_ap_mode(void) { MICROPY_PORT_WLAN_AP_CHANNEL, ANTENNA_TYPE_INTERNAL, add_mac); } -STATIC void mptask_create_main_py(void) { +static void mptask_create_main_py(void) { // create empty main.py FIL fp; f_open(&sflash_vfs_fat->fatfs, &fp, "/main.py", FA_WRITE | FA_CREATE_ALWAYS); diff --git a/ports/cc3200/mpthreadport.c b/ports/cc3200/mpthreadport.c index c3f5f38d061a6..6c3a581871411 100644 --- a/ports/cc3200/mpthreadport.c +++ b/ports/cc3200/mpthreadport.c @@ -46,9 +46,9 @@ typedef struct _mp_thread_t { } mp_thread_t; // the mutex controls access to the linked list -STATIC mp_thread_mutex_t thread_mutex; -STATIC mp_thread_t thread_entry0; -STATIC mp_thread_t *thread; // root pointer, handled bp mp_thread_gc_others +static mp_thread_mutex_t thread_mutex; +static mp_thread_t thread_entry0; +static mp_thread_t *thread; // root pointer, handled bp mp_thread_gc_others void mp_thread_init(void) { mp_thread_mutex_init(&thread_mutex); @@ -103,9 +103,9 @@ void mp_thread_start(void) { mp_thread_mutex_unlock(&thread_mutex); } -STATIC void *(*ext_thread_entry)(void *) = NULL; +static void *(*ext_thread_entry)(void *) = NULL; -STATIC void freertos_entry(void *arg) { +static void freertos_entry(void *arg) { if (ext_thread_entry) { ext_thread_entry(arg); } diff --git a/ports/cc3200/util/random.c b/ports/cc3200/util/random.c index f8e9cdf0cb21f..e6285c98eb76d 100644 --- a/ports/cc3200/util/random.c +++ b/ports/cc3200/util/random.c @@ -56,12 +56,12 @@ static uint32_t s_seed; /****************************************************************************** * LOCAL FUNCTION DECLARATIONS ******************************************************************************/ -STATIC uint32_t lfsr (uint32_t input); +static uint32_t lfsr (uint32_t input); /****************************************************************************** * PRIVATE FUNCTIONS ******************************************************************************/ -STATIC uint32_t lfsr (uint32_t input) { +static uint32_t lfsr (uint32_t input) { assert( input != 0 ); return (input >> 1) ^ (-(input & 0x01) & 0x00E10000); } @@ -69,7 +69,7 @@ STATIC uint32_t lfsr (uint32_t input) { /******************************************************************************/ // MicroPython bindings; -STATIC mp_obj_t machine_rng_get(void) { +static mp_obj_t machine_rng_get(void) { return mp_obj_new_int(rng_get()); } MP_DEFINE_CONST_FUN_OBJ_0(machine_rng_get_obj, machine_rng_get); diff --git a/ports/esp32/esp32_nvs.c b/ports/esp32/esp32_nvs.c index 0b3661918c771..daeec4c26913b 100644 --- a/ports/esp32/esp32_nvs.c +++ b/ports/esp32/esp32_nvs.c @@ -43,7 +43,7 @@ typedef struct _esp32_nvs_obj_t { } esp32_nvs_obj_t; // *esp32_nvs_new allocates a python NVS object given a handle to an esp-idf namespace C obj. -STATIC esp32_nvs_obj_t *esp32_nvs_new(nvs_handle_t namespace) { +static esp32_nvs_obj_t *esp32_nvs_new(nvs_handle_t namespace) { esp32_nvs_obj_t *self = mp_obj_malloc(esp32_nvs_obj_t, &esp32_nvs_type); self->namespace = namespace; return self; @@ -51,13 +51,13 @@ STATIC esp32_nvs_obj_t *esp32_nvs_new(nvs_handle_t namespace) { // esp32_nvs_print prints an NVS object, unfortunately it doesn't seem possible to extract the // namespace string or anything else from the opaque handle provided by esp-idf. -STATIC void esp32_nvs_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void esp32_nvs_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { // esp32_nvs_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, ""); } // esp32_nvs_make_new constructs a handle to an NVS namespace. -STATIC mp_obj_t esp32_nvs_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t esp32_nvs_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // Check args mp_arg_check_num(n_args, n_kw, 1, 1, false); @@ -69,27 +69,27 @@ STATIC mp_obj_t esp32_nvs_make_new(const mp_obj_type_t *type, size_t n_args, siz } // esp32_nvs_set_i32 sets a 32-bit integer value -STATIC mp_obj_t esp32_nvs_set_i32(mp_obj_t self_in, mp_obj_t key_in, mp_obj_t value_in) { +static mp_obj_t esp32_nvs_set_i32(mp_obj_t self_in, mp_obj_t key_in, mp_obj_t value_in) { esp32_nvs_obj_t *self = MP_OBJ_TO_PTR(self_in); const char *key = mp_obj_str_get_str(key_in); int32_t value = mp_obj_get_int(value_in); check_esp_err(nvs_set_i32(self->namespace, key, value)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp32_nvs_set_i32_obj, esp32_nvs_set_i32); +static MP_DEFINE_CONST_FUN_OBJ_3(esp32_nvs_set_i32_obj, esp32_nvs_set_i32); // esp32_nvs_get_i32 reads a 32-bit integer value -STATIC mp_obj_t esp32_nvs_get_i32(mp_obj_t self_in, mp_obj_t key_in) { +static mp_obj_t esp32_nvs_get_i32(mp_obj_t self_in, mp_obj_t key_in) { esp32_nvs_obj_t *self = MP_OBJ_TO_PTR(self_in); const char *key = mp_obj_str_get_str(key_in); int32_t value; check_esp_err(nvs_get_i32(self->namespace, key, &value)); return mp_obj_new_int(value); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_nvs_get_i32_obj, esp32_nvs_get_i32); +static MP_DEFINE_CONST_FUN_OBJ_2(esp32_nvs_get_i32_obj, esp32_nvs_get_i32); // esp32_nvs_set_blob writes a buffer object into a binary blob value. -STATIC mp_obj_t esp32_nvs_set_blob(mp_obj_t self_in, mp_obj_t key_in, mp_obj_t value_in) { +static mp_obj_t esp32_nvs_set_blob(mp_obj_t self_in, mp_obj_t key_in, mp_obj_t value_in) { esp32_nvs_obj_t *self = MP_OBJ_TO_PTR(self_in); const char *key = mp_obj_str_get_str(key_in); mp_buffer_info_t value; @@ -97,10 +97,10 @@ STATIC mp_obj_t esp32_nvs_set_blob(mp_obj_t self_in, mp_obj_t key_in, mp_obj_t v check_esp_err(nvs_set_blob(self->namespace, key, value.buf, value.len)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp32_nvs_set_blob_obj, esp32_nvs_set_blob); +static MP_DEFINE_CONST_FUN_OBJ_3(esp32_nvs_set_blob_obj, esp32_nvs_set_blob); // esp32_nvs_get_blob reads a binary blob value into a bytearray. Returns actual length. -STATIC mp_obj_t esp32_nvs_get_blob(mp_obj_t self_in, mp_obj_t key_in, mp_obj_t value_in) { +static mp_obj_t esp32_nvs_get_blob(mp_obj_t self_in, mp_obj_t key_in, mp_obj_t value_in) { esp32_nvs_obj_t *self = MP_OBJ_TO_PTR(self_in); const char *key = mp_obj_str_get_str(key_in); // get buffer to be filled @@ -112,26 +112,26 @@ STATIC mp_obj_t esp32_nvs_get_blob(mp_obj_t self_in, mp_obj_t key_in, mp_obj_t v check_esp_err(nvs_get_blob(self->namespace, key, value.buf, &length)); return MP_OBJ_NEW_SMALL_INT(length); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp32_nvs_get_blob_obj, esp32_nvs_get_blob); +static MP_DEFINE_CONST_FUN_OBJ_3(esp32_nvs_get_blob_obj, esp32_nvs_get_blob); // esp32_nvs_erase_key erases one key. -STATIC mp_obj_t esp32_nvs_erase_key(mp_obj_t self_in, mp_obj_t key_in) { +static mp_obj_t esp32_nvs_erase_key(mp_obj_t self_in, mp_obj_t key_in) { esp32_nvs_obj_t *self = MP_OBJ_TO_PTR(self_in); const char *key = mp_obj_str_get_str(key_in); check_esp_err(nvs_erase_key(self->namespace, key)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_nvs_erase_key_obj, esp32_nvs_erase_key); +static MP_DEFINE_CONST_FUN_OBJ_2(esp32_nvs_erase_key_obj, esp32_nvs_erase_key); // esp32_nvs_commit commits any changes to flash. -STATIC mp_obj_t esp32_nvs_commit(mp_obj_t self_in) { +static mp_obj_t esp32_nvs_commit(mp_obj_t self_in) { esp32_nvs_obj_t *self = MP_OBJ_TO_PTR(self_in); check_esp_err(nvs_commit(self->namespace)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_nvs_commit_obj, esp32_nvs_commit); +static MP_DEFINE_CONST_FUN_OBJ_1(esp32_nvs_commit_obj, esp32_nvs_commit); -STATIC const mp_rom_map_elem_t esp32_nvs_locals_dict_table[] = { +static const mp_rom_map_elem_t esp32_nvs_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_get_i32), MP_ROM_PTR(&esp32_nvs_get_i32_obj) }, { MP_ROM_QSTR(MP_QSTR_set_i32), MP_ROM_PTR(&esp32_nvs_set_i32_obj) }, { MP_ROM_QSTR(MP_QSTR_get_blob), MP_ROM_PTR(&esp32_nvs_get_blob_obj) }, @@ -139,7 +139,7 @@ STATIC const mp_rom_map_elem_t esp32_nvs_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_erase_key), MP_ROM_PTR(&esp32_nvs_erase_key_obj) }, { MP_ROM_QSTR(MP_QSTR_commit), MP_ROM_PTR(&esp32_nvs_commit_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(esp32_nvs_locals_dict, esp32_nvs_locals_dict_table); +static MP_DEFINE_CONST_DICT(esp32_nvs_locals_dict, esp32_nvs_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( esp32_nvs_type, diff --git a/ports/esp32/esp32_partition.c b/ports/esp32/esp32_partition.c index 3bca3b52731d8..e5d48096204b8 100644 --- a/ports/esp32/esp32_partition.c +++ b/ports/esp32/esp32_partition.c @@ -53,7 +53,7 @@ typedef struct _esp32_partition_obj_t { uint16_t block_size; } esp32_partition_obj_t; -STATIC esp32_partition_obj_t *esp32_partition_new(const esp_partition_t *part, uint16_t block_size) { +static esp32_partition_obj_t *esp32_partition_new(const esp_partition_t *part, uint16_t block_size) { if (part == NULL) { mp_raise_OSError(MP_ENOENT); } @@ -68,7 +68,7 @@ STATIC esp32_partition_obj_t *esp32_partition_new(const esp_partition_t *part, u return self; } -STATIC void esp32_partition_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void esp32_partition_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { esp32_partition_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", self->part->type, self->part->subtype, @@ -77,7 +77,7 @@ STATIC void esp32_partition_print(const mp_print_t *print, mp_obj_t self_in, mp_ ); } -STATIC mp_obj_t esp32_partition_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t esp32_partition_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // Check args mp_arg_check_num(n_args, n_kw, 1, 2, false); @@ -114,7 +114,7 @@ STATIC mp_obj_t esp32_partition_make_new(const mp_obj_type_t *type, size_t n_arg return MP_OBJ_FROM_PTR(esp32_partition_new(part, block_size)); } -STATIC mp_obj_t esp32_partition_find(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t esp32_partition_find(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // Parse args enum { ARG_type, ARG_subtype, ARG_label, ARG_block_size }; static const mp_arg_t allowed_args[] = { @@ -146,10 +146,10 @@ STATIC mp_obj_t esp32_partition_find(size_t n_args, const mp_obj_t *pos_args, mp return list; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(esp32_partition_find_fun_obj, 0, esp32_partition_find); -STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(esp32_partition_find_obj, MP_ROM_PTR(&esp32_partition_find_fun_obj)); +static MP_DEFINE_CONST_FUN_OBJ_KW(esp32_partition_find_fun_obj, 0, esp32_partition_find); +static MP_DEFINE_CONST_STATICMETHOD_OBJ(esp32_partition_find_obj, MP_ROM_PTR(&esp32_partition_find_fun_obj)); -STATIC mp_obj_t esp32_partition_info(mp_obj_t self_in) { +static mp_obj_t esp32_partition_info(mp_obj_t self_in) { esp32_partition_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_t tuple[] = { MP_OBJ_NEW_SMALL_INT(self->part->type), @@ -161,9 +161,9 @@ STATIC mp_obj_t esp32_partition_info(mp_obj_t self_in) { }; return mp_obj_new_tuple(6, tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_partition_info_obj, esp32_partition_info); +static MP_DEFINE_CONST_FUN_OBJ_1(esp32_partition_info_obj, esp32_partition_info); -STATIC mp_obj_t esp32_partition_readblocks(size_t n_args, const mp_obj_t *args) { +static mp_obj_t esp32_partition_readblocks(size_t n_args, const mp_obj_t *args) { esp32_partition_obj_t *self = MP_OBJ_TO_PTR(args[0]); uint32_t offset = mp_obj_get_int(args[1]) * self->block_size; mp_buffer_info_t bufinfo; @@ -174,9 +174,9 @@ STATIC mp_obj_t esp32_partition_readblocks(size_t n_args, const mp_obj_t *args) check_esp_err(esp_partition_read(self->part, offset, bufinfo.buf, bufinfo.len)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp32_partition_readblocks_obj, 3, 4, esp32_partition_readblocks); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp32_partition_readblocks_obj, 3, 4, esp32_partition_readblocks); -STATIC mp_obj_t esp32_partition_writeblocks(size_t n_args, const mp_obj_t *args) { +static mp_obj_t esp32_partition_writeblocks(size_t n_args, const mp_obj_t *args) { esp32_partition_obj_t *self = MP_OBJ_TO_PTR(args[0]); uint32_t offset = mp_obj_get_int(args[1]) * self->block_size; mp_buffer_info_t bufinfo; @@ -213,9 +213,9 @@ STATIC mp_obj_t esp32_partition_writeblocks(size_t n_args, const mp_obj_t *args) check_esp_err(esp_partition_write(self->part, offset, bufinfo.buf, bufinfo.len)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp32_partition_writeblocks_obj, 3, 4, esp32_partition_writeblocks); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp32_partition_writeblocks_obj, 3, 4, esp32_partition_writeblocks); -STATIC mp_obj_t esp32_partition_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { +static mp_obj_t esp32_partition_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { esp32_partition_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t cmd = mp_obj_get_int(cmd_in); switch (cmd) { @@ -241,31 +241,31 @@ STATIC mp_obj_t esp32_partition_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_ return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp32_partition_ioctl_obj, esp32_partition_ioctl); +static MP_DEFINE_CONST_FUN_OBJ_3(esp32_partition_ioctl_obj, esp32_partition_ioctl); -STATIC mp_obj_t esp32_partition_set_boot(mp_obj_t self_in) { +static mp_obj_t esp32_partition_set_boot(mp_obj_t self_in) { esp32_partition_obj_t *self = MP_OBJ_TO_PTR(self_in); check_esp_err(esp_ota_set_boot_partition(self->part)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_partition_set_boot_obj, esp32_partition_set_boot); +static MP_DEFINE_CONST_FUN_OBJ_1(esp32_partition_set_boot_obj, esp32_partition_set_boot); -STATIC mp_obj_t esp32_partition_get_next_update(mp_obj_t self_in) { +static mp_obj_t esp32_partition_get_next_update(mp_obj_t self_in) { esp32_partition_obj_t *self = MP_OBJ_TO_PTR(self_in); return MP_OBJ_FROM_PTR(esp32_partition_new(esp_ota_get_next_update_partition(self->part), NATIVE_BLOCK_SIZE_BYTES)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_partition_get_next_update_obj, esp32_partition_get_next_update); +static MP_DEFINE_CONST_FUN_OBJ_1(esp32_partition_get_next_update_obj, esp32_partition_get_next_update); -STATIC mp_obj_t esp32_partition_mark_app_valid_cancel_rollback(mp_obj_t cls_in) { +static mp_obj_t esp32_partition_mark_app_valid_cancel_rollback(mp_obj_t cls_in) { check_esp_err(esp_ota_mark_app_valid_cancel_rollback()); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_partition_mark_app_valid_cancel_rollback_fun_obj, +static MP_DEFINE_CONST_FUN_OBJ_1(esp32_partition_mark_app_valid_cancel_rollback_fun_obj, esp32_partition_mark_app_valid_cancel_rollback); -STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(esp32_partition_mark_app_valid_cancel_rollback_obj, +static MP_DEFINE_CONST_CLASSMETHOD_OBJ(esp32_partition_mark_app_valid_cancel_rollback_obj, MP_ROM_PTR(&esp32_partition_mark_app_valid_cancel_rollback_fun_obj)); -STATIC const mp_rom_map_elem_t esp32_partition_locals_dict_table[] = { +static const mp_rom_map_elem_t esp32_partition_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_find), MP_ROM_PTR(&esp32_partition_find_obj) }, { MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&esp32_partition_info_obj) }, @@ -282,7 +282,7 @@ STATIC const mp_rom_map_elem_t esp32_partition_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_TYPE_APP), MP_ROM_INT(ESP_PARTITION_TYPE_APP) }, { MP_ROM_QSTR(MP_QSTR_TYPE_DATA), MP_ROM_INT(ESP_PARTITION_TYPE_DATA) }, }; -STATIC MP_DEFINE_CONST_DICT(esp32_partition_locals_dict, esp32_partition_locals_dict_table); +static MP_DEFINE_CONST_DICT(esp32_partition_locals_dict, esp32_partition_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( esp32_partition_type, diff --git a/ports/esp32/esp32_rmt.c b/ports/esp32/esp32_rmt.c index 494ae48f46cfe..c765a9741bcaa 100644 --- a/ports/esp32/esp32_rmt.c +++ b/ports/esp32/esp32_rmt.c @@ -75,7 +75,7 @@ typedef struct _rmt_install_state_t { esp_err_t ret; } rmt_install_state_t; -STATIC void rmt_install_task(void *pvParameter) { +static void rmt_install_task(void *pvParameter) { rmt_install_state_t *state = pvParameter; state->ret = rmt_driver_install(state->channel_id, 0, 0); xSemaphoreGive(state->handle); @@ -107,7 +107,7 @@ esp_err_t rmt_driver_install_core1(uint8_t channel_id) { #endif -STATIC mp_obj_t esp32_rmt_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t esp32_rmt_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_id, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = -1} }, { MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, @@ -177,7 +177,7 @@ STATIC mp_obj_t esp32_rmt_make_new(const mp_obj_type_t *type, size_t n_args, siz return MP_OBJ_FROM_PTR(self); } -STATIC void esp32_rmt_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void esp32_rmt_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { esp32_rmt_obj_t *self = MP_OBJ_TO_PTR(self_in); if (self->pin != -1) { bool idle_output_en; @@ -190,7 +190,7 @@ STATIC void esp32_rmt_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ } } -STATIC mp_obj_t esp32_rmt_deinit(mp_obj_t self_in) { +static mp_obj_t esp32_rmt_deinit(mp_obj_t self_in) { // fixme: check for valid channel. Return exception if error occurs. esp32_rmt_obj_t *self = MP_OBJ_TO_PTR(self_in); if (self->pin != -1) { // Check if channel has already been deinitialised. @@ -200,28 +200,28 @@ STATIC mp_obj_t esp32_rmt_deinit(mp_obj_t self_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_rmt_deinit_obj, esp32_rmt_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(esp32_rmt_deinit_obj, esp32_rmt_deinit); // Return the source frequency. // Currently only the APB clock (80MHz) can be used but it is possible other // clock sources will added in the future. -STATIC mp_obj_t esp32_rmt_source_freq() { +static mp_obj_t esp32_rmt_source_freq() { return mp_obj_new_int(APB_CLK_FREQ); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp32_rmt_source_freq_obj, esp32_rmt_source_freq); -STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(esp32_rmt_source_obj, MP_ROM_PTR(&esp32_rmt_source_freq_obj)); +static MP_DEFINE_CONST_FUN_OBJ_0(esp32_rmt_source_freq_obj, esp32_rmt_source_freq); +static MP_DEFINE_CONST_STATICMETHOD_OBJ(esp32_rmt_source_obj, MP_ROM_PTR(&esp32_rmt_source_freq_obj)); // Return the clock divider. -STATIC mp_obj_t esp32_rmt_clock_div(mp_obj_t self_in) { +static mp_obj_t esp32_rmt_clock_div(mp_obj_t self_in) { esp32_rmt_obj_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_int(self->clock_div); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_rmt_clock_div_obj, esp32_rmt_clock_div); +static MP_DEFINE_CONST_FUN_OBJ_1(esp32_rmt_clock_div_obj, esp32_rmt_clock_div); // Query whether the channel has finished sending pulses. Takes an optional // timeout (in milliseconds), returning true if the pulse stream has // completed or false if they are still transmitting (or timeout is reached). -STATIC mp_obj_t esp32_rmt_wait_done(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t esp32_rmt_wait_done(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_self, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, @@ -235,9 +235,9 @@ STATIC mp_obj_t esp32_rmt_wait_done(size_t n_args, const mp_obj_t *pos_args, mp_ esp_err_t err = rmt_wait_tx_done(self->channel_id, args[1].u_int / portTICK_PERIOD_MS); return err == ESP_OK ? mp_const_true : mp_const_false; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(esp32_rmt_wait_done_obj, 1, esp32_rmt_wait_done); +static MP_DEFINE_CONST_FUN_OBJ_KW(esp32_rmt_wait_done_obj, 1, esp32_rmt_wait_done); -STATIC mp_obj_t esp32_rmt_loop(mp_obj_t self_in, mp_obj_t loop) { +static mp_obj_t esp32_rmt_loop(mp_obj_t self_in, mp_obj_t loop) { esp32_rmt_obj_t *self = MP_OBJ_TO_PTR(self_in); self->loop_en = mp_obj_get_int(loop); if (!self->loop_en) { @@ -250,9 +250,9 @@ STATIC mp_obj_t esp32_rmt_loop(mp_obj_t self_in, mp_obj_t loop) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_rmt_loop_obj, esp32_rmt_loop); +static MP_DEFINE_CONST_FUN_OBJ_2(esp32_rmt_loop_obj, esp32_rmt_loop); -STATIC mp_obj_t esp32_rmt_write_pulses(size_t n_args, const mp_obj_t *args) { +static mp_obj_t esp32_rmt_write_pulses(size_t n_args, const mp_obj_t *args) { esp32_rmt_obj_t *self = MP_OBJ_TO_PTR(args[0]); mp_obj_t duration_obj = args[1]; mp_obj_t data_obj = n_args > 2 ? args[2] : mp_const_true; @@ -337,9 +337,9 @@ STATIC mp_obj_t esp32_rmt_write_pulses(size_t n_args, const mp_obj_t *args) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp32_rmt_write_pulses_obj, 2, 3, esp32_rmt_write_pulses); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp32_rmt_write_pulses_obj, 2, 3, esp32_rmt_write_pulses); -STATIC mp_obj_t esp32_rmt_bitstream_channel(size_t n_args, const mp_obj_t *args) { +static mp_obj_t esp32_rmt_bitstream_channel(size_t n_args, const mp_obj_t *args) { if (n_args > 0) { if (args[0] == mp_const_none) { esp32_rmt_bitstream_channel_id = -1; @@ -357,10 +357,10 @@ STATIC mp_obj_t esp32_rmt_bitstream_channel(size_t n_args, const mp_obj_t *args) return MP_OBJ_NEW_SMALL_INT(esp32_rmt_bitstream_channel_id); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp32_rmt_bitstream_channel_fun_obj, 0, 1, esp32_rmt_bitstream_channel); -STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(esp32_rmt_bitstream_channel_obj, MP_ROM_PTR(&esp32_rmt_bitstream_channel_fun_obj)); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp32_rmt_bitstream_channel_fun_obj, 0, 1, esp32_rmt_bitstream_channel); +static MP_DEFINE_CONST_STATICMETHOD_OBJ(esp32_rmt_bitstream_channel_obj, MP_ROM_PTR(&esp32_rmt_bitstream_channel_fun_obj)); -STATIC const mp_rom_map_elem_t esp32_rmt_locals_dict_table[] = { +static const mp_rom_map_elem_t esp32_rmt_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&esp32_rmt_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&esp32_rmt_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR_clock_div), MP_ROM_PTR(&esp32_rmt_clock_div_obj) }, @@ -377,7 +377,7 @@ STATIC const mp_rom_map_elem_t esp32_rmt_locals_dict_table[] = { // Constants { MP_ROM_QSTR(MP_QSTR_PULSE_MAX), MP_ROM_INT(32767) }, }; -STATIC MP_DEFINE_CONST_DICT(esp32_rmt_locals_dict, esp32_rmt_locals_dict_table); +static MP_DEFINE_CONST_DICT(esp32_rmt_locals_dict, esp32_rmt_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( esp32_rmt_type, diff --git a/ports/esp32/esp32_ulp.c b/ports/esp32/esp32_ulp.c index 97041c60bd6be..17d210952f465 100644 --- a/ports/esp32/esp32_ulp.c +++ b/ports/esp32/esp32_ulp.c @@ -43,9 +43,9 @@ typedef struct _esp32_ulp_obj_t { const mp_obj_type_t esp32_ulp_type; // singleton ULP object -STATIC const esp32_ulp_obj_t esp32_ulp_obj = {{&esp32_ulp_type}}; +static const esp32_ulp_obj_t esp32_ulp_obj = {{&esp32_ulp_type}}; -STATIC mp_obj_t esp32_ulp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t esp32_ulp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 0, 0, false); @@ -53,7 +53,7 @@ STATIC mp_obj_t esp32_ulp_make_new(const mp_obj_type_t *type, size_t n_args, siz return (mp_obj_t)&esp32_ulp_obj; } -STATIC mp_obj_t esp32_ulp_set_wakeup_period(mp_obj_t self_in, mp_obj_t period_index_in, mp_obj_t period_us_in) { +static mp_obj_t esp32_ulp_set_wakeup_period(mp_obj_t self_in, mp_obj_t period_index_in, mp_obj_t period_us_in) { mp_uint_t period_index = mp_obj_get_int(period_index_in); mp_uint_t period_us = mp_obj_get_int(period_us_in); int _errno = ulp_set_wakeup_period(period_index, period_us); @@ -62,9 +62,9 @@ STATIC mp_obj_t esp32_ulp_set_wakeup_period(mp_obj_t self_in, mp_obj_t period_in } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp32_ulp_set_wakeup_period_obj, esp32_ulp_set_wakeup_period); +static MP_DEFINE_CONST_FUN_OBJ_3(esp32_ulp_set_wakeup_period_obj, esp32_ulp_set_wakeup_period); -STATIC mp_obj_t esp32_ulp_load_binary(mp_obj_t self_in, mp_obj_t load_addr_in, mp_obj_t program_binary_in) { +static mp_obj_t esp32_ulp_load_binary(mp_obj_t self_in, mp_obj_t load_addr_in, mp_obj_t program_binary_in) { mp_uint_t load_addr = mp_obj_get_int(load_addr_in); mp_buffer_info_t bufinfo; @@ -76,9 +76,9 @@ STATIC mp_obj_t esp32_ulp_load_binary(mp_obj_t self_in, mp_obj_t load_addr_in, m } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp32_ulp_load_binary_obj, esp32_ulp_load_binary); +static MP_DEFINE_CONST_FUN_OBJ_3(esp32_ulp_load_binary_obj, esp32_ulp_load_binary); -STATIC mp_obj_t esp32_ulp_run(mp_obj_t self_in, mp_obj_t entry_point_in) { +static mp_obj_t esp32_ulp_run(mp_obj_t self_in, mp_obj_t entry_point_in) { mp_uint_t entry_point = mp_obj_get_int(entry_point_in); int _errno = ulp_run(entry_point / sizeof(uint32_t)); if (_errno != ESP_OK) { @@ -86,15 +86,15 @@ STATIC mp_obj_t esp32_ulp_run(mp_obj_t self_in, mp_obj_t entry_point_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_ulp_run_obj, esp32_ulp_run); +static MP_DEFINE_CONST_FUN_OBJ_2(esp32_ulp_run_obj, esp32_ulp_run); -STATIC const mp_rom_map_elem_t esp32_ulp_locals_dict_table[] = { +static const mp_rom_map_elem_t esp32_ulp_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_set_wakeup_period), MP_ROM_PTR(&esp32_ulp_set_wakeup_period_obj) }, { MP_ROM_QSTR(MP_QSTR_load_binary), MP_ROM_PTR(&esp32_ulp_load_binary_obj) }, { MP_ROM_QSTR(MP_QSTR_run), MP_ROM_PTR(&esp32_ulp_run_obj) }, { MP_ROM_QSTR(MP_QSTR_RESERVE_MEM), MP_ROM_INT(CONFIG_ULP_COPROC_RESERVE_MEM) }, }; -STATIC MP_DEFINE_CONST_DICT(esp32_ulp_locals_dict, esp32_ulp_locals_dict_table); +static MP_DEFINE_CONST_DICT(esp32_ulp_locals_dict, esp32_ulp_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( esp32_ulp_type, diff --git a/ports/esp32/machine_adc.c b/ports/esp32/machine_adc.c index b5233e4ddadd8..0ac9f5d266d9c 100644 --- a/ports/esp32/machine_adc.c +++ b/ports/esp32/machine_adc.c @@ -67,7 +67,7 @@ MICROPY_PY_MACHINE_ADC_CLASS_CONSTANTS_WIDTH_12 \ MICROPY_PY_MACHINE_ADC_CLASS_CONSTANTS_WIDTH_13 \ -STATIC const machine_adc_obj_t madc_obj[] = { +static const machine_adc_obj_t madc_obj[] = { #if CONFIG_IDF_TARGET_ESP32 {{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_0, GPIO_NUM_36}, {{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_1, GPIO_NUM_37}, @@ -121,7 +121,7 @@ STATIC const machine_adc_obj_t madc_obj[] = { // These values are initialised to 0, which means the corresponding ADC channel is not initialised. // The madc_atten_get/madc_atten_set functions store (atten+1) here so that the uninitialised state // can be distinguished from the initialised state. -STATIC uint8_t madc_obj_atten[MP_ARRAY_SIZE(madc_obj)]; +static uint8_t madc_obj_atten[MP_ARRAY_SIZE(madc_obj)]; static inline adc_atten_t madc_atten_get(const machine_adc_obj_t *self) { uint8_t value = madc_obj_atten[self - &madc_obj[0]]; @@ -142,12 +142,12 @@ const machine_adc_obj_t *madc_search_helper(machine_adc_block_obj_t *block, adc_ return NULL; } -STATIC void mp_machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { const machine_adc_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "ADC(Pin(%u), atten=%u)", self->gpio_id, madc_atten_get(self)); } -STATIC void madc_atten_helper(const machine_adc_obj_t *self, mp_int_t atten) { +static void madc_atten_helper(const machine_adc_obj_t *self, mp_int_t atten) { esp_err_t err; if (self->block->unit_id == ADC_UNIT_1) { err = adc1_config_channel_atten(self->channel_id, atten); @@ -180,11 +180,11 @@ void madc_init_helper(const machine_adc_obj_t *self, size_t n_pos_args, const mp } } -STATIC void mp_machine_adc_init_helper(machine_adc_obj_t *self, size_t n_pos_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void mp_machine_adc_init_helper(machine_adc_obj_t *self, size_t n_pos_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { madc_init_helper(self, n_pos_args, pos_args, kw_args); } -STATIC mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_pos_args, size_t n_kw_args, const mp_obj_t *args) { +static mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_pos_args, size_t n_kw_args, const mp_obj_t *args) { mp_arg_check_num(n_pos_args, n_kw_args, 1, MP_OBJ_FUN_ARGS_MAX, true); gpio_num_t gpio_id = machine_pin_get_id(args[0]); const machine_adc_obj_t *self = madc_search_helper(NULL, -1, gpio_id); @@ -203,16 +203,16 @@ STATIC mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_pos_ return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t mp_machine_adc_block(machine_adc_obj_t *self) { +static mp_obj_t mp_machine_adc_block(machine_adc_obj_t *self) { return MP_OBJ_FROM_PTR(self->block); } -STATIC mp_int_t mp_machine_adc_read(machine_adc_obj_t *self) { +static mp_int_t mp_machine_adc_read(machine_adc_obj_t *self) { mp_int_t raw = madcblock_read_helper(self->block, self->channel_id); return raw; } -STATIC mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) { +static mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) { mp_uint_t raw = madcblock_read_helper(self->block, self->channel_id); // Scale raw reading to 16 bit value using a Taylor expansion (for 8 <= bits <= 16) mp_int_t bits = self->block->bits; @@ -220,15 +220,15 @@ STATIC mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) { return u16; } -STATIC mp_int_t mp_machine_adc_read_uv(machine_adc_obj_t *self) { +static mp_int_t mp_machine_adc_read_uv(machine_adc_obj_t *self) { adc_atten_t atten = madc_atten_get(self); return madcblock_read_uv_helper(self->block, self->channel_id, atten); } -STATIC void mp_machine_adc_atten_set(machine_adc_obj_t *self, mp_int_t atten) { +static void mp_machine_adc_atten_set(machine_adc_obj_t *self, mp_int_t atten) { madc_atten_helper(self, atten); } -STATIC void mp_machine_adc_width_set(machine_adc_obj_t *self, mp_int_t width) { +static void mp_machine_adc_width_set(machine_adc_obj_t *self, mp_int_t width) { madcblock_bits_helper(self->block, width); } diff --git a/ports/esp32/machine_adc_block.c b/ports/esp32/machine_adc_block.c index f2975ff2f21d2..c610233900569 100644 --- a/ports/esp32/machine_adc_block.c +++ b/ports/esp32/machine_adc_block.c @@ -41,11 +41,11 @@ machine_adc_block_obj_t madcblock_obj[] = { #endif }; -STATIC void mp_machine_adc_block_print(const mp_print_t *print, machine_adc_block_obj_t *self) { +static void mp_machine_adc_block_print(const mp_print_t *print, machine_adc_block_obj_t *self) { mp_printf(print, "ADCBlock(%u, bits=%u)", self->unit_id, self->bits); } -STATIC void mp_machine_adc_block_bits_set(machine_adc_block_obj_t *self, mp_int_t bits) { +static void mp_machine_adc_block_bits_set(machine_adc_block_obj_t *self, mp_int_t bits) { if (bits != -1) { madcblock_bits_helper(self, bits); } else if (self->width == -1) { @@ -53,7 +53,7 @@ STATIC void mp_machine_adc_block_bits_set(machine_adc_block_obj_t *self, mp_int_ } } -STATIC machine_adc_block_obj_t *mp_machine_adc_block_get(mp_int_t unit) { +static machine_adc_block_obj_t *mp_machine_adc_block_get(mp_int_t unit) { for (int i = 0; i < MP_ARRAY_SIZE(madcblock_obj); i++) { if (unit == madcblock_obj[i].unit_id) { return &madcblock_obj[i]; @@ -62,7 +62,7 @@ STATIC machine_adc_block_obj_t *mp_machine_adc_block_get(mp_int_t unit) { return NULL; } -STATIC machine_adc_obj_t *mp_machine_adc_block_connect(machine_adc_block_obj_t *self, mp_int_t channel_id, mp_hal_pin_obj_t gpio_id, mp_map_t *kw_args) { +static machine_adc_obj_t *mp_machine_adc_block_connect(machine_adc_block_obj_t *self, mp_int_t channel_id, mp_hal_pin_obj_t gpio_id, mp_map_t *kw_args) { const machine_adc_obj_t *adc = madc_search_helper(self, channel_id, gpio_id); if (adc == NULL) { return NULL; diff --git a/ports/esp32/machine_bitstream.c b/ports/esp32/machine_bitstream.c index 87a5ae53cfe54..ceb1e6ad14291 100644 --- a/ports/esp32/machine_bitstream.c +++ b/ports/esp32/machine_bitstream.c @@ -40,7 +40,7 @@ #define NS_TICKS_OVERHEAD (6) // This is a translation of the cycle counter implementation in ports/stm32/machine_bitstream.c. -STATIC void IRAM_ATTR machine_bitstream_high_low_bitbang(mp_hal_pin_obj_t pin, uint32_t *timing_ns, const uint8_t *buf, size_t len) { +static void IRAM_ATTR machine_bitstream_high_low_bitbang(mp_hal_pin_obj_t pin, uint32_t *timing_ns, const uint8_t *buf, size_t len) { uint32_t pin_mask, gpio_reg_set, gpio_reg_clear; #if !CONFIG_IDF_TARGET_ESP32C3 if (pin >= 32) { @@ -97,13 +97,13 @@ STATIC void IRAM_ATTR machine_bitstream_high_low_bitbang(mp_hal_pin_obj_t pin, u // Logical 0 and 1 values (encoded as a rmt_item32_t). // The duration fields will be set later. -STATIC rmt_item32_t bitstream_high_low_0 = {{{ 0, 1, 0, 0 }}}; -STATIC rmt_item32_t bitstream_high_low_1 = {{{ 0, 1, 0, 0 }}}; +static rmt_item32_t bitstream_high_low_0 = {{{ 0, 1, 0, 0 }}}; +static rmt_item32_t bitstream_high_low_1 = {{{ 0, 1, 0, 0 }}}; // See https://github.com/espressif/esp-idf/blob/master/examples/common_components/led_strip/led_strip_rmt_ws2812.c // This is called automatically by the IDF during rmt_write_sample in order to // convert the byte stream to rmt_item32_t's. -STATIC void IRAM_ATTR bitstream_high_low_rmt_adapter(const void *src, rmt_item32_t *dest, size_t src_size, size_t wanted_num, size_t *translated_size, size_t *item_num) { +static void IRAM_ATTR bitstream_high_low_rmt_adapter(const void *src, rmt_item32_t *dest, size_t src_size, size_t wanted_num, size_t *translated_size, size_t *item_num) { if (src == NULL || dest == NULL) { *translated_size = 0; *item_num = 0; @@ -134,7 +134,7 @@ STATIC void IRAM_ATTR bitstream_high_low_rmt_adapter(const void *src, rmt_item32 } // Use the reserved RMT channel to stream high/low data on the specified pin. -STATIC void machine_bitstream_high_low_rmt(mp_hal_pin_obj_t pin, uint32_t *timing_ns, const uint8_t *buf, size_t len, uint8_t channel_id) { +static void machine_bitstream_high_low_rmt(mp_hal_pin_obj_t pin, uint32_t *timing_ns, const uint8_t *buf, size_t len, uint8_t channel_id) { rmt_config_t config = RMT_DEFAULT_CONFIG_TX(pin, channel_id); // Use 40MHz clock (although 2MHz would probably be sufficient). diff --git a/ports/esp32/machine_dac.c b/ports/esp32/machine_dac.c index 34f51cc521d94..3d1d2df80818a 100644 --- a/ports/esp32/machine_dac.c +++ b/ports/esp32/machine_dac.c @@ -51,7 +51,7 @@ typedef struct _mdac_obj_t { #endif } mdac_obj_t; -STATIC mdac_obj_t mdac_obj[] = { +static mdac_obj_t mdac_obj[] = { #if CONFIG_IDF_TARGET_ESP32 {{&machine_dac_type}, GPIO_NUM_25, DAC_CHAN_0}, {{&machine_dac_type}, GPIO_NUM_26, DAC_CHAN_1}, @@ -61,7 +61,7 @@ STATIC mdac_obj_t mdac_obj[] = { #endif }; -STATIC mp_obj_t mdac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, +static mp_obj_t mdac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 1, true); @@ -94,12 +94,12 @@ STATIC mp_obj_t mdac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n #endif } -STATIC void mdac_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mdac_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { mdac_obj_t *self = self_in; mp_printf(print, "DAC(Pin(%u))", self->gpio_id); } -STATIC mp_obj_t mdac_write(mp_obj_t self_in, mp_obj_t value_in) { +static mp_obj_t mdac_write(mp_obj_t self_in, mp_obj_t value_in) { mdac_obj_t *self = self_in; int value = mp_obj_get_int(value_in); if (value < 0 || value > 255) { @@ -119,11 +119,11 @@ STATIC mp_obj_t mdac_write(mp_obj_t self_in, mp_obj_t value_in) { } MP_DEFINE_CONST_FUN_OBJ_2(mdac_write_obj, mdac_write); -STATIC const mp_rom_map_elem_t mdac_locals_dict_table[] = { +static const mp_rom_map_elem_t mdac_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mdac_write_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mdac_locals_dict, mdac_locals_dict_table); +static MP_DEFINE_CONST_DICT(mdac_locals_dict, mdac_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( machine_dac_type, diff --git a/ports/esp32/machine_hw_spi.c b/ports/esp32/machine_hw_spi.c index 06e9ec3c8291c..a0531b95f8eaa 100644 --- a/ports/esp32/machine_hw_spi.c +++ b/ports/esp32/machine_hw_spi.c @@ -111,7 +111,7 @@ typedef struct _machine_hw_spi_obj_t { } machine_hw_spi_obj_t; // Default pin mappings for the hardware SPI instances -STATIC const machine_hw_spi_default_pins_t machine_hw_spi_default_pins[MICROPY_HW_SPI_MAX] = { +static const machine_hw_spi_default_pins_t machine_hw_spi_default_pins[MICROPY_HW_SPI_MAX] = { { .pins = { .sck = MICROPY_HW_SPI1_SCK, .mosi = MICROPY_HW_SPI1_MOSI, .miso = MICROPY_HW_SPI1_MISO }}, #ifdef MICROPY_HW_SPI2_SCK { .pins = { .sck = MICROPY_HW_SPI2_SCK, .mosi = MICROPY_HW_SPI2_MOSI, .miso = MICROPY_HW_SPI2_MISO }}, @@ -133,9 +133,9 @@ static const mp_arg_t spi_allowed_args[] = { }; // Static objects mapping to SPI2 (and SPI3 if available) hardware peripherals. -STATIC machine_hw_spi_obj_t machine_hw_spi_obj[MICROPY_HW_SPI_MAX]; +static machine_hw_spi_obj_t machine_hw_spi_obj[MICROPY_HW_SPI_MAX]; -STATIC void machine_hw_spi_deinit_internal(machine_hw_spi_obj_t *self) { +static void machine_hw_spi_deinit_internal(machine_hw_spi_obj_t *self) { switch (spi_bus_remove_device(self->spi)) { case ESP_ERR_INVALID_ARG: mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("invalid configuration")); @@ -167,7 +167,7 @@ STATIC void machine_hw_spi_deinit_internal(machine_hw_spi_obj_t *self) { } } -STATIC void machine_hw_spi_init_internal(machine_hw_spi_obj_t *self, mp_arg_val_t args[]) { +static void machine_hw_spi_init_internal(machine_hw_spi_obj_t *self, mp_arg_val_t args[]) { // if we're not initialized, then we're // implicitly 'changed', since this is the init routine @@ -292,7 +292,7 @@ STATIC void machine_hw_spi_init_internal(machine_hw_spi_obj_t *self, mp_arg_val_ self->state = MACHINE_HW_SPI_STATE_INIT; } -STATIC void machine_hw_spi_deinit(mp_obj_base_t *self_in) { +static void machine_hw_spi_deinit(mp_obj_base_t *self_in) { machine_hw_spi_obj_t *self = (machine_hw_spi_obj_t *)self_in; if (self->state == MACHINE_HW_SPI_STATE_INIT) { self->state = MACHINE_HW_SPI_STATE_DEINIT; @@ -300,7 +300,7 @@ STATIC void machine_hw_spi_deinit(mp_obj_base_t *self_in) { } } -STATIC mp_uint_t gcd(mp_uint_t x, mp_uint_t y) { +static mp_uint_t gcd(mp_uint_t x, mp_uint_t y) { while (x != y) { if (x > y) { x -= y; @@ -311,7 +311,7 @@ STATIC mp_uint_t gcd(mp_uint_t x, mp_uint_t y) { return x; } -STATIC void machine_hw_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) { +static void machine_hw_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) { machine_hw_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); if (self->state == MACHINE_HW_SPI_STATE_DEINIT) { @@ -389,7 +389,7 @@ STATIC void machine_hw_spi_transfer(mp_obj_base_t *self_in, size_t len, const ui /******************************************************************************/ // MicroPython bindings for hw_spi -STATIC void machine_hw_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_hw_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_hw_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "SPI(id=%u, baudrate=%u, polarity=%u, phase=%u, bits=%u, firstbit=%u, sck=%d, mosi=%d, miso=%d)", self->host, self->baudrate, self->polarity, @@ -401,7 +401,7 @@ STATIC void machine_hw_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_p // into all the u_int fields. // The behavior is slightly different for a new call vs an init method on an existing object. // Unspecified arguments for new will use defaults, for init they keep the existing value. -STATIC void machine_hw_spi_argcheck(mp_arg_val_t args[], const machine_hw_spi_default_pins_t *default_pins) { +static void machine_hw_spi_argcheck(mp_arg_val_t args[], const machine_hw_spi_default_pins_t *default_pins) { // A non-NULL default_pins argument will trigger the "use default" behavior. // Replace pin args with default/current values for new vs init call, respectively for (int i = ARG_sck; i <= ARG_miso; i++) { @@ -415,7 +415,7 @@ STATIC void machine_hw_spi_argcheck(mp_arg_val_t args[], const machine_hw_spi_de } } -STATIC void machine_hw_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void machine_hw_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { machine_hw_spi_obj_t *self = (machine_hw_spi_obj_t *)self_in; mp_arg_val_t args[MP_ARRAY_SIZE(spi_allowed_args)]; @@ -465,7 +465,7 @@ spi_host_device_t machine_hw_spi_get_host(mp_obj_t in) { return self->host; } -STATIC const mp_machine_spi_p_t machine_hw_spi_p = { +static const mp_machine_spi_p_t machine_hw_spi_p = { .init = machine_hw_spi_init, .deinit = machine_hw_spi_deinit, .transfer = machine_hw_spi_transfer, diff --git a/ports/esp32/machine_i2c.c b/ports/esp32/machine_i2c.c index f4cfa58166e06..fe42d2e8c27cc 100755 --- a/ports/esp32/machine_i2c.c +++ b/ports/esp32/machine_i2c.c @@ -66,9 +66,9 @@ typedef struct _machine_hw_i2c_obj_t { gpio_num_t sda : 8; } machine_hw_i2c_obj_t; -STATIC machine_hw_i2c_obj_t machine_hw_i2c_obj[I2C_NUM_MAX]; +static machine_hw_i2c_obj_t machine_hw_i2c_obj[I2C_NUM_MAX]; -STATIC void machine_hw_i2c_init(machine_hw_i2c_obj_t *self, uint32_t freq, uint32_t timeout_us, bool first_init) { +static void machine_hw_i2c_init(machine_hw_i2c_obj_t *self, uint32_t freq, uint32_t timeout_us, bool first_init) { if (!first_init) { i2c_driver_delete(self->port); } @@ -137,7 +137,7 @@ int machine_hw_i2c_transfer(mp_obj_base_t *self_in, uint16_t addr, size_t n, mp_ /******************************************************************************/ // MicroPython bindings for machine API -STATIC void machine_hw_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_hw_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_hw_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in); int h, l; i2c_get_period(self->port, &h, &l); @@ -198,7 +198,7 @@ mp_obj_t machine_hw_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_ return MP_OBJ_FROM_PTR(self); } -STATIC const mp_machine_i2c_p_t machine_hw_i2c_p = { +static const mp_machine_i2c_p_t machine_hw_i2c_p = { .transfer_supports_write1 = true, .transfer = machine_hw_i2c_transfer, }; diff --git a/ports/esp32/machine_i2s.c b/ports/esp32/machine_i2s.c index 3b7bcfeffc673..574125ad6a0d9 100644 --- a/ports/esp32/machine_i2s.c +++ b/ports/esp32/machine_i2s.c @@ -81,12 +81,12 @@ typedef struct _machine_i2s_obj_t { TaskHandle_t non_blocking_mode_task; } machine_i2s_obj_t; -STATIC mp_obj_t machine_i2s_deinit(mp_obj_t self_in); +static mp_obj_t machine_i2s_deinit(mp_obj_t self_in); // The frame map is used with the readinto() method to transform the audio sample data coming // from DMA memory (32-bit stereo, with the L and R channels reversed) to the format specified // in the I2S constructor. e.g. 16-bit mono -STATIC const int8_t i2s_frame_map[NUM_I2S_USER_FORMATS][I2S_RX_FRAME_SIZE_IN_BYTES] = { +static const int8_t i2s_frame_map[NUM_I2S_USER_FORMATS][I2S_RX_FRAME_SIZE_IN_BYTES] = { { 6, 7, -1, -1, -1, -1, -1, -1 }, // Mono, 16-bits { 4, 5, 6, 7, -1, -1, -1, -1 }, // Mono, 32-bits { 6, 7, 2, 3, -1, -1, -1, -1 }, // Stereo, 16-bits @@ -122,7 +122,7 @@ void machine_i2s_init0() { // samples in appbuf are in little endian format: // 0x77 is the most significant byte of the 32-bit sample // 0x44 is the least significant byte of the 32-bit sample -STATIC void swap_32_bit_stereo_channels(mp_buffer_info_t *bufinfo) { +static void swap_32_bit_stereo_channels(mp_buffer_info_t *bufinfo) { int32_t swap_sample; int32_t *sample = bufinfo->buf; uint32_t num_samples = bufinfo->len / 4; @@ -133,7 +133,7 @@ STATIC void swap_32_bit_stereo_channels(mp_buffer_info_t *bufinfo) { } } -STATIC int8_t get_frame_mapping_index(i2s_bits_per_sample_t bits, format_t format) { +static int8_t get_frame_mapping_index(i2s_bits_per_sample_t bits, format_t format) { if (format == MONO) { if (bits == I2S_BITS_PER_SAMPLE_16BIT) { return 0; @@ -149,7 +149,7 @@ STATIC int8_t get_frame_mapping_index(i2s_bits_per_sample_t bits, format_t forma } } -STATIC i2s_bits_per_sample_t get_dma_bits(uint8_t mode, i2s_bits_per_sample_t bits) { +static i2s_bits_per_sample_t get_dma_bits(uint8_t mode, i2s_bits_per_sample_t bits) { if (mode == (I2S_MODE_MASTER | I2S_MODE_TX)) { return bits; } else { // Master Rx @@ -158,7 +158,7 @@ STATIC i2s_bits_per_sample_t get_dma_bits(uint8_t mode, i2s_bits_per_sample_t bi } } -STATIC i2s_channel_fmt_t get_dma_format(uint8_t mode, format_t format) { +static i2s_channel_fmt_t get_dma_format(uint8_t mode, format_t format) { if (mode == (I2S_MODE_MASTER | I2S_MODE_TX)) { if (format == MONO) { return I2S_CHANNEL_FMT_ONLY_LEFT; @@ -171,7 +171,7 @@ STATIC i2s_channel_fmt_t get_dma_format(uint8_t mode, format_t format) { } } -STATIC uint32_t get_dma_buf_count(uint8_t mode, i2s_bits_per_sample_t bits, format_t format, int32_t ibuf) { +static uint32_t get_dma_buf_count(uint8_t mode, i2s_bits_per_sample_t bits, format_t format, int32_t ibuf) { // calculate how many DMA buffers need to be allocated uint32_t dma_frame_size_in_bytes = (get_dma_bits(mode, bits) / 8) * (get_dma_format(mode, format) == I2S_CHANNEL_FMT_RIGHT_LEFT ? 2: 1); @@ -181,7 +181,7 @@ STATIC uint32_t get_dma_buf_count(uint8_t mode, i2s_bits_per_sample_t bits, form return dma_buf_count; } -STATIC uint32_t fill_appbuf_from_dma(machine_i2s_obj_t *self, mp_buffer_info_t *appbuf) { +static uint32_t fill_appbuf_from_dma(machine_i2s_obj_t *self, mp_buffer_info_t *appbuf) { // copy audio samples from DMA memory to the app buffer // audio samples are read from DMA memory in chunks @@ -256,7 +256,7 @@ STATIC uint32_t fill_appbuf_from_dma(machine_i2s_obj_t *self, mp_buffer_info_t * return a_index; } -STATIC size_t copy_appbuf_to_dma(machine_i2s_obj_t *self, mp_buffer_info_t *appbuf) { +static size_t copy_appbuf_to_dma(machine_i2s_obj_t *self, mp_buffer_info_t *appbuf) { if ((self->bits == I2S_BITS_PER_SAMPLE_32BIT) && (self->format == STEREO)) { swap_32_bit_stereo_channels(appbuf); } @@ -289,7 +289,7 @@ STATIC size_t copy_appbuf_to_dma(machine_i2s_obj_t *self, mp_buffer_info_t *appb } // FreeRTOS task used for non-blocking mode -STATIC void task_for_non_blocking_mode(void *self_in) { +static void task_for_non_blocking_mode(void *self_in) { machine_i2s_obj_t *self = (machine_i2s_obj_t *)self_in; non_blocking_descriptor_t descriptor; @@ -306,7 +306,7 @@ STATIC void task_for_non_blocking_mode(void *self_in) { } } -STATIC void mp_machine_i2s_init_helper(machine_i2s_obj_t *self, mp_arg_val_t *args) { +static void mp_machine_i2s_init_helper(machine_i2s_obj_t *self, mp_arg_val_t *args) { // are Pins valid? int8_t sck = args[ARG_sck].u_obj == MP_OBJ_NULL ? -1 : machine_pin_get_id(args[ARG_sck].u_obj); int8_t ws = args[ARG_ws].u_obj == MP_OBJ_NULL ? -1 : machine_pin_get_id(args[ARG_ws].u_obj); @@ -398,7 +398,7 @@ STATIC void mp_machine_i2s_init_helper(machine_i2s_obj_t *self, mp_arg_val_t *ar check_esp_err(i2s_set_pin(self->i2s_id, &pin_config)); } -STATIC machine_i2s_obj_t *mp_machine_i2s_make_new_instance(mp_int_t i2s_id) { +static machine_i2s_obj_t *mp_machine_i2s_make_new_instance(mp_int_t i2s_id) { if (i2s_id < 0 || i2s_id >= I2S_NUM_AUTO) { mp_raise_ValueError(MP_ERROR_TEXT("invalid id")); } @@ -416,7 +416,7 @@ STATIC machine_i2s_obj_t *mp_machine_i2s_make_new_instance(mp_int_t i2s_id) { return self; } -STATIC void mp_machine_i2s_deinit(machine_i2s_obj_t *self) { +static void mp_machine_i2s_deinit(machine_i2s_obj_t *self) { i2s_driver_uninstall(self->i2s_id); if (self->non_blocking_mode_task != NULL) { @@ -432,7 +432,7 @@ STATIC void mp_machine_i2s_deinit(machine_i2s_obj_t *self) { self->i2s_event_queue = NULL; } -STATIC void mp_machine_i2s_irq_update(machine_i2s_obj_t *self) { +static void mp_machine_i2s_irq_update(machine_i2s_obj_t *self) { if (self->io_mode == NON_BLOCKING) { // create a queue linking the MicroPython task to a FreeRTOS task // that manages the non blocking mode of operation diff --git a/ports/esp32/machine_pin.c b/ports/esp32/machine_pin.c index 34c6512c8da79..1e7b86baeb379 100644 --- a/ports/esp32/machine_pin.c +++ b/ports/esp32/machine_pin.c @@ -63,7 +63,7 @@ // Return the machine_pin_obj_t pointer corresponding to a machine_pin_irq_obj_t pointer. #define PIN_OBJ_PTR_FROM_IRQ_OBJ_PTR(self) ((machine_pin_obj_t *)((uintptr_t)(self) - offsetof(machine_pin_obj_t, irq))) -STATIC const machine_pin_obj_t *machine_pin_find_named(const mp_obj_dict_t *named_pins, mp_obj_t name) { +static const machine_pin_obj_t *machine_pin_find_named(const mp_obj_dict_t *named_pins, mp_obj_t name) { const mp_map_t *named_map = &named_pins->map; mp_map_elem_t *named_elem = mp_map_lookup((mp_map_t *)named_map, name, MP_MAP_LOOKUP); if (named_elem != NULL && named_elem->value != NULL) { @@ -89,14 +89,14 @@ void machine_pins_deinit(void) { } } -STATIC void machine_pin_isr_handler(void *arg) { +static void machine_pin_isr_handler(void *arg) { machine_pin_obj_t *self = arg; mp_obj_t handler = MP_STATE_PORT(machine_pin_irq_handler)[PIN_OBJ_PTR_INDEX(self)]; mp_sched_schedule(handler, MP_OBJ_FROM_PTR(self)); mp_hal_wake_main_task_from_isr(); } -STATIC const machine_pin_obj_t *machine_pin_find(mp_obj_t pin_in) { +static const machine_pin_obj_t *machine_pin_find(mp_obj_t pin_in) { if (mp_obj_is_type(pin_in, &machine_pin_type)) { return pin_in; } @@ -128,13 +128,13 @@ gpio_num_t machine_pin_get_id(mp_obj_t pin_in) { return PIN_OBJ_PTR_INDEX(self); } -STATIC void machine_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_pin_obj_t *self = self_in; mp_printf(print, "Pin(%u)", PIN_OBJ_PTR_INDEX(self)); } // pin.init(mode=None, pull=-1, *, value, drive, hold) -STATIC mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_mode, ARG_pull, ARG_value, ARG_drive, ARG_hold }; static const mp_arg_t allowed_args[] = { { MP_QSTR_mode, MP_ARG_OBJ, {.u_obj = mp_const_none}}, @@ -241,7 +241,7 @@ mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, } // fast method for getting/setting pin value -STATIC mp_obj_t machine_pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t machine_pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); machine_pin_obj_t *self = self_in; gpio_num_t index = PIN_OBJ_PTR_INDEX(self); @@ -256,35 +256,35 @@ STATIC mp_obj_t machine_pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, c } // pin.init(mode, pull) -STATIC mp_obj_t machine_pin_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t machine_pin_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { return machine_pin_obj_init_helper(args[0], n_args - 1, args + 1, kw_args); } MP_DEFINE_CONST_FUN_OBJ_KW(machine_pin_init_obj, 1, machine_pin_obj_init); // pin.value([value]) -STATIC mp_obj_t machine_pin_value(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_pin_value(size_t n_args, const mp_obj_t *args) { return machine_pin_call(args[0], n_args - 1, 0, args + 1); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pin_value_obj, 1, 2, machine_pin_value); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pin_value_obj, 1, 2, machine_pin_value); // pin.off() -STATIC mp_obj_t machine_pin_off(mp_obj_t self_in) { +static mp_obj_t machine_pin_off(mp_obj_t self_in) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); gpio_set_level(PIN_OBJ_PTR_INDEX(self), 0); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_off_obj, machine_pin_off); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_off_obj, machine_pin_off); // pin.on() -STATIC mp_obj_t machine_pin_on(mp_obj_t self_in) { +static mp_obj_t machine_pin_on(mp_obj_t self_in) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); gpio_set_level(PIN_OBJ_PTR_INDEX(self), 1); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_on_obj, machine_pin_on); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_on_obj, machine_pin_on); // pin.irq(handler=None, trigger=IRQ_FALLING|IRQ_RISING) -STATIC mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_handler, ARG_trigger, ARG_wake }; static const mp_arg_t allowed_args[] = { { MP_QSTR_handler, MP_ARG_OBJ, {.u_obj = mp_const_none} }, @@ -347,7 +347,7 @@ STATIC mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_ // return the irq object return MP_OBJ_FROM_PTR(&self->irq); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_pin_irq_obj, 1, machine_pin_irq); +static MP_DEFINE_CONST_FUN_OBJ_KW(machine_pin_irq_obj, 1, machine_pin_irq); MP_DEFINE_CONST_OBJ_TYPE( machine_pin_board_pins_obj_type, @@ -356,7 +356,7 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &machine_pin_board_pins_locals_dict ); -STATIC const mp_rom_map_elem_t machine_pin_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_pin_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_pin_init_obj) }, { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&machine_pin_value_obj) }, @@ -383,7 +383,7 @@ STATIC const mp_rom_map_elem_t machine_pin_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_DRIVE_3), MP_ROM_INT(GPIO_DRIVE_CAP_3) }, }; -STATIC mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { (void)errcode; machine_pin_obj_t *self = self_in; gpio_num_t index = PIN_OBJ_PTR_INDEX(self); @@ -400,9 +400,9 @@ STATIC mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, i return -1; } -STATIC MP_DEFINE_CONST_DICT(machine_pin_locals_dict, machine_pin_locals_dict_table); +static MP_DEFINE_CONST_DICT(machine_pin_locals_dict, machine_pin_locals_dict_table); -STATIC const mp_pin_p_t pin_pin_p = { +static const mp_pin_p_t pin_pin_p = { .ioctl = pin_ioctl, }; @@ -420,14 +420,14 @@ MP_DEFINE_CONST_OBJ_TYPE( /******************************************************************************/ // Pin IRQ object -STATIC mp_obj_t machine_pin_irq_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t machine_pin_irq_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { machine_pin_irq_obj_t *self = self_in; mp_arg_check_num(n_args, n_kw, 0, 0, false); machine_pin_isr_handler((void *)PIN_OBJ_PTR_FROM_IRQ_OBJ_PTR(self)); return mp_const_none; } -STATIC mp_obj_t machine_pin_irq_trigger(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_pin_irq_trigger(size_t n_args, const mp_obj_t *args) { machine_pin_irq_obj_t *self = args[0]; gpio_num_t index = PIN_OBJ_PTR_INDEX(PIN_OBJ_PTR_FROM_IRQ_OBJ_PTR(self)); uint32_t orig_trig = GPIO.pin[index].int_type; @@ -438,12 +438,12 @@ STATIC mp_obj_t machine_pin_irq_trigger(size_t n_args, const mp_obj_t *args) { // return original trigger value return MP_OBJ_NEW_SMALL_INT(orig_trig); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pin_irq_trigger_obj, 1, 2, machine_pin_irq_trigger); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pin_irq_trigger_obj, 1, 2, machine_pin_irq_trigger); -STATIC const mp_rom_map_elem_t machine_pin_irq_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_pin_irq_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_trigger), MP_ROM_PTR(&machine_pin_irq_trigger_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(machine_pin_irq_locals_dict, machine_pin_irq_locals_dict_table); +static MP_DEFINE_CONST_DICT(machine_pin_irq_locals_dict, machine_pin_irq_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( machine_pin_irq_type, diff --git a/ports/esp32/machine_pwm.c b/ports/esp32/machine_pwm.c index 03ef2d77fd299..e5d8986c8a839 100644 --- a/ports/esp32/machine_pwm.c +++ b/ports/esp32/machine_pwm.c @@ -52,7 +52,7 @@ typedef struct _chan_t { } chan_t; // List of PWM channels -STATIC chan_t chans[PWM_CHANNEL_MAX]; +static chan_t chans[PWM_CHANNEL_MAX]; // channel_idx is an index (end-to-end sequential numbering) for all channels // available on the chip and described in chans[] @@ -64,7 +64,7 @@ STATIC chan_t chans[PWM_CHANNEL_MAX]; #define PWM_TIMER_MAX (LEDC_SPEED_MODE_MAX * LEDC_TIMER_MAX) // List of timer configs -STATIC ledc_timer_config_t timers[PWM_TIMER_MAX]; +static ledc_timer_config_t timers[PWM_TIMER_MAX]; // timer_idx is an index (end-to-end sequential numbering) for all timers // available on the chip and configured in timers[] @@ -104,7 +104,7 @@ STATIC ledc_timer_config_t timers[PWM_TIMER_MAX]; #endif // Config of timer upon which we run all PWM'ed GPIO pins -STATIC bool pwm_inited = false; +static bool pwm_inited = false; // MicroPython PWM object struct typedef struct _machine_pwm_obj_t { @@ -120,12 +120,12 @@ typedef struct _machine_pwm_obj_t { int duty_ns; // - / - } machine_pwm_obj_t; -STATIC bool is_timer_in_use(int current_channel_idx, int timer_idx); -STATIC void set_duty_u16(machine_pwm_obj_t *self, int duty); -STATIC void set_duty_u10(machine_pwm_obj_t *self, int duty); -STATIC void set_duty_ns(machine_pwm_obj_t *self, int ns); +static bool is_timer_in_use(int current_channel_idx, int timer_idx); +static void set_duty_u16(machine_pwm_obj_t *self, int duty); +static void set_duty_u10(machine_pwm_obj_t *self, int duty); +static void set_duty_ns(machine_pwm_obj_t *self, int ns); -STATIC void pwm_init(void) { +static void pwm_init(void) { // Initial condition: no channels assigned for (int i = 0; i < PWM_CHANNEL_MAX; ++i) { chans[i].pin = -1; @@ -145,7 +145,7 @@ STATIC void pwm_init(void) { } // Deinit channel and timer if the timer is unused -STATIC void pwm_deinit(int channel_idx) { +static void pwm_deinit(int channel_idx) { // Valid channel? if ((channel_idx >= 0) && (channel_idx < PWM_CHANNEL_MAX)) { // Clean up timer if necessary @@ -193,7 +193,7 @@ void machine_pwm_deinit_all(void) { } } -STATIC void configure_channel(machine_pwm_obj_t *self) { +static void configure_channel(machine_pwm_obj_t *self) { ledc_channel_config_t cfg = { .channel = self->channel, .duty = (1 << (timers[TIMER_IDX(self->mode, self->timer)].duty_resolution)) / 2, @@ -207,7 +207,7 @@ STATIC void configure_channel(machine_pwm_obj_t *self) { } } -STATIC void set_freq(machine_pwm_obj_t *self, unsigned int freq, ledc_timer_config_t *timer) { +static void set_freq(machine_pwm_obj_t *self, unsigned int freq, ledc_timer_config_t *timer) { if (freq != timer->freq_hz) { // Find the highest bit resolution for the requested frequency unsigned int i = APB_CLK_FREQ; // 80 MHz @@ -274,7 +274,7 @@ STATIC void set_freq(machine_pwm_obj_t *self, unsigned int freq, ledc_timer_conf } // Calculate the duty parameters based on an ns value -STATIC int ns_to_duty(machine_pwm_obj_t *self, int ns) { +static int ns_to_duty(machine_pwm_obj_t *self, int ns) { ledc_timer_config_t timer = timers[TIMER_IDX(self->mode, self->timer)]; int64_t duty = ((int64_t)ns * UI_MAX_DUTY * timer.freq_hz + 500000000LL) / 1000000000LL; if ((ns > 0) && (duty == 0)) { @@ -285,7 +285,7 @@ STATIC int ns_to_duty(machine_pwm_obj_t *self, int ns) { return duty; } -STATIC int duty_to_ns(machine_pwm_obj_t *self, int duty) { +static int duty_to_ns(machine_pwm_obj_t *self, int duty) { ledc_timer_config_t timer = timers[TIMER_IDX(self->mode, self->timer)]; int64_t ns = ((int64_t)duty * 1000000000LL + (int64_t)timer.freq_hz * UI_MAX_DUTY / 2) / ((int64_t)timer.freq_hz * UI_MAX_DUTY); return ns; @@ -293,13 +293,13 @@ STATIC int duty_to_ns(machine_pwm_obj_t *self, int duty) { #define get_duty_raw(self) ledc_get_duty(self->mode, self->channel) -STATIC void pwm_is_active(machine_pwm_obj_t *self) { +static void pwm_is_active(machine_pwm_obj_t *self) { if (self->active == false) { mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("PWM inactive")); } } -STATIC uint32_t get_duty_u16(machine_pwm_obj_t *self) { +static uint32_t get_duty_u16(machine_pwm_obj_t *self) { pwm_is_active(self); int resolution = timers[TIMER_IDX(self->mode, self->timer)].duty_resolution; int duty = ledc_get_duty(self->mode, self->channel); @@ -311,17 +311,17 @@ STATIC uint32_t get_duty_u16(machine_pwm_obj_t *self) { return duty; } -STATIC uint32_t get_duty_u10(machine_pwm_obj_t *self) { +static uint32_t get_duty_u10(machine_pwm_obj_t *self) { pwm_is_active(self); return get_duty_u16(self) >> 6; // Scale down from 16 bit to 10 bit resolution } -STATIC uint32_t get_duty_ns(machine_pwm_obj_t *self) { +static uint32_t get_duty_ns(machine_pwm_obj_t *self) { pwm_is_active(self); return duty_to_ns(self, get_duty_u16(self)); } -STATIC void set_duty_u16(machine_pwm_obj_t *self, int duty) { +static void set_duty_u16(machine_pwm_obj_t *self, int duty) { pwm_is_active(self); if ((duty < 0) || (duty > UI_MAX_DUTY)) { mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("duty_u16 must be from 0 to %d"), UI_MAX_DUTY); @@ -360,7 +360,7 @@ STATIC void set_duty_u16(machine_pwm_obj_t *self, int duty) { self->duty_u16 = duty; } -STATIC void set_duty_u10(machine_pwm_obj_t *self, int duty) { +static void set_duty_u10(machine_pwm_obj_t *self, int duty) { pwm_is_active(self); if ((duty < 0) || (duty > MAX_DUTY_U10)) { mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("duty must be from 0 to %u"), MAX_DUTY_U10); @@ -370,7 +370,7 @@ STATIC void set_duty_u10(machine_pwm_obj_t *self, int duty) { self->duty_u10 = duty; } -STATIC void set_duty_ns(machine_pwm_obj_t *self, int ns) { +static void set_duty_ns(machine_pwm_obj_t *self, int ns) { pwm_is_active(self); if ((ns < 0) || (ns > duty_to_ns(self, UI_MAX_DUTY))) { mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("duty_ns must be from 0 to %d ns"), duty_to_ns(self, UI_MAX_DUTY)); @@ -387,7 +387,7 @@ STATIC void set_duty_ns(machine_pwm_obj_t *self, int ns) { #define ANY_MODE (-1) // Return timer_idx. Use TIMER_IDX_TO_MODE(timer_idx) and TIMER_IDX_TO_TIMER(timer_idx) to get mode and timer -STATIC int find_timer(unsigned int freq, bool same_freq_only, int mode) { +static int find_timer(unsigned int freq, bool same_freq_only, int mode) { int free_timer_idx_found = -1; // Find a free PWM Timer using the same freq for (int timer_idx = 0; timer_idx < PWM_TIMER_MAX; ++timer_idx) { @@ -407,7 +407,7 @@ STATIC int find_timer(unsigned int freq, bool same_freq_only, int mode) { } // Return true if the timer is in use in addition to current channel -STATIC bool is_timer_in_use(int current_channel_idx, int timer_idx) { +static bool is_timer_in_use(int current_channel_idx, int timer_idx) { for (int i = 0; i < PWM_CHANNEL_MAX; ++i) { if ((i != current_channel_idx) && (chans[i].timer_idx == timer_idx)) { return true; @@ -419,7 +419,7 @@ STATIC bool is_timer_in_use(int current_channel_idx, int timer_idx) { // Find a free PWM channel, also spot if our pin is already mentioned. // Return channel_idx. Use CHANNEL_IDX_TO_MODE(channel_idx) and CHANNEL_IDX_TO_CHANNEL(channel_idx) to get mode and channel -STATIC int find_channel(int pin, int mode) { +static int find_channel(int pin, int mode) { int avail_idx = -1; int channel_idx; for (channel_idx = 0; channel_idx < PWM_CHANNEL_MAX; ++channel_idx) { @@ -441,7 +441,7 @@ STATIC int find_channel(int pin, int mode) { /******************************************************************************/ // MicroPython bindings for PWM -STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_pwm_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "PWM(Pin(%u)", self->pin); if (self->active) { @@ -465,7 +465,7 @@ STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_p } // This called from pwm.init() method -STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, +static void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_freq, ARG_duty, ARG_duty_u16, ARG_duty_ns }; static const mp_arg_t allowed_args[] = { @@ -563,7 +563,7 @@ STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, } // This called from PWM() constructor -STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, +static mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 2, true); gpio_num_t pin_id = machine_pin_get_id(args[0]); @@ -592,7 +592,7 @@ STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, } // This called from pwm.deinit() method -STATIC void mp_machine_pwm_deinit(machine_pwm_obj_t *self) { +static void mp_machine_pwm_deinit(machine_pwm_obj_t *self) { int channel_idx = CHANNEL_IDX(self->mode, self->channel); pwm_deinit(channel_idx); self->active = false; @@ -604,12 +604,12 @@ STATIC void mp_machine_pwm_deinit(machine_pwm_obj_t *self) { // Set and get methods of PWM class -STATIC mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) { pwm_is_active(self); return MP_OBJ_NEW_SMALL_INT(ledc_get_freq(self->mode, self->timer)); } -STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { +static void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { pwm_is_active(self); if ((freq <= 0) || (freq > 40000000)) { mp_raise_ValueError(MP_ERROR_TEXT("frequency must be from 1Hz to 40MHz")); @@ -658,26 +658,26 @@ STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { set_freq(self, freq, &timers[current_timer_idx]); } -STATIC mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self) { return MP_OBJ_NEW_SMALL_INT(get_duty_u10(self)); } -STATIC void mp_machine_pwm_duty_set(machine_pwm_obj_t *self, mp_int_t duty) { +static void mp_machine_pwm_duty_set(machine_pwm_obj_t *self, mp_int_t duty) { set_duty_u10(self, duty); } -STATIC mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) { return MP_OBJ_NEW_SMALL_INT(get_duty_u16(self)); } -STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16) { +static void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16) { set_duty_u16(self, duty_u16); } -STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { return MP_OBJ_NEW_SMALL_INT(get_duty_ns(self)); } -STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns) { +static void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns) { set_duty_ns(self, duty_ns); } diff --git a/ports/esp32/machine_rtc.c b/ports/esp32/machine_rtc.c index cbbfb4b84c2de..087ba9d69efe7 100644 --- a/ports/esp32/machine_rtc.c +++ b/ports/esp32/machine_rtc.c @@ -79,14 +79,14 @@ _USER_MEM_ATTR uint8_t rtc_user_mem_data[MICROPY_HW_RTC_USER_MEM_MAX]; #undef _USER_MEM_ATTR // singleton RTC object -STATIC const machine_rtc_obj_t machine_rtc_obj = {{&machine_rtc_type}}; +static const machine_rtc_obj_t machine_rtc_obj = {{&machine_rtc_type}}; machine_rtc_config_t machine_rtc_config = { .ext1_pins = 0, .ext0_pin = -1 }; -STATIC mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 0, 0, false); @@ -101,7 +101,7 @@ STATIC mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, s return (mp_obj_t)&machine_rtc_obj; } -STATIC mp_obj_t machine_rtc_datetime_helper(mp_uint_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_rtc_datetime_helper(mp_uint_t n_args, const mp_obj_t *args) { if (n_args == 1) { // Get time @@ -138,21 +138,21 @@ STATIC mp_obj_t machine_rtc_datetime_helper(mp_uint_t n_args, const mp_obj_t *ar return mp_const_none; } } -STATIC mp_obj_t machine_rtc_datetime(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_rtc_datetime(size_t n_args, const mp_obj_t *args) { return machine_rtc_datetime_helper(n_args, args); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_rtc_datetime_obj, 1, 2, machine_rtc_datetime); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_rtc_datetime_obj, 1, 2, machine_rtc_datetime); -STATIC mp_obj_t machine_rtc_init(mp_obj_t self_in, mp_obj_t date) { +static mp_obj_t machine_rtc_init(mp_obj_t self_in, mp_obj_t date) { mp_obj_t args[2] = {self_in, date}; machine_rtc_datetime_helper(2, args); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_rtc_init_obj, machine_rtc_init); +static MP_DEFINE_CONST_FUN_OBJ_2(machine_rtc_init_obj, machine_rtc_init); #if MICROPY_HW_RTC_USER_MEM_MAX > 0 -STATIC mp_obj_t machine_rtc_memory(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_rtc_memory(size_t n_args, const mp_obj_t *args) { if (n_args == 1) { // read RTC memory uint8_t rtcram[MICROPY_HW_RTC_USER_MEM_MAX]; @@ -171,17 +171,17 @@ STATIC mp_obj_t machine_rtc_memory(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_rtc_memory_obj, 1, 2, machine_rtc_memory); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_rtc_memory_obj, 1, 2, machine_rtc_memory); #endif -STATIC const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_rtc_init_obj) }, { MP_ROM_QSTR(MP_QSTR_datetime), MP_ROM_PTR(&machine_rtc_datetime_obj) }, #if MICROPY_HW_RTC_USER_MEM_MAX > 0 { MP_ROM_QSTR(MP_QSTR_memory), MP_ROM_PTR(&machine_rtc_memory_obj) }, #endif }; -STATIC MP_DEFINE_CONST_DICT(machine_rtc_locals_dict, machine_rtc_locals_dict_table); +static MP_DEFINE_CONST_DICT(machine_rtc_locals_dict, machine_rtc_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( machine_rtc_type, diff --git a/ports/esp32/machine_sdcard.c b/ports/esp32/machine_sdcard.c index 8cc6452ddc503..92c6e64698c33 100644 --- a/ports/esp32/machine_sdcard.c +++ b/ports/esp32/machine_sdcard.c @@ -135,7 +135,7 @@ static const sdspi_device_config_t spi_dev_defaults[2] = { if (arg_vals[arg_id].u_obj != mp_const_none) \ config.pin_var = machine_pin_get_id(arg_vals[arg_id].u_obj) -STATIC esp_err_t sdcard_ensure_card_init(sdcard_card_obj_t *self, bool force) { +static esp_err_t sdcard_ensure_card_init(sdcard_card_obj_t *self, bool force) { if (force || !(self->flags & SDCARD_CARD_FLAGS_CARD_INIT_DONE)) { DEBUG_printf(" Calling card init"); @@ -166,7 +166,7 @@ STATIC esp_err_t sdcard_ensure_card_init(sdcard_card_obj_t *self, bool force) { // transfers. Only 1-bit is supported on the SPI interfaces. // card = SDCard(slot=1, width=None, present_pin=None, wp_pin=None) -STATIC mp_obj_t machine_sdcard_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t machine_sdcard_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments enum { ARG_slot, @@ -179,7 +179,7 @@ STATIC mp_obj_t machine_sdcard_make_new(const mp_obj_type_t *type, size_t n_args ARG_cs, ARG_freq, }; - STATIC const mp_arg_t allowed_args[] = { + static const mp_arg_t allowed_args[] = { { MP_QSTR_slot, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} }, { MP_QSTR_width, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} }, { MP_QSTR_cd, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, @@ -315,7 +315,7 @@ STATIC mp_obj_t machine_sdcard_make_new(const mp_obj_type_t *type, size_t n_args return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t sd_deinit(mp_obj_t self_in) { +static mp_obj_t sd_deinit(mp_obj_t self_in) { sdcard_card_obj_t *self = self_in; DEBUG_printf("De-init host\n"); @@ -335,9 +335,9 @@ STATIC mp_obj_t sd_deinit(mp_obj_t self_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(sd_deinit_obj, sd_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(sd_deinit_obj, sd_deinit); -STATIC mp_obj_t sd_info(mp_obj_t self_in) { +static mp_obj_t sd_info(mp_obj_t self_in) { sdcard_card_obj_t *self = self_in; // We could potential return a great deal more SD card data but it // is not clear that it is worth the extra code space to do @@ -355,9 +355,9 @@ STATIC mp_obj_t sd_info(mp_obj_t self_in) { }; return mp_obj_new_tuple(2, tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(sd_info_obj, sd_info); +static MP_DEFINE_CONST_FUN_OBJ_1(sd_info_obj, sd_info); -STATIC mp_obj_t machine_sdcard_readblocks(mp_obj_t self_in, mp_obj_t block_num, mp_obj_t buf) { +static mp_obj_t machine_sdcard_readblocks(mp_obj_t self_in, mp_obj_t block_num, mp_obj_t buf) { sdcard_card_obj_t *self = self_in; mp_buffer_info_t bufinfo; esp_err_t err; @@ -372,9 +372,9 @@ STATIC mp_obj_t machine_sdcard_readblocks(mp_obj_t self_in, mp_obj_t block_num, return mp_obj_new_bool(err == ESP_OK); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(machine_sdcard_readblocks_obj, machine_sdcard_readblocks); +static MP_DEFINE_CONST_FUN_OBJ_3(machine_sdcard_readblocks_obj, machine_sdcard_readblocks); -STATIC mp_obj_t machine_sdcard_writeblocks(mp_obj_t self_in, mp_obj_t block_num, mp_obj_t buf) { +static mp_obj_t machine_sdcard_writeblocks(mp_obj_t self_in, mp_obj_t block_num, mp_obj_t buf) { sdcard_card_obj_t *self = self_in; mp_buffer_info_t bufinfo; esp_err_t err; @@ -389,9 +389,9 @@ STATIC mp_obj_t machine_sdcard_writeblocks(mp_obj_t self_in, mp_obj_t block_num, return mp_obj_new_bool(err == ESP_OK); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(machine_sdcard_writeblocks_obj, machine_sdcard_writeblocks); +static MP_DEFINE_CONST_FUN_OBJ_3(machine_sdcard_writeblocks_obj, machine_sdcard_writeblocks); -STATIC mp_obj_t machine_sdcard_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { +static mp_obj_t machine_sdcard_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { sdcard_card_obj_t *self = self_in; esp_err_t err = ESP_OK; mp_int_t cmd = mp_obj_get_int(cmd_in); @@ -428,9 +428,9 @@ STATIC mp_obj_t machine_sdcard_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t return MP_OBJ_NEW_SMALL_INT(-1); // error } } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(machine_sdcard_ioctl_obj, machine_sdcard_ioctl); +static MP_DEFINE_CONST_FUN_OBJ_3(machine_sdcard_ioctl_obj, machine_sdcard_ioctl); -STATIC const mp_rom_map_elem_t machine_sdcard_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_sdcard_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&sd_info_obj) }, { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&sd_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&sd_deinit_obj) }, @@ -440,7 +440,7 @@ STATIC const mp_rom_map_elem_t machine_sdcard_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&machine_sdcard_ioctl_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(machine_sdcard_locals_dict, machine_sdcard_locals_dict_table); +static MP_DEFINE_CONST_DICT(machine_sdcard_locals_dict, machine_sdcard_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( machine_sdcard_type, diff --git a/ports/esp32/machine_timer.c b/ports/esp32/machine_timer.c index aba3db1983fce..5e249e46e62c7 100644 --- a/ports/esp32/machine_timer.c +++ b/ports/esp32/machine_timer.c @@ -66,8 +66,8 @@ typedef struct _machine_timer_obj_t { const mp_obj_type_t machine_timer_type; -STATIC void machine_timer_disable(machine_timer_obj_t *self); -STATIC mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args); +static void machine_timer_disable(machine_timer_obj_t *self); +static mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args); void machine_timer_deinit_all(void) { // Disable, deallocate and remove all timers from list @@ -80,14 +80,14 @@ void machine_timer_deinit_all(void) { } } -STATIC void machine_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_timer_obj_t *self = self_in; qstr mode = self->repeat ? MP_QSTR_PERIODIC : MP_QSTR_ONE_SHOT; uint64_t period = self->period / (TIMER_SCALE / 1000); // convert to ms mp_printf(print, "Timer(%u, mode=%q, period=%lu)", (self->group << 1) | self->index, mode, period); } -STATIC mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); mp_uint_t group = (mp_obj_get_int(args[0]) >> 1) & 1; mp_uint_t index = mp_obj_get_int(args[0]) & 1; @@ -121,7 +121,7 @@ STATIC mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args, return self; } -STATIC void machine_timer_disable(machine_timer_obj_t *self) { +static void machine_timer_disable(machine_timer_obj_t *self) { if (self->hal_context.dev != NULL) { // Disable the counter and alarm. timer_ll_enable_counter(self->hal_context.dev, self->index, false); @@ -138,7 +138,7 @@ STATIC void machine_timer_disable(machine_timer_obj_t *self) { // referenced elsewhere } -STATIC void machine_timer_isr(void *self_in) { +static void machine_timer_isr(void *self_in) { machine_timer_obj_t *self = self_in; uint32_t intr_status = timer_ll_get_intr_status(self->hal_context.dev); @@ -153,7 +153,7 @@ STATIC void machine_timer_isr(void *self_in) { } } -STATIC void machine_timer_enable(machine_timer_obj_t *self) { +static void machine_timer_enable(machine_timer_obj_t *self) { // Initialise the timer. timer_hal_init(&self->hal_context, self->group, self->index); timer_ll_enable_counter(self->hal_context.dev, self->index, false); @@ -183,7 +183,7 @@ STATIC void machine_timer_enable(machine_timer_obj_t *self) { timer_ll_enable_counter(self->hal_context.dev, self->index, true); } -STATIC mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_mode, ARG_callback, @@ -230,26 +230,26 @@ STATIC mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, mp_uint_t n return mp_const_none; } -STATIC mp_obj_t machine_timer_deinit(mp_obj_t self_in) { +static mp_obj_t machine_timer_deinit(mp_obj_t self_in) { machine_timer_disable(self_in); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_deinit_obj, machine_timer_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_deinit_obj, machine_timer_deinit); -STATIC mp_obj_t machine_timer_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t machine_timer_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { return machine_timer_init_helper(args[0], n_args - 1, args + 1, kw_args); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_timer_init_obj, 1, machine_timer_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(machine_timer_init_obj, 1, machine_timer_init); -STATIC mp_obj_t machine_timer_value(mp_obj_t self_in) { +static mp_obj_t machine_timer_value(mp_obj_t self_in) { machine_timer_obj_t *self = self_in; uint64_t result = timer_ll_get_counter_value(self->hal_context.dev, self->index); return MP_OBJ_NEW_SMALL_INT((mp_uint_t)(result / (TIMER_SCALE / 1000))); // value in ms } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_value_obj, machine_timer_value); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_value_obj, machine_timer_value); -STATIC const mp_rom_map_elem_t machine_timer_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_timer_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&machine_timer_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&machine_timer_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_timer_init_obj) }, @@ -257,7 +257,7 @@ STATIC const mp_rom_map_elem_t machine_timer_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_ONE_SHOT), MP_ROM_INT(false) }, { MP_ROM_QSTR(MP_QSTR_PERIODIC), MP_ROM_INT(true) }, }; -STATIC MP_DEFINE_CONST_DICT(machine_timer_locals_dict, machine_timer_locals_dict_table); +static MP_DEFINE_CONST_DICT(machine_timer_locals_dict, machine_timer_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( machine_timer_type, diff --git a/ports/esp32/machine_touchpad.c b/ports/esp32/machine_touchpad.c index d9f4ef3ebc7f4..7612063e51d4a 100644 --- a/ports/esp32/machine_touchpad.c +++ b/ports/esp32/machine_touchpad.c @@ -43,7 +43,7 @@ typedef struct _mtp_obj_t { touch_pad_t touchpad_id; } mtp_obj_t; -STATIC const mtp_obj_t touchpad_obj[] = { +static const mtp_obj_t touchpad_obj[] = { #if CONFIG_IDF_TARGET_ESP32 {{&machine_touchpad_type}, GPIO_NUM_4, TOUCH_PAD_NUM0}, {{&machine_touchpad_type}, GPIO_NUM_0, TOUCH_PAD_NUM1}, @@ -73,7 +73,7 @@ STATIC const mtp_obj_t touchpad_obj[] = { #endif }; -STATIC mp_obj_t mtp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, +static mp_obj_t mtp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 1, true); gpio_num_t pin_id = machine_pin_get_id(args[0]); @@ -108,7 +108,7 @@ STATIC mp_obj_t mtp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ mp_raise_ValueError(MP_ERROR_TEXT("Touch pad error")); } -STATIC mp_obj_t mtp_config(mp_obj_t self_in, mp_obj_t value_in) { +static mp_obj_t mtp_config(mp_obj_t self_in, mp_obj_t value_in) { mtp_obj_t *self = self_in; #if CONFIG_IDF_TARGET_ESP32 uint16_t value = mp_obj_get_int(value_in); @@ -123,7 +123,7 @@ STATIC mp_obj_t mtp_config(mp_obj_t self_in, mp_obj_t value_in) { } MP_DEFINE_CONST_FUN_OBJ_2(mtp_config_obj, mtp_config); -STATIC mp_obj_t mtp_read(mp_obj_t self_in) { +static mp_obj_t mtp_read(mp_obj_t self_in) { mtp_obj_t *self = self_in; #if CONFIG_IDF_TARGET_ESP32 uint16_t value; @@ -139,13 +139,13 @@ STATIC mp_obj_t mtp_read(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mtp_read_obj, mtp_read); -STATIC const mp_rom_map_elem_t mtp_locals_dict_table[] = { +static const mp_rom_map_elem_t mtp_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&mtp_config_obj) }, { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mtp_read_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mtp_locals_dict, mtp_locals_dict_table); +static MP_DEFINE_CONST_DICT(mtp_locals_dict, mtp_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( machine_touchpad_type, diff --git a/ports/esp32/machine_uart.c b/ports/esp32/machine_uart.c index 0e384dc07a2d7..b7adbf81c7aa7 100644 --- a/ports/esp32/machine_uart.c +++ b/ports/esp32/machine_uart.c @@ -68,7 +68,7 @@ typedef struct _machine_uart_obj_t { uint32_t invert; // lines to invert } machine_uart_obj_t; -STATIC const char *_parity_name[] = {"None", "1", "0"}; +static const char *_parity_name[] = {"None", "1", "0"}; /******************************************************************************/ // MicroPython bindings for UART @@ -81,7 +81,7 @@ STATIC const char *_parity_name[] = {"None", "1", "0"}; { MP_ROM_QSTR(MP_QSTR_RTS), MP_ROM_INT(UART_HW_FLOWCTRL_RTS) }, \ { MP_ROM_QSTR(MP_QSTR_CTS), MP_ROM_INT(UART_HW_FLOWCTRL_CTS) }, \ -STATIC void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); uint32_t baudrate; check_esp_err(uart_get_baudrate(self->uart_num, &baudrate)); @@ -133,7 +133,7 @@ STATIC void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_ mp_printf(print, ")"); } -STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_baudrate, ARG_bits, ARG_parity, ARG_stop, ARG_tx, ARG_rx, ARG_rts, ARG_cts, ARG_txbuf, ARG_rxbuf, ARG_timeout, ARG_timeout_char, ARG_invert, ARG_flow }; static const mp_arg_t allowed_args[] = { { MP_QSTR_baudrate, MP_ARG_INT, {.u_int = 0} }, @@ -309,7 +309,7 @@ STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, check_esp_err(uart_set_hw_flow_ctrl(self->uart_num, self->flowcontrol, UART_FIFO_LEN - UART_FIFO_LEN / 4)); } -STATIC mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); // get uart id @@ -386,21 +386,21 @@ STATIC mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_arg return MP_OBJ_FROM_PTR(self); } -STATIC void mp_machine_uart_deinit(machine_uart_obj_t *self) { +static void mp_machine_uart_deinit(machine_uart_obj_t *self) { check_esp_err(uart_driver_delete(self->uart_num)); } -STATIC mp_int_t mp_machine_uart_any(machine_uart_obj_t *self) { +static mp_int_t mp_machine_uart_any(machine_uart_obj_t *self) { size_t rxbufsize; check_esp_err(uart_get_buffered_data_len(self->uart_num, &rxbufsize)); return rxbufsize; } -STATIC bool mp_machine_uart_txdone(machine_uart_obj_t *self) { +static bool mp_machine_uart_txdone(machine_uart_obj_t *self) { return uart_wait_tx_done(self->uart_num, 0) == ESP_OK; } -STATIC void mp_machine_uart_sendbreak(machine_uart_obj_t *self) { +static void mp_machine_uart_sendbreak(machine_uart_obj_t *self) { // Save settings uint32_t baudrate; check_esp_err(uart_get_baudrate(self->uart_num, &baudrate)); @@ -417,7 +417,7 @@ STATIC void mp_machine_uart_sendbreak(machine_uart_obj_t *self) { check_esp_err(uart_set_baudrate(self->uart_num, baudrate)); } -STATIC mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { +static mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); // make sure we want at least 1 char @@ -451,7 +451,7 @@ STATIC mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t return bytes_read; } -STATIC mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { +static mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); int bytes_written = uart_write_bytes(self->uart_num, buf_in, size); @@ -465,7 +465,7 @@ STATIC mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_ return bytes_written; } -STATIC mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { machine_uart_obj_t *self = self_in; mp_uint_t ret; if (request == MP_STREAM_POLL) { diff --git a/ports/esp32/machine_wdt.c b/ports/esp32/machine_wdt.c index cee761f265e79..06bdc9d10185a 100644 --- a/ports/esp32/machine_wdt.c +++ b/ports/esp32/machine_wdt.c @@ -35,11 +35,11 @@ typedef struct _machine_wdt_obj_t { esp_task_wdt_user_handle_t twdt_user_handle; } machine_wdt_obj_t; -STATIC machine_wdt_obj_t wdt_default = { +static machine_wdt_obj_t wdt_default = { {&machine_wdt_type}, 0 }; -STATIC machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t timeout_ms) { +static machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t timeout_ms) { if (id != 0) { mp_raise_ValueError(NULL); } @@ -68,7 +68,7 @@ STATIC machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t return &wdt_default; } -STATIC void mp_machine_wdt_feed(machine_wdt_obj_t *self) { +static void mp_machine_wdt_feed(machine_wdt_obj_t *self) { (void)self; mp_int_t rs_code = esp_task_wdt_reset_user(wdt_default.twdt_user_handle); if (rs_code != ESP_OK) { diff --git a/ports/esp32/modesp.c b/ports/esp32/modesp.c index f51ba6ab34d50..d3cefbe219662 100644 --- a/ports/esp32/modesp.c +++ b/ports/esp32/modesp.c @@ -36,7 +36,7 @@ #include "py/mperrno.h" #include "py/mphal.h" -STATIC mp_obj_t esp_osdebug(size_t n_args, const mp_obj_t *args) { +static mp_obj_t esp_osdebug(size_t n_args, const mp_obj_t *args) { esp_log_level_t level = LOG_LOCAL_LEVEL; // Maximum available level if (n_args == 2) { level = mp_obj_get_int(args[1]); @@ -51,9 +51,9 @@ STATIC mp_obj_t esp_osdebug(size_t n_args, const mp_obj_t *args) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_osdebug_obj, 1, 2, esp_osdebug); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_osdebug_obj, 1, 2, esp_osdebug); -STATIC mp_obj_t esp_flash_read_(mp_obj_t offset_in, mp_obj_t buf_in) { +static mp_obj_t esp_flash_read_(mp_obj_t offset_in, mp_obj_t buf_in) { mp_int_t offset = mp_obj_get_int(offset_in); mp_buffer_info_t bufinfo; mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_WRITE); @@ -63,9 +63,9 @@ STATIC mp_obj_t esp_flash_read_(mp_obj_t offset_in, mp_obj_t buf_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp_flash_read_obj, esp_flash_read_); +static MP_DEFINE_CONST_FUN_OBJ_2(esp_flash_read_obj, esp_flash_read_); -STATIC mp_obj_t esp_flash_write_(mp_obj_t offset_in, mp_obj_t buf_in) { +static mp_obj_t esp_flash_write_(mp_obj_t offset_in, mp_obj_t buf_in) { mp_int_t offset = mp_obj_get_int(offset_in); mp_buffer_info_t bufinfo; mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ); @@ -75,9 +75,9 @@ STATIC mp_obj_t esp_flash_write_(mp_obj_t offset_in, mp_obj_t buf_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp_flash_write_obj, esp_flash_write_); +static MP_DEFINE_CONST_FUN_OBJ_2(esp_flash_write_obj, esp_flash_write_); -STATIC mp_obj_t esp_flash_erase(mp_obj_t sector_in) { +static mp_obj_t esp_flash_erase(mp_obj_t sector_in) { mp_int_t sector = mp_obj_get_int(sector_in); esp_err_t res = esp_flash_erase_region(NULL, sector * 4096, 4096); if (res != ESP_OK) { @@ -85,34 +85,34 @@ STATIC mp_obj_t esp_flash_erase(mp_obj_t sector_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_flash_erase_obj, esp_flash_erase); +static MP_DEFINE_CONST_FUN_OBJ_1(esp_flash_erase_obj, esp_flash_erase); -STATIC mp_obj_t esp_flash_size(void) { +static mp_obj_t esp_flash_size(void) { uint32_t size; esp_flash_get_size(NULL, &size); return mp_obj_new_int_from_uint(size); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_flash_size_obj, esp_flash_size); +static MP_DEFINE_CONST_FUN_OBJ_0(esp_flash_size_obj, esp_flash_size); -STATIC mp_obj_t esp_flash_user_start(void) { +static mp_obj_t esp_flash_user_start(void) { return MP_OBJ_NEW_SMALL_INT(0x200000); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_flash_user_start_obj, esp_flash_user_start); +static MP_DEFINE_CONST_FUN_OBJ_0(esp_flash_user_start_obj, esp_flash_user_start); -STATIC mp_obj_t esp_gpio_matrix_in(mp_obj_t pin, mp_obj_t sig, mp_obj_t inv) { +static mp_obj_t esp_gpio_matrix_in(mp_obj_t pin, mp_obj_t sig, mp_obj_t inv) { esp_rom_gpio_connect_in_signal(mp_obj_get_int(pin), mp_obj_get_int(sig), mp_obj_get_int(inv)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp_gpio_matrix_in_obj, esp_gpio_matrix_in); +static MP_DEFINE_CONST_FUN_OBJ_3(esp_gpio_matrix_in_obj, esp_gpio_matrix_in); -STATIC mp_obj_t esp_gpio_matrix_out(size_t n_args, const mp_obj_t *args) { +static mp_obj_t esp_gpio_matrix_out(size_t n_args, const mp_obj_t *args) { (void)n_args; esp_rom_gpio_connect_out_signal(mp_obj_get_int(args[0]), mp_obj_get_int(args[1]), mp_obj_get_int(args[2]), mp_obj_get_int(args[3])); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_gpio_matrix_out_obj, 4, 4, esp_gpio_matrix_out); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_gpio_matrix_out_obj, 4, 4, esp_gpio_matrix_out); -STATIC const mp_rom_map_elem_t esp_module_globals_table[] = { +static const mp_rom_map_elem_t esp_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_esp) }, { MP_ROM_QSTR(MP_QSTR_osdebug), MP_ROM_PTR(&esp_osdebug_obj) }, @@ -135,7 +135,7 @@ STATIC const mp_rom_map_elem_t esp_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_LOG_VERBOSE), MP_ROM_INT((mp_uint_t)ESP_LOG_VERBOSE)}, }; -STATIC MP_DEFINE_CONST_DICT(esp_module_globals, esp_module_globals_table); +static MP_DEFINE_CONST_DICT(esp_module_globals, esp_module_globals_table); const mp_obj_module_t esp_module = { .base = { &mp_type_module }, diff --git a/ports/esp32/modesp32.c b/ports/esp32/modesp32.c index ef3ad0b76d459..f363939483c6c 100644 --- a/ports/esp32/modesp32.c +++ b/ports/esp32/modesp32.c @@ -49,7 +49,7 @@ #include "../multi_heap_platform.h" #include "../heap_private.h" -STATIC mp_obj_t esp32_wake_on_touch(const mp_obj_t wake) { +static mp_obj_t esp32_wake_on_touch(const mp_obj_t wake) { if (machine_rtc_config.ext0_pin != -1) { mp_raise_ValueError(MP_ERROR_TEXT("no resources")); @@ -59,9 +59,9 @@ STATIC mp_obj_t esp32_wake_on_touch(const mp_obj_t wake) { machine_rtc_config.wake_on_touch = mp_obj_is_true(wake); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_wake_on_touch_obj, esp32_wake_on_touch); +static MP_DEFINE_CONST_FUN_OBJ_1(esp32_wake_on_touch_obj, esp32_wake_on_touch); -STATIC mp_obj_t esp32_wake_on_ext0(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t esp32_wake_on_ext0(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { if (machine_rtc_config.wake_on_touch) { mp_raise_ValueError(MP_ERROR_TEXT("no resources")); @@ -91,9 +91,9 @@ STATIC mp_obj_t esp32_wake_on_ext0(size_t n_args, const mp_obj_t *pos_args, mp_m return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(esp32_wake_on_ext0_obj, 0, esp32_wake_on_ext0); +static MP_DEFINE_CONST_FUN_OBJ_KW(esp32_wake_on_ext0_obj, 0, esp32_wake_on_ext0); -STATIC mp_obj_t esp32_wake_on_ext1(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t esp32_wake_on_ext1(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum {ARG_pins, ARG_level}; const mp_arg_t allowed_args[] = { { MP_QSTR_pins, MP_ARG_OBJ, {.u_obj = mp_const_none} }, @@ -127,18 +127,18 @@ STATIC mp_obj_t esp32_wake_on_ext1(size_t n_args, const mp_obj_t *pos_args, mp_m return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(esp32_wake_on_ext1_obj, 0, esp32_wake_on_ext1); +static MP_DEFINE_CONST_FUN_OBJ_KW(esp32_wake_on_ext1_obj, 0, esp32_wake_on_ext1); -STATIC mp_obj_t esp32_wake_on_ulp(const mp_obj_t wake) { +static mp_obj_t esp32_wake_on_ulp(const mp_obj_t wake) { if (machine_rtc_config.ext0_pin != -1) { mp_raise_ValueError(MP_ERROR_TEXT("no resources")); } machine_rtc_config.wake_on_ulp = mp_obj_is_true(wake); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_wake_on_ulp_obj, esp32_wake_on_ulp); +static MP_DEFINE_CONST_FUN_OBJ_1(esp32_wake_on_ulp_obj, esp32_wake_on_ulp); -STATIC mp_obj_t esp32_gpio_deep_sleep_hold(const mp_obj_t enable) { +static mp_obj_t esp32_gpio_deep_sleep_hold(const mp_obj_t enable) { if (mp_obj_is_true(enable)) { gpio_deep_sleep_hold_en(); } else { @@ -146,13 +146,13 @@ STATIC mp_obj_t esp32_gpio_deep_sleep_hold(const mp_obj_t enable) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_gpio_deep_sleep_hold_obj, esp32_gpio_deep_sleep_hold); +static MP_DEFINE_CONST_FUN_OBJ_1(esp32_gpio_deep_sleep_hold_obj, esp32_gpio_deep_sleep_hold); #if CONFIG_IDF_TARGET_ESP32 #include "soc/sens_reg.h" -STATIC mp_obj_t esp32_raw_temperature(void) { +static mp_obj_t esp32_raw_temperature(void) { SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_SAR, 3, SENS_FORCE_XPD_SAR_S); SET_PERI_REG_BITS(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_CLK_DIV, 10, SENS_TSENS_CLK_DIV_S); CLEAR_PERI_REG_MASK(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_POWER_UP); @@ -166,11 +166,11 @@ STATIC mp_obj_t esp32_raw_temperature(void) { return mp_obj_new_int(res); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp32_raw_temperature_obj, esp32_raw_temperature); +static MP_DEFINE_CONST_FUN_OBJ_0(esp32_raw_temperature_obj, esp32_raw_temperature); #endif -STATIC mp_obj_t esp32_idf_heap_info(const mp_obj_t cap_in) { +static mp_obj_t esp32_idf_heap_info(const mp_obj_t cap_in) { mp_int_t cap = mp_obj_get_int(cap_in); multi_heap_info_t info; heap_t *heap; @@ -190,9 +190,9 @@ STATIC mp_obj_t esp32_idf_heap_info(const mp_obj_t cap_in) { } return heap_list; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_idf_heap_info_obj, esp32_idf_heap_info); +static MP_DEFINE_CONST_FUN_OBJ_1(esp32_idf_heap_info_obj, esp32_idf_heap_info); -STATIC const mp_rom_map_elem_t esp32_module_globals_table[] = { +static const mp_rom_map_elem_t esp32_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_esp32) }, { MP_ROM_QSTR(MP_QSTR_wake_on_touch), MP_ROM_PTR(&esp32_wake_on_touch_obj) }, @@ -219,7 +219,7 @@ STATIC const mp_rom_map_elem_t esp32_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_HEAP_EXEC), MP_ROM_INT(MALLOC_CAP_EXEC) }, }; -STATIC MP_DEFINE_CONST_DICT(esp32_module_globals, esp32_module_globals_table); +static MP_DEFINE_CONST_DICT(esp32_module_globals, esp32_module_globals_table); const mp_obj_module_t esp32_module = { .base = { &mp_type_module }, diff --git a/ports/esp32/modespnow.c b/ports/esp32/modespnow.c index 77dc970f517d8..e7e51ee57ec0f 100644 --- a/ports/esp32/modespnow.c +++ b/ports/esp32/modespnow.c @@ -149,7 +149,7 @@ static esp_espnow_obj_t *_get_singleton_initialised() { // Allocate and initialise the ESPNow module as a singleton. // Returns the initialised espnow_singleton. -STATIC mp_obj_t espnow_make_new(const mp_obj_type_t *type, size_t n_args, +static mp_obj_t espnow_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // The espnow_singleton must be defined in MICROPY_PORT_ROOT_POINTERS @@ -180,9 +180,9 @@ STATIC mp_obj_t espnow_make_new(const mp_obj_type_t *type, size_t n_args, } // Forward declare the send and recv ESPNow callbacks -STATIC void send_cb(const uint8_t *mac_addr, esp_now_send_status_t status); +static void send_cb(const uint8_t *mac_addr, esp_now_send_status_t status); -STATIC void recv_cb(const esp_now_recv_info_t *recv_info, const uint8_t *msg, int msg_len); +static void recv_cb(const esp_now_recv_info_t *recv_info, const uint8_t *msg, int msg_len); // ESPNow.init(): Initialise the data buffers and ESP-NOW functions. // Initialise the Espressif ESPNOW software stack, register callbacks and @@ -205,7 +205,7 @@ static mp_obj_t espnow_init(mp_obj_t _) { // ESPNow.deinit(): De-initialise the ESPNOW software stack, disable callbacks // and deallocate the recv data buffers. // Note: this function is called from main.c:mp_task() to cleanup before soft -// reset, so cannot be declared STATIC and must guard against self == NULL;. +// reset, so cannot be declared static and must guard against self == NULL;. mp_obj_t espnow_deinit(mp_obj_t _) { esp_espnow_obj_t *self = _get_singleton(); if (self != NULL && self->recv_buffer != NULL) { @@ -220,7 +220,7 @@ mp_obj_t espnow_deinit(mp_obj_t _) { return mp_const_none; } -STATIC mp_obj_t espnow_active(size_t n_args, const mp_obj_t *args) { +static mp_obj_t espnow_active(size_t n_args, const mp_obj_t *args) { esp_espnow_obj_t *self = _get_singleton(); if (n_args > 1) { if (mp_obj_is_true(args[1])) { @@ -231,13 +231,13 @@ STATIC mp_obj_t espnow_active(size_t n_args, const mp_obj_t *args) { } return self->recv_buffer != NULL ? mp_const_true : mp_const_false; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_active_obj, 1, 2, espnow_active); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_active_obj, 1, 2, espnow_active); // ESPNow.config(['param'|param=value, ..]) // Get or set configuration values. Supported config params: // buffer: size of buffer for rx packets (default=514 bytes) // timeout: Default read timeout (default=300,000 milliseconds) -STATIC mp_obj_t espnow_config(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t espnow_config(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { esp_espnow_obj_t *self = _get_singleton(); enum { ARG_get, ARG_rxbuf, ARG_timeout_ms, ARG_rate }; static const mp_arg_t allowed_args[] = { @@ -278,11 +278,11 @@ STATIC mp_obj_t espnow_config(size_t n_args, const mp_obj_t *pos_args, mp_map_t return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(espnow_config_obj, 1, espnow_config); +static MP_DEFINE_CONST_FUN_OBJ_KW(espnow_config_obj, 1, espnow_config); // ESPNow.irq(recv_cb) // Set callback function to be invoked when a message is received. -STATIC mp_obj_t espnow_irq(size_t n_args, const mp_obj_t *args) { +static mp_obj_t espnow_irq(size_t n_args, const mp_obj_t *args) { esp_espnow_obj_t *self = _get_singleton(); mp_obj_t recv_cb = args[1]; if (recv_cb != mp_const_none && !mp_obj_is_callable(recv_cb)) { @@ -292,12 +292,12 @@ STATIC mp_obj_t espnow_irq(size_t n_args, const mp_obj_t *args) { self->recv_cb_arg = (n_args > 2) ? args[2] : mp_const_none; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_irq_obj, 2, 3, espnow_irq); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_irq_obj, 2, 3, espnow_irq); // ESPnow.stats(): Provide some useful stats. // Returns a tuple of: // (tx_pkts, tx_responses, tx_failures, rx_pkts, dropped_rx_pkts) -STATIC mp_obj_t espnow_stats(mp_obj_t _) { +static mp_obj_t espnow_stats(mp_obj_t _) { const esp_espnow_obj_t *self = _get_singleton(); return NEW_TUPLE( mp_obj_new_int(self->tx_packets), @@ -306,7 +306,7 @@ STATIC mp_obj_t espnow_stats(mp_obj_t _) { mp_obj_new_int(self->rx_packets), mp_obj_new_int(self->dropped_rx_pkts)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(espnow_stats_obj, espnow_stats); +static MP_DEFINE_CONST_FUN_OBJ_1(espnow_stats_obj, espnow_stats); #if MICROPY_PY_ESPNOW_RSSI // ### Maintaining the peer table and reading RSSI values @@ -401,7 +401,7 @@ static int ringbuf_get_bytes_wait(ringbuf_t *r, uint8_t *data, size_t len, mp_in // loaded into the 3rd and 4th elements. // Default timeout is set with ESPNow.config(timeout=milliseconds). // Return (None, None) on timeout. -STATIC mp_obj_t espnow_recvinto(size_t n_args, const mp_obj_t *args) { +static mp_obj_t espnow_recvinto(size_t n_args, const mp_obj_t *args) { esp_espnow_obj_t *self = _get_singleton_initialised(); mp_int_t timeout_ms = ((n_args > 2 && args[2] != mp_const_none) @@ -456,15 +456,15 @@ STATIC mp_obj_t espnow_recvinto(size_t n_args, const mp_obj_t *args) { return MP_OBJ_NEW_SMALL_INT(msg_len); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_recvinto_obj, 2, 3, espnow_recvinto); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_recvinto_obj, 2, 3, espnow_recvinto); // Test if data is available to read from the buffers -STATIC mp_obj_t espnow_any(const mp_obj_t _) { +static mp_obj_t espnow_any(const mp_obj_t _) { esp_espnow_obj_t *self = _get_singleton_initialised(); return ringbuf_avail(self->recv_buffer) ? mp_const_true : mp_const_false; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(espnow_any_obj, espnow_any); +static MP_DEFINE_CONST_FUN_OBJ_1(espnow_any_obj, espnow_any); // Used by espnow_send() for sends() with sync==True. // Wait till all pending sent packet responses have been received. @@ -494,7 +494,7 @@ static void _wait_for_pending_responses(esp_espnow_obj_t *self) { // True if sync==True and message is received successfully by all recipients // False if sync==True and message is not received by at least one recipient // Raises: EAGAIN if the internal espnow buffers are full. -STATIC mp_obj_t espnow_send(size_t n_args, const mp_obj_t *args) { +static mp_obj_t espnow_send(size_t n_args, const mp_obj_t *args) { esp_espnow_obj_t *self = _get_singleton_initialised(); // Check the various combinations of input arguments const uint8_t *peer = (n_args > 2) ? _get_peer(args[1]) : NULL; @@ -532,7 +532,7 @@ STATIC mp_obj_t espnow_send(size_t n_args, const mp_obj_t *args) { // Return False if sync and any peers did not respond. return mp_obj_new_bool(!(sync && self->tx_failures != saved_failures)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_send_obj, 2, 4, espnow_send); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_send_obj, 2, 4, espnow_send); // ### The ESP_Now send and recv callback routines // @@ -540,7 +540,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_send_obj, 2, 4, espnow_send); // Callback triggered when a sent packet is acknowledged by the peer (or not). // Just count the number of responses and number of failures. // These are used in the send() logic. -STATIC void send_cb(const uint8_t *mac_addr, esp_now_send_status_t status) { +static void send_cb(const uint8_t *mac_addr, esp_now_send_status_t status) { esp_espnow_obj_t *self = _get_singleton(); self->tx_responses++; if (status != ESP_NOW_SEND_SUCCESS) { @@ -553,7 +553,7 @@ STATIC void send_cb(const uint8_t *mac_addr, esp_now_send_status_t status) { // ESPNow packet. // If the buffer is full, drop the message and increment the dropped count. // Schedules the user callback if one has been registered (ESPNow.config()). -STATIC void recv_cb(const esp_now_recv_info_t *recv_info, const uint8_t *msg, int msg_len) { +static void recv_cb(const esp_now_recv_info_t *recv_info, const uint8_t *msg, int msg_len) { esp_espnow_obj_t *self = _get_singleton(); ringbuf_t *buf = self->recv_buffer; // TODO: Test this works with ">". @@ -584,17 +584,17 @@ STATIC void recv_cb(const esp_now_recv_info_t *recv_info, const uint8_t *msg, in // Set the ESP-NOW Primary Master Key (pmk) (for encrypted communications). // Raise OSError if ESP-NOW functions are not initialised. // Raise ValueError if key is not a bytes-like object exactly 16 bytes long. -STATIC mp_obj_t espnow_set_pmk(mp_obj_t _, mp_obj_t key) { +static mp_obj_t espnow_set_pmk(mp_obj_t _, mp_obj_t key) { check_esp_err(esp_now_set_pmk(_get_bytes_len(key, ESP_NOW_KEY_LEN))); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(espnow_set_pmk_obj, espnow_set_pmk); +static MP_DEFINE_CONST_FUN_OBJ_2(espnow_set_pmk_obj, espnow_set_pmk); // Common code for add_peer() and mod_peer() to process the args and kw_args: // Raise ValueError if the LMK is not a bytes-like object of exactly 16 bytes. // Raise TypeError if invalid keyword args or too many positional args. // Return true if all args parsed correctly. -STATIC bool _update_peer_info( +static bool _update_peer_info( esp_now_peer_info_t *peer, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { @@ -630,7 +630,7 @@ STATIC bool _update_peer_info( // Update the cached peer count in self->peer_count; // The peer_count ignores broadcast and multicast addresses and is used for the // send() logic and is updated from add_peer(), mod_peer() and del_peer(). -STATIC void _update_peer_count() { +static void _update_peer_count() { esp_espnow_obj_t *self = _get_singleton_initialised(); esp_now_peer_info_t peer = {0}; @@ -654,7 +654,7 @@ STATIC void _update_peer_count() { // Raise ValueError if mac or LMK are not bytes-like objects or wrong length. // Raise TypeError if invalid keyword args or too many positional args. // Return None. -STATIC mp_obj_t espnow_add_peer(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t espnow_add_peer(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { esp_now_peer_info_t peer = {0}; memcpy(peer.peer_addr, _get_peer(args[1]), ESP_NOW_ETH_ALEN); _update_peer_info(&peer, n_args - 2, args + 2, kw_args); @@ -664,13 +664,13 @@ STATIC mp_obj_t espnow_add_peer(size_t n_args, const mp_obj_t *args, mp_map_t *k return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(espnow_add_peer_obj, 2, espnow_add_peer); +static MP_DEFINE_CONST_FUN_OBJ_KW(espnow_add_peer_obj, 2, espnow_add_peer); // ESPNow.del_peer(peer_mac): Unregister peer_mac. // Raise OSError if ESPNow.init() has not been called. // Raise ValueError if peer is not a bytes-like objects or wrong length. // Return None. -STATIC mp_obj_t espnow_del_peer(mp_obj_t _, mp_obj_t peer) { +static mp_obj_t espnow_del_peer(mp_obj_t _, mp_obj_t peer) { uint8_t peer_addr[ESP_NOW_ETH_ALEN]; memcpy(peer_addr, _get_peer(peer), ESP_NOW_ETH_ALEN); @@ -679,7 +679,7 @@ STATIC mp_obj_t espnow_del_peer(mp_obj_t _, mp_obj_t peer) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(espnow_del_peer_obj, espnow_del_peer); +static MP_DEFINE_CONST_FUN_OBJ_2(espnow_del_peer_obj, espnow_del_peer); // Convert a peer_info struct to python tuple // Used by espnow_get_peer() and espnow_get_peers() @@ -697,7 +697,7 @@ static mp_obj_t _peer_info_to_tuple(const esp_now_peer_info_t *peer) { // Return a tuple of tuples: // ((peer_addr, lmk, channel, ifidx, encrypt), // (peer_addr, lmk, channel, ifidx, encrypt), ...) -STATIC mp_obj_t espnow_get_peers(mp_obj_t _) { +static mp_obj_t espnow_get_peers(mp_obj_t _) { esp_espnow_obj_t *self = _get_singleton_initialised(); // Build and initialise the peer info tuple. @@ -711,14 +711,14 @@ STATIC mp_obj_t espnow_get_peers(mp_obj_t _) { return peerinfo_tuple; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(espnow_get_peers_obj, espnow_get_peers); +static MP_DEFINE_CONST_FUN_OBJ_1(espnow_get_peers_obj, espnow_get_peers); #if MICROPY_PY_ESPNOW_EXTRA_PEER_METHODS // ESPNow.get_peer(peer_mac): Get the peer info for peer_mac as a tuple. // Raise OSError if ESPNow.init() has not been called. // Raise ValueError if mac or LMK are not bytes-like objects or wrong length. // Return a tuple of (peer_addr, lmk, channel, ifidx, encrypt). -STATIC mp_obj_t espnow_get_peer(mp_obj_t _, mp_obj_t arg1) { +static mp_obj_t espnow_get_peer(mp_obj_t _, mp_obj_t arg1) { esp_now_peer_info_t peer = {0}; memcpy(peer.peer_addr, _get_peer(arg1), ESP_NOW_ETH_ALEN); @@ -726,7 +726,7 @@ STATIC mp_obj_t espnow_get_peer(mp_obj_t _, mp_obj_t arg1) { return _peer_info_to_tuple(&peer); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(espnow_get_peer_obj, espnow_get_peer); +static MP_DEFINE_CONST_FUN_OBJ_2(espnow_get_peer_obj, espnow_get_peer); // ESPNow.mod_peer(peer_mac, [lmk, [channel, [ifidx, [encrypt]]]]) or // ESPNow.mod_peer(peer_mac, [lmk=b'0123456789abcdef'|b''|None|False], @@ -736,7 +736,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(espnow_get_peer_obj, espnow_get_peer); // Raise ValueError if mac or LMK are not bytes-like objects or wrong length. // Raise TypeError if invalid keyword args or too many positional args. // Return None. -STATIC mp_obj_t espnow_mod_peer(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t espnow_mod_peer(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { esp_now_peer_info_t peer = {0}; memcpy(peer.peer_addr, _get_peer(args[1]), ESP_NOW_ETH_ALEN); check_esp_err(esp_now_get_peer(peer.peer_addr, &peer)); @@ -748,12 +748,12 @@ STATIC mp_obj_t espnow_mod_peer(size_t n_args, const mp_obj_t *args, mp_map_t *k return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(espnow_mod_peer_obj, 2, espnow_mod_peer); +static MP_DEFINE_CONST_FUN_OBJ_KW(espnow_mod_peer_obj, 2, espnow_mod_peer); // ESPNow.espnow_peer_count(): Get the number of registered peers. // Raise OSError if ESPNow.init() has not been called. // Return a tuple of (num_total_peers, num_encrypted_peers). -STATIC mp_obj_t espnow_peer_count(mp_obj_t _) { +static mp_obj_t espnow_peer_count(mp_obj_t _) { esp_now_peer_num_t peer_num = {0}; check_esp_err(esp_now_get_peer_num(&peer_num)); @@ -761,10 +761,10 @@ STATIC mp_obj_t espnow_peer_count(mp_obj_t _) { mp_obj_new_int(peer_num.total_num), mp_obj_new_int(peer_num.encrypt_num)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(espnow_peer_count_obj, espnow_peer_count); +static MP_DEFINE_CONST_FUN_OBJ_1(espnow_peer_count_obj, espnow_peer_count); #endif -STATIC const mp_rom_map_elem_t esp_espnow_locals_dict_table[] = { +static const mp_rom_map_elem_t esp_espnow_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&espnow_active_obj) }, { MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&espnow_config_obj) }, { MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&espnow_irq_obj) }, @@ -786,9 +786,9 @@ STATIC const mp_rom_map_elem_t esp_espnow_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_peer_count), MP_ROM_PTR(&espnow_peer_count_obj) }, #endif // MICROPY_PY_ESPNOW_EXTRA_PEER_METHODS }; -STATIC MP_DEFINE_CONST_DICT(esp_espnow_locals_dict, esp_espnow_locals_dict_table); +static MP_DEFINE_CONST_DICT(esp_espnow_locals_dict, esp_espnow_locals_dict_table); -STATIC const mp_rom_map_elem_t espnow_globals_dict_table[] = { +static const mp_rom_map_elem_t espnow_globals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__espnow) }, { MP_ROM_QSTR(MP_QSTR_ESPNowBase), MP_ROM_PTR(&esp_espnow_type) }, { MP_ROM_QSTR(MP_QSTR_MAX_DATA_LEN), MP_ROM_INT(ESP_NOW_MAX_DATA_LEN)}, @@ -797,13 +797,13 @@ STATIC const mp_rom_map_elem_t espnow_globals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_MAX_TOTAL_PEER_NUM), MP_ROM_INT(ESP_NOW_MAX_TOTAL_PEER_NUM)}, { MP_ROM_QSTR(MP_QSTR_MAX_ENCRYPT_PEER_NUM), MP_ROM_INT(ESP_NOW_MAX_ENCRYPT_PEER_NUM)}, }; -STATIC MP_DEFINE_CONST_DICT(espnow_globals_dict, espnow_globals_dict_table); +static MP_DEFINE_CONST_DICT(espnow_globals_dict, espnow_globals_dict_table); // ### Dummy Buffer Protocol support // ...so asyncio can poll.ipoll() on this device // Support ioctl(MP_STREAM_POLL, ) for asyncio -STATIC mp_uint_t espnow_stream_ioctl( +static mp_uint_t espnow_stream_ioctl( mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { if (request != MP_STREAM_POLL) { *errcode = MP_EINVAL; @@ -818,7 +818,7 @@ STATIC mp_uint_t espnow_stream_ioctl( ((self->tx_responses < self->tx_packets) ? MP_STREAM_POLL_WR : 0)); } -STATIC const mp_stream_p_t espnow_stream_p = { +static const mp_stream_p_t espnow_stream_p = { .ioctl = espnow_stream_ioctl, }; @@ -830,7 +830,7 @@ STATIC const mp_stream_p_t espnow_stream_p = { // rssi is the wifi signal strength from the last msg received // (in dBm from -127 to 0) // time_sec is the time in milliseconds since device last booted. -STATIC void espnow_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void espnow_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { esp_espnow_obj_t *self = _get_singleton(); if (dest[0] != MP_OBJ_NULL) { // Only allow "Load" operation return; diff --git a/ports/esp32/modmachine.c b/ports/esp32/modmachine.c index 145ae9341cf2a..6e6a57896814c 100755 --- a/ports/esp32/modmachine.c +++ b/ports/esp32/modmachine.c @@ -88,17 +88,17 @@ typedef enum { MP_SOFT_RESET } reset_reason_t; -STATIC bool is_soft_reset = 0; +static bool is_soft_reset = 0; #if CONFIG_IDF_TARGET_ESP32C3 int esp_clk_cpu_freq(void); #endif -STATIC mp_obj_t mp_machine_get_freq(void) { +static mp_obj_t mp_machine_get_freq(void) { return mp_obj_new_int(esp_rom_get_cpu_ticks_per_us() * 1000000); } -STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) { +static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) { mp_int_t freq = mp_obj_get_int(args[0]) / 1000000; if (freq != 20 && freq != 40 && freq != 80 && freq != 160 #if !CONFIG_IDF_TARGET_ESP32C3 @@ -136,7 +136,7 @@ STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) { } } -STATIC void machine_sleep_helper(wake_type_t wake_type, size_t n_args, const mp_obj_t *args) { +static void machine_sleep_helper(wake_type_t wake_type, size_t n_args, const mp_obj_t *args) { // First, disable any previously set wake-up source esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL); @@ -182,16 +182,16 @@ STATIC void machine_sleep_helper(wake_type_t wake_type, size_t n_args, const mp_ } } -STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) { +static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) { machine_sleep_helper(MACHINE_WAKE_SLEEP, n_args, args); }; -NORETURN STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) { +NORETURN static void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) { machine_sleep_helper(MACHINE_WAKE_DEEPSLEEP, n_args, args); mp_machine_reset(); }; -STATIC mp_int_t mp_machine_reset_cause(void) { +static mp_int_t mp_machine_reset_cause(void) { if (is_soft_reset) { return MP_SOFT_RESET; } @@ -235,22 +235,22 @@ void machine_deinit(void) { is_soft_reset = 1; } -STATIC mp_obj_t machine_wake_reason(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_wake_reason(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { return MP_OBJ_NEW_SMALL_INT(esp_sleep_get_wakeup_cause()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_wake_reason_obj, 0, machine_wake_reason); +static MP_DEFINE_CONST_FUN_OBJ_KW(machine_wake_reason_obj, 0, machine_wake_reason); -NORETURN STATIC void mp_machine_reset(void) { +NORETURN static void mp_machine_reset(void) { esp_restart(); } -STATIC mp_obj_t mp_machine_unique_id(void) { +static mp_obj_t mp_machine_unique_id(void) { uint8_t chipid[6]; esp_efuse_mac_get_default(chipid); return mp_obj_new_bytes(chipid, 6); } -STATIC void mp_machine_idle(void) { +static void mp_machine_idle(void) { MP_THREAD_GIL_EXIT(); taskYIELD(); MP_THREAD_GIL_ENTER(); diff --git a/ports/esp32/modos.c b/ports/esp32/modos.c index 5b055eb979817..d5ba611e88b36 100644 --- a/ports/esp32/modos.c +++ b/ports/esp32/modos.c @@ -36,7 +36,7 @@ #include "py/mphal.h" #include "extmod/misc.h" -STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { +static mp_obj_t mp_os_urandom(mp_obj_t num) { mp_int_t n = mp_obj_get_int(num); vstr_t vstr; vstr_init_len(&vstr, n); @@ -50,4 +50,4 @@ STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { } return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); diff --git a/ports/esp32/modsocket.c b/ports/esp32/modsocket.c index 9280ab203d25b..507609dfef6b1 100644 --- a/ports/esp32/modsocket.c +++ b/ports/esp32/modsocket.c @@ -83,7 +83,7 @@ typedef struct _socket_obj_t { #endif } socket_obj_t; -STATIC const char *TAG = "modsocket"; +static const char *TAG = "modsocket"; void _socket_settimeout(socket_obj_t *sock, uint64_t timeout_ms); @@ -93,21 +93,21 @@ void _socket_settimeout(socket_obj_t *sock, uint64_t timeout_ms); // This divisor is used to reduce the load on the system, so it doesn't poll sockets too often #define USOCKET_EVENTS_DIVISOR (8) -STATIC uint8_t socket_events_divisor; -STATIC socket_obj_t *socket_events_head; +static uint8_t socket_events_divisor; +static socket_obj_t *socket_events_head; void socket_events_deinit(void) { socket_events_head = NULL; } // Assumes the socket is not already in the linked list, and adds it -STATIC void socket_events_add(socket_obj_t *sock) { +static void socket_events_add(socket_obj_t *sock) { sock->events_next = socket_events_head; socket_events_head = sock; } // Assumes the socket is already in the linked list, and removes it -STATIC void socket_events_remove(socket_obj_t *sock) { +static void socket_events_remove(socket_obj_t *sock) { for (socket_obj_t **s = &socket_events_head;; s = &(*s)->events_next) { if (*s == sock) { *s = (*s)->events_next; @@ -158,7 +158,7 @@ static inline void check_for_exceptions(void) { #if MICROPY_HW_ENABLE_MDNS_QUERIES // This function mimics lwip_getaddrinfo, but makes an mDNS query -STATIC int mdns_getaddrinfo(const char *host_str, const char *port_str, +static int mdns_getaddrinfo(const char *host_str, const char *port_str, const struct addrinfo *hints, struct addrinfo **res) { int host_len = strlen(host_str); const int local_len = sizeof(MDNS_LOCAL_SUFFIX) - 1; @@ -261,13 +261,13 @@ static void _getaddrinfo_inner(const mp_obj_t host, const mp_obj_t portx, assert(retval == 0 && *res != NULL); } -STATIC void _socket_getaddrinfo(const mp_obj_t addrtuple, struct addrinfo **resp) { +static void _socket_getaddrinfo(const mp_obj_t addrtuple, struct addrinfo **resp) { mp_obj_t *elem; mp_obj_get_array_fixed_n(addrtuple, 2, &elem); _getaddrinfo_inner(elem[0], elem[1], NULL, resp); } -STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t socket_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 3, false); socket_obj_t *sock = mp_obj_malloc_with_finaliser(socket_obj_t, type_in); @@ -302,7 +302,7 @@ STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type_in, size_t n_args, siz return MP_OBJ_FROM_PTR(sock); } -STATIC mp_obj_t socket_bind(const mp_obj_t arg0, const mp_obj_t arg1) { +static mp_obj_t socket_bind(const mp_obj_t arg0, const mp_obj_t arg1) { socket_obj_t *self = MP_OBJ_TO_PTR(arg0); struct addrinfo *res; _socket_getaddrinfo(arg1, &res); @@ -314,10 +314,10 @@ STATIC mp_obj_t socket_bind(const mp_obj_t arg0, const mp_obj_t arg1) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind); // method socket.listen([backlog]) -STATIC mp_obj_t socket_listen(size_t n_args, const mp_obj_t *args) { +static mp_obj_t socket_listen(size_t n_args, const mp_obj_t *args) { socket_obj_t *self = MP_OBJ_TO_PTR(args[0]); int backlog = MICROPY_PY_SOCKET_LISTEN_BACKLOG_DEFAULT; @@ -333,9 +333,9 @@ STATIC mp_obj_t socket_listen(size_t n_args, const mp_obj_t *args) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_listen_obj, 1, 2, socket_listen); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_listen_obj, 1, 2, socket_listen); -STATIC mp_obj_t socket_accept(const mp_obj_t arg0) { +static mp_obj_t socket_accept(const mp_obj_t arg0) { socket_obj_t *self = MP_OBJ_TO_PTR(arg0); struct sockaddr addr; @@ -380,9 +380,9 @@ STATIC mp_obj_t socket_accept(const mp_obj_t arg0) { return client; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_accept_obj, socket_accept); +static MP_DEFINE_CONST_FUN_OBJ_1(socket_accept_obj, socket_accept); -STATIC mp_obj_t socket_connect(const mp_obj_t arg0, const mp_obj_t arg1) { +static mp_obj_t socket_connect(const mp_obj_t arg0, const mp_obj_t arg1) { socket_obj_t *self = MP_OBJ_TO_PTR(arg0); struct addrinfo *res; bool blocking = false; @@ -477,9 +477,9 @@ STATIC mp_obj_t socket_connect(const mp_obj_t arg0, const mp_obj_t arg1) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect); -STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) { +static mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) { (void)n_args; // always 4 socket_obj_t *self = MP_OBJ_TO_PTR(args[0]); @@ -550,7 +550,7 @@ STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_setsockopt_obj, 4, 4, socket_setsockopt); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_setsockopt_obj, 4, 4, socket_setsockopt); void _socket_settimeout(socket_obj_t *sock, uint64_t timeout_ms) { // Rather than waiting for the entire timeout specified, we wait sock->retries times @@ -568,7 +568,7 @@ void _socket_settimeout(socket_obj_t *sock, uint64_t timeout_ms) { lwip_fcntl(sock->fd, F_SETFL, timeout_ms ? 0 : O_NONBLOCK); } -STATIC mp_obj_t socket_settimeout(const mp_obj_t arg0, const mp_obj_t arg1) { +static mp_obj_t socket_settimeout(const mp_obj_t arg0, const mp_obj_t arg1) { socket_obj_t *self = MP_OBJ_TO_PTR(arg0); if (arg1 == mp_const_none) { _socket_settimeout(self, UINT64_MAX); @@ -581,9 +581,9 @@ STATIC mp_obj_t socket_settimeout(const mp_obj_t arg0, const mp_obj_t arg1) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_settimeout_obj, socket_settimeout); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_settimeout_obj, socket_settimeout); -STATIC mp_obj_t socket_setblocking(const mp_obj_t arg0, const mp_obj_t arg1) { +static mp_obj_t socket_setblocking(const mp_obj_t arg0, const mp_obj_t arg1) { socket_obj_t *self = MP_OBJ_TO_PTR(arg0); if (mp_obj_is_true(arg1)) { _socket_settimeout(self, UINT64_MAX); @@ -592,12 +592,12 @@ STATIC mp_obj_t socket_setblocking(const mp_obj_t arg0, const mp_obj_t arg1) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking); // XXX this can end up waiting a very long time if the content is dribbled in one character // at a time, as the timeout resets each time a recvfrom succeeds ... this is probably not // good behaviour. -STATIC mp_uint_t _socket_read_data(mp_obj_t self_in, void *buf, size_t size, +static mp_uint_t _socket_read_data(mp_obj_t self_in, void *buf, size_t size, struct sockaddr *from, socklen_t *from_len, int *errcode) { socket_obj_t *sock = MP_OBJ_TO_PTR(self_in); @@ -668,12 +668,12 @@ mp_obj_t _socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in, return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) { +static mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) { return _socket_recvfrom(self_in, len_in, NULL, NULL); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_recv_obj, socket_recv); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_recv_obj, socket_recv); -STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) { +static mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) { struct sockaddr from; socklen_t fromlen = sizeof(from); @@ -686,7 +686,7 @@ STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) { return mp_obj_new_tuple(2, tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_recvfrom_obj, socket_recvfrom); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_recvfrom_obj, socket_recvfrom); int _socket_send(socket_obj_t *sock, const char *data, size_t datalen) { int sentlen = 0; @@ -709,16 +709,16 @@ int _socket_send(socket_obj_t *sock, const char *data, size_t datalen) { return sentlen; } -STATIC mp_obj_t socket_send(const mp_obj_t arg0, const mp_obj_t arg1) { +static mp_obj_t socket_send(const mp_obj_t arg0, const mp_obj_t arg1) { socket_obj_t *sock = MP_OBJ_TO_PTR(arg0); mp_buffer_info_t bufinfo; mp_get_buffer_raise(arg1, &bufinfo, MP_BUFFER_READ); int r = _socket_send(sock, bufinfo.buf, bufinfo.len); return mp_obj_new_int(r); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_send_obj, socket_send); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_send_obj, socket_send); -STATIC mp_obj_t socket_sendall(const mp_obj_t arg0, const mp_obj_t arg1) { +static mp_obj_t socket_sendall(const mp_obj_t arg0, const mp_obj_t arg1) { // XXX behaviour when nonblocking (see extmod/modlwip.c) // XXX also timeout behaviour. socket_obj_t *sock = MP_OBJ_TO_PTR(arg0); @@ -730,9 +730,9 @@ STATIC mp_obj_t socket_sendall(const mp_obj_t arg0, const mp_obj_t arg1) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_sendall_obj, socket_sendall); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_sendall_obj, socket_sendall); -STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_in) { +static mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_in) { socket_obj_t *self = MP_OBJ_TO_PTR(self_in); // get the buffer to send @@ -760,25 +760,25 @@ STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_ } mp_raise_OSError(MP_ETIMEDOUT); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(socket_sendto_obj, socket_sendto); +static MP_DEFINE_CONST_FUN_OBJ_3(socket_sendto_obj, socket_sendto); -STATIC mp_obj_t socket_fileno(const mp_obj_t arg0) { +static mp_obj_t socket_fileno(const mp_obj_t arg0) { socket_obj_t *self = MP_OBJ_TO_PTR(arg0); return mp_obj_new_int(self->fd); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_fileno_obj, socket_fileno); +static MP_DEFINE_CONST_FUN_OBJ_1(socket_fileno_obj, socket_fileno); -STATIC mp_obj_t socket_makefile(size_t n_args, const mp_obj_t *args) { +static mp_obj_t socket_makefile(size_t n_args, const mp_obj_t *args) { (void)n_args; return args[0]; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_makefile_obj, 1, 3, socket_makefile); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_makefile_obj, 1, 3, socket_makefile); -STATIC mp_uint_t socket_stream_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t socket_stream_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { return _socket_read_data(self_in, buf, size, NULL, NULL, errcode); } -STATIC mp_uint_t socket_stream_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t socket_stream_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { socket_obj_t *sock = self_in; for (int i = 0; i <= sock->retries; i++) { MP_THREAD_GIL_EXIT(); @@ -798,7 +798,7 @@ STATIC mp_uint_t socket_stream_write(mp_obj_t self_in, const void *buf, mp_uint_ return MP_STREAM_ERROR; } -STATIC mp_uint_t socket_stream_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t socket_stream_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { socket_obj_t *socket = self_in; if (request == MP_STREAM_POLL) { if (socket->fd == -1) { @@ -867,7 +867,7 @@ STATIC mp_uint_t socket_stream_ioctl(mp_obj_t self_in, mp_uint_t request, uintpt return MP_STREAM_ERROR; } -STATIC const mp_rom_map_elem_t socket_locals_dict_table[] = { +static const mp_rom_map_elem_t socket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_stream_close_obj) }, { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) }, { MP_ROM_QSTR(MP_QSTR_bind), MP_ROM_PTR(&socket_bind_obj) }, @@ -890,15 +890,15 @@ STATIC const mp_rom_map_elem_t socket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) }, { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(socket_locals_dict, socket_locals_dict_table); +static MP_DEFINE_CONST_DICT(socket_locals_dict, socket_locals_dict_table); -STATIC const mp_stream_p_t socket_stream_p = { +static const mp_stream_p_t socket_stream_p = { .read = socket_stream_read, .write = socket_stream_write, .ioctl = socket_stream_ioctl }; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( socket_type, MP_QSTR_socket, MP_TYPE_FLAG_NONE, @@ -907,7 +907,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &socket_locals_dict ); -STATIC mp_obj_t esp_socket_getaddrinfo(size_t n_args, const mp_obj_t *args) { +static mp_obj_t esp_socket_getaddrinfo(size_t n_args, const mp_obj_t *args) { struct addrinfo hints = { }; struct addrinfo *res = NULL; @@ -963,9 +963,9 @@ STATIC mp_obj_t esp_socket_getaddrinfo(size_t n_args, const mp_obj_t *args) { lwip_freeaddrinfo(res); return ret_list; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_socket_getaddrinfo_obj, 2, 6, esp_socket_getaddrinfo); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_socket_getaddrinfo_obj, 2, 6, esp_socket_getaddrinfo); -STATIC mp_obj_t esp_socket_initialize() { +static mp_obj_t esp_socket_initialize() { static int initialized = 0; if (!initialized) { ESP_LOGI(TAG, "Initializing"); @@ -974,9 +974,9 @@ STATIC mp_obj_t esp_socket_initialize() { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_socket_initialize_obj, esp_socket_initialize); +static MP_DEFINE_CONST_FUN_OBJ_0(esp_socket_initialize_obj, esp_socket_initialize); -STATIC const mp_rom_map_elem_t mp_module_socket_globals_table[] = { +static const mp_rom_map_elem_t mp_module_socket_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_socket) }, { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&esp_socket_initialize_obj) }, { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&socket_type) }, @@ -997,7 +997,7 @@ STATIC const mp_rom_map_elem_t mp_module_socket_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_IP_ADD_MEMBERSHIP), MP_ROM_INT(IP_ADD_MEMBERSHIP) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_socket_globals, mp_module_socket_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_socket_globals, mp_module_socket_globals_table); const mp_obj_module_t mp_module_socket = { .base = { &mp_type_module }, diff --git a/ports/esp32/modtime.c b/ports/esp32/modtime.c index 7a2b2150869e1..4695dd23e7f3e 100644 --- a/ports/esp32/modtime.c +++ b/ports/esp32/modtime.c @@ -32,7 +32,7 @@ #include "shared/timeutils/timeutils.h" // Return the localtime as an 8-tuple. -STATIC mp_obj_t mp_time_localtime_get(void) { +static mp_obj_t mp_time_localtime_get(void) { struct timeval tv; gettimeofday(&tv, NULL); timeutils_struct_time_t tm; @@ -51,7 +51,7 @@ STATIC mp_obj_t mp_time_localtime_get(void) { } // Return the number of seconds since the Epoch. -STATIC mp_obj_t mp_time_time_get(void) { +static mp_obj_t mp_time_time_get(void) { struct timeval tv; gettimeofday(&tv, NULL); return mp_obj_new_int(tv.tv_sec); diff --git a/ports/esp32/mphalport.c b/ports/esp32/mphalport.c index fb322dff6dd54..fd1cbcdb985f1 100644 --- a/ports/esp32/mphalport.c +++ b/ports/esp32/mphalport.c @@ -49,7 +49,7 @@ TaskHandle_t mp_main_task_handle; -STATIC uint8_t stdin_ringbuf_array[260]; +static uint8_t stdin_ringbuf_array[260]; ringbuf_t stdin_ringbuf = {stdin_ringbuf_array, sizeof(stdin_ringbuf_array), 0, 0}; // Check the ESP-IDF error code and raise an OSError if it's not ESP_OK. diff --git a/ports/esp32/mpnimbleport.c b/ports/esp32/mpnimbleport.c index 5b57edf3c1c19..669aeb746a58d 100644 --- a/ports/esp32/mpnimbleport.c +++ b/ports/esp32/mpnimbleport.c @@ -38,7 +38,7 @@ #include "extmod/nimble/modbluetooth_nimble.h" -STATIC void ble_host_task(void *param) { +static void ble_host_task(void *param) { DEBUG_printf("ble_host_task\n"); nimble_port_run(); // This function will return only when nimble_port_stop() is executed. nimble_port_freertos_deinit(); diff --git a/ports/esp32/mpthreadport.c b/ports/esp32/mpthreadport.c index 74dbc14797432..1c13e928d9722 100644 --- a/ports/esp32/mpthreadport.c +++ b/ports/esp32/mpthreadport.c @@ -52,9 +52,9 @@ typedef struct _mp_thread_t { } mp_thread_t; // the mutex controls access to the linked list -STATIC mp_thread_mutex_t thread_mutex; -STATIC mp_thread_t thread_entry0; -STATIC mp_thread_t *thread = NULL; // root pointer, handled by mp_thread_gc_others +static mp_thread_mutex_t thread_mutex; +static mp_thread_t thread_entry0; +static mp_thread_t *thread = NULL; // root pointer, handled by mp_thread_gc_others void mp_thread_init(void *stack, uint32_t stack_len) { mp_thread_set_state(&mp_state_ctx.thread); @@ -113,9 +113,9 @@ void mp_thread_start(void) { mp_thread_mutex_unlock(&thread_mutex); } -STATIC void *(*ext_thread_entry)(void *) = NULL; +static void *(*ext_thread_entry)(void *) = NULL; -STATIC void freertos_entry(void *arg) { +static void freertos_entry(void *arg) { if (ext_thread_entry) { ext_thread_entry(arg); } diff --git a/ports/esp32/network_common.c b/ports/esp32/network_common.c index 1c5979175d0a1..fb51656817153 100644 --- a/ports/esp32/network_common.c +++ b/ports/esp32/network_common.c @@ -81,7 +81,7 @@ NORETURN void esp_exceptions_helper(esp_err_t e) { } } -STATIC mp_obj_t esp_initialize() { +static mp_obj_t esp_initialize() { static int initialized = 0; if (!initialized) { esp_exceptions(esp_netif_init()); @@ -91,7 +91,7 @@ STATIC mp_obj_t esp_initialize() { } MP_DEFINE_CONST_FUN_OBJ_0(esp_network_initialize_obj, esp_initialize); -STATIC mp_obj_t esp_ifconfig(size_t n_args, const mp_obj_t *args) { +static mp_obj_t esp_ifconfig(size_t n_args, const mp_obj_t *args) { base_if_obj_t *self = MP_OBJ_TO_PTR(args[0]); esp_netif_ip_info_t info; esp_netif_dns_info_t dns_info; @@ -163,7 +163,7 @@ mp_obj_t esp_ifname(esp_netif_t *netif) { return ret; } -STATIC mp_obj_t esp_phy_mode(size_t n_args, const mp_obj_t *args) { +static mp_obj_t esp_phy_mode(size_t n_args, const mp_obj_t *args) { return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_network_phy_mode_obj, 0, 1, esp_phy_mode); diff --git a/ports/esp32/network_lan.c b/ports/esp32/network_lan.c index f66895f9e098a..d7d9a9f7ac540 100644 --- a/ports/esp32/network_lan.c +++ b/ports/esp32/network_lan.c @@ -61,8 +61,8 @@ typedef struct _lan_if_obj_t { } lan_if_obj_t; const mp_obj_type_t lan_if_type; -STATIC lan_if_obj_t lan_obj = {{{&lan_if_type}, ESP_IF_ETH, NULL}, false, false}; -STATIC uint8_t eth_status = 0; +static lan_if_obj_t lan_obj = {{{&lan_if_type}, ESP_IF_ETH, NULL}, false, false}; +static uint8_t eth_status = 0; static void eth_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) { @@ -92,7 +92,7 @@ static void eth_event_handler(void *arg, esp_event_base_t event_base, } } -STATIC mp_obj_t get_lan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t get_lan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { lan_if_obj_t *self = &lan_obj; if (self->initialized) { @@ -298,7 +298,7 @@ STATIC mp_obj_t get_lan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar } MP_DEFINE_CONST_FUN_OBJ_KW(esp_network_get_lan_obj, 0, get_lan); -STATIC mp_obj_t lan_active(size_t n_args, const mp_obj_t *args) { +static mp_obj_t lan_active(size_t n_args, const mp_obj_t *args) { lan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args > 1) { @@ -318,20 +318,20 @@ STATIC mp_obj_t lan_active(size_t n_args, const mp_obj_t *args) { return mp_obj_new_bool(self->base.active); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lan_active_obj, 1, 2, lan_active); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lan_active_obj, 1, 2, lan_active); -STATIC mp_obj_t lan_status(mp_obj_t self_in) { +static mp_obj_t lan_status(mp_obj_t self_in) { return MP_OBJ_NEW_SMALL_INT(eth_status); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(lan_status_obj, lan_status); +static MP_DEFINE_CONST_FUN_OBJ_1(lan_status_obj, lan_status); -STATIC mp_obj_t lan_isconnected(mp_obj_t self_in) { +static mp_obj_t lan_isconnected(mp_obj_t self_in) { lan_if_obj_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_bool(self->base.active && (eth_status == ETH_GOT_IP)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(lan_isconnected_obj, lan_isconnected); +static MP_DEFINE_CONST_FUN_OBJ_1(lan_isconnected_obj, lan_isconnected); -STATIC mp_obj_t lan_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { +static mp_obj_t lan_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { if (n_args != 1 && kwargs->used != 0) { mp_raise_TypeError(MP_ERROR_TEXT("either pos or kw args are allowed")); } @@ -386,9 +386,9 @@ STATIC mp_obj_t lan_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs return val; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(lan_config_obj, 1, lan_config); +static MP_DEFINE_CONST_FUN_OBJ_KW(lan_config_obj, 1, lan_config); -STATIC const mp_rom_map_elem_t lan_if_locals_dict_table[] = { +static const mp_rom_map_elem_t lan_if_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&lan_active_obj) }, { MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&lan_isconnected_obj) }, { MP_ROM_QSTR(MP_QSTR_status), MP_ROM_PTR(&lan_status_obj) }, @@ -396,7 +396,7 @@ STATIC const mp_rom_map_elem_t lan_if_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&esp_network_ifconfig_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(lan_if_locals_dict, lan_if_locals_dict_table); +static MP_DEFINE_CONST_DICT(lan_if_locals_dict, lan_if_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( lan_if_type, diff --git a/ports/esp32/network_ppp.c b/ports/esp32/network_ppp.c index cf644a6bd7319..4e9b2a32ca0b6 100644 --- a/ports/esp32/network_ppp.c +++ b/ports/esp32/network_ppp.c @@ -84,7 +84,7 @@ static void ppp_status_cb(ppp_pcb *pcb, int err_code, void *ctx) { } } -STATIC mp_obj_t ppp_make_new(mp_obj_t stream) { +static mp_obj_t ppp_make_new(mp_obj_t stream) { mp_get_stream_raise(stream, MP_STREAM_OP_READ | MP_STREAM_OP_WRITE); ppp_if_obj_t *self = mp_obj_malloc_with_finaliser(ppp_if_obj_t, &ppp_if_type); @@ -123,7 +123,7 @@ static void pppos_client_task(void *self_in) { } } -STATIC mp_obj_t ppp_active(size_t n_args, const mp_obj_t *args) { +static mp_obj_t ppp_active(size_t n_args, const mp_obj_t *args) { ppp_if_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args > 1) { @@ -169,9 +169,9 @@ STATIC mp_obj_t ppp_active(size_t n_args, const mp_obj_t *args) { } return mp_obj_new_bool(self->active); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ppp_active_obj, 1, 2, ppp_active); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ppp_active_obj, 1, 2, ppp_active); -STATIC mp_obj_t ppp_connect_py(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t ppp_connect_py(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { enum { ARG_authmode, ARG_username, ARG_password }; static const mp_arg_t allowed_args[] = { { MP_QSTR_authmode, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = PPPAUTHTYPE_NONE} }, @@ -224,7 +224,7 @@ STATIC mp_obj_t ppp_connect_py(size_t n_args, const mp_obj_t *args, mp_map_t *kw } MP_DEFINE_CONST_FUN_OBJ_KW(ppp_connect_obj, 1, ppp_connect_py); -STATIC mp_obj_t ppp_delete(mp_obj_t self_in) { +static mp_obj_t ppp_delete(mp_obj_t self_in) { ppp_if_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_t args[] = {self, mp_const_false}; ppp_active(2, args); @@ -232,7 +232,7 @@ STATIC mp_obj_t ppp_delete(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(ppp_delete_obj, ppp_delete); -STATIC mp_obj_t ppp_ifconfig(size_t n_args, const mp_obj_t *args) { +static mp_obj_t ppp_ifconfig(size_t n_args, const mp_obj_t *args) { ppp_if_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 1) { // get @@ -266,18 +266,18 @@ STATIC mp_obj_t ppp_ifconfig(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ppp_ifconfig_obj, 1, 2, ppp_ifconfig); -STATIC mp_obj_t ppp_status(mp_obj_t self_in) { +static mp_obj_t ppp_status(mp_obj_t self_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(ppp_status_obj, ppp_status); +static MP_DEFINE_CONST_FUN_OBJ_1(ppp_status_obj, ppp_status); -STATIC mp_obj_t ppp_isconnected(mp_obj_t self_in) { +static mp_obj_t ppp_isconnected(mp_obj_t self_in) { ppp_if_obj_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_bool(self->connected); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(ppp_isconnected_obj, ppp_isconnected); +static MP_DEFINE_CONST_FUN_OBJ_1(ppp_isconnected_obj, ppp_isconnected); -STATIC mp_obj_t ppp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { +static mp_obj_t ppp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { if (n_args != 1 && kwargs->used != 0) { mp_raise_TypeError(MP_ERROR_TEXT("either pos or kw args are allowed")); } @@ -319,9 +319,9 @@ STATIC mp_obj_t ppp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs return val; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ppp_config_obj, 1, ppp_config); +static MP_DEFINE_CONST_FUN_OBJ_KW(ppp_config_obj, 1, ppp_config); -STATIC const mp_rom_map_elem_t ppp_if_locals_dict_table[] = { +static const mp_rom_map_elem_t ppp_if_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&ppp_active_obj) }, { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&ppp_connect_obj) }, { MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&ppp_isconnected_obj) }, @@ -333,7 +333,7 @@ STATIC const mp_rom_map_elem_t ppp_if_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_AUTH_PAP), MP_ROM_INT(PPPAUTHTYPE_PAP) }, { MP_ROM_QSTR(MP_QSTR_AUTH_CHAP), MP_ROM_INT(PPPAUTHTYPE_CHAP) }, }; -STATIC MP_DEFINE_CONST_DICT(ppp_if_locals_dict, ppp_if_locals_dict_table); +static MP_DEFINE_CONST_DICT(ppp_if_locals_dict, ppp_if_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( ppp_if_type, diff --git a/ports/esp32/network_wlan.c b/ports/esp32/network_wlan.c index e8c75c619df6c..dfa3347c67953 100644 --- a/ports/esp32/network_wlan.c +++ b/ports/esp32/network_wlan.c @@ -55,8 +55,8 @@ typedef base_if_obj_t wlan_if_obj_t; -STATIC wlan_if_obj_t wlan_sta_obj; -STATIC wlan_if_obj_t wlan_ap_obj; +static wlan_if_obj_t wlan_sta_obj; +static wlan_if_obj_t wlan_ap_obj; // Set to "true" if esp_wifi_start() was called static bool wifi_started = false; @@ -183,7 +183,7 @@ static void network_wlan_ip_event_handler(void *event_handler_arg, esp_event_bas } } -STATIC void require_if(mp_obj_t wlan_if, int if_no) { +static void require_if(mp_obj_t wlan_if, int if_no) { wlan_if_obj_t *self = MP_OBJ_TO_PTR(wlan_if); if (self->if_id != if_no) { mp_raise_msg(&mp_type_OSError, if_no == ESP_IF_WIFI_STA ? MP_ERROR_TEXT("STA required") : MP_ERROR_TEXT("AP required")); @@ -233,7 +233,7 @@ void esp_initialise_wifi(void) { } } -STATIC mp_obj_t network_wlan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t network_wlan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); esp_initialise_wifi(); @@ -248,7 +248,7 @@ STATIC mp_obj_t network_wlan_make_new(const mp_obj_type_t *type, size_t n_args, } } -STATIC mp_obj_t network_wlan_active(size_t n_args, const mp_obj_t *args) { +static mp_obj_t network_wlan_active(size_t n_args, const mp_obj_t *args) { wlan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]); wifi_mode_t mode; @@ -284,9 +284,9 @@ STATIC mp_obj_t network_wlan_active(size_t n_args, const mp_obj_t *args) { return (mode & bit) ? mp_const_true : mp_const_false; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_wlan_active_obj, 1, 2, network_wlan_active); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_wlan_active_obj, 1, 2, network_wlan_active); -STATIC mp_obj_t network_wlan_connect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t network_wlan_connect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_ssid, ARG_key, ARG_bssid }; static const mp_arg_t allowed_args[] = { { MP_QSTR_, MP_ARG_OBJ, {.u_obj = mp_const_none} }, @@ -334,16 +334,16 @@ STATIC mp_obj_t network_wlan_connect(size_t n_args, const mp_obj_t *pos_args, mp return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(network_wlan_connect_obj, 1, network_wlan_connect); +static MP_DEFINE_CONST_FUN_OBJ_KW(network_wlan_connect_obj, 1, network_wlan_connect); -STATIC mp_obj_t network_wlan_disconnect(mp_obj_t self_in) { +static mp_obj_t network_wlan_disconnect(mp_obj_t self_in) { wifi_sta_connect_requested = false; esp_exceptions(esp_wifi_disconnect()); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_wlan_disconnect_obj, network_wlan_disconnect); +static MP_DEFINE_CONST_FUN_OBJ_1(network_wlan_disconnect_obj, network_wlan_disconnect); -STATIC mp_obj_t network_wlan_status(size_t n_args, const mp_obj_t *args) { +static mp_obj_t network_wlan_status(size_t n_args, const mp_obj_t *args) { wlan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 1) { if (self->if_id == ESP_IF_WIFI_STA) { @@ -405,9 +405,9 @@ STATIC mp_obj_t network_wlan_status(size_t n_args, const mp_obj_t *args) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_wlan_status_obj, 1, 2, network_wlan_status); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_wlan_status_obj, 1, 2, network_wlan_status); -STATIC mp_obj_t network_wlan_scan(mp_obj_t self_in) { +static mp_obj_t network_wlan_scan(mp_obj_t self_in) { // check that STA mode is active wifi_mode_t mode; esp_exceptions(esp_wifi_get_mode(&mode)); @@ -448,9 +448,9 @@ STATIC mp_obj_t network_wlan_scan(mp_obj_t self_in) { } return list; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_wlan_scan_obj, network_wlan_scan); +static MP_DEFINE_CONST_FUN_OBJ_1(network_wlan_scan_obj, network_wlan_scan); -STATIC mp_obj_t network_wlan_isconnected(mp_obj_t self_in) { +static mp_obj_t network_wlan_isconnected(mp_obj_t self_in) { wlan_if_obj_t *self = MP_OBJ_TO_PTR(self_in); if (self->if_id == ESP_IF_WIFI_STA) { return mp_obj_new_bool(wifi_sta_connected); @@ -460,9 +460,9 @@ STATIC mp_obj_t network_wlan_isconnected(mp_obj_t self_in) { return mp_obj_new_bool(sta.num != 0); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_wlan_isconnected_obj, network_wlan_isconnected); +static MP_DEFINE_CONST_FUN_OBJ_1(network_wlan_isconnected_obj, network_wlan_isconnected); -STATIC mp_obj_t network_wlan_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { +static mp_obj_t network_wlan_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { if (n_args != 1 && kwargs->used != 0) { mp_raise_TypeError(MP_ERROR_TEXT("either pos or kw args are allowed")); } @@ -697,7 +697,7 @@ STATIC mp_obj_t network_wlan_config(size_t n_args, const mp_obj_t *args, mp_map_ } MP_DEFINE_CONST_FUN_OBJ_KW(network_wlan_config_obj, 1, network_wlan_config); -STATIC const mp_rom_map_elem_t wlan_if_locals_dict_table[] = { +static const mp_rom_map_elem_t wlan_if_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&network_wlan_active_obj) }, { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&network_wlan_connect_obj) }, { MP_ROM_QSTR(MP_QSTR_disconnect), MP_ROM_PTR(&network_wlan_disconnect_obj) }, @@ -712,7 +712,7 @@ STATIC const mp_rom_map_elem_t wlan_if_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_PM_PERFORMANCE), MP_ROM_INT(WIFI_PS_MIN_MODEM) }, { MP_ROM_QSTR(MP_QSTR_PM_POWERSAVE), MP_ROM_INT(WIFI_PS_MAX_MODEM) }, }; -STATIC MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table); +static MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( esp_network_wlan_type, diff --git a/ports/esp32/uart.c b/ports/esp32/uart.c index b82a638a5b27a..863301143d9ac 100644 --- a/ports/esp32/uart.c +++ b/ports/esp32/uart.c @@ -37,7 +37,7 @@ #include "driver/uart.h" // For uart_get_sclk_freq() #include "hal/uart_hal.h" -STATIC void uart_irq_handler(void *arg); +static void uart_irq_handler(void *arg); // Declaring the HAL structure on the stack saves a tiny amount of static RAM #define REPL_HAL_DEFN() { .dev = UART_LL_GET_HW(MICROPY_HW_UART_REPL) } @@ -99,7 +99,7 @@ int uart_stdout_tx_strn(const char *str, size_t len) { } // all code executed in ISR must be in IRAM, and any const data must be in DRAM -STATIC void IRAM_ATTR uart_irq_handler(void *arg) { +static void IRAM_ATTR uart_irq_handler(void *arg) { uint8_t rbuf[SOC_UART_FIFO_LEN]; int len; uart_hal_context_t repl_hal = REPL_HAL_DEFN(); diff --git a/ports/esp8266/esp_mphal.c b/ports/esp8266/esp_mphal.c index 6f158058d9acc..75588f73b72b7 100644 --- a/ports/esp8266/esp_mphal.c +++ b/ports/esp8266/esp_mphal.c @@ -36,7 +36,7 @@ #include "extmod/misc.h" #include "shared/runtime/pyexec.h" -STATIC byte stdin_ringbuf_array[256]; +static byte stdin_ringbuf_array[256]; ringbuf_t stdin_ringbuf = {stdin_ringbuf_array, sizeof(stdin_ringbuf_array), 0, 0}; void mp_hal_debug_tx_strn_cooked(void *env, const char *str, uint32_t len); const mp_print_t mp_debug_print = {NULL, mp_hal_debug_tx_strn_cooked}; diff --git a/ports/esp8266/esppwm.c b/ports/esp8266/esppwm.c index d7ac44a1786c8..be11272c48f00 100644 --- a/ports/esp8266/esppwm.c +++ b/ports/esp8266/esppwm.c @@ -41,23 +41,23 @@ struct pwm_param { uint16_t duty[PWM_CHANNEL]; }; -STATIC const uint8_t pin_num[PWM_CHANNEL] = {0, 2, 4, 5, 12, 13, 14, 15}; +static const uint8_t pin_num[PWM_CHANNEL] = {0, 2, 4, 5, 12, 13, 14, 15}; -STATIC struct pwm_single_param pwm_single_toggle[2][PWM_CHANNEL + 1]; -STATIC struct pwm_single_param *pwm_single; +static struct pwm_single_param pwm_single_toggle[2][PWM_CHANNEL + 1]; +static struct pwm_single_param *pwm_single; -STATIC struct pwm_param pwm; +static struct pwm_param pwm; -STATIC int8_t pwm_out_io_num[PWM_CHANNEL] = {-1, -1, -1, -1, -1, -1, -1, -1}; +static int8_t pwm_out_io_num[PWM_CHANNEL] = {-1, -1, -1, -1, -1, -1, -1, -1}; -STATIC uint8_t pwm_channel_toggle[2]; -STATIC uint8_t *pwm_channel; -STATIC uint8_t pwm_toggle = 1; -STATIC uint8_t pwm_timer_down = 1; -STATIC uint8_t pwm_current_channel = 0; -STATIC uint16_t pwm_gpio = 0; -STATIC uint8_t pwm_channel_num = 0; -STATIC volatile uint8_t pwm_toggle_request = 0; +static uint8_t pwm_channel_toggle[2]; +static uint8_t *pwm_channel; +static uint8_t pwm_toggle = 1; +static uint8_t pwm_timer_down = 1; +static uint8_t pwm_current_channel = 0; +static uint16_t pwm_gpio = 0; +static uint8_t pwm_channel_num = 0; +static volatile uint8_t pwm_toggle_request = 0; // XXX: 0xffffffff/(80000000/16)=35A #define US_TO_RTC_TIMER_TICKS(t) \ @@ -81,7 +81,7 @@ typedef enum { TM_EDGE_INT = 0, } TIMER_INT_MODE; -STATIC void ICACHE_FLASH_ATTR +static void ICACHE_FLASH_ATTR pwm_insert_sort(struct pwm_single_param pwm[], uint8 n) { uint8 i; @@ -106,7 +106,7 @@ pwm_insert_sort(struct pwm_single_param pwm[], uint8 n) { } } -STATIC volatile uint8 critical = 0; +static volatile uint8 critical = 0; #define LOCK_PWM(c) do { \ while ((c) == 1); \ @@ -298,7 +298,7 @@ pwm_get_freq(uint8 channel) { * Parameters : NONE * Returns : NONE *******************************************************************************/ -STATIC void ICACHE_RAM_ATTR +static void ICACHE_RAM_ATTR pwm_tim1_intr_handler(void *dummy) { (void)dummy; diff --git a/ports/esp8266/lexerstr32.c b/ports/esp8266/lexerstr32.c index a921efbbdcec5..51d5658e43dc3 100644 --- a/ports/esp8266/lexerstr32.c +++ b/ports/esp8266/lexerstr32.c @@ -35,7 +35,7 @@ typedef struct _mp_lexer_str32_buf_t { uint8_t byte_off; } mp_lexer_str32_buf_t; -STATIC mp_uint_t str32_buf_next_byte(void *sb_in) { +static mp_uint_t str32_buf_next_byte(void *sb_in) { mp_lexer_str32_buf_t *sb = (mp_lexer_str32_buf_t *)sb_in; byte c = sb->val & 0xff; if (c == 0) { @@ -52,7 +52,7 @@ STATIC mp_uint_t str32_buf_next_byte(void *sb_in) { return c; } -STATIC void str32_buf_free(void *sb_in) { +static void str32_buf_free(void *sb_in) { mp_lexer_str32_buf_t *sb = (mp_lexer_str32_buf_t *)sb_in; m_del_obj(mp_lexer_str32_buf_t, sb); } diff --git a/ports/esp8266/machine_adc.c b/ports/esp8266/machine_adc.c index 83384eea971a8..840b5ac6cd77d 100644 --- a/ports/esp8266/machine_adc.c +++ b/ports/esp8266/machine_adc.c @@ -37,10 +37,10 @@ typedef struct _machine_adc_obj_t { bool isvdd; } machine_adc_obj_t; -STATIC machine_adc_obj_t machine_adc_vdd3 = {{&machine_adc_type}, true}; -STATIC machine_adc_obj_t machine_adc_adc = {{&machine_adc_type}, false}; +static machine_adc_obj_t machine_adc_vdd3 = {{&machine_adc_type}, true}; +static machine_adc_obj_t machine_adc_adc = {{&machine_adc_type}, false}; -STATIC uint16_t adc_read(machine_adc_obj_t *self) { +static uint16_t adc_read(machine_adc_obj_t *self) { if (self->isvdd) { return system_get_vdd33(); } else { @@ -48,12 +48,12 @@ STATIC uint16_t adc_read(machine_adc_obj_t *self) { } } -STATIC void mp_machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_adc_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "ADC(%u)", self->isvdd); } -STATIC mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 1, false); mp_int_t chn = mp_obj_get_int(args[0]); @@ -69,12 +69,12 @@ STATIC mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type_in, size_t n_a } // read_u16() -STATIC mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) { +static mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) { uint32_t value = adc_read(self); return value * 65535 / 1024; } // Legacy method -STATIC mp_int_t mp_machine_adc_read(machine_adc_obj_t *self) { +static mp_int_t mp_machine_adc_read(machine_adc_obj_t *self) { return adc_read(self); } diff --git a/ports/esp8266/machine_pin.c b/ports/esp8266/machine_pin.c index 344197da94720..ec22c7c588c4e 100644 --- a/ports/esp8266/machine_pin.c +++ b/ports/esp8266/machine_pin.c @@ -61,8 +61,8 @@ typedef struct _pin_irq_obj_t { uint16_t phys_port; } pin_irq_obj_t; -STATIC void pin_intr_handler_part1(void *arg); -STATIC void pin_intr_handler_part2(uint32_t status); +static void pin_intr_handler_part1(void *arg); +static void pin_intr_handler_part2(uint32_t status); const pyb_pin_obj_t pyb_pin_obj[16 + 1] = { {{&pyb_pin_type}, 0, FUNC_GPIO0, PERIPHS_IO_MUX_GPIO0_U}, @@ -89,7 +89,7 @@ const pyb_pin_obj_t pyb_pin_obj[16 + 1] = { uint8_t pin_mode[16 + 1]; // forward declaration -STATIC const pin_irq_obj_t pin_irq_obj[16]; +static const pin_irq_obj_t pin_irq_obj[16]; void pin_init0(void) { ETS_GPIO_INTR_DISABLE(); @@ -242,7 +242,7 @@ void pin_set(uint pin, int value) { } } -STATIC void pyb_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void pyb_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_pin_obj_t *self = self_in; // pin name @@ -250,7 +250,7 @@ STATIC void pyb_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki } // pin.init(mode, pull=None, *, value) -STATIC mp_obj_t pyb_pin_obj_init_helper(pyb_pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_pin_obj_init_helper(pyb_pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_mode, ARG_pull, ARG_value }; static const mp_arg_t allowed_args[] = { { MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT }, @@ -334,7 +334,7 @@ mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, } // fast method for getting/setting pin value -STATIC mp_obj_t pyb_pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pyb_pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); pyb_pin_obj_t *self = self_in; if (n_args == 0) { @@ -348,33 +348,33 @@ STATIC mp_obj_t pyb_pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const } // pin.init(mode, pull) -STATIC mp_obj_t pyb_pin_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t pyb_pin_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { return pyb_pin_obj_init_helper(args[0], n_args - 1, args + 1, kw_args); } MP_DEFINE_CONST_FUN_OBJ_KW(pyb_pin_init_obj, 1, pyb_pin_obj_init); // pin.value([value]) -STATIC mp_obj_t pyb_pin_value(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_pin_value(size_t n_args, const mp_obj_t *args) { return pyb_pin_call(args[0], n_args - 1, 0, args + 1); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_pin_value_obj, 1, 2, pyb_pin_value); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_pin_value_obj, 1, 2, pyb_pin_value); -STATIC mp_obj_t pyb_pin_off(mp_obj_t self_in) { +static mp_obj_t pyb_pin_off(mp_obj_t self_in) { pyb_pin_obj_t *self = self_in; pin_set(self->phys_port, 0); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_pin_off_obj, pyb_pin_off); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_pin_off_obj, pyb_pin_off); -STATIC mp_obj_t pyb_pin_on(mp_obj_t self_in) { +static mp_obj_t pyb_pin_on(mp_obj_t self_in) { pyb_pin_obj_t *self = self_in; pin_set(self->phys_port, 1); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_pin_on_obj, pyb_pin_on); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_pin_on_obj, pyb_pin_on); // pin.irq(handler=None, trigger=IRQ_FALLING|IRQ_RISING, hard=False) -STATIC mp_obj_t pyb_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_handler, ARG_trigger, ARG_hard }; static const mp_arg_t allowed_args[] = { { MP_QSTR_handler, MP_ARG_OBJ, {.u_obj = mp_const_none} }, @@ -410,10 +410,10 @@ STATIC mp_obj_t pyb_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k // return the irq object return MP_OBJ_FROM_PTR(&pin_irq_obj[self->phys_port]); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_pin_irq_obj, 1, pyb_pin_irq); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_pin_irq_obj, 1, pyb_pin_irq); -STATIC mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode); -STATIC mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode); +static mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { (void)errcode; pyb_pin_obj_t *self = self_in; @@ -429,7 +429,7 @@ STATIC mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, i return -1; } -STATIC const mp_rom_map_elem_t pyb_pin_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_pin_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_pin_init_obj) }, { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&pyb_pin_value_obj) }, @@ -449,9 +449,9 @@ STATIC const mp_rom_map_elem_t pyb_pin_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_IRQ_FALLING), MP_ROM_INT(GPIO_PIN_INTR_NEGEDGE) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_pin_locals_dict, pyb_pin_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_pin_locals_dict, pyb_pin_locals_dict_table); -STATIC const mp_pin_p_t pin_pin_p = { +static const mp_pin_p_t pin_pin_p = { .ioctl = pin_ioctl, }; @@ -469,9 +469,9 @@ MP_DEFINE_CONST_OBJ_TYPE( /******************************************************************************/ // Pin IRQ object -STATIC const mp_obj_type_t pin_irq_type; +static const mp_obj_type_t pin_irq_type; -STATIC const pin_irq_obj_t pin_irq_obj[16] = { +static const pin_irq_obj_t pin_irq_obj[16] = { {{&pin_irq_type}, 0}, {{&pin_irq_type}, 1}, {{&pin_irq_type}, 2}, @@ -490,14 +490,14 @@ STATIC const pin_irq_obj_t pin_irq_obj[16] = { {{&pin_irq_type}, 15}, }; -STATIC mp_obj_t pin_irq_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pin_irq_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { pin_irq_obj_t *self = self_in; mp_arg_check_num(n_args, n_kw, 0, 0, false); pin_intr_handler_part2(1 << self->phys_port); return mp_const_none; } -STATIC mp_obj_t pin_irq_trigger(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pin_irq_trigger(size_t n_args, const mp_obj_t *args) { pin_irq_obj_t *self = args[0]; uint32_t orig_trig = GET_TRIGGER(self->phys_port); if (n_args == 2) { @@ -507,15 +507,15 @@ STATIC mp_obj_t pin_irq_trigger(size_t n_args, const mp_obj_t *args) { // return original trigger value return MP_OBJ_NEW_SMALL_INT(orig_trig); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_irq_trigger_obj, 1, 2, pin_irq_trigger); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_irq_trigger_obj, 1, 2, pin_irq_trigger); -STATIC const mp_rom_map_elem_t pin_irq_locals_dict_table[] = { +static const mp_rom_map_elem_t pin_irq_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_trigger), MP_ROM_PTR(&pin_irq_trigger_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(pin_irq_locals_dict, pin_irq_locals_dict_table); +static MP_DEFINE_CONST_DICT(pin_irq_locals_dict, pin_irq_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( pin_irq_type, MP_QSTR_IRQ, MP_TYPE_FLAG_NONE, diff --git a/ports/esp8266/machine_pwm.c b/ports/esp8266/machine_pwm.c index b9e499d252bc1..25a2d6898f7c7 100644 --- a/ports/esp8266/machine_pwm.c +++ b/ports/esp8266/machine_pwm.c @@ -38,14 +38,14 @@ typedef struct _machine_pwm_obj_t { int32_t duty_ns; } machine_pwm_obj_t; -STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty); +static void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty); -STATIC bool pwm_inited = false; +static bool pwm_inited = false; /******************************************************************************/ // MicroPython bindings for PWM -STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_pwm_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "PWM(%u", self->pin->phys_port); if (self->active) { @@ -55,7 +55,7 @@ STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_p mp_printf(print, ")"); } -STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_freq, ARG_duty, ARG_duty_u16, ARG_duty_ns }; static const mp_arg_t allowed_args[] = { { MP_QSTR_freq, MP_ARG_INT, {.u_int = -1} }, @@ -96,7 +96,7 @@ STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, c pwm_start(); } -STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); pyb_pin_obj_t *pin = mp_obj_get_pin_obj(args[0]); @@ -121,17 +121,17 @@ STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args return MP_OBJ_FROM_PTR(self); } -STATIC void mp_machine_pwm_deinit(machine_pwm_obj_t *self) { +static void mp_machine_pwm_deinit(machine_pwm_obj_t *self) { pwm_delete(self->channel); self->active = 0; pwm_start(); } -STATIC mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) { return MP_OBJ_NEW_SMALL_INT(pwm_get_freq(0)); } -STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { +static void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { pwm_set_freq(freq, 0); if (self->duty_ns != -1) { mp_machine_pwm_duty_set_ns(self, self->duty_ns); @@ -140,7 +140,7 @@ STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { } } -STATIC void set_active(machine_pwm_obj_t *self, bool set_pin) { +static void set_active(machine_pwm_obj_t *self, bool set_pin) { if (!self->active) { pwm_add(self->pin->phys_port, self->pin->periph, self->pin->func); self->active = 1; @@ -150,37 +150,37 @@ STATIC void set_active(machine_pwm_obj_t *self, bool set_pin) { } } -STATIC mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self) { set_active(self, true); return MP_OBJ_NEW_SMALL_INT(pwm_get_duty(self->channel)); } -STATIC void mp_machine_pwm_duty_set(machine_pwm_obj_t *self, mp_int_t duty) { +static void mp_machine_pwm_duty_set(machine_pwm_obj_t *self, mp_int_t duty) { set_active(self, false); self->duty_ns = -1; pwm_set_duty(duty, self->channel); pwm_start(); } -STATIC mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) { set_active(self, true); return MP_OBJ_NEW_SMALL_INT(pwm_get_duty(self->channel) * 65536 / 1024); } -STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty) { +static void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty) { set_active(self, false); self->duty_ns = -1; pwm_set_duty(duty * 1024 / 65536, self->channel); pwm_start(); } -STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { set_active(self, true); uint32_t freq = pwm_get_freq(0); return MP_OBJ_NEW_SMALL_INT(pwm_get_duty(self->channel) * 976563 / freq); } -STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty) { +static void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty) { set_active(self, false); self->duty_ns = duty; uint32_t freq = pwm_get_freq(0); diff --git a/ports/esp8266/machine_rtc.c b/ports/esp8266/machine_rtc.c index d8cbb8f8247dc..9c4d46f370f42 100644 --- a/ports/esp8266/machine_rtc.c +++ b/ports/esp8266/machine_rtc.c @@ -45,14 +45,14 @@ typedef struct _pyb_rtc_obj_t { #define MEM_USER_MAXLEN (512 - (MEM_USER_DATA_ADDR - MEM_DELTA_ADDR) * 4) // singleton RTC object -STATIC const pyb_rtc_obj_t pyb_rtc_obj = {{&pyb_rtc_type}}; +static const pyb_rtc_obj_t pyb_rtc_obj = {{&pyb_rtc_type}}; // ALARM0 state uint32_t pyb_rtc_alarm0_wake; // see MACHINE_WAKE_xxx constants uint64_t pyb_rtc_alarm0_expiry; // in microseconds // RTC overflow checking -STATIC uint32_t rtc_last_ticks; +static uint32_t rtc_last_ticks; void mp_hal_rtc_init(void) { uint32_t magic; @@ -76,7 +76,7 @@ void mp_hal_rtc_init(void) { pyb_rtc_alarm0_expiry = 0; } -STATIC mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 0, 0, false); @@ -124,7 +124,7 @@ void rtc_prepare_deepsleep(uint64_t sleep_us) { system_rtc_mem_write(MEM_DELTA_ADDR, &delta, sizeof(delta)); } -STATIC mp_obj_t pyb_rtc_datetime(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_rtc_datetime(size_t n_args, const mp_obj_t *args) { if (n_args == 1) { // Get time uint64_t msecs = pyb_rtc_get_us_since_epoch() / 1000; @@ -161,9 +161,9 @@ STATIC mp_obj_t pyb_rtc_datetime(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_datetime_obj, 1, 2, pyb_rtc_datetime); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_datetime_obj, 1, 2, pyb_rtc_datetime); -STATIC mp_obj_t pyb_rtc_memory(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_rtc_memory(size_t n_args, const mp_obj_t *args) { uint8_t rtcram[MEM_USER_MAXLEN]; uint32_t len; @@ -198,9 +198,9 @@ STATIC mp_obj_t pyb_rtc_memory(size_t n_args, const mp_obj_t *args) { } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_memory_obj, 1, 2, pyb_rtc_memory); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_memory_obj, 1, 2, pyb_rtc_memory); -STATIC mp_obj_t pyb_rtc_alarm(mp_obj_t self_in, mp_obj_t alarm_id, mp_obj_t time_in) { +static mp_obj_t pyb_rtc_alarm(mp_obj_t self_in, mp_obj_t alarm_id, mp_obj_t time_in) { (void)self_in; // unused // check we want alarm0 @@ -214,9 +214,9 @@ STATIC mp_obj_t pyb_rtc_alarm(mp_obj_t self_in, mp_obj_t alarm_id, mp_obj_t time return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_rtc_alarm_obj, pyb_rtc_alarm); +static MP_DEFINE_CONST_FUN_OBJ_3(pyb_rtc_alarm_obj, pyb_rtc_alarm); -STATIC mp_obj_t pyb_rtc_alarm_left(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_rtc_alarm_left(size_t n_args, const mp_obj_t *args) { // check we want alarm0 if (n_args > 1 && mp_obj_get_int(args[1]) != 0) { mp_raise_ValueError(MP_ERROR_TEXT("invalid alarm")); @@ -229,9 +229,9 @@ STATIC mp_obj_t pyb_rtc_alarm_left(size_t n_args, const mp_obj_t *args) { return mp_obj_new_int((pyb_rtc_alarm0_expiry - now) / 1000); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_alarm_left_obj, 1, 2, pyb_rtc_alarm_left); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_alarm_left_obj, 1, 2, pyb_rtc_alarm_left); -STATIC mp_obj_t pyb_rtc_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_rtc_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_trigger, ARG_wake }; static const mp_arg_t allowed_args[] = { { MP_QSTR_trigger, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, @@ -250,9 +250,9 @@ STATIC mp_obj_t pyb_rtc_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_irq_obj, 1, pyb_rtc_irq); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_irq_obj, 1, pyb_rtc_irq); -STATIC const mp_rom_map_elem_t pyb_rtc_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_rtc_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_datetime), MP_ROM_PTR(&pyb_rtc_datetime_obj) }, { MP_ROM_QSTR(MP_QSTR_memory), MP_ROM_PTR(&pyb_rtc_memory_obj) }, { MP_ROM_QSTR(MP_QSTR_alarm), MP_ROM_PTR(&pyb_rtc_alarm_obj) }, @@ -260,7 +260,7 @@ STATIC const mp_rom_map_elem_t pyb_rtc_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&pyb_rtc_irq_obj) }, { MP_ROM_QSTR(MP_QSTR_ALARM0), MP_ROM_INT(0) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_rtc_locals_dict, pyb_rtc_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_rtc_locals_dict, pyb_rtc_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pyb_rtc_type, diff --git a/ports/esp8266/machine_spi.c b/ports/esp8266/machine_spi.c index b7f8ecf240010..68a6b82ed381e 100644 --- a/ports/esp8266/machine_spi.c +++ b/ports/esp8266/machine_spi.c @@ -48,7 +48,7 @@ typedef struct _machine_spi_obj_t { uint8_t phase; } machine_spi_obj_t; -STATIC void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) { +static void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) { (void)self_in; if (dest == NULL) { @@ -94,13 +94,13 @@ STATIC void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8 /******************************************************************************/ // MicroPython bindings for HSPI -STATIC void machine_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "HSPI(id=1, baudrate=%u, polarity=%u, phase=%u)", self->baudrate, self->polarity, self->phase); } -STATIC void machine_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void machine_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { machine_spi_obj_t *self = (machine_spi_obj_t *)self_in; enum { ARG_baudrate, ARG_polarity, ARG_phase }; @@ -170,7 +170,7 @@ mp_obj_t machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n return MP_OBJ_FROM_PTR(self); } -STATIC const mp_machine_spi_p_t machine_spi_p = { +static const mp_machine_spi_p_t machine_spi_p = { .init = machine_spi_init, .transfer = machine_spi_transfer, }; diff --git a/ports/esp8266/machine_uart.c b/ports/esp8266/machine_uart.c index eaaa8ac865991..7c9b071a1a595 100644 --- a/ports/esp8266/machine_uart.c +++ b/ports/esp8266/machine_uart.c @@ -47,7 +47,7 @@ typedef struct _machine_uart_obj_t { uint16_t timeout_char; // timeout waiting between chars (in ms) } machine_uart_obj_t; -STATIC const char *_parity_name[] = {"None", "1", "0"}; +static const char *_parity_name[] = {"None", "1", "0"}; /******************************************************************************/ // MicroPython bindings for UART @@ -55,14 +55,14 @@ STATIC const char *_parity_name[] = {"None", "1", "0"}; // The UART class doesn't have any constants for this port. #define MICROPY_PY_MACHINE_UART_CLASS_CONSTANTS -STATIC void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "UART(%u, baudrate=%u, bits=%u, parity=%s, stop=%u, rxbuf=%u, timeout=%u, timeout_char=%u)", self->uart_id, self->baudrate, self->bits, _parity_name[self->parity], self->stop, uart0_get_rxbuf_len() - 1, self->timeout, self->timeout_char); } -STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_baudrate, ARG_bits, ARG_parity, ARG_stop, ARG_tx, ARG_rx, ARG_rxbuf, ARG_timeout, ARG_timeout_char }; static const mp_arg_t allowed_args[] = { { MP_QSTR_baudrate, MP_ARG_INT, {.u_int = 0} }, @@ -190,7 +190,7 @@ STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, uart_setup(self->uart_id); } -STATIC mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); // get uart id @@ -217,19 +217,19 @@ STATIC mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_arg return MP_OBJ_FROM_PTR(self); } -STATIC void mp_machine_uart_deinit(machine_uart_obj_t *self) { +static void mp_machine_uart_deinit(machine_uart_obj_t *self) { (void)self; } -STATIC mp_int_t mp_machine_uart_any(machine_uart_obj_t *self) { +static mp_int_t mp_machine_uart_any(machine_uart_obj_t *self) { return uart_rx_any(self->uart_id); } -STATIC bool mp_machine_uart_txdone(machine_uart_obj_t *self) { +static bool mp_machine_uart_txdone(machine_uart_obj_t *self) { return uart_txdone(self->uart_id); } -STATIC mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { +static mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); if (self->uart_id == 1) { @@ -258,7 +258,7 @@ STATIC mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t } } -STATIC mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { +static mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); const byte *buf = buf_in; @@ -279,7 +279,7 @@ STATIC mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_ return size; } -STATIC mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { machine_uart_obj_t *self = self_in; mp_uint_t ret; if (request == MP_STREAM_POLL) { diff --git a/ports/esp8266/machine_wdt.c b/ports/esp8266/machine_wdt.c index 074ee56598cf7..f9399e63ad3eb 100644 --- a/ports/esp8266/machine_wdt.c +++ b/ports/esp8266/machine_wdt.c @@ -34,9 +34,9 @@ typedef struct _machine_wdt_obj_t { mp_obj_base_t base; } machine_wdt_obj_t; -STATIC machine_wdt_obj_t wdt_default = {{&machine_wdt_type}}; +static machine_wdt_obj_t wdt_default = {{&machine_wdt_type}}; -STATIC machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t timeout_ms) { +static machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t timeout_ms) { // The timeout on ESP8266 is fixed, so raise an exception if the argument is not the default. if (timeout_ms != 5000) { mp_raise_ValueError(NULL); @@ -52,7 +52,7 @@ STATIC machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t } } -STATIC void mp_machine_wdt_feed(machine_wdt_obj_t *self) { +static void mp_machine_wdt_feed(machine_wdt_obj_t *self) { (void)self; system_soft_wdt_feed(); } diff --git a/ports/esp8266/main.c b/ports/esp8266/main.c index d774bbd35a7e3..2dd7c1dece3a4 100644 --- a/ports/esp8266/main.c +++ b/ports/esp8266/main.c @@ -47,9 +47,9 @@ #include "modespnow.h" #endif -STATIC char heap[38 * 1024]; +static char heap[38 * 1024]; -STATIC void mp_reset(void) { +static void mp_reset(void) { mp_stack_set_top((void *)0x40000000); mp_stack_set_limit(8192); mp_hal_init(); diff --git a/ports/esp8266/modesp.c b/ports/esp8266/modesp.c index 95595faebc792..f303da1a33289 100644 --- a/ports/esp8266/modesp.c +++ b/ports/esp8266/modesp.c @@ -46,7 +46,7 @@ void error_check(bool status, mp_rom_error_text_t msg) { } } -STATIC mp_obj_t esp_osdebug(mp_obj_t val) { +static mp_obj_t esp_osdebug(mp_obj_t val) { if (val == mp_const_none) { uart_os_config(-1); } else { @@ -54,9 +54,9 @@ STATIC mp_obj_t esp_osdebug(mp_obj_t val) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_osdebug_obj, esp_osdebug); +static MP_DEFINE_CONST_FUN_OBJ_1(esp_osdebug_obj, esp_osdebug); -STATIC mp_obj_t esp_sleep_type(size_t n_args, const mp_obj_t *args) { +static mp_obj_t esp_sleep_type(size_t n_args, const mp_obj_t *args) { if (n_args == 0) { return mp_obj_new_int(wifi_get_sleep_type()); } else { @@ -64,9 +64,9 @@ STATIC mp_obj_t esp_sleep_type(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_sleep_type_obj, 0, 1, esp_sleep_type); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_sleep_type_obj, 0, 1, esp_sleep_type); -STATIC mp_obj_t esp_deepsleep(size_t n_args, const mp_obj_t *args) { +static mp_obj_t esp_deepsleep(size_t n_args, const mp_obj_t *args) { uint32_t sleep_us = n_args > 0 ? mp_obj_get_int(args[0]) : 0; // prepare for RTC reset at wake up rtc_prepare_deepsleep(sleep_us); @@ -74,14 +74,14 @@ STATIC mp_obj_t esp_deepsleep(size_t n_args, const mp_obj_t *args) { system_deep_sleep(sleep_us); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_deepsleep_obj, 0, 2, esp_deepsleep); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_deepsleep_obj, 0, 2, esp_deepsleep); -STATIC mp_obj_t esp_flash_id() { +static mp_obj_t esp_flash_id() { return mp_obj_new_int(spi_flash_get_id()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_flash_id_obj, esp_flash_id); +static MP_DEFINE_CONST_FUN_OBJ_0(esp_flash_id_obj, esp_flash_id); -STATIC mp_obj_t esp_flash_read(mp_obj_t offset_in, mp_obj_t len_or_buf_in) { +static mp_obj_t esp_flash_read(mp_obj_t offset_in, mp_obj_t len_or_buf_in) { mp_int_t offset = mp_obj_get_int(offset_in); mp_int_t len; @@ -111,9 +111,9 @@ STATIC mp_obj_t esp_flash_read(mp_obj_t offset_in, mp_obj_t len_or_buf_in) { } mp_raise_OSError(res == SPI_FLASH_RESULT_TIMEOUT ? MP_ETIMEDOUT : MP_EIO); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp_flash_read_obj, esp_flash_read); +static MP_DEFINE_CONST_FUN_OBJ_2(esp_flash_read_obj, esp_flash_read); -STATIC mp_obj_t esp_flash_write(mp_obj_t offset_in, const mp_obj_t buf_in) { +static mp_obj_t esp_flash_write(mp_obj_t offset_in, const mp_obj_t buf_in) { mp_int_t offset = mp_obj_get_int(offset_in); mp_buffer_info_t bufinfo; mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ); @@ -128,9 +128,9 @@ STATIC mp_obj_t esp_flash_write(mp_obj_t offset_in, const mp_obj_t buf_in) { } mp_raise_OSError(res == SPI_FLASH_RESULT_TIMEOUT ? MP_ETIMEDOUT : MP_EIO); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp_flash_write_obj, esp_flash_write); +static MP_DEFINE_CONST_FUN_OBJ_2(esp_flash_write_obj, esp_flash_write); -STATIC mp_obj_t esp_flash_erase(mp_obj_t sector_in) { +static mp_obj_t esp_flash_erase(mp_obj_t sector_in) { mp_int_t sector = mp_obj_get_int(sector_in); ets_loop_iter(); // flash access takes time so run any pending tasks SpiFlashOpResult res = spi_flash_erase_sector(sector); @@ -140,9 +140,9 @@ STATIC mp_obj_t esp_flash_erase(mp_obj_t sector_in) { } mp_raise_OSError(res == SPI_FLASH_RESULT_TIMEOUT ? MP_ETIMEDOUT : MP_EIO); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_flash_erase_obj, esp_flash_erase); +static MP_DEFINE_CONST_FUN_OBJ_1(esp_flash_erase_obj, esp_flash_erase); -STATIC mp_obj_t esp_flash_size(void) { +static mp_obj_t esp_flash_size(void) { extern char flashchip; // For SDK 1.5.2, either address has shifted and not mirrored in // eagle.rom.addr.v6.ld, or extra initial member was added. @@ -157,7 +157,7 @@ STATIC mp_obj_t esp_flash_size(void) { #endif return mp_obj_new_int_from_uint(flash->chip_size); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_flash_size_obj, esp_flash_size); +static MP_DEFINE_CONST_FUN_OBJ_0(esp_flash_size_obj, esp_flash_size); // If there's just 1 loadable segment at the start of flash, // we assume there's a yaota8266 bootloader. @@ -165,12 +165,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_flash_size_obj, esp_flash_size); extern byte _firmware_size[]; -STATIC mp_obj_t esp_flash_user_start(void) { +static mp_obj_t esp_flash_user_start(void) { return MP_OBJ_NEW_SMALL_INT((uint32_t)_firmware_size); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_flash_user_start_obj, esp_flash_user_start); +static MP_DEFINE_CONST_FUN_OBJ_0(esp_flash_user_start_obj, esp_flash_user_start); -STATIC mp_obj_t esp_check_fw(void) { +static mp_obj_t esp_check_fw(void) { MD5_CTX ctx; char *fw_start = (char *)0x40200000; if (IS_OTA_FIRMWARE()) { @@ -195,10 +195,10 @@ STATIC mp_obj_t esp_check_fw(void) { printf("\n"); return mp_obj_new_bool(memcmp(digest, fw_start + size, sizeof(digest)) == 0); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_check_fw_obj, esp_check_fw); +static MP_DEFINE_CONST_FUN_OBJ_0(esp_check_fw_obj, esp_check_fw); #if MICROPY_ESP8266_APA102 -STATIC mp_obj_t esp_apa102_write_(mp_obj_t clockPin, mp_obj_t dataPin, mp_obj_t buf) { +static mp_obj_t esp_apa102_write_(mp_obj_t clockPin, mp_obj_t dataPin, mp_obj_t buf) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ); esp_apa102_write(mp_obj_get_pin(clockPin), @@ -206,35 +206,35 @@ STATIC mp_obj_t esp_apa102_write_(mp_obj_t clockPin, mp_obj_t dataPin, mp_obj_t (uint8_t *)bufinfo.buf, bufinfo.len); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp_apa102_write_obj, esp_apa102_write_); +static MP_DEFINE_CONST_FUN_OBJ_3(esp_apa102_write_obj, esp_apa102_write_); #endif -STATIC mp_obj_t esp_freemem() { +static mp_obj_t esp_freemem() { return MP_OBJ_NEW_SMALL_INT(system_get_free_heap_size()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_freemem_obj, esp_freemem); +static MP_DEFINE_CONST_FUN_OBJ_0(esp_freemem_obj, esp_freemem); -STATIC mp_obj_t esp_meminfo() { +static mp_obj_t esp_meminfo() { system_print_meminfo(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_meminfo_obj, esp_meminfo); +static MP_DEFINE_CONST_FUN_OBJ_0(esp_meminfo_obj, esp_meminfo); -STATIC mp_obj_t esp_malloc(mp_obj_t size_in) { +static mp_obj_t esp_malloc(mp_obj_t size_in) { return MP_OBJ_NEW_SMALL_INT((mp_uint_t)os_malloc(mp_obj_get_int(size_in))); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_malloc_obj, esp_malloc); +static MP_DEFINE_CONST_FUN_OBJ_1(esp_malloc_obj, esp_malloc); -STATIC mp_obj_t esp_free(mp_obj_t addr_in) { +static mp_obj_t esp_free(mp_obj_t addr_in) { os_free((void *)mp_obj_get_int(addr_in)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_free_obj, esp_free); +static MP_DEFINE_CONST_FUN_OBJ_1(esp_free_obj, esp_free); -STATIC mp_obj_t esp_esf_free_bufs(mp_obj_t idx_in) { +static mp_obj_t esp_esf_free_bufs(mp_obj_t idx_in) { return MP_OBJ_NEW_SMALL_INT(ets_esf_free_bufs(mp_obj_get_int(idx_in))); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_esf_free_bufs_obj, esp_esf_free_bufs); +static MP_DEFINE_CONST_FUN_OBJ_1(esp_esf_free_bufs_obj, esp_esf_free_bufs); #if MICROPY_EMIT_XTENSA || MICROPY_EMIT_INLINE_XTENSA @@ -257,11 +257,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_esf_free_bufs_obj, esp_esf_free_bufs); #define ESP_NATIVE_CODE_FLASH (1) extern uint32_t _lit4_end; -STATIC uint32_t esp_native_code_location; -STATIC uint32_t esp_native_code_start; -STATIC uint32_t esp_native_code_end; -STATIC uint32_t esp_native_code_cur; -STATIC uint32_t esp_native_code_erased; +static uint32_t esp_native_code_location; +static uint32_t esp_native_code_start; +static uint32_t esp_native_code_end; +static uint32_t esp_native_code_cur; +static uint32_t esp_native_code_erased; void esp_native_code_init(void) { esp_native_code_location = ESP_NATIVE_CODE_IRAM1; @@ -317,7 +317,7 @@ void *esp_native_code_commit(void *buf, size_t len, void *reloc) { return dest; } -STATIC mp_obj_t esp_set_native_code_location(mp_obj_t start_in, mp_obj_t len_in) { +static mp_obj_t esp_set_native_code_location(mp_obj_t start_in, mp_obj_t len_in) { if (start_in == mp_const_none && len_in == mp_const_none) { // use end of iram1 region esp_native_code_init(); @@ -335,11 +335,11 @@ STATIC mp_obj_t esp_set_native_code_location(mp_obj_t start_in, mp_obj_t len_in) } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp_set_native_code_location_obj, esp_set_native_code_location); +static MP_DEFINE_CONST_FUN_OBJ_2(esp_set_native_code_location_obj, esp_set_native_code_location); #endif -STATIC const mp_rom_map_elem_t esp_module_globals_table[] = { +static const mp_rom_map_elem_t esp_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_esp) }, { MP_ROM_QSTR(MP_QSTR_osdebug), MP_ROM_PTR(&esp_osdebug_obj) }, @@ -371,7 +371,7 @@ STATIC const mp_rom_map_elem_t esp_module_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(esp_module_globals, esp_module_globals_table); +static MP_DEFINE_CONST_DICT(esp_module_globals, esp_module_globals_table); const mp_obj_module_t esp_module = { .base = { &mp_type_module }, diff --git a/ports/esp8266/modespnow.c b/ports/esp8266/modespnow.c index 170e488c10a04..91510a3f9df14 100644 --- a/ports/esp8266/modespnow.c +++ b/ports/esp8266/modespnow.c @@ -142,21 +142,21 @@ static esp_espnow_obj_t *_get_singleton_initialised() { // Allocate and initialise the ESPNow module as a singleton. // Returns the initialised espnow_singleton. -STATIC mp_obj_t espnow_make_new(const mp_obj_type_t *type, size_t n_args, +static mp_obj_t espnow_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { return _get_singleton(); } // Forward declare the send and recv ESPNow callbacks -STATIC void send_cb(uint8_t *mac_addr, uint8_t status); +static void send_cb(uint8_t *mac_addr, uint8_t status); -STATIC void recv_cb(uint8_t *mac_addr, uint8_t *data, uint8_t len); +static void recv_cb(uint8_t *mac_addr, uint8_t *data, uint8_t len); // ESPNow.deinit(): De-initialise the ESPNOW software stack, disable callbacks // and deallocate the recv data buffers. // Note: this function is called from main.c:mp_task() to cleanup before soft -// reset, so cannot be declared STATIC and must guard against self == NULL;. +// reset, so cannot be declared static and must guard against self == NULL;. mp_obj_t espnow_deinit(mp_obj_t _) { esp_espnow_obj_t *self = _get_singleton(); if (self->recv_buffer != NULL) { @@ -174,7 +174,7 @@ mp_obj_t espnow_deinit(mp_obj_t _) { // Initialise the Espressif ESPNOW software stack, register callbacks and // allocate the recv data buffers. // Returns True if interface is active, else False. -STATIC mp_obj_t espnow_active(size_t n_args, const mp_obj_t *args) { +static mp_obj_t espnow_active(size_t n_args, const mp_obj_t *args) { esp_espnow_obj_t *self = args[0]; if (n_args > 1) { if (mp_obj_is_true(args[1])) { @@ -193,13 +193,13 @@ STATIC mp_obj_t espnow_active(size_t n_args, const mp_obj_t *args) { } return mp_obj_new_bool(self->recv_buffer != NULL); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_active_obj, 1, 2, espnow_active); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_active_obj, 1, 2, espnow_active); // ESPNow.config(): Initialise the data buffers and ESP-NOW functions. // Initialise the Espressif ESPNOW software stack, register callbacks and // allocate the recv data buffers. // Returns True if interface is active, else False. -STATIC mp_obj_t espnow_config(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t espnow_config(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { esp_espnow_obj_t *self = _get_singleton(); enum { ARG_rxbuf, ARG_timeout_ms }; static const mp_arg_t allowed_args[] = { @@ -217,7 +217,7 @@ STATIC mp_obj_t espnow_config(size_t n_args, const mp_obj_t *pos_args, mp_map_t } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(espnow_config_obj, 1, espnow_config); +static MP_DEFINE_CONST_FUN_OBJ_KW(espnow_config_obj, 1, espnow_config); // ### The ESP_Now send and recv callback routines // @@ -225,7 +225,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(espnow_config_obj, 1, espnow_config); // Callback triggered when a sent packet is acknowledged by the peer (or not). // Just count the number of responses and number of failures. // These are used in the send()/write() logic. -STATIC void send_cb(uint8_t *mac_addr, uint8_t status) { +static void send_cb(uint8_t *mac_addr, uint8_t status) { esp_espnow_obj_t *self = _get_singleton(); self->tx_responses++; if (status != ESP_NOW_SEND_SUCCESS) { @@ -238,7 +238,7 @@ STATIC void send_cb(uint8_t *mac_addr, uint8_t status) { // ESPNow packet. // If the buffer is full, drop the message and increment the dropped count. // Schedules the user callback if one has been registered (ESPNow.config()). -STATIC void recv_cb(uint8_t *mac_addr, uint8_t *msg, uint8_t msg_len) { +static void recv_cb(uint8_t *mac_addr, uint8_t *msg, uint8_t msg_len) { esp_espnow_obj_t *self = _get_singleton(); ringbuf_t *buf = self->recv_buffer; // TODO: Test this works with ">". @@ -298,7 +298,7 @@ static int ringbuf_get_bytes_wait(ringbuf_t *r, uint8_t *data, size_t len, mp_in // buffers: list of bytearrays to store values: [peer, message]. // Default timeout is set with ESPNow.config(timeout=milliseconds). // Return (None, None) on timeout. -STATIC mp_obj_t espnow_recvinto(size_t n_args, const mp_obj_t *args) { +static mp_obj_t espnow_recvinto(size_t n_args, const mp_obj_t *args) { esp_espnow_obj_t *self = _get_singleton_initialised(); size_t timeout_ms = ((n_args > 2 && args[2] != mp_const_none) @@ -339,7 +339,7 @@ STATIC mp_obj_t espnow_recvinto(size_t n_args, const mp_obj_t *args) { return MP_OBJ_NEW_SMALL_INT(msg_len); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_recvinto_obj, 2, 3, espnow_recvinto); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_recvinto_obj, 2, 3, espnow_recvinto); // Used by espnow_send() for sends() with sync==True. // Wait till all pending sent packet responses have been received. @@ -365,7 +365,7 @@ static void _wait_for_pending_responses(esp_espnow_obj_t *self) { // True if sync==True and message is received successfully by all recipients // False if sync==True and message is not received by at least one recipient // Raises: EAGAIN if the internal espnow buffers are full. -STATIC mp_obj_t espnow_send(size_t n_args, const mp_obj_t *args) { +static mp_obj_t espnow_send(size_t n_args, const mp_obj_t *args) { esp_espnow_obj_t *self = _get_singleton_initialised(); bool sync = n_args <= 3 || args[3] == mp_const_none || mp_obj_is_true(args[3]); @@ -402,7 +402,7 @@ STATIC mp_obj_t espnow_send(size_t n_args, const mp_obj_t *args) { // Return False if sync and any peers did not respond. return mp_obj_new_bool(!(sync && self->tx_failures != saved_failures)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_send_obj, 3, 4, espnow_send); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_send_obj, 3, 4, espnow_send); // ### Peer Management Functions // @@ -410,11 +410,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_send_obj, 3, 4, espnow_send); // Set the ESP-NOW Primary Master Key (pmk) (for encrypted communications). // Raise OSError if not initialised. // Raise ValueError if key is not a bytes-like object exactly 16 bytes long. -STATIC mp_obj_t espnow_set_pmk(mp_obj_t _, mp_obj_t key) { +static mp_obj_t espnow_set_pmk(mp_obj_t _, mp_obj_t key) { check_esp_err(esp_now_set_kok(_get_bytes_len(key, ESP_NOW_KEY_LEN), ESP_NOW_KEY_LEN)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(espnow_set_pmk_obj, espnow_set_pmk); +static MP_DEFINE_CONST_FUN_OBJ_2(espnow_set_pmk_obj, espnow_set_pmk); // ESPNow.add_peer(peer_mac, [lmk, [channel, [ifidx, [encrypt]]]]) // Positional args set to None will be left at defaults. @@ -422,7 +422,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(espnow_set_pmk_obj, espnow_set_pmk); // Raise ValueError if mac or LMK are not bytes-like objects or wrong length. // Raise TypeError if invalid keyword args or too many positional args. // Return None. -STATIC mp_obj_t espnow_add_peer(size_t n_args, const mp_obj_t *args) { +static mp_obj_t espnow_add_peer(size_t n_args, const mp_obj_t *args) { check_esp_err( esp_now_add_peer( _get_bytes_len(args[1], ESP_NOW_ETH_ALEN), @@ -433,19 +433,19 @@ STATIC mp_obj_t espnow_add_peer(size_t n_args, const mp_obj_t *args) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_add_peer_obj, 2, 4, espnow_add_peer); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_add_peer_obj, 2, 4, espnow_add_peer); // ESPNow.del_peer(peer_mac): Unregister peer_mac. // Raise OSError if not initialised. // Raise ValueError if peer is not a bytes-like objects or wrong length. // Return None. -STATIC mp_obj_t espnow_del_peer(mp_obj_t _, mp_obj_t peer) { +static mp_obj_t espnow_del_peer(mp_obj_t _, mp_obj_t peer) { esp_now_del_peer(_get_bytes_len(peer, ESP_NOW_ETH_ALEN)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(espnow_del_peer_obj, espnow_del_peer); +static MP_DEFINE_CONST_FUN_OBJ_2(espnow_del_peer_obj, espnow_del_peer); -STATIC const mp_rom_map_elem_t esp_espnow_locals_dict_table[] = { +static const mp_rom_map_elem_t esp_espnow_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&espnow_active_obj) }, { MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&espnow_config_obj) }, { MP_ROM_QSTR(MP_QSTR_recvinto), MP_ROM_PTR(&espnow_recvinto_obj) }, @@ -456,9 +456,9 @@ STATIC const mp_rom_map_elem_t esp_espnow_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_add_peer), MP_ROM_PTR(&espnow_add_peer_obj) }, { MP_ROM_QSTR(MP_QSTR_del_peer), MP_ROM_PTR(&espnow_del_peer_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(esp_espnow_locals_dict, esp_espnow_locals_dict_table); +static MP_DEFINE_CONST_DICT(esp_espnow_locals_dict, esp_espnow_locals_dict_table); -STATIC const mp_rom_map_elem_t espnow_globals_dict_table[] = { +static const mp_rom_map_elem_t espnow_globals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__espnow) }, { MP_ROM_QSTR(MP_QSTR_ESPNowBase), MP_ROM_PTR(&esp_espnow_type) }, { MP_ROM_QSTR(MP_QSTR_MAX_DATA_LEN), MP_ROM_INT(ESP_NOW_MAX_DATA_LEN)}, @@ -467,13 +467,13 @@ STATIC const mp_rom_map_elem_t espnow_globals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_MAX_TOTAL_PEER_NUM), MP_ROM_INT(ESP_NOW_MAX_TOTAL_PEER_NUM)}, { MP_ROM_QSTR(MP_QSTR_MAX_ENCRYPT_PEER_NUM), MP_ROM_INT(ESP_NOW_MAX_ENCRYPT_PEER_NUM)}, }; -STATIC MP_DEFINE_CONST_DICT(espnow_globals_dict, espnow_globals_dict_table); +static MP_DEFINE_CONST_DICT(espnow_globals_dict, espnow_globals_dict_table); // ### Dummy Buffer Protocol support // ...so asyncio can poll.ipoll() on this device // Support ioctl(MP_STREAM_POLL, ) for asyncio -STATIC mp_uint_t espnow_stream_ioctl(mp_obj_t self_in, mp_uint_t request, +static mp_uint_t espnow_stream_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { if (request != MP_STREAM_POLL) { *errcode = MP_EINVAL; @@ -484,7 +484,7 @@ STATIC mp_uint_t espnow_stream_ioctl(mp_obj_t self_in, mp_uint_t request, arg ^ ((ringbuf_avail(self->recv_buffer) == 0) ? MP_STREAM_POLL_RD : 0); } -STATIC const mp_stream_p_t espnow_stream_p = { +static const mp_stream_p_t espnow_stream_p = { .ioctl = espnow_stream_ioctl, }; diff --git a/ports/esp8266/modmachine.c b/ports/esp8266/modmachine.c index 3cf5e3dd3bc54..23ccf8cebfb0d 100644 --- a/ports/esp8266/modmachine.c +++ b/ports/esp8266/modmachine.c @@ -59,11 +59,11 @@ { MP_ROM_QSTR(MP_QSTR_WDT_RESET), MP_ROM_INT(REASON_WDT_RST) }, \ { MP_ROM_QSTR(MP_QSTR_SOFT_RESET), MP_ROM_INT(REASON_SOFT_RESTART) }, \ -STATIC mp_obj_t mp_machine_get_freq(void) { +static mp_obj_t mp_machine_get_freq(void) { return mp_obj_new_int(system_get_cpu_freq() * 1000000); } -STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) { +static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) { mp_int_t freq = mp_obj_get_int(args[0]) / 1000000; if (freq != 80 && freq != 160) { mp_raise_ValueError(MP_ERROR_TEXT("frequency can only be either 80Mhz or 160MHz")); @@ -71,7 +71,7 @@ STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) { system_update_cpu_freq(freq); } -NORETURN STATIC void mp_machine_reset(void) { +NORETURN static void mp_machine_reset(void) { system_restart(); // we must not return @@ -80,21 +80,21 @@ NORETURN STATIC void mp_machine_reset(void) { } } -STATIC mp_int_t mp_machine_reset_cause(void) { +static mp_int_t mp_machine_reset_cause(void) { return system_get_rst_info()->reason; } -STATIC mp_obj_t mp_machine_unique_id(void) { +static mp_obj_t mp_machine_unique_id(void) { uint32_t id = system_get_chip_id(); return mp_obj_new_bytes((byte *)&id, sizeof(id)); } -STATIC void mp_machine_idle(void) { +static void mp_machine_idle(void) { asm ("waiti 0"); mp_event_handle_nowait(); // handle any events after possibly a long wait (eg feed WDT) } -STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) { +static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) { uint32_t max_us = 0xffffffff; if (n_args == 1) { mp_int_t max_ms = mp_obj_get_int(args[0]); @@ -114,7 +114,7 @@ STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) { } } -NORETURN STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) { +NORETURN static void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) { // default to sleep forever uint32_t sleep_us = 0; @@ -172,7 +172,7 @@ typedef struct _esp_timer_obj_t { mp_obj_t callback; } esp_timer_obj_t; -STATIC void esp_timer_arm_ms(esp_timer_obj_t *self, uint32_t ms, bool repeat) { +static void esp_timer_arm_ms(esp_timer_obj_t *self, uint32_t ms, bool repeat) { if (ms <= ESP_TIMER_MS_MAX) { self->remain_ms = 0; self->period_ms = 0; @@ -189,7 +189,7 @@ STATIC void esp_timer_arm_ms(esp_timer_obj_t *self, uint32_t ms, bool repeat) { os_timer_arm(&self->timer, ms, repeat); } -STATIC void esp_timer_arm_us(esp_timer_obj_t *self, uint32_t us, bool repeat) { +static void esp_timer_arm_us(esp_timer_obj_t *self, uint32_t us, bool repeat) { if (us < ESP_TIMER_US_MIN) { us = ESP_TIMER_US_MIN; } @@ -204,18 +204,18 @@ STATIC void esp_timer_arm_us(esp_timer_obj_t *self, uint32_t us, bool repeat) { const mp_obj_type_t esp_timer_type; -STATIC void esp_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void esp_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { esp_timer_obj_t *self = self_in; mp_printf(print, "Timer(%p)", &self->timer); } -STATIC mp_obj_t esp_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t esp_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 1, false); esp_timer_obj_t *tim = mp_obj_malloc(esp_timer_obj_t, &esp_timer_type); return tim; } -STATIC void esp_timer_cb(void *arg) { +static void esp_timer_cb(void *arg) { esp_timer_obj_t *self = arg; if (self->remain_ms != 0) { // Handle periods larger than the maximum system period @@ -234,7 +234,7 @@ STATIC void esp_timer_cb(void *arg) { } } -STATIC mp_obj_t esp_timer_init_helper(esp_timer_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t esp_timer_init_helper(esp_timer_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_mode, ARG_callback, @@ -298,26 +298,26 @@ STATIC mp_obj_t esp_timer_init_helper(esp_timer_obj_t *self, size_t n_args, cons return mp_const_none; } -STATIC mp_obj_t esp_timer_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t esp_timer_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { return esp_timer_init_helper(args[0], n_args - 1, args + 1, kw_args); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(esp_timer_init_obj, 1, esp_timer_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(esp_timer_init_obj, 1, esp_timer_init); -STATIC mp_obj_t esp_timer_deinit(mp_obj_t self_in) { +static mp_obj_t esp_timer_deinit(mp_obj_t self_in) { esp_timer_obj_t *self = self_in; os_timer_disarm(&self->timer); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_timer_deinit_obj, esp_timer_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(esp_timer_deinit_obj, esp_timer_deinit); -STATIC const mp_rom_map_elem_t esp_timer_locals_dict_table[] = { +static const mp_rom_map_elem_t esp_timer_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&esp_timer_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&esp_timer_init_obj) }, // { MP_ROM_QSTR(MP_QSTR_callback), MP_ROM_PTR(&esp_timer_callback_obj) }, { MP_ROM_QSTR(MP_QSTR_ONE_SHOT), MP_ROM_INT(false) }, { MP_ROM_QSTR(MP_QSTR_PERIODIC), MP_ROM_INT(true) }, }; -STATIC MP_DEFINE_CONST_DICT(esp_timer_locals_dict, esp_timer_locals_dict_table); +static MP_DEFINE_CONST_DICT(esp_timer_locals_dict, esp_timer_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( esp_timer_type, diff --git a/ports/esp8266/modos.c b/ports/esp8266/modos.c index 32c6a066761ee..8149c087fd24f 100644 --- a/ports/esp8266/modos.c +++ b/ports/esp8266/modos.c @@ -31,11 +31,11 @@ #include "extmod/modmachine.h" #include "user_interface.h" -STATIC const char *mp_os_uname_release(void) { +static const char *mp_os_uname_release(void) { return system_get_sdk_version(); } -STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { +static mp_obj_t mp_os_urandom(mp_obj_t num) { mp_int_t n = mp_obj_get_int(num); vstr_t vstr; vstr_init_len(&vstr, n); @@ -44,7 +44,7 @@ STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { } return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); void mp_os_dupterm_stream_detached_attached(mp_obj_t stream_detached, mp_obj_t stream_attached) { if (mp_obj_get_type(stream_attached) == &machine_uart_type) { diff --git a/ports/esp8266/modtime.c b/ports/esp8266/modtime.c index 21dd3cbcd9099..090300559751b 100644 --- a/ports/esp8266/modtime.c +++ b/ports/esp8266/modtime.c @@ -30,7 +30,7 @@ #include "modmachine.h" // Return the localtime as an 8-tuple. -STATIC mp_obj_t mp_time_localtime_get(void) { +static mp_obj_t mp_time_localtime_get(void) { mp_int_t seconds = pyb_rtc_get_us_since_epoch() / 1000 / 1000; timeutils_struct_time_t tm; timeutils_seconds_since_epoch_to_struct_time(seconds, &tm); @@ -48,7 +48,7 @@ STATIC mp_obj_t mp_time_localtime_get(void) { } // Returns the number of seconds, as an integer, since the Epoch. -STATIC mp_obj_t mp_time_time_get(void) { +static mp_obj_t mp_time_time_get(void) { // get date and time return mp_obj_new_int(pyb_rtc_get_us_since_epoch() / 1000 / 1000); } diff --git a/ports/esp8266/network_wlan.c b/ports/esp8266/network_wlan.c index b0e6b3aeb1753..5838cc8bc6a86 100644 --- a/ports/esp8266/network_wlan.c +++ b/ports/esp8266/network_wlan.c @@ -48,19 +48,19 @@ typedef struct _wlan_if_obj_t { void error_check(bool status, const char *msg); -STATIC const wlan_if_obj_t wlan_objs[] = { +static const wlan_if_obj_t wlan_objs[] = { {{&esp_network_wlan_type}, STATION_IF}, {{&esp_network_wlan_type}, SOFTAP_IF}, }; -STATIC void require_if(mp_obj_t wlan_if, int if_no) { +static void require_if(mp_obj_t wlan_if, int if_no) { wlan_if_obj_t *self = MP_OBJ_TO_PTR(wlan_if); if (self->if_id != if_no) { error_check(false, if_no == STATION_IF ? "STA required" : "AP required"); } } -STATIC mp_obj_t esp_wlan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t esp_wlan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); int idx = 0; if (n_args > 0) { @@ -72,7 +72,7 @@ STATIC mp_obj_t esp_wlan_make_new(const mp_obj_type_t *type, size_t n_args, size return MP_OBJ_FROM_PTR(&wlan_objs[idx]); } -STATIC mp_obj_t esp_active(size_t n_args, const mp_obj_t *args) { +static mp_obj_t esp_active(size_t n_args, const mp_obj_t *args) { wlan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]); uint32_t mode = wifi_get_opmode(); if (n_args > 1) { @@ -105,9 +105,9 @@ STATIC mp_obj_t esp_active(size_t n_args, const mp_obj_t *args) { return mp_obj_new_bool(mode & SOFTAP_MODE); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_active_obj, 1, 2, esp_active); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_active_obj, 1, 2, esp_active); -STATIC mp_obj_t esp_connect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t esp_connect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_ssid, ARG_key, ARG_bssid }; static const mp_arg_t allowed_args[] = { { MP_QSTR_, MP_ARG_OBJ, {.u_obj = mp_const_none} }, @@ -158,16 +158,16 @@ STATIC mp_obj_t esp_connect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(esp_connect_obj, 1, esp_connect); +static MP_DEFINE_CONST_FUN_OBJ_KW(esp_connect_obj, 1, esp_connect); -STATIC mp_obj_t esp_disconnect(mp_obj_t self_in) { +static mp_obj_t esp_disconnect(mp_obj_t self_in) { require_if(self_in, STATION_IF); error_check(wifi_station_disconnect(), "Cannot disconnect from AP"); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_disconnect_obj, esp_disconnect); +static MP_DEFINE_CONST_FUN_OBJ_1(esp_disconnect_obj, esp_disconnect); -STATIC mp_obj_t esp_status(size_t n_args, const mp_obj_t *args) { +static mp_obj_t esp_status(size_t n_args, const mp_obj_t *args) { wlan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 1) { // Get link status @@ -186,11 +186,11 @@ STATIC mp_obj_t esp_status(size_t n_args, const mp_obj_t *args) { mp_raise_ValueError(MP_ERROR_TEXT("unknown status param")); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_status_obj, 1, 2, esp_status); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_status_obj, 1, 2, esp_status); -STATIC mp_obj_t *esp_scan_list = NULL; +static mp_obj_t *esp_scan_list = NULL; -STATIC void esp_scan_cb(void *result, STATUS status) { +static void esp_scan_cb(void *result, STATUS status) { if (esp_scan_list == NULL) { // called unexpectedly return; @@ -228,7 +228,7 @@ STATIC void esp_scan_cb(void *result, STATUS status) { esp_scan_list = NULL; } -STATIC mp_obj_t esp_scan(mp_obj_t self_in) { +static mp_obj_t esp_scan(mp_obj_t self_in) { require_if(self_in, STATION_IF); if ((wifi_get_opmode() & STATION_MODE) == 0) { mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("STA must be active")); @@ -252,12 +252,12 @@ STATIC mp_obj_t esp_scan(mp_obj_t self_in) { } return list; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_scan_obj, esp_scan); +static MP_DEFINE_CONST_FUN_OBJ_1(esp_scan_obj, esp_scan); /// \method isconnected() /// Return True if connected to an AP and an IP address has been assigned, /// false otherwise. -STATIC mp_obj_t esp_isconnected(mp_obj_t self_in) { +static mp_obj_t esp_isconnected(mp_obj_t self_in) { wlan_if_obj_t *self = MP_OBJ_TO_PTR(self_in); if (self->if_id == STATION_IF) { if (wifi_station_get_connect_status() == STATION_GOT_IP) { @@ -271,9 +271,9 @@ STATIC mp_obj_t esp_isconnected(mp_obj_t self_in) { return mp_const_false; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_isconnected_obj, esp_isconnected); +static MP_DEFINE_CONST_FUN_OBJ_1(esp_isconnected_obj, esp_isconnected); -STATIC mp_obj_t esp_ifconfig(size_t n_args, const mp_obj_t *args) { +static mp_obj_t esp_ifconfig(size_t n_args, const mp_obj_t *args) { wlan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]); struct ip_info info; ip_addr_t dns_addr; @@ -328,9 +328,9 @@ STATIC mp_obj_t esp_ifconfig(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_ifconfig_obj, 1, 2, esp_ifconfig); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_ifconfig_obj, 1, 2, esp_ifconfig); -STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { +static mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { if (n_args != 1 && kwargs->used != 0) { mp_raise_TypeError(MP_ERROR_TEXT("either pos or kw args are allowed")); } @@ -503,9 +503,9 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs unknown: mp_raise_ValueError(MP_ERROR_TEXT("unknown config param")); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(esp_config_obj, 1, esp_config); +static MP_DEFINE_CONST_FUN_OBJ_KW(esp_config_obj, 1, esp_config); -STATIC const mp_rom_map_elem_t wlan_if_locals_dict_table[] = { +static const mp_rom_map_elem_t wlan_if_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&esp_active_obj) }, { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&esp_connect_obj) }, { MP_ROM_QSTR(MP_QSTR_disconnect), MP_ROM_PTR(&esp_disconnect_obj) }, @@ -521,7 +521,7 @@ STATIC const mp_rom_map_elem_t wlan_if_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_PM_POWERSAVE), MP_ROM_INT(LIGHT_SLEEP_T) }, }; -STATIC MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table); +static MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( esp_network_wlan_type, @@ -531,7 +531,7 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &wlan_if_locals_dict ); -STATIC mp_obj_t esp_phy_mode(size_t n_args, const mp_obj_t *args) { +static mp_obj_t esp_phy_mode(size_t n_args, const mp_obj_t *args) { if (n_args == 0) { return mp_obj_new_int(wifi_get_phy_mode()); } else { diff --git a/ports/mimxrt/dma_manager.c b/ports/mimxrt/dma_manager.c index 2890a155864ff..d332c9a1c2888 100644 --- a/ports/mimxrt/dma_manager.c +++ b/ports/mimxrt/dma_manager.c @@ -42,7 +42,7 @@ static bool channel_list[FSL_FEATURE_DMAMUX_MODULE_CHANNEL] = { #endif }; -STATIC bool dma_initialized = false; +static bool dma_initialized = false; // allocate_channel(): retrieve an available channel. Return the number or -1 int allocate_dma_channel(void) { diff --git a/ports/mimxrt/eth.c b/ports/mimxrt/eth.c index ed9db81298094..3eb1a0cc35202 100644 --- a/ports/mimxrt/eth.c +++ b/ports/mimxrt/eth.c @@ -177,7 +177,7 @@ static uint8_t hw_addr_1[6]; // The MAC address field #define TRACE_ETH_RX (0x0004) #define TRACE_ETH_FULL (0x0008) -STATIC void eth_trace(eth_t *self, size_t len, const void *data, unsigned int flags) { +static void eth_trace(eth_t *self, size_t len, const void *data, unsigned int flags) { if (((flags & NETUTILS_TRACE_IS_TX) && (self->trace_flags & TRACE_ETH_TX)) || (!(flags & NETUTILS_TRACE_IS_TX) && (self->trace_flags & TRACE_ETH_RX))) { const uint8_t *buf; @@ -197,7 +197,7 @@ STATIC void eth_trace(eth_t *self, size_t len, const void *data, unsigned int fl } } -STATIC void eth_process_frame(eth_t *self, uint8_t *buf, size_t length) { +static void eth_process_frame(eth_t *self, uint8_t *buf, size_t length) { struct netif *netif = &self->netif; if (netif->flags & NETIF_FLAG_LINK_UP) { @@ -240,7 +240,7 @@ void eth_irq_handler(ENET_Type *base, enet_handle_t *handle, } // Configure the ethernet clock -STATIC uint32_t eth_clock_init(int eth_id, bool phy_clock) { +static uint32_t eth_clock_init(int eth_id, bool phy_clock) { CLOCK_EnableClock(kCLOCK_Iomuxc); @@ -282,7 +282,7 @@ STATIC uint32_t eth_clock_init(int eth_id, bool phy_clock) { } // eth_gpio_init: Configure the GPIO pins -STATIC void eth_gpio_init(const iomux_table_t iomux_table[], size_t iomux_table_size, +static void eth_gpio_init(const iomux_table_t iomux_table[], size_t iomux_table_size, const machine_pin_obj_t *reset_pin, const machine_pin_obj_t *int_pin) { gpio_pin_config_t gpio_config = {kGPIO_DigitalOutput, 1, kGPIO_NoIntmode}; @@ -328,7 +328,7 @@ STATIC void eth_gpio_init(const iomux_table_t iomux_table[], size_t iomux_table_ } // eth_phy_init: Initilaize the PHY interface -STATIC void eth_phy_init(phy_handle_t *phyHandle, phy_config_t *phy_config, +static void eth_phy_init(phy_handle_t *phyHandle, phy_config_t *phy_config, phy_speed_t *speed, phy_duplex_t *duplex, uint32_t phy_settle_time) { bool link = false; @@ -471,12 +471,12 @@ void eth_init_1(eth_t *self, int eth_id, const phy_operations_t *phy_ops, int ph #endif // Initialize the phy interface -STATIC int eth_mac_init(eth_t *self) { +static int eth_mac_init(eth_t *self) { return 0; } // Deinit the interface -STATIC void eth_mac_deinit(eth_t *self) { +static void eth_mac_deinit(eth_t *self) { // Just as a reminder: Calling ENET_Deinit() twice causes the board to stall // with a bus error. Reason unclear. So don't do that for now (or ever). } @@ -488,7 +488,7 @@ void eth_set_trace(eth_t *self, uint32_t value) { /*******************************************************************************/ // ETH-LwIP bindings -STATIC err_t eth_send_frame_blocking(ENET_Type *base, enet_handle_t *handle, uint8_t *buffer, int len) { +static err_t eth_send_frame_blocking(ENET_Type *base, enet_handle_t *handle, uint8_t *buffer, int len) { status_t status; int i; #define XMIT_LOOP 10 @@ -504,7 +504,7 @@ STATIC err_t eth_send_frame_blocking(ENET_Type *base, enet_handle_t *handle, uin return status; } -STATIC err_t eth_netif_output(struct netif *netif, struct pbuf *p) { +static err_t eth_netif_output(struct netif *netif, struct pbuf *p) { // This function should always be called from a context where PendSV-level IRQs are disabled status_t status; ENET_Type *enet = ENET; @@ -536,7 +536,7 @@ STATIC err_t eth_netif_output(struct netif *netif, struct pbuf *p) { return status == kStatus_Success ? ERR_OK : ERR_BUF; } -STATIC err_t eth_netif_init(struct netif *netif) { +static err_t eth_netif_init(struct netif *netif) { netif->linkoutput = eth_netif_output; netif->output = etharp_output; netif->mtu = 1500; @@ -552,7 +552,7 @@ STATIC err_t eth_netif_init(struct netif *netif) { return ERR_OK; } -STATIC void eth_lwip_init(eth_t *self) { +static void eth_lwip_init(eth_t *self) { struct netif *n = &self->netif; ip_addr_t ipconfig[4]; @@ -588,7 +588,7 @@ STATIC void eth_lwip_init(eth_t *self) { MICROPY_PY_LWIP_EXIT } -STATIC void eth_lwip_deinit(eth_t *self) { +static void eth_lwip_deinit(eth_t *self) { MICROPY_PY_LWIP_ENTER for (struct netif *netif = netif_list; netif != NULL; netif = netif->next) { if (netif == &self->netif) { diff --git a/ports/mimxrt/machine_adc.c b/ports/mimxrt/machine_adc.c index 0be5f9a7d2beb..29b73a20652ce 100644 --- a/ports/mimxrt/machine_adc.c +++ b/ports/mimxrt/machine_adc.c @@ -49,9 +49,9 @@ typedef struct _machine_adc_obj_t { uint16_t resolution; } machine_adc_obj_t; -STATIC ADC_Type *const adc_bases[] = ADC_BASE_PTRS; +static ADC_Type *const adc_bases[] = ADC_BASE_PTRS; -STATIC void mp_machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; machine_adc_obj_t *self = MP_OBJ_TO_PTR(self_in); @@ -64,7 +64,7 @@ STATIC void mp_machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_p } } -STATIC mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { mp_arg_check_num(n_args, n_kw, 1, 1, false); // Unpack and check parameter @@ -99,7 +99,7 @@ STATIC mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args // read_u16() #if defined(MIMXRT117x_SERIES) -STATIC mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) { +static mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) { lpadc_conv_command_config_t adc_config; lpadc_conv_trigger_config_t trigger_config; @@ -133,7 +133,7 @@ void machine_adc_init(void) { #else -STATIC mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) { +static mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) { // Initiate conversion adc_channel_config_t channel_config = { .channelNumber = self->channel, diff --git a/ports/mimxrt/machine_i2c.c b/ports/mimxrt/machine_i2c.c index cef17272c4a22..89fe47dbf60c1 100644 --- a/ports/mimxrt/machine_i2c.c +++ b/ports/mimxrt/machine_i2c.c @@ -55,8 +55,8 @@ typedef struct _iomux_table_t { uint32_t configRegister; } iomux_table_t; -STATIC const uint8_t i2c_index_table[] = MICROPY_HW_I2C_INDEX; -STATIC LPI2C_Type *i2c_base_ptr_table[] = LPI2C_BASE_PTRS; +static const uint8_t i2c_index_table[] = MICROPY_HW_I2C_INDEX; +static LPI2C_Type *i2c_base_ptr_table[] = LPI2C_BASE_PTRS; static const iomux_table_t iomux_table[] = { IOMUX_TABLE_I2C }; #define MICROPY_HW_I2C_NUM ARRAY_SIZE(i2c_index_table) @@ -80,7 +80,7 @@ bool lpi2c_set_iomux(int8_t hw_i2c, uint8_t drive) { } } -STATIC void machine_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "I2C(%u, freq=%u)", self->i2c_id, self->master_config->baudRate_Hz); @@ -133,7 +133,7 @@ static void lpi2c_master_callback(LPI2C_Type *base, lpi2c_master_handle_t *handl self->transfer_status = status; } -STATIC int machine_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, size_t len, uint8_t *buf, unsigned int flags) { +static int machine_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, size_t len, uint8_t *buf, unsigned int flags) { machine_i2c_obj_t *self = (machine_i2c_obj_t *)self_in; status_t ret; lpi2c_master_handle_t g_master_handle; @@ -185,7 +185,7 @@ STATIC int machine_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, si } } -STATIC const mp_machine_i2c_p_t machine_i2c_p = { +static const mp_machine_i2c_p_t machine_i2c_p = { .transfer = mp_machine_i2c_transfer_adaptor, .transfer_single = machine_i2c_transfer_single, }; diff --git a/ports/mimxrt/machine_i2s.c b/ports/mimxrt/machine_i2s.c index 077c9e76fa8e6..8553cb285b668 100644 --- a/ports/mimxrt/machine_i2s.c +++ b/ports/mimxrt/machine_i2s.c @@ -126,12 +126,12 @@ typedef struct _i2s_clock_config_t { uint32_t clock_divider; } i2s_clock_config_t; -STATIC mp_obj_t machine_i2s_deinit(mp_obj_t self_in); +static mp_obj_t machine_i2s_deinit(mp_obj_t self_in); // The frame map is used with the readinto() method to transform the audio sample data coming // from DMA memory (32-bit stereo) to the format specified // in the I2S constructor. e.g. 16-bit mono -STATIC const int8_t i2s_frame_map[NUM_I2S_USER_FORMATS][I2S_RX_FRAME_SIZE_IN_BYTES] = { +static const int8_t i2s_frame_map[NUM_I2S_USER_FORMATS][I2S_RX_FRAME_SIZE_IN_BYTES] = { {-1, -1, 0, 1, -1, -1, -1, -1 }, // Mono, 16-bits { 0, 1, 2, 3, -1, -1, -1, -1 }, // Mono, 32-bits {-1, -1, 0, 1, -1, -1, 2, 3 }, // Stereo, 16-bits @@ -143,7 +143,7 @@ STATIC const int8_t i2s_frame_map[NUM_I2S_USER_FORMATS][I2S_RX_FRAME_SIZE_IN_BYT // Configuration 1: for sampling frequencies [Hz]: 8000, 12000, 16000, 24000, 32000, 48000 // Clock frequency = 786,432,000 Hz = 48000 * 64 * 256 -STATIC const clock_audio_pll_config_t audioPllConfig_8000_48000 = { +static const clock_audio_pll_config_t audioPllConfig_8000_48000 = { .loopDivider = 32, // PLL loop divider. Valid range for DIV_SELECT divider value: 27~54 .postDivider = 1, // Divider after the PLL, should only be 1, 2, 4, 8, 16 .numerator = 76800, // 30 bit numerator of fractional loop divider @@ -155,7 +155,7 @@ STATIC const clock_audio_pll_config_t audioPllConfig_8000_48000 = { // Configuration 2: for sampling frequencies [Hz]: 11025, 22050, 44100 // Clock frequency = 722,534,400 = 44100 * 64 * 256 -STATIC const clock_audio_pll_config_t audioPllConfig_11025_44100 = { +static const clock_audio_pll_config_t audioPllConfig_11025_44100 = { .loopDivider = 30, // PLL loop divider. Valid range for DIV_SELECT divider value: 27~54 .postDivider = 1, // Divider after the PLL, should only be 1, 2, 4, 8, 16 .numerator = 10560, // 30 bit numerator of fractional loop divider @@ -170,7 +170,7 @@ STATIC const clock_audio_pll_config_t audioPllConfig_11025_44100 = { // which is 2**n: 0->1, 1->2, 2->4, 3->8, 4->16, 5->32 // The divider is 8 bit and must be given as n (not n-1) // So the total division factor is given by (2**p) * d -STATIC const i2s_clock_config_t clock_config_map[] = { +static const i2s_clock_config_t clock_config_map[] = { {kSAI_SampleRate8KHz, &audioPllConfig_8000_48000, 1, 192}, // 384 {kSAI_SampleRate11025Hz, &audioPllConfig_11025_44100, 1, 128}, // 256 {kSAI_SampleRate12KHz, &audioPllConfig_8000_48000, 1, 128}, // 256 @@ -182,10 +182,10 @@ STATIC const i2s_clock_config_t clock_config_map[] = { {kSAI_SampleRate48KHz, &audioPllConfig_8000_48000, 0, 64} // 64 }; -STATIC const clock_root_t i2s_clock_mux[] = I2S_CLOCK_MUX; +static const clock_root_t i2s_clock_mux[] = I2S_CLOCK_MUX; #else // for 10xx the total division factor is given by (p + 1) * (d + 1) -STATIC const i2s_clock_config_t clock_config_map[] = { +static const i2s_clock_config_t clock_config_map[] = { {kSAI_SampleRate8KHz, &audioPllConfig_8000_48000, 5, 63}, // 384 {kSAI_SampleRate11025Hz, &audioPllConfig_11025_44100, 3, 63}, // 256 {kSAI_SampleRate12KHz, &audioPllConfig_8000_48000, 3, 63}, // 256 @@ -197,18 +197,18 @@ STATIC const i2s_clock_config_t clock_config_map[] = { {kSAI_SampleRate48KHz, &audioPllConfig_8000_48000, 0, 63} // 64 }; -STATIC const clock_mux_t i2s_clock_mux[] = I2S_CLOCK_MUX; -STATIC const clock_div_t i2s_clock_pre_div[] = I2S_CLOCK_PRE_DIV; -STATIC const clock_div_t i2s_clock_div[] = I2S_CLOCK_DIV; -STATIC const iomuxc_gpr_mode_t i2s_iomuxc_gpr_mode[] = I2S_IOMUXC_GPR_MODE; +static const clock_mux_t i2s_clock_mux[] = I2S_CLOCK_MUX; +static const clock_div_t i2s_clock_pre_div[] = I2S_CLOCK_PRE_DIV; +static const clock_div_t i2s_clock_div[] = I2S_CLOCK_DIV; +static const iomuxc_gpr_mode_t i2s_iomuxc_gpr_mode[] = I2S_IOMUXC_GPR_MODE; #endif -STATIC const I2S_Type *i2s_base_ptr[] = I2S_BASE_PTRS; +static const I2S_Type *i2s_base_ptr[] = I2S_BASE_PTRS; -STATIC const dma_request_source_t i2s_dma_req_src_tx[] = I2S_DMA_REQ_SRC_TX; -STATIC const dma_request_source_t i2s_dma_req_src_rx[] = I2S_DMA_REQ_SRC_RX; -STATIC const gpio_map_t i2s_gpio_map[] = I2S_GPIO_MAP; -AT_NONCACHEABLE_SECTION_ALIGN(STATIC edma_tcd_t edmaTcd[MICROPY_HW_I2S_NUM], 32); +static const dma_request_source_t i2s_dma_req_src_tx[] = I2S_DMA_REQ_SRC_TX; +static const dma_request_source_t i2s_dma_req_src_rx[] = I2S_DMA_REQ_SRC_RX; +static const gpio_map_t i2s_gpio_map[] = I2S_GPIO_MAP; +AT_NONCACHEABLE_SECTION_ALIGN(edma_tcd_t edmaTcd[MICROPY_HW_I2S_NUM], 32); // called on processor reset void machine_i2s_init0() { @@ -228,7 +228,7 @@ void machine_i2s_deinit_all(void) { } } -STATIC int8_t get_frame_mapping_index(int8_t bits, format_t format) { +static int8_t get_frame_mapping_index(int8_t bits, format_t format) { if (format == MONO) { if (bits == 16) { return 0; @@ -244,7 +244,7 @@ STATIC int8_t get_frame_mapping_index(int8_t bits, format_t format) { } } -STATIC int8_t get_dma_bits(uint16_t mode, int8_t bits) { +static int8_t get_dma_bits(uint16_t mode, int8_t bits) { if (mode == TX) { if (bits == 16) { return 16; @@ -258,7 +258,7 @@ STATIC int8_t get_dma_bits(uint16_t mode, int8_t bits) { } } -STATIC bool lookup_gpio(const machine_pin_obj_t *pin, i2s_pin_function_t fn, uint8_t hw_id, uint16_t *index) { +static bool lookup_gpio(const machine_pin_obj_t *pin, i2s_pin_function_t fn, uint8_t hw_id, uint16_t *index) { for (uint16_t i = 0; i < ARRAY_SIZE(i2s_gpio_map); i++) { if ((pin->name == i2s_gpio_map[i].name) && (i2s_gpio_map[i].fn == fn) && @@ -270,7 +270,7 @@ STATIC bool lookup_gpio(const machine_pin_obj_t *pin, i2s_pin_function_t fn, uin return false; } -STATIC bool set_iomux(const machine_pin_obj_t *pin, i2s_pin_function_t fn, uint8_t hw_id) { +static bool set_iomux(const machine_pin_obj_t *pin, i2s_pin_function_t fn, uint8_t hw_id) { uint16_t mapping_index; if (lookup_gpio(pin, fn, hw_id, &mapping_index)) { iomux_table_t iom = i2s_gpio_map[mapping_index].iomux; @@ -283,7 +283,7 @@ STATIC bool set_iomux(const machine_pin_obj_t *pin, i2s_pin_function_t fn, uint8 } } -STATIC bool is_rate_supported(int32_t rate) { +static bool is_rate_supported(int32_t rate) { for (uint16_t i = 0; i < ARRAY_SIZE(clock_config_map); i++) { if (clock_config_map[i].rate == rate) { return true; @@ -292,7 +292,7 @@ STATIC bool is_rate_supported(int32_t rate) { return false; } -STATIC const clock_audio_pll_config_t *get_pll_config(int32_t rate) { +static const clock_audio_pll_config_t *get_pll_config(int32_t rate) { for (uint16_t i = 0; i < ARRAY_SIZE(clock_config_map); i++) { if (clock_config_map[i].rate == rate) { return clock_config_map[i].pll_config; @@ -301,7 +301,7 @@ STATIC const clock_audio_pll_config_t *get_pll_config(int32_t rate) { return 0; } -STATIC const uint32_t get_clock_pre_divider(int32_t rate) { +static const uint32_t get_clock_pre_divider(int32_t rate) { for (uint16_t i = 0; i < ARRAY_SIZE(clock_config_map); i++) { if (clock_config_map[i].rate == rate) { return clock_config_map[i].clock_pre_divider; @@ -310,7 +310,7 @@ STATIC const uint32_t get_clock_pre_divider(int32_t rate) { return 0; } -STATIC const uint32_t get_clock_divider(int32_t rate) { +static const uint32_t get_clock_divider(int32_t rate) { for (uint16_t i = 0; i < ARRAY_SIZE(clock_config_map); i++) { if (clock_config_map[i].rate == rate) { return clock_config_map[i].clock_divider; @@ -320,7 +320,7 @@ STATIC const uint32_t get_clock_divider(int32_t rate) { } // function is used in IRQ context -STATIC void empty_dma(machine_i2s_obj_t *self, ping_pong_t dma_ping_pong) { +static void empty_dma(machine_i2s_obj_t *self, ping_pong_t dma_ping_pong) { uint16_t dma_buffer_offset = 0; if (dma_ping_pong == TOP_HALF) { @@ -343,7 +343,7 @@ STATIC void empty_dma(machine_i2s_obj_t *self, ping_pong_t dma_ping_pong) { } // function is used in IRQ context -STATIC void feed_dma(machine_i2s_obj_t *self, ping_pong_t dma_ping_pong) { +static void feed_dma(machine_i2s_obj_t *self, ping_pong_t dma_ping_pong) { uint16_t dma_buffer_offset = 0; if (dma_ping_pong == TOP_HALF) { @@ -387,7 +387,7 @@ STATIC void feed_dma(machine_i2s_obj_t *self, ping_pong_t dma_ping_pong) { MP_HAL_CLEAN_DCACHE(dma_buffer_p, SIZEOF_HALF_DMA_BUFFER_IN_BYTES); } -STATIC void edma_i2s_callback(edma_handle_t *handle, void *userData, bool transferDone, uint32_t tcds) { +static void edma_i2s_callback(edma_handle_t *handle, void *userData, bool transferDone, uint32_t tcds) { machine_i2s_obj_t *self = userData; if (self->mode == TX) { @@ -423,7 +423,7 @@ STATIC void edma_i2s_callback(edma_handle_t *handle, void *userData, bool transf } } -STATIC bool i2s_init(machine_i2s_obj_t *self) { +static bool i2s_init(machine_i2s_obj_t *self) { #if defined(MIMXRT117x_SERIES) clock_audio_pll_config_t pll_config = *get_pll_config(self->rate); @@ -570,7 +570,7 @@ STATIC bool i2s_init(machine_i2s_obj_t *self) { return true; } -STATIC void mp_machine_i2s_init_helper(machine_i2s_obj_t *self, mp_arg_val_t *args) { +static void mp_machine_i2s_init_helper(machine_i2s_obj_t *self, mp_arg_val_t *args) { // is Mode valid? uint16_t i2s_mode = args[ARG_mode].u_int; if ((i2s_mode != (RX)) && @@ -667,7 +667,7 @@ STATIC void mp_machine_i2s_init_helper(machine_i2s_obj_t *self, mp_arg_val_t *ar } } -STATIC machine_i2s_obj_t *mp_machine_i2s_make_new_instance(mp_int_t i2s_id) { +static machine_i2s_obj_t *mp_machine_i2s_make_new_instance(mp_int_t i2s_id) { if (i2s_id < 1 || i2s_id > MICROPY_HW_I2S_NUM) { mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("I2S(%d) does not exist"), i2s_id); } @@ -694,7 +694,7 @@ STATIC machine_i2s_obj_t *mp_machine_i2s_make_new_instance(mp_int_t i2s_id) { return self; } -STATIC void mp_machine_i2s_deinit(machine_i2s_obj_t *self) { +static void mp_machine_i2s_deinit(machine_i2s_obj_t *self) { // use self->i2s_inst as in indication that I2S object has already been de-initialized if (self->i2s_inst != NULL) { EDMA_AbortTransfer(&self->edmaHandle); @@ -718,7 +718,7 @@ STATIC void mp_machine_i2s_deinit(machine_i2s_obj_t *self) { } } -STATIC void mp_machine_i2s_irq_update(machine_i2s_obj_t *self) { +static void mp_machine_i2s_irq_update(machine_i2s_obj_t *self) { (void)self; } diff --git a/ports/mimxrt/machine_led.c b/ports/mimxrt/machine_led.c index a927c570a2532..2e9b17c883fe8 100644 --- a/ports/mimxrt/machine_led.c +++ b/ports/mimxrt/machine_led.c @@ -30,13 +30,13 @@ #if defined(MICROPY_HW_LED1_PIN) -STATIC void led_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void led_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; machine_led_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "LED(%u)", self->led_id); } -STATIC mp_obj_t led_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t led_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 1, false); // Extract arguments @@ -51,34 +51,34 @@ STATIC mp_obj_t led_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_ return MP_OBJ_FROM_PTR(&machine_led_obj[led_id - 1]); } -STATIC mp_obj_t led_obj_on(mp_obj_t self_in) { +static mp_obj_t led_obj_on(mp_obj_t self_in) { machine_led_obj_t *self = MP_OBJ_TO_PTR(self_in); MICROPY_HW_LED_ON(self->led_pin); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_on_obj, led_obj_on); +static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_on_obj, led_obj_on); -STATIC mp_obj_t led_obj_off(mp_obj_t self_in) { +static mp_obj_t led_obj_off(mp_obj_t self_in) { machine_led_obj_t *self = MP_OBJ_TO_PTR(self_in); MICROPY_HW_LED_OFF(self->led_pin); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_off_obj, led_obj_off); +static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_off_obj, led_obj_off); -STATIC mp_obj_t led_obj_toggle(mp_obj_t self_in) { +static mp_obj_t led_obj_toggle(mp_obj_t self_in) { machine_led_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_hal_pin_toggle(self->led_pin); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_toggle_obj, led_obj_toggle); +static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_toggle_obj, led_obj_toggle); -STATIC const mp_rom_map_elem_t led_locals_dict_table[] = { +static const mp_rom_map_elem_t led_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_on), MP_ROM_PTR(&led_obj_on_obj)}, {MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(&led_obj_off_obj)}, {MP_ROM_QSTR(MP_QSTR_toggle), MP_ROM_PTR(&led_obj_toggle_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(led_locals_dict, led_locals_dict_table); +static MP_DEFINE_CONST_DICT(led_locals_dict, led_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( machine_led_type, diff --git a/ports/mimxrt/machine_pin.c b/ports/mimxrt/machine_pin.c index 3ebccb1755ad8..ad4158c6bdee9 100644 --- a/ports/mimxrt/machine_pin.c +++ b/ports/mimxrt/machine_pin.c @@ -39,18 +39,18 @@ #endif // Local functions -STATIC mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args); +static mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args); // Class Methods -STATIC void machine_pin_obj_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind); -STATIC mp_obj_t machine_pin_obj_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args); +static void machine_pin_obj_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind); +static mp_obj_t machine_pin_obj_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args); mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args); // Instance Methods -STATIC mp_obj_t machine_pin_off(mp_obj_t self_in); -STATIC mp_obj_t machine_pin_on(mp_obj_t self_in); -STATIC mp_obj_t machine_pin_value(size_t n_args, const mp_obj_t *args); -STATIC mp_obj_t machine_pin_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args); +static mp_obj_t machine_pin_off(mp_obj_t self_in); +static mp_obj_t machine_pin_on(mp_obj_t self_in); +static mp_obj_t machine_pin_value(size_t n_args, const mp_obj_t *args); +static mp_obj_t machine_pin_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args); // Local data enum { @@ -75,12 +75,12 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &machine_pin_board_pins_locals_dict ); -STATIC const mp_irq_methods_t machine_pin_irq_methods; +static const mp_irq_methods_t machine_pin_irq_methods; static GPIO_Type *gpiobases[] = GPIO_BASE_PTRS; -STATIC const uint16_t GPIO_combined_low_irqs[] = GPIO_COMBINED_LOW_IRQS; -STATIC const uint16_t GPIO_combined_high_irqs[] = GPIO_COMBINED_HIGH_IRQS; -STATIC const uint16_t IRQ_mapping[] = {kGPIO_NoIntmode, kGPIO_IntRisingEdge, kGPIO_IntFallingEdge, kGPIO_IntRisingOrFallingEdge}; +static const uint16_t GPIO_combined_low_irqs[] = GPIO_COMBINED_LOW_IRQS; +static const uint16_t GPIO_combined_high_irqs[] = GPIO_COMBINED_HIGH_IRQS; +static const uint16_t IRQ_mapping[] = {kGPIO_NoIntmode, kGPIO_IntRisingEdge, kGPIO_IntFallingEdge, kGPIO_IntRisingOrFallingEdge}; #define GET_PIN_IRQ_INDEX(gpio_nr, pin) ((gpio_nr - 1) * 32 + pin) int GPIO_get_instance(GPIO_Type *gpio) { @@ -254,7 +254,7 @@ void machine_pin_config(const machine_pin_obj_t *self, uint8_t mode, } } -STATIC mp_obj_t machine_pin_obj_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +static mp_obj_t machine_pin_obj_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); machine_pin_obj_t *self = self_in; @@ -266,7 +266,7 @@ STATIC mp_obj_t machine_pin_obj_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint } } -STATIC mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { [PIN_INIT_ARG_MODE] { MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT }, [PIN_INIT_ARG_PULL] { MP_QSTR_pull, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE}}, @@ -326,7 +326,7 @@ STATIC mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_ return mp_const_none; } -STATIC void machine_pin_obj_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { +static void machine_pin_obj_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { (void)kind; const machine_pin_obj_t *self = MP_OBJ_TO_PTR(o); mp_printf(print, "Pin(%s)", qstr_str(self->name)); @@ -349,43 +349,43 @@ mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, } // pin.off() -STATIC mp_obj_t machine_pin_off(mp_obj_t self_in) { +static mp_obj_t machine_pin_off(mp_obj_t self_in) { machine_pin_obj_t *self = self_in; mp_hal_pin_low(self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_off_obj, machine_pin_off); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_off_obj, machine_pin_off); // pin.on() -STATIC mp_obj_t machine_pin_on(mp_obj_t self_in) { +static mp_obj_t machine_pin_on(mp_obj_t self_in) { machine_pin_obj_t *self = self_in; mp_hal_pin_high(self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_on_obj, machine_pin_on); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_on_obj, machine_pin_on); // pin.toggle() -STATIC mp_obj_t machine_pin_toggle(mp_obj_t self_in) { +static mp_obj_t machine_pin_toggle(mp_obj_t self_in) { machine_pin_obj_t *self = self_in; mp_hal_pin_toggle(self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_toggle_obj, machine_pin_toggle); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_toggle_obj, machine_pin_toggle); // pin.value([value]) -STATIC mp_obj_t machine_pin_value(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_pin_value(size_t n_args, const mp_obj_t *args) { return machine_pin_obj_call(args[0], (n_args - 1), 0, args + 1); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pin_value_obj, 1, 2, machine_pin_value); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pin_value_obj, 1, 2, machine_pin_value); // pin.init(mode, pull, [kwargs]) -STATIC mp_obj_t machine_pin_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t machine_pin_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { return machine_pin_obj_init_helper(args[0], n_args - 1, args + 1, kw_args); } MP_DEFINE_CONST_FUN_OBJ_KW(machine_pin_init_obj, 1, machine_pin_init); // pin.irq(handler=None, trigger=IRQ_FALLING|IRQ_RISING, hard=False) -STATIC mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_handler, ARG_trigger, ARG_hard }; static const mp_arg_t allowed_args[] = { { MP_QSTR_handler, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, @@ -452,9 +452,9 @@ STATIC mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_ return MP_OBJ_FROM_PTR(irq); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_pin_irq_obj, 1, machine_pin_irq); +static MP_DEFINE_CONST_FUN_OBJ_KW(machine_pin_irq_obj, 1, machine_pin_irq); -STATIC const mp_rom_map_elem_t machine_pin_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_pin_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(&machine_pin_off_obj) }, { MP_ROM_QSTR(MP_QSTR_on), MP_ROM_PTR(&machine_pin_on_obj) }, @@ -491,9 +491,9 @@ STATIC const mp_rom_map_elem_t machine_pin_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_IRQ_FALLING), MP_ROM_INT(2) }, }; -STATIC MP_DEFINE_CONST_DICT(machine_pin_locals_dict, machine_pin_locals_dict_table); +static MP_DEFINE_CONST_DICT(machine_pin_locals_dict, machine_pin_locals_dict_table); -STATIC mp_uint_t machine_pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t machine_pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { (void)errcode; machine_pin_obj_t *self = self_in; @@ -509,7 +509,7 @@ STATIC mp_uint_t machine_pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_ return -1; } -STATIC const mp_pin_p_t machine_pin_obj_protocol = { +static const mp_pin_p_t machine_pin_obj_protocol = { .ioctl = machine_pin_ioctl, }; @@ -534,7 +534,7 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &machine_pin_locals_dict ); -STATIC mp_uint_t machine_pin_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { +static mp_uint_t machine_pin_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); uint32_t gpio_nr = GPIO_get_instance(self->gpio); machine_pin_irq_obj_t *irq = MP_STATE_PORT(machine_pin_irq_objects[GET_PIN_IRQ_INDEX(gpio_nr, self->pin)]); @@ -551,7 +551,7 @@ STATIC mp_uint_t machine_pin_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger return 0; } -STATIC mp_uint_t machine_pin_irq_info(mp_obj_t self_in, mp_uint_t info_type) { +static mp_uint_t machine_pin_irq_info(mp_obj_t self_in, mp_uint_t info_type) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); uint32_t gpio_nr = GPIO_get_instance(self->gpio); machine_pin_irq_obj_t *irq = MP_STATE_PORT(machine_pin_irq_objects[GET_PIN_IRQ_INDEX(gpio_nr, self->pin)]); @@ -563,7 +563,7 @@ STATIC mp_uint_t machine_pin_irq_info(mp_obj_t self_in, mp_uint_t info_type) { return 0; } -STATIC const mp_irq_methods_t machine_pin_irq_methods = { +static const mp_irq_methods_t machine_pin_irq_methods = { .trigger = machine_pin_irq_trigger, .info = machine_pin_irq_info, }; diff --git a/ports/mimxrt/machine_pwm.c b/ports/mimxrt/machine_pwm.c index 98545eec95c51..f9ae5e22edcc3 100644 --- a/ports/mimxrt/machine_pwm.c +++ b/ports/mimxrt/machine_pwm.c @@ -70,9 +70,9 @@ static char *ERRMSG_FREQ = "PWM frequency too low"; static char *ERRMSG_INIT = "PWM set-up failed"; static char *ERRMSG_VALUE = "value larger than period"; -STATIC void mp_machine_pwm_start(machine_pwm_obj_t *self); +static void mp_machine_pwm_start(machine_pwm_obj_t *self); -STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_pwm_obj_t *self = MP_OBJ_TO_PTR(self_in); if (self->is_flexpwm) { mp_printf(print, "module, self->submodule); @@ -103,7 +103,7 @@ STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_p // Utility functions for decoding and converting // -STATIC uint32_t duty_ns_to_duty_u16(uint32_t freq, uint32_t duty_ns) { +static uint32_t duty_ns_to_duty_u16(uint32_t freq, uint32_t duty_ns) { uint64_t duty = (uint64_t)duty_ns * freq * PWM_FULL_SCALE / 1000000000ULL; if (duty > PWM_FULL_SCALE) { mp_raise_ValueError(MP_ERROR_TEXT(ERRMSG_VALUE)); @@ -111,7 +111,7 @@ STATIC uint32_t duty_ns_to_duty_u16(uint32_t freq, uint32_t duty_ns) { return (uint32_t)duty; } -STATIC uint8_t module_decode(char channel) { +static uint8_t module_decode(char channel) { switch (channel) { case '0': return kPWM_Module_0; @@ -126,7 +126,7 @@ STATIC uint8_t module_decode(char channel) { } } -STATIC uint8_t channel_decode(char channel) { +static uint8_t channel_decode(char channel) { switch (channel) { case 'A': return kPWM_PwmA; @@ -140,7 +140,7 @@ STATIC uint8_t channel_decode(char channel) { } // decode the AF objects module and Port number. Returns NULL if it is not a FLEXPWM object -STATIC const machine_pin_af_obj_t *af_name_decode_flexpwm(const machine_pin_af_obj_t *af_obj, +static const machine_pin_af_obj_t *af_name_decode_flexpwm(const machine_pin_af_obj_t *af_obj, uint8_t *module, uint8_t *submodule, uint8_t *channel) { const char *str; size_t len; @@ -158,7 +158,7 @@ STATIC const machine_pin_af_obj_t *af_name_decode_flexpwm(const machine_pin_af_o } #ifdef FSL_FEATURE_SOC_TMR_COUNT -STATIC uint8_t qtmr_decode(char channel) { +static uint8_t qtmr_decode(char channel) { switch (channel) { case '0': return kQTMR_Channel_0; @@ -174,7 +174,7 @@ STATIC uint8_t qtmr_decode(char channel) { } // decode the AF objects module and Port number. Returns NULL if it is not a QTMR object -STATIC const machine_pin_af_obj_t *af_name_decode_qtmr(const machine_pin_af_obj_t *af_obj, uint8_t *module, uint8_t *channel) { +static const machine_pin_af_obj_t *af_name_decode_qtmr(const machine_pin_af_obj_t *af_obj, uint8_t *module, uint8_t *channel) { const char *str; size_t len; str = (char *)qstr_data(af_obj->name, &len); @@ -190,7 +190,7 @@ STATIC const machine_pin_af_obj_t *af_name_decode_qtmr(const machine_pin_af_obj_ } #endif -STATIC bool is_board_pin(const machine_pin_obj_t *pin) { +static bool is_board_pin(const machine_pin_obj_t *pin) { const mp_map_t *board_map = &machine_pin_board_pins_locals_dict.map; for (uint i = 0; i < board_map->alloc; i++) { if (pin == MP_OBJ_TO_PTR(board_map->table[i].value)) { @@ -202,7 +202,7 @@ STATIC bool is_board_pin(const machine_pin_obj_t *pin) { // Functions for configuring the PWM Device // -STATIC int calc_prescaler(uint32_t clock, uint32_t freq) { +static int calc_prescaler(uint32_t clock, uint32_t freq) { float temp = (float)clock / (float)PWM_FULL_SCALE / (float)freq; for (int prescale = 0; prescale < 8; prescale++, temp /= 2) { if (temp <= 1) { @@ -213,7 +213,7 @@ STATIC int calc_prescaler(uint32_t clock, uint32_t freq) { return -1; } -STATIC void configure_flexpwm(machine_pwm_obj_t *self) { +static void configure_flexpwm(machine_pwm_obj_t *self) { pwm_signal_param_u16_t pwmSignal; // Initialize PWM module. @@ -300,7 +300,7 @@ STATIC void configure_flexpwm(machine_pwm_obj_t *self) { } #ifdef FSL_FEATURE_SOC_TMR_COUNT -STATIC void configure_qtmr(machine_pwm_obj_t *self) { +static void configure_qtmr(machine_pwm_obj_t *self) { qtmr_config_t qtmrConfig; int prescale; #if defined(MIMXRT117x_SERIES) @@ -331,7 +331,7 @@ STATIC void configure_qtmr(machine_pwm_obj_t *self) { } #endif // FSL_FEATURE_SOC_TMR_COUNT -STATIC void configure_pwm(machine_pwm_obj_t *self) { +static void configure_pwm(machine_pwm_obj_t *self) { // Set the clock frequencies // Freq range is 15Hz to ~ 3 MHz. static bool set_frequency = true; @@ -360,7 +360,7 @@ STATIC void configure_pwm(machine_pwm_obj_t *self) { // Micropython API functions // -STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, +static void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_freq, ARG_duty_u16, ARG_duty_ns, ARG_center, ARG_align, ARG_invert, ARG_sync, ARG_xor, ARG_deadtime }; @@ -444,7 +444,7 @@ STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, } // PWM(pin | pin-tuple, freq, [args]) -STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // Check number of arguments mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); @@ -580,7 +580,7 @@ void machine_pwm_deinit_all(void) { #endif } -STATIC void mp_machine_pwm_start(machine_pwm_obj_t *self) { +static void mp_machine_pwm_start(machine_pwm_obj_t *self) { if (self->is_flexpwm) { PWM_StartTimer(self->instance, 1 << self->submodule); #ifdef FSL_FEATURE_SOC_TMR_COUNT @@ -590,7 +590,7 @@ STATIC void mp_machine_pwm_start(machine_pwm_obj_t *self) { } } -STATIC void mp_machine_pwm_deinit(machine_pwm_obj_t *self) { +static void mp_machine_pwm_deinit(machine_pwm_obj_t *self) { if (self->is_flexpwm) { PWM_StopTimer(self->instance, 1 << self->submodule); #ifdef FSL_FEATURE_SOC_TMR_COUNT diff --git a/ports/mimxrt/machine_rtc.c b/ports/mimxrt/machine_rtc.c index 61b410a652cf8..294942cf5a03f 100644 --- a/ports/mimxrt/machine_rtc.c +++ b/ports/mimxrt/machine_rtc.c @@ -35,7 +35,7 @@ #include "fsl_snvs_lp.h" #include "fsl_snvs_hp.h" -STATIC mp_int_t timeout = 0; +static mp_int_t timeout = 0; void machine_rtc_alarm_clear_en(void) { SNVS_LP_SRTC_DisableInterrupts(SNVS, SNVS_LPCR_LPTA_EN_MASK); @@ -103,7 +103,7 @@ typedef struct _machine_rtc_irq_obj_t { mp_irq_obj_t base; } machine_rtc_irq_obj_t; -STATIC mp_uint_t machine_rtc_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { +static mp_uint_t machine_rtc_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { new_trigger /= 1000; if (!new_trigger) { machine_rtc_alarm_off(true); @@ -113,11 +113,11 @@ STATIC mp_uint_t machine_rtc_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger return 0; } -STATIC mp_uint_t machine_rtc_irq_info(mp_obj_t self_in, mp_uint_t info_type) { +static mp_uint_t machine_rtc_irq_info(mp_obj_t self_in, mp_uint_t info_type) { return 0; } -STATIC const mp_irq_methods_t machine_rtc_irq_methods = { +static const mp_irq_methods_t machine_rtc_irq_methods = { .trigger = machine_rtc_irq_trigger, .info = machine_rtc_irq_info, }; @@ -148,7 +148,7 @@ typedef struct _machine_rtc_obj_t { } machine_rtc_obj_t; // Singleton RTC object. -STATIC const machine_rtc_obj_t machine_rtc_obj = {{&machine_rtc_type}}; +static const machine_rtc_obj_t machine_rtc_obj = {{&machine_rtc_type}}; // Start the RTC Timer. void machine_rtc_start(void) { @@ -177,7 +177,7 @@ void machine_rtc_start(void) { } } -STATIC mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // Check arguments. mp_arg_check_num(n_args, n_kw, 0, 0, false); @@ -185,7 +185,7 @@ STATIC mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, s return (mp_obj_t)&machine_rtc_obj; } -STATIC mp_obj_t machine_rtc_datetime_helper(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_rtc_datetime_helper(size_t n_args, const mp_obj_t *args) { if (n_args == 1) { // Get date and time. snvs_lp_srtc_datetime_t srtc_date; @@ -225,12 +225,12 @@ STATIC mp_obj_t machine_rtc_datetime_helper(size_t n_args, const mp_obj_t *args) } } -STATIC mp_obj_t machine_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) { return machine_rtc_datetime_helper(n_args, args); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_rtc_datetime_obj, 1, 2, machine_rtc_datetime); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_rtc_datetime_obj, 1, 2, machine_rtc_datetime); -STATIC mp_obj_t machine_rtc_now(mp_obj_t self_in) { +static mp_obj_t machine_rtc_now(mp_obj_t self_in) { // Get date and time in CPython order. snvs_lp_srtc_datetime_t srtc_date; SNVS_LP_SRTC_GetDatetime(SNVS, &srtc_date); @@ -247,18 +247,18 @@ STATIC mp_obj_t machine_rtc_now(mp_obj_t self_in) { }; return mp_obj_new_tuple(8, tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_rtc_now_obj, machine_rtc_now); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_rtc_now_obj, machine_rtc_now); -STATIC mp_obj_t machine_rtc_init(mp_obj_t self_in, mp_obj_t date) { +static mp_obj_t machine_rtc_init(mp_obj_t self_in, mp_obj_t date) { mp_obj_t args[2] = {self_in, date}; machine_rtc_datetime_helper(2, args); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_rtc_init_obj, machine_rtc_init); +static MP_DEFINE_CONST_FUN_OBJ_2(machine_rtc_init_obj, machine_rtc_init); // calibration(cal) // When the argument is a number in the range [-16 to 15], set the calibration value. -STATIC mp_obj_t machine_rtc_calibration(mp_obj_t self_in, mp_obj_t cal_in) { +static mp_obj_t machine_rtc_calibration(mp_obj_t self_in, mp_obj_t cal_in) { mp_int_t cal = 0; snvs_lp_srtc_config_t snvsSrtcConfig; cal = mp_obj_get_int(cal_in); @@ -271,10 +271,10 @@ STATIC mp_obj_t machine_rtc_calibration(mp_obj_t self_in, mp_obj_t cal_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_rtc_calibration_obj, machine_rtc_calibration); +static MP_DEFINE_CONST_FUN_OBJ_2(machine_rtc_calibration_obj, machine_rtc_calibration); -STATIC mp_obj_t machine_rtc_alarm(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - STATIC const mp_arg_t allowed_args[] = { +static mp_obj_t machine_rtc_alarm(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + static const mp_arg_t allowed_args[] = { { MP_QSTR_id, MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_time, MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_repeat, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, @@ -321,9 +321,9 @@ STATIC mp_obj_t machine_rtc_alarm(size_t n_args, const mp_obj_t *pos_args, mp_ma return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_rtc_alarm_obj, 1, machine_rtc_alarm); +static MP_DEFINE_CONST_FUN_OBJ_KW(machine_rtc_alarm_obj, 1, machine_rtc_alarm); -STATIC mp_obj_t machine_rtc_alarm_left(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_rtc_alarm_left(size_t n_args, const mp_obj_t *args) { // only alarm id 0 is available if (n_args > 1 && mp_obj_get_int(args[1]) != 0) { mp_raise_OSError(MP_ENODEV); @@ -332,9 +332,9 @@ STATIC mp_obj_t machine_rtc_alarm_left(size_t n_args, const mp_obj_t *args) { uint32_t alarmSeconds = SNVS->LPTAR; return mp_obj_new_int((alarmSeconds >= seconds) ? ((alarmSeconds - seconds) * 1000) : 0); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_rtc_alarm_left_obj, 1, 2, machine_rtc_alarm_left); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_rtc_alarm_left_obj, 1, 2, machine_rtc_alarm_left); -STATIC mp_obj_t machine_rtc_alarm_cancel(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_rtc_alarm_cancel(size_t n_args, const mp_obj_t *args) { // only alarm id 0 is available if (n_args > 1 && mp_obj_get_int(args[1]) != 0) { mp_raise_OSError(MP_ENODEV); @@ -342,9 +342,9 @@ STATIC mp_obj_t machine_rtc_alarm_cancel(size_t n_args, const mp_obj_t *args) { machine_rtc_alarm_off(true); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_rtc_alarm_cancel_obj, 1, 2, machine_rtc_alarm_cancel); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_rtc_alarm_cancel_obj, 1, 2, machine_rtc_alarm_cancel); -STATIC mp_obj_t machine_rtc_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_rtc_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_trigger, ARG_handler, ARG_wake, ARG_hard }; static const mp_arg_t allowed_args[] = { { MP_QSTR_trigger, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, @@ -384,9 +384,9 @@ STATIC mp_obj_t machine_rtc_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_ return MP_OBJ_FROM_PTR(irq); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_rtc_irq_obj, 1, machine_rtc_irq); +static MP_DEFINE_CONST_FUN_OBJ_KW(machine_rtc_irq_obj, 1, machine_rtc_irq); -STATIC const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_rtc_init_obj) }, { MP_ROM_QSTR(MP_QSTR_datetime), MP_ROM_PTR(&machine_rtc_datetime_obj) }, { MP_ROM_QSTR(MP_QSTR_now), MP_ROM_PTR(&machine_rtc_now_obj) }, @@ -398,7 +398,7 @@ STATIC const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&machine_rtc_irq_obj) }, { MP_ROM_QSTR(MP_QSTR_ALARM0), MP_ROM_INT(0) }, }; -STATIC MP_DEFINE_CONST_DICT(machine_rtc_locals_dict, machine_rtc_locals_dict_table); +static MP_DEFINE_CONST_DICT(machine_rtc_locals_dict, machine_rtc_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( machine_rtc_type, diff --git a/ports/mimxrt/machine_sdcard.c b/ports/mimxrt/machine_sdcard.c index b0bf8613c24ab..c938fdf2e597d 100644 --- a/ports/mimxrt/machine_sdcard.c +++ b/ports/mimxrt/machine_sdcard.c @@ -44,19 +44,19 @@ enum { SDCARD_INIT_ARG_ID }; -STATIC const mp_arg_t sdcard_init_allowed_args[] = { +static const mp_arg_t sdcard_init_allowed_args[] = { [SDCARD_INIT_ARG_ID] = { MP_QSTR_id, MP_ARG_INT, {.u_int = 1} }, }; -STATIC void machine_sdcard_init_helper(mimxrt_sdcard_obj_t *self) { +static void machine_sdcard_init_helper(mimxrt_sdcard_obj_t *self) { sdcard_init(self, 198000000UL); // Initialize SDCard Host with 198MHz base clock sdcard_init_pins(self); ticks_delay_us64(2ULL * 1000ULL); // Wait 2ms to allow USDHC signals to settle/debounce } -STATIC mp_obj_t sdcard_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t sdcard_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); @@ -81,7 +81,7 @@ STATIC mp_obj_t sdcard_obj_make_new(const mp_obj_type_t *type, size_t n_args, si } // init() -STATIC mp_obj_t machine_sdcard_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_sdcard_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mimxrt_sdcard_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); if (!sdcard_state_initialized(self)) { @@ -89,18 +89,18 @@ STATIC mp_obj_t machine_sdcard_init(size_t n_args, const mp_obj_t *pos_args, mp_ } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_sdcard_init_obj, 1, machine_sdcard_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(machine_sdcard_init_obj, 1, machine_sdcard_init); // deinit() -STATIC mp_obj_t machine_sdcard_deinit(mp_obj_t self_in) { +static mp_obj_t machine_sdcard_deinit(mp_obj_t self_in) { mimxrt_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); sdcard_deinit(self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_sdcard_deinit_obj, machine_sdcard_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_sdcard_deinit_obj, machine_sdcard_deinit); // readblocks(block_num, buf) -STATIC mp_obj_t machine_sdcard_readblocks(mp_obj_t self_in, mp_obj_t block_num, mp_obj_t buf) { +static mp_obj_t machine_sdcard_readblocks(mp_obj_t self_in, mp_obj_t block_num, mp_obj_t buf) { mp_buffer_info_t bufinfo; mimxrt_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_WRITE); @@ -111,16 +111,16 @@ STATIC mp_obj_t machine_sdcard_readblocks(mp_obj_t self_in, mp_obj_t block_num, return MP_OBJ_NEW_SMALL_INT(-MP_EIO); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(machine_sdcard_readblocks_obj, machine_sdcard_readblocks); +static MP_DEFINE_CONST_FUN_OBJ_3(machine_sdcard_readblocks_obj, machine_sdcard_readblocks); // present() -STATIC mp_obj_t machine_sdcard_present(mp_obj_t self_in) { +static mp_obj_t machine_sdcard_present(mp_obj_t self_in) { mimxrt_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_bool(sdcard_detect(self)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_sdcard_present_obj, machine_sdcard_present); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_sdcard_present_obj, machine_sdcard_present); -STATIC mp_obj_t machine_sdcard_info(mp_obj_t self_in) { +static mp_obj_t machine_sdcard_info(mp_obj_t self_in) { mimxrt_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); if (sdcard_detect(self) && sdcard_state_initialized(self)) { @@ -136,10 +136,10 @@ STATIC mp_obj_t machine_sdcard_info(mp_obj_t self_in) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_sdcard_info_obj, machine_sdcard_info); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_sdcard_info_obj, machine_sdcard_info); // writeblocks(block_num, buf) -STATIC mp_obj_t machine_sdcard_writeblocks(mp_obj_t self_in, mp_obj_t block_num, mp_obj_t buf) { +static mp_obj_t machine_sdcard_writeblocks(mp_obj_t self_in, mp_obj_t block_num, mp_obj_t buf) { mp_buffer_info_t bufinfo; mimxrt_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_WRITE); @@ -150,10 +150,10 @@ STATIC mp_obj_t machine_sdcard_writeblocks(mp_obj_t self_in, mp_obj_t block_num, return MP_OBJ_NEW_SMALL_INT(-MP_EIO); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(machine_sdcard_writeblocks_obj, machine_sdcard_writeblocks); +static MP_DEFINE_CONST_FUN_OBJ_3(machine_sdcard_writeblocks_obj, machine_sdcard_writeblocks); // ioctl(op, arg) -STATIC mp_obj_t machine_sdcard_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { +static mp_obj_t machine_sdcard_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { mimxrt_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t cmd = mp_obj_get_int(cmd_in); @@ -200,9 +200,9 @@ STATIC mp_obj_t machine_sdcard_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t } } } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(machine_sdcard_ioctl_obj, machine_sdcard_ioctl); +static MP_DEFINE_CONST_FUN_OBJ_3(machine_sdcard_ioctl_obj, machine_sdcard_ioctl); -STATIC const mp_rom_map_elem_t sdcard_locals_dict_table[] = { +static const mp_rom_map_elem_t sdcard_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_sdcard_init_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&machine_sdcard_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR_present), MP_ROM_PTR(&machine_sdcard_present_obj) }, @@ -212,7 +212,7 @@ STATIC const mp_rom_map_elem_t sdcard_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&machine_sdcard_writeblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&machine_sdcard_ioctl_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(sdcard_locals_dict, sdcard_locals_dict_table); +static MP_DEFINE_CONST_DICT(sdcard_locals_dict, sdcard_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( machine_sdcard_type, diff --git a/ports/mimxrt/machine_spi.c b/ports/mimxrt/machine_spi.c index 35deaa7ae6ae9..56e155ff22f4b 100644 --- a/ports/mimxrt/machine_spi.c +++ b/ports/mimxrt/machine_spi.c @@ -78,8 +78,8 @@ typedef struct _iomux_table_t { uint32_t configRegister; } iomux_table_t; -STATIC const uint8_t spi_index_table[] = MICROPY_HW_SPI_INDEX; -STATIC LPSPI_Type *spi_base_ptr_table[] = LPSPI_BASE_PTRS; +static const uint8_t spi_index_table[] = MICROPY_HW_SPI_INDEX; +static LPSPI_Type *spi_base_ptr_table[] = LPSPI_BASE_PTRS; static const iomux_table_t iomux_table[] = { IOMUX_TABLE_SPI }; @@ -118,7 +118,7 @@ bool lpspi_set_iomux(int8_t spi, uint8_t drive, int8_t cs) { } } -STATIC void machine_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { static const char *firstbit_str[] = {"MSB", "LSB"}; machine_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "SPI(%u, baudrate=%u, polarity=%u, phase=%u, bits=%u, firstbit=%s, gap_ns=%d)", @@ -193,7 +193,7 @@ mp_obj_t machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n return MP_OBJ_FROM_PTR(self); } -STATIC void machine_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void machine_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits, ARG_firstbit, ARG_gap_ns }; static const mp_arg_t allowed_args[] = { { MP_QSTR_baudrate, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, @@ -236,7 +236,7 @@ STATIC void machine_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj LPSPI_MasterInit(self->spi_inst, self->master_config, BOARD_BOOTCLOCKRUN_LPSPI_CLK_ROOT); } -STATIC void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) { +static void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) { machine_spi_obj_t *self = (machine_spi_obj_t *)self_in; if (len > 0) { @@ -255,7 +255,7 @@ STATIC void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8 } } -STATIC const mp_machine_spi_p_t machine_spi_p = { +static const mp_machine_spi_p_t machine_spi_p = { .init = machine_spi_init, .transfer = machine_spi_transfer, }; diff --git a/ports/mimxrt/machine_uart.c b/ports/mimxrt/machine_uart.c index 4dbe1d2e5e8ec..7ae584fdd7454 100644 --- a/ports/mimxrt/machine_uart.c +++ b/ports/mimxrt/machine_uart.c @@ -73,8 +73,8 @@ typedef struct _iomux_table_t { uint32_t configRegister; } iomux_table_t; -STATIC const uint8_t uart_index_table[] = MICROPY_HW_UART_INDEX; -STATIC LPUART_Type *uart_base_ptr_table[] = LPUART_BASE_PTRS; +static const uint8_t uart_index_table[] = MICROPY_HW_UART_INDEX; +static LPUART_Type *uart_base_ptr_table[] = LPUART_BASE_PTRS; static const iomux_table_t iomux_table_uart[] = { IOMUX_TABLE_UART }; @@ -82,9 +82,9 @@ static const iomux_table_t iomux_table_uart_cts_rts[] = { IOMUX_TABLE_UART_CTS_RTS }; -STATIC const char *_parity_name[] = {"None", "", "0", "1"}; // Is defined as 0, 2, 3 -STATIC const char *_invert_name[] = {"None", "INV_TX", "INV_RX", "INV_TX|INV_RX"}; -STATIC const char *_flow_name[] = {"None", "RTS", "CTS", "RTS|CTS"}; +static const char *_parity_name[] = {"None", "", "0", "1"}; // Is defined as 0, 2, 3 +static const char *_invert_name[] = {"None", "INV_TX", "INV_RX", "INV_TX|INV_RX"}; +static const char *_flow_name[] = {"None", "RTS", "CTS", "RTS|CTS"}; #define RX (iomux_table_uart[index + 1]) #define TX (iomux_table_uart[index]) @@ -171,7 +171,7 @@ void machine_uart_set_baudrate(mp_obj_t uart_in, uint32_t baudrate) { { MP_ROM_QSTR(MP_QSTR_CTS), MP_ROM_INT(UART_HWCONTROL_CTS) }, \ { MP_ROM_QSTR(MP_QSTR_RTS), MP_ROM_INT(UART_HWCONTROL_RTS) }, \ -STATIC void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "UART(%u, baudrate=%u, bits=%u, parity=%s, stop=%u, flow=%s, " "rxbuf=%d, txbuf=%d, timeout=%u, timeout_char=%u, invert=%s)", @@ -182,7 +182,7 @@ STATIC void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_ _invert_name[self->invert]); } -STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_baudrate, ARG_bits, ARG_parity, ARG_stop, ARG_flow, ARG_timeout, ARG_timeout_char, ARG_invert, ARG_rxbuf, ARG_txbuf}; static const mp_arg_t allowed_args[] = { @@ -338,7 +338,7 @@ STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, } } -STATIC mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); // Get UART bus. @@ -372,21 +372,21 @@ STATIC mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_arg } // uart.deinit() -STATIC void mp_machine_uart_deinit(machine_uart_obj_t *self) { +static void mp_machine_uart_deinit(machine_uart_obj_t *self) { LPUART_SoftwareReset(self->lpuart); } -STATIC mp_int_t mp_machine_uart_any(machine_uart_obj_t *self) { +static mp_int_t mp_machine_uart_any(machine_uart_obj_t *self) { machine_uart_ensure_active(self); size_t count = LPUART_TransferGetRxRingBufferLength(self->lpuart, &self->handle); return count; } -STATIC bool mp_machine_uart_txdone(machine_uart_obj_t *self) { +static bool mp_machine_uart_txdone(machine_uart_obj_t *self) { return self->tx_status == kStatus_LPUART_TxIdle; } -STATIC void mp_machine_uart_sendbreak(machine_uart_obj_t *self) { +static void mp_machine_uart_sendbreak(machine_uart_obj_t *self) { machine_uart_ensure_active(self); self->lpuart->CTRL |= 1 << LPUART_CTRL_SBK_SHIFT; // Set SBK bit self->lpuart->CTRL &= ~LPUART_CTRL_SBK_MASK; // Clear SBK bit @@ -401,7 +401,7 @@ void machine_uart_deinit_all(void) { } } -STATIC mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { +static mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); uint64_t t = ticks_us64() + (uint64_t)self->timeout * 1000; uint64_t timeout_char_us = (uint64_t)self->timeout_char * 1000; @@ -436,7 +436,7 @@ STATIC mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t return size; } -STATIC mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { +static mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); lpuart_transfer_t xfer; uint64_t t; @@ -496,7 +496,7 @@ STATIC mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_ return size; } -STATIC mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { machine_uart_obj_t *self = self_in; mp_uint_t ret; if (request == MP_STREAM_POLL) { diff --git a/ports/mimxrt/machine_wdt.c b/ports/mimxrt/machine_wdt.c index 176e114f72960..24945efbfba8f 100644 --- a/ports/mimxrt/machine_wdt.c +++ b/ports/mimxrt/machine_wdt.c @@ -36,9 +36,9 @@ typedef struct _machine_wdt_obj_t { mp_obj_base_t base; } machine_wdt_obj_t; -STATIC const machine_wdt_obj_t machine_wdt = {{&machine_wdt_type}}; +static const machine_wdt_obj_t machine_wdt = {{&machine_wdt_type}}; -STATIC machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t timeout_ms) { +static machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t timeout_ms) { // Verify the WDT id. if (id != 0) { mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("WDT(%d) doesn't exist"), id); @@ -59,12 +59,12 @@ STATIC machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t return (machine_wdt_obj_t *)&machine_wdt; } -STATIC void mp_machine_wdt_feed(machine_wdt_obj_t *self) { +static void mp_machine_wdt_feed(machine_wdt_obj_t *self) { (void)self; WDOG_Refresh(WDOG1); } -STATIC void mp_machine_wdt_timeout_ms_set(machine_wdt_obj_t *self, mp_int_t timeout_ms) { +static void mp_machine_wdt_timeout_ms_set(machine_wdt_obj_t *self, mp_int_t timeout_ms) { (void)self; // confine to the valid range diff --git a/ports/mimxrt/mimxrt_flash.c b/ports/mimxrt/mimxrt_flash.c index d229367e81060..fdd48e280bc15 100644 --- a/ports/mimxrt/mimxrt_flash.c +++ b/ports/mimxrt/mimxrt_flash.c @@ -42,11 +42,11 @@ typedef struct _mimxrt_flash_obj_t { uint32_t flash_size; } mimxrt_flash_obj_t; -STATIC mimxrt_flash_obj_t mimxrt_flash_obj = { +static mimxrt_flash_obj_t mimxrt_flash_obj = { .base = { &mimxrt_flash_type } }; -STATIC mp_obj_t mimxrt_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t mimxrt_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // Check args. mp_arg_check_num(n_args, n_kw, 0, 0, false); @@ -62,7 +62,7 @@ STATIC mp_obj_t mimxrt_flash_make_new(const mp_obj_type_t *type, size_t n_args, // readblocks(block_num, buf, [offset]) // read size of buffer number of bytes from block (with offset) into buffer -STATIC mp_obj_t mimxrt_flash_readblocks(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mimxrt_flash_readblocks(size_t n_args, const mp_obj_t *args) { mimxrt_flash_obj_t *self = MP_OBJ_TO_PTR(args[0]); mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_WRITE); @@ -76,13 +76,13 @@ STATIC mp_obj_t mimxrt_flash_readblocks(size_t n_args, const mp_obj_t *args) { flash_read_block((self->flash_base + offset), (uint8_t *)bufinfo.buf, (uint32_t)bufinfo.len); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mimxrt_flash_readblocks_obj, 3, 4, mimxrt_flash_readblocks); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mimxrt_flash_readblocks_obj, 3, 4, mimxrt_flash_readblocks); // writeblocks(block_num, buf, [offset]) // Erase block based on block_num and write buffer size number of bytes from buffer into block. If additional offset // parameter is provided only write operation at block start + offset will be performed. // This requires a prior erase operation of the block! -STATIC mp_obj_t mimxrt_flash_writeblocks(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mimxrt_flash_writeblocks(size_t n_args, const mp_obj_t *args) { status_t status; mimxrt_flash_obj_t *self = MP_OBJ_TO_PTR(args[0]); mp_buffer_info_t bufinfo; @@ -110,10 +110,10 @@ STATIC mp_obj_t mimxrt_flash_writeblocks(size_t n_args, const mp_obj_t *args) { return MP_OBJ_NEW_SMALL_INT(status != kStatus_Success); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mimxrt_flash_writeblocks_obj, 3, 4, mimxrt_flash_writeblocks); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mimxrt_flash_writeblocks_obj, 3, 4, mimxrt_flash_writeblocks); // ioctl(op, arg) -STATIC mp_obj_t mimxrt_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { +static mp_obj_t mimxrt_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { mimxrt_flash_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t cmd = mp_obj_get_int(cmd_in); status_t status; @@ -137,14 +137,14 @@ STATIC mp_obj_t mimxrt_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t a return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(mimxrt_flash_ioctl_obj, mimxrt_flash_ioctl); +static MP_DEFINE_CONST_FUN_OBJ_3(mimxrt_flash_ioctl_obj, mimxrt_flash_ioctl); -STATIC const mp_rom_map_elem_t mimxrt_flash_locals_dict_table[] = { +static const mp_rom_map_elem_t mimxrt_flash_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&mimxrt_flash_readblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&mimxrt_flash_writeblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&mimxrt_flash_ioctl_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mimxrt_flash_locals_dict, mimxrt_flash_locals_dict_table); +static MP_DEFINE_CONST_DICT(mimxrt_flash_locals_dict, mimxrt_flash_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mimxrt_flash_type, diff --git a/ports/mimxrt/modmachine.c b/ports/mimxrt/modmachine.c index e01703af8cd4b..1212914d3b452 100644 --- a/ports/mimxrt/modmachine.c +++ b/ports/mimxrt/modmachine.c @@ -76,20 +76,20 @@ typedef enum { MP_SOFT_RESET } reset_reason_t; -STATIC mp_obj_t mp_machine_unique_id(void) { +static mp_obj_t mp_machine_unique_id(void) { unsigned char id[8]; mp_hal_get_unique_id(id); return mp_obj_new_bytes(id, sizeof(id)); } -NORETURN STATIC void mp_machine_reset(void) { +NORETURN static void mp_machine_reset(void) { WDOG_TriggerSystemSoftwareReset(WDOG1); while (true) { ; } } -STATIC mp_int_t mp_machine_reset_cause(void) { +static mp_int_t mp_machine_reset_cause(void) { #ifdef MIMXRT117x_SERIES uint32_t user_reset_flag = kSRC_M7CoreIppUserResetFlag; #else @@ -110,23 +110,23 @@ STATIC mp_int_t mp_machine_reset_cause(void) { return reset_cause; } -STATIC mp_obj_t mp_machine_get_freq(void) { +static mp_obj_t mp_machine_get_freq(void) { return MP_OBJ_NEW_SMALL_INT(mp_hal_get_cpu_freq()); } -STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) { +static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) { mp_raise_NotImplementedError(NULL); } -STATIC void mp_machine_idle(void) { +static void mp_machine_idle(void) { MICROPY_EVENT_POLL_HOOK; } -STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) { +static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) { mp_raise_NotImplementedError(NULL); } -NORETURN STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) { +NORETURN static void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) { if (n_args != 0) { mp_int_t seconds = mp_obj_get_int(args[0]) / 1000; if (seconds > 0) { diff --git a/ports/mimxrt/modmimxrt.c b/ports/mimxrt/modmimxrt.c index 4756efc0a27e7..0f67538ce0d21 100644 --- a/ports/mimxrt/modmimxrt.c +++ b/ports/mimxrt/modmimxrt.c @@ -28,11 +28,11 @@ #include "py/runtime.h" #include "modmimxrt.h" -STATIC const mp_rom_map_elem_t mimxrt_module_globals_table[] = { +static const mp_rom_map_elem_t mimxrt_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_mimxrt) }, { MP_ROM_QSTR(MP_QSTR_Flash), MP_ROM_PTR(&mimxrt_flash_type) }, }; -STATIC MP_DEFINE_CONST_DICT(mimxrt_module_globals, mimxrt_module_globals_table); +static MP_DEFINE_CONST_DICT(mimxrt_module_globals, mimxrt_module_globals_table); const mp_obj_module_t mp_module_mimxrt = { .base = { &mp_type_module }, diff --git a/ports/mimxrt/modos.c b/ports/mimxrt/modos.c index 2ee841815252c..0eb32afba3e31 100644 --- a/ports/mimxrt/modos.c +++ b/ports/mimxrt/modos.c @@ -43,8 +43,8 @@ static bool initialized = false; #if defined(MIMXRT117x_SERIES) -STATIC caam_handle_t caam_handle; -STATIC caam_rng_state_handle_t caam_state_handle = kCAAM_RngStateHandle0; +static caam_handle_t caam_handle; +static caam_rng_state_handle_t caam_state_handle = kCAAM_RngStateHandle0; #if defined(FSL_FEATURE_HAS_L1CACHE) || defined(__DCACHE_PRESENT) AT_NONCACHEABLE_SECTION(static caam_job_ring_interface_t s_jrif0); @@ -52,7 +52,7 @@ AT_NONCACHEABLE_SECTION(static caam_job_ring_interface_t s_jrif0); static caam_job_ring_interface_t s_jrif0; #endif -STATIC void trng_start(void) { +static void trng_start(void) { caam_config_t config; if (!initialized) { @@ -71,7 +71,7 @@ void trng_random_data(unsigned char *output, size_t len) { #else -STATIC void trng_start(void) { +static void trng_start(void) { trng_config_t trngConfig; if (!initialized) { @@ -99,7 +99,7 @@ uint32_t trng_random_u32(void) { } #if MICROPY_PY_OS_URANDOM -STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { +static mp_obj_t mp_os_urandom(mp_obj_t num) { mp_int_t n = mp_obj_get_int(num); vstr_t vstr; vstr_init_len(&vstr, n); @@ -109,5 +109,5 @@ STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); #endif diff --git a/ports/mimxrt/modtime.c b/ports/mimxrt/modtime.c index b0c927899f996..a2ccf1b273fc7 100644 --- a/ports/mimxrt/modtime.c +++ b/ports/mimxrt/modtime.c @@ -30,7 +30,7 @@ #include "fsl_snvs_lp.h" // Return the localtime as an 8-tuple. -STATIC mp_obj_t mp_time_localtime_get(void) { +static mp_obj_t mp_time_localtime_get(void) { // Get current date and time. snvs_lp_srtc_datetime_t t; SNVS_LP_SRTC_GetDatetime(SNVS, &t); @@ -48,7 +48,7 @@ STATIC mp_obj_t mp_time_localtime_get(void) { } // Return the number of seconds since the Epoch. -STATIC mp_obj_t mp_time_time_get(void) { +static mp_obj_t mp_time_time_get(void) { snvs_lp_srtc_datetime_t t; SNVS_LP_SRTC_GetDatetime(SNVS, &t); // EPOCH is 1970 for this port, which leads to the following trouble: diff --git a/ports/mimxrt/mpbthciport.c b/ports/mimxrt/mpbthciport.c index 2b0bcd2cf6c4d..45f729671728d 100644 --- a/ports/mimxrt/mpbthciport.c +++ b/ports/mimxrt/mpbthciport.c @@ -46,10 +46,10 @@ uint8_t mp_bluetooth_hci_cmd_buf[4 + 256]; -STATIC mp_sched_node_t mp_bluetooth_hci_sched_node; -STATIC soft_timer_entry_t mp_bluetooth_hci_soft_timer; +static mp_sched_node_t mp_bluetooth_hci_sched_node; +static soft_timer_entry_t mp_bluetooth_hci_soft_timer; -STATIC void mp_bluetooth_hci_soft_timer_callback(soft_timer_entry_t *self) { +static void mp_bluetooth_hci_soft_timer_callback(soft_timer_entry_t *self) { mp_bluetooth_hci_poll_now(); } @@ -62,7 +62,7 @@ void mp_bluetooth_hci_init(void) { ); } -STATIC void mp_bluetooth_hci_start_polling(void) { +static void mp_bluetooth_hci_start_polling(void) { mp_bluetooth_hci_poll_now(); } @@ -71,7 +71,7 @@ void mp_bluetooth_hci_poll_in_ms(uint32_t ms) { } // For synchronous mode, we run all BLE stack code inside a scheduled task. -STATIC void run_events_scheduled_task(mp_sched_node_t *node) { +static void run_events_scheduled_task(mp_sched_node_t *node) { // This will process all buffered HCI UART data, and run any callouts or events. mp_bluetooth_hci_poll(); } diff --git a/ports/mimxrt/mphalport.c b/ports/mimxrt/mphalport.c index be4b1d8b5c815..6e982b8c8e245 100644 --- a/ports/mimxrt/mphalport.c +++ b/ports/mimxrt/mphalport.c @@ -41,7 +41,7 @@ #include CPU_HEADER_H -STATIC uint8_t stdin_ringbuf_array[MICROPY_HW_STDIN_BUFFER_LEN]; +static uint8_t stdin_ringbuf_array[MICROPY_HW_STDIN_BUFFER_LEN]; ringbuf_t stdin_ringbuf = {stdin_ringbuf_array, sizeof(stdin_ringbuf_array), 0, 0}; uint8_t cdc_itf_pending; // keep track of cdc interfaces which need attention to poll diff --git a/ports/mimxrt/mpnetworkport.c b/ports/mimxrt/mpnetworkport.c index 2ca3426197538..aa8eef3ee2390 100644 --- a/ports/mimxrt/mpnetworkport.c +++ b/ports/mimxrt/mpnetworkport.c @@ -55,7 +55,7 @@ u32_t sys_now(void) { return mp_hal_ticks_ms(); } -STATIC void pyb_lwip_poll(void) { +static void pyb_lwip_poll(void) { // Run the lwIP internal updates sys_check_timeouts(); } diff --git a/ports/mimxrt/network_lan.c b/ports/mimxrt/network_lan.c index 355698e0b5882..e01079cbf3144 100644 --- a/ports/mimxrt/network_lan.c +++ b/ports/mimxrt/network_lan.c @@ -55,12 +55,12 @@ typedef struct _network_lan_obj_t { } network_lan_obj_t; -STATIC const network_lan_obj_t network_lan_eth0 = { { &network_lan_type }, ð_instance0 }; +static const network_lan_obj_t network_lan_eth0 = { { &network_lan_type }, ð_instance0 }; #if defined(ENET_DUAL_PORT) -STATIC const network_lan_obj_t network_lan_eth1 = { { &network_lan_type }, ð_instance1 }; +static const network_lan_obj_t network_lan_eth1 = { { &network_lan_type }, ð_instance1 }; #endif -STATIC void network_lan_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void network_lan_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { network_lan_obj_t *self = MP_OBJ_TO_PTR(self_in); struct netif *netif = eth_netif(self->eth); int status = eth_link_status(self->eth); @@ -74,7 +74,7 @@ STATIC void network_lan_print(const mp_print_t *print, mp_obj_t self_in, mp_prin ); } -STATIC mp_obj_t network_lan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t network_lan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_id, ARG_phy_type, ARG_phy_addr, ARG_ref_clk_mode}; static const mp_arg_t allowed_args[] = { { MP_QSTR_id, MP_ARG_INT, {.u_int = 0} }, @@ -148,7 +148,7 @@ STATIC mp_obj_t network_lan_make_new(const mp_obj_type_t *type, size_t n_args, s return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t network_lan_active(size_t n_args, const mp_obj_t *args) { +static mp_obj_t network_lan_active(size_t n_args, const mp_obj_t *args) { network_lan_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 1) { return mp_obj_new_bool(eth_link_status(self->eth)); @@ -165,21 +165,21 @@ STATIC mp_obj_t network_lan_active(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_lan_active_obj, 1, 2, network_lan_active); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_lan_active_obj, 1, 2, network_lan_active); -STATIC mp_obj_t network_lan_isconnected(mp_obj_t self_in) { +static mp_obj_t network_lan_isconnected(mp_obj_t self_in) { network_lan_obj_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_bool(eth_link_status(self->eth) == 3); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_lan_isconnected_obj, network_lan_isconnected); +static MP_DEFINE_CONST_FUN_OBJ_1(network_lan_isconnected_obj, network_lan_isconnected); -STATIC mp_obj_t network_lan_ifconfig(size_t n_args, const mp_obj_t *args) { +static mp_obj_t network_lan_ifconfig(size_t n_args, const mp_obj_t *args) { network_lan_obj_t *self = MP_OBJ_TO_PTR(args[0]); return mod_network_nic_ifconfig(eth_netif(self->eth), n_args - 1, args + 1); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_lan_ifconfig_obj, 1, 2, network_lan_ifconfig); -STATIC mp_obj_t network_lan_status(size_t n_args, const mp_obj_t *args) { +static mp_obj_t network_lan_status(size_t n_args, const mp_obj_t *args) { network_lan_obj_t *self = MP_OBJ_TO_PTR(args[0]); (void)self; @@ -190,9 +190,9 @@ STATIC mp_obj_t network_lan_status(size_t n_args, const mp_obj_t *args) { mp_raise_ValueError(MP_ERROR_TEXT("unknown status param")); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_lan_status_obj, 1, 2, network_lan_status); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_lan_status_obj, 1, 2, network_lan_status); -STATIC mp_obj_t network_lan_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { +static mp_obj_t network_lan_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { network_lan_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (kwargs->used == 0) { @@ -235,9 +235,9 @@ STATIC mp_obj_t network_lan_config(size_t n_args, const mp_obj_t *args, mp_map_t return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(network_lan_config_obj, 1, network_lan_config); +static MP_DEFINE_CONST_FUN_OBJ_KW(network_lan_config_obj, 1, network_lan_config); -STATIC const mp_rom_map_elem_t network_lan_locals_dict_table[] = { +static const mp_rom_map_elem_t network_lan_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&network_lan_active_obj) }, { MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&network_lan_isconnected_obj) }, { MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&network_lan_ifconfig_obj) }, @@ -252,7 +252,7 @@ STATIC const mp_rom_map_elem_t network_lan_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_IN), MP_ROM_INT(PHY_TX_CLK_IN) }, { MP_ROM_QSTR(MP_QSTR_OUT), MP_ROM_INT(PHY_TX_CLK_OUT) }, }; -STATIC MP_DEFINE_CONST_DICT(network_lan_locals_dict, network_lan_locals_dict_table); +static MP_DEFINE_CONST_DICT(network_lan_locals_dict, network_lan_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( network_lan_type, diff --git a/ports/nrf/boards/MICROBIT/modules/microbitdisplay.c b/ports/nrf/boards/MICROBIT/modules/microbitdisplay.c index ff3c499fa3251..dea12faf42cb0 100644 --- a/ports/nrf/boards/MICROBIT/modules/microbitdisplay.c +++ b/ports/nrf/boards/MICROBIT/modules/microbitdisplay.c @@ -135,7 +135,7 @@ bool microbit_display_active_animation(void) { return async_mode == ASYNC_MODE_ANIMATION; } -STATIC void async_stop(void) { +static void async_stop(void) { async_iterator = NULL; async_mode = ASYNC_MODE_STOPPED; async_tick = 0; @@ -146,7 +146,7 @@ STATIC void async_stop(void) { wakeup_event = true; } -STATIC void wait_for_event(void) { +static void wait_for_event(void) { while (!wakeup_event) { // allow CTRL-C to stop the animation if (MP_STATE_THREAD(mp_pending_exception) != MP_OBJ_NULL) { @@ -508,7 +508,7 @@ void microbit_display_set_pixel(microbit_display_obj_t *display, mp_int_t x, mp_ display->brightnesses |= (1 << bright); } -STATIC mp_obj_t microbit_display_set_pixel_func(mp_uint_t n_args, const mp_obj_t *args) { +static mp_obj_t microbit_display_set_pixel_func(mp_uint_t n_args, const mp_obj_t *args) { (void)n_args; microbit_display_obj_t *self = (microbit_display_obj_t*)args[0]; microbit_display_set_pixel(self, mp_obj_get_int(args[1]), mp_obj_get_int(args[2]), mp_obj_get_int(args[3])); @@ -523,13 +523,13 @@ mp_int_t microbit_display_get_pixel(microbit_display_obj_t *display, mp_int_t x, return display->image_buffer[x][y]; } -STATIC mp_obj_t microbit_display_get_pixel_func(mp_obj_t self_in, mp_obj_t x_in, mp_obj_t y_in) { +static mp_obj_t microbit_display_get_pixel_func(mp_obj_t self_in, mp_obj_t x_in, mp_obj_t y_in) { microbit_display_obj_t *self = (microbit_display_obj_t*)self_in; return MP_OBJ_NEW_SMALL_INT(microbit_display_get_pixel(self, mp_obj_get_int(x_in), mp_obj_get_int(y_in))); } MP_DEFINE_CONST_FUN_OBJ_3(microbit_display_get_pixel_obj, microbit_display_get_pixel_func); -STATIC const mp_rom_map_elem_t microbit_display_locals_dict_table[] = { +static const mp_rom_map_elem_t microbit_display_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_get_pixel), MP_ROM_PTR(µbit_display_get_pixel_obj) }, { MP_ROM_QSTR(MP_QSTR_set_pixel), MP_ROM_PTR(µbit_display_set_pixel_obj) }, { MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(µbit_display_show_obj) }, @@ -540,7 +540,7 @@ STATIC const mp_rom_map_elem_t microbit_display_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_is_on), MP_ROM_PTR(µbit_display_is_on_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(microbit_display_locals_dict, microbit_display_locals_dict_table); +static MP_DEFINE_CONST_DICT(microbit_display_locals_dict, microbit_display_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( microbit_display_type, diff --git a/ports/nrf/boards/MICROBIT/modules/microbitimage.c b/ports/nrf/boards/MICROBIT/modules/microbitimage.c index b3505c20a394d..43fae777c7ff9 100644 --- a/ports/nrf/boards/MICROBIT/modules/microbitimage.c +++ b/ports/nrf/boards/MICROBIT/modules/microbitimage.c @@ -40,7 +40,7 @@ const monochrome_5by5_t microbit_blank_image = { { 0, 0, 0 } }; -STATIC void microbit_image_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void microbit_image_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { microbit_image_obj_t *self = (microbit_image_obj_t*)self_in; mp_printf(print, "Image("); if (kind == PRINT_STR) @@ -112,7 +112,7 @@ mp_int_t imageHeight(microbit_image_obj_t * p_image) { return p_image->greyscale.height; } -STATIC greyscale_t *greyscale_new(mp_int_t w, mp_int_t h) { +static greyscale_t *greyscale_new(mp_int_t w, mp_int_t h) { greyscale_t *result = mp_obj_malloc_var(greyscale_t, byte_data, uint8_t, (w*h+1)>>1, µbit_image_type); result->five = 0; result->width = w; @@ -144,7 +144,7 @@ greyscale_t * imageInvert(microbit_image_obj_t * p_image) { return result; } -STATIC microbit_image_obj_t *image_from_parsed_str(const char *s, mp_int_t len) { +static microbit_image_obj_t *image_from_parsed_str(const char *s, mp_int_t len) { mp_int_t w = 0; mp_int_t h = 0; mp_int_t line_len = 0; @@ -201,7 +201,7 @@ STATIC microbit_image_obj_t *image_from_parsed_str(const char *s, mp_int_t len) } -STATIC mp_obj_t microbit_image_make_new(const mp_obj_type_t *type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +static mp_obj_t microbit_image_make_new(const mp_obj_type_t *type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { (void)type_in; mp_arg_check_num(n_args, n_kw, 0, 3, false); @@ -270,7 +270,7 @@ static void clear_rect(greyscale_t *img, mp_int_t x0, mp_int_t y0,mp_int_t x1, m } } -STATIC void image_blit(microbit_image_obj_t *src, greyscale_t *dest, mp_int_t x, mp_int_t y, mp_int_t w, mp_int_t h, mp_int_t xdest, mp_int_t ydest) { +static void image_blit(microbit_image_obj_t *src, greyscale_t *dest, mp_int_t x, mp_int_t y, mp_int_t w, mp_int_t h, mp_int_t xdest, mp_int_t ydest) { if (w < 0) w = 0; if (h < 0) @@ -323,7 +323,7 @@ greyscale_t *image_shift(microbit_image_obj_t *self, mp_int_t x, mp_int_t y) { return result; } -STATIC microbit_image_obj_t *image_crop(microbit_image_obj_t *img, mp_int_t x, mp_int_t y, mp_int_t w, mp_int_t h) { +static microbit_image_obj_t *image_crop(microbit_image_obj_t *img, mp_int_t x, mp_int_t y, mp_int_t w, mp_int_t h) { if (w < 0) w = 0; if (h < 0) @@ -483,7 +483,7 @@ mp_obj_t microbit_image_invert(mp_obj_t self_in) { MP_DEFINE_CONST_FUN_OBJ_1(microbit_image_invert_obj, microbit_image_invert); -STATIC const mp_rom_map_elem_t microbit_image_locals_dict_table[] = { +static const mp_rom_map_elem_t microbit_image_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(µbit_image_width_obj) }, { MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(µbit_image_height_obj) }, { MP_ROM_QSTR(MP_QSTR_get_pixel), MP_ROM_PTR(µbit_image_get_pixel_obj) }, @@ -565,14 +565,14 @@ STATIC const mp_rom_map_elem_t microbit_image_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_SNAKE), MP_ROM_PTR(µbit_const_image_snake_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(microbit_image_locals_dict, microbit_image_locals_dict_table); +static MP_DEFINE_CONST_DICT(microbit_image_locals_dict, microbit_image_locals_dict_table); #define THE_FONT font_pendolino3_5x5_pad3msb #define ASCII_START 32 #define ASCII_END 126 -STATIC const unsigned char *get_font_data_from_char(char c) { +static const unsigned char *get_font_data_from_char(char c) { if (c < ASCII_START || c > ASCII_END) { c = '?'; } @@ -580,7 +580,7 @@ STATIC const unsigned char *get_font_data_from_char(char c) { return THE_FONT + offset; } -STATIC mp_int_t get_pixel_from_font_data(const unsigned char *data, int x, int y) { +static mp_int_t get_pixel_from_font_data(const unsigned char *data, int x, int y) { /* The following logic belongs in MicroBitFont */ return ((data[y]>>(4-x))&1); } @@ -645,7 +645,7 @@ microbit_image_obj_t *microbit_image_sum(microbit_image_obj_t *lhs, microbit_ima return (microbit_image_obj_t *)result; } -STATIC mp_obj_t image_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { +static mp_obj_t image_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { if (mp_obj_get_type(lhs_in) != µbit_image_type) { return MP_OBJ_NULL; // op not supported } @@ -724,7 +724,7 @@ mp_obj_t scrolling_string_image_iterable(const char* str, mp_uint_t len, mp_obj_ return result; } -STATIC int font_column_non_blank(const unsigned char *font_data, unsigned int col) { +static int font_column_non_blank(const unsigned char *font_data, unsigned int col) { for (int y = 0; y < 5; ++y) { if (get_pixel_from_font_data(font_data, col, y)) { return 1; @@ -734,7 +734,7 @@ STATIC int font_column_non_blank(const unsigned char *font_data, unsigned int co } /* Not strictly the rightmost non-blank column, but the rightmost in columns 2,3 or 4. */ -STATIC unsigned int rightmost_non_blank_column(const unsigned char *font_data) { +static unsigned int rightmost_non_blank_column(const unsigned char *font_data) { if (font_column_non_blank(font_data, 4)) { return 4; } @@ -760,7 +760,7 @@ static void restart(scrolling_string_iterator_t *iter) { } } -STATIC mp_obj_t get_microbit_scrolling_string_iter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t get_microbit_scrolling_string_iter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) { (void)iter_buf; scrolling_string_t *str = (scrolling_string_t *)o_in; scrolling_string_iterator_t *result = mp_obj_malloc(scrolling_string_iterator_t, µbit_scrolling_string_iterator_type); @@ -774,7 +774,7 @@ STATIC mp_obj_t get_microbit_scrolling_string_iter(mp_obj_t o_in, mp_obj_iter_bu return result; } -STATIC mp_obj_t microbit_scrolling_string_iter_next(mp_obj_t o_in) { +static mp_obj_t microbit_scrolling_string_iter_next(mp_obj_t o_in) { scrolling_string_iterator_t *iter = (scrolling_string_iterator_t *)o_in; if (iter->next_char == iter->end && iter->offset == 5) { if (iter->repeat) { diff --git a/ports/nrf/boards/MICROBIT/modules/modmicrobit.c b/ports/nrf/boards/MICROBIT/modules/modmicrobit.c index 06b3e5f6ab916..e56f6441594a5 100644 --- a/ports/nrf/boards/MICROBIT/modules/modmicrobit.c +++ b/ports/nrf/boards/MICROBIT/modules/modmicrobit.c @@ -35,13 +35,13 @@ extern uint32_t ticks; -STATIC mp_obj_t microbit_reset_(void) { +static mp_obj_t microbit_reset_(void) { NVIC_SystemReset(); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_0(microbit_reset_obj, microbit_reset_); -STATIC mp_obj_t microbit_sleep(mp_obj_t ms_in) { +static mp_obj_t microbit_sleep(mp_obj_t ms_in) { mp_int_t ms = 0; if (mp_obj_is_integer(ms_in)) { ms = mp_obj_get_int(ms_in); @@ -57,7 +57,7 @@ STATIC mp_obj_t microbit_sleep(mp_obj_t ms_in) { } MP_DEFINE_CONST_FUN_OBJ_1(microbit_sleep_obj, microbit_sleep); -STATIC mp_obj_t microbit_running_time(void) { +static mp_obj_t microbit_running_time(void) { return MP_OBJ_NEW_SMALL_INT(ticks); } MP_DEFINE_CONST_FUN_OBJ_0(microbit_running_time_obj, microbit_running_time); @@ -70,7 +70,7 @@ static const monochrome_5by5_t panic = SMALL_IMAGE( 1,0,0,0,1 ); -STATIC mp_obj_t microbit_panic(mp_uint_t n_args, const mp_obj_t *args) { +static mp_obj_t microbit_panic(mp_uint_t n_args, const mp_obj_t *args) { while(true) { microbit_display_show(µbit_display_obj, (microbit_image_obj_t*)&panic); mp_hal_delay_ms(1000); @@ -95,7 +95,7 @@ STATIC mp_obj_t microbit_panic(mp_uint_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(microbit_panic_obj, 0, 1, microbit_panic); -STATIC mp_obj_t microbit_temperature(void) { +static mp_obj_t microbit_temperature(void) { int temp = temp_read(); #if MICROPY_PY_BUILTINS_FLOAT return mp_obj_new_float((mp_float_t)temp / MICROPY_FLOAT_CONST(100.0)); @@ -109,7 +109,7 @@ void board_modules_init0(void) { ticker_register_low_pri_callback(microbit_display_tick); } -STATIC const mp_rom_map_elem_t microbit_module_globals_table[] = { +static const mp_rom_map_elem_t microbit_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_Image), MP_ROM_PTR(µbit_image_type) }, { MP_ROM_QSTR(MP_QSTR_display), MP_ROM_PTR(µbit_display_obj) }, @@ -150,7 +150,7 @@ STATIC const mp_rom_map_elem_t microbit_module_globals_table[] = { */ }; -STATIC MP_DEFINE_CONST_DICT(microbit_module_globals, microbit_module_globals_table); +static MP_DEFINE_CONST_DICT(microbit_module_globals, microbit_module_globals_table); const mp_obj_module_t microbit_module = { .base = { &mp_type_module }, diff --git a/ports/nrf/boards/make-pins.py b/ports/nrf/boards/make-pins.py index 57e815a43d949..30da035589daf 100644 --- a/ports/nrf/boards/make-pins.py +++ b/ports/nrf/boards/make-pins.py @@ -241,7 +241,7 @@ def parse_board_file(self, filename): def print_named(self, label, named_pins, out_source): print( - "STATIC const mp_rom_map_elem_t pin_{:s}_pins_locals_dict_table[] = {{".format(label), + "static const mp_rom_map_elem_t pin_{:s}_pins_locals_dict_table[] = {{".format(label), file=out_source, ) for named_pin in named_pins: diff --git a/ports/nrf/drivers/bluetooth/ble_uart.c b/ports/nrf/drivers/bluetooth/ble_uart.c index 4ea811572518f..a342a1e00610c 100644 --- a/ports/nrf/drivers/bluetooth/ble_uart.c +++ b/ports/nrf/drivers/bluetooth/ble_uart.c @@ -173,7 +173,7 @@ uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) { } #endif -STATIC void gap_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t conn_handle, uint16_t length, uint8_t * data) { +static void gap_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t conn_handle, uint16_t length, uint8_t * data) { ubluepy_peripheral_obj_t * self = MP_OBJ_TO_PTR(self_in); if (event_id == 16) { // connect event @@ -187,7 +187,7 @@ STATIC void gap_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t conn } } -STATIC void gatts_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t attr_handle, uint16_t length, uint8_t * data) { +static void gatts_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t attr_handle, uint16_t length, uint8_t * data) { ubluepy_peripheral_obj_t * self = MP_OBJ_TO_PTR(self_in); (void)self; diff --git a/ports/nrf/drivers/flash.c b/ports/nrf/drivers/flash.c index 85e5f71d63ae3..74a7794ee8327 100644 --- a/ports/nrf/drivers/flash.c +++ b/ports/nrf/drivers/flash.c @@ -33,13 +33,13 @@ #include "nrf_soc.h" // Rotates bits in `value` left `shift` times. -STATIC inline uint32_t rotate_left(uint32_t value, uint32_t shift) { +static inline uint32_t rotate_left(uint32_t value, uint32_t shift) { return (value << shift) | (value >> (32 - shift)); } -STATIC volatile flash_state_t flash_operation_state = FLASH_STATE_BUSY; +static volatile flash_state_t flash_operation_state = FLASH_STATE_BUSY; -STATIC void operation_init(void) { +static void operation_init(void) { flash_operation_state = FLASH_STATE_BUSY; } @@ -47,7 +47,7 @@ void flash_operation_finished(flash_state_t result) { flash_operation_state = result; } -STATIC bool operation_wait(uint32_t result) { +static bool operation_wait(uint32_t result) { if (ble_drv_stack_enabled() != 1) { // SoftDevice is not enabled, no event will be generated. return result == NRF_SUCCESS; diff --git a/ports/nrf/modules/ble/modble.c b/ports/nrf/modules/ble/modble.c index 3a9c6b20da790..7a9b55523efb7 100644 --- a/ports/nrf/modules/ble/modble.c +++ b/ports/nrf/modules/ble/modble.c @@ -81,12 +81,12 @@ mp_obj_t ble_obj_address(void) { return mac_str; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(ble_obj_enable_obj, ble_obj_enable); -STATIC MP_DEFINE_CONST_FUN_OBJ_0(ble_obj_disable_obj, ble_obj_disable); -STATIC MP_DEFINE_CONST_FUN_OBJ_0(ble_obj_enabled_obj, ble_obj_enabled); -STATIC MP_DEFINE_CONST_FUN_OBJ_0(ble_obj_address_obj, ble_obj_address); +static MP_DEFINE_CONST_FUN_OBJ_0(ble_obj_enable_obj, ble_obj_enable); +static MP_DEFINE_CONST_FUN_OBJ_0(ble_obj_disable_obj, ble_obj_disable); +static MP_DEFINE_CONST_FUN_OBJ_0(ble_obj_enabled_obj, ble_obj_enabled); +static MP_DEFINE_CONST_FUN_OBJ_0(ble_obj_address_obj, ble_obj_address); -STATIC const mp_rom_map_elem_t ble_module_globals_table[] = { +static const mp_rom_map_elem_t ble_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ble) }, { MP_ROM_QSTR(MP_QSTR_enable), MP_ROM_PTR(&ble_obj_enable_obj) }, { MP_ROM_QSTR(MP_QSTR_disable), MP_ROM_PTR(&ble_obj_disable_obj) }, @@ -95,7 +95,7 @@ STATIC const mp_rom_map_elem_t ble_module_globals_table[] = { }; -STATIC MP_DEFINE_CONST_DICT(ble_module_globals, ble_module_globals_table); +static MP_DEFINE_CONST_DICT(ble_module_globals, ble_module_globals_table); const mp_obj_module_t ble_module = { .base = { &mp_type_module }, diff --git a/ports/nrf/modules/board/led.c b/ports/nrf/modules/board/led.c index 57065a48517a2..6c0df5652633b 100644 --- a/ports/nrf/modules/board/led.c +++ b/ports/nrf/modules/board/led.c @@ -142,7 +142,7 @@ void led_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t ki /// Create an LED object associated with the given LED: /// /// - `id` is the LED number, 1-4. -STATIC mp_obj_t led_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t led_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, 1, false); @@ -182,17 +182,17 @@ mp_obj_t led_obj_toggle(mp_obj_t self_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_on_obj, led_obj_on); -STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_off_obj, led_obj_off); -STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_toggle_obj, led_obj_toggle); +static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_on_obj, led_obj_on); +static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_off_obj, led_obj_off); +static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_toggle_obj, led_obj_toggle); -STATIC const mp_rom_map_elem_t led_locals_dict_table[] = { +static const mp_rom_map_elem_t led_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_on), MP_ROM_PTR(&led_obj_on_obj) }, { MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(&led_obj_off_obj) }, { MP_ROM_QSTR(MP_QSTR_toggle), MP_ROM_PTR(&led_obj_toggle_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(led_locals_dict, led_locals_dict_table); +static MP_DEFINE_CONST_DICT(led_locals_dict, led_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( board_led_type, diff --git a/ports/nrf/modules/board/modboard.c b/ports/nrf/modules/board/modboard.c index 1fe3dcc5c9817..7675a254f424b 100644 --- a/ports/nrf/modules/board/modboard.c +++ b/ports/nrf/modules/board/modboard.c @@ -38,7 +38,7 @@ #define PYB_LED_MODULE #endif -STATIC const mp_rom_map_elem_t board_module_globals_table[] = { +static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_board) }, #if MICROPY_REPL_INFO { MP_ROM_QSTR(MP_QSTR_repl_info), MP_ROM_PTR(&pyb_set_repl_info_obj) }, @@ -47,7 +47,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { }; -STATIC MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); +static MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); const mp_obj_module_t board_module = { .base = { &mp_type_module }, diff --git a/ports/nrf/modules/machine/adc.c b/ports/nrf/modules/machine/adc.c index 9bebcbe0869fe..c45d0ba5ffdab 100644 --- a/ports/nrf/modules/machine/adc.c +++ b/ports/nrf/modules/machine/adc.c @@ -44,7 +44,7 @@ typedef struct _machine_adc_obj_t { #endif } machine_adc_obj_t; -STATIC const machine_adc_obj_t machine_adc_obj[] = { +static const machine_adc_obj_t machine_adc_obj[] = { #if NRF51 {{&machine_adc_type}, .id = 0, .ain = NRF_ADC_CONFIG_INPUT_0}, {{&machine_adc_type}, .id = 1, .ain = NRF_ADC_CONFIG_INPUT_1}, @@ -73,7 +73,7 @@ void adc_init0(void) { #endif } -STATIC int adc_find(mp_obj_t id) { +static int adc_find(mp_obj_t id) { int adc_idx; if (mp_obj_is_int(id)) { // Given an integer id @@ -104,14 +104,14 @@ STATIC int adc_find(mp_obj_t id) { { MP_ROM_QSTR(MP_QSTR_battery_level), MP_ROM_PTR(&mp_machine_adc_battery_level_obj) }, /* class method */ \ // Return a string describing the ADC object. -STATIC void mp_machine_adc_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { +static void mp_machine_adc_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { machine_adc_obj_t *self = o; mp_printf(print, "ADC(%u)", self->id); } // for make_new -STATIC mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_id }; static const mp_arg_t allowed_args[] = { { MP_QSTR_id, MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_SMALL_INT(-1) } }, @@ -171,7 +171,7 @@ int16_t machine_adc_value_read(machine_adc_obj_t * adc_obj) { } // read_u16() -STATIC mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) { +static mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) { int16_t raw = machine_adc_value_read(self); #if defined(NRF52_SERIES) // raw is signed but the channel is in single-ended mode and this method cannot return negative values @@ -192,7 +192,7 @@ mp_obj_t machine_adc_value(mp_obj_t self_in) { return MP_OBJ_NEW_SMALL_INT(value); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_machine_adc_value_obj, machine_adc_value); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_machine_adc_value_obj, machine_adc_value); #if NRF51 @@ -278,4 +278,4 @@ mp_obj_t machine_adc_battery_level(void) { return MP_OBJ_NEW_SMALL_INT(batt_in_percent); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_machine_adc_battery_level_obj, machine_adc_battery_level); +static MP_DEFINE_CONST_FUN_OBJ_0(mp_machine_adc_battery_level_obj, machine_adc_battery_level); diff --git a/ports/nrf/modules/machine/i2c.c b/ports/nrf/modules/machine/i2c.c index 6d2b83a454380..7e488366d70ba 100644 --- a/ports/nrf/modules/machine/i2c.c +++ b/ports/nrf/modules/machine/i2c.c @@ -71,7 +71,7 @@ typedef struct _machine_hard_i2c_obj_t { nrfx_twi_t p_twi; // Driver instance } machine_hard_i2c_obj_t; -STATIC const machine_hard_i2c_obj_t machine_hard_i2c_obj[] = { +static const machine_hard_i2c_obj_t machine_hard_i2c_obj[] = { {{&machine_i2c_type}, .p_twi = NRFX_TWI_INSTANCE(0)}, {{&machine_i2c_type}, .p_twi = NRFX_TWI_INSTANCE(1)}, }; @@ -79,7 +79,7 @@ STATIC const machine_hard_i2c_obj_t machine_hard_i2c_obj[] = { void i2c_init0(void) { } -STATIC int i2c_find(mp_obj_t id) { +static int i2c_find(mp_obj_t id) { // given an integer id int i2c_id = mp_obj_get_int(id); if (i2c_id >= 0 && i2c_id < MP_ARRAY_SIZE(machine_hard_i2c_obj)) { @@ -88,7 +88,7 @@ STATIC int i2c_find(mp_obj_t id) { mp_raise_ValueError(MP_ERROR_TEXT("I2C doesn't exist")); } -STATIC void machine_hard_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_hard_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_hard_i2c_obj_t *self = self_in; mp_printf(print, "I2C(%u)", self->p_twi.drv_inst_idx); } @@ -171,7 +171,7 @@ int machine_hard_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, size return transfer_ret; } -STATIC const mp_machine_i2c_p_t machine_hard_i2c_p = { +static const mp_machine_i2c_p_t machine_hard_i2c_p = { .transfer = mp_machine_i2c_transfer_adaptor, .transfer_single = machine_hard_i2c_transfer_single, }; diff --git a/ports/nrf/modules/machine/modmachine.c b/ports/nrf/modules/machine/modmachine.c index 7cdeb78c0a310..9ad8d606a2654 100644 --- a/ports/nrf/modules/machine/modmachine.c +++ b/ports/nrf/modules/machine/modmachine.c @@ -102,7 +102,7 @@ { MP_ROM_QSTR(MP_QSTR_DEBUG_IF_RESET), MP_ROM_INT(PYB_RESET_DIF) }, \ MICROPY_PY_MACHINE_NFC_RESET_ENTRY \ -STATIC uint32_t reset_cause; +static uint32_t reset_cause; void machine_init(void) { uint32_t state = NRF_POWER->RESETREAS; @@ -134,7 +134,7 @@ void machine_init(void) { // machine.info([dump_alloc_table]) // Print out lots of information about the board. -STATIC mp_obj_t machine_info(mp_uint_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_info(mp_uint_t n_args, const mp_obj_t *args) { // to print info about memory { printf("_etext=%p\n", &_etext); @@ -174,14 +174,14 @@ STATIC mp_obj_t machine_info(mp_uint_t n_args, const mp_obj_t *args) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj, 0, 1, machine_info); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj, 0, 1, machine_info); -STATIC mp_obj_t mp_machine_unique_id(void) { +static mp_obj_t mp_machine_unique_id(void) { return mp_const_empty_bytes; } // Resets the board in a manner similar to pushing the external RESET button. -NORETURN STATIC void mp_machine_reset(void) { +NORETURN static void mp_machine_reset(void) { NVIC_SystemReset(); } @@ -191,31 +191,31 @@ NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) { } } -STATIC void mp_machine_idle(void) { +static void mp_machine_idle(void) { MICROPY_EVENT_POLL_HOOK; } -STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) { +static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) { __WFE(); } -NORETURN STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) { +NORETURN static void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) { mp_machine_reset(); } -STATIC mp_int_t mp_machine_reset_cause(void) { +static mp_int_t mp_machine_reset_cause(void) { return reset_cause; } -STATIC mp_obj_t mp_machine_get_freq(void) { +static mp_obj_t mp_machine_get_freq(void) { mp_raise_NotImplementedError(NULL); } -STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) { +static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) { mp_raise_NotImplementedError(NULL); } -STATIC mp_obj_t machine_enable_irq(void) { +static mp_obj_t machine_enable_irq(void) { #ifndef BLUETOOTH_SD __enable_irq(); #else @@ -226,7 +226,7 @@ STATIC mp_obj_t machine_enable_irq(void) { MP_DEFINE_CONST_FUN_OBJ_0(machine_enable_irq_obj, machine_enable_irq); // Resets the board in a manner similar to pushing the external RESET button. -STATIC mp_obj_t machine_disable_irq(void) { +static mp_obj_t machine_disable_irq(void) { #ifndef BLUETOOTH_SD __disable_irq(); #else diff --git a/ports/nrf/modules/machine/pin.c b/ports/nrf/modules/machine/pin.c index 974074fc91261..e72a16eee7c29 100644 --- a/ports/nrf/modules/machine/pin.c +++ b/ports/nrf/modules/machine/pin.c @@ -107,7 +107,7 @@ extern const uint8_t machine_pin_num_of_board_pins; // Pin class variables #if PIN_DEBUG -STATIC bool pin_class_debug; +static bool pin_class_debug; #else #define pin_class_debug (0) #endif @@ -218,7 +218,7 @@ const pin_obj_t *pin_find(mp_obj_t user_obj) { /// \method __str__() /// Return a string describing the pin object. -STATIC void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pin_obj_t *self = self_in; char *pull = "PULL_DISABLED"; @@ -239,12 +239,12 @@ STATIC void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t pull); } -STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *pin, mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args); +static mp_obj_t pin_obj_init_helper(const pin_obj_t *pin, mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args); /// \classmethod \constructor(id, ...) /// Create a new Pin object associated with the id. If additional arguments are given, /// they are used to initialise the pin. See `init`. -STATIC mp_obj_t pin_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +static mp_obj_t pin_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); // Run an argument through the mapper and return the result. @@ -261,7 +261,7 @@ STATIC mp_obj_t pin_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uin } // fast method for getting/setting pin value -STATIC mp_obj_t pin_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +static mp_obj_t pin_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); pin_obj_t *self = self_in; if (n_args == 0) { @@ -274,47 +274,47 @@ STATIC mp_obj_t pin_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, con } } -STATIC mp_obj_t pin_off(mp_obj_t self_in) { +static mp_obj_t pin_off(mp_obj_t self_in) { pin_obj_t *self = self_in; mp_hal_pin_low(self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_off_obj, pin_off); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_off_obj, pin_off); -STATIC mp_obj_t pin_on(mp_obj_t self_in) { +static mp_obj_t pin_on(mp_obj_t self_in) { pin_obj_t *self = self_in; mp_hal_pin_high(self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_on_obj, pin_on); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_on_obj, pin_on); /// \classmethod mapper([fun]) /// Get or set the pin mapper function. -STATIC mp_obj_t pin_mapper(mp_uint_t n_args, const mp_obj_t *args) { +static mp_obj_t pin_mapper(mp_uint_t n_args, const mp_obj_t *args) { if (n_args > 1) { MP_STATE_PORT(pin_class_mapper) = args[1]; return mp_const_none; } return MP_STATE_PORT(pin_class_mapper); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_mapper_fun_obj, 1, 2, pin_mapper); -STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_mapper_obj, (mp_obj_t)&pin_mapper_fun_obj); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_mapper_fun_obj, 1, 2, pin_mapper); +static MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_mapper_obj, (mp_obj_t)&pin_mapper_fun_obj); /// \classmethod dict([dict]) /// Get or set the pin mapper dictionary. -STATIC mp_obj_t pin_map_dict(mp_uint_t n_args, const mp_obj_t *args) { +static mp_obj_t pin_map_dict(mp_uint_t n_args, const mp_obj_t *args) { if (n_args > 1) { MP_STATE_PORT(pin_class_map_dict) = args[1]; return mp_const_none; } return MP_STATE_PORT(pin_class_map_dict); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_map_dict_fun_obj, 1, 2, pin_map_dict); -STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_map_dict_obj, (mp_obj_t)&pin_map_dict_fun_obj); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_map_dict_fun_obj, 1, 2, pin_map_dict); +static MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_map_dict_obj, (mp_obj_t)&pin_map_dict_fun_obj); /// \classmethod af_list() /// Returns an array of alternate functions available for this pin. -STATIC mp_obj_t pin_af_list(mp_obj_t self_in) { +static mp_obj_t pin_af_list(mp_obj_t self_in) { pin_obj_t *self = self_in; mp_obj_t result = mp_obj_new_list(0, NULL); @@ -324,24 +324,24 @@ STATIC mp_obj_t pin_af_list(mp_obj_t self_in) { } return result; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_af_list_obj, pin_af_list); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_list_obj, pin_af_list); #if PIN_DEBUG /// \classmethod debug([state]) /// Get or set the debugging state (`True` or `False` for on or off). -STATIC mp_obj_t pin_debug(mp_uint_t n_args, const mp_obj_t *args) { +static mp_obj_t pin_debug(mp_uint_t n_args, const mp_obj_t *args) { if (n_args > 1) { pin_class_debug = mp_obj_is_true(args[1]); return mp_const_none; } return mp_obj_new_bool(pin_class_debug); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_debug_fun_obj, 1, 2, pin_debug); -STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_debug_obj, (mp_obj_t)&pin_debug_fun_obj); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_debug_fun_obj, 1, 2, pin_debug); +static MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_debug_obj, (mp_obj_t)&pin_debug_fun_obj); #endif // init(mode, pull=None, af=-1, *, value, alt) -STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pin_obj_init_helper(const pin_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT }, { MP_QSTR_pull, MP_ARG_OBJ, {.u_obj = mp_const_none}}, @@ -387,7 +387,7 @@ STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *self, mp_uint_t n_args, con return mp_const_none; } -STATIC mp_obj_t pin_obj_init(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t pin_obj_init(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { return pin_obj_init_helper(args[0], n_args - 1, args + 1, kw_args); } MP_DEFINE_CONST_FUN_OBJ_KW(pin_init_obj, 1, pin_obj_init); @@ -399,40 +399,40 @@ MP_DEFINE_CONST_FUN_OBJ_KW(pin_init_obj, 1, pin_obj_init); /// - With `value` given, set the logic level of the pin. `value` can be /// anything that converts to a boolean. If it converts to `True`, the pin /// is set high, otherwise it is set low. -STATIC mp_obj_t pin_value(mp_uint_t n_args, const mp_obj_t *args) { +static mp_obj_t pin_value(mp_uint_t n_args, const mp_obj_t *args) { return pin_call(args[0], n_args - 1, 0, args + 1); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_value_obj, 1, 2, pin_value); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_value_obj, 1, 2, pin_value); /// \method low() /// Set the pin to a low logic level. -STATIC mp_obj_t pin_low(mp_obj_t self_in) { +static mp_obj_t pin_low(mp_obj_t self_in) { pin_obj_t *self = self_in; mp_hal_pin_low(self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_low_obj, pin_low); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_low_obj, pin_low); /// \method high() /// Set the pin to a high logic level. -STATIC mp_obj_t pin_high(mp_obj_t self_in) { +static mp_obj_t pin_high(mp_obj_t self_in) { pin_obj_t *self = self_in; mp_hal_pin_high(self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_high_obj, pin_high); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_high_obj, pin_high); /// \method name() /// Get the pin name. -STATIC mp_obj_t pin_name(mp_obj_t self_in) { +static mp_obj_t pin_name(mp_obj_t self_in) { pin_obj_t *self = self_in; return MP_OBJ_NEW_QSTR(self->name); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_name_obj, pin_name); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_name_obj, pin_name); /// \method names() /// Returns the cpu and board names for this pin. -STATIC mp_obj_t pin_names(mp_obj_t self_in) { +static mp_obj_t pin_names(mp_obj_t self_in) { pin_obj_t *self = self_in; mp_obj_t result = mp_obj_new_list(0, NULL); mp_obj_list_append(result, MP_OBJ_NEW_QSTR(self->name)); @@ -447,53 +447,53 @@ STATIC mp_obj_t pin_names(mp_obj_t self_in) { } return result; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_names_obj, pin_names); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_names_obj, pin_names); /// \method port() /// Get the pin port. -STATIC mp_obj_t pin_port(mp_obj_t self_in) { +static mp_obj_t pin_port(mp_obj_t self_in) { pin_obj_t *self = self_in; return MP_OBJ_NEW_SMALL_INT(self->pin / 32); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_port_obj, pin_port); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_port_obj, pin_port); /// \method pin() /// Get the pin number. -STATIC mp_obj_t pin_pin(mp_obj_t self_in) { +static mp_obj_t pin_pin(mp_obj_t self_in) { pin_obj_t *self = self_in; return MP_OBJ_NEW_SMALL_INT(self->pin); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_pin_obj, pin_pin); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_pin_obj, pin_pin); /// \method mode() /// Returns the currently configured mode of the pin. The integer returned /// will match one of the allowed constants for the mode argument to the init /// function. -STATIC mp_obj_t pin_mode(mp_obj_t self_in) { +static mp_obj_t pin_mode(mp_obj_t self_in) { return mp_const_none; // TODO: MP_OBJ_NEW_SMALL_INT(pin_get_mode(self_in)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_mode_obj, pin_mode); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_mode_obj, pin_mode); /// \method pull() /// Returns the currently configured pull of the pin. The integer returned /// will match one of the allowed constants for the pull argument to the init /// function. -STATIC mp_obj_t pin_pull(mp_obj_t self_in) { +static mp_obj_t pin_pull(mp_obj_t self_in) { return mp_const_none; // TODO: MP_OBJ_NEW_SMALL_INT(pin_get_pull(self_in)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_pull_obj, pin_pull); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_pull_obj, pin_pull); /// \method af() /// Returns the currently configured alternate-function of the pin. The /// integer returned will match one of the allowed constants for the af /// argument to the init function. -STATIC mp_obj_t pin_af(mp_obj_t self_in) { +static mp_obj_t pin_af(mp_obj_t self_in) { return mp_const_none; // TODO: MP_OBJ_NEW_SMALL_INT(pin_get_af(self_in)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_af_obj, pin_af); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_obj, pin_af); -STATIC void pin_common_irq_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { +static void pin_common_irq_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { mp_obj_t pin_handler = MP_STATE_PORT(pin_irq_handlers)[pin]; mp_obj_t pin_number = MP_OBJ_NEW_SMALL_INT(pin); const pin_obj_t *pin_obj = pin_find(pin_number); @@ -501,7 +501,7 @@ STATIC void pin_common_irq_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t mp_call_function_1(pin_handler, (mp_obj_t)pin_obj); } -STATIC mp_obj_t pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum {ARG_handler, ARG_trigger, ARG_wake}; static const mp_arg_t allowed_args[] = { { MP_QSTR_handler, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = mp_const_none} }, @@ -536,9 +536,9 @@ STATIC mp_obj_t pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar // return the irq object return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pin_irq_obj, 1, pin_irq); +static MP_DEFINE_CONST_FUN_OBJ_KW(pin_irq_obj, 1, pin_irq); -STATIC const mp_rom_map_elem_t pin_locals_dict_table[] = { +static const mp_rom_map_elem_t pin_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pin_init_obj) }, { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&pin_value_obj) }, @@ -594,7 +594,7 @@ STATIC const mp_rom_map_elem_t pin_locals_dict_table[] = { #include "genhdr/pins_af_const.h" }; -STATIC MP_DEFINE_CONST_DICT(pin_locals_dict, pin_locals_dict_table); +static MP_DEFINE_CONST_DICT(pin_locals_dict, pin_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pin_type, @@ -635,42 +635,42 @@ MP_DEFINE_CONST_OBJ_TYPE( /// \method __str__() /// Return a string describing the alternate function. -STATIC void pin_af_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void pin_af_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pin_af_obj_t *self = self_in; mp_printf(print, "Pin.%q", self->name); } /// \method index() /// Return the alternate function index. -STATIC mp_obj_t pin_af_index(mp_obj_t self_in) { +static mp_obj_t pin_af_index(mp_obj_t self_in) { pin_af_obj_t *af = self_in; return MP_OBJ_NEW_SMALL_INT(af->idx); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_af_index_obj, pin_af_index); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_index_obj, pin_af_index); /// \method name() /// Return the name of the alternate function. -STATIC mp_obj_t pin_af_name(mp_obj_t self_in) { +static mp_obj_t pin_af_name(mp_obj_t self_in) { pin_af_obj_t *af = self_in; return MP_OBJ_NEW_QSTR(af->name); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_af_name_obj, pin_af_name); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_name_obj, pin_af_name); /// \method reg() /// Return the base register associated with the peripheral assigned to this /// alternate function. -STATIC mp_obj_t pin_af_reg(mp_obj_t self_in) { +static mp_obj_t pin_af_reg(mp_obj_t self_in) { pin_af_obj_t *af = self_in; return MP_OBJ_NEW_SMALL_INT((mp_uint_t)af->reg); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_af_reg_obj, pin_af_reg); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_reg_obj, pin_af_reg); -STATIC const mp_rom_map_elem_t pin_af_locals_dict_table[] = { +static const mp_rom_map_elem_t pin_af_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_index), MP_ROM_PTR(&pin_af_index_obj) }, { MP_ROM_QSTR(MP_QSTR_name), MP_ROM_PTR(&pin_af_name_obj) }, { MP_ROM_QSTR(MP_QSTR_reg), MP_ROM_PTR(&pin_af_reg_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(pin_af_locals_dict, pin_af_locals_dict_table); +static MP_DEFINE_CONST_DICT(pin_af_locals_dict, pin_af_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pin_af_type, diff --git a/ports/nrf/modules/machine/pwm.c b/ports/nrf/modules/machine/pwm.c index f0c11fa8fc08c..393d1061799dd 100644 --- a/ports/nrf/modules/machine/pwm.c +++ b/ports/nrf/modules/machine/pwm.c @@ -81,7 +81,7 @@ typedef struct _machine_pwm_obj_t { uint8_t channel; } machine_pwm_obj_t; -STATIC const nrfx_pwm_t machine_hard_pwm_instances[] = { +static const nrfx_pwm_t machine_hard_pwm_instances[] = { #if defined(NRF52_SERIES) NRFX_PWM_INSTANCE(0), NRFX_PWM_INSTANCE(1), @@ -92,9 +92,9 @@ STATIC const nrfx_pwm_t machine_hard_pwm_instances[] = { #endif }; -STATIC machine_pwm_config_t hard_configs[MP_ARRAY_SIZE(machine_hard_pwm_instances)]; +static machine_pwm_config_t hard_configs[MP_ARRAY_SIZE(machine_hard_pwm_instances)]; -STATIC const machine_pwm_obj_t machine_hard_pwm_obj[] = { +static const machine_pwm_obj_t machine_hard_pwm_obj[] = { #if defined(NRF52_SERIES) {{&machine_pwm_type}, .p_pwm = &machine_hard_pwm_instances[0], .p_config = &hard_configs[0], 0, 0}, {{&machine_pwm_type}, .p_pwm = &machine_hard_pwm_instances[0], .p_config = &hard_configs[0], 0, 1}, @@ -127,7 +127,7 @@ void pwm_init0(void) { } // Find a free PWM object -STATIC int hard_pwm_find() { +static int hard_pwm_find() { // look for a free module. for (int j = 0; j < MP_ARRAY_SIZE(hard_configs); j++) { if (hard_configs[j].active == FREE) { @@ -137,7 +137,7 @@ STATIC int hard_pwm_find() { mp_raise_ValueError(MP_ERROR_TEXT("all PWM devices in use")); } -STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_pwm_obj_t *self = self_in; static char *duty_suffix[] = { "", "", "_u16", "_ns" }; mp_printf(print, "", @@ -149,7 +149,7 @@ STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_p /******************************************************************************/ /* MicroPython bindings for machine API */ -STATIC void machine_hard_pwm_start(const machine_pwm_obj_t *self); +static void machine_hard_pwm_start(const machine_pwm_obj_t *self); static const mp_arg_t allowed_args[] = { { MP_QSTR_pin, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, @@ -162,7 +162,7 @@ static const mp_arg_t allowed_args[] = { { MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, }; -STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_pin, ARG_freq, ARG_duty, ARG_duty_u16, ARG_duty_ns, ARG_invert, ARG_device, ARG_channel }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; @@ -190,7 +190,7 @@ STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, c } -STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_pin, ARG_freq, ARG_duty, ARG_duty_u16, ARG_duty_ns, ARG_invert, ARG_device, ARG_channel }; // parse args @@ -250,17 +250,17 @@ void pwm_deinit_all(void) { } // Stop the PWM module, but do not release it. -STATIC void mp_machine_pwm_deinit(machine_pwm_obj_t *self) { +static void mp_machine_pwm_deinit(machine_pwm_obj_t *self) { self->p_config->active = STOPPED; nrfx_pwm_stop(self->p_pwm, true); nrfx_pwm_uninit(self->p_pwm); } -STATIC mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) { return MP_OBJ_NEW_SMALL_INT(self->p_config->freq); } -STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { +static void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { uint8_t div = 0; if (freq > (PWM_MAX_BASE_FREQ / 3) || freq <= (PWM_MIN_BASE_FREQ / PWM_MAX_PERIOD)) { @@ -276,7 +276,7 @@ STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { machine_hard_pwm_start(self); } -STATIC mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self) { if (self->p_config->duty_mode[self->channel] == DUTY_PERCENT) { return MP_OBJ_NEW_SMALL_INT(self->p_config->duty[self->channel]); } else if (self->p_config->duty_mode[self->channel] == DUTY_U16) { @@ -286,13 +286,13 @@ STATIC mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self) { } } -STATIC void mp_machine_pwm_duty_set(machine_pwm_obj_t *self, mp_int_t duty) { +static void mp_machine_pwm_duty_set(machine_pwm_obj_t *self, mp_int_t duty) { self->p_config->duty[self->channel] = duty; self->p_config->duty_mode[self->channel] = DUTY_PERCENT; machine_hard_pwm_start(self); } -STATIC mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) { if (self->p_config->duty_mode[self->channel] == DUTY_U16) { return MP_OBJ_NEW_SMALL_INT(self->p_config->duty[self->channel]); } else if (self->p_config->duty_mode[self->channel] == DUTY_PERCENT) { @@ -302,13 +302,13 @@ STATIC mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) { } } -STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty) { +static void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty) { self->p_config->duty[self->channel] = duty; self->p_config->duty_mode[self->channel] = DUTY_U16; machine_hard_pwm_start(self); } -STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { if (self->p_config->duty_mode[self->channel] == DUTY_NS) { return MP_OBJ_NEW_SMALL_INT(self->p_config->duty[self->channel]); } else { @@ -316,7 +316,7 @@ STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { } } -STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty) { +static void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty) { self->p_config->duty[self->channel] = duty; self->p_config->duty_mode[self->channel] = DUTY_NS; machine_hard_pwm_start(self); @@ -324,7 +324,7 @@ STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty) { /* code for hard implementation ***********************************************/ -STATIC void machine_hard_pwm_start(const machine_pwm_obj_t *self) { +static void machine_hard_pwm_start(const machine_pwm_obj_t *self) { nrfx_pwm_config_t config; diff --git a/ports/nrf/modules/machine/rtcounter.c b/ports/nrf/modules/machine/rtcounter.c index d52ca3e9a3366..d85db9b9b7aa1 100644 --- a/ports/nrf/modules/machine/rtcounter.c +++ b/ports/nrf/modules/machine/rtcounter.c @@ -55,7 +55,7 @@ typedef struct _machine_rtc_obj_t { machine_rtc_config_t * config; // pointer to volatile part } machine_rtc_obj_t; -STATIC const nrfx_rtc_t machine_rtc_instances[] = { +static const nrfx_rtc_t machine_rtc_instances[] = { NRFX_RTC_INSTANCE(0), NRFX_RTC_INSTANCE(1), #if defined(NRF52_SERIES) @@ -63,15 +63,15 @@ STATIC const nrfx_rtc_t machine_rtc_instances[] = { #endif }; -STATIC machine_rtc_config_t configs[MP_ARRAY_SIZE(machine_rtc_instances)]; +static machine_rtc_config_t configs[MP_ARRAY_SIZE(machine_rtc_instances)]; -STATIC void interrupt_handler0(nrfx_rtc_int_type_t int_type); -STATIC void interrupt_handler1(nrfx_rtc_int_type_t int_type); +static void interrupt_handler0(nrfx_rtc_int_type_t int_type); +static void interrupt_handler1(nrfx_rtc_int_type_t int_type); #if defined(NRF52_SERIES) -STATIC void interrupt_handler2(nrfx_rtc_int_type_t int_type); +static void interrupt_handler2(nrfx_rtc_int_type_t int_type); #endif -STATIC const machine_rtc_obj_t machine_rtc_obj[] = { +static const machine_rtc_obj_t machine_rtc_obj[] = { {{&machine_rtcounter_type}, .p_rtc = &machine_rtc_instances[0], .handler=interrupt_handler0, .config=&configs[0]}, {{&machine_rtcounter_type}, .p_rtc = &machine_rtc_instances[1], .handler=interrupt_handler1, .config=&configs[1]}, #if defined(NRF52_SERIES) @@ -79,7 +79,7 @@ STATIC const machine_rtc_obj_t machine_rtc_obj[] = { #endif }; -STATIC void interrupt_handler(size_t instance_id) { +static void interrupt_handler(size_t instance_id) { const machine_rtc_obj_t * self = &machine_rtc_obj[instance_id]; machine_rtc_config_t *config = self->config; if (config->callback != NULL) { @@ -93,16 +93,16 @@ STATIC void interrupt_handler(size_t instance_id) { } } -STATIC void interrupt_handler0(nrfx_rtc_int_type_t int_type) { +static void interrupt_handler0(nrfx_rtc_int_type_t int_type) { interrupt_handler(0); } -STATIC void interrupt_handler1(nrfx_rtc_int_type_t int_type) { +static void interrupt_handler1(nrfx_rtc_int_type_t int_type) { interrupt_handler(1); } #if defined(NRF52_SERIES) -STATIC void interrupt_handler2(nrfx_rtc_int_type_t int_type) { +static void interrupt_handler2(nrfx_rtc_int_type_t int_type) { interrupt_handler(2); } #endif @@ -110,7 +110,7 @@ STATIC void interrupt_handler2(nrfx_rtc_int_type_t int_type) { void rtc_init0(void) { } -STATIC int rtc_find(mp_obj_t id) { +static int rtc_find(mp_obj_t id) { // given an integer id int rtc_id = mp_obj_get_int(id); if (rtc_id >= 0 && rtc_id < MP_ARRAY_SIZE(machine_rtc_obj)) { @@ -119,7 +119,7 @@ STATIC int rtc_find(mp_obj_t id) { mp_raise_ValueError(MP_ERROR_TEXT("RTCounter doesn't exist")); } -STATIC void rtc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void rtc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_rtc_obj_t *self = self_in; mp_printf(print, "RTCounter(%u)", self->p_rtc->instance_id); } @@ -138,7 +138,7 @@ const nrfx_rtc_config_t machine_rtc_config = { #endif }; -STATIC mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_id, ARG_period, ARG_mode, ARG_callback }; static const mp_arg_t allowed_args[] = { { MP_QSTR_id, MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_SMALL_INT(-1)} }, @@ -201,54 +201,54 @@ STATIC mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, s /// Start the RTCounter. Timeout occurs after number of periods /// in the configured frequency has been reached. /// -STATIC mp_obj_t machine_rtc_start(mp_obj_t self_in) { +static mp_obj_t machine_rtc_start(mp_obj_t self_in) { machine_rtc_obj_t * self = MP_OBJ_TO_PTR(self_in); nrfx_rtc_enable(self->p_rtc); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_rtc_start_obj, machine_rtc_start); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_rtc_start_obj, machine_rtc_start); /// \method stop() /// Stop the RTCounter. /// -STATIC mp_obj_t machine_rtc_stop(mp_obj_t self_in) { +static mp_obj_t machine_rtc_stop(mp_obj_t self_in) { machine_rtc_obj_t * self = MP_OBJ_TO_PTR(self_in); nrfx_rtc_disable(self->p_rtc); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_rtc_stop_obj, machine_rtc_stop); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_rtc_stop_obj, machine_rtc_stop); /// \method counter() /// Return the current counter value. Wraps around after about 24 days /// with the current prescaler (2^24 / 8 = 2097152 seconds). /// -STATIC mp_obj_t machine_rtc_counter(mp_obj_t self_in) { +static mp_obj_t machine_rtc_counter(mp_obj_t self_in) { machine_rtc_obj_t * self = MP_OBJ_TO_PTR(self_in); uint32_t counter = nrfx_rtc_counter_get(self->p_rtc); return MP_OBJ_NEW_SMALL_INT(counter); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_rtc_counter_obj, machine_rtc_counter); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_rtc_counter_obj, machine_rtc_counter); /// \method deinit() /// Free resources associated with this RTC. /// -STATIC mp_obj_t machine_rtc_deinit(mp_obj_t self_in) { +static mp_obj_t machine_rtc_deinit(mp_obj_t self_in) { machine_rtc_obj_t * self = MP_OBJ_TO_PTR(self_in); nrfx_rtc_uninit(self->p_rtc); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_rtc_deinit_obj, machine_rtc_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_rtc_deinit_obj, machine_rtc_deinit); -STATIC const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_start), MP_ROM_PTR(&machine_rtc_start_obj) }, { MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&machine_rtc_stop_obj) }, { MP_ROM_QSTR(MP_QSTR_counter), MP_ROM_PTR(&machine_rtc_counter_obj) }, @@ -260,7 +260,7 @@ STATIC const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_FREQUENCY), MP_ROM_INT(RTC_FREQUENCY) }, }; -STATIC MP_DEFINE_CONST_DICT(machine_rtc_locals_dict, machine_rtc_locals_dict_table); +static MP_DEFINE_CONST_DICT(machine_rtc_locals_dict, machine_rtc_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( machine_rtcounter_type, diff --git a/ports/nrf/modules/machine/soft_pwm.c b/ports/nrf/modules/machine/soft_pwm.c index c69b5f0bbe022..c61e1f86baa37 100644 --- a/ports/nrf/modules/machine/soft_pwm.c +++ b/ports/nrf/modules/machine/soft_pwm.c @@ -49,7 +49,7 @@ typedef struct _machine_pwm_obj_t { #define SOFT_PWM_BASE_FREQ (1000000) #define DUTY_FULL_SCALE (1024) -STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_pwm_obj_t *self = self_in; static char *duty_suffix[] = { "", "", "_u16", "_ns" }; mp_printf(print, "", @@ -59,9 +59,9 @@ STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_p // MicroPython bindings for machine API -STATIC void machine_soft_pwm_start(machine_pwm_obj_t *self); +static void machine_soft_pwm_start(machine_pwm_obj_t *self); -STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_freq, ARG_duty, ARG_duty_u16, ARG_duty_ns }; static const mp_arg_t allowed_args[] = { { MP_QSTR_freq, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, @@ -91,7 +91,7 @@ STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, c machine_soft_pwm_start(self); } -STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { enum { ARG_pin, ARG_freq, ARG_duty, ARG_duty_u16, ARG_duty_ns, ARG_id }; mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); @@ -117,15 +117,15 @@ STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args return MP_OBJ_FROM_PTR(self); } -STATIC void mp_machine_pwm_deinit(machine_pwm_obj_t *self) { +static void mp_machine_pwm_deinit(machine_pwm_obj_t *self) { pwm_release(self->pwm_pin); } -STATIC mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) { return MP_OBJ_NEW_SMALL_INT(self->freq); } -STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { +static void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { if (freq > (SOFT_PWM_BASE_FREQ / 256)) { mp_raise_ValueError(MP_ERROR_TEXT("frequency out of range")); @@ -134,7 +134,7 @@ STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { machine_soft_pwm_start(self); } -STATIC mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self) { if (self->duty_mode) { return MP_OBJ_NEW_SMALL_INT(self->duty); } else if (self->duty_mode == DUTY_U16) { @@ -144,13 +144,13 @@ STATIC mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self) { } } -STATIC void mp_machine_pwm_duty_set(machine_pwm_obj_t *self, mp_int_t duty) { +static void mp_machine_pwm_duty_set(machine_pwm_obj_t *self, mp_int_t duty) { self->duty = duty; self->duty_mode = DUTY; machine_soft_pwm_start(self); } -STATIC mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) { if (self->duty_mode == DUTY_U16) { return MP_OBJ_NEW_SMALL_INT(self->duty); } else if (self->duty_mode == DUTY) { @@ -160,13 +160,13 @@ STATIC mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) { } } -STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty) { +static void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty) { self->duty = duty; self->duty_mode = DUTY_U16; machine_soft_pwm_start(self); } -STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { if (self->duty_mode == DUTY_NS) { return MP_OBJ_NEW_SMALL_INT(self->duty); } else { @@ -174,7 +174,7 @@ STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { } } -STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty) { +static void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty) { self->duty = duty; self->duty_mode = DUTY_NS; machine_soft_pwm_start(self); @@ -182,7 +182,7 @@ STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty) { /* Interface for the implementation */ -STATIC void machine_soft_pwm_start(machine_pwm_obj_t *self) { +static void machine_soft_pwm_start(machine_pwm_obj_t *self) { // check if ready to go if (self->defer_start == true || self->freq == 0 || self->duty_mode == DUTY_NOT_SET) { diff --git a/ports/nrf/modules/machine/spi.c b/ports/nrf/modules/machine/spi.c index cb09a23491630..4baee39d01dc3 100644 --- a/ports/nrf/modules/machine/spi.c +++ b/ports/nrf/modules/machine/spi.c @@ -103,7 +103,7 @@ typedef struct _machine_hard_spi_obj_t { nrfx_spi_config_t * p_config; // pointer to volatile part } machine_hard_spi_obj_t; -STATIC const nrfx_spi_t machine_spi_instances[] = { +static const nrfx_spi_t machine_spi_instances[] = { NRFX_SPI_INSTANCE(0), NRFX_SPI_INSTANCE(1), #if defined(NRF52_SERIES) @@ -114,9 +114,9 @@ STATIC const nrfx_spi_t machine_spi_instances[] = { #endif // NRF52_SERIES }; -STATIC nrfx_spi_config_t configs[MP_ARRAY_SIZE(machine_spi_instances)]; +static nrfx_spi_config_t configs[MP_ARRAY_SIZE(machine_spi_instances)]; -STATIC const machine_hard_spi_obj_t machine_hard_spi_obj[] = { +static const machine_hard_spi_obj_t machine_hard_spi_obj[] = { {{&machine_spi_type}, .p_spi = &machine_spi_instances[0], .p_config = &configs[0]}, {{&machine_spi_type}, .p_spi = &machine_spi_instances[1], .p_config = &configs[1]}, #if defined(NRF52_SERIES) @@ -130,7 +130,7 @@ STATIC const machine_hard_spi_obj_t machine_hard_spi_obj[] = { void spi_init0(void) { } -STATIC int spi_find(mp_obj_t id) { +static int spi_find(mp_obj_t id) { if (mp_obj_is_str(id)) { // given a string id const char *port = mp_obj_str_get_str(id); @@ -187,14 +187,14 @@ enum { ARG_INIT_firstbit }; -STATIC void machine_hard_spi_init_helper(const machine_hard_spi_obj_t *self, mp_arg_val_t *args); +static void machine_hard_spi_init_helper(const machine_hard_spi_obj_t *self, mp_arg_val_t *args); -STATIC void machine_hard_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_hard_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_hard_spi_obj_t *self = self_in; mp_printf(print, "SPI(%u)", self->p_spi->drv_inst_idx); } -STATIC mp_obj_t machine_hard_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t machine_hard_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_id, MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_SMALL_INT(-1)} }, { MP_QSTR_baudrate, MP_ARG_INT, {.u_int = 1000000} }, @@ -243,7 +243,7 @@ STATIC mp_obj_t machine_hard_spi_make_new(const mp_obj_type_t *type, size_t n_ar return MP_OBJ_FROM_PTR(self); } -STATIC void machine_hard_spi_init_helper(const machine_hard_spi_obj_t *self, mp_arg_val_t *args) { +static void machine_hard_spi_init_helper(const machine_hard_spi_obj_t *self, mp_arg_val_t *args) { int baudrate = args[ARG_INIT_baudrate].u_int; if (baudrate <= 125000) { @@ -304,7 +304,7 @@ STATIC void machine_hard_spi_init_helper(const machine_hard_spi_obj_t *self, mp_ } } -STATIC void machine_hard_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void machine_hard_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_baudrate, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1000000} }, { MP_QSTR_polarity, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, @@ -321,17 +321,17 @@ STATIC void machine_hard_spi_init(mp_obj_base_t *self_in, size_t n_args, const m machine_hard_spi_init_helper(self, args); } -STATIC void machine_hard_spi_deinit(mp_obj_base_t *self_in) { +static void machine_hard_spi_deinit(mp_obj_base_t *self_in) { const machine_hard_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); nrfx_spi_uninit(self->p_spi); } -STATIC void machine_hard_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) { +static void machine_hard_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) { const machine_hard_spi_obj_t *self = (machine_hard_spi_obj_t*)self_in; spi_transfer(self, len, src, dest); } -STATIC const mp_machine_spi_p_t machine_hard_spi_p = { +static const mp_machine_spi_p_t machine_hard_spi_p = { .init = machine_hard_spi_init, .deinit = machine_hard_spi_deinit, .transfer = machine_hard_spi_transfer, diff --git a/ports/nrf/modules/machine/temp.c b/ports/nrf/modules/machine/temp.c index dff15a9d14974..0d206fee47a66 100644 --- a/ports/nrf/modules/machine/temp.c +++ b/ports/nrf/modules/machine/temp.c @@ -50,7 +50,7 @@ typedef struct _machine_temp_obj_t { /// \method __str__() /// Return a string describing the Temp object. -STATIC void machine_temp_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { +static void machine_temp_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { machine_temp_obj_t *self = o; (void)self; @@ -61,7 +61,7 @@ STATIC void machine_temp_print(const mp_print_t *print, mp_obj_t o, mp_print_kin /******************************************************************************/ /* MicroPython bindings for machine API */ -STATIC mp_obj_t machine_temp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t machine_temp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { static const mp_arg_t allowed_args[] = { { }, }; @@ -89,7 +89,7 @@ int32_t temp_read(void) { /// \method read() /// Get temperature. -STATIC mp_obj_t machine_temp_read(mp_uint_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_temp_read(mp_uint_t n_args, const mp_obj_t *args) { #if BLUETOOTH_SD if (BLUETOOTH_STACK_ENABLED() == 1) { @@ -102,15 +102,15 @@ STATIC mp_obj_t machine_temp_read(mp_uint_t n_args, const mp_obj_t *args) { return MP_OBJ_NEW_SMALL_INT(temp_read()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_machine_temp_read_obj, 0, 1, machine_temp_read); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_machine_temp_read_obj, 0, 1, machine_temp_read); -STATIC const mp_rom_map_elem_t machine_temp_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_temp_locals_dict_table[] = { // instance methods // class methods { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_machine_temp_read_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(machine_temp_locals_dict, machine_temp_locals_dict_table); +static MP_DEFINE_CONST_DICT(machine_temp_locals_dict, machine_temp_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( machine_temp_type, diff --git a/ports/nrf/modules/machine/timer.c b/ports/nrf/modules/machine/timer.c index db9f04c2fa7f4..3c2a039b84dfa 100644 --- a/ports/nrf/modules/machine/timer.c +++ b/ports/nrf/modules/machine/timer.c @@ -41,7 +41,7 @@ typedef struct _machine_timer_obj_t { nrfx_timer_t p_instance; } machine_timer_obj_t; -STATIC mp_obj_t machine_timer_callbacks[] = { +static mp_obj_t machine_timer_callbacks[] = { NULL, NULL, NULL, @@ -51,7 +51,7 @@ STATIC mp_obj_t machine_timer_callbacks[] = { #endif }; -STATIC const machine_timer_obj_t machine_timer_obj[] = { +static const machine_timer_obj_t machine_timer_obj[] = { {{&machine_timer_type}, NRFX_TIMER_INSTANCE(0)}, #if MICROPY_PY_MACHINE_SOFT_PWM { }, @@ -71,7 +71,7 @@ void timer_init0(void) { } } -STATIC int timer_find(mp_obj_t id) { +static int timer_find(mp_obj_t id) { // given an integer id int timer_id = mp_obj_get_int(id); if (timer_id >= 0 && timer_id < MP_ARRAY_SIZE(machine_timer_obj)) { @@ -80,12 +80,12 @@ STATIC int timer_find(mp_obj_t id) { mp_raise_ValueError(MP_ERROR_TEXT("Timer doesn't exist")); } -STATIC void timer_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { +static void timer_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { machine_timer_obj_t *self = o; mp_printf(print, "Timer(%u)", self->p_instance.instance_id); } -STATIC void timer_event_handler(nrf_timer_event_t event_type, void *p_context) { +static void timer_event_handler(nrf_timer_event_t event_type, void *p_context) { machine_timer_obj_t *self = p_context; mp_obj_t callback = machine_timer_callbacks[self->p_instance.instance_id]; if (callback != NULL) { @@ -96,7 +96,7 @@ STATIC void timer_event_handler(nrf_timer_event_t event_type, void *p_context) { /******************************************************************************/ /* MicroPython bindings for machine API */ -STATIC mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_id, ARG_period, ARG_mode, ARG_callback }; static const mp_arg_t allowed_args[] = { { MP_QSTR_id, MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_SMALL_INT(-1)} }, @@ -175,52 +175,52 @@ STATIC mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args, /// \method period() /// Return counter value, which is currently in us. /// -STATIC mp_obj_t machine_timer_period(mp_obj_t self_in) { +static mp_obj_t machine_timer_period(mp_obj_t self_in) { machine_timer_obj_t * self = MP_OBJ_TO_PTR(self_in); uint32_t period = nrfx_timer_capture(&self->p_instance, NRF_TIMER_CC_CHANNEL1); return MP_OBJ_NEW_SMALL_INT(period); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_period_obj, machine_timer_period); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_period_obj, machine_timer_period); /// \method start() /// Start the timer. /// -STATIC mp_obj_t machine_timer_start(mp_obj_t self_in) { +static mp_obj_t machine_timer_start(mp_obj_t self_in) { machine_timer_obj_t * self = MP_OBJ_TO_PTR(self_in); nrfx_timer_enable(&self->p_instance); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_start_obj, machine_timer_start); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_start_obj, machine_timer_start); /// \method stop() /// Stop the timer. /// -STATIC mp_obj_t machine_timer_stop(mp_obj_t self_in) { +static mp_obj_t machine_timer_stop(mp_obj_t self_in) { machine_timer_obj_t * self = MP_OBJ_TO_PTR(self_in); nrfx_timer_disable(&self->p_instance); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_stop_obj, machine_timer_stop); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_stop_obj, machine_timer_stop); /// \method deinit() /// Free resources associated with the timer. /// -STATIC mp_obj_t machine_timer_deinit(mp_obj_t self_in) { +static mp_obj_t machine_timer_deinit(mp_obj_t self_in) { machine_timer_obj_t * self = MP_OBJ_TO_PTR(self_in); nrfx_timer_uninit(&self->p_instance); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_deinit_obj, machine_timer_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_deinit_obj, machine_timer_deinit); -STATIC const mp_rom_map_elem_t machine_timer_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_timer_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&machine_timer_period_obj) }, // alias { MP_ROM_QSTR(MP_QSTR_period), MP_ROM_PTR(&machine_timer_period_obj) }, { MP_ROM_QSTR(MP_QSTR_start), MP_ROM_PTR(&machine_timer_start_obj) }, @@ -232,7 +232,7 @@ STATIC const mp_rom_map_elem_t machine_timer_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_PERIODIC), MP_ROM_INT(TIMER_MODE_PERIODIC) }, }; -STATIC MP_DEFINE_CONST_DICT(machine_timer_locals_dict, machine_timer_locals_dict_table); +static MP_DEFINE_CONST_DICT(machine_timer_locals_dict, machine_timer_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( machine_timer_type, diff --git a/ports/nrf/modules/machine/uart.c b/ports/nrf/modules/machine/uart.c index e0b56e831004d..6da797df1f559 100644 --- a/ports/nrf/modules/machine/uart.c +++ b/ports/nrf/modules/machine/uart.c @@ -97,14 +97,14 @@ typedef struct _machine_uart_obj_t { static const nrfx_uart_t instance0 = NRFX_UART_INSTANCE(0); -STATIC machine_uart_obj_t machine_uart_obj[] = { +static machine_uart_obj_t machine_uart_obj[] = { {{&machine_uart_type}, .p_uart = &instance0} }; void uart_init0(void) { } -STATIC int uart_find(mp_obj_t id) { +static int uart_find(mp_obj_t id) { // given an integer id int uart_id = mp_obj_get_int(id); if (uart_id >= 0 && uart_id < MP_ARRAY_SIZE(machine_uart_obj)) { @@ -113,7 +113,7 @@ STATIC int uart_find(mp_obj_t id) { mp_raise_ValueError(MP_ERROR_TEXT("UART doesn't exist")); } -STATIC void uart_event_handler(nrfx_uart_event_t const *p_event, void *p_context) { +static void uart_event_handler(nrfx_uart_event_t const *p_event, void *p_context) { machine_uart_obj_t *self = p_context; if (p_event->type == NRFX_UART_EVT_RX_DONE) { nrfx_uart_rx(self->p_uart, &self->buf.rx_buf[0], 1); @@ -142,7 +142,7 @@ int uart_rx_char(machine_uart_obj_t *self) { return ringbuf_get((ringbuf_t *)&self->buf.rx_ringbuf); } -STATIC nrfx_err_t uart_tx_char(machine_uart_obj_t *self, int c) { +static nrfx_err_t uart_tx_char(machine_uart_obj_t *self, int c) { while (nrfx_uart_tx_in_progress(self->p_uart)) { ; } @@ -172,11 +172,11 @@ void uart_tx_strn_cooked(machine_uart_obj_t *uart_obj, const char *str, uint len // The UART class doesn't have any constants for this port. #define MICROPY_PY_MACHINE_UART_CLASS_CONSTANTS -STATIC void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { mp_printf(print, "UART(0)"); } -STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // Parse args (none supported at this stage). mp_arg_parse_all(n_args, pos_args, kw_args, 0, NULL, NULL); } @@ -186,7 +186,7 @@ STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, // Initialise the UART bus with the given parameters: // - `id`is bus id. // - `baudrate` is the clock rate. -STATIC mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_id, ARG_baudrate, ARG_timeout, ARG_timeout_char }; static const mp_arg_t allowed_args[] = { { MP_QSTR_id, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -266,12 +266,12 @@ STATIC mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_arg return MP_OBJ_FROM_PTR(self); } -STATIC void mp_machine_uart_deinit(machine_uart_obj_t *self) { +static void mp_machine_uart_deinit(machine_uart_obj_t *self) { (void)self; } // Write a single character on the bus. `data` is an integer to write. -STATIC void mp_machine_uart_writechar(machine_uart_obj_t *self, uint16_t data) { +static void mp_machine_uart_writechar(machine_uart_obj_t *self, uint16_t data) { nrfx_err_t err = uart_tx_char(self, data); if (err != NRFX_SUCCESS) { mp_hal_raise(err); @@ -280,21 +280,21 @@ STATIC void mp_machine_uart_writechar(machine_uart_obj_t *self, uint16_t data) { // Receive a single character on the bus. // Return value: The character read, as an integer. Returns -1 on timeout. -STATIC mp_int_t mp_machine_uart_readchar(machine_uart_obj_t *self) { +static mp_int_t mp_machine_uart_readchar(machine_uart_obj_t *self) { return uart_rx_char(self); } // uart.any() -STATIC mp_int_t mp_machine_uart_any(machine_uart_obj_t *self) { +static mp_int_t mp_machine_uart_any(machine_uart_obj_t *self) { return ringbuf_avail((ringbuf_t *)&self->buf.rx_ringbuf); } // uart.txdone() -STATIC bool mp_machine_uart_txdone(machine_uart_obj_t *self) { +static bool mp_machine_uart_txdone(machine_uart_obj_t *self) { return !nrfx_uart_tx_in_progress(self->p_uart); } -STATIC mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { +static mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { machine_uart_obj_t *self = self_in; byte *buf = buf_in; uint32_t t = self->timeout + mp_hal_ticks_ms(); @@ -319,7 +319,7 @@ STATIC mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t return size; } -STATIC mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { +static mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { machine_uart_obj_t *self = self_in; nrfx_err_t err = nrfx_uart_tx(self->p_uart, buf_in, size); @@ -335,7 +335,7 @@ STATIC mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_ } } -STATIC mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { machine_uart_obj_t *self = self_in; (void)self; mp_uint_t ret = 0; diff --git a/ports/nrf/modules/music/modmusic.c b/ports/nrf/modules/music/modmusic.c index a0ae7f7c8e860..2c63497565156 100644 --- a/ports/nrf/modules/music/modmusic.c +++ b/ports/nrf/modules/music/modmusic.c @@ -74,7 +74,7 @@ enum { extern volatile uint32_t ticks; -STATIC uint32_t start_note(const char *note_str, size_t note_len, const pin_obj_t *pin); +static uint32_t start_note(const char *note_str, size_t note_len, const pin_obj_t *pin); void microbit_music_init0(void) { ticker_register_low_pri_callback(microbit_music_tick); @@ -136,7 +136,7 @@ void microbit_music_tick(void) { } } -STATIC void wait_async_music_idle(void) { +static void wait_async_music_idle(void) { // wait for the async music state to become idle while (music_data->async_state != ASYNC_MUSIC_STATE_IDLE) { // allow CTRL-C to stop the music @@ -148,7 +148,7 @@ STATIC void wait_async_music_idle(void) { } } -STATIC uint32_t start_note(const char *note_str, size_t note_len, const pin_obj_t *pin) { +static uint32_t start_note(const char *note_str, size_t note_len, const pin_obj_t *pin) { pwm_set_duty_cycle(pin->pin, 128); // TODO: remove pin setting. // [NOTE](#|b)(octave)(:length) @@ -157,9 +157,9 @@ STATIC uint32_t start_note(const char *note_str, size_t note_len, const pin_obj_ // array of us periods // these are the periods of note4 (the octave ascending from middle c) from A->B then C->G - STATIC uint16_t periods_us[] = {2273, 2025, 3822, 3405, 3034, 2863, 2551}; + static uint16_t periods_us[] = {2273, 2025, 3822, 3405, 3034, 2863, 2551}; // A#, -, C#, D#, -, F#, G# - STATIC uint16_t periods_sharps_us[] = {2145, 0, 3608, 3214, 0, 2703, 2408}; + static uint16_t periods_sharps_us[] = {2145, 0, 3608, 3214, 0, 2703, 2408}; // we'll represent the note as an integer (A=0, G=6) // TODO: validate the note @@ -258,7 +258,7 @@ STATIC uint32_t start_note(const char *note_str, size_t note_len, const pin_obj_ return gap_ms; } -STATIC mp_obj_t microbit_music_reset(void) { +static mp_obj_t microbit_music_reset(void) { music_data->bpm = DEFAULT_BPM; music_data->ticks = DEFAULT_TICKS; music_data->last_octave = DEFAULT_OCTAVE; @@ -268,7 +268,7 @@ STATIC mp_obj_t microbit_music_reset(void) { } MP_DEFINE_CONST_FUN_OBJ_0(microbit_music_reset_obj, microbit_music_reset); -STATIC mp_obj_t microbit_music_get_tempo(void) { +static mp_obj_t microbit_music_get_tempo(void) { mp_obj_t tempo_tuple[2]; tempo_tuple[0] = mp_obj_new_int(music_data->bpm); @@ -278,7 +278,7 @@ STATIC mp_obj_t microbit_music_get_tempo(void) { } MP_DEFINE_CONST_FUN_OBJ_0(microbit_music_get_tempo_obj, microbit_music_get_tempo); -STATIC mp_obj_t microbit_music_stop(mp_uint_t n_args, const mp_obj_t *args) { +static mp_obj_t microbit_music_stop(mp_uint_t n_args, const mp_obj_t *args) { const pin_obj_t *pin; if (n_args == 0) { #ifdef MICROPY_HW_MUSIC_PIN @@ -301,7 +301,7 @@ STATIC mp_obj_t microbit_music_stop(mp_uint_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(microbit_music_stop_obj, 0, 1, microbit_music_stop); -STATIC mp_obj_t microbit_music_play(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t microbit_music_play(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_music, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_pin, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, @@ -370,7 +370,7 @@ STATIC mp_obj_t microbit_music_play(mp_uint_t n_args, const mp_obj_t *pos_args, } MP_DEFINE_CONST_FUN_OBJ_KW(microbit_music_play_obj, 0, microbit_music_play); -STATIC mp_obj_t microbit_music_pitch(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t microbit_music_pitch(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_frequency, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_duration, MP_ARG_INT, {.u_int = -1} }, @@ -433,7 +433,7 @@ STATIC mp_obj_t microbit_music_pitch(mp_uint_t n_args, const mp_obj_t *pos_args, } MP_DEFINE_CONST_FUN_OBJ_KW(microbit_music_pitch_obj, 0, microbit_music_pitch); -STATIC mp_obj_t microbit_music_set_tempo(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t microbit_music_set_tempo(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_ticks, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_bpm, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, @@ -469,7 +469,7 @@ static mp_obj_t music_init(void) { } MP_DEFINE_CONST_FUN_OBJ_0(music___init___obj, music_init); -STATIC const mp_rom_map_elem_t microbit_music_locals_dict_table[] = { +static const mp_rom_map_elem_t microbit_music_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&music___init___obj) }, { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(µbit_music_reset_obj) }, @@ -502,7 +502,7 @@ STATIC const mp_rom_map_elem_t microbit_music_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_POWER_DOWN), MP_ROM_PTR(µbit_music_tune_power_down_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(microbit_music_locals_dict, microbit_music_locals_dict_table); +static MP_DEFINE_CONST_DICT(microbit_music_locals_dict, microbit_music_locals_dict_table); const mp_obj_module_t music_module = { .base = { &mp_type_module }, diff --git a/ports/nrf/modules/nrf/flashbdev.c b/ports/nrf/modules/nrf/flashbdev.c index e92919cac5a22..e490dc53dd677 100644 --- a/ports/nrf/modules/nrf/flashbdev.c +++ b/ports/nrf/modules/nrf/flashbdev.c @@ -74,7 +74,7 @@ mp_obj_t nrf_flashbdev_readblocks(size_t n_args, const mp_obj_t *args) { return MP_OBJ_NEW_SMALL_INT(0); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(nrf_flashbdev_readblocks_obj, 3, 4, nrf_flashbdev_readblocks); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(nrf_flashbdev_readblocks_obj, 3, 4, nrf_flashbdev_readblocks); mp_obj_t nrf_flashbdev_writeblocks(size_t n_args, const mp_obj_t *args) { nrf_flash_obj_t *self = MP_OBJ_TO_PTR(args[0]); @@ -95,7 +95,7 @@ mp_obj_t nrf_flashbdev_writeblocks(size_t n_args, const mp_obj_t *args) { return MP_OBJ_NEW_SMALL_INT(0); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(nrf_flashbdev_writeblocks_obj, 3, 4, nrf_flashbdev_writeblocks); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(nrf_flashbdev_writeblocks_obj, 3, 4, nrf_flashbdev_writeblocks); mp_obj_t nrf_flashbdev_ioctl(mp_obj_t self_in, mp_obj_t op_in, mp_obj_t arg_in) { nrf_flash_obj_t *self = MP_OBJ_TO_PTR(self_in); @@ -137,21 +137,21 @@ mp_obj_t nrf_flashbdev_ioctl(mp_obj_t self_in, mp_obj_t op_in, mp_obj_t arg_in) return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(nrf_flashbdev_ioctl_obj, nrf_flashbdev_ioctl); +static MP_DEFINE_CONST_FUN_OBJ_3(nrf_flashbdev_ioctl_obj, nrf_flashbdev_ioctl); -STATIC const mp_rom_map_elem_t nrf_flashbdev_locals_dict_table[] = { +static const mp_rom_map_elem_t nrf_flashbdev_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&nrf_flashbdev_readblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&nrf_flashbdev_writeblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&nrf_flashbdev_ioctl_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(nrf_flashbdev_locals_dict, nrf_flashbdev_locals_dict_table); +static MP_DEFINE_CONST_DICT(nrf_flashbdev_locals_dict, nrf_flashbdev_locals_dict_table); -STATIC void nrf_flashbdev_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void nrf_flashbdev_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { nrf_flash_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "Flash(start=0x%08x, len=%u)", self->start, self->len); } -STATIC mp_obj_t nrf_flashbdev_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t nrf_flashbdev_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // Parse arguments enum { ARG_start, ARG_len }; static const mp_arg_t allowed_args[] = { diff --git a/ports/nrf/modules/nrf/modnrf.c b/ports/nrf/modules/nrf/modnrf.c index 6533fa121e506..ce75635c767e4 100644 --- a/ports/nrf/modules/nrf/modnrf.c +++ b/ports/nrf/modules/nrf/modnrf.c @@ -45,7 +45,7 @@ extern uint32_t _unused_flash_start; extern uint32_t _unused_flash_len; #if NRF_POWER_HAS_DCDCEN -STATIC mp_obj_t dcdc(size_t n_args, const mp_obj_t *args) { +static mp_obj_t dcdc(size_t n_args, const mp_obj_t *args) { if (n_args > 0) { bool dcdc_state = mp_obj_is_true(args[0]); #if BLUETOOTH_SD @@ -59,14 +59,14 @@ STATIC mp_obj_t dcdc(size_t n_args, const mp_obj_t *args) { } return mp_obj_new_bool(nrf_power_dcdcen_get(NRF_POWER)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dcdc_obj, 0, 1, dcdc); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dcdc_obj, 0, 1, dcdc); #endif #if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE mp_obj_t nrf_modnrf_freeflash_start_aligned(void) { return mp_obj_new_int_from_uint(FLASH_PAGE_ALIGN_UP((uint32_t)&_unused_flash_start)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(nrf_modnrf_freeflash_start_aligned_obj, nrf_modnrf_freeflash_start_aligned); +static MP_DEFINE_CONST_FUN_OBJ_0(nrf_modnrf_freeflash_start_aligned_obj, nrf_modnrf_freeflash_start_aligned); mp_obj_t nrf_modnrf_freeflash_length_aligned(void) { uint32_t align_diff = FLASH_PAGE_ALIGN_UP((uint32_t)&_unused_flash_start) - ((uint32_t)&_unused_flash_start); @@ -74,10 +74,10 @@ mp_obj_t nrf_modnrf_freeflash_length_aligned(void) { uint32_t len_page_aligned = (temp_len / FLASH_PAGESIZE) * FLASH_PAGESIZE; return mp_obj_new_int_from_uint(len_page_aligned); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(nrf_modnrf_freeflash_length_aligned_obj, nrf_modnrf_freeflash_length_aligned); +static MP_DEFINE_CONST_FUN_OBJ_0(nrf_modnrf_freeflash_length_aligned_obj, nrf_modnrf_freeflash_length_aligned); #endif -STATIC const mp_rom_map_elem_t nrf_module_globals_table[] = { +static const mp_rom_map_elem_t nrf_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_nrf) }, #if NRF_POWER_HAS_DCDCEN { MP_ROM_QSTR(MP_QSTR_dcdc), MP_ROM_PTR(&dcdc_obj) }, @@ -88,7 +88,7 @@ STATIC const mp_rom_map_elem_t nrf_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_unused_flash_length), MP_ROM_PTR(&nrf_modnrf_freeflash_length_aligned_obj) }, #endif }; -STATIC MP_DEFINE_CONST_DICT(nrf_module_globals, nrf_module_globals_table); +static MP_DEFINE_CONST_DICT(nrf_module_globals, nrf_module_globals_table); const mp_obj_module_t nrf_module = { .base = { &mp_type_module }, diff --git a/ports/nrf/modules/os/microbitfs.c b/ports/nrf/modules/os/microbitfs.c index bc007c161f340..f549e6f32edfe 100644 --- a/ports/nrf/modules/os/microbitfs.c +++ b/ports/nrf/modules/os/microbitfs.c @@ -121,13 +121,13 @@ extern const mp_obj_type_t os_mbfs_fileio_type; extern const mp_obj_type_t os_mbfs_textio_type; // Page indexes count down from the end of ROM. -STATIC uint8_t first_page_index; -STATIC uint8_t last_page_index; +static uint8_t first_page_index; +static uint8_t last_page_index; // The number of usable chunks in the file system. -STATIC uint8_t chunks_in_file_system; +static uint8_t chunks_in_file_system; // Index of chunk to start searches. This is randomised to even out wear. -STATIC uint8_t start_index; -STATIC file_chunk *file_system_chunks; +static uint8_t start_index; +static file_chunk *file_system_chunks; // Defined by the linker extern byte _fs_start[]; @@ -136,25 +136,25 @@ extern byte _fs_end[]; STATIC_ASSERT((sizeof(file_chunk) == CHUNK_SIZE)); // From micro:bit memory.h -STATIC inline byte *rounddown(byte *addr, uint32_t align) { +static inline byte *rounddown(byte *addr, uint32_t align) { return (byte*)(((uint32_t)addr)&(-align)); } // From micro:bit memory.h -STATIC inline byte *roundup(byte *addr, uint32_t align) { +static inline byte *roundup(byte *addr, uint32_t align) { return (byte*)((((uint32_t)addr)+align-1)&(-align)); } -STATIC inline void *first_page(void) { +static inline void *first_page(void) { return _fs_end - FLASH_PAGESIZE * first_page_index; } -STATIC inline void *last_page(void) { +static inline void *last_page(void) { return _fs_end - FLASH_PAGESIZE * last_page_index; } -STATIC void init_limits(void) { +static void init_limits(void) { // First determine where to end byte *end = _fs_end; end = rounddown(end, FLASH_PAGESIZE)-FLASH_PAGESIZE; @@ -169,7 +169,7 @@ STATIC void init_limits(void) { chunks_in_file_system = (end-start)>>MBFS_LOG_CHUNK_SIZE; } -STATIC void randomise_start_index(void) { +static void randomise_start_index(void) { start_index = rng_generate_random_word() % chunks_in_file_system + 1; } @@ -187,7 +187,7 @@ void microbit_filesystem_init(void) { } } -STATIC void copy_page(void *dest, void *src) { +static void copy_page(void *dest, void *src) { DEBUG(("FILE DEBUG: Copying page from %lx to %lx.\r\n", (uint32_t)src, (uint32_t)dest)); flash_page_erase((uint32_t)dest); file_chunk *src_chunk = src; @@ -210,7 +210,7 @@ STATIC void copy_page(void *dest, void *src) { // Then all the pages are copied, one by one, into the adjacent newly unused page. // Finally, the persistent data is saved back to the opposite end of the filesystem from whence it came. // -STATIC void filesystem_sweep(void) { +static void filesystem_sweep(void) { persistent_config_t config; uint8_t *page; uint8_t *end_page; @@ -240,11 +240,11 @@ STATIC void filesystem_sweep(void) { } -STATIC inline byte *seek_address(file_descriptor_obj *self) { +static inline byte *seek_address(file_descriptor_obj *self) { return (byte*)&(file_system_chunks[self->seek_chunk].data[self->seek_offset]); } -STATIC uint8_t microbit_find_file(const char *name, int name_len) { +static uint8_t microbit_find_file(const char *name, int name_len) { for (uint8_t index = 1; index <= chunks_in_file_system; index++) { const file_chunk *p = &file_system_chunks[index]; if (p->marker != FILE_START) @@ -268,7 +268,7 @@ STATIC uint8_t microbit_find_file(const char *name, int name_len) { // 3a. Sweep the filesystem and restart. // 3b. Otherwise, fail and return FILE_NOT_FOUND. // -STATIC uint8_t find_chunk_and_erase(void) { +static uint8_t find_chunk_and_erase(void) { // Start search at a random chunk to spread the wear more evenly. // Search for unused chunk uint8_t index = start_index; @@ -316,13 +316,13 @@ STATIC uint8_t find_chunk_and_erase(void) { return find_chunk_and_erase(); } -STATIC mp_obj_t microbit_file_name(file_descriptor_obj *fd) { +static mp_obj_t microbit_file_name(file_descriptor_obj *fd) { return mp_obj_new_str(&(file_system_chunks[fd->start_chunk].header.filename[0]), file_system_chunks[fd->start_chunk].header.name_len); } -STATIC file_descriptor_obj *microbit_file_descriptor_new(uint8_t start_chunk, bool write, bool binary); +static file_descriptor_obj *microbit_file_descriptor_new(uint8_t start_chunk, bool write, bool binary); -STATIC void clear_file(uint8_t chunk) { +static void clear_file(uint8_t chunk) { do { flash_write_byte((uint32_t)&(file_system_chunks[chunk].marker), FREED_CHUNK); DEBUG(("FILE DEBUG: Freeing chunk %d.\n", chunk)); @@ -330,7 +330,7 @@ STATIC void clear_file(uint8_t chunk) { } while (chunk <= chunks_in_file_system); } -STATIC file_descriptor_obj *microbit_file_open(const char *name, size_t name_len, bool write, bool binary) { +static file_descriptor_obj *microbit_file_open(const char *name, size_t name_len, bool write, bool binary) { if (name_len > MAX_FILENAME_LENGTH) { return NULL; } @@ -355,7 +355,7 @@ STATIC file_descriptor_obj *microbit_file_open(const char *name, size_t name_len return microbit_file_descriptor_new(index, write, binary); } -STATIC file_descriptor_obj *microbit_file_descriptor_new(uint8_t start_chunk, bool write, bool binary) { +static file_descriptor_obj *microbit_file_descriptor_new(uint8_t start_chunk, bool write, bool binary) { file_descriptor_obj *res = mp_obj_malloc(file_descriptor_obj, binary ? &os_mbfs_fileio_type : &os_mbfs_textio_type); res->start_chunk = start_chunk; res->seek_chunk = start_chunk; @@ -366,7 +366,7 @@ STATIC file_descriptor_obj *microbit_file_descriptor_new(uint8_t start_chunk, bo return res; } -STATIC mp_obj_t microbit_remove(mp_obj_t filename) { +static mp_obj_t microbit_remove(mp_obj_t filename) { size_t name_len; const char *name = mp_obj_str_get_data(filename, &name_len); mp_uint_t index = microbit_find_file(name, name_len); @@ -377,13 +377,13 @@ STATIC mp_obj_t microbit_remove(mp_obj_t filename) { return mp_const_none; } -STATIC void check_file_open(file_descriptor_obj *self) { +static void check_file_open(file_descriptor_obj *self) { if (!self->open) { mp_raise_ValueError(MP_ERROR_TEXT("I/O operation on closed file")); } } -STATIC int advance(file_descriptor_obj *self, uint32_t n, bool write) { +static int advance(file_descriptor_obj *self, uint32_t n, bool write) { DEBUG(("FILE DEBUG: Advancing from chunk %d, offset %d.\r\n", self->seek_chunk, self->seek_offset)); self->seek_offset += n; if (self->seek_offset == DATA_PER_CHUNK) { @@ -405,7 +405,7 @@ STATIC int advance(file_descriptor_obj *self, uint32_t n, bool write) { return 0; } -STATIC mp_uint_t microbit_file_read(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t microbit_file_read(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode) { file_descriptor_obj *self = (file_descriptor_obj *)obj; check_file_open(self); if (self->writable || file_system_chunks[self->start_chunk].marker == FREED_CHUNK) { @@ -435,7 +435,7 @@ STATIC mp_uint_t microbit_file_read(mp_obj_t obj, void *buf, mp_uint_t size, int return bytes_read; } -STATIC mp_uint_t microbit_file_write(mp_obj_t obj, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t microbit_file_write(mp_obj_t obj, const void *buf, mp_uint_t size, int *errcode) { file_descriptor_obj *self = (file_descriptor_obj *)obj; check_file_open(self); if (!self->writable || file_system_chunks[self->start_chunk].marker == FREED_CHUNK) { @@ -458,14 +458,14 @@ STATIC mp_uint_t microbit_file_write(mp_obj_t obj, const void *buf, mp_uint_t si return size; } -STATIC void microbit_file_close(file_descriptor_obj *fd) { +static void microbit_file_close(file_descriptor_obj *fd) { if (fd->writable) { flash_write_byte((uint32_t)&(file_system_chunks[fd->start_chunk].header.end_offset), fd->seek_offset); } fd->open = false; } -STATIC mp_obj_t microbit_file_list(void) { +static mp_obj_t microbit_file_list(void) { mp_obj_t res = mp_obj_new_list(0, NULL); for (uint8_t index = 1; index <= chunks_in_file_system; index++) { if (file_system_chunks[index].marker == FILE_START) { @@ -476,7 +476,7 @@ STATIC mp_obj_t microbit_file_list(void) { return res; } -STATIC mp_obj_t microbit_file_size(mp_obj_t filename) { +static mp_obj_t microbit_file_size(mp_obj_t filename) { size_t name_len; const char *name = mp_obj_str_get_data(filename, &name_len); uint8_t chunk = microbit_find_file(name, name_len); @@ -495,7 +495,7 @@ STATIC mp_obj_t microbit_file_size(mp_obj_t filename) { return mp_obj_new_int(len); } -STATIC mp_uint_t file_read_byte(file_descriptor_obj *fd) { +static mp_uint_t file_read_byte(file_descriptor_obj *fd) { if (file_system_chunks[fd->seek_chunk].next_chunk == UNUSED_CHUNK) { uint8_t end_offset = file_system_chunks[fd->start_chunk].header.end_offset; if (end_offset == UNUSED_CHUNK || fd->seek_offset == end_offset) { @@ -530,29 +530,29 @@ mp_import_stat_t os_mbfs_import_stat(const char *path) { } } -STATIC mp_obj_t os_mbfs_file_name(mp_obj_t self) { +static mp_obj_t os_mbfs_file_name(mp_obj_t self) { file_descriptor_obj *fd = (file_descriptor_obj*)self; return microbit_file_name(fd); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_file_name_obj, os_mbfs_file_name); +static MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_file_name_obj, os_mbfs_file_name); -STATIC mp_obj_t os_mbfs_file_close(mp_obj_t self) { +static mp_obj_t os_mbfs_file_close(mp_obj_t self) { file_descriptor_obj *fd = (file_descriptor_obj*)self; microbit_file_close(fd); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_file_close_obj, os_mbfs_file_close); +static MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_file_close_obj, os_mbfs_file_close); -STATIC mp_obj_t os_mbfs_remove(mp_obj_t name) { +static mp_obj_t os_mbfs_remove(mp_obj_t name) { return microbit_remove(name); } MP_DEFINE_CONST_FUN_OBJ_1(os_mbfs_remove_obj, os_mbfs_remove); -STATIC mp_obj_t os_mbfs_file___exit__(size_t n_args, const mp_obj_t *args) { +static mp_obj_t os_mbfs_file___exit__(size_t n_args, const mp_obj_t *args) { (void)n_args; return os_mbfs_file_close(args[0]); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(os_mbfs_file___exit___obj, 4, 4, os_mbfs_file___exit__); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(os_mbfs_file___exit___obj, 4, 4, os_mbfs_file___exit__); typedef struct { mp_obj_base_t base; @@ -560,7 +560,7 @@ typedef struct { uint8_t index; } os_mbfs_ilistdir_it_t; -STATIC mp_obj_t os_mbfs_ilistdir_it_iternext(mp_obj_t self_in) { +static mp_obj_t os_mbfs_ilistdir_it_iternext(mp_obj_t self_in) { os_mbfs_ilistdir_it_t *self = MP_OBJ_TO_PTR(self_in); // Read until the next FILE_START chunk. @@ -585,7 +585,7 @@ STATIC mp_obj_t os_mbfs_ilistdir_it_iternext(mp_obj_t self_in) { return MP_OBJ_STOP_ITERATION; } -STATIC mp_obj_t os_mbfs_ilistdir(void) { +static mp_obj_t os_mbfs_ilistdir(void) { os_mbfs_ilistdir_it_t *iter = mp_obj_malloc(os_mbfs_ilistdir_it_t, &mp_type_polymorph_iter); iter->iternext = os_mbfs_ilistdir_it_iternext; iter->index = 1; @@ -596,12 +596,12 @@ MP_DEFINE_CONST_FUN_OBJ_0(os_mbfs_ilistdir_obj, os_mbfs_ilistdir); MP_DEFINE_CONST_FUN_OBJ_0(os_mbfs_listdir_obj, microbit_file_list); -STATIC mp_obj_t microbit_file_writable(mp_obj_t self) { +static mp_obj_t microbit_file_writable(mp_obj_t self) { return mp_obj_new_bool(((file_descriptor_obj *)self)->writable); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(microbit_file_writable_obj, microbit_file_writable); +static MP_DEFINE_CONST_FUN_OBJ_1(microbit_file_writable_obj, microbit_file_writable); -STATIC const mp_map_elem_t os_mbfs_file_locals_dict_table[] = { +static const mp_map_elem_t os_mbfs_file_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&os_mbfs_file_close_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_name), (mp_obj_t)&os_mbfs_file_name_obj }, { MP_ROM_QSTR(MP_QSTR___enter__), (mp_obj_t)&mp_identity_obj }, @@ -613,10 +613,10 @@ STATIC const mp_map_elem_t os_mbfs_file_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_readline), (mp_obj_t)&mp_stream_unbuffered_readline_obj}, { MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj}, }; -STATIC MP_DEFINE_CONST_DICT(os_mbfs_file_locals_dict, os_mbfs_file_locals_dict_table); +static MP_DEFINE_CONST_DICT(os_mbfs_file_locals_dict, os_mbfs_file_locals_dict_table); -STATIC const mp_stream_p_t textio_stream_p = { +static const mp_stream_p_t textio_stream_p = { .read = microbit_file_read, .write = microbit_file_write, .is_text = true, @@ -631,7 +631,7 @@ MP_DEFINE_CONST_OBJ_TYPE( ); -STATIC const mp_stream_p_t fileio_stream_p = { +static const mp_stream_p_t fileio_stream_p = { .read = microbit_file_read, .write = microbit_file_write, }; @@ -679,7 +679,7 @@ mp_obj_t os_mbfs_open(size_t n_args, const mp_obj_t *args) { mp_raise_ValueError(MP_ERROR_TEXT("illegal mode")); } -STATIC mp_obj_t os_mbfs_stat(mp_obj_t filename) { +static mp_obj_t os_mbfs_stat(mp_obj_t filename) { mp_obj_t file_size = microbit_file_size(filename); mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(10, NULL)); diff --git a/ports/nrf/modules/os/modos.c b/ports/nrf/modules/os/modos.c index 31bf1b2920ef1..f000e1eeb6457 100644 --- a/ports/nrf/modules/os/modos.c +++ b/ports/nrf/modules/os/modos.c @@ -33,7 +33,7 @@ #if MICROPY_PY_OS_URANDOM // Return a bytes object with n random bytes, generated by the hardware random number generator. -STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { +static mp_obj_t mp_os_urandom(mp_obj_t num) { mp_int_t n = mp_obj_get_int(num); vstr_t vstr; vstr_init_len(&vstr, n); @@ -42,7 +42,7 @@ STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { } return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); #endif #if MICROPY_PY_OS_DUPTERM diff --git a/ports/nrf/modules/ubluepy/modubluepy.c b/ports/nrf/modules/ubluepy/modubluepy.c index fd42c4940bb75..e84c2ebd6d56a 100644 --- a/ports/nrf/modules/ubluepy/modubluepy.c +++ b/ports/nrf/modules/ubluepy/modubluepy.c @@ -37,7 +37,7 @@ extern const mp_obj_type_t ubluepy_constants_type; extern const mp_obj_type_t ubluepy_scanner_type; extern const mp_obj_type_t ubluepy_scan_entry_type; -STATIC const mp_rom_map_elem_t mp_module_ubluepy_globals_table[] = { +static const mp_rom_map_elem_t mp_module_ubluepy_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ubluepy) }, #if MICROPY_PY_UBLUEPY_PERIPHERAL { MP_ROM_QSTR(MP_QSTR_Peripheral), MP_ROM_PTR(&ubluepy_peripheral_type) }, @@ -60,7 +60,7 @@ STATIC const mp_rom_map_elem_t mp_module_ubluepy_globals_table[] = { }; -STATIC MP_DEFINE_CONST_DICT(mp_module_ubluepy_globals, mp_module_ubluepy_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_ubluepy_globals, mp_module_ubluepy_globals_table); const mp_obj_module_t mp_module_ubluepy = { .base = { &mp_type_module }, diff --git a/ports/nrf/modules/ubluepy/ubluepy_characteristic.c b/ports/nrf/modules/ubluepy/ubluepy_characteristic.c index 7b9e3af6a3174..074cf0396e3a6 100644 --- a/ports/nrf/modules/ubluepy/ubluepy_characteristic.c +++ b/ports/nrf/modules/ubluepy/ubluepy_characteristic.c @@ -32,14 +32,14 @@ #include "modubluepy.h" #include "ble_drv.h" -STATIC void ubluepy_characteristic_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { +static void ubluepy_characteristic_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { ubluepy_characteristic_obj_t * self = (ubluepy_characteristic_obj_t *)o; mp_printf(print, "Characteristic(handle: 0x" HEX2_FMT ", conn_handle: " HEX2_FMT ")", self->handle, self->p_service->p_periph->conn_handle); } -STATIC mp_obj_t ubluepy_characteristic_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t ubluepy_characteristic_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_uuid, MP_ARG_REQUIRED| MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_props, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = UBLUEPY_PROP_READ | UBLUEPY_PROP_WRITE} }, @@ -90,7 +90,7 @@ void char_data_callback(mp_obj_t self_in, uint16_t length, uint8_t * p_data) { /// \method read() /// Read Characteristic value. /// -STATIC mp_obj_t char_read(mp_obj_t self_in) { +static mp_obj_t char_read(mp_obj_t self_in) { ubluepy_characteristic_obj_t * self = MP_OBJ_TO_PTR(self_in); #if MICROPY_PY_UBLUEPY_CENTRAL @@ -107,12 +107,12 @@ STATIC mp_obj_t char_read(mp_obj_t self_in) { return mp_const_none; #endif } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_characteristic_read_obj, char_read); +static MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_characteristic_read_obj, char_read); /// \method write(data, [with_response=False]) /// Write Characteristic value. /// -STATIC mp_obj_t char_write(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t char_write(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { ubluepy_characteristic_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); mp_obj_t data = pos_args[1]; @@ -155,28 +155,28 @@ STATIC mp_obj_t char_write(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ubluepy_characteristic_write_obj, 2, char_write); +static MP_DEFINE_CONST_FUN_OBJ_KW(ubluepy_characteristic_write_obj, 2, char_write); /// \method properties() /// Read Characteristic value properties. /// -STATIC mp_obj_t char_properties(mp_obj_t self_in) { +static mp_obj_t char_properties(mp_obj_t self_in) { ubluepy_characteristic_obj_t * self = MP_OBJ_TO_PTR(self_in); return MP_OBJ_NEW_SMALL_INT(self->props); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_characteristic_get_properties_obj, char_properties); +static MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_characteristic_get_properties_obj, char_properties); /// \method uuid() /// Get UUID instance of the characteristic. /// -STATIC mp_obj_t char_uuid(mp_obj_t self_in) { +static mp_obj_t char_uuid(mp_obj_t self_in) { ubluepy_characteristic_obj_t * self = MP_OBJ_TO_PTR(self_in); return MP_OBJ_FROM_PTR(self->p_uuid); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_characteristic_get_uuid_obj, char_uuid); +static MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_characteristic_get_uuid_obj, char_uuid); -STATIC const mp_rom_map_elem_t ubluepy_characteristic_locals_dict_table[] = { +static const mp_rom_map_elem_t ubluepy_characteristic_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&ubluepy_characteristic_read_obj) }, { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&ubluepy_characteristic_write_obj) }, #if 0 @@ -207,7 +207,7 @@ STATIC const mp_rom_map_elem_t ubluepy_characteristic_locals_dict_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(ubluepy_characteristic_locals_dict, ubluepy_characteristic_locals_dict_table); +static MP_DEFINE_CONST_DICT(ubluepy_characteristic_locals_dict, ubluepy_characteristic_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( ubluepy_characteristic_type, diff --git a/ports/nrf/modules/ubluepy/ubluepy_constants.c b/ports/nrf/modules/ubluepy/ubluepy_constants.c index cad9adbb03256..d102c41da3b47 100644 --- a/ports/nrf/modules/ubluepy/ubluepy_constants.c +++ b/ports/nrf/modules/ubluepy/ubluepy_constants.c @@ -31,7 +31,7 @@ #include "modubluepy.h" -STATIC const mp_rom_map_elem_t ubluepy_constants_ad_types_locals_dict_table[] = { +static const mp_rom_map_elem_t ubluepy_constants_ad_types_locals_dict_table[] = { // GAP AD Types { MP_ROM_QSTR(MP_QSTR_AD_TYPE_FLAGS), MP_ROM_INT(0x01) }, { MP_ROM_QSTR(MP_QSTR_AD_TYPE_16BIT_SERVICE_UUID_MORE_AVAILABLE), MP_ROM_INT(0x02) }, @@ -67,7 +67,7 @@ STATIC const mp_rom_map_elem_t ubluepy_constants_ad_types_locals_dict_table[] = { MP_ROM_QSTR(MP_QSTR_AD_TYPE_MANUFACTURER_SPECIFIC_DATA), MP_ROM_INT(0xFF) }, }; -STATIC MP_DEFINE_CONST_DICT(ubluepy_constants_ad_types_locals_dict, ubluepy_constants_ad_types_locals_dict_table); +static MP_DEFINE_CONST_DICT(ubluepy_constants_ad_types_locals_dict, ubluepy_constants_ad_types_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( ubluepy_constants_ad_types_type, @@ -76,7 +76,7 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &ubluepy_constants_ad_types_locals_dict ); -STATIC const mp_rom_map_elem_t ubluepy_constants_locals_dict_table[] = { +static const mp_rom_map_elem_t ubluepy_constants_locals_dict_table[] = { // GAP events { MP_ROM_QSTR(MP_QSTR_EVT_GAP_CONNECTED), MP_ROM_INT(16) }, { MP_ROM_QSTR(MP_QSTR_EVT_GAP_DISCONNECTED), MP_ROM_INT(17) }, @@ -89,7 +89,7 @@ STATIC const mp_rom_map_elem_t ubluepy_constants_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_ad_types), MP_ROM_PTR(&ubluepy_constants_ad_types_type) }, }; -STATIC MP_DEFINE_CONST_DICT(ubluepy_constants_locals_dict, ubluepy_constants_locals_dict_table); +static MP_DEFINE_CONST_DICT(ubluepy_constants_locals_dict, ubluepy_constants_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( ubluepy_constants_type, diff --git a/ports/nrf/modules/ubluepy/ubluepy_delegate.c b/ports/nrf/modules/ubluepy/ubluepy_delegate.c index 43720b4186b0a..3aa06d83bf840 100644 --- a/ports/nrf/modules/ubluepy/ubluepy_delegate.c +++ b/ports/nrf/modules/ubluepy/ubluepy_delegate.c @@ -31,13 +31,13 @@ #include "modubluepy.h" -STATIC void ubluepy_delegate_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { +static void ubluepy_delegate_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { ubluepy_delegate_obj_t * self = (ubluepy_delegate_obj_t *)o; (void)self; mp_printf(print, "DefaultDelegate()"); } -STATIC mp_obj_t ubluepy_delegate_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t ubluepy_delegate_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { ubluepy_delegate_obj_t *s = mp_obj_malloc(ubluepy_delegate_obj_t, type); return MP_OBJ_FROM_PTR(s); @@ -46,28 +46,28 @@ STATIC mp_obj_t ubluepy_delegate_make_new(const mp_obj_type_t *type, size_t n_ar /// \method handleConnection() /// Handle connection events. /// -STATIC mp_obj_t delegate_handle_conn(mp_obj_t self_in) { +static mp_obj_t delegate_handle_conn(mp_obj_t self_in) { ubluepy_delegate_obj_t *self = MP_OBJ_TO_PTR(self_in); (void)self; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_delegate_handle_conn_obj, delegate_handle_conn); +static MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_delegate_handle_conn_obj, delegate_handle_conn); /// \method handleNotification() /// Handle notification events. /// -STATIC mp_obj_t delegate_handle_notif(mp_obj_t self_in) { +static mp_obj_t delegate_handle_notif(mp_obj_t self_in) { ubluepy_delegate_obj_t *self = MP_OBJ_TO_PTR(self_in); (void)self; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_delegate_handle_notif_obj, delegate_handle_notif); +static MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_delegate_handle_notif_obj, delegate_handle_notif); -STATIC const mp_rom_map_elem_t ubluepy_delegate_locals_dict_table[] = { +static const mp_rom_map_elem_t ubluepy_delegate_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_handleConnection), MP_ROM_PTR(&ubluepy_delegate_handle_conn_obj) }, { MP_ROM_QSTR(MP_QSTR_handleNotification), MP_ROM_PTR(&ubluepy_delegate_handle_notif_obj) }, #if 0 @@ -75,7 +75,7 @@ STATIC const mp_rom_map_elem_t ubluepy_delegate_locals_dict_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(ubluepy_delegate_locals_dict, ubluepy_delegate_locals_dict_table); +static MP_DEFINE_CONST_DICT(ubluepy_delegate_locals_dict, ubluepy_delegate_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( ubluepy_delegate_type, diff --git a/ports/nrf/modules/ubluepy/ubluepy_descriptor.c b/ports/nrf/modules/ubluepy/ubluepy_descriptor.c index 062b4210941f7..d2a256d5c32bc 100644 --- a/ports/nrf/modules/ubluepy/ubluepy_descriptor.c +++ b/ports/nrf/modules/ubluepy/ubluepy_descriptor.c @@ -34,14 +34,14 @@ #include "modubluepy.h" #include "ble_drv.h" -STATIC void ubluepy_descriptor_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { +static void ubluepy_descriptor_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { ubluepy_descriptor_obj_t * self = (ubluepy_descriptor_obj_t *)o; mp_printf(print, "Descriptor(uuid: 0x" HEX2_FMT HEX2_FMT ")", self->p_uuid->value[1], self->p_uuid->value[0]); } -STATIC mp_obj_t ubluepy_descriptor_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t ubluepy_descriptor_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_NEW_UUID }; @@ -62,13 +62,13 @@ STATIC mp_obj_t ubluepy_descriptor_make_new(const mp_obj_type_t *type, size_t n_ return MP_OBJ_FROM_PTR(s); } -STATIC const mp_rom_map_elem_t ubluepy_descriptor_locals_dict_table[] = { +static const mp_rom_map_elem_t ubluepy_descriptor_locals_dict_table[] = { #if 0 { MP_ROM_QSTR(MP_QSTR_binVal), MP_ROM_PTR(&ubluepy_descriptor_bin_val_obj) }, #endif }; -STATIC MP_DEFINE_CONST_DICT(ubluepy_descriptor_locals_dict, ubluepy_descriptor_locals_dict_table); +static MP_DEFINE_CONST_DICT(ubluepy_descriptor_locals_dict, ubluepy_descriptor_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( ubluepy_descriptor_type, diff --git a/ports/nrf/modules/ubluepy/ubluepy_peripheral.c b/ports/nrf/modules/ubluepy/ubluepy_peripheral.c index 7de9aa26bbae8..443345042938d 100644 --- a/ports/nrf/modules/ubluepy/ubluepy_peripheral.c +++ b/ports/nrf/modules/ubluepy/ubluepy_peripheral.c @@ -34,14 +34,14 @@ #include "ble_drv.h" -STATIC void ubluepy_peripheral_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { +static void ubluepy_peripheral_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { ubluepy_peripheral_obj_t * self = (ubluepy_peripheral_obj_t *)o; (void)self; mp_printf(print, "Peripheral(conn_handle: " HEX2_FMT ")", self->conn_handle); } -STATIC void gap_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t conn_handle, uint16_t length, uint8_t * data) { +static void gap_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t conn_handle, uint16_t length, uint8_t * data) { ubluepy_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in); if (event_id == 16) { // connect event @@ -68,7 +68,7 @@ STATIC void gap_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t conn (void)self; } -STATIC void gatts_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t attr_handle, uint16_t length, uint8_t * data) { +static void gatts_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t attr_handle, uint16_t length, uint8_t * data) { ubluepy_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in); if (self->conn_handler != mp_const_none) { @@ -92,14 +92,14 @@ STATIC void gatts_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t at static volatile bool m_disc_evt_received; -STATIC void gattc_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t attr_handle, uint16_t length, uint8_t * data) { +static void gattc_event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t attr_handle, uint16_t length, uint8_t * data) { ubluepy_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in); (void)self; m_disc_evt_received = true; } #endif -STATIC mp_obj_t ubluepy_peripheral_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t ubluepy_peripheral_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_NEW_DEVICE_ADDR, ARG_NEW_ADDR_TYPE @@ -129,45 +129,45 @@ STATIC mp_obj_t ubluepy_peripheral_make_new(const mp_obj_type_t *type, size_t n_ /// \method withDelegate(DefaultDelegate) /// Set delegate instance for handling Bluetooth LE events. /// -STATIC mp_obj_t peripheral_with_delegate(mp_obj_t self_in, mp_obj_t delegate) { +static mp_obj_t peripheral_with_delegate(mp_obj_t self_in, mp_obj_t delegate) { ubluepy_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in); self->delegate = delegate; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_peripheral_with_delegate_obj, peripheral_with_delegate); +static MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_peripheral_with_delegate_obj, peripheral_with_delegate); /// \method setNotificationHandler(func) /// Set handler for Bluetooth LE notification events. /// -STATIC mp_obj_t peripheral_set_notif_handler(mp_obj_t self_in, mp_obj_t func) { +static mp_obj_t peripheral_set_notif_handler(mp_obj_t self_in, mp_obj_t func) { ubluepy_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in); self->notif_handler = func; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_peripheral_set_notif_handler_obj, peripheral_set_notif_handler); +static MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_peripheral_set_notif_handler_obj, peripheral_set_notif_handler); /// \method setConnectionHandler(func) /// Set handler for Bluetooth LE connection events. /// -STATIC mp_obj_t peripheral_set_conn_handler(mp_obj_t self_in, mp_obj_t func) { +static mp_obj_t peripheral_set_conn_handler(mp_obj_t self_in, mp_obj_t func) { ubluepy_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in); self->conn_handler = func; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_peripheral_set_conn_handler_obj, peripheral_set_conn_handler); +static MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_peripheral_set_conn_handler_obj, peripheral_set_conn_handler); #if MICROPY_PY_UBLUEPY_PERIPHERAL /// \method advertise(device_name, [service=[service1, service2, ...]], [data=bytearray], [connectable=True]) /// Start advertising. Connectable advertisement type by default. /// -STATIC mp_obj_t peripheral_advertise(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t peripheral_advertise(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_device_name, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_services, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, @@ -231,12 +231,12 @@ STATIC mp_obj_t peripheral_advertise(mp_uint_t n_args, const mp_obj_t *pos_args, return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ubluepy_peripheral_advertise_obj, 0, peripheral_advertise); +static MP_DEFINE_CONST_FUN_OBJ_KW(ubluepy_peripheral_advertise_obj, 0, peripheral_advertise); /// \method advertise_stop() /// Stop advertisement if any onging advertisement. /// -STATIC mp_obj_t peripheral_advertise_stop(mp_obj_t self_in) { +static mp_obj_t peripheral_advertise_stop(mp_obj_t self_in) { ubluepy_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in); (void)self; @@ -245,26 +245,26 @@ STATIC mp_obj_t peripheral_advertise_stop(mp_obj_t self_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_peripheral_advertise_stop_obj, peripheral_advertise_stop); +static MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_peripheral_advertise_stop_obj, peripheral_advertise_stop); #endif // MICROPY_PY_UBLUEPY_PERIPHERAL /// \method disconnect() /// disconnect connection. /// -STATIC mp_obj_t peripheral_disconnect(mp_obj_t self_in) { +static mp_obj_t peripheral_disconnect(mp_obj_t self_in) { ubluepy_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in); (void)self; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_peripheral_disconnect_obj, peripheral_disconnect); +static MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_peripheral_disconnect_obj, peripheral_disconnect); /// \method addService(Service) /// Add service to the Peripheral. /// -STATIC mp_obj_t peripheral_add_service(mp_obj_t self_in, mp_obj_t service) { +static mp_obj_t peripheral_add_service(mp_obj_t self_in, mp_obj_t service) { ubluepy_peripheral_obj_t * self = MP_OBJ_TO_PTR(self_in); ubluepy_service_obj_t * p_service = MP_OBJ_TO_PTR(service); @@ -274,17 +274,17 @@ STATIC mp_obj_t peripheral_add_service(mp_obj_t self_in, mp_obj_t service) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_peripheral_add_service_obj, peripheral_add_service); +static MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_peripheral_add_service_obj, peripheral_add_service); /// \method getServices() /// Return list with all service registered in the Peripheral. /// -STATIC mp_obj_t peripheral_get_services(mp_obj_t self_in) { +static mp_obj_t peripheral_get_services(mp_obj_t self_in) { ubluepy_peripheral_obj_t * self = MP_OBJ_TO_PTR(self_in); return self->service_list; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_peripheral_get_services_obj, peripheral_get_services); +static MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_peripheral_get_services_obj, peripheral_get_services); #if MICROPY_PY_UBLUEPY_CENTRAL @@ -337,7 +337,7 @@ void static disc_add_char(mp_obj_t service_in, ble_drv_char_data_t * p_desc_data /// addr_type can be either ADDR_TYPE_PUBLIC (default) or /// ADDR_TYPE_RANDOM_STATIC. /// -STATIC mp_obj_t peripheral_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t peripheral_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { ubluepy_peripheral_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); mp_obj_t dev_addr = pos_args[1]; @@ -439,11 +439,11 @@ STATIC mp_obj_t peripheral_connect(mp_uint_t n_args, const mp_obj_t *pos_args, m return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ubluepy_peripheral_connect_obj, 2, peripheral_connect); +static MP_DEFINE_CONST_FUN_OBJ_KW(ubluepy_peripheral_connect_obj, 2, peripheral_connect); #endif -STATIC const mp_rom_map_elem_t ubluepy_peripheral_locals_dict_table[] = { +static const mp_rom_map_elem_t ubluepy_peripheral_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_withDelegate), MP_ROM_PTR(&ubluepy_peripheral_with_delegate_obj) }, { MP_ROM_QSTR(MP_QSTR_setNotificationHandler), MP_ROM_PTR(&ubluepy_peripheral_set_notif_handler_obj) }, { MP_ROM_QSTR(MP_QSTR_setConnectionHandler), MP_ROM_PTR(&ubluepy_peripheral_set_conn_handler_obj) }, @@ -480,7 +480,7 @@ STATIC const mp_rom_map_elem_t ubluepy_peripheral_locals_dict_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(ubluepy_peripheral_locals_dict, ubluepy_peripheral_locals_dict_table); +static MP_DEFINE_CONST_DICT(ubluepy_peripheral_locals_dict, ubluepy_peripheral_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( ubluepy_peripheral_type, diff --git a/ports/nrf/modules/ubluepy/ubluepy_scan_entry.c b/ports/nrf/modules/ubluepy/ubluepy_scan_entry.c index 626578360ac95..cf329ddd9d780 100644 --- a/ports/nrf/modules/ubluepy/ubluepy_scan_entry.c +++ b/ports/nrf/modules/ubluepy/ubluepy_scan_entry.c @@ -37,7 +37,7 @@ #include "ble_drv.h" -STATIC void ubluepy_scan_entry_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { +static void ubluepy_scan_entry_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { ubluepy_scan_entry_obj_t * self = (ubluepy_scan_entry_obj_t *)o; (void)self; mp_printf(print, "ScanEntry"); @@ -46,34 +46,34 @@ STATIC void ubluepy_scan_entry_print(const mp_print_t *print, mp_obj_t o, mp_pri /// \method addr() /// Return address as text string. /// -STATIC mp_obj_t scan_entry_get_addr(mp_obj_t self_in) { +static mp_obj_t scan_entry_get_addr(mp_obj_t self_in) { ubluepy_scan_entry_obj_t *self = MP_OBJ_TO_PTR(self_in); return self->addr; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bluepy_scan_entry_get_addr_obj, scan_entry_get_addr); +static MP_DEFINE_CONST_FUN_OBJ_1(bluepy_scan_entry_get_addr_obj, scan_entry_get_addr); /// \method addr_type() /// Return address type value. /// -STATIC mp_obj_t scan_entry_get_addr_type(mp_obj_t self_in) { +static mp_obj_t scan_entry_get_addr_type(mp_obj_t self_in) { ubluepy_scan_entry_obj_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_int(self->addr_type); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bluepy_scan_entry_get_addr_type_obj, scan_entry_get_addr_type); +static MP_DEFINE_CONST_FUN_OBJ_1(bluepy_scan_entry_get_addr_type_obj, scan_entry_get_addr_type); /// \method rssi() /// Return RSSI value. /// -STATIC mp_obj_t scan_entry_get_rssi(mp_obj_t self_in) { +static mp_obj_t scan_entry_get_rssi(mp_obj_t self_in) { ubluepy_scan_entry_obj_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_int(self->rssi); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bluepy_scan_entry_get_rssi_obj, scan_entry_get_rssi); +static MP_DEFINE_CONST_FUN_OBJ_1(bluepy_scan_entry_get_rssi_obj, scan_entry_get_rssi); /// \method getScanData() /// Return list of the scan data tuples (ad_type, description, value) /// -STATIC mp_obj_t scan_entry_get_scan_data(mp_obj_t self_in) { +static mp_obj_t scan_entry_get_scan_data(mp_obj_t self_in) { ubluepy_scan_entry_obj_t * self = MP_OBJ_TO_PTR(self_in); mp_obj_t retval_list = mp_obj_new_list(0, NULL); @@ -125,16 +125,16 @@ STATIC mp_obj_t scan_entry_get_scan_data(mp_obj_t self_in) { return retval_list; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_scan_entry_get_scan_data_obj, scan_entry_get_scan_data); +static MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_scan_entry_get_scan_data_obj, scan_entry_get_scan_data); -STATIC const mp_rom_map_elem_t ubluepy_scan_entry_locals_dict_table[] = { +static const mp_rom_map_elem_t ubluepy_scan_entry_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_addr), MP_ROM_PTR(&bluepy_scan_entry_get_addr_obj) }, { MP_ROM_QSTR(MP_QSTR_addr_type), MP_ROM_PTR(&bluepy_scan_entry_get_addr_type_obj) }, { MP_ROM_QSTR(MP_QSTR_rssi), MP_ROM_PTR(&bluepy_scan_entry_get_rssi_obj) }, { MP_ROM_QSTR(MP_QSTR_getScanData), MP_ROM_PTR(&ubluepy_scan_entry_get_scan_data_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(ubluepy_scan_entry_locals_dict, ubluepy_scan_entry_locals_dict_table); +static MP_DEFINE_CONST_DICT(ubluepy_scan_entry_locals_dict, ubluepy_scan_entry_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( ubluepy_scan_entry_type, diff --git a/ports/nrf/modules/ubluepy/ubluepy_scanner.c b/ports/nrf/modules/ubluepy/ubluepy_scanner.c index ffb7e946717b2..17d697b86e3ba 100644 --- a/ports/nrf/modules/ubluepy/ubluepy_scanner.c +++ b/ports/nrf/modules/ubluepy/ubluepy_scanner.c @@ -35,7 +35,7 @@ #include "ble_drv.h" #include "mphalport.h" -STATIC void adv_event_handler(mp_obj_t self_in, uint16_t event_id, ble_drv_adv_data_t * data) { +static void adv_event_handler(mp_obj_t self_in, uint16_t event_id, ble_drv_adv_data_t * data) { ubluepy_scanner_obj_t *self = MP_OBJ_TO_PTR(self_in); ubluepy_scan_entry_obj_t * item = mp_obj_malloc(ubluepy_scan_entry_obj_t, &ubluepy_scan_entry_type); @@ -62,13 +62,13 @@ STATIC void adv_event_handler(mp_obj_t self_in, uint16_t event_id, ble_drv_adv_d ble_drv_scan_start(true); } -STATIC void ubluepy_scanner_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { +static void ubluepy_scanner_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { ubluepy_scanner_obj_t * self = (ubluepy_scanner_obj_t *)o; (void)self; mp_printf(print, "Scanner"); } -STATIC mp_obj_t ubluepy_scanner_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t ubluepy_scanner_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { static const mp_arg_t allowed_args[] = { }; @@ -86,7 +86,7 @@ STATIC mp_obj_t ubluepy_scanner_make_new(const mp_obj_type_t *type, size_t n_arg /// Scan for devices. Timeout is in milliseconds and will set the duration /// of the scanning. /// -STATIC mp_obj_t scanner_scan(mp_obj_t self_in, mp_obj_t timeout_in) { +static mp_obj_t scanner_scan(mp_obj_t self_in, mp_obj_t timeout_in) { ubluepy_scanner_obj_t * self = MP_OBJ_TO_PTR(self_in); mp_int_t timeout = mp_obj_get_int(timeout_in); @@ -105,13 +105,13 @@ STATIC mp_obj_t scanner_scan(mp_obj_t self_in, mp_obj_t timeout_in) { return self->adv_reports; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_scanner_scan_obj, scanner_scan); +static MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_scanner_scan_obj, scanner_scan); -STATIC const mp_rom_map_elem_t ubluepy_scanner_locals_dict_table[] = { +static const mp_rom_map_elem_t ubluepy_scanner_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_scan), MP_ROM_PTR(&ubluepy_scanner_scan_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(ubluepy_scanner_locals_dict, ubluepy_scanner_locals_dict_table); +static MP_DEFINE_CONST_DICT(ubluepy_scanner_locals_dict, ubluepy_scanner_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( diff --git a/ports/nrf/modules/ubluepy/ubluepy_service.c b/ports/nrf/modules/ubluepy/ubluepy_service.c index bf336d04c58ab..3c72c02c4af78 100644 --- a/ports/nrf/modules/ubluepy/ubluepy_service.c +++ b/ports/nrf/modules/ubluepy/ubluepy_service.c @@ -33,13 +33,13 @@ #include "modubluepy.h" #include "ble_drv.h" -STATIC void ubluepy_service_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { +static void ubluepy_service_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { ubluepy_service_obj_t * self = (ubluepy_service_obj_t *)o; mp_printf(print, "Service(handle: 0x" HEX2_FMT ")", self->handle); } -STATIC mp_obj_t ubluepy_service_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t ubluepy_service_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_NEW_UUID, ARG_NEW_TYPE }; @@ -86,7 +86,7 @@ STATIC mp_obj_t ubluepy_service_make_new(const mp_obj_type_t *type, size_t n_arg /// \method addCharacteristic(Characteristic) /// Add Characteristic to the Service. /// -STATIC mp_obj_t service_add_characteristic(mp_obj_t self_in, mp_obj_t characteristic) { +static mp_obj_t service_add_characteristic(mp_obj_t self_in, mp_obj_t characteristic) { ubluepy_service_obj_t * self = MP_OBJ_TO_PTR(self_in); ubluepy_characteristic_obj_t * p_char = MP_OBJ_TO_PTR(characteristic); @@ -103,22 +103,22 @@ STATIC mp_obj_t service_add_characteristic(mp_obj_t self_in, mp_obj_t characteri // return mp_obj_new_bool(retval); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_service_add_char_obj, service_add_characteristic); +static MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_service_add_char_obj, service_add_characteristic); /// \method getCharacteristics() /// Return list with all characteristics registered in the Service. /// -STATIC mp_obj_t service_get_chars(mp_obj_t self_in) { +static mp_obj_t service_get_chars(mp_obj_t self_in) { ubluepy_service_obj_t * self = MP_OBJ_TO_PTR(self_in); return self->char_list; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_service_get_chars_obj, service_get_chars); +static MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_service_get_chars_obj, service_get_chars); /// \method getCharacteristic(UUID) /// Return Characteristic with the given UUID. /// -STATIC mp_obj_t service_get_characteristic(mp_obj_t self_in, mp_obj_t uuid) { +static mp_obj_t service_get_characteristic(mp_obj_t self_in, mp_obj_t uuid) { ubluepy_service_obj_t * self = MP_OBJ_TO_PTR(self_in); ubluepy_uuid_obj_t * p_uuid = MP_OBJ_TO_PTR(uuid); @@ -145,18 +145,18 @@ STATIC mp_obj_t service_get_characteristic(mp_obj_t self_in, mp_obj_t uuid) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_service_get_char_obj, service_get_characteristic); +static MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_service_get_char_obj, service_get_characteristic); /// \method uuid() /// Get UUID instance of the Service. /// -STATIC mp_obj_t service_uuid(mp_obj_t self_in) { +static mp_obj_t service_uuid(mp_obj_t self_in) { ubluepy_service_obj_t * self = MP_OBJ_TO_PTR(self_in); return MP_OBJ_FROM_PTR(self->p_uuid); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_service_get_uuid_obj, service_uuid); +static MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_service_get_uuid_obj, service_uuid); -STATIC const mp_rom_map_elem_t ubluepy_service_locals_dict_table[] = { +static const mp_rom_map_elem_t ubluepy_service_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_getCharacteristic), MP_ROM_PTR(&ubluepy_service_get_char_obj) }, { MP_ROM_QSTR(MP_QSTR_addCharacteristic), MP_ROM_PTR(&ubluepy_service_add_char_obj) }, { MP_ROM_QSTR(MP_QSTR_getCharacteristics), MP_ROM_PTR(&ubluepy_service_get_chars_obj) }, @@ -169,7 +169,7 @@ STATIC const mp_rom_map_elem_t ubluepy_service_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_SECONDARY), MP_ROM_INT(UBLUEPY_SERVICE_SECONDARY) }, }; -STATIC MP_DEFINE_CONST_DICT(ubluepy_service_locals_dict, ubluepy_service_locals_dict_table); +static MP_DEFINE_CONST_DICT(ubluepy_service_locals_dict, ubluepy_service_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( ubluepy_service_type, diff --git a/ports/nrf/modules/ubluepy/ubluepy_uuid.c b/ports/nrf/modules/ubluepy/ubluepy_uuid.c index abfe3cadd525b..06313e8da2cbf 100644 --- a/ports/nrf/modules/ubluepy/ubluepy_uuid.c +++ b/ports/nrf/modules/ubluepy/ubluepy_uuid.c @@ -34,7 +34,7 @@ #include "modubluepy.h" #include "ble_drv.h" -STATIC void ubluepy_uuid_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { +static void ubluepy_uuid_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { ubluepy_uuid_obj_t * self = (ubluepy_uuid_obj_t *)o; if (self->type == UBLUEPY_UUID_16_BIT) { mp_printf(print, "UUID(uuid: 0x" HEX2_FMT HEX2_FMT ")", @@ -45,7 +45,7 @@ STATIC void ubluepy_uuid_print(const mp_print_t *print, mp_obj_t o, mp_print_kin } } -STATIC mp_obj_t ubluepy_uuid_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t ubluepy_uuid_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_NEW_UUID }; @@ -140,7 +140,7 @@ STATIC mp_obj_t ubluepy_uuid_make_new(const mp_obj_type_t *type, size_t n_args, /// \method binVal() /// Get binary value of the 16 or 128 bit UUID. Returned as bytearray type. /// -STATIC mp_obj_t uuid_bin_val(mp_obj_t self_in) { +static mp_obj_t uuid_bin_val(mp_obj_t self_in) { ubluepy_uuid_obj_t * self = MP_OBJ_TO_PTR(self_in); // TODO: Extend the uint16 byte value to 16 byte if 128-bit, @@ -148,9 +148,9 @@ STATIC mp_obj_t uuid_bin_val(mp_obj_t self_in) { // the uint16_t field of the UUID. return MP_OBJ_NEW_SMALL_INT(self->value[0] | self->value[1] << 8); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_uuid_bin_val_obj, uuid_bin_val); +static MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_uuid_bin_val_obj, uuid_bin_val); -STATIC const mp_rom_map_elem_t ubluepy_uuid_locals_dict_table[] = { +static const mp_rom_map_elem_t ubluepy_uuid_locals_dict_table[] = { #if 0 { MP_ROM_QSTR(MP_QSTR_getCommonName), MP_ROM_PTR(&ubluepy_uuid_get_common_name_obj) }, #endif @@ -158,7 +158,7 @@ STATIC const mp_rom_map_elem_t ubluepy_uuid_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_binVal), MP_ROM_PTR(&ubluepy_uuid_bin_val_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(ubluepy_uuid_locals_dict, ubluepy_uuid_locals_dict_table); +static MP_DEFINE_CONST_DICT(ubluepy_uuid_locals_dict, ubluepy_uuid_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( ubluepy_uuid_type, diff --git a/ports/nrf/mphalport.c b/ports/nrf/mphalport.c index c964a26c2e371..2a1a4cb13ba36 100644 --- a/ports/nrf/mphalport.c +++ b/ports/nrf/mphalport.c @@ -86,7 +86,7 @@ const nrfx_rtc_config_t rtc_config_time_ticks = { #endif }; -STATIC void rtc_irq_time(nrfx_rtc_int_type_t event) { +static void rtc_irq_time(nrfx_rtc_int_type_t event) { // irq handler for overflow if (event == NRFX_RTC_INT_OVERFLOW) { rtc_overflows += 1; diff --git a/ports/nrf/pin_named_pins.c b/ports/nrf/pin_named_pins.c index 30e60692f7410..6fbe75c757a8a 100644 --- a/ports/nrf/pin_named_pins.c +++ b/ports/nrf/pin_named_pins.c @@ -31,7 +31,7 @@ #include "py/mphal.h" #include "pin.h" -STATIC void pin_named_pins_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void pin_named_pins_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pin_named_pins_obj_t *self = self_in; mp_printf(print, "", self->name); } diff --git a/ports/pic16bit/modpyb.c b/ports/pic16bit/modpyb.c index 9774105d66ae5..5e31eb8af8ca1 100644 --- a/ports/pic16bit/modpyb.c +++ b/ports/pic16bit/modpyb.c @@ -30,28 +30,28 @@ #include "py/mphal.h" #include "modpyb.h" -STATIC mp_obj_t pyb_millis(void) { +static mp_obj_t pyb_millis(void) { return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_millis_obj, pyb_millis); +static MP_DEFINE_CONST_FUN_OBJ_0(pyb_millis_obj, pyb_millis); -STATIC mp_obj_t pyb_elapsed_millis(mp_obj_t start) { +static mp_obj_t pyb_elapsed_millis(mp_obj_t start) { uint32_t startMillis = mp_obj_get_int(start); uint32_t currMillis = mp_hal_ticks_ms(); return MP_OBJ_NEW_SMALL_INT((currMillis - startMillis) & 0x1fff); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_elapsed_millis_obj, pyb_elapsed_millis); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_elapsed_millis_obj, pyb_elapsed_millis); -STATIC mp_obj_t pyb_delay(mp_obj_t ms_in) { +static mp_obj_t pyb_delay(mp_obj_t ms_in) { mp_int_t ms = mp_obj_get_int(ms_in); if (ms >= 0) { mp_hal_delay_ms(ms); } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_delay_obj, pyb_delay); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_delay_obj, pyb_delay); -STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = { +static const mp_rom_map_elem_t pyb_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_pyb) }, { MP_ROM_QSTR(MP_QSTR_millis), MP_ROM_PTR(&pyb_millis_obj) }, @@ -62,7 +62,7 @@ STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_Switch), MP_ROM_PTR(&pyb_switch_type) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_module_globals, pyb_module_globals_table); +static MP_DEFINE_CONST_DICT(pyb_module_globals, pyb_module_globals_table); const mp_obj_module_t pyb_module = { .base = { &mp_type_module }, diff --git a/ports/pic16bit/modpybled.c b/ports/pic16bit/modpybled.c index 47e83e0409215..34d41caec2325 100644 --- a/ports/pic16bit/modpybled.c +++ b/ports/pic16bit/modpybled.c @@ -32,7 +32,7 @@ typedef struct _pyb_led_obj_t { mp_obj_base_t base; } pyb_led_obj_t; -STATIC const pyb_led_obj_t pyb_led_obj[] = { +static const pyb_led_obj_t pyb_led_obj[] = { {{&pyb_led_type}}, {{&pyb_led_type}}, {{&pyb_led_type}}, @@ -46,7 +46,7 @@ void pyb_led_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t ki mp_printf(print, "LED(%u)", LED_ID(self)); } -STATIC mp_obj_t pyb_led_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pyb_led_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 1, false); mp_int_t led_id = mp_obj_get_int(args[0]); if (!(1 <= led_id && led_id <= NUM_LED)) { @@ -60,29 +60,29 @@ mp_obj_t pyb_led_on(mp_obj_t self_in) { led_state(LED_ID(self), 1); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_led_on_obj, pyb_led_on); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_led_on_obj, pyb_led_on); mp_obj_t pyb_led_off(mp_obj_t self_in) { pyb_led_obj_t *self = self_in; led_state(LED_ID(self), 0); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_led_off_obj, pyb_led_off); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_led_off_obj, pyb_led_off); mp_obj_t pyb_led_toggle(mp_obj_t self_in) { pyb_led_obj_t *self = self_in; led_toggle(LED_ID(self)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_led_toggle_obj, pyb_led_toggle); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_led_toggle_obj, pyb_led_toggle); -STATIC const mp_rom_map_elem_t pyb_led_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_led_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_on), MP_ROM_PTR(&pyb_led_on_obj) }, { MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(&pyb_led_off_obj) }, { MP_ROM_QSTR(MP_QSTR_toggle), MP_ROM_PTR(&pyb_led_toggle_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_led_locals_dict, pyb_led_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_led_locals_dict, pyb_led_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pyb_led_type, diff --git a/ports/pic16bit/modpybswitch.c b/ports/pic16bit/modpybswitch.c index b7192c5bba69b..3e319f01b6c63 100644 --- a/ports/pic16bit/modpybswitch.c +++ b/ports/pic16bit/modpybswitch.c @@ -32,7 +32,7 @@ typedef struct _pyb_switch_obj_t { mp_obj_base_t base; } pyb_switch_obj_t; -STATIC const pyb_switch_obj_t pyb_switch_obj[] = { +static const pyb_switch_obj_t pyb_switch_obj[] = { {{&pyb_switch_type}}, {{&pyb_switch_type}}, }; @@ -45,7 +45,7 @@ void pyb_switch_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t mp_printf(print, "Switch(%u)", SWITCH_ID(self)); } -STATIC mp_obj_t pyb_switch_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pyb_switch_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 1, false); mp_int_t sw_id = mp_obj_get_int(args[0]); if (!(1 <= sw_id && sw_id <= NUM_SWITCH)) { @@ -58,18 +58,18 @@ mp_obj_t pyb_switch_value(mp_obj_t self_in) { pyb_switch_obj_t *self = self_in; return switch_get(SWITCH_ID(self)) ? mp_const_true : mp_const_false; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_switch_value_obj, pyb_switch_value); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_switch_value_obj, pyb_switch_value); mp_obj_t pyb_switch_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 0, false); return pyb_switch_value(self_in); } -STATIC const mp_rom_map_elem_t pyb_switch_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_switch_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&pyb_switch_value_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_switch_locals_dict, pyb_switch_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_switch_locals_dict, pyb_switch_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pyb_switch_type, diff --git a/ports/qemu-arm/modmachine.c b/ports/qemu-arm/modmachine.c index 72eaad6eab392..5f6db937c3384 100644 --- a/ports/qemu-arm/modmachine.c +++ b/ports/qemu-arm/modmachine.c @@ -30,6 +30,6 @@ // This variable is needed for machine.soft_reset(), but the variable is otherwise unused. int pyexec_system_exit = 0; -STATIC void mp_machine_idle(void) { +static void mp_machine_idle(void) { // Do nothing. } diff --git a/ports/renesas-ra/boardctrl.c b/ports/renesas-ra/boardctrl.c index b6f0a9093843e..6459c029a7f3f 100644 --- a/ports/renesas-ra/boardctrl.c +++ b/ports/renesas-ra/boardctrl.c @@ -32,7 +32,7 @@ #include "led.h" #include "usrsw.h" -STATIC void flash_error(int n) { +static void flash_error(int n) { for (int i = 0; i < n; i++) { led_state(RA_LED1, 1); mp_hal_delay_ms(250); @@ -42,7 +42,7 @@ STATIC void flash_error(int n) { } #if !MICROPY_HW_USES_BOOTLOADER -STATIC uint update_reset_mode(uint reset_mode) { +static uint update_reset_mode(uint reset_mode) { #if MICROPY_HW_HAS_SWITCH bool press_status; diff --git a/ports/renesas-ra/extint.c b/ports/renesas-ra/extint.c index 915c23e3cd853..f1d445346d56e 100644 --- a/ports/renesas-ra/extint.c +++ b/ports/renesas-ra/extint.c @@ -91,8 +91,8 @@ typedef struct { mp_int_t irq_no; } extint_obj_t; -STATIC uint8_t pyb_extint_mode[EXTI_NUM_VECTORS]; -STATIC bool pyb_extint_hard_irq[EXTI_NUM_VECTORS]; +static uint8_t pyb_extint_mode[EXTI_NUM_VECTORS]; +static bool pyb_extint_hard_irq[EXTI_NUM_VECTORS]; // The callback arg is a small-int or a ROM Pin object, so no need to scan by GC mp_obj_t pyb_extint_callback_arg[EXTI_NUM_VECTORS]; @@ -270,7 +270,7 @@ void extint_trigger_mode(uint line, uint32_t mode) { /// \method irq_no() /// Return the irq_no number that the pin is mapped to. -STATIC mp_obj_t extint_obj_irq_no(mp_obj_t self_in) { +static mp_obj_t extint_obj_irq_no(mp_obj_t self_in) { extint_obj_t *self = MP_OBJ_TO_PTR(self_in); uint8_t irq_no; bool find = ra_icu_find_irq_no(self->pin_idx, &irq_no); @@ -280,45 +280,45 @@ STATIC mp_obj_t extint_obj_irq_no(mp_obj_t self_in) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_irq_no_obj, extint_obj_irq_no); +static MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_irq_no_obj, extint_obj_irq_no); /// \method enable() /// Enable a disabled interrupt. -STATIC mp_obj_t extint_obj_enable(mp_obj_t self_in) { +static mp_obj_t extint_obj_enable(mp_obj_t self_in) { extint_obj_t *self = MP_OBJ_TO_PTR(self_in); ra_icu_enable_pin(self->pin_idx); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_enable_obj, extint_obj_enable); +static MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_enable_obj, extint_obj_enable); /// \method disable() /// Disable the interrupt associated with the ExtInt object. /// This could be useful for debouncing. -STATIC mp_obj_t extint_obj_disable(mp_obj_t self_in) { +static mp_obj_t extint_obj_disable(mp_obj_t self_in) { extint_obj_t *self = MP_OBJ_TO_PTR(self_in); ra_icu_disable_pin(self->pin_idx); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_disable_obj, extint_obj_disable); +static MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_disable_obj, extint_obj_disable); /// \method swint() /// Trigger the callback from software. -STATIC mp_obj_t extint_obj_swint(mp_obj_t self_in) { +static mp_obj_t extint_obj_swint(mp_obj_t self_in) { extint_obj_t *self = MP_OBJ_TO_PTR(self_in); ra_icu_swint(self->irq_no); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_swint_obj, extint_obj_swint); +static MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_swint_obj, extint_obj_swint); // TODO document as a staticmethod /// \classmethod regs() /// Dump the values of the EXTI registers. -STATIC mp_obj_t extint_regs(void) { +static mp_obj_t extint_regs(void) { printf("Not Implemented\n"); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(extint_regs_fun_obj, extint_regs); -STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(extint_regs_obj, MP_ROM_PTR(&extint_regs_fun_obj)); +static MP_DEFINE_CONST_FUN_OBJ_0(extint_regs_fun_obj, extint_regs); +static MP_DEFINE_CONST_STATICMETHOD_OBJ(extint_regs_obj, MP_ROM_PTR(&extint_regs_fun_obj)); /// \classmethod \constructor(pin, mode, pull, callback) /// Create an ExtInt object: @@ -335,7 +335,7 @@ STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(extint_regs_obj, MP_ROM_PTR(&extint_regs /// - `callback` is the function to call when the interrupt triggers. The /// callback function must accept exactly 1 argument, which is the irq_no that /// triggered the interrupt. -STATIC const mp_arg_t pyb_extint_make_new_args[] = { +static const mp_arg_t pyb_extint_make_new_args[] = { { MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_pull, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} }, @@ -343,7 +343,7 @@ STATIC const mp_arg_t pyb_extint_make_new_args[] = { }; #define PYB_EXTINT_MAKE_NEW_NUM_ARGS MP_ARRAY_SIZE(pyb_extint_make_new_args) -STATIC mp_obj_t extint_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t extint_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // type_in == extint_obj_type // parse args @@ -358,12 +358,12 @@ STATIC mp_obj_t extint_make_new(const mp_obj_type_t *type, size_t n_args, size_t return MP_OBJ_FROM_PTR(self); } -STATIC void extint_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void extint_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { extint_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", self->irq_no); } -STATIC const mp_rom_map_elem_t extint_locals_dict_table[] = { +static const mp_rom_map_elem_t extint_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_irq_no), MP_ROM_PTR(&extint_obj_irq_no_obj) }, { MP_ROM_QSTR(MP_QSTR_line), MP_ROM_PTR(&extint_obj_irq_no_obj) }, { MP_ROM_QSTR(MP_QSTR_enable), MP_ROM_PTR(&extint_obj_enable_obj) }, @@ -372,7 +372,7 @@ STATIC const mp_rom_map_elem_t extint_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_regs), MP_ROM_PTR(&extint_regs_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(extint_locals_dict, extint_locals_dict_table); +static MP_DEFINE_CONST_DICT(extint_locals_dict, extint_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( extint_type, diff --git a/ports/renesas-ra/flashbdev.c b/ports/renesas-ra/flashbdev.c index c213ed8f9b89e..c3c252232c421 100644 --- a/ports/renesas-ra/flashbdev.c +++ b/ports/renesas-ra/flashbdev.c @@ -66,7 +66,7 @@ extern uint8_t _micropy_hw_internal_flash_storage_end; #error "no internal flash storage support for this MCU" #endif -STATIC byte flash_cache_mem[FLASH_SECTOR_SIZE_MAX] __attribute__((aligned(16))); +static byte flash_cache_mem[FLASH_SECTOR_SIZE_MAX] __attribute__((aligned(16))); #define CACHE_MEM_START_ADDR (&flash_cache_mem[0]) #if !defined(FLASH_MEM_SEG2_START_ADDR) diff --git a/ports/renesas-ra/irq.c b/ports/renesas-ra/irq.c index fdaf2385cc9d1..3bef1712fccf3 100644 --- a/ports/renesas-ra/irq.c +++ b/ports/renesas-ra/irq.c @@ -36,7 +36,7 @@ uint32_t irq_stats[IRQ_STATS_MAX] = {0}; // disable_irq() // Disable interrupt requests. // Returns the previous IRQ state which can be passed to enable_irq. -STATIC mp_obj_t machine_disable_irq(void) { +static mp_obj_t machine_disable_irq(void) { return mp_obj_new_bool(disable_irq() == IRQ_STATE_ENABLED); } MP_DEFINE_CONST_FUN_OBJ_0(machine_disable_irq_obj, machine_disable_irq); @@ -44,7 +44,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(machine_disable_irq_obj, machine_disable_irq); // enable_irq(state=True) // Enable interrupt requests, based on the argument, which is usually the // value returned by a previous call to disable_irq. -STATIC mp_obj_t machine_enable_irq(uint n_args, const mp_obj_t *arg) { +static mp_obj_t machine_enable_irq(uint n_args, const mp_obj_t *arg) { enable_irq((n_args == 0 || mp_obj_is_true(arg[0])) ? IRQ_STATE_ENABLED : IRQ_STATE_DISABLED); return mp_const_none; } @@ -52,7 +52,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_enable_irq_obj, 0, 1, machine_enable #if IRQ_ENABLE_STATS // return a memoryview of the irq statistics array -STATIC mp_obj_t pyb_irq_stats(void) { +static mp_obj_t pyb_irq_stats(void) { return mp_obj_new_memoryview(0x80 | 'I', MP_ARRAY_SIZE(irq_stats), &irq_stats[0]); } MP_DEFINE_CONST_FUN_OBJ_0(pyb_irq_stats_obj, pyb_irq_stats); diff --git a/ports/renesas-ra/led.c b/ports/renesas-ra/led.c index a2284c5339b94..c52cd50e7808a 100644 --- a/ports/renesas-ra/led.c +++ b/ports/renesas-ra/led.c @@ -51,7 +51,7 @@ typedef struct _ra_led_obj_t { const machine_pin_obj_t *led_pin; } ra_led_obj_t; -STATIC const ra_led_obj_t ra_led_obj[] = { +static const ra_led_obj_t ra_led_obj[] = { {{&ra_led_type}, 1, MICROPY_HW_LED1}, #if defined(MICROPY_HW_LED2) {{&ra_led_type}, 2, MICROPY_HW_LED2}, @@ -118,7 +118,7 @@ void led_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t ki /// Create an LED object associated with the given LED: /// /// - `id` is the LED number, 1-4. -STATIC mp_obj_t led_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t led_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, 1, false); @@ -158,17 +158,17 @@ mp_obj_t led_obj_toggle(mp_obj_t self_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_on_obj, led_obj_on); -STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_off_obj, led_obj_off); -STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_toggle_obj, led_obj_toggle); +static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_on_obj, led_obj_on); +static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_off_obj, led_obj_off); +static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_toggle_obj, led_obj_toggle); -STATIC const mp_rom_map_elem_t led_locals_dict_table[] = { +static const mp_rom_map_elem_t led_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_on), MP_ROM_PTR(&led_obj_on_obj) }, { MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(&led_obj_off_obj) }, { MP_ROM_QSTR(MP_QSTR_toggle), MP_ROM_PTR(&led_obj_toggle_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(led_locals_dict, led_locals_dict_table); +static MP_DEFINE_CONST_DICT(led_locals_dict, led_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( ra_led_type, diff --git a/ports/renesas-ra/machine_adc.c b/ports/renesas-ra/machine_adc.c index 4ba30dff01e10..c617b69658e2e 100644 --- a/ports/renesas-ra/machine_adc.c +++ b/ports/renesas-ra/machine_adc.c @@ -70,14 +70,14 @@ typedef struct _machine_adc_obj_t { uint32_t sample_time; } machine_adc_obj_t; -STATIC void mp_machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_adc_obj_t *self = MP_OBJ_TO_PTR(self_in); uint8_t resolution = (uint8_t)ra_adc_get_resolution(); mp_printf(print, "", resolution, self->channel); } // ADC(id) -STATIC mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // Check number of arguments mp_arg_check_num(n_args, n_kw, 1, 1, false); @@ -110,11 +110,11 @@ STATIC mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args return MP_OBJ_FROM_PTR(o); } -STATIC mp_int_t mp_machine_adc_read(machine_adc_obj_t *self) { +static mp_int_t mp_machine_adc_read(machine_adc_obj_t *self) { return ra_adc_read((uint32_t)(self->pin)); } -STATIC mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) { +static mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) { mp_uint_t raw = (mp_uint_t)ra_adc_read((uint32_t)(self->pin)); mp_int_t bits = (mp_int_t)ra_adc_get_resolution(); // Scale raw reading to 16 bit value using a Taylor expansion (for 8 <= bits <= 16) diff --git a/ports/renesas-ra/machine_dac.c b/ports/renesas-ra/machine_dac.c index 0d9c779497588..5889fca1c253c 100644 --- a/ports/renesas-ra/machine_dac.c +++ b/ports/renesas-ra/machine_dac.c @@ -43,7 +43,7 @@ typedef struct _machine_dac_obj_t { mp_hal_pin_obj_t dac; } machine_dac_obj_t; -STATIC machine_dac_obj_t machine_dac_obj[] = { +static machine_dac_obj_t machine_dac_obj[] = { #if defined(MICROPY_HW_DAC0) {{&machine_dac_type}, 0, 0, 0, MICROPY_HW_DAC0}, #endif @@ -52,12 +52,12 @@ STATIC machine_dac_obj_t machine_dac_obj[] = { #endif }; -STATIC void machine_dac_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_dac_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_dac_obj_t *self = MP_OBJ_TO_PTR(self_in); // const char *qstr_str(qstr q); mp_printf(print, "DAC(DA%d [#%d], active=%u, out=%u mV)", self->ch, self->dac->pin, self->active, self->mv); } -STATIC mp_obj_t machine_dac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t machine_dac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_hal_pin_obj_t pin_id = MP_OBJ_NULL; machine_dac_obj_t *self = MP_OBJ_NULL; @@ -99,7 +99,7 @@ STATIC mp_obj_t machine_dac_make_new(const mp_obj_type_t *type, size_t n_args, s } // DAC.deinit() -STATIC mp_obj_t machine_dac_deinit(mp_obj_t self_in) { +static mp_obj_t machine_dac_deinit(mp_obj_t self_in) { machine_dac_obj_t *self = MP_OBJ_TO_PTR(self_in); ra_dac_deinit(self->dac->pin, self->ch); @@ -108,10 +108,10 @@ STATIC mp_obj_t machine_dac_deinit(mp_obj_t self_in) { self->mv = 0; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_dac_deinit_obj, machine_dac_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_dac_deinit_obj, machine_dac_deinit); // DAC.write(value) -STATIC mp_obj_t machine_dac_write(mp_obj_t self_in, mp_obj_t data) { // mp_obj_t value_in +static mp_obj_t machine_dac_write(mp_obj_t self_in, mp_obj_t data) { // mp_obj_t value_in machine_dac_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t value = mp_obj_get_int(data); @@ -124,18 +124,18 @@ STATIC mp_obj_t machine_dac_write(mp_obj_t self_in, mp_obj_t data) { // mp_obj_t } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_dac_write_obj, machine_dac_write); +static MP_DEFINE_CONST_FUN_OBJ_2(machine_dac_write_obj, machine_dac_write); // DAC.read() -STATIC mp_obj_t machine_dac_read(mp_obj_t self_in) { +static mp_obj_t machine_dac_read(mp_obj_t self_in) { machine_dac_obj_t *self = MP_OBJ_TO_PTR(self_in); return MP_OBJ_NEW_SMALL_INT(ra_dac_read(self->ch)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_dac_read_obj, machine_dac_read); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_dac_read_obj, machine_dac_read); // DAC.write_mv(Vout) -STATIC mp_obj_t machine_dac_write_mv(mp_obj_t self_in, mp_obj_t data) { // mp_obj_t self_in, mp_obj_t value_in +static mp_obj_t machine_dac_write_mv(mp_obj_t self_in, mp_obj_t data) { // mp_obj_t self_in, mp_obj_t value_in machine_dac_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t Vout = mp_obj_get_int(data); @@ -149,19 +149,19 @@ STATIC mp_obj_t machine_dac_write_mv(mp_obj_t self_in, mp_obj_t data) { // mp_o } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_dac_write_mv_obj, machine_dac_write_mv); +static MP_DEFINE_CONST_FUN_OBJ_2(machine_dac_write_mv_obj, machine_dac_write_mv); // DAC.read_mv() -STATIC mp_obj_t machine_dac_read_mv(mp_obj_t self_in) { +static mp_obj_t machine_dac_read_mv(mp_obj_t self_in) { machine_dac_obj_t *self = MP_OBJ_TO_PTR(self_in); return MP_OBJ_NEW_SMALL_INT(self->mv); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_dac_read_mv_obj, machine_dac_read_mv); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_dac_read_mv_obj, machine_dac_read_mv); // MP_DEFINE_CONST_FUN_OBJ_2(mp_machine_dac_write_obj, mp_machine_dac_write); -STATIC const mp_rom_map_elem_t machine_dac_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_dac_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&machine_dac_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&machine_dac_read_obj) }, { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&machine_dac_write_obj) }, @@ -169,7 +169,7 @@ STATIC const mp_rom_map_elem_t machine_dac_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_write_mv), MP_ROM_PTR(&machine_dac_write_mv_obj) } }; -STATIC MP_DEFINE_CONST_DICT(machine_dac_locals_dict, machine_dac_locals_dict_table); +static MP_DEFINE_CONST_DICT(machine_dac_locals_dict, machine_dac_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( machine_dac_type, diff --git a/ports/renesas-ra/machine_i2c.c b/ports/renesas-ra/machine_i2c.c index dc14be9594116..63bc4a4ec41de 100644 --- a/ports/renesas-ra/machine_i2c.c +++ b/ports/renesas-ra/machine_i2c.c @@ -49,7 +49,7 @@ typedef struct _machine_i2c_obj_t { uint32_t freq; } machine_i2c_obj_t; -STATIC machine_i2c_obj_t machine_i2c_obj[] = { +static machine_i2c_obj_t machine_i2c_obj[] = { #if defined(MICROPY_HW_I2C0_SCL) {{&machine_i2c_type}, R_IIC0, 0, MICROPY_HW_I2C0_SCL, MICROPY_HW_I2C0_SDA, 0}, #endif @@ -61,10 +61,10 @@ STATIC machine_i2c_obj_t machine_i2c_obj[] = { #endif }; -STATIC int i2c_read(machine_i2c_obj_t *self, uint16_t addr, uint8_t *dest, size_t len, bool stop); -STATIC int i2c_write(machine_i2c_obj_t *self, uint16_t addr, const uint8_t *src, size_t len, bool stop); +static int i2c_read(machine_i2c_obj_t *self, uint16_t addr, uint8_t *dest, size_t len, bool stop); +static int i2c_write(machine_i2c_obj_t *self, uint16_t addr, const uint8_t *src, size_t len, bool stop); -STATIC int i2c_read(machine_i2c_obj_t *self, uint16_t addr, uint8_t *dest, size_t len, bool stop) { +static int i2c_read(machine_i2c_obj_t *self, uint16_t addr, uint8_t *dest, size_t len, bool stop) { bool flag; xaction_t action; xaction_unit_t unit; @@ -74,7 +74,7 @@ STATIC int i2c_read(machine_i2c_obj_t *self, uint16_t addr, uint8_t *dest, size_ return flag? len:-1; } -STATIC int i2c_write(machine_i2c_obj_t *self, uint16_t addr, const uint8_t *src, size_t len, bool stop) { +static int i2c_write(machine_i2c_obj_t *self, uint16_t addr, const uint8_t *src, size_t len, bool stop) { bool flag; xaction_t action; xaction_unit_t unit; @@ -86,18 +86,18 @@ STATIC int i2c_write(machine_i2c_obj_t *self, uint16_t addr, const uint8_t *src, // MicroPython bindings for machine API -STATIC void machine_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "I2C(%u, freq=%u, scl=%q, sda=%q)", self->i2c_id, self->freq, self->scl->name, self->sda->name); } -STATIC void machine_i2c_init(mp_obj_base_t *obj, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void machine_i2c_init(mp_obj_base_t *obj, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_raise_NotImplementedError(MP_ERROR_TEXT("init is not supported.")); return; } -STATIC mp_obj_t machine_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t machine_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // parse args enum { ARG_id, ARG_freq, ARG_scl, ARG_sda }; static const mp_arg_t allowed_args[] = { @@ -136,7 +136,7 @@ STATIC mp_obj_t machine_i2c_make_new(const mp_obj_type_t *type, size_t n_args, s return MP_OBJ_FROM_PTR(self); } -STATIC int machine_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, size_t len, uint8_t *buf, unsigned int flags) { +static int machine_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, size_t len, uint8_t *buf, unsigned int flags) { machine_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in); int ret; bool stop; @@ -149,7 +149,7 @@ STATIC int machine_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, si return ret; } -STATIC const mp_machine_i2c_p_t machine_i2c_p = { +static const mp_machine_i2c_p_t machine_i2c_p = { .init = machine_i2c_init, .transfer = mp_machine_i2c_transfer_adaptor, .transfer_single = machine_i2c_transfer_single, diff --git a/ports/renesas-ra/machine_pin.c b/ports/renesas-ra/machine_pin.c index e11188118c4bd..e8802b2e7a892 100644 --- a/ports/renesas-ra/machine_pin.c +++ b/ports/renesas-ra/machine_pin.c @@ -71,7 +71,7 @@ const machine_pin_obj_t *machine_pin_find(mp_obj_t user_obj) { } /// Return a string describing the pin object. -STATIC void machine_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); // pin name @@ -142,7 +142,7 @@ STATIC void machine_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_prin } // pin.init(mode=-1, pull=-1, *, value=None, drive=0, alt=-1) -STATIC mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_mode, ARG_pull, ARG_value, ARG_drive, ARG_alt }; static const mp_arg_t allowed_args[] = { { MP_QSTR_mode, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE}}, @@ -222,7 +222,7 @@ mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, } // fast method for getting/setting pin value -STATIC mp_obj_t machine_pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t machine_pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); if (n_args == 0) { @@ -236,35 +236,35 @@ STATIC mp_obj_t machine_pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, c } // pin.init(mode, pull) -STATIC mp_obj_t machine_pin_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t machine_pin_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { return machine_pin_obj_init_helper(args[0], n_args - 1, args + 1, kw_args); } MP_DEFINE_CONST_FUN_OBJ_KW(machine_pin_init_obj, 1, machine_pin_obj_init); // pin.value([value]) -STATIC mp_obj_t machine_pin_value(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_pin_value(size_t n_args, const mp_obj_t *args) { return machine_pin_call(args[0], n_args - 1, 0, args + 1); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pin_value_obj, 1, 2, machine_pin_value); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pin_value_obj, 1, 2, machine_pin_value); // pin.low() -STATIC mp_obj_t machine_pin_low(mp_obj_t self_in) { +static mp_obj_t machine_pin_low(mp_obj_t self_in) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_hal_pin_write(self, false); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_low_obj, machine_pin_low); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_low_obj, machine_pin_low); // pin.high() -STATIC mp_obj_t machine_pin_high(mp_obj_t self_in) { +static mp_obj_t machine_pin_high(mp_obj_t self_in) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_hal_pin_write(self, true); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_high_obj, machine_pin_high); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_high_obj, machine_pin_high); // pin.irq(handler=None, trigger=IRQ_FALLING|IRQ_RISING, hard=False) -STATIC mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_handler, ARG_trigger, ARG_hard }; static const mp_arg_t allowed_args[] = { { MP_QSTR_handler, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, @@ -288,9 +288,9 @@ STATIC mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_ // TODO should return an IRQ object return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_pin_irq_obj, 1, machine_pin_irq); +static MP_DEFINE_CONST_FUN_OBJ_KW(machine_pin_irq_obj, 1, machine_pin_irq); -STATIC const mp_rom_map_elem_t machine_pin_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_pin_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_pin_init_obj) }, { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&machine_pin_value_obj) }, @@ -323,9 +323,9 @@ STATIC const mp_rom_map_elem_t machine_pin_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_IRQ_LOW_LEVEL), MP_ROM_INT(MP_HAL_PIN_TRIGGER_LOWLEVEL) }, { MP_ROM_QSTR(MP_QSTR_IRQ_HIGH_LEVEL), MP_ROM_INT(MP_HAL_PIN_TRIGGER_HIGHLEVEL) }, }; -STATIC MP_DEFINE_CONST_DICT(machine_pin_locals_dict, machine_pin_locals_dict_table); +static MP_DEFINE_CONST_DICT(machine_pin_locals_dict, machine_pin_locals_dict_table); -STATIC mp_uint_t machine_pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t machine_pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { (void)errcode; machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); @@ -341,7 +341,7 @@ STATIC mp_uint_t machine_pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_ return -1; } -STATIC const mp_pin_p_t machine_pin_pin_p = { +static const mp_pin_p_t machine_pin_pin_p = { .ioctl = machine_pin_ioctl, }; diff --git a/ports/renesas-ra/machine_pwm.c b/ports/renesas-ra/machine_pwm.c index 69dc5bad59932..3044367a2e5a1 100644 --- a/ports/renesas-ra/machine_pwm.c +++ b/ports/renesas-ra/machine_pwm.c @@ -44,7 +44,7 @@ typedef struct _machine_pwm_obj_t { mp_hal_pin_obj_t pwm; } machine_pwm_obj_t; -STATIC machine_pwm_obj_t machine_pwm_obj[] = { +static machine_pwm_obj_t machine_pwm_obj[] = { #if defined(MICROPY_HW_PWM_0A) {{&machine_pwm_type}, R_GPT0, 0, 0, 'A', 0, 0ul, MICROPY_HW_PWM_0A}, #endif @@ -134,12 +134,12 @@ STATIC machine_pwm_obj_t machine_pwm_obj[] = { /******************************************************************************/ // MicroPython bindings for PWM -STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_pwm_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "PWM(GTIOC %d%c[#%d], active=%u, freq=%u, duty=%u)", self->ch, self->id, self->pwm->pin, self->active, self->freq, self->duty); } -STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { uint32_t D = 0ul; enum { ARG_freq, ARG_duty }; @@ -178,7 +178,7 @@ STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, c } } -STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_hal_pin_obj_t pin_id = MP_OBJ_NULL; machine_pwm_obj_t *self = MP_OBJ_NULL; @@ -223,7 +223,7 @@ STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args return MP_OBJ_FROM_PTR(self); } -STATIC void mp_machine_pwm_deinit(machine_pwm_obj_t *self) { +static void mp_machine_pwm_deinit(machine_pwm_obj_t *self) { ra_gpt_timer_deinit(self->pwm->pin, self->ch, self->id); self->active = 0; self->ch = 0; @@ -232,11 +232,11 @@ STATIC void mp_machine_pwm_deinit(machine_pwm_obj_t *self) { self->freq = 0; } -STATIC mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) { return MP_OBJ_NEW_SMALL_INT((uint32_t)ra_gpt_timer_get_freq(self->ch)); } -STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { +static void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { if (freq) { ra_gpt_timer_set_freq(self->ch, (float)freq); self->freq = (uint32_t)ra_gpt_timer_get_freq(self->ch); @@ -255,13 +255,13 @@ STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { } } -STATIC mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self) { // give the result in % uint64_t Dc = ra_gpt_timer_get_duty(self->ch, self->id) * 100; return MP_OBJ_NEW_SMALL_INT(Dc / ra_gpt_timer_get_period(self->ch)); } -STATIC void mp_machine_pwm_duty_set(machine_pwm_obj_t *self, mp_int_t duty) { +static void mp_machine_pwm_duty_set(machine_pwm_obj_t *self, mp_int_t duty) { // assume duty is in % if (duty < 0 || duty > 100) { mp_raise_ValueError(MP_ERROR_TEXT("duty should be 0-100")); @@ -286,13 +286,13 @@ STATIC void mp_machine_pwm_duty_set(machine_pwm_obj_t *self, mp_int_t duty) { } } -STATIC mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) { // give the result in ratio (u16 / 65535) uint64_t Dc = ra_gpt_timer_get_duty(self->ch, self->id) * 65535; return MP_OBJ_NEW_SMALL_INT(Dc / ra_gpt_timer_get_period(self->ch)); } -STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16) { +static void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16) { // assume duty is a ratio (u16 / 65535) if (duty_u16 < 0 || duty_u16 > 65535) { mp_raise_ValueError(MP_ERROR_TEXT("duty should be 0-65535")); @@ -317,14 +317,14 @@ STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u } } -STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { // give the result in ns float ns = ra_gpt_timer_tick_time(self->ch); ns *= (float)ra_gpt_timer_get_duty(self->ch, self->id); return MP_OBJ_NEW_SMALL_INT(ns); } -STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns) { +static void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns) { // assume duty is ns uint32_t ns_min = (uint32_t)ra_gpt_timer_tick_time(self->ch); uint32_t ns_max = ns_min * ra_gpt_timer_get_period(self->ch); diff --git a/ports/renesas-ra/machine_rtc.c b/ports/renesas-ra/machine_rtc.c index 6637ea44ccbd3..853b0e8fcbd75 100644 --- a/ports/renesas-ra/machine_rtc.c +++ b/ports/renesas-ra/machine_rtc.c @@ -62,11 +62,11 @@ // it's a bit of a hack at the moment static mp_uint_t rtc_info; -STATIC uint32_t rtc_startup_tick; -STATIC bool rtc_need_init_finalise = false; -STATIC uint32_t rtc_wakeup_param; +static uint32_t rtc_startup_tick; +static bool rtc_need_init_finalise = false; +static uint32_t rtc_wakeup_param; -STATIC void rtc_calendar_config(void) { +static void rtc_calendar_config(void) { ra_rtc_t tm; tm.year = RTC_INIT_YEAR - 2000; tm.month = RTC_INIT_MONTH; @@ -155,11 +155,11 @@ typedef struct _machine_rtc_obj_t { mp_obj_base_t base; } machine_rtc_obj_t; -STATIC const machine_rtc_obj_t machine_rtc_obj = {{&machine_rtc_type}}; +static const machine_rtc_obj_t machine_rtc_obj = {{&machine_rtc_type}}; /// \classmethod \constructor() /// Create an RTC object. -STATIC mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 0, 0, false); @@ -333,14 +333,14 @@ mp_obj_t machine_rtc_calibration(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_rtc_calibration_obj, 1, 2, machine_rtc_calibration); -STATIC const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_rtc_init_obj) }, { MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&machine_rtc_info_obj) }, { MP_ROM_QSTR(MP_QSTR_datetime), MP_ROM_PTR(&machine_rtc_datetime_obj) }, { MP_ROM_QSTR(MP_QSTR_wakeup), MP_ROM_PTR(&machine_rtc_wakeup_obj) }, { MP_ROM_QSTR(MP_QSTR_calibration), MP_ROM_PTR(&machine_rtc_calibration_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(machine_rtc_locals_dict, machine_rtc_locals_dict_table); +static MP_DEFINE_CONST_DICT(machine_rtc_locals_dict, machine_rtc_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( machine_rtc_type, diff --git a/ports/renesas-ra/machine_sdcard.c b/ports/renesas-ra/machine_sdcard.c index 2ed0d6653567a..ec3033a8a3451 100644 --- a/ports/renesas-ra/machine_sdcard.c +++ b/ports/renesas-ra/machine_sdcard.c @@ -47,7 +47,7 @@ typedef struct _machine_sdcard_obj_t { uint32_t block_count; } machine_sdcard_obj_t; -STATIC machine_sdcard_obj_t machine_sdcard_objs[] = { +static machine_sdcard_obj_t machine_sdcard_objs[] = { {{&machine_sdcard_type}, {false, false, false}, 0, 0} }; @@ -78,7 +78,7 @@ void sdhi_ISR(sdmmc_callback_args_t *p_args) { } } -STATIC mp_obj_t machine_sdcard_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_sdcard_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { fsp_err_t err = FSP_SUCCESS; machine_sdcard_obj_t *self = mp_const_none; @@ -117,9 +117,9 @@ STATIC mp_obj_t machine_sdcard_init(size_t n_args, const mp_obj_t *pos_args, mp_ return MP_OBJ_FROM_PTR(self); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_sdcard_init_obj, 1, machine_sdcard_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(machine_sdcard_init_obj, 1, machine_sdcard_init); -STATIC mp_obj_t sdcard_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t sdcard_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { mp_map_t kw_args; mp_arg_check_num(n_args, n_kw, 0, 0, true); @@ -128,17 +128,17 @@ STATIC mp_obj_t sdcard_obj_make_new(const mp_obj_type_t *type, size_t n_args, si } // deinit() -STATIC mp_obj_t machine_sdcard_deinit(mp_obj_t self_in) { +static mp_obj_t machine_sdcard_deinit(mp_obj_t self_in) { machine_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); R_SDHI_Close(&g_sdmmc0_ctrl); self->block_count = self->block_len = 0; self->status.card_inserted = self->status.initialized = self->status.transfer_in_progress = false; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_sdcard_deinit_obj, machine_sdcard_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_sdcard_deinit_obj, machine_sdcard_deinit); // present() -STATIC mp_obj_t machine_sdcard_present(mp_obj_t self_in) { +static mp_obj_t machine_sdcard_present(mp_obj_t self_in) { fsp_err_t err = FSP_SUCCESS; machine_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); if ((err = R_SDHI_StatusGet(&g_sdmmc0_ctrl, &self->status)) == FSP_SUCCESS) { @@ -147,9 +147,9 @@ STATIC mp_obj_t machine_sdcard_present(mp_obj_t self_in) { mp_raise_msg_varg(&mp_type_OSError, MP_ERROR_TEXT("can't get SDHI Status, %d"), err); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_sdcard_present_obj, machine_sdcard_present); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_sdcard_present_obj, machine_sdcard_present); -STATIC mp_obj_t machine_sdcard_info(mp_obj_t self_in) { +static mp_obj_t machine_sdcard_info(mp_obj_t self_in) { machine_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); if (self->status.card_inserted && self->status.initialized) { @@ -165,10 +165,10 @@ STATIC mp_obj_t machine_sdcard_info(mp_obj_t self_in) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_sdcard_info_obj, machine_sdcard_info); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_sdcard_info_obj, machine_sdcard_info); // readblocks(block_num, buf) -STATIC mp_obj_t machine_sdcard_readblocks(mp_obj_t self_in, mp_obj_t block_num, mp_obj_t buf) { +static mp_obj_t machine_sdcard_readblocks(mp_obj_t self_in, mp_obj_t block_num, mp_obj_t buf) { mp_buffer_info_t bufinfo; machine_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_WRITE); @@ -188,10 +188,10 @@ STATIC mp_obj_t machine_sdcard_readblocks(mp_obj_t self_in, mp_obj_t block_num, return MP_OBJ_NEW_SMALL_INT(-MP_EIO); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(machine_sdcard_readblocks_obj, machine_sdcard_readblocks); +static MP_DEFINE_CONST_FUN_OBJ_3(machine_sdcard_readblocks_obj, machine_sdcard_readblocks); // writeblocks(block_num, buf) -STATIC mp_obj_t machine_sdcard_writeblocks(mp_obj_t self_in, mp_obj_t block_num, mp_obj_t buf) { +static mp_obj_t machine_sdcard_writeblocks(mp_obj_t self_in, mp_obj_t block_num, mp_obj_t buf) { mp_buffer_info_t bufinfo; machine_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_WRITE); @@ -211,10 +211,10 @@ STATIC mp_obj_t machine_sdcard_writeblocks(mp_obj_t self_in, mp_obj_t block_num, return MP_OBJ_NEW_SMALL_INT(-MP_EIO); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(machine_sdcard_writeblocks_obj, machine_sdcard_writeblocks); +static MP_DEFINE_CONST_FUN_OBJ_3(machine_sdcard_writeblocks_obj, machine_sdcard_writeblocks); // ioctl(op, arg) -STATIC mp_obj_t machine_sdcard_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { +static mp_obj_t machine_sdcard_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { machine_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t cmd = mp_obj_get_int(cmd_in); @@ -313,9 +313,9 @@ STATIC mp_obj_t machine_sdcard_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t break; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(machine_sdcard_ioctl_obj, machine_sdcard_ioctl); +static MP_DEFINE_CONST_FUN_OBJ_3(machine_sdcard_ioctl_obj, machine_sdcard_ioctl); -STATIC const mp_rom_map_elem_t sdcard_locals_dict_table[] = { +static const mp_rom_map_elem_t sdcard_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_sdcard_init_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&machine_sdcard_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR_present), MP_ROM_PTR(&machine_sdcard_present_obj) }, @@ -325,7 +325,7 @@ STATIC const mp_rom_map_elem_t sdcard_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&machine_sdcard_writeblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&machine_sdcard_ioctl_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(sdcard_locals_dict, sdcard_locals_dict_table); +static MP_DEFINE_CONST_DICT(sdcard_locals_dict, sdcard_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( machine_sdcard_type, diff --git a/ports/renesas-ra/machine_spi.c b/ports/renesas-ra/machine_spi.c index 04505178dab57..06a5a8fc4f7c4 100644 --- a/ports/renesas-ra/machine_spi.c +++ b/ports/renesas-ra/machine_spi.c @@ -66,7 +66,7 @@ typedef struct _machine_hard_spi_obj_t { /******************************************************************************/ // Implementation of hard SPI for machine module -STATIC machine_hard_spi_obj_t machine_hard_spi_obj[] = { +static machine_hard_spi_obj_t machine_hard_spi_obj[] = { #if defined(MICROPY_HW_SPI0_RSPCK) { {&machine_spi_type}, 0, @@ -85,7 +85,7 @@ STATIC machine_hard_spi_obj_t machine_hard_spi_obj[] = { #endif }; -STATIC void spi_init(machine_hard_spi_obj_t *self) { +static void spi_init(machine_hard_spi_obj_t *self) { const machine_pin_obj_t *pins[4] = { NULL, NULL, NULL, NULL }; if (0) { @@ -126,7 +126,7 @@ STATIC void spi_init(machine_hard_spi_obj_t *self) { ra_spi_init(self->spi_id, pins[3]->pin, pins[2]->pin, pins[1]->pin, pins[0]->pin, self->baudrate, self->bits, self->polarity, self->phase, self->firstbit); } -STATIC void machine_hard_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_hard_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_hard_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "SPI(%u, baudrate=%u, polarity=%u, phase=%u, bits=%u, firstbit=%u, sck=%q, mosi=%q, miso=%q)", self->spi_id, self->baudrate, self->polarity, self->phase, self->bits, @@ -233,7 +233,7 @@ mp_obj_t machine_hard_spi_make_new(const mp_obj_type_t *type, size_t n_args, siz return MP_OBJ_FROM_PTR(self); } -STATIC void machine_hard_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void machine_hard_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { machine_hard_spi_obj_t *self = (machine_hard_spi_obj_t *)self_in; enum { ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits, ARG_firstbit, ARG_sck, ARG_mosi, ARG_miso }; @@ -315,17 +315,17 @@ STATIC void machine_hard_spi_init(mp_obj_base_t *self_in, size_t n_args, const m spi_init(self); } -STATIC void machine_hard_spi_deinit(mp_obj_base_t *self_in) { +static void machine_hard_spi_deinit(mp_obj_base_t *self_in) { machine_hard_spi_obj_t *self = (machine_hard_spi_obj_t *)self_in; spi_deinit(self->spi_id); } -STATIC void machine_hard_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) { +static void machine_hard_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) { machine_hard_spi_obj_t *self = (machine_hard_spi_obj_t *)self_in; spi_transfer(self->spi_id, self->bits, len, src, dest, SPI_TRANSFER_TIMEOUT(len)); } -STATIC const mp_machine_spi_p_t machine_hard_spi_p = { +static const mp_machine_spi_p_t machine_hard_spi_p = { .init = machine_hard_spi_init, .deinit = machine_hard_spi_deinit, .transfer = machine_hard_spi_transfer, diff --git a/ports/renesas-ra/machine_uart.c b/ports/renesas-ra/machine_uart.c index 6c520f941f870..26ed625404374 100644 --- a/ports/renesas-ra/machine_uart.c +++ b/ports/renesas-ra/machine_uart.c @@ -42,9 +42,9 @@ { MP_ROM_QSTR(MP_QSTR_RTS), MP_ROM_INT(UART_HWCONTROL_RTS) }, \ { MP_ROM_QSTR(MP_QSTR_CTS), MP_ROM_INT(UART_HWCONTROL_CTS) }, \ -STATIC const char *_parity_name[] = {"None", "ODD", "EVEN"}; +static const char *_parity_name[] = {"None", "ODD", "EVEN"}; -STATIC void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); if (!self->is_enabled) { mp_printf(print, "UART(%u)", self->uart_id); @@ -82,7 +82,7 @@ STATIC void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_ /// - `timeout_char` is the timeout in milliseconds to wait between characters. /// - `flow` is RTS | CTS where RTS == 256, CTS == 512 /// - `read_buf_len` is the character length of the read buffer (0 to disable). -STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_baudrate, MP_ARG_INT | MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_bits, MP_ARG_INT, {.u_int = 8} }, @@ -221,7 +221,7 @@ STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, /// - `UART(6)` is on `YA`: `(TX, RX) = (Y1, Y2) = (PC6, PC7)` /// - `UART(3)` is on `YB`: `(TX, RX) = (Y9, Y10) = (PB10, PB11)` /// - `UART(2)` is on: `(TX, RX) = (X3, X4) = (PA2, PA3)` -STATIC mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); @@ -306,27 +306,27 @@ STATIC mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_arg } // Turn off the UART bus. -STATIC void mp_machine_uart_deinit(machine_uart_obj_t *self) { +static void mp_machine_uart_deinit(machine_uart_obj_t *self) { uart_deinit(self); } // Return number of characters waiting. -STATIC mp_int_t mp_machine_uart_any(machine_uart_obj_t *self) { +static mp_int_t mp_machine_uart_any(machine_uart_obj_t *self) { return uart_rx_any(self); } // Return `true` if all characters have been sent. -STATIC bool mp_machine_uart_txdone(machine_uart_obj_t *self) { +static bool mp_machine_uart_txdone(machine_uart_obj_t *self) { return !uart_tx_busy(self); } // Send a break condition. -STATIC void mp_machine_uart_sendbreak(machine_uart_obj_t *self) { +static void mp_machine_uart_sendbreak(machine_uart_obj_t *self) { ra_sci_tx_break((uint32_t)self->uart_id); } // Write a single character on the bus. `data` is an integer to write. -STATIC void mp_machine_uart_writechar(machine_uart_obj_t *self, uint16_t data) { +static void mp_machine_uart_writechar(machine_uart_obj_t *self, uint16_t data) { int errcode; if (uart_tx_wait(self, self->timeout)) { uart_tx_data(self, &data, 1, &errcode); @@ -341,7 +341,7 @@ STATIC void mp_machine_uart_writechar(machine_uart_obj_t *self, uint16_t data) { // Receive a single character on the bus. // Return value: The character read, as an integer. Returns -1 on timeout. -STATIC mp_int_t mp_machine_uart_readchar(machine_uart_obj_t *self) { +static mp_int_t mp_machine_uart_readchar(machine_uart_obj_t *self) { if (uart_rx_wait(self, self->timeout)) { return uart_rx_char(self); } else { @@ -350,7 +350,7 @@ STATIC mp_int_t mp_machine_uart_readchar(machine_uart_obj_t *self) { } } -STATIC mp_irq_obj_t *mp_machine_uart_irq(machine_uart_obj_t *self, bool any_args, mp_arg_val_t *args) { +static mp_irq_obj_t *mp_machine_uart_irq(machine_uart_obj_t *self, bool any_args, mp_arg_val_t *args) { if (self->mp_irq_obj == NULL) { self->mp_irq_trigger = 0; self->mp_irq_obj = mp_irq_new(&uart_irq_methods, MP_OBJ_FROM_PTR(self)); @@ -381,7 +381,7 @@ STATIC mp_irq_obj_t *mp_machine_uart_irq(machine_uart_obj_t *self, bool any_args return self->mp_irq_obj; } -STATIC mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { +static mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); byte *buf = buf_in; @@ -423,7 +423,7 @@ STATIC mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t } } -STATIC mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { +static mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); const byte *buf = buf_in; @@ -452,7 +452,7 @@ STATIC mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_ } } -STATIC mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_uint_t ret; if (request == MP_STREAM_POLL) { diff --git a/ports/renesas-ra/main.c b/ports/renesas-ra/main.c index 5925606f9c770..febb7b6d7aaa3 100644 --- a/ports/renesas-ra/main.c +++ b/ports/renesas-ra/main.c @@ -77,15 +77,15 @@ #define RA_EARLY_PRINT 1 /* for enabling mp_print in boardctrl. */ #if MICROPY_PY_THREAD -STATIC pyb_thread_t pyb_thread_main; +static pyb_thread_t pyb_thread_main; #endif #if defined(MICROPY_HW_UART_REPL) #ifndef MICROPY_HW_UART_REPL_RXBUF #define MICROPY_HW_UART_REPL_RXBUF (260) #endif -STATIC machine_uart_obj_t machine_uart_repl_obj; -STATIC uint8_t machine_uart_repl_rxbuf[MICROPY_HW_UART_REPL_RXBUF]; +static machine_uart_obj_t machine_uart_repl_obj; +static uint8_t machine_uart_repl_rxbuf[MICROPY_HW_UART_REPL_RXBUF]; #endif void NORETURN __fatal_error(const char *msg) { @@ -126,7 +126,7 @@ void MP_WEAK __assert_func(const char *file, int line, const char *func, const c } #endif -STATIC mp_obj_t pyb_main(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_main(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_opt, MP_ARG_INT, {.u_int = 0} } }; @@ -147,7 +147,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(pyb_main_obj, 1, pyb_main); #if MICROPY_HW_FLASH_MOUNT_AT_BOOT // avoid inlining to avoid stack usage within main() -MP_NOINLINE STATIC bool init_flash_fs(uint reset_mode) { +MP_NOINLINE static bool init_flash_fs(uint reset_mode) { if (reset_mode == BOARDCTRL_RESET_MODE_FACTORY_FILESYSTEM) { // Asked by user to reset filesystem factory_reset_create_filesystem(); diff --git a/ports/renesas-ra/modmachine.c b/ports/renesas-ra/modmachine.c index 5bfbb919f44b4..dc38d809dd701 100644 --- a/ports/renesas-ra/modmachine.c +++ b/ports/renesas-ra/modmachine.c @@ -79,7 +79,7 @@ { MP_ROM_QSTR(MP_QSTR_DEEPSLEEP_RESET), MP_ROM_INT(PYB_RESET_DEEPSLEEP) }, \ { MP_ROM_QSTR(MP_QSTR_SOFT_RESET), MP_ROM_INT(PYB_RESET_SOFT) }, \ -STATIC uint32_t reset_cause; +static uint32_t reset_cause; void get_unique_id(uint8_t *id) { uint32_t *p = (uint32_t *)id; @@ -100,7 +100,7 @@ void machine_deinit(void) { // machine.info([dump_alloc_table]) // Print out lots of information about the board. -STATIC mp_obj_t machine_info(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_info(size_t n_args, const mp_obj_t *args) { // get and print unique id; 128 bits { uint8_t id[16]; @@ -177,14 +177,14 @@ STATIC mp_obj_t machine_info(size_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj, 0, 1, machine_info); // Returns a string of 16 bytes (128 bits), which is the unique ID for the MCU. -STATIC mp_obj_t mp_machine_unique_id(void) { +static mp_obj_t mp_machine_unique_id(void) { uint8_t id[16]; get_unique_id((uint8_t *)&id); return mp_obj_new_bytes(id, 16); } // Resets the pyboard in a manner similar to pushing the external RESET button. -NORETURN STATIC void mp_machine_reset(void) { +NORETURN static void mp_machine_reset(void) { powerctrl_mcu_reset(); } @@ -209,22 +209,22 @@ NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) { } // get or set the MCU frequencies -STATIC mp_obj_t mp_machine_get_freq(void) { +static mp_obj_t mp_machine_get_freq(void) { return mp_obj_new_int(SystemCoreClock); } -STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) { +static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) { mp_raise_NotImplementedError(MP_ERROR_TEXT("machine.freq set not supported yet")); } // idle() // This executies a wfi machine instruction which reduces power consumption // of the MCU until an interrupt occurs, at which point execution continues. -STATIC void mp_machine_idle(void) { +static void mp_machine_idle(void) { __WFI(); } -STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) { +static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) { if (n_args != 0) { mp_obj_t args2[2] = {MP_OBJ_NULL, args[0]}; machine_rtc_wakeup(2, args2); @@ -232,7 +232,7 @@ STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) { powerctrl_enter_stop_mode(); } -NORETURN STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) { +NORETURN static void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) { if (n_args != 0) { mp_obj_t args2[2] = {MP_OBJ_NULL, args[0]}; machine_rtc_wakeup(2, args2); @@ -240,6 +240,6 @@ NORETURN STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) { powerctrl_enter_standby_mode(); } -STATIC mp_int_t mp_machine_reset_cause(void) { +static mp_int_t mp_machine_reset_cause(void) { return reset_cause; } diff --git a/ports/renesas-ra/modos.c b/ports/renesas-ra/modos.c index 8fd11007eaff0..2051e9420f909 100644 --- a/ports/renesas-ra/modos.c +++ b/ports/renesas-ra/modos.c @@ -46,7 +46,7 @@ void mp_os_dupterm_stream_detached_attached(mp_obj_t stream_detached, mp_obj_t s } #if MICROPY_PY_OS_URANDOM -STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { +static mp_obj_t mp_os_urandom(mp_obj_t num) { mp_int_t n = mp_obj_get_int(num); vstr_t vstr; vstr_init_len(&vstr, n); @@ -55,5 +55,5 @@ STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { } return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); #endif diff --git a/ports/renesas-ra/modtime.c b/ports/renesas-ra/modtime.c index 1ab51e336deb8..cbd639721fc2a 100644 --- a/ports/renesas-ra/modtime.c +++ b/ports/renesas-ra/modtime.c @@ -29,7 +29,7 @@ #include "rtc.h" // Return the localtime as an 8-tuple. -STATIC mp_obj_t mp_time_localtime_get(void) { +static mp_obj_t mp_time_localtime_get(void) { // get current date and time rtc_init_finalise(); ra_rtc_t time; @@ -48,7 +48,7 @@ STATIC mp_obj_t mp_time_localtime_get(void) { } // Returns the number of seconds, as an integer, since the Epoch. -STATIC mp_obj_t mp_time_time_get(void) { +static mp_obj_t mp_time_time_get(void) { // get date and time rtc_init_finalise(); ra_rtc_t time; diff --git a/ports/renesas-ra/mpbthciport.c b/ports/renesas-ra/mpbthciport.c index 2e9f6d916698b..3fc7e8411f8ed 100644 --- a/ports/renesas-ra/mpbthciport.c +++ b/ports/renesas-ra/mpbthciport.c @@ -42,10 +42,10 @@ uint8_t mp_bluetooth_hci_cmd_buf[4 + 256]; -STATIC mp_sched_node_t mp_bluetooth_hci_sched_node; -STATIC soft_timer_entry_t mp_bluetooth_hci_soft_timer; +static mp_sched_node_t mp_bluetooth_hci_sched_node; +static soft_timer_entry_t mp_bluetooth_hci_soft_timer; -STATIC void mp_bluetooth_hci_soft_timer_callback(soft_timer_entry_t *self) { +static void mp_bluetooth_hci_soft_timer_callback(soft_timer_entry_t *self) { mp_bluetooth_hci_poll_now(); } @@ -58,7 +58,7 @@ void mp_bluetooth_hci_init(void) { ); } -STATIC void mp_bluetooth_hci_start_polling(void) { +static void mp_bluetooth_hci_start_polling(void) { mp_bluetooth_hci_poll_now(); } @@ -67,7 +67,7 @@ void mp_bluetooth_hci_poll_in_ms(uint32_t ms) { } // For synchronous mode, we run all BLE stack code inside a scheduled task. -STATIC void run_events_scheduled_task(mp_sched_node_t *node) { +static void run_events_scheduled_task(mp_sched_node_t *node) { // This will process all buffered HCI UART data, and run any callouts or events. mp_bluetooth_hci_poll(); } diff --git a/ports/renesas-ra/mphalport.c b/ports/renesas-ra/mphalport.c index 8a8bfd8dc7a77..7a5bcba2c9128 100644 --- a/ports/renesas-ra/mphalport.c +++ b/ports/renesas-ra/mphalport.c @@ -47,7 +47,7 @@ void flash_cache_commit(void); #define MICROPY_HW_STDIN_BUFFER_LEN 512 #endif -STATIC uint8_t stdin_ringbuf_array[MICROPY_HW_STDIN_BUFFER_LEN]; +static uint8_t stdin_ringbuf_array[MICROPY_HW_STDIN_BUFFER_LEN]; ringbuf_t stdin_ringbuf = { stdin_ringbuf_array, sizeof(stdin_ringbuf_array) }; #endif diff --git a/ports/renesas-ra/mpthreadport.c b/ports/renesas-ra/mpthreadport.c index a7d85cfe32987..621b4311bfc34 100644 --- a/ports/renesas-ra/mpthreadport.c +++ b/ports/renesas-ra/mpthreadport.c @@ -34,7 +34,7 @@ #if MICROPY_PY_THREAD // the mutex controls access to the linked list -STATIC mp_thread_mutex_t thread_mutex; +static mp_thread_mutex_t thread_mutex; void mp_thread_init(void) { mp_thread_mutex_init(&thread_mutex); diff --git a/ports/renesas-ra/pybthread.c b/ports/renesas-ra/pybthread.c index 603bc2e4ec090..cf3f4bc2e5ae7 100644 --- a/ports/renesas-ra/pybthread.c +++ b/ports/renesas-ra/pybthread.c @@ -88,7 +88,7 @@ void pyb_thread_deinit() { enable_irq(irq_state); } -STATIC void pyb_thread_terminate(void) { +static void pyb_thread_terminate(void) { uint32_t irq_state = disable_irq(); pyb_thread_t *thread = pyb_thread_cur; // take current thread off the run list diff --git a/ports/renesas-ra/ra_it.c b/ports/renesas-ra/ra_it.c index de5a4e8daa7cc..71a5a66967068 100644 --- a/ports/renesas-ra/ra_it.c +++ b/ports/renesas-ra/ra_it.c @@ -50,7 +50,7 @@ extern void __fatal_error(const char *); // More information about decoding the fault registers can be found here: // http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0646a/Cihdjcfc.html -STATIC char *fmt_hex(uint32_t val, char *buf) { +static char *fmt_hex(uint32_t val, char *buf) { const char *hexDig = "0123456789abcdef"; buf[0] = hexDig[(val >> 28) & 0x0f]; @@ -66,7 +66,7 @@ STATIC char *fmt_hex(uint32_t val, char *buf) { return buf; } -STATIC void print_reg(const char *label, uint32_t val) { +static void print_reg(const char *label, uint32_t val) { char hexStr[9]; mp_hal_stdout_tx_str(label); @@ -74,7 +74,7 @@ STATIC void print_reg(const char *label, uint32_t val) { mp_hal_stdout_tx_str("\r\n"); } -STATIC void print_hex_hex(const char *label, uint32_t val1, uint32_t val2) { +static void print_hex_hex(const char *label, uint32_t val1, uint32_t val2) { char hex_str[9]; mp_hal_stdout_tx_str(label); mp_hal_stdout_tx_str(fmt_hex(val1, hex_str)); diff --git a/ports/renesas-ra/storage.c b/ports/renesas-ra/storage.c index 18dff9780078c..12416e4dc7a9f 100644 --- a/ports/renesas-ra/storage.c +++ b/ports/renesas-ra/storage.c @@ -249,7 +249,7 @@ const pyb_flash_obj_t pyb_flash_obj = { 0, // actual size handled in ioctl, MP_BLOCKDEV_IOCTL_BLOCK_COUNT case }; -STATIC void pyb_flash_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void pyb_flash_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_flash_obj_t *self = MP_OBJ_TO_PTR(self_in); if (self == &pyb_flash_obj) { mp_printf(print, "Flash()"); @@ -258,7 +258,7 @@ STATIC void pyb_flash_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ } } -STATIC mp_obj_t pyb_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t pyb_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // Parse arguments enum { ARG_start, ARG_len }; static const mp_arg_t allowed_args[] = { @@ -297,7 +297,7 @@ STATIC mp_obj_t pyb_flash_make_new(const mp_obj_type_t *type, size_t n_args, siz return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t pyb_flash_readblocks(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_flash_readblocks(size_t n_args, const mp_obj_t *args) { pyb_flash_obj_t *self = MP_OBJ_TO_PTR(args[0]); uint32_t block_num = mp_obj_get_int(args[1]); mp_buffer_info_t bufinfo; @@ -318,9 +318,9 @@ STATIC mp_obj_t pyb_flash_readblocks(size_t n_args, const mp_obj_t *args) { #endif return MP_OBJ_NEW_SMALL_INT(ret); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_flash_readblocks_obj, 3, 4, pyb_flash_readblocks); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_flash_readblocks_obj, 3, 4, pyb_flash_readblocks); -STATIC mp_obj_t pyb_flash_writeblocks(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_flash_writeblocks(size_t n_args, const mp_obj_t *args) { pyb_flash_obj_t *self = MP_OBJ_TO_PTR(args[0]); uint32_t block_num = mp_obj_get_int(args[1]); mp_buffer_info_t bufinfo; @@ -341,9 +341,9 @@ STATIC mp_obj_t pyb_flash_writeblocks(size_t n_args, const mp_obj_t *args) { #endif return MP_OBJ_NEW_SMALL_INT(ret); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_flash_writeblocks_obj, 3, 4, pyb_flash_writeblocks); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_flash_writeblocks_obj, 3, 4, pyb_flash_writeblocks); -STATIC mp_obj_t pyb_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { +static mp_obj_t pyb_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { pyb_flash_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t cmd = mp_obj_get_int(cmd_in); switch (cmd) { @@ -390,15 +390,15 @@ STATIC mp_obj_t pyb_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_ return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_ioctl_obj, pyb_flash_ioctl); +static MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_ioctl_obj, pyb_flash_ioctl); -STATIC const mp_rom_map_elem_t pyb_flash_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_flash_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&pyb_flash_readblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&pyb_flash_writeblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&pyb_flash_ioctl_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_flash_locals_dict, pyb_flash_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_flash_locals_dict, pyb_flash_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pyb_flash_type, diff --git a/ports/renesas-ra/timer.c b/ports/renesas-ra/timer.c index 1b32bc1eee29e..d264ab0612989 100644 --- a/ports/renesas-ra/timer.c +++ b/ports/renesas-ra/timer.c @@ -37,7 +37,7 @@ #define TIMER_SIZE 2 void timer_irq_handler(void *param); -STATIC mp_obj_t pyb_timer_freq(size_t n_args, const mp_obj_t *args); +static mp_obj_t pyb_timer_freq(size_t n_args, const mp_obj_t *args); #if defined(TIMER_CHANNEL) typedef struct _pyb_timer_channel_obj_t { @@ -59,10 +59,10 @@ typedef struct _pyb_timer_obj_t { } pyb_timer_obj_t; #define PYB_TIMER_OBJ_ALL_NUM MP_ARRAY_SIZE(MP_STATE_PORT(pyb_timer_obj_all)) -STATIC mp_obj_t pyb_timer_deinit(mp_obj_t self_in); -STATIC mp_obj_t pyb_timer_callback(mp_obj_t self_in, mp_obj_t callback); +static mp_obj_t pyb_timer_deinit(mp_obj_t self_in); +static mp_obj_t pyb_timer_callback(mp_obj_t self_in, mp_obj_t callback); #if defined(TIMER_CHANNEL) -STATIC mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback); +static mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback); #endif static const int ra_agt_timer_ch[TIMER_SIZE] = {1, 2}; @@ -86,7 +86,7 @@ void timer_deinit(void) { * Timer Class */ -STATIC void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_timer_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "Timer(%u)", self->tim_id); } @@ -106,7 +106,7 @@ STATIC void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ /// - `callback` - as per Timer.callback() ////// /// You must either specify freq. -STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // enum { ARG_freq, ARG_prescaler, ARG_period, ARG_tick_hz, ARG_mode, ARG_div, ARG_callback, ARG_deadtime }; enum { ARG_freq, ARG_callback }; static const mp_arg_t allowed_args[] = { @@ -145,7 +145,7 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, size_t n_args, cons /// Construct a new timer object of the given id. If additional /// arguments are given, then the timer is initialised by `init(...)`. /// `id` can be 1 to 14, excluding 3. -STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); @@ -174,10 +174,10 @@ STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, siz return MP_OBJ_FROM_PTR(tim); } -STATIC mp_obj_t pyb_timer_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t pyb_timer_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { return pyb_timer_init_helper(MP_OBJ_TO_PTR(args[0]), n_args - 1, args + 1, kw_args); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_init_obj, 1, pyb_timer_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_init_obj, 1, pyb_timer_init); /// \method deinit() /// Deinitialises the timer. @@ -185,7 +185,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_init_obj, 1, pyb_timer_init); /// Disables the callback (and the associated irq). /// Disables any channel callbacks (and the associated irq). /// Stops the timer, and disables the timer peripheral. -STATIC mp_obj_t pyb_timer_deinit(mp_obj_t self_in) { +static mp_obj_t pyb_timer_deinit(mp_obj_t self_in) { pyb_timer_obj_t *self = MP_OBJ_TO_PTR(self_in); // Disable the base interrupt @@ -207,7 +207,7 @@ STATIC mp_obj_t pyb_timer_deinit(mp_obj_t self_in) { ra_agt_timer_deinit(self->tim_id - 1); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj, pyb_timer_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj, pyb_timer_deinit); #if defined(TIMER_CHANNEL) /// \method channel(channel, mode, ...) @@ -221,7 +221,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj, pyb_timer_deinit); /// input capture. All channels share the same underlying timer, which means /// that they share the same timer clock. /// -STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_callback, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, { MP_QSTR_compare, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, @@ -294,14 +294,14 @@ STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_ma // ToDo return MP_OBJ_FROM_PTR(chan); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_channel_obj, 2, pyb_timer_channel); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_channel_obj, 2, pyb_timer_channel); #endif #if TIMER_COUNTER // Not implemented /// \method counter([value]) /// Get or set the timer counter. -STATIC mp_obj_t pyb_timer_counter(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_timer_counter(size_t n_args, const mp_obj_t *args) { pyb_timer_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 1) { // get @@ -312,12 +312,12 @@ STATIC mp_obj_t pyb_timer_counter(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_counter_obj, 1, 2, pyb_timer_counter); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_counter_obj, 1, 2, pyb_timer_counter); #endif /// \method freq([value]) /// Get or set the frequency for the timer (changes prescaler and period if set). -STATIC mp_obj_t pyb_timer_freq(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_timer_freq(size_t n_args, const mp_obj_t *args) { pyb_timer_obj_t *self = MP_OBJ_TO_PTR(args[0]); int ch = self->tim_id - 1; if (n_args == 1) { @@ -349,13 +349,13 @@ STATIC mp_obj_t pyb_timer_freq(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_freq_obj, 1, 2, pyb_timer_freq); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_freq_obj, 1, 2, pyb_timer_freq); #if TIMER_PERIOD // Not implemented /// \method period([value]) /// Get or set the period of the timer. -STATIC mp_obj_t pyb_timer_period(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_timer_period(size_t n_args, const mp_obj_t *args) { pyb_timer_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 1) { // get @@ -367,14 +367,14 @@ STATIC mp_obj_t pyb_timer_period(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_period_obj, 1, 2, pyb_timer_period); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_period_obj, 1, 2, pyb_timer_period); #endif /// \method callback(fun) /// Set the function to be called when the timer triggers. /// `fun` is passed 1 argument, the timer object. /// If `fun` is `None` then the callback will be disabled. -STATIC mp_obj_t pyb_timer_callback(mp_obj_t self_in, mp_obj_t callback) { +static mp_obj_t pyb_timer_callback(mp_obj_t self_in, mp_obj_t callback) { pyb_timer_obj_t *self = MP_OBJ_TO_PTR(self_in); if (callback == mp_const_none) { // stop interrupt (but not timer) @@ -393,9 +393,9 @@ STATIC mp_obj_t pyb_timer_callback(mp_obj_t self_in, mp_obj_t callback) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_timer_callback_obj, pyb_timer_callback); +static MP_DEFINE_CONST_FUN_OBJ_2(pyb_timer_callback_obj, pyb_timer_callback); -STATIC const mp_rom_map_elem_t pyb_timer_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_timer_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_timer_init_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_timer_deinit_obj) }, @@ -408,7 +408,7 @@ STATIC const mp_rom_map_elem_t pyb_timer_locals_dict_table[] = { #endif { MP_ROM_QSTR(MP_QSTR_callback), MP_ROM_PTR(&pyb_timer_callback_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_timer_locals_dict, pyb_timer_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_timer_locals_dict, pyb_timer_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pyb_timer_type, @@ -430,7 +430,7 @@ MP_DEFINE_CONST_OBJ_TYPE( /// Timer channels are used to generate/capture a signal using a timer. /// /// TimerChannel objects are created using the Timer.channel() method. -STATIC void pyb_timer_channel_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void pyb_timer_channel_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_timer_channel_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "TimerChannel(timer=%u, channel=%u", @@ -455,7 +455,7 @@ STATIC void pyb_timer_channel_print(const mp_print_t *print, mp_obj_t self_in, m /// /// In edge aligned mode, a pulse_width of `period + 1` corresponds to a duty cycle of 100% /// In center aligned mode, a pulse width of `period` corresponds to a duty cycle of 100% -STATIC mp_obj_t pyb_timer_channel_capture_compare(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_timer_channel_capture_compare(size_t n_args, const mp_obj_t *args) { pyb_timer_channel_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 1) { // get @@ -466,13 +466,13 @@ STATIC mp_obj_t pyb_timer_channel_capture_compare(size_t n_args, const mp_obj_t return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_capture_compare_obj, 1, 2, pyb_timer_channel_capture_compare); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_capture_compare_obj, 1, 2, pyb_timer_channel_capture_compare); /// \method callback(fun) /// Set the function to be called when the timer channel triggers. /// `fun` is passed 1 argument, the timer object. /// If `fun` is `None` then the callback will be disabled. -STATIC mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback) { +static mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback) { pyb_timer_channel_obj_t *self = MP_OBJ_TO_PTR(self_in); if (callback == mp_const_none) { // stop interrupt (but not timer) @@ -493,17 +493,17 @@ STATIC mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback) } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_timer_channel_callback_obj, pyb_timer_channel_callback); +static MP_DEFINE_CONST_FUN_OBJ_2(pyb_timer_channel_callback_obj, pyb_timer_channel_callback); -STATIC const mp_rom_map_elem_t pyb_timer_channel_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_timer_channel_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_callback), MP_ROM_PTR(&pyb_timer_channel_callback_obj) }, { MP_ROM_QSTR(MP_QSTR_capture), MP_ROM_PTR(&pyb_timer_channel_capture_compare_obj) }, { MP_ROM_QSTR(MP_QSTR_compare), MP_ROM_PTR(&pyb_timer_channel_capture_compare_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_timer_channel_locals_dict, pyb_timer_channel_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_timer_channel_locals_dict, pyb_timer_channel_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( pyb_timer_channel_type, MP_QSTR_TimerChannel, MP_TYPE_FLAG_NONE, @@ -512,7 +512,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); #endif -STATIC void timer_handle_irq_channel(pyb_timer_obj_t *tim, uint8_t channel, mp_obj_t callback) { +static void timer_handle_irq_channel(pyb_timer_obj_t *tim, uint8_t channel, mp_obj_t callback) { // execute callback if it's set if (callback != mp_const_none) { diff --git a/ports/renesas-ra/uart.c b/ports/renesas-ra/uart.c index 47c793e7d3b29..30707552b3efb 100644 --- a/ports/renesas-ra/uart.c +++ b/ports/renesas-ra/uart.c @@ -506,7 +506,7 @@ void uart_tx_strn(machine_uart_obj_t *uart_obj, const char *str, uint len) { uart_tx_data(uart_obj, str, len, &errcode); } -STATIC mp_uint_t uart_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { +static mp_uint_t uart_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); uart_irq_config(self, false); self->mp_irq_trigger = new_trigger; @@ -514,7 +514,7 @@ STATIC mp_uint_t uart_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { return 0; } -STATIC mp_uint_t uart_irq_info(mp_obj_t self_in, mp_uint_t info_type) { +static mp_uint_t uart_irq_info(mp_obj_t self_in, mp_uint_t info_type) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); if (info_type == MP_IRQ_INFO_FLAGS) { return self->mp_irq_flags; diff --git a/ports/renesas-ra/usrsw.c b/ports/renesas-ra/usrsw.c index edbe519683013..746c7714a6232 100644 --- a/ports/renesas-ra/usrsw.c +++ b/ports/renesas-ra/usrsw.c @@ -69,7 +69,7 @@ typedef struct _pyb_switch_obj_t { mp_obj_base_t base; } pyb_switch_obj_t; -STATIC const pyb_switch_obj_t pyb_switch_obj = {{&pyb_switch_type}}; +static const pyb_switch_obj_t pyb_switch_obj = {{&pyb_switch_type}}; void pyb_switch_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { mp_print_str(print, "Switch()"); @@ -77,7 +77,7 @@ void pyb_switch_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t /// \classmethod \constructor() /// Create and return a switch object. -STATIC mp_obj_t pyb_switch_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pyb_switch_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 0, 0, false); @@ -101,15 +101,15 @@ mp_obj_t pyb_switch_value(mp_obj_t self_in) { (void)self_in; return mp_obj_new_bool(switch_get()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_switch_value_obj, pyb_switch_value); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_switch_value_obj, pyb_switch_value); -STATIC mp_obj_t switch_callback(mp_obj_t line) { +static mp_obj_t switch_callback(mp_obj_t line) { if (MP_STATE_PORT(pyb_switch_callback) != mp_const_none) { mp_call_function_0(MP_STATE_PORT(pyb_switch_callback)); } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(switch_callback_obj, switch_callback); +static MP_DEFINE_CONST_FUN_OBJ_1(switch_callback_obj, switch_callback); /// \method callback(fun) /// Register the given function to be called when the switch is pressed down. @@ -126,14 +126,14 @@ mp_obj_t pyb_switch_callback(mp_obj_t self_in, mp_obj_t callback) { true); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_switch_callback_obj, pyb_switch_callback); +static MP_DEFINE_CONST_FUN_OBJ_2(pyb_switch_callback_obj, pyb_switch_callback); -STATIC const mp_rom_map_elem_t pyb_switch_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_switch_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&pyb_switch_value_obj) }, { MP_ROM_QSTR(MP_QSTR_callback), MP_ROM_PTR(&pyb_switch_callback_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_switch_locals_dict, pyb_switch_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_switch_locals_dict, pyb_switch_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pyb_switch_type, diff --git a/ports/rp2/machine_adc.c b/ports/rp2/machine_adc.c index 3a7a71a741124..e5a428563d1ce 100644 --- a/ports/rp2/machine_adc.c +++ b/ports/rp2/machine_adc.c @@ -35,7 +35,7 @@ #define ADC_CHANNEL_FROM_GPIO(gpio) ((gpio) - 26) #define ADC_CHANNEL_TEMPSENSOR (4) -STATIC uint16_t adc_config_and_read_u16(uint32_t channel) { +static uint16_t adc_config_and_read_u16(uint32_t channel) { adc_select_input(channel); uint32_t raw = adc_read(); const uint32_t bits = 12; @@ -57,13 +57,13 @@ typedef struct _machine_adc_obj_t { #endif } machine_adc_obj_t; -STATIC void mp_machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_adc_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", self->channel); } // ADC(id) -STATIC mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // Check number of arguments mp_arg_check_num(n_args, n_kw, 1, 1, false); @@ -132,7 +132,7 @@ STATIC mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args } // read_u16() -STATIC mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) { +static mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) { #if MICROPY_HW_ADC_EXT_COUNT if (self->is_ext) { return machine_pin_ext_read_u16(self->channel); diff --git a/ports/rp2/machine_i2c.c b/ports/rp2/machine_i2c.c index 9bea4be2caf57..28032e8085c24 100644 --- a/ports/rp2/machine_i2c.c +++ b/ports/rp2/machine_i2c.c @@ -83,12 +83,12 @@ typedef struct _machine_i2c_obj_t { uint32_t timeout; } machine_i2c_obj_t; -STATIC machine_i2c_obj_t machine_i2c_obj[] = { +static machine_i2c_obj_t machine_i2c_obj[] = { {{&machine_i2c_type}, i2c0, 0, MICROPY_HW_I2C0_SCL, MICROPY_HW_I2C0_SDA, 0}, {{&machine_i2c_type}, i2c1, 1, MICROPY_HW_I2C1_SCL, MICROPY_HW_I2C1_SDA, 0}, }; -STATIC void machine_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "I2C(%u, freq=%u, scl=%u, sda=%u, timeout=%u)", self->i2c_id, self->freq, self->scl, self->sda, self->timeout); @@ -148,7 +148,7 @@ mp_obj_t machine_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n return MP_OBJ_FROM_PTR(self); } -STATIC int machine_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, size_t len, uint8_t *buf, unsigned int flags) { +static int machine_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, size_t len, uint8_t *buf, unsigned int flags) { machine_i2c_obj_t *self = (machine_i2c_obj_t *)self_in; int ret; bool nostop = !(flags & MP_MACHINE_I2C_FLAG_STOP); @@ -189,7 +189,7 @@ STATIC int machine_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, si } } -STATIC const mp_machine_i2c_p_t machine_i2c_p = { +static const mp_machine_i2c_p_t machine_i2c_p = { .transfer = mp_machine_i2c_transfer_adaptor, .transfer_single = machine_i2c_transfer_single, }; diff --git a/ports/rp2/machine_i2s.c b/ports/rp2/machine_i2s.c index ae8026a4af662..47eb5350a6439 100644 --- a/ports/rp2/machine_i2s.c +++ b/ports/rp2/machine_i2s.c @@ -97,14 +97,14 @@ typedef struct _machine_i2s_obj_t { // The frame map is used with the readinto() method to transform the audio sample data coming // from DMA memory (32-bit stereo) to the format specified // in the I2S constructor. e.g. 16-bit mono -STATIC const int8_t i2s_frame_map[NUM_I2S_USER_FORMATS][I2S_RX_FRAME_SIZE_IN_BYTES] = { +static const int8_t i2s_frame_map[NUM_I2S_USER_FORMATS][I2S_RX_FRAME_SIZE_IN_BYTES] = { {-1, -1, 0, 1, -1, -1, -1, -1 }, // Mono, 16-bits { 0, 1, 2, 3, -1, -1, -1, -1 }, // Mono, 32-bits {-1, -1, 0, 1, -1, -1, 2, 3 }, // Stereo, 16-bits { 0, 1, 2, 3, 4, 5, 6, 7 }, // Stereo, 32-bits }; -STATIC const PIO pio_instances[NUM_PIOS] = {pio0, pio1}; +static const PIO pio_instances[NUM_PIOS] = {pio0, pio1}; // PIO program for 16-bit write // set(x, 14) .side(0b01) @@ -117,8 +117,8 @@ STATIC const PIO pio_instances[NUM_PIOS] = {pio0, pio1}; // out(pins, 1) .side(0b10) // jmp(x_dec, "right_channel") .side(0b11) // out(pins, 1) .side(0b00) -STATIC const uint16_t pio_instructions_write_16[] = {59438, 24577, 2113, 28673, 63534, 28673, 6213, 24577}; -STATIC const pio_program_t pio_write_16 = { +static const uint16_t pio_instructions_write_16[] = {59438, 24577, 2113, 28673, 63534, 28673, 6213, 24577}; +static const pio_program_t pio_write_16 = { pio_instructions_write_16, sizeof(pio_instructions_write_16) / sizeof(uint16_t), -1 @@ -135,8 +135,8 @@ STATIC const pio_program_t pio_write_16 = { // out(pins, 1) .side(0b10) // jmp(x_dec, "right_channel") .side(0b11) // out(pins, 1) .side(0b00) -STATIC const uint16_t pio_instructions_write_32[] = {59454, 24577, 2113, 28673, 63550, 28673, 6213, 24577}; -STATIC const pio_program_t pio_write_32 = { +static const uint16_t pio_instructions_write_32[] = {59454, 24577, 2113, 28673, 63550, 28673, 6213, 24577}; +static const pio_program_t pio_write_32 = { pio_instructions_write_32, sizeof(pio_instructions_write_32) / sizeof(uint16_t), -1 @@ -153,17 +153,17 @@ STATIC const pio_program_t pio_write_32 = { // in_(pins, 1) .side(0b11) // jmp(x_dec, "right_channel") .side(0b10) // in_(pins, 1) .side(0b01) -STATIC const uint16_t pio_instructions_read_32[] = {57406, 18433, 65, 22529, 61502, 22529, 4165, 18433}; -STATIC const pio_program_t pio_read_32 = { +static const uint16_t pio_instructions_read_32[] = {57406, 18433, 65, 22529, 61502, 22529, 4165, 18433}; +static const pio_program_t pio_read_32 = { pio_instructions_read_32, sizeof(pio_instructions_read_32) / sizeof(uint16_t), -1 }; -STATIC uint8_t dma_get_bits(i2s_mode_t mode, int8_t bits); -STATIC void dma_irq0_handler(void); -STATIC void dma_irq1_handler(void); -STATIC mp_obj_t machine_i2s_deinit(mp_obj_t self_in); +static uint8_t dma_get_bits(i2s_mode_t mode, int8_t bits); +static void dma_irq0_handler(void); +static void dma_irq1_handler(void); +static mp_obj_t machine_i2s_deinit(mp_obj_t self_in); void machine_i2s_init0(void) { for (uint8_t i = 0; i < MAX_I2S_RP2; i++) { @@ -171,7 +171,7 @@ void machine_i2s_init0(void) { } } -STATIC int8_t get_frame_mapping_index(int8_t bits, format_t format) { +static int8_t get_frame_mapping_index(int8_t bits, format_t format) { if (format == MONO) { if (bits == 16) { return 0; @@ -188,7 +188,7 @@ STATIC int8_t get_frame_mapping_index(int8_t bits, format_t format) { } // function is used in IRQ context -STATIC void empty_dma(machine_i2s_obj_t *self, uint8_t *dma_buffer_p) { +static void empty_dma(machine_i2s_obj_t *self, uint8_t *dma_buffer_p) { // when space exists, copy samples into ring buffer if (ringbuf_available_space(&self->ring_buffer) >= SIZEOF_HALF_DMA_BUFFER_IN_BYTES) { for (uint32_t i = 0; i < SIZEOF_HALF_DMA_BUFFER_IN_BYTES; i++) { @@ -198,7 +198,7 @@ STATIC void empty_dma(machine_i2s_obj_t *self, uint8_t *dma_buffer_p) { } // function is used in IRQ context -STATIC void feed_dma(machine_i2s_obj_t *self, uint8_t *dma_buffer_p) { +static void feed_dma(machine_i2s_obj_t *self, uint8_t *dma_buffer_p) { // when data exists, copy samples from ring buffer if (ringbuf_available_data(&self->ring_buffer) >= SIZEOF_HALF_DMA_BUFFER_IN_BYTES) { @@ -230,7 +230,7 @@ STATIC void feed_dma(machine_i2s_obj_t *self, uint8_t *dma_buffer_p) { } } -STATIC void irq_configure(machine_i2s_obj_t *self) { +static void irq_configure(machine_i2s_obj_t *self) { if (self->i2s_id == 0) { irq_add_shared_handler(DMA_IRQ_0, dma_irq0_handler, PICO_SHARED_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY); irq_set_enabled(DMA_IRQ_0, true); @@ -240,7 +240,7 @@ STATIC void irq_configure(machine_i2s_obj_t *self) { } } -STATIC void irq_deinit(machine_i2s_obj_t *self) { +static void irq_deinit(machine_i2s_obj_t *self) { if (self->i2s_id == 0) { irq_remove_handler(DMA_IRQ_0, dma_irq0_handler); } else { @@ -248,7 +248,7 @@ STATIC void irq_deinit(machine_i2s_obj_t *self) { } } -STATIC void pio_configure(machine_i2s_obj_t *self) { +static void pio_configure(machine_i2s_obj_t *self) { if (self->mode == TX) { if (self->bits == 16) { self->pio_program = &pio_write_16; @@ -322,7 +322,7 @@ STATIC void pio_configure(machine_i2s_obj_t *self) { pio_sm_set_config(self->pio, self->sm, &config); } -STATIC void pio_deinit(machine_i2s_obj_t *self) { +static void pio_deinit(machine_i2s_obj_t *self) { if (self->pio) { pio_sm_set_enabled(self->pio, self->sm, false); pio_sm_unclaim(self->pio, self->sm); @@ -330,14 +330,14 @@ STATIC void pio_deinit(machine_i2s_obj_t *self) { } } -STATIC void gpio_init_i2s(PIO pio, uint8_t sm, mp_hal_pin_obj_t pin_num, uint8_t pin_val, gpio_dir_t pin_dir) { +static void gpio_init_i2s(PIO pio, uint8_t sm, mp_hal_pin_obj_t pin_num, uint8_t pin_val, gpio_dir_t pin_dir) { uint32_t pinmask = 1 << pin_num; pio_sm_set_pins_with_mask(pio, sm, pin_val << pin_num, pinmask); pio_sm_set_pindirs_with_mask(pio, sm, pin_dir << pin_num, pinmask); pio_gpio_init(pio, pin_num); } -STATIC void gpio_configure(machine_i2s_obj_t *self) { +static void gpio_configure(machine_i2s_obj_t *self) { gpio_init_i2s(self->pio, self->sm, self->sck, 0, GP_OUTPUT); gpio_init_i2s(self->pio, self->sm, self->ws, 0, GP_OUTPUT); if (self->mode == TX) { @@ -347,7 +347,7 @@ STATIC void gpio_configure(machine_i2s_obj_t *self) { } } -STATIC uint8_t dma_get_bits(i2s_mode_t mode, int8_t bits) { +static uint8_t dma_get_bits(i2s_mode_t mode, int8_t bits) { if (mode == TX) { return bits; } else { // RX @@ -357,7 +357,7 @@ STATIC uint8_t dma_get_bits(i2s_mode_t mode, int8_t bits) { } // determine which DMA channel is associated to this IRQ -STATIC uint dma_map_irq_to_channel(uint irq_index) { +static uint dma_map_irq_to_channel(uint irq_index) { for (uint ch = 0; ch < NUM_DMA_CHANNELS; ch++) { if ((dma_irqn_get_channel_status(irq_index, ch))) { return ch; @@ -368,7 +368,7 @@ STATIC uint dma_map_irq_to_channel(uint irq_index) { } // note: first DMA channel is mapped to the top half of buffer, second is mapped to the bottom half -STATIC uint8_t *dma_get_buffer(machine_i2s_obj_t *i2s_obj, uint channel) { +static uint8_t *dma_get_buffer(machine_i2s_obj_t *i2s_obj, uint channel) { for (uint8_t ch = 0; ch < I2S_NUM_DMA_CHANNELS; ch++) { if (i2s_obj->dma_channel[ch] == channel) { return i2s_obj->dma_buffer + (SIZEOF_HALF_DMA_BUFFER_IN_BYTES * ch); @@ -378,7 +378,7 @@ STATIC uint8_t *dma_get_buffer(machine_i2s_obj_t *i2s_obj, uint channel) { return NULL; } -STATIC void dma_configure(machine_i2s_obj_t *self) { +static void dma_configure(machine_i2s_obj_t *self) { uint8_t num_free_dma_channels = 0; for (uint8_t ch = 0; ch < NUM_DMA_CHANNELS; ch++) { if (!dma_channel_is_claimed(ch)) { @@ -433,7 +433,7 @@ STATIC void dma_configure(machine_i2s_obj_t *self) { } } -STATIC void dma_deinit(machine_i2s_obj_t *self) { +static void dma_deinit(machine_i2s_obj_t *self) { for (uint8_t ch = 0; ch < I2S_NUM_DMA_CHANNELS; ch++) { int channel = self->dma_channel[ch]; @@ -448,7 +448,7 @@ STATIC void dma_deinit(machine_i2s_obj_t *self) { } } -STATIC void dma_irq_handler(uint8_t irq_index) { +static void dma_irq_handler(uint8_t irq_index) { int dma_channel = dma_map_irq_to_channel(irq_index); if (dma_channel == -1) { // This should never happen @@ -488,15 +488,15 @@ STATIC void dma_irq_handler(uint8_t irq_index) { } } -STATIC void dma_irq0_handler(void) { +static void dma_irq0_handler(void) { dma_irq_handler(0); } -STATIC void dma_irq1_handler(void) { +static void dma_irq1_handler(void) { dma_irq_handler(1); } -STATIC void mp_machine_i2s_init_helper(machine_i2s_obj_t *self, mp_arg_val_t *args) { +static void mp_machine_i2s_init_helper(machine_i2s_obj_t *self, mp_arg_val_t *args) { // are Pins valid? mp_hal_pin_obj_t sck = args[ARG_sck].u_obj == MP_OBJ_NULL ? -1 : mp_hal_get_pin_obj(args[ARG_sck].u_obj); mp_hal_pin_obj_t ws = args[ARG_ws].u_obj == MP_OBJ_NULL ? -1 : mp_hal_get_pin_obj(args[ARG_ws].u_obj); @@ -563,7 +563,7 @@ STATIC void mp_machine_i2s_init_helper(machine_i2s_obj_t *self, mp_arg_val_t *ar dma_channel_start(self->dma_channel[0]); } -STATIC machine_i2s_obj_t *mp_machine_i2s_make_new_instance(mp_int_t i2s_id) { +static machine_i2s_obj_t *mp_machine_i2s_make_new_instance(mp_int_t i2s_id) { if (i2s_id >= MAX_I2S_RP2) { mp_raise_ValueError(MP_ERROR_TEXT("invalid id")); } @@ -581,7 +581,7 @@ STATIC machine_i2s_obj_t *mp_machine_i2s_make_new_instance(mp_int_t i2s_id) { return self; } -STATIC void mp_machine_i2s_deinit(machine_i2s_obj_t *self) { +static void mp_machine_i2s_deinit(machine_i2s_obj_t *self) { // use self->pio as in indication that I2S object has already been de-initialized if (self->pio != NULL) { pio_deinit(self); @@ -592,7 +592,7 @@ STATIC void mp_machine_i2s_deinit(machine_i2s_obj_t *self) { } } -STATIC void mp_machine_i2s_irq_update(machine_i2s_obj_t *self) { +static void mp_machine_i2s_irq_update(machine_i2s_obj_t *self) { (void)self; } diff --git a/ports/rp2/machine_pin.c b/ports/rp2/machine_pin.c index b277a939e5abe..de217785690c2 100644 --- a/ports/rp2/machine_pin.c +++ b/ports/rp2/machine_pin.c @@ -85,21 +85,21 @@ typedef struct _machine_pin_irq_obj_t { uint32_t trigger; } machine_pin_irq_obj_t; -STATIC const mp_irq_methods_t machine_pin_irq_methods; +static const mp_irq_methods_t machine_pin_irq_methods; extern const machine_pin_obj_t machine_pin_obj_table[NUM_BANK0_GPIOS]; // Mask with "1" indicating that the corresponding pin is in simulated open-drain mode. uint32_t machine_pin_open_drain_mask; #if MICROPY_HW_PIN_EXT_COUNT -STATIC inline bool is_ext_pin(__unused const machine_pin_obj_t *self) { +static inline bool is_ext_pin(__unused const machine_pin_obj_t *self) { return self->is_ext; } #else #define is_ext_pin(x) false #endif -STATIC void gpio_irq(void) { +static void gpio_irq(void) { for (int i = 0; i < 4; ++i) { uint32_t intr = iobank0_hw->intr[i]; if (intr) { @@ -196,7 +196,7 @@ const machine_pin_obj_t *machine_pin_find(mp_obj_t pin) { mp_raise_ValueError("invalid pin"); } -STATIC void machine_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_pin_obj_t *self = self_in; uint funcsel = GPIO_GET_FUNCSEL(self->id); qstr mode_qst; @@ -252,7 +252,7 @@ static const mp_arg_t allowed_args[] = { {MP_QSTR_alt, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = GPIO_FUNC_SIO}}, }; -STATIC mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // parse args mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; @@ -329,7 +329,7 @@ mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, } // fast method for getting/setting pin value -STATIC mp_obj_t machine_pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t machine_pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); machine_pin_obj_t *self = self_in; if (n_args == 0) { @@ -359,19 +359,19 @@ STATIC mp_obj_t machine_pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, c } // pin.init(mode, pull) -STATIC mp_obj_t machine_pin_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t machine_pin_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { return machine_pin_obj_init_helper(args[0], n_args - 1, args + 1, kw_args); } MP_DEFINE_CONST_FUN_OBJ_KW(machine_pin_init_obj, 1, machine_pin_obj_init); // pin.value([value]) -STATIC mp_obj_t machine_pin_value(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_pin_value(size_t n_args, const mp_obj_t *args) { return machine_pin_call(args[0], n_args - 1, 0, args + 1); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pin_value_obj, 1, 2, machine_pin_value); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pin_value_obj, 1, 2, machine_pin_value); // pin.low() -STATIC mp_obj_t machine_pin_low(mp_obj_t self_in) { +static mp_obj_t machine_pin_low(mp_obj_t self_in) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); if (is_ext_pin(self)) { #if MICROPY_HW_PIN_EXT_COUNT @@ -384,10 +384,10 @@ STATIC mp_obj_t machine_pin_low(mp_obj_t self_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_low_obj, machine_pin_low); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_low_obj, machine_pin_low); // pin.high() -STATIC mp_obj_t machine_pin_high(mp_obj_t self_in) { +static mp_obj_t machine_pin_high(mp_obj_t self_in) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); if (is_ext_pin(self)) { #if MICROPY_HW_PIN_EXT_COUNT @@ -401,10 +401,10 @@ STATIC mp_obj_t machine_pin_high(mp_obj_t self_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_high_obj, machine_pin_high); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_high_obj, machine_pin_high); // pin.toggle() -STATIC mp_obj_t machine_pin_toggle(mp_obj_t self_in) { +static mp_obj_t machine_pin_toggle(mp_obj_t self_in) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); if (is_ext_pin(self)) { #if MICROPY_HW_PIN_EXT_COUNT @@ -421,9 +421,9 @@ STATIC mp_obj_t machine_pin_toggle(mp_obj_t self_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_toggle_obj, machine_pin_toggle); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_toggle_obj, machine_pin_toggle); -STATIC machine_pin_irq_obj_t *machine_pin_get_irq(mp_hal_pin_obj_t pin) { +static machine_pin_irq_obj_t *machine_pin_get_irq(mp_hal_pin_obj_t pin) { // Get the IRQ object. machine_pin_irq_obj_t *irq = MP_STATE_PORT(machine_pin_irq_obj[pin]); @@ -459,7 +459,7 @@ void mp_hal_pin_interrupt(mp_hal_pin_obj_t pin, mp_obj_t handler, mp_uint_t trig } // pin.irq(handler=None, trigger=IRQ_FALLING|IRQ_RISING, hard=False) -STATIC mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_handler, ARG_trigger, ARG_hard }; static const mp_arg_t allowed_args[] = { { MP_QSTR_handler, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, @@ -485,9 +485,9 @@ STATIC mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_ } return MP_OBJ_FROM_PTR(irq); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_pin_irq_obj, 1, machine_pin_irq); +static MP_DEFINE_CONST_FUN_OBJ_KW(machine_pin_irq_obj, 1, machine_pin_irq); -STATIC const mp_rom_map_elem_t machine_pin_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_pin_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_pin_init_obj) }, { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&machine_pin_value_obj) }, @@ -523,9 +523,9 @@ STATIC const mp_rom_map_elem_t machine_pin_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_ALT_GPCK), MP_ROM_INT(GPIO_FUNC_GPCK) }, { MP_ROM_QSTR(MP_QSTR_ALT_USB), MP_ROM_INT(GPIO_FUNC_USB) }, }; -STATIC MP_DEFINE_CONST_DICT(machine_pin_locals_dict, machine_pin_locals_dict_table); +static MP_DEFINE_CONST_DICT(machine_pin_locals_dict, machine_pin_locals_dict_table); -STATIC mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { (void)errcode; machine_pin_obj_t *self = self_in; @@ -553,7 +553,7 @@ STATIC mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, i return -1; } -STATIC const mp_pin_p_t pin_pin_p = { +static const mp_pin_p_t pin_pin_p = { .ioctl = pin_ioctl, }; @@ -568,7 +568,7 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &machine_pin_locals_dict ); -STATIC mp_uint_t machine_pin_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { +static mp_uint_t machine_pin_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); machine_pin_irq_obj_t *irq = MP_STATE_PORT(machine_pin_irq_obj[self->id]); gpio_set_irq_enabled(self->id, GPIO_IRQ_ALL, false); @@ -578,7 +578,7 @@ STATIC mp_uint_t machine_pin_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger return 0; } -STATIC mp_uint_t machine_pin_irq_info(mp_obj_t self_in, mp_uint_t info_type) { +static mp_uint_t machine_pin_irq_info(mp_obj_t self_in, mp_uint_t info_type) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); machine_pin_irq_obj_t *irq = MP_STATE_PORT(machine_pin_irq_obj[self->id]); if (info_type == MP_IRQ_INFO_FLAGS) { @@ -589,7 +589,7 @@ STATIC mp_uint_t machine_pin_irq_info(mp_obj_t self_in, mp_uint_t info_type) { return 0; } -STATIC const mp_irq_methods_t machine_pin_irq_methods = { +static const mp_irq_methods_t machine_pin_irq_methods = { .trigger = machine_pin_irq_trigger, .info = machine_pin_irq_info, }; diff --git a/ports/rp2/machine_pwm.c b/ports/rp2/machine_pwm.c index 0248b3142a0b6..4c0bc2c103243 100644 --- a/ports/rp2/machine_pwm.c +++ b/ports/rp2/machine_pwm.c @@ -50,7 +50,7 @@ enum { DUTY_NS }; -STATIC machine_pwm_obj_t machine_pwm_obj[] = { +static machine_pwm_obj_t machine_pwm_obj[] = { {{&machine_pwm_type}, 0, PWM_CHAN_A, 0, DUTY_NOT_SET, 0 }, {{&machine_pwm_type}, 0, PWM_CHAN_B, 0, DUTY_NOT_SET, 0 }, {{&machine_pwm_type}, 1, PWM_CHAN_A, 0, DUTY_NOT_SET, 0 }, @@ -69,14 +69,14 @@ STATIC machine_pwm_obj_t machine_pwm_obj[] = { {{&machine_pwm_type}, 7, PWM_CHAN_B, 0, DUTY_NOT_SET, 0 }, }; -STATIC bool defer_start; -STATIC bool slice_freq_set[8]; +static bool defer_start; +static bool slice_freq_set[8]; -STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq); -STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16); -STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns); +static void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq); +static void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16); +static void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns); -STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_pwm_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", self->slice, self->channel, self->invert); @@ -94,7 +94,7 @@ void machine_pwm_start(machine_pwm_obj_t *self) { } } -STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, +static void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_freq, ARG_duty_u16, ARG_duty_ns, ARG_invert }; static const mp_arg_t allowed_args[] = { @@ -128,7 +128,7 @@ STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, } // PWM(pin [, args]) -STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // Check number of arguments mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); @@ -161,7 +161,7 @@ void machine_pwm_deinit_all(void) { } } -STATIC void mp_machine_pwm_deinit(machine_pwm_obj_t *self) { +static void mp_machine_pwm_deinit(machine_pwm_obj_t *self) { pwm_set_enabled(self->slice, false); } @@ -188,7 +188,7 @@ uint32_t get_slice_hz_ceil(uint32_t div16) { return get_slice_hz(div16 - 1, div16); } -STATIC mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) { if (slice_freq_set[self->slice] == true) { uint32_t div16 = pwm_hw->slice[self->slice].div; uint32_t top = pwm_hw->slice[self->slice].top; @@ -199,7 +199,7 @@ STATIC mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) { } } -STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { +static void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { // Set the frequency, making "top" as large as possible for maximum resolution. // Maximum "top" is set at 65534 to be able to achieve 100% duty with 65535. #define TOP_MAX 65534 @@ -248,7 +248,7 @@ STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { } } -STATIC mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) { if (self->duty_type != DUTY_NOT_SET && slice_freq_set[self->slice] == true) { uint32_t top = pwm_hw->slice[self->slice].top; uint32_t cc = pwm_hw->slice[self->slice].cc; @@ -262,7 +262,7 @@ STATIC mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) { } } -STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16) { +static void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16) { uint32_t top = pwm_hw->slice[self->slice].top; // Limit duty_u16 to 65535 @@ -277,7 +277,7 @@ STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u machine_pwm_start(self); } -STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { if (self->duty_type != DUTY_NOT_SET && slice_freq_set[self->slice] == true) { uint32_t slice_hz = get_slice_hz_round(pwm_hw->slice[self->slice].div); uint32_t cc = pwm_hw->slice[self->slice].cc; @@ -288,7 +288,7 @@ STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { } } -STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns) { +static void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns) { uint32_t slice_hz = get_slice_hz_round(pwm_hw->slice[self->slice].div); uint32_t cc = ((uint64_t)duty_ns * slice_hz + 500000000ULL) / 1000000000ULL; uint32_t top = pwm_hw->slice[self->slice].top; diff --git a/ports/rp2/machine_rtc.c b/ports/rp2/machine_rtc.c index eb2e1615b48f8..ce224be711b89 100644 --- a/ports/rp2/machine_rtc.c +++ b/ports/rp2/machine_rtc.c @@ -45,9 +45,9 @@ typedef struct _machine_rtc_obj_t { } machine_rtc_obj_t; // singleton RTC object -STATIC const machine_rtc_obj_t machine_rtc_obj = {{&machine_rtc_type}}; +static const machine_rtc_obj_t machine_rtc_obj = {{&machine_rtc_type}}; -STATIC mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 0, 0, false); bool r = rtc_running(); @@ -64,7 +64,7 @@ STATIC mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, s return (mp_obj_t)&machine_rtc_obj; } -STATIC mp_obj_t machine_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) { if (n_args == 1) { bool ret; datetime_t t; @@ -110,12 +110,12 @@ STATIC mp_obj_t machine_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_rtc_datetime_obj, 1, 2, machine_rtc_datetime); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_rtc_datetime_obj, 1, 2, machine_rtc_datetime); -STATIC const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_datetime), MP_ROM_PTR(&machine_rtc_datetime_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(machine_rtc_locals_dict, machine_rtc_locals_dict_table); +static MP_DEFINE_CONST_DICT(machine_rtc_locals_dict, machine_rtc_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( machine_rtc_type, diff --git a/ports/rp2/machine_spi.c b/ports/rp2/machine_spi.c index a4f4243b7a1fd..abf0a70bd0ebc 100644 --- a/ports/rp2/machine_spi.c +++ b/ports/rp2/machine_spi.c @@ -103,7 +103,7 @@ typedef struct _machine_spi_obj_t { uint32_t baudrate; } machine_spi_obj_t; -STATIC machine_spi_obj_t machine_spi_obj[] = { +static machine_spi_obj_t machine_spi_obj[] = { { {&machine_spi_type}, spi0, 0, DEFAULT_SPI_POLARITY, DEFAULT_SPI_PHASE, DEFAULT_SPI_BITS, DEFAULT_SPI_FIRSTBIT, @@ -118,7 +118,7 @@ STATIC machine_spi_obj_t machine_spi_obj[] = { }, }; -STATIC void machine_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "SPI(%u, baudrate=%u, polarity=%u, phase=%u, bits=%u, sck=%u, mosi=%u, miso=%u)", self->spi_id, self->baudrate, self->polarity, self->phase, self->bits, @@ -197,7 +197,7 @@ mp_obj_t machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n return MP_OBJ_FROM_PTR(self); } -STATIC void machine_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void machine_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits, ARG_firstbit }; static const mp_arg_t allowed_args[] = { { MP_QSTR_baudrate, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, @@ -242,7 +242,7 @@ STATIC void machine_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj } } -STATIC void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) { +static void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) { machine_spi_obj_t *self = (machine_spi_obj_t *)self_in; // Use DMA for large transfers if channels are available const size_t dma_min_size_threshold = 32; @@ -304,7 +304,7 @@ STATIC void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8 // Buffer protocol implementation for SPI. // The buffer represents the SPI data FIFO. -STATIC mp_int_t machine_spi_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { +static mp_int_t machine_spi_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { machine_spi_obj_t *self = MP_OBJ_TO_PTR(o_in); bufinfo->len = 4; @@ -314,7 +314,7 @@ STATIC mp_int_t machine_spi_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, return 0; } -STATIC const mp_machine_spi_p_t machine_spi_p = { +static const mp_machine_spi_p_t machine_spi_p = { .init = machine_spi_init, .transfer = machine_spi_transfer, }; diff --git a/ports/rp2/machine_timer.c b/ports/rp2/machine_timer.c index f154507141a1f..6f8b04f10eab0 100644 --- a/ports/rp2/machine_timer.c +++ b/ports/rp2/machine_timer.c @@ -44,7 +44,7 @@ typedef struct _machine_timer_obj_t { const mp_obj_type_t machine_timer_type; -STATIC int64_t alarm_callback(alarm_id_t id, void *user_data) { +static int64_t alarm_callback(alarm_id_t id, void *user_data) { machine_timer_obj_t *self = user_data; mp_sched_schedule(self->callback, MP_OBJ_FROM_PTR(self)); if (self->mode == TIMER_MODE_ONE_SHOT) { @@ -54,7 +54,7 @@ STATIC int64_t alarm_callback(alarm_id_t id, void *user_data) { } } -STATIC void machine_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_timer_obj_t *self = MP_OBJ_TO_PTR(self_in); qstr mode = self->mode == TIMER_MODE_ONE_SHOT ? MP_QSTR_ONE_SHOT : MP_QSTR_PERIODIC; mp_printf(print, "Timer(mode=%q, tick_hz=1000000, period=", mode); @@ -65,7 +65,7 @@ STATIC void machine_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_pr } } -STATIC mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_mode, ARG_callback, ARG_period, ARG_tick_hz, ARG_freq, }; static const mp_arg_t allowed_args[] = { { MP_QSTR_mode, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = TIMER_MODE_PERIODIC} }, @@ -104,7 +104,7 @@ STATIC mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, size_t n_ar return mp_const_none; } -STATIC mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { machine_timer_obj_t *self = mp_obj_malloc_with_finaliser(machine_timer_obj_t, &machine_timer_type); self->pool = alarm_pool_get_default(); self->alarm_id = ALARM_ID_INVALID; @@ -130,7 +130,7 @@ STATIC mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args, return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t machine_timer_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t machine_timer_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { machine_timer_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (self->alarm_id != ALARM_ID_INVALID) { alarm_pool_cancel_alarm(self->pool, self->alarm_id); @@ -138,9 +138,9 @@ STATIC mp_obj_t machine_timer_init(size_t n_args, const mp_obj_t *args, mp_map_t } return machine_timer_init_helper(self, n_args - 1, args + 1, kw_args); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_timer_init_obj, 1, machine_timer_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(machine_timer_init_obj, 1, machine_timer_init); -STATIC mp_obj_t machine_timer_deinit(mp_obj_t self_in) { +static mp_obj_t machine_timer_deinit(mp_obj_t self_in) { machine_timer_obj_t *self = MP_OBJ_TO_PTR(self_in); if (self->alarm_id != ALARM_ID_INVALID) { alarm_pool_cancel_alarm(self->pool, self->alarm_id); @@ -148,9 +148,9 @@ STATIC mp_obj_t machine_timer_deinit(mp_obj_t self_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_deinit_obj, machine_timer_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_deinit_obj, machine_timer_deinit); -STATIC const mp_rom_map_elem_t machine_timer_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_timer_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&machine_timer_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_timer_init_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&machine_timer_deinit_obj) }, @@ -158,7 +158,7 @@ STATIC const mp_rom_map_elem_t machine_timer_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_ONE_SHOT), MP_ROM_INT(TIMER_MODE_ONE_SHOT) }, { MP_ROM_QSTR(MP_QSTR_PERIODIC), MP_ROM_INT(TIMER_MODE_PERIODIC) }, }; -STATIC MP_DEFINE_CONST_DICT(machine_timer_locals_dict, machine_timer_locals_dict_table); +static MP_DEFINE_CONST_DICT(machine_timer_locals_dict, machine_timer_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( machine_timer_type, diff --git a/ports/rp2/machine_uart.c b/ports/rp2/machine_uart.c index 72e68a6fb6b61..ccbf8f781ac82 100644 --- a/ports/rp2/machine_uart.c +++ b/ports/rp2/machine_uart.c @@ -81,10 +81,10 @@ #define UART_HWCONTROL_CTS (1) #define UART_HWCONTROL_RTS (2) -STATIC mutex_t write_mutex_0; -STATIC mutex_t write_mutex_1; -STATIC mutex_t read_mutex_0; -STATIC mutex_t read_mutex_1; +static mutex_t write_mutex_0; +static mutex_t write_mutex_1; +static mutex_t read_mutex_0; +static mutex_t read_mutex_1; auto_init_mutex(write_mutex_0); auto_init_mutex(write_mutex_1); @@ -113,7 +113,7 @@ typedef struct _machine_uart_obj_t { mutex_t *write_mutex; } machine_uart_obj_t; -STATIC machine_uart_obj_t machine_uart_obj[] = { +static machine_uart_obj_t machine_uart_obj[] = { {{&machine_uart_type}, uart0, 0, 0, DEFAULT_UART_BITS, UART_PARITY_NONE, DEFAULT_UART_STOP, MICROPY_HW_UART0_TX, MICROPY_HW_UART0_RX, MICROPY_HW_UART0_CTS, MICROPY_HW_UART0_RTS, 0, 0, 0, 0, {NULL, 1, 0, 0}, &read_mutex_0, {NULL, 1, 0, 0}, &write_mutex_0}, @@ -122,8 +122,8 @@ STATIC machine_uart_obj_t machine_uart_obj[] = { 0, 0, 0, 0, {NULL, 1, 0, 0}, &read_mutex_1, {NULL, 1, 0, 0}, &write_mutex_1}, }; -STATIC const char *_parity_name[] = {"None", "0", "1"}; -STATIC const char *_invert_name[] = {"None", "INV_TX", "INV_RX", "INV_TX|INV_RX"}; +static const char *_parity_name[] = {"None", "0", "1"}; +static const char *_invert_name[] = {"None", "INV_TX", "INV_RX", "INV_TX|INV_RX"}; /******************************************************************************/ // IRQ and buffer handling @@ -145,7 +145,7 @@ static inline void read_mutex_unlock(machine_uart_obj_t *u) { } // take all bytes from the fifo and store them in the buffer -STATIC void uart_drain_rx_fifo(machine_uart_obj_t *self) { +static void uart_drain_rx_fifo(machine_uart_obj_t *self) { if (read_mutex_try_lock(self)) { while (uart_is_readable(self->uart) && ringbuf_free(&self->read_buffer) > 0) { // Get a byte from uart and put into the buffer. Every entry from @@ -176,7 +176,7 @@ STATIC void uart_drain_rx_fifo(machine_uart_obj_t *self) { // take bytes from the buffer and put them into the UART FIFO // Re-entrancy: quit if an instance already running -STATIC void uart_fill_tx_fifo(machine_uart_obj_t *self) { +static void uart_fill_tx_fifo(machine_uart_obj_t *self) { if (write_mutex_try_lock(self)) { while (uart_is_writable(self->uart) && ringbuf_avail(&self->write_buffer) > 0) { // get a byte from the buffer and put it into the uart @@ -186,7 +186,7 @@ STATIC void uart_fill_tx_fifo(machine_uart_obj_t *self) { } } -STATIC inline void uart_service_interrupt(machine_uart_obj_t *self) { +static inline void uart_service_interrupt(machine_uart_obj_t *self) { if (uart_get_hw(self->uart)->mis & (UART_UARTMIS_RXMIS_BITS | UART_UARTMIS_RTMIS_BITS)) { // rx interrupt? // clear all interrupt bits but tx uart_get_hw(self->uart)->icr = UART_UARTICR_BITS & (~UART_UARTICR_TXIC_BITS); @@ -199,11 +199,11 @@ STATIC inline void uart_service_interrupt(machine_uart_obj_t *self) { } } -STATIC void uart0_irq_handler(void) { +static void uart0_irq_handler(void) { uart_service_interrupt(&machine_uart_obj[0]); } -STATIC void uart1_irq_handler(void) { +static void uart1_irq_handler(void) { uart_service_interrupt(&machine_uart_obj[1]); } @@ -216,7 +216,7 @@ STATIC void uart1_irq_handler(void) { { MP_ROM_QSTR(MP_QSTR_CTS), MP_ROM_INT(UART_HWCONTROL_CTS) }, \ { MP_ROM_QSTR(MP_QSTR_RTS), MP_ROM_INT(UART_HWCONTROL_RTS) }, \ -STATIC void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "UART(%u, baudrate=%u, bits=%u, parity=%s, stop=%u, tx=%d, rx=%d, " "txbuf=%d, rxbuf=%d, timeout=%u, timeout_char=%u, invert=%s)", @@ -225,7 +225,7 @@ STATIC void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_ self->timeout, self->timeout_char, _invert_name[self->invert]); } -STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_baudrate, ARG_bits, ARG_parity, ARG_stop, ARG_tx, ARG_rx, ARG_cts, ARG_rts, ARG_timeout, ARG_timeout_char, ARG_invert, ARG_flow, ARG_txbuf, ARG_rxbuf}; static const mp_arg_t allowed_args[] = { @@ -411,7 +411,7 @@ STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, } } -STATIC mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); // Get UART bus. @@ -431,7 +431,7 @@ STATIC mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_arg return MP_OBJ_FROM_PTR(self); } -STATIC void mp_machine_uart_deinit(machine_uart_obj_t *self) { +static void mp_machine_uart_deinit(machine_uart_obj_t *self) { uart_deinit(self->uart); if (self->uart_id == 0) { irq_set_enabled(UART0_IRQ, false); @@ -443,24 +443,24 @@ STATIC void mp_machine_uart_deinit(machine_uart_obj_t *self) { MP_STATE_PORT(rp2_uart_tx_buffer[self->uart_id]) = NULL; } -STATIC mp_int_t mp_machine_uart_any(machine_uart_obj_t *self) { +static mp_int_t mp_machine_uart_any(machine_uart_obj_t *self) { // get all bytes from the fifo first uart_drain_rx_fifo(self); return ringbuf_avail(&self->read_buffer); } -STATIC bool mp_machine_uart_txdone(machine_uart_obj_t *self) { +static bool mp_machine_uart_txdone(machine_uart_obj_t *self) { return ringbuf_avail(&self->write_buffer) == 0 && (uart_get_hw(self->uart)->fr & UART_UARTFR_TXFE_BITS); } -STATIC void mp_machine_uart_sendbreak(machine_uart_obj_t *self) { +static void mp_machine_uart_sendbreak(machine_uart_obj_t *self) { uart_set_break(self->uart, true); mp_hal_delay_us(13000000 / self->baudrate + 1); uart_set_break(self->uart, false); } -STATIC mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { +static mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_uint_t start = mp_hal_ticks_ms(); mp_uint_t timeout = self->timeout; @@ -492,7 +492,7 @@ STATIC mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t return size; } -STATIC mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { +static mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_uint_t start = mp_hal_ticks_ms(); mp_uint_t timeout = self->timeout; @@ -534,7 +534,7 @@ STATIC mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_ return size; } -STATIC mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { machine_uart_obj_t *self = self_in; mp_uint_t ret; if (request == MP_STREAM_POLL) { diff --git a/ports/rp2/machine_wdt.c b/ports/rp2/machine_wdt.c index 58c372176c721..9cc955810c6ea 100644 --- a/ports/rp2/machine_wdt.c +++ b/ports/rp2/machine_wdt.c @@ -36,9 +36,9 @@ typedef struct _machine_wdt_obj_t { mp_obj_base_t base; } machine_wdt_obj_t; -STATIC const machine_wdt_obj_t machine_wdt = {{&machine_wdt_type}}; +static const machine_wdt_obj_t machine_wdt = {{&machine_wdt_type}}; -STATIC machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t timeout_ms) { +static machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t timeout_ms) { // Verify the WDT id. if (id != 0) { mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("WDT(%d) doesn't exist"), id); @@ -54,7 +54,7 @@ STATIC machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t return (machine_wdt_obj_t *)&machine_wdt; } -STATIC void mp_machine_wdt_feed(machine_wdt_obj_t *self) { +static void mp_machine_wdt_feed(machine_wdt_obj_t *self) { (void)self; watchdog_update(); } diff --git a/ports/rp2/modmachine.c b/ports/rp2/modmachine.c index 70b22dac01fc3..6189e7dc53796 100644 --- a/ports/rp2/modmachine.c +++ b/ports/rp2/modmachine.c @@ -55,20 +55,20 @@ { MP_ROM_QSTR(MP_QSTR_PWRON_RESET), MP_ROM_INT(RP2_RESET_PWRON) }, \ { MP_ROM_QSTR(MP_QSTR_WDT_RESET), MP_ROM_INT(RP2_RESET_WDT) }, \ -STATIC mp_obj_t mp_machine_unique_id(void) { +static mp_obj_t mp_machine_unique_id(void) { pico_unique_board_id_t id; pico_get_unique_board_id(&id); return mp_obj_new_bytes(id.id, sizeof(id.id)); } -NORETURN STATIC void mp_machine_reset(void) { +NORETURN static void mp_machine_reset(void) { watchdog_reboot(0, SRAM_END, 0); for (;;) { __wfi(); } } -STATIC mp_int_t mp_machine_reset_cause(void) { +static mp_int_t mp_machine_reset_cause(void) { int reset_cause; if (watchdog_caused_reboot()) { reset_cause = RP2_RESET_WDT; @@ -86,11 +86,11 @@ NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) { } } -STATIC mp_obj_t mp_machine_get_freq(void) { +static mp_obj_t mp_machine_get_freq(void) { return MP_OBJ_NEW_SMALL_INT(mp_hal_get_cpu_freq()); } -STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) { +static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) { mp_int_t freq = mp_obj_get_int(args[0]); if (!set_sys_clock_khz(freq / 1000, false)) { mp_raise_ValueError(MP_ERROR_TEXT("cannot change frequency")); @@ -101,11 +101,11 @@ STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) { #endif } -STATIC void mp_machine_idle(void) { +static void mp_machine_idle(void) { __wfe(); } -STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) { +static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) { mp_int_t delay_ms = 0; bool use_timer_alarm = false; @@ -189,7 +189,7 @@ STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) { restore_interrupts(my_interrupts); } -NORETURN STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) { +NORETURN static void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) { mp_machine_lightsleep(n_args, args); mp_machine_reset(); } diff --git a/ports/rp2/modos.c b/ports/rp2/modos.c index 77f980a731bb8..0008854a16e30 100644 --- a/ports/rp2/modos.c +++ b/ports/rp2/modos.c @@ -28,7 +28,7 @@ uint8_t rosc_random_u8(size_t cycles); -STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { +static mp_obj_t mp_os_urandom(mp_obj_t num) { mp_int_t n = mp_obj_get_int(num); vstr_t vstr; vstr_init_len(&vstr, n); @@ -37,4 +37,4 @@ STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { } return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); diff --git a/ports/rp2/modrp2.c b/ports/rp2/modrp2.c index bd00eaf40c89d..c90b6d5840208 100644 --- a/ports/rp2/modrp2.c +++ b/ports/rp2/modrp2.c @@ -44,7 +44,7 @@ MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mod_network_country_obj); // Improved version of // https://github.com/raspberrypi/pico-examples/blob/master/picoboard/button/button.c -STATIC bool __no_inline_not_in_flash_func(bootsel_button)(void) { +static bool __no_inline_not_in_flash_func(bootsel_button)(void) { const uint CS_PIN_INDEX = 1; // Disable interrupts and the other core since they might be @@ -77,13 +77,13 @@ STATIC bool __no_inline_not_in_flash_func(bootsel_button)(void) { return button_state; } -STATIC mp_obj_t rp2_bootsel_button(void) { +static mp_obj_t rp2_bootsel_button(void) { return MP_OBJ_NEW_SMALL_INT(bootsel_button()); } MP_DEFINE_CONST_FUN_OBJ_0(rp2_bootsel_button_obj, rp2_bootsel_button); -STATIC const mp_rom_map_elem_t rp2_module_globals_table[] = { +static const mp_rom_map_elem_t rp2_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_rp2) }, { MP_ROM_QSTR(MP_QSTR_Flash), MP_ROM_PTR(&rp2_flash_type) }, { MP_ROM_QSTR(MP_QSTR_PIO), MP_ROM_PTR(&rp2_pio_type) }, @@ -96,7 +96,7 @@ STATIC const mp_rom_map_elem_t rp2_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_country), MP_ROM_PTR(&mod_network_country_obj) }, #endif }; -STATIC MP_DEFINE_CONST_DICT(rp2_module_globals, rp2_module_globals_table); +static MP_DEFINE_CONST_DICT(rp2_module_globals, rp2_module_globals_table); const mp_obj_module_t mp_module_rp2 = { .base = { &mp_type_module }, diff --git a/ports/rp2/modtime.c b/ports/rp2/modtime.c index b4120be7c3ea6..21e5cb459b283 100644 --- a/ports/rp2/modtime.c +++ b/ports/rp2/modtime.c @@ -29,7 +29,7 @@ #include "hardware/rtc.h" // Return the localtime as an 8-tuple. -STATIC mp_obj_t mp_time_localtime_get(void) { +static mp_obj_t mp_time_localtime_get(void) { datetime_t t; rtc_get_datetime(&t); mp_obj_t tuple[8] = { @@ -46,7 +46,7 @@ STATIC mp_obj_t mp_time_localtime_get(void) { } // Return the number of seconds since the Epoch. -STATIC mp_obj_t mp_time_time_get(void) { +static mp_obj_t mp_time_time_get(void) { datetime_t t; rtc_get_datetime(&t); return mp_obj_new_int_from_ull(timeutils_seconds_since_epoch(t.year, t.month, t.day, t.hour, t.min, t.sec)); diff --git a/ports/rp2/mpbthciport.c b/ports/rp2/mpbthciport.c index 1aacbe881f9f0..0112304620deb 100644 --- a/ports/rp2/mpbthciport.c +++ b/ports/rp2/mpbthciport.c @@ -65,7 +65,7 @@ void mp_bluetooth_hci_poll_in_ms(uint32_t ms) { // For synchronous mode, we run all BLE stack code inside a scheduled task. // This task is scheduled periodically via a timer, or immediately after UART RX IRQ. -STATIC void run_events_scheduled_task(mp_sched_node_t *node) { +static void run_events_scheduled_task(mp_sched_node_t *node) { (void)node; // This will process all buffered HCI UART data, and run any callouts or events. mp_bluetooth_hci_poll(); @@ -81,7 +81,7 @@ void mp_bluetooth_hci_poll_now(void) { mp_obj_t mp_bthci_uart; -STATIC void mp_bluetooth_hci_start_polling(void) { +static void mp_bluetooth_hci_start_polling(void) { mp_bluetooth_hci_poll_now(); } diff --git a/ports/rp2/mphalport.c b/ports/rp2/mphalport.c index c5ae221e984b4..1641eadb7b696 100644 --- a/ports/rp2/mphalport.c +++ b/ports/rp2/mphalport.c @@ -44,7 +44,7 @@ // This needs to be added to the result of time_us_64() to get the number of // microseconds since the Epoch. -STATIC uint64_t time_us_64_offset_from_epoch; +static uint64_t time_us_64_offset_from_epoch; static alarm_id_t soft_timer_alarm_id = 0; @@ -54,7 +54,7 @@ static alarm_id_t soft_timer_alarm_id = 0; #define MICROPY_HW_STDIN_BUFFER_LEN 512 #endif -STATIC uint8_t stdin_ringbuf_array[MICROPY_HW_STDIN_BUFFER_LEN]; +static uint8_t stdin_ringbuf_array[MICROPY_HW_STDIN_BUFFER_LEN]; ringbuf_t stdin_ringbuf = { stdin_ringbuf_array, sizeof(stdin_ringbuf_array) }; #endif diff --git a/ports/rp2/mpthreadport.c b/ports/rp2/mpthreadport.c index 977df80449b1e..8d8f13a089059 100644 --- a/ports/rp2/mpthreadport.c +++ b/ports/rp2/mpthreadport.c @@ -39,14 +39,14 @@ extern uint8_t __StackTop, __StackBottom; void *core_state[2]; // This will be non-NULL while Python code is executing. -STATIC void *(*core1_entry)(void *) = NULL; +static void *(*core1_entry)(void *) = NULL; -STATIC void *core1_arg = NULL; -STATIC uint32_t *core1_stack = NULL; -STATIC size_t core1_stack_num_words = 0; +static void *core1_arg = NULL; +static uint32_t *core1_stack = NULL; +static size_t core1_stack_num_words = 0; // Thread mutex. -STATIC mutex_t atomic_mutex; +static mutex_t atomic_mutex; uint32_t mp_thread_begin_atomic_section(void) { if (core1_entry) { @@ -102,7 +102,7 @@ void mp_thread_gc_others(void) { } } -STATIC void core1_entry_wrapper(void) { +static void core1_entry_wrapper(void) { // Allow MICROPY_BEGIN_ATOMIC_SECTION to be invoked from core0. multicore_lockout_victim_init(); diff --git a/ports/rp2/rp2_dma.c b/ports/rp2/rp2_dma.c index 27624ea8bfe12..3afcf8b5d63af 100644 --- a/ports/rp2/rp2_dma.c +++ b/ports/rp2/rp2_dma.c @@ -56,7 +56,7 @@ typedef struct _rp2_dma_ctrl_field_t { uint8_t read_only : 1; } rp2_dma_ctrl_field_t; -STATIC rp2_dma_ctrl_field_t rp2_dma_ctrl_fields_table[] = { +static rp2_dma_ctrl_field_t rp2_dma_ctrl_fields_table[] = { { MP_QSTR_enable, 0, 1, 0 }, { MP_QSTR_high_pri, 1, 1, 0 }, { MP_QSTR_size, 2, 2, 0 }, @@ -76,14 +76,14 @@ STATIC rp2_dma_ctrl_field_t rp2_dma_ctrl_fields_table[] = { { MP_QSTR_ahb_err, 31, 1, 1 }, }; -STATIC const uint32_t rp2_dma_ctrl_field_count = MP_ARRAY_SIZE(rp2_dma_ctrl_fields_table); +static const uint32_t rp2_dma_ctrl_field_count = MP_ARRAY_SIZE(rp2_dma_ctrl_fields_table); #define REG_TYPE_COUNT 0 // Accept just integers #define REG_TYPE_CONF 1 // Accept integers or ctrl values #define REG_TYPE_ADDR_READ 2 // Accept integers, buffers or objects that can be read from #define REG_TYPE_ADDR_WRITE 3 // Accept integers, buffers or objects that can be written to -STATIC uint32_t rp2_dma_register_value_from_obj(mp_obj_t o, int reg_type) { +static uint32_t rp2_dma_register_value_from_obj(mp_obj_t o, int reg_type) { if (reg_type == REG_TYPE_ADDR_READ || reg_type == REG_TYPE_ADDR_WRITE) { mp_buffer_info_t buf_info; mp_uint_t flags = (reg_type == REG_TYPE_ADDR_READ) ? MP_BUFFER_READ : MP_BUFFER_WRITE; @@ -95,7 +95,7 @@ STATIC uint32_t rp2_dma_register_value_from_obj(mp_obj_t o, int reg_type) { return mp_obj_get_int_truncated(o); } -STATIC void rp2_dma_irq_handler(void) { +static void rp2_dma_irq_handler(void) { // Main IRQ handler uint32_t irq_bits = dma_hw->ints0; @@ -113,7 +113,7 @@ STATIC void rp2_dma_irq_handler(void) { } } -STATIC mp_uint_t rp2_dma_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { +static mp_uint_t rp2_dma_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { rp2_dma_obj_t *self = MP_OBJ_TO_PTR(self_in); irq_set_enabled(DMA_IRQ_0, false); self->irq_flag = 0; @@ -122,7 +122,7 @@ STATIC mp_uint_t rp2_dma_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { return 0; } -STATIC mp_uint_t rp2_dma_irq_info(mp_obj_t self_in, mp_uint_t info_type) { +static mp_uint_t rp2_dma_irq_info(mp_obj_t self_in, mp_uint_t info_type) { rp2_dma_obj_t *self = MP_OBJ_TO_PTR(self_in); if (info_type == MP_IRQ_INFO_FLAGS) { return self->irq_flag; @@ -132,12 +132,12 @@ STATIC mp_uint_t rp2_dma_irq_info(mp_obj_t self_in, mp_uint_t info_type) { return 0; } -STATIC const mp_irq_methods_t rp2_dma_irq_methods = { +static const mp_irq_methods_t rp2_dma_irq_methods = { .trigger = rp2_dma_irq_trigger, .info = rp2_dma_irq_info, }; -STATIC mp_obj_t rp2_dma_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t rp2_dma_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 0, false); int dma_channel = dma_claim_unused_channel(false); @@ -152,13 +152,13 @@ STATIC mp_obj_t rp2_dma_make_new(const mp_obj_type_t *type, size_t n_args, size_ return MP_OBJ_FROM_PTR(self); } -STATIC void rp2_dma_error_if_closed(rp2_dma_obj_t *self) { +static void rp2_dma_error_if_closed(rp2_dma_obj_t *self) { if (self->channel == CHANNEL_CLOSED) { mp_raise_ValueError(MP_ERROR_TEXT("channel closed")); } } -STATIC void rp2_dma_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) { +static void rp2_dma_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) { rp2_dma_obj_t *self = MP_OBJ_TO_PTR(self_in); if (dest[0] == MP_OBJ_NULL) { @@ -215,13 +215,13 @@ STATIC void rp2_dma_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) { } } -STATIC void rp2_dma_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void rp2_dma_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { rp2_dma_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "DMA(%u)", self->channel); } // DMA.config(*, read, write, count, ctrl, trigger) -STATIC mp_obj_t rp2_dma_config(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t rp2_dma_config(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { rp2_dma_obj_t *self = MP_OBJ_TO_PTR(*pos_args); rp2_dma_error_if_closed(self); @@ -277,10 +277,10 @@ STATIC mp_obj_t rp2_dma_config(size_t n_args, const mp_obj_t *pos_args, mp_map_t return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(rp2_dma_config_obj, 1, rp2_dma_config); +static MP_DEFINE_CONST_FUN_OBJ_KW(rp2_dma_config_obj, 1, rp2_dma_config); // DMA.active([value]) -STATIC mp_obj_t rp2_dma_active(size_t n_args, const mp_obj_t *args) { +static mp_obj_t rp2_dma_active(size_t n_args, const mp_obj_t *args) { rp2_dma_obj_t *self = MP_OBJ_TO_PTR(args[0]); rp2_dma_error_if_closed(self); @@ -295,13 +295,13 @@ STATIC mp_obj_t rp2_dma_active(size_t n_args, const mp_obj_t *args) { uint32_t busy = dma_channel_is_busy(self->channel); return mp_obj_new_bool((mp_int_t)busy); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_dma_active_obj, 1, 2, rp2_dma_active); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_dma_active_obj, 1, 2, rp2_dma_active); // Default is quiet, unpaced, read and write incrementing, word transfers, enabled #define DEFAULT_DMA_CONFIG (1 << 21) | (0x3f << 15) | (1 << 5) | (1 << 4) | (2 << 2) | (1 << 0) // DMA.pack_ctrl(...) -STATIC mp_obj_t rp2_dma_pack_ctrl(size_t n_pos_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t rp2_dma_pack_ctrl(size_t n_pos_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // Pack keyword settings into a control register value, using either the default for this // DMA channel or the provided defaults rp2_dma_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); @@ -346,10 +346,10 @@ STATIC mp_obj_t rp2_dma_pack_ctrl(size_t n_pos_args, const mp_obj_t *pos_args, m return mp_obj_new_int_from_uint(value); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(rp2_dma_pack_ctrl_obj, 1, rp2_dma_pack_ctrl); +static MP_DEFINE_CONST_FUN_OBJ_KW(rp2_dma_pack_ctrl_obj, 1, rp2_dma_pack_ctrl); // DMA.unpack_ctrl(value) -STATIC mp_obj_t rp2_dma_unpack_ctrl(mp_obj_t value_obj) { +static mp_obj_t rp2_dma_unpack_ctrl(mp_obj_t value_obj) { // Return a dict representing the unpacked fields of a control register value mp_obj_t result_dict[rp2_dma_ctrl_field_count * 2]; @@ -364,10 +364,10 @@ STATIC mp_obj_t rp2_dma_unpack_ctrl(mp_obj_t value_obj) { return mp_obj_dict_make_new(&mp_type_dict, 0, rp2_dma_ctrl_field_count, result_dict); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(rp2_dma_unpack_ctrl_fun_obj, rp2_dma_unpack_ctrl); -STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(rp2_dma_unpack_ctrl_obj, MP_ROM_PTR(&rp2_dma_unpack_ctrl_fun_obj)); +static MP_DEFINE_CONST_FUN_OBJ_1(rp2_dma_unpack_ctrl_fun_obj, rp2_dma_unpack_ctrl); +static MP_DEFINE_CONST_STATICMETHOD_OBJ(rp2_dma_unpack_ctrl_obj, MP_ROM_PTR(&rp2_dma_unpack_ctrl_fun_obj)); -STATIC mp_obj_t rp2_dma_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t rp2_dma_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_handler, ARG_hard }; static const mp_arg_t allowed_args[] = { { MP_QSTR_handler, MP_ARG_OBJ, {.u_rom_obj = mp_const_none} }, @@ -409,10 +409,10 @@ STATIC mp_obj_t rp2_dma_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k return MP_OBJ_FROM_PTR(irq); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(rp2_dma_irq_obj, 1, rp2_dma_irq); +static MP_DEFINE_CONST_FUN_OBJ_KW(rp2_dma_irq_obj, 1, rp2_dma_irq); // DMA.close() -STATIC mp_obj_t rp2_dma_close(mp_obj_t self_in) { +static mp_obj_t rp2_dma_close(mp_obj_t self_in) { rp2_dma_obj_t *self = MP_OBJ_TO_PTR(self_in); uint8_t channel = self->channel; @@ -431,9 +431,9 @@ STATIC mp_obj_t rp2_dma_close(mp_obj_t self_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(rp2_dma_close_obj, rp2_dma_close); +static MP_DEFINE_CONST_FUN_OBJ_1(rp2_dma_close_obj, rp2_dma_close); -STATIC const mp_rom_map_elem_t rp2_dma_locals_dict_table[] = { +static const mp_rom_map_elem_t rp2_dma_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&rp2_dma_config_obj) }, { MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&rp2_dma_active_obj) }, { MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&rp2_dma_irq_obj) }, @@ -442,7 +442,7 @@ STATIC const mp_rom_map_elem_t rp2_dma_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_pack_ctrl), MP_ROM_PTR(&rp2_dma_pack_ctrl_obj) }, { MP_ROM_QSTR(MP_QSTR_unpack_ctrl), MP_ROM_PTR(&rp2_dma_unpack_ctrl_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(rp2_dma_locals_dict, rp2_dma_locals_dict_table); +static MP_DEFINE_CONST_DICT(rp2_dma_locals_dict, rp2_dma_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( rp2_dma_type, diff --git a/ports/rp2/rp2_flash.c b/ports/rp2/rp2_flash.c index 35c51641692f4..c1acb54e75748 100644 --- a/ports/rp2/rp2_flash.c +++ b/ports/rp2/rp2_flash.c @@ -53,7 +53,7 @@ typedef struct _rp2_flash_obj_t { uint32_t flash_size; } rp2_flash_obj_t; -STATIC rp2_flash_obj_t rp2_flash_obj = { +static rp2_flash_obj_t rp2_flash_obj = { .base = { &rp2_flash_type }, .flash_base = MICROPY_HW_FLASH_STORAGE_BASE, .flash_size = MICROPY_HW_FLASH_STORAGE_BYTES, @@ -86,7 +86,7 @@ static void end_critical_flash_section(uint32_t state) { } } -STATIC mp_obj_t rp2_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t rp2_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // Parse arguments enum { ARG_start, ARG_len }; static const mp_arg_t allowed_args[] = { @@ -128,7 +128,7 @@ STATIC mp_obj_t rp2_flash_make_new(const mp_obj_type_t *type, size_t n_args, siz return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t rp2_flash_readblocks(size_t n_args, const mp_obj_t *args) { +static mp_obj_t rp2_flash_readblocks(size_t n_args, const mp_obj_t *args) { rp2_flash_obj_t *self = MP_OBJ_TO_PTR(args[0]); uint32_t offset = mp_obj_get_int(args[1]) * BLOCK_SIZE_BYTES; mp_buffer_info_t bufinfo; @@ -143,9 +143,9 @@ STATIC mp_obj_t rp2_flash_readblocks(size_t n_args, const mp_obj_t *args) { mp_event_handle_nowait(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_flash_readblocks_obj, 3, 4, rp2_flash_readblocks); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_flash_readblocks_obj, 3, 4, rp2_flash_readblocks); -STATIC mp_obj_t rp2_flash_writeblocks(size_t n_args, const mp_obj_t *args) { +static mp_obj_t rp2_flash_writeblocks(size_t n_args, const mp_obj_t *args) { rp2_flash_obj_t *self = MP_OBJ_TO_PTR(args[0]); uint32_t offset = mp_obj_get_int(args[1]) * BLOCK_SIZE_BYTES; mp_buffer_info_t bufinfo; @@ -166,9 +166,9 @@ STATIC mp_obj_t rp2_flash_writeblocks(size_t n_args, const mp_obj_t *args) { // TODO check return value return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_flash_writeblocks_obj, 3, 4, rp2_flash_writeblocks); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_flash_writeblocks_obj, 3, 4, rp2_flash_writeblocks); -STATIC mp_obj_t rp2_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { +static mp_obj_t rp2_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { rp2_flash_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t cmd = mp_obj_get_int(cmd_in); switch (cmd) { @@ -194,14 +194,14 @@ STATIC mp_obj_t rp2_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_ return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(rp2_flash_ioctl_obj, rp2_flash_ioctl); +static MP_DEFINE_CONST_FUN_OBJ_3(rp2_flash_ioctl_obj, rp2_flash_ioctl); -STATIC const mp_rom_map_elem_t rp2_flash_locals_dict_table[] = { +static const mp_rom_map_elem_t rp2_flash_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&rp2_flash_readblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&rp2_flash_writeblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&rp2_flash_ioctl_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(rp2_flash_locals_dict, rp2_flash_locals_dict_table); +static MP_DEFINE_CONST_DICT(rp2_flash_locals_dict, rp2_flash_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( rp2_flash_type, diff --git a/ports/rp2/rp2_pio.c b/ports/rp2/rp2_pio.c index 42e61684b3369..b882bbbc50c8c 100644 --- a/ports/rp2/rp2_pio.c +++ b/ports/rp2/rp2_pio.c @@ -65,17 +65,17 @@ typedef struct _rp2_state_machine_irq_obj_t { uint8_t trigger; } rp2_state_machine_irq_obj_t; -STATIC const rp2_state_machine_obj_t rp2_state_machine_obj[8]; -STATIC uint8_t rp2_state_machine_initial_pc[8]; +static const rp2_state_machine_obj_t rp2_state_machine_obj[8]; +static uint8_t rp2_state_machine_initial_pc[8]; // These masks keep track of PIO instruction memory used by this module. -STATIC uint32_t rp2_pio_instruction_memory_usage_mask[2]; +static uint32_t rp2_pio_instruction_memory_usage_mask[2]; -STATIC const rp2_state_machine_obj_t *rp2_state_machine_get_object(mp_int_t sm_id); -STATIC void rp2_state_machine_reset_all(void); -STATIC mp_obj_t rp2_state_machine_init_helper(const rp2_state_machine_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args); +static const rp2_state_machine_obj_t *rp2_state_machine_get_object(mp_int_t sm_id); +static void rp2_state_machine_reset_all(void); +static mp_obj_t rp2_state_machine_init_helper(const rp2_state_machine_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args); -STATIC void pio_irq0(PIO pio) { +static void pio_irq0(PIO pio) { uint32_t ints = pio->ints0; // Acknowledge SM0-3 IRQs if they are enabled on this IRQ0. @@ -98,16 +98,16 @@ STATIC void pio_irq0(PIO pio) { } } -STATIC void pio0_irq0(void) { +static void pio0_irq0(void) { pio_irq0(pio0); } -STATIC void pio1_irq0(void) { +static void pio1_irq0(void) { pio_irq0(pio1); } // Calls pio_add_program() and keeps track of used instruction memory. -STATIC uint rp2_pio_add_managed_program(PIO pio, struct pio_program *pio_program) { +static uint rp2_pio_add_managed_program(PIO pio, struct pio_program *pio_program) { uint offset = pio_add_program(pio, pio_program); uint32_t mask = ((1 << pio_program->length) - 1) << offset; rp2_pio_instruction_memory_usage_mask[pio_get_index(pio)] |= mask; @@ -115,7 +115,7 @@ STATIC uint rp2_pio_add_managed_program(PIO pio, struct pio_program *pio_program } // Calls pio_remove_program() and keeps track of used instruction memory. -STATIC void rp2_pio_remove_managed_program(PIO pio, struct pio_program *pio_program, uint offset) { +static void rp2_pio_remove_managed_program(PIO pio, struct pio_program *pio_program, uint offset) { pio_remove_program(pio, pio_program, offset); uint32_t mask = ((1 << pio_program->length) - 1) << offset; rp2_pio_instruction_memory_usage_mask[pio_get_index(pio)] &= ~mask; @@ -123,7 +123,7 @@ STATIC void rp2_pio_remove_managed_program(PIO pio, struct pio_program *pio_prog // Calls pio_remove_program() for all programs registered with rp2_pio_add_managed_program(), // that weren't already removed via rp2_pio_remove_managed_program(). -STATIC void rp2_pio_remove_all_managed_programs(PIO pio) { +static void rp2_pio_remove_all_managed_programs(PIO pio) { uint32_t mask = rp2_pio_instruction_memory_usage_mask[pio_get_index(pio)]; for (size_t i = 0; i < 32; ++i) { if (mask & (1 << i)) { @@ -188,13 +188,13 @@ typedef struct _asm_pio_config_t { uint32_t pinvals; } asm_pio_config_t; -STATIC void asm_pio_override_shiftctrl(mp_obj_t arg, uint32_t bits, uint32_t lsb, pio_sm_config *config) { +static void asm_pio_override_shiftctrl(mp_obj_t arg, uint32_t bits, uint32_t lsb, pio_sm_config *config) { if (arg != mp_const_none) { config->shiftctrl = (config->shiftctrl & ~bits) | (mp_obj_get_int(arg) << lsb); } } -STATIC void asm_pio_get_pins(const char *type, mp_obj_t prog_pins, mp_obj_t arg_base, asm_pio_config_t *config) { +static void asm_pio_get_pins(const char *type, mp_obj_t prog_pins, mp_obj_t arg_base, asm_pio_config_t *config) { if (prog_pins != mp_const_none) { // The PIO program specified pins for initialisation on out/set/sideset. if (mp_obj_is_integer(prog_pins)) { @@ -223,7 +223,7 @@ STATIC void asm_pio_get_pins(const char *type, mp_obj_t prog_pins, mp_obj_t arg_ } } -STATIC void asm_pio_init_gpio(PIO pio, uint32_t sm, asm_pio_config_t *config) { +static void asm_pio_init_gpio(PIO pio, uint32_t sm, asm_pio_config_t *config) { uint32_t pinmask = ((1 << config->count) - 1) << config->base; pio_sm_set_pins_with_mask(pio, sm, config->pinvals << config->base, pinmask); pio_sm_set_pindirs_with_mask(pio, sm, config->pindirs << config->base, pinmask); @@ -235,20 +235,20 @@ STATIC void asm_pio_init_gpio(PIO pio, uint32_t sm, asm_pio_config_t *config) { /******************************************************************************/ // PIO object -STATIC const mp_irq_methods_t rp2_pio_irq_methods; +static const mp_irq_methods_t rp2_pio_irq_methods; -STATIC rp2_pio_obj_t rp2_pio_obj[] = { +static rp2_pio_obj_t rp2_pio_obj[] = { { { &rp2_pio_type }, pio0, PIO0_IRQ_0 }, { { &rp2_pio_type }, pio1, PIO1_IRQ_0 }, }; -STATIC void rp2_pio_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void rp2_pio_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { rp2_pio_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "PIO(%u)", self->pio == pio0 ? 0 : 1); } // constructor(id) -STATIC mp_obj_t rp2_pio_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t rp2_pio_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 1, false); // Get the PIO object. @@ -263,7 +263,7 @@ STATIC mp_obj_t rp2_pio_make_new(const mp_obj_type_t *type, size_t n_args, size_ } // PIO.add_program(prog) -STATIC mp_obj_t rp2_pio_add_program(mp_obj_t self_in, mp_obj_t prog_in) { +static mp_obj_t rp2_pio_add_program(mp_obj_t self_in, mp_obj_t prog_in) { rp2_pio_obj_t *self = MP_OBJ_TO_PTR(self_in); // Get the program data. @@ -284,10 +284,10 @@ STATIC mp_obj_t rp2_pio_add_program(mp_obj_t self_in, mp_obj_t prog_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(rp2_pio_add_program_obj, rp2_pio_add_program); +static MP_DEFINE_CONST_FUN_OBJ_2(rp2_pio_add_program_obj, rp2_pio_add_program); // PIO.remove_program([prog]) -STATIC mp_obj_t rp2_pio_remove_program(size_t n_args, const mp_obj_t *args) { +static mp_obj_t rp2_pio_remove_program(size_t n_args, const mp_obj_t *args) { rp2_pio_obj_t *self = MP_OBJ_TO_PTR(args[0]); // Default to remove all programs. @@ -315,10 +315,10 @@ STATIC mp_obj_t rp2_pio_remove_program(size_t n_args, const mp_obj_t *args) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_pio_remove_program_obj, 1, 2, rp2_pio_remove_program); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_pio_remove_program_obj, 1, 2, rp2_pio_remove_program); // PIO.state_machine(id, prog, freq=-1, *, set=None) -STATIC mp_obj_t rp2_pio_state_machine(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t rp2_pio_state_machine(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { rp2_pio_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); // Get and verify the state machine id. @@ -340,7 +340,7 @@ STATIC mp_obj_t rp2_pio_state_machine(size_t n_args, const mp_obj_t *pos_args, m MP_DEFINE_CONST_FUN_OBJ_KW(rp2_pio_state_machine_obj, 2, rp2_pio_state_machine); // PIO.irq(handler=None, trigger=IRQ_SM0|IRQ_SM1|IRQ_SM2|IRQ_SM3, hard=False) -STATIC mp_obj_t rp2_pio_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t rp2_pio_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_handler, ARG_trigger, ARG_hard }; static const mp_arg_t allowed_args[] = { { MP_QSTR_handler, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, @@ -388,9 +388,9 @@ STATIC mp_obj_t rp2_pio_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k return MP_OBJ_FROM_PTR(irq); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(rp2_pio_irq_obj, 1, rp2_pio_irq); +static MP_DEFINE_CONST_FUN_OBJ_KW(rp2_pio_irq_obj, 1, rp2_pio_irq); -STATIC const mp_rom_map_elem_t rp2_pio_locals_dict_table[] = { +static const mp_rom_map_elem_t rp2_pio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_add_program), MP_ROM_PTR(&rp2_pio_add_program_obj) }, { MP_ROM_QSTR(MP_QSTR_remove_program), MP_ROM_PTR(&rp2_pio_remove_program_obj) }, { MP_ROM_QSTR(MP_QSTR_state_machine), MP_ROM_PTR(&rp2_pio_state_machine_obj) }, @@ -413,7 +413,7 @@ STATIC const mp_rom_map_elem_t rp2_pio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_IRQ_SM2), MP_ROM_INT(0x400) }, { MP_ROM_QSTR(MP_QSTR_IRQ_SM3), MP_ROM_INT(0x800) }, }; -STATIC MP_DEFINE_CONST_DICT(rp2_pio_locals_dict, rp2_pio_locals_dict_table); +static MP_DEFINE_CONST_DICT(rp2_pio_locals_dict, rp2_pio_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( rp2_pio_type, @@ -424,7 +424,7 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &rp2_pio_locals_dict ); -STATIC mp_uint_t rp2_pio_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { +static mp_uint_t rp2_pio_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { rp2_pio_obj_t *self = MP_OBJ_TO_PTR(self_in); rp2_pio_irq_obj_t *irq = MP_STATE_PORT(rp2_pio_irq_obj[PIO_NUM(self->pio)]); irq_set_enabled(self->irq, false); @@ -434,7 +434,7 @@ STATIC mp_uint_t rp2_pio_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { return 0; } -STATIC mp_uint_t rp2_pio_irq_info(mp_obj_t self_in, mp_uint_t info_type) { +static mp_uint_t rp2_pio_irq_info(mp_obj_t self_in, mp_uint_t info_type) { rp2_pio_obj_t *self = MP_OBJ_TO_PTR(self_in); rp2_pio_irq_obj_t *irq = MP_STATE_PORT(rp2_pio_irq_obj[PIO_NUM(self->pio)]); if (info_type == MP_IRQ_INFO_FLAGS) { @@ -445,7 +445,7 @@ STATIC mp_uint_t rp2_pio_irq_info(mp_obj_t self_in, mp_uint_t info_type) { return 0; } -STATIC const mp_irq_methods_t rp2_pio_irq_methods = { +static const mp_irq_methods_t rp2_pio_irq_methods = { .trigger = rp2_pio_irq_trigger, .info = rp2_pio_irq_info, }; @@ -454,11 +454,11 @@ STATIC const mp_irq_methods_t rp2_pio_irq_methods = { // StateMachine object // This mask keeps track of state machines claimed by this module. -STATIC uint32_t rp2_state_machine_claimed_mask; +static uint32_t rp2_state_machine_claimed_mask; -STATIC const mp_irq_methods_t rp2_state_machine_irq_methods; +static const mp_irq_methods_t rp2_state_machine_irq_methods; -STATIC const rp2_state_machine_obj_t rp2_state_machine_obj[] = { +static const rp2_state_machine_obj_t rp2_state_machine_obj[] = { { { &rp2_state_machine_type }, pio0, PIO0_IRQ_0, 0, 0 }, { { &rp2_state_machine_type }, pio0, PIO0_IRQ_0, 1, 1 }, { { &rp2_state_machine_type }, pio0, PIO0_IRQ_0, 2, 2 }, @@ -469,7 +469,7 @@ STATIC const rp2_state_machine_obj_t rp2_state_machine_obj[] = { { { &rp2_state_machine_type }, pio1, PIO1_IRQ_0, 3, 7 }, }; -STATIC const rp2_state_machine_obj_t *rp2_state_machine_get_object(mp_int_t sm_id) { +static const rp2_state_machine_obj_t *rp2_state_machine_get_object(mp_int_t sm_id) { if (!(0 <= sm_id && sm_id < MP_ARRAY_SIZE(rp2_state_machine_obj))) { mp_raise_ValueError("invalid StateMachine"); } @@ -487,7 +487,7 @@ STATIC const rp2_state_machine_obj_t *rp2_state_machine_get_object(mp_int_t sm_i return sm_obj; } -STATIC void rp2_state_machine_reset_all(void) { +static void rp2_state_machine_reset_all(void) { for (size_t i = 0; i < MP_ARRAY_SIZE(rp2_state_machine_obj); ++i) { if (rp2_state_machine_claimed_mask & (1 << i)) { const rp2_state_machine_obj_t *sm_obj = &rp2_state_machine_obj[i]; @@ -498,7 +498,7 @@ STATIC void rp2_state_machine_reset_all(void) { rp2_state_machine_claimed_mask = 0; } -STATIC void rp2_state_machine_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void rp2_state_machine_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "StateMachine(%u)", self->id); } @@ -508,7 +508,7 @@ STATIC void rp2_state_machine_print(const mp_print_t *print, mp_obj_t self_in, m // sideset_base=None, in_shiftdir=None, out_shiftdir=None, // push_thresh=None, pull_thresh=None, // ) -STATIC mp_obj_t rp2_state_machine_init_helper(const rp2_state_machine_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t rp2_state_machine_init_helper(const rp2_state_machine_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_prog, ARG_freq, ARG_in_base, ARG_out_base, ARG_set_base, ARG_jmp_pin, ARG_sideset_base, @@ -639,7 +639,7 @@ STATIC mp_obj_t rp2_state_machine_init_helper(const rp2_state_machine_obj_t *sel } // StateMachine(id, ...) -STATIC mp_obj_t rp2_state_machine_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t rp2_state_machine_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); // Get the StateMachine object. @@ -657,32 +657,32 @@ STATIC mp_obj_t rp2_state_machine_make_new(const mp_obj_type_t *type, size_t n_a return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t rp2_state_machine_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t rp2_state_machine_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { return rp2_state_machine_init_helper(MP_OBJ_TO_PTR(args[0]), n_args - 1, args + 1, kw_args); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(rp2_state_machine_init_obj, 1, rp2_state_machine_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(rp2_state_machine_init_obj, 1, rp2_state_machine_init); // StateMachine.active([value]) -STATIC mp_obj_t rp2_state_machine_active(size_t n_args, const mp_obj_t *args) { +static mp_obj_t rp2_state_machine_active(size_t n_args, const mp_obj_t *args) { rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args > 1) { pio_sm_set_enabled(self->pio, self->sm, mp_obj_is_true(args[1])); } return mp_obj_new_bool((self->pio->ctrl >> self->sm) & 1); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_state_machine_active_obj, 1, 2, rp2_state_machine_active); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_state_machine_active_obj, 1, 2, rp2_state_machine_active); // StateMachine.restart() -STATIC mp_obj_t rp2_state_machine_restart(mp_obj_t self_in) { +static mp_obj_t rp2_state_machine_restart(mp_obj_t self_in) { rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(self_in); pio_sm_restart(self->pio, self->sm); pio_sm_exec(self->pio, self->sm, pio_encode_jmp(rp2_state_machine_initial_pc[self->id])); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(rp2_state_machine_restart_obj, rp2_state_machine_restart); +static MP_DEFINE_CONST_FUN_OBJ_1(rp2_state_machine_restart_obj, rp2_state_machine_restart); // StateMachine.exec(instr) -STATIC mp_obj_t rp2_state_machine_exec(mp_obj_t self_in, mp_obj_t instr_in) { +static mp_obj_t rp2_state_machine_exec(mp_obj_t self_in, mp_obj_t instr_in) { rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t encoded = 0; if (!mp_obj_get_int_maybe(instr_in, &encoded)) { @@ -700,10 +700,10 @@ STATIC mp_obj_t rp2_state_machine_exec(mp_obj_t self_in, mp_obj_t instr_in) { pio_sm_exec(self->pio, self->sm, encoded); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(rp2_state_machine_exec_obj, rp2_state_machine_exec); +static MP_DEFINE_CONST_FUN_OBJ_2(rp2_state_machine_exec_obj, rp2_state_machine_exec); // StateMachine.get(buf=None, shift=0) -STATIC mp_obj_t rp2_state_machine_get(size_t n_args, const mp_obj_t *args) { +static mp_obj_t rp2_state_machine_get(size_t n_args, const mp_obj_t *args) { rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(args[0]); mp_buffer_info_t bufinfo; bufinfo.buf = NULL; @@ -752,10 +752,10 @@ STATIC mp_obj_t rp2_state_machine_get(size_t n_args, const mp_obj_t *args) { } } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_state_machine_get_obj, 1, 3, rp2_state_machine_get); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_state_machine_get_obj, 1, 3, rp2_state_machine_get); // StateMachine.put(value, shift=0) -STATIC mp_obj_t rp2_state_machine_put(size_t n_args, const mp_obj_t *args) { +static mp_obj_t rp2_state_machine_put(size_t n_args, const mp_obj_t *args) { rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(args[0]); uint32_t shift = 0; if (n_args > 2) { @@ -793,26 +793,26 @@ STATIC mp_obj_t rp2_state_machine_put(size_t n_args, const mp_obj_t *args) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_state_machine_put_obj, 2, 3, rp2_state_machine_put); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_state_machine_put_obj, 2, 3, rp2_state_machine_put); // StateMachine.rx_fifo() -STATIC mp_obj_t rp2_state_machine_rx_fifo(mp_obj_t self_in) { +static mp_obj_t rp2_state_machine_rx_fifo(mp_obj_t self_in) { rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(self_in); return MP_OBJ_NEW_SMALL_INT(pio_sm_get_rx_fifo_level(self->pio, self->sm)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(rp2_state_machine_rx_fifo_obj, rp2_state_machine_rx_fifo); +static MP_DEFINE_CONST_FUN_OBJ_1(rp2_state_machine_rx_fifo_obj, rp2_state_machine_rx_fifo); // StateMachine.tx_fifo() -STATIC mp_obj_t rp2_state_machine_tx_fifo(mp_obj_t self_in) { +static mp_obj_t rp2_state_machine_tx_fifo(mp_obj_t self_in) { rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(self_in); return MP_OBJ_NEW_SMALL_INT(pio_sm_get_tx_fifo_level(self->pio, self->sm)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(rp2_state_machine_tx_fifo_obj, rp2_state_machine_tx_fifo); +static MP_DEFINE_CONST_FUN_OBJ_1(rp2_state_machine_tx_fifo_obj, rp2_state_machine_tx_fifo); // Buffer protocol implementation for StateMachine. // The buffer represents one of the FIFO ports of the state machine. Note that a different // pointer is returned depending on if this is for reading or writing. -STATIC mp_int_t rp2_state_machine_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { +static mp_int_t rp2_state_machine_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(o_in); bufinfo->len = 4; @@ -827,7 +827,7 @@ STATIC mp_int_t rp2_state_machine_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bu } // StateMachine.irq(handler=None, trigger=0|1, hard=False) -STATIC mp_obj_t rp2_state_machine_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t rp2_state_machine_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_handler, ARG_trigger, ARG_hard }; static const mp_arg_t allowed_args[] = { { MP_QSTR_handler, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, @@ -880,9 +880,9 @@ STATIC mp_obj_t rp2_state_machine_irq(size_t n_args, const mp_obj_t *pos_args, m return MP_OBJ_FROM_PTR(irq); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(rp2_state_machine_irq_obj, 1, rp2_state_machine_irq); +static MP_DEFINE_CONST_FUN_OBJ_KW(rp2_state_machine_irq_obj, 1, rp2_state_machine_irq); -STATIC const mp_rom_map_elem_t rp2_state_machine_locals_dict_table[] = { +static const mp_rom_map_elem_t rp2_state_machine_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&rp2_state_machine_init_obj) }, { MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&rp2_state_machine_active_obj) }, { MP_ROM_QSTR(MP_QSTR_restart), MP_ROM_PTR(&rp2_state_machine_restart_obj) }, @@ -893,7 +893,7 @@ STATIC const mp_rom_map_elem_t rp2_state_machine_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_tx_fifo), MP_ROM_PTR(&rp2_state_machine_tx_fifo_obj) }, { MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&rp2_state_machine_irq_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(rp2_state_machine_locals_dict, rp2_state_machine_locals_dict_table); +static MP_DEFINE_CONST_DICT(rp2_state_machine_locals_dict, rp2_state_machine_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( rp2_state_machine_type, @@ -905,7 +905,7 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &rp2_state_machine_locals_dict ); -STATIC mp_uint_t rp2_state_machine_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { +static mp_uint_t rp2_state_machine_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(self_in); rp2_state_machine_irq_obj_t *irq = MP_STATE_PORT(rp2_state_machine_irq_obj[PIO_NUM(self->pio)]); irq_set_enabled(self->irq, false); @@ -915,7 +915,7 @@ STATIC mp_uint_t rp2_state_machine_irq_trigger(mp_obj_t self_in, mp_uint_t new_t return 0; } -STATIC mp_uint_t rp2_state_machine_irq_info(mp_obj_t self_in, mp_uint_t info_type) { +static mp_uint_t rp2_state_machine_irq_info(mp_obj_t self_in, mp_uint_t info_type) { rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(self_in); rp2_state_machine_irq_obj_t *irq = MP_STATE_PORT(rp2_state_machine_irq_obj[PIO_NUM(self->pio)]); if (info_type == MP_IRQ_INFO_FLAGS) { @@ -926,7 +926,7 @@ STATIC mp_uint_t rp2_state_machine_irq_info(mp_obj_t self_in, mp_uint_t info_typ return 0; } -STATIC const mp_irq_methods_t rp2_state_machine_irq_methods = { +static const mp_irq_methods_t rp2_state_machine_irq_methods = { .trigger = rp2_state_machine_irq_trigger, .info = rp2_state_machine_irq_info, }; diff --git a/ports/samd/machine_adc.c b/ports/samd/machine_adc.c index 2e4d4ed842326..665af6f6f2785 100644 --- a/ports/samd/machine_adc.c +++ b/ports/samd/machine_adc.c @@ -85,7 +85,7 @@ static uint8_t resolution[] = { extern mp_int_t log2i(mp_int_t num); -STATIC void mp_machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; machine_adc_obj_t *self = MP_OBJ_TO_PTR(self_in); @@ -94,7 +94,7 @@ STATIC void mp_machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_p self->adc_config.channel, self->bits, 1 << self->avg, self->vref); } -STATIC mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_id, ARG_bits, ARG_average, ARG_vref }; static const mp_arg_t allowed_args[] = { { MP_QSTR_id, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -138,7 +138,7 @@ STATIC mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args } // read_u16() -STATIC mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) { +static mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) { Adc *adc = adc_bases[self->adc_config.device]; // Set the reference voltage. Default: external AREFA. adc->REFCTRL.reg = adc_vref_table[self->vref]; @@ -156,7 +156,7 @@ STATIC mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) { } // deinit() : release the ADC channel -STATIC void mp_machine_adc_deinit(machine_adc_obj_t *self) { +static void mp_machine_adc_deinit(machine_adc_obj_t *self) { busy_flags &= ~((1 << (self->adc_config.device * 16 + self->adc_config.channel))); } diff --git a/ports/samd/machine_dac.c b/ports/samd/machine_dac.c index 5c9d77624dce4..c611f95e653d0 100644 --- a/ports/samd/machine_dac.c +++ b/ports/samd/machine_dac.c @@ -44,7 +44,7 @@ typedef struct _dac_obj_t { uint8_t vref; } dac_obj_t; -STATIC dac_obj_t dac_obj[] = { +static dac_obj_t dac_obj[] = { #if defined(MCU_SAMD21) {{&machine_dac_type}, 0, PIN_PA02}, #elif defined(MCU_SAMD51) @@ -76,7 +76,7 @@ static bool dac_init = false; #endif -STATIC mp_obj_t dac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, +static mp_obj_t dac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_id, ARG_vref }; @@ -150,12 +150,12 @@ STATIC mp_obj_t dac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ return MP_OBJ_FROM_PTR(self); } -STATIC void dac_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void dac_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { dac_obj_t *self = self_in; mp_printf(print, "DAC(%u, Pin=%q, vref=%d)", self->id, pin_find_by_id(self->gpio_id)->name, self->vref); } -STATIC mp_obj_t dac_write(mp_obj_t self_in, mp_obj_t value_in) { +static mp_obj_t dac_write(mp_obj_t self_in, mp_obj_t value_in) { Dac *dac = dac_bases[0]; // Just one DAC int value = mp_obj_get_int(value_in); if (value < 0 || value > MAX_DAC_VALUE) { @@ -172,11 +172,11 @@ STATIC mp_obj_t dac_write(mp_obj_t self_in, mp_obj_t value_in) { } MP_DEFINE_CONST_FUN_OBJ_2(dac_write_obj, dac_write); -STATIC const mp_rom_map_elem_t dac_locals_dict_table[] = { +static const mp_rom_map_elem_t dac_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&dac_write_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(dac_locals_dict, dac_locals_dict_table); +static MP_DEFINE_CONST_DICT(dac_locals_dict, dac_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( machine_dac_type, diff --git a/ports/samd/machine_i2c.c b/ports/samd/machine_i2c.c index ea5178dc061f9..a7b728ddaf362 100644 --- a/ports/samd/machine_i2c.c +++ b/ports/samd/machine_i2c.c @@ -70,7 +70,7 @@ typedef struct _machine_i2c_obj_t { uint8_t *buf; } machine_i2c_obj_t; -STATIC void i2c_send_command(Sercom *i2c, uint8_t command) { +static void i2c_send_command(Sercom *i2c, uint8_t command) { i2c->I2CM.CTRLB.bit.CMD = command; while (i2c->I2CM.SYNCBUSY.bit.SYSOP) { } @@ -117,7 +117,7 @@ void common_i2c_irq_handler(int i2c_id) { } } -STATIC void machine_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "I2C(%u, freq=%u, scl=%u, sda=%u)", self->id, self->freq, self->scl, self->sda); @@ -212,7 +212,7 @@ mp_obj_t machine_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n return MP_OBJ_FROM_PTR(self); } -STATIC int machine_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, size_t len, uint8_t *buf, unsigned int flags) { +static int machine_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, size_t len, uint8_t *buf, unsigned int flags) { machine_i2c_obj_t *self = (machine_i2c_obj_t *)self_in; Sercom *i2c = self->instance; @@ -260,7 +260,7 @@ STATIC int machine_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, si return len; } -STATIC const mp_machine_i2c_p_t machine_i2c_p = { +static const mp_machine_i2c_p_t machine_i2c_p = { .transfer = mp_machine_i2c_transfer_adaptor, .transfer_single = machine_i2c_transfer_single, }; diff --git a/ports/samd/machine_pin.c b/ports/samd/machine_pin.c index 30b254722b842..4dfbd69dcde62 100644 --- a/ports/samd/machine_pin.c +++ b/ports/samd/machine_pin.c @@ -69,7 +69,7 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &machine_pin_board_pins_locals_dict ); -STATIC const mp_irq_methods_t machine_pin_irq_methods; +static const mp_irq_methods_t machine_pin_irq_methods; bool EIC_occured; @@ -78,7 +78,7 @@ uint32_t machine_pin_open_drain_mask[4]; // Open drain behaviour is simulated. #define GPIO_IS_OPEN_DRAIN(id) (machine_pin_open_drain_mask[id / 32] & (1 << (id % 32))) -STATIC void machine_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_pin_obj_t *self = self_in; char *mode_str; char *pull_str[] = {"PULL_OFF", "PULL_UP", "PULL_DOWN"}; @@ -94,14 +94,14 @@ STATIC void machine_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_prin pull_str[mp_hal_get_pull_mode(self->pin_id)]); } -STATIC void pin_validate_drive(bool strength) { +static void pin_validate_drive(bool strength) { if (strength != GPIO_STRENGTH_2MA && strength != GPIO_STRENGTH_8MA) { mp_raise_ValueError(MP_ERROR_TEXT("invalid argument(s) value")); } } // Pin.init(mode, pull=None, *, value=None, drive=0). No 'alt' yet. -STATIC mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_mode, ARG_pull, ARG_value, ARG_drive, ARG_alt }; static const mp_arg_t allowed_args[] = { { MP_QSTR_mode, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE}}, @@ -193,7 +193,7 @@ mp_obj_t machine_pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp } // Pin.init(mode, pull) -STATIC mp_obj_t machine_pin_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t machine_pin_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { return machine_pin_obj_init_helper(args[0], n_args - 1, args + 1, kw_args); } MP_DEFINE_CONST_FUN_OBJ_KW(machine_pin_init_obj, 1, machine_pin_obj_init); @@ -202,18 +202,18 @@ MP_DEFINE_CONST_FUN_OBJ_KW(machine_pin_init_obj, 1, machine_pin_obj_init); mp_obj_t machine_pin_value(size_t n_args, const mp_obj_t *args) { return machine_pin_call(args[0], n_args - 1, 0, args + 1); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pin_value_obj, 1, 2, machine_pin_value); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pin_value_obj, 1, 2, machine_pin_value); // Pin.disable(pin) -STATIC mp_obj_t machine_pin_disable(mp_obj_t self_in) { +static mp_obj_t machine_pin_disable(mp_obj_t self_in) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); gpio_set_pin_direction(self->pin_id, GPIO_DIRECTION_OFF); // Disables the pin (low power state) return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_disable_obj, machine_pin_disable); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_disable_obj, machine_pin_disable); // Pin.low() Totem-pole (push-pull) -STATIC mp_obj_t machine_pin_low(mp_obj_t self_in) { +static mp_obj_t machine_pin_low(mp_obj_t self_in) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); if (GPIO_IS_OPEN_DRAIN(self->pin_id)) { mp_hal_pin_od_low(self->pin_id); @@ -225,7 +225,7 @@ STATIC mp_obj_t machine_pin_low(mp_obj_t self_in) { MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_low_obj, machine_pin_low); // Pin.high() Totem-pole (push-pull) -STATIC mp_obj_t machine_pin_high(mp_obj_t self_in) { +static mp_obj_t machine_pin_high(mp_obj_t self_in) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); if (GPIO_IS_OPEN_DRAIN(self->pin_id)) { mp_hal_pin_od_high(self->pin_id); @@ -237,7 +237,7 @@ STATIC mp_obj_t machine_pin_high(mp_obj_t self_in) { MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_high_obj, machine_pin_high); // Pin.toggle(). Only TOGGLE pins set as OUTPUT. -STATIC mp_obj_t machine_pin_toggle(mp_obj_t self_in) { +static mp_obj_t machine_pin_toggle(mp_obj_t self_in) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); // Determine DIRECTION of PIN. @@ -259,7 +259,7 @@ STATIC mp_obj_t machine_pin_toggle(mp_obj_t self_in) { MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_toggle_obj, machine_pin_toggle); // Pin.drive(). Normal (0) is 2mA, High (1) allows 8mA. -STATIC mp_obj_t machine_pin_drive(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_pin_drive(size_t n_args, const mp_obj_t *args) { machine_pin_obj_t *self = args[0]; // Pin if (n_args == 1) { return mp_const_none; @@ -274,10 +274,10 @@ STATIC mp_obj_t machine_pin_drive(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pin_drive_obj, 1, 2, machine_pin_drive); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pin_drive_obj, 1, 2, machine_pin_drive); // pin.irq(handler=None, trigger=IRQ_FALLING|IRQ_RISING, hard=False) -STATIC mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_handler, ARG_trigger, ARG_hard }; static const mp_arg_t allowed_args[] = { { MP_QSTR_handler, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, @@ -375,7 +375,7 @@ STATIC mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_ } return MP_OBJ_FROM_PTR(irq); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_pin_irq_obj, 1, machine_pin_irq); +static MP_DEFINE_CONST_FUN_OBJ_KW(machine_pin_irq_obj, 1, machine_pin_irq); void pin_irq_deinit_all(void) { @@ -412,7 +412,7 @@ void EIC_Handler() { } } -STATIC const mp_rom_map_elem_t machine_pin_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_pin_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_pin_init_obj) }, { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&machine_pin_value_obj) }, @@ -441,9 +441,9 @@ STATIC const mp_rom_map_elem_t machine_pin_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_IRQ_RISING), MP_ROM_INT(GPIO_IRQ_EDGE_RISE) }, { MP_ROM_QSTR(MP_QSTR_IRQ_FALLING), MP_ROM_INT(GPIO_IRQ_EDGE_FALL) }, }; -STATIC MP_DEFINE_CONST_DICT(machine_pin_locals_dict, machine_pin_locals_dict_table); +static MP_DEFINE_CONST_DICT(machine_pin_locals_dict, machine_pin_locals_dict_table); -STATIC mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { (void)errcode; machine_pin_obj_t *self = self_in; @@ -459,7 +459,7 @@ STATIC mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, i return -1; } -STATIC const mp_pin_p_t pin_pin_p = { +static const mp_pin_p_t pin_pin_p = { .ioctl = pin_ioctl, }; @@ -484,7 +484,7 @@ static uint8_t find_eic_id(int pin) { return 0xff; } -STATIC mp_uint_t machine_pin_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { +static mp_uint_t machine_pin_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); uint8_t eic_id = find_eic_id(self->pin_id); if (eic_id != 0xff) { @@ -497,7 +497,7 @@ STATIC mp_uint_t machine_pin_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger return 0; } -STATIC mp_uint_t machine_pin_irq_info(mp_obj_t self_in, mp_uint_t info_type) { +static mp_uint_t machine_pin_irq_info(mp_obj_t self_in, mp_uint_t info_type) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); uint8_t eic_id = find_eic_id(self->pin_id); if (eic_id != 0xff) { @@ -511,7 +511,7 @@ STATIC mp_uint_t machine_pin_irq_info(mp_obj_t self_in, mp_uint_t info_type) { return 0; } -STATIC const mp_irq_methods_t machine_pin_irq_methods = { +static const mp_irq_methods_t machine_pin_irq_methods = { .trigger = machine_pin_irq_trigger, .info = machine_pin_irq_info, }; diff --git a/ports/samd/machine_pwm.c b/ports/samd/machine_pwm.c index 6fc8145372bce..b2a383c21cba1 100644 --- a/ports/samd/machine_pwm.c +++ b/ports/samd/machine_pwm.c @@ -105,21 +105,21 @@ static uint8_t device_status[TCC_INST_NUM]; static uint8_t output_active[TCC_INST_NUM]; const uint16_t prescaler_table[] = {1, 2, 4, 8, 16, 64, 256, 1024}; -STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq); -STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16); -STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns); -STATIC void mp_machine_pwm_start(machine_pwm_obj_t *self); -STATIC void mp_machine_pwm_stop(machine_pwm_obj_t *self); +static void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq); +static void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16); +static void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns); +static void mp_machine_pwm_start(machine_pwm_obj_t *self); +static void mp_machine_pwm_stop(machine_pwm_obj_t *self); -STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_pwm_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "PWM(%q, device=%u, channel=%u, output=%u)", pin_find_by_id(self->pin_id)->name, self->device, self->channel, self->output); } // called by the constructor and init() -STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, +static void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_freq, ARG_duty_u16, ARG_duty_ns, ARG_invert, ARG_device }; static const mp_arg_t allowed_args[] = { @@ -225,7 +225,7 @@ STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, } // PWM(pin) -STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // Check number of arguments mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); @@ -245,7 +245,7 @@ STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args return MP_OBJ_FROM_PTR(self); } -STATIC void mp_machine_pwm_stop(machine_pwm_obj_t *self) { +static void mp_machine_pwm_stop(machine_pwm_obj_t *self) { Tcc *tcc = tcc_instance[self->device]; tcc->CTRLA.bit.ENABLE = 0; while (tcc->SYNCBUSY.reg & TCC_SYNCBUSY_ENABLE) { @@ -271,7 +271,7 @@ void pwm_deinit_all(void) { // switch off that device. // This stops all channels, but keeps the configuration // Calling pwm.freq(n), pwm.duty_x() or pwm.init() will start it again. -STATIC void mp_machine_pwm_deinit(machine_pwm_obj_t *self) { +static void mp_machine_pwm_deinit(machine_pwm_obj_t *self) { mp_hal_clr_pin_mux(self->pin_id); // Switch the output off output_active[self->device] &= ~(1 << self->output); // clear output flasg // Stop the device, if no output is active. @@ -280,7 +280,7 @@ STATIC void mp_machine_pwm_deinit(machine_pwm_obj_t *self) { } } -STATIC void wait_for_register_update(Tcc *tcc) { +static void wait_for_register_update(Tcc *tcc) { // Wait for a period's end (may be long) to have the change settled // Each loop cycle takes at least 1 ms, giving an implicit timeout. for (int i = 0; i < PWM_UPDATE_TIMEOUT; i++) { @@ -293,7 +293,7 @@ STATIC void wait_for_register_update(Tcc *tcc) { tcc->INTFLAG.reg = TCC_INTFLAG_OVF; } -STATIC void mp_machine_pwm_start(machine_pwm_obj_t *self) { +static void mp_machine_pwm_start(machine_pwm_obj_t *self) { // Start the PWM. The period counter is 24 bit or 16 bit with a pre-scaling // of up to 1024, allowing a range from 24 MHz down to 1 Hz. static const uint32_t max_period[5] = {1 << 24, 1 << 24, 1 << 16, 1 << 16, 1 << 16}; @@ -357,16 +357,16 @@ STATIC void mp_machine_pwm_start(machine_pwm_obj_t *self) { tcc->CTRLBCLR.reg = TCC_CTRLBCLR_LUPD; } -STATIC mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) { return MP_OBJ_NEW_SMALL_INT(self->freq); } -STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { +static void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { self->freq = freq; mp_machine_pwm_start(self); } -STATIC mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) { if (duty_type_flags[self->device] & (1 << self->channel)) { return MP_OBJ_NEW_SMALL_INT(get_duty_value(self->device, self->channel)); } else { @@ -374,13 +374,13 @@ STATIC mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) { } } -STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16) { +static void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16) { put_duty_value(self->device, self->channel, duty_u16); duty_type_flags[self->device] |= 1 << self->channel; mp_machine_pwm_start(self); } -STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { +static mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { if (!(duty_type_flags[self->device] & (1 << self->channel))) { return MP_OBJ_NEW_SMALL_INT(get_duty_value(self->device, self->channel)); } else { @@ -388,7 +388,7 @@ STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { } } -STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns) { +static void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns) { put_duty_value(self->device, self->channel, duty_ns); duty_type_flags[self->device] &= ~(1 << self->channel); mp_machine_pwm_start(self); diff --git a/ports/samd/machine_rtc.c b/ports/samd/machine_rtc.c index 1f0c9f4dca990..a906f9176f9fe 100644 --- a/ports/samd/machine_rtc.c +++ b/ports/samd/machine_rtc.c @@ -37,7 +37,7 @@ typedef struct _machine_rtc_obj_t { } machine_rtc_obj_t; // Singleton RTC object. -STATIC const machine_rtc_obj_t machine_rtc_obj = {{&machine_rtc_type}}; +static const machine_rtc_obj_t machine_rtc_obj = {{&machine_rtc_type}}; // Start the RTC Timer. void machine_rtc_start(bool force) { @@ -85,7 +85,7 @@ void rtc_gettime(timeutils_struct_time_t *tm) { tm->tm_sec = RTC->MODE2.CLOCK.bit.SECOND; } -STATIC mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // Check arguments. mp_arg_check_num(n_args, n_kw, 0, 0, false); // RTC was already started at boot time. So nothing to do here. @@ -93,7 +93,7 @@ STATIC mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, s return (mp_obj_t)&machine_rtc_obj; } -STATIC mp_obj_t machine_rtc_datetime_helper(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_rtc_datetime_helper(size_t n_args, const mp_obj_t *args) { // Rtc *rtc = RTC; if (n_args == 1) { // Get date and time. @@ -137,21 +137,21 @@ STATIC mp_obj_t machine_rtc_datetime_helper(size_t n_args, const mp_obj_t *args) } } -STATIC mp_obj_t machine_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) { return machine_rtc_datetime_helper(n_args, args); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_rtc_datetime_obj, 1, 2, machine_rtc_datetime); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_rtc_datetime_obj, 1, 2, machine_rtc_datetime); -STATIC mp_obj_t machine_rtc_init(mp_obj_t self_in, mp_obj_t date) { +static mp_obj_t machine_rtc_init(mp_obj_t self_in, mp_obj_t date) { mp_obj_t args[2] = {self_in, date}; machine_rtc_datetime_helper(2, args); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_rtc_init_obj, machine_rtc_init); +static MP_DEFINE_CONST_FUN_OBJ_2(machine_rtc_init_obj, machine_rtc_init); // calibration(cal) // When the argument is a number in the range [-16 to 15], set the calibration value. -STATIC mp_obj_t machine_rtc_calibration(mp_obj_t self_in, mp_obj_t cal_in) { +static mp_obj_t machine_rtc_calibration(mp_obj_t self_in, mp_obj_t cal_in) { int8_t cal = 0; // Make it negative for a "natural" behavior: // value > 0: faster, value < 0: slower @@ -159,14 +159,14 @@ STATIC mp_obj_t machine_rtc_calibration(mp_obj_t self_in, mp_obj_t cal_in) { RTC->MODE2.FREQCORR.reg = (uint8_t)cal; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_rtc_calibration_obj, machine_rtc_calibration); +static MP_DEFINE_CONST_FUN_OBJ_2(machine_rtc_calibration_obj, machine_rtc_calibration); -STATIC const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_rtc_init_obj) }, { MP_ROM_QSTR(MP_QSTR_datetime), MP_ROM_PTR(&machine_rtc_datetime_obj) }, { MP_ROM_QSTR(MP_QSTR_calibration), MP_ROM_PTR(&machine_rtc_calibration_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(machine_rtc_locals_dict, machine_rtc_locals_dict_table); +static MP_DEFINE_CONST_DICT(machine_rtc_locals_dict, machine_rtc_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( machine_rtc_type, diff --git a/ports/samd/machine_spi.c b/ports/samd/machine_spi.c index 3d5729c1f4264..9c31cc2778dba 100644 --- a/ports/samd/machine_spi.c +++ b/ports/samd/machine_spi.c @@ -80,13 +80,13 @@ void common_spi_irq_handler(int spi_id) { } } -STATIC void machine_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "SPI(%u, baudrate=%u, firstbit=%u, polarity=%u, phase=%u, bits=8)", self->id, self->baudrate, self->firstbit, self->polarity, self->phase); } -STATIC void machine_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void machine_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_baudrate, ARG_polarity, ARG_phase, ARG_firstbit, ARG_sck, ARG_mosi, ARG_miso}; static const mp_arg_t allowed_args[] = { @@ -231,7 +231,7 @@ STATIC void machine_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj } } -STATIC mp_obj_t machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); // Get SPI bus. @@ -260,7 +260,7 @@ STATIC mp_obj_t machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, s return self; } -STATIC void machine_sercom_deinit(mp_obj_base_t *self_in) { +static void machine_sercom_deinit(mp_obj_base_t *self_in) { machine_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); Sercom *spi = sercom_instance[self->id]; // Disable interrupts (if any) @@ -270,7 +270,7 @@ STATIC void machine_sercom_deinit(mp_obj_base_t *self_in) { MP_STATE_PORT(sercom_table[self->id]) = NULL; } -STATIC void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) { +static void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) { machine_spi_obj_t *self = (machine_spi_obj_t *)self_in; Sercom *spi = sercom_instance[self->id]; @@ -316,7 +316,7 @@ STATIC void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8 } -STATIC const mp_machine_spi_p_t machine_spi_p = { +static const mp_machine_spi_p_t machine_spi_p = { .init = machine_spi_init, .deinit = machine_sercom_deinit, .transfer = machine_spi_transfer, diff --git a/ports/samd/machine_uart.c b/ports/samd/machine_uart.c index de6c92c5f5e78..b560e0e8e6924 100644 --- a/ports/samd/machine_uart.c +++ b/ports/samd/machine_uart.c @@ -69,12 +69,12 @@ typedef struct _machine_uart_obj_t { #endif } machine_uart_obj_t; -STATIC const char *_parity_name[] = {"None", "", "0", "1"}; // Is defined as 0, 2, 3 +static const char *_parity_name[] = {"None", "", "0", "1"}; // Is defined as 0, 2, 3 // Irq handler // take all bytes from the fifo and store them in the buffer -STATIC void uart_drain_rx_fifo(machine_uart_obj_t *self, Sercom *uart) { +static void uart_drain_rx_fifo(machine_uart_obj_t *self, Sercom *uart) { while (uart->USART.INTFLAG.bit.RXC != 0) { if (ringbuf_free(&self->read_buffer) > 0) { // get a byte from uart and put into the buffer @@ -114,7 +114,7 @@ void common_uart_irq_handler(int uart_id) { } // Configure the Sercom device -STATIC void machine_sercom_configure(machine_uart_obj_t *self) { +static void machine_sercom_configure(machine_uart_obj_t *self) { Sercom *uart = sercom_instance[self->id]; // Reset (clear) the peripheral registers. @@ -192,7 +192,7 @@ void machine_uart_set_baudrate(mp_obj_t self_in, uint32_t baudrate) { machine_sercom_configure(self); } -STATIC void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "UART(%u, baudrate=%u, bits=%u, parity=%s, stop=%u, " "timeout=%u, timeout_char=%u, rxbuf=%d" @@ -215,7 +215,7 @@ STATIC void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_ ); } -STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_baudrate, ARG_bits, ARG_parity, ARG_stop, ARG_tx, ARG_rx, ARG_timeout, ARG_timeout_char, ARG_rxbuf, ARG_txbuf, ARG_rts, ARG_cts }; static const mp_arg_t allowed_args[] = { @@ -363,7 +363,7 @@ STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, } } -STATIC mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); // Get UART bus. @@ -396,7 +396,7 @@ STATIC mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_arg return MP_OBJ_FROM_PTR(self); } -STATIC void mp_machine_uart_deinit(machine_uart_obj_t *self) { +static void mp_machine_uart_deinit(machine_uart_obj_t *self) { // Check if it is the active object. if (MP_STATE_PORT(sercom_table)[self->id] == self) { Sercom *uart = sercom_instance[self->id]; @@ -409,11 +409,11 @@ STATIC void mp_machine_uart_deinit(machine_uart_obj_t *self) { } } -STATIC mp_int_t mp_machine_uart_any(machine_uart_obj_t *self) { +static mp_int_t mp_machine_uart_any(machine_uart_obj_t *self) { return ringbuf_avail(&self->read_buffer); } -STATIC bool mp_machine_uart_txdone(machine_uart_obj_t *self) { +static bool mp_machine_uart_txdone(machine_uart_obj_t *self) { Sercom *uart = sercom_instance[self->id]; return uart->USART.INTFLAG.bit.DRE @@ -423,7 +423,7 @@ STATIC bool mp_machine_uart_txdone(machine_uart_obj_t *self) { && uart->USART.INTFLAG.bit.TXC; } -STATIC void mp_machine_uart_sendbreak(machine_uart_obj_t *self) { +static void mp_machine_uart_sendbreak(machine_uart_obj_t *self) { uint32_t break_time_us = 13 * 1000000 / self->baudrate; // Wait for the tx buffer to drain. @@ -445,7 +445,7 @@ STATIC void mp_machine_uart_sendbreak(machine_uart_obj_t *self) { mp_hal_set_pin_mux(self->tx, self->tx_pad_config.alt_fct); } -STATIC mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { +static mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); Sercom *uart = sercom_instance[self->id]; uint64_t t = mp_hal_ticks_ms_64() + self->timeout; @@ -475,7 +475,7 @@ STATIC mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t return size; } -STATIC mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { +static mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); size_t i = 0; const uint8_t *src = buf_in; @@ -514,7 +514,7 @@ STATIC mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_ return size; } -STATIC mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { machine_uart_obj_t *self = self_in; mp_uint_t ret; Sercom *uart = sercom_instance[self->id]; diff --git a/ports/samd/machine_wdt.c b/ports/samd/machine_wdt.c index d6fadfd1232db..301abbe90c7cf 100644 --- a/ports/samd/machine_wdt.c +++ b/ports/samd/machine_wdt.c @@ -45,9 +45,9 @@ mp_int_t log2i(mp_int_t num) { return res; } -STATIC const machine_wdt_obj_t machine_wdt = {{&machine_wdt_type}}; +static const machine_wdt_obj_t machine_wdt = {{&machine_wdt_type}}; -STATIC void set_timeout(uint32_t timeout) { +static void set_timeout(uint32_t timeout) { // Set new timeout. Have to disable WDT first. // Confine to the valid range @@ -76,7 +76,7 @@ STATIC void set_timeout(uint32_t timeout) { #endif } -STATIC machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t timeout_ms) { +static machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t timeout_ms) { #if defined(MCU_SAMD51) // Verify the WDT id. SAMD51 only, saving a few bytes for SAMD21 if (id != 0) { @@ -105,12 +105,12 @@ STATIC machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t return (machine_wdt_obj_t *)&machine_wdt; } -STATIC void mp_machine_wdt_feed(machine_wdt_obj_t *self) { +static void mp_machine_wdt_feed(machine_wdt_obj_t *self) { (void)self; WDT->CLEAR.reg = 0xa5; } -STATIC void mp_machine_wdt_timeout_ms_set(machine_wdt_obj_t *self, mp_int_t timeout_ms) { +static void mp_machine_wdt_timeout_ms_set(machine_wdt_obj_t *self, mp_int_t timeout_ms) { (void)self; set_timeout(timeout_ms); } diff --git a/ports/samd/modmachine.c b/ports/samd/modmachine.c index c39aec95ea156..65dbf8a7f5039 100644 --- a/ports/samd/modmachine.c +++ b/ports/samd/modmachine.c @@ -65,7 +65,7 @@ extern bool EIC_occured; extern uint32_t _dbl_tap_addr; -NORETURN STATIC void mp_machine_reset(void) { +NORETURN static void mp_machine_reset(void) { *DBL_TAP_ADDR = DBL_TAP_MAGIC_RESET; #ifdef DBL_TAP_ADDR_ALT *DBL_TAP_ADDR_ALT = DBL_TAP_MAGIC_RESET; @@ -81,28 +81,28 @@ NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) { NVIC_SystemReset(); } -STATIC mp_obj_t mp_machine_get_freq(void) { +static mp_obj_t mp_machine_get_freq(void) { return MP_OBJ_NEW_SMALL_INT(get_cpu_freq()); } -STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) { +static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) { uint32_t freq = mp_obj_get_int(args[0]); if (freq >= 1000000 && freq <= MAX_CPU_FREQ) { set_cpu_freq(freq); } } -STATIC mp_obj_t mp_machine_unique_id(void) { +static mp_obj_t mp_machine_unique_id(void) { samd_unique_id_t id; samd_get_unique_id(&id); return mp_obj_new_bytes((byte *)&id.bytes, sizeof(id.bytes)); } -STATIC void mp_machine_idle(void) { +static void mp_machine_idle(void) { MICROPY_EVENT_POLL_HOOK; } -STATIC mp_int_t mp_machine_reset_cause(void) { +static mp_int_t mp_machine_reset_cause(void) { #if defined(MCU_SAMD21) return PM->RCAUSE.reg; #elif defined(MCU_SAMD51) @@ -112,7 +112,7 @@ STATIC mp_int_t mp_machine_reset_cause(void) { #endif } -STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) { +static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) { int32_t duration = -1; uint32_t freq = get_cpu_freq(); if (n_args > 0) { @@ -164,7 +164,7 @@ STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) { set_cpu_freq(freq); } -NORETURN STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) { +NORETURN static void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) { mp_machine_lightsleep(n_args, args); mp_machine_reset(); } diff --git a/ports/samd/modos.c b/ports/samd/modos.c index 16b9eb084104e..64d40a46cc0a4 100644 --- a/ports/samd/modos.c +++ b/ports/samd/modos.c @@ -40,7 +40,7 @@ #if defined(MCU_SAMD51) static bool initialized = false; -STATIC void trng_start(void) { +static void trng_start(void) { if (!initialized) { MCLK->APBCMASK.bit.TRNG_ = 1; REG_TRNG_CTRLA = TRNG_CTRLA_ENABLE; @@ -73,7 +73,7 @@ uint32_t trng_random_u32(int delay) { #endif #if MICROPY_PY_OS_URANDOM -STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { +static mp_obj_t mp_os_urandom(mp_obj_t num) { mp_int_t n = mp_obj_get_int(num); vstr_t vstr; vstr_init_len(&vstr, n); @@ -89,7 +89,7 @@ STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { } return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); #endif // MICROPY_PY_OS_URANDOM diff --git a/ports/samd/modsamd.c b/ports/samd/modsamd.c index 307de62af56e8..2afe1d1222ed2 100644 --- a/ports/samd/modsamd.c +++ b/ports/samd/modsamd.c @@ -45,7 +45,7 @@ extern const mp_obj_type_t samd_spiflash_type; #define SPIFLASH_TYPE samd_spiflash_type #endif -STATIC mp_obj_t samd_pininfo(mp_obj_t pin_obj) { +static mp_obj_t samd_pininfo(mp_obj_t pin_obj) { const machine_pin_obj_t *pin_af = pin_find(pin_obj); #if defined(MCU_SAMD21) mp_obj_t tuple[7] = { @@ -74,14 +74,14 @@ STATIC mp_obj_t samd_pininfo(mp_obj_t pin_obj) { #endif return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(samd_pininfo_obj, samd_pininfo); +static MP_DEFINE_CONST_FUN_OBJ_1(samd_pininfo_obj, samd_pininfo); -STATIC const mp_rom_map_elem_t samd_module_globals_table[] = { +static const mp_rom_map_elem_t samd_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_samd) }, { MP_ROM_QSTR(MP_QSTR_Flash), MP_ROM_PTR(&SPIFLASH_TYPE) }, { MP_ROM_QSTR(MP_QSTR_pininfo), MP_ROM_PTR(&samd_pininfo_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(samd_module_globals, samd_module_globals_table); +static MP_DEFINE_CONST_DICT(samd_module_globals, samd_module_globals_table); const mp_obj_module_t mp_module_samd = { .base = { &mp_type_module }, diff --git a/ports/samd/modtime.c b/ports/samd/modtime.c index aa5bd33609f08..83072dd16feeb 100644 --- a/ports/samd/modtime.c +++ b/ports/samd/modtime.c @@ -29,7 +29,7 @@ #include "modmachine.h" // Return the localtime as an 8-tuple. -STATIC mp_obj_t mp_time_localtime_get(void) { +static mp_obj_t mp_time_localtime_get(void) { timeutils_struct_time_t tm; rtc_gettime(&tm); tm.tm_wday = timeutils_calc_weekday(tm.tm_year, tm.tm_mon, tm.tm_mday); @@ -48,7 +48,7 @@ STATIC mp_obj_t mp_time_localtime_get(void) { } // Returns the number of seconds, as an integer, since the Epoch. -STATIC mp_obj_t mp_time_time_get(void) { +static mp_obj_t mp_time_time_get(void) { timeutils_struct_time_t tm; rtc_gettime(&tm); return mp_obj_new_int_from_uint(timeutils_mktime( diff --git a/ports/samd/mphalport.c b/ports/samd/mphalport.c index de1650c9914b1..3fc6875908975 100644 --- a/ports/samd/mphalport.c +++ b/ports/samd/mphalport.c @@ -40,7 +40,7 @@ extern volatile uint32_t ticks_us64_upper; -STATIC uint8_t stdin_ringbuf_array[MICROPY_HW_STDIN_BUFFER_LEN]; +static uint8_t stdin_ringbuf_array[MICROPY_HW_STDIN_BUFFER_LEN]; ringbuf_t stdin_ringbuf = { stdin_ringbuf_array, sizeof(stdin_ringbuf_array), 0, 0 }; // Explicitly run the USB stack in case the scheduler is locked (eg we are in an diff --git a/ports/samd/pin_af.c b/ports/samd/pin_af.c index a73c6591dd9a4..5d05b6d18d5c1 100644 --- a/ports/samd/pin_af.c +++ b/ports/samd/pin_af.c @@ -53,7 +53,7 @@ const machine_pin_obj_t *pin_find_by_id(int pin_id) { mp_raise_ValueError(MP_ERROR_TEXT("not a Pin")); } -STATIC const machine_pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name) { +static const machine_pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name) { mp_map_elem_t *named_elem = mp_map_lookup((mp_map_t *)&named_pins->map, name, MP_MAP_LOOKUP); if (named_elem != NULL) { return named_elem->value; diff --git a/ports/samd/samd_flash.c b/ports/samd/samd_flash.c index b00b4af6032bf..ef0de7b6fb585 100644 --- a/ports/samd/samd_flash.c +++ b/ports/samd/samd_flash.c @@ -45,7 +45,7 @@ #endif static struct flash_descriptor flash_desc; -STATIC mp_int_t BLOCK_SIZE = VFS_BLOCK_SIZE_BYTES; // Board specific: mpconfigboard.h +static mp_int_t BLOCK_SIZE = VFS_BLOCK_SIZE_BYTES; // Board specific: mpconfigboard.h extern const mp_obj_type_t samd_flash_type; typedef struct _samd_flash_obj_t { @@ -57,7 +57,7 @@ typedef struct _samd_flash_obj_t { extern uint8_t _oflash_fs, _sflash_fs; // Build a Flash storage at top. -STATIC samd_flash_obj_t samd_flash_obj = { +static samd_flash_obj_t samd_flash_obj = { .base = { &samd_flash_type }, .flash_base = (uint32_t)&_oflash_fs, // Get from MCU-Specific loader script. .flash_size = (uint32_t)&_sflash_fs, // Get from MCU-Specific loader script. @@ -65,7 +65,7 @@ STATIC samd_flash_obj_t samd_flash_obj = { // Flash init (from cctpy) // Method is needed for when MP starts up in _boot.py -STATIC void samd_flash_init(void) { +static void samd_flash_init(void) { #ifdef SAMD51 hri_mclk_set_AHBMASK_NVMCTRL_bit(MCLK); #endif @@ -76,7 +76,7 @@ STATIC void samd_flash_init(void) { flash_init(&flash_desc, NVMCTRL); } -STATIC mp_obj_t samd_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t samd_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // No args required. bdev=Flash(). Start Addr & Size defined in samd_flash_obj. mp_arg_check_num(n_args, n_kw, 0, 0, false); @@ -87,7 +87,7 @@ STATIC mp_obj_t samd_flash_make_new(const mp_obj_type_t *type, size_t n_args, si } // Function for ioctl. -STATIC mp_obj_t eraseblock(uint32_t sector_in) { +static mp_obj_t eraseblock(uint32_t sector_in) { // Destination address aligned with page start to be erased. uint32_t DEST_ADDR = sector_in; // Number of pages to be erased. mp_int_t PAGE_SIZE = flash_get_page_size(&flash_desc); // adf4 API call @@ -97,12 +97,12 @@ STATIC mp_obj_t eraseblock(uint32_t sector_in) { return mp_const_none; } -STATIC mp_obj_t samd_flash_version(void) { +static mp_obj_t samd_flash_version(void) { return MP_OBJ_NEW_SMALL_INT(flash_get_version()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(samd_flash_version_obj, samd_flash_version); +static MP_DEFINE_CONST_FUN_OBJ_0(samd_flash_version_obj, samd_flash_version); -STATIC mp_obj_t samd_flash_readblocks(size_t n_args, const mp_obj_t *args) { +static mp_obj_t samd_flash_readblocks(size_t n_args, const mp_obj_t *args) { uint32_t offset = (mp_obj_get_int(args[1]) * BLOCK_SIZE) + samd_flash_obj.flash_base; mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_WRITE); @@ -115,9 +115,9 @@ STATIC mp_obj_t samd_flash_readblocks(size_t n_args, const mp_obj_t *args) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(samd_flash_readblocks_obj, 3, 4, samd_flash_readblocks); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(samd_flash_readblocks_obj, 3, 4, samd_flash_readblocks); -STATIC mp_obj_t samd_flash_writeblocks(size_t n_args, const mp_obj_t *args) { +static mp_obj_t samd_flash_writeblocks(size_t n_args, const mp_obj_t *args) { uint32_t offset = (mp_obj_get_int(args[1]) * BLOCK_SIZE) + samd_flash_obj.flash_base; mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_READ); @@ -132,9 +132,9 @@ STATIC mp_obj_t samd_flash_writeblocks(size_t n_args, const mp_obj_t *args) { // TODO check return value return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(samd_flash_writeblocks_obj, 3, 4, samd_flash_writeblocks); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(samd_flash_writeblocks_obj, 3, 4, samd_flash_writeblocks); -STATIC mp_obj_t samd_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { +static mp_obj_t samd_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { samd_flash_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t cmd = mp_obj_get_int(cmd_in); @@ -159,15 +159,15 @@ STATIC mp_obj_t samd_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(samd_flash_ioctl_obj, samd_flash_ioctl); +static MP_DEFINE_CONST_FUN_OBJ_3(samd_flash_ioctl_obj, samd_flash_ioctl); -STATIC const mp_rom_map_elem_t samd_flash_locals_dict_table[] = { +static const mp_rom_map_elem_t samd_flash_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_flash_version), MP_ROM_PTR(&samd_flash_version_obj) }, { MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&samd_flash_readblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&samd_flash_writeblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&samd_flash_ioctl_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(samd_flash_locals_dict, samd_flash_locals_dict_table); +static MP_DEFINE_CONST_DICT(samd_flash_locals_dict, samd_flash_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( samd_flash_type, diff --git a/ports/samd/samd_qspiflash.c b/ports/samd/samd_qspiflash.c index 054bfd231e041..60aa434dcfdaa 100644 --- a/ports/samd/samd_qspiflash.c +++ b/ports/samd/samd_qspiflash.c @@ -257,7 +257,7 @@ int get_sfdp_table(uint8_t *table, int maxlen) { return len; } -STATIC mp_obj_t samd_qspiflash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t samd_qspiflash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { mp_arg_check_num(n_args, n_kw, 0, 0, false); // The QSPI is a singleton @@ -374,7 +374,7 @@ STATIC mp_obj_t samd_qspiflash_make_new(const mp_obj_type_t *type, size_t n_args return self; } -STATIC mp_obj_t samd_qspiflash_read(samd_qspiflash_obj_t *self, uint32_t addr, uint8_t *dest, uint32_t len) { +static mp_obj_t samd_qspiflash_read(samd_qspiflash_obj_t *self, uint32_t addr, uint8_t *dest, uint32_t len) { if (len > 0) { wait_for_flash_ready(); // Command 0x6B 1 line address, 4 line Data @@ -385,7 +385,7 @@ STATIC mp_obj_t samd_qspiflash_read(samd_qspiflash_obj_t *self, uint32_t addr, u return mp_const_none; } -STATIC mp_obj_t samd_qspiflash_write(samd_qspiflash_obj_t *self, uint32_t addr, uint8_t *src, uint32_t len) { +static mp_obj_t samd_qspiflash_write(samd_qspiflash_obj_t *self, uint32_t addr, uint8_t *src, uint32_t len) { uint32_t length = len; uint32_t pos = 0; uint8_t *buf = src; @@ -405,7 +405,7 @@ STATIC mp_obj_t samd_qspiflash_write(samd_qspiflash_obj_t *self, uint32_t addr, return mp_const_none; } -STATIC mp_obj_t samd_qspiflash_erase(uint32_t addr) { +static mp_obj_t samd_qspiflash_erase(uint32_t addr) { wait_for_flash_ready(); write_enable(); erase_command(QSPI_CMD_ERASE_SECTOR, addr); @@ -413,7 +413,7 @@ STATIC mp_obj_t samd_qspiflash_erase(uint32_t addr) { return mp_const_none; } -STATIC mp_obj_t samd_qspiflash_readblocks(size_t n_args, const mp_obj_t *args) { +static mp_obj_t samd_qspiflash_readblocks(size_t n_args, const mp_obj_t *args) { samd_qspiflash_obj_t *self = MP_OBJ_TO_PTR(args[0]); uint32_t offset = (mp_obj_get_int(args[1]) * self->sectorsize); mp_buffer_info_t bufinfo; @@ -427,9 +427,9 @@ STATIC mp_obj_t samd_qspiflash_readblocks(size_t n_args, const mp_obj_t *args) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(samd_qspiflash_readblocks_obj, 3, 4, samd_qspiflash_readblocks); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(samd_qspiflash_readblocks_obj, 3, 4, samd_qspiflash_readblocks); -STATIC mp_obj_t samd_qspiflash_writeblocks(size_t n_args, const mp_obj_t *args) { +static mp_obj_t samd_qspiflash_writeblocks(size_t n_args, const mp_obj_t *args) { samd_qspiflash_obj_t *self = MP_OBJ_TO_PTR(args[0]); uint32_t offset = (mp_obj_get_int(args[1]) * self->sectorsize); mp_buffer_info_t bufinfo; @@ -445,9 +445,9 @@ STATIC mp_obj_t samd_qspiflash_writeblocks(size_t n_args, const mp_obj_t *args) // TODO check return value return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(samd_qspiflash_writeblocks_obj, 3, 4, samd_qspiflash_writeblocks); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(samd_qspiflash_writeblocks_obj, 3, 4, samd_qspiflash_writeblocks); -STATIC mp_obj_t samd_qspiflash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { +static mp_obj_t samd_qspiflash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { samd_qspiflash_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t cmd = mp_obj_get_int(cmd_in); @@ -471,14 +471,14 @@ STATIC mp_obj_t samd_qspiflash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(samd_qspiflash_ioctl_obj, samd_qspiflash_ioctl); +static MP_DEFINE_CONST_FUN_OBJ_3(samd_qspiflash_ioctl_obj, samd_qspiflash_ioctl); -STATIC const mp_rom_map_elem_t samd_qspiflash_locals_dict_table[] = { +static const mp_rom_map_elem_t samd_qspiflash_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&samd_qspiflash_readblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&samd_qspiflash_writeblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&samd_qspiflash_ioctl_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(samd_qspiflash_locals_dict, samd_qspiflash_locals_dict_table); +static MP_DEFINE_CONST_DICT(samd_qspiflash_locals_dict, samd_qspiflash_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( samd_qspiflash_type, diff --git a/ports/samd/samd_spiflash.c b/ports/samd/samd_spiflash.c index f17d3c45ca524..1313a6fd9d0d0 100644 --- a/ports/samd/samd_spiflash.c +++ b/ports/samd/samd_spiflash.c @@ -128,7 +128,7 @@ static void get_sfdp(spiflash_obj_t *self, uint32_t addr, uint8_t *buffer, int s mp_hal_pin_write(self->cs, 1); } -STATIC mp_obj_t spiflash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t spiflash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { mp_arg_check_num(n_args, n_kw, 0, 0, false); // Set up the object @@ -179,7 +179,7 @@ STATIC mp_obj_t spiflash_make_new(const mp_obj_type_t *type, size_t n_args, size return self; } -STATIC mp_obj_t spiflash_read(spiflash_obj_t *self, uint32_t addr, uint8_t *dest, uint32_t len) { +static mp_obj_t spiflash_read(spiflash_obj_t *self, uint32_t addr, uint8_t *dest, uint32_t len) { if (len > 0) { write_addr(self, self->commands[_READ_INDEX], addr); spi_transfer(self->spi, len, dest, dest); @@ -189,7 +189,7 @@ STATIC mp_obj_t spiflash_read(spiflash_obj_t *self, uint32_t addr, uint8_t *dest return mp_const_none; } -STATIC mp_obj_t spiflash_write(spiflash_obj_t *self, uint32_t addr, uint8_t *src, uint32_t len) { +static mp_obj_t spiflash_write(spiflash_obj_t *self, uint32_t addr, uint8_t *src, uint32_t len) { uint32_t length = len; uint32_t pos = 0; uint8_t *buf = src; @@ -211,7 +211,7 @@ STATIC mp_obj_t spiflash_write(spiflash_obj_t *self, uint32_t addr, uint8_t *src return mp_const_none; } -STATIC mp_obj_t spiflash_erase(spiflash_obj_t *self, uint32_t addr) { +static mp_obj_t spiflash_erase(spiflash_obj_t *self, uint32_t addr) { write_enable(self); write_addr(self, self->commands[_SECTOR_ERASE_INDEX], addr); mp_hal_pin_write(self->cs, 1); @@ -220,7 +220,7 @@ STATIC mp_obj_t spiflash_erase(spiflash_obj_t *self, uint32_t addr) { return mp_const_none; } -STATIC mp_obj_t spiflash_readblocks(size_t n_args, const mp_obj_t *args) { +static mp_obj_t spiflash_readblocks(size_t n_args, const mp_obj_t *args) { spiflash_obj_t *self = MP_OBJ_TO_PTR(args[0]); uint32_t offset = (mp_obj_get_int(args[1]) * self->sectorsize); mp_buffer_info_t bufinfo; @@ -234,9 +234,9 @@ STATIC mp_obj_t spiflash_readblocks(size_t n_args, const mp_obj_t *args) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(spiflash_readblocks_obj, 3, 4, spiflash_readblocks); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(spiflash_readblocks_obj, 3, 4, spiflash_readblocks); -STATIC mp_obj_t spiflash_writeblocks(size_t n_args, const mp_obj_t *args) { +static mp_obj_t spiflash_writeblocks(size_t n_args, const mp_obj_t *args) { spiflash_obj_t *self = MP_OBJ_TO_PTR(args[0]); uint32_t offset = (mp_obj_get_int(args[1]) * self->sectorsize); mp_buffer_info_t bufinfo; @@ -252,9 +252,9 @@ STATIC mp_obj_t spiflash_writeblocks(size_t n_args, const mp_obj_t *args) { // TODO check return value return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(spiflash_writeblocks_obj, 3, 4, spiflash_writeblocks); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(spiflash_writeblocks_obj, 3, 4, spiflash_writeblocks); -STATIC mp_obj_t spiflash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { +static mp_obj_t spiflash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { spiflash_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t cmd = mp_obj_get_int(cmd_in); @@ -278,14 +278,14 @@ STATIC mp_obj_t spiflash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_i return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(spiflash_ioctl_obj, spiflash_ioctl); +static MP_DEFINE_CONST_FUN_OBJ_3(spiflash_ioctl_obj, spiflash_ioctl); -STATIC const mp_rom_map_elem_t spiflash_locals_dict_table[] = { +static const mp_rom_map_elem_t spiflash_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&spiflash_readblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&spiflash_writeblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&spiflash_ioctl_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(spiflash_locals_dict, spiflash_locals_dict_table); +static MP_DEFINE_CONST_DICT(spiflash_locals_dict, spiflash_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( samd_spiflash_type, diff --git a/ports/stm32/accel.c b/ports/stm32/accel.c index 19e16831ead84..9f1d4ee9a0384 100644 --- a/ports/stm32/accel.c +++ b/ports/stm32/accel.c @@ -89,7 +89,7 @@ void accel_init(void) { #endif } -STATIC void accel_start(void) { +static void accel_start(void) { // start the I2C bus in master mode i2c_init(I2C1, MICROPY_HW_I2C1_SCL, MICROPY_HW_I2C1_SDA, 400000, I2C_TIMEOUT_MS); @@ -153,7 +153,7 @@ typedef struct _pyb_accel_obj_t { int16_t buf[NUM_AXIS * FILT_DEPTH]; } pyb_accel_obj_t; -STATIC pyb_accel_obj_t pyb_accel_obj; +static pyb_accel_obj_t pyb_accel_obj; /// \classmethod \constructor() /// Create and return an accelerometer object. @@ -166,7 +166,7 @@ STATIC pyb_accel_obj_t pyb_accel_obj; /// accel = pyb.Accel() /// pyb.delay(20) /// print(accel.x()) -STATIC mp_obj_t pyb_accel_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pyb_accel_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 0, 0, false); @@ -177,7 +177,7 @@ STATIC mp_obj_t pyb_accel_make_new(const mp_obj_type_t *type, size_t n_args, siz return MP_OBJ_FROM_PTR(&pyb_accel_obj); } -STATIC mp_obj_t read_axis(int axis) { +static mp_obj_t read_axis(int axis) { uint8_t data[1] = { axis }; i2c_writeto(I2C1, ACCEL_ADDR, data, 1, false); i2c_readfrom(I2C1, ACCEL_ADDR, data, 1, true); @@ -186,28 +186,28 @@ STATIC mp_obj_t read_axis(int axis) { /// \method x() /// Get the x-axis value. -STATIC mp_obj_t pyb_accel_x(mp_obj_t self_in) { +static mp_obj_t pyb_accel_x(mp_obj_t self_in) { return read_axis(ACCEL_REG_X); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_accel_x_obj, pyb_accel_x); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_accel_x_obj, pyb_accel_x); /// \method y() /// Get the y-axis value. -STATIC mp_obj_t pyb_accel_y(mp_obj_t self_in) { +static mp_obj_t pyb_accel_y(mp_obj_t self_in) { return read_axis(ACCEL_REG_Y); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_accel_y_obj, pyb_accel_y); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_accel_y_obj, pyb_accel_y); /// \method z() /// Get the z-axis value. -STATIC mp_obj_t pyb_accel_z(mp_obj_t self_in) { +static mp_obj_t pyb_accel_z(mp_obj_t self_in) { return read_axis(ACCEL_REG_Z); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_accel_z_obj, pyb_accel_z); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_accel_z_obj, pyb_accel_z); /// \method tilt() /// Get the tilt register. -STATIC mp_obj_t pyb_accel_tilt(mp_obj_t self_in) { +static mp_obj_t pyb_accel_tilt(mp_obj_t self_in) { #if MICROPY_HW_HAS_MMA7660 uint8_t data[1] = { ACCEL_REG_TILT }; i2c_writeto(I2C1, ACCEL_ADDR, data, 1, false); @@ -218,11 +218,11 @@ STATIC mp_obj_t pyb_accel_tilt(mp_obj_t self_in) { return 0; #endif } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_accel_tilt_obj, pyb_accel_tilt); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_accel_tilt_obj, pyb_accel_tilt); /// \method filtered_xyz() /// Get a 3-tuple of filtered x, y and z values. -STATIC mp_obj_t pyb_accel_filtered_xyz(mp_obj_t self_in) { +static mp_obj_t pyb_accel_filtered_xyz(mp_obj_t self_in) { pyb_accel_obj_t *self = MP_OBJ_TO_PTR(self_in); memmove(self->buf, self->buf + NUM_AXIS, NUM_AXIS * (FILT_DEPTH - 1) * sizeof(int16_t)); @@ -251,9 +251,9 @@ STATIC mp_obj_t pyb_accel_filtered_xyz(mp_obj_t self_in) { return mp_obj_new_tuple(3, tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_accel_filtered_xyz_obj, pyb_accel_filtered_xyz); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_accel_filtered_xyz_obj, pyb_accel_filtered_xyz); -STATIC mp_obj_t pyb_accel_read(mp_obj_t self_in, mp_obj_t reg) { +static mp_obj_t pyb_accel_read(mp_obj_t self_in, mp_obj_t reg) { uint8_t data[1] = { mp_obj_get_int(reg) }; i2c_writeto(I2C1, ACCEL_ADDR, data, 1, false); i2c_readfrom(I2C1, ACCEL_ADDR, data, 1, true); @@ -261,14 +261,14 @@ STATIC mp_obj_t pyb_accel_read(mp_obj_t self_in, mp_obj_t reg) { } MP_DEFINE_CONST_FUN_OBJ_2(pyb_accel_read_obj, pyb_accel_read); -STATIC mp_obj_t pyb_accel_write(mp_obj_t self_in, mp_obj_t reg, mp_obj_t val) { +static mp_obj_t pyb_accel_write(mp_obj_t self_in, mp_obj_t reg, mp_obj_t val) { uint8_t data[2] = { mp_obj_get_int(reg), mp_obj_get_int(val) }; i2c_writeto(I2C1, ACCEL_ADDR, data, 2, true); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_3(pyb_accel_write_obj, pyb_accel_write); -STATIC const mp_rom_map_elem_t pyb_accel_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_accel_locals_dict_table[] = { // TODO add init, deinit, and perhaps reset methods { MP_ROM_QSTR(MP_QSTR_x), MP_ROM_PTR(&pyb_accel_x_obj) }, { MP_ROM_QSTR(MP_QSTR_y), MP_ROM_PTR(&pyb_accel_y_obj) }, @@ -279,7 +279,7 @@ STATIC const mp_rom_map_elem_t pyb_accel_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&pyb_accel_write_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_accel_locals_dict, pyb_accel_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_accel_locals_dict, pyb_accel_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pyb_accel_type, diff --git a/ports/stm32/adc.c b/ports/stm32/adc.c index ddb8a35703bb4..3549fc29a98b8 100644 --- a/ports/stm32/adc.c +++ b/ports/stm32/adc.c @@ -245,7 +245,7 @@ static inline uint32_t adc_get_internal_channel(uint32_t channel) { return channel; } -STATIC bool is_adcx_channel(int channel) { +static bool is_adcx_channel(int channel) { #if defined(STM32F411xE) // The HAL has an incorrect IS_ADC_CHANNEL macro for the F411 so we check for temp return IS_ADC_CHANNEL(channel) || channel == ADC_CHANNEL_TEMPSENSOR; @@ -272,7 +272,7 @@ STATIC bool is_adcx_channel(int channel) { #endif } -STATIC void adc_wait_for_eoc_or_timeout(ADC_HandleTypeDef *adcHandle, int32_t timeout) { +static void adc_wait_for_eoc_or_timeout(ADC_HandleTypeDef *adcHandle, int32_t timeout) { uint32_t tickstart = HAL_GetTick(); #if defined(STM32F4) || defined(STM32F7) || defined(STM32L1) while ((adcHandle->Instance->SR & ADC_FLAG_EOC) != ADC_FLAG_EOC) { @@ -287,7 +287,7 @@ STATIC void adc_wait_for_eoc_or_timeout(ADC_HandleTypeDef *adcHandle, int32_t ti } } -STATIC void adcx_clock_enable(ADC_HandleTypeDef *adch) { +static void adcx_clock_enable(ADC_HandleTypeDef *adch) { #if defined(STM32F0) || defined(STM32F4) || defined(STM32F7) || defined(STM32L1) ADCx_CLK_ENABLE(); #elif defined(STM32H7A3xx) || defined(STM32H7A3xxQ) || defined(STM32H7B3xx) || defined(STM32H7B3xxQ) @@ -316,7 +316,7 @@ STATIC void adcx_clock_enable(ADC_HandleTypeDef *adch) { #endif } -STATIC void adcx_init_periph(ADC_HandleTypeDef *adch, uint32_t resolution) { +static void adcx_init_periph(ADC_HandleTypeDef *adch, uint32_t resolution) { adcx_clock_enable(adch); adch->Init.Resolution = resolution; @@ -384,7 +384,7 @@ STATIC void adcx_init_periph(ADC_HandleTypeDef *adch, uint32_t resolution) { #endif } -STATIC void adc_init_single(pyb_obj_adc_t *adc_obj, ADC_TypeDef *adc) { +static void adc_init_single(pyb_obj_adc_t *adc_obj, ADC_TypeDef *adc) { adc_obj->handle.Instance = adc; adcx_init_periph(&adc_obj->handle, ADC_RESOLUTION_12B); @@ -397,7 +397,7 @@ STATIC void adc_init_single(pyb_obj_adc_t *adc_obj, ADC_TypeDef *adc) { #endif } -STATIC void adc_config_channel(ADC_HandleTypeDef *adc_handle, uint32_t channel) { +static void adc_config_channel(ADC_HandleTypeDef *adc_handle, uint32_t channel) { ADC_ChannelConfTypeDef sConfig; #if defined(STM32G0) || defined(STM32G4) || defined(STM32H5) || defined(STM32H7) || defined(STM32L4) || defined(STM32WB) @@ -462,7 +462,7 @@ STATIC void adc_config_channel(ADC_HandleTypeDef *adc_handle, uint32_t channel) HAL_ADC_ConfigChannel(adc_handle, &sConfig); } -STATIC uint32_t adc_read_channel(ADC_HandleTypeDef *adcHandle) { +static uint32_t adc_read_channel(ADC_HandleTypeDef *adcHandle) { uint32_t value; #if defined(STM32G4) // For STM32G4 there is errata 2.7.7, "Wrong ADC result if conversion done late after @@ -479,7 +479,7 @@ STATIC uint32_t adc_read_channel(ADC_HandleTypeDef *adcHandle) { return value; } -STATIC uint32_t adc_config_and_read_channel(ADC_HandleTypeDef *adcHandle, uint32_t channel) { +static uint32_t adc_config_and_read_channel(ADC_HandleTypeDef *adcHandle, uint32_t channel) { adc_config_channel(adcHandle, channel); uint32_t raw_value = adc_read_channel(adcHandle); @@ -498,7 +498,7 @@ STATIC uint32_t adc_config_and_read_channel(ADC_HandleTypeDef *adcHandle, uint32 /******************************************************************************/ /* MicroPython bindings : adc object (single channel) */ -STATIC void adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_obj_adc_t *self = MP_OBJ_TO_PTR(self_in); #if defined STM32H5 unsigned adc_id = 1; @@ -516,7 +516,7 @@ STATIC void adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t /// \classmethod \constructor(pin) /// Create an ADC object associated with the given pin. /// This allows you to then read analog values on that pin. -STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check number of arguments mp_arg_check_num(n_args, n_kw, 1, 1, false); @@ -587,11 +587,11 @@ STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ /// \method read() /// Read the value on the analog pin and return it. The returned value /// will be between 0 and 4095. -STATIC mp_obj_t adc_read(mp_obj_t self_in) { +static mp_obj_t adc_read(mp_obj_t self_in) { pyb_obj_adc_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_int(adc_config_and_read_channel(&self->handle, self->channel)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_read_obj, adc_read); +static MP_DEFINE_CONST_FUN_OBJ_1(adc_read_obj, adc_read); /// \method read_timed(buf, timer) /// @@ -627,7 +627,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_read_obj, adc_read); /// print(val) # print the value out /// /// This function does not allocate any memory. -STATIC mp_obj_t adc_read_timed(mp_obj_t self_in, mp_obj_t buf_in, mp_obj_t freq_in) { +static mp_obj_t adc_read_timed(mp_obj_t self_in, mp_obj_t buf_in, mp_obj_t freq_in) { pyb_obj_adc_t *self = MP_OBJ_TO_PTR(self_in); mp_buffer_info_t bufinfo; @@ -699,7 +699,7 @@ STATIC mp_obj_t adc_read_timed(mp_obj_t self_in, mp_obj_t buf_in, mp_obj_t freq_ return mp_obj_new_int(bufinfo.len); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(adc_read_timed_obj, adc_read_timed); +static MP_DEFINE_CONST_FUN_OBJ_3(adc_read_timed_obj, adc_read_timed); // read_timed_multi((adcx, adcy, ...), (bufx, bufy, ...), timer) // @@ -709,7 +709,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(adc_read_timed_obj, adc_read_timed); // the sample resolution will be reduced to 8 bits. // // This function should not allocate any heap memory. -STATIC mp_obj_t adc_read_timed_multi(mp_obj_t adc_array_in, mp_obj_t buf_array_in, mp_obj_t tim_in) { +static mp_obj_t adc_read_timed_multi(mp_obj_t adc_array_in, mp_obj_t buf_array_in, mp_obj_t tim_in) { size_t nadcs, nbufs; mp_obj_t *adc_array, *buf_array; mp_obj_get_array(adc_array_in, &nadcs, &adc_array); @@ -802,16 +802,16 @@ STATIC mp_obj_t adc_read_timed_multi(mp_obj_t adc_array_in, mp_obj_t buf_array_i return mp_obj_new_bool(success); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(adc_read_timed_multi_fun_obj, adc_read_timed_multi); -STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(adc_read_timed_multi_obj, MP_ROM_PTR(&adc_read_timed_multi_fun_obj)); +static MP_DEFINE_CONST_FUN_OBJ_3(adc_read_timed_multi_fun_obj, adc_read_timed_multi); +static MP_DEFINE_CONST_STATICMETHOD_OBJ(adc_read_timed_multi_obj, MP_ROM_PTR(&adc_read_timed_multi_fun_obj)); -STATIC const mp_rom_map_elem_t adc_locals_dict_table[] = { +static const mp_rom_map_elem_t adc_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&adc_read_obj) }, { MP_ROM_QSTR(MP_QSTR_read_timed), MP_ROM_PTR(&adc_read_timed_obj) }, { MP_ROM_QSTR(MP_QSTR_read_timed_multi), MP_ROM_PTR(&adc_read_timed_multi_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(adc_locals_dict, adc_locals_dict_table); +static MP_DEFINE_CONST_DICT(adc_locals_dict, adc_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pyb_adc_type, @@ -897,7 +897,7 @@ int adc_get_resolution(ADC_HandleTypeDef *adcHandle) { return 12; } -STATIC uint32_t adc_config_and_read_ref(ADC_HandleTypeDef *adcHandle, uint32_t channel) { +static uint32_t adc_config_and_read_ref(ADC_HandleTypeDef *adcHandle, uint32_t channel) { uint32_t raw_value = adc_config_and_read_channel(adcHandle, channel); // Scale raw reading to the number of bits used by the calibration constants return raw_value << (ADC_CAL_BITS - adc_get_resolution(adcHandle)); @@ -919,7 +919,7 @@ int adc_read_core_temp(ADC_HandleTypeDef *adcHandle) { #if MICROPY_PY_BUILTINS_FLOAT // correction factor for reference value -STATIC volatile float adc_refcor = 1.0f; +static volatile float adc_refcor = 1.0f; float adc_read_core_temp_float(ADC_HandleTypeDef *adcHandle) { #if defined(STM32G4) || defined(STM32L1) || defined(STM32L4) @@ -974,7 +974,7 @@ float adc_read_core_vref(ADC_HandleTypeDef *adcHandle) { /******************************************************************************/ /* MicroPython bindings : adc_all object */ -STATIC mp_obj_t adc_all_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t adc_all_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check number of arguments mp_arg_check_num(n_args, n_kw, 1, 2, false); @@ -990,7 +990,7 @@ STATIC mp_obj_t adc_all_make_new(const mp_obj_type_t *type, size_t n_args, size_ return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t adc_all_read_channel(mp_obj_t self_in, mp_obj_t channel) { +static mp_obj_t adc_all_read_channel(mp_obj_t self_in, mp_obj_t channel) { pyb_adc_all_obj_t *self = MP_OBJ_TO_PTR(self_in); uint32_t chan = adc_get_internal_channel(mp_obj_get_int(channel)); if (!is_adcx_channel(chan)) { @@ -999,9 +999,9 @@ STATIC mp_obj_t adc_all_read_channel(mp_obj_t self_in, mp_obj_t channel) { uint32_t data = adc_config_and_read_channel(&self->handle, chan); return mp_obj_new_int(data); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(adc_all_read_channel_obj, adc_all_read_channel); +static MP_DEFINE_CONST_FUN_OBJ_2(adc_all_read_channel_obj, adc_all_read_channel); -STATIC mp_obj_t adc_all_read_core_temp(mp_obj_t self_in) { +static mp_obj_t adc_all_read_core_temp(mp_obj_t self_in) { pyb_adc_all_obj_t *self = MP_OBJ_TO_PTR(self_in); #if MICROPY_PY_BUILTINS_FLOAT float data = adc_read_core_temp_float(&self->handle); @@ -1011,32 +1011,32 @@ STATIC mp_obj_t adc_all_read_core_temp(mp_obj_t self_in) { return mp_obj_new_int(data); #endif } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_all_read_core_temp_obj, adc_all_read_core_temp); +static MP_DEFINE_CONST_FUN_OBJ_1(adc_all_read_core_temp_obj, adc_all_read_core_temp); #if MICROPY_PY_BUILTINS_FLOAT -STATIC mp_obj_t adc_all_read_core_vbat(mp_obj_t self_in) { +static mp_obj_t adc_all_read_core_vbat(mp_obj_t self_in) { pyb_adc_all_obj_t *self = MP_OBJ_TO_PTR(self_in); float data = adc_read_core_vbat(&self->handle); return mp_obj_new_float(data); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_all_read_core_vbat_obj, adc_all_read_core_vbat); +static MP_DEFINE_CONST_FUN_OBJ_1(adc_all_read_core_vbat_obj, adc_all_read_core_vbat); -STATIC mp_obj_t adc_all_read_core_vref(mp_obj_t self_in) { +static mp_obj_t adc_all_read_core_vref(mp_obj_t self_in) { pyb_adc_all_obj_t *self = MP_OBJ_TO_PTR(self_in); float data = adc_read_core_vref(&self->handle); return mp_obj_new_float(data); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_all_read_core_vref_obj, adc_all_read_core_vref); +static MP_DEFINE_CONST_FUN_OBJ_1(adc_all_read_core_vref_obj, adc_all_read_core_vref); -STATIC mp_obj_t adc_all_read_vref(mp_obj_t self_in) { +static mp_obj_t adc_all_read_vref(mp_obj_t self_in) { pyb_adc_all_obj_t *self = MP_OBJ_TO_PTR(self_in); adc_read_core_vref(&self->handle); return mp_obj_new_float(ADC_SCALE_V * adc_refcor); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_all_read_vref_obj, adc_all_read_vref); +static MP_DEFINE_CONST_FUN_OBJ_1(adc_all_read_vref_obj, adc_all_read_vref); #endif -STATIC const mp_rom_map_elem_t adc_all_locals_dict_table[] = { +static const mp_rom_map_elem_t adc_all_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_read_channel), MP_ROM_PTR(&adc_all_read_channel_obj) }, { MP_ROM_QSTR(MP_QSTR_read_core_temp), MP_ROM_PTR(&adc_all_read_core_temp_obj) }, #if MICROPY_PY_BUILTINS_FLOAT @@ -1046,7 +1046,7 @@ STATIC const mp_rom_map_elem_t adc_all_locals_dict_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(adc_all_locals_dict, adc_all_locals_dict_table); +static MP_DEFINE_CONST_DICT(adc_all_locals_dict, adc_all_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pyb_adc_all_type, diff --git a/ports/stm32/boardctrl.c b/ports/stm32/boardctrl.c index 85a42a240ff0d..8f0d066f372b4 100644 --- a/ports/stm32/boardctrl.c +++ b/ports/stm32/boardctrl.c @@ -55,7 +55,7 @@ NORETURN void boardctrl_fatal_error(const char *msg) { } } -STATIC void flash_error(int n) { +static void flash_error(int n) { for (int i = 0; i < n; i++) { led_state(PYB_LED_RED, 1); led_state(PYB_LED_GREEN, 0); @@ -88,7 +88,7 @@ void boardctrl_maybe_enter_mboot(size_t n_args, const void *args_in) { #endif #if !MICROPY_HW_USES_BOOTLOADER -STATIC uint update_reset_mode(uint reset_mode) { +static uint update_reset_mode(uint reset_mode) { // Note: Must use HAL_Delay here as MicroPython is not yet initialised // and mp_hal_delay_ms will attempt to invoke the scheduler. diff --git a/ports/stm32/boards/ADAFRUIT_F405_EXPRESS/bdev.c b/ports/stm32/boards/ADAFRUIT_F405_EXPRESS/bdev.c index 402d5b83a97bc..3a6336bc2c756 100644 --- a/ports/stm32/boards/ADAFRUIT_F405_EXPRESS/bdev.c +++ b/ports/stm32/boards/ADAFRUIT_F405_EXPRESS/bdev.c @@ -4,7 +4,7 @@ #if !MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE -STATIC const spi_proto_cfg_t spi_bus = { +static const spi_proto_cfg_t spi_bus = { .spi = &spi_obj[0], // SPI1 .baudrate = 25000000, .polarity = 0, @@ -13,7 +13,7 @@ STATIC const spi_proto_cfg_t spi_bus = { .firstbit = SPI_FIRSTBIT_MSB, }; -STATIC mp_spiflash_cache_t spi_bdev_cache; +static mp_spiflash_cache_t spi_bdev_cache; const mp_spiflash_config_t spiflash_config = { .bus_kind = MP_SPIFLASH_BUS_SPI, diff --git a/ports/stm32/boards/ARDUINO_GIGA/bdev.c b/ports/stm32/boards/ARDUINO_GIGA/bdev.c index caadc2b649eed..fea6241686a08 100644 --- a/ports/stm32/boards/ARDUINO_GIGA/bdev.c +++ b/ports/stm32/boards/ARDUINO_GIGA/bdev.c @@ -29,7 +29,7 @@ #if MICROPY_HW_SPIFLASH_ENABLE_CACHE // Shared cache for first and second SPI block devices -STATIC mp_spiflash_cache_t spi_bdev_cache; +static mp_spiflash_cache_t spi_bdev_cache; #endif // First external SPI flash uses hardware QSPI interface diff --git a/ports/stm32/boards/ARDUINO_NICLA_VISION/bdev.c b/ports/stm32/boards/ARDUINO_NICLA_VISION/bdev.c index caadc2b649eed..fea6241686a08 100644 --- a/ports/stm32/boards/ARDUINO_NICLA_VISION/bdev.c +++ b/ports/stm32/boards/ARDUINO_NICLA_VISION/bdev.c @@ -29,7 +29,7 @@ #if MICROPY_HW_SPIFLASH_ENABLE_CACHE // Shared cache for first and second SPI block devices -STATIC mp_spiflash_cache_t spi_bdev_cache; +static mp_spiflash_cache_t spi_bdev_cache; #endif // First external SPI flash uses hardware QSPI interface diff --git a/ports/stm32/boards/ARDUINO_PORTENTA_H7/bdev.c b/ports/stm32/boards/ARDUINO_PORTENTA_H7/bdev.c index bba81990cf90b..1e9248636828f 100644 --- a/ports/stm32/boards/ARDUINO_PORTENTA_H7/bdev.c +++ b/ports/stm32/boards/ARDUINO_PORTENTA_H7/bdev.c @@ -29,7 +29,7 @@ #if MICROPY_HW_SPIFLASH_ENABLE_CACHE // Shared cache for first and second SPI block devices -STATIC mp_spiflash_cache_t spi_bdev_cache; +static mp_spiflash_cache_t spi_bdev_cache; #endif // First external SPI flash uses hardware QSPI interface diff --git a/ports/stm32/boards/LEGO_HUB_NO6/bdev.c b/ports/stm32/boards/LEGO_HUB_NO6/bdev.c index c90614a0289a0..0c9b6e4797190 100644 --- a/ports/stm32/boards/LEGO_HUB_NO6/bdev.c +++ b/ports/stm32/boards/LEGO_HUB_NO6/bdev.c @@ -32,7 +32,7 @@ // Mboot doesn't support hardware SPI, so use software SPI instead. -STATIC const mp_soft_spi_obj_t soft_spi_bus = { +static const mp_soft_spi_obj_t soft_spi_bus = { .delay_half = MICROPY_HW_SOFTSPI_MIN_DELAY, .polarity = 0, .phase = 0, @@ -52,7 +52,7 @@ mp_spiflash_t board_mboot_spiflash; #else -STATIC const spi_proto_cfg_t spi_bus = { +static const spi_proto_cfg_t spi_bus = { .spi = &spi_obj[1], // SPI2 hardware peripheral .baudrate = 25000000, .polarity = 0, @@ -61,7 +61,7 @@ STATIC const spi_proto_cfg_t spi_bus = { .firstbit = SPI_FIRSTBIT_MSB, }; -STATIC mp_spiflash_cache_t spi_bdev_cache; +static mp_spiflash_cache_t spi_bdev_cache; const mp_spiflash_config_t spiflash_config = { .bus_kind = MP_SPIFLASH_BUS_SPI, diff --git a/ports/stm32/boards/LEGO_HUB_NO6/cc2564.c b/ports/stm32/boards/LEGO_HUB_NO6/cc2564.c index 6ec20935f001a..b47c1aafc2400 100644 --- a/ports/stm32/boards/LEGO_HUB_NO6/cc2564.c +++ b/ports/stm32/boards/LEGO_HUB_NO6/cc2564.c @@ -44,7 +44,7 @@ #define CC2564_TIMER_BT_SLOWCLOCK_TIM_CH 4 #endif -STATIC void cc2564_wait_cts_low(mp_hal_pin_obj_t cts, uint32_t timeout_ms) { +static void cc2564_wait_cts_low(mp_hal_pin_obj_t cts, uint32_t timeout_ms) { for (int i = 0; i < timeout_ms; ++i) { if (mp_hal_pin_read(cts) == 0) { break; diff --git a/ports/stm32/boards/MIKROE_QUAIL/bdev.c b/ports/stm32/boards/MIKROE_QUAIL/bdev.c index 7095817e494cc..913b308339ebd 100644 --- a/ports/stm32/boards/MIKROE_QUAIL/bdev.c +++ b/ports/stm32/boards/MIKROE_QUAIL/bdev.c @@ -4,7 +4,7 @@ #if !MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE -STATIC const spi_proto_cfg_t spi_bus = { +static const spi_proto_cfg_t spi_bus = { .spi = &spi_obj[2], // SPI3 hardware peripheral .baudrate = 25000000, .polarity = 0, @@ -13,7 +13,7 @@ STATIC const spi_proto_cfg_t spi_bus = { .firstbit = SPI_FIRSTBIT_MSB, }; -STATIC mp_spiflash_cache_t spi_bdev_cache; +static mp_spiflash_cache_t spi_bdev_cache; const mp_spiflash_config_t spiflash_config = { .bus_kind = MP_SPIFLASH_BUS_SPI, diff --git a/ports/stm32/boards/PYBD_SF2/bdev.c b/ports/stm32/boards/PYBD_SF2/bdev.c index fba0b8f22790a..2c9dd5b0d4577 100644 --- a/ports/stm32/boards/PYBD_SF2/bdev.c +++ b/ports/stm32/boards/PYBD_SF2/bdev.c @@ -29,12 +29,12 @@ #if MICROPY_HW_SPIFLASH_ENABLE_CACHE // Shared cache for first and second SPI block devices -STATIC mp_spiflash_cache_t spi_bdev_cache; +static mp_spiflash_cache_t spi_bdev_cache; #endif // First external SPI flash uses software QSPI interface -STATIC const mp_soft_qspi_obj_t soft_qspi_bus = { +static const mp_soft_qspi_obj_t soft_qspi_bus = { .cs = MICROPY_HW_SPIFLASH_CS, .clk = MICROPY_HW_SPIFLASH_SCK, .io0 = MICROPY_HW_SPIFLASH_IO0, diff --git a/ports/stm32/boards/SPARKFUN_MICROMOD_STM32/bdev.c b/ports/stm32/boards/SPARKFUN_MICROMOD_STM32/bdev.c index dd62a0eb17fd1..0e23a9df6aab8 100644 --- a/ports/stm32/boards/SPARKFUN_MICROMOD_STM32/bdev.c +++ b/ports/stm32/boards/SPARKFUN_MICROMOD_STM32/bdev.c @@ -4,7 +4,7 @@ // External SPI flash uses standard SPI interface -STATIC const mp_soft_spi_obj_t soft_spi_bus = { +static const mp_soft_spi_obj_t soft_spi_bus = { .delay_half = MICROPY_HW_SOFTSPI_MIN_DELAY, .polarity = 0, .phase = 0, @@ -13,7 +13,7 @@ STATIC const mp_soft_spi_obj_t soft_spi_bus = { .miso = MICROPY_HW_SPIFLASH_MISO, }; -STATIC mp_spiflash_cache_t spi_bdev_cache; +static mp_spiflash_cache_t spi_bdev_cache; const mp_spiflash_config_t spiflash_config = { .bus_kind = MP_SPIFLASH_BUS_SPI, diff --git a/ports/stm32/boards/STM32F769DISC/board_init.c b/ports/stm32/boards/STM32F769DISC/board_init.c index e89d187fece7a..578dc9adb6c82 100644 --- a/ports/stm32/boards/STM32F769DISC/board_init.c +++ b/ports/stm32/boards/STM32F769DISC/board_init.c @@ -4,7 +4,7 @@ // This configuration is needed for mboot to be able to write to the external QSPI flash #if MICROPY_HW_SPIFLASH_ENABLE_CACHE -STATIC mp_spiflash_cache_t spi_bdev_cache; +static mp_spiflash_cache_t spi_bdev_cache; #endif const mp_spiflash_config_t spiflash_config = { diff --git a/ports/stm32/boards/STM32L476DISC/bdev.c b/ports/stm32/boards/STM32L476DISC/bdev.c index c76eb6e2c9077..b5628c4fba793 100644 --- a/ports/stm32/boards/STM32L476DISC/bdev.c +++ b/ports/stm32/boards/STM32L476DISC/bdev.c @@ -2,7 +2,7 @@ // External SPI flash uses standard SPI interface -STATIC const mp_soft_spi_obj_t soft_spi_bus = { +static const mp_soft_spi_obj_t soft_spi_bus = { .delay_half = MICROPY_HW_SOFTSPI_MIN_DELAY, .polarity = 0, .phase = 0, @@ -11,7 +11,7 @@ STATIC const mp_soft_spi_obj_t soft_spi_bus = { .miso = MICROPY_HW_SPIFLASH_MISO, }; -STATIC mp_spiflash_cache_t spi_bdev_cache; +static mp_spiflash_cache_t spi_bdev_cache; const mp_spiflash_config_t spiflash_config = { .bus_kind = MP_SPIFLASH_BUS_SPI, diff --git a/ports/stm32/boards/VCC_GND_F407VE/bdev.c b/ports/stm32/boards/VCC_GND_F407VE/bdev.c index dd62a0eb17fd1..0e23a9df6aab8 100644 --- a/ports/stm32/boards/VCC_GND_F407VE/bdev.c +++ b/ports/stm32/boards/VCC_GND_F407VE/bdev.c @@ -4,7 +4,7 @@ // External SPI flash uses standard SPI interface -STATIC const mp_soft_spi_obj_t soft_spi_bus = { +static const mp_soft_spi_obj_t soft_spi_bus = { .delay_half = MICROPY_HW_SOFTSPI_MIN_DELAY, .polarity = 0, .phase = 0, @@ -13,7 +13,7 @@ STATIC const mp_soft_spi_obj_t soft_spi_bus = { .miso = MICROPY_HW_SPIFLASH_MISO, }; -STATIC mp_spiflash_cache_t spi_bdev_cache; +static mp_spiflash_cache_t spi_bdev_cache; const mp_spiflash_config_t spiflash_config = { .bus_kind = MP_SPIFLASH_BUS_SPI, diff --git a/ports/stm32/boards/VCC_GND_F407ZG/bdev.c b/ports/stm32/boards/VCC_GND_F407ZG/bdev.c index dd62a0eb17fd1..0e23a9df6aab8 100644 --- a/ports/stm32/boards/VCC_GND_F407ZG/bdev.c +++ b/ports/stm32/boards/VCC_GND_F407ZG/bdev.c @@ -4,7 +4,7 @@ // External SPI flash uses standard SPI interface -STATIC const mp_soft_spi_obj_t soft_spi_bus = { +static const mp_soft_spi_obj_t soft_spi_bus = { .delay_half = MICROPY_HW_SOFTSPI_MIN_DELAY, .polarity = 0, .phase = 0, @@ -13,7 +13,7 @@ STATIC const mp_soft_spi_obj_t soft_spi_bus = { .miso = MICROPY_HW_SPIFLASH_MISO, }; -STATIC mp_spiflash_cache_t spi_bdev_cache; +static mp_spiflash_cache_t spi_bdev_cache; const mp_spiflash_config_t spiflash_config = { .bus_kind = MP_SPIFLASH_BUS_SPI, diff --git a/ports/stm32/can.c b/ports/stm32/can.c index 9248e216c9782..27d29207227ba 100644 --- a/ports/stm32/can.c +++ b/ports/stm32/can.c @@ -312,7 +312,7 @@ HAL_StatusTypeDef CAN_Transmit(CAN_HandleTypeDef *hcan, uint32_t Timeout) { } } -STATIC void can_rx_irq_handler(uint can_id, uint fifo_id) { +static void can_rx_irq_handler(uint can_id, uint fifo_id) { mp_obj_t callback; pyb_can_obj_t *self; mp_obj_t irq_reason = MP_OBJ_NEW_SMALL_INT(0); @@ -354,7 +354,7 @@ STATIC void can_rx_irq_handler(uint can_id, uint fifo_id) { pyb_can_handle_callback(self, fifo_id, callback, irq_reason); } -STATIC void can_sce_irq_handler(uint can_id) { +static void can_sce_irq_handler(uint can_id) { pyb_can_obj_t *self = MP_STATE_PORT(pyb_can_obj_all)[can_id - 1]; if (self) { self->can.Instance->MSR = CAN_MSR_ERRI; diff --git a/ports/stm32/dac.c b/ports/stm32/dac.c index 252af369c0087..54d5acc6cea9d 100644 --- a/ports/stm32/dac.c +++ b/ports/stm32/dac.c @@ -71,7 +71,7 @@ #endif #if defined(TIM6) -STATIC void TIM6_Config(uint freq) { +static void TIM6_Config(uint freq) { // Init TIM6 at the required frequency (in Hz) TIM_HandleTypeDef *tim = timer_tim6_init(freq); @@ -86,7 +86,7 @@ STATIC void TIM6_Config(uint freq) { } #endif -STATIC uint32_t TIMx_Config(mp_obj_t timer) { +static uint32_t TIMx_Config(mp_obj_t timer) { // TRGO selection to trigger DAC TIM_HandleTypeDef *tim = pyb_timer_get_handle(timer); TIM_MasterConfigTypeDef config; @@ -122,7 +122,7 @@ STATIC uint32_t TIMx_Config(mp_obj_t timer) { } } -STATIC void dac_deinit(uint32_t dac_channel) { +static void dac_deinit(uint32_t dac_channel) { DAC->CR &= ~(DAC_CR_EN1 << dac_channel); #if defined(STM32G0) || defined(STM32G4) || defined(STM32H5) || defined(STM32H7) || defined(STM32L4) DAC->MCR = (DAC->MCR & ~(DAC_MCR_MODE1_Msk << dac_channel)) | (DAC_OUTPUTBUFFER_DISABLE << dac_channel); @@ -138,7 +138,7 @@ void dac_deinit_all(void) { #endif } -STATIC void dac_config_channel(uint32_t dac_channel, uint32_t trig, uint32_t outbuf) { +static void dac_config_channel(uint32_t dac_channel, uint32_t trig, uint32_t outbuf) { DAC->CR &= ~(DAC_CR_EN1 << dac_channel); uint32_t cr_off = DAC_CR_DMAEN1 | DAC_CR_MAMP1 | DAC_CR_WAVE1 | DAC_CR_TSEL1 | DAC_CR_TEN1; uint32_t cr_on = trig; @@ -151,7 +151,7 @@ STATIC void dac_config_channel(uint32_t dac_channel, uint32_t trig, uint32_t out DAC->CR = (DAC->CR & ~(cr_off << dac_channel)) | (cr_on << dac_channel); } -STATIC void dac_set_value(uint32_t dac_channel, uint32_t align, uint32_t value) { +static void dac_set_value(uint32_t dac_channel, uint32_t align, uint32_t value) { uint32_t base; if (dac_channel == DAC_CHANNEL_1) { base = (uint32_t)&DAC->DHR12R1; @@ -163,11 +163,11 @@ STATIC void dac_set_value(uint32_t dac_channel, uint32_t align, uint32_t value) *(volatile uint32_t *)(base + align) = value; } -STATIC void dac_start(uint32_t dac_channel) { +static void dac_start(uint32_t dac_channel) { DAC->CR |= DAC_CR_EN1 << dac_channel; } -STATIC void dac_start_dma(uint32_t dac_channel, const dma_descr_t *dma_descr, uint32_t dma_mode, uint32_t bit_size, uint32_t dac_align, size_t len, void *buf) { +static void dac_start_dma(uint32_t dac_channel, const dma_descr_t *dma_descr, uint32_t dma_mode, uint32_t bit_size, uint32_t dac_align, size_t len, void *buf) { uint32_t dma_align; if (bit_size == 8) { #if defined(STM32G4) @@ -216,9 +216,9 @@ typedef struct _pyb_dac_obj_t { uint8_t outbuf_waveform; } pyb_dac_obj_t; -STATIC pyb_dac_obj_t pyb_dac_obj[2]; +static pyb_dac_obj_t pyb_dac_obj[2]; -STATIC void pyb_dac_reconfigure(pyb_dac_obj_t *self, uint32_t cr, uint32_t outbuf, uint32_t value) { +static void pyb_dac_reconfigure(pyb_dac_obj_t *self, uint32_t cr, uint32_t outbuf, uint32_t value) { bool restart = false; const uint32_t cr_mask = DAC_CR_DMAEN1 | DAC_CR_MAMP1 | DAC_CR_WAVE1 | DAC_CR_TSEL1 | DAC_CR_TEN1 | DAC_CR_EN1; if (((DAC->CR >> self->dac_channel) & cr_mask) != (cr | DAC_CR_EN1)) { @@ -240,14 +240,14 @@ STATIC void pyb_dac_reconfigure(pyb_dac_obj_t *self, uint32_t cr, uint32_t outbu } } -STATIC void pyb_dac_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void pyb_dac_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_dac_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "DAC(%u, bits=%u)", self->dac_channel == DAC_CHANNEL_1 ? 1 : 2, self->bits); } -STATIC mp_obj_t pyb_dac_init_helper(pyb_dac_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_dac_init_helper(pyb_dac_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_bits, MP_ARG_INT, {.u_int = 8} }, { MP_QSTR_buffering, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, @@ -315,7 +315,7 @@ STATIC mp_obj_t pyb_dac_init_helper(pyb_dac_obj_t *self, size_t n_args, const mp /// /// `port` can be a pin object, or an integer (1 or 2). /// DAC(1) is on pin X5 and DAC(2) is on pin X6. -STATIC mp_obj_t pyb_dac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pyb_dac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); @@ -360,25 +360,25 @@ STATIC mp_obj_t pyb_dac_make_new(const mp_obj_type_t *type, size_t n_args, size_ return MP_OBJ_FROM_PTR(dac); } -STATIC mp_obj_t pyb_dac_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t pyb_dac_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { return pyb_dac_init_helper(MP_OBJ_TO_PTR(args[0]), n_args - 1, args + 1, kw_args); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_dac_init_obj, 1, pyb_dac_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_dac_init_obj, 1, pyb_dac_init); /// \method deinit() /// Turn off the DAC, enable other use of pin. -STATIC mp_obj_t pyb_dac_deinit(mp_obj_t self_in) { +static mp_obj_t pyb_dac_deinit(mp_obj_t self_in) { pyb_dac_obj_t *self = MP_OBJ_TO_PTR(self_in); dac_deinit(self->dac_channel); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_dac_deinit_obj, pyb_dac_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_dac_deinit_obj, pyb_dac_deinit); #if defined(TIM6) /// \method noise(freq) /// Generate a pseudo-random noise signal. A new random sample is written /// to the DAC output at the given frequency. -STATIC mp_obj_t pyb_dac_noise(mp_obj_t self_in, mp_obj_t freq) { +static mp_obj_t pyb_dac_noise(mp_obj_t self_in, mp_obj_t freq) { pyb_dac_obj_t *self = MP_OBJ_TO_PTR(self_in); // set TIM6 to trigger the DAC at the given frequency @@ -390,7 +390,7 @@ STATIC mp_obj_t pyb_dac_noise(mp_obj_t self_in, mp_obj_t freq) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_dac_noise_obj, pyb_dac_noise); +static MP_DEFINE_CONST_FUN_OBJ_2(pyb_dac_noise_obj, pyb_dac_noise); #endif #if defined(TIM6) @@ -398,7 +398,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_dac_noise_obj, pyb_dac_noise); /// Generate a triangle wave. The value on the DAC output changes at /// the given frequency, and the frequency of the repeating triangle wave /// itself is 8192 times smaller. -STATIC mp_obj_t pyb_dac_triangle(mp_obj_t self_in, mp_obj_t freq) { +static mp_obj_t pyb_dac_triangle(mp_obj_t self_in, mp_obj_t freq) { pyb_dac_obj_t *self = MP_OBJ_TO_PTR(self_in); // set TIM6 to trigger the DAC at the given frequency @@ -410,12 +410,12 @@ STATIC mp_obj_t pyb_dac_triangle(mp_obj_t self_in, mp_obj_t freq) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_dac_triangle_obj, pyb_dac_triangle); +static MP_DEFINE_CONST_FUN_OBJ_2(pyb_dac_triangle_obj, pyb_dac_triangle); #endif /// \method write(value) /// Direct access to the DAC output (8 bit only at the moment). -STATIC mp_obj_t pyb_dac_write(mp_obj_t self_in, mp_obj_t val) { +static mp_obj_t pyb_dac_write(mp_obj_t self_in, mp_obj_t val) { pyb_dac_obj_t *self = MP_OBJ_TO_PTR(self_in); // DAC output is always 12-bit at the hardware level, and we provide support @@ -426,7 +426,7 @@ STATIC mp_obj_t pyb_dac_write(mp_obj_t self_in, mp_obj_t val) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_dac_write_obj, pyb_dac_write); +static MP_DEFINE_CONST_FUN_OBJ_2(pyb_dac_write_obj, pyb_dac_write); #if defined(TIM6) /// \method write_timed(data, freq, *, mode=DAC.NORMAL) @@ -497,10 +497,10 @@ mp_obj_t pyb_dac_write_timed(size_t n_args, const mp_obj_t *pos_args, mp_map_t * return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_dac_write_timed_obj, 1, pyb_dac_write_timed); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_dac_write_timed_obj, 1, pyb_dac_write_timed); #endif -STATIC const mp_rom_map_elem_t pyb_dac_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_dac_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_dac_init_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_dac_deinit_obj) }, @@ -516,7 +516,7 @@ STATIC const mp_rom_map_elem_t pyb_dac_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_CIRCULAR), MP_ROM_INT(DMA_CIRCULAR) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_dac_locals_dict, pyb_dac_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_dac_locals_dict, pyb_dac_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pyb_dac_type, diff --git a/ports/stm32/eth.c b/ports/stm32/eth.c index 363357dac9ecd..12c29f071616b 100644 --- a/ports/stm32/eth.c +++ b/ports/stm32/eth.c @@ -143,10 +143,10 @@ static eth_dma_t eth_dma __attribute__((aligned(16384))); eth_t eth_instance; -STATIC void eth_mac_deinit(eth_t *self); -STATIC void eth_process_frame(eth_t *self, size_t len, const uint8_t *buf); +static void eth_mac_deinit(eth_t *self); +static void eth_process_frame(eth_t *self, size_t len, const uint8_t *buf); -STATIC void eth_phy_write(uint32_t reg, uint32_t val) { +static void eth_phy_write(uint32_t reg, uint32_t val) { #if defined(STM32H5) || defined(STM32H7) while (ETH->MACMDIOAR & ETH_MACMDIOAR_MB) { } @@ -172,7 +172,7 @@ STATIC void eth_phy_write(uint32_t reg, uint32_t val) { #endif } -STATIC uint32_t eth_phy_read(uint32_t reg) { +static uint32_t eth_phy_read(uint32_t reg) { #if defined(STM32H5) || defined(STM32H7) while (ETH->MACMDIOAR & ETH_MACMDIOAR_MB) { } @@ -231,7 +231,7 @@ void eth_set_trace(eth_t *self, uint32_t value) { self->trace_flags = value; } -STATIC int eth_mac_init(eth_t *self) { +static int eth_mac_init(eth_t *self) { // Configure MPU uint32_t irq_state = mpu_config_start(); #if defined(STM32H5) @@ -540,7 +540,7 @@ STATIC int eth_mac_init(eth_t *self) { return 0; } -STATIC void eth_mac_deinit(eth_t *self) { +static void eth_mac_deinit(eth_t *self) { (void)self; HAL_NVIC_DisableIRQ(ETH_IRQn); #if defined(STM32H5) @@ -558,7 +558,7 @@ STATIC void eth_mac_deinit(eth_t *self) { #endif } -STATIC int eth_tx_buf_get(size_t len, uint8_t **buf) { +static int eth_tx_buf_get(size_t len, uint8_t **buf) { if (len > TX_BUF_SIZE) { return -MP_EINVAL; } @@ -597,7 +597,7 @@ STATIC int eth_tx_buf_get(size_t len, uint8_t **buf) { return 0; } -STATIC int eth_tx_buf_send(void) { +static int eth_tx_buf_send(void) { // Get TX descriptor and move to next one eth_dma_tx_descr_t *tx_descr = ð_dma.tx_descr[eth_dma.tx_descr_idx]; eth_dma.tx_descr_idx = (eth_dma.tx_descr_idx + 1) % TX_BUF_NUM; @@ -637,7 +637,7 @@ STATIC int eth_tx_buf_send(void) { return 0; } -STATIC void eth_dma_rx_free(void) { +static void eth_dma_rx_free(void) { // Get RX descriptor, RX buffer and move to next one eth_dma_rx_descr_t *rx_descr = ð_dma.rx_descr[eth_dma.rx_descr_idx]; uint8_t *buf = ð_dma.rx_buf[eth_dma.rx_descr_idx * RX_BUF_SIZE]; @@ -727,7 +727,7 @@ void ETH_IRQHandler(void) { #define TRACE_ETH_RX (0x0004) #define TRACE_ETH_FULL (0x0008) -STATIC void eth_trace(eth_t *self, size_t len, const void *data, unsigned int flags) { +static void eth_trace(eth_t *self, size_t len, const void *data, unsigned int flags) { if (((flags & NETUTILS_TRACE_IS_TX) && (self->trace_flags & TRACE_ETH_TX)) || (!(flags & NETUTILS_TRACE_IS_TX) && (self->trace_flags & TRACE_ETH_RX))) { const uint8_t *buf; @@ -747,7 +747,7 @@ STATIC void eth_trace(eth_t *self, size_t len, const void *data, unsigned int fl } } -STATIC err_t eth_netif_output(struct netif *netif, struct pbuf *p) { +static err_t eth_netif_output(struct netif *netif, struct pbuf *p) { // This function should always be called from a context where PendSV-level IRQs are disabled LINK_STATS_INC(link.xmit); @@ -763,7 +763,7 @@ STATIC err_t eth_netif_output(struct netif *netif, struct pbuf *p) { return ret ? ERR_BUF : ERR_OK; } -STATIC err_t eth_netif_init(struct netif *netif) { +static err_t eth_netif_init(struct netif *netif) { netif->linkoutput = eth_netif_output; netif->output = etharp_output; netif->mtu = 1500; @@ -778,7 +778,7 @@ STATIC err_t eth_netif_init(struct netif *netif) { return ERR_OK; } -STATIC void eth_lwip_init(eth_t *self) { +static void eth_lwip_init(eth_t *self) { ip_addr_t ipconfig[4]; IP4_ADDR(&ipconfig[0], 0, 0, 0, 0); IP4_ADDR(&ipconfig[2], 192, 168, 0, 1); @@ -804,7 +804,7 @@ STATIC void eth_lwip_init(eth_t *self) { MICROPY_PY_LWIP_EXIT } -STATIC void eth_lwip_deinit(eth_t *self) { +static void eth_lwip_deinit(eth_t *self) { MICROPY_PY_LWIP_ENTER for (struct netif *netif = netif_list; netif != NULL; netif = netif->next) { if (netif == &self->netif) { @@ -816,7 +816,7 @@ STATIC void eth_lwip_deinit(eth_t *self) { MICROPY_PY_LWIP_EXIT } -STATIC void eth_process_frame(eth_t *self, size_t len, const uint8_t *buf) { +static void eth_process_frame(eth_t *self, size_t len, const uint8_t *buf) { eth_trace(self, len, buf, NETUTILS_TRACE_NEWLINE); struct netif *netif = &self->netif; diff --git a/ports/stm32/extint.c b/ports/stm32/extint.c index f6db1e632880a..2a08810125572 100644 --- a/ports/stm32/extint.c +++ b/ports/stm32/extint.c @@ -123,11 +123,11 @@ typedef struct { mp_int_t line; } extint_obj_t; -STATIC uint8_t pyb_extint_mode[EXTI_NUM_VECTORS]; -STATIC bool pyb_extint_hard_irq[EXTI_NUM_VECTORS]; +static uint8_t pyb_extint_mode[EXTI_NUM_VECTORS]; +static bool pyb_extint_hard_irq[EXTI_NUM_VECTORS]; // The callback arg is a small-int or a ROM Pin object, so no need to scan by GC -STATIC mp_obj_t pyb_extint_callback_arg[EXTI_NUM_VECTORS]; +static mp_obj_t pyb_extint_callback_arg[EXTI_NUM_VECTORS]; #if !defined(ETH) #define ETH_WKUP_IRQn 62 // Some MCUs don't have ETH, but we want a value to put in our table @@ -143,7 +143,7 @@ STATIC mp_obj_t pyb_extint_callback_arg[EXTI_NUM_VECTORS]; #define TAMP_STAMP_IRQn RTC_TAMP_LSECSS_IRQn #endif -STATIC const uint8_t nvic_irq_channel[EXTI_NUM_VECTORS] = { +static const uint8_t nvic_irq_channel[EXTI_NUM_VECTORS] = { #if defined(STM32F0) || defined(STM32L0) || defined(STM32G0) EXTI0_1_IRQn, EXTI0_1_IRQn, EXTI2_3_IRQn, EXTI2_3_IRQn, @@ -531,44 +531,44 @@ void extint_trigger_mode(uint line, uint32_t mode) { /// \method line() /// Return the line number that the pin is mapped to. -STATIC mp_obj_t extint_obj_line(mp_obj_t self_in) { +static mp_obj_t extint_obj_line(mp_obj_t self_in) { extint_obj_t *self = MP_OBJ_TO_PTR(self_in); return MP_OBJ_NEW_SMALL_INT(self->line); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_line_obj, extint_obj_line); +static MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_line_obj, extint_obj_line); /// \method enable() /// Enable a disabled interrupt. -STATIC mp_obj_t extint_obj_enable(mp_obj_t self_in) { +static mp_obj_t extint_obj_enable(mp_obj_t self_in) { extint_obj_t *self = MP_OBJ_TO_PTR(self_in); extint_enable(self->line); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_enable_obj, extint_obj_enable); +static MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_enable_obj, extint_obj_enable); /// \method disable() /// Disable the interrupt associated with the ExtInt object. /// This could be useful for debouncing. -STATIC mp_obj_t extint_obj_disable(mp_obj_t self_in) { +static mp_obj_t extint_obj_disable(mp_obj_t self_in) { extint_obj_t *self = MP_OBJ_TO_PTR(self_in); extint_disable(self->line); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_disable_obj, extint_obj_disable); +static MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_disable_obj, extint_obj_disable); /// \method swint() /// Trigger the callback from software. -STATIC mp_obj_t extint_obj_swint(mp_obj_t self_in) { +static mp_obj_t extint_obj_swint(mp_obj_t self_in) { extint_obj_t *self = MP_OBJ_TO_PTR(self_in); extint_swint(self->line); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_swint_obj, extint_obj_swint); +static MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_swint_obj, extint_obj_swint); // TODO document as a staticmethod /// \classmethod regs() /// Dump the values of the EXTI registers. -STATIC mp_obj_t extint_regs(void) { +static mp_obj_t extint_regs(void) { const mp_print_t *print = &mp_plat_print; #if defined(STM32G0) || defined(STM32G4) || defined(STM32H5) || defined(STM32L4) || defined(STM32WB) || defined(STM32WL) @@ -621,8 +621,8 @@ STATIC mp_obj_t extint_regs(void) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(extint_regs_fun_obj, extint_regs); -STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(extint_regs_obj, MP_ROM_PTR(&extint_regs_fun_obj)); +static MP_DEFINE_CONST_FUN_OBJ_0(extint_regs_fun_obj, extint_regs); +static MP_DEFINE_CONST_STATICMETHOD_OBJ(extint_regs_obj, MP_ROM_PTR(&extint_regs_fun_obj)); /// \classmethod \constructor(pin, mode, pull, callback) /// Create an ExtInt object: @@ -639,7 +639,7 @@ STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(extint_regs_obj, MP_ROM_PTR(&extint_regs /// - `callback` is the function to call when the interrupt triggers. The /// callback function must accept exactly 1 argument, which is the line that /// triggered the interrupt. -STATIC const mp_arg_t pyb_extint_make_new_args[] = { +static const mp_arg_t pyb_extint_make_new_args[] = { { MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_pull, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} }, @@ -647,7 +647,7 @@ STATIC const mp_arg_t pyb_extint_make_new_args[] = { }; #define PYB_EXTINT_MAKE_NEW_NUM_ARGS MP_ARRAY_SIZE(pyb_extint_make_new_args) -STATIC mp_obj_t extint_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t extint_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // type_in == extint_obj_type // parse args @@ -660,12 +660,12 @@ STATIC mp_obj_t extint_make_new(const mp_obj_type_t *type, size_t n_args, size_t return MP_OBJ_FROM_PTR(self); } -STATIC void extint_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void extint_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { extint_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", self->line); } -STATIC const mp_rom_map_elem_t extint_locals_dict_table[] = { +static const mp_rom_map_elem_t extint_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_line), MP_ROM_PTR(&extint_obj_line_obj) }, { MP_ROM_QSTR(MP_QSTR_enable), MP_ROM_PTR(&extint_obj_enable_obj) }, { MP_ROM_QSTR(MP_QSTR_disable), MP_ROM_PTR(&extint_obj_disable_obj) }, @@ -684,7 +684,7 @@ STATIC const mp_rom_map_elem_t extint_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_EVT_RISING_FALLING), MP_ROM_INT(GPIO_MODE_EVT_RISING_FALLING) }, }; -STATIC MP_DEFINE_CONST_DICT(extint_locals_dict, extint_locals_dict_table); +static MP_DEFINE_CONST_DICT(extint_locals_dict, extint_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( extint_type, diff --git a/ports/stm32/fdcan.c b/ports/stm32/fdcan.c index 640244a3b9d8b..26a8860988418 100644 --- a/ports/stm32/fdcan.c +++ b/ports/stm32/fdcan.c @@ -340,7 +340,7 @@ int can_receive(FDCAN_HandleTypeDef *can, int fifo, FDCAN_RxHeaderTypeDef *hdr, return 0; // success } -STATIC void can_rx_irq_handler(uint can_id, uint fifo_id) { +static void can_rx_irq_handler(uint can_id, uint fifo_id) { mp_obj_t callback; pyb_can_obj_t *self; mp_obj_t irq_reason = MP_OBJ_NEW_SMALL_INT(0); diff --git a/ports/stm32/i2c.c b/ports/stm32/i2c.c index 52f227a950eb9..9d128acc3cdd2 100644 --- a/ports/stm32/i2c.c +++ b/ports/stm32/i2c.c @@ -34,7 +34,7 @@ #if defined(STM32F4) || defined(STM32L1) -STATIC uint16_t i2c_timeout_ms[MICROPY_HW_MAX_I2C]; +static uint16_t i2c_timeout_ms[MICROPY_HW_MAX_I2C]; int i2c_init(i2c_t *i2c, mp_hal_pin_obj_t scl, mp_hal_pin_obj_t sda, uint32_t freq, uint16_t timeout_ms) { uint32_t i2c_id = ((uint32_t)i2c - I2C1_BASE) / (I2C2_BASE - I2C1_BASE); @@ -93,7 +93,7 @@ int i2c_init(i2c_t *i2c, mp_hal_pin_obj_t scl, mp_hal_pin_obj_t sda, uint32_t fr return 0; } -STATIC int i2c_wait_sr1_set(i2c_t *i2c, uint32_t mask) { +static int i2c_wait_sr1_set(i2c_t *i2c, uint32_t mask) { uint32_t i2c_id = ((uint32_t)i2c - I2C1_BASE) / (I2C2_BASE - I2C1_BASE); uint32_t t0 = HAL_GetTick(); while (!(i2c->SR1 & mask)) { @@ -105,7 +105,7 @@ STATIC int i2c_wait_sr1_set(i2c_t *i2c, uint32_t mask) { return 0; } -STATIC int i2c_wait_stop(i2c_t *i2c) { +static int i2c_wait_stop(i2c_t *i2c) { uint32_t i2c_id = ((uint32_t)i2c - I2C1_BASE) / (I2C2_BASE - I2C1_BASE); uint32_t t0 = HAL_GetTick(); while (i2c->CR1 & I2C_CR1_STOP) { @@ -284,7 +284,7 @@ int i2c_write(i2c_t *i2c, const uint8_t *src, size_t len, size_t next_len) { #endif #endif -STATIC uint16_t i2c_timeout_ms[MICROPY_HW_MAX_I2C]; +static uint16_t i2c_timeout_ms[MICROPY_HW_MAX_I2C]; static uint32_t i2c_get_id(i2c_t *i2c) { #if defined(STM32H7) @@ -362,7 +362,7 @@ int i2c_init(i2c_t *i2c, mp_hal_pin_obj_t scl, mp_hal_pin_obj_t sda, uint32_t fr return 0; } -STATIC int i2c_wait_cr2_clear(i2c_t *i2c, uint32_t mask) { +static int i2c_wait_cr2_clear(i2c_t *i2c, uint32_t mask) { uint32_t i2c_id = i2c_get_id(i2c); uint32_t t0 = HAL_GetTick(); @@ -375,7 +375,7 @@ STATIC int i2c_wait_cr2_clear(i2c_t *i2c, uint32_t mask) { return 0; } -STATIC int i2c_wait_isr_set(i2c_t *i2c, uint32_t mask) { +static int i2c_wait_isr_set(i2c_t *i2c, uint32_t mask) { uint32_t i2c_id = i2c_get_id(i2c); uint32_t t0 = HAL_GetTick(); @@ -423,7 +423,7 @@ int i2c_start_addr(i2c_t *i2c, int rd_wrn, uint16_t addr, size_t len, bool stop) return 0; } -STATIC int i2c_check_stop(i2c_t *i2c) { +static int i2c_check_stop(i2c_t *i2c) { if (i2c->CR2 & I2C_CR2_AUTOEND) { // Wait for the STOP condition and then disable the peripheral int ret; @@ -539,7 +539,7 @@ int i2c_writeto(i2c_t *i2c, uint16_t addr, const uint8_t *src, size_t len, bool #endif -STATIC const uint8_t i2c_available = +static const uint8_t i2c_available = 0 #if defined(MICROPY_HW_I2C1_SCL) | 1 << 1 diff --git a/ports/stm32/irq.c b/ports/stm32/irq.c index fdaf2385cc9d1..3bef1712fccf3 100644 --- a/ports/stm32/irq.c +++ b/ports/stm32/irq.c @@ -36,7 +36,7 @@ uint32_t irq_stats[IRQ_STATS_MAX] = {0}; // disable_irq() // Disable interrupt requests. // Returns the previous IRQ state which can be passed to enable_irq. -STATIC mp_obj_t machine_disable_irq(void) { +static mp_obj_t machine_disable_irq(void) { return mp_obj_new_bool(disable_irq() == IRQ_STATE_ENABLED); } MP_DEFINE_CONST_FUN_OBJ_0(machine_disable_irq_obj, machine_disable_irq); @@ -44,7 +44,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(machine_disable_irq_obj, machine_disable_irq); // enable_irq(state=True) // Enable interrupt requests, based on the argument, which is usually the // value returned by a previous call to disable_irq. -STATIC mp_obj_t machine_enable_irq(uint n_args, const mp_obj_t *arg) { +static mp_obj_t machine_enable_irq(uint n_args, const mp_obj_t *arg) { enable_irq((n_args == 0 || mp_obj_is_true(arg[0])) ? IRQ_STATE_ENABLED : IRQ_STATE_DISABLED); return mp_const_none; } @@ -52,7 +52,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_enable_irq_obj, 0, 1, machine_enable #if IRQ_ENABLE_STATS // return a memoryview of the irq statistics array -STATIC mp_obj_t pyb_irq_stats(void) { +static mp_obj_t pyb_irq_stats(void) { return mp_obj_new_memoryview(0x80 | 'I', MP_ARRAY_SIZE(irq_stats), &irq_stats[0]); } MP_DEFINE_CONST_FUN_OBJ_0(pyb_irq_stats_obj, pyb_irq_stats); diff --git a/ports/stm32/lcd.c b/ports/stm32/lcd.c index a78718872baed..ec53b1c46bf37 100644 --- a/ports/stm32/lcd.c +++ b/ports/stm32/lcd.c @@ -105,11 +105,11 @@ typedef struct _pyb_lcd_obj_t { byte pix_buf2[LCD_PIX_BUF_BYTE_SIZE]; } pyb_lcd_obj_t; -STATIC void lcd_delay(void) { +static void lcd_delay(void) { __asm volatile ("nop\nnop"); } -STATIC void lcd_out(pyb_lcd_obj_t *lcd, int instr_data, uint8_t i) { +static void lcd_out(pyb_lcd_obj_t *lcd, int instr_data, uint8_t i) { lcd_delay(); mp_hal_pin_low(lcd->pin_cs1); // CS=0; enable if (instr_data == LCD_INSTR) { @@ -125,7 +125,7 @@ STATIC void lcd_out(pyb_lcd_obj_t *lcd, int instr_data, uint8_t i) { // write a string to the LCD at the current cursor location // output it straight away (doesn't use the pixel buffer) -STATIC void lcd_write_strn(pyb_lcd_obj_t *lcd, const char *str, unsigned int len) { +static void lcd_write_strn(pyb_lcd_obj_t *lcd, const char *str, unsigned int len) { int redraw_min = lcd->line * LCD_CHAR_BUF_W + lcd->column; int redraw_max = redraw_min; for (; len > 0; len--, str++) { @@ -192,7 +192,7 @@ STATIC void lcd_write_strn(pyb_lcd_obj_t *lcd, const char *str, unsigned int len /// /// Construct an LCD object in the given skin position. `skin_position` can be 'X' or 'Y', and /// should match the position where the LCD pyskin is plugged in. -STATIC mp_obj_t pyb_lcd_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pyb_lcd_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, 1, false); @@ -323,7 +323,7 @@ STATIC mp_obj_t pyb_lcd_make_new(const mp_obj_type_t *type, size_t n_args, size_ /// Send an arbitrary command to the LCD. Pass 0 for `instr_data` to send an /// instruction, otherwise pass 1 to send data. `buf` is a buffer with the /// instructions/data to send. -STATIC mp_obj_t pyb_lcd_command(mp_obj_t self_in, mp_obj_t instr_data_in, mp_obj_t val) { +static mp_obj_t pyb_lcd_command(mp_obj_t self_in, mp_obj_t instr_data_in, mp_obj_t val) { pyb_lcd_obj_t *self = MP_OBJ_TO_PTR(self_in); // get whether instr or data @@ -341,12 +341,12 @@ STATIC mp_obj_t pyb_lcd_command(mp_obj_t self_in, mp_obj_t instr_data_in, mp_obj return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_lcd_command_obj, pyb_lcd_command); +static MP_DEFINE_CONST_FUN_OBJ_3(pyb_lcd_command_obj, pyb_lcd_command); /// \method contrast(value) /// /// Set the contrast of the LCD. Valid values are between 0 and 47. -STATIC mp_obj_t pyb_lcd_contrast(mp_obj_t self_in, mp_obj_t contrast_in) { +static mp_obj_t pyb_lcd_contrast(mp_obj_t self_in, mp_obj_t contrast_in) { pyb_lcd_obj_t *self = MP_OBJ_TO_PTR(self_in); int contrast = mp_obj_get_int(contrast_in); if (contrast < 0) { @@ -358,12 +358,12 @@ STATIC mp_obj_t pyb_lcd_contrast(mp_obj_t self_in, mp_obj_t contrast_in) { lcd_out(self, LCD_INSTR, contrast); // electronic volume register set return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_lcd_contrast_obj, pyb_lcd_contrast); +static MP_DEFINE_CONST_FUN_OBJ_2(pyb_lcd_contrast_obj, pyb_lcd_contrast); /// \method light(value) /// /// Turn the backlight on/off. True or 1 turns it on, False or 0 turns it off. -STATIC mp_obj_t pyb_lcd_light(mp_obj_t self_in, mp_obj_t value) { +static mp_obj_t pyb_lcd_light(mp_obj_t self_in, mp_obj_t value) { pyb_lcd_obj_t *self = MP_OBJ_TO_PTR(self_in); if (mp_obj_is_true(value)) { mp_hal_pin_high(self->pin_bl); // set pin high to turn backlight on @@ -372,26 +372,26 @@ STATIC mp_obj_t pyb_lcd_light(mp_obj_t self_in, mp_obj_t value) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_lcd_light_obj, pyb_lcd_light); +static MP_DEFINE_CONST_FUN_OBJ_2(pyb_lcd_light_obj, pyb_lcd_light); /// \method write(str) /// /// Write the string `str` to the screen. It will appear immediately. -STATIC mp_obj_t pyb_lcd_write(mp_obj_t self_in, mp_obj_t str) { +static mp_obj_t pyb_lcd_write(mp_obj_t self_in, mp_obj_t str) { pyb_lcd_obj_t *self = MP_OBJ_TO_PTR(self_in); size_t len; const char *data = mp_obj_str_get_data(str, &len); lcd_write_strn(self, data, len); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_lcd_write_obj, pyb_lcd_write); +static MP_DEFINE_CONST_FUN_OBJ_2(pyb_lcd_write_obj, pyb_lcd_write); /// \method fill(colour) /// /// Fill the screen with the given colour (0 or 1 for white or black). /// /// This method writes to the hidden buffer. Use `show()` to show the buffer. -STATIC mp_obj_t pyb_lcd_fill(mp_obj_t self_in, mp_obj_t col_in) { +static mp_obj_t pyb_lcd_fill(mp_obj_t self_in, mp_obj_t col_in) { pyb_lcd_obj_t *self = MP_OBJ_TO_PTR(self_in); int col = mp_obj_get_int(col_in); if (col) { @@ -401,14 +401,14 @@ STATIC mp_obj_t pyb_lcd_fill(mp_obj_t self_in, mp_obj_t col_in) { memset(self->pix_buf2, col, LCD_PIX_BUF_BYTE_SIZE); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_lcd_fill_obj, pyb_lcd_fill); +static MP_DEFINE_CONST_FUN_OBJ_2(pyb_lcd_fill_obj, pyb_lcd_fill); /// \method get(x, y) /// /// Get the pixel at the position `(x, y)`. Returns 0 or 1. /// /// This method reads from the visible buffer. -STATIC mp_obj_t pyb_lcd_get(mp_obj_t self_in, mp_obj_t x_in, mp_obj_t y_in) { +static mp_obj_t pyb_lcd_get(mp_obj_t self_in, mp_obj_t x_in, mp_obj_t y_in) { pyb_lcd_obj_t *self = MP_OBJ_TO_PTR(self_in); int x = mp_obj_get_int(x_in); int y = mp_obj_get_int(y_in); @@ -420,14 +420,14 @@ STATIC mp_obj_t pyb_lcd_get(mp_obj_t self_in, mp_obj_t x_in, mp_obj_t y_in) { } return mp_obj_new_int(0); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_lcd_get_obj, pyb_lcd_get); +static MP_DEFINE_CONST_FUN_OBJ_3(pyb_lcd_get_obj, pyb_lcd_get); /// \method pixel(x, y, colour) /// /// Set the pixel at `(x, y)` to the given colour (0 or 1). /// /// This method writes to the hidden buffer. Use `show()` to show the buffer. -STATIC mp_obj_t pyb_lcd_pixel(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_lcd_pixel(size_t n_args, const mp_obj_t *args) { pyb_lcd_obj_t *self = MP_OBJ_TO_PTR(args[0]); int x = mp_obj_get_int(args[1]); int y = mp_obj_get_int(args[2]); @@ -441,14 +441,14 @@ STATIC mp_obj_t pyb_lcd_pixel(size_t n_args, const mp_obj_t *args) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_lcd_pixel_obj, 4, 4, pyb_lcd_pixel); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_lcd_pixel_obj, 4, 4, pyb_lcd_pixel); /// \method text(str, x, y, colour) /// /// Draw the given text to the position `(x, y)` using the given colour (0 or 1). /// /// This method writes to the hidden buffer. Use `show()` to show the buffer. -STATIC mp_obj_t pyb_lcd_text(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_lcd_text(size_t n_args, const mp_obj_t *args) { // extract arguments pyb_lcd_obj_t *self = MP_OBJ_TO_PTR(args[0]); size_t len; @@ -490,12 +490,12 @@ STATIC mp_obj_t pyb_lcd_text(size_t n_args, const mp_obj_t *args) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_lcd_text_obj, 5, 5, pyb_lcd_text); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_lcd_text_obj, 5, 5, pyb_lcd_text); /// \method show() /// /// Show the hidden buffer on the screen. -STATIC mp_obj_t pyb_lcd_show(mp_obj_t self_in) { +static mp_obj_t pyb_lcd_show(mp_obj_t self_in) { pyb_lcd_obj_t *self = MP_OBJ_TO_PTR(self_in); memcpy(self->pix_buf, self->pix_buf2, LCD_PIX_BUF_BYTE_SIZE); for (uint page = 0; page < 4; page++) { @@ -508,9 +508,9 @@ STATIC mp_obj_t pyb_lcd_show(mp_obj_t self_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_lcd_show_obj, pyb_lcd_show); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_lcd_show_obj, pyb_lcd_show); -STATIC const mp_rom_map_elem_t pyb_lcd_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_lcd_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_command), MP_ROM_PTR(&pyb_lcd_command_obj) }, { MP_ROM_QSTR(MP_QSTR_contrast), MP_ROM_PTR(&pyb_lcd_contrast_obj) }, @@ -523,7 +523,7 @@ STATIC const mp_rom_map_elem_t pyb_lcd_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&pyb_lcd_show_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_lcd_locals_dict, pyb_lcd_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_lcd_locals_dict, pyb_lcd_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pyb_lcd_type, diff --git a/ports/stm32/led.c b/ports/stm32/led.c index 39b1f7e388814..795d8c1109621 100644 --- a/ports/stm32/led.c +++ b/ports/stm32/led.c @@ -50,7 +50,7 @@ typedef struct _pyb_led_obj_t { const machine_pin_obj_t *led_pin; } pyb_led_obj_t; -STATIC const pyb_led_obj_t pyb_led_obj[] = { +static const pyb_led_obj_t pyb_led_obj[] = { {{&pyb_led_type}, 1, MICROPY_HW_LED1}, #if defined(MICROPY_HW_LED2) {{&pyb_led_type}, 2, MICROPY_HW_LED2}, @@ -125,7 +125,7 @@ typedef struct _led_pwm_config_t { uint8_t alt_func; } led_pwm_config_t; -STATIC const led_pwm_config_t led_pwm_config[] = { +static const led_pwm_config_t led_pwm_config[] = { MICROPY_HW_LED1_PWM, MICROPY_HW_LED2_PWM, MICROPY_HW_LED3_PWM, @@ -134,15 +134,15 @@ STATIC const led_pwm_config_t led_pwm_config[] = { MICROPY_HW_LED6_PWM, }; -STATIC uint8_t led_pwm_state = 0; +static uint8_t led_pwm_state = 0; static inline bool led_pwm_is_enabled(int led) { return (led_pwm_state & (1 << led)) != 0; } // this function has a large stack so it should not be inlined -STATIC void led_pwm_init(int led) __attribute__((noinline)); -STATIC void led_pwm_init(int led) { +static void led_pwm_init(int led) __attribute__((noinline)); +static void led_pwm_init(int led) { const machine_pin_obj_t *led_pin = pyb_led_obj[led - 1].led_pin; const led_pwm_config_t *pwm_cfg = &led_pwm_config[led - 1]; @@ -190,7 +190,7 @@ STATIC void led_pwm_init(int led) { led_pwm_state |= 1 << led; } -STATIC void led_pwm_deinit(int led) { +static void led_pwm_deinit(int led) { // make the LED's pin a standard GPIO output pin const machine_pin_obj_t *led_pin = pyb_led_obj[led - 1].led_pin; GPIO_TypeDef *g = led_pin->gpio; @@ -312,7 +312,7 @@ void led_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t ki /// Create an LED object associated with the given LED: /// /// - `id` is the LED number, 1-4. -STATIC mp_obj_t led_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t led_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, 1, false); @@ -366,19 +366,19 @@ mp_obj_t led_obj_intensity(size_t n_args, const mp_obj_t *args) { } } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_on_obj, led_obj_on); -STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_off_obj, led_obj_off); -STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_toggle_obj, led_obj_toggle); -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(led_obj_intensity_obj, 1, 2, led_obj_intensity); +static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_on_obj, led_obj_on); +static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_off_obj, led_obj_off); +static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_toggle_obj, led_obj_toggle); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(led_obj_intensity_obj, 1, 2, led_obj_intensity); -STATIC const mp_rom_map_elem_t led_locals_dict_table[] = { +static const mp_rom_map_elem_t led_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_on), MP_ROM_PTR(&led_obj_on_obj) }, { MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(&led_obj_off_obj) }, { MP_ROM_QSTR(MP_QSTR_toggle), MP_ROM_PTR(&led_obj_toggle_obj) }, { MP_ROM_QSTR(MP_QSTR_intensity), MP_ROM_PTR(&led_obj_intensity_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(led_locals_dict, led_locals_dict_table); +static MP_DEFINE_CONST_DICT(led_locals_dict, led_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pyb_led_type, diff --git a/ports/stm32/machine_adc.c b/ports/stm32/machine_adc.c index 91094427b86cc..8f07075914b88 100644 --- a/ports/stm32/machine_adc.c +++ b/ports/stm32/machine_adc.c @@ -112,7 +112,7 @@ typedef enum _machine_adc_internal_ch_t { // Convert machine_adc_internal_ch_t value to STM32 library ADC channel literal. // This function is required as literals are uint32_t types that don't map with MP_ROM_INT (31 bit signed). -STATIC uint32_t adc_ll_channel(uint32_t channel_id) { +static uint32_t adc_ll_channel(uint32_t channel_id) { uint32_t adc_ll_ch; switch (channel_id) { // external channels map 1:1 @@ -154,7 +154,7 @@ static inline void adc_stabilisation_delay_us(uint32_t us) { mp_hal_delay_us(us + 1); } -STATIC void adc_wait_eoc(ADC_TypeDef *adc, int32_t timeout_ms) { +static void adc_wait_eoc(ADC_TypeDef *adc, int32_t timeout_ms) { uint32_t t0 = mp_hal_ticks_ms(); #if ADC_V2 while (!(adc->ISR & ADC_ISR_EOC)) @@ -169,9 +169,9 @@ STATIC void adc_wait_eoc(ADC_TypeDef *adc, int32_t timeout_ms) { } #if defined(STM32H7) -STATIC const uint8_t adc_cr_to_bits_table[] = {16, 14, 12, 10, 8, 8, 8, 8}; +static const uint8_t adc_cr_to_bits_table[] = {16, 14, 12, 10, 8, 8, 8, 8}; #else -STATIC const uint8_t adc_cr_to_bits_table[] = {12, 10, 8, 6}; +static const uint8_t adc_cr_to_bits_table[] = {12, 10, 8, 6}; #endif void adc_config(ADC_TypeDef *adc, uint32_t bits) { @@ -313,7 +313,7 @@ void adc_config(ADC_TypeDef *adc, uint32_t bits) { #endif } -STATIC int adc_get_bits(ADC_TypeDef *adc) { +static int adc_get_bits(ADC_TypeDef *adc) { #if defined(STM32F0) || defined(STM32G0) || defined(STM32L0) || defined(STM32WL) uint32_t res = (adc->CFGR1 & ADC_CFGR1_RES) >> ADC_CFGR1_RES_Pos; #elif defined(STM32F4) || defined(STM32F7) || defined(STM32L1) @@ -324,7 +324,7 @@ STATIC int adc_get_bits(ADC_TypeDef *adc) { return adc_cr_to_bits_table[res]; } -STATIC void adc_config_channel(ADC_TypeDef *adc, uint32_t channel, uint32_t sample_time) { +static void adc_config_channel(ADC_TypeDef *adc, uint32_t channel, uint32_t sample_time) { #if ADC_V2 if (!(adc->CR & ADC_CR_ADEN)) { if (adc->CR & 0x3f) { @@ -443,7 +443,7 @@ STATIC void adc_config_channel(ADC_TypeDef *adc, uint32_t channel, uint32_t samp #endif } -STATIC uint32_t adc_read_channel(ADC_TypeDef *adc) { +static uint32_t adc_read_channel(ADC_TypeDef *adc) { uint32_t value; #if defined(STM32G4) // For STM32G4 there is errata 2.7.7, "Wrong ADC result if conversion done late after @@ -520,7 +520,7 @@ typedef struct _machine_adc_obj_t { uint32_t sample_time; } machine_adc_obj_t; -STATIC void mp_machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_adc_obj_t *self = MP_OBJ_TO_PTR(self_in); unsigned adc_id = 1; #if defined(ADC2) @@ -537,7 +537,7 @@ STATIC void mp_machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_p } // ADC(id) -STATIC mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // Check number of arguments mp_arg_check_num(n_args, n_kw, 1, 1, false); @@ -607,7 +607,7 @@ STATIC mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args } // read_u16() -STATIC mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) { +static mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) { return adc_config_and_read_u16(self->adc, self->channel, self->sample_time); } diff --git a/ports/stm32/machine_i2c.c b/ports/stm32/machine_i2c.c index 8beefcad6d2f1..ca2170e32d3bc 100644 --- a/ports/stm32/machine_i2c.c +++ b/ports/stm32/machine_i2c.c @@ -43,7 +43,7 @@ typedef struct _machine_hard_i2c_obj_t { mp_hal_pin_obj_t sda; } machine_hard_i2c_obj_t; -STATIC const machine_hard_i2c_obj_t machine_hard_i2c_obj[MICROPY_HW_MAX_I2C] = { +static const machine_hard_i2c_obj_t machine_hard_i2c_obj[MICROPY_HW_MAX_I2C] = { #if defined(MICROPY_HW_I2C1_SCL) [0] = {{&machine_i2c_type}, I2C1, MICROPY_HW_I2C1_SCL, MICROPY_HW_I2C1_SDA}, #endif @@ -58,7 +58,7 @@ STATIC const machine_hard_i2c_obj_t machine_hard_i2c_obj[MICROPY_HW_MAX_I2C] = { #endif }; -STATIC void machine_hard_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_hard_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_hard_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in); #if defined(STM32F4) || defined(STM32L1) @@ -134,7 +134,7 @@ int machine_hard_i2c_transfer(mp_obj_base_t *self_in, uint16_t addr, size_t n, m typedef mp_machine_soft_i2c_obj_t machine_hard_i2c_obj_t; -STATIC machine_hard_i2c_obj_t machine_hard_i2c_obj[MICROPY_HW_MAX_I2C] = { +static machine_hard_i2c_obj_t machine_hard_i2c_obj[MICROPY_HW_MAX_I2C] = { #if defined(MICROPY_HW_I2C1_SCL) [0] = {{&machine_i2c_type}, 1, I2C_POLL_DEFAULT_TIMEOUT_US, MICROPY_HW_I2C1_SCL, MICROPY_HW_I2C1_SDA}, #endif @@ -149,14 +149,14 @@ STATIC machine_hard_i2c_obj_t machine_hard_i2c_obj[MICROPY_HW_MAX_I2C] = { #endif }; -STATIC void machine_hard_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_hard_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_hard_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "I2C(%u, scl=%q, sda=%q, freq=%u, timeout=%u)", self - &machine_hard_i2c_obj[0] + 1, self->scl->name, self->sda->name, 500000 / self->us_delay, self->us_timeout); } -STATIC void machine_hard_i2c_init(machine_hard_i2c_obj_t *self, uint32_t freq, uint32_t timeout) { +static void machine_hard_i2c_init(machine_hard_i2c_obj_t *self, uint32_t freq, uint32_t timeout) { // set parameters if (freq >= 1000000) { // allow fastest possible bit-bang rate @@ -228,7 +228,7 @@ mp_obj_t machine_hard_i2c_make_new(const mp_obj_type_t *type, size_t n_args, siz return MP_OBJ_FROM_PTR(self); } -STATIC const mp_machine_i2c_p_t machine_hard_i2c_p = { +static const mp_machine_i2c_p_t machine_hard_i2c_p = { .transfer = machine_hard_i2c_transfer, }; diff --git a/ports/stm32/machine_i2s.c b/ports/stm32/machine_i2s.c index dbee81bb395a6..a2a0a8291008c 100644 --- a/ports/stm32/machine_i2s.c +++ b/ports/stm32/machine_i2s.c @@ -94,19 +94,19 @@ typedef struct _machine_i2s_obj_t { const dma_descr_t *dma_descr_rx; } machine_i2s_obj_t; -STATIC mp_obj_t machine_i2s_deinit(mp_obj_t self_in); +static mp_obj_t machine_i2s_deinit(mp_obj_t self_in); // The frame map is used with the readinto() method to transform the audio sample data coming // from DMA memory (32-bit stereo) to the format specified // in the I2S constructor. e.g. 16-bit mono -STATIC const int8_t i2s_frame_map[NUM_I2S_USER_FORMATS][I2S_RX_FRAME_SIZE_IN_BYTES] = { +static const int8_t i2s_frame_map[NUM_I2S_USER_FORMATS][I2S_RX_FRAME_SIZE_IN_BYTES] = { { 0, 1, -1, -1, -1, -1, -1, -1 }, // Mono, 16-bits { 2, 3, 0, 1, -1, -1, -1, -1 }, // Mono, 32-bits { 0, 1, -1, -1, 2, 3, -1, -1 }, // Stereo, 16-bits { 2, 3, 0, 1, 6, 7, 4, 5 }, // Stereo, 32-bits }; -STATIC const plli2s_config_t plli2s_config[] = PLLI2S_TABLE; +static const plli2s_config_t plli2s_config[] = PLLI2S_TABLE; void machine_i2s_init0() { for (uint8_t i = 0; i < MICROPY_HW_MAX_I2S; i++) { @@ -114,7 +114,7 @@ void machine_i2s_init0() { } } -STATIC bool lookup_plli2s_config(int8_t bits, int32_t rate, uint16_t *plli2sn, uint16_t *plli2sr) { +static bool lookup_plli2s_config(int8_t bits, int32_t rate, uint16_t *plli2sn, uint16_t *plli2sr) { for (uint16_t i = 0; i < MP_ARRAY_SIZE(plli2s_config); i++) { if ((plli2s_config[i].bits == bits) && (plli2s_config[i].rate == rate)) { *plli2sn = plli2s_config[i].plli2sn; @@ -148,7 +148,7 @@ STATIC bool lookup_plli2s_config(int8_t bits, int32_t rate, uint16_t *plli2sn, u // where: // LEFT Channel = 0x99, 0xBB, 0x11, 0x22 // RIGHT Channel = 0x44, 0x55, 0xAB, 0x77 -STATIC void reformat_32_bit_samples(int32_t *sample, uint32_t num_samples) { +static void reformat_32_bit_samples(int32_t *sample, uint32_t num_samples) { int16_t sample_ms; int16_t sample_ls; for (uint32_t i = 0; i < num_samples; i++) { @@ -158,7 +158,7 @@ STATIC void reformat_32_bit_samples(int32_t *sample, uint32_t num_samples) { } } -STATIC int8_t get_frame_mapping_index(int8_t bits, format_t format) { +static int8_t get_frame_mapping_index(int8_t bits, format_t format) { if (format == MONO) { if (bits == 16) { return 0; @@ -174,7 +174,7 @@ STATIC int8_t get_frame_mapping_index(int8_t bits, format_t format) { } } -STATIC int8_t get_dma_bits(uint16_t mode, int8_t bits) { +static int8_t get_dma_bits(uint16_t mode, int8_t bits) { if (mode == I2S_MODE_MASTER_TX) { if (bits == 16) { return I2S_DATAFORMAT_16B; @@ -189,7 +189,7 @@ STATIC int8_t get_dma_bits(uint16_t mode, int8_t bits) { } // function is used in IRQ context -STATIC void empty_dma(machine_i2s_obj_t *self, ping_pong_t dma_ping_pong) { +static void empty_dma(machine_i2s_obj_t *self, ping_pong_t dma_ping_pong) { uint16_t dma_buffer_offset = 0; if (dma_ping_pong == TOP_HALF) { @@ -212,7 +212,7 @@ STATIC void empty_dma(machine_i2s_obj_t *self, ping_pong_t dma_ping_pong) { } // function is used in IRQ context -STATIC void feed_dma(machine_i2s_obj_t *self, ping_pong_t dma_ping_pong) { +static void feed_dma(machine_i2s_obj_t *self, ping_pong_t dma_ping_pong) { uint16_t dma_buffer_offset = 0; if (dma_ping_pong == TOP_HALF) { @@ -262,7 +262,7 @@ STATIC void feed_dma(machine_i2s_obj_t *self, ping_pong_t dma_ping_pong) { MP_HAL_CLEAN_DCACHE(dma_buffer_p, SIZEOF_HALF_DMA_BUFFER_IN_BYTES); } -STATIC bool i2s_init(machine_i2s_obj_t *self) { +static bool i2s_init(machine_i2s_obj_t *self) { // init the GPIO lines GPIO_InitTypeDef GPIO_InitStructure; @@ -439,7 +439,7 @@ void HAL_I2S_TxHalfCpltCallback(I2S_HandleTypeDef *hi2s) { feed_dma(self, TOP_HALF); } -STATIC void mp_machine_i2s_init_helper(machine_i2s_obj_t *self, mp_arg_val_t *args) { +static void mp_machine_i2s_init_helper(machine_i2s_obj_t *self, mp_arg_val_t *args) { memset(&self->hi2s, 0, sizeof(self->hi2s)); // are I2S pin assignments valid? @@ -558,7 +558,7 @@ STATIC void mp_machine_i2s_init_helper(machine_i2s_obj_t *self, mp_arg_val_t *ar } } -STATIC machine_i2s_obj_t *mp_machine_i2s_make_new_instance(mp_int_t i2s_id) { +static machine_i2s_obj_t *mp_machine_i2s_make_new_instance(mp_int_t i2s_id) { uint8_t i2s_id_zero_base = 0; if (0) { @@ -590,7 +590,7 @@ STATIC machine_i2s_obj_t *mp_machine_i2s_make_new_instance(mp_int_t i2s_id) { return self; } -STATIC void mp_machine_i2s_deinit(machine_i2s_obj_t *self) { +static void mp_machine_i2s_deinit(machine_i2s_obj_t *self) { if (self->ring_buffer_storage != NULL) { dma_deinit(self->dma_descr_tx); dma_deinit(self->dma_descr_rx); @@ -611,7 +611,7 @@ STATIC void mp_machine_i2s_deinit(machine_i2s_obj_t *self) { } } -STATIC void mp_machine_i2s_irq_update(machine_i2s_obj_t *self) { +static void mp_machine_i2s_irq_update(machine_i2s_obj_t *self) { (void)self; } diff --git a/ports/stm32/machine_spi.c b/ports/stm32/machine_spi.c index 0a5a67ef2ed9b..a2e3e3595412a 100644 --- a/ports/stm32/machine_spi.c +++ b/ports/stm32/machine_spi.c @@ -33,7 +33,7 @@ /******************************************************************************/ // Implementation of hard SPI for machine module -STATIC const machine_hard_spi_obj_t machine_hard_spi_obj[] = { +static const machine_hard_spi_obj_t machine_hard_spi_obj[] = { {{&machine_spi_type}, &spi_obj[0]}, {{&machine_spi_type}, &spi_obj[1]}, {{&machine_spi_type}, &spi_obj[2]}, @@ -42,7 +42,7 @@ STATIC const machine_hard_spi_obj_t machine_hard_spi_obj[] = { {{&machine_spi_type}, &spi_obj[5]}, }; -STATIC void machine_hard_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_hard_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_hard_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); spi_print(print, self->spi, false); } @@ -101,7 +101,7 @@ mp_obj_t machine_hard_spi_make_new(const mp_obj_type_t *type, size_t n_args, siz return MP_OBJ_FROM_PTR(self); } -STATIC void machine_hard_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void machine_hard_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { machine_hard_spi_obj_t *self = (machine_hard_spi_obj_t *)self_in; enum { ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits, ARG_firstbit }; @@ -127,17 +127,17 @@ STATIC void machine_hard_spi_init(mp_obj_base_t *self_in, size_t n_args, const m } } -STATIC void machine_hard_spi_deinit(mp_obj_base_t *self_in) { +static void machine_hard_spi_deinit(mp_obj_base_t *self_in) { machine_hard_spi_obj_t *self = (machine_hard_spi_obj_t *)self_in; spi_deinit(self->spi); } -STATIC void machine_hard_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) { +static void machine_hard_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) { machine_hard_spi_obj_t *self = (machine_hard_spi_obj_t *)self_in; spi_transfer(self->spi, len, src, dest, SPI_TRANSFER_TIMEOUT(len)); } -STATIC const mp_machine_spi_p_t machine_hard_spi_p = { +static const mp_machine_spi_p_t machine_hard_spi_p = { .init = machine_hard_spi_init, .deinit = machine_hard_spi_deinit, .transfer = machine_hard_spi_transfer, diff --git a/ports/stm32/machine_uart.c b/ports/stm32/machine_uart.c index 6f1a7f9a2d5fd..0f139ae83272f 100644 --- a/ports/stm32/machine_uart.c +++ b/ports/stm32/machine_uart.c @@ -42,7 +42,7 @@ { MP_ROM_QSTR(MP_QSTR_CTS), MP_ROM_INT(UART_HWCONTROL_CTS) }, \ { MP_ROM_QSTR(MP_QSTR_IRQ_RXIDLE), MP_ROM_INT(UART_FLAG_IDLE) }, \ -STATIC void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); if (!self->is_enabled) { #if defined(LPUART1) @@ -140,7 +140,7 @@ STATIC void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_ /// - `timeout_char` is the timeout in milliseconds to wait between characters. /// - `flow` is RTS | CTS where RTS == 256, CTS == 512 /// - `read_buf_len` is the character length of the read buffer (0 to disable). -STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_baudrate, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 9600} }, { MP_QSTR_bits, MP_ARG_INT, {.u_int = 8} }, @@ -278,7 +278,7 @@ STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, /// - `UART(6)` is on `YA`: `(TX, RX) = (Y1, Y2) = (PC6, PC7)` /// - `UART(3)` is on `YB`: `(TX, RX) = (Y9, Y10) = (PB10, PB11)` /// - `UART(2)` is on: `(TX, RX) = (X3, X4) = (PA2, PA3)` -STATIC mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); @@ -381,23 +381,23 @@ STATIC mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_arg } // Turn off the UART bus. -STATIC void mp_machine_uart_deinit(machine_uart_obj_t *self) { +static void mp_machine_uart_deinit(machine_uart_obj_t *self) { uart_deinit(self); } // Return number of characters waiting. -STATIC mp_int_t mp_machine_uart_any(machine_uart_obj_t *self) { +static mp_int_t mp_machine_uart_any(machine_uart_obj_t *self) { return uart_rx_any(self); } // Since uart.write() waits up to the last byte, uart.txdone() always returns True. -STATIC bool mp_machine_uart_txdone(machine_uart_obj_t *self) { +static bool mp_machine_uart_txdone(machine_uart_obj_t *self) { (void)self; return true; } // Send a break condition. -STATIC void mp_machine_uart_sendbreak(machine_uart_obj_t *self) { +static void mp_machine_uart_sendbreak(machine_uart_obj_t *self) { #if defined(STM32F0) || defined(STM32F7) || defined(STM32G0) || defined(STM32G4) || defined(STM32H5) || defined(STM32H7) || defined(STM32L0) || defined(STM32L4) || defined(STM32WB) || defined(STM32WL) self->uartx->RQR = USART_RQR_SBKRQ; // write-only register #else @@ -407,7 +407,7 @@ STATIC void mp_machine_uart_sendbreak(machine_uart_obj_t *self) { // Write a single character on the bus. `data` is an integer to write. // The `data` can be up to 9 bits. -STATIC void mp_machine_uart_writechar(machine_uart_obj_t *self, uint16_t data) { +static void mp_machine_uart_writechar(machine_uart_obj_t *self, uint16_t data) { // write the character int errcode; if (uart_tx_wait(self, self->timeout)) { @@ -423,7 +423,7 @@ STATIC void mp_machine_uart_writechar(machine_uart_obj_t *self, uint16_t data) { // Receive a single character on the bus. // Return value: The character read, as an integer. Returns -1 on timeout. -STATIC mp_int_t mp_machine_uart_readchar(machine_uart_obj_t *self) { +static mp_int_t mp_machine_uart_readchar(machine_uart_obj_t *self) { if (uart_rx_wait(self, self->timeout)) { return uart_rx_char(self); } else { @@ -432,7 +432,7 @@ STATIC mp_int_t mp_machine_uart_readchar(machine_uart_obj_t *self) { } } -STATIC mp_irq_obj_t *mp_machine_uart_irq(machine_uart_obj_t *self, bool any_args, mp_arg_val_t *args) { +static mp_irq_obj_t *mp_machine_uart_irq(machine_uart_obj_t *self, bool any_args, mp_arg_val_t *args) { if (self->mp_irq_obj == NULL) { self->mp_irq_trigger = 0; self->mp_irq_obj = mp_irq_new(&uart_irq_methods, MP_OBJ_FROM_PTR(self)); @@ -463,7 +463,7 @@ STATIC mp_irq_obj_t *mp_machine_uart_irq(machine_uart_obj_t *self, bool any_args return self->mp_irq_obj; } -STATIC mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { +static mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); byte *buf = buf_in; @@ -505,7 +505,7 @@ STATIC mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t } } -STATIC mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { +static mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); const byte *buf = buf_in; @@ -532,7 +532,7 @@ STATIC mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_ } } -STATIC mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_uint_t ret; if (request == MP_STREAM_POLL) { diff --git a/ports/stm32/machine_wdt.c b/ports/stm32/machine_wdt.c index e0605751d1f4e..4789b85a60955 100644 --- a/ports/stm32/machine_wdt.c +++ b/ports/stm32/machine_wdt.c @@ -37,9 +37,9 @@ typedef struct _machine_wdt_obj_t { mp_obj_base_t base; } machine_wdt_obj_t; -STATIC const machine_wdt_obj_t machine_wdt = {{&machine_wdt_type}}; +static const machine_wdt_obj_t machine_wdt = {{&machine_wdt_type}}; -STATIC machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t timeout_ms) { +static machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t timeout_ms) { if (id != 0) { mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("WDT(%d) doesn't exist"), id); } @@ -77,7 +77,7 @@ STATIC machine_wdt_obj_t *mp_machine_wdt_make_new_instance(mp_int_t id, mp_int_t return (machine_wdt_obj_t *)&machine_wdt; } -STATIC void mp_machine_wdt_feed(machine_wdt_obj_t *self) { +static void mp_machine_wdt_feed(machine_wdt_obj_t *self) { (void)self; IWDG->KR = 0xaaaa; } diff --git a/ports/stm32/main.c b/ports/stm32/main.c index 3279770ea03ce..802a884d87d7f 100644 --- a/ports/stm32/main.c +++ b/ports/stm32/main.c @@ -90,15 +90,15 @@ #include "subghz.h" #if MICROPY_PY_THREAD -STATIC pyb_thread_t pyb_thread_main; +static pyb_thread_t pyb_thread_main; #endif #if defined(MICROPY_HW_UART_REPL) #ifndef MICROPY_HW_UART_REPL_RXBUF #define MICROPY_HW_UART_REPL_RXBUF (260) #endif -STATIC machine_uart_obj_t pyb_uart_repl_obj; -STATIC uint8_t pyb_uart_repl_rxbuf[MICROPY_HW_UART_REPL_RXBUF]; +static machine_uart_obj_t pyb_uart_repl_obj; +static uint8_t pyb_uart_repl_rxbuf[MICROPY_HW_UART_REPL_RXBUF]; #endif void nlr_jump_fail(void *val) { @@ -119,7 +119,7 @@ void MP_WEAK __assert_func(const char *file, int line, const char *func, const c } #endif -STATIC mp_obj_t pyb_main(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_main(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_opt, MP_ARG_INT, {.u_int = 0} } }; @@ -140,7 +140,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(pyb_main_obj, 1, pyb_main); #if MICROPY_HW_FLASH_MOUNT_AT_BOOT // avoid inlining to avoid stack usage within main() -MP_NOINLINE STATIC bool init_flash_fs(uint reset_mode) { +MP_NOINLINE static bool init_flash_fs(uint reset_mode) { if (reset_mode == BOARDCTRL_RESET_MODE_FACTORY_FILESYSTEM) { // Asked by user to reset filesystem factory_reset_create_filesystem(); @@ -215,7 +215,7 @@ MP_NOINLINE STATIC bool init_flash_fs(uint reset_mode) { #endif #if MICROPY_HW_SDCARD_MOUNT_AT_BOOT -STATIC bool init_sdcard_fs(void) { +static bool init_sdcard_fs(void) { bool first_part = true; for (int part_num = 1; part_num <= 5; ++part_num) { // create vfs object diff --git a/ports/stm32/make-stmconst.py b/ports/stm32/make-stmconst.py index 6d64fe3cfaf4f..4ef6143bda560 100644 --- a/ports/stm32/make-stmconst.py +++ b/ports/stm32/make-stmconst.py @@ -213,7 +213,7 @@ def print_regs_as_submodules(reg_name, reg_defs, modules): print( """ -STATIC const mp_rom_map_elem_t stm_%s_globals_table[] = { +static const mp_rom_map_elem_t stm_%s_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_%s) }, """ % (mod_name_lower, mod_name_upper) @@ -228,7 +228,7 @@ def print_regs_as_submodules(reg_name, reg_defs, modules): print( """}; -STATIC MP_DEFINE_CONST_DICT(stm_%s_globals, stm_%s_globals_table); +static MP_DEFINE_CONST_DICT(stm_%s_globals, stm_%s_globals_table); const mp_obj_module_t stm_%s_obj = { .base = { &mp_type_module }, @@ -310,7 +310,7 @@ def main(): for mpz in sorted(needed_mpzs): assert 0 <= mpz <= 0xFFFFFFFF print( - "STATIC const mp_obj_int_t mpz_%08x = {{&mp_type_int}, " + "static const mp_obj_int_t mpz_%08x = {{&mp_type_int}, " "{.neg=0, .fixed_dig=1, .alloc=2, .len=2, " ".dig=(uint16_t*)(const uint16_t[]){%#x, %#x}}};" % (mpz, mpz & 0xFFFF, (mpz >> 16) & 0xFFFF), diff --git a/ports/stm32/mboot/main.c b/ports/stm32/mboot/main.c index 39492b4e5474e..9bb2dcfcaf408 100644 --- a/ports/stm32/mboot/main.c +++ b/ports/stm32/mboot/main.c @@ -1051,7 +1051,7 @@ typedef struct _pyb_usbdd_obj_t { #define MSFT100_VENDOR_CODE (0x42) #if !MICROPY_HW_USB_IS_MULTI_OTG -STATIC const uint8_t usbd_fifo_size[USBD_PMA_NUM_FIFO] = { +static const uint8_t usbd_fifo_size[USBD_PMA_NUM_FIFO] = { 32, 32, // EP0(out), EP0(in) 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 14x unused }; diff --git a/ports/stm32/modmachine.c b/ports/stm32/modmachine.c index 206d28a89e25d..7c1c4da60bff2 100644 --- a/ports/stm32/modmachine.c +++ b/ports/stm32/modmachine.c @@ -114,7 +114,7 @@ { MP_ROM_QSTR(MP_QSTR_DEEPSLEEP_RESET), MP_ROM_INT(PYB_RESET_DEEPSLEEP) }, \ { MP_ROM_QSTR(MP_QSTR_SOFT_RESET), MP_ROM_INT(PYB_RESET_SOFT) }, \ -STATIC uint32_t reset_cause; +static uint32_t reset_cause; void machine_init(void) { #if defined(STM32F4) @@ -186,7 +186,7 @@ void machine_deinit(void) { // machine.info([dump_alloc_table]) // Print out lots of information about the board. -STATIC mp_obj_t machine_info(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_info(size_t n_args, const mp_obj_t *args) { const mp_print_t *print = &mp_plat_print; // get and print unique id; 96 bits @@ -277,13 +277,13 @@ STATIC mp_obj_t machine_info(size_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj, 0, 1, machine_info); // Returns a string of 12 bytes (96 bits), which is the unique ID for the MCU. -STATIC mp_obj_t mp_machine_unique_id(void) { +static mp_obj_t mp_machine_unique_id(void) { byte *id = (byte *)MP_HAL_UNIQUE_ID_ADDRESS; return mp_obj_new_bytes(id, 12); } // Resets the pyboard in a manner similar to pushing the external RESET button. -NORETURN STATIC void mp_machine_reset(void) { +NORETURN static void mp_machine_reset(void) { powerctrl_mcu_reset(); } @@ -314,7 +314,7 @@ NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) { } // get or set the MCU frequencies -STATIC mp_obj_t mp_machine_get_freq(void) { +static mp_obj_t mp_machine_get_freq(void) { mp_obj_t tuple[] = { mp_obj_new_int(HAL_RCC_GetSysClockFreq()), mp_obj_new_int(HAL_RCC_GetHCLKFreq()), @@ -326,7 +326,7 @@ STATIC mp_obj_t mp_machine_get_freq(void) { return mp_obj_new_tuple(MP_ARRAY_SIZE(tuple), tuple); } -STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) { +static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) { #if defined(STM32F0) || defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32G0) mp_raise_NotImplementedError(MP_ERROR_TEXT("machine.freq set not supported yet")); #else @@ -365,11 +365,11 @@ STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) { // idle() // This executies a wfi machine instruction which reduces power consumption // of the MCU until an interrupt occurs, at which point execution continues. -STATIC void mp_machine_idle(void) { +static void mp_machine_idle(void) { __WFI(); } -STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) { +static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) { if (n_args != 0) { mp_obj_t args2[2] = {MP_OBJ_NULL, args[0]}; pyb_rtc_wakeup(2, args2); @@ -377,7 +377,7 @@ STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) { powerctrl_enter_stop_mode(); } -STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) { +static void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) { if (n_args != 0) { mp_obj_t args2[2] = {MP_OBJ_NULL, args[0]}; pyb_rtc_wakeup(2, args2); @@ -385,6 +385,6 @@ STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) { powerctrl_enter_standby_mode(); } -STATIC mp_int_t mp_machine_reset_cause(void) { +static mp_int_t mp_machine_reset_cause(void) { return reset_cause; } diff --git a/ports/stm32/modos.c b/ports/stm32/modos.c index 6f3577f44a2ed..7949cf87cdecd 100644 --- a/ports/stm32/modos.c +++ b/ports/stm32/modos.c @@ -34,7 +34,7 @@ // urandom(n) // Return a bytes object with n random bytes, generated by the hardware // random number generator. -STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { +static mp_obj_t mp_os_urandom(mp_obj_t num) { mp_int_t n = mp_obj_get_int(num); vstr_t vstr; vstr_init_len(&vstr, n); @@ -43,7 +43,7 @@ STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { } return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); #endif bool mp_os_dupterm_is_builtin_stream(mp_const_obj_t stream) { diff --git a/ports/stm32/modpyb.c b/ports/stm32/modpyb.c index 165c982f5daf7..176010a7e5107 100644 --- a/ports/stm32/modpyb.c +++ b/ports/stm32/modpyb.c @@ -59,37 +59,37 @@ #if MICROPY_PY_PYB -STATIC mp_obj_t pyb_fault_debug(mp_obj_t value) { +static mp_obj_t pyb_fault_debug(mp_obj_t value) { pyb_hard_fault_debug = mp_obj_is_true(value); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_fault_debug_obj, pyb_fault_debug); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_fault_debug_obj, pyb_fault_debug); -STATIC mp_obj_t pyb_idle(void) { +static mp_obj_t pyb_idle(void) { __WFI(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_idle_obj, pyb_idle); +static MP_DEFINE_CONST_FUN_OBJ_0(pyb_idle_obj, pyb_idle); #if MICROPY_PY_PYB_LEGACY // Returns the number of milliseconds which have elapsed since `start`. // This function takes care of counter wrap and always returns a positive number. -STATIC mp_obj_t pyb_elapsed_millis(mp_obj_t start) { +static mp_obj_t pyb_elapsed_millis(mp_obj_t start) { uint32_t startMillis = mp_obj_get_int(start); uint32_t currMillis = mp_hal_ticks_ms(); return MP_OBJ_NEW_SMALL_INT((currMillis - startMillis) & 0x3fffffff); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_elapsed_millis_obj, pyb_elapsed_millis); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_elapsed_millis_obj, pyb_elapsed_millis); // Returns the number of microseconds which have elapsed since `start`. // This function takes care of counter wrap and always returns a positive number. -STATIC mp_obj_t pyb_elapsed_micros(mp_obj_t start) { +static mp_obj_t pyb_elapsed_micros(mp_obj_t start) { uint32_t startMicros = mp_obj_get_int(start); uint32_t currMicros = mp_hal_ticks_us(); return MP_OBJ_NEW_SMALL_INT((currMicros - startMicros) & 0x3fffffff); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_elapsed_micros_obj, pyb_elapsed_micros); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_elapsed_micros_obj, pyb_elapsed_micros); #endif @@ -97,7 +97,7 @@ MP_DECLARE_CONST_FUN_OBJ_KW(pyb_main_obj); // defined in main.c // Get or set the UART object that the REPL is repeated on. // This is a legacy function, use of os.dupterm is preferred. -STATIC mp_obj_t pyb_repl_uart(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_repl_uart(size_t n_args, const mp_obj_t *args) { if (n_args == 0) { if (MP_STATE_PORT(pyb_stdio_uart) == NULL) { return mp_const_none; @@ -119,22 +119,22 @@ STATIC mp_obj_t pyb_repl_uart(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_repl_uart_obj, 0, 1, pyb_repl_uart); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_repl_uart_obj, 0, 1, pyb_repl_uart); #if MICROPY_PY_NETWORK MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mod_network_country_obj); #else // Provide a no-op version of pyb.country for backwards compatibility on // boards that don't support networking. -STATIC mp_obj_t pyb_country(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_country(size_t n_args, const mp_obj_t *args) { (void)n_args; (void)args; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_network_country_obj, 0, 1, pyb_country); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_network_country_obj, 0, 1, pyb_country); #endif -STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = { +static const mp_rom_map_elem_t pyb_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_pyb) }, { MP_ROM_QSTR(MP_QSTR_fault_debug), MP_ROM_PTR(&pyb_fault_debug_obj) }, @@ -262,7 +262,7 @@ STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(pyb_module_globals, pyb_module_globals_table); +static MP_DEFINE_CONST_DICT(pyb_module_globals, pyb_module_globals_table); const mp_obj_module_t pyb_module = { .base = { &mp_type_module }, diff --git a/ports/stm32/modstm.c b/ports/stm32/modstm.c index 896465d0cc927..4f26dce790f43 100644 --- a/ports/stm32/modstm.c +++ b/ports/stm32/modstm.c @@ -38,7 +38,7 @@ #include "genhdr/modstm_mpz.h" -STATIC const mp_rom_map_elem_t stm_module_globals_table[] = { +static const mp_rom_map_elem_t stm_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_stm) }, { MP_ROM_QSTR(MP_QSTR_mem8), MP_ROM_PTR(&machine_mem8_obj) }, @@ -62,7 +62,7 @@ STATIC const mp_rom_map_elem_t stm_module_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(stm_module_globals, stm_module_globals_table); +static MP_DEFINE_CONST_DICT(stm_module_globals, stm_module_globals_table); const mp_obj_module_t stm_module = { .base = { &mp_type_module }, diff --git a/ports/stm32/modtime.c b/ports/stm32/modtime.c index e7160cd5b2cc0..ff1495a5d965a 100644 --- a/ports/stm32/modtime.c +++ b/ports/stm32/modtime.c @@ -29,7 +29,7 @@ #include "rtc.h" // Return the localtime as an 8-tuple. -STATIC mp_obj_t mp_time_localtime_get(void) { +static mp_obj_t mp_time_localtime_get(void) { // get current date and time // note: need to call get time then get date to correctly access the registers rtc_init_finalise(); @@ -51,7 +51,7 @@ STATIC mp_obj_t mp_time_localtime_get(void) { } // Returns the number of seconds, as an integer, since 1/1/2000. -STATIC mp_obj_t mp_time_time_get(void) { +static mp_obj_t mp_time_time_get(void) { // get date and time // note: need to call get time then get date to correctly access the registers rtc_init_finalise(); diff --git a/ports/stm32/mpbthciport.c b/ports/stm32/mpbthciport.c index 06ff8a7faa658..3f71146834e91 100644 --- a/ports/stm32/mpbthciport.c +++ b/ports/stm32/mpbthciport.c @@ -41,10 +41,10 @@ uint8_t mp_bluetooth_hci_cmd_buf[4 + 256]; // Soft timer for scheduling a HCI poll. -STATIC soft_timer_entry_t mp_bluetooth_hci_soft_timer; +static soft_timer_entry_t mp_bluetooth_hci_soft_timer; // This is called by soft_timer and executes at IRQ_PRI_PENDSV. -STATIC void mp_bluetooth_hci_soft_timer_callback(soft_timer_entry_t *self) { +static void mp_bluetooth_hci_soft_timer_callback(soft_timer_entry_t *self) { mp_bluetooth_hci_poll_now(); } @@ -57,7 +57,7 @@ void mp_bluetooth_hci_init(void) { ); } -STATIC void mp_bluetooth_hci_start_polling(void) { +static void mp_bluetooth_hci_start_polling(void) { mp_bluetooth_hci_poll_now(); } @@ -67,12 +67,12 @@ void mp_bluetooth_hci_poll_in_ms_default(uint32_t ms) { #if MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS -STATIC mp_sched_node_t mp_bluetooth_hci_sched_node; +static mp_sched_node_t mp_bluetooth_hci_sched_node; // For synchronous mode, we run all BLE stack code inside a scheduled task. // This task is scheduled periodically via a soft timer, or // immediately on HCI UART RXIDLE. -STATIC void run_events_scheduled_task(mp_sched_node_t *node) { +static void run_events_scheduled_task(mp_sched_node_t *node) { // This will process all buffered HCI UART data, and run any callouts or events. (void)node; mp_bluetooth_hci_poll(); @@ -133,7 +133,7 @@ int mp_bluetooth_hci_uart_write(const uint8_t *buf, size_t len) { } // Callback to forward data from rfcore to the bluetooth hci handler. -STATIC void mp_bluetooth_hci_uart_msg_cb(void *env, const uint8_t *buf, size_t len) { +static void mp_bluetooth_hci_uart_msg_cb(void *env, const uint8_t *buf, size_t len) { mp_bluetooth_hci_uart_readchar_t handler = (mp_bluetooth_hci_uart_readchar_t)env; for (size_t i = 0; i < len; ++i) { handler(buf[i]); diff --git a/ports/stm32/mpbtstackport.c b/ports/stm32/mpbtstackport.c index 728594d19c96a..bbc1280b8624b 100644 --- a/ports/stm32/mpbtstackport.c +++ b/ports/stm32/mpbtstackport.c @@ -106,7 +106,7 @@ static const btstack_run_loop_t mp_btstack_runloop_stm32 = { &mp_btstack_runloop_get_time_ms, }; -STATIC const hci_transport_config_uart_t hci_transport_config_uart = { +static const hci_transport_config_uart_t hci_transport_config_uart = { HCI_TRANSPORT_CONFIG_UART, MICROPY_HW_BLE_UART_BAUDRATE, MICROPY_HW_BLE_UART_BAUDRATE_SECONDARY, diff --git a/ports/stm32/mpnetworkport.c b/ports/stm32/mpnetworkport.c index 3b9591213a8d2..6db3e91ba90ef 100644 --- a/ports/stm32/mpnetworkport.c +++ b/ports/stm32/mpnetworkport.c @@ -64,7 +64,7 @@ u32_t sys_now(void) { return mp_hal_ticks_ms(); } -STATIC void pyb_lwip_poll(void) { +static void pyb_lwip_poll(void) { #if MICROPY_PY_NETWORK_WIZNET5K // Poll the NIC for incoming data wiznet5k_poll(); diff --git a/ports/stm32/mpthreadport.c b/ports/stm32/mpthreadport.c index a7d85cfe32987..621b4311bfc34 100644 --- a/ports/stm32/mpthreadport.c +++ b/ports/stm32/mpthreadport.c @@ -34,7 +34,7 @@ #if MICROPY_PY_THREAD // the mutex controls access to the linked list -STATIC mp_thread_mutex_t thread_mutex; +static mp_thread_mutex_t thread_mutex; void mp_thread_init(void) { mp_thread_mutex_init(&thread_mutex); diff --git a/ports/stm32/network_lan.c b/ports/stm32/network_lan.c index 556adebd8fe95..2f70caf0123a4 100644 --- a/ports/stm32/network_lan.c +++ b/ports/stm32/network_lan.c @@ -38,9 +38,9 @@ typedef struct _network_lan_obj_t { eth_t *eth; } network_lan_obj_t; -STATIC const network_lan_obj_t network_lan_eth0 = { { &network_lan_type }, ð_instance }; +static const network_lan_obj_t network_lan_eth0 = { { &network_lan_type }, ð_instance }; -STATIC void network_lan_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void network_lan_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { network_lan_obj_t *self = MP_OBJ_TO_PTR(self_in); struct netif *netif = eth_netif(self->eth); int status = eth_link_status(self->eth); @@ -53,14 +53,14 @@ STATIC void network_lan_print(const mp_print_t *print, mp_obj_t self_in, mp_prin ); } -STATIC mp_obj_t network_lan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t network_lan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 0, false); const network_lan_obj_t *self = &network_lan_eth0; eth_init(self->eth, MP_HAL_MAC_ETH0); return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t network_lan_active(size_t n_args, const mp_obj_t *args) { +static mp_obj_t network_lan_active(size_t n_args, const mp_obj_t *args) { network_lan_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 1) { return mp_obj_new_bool(eth_link_status(self->eth)); @@ -77,21 +77,21 @@ STATIC mp_obj_t network_lan_active(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_lan_active_obj, 1, 2, network_lan_active); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_lan_active_obj, 1, 2, network_lan_active); -STATIC mp_obj_t network_lan_isconnected(mp_obj_t self_in) { +static mp_obj_t network_lan_isconnected(mp_obj_t self_in) { network_lan_obj_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_bool(eth_link_status(self->eth) == 3); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_lan_isconnected_obj, network_lan_isconnected); +static MP_DEFINE_CONST_FUN_OBJ_1(network_lan_isconnected_obj, network_lan_isconnected); -STATIC mp_obj_t network_lan_ifconfig(size_t n_args, const mp_obj_t *args) { +static mp_obj_t network_lan_ifconfig(size_t n_args, const mp_obj_t *args) { network_lan_obj_t *self = MP_OBJ_TO_PTR(args[0]); return mod_network_nic_ifconfig(eth_netif(self->eth), n_args - 1, args + 1); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_lan_ifconfig_obj, 1, 2, network_lan_ifconfig); -STATIC mp_obj_t network_lan_status(size_t n_args, const mp_obj_t *args) { +static mp_obj_t network_lan_status(size_t n_args, const mp_obj_t *args) { network_lan_obj_t *self = MP_OBJ_TO_PTR(args[0]); (void)self; @@ -102,9 +102,9 @@ STATIC mp_obj_t network_lan_status(size_t n_args, const mp_obj_t *args) { mp_raise_ValueError(MP_ERROR_TEXT("unknown status param")); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_lan_status_obj, 1, 2, network_lan_status); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_lan_status_obj, 1, 2, network_lan_status); -STATIC mp_obj_t network_lan_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { +static mp_obj_t network_lan_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { network_lan_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (kwargs->used == 0) { @@ -147,16 +147,16 @@ STATIC mp_obj_t network_lan_config(size_t n_args, const mp_obj_t *args, mp_map_t return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(network_lan_config_obj, 1, network_lan_config); +static MP_DEFINE_CONST_FUN_OBJ_KW(network_lan_config_obj, 1, network_lan_config); -STATIC const mp_rom_map_elem_t network_lan_locals_dict_table[] = { +static const mp_rom_map_elem_t network_lan_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&network_lan_active_obj) }, { MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&network_lan_isconnected_obj) }, { MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&network_lan_ifconfig_obj) }, { MP_ROM_QSTR(MP_QSTR_status), MP_ROM_PTR(&network_lan_status_obj) }, { MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&network_lan_config_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(network_lan_locals_dict, network_lan_locals_dict_table); +static MP_DEFINE_CONST_DICT(network_lan_locals_dict, network_lan_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( network_lan_type, diff --git a/ports/stm32/octospi.c b/ports/stm32/octospi.c index f2854f3796eb2..1d59e2b560eda 100644 --- a/ports/stm32/octospi.c +++ b/ports/stm32/octospi.c @@ -92,7 +92,7 @@ void octospi_init(void) { OCTOSPI1->CR |= OCTOSPI_CR_EN; } -STATIC int octospi_ioctl(void *self_in, uint32_t cmd) { +static int octospi_ioctl(void *self_in, uint32_t cmd) { (void)self_in; switch (cmd) { case MP_QSPI_IOCTL_INIT: @@ -112,7 +112,7 @@ STATIC int octospi_ioctl(void *self_in, uint32_t cmd) { return 0; // success } -STATIC int octospi_write_cmd_data(void *self_in, uint8_t cmd, size_t len, uint32_t data) { +static int octospi_write_cmd_data(void *self_in, uint8_t cmd, size_t len, uint32_t data) { (void)self_in; OCTOSPI1->FCR = OCTOSPI_FCR_CTCF; // clear TC flag @@ -166,7 +166,7 @@ STATIC int octospi_write_cmd_data(void *self_in, uint8_t cmd, size_t len, uint32 return 0; } -STATIC int octospi_write_cmd_addr_data(void *self_in, uint8_t cmd, uint32_t addr, size_t len, const uint8_t *src) { +static int octospi_write_cmd_addr_data(void *self_in, uint8_t cmd, uint32_t addr, size_t len, const uint8_t *src) { (void)self_in; uint8_t adsize = MICROPY_HW_SPI_ADDR_IS_32BIT(addr) ? 3 : 2; @@ -231,7 +231,7 @@ STATIC int octospi_write_cmd_addr_data(void *self_in, uint8_t cmd, uint32_t addr return 0; } -STATIC int octospi_read_cmd(void *self_in, uint8_t cmd, size_t len, uint32_t *dest) { +static int octospi_read_cmd(void *self_in, uint8_t cmd, size_t len, uint32_t *dest) { (void)self_in; OCTOSPI1->FCR = OCTOSPI_FCR_CTCF; // clear TC flag @@ -269,7 +269,7 @@ STATIC int octospi_read_cmd(void *self_in, uint8_t cmd, size_t len, uint32_t *de return 0; } -STATIC int octospi_read_cmd_qaddr_qdata(void *self_in, uint8_t cmd, uint32_t addr, size_t len, uint8_t *dest) { +static int octospi_read_cmd_qaddr_qdata(void *self_in, uint8_t cmd, uint32_t addr, size_t len, uint8_t *dest) { (void)self_in; #if defined(MICROPY_HW_OSPIFLASH_IO1) && !defined(MICROPY_HW_OSPIFLASH_IO2) && !defined(MICROPY_HW_OSPIFLASH_IO4) diff --git a/ports/stm32/pin.c b/ports/stm32/pin.c index 599d61de41682..0b939334a2b6d 100644 --- a/ports/stm32/pin.c +++ b/ports/stm32/pin.c @@ -88,7 +88,7 @@ /// how a particular object gets mapped to a pin. // Pin class variables -STATIC bool pin_class_debug; +static bool pin_class_debug; void pin_init0(void) { MP_STATE_PORT(pin_class_mapper) = mp_const_none; @@ -179,7 +179,7 @@ const machine_pin_obj_t *pin_find(mp_obj_t user_obj) { /// \method __str__() /// Return a string describing the pin object. -STATIC void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); // pin name @@ -238,7 +238,7 @@ STATIC void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t } } -STATIC mp_obj_t pin_obj_init_helper(const machine_pin_obj_t *pin, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args); +static mp_obj_t pin_obj_init_helper(const machine_pin_obj_t *pin, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args); /// \classmethod \constructor(id, ...) /// Create a new Pin object associated with the id. If additional arguments are given, @@ -263,7 +263,7 @@ mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, } // fast method for getting/setting pin value -STATIC mp_obj_t pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); if (n_args == 0) { @@ -278,31 +278,31 @@ STATIC mp_obj_t pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_ /// \classmethod mapper([fun]) /// Get or set the pin mapper function. -STATIC mp_obj_t pin_mapper(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pin_mapper(size_t n_args, const mp_obj_t *args) { if (n_args > 1) { MP_STATE_PORT(pin_class_mapper) = args[1]; return mp_const_none; } return MP_STATE_PORT(pin_class_mapper); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_mapper_fun_obj, 1, 2, pin_mapper); -STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_mapper_obj, MP_ROM_PTR(&pin_mapper_fun_obj)); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_mapper_fun_obj, 1, 2, pin_mapper); +static MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_mapper_obj, MP_ROM_PTR(&pin_mapper_fun_obj)); /// \classmethod dict([dict]) /// Get or set the pin mapper dictionary. -STATIC mp_obj_t pin_map_dict(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pin_map_dict(size_t n_args, const mp_obj_t *args) { if (n_args > 1) { MP_STATE_PORT(pin_class_map_dict) = args[1]; return mp_const_none; } return MP_STATE_PORT(pin_class_map_dict); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_map_dict_fun_obj, 1, 2, pin_map_dict); -STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_map_dict_obj, MP_ROM_PTR(&pin_map_dict_fun_obj)); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_map_dict_fun_obj, 1, 2, pin_map_dict); +static MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_map_dict_obj, MP_ROM_PTR(&pin_map_dict_fun_obj)); /// \classmethod af_list() /// Returns an array of alternate functions available for this pin. -STATIC mp_obj_t pin_af_list(mp_obj_t self_in) { +static mp_obj_t pin_af_list(mp_obj_t self_in) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_t result = mp_obj_new_list(0, NULL); @@ -312,22 +312,22 @@ STATIC mp_obj_t pin_af_list(mp_obj_t self_in) { } return result; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_af_list_obj, pin_af_list); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_list_obj, pin_af_list); /// \classmethod debug([state]) /// Get or set the debugging state (`True` or `False` for on or off). -STATIC mp_obj_t pin_debug(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pin_debug(size_t n_args, const mp_obj_t *args) { if (n_args > 1) { pin_class_debug = mp_obj_is_true(args[1]); return mp_const_none; } return mp_obj_new_bool(pin_class_debug); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_debug_fun_obj, 1, 2, pin_debug); -STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_debug_obj, MP_ROM_PTR(&pin_debug_fun_obj)); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_debug_fun_obj, 1, 2, pin_debug); +static MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_debug_obj, MP_ROM_PTR(&pin_debug_fun_obj)); // init(mode, pull=None, alt=-1, *, value, alt) -STATIC mp_obj_t pin_obj_init_helper(const machine_pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pin_obj_init_helper(const machine_pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT }, { MP_QSTR_pull, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE}}, @@ -384,7 +384,7 @@ STATIC mp_obj_t pin_obj_init_helper(const machine_pin_obj_t *self, size_t n_args return mp_const_none; } -STATIC mp_obj_t pin_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t pin_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { return pin_obj_init_helper(MP_OBJ_TO_PTR(args[0]), n_args - 1, args + 1, kw_args); } MP_DEFINE_CONST_FUN_OBJ_KW(pin_init_obj, 1, pin_obj_init); @@ -396,27 +396,27 @@ MP_DEFINE_CONST_FUN_OBJ_KW(pin_init_obj, 1, pin_obj_init); /// - With `value` given, set the logic level of the pin. `value` can be /// anything that converts to a boolean. If it converts to `True`, the pin /// is set high, otherwise it is set low. -STATIC mp_obj_t pin_value(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pin_value(size_t n_args, const mp_obj_t *args) { return pin_call(args[0], n_args - 1, 0, args + 1); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_value_obj, 1, 2, pin_value); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_value_obj, 1, 2, pin_value); -STATIC mp_obj_t pin_off(mp_obj_t self_in) { +static mp_obj_t pin_off(mp_obj_t self_in) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_hal_pin_low(self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_off_obj, pin_off); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_off_obj, pin_off); -STATIC mp_obj_t pin_on(mp_obj_t self_in) { +static mp_obj_t pin_on(mp_obj_t self_in) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_hal_pin_high(self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_on_obj, pin_on); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_on_obj, pin_on); // pin.irq(handler=None, trigger=IRQ_FALLING|IRQ_RISING, hard=False) -STATIC mp_obj_t pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_handler, ARG_trigger, ARG_hard }; static const mp_arg_t allowed_args[] = { { MP_QSTR_handler, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, @@ -436,19 +436,19 @@ STATIC mp_obj_t pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar // TODO should return an IRQ object return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pin_irq_obj, 1, pin_irq); +static MP_DEFINE_CONST_FUN_OBJ_KW(pin_irq_obj, 1, pin_irq); /// \method name() /// Get the pin name. -STATIC mp_obj_t pin_name(mp_obj_t self_in) { +static mp_obj_t pin_name(mp_obj_t self_in) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); return MP_OBJ_NEW_QSTR(self->name); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_name_obj, pin_name); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_name_obj, pin_name); /// \method names() /// Returns the cpu and board names for this pin. -STATIC mp_obj_t pin_names(mp_obj_t self_in) { +static mp_obj_t pin_names(mp_obj_t self_in) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_t result = mp_obj_new_list(0, NULL); mp_obj_list_append(result, MP_OBJ_NEW_QSTR(self->name)); @@ -463,60 +463,60 @@ STATIC mp_obj_t pin_names(mp_obj_t self_in) { } return result; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_names_obj, pin_names); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_names_obj, pin_names); /// \method port() /// Get the pin port. -STATIC mp_obj_t pin_port(mp_obj_t self_in) { +static mp_obj_t pin_port(mp_obj_t self_in) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); return MP_OBJ_NEW_SMALL_INT(self->port); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_port_obj, pin_port); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_port_obj, pin_port); /// \method pin() /// Get the pin number. -STATIC mp_obj_t pin_pin(mp_obj_t self_in) { +static mp_obj_t pin_pin(mp_obj_t self_in) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); return MP_OBJ_NEW_SMALL_INT(self->pin); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_pin_obj, pin_pin); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_pin_obj, pin_pin); /// \method gpio() /// Returns the base address of the GPIO block associated with this pin. -STATIC mp_obj_t pin_gpio(mp_obj_t self_in) { +static mp_obj_t pin_gpio(mp_obj_t self_in) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); return MP_OBJ_NEW_SMALL_INT((intptr_t)self->gpio); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_gpio_obj, pin_gpio); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_gpio_obj, pin_gpio); /// \method mode() /// Returns the currently configured mode of the pin. The integer returned /// will match one of the allowed constants for the mode argument to the init /// function. -STATIC mp_obj_t pin_mode(mp_obj_t self_in) { +static mp_obj_t pin_mode(mp_obj_t self_in) { return MP_OBJ_NEW_SMALL_INT(pin_get_mode(MP_OBJ_TO_PTR(self_in))); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_mode_obj, pin_mode); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_mode_obj, pin_mode); /// \method pull() /// Returns the currently configured pull of the pin. The integer returned /// will match one of the allowed constants for the pull argument to the init /// function. -STATIC mp_obj_t pin_pull(mp_obj_t self_in) { +static mp_obj_t pin_pull(mp_obj_t self_in) { return MP_OBJ_NEW_SMALL_INT(pin_get_pull(MP_OBJ_TO_PTR(self_in))); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_pull_obj, pin_pull); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_pull_obj, pin_pull); /// \method af() /// Returns the currently configured alternate-function of the pin. The /// integer returned will match one of the allowed constants for the af /// argument to the init function. -STATIC mp_obj_t pin_af(mp_obj_t self_in) { +static mp_obj_t pin_af(mp_obj_t self_in) { return MP_OBJ_NEW_SMALL_INT(pin_get_af(MP_OBJ_TO_PTR(self_in))); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_af_obj, pin_af); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_obj, pin_af); -STATIC const mp_rom_map_elem_t pin_locals_dict_table[] = { +static const mp_rom_map_elem_t pin_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pin_init_obj) }, { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&pin_value_obj) }, @@ -568,9 +568,9 @@ STATIC const mp_rom_map_elem_t pin_locals_dict_table[] = { #include "genhdr/pins_af_const.h" }; -STATIC MP_DEFINE_CONST_DICT(pin_locals_dict, pin_locals_dict_table); +static MP_DEFINE_CONST_DICT(pin_locals_dict, pin_locals_dict_table); -STATIC mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { (void)errcode; machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); @@ -586,7 +586,7 @@ STATIC mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, i return -1; } -STATIC const mp_pin_p_t pin_pin_p = { +static const mp_pin_p_t pin_pin_p = { .ioctl = pin_ioctl, }; @@ -630,43 +630,43 @@ MP_DEFINE_CONST_OBJ_TYPE( /// \method __str__() /// Return a string describing the alternate function. -STATIC void pin_af_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void pin_af_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pin_af_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "Pin.%q", self->name); } /// \method index() /// Return the alternate function index. -STATIC mp_obj_t pin_af_index(mp_obj_t self_in) { +static mp_obj_t pin_af_index(mp_obj_t self_in) { pin_af_obj_t *af = MP_OBJ_TO_PTR(self_in); return MP_OBJ_NEW_SMALL_INT(af->idx); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_af_index_obj, pin_af_index); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_index_obj, pin_af_index); /// \method name() /// Return the name of the alternate function. -STATIC mp_obj_t pin_af_name(mp_obj_t self_in) { +static mp_obj_t pin_af_name(mp_obj_t self_in) { pin_af_obj_t *af = MP_OBJ_TO_PTR(self_in); return MP_OBJ_NEW_QSTR(af->name); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_af_name_obj, pin_af_name); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_name_obj, pin_af_name); /// \method reg() /// Return the base register associated with the peripheral assigned to this /// alternate function. For example, if the alternate function were TIM2_CH3 /// this would return stm.TIM2 -STATIC mp_obj_t pin_af_reg(mp_obj_t self_in) { +static mp_obj_t pin_af_reg(mp_obj_t self_in) { pin_af_obj_t *af = MP_OBJ_TO_PTR(self_in); return MP_OBJ_NEW_SMALL_INT((uintptr_t)af->reg); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pin_af_reg_obj, pin_af_reg); +static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_reg_obj, pin_af_reg); -STATIC const mp_rom_map_elem_t pin_af_locals_dict_table[] = { +static const mp_rom_map_elem_t pin_af_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_index), MP_ROM_PTR(&pin_af_index_obj) }, { MP_ROM_QSTR(MP_QSTR_name), MP_ROM_PTR(&pin_af_name_obj) }, { MP_ROM_QSTR(MP_QSTR_reg), MP_ROM_PTR(&pin_af_reg_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(pin_af_locals_dict, pin_af_locals_dict_table); +static MP_DEFINE_CONST_DICT(pin_af_locals_dict, pin_af_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pin_af_type, diff --git a/ports/stm32/powerctrl.c b/ports/stm32/powerctrl.c index 712021edb63ce..7755149227216 100644 --- a/ports/stm32/powerctrl.c +++ b/ports/stm32/powerctrl.c @@ -162,14 +162,14 @@ typedef struct _sysclk_scaling_table_entry_t { } sysclk_scaling_table_entry_t; #if defined(STM32F7) -STATIC const sysclk_scaling_table_entry_t volt_scale_table[] = { +static const sysclk_scaling_table_entry_t volt_scale_table[] = { { 151, PWR_REGULATOR_VOLTAGE_SCALE3 }, { 180, PWR_REGULATOR_VOLTAGE_SCALE2 }, // Above 180MHz uses default PWR_REGULATOR_VOLTAGE_SCALE1 }; #elif defined(STM32H7A3xx) || defined(STM32H7A3xxQ) || \ defined(STM32H7B3xx) || defined(STM32H7B3xxQ) -STATIC const sysclk_scaling_table_entry_t volt_scale_table[] = { +static const sysclk_scaling_table_entry_t volt_scale_table[] = { // See table 15 "FLASH recommended number of wait states and programming delay" of RM0455. {88, PWR_REGULATOR_VOLTAGE_SCALE3}, {160, PWR_REGULATOR_VOLTAGE_SCALE2}, @@ -177,7 +177,7 @@ STATIC const sysclk_scaling_table_entry_t volt_scale_table[] = { {280, PWR_REGULATOR_VOLTAGE_SCALE0}, }; #elif defined(STM32H7) -STATIC const sysclk_scaling_table_entry_t volt_scale_table[] = { +static const sysclk_scaling_table_entry_t volt_scale_table[] = { // See table 55 "Kernel clock distribution overview" of RM0433. {200, PWR_REGULATOR_VOLTAGE_SCALE3}, {300, PWR_REGULATOR_VOLTAGE_SCALE2}, @@ -186,7 +186,7 @@ STATIC const sysclk_scaling_table_entry_t volt_scale_table[] = { }; #endif -STATIC int powerctrl_config_vos(uint32_t sysclk_mhz) { +static int powerctrl_config_vos(uint32_t sysclk_mhz) { #if defined(STM32F7) || defined(STM32H7) uint32_t volt_scale = PWR_REGULATOR_VOLTAGE_SCALE1; for (int i = 0; i < MP_ARRAY_SIZE(volt_scale_table); ++i) { @@ -291,7 +291,7 @@ int powerctrl_rcc_clock_config_pll(RCC_ClkInitTypeDef *rcc_init, uint32_t sysclk #if !defined(STM32F0) && !defined(STM32G0) && !defined(STM32L0) && !defined(STM32L1) && !defined(STM32L4) -STATIC uint32_t calc_ahb_div(uint32_t wanted_div) { +static uint32_t calc_ahb_div(uint32_t wanted_div) { #if defined(STM32H7) if (wanted_div <= 1) { return RCC_HCLK_DIV1; @@ -335,7 +335,7 @@ STATIC uint32_t calc_ahb_div(uint32_t wanted_div) { #endif } -STATIC uint32_t calc_apb1_div(uint32_t wanted_div) { +static uint32_t calc_apb1_div(uint32_t wanted_div) { #if defined(STM32H7) if (wanted_div <= 1) { return RCC_APB1_DIV1; @@ -363,7 +363,7 @@ STATIC uint32_t calc_apb1_div(uint32_t wanted_div) { #endif } -STATIC uint32_t calc_apb2_div(uint32_t wanted_div) { +static uint32_t calc_apb2_div(uint32_t wanted_div) { #if defined(STM32H7) if (wanted_div <= 1) { return RCC_APB2_DIV1; diff --git a/ports/stm32/pyb_can.c b/ports/stm32/pyb_can.c index 3c61405e7c317..71c717782449f 100644 --- a/ports/stm32/pyb_can.c +++ b/ports/stm32/pyb_can.c @@ -123,11 +123,11 @@ extern const uint8_t DLCtoBytes[16]; #define CAN_FLAG_FIFO0_OVRF CAN_FLAG_FOV0 #define CAN_FLAG_FIFO1_OVRF CAN_FLAG_FOV1 -STATIC uint8_t can2_start_bank = 14; +static uint8_t can2_start_bank = 14; #endif -STATIC void pyb_can_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void pyb_can_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_can_obj_t *self = MP_OBJ_TO_PTR(self_in); if (!self->is_enabled) { mp_printf(print, "CAN(%u)", self->can_id); @@ -160,7 +160,7 @@ STATIC void pyb_can_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki } } -STATIC uint32_t pyb_can_get_source_freq() { +static uint32_t pyb_can_get_source_freq() { uint32_t can_kern_clk = 0; // Find CAN kernel clock @@ -192,7 +192,7 @@ STATIC uint32_t pyb_can_get_source_freq() { return can_kern_clk; } -STATIC void pyb_can_get_bit_timing(mp_uint_t baudrate, mp_uint_t sample_point, +static void pyb_can_get_bit_timing(mp_uint_t baudrate, mp_uint_t sample_point, uint32_t max_brp, uint32_t max_bs1, uint32_t max_bs2, uint32_t min_tseg, mp_int_t *bs1_out, mp_int_t *bs2_out, mp_int_t *prescaler_out) { uint32_t can_kern_clk = pyb_can_get_source_freq(); @@ -215,7 +215,7 @@ STATIC void pyb_can_get_bit_timing(mp_uint_t baudrate, mp_uint_t sample_point, } // init(mode, prescaler=100, *, sjw=1, bs1=6, bs2=8) -STATIC mp_obj_t pyb_can_init_helper(pyb_can_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_can_init_helper(pyb_can_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_mode, ARG_prescaler, ARG_sjw, ARG_bs1, ARG_bs2, ARG_auto_restart, ARG_baudrate, ARG_sample_point, ARG_num_filter_banks, ARG_brs_prescaler, ARG_brs_sjw, ARG_brs_bs1, ARG_brs_bs2, ARG_brs_baudrate, ARG_brs_sample_point }; static const mp_arg_t allowed_args[] = { @@ -285,7 +285,7 @@ STATIC mp_obj_t pyb_can_init_helper(pyb_can_obj_t *self, size_t n_args, const mp } // CAN(bus, ...) -STATIC mp_obj_t pyb_can_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pyb_can_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); @@ -354,21 +354,21 @@ STATIC mp_obj_t pyb_can_make_new(const mp_obj_type_t *type, size_t n_args, size_ return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t pyb_can_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t pyb_can_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { return pyb_can_init_helper(MP_OBJ_TO_PTR(args[0]), n_args - 1, args + 1, kw_args); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_can_init_obj, 1, pyb_can_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_can_init_obj, 1, pyb_can_init); // deinit() -STATIC mp_obj_t pyb_can_deinit(mp_obj_t self_in) { +static mp_obj_t pyb_can_deinit(mp_obj_t self_in) { pyb_can_obj_t *self = MP_OBJ_TO_PTR(self_in); can_deinit(self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_can_deinit_obj, pyb_can_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_can_deinit_obj, pyb_can_deinit); // Force a software restart of the controller, to allow transmission after a bus error -STATIC mp_obj_t pyb_can_restart(mp_obj_t self_in) { +static mp_obj_t pyb_can_restart(mp_obj_t self_in) { pyb_can_obj_t *self = MP_OBJ_TO_PTR(self_in); if (!self->is_enabled) { mp_raise_ValueError(NULL); @@ -394,10 +394,10 @@ STATIC mp_obj_t pyb_can_restart(mp_obj_t self_in) { #endif return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_can_restart_obj, pyb_can_restart); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_can_restart_obj, pyb_can_restart); // Get the state of the controller -STATIC mp_obj_t pyb_can_state(mp_obj_t self_in) { +static mp_obj_t pyb_can_state(mp_obj_t self_in) { pyb_can_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t state = CAN_STATE_STOPPED; if (self->is_enabled) { @@ -427,10 +427,10 @@ STATIC mp_obj_t pyb_can_state(mp_obj_t self_in) { } return MP_OBJ_NEW_SMALL_INT(state); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_can_state_obj, pyb_can_state); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_can_state_obj, pyb_can_state); // Get info about error states and TX/RX buffers -STATIC mp_obj_t pyb_can_info(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_can_info(size_t n_args, const mp_obj_t *args) { pyb_can_obj_t *self = MP_OBJ_TO_PTR(args[0]); mp_obj_list_t *list; if (n_args == 1) { @@ -473,10 +473,10 @@ STATIC mp_obj_t pyb_can_info(size_t n_args, const mp_obj_t *args) { return MP_OBJ_FROM_PTR(list); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_can_info_obj, 1, 2, pyb_can_info); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_can_info_obj, 1, 2, pyb_can_info); // any(fifo) - return `True` if any message waiting on the FIFO, else `False` -STATIC mp_obj_t pyb_can_any(mp_obj_t self_in, mp_obj_t fifo_in) { +static mp_obj_t pyb_can_any(mp_obj_t self_in, mp_obj_t fifo_in) { pyb_can_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t fifo = mp_obj_get_int(fifo_in); if (fifo == 0) { @@ -490,10 +490,10 @@ STATIC mp_obj_t pyb_can_any(mp_obj_t self_in, mp_obj_t fifo_in) { } return mp_const_false; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_can_any_obj, pyb_can_any); +static MP_DEFINE_CONST_FUN_OBJ_2(pyb_can_any_obj, pyb_can_any); // send(send, addr, *, timeout=5000) -STATIC mp_obj_t pyb_can_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_can_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_data, ARG_id, ARG_timeout, ARG_rtr, ARG_extframe, ARG_fdf, ARG_brs }; static const mp_arg_t allowed_args[] = { { MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, @@ -611,10 +611,10 @@ STATIC mp_obj_t pyb_can_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t * return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_can_send_obj, 1, pyb_can_send); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_can_send_obj, 1, pyb_can_send); // recv(fifo, list=None, *, timeout=5000) -STATIC mp_obj_t pyb_can_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_can_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_fifo, ARG_list, ARG_timeout }; static const mp_arg_t allowed_args[] = { { MP_QSTR_fifo, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} }, @@ -730,9 +730,9 @@ STATIC mp_obj_t pyb_can_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t * // Return the result return ret_obj; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_can_recv_obj, 1, pyb_can_recv); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_can_recv_obj, 1, pyb_can_recv); -STATIC mp_obj_t pyb_can_clearfilter(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_can_clearfilter(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_extframe }; static const mp_arg_t allowed_args[] = { { MP_QSTR_extframe, MP_ARG_BOOL, {.u_bool = false} }, @@ -754,11 +754,11 @@ STATIC mp_obj_t pyb_can_clearfilter(size_t n_args, const mp_obj_t *pos_args, mp_ #endif return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_can_clearfilter_obj, 2, pyb_can_clearfilter); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_can_clearfilter_obj, 2, pyb_can_clearfilter); // setfilter(bank, mode, fifo, params, *, rtr) #define EXTENDED_ID_TO_16BIT_FILTER(id) (((id & 0xC00000) >> 13) | ((id & 0x38000) >> 15)) | 8 -STATIC mp_obj_t pyb_can_setfilter(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_can_setfilter(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_bank, ARG_mode, ARG_fifo, ARG_params, ARG_rtr, ARG_extframe }; static const mp_arg_t allowed_args[] = { { MP_QSTR_bank, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} }, @@ -930,9 +930,9 @@ STATIC mp_obj_t pyb_can_setfilter(size_t n_args, const mp_obj_t *pos_args, mp_ma error: mp_raise_ValueError(MP_ERROR_TEXT("CAN filter parameter error")); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_can_setfilter_obj, 1, pyb_can_setfilter); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_can_setfilter_obj, 1, pyb_can_setfilter); -STATIC mp_obj_t pyb_can_rxcallback(mp_obj_t self_in, mp_obj_t fifo_in, mp_obj_t callback_in) { +static mp_obj_t pyb_can_rxcallback(mp_obj_t self_in, mp_obj_t fifo_in, mp_obj_t callback_in) { pyb_can_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t fifo = mp_obj_get_int(fifo_in); mp_obj_t *callback; @@ -971,9 +971,9 @@ STATIC mp_obj_t pyb_can_rxcallback(mp_obj_t self_in, mp_obj_t fifo_in, mp_obj_t } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_can_rxcallback_obj, pyb_can_rxcallback); +static MP_DEFINE_CONST_FUN_OBJ_3(pyb_can_rxcallback_obj, pyb_can_rxcallback); -STATIC const mp_rom_map_elem_t pyb_can_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_can_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_can_init_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_can_deinit_obj) }, @@ -1018,9 +1018,9 @@ STATIC const mp_rom_map_elem_t pyb_can_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_ERROR_PASSIVE), MP_ROM_INT(CAN_STATE_ERROR_PASSIVE) }, { MP_ROM_QSTR(MP_QSTR_BUS_OFF), MP_ROM_INT(CAN_STATE_BUS_OFF) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_can_locals_dict, pyb_can_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_can_locals_dict, pyb_can_locals_dict_table); -STATIC mp_uint_t can_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t can_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { pyb_can_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_uint_t ret; if (request == MP_STREAM_POLL) { @@ -1065,7 +1065,7 @@ void pyb_can_handle_callback(pyb_can_obj_t *self, uint fifo_id, mp_obj_t callbac } } -STATIC const mp_stream_p_t can_stream_p = { +static const mp_stream_p_t can_stream_p = { // .read = can_read, // is read sensible for CAN? // .write = can_write, // is write sensible for CAN? .ioctl = can_ioctl, diff --git a/ports/stm32/pyb_i2c.c b/ports/stm32/pyb_i2c.c index fa38ef372dabe..0529d3bd56e40 100644 --- a/ports/stm32/pyb_i2c.c +++ b/ports/stm32/pyb_i2c.c @@ -103,7 +103,7 @@ I2C_HandleTypeDef I2CHandle3 = {.Instance = NULL}; I2C_HandleTypeDef I2CHandle4 = {.Instance = NULL}; #endif -STATIC bool pyb_i2c_use_dma[4]; +static bool pyb_i2c_use_dma[4]; const pyb_i2c_obj_t pyb_i2c_obj[] = { #if defined(MICROPY_HW_I2C1_SCL) @@ -219,14 +219,14 @@ const pyb_i2c_obj_t pyb_i2c_obj[] = { #error "no I2C timings for this MCU" #endif -STATIC const struct { +static const struct { uint32_t baudrate; uint32_t timing; } pyb_i2c_baudrate_timing[] = MICROPY_HW_I2C_BAUDRATE_TIMING; #define NUM_BAUDRATE_TIMINGS MP_ARRAY_SIZE(pyb_i2c_baudrate_timing) -STATIC void i2c_set_baudrate(I2C_InitTypeDef *init, uint32_t baudrate) { +static void i2c_set_baudrate(I2C_InitTypeDef *init, uint32_t baudrate) { for (int i = 0; i < NUM_BAUDRATE_TIMINGS; i++) { if (pyb_i2c_baudrate_timing[i].baudrate == baudrate) { init->Timing = pyb_i2c_baudrate_timing[i].timing; @@ -252,7 +252,7 @@ uint32_t pyb_i2c_get_baudrate(I2C_HandleTypeDef *i2c) { #define MICROPY_HW_I2C_BAUDRATE_DEFAULT (PYB_I2C_SPEED_FULL) #define MICROPY_HW_I2C_BAUDRATE_MAX (PYB_I2C_SPEED_FULL) -STATIC void i2c_set_baudrate(I2C_InitTypeDef *init, uint32_t baudrate) { +static void i2c_set_baudrate(I2C_InitTypeDef *init, uint32_t baudrate) { init->ClockSpeed = baudrate; init->DutyCycle = I2C_DUTYCYCLE_16_9; } @@ -428,7 +428,7 @@ int pyb_i2c_init_freq(const pyb_i2c_obj_t *self, mp_int_t freq) { return pyb_i2c_init(self->i2c); } -STATIC void i2c_reset_after_error(I2C_HandleTypeDef *i2c) { +static void i2c_reset_after_error(I2C_HandleTypeDef *i2c) { // wait for bus-busy flag to be cleared, with a timeout for (int timeout = 50; timeout > 0; --timeout) { if (!__HAL_I2C_GET_FLAG(i2c, I2C_FLAG_BUSY)) { @@ -581,7 +581,7 @@ void i2c_er_irq_handler(mp_uint_t i2c_id) { #endif } -STATIC HAL_StatusTypeDef i2c_wait_dma_finished(I2C_HandleTypeDef *i2c, uint32_t timeout) { +static HAL_StatusTypeDef i2c_wait_dma_finished(I2C_HandleTypeDef *i2c, uint32_t timeout) { // Note: we can't use WFI to idle in this loop because the DMA completion // interrupt may occur before the WFI. Hence we miss it and have to wait // until the next sys-tick (up to 1ms). @@ -601,7 +601,7 @@ static inline bool in_master_mode(pyb_i2c_obj_t *self) { return self->i2c->Init.OwnAddress1 == PYB_I2C_MASTER_ADDRESS; } -STATIC void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in); uint i2c_num = 0; @@ -655,7 +655,7 @@ STATIC void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki /// - `addr` is the 7-bit address (only sensible for a peripheral) /// - `baudrate` is the SCL clock rate (only sensible for a controller) /// - `gencall` is whether to support general call mode -STATIC mp_obj_t pyb_i2c_init_helper(const pyb_i2c_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_i2c_init_helper(const pyb_i2c_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_mode, MP_ARG_INT, {.u_int = PYB_I2C_MASTER} }, { MP_QSTR_addr, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0x12} }, @@ -721,7 +721,7 @@ STATIC mp_obj_t pyb_i2c_init_helper(const pyb_i2c_obj_t *self, size_t n_args, co /// /// - `I2C(1)` is on the X position: `(SCL, SDA) = (X9, X10) = (PB6, PB7)` /// - `I2C(2)` is on the Y position: `(SCL, SDA) = (Y9, Y10) = (PB10, PB11)` -STATIC mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); @@ -739,23 +739,23 @@ STATIC mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_ return MP_OBJ_FROM_PTR(i2c_obj); } -STATIC mp_obj_t pyb_i2c_init_(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t pyb_i2c_init_(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { return pyb_i2c_init_helper(MP_OBJ_TO_PTR(args[0]), n_args - 1, args + 1, kw_args); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_init_obj, 1, pyb_i2c_init_); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_init_obj, 1, pyb_i2c_init_); /// \method deinit() /// Turn off the I2C bus. -STATIC mp_obj_t pyb_i2c_deinit(mp_obj_t self_in) { +static mp_obj_t pyb_i2c_deinit(mp_obj_t self_in) { pyb_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in); i2c_deinit(self->i2c); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_deinit_obj, pyb_i2c_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_deinit_obj, pyb_i2c_deinit); /// \method is_ready(addr) /// Check if an I2C device responds to the given address. Only valid when in controller mode. -STATIC mp_obj_t pyb_i2c_is_ready(mp_obj_t self_in, mp_obj_t i2c_addr_o) { +static mp_obj_t pyb_i2c_is_ready(mp_obj_t self_in, mp_obj_t i2c_addr_o) { pyb_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in); if (!in_master_mode(self)) { @@ -773,12 +773,12 @@ STATIC mp_obj_t pyb_i2c_is_ready(mp_obj_t self_in, mp_obj_t i2c_addr_o) { return mp_const_false; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_i2c_is_ready_obj, pyb_i2c_is_ready); +static MP_DEFINE_CONST_FUN_OBJ_2(pyb_i2c_is_ready_obj, pyb_i2c_is_ready); /// \method scan() /// Scan all I2C addresses from 0x08 to 0x77 and return a list of those that respond. /// Only valid when in controller mode. -STATIC mp_obj_t pyb_i2c_scan(mp_obj_t self_in) { +static mp_obj_t pyb_i2c_scan(mp_obj_t self_in) { pyb_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in); if (!in_master_mode(self)) { @@ -796,7 +796,7 @@ STATIC mp_obj_t pyb_i2c_scan(mp_obj_t self_in) { return list; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_scan_obj, pyb_i2c_scan); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_scan_obj, pyb_i2c_scan); /// \method send(send, addr=0x00, timeout=5000) /// Send data on the bus: @@ -806,7 +806,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_scan_obj, pyb_i2c_scan); /// - `timeout` is the timeout in milliseconds to wait for the send /// /// Return value: `None`. -STATIC mp_obj_t pyb_i2c_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_i2c_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_send, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_addr, MP_ARG_INT, {.u_int = PYB_I2C_MASTER_ADDRESS} }, @@ -873,7 +873,7 @@ STATIC mp_obj_t pyb_i2c_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t * return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_send_obj, 1, pyb_i2c_send); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_send_obj, 1, pyb_i2c_send); /// \method recv(recv, addr=0x00, timeout=5000) /// @@ -886,7 +886,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_send_obj, 1, pyb_i2c_send); /// /// Return value: if `recv` is an integer then a new buffer of the bytes received, /// otherwise the same buffer that was passed in to `recv`. -STATIC mp_obj_t pyb_i2c_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_i2c_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_recv, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_addr, MP_ARG_INT, {.u_int = PYB_I2C_MASTER_ADDRESS} }, @@ -954,7 +954,7 @@ STATIC mp_obj_t pyb_i2c_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t * return mp_obj_new_bytes_from_vstr(&vstr); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_recv_obj, 1, pyb_i2c_recv); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_recv_obj, 1, pyb_i2c_recv); /// \method mem_read(data, addr, memaddr, timeout=5000, addr_size=8) /// @@ -968,7 +968,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_recv_obj, 1, pyb_i2c_recv); /// /// Returns the read data. /// This is only valid in controller mode. -STATIC const mp_arg_t pyb_i2c_mem_read_allowed_args[] = { +static const mp_arg_t pyb_i2c_mem_read_allowed_args[] = { { MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_addr, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_memaddr, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} }, @@ -976,7 +976,7 @@ STATIC const mp_arg_t pyb_i2c_mem_read_allowed_args[] = { { MP_QSTR_addr_size, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 8} }, }; -STATIC mp_obj_t pyb_i2c_mem_read(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_i2c_mem_read(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // parse args pyb_i2c_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); mp_arg_val_t args[MP_ARRAY_SIZE(pyb_i2c_mem_read_allowed_args)]; @@ -1030,7 +1030,7 @@ STATIC mp_obj_t pyb_i2c_mem_read(size_t n_args, const mp_obj_t *pos_args, mp_map return mp_obj_new_bytes_from_vstr(&vstr); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_mem_read_obj, 1, pyb_i2c_mem_read); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_mem_read_obj, 1, pyb_i2c_mem_read); /// \method mem_write(data, addr, memaddr, timeout=5000, addr_size=8) /// @@ -1044,7 +1044,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_mem_read_obj, 1, pyb_i2c_mem_read); /// /// Returns `None`. /// This is only valid in controller mode. -STATIC mp_obj_t pyb_i2c_mem_write(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_i2c_mem_write(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // parse args (same as mem_read) pyb_i2c_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); mp_arg_val_t args[MP_ARRAY_SIZE(pyb_i2c_mem_read_allowed_args)]; @@ -1094,9 +1094,9 @@ STATIC mp_obj_t pyb_i2c_mem_write(size_t n_args, const mp_obj_t *pos_args, mp_ma return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_mem_write_obj, 1, pyb_i2c_mem_write); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_mem_write_obj, 1, pyb_i2c_mem_write); -STATIC const mp_rom_map_elem_t pyb_i2c_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_i2c_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_i2c_init_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_i2c_deinit_obj) }, @@ -1117,7 +1117,7 @@ STATIC const mp_rom_map_elem_t pyb_i2c_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_SLAVE), MP_ROM_INT(PYB_I2C_SLAVE) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_i2c_locals_dict, pyb_i2c_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_i2c_locals_dict, pyb_i2c_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pyb_i2c_type, diff --git a/ports/stm32/pyb_spi.c b/ports/stm32/pyb_spi.c index f92642dddcd88..2fcccaf161bde 100644 --- a/ports/stm32/pyb_spi.c +++ b/ports/stm32/pyb_spi.c @@ -57,7 +57,7 @@ // spi.send_recv(b'1234', buf) # send 4 bytes and receive 4 into buf // spi.send_recv(buf, buf) # send/recv 4 bytes from/to buf -STATIC const pyb_spi_obj_t pyb_spi_obj[] = { +static const pyb_spi_obj_t pyb_spi_obj[] = { {{&pyb_spi_type}, &spi_obj[0]}, {{&pyb_spi_type}, &spi_obj[1]}, {{&pyb_spi_type}, &spi_obj[2]}, @@ -66,7 +66,7 @@ STATIC const pyb_spi_obj_t pyb_spi_obj[] = { {{&pyb_spi_type}, &spi_obj[5]}, }; -STATIC void pyb_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void pyb_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); spi_print(print, self->spi, true); } @@ -76,7 +76,7 @@ STATIC void pyb_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki // Initialise the SPI bus with the given parameters: // - `mode` must be either `SPI.CONTROLLER` or `SPI.PERIPHERAL`. // - `baudrate` is the SCK clock rate (only sensible for a controller). -STATIC mp_obj_t pyb_spi_init_helper(const pyb_spi_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_spi_init_helper(const pyb_spi_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_baudrate, MP_ARG_INT, {.u_int = 328125} }, @@ -136,7 +136,7 @@ STATIC mp_obj_t pyb_spi_init_helper(const pyb_spi_obj_t *self, size_t n_args, co // // At the moment, the NSS pin is not used by the SPI driver and is free // for other use. -STATIC mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); @@ -156,19 +156,19 @@ STATIC mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_ return MP_OBJ_FROM_PTR(spi_obj); } -STATIC mp_obj_t pyb_spi_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t pyb_spi_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { return pyb_spi_init_helper(MP_OBJ_TO_PTR(args[0]), n_args - 1, args + 1, kw_args); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_init_obj, 1, pyb_spi_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_init_obj, 1, pyb_spi_init); // deinit() // Turn off the SPI bus. -STATIC mp_obj_t pyb_spi_deinit(mp_obj_t self_in) { +static mp_obj_t pyb_spi_deinit(mp_obj_t self_in) { pyb_spi_obj_t *self = MP_OBJ_TO_PTR(self_in); spi_deinit(self->spi); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_spi_deinit_obj, pyb_spi_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_spi_deinit_obj, pyb_spi_deinit); // send(send, *, timeout=5000) // Send data on the bus: @@ -176,7 +176,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_spi_deinit_obj, pyb_spi_deinit); // - `timeout` is the timeout in milliseconds to wait for the send. // // Return value: `None`. -STATIC mp_obj_t pyb_spi_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_spi_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // TODO assumes transmission size is 8-bits wide static const mp_arg_t allowed_args[] = { @@ -199,7 +199,7 @@ STATIC mp_obj_t pyb_spi_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t * return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_send_obj, 1, pyb_spi_send); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_send_obj, 1, pyb_spi_send); // recv(recv, *, timeout=5000) // @@ -210,7 +210,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_send_obj, 1, pyb_spi_send); // // Return value: if `recv` is an integer then a new buffer of the bytes received, // otherwise the same buffer that was passed in to `recv`. -STATIC mp_obj_t pyb_spi_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_spi_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // TODO assumes transmission size is 8-bits wide static const mp_arg_t allowed_args[] = { @@ -237,7 +237,7 @@ STATIC mp_obj_t pyb_spi_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t * return mp_obj_new_bytes_from_vstr(&vstr); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_recv_obj, 1, pyb_spi_recv); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_recv_obj, 1, pyb_spi_recv); // send_recv(send, recv=None, *, timeout=5000) // @@ -249,7 +249,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_recv_obj, 1, pyb_spi_recv); // - `timeout` is the timeout in milliseconds to wait for the receive. // // Return value: the buffer with the received bytes. -STATIC mp_obj_t pyb_spi_send_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_spi_send_recv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // TODO assumes transmission size is 8-bits wide static const mp_arg_t allowed_args[] = { @@ -306,9 +306,9 @@ STATIC mp_obj_t pyb_spi_send_recv(size_t n_args, const mp_obj_t *pos_args, mp_ma return mp_obj_new_bytes_from_vstr(&vstr_recv); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_send_recv_obj, 1, pyb_spi_send_recv); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_send_recv_obj, 1, pyb_spi_send_recv); -STATIC const mp_rom_map_elem_t pyb_spi_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_spi_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_spi_init_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_spi_deinit_obj) }, @@ -344,14 +344,14 @@ STATIC const mp_rom_map_elem_t pyb_spi_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_NSS_HARD_OUTPUT ((uint32_t)0x00040000) */ }; -STATIC MP_DEFINE_CONST_DICT(pyb_spi_locals_dict, pyb_spi_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_spi_locals_dict, pyb_spi_locals_dict_table); -STATIC void spi_transfer_machine(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) { +static void spi_transfer_machine(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) { pyb_spi_obj_t *self = (pyb_spi_obj_t *)self_in; spi_transfer(self->spi, len, src, dest, SPI_TRANSFER_TIMEOUT(len)); } -STATIC const mp_machine_spi_p_t pyb_spi_p = { +static const mp_machine_spi_p_t pyb_spi_p = { .transfer = spi_transfer_machine, }; diff --git a/ports/stm32/pybthread.c b/ports/stm32/pybthread.c index 57c8d1fddefaf..e2f2de7ff05b5 100644 --- a/ports/stm32/pybthread.c +++ b/ports/stm32/pybthread.c @@ -84,7 +84,7 @@ void pyb_thread_deinit() { enable_irq(irq_state); } -STATIC void pyb_thread_terminate(void) { +static void pyb_thread_terminate(void) { uint32_t irq_state = disable_irq(); pyb_thread_t *thread = pyb_thread_cur; // take current thread off the run list diff --git a/ports/stm32/qspi.c b/ports/stm32/qspi.c index c10bec2365504..a560f8fb6265d 100644 --- a/ports/stm32/qspi.c +++ b/ports/stm32/qspi.c @@ -172,7 +172,7 @@ void qspi_memory_map(void) { qspi_mpu_enable_mapped(); } -STATIC int qspi_ioctl(void *self_in, uint32_t cmd) { +static int qspi_ioctl(void *self_in, uint32_t cmd) { (void)self_in; switch (cmd) { case MP_QSPI_IOCTL_INIT: @@ -196,7 +196,7 @@ STATIC int qspi_ioctl(void *self_in, uint32_t cmd) { return 0; // success } -STATIC int qspi_write_cmd_data(void *self_in, uint8_t cmd, size_t len, uint32_t data) { +static int qspi_write_cmd_data(void *self_in, uint8_t cmd, size_t len, uint32_t data) { (void)self_in; QUADSPI->FCR = QUADSPI_FCR_CTCF; // clear TC flag @@ -252,7 +252,7 @@ STATIC int qspi_write_cmd_data(void *self_in, uint8_t cmd, size_t len, uint32_t return 0; } -STATIC int qspi_write_cmd_addr_data(void *self_in, uint8_t cmd, uint32_t addr, size_t len, const uint8_t *src) { +static int qspi_write_cmd_addr_data(void *self_in, uint8_t cmd, uint32_t addr, size_t len, const uint8_t *src) { (void)self_in; uint8_t adsize = MICROPY_HW_SPI_ADDR_IS_32BIT(addr) ? 3 : 2; @@ -316,7 +316,7 @@ STATIC int qspi_write_cmd_addr_data(void *self_in, uint8_t cmd, uint32_t addr, s return 0; } -STATIC int qspi_read_cmd(void *self_in, uint8_t cmd, size_t len, uint32_t *dest) { +static int qspi_read_cmd(void *self_in, uint8_t cmd, size_t len, uint32_t *dest) { (void)self_in; QUADSPI->FCR = QUADSPI_FCR_CTCF; // clear TC flag @@ -350,7 +350,7 @@ STATIC int qspi_read_cmd(void *self_in, uint8_t cmd, size_t len, uint32_t *dest) return 0; } -STATIC int qspi_read_cmd_qaddr_qdata(void *self_in, uint8_t cmd, uint32_t addr, size_t len, uint8_t *dest) { +static int qspi_read_cmd_qaddr_qdata(void *self_in, uint8_t cmd, uint32_t addr, size_t len, uint8_t *dest) { (void)self_in; uint8_t adsize = MICROPY_HW_SPI_ADDR_IS_32BIT(addr) ? 3 : 2; diff --git a/ports/stm32/rfcore.c b/ports/stm32/rfcore.c index 2e660d6d9e17e..05582e887eeb5 100644 --- a/ports/stm32/rfcore.c +++ b/ports/stm32/rfcore.c @@ -195,33 +195,33 @@ typedef struct __attribute__((packed)) _ipcc_ref_table_t { // The stm32wb55xg.ld script puts .bss.ipcc_mem_* into SRAM2A and .bss_ipcc_membuf_* into SRAM2B. // It also leaves 64 bytes at the start of SRAM2A for the ref table. -STATIC ipcc_device_info_table_t ipcc_mem_dev_info_tab; // mem1 -STATIC ipcc_ble_table_t ipcc_mem_ble_tab; // mem1 -STATIC ipcc_sys_table_t ipcc_mem_sys_tab; // mem1 -STATIC ipcc_mem_manager_table_t ipcc_mem_memmgr_tab; // mem1 +static ipcc_device_info_table_t ipcc_mem_dev_info_tab; // mem1 +static ipcc_ble_table_t ipcc_mem_ble_tab; // mem1 +static ipcc_sys_table_t ipcc_mem_sys_tab; // mem1 +static ipcc_mem_manager_table_t ipcc_mem_memmgr_tab; // mem1 -STATIC uint8_t ipcc_membuf_sys_cmd_buf[272]; // mem2 -STATIC tl_list_node_t ipcc_mem_sys_queue; // mem1 +static uint8_t ipcc_membuf_sys_cmd_buf[272]; // mem2 +static tl_list_node_t ipcc_mem_sys_queue; // mem1 -STATIC tl_list_node_t ipcc_mem_memmgr_free_buf_queue; // mem1 -STATIC uint8_t ipcc_membuf_memmgr_ble_spare_evt_buf[272]; // mem2 -STATIC uint8_t ipcc_membuf_memmgr_sys_spare_evt_buf[272]; // mem2 -STATIC uint8_t ipcc_membuf_memmgr_evt_pool[6 * 272]; // mem2 +static tl_list_node_t ipcc_mem_memmgr_free_buf_queue; // mem1 +static uint8_t ipcc_membuf_memmgr_ble_spare_evt_buf[272]; // mem2 +static uint8_t ipcc_membuf_memmgr_sys_spare_evt_buf[272]; // mem2 +static uint8_t ipcc_membuf_memmgr_evt_pool[6 * 272]; // mem2 -STATIC uint8_t ipcc_membuf_ble_cmd_buf[272]; // mem2 -STATIC uint8_t ipcc_membuf_ble_cs_buf[272]; // mem2 -STATIC tl_list_node_t ipcc_mem_ble_evt_queue; // mem1 -STATIC uint8_t ipcc_membuf_ble_hci_acl_data_buf[272]; // mem2 +static uint8_t ipcc_membuf_ble_cmd_buf[272]; // mem2 +static uint8_t ipcc_membuf_ble_cs_buf[272]; // mem2 +static tl_list_node_t ipcc_mem_ble_evt_queue; // mem1 +static uint8_t ipcc_membuf_ble_hci_acl_data_buf[272]; // mem2 /******************************************************************************/ // Transport layer linked list -STATIC void tl_list_init(volatile tl_list_node_t *n) { +static void tl_list_init(volatile tl_list_node_t *n) { n->next = n; n->prev = n; } -STATIC volatile tl_list_node_t *tl_list_unlink(volatile tl_list_node_t *n) { +static volatile tl_list_node_t *tl_list_unlink(volatile tl_list_node_t *n) { volatile tl_list_node_t *next = n->next; volatile tl_list_node_t *prev = n->prev; prev->next = next; @@ -229,7 +229,7 @@ STATIC volatile tl_list_node_t *tl_list_unlink(volatile tl_list_node_t *n) { return next; } -STATIC void tl_list_append(volatile tl_list_node_t *head, volatile tl_list_node_t *n) { +static void tl_list_append(volatile tl_list_node_t *head, volatile tl_list_node_t *n) { n->next = head; n->prev = head->prev; head->prev->next = n; @@ -239,7 +239,7 @@ STATIC void tl_list_append(volatile tl_list_node_t *head, volatile tl_list_node_ /******************************************************************************/ // IPCC interface -STATIC volatile ipcc_ref_table_t *get_buffer_table(void) { +static volatile ipcc_ref_table_t *get_buffer_table(void) { // The IPCCDBA option bytes must not be changed without // making a corresponding change to the linker script. return (volatile ipcc_ref_table_t *)(SRAM2A_BASE + LL_FLASH_GetIPCCBufferAddr() * 4); @@ -299,9 +299,9 @@ void ipcc_init(uint32_t irq_pri) { // In either case we detect the failure response and inject this response // instead (which is HCI_EVENT_COMMAND_COMPLETE for OCF_CB_SET_EVENT_MASK2 // with status=0). -STATIC const uint8_t set_event_event_mask2_fix_payload[] = { 0x04, 0x0e, 0x04, 0x01, 0x63, 0x0c, 0x00 }; +static const uint8_t set_event_event_mask2_fix_payload[] = { 0x04, 0x0e, 0x04, 0x01, 0x63, 0x0c, 0x00 }; -STATIC size_t tl_parse_hci_msg(const uint8_t *buf, parse_hci_info_t *parse) { +static size_t tl_parse_hci_msg(const uint8_t *buf, parse_hci_info_t *parse) { const char *info; #if HCI_TRACE int applied_set_event_event_mask2_fix = 0; @@ -408,7 +408,7 @@ STATIC size_t tl_parse_hci_msg(const uint8_t *buf, parse_hci_info_t *parse) { return len; } -STATIC size_t tl_process_msg(volatile tl_list_node_t *head, unsigned int ch, parse_hci_info_t *parse) { +static size_t tl_process_msg(volatile tl_list_node_t *head, unsigned int ch, parse_hci_info_t *parse) { volatile tl_list_node_t *cur = head->next; bool added_to_free_queue = false; size_t len = 0; @@ -441,7 +441,7 @@ STATIC size_t tl_process_msg(volatile tl_list_node_t *head, unsigned int ch, par } // Only call this when IRQs are disabled on this channel. -STATIC size_t tl_check_msg(volatile tl_list_node_t *head, unsigned int ch, parse_hci_info_t *parse) { +static size_t tl_check_msg(volatile tl_list_node_t *head, unsigned int ch, parse_hci_info_t *parse) { size_t len = 0; if (LL_C2_IPCC_IsActiveFlag_CHx(IPCC, ch)) { // Process new data. @@ -458,7 +458,7 @@ STATIC size_t tl_check_msg(volatile tl_list_node_t *head, unsigned int ch, parse return len; } -STATIC void tl_hci_cmd(uint8_t *cmd, unsigned int ch, uint8_t hdr, uint16_t opcode, const uint8_t *buf, size_t len) { +static void tl_hci_cmd(uint8_t *cmd, unsigned int ch, uint8_t hdr, uint16_t opcode, const uint8_t *buf, size_t len) { tl_list_node_t *n = (tl_list_node_t *)cmd; n->next = NULL; n->prev = NULL; @@ -480,7 +480,7 @@ STATIC void tl_hci_cmd(uint8_t *cmd, unsigned int ch, uint8_t hdr, uint16_t opco LL_C1_IPCC_SetFlag_CHx(IPCC, ch); } -STATIC ssize_t tl_sys_wait_ack(const uint8_t *buf, mp_int_t timeout_ms) { +static ssize_t tl_sys_wait_ack(const uint8_t *buf, mp_int_t timeout_ms) { uint32_t t0 = mp_hal_ticks_ms(); timeout_ms = MAX(SYS_ACK_TIMEOUT_MS, timeout_ms); @@ -498,12 +498,12 @@ STATIC ssize_t tl_sys_wait_ack(const uint8_t *buf, mp_int_t timeout_ms) { return (ssize_t)tl_parse_hci_msg(buf, NULL); } -STATIC ssize_t tl_sys_hci_cmd_resp(uint16_t opcode, const uint8_t *buf, size_t len, mp_int_t timeout_ms) { +static ssize_t tl_sys_hci_cmd_resp(uint16_t opcode, const uint8_t *buf, size_t len, mp_int_t timeout_ms) { tl_hci_cmd(ipcc_membuf_sys_cmd_buf, IPCC_CH_SYS, 0x10, opcode, buf, len); return tl_sys_wait_ack(ipcc_membuf_sys_cmd_buf, timeout_ms); } -STATIC int tl_ble_wait_resp(void) { +static int tl_ble_wait_resp(void) { uint32_t t0 = mp_hal_ticks_ms(); while (!LL_C2_IPCC_IsActiveFlag_CHx(IPCC, IPCC_CH_BLE)) { if (mp_hal_ticks_ms() - t0 > BLE_ACK_TIMEOUT_MS) { @@ -518,7 +518,7 @@ STATIC int tl_ble_wait_resp(void) { } // Synchronously send a BLE command. -STATIC void tl_ble_hci_cmd_resp(uint16_t opcode, const uint8_t *buf, size_t len) { +static void tl_ble_hci_cmd_resp(uint16_t opcode, const uint8_t *buf, size_t len) { // Poll for completion rather than wait for IRQ->scheduler. LL_C1_IPCC_DisableReceiveChannel(IPCC, IPCC_CH_BLE); tl_hci_cmd(ipcc_membuf_ble_cmd_buf, IPCC_CH_BLE, HCI_KIND_BT_CMD, opcode, buf, len); @@ -743,19 +743,19 @@ void IPCC_C1_RX_IRQHandler(void) { /******************************************************************************/ // MicroPython bindings -STATIC mp_obj_t rfcore_status(void) { +static mp_obj_t rfcore_status(void) { return mp_obj_new_int_from_uint(ipcc_mem_dev_info_tab.fus.table_state); } MP_DEFINE_CONST_FUN_OBJ_0(rfcore_status_obj, rfcore_status); -STATIC mp_obj_t get_version_tuple(uint32_t data) { +static mp_obj_t get_version_tuple(uint32_t data) { mp_obj_t items[] = { MP_OBJ_NEW_SMALL_INT(data >> 24), MP_OBJ_NEW_SMALL_INT(data >> 16 & 0xFF), MP_OBJ_NEW_SMALL_INT(data >> 8 & 0xFF), MP_OBJ_NEW_SMALL_INT(data >> 4 & 0xF), MP_OBJ_NEW_SMALL_INT(data & 0xF) }; return mp_obj_new_tuple(5, items); } -STATIC mp_obj_t rfcore_fw_version(mp_obj_t fw_id_in) { +static mp_obj_t rfcore_fw_version(mp_obj_t fw_id_in) { if (ipcc_mem_dev_info_tab.fus.table_state == MAGIC_IPCC_MEM_INCORRECT) { mp_raise_OSError(MP_EINVAL); } @@ -773,7 +773,7 @@ STATIC mp_obj_t rfcore_fw_version(mp_obj_t fw_id_in) { } MP_DEFINE_CONST_FUN_OBJ_1(rfcore_fw_version_obj, rfcore_fw_version); -STATIC mp_obj_t rfcore_sys_hci(size_t n_args, const mp_obj_t *args) { +static mp_obj_t rfcore_sys_hci(size_t n_args, const mp_obj_t *args) { if (ipcc_mem_dev_info_tab.fus.table_state == MAGIC_IPCC_MEM_INCORRECT) { mp_raise_OSError(MP_EINVAL); } diff --git a/ports/stm32/rng.c b/ports/stm32/rng.c index 236d79ea87952..400e1bd16da88 100644 --- a/ports/stm32/rng.c +++ b/ports/stm32/rng.c @@ -57,7 +57,7 @@ uint32_t rng_get(void) { } // Return a 30-bit hardware generated random number. -STATIC mp_obj_t pyb_rng_get(void) { +static mp_obj_t pyb_rng_get(void) { return mp_obj_new_int(rng_get() >> 2); } MP_DEFINE_CONST_FUN_OBJ_0(pyb_rng_get_obj, pyb_rng_get); @@ -72,7 +72,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(pyb_rng_get_obj, pyb_rng_get); // Yasmarang random number generator by Ilya Levin // http://www.literatecode.com/yasmarang -STATIC uint32_t pyb_rng_yasmarang(void) { +static uint32_t pyb_rng_yasmarang(void) { static bool seeded = false; static uint32_t pad = 0, n = 0, d = 0; static uint8_t dat = 0; diff --git a/ports/stm32/rtc.c b/ports/stm32/rtc.c index b209ea83540d8..8dadc4a88d760 100644 --- a/ports/stm32/rtc.c +++ b/ports/stm32/rtc.c @@ -67,18 +67,18 @@ static mp_uint_t rtc_info; #define RTC_SYNCH_PREDIV (0x00ff) #endif -STATIC HAL_StatusTypeDef PYB_RTC_Init(RTC_HandleTypeDef *hrtc); -STATIC void PYB_RTC_MspInit_Kick(RTC_HandleTypeDef *hrtc, bool rtc_use_lse, bool rtc_use_byp); -STATIC HAL_StatusTypeDef PYB_RTC_MspInit_Finalise(RTC_HandleTypeDef *hrtc); -STATIC void RTC_CalendarConfig(void); +static HAL_StatusTypeDef PYB_RTC_Init(RTC_HandleTypeDef *hrtc); +static void PYB_RTC_MspInit_Kick(RTC_HandleTypeDef *hrtc, bool rtc_use_lse, bool rtc_use_byp); +static HAL_StatusTypeDef PYB_RTC_MspInit_Finalise(RTC_HandleTypeDef *hrtc); +static void RTC_CalendarConfig(void); #if MICROPY_HW_RTC_USE_LSE || MICROPY_HW_RTC_USE_BYPASS -STATIC bool rtc_use_lse = true; +static bool rtc_use_lse = true; #else -STATIC bool rtc_use_lse = false; +static bool rtc_use_lse = false; #endif -STATIC uint32_t rtc_startup_tick; -STATIC bool rtc_need_init_finalise = false; +static uint32_t rtc_startup_tick; +static bool rtc_need_init_finalise = false; #if defined(STM32L0) #define BDCR CSR @@ -262,7 +262,7 @@ void rtc_init_finalise() { rtc_need_init_finalise = false; } -STATIC HAL_StatusTypeDef PYB_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct) { +static HAL_StatusTypeDef PYB_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct) { /*------------------------------ LSI Configuration -------------------------*/ if ((RCC_OscInitStruct->OscillatorType & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI) { // Check the LSI State @@ -331,7 +331,7 @@ STATIC HAL_StatusTypeDef PYB_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct return HAL_OK; } -STATIC HAL_StatusTypeDef PYB_RTC_Init(RTC_HandleTypeDef *hrtc) { +static HAL_StatusTypeDef PYB_RTC_Init(RTC_HandleTypeDef *hrtc) { // Check the RTC peripheral state if (hrtc == NULL) { return HAL_ERROR; @@ -399,7 +399,7 @@ STATIC HAL_StatusTypeDef PYB_RTC_Init(RTC_HandleTypeDef *hrtc) { } } -STATIC void PYB_RTC_MspInit_Kick(RTC_HandleTypeDef *hrtc, bool rtc_use_lse, bool rtc_use_byp) { +static void PYB_RTC_MspInit_Kick(RTC_HandleTypeDef *hrtc, bool rtc_use_lse, bool rtc_use_byp) { /* To change the source clock of the RTC feature (LSE, LSI), You have to: - Enable the power clock using __PWR_CLK_ENABLE() - Enable write access using HAL_PWR_EnableBkUpAccess() function before to @@ -443,7 +443,7 @@ STATIC void PYB_RTC_MspInit_Kick(RTC_HandleTypeDef *hrtc, bool rtc_use_lse, bool #define MICROPY_HW_RTC_BYP_TIMEOUT_MS 150 #endif -STATIC HAL_StatusTypeDef PYB_RTC_MspInit_Finalise(RTC_HandleTypeDef *hrtc) { +static HAL_StatusTypeDef PYB_RTC_MspInit_Finalise(RTC_HandleTypeDef *hrtc) { // we already had a kick so now wait for the corresponding ready state... if (rtc_use_lse) { // we now have to wait for LSE ready or timeout @@ -486,7 +486,7 @@ STATIC HAL_StatusTypeDef PYB_RTC_MspInit_Finalise(RTC_HandleTypeDef *hrtc) { return HAL_OK; } -STATIC void RTC_CalendarConfig(void) { +static void RTC_CalendarConfig(void) { // set the date to 1st Jan 2015 RTC_DateTypeDef date; date.Year = 15; @@ -538,11 +538,11 @@ typedef struct _pyb_rtc_obj_t { mp_obj_base_t base; } pyb_rtc_obj_t; -STATIC const pyb_rtc_obj_t pyb_rtc_obj = {{&pyb_rtc_type}}; +static const pyb_rtc_obj_t pyb_rtc_obj = {{&pyb_rtc_type}}; /// \classmethod \constructor() /// Create an RTC object. -STATIC mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 0, 0, false); @@ -862,14 +862,14 @@ mp_obj_t pyb_rtc_calibration(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_calibration_obj, 1, 2, pyb_rtc_calibration); -STATIC const mp_rom_map_elem_t pyb_rtc_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_rtc_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_rtc_init_obj) }, { MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&pyb_rtc_info_obj) }, { MP_ROM_QSTR(MP_QSTR_datetime), MP_ROM_PTR(&pyb_rtc_datetime_obj) }, { MP_ROM_QSTR(MP_QSTR_wakeup), MP_ROM_PTR(&pyb_rtc_wakeup_obj) }, { MP_ROM_QSTR(MP_QSTR_calibration), MP_ROM_PTR(&pyb_rtc_calibration_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_rtc_locals_dict, pyb_rtc_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_rtc_locals_dict, pyb_rtc_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pyb_rtc_type, diff --git a/ports/stm32/sdcard.c b/ports/stm32/sdcard.c index a903f79ed2161..a7d0629399651 100644 --- a/ports/stm32/sdcard.c +++ b/ports/stm32/sdcard.c @@ -208,7 +208,7 @@ void sdcard_select_mmc(void) { pyb_sdmmc_flags |= PYB_SDMMC_FLAG_MMC; } -STATIC void sdmmc_msp_init(void) { +static void sdmmc_msp_init(void) { // enable SDIO clock SDMMC_CLK_ENABLE(); @@ -264,7 +264,7 @@ bool sdcard_is_present(void) { } #if MICROPY_HW_ENABLE_SDCARD -STATIC HAL_StatusTypeDef sdmmc_init_sd(void) { +static HAL_StatusTypeDef sdmmc_init_sd(void) { // SD device interface configuration sdmmc_handle.sd.Instance = SDIO; sdmmc_handle.sd.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING; @@ -299,7 +299,7 @@ STATIC HAL_StatusTypeDef sdmmc_init_sd(void) { #endif #if MICROPY_HW_ENABLE_MMCARD -STATIC HAL_StatusTypeDef sdmmc_init_mmc(void) { +static HAL_StatusTypeDef sdmmc_init_mmc(void) { // MMC device interface configuration sdmmc_handle.mmc.Instance = SDIO; sdmmc_handle.mmc.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING; @@ -410,7 +410,7 @@ uint64_t sdcard_get_capacity_in_bytes(void) { } } -STATIC void sdmmc_irq_handler(void) { +static void sdmmc_irq_handler(void) { switch (pyb_sdmmc_flags) { #if MICROPY_HW_ENABLE_SDCARD case PYB_SDMMC_FLAG_ACTIVE | PYB_SDMMC_FLAG_SD: @@ -431,7 +431,7 @@ void SDMMC_IRQHandler(void) { IRQ_EXIT(SDMMC_IRQn); } -STATIC void sdcard_reset_periph(void) { +static void sdcard_reset_periph(void) { // Fully reset the SDMMC peripheral before calling HAL SD DMA functions. // (There could be an outstanding DTIMEOUT event from a previous call and the // HAL function enables IRQs before fully configuring the SDMMC peripheral.) @@ -441,7 +441,7 @@ STATIC void sdcard_reset_periph(void) { SDIO->ICR = SDMMC_STATIC_FLAGS; } -STATIC HAL_StatusTypeDef sdcard_wait_finished(uint32_t timeout) { +static HAL_StatusTypeDef sdcard_wait_finished(uint32_t timeout) { // Wait for HAL driver to be ready (eg for DMA to finish) uint32_t start = HAL_GetTick(); for (;;) { @@ -699,7 +699,7 @@ const mp_obj_base_t pyb_mmcard_obj = {&pyb_mmcard_type}; #endif #if MICROPY_HW_ENABLE_SDCARD -STATIC mp_obj_t pyb_sdcard_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pyb_sdcard_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 0, 0, false); @@ -717,7 +717,7 @@ STATIC mp_obj_t pyb_sdcard_make_new(const mp_obj_type_t *type, size_t n_args, si #endif #if MICROPY_HW_ENABLE_MMCARD -STATIC mp_obj_t pyb_mmcard_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pyb_mmcard_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 0, 0, false); @@ -734,12 +734,12 @@ STATIC mp_obj_t pyb_mmcard_make_new(const mp_obj_type_t *type, size_t n_args, si } #endif -STATIC mp_obj_t sd_present(mp_obj_t self) { +static mp_obj_t sd_present(mp_obj_t self) { return mp_obj_new_bool(sdcard_is_present()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(sd_present_obj, sd_present); +static MP_DEFINE_CONST_FUN_OBJ_1(sd_present_obj, sd_present); -STATIC mp_obj_t sd_power(mp_obj_t self, mp_obj_t state) { +static mp_obj_t sd_power(mp_obj_t self, mp_obj_t state) { bool result; if (mp_obj_is_true(state)) { result = sdcard_power_on(); @@ -749,9 +749,9 @@ STATIC mp_obj_t sd_power(mp_obj_t self, mp_obj_t state) { } return mp_obj_new_bool(result); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(sd_power_obj, sd_power); +static MP_DEFINE_CONST_FUN_OBJ_2(sd_power_obj, sd_power); -STATIC mp_obj_t sd_info(mp_obj_t self) { +static mp_obj_t sd_info(mp_obj_t self) { if (!(pyb_sdmmc_flags & PYB_SDMMC_FLAG_ACTIVE)) { return mp_const_none; } @@ -778,10 +778,10 @@ STATIC mp_obj_t sd_info(mp_obj_t self) { }; return mp_obj_new_tuple(3, tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(sd_info_obj, sd_info); +static MP_DEFINE_CONST_FUN_OBJ_1(sd_info_obj, sd_info); // now obsolete, kept for backwards compatibility -STATIC mp_obj_t sd_read(mp_obj_t self, mp_obj_t block_num) { +static mp_obj_t sd_read(mp_obj_t self, mp_obj_t block_num) { uint8_t *dest = m_new(uint8_t, SDCARD_BLOCK_SIZE); mp_uint_t ret = sdcard_read_blocks(dest, mp_obj_get_int(block_num), 1); @@ -792,10 +792,10 @@ STATIC mp_obj_t sd_read(mp_obj_t self, mp_obj_t block_num) { return mp_obj_new_bytearray_by_ref(SDCARD_BLOCK_SIZE, dest); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(sd_read_obj, sd_read); +static MP_DEFINE_CONST_FUN_OBJ_2(sd_read_obj, sd_read); // now obsolete, kept for backwards compatibility -STATIC mp_obj_t sd_write(mp_obj_t self, mp_obj_t block_num, mp_obj_t data) { +static mp_obj_t sd_write(mp_obj_t self, mp_obj_t block_num, mp_obj_t data) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ); if (bufinfo.len % SDCARD_BLOCK_SIZE != 0) { @@ -810,25 +810,25 @@ STATIC mp_obj_t sd_write(mp_obj_t self, mp_obj_t block_num, mp_obj_t data) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(sd_write_obj, sd_write); +static MP_DEFINE_CONST_FUN_OBJ_3(sd_write_obj, sd_write); -STATIC mp_obj_t pyb_sdcard_readblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) { +static mp_obj_t pyb_sdcard_readblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_WRITE); mp_uint_t ret = sdcard_read_blocks(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SDCARD_BLOCK_SIZE); return mp_obj_new_bool(ret == 0); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_sdcard_readblocks_obj, pyb_sdcard_readblocks); +static MP_DEFINE_CONST_FUN_OBJ_3(pyb_sdcard_readblocks_obj, pyb_sdcard_readblocks); -STATIC mp_obj_t pyb_sdcard_writeblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) { +static mp_obj_t pyb_sdcard_writeblocks(mp_obj_t self, mp_obj_t block_num, mp_obj_t buf) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ); mp_uint_t ret = sdcard_write_blocks(bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / SDCARD_BLOCK_SIZE); return mp_obj_new_bool(ret == 0); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_sdcard_writeblocks_obj, pyb_sdcard_writeblocks); +static MP_DEFINE_CONST_FUN_OBJ_3(pyb_sdcard_writeblocks_obj, pyb_sdcard_writeblocks); -STATIC mp_obj_t pyb_sdcard_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) { +static mp_obj_t pyb_sdcard_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) { mp_int_t cmd = mp_obj_get_int(cmd_in); switch (cmd) { case MP_BLOCKDEV_IOCTL_INIT: @@ -855,9 +855,9 @@ STATIC mp_obj_t pyb_sdcard_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in return MP_OBJ_NEW_SMALL_INT(-1); // error } } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_sdcard_ioctl_obj, pyb_sdcard_ioctl); +static MP_DEFINE_CONST_FUN_OBJ_3(pyb_sdcard_ioctl_obj, pyb_sdcard_ioctl); -STATIC const mp_rom_map_elem_t pyb_sdcard_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_sdcard_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_present), MP_ROM_PTR(&sd_present_obj) }, { MP_ROM_QSTR(MP_QSTR_power), MP_ROM_PTR(&sd_power_obj) }, { MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&sd_info_obj) }, @@ -869,7 +869,7 @@ STATIC const mp_rom_map_elem_t pyb_sdcard_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&pyb_sdcard_ioctl_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_sdcard_locals_dict, pyb_sdcard_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_sdcard_locals_dict, pyb_sdcard_locals_dict_table); #if MICROPY_HW_ENABLE_SDCARD MP_DEFINE_CONST_OBJ_TYPE( diff --git a/ports/stm32/servo.c b/ports/stm32/servo.c index 07cc4eab88536..ea8205756a682 100644 --- a/ports/stm32/servo.c +++ b/ports/stm32/servo.c @@ -60,7 +60,7 @@ typedef struct _pyb_servo_obj_t { uint16_t time_left; } pyb_servo_obj_t; -STATIC pyb_servo_obj_t pyb_servo_obj[PYB_SERVO_NUM]; +static pyb_servo_obj_t pyb_servo_obj[PYB_SERVO_NUM]; void servo_init(void) { // reset servo objects @@ -123,7 +123,7 @@ void servo_timer_irq_callback(void) { } } -STATIC void servo_init_channel(pyb_servo_obj_t *s) { +static void servo_init_channel(pyb_servo_obj_t *s) { static const uint8_t channel_table[4] = {TIM_CHANNEL_1, TIM_CHANNEL_2, TIM_CHANNEL_3, TIM_CHANNEL_4}; uint32_t channel = channel_table[s->pin->pin]; @@ -150,7 +150,7 @@ STATIC void servo_init_channel(pyb_servo_obj_t *s) { /******************************************************************************/ // MicroPython bindings -STATIC mp_obj_t pyb_servo_set(mp_obj_t port, mp_obj_t value) { +static mp_obj_t pyb_servo_set(mp_obj_t port, mp_obj_t value) { int p = mp_obj_get_int(port); int v = mp_obj_get_int(value); if (v < 50) { @@ -178,7 +178,7 @@ STATIC mp_obj_t pyb_servo_set(mp_obj_t port, mp_obj_t value) { MP_DEFINE_CONST_FUN_OBJ_2(pyb_servo_set_obj, pyb_servo_set); -STATIC mp_obj_t pyb_pwm_set(mp_obj_t period, mp_obj_t pulse) { +static mp_obj_t pyb_pwm_set(mp_obj_t period, mp_obj_t pulse) { int pe = mp_obj_get_int(period); int pu = mp_obj_get_int(pulse); TIM5->ARR = pe; @@ -188,14 +188,14 @@ STATIC mp_obj_t pyb_pwm_set(mp_obj_t period, mp_obj_t pulse) { MP_DEFINE_CONST_FUN_OBJ_2(pyb_pwm_set_obj, pyb_pwm_set); -STATIC void pyb_servo_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void pyb_servo_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_servo_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", self - &pyb_servo_obj[0] + 1, 10 * self->pulse_cur); } /// \classmethod \constructor(id) /// Create a servo object. `id` is 1-4. -STATIC mp_obj_t pyb_servo_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pyb_servo_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, 1, false); @@ -218,7 +218,7 @@ STATIC mp_obj_t pyb_servo_make_new(const mp_obj_type_t *type, size_t n_args, siz /// \method pulse_width([value]) /// Get or set the pulse width in milliseconds. -STATIC mp_obj_t pyb_servo_pulse_width(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_servo_pulse_width(size_t n_args, const mp_obj_t *args) { pyb_servo_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 1) { // get pulse width, in us @@ -231,12 +231,12 @@ STATIC mp_obj_t pyb_servo_pulse_width(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_pulse_width_obj, 1, 2, pyb_servo_pulse_width); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_pulse_width_obj, 1, 2, pyb_servo_pulse_width); /// \method calibration([pulse_min, pulse_max, pulse_centre, [pulse_angle_90, pulse_speed_100]]) /// Get or set the calibration of the servo timing. // TODO should accept 1 arg, a 5-tuple of values to set -STATIC mp_obj_t pyb_servo_calibration(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_servo_calibration(size_t n_args, const mp_obj_t *args) { pyb_servo_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 1) { // get calibration values @@ -264,14 +264,14 @@ STATIC mp_obj_t pyb_servo_calibration(size_t n_args, const mp_obj_t *args) { // bad number of arguments mp_raise_msg_varg(&mp_type_TypeError, MP_ERROR_TEXT("calibration expecting 1, 4 or 6 arguments, got %d"), n_args); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_calibration_obj, 1, 6, pyb_servo_calibration); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_calibration_obj, 1, 6, pyb_servo_calibration); /// \method angle([angle, time=0]) /// Get or set the angle of the servo. /// /// - `angle` is the angle to move to in degrees. /// - `time` is the number of milliseconds to take to get to the specified angle. -STATIC mp_obj_t pyb_servo_angle(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_servo_angle(size_t n_args, const mp_obj_t *args) { pyb_servo_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 1) { // get angle @@ -294,14 +294,14 @@ STATIC mp_obj_t pyb_servo_angle(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_angle_obj, 1, 3, pyb_servo_angle); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_angle_obj, 1, 3, pyb_servo_angle); /// \method speed([speed, time=0]) /// Get or set the speed of a continuous rotation servo. /// /// - `speed` is the speed to move to change to, between -100 and 100. /// - `time` is the number of milliseconds to take to get to the specified speed. -STATIC mp_obj_t pyb_servo_speed(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_servo_speed(size_t n_args, const mp_obj_t *args) { pyb_servo_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 1) { // get speed @@ -325,16 +325,16 @@ STATIC mp_obj_t pyb_servo_speed(size_t n_args, const mp_obj_t *args) { } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_speed_obj, 1, 3, pyb_servo_speed); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_speed_obj, 1, 3, pyb_servo_speed); -STATIC const mp_rom_map_elem_t pyb_servo_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_servo_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_pulse_width), MP_ROM_PTR(&pyb_servo_pulse_width_obj) }, { MP_ROM_QSTR(MP_QSTR_calibration), MP_ROM_PTR(&pyb_servo_calibration_obj) }, { MP_ROM_QSTR(MP_QSTR_angle), MP_ROM_PTR(&pyb_servo_angle_obj) }, { MP_ROM_QSTR(MP_QSTR_speed), MP_ROM_PTR(&pyb_servo_speed_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_servo_locals_dict, pyb_servo_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_servo_locals_dict, pyb_servo_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pyb_servo_type, diff --git a/ports/stm32/spi.c b/ports/stm32/spi.c index df71efd3fe11a..5aace8e9a3e1f 100644 --- a/ports/stm32/spi.c +++ b/ports/stm32/spi.c @@ -46,22 +46,22 @@ // SPI6_RX: DMA2_Stream6.CHANNEL_1 #if defined(MICROPY_HW_SPI1_SCK) -STATIC SPI_HandleTypeDef SPIHandle1 = {.Instance = NULL}; +static SPI_HandleTypeDef SPIHandle1 = {.Instance = NULL}; #endif #if defined(MICROPY_HW_SPI2_SCK) -STATIC SPI_HandleTypeDef SPIHandle2 = {.Instance = NULL}; +static SPI_HandleTypeDef SPIHandle2 = {.Instance = NULL}; #endif #if defined(MICROPY_HW_SPI3_SCK) -STATIC SPI_HandleTypeDef SPIHandle3 = {.Instance = NULL}; +static SPI_HandleTypeDef SPIHandle3 = {.Instance = NULL}; #endif #if defined(MICROPY_HW_SPI4_SCK) -STATIC SPI_HandleTypeDef SPIHandle4 = {.Instance = NULL}; +static SPI_HandleTypeDef SPIHandle4 = {.Instance = NULL}; #endif #if defined(MICROPY_HW_SPI5_SCK) -STATIC SPI_HandleTypeDef SPIHandle5 = {.Instance = NULL}; +static SPI_HandleTypeDef SPIHandle5 = {.Instance = NULL}; #endif #if defined(MICROPY_HW_SPI6_SCK) -STATIC SPI_HandleTypeDef SPIHandle6 = {.Instance = NULL}; +static SPI_HandleTypeDef SPIHandle6 = {.Instance = NULL}; #endif #if defined(MICROPY_HW_SUBGHZSPI_ID) static SPI_HandleTypeDef SPIHandleSubGhz = {.Instance = NULL}; @@ -231,7 +231,7 @@ int spi_find_index(mp_obj_t id) { return spi_id; } -STATIC uint32_t spi_get_source_freq(SPI_HandleTypeDef *spi) { +static uint32_t spi_get_source_freq(SPI_HandleTypeDef *spi) { #if defined(STM32F0) || defined(STM32G0) return HAL_RCC_GetPCLK1Freq(); #elif defined(STM32H5) @@ -545,7 +545,7 @@ void spi_deinit(const spi_t *spi_obj) { } } -STATIC HAL_StatusTypeDef spi_wait_dma_finished(const spi_t *spi, uint32_t t_start, uint32_t timeout) { +static HAL_StatusTypeDef spi_wait_dma_finished(const spi_t *spi, uint32_t t_start, uint32_t timeout) { volatile HAL_SPI_StateTypeDef *state = &spi->spi->State; for (;;) { // Do an atomic check of the state; WFI will exit even if IRQs are disabled @@ -768,7 +768,7 @@ mp_obj_base_t *mp_hal_get_spi_obj(mp_obj_t o) { /******************************************************************************/ // Implementation of low-level SPI C protocol -STATIC int spi_proto_ioctl(void *self_in, uint32_t cmd) { +static int spi_proto_ioctl(void *self_in, uint32_t cmd) { spi_proto_cfg_t *self = (spi_proto_cfg_t *)self_in; switch (cmd) { @@ -790,7 +790,7 @@ STATIC int spi_proto_ioctl(void *self_in, uint32_t cmd) { return 0; } -STATIC void spi_proto_transfer(void *self_in, size_t len, const uint8_t *src, uint8_t *dest) { +static void spi_proto_transfer(void *self_in, size_t len, const uint8_t *src, uint8_t *dest) { spi_proto_cfg_t *self = (spi_proto_cfg_t *)self_in; spi_transfer(self->spi, len, src, dest, SPI_TRANSFER_TIMEOUT(len)); } diff --git a/ports/stm32/stm32_it.c b/ports/stm32/stm32_it.c index 50fd56ecaed0f..bc1feceb9c2b5 100644 --- a/ports/stm32/stm32_it.c +++ b/ports/stm32/stm32_it.c @@ -98,7 +98,7 @@ extern PCD_HandleTypeDef pcd_hs_handle; // More information about decoding the fault registers can be found here: // http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0646a/Cihdjcfc.html -STATIC char *fmt_hex(uint32_t val, char *buf) { +static char *fmt_hex(uint32_t val, char *buf) { const char *hexDig = "0123456789abcdef"; buf[0] = hexDig[(val >> 28) & 0x0f]; @@ -114,7 +114,7 @@ STATIC char *fmt_hex(uint32_t val, char *buf) { return buf; } -STATIC void print_reg(const char *label, uint32_t val) { +static void print_reg(const char *label, uint32_t val) { char hexStr[9]; mp_hal_stdout_tx_str(label); @@ -122,7 +122,7 @@ STATIC void print_reg(const char *label, uint32_t val) { mp_hal_stdout_tx_str("\r\n"); } -STATIC void print_hex_hex(const char *label, uint32_t val1, uint32_t val2) { +static void print_hex_hex(const char *label, uint32_t val1, uint32_t val2) { char hex_str[9]; mp_hal_stdout_tx_str(label); mp_hal_stdout_tx_str(fmt_hex(val1, hex_str)); @@ -356,7 +356,7 @@ void OTG_HS_IRQHandler(void) { * @param *pcd_handle for FS or HS * @retval None */ -STATIC void OTG_CMD_WKUP_Handler(PCD_HandleTypeDef *pcd_handle) { +static void OTG_CMD_WKUP_Handler(PCD_HandleTypeDef *pcd_handle) { if (pcd_handle->Init.low_power_enable) { /* Reset SLEEPDEEP bit of Cortex System Control Register */ diff --git a/ports/stm32/storage.c b/ports/stm32/storage.c index 4623225804ce0..a6594fd4d98c9 100644 --- a/ports/stm32/storage.c +++ b/ports/stm32/storage.c @@ -273,7 +273,7 @@ const pyb_flash_obj_t pyb_flash_obj = { 0, // actual size handled in ioctl, MP_BLOCKDEV_IOCTL_BLOCK_COUNT case }; -STATIC void pyb_flash_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void pyb_flash_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_flash_obj_t *self = MP_OBJ_TO_PTR(self_in); if (self == &pyb_flash_obj) { mp_printf(print, "Flash()"); @@ -282,7 +282,7 @@ STATIC void pyb_flash_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ } } -STATIC mp_obj_t pyb_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t pyb_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // Parse arguments enum { ARG_start, ARG_len }; static const mp_arg_t allowed_args[] = { @@ -322,7 +322,7 @@ STATIC mp_obj_t pyb_flash_make_new(const mp_obj_type_t *type, size_t n_args, siz return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t pyb_flash_readblocks(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_flash_readblocks(size_t n_args, const mp_obj_t *args) { pyb_flash_obj_t *self = MP_OBJ_TO_PTR(args[0]); uint32_t block_num = mp_obj_get_int(args[1]); mp_buffer_info_t bufinfo; @@ -347,9 +347,9 @@ STATIC mp_obj_t pyb_flash_readblocks(size_t n_args, const mp_obj_t *args) { #endif return MP_OBJ_NEW_SMALL_INT(ret); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_flash_readblocks_obj, 3, 4, pyb_flash_readblocks); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_flash_readblocks_obj, 3, 4, pyb_flash_readblocks); -STATIC mp_obj_t pyb_flash_writeblocks(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_flash_writeblocks(size_t n_args, const mp_obj_t *args) { pyb_flash_obj_t *self = MP_OBJ_TO_PTR(args[0]); uint32_t block_num = mp_obj_get_int(args[1]); mp_buffer_info_t bufinfo; @@ -374,9 +374,9 @@ STATIC mp_obj_t pyb_flash_writeblocks(size_t n_args, const mp_obj_t *args) { #endif return MP_OBJ_NEW_SMALL_INT(ret); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_flash_writeblocks_obj, 3, 4, pyb_flash_writeblocks); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_flash_writeblocks_obj, 3, 4, pyb_flash_writeblocks); -STATIC mp_obj_t pyb_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { +static mp_obj_t pyb_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { pyb_flash_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t cmd = mp_obj_get_int(cmd_in); switch (cmd) { @@ -438,15 +438,15 @@ STATIC mp_obj_t pyb_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_ return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_ioctl_obj, pyb_flash_ioctl); +static MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_ioctl_obj, pyb_flash_ioctl); -STATIC const mp_rom_map_elem_t pyb_flash_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_flash_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&pyb_flash_readblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&pyb_flash_writeblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&pyb_flash_ioctl_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_flash_locals_dict, pyb_flash_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_flash_locals_dict, pyb_flash_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pyb_flash_type, diff --git a/ports/stm32/subghz.c b/ports/stm32/subghz.c index 1daed59aaf2aa..f131a2f91a33c 100644 --- a/ports/stm32/subghz.c +++ b/ports/stm32/subghz.c @@ -34,7 +34,7 @@ // Interface to the STM32WL series "SUBGHZ Radio" module -STATIC void handle_radio_irq() { +static void handle_radio_irq() { // Level-triggered interrupts means the interrupt has to be cleared before // this function returns. // @@ -90,7 +90,7 @@ void subghz_deinit(void) { __HAL_RCC_SUBGHZ_RADIO_RELEASE_RESET(); } -STATIC mp_obj_t subghz_cs(mp_obj_t value) { +static mp_obj_t subghz_cs(mp_obj_t value) { // Treat the same as normal SPI - truthy is "unselected", // falsey is active low "selected", if (mp_obj_is_true(value)) { @@ -103,7 +103,7 @@ STATIC mp_obj_t subghz_cs(mp_obj_t value) { } MP_DEFINE_CONST_FUN_OBJ_1(subghz_cs_obj, subghz_cs); -STATIC mp_obj_t subghz_irq(mp_obj_t handler) { +static mp_obj_t subghz_irq(mp_obj_t handler) { MP_STATE_PORT(subghz_callback) = handler; if (mp_obj_is_true(handler)) { @@ -117,7 +117,7 @@ STATIC mp_obj_t subghz_irq(mp_obj_t handler) { } MP_DEFINE_CONST_FUN_OBJ_1(subghz_irq_obj, subghz_irq); -STATIC mp_obj_t subghz_is_busy(void) { +static mp_obj_t subghz_is_busy(void) { // Read the raw unmasked busy signal. This should be checked before driving // CS low to start a command. // diff --git a/ports/stm32/timer.c b/ports/stm32/timer.c index 41e5c6157d5ac..d999e57462edb 100644 --- a/ports/stm32/timer.c +++ b/ports/stm32/timer.c @@ -93,7 +93,7 @@ typedef enum { CHANNEL_MODE_ENC_AB, } pyb_channel_mode; -STATIC const struct { +static const struct { qstr name; uint32_t oc_mode; } channel_mode_info[] = { @@ -147,9 +147,9 @@ TIM_HandleTypeDef TIM6_Handle; #define PYB_TIMER_OBJ_ALL_NUM MP_ARRAY_SIZE(MP_STATE_PORT(pyb_timer_obj_all)) -STATIC mp_obj_t pyb_timer_deinit(mp_obj_t self_in); -STATIC mp_obj_t pyb_timer_callback(mp_obj_t self_in, mp_obj_t callback); -STATIC mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback); +static mp_obj_t pyb_timer_deinit(mp_obj_t self_in); +static mp_obj_t pyb_timer_callback(mp_obj_t self_in, mp_obj_t callback); +static mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback); void timer_init0(void) { for (uint i = 0; i < PYB_TIMER_OBJ_ALL_NUM; i++) { @@ -304,14 +304,14 @@ uint32_t timer_get_source_freq(uint32_t tim_id) { /******************************************************************************/ /* MicroPython bindings */ -STATIC const mp_obj_type_t pyb_timer_channel_type; +static const mp_obj_type_t pyb_timer_channel_type; // This is the largest value that we can multiply by 100 and have the result // fit in a uint32_t. #define MAX_PERIOD_DIV_100 42949672 // computes prescaler and period so TIM triggers at freq-Hz -STATIC uint32_t compute_prescaler_period_from_freq(pyb_timer_obj_t *self, mp_obj_t freq_in, uint32_t *period_out) { +static uint32_t compute_prescaler_period_from_freq(pyb_timer_obj_t *self, mp_obj_t freq_in, uint32_t *period_out) { uint32_t source_freq = timer_get_source_freq(self->tim_id); uint32_t prescaler = 1; uint32_t period; @@ -357,7 +357,7 @@ STATIC uint32_t compute_prescaler_period_from_freq(pyb_timer_obj_t *self, mp_obj } // computes prescaler and period so TIM triggers with a period of t_num/t_den seconds -STATIC uint32_t compute_prescaler_period_from_t(pyb_timer_obj_t *self, int32_t t_num, int32_t t_den, uint32_t *period_out) { +static uint32_t compute_prescaler_period_from_t(pyb_timer_obj_t *self, int32_t t_num, int32_t t_den, uint32_t *period_out) { uint32_t source_freq = timer_get_source_freq(self->tim_id); if (t_num <= 0 || t_den <= 0) { mp_raise_ValueError(MP_ERROR_TEXT("must have positive freq")); @@ -391,7 +391,7 @@ STATIC uint32_t compute_prescaler_period_from_t(pyb_timer_obj_t *self, int32_t t } // Helper function for determining the period used for calculating percent -STATIC uint32_t compute_period(pyb_timer_obj_t *self) { +static uint32_t compute_period(pyb_timer_obj_t *self) { // In center mode, compare == period corresponds to 100% // In edge mode, compare == (period + 1) corresponds to 100% uint32_t period = (__HAL_TIM_GET_AUTORELOAD(&self->tim) & TIMER_CNT_MASK(self)); @@ -408,7 +408,7 @@ STATIC uint32_t compute_period(pyb_timer_obj_t *self) { // Helper function to compute PWM value from timer period and percent value. // 'percent_in' can be an int or a float between 0 and 100 (out of range // values are clamped). -STATIC uint32_t compute_pwm_value_from_percent(uint32_t period, mp_obj_t percent_in) { +static uint32_t compute_pwm_value_from_percent(uint32_t period, mp_obj_t percent_in) { uint32_t cmp; if (0) { #if MICROPY_PY_BUILTINS_FLOAT @@ -441,7 +441,7 @@ STATIC uint32_t compute_pwm_value_from_percent(uint32_t period, mp_obj_t percent } // Helper function to compute percentage from timer perion and PWM value. -STATIC mp_obj_t compute_percent_from_pwm_value(uint32_t period, uint32_t cmp) { +static mp_obj_t compute_percent_from_pwm_value(uint32_t period, uint32_t cmp) { #if MICROPY_PY_BUILTINS_FLOAT mp_float_t percent; if (cmp >= period) { @@ -472,7 +472,7 @@ STATIC mp_obj_t compute_percent_from_pwm_value(uint32_t period, uint32_t cmp) { // 128-256 ticks in increments of 2 // 256-512 ticks in increments of 8 // 512-1008 ticks in increments of 16 -STATIC uint32_t compute_dtg_from_ticks(mp_int_t ticks) { +static uint32_t compute_dtg_from_ticks(mp_int_t ticks) { if (ticks <= 0) { return 0; } @@ -493,7 +493,7 @@ STATIC uint32_t compute_dtg_from_ticks(mp_int_t ticks) { // Given the 8-bit value stored in the DTG field of the BDTR register, compute // the number of ticks. -STATIC mp_int_t compute_ticks_from_dtg(uint32_t dtg) { +static mp_int_t compute_ticks_from_dtg(uint32_t dtg) { if ((dtg & 0x80) == 0) { return dtg & 0x7F; } @@ -506,7 +506,7 @@ STATIC mp_int_t compute_ticks_from_dtg(uint32_t dtg) { return 512 + ((dtg & 0x1F) * 16); } -STATIC void config_deadtime(pyb_timer_obj_t *self, mp_int_t ticks, mp_int_t brk) { +static void config_deadtime(pyb_timer_obj_t *self, mp_int_t ticks, mp_int_t brk) { TIM_BreakDeadTimeConfigTypeDef deadTimeConfig = {0}; deadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE; deadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE; @@ -534,7 +534,7 @@ TIM_HandleTypeDef *pyb_timer_get_handle(mp_obj_t timer) { return &self->tim; } -STATIC void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_timer_obj_t *self = MP_OBJ_TO_PTR(self_in); if (self->tim.State == HAL_TIM_STATE_RESET) { @@ -628,7 +628,7 @@ STATIC void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ /// /// /// You must either specify freq or both of period and prescaler. -STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_freq, ARG_prescaler, ARG_period, ARG_tick_hz, ARG_mode, ARG_div, ARG_callback, ARG_deadtime, ARG_brk }; static const mp_arg_t allowed_args[] = { { MP_QSTR_freq, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, @@ -834,7 +834,7 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, size_t n_args, cons // This table encodes the timer instance and irq number (for the update irq). // It assumes that timer instance pointer has the lower 8 bits cleared. #define TIM_ENTRY(id, irq) [id - 1] = (uint32_t)TIM##id | irq -STATIC const uint32_t tim_instance_table[MICROPY_HW_MAX_TIMER] = { +static const uint32_t tim_instance_table[MICROPY_HW_MAX_TIMER] = { #if defined(TIM1) #if defined(STM32F0) || defined(STM32G0) TIM_ENTRY(1, TIM1_BRK_UP_TRG_COM_IRQn), @@ -977,7 +977,7 @@ STATIC const uint32_t tim_instance_table[MICROPY_HW_MAX_TIMER] = { /// Construct a new timer object of the given id. If additional /// arguments are given, then the timer is initialised by `init(...)`. /// `id` can be 1 to 14, excluding 3. -STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); @@ -1026,13 +1026,13 @@ STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, size_t n_args, siz return MP_OBJ_FROM_PTR(tim); } -STATIC mp_obj_t pyb_timer_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t pyb_timer_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { return pyb_timer_init_helper(MP_OBJ_TO_PTR(args[0]), n_args - 1, args + 1, kw_args); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_init_obj, 1, pyb_timer_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_init_obj, 1, pyb_timer_init); // timer.deinit() -STATIC mp_obj_t pyb_timer_deinit(mp_obj_t self_in) { +static mp_obj_t pyb_timer_deinit(mp_obj_t self_in) { pyb_timer_obj_t *self = MP_OBJ_TO_PTR(self_in); // Disable the base interrupt @@ -1055,7 +1055,7 @@ STATIC mp_obj_t pyb_timer_deinit(mp_obj_t self_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj, pyb_timer_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj, pyb_timer_deinit); /// \method channel(channel, mode, ...) /// @@ -1129,7 +1129,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj, pyb_timer_deinit); /// timer = pyb.Timer(2, freq=1000) /// ch2 = timer.channel(2, pyb.Timer.PWM, pin=pyb.Pin.board.X2, pulse_width=210000) /// ch3 = timer.channel(3, pyb.Timer.PWM, pin=pyb.Pin.board.X3, pulse_width=420000) -STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_callback, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, @@ -1386,11 +1386,11 @@ STATIC mp_obj_t pyb_timer_channel(size_t n_args, const mp_obj_t *pos_args, mp_ma return MP_OBJ_FROM_PTR(chan); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_channel_obj, 2, pyb_timer_channel); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_channel_obj, 2, pyb_timer_channel); /// \method counter([value]) /// Get or set the timer counter. -STATIC mp_obj_t pyb_timer_counter(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_timer_counter(size_t n_args, const mp_obj_t *args) { pyb_timer_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 1) { // get @@ -1401,20 +1401,20 @@ STATIC mp_obj_t pyb_timer_counter(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_counter_obj, 1, 2, pyb_timer_counter); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_counter_obj, 1, 2, pyb_timer_counter); /// \method source_freq() /// Get the frequency of the source of the timer. -STATIC mp_obj_t pyb_timer_source_freq(mp_obj_t self_in) { +static mp_obj_t pyb_timer_source_freq(mp_obj_t self_in) { pyb_timer_obj_t *self = MP_OBJ_TO_PTR(self_in); uint32_t source_freq = timer_get_source_freq(self->tim_id); return mp_obj_new_int(source_freq); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_source_freq_obj, pyb_timer_source_freq); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_source_freq_obj, pyb_timer_source_freq); /// \method freq([value]) /// Get or set the frequency for the timer (changes prescaler and period if set). -STATIC mp_obj_t pyb_timer_freq(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_timer_freq(size_t n_args, const mp_obj_t *args) { pyb_timer_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 1) { // get @@ -1445,11 +1445,11 @@ STATIC mp_obj_t pyb_timer_freq(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_freq_obj, 1, 2, pyb_timer_freq); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_freq_obj, 1, 2, pyb_timer_freq); /// \method prescaler([value]) /// Get or set the prescaler for the timer. -STATIC mp_obj_t pyb_timer_prescaler(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_timer_prescaler(size_t n_args, const mp_obj_t *args) { pyb_timer_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 1) { // get @@ -1460,11 +1460,11 @@ STATIC mp_obj_t pyb_timer_prescaler(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_prescaler_obj, 1, 2, pyb_timer_prescaler); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_prescaler_obj, 1, 2, pyb_timer_prescaler); /// \method period([value]) /// Get or set the period of the timer. -STATIC mp_obj_t pyb_timer_period(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_timer_period(size_t n_args, const mp_obj_t *args) { pyb_timer_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 1) { // get @@ -1475,13 +1475,13 @@ STATIC mp_obj_t pyb_timer_period(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_period_obj, 1, 2, pyb_timer_period); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_period_obj, 1, 2, pyb_timer_period); /// \method callback(fun) /// Set the function to be called when the timer triggers. /// `fun` is passed 1 argument, the timer object. /// If `fun` is `None` then the callback will be disabled. -STATIC mp_obj_t pyb_timer_callback(mp_obj_t self_in, mp_obj_t callback) { +static mp_obj_t pyb_timer_callback(mp_obj_t self_in, mp_obj_t callback) { pyb_timer_obj_t *self = MP_OBJ_TO_PTR(self_in); if (callback == mp_const_none) { // stop interrupt (but not timer) @@ -1501,9 +1501,9 @@ STATIC mp_obj_t pyb_timer_callback(mp_obj_t self_in, mp_obj_t callback) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_timer_callback_obj, pyb_timer_callback); +static MP_DEFINE_CONST_FUN_OBJ_2(pyb_timer_callback_obj, pyb_timer_callback); -STATIC const mp_rom_map_elem_t pyb_timer_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_timer_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_timer_init_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_timer_deinit_obj) }, @@ -1538,7 +1538,7 @@ STATIC const mp_rom_map_elem_t pyb_timer_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_BRK_LOW), MP_ROM_INT(BRK_LOW) }, { MP_ROM_QSTR(MP_QSTR_BRK_HIGH), MP_ROM_INT(BRK_HIGH) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_timer_locals_dict, pyb_timer_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_timer_locals_dict, pyb_timer_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pyb_timer_type, @@ -1555,7 +1555,7 @@ MP_DEFINE_CONST_OBJ_TYPE( /// Timer channels are used to generate/capture a signal using a timer. /// /// TimerChannel objects are created using the Timer.channel() method. -STATIC void pyb_timer_channel_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void pyb_timer_channel_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_timer_channel_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "TimerChannel(timer=%u, channel=%u, mode=%s)", @@ -1581,7 +1581,7 @@ STATIC void pyb_timer_channel_print(const mp_print_t *print, mp_obj_t self_in, m /// /// In edge aligned mode, a pulse_width of `period + 1` corresponds to a duty cycle of 100% /// In center aligned mode, a pulse width of `period` corresponds to a duty cycle of 100% -STATIC mp_obj_t pyb_timer_channel_capture_compare(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_timer_channel_capture_compare(size_t n_args, const mp_obj_t *args) { pyb_timer_channel_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 1) { // get @@ -1592,7 +1592,7 @@ STATIC mp_obj_t pyb_timer_channel_capture_compare(size_t n_args, const mp_obj_t return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_capture_compare_obj, 1, 2, pyb_timer_channel_capture_compare); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_capture_compare_obj, 1, 2, pyb_timer_channel_capture_compare); /// \method pulse_width_percent([value]) /// Get or set the pulse width percentage associated with a channel. The value @@ -1600,7 +1600,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_capture_compare_obj /// for which the pulse is active. The value can be an integer or /// floating-point number for more accuracy. For example, a value of 25 gives /// a duty cycle of 25%. -STATIC mp_obj_t pyb_timer_channel_pulse_width_percent(size_t n_args, const mp_obj_t *args) { +static mp_obj_t pyb_timer_channel_pulse_width_percent(size_t n_args, const mp_obj_t *args) { pyb_timer_channel_obj_t *self = MP_OBJ_TO_PTR(args[0]); uint32_t period = compute_period(self->timer); if (n_args == 1) { @@ -1614,13 +1614,13 @@ STATIC mp_obj_t pyb_timer_channel_pulse_width_percent(size_t n_args, const mp_ob return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_pulse_width_percent_obj, 1, 2, pyb_timer_channel_pulse_width_percent); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_timer_channel_pulse_width_percent_obj, 1, 2, pyb_timer_channel_pulse_width_percent); /// \method callback(fun) /// Set the function to be called when the timer channel triggers. /// `fun` is passed 1 argument, the timer object. /// If `fun` is `None` then the callback will be disabled. -STATIC mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback) { +static mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback) { pyb_timer_channel_obj_t *self = MP_OBJ_TO_PTR(self_in); if (callback == mp_const_none) { // stop interrupt (but not timer) @@ -1668,9 +1668,9 @@ STATIC mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback) } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_timer_channel_callback_obj, pyb_timer_channel_callback); +static MP_DEFINE_CONST_FUN_OBJ_2(pyb_timer_channel_callback_obj, pyb_timer_channel_callback); -STATIC const mp_rom_map_elem_t pyb_timer_channel_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_timer_channel_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_callback), MP_ROM_PTR(&pyb_timer_channel_callback_obj) }, { MP_ROM_QSTR(MP_QSTR_pulse_width), MP_ROM_PTR(&pyb_timer_channel_capture_compare_obj) }, @@ -1678,9 +1678,9 @@ STATIC const mp_rom_map_elem_t pyb_timer_channel_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_capture), MP_ROM_PTR(&pyb_timer_channel_capture_compare_obj) }, { MP_ROM_QSTR(MP_QSTR_compare), MP_ROM_PTR(&pyb_timer_channel_capture_compare_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_timer_channel_locals_dict, pyb_timer_channel_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_timer_channel_locals_dict, pyb_timer_channel_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( pyb_timer_channel_type, MP_QSTR_TimerChannel, MP_TYPE_FLAG_NONE, @@ -1688,7 +1688,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &pyb_timer_channel_locals_dict ); -STATIC void timer_handle_irq_channel(pyb_timer_obj_t *tim, uint8_t channel, mp_obj_t callback) { +static void timer_handle_irq_channel(pyb_timer_obj_t *tim, uint8_t channel, mp_obj_t callback) { uint32_t irq_mask = TIMER_IRQ_MASK(channel); if (__HAL_TIM_GET_FLAG(&tim->tim, irq_mask) != RESET) { diff --git a/ports/stm32/uart.c b/ports/stm32/uart.c index 83e9e0fdd8597..886cf1ab340ba 100644 --- a/ports/stm32/uart.c +++ b/ports/stm32/uart.c @@ -122,7 +122,7 @@ typedef struct _machine_uart_irq_map_t { uint16_t flag; } machine_uart_irq_map_t; -STATIC const machine_uart_irq_map_t mp_uart_irq_map[] = { +static const machine_uart_irq_map_t mp_uart_irq_map[] = { { USART_CR1_IDLEIE, UART_FLAG_IDLE}, // RX idle { USART_CR1_PEIE, UART_FLAG_PE}, // parity error #if defined(STM32G0) || defined(STM32WL) @@ -1038,7 +1038,7 @@ bool uart_tx_wait(machine_uart_obj_t *self, uint32_t timeout) { // Waits at most timeout milliseconds for UART flag to be set. // Returns true if flag is/was set, false on timeout. -STATIC bool uart_wait_flag_set(machine_uart_obj_t *self, uint32_t flag, uint32_t timeout) { +static bool uart_wait_flag_set(machine_uart_obj_t *self, uint32_t flag, uint32_t timeout) { // Note: we don't use WFI to idle in this loop because UART tx doesn't generate // an interrupt and the flag can be set quickly if the baudrate is large. uint32_t start = HAL_GetTick(); @@ -1215,7 +1215,7 @@ void uart_irq_handler(mp_uint_t uart_id) { } } -STATIC mp_uint_t uart_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { +static mp_uint_t uart_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); uart_irq_config(self, false); self->mp_irq_trigger = new_trigger; @@ -1223,7 +1223,7 @@ STATIC mp_uint_t uart_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { return 0; } -STATIC mp_uint_t uart_irq_info(mp_obj_t self_in, mp_uint_t info_type) { +static mp_uint_t uart_irq_info(mp_obj_t self_in, mp_uint_t info_type) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); if (info_type == MP_IRQ_INFO_FLAGS) { return self->mp_irq_flags; diff --git a/ports/stm32/usb.c b/ports/stm32/usb.c index df6b2cf62a1ff..af9dd1d70ec2b 100644 --- a/ports/stm32/usb.c +++ b/ports/stm32/usb.c @@ -74,7 +74,7 @@ // Constants for USB_VCP.irq trigger. #define USBD_CDC_IRQ_RX (1) -STATIC void pyb_usb_vcp_init0(void); +static void pyb_usb_vcp_init0(void); // this will be persistent across a soft-reset mp_uint_t pyb_usb_flags = 0; @@ -97,14 +97,14 @@ pyb_usb_storage_medium_t pyb_usb_storage_medium = PYB_USB_STORAGE_MEDIUM_NONE; // Units of FIFO size arrays below are 4x 16-bit words = 8 bytes // There are 512x 16-bit words it total to use here (when using PCD_SNG_BUF) -STATIC const uint8_t usbd_fifo_size_cdc1[USBD_PMA_NUM_FIFO] = { +static const uint8_t usbd_fifo_size_cdc1[USBD_PMA_NUM_FIFO] = { 16, 16, 16, 16, // EP0(out), EP0(in), MSC/HID(out), MSC/HID(in) 0, 16, 16, 16, // unused, CDC_CMD(in), CDC_DATA(out), CDC_DATA(in) 0, 0, 0, 0, 0, 0, 0, 0, // 8x unused }; #if MICROPY_HW_USB_CDC_NUM >= 2 -STATIC const uint8_t usbd_fifo_size_cdc2[USBD_PMA_NUM_FIFO] = { +static const uint8_t usbd_fifo_size_cdc2[USBD_PMA_NUM_FIFO] = { 8, 8, 16, 16, // EP0(out), EP0(in), MSC/HID(out), MSC/HID(in) 0, 8, 16, 8, // unused, CDC_CMD(in), CDC_DATA(out), CDC_DATA(in) 0, 8, 16, 8, // unused, CDC2_CMD(in), CDC2_DATA(out), CDC2_DATA(in) @@ -112,7 +112,7 @@ STATIC const uint8_t usbd_fifo_size_cdc2[USBD_PMA_NUM_FIFO] = { }; // RX; EP0(in), MSC/HID, CDC_CMD, CDC_DATA, CDC2_CMD/HID, CDC2_DATA, HID -STATIC const uint8_t usbd_fifo_size_cdc2_msc_hid[USBD_PMA_NUM_FIFO] = { +static const uint8_t usbd_fifo_size_cdc2_msc_hid[USBD_PMA_NUM_FIFO] = { 8, 8, 16, 16, // EP0(out), EP0(in), MSC/HID(out), MSC/HID(in) 0, 8, 8, 8, // unused, CDC_CMD(in), CDC_DATA(out), CDC_DATA(in) 0, 8, 8, 8, // unused, CDC2_CMD(in), CDC2_DATA(out), CDC2_DATA(in) @@ -128,7 +128,7 @@ STATIC const uint8_t usbd_fifo_size_cdc2_msc_hid[USBD_PMA_NUM_FIFO] = { // HS: there are 1024x 32-bit words in total to use here // RX; EP0(in), MSC/HID, CDC_CMD, CDC_DATA -STATIC const uint8_t usbd_fifo_size_cdc1[] = { +static const uint8_t usbd_fifo_size_cdc1[] = { 32, 8, 16, 8, 16, 0, 0, // FS: RX, EP0(in), 5x IN endpoints #if MICROPY_HW_USB_HS 116, 8, 64, 4, 64, 0, 0, 0, 0, 0, // HS: RX, EP0(in), 8x IN endpoints @@ -136,7 +136,7 @@ STATIC const uint8_t usbd_fifo_size_cdc1[] = { }; // RX; EP0(in), MSC/HID, CDC_CMD, CDC_DATA, HID -STATIC const uint8_t usbd_fifo_size_cdc1_msc_hid[] = { +static const uint8_t usbd_fifo_size_cdc1_msc_hid[] = { 32, 8, 16, 4, 12, 8, 0, #if MICROPY_HW_USB_HS 116, 8, 64, 4, 56, 8, 0, 0, 0, 0, @@ -145,7 +145,7 @@ STATIC const uint8_t usbd_fifo_size_cdc1_msc_hid[] = { #if MICROPY_HW_USB_CDC_NUM >= 2 // RX; EP0(in), MSC/HID, CDC_CMD, CDC_DATA, CDC2_CMD, CDC2_DATA -STATIC const uint8_t usbd_fifo_size_cdc2[] = { +static const uint8_t usbd_fifo_size_cdc2[] = { 32, 8, 16, 4, 8, 4, 8, #if MICROPY_HW_USB_HS 116, 8, 64, 2, 32, 2, 32, 0, 0, 0, @@ -153,7 +153,7 @@ STATIC const uint8_t usbd_fifo_size_cdc2[] = { }; // RX; EP0(in), MSC/HID, CDC_CMD, CDC_DATA, CDC2_CMD/HID, CDC2_DATA, HID -STATIC const uint8_t usbd_fifo_size_cdc2_msc_hid[] = { +static const uint8_t usbd_fifo_size_cdc2_msc_hid[] = { 0, 0, 0, 0, 0, 0, 0, // FS: can't support 2xVCP+MSC+HID #if MICROPY_HW_USB_HS 102, 8, 64, 2, 32, 8, 32, 8, 0, 0, @@ -163,7 +163,7 @@ STATIC const uint8_t usbd_fifo_size_cdc2_msc_hid[] = { #if MICROPY_HW_USB_CDC_NUM >= 3 // RX; EP0(in), MSC/HID, CDC_CMD, CDC_DATA, CDC2_CMD, CDC2_DATA, CDC3_CMD, CDC3_DATA -STATIC const uint8_t usbd_fifo_size_cdc3[] = { +static const uint8_t usbd_fifo_size_cdc3[] = { 0, 0, 0, 0, 0, 0, 0, // FS: can't support 3x VCP mode #if MICROPY_HW_USB_HS 82, 8, 64, 2, 32, 2, 32, 2, 32, 0, @@ -171,7 +171,7 @@ STATIC const uint8_t usbd_fifo_size_cdc3[] = { }; // RX; EP0(in), MSC/HID, CDC_CMD, CDC_DATA, CDC2_CMD/HID, CDC2_DATA, CDC3_CMD/HID, CDC3_DATA, HID -STATIC const uint8_t usbd_fifo_size_cdc3_msc_hid[] = { +static const uint8_t usbd_fifo_size_cdc3_msc_hid[] = { 0, 0, 0, 0, 0, 0, 0, // FS: can't support 3x VCP mode #if MICROPY_HW_USB_HS 82, 8, 64, 2, 25, 8, 25, 8, 25, 8, @@ -183,7 +183,7 @@ STATIC const uint8_t usbd_fifo_size_cdc3_msc_hid[] = { #if MICROPY_HW_USB_HID // predefined hid mouse data -STATIC const mp_obj_str_t pyb_usb_hid_mouse_desc_obj = { +static const mp_obj_str_t pyb_usb_hid_mouse_desc_obj = { {&mp_type_bytes}, 0, // hash not valid USBD_HID_MOUSE_REPORT_DESC_SIZE, @@ -202,7 +202,7 @@ const mp_rom_obj_tuple_t pyb_usb_hid_mouse_obj = { }; // predefined hid keyboard data -STATIC const mp_obj_str_t pyb_usb_hid_keyboard_desc_obj = { +static const mp_obj_str_t pyb_usb_hid_keyboard_desc_obj = { {&mp_type_bytes}, 0, // hash not valid USBD_HID_KEYBOARD_REPORT_DESC_SIZE, @@ -423,7 +423,7 @@ typedef struct _pyb_usb_mode_table_t { // These are all the modes supported by USBD_SelectMode. // Note: there are some names (eg CDC, VCP+VCP) which are supported for backwards compatibility. -STATIC const pyb_usb_mode_table_t pyb_usb_mode_table[] = { +static const pyb_usb_mode_table_t pyb_usb_mode_table[] = { { USBD_MODE_CDC, MP_QSTR_VCP, "CDC", MICROPY_HW_USB_PID_CDC }, { USBD_MODE_MSC, MP_QSTR_MSC, NULL, MICROPY_HW_USB_PID_MSC }, { USBD_MODE_CDC_MSC, MP_QSTR_VCP_plus_MSC, "CDC+MSC", MICROPY_HW_USB_PID_CDC_MSC }, @@ -443,7 +443,7 @@ STATIC const pyb_usb_mode_table_t pyb_usb_mode_table[] = { #endif }; -STATIC mp_obj_t pyb_usb_mode(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_usb_mode(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_mode, ARG_port, ARG_vid, ARG_pid, #if MICROPY_HW_USB_MSC @@ -638,9 +638,9 @@ const pyb_usb_vcp_obj_t pyb_usb_vcp_obj[MICROPY_HW_USB_CDC_NUM] = { #endif }; -STATIC bool pyb_usb_vcp_irq_scheduled[MICROPY_HW_USB_CDC_NUM]; +static bool pyb_usb_vcp_irq_scheduled[MICROPY_HW_USB_CDC_NUM]; -STATIC void pyb_usb_vcp_init0(void) { +static void pyb_usb_vcp_init0(void) { for (size_t i = 0; i < MICROPY_HW_USB_CDC_NUM; ++i) { MP_STATE_PORT(pyb_usb_vcp_irq)[i] = mp_const_none; pyb_usb_vcp_irq_scheduled[i] = false; @@ -651,7 +651,7 @@ STATIC void pyb_usb_vcp_init0(void) { usb_vcp_attach_to_repl(&pyb_usb_vcp_obj[0], true); } -STATIC mp_obj_t pyb_usb_vcp_irq_run(mp_obj_t self_in) { +static mp_obj_t pyb_usb_vcp_irq_run(mp_obj_t self_in) { pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(self_in); uint8_t idx = self->cdc_itf->cdc_idx; mp_obj_t callback = MP_STATE_PORT(pyb_usb_vcp_irq)[idx]; @@ -661,7 +661,7 @@ STATIC mp_obj_t pyb_usb_vcp_irq_run(mp_obj_t self_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_usb_vcp_irq_run_obj, pyb_usb_vcp_irq_run); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_usb_vcp_irq_run_obj, pyb_usb_vcp_irq_run); void usbd_cdc_rx_event_callback(usbd_cdc_itf_t *cdc) { uint8_t idx = cdc->cdc_idx; @@ -672,7 +672,7 @@ void usbd_cdc_rx_event_callback(usbd_cdc_itf_t *cdc) { } } -STATIC void pyb_usb_vcp_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void pyb_usb_vcp_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { int id = ((pyb_usb_vcp_obj_t *)MP_OBJ_TO_PTR(self_in))->cdc_itf->cdc_idx; mp_printf(print, "USB_VCP(%u)", id); } @@ -689,7 +689,7 @@ void usb_vcp_attach_to_repl(const pyb_usb_vcp_obj_t *self, bool attached) { /// \classmethod \constructor() /// Create a new USB_VCP object. -STATIC mp_obj_t pyb_usb_vcp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pyb_usb_vcp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 0, 1, false); @@ -704,7 +704,7 @@ STATIC mp_obj_t pyb_usb_vcp_make_new(const mp_obj_type_t *type, size_t n_args, s } // init(*, flow=-1) -STATIC mp_obj_t pyb_usb_vcp_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_usb_vcp_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_flow }; static const mp_arg_t allowed_args[] = { { MP_QSTR_flow, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, @@ -722,29 +722,29 @@ STATIC mp_obj_t pyb_usb_vcp_init(size_t n_args, const mp_obj_t *pos_args, mp_map return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_vcp_init_obj, 1, pyb_usb_vcp_init); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_vcp_init_obj, 1, pyb_usb_vcp_init); -STATIC mp_obj_t pyb_usb_vcp_setinterrupt(mp_obj_t self_in, mp_obj_t int_chr_in) { +static mp_obj_t pyb_usb_vcp_setinterrupt(mp_obj_t self_in, mp_obj_t int_chr_in) { mp_hal_set_interrupt_char(mp_obj_get_int(int_chr_in)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_usb_vcp_setinterrupt_obj, pyb_usb_vcp_setinterrupt); +static MP_DEFINE_CONST_FUN_OBJ_2(pyb_usb_vcp_setinterrupt_obj, pyb_usb_vcp_setinterrupt); -STATIC mp_obj_t pyb_usb_vcp_isconnected(mp_obj_t self_in) { +static mp_obj_t pyb_usb_vcp_isconnected(mp_obj_t self_in) { pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_bool(usbd_cdc_is_connected(self->cdc_itf)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_usb_vcp_isconnected_obj, pyb_usb_vcp_isconnected); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_usb_vcp_isconnected_obj, pyb_usb_vcp_isconnected); // deprecated in favour of USB_VCP.isconnected -STATIC mp_obj_t pyb_have_cdc(void) { +static mp_obj_t pyb_have_cdc(void) { return pyb_usb_vcp_isconnected(MP_OBJ_FROM_PTR(&pyb_usb_vcp_obj[0])); } MP_DEFINE_CONST_FUN_OBJ_0(pyb_have_cdc_obj, pyb_have_cdc); /// \method any() /// Return `True` if any characters waiting, else `False`. -STATIC mp_obj_t pyb_usb_vcp_any(mp_obj_t self_in) { +static mp_obj_t pyb_usb_vcp_any(mp_obj_t self_in) { pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(self_in); if (usbd_cdc_rx_num(self->cdc_itf) > 0) { return mp_const_true; @@ -752,7 +752,7 @@ STATIC mp_obj_t pyb_usb_vcp_any(mp_obj_t self_in) { return mp_const_false; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_usb_vcp_any_obj, pyb_usb_vcp_any); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_usb_vcp_any_obj, pyb_usb_vcp_any); /// \method send(data, *, timeout=5000) /// Send data over the USB VCP: @@ -761,13 +761,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_usb_vcp_any_obj, pyb_usb_vcp_any); /// - `timeout` is the timeout in milliseconds to wait for the send. /// /// Return value: number of bytes sent. -STATIC const mp_arg_t pyb_usb_vcp_send_args[] = { +static const mp_arg_t pyb_usb_vcp_send_args[] = { { MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 5000} }, }; #define PYB_USB_VCP_SEND_NUM_ARGS MP_ARRAY_SIZE(pyb_usb_vcp_send_args) -STATIC mp_obj_t pyb_usb_vcp_send(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t pyb_usb_vcp_send(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { // parse args pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(args[0]); mp_arg_val_t vals[PYB_USB_VCP_SEND_NUM_ARGS]; @@ -783,7 +783,7 @@ STATIC mp_obj_t pyb_usb_vcp_send(size_t n_args, const mp_obj_t *args, mp_map_t * return mp_obj_new_int(ret); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_vcp_send_obj, 1, pyb_usb_vcp_send); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_vcp_send_obj, 1, pyb_usb_vcp_send); /// \method recv(data, *, timeout=5000) /// @@ -795,7 +795,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_vcp_send_obj, 1, pyb_usb_vcp_send); /// /// Return value: if `data` is an integer then a new buffer of the bytes received, /// otherwise the number of bytes read into `data` is returned. -STATIC mp_obj_t pyb_usb_vcp_recv(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t pyb_usb_vcp_recv(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { // parse args pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(args[0]); mp_arg_val_t vals[PYB_USB_VCP_SEND_NUM_ARGS]; @@ -816,10 +816,10 @@ STATIC mp_obj_t pyb_usb_vcp_recv(size_t n_args, const mp_obj_t *args, mp_map_t * return mp_obj_new_bytes_from_vstr(&vstr); // create a new buffer } } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_vcp_recv_obj, 1, pyb_usb_vcp_recv); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_vcp_recv_obj, 1, pyb_usb_vcp_recv); // irq(handler=None, trigger=IRQ_RX, hard=False) -STATIC mp_obj_t pyb_usb_vcp_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t pyb_usb_vcp_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_handler, ARG_trigger, ARG_hard }; static const mp_arg_t allowed_args[] = { { MP_QSTR_handler, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, @@ -856,9 +856,9 @@ STATIC mp_obj_t pyb_usb_vcp_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_ return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_vcp_irq_obj, 1, pyb_usb_vcp_irq); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_vcp_irq_obj, 1, pyb_usb_vcp_irq); -STATIC const mp_rom_map_elem_t pyb_usb_vcp_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_usb_vcp_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_usb_vcp_init_obj) }, { MP_ROM_QSTR(MP_QSTR_setinterrupt), MP_ROM_PTR(&pyb_usb_vcp_setinterrupt_obj) }, { MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&pyb_usb_vcp_isconnected_obj) }, @@ -882,9 +882,9 @@ STATIC const mp_rom_map_elem_t pyb_usb_vcp_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_IRQ_RX), MP_ROM_INT(USBD_CDC_IRQ_RX) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_usb_vcp_locals_dict, pyb_usb_vcp_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_usb_vcp_locals_dict, pyb_usb_vcp_locals_dict_table); -STATIC mp_uint_t pyb_usb_vcp_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t pyb_usb_vcp_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(self_in); int ret = usbd_cdc_rx(self->cdc_itf, (byte *)buf, size, 0); if (ret == 0) { @@ -895,7 +895,7 @@ STATIC mp_uint_t pyb_usb_vcp_read(mp_obj_t self_in, void *buf, mp_uint_t size, i return ret; } -STATIC mp_uint_t pyb_usb_vcp_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t pyb_usb_vcp_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(self_in); int ret = usbd_cdc_tx_flow(self->cdc_itf, (const byte *)buf, size); if (ret == 0) { @@ -906,7 +906,7 @@ STATIC mp_uint_t pyb_usb_vcp_write(mp_obj_t self_in, const void *buf, mp_uint_t return ret; } -STATIC mp_uint_t pyb_usb_vcp_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t pyb_usb_vcp_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { mp_uint_t ret; pyb_usb_vcp_obj_t *self = MP_OBJ_TO_PTR(self_in); if (request == MP_STREAM_POLL) { @@ -927,7 +927,7 @@ STATIC mp_uint_t pyb_usb_vcp_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_ return ret; } -STATIC const mp_stream_p_t pyb_usb_vcp_stream_p = { +static const mp_stream_p_t pyb_usb_vcp_stream_p = { .read = pyb_usb_vcp_read, .write = pyb_usb_vcp_write, .ioctl = pyb_usb_vcp_ioctl, @@ -953,9 +953,9 @@ typedef struct _pyb_usb_hid_obj_t { usb_device_t *usb_dev; } pyb_usb_hid_obj_t; -STATIC const pyb_usb_hid_obj_t pyb_usb_hid_obj = {{&pyb_usb_hid_type}, &usb_device}; +static const pyb_usb_hid_obj_t pyb_usb_hid_obj = {{&pyb_usb_hid_type}, &usb_device}; -STATIC mp_obj_t pyb_usb_hid_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pyb_usb_hid_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 0, 0, false); @@ -975,7 +975,7 @@ STATIC mp_obj_t pyb_usb_hid_make_new(const mp_obj_type_t *type, size_t n_args, s /// /// Return value: if `data` is an integer then a new buffer of the bytes received, /// otherwise the number of bytes read into `data` is returned. -STATIC mp_obj_t pyb_usb_hid_recv(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t pyb_usb_hid_recv(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 5000} }, @@ -1006,9 +1006,9 @@ STATIC mp_obj_t pyb_usb_hid_recv(size_t n_args, const mp_obj_t *args, mp_map_t * return mp_obj_new_bytes_from_vstr(&vstr); // create a new buffer } } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_hid_recv_obj, 1, pyb_usb_hid_recv); +static MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_hid_recv_obj, 1, pyb_usb_hid_recv); -STATIC mp_obj_t pyb_usb_hid_send(mp_obj_t self_in, mp_obj_t report_in) { +static mp_obj_t pyb_usb_hid_send(mp_obj_t self_in, mp_obj_t report_in) { pyb_usb_hid_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_buffer_info_t bufinfo; byte temp_buf[8]; @@ -1035,22 +1035,22 @@ STATIC mp_obj_t pyb_usb_hid_send(mp_obj_t self_in, mp_obj_t report_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_usb_hid_send_obj, pyb_usb_hid_send); +static MP_DEFINE_CONST_FUN_OBJ_2(pyb_usb_hid_send_obj, pyb_usb_hid_send); // deprecated in favour of USB_HID.send -STATIC mp_obj_t pyb_hid_send_report(mp_obj_t arg) { +static mp_obj_t pyb_hid_send_report(mp_obj_t arg) { return pyb_usb_hid_send(MP_OBJ_FROM_PTR(&pyb_usb_hid_obj), arg); } MP_DEFINE_CONST_FUN_OBJ_1(pyb_hid_send_report_obj, pyb_hid_send_report); -STATIC const mp_rom_map_elem_t pyb_usb_hid_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_usb_hid_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&pyb_usb_hid_send_obj) }, { MP_ROM_QSTR(MP_QSTR_recv), MP_ROM_PTR(&pyb_usb_hid_recv_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_usb_hid_locals_dict, pyb_usb_hid_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_usb_hid_locals_dict, pyb_usb_hid_locals_dict_table); -STATIC mp_uint_t pyb_usb_hid_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t pyb_usb_hid_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { pyb_usb_hid_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_uint_t ret; if (request == MP_STREAM_POLL) { @@ -1069,7 +1069,7 @@ STATIC mp_uint_t pyb_usb_hid_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_ return ret; } -STATIC const mp_stream_p_t pyb_usb_hid_stream_p = { +static const mp_stream_p_t pyb_usb_hid_stream_p = { .ioctl = pyb_usb_hid_ioctl, }; diff --git a/ports/stm32/usbd_cdc_interface.c b/ports/stm32/usbd_cdc_interface.c index 20d8b3036dc1f..88a9cafe0c495 100644 --- a/ports/stm32/usbd_cdc_interface.c +++ b/ports/stm32/usbd_cdc_interface.c @@ -75,7 +75,7 @@ static uint8_t usbd_cdc_connect_tx_timer; #if MICROPY_HW_USB_CDC_1200BPS_TOUCH static mp_sched_node_t mp_bootloader_sched_node; -STATIC void usbd_cdc_run_bootloader_task(mp_sched_node_t *node) { +static void usbd_cdc_run_bootloader_task(mp_sched_node_t *node) { mp_hal_delay_ms(250); machine_bootloader(0, NULL); } diff --git a/ports/stm32/usbd_desc.c b/ports/stm32/usbd_desc.c index db94fd2be8986..340d317c547f9 100644 --- a/ports/stm32/usbd_desc.c +++ b/ports/stm32/usbd_desc.c @@ -86,7 +86,7 @@ void USBD_SetVIDPIDRelease(usbd_cdc_msc_hid_state_t *usbd, uint16_t vid, uint16_ * @param length: Pointer to data length variable * @retval Pointer to descriptor buffer */ -STATIC uint8_t *USBD_DeviceDescriptor(USBD_HandleTypeDef *pdev, uint16_t *length) { +static uint8_t *USBD_DeviceDescriptor(USBD_HandleTypeDef *pdev, uint16_t *length) { uint8_t *dev_desc = ((usbd_cdc_msc_hid_state_t *)pdev->pClassData)->usbd_device_desc; *length = USB_LEN_DEV_DESC; return dev_desc; @@ -98,7 +98,7 @@ STATIC uint8_t *USBD_DeviceDescriptor(USBD_HandleTypeDef *pdev, uint16_t *length * @param length: Pointer to data length variable * @retval Pointer to descriptor buffer, or NULL if idx is invalid */ -STATIC uint8_t *USBD_StrDescriptor(USBD_HandleTypeDef *pdev, uint8_t idx, uint16_t *length) { +static uint8_t *USBD_StrDescriptor(USBD_HandleTypeDef *pdev, uint8_t idx, uint16_t *length) { char str_buf[16]; const char *str = NULL; diff --git a/ports/stm32/usbd_msc_interface.c b/ports/stm32/usbd_msc_interface.c index a294a295b3eb4..68236e5c51205 100644 --- a/ports/stm32/usbd_msc_interface.c +++ b/ports/stm32/usbd_msc_interface.c @@ -41,9 +41,9 @@ #define FLAGS_READONLY (0x02) -STATIC const void *usbd_msc_lu_data[USBD_MSC_MAX_LUN]; -STATIC uint8_t usbd_msc_lu_num; -STATIC uint16_t usbd_msc_lu_flags; +static const void *usbd_msc_lu_data[USBD_MSC_MAX_LUN]; +static uint8_t usbd_msc_lu_num; +static uint16_t usbd_msc_lu_flags; static inline void lu_flag_set(uint8_t lun, uint8_t flag) { usbd_msc_lu_flags |= flag << (lun * 2); @@ -75,7 +75,7 @@ const uint8_t USBD_MSC_Mode_Sense10_Data[8] = { 0x00, 0x00, // block descriptor length }; -STATIC const uint8_t usbd_msc_vpd00[6] = { +static const uint8_t usbd_msc_vpd00[6] = { 0x00, // peripheral qualifier; peripheral device type 0x00, // page code 0x00, // reserved @@ -84,13 +84,13 @@ STATIC const uint8_t usbd_msc_vpd00[6] = { 0x83, // page 0x83 supported }; -STATIC const uint8_t usbd_msc_vpd83[4] = { +static const uint8_t usbd_msc_vpd83[4] = { 0x00, // peripheral qualifier; peripheral device type 0x83, // page code 0x00, 0x00, // page length (additional bytes beyond this entry) }; -STATIC const int8_t usbd_msc_inquiry_data[STANDARD_INQUIRY_DATA_LEN] = \ +static const int8_t usbd_msc_inquiry_data[STANDARD_INQUIRY_DATA_LEN] = \ "\x00" // peripheral qualifier; peripheral device type "\x80" // 0x00 for a fixed drive, 0x80 for a removable drive "\x02" // version @@ -110,7 +110,7 @@ void usbd_msc_init_lu(size_t lu_n, const void *lu_data) { } // Helper function to perform an ioctl on a logical unit -STATIC int lu_ioctl(uint8_t lun, int op, uint32_t *data) { +static int lu_ioctl(uint8_t lun, int op, uint32_t *data) { if (lun >= usbd_msc_lu_num) { return -1; } @@ -165,7 +165,7 @@ STATIC int lu_ioctl(uint8_t lun, int op, uint32_t *data) { } // Initialise all logical units (it's only ever called once, with lun_in=0) -STATIC int8_t usbd_msc_Init(uint8_t lun_in) { +static int8_t usbd_msc_Init(uint8_t lun_in) { if (lun_in != 0) { return 0; } @@ -185,7 +185,7 @@ STATIC int8_t usbd_msc_Init(uint8_t lun_in) { } // Process SCSI INQUIRY command for the logical unit -STATIC int usbd_msc_Inquiry(uint8_t lun, const uint8_t *params, uint8_t *data_out) { +static int usbd_msc_Inquiry(uint8_t lun, const uint8_t *params, uint8_t *data_out) { if (params[1] & 1) { // EVPD set - return vital product data parameters uint8_t page_code = params[2]; @@ -234,7 +234,7 @@ STATIC int usbd_msc_Inquiry(uint8_t lun, const uint8_t *params, uint8_t *data_ou } // Get storage capacity of a logical unit -STATIC int8_t usbd_msc_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *block_size) { +static int8_t usbd_msc_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *block_size) { uint32_t block_size_u32 = 0; int res = lu_ioctl(lun, MP_BLOCKDEV_IOCTL_BLOCK_SIZE, &block_size_u32); if (res != 0) { @@ -245,7 +245,7 @@ STATIC int8_t usbd_msc_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *b } // Check if a logical unit is ready -STATIC int8_t usbd_msc_IsReady(uint8_t lun) { +static int8_t usbd_msc_IsReady(uint8_t lun) { if (lun >= usbd_msc_lu_num) { return -1; } @@ -253,7 +253,7 @@ STATIC int8_t usbd_msc_IsReady(uint8_t lun) { } // Check if a logical unit is write protected -STATIC int8_t usbd_msc_IsWriteProtected(uint8_t lun) { +static int8_t usbd_msc_IsWriteProtected(uint8_t lun) { if (lun >= usbd_msc_lu_num) { return -1; } @@ -261,7 +261,7 @@ STATIC int8_t usbd_msc_IsWriteProtected(uint8_t lun) { } // Start or stop a logical unit -STATIC int8_t usbd_msc_StartStopUnit(uint8_t lun, uint8_t started) { +static int8_t usbd_msc_StartStopUnit(uint8_t lun, uint8_t started) { if (lun >= usbd_msc_lu_num) { return -1; } @@ -274,14 +274,14 @@ STATIC int8_t usbd_msc_StartStopUnit(uint8_t lun, uint8_t started) { } // Prepare a logical unit for possible removal -STATIC int8_t usbd_msc_PreventAllowMediumRemoval(uint8_t lun, uint8_t param) { +static int8_t usbd_msc_PreventAllowMediumRemoval(uint8_t lun, uint8_t param) { uint32_t dummy; // Sync the logical unit so the device can be unplugged/turned off return lu_ioctl(lun, MP_BLOCKDEV_IOCTL_SYNC, &dummy); } // Read data from a logical unit -STATIC int8_t usbd_msc_Read(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) { +static int8_t usbd_msc_Read(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) { if (lun >= usbd_msc_lu_num) { return -1; } @@ -305,7 +305,7 @@ STATIC int8_t usbd_msc_Read(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16 } // Write data to a logical unit -STATIC int8_t usbd_msc_Write(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) { +static int8_t usbd_msc_Write(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) { if (lun >= usbd_msc_lu_num) { return -1; } @@ -329,7 +329,7 @@ STATIC int8_t usbd_msc_Write(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint1 } // Get the number of attached logical units -STATIC int8_t usbd_msc_GetMaxLun(void) { +static int8_t usbd_msc_GetMaxLun(void) { return usbd_msc_lu_num - 1; } diff --git a/ports/stm32/usrsw.c b/ports/stm32/usrsw.c index 170c01bd6d043..cbf4a36fb4828 100644 --- a/ports/stm32/usrsw.c +++ b/ports/stm32/usrsw.c @@ -68,7 +68,7 @@ typedef struct _pyb_switch_obj_t { mp_obj_base_t base; } pyb_switch_obj_t; -STATIC const pyb_switch_obj_t pyb_switch_obj = {{&pyb_switch_type}}; +static const pyb_switch_obj_t pyb_switch_obj = {{&pyb_switch_type}}; void pyb_switch_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { mp_print_str(print, "Switch()"); @@ -76,7 +76,7 @@ void pyb_switch_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t /// \classmethod \constructor() /// Create and return a switch object. -STATIC mp_obj_t pyb_switch_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t pyb_switch_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 0, 0, false); @@ -100,15 +100,15 @@ mp_obj_t pyb_switch_value(mp_obj_t self_in) { (void)self_in; return mp_obj_new_bool(switch_get()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_switch_value_obj, pyb_switch_value); +static MP_DEFINE_CONST_FUN_OBJ_1(pyb_switch_value_obj, pyb_switch_value); -STATIC mp_obj_t switch_callback(mp_obj_t line) { +static mp_obj_t switch_callback(mp_obj_t line) { if (MP_STATE_PORT(pyb_switch_callback) != mp_const_none) { mp_call_function_0(MP_STATE_PORT(pyb_switch_callback)); } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(switch_callback_obj, switch_callback); +static MP_DEFINE_CONST_FUN_OBJ_1(switch_callback_obj, switch_callback); /// \method callback(fun) /// Register the given function to be called when the switch is pressed down. @@ -125,14 +125,14 @@ mp_obj_t pyb_switch_callback(mp_obj_t self_in, mp_obj_t callback) { true); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_switch_callback_obj, pyb_switch_callback); +static MP_DEFINE_CONST_FUN_OBJ_2(pyb_switch_callback_obj, pyb_switch_callback); -STATIC const mp_rom_map_elem_t pyb_switch_locals_dict_table[] = { +static const mp_rom_map_elem_t pyb_switch_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&pyb_switch_value_obj) }, { MP_ROM_QSTR(MP_QSTR_callback), MP_ROM_PTR(&pyb_switch_callback_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(pyb_switch_locals_dict, pyb_switch_locals_dict_table); +static MP_DEFINE_CONST_DICT(pyb_switch_locals_dict, pyb_switch_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( pyb_switch_type, diff --git a/ports/unix/coverage.c b/ports/unix/coverage.c index 543af365c25e9..803f849535cbe 100644 --- a/ports/unix/coverage.c +++ b/ports/unix/coverage.c @@ -31,7 +31,7 @@ typedef struct _mp_obj_streamtest_t { int error_code; } mp_obj_streamtest_t; -STATIC mp_obj_t stest_set_buf(mp_obj_t o_in, mp_obj_t buf_in) { +static mp_obj_t stest_set_buf(mp_obj_t o_in, mp_obj_t buf_in) { mp_obj_streamtest_t *o = MP_OBJ_TO_PTR(o_in); mp_buffer_info_t bufinfo; mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ); @@ -41,16 +41,16 @@ STATIC mp_obj_t stest_set_buf(mp_obj_t o_in, mp_obj_t buf_in) { o->pos = 0; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(stest_set_buf_obj, stest_set_buf); +static MP_DEFINE_CONST_FUN_OBJ_2(stest_set_buf_obj, stest_set_buf); -STATIC mp_obj_t stest_set_error(mp_obj_t o_in, mp_obj_t err_in) { +static mp_obj_t stest_set_error(mp_obj_t o_in, mp_obj_t err_in) { mp_obj_streamtest_t *o = MP_OBJ_TO_PTR(o_in); o->error_code = mp_obj_get_int(err_in); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(stest_set_error_obj, stest_set_error); +static MP_DEFINE_CONST_FUN_OBJ_2(stest_set_error_obj, stest_set_error); -STATIC mp_uint_t stest_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t stest_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { mp_obj_streamtest_t *o = MP_OBJ_TO_PTR(o_in); if (o->pos < o->len) { if (size > o->len - o->pos) { @@ -67,7 +67,7 @@ STATIC mp_uint_t stest_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errco } } -STATIC mp_uint_t stest_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t stest_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) { mp_obj_streamtest_t *o = MP_OBJ_TO_PTR(o_in); (void)buf; (void)size; @@ -75,7 +75,7 @@ STATIC mp_uint_t stest_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int return MP_STREAM_ERROR; } -STATIC mp_uint_t stest_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t stest_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { mp_obj_streamtest_t *o = MP_OBJ_TO_PTR(o_in); (void)arg; (void)request; @@ -87,7 +87,7 @@ STATIC mp_uint_t stest_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, in return 0; } -STATIC const mp_rom_map_elem_t rawfile_locals_dict_table[] = { +static const mp_rom_map_elem_t rawfile_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_set_buf), MP_ROM_PTR(&stest_set_buf_obj) }, { MP_ROM_QSTR(MP_QSTR_set_error), MP_ROM_PTR(&stest_set_error_obj) }, { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, @@ -99,15 +99,15 @@ STATIC const mp_rom_map_elem_t rawfile_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&mp_stream_ioctl_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(rawfile_locals_dict, rawfile_locals_dict_table); +static MP_DEFINE_CONST_DICT(rawfile_locals_dict, rawfile_locals_dict_table); -STATIC const mp_stream_p_t fileio_stream_p = { +static const mp_stream_p_t fileio_stream_p = { .read = stest_read, .write = stest_write, .ioctl = stest_ioctl, }; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_stest_fileio, MP_QSTR_stest_fileio, MP_TYPE_FLAG_NONE, @@ -116,7 +116,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); // stream read returns non-blocking error -STATIC mp_uint_t stest_read2(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t stest_read2(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { (void)o_in; (void)buf; (void)size; @@ -124,19 +124,19 @@ STATIC mp_uint_t stest_read2(mp_obj_t o_in, void *buf, mp_uint_t size, int *errc return MP_STREAM_ERROR; } -STATIC const mp_rom_map_elem_t rawfile_locals_dict_table2[] = { +static const mp_rom_map_elem_t rawfile_locals_dict_table2[] = { { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(rawfile_locals_dict2, rawfile_locals_dict_table2); +static MP_DEFINE_CONST_DICT(rawfile_locals_dict2, rawfile_locals_dict_table2); -STATIC const mp_stream_p_t textio_stream_p2 = { +static const mp_stream_p_t textio_stream_p2 = { .read = stest_read2, .write = NULL, .is_text = true, }; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_stest_textio2, MP_QSTR_stest_textio2, MP_TYPE_FLAG_NONE, @@ -145,15 +145,15 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); // str/bytes objects without a valid hash -STATIC const mp_obj_str_t str_no_hash_obj = {{&mp_type_str}, 0, 10, (const byte *)"0123456789"}; -STATIC const mp_obj_str_t bytes_no_hash_obj = {{&mp_type_bytes}, 0, 10, (const byte *)"0123456789"}; +static const mp_obj_str_t str_no_hash_obj = {{&mp_type_str}, 0, 10, (const byte *)"0123456789"}; +static const mp_obj_str_t bytes_no_hash_obj = {{&mp_type_bytes}, 0, 10, (const byte *)"0123456789"}; -STATIC int pairheap_lt(mp_pairheap_t *a, mp_pairheap_t *b) { +static int pairheap_lt(mp_pairheap_t *a, mp_pairheap_t *b) { return (uintptr_t)a < (uintptr_t)b; } // ops array contain operations: x>=0 means push(x), x<0 means delete(-x) -STATIC void pairheap_test(size_t nops, int *ops) { +static void pairheap_test(size_t nops, int *ops) { mp_pairheap_t node[8]; for (size_t i = 0; i < MP_ARRAY_SIZE(node); ++i) { mp_pairheap_init_node(pairheap_lt, &node[i]); @@ -183,7 +183,7 @@ STATIC void pairheap_test(size_t nops, int *ops) { } // function to run extra tests for things that can't be checked by scripts -STATIC mp_obj_t extra_coverage(void) { +static mp_obj_t extra_coverage(void) { // mp_printf (used by ports that don't have a native printf) { mp_printf(&mp_plat_print, "# mp_printf\n"); diff --git a/ports/unix/coveragecpp.cpp b/ports/unix/coveragecpp.cpp index ea7418e1dd46a..93c1b387fe285 100644 --- a/ports/unix/coveragecpp.cpp +++ b/ports/unix/coveragecpp.cpp @@ -5,7 +5,7 @@ extern "C" { #if defined(MICROPY_UNIX_COVERAGE) // Just to test building of C++ code. -STATIC mp_obj_t extra_cpp_coverage_impl() { +static mp_obj_t extra_cpp_coverage_impl() { return mp_const_none; } diff --git a/ports/unix/main.c b/ports/unix/main.c index 468fc409640b3..0cf11d37cf8d9 100644 --- a/ports/unix/main.c +++ b/ports/unix/main.c @@ -55,8 +55,8 @@ #include "input.h" // Command line options, with their defaults -STATIC bool compile_only = false; -STATIC uint emit_opt = MP_EMIT_OPT_NONE; +static bool compile_only = false; +static uint emit_opt = MP_EMIT_OPT_NONE; #if MICROPY_ENABLE_GC // Heap size of GC heap (if enabled) @@ -77,7 +77,7 @@ long heap_size = 1024 * 1024 * (sizeof(mp_uint_t) / 4); #error "The unix port requires MICROPY_PY_SYS_ARGV=1" #endif -STATIC void stderr_print_strn(void *env, const char *str, size_t len) { +static void stderr_print_strn(void *env, const char *str, size_t len) { (void)env; ssize_t ret; MP_HAL_RETRY_SYSCALL(ret, write(STDERR_FILENO, str, len), {}); @@ -90,7 +90,7 @@ const mp_print_t mp_stderr_print = {NULL, stderr_print_strn}; // If exc is SystemExit, return value where FORCED_EXIT bit set, // and lower 8 bits are SystemExit value. For all other exceptions, // return 1. -STATIC int handle_uncaught_exception(mp_obj_base_t *exc) { +static int handle_uncaught_exception(mp_obj_base_t *exc) { // check for SystemExit if (mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(exc->type), MP_OBJ_FROM_PTR(&mp_type_SystemExit))) { // None is an exit value of 0; an int is its value; anything else is 1 @@ -115,7 +115,7 @@ STATIC int handle_uncaught_exception(mp_obj_base_t *exc) { // Returns standard error codes: 0 for success, 1 for all other errors, // except if FORCED_EXIT bit is set then script raised SystemExit and the // value of the exit is in the lower 8 bits of the return value -STATIC int execute_from_lexer(int source_kind, const void *source, mp_parse_input_kind_t input_kind, bool is_repl) { +static int execute_from_lexer(int source_kind, const void *source, mp_parse_input_kind_t input_kind, bool is_repl) { mp_hal_set_interrupt_char(CHAR_CTRL_C); nlr_buf_t nlr; @@ -177,7 +177,7 @@ STATIC int execute_from_lexer(int source_kind, const void *source, mp_parse_inpu #if MICROPY_USE_READLINE == 1 #include "shared/readline/readline.h" #else -STATIC char *strjoin(const char *s1, int sep_char, const char *s2) { +static char *strjoin(const char *s1, int sep_char, const char *s2) { int l1 = strlen(s1); int l2 = strlen(s2); char *s = malloc(l1 + l2 + 2); @@ -192,7 +192,7 @@ STATIC char *strjoin(const char *s1, int sep_char, const char *s2) { } #endif -STATIC int do_repl(void) { +static int do_repl(void) { mp_hal_stdout_tx_str(MICROPY_BANNER_NAME_AND_VERSION); mp_hal_stdout_tx_str("; " MICROPY_BANNER_MACHINE); mp_hal_stdout_tx_str("\nUse Ctrl-D to exit, Ctrl-E for paste mode\n"); @@ -306,15 +306,15 @@ STATIC int do_repl(void) { #endif } -STATIC int do_file(const char *file) { +static int do_file(const char *file) { return execute_from_lexer(LEX_SRC_FILENAME, file, MP_PARSE_FILE_INPUT, false); } -STATIC int do_str(const char *str) { +static int do_str(const char *str) { return execute_from_lexer(LEX_SRC_STR, str, MP_PARSE_FILE_INPUT, false); } -STATIC void print_help(char **argv) { +static void print_help(char **argv) { printf( "usage: %s [] [-X ] [-c | -m | ]\n" "Options:\n" @@ -353,13 +353,13 @@ STATIC void print_help(char **argv) { } } -STATIC int invalid_args(void) { +static int invalid_args(void) { fprintf(stderr, "Invalid command line arguments. Use -h option for help.\n"); return 1; } // Process options which set interpreter init options -STATIC void pre_process_options(int argc, char **argv) { +static void pre_process_options(int argc, char **argv) { for (int a = 1; a < argc; a++) { if (argv[a][0] == '-') { if (strcmp(argv[a], "-c") == 0 || strcmp(argv[a], "-m") == 0) { @@ -439,7 +439,7 @@ STATIC void pre_process_options(int argc, char **argv) { } } -STATIC void set_sys_argv(char *argv[], int argc, int start_arg) { +static void set_sys_argv(char *argv[], int argc, int start_arg) { for (int i = start_arg; i < argc; i++) { mp_obj_list_append(mp_sys_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i]))); } @@ -447,9 +447,9 @@ STATIC void set_sys_argv(char *argv[], int argc, int start_arg) { #if MICROPY_PY_SYS_EXECUTABLE extern mp_obj_str_t mp_sys_executable_obj; -STATIC char executable_path[MICROPY_ALLOC_PATH_MAX]; +static char executable_path[MICROPY_ALLOC_PATH_MAX]; -STATIC void sys_set_excecutable(char *argv0) { +static void sys_set_excecutable(char *argv0) { if (realpath(argv0, executable_path)) { mp_obj_str_set_data(&mp_sys_executable_obj, (byte *)executable_path, strlen(executable_path)); } diff --git a/ports/unix/modffi.c b/ports/unix/modffi.c index 897fa07ace1f3..b7d03e84dde6f 100644 --- a/ports/unix/modffi.c +++ b/ports/unix/modffi.c @@ -107,13 +107,13 @@ typedef struct _mp_obj_fficallback_t { ffi_type *params[]; } mp_obj_fficallback_t; -// STATIC const mp_obj_type_t opaque_type; -STATIC const mp_obj_type_t ffimod_type; -STATIC const mp_obj_type_t ffifunc_type; -STATIC const mp_obj_type_t fficallback_type; -STATIC const mp_obj_type_t ffivar_type; +// static const mp_obj_type_t opaque_type; +static const mp_obj_type_t ffimod_type; +static const mp_obj_type_t ffifunc_type; +static const mp_obj_type_t fficallback_type; +static const mp_obj_type_t ffivar_type; -STATIC ffi_type *char2ffi_type(char c) { +static ffi_type *char2ffi_type(char c) { switch (c) { case 'b': return &ffi_type_schar; @@ -154,7 +154,7 @@ STATIC ffi_type *char2ffi_type(char c) { } } -STATIC ffi_type *get_ffi_type(mp_obj_t o_in) { +static ffi_type *get_ffi_type(mp_obj_t o_in) { if (mp_obj_is_str(o_in)) { const char *s = mp_obj_str_get_str(o_in); ffi_type *t = char2ffi_type(*s); @@ -167,7 +167,7 @@ STATIC ffi_type *get_ffi_type(mp_obj_t o_in) { mp_raise_TypeError(MP_ERROR_TEXT("unknown type")); } -STATIC mp_obj_t return_ffi_value(ffi_union_t *val, char type) { +static mp_obj_t return_ffi_value(ffi_union_t *val, char type) { switch (type) { case 's': { const char *s = (const char *)(intptr_t)val->ffi; @@ -209,20 +209,20 @@ STATIC mp_obj_t return_ffi_value(ffi_union_t *val, char type) { // FFI module -STATIC void ffimod_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void ffimod_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_ffimod_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", self->handle); } -STATIC mp_obj_t ffimod_close(mp_obj_t self_in) { +static mp_obj_t ffimod_close(mp_obj_t self_in) { mp_obj_ffimod_t *self = MP_OBJ_TO_PTR(self_in); dlclose(self->handle); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(ffimod_close_obj, ffimod_close); +static MP_DEFINE_CONST_FUN_OBJ_1(ffimod_close_obj, ffimod_close); -STATIC mp_obj_t make_func(mp_obj_t rettype_in, void *func, mp_obj_t argtypes_in) { +static mp_obj_t make_func(mp_obj_t rettype_in, void *func, mp_obj_t argtypes_in) { const char *rettype = mp_obj_str_get_str(rettype_in); const char *argtypes = mp_obj_str_get_str(argtypes_in); @@ -249,7 +249,7 @@ STATIC mp_obj_t make_func(mp_obj_t rettype_in, void *func, mp_obj_t argtypes_in) return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t ffimod_func(size_t n_args, const mp_obj_t *args) { +static mp_obj_t ffimod_func(size_t n_args, const mp_obj_t *args) { (void)n_args; // always 4 mp_obj_ffimod_t *self = MP_OBJ_TO_PTR(args[0]); const char *symname = mp_obj_str_get_str(args[2]); @@ -262,13 +262,13 @@ STATIC mp_obj_t ffimod_func(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ffimod_func_obj, 4, 4, ffimod_func); -STATIC mp_obj_t mod_ffi_func(mp_obj_t rettype, mp_obj_t addr_in, mp_obj_t argtypes) { +static mp_obj_t mod_ffi_func(mp_obj_t rettype, mp_obj_t addr_in, mp_obj_t argtypes) { void *addr = (void *)MP_OBJ_TO_PTR(mp_obj_int_get_truncated(addr_in)); return make_func(rettype, addr, argtypes); } MP_DEFINE_CONST_FUN_OBJ_3(mod_ffi_func_obj, mod_ffi_func); -STATIC void call_py_func(ffi_cif *cif, void *ret, void **args, void *user_data) { +static void call_py_func(ffi_cif *cif, void *ret, void **args, void *user_data) { mp_obj_t pyargs[cif->nargs]; mp_obj_fficallback_t *o = user_data; mp_obj_t pyfunc = o->pyfunc; @@ -283,7 +283,7 @@ STATIC void call_py_func(ffi_cif *cif, void *ret, void **args, void *user_data) } } -STATIC void call_py_func_with_lock(ffi_cif *cif, void *ret, void **args, void *user_data) { +static void call_py_func_with_lock(ffi_cif *cif, void *ret, void **args, void *user_data) { mp_obj_t pyargs[cif->nargs]; mp_obj_fficallback_t *o = user_data; mp_obj_t pyfunc = o->pyfunc; @@ -316,7 +316,7 @@ STATIC void call_py_func_with_lock(ffi_cif *cif, void *ret, void **args, void *u #endif } -STATIC mp_obj_t mod_ffi_callback(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t mod_ffi_callback(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // first 3 args are positional: retttype, func, paramtypes. mp_obj_t rettype_in = pos_args[0]; mp_obj_t func_in = pos_args[1]; @@ -364,7 +364,7 @@ STATIC mp_obj_t mod_ffi_callback(size_t n_args, const mp_obj_t *pos_args, mp_map } MP_DEFINE_CONST_FUN_OBJ_KW(mod_ffi_callback_obj, 3, mod_ffi_callback); -STATIC mp_obj_t ffimod_var(mp_obj_t self_in, mp_obj_t vartype_in, mp_obj_t symname_in) { +static mp_obj_t ffimod_var(mp_obj_t self_in, mp_obj_t vartype_in, mp_obj_t symname_in) { mp_obj_ffimod_t *self = MP_OBJ_TO_PTR(self_in); const char *rettype = mp_obj_str_get_str(vartype_in); const char *symname = mp_obj_str_get_str(symname_in); @@ -381,7 +381,7 @@ STATIC mp_obj_t ffimod_var(mp_obj_t self_in, mp_obj_t vartype_in, mp_obj_t symna } MP_DEFINE_CONST_FUN_OBJ_3(ffimod_var_obj, ffimod_var); -STATIC mp_obj_t ffimod_addr(mp_obj_t self_in, mp_obj_t symname_in) { +static mp_obj_t ffimod_addr(mp_obj_t self_in, mp_obj_t symname_in) { mp_obj_ffimod_t *self = MP_OBJ_TO_PTR(self_in); const char *symname = mp_obj_str_get_str(symname_in); @@ -393,7 +393,7 @@ STATIC mp_obj_t ffimod_addr(mp_obj_t self_in, mp_obj_t symname_in) { } MP_DEFINE_CONST_FUN_OBJ_2(ffimod_addr_obj, ffimod_addr); -STATIC mp_obj_t ffimod_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t ffimod_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)n_args; (void)n_kw; @@ -411,16 +411,16 @@ STATIC mp_obj_t ffimod_make_new(const mp_obj_type_t *type, size_t n_args, size_t return MP_OBJ_FROM_PTR(o); } -STATIC const mp_rom_map_elem_t ffimod_locals_dict_table[] = { +static const mp_rom_map_elem_t ffimod_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_func), MP_ROM_PTR(&ffimod_func_obj) }, { MP_ROM_QSTR(MP_QSTR_var), MP_ROM_PTR(&ffimod_var_obj) }, { MP_ROM_QSTR(MP_QSTR_addr), MP_ROM_PTR(&ffimod_addr_obj) }, { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&ffimod_close_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(ffimod_locals_dict, ffimod_locals_dict_table); +static MP_DEFINE_CONST_DICT(ffimod_locals_dict, ffimod_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( ffimod_type, MP_QSTR_ffimod, MP_TYPE_FLAG_NONE, @@ -431,13 +431,13 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( // FFI function -STATIC void ffifunc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void ffifunc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_ffifunc_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", self->func); } -STATIC unsigned long long ffi_get_int_value(mp_obj_t o) { +static unsigned long long ffi_get_int_value(mp_obj_t o) { if (mp_obj_is_small_int(o)) { return MP_OBJ_SMALL_INT_VALUE(o); } else { @@ -447,7 +447,7 @@ STATIC unsigned long long ffi_get_int_value(mp_obj_t o) { } } -STATIC ffi_union_t ffi_int_obj_to_ffi_union(mp_obj_t o, const char argtype) { +static ffi_union_t ffi_int_obj_to_ffi_union(mp_obj_t o, const char argtype) { ffi_union_t ret; if ((argtype | 0x20) == 'q') { ret.Q = ffi_get_int_value(o); @@ -479,7 +479,7 @@ STATIC ffi_union_t ffi_int_obj_to_ffi_union(mp_obj_t o, const char argtype) { return ret; } -STATIC mp_obj_t ffifunc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t ffifunc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)n_kw; mp_obj_ffifunc_t *self = MP_OBJ_TO_PTR(self_in); assert(n_kw == 0); @@ -530,7 +530,7 @@ STATIC mp_obj_t ffifunc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_raise_TypeError(MP_ERROR_TEXT("don't know how to pass object to native function")); } -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( ffifunc_type, MP_QSTR_ffifunc, MP_TYPE_FLAG_NONE, @@ -540,24 +540,24 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( // FFI callback for Python function -STATIC void fficallback_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void fficallback_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_fficallback_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", self->func); } -STATIC mp_obj_t fficallback_cfun(mp_obj_t self_in) { +static mp_obj_t fficallback_cfun(mp_obj_t self_in) { mp_obj_fficallback_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_int_from_ull((uintptr_t)self->func); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(fficallback_cfun_obj, fficallback_cfun); +static MP_DEFINE_CONST_FUN_OBJ_1(fficallback_cfun_obj, fficallback_cfun); -STATIC const mp_rom_map_elem_t fficallback_locals_dict_table[] = { +static const mp_rom_map_elem_t fficallback_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_cfun), MP_ROM_PTR(&fficallback_cfun_obj) } }; -STATIC MP_DEFINE_CONST_DICT(fficallback_locals_dict, fficallback_locals_dict_table); +static MP_DEFINE_CONST_DICT(fficallback_locals_dict, fficallback_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( fficallback_type, MP_QSTR_fficallback, MP_TYPE_FLAG_NONE, @@ -567,34 +567,34 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( // FFI variable -STATIC void ffivar_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void ffivar_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_ffivar_t *self = MP_OBJ_TO_PTR(self_in); // Variable value printed as cast to int mp_printf(print, "", self->var, *(int *)self->var); } -STATIC mp_obj_t ffivar_get(mp_obj_t self_in) { +static mp_obj_t ffivar_get(mp_obj_t self_in) { mp_obj_ffivar_t *self = MP_OBJ_TO_PTR(self_in); return mp_binary_get_val_array(self->type, self->var, 0); } MP_DEFINE_CONST_FUN_OBJ_1(ffivar_get_obj, ffivar_get); -STATIC mp_obj_t ffivar_set(mp_obj_t self_in, mp_obj_t val_in) { +static mp_obj_t ffivar_set(mp_obj_t self_in, mp_obj_t val_in) { mp_obj_ffivar_t *self = MP_OBJ_TO_PTR(self_in); mp_binary_set_val_array(self->type, self->var, 0, val_in); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_2(ffivar_set_obj, ffivar_set); -STATIC const mp_rom_map_elem_t ffivar_locals_dict_table[] = { +static const mp_rom_map_elem_t ffivar_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_get), MP_ROM_PTR(&ffivar_get_obj) }, { MP_ROM_QSTR(MP_QSTR_set), MP_ROM_PTR(&ffivar_set_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(ffivar_locals_dict, ffivar_locals_dict_table); +static MP_DEFINE_CONST_DICT(ffivar_locals_dict, ffivar_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( ffivar_type, MP_QSTR_ffivar, MP_TYPE_FLAG_NONE, @@ -605,7 +605,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( // Generic opaque storage object (unused) /* -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( opaque_type, MP_QSTR_opaqueval, MP_TYPE_FLAG_NONE, @@ -613,17 +613,17 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); */ -STATIC mp_obj_t mod_ffi_open(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_ffi_open(size_t n_args, const mp_obj_t *args) { return ffimod_make_new(&ffimod_type, n_args, 0, args); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_ffi_open_obj, 1, 2, mod_ffi_open); -STATIC mp_obj_t mod_ffi_as_bytearray(mp_obj_t ptr, mp_obj_t size) { +static mp_obj_t mod_ffi_as_bytearray(mp_obj_t ptr, mp_obj_t size) { return mp_obj_new_bytearray_by_ref(mp_obj_int_get_truncated(size), (void *)(uintptr_t)mp_obj_int_get_truncated(ptr)); } MP_DEFINE_CONST_FUN_OBJ_2(mod_ffi_as_bytearray_obj, mod_ffi_as_bytearray); -STATIC const mp_rom_map_elem_t mp_module_ffi_globals_table[] = { +static const mp_rom_map_elem_t mp_module_ffi_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ffi) }, { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mod_ffi_open_obj) }, { MP_ROM_QSTR(MP_QSTR_callback), MP_ROM_PTR(&mod_ffi_callback_obj) }, @@ -631,7 +631,7 @@ STATIC const mp_rom_map_elem_t mp_module_ffi_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_as_bytearray), MP_ROM_PTR(&mod_ffi_as_bytearray_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_ffi_globals, mp_module_ffi_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_ffi_globals, mp_module_ffi_globals_table); const mp_obj_module_t mp_module_ffi = { .base = { &mp_type_module }, diff --git a/ports/unix/modjni.c b/ports/unix/modjni.c index a1cfca81495f4..d953e7e015237 100644 --- a/ports/unix/modjni.c +++ b/ports/unix/modjni.c @@ -59,13 +59,13 @@ static jmethodID List_size_mid; static jclass IndexException_class; -STATIC const mp_obj_type_t jobject_type; -STATIC const mp_obj_type_t jmethod_type; +static const mp_obj_type_t jobject_type; +static const mp_obj_type_t jmethod_type; -STATIC mp_obj_t new_jobject(jobject jo); -STATIC mp_obj_t new_jclass(jclass jc); -STATIC mp_obj_t call_method(jobject obj, const char *name, jarray methods, bool is_constr, size_t n_args, const mp_obj_t *args); -STATIC bool py2jvalue(const char **jtypesig, mp_obj_t arg, jvalue *out); +static mp_obj_t new_jobject(jobject jo); +static mp_obj_t new_jclass(jclass jc); +static mp_obj_t call_method(jobject obj, const char *name, jarray methods, bool is_constr, size_t n_args, const mp_obj_t *args); +static bool py2jvalue(const char **jtypesig, mp_obj_t arg, jvalue *out); typedef struct _mp_obj_jclass_t { mp_obj_base_t base; @@ -87,7 +87,7 @@ typedef struct _mp_obj_jmethod_t { // Utility functions -STATIC bool is_object_type(const char *jtypesig) { +static bool is_object_type(const char *jtypesig) { while (*jtypesig != ' ' && *jtypesig) { if (*jtypesig == '.') { return true; @@ -97,7 +97,7 @@ STATIC bool is_object_type(const char *jtypesig) { return false; } -STATIC void check_exception(void) { +static void check_exception(void) { jobject exc = JJ1(ExceptionOccurred); if (exc) { // JJ1(ExceptionDescribe); @@ -110,7 +110,7 @@ STATIC void check_exception(void) { } } -STATIC void print_jobject(const mp_print_t *print, jobject obj) { +static void print_jobject(const mp_print_t *print, jobject obj) { jobject str_o = JJ(CallObjectMethod, obj, Object_toString_mid); const char *str = JJ(GetStringUTFChars, str_o, NULL); mp_printf(print, str); @@ -119,7 +119,7 @@ STATIC void print_jobject(const mp_print_t *print, jobject obj) { // jclass -STATIC void jclass_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void jclass_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { mp_obj_jclass_t *self = MP_OBJ_TO_PTR(self_in); if (kind == PRINT_REPR) { mp_printf(print, "cls); @@ -130,7 +130,7 @@ STATIC void jclass_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kin } } -STATIC void jclass_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) { +static void jclass_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) { if (dest[0] == MP_OBJ_NULL) { // load attribute mp_obj_jclass_t *self = MP_OBJ_TO_PTR(self_in); @@ -156,7 +156,7 @@ STATIC void jclass_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) { } } -STATIC mp_obj_t jclass_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t jclass_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { if (n_kw != 0) { mp_raise_TypeError(MP_ERROR_TEXT("kwargs not supported")); } @@ -167,14 +167,14 @@ STATIC mp_obj_t jclass_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const return call_method(self->cls, NULL, methods, true, n_args, args); } -STATIC const mp_rom_map_elem_t jclass_locals_dict_table[] = { +static const mp_rom_map_elem_t jclass_locals_dict_table[] = { // { MP_ROM_QSTR(MP_QSTR_get), MP_ROM_PTR(&ffivar_get_obj) }, // { MP_ROM_QSTR(MP_QSTR_set), MP_ROM_PTR(&ffivar_set_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(jclass_locals_dict, jclass_locals_dict_table); +static MP_DEFINE_CONST_DICT(jclass_locals_dict, jclass_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( jclass_type, MP_QSTR_jclass, MP_TYPE_FLAG_NONE, @@ -184,7 +184,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &jclass_locals_dict ); -STATIC mp_obj_t new_jclass(jclass jc) { +static mp_obj_t new_jclass(jclass jc) { mp_obj_jclass_t *o = mp_obj_malloc(mp_obj_jclass_t, &jclass_type); o->cls = jc; return MP_OBJ_FROM_PTR(o); @@ -192,7 +192,7 @@ STATIC mp_obj_t new_jclass(jclass jc) { // jobject -STATIC void jobject_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void jobject_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { mp_obj_jobject_t *self = MP_OBJ_TO_PTR(self_in); if (kind == PRINT_REPR) { mp_printf(print, "obj); @@ -203,7 +203,7 @@ STATIC void jobject_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki } } -STATIC void jobject_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) { +static void jobject_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) { if (dest[0] == MP_OBJ_NULL) { // load attribute mp_obj_jobject_t *self = MP_OBJ_TO_PTR(self_in); @@ -233,7 +233,7 @@ STATIC void jobject_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) { } } -STATIC void get_jclass_name(jobject obj, char *buf) { +static void get_jclass_name(jobject obj, char *buf) { jclass obj_class = JJ(GetObjectClass, obj); jstring name = JJ(CallObjectMethod, obj_class, Class_getName_mid); jint len = JJ(GetStringLength, name); @@ -241,7 +241,7 @@ STATIC void get_jclass_name(jobject obj, char *buf) { check_exception(); } -STATIC mp_obj_t jobject_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { +static mp_obj_t jobject_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { mp_obj_jobject_t *self = MP_OBJ_TO_PTR(self_in); mp_uint_t idx = mp_obj_get_int(index); char class_name[64]; @@ -291,7 +291,7 @@ STATIC mp_obj_t jobject_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) return MP_OBJ_NULL; } -STATIC mp_obj_t jobject_unary_op(mp_unary_op_t op, mp_obj_t self_in) { +static mp_obj_t jobject_unary_op(mp_unary_op_t op, mp_obj_t self_in) { mp_obj_jobject_t *self = MP_OBJ_TO_PTR(self_in); switch (op) { case MP_UNARY_OP_BOOL: @@ -309,19 +309,19 @@ STATIC mp_obj_t jobject_unary_op(mp_unary_op_t op, mp_obj_t self_in) { // TODO: subscr_load_adaptor & subscr_getiter convenience functions // should be moved to common location for reuse. -STATIC mp_obj_t subscr_load_adaptor(mp_obj_t self_in, mp_obj_t index_in) { +static mp_obj_t subscr_load_adaptor(mp_obj_t self_in, mp_obj_t index_in) { return mp_obj_subscr(self_in, index_in, MP_OBJ_SENTINEL); } MP_DEFINE_CONST_FUN_OBJ_2(subscr_load_adaptor_obj, subscr_load_adaptor); // .getiter special method which returns iterator which works in terms // of object subscription. -STATIC mp_obj_t subscr_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t subscr_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { mp_obj_t dest[2] = {MP_OBJ_FROM_PTR(&subscr_load_adaptor_obj), self_in}; return mp_obj_new_getitem_iter(dest, iter_buf); } -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( jobject_type, MP_QSTR_jobject, MP_TYPE_FLAG_ITER_IS_GETITER, @@ -332,7 +332,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( iter, subscr_getiter ); -STATIC mp_obj_t new_jobject(jobject jo) { +static mp_obj_t new_jobject(jobject jo) { if (jo == NULL) { return mp_const_none; } else if (JJ(IsInstanceOf, jo, String_class)) { @@ -353,7 +353,7 @@ STATIC mp_obj_t new_jobject(jobject jo) { // jmethod -STATIC void jmethod_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void jmethod_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_jmethod_t *self = MP_OBJ_TO_PTR(self_in); // Variable value printed as cast to int @@ -368,14 +368,14 @@ STATIC void jmethod_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki } \ arg_type += sizeof(java_type_name) - 1; -STATIC const char *strprev(const char *s, char c) { +static const char *strprev(const char *s, char c) { while (*s != c) { s--; } return s; } -STATIC bool py2jvalue(const char **jtypesig, mp_obj_t arg, jvalue *out) { +static bool py2jvalue(const char **jtypesig, mp_obj_t arg, jvalue *out) { const char *arg_type = *jtypesig; const mp_obj_type_t *type = mp_obj_get_type(arg); @@ -442,7 +442,7 @@ STATIC bool py2jvalue(const char **jtypesig, mp_obj_t arg, jvalue *out) { // perspective, it's aggregate object which may require passing via stack // instead of registers. Work that around by passing jobject and typecasting // it. -STATIC mp_obj_t jvalue2py(const char *jtypesig, jobject arg) { +static mp_obj_t jvalue2py(const char *jtypesig, jobject arg) { if (arg == NULL || MATCH(jtypesig, "void")) { return mp_const_none; } else if (MATCH(jtypesig, "boolean")) { @@ -460,7 +460,7 @@ STATIC mp_obj_t jvalue2py(const char *jtypesig, jobject arg) { } #endif -STATIC mp_obj_t call_method(jobject obj, const char *name, jarray methods, bool is_constr, size_t n_args, const mp_obj_t *args) { +static mp_obj_t call_method(jobject obj, const char *name, jarray methods, bool is_constr, size_t n_args, const mp_obj_t *args) { jvalue jargs[n_args]; // printf("methods=%p\n", methods); jsize num_methods = JJ(GetArrayLength, methods); @@ -550,7 +550,7 @@ STATIC mp_obj_t call_method(jobject obj, const char *name, jarray methods, bool } -STATIC mp_obj_t jmethod_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t jmethod_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { if (n_kw != 0) { mp_raise_TypeError(MP_ERROR_TEXT("kwargs not supported")); } @@ -568,7 +568,7 @@ STATIC mp_obj_t jmethod_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const return call_method(self->obj, name, methods, false, n_args, args); } -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( jmethod_type, MP_QSTR_jmethod, MP_TYPE_FLAG_NONE, @@ -582,7 +582,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( #define LIBJVM_SO "libjvm.so" #endif -STATIC void create_jvm(void) { +static void create_jvm(void) { JavaVMInitArgs args; JavaVMOption options; options.optionString = "-Djava.class.path=."; @@ -635,7 +635,7 @@ STATIC void create_jvm(void) { IndexException_class = JJ(FindClass, "java/lang/IndexOutOfBoundsException"); } -STATIC mp_obj_t mod_jni_cls(mp_obj_t cls_name_in) { +static mp_obj_t mod_jni_cls(mp_obj_t cls_name_in) { const char *cls_name = mp_obj_str_get_str(cls_name_in); if (!env) { create_jvm(); @@ -648,7 +648,7 @@ STATIC mp_obj_t mod_jni_cls(mp_obj_t cls_name_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mod_jni_cls_obj, mod_jni_cls); -STATIC mp_obj_t mod_jni_array(mp_obj_t type_in, mp_obj_t size_in) { +static mp_obj_t mod_jni_array(mp_obj_t type_in, mp_obj_t size_in) { if (!env) { create_jvm(); } @@ -696,19 +696,19 @@ STATIC mp_obj_t mod_jni_array(mp_obj_t type_in, mp_obj_t size_in) { MP_DEFINE_CONST_FUN_OBJ_2(mod_jni_array_obj, mod_jni_array); -STATIC mp_obj_t mod_jni_env(void) { +static mp_obj_t mod_jni_env(void) { return mp_obj_new_int((mp_int_t)(uintptr_t)env); } MP_DEFINE_CONST_FUN_OBJ_0(mod_jni_env_obj, mod_jni_env); -STATIC const mp_rom_map_elem_t mp_module_jni_globals_table[] = { +static const mp_rom_map_elem_t mp_module_jni_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_jni) }, { MP_ROM_QSTR(MP_QSTR_cls), MP_ROM_PTR(&mod_jni_cls_obj) }, { MP_ROM_QSTR(MP_QSTR_array), MP_ROM_PTR(&mod_jni_array_obj) }, { MP_ROM_QSTR(MP_QSTR_env), MP_ROM_PTR(&mod_jni_env_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_jni_globals, mp_module_jni_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_jni_globals, mp_module_jni_globals_table); const mp_obj_module_t mp_module_jni = { .base = { &mp_type_module }, diff --git a/ports/unix/modmachine.c b/ports/unix/modmachine.c index 40d08d9111422..6f3ab80944061 100644 --- a/ports/unix/modmachine.c +++ b/ports/unix/modmachine.c @@ -70,7 +70,7 @@ uintptr_t mod_machine_mem_get_addr(mp_obj_t addr_o, uint align) { return addr; } -STATIC void mp_machine_idle(void) { +static void mp_machine_idle(void) { #ifdef MICROPY_UNIX_MACHINE_IDLE MICROPY_UNIX_MACHINE_IDLE #else diff --git a/ports/unix/modos.c b/ports/unix/modos.c index 1d5e2afef4ad9..d5e963583b7a4 100644 --- a/ports/unix/modos.c +++ b/ports/unix/modos.c @@ -32,7 +32,7 @@ #include "py/runtime.h" #include "py/mphal.h" -STATIC mp_obj_t mp_os_getenv(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_os_getenv(size_t n_args, const mp_obj_t *args) { const char *s = getenv(mp_obj_str_get_str(args[0])); if (s == NULL) { if (n_args == 2) { @@ -42,9 +42,9 @@ STATIC mp_obj_t mp_os_getenv(size_t n_args, const mp_obj_t *args) { } return mp_obj_new_str(s, strlen(s)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_os_getenv_obj, 1, 2, mp_os_getenv); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_os_getenv_obj, 1, 2, mp_os_getenv); -STATIC mp_obj_t mp_os_putenv(mp_obj_t key_in, mp_obj_t value_in) { +static mp_obj_t mp_os_putenv(mp_obj_t key_in, mp_obj_t value_in) { const char *key = mp_obj_str_get_str(key_in); const char *value = mp_obj_str_get_str(value_in); int ret; @@ -60,9 +60,9 @@ STATIC mp_obj_t mp_os_putenv(mp_obj_t key_in, mp_obj_t value_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_os_putenv_obj, mp_os_putenv); +static MP_DEFINE_CONST_FUN_OBJ_2(mp_os_putenv_obj, mp_os_putenv); -STATIC mp_obj_t mp_os_unsetenv(mp_obj_t key_in) { +static mp_obj_t mp_os_unsetenv(mp_obj_t key_in) { const char *key = mp_obj_str_get_str(key_in); int ret; @@ -77,9 +77,9 @@ STATIC mp_obj_t mp_os_unsetenv(mp_obj_t key_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_unsetenv_obj, mp_os_unsetenv); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_os_unsetenv_obj, mp_os_unsetenv); -STATIC mp_obj_t mp_os_system(mp_obj_t cmd_in) { +static mp_obj_t mp_os_system(mp_obj_t cmd_in) { const char *cmd = mp_obj_str_get_str(cmd_in); MP_THREAD_GIL_EXIT(); @@ -90,18 +90,18 @@ STATIC mp_obj_t mp_os_system(mp_obj_t cmd_in) { return MP_OBJ_NEW_SMALL_INT(r); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_system_obj, mp_os_system); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_os_system_obj, mp_os_system); -STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { +static mp_obj_t mp_os_urandom(mp_obj_t num) { mp_int_t n = mp_obj_get_int(num); vstr_t vstr; vstr_init_len(&vstr, n); mp_hal_get_random(n, vstr.buf); return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); -STATIC mp_obj_t mp_os_errno(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_os_errno(size_t n_args, const mp_obj_t *args) { if (n_args == 0) { return MP_OBJ_NEW_SMALL_INT(errno); } @@ -109,4 +109,4 @@ STATIC mp_obj_t mp_os_errno(size_t n_args, const mp_obj_t *args) { errno = mp_obj_get_int(args[0]); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_os_errno_obj, 0, 1, mp_os_errno); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_os_errno_obj, 0, 1, mp_os_errno); diff --git a/ports/unix/modsocket.c b/ports/unix/modsocket.c index 5c935d2299bae..6d6059ae44c54 100644 --- a/ports/unix/modsocket.c +++ b/ports/unix/modsocket.c @@ -82,7 +82,7 @@ static inline mp_obj_t mp_obj_from_sockaddr(const struct sockaddr *addr, socklen return mp_obj_new_bytes((const byte *)addr, len); } -STATIC mp_obj_socket_t *socket_new(int fd) { +static mp_obj_socket_t *socket_new(int fd) { mp_obj_socket_t *o = mp_obj_malloc(mp_obj_socket_t, &mp_type_socket); o->fd = fd; o->blocking = true; @@ -90,13 +90,13 @@ STATIC mp_obj_socket_t *socket_new(int fd) { } -STATIC void socket_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void socket_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_socket_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "<_socket %d>", self->fd); } -STATIC mp_uint_t socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { mp_obj_socket_t *o = MP_OBJ_TO_PTR(o_in); ssize_t r; MP_HAL_RETRY_SYSCALL(r, read(o->fd, buf, size), { @@ -112,7 +112,7 @@ STATIC mp_uint_t socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errc return (mp_uint_t)r; } -STATIC mp_uint_t socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) { mp_obj_socket_t *o = MP_OBJ_TO_PTR(o_in); ssize_t r; MP_HAL_RETRY_SYSCALL(r, write(o->fd, buf, size), { @@ -128,7 +128,7 @@ STATIC mp_uint_t socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, in return (mp_uint_t)r; } -STATIC mp_uint_t socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { mp_obj_socket_t *self = MP_OBJ_TO_PTR(o_in); (void)arg; switch (request) { @@ -186,13 +186,13 @@ STATIC mp_uint_t socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, i } } -STATIC mp_obj_t socket_fileno(mp_obj_t self_in) { +static mp_obj_t socket_fileno(mp_obj_t self_in) { mp_obj_socket_t *self = MP_OBJ_TO_PTR(self_in); return MP_OBJ_NEW_SMALL_INT(self->fd); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_fileno_obj, socket_fileno); +static MP_DEFINE_CONST_FUN_OBJ_1(socket_fileno_obj, socket_fileno); -STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { +static mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { mp_obj_socket_t *self = MP_OBJ_TO_PTR(self_in); mp_buffer_info_t bufinfo; mp_get_buffer_raise(addr_in, &bufinfo, MP_BUFFER_READ); @@ -220,9 +220,9 @@ STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect); -STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { +static mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { mp_obj_socket_t *self = MP_OBJ_TO_PTR(self_in); mp_buffer_info_t bufinfo; mp_get_buffer_raise(addr_in, &bufinfo, MP_BUFFER_READ); @@ -232,10 +232,10 @@ STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { RAISE_ERRNO(r, errno); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind); // method socket.listen([backlog]) -STATIC mp_obj_t socket_listen(size_t n_args, const mp_obj_t *args) { +static mp_obj_t socket_listen(size_t n_args, const mp_obj_t *args) { mp_obj_socket_t *self = MP_OBJ_TO_PTR(args[0]); int backlog = MICROPY_PY_SOCKET_LISTEN_BACKLOG_DEFAULT; @@ -250,9 +250,9 @@ STATIC mp_obj_t socket_listen(size_t n_args, const mp_obj_t *args) { RAISE_ERRNO(r, errno); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_listen_obj, 1, 2, socket_listen); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_listen_obj, 1, 2, socket_listen); -STATIC mp_obj_t socket_accept(mp_obj_t self_in) { +static mp_obj_t socket_accept(mp_obj_t self_in) { mp_obj_socket_t *self = MP_OBJ_TO_PTR(self_in); // sockaddr_storage isn't stack-friendly (129 bytes or so) // struct sockaddr_storage addr; @@ -273,12 +273,12 @@ STATIC mp_obj_t socket_accept(mp_obj_t self_in) { return MP_OBJ_FROM_PTR(t); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_accept_obj, socket_accept); +static MP_DEFINE_CONST_FUN_OBJ_1(socket_accept_obj, socket_accept); // Note: besides flag param, this differs from read() in that // this does not swallow blocking errors (EAGAIN, EWOULDBLOCK) - // these would be thrown as exceptions. -STATIC mp_obj_t socket_recv(size_t n_args, const mp_obj_t *args) { +static mp_obj_t socket_recv(size_t n_args, const mp_obj_t *args) { mp_obj_socket_t *self = MP_OBJ_TO_PTR(args[0]); int sz = MP_OBJ_SMALL_INT_VALUE(args[1]); int flags = 0; @@ -294,9 +294,9 @@ STATIC mp_obj_t socket_recv(size_t n_args, const mp_obj_t *args) { m_del(char, buf, sz); return ret; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_recv_obj, 2, 3, socket_recv); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_recv_obj, 2, 3, socket_recv); -STATIC mp_obj_t socket_recvfrom(size_t n_args, const mp_obj_t *args) { +static mp_obj_t socket_recvfrom(size_t n_args, const mp_obj_t *args) { mp_obj_socket_t *self = MP_OBJ_TO_PTR(args[0]); int sz = MP_OBJ_SMALL_INT_VALUE(args[1]); int flags = 0; @@ -321,12 +321,12 @@ STATIC mp_obj_t socket_recvfrom(size_t n_args, const mp_obj_t *args) { return MP_OBJ_FROM_PTR(t); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_recvfrom_obj, 2, 3, socket_recvfrom); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_recvfrom_obj, 2, 3, socket_recvfrom); // Note: besides flag param, this differs from write() in that // this does not swallow blocking errors (EAGAIN, EWOULDBLOCK) - // these would be thrown as exceptions. -STATIC mp_obj_t socket_send(size_t n_args, const mp_obj_t *args) { +static mp_obj_t socket_send(size_t n_args, const mp_obj_t *args) { mp_obj_socket_t *self = MP_OBJ_TO_PTR(args[0]); int flags = 0; @@ -341,9 +341,9 @@ STATIC mp_obj_t socket_send(size_t n_args, const mp_obj_t *args) { mp_raise_OSError(err)); return MP_OBJ_NEW_SMALL_INT(out_sz); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_send_obj, 2, 3, socket_send); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_send_obj, 2, 3, socket_send); -STATIC mp_obj_t socket_sendto(size_t n_args, const mp_obj_t *args) { +static mp_obj_t socket_sendto(size_t n_args, const mp_obj_t *args) { mp_obj_socket_t *self = MP_OBJ_TO_PTR(args[0]); int flags = 0; @@ -361,9 +361,9 @@ STATIC mp_obj_t socket_sendto(size_t n_args, const mp_obj_t *args) { (struct sockaddr *)addr_bi.buf, addr_bi.len), mp_raise_OSError(err)); return MP_OBJ_NEW_SMALL_INT(out_sz); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_sendto_obj, 3, 4, socket_sendto); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_sendto_obj, 3, 4, socket_sendto); -STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) { +static mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) { (void)n_args; // always 4 mp_obj_socket_t *self = MP_OBJ_TO_PTR(args[0]); int level = MP_OBJ_SMALL_INT_VALUE(args[1]); @@ -388,9 +388,9 @@ STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) { RAISE_ERRNO(r, errno); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_setsockopt_obj, 4, 4, socket_setsockopt); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_setsockopt_obj, 4, 4, socket_setsockopt); -STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) { +static mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) { mp_obj_socket_t *self = MP_OBJ_TO_PTR(self_in); int val = mp_obj_is_true(flag_in); MP_THREAD_GIL_EXIT(); @@ -410,9 +410,9 @@ STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) { self->blocking = val; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking); -STATIC mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) { +static mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) { mp_obj_socket_t *self = MP_OBJ_TO_PTR(self_in); struct timeval tv = {0, }; bool new_blocking = true; @@ -455,9 +455,9 @@ STATIC mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_settimeout_obj, socket_settimeout); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_settimeout_obj, socket_settimeout); -STATIC mp_obj_t socket_makefile(size_t n_args, const mp_obj_t *args) { +static mp_obj_t socket_makefile(size_t n_args, const mp_obj_t *args) { // TODO: CPython explicitly says that closing returned object doesn't close // the original socket (Python2 at all says that fd is dup()ed). But we // save on the bloat. @@ -467,9 +467,9 @@ STATIC mp_obj_t socket_makefile(size_t n_args, const mp_obj_t *args) { new_args[0] = MP_OBJ_NEW_SMALL_INT(self->fd); return mp_vfs_open(n_args, new_args, (mp_map_t *)&mp_const_empty_map); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_makefile_obj, 1, 3, socket_makefile); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_makefile_obj, 1, 3, socket_makefile); -STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t socket_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; (void)n_kw; @@ -497,7 +497,7 @@ STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type_in, size_t n_args, siz return MP_OBJ_FROM_PTR(socket_new(fd)); } -STATIC const mp_rom_map_elem_t socket_locals_dict_table[] = { +static const mp_rom_map_elem_t socket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_fileno), MP_ROM_PTR(&socket_fileno_obj) }, { MP_ROM_QSTR(MP_QSTR_makefile), MP_ROM_PTR(&socket_makefile_obj) }, { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, @@ -518,9 +518,9 @@ STATIC const mp_rom_map_elem_t socket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(socket_locals_dict, socket_locals_dict_table); +static MP_DEFINE_CONST_DICT(socket_locals_dict, socket_locals_dict_table); -STATIC const mp_stream_p_t socket_stream_p = { +static const mp_stream_p_t socket_stream_p = { .read = socket_read, .write = socket_write, .ioctl = socket_ioctl, @@ -537,7 +537,7 @@ MP_DEFINE_CONST_OBJ_TYPE( ); #define BINADDR_MAX_LEN sizeof(struct in6_addr) -STATIC mp_obj_t mod_socket_inet_pton(mp_obj_t family_in, mp_obj_t addr_in) { +static mp_obj_t mod_socket_inet_pton(mp_obj_t family_in, mp_obj_t addr_in) { int family = mp_obj_get_int(family_in); byte binaddr[BINADDR_MAX_LEN]; int r = inet_pton(family, mp_obj_str_get_str(addr_in), binaddr); @@ -556,9 +556,9 @@ STATIC mp_obj_t mod_socket_inet_pton(mp_obj_t family_in, mp_obj_t addr_in) { } return mp_obj_new_bytes(binaddr, binaddr_len); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_socket_inet_pton_obj, mod_socket_inet_pton); +static MP_DEFINE_CONST_FUN_OBJ_2(mod_socket_inet_pton_obj, mod_socket_inet_pton); -STATIC mp_obj_t mod_socket_inet_ntop(mp_obj_t family_in, mp_obj_t binaddr_in) { +static mp_obj_t mod_socket_inet_ntop(mp_obj_t family_in, mp_obj_t binaddr_in) { int family = mp_obj_get_int(family_in); mp_buffer_info_t bufinfo; mp_get_buffer_raise(binaddr_in, &bufinfo, MP_BUFFER_READ); @@ -570,9 +570,9 @@ STATIC mp_obj_t mod_socket_inet_ntop(mp_obj_t family_in, mp_obj_t binaddr_in) { vstr.len = strlen(vstr.buf); return mp_obj_new_str_from_utf8_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_socket_inet_ntop_obj, mod_socket_inet_ntop); +static MP_DEFINE_CONST_FUN_OBJ_2(mod_socket_inet_ntop_obj, mod_socket_inet_ntop); -STATIC mp_obj_t mod_socket_getaddrinfo(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_socket_getaddrinfo(size_t n_args, const mp_obj_t *args) { const char *host = mp_obj_str_get_str(args[0]); const char *serv = NULL; @@ -647,9 +647,9 @@ STATIC mp_obj_t mod_socket_getaddrinfo(size_t n_args, const mp_obj_t *args) { freeaddrinfo(addr_list); return list; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_socket_getaddrinfo_obj, 2, 6, mod_socket_getaddrinfo); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_socket_getaddrinfo_obj, 2, 6, mod_socket_getaddrinfo); -STATIC mp_obj_t mod_socket_sockaddr(mp_obj_t sockaddr_in) { +static mp_obj_t mod_socket_sockaddr(mp_obj_t sockaddr_in) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(sockaddr_in, &bufinfo, MP_BUFFER_READ); switch (((struct sockaddr *)bufinfo.buf)->sa_family) { @@ -681,9 +681,9 @@ STATIC mp_obj_t mod_socket_sockaddr(mp_obj_t sockaddr_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_sockaddr_obj, mod_socket_sockaddr); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_sockaddr_obj, mod_socket_sockaddr); -STATIC const mp_rom_map_elem_t mp_module_socket_globals_table[] = { +static const mp_rom_map_elem_t mp_module_socket_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_socket) }, { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&mp_type_socket) }, { MP_ROM_QSTR(MP_QSTR_getaddrinfo), MP_ROM_PTR(&mod_socket_getaddrinfo_obj) }, @@ -711,7 +711,7 @@ STATIC const mp_rom_map_elem_t mp_module_socket_globals_table[] = { #undef C }; -STATIC MP_DEFINE_CONST_DICT(mp_module_socket_globals, mp_module_socket_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_socket_globals, mp_module_socket_globals_table); const mp_obj_module_t mp_module_socket = { .base = { &mp_type_module }, diff --git a/ports/unix/modtermios.c b/ports/unix/modtermios.c index 8a79bc3a5943d..b1ad9a450e0c8 100644 --- a/ports/unix/modtermios.c +++ b/ports/unix/modtermios.c @@ -35,7 +35,7 @@ #include "py/runtime.h" #include "py/mphal.h" -STATIC mp_obj_t mod_termios_tcgetattr(mp_obj_t fd_in) { +static mp_obj_t mod_termios_tcgetattr(mp_obj_t fd_in) { struct termios term; int fd = mp_obj_get_int(fd_in); @@ -65,9 +65,9 @@ STATIC mp_obj_t mod_termios_tcgetattr(mp_obj_t fd_in) { } return MP_OBJ_FROM_PTR(r); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_termios_tcgetattr_obj, mod_termios_tcgetattr); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_termios_tcgetattr_obj, mod_termios_tcgetattr); -STATIC mp_obj_t mod_termios_tcsetattr(mp_obj_t fd_in, mp_obj_t when_in, mp_obj_t attrs_in) { +static mp_obj_t mod_termios_tcsetattr(mp_obj_t fd_in, mp_obj_t when_in, mp_obj_t attrs_in) { struct termios term; int fd = mp_obj_get_int(fd_in); int when = mp_obj_get_int(when_in); @@ -105,9 +105,9 @@ STATIC mp_obj_t mod_termios_tcsetattr(mp_obj_t fd_in, mp_obj_t when_in, mp_obj_t RAISE_ERRNO(res, errno); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_termios_tcsetattr_obj, mod_termios_tcsetattr); +static MP_DEFINE_CONST_FUN_OBJ_3(mod_termios_tcsetattr_obj, mod_termios_tcsetattr); -STATIC mp_obj_t mod_termios_setraw(mp_obj_t fd_in) { +static mp_obj_t mod_termios_setraw(mp_obj_t fd_in) { struct termios term; int fd = mp_obj_get_int(fd_in); int res = tcgetattr(fd, &term); @@ -123,9 +123,9 @@ STATIC mp_obj_t mod_termios_setraw(mp_obj_t fd_in) { RAISE_ERRNO(res, errno); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_termios_setraw_obj, mod_termios_setraw); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_termios_setraw_obj, mod_termios_setraw); -STATIC const mp_rom_map_elem_t mp_module_termios_globals_table[] = { +static const mp_rom_map_elem_t mp_module_termios_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_termios) }, { MP_ROM_QSTR(MP_QSTR_tcgetattr), MP_ROM_PTR(&mod_termios_tcgetattr_obj) }, { MP_ROM_QSTR(MP_QSTR_tcsetattr), MP_ROM_PTR(&mod_termios_tcsetattr_obj) }, @@ -144,7 +144,7 @@ STATIC const mp_rom_map_elem_t mp_module_termios_globals_table[] = { #undef C }; -STATIC MP_DEFINE_CONST_DICT(mp_module_termios_globals, mp_module_termios_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_termios_globals, mp_module_termios_globals_table); const mp_obj_module_t mp_module_termios = { .base = { &mp_type_module }, diff --git a/ports/unix/modtime.c b/ports/unix/modtime.c index b6fbae0d1c24b..fbd94b5ecd129 100644 --- a/ports/unix/modtime.c +++ b/ports/unix/modtime.c @@ -61,7 +61,7 @@ static inline int msec_sleep_tv(struct timeval *tv) { #error Unsupported clock() implementation #endif -STATIC mp_obj_t mp_time_time_get(void) { +static mp_obj_t mp_time_time_get(void) { #if MICROPY_PY_BUILTINS_FLOAT && MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE struct timeval tv; gettimeofday(&tv, NULL); @@ -73,7 +73,7 @@ STATIC mp_obj_t mp_time_time_get(void) { } // Note: this is deprecated since CPy3.3, but pystone still uses it. -STATIC mp_obj_t mod_time_clock(void) { +static mp_obj_t mod_time_clock(void) { #if MICROPY_PY_BUILTINS_FLOAT // float cannot represent full range of int32 precisely, so we pre-divide // int to reduce resolution, and then actually do float division hoping @@ -83,9 +83,9 @@ STATIC mp_obj_t mod_time_clock(void) { return mp_obj_new_int((mp_int_t)clock()); #endif } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_time_clock_obj, mod_time_clock); +static MP_DEFINE_CONST_FUN_OBJ_0(mod_time_clock_obj, mod_time_clock); -STATIC mp_obj_t mp_time_sleep(mp_obj_t arg) { +static mp_obj_t mp_time_sleep(mp_obj_t arg) { #if MICROPY_PY_BUILTINS_FLOAT struct timeval tv; mp_float_t val = mp_obj_get_float(arg); @@ -125,7 +125,7 @@ STATIC mp_obj_t mp_time_sleep(mp_obj_t arg) { return mp_const_none; } -STATIC mp_obj_t mod_time_gm_local_time(size_t n_args, const mp_obj_t *args, struct tm *(*time_func)(const time_t *timep)) { +static mp_obj_t mod_time_gm_local_time(size_t n_args, const mp_obj_t *args, struct tm *(*time_func)(const time_t *timep)) { time_t t; if (n_args == 0) { t = time(NULL); @@ -159,17 +159,17 @@ STATIC mp_obj_t mod_time_gm_local_time(size_t n_args, const mp_obj_t *args, stru return ret; } -STATIC mp_obj_t mod_time_gmtime(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_time_gmtime(size_t n_args, const mp_obj_t *args) { return mod_time_gm_local_time(n_args, args, gmtime); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_time_gmtime_obj, 0, 1, mod_time_gmtime); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_time_gmtime_obj, 0, 1, mod_time_gmtime); -STATIC mp_obj_t mod_time_localtime(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_time_localtime(size_t n_args, const mp_obj_t *args) { return mod_time_gm_local_time(n_args, args, localtime); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_time_localtime_obj, 0, 1, mod_time_localtime); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_time_localtime_obj, 0, 1, mod_time_localtime); -STATIC mp_obj_t mod_time_mktime(mp_obj_t tuple) { +static mp_obj_t mod_time_mktime(mp_obj_t tuple) { size_t len; mp_obj_t *elem; mp_obj_get_array(tuple, &len, &elem); diff --git a/ports/unix/mpbthciport.c b/ports/unix/mpbthciport.c index 8813ce147c1ee..95c39f559910d 100644 --- a/ports/unix/mpbthciport.c +++ b/ports/unix/mpbthciport.c @@ -54,7 +54,7 @@ uint8_t mp_bluetooth_hci_cmd_buf[4 + 256]; -STATIC int uart_fd = -1; +static int uart_fd = -1; // Must be provided by the stack bindings (e.g. mpnimbleport.c or mpbtstackport.c). extern bool mp_bluetooth_hci_poll(void); @@ -68,9 +68,9 @@ extern bool mp_bluetooth_hci_poll(void); extern bool mp_bluetooth_hci_active(void); // Prevent double-enqueuing of the scheduled task. -STATIC volatile bool events_task_is_scheduled = false; +static volatile bool events_task_is_scheduled = false; -STATIC mp_obj_t run_events_scheduled_task(mp_obj_t none_in) { +static mp_obj_t run_events_scheduled_task(mp_obj_t none_in) { (void)none_in; MICROPY_PY_BLUETOOTH_ENTER events_task_is_scheduled = false; @@ -78,14 +78,14 @@ STATIC mp_obj_t run_events_scheduled_task(mp_obj_t none_in) { mp_bluetooth_hci_poll(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(run_events_scheduled_task_obj, run_events_scheduled_task); +static MP_DEFINE_CONST_FUN_OBJ_1(run_events_scheduled_task_obj, run_events_scheduled_task); #endif // MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS -STATIC const useconds_t UART_POLL_INTERVAL_US = 1000; -STATIC pthread_t hci_poll_thread_id; +static const useconds_t UART_POLL_INTERVAL_US = 1000; +static pthread_t hci_poll_thread_id; -STATIC void *hci_poll_thread(void *arg) { +static void *hci_poll_thread(void *arg) { (void)arg; DEBUG_printf("hci_poll_thread: starting\n"); @@ -118,7 +118,7 @@ STATIC void *hci_poll_thread(void *arg) { return NULL; } -STATIC int configure_uart(void) { +static int configure_uart(void) { struct termios toptions; // Get existing config. diff --git a/ports/unix/mpbtstackport_h4.c b/ports/unix/mpbtstackport_h4.c index a2038c16a90a8..14d418c63f229 100644 --- a/ports/unix/mpbtstackport_h4.c +++ b/ports/unix/mpbtstackport_h4.c @@ -44,7 +44,7 @@ #define DEBUG_printf(...) // printf(__VA_ARGS__) -STATIC hci_transport_config_uart_t hci_transport_config_uart = { +static hci_transport_config_uart_t hci_transport_config_uart = { .type = HCI_TRANSPORT_CONFIG_UART, .baudrate_init = 1000000, .baudrate_main = 0, diff --git a/ports/unix/mpbtstackport_usb.c b/ports/unix/mpbtstackport_usb.c index 1793e2bacd21e..8b1d1fff2189f 100644 --- a/ports/unix/mpbtstackport_usb.c +++ b/ports/unix/mpbtstackport_usb.c @@ -49,7 +49,7 @@ #error Unix btstack requires MICROPY_PY_THREAD #endif -STATIC const useconds_t USB_POLL_INTERVAL_US = 1000; +static const useconds_t USB_POLL_INTERVAL_US = 1000; void mp_bluetooth_btstack_port_init_usb(void) { // MICROPYBTUSB can be a ':'' or '-' separated port list. @@ -73,7 +73,7 @@ void mp_bluetooth_btstack_port_init_usb(void) { hci_init(hci_transport_usb_instance(), NULL); } -STATIC pthread_t bstack_thread_id; +static pthread_t bstack_thread_id; void mp_bluetooth_btstack_port_deinit(void) { hci_power_control(HCI_POWER_OFF); @@ -86,7 +86,7 @@ void mp_bluetooth_btstack_port_deinit(void) { // Provided by mpbstackport_common.c. extern bool mp_bluetooth_hci_poll(void); -STATIC void *btstack_thread(void *arg) { +static void *btstack_thread(void *arg) { (void)arg; hci_power_control(HCI_POWER_ON); diff --git a/ports/unix/mpthreadport.c b/ports/unix/mpthreadport.c index 2190bf4ad1ba3..16ac4da8bf56f 100644 --- a/ports/unix/mpthreadport.c +++ b/ports/unix/mpthreadport.c @@ -60,21 +60,21 @@ typedef struct _mp_thread_t { struct _mp_thread_t *next; } mp_thread_t; -STATIC pthread_key_t tls_key; +static pthread_key_t tls_key; // The mutex is used for any code in this port that needs to be thread safe. // Specifically for thread management, access to the linked list is one example. // But also, e.g. scheduler state. -STATIC pthread_mutex_t thread_mutex; -STATIC mp_thread_t *thread; +static pthread_mutex_t thread_mutex; +static mp_thread_t *thread; // this is used to synchronise the signal handler of the thread // it's needed because we can't use any pthread calls in a signal handler #if defined(__APPLE__) -STATIC char thread_signal_done_name[25]; -STATIC sem_t *thread_signal_done_p; +static char thread_signal_done_name[25]; +static sem_t *thread_signal_done_p; #else -STATIC sem_t thread_signal_done; +static sem_t thread_signal_done; #endif void mp_thread_unix_begin_atomic_section(void) { @@ -86,7 +86,7 @@ void mp_thread_unix_end_atomic_section(void) { } // this signal handler is used to scan the regs and stack of a thread -STATIC void mp_thread_gc(int signo, siginfo_t *info, void *context) { +static void mp_thread_gc(int signo, siginfo_t *info, void *context) { (void)info; // unused (void)context; // unused if (signo == MP_THREAD_GC_SIGNAL) { diff --git a/ports/unix/unix_mphal.c b/ports/unix/unix_mphal.c index 24c0fa3cdae53..5f5abc2e056f6 100644 --- a/ports/unix/unix_mphal.c +++ b/ports/unix/unix_mphal.c @@ -46,7 +46,7 @@ #ifndef _WIN32 #include -STATIC void sighandler(int signum) { +static void sighandler(int signum) { if (signum == SIGINT) { #if MICROPY_ASYNC_KBD_INTR #if MICROPY_PY_THREAD_GIL diff --git a/ports/webassembly/main.c b/ports/webassembly/main.c index c3cb8c1974ee9..0aacf1ee095be 100644 --- a/ports/webassembly/main.c +++ b/ports/webassembly/main.c @@ -112,7 +112,7 @@ void mp_js_init_repl() { pyexec_event_repl_init(); } -STATIC void gc_scan_func(void *begin, void *end) { +static void gc_scan_func(void *begin, void *end) { gc_collect_root((void **)begin, (void **)end - (void **)begin + 1); } diff --git a/ports/windows/fmode.c b/ports/windows/fmode.c index a7976b87e32dc..128c951ec40cd 100644 --- a/ports/windows/fmode.c +++ b/ports/windows/fmode.c @@ -31,7 +31,7 @@ // Workaround for setting file translation mode: we must distinguish toolsets // since mingw has no _set_fmode, and altering msvc's _fmode directly has no effect -STATIC int set_fmode_impl(int mode) { +static int set_fmode_impl(int mode) { #ifndef _MSC_VER _fmode = mode; return 0; diff --git a/ports/windows/windows_mphal.c b/ports/windows/windows_mphal.c index dcee20784e79f..b636393f5401c 100644 --- a/ports/windows/windows_mphal.c +++ b/ports/windows/windows_mphal.c @@ -38,14 +38,14 @@ HANDLE std_in = NULL; HANDLE con_out = NULL; DWORD orig_mode = 0; -STATIC void assure_stdin_handle() { +static void assure_stdin_handle() { if (!std_in) { std_in = GetStdHandle(STD_INPUT_HANDLE); assert(std_in != INVALID_HANDLE_VALUE); } } -STATIC void assure_conout_handle() { +static void assure_conout_handle() { if (!con_out) { con_out = CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, @@ -143,7 +143,7 @@ typedef struct item_t { } item_t; // map virtual key codes to key sequences known by MicroPython's readline implementation -STATIC item_t keyCodeMap[] = { +static item_t keyCodeMap[] = { {VK_UP, "[A"}, {VK_DOWN, "[B"}, {VK_RIGHT, "[C"}, @@ -155,7 +155,7 @@ STATIC item_t keyCodeMap[] = { }; // likewise, but with Ctrl key down -STATIC item_t ctrlKeyCodeMap[] = { +static item_t ctrlKeyCodeMap[] = { {VK_LEFT, "b"}, {VK_RIGHT, "f"}, {VK_DELETE, "d"}, @@ -163,9 +163,9 @@ STATIC item_t ctrlKeyCodeMap[] = { {0, ""} // sentinel }; -STATIC const char *cur_esc_seq = NULL; +static const char *cur_esc_seq = NULL; -STATIC int esc_seq_process_vk(WORD vk, bool ctrl_key_down) { +static int esc_seq_process_vk(WORD vk, bool ctrl_key_down) { for (item_t *p = (ctrl_key_down ? ctrlKeyCodeMap : keyCodeMap); p->vkey != 0; ++p) { if (p->vkey == vk) { cur_esc_seq = p->seq; @@ -175,7 +175,7 @@ STATIC int esc_seq_process_vk(WORD vk, bool ctrl_key_down) { return 0; // nothing found } -STATIC int esc_seq_chr() { +static int esc_seq_chr() { if (cur_esc_seq) { const char c = *cur_esc_seq++; if (c) { diff --git a/ports/zephyr/machine_i2c.c b/ports/zephyr/machine_i2c.c index 36d88204f4a5b..27c0a63a0ef9c 100644 --- a/ports/zephyr/machine_i2c.c +++ b/ports/zephyr/machine_i2c.c @@ -46,7 +46,7 @@ typedef struct _machine_hard_i2c_obj_t { bool restart; } machine_hard_i2c_obj_t; -STATIC void machine_hard_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_hard_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_hard_i2c_obj_t *self = self_in; mp_printf(print, "%s", self->dev->name); } @@ -90,7 +90,7 @@ mp_obj_t machine_hard_i2c_make_new(const mp_obj_type_t *type, size_t n_args, siz return MP_OBJ_FROM_PTR(self); } -STATIC int machine_hard_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, size_t len, uint8_t *buf, unsigned int flags) { +static int machine_hard_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, size_t len, uint8_t *buf, unsigned int flags) { machine_hard_i2c_obj_t *self = (machine_hard_i2c_obj_t *)self_in; struct i2c_msg msg; int ret; @@ -120,7 +120,7 @@ STATIC int machine_hard_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t add return (ret < 0) ? -MP_EIO : len; } -STATIC const mp_machine_i2c_p_t machine_hard_i2c_p = { +static const mp_machine_i2c_p_t machine_hard_i2c_p = { .transfer = mp_machine_i2c_transfer_adaptor, .transfer_single = machine_hard_i2c_transfer_single, }; diff --git a/ports/zephyr/machine_pin.c b/ports/zephyr/machine_pin.c index d27b5900929f6..97a852be8abca 100644 --- a/ports/zephyr/machine_pin.c +++ b/ports/zephyr/machine_pin.c @@ -47,7 +47,7 @@ typedef struct _machine_pin_irq_obj_t { struct gpio_callback callback; } machine_pin_irq_obj_t; -STATIC const mp_irq_methods_t machine_pin_irq_methods; +static const mp_irq_methods_t machine_pin_irq_methods; const mp_obj_base_t machine_pin_obj_template = {&machine_pin_type}; void machine_pin_deinit(void) { @@ -59,7 +59,7 @@ void machine_pin_deinit(void) { MP_STATE_PORT(machine_pin_irq_list) = NULL; } -STATIC void gpio_callback_handler(const struct device *port, struct gpio_callback *cb, gpio_port_pins_t pins) { +static void gpio_callback_handler(const struct device *port, struct gpio_callback *cb, gpio_port_pins_t pins) { machine_pin_irq_obj_t *irq = CONTAINER_OF(cb, machine_pin_irq_obj_t, callback); #if MICROPY_STACK_CHECK @@ -80,13 +80,13 @@ STATIC void gpio_callback_handler(const struct device *port, struct gpio_callbac #endif } -STATIC void machine_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_pin_obj_t *self = self_in; mp_printf(print, "", self->port, self->pin); } // pin.init(mode, pull=None, *, value) -STATIC mp_obj_t machine_pin_obj_init_helper(machine_pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_pin_obj_init_helper(machine_pin_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_mode, ARG_pull, ARG_value }; static const mp_arg_t allowed_args[] = { { MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT }, @@ -154,7 +154,7 @@ mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, } // fast method for getting/setting pin value -STATIC mp_obj_t machine_pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t machine_pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); machine_pin_obj_t *self = self_in; if (n_args == 0) { @@ -167,33 +167,33 @@ STATIC mp_obj_t machine_pin_call(mp_obj_t self_in, size_t n_args, size_t n_kw, c } // pin.init(mode, pull) -STATIC mp_obj_t machine_pin_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +static mp_obj_t machine_pin_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { return machine_pin_obj_init_helper(args[0], n_args - 1, args + 1, kw_args); } MP_DEFINE_CONST_FUN_OBJ_KW(machine_pin_init_obj, 1, machine_pin_obj_init); // pin.value([value]) -STATIC mp_obj_t machine_pin_value(size_t n_args, const mp_obj_t *args) { +static mp_obj_t machine_pin_value(size_t n_args, const mp_obj_t *args) { return machine_pin_call(args[0], n_args - 1, 0, args + 1); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pin_value_obj, 1, 2, machine_pin_value); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pin_value_obj, 1, 2, machine_pin_value); -STATIC mp_obj_t machine_pin_off(mp_obj_t self_in) { +static mp_obj_t machine_pin_off(mp_obj_t self_in) { machine_pin_obj_t *self = self_in; (void)gpio_pin_set_raw(self->port, self->pin, 0); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_off_obj, machine_pin_off); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_off_obj, machine_pin_off); -STATIC mp_obj_t machine_pin_on(mp_obj_t self_in) { +static mp_obj_t machine_pin_on(mp_obj_t self_in) { machine_pin_obj_t *self = self_in; (void)gpio_pin_set_raw(self->port, self->pin, 1); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_on_obj, machine_pin_on); +static MP_DEFINE_CONST_FUN_OBJ_1(machine_pin_on_obj, machine_pin_on); // pin.irq(handler=None, trigger=IRQ_FALLING|IRQ_RISING, hard=False) -STATIC mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_handler, ARG_trigger, ARG_hard }; static const mp_arg_t allowed_args[] = { { MP_QSTR_handler, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, @@ -246,9 +246,9 @@ STATIC mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_ return MP_OBJ_FROM_PTR(self->irq); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_pin_irq_obj, 1, machine_pin_irq); +static MP_DEFINE_CONST_FUN_OBJ_KW(machine_pin_irq_obj, 1, machine_pin_irq); -STATIC mp_uint_t machine_pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t machine_pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { (void)errcode; machine_pin_obj_t *self = self_in; @@ -263,7 +263,7 @@ STATIC mp_uint_t machine_pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_ return -1; } -STATIC const mp_rom_map_elem_t machine_pin_locals_dict_table[] = { +static const mp_rom_map_elem_t machine_pin_locals_dict_table[] = { // instance methods { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_pin_init_obj) }, { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&machine_pin_value_obj) }, @@ -280,9 +280,9 @@ STATIC const mp_rom_map_elem_t machine_pin_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_IRQ_FALLING), MP_ROM_INT(GPIO_INT_EDGE_FALLING) }, }; -STATIC MP_DEFINE_CONST_DICT(machine_pin_locals_dict, machine_pin_locals_dict_table); +static MP_DEFINE_CONST_DICT(machine_pin_locals_dict, machine_pin_locals_dict_table); -STATIC const mp_pin_p_t machine_pin_pin_p = { +static const mp_pin_p_t machine_pin_pin_p = { .ioctl = machine_pin_ioctl, }; @@ -297,7 +297,7 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &machine_pin_locals_dict ); -STATIC mp_uint_t machine_pin_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { +static mp_uint_t machine_pin_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); if (new_trigger == 0) { new_trigger = GPIO_INT_DISABLE; @@ -309,7 +309,7 @@ STATIC mp_uint_t machine_pin_irq_trigger(mp_obj_t self_in, mp_uint_t new_trigger return 0; } -STATIC mp_uint_t machine_pin_irq_info(mp_obj_t self_in, mp_uint_t info_type) { +static mp_uint_t machine_pin_irq_info(mp_obj_t self_in, mp_uint_t info_type) { machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); if (info_type == MP_IRQ_INFO_FLAGS) { return gpio_get_pending_int(self->port); @@ -319,7 +319,7 @@ STATIC mp_uint_t machine_pin_irq_info(mp_obj_t self_in, mp_uint_t info_type) { return 0; } -STATIC const mp_irq_methods_t machine_pin_irq_methods = { +static const mp_irq_methods_t machine_pin_irq_methods = { .trigger = machine_pin_irq_trigger, .info = machine_pin_irq_info, }; diff --git a/ports/zephyr/machine_spi.c b/ports/zephyr/machine_spi.c index 5c882a6ae3c0e..5c090e15cfa27 100644 --- a/ports/zephyr/machine_spi.c +++ b/ports/zephyr/machine_spi.c @@ -52,7 +52,7 @@ typedef struct _machine_hard_spi_obj_t { struct spi_config config; } machine_hard_spi_obj_t; -STATIC void machine_hard_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void machine_hard_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_hard_spi_obj_t *self = self_in; mp_printf(print, "SPI(%s, baudrate=%u, polarity=%u, phase=%u, bits=%u, firstbit=%s)", self->dev->name, @@ -112,7 +112,7 @@ mp_obj_t machine_hard_spi_make_new(const mp_obj_type_t *type, size_t n_args, siz return MP_OBJ_FROM_PTR(self); } -STATIC void machine_hard_spi_init(mp_obj_base_t *obj, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void machine_hard_spi_init(mp_obj_base_t *obj, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum {ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits, ARG_firstbit}; static const mp_arg_t allowed_args[] = { @@ -163,7 +163,7 @@ STATIC void machine_hard_spi_init(mp_obj_base_t *obj, size_t n_args, const mp_ob self->config = cfg; } -STATIC void machine_hard_spi_transfer(mp_obj_base_t *obj, size_t len, const uint8_t *src, uint8_t *dest) { +static void machine_hard_spi_transfer(mp_obj_base_t *obj, size_t len, const uint8_t *src, uint8_t *dest) { machine_hard_spi_obj_t *self = (machine_hard_spi_obj_t *)obj; int ret; @@ -191,7 +191,7 @@ STATIC void machine_hard_spi_transfer(mp_obj_base_t *obj, size_t len, const uint } } -STATIC const mp_machine_spi_p_t machine_hard_spi_p = { +static const mp_machine_spi_p_t machine_hard_spi_p = { .init = machine_hard_spi_init, .transfer = machine_hard_spi_transfer, }; diff --git a/ports/zephyr/machine_uart.c b/ports/zephyr/machine_uart.c index 2c4b3a470b58e..bd40137a3e7d6 100644 --- a/ports/zephyr/machine_uart.c +++ b/ports/zephyr/machine_uart.c @@ -43,12 +43,12 @@ typedef struct _machine_uart_obj_t { uint16_t timeout_char; // timeout waiting between chars (in ms) } machine_uart_obj_t; -STATIC const char *_parity_name[] = {"None", "Odd", "Even", "Mark", "Space"}; -STATIC const char *_stop_bits_name[] = {"0.5", "1", "1.5", "2"}; -STATIC const char *_data_bits_name[] = {"5", "6", "7", "8", "9"}; -STATIC const char *_flow_control_name[] = {"None", "RTS/CTS", "DTR/DSR"}; +static const char *_parity_name[] = {"None", "Odd", "Even", "Mark", "Space"}; +static const char *_stop_bits_name[] = {"0.5", "1", "1.5", "2"}; +static const char *_data_bits_name[] = {"5", "6", "7", "8", "9"}; +static const char *_flow_control_name[] = {"None", "RTS/CTS", "DTR/DSR"}; -STATIC void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); struct uart_config config; uart_config_get(self->dev, &config); @@ -58,7 +58,7 @@ STATIC void mp_machine_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_ self->timeout, self->timeout_char); } -STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_timeout, ARG_timeout_char }; static const mp_arg_t allowed_args[] = { { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, @@ -71,7 +71,7 @@ STATIC void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, self->timeout_char = args[ARG_timeout_char].u_int; } -STATIC mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); machine_uart_obj_t *self = mp_obj_malloc(machine_uart_obj_t, &machine_uart_type); @@ -87,21 +87,21 @@ STATIC mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_arg return MP_OBJ_FROM_PTR(self); } -STATIC void mp_machine_uart_deinit(machine_uart_obj_t *self) { +static void mp_machine_uart_deinit(machine_uart_obj_t *self) { (void)self; } -STATIC mp_int_t mp_machine_uart_any(machine_uart_obj_t *self) { +static mp_int_t mp_machine_uart_any(machine_uart_obj_t *self) { (void)self; mp_raise_NotImplementedError(NULL); // TODO } -STATIC bool mp_machine_uart_txdone(machine_uart_obj_t *self) { +static bool mp_machine_uart_txdone(machine_uart_obj_t *self) { (void)self; mp_raise_NotImplementedError(NULL); // TODO } -STATIC mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { +static mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); uint8_t *buffer = (uint8_t *)buf_in; uint8_t data; @@ -122,7 +122,7 @@ STATIC mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t return bytes_read; } -STATIC mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { +static mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { machine_uart_obj_t *self = MP_OBJ_TO_PTR(self_in); uint8_t *buffer = (uint8_t *)buf_in; @@ -133,7 +133,7 @@ STATIC mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_ return size; } -STATIC mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { mp_uint_t ret; if (request == MP_STREAM_POLL) { diff --git a/ports/zephyr/main.c b/ports/zephyr/main.c index 36bc628bbe953..314bbfd263b45 100644 --- a/ports/zephyr/main.c +++ b/ports/zephyr/main.c @@ -96,7 +96,7 @@ void init_zephyr(void) { } #if MICROPY_VFS -STATIC void vfs_init(void) { +static void vfs_init(void) { mp_obj_t bdev = NULL; mp_obj_t mount_point; const char *mount_point_str = NULL; diff --git a/ports/zephyr/modbluetooth_zephyr.c b/ports/zephyr/modbluetooth_zephyr.c index 279e4ca9a03bc..b427a6cd98b9f 100644 --- a/ports/zephyr/modbluetooth_zephyr.c +++ b/ports/zephyr/modbluetooth_zephyr.c @@ -61,21 +61,21 @@ typedef struct _mp_bluetooth_zephyr_root_pointers_t { mp_gatts_db_t gatts_db; } mp_bluetooth_zephyr_root_pointers_t; -STATIC int mp_bluetooth_zephyr_ble_state; +static int mp_bluetooth_zephyr_ble_state; #if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE -STATIC int mp_bluetooth_zephyr_gap_scan_state; -STATIC struct k_timer mp_bluetooth_zephyr_gap_scan_timer; -STATIC struct bt_le_scan_cb mp_bluetooth_zephyr_gap_scan_cb_struct; +static int mp_bluetooth_zephyr_gap_scan_state; +static struct k_timer mp_bluetooth_zephyr_gap_scan_timer; +static struct bt_le_scan_cb mp_bluetooth_zephyr_gap_scan_cb_struct; #endif -STATIC int bt_err_to_errno(int err) { +static int bt_err_to_errno(int err) { // Zephyr uses errno codes directly, but they are negative. return -err; } // modbluetooth (and the layers above it) work in BE for addresses, Zephyr works in LE. -STATIC void reverse_addr_byte_order(uint8_t *addr_out, const bt_addr_le_t *addr_in) { +static void reverse_addr_byte_order(uint8_t *addr_out, const bt_addr_le_t *addr_in) { for (int i = 0; i < 6; ++i) { addr_out[i] = addr_in->a.val[5 - i]; } @@ -98,12 +98,12 @@ void gap_scan_cb_recv(const struct bt_le_scan_recv_info *info, struct net_buf_si mp_bluetooth_gap_on_scan_result(info->addr->type, addr, info->adv_type, info->rssi, buf->data, buf->len); } -STATIC mp_obj_t gap_scan_stop(mp_obj_t unused) { +static mp_obj_t gap_scan_stop(mp_obj_t unused) { (void)unused; mp_bluetooth_gap_scan_stop(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(gap_scan_stop_obj, gap_scan_stop); +static MP_DEFINE_CONST_FUN_OBJ_1(gap_scan_stop_obj, gap_scan_stop); void gap_scan_cb_timeout(struct k_timer *timer_id) { DEBUG_printf("gap_scan_cb_timeout\n"); @@ -212,7 +212,7 @@ int mp_bluetooth_gap_set_device_name(const uint8_t *buf, size_t len) { // Zephyr takes advertising/scan data as an array of (type, len, payload) packets, // and this function constructs such an array from raw advertising/scan data. -STATIC void mp_bluetooth_prepare_bt_data(const uint8_t *data, size_t len, struct bt_data *bt_data, size_t *bt_len) { +static void mp_bluetooth_prepare_bt_data(const uint8_t *data, size_t len, struct bt_data *bt_data, size_t *bt_len) { size_t i = 0; const uint8_t *d = data; while (d < data + len && i < *bt_len) { diff --git a/ports/zephyr/modmachine.c b/ports/zephyr/modmachine.c index 7015989784f5c..bbb9280a5dcb9 100644 --- a/ports/zephyr/modmachine.c +++ b/ports/zephyr/modmachine.c @@ -45,19 +45,19 @@ { MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) }, \ { MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&machine_pin_type) }, \ -STATIC mp_obj_t machine_reset(void) { +static mp_obj_t machine_reset(void) { sys_reboot(SYS_REBOOT_COLD); // Won't get here, Zephyr has infiniloop on its side return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset); -STATIC mp_obj_t machine_reset_cause(void) { +static mp_obj_t machine_reset_cause(void) { printf("Warning: %s is not implemented\n", __func__); return MP_OBJ_NEW_SMALL_INT(42); } MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause); -STATIC void mp_machine_idle(void) { +static void mp_machine_idle(void) { k_yield(); } diff --git a/ports/zephyr/modsocket.c b/ports/zephyr/modsocket.c index 3d91fa976930d..12c4c934bcd2f 100644 --- a/ports/zephyr/modsocket.c +++ b/ports/zephyr/modsocket.c @@ -59,21 +59,21 @@ typedef struct _socket_obj_t { int8_t state; } socket_obj_t; -STATIC const mp_obj_type_t socket_type; +static const mp_obj_type_t socket_type; // Helper functions #define RAISE_ERRNO(x) { int _err = x; if (_err < 0) mp_raise_OSError(-_err); } #define RAISE_SOCK_ERRNO(x) { if ((int)(x) == -1) mp_raise_OSError(errno); } -STATIC void socket_check_closed(socket_obj_t *socket) { +static void socket_check_closed(socket_obj_t *socket) { if (socket->ctx == -1) { // already closed mp_raise_OSError(EBADF); } } -STATIC void parse_inet_addr(socket_obj_t *socket, mp_obj_t addr_in, struct sockaddr *sockaddr) { +static void parse_inet_addr(socket_obj_t *socket, mp_obj_t addr_in, struct sockaddr *sockaddr) { // We employ the fact that port and address offsets are the same for IPv4 & IPv6 struct sockaddr_in *sockaddr_in = (struct sockaddr_in *)sockaddr; @@ -85,7 +85,7 @@ STATIC void parse_inet_addr(socket_obj_t *socket, mp_obj_t addr_in, struct socka sockaddr_in->sin_port = htons(mp_obj_get_int(addr_items[1])); } -STATIC mp_obj_t format_inet_addr(struct sockaddr *addr, mp_obj_t port) { +static mp_obj_t format_inet_addr(struct sockaddr *addr, mp_obj_t port) { // We employ the fact that port and address offsets are the same for IPv4 & IPv6 struct sockaddr_in6 *sockaddr_in6 = (struct sockaddr_in6 *)addr; char buf[40]; @@ -114,7 +114,7 @@ socket_obj_t *socket_new(void) { // Methods -STATIC void socket_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void socket_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { socket_obj_t *self = self_in; if (self->ctx == -1) { mp_printf(print, ""); @@ -124,7 +124,7 @@ STATIC void socket_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kin } } -STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 4, false); socket_obj_t *socket = socket_new(); @@ -156,7 +156,7 @@ STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t return MP_OBJ_FROM_PTR(socket); } -STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { +static mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { socket_obj_t *socket = self_in; socket_check_closed(socket); @@ -168,9 +168,9 @@ STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind); -STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { +static mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { socket_obj_t *socket = self_in; socket_check_closed(socket); @@ -182,10 +182,10 @@ STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect); // method socket.listen([backlog]) -STATIC mp_obj_t socket_listen(size_t n_args, const mp_obj_t *args) { +static mp_obj_t socket_listen(size_t n_args, const mp_obj_t *args) { socket_obj_t *socket = args[0]; socket_check_closed(socket); @@ -200,9 +200,9 @@ STATIC mp_obj_t socket_listen(size_t n_args, const mp_obj_t *args) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_listen_obj, 1, 2, socket_listen); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_listen_obj, 1, 2, socket_listen); -STATIC mp_obj_t socket_accept(mp_obj_t self_in) { +static mp_obj_t socket_accept(mp_obj_t self_in) { socket_obj_t *socket = self_in; socket_check_closed(socket); @@ -220,9 +220,9 @@ STATIC mp_obj_t socket_accept(mp_obj_t self_in) { return MP_OBJ_FROM_PTR(client); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_accept_obj, socket_accept); +static MP_DEFINE_CONST_FUN_OBJ_1(socket_accept_obj, socket_accept); -STATIC mp_uint_t sock_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t sock_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { socket_obj_t *socket = self_in; if (socket->ctx == -1) { // already closed @@ -239,7 +239,7 @@ STATIC mp_uint_t sock_write(mp_obj_t self_in, const void *buf, mp_uint_t size, i return len; } -STATIC mp_obj_t socket_send(mp_obj_t self_in, mp_obj_t buf_in) { +static mp_obj_t socket_send(mp_obj_t self_in, mp_obj_t buf_in) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ); int err = 0; @@ -249,9 +249,9 @@ STATIC mp_obj_t socket_send(mp_obj_t self_in, mp_obj_t buf_in) { } return mp_obj_new_int_from_uint(len); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_send_obj, socket_send); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_send_obj, socket_send); -STATIC mp_uint_t sock_read(mp_obj_t self_in, void *buf, mp_uint_t max_len, int *errcode) { +static mp_uint_t sock_read(mp_obj_t self_in, void *buf, mp_uint_t max_len, int *errcode) { socket_obj_t *socket = self_in; if (socket->ctx == -1) { // already closed @@ -268,7 +268,7 @@ STATIC mp_uint_t sock_read(mp_obj_t self_in, void *buf, mp_uint_t max_len, int * return recv_len; } -STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) { +static mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) { mp_int_t max_len = mp_obj_get_int(len_in); vstr_t vstr; // +1 to accommodate for trailing \0 @@ -290,22 +290,22 @@ STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) { vstr.len = len; return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_recv_obj, socket_recv); +static MP_DEFINE_CONST_FUN_OBJ_2(socket_recv_obj, socket_recv); -STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) { +static mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) { (void)n_args; // always 4 mp_warning(MP_WARN_CAT(RuntimeWarning), "setsockopt() not implemented"); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_setsockopt_obj, 4, 4, socket_setsockopt); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_setsockopt_obj, 4, 4, socket_setsockopt); -STATIC mp_obj_t socket_makefile(size_t n_args, const mp_obj_t *args) { +static mp_obj_t socket_makefile(size_t n_args, const mp_obj_t *args) { (void)n_args; return args[0]; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_makefile_obj, 1, 3, socket_makefile); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_makefile_obj, 1, 3, socket_makefile); -STATIC mp_uint_t sock_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t sock_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { socket_obj_t *socket = o_in; (void)arg; switch (request) { @@ -327,7 +327,7 @@ STATIC mp_uint_t sock_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int } } -STATIC const mp_rom_map_elem_t socket_locals_dict_table[] = { +static const mp_rom_map_elem_t socket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_stream_close_obj) }, { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) }, { MP_ROM_QSTR(MP_QSTR_bind), MP_ROM_PTR(&socket_bind_obj) }, @@ -344,15 +344,15 @@ STATIC const mp_rom_map_elem_t socket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) }, { MP_ROM_QSTR(MP_QSTR_makefile), MP_ROM_PTR(&socket_makefile_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(socket_locals_dict, socket_locals_dict_table); +static MP_DEFINE_CONST_DICT(socket_locals_dict, socket_locals_dict_table); -STATIC const mp_stream_p_t socket_stream_p = { +static const mp_stream_p_t socket_stream_p = { .read = sock_read, .write = sock_write, .ioctl = sock_ioctl, }; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( socket_type, MP_QSTR_socket, MP_TYPE_FLAG_NONE, @@ -397,7 +397,7 @@ void dns_resolve_cb(enum dns_resolve_status status, struct dns_addrinfo *info, v mp_obj_list_append(state->result, MP_OBJ_FROM_PTR(tuple)); } -STATIC mp_obj_t mod_getaddrinfo(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_getaddrinfo(size_t n_args, const mp_obj_t *args) { mp_obj_t host_in = args[0], port_in = args[1]; const char *host = mp_obj_str_get_str(host_in); mp_int_t family = 0; @@ -431,10 +431,10 @@ STATIC mp_obj_t mod_getaddrinfo(size_t n_args, const mp_obj_t *args) { return state.result; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_getaddrinfo_obj, 2, 3, mod_getaddrinfo); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_getaddrinfo_obj, 2, 3, mod_getaddrinfo); -STATIC mp_obj_t pkt_get_info(void) { +static mp_obj_t pkt_get_info(void) { struct k_mem_slab *rx, *tx; struct net_buf_pool *rx_data, *tx_data; net_pkt_get_info(&rx, &tx, &rx_data, &tx_data); @@ -445,9 +445,9 @@ STATIC mp_obj_t pkt_get_info(void) { t->items[3] = MP_OBJ_NEW_SMALL_INT(tx_data->avail_count); return MP_OBJ_FROM_PTR(t); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(pkt_get_info_obj, pkt_get_info); +static MP_DEFINE_CONST_FUN_OBJ_0(pkt_get_info_obj, pkt_get_info); -STATIC const mp_rom_map_elem_t mp_module_socket_globals_table[] = { +static const mp_rom_map_elem_t mp_module_socket_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_socket) }, // objects { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&socket_type) }, @@ -465,7 +465,7 @@ STATIC const mp_rom_map_elem_t mp_module_socket_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_pkt_get_info), MP_ROM_PTR(&pkt_get_info_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_socket_globals, mp_module_socket_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_socket_globals, mp_module_socket_globals_table); const mp_obj_module_t mp_module_socket = { .base = { &mp_type_module }, diff --git a/ports/zephyr/modtime.c b/ports/zephyr/modtime.c index 65ba1e6e6917c..f1181232ae2df 100644 --- a/ports/zephyr/modtime.c +++ b/ports/zephyr/modtime.c @@ -29,7 +29,7 @@ #include "py/obj.h" -STATIC mp_obj_t mp_time_time_get(void) { +static mp_obj_t mp_time_time_get(void) { /* The absence of FP support is deliberate. The Zephyr port uses * single precision floats so the fraction component will start to * lose precision on devices with a long uptime. diff --git a/ports/zephyr/modzephyr.c b/ports/zephyr/modzephyr.c index f87e2e33f3c78..2e3fc2fecf533 100644 --- a/ports/zephyr/modzephyr.c +++ b/ports/zephyr/modzephyr.c @@ -37,34 +37,34 @@ #include "modzephyr.h" #include "py/runtime.h" -STATIC mp_obj_t mod_is_preempt_thread(void) { +static mp_obj_t mod_is_preempt_thread(void) { return mp_obj_new_bool(k_is_preempt_thread()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_is_preempt_thread_obj, mod_is_preempt_thread); +static MP_DEFINE_CONST_FUN_OBJ_0(mod_is_preempt_thread_obj, mod_is_preempt_thread); -STATIC mp_obj_t mod_current_tid(void) { +static mp_obj_t mod_current_tid(void) { return MP_OBJ_NEW_SMALL_INT(k_current_get()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_current_tid_obj, mod_current_tid); +static MP_DEFINE_CONST_FUN_OBJ_0(mod_current_tid_obj, mod_current_tid); #ifdef CONFIG_THREAD_ANALYZER -STATIC mp_obj_t mod_thread_analyze(void) { +static mp_obj_t mod_thread_analyze(void) { thread_analyzer_print(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_thread_analyze_obj, mod_thread_analyze); +static MP_DEFINE_CONST_FUN_OBJ_0(mod_thread_analyze_obj, mod_thread_analyze); #endif #ifdef CONFIG_SHELL_BACKEND_SERIAL -STATIC mp_obj_t mod_shell_exec(mp_obj_t cmd_in) { +static mp_obj_t mod_shell_exec(mp_obj_t cmd_in) { const char *cmd = mp_obj_str_get_str(cmd_in); shell_execute_cmd(shell_backend_uart_get_ptr(), cmd); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_shell_exec_obj, mod_shell_exec); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_shell_exec_obj, mod_shell_exec); #endif // CONFIG_SHELL_BACKEND_SERIAL -STATIC const mp_rom_map_elem_t mp_module_time_globals_table[] = { +static const mp_rom_map_elem_t mp_module_time_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_zephyr) }, { MP_ROM_QSTR(MP_QSTR_is_preempt_thread), MP_ROM_PTR(&mod_is_preempt_thread_obj) }, { MP_ROM_QSTR(MP_QSTR_current_tid), MP_ROM_PTR(&mod_current_tid_obj) }, @@ -82,7 +82,7 @@ STATIC const mp_rom_map_elem_t mp_module_time_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_time_globals, mp_module_time_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_time_globals, mp_module_time_globals_table); const mp_obj_module_t mp_module_zephyr = { .base = { &mp_type_module }, diff --git a/ports/zephyr/modzsensor.c b/ports/zephyr/modzsensor.c index 5b55f0ebbaa1e..2a7278a61481e 100644 --- a/ports/zephyr/modzsensor.c +++ b/ports/zephyr/modzsensor.c @@ -38,7 +38,7 @@ typedef struct _mp_obj_sensor_t { const struct device *dev; } mp_obj_sensor_t; -STATIC mp_obj_t sensor_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t sensor_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 1, false); mp_obj_sensor_t *o = mp_obj_malloc(mp_obj_sensor_t, type); o->dev = device_get_binding(mp_obj_str_get_str(args[0])); @@ -48,7 +48,7 @@ STATIC mp_obj_t sensor_make_new(const mp_obj_type_t *type, size_t n_args, size_t return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t sensor_measure(mp_obj_t self_in) { +static mp_obj_t sensor_measure(mp_obj_t self_in) { mp_obj_sensor_t *self = MP_OBJ_TO_PTR(self_in); int st = sensor_sample_fetch(self->dev); if (st != 0) { @@ -58,7 +58,7 @@ STATIC mp_obj_t sensor_measure(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(sensor_measure_obj, sensor_measure); -STATIC void sensor_get_internal(mp_obj_t self_in, mp_obj_t channel_in, struct sensor_value *res) { +static void sensor_get_internal(mp_obj_t self_in, mp_obj_t channel_in, struct sensor_value *res) { mp_obj_sensor_t *self = MP_OBJ_TO_PTR(self_in); int st = sensor_channel_get(self->dev, mp_obj_get_int(channel_in), res); @@ -67,35 +67,35 @@ STATIC void sensor_get_internal(mp_obj_t self_in, mp_obj_t channel_in, struct se } } -STATIC mp_obj_t sensor_get_float(mp_obj_t self_in, mp_obj_t channel_in) { +static mp_obj_t sensor_get_float(mp_obj_t self_in, mp_obj_t channel_in) { struct sensor_value val; sensor_get_internal(self_in, channel_in, &val); return mp_obj_new_float(val.val1 + (mp_float_t)val.val2 / 1000000); } MP_DEFINE_CONST_FUN_OBJ_2(sensor_get_float_obj, sensor_get_float); -STATIC mp_obj_t sensor_get_micros(mp_obj_t self_in, mp_obj_t channel_in) { +static mp_obj_t sensor_get_micros(mp_obj_t self_in, mp_obj_t channel_in) { struct sensor_value val; sensor_get_internal(self_in, channel_in, &val); return MP_OBJ_NEW_SMALL_INT(val.val1 * 1000000 + val.val2); } MP_DEFINE_CONST_FUN_OBJ_2(sensor_get_micros_obj, sensor_get_micros); -STATIC mp_obj_t sensor_get_millis(mp_obj_t self_in, mp_obj_t channel_in) { +static mp_obj_t sensor_get_millis(mp_obj_t self_in, mp_obj_t channel_in) { struct sensor_value val; sensor_get_internal(self_in, channel_in, &val); return MP_OBJ_NEW_SMALL_INT(val.val1 * 1000 + val.val2 / 1000); } MP_DEFINE_CONST_FUN_OBJ_2(sensor_get_millis_obj, sensor_get_millis); -STATIC mp_obj_t sensor_get_int(mp_obj_t self_in, mp_obj_t channel_in) { +static mp_obj_t sensor_get_int(mp_obj_t self_in, mp_obj_t channel_in) { struct sensor_value val; sensor_get_internal(self_in, channel_in, &val); return MP_OBJ_NEW_SMALL_INT(val.val1); } MP_DEFINE_CONST_FUN_OBJ_2(sensor_get_int_obj, sensor_get_int); -STATIC const mp_rom_map_elem_t sensor_locals_dict_table[] = { +static const mp_rom_map_elem_t sensor_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_measure), MP_ROM_PTR(&sensor_measure_obj) }, { MP_ROM_QSTR(MP_QSTR_get_float), MP_ROM_PTR(&sensor_get_float_obj) }, { MP_ROM_QSTR(MP_QSTR_get_micros), MP_ROM_PTR(&sensor_get_micros_obj) }, @@ -103,9 +103,9 @@ STATIC const mp_rom_map_elem_t sensor_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_get_int), MP_ROM_PTR(&sensor_get_int_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(sensor_locals_dict, sensor_locals_dict_table); +static MP_DEFINE_CONST_DICT(sensor_locals_dict, sensor_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( sensor_type, MP_QSTR_Sensor, MP_TYPE_FLAG_NONE, @@ -113,7 +113,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &sensor_locals_dict ); -STATIC const mp_rom_map_elem_t mp_module_zsensor_globals_table[] = { +static const mp_rom_map_elem_t mp_module_zsensor_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_zsensor) }, { MP_ROM_QSTR(MP_QSTR_Sensor), MP_ROM_PTR(&sensor_type) }, @@ -136,7 +136,7 @@ STATIC const mp_rom_map_elem_t mp_module_zsensor_globals_table[] = { #undef C }; -STATIC MP_DEFINE_CONST_DICT(mp_module_zsensor_globals, mp_module_zsensor_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_zsensor_globals, mp_module_zsensor_globals_table); const mp_obj_module_t mp_module_zsensor = { .base = { &mp_type_module }, diff --git a/ports/zephyr/zephyr_storage.c b/ports/zephyr/zephyr_storage.c index 498fea6fb1c8d..af1772205e06c 100644 --- a/ports/zephyr/zephyr_storage.c +++ b/ports/zephyr/zephyr_storage.c @@ -47,12 +47,12 @@ typedef struct _zephyr_disk_access_obj_t { int block_count; } zephyr_disk_access_obj_t; -STATIC void zephyr_disk_access_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void zephyr_disk_access_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { zephyr_disk_access_obj_t *self = self_in; mp_printf(print, "DiskAccess(%s)", self->pdrv); } -STATIC mp_obj_t zephyr_disk_access_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t zephyr_disk_access_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 1, false); zephyr_disk_access_obj_t *self = mp_obj_malloc(zephyr_disk_access_obj_t, type); self->pdrv = mp_obj_str_get_str(args[0]); @@ -72,7 +72,7 @@ STATIC mp_obj_t zephyr_disk_access_make_new(const mp_obj_type_t *type, size_t n_ return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t zephyr_disk_access_readblocks(mp_obj_t self_in, mp_obj_t block_num, mp_obj_t buf) { +static mp_obj_t zephyr_disk_access_readblocks(mp_obj_t self_in, mp_obj_t block_num, mp_obj_t buf) { zephyr_disk_access_obj_t *self = self_in; mp_buffer_info_t bufinfo; int ret; @@ -81,9 +81,9 @@ STATIC mp_obj_t zephyr_disk_access_readblocks(mp_obj_t self_in, mp_obj_t block_n ret = disk_access_read(self->pdrv, bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / self->block_size); return MP_OBJ_NEW_SMALL_INT(ret); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(zephyr_disk_access_readblocks_obj, zephyr_disk_access_readblocks); +static MP_DEFINE_CONST_FUN_OBJ_3(zephyr_disk_access_readblocks_obj, zephyr_disk_access_readblocks); -STATIC mp_obj_t zephyr_disk_access_writeblocks(mp_obj_t self_in, mp_obj_t block_num, mp_obj_t buf) { +static mp_obj_t zephyr_disk_access_writeblocks(mp_obj_t self_in, mp_obj_t block_num, mp_obj_t buf) { zephyr_disk_access_obj_t *self = self_in; mp_buffer_info_t bufinfo; int ret; @@ -92,9 +92,9 @@ STATIC mp_obj_t zephyr_disk_access_writeblocks(mp_obj_t self_in, mp_obj_t block_ ret = disk_access_write(self->pdrv, bufinfo.buf, mp_obj_get_int(block_num), bufinfo.len / self->block_size); return MP_OBJ_NEW_SMALL_INT(ret); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(zephyr_disk_access_writeblocks_obj, zephyr_disk_access_writeblocks); +static MP_DEFINE_CONST_FUN_OBJ_3(zephyr_disk_access_writeblocks_obj, zephyr_disk_access_writeblocks); -STATIC mp_obj_t zephyr_disk_access_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { +static mp_obj_t zephyr_disk_access_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { zephyr_disk_access_obj_t *self = self_in; mp_int_t cmd = mp_obj_get_int(cmd_in); int buf; @@ -119,14 +119,14 @@ STATIC mp_obj_t zephyr_disk_access_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_o return MP_OBJ_NEW_SMALL_INT(-1); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(zephyr_disk_access_ioctl_obj, zephyr_disk_access_ioctl); +static MP_DEFINE_CONST_FUN_OBJ_3(zephyr_disk_access_ioctl_obj, zephyr_disk_access_ioctl); -STATIC const mp_rom_map_elem_t zephyr_disk_access_locals_dict_table[] = { +static const mp_rom_map_elem_t zephyr_disk_access_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&zephyr_disk_access_readblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&zephyr_disk_access_writeblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&zephyr_disk_access_ioctl_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(zephyr_disk_access_locals_dict, zephyr_disk_access_locals_dict_table); +static MP_DEFINE_CONST_DICT(zephyr_disk_access_locals_dict, zephyr_disk_access_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( zephyr_disk_access_type, @@ -149,12 +149,12 @@ typedef struct _zephyr_flash_area_obj_t { uint8_t id; } zephyr_flash_area_obj_t; -STATIC void zephyr_flash_area_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void zephyr_flash_area_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { zephyr_flash_area_obj_t *self = self_in; mp_printf(print, "FlashArea(%d)", self->id); } -STATIC mp_obj_t zephyr_flash_area_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t zephyr_flash_area_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 2, 2, false); zephyr_flash_area_obj_t *self = mp_obj_malloc(zephyr_flash_area_obj_t, type); self->id = mp_obj_get_int(args[0]); @@ -173,7 +173,7 @@ STATIC mp_obj_t zephyr_flash_area_make_new(const mp_obj_type_t *type, size_t n_a return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t zephyr_flash_area_readblocks(size_t n_args, const mp_obj_t *args) { +static mp_obj_t zephyr_flash_area_readblocks(size_t n_args, const mp_obj_t *args) { zephyr_flash_area_obj_t *self = MP_OBJ_TO_PTR(args[0]); uint32_t block_num = mp_obj_get_int(args[1]); off_t offset = block_num * self->block_size; @@ -188,9 +188,9 @@ STATIC mp_obj_t zephyr_flash_area_readblocks(size_t n_args, const mp_obj_t *args ret = flash_area_read(self->area, offset, bufinfo.buf, bufinfo.len); return MP_OBJ_NEW_SMALL_INT(ret); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(zephyr_flash_area_readblocks_obj, 3, 4, zephyr_flash_area_readblocks); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(zephyr_flash_area_readblocks_obj, 3, 4, zephyr_flash_area_readblocks); -STATIC mp_obj_t zephyr_flash_area_writeblocks(size_t n_args, const mp_obj_t *args) { +static mp_obj_t zephyr_flash_area_writeblocks(size_t n_args, const mp_obj_t *args) { zephyr_flash_area_obj_t *self = MP_OBJ_TO_PTR(args[0]); uint32_t block_num = mp_obj_get_int(args[1]); off_t offset = block_num * self->block_size; @@ -210,9 +210,9 @@ STATIC mp_obj_t zephyr_flash_area_writeblocks(size_t n_args, const mp_obj_t *arg ret = flash_area_write(self->area, offset, bufinfo.buf, bufinfo.len); return MP_OBJ_NEW_SMALL_INT(ret); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(zephyr_flash_area_writeblocks_obj, 3, 4, zephyr_flash_area_writeblocks); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(zephyr_flash_area_writeblocks_obj, 3, 4, zephyr_flash_area_writeblocks); -STATIC mp_obj_t zephyr_flash_area_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { +static mp_obj_t zephyr_flash_area_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { zephyr_flash_area_obj_t *self = self_in; mp_int_t cmd = mp_obj_get_int(cmd_in); mp_int_t block_num = mp_obj_get_int(arg_in); @@ -238,9 +238,9 @@ STATIC mp_obj_t zephyr_flash_area_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_ob return MP_OBJ_NEW_SMALL_INT(-1); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(zephyr_flash_area_ioctl_obj, zephyr_flash_area_ioctl); +static MP_DEFINE_CONST_FUN_OBJ_3(zephyr_flash_area_ioctl_obj, zephyr_flash_area_ioctl); -STATIC const mp_rom_map_elem_t zephyr_flash_area_locals_dict_table[] = { +static const mp_rom_map_elem_t zephyr_flash_area_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&zephyr_flash_area_readblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&zephyr_flash_area_writeblocks_obj) }, { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&zephyr_flash_area_ioctl_obj) }, @@ -248,7 +248,7 @@ STATIC const mp_rom_map_elem_t zephyr_flash_area_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_STORAGE), MP_ROM_INT(FLASH_AREA_ID(storage)) }, #endif }; -STATIC MP_DEFINE_CONST_DICT(zephyr_flash_area_locals_dict, zephyr_flash_area_locals_dict_table); +static MP_DEFINE_CONST_DICT(zephyr_flash_area_locals_dict, zephyr_flash_area_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( zephyr_flash_area_type, diff --git a/py/asmarm.c b/py/asmarm.c index 42724e4d4b37c..cd346949eb0db 100644 --- a/py/asmarm.c +++ b/py/asmarm.c @@ -39,7 +39,7 @@ #define SIGNED_FIT24(x) (((x) & 0xff800000) == 0) || (((x) & 0xff000000) == 0xff000000) // Insert word into instruction flow -STATIC void emit(asm_arm_t *as, uint op) { +static void emit(asm_arm_t *as, uint op) { uint8_t *c = mp_asm_base_get_cur_to_write_bytes(&as->base, 4); if (c != NULL) { *(uint32_t *)c = op; @@ -47,73 +47,73 @@ STATIC void emit(asm_arm_t *as, uint op) { } // Insert word into instruction flow, add "ALWAYS" condition code -STATIC void emit_al(asm_arm_t *as, uint op) { +static void emit_al(asm_arm_t *as, uint op) { emit(as, op | ASM_ARM_CC_AL); } // Basic instructions without condition code -STATIC uint asm_arm_op_push(uint reglist) { +static uint asm_arm_op_push(uint reglist) { // stmfd sp!, {reglist} return 0x92d0000 | (reglist & 0xFFFF); } -STATIC uint asm_arm_op_pop(uint reglist) { +static uint asm_arm_op_pop(uint reglist) { // ldmfd sp!, {reglist} return 0x8bd0000 | (reglist & 0xFFFF); } -STATIC uint asm_arm_op_mov_reg(uint rd, uint rn) { +static uint asm_arm_op_mov_reg(uint rd, uint rn) { // mov rd, rn return 0x1a00000 | (rd << 12) | rn; } -STATIC uint asm_arm_op_mov_imm(uint rd, uint imm) { +static uint asm_arm_op_mov_imm(uint rd, uint imm) { // mov rd, #imm return 0x3a00000 | (rd << 12) | imm; } -STATIC uint asm_arm_op_mvn_imm(uint rd, uint imm) { +static uint asm_arm_op_mvn_imm(uint rd, uint imm) { // mvn rd, #imm return 0x3e00000 | (rd << 12) | imm; } -STATIC uint asm_arm_op_add_imm(uint rd, uint rn, uint imm) { +static uint asm_arm_op_add_imm(uint rd, uint rn, uint imm) { // add rd, rn, #imm return 0x2800000 | (rn << 16) | (rd << 12) | (imm & 0xFF); } -STATIC uint asm_arm_op_add_reg(uint rd, uint rn, uint rm) { +static uint asm_arm_op_add_reg(uint rd, uint rn, uint rm) { // add rd, rn, rm return 0x0800000 | (rn << 16) | (rd << 12) | rm; } -STATIC uint asm_arm_op_sub_imm(uint rd, uint rn, uint imm) { +static uint asm_arm_op_sub_imm(uint rd, uint rn, uint imm) { // sub rd, rn, #imm return 0x2400000 | (rn << 16) | (rd << 12) | (imm & 0xFF); } -STATIC uint asm_arm_op_sub_reg(uint rd, uint rn, uint rm) { +static uint asm_arm_op_sub_reg(uint rd, uint rn, uint rm) { // sub rd, rn, rm return 0x0400000 | (rn << 16) | (rd << 12) | rm; } -STATIC uint asm_arm_op_mul_reg(uint rd, uint rm, uint rs) { +static uint asm_arm_op_mul_reg(uint rd, uint rm, uint rs) { // mul rd, rm, rs assert(rd != rm); return 0x0000090 | (rd << 16) | (rs << 8) | rm; } -STATIC uint asm_arm_op_and_reg(uint rd, uint rn, uint rm) { +static uint asm_arm_op_and_reg(uint rd, uint rn, uint rm) { // and rd, rn, rm return 0x0000000 | (rn << 16) | (rd << 12) | rm; } -STATIC uint asm_arm_op_eor_reg(uint rd, uint rn, uint rm) { +static uint asm_arm_op_eor_reg(uint rd, uint rn, uint rm) { // eor rd, rn, rm return 0x0200000 | (rn << 16) | (rd << 12) | rm; } -STATIC uint asm_arm_op_orr_reg(uint rd, uint rn, uint rm) { +static uint asm_arm_op_orr_reg(uint rd, uint rn, uint rm) { // orr rd, rn, rm return 0x1800000 | (rn << 16) | (rd << 12) | rm; } diff --git a/py/asmthumb.c b/py/asmthumb.c index 395134028aaa9..0df79e5fd6203 100644 --- a/py/asmthumb.c +++ b/py/asmthumb.c @@ -79,7 +79,7 @@ static inline byte *asm_thumb_get_cur_to_write_bytes(asm_thumb_t *as, int n) { } /* -STATIC void asm_thumb_write_byte_1(asm_thumb_t *as, byte b1) { +static void asm_thumb_write_byte_1(asm_thumb_t *as, byte b1) { byte *c = asm_thumb_get_cur_to_write_bytes(as, 1); c[0] = b1; } @@ -91,7 +91,7 @@ STATIC void asm_thumb_write_byte_1(asm_thumb_t *as, byte b1) { #define IMM32_L2(x) (((x) >> 16) & 0xff) #define IMM32_L3(x) (((x) >> 24) & 0xff) -STATIC void asm_thumb_write_word32(asm_thumb_t *as, int w32) { +static void asm_thumb_write_word32(asm_thumb_t *as, int w32) { byte *c = asm_thumb_get_cur_to_write_bytes(as, 4); c[0] = IMM32_L0(w32); c[1] = IMM32_L1(w32); @@ -216,7 +216,7 @@ void asm_thumb_exit(asm_thumb_t *as) { asm_thumb_op16(as, OP_POP_RLIST_PC(as->push_reglist)); } -STATIC mp_uint_t get_label_dest(asm_thumb_t *as, uint label) { +static mp_uint_t get_label_dest(asm_thumb_t *as, uint label) { assert(label < as->base.max_num_labels); return as->base.label_offsets[label]; } diff --git a/py/asmx64.c b/py/asmx64.c index 5c923a523ca54..abddc162696c0 100644 --- a/py/asmx64.c +++ b/py/asmx64.c @@ -123,14 +123,14 @@ static inline byte *asm_x64_get_cur_to_write_bytes(asm_x64_t *as, int n) { return mp_asm_base_get_cur_to_write_bytes(&as->base, n); } -STATIC void asm_x64_write_byte_1(asm_x64_t *as, byte b1) { +static void asm_x64_write_byte_1(asm_x64_t *as, byte b1) { byte *c = asm_x64_get_cur_to_write_bytes(as, 1); if (c != NULL) { c[0] = b1; } } -STATIC void asm_x64_write_byte_2(asm_x64_t *as, byte b1, byte b2) { +static void asm_x64_write_byte_2(asm_x64_t *as, byte b1, byte b2) { byte *c = asm_x64_get_cur_to_write_bytes(as, 2); if (c != NULL) { c[0] = b1; @@ -138,7 +138,7 @@ STATIC void asm_x64_write_byte_2(asm_x64_t *as, byte b1, byte b2) { } } -STATIC void asm_x64_write_byte_3(asm_x64_t *as, byte b1, byte b2, byte b3) { +static void asm_x64_write_byte_3(asm_x64_t *as, byte b1, byte b2, byte b3) { byte *c = asm_x64_get_cur_to_write_bytes(as, 3); if (c != NULL) { c[0] = b1; @@ -147,7 +147,7 @@ STATIC void asm_x64_write_byte_3(asm_x64_t *as, byte b1, byte b2, byte b3) { } } -STATIC void asm_x64_write_word32(asm_x64_t *as, int w32) { +static void asm_x64_write_word32(asm_x64_t *as, int w32) { byte *c = asm_x64_get_cur_to_write_bytes(as, 4); if (c != NULL) { c[0] = IMM32_L0(w32); @@ -157,7 +157,7 @@ STATIC void asm_x64_write_word32(asm_x64_t *as, int w32) { } } -STATIC void asm_x64_write_word64(asm_x64_t *as, int64_t w64) { +static void asm_x64_write_word64(asm_x64_t *as, int64_t w64) { byte *c = asm_x64_get_cur_to_write_bytes(as, 8); if (c != NULL) { c[0] = IMM32_L0(w64); @@ -172,7 +172,7 @@ STATIC void asm_x64_write_word64(asm_x64_t *as, int64_t w64) { } /* unused -STATIC void asm_x64_write_word32_to(asm_x64_t *as, int offset, int w32) { +static void asm_x64_write_word32_to(asm_x64_t *as, int offset, int w32) { byte* c; assert(offset + 4 <= as->code_size); c = as->code_base + offset; @@ -183,7 +183,7 @@ STATIC void asm_x64_write_word32_to(asm_x64_t *as, int offset, int w32) { } */ -STATIC void asm_x64_write_r64_disp(asm_x64_t *as, int r64, int disp_r64, int disp_offset) { +static void asm_x64_write_r64_disp(asm_x64_t *as, int r64, int disp_r64, int disp_offset) { uint8_t rm_disp; if (disp_offset == 0 && (disp_r64 & 7) != ASM_X64_REG_RBP) { rm_disp = MODRM_RM_DISP0; @@ -204,7 +204,7 @@ STATIC void asm_x64_write_r64_disp(asm_x64_t *as, int r64, int disp_r64, int dis } } -STATIC void asm_x64_generic_r64_r64(asm_x64_t *as, int dest_r64, int src_r64, int op) { +static void asm_x64_generic_r64_r64(asm_x64_t *as, int dest_r64, int src_r64, int op) { asm_x64_write_byte_3(as, REX_PREFIX | REX_W | REX_R_FROM_R64(src_r64) | REX_B_FROM_R64(dest_r64), op, MODRM_R64(src_r64) | MODRM_RM_REG | MODRM_RM_R64(dest_r64)); } @@ -243,7 +243,7 @@ void asm_x64_pop_r64(asm_x64_t *as, int dest_r64) { } } -STATIC void asm_x64_ret(asm_x64_t *as) { +static void asm_x64_ret(asm_x64_t *as) { asm_x64_write_byte_1(as, OPCODE_RET); } @@ -317,7 +317,7 @@ void asm_x64_mov_mem64_to_r64(asm_x64_t *as, int src_r64, int src_disp, int dest asm_x64_write_r64_disp(as, dest_r64, src_r64, src_disp); } -STATIC void asm_x64_lea_disp_to_r64(asm_x64_t *as, int src_r64, int src_disp, int dest_r64) { +static void asm_x64_lea_disp_to_r64(asm_x64_t *as, int src_r64, int src_disp, int dest_r64) { // use REX prefix for 64 bit operation asm_x64_write_byte_2(as, REX_PREFIX | REX_W | REX_R_FROM_R64(dest_r64) | REX_B_FROM_R64(src_r64), OPCODE_LEA_MEM_TO_R64); asm_x64_write_r64_disp(as, dest_r64, src_r64, src_disp); @@ -414,7 +414,7 @@ void asm_x64_sub_i32_from_r32(asm_x64_t *as, int src_i32, int dest_r32) { } */ -STATIC void asm_x64_sub_r64_i32(asm_x64_t *as, int dest_r64, int src_i32) { +static void asm_x64_sub_r64_i32(asm_x64_t *as, int dest_r64, int src_i32) { assert(dest_r64 < 8); if (SIGNED_FIT8(src_i32)) { // use REX prefix for 64 bit operation @@ -480,7 +480,7 @@ void asm_x64_jmp_reg(asm_x64_t *as, int src_r64) { asm_x64_write_byte_2(as, OPCODE_JMP_RM64, MODRM_R64(4) | MODRM_RM_REG | MODRM_RM_R64(src_r64)); } -STATIC mp_uint_t get_label_dest(asm_x64_t *as, mp_uint_t label) { +static mp_uint_t get_label_dest(asm_x64_t *as, mp_uint_t label) { assert(label < as->base.max_num_labels); return as->base.label_offsets[label]; } @@ -560,7 +560,7 @@ void asm_x64_exit(asm_x64_t *as) { // ^ ^ // | low address | high address in RAM // -STATIC int asm_x64_local_offset_from_rsp(asm_x64_t *as, int local_num) { +static int asm_x64_local_offset_from_rsp(asm_x64_t *as, int local_num) { (void)as; // Stack is full descending, RSP points to local0 return local_num * WORD_SIZE; diff --git a/py/asmx86.c b/py/asmx86.c index 4b0f8047f6eb7..94e0213d65c0f 100644 --- a/py/asmx86.c +++ b/py/asmx86.c @@ -103,14 +103,14 @@ #define SIGNED_FIT8(x) (((x) & 0xffffff80) == 0) || (((x) & 0xffffff80) == 0xffffff80) -STATIC void asm_x86_write_byte_1(asm_x86_t *as, byte b1) { +static void asm_x86_write_byte_1(asm_x86_t *as, byte b1) { byte *c = mp_asm_base_get_cur_to_write_bytes(&as->base, 1); if (c != NULL) { c[0] = b1; } } -STATIC void asm_x86_write_byte_2(asm_x86_t *as, byte b1, byte b2) { +static void asm_x86_write_byte_2(asm_x86_t *as, byte b1, byte b2) { byte *c = mp_asm_base_get_cur_to_write_bytes(&as->base, 2); if (c != NULL) { c[0] = b1; @@ -118,7 +118,7 @@ STATIC void asm_x86_write_byte_2(asm_x86_t *as, byte b1, byte b2) { } } -STATIC void asm_x86_write_byte_3(asm_x86_t *as, byte b1, byte b2, byte b3) { +static void asm_x86_write_byte_3(asm_x86_t *as, byte b1, byte b2, byte b3) { byte *c = mp_asm_base_get_cur_to_write_bytes(&as->base, 3); if (c != NULL) { c[0] = b1; @@ -127,7 +127,7 @@ STATIC void asm_x86_write_byte_3(asm_x86_t *as, byte b1, byte b2, byte b3) { } } -STATIC void asm_x86_write_word32(asm_x86_t *as, int w32) { +static void asm_x86_write_word32(asm_x86_t *as, int w32) { byte *c = mp_asm_base_get_cur_to_write_bytes(&as->base, 4); if (c != NULL) { c[0] = IMM32_L0(w32); @@ -137,7 +137,7 @@ STATIC void asm_x86_write_word32(asm_x86_t *as, int w32) { } } -STATIC void asm_x86_write_r32_disp(asm_x86_t *as, int r32, int disp_r32, int disp_offset) { +static void asm_x86_write_r32_disp(asm_x86_t *as, int r32, int disp_r32, int disp_offset) { uint8_t rm_disp; if (disp_offset == 0 && disp_r32 != ASM_X86_REG_EBP) { rm_disp = MODRM_RM_DISP0; @@ -158,17 +158,17 @@ STATIC void asm_x86_write_r32_disp(asm_x86_t *as, int r32, int disp_r32, int dis } } -STATIC void asm_x86_generic_r32_r32(asm_x86_t *as, int dest_r32, int src_r32, int op) { +static void asm_x86_generic_r32_r32(asm_x86_t *as, int dest_r32, int src_r32, int op) { asm_x86_write_byte_2(as, op, MODRM_R32(src_r32) | MODRM_RM_REG | MODRM_RM_R32(dest_r32)); } #if 0 -STATIC void asm_x86_nop(asm_x86_t *as) { +static void asm_x86_nop(asm_x86_t *as) { asm_x86_write_byte_1(as, OPCODE_NOP); } #endif -STATIC void asm_x86_push_r32(asm_x86_t *as, int src_r32) { +static void asm_x86_push_r32(asm_x86_t *as, int src_r32) { asm_x86_write_byte_1(as, OPCODE_PUSH_R32 | src_r32); } @@ -184,11 +184,11 @@ void asm_x86_push_disp(asm_x86_t *as, int src_r32, int src_offset) { } #endif -STATIC void asm_x86_pop_r32(asm_x86_t *as, int dest_r32) { +static void asm_x86_pop_r32(asm_x86_t *as, int dest_r32) { asm_x86_write_byte_1(as, OPCODE_POP_R32 | dest_r32); } -STATIC void asm_x86_ret(asm_x86_t *as) { +static void asm_x86_ret(asm_x86_t *as) { asm_x86_write_byte_1(as, OPCODE_RET); } @@ -226,7 +226,7 @@ void asm_x86_mov_mem32_to_r32(asm_x86_t *as, int src_r32, int src_disp, int dest asm_x86_write_r32_disp(as, dest_r32, src_r32, src_disp); } -STATIC void asm_x86_lea_disp_to_r32(asm_x86_t *as, int src_r32, int src_disp, int dest_r32) { +static void asm_x86_lea_disp_to_r32(asm_x86_t *as, int src_r32, int src_disp, int dest_r32) { asm_x86_write_byte_1(as, OPCODE_LEA_MEM_TO_R32); asm_x86_write_r32_disp(as, dest_r32, src_r32, src_disp); } @@ -272,7 +272,7 @@ void asm_x86_add_r32_r32(asm_x86_t *as, int dest_r32, int src_r32) { asm_x86_generic_r32_r32(as, dest_r32, src_r32, OPCODE_ADD_R32_TO_RM32); } -STATIC void asm_x86_add_i32_to_r32(asm_x86_t *as, int src_i32, int dest_r32) { +static void asm_x86_add_i32_to_r32(asm_x86_t *as, int src_i32, int dest_r32) { if (SIGNED_FIT8(src_i32)) { asm_x86_write_byte_2(as, OPCODE_ADD_I8_TO_RM32, MODRM_R32(0) | MODRM_RM_REG | MODRM_RM_R32(dest_r32)); asm_x86_write_byte_1(as, src_i32 & 0xff); @@ -286,7 +286,7 @@ void asm_x86_sub_r32_r32(asm_x86_t *as, int dest_r32, int src_r32) { asm_x86_generic_r32_r32(as, dest_r32, src_r32, OPCODE_SUB_R32_FROM_RM32); } -STATIC void asm_x86_sub_r32_i32(asm_x86_t *as, int dest_r32, int src_i32) { +static void asm_x86_sub_r32_i32(asm_x86_t *as, int dest_r32, int src_i32) { if (SIGNED_FIT8(src_i32)) { // defaults to 32 bit operation asm_x86_write_byte_2(as, OPCODE_SUB_I8_FROM_RM32, MODRM_R32(5) | MODRM_RM_REG | MODRM_RM_R32(dest_r32)); @@ -353,7 +353,7 @@ void asm_x86_jmp_reg(asm_x86_t *as, int src_r32) { asm_x86_write_byte_2(as, OPCODE_JMP_RM32, MODRM_R32(4) | MODRM_RM_REG | MODRM_RM_R32(src_r32)); } -STATIC mp_uint_t get_label_dest(asm_x86_t *as, mp_uint_t label) { +static mp_uint_t get_label_dest(asm_x86_t *as, mp_uint_t label) { assert(label < as->base.max_num_labels); return as->base.label_offsets[label]; } @@ -422,7 +422,7 @@ void asm_x86_exit(asm_x86_t *as) { asm_x86_ret(as); } -STATIC int asm_x86_arg_offset_from_esp(asm_x86_t *as, size_t arg_num) { +static int asm_x86_arg_offset_from_esp(asm_x86_t *as, size_t arg_num) { // Above esp are: locals, 4 saved registers, return eip, arguments return (as->num_locals + 4 + 1 + arg_num) * WORD_SIZE; } @@ -454,7 +454,7 @@ void asm_x86_mov_r32_to_arg(asm_x86_t *as, int src_r32, int dest_arg_num) { // ^ ^ // | low address | high address in RAM // -STATIC int asm_x86_local_offset_from_esp(asm_x86_t *as, int local_num) { +static int asm_x86_local_offset_from_esp(asm_x86_t *as, int local_num) { (void)as; // Stack is full descending, ESP points to local0 return local_num * WORD_SIZE; diff --git a/py/asmxtensa.c b/py/asmxtensa.c index 8ac914ec412a4..84018402f69e9 100644 --- a/py/asmxtensa.c +++ b/py/asmxtensa.c @@ -117,7 +117,7 @@ void asm_xtensa_exit_win(asm_xtensa_t *as) { asm_xtensa_op_retw_n(as); } -STATIC uint32_t get_label_dest(asm_xtensa_t *as, uint label) { +static uint32_t get_label_dest(asm_xtensa_t *as, uint label) { assert(label < as->base.max_num_labels); return as->base.label_offsets[label]; } diff --git a/py/bc.c b/py/bc.c index dc70fddf2bca7..899dbd6a0727d 100644 --- a/py/bc.c +++ b/py/bc.c @@ -88,7 +88,7 @@ const byte *mp_decode_uint_skip(const byte *ptr) { return ptr; } -STATIC NORETURN void fun_pos_args_mismatch(mp_obj_fun_bc_t *f, size_t expected, size_t given) { +static NORETURN void fun_pos_args_mismatch(mp_obj_fun_bc_t *f, size_t expected, size_t given) { #if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE // generic message, used also for other argument issues (void)f; @@ -107,7 +107,7 @@ STATIC NORETURN void fun_pos_args_mismatch(mp_obj_fun_bc_t *f, size_t expected, } #if DEBUG_PRINT -STATIC void dump_args(const mp_obj_t *a, size_t sz) { +static void dump_args(const mp_obj_t *a, size_t sz) { DEBUG_printf("%p: ", a); for (size_t i = 0; i < sz; i++) { DEBUG_printf("%p ", a[i]); @@ -124,7 +124,7 @@ STATIC void dump_args(const mp_obj_t *a, size_t sz) { // - code_state->ip should contain a pointer to the beginning of the prelude // - code_state->sp should be: &code_state->state[0] - 1 // - code_state->n_state should be the number of objects in the local state -STATIC void mp_setup_code_state_helper(mp_code_state_t *code_state, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static void mp_setup_code_state_helper(mp_code_state_t *code_state, size_t n_args, size_t n_kw, const mp_obj_t *args) { // This function is pretty complicated. It's main aim is to be efficient in speed and RAM // usage for the common case of positional only args. diff --git a/py/builtinevex.c b/py/builtinevex.c index 7737e67f2cd22..e25cbd4d08502 100644 --- a/py/builtinevex.c +++ b/py/builtinevex.c @@ -38,13 +38,13 @@ typedef struct _mp_obj_code_t { mp_obj_t module_fun; } mp_obj_code_t; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_code, MP_QSTR_code, MP_TYPE_FLAG_NONE ); -STATIC mp_obj_t code_execute(mp_obj_code_t *self, mp_obj_dict_t *globals, mp_obj_dict_t *locals) { +static mp_obj_t code_execute(mp_obj_code_t *self, mp_obj_dict_t *globals, mp_obj_dict_t *locals) { // save context nlr_jump_callback_node_globals_locals_t ctx; ctx.globals = mp_globals_get(); @@ -78,7 +78,7 @@ STATIC mp_obj_t code_execute(mp_obj_code_t *self, mp_obj_dict_t *globals, mp_obj return ret; } -STATIC mp_obj_t mp_builtin_compile(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_builtin_compile(size_t n_args, const mp_obj_t *args) { (void)n_args; // get the source @@ -118,7 +118,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_compile_obj, 3, 6, mp_builtin_com #if MICROPY_PY_BUILTINS_EVAL_EXEC -STATIC mp_obj_t eval_exec_helper(size_t n_args, const mp_obj_t *args, mp_parse_input_kind_t parse_input_kind) { +static mp_obj_t eval_exec_helper(size_t n_args, const mp_obj_t *args, mp_parse_input_kind_t parse_input_kind) { // work out the context mp_obj_dict_t *globals = mp_globals_get(); mp_obj_dict_t *locals = mp_locals_get(); @@ -158,12 +158,12 @@ STATIC mp_obj_t eval_exec_helper(size_t n_args, const mp_obj_t *args, mp_parse_i return mp_parse_compile_execute(lex, parse_input_kind, globals, locals); } -STATIC mp_obj_t mp_builtin_eval(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_builtin_eval(size_t n_args, const mp_obj_t *args) { return eval_exec_helper(n_args, args, MP_PARSE_EVAL_INPUT); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_eval_obj, 1, 3, mp_builtin_eval); -STATIC mp_obj_t mp_builtin_exec(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_builtin_exec(size_t n_args, const mp_obj_t *args) { return eval_exec_helper(n_args, args, MP_PARSE_FILE_INPUT); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_exec_obj, 1, 3, mp_builtin_exec); @@ -171,7 +171,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_exec_obj, 1, 3, mp_builtin_exec); #endif // MICROPY_PY_BUILTINS_EVAL_EXEC #if MICROPY_PY_BUILTINS_EXECFILE -STATIC mp_obj_t mp_builtin_execfile(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_builtin_execfile(size_t n_args, const mp_obj_t *args) { // MP_PARSE_SINGLE_INPUT is used to indicate a file input return eval_exec_helper(n_args, args, MP_PARSE_SINGLE_INPUT); } diff --git a/py/builtinhelp.c b/py/builtinhelp.c index 9bd56cca0962e..a3fcc4dfb77c6 100644 --- a/py/builtinhelp.c +++ b/py/builtinhelp.c @@ -47,7 +47,7 @@ const char mp_help_default_text[] = "For further help on a specific object, type help(obj)\n" ; -STATIC void mp_help_print_info_about_object(mp_obj_t name_o, mp_obj_t value) { +static void mp_help_print_info_about_object(mp_obj_t name_o, mp_obj_t value) { mp_print_str(MP_PYTHON_PRINTER, " "); mp_obj_print(name_o, PRINT_STR); mp_print_str(MP_PYTHON_PRINTER, " -- "); @@ -56,7 +56,7 @@ STATIC void mp_help_print_info_about_object(mp_obj_t name_o, mp_obj_t value) { } #if MICROPY_PY_BUILTINS_HELP_MODULES -STATIC void mp_help_add_from_map(mp_obj_t list, const mp_map_t *map) { +static void mp_help_add_from_map(mp_obj_t list, const mp_map_t *map) { for (size_t i = 0; i < map->alloc; i++) { if (mp_map_slot_is_filled(map, i)) { mp_obj_list_append(list, map->table[i].key); @@ -65,7 +65,7 @@ STATIC void mp_help_add_from_map(mp_obj_t list, const mp_map_t *map) { } #if MICROPY_MODULE_FROZEN -STATIC void mp_help_add_from_names(mp_obj_t list, const char *name) { +static void mp_help_add_from_names(mp_obj_t list, const char *name) { while (*name) { size_t len = strlen(name); // name should end in '.py' and we strip it off @@ -75,7 +75,7 @@ STATIC void mp_help_add_from_names(mp_obj_t list, const char *name) { } #endif -STATIC void mp_help_print_modules(void) { +static void mp_help_print_modules(void) { mp_obj_t list = mp_obj_new_list(0, NULL); mp_help_add_from_map(list, &mp_builtin_module_map); @@ -122,7 +122,7 @@ STATIC void mp_help_print_modules(void) { } #endif -STATIC void mp_help_print_obj(const mp_obj_t obj) { +static void mp_help_print_obj(const mp_obj_t obj) { #if MICROPY_PY_BUILTINS_HELP_MODULES if (obj == MP_OBJ_NEW_QSTR(MP_QSTR_modules)) { mp_help_print_modules(); @@ -158,7 +158,7 @@ STATIC void mp_help_print_obj(const mp_obj_t obj) { } } -STATIC mp_obj_t mp_builtin_help(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_builtin_help(size_t n_args, const mp_obj_t *args) { if (n_args == 0) { // print a general help message mp_print_str(MP_PYTHON_PRINTER, MICROPY_PY_BUILTINS_HELP_TEXT); diff --git a/py/builtinimport.c b/py/builtinimport.c index 002a5cb853529..0611926fdd52a 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -57,7 +57,7 @@ // uses mp_vfs_import_stat) to also search frozen modules. Given an exact // path to a file or directory (e.g. "foo/bar", foo/bar.py" or "foo/bar.mpy"), // will return whether the path is a file, directory, or doesn't exist. -STATIC mp_import_stat_t stat_path(vstr_t *path) { +static mp_import_stat_t stat_path(vstr_t *path) { const char *str = vstr_null_terminated_str(path); #if MICROPY_MODULE_FROZEN // Only try and load as a frozen module if it starts with .frozen/. @@ -75,7 +75,7 @@ STATIC mp_import_stat_t stat_path(vstr_t *path) { // argument. This is the logic that makes .py files take precedent over .mpy // files. This uses stat_path above, rather than mp_import_stat directly, so // that the .frozen path prefix is handled. -STATIC mp_import_stat_t stat_file_py_or_mpy(vstr_t *path) { +static mp_import_stat_t stat_file_py_or_mpy(vstr_t *path) { mp_import_stat_t stat = stat_path(path); if (stat == MP_IMPORT_STAT_FILE) { return stat; @@ -99,7 +99,7 @@ STATIC mp_import_stat_t stat_file_py_or_mpy(vstr_t *path) { // or "foo/bar.(m)py" in either the filesystem or frozen modules. If the // result is a file, the path argument will be updated to include the file // extension. -STATIC mp_import_stat_t stat_module(vstr_t *path) { +static mp_import_stat_t stat_module(vstr_t *path) { mp_import_stat_t stat = stat_path(path); DEBUG_printf("stat %s: %d\n", vstr_str(path), stat); if (stat == MP_IMPORT_STAT_DIR) { @@ -114,7 +114,7 @@ STATIC mp_import_stat_t stat_module(vstr_t *path) { // Given a top-level module name, try and find it in each of the sys.path // entries. Note: On success, the dest argument will be updated to the matching // path (i.e. "/mod_name(.py)"). -STATIC mp_import_stat_t stat_top_level(qstr mod_name, vstr_t *dest) { +static mp_import_stat_t stat_top_level(qstr mod_name, vstr_t *dest) { DEBUG_printf("stat_top_level: '%s'\n", qstr_str(mod_name)); #if MICROPY_PY_SYS size_t path_num; @@ -152,7 +152,7 @@ STATIC mp_import_stat_t stat_top_level(qstr mod_name, vstr_t *dest) { } #if MICROPY_MODULE_FROZEN_STR || MICROPY_ENABLE_COMPILER -STATIC void do_load_from_lexer(mp_module_context_t *context, mp_lexer_t *lex) { +static void do_load_from_lexer(mp_module_context_t *context, mp_lexer_t *lex) { #if MICROPY_PY___FILE__ qstr source_name = lex->source_name; mp_store_attr(MP_OBJ_FROM_PTR(&context->module), MP_QSTR___file__, MP_OBJ_NEW_QSTR(source_name)); @@ -165,7 +165,7 @@ STATIC void do_load_from_lexer(mp_module_context_t *context, mp_lexer_t *lex) { #endif #if (MICROPY_HAS_FILE_READER && MICROPY_PERSISTENT_CODE_LOAD) || MICROPY_MODULE_FROZEN_MPY -STATIC void do_execute_proto_fun(const mp_module_context_t *context, mp_proto_fun_t proto_fun, qstr source_name) { +static void do_execute_proto_fun(const mp_module_context_t *context, mp_proto_fun_t proto_fun, qstr source_name) { #if MICROPY_PY___FILE__ mp_store_attr(MP_OBJ_FROM_PTR(&context->module), MP_QSTR___file__, MP_OBJ_NEW_QSTR(source_name)); #else @@ -196,7 +196,7 @@ STATIC void do_execute_proto_fun(const mp_module_context_t *context, mp_proto_fu } #endif -STATIC void do_load(mp_module_context_t *module_obj, vstr_t *file) { +static void do_load(mp_module_context_t *module_obj, vstr_t *file) { #if MICROPY_MODULE_FROZEN || MICROPY_ENABLE_COMPILER || (MICROPY_PERSISTENT_CODE_LOAD && MICROPY_HAS_FILE_READER) const char *file_str = vstr_null_terminated_str(file); #endif @@ -267,7 +267,7 @@ STATIC void do_load(mp_module_context_t *module_obj, vstr_t *file) { // Convert a relative (to the current module) import, going up "level" levels, // into an absolute import. -STATIC void evaluate_relative_import(mp_int_t level, const char **module_name, size_t *module_name_len) { +static void evaluate_relative_import(mp_int_t level, const char **module_name, size_t *module_name_len) { // What we want to do here is to take the name of the current module, // remove trailing components, and concatenate the passed-in // module name. @@ -350,7 +350,7 @@ typedef struct _nlr_jump_callback_node_unregister_module_t { qstr name; } nlr_jump_callback_node_unregister_module_t; -STATIC void unregister_module_from_nlr_jump_callback(void *ctx_in) { +static void unregister_module_from_nlr_jump_callback(void *ctx_in) { nlr_jump_callback_node_unregister_module_t *ctx = ctx_in; mp_map_t *mp_loaded_modules_map = &MP_STATE_VM(mp_loaded_modules_dict).map; mp_map_lookup(mp_loaded_modules_map, MP_OBJ_NEW_QSTR(ctx->name), MP_MAP_LOOKUP_REMOVE_IF_FOUND); @@ -363,7 +363,7 @@ STATIC void unregister_module_from_nlr_jump_callback(void *ctx_in) { // attribute on it) (or MP_OBJ_NULL for top-level). // override_main: Whether to set the __name__ to "__main__" (and use __main__ // for the actual path). -STATIC mp_obj_t process_import_at_level(qstr full_mod_name, qstr level_mod_name, mp_obj_t outer_module_obj, bool override_main) { +static mp_obj_t process_import_at_level(qstr full_mod_name, qstr level_mod_name, mp_obj_t outer_module_obj, bool override_main) { // Immediately return if the module at this level is already loaded. mp_map_elem_t *elem; diff --git a/py/compile.c b/py/compile.c index fe7ad6e13c307..7a359e662e731 100644 --- a/py/compile.c +++ b/py/compile.c @@ -90,7 +90,7 @@ typedef enum { #define NATIVE_EMITTER(f) emit_native_table[mp_dynamic_compiler.native_arch]->emit_##f #define NATIVE_EMITTER_TABLE (emit_native_table[mp_dynamic_compiler.native_arch]) -STATIC const emit_method_table_t *emit_native_table[] = { +static const emit_method_table_t *emit_native_table[] = { NULL, &emit_native_x86_method_table, &emit_native_x64_method_table, @@ -129,7 +129,7 @@ STATIC const emit_method_table_t *emit_native_table[] = { #define ASM_EMITTER(f) emit_asm_table[mp_dynamic_compiler.native_arch]->asm_##f #define ASM_EMITTER_TABLE emit_asm_table[mp_dynamic_compiler.native_arch] -STATIC const emit_inline_asm_method_table_t *emit_asm_table[] = { +static const emit_inline_asm_method_table_t *emit_asm_table[] = { NULL, NULL, NULL, @@ -200,7 +200,7 @@ typedef struct _compiler_t { // mp_emit_common_t helper functions // These are defined here so they can be inlined, to reduce code size. -STATIC void mp_emit_common_init(mp_emit_common_t *emit, qstr source_file) { +static void mp_emit_common_init(mp_emit_common_t *emit, qstr source_file) { #if MICROPY_EMIT_BYTECODE_USES_QSTR_TABLE mp_map_init(&emit->qstr_map, 1); @@ -211,7 +211,7 @@ STATIC void mp_emit_common_init(mp_emit_common_t *emit, qstr source_file) { mp_obj_list_init(&emit->const_obj_list, 0); } -STATIC void mp_emit_common_start_pass(mp_emit_common_t *emit, pass_kind_t pass) { +static void mp_emit_common_start_pass(mp_emit_common_t *emit, pass_kind_t pass) { emit->pass = pass; if (pass == MP_PASS_CODE_SIZE) { if (emit->ct_cur_child == 0) { @@ -223,7 +223,7 @@ STATIC void mp_emit_common_start_pass(mp_emit_common_t *emit, pass_kind_t pass) emit->ct_cur_child = 0; } -STATIC void mp_emit_common_populate_module_context(mp_emit_common_t *emit, qstr source_file, mp_module_context_t *context) { +static void mp_emit_common_populate_module_context(mp_emit_common_t *emit, qstr source_file, mp_module_context_t *context) { #if MICROPY_EMIT_BYTECODE_USES_QSTR_TABLE size_t qstr_map_used = emit->qstr_map.used; mp_module_context_alloc_tables(context, qstr_map_used, emit->const_obj_list.len); @@ -246,14 +246,14 @@ STATIC void mp_emit_common_populate_module_context(mp_emit_common_t *emit, qstr /******************************************************************************/ -STATIC void compile_error_set_line(compiler_t *comp, mp_parse_node_t pn) { +static void compile_error_set_line(compiler_t *comp, mp_parse_node_t pn) { // if the line of the error is unknown then try to update it from the pn if (comp->compile_error_line == 0 && MP_PARSE_NODE_IS_STRUCT(pn)) { comp->compile_error_line = ((mp_parse_node_struct_t *)pn)->source_line; } } -STATIC void compile_syntax_error(compiler_t *comp, mp_parse_node_t pn, mp_rom_error_text_t msg) { +static void compile_syntax_error(compiler_t *comp, mp_parse_node_t pn, mp_rom_error_text_t msg) { // only register the error if there has been no other error if (comp->compile_error == MP_OBJ_NULL) { comp->compile_error = mp_obj_new_exception_msg(&mp_type_SyntaxError, msg); @@ -261,17 +261,17 @@ STATIC void compile_syntax_error(compiler_t *comp, mp_parse_node_t pn, mp_rom_er } } -STATIC void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_arglist, bool is_method_call, int n_positional_extra); -STATIC void compile_comprehension(compiler_t *comp, mp_parse_node_struct_t *pns, scope_kind_t kind); -STATIC void compile_atom_brace_helper(compiler_t *comp, mp_parse_node_struct_t *pns, bool create_map); -STATIC void compile_node(compiler_t *comp, mp_parse_node_t pn); +static void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_arglist, bool is_method_call, int n_positional_extra); +static void compile_comprehension(compiler_t *comp, mp_parse_node_struct_t *pns, scope_kind_t kind); +static void compile_atom_brace_helper(compiler_t *comp, mp_parse_node_struct_t *pns, bool create_map); +static void compile_node(compiler_t *comp, mp_parse_node_t pn); -STATIC uint comp_next_label(compiler_t *comp) { +static uint comp_next_label(compiler_t *comp) { return comp->next_label++; } #if MICROPY_EMIT_NATIVE -STATIC void reserve_labels_for_native(compiler_t *comp, int n) { +static void reserve_labels_for_native(compiler_t *comp, int n) { if (comp->scope_cur->emit_options != MP_EMIT_OPT_BYTECODE) { comp->next_label += n; } @@ -280,7 +280,7 @@ STATIC void reserve_labels_for_native(compiler_t *comp, int n) { #define reserve_labels_for_native(comp, n) #endif -STATIC void compile_increase_except_level(compiler_t *comp, uint label, int kind) { +static void compile_increase_except_level(compiler_t *comp, uint label, int kind) { EMIT_ARG(setup_block, label, kind); comp->cur_except_level += 1; if (comp->cur_except_level > comp->scope_cur->exc_stack_size) { @@ -288,14 +288,14 @@ STATIC void compile_increase_except_level(compiler_t *comp, uint label, int kind } } -STATIC void compile_decrease_except_level(compiler_t *comp) { +static void compile_decrease_except_level(compiler_t *comp) { assert(comp->cur_except_level > 0); comp->cur_except_level -= 1; EMIT(end_finally); reserve_labels_for_native(comp, 1); } -STATIC scope_t *scope_new_and_link(compiler_t *comp, scope_kind_t kind, mp_parse_node_t pn, uint emit_options) { +static scope_t *scope_new_and_link(compiler_t *comp, scope_kind_t kind, mp_parse_node_t pn, uint emit_options) { scope_t *scope = scope_new(kind, pn, emit_options); scope->parent = comp->scope_cur; scope->next = NULL; @@ -313,7 +313,7 @@ STATIC scope_t *scope_new_and_link(compiler_t *comp, scope_kind_t kind, mp_parse typedef void (*apply_list_fun_t)(compiler_t *comp, mp_parse_node_t pn); -STATIC void apply_to_single_or_list(compiler_t *comp, mp_parse_node_t pn, pn_kind_t pn_list_kind, apply_list_fun_t f) { +static void apply_to_single_or_list(compiler_t *comp, mp_parse_node_t pn, pn_kind_t pn_list_kind, apply_list_fun_t f) { if (MP_PARSE_NODE_IS_STRUCT_KIND(pn, pn_list_kind)) { mp_parse_node_struct_t *pns = (mp_parse_node_struct_t *)pn; int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); @@ -325,7 +325,7 @@ STATIC void apply_to_single_or_list(compiler_t *comp, mp_parse_node_t pn, pn_kin } } -STATIC void compile_generic_all_nodes(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_generic_all_nodes(compiler_t *comp, mp_parse_node_struct_t *pns) { int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); for (int i = 0; i < num_nodes; i++) { compile_node(comp, pns->nodes[i]); @@ -337,7 +337,7 @@ STATIC void compile_generic_all_nodes(compiler_t *comp, mp_parse_node_struct_t * } } -STATIC void compile_load_id(compiler_t *comp, qstr qst) { +static void compile_load_id(compiler_t *comp, qstr qst) { if (comp->pass == MP_PASS_SCOPE) { mp_emit_common_get_id_for_load(comp->scope_cur, qst); } else { @@ -349,7 +349,7 @@ STATIC void compile_load_id(compiler_t *comp, qstr qst) { } } -STATIC void compile_store_id(compiler_t *comp, qstr qst) { +static void compile_store_id(compiler_t *comp, qstr qst) { if (comp->pass == MP_PASS_SCOPE) { mp_emit_common_get_id_for_modification(comp->scope_cur, qst); } else { @@ -361,7 +361,7 @@ STATIC void compile_store_id(compiler_t *comp, qstr qst) { } } -STATIC void compile_delete_id(compiler_t *comp, qstr qst) { +static void compile_delete_id(compiler_t *comp, qstr qst) { if (comp->pass == MP_PASS_SCOPE) { mp_emit_common_get_id_for_modification(comp->scope_cur, qst); } else { @@ -373,7 +373,7 @@ STATIC void compile_delete_id(compiler_t *comp, qstr qst) { } } -STATIC void compile_generic_tuple(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_generic_tuple(compiler_t *comp, mp_parse_node_struct_t *pns) { // a simple tuple expression size_t num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); for (size_t i = 0; i < num_nodes; i++) { @@ -382,7 +382,7 @@ STATIC void compile_generic_tuple(compiler_t *comp, mp_parse_node_struct_t *pns) EMIT_ARG(build, num_nodes, MP_EMIT_BUILD_TUPLE); } -STATIC void c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int label) { +static void c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int label) { if (mp_parse_node_is_const_false(pn)) { if (jump_if == false) { EMIT_ARG(jump, label); @@ -430,9 +430,9 @@ STATIC void c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int la } typedef enum { ASSIGN_STORE, ASSIGN_AUG_LOAD, ASSIGN_AUG_STORE } assign_kind_t; -STATIC void c_assign(compiler_t *comp, mp_parse_node_t pn, assign_kind_t kind); +static void c_assign(compiler_t *comp, mp_parse_node_t pn, assign_kind_t kind); -STATIC void c_assign_atom_expr(compiler_t *comp, mp_parse_node_struct_t *pns, assign_kind_t assign_kind) { +static void c_assign_atom_expr(compiler_t *comp, mp_parse_node_struct_t *pns, assign_kind_t assign_kind) { if (assign_kind != ASSIGN_AUG_STORE) { compile_node(comp, pns->nodes[0]); } @@ -481,7 +481,7 @@ STATIC void c_assign_atom_expr(compiler_t *comp, mp_parse_node_struct_t *pns, as compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("can't assign to expression")); } -STATIC void c_assign_tuple(compiler_t *comp, uint num_tail, mp_parse_node_t *nodes_tail) { +static void c_assign_tuple(compiler_t *comp, uint num_tail, mp_parse_node_t *nodes_tail) { // look for star expression uint have_star_index = -1; for (uint i = 0; i < num_tail; i++) { @@ -508,7 +508,7 @@ STATIC void c_assign_tuple(compiler_t *comp, uint num_tail, mp_parse_node_t *nod } // assigns top of stack to pn -STATIC void c_assign(compiler_t *comp, mp_parse_node_t pn, assign_kind_t assign_kind) { +static void c_assign(compiler_t *comp, mp_parse_node_t pn, assign_kind_t assign_kind) { assert(!MP_PARSE_NODE_IS_NULL(pn)); if (MP_PARSE_NODE_IS_LEAF(pn)) { if (MP_PARSE_NODE_IS_ID(pn)) { @@ -599,7 +599,7 @@ STATIC void c_assign(compiler_t *comp, mp_parse_node_t pn, assign_kind_t assign_ // if n_pos_defaults > 0 then there is a tuple on the stack with the positional defaults // if n_kw_defaults > 0 then there is a dictionary on the stack with the keyword defaults // if both exist, the tuple is above the dictionary (ie the first pop gets the tuple) -STATIC void close_over_variables_etc(compiler_t *comp, scope_t *this_scope, int n_pos_defaults, int n_kw_defaults) { +static void close_over_variables_etc(compiler_t *comp, scope_t *this_scope, int n_pos_defaults, int n_kw_defaults) { assert(n_pos_defaults >= 0); assert(n_kw_defaults >= 0); @@ -641,7 +641,7 @@ STATIC void close_over_variables_etc(compiler_t *comp, scope_t *this_scope, int } } -STATIC void compile_funcdef_lambdef_param(compiler_t *comp, mp_parse_node_t pn) { +static void compile_funcdef_lambdef_param(compiler_t *comp, mp_parse_node_t pn) { // For efficiency of the code below we extract the parse-node kind here int pn_kind; if (MP_PARSE_NODE_IS_ID(pn)) { @@ -732,7 +732,7 @@ STATIC void compile_funcdef_lambdef_param(compiler_t *comp, mp_parse_node_t pn) } } -STATIC void compile_funcdef_lambdef(compiler_t *comp, scope_t *scope, mp_parse_node_t pn_params, pn_kind_t pn_list_kind) { +static void compile_funcdef_lambdef(compiler_t *comp, scope_t *scope, mp_parse_node_t pn_params, pn_kind_t pn_list_kind) { // When we call compile_funcdef_lambdef_param below it can compile an arbitrary // expression for default arguments, which may contain a lambda. The lambda will // call here in a nested way, so we must save and restore the relevant state. @@ -768,7 +768,7 @@ STATIC void compile_funcdef_lambdef(compiler_t *comp, scope_t *scope, mp_parse_n // leaves function object on stack // returns function name -STATIC qstr compile_funcdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint emit_options) { +static qstr compile_funcdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint emit_options) { if (comp->pass == MP_PASS_SCOPE) { // create a new scope for this function scope_t *s = scope_new_and_link(comp, SCOPE_FUNCTION, (mp_parse_node_t)pns, emit_options); @@ -788,7 +788,7 @@ STATIC qstr compile_funcdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns // leaves class object on stack // returns class name -STATIC qstr compile_classdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint emit_options) { +static qstr compile_classdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint emit_options) { if (comp->pass == MP_PASS_SCOPE) { // create a new scope for this class scope_t *s = scope_new_and_link(comp, SCOPE_CLASS, (mp_parse_node_t)pns, emit_options); @@ -820,7 +820,7 @@ STATIC qstr compile_classdef_helper(compiler_t *comp, mp_parse_node_struct_t *pn } // returns true if it was a built-in decorator (even if the built-in had an error) -STATIC bool compile_built_in_decorator(compiler_t *comp, size_t name_len, mp_parse_node_t *name_nodes, uint *emit_options) { +static bool compile_built_in_decorator(compiler_t *comp, size_t name_len, mp_parse_node_t *name_nodes, uint *emit_options) { if (MP_PARSE_NODE_LEAF_ARG(name_nodes[0]) != MP_QSTR_micropython) { return false; } @@ -869,7 +869,7 @@ STATIC bool compile_built_in_decorator(compiler_t *comp, size_t name_len, mp_par return true; } -STATIC void compile_decorated(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_decorated(compiler_t *comp, mp_parse_node_struct_t *pns) { // get the list of decorators mp_parse_node_t *nodes; size_t n = mp_parse_node_extract_list(&pns->nodes[0], PN_decorators, &nodes); @@ -937,13 +937,13 @@ STATIC void compile_decorated(compiler_t *comp, mp_parse_node_struct_t *pns) { compile_store_id(comp, body_name); } -STATIC void compile_funcdef(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_funcdef(compiler_t *comp, mp_parse_node_struct_t *pns) { qstr fname = compile_funcdef_helper(comp, pns, comp->scope_cur->emit_options); // store function object into function name compile_store_id(comp, fname); } -STATIC void c_del_stmt(compiler_t *comp, mp_parse_node_t pn) { +static void c_del_stmt(compiler_t *comp, mp_parse_node_t pn) { if (MP_PARSE_NODE_IS_ID(pn)) { compile_delete_id(comp, MP_PARSE_NODE_LEAF_ARG(pn)); } else if (MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_atom_expr_normal)) { @@ -999,11 +999,11 @@ STATIC void c_del_stmt(compiler_t *comp, mp_parse_node_t pn) { compile_syntax_error(comp, (mp_parse_node_t)pn, MP_ERROR_TEXT("can't delete expression")); } -STATIC void compile_del_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_del_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { apply_to_single_or_list(comp, pns->nodes[0], PN_exprlist, c_del_stmt); } -STATIC void compile_break_cont_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_break_cont_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { uint16_t label; if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_break_stmt) { label = comp->break_label; @@ -1017,7 +1017,7 @@ STATIC void compile_break_cont_stmt(compiler_t *comp, mp_parse_node_struct_t *pn EMIT_ARG(unwind_jump, label, comp->cur_except_level - comp->break_continue_except_level); } -STATIC void compile_return_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_return_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { #if MICROPY_CPYTHON_COMPAT if (comp->scope_cur->kind != SCOPE_FUNCTION) { compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("'return' outside function")); @@ -1045,12 +1045,12 @@ STATIC void compile_return_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { EMIT(return_value); } -STATIC void compile_yield_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_yield_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { compile_node(comp, pns->nodes[0]); EMIT(pop_top); } -STATIC void compile_raise_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_raise_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) { // raise EMIT_ARG(raise_varargs, 0); @@ -1070,7 +1070,7 @@ STATIC void compile_raise_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { // q_base holds the base of the name // eg a -> q_base=a // a.b.c -> q_base=a -STATIC void do_import_name(compiler_t *comp, mp_parse_node_t pn, qstr *q_base) { +static void do_import_name(compiler_t *comp, mp_parse_node_t pn, qstr *q_base) { bool is_as = false; if (MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_dotted_as_name)) { mp_parse_node_struct_t *pns = (mp_parse_node_struct_t *)pn; @@ -1131,7 +1131,7 @@ STATIC void do_import_name(compiler_t *comp, mp_parse_node_t pn, qstr *q_base) { } } -STATIC void compile_dotted_as_name(compiler_t *comp, mp_parse_node_t pn) { +static void compile_dotted_as_name(compiler_t *comp, mp_parse_node_t pn) { EMIT_ARG(load_const_small_int, 0); // level 0 import EMIT_ARG(load_const_tok, MP_TOKEN_KW_NONE); // not importing from anything qstr q_base; @@ -1139,11 +1139,11 @@ STATIC void compile_dotted_as_name(compiler_t *comp, mp_parse_node_t pn) { compile_store_id(comp, q_base); } -STATIC void compile_import_name(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_import_name(compiler_t *comp, mp_parse_node_struct_t *pns) { apply_to_single_or_list(comp, pns->nodes[0], PN_dotted_as_names, compile_dotted_as_name); } -STATIC void compile_import_from(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_import_from(compiler_t *comp, mp_parse_node_struct_t *pns) { mp_parse_node_t pn_import_source = pns->nodes[0]; // extract the preceding .'s (if any) for a relative import, to compute the import level @@ -1231,7 +1231,7 @@ STATIC void compile_import_from(compiler_t *comp, mp_parse_node_struct_t *pns) { } } -STATIC void compile_declare_global(compiler_t *comp, mp_parse_node_t pn, id_info_t *id_info) { +static void compile_declare_global(compiler_t *comp, mp_parse_node_t pn, id_info_t *id_info) { if (id_info->kind != ID_INFO_KIND_UNDECIDED && id_info->kind != ID_INFO_KIND_GLOBAL_EXPLICIT) { compile_syntax_error(comp, pn, MP_ERROR_TEXT("identifier redefined as global")); return; @@ -1245,7 +1245,7 @@ STATIC void compile_declare_global(compiler_t *comp, mp_parse_node_t pn, id_info } } -STATIC void compile_declare_nonlocal(compiler_t *comp, mp_parse_node_t pn, id_info_t *id_info) { +static void compile_declare_nonlocal(compiler_t *comp, mp_parse_node_t pn, id_info_t *id_info) { if (id_info->kind == ID_INFO_KIND_UNDECIDED) { id_info->kind = ID_INFO_KIND_GLOBAL_IMPLICIT; scope_check_to_close_over(comp->scope_cur, id_info); @@ -1257,7 +1257,7 @@ STATIC void compile_declare_nonlocal(compiler_t *comp, mp_parse_node_t pn, id_in } } -STATIC void compile_declare_global_or_nonlocal(compiler_t *comp, mp_parse_node_t pn, id_info_t *id_info, bool is_global) { +static void compile_declare_global_or_nonlocal(compiler_t *comp, mp_parse_node_t pn, id_info_t *id_info, bool is_global) { if (is_global) { compile_declare_global(comp, pn, id_info); } else { @@ -1265,7 +1265,7 @@ STATIC void compile_declare_global_or_nonlocal(compiler_t *comp, mp_parse_node_t } } -STATIC void compile_global_nonlocal_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_global_nonlocal_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { if (comp->pass == MP_PASS_SCOPE) { bool is_global = MP_PARSE_NODE_STRUCT_KIND(pns) == PN_global_stmt; @@ -1284,7 +1284,7 @@ STATIC void compile_global_nonlocal_stmt(compiler_t *comp, mp_parse_node_struct_ } } -STATIC void compile_assert_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_assert_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { // with optimisations enabled we don't compile assertions if (MP_STATE_VM(mp_optimise_value) != 0) { return; @@ -1302,7 +1302,7 @@ STATIC void compile_assert_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { EMIT_ARG(label_assign, l_end); } -STATIC void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { uint l_end = comp_next_label(comp); // optimisation: don't emit anything when "if False" @@ -1372,7 +1372,7 @@ STATIC void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { comp->continue_label = old_continue_label; \ comp->break_continue_except_level = old_break_continue_except_level; -STATIC void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { START_BREAK_CONTINUE_BLOCK if (!mp_parse_node_is_const_false(pns->nodes[0])) { // optimisation: don't emit anything for "while False" @@ -1410,7 +1410,7 @@ STATIC void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { // If is a small-int, then the stack during the for-loop contains just // the current value of . Otherwise, the stack contains then the // current value of . -STATIC void compile_for_stmt_optimised_range(compiler_t *comp, mp_parse_node_t pn_var, mp_parse_node_t pn_start, mp_parse_node_t pn_end, mp_parse_node_t pn_step, mp_parse_node_t pn_body, mp_parse_node_t pn_else) { +static void compile_for_stmt_optimised_range(compiler_t *comp, mp_parse_node_t pn_var, mp_parse_node_t pn_start, mp_parse_node_t pn_end, mp_parse_node_t pn_step, mp_parse_node_t pn_body, mp_parse_node_t pn_else) { START_BREAK_CONTINUE_BLOCK uint top_label = comp_next_label(comp); @@ -1492,7 +1492,7 @@ STATIC void compile_for_stmt_optimised_range(compiler_t *comp, mp_parse_node_t p } } -STATIC void compile_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { // this bit optimises: for in range(...), turning it into an explicitly incremented variable // this is actually slower, but uses no heap memory // for viper it will be much, much faster @@ -1572,7 +1572,7 @@ STATIC void compile_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { EMIT_ARG(label_assign, break_label); } -STATIC void compile_try_except(compiler_t *comp, mp_parse_node_t pn_body, int n_except, mp_parse_node_t *pn_excepts, mp_parse_node_t pn_else) { +static void compile_try_except(compiler_t *comp, mp_parse_node_t pn_body, int n_except, mp_parse_node_t *pn_excepts, mp_parse_node_t pn_else) { // setup code uint l1 = comp_next_label(comp); uint success_label = comp_next_label(comp); @@ -1669,7 +1669,7 @@ STATIC void compile_try_except(compiler_t *comp, mp_parse_node_t pn_body, int n_ EMIT_ARG(label_assign, l2); } -STATIC void compile_try_finally(compiler_t *comp, mp_parse_node_t pn_body, int n_except, mp_parse_node_t *pn_except, mp_parse_node_t pn_else, mp_parse_node_t pn_finally) { +static void compile_try_finally(compiler_t *comp, mp_parse_node_t pn_body, int n_except, mp_parse_node_t *pn_except, mp_parse_node_t pn_else, mp_parse_node_t pn_finally) { uint l_finally_block = comp_next_label(comp); compile_increase_except_level(comp, l_finally_block, MP_EMIT_SETUP_BLOCK_FINALLY); @@ -1698,7 +1698,7 @@ STATIC void compile_try_finally(compiler_t *comp, mp_parse_node_t pn_body, int n compile_decrease_except_level(comp); } -STATIC void compile_try_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_try_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { assert(MP_PARSE_NODE_IS_STRUCT(pns->nodes[1])); // should be { mp_parse_node_struct_t *pns2 = (mp_parse_node_struct_t *)pns->nodes[1]; @@ -1725,7 +1725,7 @@ STATIC void compile_try_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { } } -STATIC void compile_with_stmt_helper(compiler_t *comp, size_t n, mp_parse_node_t *nodes, mp_parse_node_t body) { +static void compile_with_stmt_helper(compiler_t *comp, size_t n, mp_parse_node_t *nodes, mp_parse_node_t body) { if (n == 0) { // no more pre-bits, compile the body of the with compile_node(comp, body); @@ -1752,7 +1752,7 @@ STATIC void compile_with_stmt_helper(compiler_t *comp, size_t n, mp_parse_node_t } } -STATIC void compile_with_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_with_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { // get the nodes for the pre-bit of the with (the a as b, c as d, ... bit) mp_parse_node_t *nodes; size_t n = mp_parse_node_extract_list(&pns->nodes[0], PN_with_stmt_list, &nodes); @@ -1762,7 +1762,7 @@ STATIC void compile_with_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { compile_with_stmt_helper(comp, n, nodes, pns->nodes[1]); } -STATIC void compile_yield_from(compiler_t *comp) { +static void compile_yield_from(compiler_t *comp) { EMIT_ARG(get_iter, false); EMIT_ARG(load_const_tok, MP_TOKEN_KW_NONE); EMIT_ARG(yield, MP_EMIT_YIELD_FROM); @@ -1770,13 +1770,13 @@ STATIC void compile_yield_from(compiler_t *comp) { } #if MICROPY_PY_ASYNC_AWAIT -STATIC void compile_await_object_method(compiler_t *comp, qstr method) { +static void compile_await_object_method(compiler_t *comp, qstr method) { EMIT_ARG(load_method, method, false); EMIT_ARG(call_method, 0, 0, 0); compile_yield_from(comp); } -STATIC void compile_async_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_async_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { // Allocate labels. uint while_else_label = comp_next_label(comp); uint try_exception_label = comp_next_label(comp); @@ -1843,7 +1843,7 @@ STATIC void compile_async_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns // Stack: (...) } -STATIC void compile_async_with_stmt_helper(compiler_t *comp, size_t n, mp_parse_node_t *nodes, mp_parse_node_t body) { +static void compile_async_with_stmt_helper(compiler_t *comp, size_t n, mp_parse_node_t *nodes, mp_parse_node_t body) { if (n == 0) { // no more pre-bits, compile the body of the with compile_node(comp, body); @@ -1955,7 +1955,7 @@ STATIC void compile_async_with_stmt_helper(compiler_t *comp, size_t n, mp_parse_ } } -STATIC void compile_async_with_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_async_with_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { // get the nodes for the pre-bit of the with (the a as b, c as d, ... bit) mp_parse_node_t *nodes; size_t n = mp_parse_node_extract_list(&pns->nodes[0], PN_with_stmt_list, &nodes); @@ -1965,7 +1965,7 @@ STATIC void compile_async_with_stmt(compiler_t *comp, mp_parse_node_struct_t *pn compile_async_with_stmt_helper(comp, n, nodes, pns->nodes[1]); } -STATIC void compile_async_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_async_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { assert(MP_PARSE_NODE_IS_STRUCT(pns->nodes[0])); mp_parse_node_struct_t *pns0 = (mp_parse_node_struct_t *)pns->nodes[0]; if (MP_PARSE_NODE_STRUCT_KIND(pns0) == PN_funcdef) { @@ -1994,7 +1994,7 @@ STATIC void compile_async_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { } #endif -STATIC void compile_expr_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_expr_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { mp_parse_node_t pn_rhs = pns->nodes[1]; if (MP_PARSE_NODE_IS_NULL(pn_rhs)) { if (comp->is_repl && comp->scope_cur->kind == SCOPE_MODULE) { @@ -2109,7 +2109,7 @@ STATIC void compile_expr_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { } } -STATIC void compile_test_if_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_test_if_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { assert(MP_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[1], PN_test_if_else)); mp_parse_node_struct_t *pns_test_if_else = (mp_parse_node_struct_t *)pns->nodes[1]; @@ -2124,7 +2124,7 @@ STATIC void compile_test_if_expr(compiler_t *comp, mp_parse_node_struct_t *pns) EMIT_ARG(label_assign, l_end); } -STATIC void compile_lambdef(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_lambdef(compiler_t *comp, mp_parse_node_struct_t *pns) { if (comp->pass == MP_PASS_SCOPE) { // create a new scope for this lambda scope_t *s = scope_new_and_link(comp, SCOPE_LAMBDA, (mp_parse_node_t)pns, comp->scope_cur->emit_options); @@ -2140,7 +2140,7 @@ STATIC void compile_lambdef(compiler_t *comp, mp_parse_node_struct_t *pns) { } #if MICROPY_PY_ASSIGN_EXPR -STATIC void compile_namedexpr_helper(compiler_t *comp, mp_parse_node_t pn_name, mp_parse_node_t pn_expr) { +static void compile_namedexpr_helper(compiler_t *comp, mp_parse_node_t pn_name, mp_parse_node_t pn_expr) { if (!MP_PARSE_NODE_IS_ID(pn_name)) { compile_syntax_error(comp, (mp_parse_node_t)pn_name, MP_ERROR_TEXT("can't assign to expression")); } @@ -2172,12 +2172,12 @@ STATIC void compile_namedexpr_helper(compiler_t *comp, mp_parse_node_t pn_name, compile_store_id(comp, target); } -STATIC void compile_namedexpr(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_namedexpr(compiler_t *comp, mp_parse_node_struct_t *pns) { compile_namedexpr_helper(comp, pns->nodes[0], pns->nodes[1]); } #endif -STATIC void compile_or_and_test(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_or_and_test(compiler_t *comp, mp_parse_node_struct_t *pns) { bool cond = MP_PARSE_NODE_STRUCT_KIND(pns) == PN_or_test; uint l_end = comp_next_label(comp); int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); @@ -2190,12 +2190,12 @@ STATIC void compile_or_and_test(compiler_t *comp, mp_parse_node_struct_t *pns) { EMIT_ARG(label_assign, l_end); } -STATIC void compile_not_test_2(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_not_test_2(compiler_t *comp, mp_parse_node_struct_t *pns) { compile_node(comp, pns->nodes[0]); EMIT_ARG(unary_op, MP_UNARY_OP_NOT); } -STATIC void compile_comparison(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_comparison(compiler_t *comp, mp_parse_node_struct_t *pns) { int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); compile_node(comp, pns->nodes[0]); bool multi = (num_nodes > 3); @@ -2248,11 +2248,11 @@ STATIC void compile_comparison(compiler_t *comp, mp_parse_node_struct_t *pns) { } } -STATIC void compile_star_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_star_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("*x must be assignment target")); } -STATIC void compile_binary_op(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_binary_op(compiler_t *comp, mp_parse_node_struct_t *pns) { MP_STATIC_ASSERT(MP_BINARY_OP_OR + PN_xor_expr - PN_expr == MP_BINARY_OP_XOR); MP_STATIC_ASSERT(MP_BINARY_OP_OR + PN_and_expr - PN_expr == MP_BINARY_OP_AND); mp_binary_op_t binary_op = MP_BINARY_OP_OR + MP_PARSE_NODE_STRUCT_KIND(pns) - PN_expr; @@ -2264,7 +2264,7 @@ STATIC void compile_binary_op(compiler_t *comp, mp_parse_node_struct_t *pns) { } } -STATIC void compile_term(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_term(compiler_t *comp, mp_parse_node_struct_t *pns) { int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); compile_node(comp, pns->nodes[0]); for (int i = 1; i + 1 < num_nodes; i += 2) { @@ -2275,7 +2275,7 @@ STATIC void compile_term(compiler_t *comp, mp_parse_node_struct_t *pns) { } } -STATIC void compile_factor_2(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_factor_2(compiler_t *comp, mp_parse_node_struct_t *pns) { compile_node(comp, pns->nodes[1]); mp_token_kind_t tok = MP_PARSE_NODE_LEAF_ARG(pns->nodes[0]); mp_unary_op_t op; @@ -2288,7 +2288,7 @@ STATIC void compile_factor_2(compiler_t *comp, mp_parse_node_struct_t *pns) { EMIT_ARG(unary_op, op); } -STATIC void compile_atom_expr_normal(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_atom_expr_normal(compiler_t *comp, mp_parse_node_struct_t *pns) { // compile the subject of the expression compile_node(comp, pns->nodes[0]); @@ -2384,12 +2384,12 @@ STATIC void compile_atom_expr_normal(compiler_t *comp, mp_parse_node_struct_t *p } } -STATIC void compile_power(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_power(compiler_t *comp, mp_parse_node_struct_t *pns) { compile_generic_all_nodes(comp, pns); // 2 nodes, arguments of power EMIT_ARG(binary_op, MP_BINARY_OP_POWER); } -STATIC void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_arglist, bool is_method_call, int n_positional_extra) { +static void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_arglist, bool is_method_call, int n_positional_extra) { // function to call is on top of stack // get the list of arguments @@ -2484,7 +2484,7 @@ STATIC void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_ar } // pns needs to have 2 nodes, first is lhs of comprehension, second is PN_comp_for node -STATIC void compile_comprehension(compiler_t *comp, mp_parse_node_struct_t *pns, scope_kind_t kind) { +static void compile_comprehension(compiler_t *comp, mp_parse_node_struct_t *pns, scope_kind_t kind) { assert(MP_PARSE_NODE_STRUCT_NUM_NODES(pns) == 2); assert(MP_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[1], PN_comp_for)); mp_parse_node_struct_t *pns_comp_for = (mp_parse_node_struct_t *)pns->nodes[1]; @@ -2509,7 +2509,7 @@ STATIC void compile_comprehension(compiler_t *comp, mp_parse_node_struct_t *pns, EMIT_ARG(call_function, 1, 0, 0); } -STATIC void compile_atom_paren(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_atom_paren(compiler_t *comp, mp_parse_node_struct_t *pns) { if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) { // an empty tuple EMIT_ARG(build, 0, MP_EMIT_BUILD_TUPLE); @@ -2526,7 +2526,7 @@ STATIC void compile_atom_paren(compiler_t *comp, mp_parse_node_struct_t *pns) { } } -STATIC void compile_atom_bracket(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_atom_bracket(compiler_t *comp, mp_parse_node_struct_t *pns) { if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) { // empty list EMIT_ARG(build, 0, MP_EMIT_BUILD_LIST); @@ -2547,7 +2547,7 @@ STATIC void compile_atom_bracket(compiler_t *comp, mp_parse_node_struct_t *pns) } } -STATIC void compile_atom_brace_helper(compiler_t *comp, mp_parse_node_struct_t *pns, bool create_map) { +static void compile_atom_brace_helper(compiler_t *comp, mp_parse_node_struct_t *pns, bool create_map) { mp_parse_node_t pn = pns->nodes[0]; if (MP_PARSE_NODE_IS_NULL(pn)) { // empty dict @@ -2649,27 +2649,27 @@ STATIC void compile_atom_brace_helper(compiler_t *comp, mp_parse_node_struct_t * } } -STATIC void compile_atom_brace(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_atom_brace(compiler_t *comp, mp_parse_node_struct_t *pns) { compile_atom_brace_helper(comp, pns, true); } -STATIC void compile_trailer_paren(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_trailer_paren(compiler_t *comp, mp_parse_node_struct_t *pns) { compile_trailer_paren_helper(comp, pns->nodes[0], false, 0); } -STATIC void compile_trailer_bracket(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_trailer_bracket(compiler_t *comp, mp_parse_node_struct_t *pns) { // object who's index we want is on top of stack compile_node(comp, pns->nodes[0]); // the index EMIT_ARG(subscr, MP_EMIT_SUBSCR_LOAD); } -STATIC void compile_trailer_period(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_trailer_period(compiler_t *comp, mp_parse_node_struct_t *pns) { // object who's attribute we want is on top of stack EMIT_ARG(attr, MP_PARSE_NODE_LEAF_ARG(pns->nodes[0]), MP_EMIT_ATTR_LOAD); // attribute to get } #if MICROPY_PY_BUILTINS_SLICE -STATIC void compile_subscript(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_subscript(compiler_t *comp, mp_parse_node_struct_t *pns) { if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_subscript_2) { compile_node(comp, pns->nodes[0]); // start of slice assert(MP_PARSE_NODE_IS_STRUCT(pns->nodes[1])); // should always be @@ -2724,19 +2724,19 @@ STATIC void compile_subscript(compiler_t *comp, mp_parse_node_struct_t *pns) { } #endif // MICROPY_PY_BUILTINS_SLICE -STATIC void compile_dictorsetmaker_item(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_dictorsetmaker_item(compiler_t *comp, mp_parse_node_struct_t *pns) { // if this is called then we are compiling a dict key:value pair compile_node(comp, pns->nodes[1]); // value compile_node(comp, pns->nodes[0]); // key } -STATIC void compile_classdef(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_classdef(compiler_t *comp, mp_parse_node_struct_t *pns) { qstr cname = compile_classdef_helper(comp, pns, comp->scope_cur->emit_options); // store class object into class name compile_store_id(comp, cname); } -STATIC void compile_yield_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_yield_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { if (comp->scope_cur->kind != SCOPE_FUNCTION && comp->scope_cur->kind != SCOPE_LAMBDA) { compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("'yield' outside function")); return; @@ -2757,7 +2757,7 @@ STATIC void compile_yield_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { } #if MICROPY_PY_ASYNC_AWAIT -STATIC void compile_atom_expr_await(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_atom_expr_await(compiler_t *comp, mp_parse_node_struct_t *pns) { if (comp->scope_cur->kind != SCOPE_FUNCTION && comp->scope_cur->kind != SCOPE_LAMBDA) { compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("'await' outside function")); return; @@ -2767,16 +2767,16 @@ STATIC void compile_atom_expr_await(compiler_t *comp, mp_parse_node_struct_t *pn } #endif -STATIC mp_obj_t get_const_object(mp_parse_node_struct_t *pns) { +static mp_obj_t get_const_object(mp_parse_node_struct_t *pns) { return mp_parse_node_extract_const_object(pns); } -STATIC void compile_const_object(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_const_object(compiler_t *comp, mp_parse_node_struct_t *pns) { EMIT_ARG(load_const_obj, get_const_object(pns)); } typedef void (*compile_function_t)(compiler_t *, mp_parse_node_struct_t *); -STATIC const compile_function_t compile_function[] = { +static const compile_function_t compile_function[] = { // only define rules with a compile function #define c(f) compile_##f #define DEF_RULE(rule, comp, kind, ...) comp, @@ -2788,7 +2788,7 @@ STATIC const compile_function_t compile_function[] = { compile_const_object, }; -STATIC void compile_node(compiler_t *comp, mp_parse_node_t pn) { +static void compile_node(compiler_t *comp, mp_parse_node_t pn) { if (MP_PARSE_NODE_IS_NULL(pn)) { // pass } else if (MP_PARSE_NODE_IS_SMALL_INT(pn)) { @@ -2824,7 +2824,7 @@ STATIC void compile_node(compiler_t *comp, mp_parse_node_t pn) { } #if MICROPY_EMIT_NATIVE -STATIC int compile_viper_type_annotation(compiler_t *comp, mp_parse_node_t pn_annotation) { +static int compile_viper_type_annotation(compiler_t *comp, mp_parse_node_t pn_annotation) { int native_type = MP_NATIVE_TYPE_OBJ; if (MP_PARSE_NODE_IS_NULL(pn_annotation)) { // No annotation, type defaults to object @@ -2842,7 +2842,7 @@ STATIC int compile_viper_type_annotation(compiler_t *comp, mp_parse_node_t pn_an } #endif -STATIC void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn, pn_kind_t pn_name, pn_kind_t pn_star, pn_kind_t pn_dbl_star) { +static void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn, pn_kind_t pn_name, pn_kind_t pn_star, pn_kind_t pn_dbl_star) { (void)pn_dbl_star; // check that **kw is last @@ -2929,15 +2929,15 @@ STATIC void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn } } -STATIC void compile_scope_func_param(compiler_t *comp, mp_parse_node_t pn) { +static void compile_scope_func_param(compiler_t *comp, mp_parse_node_t pn) { compile_scope_func_lambda_param(comp, pn, PN_typedargslist_name, PN_typedargslist_star, PN_typedargslist_dbl_star); } -STATIC void compile_scope_lambda_param(compiler_t *comp, mp_parse_node_t pn) { +static void compile_scope_lambda_param(compiler_t *comp, mp_parse_node_t pn) { compile_scope_func_lambda_param(comp, pn, PN_varargslist_name, PN_varargslist_star, PN_varargslist_dbl_star); } -STATIC void compile_scope_comp_iter(compiler_t *comp, mp_parse_node_struct_t *pns_comp_for, mp_parse_node_t pn_inner_expr, int for_depth) { +static void compile_scope_comp_iter(compiler_t *comp, mp_parse_node_struct_t *pns_comp_for, mp_parse_node_t pn_inner_expr, int for_depth) { uint l_top = comp_next_label(comp); uint l_end = comp_next_label(comp); EMIT_ARG(label_assign, l_top); @@ -2976,7 +2976,7 @@ STATIC void compile_scope_comp_iter(compiler_t *comp, mp_parse_node_struct_t *pn EMIT(for_iter_end); } -STATIC void check_for_doc_string(compiler_t *comp, mp_parse_node_t pn) { +static void check_for_doc_string(compiler_t *comp, mp_parse_node_t pn) { #if MICROPY_ENABLE_DOC_STRING // see http://www.python.org/dev/peps/pep-0257/ @@ -3021,7 +3021,7 @@ STATIC void check_for_doc_string(compiler_t *comp, mp_parse_node_t pn) { #endif } -STATIC bool compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) { +static bool compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) { comp->pass = pass; comp->scope_cur = scope; comp->next_label = 0; @@ -3186,7 +3186,7 @@ STATIC bool compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) { #if MICROPY_EMIT_INLINE_ASM // requires 3 passes: SCOPE, CODE_SIZE, EMIT -STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind_t pass) { +static void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind_t pass) { comp->pass = pass; comp->scope_cur = scope; comp->next_label = 0; @@ -3361,7 +3361,7 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind } #endif -STATIC void scope_compute_things(scope_t *scope) { +static void scope_compute_things(scope_t *scope) { // in MicroPython we put the *x parameter after all other parameters (except **y) if (scope->scope_flags & MP_SCOPE_FLAG_VARARGS) { id_info_t *id_param = NULL; @@ -3455,7 +3455,7 @@ STATIC void scope_compute_things(scope_t *scope) { } #if !MICROPY_PERSISTENT_CODE_SAVE -STATIC +static #endif void mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr source_file, bool is_repl, mp_compiled_module_t *cm) { // put compiler state on the stack, it's relatively small diff --git a/py/emitbc.c b/py/emitbc.c index 85fc5f218b0af..05754cfabf65d 100644 --- a/py/emitbc.c +++ b/py/emitbc.c @@ -92,7 +92,7 @@ void emit_bc_free(emit_t *emit) { } // all functions must go through this one to emit code info -STATIC uint8_t *emit_get_cur_to_write_code_info(void *emit_in, size_t num_bytes_to_write) { +static uint8_t *emit_get_cur_to_write_code_info(void *emit_in, size_t num_bytes_to_write) { emit_t *emit = emit_in; if (emit->pass < MP_PASS_EMIT) { emit->code_info_offset += num_bytes_to_write; @@ -105,16 +105,16 @@ STATIC uint8_t *emit_get_cur_to_write_code_info(void *emit_in, size_t num_bytes_ } } -STATIC void emit_write_code_info_byte(emit_t *emit, byte val) { +static void emit_write_code_info_byte(emit_t *emit, byte val) { *emit_get_cur_to_write_code_info(emit, 1) = val; } -STATIC void emit_write_code_info_qstr(emit_t *emit, qstr qst) { +static void emit_write_code_info_qstr(emit_t *emit, qstr qst) { mp_encode_uint(emit, emit_get_cur_to_write_code_info, mp_emit_common_use_qstr(emit->emit_common, qst)); } #if MICROPY_ENABLE_SOURCE_LINE -STATIC void emit_write_code_info_bytes_lines(emit_t *emit, mp_uint_t bytes_to_skip, mp_uint_t lines_to_skip) { +static void emit_write_code_info_bytes_lines(emit_t *emit, mp_uint_t bytes_to_skip, mp_uint_t lines_to_skip) { assert(bytes_to_skip > 0 || lines_to_skip > 0); while (bytes_to_skip > 0 || lines_to_skip > 0) { mp_uint_t b, l; @@ -143,7 +143,7 @@ STATIC void emit_write_code_info_bytes_lines(emit_t *emit, mp_uint_t bytes_to_sk #endif // all functions must go through this one to emit byte code -STATIC uint8_t *emit_get_cur_to_write_bytecode(void *emit_in, size_t num_bytes_to_write) { +static uint8_t *emit_get_cur_to_write_bytecode(void *emit_in, size_t num_bytes_to_write) { emit_t *emit = emit_in; if (emit->suppress) { return emit->dummy_data; @@ -159,19 +159,19 @@ STATIC uint8_t *emit_get_cur_to_write_bytecode(void *emit_in, size_t num_bytes_t } } -STATIC void emit_write_bytecode_raw_byte(emit_t *emit, byte b1) { +static void emit_write_bytecode_raw_byte(emit_t *emit, byte b1) { byte *c = emit_get_cur_to_write_bytecode(emit, 1); c[0] = b1; } -STATIC void emit_write_bytecode_byte(emit_t *emit, int stack_adj, byte b1) { +static void emit_write_bytecode_byte(emit_t *emit, int stack_adj, byte b1) { mp_emit_bc_adjust_stack_size(emit, stack_adj); byte *c = emit_get_cur_to_write_bytecode(emit, 1); c[0] = b1; } // Similar to mp_encode_uint(), just some extra handling to encode sign -STATIC void emit_write_bytecode_byte_int(emit_t *emit, int stack_adj, byte b1, mp_int_t num) { +static void emit_write_bytecode_byte_int(emit_t *emit, int stack_adj, byte b1, mp_int_t num) { emit_write_bytecode_byte(emit, stack_adj, b1); // We store each 7 bits in a separate byte, and that's how many bytes needed @@ -197,24 +197,24 @@ STATIC void emit_write_bytecode_byte_int(emit_t *emit, int stack_adj, byte b1, m *c = *p; } -STATIC void emit_write_bytecode_byte_uint(emit_t *emit, int stack_adj, byte b, mp_uint_t val) { +static void emit_write_bytecode_byte_uint(emit_t *emit, int stack_adj, byte b, mp_uint_t val) { emit_write_bytecode_byte(emit, stack_adj, b); mp_encode_uint(emit, emit_get_cur_to_write_bytecode, val); } -STATIC void emit_write_bytecode_byte_const(emit_t *emit, int stack_adj, byte b, mp_uint_t n) { +static void emit_write_bytecode_byte_const(emit_t *emit, int stack_adj, byte b, mp_uint_t n) { emit_write_bytecode_byte_uint(emit, stack_adj, b, n); } -STATIC void emit_write_bytecode_byte_qstr(emit_t *emit, int stack_adj, byte b, qstr qst) { +static void emit_write_bytecode_byte_qstr(emit_t *emit, int stack_adj, byte b, qstr qst) { emit_write_bytecode_byte_uint(emit, stack_adj, b, mp_emit_common_use_qstr(emit->emit_common, qst)); } -STATIC void emit_write_bytecode_byte_obj(emit_t *emit, int stack_adj, byte b, mp_obj_t obj) { +static void emit_write_bytecode_byte_obj(emit_t *emit, int stack_adj, byte b, mp_obj_t obj) { emit_write_bytecode_byte_const(emit, stack_adj, b, mp_emit_common_use_const_obj(emit->emit_common, obj)); } -STATIC void emit_write_bytecode_byte_child(emit_t *emit, int stack_adj, byte b, mp_raw_code_t *rc) { +static void emit_write_bytecode_byte_child(emit_t *emit, int stack_adj, byte b, mp_raw_code_t *rc) { emit_write_bytecode_byte_const(emit, stack_adj, b, mp_emit_common_alloc_const_child(emit->emit_common, rc)); #if MICROPY_PY_SYS_SETTRACE @@ -227,7 +227,7 @@ STATIC void emit_write_bytecode_byte_child(emit_t *emit, int stack_adj, byte b, // The offset is encoded as either 1 or 2 bytes, depending on how big it is. // The encoding of this jump opcode can change size from one pass to the next, // but it must only ever decrease in size on successive passes. -STATIC void emit_write_bytecode_byte_label(emit_t *emit, int stack_adj, byte b1, mp_uint_t label) { +static void emit_write_bytecode_byte_label(emit_t *emit, int stack_adj, byte b1, mp_uint_t label) { mp_emit_bc_adjust_stack_size(emit, stack_adj); if (emit->suppress) { @@ -768,7 +768,7 @@ void mp_emit_bc_make_closure(emit_t *emit, scope_t *scope, mp_uint_t n_closed_ov } } -STATIC void emit_bc_call_function_method_helper(emit_t *emit, int stack_adj, mp_uint_t bytecode_base, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags) { +static void emit_bc_call_function_method_helper(emit_t *emit, int stack_adj, mp_uint_t bytecode_base, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags) { if (star_flags) { // each positional arg is one object, each kwarg is two objects, the key // and the value and one extra object for the star args bitmap. diff --git a/py/emitinlinethumb.c b/py/emitinlinethumb.c index 29487f10483f9..7818bb4f46da8 100644 --- a/py/emitinlinethumb.c +++ b/py/emitinlinethumb.c @@ -74,11 +74,11 @@ static inline bool emit_inline_thumb_allow_float(emit_inline_asm_t *emit) { #endif -STATIC void emit_inline_thumb_error_msg(emit_inline_asm_t *emit, mp_rom_error_text_t msg) { +static void emit_inline_thumb_error_msg(emit_inline_asm_t *emit, mp_rom_error_text_t msg) { *emit->error_slot = mp_obj_new_exception_msg(&mp_type_SyntaxError, msg); } -STATIC void emit_inline_thumb_error_exc(emit_inline_asm_t *emit, mp_obj_t exc) { +static void emit_inline_thumb_error_exc(emit_inline_asm_t *emit, mp_obj_t exc) { *emit->error_slot = exc; } @@ -97,7 +97,7 @@ void emit_inline_thumb_free(emit_inline_asm_t *emit) { m_del_obj(emit_inline_asm_t, emit); } -STATIC void emit_inline_thumb_start_pass(emit_inline_asm_t *emit, pass_kind_t pass, mp_obj_t *error_slot) { +static void emit_inline_thumb_start_pass(emit_inline_asm_t *emit, pass_kind_t pass, mp_obj_t *error_slot) { emit->pass = pass; emit->error_slot = error_slot; if (emit->pass == MP_PASS_CODE_SIZE) { @@ -107,12 +107,12 @@ STATIC void emit_inline_thumb_start_pass(emit_inline_asm_t *emit, pass_kind_t pa asm_thumb_entry(&emit->as, 0); } -STATIC void emit_inline_thumb_end_pass(emit_inline_asm_t *emit, mp_uint_t type_sig) { +static void emit_inline_thumb_end_pass(emit_inline_asm_t *emit, mp_uint_t type_sig) { asm_thumb_exit(&emit->as); asm_thumb_end_pass(&emit->as); } -STATIC mp_uint_t emit_inline_thumb_count_params(emit_inline_asm_t *emit, mp_uint_t n_params, mp_parse_node_t *pn_params) { +static mp_uint_t emit_inline_thumb_count_params(emit_inline_asm_t *emit, mp_uint_t n_params, mp_parse_node_t *pn_params) { if (n_params > 4) { emit_inline_thumb_error_msg(emit, MP_ERROR_TEXT("can only have up to 4 parameters to Thumb assembly")); return 0; @@ -131,7 +131,7 @@ STATIC mp_uint_t emit_inline_thumb_count_params(emit_inline_asm_t *emit, mp_uint return n_params; } -STATIC bool emit_inline_thumb_label(emit_inline_asm_t *emit, mp_uint_t label_num, qstr label_id) { +static bool emit_inline_thumb_label(emit_inline_asm_t *emit, mp_uint_t label_num, qstr label_id) { assert(label_num < emit->max_num_labels); if (emit->pass == MP_PASS_CODE_SIZE) { // check for duplicate label on first pass @@ -149,7 +149,7 @@ STATIC bool emit_inline_thumb_label(emit_inline_asm_t *emit, mp_uint_t label_num typedef struct _reg_name_t { byte reg; byte name[3]; } reg_name_t; -STATIC const reg_name_t reg_name_table[] = { +static const reg_name_t reg_name_table[] = { {0, "r0\0"}, {1, "r1\0"}, {2, "r2\0"}, @@ -177,14 +177,14 @@ STATIC const reg_name_t reg_name_table[] = { typedef struct _special_reg_name_t { byte reg; char name[MAX_SPECIAL_REGISTER_NAME_LENGTH + 1]; } special_reg_name_t; -STATIC const special_reg_name_t special_reg_name_table[] = { +static const special_reg_name_t special_reg_name_table[] = { {5, "IPSR"}, {17, "BASEPRI"}, }; // return empty string in case of error, so we can attempt to parse the string // without a special check if it was in fact a string -STATIC const char *get_arg_str(mp_parse_node_t pn) { +static const char *get_arg_str(mp_parse_node_t pn) { if (MP_PARSE_NODE_IS_ID(pn)) { qstr qst = MP_PARSE_NODE_LEAF_ARG(pn); return qstr_str(qst); @@ -193,7 +193,7 @@ STATIC const char *get_arg_str(mp_parse_node_t pn) { } } -STATIC mp_uint_t get_arg_reg(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn, mp_uint_t max_reg) { +static mp_uint_t get_arg_reg(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn, mp_uint_t max_reg) { const char *reg_str = get_arg_str(pn); for (mp_uint_t i = 0; i < MP_ARRAY_SIZE(reg_name_table); i++) { const reg_name_t *r = ®_name_table[i]; @@ -217,7 +217,7 @@ STATIC mp_uint_t get_arg_reg(emit_inline_asm_t *emit, const char *op, mp_parse_n return 0; } -STATIC mp_uint_t get_arg_special_reg(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) { +static mp_uint_t get_arg_special_reg(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) { const char *reg_str = get_arg_str(pn); for (mp_uint_t i = 0; i < MP_ARRAY_SIZE(special_reg_name_table); i++) { const special_reg_name_t *r = &special_reg_name_table[i]; @@ -231,7 +231,7 @@ STATIC mp_uint_t get_arg_special_reg(emit_inline_asm_t *emit, const char *op, mp return 0; } -STATIC mp_uint_t get_arg_vfpreg(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) { +static mp_uint_t get_arg_vfpreg(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) { const char *reg_str = get_arg_str(pn); if (reg_str[0] == 's' && reg_str[1] != '\0') { mp_uint_t regno = 0; @@ -258,7 +258,7 @@ STATIC mp_uint_t get_arg_vfpreg(emit_inline_asm_t *emit, const char *op, mp_pars return 0; } -STATIC mp_uint_t get_arg_reglist(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) { +static mp_uint_t get_arg_reglist(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) { // a register list looks like {r0, r1, r2} and is parsed as a Python set if (!MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_atom_brace)) { @@ -310,7 +310,7 @@ STATIC mp_uint_t get_arg_reglist(emit_inline_asm_t *emit, const char *op, mp_par return 0; } -STATIC uint32_t get_arg_i(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn, uint32_t fit_mask) { +static uint32_t get_arg_i(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn, uint32_t fit_mask) { mp_obj_t o; if (!mp_parse_node_get_int_maybe(pn, &o)) { emit_inline_thumb_error_exc(emit, mp_obj_new_exception_msg_varg(&mp_type_SyntaxError, MP_ERROR_TEXT("'%s' expects an integer"), op)); @@ -324,7 +324,7 @@ STATIC uint32_t get_arg_i(emit_inline_asm_t *emit, const char *op, mp_parse_node return i; } -STATIC bool get_arg_addr(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn, mp_parse_node_t *pn_base, mp_parse_node_t *pn_offset) { +static bool get_arg_addr(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn, mp_parse_node_t *pn_base, mp_parse_node_t *pn_offset) { if (!MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_atom_bracket)) { goto bad_arg; } @@ -346,7 +346,7 @@ STATIC bool get_arg_addr(emit_inline_asm_t *emit, const char *op, mp_parse_node_ return false; } -STATIC int get_arg_label(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) { +static int get_arg_label(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) { if (!MP_PARSE_NODE_IS_ID(pn)) { emit_inline_thumb_error_exc(emit, mp_obj_new_exception_msg_varg(&mp_type_SyntaxError, MP_ERROR_TEXT("'%s' expects a label"), op)); return 0; @@ -367,7 +367,7 @@ STATIC int get_arg_label(emit_inline_asm_t *emit, const char *op, mp_parse_node_ typedef struct _cc_name_t { byte cc; byte name[2]; } cc_name_t; -STATIC const cc_name_t cc_name_table[] = { +static const cc_name_t cc_name_table[] = { { ASM_THUMB_CC_EQ, "eq" }, { ASM_THUMB_CC_NE, "ne" }, { ASM_THUMB_CC_CS, "cs" }, @@ -388,7 +388,7 @@ typedef struct _format_4_op_t { byte op; char name[3]; } format_4_op_t; #define X(x) (((x) >> 4) & 0xff) // only need 1 byte to distinguish these ops -STATIC const format_4_op_t format_4_op_table[] = { +static const format_4_op_t format_4_op_table[] = { { X(ASM_THUMB_FORMAT_4_EOR), "eor" }, { X(ASM_THUMB_FORMAT_4_LSL), "lsl" }, { X(ASM_THUMB_FORMAT_4_LSR), "lsr" }, @@ -412,7 +412,7 @@ typedef struct _format_9_10_op_t { uint16_t op; uint16_t name; } format_9_10_op_t; #define X(x) (x) -STATIC const format_9_10_op_t format_9_10_op_table[] = { +static const format_9_10_op_t format_9_10_op_table[] = { { X(ASM_THUMB_FORMAT_9_LDR | ASM_THUMB_FORMAT_9_WORD_TRANSFER), MP_QSTR_ldr }, { X(ASM_THUMB_FORMAT_9_LDR | ASM_THUMB_FORMAT_9_BYTE_TRANSFER), MP_QSTR_ldrb }, { X(ASM_THUMB_FORMAT_10_LDRH), MP_QSTR_ldrh }, @@ -427,7 +427,7 @@ typedef struct _format_vfp_op_t { byte op; char name[3]; } format_vfp_op_t; -STATIC const format_vfp_op_t format_vfp_op_table[] = { +static const format_vfp_op_t format_vfp_op_table[] = { { 0x30, "add" }, { 0x34, "sub" }, { 0x20, "mul" }, @@ -437,7 +437,7 @@ STATIC const format_vfp_op_t format_vfp_op_table[] = { // shorthand alias for whether we allow ARMv7-M instructions #define ARMV7M asm_thumb_allow_armv7m(&emit->as) -STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_args, mp_parse_node_t *pn_args) { +static void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_args, mp_parse_node_t *pn_args) { // TODO perhaps make two tables: // one_args = // "b", LAB, asm_thumb_b_n, diff --git a/py/emitinlinextensa.c b/py/emitinlinextensa.c index 5dac2ae3907f1..57056d597aab7 100644 --- a/py/emitinlinextensa.c +++ b/py/emitinlinextensa.c @@ -43,11 +43,11 @@ struct _emit_inline_asm_t { qstr *label_lookup; }; -STATIC void emit_inline_xtensa_error_msg(emit_inline_asm_t *emit, mp_rom_error_text_t msg) { +static void emit_inline_xtensa_error_msg(emit_inline_asm_t *emit, mp_rom_error_text_t msg) { *emit->error_slot = mp_obj_new_exception_msg(&mp_type_SyntaxError, msg); } -STATIC void emit_inline_xtensa_error_exc(emit_inline_asm_t *emit, mp_obj_t exc) { +static void emit_inline_xtensa_error_exc(emit_inline_asm_t *emit, mp_obj_t exc) { *emit->error_slot = exc; } @@ -66,7 +66,7 @@ void emit_inline_xtensa_free(emit_inline_asm_t *emit) { m_del_obj(emit_inline_asm_t, emit); } -STATIC void emit_inline_xtensa_start_pass(emit_inline_asm_t *emit, pass_kind_t pass, mp_obj_t *error_slot) { +static void emit_inline_xtensa_start_pass(emit_inline_asm_t *emit, pass_kind_t pass, mp_obj_t *error_slot) { emit->pass = pass; emit->error_slot = error_slot; if (emit->pass == MP_PASS_CODE_SIZE) { @@ -76,12 +76,12 @@ STATIC void emit_inline_xtensa_start_pass(emit_inline_asm_t *emit, pass_kind_t p asm_xtensa_entry(&emit->as, 0); } -STATIC void emit_inline_xtensa_end_pass(emit_inline_asm_t *emit, mp_uint_t type_sig) { +static void emit_inline_xtensa_end_pass(emit_inline_asm_t *emit, mp_uint_t type_sig) { asm_xtensa_exit(&emit->as); asm_xtensa_end_pass(&emit->as); } -STATIC mp_uint_t emit_inline_xtensa_count_params(emit_inline_asm_t *emit, mp_uint_t n_params, mp_parse_node_t *pn_params) { +static mp_uint_t emit_inline_xtensa_count_params(emit_inline_asm_t *emit, mp_uint_t n_params, mp_parse_node_t *pn_params) { if (n_params > 4) { emit_inline_xtensa_error_msg(emit, MP_ERROR_TEXT("can only have up to 4 parameters to Xtensa assembly")); return 0; @@ -100,7 +100,7 @@ STATIC mp_uint_t emit_inline_xtensa_count_params(emit_inline_asm_t *emit, mp_uin return n_params; } -STATIC bool emit_inline_xtensa_label(emit_inline_asm_t *emit, mp_uint_t label_num, qstr label_id) { +static bool emit_inline_xtensa_label(emit_inline_asm_t *emit, mp_uint_t label_num, qstr label_id) { assert(label_num < emit->max_num_labels); if (emit->pass == MP_PASS_CODE_SIZE) { // check for duplicate label on first pass @@ -118,7 +118,7 @@ STATIC bool emit_inline_xtensa_label(emit_inline_asm_t *emit, mp_uint_t label_nu typedef struct _reg_name_t { byte reg; byte name[3]; } reg_name_t; -STATIC const reg_name_t reg_name_table[] = { +static const reg_name_t reg_name_table[] = { {0, "a0\0"}, {1, "a1\0"}, {2, "a2\0"}, @@ -139,7 +139,7 @@ STATIC const reg_name_t reg_name_table[] = { // return empty string in case of error, so we can attempt to parse the string // without a special check if it was in fact a string -STATIC const char *get_arg_str(mp_parse_node_t pn) { +static const char *get_arg_str(mp_parse_node_t pn) { if (MP_PARSE_NODE_IS_ID(pn)) { qstr qst = MP_PARSE_NODE_LEAF_ARG(pn); return qstr_str(qst); @@ -148,7 +148,7 @@ STATIC const char *get_arg_str(mp_parse_node_t pn) { } } -STATIC mp_uint_t get_arg_reg(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) { +static mp_uint_t get_arg_reg(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) { const char *reg_str = get_arg_str(pn); for (mp_uint_t i = 0; i < MP_ARRAY_SIZE(reg_name_table); i++) { const reg_name_t *r = ®_name_table[i]; @@ -165,7 +165,7 @@ STATIC mp_uint_t get_arg_reg(emit_inline_asm_t *emit, const char *op, mp_parse_n return 0; } -STATIC uint32_t get_arg_i(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn, int min, int max) { +static uint32_t get_arg_i(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn, int min, int max) { mp_obj_t o; if (!mp_parse_node_get_int_maybe(pn, &o)) { emit_inline_xtensa_error_exc(emit, mp_obj_new_exception_msg_varg(&mp_type_SyntaxError, MP_ERROR_TEXT("'%s' expects an integer"), op)); @@ -179,7 +179,7 @@ STATIC uint32_t get_arg_i(emit_inline_asm_t *emit, const char *op, mp_parse_node return i; } -STATIC int get_arg_label(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) { +static int get_arg_label(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) { if (!MP_PARSE_NODE_IS_ID(pn)) { emit_inline_xtensa_error_exc(emit, mp_obj_new_exception_msg_varg(&mp_type_SyntaxError, MP_ERROR_TEXT("'%s' expects a label"), op)); return 0; @@ -208,7 +208,7 @@ typedef struct _opcode_table_3arg_t { uint8_t a1 : 4; } opcode_table_3arg_t; -STATIC const opcode_table_3arg_t opcode_table_3arg[] = { +static const opcode_table_3arg_t opcode_table_3arg[] = { // arithmetic opcodes: reg, reg, reg {MP_QSTR_and_, RRR, 0, 1}, {MP_QSTR_or_, RRR, 0, 2}, @@ -242,7 +242,7 @@ STATIC const opcode_table_3arg_t opcode_table_3arg[] = { {MP_QSTR_bnone, RRI8_B, ASM_XTENSA_CC_NONE, 0}, }; -STATIC void emit_inline_xtensa_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_args, mp_parse_node_t *pn_args) { +static void emit_inline_xtensa_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_args, mp_parse_node_t *pn_args) { size_t op_len; const char *op_str = (const char *)qstr_data(op, &op_len); diff --git a/py/emitnative.c b/py/emitnative.c index 6b5c9452ae6aa..f80461dd42f3b 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -156,7 +156,7 @@ #define REG_QSTR_TABLE (REG_LOCAL_3) #define MAX_REGS_FOR_LOCAL_VARS (2) -STATIC const uint8_t reg_local_table[MAX_REGS_FOR_LOCAL_VARS] = {REG_LOCAL_1, REG_LOCAL_2}; +static const uint8_t reg_local_table[MAX_REGS_FOR_LOCAL_VARS] = {REG_LOCAL_1, REG_LOCAL_2}; #else @@ -168,7 +168,7 @@ STATIC const uint8_t reg_local_table[MAX_REGS_FOR_LOCAL_VARS] = {REG_LOCAL_1, RE #define REG_GENERATOR_STATE (REG_LOCAL_3) #define MAX_REGS_FOR_LOCAL_VARS (3) -STATIC const uint8_t reg_local_table[MAX_REGS_FOR_LOCAL_VARS] = {REG_LOCAL_1, REG_LOCAL_2, REG_LOCAL_3}; +static const uint8_t reg_local_table[MAX_REGS_FOR_LOCAL_VARS] = {REG_LOCAL_1, REG_LOCAL_2, REG_LOCAL_3}; #endif @@ -202,7 +202,7 @@ typedef enum { VTYPE_BUILTIN_CAST = 0x70 | MP_NATIVE_TYPE_OBJ, } vtype_kind_t; -STATIC qstr vtype_to_qstr(vtype_kind_t vtype) { +static qstr vtype_to_qstr(vtype_kind_t vtype) { switch (vtype) { case VTYPE_PYOBJ: return MP_QSTR_object; @@ -280,10 +280,10 @@ struct _emit_t { ASM_T *as; }; -STATIC void emit_load_reg_with_object(emit_t *emit, int reg, mp_obj_t obj); -STATIC void emit_native_global_exc_entry(emit_t *emit); -STATIC void emit_native_global_exc_exit(emit_t *emit); -STATIC void emit_native_load_const_obj(emit_t *emit, mp_obj_t obj); +static void emit_load_reg_with_object(emit_t *emit, int reg, mp_obj_t obj); +static void emit_native_global_exc_entry(emit_t *emit); +static void emit_native_global_exc_exit(emit_t *emit); +static void emit_native_load_const_obj(emit_t *emit, mp_obj_t obj); emit_t *EXPORT_FUN(new)(mp_emit_common_t * emit_common, mp_obj_t *error_slot, uint *label_slot, mp_uint_t max_num_labels) { emit_t *emit = m_new0(emit_t, 1); @@ -308,13 +308,13 @@ void EXPORT_FUN(free)(emit_t * emit) { m_del_obj(emit_t, emit); } -STATIC void emit_call_with_imm_arg(emit_t *emit, mp_fun_kind_t fun_kind, mp_int_t arg_val, int arg_reg); +static void emit_call_with_imm_arg(emit_t *emit, mp_fun_kind_t fun_kind, mp_int_t arg_val, int arg_reg); -STATIC void emit_native_mov_reg_const(emit_t *emit, int reg_dest, int const_val) { +static void emit_native_mov_reg_const(emit_t *emit, int reg_dest, int const_val) { ASM_LOAD_REG_REG_OFFSET(emit->as, reg_dest, REG_FUN_TABLE, const_val); } -STATIC void emit_native_mov_state_reg(emit_t *emit, int local_num, int reg_src) { +static void emit_native_mov_state_reg(emit_t *emit, int local_num, int reg_src) { if (emit->scope->scope_flags & MP_SCOPE_FLAG_GENERATOR) { ASM_STORE_REG_REG_OFFSET(emit->as, reg_src, REG_GENERATOR_STATE, local_num); } else { @@ -322,7 +322,7 @@ STATIC void emit_native_mov_state_reg(emit_t *emit, int local_num, int reg_src) } } -STATIC void emit_native_mov_reg_state(emit_t *emit, int reg_dest, int local_num) { +static void emit_native_mov_reg_state(emit_t *emit, int reg_dest, int local_num) { if (emit->scope->scope_flags & MP_SCOPE_FLAG_GENERATOR) { ASM_LOAD_REG_REG_OFFSET(emit->as, reg_dest, REG_GENERATOR_STATE, local_num); } else { @@ -330,7 +330,7 @@ STATIC void emit_native_mov_reg_state(emit_t *emit, int reg_dest, int local_num) } } -STATIC void emit_native_mov_reg_state_addr(emit_t *emit, int reg_dest, int local_num) { +static void emit_native_mov_reg_state_addr(emit_t *emit, int reg_dest, int local_num) { if (emit->scope->scope_flags & MP_SCOPE_FLAG_GENERATOR) { ASM_MOV_REG_IMM(emit->as, reg_dest, local_num * ASM_WORD_SIZE); ASM_ADD_REG_REG(emit->as, reg_dest, REG_GENERATOR_STATE); @@ -339,7 +339,7 @@ STATIC void emit_native_mov_reg_state_addr(emit_t *emit, int reg_dest, int local } } -STATIC void emit_native_mov_reg_qstr(emit_t *emit, int arg_reg, qstr qst) { +static void emit_native_mov_reg_qstr(emit_t *emit, int arg_reg, qstr qst) { #if MICROPY_PERSISTENT_CODE_SAVE ASM_LOAD16_REG_REG_OFFSET(emit->as, arg_reg, REG_QSTR_TABLE, mp_emit_common_use_qstr(emit->emit_common, qst)); #else @@ -347,7 +347,7 @@ STATIC void emit_native_mov_reg_qstr(emit_t *emit, int arg_reg, qstr qst) { #endif } -STATIC void emit_native_mov_reg_qstr_obj(emit_t *emit, int reg_dest, qstr qst) { +static void emit_native_mov_reg_qstr_obj(emit_t *emit, int reg_dest, qstr qst) { #if MICROPY_PERSISTENT_CODE_SAVE emit_load_reg_with_object(emit, reg_dest, MP_OBJ_NEW_QSTR(qst)); #else @@ -361,7 +361,7 @@ STATIC void emit_native_mov_reg_qstr_obj(emit_t *emit, int reg_dest, qstr qst) { emit_native_mov_state_reg((emit), (local_num), (reg_temp)); \ } while (false) -STATIC void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) { +static void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) { DEBUG_printf("start_pass(pass=%u, scope=%p)\n", pass, scope); emit->pass = pass; @@ -632,7 +632,7 @@ static inline void emit_native_write_code_info_qstr(emit_t *emit, qstr qst) { mp_encode_uint(&emit->as->base, mp_asm_base_get_cur_to_write_bytes, mp_emit_common_use_qstr(emit->emit_common, qst)); } -STATIC bool emit_native_end_pass(emit_t *emit) { +static bool emit_native_end_pass(emit_t *emit) { emit_native_global_exc_exit(emit); if (!emit->do_viper_types) { @@ -723,7 +723,7 @@ STATIC bool emit_native_end_pass(emit_t *emit) { return true; } -STATIC void ensure_extra_stack(emit_t *emit, size_t delta) { +static void ensure_extra_stack(emit_t *emit, size_t delta) { if (emit->stack_size + delta > emit->stack_info_alloc) { size_t new_alloc = (emit->stack_size + delta + 8) & ~3; emit->stack_info = m_renew(stack_info_t, emit->stack_info, emit->stack_info_alloc, new_alloc); @@ -731,7 +731,7 @@ STATIC void ensure_extra_stack(emit_t *emit, size_t delta) { } } -STATIC void adjust_stack(emit_t *emit, mp_int_t stack_size_delta) { +static void adjust_stack(emit_t *emit, mp_int_t stack_size_delta) { assert((mp_int_t)emit->stack_size + stack_size_delta >= 0); assert((mp_int_t)emit->stack_size + stack_size_delta <= (mp_int_t)emit->stack_info_alloc); emit->stack_size += stack_size_delta; @@ -748,7 +748,7 @@ STATIC void adjust_stack(emit_t *emit, mp_int_t stack_size_delta) { #endif } -STATIC void emit_native_adjust_stack_size(emit_t *emit, mp_int_t delta) { +static void emit_native_adjust_stack_size(emit_t *emit, mp_int_t delta) { DEBUG_printf("adjust_stack_size(" INT_FMT ")\n", delta); if (delta > 0) { ensure_extra_stack(emit, delta); @@ -772,23 +772,23 @@ STATIC void emit_native_adjust_stack_size(emit_t *emit, mp_int_t delta) { adjust_stack(emit, delta); } -STATIC void emit_native_set_source_line(emit_t *emit, mp_uint_t source_line) { +static void emit_native_set_source_line(emit_t *emit, mp_uint_t source_line) { (void)emit; (void)source_line; } // this must be called at start of emit functions -STATIC void emit_native_pre(emit_t *emit) { +static void emit_native_pre(emit_t *emit) { (void)emit; } // depth==0 is top, depth==1 is before top, etc -STATIC stack_info_t *peek_stack(emit_t *emit, mp_uint_t depth) { +static stack_info_t *peek_stack(emit_t *emit, mp_uint_t depth) { return &emit->stack_info[emit->stack_size - 1 - depth]; } // depth==0 is top, depth==1 is before top, etc -STATIC vtype_kind_t peek_vtype(emit_t *emit, mp_uint_t depth) { +static vtype_kind_t peek_vtype(emit_t *emit, mp_uint_t depth) { if (emit->do_viper_types) { return peek_stack(emit, depth)->vtype; } else { @@ -799,7 +799,7 @@ STATIC vtype_kind_t peek_vtype(emit_t *emit, mp_uint_t depth) { // pos=1 is TOS, pos=2 is next, etc // use pos=0 for no skipping -STATIC void need_reg_single(emit_t *emit, int reg_needed, int skip_stack_pos) { +static void need_reg_single(emit_t *emit, int reg_needed, int skip_stack_pos) { skip_stack_pos = emit->stack_size - skip_stack_pos; for (int i = 0; i < emit->stack_size; i++) { if (i != skip_stack_pos) { @@ -814,7 +814,7 @@ STATIC void need_reg_single(emit_t *emit, int reg_needed, int skip_stack_pos) { // Ensures all unsettled registers that hold Python values are copied to the // concrete Python stack. All registers are then free to use. -STATIC void need_reg_all(emit_t *emit) { +static void need_reg_all(emit_t *emit) { for (int i = 0; i < emit->stack_size; i++) { stack_info_t *si = &emit->stack_info[i]; if (si->kind == STACK_REG) { @@ -825,7 +825,7 @@ STATIC void need_reg_all(emit_t *emit) { } } -STATIC vtype_kind_t load_reg_stack_imm(emit_t *emit, int reg_dest, const stack_info_t *si, bool convert_to_pyobj) { +static vtype_kind_t load_reg_stack_imm(emit_t *emit, int reg_dest, const stack_info_t *si, bool convert_to_pyobj) { if (!convert_to_pyobj && emit->do_viper_types) { ASM_MOV_REG_IMM(emit->as, reg_dest, si->data.u_imm); return si->vtype; @@ -849,7 +849,7 @@ STATIC vtype_kind_t load_reg_stack_imm(emit_t *emit, int reg_dest, const stack_i // concrete Python stack. This ensures the concrete Python stack holds valid // values for the current stack_size. // This function may clobber REG_TEMP1. -STATIC void need_stack_settled(emit_t *emit) { +static void need_stack_settled(emit_t *emit) { DEBUG_printf(" need_stack_settled; stack_size=%d\n", emit->stack_size); need_reg_all(emit); for (int i = 0; i < emit->stack_size; i++) { @@ -865,7 +865,7 @@ STATIC void need_stack_settled(emit_t *emit) { } // pos=1 is TOS, pos=2 is next, etc -STATIC void emit_access_stack(emit_t *emit, int pos, vtype_kind_t *vtype, int reg_dest) { +static void emit_access_stack(emit_t *emit, int pos, vtype_kind_t *vtype, int reg_dest) { need_reg_single(emit, reg_dest, pos); stack_info_t *si = &emit->stack_info[emit->stack_size - pos]; *vtype = si->vtype; @@ -888,7 +888,7 @@ STATIC void emit_access_stack(emit_t *emit, int pos, vtype_kind_t *vtype, int re // does an efficient X=pop(); discard(); push(X) // needs a (non-temp) register in case the popped element was stored in the stack -STATIC void emit_fold_stack_top(emit_t *emit, int reg_dest) { +static void emit_fold_stack_top(emit_t *emit, int reg_dest) { stack_info_t *si = &emit->stack_info[emit->stack_size - 2]; si[0] = si[1]; if (si->kind == STACK_VALUE) { @@ -902,7 +902,7 @@ STATIC void emit_fold_stack_top(emit_t *emit, int reg_dest) { // If stacked value is in a register and the register is not r1 or r2, then // *reg_dest is set to that register. Otherwise the value is put in *reg_dest. -STATIC void emit_pre_pop_reg_flexible(emit_t *emit, vtype_kind_t *vtype, int *reg_dest, int not_r1, int not_r2) { +static void emit_pre_pop_reg_flexible(emit_t *emit, vtype_kind_t *vtype, int *reg_dest, int not_r1, int not_r2) { stack_info_t *si = peek_stack(emit, 0); if (si->kind == STACK_REG && si->data.u_reg != not_r1 && si->data.u_reg != not_r2) { *vtype = si->vtype; @@ -914,36 +914,36 @@ STATIC void emit_pre_pop_reg_flexible(emit_t *emit, vtype_kind_t *vtype, int *re adjust_stack(emit, -1); } -STATIC void emit_pre_pop_discard(emit_t *emit) { +static void emit_pre_pop_discard(emit_t *emit) { adjust_stack(emit, -1); } -STATIC void emit_pre_pop_reg(emit_t *emit, vtype_kind_t *vtype, int reg_dest) { +static void emit_pre_pop_reg(emit_t *emit, vtype_kind_t *vtype, int reg_dest) { emit_access_stack(emit, 1, vtype, reg_dest); adjust_stack(emit, -1); } -STATIC void emit_pre_pop_reg_reg(emit_t *emit, vtype_kind_t *vtypea, int rega, vtype_kind_t *vtypeb, int regb) { +static void emit_pre_pop_reg_reg(emit_t *emit, vtype_kind_t *vtypea, int rega, vtype_kind_t *vtypeb, int regb) { emit_pre_pop_reg(emit, vtypea, rega); emit_pre_pop_reg(emit, vtypeb, regb); } -STATIC void emit_pre_pop_reg_reg_reg(emit_t *emit, vtype_kind_t *vtypea, int rega, vtype_kind_t *vtypeb, int regb, vtype_kind_t *vtypec, int regc) { +static void emit_pre_pop_reg_reg_reg(emit_t *emit, vtype_kind_t *vtypea, int rega, vtype_kind_t *vtypeb, int regb, vtype_kind_t *vtypec, int regc) { emit_pre_pop_reg(emit, vtypea, rega); emit_pre_pop_reg(emit, vtypeb, regb); emit_pre_pop_reg(emit, vtypec, regc); } -STATIC void emit_post(emit_t *emit) { +static void emit_post(emit_t *emit) { (void)emit; } -STATIC void emit_post_top_set_vtype(emit_t *emit, vtype_kind_t new_vtype) { +static void emit_post_top_set_vtype(emit_t *emit, vtype_kind_t new_vtype) { stack_info_t *si = &emit->stack_info[emit->stack_size - 1]; si->vtype = new_vtype; } -STATIC void emit_post_push_reg(emit_t *emit, vtype_kind_t vtype, int reg) { +static void emit_post_push_reg(emit_t *emit, vtype_kind_t vtype, int reg) { ensure_extra_stack(emit, 1); stack_info_t *si = &emit->stack_info[emit->stack_size]; si->vtype = vtype; @@ -952,7 +952,7 @@ STATIC void emit_post_push_reg(emit_t *emit, vtype_kind_t vtype, int reg) { adjust_stack(emit, 1); } -STATIC void emit_post_push_imm(emit_t *emit, vtype_kind_t vtype, mp_int_t imm) { +static void emit_post_push_imm(emit_t *emit, vtype_kind_t vtype, mp_int_t imm) { ensure_extra_stack(emit, 1); stack_info_t *si = &emit->stack_info[emit->stack_size]; si->vtype = vtype; @@ -961,43 +961,43 @@ STATIC void emit_post_push_imm(emit_t *emit, vtype_kind_t vtype, mp_int_t imm) { adjust_stack(emit, 1); } -STATIC void emit_post_push_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb) { +static void emit_post_push_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb) { emit_post_push_reg(emit, vtypea, rega); emit_post_push_reg(emit, vtypeb, regb); } -STATIC void emit_post_push_reg_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb, vtype_kind_t vtypec, int regc) { +static void emit_post_push_reg_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb, vtype_kind_t vtypec, int regc) { emit_post_push_reg(emit, vtypea, rega); emit_post_push_reg(emit, vtypeb, regb); emit_post_push_reg(emit, vtypec, regc); } -STATIC void emit_post_push_reg_reg_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb, vtype_kind_t vtypec, int regc, vtype_kind_t vtyped, int regd) { +static void emit_post_push_reg_reg_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb, vtype_kind_t vtypec, int regc, vtype_kind_t vtyped, int regd) { emit_post_push_reg(emit, vtypea, rega); emit_post_push_reg(emit, vtypeb, regb); emit_post_push_reg(emit, vtypec, regc); emit_post_push_reg(emit, vtyped, regd); } -STATIC void emit_call(emit_t *emit, mp_fun_kind_t fun_kind) { +static void emit_call(emit_t *emit, mp_fun_kind_t fun_kind) { need_reg_all(emit); ASM_CALL_IND(emit->as, fun_kind); } -STATIC void emit_call_with_imm_arg(emit_t *emit, mp_fun_kind_t fun_kind, mp_int_t arg_val, int arg_reg) { +static void emit_call_with_imm_arg(emit_t *emit, mp_fun_kind_t fun_kind, mp_int_t arg_val, int arg_reg) { need_reg_all(emit); ASM_MOV_REG_IMM(emit->as, arg_reg, arg_val); ASM_CALL_IND(emit->as, fun_kind); } -STATIC void emit_call_with_2_imm_args(emit_t *emit, mp_fun_kind_t fun_kind, mp_int_t arg_val1, int arg_reg1, mp_int_t arg_val2, int arg_reg2) { +static void emit_call_with_2_imm_args(emit_t *emit, mp_fun_kind_t fun_kind, mp_int_t arg_val1, int arg_reg1, mp_int_t arg_val2, int arg_reg2) { need_reg_all(emit); ASM_MOV_REG_IMM(emit->as, arg_reg1, arg_val1); ASM_MOV_REG_IMM(emit->as, arg_reg2, arg_val2); ASM_CALL_IND(emit->as, fun_kind); } -STATIC void emit_call_with_qstr_arg(emit_t *emit, mp_fun_kind_t fun_kind, qstr qst, int arg_reg) { +static void emit_call_with_qstr_arg(emit_t *emit, mp_fun_kind_t fun_kind, qstr qst, int arg_reg) { need_reg_all(emit); emit_native_mov_reg_qstr(emit, arg_reg, qst); ASM_CALL_IND(emit->as, fun_kind); @@ -1007,7 +1007,7 @@ STATIC void emit_call_with_qstr_arg(emit_t *emit, mp_fun_kind_t fun_kind, qstr q // Will convert any items that are not VTYPE_PYOBJ to this type and put them back on the stack. // If any conversions of non-immediate values are needed, then it uses REG_ARG_1, REG_ARG_2 and REG_RET. // Otherwise, it does not use any temporary registers (but may use reg_dest before loading it with stack pointer). -STATIC void emit_get_stack_pointer_to_reg_for_pop(emit_t *emit, mp_uint_t reg_dest, mp_uint_t n_pop) { +static void emit_get_stack_pointer_to_reg_for_pop(emit_t *emit, mp_uint_t reg_dest, mp_uint_t n_pop) { need_reg_all(emit); // First, store any immediate values to their respective place on the stack. @@ -1044,7 +1044,7 @@ STATIC void emit_get_stack_pointer_to_reg_for_pop(emit_t *emit, mp_uint_t reg_de } // vtype of all n_push objects is VTYPE_PYOBJ -STATIC void emit_get_stack_pointer_to_reg_for_push(emit_t *emit, mp_uint_t reg_dest, mp_uint_t n_push) { +static void emit_get_stack_pointer_to_reg_for_push(emit_t *emit, mp_uint_t reg_dest, mp_uint_t n_push) { need_reg_all(emit); ensure_extra_stack(emit, n_push); for (mp_uint_t i = 0; i < n_push; i++) { @@ -1055,7 +1055,7 @@ STATIC void emit_get_stack_pointer_to_reg_for_push(emit_t *emit, mp_uint_t reg_d adjust_stack(emit, n_push); } -STATIC void emit_native_push_exc_stack(emit_t *emit, uint label, bool is_finally) { +static void emit_native_push_exc_stack(emit_t *emit, uint label, bool is_finally) { if (emit->exc_stack_size + 1 > emit->exc_stack_alloc) { size_t new_alloc = emit->exc_stack_alloc + 4; emit->exc_stack = m_renew(exc_stack_entry_t, emit->exc_stack, emit->exc_stack_alloc, new_alloc); @@ -1072,7 +1072,7 @@ STATIC void emit_native_push_exc_stack(emit_t *emit, uint label, bool is_finally ASM_MOV_LOCAL_REG(emit->as, LOCAL_IDX_EXC_HANDLER_PC(emit), REG_RET); } -STATIC void emit_native_leave_exc_stack(emit_t *emit, bool start_of_handler) { +static void emit_native_leave_exc_stack(emit_t *emit, bool start_of_handler) { assert(emit->exc_stack_size > 0); // Get current exception handler and deactivate it @@ -1098,14 +1098,14 @@ STATIC void emit_native_leave_exc_stack(emit_t *emit, bool start_of_handler) { ASM_MOV_LOCAL_REG(emit->as, LOCAL_IDX_EXC_HANDLER_PC(emit), REG_RET); } -STATIC exc_stack_entry_t *emit_native_pop_exc_stack(emit_t *emit) { +static exc_stack_entry_t *emit_native_pop_exc_stack(emit_t *emit) { assert(emit->exc_stack_size > 0); exc_stack_entry_t *e = &emit->exc_stack[--emit->exc_stack_size]; assert(e->is_active == false); return e; } -STATIC void emit_load_reg_with_object(emit_t *emit, int reg, mp_obj_t obj) { +static void emit_load_reg_with_object(emit_t *emit, int reg, mp_obj_t obj) { emit->scope->scope_flags |= MP_SCOPE_FLAG_HASCONSTS; size_t table_off = mp_emit_common_use_const_obj(emit->emit_common, obj); emit_native_mov_reg_state(emit, REG_TEMP0, LOCAL_IDX_FUN_OBJ(emit)); @@ -1114,14 +1114,14 @@ STATIC void emit_load_reg_with_object(emit_t *emit, int reg, mp_obj_t obj) { ASM_LOAD_REG_REG_OFFSET(emit->as, reg, REG_TEMP0, table_off); } -STATIC void emit_load_reg_with_child(emit_t *emit, int reg, mp_raw_code_t *rc) { +static void emit_load_reg_with_child(emit_t *emit, int reg, mp_raw_code_t *rc) { size_t table_off = mp_emit_common_alloc_const_child(emit->emit_common, rc); emit_native_mov_reg_state(emit, REG_TEMP0, LOCAL_IDX_FUN_OBJ(emit)); ASM_LOAD_REG_REG_OFFSET(emit->as, REG_TEMP0, REG_TEMP0, OFFSETOF_OBJ_FUN_BC_CHILD_TABLE); ASM_LOAD_REG_REG_OFFSET(emit->as, reg, REG_TEMP0, table_off); } -STATIC void emit_native_label_assign(emit_t *emit, mp_uint_t l) { +static void emit_native_label_assign(emit_t *emit, mp_uint_t l) { DEBUG_printf("label_assign(" UINT_FMT ")\n", l); bool is_finally = false; @@ -1149,7 +1149,7 @@ STATIC void emit_native_label_assign(emit_t *emit, mp_uint_t l) { } } -STATIC void emit_native_global_exc_entry(emit_t *emit) { +static void emit_native_global_exc_entry(emit_t *emit) { // Note: 4 labels are reserved for this function, starting at *emit->label_slot emit->exit_label = *emit->label_slot; @@ -1251,7 +1251,7 @@ STATIC void emit_native_global_exc_entry(emit_t *emit) { } } -STATIC void emit_native_global_exc_exit(emit_t *emit) { +static void emit_native_global_exc_exit(emit_t *emit) { // Label for end of function emit_native_label_assign(emit, emit->exit_label); @@ -1286,7 +1286,7 @@ STATIC void emit_native_global_exc_exit(emit_t *emit) { ASM_EXIT(emit->as); } -STATIC void emit_native_import_name(emit_t *emit, qstr qst) { +static void emit_native_import_name(emit_t *emit, qstr qst) { DEBUG_printf("import_name %s\n", qstr_str(qst)); // get arguments from stack: arg2 = fromlist, arg3 = level @@ -1305,7 +1305,7 @@ STATIC void emit_native_import_name(emit_t *emit, qstr qst) { emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } -STATIC void emit_native_import_from(emit_t *emit, qstr qst) { +static void emit_native_import_from(emit_t *emit, qstr qst) { DEBUG_printf("import_from %s\n", qstr_str(qst)); emit_native_pre(emit); vtype_kind_t vtype_module; @@ -1315,7 +1315,7 @@ STATIC void emit_native_import_from(emit_t *emit, qstr qst) { emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } -STATIC void emit_native_import_star(emit_t *emit) { +static void emit_native_import_star(emit_t *emit) { DEBUG_printf("import_star\n"); vtype_kind_t vtype_module; emit_pre_pop_reg(emit, &vtype_module, REG_ARG_1); // arg1 = module @@ -1324,7 +1324,7 @@ STATIC void emit_native_import_star(emit_t *emit) { emit_post(emit); } -STATIC void emit_native_import(emit_t *emit, qstr qst, int kind) { +static void emit_native_import(emit_t *emit, qstr qst, int kind) { if (kind == MP_EMIT_IMPORT_NAME) { emit_native_import_name(emit, qst); } else if (kind == MP_EMIT_IMPORT_FROM) { @@ -1334,7 +1334,7 @@ STATIC void emit_native_import(emit_t *emit, qstr qst, int kind) { } } -STATIC void emit_native_load_const_tok(emit_t *emit, mp_token_kind_t tok) { +static void emit_native_load_const_tok(emit_t *emit, mp_token_kind_t tok) { DEBUG_printf("load_const_tok(tok=%u)\n", tok); if (tok == MP_TOKEN_ELLIPSIS) { emit_native_load_const_obj(emit, MP_OBJ_FROM_PTR(&mp_const_ellipsis_obj)); @@ -1348,13 +1348,13 @@ STATIC void emit_native_load_const_tok(emit_t *emit, mp_token_kind_t tok) { } } -STATIC void emit_native_load_const_small_int(emit_t *emit, mp_int_t arg) { +static void emit_native_load_const_small_int(emit_t *emit, mp_int_t arg) { DEBUG_printf("load_const_small_int(int=" INT_FMT ")\n", arg); emit_native_pre(emit); emit_post_push_imm(emit, VTYPE_INT, arg); } -STATIC void emit_native_load_const_str(emit_t *emit, qstr qst) { +static void emit_native_load_const_str(emit_t *emit, qstr qst) { emit_native_pre(emit); // TODO: Eventually we want to be able to work with raw pointers in viper to // do native array access. For now we just load them as any other object. @@ -1371,19 +1371,19 @@ STATIC void emit_native_load_const_str(emit_t *emit, qstr qst) { } } -STATIC void emit_native_load_const_obj(emit_t *emit, mp_obj_t obj) { +static void emit_native_load_const_obj(emit_t *emit, mp_obj_t obj) { emit_native_pre(emit); need_reg_single(emit, REG_RET, 0); emit_load_reg_with_object(emit, REG_RET, obj); emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } -STATIC void emit_native_load_null(emit_t *emit) { +static void emit_native_load_null(emit_t *emit) { emit_native_pre(emit); emit_post_push_imm(emit, VTYPE_PYOBJ, 0); } -STATIC void emit_native_load_fast(emit_t *emit, qstr qst, mp_uint_t local_num) { +static void emit_native_load_fast(emit_t *emit, qstr qst, mp_uint_t local_num) { DEBUG_printf("load_fast(%s, " UINT_FMT ")\n", qstr_str(qst), local_num); vtype_kind_t vtype = emit->local_vtype[local_num]; if (vtype == VTYPE_UNBOUND) { @@ -1399,7 +1399,7 @@ STATIC void emit_native_load_fast(emit_t *emit, qstr qst, mp_uint_t local_num) { } } -STATIC void emit_native_load_deref(emit_t *emit, qstr qst, mp_uint_t local_num) { +static void emit_native_load_deref(emit_t *emit, qstr qst, mp_uint_t local_num) { DEBUG_printf("load_deref(%s, " UINT_FMT ")\n", qstr_str(qst), local_num); need_reg_single(emit, REG_RET, 0); emit_native_load_fast(emit, qst, local_num); @@ -1411,7 +1411,7 @@ STATIC void emit_native_load_deref(emit_t *emit, qstr qst, mp_uint_t local_num) emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } -STATIC void emit_native_load_local(emit_t *emit, qstr qst, mp_uint_t local_num, int kind) { +static void emit_native_load_local(emit_t *emit, qstr qst, mp_uint_t local_num, int kind) { if (kind == MP_EMIT_IDOP_LOCAL_FAST) { emit_native_load_fast(emit, qst, local_num); } else { @@ -1419,7 +1419,7 @@ STATIC void emit_native_load_local(emit_t *emit, qstr qst, mp_uint_t local_num, } } -STATIC void emit_native_load_global(emit_t *emit, qstr qst, int kind) { +static void emit_native_load_global(emit_t *emit, qstr qst, int kind) { MP_STATIC_ASSERT(MP_F_LOAD_NAME + MP_EMIT_IDOP_GLOBAL_NAME == MP_F_LOAD_NAME); MP_STATIC_ASSERT(MP_F_LOAD_NAME + MP_EMIT_IDOP_GLOBAL_GLOBAL == MP_F_LOAD_GLOBAL); emit_native_pre(emit); @@ -1440,7 +1440,7 @@ STATIC void emit_native_load_global(emit_t *emit, qstr qst, int kind) { emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } -STATIC void emit_native_load_attr(emit_t *emit, qstr qst) { +static void emit_native_load_attr(emit_t *emit, qstr qst) { // depends on type of subject: // - integer, function, pointer to integers: error // - pointer to structure: get member, quite easy @@ -1452,7 +1452,7 @@ STATIC void emit_native_load_attr(emit_t *emit, qstr qst) { emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } -STATIC void emit_native_load_method(emit_t *emit, qstr qst, bool is_super) { +static void emit_native_load_method(emit_t *emit, qstr qst, bool is_super) { if (is_super) { emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, 3); // arg2 = dest ptr emit_get_stack_pointer_to_reg_for_push(emit, REG_ARG_2, 2); // arg2 = dest ptr @@ -1466,13 +1466,13 @@ STATIC void emit_native_load_method(emit_t *emit, qstr qst, bool is_super) { } } -STATIC void emit_native_load_build_class(emit_t *emit) { +static void emit_native_load_build_class(emit_t *emit) { emit_native_pre(emit); emit_call(emit, MP_F_LOAD_BUILD_CLASS); emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } -STATIC void emit_native_load_subscr(emit_t *emit) { +static void emit_native_load_subscr(emit_t *emit) { DEBUG_printf("load_subscr\n"); // need to compile: base[index] @@ -1612,7 +1612,7 @@ STATIC void emit_native_load_subscr(emit_t *emit) { } } -STATIC void emit_native_store_fast(emit_t *emit, qstr qst, mp_uint_t local_num) { +static void emit_native_store_fast(emit_t *emit, qstr qst, mp_uint_t local_num) { vtype_kind_t vtype; if (local_num < MAX_REGS_FOR_LOCAL_VARS && CAN_USE_REGS_FOR_LOCALS(emit)) { emit_pre_pop_reg(emit, &vtype, reg_local_table[local_num]); @@ -1634,7 +1634,7 @@ STATIC void emit_native_store_fast(emit_t *emit, qstr qst, mp_uint_t local_num) } } -STATIC void emit_native_store_deref(emit_t *emit, qstr qst, mp_uint_t local_num) { +static void emit_native_store_deref(emit_t *emit, qstr qst, mp_uint_t local_num) { DEBUG_printf("store_deref(%s, " UINT_FMT ")\n", qstr_str(qst), local_num); need_reg_single(emit, REG_TEMP0, 0); need_reg_single(emit, REG_TEMP1, 0); @@ -1648,7 +1648,7 @@ STATIC void emit_native_store_deref(emit_t *emit, qstr qst, mp_uint_t local_num) emit_post(emit); } -STATIC void emit_native_store_local(emit_t *emit, qstr qst, mp_uint_t local_num, int kind) { +static void emit_native_store_local(emit_t *emit, qstr qst, mp_uint_t local_num, int kind) { if (kind == MP_EMIT_IDOP_LOCAL_FAST) { emit_native_store_fast(emit, qst, local_num); } else { @@ -1656,7 +1656,7 @@ STATIC void emit_native_store_local(emit_t *emit, qstr qst, mp_uint_t local_num, } } -STATIC void emit_native_store_global(emit_t *emit, qstr qst, int kind) { +static void emit_native_store_global(emit_t *emit, qstr qst, int kind) { MP_STATIC_ASSERT(MP_F_STORE_NAME + MP_EMIT_IDOP_GLOBAL_NAME == MP_F_STORE_NAME); MP_STATIC_ASSERT(MP_F_STORE_NAME + MP_EMIT_IDOP_GLOBAL_GLOBAL == MP_F_STORE_GLOBAL); if (kind == MP_EMIT_IDOP_GLOBAL_NAME) { @@ -1678,7 +1678,7 @@ STATIC void emit_native_store_global(emit_t *emit, qstr qst, int kind) { emit_post(emit); } -STATIC void emit_native_store_attr(emit_t *emit, qstr qst) { +static void emit_native_store_attr(emit_t *emit, qstr qst) { vtype_kind_t vtype_base; vtype_kind_t vtype_val = peek_vtype(emit, 1); if (vtype_val == VTYPE_PYOBJ) { @@ -1695,7 +1695,7 @@ STATIC void emit_native_store_attr(emit_t *emit, qstr qst) { emit_post(emit); } -STATIC void emit_native_store_subscr(emit_t *emit) { +static void emit_native_store_subscr(emit_t *emit) { DEBUG_printf("store_subscr\n"); // need to compile: base[index] = value @@ -1872,7 +1872,7 @@ STATIC void emit_native_store_subscr(emit_t *emit) { } } -STATIC void emit_native_delete_local(emit_t *emit, qstr qst, mp_uint_t local_num, int kind) { +static void emit_native_delete_local(emit_t *emit, qstr qst, mp_uint_t local_num, int kind) { if (kind == MP_EMIT_IDOP_LOCAL_FAST) { // TODO: This is not compliant implementation. We could use MP_OBJ_SENTINEL // to mark deleted vars but then every var would need to be checked on @@ -1884,7 +1884,7 @@ STATIC void emit_native_delete_local(emit_t *emit, qstr qst, mp_uint_t local_num } } -STATIC void emit_native_delete_global(emit_t *emit, qstr qst, int kind) { +static void emit_native_delete_global(emit_t *emit, qstr qst, int kind) { MP_STATIC_ASSERT(MP_F_DELETE_NAME + MP_EMIT_IDOP_GLOBAL_NAME == MP_F_DELETE_NAME); MP_STATIC_ASSERT(MP_F_DELETE_NAME + MP_EMIT_IDOP_GLOBAL_GLOBAL == MP_F_DELETE_GLOBAL); emit_native_pre(emit); @@ -1892,7 +1892,7 @@ STATIC void emit_native_delete_global(emit_t *emit, qstr qst, int kind) { emit_post(emit); } -STATIC void emit_native_delete_attr(emit_t *emit, qstr qst) { +static void emit_native_delete_attr(emit_t *emit, qstr qst) { vtype_kind_t vtype_base; emit_pre_pop_reg(emit, &vtype_base, REG_ARG_1); // arg1 = base assert(vtype_base == VTYPE_PYOBJ); @@ -1901,7 +1901,7 @@ STATIC void emit_native_delete_attr(emit_t *emit, qstr qst) { emit_post(emit); } -STATIC void emit_native_delete_subscr(emit_t *emit) { +static void emit_native_delete_subscr(emit_t *emit) { vtype_kind_t vtype_index, vtype_base; emit_pre_pop_reg_reg(emit, &vtype_index, REG_ARG_2, &vtype_base, REG_ARG_1); // index, base assert(vtype_index == VTYPE_PYOBJ); @@ -1909,7 +1909,7 @@ STATIC void emit_native_delete_subscr(emit_t *emit) { emit_call_with_imm_arg(emit, MP_F_OBJ_SUBSCR, (mp_uint_t)MP_OBJ_NULL, REG_ARG_3); } -STATIC void emit_native_subscr(emit_t *emit, int kind) { +static void emit_native_subscr(emit_t *emit, int kind) { if (kind == MP_EMIT_SUBSCR_LOAD) { emit_native_load_subscr(emit); } else if (kind == MP_EMIT_SUBSCR_STORE) { @@ -1919,7 +1919,7 @@ STATIC void emit_native_subscr(emit_t *emit, int kind) { } } -STATIC void emit_native_attr(emit_t *emit, qstr qst, int kind) { +static void emit_native_attr(emit_t *emit, qstr qst, int kind) { if (kind == MP_EMIT_ATTR_LOAD) { emit_native_load_attr(emit, qst); } else if (kind == MP_EMIT_ATTR_STORE) { @@ -1929,7 +1929,7 @@ STATIC void emit_native_attr(emit_t *emit, qstr qst, int kind) { } } -STATIC void emit_native_dup_top(emit_t *emit) { +static void emit_native_dup_top(emit_t *emit) { DEBUG_printf("dup_top\n"); vtype_kind_t vtype; int reg = REG_TEMP0; @@ -1937,33 +1937,33 @@ STATIC void emit_native_dup_top(emit_t *emit) { emit_post_push_reg_reg(emit, vtype, reg, vtype, reg); } -STATIC void emit_native_dup_top_two(emit_t *emit) { +static void emit_native_dup_top_two(emit_t *emit) { vtype_kind_t vtype0, vtype1; emit_pre_pop_reg_reg(emit, &vtype0, REG_TEMP0, &vtype1, REG_TEMP1); emit_post_push_reg_reg_reg_reg(emit, vtype1, REG_TEMP1, vtype0, REG_TEMP0, vtype1, REG_TEMP1, vtype0, REG_TEMP0); } -STATIC void emit_native_pop_top(emit_t *emit) { +static void emit_native_pop_top(emit_t *emit) { DEBUG_printf("pop_top\n"); emit_pre_pop_discard(emit); emit_post(emit); } -STATIC void emit_native_rot_two(emit_t *emit) { +static void emit_native_rot_two(emit_t *emit) { DEBUG_printf("rot_two\n"); vtype_kind_t vtype0, vtype1; emit_pre_pop_reg_reg(emit, &vtype0, REG_TEMP0, &vtype1, REG_TEMP1); emit_post_push_reg_reg(emit, vtype0, REG_TEMP0, vtype1, REG_TEMP1); } -STATIC void emit_native_rot_three(emit_t *emit) { +static void emit_native_rot_three(emit_t *emit) { DEBUG_printf("rot_three\n"); vtype_kind_t vtype0, vtype1, vtype2; emit_pre_pop_reg_reg_reg(emit, &vtype0, REG_TEMP0, &vtype1, REG_TEMP1, &vtype2, REG_TEMP2); emit_post_push_reg_reg_reg(emit, vtype0, REG_TEMP0, vtype2, REG_TEMP2, vtype1, REG_TEMP1); } -STATIC void emit_native_jump(emit_t *emit, mp_uint_t label) { +static void emit_native_jump(emit_t *emit, mp_uint_t label) { DEBUG_printf("jump(label=" UINT_FMT ")\n", label); emit_native_pre(emit); // need to commit stack because we are jumping elsewhere @@ -1973,7 +1973,7 @@ STATIC void emit_native_jump(emit_t *emit, mp_uint_t label) { mp_asm_base_suppress_code(&emit->as->base); } -STATIC void emit_native_jump_helper(emit_t *emit, bool cond, mp_uint_t label, bool pop) { +static void emit_native_jump_helper(emit_t *emit, bool cond, mp_uint_t label, bool pop) { vtype_kind_t vtype = peek_vtype(emit, 0); if (vtype == VTYPE_PYOBJ) { emit_pre_pop_reg(emit, &vtype, REG_ARG_1); @@ -2010,17 +2010,17 @@ STATIC void emit_native_jump_helper(emit_t *emit, bool cond, mp_uint_t label, bo emit_post(emit); } -STATIC void emit_native_pop_jump_if(emit_t *emit, bool cond, mp_uint_t label) { +static void emit_native_pop_jump_if(emit_t *emit, bool cond, mp_uint_t label) { DEBUG_printf("pop_jump_if(cond=%u, label=" UINT_FMT ")\n", cond, label); emit_native_jump_helper(emit, cond, label, true); } -STATIC void emit_native_jump_if_or_pop(emit_t *emit, bool cond, mp_uint_t label) { +static void emit_native_jump_if_or_pop(emit_t *emit, bool cond, mp_uint_t label) { DEBUG_printf("jump_if_or_pop(cond=%u, label=" UINT_FMT ")\n", cond, label); emit_native_jump_helper(emit, cond, label, false); } -STATIC void emit_native_unwind_jump(emit_t *emit, mp_uint_t label, mp_uint_t except_depth) { +static void emit_native_unwind_jump(emit_t *emit, mp_uint_t label, mp_uint_t except_depth) { if (except_depth > 0) { exc_stack_entry_t *first_finally = NULL; exc_stack_entry_t *prev_finally = NULL; @@ -2063,7 +2063,7 @@ STATIC void emit_native_unwind_jump(emit_t *emit, mp_uint_t label, mp_uint_t exc emit_native_jump(emit, label & ~MP_EMIT_BREAK_FROM_FOR); } -STATIC void emit_native_setup_with(emit_t *emit, mp_uint_t label) { +static void emit_native_setup_with(emit_t *emit, mp_uint_t label) { // the context manager is on the top of the stack // stack: (..., ctx_mgr) @@ -2102,7 +2102,7 @@ STATIC void emit_native_setup_with(emit_t *emit, mp_uint_t label) { // stack: (..., __exit__, self, as_value, as_value) } -STATIC void emit_native_setup_block(emit_t *emit, mp_uint_t label, int kind) { +static void emit_native_setup_block(emit_t *emit, mp_uint_t label, int kind) { if (kind == MP_EMIT_SETUP_BLOCK_WITH) { emit_native_setup_with(emit, label); } else { @@ -2114,7 +2114,7 @@ STATIC void emit_native_setup_block(emit_t *emit, mp_uint_t label, int kind) { } } -STATIC void emit_native_with_cleanup(emit_t *emit, mp_uint_t label) { +static void emit_native_with_cleanup(emit_t *emit, mp_uint_t label) { // Note: 3 labels are reserved for this function, starting at *emit->label_slot // stack: (..., __exit__, self, as_value) @@ -2181,7 +2181,7 @@ STATIC void emit_native_with_cleanup(emit_t *emit, mp_uint_t label) { // Exception is in nlr_buf.ret_val slot } -STATIC void emit_native_end_finally(emit_t *emit) { +static void emit_native_end_finally(emit_t *emit) { // logic: // exc = pop_stack // if exc == None: pass @@ -2207,7 +2207,7 @@ STATIC void emit_native_end_finally(emit_t *emit) { emit_post(emit); } -STATIC void emit_native_get_iter(emit_t *emit, bool use_stack) { +static void emit_native_get_iter(emit_t *emit, bool use_stack) { // perhaps the difficult one, as we want to rewrite for loops using native code // in cases where we iterate over a Python object, can we use normal runtime calls? @@ -2225,7 +2225,7 @@ STATIC void emit_native_get_iter(emit_t *emit, bool use_stack) { } } -STATIC void emit_native_for_iter(emit_t *emit, mp_uint_t label) { +static void emit_native_for_iter(emit_t *emit, mp_uint_t label) { emit_native_pre(emit); emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_1, MP_OBJ_ITER_BUF_NSLOTS); adjust_stack(emit, MP_OBJ_ITER_BUF_NSLOTS); @@ -2240,14 +2240,14 @@ STATIC void emit_native_for_iter(emit_t *emit, mp_uint_t label) { emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } -STATIC void emit_native_for_iter_end(emit_t *emit) { +static void emit_native_for_iter_end(emit_t *emit) { // adjust stack counter (we get here from for_iter ending, which popped the value for us) emit_native_pre(emit); adjust_stack(emit, -MP_OBJ_ITER_BUF_NSLOTS); emit_post(emit); } -STATIC void emit_native_pop_except_jump(emit_t *emit, mp_uint_t label, bool within_exc_handler) { +static void emit_native_pop_except_jump(emit_t *emit, mp_uint_t label, bool within_exc_handler) { if (within_exc_handler) { // Cancel any active exception so subsequent handlers don't see it ASM_MOV_REG_IMM(emit->as, REG_TEMP0, (mp_uint_t)MP_OBJ_NULL); @@ -2258,7 +2258,7 @@ STATIC void emit_native_pop_except_jump(emit_t *emit, mp_uint_t label, bool with emit_native_jump(emit, label); } -STATIC void emit_native_unary_op(emit_t *emit, mp_unary_op_t op) { +static void emit_native_unary_op(emit_t *emit, mp_unary_op_t op) { vtype_kind_t vtype; emit_pre_pop_reg(emit, &vtype, REG_ARG_2); if (vtype == VTYPE_PYOBJ) { @@ -2271,7 +2271,7 @@ STATIC void emit_native_unary_op(emit_t *emit, mp_unary_op_t op) { } } -STATIC void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) { +static void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) { DEBUG_printf("binary_op(" UINT_FMT ")\n", op); vtype_kind_t vtype_lhs = peek_vtype(emit, 1); vtype_kind_t vtype_rhs = peek_vtype(emit, 0); @@ -2534,10 +2534,10 @@ STATIC void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) { } #if MICROPY_PY_BUILTINS_SLICE -STATIC void emit_native_build_slice(emit_t *emit, mp_uint_t n_args); +static void emit_native_build_slice(emit_t *emit, mp_uint_t n_args); #endif -STATIC void emit_native_build(emit_t *emit, mp_uint_t n_args, int kind) { +static void emit_native_build(emit_t *emit, mp_uint_t n_args, int kind) { // for viper: call runtime, with types of args // if wrapped in byte_array, or something, allocates memory and fills it MP_STATIC_ASSERT(MP_F_BUILD_TUPLE + MP_EMIT_BUILD_TUPLE == MP_F_BUILD_TUPLE); @@ -2558,7 +2558,7 @@ STATIC void emit_native_build(emit_t *emit, mp_uint_t n_args, int kind) { emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new tuple/list/map/set } -STATIC void emit_native_store_map(emit_t *emit) { +static void emit_native_store_map(emit_t *emit) { vtype_kind_t vtype_key, vtype_value, vtype_map; emit_pre_pop_reg_reg_reg(emit, &vtype_key, REG_ARG_2, &vtype_value, REG_ARG_3, &vtype_map, REG_ARG_1); // key, value, map assert(vtype_key == VTYPE_PYOBJ); @@ -2569,7 +2569,7 @@ STATIC void emit_native_store_map(emit_t *emit) { } #if MICROPY_PY_BUILTINS_SLICE -STATIC void emit_native_build_slice(emit_t *emit, mp_uint_t n_args) { +static void emit_native_build_slice(emit_t *emit, mp_uint_t n_args) { DEBUG_printf("build_slice %d\n", n_args); if (n_args == 2) { vtype_kind_t vtype_start, vtype_stop; @@ -2590,7 +2590,7 @@ STATIC void emit_native_build_slice(emit_t *emit, mp_uint_t n_args) { } #endif -STATIC void emit_native_store_comp(emit_t *emit, scope_kind_t kind, mp_uint_t collection_index) { +static void emit_native_store_comp(emit_t *emit, scope_kind_t kind, mp_uint_t collection_index) { mp_fun_kind_t f; if (kind == SCOPE_LIST_COMP) { vtype_kind_t vtype_item; @@ -2619,7 +2619,7 @@ STATIC void emit_native_store_comp(emit_t *emit, scope_kind_t kind, mp_uint_t co emit_post(emit); } -STATIC void emit_native_unpack_sequence(emit_t *emit, mp_uint_t n_args) { +static void emit_native_unpack_sequence(emit_t *emit, mp_uint_t n_args) { DEBUG_printf("unpack_sequence %d\n", n_args); vtype_kind_t vtype_base; emit_pre_pop_reg(emit, &vtype_base, REG_ARG_1); // arg1 = seq @@ -2628,7 +2628,7 @@ STATIC void emit_native_unpack_sequence(emit_t *emit, mp_uint_t n_args) { emit_call_with_imm_arg(emit, MP_F_UNPACK_SEQUENCE, n_args, REG_ARG_2); // arg2 = n_args } -STATIC void emit_native_unpack_ex(emit_t *emit, mp_uint_t n_left, mp_uint_t n_right) { +static void emit_native_unpack_ex(emit_t *emit, mp_uint_t n_left, mp_uint_t n_right) { DEBUG_printf("unpack_ex %d %d\n", n_left, n_right); vtype_kind_t vtype_base; emit_pre_pop_reg(emit, &vtype_base, REG_ARG_1); // arg1 = seq @@ -2637,7 +2637,7 @@ STATIC void emit_native_unpack_ex(emit_t *emit, mp_uint_t n_left, mp_uint_t n_ri emit_call_with_imm_arg(emit, MP_F_UNPACK_EX, n_left | (n_right << 8), REG_ARG_2); // arg2 = n_left + n_right } -STATIC void emit_native_make_function(emit_t *emit, scope_t *scope, mp_uint_t n_pos_defaults, mp_uint_t n_kw_defaults) { +static void emit_native_make_function(emit_t *emit, scope_t *scope, mp_uint_t n_pos_defaults, mp_uint_t n_kw_defaults) { // call runtime, with type info for args, or don't support dict/default params, or only support Python objects for them emit_native_pre(emit); emit_native_mov_reg_state(emit, REG_ARG_2, LOCAL_IDX_FUN_OBJ(emit)); @@ -2654,7 +2654,7 @@ STATIC void emit_native_make_function(emit_t *emit, scope_t *scope, mp_uint_t n_ emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } -STATIC void emit_native_make_closure(emit_t *emit, scope_t *scope, mp_uint_t n_closed_over, mp_uint_t n_pos_defaults, mp_uint_t n_kw_defaults) { +static void emit_native_make_closure(emit_t *emit, scope_t *scope, mp_uint_t n_closed_over, mp_uint_t n_pos_defaults, mp_uint_t n_kw_defaults) { // make function emit_native_pre(emit); emit_native_mov_reg_state(emit, REG_ARG_2, LOCAL_IDX_FUN_OBJ(emit)); @@ -2683,7 +2683,7 @@ STATIC void emit_native_make_closure(emit_t *emit, scope_t *scope, mp_uint_t n_c emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } -STATIC void emit_native_call_function(emit_t *emit, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags) { +static void emit_native_call_function(emit_t *emit, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags) { DEBUG_printf("call_function(n_pos=" UINT_FMT ", n_kw=" UINT_FMT ", star_flags=" UINT_FMT ")\n", n_positional, n_keyword, star_flags); // TODO: in viper mode, call special runtime routine with type info for args, @@ -2738,7 +2738,7 @@ STATIC void emit_native_call_function(emit_t *emit, mp_uint_t n_positional, mp_u } } -STATIC void emit_native_call_method(emit_t *emit, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags) { +static void emit_native_call_method(emit_t *emit, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags) { if (star_flags) { emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_3, n_positional + 2 * n_keyword + 3); // pointer to args emit_call_with_2_imm_args(emit, MP_F_CALL_METHOD_N_KW_VAR, 1, REG_ARG_1, n_positional | (n_keyword << 8), REG_ARG_2); @@ -2751,7 +2751,7 @@ STATIC void emit_native_call_method(emit_t *emit, mp_uint_t n_positional, mp_uin } } -STATIC void emit_native_return_value(emit_t *emit) { +static void emit_native_return_value(emit_t *emit) { DEBUG_printf("return_value\n"); if (emit->scope->scope_flags & MP_SCOPE_FLAG_GENERATOR) { @@ -2804,7 +2804,7 @@ STATIC void emit_native_return_value(emit_t *emit) { emit_native_unwind_jump(emit, emit->exit_label, emit->exc_stack_size); } -STATIC void emit_native_raise_varargs(emit_t *emit, mp_uint_t n_args) { +static void emit_native_raise_varargs(emit_t *emit, mp_uint_t n_args) { (void)n_args; assert(n_args == 1); vtype_kind_t vtype_exc; @@ -2817,7 +2817,7 @@ STATIC void emit_native_raise_varargs(emit_t *emit, mp_uint_t n_args) { mp_asm_base_suppress_code(&emit->as->base); } -STATIC void emit_native_yield(emit_t *emit, int kind) { +static void emit_native_yield(emit_t *emit, int kind) { // Note: 1 (yield) or 3 (yield from) labels are reserved for this function, starting at *emit->label_slot if (emit->do_viper_types) { @@ -2900,7 +2900,7 @@ STATIC void emit_native_yield(emit_t *emit, int kind) { } } -STATIC void emit_native_start_except_handler(emit_t *emit) { +static void emit_native_start_except_handler(emit_t *emit) { // Protected block has finished so leave the current exception handler emit_native_leave_exc_stack(emit, true); @@ -2909,7 +2909,7 @@ STATIC void emit_native_start_except_handler(emit_t *emit) { emit_post_push_reg(emit, VTYPE_PYOBJ, REG_TEMP0); } -STATIC void emit_native_end_except_handler(emit_t *emit) { +static void emit_native_end_except_handler(emit_t *emit) { adjust_stack(emit, -1); // pop the exception (end_finally didn't use it) } diff --git a/py/emitnx86.c b/py/emitnx86.c index cb2b7f19eac73..1d2aefa7920bc 100644 --- a/py/emitnx86.c +++ b/py/emitnx86.c @@ -13,7 +13,7 @@ #define NLR_BUF_IDX_LOCAL_1 (5) // ebx // x86 needs a table to know how many args a given function has -STATIC byte mp_f_n_args[MP_F_NUMBER_OF] = { +static byte mp_f_n_args[MP_F_NUMBER_OF] = { [MP_F_CONVERT_OBJ_TO_NATIVE] = 2, [MP_F_CONVERT_NATIVE_TO_OBJ] = 2, [MP_F_NATIVE_SWAP_GLOBALS] = 1, diff --git a/py/gc.c b/py/gc.c index b6969dfd42429..8a03ce5264e89 100644 --- a/py/gc.c +++ b/py/gc.c @@ -121,7 +121,7 @@ #endif // TODO waste less memory; currently requires that all entries in alloc_table have a corresponding block in pool -STATIC void gc_setup_area(mp_state_mem_area_t *area, void *start, void *end) { +static void gc_setup_area(mp_state_mem_area_t *area, void *start, void *end) { // calculate parameters for GC (T=total, A=alloc table, F=finaliser table, P=pool; all in bytes): // T = A + F + P // F = A * BLOCKS_PER_ATB / BLOCKS_PER_FTB @@ -239,7 +239,7 @@ void gc_add(void *start, void *end) { #if MICROPY_GC_SPLIT_HEAP_AUTO // Try to automatically add a heap area large enough to fulfill 'failed_alloc'. -STATIC bool gc_try_add_heap(size_t failed_alloc) { +static bool gc_try_add_heap(size_t failed_alloc) { // 'needed' is the size of a heap large enough to hold failed_alloc, with // the additional metadata overheads as calculated in gc_setup_area(). // @@ -349,7 +349,7 @@ bool gc_is_locked(void) { #if MICROPY_GC_SPLIT_HEAP // Returns the area to which this pointer belongs, or NULL if it isn't // allocated on the GC-managed heap. -STATIC inline mp_state_mem_area_t *gc_get_ptr_area(const void *ptr) { +static inline mp_state_mem_area_t *gc_get_ptr_area(const void *ptr) { if (((uintptr_t)(ptr) & (BYTES_PER_BLOCK - 1)) != 0) { // must be aligned on a block return NULL; } @@ -383,9 +383,9 @@ STATIC inline mp_state_mem_area_t *gc_get_ptr_area(const void *ptr) { // blocks on the stack. When all children have been checked, pop off the // topmost block on the stack and repeat with that one. #if MICROPY_GC_SPLIT_HEAP -STATIC void gc_mark_subtree(mp_state_mem_area_t *area, size_t block) +static void gc_mark_subtree(mp_state_mem_area_t *area, size_t block) #else -STATIC void gc_mark_subtree(size_t block) +static void gc_mark_subtree(size_t block) #endif { // Start with the block passed in the argument. @@ -456,7 +456,7 @@ STATIC void gc_mark_subtree(size_t block) } } -STATIC void gc_deal_with_stack_overflow(void) { +static void gc_deal_with_stack_overflow(void) { while (MP_STATE_MEM(gc_stack_overflow)) { MP_STATE_MEM(gc_stack_overflow) = 0; @@ -477,7 +477,7 @@ STATIC void gc_deal_with_stack_overflow(void) { } } -STATIC void gc_sweep(void) { +static void gc_sweep(void) { #if MICROPY_PY_GC_COLLECT_RETVAL MP_STATE_MEM(gc_collected) = 0; #endif diff --git a/py/lexer.c b/py/lexer.c index 5e911a1a23337..bff8e637656d6 100644 --- a/py/lexer.c +++ b/py/lexer.c @@ -42,74 +42,74 @@ #define MP_LEXER_EOF ((unichar)MP_READER_EOF) #define CUR_CHAR(lex) ((lex)->chr0) -STATIC bool is_end(mp_lexer_t *lex) { +static bool is_end(mp_lexer_t *lex) { return lex->chr0 == MP_LEXER_EOF; } -STATIC bool is_physical_newline(mp_lexer_t *lex) { +static bool is_physical_newline(mp_lexer_t *lex) { return lex->chr0 == '\n'; } -STATIC bool is_char(mp_lexer_t *lex, byte c) { +static bool is_char(mp_lexer_t *lex, byte c) { return lex->chr0 == c; } -STATIC bool is_char_or(mp_lexer_t *lex, byte c1, byte c2) { +static bool is_char_or(mp_lexer_t *lex, byte c1, byte c2) { return lex->chr0 == c1 || lex->chr0 == c2; } -STATIC bool is_char_or3(mp_lexer_t *lex, byte c1, byte c2, byte c3) { +static bool is_char_or3(mp_lexer_t *lex, byte c1, byte c2, byte c3) { return lex->chr0 == c1 || lex->chr0 == c2 || lex->chr0 == c3; } #if MICROPY_PY_FSTRINGS -STATIC bool is_char_or4(mp_lexer_t *lex, byte c1, byte c2, byte c3, byte c4) { +static bool is_char_or4(mp_lexer_t *lex, byte c1, byte c2, byte c3, byte c4) { return lex->chr0 == c1 || lex->chr0 == c2 || lex->chr0 == c3 || lex->chr0 == c4; } #endif -STATIC bool is_char_following(mp_lexer_t *lex, byte c) { +static bool is_char_following(mp_lexer_t *lex, byte c) { return lex->chr1 == c; } -STATIC bool is_char_following_or(mp_lexer_t *lex, byte c1, byte c2) { +static bool is_char_following_or(mp_lexer_t *lex, byte c1, byte c2) { return lex->chr1 == c1 || lex->chr1 == c2; } -STATIC bool is_char_following_following_or(mp_lexer_t *lex, byte c1, byte c2) { +static bool is_char_following_following_or(mp_lexer_t *lex, byte c1, byte c2) { return lex->chr2 == c1 || lex->chr2 == c2; } -STATIC bool is_char_and(mp_lexer_t *lex, byte c1, byte c2) { +static bool is_char_and(mp_lexer_t *lex, byte c1, byte c2) { return lex->chr0 == c1 && lex->chr1 == c2; } -STATIC bool is_whitespace(mp_lexer_t *lex) { +static bool is_whitespace(mp_lexer_t *lex) { return unichar_isspace(lex->chr0); } -STATIC bool is_letter(mp_lexer_t *lex) { +static bool is_letter(mp_lexer_t *lex) { return unichar_isalpha(lex->chr0); } -STATIC bool is_digit(mp_lexer_t *lex) { +static bool is_digit(mp_lexer_t *lex) { return unichar_isdigit(lex->chr0); } -STATIC bool is_following_digit(mp_lexer_t *lex) { +static bool is_following_digit(mp_lexer_t *lex) { return unichar_isdigit(lex->chr1); } -STATIC bool is_following_base_char(mp_lexer_t *lex) { +static bool is_following_base_char(mp_lexer_t *lex) { const unichar chr1 = lex->chr1 | 0x20; return chr1 == 'b' || chr1 == 'o' || chr1 == 'x'; } -STATIC bool is_following_odigit(mp_lexer_t *lex) { +static bool is_following_odigit(mp_lexer_t *lex) { return lex->chr1 >= '0' && lex->chr1 <= '7'; } -STATIC bool is_string_or_bytes(mp_lexer_t *lex) { +static bool is_string_or_bytes(mp_lexer_t *lex) { return is_char_or(lex, '\'', '\"') #if MICROPY_PY_FSTRINGS || (is_char_or4(lex, 'r', 'u', 'b', 'f') && is_char_following_or(lex, '\'', '\"')) @@ -123,15 +123,15 @@ STATIC bool is_string_or_bytes(mp_lexer_t *lex) { } // to easily parse utf-8 identifiers we allow any raw byte with high bit set -STATIC bool is_head_of_identifier(mp_lexer_t *lex) { +static bool is_head_of_identifier(mp_lexer_t *lex) { return is_letter(lex) || lex->chr0 == '_' || lex->chr0 >= 0x80; } -STATIC bool is_tail_of_identifier(mp_lexer_t *lex) { +static bool is_tail_of_identifier(mp_lexer_t *lex) { return is_head_of_identifier(lex) || is_digit(lex); } -STATIC void next_char(mp_lexer_t *lex) { +static void next_char(mp_lexer_t *lex) { if (lex->chr0 == '\n') { // a new line ++lex->line; @@ -189,7 +189,7 @@ STATIC void next_char(mp_lexer_t *lex) { } } -STATIC void indent_push(mp_lexer_t *lex, size_t indent) { +static void indent_push(mp_lexer_t *lex, size_t indent) { if (lex->num_indent_level >= lex->alloc_indent_level) { lex->indent_level = m_renew(uint16_t, lex->indent_level, lex->alloc_indent_level, lex->alloc_indent_level + MICROPY_ALLOC_LEXEL_INDENT_INC); lex->alloc_indent_level += MICROPY_ALLOC_LEXEL_INDENT_INC; @@ -197,11 +197,11 @@ STATIC void indent_push(mp_lexer_t *lex, size_t indent) { lex->indent_level[lex->num_indent_level++] = indent; } -STATIC size_t indent_top(mp_lexer_t *lex) { +static size_t indent_top(mp_lexer_t *lex) { return lex->indent_level[lex->num_indent_level - 1]; } -STATIC void indent_pop(mp_lexer_t *lex) { +static void indent_pop(mp_lexer_t *lex) { lex->num_indent_level -= 1; } @@ -211,7 +211,7 @@ STATIC void indent_pop(mp_lexer_t *lex) { // c = continue with , if this opchar matches then continue matching // this means if the start of two ops are the same then they are equal til the last char -STATIC const char *const tok_enc = +static const char *const tok_enc = "()[]{},;~" // singles ":e=" // : := "nested_bracket_level == 0) { diff --git a/py/malloc.c b/py/malloc.c index ddf139e386053..f557ade44f500 100644 --- a/py/malloc.c +++ b/py/malloc.c @@ -69,7 +69,7 @@ #error MICROPY_ENABLE_FINALISER requires MICROPY_ENABLE_GC #endif -STATIC void *realloc_ext(void *ptr, size_t n_bytes, bool allow_move) { +static void *realloc_ext(void *ptr, size_t n_bytes, bool allow_move) { if (allow_move) { return realloc(ptr, n_bytes); } else { @@ -221,7 +221,7 @@ typedef struct _m_tracked_node_t { } m_tracked_node_t; #if MICROPY_DEBUG_VERBOSE -STATIC size_t m_tracked_count_links(size_t *nb) { +static size_t m_tracked_count_links(size_t *nb) { m_tracked_node_t *node = MP_STATE_VM(m_tracked_head); size_t n = 0; *nb = 0; diff --git a/py/map.c b/py/map.c index c18df5a9f333c..d40e3dc4d02d7 100644 --- a/py/map.c +++ b/py/map.c @@ -65,14 +65,14 @@ // The first set of sizes are chosen so the allocation fits exactly in a // 4-word GC block, and it's not so important for these small values to be // prime. The latter sizes are prime and increase at an increasing rate. -STATIC const uint16_t hash_allocation_sizes[] = { +static const uint16_t hash_allocation_sizes[] = { 0, 2, 4, 6, 8, 10, 12, // +2 17, 23, 29, 37, 47, 59, 73, // *1.25 97, 127, 167, 223, 293, 389, 521, 691, 919, 1223, 1627, 2161, // *1.33 3229, 4831, 7243, 10861, 16273, 24407, 36607, 54907, // *1.5 }; -STATIC size_t get_hash_alloc_greater_or_equal_to(size_t x) { +static size_t get_hash_alloc_greater_or_equal_to(size_t x) { for (size_t i = 0; i < MP_ARRAY_SIZE(hash_allocation_sizes); i++) { if (hash_allocation_sizes[i] >= x) { return hash_allocation_sizes[i]; @@ -128,7 +128,7 @@ void mp_map_clear(mp_map_t *map) { map->table = NULL; } -STATIC void mp_map_rehash(mp_map_t *map) { +static void mp_map_rehash(mp_map_t *map) { size_t old_alloc = map->alloc; size_t new_alloc = get_hash_alloc_greater_or_equal_to(map->alloc + 1); DEBUG_printf("mp_map_rehash(%p): " UINT_FMT " -> " UINT_FMT "\n", map, old_alloc, new_alloc); @@ -332,7 +332,7 @@ void mp_set_init(mp_set_t *set, size_t n) { set->table = m_new0(mp_obj_t, set->alloc); } -STATIC void mp_set_rehash(mp_set_t *set) { +static void mp_set_rehash(mp_set_t *set) { size_t old_alloc = set->alloc; mp_obj_t *old_table = set->table; set->alloc = get_hash_alloc_greater_or_equal_to(set->alloc + 1); diff --git a/py/modarray.c b/py/modarray.c index ac2e56ed38b40..116c844e8eb1c 100644 --- a/py/modarray.c +++ b/py/modarray.c @@ -28,12 +28,12 @@ #if MICROPY_PY_ARRAY -STATIC const mp_rom_map_elem_t mp_module_array_globals_table[] = { +static const mp_rom_map_elem_t mp_module_array_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_array) }, { MP_ROM_QSTR(MP_QSTR_array), MP_ROM_PTR(&mp_type_array) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_array_globals, mp_module_array_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_array_globals, mp_module_array_globals_table); const mp_obj_module_t mp_module_array = { .base = { &mp_type_module }, diff --git a/py/modbuiltins.c b/py/modbuiltins.c index 4ff7d445097df..51cf3137bfddb 100644 --- a/py/modbuiltins.c +++ b/py/modbuiltins.c @@ -46,7 +46,7 @@ extern struct _mp_dummy_t mp_sys_stdout_obj; // type is irrelevant, just need po // args[0] is function from class body // args[1] is class name // args[2:] are base objects -STATIC mp_obj_t mp_builtin___build_class__(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_builtin___build_class__(size_t n_args, const mp_obj_t *args) { assert(2 <= n_args); // set the new classes __locals__ object @@ -88,12 +88,12 @@ STATIC mp_obj_t mp_builtin___build_class__(size_t n_args, const mp_obj_t *args) } MP_DEFINE_CONST_FUN_OBJ_VAR(mp_builtin___build_class___obj, 2, mp_builtin___build_class__); -STATIC mp_obj_t mp_builtin_abs(mp_obj_t o_in) { +static mp_obj_t mp_builtin_abs(mp_obj_t o_in) { return mp_unary_op(MP_UNARY_OP_ABS, o_in); } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_abs_obj, mp_builtin_abs); -STATIC mp_obj_t mp_builtin_all(mp_obj_t o_in) { +static mp_obj_t mp_builtin_all(mp_obj_t o_in) { mp_obj_iter_buf_t iter_buf; mp_obj_t iterable = mp_getiter(o_in, &iter_buf); mp_obj_t item; @@ -106,7 +106,7 @@ STATIC mp_obj_t mp_builtin_all(mp_obj_t o_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_all_obj, mp_builtin_all); -STATIC mp_obj_t mp_builtin_any(mp_obj_t o_in) { +static mp_obj_t mp_builtin_any(mp_obj_t o_in) { mp_obj_iter_buf_t iter_buf; mp_obj_t iterable = mp_getiter(o_in, &iter_buf); mp_obj_t item; @@ -119,13 +119,13 @@ STATIC mp_obj_t mp_builtin_any(mp_obj_t o_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_any_obj, mp_builtin_any); -STATIC mp_obj_t mp_builtin_bin(mp_obj_t o_in) { +static mp_obj_t mp_builtin_bin(mp_obj_t o_in) { mp_obj_t args[] = { MP_OBJ_NEW_QSTR(MP_QSTR__brace_open__colon__hash_b_brace_close_), o_in }; return mp_obj_str_format(MP_ARRAY_SIZE(args), args, NULL); } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_bin_obj, mp_builtin_bin); -STATIC mp_obj_t mp_builtin_callable(mp_obj_t o_in) { +static mp_obj_t mp_builtin_callable(mp_obj_t o_in) { if (mp_obj_is_callable(o_in)) { return mp_const_true; } else { @@ -134,7 +134,7 @@ STATIC mp_obj_t mp_builtin_callable(mp_obj_t o_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_callable_obj, mp_builtin_callable); -STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) { +static mp_obj_t mp_builtin_chr(mp_obj_t o_in) { #if MICROPY_PY_BUILTINS_STR_UNICODE mp_uint_t c = mp_obj_get_int(o_in); if (c >= 0x110000) { @@ -155,7 +155,7 @@ STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_chr_obj, mp_builtin_chr); -STATIC mp_obj_t mp_builtin_dir(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_builtin_dir(size_t n_args, const mp_obj_t *args) { mp_obj_t dir = mp_obj_new_list(0, NULL); if (n_args == 0) { // Make a list of names in the local namespace @@ -188,18 +188,18 @@ STATIC mp_obj_t mp_builtin_dir(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_dir_obj, 0, 1, mp_builtin_dir); -STATIC mp_obj_t mp_builtin_divmod(mp_obj_t o1_in, mp_obj_t o2_in) { +static mp_obj_t mp_builtin_divmod(mp_obj_t o1_in, mp_obj_t o2_in) { return mp_binary_op(MP_BINARY_OP_DIVMOD, o1_in, o2_in); } MP_DEFINE_CONST_FUN_OBJ_2(mp_builtin_divmod_obj, mp_builtin_divmod); -STATIC mp_obj_t mp_builtin_hash(mp_obj_t o_in) { +static mp_obj_t mp_builtin_hash(mp_obj_t o_in) { // result is guaranteed to be a (small) int return mp_unary_op(MP_UNARY_OP_HASH, o_in); } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_hash_obj, mp_builtin_hash); -STATIC mp_obj_t mp_builtin_hex(mp_obj_t o_in) { +static mp_obj_t mp_builtin_hex(mp_obj_t o_in) { #if MICROPY_PY_BUILTINS_STR_OP_MODULO return mp_binary_op(MP_BINARY_OP_MODULO, MP_OBJ_NEW_QSTR(MP_QSTR__percent__hash_x), o_in); #else @@ -219,7 +219,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_hex_obj, mp_builtin_hex); #define mp_hal_readline readline #endif -STATIC mp_obj_t mp_builtin_input(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_builtin_input(size_t n_args, const mp_obj_t *args) { if (n_args == 1) { mp_obj_print(args[0], PRINT_STR); } @@ -238,14 +238,14 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_input_obj, 0, 1, mp_builtin_input #endif -STATIC mp_obj_t mp_builtin_iter(mp_obj_t o_in) { +static mp_obj_t mp_builtin_iter(mp_obj_t o_in) { return mp_getiter(o_in, NULL); } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_iter_obj, mp_builtin_iter); #if MICROPY_PY_BUILTINS_MIN_MAX -STATIC mp_obj_t mp_builtin_min_max(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs, mp_uint_t op) { +static mp_obj_t mp_builtin_min_max(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs, mp_uint_t op) { mp_map_elem_t *key_elem = mp_map_lookup(kwargs, MP_OBJ_NEW_QSTR(MP_QSTR_key), MP_MAP_LOOKUP); mp_map_elem_t *default_elem; mp_obj_t key_fn = key_elem == NULL ? MP_OBJ_NULL : key_elem->value; @@ -287,12 +287,12 @@ STATIC mp_obj_t mp_builtin_min_max(size_t n_args, const mp_obj_t *args, mp_map_t } } -STATIC mp_obj_t mp_builtin_max(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { +static mp_obj_t mp_builtin_max(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { return mp_builtin_min_max(n_args, args, kwargs, MP_BINARY_OP_MORE); } MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_max_obj, 1, mp_builtin_max); -STATIC mp_obj_t mp_builtin_min(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { +static mp_obj_t mp_builtin_min(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { return mp_builtin_min_max(n_args, args, kwargs, MP_BINARY_OP_LESS); } MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_min_obj, 1, mp_builtin_min); @@ -300,7 +300,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_min_obj, 1, mp_builtin_min); #endif #if MICROPY_PY_BUILTINS_NEXT2 -STATIC mp_obj_t mp_builtin_next(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_builtin_next(size_t n_args, const mp_obj_t *args) { if (n_args == 1) { mp_obj_t ret = mp_iternext_allow_raise(args[0]); if (ret == MP_OBJ_STOP_ITERATION) { @@ -315,7 +315,7 @@ STATIC mp_obj_t mp_builtin_next(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_next_obj, 1, 2, mp_builtin_next); #else -STATIC mp_obj_t mp_builtin_next(mp_obj_t o) { +static mp_obj_t mp_builtin_next(mp_obj_t o) { mp_obj_t ret = mp_iternext_allow_raise(o); if (ret == MP_OBJ_STOP_ITERATION) { mp_raise_StopIteration(MP_STATE_THREAD(stop_iteration_arg)); @@ -326,7 +326,7 @@ STATIC mp_obj_t mp_builtin_next(mp_obj_t o) { MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_next_obj, mp_builtin_next); #endif -STATIC mp_obj_t mp_builtin_oct(mp_obj_t o_in) { +static mp_obj_t mp_builtin_oct(mp_obj_t o_in) { #if MICROPY_PY_BUILTINS_STR_OP_MODULO return mp_binary_op(MP_BINARY_OP_MODULO, MP_OBJ_NEW_QSTR(MP_QSTR__percent__hash_o), o_in); #else @@ -336,7 +336,7 @@ STATIC mp_obj_t mp_builtin_oct(mp_obj_t o_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_oct_obj, mp_builtin_oct); -STATIC mp_obj_t mp_builtin_ord(mp_obj_t o_in) { +static mp_obj_t mp_builtin_ord(mp_obj_t o_in) { size_t len; const byte *str = (const byte *)mp_obj_str_get_data(o_in, &len); #if MICROPY_PY_BUILTINS_STR_UNICODE @@ -363,7 +363,7 @@ STATIC mp_obj_t mp_builtin_ord(mp_obj_t o_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_ord_obj, mp_builtin_ord); -STATIC mp_obj_t mp_builtin_pow(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_builtin_pow(size_t n_args, const mp_obj_t *args) { switch (n_args) { case 2: return mp_binary_op(MP_BINARY_OP_POWER, args[0], args[1]); @@ -379,7 +379,7 @@ STATIC mp_obj_t mp_builtin_pow(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_pow_obj, 2, 3, mp_builtin_pow); -STATIC mp_obj_t mp_builtin_print(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t mp_builtin_print(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_sep, ARG_end, ARG_file }; static const mp_arg_t allowed_args[] = { { MP_QSTR_sep, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_QSTR(MP_QSTR__space_)} }, @@ -430,7 +430,7 @@ STATIC mp_obj_t mp_builtin_print(size_t n_args, const mp_obj_t *pos_args, mp_map } MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_print_obj, 0, mp_builtin_print); -STATIC mp_obj_t mp_builtin___repl_print__(mp_obj_t o) { +static mp_obj_t mp_builtin___repl_print__(mp_obj_t o) { if (o != mp_const_none) { mp_obj_print_helper(MP_PYTHON_PRINTER, o, PRINT_REPR); mp_print_str(MP_PYTHON_PRINTER, "\n"); @@ -444,7 +444,7 @@ STATIC mp_obj_t mp_builtin___repl_print__(mp_obj_t o) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin___repl_print___obj, mp_builtin___repl_print__); -STATIC mp_obj_t mp_builtin_repr(mp_obj_t o_in) { +static mp_obj_t mp_builtin_repr(mp_obj_t o_in) { vstr_t vstr; mp_print_t print; vstr_init_print(&vstr, 16, &print); @@ -453,7 +453,7 @@ STATIC mp_obj_t mp_builtin_repr(mp_obj_t o_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_repr_obj, mp_builtin_repr); -STATIC mp_obj_t mp_builtin_round(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_builtin_round(size_t n_args, const mp_obj_t *args) { mp_obj_t o_in = args[0]; if (mp_obj_is_int(o_in)) { if (n_args <= 1) { @@ -505,7 +505,7 @@ STATIC mp_obj_t mp_builtin_round(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_round_obj, 1, 2, mp_builtin_round); -STATIC mp_obj_t mp_builtin_sum(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_builtin_sum(size_t n_args, const mp_obj_t *args) { mp_obj_t value; switch (n_args) { case 1: @@ -525,7 +525,7 @@ STATIC mp_obj_t mp_builtin_sum(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_sum_obj, 1, 2, mp_builtin_sum); -STATIC mp_obj_t mp_builtin_sorted(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { +static mp_obj_t mp_builtin_sorted(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { if (n_args > 1) { mp_raise_TypeError(MP_ERROR_TEXT("must use keyword argument for key function")); } @@ -556,7 +556,7 @@ static inline mp_obj_t mp_load_attr_default(mp_obj_t base, qstr attr, mp_obj_t d } } -STATIC mp_obj_t mp_builtin_getattr(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_builtin_getattr(size_t n_args, const mp_obj_t *args) { mp_obj_t defval = MP_OBJ_NULL; if (n_args > 2) { defval = args[2]; @@ -565,20 +565,20 @@ STATIC mp_obj_t mp_builtin_getattr(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_getattr_obj, 2, 3, mp_builtin_getattr); -STATIC mp_obj_t mp_builtin_setattr(mp_obj_t base, mp_obj_t attr, mp_obj_t value) { +static mp_obj_t mp_builtin_setattr(mp_obj_t base, mp_obj_t attr, mp_obj_t value) { mp_store_attr(base, mp_obj_str_get_qstr(attr), value); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_3(mp_builtin_setattr_obj, mp_builtin_setattr); #if MICROPY_CPYTHON_COMPAT -STATIC mp_obj_t mp_builtin_delattr(mp_obj_t base, mp_obj_t attr) { +static mp_obj_t mp_builtin_delattr(mp_obj_t base, mp_obj_t attr) { return mp_builtin_setattr(base, attr, MP_OBJ_NULL); } MP_DEFINE_CONST_FUN_OBJ_2(mp_builtin_delattr_obj, mp_builtin_delattr); #endif -STATIC mp_obj_t mp_builtin_hasattr(mp_obj_t object_in, mp_obj_t attr_in) { +static mp_obj_t mp_builtin_hasattr(mp_obj_t object_in, mp_obj_t attr_in) { qstr attr = mp_obj_str_get_qstr(attr_in); mp_obj_t dest[2]; mp_load_method_protected(object_in, attr, dest, false); @@ -586,12 +586,12 @@ STATIC mp_obj_t mp_builtin_hasattr(mp_obj_t object_in, mp_obj_t attr_in) { } MP_DEFINE_CONST_FUN_OBJ_2(mp_builtin_hasattr_obj, mp_builtin_hasattr); -STATIC mp_obj_t mp_builtin_globals(void) { +static mp_obj_t mp_builtin_globals(void) { return MP_OBJ_FROM_PTR(mp_globals_get()); } MP_DEFINE_CONST_FUN_OBJ_0(mp_builtin_globals_obj, mp_builtin_globals); -STATIC mp_obj_t mp_builtin_locals(void) { +static mp_obj_t mp_builtin_locals(void) { return MP_OBJ_FROM_PTR(mp_locals_get()); } MP_DEFINE_CONST_FUN_OBJ_0(mp_builtin_locals_obj, mp_builtin_locals); @@ -600,7 +600,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(mp_builtin_locals_obj, mp_builtin_locals); MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_id_obj, mp_obj_id); MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_len_obj, mp_obj_len); -STATIC const mp_rom_map_elem_t mp_module_builtins_globals_table[] = { +static const mp_rom_map_elem_t mp_module_builtins_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_builtins) }, // built-in core functions diff --git a/py/modcmath.c b/py/modcmath.c index 1418362ad9b1e..33cb00cbe7e69 100644 --- a/py/modcmath.c +++ b/py/modcmath.c @@ -31,15 +31,15 @@ #include // phase(z): returns the phase of the number z in the range (-pi, +pi] -STATIC mp_obj_t mp_cmath_phase(mp_obj_t z_obj) { +static mp_obj_t mp_cmath_phase(mp_obj_t z_obj) { mp_float_t real, imag; mp_obj_get_complex(z_obj, &real, &imag); return mp_obj_new_float(MICROPY_FLOAT_C_FUN(atan2)(imag, real)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_phase_obj, mp_cmath_phase); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_phase_obj, mp_cmath_phase); // polar(z): returns the polar form of z as a tuple -STATIC mp_obj_t mp_cmath_polar(mp_obj_t z_obj) { +static mp_obj_t mp_cmath_polar(mp_obj_t z_obj) { mp_float_t real, imag; mp_obj_get_complex(z_obj, &real, &imag); mp_obj_t tuple[2] = { @@ -48,71 +48,71 @@ STATIC mp_obj_t mp_cmath_polar(mp_obj_t z_obj) { }; return mp_obj_new_tuple(2, tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_polar_obj, mp_cmath_polar); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_polar_obj, mp_cmath_polar); // rect(r, phi): returns the complex number with modulus r and phase phi -STATIC mp_obj_t mp_cmath_rect(mp_obj_t r_obj, mp_obj_t phi_obj) { +static mp_obj_t mp_cmath_rect(mp_obj_t r_obj, mp_obj_t phi_obj) { mp_float_t r = mp_obj_get_float(r_obj); mp_float_t phi = mp_obj_get_float(phi_obj); return mp_obj_new_complex(r * MICROPY_FLOAT_C_FUN(cos)(phi), r * MICROPY_FLOAT_C_FUN(sin)(phi)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_cmath_rect_obj, mp_cmath_rect); +static MP_DEFINE_CONST_FUN_OBJ_2(mp_cmath_rect_obj, mp_cmath_rect); // exp(z): return the exponential of z -STATIC mp_obj_t mp_cmath_exp(mp_obj_t z_obj) { +static mp_obj_t mp_cmath_exp(mp_obj_t z_obj) { mp_float_t real, imag; mp_obj_get_complex(z_obj, &real, &imag); mp_float_t exp_real = MICROPY_FLOAT_C_FUN(exp)(real); return mp_obj_new_complex(exp_real * MICROPY_FLOAT_C_FUN(cos)(imag), exp_real * MICROPY_FLOAT_C_FUN(sin)(imag)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_exp_obj, mp_cmath_exp); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_exp_obj, mp_cmath_exp); // log(z): return the natural logarithm of z, with branch cut along the negative real axis // TODO can take second argument, being the base -STATIC mp_obj_t mp_cmath_log(mp_obj_t z_obj) { +static mp_obj_t mp_cmath_log(mp_obj_t z_obj) { mp_float_t real, imag; mp_obj_get_complex(z_obj, &real, &imag); return mp_obj_new_complex(MICROPY_FLOAT_CONST(0.5) * MICROPY_FLOAT_C_FUN(log)(real * real + imag * imag), MICROPY_FLOAT_C_FUN(atan2)(imag, real)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_log_obj, mp_cmath_log); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_log_obj, mp_cmath_log); #if MICROPY_PY_MATH_SPECIAL_FUNCTIONS // log10(z): return the base-10 logarithm of z, with branch cut along the negative real axis -STATIC mp_obj_t mp_cmath_log10(mp_obj_t z_obj) { +static mp_obj_t mp_cmath_log10(mp_obj_t z_obj) { mp_float_t real, imag; mp_obj_get_complex(z_obj, &real, &imag); return mp_obj_new_complex(MICROPY_FLOAT_CONST(0.5) * MICROPY_FLOAT_C_FUN(log10)(real * real + imag * imag), MICROPY_FLOAT_CONST(0.4342944819032518) * MICROPY_FLOAT_C_FUN(atan2)(imag, real)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_log10_obj, mp_cmath_log10); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_log10_obj, mp_cmath_log10); #endif // sqrt(z): return the square-root of z -STATIC mp_obj_t mp_cmath_sqrt(mp_obj_t z_obj) { +static mp_obj_t mp_cmath_sqrt(mp_obj_t z_obj) { mp_float_t real, imag; mp_obj_get_complex(z_obj, &real, &imag); mp_float_t sqrt_abs = MICROPY_FLOAT_C_FUN(pow)(real * real + imag * imag, MICROPY_FLOAT_CONST(0.25)); mp_float_t theta = MICROPY_FLOAT_CONST(0.5) * MICROPY_FLOAT_C_FUN(atan2)(imag, real); return mp_obj_new_complex(sqrt_abs * MICROPY_FLOAT_C_FUN(cos)(theta), sqrt_abs * MICROPY_FLOAT_C_FUN(sin)(theta)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_sqrt_obj, mp_cmath_sqrt); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_sqrt_obj, mp_cmath_sqrt); // cos(z): return the cosine of z -STATIC mp_obj_t mp_cmath_cos(mp_obj_t z_obj) { +static mp_obj_t mp_cmath_cos(mp_obj_t z_obj) { mp_float_t real, imag; mp_obj_get_complex(z_obj, &real, &imag); return mp_obj_new_complex(MICROPY_FLOAT_C_FUN(cos)(real) * MICROPY_FLOAT_C_FUN(cosh)(imag), -MICROPY_FLOAT_C_FUN(sin)(real) * MICROPY_FLOAT_C_FUN(sinh)(imag)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_cos_obj, mp_cmath_cos); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_cos_obj, mp_cmath_cos); // sin(z): return the sine of z -STATIC mp_obj_t mp_cmath_sin(mp_obj_t z_obj) { +static mp_obj_t mp_cmath_sin(mp_obj_t z_obj) { mp_float_t real, imag; mp_obj_get_complex(z_obj, &real, &imag); return mp_obj_new_complex(MICROPY_FLOAT_C_FUN(sin)(real) * MICROPY_FLOAT_C_FUN(cosh)(imag), MICROPY_FLOAT_C_FUN(cos)(real) * MICROPY_FLOAT_C_FUN(sinh)(imag)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_sin_obj, mp_cmath_sin); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_sin_obj, mp_cmath_sin); -STATIC const mp_rom_map_elem_t mp_module_cmath_globals_table[] = { +static const mp_rom_map_elem_t mp_module_cmath_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_cmath) }, { MP_ROM_QSTR(MP_QSTR_e), mp_const_float_e }, { MP_ROM_QSTR(MP_QSTR_pi), mp_const_float_pi }, @@ -142,7 +142,7 @@ STATIC const mp_rom_map_elem_t mp_module_cmath_globals_table[] = { // { MP_ROM_QSTR(MP_QSTR_isnan), MP_ROM_PTR(&mp_cmath_isnan_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_cmath_globals, mp_module_cmath_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_cmath_globals, mp_module_cmath_globals_table); const mp_obj_module_t mp_module_cmath = { .base = { &mp_type_module }, diff --git a/py/modcollections.c b/py/modcollections.c index 30a5881bc2c3a..46326d13eef5a 100644 --- a/py/modcollections.c +++ b/py/modcollections.c @@ -28,7 +28,7 @@ #if MICROPY_PY_COLLECTIONS -STATIC const mp_rom_map_elem_t mp_module_collections_globals_table[] = { +static const mp_rom_map_elem_t mp_module_collections_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_collections) }, #if MICROPY_PY_COLLECTIONS_DEQUE { MP_ROM_QSTR(MP_QSTR_deque), MP_ROM_PTR(&mp_type_deque) }, @@ -39,7 +39,7 @@ STATIC const mp_rom_map_elem_t mp_module_collections_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_collections_globals, mp_module_collections_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_collections_globals, mp_module_collections_globals_table); const mp_obj_module_t mp_module_collections = { .base = { &mp_type_module }, diff --git a/py/moderrno.c b/py/moderrno.c index 4f0673a23a255..58a141c102025 100644 --- a/py/moderrno.c +++ b/py/moderrno.c @@ -62,13 +62,13 @@ #endif #if MICROPY_PY_ERRNO_ERRORCODE -STATIC const mp_rom_map_elem_t errorcode_table[] = { +static const mp_rom_map_elem_t errorcode_table[] = { #define X(e) { MP_ROM_INT(MP_##e), MP_ROM_QSTR(MP_QSTR_##e) }, MICROPY_PY_ERRNO_LIST #undef X }; -STATIC const mp_obj_dict_t errorcode_dict = { +static const mp_obj_dict_t errorcode_dict = { .base = {&mp_type_dict}, .map = { .all_keys_are_qstrs = 0, // keys are integers @@ -81,7 +81,7 @@ STATIC const mp_obj_dict_t errorcode_dict = { }; #endif -STATIC const mp_rom_map_elem_t mp_module_errno_globals_table[] = { +static const mp_rom_map_elem_t mp_module_errno_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_errno) }, #if MICROPY_PY_ERRNO_ERRORCODE { MP_ROM_QSTR(MP_QSTR_errorcode), MP_ROM_PTR(&errorcode_dict) }, @@ -92,7 +92,7 @@ STATIC const mp_rom_map_elem_t mp_module_errno_globals_table[] = { #undef X }; -STATIC MP_DEFINE_CONST_DICT(mp_module_errno_globals, mp_module_errno_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_errno_globals, mp_module_errno_globals_table); const mp_obj_module_t mp_module_errno = { .base = { &mp_type_module }, diff --git a/py/modgc.c b/py/modgc.c index 7b18045b083a3..47902d8c95bce 100644 --- a/py/modgc.c +++ b/py/modgc.c @@ -31,7 +31,7 @@ #if MICROPY_PY_GC && MICROPY_ENABLE_GC // collect(): run a garbage collection -STATIC mp_obj_t py_gc_collect(void) { +static mp_obj_t py_gc_collect(void) { gc_collect(); #if MICROPY_PY_GC_COLLECT_RETVAL return MP_OBJ_NEW_SMALL_INT(MP_STATE_MEM(gc_collected)); @@ -42,26 +42,26 @@ STATIC mp_obj_t py_gc_collect(void) { MP_DEFINE_CONST_FUN_OBJ_0(gc_collect_obj, py_gc_collect); // disable(): disable the garbage collector -STATIC mp_obj_t gc_disable(void) { +static mp_obj_t gc_disable(void) { MP_STATE_MEM(gc_auto_collect_enabled) = 0; return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_0(gc_disable_obj, gc_disable); // enable(): enable the garbage collector -STATIC mp_obj_t gc_enable(void) { +static mp_obj_t gc_enable(void) { MP_STATE_MEM(gc_auto_collect_enabled) = 1; return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_0(gc_enable_obj, gc_enable); -STATIC mp_obj_t gc_isenabled(void) { +static mp_obj_t gc_isenabled(void) { return mp_obj_new_bool(MP_STATE_MEM(gc_auto_collect_enabled)); } MP_DEFINE_CONST_FUN_OBJ_0(gc_isenabled_obj, gc_isenabled); // mem_free(): return the number of bytes of available heap RAM -STATIC mp_obj_t gc_mem_free(void) { +static mp_obj_t gc_mem_free(void) { gc_info_t info; gc_info(&info); #if MICROPY_GC_SPLIT_HEAP_AUTO @@ -74,7 +74,7 @@ STATIC mp_obj_t gc_mem_free(void) { MP_DEFINE_CONST_FUN_OBJ_0(gc_mem_free_obj, gc_mem_free); // mem_alloc(): return the number of bytes of heap RAM that are allocated -STATIC mp_obj_t gc_mem_alloc(void) { +static mp_obj_t gc_mem_alloc(void) { gc_info_t info; gc_info(&info); return MP_OBJ_NEW_SMALL_INT(info.used); @@ -82,7 +82,7 @@ STATIC mp_obj_t gc_mem_alloc(void) { MP_DEFINE_CONST_FUN_OBJ_0(gc_mem_alloc_obj, gc_mem_alloc); #if MICROPY_GC_ALLOC_THRESHOLD -STATIC mp_obj_t gc_threshold(size_t n_args, const mp_obj_t *args) { +static mp_obj_t gc_threshold(size_t n_args, const mp_obj_t *args) { if (n_args == 0) { if (MP_STATE_MEM(gc_alloc_threshold) == (size_t)-1) { return MP_OBJ_NEW_SMALL_INT(-1); @@ -100,7 +100,7 @@ STATIC mp_obj_t gc_threshold(size_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(gc_threshold_obj, 0, 1, gc_threshold); #endif -STATIC const mp_rom_map_elem_t mp_module_gc_globals_table[] = { +static const mp_rom_map_elem_t mp_module_gc_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_gc) }, { MP_ROM_QSTR(MP_QSTR_collect), MP_ROM_PTR(&gc_collect_obj) }, { MP_ROM_QSTR(MP_QSTR_disable), MP_ROM_PTR(&gc_disable_obj) }, @@ -113,7 +113,7 @@ STATIC const mp_rom_map_elem_t mp_module_gc_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_gc_globals, mp_module_gc_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_gc_globals, mp_module_gc_globals_table); const mp_obj_module_t mp_module_gc = { .base = { &mp_type_module }, diff --git a/py/modio.c b/py/modio.c index 37eff3c41c4a0..d3e563dbcf447 100644 --- a/py/modio.c +++ b/py/modio.c @@ -39,11 +39,11 @@ #if MICROPY_PY_IO_IOBASE -STATIC const mp_obj_type_t mp_type_iobase; +static const mp_obj_type_t mp_type_iobase; -STATIC const mp_obj_base_t iobase_singleton = {&mp_type_iobase}; +static const mp_obj_base_t iobase_singleton = {&mp_type_iobase}; -STATIC mp_obj_t iobase_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t iobase_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type; (void)n_args; (void)n_kw; @@ -51,7 +51,7 @@ STATIC mp_obj_t iobase_make_new(const mp_obj_type_t *type, size_t n_args, size_t return MP_OBJ_FROM_PTR(&iobase_singleton); } -STATIC mp_uint_t iobase_read_write(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode, qstr qst) { +static mp_uint_t iobase_read_write(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode, qstr qst) { mp_obj_t dest[3]; mp_load_method(obj, qst, dest); mp_obj_array_t ar = {{&mp_type_bytearray}, BYTEARRAY_TYPECODE, 0, size, buf}; @@ -69,15 +69,15 @@ STATIC mp_uint_t iobase_read_write(mp_obj_t obj, void *buf, mp_uint_t size, int return MP_STREAM_ERROR; } } -STATIC mp_uint_t iobase_read(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t iobase_read(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode) { return iobase_read_write(obj, buf, size, errcode, MP_QSTR_readinto); } -STATIC mp_uint_t iobase_write(mp_obj_t obj, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t iobase_write(mp_obj_t obj, const void *buf, mp_uint_t size, int *errcode) { return iobase_read_write(obj, (void *)buf, size, errcode, MP_QSTR_write); } -STATIC mp_uint_t iobase_ioctl(mp_obj_t obj, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t iobase_ioctl(mp_obj_t obj, mp_uint_t request, uintptr_t arg, int *errcode) { mp_obj_t dest[4]; mp_load_method(obj, MP_QSTR_ioctl, dest); dest[2] = mp_obj_new_int_from_uint(request); @@ -91,13 +91,13 @@ STATIC mp_uint_t iobase_ioctl(mp_obj_t obj, mp_uint_t request, uintptr_t arg, in } } -STATIC const mp_stream_p_t iobase_p = { +static const mp_stream_p_t iobase_p = { .read = iobase_read, .write = iobase_write, .ioctl = iobase_ioctl, }; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_iobase, MP_QSTR_IOBase, MP_TYPE_FLAG_NONE, @@ -116,7 +116,7 @@ typedef struct _mp_obj_bufwriter_t { byte buf[0]; } mp_obj_bufwriter_t; -STATIC mp_obj_t bufwriter_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t bufwriter_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 2, 2, false); size_t alloc = mp_obj_get_int(args[1]); mp_obj_bufwriter_t *o = mp_obj_malloc_var(mp_obj_bufwriter_t, buf, byte, alloc, type); @@ -126,7 +126,7 @@ STATIC mp_obj_t bufwriter_make_new(const mp_obj_type_t *type, size_t n_args, siz return o; } -STATIC mp_uint_t bufwriter_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t bufwriter_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { mp_obj_bufwriter_t *self = MP_OBJ_TO_PTR(self_in); mp_uint_t org_size = size; @@ -162,7 +162,7 @@ STATIC mp_uint_t bufwriter_write(mp_obj_t self_in, const void *buf, mp_uint_t si return org_size; } -STATIC mp_obj_t bufwriter_flush(mp_obj_t self_in) { +static mp_obj_t bufwriter_flush(mp_obj_t self_in) { mp_obj_bufwriter_t *self = MP_OBJ_TO_PTR(self_in); if (self->len != 0) { @@ -180,19 +180,19 @@ STATIC mp_obj_t bufwriter_flush(mp_obj_t self_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bufwriter_flush_obj, bufwriter_flush); +static MP_DEFINE_CONST_FUN_OBJ_1(bufwriter_flush_obj, bufwriter_flush); -STATIC const mp_rom_map_elem_t bufwriter_locals_dict_table[] = { +static const mp_rom_map_elem_t bufwriter_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) }, { MP_ROM_QSTR(MP_QSTR_flush), MP_ROM_PTR(&bufwriter_flush_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(bufwriter_locals_dict, bufwriter_locals_dict_table); +static MP_DEFINE_CONST_DICT(bufwriter_locals_dict, bufwriter_locals_dict_table); -STATIC const mp_stream_p_t bufwriter_stream_p = { +static const mp_stream_p_t bufwriter_stream_p = { .write = bufwriter_write, }; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_bufwriter, MP_QSTR_BufferedWriter, MP_TYPE_FLAG_NONE, @@ -202,7 +202,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); #endif // MICROPY_PY_IO_BUFFEREDWRITER -STATIC const mp_rom_map_elem_t mp_module_io_globals_table[] = { +static const mp_rom_map_elem_t mp_module_io_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_io) }, // Note: mp_builtin_open_obj should be defined by port, it's not // part of the core. @@ -219,7 +219,7 @@ STATIC const mp_rom_map_elem_t mp_module_io_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_io_globals, mp_module_io_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_io_globals, mp_module_io_globals_table); const mp_obj_module_t mp_module_io = { .base = { &mp_type_module }, diff --git a/py/modmath.c b/py/modmath.c index 861a23b48b3e6..db30f0e62559c 100644 --- a/py/modmath.c +++ b/py/modmath.c @@ -37,11 +37,11 @@ #define MP_PI_4 MICROPY_FLOAT_CONST(0.78539816339744830962) #define MP_3_PI_4 MICROPY_FLOAT_CONST(2.35619449019234492885) -STATIC NORETURN void math_error(void) { +static NORETURN void math_error(void) { mp_raise_ValueError(MP_ERROR_TEXT("math domain error")); } -STATIC mp_obj_t math_generic_1(mp_obj_t x_obj, mp_float_t (*f)(mp_float_t)) { +static mp_obj_t math_generic_1(mp_obj_t x_obj, mp_float_t (*f)(mp_float_t)) { mp_float_t x = mp_obj_get_float(x_obj); mp_float_t ans = f(x); if ((isnan(ans) && !isnan(x)) || (isinf(ans) && !isinf(x))) { @@ -50,7 +50,7 @@ STATIC mp_obj_t math_generic_1(mp_obj_t x_obj, mp_float_t (*f)(mp_float_t)) { return mp_obj_new_float(ans); } -STATIC mp_obj_t math_generic_2(mp_obj_t x_obj, mp_obj_t y_obj, mp_float_t (*f)(mp_float_t, mp_float_t)) { +static mp_obj_t math_generic_2(mp_obj_t x_obj, mp_obj_t y_obj, mp_float_t (*f)(mp_float_t, mp_float_t)) { mp_float_t x = mp_obj_get_float(x_obj); mp_float_t y = mp_obj_get_float(y_obj); mp_float_t ans = f(x, y); @@ -61,30 +61,30 @@ STATIC mp_obj_t math_generic_2(mp_obj_t x_obj, mp_obj_t y_obj, mp_float_t (*f)(m } #define MATH_FUN_1(py_name, c_name) \ - STATIC mp_obj_t mp_math_##py_name(mp_obj_t x_obj) { \ + static mp_obj_t mp_math_##py_name(mp_obj_t x_obj) { \ return math_generic_1(x_obj, MICROPY_FLOAT_C_FUN(c_name)); \ } \ - STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_##py_name##_obj, mp_math_##py_name); + static MP_DEFINE_CONST_FUN_OBJ_1(mp_math_##py_name##_obj, mp_math_##py_name); #define MATH_FUN_1_TO_BOOL(py_name, c_name) \ - STATIC mp_obj_t mp_math_##py_name(mp_obj_t x_obj) { return mp_obj_new_bool(c_name(mp_obj_get_float(x_obj))); } \ - STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_##py_name##_obj, mp_math_##py_name); + static mp_obj_t mp_math_##py_name(mp_obj_t x_obj) { return mp_obj_new_bool(c_name(mp_obj_get_float(x_obj))); } \ + static MP_DEFINE_CONST_FUN_OBJ_1(mp_math_##py_name##_obj, mp_math_##py_name); #define MATH_FUN_1_TO_INT(py_name, c_name) \ - STATIC mp_obj_t mp_math_##py_name(mp_obj_t x_obj) { return mp_obj_new_int_from_float(MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj))); } \ - STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_##py_name##_obj, mp_math_##py_name); + static mp_obj_t mp_math_##py_name(mp_obj_t x_obj) { return mp_obj_new_int_from_float(MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj))); } \ + static MP_DEFINE_CONST_FUN_OBJ_1(mp_math_##py_name##_obj, mp_math_##py_name); #define MATH_FUN_2(py_name, c_name) \ - STATIC mp_obj_t mp_math_##py_name(mp_obj_t x_obj, mp_obj_t y_obj) { \ + static mp_obj_t mp_math_##py_name(mp_obj_t x_obj, mp_obj_t y_obj) { \ return math_generic_2(x_obj, y_obj, MICROPY_FLOAT_C_FUN(c_name)); \ } \ - STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_math_##py_name##_obj, mp_math_##py_name); + static MP_DEFINE_CONST_FUN_OBJ_2(mp_math_##py_name##_obj, mp_math_##py_name); #define MATH_FUN_2_FLT_INT(py_name, c_name) \ - STATIC mp_obj_t mp_math_##py_name(mp_obj_t x_obj, mp_obj_t y_obj) { \ + static mp_obj_t mp_math_##py_name(mp_obj_t x_obj, mp_obj_t y_obj) { \ return mp_obj_new_float(MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj), mp_obj_get_int(y_obj))); \ } \ - STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_math_##py_name##_obj, mp_math_##py_name); + static MP_DEFINE_CONST_FUN_OBJ_2(mp_math_##py_name##_obj, mp_math_##py_name); #if MP_NEED_LOG2 #undef log2 @@ -160,12 +160,12 @@ MATH_FUN_2(atan2, atan2) // ceil(x) MATH_FUN_1_TO_INT(ceil, ceil) // copysign(x, y) -STATIC mp_float_t MICROPY_FLOAT_C_FUN(copysign_func)(mp_float_t x, mp_float_t y) { +static mp_float_t MICROPY_FLOAT_C_FUN(copysign_func)(mp_float_t x, mp_float_t y) { return MICROPY_FLOAT_C_FUN(copysign)(x, y); } MATH_FUN_2(copysign, copysign_func) // fabs(x) -STATIC mp_float_t MICROPY_FLOAT_C_FUN(fabs_func)(mp_float_t x) { +static mp_float_t MICROPY_FLOAT_C_FUN(fabs_func)(mp_float_t x) { return MICROPY_FLOAT_C_FUN(fabs)(x); } MATH_FUN_1(fabs, fabs_func) @@ -203,7 +203,7 @@ MATH_FUN_1(lgamma, lgamma) // TODO: fsum #if MICROPY_PY_MATH_ISCLOSE -STATIC mp_obj_t mp_math_isclose(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t mp_math_isclose(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_rel_tol, ARG_abs_tol }; static const mp_arg_t allowed_args[] = { {MP_QSTR_rel_tol, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL}}, @@ -239,7 +239,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(mp_math_isclose_obj, 2, mp_math_isclose); // Function that takes a variable number of arguments // log(x[, base]) -STATIC mp_obj_t mp_math_log(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_math_log(size_t n_args, const mp_obj_t *args) { mp_float_t x = mp_obj_get_float(args[0]); if (x <= (mp_float_t)0.0) { math_error(); @@ -257,12 +257,12 @@ STATIC mp_obj_t mp_math_log(size_t n_args, const mp_obj_t *args) { return mp_obj_new_float(l / MICROPY_FLOAT_C_FUN(log)(base)); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_math_log_obj, 1, 2, mp_math_log); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_math_log_obj, 1, 2, mp_math_log); // Functions that return a tuple // frexp(x): converts a floating-point number to fractional and integral components -STATIC mp_obj_t mp_math_frexp(mp_obj_t x_obj) { +static mp_obj_t mp_math_frexp(mp_obj_t x_obj) { int int_exponent = 0; mp_float_t significand = MICROPY_FLOAT_C_FUN(frexp)(mp_obj_get_float(x_obj), &int_exponent); mp_obj_t tuple[2]; @@ -270,10 +270,10 @@ STATIC mp_obj_t mp_math_frexp(mp_obj_t x_obj) { tuple[1] = mp_obj_new_int(int_exponent); return mp_obj_new_tuple(2, tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_frexp_obj, mp_math_frexp); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_math_frexp_obj, mp_math_frexp); // modf(x) -STATIC mp_obj_t mp_math_modf(mp_obj_t x_obj) { +static mp_obj_t mp_math_modf(mp_obj_t x_obj) { mp_float_t int_part = 0.0; mp_float_t x = mp_obj_get_float(x_obj); mp_float_t fractional_part = MICROPY_FLOAT_C_FUN(modf)(x, &int_part); @@ -287,28 +287,28 @@ STATIC mp_obj_t mp_math_modf(mp_obj_t x_obj) { tuple[1] = mp_obj_new_float(int_part); return mp_obj_new_tuple(2, tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_modf_obj, mp_math_modf); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_math_modf_obj, mp_math_modf); // Angular conversions // radians(x) -STATIC mp_obj_t mp_math_radians(mp_obj_t x_obj) { +static mp_obj_t mp_math_radians(mp_obj_t x_obj) { return mp_obj_new_float(mp_obj_get_float(x_obj) * (MP_PI / MICROPY_FLOAT_CONST(180.0))); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_radians_obj, mp_math_radians); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_math_radians_obj, mp_math_radians); // degrees(x) -STATIC mp_obj_t mp_math_degrees(mp_obj_t x_obj) { +static mp_obj_t mp_math_degrees(mp_obj_t x_obj) { return mp_obj_new_float(mp_obj_get_float(x_obj) * (MICROPY_FLOAT_CONST(180.0) / MP_PI)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_degrees_obj, mp_math_degrees); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_math_degrees_obj, mp_math_degrees); #if MICROPY_PY_MATH_FACTORIAL #if MICROPY_OPT_MATH_FACTORIAL // factorial(x): slightly efficient recursive implementation -STATIC mp_obj_t mp_math_factorial_inner(mp_uint_t start, mp_uint_t end) { +static mp_obj_t mp_math_factorial_inner(mp_uint_t start, mp_uint_t end) { if (start == end) { return mp_obj_new_int(start); } else if (end - start == 1) { @@ -326,7 +326,7 @@ STATIC mp_obj_t mp_math_factorial_inner(mp_uint_t start, mp_uint_t end) { return mp_binary_op(MP_BINARY_OP_MULTIPLY, left, right); } } -STATIC mp_obj_t mp_math_factorial(mp_obj_t x_obj) { +static mp_obj_t mp_math_factorial(mp_obj_t x_obj) { mp_int_t max = mp_obj_get_int(x_obj); if (max < 0) { mp_raise_ValueError(MP_ERROR_TEXT("negative factorial")); @@ -340,7 +340,7 @@ STATIC mp_obj_t mp_math_factorial(mp_obj_t x_obj) { // factorial(x): squared difference implementation // based on http://www.luschny.de/math/factorial/index.html -STATIC mp_obj_t mp_math_factorial(mp_obj_t x_obj) { +static mp_obj_t mp_math_factorial(mp_obj_t x_obj) { mp_int_t max = mp_obj_get_int(x_obj); if (max < 0) { mp_raise_ValueError(MP_ERROR_TEXT("negative factorial")); @@ -363,11 +363,11 @@ STATIC mp_obj_t mp_math_factorial(mp_obj_t x_obj) { #endif -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_factorial_obj, mp_math_factorial); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_math_factorial_obj, mp_math_factorial); #endif -STATIC const mp_rom_map_elem_t mp_module_math_globals_table[] = { +static const mp_rom_map_elem_t mp_module_math_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_math) }, { MP_ROM_QSTR(MP_QSTR_e), mp_const_float_e }, { MP_ROM_QSTR(MP_QSTR_pi), mp_const_float_pi }, @@ -428,7 +428,7 @@ STATIC const mp_rom_map_elem_t mp_module_math_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_math_globals, mp_module_math_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_math_globals, mp_module_math_globals_table); const mp_obj_module_t mp_module_math = { .base = { &mp_type_module }, diff --git a/py/modmicropython.c b/py/modmicropython.c index bdb1e8b9b4c00..af6ad01795f67 100644 --- a/py/modmicropython.c +++ b/py/modmicropython.c @@ -38,7 +38,7 @@ // living in micropython module #if MICROPY_ENABLE_COMPILER -STATIC mp_obj_t mp_micropython_opt_level(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_micropython_opt_level(size_t n_args, const mp_obj_t *args) { if (n_args == 0) { return MP_OBJ_NEW_SMALL_INT(MP_STATE_VM(mp_optimise_value)); } else { @@ -46,26 +46,26 @@ STATIC mp_obj_t mp_micropython_opt_level(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_micropython_opt_level_obj, 0, 1, mp_micropython_opt_level); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_micropython_opt_level_obj, 0, 1, mp_micropython_opt_level); #endif #if MICROPY_PY_MICROPYTHON_MEM_INFO #if MICROPY_MEM_STATS -STATIC mp_obj_t mp_micropython_mem_total(void) { +static mp_obj_t mp_micropython_mem_total(void) { return MP_OBJ_NEW_SMALL_INT(m_get_total_bytes_allocated()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_mem_total_obj, mp_micropython_mem_total); +static MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_mem_total_obj, mp_micropython_mem_total); -STATIC mp_obj_t mp_micropython_mem_current(void) { +static mp_obj_t mp_micropython_mem_current(void) { return MP_OBJ_NEW_SMALL_INT(m_get_current_bytes_allocated()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_mem_current_obj, mp_micropython_mem_current); +static MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_mem_current_obj, mp_micropython_mem_current); -STATIC mp_obj_t mp_micropython_mem_peak(void) { +static mp_obj_t mp_micropython_mem_peak(void) { return MP_OBJ_NEW_SMALL_INT(m_get_peak_bytes_allocated()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_mem_peak_obj, mp_micropython_mem_peak); +static MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_mem_peak_obj, mp_micropython_mem_peak); #endif mp_obj_t mp_micropython_mem_info(size_t n_args, const mp_obj_t *args) { @@ -91,9 +91,9 @@ mp_obj_t mp_micropython_mem_info(size_t n_args, const mp_obj_t *args) { #endif return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_micropython_mem_info_obj, 0, 1, mp_micropython_mem_info); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_micropython_mem_info_obj, 0, 1, mp_micropython_mem_info); -STATIC mp_obj_t mp_micropython_qstr_info(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_micropython_qstr_info(size_t n_args, const mp_obj_t *args) { (void)args; size_t n_pool, n_qstr, n_str_data_bytes, n_total_bytes; qstr_pool_info(&n_pool, &n_qstr, &n_str_data_bytes, &n_total_bytes); @@ -105,68 +105,68 @@ STATIC mp_obj_t mp_micropython_qstr_info(size_t n_args, const mp_obj_t *args) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_micropython_qstr_info_obj, 0, 1, mp_micropython_qstr_info); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_micropython_qstr_info_obj, 0, 1, mp_micropython_qstr_info); #endif // MICROPY_PY_MICROPYTHON_MEM_INFO #if MICROPY_PY_MICROPYTHON_STACK_USE -STATIC mp_obj_t mp_micropython_stack_use(void) { +static mp_obj_t mp_micropython_stack_use(void) { return MP_OBJ_NEW_SMALL_INT(mp_stack_usage()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_stack_use_obj, mp_micropython_stack_use); +static MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_stack_use_obj, mp_micropython_stack_use); #endif #if MICROPY_ENABLE_PYSTACK -STATIC mp_obj_t mp_micropython_pystack_use(void) { +static mp_obj_t mp_micropython_pystack_use(void) { return MP_OBJ_NEW_SMALL_INT(mp_pystack_usage()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_pystack_use_obj, mp_micropython_pystack_use); +static MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_pystack_use_obj, mp_micropython_pystack_use); #endif #if MICROPY_ENABLE_GC -STATIC mp_obj_t mp_micropython_heap_lock(void) { +static mp_obj_t mp_micropython_heap_lock(void) { gc_lock(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_heap_lock_obj, mp_micropython_heap_lock); +static MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_heap_lock_obj, mp_micropython_heap_lock); -STATIC mp_obj_t mp_micropython_heap_unlock(void) { +static mp_obj_t mp_micropython_heap_unlock(void) { gc_unlock(); return MP_OBJ_NEW_SMALL_INT(MP_STATE_THREAD(gc_lock_depth)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_heap_unlock_obj, mp_micropython_heap_unlock); +static MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_heap_unlock_obj, mp_micropython_heap_unlock); #if MICROPY_PY_MICROPYTHON_HEAP_LOCKED -STATIC mp_obj_t mp_micropython_heap_locked(void) { +static mp_obj_t mp_micropython_heap_locked(void) { return MP_OBJ_NEW_SMALL_INT(MP_STATE_THREAD(gc_lock_depth)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_heap_locked_obj, mp_micropython_heap_locked); +static MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_heap_locked_obj, mp_micropython_heap_locked); #endif #endif #if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF && (MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE == 0) -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_alloc_emergency_exception_buf_obj, mp_alloc_emergency_exception_buf); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_alloc_emergency_exception_buf_obj, mp_alloc_emergency_exception_buf); #endif #if MICROPY_KBD_EXCEPTION -STATIC mp_obj_t mp_micropython_kbd_intr(mp_obj_t int_chr_in) { +static mp_obj_t mp_micropython_kbd_intr(mp_obj_t int_chr_in) { mp_hal_set_interrupt_char(mp_obj_get_int(int_chr_in)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_micropython_kbd_intr_obj, mp_micropython_kbd_intr); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_micropython_kbd_intr_obj, mp_micropython_kbd_intr); #endif #if MICROPY_ENABLE_SCHEDULER -STATIC mp_obj_t mp_micropython_schedule(mp_obj_t function, mp_obj_t arg) { +static mp_obj_t mp_micropython_schedule(mp_obj_t function, mp_obj_t arg) { if (!mp_sched_schedule(function, arg)) { mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("schedule queue full")); } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_micropython_schedule_obj, mp_micropython_schedule); +static MP_DEFINE_CONST_FUN_OBJ_2(mp_micropython_schedule_obj, mp_micropython_schedule); #endif -STATIC const mp_rom_map_elem_t mp_module_micropython_globals_table[] = { +static const mp_rom_map_elem_t mp_module_micropython_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_micropython) }, { MP_ROM_QSTR(MP_QSTR_const), MP_ROM_PTR(&mp_identity_obj) }, #if MICROPY_ENABLE_COMPILER @@ -205,7 +205,7 @@ STATIC const mp_rom_map_elem_t mp_module_micropython_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_micropython_globals, mp_module_micropython_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_micropython_globals, mp_module_micropython_globals_table); const mp_obj_module_t mp_module_micropython = { .base = { &mp_type_module }, diff --git a/py/modstruct.c b/py/modstruct.c index b3edc96328703..3b9dd30aa707a 100644 --- a/py/modstruct.c +++ b/py/modstruct.c @@ -52,7 +52,7 @@ character data". */ -STATIC char get_fmt_type(const char **fmt) { +static char get_fmt_type(const char **fmt) { char t = **fmt; switch (t) { case '!': @@ -71,7 +71,7 @@ STATIC char get_fmt_type(const char **fmt) { return t; } -STATIC mp_uint_t get_fmt_num(const char **p) { +static mp_uint_t get_fmt_num(const char **p) { const char *num = *p; uint len = 1; while (unichar_isdigit(*++num)) { @@ -82,7 +82,7 @@ STATIC mp_uint_t get_fmt_num(const char **p) { return val; } -STATIC size_t calc_size_items(const char *fmt, size_t *total_sz) { +static size_t calc_size_items(const char *fmt, size_t *total_sz) { char fmt_type = get_fmt_type(&fmt); size_t total_cnt = 0; size_t size; @@ -112,7 +112,7 @@ STATIC size_t calc_size_items(const char *fmt, size_t *total_sz) { return total_cnt; } -STATIC mp_obj_t struct_calcsize(mp_obj_t fmt_in) { +static mp_obj_t struct_calcsize(mp_obj_t fmt_in) { const char *fmt = mp_obj_str_get_str(fmt_in); size_t size; calc_size_items(fmt, &size); @@ -120,7 +120,7 @@ STATIC mp_obj_t struct_calcsize(mp_obj_t fmt_in) { } MP_DEFINE_CONST_FUN_OBJ_1(struct_calcsize_obj, struct_calcsize); -STATIC mp_obj_t struct_unpack_from(size_t n_args, const mp_obj_t *args) { +static mp_obj_t struct_unpack_from(size_t n_args, const mp_obj_t *args) { // unpack requires that the buffer be exactly the right size. // unpack_from requires that the buffer be "big enough". // Since we implement unpack and unpack_from using the same function @@ -180,7 +180,7 @@ STATIC mp_obj_t struct_unpack_from(size_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(struct_unpack_from_obj, 2, 3, struct_unpack_from); // This function assumes there is enough room in p to store all the values -STATIC void struct_pack_into_internal(mp_obj_t fmt_in, byte *p, size_t n_args, const mp_obj_t *args) { +static void struct_pack_into_internal(mp_obj_t fmt_in, byte *p, size_t n_args, const mp_obj_t *args) { const char *fmt = mp_obj_str_get_str(fmt_in); char fmt_type = get_fmt_type(&fmt); @@ -219,7 +219,7 @@ STATIC void struct_pack_into_internal(mp_obj_t fmt_in, byte *p, size_t n_args, c } } -STATIC mp_obj_t struct_pack(size_t n_args, const mp_obj_t *args) { +static mp_obj_t struct_pack(size_t n_args, const mp_obj_t *args) { // TODO: "The arguments must match the values required by the format exactly." mp_int_t size = MP_OBJ_SMALL_INT_VALUE(struct_calcsize(args[0])); vstr_t vstr; @@ -231,7 +231,7 @@ STATIC mp_obj_t struct_pack(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(struct_pack_obj, 1, MP_OBJ_FUN_ARGS_MAX, struct_pack); -STATIC mp_obj_t struct_pack_into(size_t n_args, const mp_obj_t *args) { +static mp_obj_t struct_pack_into(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_WRITE); mp_int_t offset = mp_obj_get_int(args[2]); @@ -257,7 +257,7 @@ STATIC mp_obj_t struct_pack_into(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(struct_pack_into_obj, 3, MP_OBJ_FUN_ARGS_MAX, struct_pack_into); -STATIC const mp_rom_map_elem_t mp_module_struct_globals_table[] = { +static const mp_rom_map_elem_t mp_module_struct_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_struct) }, { MP_ROM_QSTR(MP_QSTR_calcsize), MP_ROM_PTR(&struct_calcsize_obj) }, { MP_ROM_QSTR(MP_QSTR_pack), MP_ROM_PTR(&struct_pack_obj) }, @@ -266,7 +266,7 @@ STATIC const mp_rom_map_elem_t mp_module_struct_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_unpack_from), MP_ROM_PTR(&struct_unpack_from_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_struct_globals, mp_module_struct_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_struct_globals, mp_module_struct_globals_table); const mp_obj_module_t mp_module_struct = { .base = { &mp_type_module }, diff --git a/py/modsys.c b/py/modsys.c index 2af81046f483b..e90ea2233a732 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -56,15 +56,15 @@ const mp_print_t mp_sys_stdout_print = {&mp_sys_stdout_obj, mp_stream_write_adap #endif // version - Python language version that this implementation conforms to, as a string -STATIC const MP_DEFINE_STR_OBJ(mp_sys_version_obj, "3.4.0; " MICROPY_BANNER_NAME_AND_VERSION); +static const MP_DEFINE_STR_OBJ(mp_sys_version_obj, "3.4.0; " MICROPY_BANNER_NAME_AND_VERSION); // version_info - Python language version that this implementation conforms to, as a tuple of ints // TODO: CPython is now at 5-element array (major, minor, micro, releaselevel, serial), but save 2 els so far... -STATIC const mp_rom_obj_tuple_t mp_sys_version_info_obj = {{&mp_type_tuple}, 3, {MP_ROM_INT(3), MP_ROM_INT(4), MP_ROM_INT(0)}}; +static const mp_rom_obj_tuple_t mp_sys_version_info_obj = {{&mp_type_tuple}, 3, {MP_ROM_INT(3), MP_ROM_INT(4), MP_ROM_INT(0)}}; // sys.implementation object // this holds the MicroPython version -STATIC const mp_rom_obj_tuple_t mp_sys_implementation_version_info_obj = { +static const mp_rom_obj_tuple_t mp_sys_implementation_version_info_obj = { {&mp_type_tuple}, 4, { @@ -78,7 +78,7 @@ STATIC const mp_rom_obj_tuple_t mp_sys_implementation_version_info_obj = { #endif } }; -STATIC const MP_DEFINE_STR_OBJ(mp_sys_implementation_machine_obj, MICROPY_BANNER_MACHINE); +static const MP_DEFINE_STR_OBJ(mp_sys_implementation_machine_obj, MICROPY_BANNER_MACHINE); #define SYS_IMPLEMENTATION_ELEMS_BASE \ MP_ROM_QSTR(MP_QSTR_micropython), \ MP_ROM_PTR(&mp_sys_implementation_version_info_obj), \ @@ -99,7 +99,7 @@ STATIC const MP_DEFINE_STR_OBJ(mp_sys_implementation_machine_obj, MICROPY_BANNER #define SYS_IMPLEMENTATION_ELEMS__V2 #endif -STATIC const qstr impl_fields[] = { +static const qstr impl_fields[] = { MP_QSTR_name, MP_QSTR_version, MP_QSTR__machine, @@ -110,7 +110,7 @@ STATIC const qstr impl_fields[] = { MP_QSTR__v2, #endif }; -STATIC MP_DEFINE_ATTRTUPLE( +static MP_DEFINE_ATTRTUPLE( mp_sys_implementation_obj, impl_fields, 3 + MICROPY_PERSISTENT_CODE_LOAD + MICROPY_PREVIEW_VERSION_2, @@ -119,7 +119,7 @@ STATIC MP_DEFINE_ATTRTUPLE( SYS_IMPLEMENTATION_ELEMS__V2 ); #else -STATIC const mp_rom_obj_tuple_t mp_sys_implementation_obj = { +static const mp_rom_obj_tuple_t mp_sys_implementation_obj = { {&mp_type_tuple}, 3 + MICROPY_PERSISTENT_CODE_LOAD, // Do not include SYS_IMPLEMENTATION_ELEMS__V2 because @@ -138,7 +138,7 @@ STATIC const mp_rom_obj_tuple_t mp_sys_implementation_obj = { #ifdef MICROPY_PY_SYS_PLATFORM // platform - the platform that MicroPython is running on -STATIC const MP_DEFINE_STR_OBJ(mp_sys_platform_obj, MICROPY_PY_SYS_PLATFORM); +static const MP_DEFINE_STR_OBJ(mp_sys_platform_obj, MICROPY_PY_SYS_PLATFORM); #endif #ifdef MICROPY_PY_SYS_EXECUTABLE @@ -152,7 +152,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_intern_obj, mp_obj_str_intern_checked); #endif // exit([retval]): raise SystemExit, with optional argument given to the exception -STATIC mp_obj_t mp_sys_exit(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_sys_exit(size_t n_args, const mp_obj_t *args) { if (n_args == 0) { mp_raise_type(&mp_type_SystemExit); } else { @@ -161,7 +161,7 @@ STATIC mp_obj_t mp_sys_exit(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_exit_obj, 0, 1, mp_sys_exit); -STATIC mp_obj_t mp_sys_print_exception(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_sys_print_exception(size_t n_args, const mp_obj_t *args) { #if MICROPY_PY_IO && MICROPY_PY_SYS_STDFILES void *stream_obj = &mp_sys_stdout_obj; if (n_args > 1) { @@ -181,7 +181,7 @@ STATIC mp_obj_t mp_sys_print_exception(size_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_print_exception_obj, 1, 2, mp_sys_print_exception); #if MICROPY_PY_SYS_EXC_INFO -STATIC mp_obj_t mp_sys_exc_info(void) { +static mp_obj_t mp_sys_exc_info(void) { mp_obj_t cur_exc = MP_OBJ_FROM_PTR(MP_STATE_VM(cur_exception)); mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL)); @@ -201,25 +201,25 @@ MP_DEFINE_CONST_FUN_OBJ_0(mp_sys_exc_info_obj, mp_sys_exc_info); #endif #if MICROPY_PY_SYS_GETSIZEOF -STATIC mp_obj_t mp_sys_getsizeof(mp_obj_t obj) { +static mp_obj_t mp_sys_getsizeof(mp_obj_t obj) { return mp_unary_op(MP_UNARY_OP_SIZEOF, obj); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_getsizeof_obj, mp_sys_getsizeof); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_getsizeof_obj, mp_sys_getsizeof); #endif #if MICROPY_PY_SYS_ATEXIT // atexit(callback): Callback is called when sys.exit is called. -STATIC mp_obj_t mp_sys_atexit(mp_obj_t obj) { +static mp_obj_t mp_sys_atexit(mp_obj_t obj) { mp_obj_t old = MP_STATE_VM(sys_exitfunc); MP_STATE_VM(sys_exitfunc) = obj; return old; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_atexit_obj, mp_sys_atexit); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_atexit_obj, mp_sys_atexit); #endif #if MICROPY_PY_SYS_SETTRACE // settrace(tracefunc): Set the system's trace function. -STATIC mp_obj_t mp_sys_settrace(mp_obj_t obj) { +static mp_obj_t mp_sys_settrace(mp_obj_t obj) { return mp_prof_settrace(obj); } MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_settrace_obj, mp_sys_settrace); @@ -243,7 +243,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_settrace_obj, mp_sys_settrace); #if MICROPY_PY_SYS_ATTR_DELEGATION // Must be kept in sync with the enum at the top of mpstate.h. -STATIC const uint16_t sys_mutable_keys[] = { +static const uint16_t sys_mutable_keys[] = { #if MICROPY_PY_SYS_PATH // Code should access this (as an mp_obj_t) for use with e.g. // mp_obj_list_append by using the `mp_sys_path` macro defined in runtime.h. @@ -266,7 +266,7 @@ void mp_module_sys_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } #endif -STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = { +static const mp_rom_map_elem_t mp_module_sys_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sys) }, #if MICROPY_PY_SYS_ARGV @@ -339,7 +339,7 @@ STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_sys_globals, mp_module_sys_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_sys_globals, mp_module_sys_globals_table); const mp_obj_module_t mp_module_sys = { .base = { &mp_type_module }, diff --git a/py/modthread.c b/py/modthread.c index 9fc20570be1f0..2826fadeaa6b4 100644 --- a/py/modthread.c +++ b/py/modthread.c @@ -45,7 +45,7 @@ /****************************************************************/ // Lock object -STATIC const mp_obj_type_t mp_type_thread_lock; +static const mp_obj_type_t mp_type_thread_lock; typedef struct _mp_obj_thread_lock_t { mp_obj_base_t base; @@ -53,14 +53,14 @@ typedef struct _mp_obj_thread_lock_t { volatile bool locked; } mp_obj_thread_lock_t; -STATIC mp_obj_thread_lock_t *mp_obj_new_thread_lock(void) { +static mp_obj_thread_lock_t *mp_obj_new_thread_lock(void) { mp_obj_thread_lock_t *self = mp_obj_malloc(mp_obj_thread_lock_t, &mp_type_thread_lock); mp_thread_mutex_init(&self->mutex); self->locked = false; return self; } -STATIC mp_obj_t thread_lock_acquire(size_t n_args, const mp_obj_t *args) { +static mp_obj_t thread_lock_acquire(size_t n_args, const mp_obj_t *args) { mp_obj_thread_lock_t *self = MP_OBJ_TO_PTR(args[0]); bool wait = true; if (n_args > 1) { @@ -79,9 +79,9 @@ STATIC mp_obj_t thread_lock_acquire(size_t n_args, const mp_obj_t *args) { mp_raise_OSError(-ret); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(thread_lock_acquire_obj, 1, 3, thread_lock_acquire); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(thread_lock_acquire_obj, 1, 3, thread_lock_acquire); -STATIC mp_obj_t thread_lock_release(mp_obj_t self_in) { +static mp_obj_t thread_lock_release(mp_obj_t self_in) { mp_obj_thread_lock_t *self = MP_OBJ_TO_PTR(self_in); if (!self->locked) { mp_raise_msg(&mp_type_RuntimeError, NULL); @@ -92,21 +92,21 @@ STATIC mp_obj_t thread_lock_release(mp_obj_t self_in) { MP_THREAD_GIL_ENTER(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(thread_lock_release_obj, thread_lock_release); +static MP_DEFINE_CONST_FUN_OBJ_1(thread_lock_release_obj, thread_lock_release); -STATIC mp_obj_t thread_lock_locked(mp_obj_t self_in) { +static mp_obj_t thread_lock_locked(mp_obj_t self_in) { mp_obj_thread_lock_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_bool(self->locked); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(thread_lock_locked_obj, thread_lock_locked); +static MP_DEFINE_CONST_FUN_OBJ_1(thread_lock_locked_obj, thread_lock_locked); -STATIC mp_obj_t thread_lock___exit__(size_t n_args, const mp_obj_t *args) { +static mp_obj_t thread_lock___exit__(size_t n_args, const mp_obj_t *args) { (void)n_args; // unused return thread_lock_release(args[0]); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(thread_lock___exit___obj, 4, 4, thread_lock___exit__); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(thread_lock___exit___obj, 4, 4, thread_lock___exit__); -STATIC const mp_rom_map_elem_t thread_lock_locals_dict_table[] = { +static const mp_rom_map_elem_t thread_lock_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_acquire), MP_ROM_PTR(&thread_lock_acquire_obj) }, { MP_ROM_QSTR(MP_QSTR_release), MP_ROM_PTR(&thread_lock_release_obj) }, { MP_ROM_QSTR(MP_QSTR_locked), MP_ROM_PTR(&thread_lock_locked_obj) }, @@ -114,9 +114,9 @@ STATIC const mp_rom_map_elem_t thread_lock_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&thread_lock___exit___obj) }, }; -STATIC MP_DEFINE_CONST_DICT(thread_lock_locals_dict, thread_lock_locals_dict_table); +static MP_DEFINE_CONST_DICT(thread_lock_locals_dict, thread_lock_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_thread_lock, MP_QSTR_lock, MP_TYPE_FLAG_NONE, @@ -126,14 +126,14 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( /****************************************************************/ // _thread module -STATIC size_t thread_stack_size = 0; +static size_t thread_stack_size = 0; -STATIC mp_obj_t mod_thread_get_ident(void) { +static mp_obj_t mod_thread_get_ident(void) { return mp_obj_new_int_from_uint(mp_thread_get_id()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_thread_get_ident_obj, mod_thread_get_ident); +static MP_DEFINE_CONST_FUN_OBJ_0(mod_thread_get_ident_obj, mod_thread_get_ident); -STATIC mp_obj_t mod_thread_stack_size(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_thread_stack_size(size_t n_args, const mp_obj_t *args) { mp_obj_t ret = mp_obj_new_int_from_uint(thread_stack_size); if (n_args == 0) { thread_stack_size = 0; @@ -142,7 +142,7 @@ STATIC mp_obj_t mod_thread_stack_size(size_t n_args, const mp_obj_t *args) { } return ret; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_thread_stack_size_obj, 0, 1, mod_thread_stack_size); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_thread_stack_size_obj, 0, 1, mod_thread_stack_size); typedef struct _thread_entry_args_t { mp_obj_dict_t *dict_locals; @@ -154,7 +154,7 @@ typedef struct _thread_entry_args_t { mp_obj_t args[]; } thread_entry_args_t; -STATIC void *thread_entry(void *args_in) { +static void *thread_entry(void *args_in) { // Execution begins here for a new thread. We do not have the GIL. thread_entry_args_t *args = (thread_entry_args_t *)args_in; @@ -207,7 +207,7 @@ STATIC void *thread_entry(void *args_in) { return NULL; } -STATIC mp_obj_t mod_thread_start_new_thread(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_thread_start_new_thread(size_t n_args, const mp_obj_t *args) { // This structure holds the Python function and arguments for thread entry. // We copy all arguments into this structure to keep ownership of them. // We must be very careful about root pointers because this pointer may @@ -258,19 +258,19 @@ STATIC mp_obj_t mod_thread_start_new_thread(size_t n_args, const mp_obj_t *args) // spawn the thread! return mp_obj_new_int_from_uint(mp_thread_create(thread_entry, th_args, &th_args->stack_size)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_thread_start_new_thread_obj, 2, 3, mod_thread_start_new_thread); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_thread_start_new_thread_obj, 2, 3, mod_thread_start_new_thread); -STATIC mp_obj_t mod_thread_exit(void) { +static mp_obj_t mod_thread_exit(void) { mp_raise_type(&mp_type_SystemExit); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_thread_exit_obj, mod_thread_exit); +static MP_DEFINE_CONST_FUN_OBJ_0(mod_thread_exit_obj, mod_thread_exit); -STATIC mp_obj_t mod_thread_allocate_lock(void) { +static mp_obj_t mod_thread_allocate_lock(void) { return MP_OBJ_FROM_PTR(mp_obj_new_thread_lock()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_thread_allocate_lock_obj, mod_thread_allocate_lock); +static MP_DEFINE_CONST_FUN_OBJ_0(mod_thread_allocate_lock_obj, mod_thread_allocate_lock); -STATIC const mp_rom_map_elem_t mp_module_thread_globals_table[] = { +static const mp_rom_map_elem_t mp_module_thread_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__thread) }, { MP_ROM_QSTR(MP_QSTR_LockType), MP_ROM_PTR(&mp_type_thread_lock) }, { MP_ROM_QSTR(MP_QSTR_get_ident), MP_ROM_PTR(&mod_thread_get_ident_obj) }, @@ -280,7 +280,7 @@ STATIC const mp_rom_map_elem_t mp_module_thread_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_allocate_lock), MP_ROM_PTR(&mod_thread_allocate_lock_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_thread_globals, mp_module_thread_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_thread_globals, mp_module_thread_globals_table); const mp_obj_module_t mp_module_thread = { .base = { &mp_type_module }, diff --git a/py/mpconfig.h b/py/mpconfig.h index e7b72c642274f..90f8e592bfe8b 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1862,12 +1862,6 @@ typedef double mp_float_t; #endif #endif -// Allow to override static modifier for global objects, e.g. to use with -// object code analysis tools which don't support static symbols. -#ifndef STATIC -#define STATIC static -#endif - // Number of bytes in an object word: mp_obj_t, mp_uint_t, mp_uint_t #ifndef MP_BYTES_PER_OBJ_WORD #define MP_BYTES_PER_OBJ_WORD (sizeof(mp_uint_t)) diff --git a/py/mpprint.c b/py/mpprint.c index 3218bd2f4dcf8..291e4145ff0cd 100644 --- a/py/mpprint.c +++ b/py/mpprint.c @@ -43,7 +43,7 @@ static const char pad_spaces[] = " "; static const char pad_zeroes[] = "0000000000000000"; -STATIC void plat_print_strn(void *env, const char *str, size_t len) { +static void plat_print_strn(void *env, const char *str, size_t len) { (void)env; MP_PLAT_PRINT_STRN(str, len); } @@ -127,7 +127,7 @@ int mp_print_strn(const mp_print_t *print, const char *str, size_t len, int flag // This function is used exclusively by mp_vprintf to format ints. // It needs to be a separate function to mp_print_mp_int, since converting to a mp_int looses the MSB. -STATIC int mp_print_int(const mp_print_t *print, mp_uint_t x, int sgn, int base, int base_char, int flags, char fill, int width) { +static int mp_print_int(const mp_print_t *print, mp_uint_t x, int sgn, int base, int base_char, int flags, char fill, int width) { char sign = 0; if (sgn) { if ((mp_int_t)x < 0) { diff --git a/py/mpz.c b/py/mpz.c index b61997e2fd4ed..502d4e1c138f0 100644 --- a/py/mpz.c +++ b/py/mpz.c @@ -49,7 +49,7 @@ Definition of normalise: ? */ -STATIC size_t mpn_remove_trailing_zeros(mpz_dig_t *oidig, mpz_dig_t *idig) { +static size_t mpn_remove_trailing_zeros(mpz_dig_t *oidig, mpz_dig_t *idig) { for (--idig; idig >= oidig && *idig == 0; --idig) { } return idig + 1 - oidig; @@ -59,7 +59,7 @@ STATIC size_t mpn_remove_trailing_zeros(mpz_dig_t *oidig, mpz_dig_t *idig) { returns sign(i - j) assumes i, j are normalised */ -STATIC int mpn_cmp(const mpz_dig_t *idig, size_t ilen, const mpz_dig_t *jdig, size_t jlen) { +static int mpn_cmp(const mpz_dig_t *idig, size_t ilen, const mpz_dig_t *jdig, size_t jlen) { if (ilen < jlen) { return -1; } @@ -85,7 +85,7 @@ STATIC int mpn_cmp(const mpz_dig_t *idig, size_t ilen, const mpz_dig_t *jdig, si assumes enough memory in i; assumes normalised j; assumes n > 0 can have i, j pointing to same memory */ -STATIC size_t mpn_shl(mpz_dig_t *idig, mpz_dig_t *jdig, size_t jlen, mp_uint_t n) { +static size_t mpn_shl(mpz_dig_t *idig, mpz_dig_t *jdig, size_t jlen, mp_uint_t n) { mp_uint_t n_whole = (n + DIG_SIZE - 1) / DIG_SIZE; mp_uint_t n_part = n % DIG_SIZE; if (n_part == 0) { @@ -124,7 +124,7 @@ STATIC size_t mpn_shl(mpz_dig_t *idig, mpz_dig_t *jdig, size_t jlen, mp_uint_t n assumes enough memory in i; assumes normalised j; assumes n > 0 can have i, j pointing to same memory */ -STATIC size_t mpn_shr(mpz_dig_t *idig, mpz_dig_t *jdig, size_t jlen, mp_uint_t n) { +static size_t mpn_shr(mpz_dig_t *idig, mpz_dig_t *jdig, size_t jlen, mp_uint_t n) { mp_uint_t n_whole = n / DIG_SIZE; mp_uint_t n_part = n % DIG_SIZE; @@ -156,7 +156,7 @@ STATIC size_t mpn_shr(mpz_dig_t *idig, mpz_dig_t *jdig, size_t jlen, mp_uint_t n assumes enough memory in i; assumes normalised j, k; assumes jlen >= klen can have i, j, k pointing to same memory */ -STATIC size_t mpn_add(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen) { +static size_t mpn_add(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen) { mpz_dig_t *oidig = idig; mpz_dbl_dig_t carry = 0; @@ -186,7 +186,7 @@ STATIC size_t mpn_add(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const assumes enough memory in i; assumes normalised j, k; assumes j >= k can have i, j, k pointing to same memory */ -STATIC size_t mpn_sub(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen) { +static size_t mpn_sub(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen) { mpz_dig_t *oidig = idig; mpz_dbl_dig_signed_t borrow = 0; @@ -214,7 +214,7 @@ STATIC size_t mpn_sub(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const assumes enough memory in i; assumes normalised j, k; assumes jlen >= klen (jlen argument not needed) can have i, j, k pointing to same memory */ -STATIC size_t mpn_and(mpz_dig_t *idig, const mpz_dig_t *jdig, const mpz_dig_t *kdig, size_t klen) { +static size_t mpn_and(mpz_dig_t *idig, const mpz_dig_t *jdig, const mpz_dig_t *kdig, size_t klen) { mpz_dig_t *oidig = idig; for (; klen > 0; --klen, ++idig, ++jdig, ++kdig) { @@ -235,7 +235,7 @@ STATIC size_t mpn_and(mpz_dig_t *idig, const mpz_dig_t *jdig, const mpz_dig_t *k assumes enough memory in i; assumes normalised j, k; assumes length j >= length k can have i, j, k pointing to same memory */ -STATIC size_t mpn_and_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen, +static size_t mpn_and_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen, mpz_dbl_dig_t carryi, mpz_dbl_dig_t carryj, mpz_dbl_dig_t carryk) { mpz_dig_t *oidig = idig; mpz_dig_t imask = (0 == carryi) ? 0 : DIG_MASK; @@ -266,7 +266,7 @@ STATIC size_t mpn_and_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, c assumes enough memory in i; assumes normalised j, k; assumes jlen >= klen can have i, j, k pointing to same memory */ -STATIC size_t mpn_or(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen) { +static size_t mpn_or(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen) { mpz_dig_t *oidig = idig; jlen -= klen; @@ -296,7 +296,7 @@ STATIC size_t mpn_or(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const #if MICROPY_OPT_MPZ_BITWISE -STATIC size_t mpn_or_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen, +static size_t mpn_or_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen, mpz_dbl_dig_t carryj, mpz_dbl_dig_t carryk) { mpz_dig_t *oidig = idig; mpz_dbl_dig_t carryi = 1; @@ -326,7 +326,7 @@ STATIC size_t mpn_or_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, co #else -STATIC size_t mpn_or_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen, +static size_t mpn_or_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen, mpz_dbl_dig_t carryi, mpz_dbl_dig_t carryj, mpz_dbl_dig_t carryk) { mpz_dig_t *oidig = idig; mpz_dig_t imask = (0 == carryi) ? 0 : DIG_MASK; @@ -358,7 +358,7 @@ STATIC size_t mpn_or_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, co assumes enough memory in i; assumes normalised j, k; assumes jlen >= klen can have i, j, k pointing to same memory */ -STATIC size_t mpn_xor(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen) { +static size_t mpn_xor(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen) { mpz_dig_t *oidig = idig; jlen -= klen; @@ -385,7 +385,7 @@ STATIC size_t mpn_xor(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const assumes enough memory in i; assumes normalised j, k; assumes length j >= length k can have i, j, k pointing to same memory */ -STATIC size_t mpn_xor_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen, +static size_t mpn_xor_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen, mpz_dbl_dig_t carryi, mpz_dbl_dig_t carryj, mpz_dbl_dig_t carryk) { mpz_dig_t *oidig = idig; @@ -410,7 +410,7 @@ STATIC size_t mpn_xor_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, c returns number of digits in i assumes enough memory in i; assumes normalised i; assumes dmul != 0 */ -STATIC size_t mpn_mul_dig_add_dig(mpz_dig_t *idig, size_t ilen, mpz_dig_t dmul, mpz_dig_t dadd) { +static size_t mpn_mul_dig_add_dig(mpz_dig_t *idig, size_t ilen, mpz_dig_t dmul, mpz_dig_t dadd) { mpz_dig_t *oidig = idig; mpz_dbl_dig_t carry = dadd; @@ -432,7 +432,7 @@ STATIC size_t mpn_mul_dig_add_dig(mpz_dig_t *idig, size_t ilen, mpz_dig_t dmul, assumes enough memory in i; assumes i is zeroed; assumes normalised j, k can have j, k point to same memory */ -STATIC size_t mpn_mul(mpz_dig_t *idig, mpz_dig_t *jdig, size_t jlen, mpz_dig_t *kdig, size_t klen) { +static size_t mpn_mul(mpz_dig_t *idig, mpz_dig_t *jdig, size_t jlen, mpz_dig_t *kdig, size_t klen) { mpz_dig_t *oidig = idig; size_t ilen = 0; @@ -463,7 +463,7 @@ STATIC size_t mpn_mul(mpz_dig_t *idig, mpz_dig_t *jdig, size_t jlen, mpz_dig_t * assumes quo_dig has enough memory (as many digits as num) assumes quo_dig is filled with zeros */ -STATIC void mpn_div(mpz_dig_t *num_dig, size_t *num_len, const mpz_dig_t *den_dig, size_t den_len, mpz_dig_t *quo_dig, size_t *quo_len) { +static void mpn_div(mpz_dig_t *num_dig, size_t *num_len, const mpz_dig_t *den_dig, size_t den_len, mpz_dig_t *quo_dig, size_t *quo_len) { mpz_dig_t *orig_num_dig = num_dig; mpz_dig_t *orig_quo_dig = quo_dig; mpz_dig_t norm_shift = 0; @@ -668,14 +668,14 @@ mpz_t *mpz_from_str(const char *str, size_t len, bool neg, unsigned int base) { } #endif -STATIC void mpz_free(mpz_t *z) { +static void mpz_free(mpz_t *z) { if (z != NULL) { m_del(mpz_dig_t, z->dig, z->alloc); m_del_obj(mpz_t, z); } } -STATIC void mpz_need_dig(mpz_t *z, size_t need) { +static void mpz_need_dig(mpz_t *z, size_t need) { if (need < MIN_ALLOC) { need = MIN_ALLOC; } @@ -689,7 +689,7 @@ STATIC void mpz_need_dig(mpz_t *z, size_t need) { } } -STATIC mpz_t *mpz_clone(const mpz_t *src) { +static mpz_t *mpz_clone(const mpz_t *src) { assert(src->alloc != 0); mpz_t *z = m_new_obj(mpz_t); z->neg = src->neg; diff --git a/py/nativeglue.c b/py/nativeglue.c index 074b1206ee5f5..4cd090c0a2a78 100644 --- a/py/nativeglue.c +++ b/py/nativeglue.c @@ -139,7 +139,7 @@ mp_obj_t mp_obj_new_slice(mp_obj_t ostart, mp_obj_t ostop, mp_obj_t ostep) { } #endif -STATIC mp_obj_dict_t *mp_native_swap_globals(mp_obj_dict_t *new_globals) { +static mp_obj_dict_t *mp_native_swap_globals(mp_obj_dict_t *new_globals) { if (new_globals == NULL) { // Globals were the originally the same so don't restore them return NULL; @@ -155,20 +155,20 @@ STATIC mp_obj_dict_t *mp_native_swap_globals(mp_obj_dict_t *new_globals) { // wrapper that accepts n_args and n_kw in one argument // (native emitter can only pass at most 3 arguments to a function) -STATIC mp_obj_t mp_native_call_function_n_kw(mp_obj_t fun_in, size_t n_args_kw, const mp_obj_t *args) { +static mp_obj_t mp_native_call_function_n_kw(mp_obj_t fun_in, size_t n_args_kw, const mp_obj_t *args) { return mp_call_function_n_kw(fun_in, n_args_kw & 0xff, (n_args_kw >> 8) & 0xff, args); } // wrapper that makes raise obj and raises it // END_FINALLY opcode requires that we don't raise if o==None -STATIC void mp_native_raise(mp_obj_t o) { +static void mp_native_raise(mp_obj_t o) { if (o != MP_OBJ_NULL && o != mp_const_none) { nlr_raise(mp_make_raise_obj(o)); } } // wrapper that handles iterator buffer -STATIC mp_obj_t mp_native_getiter(mp_obj_t obj, mp_obj_iter_buf_t *iter) { +static mp_obj_t mp_native_getiter(mp_obj_t obj, mp_obj_iter_buf_t *iter) { if (iter == NULL) { return mp_getiter(obj, NULL); } else { @@ -183,7 +183,7 @@ STATIC mp_obj_t mp_native_getiter(mp_obj_t obj, mp_obj_iter_buf_t *iter) { } // wrapper that handles iterator buffer -STATIC mp_obj_t mp_native_iternext(mp_obj_iter_buf_t *iter) { +static mp_obj_t mp_native_iternext(mp_obj_iter_buf_t *iter) { mp_obj_t obj; if (iter->base.type == MP_OBJ_NULL) { obj = iter->buf[0]; @@ -193,7 +193,7 @@ STATIC mp_obj_t mp_native_iternext(mp_obj_iter_buf_t *iter) { return mp_iternext(obj); } -STATIC bool mp_native_yield_from(mp_obj_t gen, mp_obj_t send_value, mp_obj_t *ret_value) { +static bool mp_native_yield_from(mp_obj_t gen, mp_obj_t send_value, mp_obj_t *ret_value) { mp_vm_return_kind_t ret_kind; nlr_buf_t nlr_buf; mp_obj_t throw_value = *ret_value; @@ -231,22 +231,22 @@ STATIC bool mp_native_yield_from(mp_obj_t gen, mp_obj_t send_value, mp_obj_t *re #if !MICROPY_PY_BUILTINS_FLOAT -STATIC mp_obj_t mp_obj_new_float_from_f(float f) { +static mp_obj_t mp_obj_new_float_from_f(float f) { (void)f; mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("float unsupported")); } -STATIC mp_obj_t mp_obj_new_float_from_d(double d) { +static mp_obj_t mp_obj_new_float_from_d(double d) { (void)d; mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("float unsupported")); } -STATIC float mp_obj_get_float_to_f(mp_obj_t o) { +static float mp_obj_get_float_to_f(mp_obj_t o) { (void)o; mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("float unsupported")); } -STATIC double mp_obj_get_float_to_d(mp_obj_t o) { +static double mp_obj_get_float_to_d(mp_obj_t o) { (void)o; mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("float unsupported")); } diff --git a/py/objarray.c b/py/objarray.c index a3adb255e8381..1fff234822521 100644 --- a/py/objarray.c +++ b/py/objarray.c @@ -61,16 +61,16 @@ // so not defined to catch errors #endif -STATIC mp_obj_t array_iterator_new(mp_obj_t array_in, mp_obj_iter_buf_t *iter_buf); -STATIC mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg); -STATIC mp_obj_t array_extend(mp_obj_t self_in, mp_obj_t arg_in); -STATIC mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags); +static mp_obj_t array_iterator_new(mp_obj_t array_in, mp_obj_iter_buf_t *iter_buf); +static mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg); +static mp_obj_t array_extend(mp_obj_t self_in, mp_obj_t arg_in); +static mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags); /******************************************************************************/ // array #if MICROPY_PY_BUILTINS_BYTEARRAY || MICROPY_PY_ARRAY -STATIC void array_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +static void array_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; mp_obj_array_t *o = MP_OBJ_TO_PTR(o_in); if (o->typecode == BYTEARRAY_TYPECODE) { @@ -94,7 +94,7 @@ STATIC void array_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t #endif #if MICROPY_PY_BUILTINS_BYTEARRAY || MICROPY_PY_ARRAY -STATIC mp_obj_array_t *array_new(char typecode, size_t n) { +static mp_obj_array_t *array_new(char typecode, size_t n) { int typecode_size = mp_binary_get_size('@', typecode, NULL); mp_obj_array_t *o = m_new_obj(mp_obj_array_t); #if MICROPY_PY_BUILTINS_BYTEARRAY && MICROPY_PY_ARRAY @@ -113,7 +113,7 @@ STATIC mp_obj_array_t *array_new(char typecode, size_t n) { #endif #if MICROPY_PY_BUILTINS_BYTEARRAY || MICROPY_PY_ARRAY -STATIC mp_obj_t array_construct(char typecode, mp_obj_t initializer) { +static mp_obj_t array_construct(char typecode, mp_obj_t initializer) { // bytearrays can be raw-initialised from anything with the buffer protocol // other arrays can only be raw-initialised from bytes and bytearray objects mp_buffer_info_t bufinfo; @@ -159,7 +159,7 @@ STATIC mp_obj_t array_construct(char typecode, mp_obj_t initializer) { #endif #if MICROPY_PY_ARRAY -STATIC mp_obj_t array_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t array_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; mp_arg_check_num(n_args, n_kw, 1, 2, false); @@ -177,7 +177,7 @@ STATIC mp_obj_t array_make_new(const mp_obj_type_t *type_in, size_t n_args, size #endif #if MICROPY_PY_BUILTINS_BYTEARRAY -STATIC mp_obj_t bytearray_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t bytearray_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; // Can take 2nd/3rd arg if constructs from str mp_arg_check_num(n_args, n_kw, 0, 3, false); @@ -214,7 +214,7 @@ mp_obj_t mp_obj_new_memoryview(byte typecode, size_t nitems, void *items) { return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t memoryview_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t memoryview_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; // TODO possibly allow memoryview constructor to take start/stop so that one @@ -246,7 +246,7 @@ STATIC mp_obj_t memoryview_make_new(const mp_obj_type_t *type_in, size_t n_args, } #if MICROPY_PY_BUILTINS_MEMORYVIEW_ITEMSIZE -STATIC void memoryview_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void memoryview_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] != MP_OBJ_NULL) { return; } @@ -265,7 +265,7 @@ STATIC void memoryview_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { #endif -STATIC mp_obj_t array_unary_op(mp_unary_op_t op, mp_obj_t o_in) { +static mp_obj_t array_unary_op(mp_unary_op_t op, mp_obj_t o_in) { mp_obj_array_t *o = MP_OBJ_TO_PTR(o_in); switch (op) { case MP_UNARY_OP_BOOL: @@ -277,7 +277,7 @@ STATIC mp_obj_t array_unary_op(mp_unary_op_t op, mp_obj_t o_in) { } } -STATIC int typecode_for_comparison(int typecode, bool *is_unsigned) { +static int typecode_for_comparison(int typecode, bool *is_unsigned) { if (typecode == BYTEARRAY_TYPECODE) { typecode = 'B'; } @@ -288,7 +288,7 @@ STATIC int typecode_for_comparison(int typecode, bool *is_unsigned) { return typecode; } -STATIC mp_obj_t array_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { +static mp_obj_t array_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { mp_obj_array_t *lhs = MP_OBJ_TO_PTR(lhs_in); switch (op) { case MP_BINARY_OP_ADD: { @@ -383,7 +383,7 @@ STATIC mp_obj_t array_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs } #if MICROPY_PY_BUILTINS_BYTEARRAY || MICROPY_PY_ARRAY -STATIC mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg) { // self is not a memoryview, so we don't need to use (& TYPECODE_MASK) assert((MICROPY_PY_BUILTINS_BYTEARRAY && mp_obj_is_type(self_in, &mp_type_bytearray)) || (MICROPY_PY_ARRAY && mp_obj_is_type(self_in, &mp_type_array))); @@ -404,7 +404,7 @@ STATIC mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg) { } MP_DEFINE_CONST_FUN_OBJ_2(mp_obj_array_append_obj, array_append); -STATIC mp_obj_t array_extend(mp_obj_t self_in, mp_obj_t arg_in) { +static mp_obj_t array_extend(mp_obj_t self_in, mp_obj_t arg_in) { // self is not a memoryview, so we don't need to use (& TYPECODE_MASK) assert((MICROPY_PY_BUILTINS_BYTEARRAY && mp_obj_is_type(self_in, &mp_type_bytearray)) || (MICROPY_PY_ARRAY && mp_obj_is_type(self_in, &mp_type_array))); @@ -437,7 +437,7 @@ STATIC mp_obj_t array_extend(mp_obj_t self_in, mp_obj_t arg_in) { MP_DEFINE_CONST_FUN_OBJ_2(mp_obj_array_extend_obj, array_extend); #endif -STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) { +static mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) { if (value == MP_OBJ_NULL) { // delete item // TODO implement @@ -568,7 +568,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value } } -STATIC mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { +static mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { mp_obj_array_t *o = MP_OBJ_TO_PTR(o_in); size_t sz = mp_binary_get_size('@', o->typecode & TYPECODE_MASK, NULL); bufinfo->buf = o->items; @@ -682,7 +682,7 @@ typedef struct _mp_obj_array_it_t { size_t cur; } mp_obj_array_it_t; -STATIC mp_obj_t array_it_iternext(mp_obj_t self_in) { +static mp_obj_t array_it_iternext(mp_obj_t self_in) { mp_obj_array_it_t *self = MP_OBJ_TO_PTR(self_in); if (self->cur < self->array->len) { return mp_binary_get_val_array(self->array->typecode & TYPECODE_MASK, self->array->items, self->offset + self->cur++); @@ -691,14 +691,14 @@ STATIC mp_obj_t array_it_iternext(mp_obj_t self_in) { } } -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_array_it, MP_QSTR_iterator, MP_TYPE_FLAG_ITER_IS_ITERNEXT, iter, array_it_iternext ); -STATIC mp_obj_t array_iterator_new(mp_obj_t array_in, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t array_iterator_new(mp_obj_t array_in, mp_obj_iter_buf_t *iter_buf) { assert(sizeof(mp_obj_array_t) <= sizeof(mp_obj_iter_buf_t)); mp_obj_array_t *array = MP_OBJ_TO_PTR(array_in); mp_obj_array_it_t *o = (mp_obj_array_it_t *)iter_buf; diff --git a/py/objattrtuple.c b/py/objattrtuple.c index 1ec9499893236..1280e3308938e 100644 --- a/py/objattrtuple.c +++ b/py/objattrtuple.c @@ -30,7 +30,7 @@ // this helper function is used by collections.namedtuple #if !MICROPY_PY_COLLECTIONS -STATIC +static #endif void mp_obj_attrtuple_print_helper(const mp_print_t *print, const qstr *fields, mp_obj_tuple_t *o) { mp_print_str(print, "("); @@ -48,14 +48,14 @@ void mp_obj_attrtuple_print_helper(const mp_print_t *print, const qstr *fields, #if MICROPY_PY_ATTRTUPLE -STATIC void mp_obj_attrtuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +static void mp_obj_attrtuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; mp_obj_tuple_t *o = MP_OBJ_TO_PTR(o_in); const qstr *fields = (const qstr *)MP_OBJ_TO_PTR(o->items[o->len]); mp_obj_attrtuple_print_helper(print, fields, o); } -STATIC void mp_obj_attrtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void mp_obj_attrtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] == MP_OBJ_NULL) { // load attribute mp_obj_tuple_t *self = MP_OBJ_TO_PTR(self_in); diff --git a/py/objbool.c b/py/objbool.c index 96f0e60dd1765..5b3e3660e9510 100644 --- a/py/objbool.c +++ b/py/objbool.c @@ -43,7 +43,7 @@ typedef struct _mp_obj_bool_t { #endif -STATIC void bool_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void bool_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { bool value = BOOL_VALUE(self_in); if (MICROPY_PY_JSON && kind == PRINT_JSON) { if (value) { @@ -60,7 +60,7 @@ STATIC void bool_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_ } } -STATIC mp_obj_t bool_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t bool_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; mp_arg_check_num(n_args, n_kw, 0, 1, false); @@ -71,7 +71,7 @@ STATIC mp_obj_t bool_make_new(const mp_obj_type_t *type_in, size_t n_args, size_ } } -STATIC mp_obj_t bool_unary_op(mp_unary_op_t op, mp_obj_t o_in) { +static mp_obj_t bool_unary_op(mp_unary_op_t op, mp_obj_t o_in) { if (op == MP_UNARY_OP_LEN) { return MP_OBJ_NULL; } @@ -79,7 +79,7 @@ STATIC mp_obj_t bool_unary_op(mp_unary_op_t op, mp_obj_t o_in) { return mp_unary_op(op, MP_OBJ_NEW_SMALL_INT(value)); } -STATIC mp_obj_t bool_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { +static mp_obj_t bool_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { bool value = BOOL_VALUE(lhs_in); return mp_binary_op(op, MP_OBJ_NEW_SMALL_INT(value), rhs_in); } diff --git a/py/objboundmeth.c b/py/objboundmeth.c index b0be810c5c15e..e3503ff154a65 100644 --- a/py/objboundmeth.c +++ b/py/objboundmeth.c @@ -36,7 +36,7 @@ typedef struct _mp_obj_bound_meth_t { } mp_obj_bound_meth_t; #if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED -STATIC void bound_meth_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +static void bound_meth_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; mp_obj_bound_meth_t *o = MP_OBJ_TO_PTR(o_in); mp_printf(print, "meth, self->self, n_args, n_kw, args); } -STATIC mp_obj_t bound_meth_unary_op(mp_unary_op_t op, mp_obj_t self_in) { +static mp_obj_t bound_meth_unary_op(mp_unary_op_t op, mp_obj_t self_in) { mp_obj_bound_meth_t *self = MP_OBJ_TO_PTR(self_in); switch (op) { case MP_UNARY_OP_HASH: @@ -93,7 +93,7 @@ STATIC mp_obj_t bound_meth_unary_op(mp_unary_op_t op, mp_obj_t self_in) { } } -STATIC mp_obj_t bound_meth_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { +static mp_obj_t bound_meth_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { // The MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE flag is clear for this type, so if this // function is called with MP_BINARY_OP_EQUAL then lhs_in and rhs_in must have the // same type, which is mp_type_bound_meth. @@ -106,7 +106,7 @@ STATIC mp_obj_t bound_meth_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_ } #if MICROPY_PY_FUNCTION_ATTRS -STATIC void bound_meth_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void bound_meth_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] != MP_OBJ_NULL) { // not load attribute return; diff --git a/py/objcell.c b/py/objcell.c index 0a74e29d2064a..95966c7917cb7 100644 --- a/py/objcell.c +++ b/py/objcell.c @@ -27,7 +27,7 @@ #include "py/obj.h" #if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED -STATIC void cell_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +static void cell_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; mp_obj_cell_t *o = MP_OBJ_TO_PTR(o_in); mp_printf(print, "obj); @@ -46,7 +46,7 @@ STATIC void cell_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t k #define CELL_TYPE_PRINT #endif -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( // cell representation is just value in < > mp_type_cell, MP_QSTR_, MP_TYPE_FLAG_NONE CELL_TYPE_PRINT diff --git a/py/objclosure.c b/py/objclosure.c index 88109cc919642..3ba507b959382 100644 --- a/py/objclosure.c +++ b/py/objclosure.c @@ -36,7 +36,7 @@ typedef struct _mp_obj_closure_t { mp_obj_t closed[]; } mp_obj_closure_t; -STATIC mp_obj_t closure_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t closure_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_obj_closure_t *self = MP_OBJ_TO_PTR(self_in); // need to concatenate closed-over-vars and args @@ -60,7 +60,7 @@ STATIC mp_obj_t closure_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const } #if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED -STATIC void closure_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +static void closure_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; mp_obj_closure_t *o = MP_OBJ_TO_PTR(o_in); mp_print_str(print, "fun mp_obj_closure_t *o = MP_OBJ_TO_PTR(self_in); mp_load_method_maybe(o->fun, attr, dest); diff --git a/py/objcomplex.c b/py/objcomplex.c index ddd103eeb46e3..85b5852845737 100644 --- a/py/objcomplex.c +++ b/py/objcomplex.c @@ -42,7 +42,7 @@ typedef struct _mp_obj_complex_t { mp_float_t imag; } mp_obj_complex_t; -STATIC void complex_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +static void complex_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; mp_obj_complex_t *o = MP_OBJ_TO_PTR(o_in); #if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT @@ -70,7 +70,7 @@ STATIC void complex_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_ } } -STATIC mp_obj_t complex_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t complex_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; mp_arg_check_num(n_args, n_kw, 0, 2, false); @@ -115,7 +115,7 @@ STATIC mp_obj_t complex_make_new(const mp_obj_type_t *type_in, size_t n_args, si } } -STATIC mp_obj_t complex_unary_op(mp_unary_op_t op, mp_obj_t o_in) { +static mp_obj_t complex_unary_op(mp_unary_op_t op, mp_obj_t o_in) { mp_obj_complex_t *o = MP_OBJ_TO_PTR(o_in); switch (op) { case MP_UNARY_OP_BOOL: @@ -133,12 +133,12 @@ STATIC mp_obj_t complex_unary_op(mp_unary_op_t op, mp_obj_t o_in) { } } -STATIC mp_obj_t complex_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { +static mp_obj_t complex_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { mp_obj_complex_t *lhs = MP_OBJ_TO_PTR(lhs_in); return mp_obj_complex_binary_op(op, lhs->real, lhs->imag, rhs_in); } -STATIC void complex_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void complex_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] != MP_OBJ_NULL) { // not load attribute return; diff --git a/py/objdeque.c b/py/objdeque.c index 8b52b8d387303..68e1621793116 100644 --- a/py/objdeque.c +++ b/py/objdeque.c @@ -42,7 +42,7 @@ typedef struct _mp_obj_deque_t { #define FLAG_CHECK_OVERFLOW 1 } mp_obj_deque_t; -STATIC mp_obj_t deque_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t deque_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 2, 3, false); /* Initialization from existing sequence is not supported, so an empty @@ -69,7 +69,7 @@ STATIC mp_obj_t deque_make_new(const mp_obj_type_t *type, size_t n_args, size_t return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t deque_unary_op(mp_unary_op_t op, mp_obj_t self_in) { +static mp_obj_t deque_unary_op(mp_unary_op_t op, mp_obj_t self_in) { mp_obj_deque_t *self = MP_OBJ_TO_PTR(self_in); switch (op) { case MP_UNARY_OP_BOOL: @@ -92,7 +92,7 @@ STATIC mp_obj_t deque_unary_op(mp_unary_op_t op, mp_obj_t self_in) { } } -STATIC mp_obj_t mp_obj_deque_append(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t mp_obj_deque_append(mp_obj_t self_in, mp_obj_t arg) { mp_obj_deque_t *self = MP_OBJ_TO_PTR(self_in); size_t new_i_put = self->i_put + 1; @@ -115,9 +115,9 @@ STATIC mp_obj_t mp_obj_deque_append(mp_obj_t self_in, mp_obj_t arg) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(deque_append_obj, mp_obj_deque_append); +static MP_DEFINE_CONST_FUN_OBJ_2(deque_append_obj, mp_obj_deque_append); -STATIC mp_obj_t deque_popleft(mp_obj_t self_in) { +static mp_obj_t deque_popleft(mp_obj_t self_in) { mp_obj_deque_t *self = MP_OBJ_TO_PTR(self_in); if (self->i_get == self->i_put) { @@ -133,19 +133,19 @@ STATIC mp_obj_t deque_popleft(mp_obj_t self_in) { return ret; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(deque_popleft_obj, deque_popleft); +static MP_DEFINE_CONST_FUN_OBJ_1(deque_popleft_obj, deque_popleft); #if 0 -STATIC mp_obj_t deque_clear(mp_obj_t self_in) { +static mp_obj_t deque_clear(mp_obj_t self_in) { mp_obj_deque_t *self = MP_OBJ_TO_PTR(self_in); self->i_get = self->i_put = 0; mp_seq_clear(self->items, 0, self->alloc, sizeof(*self->items)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(deque_clear_obj, deque_clear); +static MP_DEFINE_CONST_FUN_OBJ_1(deque_clear_obj, deque_clear); #endif -STATIC const mp_rom_map_elem_t deque_locals_dict_table[] = { +static const mp_rom_map_elem_t deque_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_append), MP_ROM_PTR(&deque_append_obj) }, #if 0 { MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&deque_clear_obj) }, @@ -153,7 +153,7 @@ STATIC const mp_rom_map_elem_t deque_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_popleft), MP_ROM_PTR(&deque_popleft_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(deque_locals_dict, deque_locals_dict_table); +static MP_DEFINE_CONST_DICT(deque_locals_dict, deque_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mp_type_deque, diff --git a/py/objdict.c b/py/objdict.c index 8aafe607d69ff..cf64fa9555a28 100644 --- a/py/objdict.c +++ b/py/objdict.c @@ -49,12 +49,12 @@ const mp_obj_dict_t mp_const_empty_dict_obj = { } }; -STATIC mp_obj_t dict_update(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs); +static mp_obj_t dict_update(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs); // This is a helper function to iterate through a dictionary. The state of // the iteration is held in *cur and should be initialised with zero for the // first call. Will return NULL when no more elements are available. -STATIC mp_map_elem_t *dict_iter_next(mp_obj_dict_t *dict, size_t *cur) { +static mp_map_elem_t *dict_iter_next(mp_obj_dict_t *dict, size_t *cur) { size_t max = dict->map.alloc; mp_map_t *map = &dict->map; @@ -70,7 +70,7 @@ STATIC mp_map_elem_t *dict_iter_next(mp_obj_dict_t *dict, size_t *cur) { return NULL; } -STATIC void dict_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void dict_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { mp_obj_dict_t *self = MP_OBJ_TO_PTR(self_in); bool first = true; const char *item_separator = ", "; @@ -129,7 +129,7 @@ mp_obj_t mp_obj_dict_make_new(const mp_obj_type_t *type, size_t n_args, size_t n return dict_out; } -STATIC mp_obj_t dict_unary_op(mp_unary_op_t op, mp_obj_t self_in) { +static mp_obj_t dict_unary_op(mp_unary_op_t op, mp_obj_t self_in) { mp_obj_dict_t *self = MP_OBJ_TO_PTR(self_in); switch (op) { case MP_UNARY_OP_BOOL: @@ -147,7 +147,7 @@ STATIC mp_obj_t dict_unary_op(mp_unary_op_t op, mp_obj_t self_in) { } } -STATIC mp_obj_t dict_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { +static mp_obj_t dict_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { mp_obj_dict_t *o = MP_OBJ_TO_PTR(lhs_in); switch (op) { case MP_BINARY_OP_CONTAINS: { @@ -218,7 +218,7 @@ mp_obj_t mp_obj_dict_get(mp_obj_t self_in, mp_obj_t index) { } } -STATIC mp_obj_t dict_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { +static mp_obj_t dict_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { if (value == MP_OBJ_NULL) { // delete mp_obj_dict_delete(self_in, index); @@ -242,13 +242,13 @@ STATIC mp_obj_t dict_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { /******************************************************************************/ /* dict methods */ -STATIC void mp_ensure_not_fixed(const mp_obj_dict_t *dict) { +static void mp_ensure_not_fixed(const mp_obj_dict_t *dict) { if (dict->map.is_fixed) { mp_raise_TypeError(NULL); } } -STATIC mp_obj_t dict_clear(mp_obj_t self_in) { +static mp_obj_t dict_clear(mp_obj_t self_in) { mp_check_self(mp_obj_is_dict_or_ordereddict(self_in)); mp_obj_dict_t *self = MP_OBJ_TO_PTR(self_in); mp_ensure_not_fixed(self); @@ -257,7 +257,7 @@ STATIC mp_obj_t dict_clear(mp_obj_t self_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_clear_obj, dict_clear); +static MP_DEFINE_CONST_FUN_OBJ_1(dict_clear_obj, dict_clear); mp_obj_t mp_obj_dict_copy(mp_obj_t self_in) { mp_check_self(mp_obj_is_dict_or_ordereddict(self_in)); @@ -272,11 +272,11 @@ mp_obj_t mp_obj_dict_copy(mp_obj_t self_in) { memcpy(other->map.table, self->map.table, self->map.alloc * sizeof(mp_map_elem_t)); return other_out; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_copy_obj, mp_obj_dict_copy); +static MP_DEFINE_CONST_FUN_OBJ_1(dict_copy_obj, mp_obj_dict_copy); #if MICROPY_PY_BUILTINS_DICT_FROMKEYS // this is a classmethod -STATIC mp_obj_t dict_fromkeys(size_t n_args, const mp_obj_t *args) { +static mp_obj_t dict_fromkeys(size_t n_args, const mp_obj_t *args) { mp_obj_t iter = mp_getiter(args[1], NULL); mp_obj_t value = mp_const_none; mp_obj_t next = MP_OBJ_NULL; @@ -302,11 +302,11 @@ STATIC mp_obj_t dict_fromkeys(size_t n_args, const mp_obj_t *args) { return self_out; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_fromkeys_fun_obj, 2, 3, dict_fromkeys); -STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(dict_fromkeys_obj, MP_ROM_PTR(&dict_fromkeys_fun_obj)); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_fromkeys_fun_obj, 2, 3, dict_fromkeys); +static MP_DEFINE_CONST_CLASSMETHOD_OBJ(dict_fromkeys_obj, MP_ROM_PTR(&dict_fromkeys_fun_obj)); #endif -STATIC mp_obj_t dict_get_helper(size_t n_args, const mp_obj_t *args, mp_map_lookup_kind_t lookup_kind) { +static mp_obj_t dict_get_helper(size_t n_args, const mp_obj_t *args, mp_map_lookup_kind_t lookup_kind) { mp_check_self(mp_obj_is_dict_or_ordereddict(args[0])); mp_obj_dict_t *self = MP_OBJ_TO_PTR(args[0]); if (lookup_kind != MP_MAP_LOOKUP) { @@ -336,22 +336,22 @@ STATIC mp_obj_t dict_get_helper(size_t n_args, const mp_obj_t *args, mp_map_look return value; } -STATIC mp_obj_t dict_get(size_t n_args, const mp_obj_t *args) { +static mp_obj_t dict_get(size_t n_args, const mp_obj_t *args) { return dict_get_helper(n_args, args, MP_MAP_LOOKUP); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_get_obj, 2, 3, dict_get); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_get_obj, 2, 3, dict_get); -STATIC mp_obj_t dict_pop(size_t n_args, const mp_obj_t *args) { +static mp_obj_t dict_pop(size_t n_args, const mp_obj_t *args) { return dict_get_helper(n_args, args, MP_MAP_LOOKUP_REMOVE_IF_FOUND); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_pop_obj, 2, 3, dict_pop); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_pop_obj, 2, 3, dict_pop); -STATIC mp_obj_t dict_setdefault(size_t n_args, const mp_obj_t *args) { +static mp_obj_t dict_setdefault(size_t n_args, const mp_obj_t *args) { return dict_get_helper(n_args, args, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_setdefault_obj, 2, 3, dict_setdefault); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_setdefault_obj, 2, 3, dict_setdefault); -STATIC mp_obj_t dict_popitem(mp_obj_t self_in) { +static mp_obj_t dict_popitem(mp_obj_t self_in) { mp_check_self(mp_obj_is_dict_or_ordereddict(self_in)); mp_obj_dict_t *self = MP_OBJ_TO_PTR(self_in); mp_ensure_not_fixed(self); @@ -374,9 +374,9 @@ STATIC mp_obj_t dict_popitem(mp_obj_t self_in) { return tuple; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_popitem_obj, dict_popitem); +static MP_DEFINE_CONST_FUN_OBJ_1(dict_popitem_obj, dict_popitem); -STATIC mp_obj_t dict_update(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { +static mp_obj_t dict_update(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { mp_check_self(mp_obj_is_dict_or_ordereddict(args[0])); mp_obj_dict_t *self = MP_OBJ_TO_PTR(args[0]); mp_ensure_not_fixed(self); @@ -424,14 +424,14 @@ STATIC mp_obj_t dict_update(size_t n_args, const mp_obj_t *args, mp_map_t *kwarg return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(dict_update_obj, 1, dict_update); +static MP_DEFINE_CONST_FUN_OBJ_KW(dict_update_obj, 1, dict_update); /******************************************************************************/ /* dict views */ -STATIC const mp_obj_type_t mp_type_dict_view; -STATIC const mp_obj_type_t mp_type_dict_view_it; +static const mp_obj_type_t mp_type_dict_view; +static const mp_obj_type_t mp_type_dict_view_it; typedef enum _mp_dict_view_kind_t { MP_DICT_VIEW_ITEMS, @@ -439,7 +439,7 @@ typedef enum _mp_dict_view_kind_t { MP_DICT_VIEW_VALUES, } mp_dict_view_kind_t; -STATIC const char *const mp_dict_view_names[] = {"dict_items", "dict_keys", "dict_values"}; +static const char *const mp_dict_view_names[] = {"dict_items", "dict_keys", "dict_values"}; typedef struct _mp_obj_dict_view_it_t { mp_obj_base_t base; @@ -454,7 +454,7 @@ typedef struct _mp_obj_dict_view_t { mp_dict_view_kind_t kind; } mp_obj_dict_view_t; -STATIC mp_obj_t dict_view_it_iternext(mp_obj_t self_in) { +static mp_obj_t dict_view_it_iternext(mp_obj_t self_in) { mp_check_self(mp_obj_is_type(self_in, &mp_type_dict_view_it)); mp_obj_dict_view_it_t *self = MP_OBJ_TO_PTR(self_in); mp_map_elem_t *next = dict_iter_next(MP_OBJ_TO_PTR(self->dict), &self->cur); @@ -476,14 +476,14 @@ STATIC mp_obj_t dict_view_it_iternext(mp_obj_t self_in) { } } -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_dict_view_it, MP_QSTR_iterator, MP_TYPE_FLAG_ITER_IS_ITERNEXT, iter, dict_view_it_iternext ); -STATIC mp_obj_t dict_view_getiter(mp_obj_t view_in, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t dict_view_getiter(mp_obj_t view_in, mp_obj_iter_buf_t *iter_buf) { assert(sizeof(mp_obj_dict_view_it_t) <= sizeof(mp_obj_iter_buf_t)); mp_check_self(mp_obj_is_type(view_in, &mp_type_dict_view)); mp_obj_dict_view_t *view = MP_OBJ_TO_PTR(view_in); @@ -495,7 +495,7 @@ STATIC mp_obj_t dict_view_getiter(mp_obj_t view_in, mp_obj_iter_buf_t *iter_buf) return MP_OBJ_FROM_PTR(o); } -STATIC void dict_view_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void dict_view_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_check_self(mp_obj_is_type(self_in, &mp_type_dict_view)); mp_obj_dict_view_t *self = MP_OBJ_TO_PTR(self_in); @@ -515,7 +515,7 @@ STATIC void dict_view_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ mp_print_str(print, "])"); } -STATIC mp_obj_t dict_view_unary_op(mp_unary_op_t op, mp_obj_t o_in) { +static mp_obj_t dict_view_unary_op(mp_unary_op_t op, mp_obj_t o_in) { mp_obj_dict_view_t *o = MP_OBJ_TO_PTR(o_in); // only dict.values() supports __hash__. if (op == MP_UNARY_OP_HASH && o->kind == MP_DICT_VIEW_VALUES) { @@ -524,7 +524,7 @@ STATIC mp_obj_t dict_view_unary_op(mp_unary_op_t op, mp_obj_t o_in) { return MP_OBJ_NULL; } -STATIC mp_obj_t dict_view_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { +static mp_obj_t dict_view_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { // only supported for the 'keys' kind until sets and dicts are refactored mp_obj_dict_view_t *o = MP_OBJ_TO_PTR(lhs_in); if (o->kind != MP_DICT_VIEW_KEYS) { @@ -536,7 +536,7 @@ STATIC mp_obj_t dict_view_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t return dict_binary_op(op, o->dict, rhs_in); } -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_dict_view, MP_QSTR_dict_view, MP_TYPE_FLAG_ITER_IS_GETITER, @@ -546,37 +546,37 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( iter, dict_view_getiter ); -STATIC mp_obj_t mp_obj_new_dict_view(mp_obj_t dict, mp_dict_view_kind_t kind) { +static mp_obj_t mp_obj_new_dict_view(mp_obj_t dict, mp_dict_view_kind_t kind) { mp_obj_dict_view_t *o = mp_obj_malloc(mp_obj_dict_view_t, &mp_type_dict_view); o->dict = dict; o->kind = kind; return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t dict_view(mp_obj_t self_in, mp_dict_view_kind_t kind) { +static mp_obj_t dict_view(mp_obj_t self_in, mp_dict_view_kind_t kind) { mp_check_self(mp_obj_is_dict_or_ordereddict(self_in)); return mp_obj_new_dict_view(self_in, kind); } -STATIC mp_obj_t dict_items(mp_obj_t self_in) { +static mp_obj_t dict_items(mp_obj_t self_in) { return dict_view(self_in, MP_DICT_VIEW_ITEMS); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_items_obj, dict_items); +static MP_DEFINE_CONST_FUN_OBJ_1(dict_items_obj, dict_items); -STATIC mp_obj_t dict_keys(mp_obj_t self_in) { +static mp_obj_t dict_keys(mp_obj_t self_in) { return dict_view(self_in, MP_DICT_VIEW_KEYS); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_keys_obj, dict_keys); +static MP_DEFINE_CONST_FUN_OBJ_1(dict_keys_obj, dict_keys); -STATIC mp_obj_t dict_values(mp_obj_t self_in) { +static mp_obj_t dict_values(mp_obj_t self_in) { return dict_view(self_in, MP_DICT_VIEW_VALUES); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_values_obj, dict_values); +static MP_DEFINE_CONST_FUN_OBJ_1(dict_values_obj, dict_values); /******************************************************************************/ /* dict iterator */ -STATIC mp_obj_t dict_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t dict_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { assert(sizeof(mp_obj_dict_view_it_t) <= sizeof(mp_obj_iter_buf_t)); mp_check_self(mp_obj_is_dict_or_ordereddict(self_in)); mp_obj_dict_view_it_t *o = (mp_obj_dict_view_it_t *)iter_buf; @@ -590,7 +590,7 @@ STATIC mp_obj_t dict_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { /******************************************************************************/ /* dict constructors & public C API */ -STATIC const mp_rom_map_elem_t dict_locals_dict_table[] = { +static const mp_rom_map_elem_t dict_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&dict_clear_obj) }, { MP_ROM_QSTR(MP_QSTR_copy), MP_ROM_PTR(&dict_copy_obj) }, #if MICROPY_PY_BUILTINS_DICT_FROMKEYS @@ -609,7 +609,7 @@ STATIC const mp_rom_map_elem_t dict_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___delitem__), MP_ROM_PTR(&mp_op_delitem_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(dict_locals_dict, dict_locals_dict_table); +static MP_DEFINE_CONST_DICT(dict_locals_dict, dict_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mp_type_dict, diff --git a/py/objenumerate.c b/py/objenumerate.c index 40bed919ed750..8217a0d4f9927 100644 --- a/py/objenumerate.c +++ b/py/objenumerate.c @@ -37,9 +37,9 @@ typedef struct _mp_obj_enumerate_t { mp_int_t cur; } mp_obj_enumerate_t; -STATIC mp_obj_t enumerate_iternext(mp_obj_t self_in); +static mp_obj_t enumerate_iternext(mp_obj_t self_in); -STATIC mp_obj_t enumerate_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t enumerate_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { #if MICROPY_CPYTHON_COMPAT static const mp_arg_t allowed_args[] = { { MP_QSTR_iterable, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, @@ -75,7 +75,7 @@ MP_DEFINE_CONST_OBJ_TYPE( iter, enumerate_iternext ); -STATIC mp_obj_t enumerate_iternext(mp_obj_t self_in) { +static mp_obj_t enumerate_iternext(mp_obj_t self_in) { assert(mp_obj_is_type(self_in, &mp_type_enumerate)); mp_obj_enumerate_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_t next = mp_iternext(self->iter); diff --git a/py/objexcept.c b/py/objexcept.c index fe74458cae8c3..5bf4e672baaf1 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -117,7 +117,7 @@ bool mp_obj_is_native_exception_instance(mp_obj_t self_in) { return MP_OBJ_TYPE_GET_SLOT_OR_NULL(mp_obj_get_type(self_in), make_new) == mp_obj_exception_make_new; } -STATIC mp_obj_exception_t *get_native_exception(mp_obj_t self_in) { +static mp_obj_exception_t *get_native_exception(mp_obj_t self_in) { assert(mp_obj_is_exception_instance(self_in)); if (mp_obj_is_native_exception_instance(self_in)) { return MP_OBJ_TO_PTR(self_in); @@ -126,7 +126,7 @@ STATIC mp_obj_exception_t *get_native_exception(mp_obj_t self_in) { } } -STATIC void decompress_error_text_maybe(mp_obj_exception_t *o) { +static void decompress_error_text_maybe(mp_obj_exception_t *o) { #if MICROPY_ROM_TEXT_COMPRESSION if (o->args->len == 1 && mp_obj_is_exact_type(o->args->items[0], &mp_type_str)) { mp_obj_str_t *o_str = MP_OBJ_TO_PTR(o->args->items[0]); @@ -439,7 +439,7 @@ struct _exc_printer_t { byte *buf; }; -STATIC void exc_add_strn(void *data, const char *str, size_t len) { +static void exc_add_strn(void *data, const char *str, size_t len) { struct _exc_printer_t *pr = data; if (pr->len + len >= pr->alloc) { // Not enough room for data plus a null byte so try to grow the buffer diff --git a/py/objfilter.c b/py/objfilter.c index 2a657fde4b71b..7f1f700f6a607 100644 --- a/py/objfilter.c +++ b/py/objfilter.c @@ -34,7 +34,7 @@ typedef struct _mp_obj_filter_t { mp_obj_t iter; } mp_obj_filter_t; -STATIC mp_obj_t filter_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t filter_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 2, 2, false); mp_obj_filter_t *o = mp_obj_malloc(mp_obj_filter_t, type); o->fun = args[0]; @@ -42,7 +42,7 @@ STATIC mp_obj_t filter_make_new(const mp_obj_type_t *type, size_t n_args, size_t return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t filter_iternext(mp_obj_t self_in) { +static mp_obj_t filter_iternext(mp_obj_t self_in) { mp_check_self(mp_obj_is_type(self_in, &mp_type_filter)); mp_obj_filter_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_t next; diff --git a/py/objfloat.c b/py/objfloat.c index c862b4843b278..5c90b1491cebf 100644 --- a/py/objfloat.c +++ b/py/objfloat.c @@ -102,7 +102,7 @@ mp_int_t mp_float_hash(mp_float_t src) { } #endif -STATIC void float_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +static void float_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; mp_float_t o_val = mp_obj_float_get(o_in); #if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT @@ -124,7 +124,7 @@ STATIC void float_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t } } -STATIC mp_obj_t float_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t float_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; mp_arg_check_num(n_args, n_kw, 0, 1, false); @@ -149,7 +149,7 @@ STATIC mp_obj_t float_make_new(const mp_obj_type_t *type_in, size_t n_args, size } } -STATIC mp_obj_t float_unary_op(mp_unary_op_t op, mp_obj_t o_in) { +static mp_obj_t float_unary_op(mp_unary_op_t op, mp_obj_t o_in) { mp_float_t val = mp_obj_float_get(o_in); switch (op) { case MP_UNARY_OP_BOOL: @@ -172,7 +172,7 @@ STATIC mp_obj_t float_unary_op(mp_unary_op_t op, mp_obj_t o_in) { } } -STATIC mp_obj_t float_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { +static mp_obj_t float_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { mp_float_t lhs_val = mp_obj_float_get(lhs_in); #if MICROPY_PY_BUILTINS_COMPLEX if (mp_obj_is_type(rhs_in, &mp_type_complex)) { @@ -208,7 +208,7 @@ mp_float_t mp_obj_float_get(mp_obj_t self_in) { #endif -STATIC void mp_obj_float_divmod(mp_float_t *x, mp_float_t *y) { +static void mp_obj_float_divmod(mp_float_t *x, mp_float_t *y) { // logic here follows that of CPython // https://docs.python.org/3/reference/expressions.html#binary-arithmetic-operations // x == (x//y)*y + (x%y) diff --git a/py/objfun.c b/py/objfun.c index 2e86aaa14d594..1ebfa3d5af217 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -48,7 +48,7 @@ /******************************************************************************/ /* builtin functions */ -STATIC mp_obj_t fun_builtin_0_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t fun_builtin_0_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)args; assert(mp_obj_is_type(self_in, &mp_type_fun_builtin_0)); mp_obj_fun_builtin_fixed_t *self = MP_OBJ_TO_PTR(self_in); @@ -61,7 +61,7 @@ MP_DEFINE_CONST_OBJ_TYPE( call, fun_builtin_0_call ); -STATIC mp_obj_t fun_builtin_1_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t fun_builtin_1_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { assert(mp_obj_is_type(self_in, &mp_type_fun_builtin_1)); mp_obj_fun_builtin_fixed_t *self = MP_OBJ_TO_PTR(self_in); mp_arg_check_num(n_args, n_kw, 1, 1, false); @@ -73,7 +73,7 @@ MP_DEFINE_CONST_OBJ_TYPE( call, fun_builtin_1_call ); -STATIC mp_obj_t fun_builtin_2_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t fun_builtin_2_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { assert(mp_obj_is_type(self_in, &mp_type_fun_builtin_2)); mp_obj_fun_builtin_fixed_t *self = MP_OBJ_TO_PTR(self_in); mp_arg_check_num(n_args, n_kw, 2, 2, false); @@ -85,7 +85,7 @@ MP_DEFINE_CONST_OBJ_TYPE( call, fun_builtin_2_call ); -STATIC mp_obj_t fun_builtin_3_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t fun_builtin_3_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { assert(mp_obj_is_type(self_in, &mp_type_fun_builtin_3)); mp_obj_fun_builtin_fixed_t *self = MP_OBJ_TO_PTR(self_in); mp_arg_check_num(n_args, n_kw, 3, 3, false); @@ -97,7 +97,7 @@ MP_DEFINE_CONST_OBJ_TYPE( call, fun_builtin_3_call ); -STATIC mp_obj_t fun_builtin_var_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t fun_builtin_var_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { assert(mp_obj_is_type(self_in, &mp_type_fun_builtin_var)); mp_obj_fun_builtin_var_t *self = MP_OBJ_TO_PTR(self_in); @@ -150,7 +150,7 @@ qstr mp_obj_fun_get_name(mp_const_obj_t fun_in) { } #if MICROPY_CPYTHON_COMPAT -STATIC void fun_bc_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +static void fun_bc_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; mp_obj_fun_bc_t *o = MP_OBJ_TO_PTR(o_in); mp_printf(print, "", mp_obj_fun_get_name(o_in), o); @@ -158,7 +158,7 @@ STATIC void fun_bc_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t #endif #if DEBUG_PRINT -STATIC void dump_args(const mp_obj_t *a, size_t sz) { +static void dump_args(const mp_obj_t *a, size_t sz) { DEBUG_printf("%p: ", a); for (size_t i = 0; i < sz; i++) { DEBUG_printf("%p ", a[i]); @@ -224,7 +224,7 @@ mp_code_state_t *mp_obj_fun_bc_prepare_codestate(mp_obj_t self_in, size_t n_args } #endif -STATIC mp_obj_t fun_bc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t fun_bc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { MP_STACK_CHECK(); DEBUG_printf("Input n_args: " UINT_FMT ", n_kw: " UINT_FMT "\n", n_args, n_kw); @@ -396,7 +396,7 @@ mp_obj_t mp_obj_new_fun_bc(const mp_obj_t *def_args, const byte *code, const mp_ #if MICROPY_EMIT_NATIVE -STATIC mp_obj_t fun_native_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t fun_native_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { MP_STACK_CHECK(); mp_obj_fun_bc_t *self = MP_OBJ_TO_PTR(self_in); mp_call_fun_t fun = mp_obj_fun_native_get_function_start(self); @@ -430,7 +430,7 @@ MP_DEFINE_CONST_OBJ_TYPE( #if MICROPY_EMIT_NATIVE -STATIC mp_obj_t fun_viper_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t fun_viper_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { MP_STACK_CHECK(); mp_obj_fun_bc_t *self = MP_OBJ_TO_PTR(self_in); mp_call_fun_t fun = MICROPY_MAKE_POINTER_CALLABLE((void *)self->bytecode); @@ -458,7 +458,7 @@ typedef mp_uint_t (*inline_asm_fun_3_t)(mp_uint_t, mp_uint_t, mp_uint_t); typedef mp_uint_t (*inline_asm_fun_4_t)(mp_uint_t, mp_uint_t, mp_uint_t, mp_uint_t); // convert a MicroPython object to a sensible value for inline asm -STATIC mp_uint_t convert_obj_for_inline_asm(mp_obj_t obj) { +static mp_uint_t convert_obj_for_inline_asm(mp_obj_t obj) { // TODO for byte_array, pass pointer to the array if (mp_obj_is_small_int(obj)) { return MP_OBJ_SMALL_INT_VALUE(obj); @@ -501,7 +501,7 @@ STATIC mp_uint_t convert_obj_for_inline_asm(mp_obj_t obj) { } } -STATIC mp_obj_t fun_asm_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t fun_asm_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_obj_fun_asm_t *self = MP_OBJ_TO_PTR(self_in); mp_arg_check_num(n_args, n_kw, self->n_args, self->n_args, false); diff --git a/py/objgenerator.c b/py/objgenerator.c index e4acd5e49b9cc..431cbad5a79d8 100644 --- a/py/objgenerator.c +++ b/py/objgenerator.c @@ -50,7 +50,7 @@ typedef struct _mp_obj_gen_instance_t { mp_code_state_t code_state; } mp_obj_gen_instance_t; -STATIC mp_obj_t gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { // A generating function is just a bytecode function with type mp_type_gen_wrap mp_obj_fun_bc_t *self_fun = MP_OBJ_TO_PTR(self_in); @@ -96,7 +96,7 @@ typedef struct _mp_obj_gen_instance_native_t { mp_code_state_native_t code_state; } mp_obj_gen_instance_native_t; -STATIC mp_obj_t native_gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t native_gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { // The state for a native generating function is held in the same struct as a bytecode function mp_obj_fun_bc_t *self_fun = MP_OBJ_TO_PTR(self_in); @@ -144,7 +144,7 @@ MP_DEFINE_CONST_OBJ_TYPE( /******************************************************************************/ /* generator instance */ -STATIC void gen_instance_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void gen_instance_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_gen_instance_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", mp_obj_fun_get_name(MP_OBJ_FROM_PTR(self->code_state.fun_bc)), self); @@ -254,7 +254,7 @@ mp_vm_return_kind_t mp_obj_gen_resume(mp_obj_t self_in, mp_obj_t send_value, mp_ return ret_kind; } -STATIC mp_obj_t gen_resume_and_raise(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t throw_value, bool raise_stop_iteration) { +static mp_obj_t gen_resume_and_raise(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t throw_value, bool raise_stop_iteration) { mp_obj_t ret; switch (mp_obj_gen_resume(self_in, send_value, throw_value, &ret)) { case MP_VM_RETURN_NORMAL: @@ -278,16 +278,16 @@ STATIC mp_obj_t gen_resume_and_raise(mp_obj_t self_in, mp_obj_t send_value, mp_o } } -STATIC mp_obj_t gen_instance_iternext(mp_obj_t self_in) { +static mp_obj_t gen_instance_iternext(mp_obj_t self_in) { return gen_resume_and_raise(self_in, mp_const_none, MP_OBJ_NULL, false); } -STATIC mp_obj_t gen_instance_send(mp_obj_t self_in, mp_obj_t send_value) { +static mp_obj_t gen_instance_send(mp_obj_t self_in, mp_obj_t send_value) { return gen_resume_and_raise(self_in, send_value, MP_OBJ_NULL, true); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(gen_instance_send_obj, gen_instance_send); +static MP_DEFINE_CONST_FUN_OBJ_2(gen_instance_send_obj, gen_instance_send); -STATIC mp_obj_t gen_instance_throw(size_t n_args, const mp_obj_t *args) { +static mp_obj_t gen_instance_throw(size_t n_args, const mp_obj_t *args) { // The signature of this function is: throw(type[, value[, traceback]]) // CPython will pass all given arguments through the call chain and process them // at the point they are used (native generators will handle them differently to @@ -307,9 +307,9 @@ STATIC mp_obj_t gen_instance_throw(size_t n_args, const mp_obj_t *args) { return gen_resume_and_raise(args[0], mp_const_none, exc, true); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(gen_instance_throw_obj, 2, 4, gen_instance_throw); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(gen_instance_throw_obj, 2, 4, gen_instance_throw); -STATIC mp_obj_t gen_instance_close(mp_obj_t self_in) { +static mp_obj_t gen_instance_close(mp_obj_t self_in) { mp_obj_t ret; switch (mp_obj_gen_resume(self_in, mp_const_none, MP_OBJ_FROM_PTR(&mp_const_GeneratorExit_obj), &ret)) { case MP_VM_RETURN_YIELD: @@ -328,10 +328,10 @@ STATIC mp_obj_t gen_instance_close(mp_obj_t self_in) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(gen_instance_close_obj, gen_instance_close); +static MP_DEFINE_CONST_FUN_OBJ_1(gen_instance_close_obj, gen_instance_close); #if MICROPY_PY_GENERATOR_PEND_THROW -STATIC mp_obj_t gen_instance_pend_throw(mp_obj_t self_in, mp_obj_t exc_in) { +static mp_obj_t gen_instance_pend_throw(mp_obj_t self_in, mp_obj_t exc_in) { mp_obj_gen_instance_t *self = MP_OBJ_TO_PTR(self_in); if (self->pend_exc == MP_OBJ_NULL) { mp_raise_ValueError(MP_ERROR_TEXT("generator already executing")); @@ -340,10 +340,10 @@ STATIC mp_obj_t gen_instance_pend_throw(mp_obj_t self_in, mp_obj_t exc_in) { self->pend_exc = exc_in; return prev; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(gen_instance_pend_throw_obj, gen_instance_pend_throw); +static MP_DEFINE_CONST_FUN_OBJ_2(gen_instance_pend_throw_obj, gen_instance_pend_throw); #endif -STATIC const mp_rom_map_elem_t gen_instance_locals_dict_table[] = { +static const mp_rom_map_elem_t gen_instance_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&gen_instance_close_obj) }, { MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&gen_instance_send_obj) }, { MP_ROM_QSTR(MP_QSTR_throw), MP_ROM_PTR(&gen_instance_throw_obj) }, @@ -352,7 +352,7 @@ STATIC const mp_rom_map_elem_t gen_instance_locals_dict_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(gen_instance_locals_dict, gen_instance_locals_dict_table); +static MP_DEFINE_CONST_DICT(gen_instance_locals_dict, gen_instance_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mp_type_gen_instance, diff --git a/py/objgetitemiter.c b/py/objgetitemiter.c index c598d1daaca9a..c735c65b652d6 100644 --- a/py/objgetitemiter.c +++ b/py/objgetitemiter.c @@ -35,7 +35,7 @@ typedef struct _mp_obj_getitem_iter_t { mp_obj_t args[3]; } mp_obj_getitem_iter_t; -STATIC mp_obj_t it_iternext(mp_obj_t self_in) { +static mp_obj_t it_iternext(mp_obj_t self_in) { mp_obj_getitem_iter_t *self = MP_OBJ_TO_PTR(self_in); nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { @@ -56,7 +56,7 @@ STATIC mp_obj_t it_iternext(mp_obj_t self_in) { } } -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_it, MP_QSTR_iterator, MP_TYPE_FLAG_ITER_IS_ITERNEXT, diff --git a/py/objint.c b/py/objint.c index be5f4653a7dec..6caa608f33035 100644 --- a/py/objint.c +++ b/py/objint.c @@ -40,7 +40,7 @@ #endif // This dispatcher function is expected to be independent of the implementation of long int -STATIC mp_obj_t mp_obj_int_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t mp_obj_int_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; mp_arg_check_num(n_args, n_kw, 0, 2, false); @@ -83,7 +83,7 @@ typedef enum { MP_FP_CLASS_OVERFLOW } mp_fp_as_int_class_t; -STATIC mp_fp_as_int_class_t mp_classify_fp_as_int(mp_float_t val) { +static mp_fp_as_int_class_t mp_classify_fp_as_int(mp_float_t val) { union { mp_float_t f; #if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT @@ -193,7 +193,7 @@ void mp_obj_int_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t } } -STATIC const uint8_t log_base2_floor[] = { +static const uint8_t log_base2_floor[] = { 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, @@ -388,7 +388,7 @@ mp_obj_t mp_obj_int_binary_op_extra_cases(mp_binary_op_t op, mp_obj_t lhs_in, mp } // this is a classmethod -STATIC mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *args) { +static mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *args) { // TODO: Support signed param (assumes signed=False at the moment) (void)n_args; @@ -417,10 +417,10 @@ STATIC mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *args) { return mp_obj_new_int_from_uint(value); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(int_from_bytes_fun_obj, 3, 4, int_from_bytes); -STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(int_from_bytes_obj, MP_ROM_PTR(&int_from_bytes_fun_obj)); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(int_from_bytes_fun_obj, 3, 4, int_from_bytes); +static MP_DEFINE_CONST_CLASSMETHOD_OBJ(int_from_bytes_obj, MP_ROM_PTR(&int_from_bytes_fun_obj)); -STATIC mp_obj_t int_to_bytes(size_t n_args, const mp_obj_t *args) { +static mp_obj_t int_to_bytes(size_t n_args, const mp_obj_t *args) { // TODO: Support signed param (assumes signed=False) (void)n_args; @@ -448,14 +448,14 @@ STATIC mp_obj_t int_to_bytes(size_t n_args, const mp_obj_t *args) { return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(int_to_bytes_obj, 3, 4, int_to_bytes); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(int_to_bytes_obj, 3, 4, int_to_bytes); -STATIC const mp_rom_map_elem_t int_locals_dict_table[] = { +static const mp_rom_map_elem_t int_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_from_bytes), MP_ROM_PTR(&int_from_bytes_obj) }, { MP_ROM_QSTR(MP_QSTR_to_bytes), MP_ROM_PTR(&int_to_bytes_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(int_locals_dict, int_locals_dict_table); +static MP_DEFINE_CONST_DICT(int_locals_dict, int_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mp_type_int, diff --git a/py/objint_mpz.c b/py/objint_mpz.c index 8078441d66a0b..600316a42abba 100644 --- a/py/objint_mpz.c +++ b/py/objint_mpz.c @@ -43,7 +43,7 @@ // Export value for sys.maxsize // *FORMAT-OFF* #define DIG_MASK ((MPZ_LONG_1 << MPZ_DIG_SIZE) - 1) -STATIC const mpz_dig_t maxsize_dig[] = { +static const mpz_dig_t maxsize_dig[] = { #define NUM_DIG 1 (MP_SSIZE_MAX >> MPZ_DIG_SIZE * 0) & DIG_MASK, #if (MP_SSIZE_MAX >> MPZ_DIG_SIZE * 0) > DIG_MASK @@ -335,7 +335,7 @@ mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_i } #if MICROPY_PY_BUILTINS_POW3 -STATIC mpz_t *mp_mpz_for_int(mp_obj_t arg, mpz_t *temp) { +static mpz_t *mp_mpz_for_int(mp_obj_t arg, mpz_t *temp) { if (mp_obj_is_small_int(arg)) { mpz_init_from_int(temp, MP_OBJ_SMALL_INT_VALUE(arg)); return temp; diff --git a/py/objlist.c b/py/objlist.c index 1423cb1deeb73..2198beb839f14 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -31,10 +31,10 @@ #include "py/runtime.h" #include "py/stackctrl.h" -STATIC mp_obj_t mp_obj_new_list_iterator(mp_obj_t list, size_t cur, mp_obj_iter_buf_t *iter_buf); -STATIC mp_obj_list_t *list_new(size_t n); -STATIC mp_obj_t list_extend(mp_obj_t self_in, mp_obj_t arg_in); -STATIC mp_obj_t list_pop(size_t n_args, const mp_obj_t *args); +static mp_obj_t mp_obj_new_list_iterator(mp_obj_t list, size_t cur, mp_obj_iter_buf_t *iter_buf); +static mp_obj_list_t *list_new(size_t n); +static mp_obj_t list_extend(mp_obj_t self_in, mp_obj_t arg_in); +static mp_obj_t list_pop(size_t n_args, const mp_obj_t *args); // TODO: Move to mpconfig.h #define LIST_MIN_ALLOC 4 @@ -42,7 +42,7 @@ STATIC mp_obj_t list_pop(size_t n_args, const mp_obj_t *args); /******************************************************************************/ /* list */ -STATIC void list_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +static void list_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { mp_obj_list_t *o = MP_OBJ_TO_PTR(o_in); const char *item_separator = ", "; if (!(MICROPY_PY_JSON && kind == PRINT_JSON)) { @@ -62,7 +62,7 @@ STATIC void list_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t k mp_print_str(print, "]"); } -STATIC mp_obj_t list_extend_from_iter(mp_obj_t list, mp_obj_t iterable) { +static mp_obj_t list_extend_from_iter(mp_obj_t list, mp_obj_t iterable) { mp_obj_t iter = mp_getiter(iterable, NULL); mp_obj_t item; while ((item = mp_iternext(iter)) != MP_OBJ_STOP_ITERATION) { @@ -90,7 +90,7 @@ mp_obj_t mp_obj_list_make_new(const mp_obj_type_t *type_in, size_t n_args, size_ } } -STATIC mp_obj_t list_unary_op(mp_unary_op_t op, mp_obj_t self_in) { +static mp_obj_t list_unary_op(mp_unary_op_t op, mp_obj_t self_in) { mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in); switch (op) { case MP_UNARY_OP_BOOL: @@ -108,7 +108,7 @@ STATIC mp_obj_t list_unary_op(mp_unary_op_t op, mp_obj_t self_in) { } } -STATIC mp_obj_t list_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) { +static mp_obj_t list_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) { mp_obj_list_t *o = MP_OBJ_TO_PTR(lhs); switch (op) { case MP_BINARY_OP_ADD: { @@ -158,7 +158,7 @@ STATIC mp_obj_t list_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) { } } -STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { +static mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { if (value == MP_OBJ_NULL) { // delete #if MICROPY_PY_BUILTINS_SLICE @@ -234,7 +234,7 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { } } -STATIC mp_obj_t list_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t list_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) { return mp_obj_new_list_iterator(o_in, 0, iter_buf); } @@ -250,7 +250,7 @@ mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg) { return mp_const_none; // return None, as per CPython } -STATIC mp_obj_t list_extend(mp_obj_t self_in, mp_obj_t arg_in) { +static mp_obj_t list_extend(mp_obj_t self_in, mp_obj_t arg_in) { mp_check_self(mp_obj_is_type(self_in, &mp_type_list)); if (mp_obj_is_type(arg_in, &mp_type_list)) { mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in); @@ -271,7 +271,7 @@ STATIC mp_obj_t list_extend(mp_obj_t self_in, mp_obj_t arg_in) { return mp_const_none; // return None, as per CPython } -STATIC mp_obj_t list_pop(size_t n_args, const mp_obj_t *args) { +static mp_obj_t list_pop(size_t n_args, const mp_obj_t *args) { mp_check_self(mp_obj_is_type(args[0], &mp_type_list)); mp_obj_list_t *self = MP_OBJ_TO_PTR(args[0]); if (self->len == 0) { @@ -290,7 +290,7 @@ STATIC mp_obj_t list_pop(size_t n_args, const mp_obj_t *args) { return ret; } -STATIC void mp_quicksort(mp_obj_t *head, mp_obj_t *tail, mp_obj_t key_fn, mp_obj_t binop_less_result) { +static void mp_quicksort(mp_obj_t *head, mp_obj_t *tail, mp_obj_t key_fn, mp_obj_t binop_less_result) { MP_STACK_CHECK(); while (head < tail) { mp_obj_t *h = head - 1; @@ -348,7 +348,7 @@ mp_obj_t mp_obj_list_sort(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ return mp_const_none; } -STATIC mp_obj_t list_clear(mp_obj_t self_in) { +static mp_obj_t list_clear(mp_obj_t self_in) { mp_check_self(mp_obj_is_type(self_in, &mp_type_list)); mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in); self->len = 0; @@ -358,25 +358,25 @@ STATIC mp_obj_t list_clear(mp_obj_t self_in) { return mp_const_none; } -STATIC mp_obj_t list_copy(mp_obj_t self_in) { +static mp_obj_t list_copy(mp_obj_t self_in) { mp_check_self(mp_obj_is_type(self_in, &mp_type_list)); mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_list(self->len, self->items); } -STATIC mp_obj_t list_count(mp_obj_t self_in, mp_obj_t value) { +static mp_obj_t list_count(mp_obj_t self_in, mp_obj_t value) { mp_check_self(mp_obj_is_type(self_in, &mp_type_list)); mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in); return mp_seq_count_obj(self->items, self->len, value); } -STATIC mp_obj_t list_index(size_t n_args, const mp_obj_t *args) { +static mp_obj_t list_index(size_t n_args, const mp_obj_t *args) { mp_check_self(mp_obj_is_type(args[0], &mp_type_list)); mp_obj_list_t *self = MP_OBJ_TO_PTR(args[0]); return mp_seq_index_obj(self->items, self->len, n_args, args); } -STATIC mp_obj_t list_insert(mp_obj_t self_in, mp_obj_t idx, mp_obj_t obj) { +static mp_obj_t list_insert(mp_obj_t self_in, mp_obj_t idx, mp_obj_t obj) { mp_check_self(mp_obj_is_type(self_in, &mp_type_list)); mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in); // insert has its own strange index logic @@ -410,7 +410,7 @@ mp_obj_t mp_obj_list_remove(mp_obj_t self_in, mp_obj_t value) { return mp_const_none; } -STATIC mp_obj_t list_reverse(mp_obj_t self_in) { +static mp_obj_t list_reverse(mp_obj_t self_in) { mp_check_self(mp_obj_is_type(self_in, &mp_type_list)); mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in); @@ -424,19 +424,19 @@ STATIC mp_obj_t list_reverse(mp_obj_t self_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(list_append_obj, mp_obj_list_append); -STATIC MP_DEFINE_CONST_FUN_OBJ_2(list_extend_obj, list_extend); -STATIC MP_DEFINE_CONST_FUN_OBJ_1(list_clear_obj, list_clear); -STATIC MP_DEFINE_CONST_FUN_OBJ_1(list_copy_obj, list_copy); -STATIC MP_DEFINE_CONST_FUN_OBJ_2(list_count_obj, list_count); -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(list_index_obj, 2, 4, list_index); -STATIC MP_DEFINE_CONST_FUN_OBJ_3(list_insert_obj, list_insert); -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(list_pop_obj, 1, 2, list_pop); -STATIC MP_DEFINE_CONST_FUN_OBJ_2(list_remove_obj, mp_obj_list_remove); -STATIC MP_DEFINE_CONST_FUN_OBJ_1(list_reverse_obj, list_reverse); -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(list_sort_obj, 1, mp_obj_list_sort); - -STATIC const mp_rom_map_elem_t list_locals_dict_table[] = { +static MP_DEFINE_CONST_FUN_OBJ_2(list_append_obj, mp_obj_list_append); +static MP_DEFINE_CONST_FUN_OBJ_2(list_extend_obj, list_extend); +static MP_DEFINE_CONST_FUN_OBJ_1(list_clear_obj, list_clear); +static MP_DEFINE_CONST_FUN_OBJ_1(list_copy_obj, list_copy); +static MP_DEFINE_CONST_FUN_OBJ_2(list_count_obj, list_count); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(list_index_obj, 2, 4, list_index); +static MP_DEFINE_CONST_FUN_OBJ_3(list_insert_obj, list_insert); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(list_pop_obj, 1, 2, list_pop); +static MP_DEFINE_CONST_FUN_OBJ_2(list_remove_obj, mp_obj_list_remove); +static MP_DEFINE_CONST_FUN_OBJ_1(list_reverse_obj, list_reverse); +static MP_DEFINE_CONST_FUN_OBJ_KW(list_sort_obj, 1, mp_obj_list_sort); + +static const mp_rom_map_elem_t list_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_append), MP_ROM_PTR(&list_append_obj) }, { MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&list_clear_obj) }, { MP_ROM_QSTR(MP_QSTR_copy), MP_ROM_PTR(&list_copy_obj) }, @@ -450,7 +450,7 @@ STATIC const mp_rom_map_elem_t list_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_sort), MP_ROM_PTR(&list_sort_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(list_locals_dict, list_locals_dict_table); +static MP_DEFINE_CONST_DICT(list_locals_dict, list_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mp_type_list, @@ -474,7 +474,7 @@ void mp_obj_list_init(mp_obj_list_t *o, size_t n) { mp_seq_clear(o->items, n, o->alloc, sizeof(*o->items)); } -STATIC mp_obj_list_t *list_new(size_t n) { +static mp_obj_list_t *list_new(size_t n) { mp_obj_list_t *o = m_new_obj(mp_obj_list_t); mp_obj_list_init(o, n); return o; @@ -519,7 +519,7 @@ typedef struct _mp_obj_list_it_t { size_t cur; } mp_obj_list_it_t; -STATIC mp_obj_t list_it_iternext(mp_obj_t self_in) { +static mp_obj_t list_it_iternext(mp_obj_t self_in) { mp_obj_list_it_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_list_t *list = MP_OBJ_TO_PTR(self->list); if (self->cur < list->len) { diff --git a/py/objmap.c b/py/objmap.c index 98ff19bb7bb6f..1911a7510abe8 100644 --- a/py/objmap.c +++ b/py/objmap.c @@ -36,7 +36,7 @@ typedef struct _mp_obj_map_t { mp_obj_t iters[]; } mp_obj_map_t; -STATIC mp_obj_t map_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t map_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 2, MP_OBJ_FUN_ARGS_MAX, false); mp_obj_map_t *o = mp_obj_malloc_var(mp_obj_map_t, iters, mp_obj_t, n_args - 1, type); o->n_iters = n_args - 1; @@ -47,7 +47,7 @@ STATIC mp_obj_t map_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t map_iternext(mp_obj_t self_in) { +static mp_obj_t map_iternext(mp_obj_t self_in) { mp_check_self(mp_obj_is_type(self_in, &mp_type_map)); mp_obj_map_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_t *nextses = m_new(mp_obj_t, self->n_iters); diff --git a/py/objmodule.c b/py/objmodule.c index 5266421b79645..5ce373b83d3f1 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -34,7 +34,7 @@ #include "py/runtime.h" #include "py/builtin.h" -STATIC void module_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void module_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_module_t *self = MP_OBJ_TO_PTR(self_in); @@ -57,9 +57,9 @@ STATIC void module_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kin mp_printf(print, "", module_name); } -STATIC void module_attr_try_delegation(mp_obj_t self_in, qstr attr, mp_obj_t *dest); +static void module_attr_try_delegation(mp_obj_t self_in, qstr attr, mp_obj_t *dest); -STATIC void module_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void module_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { mp_obj_module_t *self = MP_OBJ_TO_PTR(self_in); if (dest[0] == MP_OBJ_NULL) { // load attribute @@ -146,13 +146,13 @@ mp_obj_t mp_obj_new_module(qstr module_name) { /******************************************************************************/ // Global module table and related functions -STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = { +static const mp_rom_map_elem_t mp_builtin_module_table[] = { // built-in modules declared with MP_REGISTER_MODULE() MICROPY_REGISTERED_MODULES }; MP_DEFINE_CONST_MAP(mp_builtin_module_map, mp_builtin_module_table); -STATIC const mp_rom_map_elem_t mp_builtin_extensible_module_table[] = { +static const mp_rom_map_elem_t mp_builtin_extensible_module_table[] = { // built-in modules declared with MP_REGISTER_EXTENSIBLE_MODULE() MICROPY_REGISTERED_EXTENSIBLE_MODULES }; @@ -164,7 +164,7 @@ typedef struct _mp_module_delegation_entry_t { mp_attr_fun_t fun; } mp_module_delegation_entry_t; -STATIC const mp_module_delegation_entry_t mp_builtin_module_delegation_table[] = { +static const mp_module_delegation_entry_t mp_builtin_module_delegation_table[] = { // delegation entries declared with MP_REGISTER_MODULE_DELEGATION() MICROPY_MODULE_DELEGATIONS }; @@ -223,7 +223,7 @@ mp_obj_t mp_module_get_builtin(qstr module_name, bool extensible) { return elem->value; } -STATIC void module_attr_try_delegation(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void module_attr_try_delegation(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { #if MICROPY_MODULE_ATTR_DELEGATION && defined(MICROPY_MODULE_DELEGATIONS) // Delegate lookup to a module's custom attr method. size_t n = MP_ARRAY_SIZE(mp_builtin_module_delegation_table); diff --git a/py/objnamedtuple.c b/py/objnamedtuple.c index 0adf83fe96bcd..f019604d5257b 100644 --- a/py/objnamedtuple.c +++ b/py/objnamedtuple.c @@ -44,7 +44,7 @@ size_t mp_obj_namedtuple_find_field(const mp_obj_namedtuple_type_t *type, qstr n } #if MICROPY_PY_COLLECTIONS_NAMEDTUPLE__ASDICT -STATIC mp_obj_t namedtuple_asdict(mp_obj_t self_in) { +static mp_obj_t namedtuple_asdict(mp_obj_t self_in) { mp_obj_namedtuple_t *self = MP_OBJ_TO_PTR(self_in); const qstr *fields = ((mp_obj_namedtuple_type_t *)self->tuple.base.type)->fields; mp_obj_t dict = mp_obj_new_dict(self->tuple.len); @@ -60,7 +60,7 @@ STATIC mp_obj_t namedtuple_asdict(mp_obj_t self_in) { MP_DEFINE_CONST_FUN_OBJ_1(namedtuple_asdict_obj, namedtuple_asdict); #endif -STATIC void namedtuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +static void namedtuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; mp_obj_namedtuple_t *o = MP_OBJ_TO_PTR(o_in); mp_printf(print, "%q", o->tuple.base.type->name); @@ -68,7 +68,7 @@ STATIC void namedtuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_ki mp_obj_attrtuple_print_helper(print, fields, &o->tuple); } -STATIC void namedtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void namedtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] == MP_OBJ_NULL) { // load attribute mp_obj_namedtuple_t *self = MP_OBJ_TO_PTR(self_in); @@ -91,7 +91,7 @@ STATIC void namedtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } } -STATIC mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { const mp_obj_namedtuple_type_t *type = (const mp_obj_namedtuple_type_t *)type_in; size_t num_fields = type->n_fields; if (n_args + n_kw != num_fields) { @@ -151,7 +151,7 @@ mp_obj_namedtuple_type_t *mp_obj_new_namedtuple_base(size_t n_fields, mp_obj_t * return o; } -STATIC mp_obj_t mp_obj_new_namedtuple_type(qstr name, size_t n_fields, mp_obj_t *fields) { +static mp_obj_t mp_obj_new_namedtuple_type(qstr name, size_t n_fields, mp_obj_t *fields) { mp_obj_namedtuple_type_t *o = mp_obj_new_namedtuple_base(n_fields, fields); mp_obj_type_t *type = (mp_obj_type_t *)&o->base; type->base.type = &mp_type_type; @@ -168,7 +168,7 @@ STATIC mp_obj_t mp_obj_new_namedtuple_type(qstr name, size_t n_fields, mp_obj_t return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t new_namedtuple_type(mp_obj_t name_in, mp_obj_t fields_in) { +static mp_obj_t new_namedtuple_type(mp_obj_t name_in, mp_obj_t fields_in) { qstr name = mp_obj_str_get_qstr(name_in); size_t n_fields; mp_obj_t *fields; diff --git a/py/objnone.c b/py/objnone.c index 5b25cd38c46d5..a8ce8ebfedf82 100644 --- a/py/objnone.c +++ b/py/objnone.c @@ -34,7 +34,7 @@ typedef struct _mp_obj_none_t { } mp_obj_none_t; #endif -STATIC void none_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void none_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)self_in; if (MICROPY_PY_JSON && kind == PRINT_JSON) { mp_print_str(print, "null"); diff --git a/py/objobject.c b/py/objobject.c index 1acae6d00b189..ff93fd0827d2f 100644 --- a/py/objobject.c +++ b/py/objobject.c @@ -33,7 +33,7 @@ typedef struct _mp_obj_object_t { mp_obj_base_t base; } mp_obj_object_t; -STATIC mp_obj_t object_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t object_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)args; mp_arg_check_num(n_args, n_kw, 0, 0, false); mp_obj_object_t *o = mp_obj_malloc(mp_obj_object_t, type); @@ -41,13 +41,13 @@ STATIC mp_obj_t object_make_new(const mp_obj_type_t *type, size_t n_args, size_t } #if MICROPY_CPYTHON_COMPAT -STATIC mp_obj_t object___init__(mp_obj_t self) { +static mp_obj_t object___init__(mp_obj_t self) { (void)self; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(object___init___obj, object___init__); +static MP_DEFINE_CONST_FUN_OBJ_1(object___init___obj, object___init__); -STATIC mp_obj_t object___new__(mp_obj_t cls) { +static mp_obj_t object___new__(mp_obj_t cls) { if (!mp_obj_is_type(cls, &mp_type_type) || !mp_obj_is_instance_type((mp_obj_type_t *)MP_OBJ_TO_PTR(cls))) { mp_raise_TypeError(MP_ERROR_TEXT("arg must be user-type")); } @@ -58,11 +58,11 @@ STATIC mp_obj_t object___new__(mp_obj_t cls) { const mp_obj_type_t *native_base; return MP_OBJ_FROM_PTR(mp_obj_new_instance(MP_OBJ_TO_PTR(cls), &native_base)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(object___new___fun_obj, object___new__); -STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(object___new___obj, MP_ROM_PTR(&object___new___fun_obj)); +static MP_DEFINE_CONST_FUN_OBJ_1(object___new___fun_obj, object___new__); +static MP_DEFINE_CONST_STATICMETHOD_OBJ(object___new___obj, MP_ROM_PTR(&object___new___fun_obj)); #if MICROPY_PY_DELATTR_SETATTR -STATIC mp_obj_t object___setattr__(mp_obj_t self_in, mp_obj_t attr, mp_obj_t value) { +static mp_obj_t object___setattr__(mp_obj_t self_in, mp_obj_t attr, mp_obj_t value) { if (!mp_obj_is_instance_type(mp_obj_get_type(self_in))) { mp_raise_TypeError(MP_ERROR_TEXT("arg must be user-type")); } @@ -75,9 +75,9 @@ STATIC mp_obj_t object___setattr__(mp_obj_t self_in, mp_obj_t attr, mp_obj_t val mp_map_lookup(&self->members, attr, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = value; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(object___setattr___obj, object___setattr__); +static MP_DEFINE_CONST_FUN_OBJ_3(object___setattr___obj, object___setattr__); -STATIC mp_obj_t object___delattr__(mp_obj_t self_in, mp_obj_t attr) { +static mp_obj_t object___delattr__(mp_obj_t self_in, mp_obj_t attr) { if (!mp_obj_is_instance_type(mp_obj_get_type(self_in))) { mp_raise_TypeError(MP_ERROR_TEXT("arg must be user-type")); } @@ -92,10 +92,10 @@ STATIC mp_obj_t object___delattr__(mp_obj_t self_in, mp_obj_t attr) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(object___delattr___obj, object___delattr__); +static MP_DEFINE_CONST_FUN_OBJ_2(object___delattr___obj, object___delattr__); #endif -STATIC const mp_rom_map_elem_t object_locals_dict_table[] = { +static const mp_rom_map_elem_t object_locals_dict_table[] = { #if MICROPY_CPYTHON_COMPAT { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&object___init___obj) }, #endif @@ -108,7 +108,7 @@ STATIC const mp_rom_map_elem_t object_locals_dict_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(object_locals_dict, object_locals_dict_table); +static MP_DEFINE_CONST_DICT(object_locals_dict, object_locals_dict_table); #endif #if MICROPY_CPYTHON_COMPAT diff --git a/py/objpolyiter.c b/py/objpolyiter.c index 78b600abacdcd..65c1f182ec8ec 100644 --- a/py/objpolyiter.c +++ b/py/objpolyiter.c @@ -39,7 +39,7 @@ typedef struct _mp_obj_polymorph_iter_t { mp_fun_1_t iternext; } mp_obj_polymorph_iter_t; -STATIC mp_obj_t polymorph_it_iternext(mp_obj_t self_in) { +static mp_obj_t polymorph_it_iternext(mp_obj_t self_in) { mp_obj_polymorph_iter_t *self = MP_OBJ_TO_PTR(self_in); // Redirect call to object instance's iternext method return self->iternext(self_in); @@ -64,17 +64,17 @@ typedef struct _mp_obj_polymorph_iter_with_finaliser_t { mp_fun_1_t finaliser; } mp_obj_polymorph_with_finaliser_iter_t; -STATIC mp_obj_t mp_obj_polymorph_iter_del(mp_obj_t self_in) { +static mp_obj_t mp_obj_polymorph_iter_del(mp_obj_t self_in) { mp_obj_polymorph_with_finaliser_iter_t *self = MP_OBJ_TO_PTR(self_in); // Redirect call to object instance's finaliser method return self->finaliser(self_in); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_obj_polymorph_iter_del_obj, mp_obj_polymorph_iter_del); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_obj_polymorph_iter_del_obj, mp_obj_polymorph_iter_del); -STATIC const mp_rom_map_elem_t mp_obj_polymorph_iter_locals_dict_table[] = { +static const mp_rom_map_elem_t mp_obj_polymorph_iter_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_obj_polymorph_iter_del_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_obj_polymorph_iter_locals_dict, mp_obj_polymorph_iter_locals_dict_table); +static MP_DEFINE_CONST_DICT(mp_obj_polymorph_iter_locals_dict, mp_obj_polymorph_iter_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mp_type_polymorph_iter_with_finaliser, diff --git a/py/objproperty.c b/py/objproperty.c index 2d3af10e8c70a..155ffb16b58a2 100644 --- a/py/objproperty.c +++ b/py/objproperty.c @@ -36,7 +36,7 @@ typedef struct _mp_obj_property_t { mp_obj_t proxy[3]; // getter, setter, deleter } mp_obj_property_t; -STATIC mp_obj_t property_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t property_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { enum { ARG_fget, ARG_fset, ARG_fdel, ARG_doc }; static const mp_arg_t allowed_args[] = { { MP_QSTR_, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, @@ -55,40 +55,40 @@ STATIC mp_obj_t property_make_new(const mp_obj_type_t *type, size_t n_args, size return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t property_getter(mp_obj_t self_in, mp_obj_t getter) { +static mp_obj_t property_getter(mp_obj_t self_in, mp_obj_t getter) { mp_obj_property_t *p2 = m_new_obj(mp_obj_property_t); *p2 = *(mp_obj_property_t *)MP_OBJ_TO_PTR(self_in); p2->proxy[0] = getter; return MP_OBJ_FROM_PTR(p2); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(property_getter_obj, property_getter); +static MP_DEFINE_CONST_FUN_OBJ_2(property_getter_obj, property_getter); -STATIC mp_obj_t property_setter(mp_obj_t self_in, mp_obj_t setter) { +static mp_obj_t property_setter(mp_obj_t self_in, mp_obj_t setter) { mp_obj_property_t *p2 = m_new_obj(mp_obj_property_t); *p2 = *(mp_obj_property_t *)MP_OBJ_TO_PTR(self_in); p2->proxy[1] = setter; return MP_OBJ_FROM_PTR(p2); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(property_setter_obj, property_setter); +static MP_DEFINE_CONST_FUN_OBJ_2(property_setter_obj, property_setter); -STATIC mp_obj_t property_deleter(mp_obj_t self_in, mp_obj_t deleter) { +static mp_obj_t property_deleter(mp_obj_t self_in, mp_obj_t deleter) { mp_obj_property_t *p2 = m_new_obj(mp_obj_property_t); *p2 = *(mp_obj_property_t *)MP_OBJ_TO_PTR(self_in); p2->proxy[2] = deleter; return MP_OBJ_FROM_PTR(p2); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(property_deleter_obj, property_deleter); +static MP_DEFINE_CONST_FUN_OBJ_2(property_deleter_obj, property_deleter); -STATIC const mp_rom_map_elem_t property_locals_dict_table[] = { +static const mp_rom_map_elem_t property_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_getter), MP_ROM_PTR(&property_getter_obj) }, { MP_ROM_QSTR(MP_QSTR_setter), MP_ROM_PTR(&property_setter_obj) }, { MP_ROM_QSTR(MP_QSTR_deleter), MP_ROM_PTR(&property_deleter_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(property_locals_dict, property_locals_dict_table); +static MP_DEFINE_CONST_DICT(property_locals_dict, property_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mp_type_property, diff --git a/py/objrange.c b/py/objrange.c index f0fe56d9db12e..9a4ecd3fcd7f2 100644 --- a/py/objrange.c +++ b/py/objrange.c @@ -39,7 +39,7 @@ typedef struct _mp_obj_range_it_t { mp_int_t step; } mp_obj_range_it_t; -STATIC mp_obj_t range_it_iternext(mp_obj_t o_in) { +static mp_obj_t range_it_iternext(mp_obj_t o_in) { mp_obj_range_it_t *o = MP_OBJ_TO_PTR(o_in); if ((o->step > 0 && o->cur < o->stop) || (o->step < 0 && o->cur > o->stop)) { mp_obj_t o_out = MP_OBJ_NEW_SMALL_INT(o->cur); @@ -50,14 +50,14 @@ STATIC mp_obj_t range_it_iternext(mp_obj_t o_in) { } } -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_range_it, MP_QSTR_iterator, MP_TYPE_FLAG_ITER_IS_ITERNEXT, iter, range_it_iternext ); -STATIC mp_obj_t mp_obj_new_range_iterator(mp_int_t cur, mp_int_t stop, mp_int_t step, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t mp_obj_new_range_iterator(mp_int_t cur, mp_int_t stop, mp_int_t step, mp_obj_iter_buf_t *iter_buf) { assert(sizeof(mp_obj_range_it_t) <= sizeof(mp_obj_iter_buf_t)); mp_obj_range_it_t *o = (mp_obj_range_it_t *)iter_buf; o->base.type = &mp_type_range_it; @@ -78,7 +78,7 @@ typedef struct _mp_obj_range_t { mp_int_t step; } mp_obj_range_t; -STATIC void range_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void range_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_range_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "range(" INT_FMT ", " INT_FMT "", self->start, self->stop); @@ -89,7 +89,7 @@ STATIC void range_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind } } -STATIC mp_obj_t range_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t range_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 3, false); mp_obj_range_t *o = mp_obj_malloc(mp_obj_range_t, type); @@ -112,7 +112,7 @@ STATIC mp_obj_t range_make_new(const mp_obj_type_t *type, size_t n_args, size_t return MP_OBJ_FROM_PTR(o); } -STATIC mp_int_t range_len(mp_obj_range_t *self) { +static mp_int_t range_len(mp_obj_range_t *self) { // When computing length, need to take into account step!=1 and step<0. mp_int_t len = self->stop - self->start + self->step; if (self->step > 0) { @@ -127,7 +127,7 @@ STATIC mp_int_t range_len(mp_obj_range_t *self) { return len; } -STATIC mp_obj_t range_unary_op(mp_unary_op_t op, mp_obj_t self_in) { +static mp_obj_t range_unary_op(mp_unary_op_t op, mp_obj_t self_in) { mp_obj_range_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t len = range_len(self); switch (op) { @@ -141,7 +141,7 @@ STATIC mp_obj_t range_unary_op(mp_unary_op_t op, mp_obj_t self_in) { } #if MICROPY_PY_BUILTINS_RANGE_BINOP -STATIC mp_obj_t range_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { +static mp_obj_t range_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { if (!mp_obj_is_type(rhs_in, &mp_type_range) || op != MP_BINARY_OP_EQUAL) { return MP_OBJ_NULL; // op not supported } @@ -158,7 +158,7 @@ STATIC mp_obj_t range_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs } #endif -STATIC mp_obj_t range_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { +static mp_obj_t range_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { if (value == MP_OBJ_SENTINEL) { // load mp_obj_range_t *self = MP_OBJ_TO_PTR(self_in); @@ -185,14 +185,14 @@ STATIC mp_obj_t range_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { } } -STATIC mp_obj_t range_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t range_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) { mp_obj_range_t *o = MP_OBJ_TO_PTR(o_in); return mp_obj_new_range_iterator(o->start, o->stop, o->step, iter_buf); } #if MICROPY_PY_BUILTINS_RANGE_ATTRS -STATIC void range_attr(mp_obj_t o_in, qstr attr, mp_obj_t *dest) { +static void range_attr(mp_obj_t o_in, qstr attr, mp_obj_t *dest) { if (dest[0] != MP_OBJ_NULL) { // not load attribute return; diff --git a/py/objreversed.c b/py/objreversed.c index c66698f028adf..c580ee286b76d 100644 --- a/py/objreversed.c +++ b/py/objreversed.c @@ -37,7 +37,7 @@ typedef struct _mp_obj_reversed_t { mp_uint_t cur_index; // current index, plus 1; 0=no more, 1=last one (index 0) } mp_obj_reversed_t; -STATIC mp_obj_t reversed_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t reversed_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 1, false); // check if __reversed__ exists, and if so delegate to it @@ -54,7 +54,7 @@ STATIC mp_obj_t reversed_make_new(const mp_obj_type_t *type, size_t n_args, size return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t reversed_iternext(mp_obj_t self_in) { +static mp_obj_t reversed_iternext(mp_obj_t self_in) { mp_check_self(mp_obj_is_type(self_in, &mp_type_reversed)); mp_obj_reversed_t *self = MP_OBJ_TO_PTR(self_in); diff --git a/py/objset.c b/py/objset.c index 906807889ab36..c8fa12a7ec58f 100644 --- a/py/objset.c +++ b/py/objset.c @@ -45,7 +45,7 @@ typedef struct _mp_obj_set_it_t { size_t cur; } mp_obj_set_it_t; -STATIC bool is_set_or_frozenset(mp_obj_t o) { +static bool is_set_or_frozenset(mp_obj_t o) { return mp_obj_is_type(o, &mp_type_set) #if MICROPY_PY_BUILTINS_FROZENSET || mp_obj_is_type(o, &mp_type_frozenset) @@ -60,7 +60,7 @@ STATIC bool is_set_or_frozenset(mp_obj_t o) { // set or frozenset for methods that operate on both of these types. #define check_set_or_frozenset(o) mp_check_self(is_set_or_frozenset(o)) -STATIC void set_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void set_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in); #if MICROPY_PY_BUILTINS_FROZENSET @@ -99,7 +99,7 @@ STATIC void set_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t #endif } -STATIC mp_obj_t set_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t set_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); switch (n_args) { @@ -127,7 +127,7 @@ STATIC mp_obj_t set_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ } } -STATIC mp_obj_t set_it_iternext(mp_obj_t self_in) { +static mp_obj_t set_it_iternext(mp_obj_t self_in) { mp_obj_set_it_t *self = MP_OBJ_TO_PTR(self_in); size_t max = self->set->set.alloc; mp_set_t *set = &self->set->set; @@ -142,7 +142,7 @@ STATIC mp_obj_t set_it_iternext(mp_obj_t self_in) { return MP_OBJ_STOP_ITERATION; } -STATIC mp_obj_t set_getiter(mp_obj_t set_in, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t set_getiter(mp_obj_t set_in, mp_obj_iter_buf_t *iter_buf) { assert(sizeof(mp_obj_set_it_t) <= sizeof(mp_obj_iter_buf_t)); mp_obj_set_it_t *o = (mp_obj_set_it_t *)iter_buf; o->base.type = &mp_type_polymorph_iter; @@ -155,23 +155,23 @@ STATIC mp_obj_t set_getiter(mp_obj_t set_in, mp_obj_iter_buf_t *iter_buf) { /******************************************************************************/ /* set methods */ -STATIC mp_obj_t set_add(mp_obj_t self_in, mp_obj_t item) { +static mp_obj_t set_add(mp_obj_t self_in, mp_obj_t item) { check_set(self_in); mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in); mp_set_lookup(&self->set, item, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_add_obj, set_add); +static MP_DEFINE_CONST_FUN_OBJ_2(set_add_obj, set_add); -STATIC mp_obj_t set_clear(mp_obj_t self_in) { +static mp_obj_t set_clear(mp_obj_t self_in) { check_set(self_in); mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in); mp_set_clear(&self->set); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(set_clear_obj, set_clear); +static MP_DEFINE_CONST_FUN_OBJ_1(set_clear_obj, set_clear); -STATIC mp_obj_t set_copy(mp_obj_t self_in) { +static mp_obj_t set_copy(mp_obj_t self_in) { check_set_or_frozenset(self_in); mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_set_t *other = mp_obj_malloc(mp_obj_set_t, self->base.type); @@ -180,17 +180,17 @@ STATIC mp_obj_t set_copy(mp_obj_t self_in) { memcpy(other->set.table, self->set.table, self->set.alloc * sizeof(mp_obj_t)); return MP_OBJ_FROM_PTR(other); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(set_copy_obj, set_copy); +static MP_DEFINE_CONST_FUN_OBJ_1(set_copy_obj, set_copy); -STATIC mp_obj_t set_discard(mp_obj_t self_in, mp_obj_t item) { +static mp_obj_t set_discard(mp_obj_t self_in, mp_obj_t item) { check_set(self_in); mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in); mp_set_lookup(&self->set, item, MP_MAP_LOOKUP_REMOVE_IF_FOUND); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_discard_obj, set_discard); +static MP_DEFINE_CONST_FUN_OBJ_2(set_discard_obj, set_discard); -STATIC mp_obj_t set_diff_int(size_t n_args, const mp_obj_t *args, bool update) { +static mp_obj_t set_diff_int(size_t n_args, const mp_obj_t *args, bool update) { mp_obj_t self; if (update) { check_set(args[0]); @@ -216,18 +216,18 @@ STATIC mp_obj_t set_diff_int(size_t n_args, const mp_obj_t *args, bool update) { return self; } -STATIC mp_obj_t set_diff(size_t n_args, const mp_obj_t *args) { +static mp_obj_t set_diff(size_t n_args, const mp_obj_t *args) { return set_diff_int(n_args, args, false); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(set_diff_obj, 1, set_diff); +static MP_DEFINE_CONST_FUN_OBJ_VAR(set_diff_obj, 1, set_diff); -STATIC mp_obj_t set_diff_update(size_t n_args, const mp_obj_t *args) { +static mp_obj_t set_diff_update(size_t n_args, const mp_obj_t *args) { set_diff_int(n_args, args, true); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(set_diff_update_obj, 1, set_diff_update); +static MP_DEFINE_CONST_FUN_OBJ_VAR(set_diff_update_obj, 1, set_diff_update); -STATIC mp_obj_t set_intersect_int(mp_obj_t self_in, mp_obj_t other, bool update) { +static mp_obj_t set_intersect_int(mp_obj_t self_in, mp_obj_t other, bool update) { if (update) { check_set(self_in); } else { @@ -259,17 +259,17 @@ STATIC mp_obj_t set_intersect_int(mp_obj_t self_in, mp_obj_t other, bool update) return update ? mp_const_none : MP_OBJ_FROM_PTR(out); } -STATIC mp_obj_t set_intersect(mp_obj_t self_in, mp_obj_t other) { +static mp_obj_t set_intersect(mp_obj_t self_in, mp_obj_t other) { return set_intersect_int(self_in, other, false); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_intersect_obj, set_intersect); +static MP_DEFINE_CONST_FUN_OBJ_2(set_intersect_obj, set_intersect); -STATIC mp_obj_t set_intersect_update(mp_obj_t self_in, mp_obj_t other) { +static mp_obj_t set_intersect_update(mp_obj_t self_in, mp_obj_t other) { return set_intersect_int(self_in, other, true); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_intersect_update_obj, set_intersect_update); +static MP_DEFINE_CONST_FUN_OBJ_2(set_intersect_update_obj, set_intersect_update); -STATIC mp_obj_t set_isdisjoint(mp_obj_t self_in, mp_obj_t other) { +static mp_obj_t set_isdisjoint(mp_obj_t self_in, mp_obj_t other) { check_set_or_frozenset(self_in); mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in); @@ -283,9 +283,9 @@ STATIC mp_obj_t set_isdisjoint(mp_obj_t self_in, mp_obj_t other) { } return mp_const_true; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_isdisjoint_obj, set_isdisjoint); +static MP_DEFINE_CONST_FUN_OBJ_2(set_isdisjoint_obj, set_isdisjoint); -STATIC mp_obj_t set_issubset_internal(mp_obj_t self_in, mp_obj_t other_in, bool proper) { +static mp_obj_t set_issubset_internal(mp_obj_t self_in, mp_obj_t other_in, bool proper) { mp_obj_set_t *self; bool cleanup_self = false; if (is_set_or_frozenset(self_in)) { @@ -327,25 +327,25 @@ STATIC mp_obj_t set_issubset_internal(mp_obj_t self_in, mp_obj_t other_in, bool return out; } -STATIC mp_obj_t set_issubset(mp_obj_t self_in, mp_obj_t other_in) { +static mp_obj_t set_issubset(mp_obj_t self_in, mp_obj_t other_in) { return set_issubset_internal(self_in, other_in, false); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_issubset_obj, set_issubset); +static MP_DEFINE_CONST_FUN_OBJ_2(set_issubset_obj, set_issubset); -STATIC mp_obj_t set_issubset_proper(mp_obj_t self_in, mp_obj_t other_in) { +static mp_obj_t set_issubset_proper(mp_obj_t self_in, mp_obj_t other_in) { return set_issubset_internal(self_in, other_in, true); } -STATIC mp_obj_t set_issuperset(mp_obj_t self_in, mp_obj_t other_in) { +static mp_obj_t set_issuperset(mp_obj_t self_in, mp_obj_t other_in) { return set_issubset_internal(other_in, self_in, false); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_issuperset_obj, set_issuperset); +static MP_DEFINE_CONST_FUN_OBJ_2(set_issuperset_obj, set_issuperset); -STATIC mp_obj_t set_issuperset_proper(mp_obj_t self_in, mp_obj_t other_in) { +static mp_obj_t set_issuperset_proper(mp_obj_t self_in, mp_obj_t other_in) { return set_issubset_internal(other_in, self_in, true); } -STATIC mp_obj_t set_equal(mp_obj_t self_in, mp_obj_t other_in) { +static mp_obj_t set_equal(mp_obj_t self_in, mp_obj_t other_in) { assert(is_set_or_frozenset(other_in)); check_set_or_frozenset(self_in); mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in); @@ -356,7 +356,7 @@ STATIC mp_obj_t set_equal(mp_obj_t self_in, mp_obj_t other_in) { return set_issubset(self_in, other_in); } -STATIC mp_obj_t set_pop(mp_obj_t self_in) { +static mp_obj_t set_pop(mp_obj_t self_in) { check_set(self_in); mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_t obj = mp_set_remove_first(&self->set); @@ -365,9 +365,9 @@ STATIC mp_obj_t set_pop(mp_obj_t self_in) { } return obj; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(set_pop_obj, set_pop); +static MP_DEFINE_CONST_FUN_OBJ_1(set_pop_obj, set_pop); -STATIC mp_obj_t set_remove(mp_obj_t self_in, mp_obj_t item) { +static mp_obj_t set_remove(mp_obj_t self_in, mp_obj_t item) { check_set(self_in); mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in); if (mp_set_lookup(&self->set, item, MP_MAP_LOOKUP_REMOVE_IF_FOUND) == MP_OBJ_NULL) { @@ -375,9 +375,9 @@ STATIC mp_obj_t set_remove(mp_obj_t self_in, mp_obj_t item) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_remove_obj, set_remove); +static MP_DEFINE_CONST_FUN_OBJ_2(set_remove_obj, set_remove); -STATIC mp_obj_t set_symmetric_difference_update(mp_obj_t self_in, mp_obj_t other_in) { +static mp_obj_t set_symmetric_difference_update(mp_obj_t self_in, mp_obj_t other_in) { check_set_or_frozenset(self_in); // can be frozenset due to call from set_symmetric_difference mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_t iter = mp_getiter(other_in, NULL); @@ -387,16 +387,16 @@ STATIC mp_obj_t set_symmetric_difference_update(mp_obj_t self_in, mp_obj_t other } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_symmetric_difference_update_obj, set_symmetric_difference_update); +static MP_DEFINE_CONST_FUN_OBJ_2(set_symmetric_difference_update_obj, set_symmetric_difference_update); -STATIC mp_obj_t set_symmetric_difference(mp_obj_t self_in, mp_obj_t other_in) { +static mp_obj_t set_symmetric_difference(mp_obj_t self_in, mp_obj_t other_in) { mp_obj_t self_out = set_copy(self_in); set_symmetric_difference_update(self_out, other_in); return self_out; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_symmetric_difference_obj, set_symmetric_difference); +static MP_DEFINE_CONST_FUN_OBJ_2(set_symmetric_difference_obj, set_symmetric_difference); -STATIC void set_update_int(mp_obj_set_t *self, mp_obj_t other_in) { +static void set_update_int(mp_obj_set_t *self, mp_obj_t other_in) { mp_obj_t iter = mp_getiter(other_in, NULL); mp_obj_t next; while ((next = mp_iternext(iter)) != MP_OBJ_STOP_ITERATION) { @@ -404,7 +404,7 @@ STATIC void set_update_int(mp_obj_set_t *self, mp_obj_t other_in) { } } -STATIC mp_obj_t set_update(size_t n_args, const mp_obj_t *args) { +static mp_obj_t set_update(size_t n_args, const mp_obj_t *args) { check_set(args[0]); for (size_t i = 1; i < n_args; i++) { set_update_int(MP_OBJ_TO_PTR(args[0]), args[i]); @@ -412,17 +412,17 @@ STATIC mp_obj_t set_update(size_t n_args, const mp_obj_t *args) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(set_update_obj, 1, set_update); +static MP_DEFINE_CONST_FUN_OBJ_VAR(set_update_obj, 1, set_update); -STATIC mp_obj_t set_union(mp_obj_t self_in, mp_obj_t other_in) { +static mp_obj_t set_union(mp_obj_t self_in, mp_obj_t other_in) { check_set_or_frozenset(self_in); mp_obj_t self = set_copy(self_in); set_update_int(MP_OBJ_TO_PTR(self), other_in); return self; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_union_obj, set_union); +static MP_DEFINE_CONST_FUN_OBJ_2(set_union_obj, set_union); -STATIC mp_obj_t set_unary_op(mp_unary_op_t op, mp_obj_t self_in) { +static mp_obj_t set_unary_op(mp_unary_op_t op, mp_obj_t self_in) { mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in); switch (op) { case MP_UNARY_OP_BOOL: @@ -451,7 +451,7 @@ STATIC mp_obj_t set_unary_op(mp_unary_op_t op, mp_obj_t self_in) { } } -STATIC mp_obj_t set_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) { +static mp_obj_t set_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) { mp_obj_t args[] = {lhs, rhs}; #if MICROPY_PY_BUILTINS_FROZENSET bool update = mp_obj_is_type(lhs, &mp_type_set); @@ -517,7 +517,7 @@ STATIC mp_obj_t set_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) { /******************************************************************************/ /* set constructors & public C API */ -STATIC const mp_rom_map_elem_t set_locals_dict_table[] = { +static const mp_rom_map_elem_t set_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_add), MP_ROM_PTR(&set_add_obj) }, { MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&set_clear_obj) }, { MP_ROM_QSTR(MP_QSTR_copy), MP_ROM_PTR(&set_copy_obj) }, @@ -537,7 +537,7 @@ STATIC const mp_rom_map_elem_t set_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&set_update_obj) }, { MP_ROM_QSTR(MP_QSTR___contains__), MP_ROM_PTR(&mp_op_contains_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(set_locals_dict, set_locals_dict_table); +static MP_DEFINE_CONST_DICT(set_locals_dict, set_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mp_type_set, @@ -552,7 +552,7 @@ MP_DEFINE_CONST_OBJ_TYPE( ); #if MICROPY_PY_BUILTINS_FROZENSET -STATIC const mp_rom_map_elem_t frozenset_locals_dict_table[] = { +static const mp_rom_map_elem_t frozenset_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_copy), MP_ROM_PTR(&set_copy_obj) }, { MP_ROM_QSTR(MP_QSTR_difference), MP_ROM_PTR(&set_diff_obj) }, { MP_ROM_QSTR(MP_QSTR_intersection), MP_ROM_PTR(&set_intersect_obj) }, @@ -563,7 +563,7 @@ STATIC const mp_rom_map_elem_t frozenset_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_union), MP_ROM_PTR(&set_union_obj) }, { MP_ROM_QSTR(MP_QSTR___contains__), MP_ROM_PTR(&mp_op_contains_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(frozenset_locals_dict, frozenset_locals_dict_table); +static MP_DEFINE_CONST_DICT(frozenset_locals_dict, frozenset_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mp_type_frozenset, diff --git a/py/objsingleton.c b/py/objsingleton.c index 6537676c52329..c1f102c94c014 100644 --- a/py/objsingleton.c +++ b/py/objsingleton.c @@ -37,7 +37,7 @@ typedef struct _mp_obj_singleton_t { qstr name; } mp_obj_singleton_t; -STATIC void singleton_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void singleton_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_singleton_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "%q", self->name); diff --git a/py/objslice.c b/py/objslice.c index dcd6af8b2856f..3e7575522b28d 100644 --- a/py/objslice.c +++ b/py/objslice.c @@ -34,7 +34,7 @@ #if MICROPY_PY_BUILTINS_SLICE -STATIC void slice_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +static void slice_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; mp_obj_slice_t *o = MP_OBJ_TO_PTR(o_in); mp_print_str(print, "slice("); @@ -46,14 +46,14 @@ STATIC void slice_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t mp_print_str(print, ")"); } -STATIC mp_obj_t slice_unary_op(mp_unary_op_t op, mp_obj_t o_in) { +static mp_obj_t slice_unary_op(mp_unary_op_t op, mp_obj_t o_in) { // Needed to explicitly opt out of default __hash__. // REVISIT: CPython implements comparison operators for slice. return MP_OBJ_NULL; } #if MICROPY_PY_BUILTINS_SLICE_INDICES -STATIC mp_obj_t slice_indices(mp_obj_t self_in, mp_obj_t length_obj) { +static mp_obj_t slice_indices(mp_obj_t self_in, mp_obj_t length_obj) { mp_int_t length = mp_obj_get_int(length_obj); mp_bound_slice_t bound_indices; mp_obj_slice_indices(self_in, length, &bound_indices); @@ -65,11 +65,11 @@ STATIC mp_obj_t slice_indices(mp_obj_t self_in, mp_obj_t length_obj) { }; return mp_obj_new_tuple(3, results); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(slice_indices_obj, slice_indices); +static MP_DEFINE_CONST_FUN_OBJ_2(slice_indices_obj, slice_indices); #endif #if MICROPY_PY_BUILTINS_SLICE_ATTRS -STATIC void slice_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void slice_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] != MP_OBJ_NULL) { // not load attribute return; @@ -92,10 +92,10 @@ STATIC void slice_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { #endif #if MICROPY_PY_BUILTINS_SLICE_INDICES && !MICROPY_PY_BUILTINS_SLICE_ATTRS -STATIC const mp_rom_map_elem_t slice_locals_dict_table[] = { +static const mp_rom_map_elem_t slice_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_indices), MP_ROM_PTR(&slice_indices_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(slice_locals_dict, slice_locals_dict_table); +static MP_DEFINE_CONST_DICT(slice_locals_dict, slice_locals_dict_table); #endif #if MICROPY_PY_BUILTINS_SLICE_ATTRS diff --git a/py/objstr.c b/py/objstr.c index 5dfe94ac4fe1c..c7e4ebf53b753 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -35,15 +35,15 @@ #include "py/stackctrl.h" #if MICROPY_PY_BUILTINS_STR_OP_MODULO -STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_t *args, mp_obj_t dict); +static mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_t *args, mp_obj_t dict); #endif -STATIC mp_obj_t mp_obj_new_bytes_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf); -STATIC NORETURN void bad_implicit_conversion(mp_obj_t self_in); +static mp_obj_t mp_obj_new_bytes_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf); +static NORETURN void bad_implicit_conversion(mp_obj_t self_in); -STATIC mp_obj_t mp_obj_new_str_type_from_vstr(const mp_obj_type_t *type, vstr_t *vstr); +static mp_obj_t mp_obj_new_str_type_from_vstr(const mp_obj_type_t *type, vstr_t *vstr); -STATIC void str_check_arg_type(const mp_obj_type_t *self_type, const mp_obj_t arg) { +static void str_check_arg_type(const mp_obj_type_t *self_type, const mp_obj_t arg) { // String operations generally need the args type to match the object they're called on, // e.g. str.find(str), byte.startswith(byte) // with the exception that bytes may be used for bytearray and vice versa. @@ -63,7 +63,7 @@ STATIC void str_check_arg_type(const mp_obj_type_t *self_type, const mp_obj_t ar } } -STATIC void check_is_str_or_bytes(mp_obj_t self_in) { +static void check_is_str_or_bytes(mp_obj_t self_in) { mp_check_self(mp_obj_is_str_or_bytes(self_in)); } @@ -135,7 +135,7 @@ void mp_str_print_json(const mp_print_t *print, const byte *str_data, size_t str } #endif -STATIC void str_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void str_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { GET_STR_DATA_LEN(self_in, str_data, str_len); #if MICROPY_PY_JSON if (kind == PRINT_JSON) { @@ -212,7 +212,7 @@ mp_obj_t mp_obj_str_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ } } -STATIC mp_obj_t bytes_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t bytes_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; #if MICROPY_CPYTHON_COMPAT @@ -458,7 +458,7 @@ const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, s #endif // This is used for both bytes and 8-bit strings. This is not used for unicode strings. -STATIC mp_obj_t bytes_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { +static mp_obj_t bytes_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { const mp_obj_type_t *type = mp_obj_get_type(self_in); GET_STR_DATA_LEN(self_in, self_data, self_len); if (value == MP_OBJ_SENTINEL) { @@ -484,7 +484,7 @@ STATIC mp_obj_t bytes_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { } } -STATIC mp_obj_t str_join(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t str_join(mp_obj_t self_in, mp_obj_t arg) { check_is_str_or_bytes(self_in); const mp_obj_type_t *self_type = mp_obj_get_type(self_in); const mp_obj_type_t *ret_type = self_type; @@ -628,7 +628,7 @@ mp_obj_t mp_obj_str_split(size_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_split_obj, 1, 3, mp_obj_str_split); #if MICROPY_PY_BUILTINS_STR_SPLITLINES -STATIC mp_obj_t str_splitlines(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t str_splitlines(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_keepends }; static const mp_arg_t allowed_args[] = { { MP_QSTR_keepends, MP_ARG_BOOL, {.u_bool = false} }, @@ -674,7 +674,7 @@ STATIC mp_obj_t str_splitlines(size_t n_args, const mp_obj_t *pos_args, mp_map_t MP_DEFINE_CONST_FUN_OBJ_KW(str_splitlines_obj, 1, str_splitlines); #endif -STATIC mp_obj_t str_rsplit(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_rsplit(size_t n_args, const mp_obj_t *args) { if (n_args < 3) { // If we don't have split limit, it doesn't matter from which side // we split. @@ -739,7 +739,7 @@ STATIC mp_obj_t str_rsplit(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_rsplit_obj, 1, 3, str_rsplit); -STATIC mp_obj_t str_finder(size_t n_args, const mp_obj_t *args, int direction, bool is_index) { +static mp_obj_t str_finder(size_t n_args, const mp_obj_t *args, int direction, bool is_index) { const mp_obj_type_t *self_type = mp_obj_get_type(args[0]); check_is_str_or_bytes(args[0]); @@ -782,28 +782,28 @@ STATIC mp_obj_t str_finder(size_t n_args, const mp_obj_t *args, int direction, b } } -STATIC mp_obj_t str_find(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_find(size_t n_args, const mp_obj_t *args) { return str_finder(n_args, args, 1, false); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_find_obj, 2, 4, str_find); -STATIC mp_obj_t str_rfind(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_rfind(size_t n_args, const mp_obj_t *args) { return str_finder(n_args, args, -1, false); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_rfind_obj, 2, 4, str_rfind); -STATIC mp_obj_t str_index(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_index(size_t n_args, const mp_obj_t *args) { return str_finder(n_args, args, 1, true); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_index_obj, 2, 4, str_index); -STATIC mp_obj_t str_rindex(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_rindex(size_t n_args, const mp_obj_t *args) { return str_finder(n_args, args, -1, true); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_rindex_obj, 2, 4, str_rindex); // TODO: (Much) more variety in args -STATIC mp_obj_t str_startswith(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_startswith(size_t n_args, const mp_obj_t *args) { const mp_obj_type_t *self_type = mp_obj_get_type(args[0]); GET_STR_DATA_LEN(args[0], str, str_len); size_t prefix_len; @@ -819,7 +819,7 @@ STATIC mp_obj_t str_startswith(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_startswith_obj, 2, 3, str_startswith); -STATIC mp_obj_t str_endswith(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_endswith(size_t n_args, const mp_obj_t *args) { GET_STR_DATA_LEN(args[0], str, str_len); size_t suffix_len; const char *suffix = mp_obj_str_get_data(args[1], &suffix_len); @@ -836,7 +836,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_endswith_obj, 2, 3, str_endswith); enum { LSTRIP, RSTRIP, STRIP }; -STATIC mp_obj_t str_uni_strip(int type, size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_uni_strip(int type, size_t n_args, const mp_obj_t *args) { check_is_str_or_bytes(args[0]); const mp_obj_type_t *self_type = mp_obj_get_type(args[0]); @@ -905,23 +905,23 @@ STATIC mp_obj_t str_uni_strip(int type, size_t n_args, const mp_obj_t *args) { return mp_obj_new_str_of_type(self_type, orig_str + first_good_char_pos, stripped_len); } -STATIC mp_obj_t str_strip(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_strip(size_t n_args, const mp_obj_t *args) { return str_uni_strip(STRIP, n_args, args); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_strip_obj, 1, 2, str_strip); -STATIC mp_obj_t str_lstrip(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_lstrip(size_t n_args, const mp_obj_t *args) { return str_uni_strip(LSTRIP, n_args, args); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_lstrip_obj, 1, 2, str_lstrip); -STATIC mp_obj_t str_rstrip(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_rstrip(size_t n_args, const mp_obj_t *args) { return str_uni_strip(RSTRIP, n_args, args); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_rstrip_obj, 1, 2, str_rstrip); #if MICROPY_PY_BUILTINS_STR_CENTER -STATIC mp_obj_t str_center(mp_obj_t str_in, mp_obj_t width_in) { +static mp_obj_t str_center(mp_obj_t str_in, mp_obj_t width_in) { GET_STR_DATA_LEN(str_in, str, str_len); mp_uint_t width = mp_obj_get_int(width_in); if (str_len >= width) { @@ -940,7 +940,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(str_center_obj, str_center); // Takes an int arg, but only parses unsigned numbers, and only changes // *num if at least one digit was parsed. -STATIC const char *str_to_int(const char *str, const char *top, int *num) { +static const char *str_to_int(const char *str, const char *top, int *num) { if (str < top && '0' <= *str && *str <= '9') { *num = 0; do { @@ -952,19 +952,19 @@ STATIC const char *str_to_int(const char *str, const char *top, int *num) { return str; } -STATIC bool isalignment(char ch) { +static bool isalignment(char ch) { return ch && strchr("<>=^", ch) != NULL; } -STATIC bool istype(char ch) { +static bool istype(char ch) { return ch && strchr("bcdeEfFgGnosxX%", ch) != NULL; } -STATIC bool arg_looks_integer(mp_obj_t arg) { +static bool arg_looks_integer(mp_obj_t arg) { return mp_obj_is_bool(arg) || mp_obj_is_int(arg); } -STATIC bool arg_looks_numeric(mp_obj_t arg) { +static bool arg_looks_numeric(mp_obj_t arg) { return arg_looks_integer(arg) #if MICROPY_PY_BUILTINS_FLOAT || mp_obj_is_float(arg) @@ -973,7 +973,7 @@ STATIC bool arg_looks_numeric(mp_obj_t arg) { } #if MICROPY_PY_BUILTINS_STR_OP_MODULO -STATIC mp_obj_t arg_as_int(mp_obj_t arg) { +static mp_obj_t arg_as_int(mp_obj_t arg) { #if MICROPY_PY_BUILTINS_FLOAT if (mp_obj_is_float(arg)) { return mp_obj_new_int_from_float(mp_obj_float_get(arg)); @@ -984,7 +984,7 @@ STATIC mp_obj_t arg_as_int(mp_obj_t arg) { #endif #if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE -STATIC NORETURN void terse_str_format_value_error(void) { +static NORETURN void terse_str_format_value_error(void) { mp_raise_ValueError(MP_ERROR_TEXT("bad format string")); } #else @@ -992,7 +992,7 @@ STATIC NORETURN void terse_str_format_value_error(void) { #define terse_str_format_value_error() #endif -STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *arg_i, size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { +static vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *arg_i, size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { vstr_t vstr; mp_print_t print; vstr_init_print(&vstr, 16, &print); @@ -1449,7 +1449,7 @@ mp_obj_t mp_obj_str_format(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs MP_DEFINE_CONST_FUN_OBJ_KW(str_format_obj, 1, mp_obj_str_format); #if MICROPY_PY_BUILTINS_STR_OP_MODULO -STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_t *args, mp_obj_t dict) { +static mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_t *args, mp_obj_t dict) { check_is_str_or_bytes(pattern); GET_STR_DATA_LEN(pattern, str, len); @@ -1657,7 +1657,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_ // The implementation is optimized, returning the original string if there's // nothing to replace. -STATIC mp_obj_t str_replace(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_replace(size_t n_args, const mp_obj_t *args) { check_is_str_or_bytes(args[0]); mp_int_t max_rep = -1; @@ -1759,7 +1759,7 @@ STATIC mp_obj_t str_replace(size_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_replace_obj, 3, 4, str_replace); #if MICROPY_PY_BUILTINS_STR_COUNT -STATIC mp_obj_t str_count(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_count(size_t n_args, const mp_obj_t *args) { const mp_obj_type_t *self_type = mp_obj_get_type(args[0]); check_is_str_or_bytes(args[0]); @@ -1802,7 +1802,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_count_obj, 2, 4, str_count); #endif #if MICROPY_PY_BUILTINS_STR_PARTITION -STATIC mp_obj_t str_partitioner(mp_obj_t self_in, mp_obj_t arg, int direction) { +static mp_obj_t str_partitioner(mp_obj_t self_in, mp_obj_t arg, int direction) { check_is_str_or_bytes(self_in); const mp_obj_type_t *self_type = mp_obj_get_type(self_in); str_check_arg_type(self_type, arg); @@ -1848,19 +1848,19 @@ STATIC mp_obj_t str_partitioner(mp_obj_t self_in, mp_obj_t arg, int direction) { return mp_obj_new_tuple(3, result); } -STATIC mp_obj_t str_partition(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t str_partition(mp_obj_t self_in, mp_obj_t arg) { return str_partitioner(self_in, arg, 1); } MP_DEFINE_CONST_FUN_OBJ_2(str_partition_obj, str_partition); -STATIC mp_obj_t str_rpartition(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t str_rpartition(mp_obj_t self_in, mp_obj_t arg) { return str_partitioner(self_in, arg, -1); } MP_DEFINE_CONST_FUN_OBJ_2(str_rpartition_obj, str_rpartition); #endif // Supposedly not too critical operations, so optimize for code size -STATIC mp_obj_t str_caseconv(unichar (*op)(unichar), mp_obj_t self_in) { +static mp_obj_t str_caseconv(unichar (*op)(unichar), mp_obj_t self_in) { GET_STR_DATA_LEN(self_in, self_data, self_len); vstr_t vstr; vstr_init_len(&vstr, self_len); @@ -1871,17 +1871,17 @@ STATIC mp_obj_t str_caseconv(unichar (*op)(unichar), mp_obj_t self_in) { return mp_obj_new_str_type_from_vstr(mp_obj_get_type(self_in), &vstr); } -STATIC mp_obj_t str_lower(mp_obj_t self_in) { +static mp_obj_t str_lower(mp_obj_t self_in) { return str_caseconv(unichar_tolower, self_in); } MP_DEFINE_CONST_FUN_OBJ_1(str_lower_obj, str_lower); -STATIC mp_obj_t str_upper(mp_obj_t self_in) { +static mp_obj_t str_upper(mp_obj_t self_in) { return str_caseconv(unichar_toupper, self_in); } MP_DEFINE_CONST_FUN_OBJ_1(str_upper_obj, str_upper); -STATIC mp_obj_t str_uni_istype(bool (*f)(unichar), mp_obj_t self_in) { +static mp_obj_t str_uni_istype(bool (*f)(unichar), mp_obj_t self_in) { GET_STR_DATA_LEN(self_in, self_data, self_len); if (self_len == 0) { @@ -1914,27 +1914,27 @@ STATIC mp_obj_t str_uni_istype(bool (*f)(unichar), mp_obj_t self_in) { return mp_const_true; } -STATIC mp_obj_t str_isspace(mp_obj_t self_in) { +static mp_obj_t str_isspace(mp_obj_t self_in) { return str_uni_istype(unichar_isspace, self_in); } MP_DEFINE_CONST_FUN_OBJ_1(str_isspace_obj, str_isspace); -STATIC mp_obj_t str_isalpha(mp_obj_t self_in) { +static mp_obj_t str_isalpha(mp_obj_t self_in) { return str_uni_istype(unichar_isalpha, self_in); } MP_DEFINE_CONST_FUN_OBJ_1(str_isalpha_obj, str_isalpha); -STATIC mp_obj_t str_isdigit(mp_obj_t self_in) { +static mp_obj_t str_isdigit(mp_obj_t self_in) { return str_uni_istype(unichar_isdigit, self_in); } MP_DEFINE_CONST_FUN_OBJ_1(str_isdigit_obj, str_isdigit); -STATIC mp_obj_t str_isupper(mp_obj_t self_in) { +static mp_obj_t str_isupper(mp_obj_t self_in) { return str_uni_istype(unichar_isupper, self_in); } MP_DEFINE_CONST_FUN_OBJ_1(str_isupper_obj, str_isupper); -STATIC mp_obj_t str_islower(mp_obj_t self_in) { +static mp_obj_t str_islower(mp_obj_t self_in) { return str_uni_istype(unichar_islower, self_in); } MP_DEFINE_CONST_FUN_OBJ_1(str_islower_obj, str_islower); @@ -1943,7 +1943,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(str_islower_obj, str_islower); // These methods are superfluous in the presence of str() and bytes() // constructors. // TODO: should accept kwargs too -STATIC mp_obj_t bytes_decode(size_t n_args, const mp_obj_t *args) { +static mp_obj_t bytes_decode(size_t n_args, const mp_obj_t *args) { mp_obj_t new_args[2]; if (n_args == 1) { new_args[0] = args[0]; @@ -1956,7 +1956,7 @@ STATIC mp_obj_t bytes_decode(size_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bytes_decode_obj, 1, 3, bytes_decode); // TODO: should accept kwargs too -STATIC mp_obj_t str_encode(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_encode(size_t n_args, const mp_obj_t *args) { mp_obj_t new_args[2]; if (n_args == 1) { new_args[0] = args[0]; @@ -2038,13 +2038,13 @@ mp_obj_t mp_obj_bytes_fromhex(mp_obj_t type_in, mp_obj_t data) { return mp_obj_new_str_type_from_vstr(MP_OBJ_TO_PTR(type_in), &vstr); } -STATIC mp_obj_t bytes_hex_as_str(size_t n_args, const mp_obj_t *args) { +static mp_obj_t bytes_hex_as_str(size_t n_args, const mp_obj_t *args) { return mp_obj_bytes_hex(n_args, args, &mp_type_str); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bytes_hex_as_str_obj, 1, 2, bytes_hex_as_str); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bytes_hex_as_str_obj, 1, 2, bytes_hex_as_str); -STATIC MP_DEFINE_CONST_FUN_OBJ_2(bytes_fromhex_obj, mp_obj_bytes_fromhex); -STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(bytes_fromhex_classmethod_obj, MP_ROM_PTR(&bytes_fromhex_obj)); +static MP_DEFINE_CONST_FUN_OBJ_2(bytes_fromhex_obj, mp_obj_bytes_fromhex); +static MP_DEFINE_CONST_CLASSMETHOD_OBJ(bytes_fromhex_classmethod_obj, MP_ROM_PTR(&bytes_fromhex_obj)); #endif // MICROPY_PY_BUILTINS_BYTES_HEX mp_int_t mp_obj_str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { @@ -2068,7 +2068,7 @@ void mp_obj_str_set_data(mp_obj_str_t *str, const byte *data, size_t len) { // This locals table is used for the following types: str, bytes, bytearray, array.array. // Each type takes a different section (start to end offset) of this table. -STATIC const mp_rom_map_elem_t array_bytearray_str_bytes_locals_table[] = { +static const mp_rom_map_elem_t array_bytearray_str_bytes_locals_table[] = { #if MICROPY_PY_ARRAY || MICROPY_PY_BUILTINS_BYTEARRAY { MP_ROM_QSTR(MP_QSTR_append), MP_ROM_PTR(&mp_obj_array_append_obj) }, { MP_ROM_QSTR(MP_QSTR_extend), MP_ROM_PTR(&mp_obj_array_extend_obj) }, @@ -2168,7 +2168,7 @@ MP_DEFINE_CONST_DICT_WITH_SIZE(mp_obj_memoryview_locals_dict, #endif #if !MICROPY_PY_BUILTINS_STR_UNICODE -STATIC mp_obj_t mp_obj_new_str_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf); +static mp_obj_t mp_obj_new_str_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf); MP_DEFINE_CONST_OBJ_TYPE( mp_type_str, @@ -2240,7 +2240,7 @@ mp_obj_t mp_obj_new_str_via_qstr(const char *data, size_t len) { // Create a str/bytes object from the given vstr. The vstr buffer is resized to // the exact length required and then reused for the str/bytes object. The vstr // is cleared and can safely be passed to vstr_free if it was heap allocated. -STATIC mp_obj_t mp_obj_new_str_type_from_vstr(const mp_obj_type_t *type, vstr_t *vstr) { +static mp_obj_t mp_obj_new_str_type_from_vstr(const mp_obj_type_t *type, vstr_t *vstr) { // if not a bytes object, look if a qstr with this data already exists if (type == &mp_type_str) { qstr q = qstr_find_strn(vstr->buf, vstr->len); @@ -2342,7 +2342,7 @@ bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2) { } } -STATIC NORETURN void bad_implicit_conversion(mp_obj_t self_in) { +static NORETURN void bad_implicit_conversion(mp_obj_t self_in) { #if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE mp_raise_TypeError(MP_ERROR_TEXT("can't convert to str implicitly")); #else @@ -2411,7 +2411,7 @@ typedef struct _mp_obj_str8_it_t { } mp_obj_str8_it_t; #if !MICROPY_PY_BUILTINS_STR_UNICODE -STATIC mp_obj_t str_it_iternext(mp_obj_t self_in) { +static mp_obj_t str_it_iternext(mp_obj_t self_in) { mp_obj_str8_it_t *self = MP_OBJ_TO_PTR(self_in); GET_STR_DATA_LEN(self->str, str, len); if (self->cur < len) { @@ -2423,7 +2423,7 @@ STATIC mp_obj_t str_it_iternext(mp_obj_t self_in) { } } -STATIC mp_obj_t mp_obj_new_str_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t mp_obj_new_str_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf) { assert(sizeof(mp_obj_str8_it_t) <= sizeof(mp_obj_iter_buf_t)); mp_obj_str8_it_t *o = (mp_obj_str8_it_t *)iter_buf; o->base.type = &mp_type_polymorph_iter; @@ -2434,7 +2434,7 @@ STATIC mp_obj_t mp_obj_new_str_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_bu } #endif -STATIC mp_obj_t bytes_it_iternext(mp_obj_t self_in) { +static mp_obj_t bytes_it_iternext(mp_obj_t self_in) { mp_obj_str8_it_t *self = MP_OBJ_TO_PTR(self_in); GET_STR_DATA_LEN(self->str, str, len); if (self->cur < len) { diff --git a/py/objstringio.c b/py/objstringio.c index a3c66ed010cc0..a4dc8cfc9151b 100644 --- a/py/objstringio.c +++ b/py/objstringio.c @@ -36,7 +36,7 @@ #if MICROPY_PY_IO #if MICROPY_CPYTHON_COMPAT -STATIC void check_stringio_is_open(const mp_obj_stringio_t *o) { +static void check_stringio_is_open(const mp_obj_stringio_t *o) { if (o->vstr == NULL) { mp_raise_ValueError(MP_ERROR_TEXT("I/O operation on closed file")); } @@ -45,13 +45,13 @@ STATIC void check_stringio_is_open(const mp_obj_stringio_t *o) { #define check_stringio_is_open(o) #endif -STATIC void stringio_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void stringio_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_stringio_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, self->base.type == &mp_type_stringio ? "" : "", self); } -STATIC mp_uint_t stringio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t stringio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { (void)errcode; mp_obj_stringio_t *o = MP_OBJ_TO_PTR(o_in); check_stringio_is_open(o); @@ -67,7 +67,7 @@ STATIC mp_uint_t stringio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *er return size; } -STATIC void stringio_copy_on_write(mp_obj_stringio_t *o) { +static void stringio_copy_on_write(mp_obj_stringio_t *o) { const void *buf = o->vstr->buf; o->vstr->buf = m_new(char, o->vstr->len); o->vstr->fixed_buf = false; @@ -75,7 +75,7 @@ STATIC void stringio_copy_on_write(mp_obj_stringio_t *o) { memcpy(o->vstr->buf, buf, o->vstr->len); } -STATIC mp_uint_t stringio_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t stringio_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) { (void)errcode; mp_obj_stringio_t *o = MP_OBJ_TO_PTR(o_in); check_stringio_is_open(o); @@ -109,7 +109,7 @@ STATIC mp_uint_t stringio_write(mp_obj_t o_in, const void *buf, mp_uint_t size, return size; } -STATIC mp_uint_t stringio_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t stringio_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { (void)errcode; mp_obj_stringio_t *o = MP_OBJ_TO_PTR(o_in); switch (request) { @@ -162,22 +162,22 @@ STATIC mp_uint_t stringio_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, #define STREAM_TO_CONTENT_TYPE(o) (((o)->base.type == &mp_type_stringio) ? &mp_type_str : &mp_type_bytes) -STATIC mp_obj_t stringio_getvalue(mp_obj_t self_in) { +static mp_obj_t stringio_getvalue(mp_obj_t self_in) { mp_obj_stringio_t *self = MP_OBJ_TO_PTR(self_in); check_stringio_is_open(self); // TODO: Try to avoid copying string return mp_obj_new_str_of_type(STREAM_TO_CONTENT_TYPE(self), (byte *)self->vstr->buf, self->vstr->len); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(stringio_getvalue_obj, stringio_getvalue); +static MP_DEFINE_CONST_FUN_OBJ_1(stringio_getvalue_obj, stringio_getvalue); -STATIC mp_obj_stringio_t *stringio_new(const mp_obj_type_t *type) { +static mp_obj_stringio_t *stringio_new(const mp_obj_type_t *type) { mp_obj_stringio_t *o = mp_obj_malloc(mp_obj_stringio_t, type); o->pos = 0; o->ref_obj = MP_OBJ_NULL; return o; } -STATIC mp_obj_t stringio_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t stringio_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)n_kw; // TODO check n_kw==0 mp_uint_t sz = 16; @@ -215,7 +215,7 @@ STATIC mp_obj_t stringio_make_new(const mp_obj_type_t *type_in, size_t n_args, s return MP_OBJ_FROM_PTR(o); } -STATIC const mp_rom_map_elem_t stringio_locals_dict_table[] = { +static const mp_rom_map_elem_t stringio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) }, { MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) }, @@ -229,9 +229,9 @@ STATIC const mp_rom_map_elem_t stringio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&mp_stream___exit___obj) }, }; -STATIC MP_DEFINE_CONST_DICT(stringio_locals_dict, stringio_locals_dict_table); +static MP_DEFINE_CONST_DICT(stringio_locals_dict, stringio_locals_dict_table); -STATIC const mp_stream_p_t stringio_stream_p = { +static const mp_stream_p_t stringio_stream_p = { .read = stringio_read, .write = stringio_write, .ioctl = stringio_ioctl, @@ -249,7 +249,7 @@ MP_DEFINE_CONST_OBJ_TYPE( ); #if MICROPY_PY_IO_BYTESIO -STATIC const mp_stream_p_t bytesio_stream_p = { +static const mp_stream_p_t bytesio_stream_p = { .read = stringio_read, .write = stringio_write, .ioctl = stringio_ioctl, diff --git a/py/objstrunicode.c b/py/objstrunicode.c index cbc797de29128..d7ce4fca0e58e 100644 --- a/py/objstrunicode.c +++ b/py/objstrunicode.c @@ -34,12 +34,12 @@ #if MICROPY_PY_BUILTINS_STR_UNICODE -STATIC mp_obj_t mp_obj_new_str_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf); +static mp_obj_t mp_obj_new_str_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf); /******************************************************************************/ /* str */ -STATIC void uni_print_quoted(const mp_print_t *print, const byte *str_data, uint str_len) { +static void uni_print_quoted(const mp_print_t *print, const byte *str_data, uint str_len) { // this escapes characters, but it will be very slow to print (calling print many times) bool has_single_quote = false; bool has_double_quote = false; @@ -83,7 +83,7 @@ STATIC void uni_print_quoted(const mp_print_t *print, const byte *str_data, uint mp_printf(print, "%c", quote_char); } -STATIC void uni_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void uni_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { GET_STR_DATA_LEN(self_in, str_data, str_len); #if MICROPY_PY_JSON if (kind == PRINT_JSON) { @@ -98,7 +98,7 @@ STATIC void uni_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t } } -STATIC mp_obj_t uni_unary_op(mp_unary_op_t op, mp_obj_t self_in) { +static mp_obj_t uni_unary_op(mp_unary_op_t op, mp_obj_t self_in) { GET_STR_DATA_LEN(self_in, str_data, str_len); switch (op) { case MP_UNARY_OP_BOOL: @@ -178,7 +178,7 @@ const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, s return s; } -STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { +static mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { const mp_obj_type_t *type = mp_obj_get_type(self_in); assert(type == &mp_type_str); GET_STR_DATA_LEN(self_in, self_data, self_len); @@ -253,7 +253,7 @@ typedef struct _mp_obj_str_it_t { size_t cur; } mp_obj_str_it_t; -STATIC mp_obj_t str_it_iternext(mp_obj_t self_in) { +static mp_obj_t str_it_iternext(mp_obj_t self_in) { mp_obj_str_it_t *self = MP_OBJ_TO_PTR(self_in); GET_STR_DATA_LEN(self->str, str, len); if (self->cur < len) { @@ -267,7 +267,7 @@ STATIC mp_obj_t str_it_iternext(mp_obj_t self_in) { } } -STATIC mp_obj_t mp_obj_new_str_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t mp_obj_new_str_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf) { assert(sizeof(mp_obj_str_it_t) <= sizeof(mp_obj_iter_buf_t)); mp_obj_str_it_t *o = (mp_obj_str_it_t *)iter_buf; o->base.type = &mp_type_polymorph_iter; diff --git a/py/objtuple.c b/py/objtuple.c index cb1d7cd388a91..2cbcc0e502f9a 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -65,7 +65,7 @@ void mp_obj_tuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t } } -STATIC mp_obj_t mp_obj_tuple_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t mp_obj_tuple_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; mp_arg_check_num(n_args, n_kw, 0, 1, false); @@ -107,7 +107,7 @@ STATIC mp_obj_t mp_obj_tuple_make_new(const mp_obj_type_t *type_in, size_t n_arg } // Don't pass MP_BINARY_OP_NOT_EQUAL here -STATIC mp_obj_t tuple_cmp_helper(mp_uint_t op, mp_obj_t self_in, mp_obj_t another_in) { +static mp_obj_t tuple_cmp_helper(mp_uint_t op, mp_obj_t self_in, mp_obj_t another_in) { mp_check_self(mp_obj_is_tuple_compatible(self_in)); const mp_obj_type_t *another_type = mp_obj_get_type(another_in); mp_obj_tuple_t *self = MP_OBJ_TO_PTR(self_in); @@ -203,26 +203,26 @@ mp_obj_t mp_obj_tuple_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { } } -STATIC mp_obj_t tuple_count(mp_obj_t self_in, mp_obj_t value) { +static mp_obj_t tuple_count(mp_obj_t self_in, mp_obj_t value) { mp_check_self(mp_obj_is_type(self_in, &mp_type_tuple)); mp_obj_tuple_t *self = MP_OBJ_TO_PTR(self_in); return mp_seq_count_obj(self->items, self->len, value); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(tuple_count_obj, tuple_count); +static MP_DEFINE_CONST_FUN_OBJ_2(tuple_count_obj, tuple_count); -STATIC mp_obj_t tuple_index(size_t n_args, const mp_obj_t *args) { +static mp_obj_t tuple_index(size_t n_args, const mp_obj_t *args) { mp_check_self(mp_obj_is_type(args[0], &mp_type_tuple)); mp_obj_tuple_t *self = MP_OBJ_TO_PTR(args[0]); return mp_seq_index_obj(self->items, self->len, n_args, args); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(tuple_index_obj, 2, 4, tuple_index); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(tuple_index_obj, 2, 4, tuple_index); -STATIC const mp_rom_map_elem_t tuple_locals_dict_table[] = { +static const mp_rom_map_elem_t tuple_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_count), MP_ROM_PTR(&tuple_count_obj) }, { MP_ROM_QSTR(MP_QSTR_index), MP_ROM_PTR(&tuple_index_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(tuple_locals_dict, tuple_locals_dict_table); +static MP_DEFINE_CONST_DICT(tuple_locals_dict, tuple_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mp_type_tuple, @@ -277,7 +277,7 @@ typedef struct _mp_obj_tuple_it_t { size_t cur; } mp_obj_tuple_it_t; -STATIC mp_obj_t tuple_it_iternext(mp_obj_t self_in) { +static mp_obj_t tuple_it_iternext(mp_obj_t self_in) { mp_obj_tuple_it_t *self = MP_OBJ_TO_PTR(self_in); if (self->cur < self->tuple->len) { mp_obj_t o_out = self->tuple->items[self->cur]; diff --git a/py/objtype.c b/py/objtype.c index 694db3008f6f2..8b2eb6de04eec 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -44,12 +44,12 @@ #define ENABLE_SPECIAL_ACCESSORS \ (MICROPY_PY_DESCRIPTORS || MICROPY_PY_DELATTR_SETATTR || MICROPY_PY_BUILTINS_PROPERTY) -STATIC mp_obj_t static_class_method_make_new(const mp_obj_type_t *self_in, size_t n_args, size_t n_kw, const mp_obj_t *args); +static mp_obj_t static_class_method_make_new(const mp_obj_type_t *self_in, size_t n_args, size_t n_kw, const mp_obj_t *args); /******************************************************************************/ // instance object -STATIC int instance_count_native_bases(const mp_obj_type_t *type, const mp_obj_type_t **last_native_base) { +static int instance_count_native_bases(const mp_obj_type_t *type, const mp_obj_type_t **last_native_base) { int count = 0; for (;;) { if (type == &mp_type_object) { @@ -84,17 +84,17 @@ STATIC int instance_count_native_bases(const mp_obj_type_t *type, const mp_obj_t // This wrapper function is allows a subclass of a native type to call the // __init__() method (corresponding to type->make_new) of the native type. -STATIC mp_obj_t native_base_init_wrapper(size_t n_args, const mp_obj_t *args) { +static mp_obj_t native_base_init_wrapper(size_t n_args, const mp_obj_t *args) { mp_obj_instance_t *self = MP_OBJ_TO_PTR(args[0]); const mp_obj_type_t *native_base = NULL; instance_count_native_bases(self->base.type, &native_base); self->subobj[0] = MP_OBJ_TYPE_GET_SLOT(native_base, make_new)(native_base, n_args - 1, 0, args + 1); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(native_base_init_wrapper_obj, 1, MP_OBJ_FUN_ARGS_MAX, native_base_init_wrapper); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(native_base_init_wrapper_obj, 1, MP_OBJ_FUN_ARGS_MAX, native_base_init_wrapper); #if !MICROPY_CPYTHON_COMPAT -STATIC +static #endif mp_obj_instance_t *mp_obj_new_instance(const mp_obj_type_t *class, const mp_obj_type_t **native_base) { size_t num_native_bases = instance_count_native_bases(class, native_base); @@ -132,7 +132,7 @@ struct class_lookup_data { bool is_type; }; -STATIC void mp_obj_class_lookup(struct class_lookup_data *lookup, const mp_obj_type_t *type) { +static void mp_obj_class_lookup(struct class_lookup_data *lookup, const mp_obj_type_t *type) { assert(lookup->dest[0] == MP_OBJ_NULL); assert(lookup->dest[1] == MP_OBJ_NULL); for (;;) { @@ -235,7 +235,7 @@ STATIC void mp_obj_class_lookup(struct class_lookup_data *lookup, const mp_obj_t } } -STATIC void instance_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void instance_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in); qstr meth = (kind == PRINT_STR) ? MP_QSTR___str__ : MP_QSTR___repr__; mp_obj_t member[2] = {MP_OBJ_NULL}; @@ -277,7 +277,7 @@ STATIC void instance_print(const mp_print_t *print, mp_obj_t self_in, mp_print_k mp_printf(print, "<%s object at %p>", mp_obj_get_type_str(self_in), self); } -STATIC mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, size_t n_kw, const mp_obj_t *args) { assert(mp_obj_is_instance_type(self)); // look for __new__ function @@ -392,7 +392,7 @@ const byte mp_unary_op_method_name[MP_UNARY_OP_NUM_RUNTIME] = { #endif }; -STATIC mp_obj_t instance_unary_op(mp_unary_op_t op, mp_obj_t self_in) { +static mp_obj_t instance_unary_op(mp_unary_op_t op, mp_obj_t self_in) { mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in); #if MICROPY_PY_SYS_GETSIZEOF @@ -530,7 +530,7 @@ const byte mp_binary_op_method_name[MP_BINARY_OP_NUM_RUNTIME] = { #endif }; -STATIC mp_obj_t instance_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { +static mp_obj_t instance_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { // Note: For ducktyping, CPython does not look in the instance members or use // __getattr__ or __getattribute__. It only looks in the class dictionary. mp_obj_instance_t *lhs = MP_OBJ_TO_PTR(lhs_in); @@ -572,7 +572,7 @@ STATIC mp_obj_t instance_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t return res; } -STATIC void mp_obj_instance_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void mp_obj_instance_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { // logic: look in instance members then class locals assert(mp_obj_is_instance_type(mp_obj_get_type(self_in))); mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in); @@ -669,7 +669,7 @@ STATIC void mp_obj_instance_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *des } } -STATIC bool mp_obj_instance_store_attr(mp_obj_t self_in, qstr attr, mp_obj_t value) { +static bool mp_obj_instance_store_attr(mp_obj_t self_in, qstr attr, mp_obj_t value) { mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in); if (!(self->base.type->flags & MP_TYPE_FLAG_HAS_SPECIAL_ACCESSORS)) { @@ -792,7 +792,7 @@ STATIC bool mp_obj_instance_store_attr(mp_obj_t self_in, qstr attr, mp_obj_t val } } -STATIC void mp_obj_instance_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void mp_obj_instance_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] == MP_OBJ_NULL) { mp_obj_instance_load_attr(self_in, attr, dest); } else { @@ -802,7 +802,7 @@ STATIC void mp_obj_instance_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } } -STATIC mp_obj_t instance_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { +static mp_obj_t instance_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_t member[4] = {MP_OBJ_NULL, MP_OBJ_NULL, index, value}; struct class_lookup_data lookup = { @@ -837,7 +837,7 @@ STATIC mp_obj_t instance_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value } } -STATIC mp_obj_t mp_obj_instance_get_call(mp_obj_t self_in, mp_obj_t *member) { +static mp_obj_t mp_obj_instance_get_call(mp_obj_t self_in, mp_obj_t *member) { mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in); struct class_lookup_data lookup = { .obj = self, @@ -903,7 +903,7 @@ mp_obj_t mp_obj_instance_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) } } -STATIC mp_int_t instance_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { +static mp_int_t instance_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_t member[2] = {MP_OBJ_NULL}; struct class_lookup_data lookup = { @@ -929,7 +929,7 @@ STATIC mp_int_t instance_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, // - creating a new class (a new type) creates a new mp_obj_type_t #if ENABLE_SPECIAL_ACCESSORS -STATIC bool check_for_special_accessors(mp_obj_t key, mp_obj_t value) { +static bool check_for_special_accessors(mp_obj_t key, mp_obj_t value) { #if MICROPY_PY_DELATTR_SETATTR if (key == MP_OBJ_NEW_QSTR(MP_QSTR___setattr__) || key == MP_OBJ_NEW_QSTR(MP_QSTR___delattr__)) { return true; @@ -956,13 +956,13 @@ STATIC bool check_for_special_accessors(mp_obj_t key, mp_obj_t value) { } #endif -STATIC void type_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void type_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_type_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", self->name); } -STATIC mp_obj_t type_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t type_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; mp_arg_check_num(n_args, n_kw, 1, 3, false); @@ -982,7 +982,7 @@ STATIC mp_obj_t type_make_new(const mp_obj_type_t *type_in, size_t n_args, size_ } } -STATIC mp_obj_t type_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t type_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { // instantiate an instance of a class mp_obj_type_t *self = MP_OBJ_TO_PTR(self_in); @@ -1002,7 +1002,7 @@ STATIC mp_obj_t type_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp return o; } -STATIC void type_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void type_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { assert(mp_obj_is_type(self_in, &mp_type_type)); mp_obj_type_t *self = MP_OBJ_TO_PTR(self_in); @@ -1235,7 +1235,7 @@ typedef struct _mp_obj_super_t { mp_obj_t obj; } mp_obj_super_t; -STATIC void super_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void super_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_super_t *self = MP_OBJ_TO_PTR(self_in); mp_print_str(print, ""); } -STATIC mp_obj_t super_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t super_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; // 0 arguments are turned into 2 in the compiler // 1 argument is not yet implemented @@ -1258,7 +1258,7 @@ STATIC mp_obj_t super_make_new(const mp_obj_type_t *type_in, size_t n_args, size return MP_OBJ_FROM_PTR(o); } -STATIC void super_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void super_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] != MP_OBJ_NULL) { // not load attribute return; @@ -1386,7 +1386,7 @@ bool mp_obj_is_subclass_fast(mp_const_obj_t object, mp_const_obj_t classinfo) { } } -STATIC mp_obj_t mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo) { +static mp_obj_t mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo) { size_t len; mp_obj_t *items; if (mp_obj_is_type(classinfo, &mp_type_type)) { @@ -1407,7 +1407,7 @@ STATIC mp_obj_t mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo) { return mp_const_false; } -STATIC mp_obj_t mp_builtin_issubclass(mp_obj_t object, mp_obj_t classinfo) { +static mp_obj_t mp_builtin_issubclass(mp_obj_t object, mp_obj_t classinfo) { if (!mp_obj_is_type(object, &mp_type_type)) { mp_raise_TypeError(MP_ERROR_TEXT("issubclass() arg 1 must be a class")); } @@ -1416,7 +1416,7 @@ STATIC mp_obj_t mp_builtin_issubclass(mp_obj_t object, mp_obj_t classinfo) { MP_DEFINE_CONST_FUN_OBJ_2(mp_builtin_issubclass_obj, mp_builtin_issubclass); -STATIC mp_obj_t mp_builtin_isinstance(mp_obj_t object, mp_obj_t classinfo) { +static mp_obj_t mp_builtin_isinstance(mp_obj_t object, mp_obj_t classinfo) { return mp_obj_is_subclass(MP_OBJ_FROM_PTR(mp_obj_get_type(object)), classinfo); } @@ -1438,7 +1438,7 @@ mp_obj_t mp_obj_cast_to_native_base(mp_obj_t self_in, mp_const_obj_t native_type /******************************************************************************/ // staticmethod and classmethod types (probably should go in a different file) -STATIC mp_obj_t static_class_method_make_new(const mp_obj_type_t *self, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t static_class_method_make_new(const mp_obj_type_t *self, size_t n_args, size_t n_kw, const mp_obj_t *args) { assert(self == &mp_type_staticmethod || self == &mp_type_classmethod); mp_arg_check_num(n_args, n_kw, 1, 1, false); diff --git a/py/objzip.c b/py/objzip.c index 7b4ae7548e8a5..dd2b39ee07110 100644 --- a/py/objzip.c +++ b/py/objzip.c @@ -36,7 +36,7 @@ typedef struct _mp_obj_zip_t { mp_obj_t iters[]; } mp_obj_zip_t; -STATIC mp_obj_t zip_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t zip_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, false); mp_obj_zip_t *o = mp_obj_malloc_var(mp_obj_zip_t, iters, mp_obj_t, n_args, type); @@ -47,7 +47,7 @@ STATIC mp_obj_t zip_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t zip_iternext(mp_obj_t self_in) { +static mp_obj_t zip_iternext(mp_obj_t self_in) { mp_check_self(mp_obj_is_type(self_in, &mp_type_zip)); mp_obj_zip_t *self = MP_OBJ_TO_PTR(self_in); if (self->n_iters == 0) { diff --git a/py/opmethods.c b/py/opmethods.c index c3931fd358466..32ab187b05510 100644 --- a/py/opmethods.c +++ b/py/opmethods.c @@ -27,28 +27,28 @@ #include "py/obj.h" #include "py/builtin.h" -STATIC mp_obj_t op_getitem(mp_obj_t self_in, mp_obj_t key_in) { +static mp_obj_t op_getitem(mp_obj_t self_in, mp_obj_t key_in) { const mp_obj_type_t *type = mp_obj_get_type(self_in); // Note: assumes type must have subscr (only used by dict). return MP_OBJ_TYPE_GET_SLOT(type, subscr)(self_in, key_in, MP_OBJ_SENTINEL); } MP_DEFINE_CONST_FUN_OBJ_2(mp_op_getitem_obj, op_getitem); -STATIC mp_obj_t op_setitem(mp_obj_t self_in, mp_obj_t key_in, mp_obj_t value_in) { +static mp_obj_t op_setitem(mp_obj_t self_in, mp_obj_t key_in, mp_obj_t value_in) { const mp_obj_type_t *type = mp_obj_get_type(self_in); // Note: assumes type must have subscr (only used by dict). return MP_OBJ_TYPE_GET_SLOT(type, subscr)(self_in, key_in, value_in); } MP_DEFINE_CONST_FUN_OBJ_3(mp_op_setitem_obj, op_setitem); -STATIC mp_obj_t op_delitem(mp_obj_t self_in, mp_obj_t key_in) { +static mp_obj_t op_delitem(mp_obj_t self_in, mp_obj_t key_in) { const mp_obj_type_t *type = mp_obj_get_type(self_in); // Note: assumes type must have subscr (only used by dict). return MP_OBJ_TYPE_GET_SLOT(type, subscr)(self_in, key_in, MP_OBJ_NULL); } MP_DEFINE_CONST_FUN_OBJ_2(mp_op_delitem_obj, op_delitem); -STATIC mp_obj_t op_contains(mp_obj_t lhs_in, mp_obj_t rhs_in) { +static mp_obj_t op_contains(mp_obj_t lhs_in, mp_obj_t rhs_in) { const mp_obj_type_t *type = mp_obj_get_type(lhs_in); // Note: assumes type must have binary_op (only used by set/frozenset). return MP_OBJ_TYPE_GET_SLOT(type, binary_op)(MP_BINARY_OP_CONTAINS, lhs_in, rhs_in); diff --git a/py/parse.c b/py/parse.c index e86103ed8e02a..54be8b97d092d 100644 --- a/py/parse.c +++ b/py/parse.c @@ -75,7 +75,7 @@ enum { }; // Define an array of actions corresponding to each rule -STATIC const uint8_t rule_act_table[] = { +static const uint8_t rule_act_table[] = { #define or(n) (RULE_ACT_OR | n) #define and(n) (RULE_ACT_AND | n) #define and_ident(n) (RULE_ACT_AND | n | RULE_ACT_ALLOW_IDENT) @@ -108,7 +108,7 @@ STATIC const uint8_t rule_act_table[] = { }; // Define the argument data for each rule, as a combined array -STATIC const uint16_t rule_arg_combined_table[] = { +static const uint16_t rule_arg_combined_table[] = { #define tok(t) (RULE_ARG_TOK | MP_TOKEN_##t) #define rule(r) (RULE_ARG_RULE | RULE_##r) #define opt_rule(r) (RULE_ARG_OPT_RULE | RULE_##r) @@ -161,7 +161,7 @@ enum { // data, which indexes rule_arg_combined_table. The offsets require 9 bits of // storage but only the lower 8 bits are stored here. The 9th bit is computed // in get_rule_arg using the FIRST_RULE_WITH_OFFSET_ABOVE_255 constant. -STATIC const uint8_t rule_arg_offset_table[] = { +static const uint8_t rule_arg_offset_table[] = { #define DEF_RULE(rule, comp, kind, ...) RULE_ARG_OFFSET(rule, __VA_ARGS__) & 0xff, #define DEF_RULE_NC(rule, kind, ...) #include "py/grammar.h" @@ -191,7 +191,7 @@ static const size_t FIRST_RULE_WITH_OFFSET_ABOVE_255 = #if MICROPY_DEBUG_PARSE_RULE_NAME // Define an array of rule names corresponding to each rule -STATIC const char *const rule_name_table[] = { +static const char *const rule_name_table[] = { #define DEF_RULE(rule, comp, kind, ...) #rule, #define DEF_RULE_NC(rule, kind, ...) #include "py/grammar.h" @@ -242,9 +242,9 @@ typedef struct _parser_t { #endif } parser_t; -STATIC void push_result_rule(parser_t *parser, size_t src_line, uint8_t rule_id, size_t num_args); +static void push_result_rule(parser_t *parser, size_t src_line, uint8_t rule_id, size_t num_args); -STATIC const uint16_t *get_rule_arg(uint8_t r_id) { +static const uint16_t *get_rule_arg(uint8_t r_id) { size_t off = rule_arg_offset_table[r_id]; if (r_id >= FIRST_RULE_WITH_OFFSET_ABOVE_255) { off |= 0x100; @@ -252,7 +252,7 @@ STATIC const uint16_t *get_rule_arg(uint8_t r_id) { return &rule_arg_combined_table[off]; } -STATIC void *parser_alloc(parser_t *parser, size_t num_bytes) { +static void *parser_alloc(parser_t *parser, size_t num_bytes) { // use a custom memory allocator to store parse nodes sequentially in large chunks mp_parse_chunk_t *chunk = parser->cur_chunk; @@ -294,7 +294,7 @@ STATIC void *parser_alloc(parser_t *parser, size_t num_bytes) { } #if MICROPY_COMP_CONST_TUPLE -STATIC void parser_free_parse_node_struct(parser_t *parser, mp_parse_node_struct_t *pns) { +static void parser_free_parse_node_struct(parser_t *parser, mp_parse_node_struct_t *pns) { mp_parse_chunk_t *chunk = parser->cur_chunk; if (chunk->data <= (byte *)pns && (byte *)pns < chunk->data + chunk->union_.used) { size_t num_bytes = sizeof(mp_parse_node_struct_t) + sizeof(mp_parse_node_t) * MP_PARSE_NODE_STRUCT_NUM_NODES(pns); @@ -303,7 +303,7 @@ STATIC void parser_free_parse_node_struct(parser_t *parser, mp_parse_node_struct } #endif -STATIC void push_rule(parser_t *parser, size_t src_line, uint8_t rule_id, size_t arg_i) { +static void push_rule(parser_t *parser, size_t src_line, uint8_t rule_id, size_t arg_i) { if (parser->rule_stack_top >= parser->rule_stack_alloc) { rule_stack_t *rs = m_renew(rule_stack_t, parser->rule_stack, parser->rule_stack_alloc, parser->rule_stack_alloc + MICROPY_ALLOC_PARSE_RULE_INC); parser->rule_stack = rs; @@ -315,13 +315,13 @@ STATIC void push_rule(parser_t *parser, size_t src_line, uint8_t rule_id, size_t rs->arg_i = arg_i; } -STATIC void push_rule_from_arg(parser_t *parser, size_t arg) { +static void push_rule_from_arg(parser_t *parser, size_t arg) { assert((arg & RULE_ARG_KIND_MASK) == RULE_ARG_RULE || (arg & RULE_ARG_KIND_MASK) == RULE_ARG_OPT_RULE); size_t rule_id = arg & RULE_ARG_ARG_MASK; push_rule(parser, parser->lexer->tok_line, rule_id, 0); } -STATIC uint8_t pop_rule(parser_t *parser, size_t *arg_i, size_t *src_line) { +static uint8_t pop_rule(parser_t *parser, size_t *arg_i, size_t *src_line) { parser->rule_stack_top -= 1; uint8_t rule_id = parser->rule_stack[parser->rule_stack_top].rule_id; *arg_i = parser->rule_stack[parser->rule_stack_top].arg_i; @@ -330,7 +330,7 @@ STATIC uint8_t pop_rule(parser_t *parser, size_t *arg_i, size_t *src_line) { } #if MICROPY_COMP_CONST_TUPLE -STATIC uint8_t peek_rule(parser_t *parser, size_t n) { +static uint8_t peek_rule(parser_t *parser, size_t n) { assert(parser->rule_stack_top > n); return parser->rule_stack[parser->rule_stack_top - 1 - n].rule_id; } @@ -350,7 +350,7 @@ bool mp_parse_node_get_int_maybe(mp_parse_node_t pn, mp_obj_t *o) { } #if MICROPY_COMP_CONST_TUPLE || MICROPY_COMP_CONST -STATIC bool mp_parse_node_is_const(mp_parse_node_t pn) { +static bool mp_parse_node_is_const(mp_parse_node_t pn) { if (MP_PARSE_NODE_IS_SMALL_INT(pn)) { // Small integer. return true; @@ -377,7 +377,7 @@ STATIC bool mp_parse_node_is_const(mp_parse_node_t pn) { return false; } -STATIC mp_obj_t mp_parse_node_convert_to_obj(mp_parse_node_t pn) { +static mp_obj_t mp_parse_node_convert_to_obj(mp_parse_node_t pn) { assert(mp_parse_node_is_const(pn)); if (MP_PARSE_NODE_IS_SMALL_INT(pn)) { mp_int_t arg = MP_PARSE_NODE_LEAF_SMALL_INT(pn); @@ -419,7 +419,7 @@ STATIC mp_obj_t mp_parse_node_convert_to_obj(mp_parse_node_t pn) { } #endif -STATIC bool parse_node_is_const_bool(mp_parse_node_t pn, bool value) { +static bool parse_node_is_const_bool(mp_parse_node_t pn, bool value) { // Returns true if 'pn' is a constant whose boolean value is equivalent to 'value' #if MICROPY_COMP_CONST_TUPLE || MICROPY_COMP_CONST return mp_parse_node_is_const(pn) && mp_obj_is_true(mp_parse_node_convert_to_obj(pn)) == value; @@ -513,7 +513,7 @@ void mp_parse_node_print(const mp_print_t *print, mp_parse_node_t pn, size_t ind #endif // MICROPY_DEBUG_PRINTERS /* -STATIC void result_stack_show(const mp_print_t *print, parser_t *parser) { +static void result_stack_show(const mp_print_t *print, parser_t *parser) { mp_printf(print, "result stack, most recent first\n"); for (ssize_t i = parser->result_stack_top - 1; i >= 0; i--) { mp_parse_node_print(print, parser->result_stack[i], 0); @@ -521,17 +521,17 @@ STATIC void result_stack_show(const mp_print_t *print, parser_t *parser) { } */ -STATIC mp_parse_node_t pop_result(parser_t *parser) { +static mp_parse_node_t pop_result(parser_t *parser) { assert(parser->result_stack_top > 0); return parser->result_stack[--parser->result_stack_top]; } -STATIC mp_parse_node_t peek_result(parser_t *parser, size_t pos) { +static mp_parse_node_t peek_result(parser_t *parser, size_t pos) { assert(parser->result_stack_top > pos); return parser->result_stack[parser->result_stack_top - 1 - pos]; } -STATIC void push_result_node(parser_t *parser, mp_parse_node_t pn) { +static void push_result_node(parser_t *parser, mp_parse_node_t pn) { if (parser->result_stack_top >= parser->result_stack_alloc) { mp_parse_node_t *stack = m_renew(mp_parse_node_t, parser->result_stack, parser->result_stack_alloc, parser->result_stack_alloc + MICROPY_ALLOC_PARSE_RESULT_INC); parser->result_stack = stack; @@ -540,7 +540,7 @@ STATIC void push_result_node(parser_t *parser, mp_parse_node_t pn) { parser->result_stack[parser->result_stack_top++] = pn; } -STATIC mp_parse_node_t make_node_const_object(parser_t *parser, size_t src_line, mp_obj_t obj) { +static mp_parse_node_t make_node_const_object(parser_t *parser, size_t src_line, mp_obj_t obj) { mp_parse_node_struct_t *pn = parser_alloc(parser, sizeof(mp_parse_node_struct_t) + sizeof(mp_obj_t)); pn->source_line = src_line; #if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_D @@ -557,7 +557,7 @@ STATIC mp_parse_node_t make_node_const_object(parser_t *parser, size_t src_line, // Create a parse node representing a constant object, possibly optimising the case of // an integer, by putting the (small) integer value directly in the parse node itself. -STATIC mp_parse_node_t make_node_const_object_optimised(parser_t *parser, size_t src_line, mp_obj_t obj) { +static mp_parse_node_t make_node_const_object_optimised(parser_t *parser, size_t src_line, mp_obj_t obj) { if (mp_obj_is_small_int(obj)) { mp_int_t val = MP_OBJ_SMALL_INT_VALUE(obj); #if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_D @@ -579,7 +579,7 @@ STATIC mp_parse_node_t make_node_const_object_optimised(parser_t *parser, size_t } } -STATIC void push_result_token(parser_t *parser, uint8_t rule_id) { +static void push_result_token(parser_t *parser, uint8_t rule_id) { mp_parse_node_t pn; mp_lexer_t *lex = parser->lexer; if (lex->tok_kind == MP_TOKEN_NAME) { @@ -635,7 +635,7 @@ STATIC void push_result_token(parser_t *parser, uint8_t rule_id) { #if MICROPY_COMP_CONST_FOLDING #if MICROPY_COMP_MODULE_CONST -STATIC const mp_rom_map_elem_t mp_constants_table[] = { +static const mp_rom_map_elem_t mp_constants_table[] = { #if MICROPY_PY_ERRNO { MP_ROM_QSTR(MP_QSTR_errno), MP_ROM_PTR(&mp_module_errno) }, #endif @@ -645,7 +645,7 @@ STATIC const mp_rom_map_elem_t mp_constants_table[] = { // Extra constants as defined by a port MICROPY_PORT_CONSTANTS }; -STATIC MP_DEFINE_CONST_MAP(mp_constants_map, mp_constants_table); +static MP_DEFINE_CONST_MAP(mp_constants_map, mp_constants_table); #endif #if MICROPY_COMP_CONST_FOLDING_COMPILER_WORKAROUND @@ -653,7 +653,7 @@ STATIC MP_DEFINE_CONST_MAP(mp_constants_map, mp_constants_table); // function is static, so provide a hook for them to work around this problem. MP_NOINLINE #endif -STATIC bool fold_logical_constants(parser_t *parser, uint8_t rule_id, size_t *num_args) { +static bool fold_logical_constants(parser_t *parser, uint8_t rule_id, size_t *num_args) { if (rule_id == RULE_or_test || rule_id == RULE_and_test) { // folding for binary logical ops: or and @@ -710,7 +710,7 @@ STATIC bool fold_logical_constants(parser_t *parser, uint8_t rule_id, size_t *nu return false; } -STATIC bool fold_constants(parser_t *parser, uint8_t rule_id, size_t num_args) { +static bool fold_constants(parser_t *parser, uint8_t rule_id, size_t num_args) { // this code does folding of arbitrary integer expressions, eg 1 + 2 * 3 + 4 // it does not do partial folding, eg 1 + 2 + x -> 3 + x @@ -894,7 +894,7 @@ STATIC bool fold_constants(parser_t *parser, uint8_t rule_id, size_t num_args) { #endif // MICROPY_COMP_CONST_FOLDING #if MICROPY_COMP_CONST_TUPLE -STATIC bool build_tuple_from_stack(parser_t *parser, size_t src_line, size_t num_args) { +static bool build_tuple_from_stack(parser_t *parser, size_t src_line, size_t num_args) { for (size_t i = num_args; i > 0;) { mp_parse_node_t pn = peek_result(parser, --i); if (!mp_parse_node_is_const(pn)) { @@ -913,7 +913,7 @@ STATIC bool build_tuple_from_stack(parser_t *parser, size_t src_line, size_t num return true; } -STATIC bool build_tuple(parser_t *parser, size_t src_line, uint8_t rule_id, size_t num_args) { +static bool build_tuple(parser_t *parser, size_t src_line, uint8_t rule_id, size_t num_args) { if (rule_id == RULE_testlist_comp) { if (peek_rule(parser, 0) == RULE_atom_paren) { // Tuple of the form "(a,)". @@ -946,7 +946,7 @@ STATIC bool build_tuple(parser_t *parser, size_t src_line, uint8_t rule_id, size } #endif -STATIC void push_result_rule(parser_t *parser, size_t src_line, uint8_t rule_id, size_t num_args) { +static void push_result_rule(parser_t *parser, size_t src_line, uint8_t rule_id, size_t num_args) { // Simplify and optimise certain rules, to reduce memory usage and simplify the compiler. if (rule_id == RULE_atom_paren) { // Remove parenthesis around a single expression if possible. diff --git a/py/parsenum.c b/py/parsenum.c index e3ad8070c6e02..b33ffb6ff23e0 100644 --- a/py/parsenum.c +++ b/py/parsenum.c @@ -36,7 +36,7 @@ #include #endif -STATIC NORETURN void raise_exc(mp_obj_t exc, mp_lexer_t *lex) { +static NORETURN void raise_exc(mp_obj_t exc, mp_lexer_t *lex) { // if lex!=NULL then the parser called us and we need to convert the // exception's type from ValueError to SyntaxError and add traceback info if (lex != NULL) { diff --git a/py/persistentcode.c b/py/persistentcode.c index 1fe9a9a23fde8..5088c05f03c2b 100644 --- a/py/persistentcode.c +++ b/py/persistentcode.c @@ -69,8 +69,8 @@ typedef struct _bytecode_prelude_t { #include "py/parsenum.h" -STATIC int read_byte(mp_reader_t *reader); -STATIC size_t read_uint(mp_reader_t *reader); +static int read_byte(mp_reader_t *reader); +static size_t read_uint(mp_reader_t *reader); #if MICROPY_EMIT_MACHINE_CODE @@ -138,17 +138,17 @@ void mp_native_relocate(void *ri_in, uint8_t *text, uintptr_t reloc_text) { #endif -STATIC int read_byte(mp_reader_t *reader) { +static int read_byte(mp_reader_t *reader) { return reader->readbyte(reader->data); } -STATIC void read_bytes(mp_reader_t *reader, byte *buf, size_t len) { +static void read_bytes(mp_reader_t *reader, byte *buf, size_t len) { while (len-- > 0) { *buf++ = reader->readbyte(reader->data); } } -STATIC size_t read_uint(mp_reader_t *reader) { +static size_t read_uint(mp_reader_t *reader) { size_t unum = 0; for (;;) { byte b = reader->readbyte(reader->data); @@ -160,7 +160,7 @@ STATIC size_t read_uint(mp_reader_t *reader) { return unum; } -STATIC qstr load_qstr(mp_reader_t *reader) { +static qstr load_qstr(mp_reader_t *reader) { size_t len = read_uint(reader); if (len & 1) { // static qstr @@ -175,7 +175,7 @@ STATIC qstr load_qstr(mp_reader_t *reader) { return qst; } -STATIC mp_obj_t load_obj(mp_reader_t *reader) { +static mp_obj_t load_obj(mp_reader_t *reader) { byte obj_type = read_byte(reader); #if MICROPY_EMIT_MACHINE_CODE if (obj_type == MP_PERSISTENT_OBJ_FUN_TABLE) { @@ -221,7 +221,7 @@ STATIC mp_obj_t load_obj(mp_reader_t *reader) { } } -STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader, mp_module_context_t *context) { +static mp_raw_code_t *load_raw_code(mp_reader_t *reader, mp_module_context_t *context) { // Load function kind and data length size_t kind_len = read_uint(reader); int kind = (kind_len & 3) + MP_CODE_BYTECODE; @@ -468,12 +468,12 @@ void mp_raw_code_load_file(qstr filename, mp_compiled_module_t *context) { #include "py/objstr.h" -STATIC void mp_print_bytes(mp_print_t *print, const byte *data, size_t len) { +static void mp_print_bytes(mp_print_t *print, const byte *data, size_t len) { print->print_strn(print->data, (const char *)data, len); } #define BYTES_FOR_INT ((MP_BYTES_PER_OBJ_WORD * 8 + 6) / 7) -STATIC void mp_print_uint(mp_print_t *print, size_t n) { +static void mp_print_uint(mp_print_t *print, size_t n) { byte buf[BYTES_FOR_INT]; byte *p = buf + sizeof(buf); *--p = n & 0x7f; @@ -484,7 +484,7 @@ STATIC void mp_print_uint(mp_print_t *print, size_t n) { print->print_strn(print->data, (char *)p, buf + sizeof(buf) - p); } -STATIC void save_qstr(mp_print_t *print, qstr qst) { +static void save_qstr(mp_print_t *print, qstr qst) { if (qst <= QSTR_LAST_STATIC) { // encode static qstr mp_print_uint(print, qst << 1 | 1); @@ -496,7 +496,7 @@ STATIC void save_qstr(mp_print_t *print, qstr qst) { mp_print_bytes(print, str, len + 1); // +1 to store null terminator } -STATIC void save_obj(mp_print_t *print, mp_obj_t o) { +static void save_obj(mp_print_t *print, mp_obj_t o) { #if MICROPY_EMIT_MACHINE_CODE if (o == MP_OBJ_FROM_PTR(&mp_fun_table)) { byte obj_type = MP_PERSISTENT_OBJ_FUN_TABLE; @@ -562,7 +562,7 @@ STATIC void save_obj(mp_print_t *print, mp_obj_t o) { } } -STATIC void save_raw_code(mp_print_t *print, const mp_raw_code_t *rc) { +static void save_raw_code(mp_print_t *print, const mp_raw_code_t *rc) { // Save function kind and data length mp_print_uint(print, (rc->fun_data_len << 3) | ((rc->n_children != 0) << 2) | (rc->kind - MP_CODE_BYTECODE)); @@ -637,7 +637,7 @@ void mp_raw_code_save(mp_compiled_module_t *cm, mp_print_t *print) { #include #include -STATIC void fd_print_strn(void *env, const char *str, size_t len) { +static void fd_print_strn(void *env, const char *str, size_t len) { int fd = (intptr_t)env; MP_THREAD_GIL_EXIT(); ssize_t ret = write(fd, str, len); diff --git a/py/profile.c b/py/profile.c index 274089d7022f1..92f414ace7c92 100644 --- a/py/profile.c +++ b/py/profile.c @@ -40,7 +40,7 @@ #define prof_trace_cb MP_STATE_THREAD(prof_trace_callback) #define QSTR_MAP(context, idx) (context->constants.qstr_table[idx]) -STATIC uint mp_prof_bytecode_lineno(const mp_raw_code_t *rc, size_t bc) { +static uint mp_prof_bytecode_lineno(const mp_raw_code_t *rc, size_t bc) { const mp_bytecode_prelude_t *prelude = &rc->prelude; return mp_bytecode_get_source_line(prelude->line_info, prelude->line_info_top, bc); } @@ -71,7 +71,7 @@ void mp_prof_extract_prelude(const byte *bytecode, mp_bytecode_prelude_t *prelud /******************************************************************************/ // code object -STATIC void code_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +static void code_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; mp_obj_code_t *o = MP_OBJ_TO_PTR(o_in); const mp_raw_code_t *rc = o->rc; @@ -85,7 +85,7 @@ STATIC void code_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t k ); } -STATIC mp_obj_tuple_t *code_consts(const mp_module_context_t *context, const mp_raw_code_t *rc) { +static mp_obj_tuple_t *code_consts(const mp_module_context_t *context, const mp_raw_code_t *rc) { mp_obj_tuple_t *consts = MP_OBJ_TO_PTR(mp_obj_new_tuple(rc->n_children + 1, NULL)); size_t const_no = 0; @@ -101,7 +101,7 @@ STATIC mp_obj_tuple_t *code_consts(const mp_module_context_t *context, const mp_ return consts; } -STATIC mp_obj_t raw_code_lnotab(const mp_raw_code_t *rc) { +static mp_obj_t raw_code_lnotab(const mp_raw_code_t *rc) { // const mp_bytecode_prelude_t *prelude = &rc->prelude; uint start = 0; uint stop = rc->fun_data_len - start; @@ -139,7 +139,7 @@ STATIC mp_obj_t raw_code_lnotab(const mp_raw_code_t *rc) { return o; } -STATIC void code_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void code_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] != MP_OBJ_NULL) { // not load attribute return; @@ -202,7 +202,7 @@ mp_obj_t mp_obj_new_code(const mp_module_context_t *context, const mp_raw_code_t /******************************************************************************/ // frame object -STATIC void frame_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +static void frame_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; mp_obj_frame_t *frame = MP_OBJ_TO_PTR(o_in); mp_obj_code_t *code = frame->code; @@ -217,7 +217,7 @@ STATIC void frame_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t ); } -STATIC void frame_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void frame_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] != MP_OBJ_NULL) { // not load attribute return; @@ -294,7 +294,7 @@ typedef struct { mp_obj_t arg; } prof_callback_args_t; -STATIC mp_obj_t mp_prof_callback_invoke(mp_obj_t callback, prof_callback_args_t *args) { +static mp_obj_t mp_prof_callback_invoke(mp_obj_t callback, prof_callback_args_t *args) { assert(mp_obj_is_callable(callback)); mp_prof_is_executing = true; @@ -474,7 +474,7 @@ typedef struct _mp_dis_instruction_t { mp_obj_t argobjex_cache; } mp_dis_instruction_t; -STATIC const byte *mp_prof_opcode_decode(const byte *ip, const mp_uint_t *const_table, mp_dis_instruction_t *instruction) { +static const byte *mp_prof_opcode_decode(const byte *ip, const mp_uint_t *const_table, mp_dis_instruction_t *instruction) { mp_uint_t unum; const byte *ptr; mp_obj_t obj; diff --git a/py/qstr.c b/py/qstr.c index 204becd2136e0..3720932250ca8 100644 --- a/py/qstr.c +++ b/py/qstr.c @@ -187,7 +187,7 @@ void qstr_init(void) { #endif } -STATIC const qstr_pool_t *find_qstr(qstr *q) { +static const qstr_pool_t *find_qstr(qstr *q) { // search pool for this qstr // total_prev_len==0 in the final pool, so the loop will always terminate const qstr_pool_t *pool = MP_STATE_VM(last_pool); @@ -200,7 +200,7 @@ STATIC const qstr_pool_t *find_qstr(qstr *q) { } // qstr_mutex must be taken while in this function -STATIC qstr qstr_add(mp_uint_t len, const char *q_ptr) { +static qstr qstr_add(mp_uint_t len, const char *q_ptr) { #if MICROPY_QSTR_BYTES_IN_HASH mp_uint_t hash = qstr_compute_hash((const byte *)q_ptr, len); DEBUG_printf("QSTR: add hash=%d len=%d data=%.*s\n", hash, len, len, q_ptr); @@ -444,7 +444,7 @@ void qstr_dump_data(void) { #else // Emit the compressed_string_data string. -#define MP_COMPRESSED_DATA(x) STATIC const char *compressed_string_data = x; +#define MP_COMPRESSED_DATA(x) static const char *compressed_string_data = x; #define MP_MATCH_COMPRESSED(a, b) #include "genhdr/compressed.data.h" #undef MP_COMPRESSED_DATA @@ -458,7 +458,7 @@ void qstr_dump_data(void) { // The compressed string data is delimited by setting high bit in the final char of each word. // e.g. aaaa<0x80|a>bbbbbb<0x80|b>.... // This method finds the n'th string. -STATIC const byte *find_uncompressed_string(uint8_t n) { +static const byte *find_uncompressed_string(uint8_t n) { const byte *c = (byte *)compressed_string_data; while (n > 0) { while ((*c & 0x80) == 0) { diff --git a/py/reader.c b/py/reader.c index d2af62cfb344d..151e04cac2c71 100644 --- a/py/reader.c +++ b/py/reader.c @@ -39,7 +39,7 @@ typedef struct _mp_reader_mem_t { const byte *end; } mp_reader_mem_t; -STATIC mp_uint_t mp_reader_mem_readbyte(void *data) { +static mp_uint_t mp_reader_mem_readbyte(void *data) { mp_reader_mem_t *reader = (mp_reader_mem_t *)data; if (reader->cur < reader->end) { return *reader->cur++; @@ -48,7 +48,7 @@ STATIC mp_uint_t mp_reader_mem_readbyte(void *data) { } } -STATIC void mp_reader_mem_close(void *data) { +static void mp_reader_mem_close(void *data) { mp_reader_mem_t *reader = (mp_reader_mem_t *)data; if (reader->free_len > 0) { m_del(char, (char *)reader->beg, reader->free_len); @@ -81,7 +81,7 @@ typedef struct _mp_reader_posix_t { byte buf[20]; } mp_reader_posix_t; -STATIC mp_uint_t mp_reader_posix_readbyte(void *data) { +static mp_uint_t mp_reader_posix_readbyte(void *data) { mp_reader_posix_t *reader = (mp_reader_posix_t *)data; if (reader->pos >= reader->len) { if (reader->len == 0) { @@ -101,7 +101,7 @@ STATIC mp_uint_t mp_reader_posix_readbyte(void *data) { return reader->buf[reader->pos++]; } -STATIC void mp_reader_posix_close(void *data) { +static void mp_reader_posix_close(void *data) { mp_reader_posix_t *reader = (mp_reader_posix_t *)data; if (reader->close_fd) { MP_THREAD_GIL_EXIT(); diff --git a/py/repl.c b/py/repl.c index cf69d3d8993df..b79a2d3c42783 100644 --- a/py/repl.c +++ b/py/repl.c @@ -43,7 +43,7 @@ const char *mp_repl_get_psx(unsigned int entry) { } #endif -STATIC bool str_startswith_word(const char *str, const char *head) { +static bool str_startswith_word(const char *str, const char *head) { size_t i; for (i = 0; str[i] && head[i]; i++) { if (str[i] != head[i]) { @@ -154,7 +154,7 @@ bool mp_repl_continue_with_input(const char *input) { return false; } -STATIC bool test_qstr(mp_obj_t obj, qstr name) { +static bool test_qstr(mp_obj_t obj, qstr name) { if (obj) { // try object member mp_obj_t dest[2]; @@ -167,7 +167,7 @@ STATIC bool test_qstr(mp_obj_t obj, qstr name) { } } -STATIC const char *find_completions(const char *s_start, size_t s_len, +static const char *find_completions(const char *s_start, size_t s_len, mp_obj_t obj, size_t *match_len, qstr *q_first, qstr *q_last) { const char *match_str = NULL; @@ -207,7 +207,7 @@ STATIC const char *find_completions(const char *s_start, size_t s_len, return match_str; } -STATIC void print_completions(const mp_print_t *print, +static void print_completions(const mp_print_t *print, const char *s_start, size_t s_len, mp_obj_t obj, qstr q_first, qstr q_last) { diff --git a/py/runtime.c b/py/runtime.c index 6d8eddedc8646..f7e0abdb46009 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -731,7 +731,7 @@ mp_obj_t mp_call_method_n_kw(size_t n_args, size_t n_kw, const mp_obj_t *args) { // This function only needs to be exposed externally when in stackless mode. #if !MICROPY_STACKLESS -STATIC +static #endif void mp_call_prepare_args_n_kw_var(bool have_self, size_t n_args_n_kw, const mp_obj_t *args, mp_call_args_t *out_args) { mp_obj_t fun = *args++; @@ -1074,7 +1074,7 @@ typedef struct _mp_obj_checked_fun_t { mp_obj_t fun; } mp_obj_checked_fun_t; -STATIC mp_obj_t checked_fun_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t checked_fun_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_obj_checked_fun_t *self = MP_OBJ_TO_PTR(self_in); if (n_args > 0) { const mp_obj_type_t *arg0_type = mp_obj_get_type(args[0]); @@ -1090,14 +1090,14 @@ STATIC mp_obj_t checked_fun_call(mp_obj_t self_in, size_t n_args, size_t n_kw, c return mp_call_function_n_kw(self->fun, n_args, n_kw, args); } -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_checked_fun, MP_QSTR_function, MP_TYPE_FLAG_BINDS_SELF, call, checked_fun_call ); -STATIC mp_obj_t mp_obj_new_checked_fun(const mp_obj_type_t *type, mp_obj_t fun) { +static mp_obj_t mp_obj_new_checked_fun(const mp_obj_type_t *type, mp_obj_t fun) { mp_obj_checked_fun_t *o = mp_obj_malloc(mp_obj_checked_fun_t, &mp_type_checked_fun); o->type = type; o->fun = fun; @@ -1326,7 +1326,7 @@ mp_obj_t mp_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) { } -STATIC mp_fun_1_t type_get_iternext(const mp_obj_type_t *type) { +static mp_fun_1_t type_get_iternext(const mp_obj_type_t *type) { if ((type->flags & MP_TYPE_FLAG_ITER_IS_STREAM) == MP_TYPE_FLAG_ITER_IS_STREAM) { return mp_stream_unbuffered_iter; } else if (type->flags & MP_TYPE_FLAG_ITER_IS_ITERNEXT) { diff --git a/py/scope.c b/py/scope.c index 8fc0943289b4f..1a4c6cc77f156 100644 --- a/py/scope.c +++ b/py/scope.c @@ -31,7 +31,7 @@ #if MICROPY_ENABLE_COMPILER // These low numbered qstrs should fit in 8 bits. See assertions below. -STATIC const uint8_t scope_simple_name_table[] = { +static const uint8_t scope_simple_name_table[] = { [SCOPE_MODULE] = MP_QSTR__lt_module_gt_, [SCOPE_LAMBDA] = MP_QSTR__lt_lambda_gt_, [SCOPE_LIST_COMP] = MP_QSTR__lt_listcomp_gt_, @@ -111,7 +111,7 @@ id_info_t *scope_find_global(scope_t *scope, qstr qst) { return scope_find(scope, qst); } -STATIC void scope_close_over_in_parents(scope_t *scope, qstr qst) { +static void scope_close_over_in_parents(scope_t *scope, qstr qst) { assert(scope->parent != NULL); // we should have at least 1 parent for (scope_t *s = scope->parent;; s = s->parent) { assert(s->parent != NULL); // we should not get to the outer scope diff --git a/py/stream.c b/py/stream.c index ac0234ac1353c..aa905ca8cc904 100644 --- a/py/stream.c +++ b/py/stream.c @@ -38,7 +38,7 @@ // TODO: should be in mpconfig.h #define DEFAULT_BUFFER_SIZE 256 -STATIC mp_obj_t stream_readall(mp_obj_t self_in); +static mp_obj_t stream_readall(mp_obj_t self_in); // Returns error condition in *errcode, if non-zero, return value is number of bytes written // before error condition occurred. If *errcode == 0, returns total bytes written (which will @@ -96,7 +96,7 @@ const mp_stream_p_t *mp_get_stream_raise(mp_obj_t self_in, int flags) { mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("stream operation not supported")); } -STATIC mp_obj_t stream_read_generic(size_t n_args, const mp_obj_t *args, byte flags) { +static mp_obj_t stream_read_generic(size_t n_args, const mp_obj_t *args, byte flags) { // What to do if sz < -1? Python docs don't specify this case. // CPython does a readall, but here we silently let negatives through, // and they will cause a MemoryError. @@ -218,12 +218,12 @@ STATIC mp_obj_t stream_read_generic(size_t n_args, const mp_obj_t *args, byte fl } } -STATIC mp_obj_t stream_read(size_t n_args, const mp_obj_t *args) { +static mp_obj_t stream_read(size_t n_args, const mp_obj_t *args) { return stream_read_generic(n_args, args, MP_STREAM_RW_READ); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_read_obj, 1, 2, stream_read); -STATIC mp_obj_t stream_read1(size_t n_args, const mp_obj_t *args) { +static mp_obj_t stream_read1(size_t n_args, const mp_obj_t *args) { return stream_read_generic(n_args, args, MP_STREAM_RW_READ | MP_STREAM_RW_ONCE); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_read1_obj, 1, 2, stream_read1); @@ -249,7 +249,7 @@ void mp_stream_write_adaptor(void *self, const char *buf, size_t len) { mp_stream_write(MP_OBJ_FROM_PTR(self), buf, len, MP_STREAM_RW_WRITE); } -STATIC mp_obj_t stream_write_method(size_t n_args, const mp_obj_t *args) { +static mp_obj_t stream_write_method(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_READ); size_t max_len = (size_t)-1; @@ -268,14 +268,14 @@ STATIC mp_obj_t stream_write_method(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_write_obj, 2, 4, stream_write_method); -STATIC mp_obj_t stream_write1_method(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t stream_write1_method(mp_obj_t self_in, mp_obj_t arg) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ); return mp_stream_write(self_in, bufinfo.buf, bufinfo.len, MP_STREAM_RW_WRITE | MP_STREAM_RW_ONCE); } MP_DEFINE_CONST_FUN_OBJ_2(mp_stream_write1_obj, stream_write1_method); -STATIC mp_obj_t stream_readinto(size_t n_args, const mp_obj_t *args) { +static mp_obj_t stream_readinto(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_WRITE); @@ -303,7 +303,7 @@ STATIC mp_obj_t stream_readinto(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_readinto_obj, 2, 3, stream_readinto); -STATIC mp_obj_t stream_readall(mp_obj_t self_in) { +static mp_obj_t stream_readall(mp_obj_t self_in) { const mp_stream_p_t *stream_p = mp_get_stream(self_in); mp_uint_t total_size = 0; @@ -348,7 +348,7 @@ STATIC mp_obj_t stream_readall(mp_obj_t self_in) { } // Unbuffered, inefficient implementation of readline() for raw I/O files. -STATIC mp_obj_t stream_unbuffered_readline(size_t n_args, const mp_obj_t *args) { +static mp_obj_t stream_unbuffered_readline(size_t n_args, const mp_obj_t *args) { const mp_stream_p_t *stream_p = mp_get_stream(args[0]); mp_int_t max_size = -1; @@ -406,7 +406,7 @@ STATIC mp_obj_t stream_unbuffered_readline(size_t n_args, const mp_obj_t *args) MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_unbuffered_readline_obj, 1, 2, stream_unbuffered_readline); // TODO take an optional extra argument (what does it do exactly?) -STATIC mp_obj_t stream_unbuffered_readlines(mp_obj_t self) { +static mp_obj_t stream_unbuffered_readlines(mp_obj_t self) { mp_obj_t lines = mp_obj_new_list(0, NULL); for (;;) { mp_obj_t line = stream_unbuffered_readline(1, &self); @@ -438,13 +438,13 @@ mp_obj_t mp_stream_close(mp_obj_t stream) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_stream_close_obj, mp_stream_close); -STATIC mp_obj_t mp_stream___exit__(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_stream___exit__(size_t n_args, const mp_obj_t *args) { (void)n_args; return mp_stream_close(args[0]); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream___exit___obj, 4, 4, mp_stream___exit__); -STATIC mp_obj_t stream_seek(size_t n_args, const mp_obj_t *args) { +static mp_obj_t stream_seek(size_t n_args, const mp_obj_t *args) { struct mp_stream_seek_t seek_s; // TODO: Could be uint64 seek_s.offset = mp_obj_get_int(args[1]); @@ -470,7 +470,7 @@ STATIC mp_obj_t stream_seek(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_seek_obj, 2, 3, stream_seek); -STATIC mp_obj_t stream_tell(mp_obj_t self) { +static mp_obj_t stream_tell(mp_obj_t self) { mp_obj_t offset = MP_OBJ_NEW_SMALL_INT(0); mp_obj_t whence = MP_OBJ_NEW_SMALL_INT(SEEK_CUR); const mp_obj_t args[3] = {self, offset, whence}; @@ -478,7 +478,7 @@ STATIC mp_obj_t stream_tell(mp_obj_t self) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_stream_tell_obj, stream_tell); -STATIC mp_obj_t stream_flush(mp_obj_t self) { +static mp_obj_t stream_flush(mp_obj_t self) { const mp_stream_p_t *stream_p = mp_get_stream(self); int error; mp_uint_t res = stream_p->ioctl(self, MP_STREAM_FLUSH, 0, &error); @@ -489,7 +489,7 @@ STATIC mp_obj_t stream_flush(mp_obj_t self) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_stream_flush_obj, stream_flush); -STATIC mp_obj_t stream_ioctl(size_t n_args, const mp_obj_t *args) { +static mp_obj_t stream_ioctl(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t bufinfo; uintptr_t val = 0; if (n_args > 2) { diff --git a/py/unicode.c b/py/unicode.c index 5acaad378843c..81a37880f3c72 100644 --- a/py/unicode.c +++ b/py/unicode.c @@ -48,7 +48,7 @@ #define AT_LX (FL_LOWER | FL_ALPHA | FL_PRINT | FL_XDIGIT) // table of attributes for ascii characters -STATIC const uint8_t attr[] = { +static const uint8_t attr[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, AT_SP, AT_SP, AT_SP, AT_SP, AT_SP, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, diff --git a/py/vstr.c b/py/vstr.c index 56327b5f7ac7c..fc55d6948ccf2 100644 --- a/py/vstr.c +++ b/py/vstr.c @@ -104,7 +104,7 @@ char *vstr_extend(vstr_t *vstr, size_t size) { return p; } -STATIC void vstr_ensure_extra(vstr_t *vstr, size_t size) { +static void vstr_ensure_extra(vstr_t *vstr, size_t size) { if (vstr->len + size > vstr->alloc) { if (vstr->fixed_buf) { // We can't reallocate, and the caller is expecting the space to @@ -183,7 +183,7 @@ void vstr_add_strn(vstr_t *vstr, const char *str, size_t len) { vstr->len += len; } -STATIC char *vstr_ins_blank_bytes(vstr_t *vstr, size_t byte_pos, size_t byte_len) { +static char *vstr_ins_blank_bytes(vstr_t *vstr, size_t byte_pos, size_t byte_len) { size_t l = vstr->len; if (byte_pos > l) { byte_pos = l; diff --git a/shared/libc/printf.c b/shared/libc/printf.c index 715181229e4fc..50b04ce9be082 100644 --- a/shared/libc/printf.c +++ b/shared/libc/printf.c @@ -87,7 +87,7 @@ typedef struct _strn_print_env_t { size_t remain; } strn_print_env_t; -STATIC void strn_print_strn(void *data, const char *str, size_t len) { +static void strn_print_strn(void *data, const char *str, size_t len) { strn_print_env_t *strn_print_env = data; if (len > strn_print_env->remain) { len = strn_print_env->remain; diff --git a/shared/readline/readline.c b/shared/readline/readline.c index b85bbd5bea85a..c9386f16b575d 100644 --- a/shared/readline/readline.c +++ b/shared/readline/readline.c @@ -55,7 +55,7 @@ void readline_init0(void) { memset(MP_STATE_PORT(readline_hist), 0, MICROPY_READLINE_HISTORY_SIZE * sizeof(const char*)); } -STATIC char *str_dup_maybe(const char *str) { +static char *str_dup_maybe(const char *str) { uint32_t len = strlen(str); char *s2 = m_new_maybe(char, len + 1); if (s2 == NULL) { @@ -72,7 +72,7 @@ STATIC char *str_dup_maybe(const char *str) { // ...and provide the implementation using them #if MICROPY_HAL_HAS_VT100 -STATIC void mp_hal_move_cursor_back(uint pos) { +static void mp_hal_move_cursor_back(uint pos) { if (pos <= 4) { // fast path for most common case of 1 step back mp_hal_stdout_tx_strn("\b\b\b\b", pos); @@ -88,7 +88,7 @@ STATIC void mp_hal_move_cursor_back(uint pos) { } } -STATIC void mp_hal_erase_line_from_cursor(uint n_chars_to_erase) { +static void mp_hal_erase_line_from_cursor(uint n_chars_to_erase) { (void)n_chars_to_erase; mp_hal_stdout_tx_strn("\x1b[K", 3); } @@ -107,10 +107,10 @@ typedef struct _readline_t { const char *prompt; } readline_t; -STATIC readline_t rl; +static readline_t rl; #if MICROPY_REPL_EMACS_WORDS_MOVE -STATIC size_t cursor_count_word(int forward) { +static size_t cursor_count_word(int forward) { const char *line_buf = vstr_str(rl.line); size_t pos = rl.cursor_pos; bool in_word = false; @@ -481,7 +481,7 @@ int readline_process_char(int c) { } #if MICROPY_REPL_AUTO_INDENT -STATIC void readline_auto_indent(void) { +static void readline_auto_indent(void) { if (!(rl.auto_indent_state & AUTO_INDENT_ENABLED)) { return; } diff --git a/shared/runtime/gchelper_generic.c b/shared/runtime/gchelper_generic.c index 272e37056aaa8..4ef2e73f7a2ee 100644 --- a/shared/runtime/gchelper_generic.c +++ b/shared/runtime/gchelper_generic.c @@ -42,7 +42,7 @@ // stack already by the caller. #if defined(__x86_64__) -STATIC void gc_helper_get_regs(gc_helper_regs_t arr) { +static void gc_helper_get_regs(gc_helper_regs_t arr) { register long rbx asm ("rbx"); register long rbp asm ("rbp"); register long r12 asm ("r12"); @@ -73,7 +73,7 @@ STATIC void gc_helper_get_regs(gc_helper_regs_t arr) { #elif defined(__i386__) -STATIC void gc_helper_get_regs(gc_helper_regs_t arr) { +static void gc_helper_get_regs(gc_helper_regs_t arr) { register long ebx asm ("ebx"); register long esi asm ("esi"); register long edi asm ("edi"); @@ -100,7 +100,7 @@ STATIC void gc_helper_get_regs(gc_helper_regs_t arr) { // Fallback implementation, prefer gchelper_thumb1.s or gchelper_thumb2.s -STATIC void gc_helper_get_regs(gc_helper_regs_t arr) { +static void gc_helper_get_regs(gc_helper_regs_t arr) { register long r4 asm ("r4"); register long r5 asm ("r5"); register long r6 asm ("r6"); @@ -125,7 +125,7 @@ STATIC void gc_helper_get_regs(gc_helper_regs_t arr) { #elif defined(__aarch64__) -STATIC void gc_helper_get_regs(gc_helper_regs_t arr) { +static void gc_helper_get_regs(gc_helper_regs_t arr) { const register long x19 asm ("x19"); const register long x20 asm ("x20"); const register long x21 asm ("x21"); @@ -161,7 +161,7 @@ STATIC void gc_helper_get_regs(gc_helper_regs_t arr) { // Even if we have specific support for an architecture, it is // possible to force use of setjmp-based implementation. -STATIC void gc_helper_get_regs(gc_helper_regs_t arr) { +static void gc_helper_get_regs(gc_helper_regs_t arr) { setjmp(arr); } diff --git a/shared/runtime/mpirq.c b/shared/runtime/mpirq.c index acd727403b558..6111b9b10cfe4 100644 --- a/shared/runtime/mpirq.c +++ b/shared/runtime/mpirq.c @@ -96,13 +96,13 @@ void mp_irq_handler(mp_irq_obj_t *self) { /******************************************************************************/ // MicroPython bindings -STATIC mp_obj_t mp_irq_flags(mp_obj_t self_in) { +static mp_obj_t mp_irq_flags(mp_obj_t self_in) { mp_irq_obj_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_int(self->methods->info(self->parent, MP_IRQ_INFO_FLAGS)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_irq_flags_obj, mp_irq_flags); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_irq_flags_obj, mp_irq_flags); -STATIC mp_obj_t mp_irq_trigger(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_irq_trigger(size_t n_args, const mp_obj_t *args) { mp_irq_obj_t *self = MP_OBJ_TO_PTR(args[0]); mp_obj_t ret_obj = mp_obj_new_int(self->methods->info(self->parent, MP_IRQ_INFO_TRIGGERS)); if (n_args == 2) { @@ -111,19 +111,19 @@ STATIC mp_obj_t mp_irq_trigger(size_t n_args, const mp_obj_t *args) { } return ret_obj; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_irq_trigger_obj, 1, 2, mp_irq_trigger); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_irq_trigger_obj, 1, 2, mp_irq_trigger); -STATIC mp_obj_t mp_irq_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t mp_irq_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 0, false); mp_irq_handler(MP_OBJ_TO_PTR(self_in)); return mp_const_none; } -STATIC const mp_rom_map_elem_t mp_irq_locals_dict_table[] = { +static const mp_rom_map_elem_t mp_irq_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_flags), MP_ROM_PTR(&mp_irq_flags_obj) }, { MP_ROM_QSTR(MP_QSTR_trigger), MP_ROM_PTR(&mp_irq_trigger_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_irq_locals_dict, mp_irq_locals_dict_table); +static MP_DEFINE_CONST_DICT(mp_irq_locals_dict, mp_irq_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mp_irq_type, diff --git a/shared/runtime/pyexec.c b/shared/runtime/pyexec.c index cc2aa535042c8..a305e6a5df6dd 100644 --- a/shared/runtime/pyexec.c +++ b/shared/runtime/pyexec.c @@ -47,7 +47,7 @@ pyexec_mode_kind_t pyexec_mode_kind = PYEXEC_MODE_FRIENDLY_REPL; int pyexec_system_exit = 0; #if MICROPY_REPL_INFO -STATIC bool repl_display_debugging_info = 0; +static bool repl_display_debugging_info = 0; #endif #define EXEC_FLAG_PRINT_EOF (1 << 0) @@ -64,7 +64,7 @@ STATIC bool repl_display_debugging_info = 0; // EXEC_FLAG_PRINT_EOF prints 2 EOF chars: 1 after normal output, 1 after exception output // EXEC_FLAG_ALLOW_DEBUGGING allows debugging info to be printed after executing the code // EXEC_FLAG_IS_REPL is used for REPL inputs (flag passed on to mp_compile) -STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input_kind, mp_uint_t exec_flags) { +static int parse_compile_execute(const void *source, mp_parse_input_kind_t input_kind, mp_uint_t exec_flags) { int ret = 0; #if MICROPY_REPL_INFO uint32_t start = 0; @@ -201,7 +201,7 @@ typedef struct _mp_reader_stdin_t { uint16_t window_remain; } mp_reader_stdin_t; -STATIC mp_uint_t mp_reader_stdin_readbyte(void *data) { +static mp_uint_t mp_reader_stdin_readbyte(void *data) { mp_reader_stdin_t *reader = (mp_reader_stdin_t *)data; if (reader->eof) { @@ -233,7 +233,7 @@ STATIC mp_uint_t mp_reader_stdin_readbyte(void *data) { return c; } -STATIC void mp_reader_stdin_close(void *data) { +static void mp_reader_stdin_close(void *data) { mp_reader_stdin_t *reader = (mp_reader_stdin_t *)data; if (!reader->eof) { reader->eof = true; @@ -247,7 +247,7 @@ STATIC void mp_reader_stdin_close(void *data) { } } -STATIC void mp_reader_new_stdin(mp_reader_t *reader, mp_reader_stdin_t *reader_stdin, uint16_t buf_max) { +static void mp_reader_new_stdin(mp_reader_t *reader, mp_reader_stdin_t *reader_stdin, uint16_t buf_max) { // Make flow-control window half the buffer size, and indicate to the host that 2x windows are // free (sending the window size implicitly indicates that a window is free, and then the 0x01 // indicates that another window is free). @@ -263,7 +263,7 @@ STATIC void mp_reader_new_stdin(mp_reader_t *reader, mp_reader_stdin_t *reader_s reader->close = mp_reader_stdin_close; } -STATIC int do_reader_stdin(int c) { +static int do_reader_stdin(int c) { if (c != 'A') { // Unsupported command. mp_hal_stdout_tx_strn("R\x00", 2); @@ -294,8 +294,8 @@ typedef struct _repl_t { repl_t repl; -STATIC int pyexec_raw_repl_process_char(int c); -STATIC int pyexec_friendly_repl_process_char(int c); +static int pyexec_raw_repl_process_char(int c); +static int pyexec_friendly_repl_process_char(int c); void pyexec_event_repl_init(void) { MP_STATE_VM(repl_line) = vstr_new(32); @@ -310,7 +310,7 @@ void pyexec_event_repl_init(void) { } } -STATIC int pyexec_raw_repl_process_char(int c) { +static int pyexec_raw_repl_process_char(int c) { if (c == CHAR_CTRL_A) { // reset raw REPL if (vstr_len(MP_STATE_VM(repl_line)) == 2 && vstr_str(MP_STATE_VM(repl_line))[0] == CHAR_CTRL_E) { @@ -364,7 +364,7 @@ STATIC int pyexec_raw_repl_process_char(int c) { return 0; } -STATIC int pyexec_friendly_repl_process_char(int c) { +static int pyexec_friendly_repl_process_char(int c) { if (repl.paste_mode) { if (c == CHAR_CTRL_C) { // cancel everything diff --git a/shared/runtime/softtimer.c b/shared/runtime/softtimer.c index 468fa95b7208c..13a6e78777ef4 100644 --- a/shared/runtime/softtimer.c +++ b/shared/runtime/softtimer.c @@ -56,9 +56,9 @@ static void soft_timer_schedule_at_ms(uint32_t ticks_ms) { // Pointer to the pairheap of soft timer objects. // This may contain bss/data pointers as well as GC-heap pointers, // and is explicitly GC traced by soft_timer_gc_mark_all(). -STATIC soft_timer_entry_t *soft_timer_heap; +static soft_timer_entry_t *soft_timer_heap; -STATIC int soft_timer_lt(mp_pairheap_t *n1, mp_pairheap_t *n2) { +static int soft_timer_lt(mp_pairheap_t *n1, mp_pairheap_t *n2) { soft_timer_entry_t *e1 = (soft_timer_entry_t *)n1; soft_timer_entry_t *e2 = (soft_timer_entry_t *)n2; return soft_timer_ticks_diff(e1->expiry_ms, e2->expiry_ms) < 0; diff --git a/shared/runtime/sys_stdio_mphal.c b/shared/runtime/sys_stdio_mphal.c index b7a35a5cbaa0b..ad045fb3a9537 100644 --- a/shared/runtime/sys_stdio_mphal.c +++ b/shared/runtime/sys_stdio_mphal.c @@ -49,15 +49,15 @@ typedef struct _sys_stdio_obj_t { } sys_stdio_obj_t; #if MICROPY_PY_SYS_STDIO_BUFFER -STATIC const sys_stdio_obj_t stdio_buffer_obj; +static const sys_stdio_obj_t stdio_buffer_obj; #endif -STATIC void stdio_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void stdio_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { sys_stdio_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", self->fd); } -STATIC mp_uint_t stdio_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t stdio_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { sys_stdio_obj_t *self = MP_OBJ_TO_PTR(self_in); if (self->fd == STDIO_FD_IN) { for (uint i = 0; i < size; i++) { @@ -74,7 +74,7 @@ STATIC mp_uint_t stdio_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *er } } -STATIC mp_uint_t stdio_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t stdio_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { sys_stdio_obj_t *self = MP_OBJ_TO_PTR(self_in); if (self->fd == STDIO_FD_OUT || self->fd == STDIO_FD_ERR) { mp_hal_stdout_tx_strn_cooked(buf, size); @@ -85,7 +85,7 @@ STATIC mp_uint_t stdio_write(mp_obj_t self_in, const void *buf, mp_uint_t size, } } -STATIC mp_uint_t stdio_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t stdio_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { (void)self_in; if (request == MP_STREAM_POLL) { return mp_hal_stdio_poll(arg); @@ -97,7 +97,7 @@ STATIC mp_uint_t stdio_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, } } -STATIC const mp_rom_map_elem_t stdio_locals_dict_table[] = { +static const mp_rom_map_elem_t stdio_locals_dict_table[] = { #if MICROPY_PY_SYS_STDIO_BUFFER { MP_ROM_QSTR(MP_QSTR_buffer), MP_ROM_PTR(&stdio_buffer_obj) }, #endif @@ -111,9 +111,9 @@ STATIC const mp_rom_map_elem_t stdio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&mp_stream___exit___obj) }, }; -STATIC MP_DEFINE_CONST_DICT(stdio_locals_dict, stdio_locals_dict_table); +static MP_DEFINE_CONST_DICT(stdio_locals_dict, stdio_locals_dict_table); -STATIC const mp_stream_p_t stdio_obj_stream_p = { +static const mp_stream_p_t stdio_obj_stream_p = { .read = stdio_read, .write = stdio_write, .ioctl = stdio_ioctl, @@ -134,25 +134,25 @@ const sys_stdio_obj_t mp_sys_stdout_obj = {{&stdio_obj_type}, .fd = STDIO_FD_OUT const sys_stdio_obj_t mp_sys_stderr_obj = {{&stdio_obj_type}, .fd = STDIO_FD_ERR}; #if MICROPY_PY_SYS_STDIO_BUFFER -STATIC mp_uint_t stdio_buffer_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t stdio_buffer_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { for (uint i = 0; i < size; i++) { ((byte *)buf)[i] = mp_hal_stdin_rx_chr(); } return size; } -STATIC mp_uint_t stdio_buffer_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t stdio_buffer_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { return mp_hal_stdout_tx_strn(buf, size); } -STATIC const mp_stream_p_t stdio_buffer_obj_stream_p = { +static const mp_stream_p_t stdio_buffer_obj_stream_p = { .read = stdio_buffer_read, .write = stdio_buffer_write, .ioctl = stdio_ioctl, .is_text = false, }; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( stdio_buffer_obj_type, MP_QSTR_FileIO, MP_TYPE_FLAG_ITER_IS_STREAM, @@ -161,5 +161,5 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &stdio_locals_dict ); -STATIC const sys_stdio_obj_t stdio_buffer_obj = {{&stdio_buffer_obj_type}, .fd = 0}; // fd unused +static const sys_stdio_obj_t stdio_buffer_obj = {{&stdio_buffer_obj_type}, .fd = 0}; // fd unused #endif diff --git a/shared/timeutils/timeutils.c b/shared/timeutils/timeutils.c index 6bf3eca84a82b..4282a0178dd6e 100644 --- a/shared/timeutils/timeutils.c +++ b/shared/timeutils/timeutils.c @@ -40,7 +40,7 @@ #define DAYS_PER_100Y (365 * 100 + 24) #define DAYS_PER_4Y (365 * 4 + 1) -STATIC const uint16_t days_since_jan1[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }; +static const uint16_t days_since_jan1[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }; bool timeutils_is_leap_year(mp_uint_t year) { return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0; @@ -125,7 +125,7 @@ void timeutils_seconds_since_2000_to_struct_time(mp_uint_t t, timeutils_struct_t tm->tm_year = 2000 + years + 4 * q_cycles + 100 * c_cycles + 400 * qc_cycles; // Note: days_in_month[0] corresponds to March - STATIC const int8_t days_in_month[] = {31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29}; + static const int8_t days_in_month[] = {31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29}; mp_int_t month; for (month = 0; days_in_month[month] <= days; month++) { diff --git a/shared/tinyusb/mp_cdc_common.c b/shared/tinyusb/mp_cdc_common.c index 8278685262fa1..e790646f4f86d 100644 --- a/shared/tinyusb/mp_cdc_common.c +++ b/shared/tinyusb/mp_cdc_common.c @@ -34,7 +34,7 @@ static mp_sched_node_t mp_bootloader_sched_node; -STATIC void usbd_cdc_run_bootloader_task(mp_sched_node_t *node) { +static void usbd_cdc_run_bootloader_task(mp_sched_node_t *node) { mp_hal_delay_ms(250); machine_bootloader(0, NULL); } diff --git a/tools/boardgen.py b/tools/boardgen.py index caa9fe851c768..41a8e9f2e597b 100644 --- a/tools/boardgen.py +++ b/tools/boardgen.py @@ -289,7 +289,7 @@ def find_pin_by_cpu_pin_name(self, cpu_pin_name, create=True): def print_board_locals_dict(self, out_source): print(file=out_source) print( - "STATIC const mp_rom_map_elem_t machine_pin_board_pins_locals_dict_table[] = {", + "static const mp_rom_map_elem_t machine_pin_board_pins_locals_dict_table[] = {", file=out_source, ) for pin in self.available_pins(): @@ -318,7 +318,7 @@ def print_board_locals_dict(self, out_source): def print_cpu_locals_dict(self, out_source): print(file=out_source) print( - "STATIC const mp_rom_map_elem_t machine_pin_cpu_pins_locals_dict_table[] = {", + "static const mp_rom_map_elem_t machine_pin_cpu_pins_locals_dict_table[] = {", file=out_source, ) for pin in self.available_pins(exclude_hidden=True): From dda9b9c6da5d3c31fa8769e581a753e95a270803 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Thu, 29 Feb 2024 00:27:06 +0000 Subject: [PATCH 181/408] all: Prune trailing whitespace. Prune trailing whitespace across the whole project (almost), done automatically with: grep -IUrl --color "[[:blank:]]$" --exclude-dir=.git --exclude=*.exp |\ xargs sed -i 's/[[:space:]]*$//' Exceptions: - Skip third-party code in lib/ and drivers/cc3100/ - Skip generated code in bluetooth_init_cc2564C_1.5.c - Preserve command output whitespace in docs, eg: docs/esp8266/tutorial/repl.rst Signed-off-by: Phil Howard --- .github/workflows/ports_windows.yml | 6 +- docs/develop/gettingstarted.rst | 2 +- docs/differences/python_37.rst | 2 +- docs/library/machine.ADCBlock.rst | 2 +- docs/library/machine.PWM.rst | 4 +- docs/mimxrt/pinout.rst | 4 +- docs/mimxrt/quickref.rst | 2 +- docs/samd/pinout.rst | 86 +++---- extmod/axtls-include/config.h | 14 +- logo/FONT-LICENSE.txt | 2 +- ports/cc3200/README.md | 10 +- ports/cc3200/application.lds | 4 +- ports/cc3200/bootmgr/bootgen.sh | 2 +- ports/cc3200/bootmgr/bootloader.mk | 4 +- ports/cc3200/bootmgr/flc.h | 6 +- ports/cc3200/bootmgr/sl/user.h | 56 ++--- ports/cc3200/fatfs/src/drivers/stdcmd.h | 34 +-- ports/cc3200/hal/cc3200_hal.c | 2 +- ports/cc3200/hal/gpio.c | 2 +- ports/cc3200/hal/inc/hw_memmap.h | 2 +- ports/cc3200/hal/pin.h | 4 +- ports/cc3200/hal/prcm.h | 4 +- ports/cc3200/hal/spi.c | 2 +- ports/cc3200/simplelink/oslib/osi.h | 64 +++--- ports/cc3200/simplelink/oslib/osi_freertos.c | 56 ++--- ports/cc3200/simplelink/user.h | 56 ++--- ports/embed/embed.mk | 2 +- ports/esp32/README.ulp.md | 12 +- .../boards/OLIMEX_RT1010/deploy_olimex.md | 8 +- .../boards/SEEED_ARCH_MIX/mpconfigboard.mk | 2 +- ports/mimxrt/boards/common.ld | 14 +- .../boards/ACTINIUS_ICARUS/mpconfigboard.mk | 2 +- .../boards/NRF52840_MDK_USB_DONGLE/README.md | 2 +- .../drivers/bluetooth/download_ble_stack.sh | 4 +- ports/renesas-ra/Makefile | 4 +- ports/rp2/CMakeLists.txt | 2 +- ports/stm32/Makefile | 2 +- ports/stm32/boards/stm32h7b3.ld | 2 +- .../stm32/usbdev/class/inc/usbd_cdc_msc_hid.h | 14 +- tests/README.md | 2 +- tests/basics/generator_throw.py | 4 +- tests/basics/int_big_and2.py | 4 +- tests/basics/int_big_and3.py | 4 +- tests/basics/int_big_or.py | 8 +- tests/basics/int_big_or2.py | 4 +- tests/basics/int_big_or3.py | 4 +- tests/basics/int_big_xor.py | 8 +- tests/basics/int_big_xor2.py | 4 +- tests/basics/int_big_xor3.py | 4 +- tests/io/data/bigfile1 | 214 +++++++++--------- tests/ports/cc3200/pin.py | 6 +- tests/ports/cc3200/uart.py | 2 +- tools/codestats.sh | 2 +- 53 files changed, 386 insertions(+), 386 deletions(-) diff --git a/.github/workflows/ports_windows.yml b/.github/workflows/ports_windows.yml index a2759880a2f65..be2a2a8dac332 100644 --- a/.github/workflows/ports_windows.yml +++ b/.github/workflows/ports_windows.yml @@ -56,14 +56,14 @@ jobs: - uses: actions/setup-python@v5 if: matrix.runner == 'windows-2019' with: - python-version: '3.9' + python-version: '3.9' - uses: actions/checkout@v4 - name: Build mpy-cross.exe run: msbuild mpy-cross\mpy-cross.vcxproj -maxcpucount -property:Configuration=${{ matrix.configuration }} -property:Platform=${{ matrix.platform }} - name: Update submodules run: git submodule update --init lib/micropython-lib - name: Build micropython.exe - run: msbuild ports\windows\micropython.vcxproj -maxcpucount -property:Configuration=${{ matrix.configuration }} -property:Platform=${{ matrix.platform }} -property:PyVariant=${{ matrix.variant }} + run: msbuild ports\windows\micropython.vcxproj -maxcpucount -property:Configuration=${{ matrix.configuration }} -property:Platform=${{ matrix.platform }} -property:PyVariant=${{ matrix.variant }} - name: Get micropython.exe path id: get_path run: | @@ -123,7 +123,7 @@ jobs: msystem: ${{ matrix.sys }} update: true install: >- - make + make mingw-w64-${{ matrix.env }}-gcc pkg-config python3 diff --git a/docs/develop/gettingstarted.rst b/docs/develop/gettingstarted.rst index a17a320671f52..c1fd338c54cc0 100644 --- a/docs/develop/gettingstarted.rst +++ b/docs/develop/gettingstarted.rst @@ -112,7 +112,7 @@ Check that you have Python available on your system: .. code-block:: bash $ python3 - Python 3.5.0 (default, Jul 17 2020, 14:04:10) + Python 3.5.0 (default, Jul 17 2020, 14:04:10) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> diff --git a/docs/differences/python_37.rst b/docs/differences/python_37.rst index 86d1b6e81f96d..2b9a089217f6d 100644 --- a/docs/differences/python_37.rst +++ b/docs/differences/python_37.rst @@ -105,4 +105,4 @@ Changes to built-in modules: .. rubric:: Notes -.. [#ftimenanosec] Only :func:`time.time_ns` is implemented. +.. [#ftimenanosec] Only :func:`time.time_ns` is implemented. diff --git a/docs/library/machine.ADCBlock.rst b/docs/library/machine.ADCBlock.rst index eb94362d5597c..e947f70815071 100644 --- a/docs/library/machine.ADCBlock.rst +++ b/docs/library/machine.ADCBlock.rst @@ -26,7 +26,7 @@ Constructors Access the ADC peripheral identified by *id*, which may be an integer or string. - + The *bits* argument, if given, sets the resolution in bits of the conversion process. If not specified then the previous or default resolution is used. diff --git a/docs/library/machine.PWM.rst b/docs/library/machine.PWM.rst index b9cf00240314c..5f592b8dff593 100644 --- a/docs/library/machine.PWM.rst +++ b/docs/library/machine.PWM.rst @@ -86,7 +86,7 @@ Specific PWM class implementations The following concrete class(es) implement enhancements to the PWM class. - | :ref:`pyb.Timer for PyBoard ` + | :ref:`pyb.Timer for PyBoard ` Limitations of PWM ------------------ @@ -103,7 +103,7 @@ Limitations of PWM Some ports like the RP2040 one use a fractional divider, which allow a finer granularity of the frequency at higher frequencies by switching the PWM pulse duration between two adjacent values, such that the resulting average - frequency is more close to the intended one, at the cost of spectral purity. + frequency is more close to the intended one, at the cost of spectral purity. * The duty cycle has the same discrete nature and its absolute accuracy is not achievable. On most hardware platforms the duty will be applied at the next diff --git a/docs/mimxrt/pinout.rst b/docs/mimxrt/pinout.rst index 16bb4722734a2..3ff892c64d688 100644 --- a/docs/mimxrt/pinout.rst +++ b/docs/mimxrt/pinout.rst @@ -319,7 +319,7 @@ MIXMXRT1050-EVKB D10/-/D11/D12/D13 (*) - - MIXMXRT1060-EVK D10/-/D11/D12/D13 (*) - - MIXMXRT1064-EVK D10/-/D11/D12/D13 (*) - - MIXMXRT1170-EVK D10/-/D11/D12/D13 D28/-/D25/D24/D26 -/-/D14/D15/D24 -Adafruit Metro M7 -/-/MOSI/MISO/SCK - - +Adafruit Metro M7 -/-/MOSI/MISO/SCK - - Olimex RT1010Py - CS0/-/SDO/SDI/SCK SDCARD with CS1 Seeed ARCH MIX J4_12/-/J4_14/J4_13/J4_15 J3_09/J3_05/J3_08_J3_11 ================= ========================= ======================= =============== @@ -375,7 +375,7 @@ Teensy 4.0 2 33 4 3 2 - - 5 Teensy 4.1 1 23 26 27 7 21 20 8 Teensy 4.1 2 33 4 3 2 - - 5 Seeed Arch MIX 1 J4_09 J4_14 J4_15 J14_13 J4_11 J4_10 J4_10 -Adafruit Metro M7 1 D8 D10 D9 D12 D14 D15 D13 +Adafruit Metro M7 1 D8 D10 D9 D12 D14 D15 D13 Olimex RT1010Py 1 D8 D6 D7 D4 D1 D2 D3 Olimex RT1010Py 3 - D10 D9 D11 - - - MIMXRT_DEV 1 "MCK" "SCK_TX" "WS_TX" "SD_TX" "SCK_RX" "WS_RX" "SD_RX" diff --git a/docs/mimxrt/quickref.rst b/docs/mimxrt/quickref.rst index 519313438321c..1a73929bedbe3 100644 --- a/docs/mimxrt/quickref.rst +++ b/docs/mimxrt/quickref.rst @@ -309,7 +309,7 @@ rates (up to 30Mhz). Hardware SPI is accessed via the For the assignment of Pins to SPI signals, refer to :ref:`Hardware SPI pinout `. The keyword option cs=n can be used to enable the cs pin 0 or 1 for an automatic cs signal. The -default is cs=-1. Using cs=-1 the automatic cs signal is not created. +default is cs=-1. Using cs=-1 the automatic cs signal is not created. In that case, cs has to be set by the script. Clearing that assignment requires a power cycle. Notes: diff --git a/docs/samd/pinout.rst b/docs/samd/pinout.rst index 5ff72b83586ac..5da4ae78d45b5 100644 --- a/docs/samd/pinout.rst +++ b/docs/samd/pinout.rst @@ -17,12 +17,12 @@ Adafruit ItsyBitsy M0 Express pin assignment table === ==== ============ ==== ==== ====== ====== ====== ====== Pin GPIO Pin name IRQ ADC Serial Serial TCC/TC TCC/TC === ==== ============ ==== ==== ====== ====== ====== ====== - 2 PA02 A0 2 0 - - - - - 40 PB08 A1 8 2 - 4/0 4/0 - - 41 PB09 A2 9 3 - 4/1 4/1 - - 4 PA04 A3 4 4 - 0/0 0/0 - - 5 PA05 A4 5 5 - 0/1 0/1 - - 34 PB02 A5 2 10 - 5/0 6/0 - + 2 PA02 A0 2 0 - - - - + 40 PB08 A1 8 2 - 4/0 4/0 - + 41 PB09 A2 9 3 - 4/1 4/1 - + 4 PA04 A3 4 4 - 0/0 0/0 - + 5 PA05 A4 5 5 - 0/1 0/1 - + 34 PB02 A5 2 10 - 5/0 6/0 - 11 PA11 D0 11 19 0/3 2/3 1/1 0/3 10 PA10 D1 10 18 0/2 2/2 1/0 0/2 14 PA14 D2 14 - 2/2 4/2 3/0 0/4 @@ -30,31 +30,31 @@ Pin GPIO Pin name IRQ ADC Serial Serial TCC/TC TCC/TC 8 PA08 D4 - 16 0/0 2/0 0/0 1/2 15 PA15 D5 15 - 2/3 4/3 3/1 0/5 21 PA21 D7 5 - 5/3 3/3 7/1 0/7 - 7 PA07 D9 7 7 - 0/3 1/1 - + 7 PA07 D9 7 7 - 0/3 1/1 - 18 PA18 D10 2 - 1/2 3/2 3/0 0/2 16 PA16 D11 0 - 1/0 3/0 2/0 0/6 19 PA19 D12 3 - 1/3 3/3 3/1 0/3 17 PA17 D13 1 - 1/1 3/1 2/1 0/7 - 0 PA00 DOTSTAR_CLK 0 - - 1/0 2/0 - - 1 PA01 DOTSTAR_DATA 1 - - 1/1 2/1 - - 27 PA27 FLASH_CS 15 - - - - - - 35 PB03 FLASH_MISO 3 11 - 5/1 6/1 - - 54 PB22 FLASH_MOSI 6 - - 5/2 7/0 - - 55 PB23 FLASH_SCK 7 - - 5/3 7/1 - + 0 PA00 DOTSTAR_CLK 0 - - 1/0 2/0 - + 1 PA01 DOTSTAR_DATA 1 - - 1/1 2/1 - + 27 PA27 FLASH_CS 15 - - - - - + 35 PB03 FLASH_MISO 3 11 - 5/1 6/1 - + 54 PB22 FLASH_MOSI 6 - - 5/2 7/0 - + 55 PB23 FLASH_SCK 7 - - 5/3 7/1 - 12 PA12 MISO 12 - 2/0 4/0 2/0 0/6 42 PB10 MOSI 10 - - 4/2 5/0 0/4 43 PB11 SCK 11 - - 4/3 5/1 0/5 23 PA23 SCL 7 - 3/1 5/1 4/1 0/5 22 PA22 SDA 6 - 3/0 5/0 4/0 0/4 - 30 PA30 SWCLK 10 - - 1/2 1/0 - - 31 PA31 SWDIO 11 - - 1/3 1/1 - + 30 PA30 SWCLK 10 - - 1/2 1/0 - + 31 PA31 SWDIO 11 - - 1/3 1/1 - 24 PA24 USB_DM 12 - 3/2 5/2 5/0 1/2 25 PA25 USB_DP 13 - 3/3 5/3 5/1 1/3 - 3 PA03 3 1 - - - - - 6 PA06 6 6 - 0/2 1/0 - + 3 PA03 3 1 - - - - + 6 PA06 6 6 - 0/2 1/0 - 13 PA13 13 - 2/1 4/1 2/0 0/7 20 PA20 4 - 5/2 3/2 7/0 0/4 - 28 PA28 8 - - - - - + 28 PA28 8 - - - - - === ==== ============ ==== ==== ====== ====== ====== ====== @@ -348,12 +348,12 @@ Adafruit Metro M4 Airlift pin assignment table === ==== ============ ==== ==== ==== ====== ====== ===== ===== ===== Pin GPIO Pin name IRQ ADC ADC Serial Serial TC PWM PWM === ==== ============ ==== ==== ==== ====== ====== ===== ===== ===== - 2 PA02 A0 2 0 - - - - - - - 5 PA05 A1 5 5 - - 0/1 0/1 - - - 6 PA06 A2 6 6 - - 0/2 1/0 - - - 32 PB00 A3 9 12 - - 5/2 7/0 - - - 40 PB08 A4 8 2 0 - 4/0 4/0 - - - 41 PB09 A5 9 3 1 - 4/1 4/1 - - + 2 PA02 A0 2 0 - - - - - - + 5 PA05 A1 5 5 - - 0/1 0/1 - - + 6 PA06 A2 6 6 - - 0/2 1/0 - - + 32 PB00 A3 9 12 - - 5/2 7/0 - - + 40 PB08 A4 8 2 0 - 4/0 4/0 - - + 41 PB09 A5 9 3 1 - 4/1 4/1 - - 23 PA23 D0 7 - - 3/1 5/0 4/1 1/7 0/3 22 PA22 D1 6 - - 3/0 5/1 4/0 1/6 0/2 49 PB17 D2 1 - - 5/1 - 6/1 3/1 0/5 @@ -364,17 +364,17 @@ Pin GPIO Pin name IRQ ADC ADC Serial Serial TC PWM PWM 44 PB12 D7 12 - - 4/0 - 4/0 3/0 0/0 21 PA21 D8 5 - - 5/3 3/3 7/1 1/5 0/1 20 PA20 D9 4 - - 5/2 3/2 7/0 1/4 0/0 - 3 PA03 AREF 3 10 - - - - - - + 3 PA03 AREF 3 10 - - - - - - 18 PA18 D10 2 - - 1/2 3/2 3/0 1/2 0/6 19 PA19 D11 3 - - 1/3 3/3 3/1 1/3 0/7 16 PA16 D13 0 - - 1/0 3/1 2/0 1/0 0/4 - 36 PB04 ESP_BUSY 4 - 6 - - - - - + 36 PB04 ESP_BUSY 4 - 6 - - - - - 15 PA15 ESP_CS 15 - - 2/3 4/3 3/1 2/1 1/3 - 33 PB01 ESP_GPIO0 1 13 - - 5/3 7/1 - - - 37 PB05 ESP_RESET 5 - 7 - - - - - - 55 PB23 ESP_RTS 7 - - 1/3 5/3 7/1 - - - 7 PA07 ESP_RX 7 7 - - 0/3 1/1 - - - 4 PA04 ESP_TX 4 4 - - 0/0 0/0 - - + 33 PB01 ESP_GPIO0 1 13 - - 5/3 7/1 - - + 37 PB05 ESP_RESET 5 - 7 - - - - - + 55 PB23 ESP_RTS 7 - - 1/3 5/3 7/1 - - + 7 PA07 ESP_RX 7 7 - - 0/3 1/1 - - + 4 PA04 ESP_TX 4 4 - - 0/0 0/0 - - 43 PB11 FLASH_CS 12 - - - 4/3 5/1 0/5 1/1 11 PA11 FLASH_HOLD 11 11 - 0/3 2/3 1/1 0/3 1/7 9 PA09 FLASH_MISO 9 9 3 0/1 2/0 0/1 0/1 1/5 @@ -383,21 +383,21 @@ Pin GPIO Pin name IRQ ADC ADC Serial Serial TC PWM PWM 10 PA10 FLASH_WP 10 10 - 0/2 2/2 1/0 0/2 1/6 14 PA14 MISO 14 - - 2/2 4/2 3/0 2/0 1/2 12 PA12 MOSI 12 - - 2/0 4/1 2/0 0/6 1/2 - 54 PB22 NEOPIXEL 22 - - 1/2 5/2 7/0 - - - 38 PB06 RXLED 6 - 8 - - - - - + 54 PB22 NEOPIXEL 22 - - 1/2 5/2 7/0 - - + 38 PB06 RXLED 6 - 8 - - - - - 13 PA13 SCK 13 - - 2/1 4/0 2/1 0/7 1/3 - 35 PB03 SCL 9 15 - - 5/1 6/1 - - - 34 PB02 SDA 2 14 - - 5/0 6/0 2/2 - - 30 PA30 SWCLK 14 - - 7/2 1/2 6/0 2/0 - - 31 PA31 SWDIO 15 - - 7/3 1/3 6/1 2/1 - + 35 PB03 SCL 9 15 - - 5/1 6/1 - - + 34 PB02 SDA 2 14 - - 5/0 6/0 2/2 - + 30 PA30 SWCLK 14 - - 7/2 1/2 6/0 2/0 - + 31 PA31 SWDIO 15 - - 7/3 1/3 6/1 2/1 - 62 PB30 SWO 14 - - 7/0 5/1 0/0 4/0 0/6 - 39 PB07 TXLED 7 - 9 - - - - - - 24 PA24 USB_DM 8 - - 3/2 5/2 5/0 2/2 - - 25 PA25 USB_DP 9 - - 3/3 5/3 5/1 - - + 39 PB07 TXLED 7 - 9 - - - - - + 24 PA24 USB_DM 8 - - 3/2 5/2 5/0 2/2 - + 25 PA25 USB_DP 9 - - 3/3 5/3 5/1 - - 17 PA17 USB_HOSTEN 1 - - 1/1 3/0 2/1 1/1 0/5 - 0 PA00 - 0 - - - 1/0 2/0 - - - 1 PA01 - 1 - - - 1/1 2/1 - - - 27 PA27 - 11 - - - - - - - + 0 PA00 - 0 - - - 1/0 2/0 - - + 1 PA01 - 1 - - - 1/1 2/1 - - + 27 PA27 - 11 - - - - - - - 63 PB31 - 15 - - 7/1 5/0 0/1 4/1 0/7 === ==== ============ ==== ==== ==== ====== ====== ===== ===== ===== diff --git a/extmod/axtls-include/config.h b/extmod/axtls-include/config.h index a0dd2b2b60f6d..4cb1aed9ca71c 100644 --- a/extmod/axtls-include/config.h +++ b/extmod/axtls-include/config.h @@ -46,7 +46,7 @@ #define CONFIG_SSL_X509_ORGANIZATION_UNIT_NAME "" #undef CONFIG_SSL_HAS_PEM #undef CONFIG_SSL_USE_PKCS12 -#define CONFIG_SSL_EXPIRY_TIME +#define CONFIG_SSL_EXPIRY_TIME #define CONFIG_X509_MAX_CA_CERTS 0 #define CONFIG_SSL_MAX_CERTS 3 #undef CONFIG_SSL_CTX_MUTEXING @@ -58,11 +58,11 @@ #undef CONFIG_AXTLSWRAP #undef CONFIG_AXHTTPD #undef CONFIG_HTTP_STATIC_BUILD -#define CONFIG_HTTP_PORT -#define CONFIG_HTTP_HTTPS_PORT -#define CONFIG_HTTP_SESSION_CACHE_SIZE +#define CONFIG_HTTP_PORT +#define CONFIG_HTTP_HTTPS_PORT +#define CONFIG_HTTP_SESSION_CACHE_SIZE #define CONFIG_HTTP_WEBROOT "" -#define CONFIG_HTTP_TIMEOUT +#define CONFIG_HTTP_TIMEOUT #undef CONFIG_HTTP_HAS_CGI #define CONFIG_HTTP_CGI_EXTENSIONS "" #undef CONFIG_HTTP_ENABLE_LUA @@ -107,8 +107,8 @@ #undef CONFIG_BIGINT_BARRETT #undef CONFIG_BIGINT_CRT #undef CONFIG_BIGINT_KARATSUBA -#define MUL_KARATSUBA_THRESH -#define SQU_KARATSUBA_THRESH +#define MUL_KARATSUBA_THRESH +#define SQU_KARATSUBA_THRESH #undef CONFIG_BIGINT_SLIDING_WINDOW #undef CONFIG_BIGINT_SQUARE #undef CONFIG_BIGINT_CHECK_ON diff --git a/logo/FONT-LICENSE.txt b/logo/FONT-LICENSE.txt index 69c49d84c83c2..b63d4875e7757 100644 --- a/logo/FONT-LICENSE.txt +++ b/logo/FONT-LICENSE.txt @@ -22,7 +22,7 @@ with others. The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The -fonts, including any derivative works, can be bundled, embedded, +fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The diff --git a/ports/cc3200/README.md b/ports/cc3200/README.md index 53cad3ba0ff15..093feba4e243e 100644 --- a/ports/cc3200/README.md +++ b/ports/cc3200/README.md @@ -61,7 +61,7 @@ below). Flashing process using TI Uniflash: -- Open CCS_Uniflash and connect to the board (by default on port 22). +- Open CCS_Uniflash and connect to the board (by default on port 22). - Format the serial flash (select 1MB size in case of the CC3200-LAUNCHXL, 2MB in case of the WiPy, leave the rest unchecked). - Mark the following files for erasing: `/cert/ca.pem`, `/cert/client.pem`, `/cert/private.key` and `/tmp/pac.bin`. - Add a new file with the name of /sys/mcuimg.bin, and select the URL to point to cc3200\bootmgr\build\\bootloader.bin. @@ -94,7 +94,7 @@ Once the software is running, you have two options to access the MicroPython REP in boot.py, so you can override it at runtime regardless of MICROPY_STDIO_UART setting). -The board has a small file system of 192K (WiPy) or 64K (Launchpad) located in the serial flash connected to the CC3200. +The board has a small file system of 192K (WiPy) or 64K (Launchpad) located in the serial flash connected to the CC3200. SD cards are also supported, you can connect any SD card and configure the pinout using the SD class API. ## Uploading scripts: @@ -142,7 +142,7 @@ there. Make sure to use a **v4.1 (or higher) LAUNCHXL board** when trying this p ### Note regarding FileZilla -Do not use the quick connect button, instead, open the site manager and create a new configuration. In the "General" tab make -sure that encryption is set to: "Only use plain FTP (insecure)". In the Transfer Settings tab limit the max number of connections -to one, otherwise FileZilla will try to open a second command connection when retrieving and saving files, and for simplicity and +Do not use the quick connect button, instead, open the site manager and create a new configuration. In the "General" tab make +sure that encryption is set to: "Only use plain FTP (insecure)". In the Transfer Settings tab limit the max number of connections +to one, otherwise FileZilla will try to open a second command connection when retrieving and saving files, and for simplicity and to reduce code size, only one command and one data connections are possible. diff --git a/ports/cc3200/application.lds b/ports/cc3200/application.lds index 2d7dd04621306..b1ca73350eb29 100644 --- a/ports/cc3200/application.lds +++ b/ports/cc3200/application.lds @@ -36,7 +36,7 @@ MEMORY ENTRY(ResetISR) SECTIONS -{ +{ /* place the FreeRTOS heap (the MicroPython stack will live here) */ .rtos_heap (NOLOAD) : { @@ -92,7 +92,7 @@ SECTIONS . = ALIGN(8); _eboot = .; } > SRAM - + /* allocate the MicroPython heap */ .heap : { diff --git a/ports/cc3200/bootmgr/bootgen.sh b/ports/cc3200/bootmgr/bootgen.sh index f4bf32540c066..a802afef6e7c9 100644 --- a/ports/cc3200/bootmgr/bootgen.sh +++ b/ports/cc3200/bootmgr/bootgen.sh @@ -37,7 +37,7 @@ echo "Generating bootloader..." # Generate an all 0 bin file dd if=/dev/zero of=__tmp.bin ibs=1 count=256 conv=notrunc >/dev/null 2>&1 -# Generate a 0 padded version of the relocator +# Generate a 0 padded version of the relocator dd if=$RELOCATOR/relocator.bin of=__tmp.bin ibs=1 conv=notrunc >/dev/null 2>&1 # Concatenate the re-locator and the boot-manager diff --git a/ports/cc3200/bootmgr/bootloader.mk b/ports/cc3200/bootmgr/bootloader.mk index 3aeda062ce422..39a960ef4fb0a 100644 --- a/ports/cc3200/bootmgr/bootloader.mk +++ b/ports/cc3200/bootmgr/bootloader.mk @@ -53,7 +53,7 @@ BOOT_SL_SRC_C = $(addprefix simplelink/,\ BOOT_UTIL_SRC_C = $(addprefix util/,\ cryptohash.c \ - ) + ) BOOT_MAIN_SRC_C = \ bootmgr/main.c @@ -114,7 +114,7 @@ $(BUILD)/bootmgr.axf: $(OBJ) $(LINKER_SCRIPT) $(ECHO) "LINK $@" $(Q)$(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBS) $(Q)$(SIZE) $@ - + $(BUILD)/bootmgr.bin: $(BUILD)/bootmgr.axf $(ECHO) "Create $@" $(Q)$(OBJCOPY) -O binary $< $@ diff --git a/ports/cc3200/bootmgr/flc.h b/ports/cc3200/bootmgr/flc.h index 8f05bb320e726..2a319a42fd207 100644 --- a/ports/cc3200/bootmgr/flc.h +++ b/ports/cc3200/bootmgr/flc.h @@ -30,7 +30,7 @@ If building with a C++ compiler, make all of the definitions in this header have a C binding. - + *******************************************************************************/ #ifdef __cplusplus extern "C" @@ -84,9 +84,9 @@ typedef struct _sBootInfo_t /****************************************************************************** - + Mark the end of the C bindings section for C++ compilers. - + *******************************************************************************/ #ifdef __cplusplus } diff --git a/ports/cc3200/bootmgr/sl/user.h b/ports/cc3200/bootmgr/sl/user.h index be93029d1c0a5..6753188ee2dc3 100644 --- a/ports/cc3200/bootmgr/sl/user.h +++ b/ports/cc3200/bootmgr/sl/user.h @@ -1,40 +1,40 @@ /* * user.h - CC31xx/CC32xx Host Driver Implementation * - * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions * are met: * - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the * distribution. * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ - + #ifndef __USER_H__ #define __USER_H__ @@ -63,8 +63,8 @@ extern "C" { ****************************************************************************** */ - -#include + +#include #include "cc_pal.h" /*! @@ -90,8 +90,8 @@ extern "C" { /*! \def CPU_FREQ_IN_MHZ \brief Defines CPU frequency for Host side, for better accuracy of busy loops, if any - \sa - \note + \sa + \note \warning If not set the default CPU frequency is set to 200MHz This option will be deprecated in future release @@ -330,7 +330,7 @@ extern "C" { The enable/disable API provide mechanism to enable/disable the network processor - + PORTING ACTION: - None @{ @@ -568,9 +568,9 @@ extern "C" { */ #define sl_IfUnMaskIntHdlr() NwpUnMaskInterrupt() - + /*! - \brief Write Handers for statistics debug on write + \brief Write Handers for statistics debug on write \param interface handler - pointer to interrupt handler routine @@ -583,7 +583,7 @@ extern "C" { \note belongs to \ref ported_sec - \warning + \warning */ /* #define SL_START_WRITE_STAT */ @@ -921,7 +921,7 @@ typedef OsiLockObj_t _SlLockObj_t; \brief \sa \note belongs to \ref ported_sec - \warning + \warning */ #define sl_Malloc(Size) malloc(Size) @@ -929,7 +929,7 @@ typedef OsiLockObj_t _SlLockObj_t; \brief \sa \note belongs to \ref ported_sec - \warning + \warning */ #define sl_Free(pMem) free(pMem) #endif @@ -973,9 +973,9 @@ typedef OsiLockObj_t _SlLockObj_t; /*! \brief An event handler for WLAN connection or disconnection indication - This event handles async WLAN events. + This event handles async WLAN events. Possible events are: - SL_WLAN_CONNECT_EVENT - indicates WLAN is connected + SL_WLAN_CONNECT_EVENT - indicates WLAN is connected SL_WLAN_DISCONNECT_EVENT - indicates WLAN is disconnected \sa diff --git a/ports/cc3200/fatfs/src/drivers/stdcmd.h b/ports/cc3200/fatfs/src/drivers/stdcmd.h index 464e2ddfaaec8..a3e617b70adac 100644 --- a/ports/cc3200/fatfs/src/drivers/stdcmd.h +++ b/ports/cc3200/fatfs/src/drivers/stdcmd.h @@ -1,37 +1,37 @@ //***************************************************************************** // stdcmd.h // -// Defines standard SD Card commands for CC3200 SDHOST module. +// Defines standard SD Card commands for CC3200 SDHOST module. // -// Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ -// -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions +// Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ +// +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions // are met: // -// Redistributions of source code must retain the above copyright +// Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the // distribution. // // Neither the name of Texas Instruments Incorporated nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // //***************************************************************************** @@ -40,7 +40,7 @@ #define __STDCMD_H__ //***************************************************************************** -// Standard MMC/SD Card Commands +// Standard MMC/SD Card Commands //***************************************************************************** #define CMD_GO_IDLE_STATE SDHOST_CMD_0 #define CMD_SEND_IF_COND SDHOST_CMD_8|SDHOST_RESP_LEN_48 diff --git a/ports/cc3200/hal/cc3200_hal.c b/ports/cc3200/hal/cc3200_hal.c index 8bfd2fda1c8ae..e149968a51d76 100644 --- a/ports/cc3200/hal/cc3200_hal.c +++ b/ports/cc3200/hal/cc3200_hal.c @@ -96,7 +96,7 @@ void HAL_SystemInit (void) { void HAL_SystemDeInit (void) { } - + void HAL_IncrementTick(void) { HAL_tickCount++; } diff --git a/ports/cc3200/hal/gpio.c b/ports/cc3200/hal/gpio.c index 59aa71aa57008..84af18e0fac3a 100644 --- a/ports/cc3200/hal/gpio.c +++ b/ports/cc3200/hal/gpio.c @@ -74,7 +74,7 @@ GPIOBaseValid(unsigned long ulPort) return((ulPort == GPIOA0_BASE) || (ulPort == GPIOA1_BASE) || (ulPort == GPIOA2_BASE) || - (ulPort == GPIOA3_BASE) || + (ulPort == GPIOA3_BASE) || (ulPort == GPIOA4_BASE)); } #else diff --git a/ports/cc3200/hal/inc/hw_memmap.h b/ports/cc3200/hal/inc/hw_memmap.h index 244905dd20ac3..b20a271287908 100644 --- a/ports/cc3200/hal/inc/hw_memmap.h +++ b/ports/cc3200/hal/inc/hw_memmap.h @@ -49,7 +49,7 @@ #define GPIOA1_BASE 0x40005000 #define GPIOA2_BASE 0x40006000 #define GPIOA3_BASE 0x40007000 -#define GPIOA4_BASE 0x40024000 +#define GPIOA4_BASE 0x40024000 #define UARTA0_BASE 0x4000C000 #define UARTA1_BASE 0x4000D000 #define I2CA0_BASE 0x40020000 diff --git a/ports/cc3200/hal/pin.h b/ports/cc3200/hal/pin.h index 784e9f46354b0..61b6446772f7f 100644 --- a/ports/cc3200/hal/pin.h +++ b/ports/cc3200/hal/pin.h @@ -116,8 +116,8 @@ extern "C" #define PIN_MODE_14 0x0000000E #define PIN_MODE_15 0x0000000F // Note : PIN_MODE_255 is a dummy define for pinmux utility code generation -// PIN_MODE_255 should never be used in any user code. -#define PIN_MODE_255 0x000000FF +// PIN_MODE_255 should never be used in any user code. +#define PIN_MODE_255 0x000000FF //***************************************************************************** // Macros that can be used with PinDirModeSet() and returned from diff --git a/ports/cc3200/hal/prcm.h b/ports/cc3200/hal/prcm.h index 2f700ae2c647f..d16538e4aff14 100644 --- a/ports/cc3200/hal/prcm.h +++ b/ports/cc3200/hal/prcm.h @@ -189,8 +189,8 @@ unsigned char ulRstReg; #define PRCM_SSPI 0x00000013 #define PRCM_I2CA0 0x00000014 // Note : PRCM_ADC is a dummy define for pinmux utility code generation -// PRCM_ADC should never be used in any user code. -#define PRCM_ADC 0x000000FF +// PRCM_ADC should never be used in any user code. +#define PRCM_ADC 0x000000FF //***************************************************************************** // User bits in the PRCM persistent registers diff --git a/ports/cc3200/hal/spi.c b/ports/cc3200/hal/spi.c index 8c8c6782897e4..3a6371fd82e02 100644 --- a/ports/cc3200/hal/spi.c +++ b/ports/cc3200/hal/spi.c @@ -762,7 +762,7 @@ SPIConfigSetExpClk(unsigned long ulBase,unsigned long ulSPIClk, // Enable software control Chip Select, Init delay // and 3-pin mode // - ulRegData |= (((ulConfig >> 24) | ulMode) & 0xFF); + ulRegData |= (((ulConfig >> 24) | ulMode) & 0xFF); // // Write the configuration diff --git a/ports/cc3200/simplelink/oslib/osi.h b/ports/cc3200/simplelink/oslib/osi.h index 11fe61bb63ac9..4ab811fc8ad7a 100644 --- a/ports/cc3200/simplelink/oslib/osi.h +++ b/ports/cc3200/simplelink/oslib/osi.h @@ -3,35 +3,35 @@ // // MACRO and Function prototypes for TI-RTOS and Free-RTOS API calls // -// Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ -// -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions +// Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ +// +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions // are met: // -// Redistributions of source code must retain the above copyright +// Redistributions of source code must retain the above copyright // notice, this list zof conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the // distribution. // // Neither the name of Texas Instruments Incorporated nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // //***************************************************************************** @@ -367,23 +367,23 @@ OsiReturnVal_e osi_Spawn(P_OSI_SPAWN_ENTRY pEntry , void* pValue , unsigned long /******************************************************************************* This function creates a message queue that is typically used for inter thread -communication. +communication. Parameters: pMsgQ - pointer to the message queue control block pMsgQName - pointer to the name of the message queue - MsgSize - the size of the message. + MsgSize - the size of the message. NOTICE: THE MESSGAE SIZE MUST BE SMALLER THAN 16 MaxMsgs - maximum number of messages. -Please note that this function allocates the entire memory required -for the maximum number of messages (MsgSize * MaxMsgs). +Please note that this function allocates the entire memory required +for the maximum number of messages (MsgSize * MaxMsgs). ********************************************************************************/ -OsiReturnVal_e osi_MsgQCreate(OsiMsgQ_t* pMsgQ , +OsiReturnVal_e osi_MsgQCreate(OsiMsgQ_t* pMsgQ , char* pMsgQName, unsigned long MsgSize, unsigned long MaxMsgs); @@ -392,7 +392,7 @@ OsiReturnVal_e osi_MsgQCreate(OsiMsgQ_t* pMsgQ , This function deletes a specific message queue. All threads suspended waiting for a message from this queue are resumed with -an error return value. +an error return value. Parameters: @@ -406,11 +406,11 @@ OsiReturnVal_e osi_MsgQDelete(OsiMsgQ_t* pMsgQ); This function writes a message to a specific message queue. -Notice that the message is copied to the queue from the memory area specified +Notice that the message is copied to the queue from the memory area specified by pMsg pointer. -------------------------------------------------------------------------------- -THIS FUNCTION COULD BE CALLED FROM ISR AS LONG AS THE TIMEOUT PARAMETER IS +THIS FUNCTION COULD BE CALLED FROM ISR AS LONG AS THE TIMEOUT PARAMETER IS SET TO "OSI_NO_WAIT" -------------------------------------------------------------------------------- @@ -418,7 +418,7 @@ SET TO "OSI_NO_WAIT" pMsgQ - pointer to the message queue control block pMsg - pointer to the message - Timeout - numeric value specifies the maximum number of mSec to stay + Timeout - numeric value specifies the maximum number of mSec to stay suspended while waiting for available space for the message ********************************************************************************/ @@ -428,14 +428,14 @@ OsiReturnVal_e osi_MsgQWrite(OsiMsgQ_t* pMsgQ, void* pMsg , OsiTime_t Timeout); /******************************************************************************* This function retrieves a message from the specified message queue. The -retrieved message is copied from the queue into the memory area specified by -the pMsg pointer +retrieved message is copied from the queue into the memory area specified by +the pMsg pointer Parameters: pMsgQ - pointer to the message queue control block pMsg - pointer that specify the location where to copy the message - Timeout - numeric value specifies the maximum number of mSec to stay + Timeout - numeric value specifies the maximum number of mSec to stay suspended while waiting for a message to be available ********************************************************************************/ @@ -478,7 +478,7 @@ void mem_Free(void *pMem); \param Size - Size of the memory to be set \sa \note - \warning + \warning */ void mem_set(void *pBuf,int Val,size_t Size); @@ -489,7 +489,7 @@ void mem_set(void *pBuf,int Val,size_t Size); \param Size - Size of the memory to be copied \return void \note - \warning + \warning */ void mem_copy(void *pDst, void *pSrc,size_t Size); @@ -497,7 +497,7 @@ void mem_copy(void *pDst, void *pSrc,size_t Size); \brief Enter Critical Section \sa \note - \warning + \warning */ void osi_EnterCritical(void); @@ -505,7 +505,7 @@ void osi_EnterCritical(void); \brief Exit Critical Section \sa \note - \warning + \warning */ void osi_ExitCritical(void); @@ -563,7 +563,7 @@ typedef struct P_OSI_SPAWN_ENTRY pEntry; void* pValue; }tSimpleLinkSpawnMsg; - + /* The queue used to send message to simple link spawn task. */ extern void* xSimpleLinkSpawnQueue; diff --git a/ports/cc3200/simplelink/oslib/osi_freertos.c b/ports/cc3200/simplelink/oslib/osi_freertos.c index 53822add73d52..dcc7a2a7c7fbd 100644 --- a/ports/cc3200/simplelink/oslib/osi_freertos.c +++ b/ports/cc3200/simplelink/oslib/osi_freertos.c @@ -3,35 +3,35 @@ // // Interface APIs for free-rtos function calls // -// Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ -// -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions +// Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ +// +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions // are met: // -// Redistributions of source code must retain the above copyright +// Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the // distribution. // // Neither the name of Texas Instruments Incorporated nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // //***************************************************************************** @@ -57,7 +57,7 @@ static void vSimpleLinkSpawnTask( void *pvParameters ); //Queue Handler QueueHandle_t xSimpleLinkSpawnQueue = NULL; TaskHandle_t xSimpleLinkSpawnTaskHndl = NULL; -// Queue size +// Queue size #define slQUEUE_SIZE ( 3 ) #define SL_SPAWN_MAX_WAIT_MS ( 200 ) @@ -282,7 +282,7 @@ OsiReturnVal_e osi_TaskCreate(P_OSI_TASK_ENTRY pEntry,const signed char * const unsigned long uxPriority,OsiTaskHandle* pTaskHandle) { ASSERT (pdPASS == xTaskCreate( pEntry, (char const*)pcName, - (usStackDepth/(sizeof( portSTACK_TYPE ))), + (usStackDepth/(sizeof( portSTACK_TYPE ))), pvParameters,(unsigned portBASE_TYPE)uxPriority, (TaskHandle_t*)pTaskHandle )); return OSI_OK; @@ -417,7 +417,7 @@ OsiReturnVal_e osi_Spawn(P_OSI_SPAWN_ENTRY pEntry , void* pValue , unsigned long /*! - \brief This is the simplelink spawn task to call SL callback from a different context + \brief This is the simplelink spawn task to call SL callback from a different context \param pvParameters - pointer to the task parameter @@ -510,7 +510,7 @@ void VDeleteSimpleLinkSpawnTask( void ) \note \warning */ -OsiReturnVal_e osi_MsgQCreate(OsiMsgQ_t* pMsgQ , +OsiReturnVal_e osi_MsgQCreate(OsiMsgQ_t* pMsgQ , char* pMsgQName, unsigned long MsgSize, unsigned long MaxMsgs) @@ -607,8 +607,8 @@ void * mem_Malloc(unsigned long Size) \brief This function to call the memory de-allocation function of the FREERTOS \param pMem - pointer to the memory which needs to be freed - - \return - void + + \return - void \note \warning */ @@ -622,7 +622,7 @@ void mem_Free(void *pMem) \param pBuf - pointer to the memory to be fill \param Val - Value to be fill \param Size - Size of the memory which needs to be fill - \return - void + \return - void \note \warning */ @@ -637,8 +637,8 @@ void mem_set(void *pBuf,int Val,size_t Size) \param pDst - pointer to the destination \param pSrc - pointer to the source \param Size - Size of the memory which needs to be copy - - \return - void + + \return - void \note \warning */ @@ -650,8 +650,8 @@ void mem_copy(void *pDst, void *pSrc,size_t Size) /*! \brief This function use to entering into critical section - \param void - \return - void + \param void + \return - void \note \warning */ @@ -663,8 +663,8 @@ void osi_EnterCritical(void) /*! \brief This function use to exit critical section - \param void - \return - void + \param void + \return - void \note \warning */ diff --git a/ports/cc3200/simplelink/user.h b/ports/cc3200/simplelink/user.h index d3f6d4adfb6fd..3ab0b09a7780b 100644 --- a/ports/cc3200/simplelink/user.h +++ b/ports/cc3200/simplelink/user.h @@ -1,40 +1,40 @@ /* * user.h - CC31xx/CC32xx Host Driver Implementation * - * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions * are met: * - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the * distribution. * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ - + #ifndef __USER_H__ #define __USER_H__ @@ -63,8 +63,8 @@ extern "C" { ****************************************************************************** */ - -#include + +#include #include "cc_pal.h" #include "debug.h" @@ -91,8 +91,8 @@ extern "C" { /*! \def CPU_FREQ_IN_MHZ \brief Defines CPU frequency for Host side, for better accuracy of busy loops, if any - \sa - \note + \sa + \note \warning If not set the default CPU frequency is set to 200MHz This option will be deprecated in future release @@ -331,7 +331,7 @@ extern "C" { The enable/disable API provide mechanism to enable/disable the network processor - + PORTING ACTION: - None @{ @@ -569,9 +569,9 @@ extern "C" { */ #define sl_IfUnMaskIntHdlr() NwpUnMaskInterrupt() - + /*! - \brief Write Handers for statistics debug on write + \brief Write Handers for statistics debug on write \param interface handler - pointer to interrupt handler routine @@ -584,7 +584,7 @@ extern "C" { \note belongs to \ref ported_sec - \warning + \warning */ /* #define SL_START_WRITE_STAT */ @@ -921,7 +921,7 @@ typedef OsiLockObj_t _SlLockObj_t; \brief \sa \note belongs to \ref ported_sec - \warning + \warning */ #define sl_Malloc(Size) malloc(Size) @@ -929,7 +929,7 @@ typedef OsiLockObj_t _SlLockObj_t; \brief \sa \note belongs to \ref ported_sec - \warning + \warning */ #define sl_Free(pMem) free(pMem) #endif @@ -973,9 +973,9 @@ typedef OsiLockObj_t _SlLockObj_t; /*! \brief An event handler for WLAN connection or disconnection indication - This event handles async WLAN events. + This event handles async WLAN events. Possible events are: - SL_WLAN_CONNECT_EVENT - indicates WLAN is connected + SL_WLAN_CONNECT_EVENT - indicates WLAN is connected SL_WLAN_DISCONNECT_EVENT - indicates WLAN is disconnected \sa diff --git a/ports/embed/embed.mk b/ports/embed/embed.mk index 84d45accd2d71..bea5e5d65bbab 100644 --- a/ports/embed/embed.mk +++ b/ports/embed/embed.mk @@ -1,7 +1,7 @@ # This file is part of the MicroPython project, http://micropython.org/ # The MIT License (MIT) # Copyright (c) 2022-2023 Damien P. George -# +# # This file is intended to be included by a Makefile in a custom project. # Set the build output directory for the generated files. diff --git a/ports/esp32/README.ulp.md b/ports/esp32/README.ulp.md index cbc5771a9042f..ada19ec193188 100644 --- a/ports/esp32/README.ulp.md +++ b/ports/esp32/README.ulp.md @@ -13,7 +13,7 @@ ULP_LD_SCRIPT := esp32.ulp.ld SRC_PATH := src BUILD_PATH := build -include $(ESPIDF)/components/ulp/Makefile.projbuild +include $(ESPIDF)/components/ulp/Makefile.projbuild ULP_ELF := $(ULP_APP_NAME).elf ULP_MAP := $(ULP_ELF:.elf=.map) @@ -29,7 +29,7 @@ ULP_LISTINGS := $(notdir $(ULP_S_SOURCES:.S=.ulp.lst)) .PHONY: all clean -all: $(BUILD_PATH) $(BUILD_PATH)/$(ULP_BIN) +all: $(BUILD_PATH) $(BUILD_PATH)/$(ULP_BIN) clean: rm -rf $(BUILD_PATH) @@ -42,7 +42,7 @@ $(BUILD_PATH)/$(ULP_APP_NAME).ld: $(SRC_PATH)/$(ULP_LD_SCRIPT) cpp -P $< -o $@ # Generate preprocessed assembly files. -# To inspect these preprocessed files, add a ".PRECIOUS: %.ulp.pS" rule. +# To inspect these preprocessed files, add a ".PRECIOUS: %.ulp.pS" rule. $(BUILD_PATH)/%.ulp.pS: $(SRC_PATH)/%.S cpp $< -o $@ @@ -58,7 +58,7 @@ $(BUILD_PATH)/$(ULP_ELF): $(BUILD_PATH)/$(ULP_OBJECTS) $(BUILD_PATH)/$(ULP_APP_N $(ULP_SYM): $(ULP_ELF) $(ULP_NM) -g -f posix $< > $@ -# Dump the binary for inclusion into the project +# Dump the binary for inclusion into the project $(BUILD_PATH)/$(ULP_BIN): $(BUILD_PATH)/$(ULP_ELF) $(ULP_OBJCOPY) -O binary $< $@ ``` @@ -90,11 +90,11 @@ SECTIONS . = ALIGN(4); *(.bss) } >ram - + .header : AT(0) { LONG(ULP_BIN_MAGIC) - SHORT(LOADADDR(.text)) + SHORT(LOADADDR(.text)) SHORT(SIZEOF(.text)) SHORT(SIZEOF(.data)) SHORT(SIZEOF(.bss)) diff --git a/ports/mimxrt/boards/OLIMEX_RT1010/deploy_olimex.md b/ports/mimxrt/boards/OLIMEX_RT1010/deploy_olimex.md index 1238ded848c0a..92f3df57c9b84 100644 --- a/ports/mimxrt/boards/OLIMEX_RT1010/deploy_olimex.md +++ b/ports/mimxrt/boards/OLIMEX_RT1010/deploy_olimex.md @@ -17,11 +17,11 @@ Now you have all files at hand that you will need for updating. 2. Push and hold the "Boot" button, then press "Reset", and release both buttons. -3. Run the commands: +3. Run the commands: ``` -sudo ./sdphost -u 0x1fc9,0x0145 -- write-file 0x20206400 tinyuf2-imxrt1010_evk-0.9.0.bin -sudo ./sdphost -u 0x1fc9,0x0145 -- jump-address 0x20207000 +sudo ./sdphost -u 0x1fc9,0x0145 -- write-file 0x20206400 tinyuf2-imxrt1010_evk-0.9.0.bin +sudo ./sdphost -u 0x1fc9,0x0145 -- jump-address 0x20207000 ``` Wait until a drive icon appears on the computer (or mount it explicitly), and then run: ``` @@ -32,7 +32,7 @@ You can put all of that in a script. Just add a short wait before the 3rd comman 4. Once the upload is finished, push Reset again. Using sudo is Linux specific. You may not need it at all, if the access rights are set properly, -and you will not need it for Windows. +and you will not need it for Windows. Once the generic boot-loader is available, this procedure is only required for the first firmware load or in case the flash is corrupted and the existing firmware is not functioning diff --git a/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.mk b/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.mk index 2cf7d33c6331d..63e68e1e57994 100644 --- a/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.mk +++ b/ports/mimxrt/boards/SEEED_ARCH_MIX/mpconfigboard.mk @@ -4,7 +4,7 @@ MCU_VARIANT = MIMXRT1052DVL6B MICROPY_FLOAT_IMPL = double MICROPY_HW_FLASH_TYPE = qspi_nor_flash MICROPY_HW_FLASH_SIZE = 0x800000 # 8MB - + MICROPY_HW_SDRAM_AVAIL = 1 MICROPY_HW_SDRAM_SIZE = 0x2000000 # 32MB diff --git a/ports/mimxrt/boards/common.ld b/ports/mimxrt/boards/common.ld index 6c78fea319f96..587fc82a1953d 100644 --- a/ports/mimxrt/boards/common.ld +++ b/ports/mimxrt/boards/common.ld @@ -1,7 +1,7 @@ /* ** ################################################################### ** Linker script inspired by NXP linker script for MIMXRT10xx -** +** ** Copyright for original linker script: ** Copyright 2016 Freescale Semiconductor, Inc. ** Copyright 2016-2018 NXP @@ -26,7 +26,7 @@ HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 0x0400; STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x0400; /* Reserved Area - * Users can create a reserved area at the end of the flash memory via + * Users can create a reserved area at the end of the flash memory via * 'reserved_size' variable. The size of the reserved area should be a multiple * of the sector size of the flash memory! */ @@ -41,7 +41,7 @@ MEMORY m_text (RX) : ORIGIN = text_start, LENGTH = text_size m_vfs (RX) : ORIGIN = vfs_start, LENGTH = vfs_size /* Teensy uses the last bit of flash for recovery. */ - m_reserved (RX) : ORIGIN = (vfs_start + vfs_size), LENGTH = reserved_size + m_reserved (RX) : ORIGIN = (vfs_start + vfs_size), LENGTH = reserved_size m_itcm (RX) : ORIGIN = itcm_start, LENGTH = itcm_size m_dtcm (RW) : ORIGIN = dtcm_start, LENGTH = dtcm_size m_ocrm (RW) : ORIGIN = ocrm_start, LENGTH = ocrm_size @@ -59,8 +59,8 @@ SECTIONS __sdram_start = sdram_start; #endif __vfs_start = ORIGIN(m_vfs); - __vfs_end = __vfs_start + LENGTH(m_vfs); - + __vfs_end = __vfs_start + LENGTH(m_vfs); + .flash_config : { . = ALIGN(4); @@ -177,7 +177,7 @@ SECTIONS KEEP (*(.fini_array*)) PROVIDE_HIDDEN (__fini_array_end = .); } > m_text - + __etext = .; /* define a global symbol at end of code */ __DATA_ROM = .; /* Symbol is used by startup for data initialization */ @@ -206,7 +206,7 @@ SECTIONS *(.text*) . = ALIGN(4); __ram_function_end__ = .; - } > m_itcm + } > m_itcm __NDATA_ROM = __RAM_FUNCTIONS_ROM + (__ram_function_end__ - __ram_function_start__); .ncache.init : AT(__NDATA_ROM) diff --git a/ports/nrf/boards/ACTINIUS_ICARUS/mpconfigboard.mk b/ports/nrf/boards/ACTINIUS_ICARUS/mpconfigboard.mk index 8e6f75b36ce42..cc7e7c3683da6 100644 --- a/ports/nrf/boards/ACTINIUS_ICARUS/mpconfigboard.mk +++ b/ports/nrf/boards/ACTINIUS_ICARUS/mpconfigboard.mk @@ -3,6 +3,6 @@ MCU_VARIANT = nrf91 MCU_SUB_VARIANT = nrf9160 LD_FILES += boards/nrf9160_1M_256k.ld -NRF_DEFINES += -DNRF9160_XXAA -DNRF_TRUSTZONE_NONSECURE +NRF_DEFINES += -DNRF9160_XXAA -DNRF_TRUSTZONE_NONSECURE MICROPY_VFS_LFS2 = 1 diff --git a/ports/nrf/boards/NRF52840_MDK_USB_DONGLE/README.md b/ports/nrf/boards/NRF52840_MDK_USB_DONGLE/README.md index f993c7dc53623..ecf9259042e6a 100644 --- a/ports/nrf/boards/NRF52840_MDK_USB_DONGLE/README.md +++ b/ports/nrf/boards/NRF52840_MDK_USB_DONGLE/README.md @@ -45,4 +45,4 @@ built, the target can be deployed to the device as described in An alternative way to deploy to the device, is to open `firmware.hex` using *nRF Connect* and select *Write*. Detailed instructions can be found on the [developer -wiki](https://wiki.makerdiary.com/nrf52840-mdk-usb-dongle/programming/). +wiki](https://wiki.makerdiary.com/nrf52840-mdk-usb-dongle/programming/). diff --git a/ports/nrf/drivers/bluetooth/download_ble_stack.sh b/ports/nrf/drivers/bluetooth/download_ble_stack.sh index 6498278f496c7..7886682b718e0 100755 --- a/ports/nrf/drivers/bluetooth/download_ble_stack.sh +++ b/ports/nrf/drivers/bluetooth/download_ble_stack.sh @@ -78,13 +78,13 @@ function download_s140_nrf52_7_3_0 SCRIPT_DIR="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -if [ $# -eq 0 ]; then +if [ $# -eq 0 ]; then echo "No Bluetooth LE stack defined, downloading all." download_s110_nrf51_8_0_0 ${SCRIPT_DIR} download_s132_nrf52_6_1_1 ${SCRIPT_DIR} download_s140_nrf52_6_1_1 ${SCRIPT_DIR} download_s140_nrf52_7_3_0 ${SCRIPT_DIR} -else +else case $1 in "s110_nrf51" ) download_s110_nrf51_8_0_0 ${SCRIPT_DIR} ;; diff --git a/ports/renesas-ra/Makefile b/ports/renesas-ra/Makefile index f8b46fe453902..b4b9733182bc0 100644 --- a/ports/renesas-ra/Makefile +++ b/ports/renesas-ra/Makefile @@ -93,12 +93,12 @@ CFLAGS_CORTEX_M = -mthumb SUPPORTS_HARDWARE_FP_SINGLE = 0 SUPPORTS_HARDWARE_FP_DOUBLE = 0 ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),m4)) -CFLAGS_CORTEX_M += -mfpu=fpv4-sp-d16 -mfloat-abi=hard +CFLAGS_CORTEX_M += -mfpu=fpv4-sp-d16 -mfloat-abi=hard SUPPORTS_HARDWARE_FP_SINGLE = 1 endif ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),m33)) -CFLAGS_CORTEX_M += -mfpu=fpv5-sp-d16 -mfloat-abi=hard +CFLAGS_CORTEX_M += -mfpu=fpv5-sp-d16 -mfloat-abi=hard SUPPORTS_HARDWARE_FP_SINGLE = 1 endif diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt index 3a46fdaa7f47b..392fed29b1ff4 100644 --- a/ports/rp2/CMakeLists.txt +++ b/ports/rp2/CMakeLists.txt @@ -41,7 +41,7 @@ endif() set(MICROPY_USER_FROZEN_MANIFEST ${MICROPY_FROZEN_MANIFEST}) # Include board config, it may override MICROPY_FROZEN_MANIFEST -include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake) +include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake) # Set the PICO_BOARD if it's not already set (allow a board to override it). if(NOT PICO_BOARD) diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile index 2947e4119beac..19f6f420e1fff 100644 --- a/ports/stm32/Makefile +++ b/ports/stm32/Makefile @@ -282,7 +282,7 @@ SRC_C += \ SRC_O += \ $(STARTUP_FILE) \ $(SYSTEM_FILE) - + ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f0 g0 l0)) CSUPEROPT = -Os # save some code space SRC_O += \ diff --git a/ports/stm32/boards/stm32h7b3.ld b/ports/stm32/boards/stm32h7b3.ld index cccea983fa89e..83a261029fb8b 100644 --- a/ports/stm32/boards/stm32h7b3.ld +++ b/ports/stm32/boards/stm32h7b3.ld @@ -10,7 +10,7 @@ MEMORY FLASH_FS (r) : ORIGIN = 0x08020000, LENGTH = 128K /* sector 1, 128K */ FLASH_TEXT (rx) : ORIGIN = 0x08040000, LENGTH = 1792K /* sectors 6*128 + 8*128 */ DTCM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K /* Used for storage cache */ - RAM (xrw) : ORIGIN = 0x24000000, LENGTH = 512K /* AXI SRAM */ + RAM (xrw) : ORIGIN = 0x24000000, LENGTH = 512K /* AXI SRAM */ RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 288K } diff --git a/ports/stm32/usbdev/class/inc/usbd_cdc_msc_hid.h b/ports/stm32/usbdev/class/inc/usbd_cdc_msc_hid.h index d6c38bbd07e34..2c90ce165e2a7 100644 --- a/ports/stm32/usbdev/class/inc/usbd_cdc_msc_hid.h +++ b/ports/stm32/usbdev/class/inc/usbd_cdc_msc_hid.h @@ -68,22 +68,22 @@ typedef struct _USBD_STORAGE { } USBD_StorageTypeDef; typedef struct { - uint32_t max_lun; - uint32_t interface; + uint32_t max_lun; + uint32_t interface; uint8_t bot_state; - uint8_t bot_status; + uint8_t bot_status; uint16_t bot_data_length; - uint8_t bot_data[MSC_MEDIA_PACKET]; + uint8_t bot_data[MSC_MEDIA_PACKET]; USBD_MSC_BOT_CBWTypeDef cbw; USBD_MSC_BOT_CSWTypeDef csw; - + USBD_SCSI_SenseTypeDef scsi_sense [SENSE_LIST_DEEPTH]; uint8_t scsi_sense_head; uint8_t scsi_sense_tail; - + uint16_t scsi_blk_size[USBD_MSC_MAX_LUN]; uint32_t scsi_blk_nbr[USBD_MSC_MAX_LUN]; - + uint32_t scsi_blk_addr_in_blks; uint32_t scsi_blk_len; diff --git a/tests/README.md b/tests/README.md index 3bc626bf9e416..54dd078053ef0 100644 --- a/tests/README.md +++ b/tests/README.md @@ -177,7 +177,7 @@ internal_bench/bytebuf: ## Test key/certificates -SSL/TLS tests in `multi_net` and `net_inet` use a +SSL/TLS tests in `multi_net` and `net_inet` use a self-signed key/cert pair that is randomly generated and to be used for testing/demonstration only. You should always generate your own key/cert. diff --git a/tests/basics/generator_throw.py b/tests/basics/generator_throw.py index 1b43c125eabc1..067ab2b8eb2a1 100644 --- a/tests/basics/generator_throw.py +++ b/tests/basics/generator_throw.py @@ -2,7 +2,7 @@ def gen(): yield 123 yield 456 - + g = gen() print(next(g)) try: @@ -31,7 +31,7 @@ def gen(): except GeneratorExit as e: print('GeneratorExit', repr(e.args)) yield 456 - + # thrown a class g = gen() print(next(g)) diff --git a/tests/basics/int_big_and2.py b/tests/basics/int_big_and2.py index f8c81fe0cd22d..045a90ef75035 100644 --- a/tests/basics/int_big_and2.py +++ b/tests/basics/int_big_and2.py @@ -1,4 +1,4 @@ -# test + + +# test + + print( 97989513389222316022151446562729620153292831887555425160965597396 & 23716683549865351578586448630079789776107310103486834795830390982) @@ -24,7 +24,7 @@ print( 40019818573920230246248826511203818792007462193311949166285967147 & 9487909752) -# test - - +# test - - print( -97989513389222316022151446562729620153292831887555425160965597396 & -23716683549865351578586448630079789776107310103486834795830390982) diff --git a/tests/basics/int_big_and3.py b/tests/basics/int_big_and3.py index 788ecd823bc8f..7a3b415af71d1 100644 --- a/tests/basics/int_big_and3.py +++ b/tests/basics/int_big_and3.py @@ -1,4 +1,4 @@ -# test - + +# test - + print( -97989513389222316022151446562729620153292831887555425160965597396 & 23716683549865351578586448630079789776107310103486834795830390982) @@ -24,7 +24,7 @@ print( -40019818573920230246248826511203818792007462193311949166285967147 & 9487909752) -# test + - +# test + - print( 97989513389222316022151446562729620153292831887555425160965597396 & -23716683549865351578586448630079789776107310103486834795830390982) diff --git a/tests/basics/int_big_or.py b/tests/basics/int_big_or.py index 17d9935265fce..ccded377812b0 100644 --- a/tests/basics/int_big_or.py +++ b/tests/basics/int_big_or.py @@ -3,7 +3,7 @@ a = 0xfffffffffffffffffffffffffffff print(a | (1 << 200)) -# test + + +# test + + print(0 | (1 << 80)) print((1 << 80) | (1 << 80)) @@ -15,7 +15,7 @@ print(a | a == 0) print(bool(a | a)) -# test - + +# test - + print((-1 << 80) | (1 << 80)) print((-1 << 80) | 0) @@ -25,7 +25,7 @@ print((-a) | a == 0) print(bool((-a) | a)) -# test + - +# test + - print(0 | (-1 << 80)) print((1 << 80) | (-1 << 80)) @@ -35,7 +35,7 @@ print(a | (-a) == 0) print(bool(a | (-a))) -# test - - +# test - - print((-1 << 80) | (-1 << 80)) diff --git a/tests/basics/int_big_or2.py b/tests/basics/int_big_or2.py index 255495150ab74..92d76c77034f1 100644 --- a/tests/basics/int_big_or2.py +++ b/tests/basics/int_big_or2.py @@ -1,4 +1,4 @@ -# test + + +# test + + print( 97989513389222316022151446562729620153292831887555425160965597396 | 23716683549865351578586448630079789776107310103486834795830390982) @@ -23,7 +23,7 @@ print( 40019818573920230246248826511203818792007462193311949166285967147 | 9487909752) -# test - - +# test - - print( -97989513389222316022151446562729620153292831887555425160965597396 | -23716683549865351578586448630079789776107310103486834795830390982) diff --git a/tests/basics/int_big_or3.py b/tests/basics/int_big_or3.py index 07edaea2df912..212b3da8a6442 100644 --- a/tests/basics/int_big_or3.py +++ b/tests/basics/int_big_or3.py @@ -1,4 +1,4 @@ -# test - + +# test - + print( -97989513389222316022151446562729620153292831887555425160965597396 | 23716683549865351578586448630079789776107310103486834795830390982) @@ -24,7 +24,7 @@ print( -40019818573920230246248826511203818792007462193311949166285967147 | 9487909752) -# test + - +# test + - print( 97989513389222316022151446562729620153292831887555425160965597396 | -23716683549865351578586448630079789776107310103486834795830390982) diff --git a/tests/basics/int_big_xor.py b/tests/basics/int_big_xor.py index cd1d9ae97fa75..28b191d3d948e 100644 --- a/tests/basics/int_big_xor.py +++ b/tests/basics/int_big_xor.py @@ -1,4 +1,4 @@ -# test + + +# test + + print(0 ^ (1 << 80)) print((1 << 80) ^ (1 << 80)) @@ -10,7 +10,7 @@ print(a ^ a == 0) print(bool(a ^ a)) -# test - + +# test - + print((-1 << 80) ^ (1 << 80)) print((-1 << 80) ^ 0) @@ -22,7 +22,7 @@ i = -1 print(i ^ 0xffffffffffffffff) # carry overflows to higher digit -# test + - +# test + - print(0 ^ (-1 << 80)) print((1 << 80) ^ (-1 << 80)) @@ -32,7 +32,7 @@ print(a ^ (-a) == 0) print(bool(a ^ (-a))) -# test - - +# test - - print((-1 << 80) ^ (-1 << 80)) diff --git a/tests/basics/int_big_xor2.py b/tests/basics/int_big_xor2.py index b5b3db60c69f7..21ef842f86620 100644 --- a/tests/basics/int_big_xor2.py +++ b/tests/basics/int_big_xor2.py @@ -1,4 +1,4 @@ -# test + + +# test + + print( 97989513389222316022151446562729620153292831887555425160965597396 ^ 23716683549865351578586448630079789776107310103486834795830390982) @@ -24,7 +24,7 @@ print( 40019818573920230246248826511203818792007462193311949166285967147 ^ 9487909752) -# test - - +# test - - print( -97989513389222316022151446562729620153292831887555425160965597396 ^ -23716683549865351578586448630079789776107310103486834795830390982) diff --git a/tests/basics/int_big_xor3.py b/tests/basics/int_big_xor3.py index 00881e3740985..ff5e9aeff2f9e 100644 --- a/tests/basics/int_big_xor3.py +++ b/tests/basics/int_big_xor3.py @@ -1,4 +1,4 @@ -# test - + +# test - + print( -97989513389222316022151446562729620153292831887555425160965597396 ^ 23716683549865351578586448630079789776107310103486834795830390982) @@ -24,7 +24,7 @@ print( -40019818573920230246248826511203818792007462193311949166285967147 ^ 9487909752) -# test + - +# test + - print( 97989513389222316022151446562729620153292831887555425160965597396 ^ -23716683549865351578586448630079789776107310103486834795830390982) diff --git a/tests/io/data/bigfile1 b/tests/io/data/bigfile1 index 5afbf01a6f4e5..777c436a21f2f 100644 --- a/tests/io/data/bigfile1 +++ b/tests/io/data/bigfile1 @@ -1,147 +1,147 @@ { "info": { - "maintainer": null, - "docs_url": "", - "requires_python": null, - "maintainer_email": null, - "cheesecake_code_kwalitee_id": null, - "keywords": null, - "package_url": "http://pypi.python.org/pypi/micropython-uasyncio", - "author": "MicroPython Developers", - "author_email": "micro-python@googlegroups.com", - "download_url": "UNKNOWN", - "platform": "UNKNOWN", - "version": "0.8.1", - "cheesecake_documentation_id": null, - "_pypi_hidden": false, - "description": "Lightweight asyncio-like library built around native Python coroutines, not around un-Python devices like callback mess.", - "release_url": "http://pypi.python.org/pypi/micropython-uasyncio/0.8.1", + "maintainer": null, + "docs_url": "", + "requires_python": null, + "maintainer_email": null, + "cheesecake_code_kwalitee_id": null, + "keywords": null, + "package_url": "http://pypi.python.org/pypi/micropython-uasyncio", + "author": "MicroPython Developers", + "author_email": "micro-python@googlegroups.com", + "download_url": "UNKNOWN", + "platform": "UNKNOWN", + "version": "0.8.1", + "cheesecake_documentation_id": null, + "_pypi_hidden": false, + "description": "Lightweight asyncio-like library built around native Python coroutines, not around un-Python devices like callback mess.", + "release_url": "http://pypi.python.org/pypi/micropython-uasyncio/0.8.1", "downloads": { - "last_month": 942, - "last_week": 173, + "last_month": 942, + "last_week": 173, "last_day": 29 - }, - "_pypi_ordering": 6, - "classifiers": [], - "name": "micropython-uasyncio", - "bugtrack_url": null, - "license": "MIT", - "summary": "uasyncio module for MicroPython", - "home_page": "https://github.com/micropython/micropython/issues/405", - "stable_version": null, + }, + "_pypi_ordering": 6, + "classifiers": [], + "name": "micropython-uasyncio", + "bugtrack_url": null, + "license": "MIT", + "summary": "uasyncio module for MicroPython", + "home_page": "https://github.com/micropython/micropython/issues/405", + "stable_version": null, "cheesecake_installability_id": null - }, + }, "releases": { "0.8": [ { - "has_sig": false, - "upload_time": "2015-01-01T23:52:41", - "comment_text": "", - "python_version": "source", - "url": "https://pypi.python.org/packages/source/m/micropython-uasyncio/micropython-uasyncio-0.8.tar.gz", - "md5_digest": "5df4d0d6b5fdb7c05fc418e5785e1336", - "downloads": 352, - "filename": "micropython-uasyncio-0.8.tar.gz", - "packagetype": "sdist", + "has_sig": false, + "upload_time": "2015-01-01T23:52:41", + "comment_text": "", + "python_version": "source", + "url": "https://pypi.python.org/packages/source/m/micropython-uasyncio/micropython-uasyncio-0.8.tar.gz", + "md5_digest": "5df4d0d6b5fdb7c05fc418e5785e1336", + "downloads": 352, + "filename": "micropython-uasyncio-0.8.tar.gz", + "packagetype": "sdist", "size": 2476 } - ], + ], "0.6.2": [ { - "has_sig": false, - "upload_time": "2014-10-18T11:26:52", - "comment_text": "", - "python_version": "source", - "url": "https://pypi.python.org/packages/source/m/micropython-uasyncio/micropython-uasyncio-0.6.2.tar.gz", - "md5_digest": "c85fa7c11ef437f4e73c1fcd639db066", - "downloads": 475, - "filename": "micropython-uasyncio-0.6.2.tar.gz", - "packagetype": "sdist", + "has_sig": false, + "upload_time": "2014-10-18T11:26:52", + "comment_text": "", + "python_version": "source", + "url": "https://pypi.python.org/packages/source/m/micropython-uasyncio/micropython-uasyncio-0.6.2.tar.gz", + "md5_digest": "c85fa7c11ef437f4e73c1fcd639db066", + "downloads": 475, + "filename": "micropython-uasyncio-0.6.2.tar.gz", + "packagetype": "sdist", "size": 3262 } - ], + ], "0.6.1": [ { - "has_sig": false, - "upload_time": "2014-10-11T02:21:17", - "comment_text": "", - "python_version": "source", - "url": "https://pypi.python.org/packages/source/m/micropython-uasyncio/micropython-uasyncio-0.6.1.tar.gz", - "md5_digest": "48cb0db7d8249d5f4a86db9c4b302d03", - "downloads": 507, - "filename": "micropython-uasyncio-0.6.1.tar.gz", - "packagetype": "sdist", + "has_sig": false, + "upload_time": "2014-10-11T02:21:17", + "comment_text": "", + "python_version": "source", + "url": "https://pypi.python.org/packages/source/m/micropython-uasyncio/micropython-uasyncio-0.6.1.tar.gz", + "md5_digest": "48cb0db7d8249d5f4a86db9c4b302d03", + "downloads": 507, + "filename": "micropython-uasyncio-0.6.1.tar.gz", + "packagetype": "sdist", "size": 3237 } - ], + ], "0.8.1": [ { - "has_sig": false, - "upload_time": "2015-01-04T20:02:03", - "comment_text": "", - "python_version": "source", - "url": "https://pypi.python.org/packages/source/m/micropython-uasyncio/micropython-uasyncio-0.8.1.tar.gz", - "md5_digest": "940d2647b8355289d54de543ff710b05", - "downloads": 249, - "filename": "micropython-uasyncio-0.8.1.tar.gz", - "packagetype": "sdist", + "has_sig": false, + "upload_time": "2015-01-04T20:02:03", + "comment_text": "", + "python_version": "source", + "url": "https://pypi.python.org/packages/source/m/micropython-uasyncio/micropython-uasyncio-0.8.1.tar.gz", + "md5_digest": "940d2647b8355289d54de543ff710b05", + "downloads": 249, + "filename": "micropython-uasyncio-0.8.1.tar.gz", + "packagetype": "sdist", "size": 2484 } - ], + ], "0.7": [ { - "has_sig": false, - "upload_time": "2014-10-23T22:02:11", - "comment_text": "", - "python_version": "source", - "url": "https://pypi.python.org/packages/source/m/micropython-uasyncio/micropython-uasyncio-0.7.tar.gz", - "md5_digest": "81250a0ee6649b5117878d5788ba96d3", - "downloads": 457, - "filename": "micropython-uasyncio-0.7.tar.gz", - "packagetype": "sdist", + "has_sig": false, + "upload_time": "2014-10-23T22:02:11", + "comment_text": "", + "python_version": "source", + "url": "https://pypi.python.org/packages/source/m/micropython-uasyncio/micropython-uasyncio-0.7.tar.gz", + "md5_digest": "81250a0ee6649b5117878d5788ba96d3", + "downloads": 457, + "filename": "micropython-uasyncio-0.7.tar.gz", + "packagetype": "sdist", "size": 2277 } - ], + ], "0.7.1": [ { - "has_sig": false, - "upload_time": "2014-11-04T00:56:16", - "comment_text": "", - "python_version": "source", - "url": "https://pypi.python.org/packages/source/m/micropython-uasyncio/micropython-uasyncio-0.7.1.tar.gz", - "md5_digest": "21eda0501142830730cd82e1b0fa1a33", - "downloads": 412, - "filename": "micropython-uasyncio-0.7.1.tar.gz", - "packagetype": "sdist", + "has_sig": false, + "upload_time": "2014-11-04T00:56:16", + "comment_text": "", + "python_version": "source", + "url": "https://pypi.python.org/packages/source/m/micropython-uasyncio/micropython-uasyncio-0.7.1.tar.gz", + "md5_digest": "21eda0501142830730cd82e1b0fa1a33", + "downloads": 412, + "filename": "micropython-uasyncio-0.7.1.tar.gz", + "packagetype": "sdist", "size": 2474 } - ], + ], "0.6": [ { - "has_sig": false, - "upload_time": "2014-08-27T00:17:45", - "comment_text": "", - "python_version": "source", - "url": "https://pypi.python.org/packages/source/m/micropython-uasyncio/micropython-uasyncio-0.6.tar.gz", - "md5_digest": "9d0b15108c5ade3a6902c9370c9dacf1", - "downloads": 668, - "filename": "micropython-uasyncio-0.6.tar.gz", - "packagetype": "sdist", + "has_sig": false, + "upload_time": "2014-08-27T00:17:45", + "comment_text": "", + "python_version": "source", + "url": "https://pypi.python.org/packages/source/m/micropython-uasyncio/micropython-uasyncio-0.6.tar.gz", + "md5_digest": "9d0b15108c5ade3a6902c9370c9dacf1", + "downloads": 668, + "filename": "micropython-uasyncio-0.6.tar.gz", + "packagetype": "sdist", "size": 3246 } ] - }, + }, "urls": [ { - "has_sig": false, - "upload_time": "2015-01-04T20:02:03", - "comment_text": "", - "python_version": "source", - "url": "https://pypi.python.org/packages/source/m/micropython-uasyncio/micropython-uasyncio-0.8.1.tar.gz", - "md5_digest": "940d2647b8355289d54de543ff710b05", - "downloads": 249, - "filename": "micropython-uasyncio-0.8.1.tar.gz", - "packagetype": "sdist", + "has_sig": false, + "upload_time": "2015-01-04T20:02:03", + "comment_text": "", + "python_version": "source", + "url": "https://pypi.python.org/packages/source/m/micropython-uasyncio/micropython-uasyncio-0.8.1.tar.gz", + "md5_digest": "940d2647b8355289d54de543ff710b05", + "downloads": 249, + "filename": "micropython-uasyncio-0.8.1.tar.gz", + "packagetype": "sdist", "size": 2484 } ] diff --git a/tests/ports/cc3200/pin.py b/tests/ports/cc3200/pin.py index 9ffd152e93ea7..43537bba5ce07 100644 --- a/tests/ports/cc3200/pin.py +++ b/tests/ports/cc3200/pin.py @@ -1,7 +1,7 @@ -""" -This test need a set of pins which can be set as inputs and have no external +""" +This test need a set of pins which can be set as inputs and have no external pull up or pull down connected. -GP12 and GP17 must be connected together +GP12 and GP17 must be connected together """ from machine import Pin import os diff --git a/tests/ports/cc3200/uart.py b/tests/ports/cc3200/uart.py index 94ac9051b24d3..c92c8041fc0ce 100644 --- a/tests/ports/cc3200/uart.py +++ b/tests/ports/cc3200/uart.py @@ -1,5 +1,5 @@ """ -UART test for the CC3200 based boards. +UART test for the CC3200 based boards. UART0 and UART1 must be connected together for this test to pass. """ diff --git a/tools/codestats.sh b/tools/codestats.sh index 74430739917b5..be796568a19d8 100755 --- a/tools/codestats.sh +++ b/tools/codestats.sh @@ -116,7 +116,7 @@ index 77d2945..dae0644 100644 @@ -55,10 +55,8 @@ void msec_sleep_tv(struct timeval *tv) { #define MP_CLOCKS_PER_SEC CLOCKS_PER_SEC #endif - + -#if defined(MP_CLOCKS_PER_SEC) && (MP_CLOCKS_PER_SEC == 1000000) // POSIX -#define CLOCK_DIV 1000.0 -#elif defined(MP_CLOCKS_PER_SEC) && (MP_CLOCKS_PER_SEC == 1000) // WIN32 From b3c62f31690ba0e6458589d934acd2db5ee92375 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 7 Mar 2024 16:29:46 +1100 Subject: [PATCH 182/408] top: Update .git-blame-ignore-revs for latest format/spell commits. Signed-off-by: Damien George --- .git-blame-ignore-revs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 690e5f46a4fc0..195e1e06eea46 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -1,3 +1,12 @@ +# all: Prune trailing whitespace. +dda9b9c6da5d3c31fa8769e581a753e95a270803 + +# all: Remove the "STATIC" macro and just use "static" instead. +decf8e6a8bb940d5829ca3296790631fcece7b21 + +# renesas-ra: Fix spelling mistakes found by codespell. +b3f2f18f927fa2fad10daf63d8c391331f5edf58 + # all: Update Python formatting to ruff-format. bbd8760bd9a2302e5abee29db279102bb11d7732 From 185ae18360f47f8d97070689116b398b019e14db Mon Sep 17 00:00:00 2001 From: robert-hh Date: Thu, 8 Feb 2024 17:56:49 +0100 Subject: [PATCH 183/408] stm32/network_lan: Allow defining phy_addr in the LAN constructor. The default value is 0, which is compatible with the existing behaviour. Implementing that required changes to eth.c as well. The value of phy_addr is added to the eth_t data type. Tested with a STM32F767 and a STM32H750 device. Signed-off-by: robert-hh --- .../boards/ARDUINO_PORTENTA_H7/board_init.c | 2 +- ports/stm32/eth.c | 37 +++++++++++-------- ports/stm32/eth.h | 2 +- ports/stm32/network_lan.c | 13 +++++-- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/ports/stm32/boards/ARDUINO_PORTENTA_H7/board_init.c b/ports/stm32/boards/ARDUINO_PORTENTA_H7/board_init.c index 39f7828773130..ad275ef87c3e8 100644 --- a/ports/stm32/boards/ARDUINO_PORTENTA_H7/board_init.c +++ b/ports/stm32/boards/ARDUINO_PORTENTA_H7/board_init.c @@ -115,7 +115,7 @@ void PORTENTA_board_early_init(void) { mp_hal_pin_write(pyb_pin_ETH_RST, 1); // Put Eth in low-power mode - eth_init(ð_instance, MP_HAL_MAC_ETH0); + eth_init(ð_instance, MP_HAL_MAC_ETH0, 0); eth_low_power_mode(ð_instance, true); #if MICROPY_HW_USB_HS_ULPI3320 diff --git a/ports/stm32/eth.c b/ports/stm32/eth.c index 12c29f071616b..e1e6f074cdf66 100644 --- a/ports/stm32/eth.c +++ b/ports/stm32/eth.c @@ -40,8 +40,7 @@ #include "lwip/dhcp.h" #include "netif/ethernet.h" -// ETH PHY register definitions (for LAN8742) - +// ETH PHY register definitions (for LAN8742 and LAN8720/LAN8710) #undef PHY_BCR #define PHY_BCR (0x0000) #define PHY_BCR_SOFT_RESET (0x8000) @@ -137,6 +136,7 @@ typedef struct _eth_t { uint32_t trace_flags; struct netif netif; struct dhcp dhcp_struct; + uint32_t phy_addr; } eth_t; static eth_dma_t eth_dma __attribute__((aligned(16384))); @@ -146,11 +146,13 @@ eth_t eth_instance; static void eth_mac_deinit(eth_t *self); static void eth_process_frame(eth_t *self, size_t len, const uint8_t *buf); -static void eth_phy_write(uint32_t reg, uint32_t val) { +static void eth_phy_write(uint32_t phy_addr, uint32_t reg, uint32_t val) { #if defined(STM32H5) || defined(STM32H7) while (ETH->MACMDIOAR & ETH_MACMDIOAR_MB) { } uint32_t ar = ETH->MACMDIOAR; + ar &= ~ETH_MACMDIOAR_PA_Msk; + ar |= (phy_addr << ETH_MACMDIOAR_PA_Pos); ar &= ~ETH_MACMDIOAR_RDA_Msk; ar |= reg << ETH_MACMDIOAR_RDA_Pos; ar &= ~ETH_MACMDIOAR_MOC_Msk; @@ -165,18 +167,20 @@ static void eth_phy_write(uint32_t reg, uint32_t val) { } ETH->MACMIIDR = val; uint32_t ar = ETH->MACMIIAR; - ar = reg << ETH_MACMIIAR_MR_Pos | (ar & ETH_MACMIIAR_CR_Msk) | ETH_MACMIIAR_MW | ETH_MACMIIAR_MB; + ar = (phy_addr << ETH_MACMIIAR_PA_Pos) | (reg << ETH_MACMIIAR_MR_Pos) | (ar & ETH_MACMIIAR_CR_Msk) | ETH_MACMIIAR_MW | ETH_MACMIIAR_MB; ETH->MACMIIAR = ar; while (ETH->MACMIIAR & ETH_MACMIIAR_MB) { } #endif } -static uint32_t eth_phy_read(uint32_t reg) { +static uint32_t eth_phy_read(uint32_t phy_addr, uint32_t reg) { #if defined(STM32H5) || defined(STM32H7) while (ETH->MACMDIOAR & ETH_MACMDIOAR_MB) { } uint32_t ar = ETH->MACMDIOAR; + ar &= ~ETH_MACMDIOAR_PA_Msk; + ar |= (phy_addr << ETH_MACMDIOAR_PA_Pos); ar &= ~ETH_MACMDIOAR_RDA_Msk; ar |= reg << ETH_MACMDIOAR_RDA_Pos; ar &= ~ETH_MACMDIOAR_MOC_Msk; @@ -190,7 +194,7 @@ static uint32_t eth_phy_read(uint32_t reg) { while (ETH->MACMIIAR & ETH_MACMIIAR_MB) { } uint32_t ar = ETH->MACMIIAR; - ar = reg << ETH_MACMIIAR_MR_Pos | (ar & ETH_MACMIIAR_CR_Msk) | ETH_MACMIIAR_MB; + ar = (phy_addr << ETH_MACMIIAR_PA_Pos) | (reg << ETH_MACMIIAR_MR_Pos) | (ar & ETH_MACMIIAR_CR_Msk) | ETH_MACMIIAR_MB; ETH->MACMIIAR = ar; while (ETH->MACMIIAR & ETH_MACMIIAR_MB) { } @@ -198,9 +202,10 @@ static uint32_t eth_phy_read(uint32_t reg) { #endif } -void eth_init(eth_t *self, int mac_idx) { +void eth_init(eth_t *self, int mac_idx, uint32_t phy_addr) { mp_hal_get_mac(mac_idx, &self->netif.hwaddr[0]); self->netif.hwaddr_len = 6; + self->phy_addr = phy_addr; // Configure GPIO mp_hal_pin_config_alt_static(MICROPY_HW_ETH_MDC, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_NONE, STATIC_AF_ETH_MDC); @@ -362,7 +367,7 @@ static int eth_mac_init(eth_t *self) { #endif // Reset the PHY - eth_phy_write(PHY_BCR, PHY_BCR_SOFT_RESET); + eth_phy_write(self->phy_addr, PHY_BCR, PHY_BCR_SOFT_RESET); mp_hal_delay_ms(50); // Wait for the PHY link to be established @@ -373,8 +378,8 @@ static int eth_mac_init(eth_t *self) { eth_mac_deinit(self); return -MP_ETIMEDOUT; } - uint16_t bcr = eth_phy_read(0); - uint16_t bsr = eth_phy_read(1); + uint16_t bcr = eth_phy_read(self->phy_addr, PHY_BCR); + uint16_t bsr = eth_phy_read(self->phy_addr, PHY_BSR); switch (phy_state) { case 0: if (!(bcr & PHY_BCR_SOFT_RESET)) { @@ -383,7 +388,7 @@ static int eth_mac_init(eth_t *self) { break; case 1: if (bsr & PHY_BSR_LINK_STATUS) { - eth_phy_write(PHY_BCR, PHY_BCR_AUTONEG_EN); + eth_phy_write(self->phy_addr, PHY_BCR, PHY_BCR_AUTONEG_EN); phy_state = 2; } break; @@ -398,7 +403,7 @@ static int eth_mac_init(eth_t *self) { } // Get register with link status - uint16_t phy_scsr = eth_phy_read(PHY_SCSR); + uint16_t phy_scsr = eth_phy_read(self->phy_addr, PHY_SCSR); // Burst mode configuration #if defined(STM32H5) || defined(STM32H7) @@ -845,7 +850,7 @@ int eth_link_status(eth_t *self) { return 2; // link no-ip; } } else { - if (eth_phy_read(PHY_BSR) & PHY_BSR_LINK_STATUS) { + if (eth_phy_read(self->phy_addr, PHY_BSR) & PHY_BSR_LINK_STATUS) { return 1; // link up } else { return 0; // link down @@ -883,10 +888,10 @@ void eth_low_power_mode(eth_t *self, bool enable) { __HAL_RCC_ETH_CLK_ENABLE(); #endif - uint16_t bcr = eth_phy_read(PHY_BCR); + uint16_t bcr = eth_phy_read(self->phy_addr, PHY_BCR); if (enable) { // Enable low-power mode. - eth_phy_write(PHY_BCR, bcr | PHY_BCR_POWER_DOWN); + eth_phy_write(self->phy_addr, PHY_BCR, bcr | PHY_BCR_POWER_DOWN); // Disable eth clock. #if defined(STM32H7) __HAL_RCC_ETH1MAC_CLK_DISABLE(); @@ -895,7 +900,7 @@ void eth_low_power_mode(eth_t *self, bool enable) { #endif } else { // Disable low-power mode. - eth_phy_write(PHY_BCR, bcr & (~PHY_BCR_POWER_DOWN)); + eth_phy_write(self->phy_addr, PHY_BCR, bcr & (~PHY_BCR_POWER_DOWN)); } } #endif // defined(MICROPY_HW_ETH_MDC) diff --git a/ports/stm32/eth.h b/ports/stm32/eth.h index 47344b9526fd4..45c385a2524ab 100644 --- a/ports/stm32/eth.h +++ b/ports/stm32/eth.h @@ -29,7 +29,7 @@ typedef struct _eth_t eth_t; extern eth_t eth_instance; -void eth_init(eth_t *self, int mac_idx); +void eth_init(eth_t *self, int mac_idx, uint32_t phy_addr); void eth_set_trace(eth_t *self, uint32_t value); struct netif *eth_netif(eth_t *self); int eth_link_status(eth_t *self); diff --git a/ports/stm32/network_lan.c b/ports/stm32/network_lan.c index 2f70caf0123a4..efdd354fb3a64 100644 --- a/ports/stm32/network_lan.c +++ b/ports/stm32/network_lan.c @@ -53,10 +53,17 @@ static void network_lan_print(const mp_print_t *print, mp_obj_t self_in, mp_prin ); } -static mp_obj_t network_lan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { - mp_arg_check_num(n_args, n_kw, 0, 0, false); +static mp_obj_t network_lan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { + enum { ARG_phy_addr}; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_phy_addr, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, + }; + // Parse args. + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + const network_lan_obj_t *self = &network_lan_eth0; - eth_init(self->eth, MP_HAL_MAC_ETH0); + eth_init(self->eth, MP_HAL_MAC_ETH0, args[ARG_phy_addr].u_int); return MP_OBJ_FROM_PTR(self); } From 085e3244f0bc5a1ddaaad4ab32c33ce5545be4ac Mon Sep 17 00:00:00 2001 From: robert-hh Date: Sun, 11 Feb 2024 12:33:08 +0100 Subject: [PATCH 184/408] stm32/eth: Remove redundant ETH clock enable code. The MAC clock was initialized both in eth_init() and eth_mac_init(). The latter is not required. Signed-off-by: robert-hh --- ports/stm32/eth.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/ports/stm32/eth.c b/ports/stm32/eth.c index e1e6f074cdf66..f5bdcc1524791 100644 --- a/ports/stm32/eth.c +++ b/ports/stm32/eth.c @@ -246,19 +246,12 @@ static int eth_mac_init(eth_t *self) { #endif mpu_config_end(irq_state); - // Enable peripheral clock + // Set MAC to reset state #if defined(STM32H5) - __HAL_RCC_ETH_CLK_ENABLE(); - __HAL_RCC_ETHTX_CLK_ENABLE(); - __HAL_RCC_ETHRX_CLK_ENABLE(); __HAL_RCC_ETH_FORCE_RESET(); #elif defined(STM32H7) - __HAL_RCC_ETH1MAC_CLK_ENABLE(); - __HAL_RCC_ETH1TX_CLK_ENABLE(); - __HAL_RCC_ETH1RX_CLK_ENABLE(); __HAL_RCC_ETH1MAC_FORCE_RESET(); #else - __HAL_RCC_ETH_CLK_ENABLE(); __HAL_RCC_ETHMAC_FORCE_RESET(); #endif From bf68bb95f9774127a026845e286822ca83bcaa37 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Thu, 15 Feb 2024 21:05:51 +0100 Subject: [PATCH 185/408] stm32/network_lan: Add the phy_type=x keyword option to network.LAN(). With LAN8742, LAN8720, LAN83825 and DP83848 as possible options, and the symbols PHY_LAN8720, PHY_LAN8742, PHY_DP83825 and PHY_DP8348. The default is PHY_LAN8742 which is the existing behaviour. The eth_init() parameters for the Portenta H7 board are set to phy_addr=0 and phy_type=LAN8742, which matches the previous defaults and the schematics. Tested with LAN8720 and DP83848 breakout boards at 10M Duplex and 100M Duplex modes. Signed-off-by: robert-hh --- ports/stm32/Makefile | 1 + .../boards/ARDUINO_PORTENTA_H7/board_init.c | 2 +- ports/stm32/eth.c | 52 +++++++------- ports/stm32/eth.h | 9 ++- ports/stm32/eth_phy.c | 59 ++++++++++++++++ ports/stm32/eth_phy.h | 67 +++++++++++++++++++ ports/stm32/network_lan.c | 12 +++- 7 files changed, 171 insertions(+), 31 deletions(-) create mode 100644 ports/stm32/eth_phy.c create mode 100644 ports/stm32/eth_phy.h diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile index 19f6f420e1fff..d1694426d3529 100644 --- a/ports/stm32/Makefile +++ b/ports/stm32/Makefile @@ -251,6 +251,7 @@ SRC_C += \ pyb_can.c \ usb.c \ eth.c \ + eth_phy.c \ gccollect.c \ help.c \ machine_bitstream.c \ diff --git a/ports/stm32/boards/ARDUINO_PORTENTA_H7/board_init.c b/ports/stm32/boards/ARDUINO_PORTENTA_H7/board_init.c index ad275ef87c3e8..04fa3b9bc37be 100644 --- a/ports/stm32/boards/ARDUINO_PORTENTA_H7/board_init.c +++ b/ports/stm32/boards/ARDUINO_PORTENTA_H7/board_init.c @@ -115,7 +115,7 @@ void PORTENTA_board_early_init(void) { mp_hal_pin_write(pyb_pin_ETH_RST, 1); // Put Eth in low-power mode - eth_init(ð_instance, MP_HAL_MAC_ETH0, 0); + eth_init(ð_instance, MP_HAL_MAC_ETH0, 0, ETH_PHY_LAN8742); eth_low_power_mode(ð_instance, true); #if MICROPY_HW_USB_HS_ULPI3320 diff --git a/ports/stm32/eth.c b/ports/stm32/eth.c index f5bdcc1524791..fd46bde23cb3f 100644 --- a/ports/stm32/eth.c +++ b/ports/stm32/eth.c @@ -32,6 +32,7 @@ #include "extmod/modnetwork.h" #include "mpu.h" #include "eth.h" +#include "eth_phy.h" #if defined(MICROPY_HW_ETH_MDC) @@ -40,26 +41,6 @@ #include "lwip/dhcp.h" #include "netif/ethernet.h" -// ETH PHY register definitions (for LAN8742 and LAN8720/LAN8710) -#undef PHY_BCR -#define PHY_BCR (0x0000) -#define PHY_BCR_SOFT_RESET (0x8000) -#define PHY_BCR_AUTONEG_EN (0x1000) -#define PHY_BCR_POWER_DOWN (0x0800U) - -#undef PHY_BSR -#define PHY_BSR (0x0001) -#define PHY_BSR_LINK_STATUS (0x0004) -#define PHY_BSR_AUTONEG_DONE (0x0020) - -#define PHY_SCSR (0x001f) -#define PHY_SCSR_SPEED_Pos (2) -#define PHY_SCSR_SPEED_Msk (7 << PHY_SCSR_SPEED_Pos) -#define PHY_SCSR_SPEED_10HALF (1 << PHY_SCSR_SPEED_Pos) -#define PHY_SCSR_SPEED_10FULL (5 << PHY_SCSR_SPEED_Pos) -#define PHY_SCSR_SPEED_100HALF (2 << PHY_SCSR_SPEED_Pos) -#define PHY_SCSR_SPEED_100FULL (6 << PHY_SCSR_SPEED_Pos) - // ETH DMA RX and TX descriptor definitions #if defined(STM32H5) #define RX_DESCR_3_OWN_Pos (31) @@ -137,6 +118,7 @@ typedef struct _eth_t { struct netif netif; struct dhcp dhcp_struct; uint32_t phy_addr; + int16_t (*phy_get_link_status)(uint32_t phy_addr); } eth_t; static eth_dma_t eth_dma __attribute__((aligned(16384))); @@ -146,7 +128,7 @@ eth_t eth_instance; static void eth_mac_deinit(eth_t *self); static void eth_process_frame(eth_t *self, size_t len, const uint8_t *buf); -static void eth_phy_write(uint32_t phy_addr, uint32_t reg, uint32_t val) { +void eth_phy_write(uint32_t phy_addr, uint32_t reg, uint32_t val) { #if defined(STM32H5) || defined(STM32H7) while (ETH->MACMDIOAR & ETH_MACMDIOAR_MB) { } @@ -174,7 +156,7 @@ static void eth_phy_write(uint32_t phy_addr, uint32_t reg, uint32_t val) { #endif } -static uint32_t eth_phy_read(uint32_t phy_addr, uint32_t reg) { +uint32_t eth_phy_read(uint32_t phy_addr, uint32_t reg) { #if defined(STM32H5) || defined(STM32H7) while (ETH->MACMDIOAR & ETH_MACMDIOAR_MB) { } @@ -202,10 +184,17 @@ static uint32_t eth_phy_read(uint32_t phy_addr, uint32_t reg) { #endif } -void eth_init(eth_t *self, int mac_idx, uint32_t phy_addr) { +int eth_init(eth_t *self, int mac_idx, uint32_t phy_addr, int phy_type) { mp_hal_get_mac(mac_idx, &self->netif.hwaddr[0]); self->netif.hwaddr_len = 6; self->phy_addr = phy_addr; + if (phy_type == ETH_PHY_DP83825 || phy_type == ETH_PHY_DP83848) { + self->phy_get_link_status = eth_phy_dp838xx_get_link_status; + } else if (phy_type == ETH_PHY_LAN8720 || phy_type == ETH_PHY_LAN8742) { + self->phy_get_link_status = eth_phy_lan87xx_get_link_status; + } else { + return -1; + } // Configure GPIO mp_hal_pin_config_alt_static(MICROPY_HW_ETH_MDC, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_NONE, STATIC_AF_ETH_MDC); @@ -230,6 +219,7 @@ void eth_init(eth_t *self, int mac_idx, uint32_t phy_addr) { #else __HAL_RCC_ETH_CLK_ENABLE(); #endif + return 0; } void eth_set_trace(eth_t *self, uint32_t value) { @@ -381,6 +371,14 @@ static int eth_mac_init(eth_t *self) { break; case 1: if (bsr & PHY_BSR_LINK_STATUS) { + // Announce all modes + eth_phy_write(self->phy_addr, PHY_ANAR, + PHY_ANAR_SPEED_10HALF | + PHY_ANAR_SPEED_10FULL | + PHY_ANAR_SPEED_100HALF | + PHY_ANAR_SPEED_100FULL | + PHY_ANAR_IEEE802_3); + // Start autonegotiate. eth_phy_write(self->phy_addr, PHY_BCR, PHY_BCR_AUTONEG_EN); phy_state = 2; } @@ -396,7 +394,7 @@ static int eth_mac_init(eth_t *self) { } // Get register with link status - uint16_t phy_scsr = eth_phy_read(self->phy_addr, PHY_SCSR); + uint16_t phy_scsr = self->phy_get_link_status(self->phy_addr); // Burst mode configuration #if defined(STM32H5) || defined(STM32H7) @@ -505,9 +503,9 @@ static int eth_mac_init(eth_t *self) { // Set main MAC control register ETH->MACCR = - (phy_scsr & PHY_SCSR_SPEED_Msk) == PHY_SCSR_SPEED_10FULL ? ETH_MACCR_DM - : (phy_scsr & PHY_SCSR_SPEED_Msk) == PHY_SCSR_SPEED_100HALF ? ETH_MACCR_FES - : (phy_scsr & PHY_SCSR_SPEED_Msk) == PHY_SCSR_SPEED_100FULL ? (ETH_MACCR_FES | ETH_MACCR_DM) + phy_scsr == PHY_SPEED_10FULL ? ETH_MACCR_DM + : phy_scsr == PHY_SPEED_100HALF ? ETH_MACCR_FES + : phy_scsr == PHY_SPEED_100FULL ? (ETH_MACCR_FES | ETH_MACCR_DM) : 0 ; mp_hal_delay_ms(2); diff --git a/ports/stm32/eth.h b/ports/stm32/eth.h index 45c385a2524ab..5647449690cfa 100644 --- a/ports/stm32/eth.h +++ b/ports/stm32/eth.h @@ -26,10 +26,17 @@ #ifndef MICROPY_INCLUDED_STM32_ETH_H #define MICROPY_INCLUDED_STM32_ETH_H +enum { + ETH_PHY_LAN8742 = 0, + ETH_PHY_LAN8720, + ETH_PHY_DP83848, + ETH_PHY_DP83825 +}; + typedef struct _eth_t eth_t; extern eth_t eth_instance; -void eth_init(eth_t *self, int mac_idx, uint32_t phy_addr); +int eth_init(eth_t *self, int mac_idx, uint32_t phy_addr, int phy_type); void eth_set_trace(eth_t *self, uint32_t value); struct netif *eth_netif(eth_t *self); int eth_link_status(eth_t *self); diff --git a/ports/stm32/eth_phy.c b/ports/stm32/eth_phy.c new file mode 100644 index 0000000000000..56cddba9c520b --- /dev/null +++ b/ports/stm32/eth_phy.c @@ -0,0 +1,59 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Damien P. George + * Copyright (c) 2024 Robert Hammelrath + * + * 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 "eth_phy.h" + +#if defined(MICROPY_HW_ETH_MDC) + +#define PHY_SCSR_LAN87XX (0x001f) +#define PHY_SCSR_LAN87XX_SPEED_Pos (2) +#define PHY_SCSR_LAN87XX_SPEED_Msk (7) + +#define PHY_SCSR_DP838XX (0x0010) +#define PHY_RECR_DP838XX (0x0015) +#define PHY_SCSR_DP838XX_DUPLEX_Msk (4) +#define PHY_SCSR_DP838XX_10M_Msk (2) + +int16_t eth_phy_lan87xx_get_link_status(uint32_t phy_addr) { + // Get the link mode & speed + int16_t scsr = eth_phy_read(phy_addr, PHY_SCSR_LAN87XX); + return (scsr >> PHY_SCSR_LAN87XX_SPEED_Pos) & PHY_SCSR_LAN87XX_SPEED_Msk; +} + +int16_t eth_phy_dp838xx_get_link_status(uint32_t phy_addr) { + int16_t scsr = 0; + // Get the link mode & speed + uint16_t temp = eth_phy_read(phy_addr, PHY_SCSR_DP838XX); + scsr = (temp & PHY_SCSR_DP838XX_10M_Msk) ? PHY_SPEED_10HALF : PHY_SPEED_100HALF; + if (temp & PHY_SCSR_DP838XX_DUPLEX_Msk) { + scsr |= PHY_DUPLEX; + } + return scsr; +} + +#endif diff --git a/ports/stm32/eth_phy.h b/ports/stm32/eth_phy.h new file mode 100644 index 0000000000000..5036905c1f582 --- /dev/null +++ b/ports/stm32/eth_phy.h @@ -0,0 +1,67 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Damien P. George + * Copyright (c) 2024 Robert Hammelrath + * + * 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_STM32_PHY_H +#define MICROPY_INCLUDED_STM32_PYH_H + +#if defined(MICROPY_HW_ETH_MDC) + +// Common ETH PHY register definitions +#undef PHY_BCR +#define PHY_BCR (0x0000) +#define PHY_BCR_SOFT_RESET (0x8000) +#define PHY_BCR_AUTONEG_EN (0x1000) +#define PHY_BCR_POWER_DOWN (0x0800U) + +#undef PHY_BSR +#define PHY_BSR (0x0001) +#define PHY_BSR_LINK_STATUS (0x0004) +#define PHY_BSR_AUTONEG_DONE (0x0020) + +#undef PHY_ANAR +#define PHY_ANAR (0x0004) +#define PHY_ANAR_SPEED_10HALF (0x0020) +#define PHY_ANAR_SPEED_10FULL (0x0040) +#define PHY_ANAR_SPEED_100HALF (0x0080) +#define PHY_ANAR_SPEED_100FULL (0x0100) +#define PHY_ANAR_IEEE802_3 (0x0001) + +#define PHY_SPEED_10HALF (1) +#define PHY_SPEED_10FULL (5) +#define PHY_SPEED_100HALF (2) +#define PHY_SPEED_100FULL (6) +#define PHY_DUPLEX (4) + +uint32_t eth_phy_read(uint32_t phy_addr, uint32_t reg); +void eth_phy_write(uint32_t phy_addr, uint32_t reg, uint32_t val); + +int16_t eth_phy_lan87xx_get_link_status(uint32_t phy_addr); +int16_t eth_phy_dp838xx_get_link_status(uint32_t phy_addr); + +#endif + +#endif // MICROPY_INCLUDED_STM32_PHY_H diff --git a/ports/stm32/network_lan.c b/ports/stm32/network_lan.c index efdd354fb3a64..27f3e1337e693 100644 --- a/ports/stm32/network_lan.c +++ b/ports/stm32/network_lan.c @@ -54,16 +54,19 @@ static void network_lan_print(const mp_print_t *print, mp_obj_t self_in, mp_prin } static mp_obj_t network_lan_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - enum { ARG_phy_addr}; + enum { ARG_phy_addr, ARG_phy_type}; static const mp_arg_t allowed_args[] = { { MP_QSTR_phy_addr, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, + { MP_QSTR_phy_type, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = ETH_PHY_LAN8742} }, }; // Parse args. mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); const network_lan_obj_t *self = &network_lan_eth0; - eth_init(self->eth, MP_HAL_MAC_ETH0, args[ARG_phy_addr].u_int); + if (eth_init(self->eth, MP_HAL_MAC_ETH0, args[ARG_phy_addr].u_int, args[ARG_phy_type].u_int) != 0) { + mp_raise_ValueError(MP_ERROR_TEXT("invalid phy_type")); + } return MP_OBJ_FROM_PTR(self); } @@ -162,6 +165,11 @@ static const mp_rom_map_elem_t network_lan_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&network_lan_ifconfig_obj) }, { MP_ROM_QSTR(MP_QSTR_status), MP_ROM_PTR(&network_lan_status_obj) }, { MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&network_lan_config_obj) }, + + { MP_ROM_QSTR(MP_QSTR_PHY_LAN8742), MP_ROM_INT(ETH_PHY_LAN8742) }, + { MP_ROM_QSTR(MP_QSTR_PHY_LAN8720), MP_ROM_INT(ETH_PHY_LAN8720) }, + { MP_ROM_QSTR(MP_QSTR_PHY_DP83848), MP_ROM_INT(ETH_PHY_DP83848) }, + { MP_ROM_QSTR(MP_QSTR_PHY_DP83825), MP_ROM_INT(ETH_PHY_DP83825) }, }; static MP_DEFINE_CONST_DICT(network_lan_locals_dict, network_lan_locals_dict_table); From 5fe99013b6a58d6743706c5d76a1dbad133c300a Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Tue, 20 Feb 2024 12:48:04 +1100 Subject: [PATCH 186/408] stm32: Simplify D-cache clean and invalidate macros. The inline functions that these are wrappers around already account for cache line size. Signed-off-by: Angus Gratton --- ports/stm32/mpconfigboard_common.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ports/stm32/mpconfigboard_common.h b/ports/stm32/mpconfigboard_common.h index 6d9ef8de3b09f..16ee01b67bd9b 100644 --- a/ports/stm32/mpconfigboard_common.h +++ b/ports/stm32/mpconfigboard_common.h @@ -632,12 +632,12 @@ // D-cache clean/invalidate helpers #if __DCACHE_PRESENT == 1 -#define MP_HAL_CLEANINVALIDATE_DCACHE(addr, size) \ - (SCB_CleanInvalidateDCache_by_Addr((uint32_t *)((uint32_t)addr & ~0x1f), \ - ((uint32_t)((uint8_t *)addr + size + 0x1f) & ~0x1f) - ((uint32_t)addr & ~0x1f))) -#define MP_HAL_CLEAN_DCACHE(addr, size) \ - (SCB_CleanDCache_by_Addr((uint32_t *)((uint32_t)addr & ~0x1f), \ - ((uint32_t)((uint8_t *)addr + size + 0x1f) & ~0x1f) - ((uint32_t)addr & ~0x1f))) +// Note: The SCB_Clean<...> functions automatically align their arguments to cover full cache lines. +// CLEANINVALIDATE will write back (flush) any dirty lines in this region to RAM, then +// invalidate (evict) the whole region from the cache. +#define MP_HAL_CLEANINVALIDATE_DCACHE(addr, size) SCB_CleanInvalidateDCache_by_Addr((volatile void *)(addr), (size)) +// CLEAN will write back (flush) any dirty lines in this region to RAM. +#define MP_HAL_CLEAN_DCACHE(addr, size) SCB_CleanDCache_by_Addr((volatile void *)(addr), (size)) #else #define MP_HAL_CLEANINVALIDATE_DCACHE(addr, size) #define MP_HAL_CLEAN_DCACHE(addr, size) From 2345c1a04e6d8f8a7376c2c37c0f5248f7629bbb Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 21 Feb 2024 12:31:11 +1100 Subject: [PATCH 187/408] stm32/mpu: Rename MPU_CONFIG_DISABLE to MPU_CONFIG_NOACCESS. The existing MPU_CONFIG_DISABLE macro enables the MPU region but disables all access to it. The rename is necessary to support an MPU_CONFIG_DISABLE macro that actually disables the MPU region entirely. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- ports/stm32/mpu.h | 7 ++++++- ports/stm32/qspi.c | 34 +++++++++++++++++----------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/ports/stm32/mpu.h b/ports/stm32/mpu.h index e260b502199c0..62a428198ef9f 100644 --- a/ports/stm32/mpu.h +++ b/ports/stm32/mpu.h @@ -37,7 +37,12 @@ #define MPU_REGION_SDRAM1 (MPU_REGION_NUMBER4) #define MPU_REGION_SDRAM2 (MPU_REGION_NUMBER5) -#define MPU_CONFIG_DISABLE(srd, size) ( \ +// Attribute value to disable a region entirely, remove it from the MPU +// (i.e. the MPU_REGION_ENABLE bit is unset.) +#define MPU_CONFIG_DISABLE 0 + +// Configure a region with all access disabled. Can also set a Subregion Disable mask. +#define MPU_CONFIG_NOACCESS(srd, size) ( \ MPU_INSTRUCTION_ACCESS_DISABLE << MPU_RASR_XN_Pos \ | MPU_REGION_NO_ACCESS << MPU_RASR_AP_Pos \ | MPU_TEX_LEVEL0 << MPU_RASR_TEX_Pos \ diff --git a/ports/stm32/qspi.c b/ports/stm32/qspi.c index a560f8fb6265d..98364db41d4fb 100644 --- a/ports/stm32/qspi.c +++ b/ports/stm32/qspi.c @@ -68,7 +68,7 @@ static inline void qspi_mpu_disable_all(void) { // Configure MPU to disable access to entire QSPI region, to prevent CPU // speculative execution from accessing this region and modifying QSPI registers. uint32_t irq_state = mpu_config_start(); - mpu_config_region(MPU_REGION_QSPI1, QSPI_MAP_ADDR, MPU_CONFIG_DISABLE(0x00, MPU_REGION_SIZE_256MB)); + mpu_config_region(MPU_REGION_QSPI1, QSPI_MAP_ADDR, MPU_CONFIG_NOACCESS(0x00, MPU_REGION_SIZE_256MB)); mpu_config_end(irq_state); } @@ -84,30 +84,30 @@ static inline void qspi_mpu_enable_mapped(void) { // unprivileged or the background region is disabled, the MPU issues a fault. uint32_t irq_state = mpu_config_start(); #if MICROPY_HW_QSPI_MPU_REGION_SIZE > 128 - mpu_config_region(MPU_REGION_QSPI1, QSPI_MAP_ADDR, MPU_CONFIG_DISABLE(0xFF, MPU_REGION_SIZE_256MB)); + mpu_config_region(MPU_REGION_QSPI1, QSPI_MAP_ADDR, MPU_CONFIG_NOACCESS(0xFF, MPU_REGION_SIZE_256MB)); #elif MICROPY_HW_QSPI_MPU_REGION_SIZE > 64 - mpu_config_region(MPU_REGION_QSPI1, QSPI_MAP_ADDR, MPU_CONFIG_DISABLE(0x0F, MPU_REGION_SIZE_256MB)); + mpu_config_region(MPU_REGION_QSPI1, QSPI_MAP_ADDR, MPU_CONFIG_NOACCESS(0x0F, MPU_REGION_SIZE_256MB)); #elif MICROPY_HW_QSPI_MPU_REGION_SIZE > 32 - mpu_config_region(MPU_REGION_QSPI1, QSPI_MAP_ADDR, MPU_CONFIG_DISABLE(0x03, MPU_REGION_SIZE_256MB)); + mpu_config_region(MPU_REGION_QSPI1, QSPI_MAP_ADDR, MPU_CONFIG_NOACCESS(0x03, MPU_REGION_SIZE_256MB)); #elif MICROPY_HW_QSPI_MPU_REGION_SIZE > 16 - mpu_config_region(MPU_REGION_QSPI1, QSPI_MAP_ADDR, MPU_CONFIG_DISABLE(0x01, MPU_REGION_SIZE_256MB)); + mpu_config_region(MPU_REGION_QSPI1, QSPI_MAP_ADDR, MPU_CONFIG_NOACCESS(0x01, MPU_REGION_SIZE_256MB)); #elif MICROPY_HW_QSPI_MPU_REGION_SIZE > 8 - mpu_config_region(MPU_REGION_QSPI1, QSPI_MAP_ADDR, MPU_CONFIG_DISABLE(0x01, MPU_REGION_SIZE_256MB)); - mpu_config_region(MPU_REGION_QSPI2, QSPI_MAP_ADDR, MPU_CONFIG_DISABLE(0x0F, MPU_REGION_SIZE_32MB)); + mpu_config_region(MPU_REGION_QSPI1, QSPI_MAP_ADDR, MPU_CONFIG_NOACCESS(0x01, MPU_REGION_SIZE_256MB)); + mpu_config_region(MPU_REGION_QSPI2, QSPI_MAP_ADDR, MPU_CONFIG_NOACCESS(0x0F, MPU_REGION_SIZE_32MB)); #elif MICROPY_HW_QSPI_MPU_REGION_SIZE > 4 - mpu_config_region(MPU_REGION_QSPI1, QSPI_MAP_ADDR, MPU_CONFIG_DISABLE(0x01, MPU_REGION_SIZE_256MB)); - mpu_config_region(MPU_REGION_QSPI2, QSPI_MAP_ADDR, MPU_CONFIG_DISABLE(0x03, MPU_REGION_SIZE_32MB)); + mpu_config_region(MPU_REGION_QSPI1, QSPI_MAP_ADDR, MPU_CONFIG_NOACCESS(0x01, MPU_REGION_SIZE_256MB)); + mpu_config_region(MPU_REGION_QSPI2, QSPI_MAP_ADDR, MPU_CONFIG_NOACCESS(0x03, MPU_REGION_SIZE_32MB)); #elif MICROPY_HW_QSPI_MPU_REGION_SIZE > 2 - mpu_config_region(MPU_REGION_QSPI1, QSPI_MAP_ADDR, MPU_CONFIG_DISABLE(0x01, MPU_REGION_SIZE_256MB)); - mpu_config_region(MPU_REGION_QSPI2, QSPI_MAP_ADDR, MPU_CONFIG_DISABLE(0x01, MPU_REGION_SIZE_32MB)); + mpu_config_region(MPU_REGION_QSPI1, QSPI_MAP_ADDR, MPU_CONFIG_NOACCESS(0x01, MPU_REGION_SIZE_256MB)); + mpu_config_region(MPU_REGION_QSPI2, QSPI_MAP_ADDR, MPU_CONFIG_NOACCESS(0x01, MPU_REGION_SIZE_32MB)); #elif MICROPY_HW_QSPI_MPU_REGION_SIZE > 1 - mpu_config_region(MPU_REGION_QSPI1, QSPI_MAP_ADDR, MPU_CONFIG_DISABLE(0x01, MPU_REGION_SIZE_256MB)); - mpu_config_region(MPU_REGION_QSPI2, QSPI_MAP_ADDR, MPU_CONFIG_DISABLE(0x0F, MPU_REGION_SIZE_32MB)); - mpu_config_region(MPU_REGION_QSPI3, QSPI_MAP_ADDR, MPU_CONFIG_DISABLE(0x01, MPU_REGION_SIZE_16MB)); + mpu_config_region(MPU_REGION_QSPI1, QSPI_MAP_ADDR, MPU_CONFIG_NOACCESS(0x01, MPU_REGION_SIZE_256MB)); + mpu_config_region(MPU_REGION_QSPI2, QSPI_MAP_ADDR, MPU_CONFIG_NOACCESS(0x0F, MPU_REGION_SIZE_32MB)); + mpu_config_region(MPU_REGION_QSPI3, QSPI_MAP_ADDR, MPU_CONFIG_NOACCESS(0x01, MPU_REGION_SIZE_16MB)); #else - mpu_config_region(MPU_REGION_QSPI1, QSPI_MAP_ADDR, MPU_CONFIG_DISABLE(0x01, MPU_REGION_SIZE_256MB)); - mpu_config_region(MPU_REGION_QSPI2, QSPI_MAP_ADDR, MPU_CONFIG_DISABLE(0x01, MPU_REGION_SIZE_32MB)); - mpu_config_region(MPU_REGION_QSPI3, QSPI_MAP_ADDR, MPU_CONFIG_DISABLE(0x03, MPU_REGION_SIZE_4MB)); + mpu_config_region(MPU_REGION_QSPI1, QSPI_MAP_ADDR, MPU_CONFIG_NOACCESS(0x01, MPU_REGION_SIZE_256MB)); + mpu_config_region(MPU_REGION_QSPI2, QSPI_MAP_ADDR, MPU_CONFIG_NOACCESS(0x01, MPU_REGION_SIZE_32MB)); + mpu_config_region(MPU_REGION_QSPI3, QSPI_MAP_ADDR, MPU_CONFIG_NOACCESS(0x03, MPU_REGION_SIZE_4MB)); #endif mpu_config_end(irq_state); } From 7fd8a6d4bced2fcad11b30189e1fba4c32eaafc5 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Tue, 20 Feb 2024 12:14:44 +1100 Subject: [PATCH 188/408] stm32/dma: Add D-cache protection for DMA RX operations, including SPI. This new DMA API corrects possible cache coherency issues on chips with D-Cache, when working with buffers at arbitrary memory locations (i.e. supplied by Python code). The API is used by SPI to fix an issue with corrupt data when reading from SPI using DMA in certain cases. A regression test is included (it depends on external hardware connection). Explanation: 1) It's necessary to invalidate D-Cache after a DMA RX operation completes in case the CPU reads (or speculatively reads) from the DMA RX region during the operation. This seems to have been the root cause of issue #13471 (only when src==dest for this case). 2) More generally, it is also necessary to temporarily mark the first and last cache lines of a DMA RX operation as "uncached", in case the DMA buffer shares this cache line with unrelated data. The CPU could otherwise write the other data at any time during the DMA operation (for example from an interrupt handler), creating a dirty cache line that's inconsistent with the DMA result. Fixes issue #13471. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- ports/stm32/dma.c | 53 +++++++++++++++++++ ports/stm32/dma.h | 38 +++++++++++++ ports/stm32/mpu.h | 16 ++++++ ports/stm32/spi.c | 8 ++- tests/ports/stm32_hardware/dma_alignment.py | 43 +++++++++++++++ .../ports/stm32_hardware/dma_alignment.py.exp | 2 + 6 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 tests/ports/stm32_hardware/dma_alignment.py create mode 100644 tests/ports/stm32_hardware/dma_alignment.py.exp diff --git a/ports/stm32/dma.c b/ports/stm32/dma.c index af56d812367c7..df8a408cbf8ba 100644 --- a/ports/stm32/dma.c +++ b/ports/stm32/dma.c @@ -33,6 +33,7 @@ #include "systick.h" #include "dma.h" #include "irq.h" +#include "mpu.h" // When this option is enabled, the DMA will turn off automatically after // a period of inactivity. @@ -1852,3 +1853,55 @@ void dma_external_acquire(uint32_t controller, uint32_t stream) { void dma_external_release(uint32_t controller, uint32_t stream) { dma_disable_clock(DMA_ID_FROM_CONTROLLER_STREAM(controller, stream)); } + +#if __DCACHE_PRESENT + +void dma_protect_rx_region(void *dest, size_t len) { + #if __DCACHE_PRESENT + uint32_t start_addr = (uint32_t)dest; + uint32_t start_aligned = start_addr & ~(__SCB_DCACHE_LINE_SIZE - 1U); + uint32_t end_addr = start_addr + len - 1; // Address of last byte in the buffer + uint32_t end_aligned = end_addr & ~(__SCB_DCACHE_LINE_SIZE - 1U); + + uint32_t irq_state = mpu_config_start(); + + // Clean (write back) any cached memory in this region, so there's no dirty + // cache entries that might be written back later after DMA RX is done. + MP_HAL_CLEAN_DCACHE(dest, len); + + // The way we protect the whole region is to mark the first and last cache + // line as UNCACHED using the MPU. This means any unrelated reads/writes in + // these cache lines will bypass the cache, and can coexist with DMA also + // writing to parts of these cache lines. + // + // This is redundant sometimes (because the DMA region fills the entire cache line, or because + // the region fits in a single cache line.) However, the implementation is only 3 register writes so + // it's more efficient to call it every time. + mpu_config_region(MPU_REGION_DMA_UNCACHED_1, start_aligned, MPU_CONFIG_UNCACHED(MPU_REGION_SIZE_32B)); + mpu_config_region(MPU_REGION_DMA_UNCACHED_2, end_aligned, MPU_CONFIG_UNCACHED(MPU_REGION_SIZE_32B)); + + mpu_config_end(irq_state); + #endif +} + +void dma_unprotect_rx_region(void *dest, size_t len) { + #if __DCACHE_PRESENT + uint32_t irq_state = mpu_config_start(); + + // Disabling these regions removes them from the MPU + mpu_config_region(MPU_REGION_DMA_UNCACHED_1, 0, MPU_CONFIG_DISABLE); + mpu_config_region(MPU_REGION_DMA_UNCACHED_2, 0, MPU_CONFIG_DISABLE); + + // Invalidate the whole region in the cache. This may seem redundant, but it + // is possible that during the DMA operation the CPU read inside this region + // (excluding the first & last cache lines), and cache lines were filled. + // + // (This can happen in SPI if src==dest, for example, possibly due to speculative + // cache line fills.) + MP_HAL_CLEANINVALIDATE_DCACHE(dest, len); + + mpu_config_end(irq_state); + #endif +} + +#endif diff --git a/ports/stm32/dma.h b/ports/stm32/dma.h index fa3238413ea49..7ba04baf520ba 100644 --- a/ports/stm32/dma.h +++ b/ports/stm32/dma.h @@ -26,6 +26,8 @@ #ifndef MICROPY_INCLUDED_STM32_DMA_H #define MICROPY_INCLUDED_STM32_DMA_H +#include "py/mpconfig.h" + typedef struct _dma_descr_t dma_descr_t; #if defined(STM32H5) @@ -164,4 +166,40 @@ void dma_nohal_start(const dma_descr_t *descr, uint32_t src_addr, uint32_t dst_a void dma_external_acquire(uint32_t controller, uint32_t stream); void dma_external_release(uint32_t controller, uint32_t stream); +#if __DCACHE_PRESENT +// On chips with D-Cache, it's necessary to call this function before using DMA to read +// into a user-supplied buffer. It does two things: +// +// 1) Cleans this region in the cache. +// +// 2) Temporarily disables caching for the first and last cache lines of the +// buffer. This prevents cache coherency issues if the start or end of the +// buffer don't align to a cache line. (For example, this can happen if the CPU +// accesses unrelated memory adjacent to the buffer and in the same cache +// line.) +// +// Only one region can be protected in this way at a time. +void dma_protect_rx_region(void *dest, size_t len); + +// Release the region protected by dma_protect_rx_region(). +// +// Call this after the DMA operation completes, before the CPU reads any of the +// data that was written. +// +// As well as restoring data caching, this function invalidates D-cache for the +// entire specified region. +void dma_unprotect_rx_region(void *dest, size_t len); + +#else + +inline static void dma_protect_rx_region(uint8_t *dest, size_t len) { + // No-ops on targets without D-Cache. +} + +inline static void dma_unprotect_rx_region(void *dest, size_t len) { + +} + +#endif // __DCACHE_PRESENT + #endif // MICROPY_INCLUDED_STM32_DMA_H diff --git a/ports/stm32/mpu.h b/ports/stm32/mpu.h index 62a428198ef9f..64880a85db75f 100644 --- a/ports/stm32/mpu.h +++ b/ports/stm32/mpu.h @@ -37,6 +37,10 @@ #define MPU_REGION_SDRAM1 (MPU_REGION_NUMBER4) #define MPU_REGION_SDRAM2 (MPU_REGION_NUMBER5) +// Only relevant on CPUs with D-Cache, must be higher priority than SDRAM +#define MPU_REGION_DMA_UNCACHED_1 (MPU_REGION_NUMBER6) +#define MPU_REGION_DMA_UNCACHED_2 (MPU_REGION_NUMBER7) + // Attribute value to disable a region entirely, remove it from the MPU // (i.e. the MPU_REGION_ENABLE bit is unset.) #define MPU_CONFIG_DISABLE 0 @@ -78,6 +82,18 @@ | MPU_REGION_ENABLE << MPU_RASR_ENABLE_Pos \ ) +#define MPU_CONFIG_UNCACHED(size) ( \ + MPU_INSTRUCTION_ACCESS_DISABLE << MPU_RASR_XN_Pos \ + | MPU_REGION_FULL_ACCESS << MPU_RASR_AP_Pos \ + | MPU_TEX_LEVEL1 << MPU_RASR_TEX_Pos \ + | MPU_ACCESS_NOT_SHAREABLE << MPU_RASR_S_Pos \ + | MPU_ACCESS_NOT_CACHEABLE << MPU_RASR_C_Pos \ + | MPU_ACCESS_NOT_BUFFERABLE << MPU_RASR_B_Pos \ + | 0x00 << MPU_RASR_SRD_Pos \ + | (size) << MPU_RASR_SIZE_Pos \ + | MPU_REGION_ENABLE << MPU_RASR_ENABLE_Pos \ + ) + static inline void mpu_init(void) { MPU->CTRL = MPU_PRIVILEGED_DEFAULT | MPU_CTRL_ENABLE_Msk; SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk; diff --git a/ports/stm32/spi.c b/ports/stm32/spi.c index 5aace8e9a3e1f..607b3fe685a4c 100644 --- a/ports/stm32/spi.c +++ b/ports/stm32/spi.c @@ -571,6 +571,8 @@ void spi_transfer(const spi_t *self, size_t len, const uint8_t *src, uint8_t *de // Note: DMA transfers are limited to 65535 bytes at a time. HAL_StatusTypeDef status; + void *odest = dest; // Original values of dest & len + size_t olen = len; if (dest == NULL) { // send only @@ -613,7 +615,7 @@ void spi_transfer(const spi_t *self, size_t len, const uint8_t *src, uint8_t *de } dma_init(&rx_dma, self->rx_dma_descr, DMA_PERIPH_TO_MEMORY, self->spi); self->spi->hdmarx = &rx_dma; - MP_HAL_CLEANINVALIDATE_DCACHE(dest, len); + dma_protect_rx_region(dest, len); uint32_t t_start = HAL_GetTick(); do { uint32_t l = MIN(len, 65535); @@ -632,6 +634,7 @@ void spi_transfer(const spi_t *self, size_t len, const uint8_t *src, uint8_t *de dma_deinit(self->tx_dma_descr); } dma_deinit(self->rx_dma_descr); + dma_unprotect_rx_region(odest, olen); } } else { // send and receive @@ -644,7 +647,7 @@ void spi_transfer(const spi_t *self, size_t len, const uint8_t *src, uint8_t *de dma_init(&rx_dma, self->rx_dma_descr, DMA_PERIPH_TO_MEMORY, self->spi); self->spi->hdmarx = &rx_dma; MP_HAL_CLEAN_DCACHE(src, len); - MP_HAL_CLEANINVALIDATE_DCACHE(dest, len); + dma_protect_rx_region(dest, len); uint32_t t_start = HAL_GetTick(); do { uint32_t l = MIN(len, 65535); @@ -662,6 +665,7 @@ void spi_transfer(const spi_t *self, size_t len, const uint8_t *src, uint8_t *de } while (len); dma_deinit(self->tx_dma_descr); dma_deinit(self->rx_dma_descr); + dma_unprotect_rx_region(odest, olen); } } diff --git a/tests/ports/stm32_hardware/dma_alignment.py b/tests/ports/stm32_hardware/dma_alignment.py new file mode 100644 index 0000000000000..1836b25d86d53 --- /dev/null +++ b/tests/ports/stm32_hardware/dma_alignment.py @@ -0,0 +1,43 @@ +from machine import SPI +# Regression test for DMA for DCache coherency bugs with cache line +# written originally for https://github.com/micropython/micropython/issues/13471 + +# IMPORTANT: This test requires SPI2 MISO (pin Y8 on Pyboard D) to be connected to GND + +SPI_NUM = 2 + +spi = SPI(SPI_NUM, baudrate=5_000_000) +buf = bytearray(1024) +ok = True + +for offs in range(0, len(buf)): + v = memoryview(buf)[offs : offs + 128] + spi.readinto(v, 0xFF) + if not all(b == 0x00 for b in v): + print(offs, v.hex()) + ok = False + +print("Variable offset fixed length " + ("OK" if ok else "FAIL")) + +# this takes around 30s to run, so skipped if already failing +if ok: + for op_len in range(1, 66): + wr = b"\xFF" * op_len + for offs in range(1, len(buf) - op_len - 1): + # Place some "sentinel" values before and after the DMA buffer + before = offs & 0xFF + after = (~offs) & 0xFF + buf[offs - 1] = before + buf[offs + op_len] = after + v = memoryview(buf)[offs : offs + op_len] + spi.write_readinto(wr, v) + if ( + not all(b == 0x00 for b in v) + or buf[offs - 1] != before + or buf[offs + op_len] != after + ): + print(v.hex()) + print(hex(op_len), hex(offs), hex(buf[offs - 1]), hex(buf[offs + op_len])) + ok = False + + print("Variable offset and lengths " + ("OK" if ok else "FAIL")) diff --git a/tests/ports/stm32_hardware/dma_alignment.py.exp b/tests/ports/stm32_hardware/dma_alignment.py.exp new file mode 100644 index 0000000000000..e890e0081c4b7 --- /dev/null +++ b/tests/ports/stm32_hardware/dma_alignment.py.exp @@ -0,0 +1,2 @@ +Variable offset fixed length OK +Variable offset and lengths OK From a9efffca96d321a09829bbba4de558f1ca718800 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 27 Feb 2024 16:57:18 +1100 Subject: [PATCH 189/408] stm32: Add support for dual-analog-pad "_C" pins on H7 MCUs. This commit adds support for the dual-analog-pads on STM32H7 parts. These pads/pins are called PA0_C/PA1_C/PC2_C/PC3_C in the datasheet. They each have an analog switch that can optionally connect them to their normal pin (eg PA0). When the switch is open, the normal and _C pin are independent pins/pads. The approach taken in this commit to make these _C pins available to Python is: - put them in their own, independent row in the stm32h7_af.csv definition file, with only the ADC column defined (they are separate machine.Pin entities, and doing it this way keeps make-pins.py pretty clean) - allow a board to reference these pins in the board's pins.csv file by the name PA0_C etc (so a board can alias them, for example) - these pins (when enabled in pins.csv) now become available like any other machine.Pin through both machine.Pin.board and machine.Pin.cpu - BUT these _C pins have a separate pin type which doesn't have any methods, because they don't have any functionality - these _C pins can be used with machine.ADC to construct the appropriate ADC object, either by passing the string as machine.ADC("PA0_C") or by passing the object as machine.ADC(machine.Pin.cpu.PA0_C) - if a board defines both the normal and _C pin (eg both PA0 and PA0_C) in pins.csv then it must not define the analog switch to be closed (this is a sanity check for the build, because it doesn't make sense to close the switch and have two separate pins) Signed-off-by: Damien George --- ports/stm32/boards/make-pins.py | 18 ++++++----- ports/stm32/boards/stm32f4xx_prefix.c | 18 +++++++++++ ports/stm32/boards/stm32h723_af.csv | 6 ++-- ports/stm32/boards/stm32h743_af.csv | 12 +++++--- ports/stm32/boards/stm32h7b3_af.csv | 12 +++++--- ports/stm32/mpconfigboard_common.h | 9 ++++++ ports/stm32/pin.c | 44 ++++++++++++++++++++++++++- ports/stm32/pin.h | 1 + 8 files changed, 101 insertions(+), 19 deletions(-) diff --git a/ports/stm32/boards/make-pins.py b/ports/stm32/boards/make-pins.py index bfa22d7974967..8fb442153fad9 100755 --- a/ports/stm32/boards/make-pins.py +++ b/ports/stm32/boards/make-pins.py @@ -59,6 +59,12 @@ class Stm32Pin(boardgen.Pin): def __init__(self, cpu_pin_name): super().__init__(cpu_pin_name) + # Pins ending in "_C" correspond to the analog-only pad of a pair + # of dual (analog) pads found on H7 MCUs (eg PA0 and PA0_C pair). + self._analog_only = cpu_pin_name.endswith("_C") + if self._analog_only: + cpu_pin_name = cpu_pin_name[:-2] + # P (already verified by validate_cpu_pin_name). self._port = cpu_pin_name[1] self._pin = int(cpu_pin_name[2:]) @@ -129,11 +135,6 @@ def add_adc(self, adc): # be the P for one channel, and the N for a different channel. # e.g. "ADC123_INP12/ADC123_INN11". for adc_name in adc.split("/"): - if adc_name.startswith("C_"): - # Currently unsupported, H7 dual-pad. The C_ADC entries should - # only be available directly from machine.ADC (not via the pin - # object). - continue m = re.match("ADC([1-5]+)_(IN[NP]?)([0-9]+)$", adc_name) if not m: raise boardgen.PinGeneratorError( @@ -167,8 +168,9 @@ def definition(self): ) # PIN(p_port, p_pin, p_af, p_adc_num, p_adc_channel) - return "PIN({:s}, {:d}, pin_{:s}_af, {:s}, {:d})".format( - self._port, self._pin, self.name(), adc_units_bitfield, self._adc_channel + pin_macro = "PIN_ANALOG" if self._analog_only else "PIN" + return "{:s}({:s}, {:d}, pin_{:s}_af, {:s}, {:d})".format( + pin_macro, self._port, self._pin, self.name(), adc_units_bitfield, self._adc_channel ) # This will be called at the start of the output (after the prefix). Use @@ -210,7 +212,7 @@ def print_source(self, out_source): def validate_cpu_pin_name(cpu_pin_name): boardgen.Pin.validate_cpu_pin_name(cpu_pin_name) - if not re.match("P[A-K][0-9]+$", cpu_pin_name): + if not re.match("P[A-K][0-9]+(_C)?$", cpu_pin_name): raise boardgen.PinGeneratorError("Invalid cpu pin name '{}'".format(cpu_pin_name)) diff --git a/ports/stm32/boards/stm32f4xx_prefix.c b/ports/stm32/boards/stm32f4xx_prefix.c index 99bf4473aa1a1..c06e366d712e2 100644 --- a/ports/stm32/boards/stm32f4xx_prefix.c +++ b/ports/stm32/boards/stm32f4xx_prefix.c @@ -30,3 +30,21 @@ .adc_num = p_adc_num, \ .adc_channel = p_adc_channel, \ } + +#if MICROPY_HW_ENABLE_ANALOG_ONLY_PINS +#define PIN_ANALOG(p_port, p_pin, p_af, p_adc_num, p_adc_channel) \ + { \ + { &pin_analog_type }, \ + .name = MP_QSTR_##p_port##p_pin##_C, \ + .port = PORT_##p_port, \ + .pin = (p_pin), \ + .num_af = (sizeof(p_af) / sizeof(pin_af_obj_t)), \ + .pin_mask = (1 << ((p_pin) & 0x0f)), \ + .gpio = GPIO##p_port, \ + .af = p_af, \ + .adc_num = p_adc_num, \ + .adc_channel = p_adc_channel, \ + } +#else +#define PIN_ANALOG DUAL_PAD_SUPPORT_NOT_ENABLED__CONFIGURE__MICROPY_HW_ANALOG_SWITCH_Pxy +#endif diff --git a/ports/stm32/boards/stm32h723_af.csv b/ports/stm32/boards/stm32h723_af.csv index 71873e670b3d0..bf360a13c9249 100644 --- a/ports/stm32/boards/stm32h723_af.csv +++ b/ports/stm32/boards/stm32h723_af.csv @@ -34,8 +34,10 @@ PortB,PB14, ,TIM1_CH2N ,TIM12_CH1 PortB,PB15,RTC_REFIN ,TIM1_CH3N ,TIM12_CH2 ,TIM8_CH3N ,USART1_RX ,SPI2_MOSI/I2S2_SDO ,DFSDM1_CKIN2 , ,UART4_CTS ,SDMMC2_D1 , , ,FMC_D11/FMC_AD11 , ,LCD_G7 ,EVENTOUT, PortC,PC0 , ,FMC_D12/FMC_AD12 , ,DFSDM1_CKIN0 , , ,DFSDM1_DATIN4 , ,SAI4_FS_B ,FMC_A25 ,OTG_HS_ULPI_STP ,LCD_G2 ,FMC_SDNWE , ,LCD_R5 ,EVENTOUT,ADC123_INP10 PortC,PC1 ,TRACED0 ,SAI4_D1 ,SAI1_D1 ,DFSDM1_DATIN0 ,DFSDM1_CKIN4 ,SPI2_MOSI/I2S2_SDO ,SAI1_SD_A , ,SAI4_SD_A ,SDMMC2_CK ,OCTOSPIM_P1_IO4 ,ETH_MDC ,MDIOS_MDC , ,LCD_G5 ,EVENTOUT,ADC123_INP11/ADC123_INN10 -PortC,PC2 ,PWR_DEEPSLEEP, , ,DFSDM1_CKIN1 ,OCTOSPIM_P1_IO5 ,SPI2_MISO/I2S2_SDI ,DFSDM1_CKOUT , , ,OCTOSPIM_P1_IO2 ,OTG_HS_ULPI_DIR ,ETH_MII_TXD2 ,FMC_SDNE0 , , ,EVENTOUT,ADC123_INP12/ADC123_INN11/C_ADC3_INN1/C_ADC3_INP0 -PortC,PC3 ,PWR_SLEEP , , ,DFSDM1_DATIN1 ,OCTOSPIM_P1_IO6 ,SPI2_MOSI/I2S2_SDO , , , ,OCTOSPIM_P1_IO0 ,OTG_HS_ULPI_NXT ,ETH_MII_TX_CLK ,FMC_SDCKE0 , , ,EVENTOUT,ADC12_INP13/ADC12_INN12/C_ADC3_INP1 +PortC,PC2 ,PWR_DEEPSLEEP, , ,DFSDM1_CKIN1 ,OCTOSPIM_P1_IO5 ,SPI2_MISO/I2S2_SDI ,DFSDM1_CKOUT , , ,OCTOSPIM_P1_IO2 ,OTG_HS_ULPI_DIR ,ETH_MII_TXD2 ,FMC_SDNE0 , , ,EVENTOUT,ADC123_INP12/ADC123_INN11 +PortC,PC2_C, , , , , , , , , , , , , , , , ,ADC3_INN1/ADC3_INP0 +PortC,PC3 ,PWR_SLEEP , , ,DFSDM1_DATIN1 ,OCTOSPIM_P1_IO6 ,SPI2_MOSI/I2S2_SDO , , , ,OCTOSPIM_P1_IO0 ,OTG_HS_ULPI_NXT ,ETH_MII_TX_CLK ,FMC_SDCKE0 , , ,EVENTOUT,ADC12_INP13/ADC12_INN12 +PortC,PC3_C, , , , , , , , , , , , , , , , ,ADC3_INP1 PortC,PC4 ,PWR_DEEPSLEEP,FMC_A22 , ,DFSDM1_CKIN2 , ,I2S1_MCK , , , ,SPDIFRX1_IN3 ,SDMMC2_CKIN ,ETH_MII_RXD0/ETH_RMII_RXD0 ,FMC_SDNE0 , ,LCD_R7 ,EVENTOUT,ADC12_INP4 PortC,PC5 ,PWR_SLEEP ,SAI4_D3 ,SAI1_D3 ,DFSDM1_DATIN2 ,PSSI_D15 , , , , ,SPDIFRX1_IN4 ,OCTOSPIM_P1_DQS ,ETH_MII_RXD1/ETH_RMII_RXD1 ,FMC_SDCKE0 ,COMP1_OUT ,LCD_DE ,EVENTOUT,ADC12_INP8/ADC12_INN4 PortC,PC6 , , ,TIM3_CH1 ,TIM8_CH1 ,DFSDM1_CKIN3 ,I2S2_MCK , ,USART6_TX ,SDMMC1_D0DIR ,FMC_NWAIT ,SDMMC2_D6 , ,SDMMC1_D6 ,DCMI_D0/PSSI_D0 ,LCD_HSYNC ,EVENTOUT, diff --git a/ports/stm32/boards/stm32h743_af.csv b/ports/stm32/boards/stm32h743_af.csv index 4a291265c48fb..2c43b80dfe582 100644 --- a/ports/stm32/boards/stm32h743_af.csv +++ b/ports/stm32/boards/stm32h743_af.csv @@ -1,7 +1,9 @@ Port ,Pin ,AF0 ,AF1 ,AF2 ,AF3 ,AF4 ,AF5 ,AF6 ,AF7 ,AF8 ,AF9 ,AF10 ,AF11 ,AF12 ,AF13 ,AF14 ,AF15 ,ADC , ,SYS ,TIM1/2/16/17/LPTIM1/HRTIM1,SAI1/TIM3/4/5/12/HRTIM1,LPUART/TIM8/LPTIM2/3/4/5/HRTIM1/DFSDM,I2C1/2/3/4/USART1/TIM15/LPTIM2/DFSDM/CEC,SPI1/2/3/4/5/6/CEC,SPI2/3/SAI1/3/I2C4/UART4/DFSDM,SPI2/3/6/USART1/2/3/6/UART7/SDMMC1,SPI6/SAI2/4/UART4/5/8/LPUART/SDMMC1/SPDIFRX,SAI4/FDCAN1/2/TIM13/14/QUADSPI/FMC/SDMMC2/LCD/SPDIFRX,SAI2/4/TIM8/QUADSPI/SDMMC2/OTG1_HS/OTG2_FS/LCD,I2C4/UART7/SWPMI1/TIM1/8/DFSDM/SDMMC2/MDIOS/ETH,TIM1/8/FMC/SDMMC1/MDIOS/OTG1_FS/LCD,TIM1/DCMI/LCD/COMP,UART5/LCD,SYS ,ADC -PortA,PA0 , ,TIM2_CH1/TIM2_ETR ,TIM5_CH1 ,TIM8_ETR ,TIM15_BKIN , , ,USART2_CTS/USART2_NSS ,UART4_TX ,SDMMC2_CMD ,SAI2_SD_B ,ETH_MII_CRS , , , ,EVENTOUT,ADC1_INP16/C_ADC12_INN1/C_ADC12_INP0 -PortA,PA1 , ,TIM2_CH2 ,TIM5_CH2 ,LPTIM3_OUT ,TIM15_CH1N , , ,USART2_RTS ,UART4_RX ,QUADSPI_BK1_IO3 ,SAI2_MCK_B ,ETH_MII_RX_CLK/ETH_RMII_REF_CLK , , ,LCD_R2 ,EVENTOUT,ADC1_INN16/ADC1_INP17/C_ADC12_INP1 +PortA,PA0 , ,TIM2_CH1/TIM2_ETR ,TIM5_CH1 ,TIM8_ETR ,TIM15_BKIN , , ,USART2_CTS/USART2_NSS ,UART4_TX ,SDMMC2_CMD ,SAI2_SD_B ,ETH_MII_CRS , , , ,EVENTOUT,ADC1_INP16 +PortA,PA0_C, , , , , , , , , , , , , , , , ,ADC12_INP0 +PortA,PA1 , ,TIM2_CH2 ,TIM5_CH2 ,LPTIM3_OUT ,TIM15_CH1N , , ,USART2_RTS ,UART4_RX ,QUADSPI_BK1_IO3 ,SAI2_MCK_B ,ETH_MII_RX_CLK/ETH_RMII_REF_CLK , , ,LCD_R2 ,EVENTOUT,ADC1_INN16/ADC1_INP17/ADC12_INP1 +PortA,PA1_C, , , , , , , , , , , , , , , , ,ADC12_INP1 PortA,PA2 , ,TIM2_CH3 ,TIM5_CH3 ,LPTIM4_OUT ,TIM15_CH1 , , ,USART2_TX ,SAI2_SCK_B , , ,ETH_MDIO ,MDIOS_MDIO , ,LCD_R1 ,EVENTOUT,ADC12_INP14 PortA,PA3 , ,TIM2_CH4 ,TIM5_CH4 ,LPTIM5_OUT ,TIM15_CH2 , , ,USART2_RX , ,LCD_B2 ,OTG_HS_ULPI_D0 ,ETH_MII_COL , , ,LCD_B5 ,EVENTOUT,ADC12_INP15 PortA,PA4 , , ,TIM5_ETR , , ,SPI1_NSS/I2S1_WS ,SPI3_NSS/I2S3_WS ,USART2_CK ,SPI6_NSS , , , ,OTG_HS_SOF ,DCMI_HSYNC ,LCD_VSYNC,EVENTOUT,ADC12_INP18 @@ -34,8 +36,10 @@ PortB,PB14, ,TIM1_CH2N ,TIM12_CH1 ,TIM8 PortB,PB15,RTC_REFIN ,TIM1_CH3N ,TIM12_CH2 ,TIM8_CH3N ,USART1_RX ,SPI2_MOSI/I2S2_SDO,DFSDM_CKIN2 , ,UART4_CTS ,SDMMC2_D1 , , ,OTG_HS_DP , , ,EVENTOUT, PortC,PC0 , , , ,DFSDM_CKIN0 , , ,DFSDM_DATIN4 , ,SAI2_FS_B , ,OTG_HS_ULPI_STP , ,FMC_SDNWE , ,LCD_R5 ,EVENTOUT,ADC123_INP10 PortC,PC1 ,TRACED0 , ,SAI1_D1 ,DFSDM_DATIN0 ,DFSDM_CKIN4 ,SPI2_MOSI/I2S2_SDO,SAI1_SD_A , ,SAI4_SD_A ,SDMMC2_CK ,SAI4_D1 ,ETH_MDC ,MDIOS_MDC , , ,EVENTOUT,ADC123_INN10/ADC123_INP11 -PortC,PC2 , , , ,DFSDM_CKIN1 , ,SPI2_MISO/I2S2_SDI,DFSDM_CKOUT , , , ,OTG_HS_ULPI_DIR ,ETH_MII_TXD2 ,FMC_SDNE0 , , ,EVENTOUT,ADC123_INN11/ADC123_INP12/C_ADC3_INN1/C_ADC3_INP0 -PortC,PC3 , , , ,DFSDM_DATIN1 , ,SPI2_MOSI/I2S2_SDO, , , , ,OTG_HS_ULPI_NXT ,ETH_MII_TX_CLK ,FMC_SDCKE0 , , ,EVENTOUT,ADC12_INN12/ADC12_INP13/C_ADC3_INP1 +PortC,PC2 , , , ,DFSDM_CKIN1 , ,SPI2_MISO/I2S2_SDI,DFSDM_CKOUT , , , ,OTG_HS_ULPI_DIR ,ETH_MII_TXD2 ,FMC_SDNE0 , , ,EVENTOUT,ADC123_INN11/ADC123_INP12 +PortC,PC2_C, , , , , , , , , , , , , , , , ,ADC3_INP0 +PortC,PC3 , , , ,DFSDM_DATIN1 , ,SPI2_MOSI/I2S2_SDO, , , , ,OTG_HS_ULPI_NXT ,ETH_MII_TX_CLK ,FMC_SDCKE0 , , ,EVENTOUT,ADC12_INN12/ADC12_INP13 +PortC,PC3_C, , , , , , , , , , , , , , , , ,ADC3_INP1 PortC,PC4 , , , ,DFSDM_CKIN2 , ,I2S1_MCK , , , ,SPDIFRX_IN2 , ,ETH_MII_RXD0/ETH_RMII_RXD0 ,FMC_SDNE0 , , ,EVENTOUT,ADC12_INP4 PortC,PC5 , , ,SAI1_D3 ,DFSDM_DATIN2 , , , , , ,SPDIFRX_IN3 ,SAI4_D3 ,ETH_MII_RXD1/ETH_RMII_RXD1 ,FMC_SDCKE0 ,COMP_1_OUT , ,EVENTOUT,ADC12_INN4/ADC12_INP8 PortC,PC6 , ,HRTIM_CHA1 ,TIM3_CH1 ,TIM8_CH1 ,DFSDM_CKIN3 ,I2S2_MCK , ,USART6_TX ,SDMMC1_D0DIR ,FMC_NWAIT ,SDMMC2_D6 , ,SDMMC1_D6 ,DCMI_D0 ,LCD_HSYNC,EVENTOUT, diff --git a/ports/stm32/boards/stm32h7b3_af.csv b/ports/stm32/boards/stm32h7b3_af.csv index 1acef21f37e56..f202f56c89bd9 100644 --- a/ports/stm32/boards/stm32h7b3_af.csv +++ b/ports/stm32/boards/stm32h7b3_af.csv @@ -1,7 +1,9 @@ Port ,Pin ,AF0 ,AF1 ,AF2 ,AF3 ,AF4 ,AF5 ,AF6 ,AF7 ,AF8 ,AF9 ,AF10 ,AF11 ,AF12 ,AF13 ,AF14 ,AF15 ,ADC , ,SYS ,LPTIM1/TIM1/2/16/17,PDM_SAI1/TIM3/4/5/12/15,DFSDM1/LPTIM2/3/LPUART1/OCTOSPIM_P1/2/TIM8,CEC/DCMI/PSSI/DFSDM1/2/I2C1/2/3/4/LPTIM2/TIM15/USART1,CEC/SPI1/I2S1/SPI2/I2S2/SPI3/I2S3/SPI4/5/SPI6/I2S6,DFSDM1/2/I2C4/OCTOSPIM_P1/SAI1/SPI3/I2S3/UART4,SDMMC1/SPI2/I2S2/SPI3/I2S3/SPI6/I2S6/UART7/USART1/2/3/6,LPUART1/SAI2/SDMMC1/SPDIFRX1/SPI6/I2S6/UART4/5/8,FDCAN1/2/FMC/LCD/OCTOSPIM_P1/2/SDMMC2/SPDIFRX1/TIM13/14,CRS/FMC/LCD/OCTOSPIM_P1/OTG1_FS/OTG1_HS/SAI2/SDMMC2/TIM8,DFSDM1/2/I2C4/LCD/MDIOS/OCTOSPIM_P1/SDMMC2/SWPMI1/TIM1/8/UART7/9/USART10,FMC/LCD/MDIOS/SDMMC1/TIM1/8 ,COMP/DCMI/PSSI/LCD/TIM1 ,LCD/UART5 ,SYS ,ADC -PortA,PA0 , ,TIM2_CH1/TIM2_ETR ,TIM5_CH1 ,TIM8_ETR ,TIM15_BKIN ,I2S6_WS/SPI6_NSS , ,USART2_CTS/USART2_NSS ,UART4_TX ,SDMMC2_CMD ,SAI2_SD_B , , , , ,EVENTOUT,ADC1_INP16/C_ADC1_INP0/C_ADC1_INN1 -PortA,PA1 , ,TIM2_CH2 ,TIM5_CH2 ,LPTIM3_OUT ,TIM15_CH1N , , ,USART2_DE/USART2_RTS ,UART4_RX ,OCTOSPIM_P1_IO3 ,SAI2_MCLK_B ,OCTOSPIM_P1_DQS , , ,LTDC_R2 ,EVENTOUT,ADC1_INN16/ADC1_INP17/C_ADC1_INP1 +PortA,PA0 , ,TIM2_CH1/TIM2_ETR ,TIM5_CH1 ,TIM8_ETR ,TIM15_BKIN ,I2S6_WS/SPI6_NSS , ,USART2_CTS/USART2_NSS ,UART4_TX ,SDMMC2_CMD ,SAI2_SD_B , , , , ,EVENTOUT,ADC1_INP16 +PortA,PA0_C, , , , , , , , , , , , , , , , ,ADC1_INP0/ADC1_INN1 +PortA,PA1 , ,TIM2_CH2 ,TIM5_CH2 ,LPTIM3_OUT ,TIM15_CH1N , , ,USART2_DE/USART2_RTS ,UART4_RX ,OCTOSPIM_P1_IO3 ,SAI2_MCLK_B ,OCTOSPIM_P1_DQS , , ,LTDC_R2 ,EVENTOUT,ADC1_INN16/ADC1_INP17 +PortA,PA1_C, , , , , , , , , , , , , , , , ,ADC1_INP1 PortA,PA2 , ,TIM2_CH3 ,TIM5_CH3 , ,TIM15_CH1 , ,DFSDM2_CKIN1 ,USART2_TX ,SAI2_SCK_B , , , ,MDIOS_MDIO , ,LTDC_R1 ,EVENTOUT,ADC1_INP14 PortA,PA3 , ,TIM2_CH4 ,TIM5_CH4 ,OCTOSPIM_P1_CLK ,TIM15_CH2 ,I2S6_MCK , ,USART2_RX , ,LTDC_B2 ,USB_OTG_HS_ULPI_D0 , , , ,LTDC_B5 ,EVENTOUT,ADC1_INP15 PortA,PA4 , , ,TIM5_ETR , , ,I2S1_WS/SPI1_NSS ,I2S3_WS/SPI3_NSS ,USART2_CK ,I2S6_WS/SPI6_NSS , , , , ,DCMI_HSYNC/PSSI_DE ,LTDC_VSYNC,EVENTOUT,ADC1_INP18 @@ -34,8 +36,10 @@ PortB,PB14, ,TIM1_CH2N ,TIM12_CH1 ,TIM8_CH2 PortB,PB15,RTC_REFIN ,TIM1_CH3N ,TIM12_CH2 ,TIM8_CH3N ,USART1_RX ,I2S2_SDO/SPI2_MOSI ,DFSDM1_CKIN2 , ,UART4_CTS ,SDMMC2_D1 , , , , ,LTDC_G7 ,EVENTOUT, PortC,PC0 , , , ,DFSDM1_CKIN0 , , ,DFSDM1_DATIN4 , ,SAI2_FS_B ,FMC_A25 ,USB_OTG_HS_ULPI_STP ,LTDC_G2 ,FMC_SDNWE , ,LTDC_R5 ,EVENTOUT,ADC12_INP10 PortC,PC1 ,DEBUG_TRACED0 , ,SAI1_D1 ,DFSDM1_DATIN0 ,DFSDM1_CKIN4 ,I2S2_SDO/SPI2_MOSI ,SAI1_SD_A , , ,SDMMC2_CK ,OCTOSPIM_P1_IO4 , ,MDIOS_MDC , ,LTDC_G5 ,EVENTOUT,ADC12_INN10/ADC12_INP11 -PortC,PC2 ,PWR_CSTOP , , ,DFSDM1_CKIN1 , ,I2S2_SDI/SPI2_MISO ,DFSDM1_CKOUT , , ,OCTOSPIM_P1_IO2 ,USB_OTG_HS_ULPI_DIR ,OCTOSPIM_P1_IO5 ,FMC_SDNE0 , , ,EVENTOUT,ADC12_INN11/ADC12_INP12/C_ADC2_INP0/C_ADC2_INN1 -PortC,PC3 ,PWR_CSLEEP , , ,DFSDM1_DATIN1 , ,I2S2_SDO/SPI2_MOSI , , , ,OCTOSPIM_P1_IO0 ,USB_OTG_HS_ULPI_NXT ,OCTOSPIM_P1_IO6 ,FMC_SDCKE0 , , ,EVENTOUT,ADC12_INP13,ADC12_INN12/C_ADC2_INP1 +PortC,PC2 ,PWR_CSTOP , , ,DFSDM1_CKIN1 , ,I2S2_SDI/SPI2_MISO ,DFSDM1_CKOUT , , ,OCTOSPIM_P1_IO2 ,USB_OTG_HS_ULPI_DIR ,OCTOSPIM_P1_IO5 ,FMC_SDNE0 , , ,EVENTOUT,ADC12_INN11/ADC12_INP12 +PortC,PC2_C, , , , , , , , , , , , , , , , ,ADC2_INP0/ADC2_INN1 +PortC,PC3 ,PWR_CSLEEP , , ,DFSDM1_DATIN1 , ,I2S2_SDO/SPI2_MOSI , , , ,OCTOSPIM_P1_IO0 ,USB_OTG_HS_ULPI_NXT ,OCTOSPIM_P1_IO6 ,FMC_SDCKE0 , , ,EVENTOUT,ADC12_INP13,ADC12_INN12 +PortC,PC3_C, , , , , , , , , , , , , , , , ,ADC2_INP1 PortC,PC4 , , , ,DFSDM1_CKIN2 , ,I2S1_MCK , , , ,SPDIFRX_IN3 , , ,FMC_SDNE0 , ,LTDC_R7 ,EVENTOUT,ADC12_INP4 PortC,PC5 , , ,SAI1_D3 ,DFSDM1_DATIN2 ,PSSI_D15 , , , , ,SPDIFRX_IN4 ,OCTOSPIM_P1_DQS , ,FMC_SDCKE0 ,COMP1_OUT ,LTDC_DE ,EVENTOUT,ADC12_INN4/ADC12_INP8 PortC,PC6 , , ,TIM3_CH1 ,TIM8_CH1 ,DFSDM1_CKIN3 ,I2S2_MCK , ,USART6_TX ,SDMMC1_D0DIR ,FMC_NWAIT ,SDMMC2_D6 , ,SDMMC1_D6 ,DCMI_D0/PSSI_D0 ,LTDC_HSYNC,EVENTOUT, diff --git a/ports/stm32/mpconfigboard_common.h b/ports/stm32/mpconfigboard_common.h index 16ee01b67bd9b..67a6ee990e399 100644 --- a/ports/stm32/mpconfigboard_common.h +++ b/ports/stm32/mpconfigboard_common.h @@ -390,6 +390,15 @@ #define MICROPY_HW_MAX_UART (8) #define MICROPY_HW_MAX_LPUART (1) +#if defined(MICROPY_HW_ANALOG_SWITCH_PA0) \ + || defined(MICROPY_HW_ANALOG_SWITCH_PA1) \ + || defined(MICROPY_HW_ANALOG_SWITCH_PC2) \ + || defined(MICROPY_HW_ANALOG_SWITCH_PC3) +#define MICROPY_HW_ENABLE_ANALOG_ONLY_PINS (1) +#else +#define MICROPY_HW_ENABLE_ANALOG_ONLY_PINS (0) +#endif + // Configuration for STM32L0 series #elif defined(STM32L0) diff --git a/ports/stm32/pin.c b/ports/stm32/pin.c index 0b939334a2b6d..117a8366dbffe 100644 --- a/ports/stm32/pin.c +++ b/ports/stm32/pin.c @@ -103,7 +103,11 @@ const machine_pin_obj_t *pin_find(mp_obj_t user_obj) { const machine_pin_obj_t *pin_obj; // If a pin was provided, then use it - if (mp_obj_is_type(user_obj, &pin_type)) { + if (mp_obj_is_type(user_obj, &pin_type) + #if MICROPY_HW_ENABLE_ANALOG_ONLY_PINS + || mp_obj_is_type(user_obj, &pin_analog_type) + #endif + ) { pin_obj = MP_OBJ_TO_PTR(user_obj); if (pin_class_debug) { mp_printf(print, "Pin map passed pin "); @@ -601,6 +605,44 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &pin_locals_dict ); +/******************************************************************************/ +// Special analog-only pin. + +#if MICROPY_HW_ENABLE_ANALOG_ONLY_PINS + +// When both normal and _C pins are defined in pins.csv, force the corresponding +// analog switch to be open. The macro code below will produce a compiler warning +// if the board defines the switch as closed. +#if defined(pin_A0) && defined(pin_A0_C) +#define MICROPY_HW_ANALOG_SWITCH_PA0 (SYSCFG_SWITCH_PA0_OPEN) +#endif +#if defined(pin_A1) && defined(pin_A1_C) +#define MICROPY_HW_ANALOG_SWITCH_PA1 (SYSCFG_SWITCH_PA1_OPEN) +#endif +#if defined(pin_C2) && defined(pin_C2_C) +#define MICROPY_HW_ANALOG_SWITCH_PC2 (SYSCFG_SWITCH_PC2_OPEN) +#endif +#if defined(pin_C3) && defined(pin_C3_C) +#define MICROPY_HW_ANALOG_SWITCH_PC3 (SYSCFG_SWITCH_PC3_OPEN) +#endif + +static void pin_analog_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { + machine_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); + mp_printf(print, "Pin(Pin.cpu.%q, mode=Pin.ANALOG)", self->name); +} + +MP_DEFINE_CONST_OBJ_TYPE( + pin_analog_type, + MP_QSTR_Pin, + MP_TYPE_FLAG_NONE, + print, pin_analog_print + ); + +#endif + +/******************************************************************************/ +// PinAF class + /// \moduleref pyb /// \class PinAF - Pin Alternate Functions /// diff --git a/ports/stm32/pin.h b/ports/stm32/pin.h index d16c176380262..04479bd042f71 100644 --- a/ports/stm32/pin.h +++ b/ports/stm32/pin.h @@ -56,6 +56,7 @@ typedef struct { } machine_pin_obj_t; extern const mp_obj_type_t pin_type; +extern const mp_obj_type_t pin_analog_type; extern const mp_obj_type_t pin_af_type; // Include all of the individual pin objects From 32623d3d198c702085d8cede8c306bb61962bd9a Mon Sep 17 00:00:00 2001 From: Sebastian Romero Date: Mon, 29 Jan 2024 15:53:16 -0300 Subject: [PATCH 190/408] stm32/boards: Add named digital and analog pins for Arduino boardrs. Adds Dx and Ax named pins for Arduino Gigi, Arduino Nicla Vision and Arduino Portenta H7. The analog pins include the dual-pad _C pins. Signed-off-by: Sebastian Romero --- ports/stm32/boards/ARDUINO_GIGA/pins.csv | 122 +++++++++++++++++- .../boards/ARDUINO_NICLA_VISION/pins.csv | 24 ++++ .../stm32/boards/ARDUINO_PORTENTA_H7/pins.csv | 31 +++++ 3 files changed, 175 insertions(+), 2 deletions(-) diff --git a/ports/stm32/boards/ARDUINO_GIGA/pins.csv b/ports/stm32/boards/ARDUINO_GIGA/pins.csv index 9de1a316d1cd4..8a1f505aef5fa 100644 --- a/ports/stm32/boards/ARDUINO_GIGA/pins.csv +++ b/ports/stm32/boards/ARDUINO_GIGA/pins.csv @@ -166,6 +166,123 @@ PK4,PK4 PK5,PK5 PK6,PK6 PK7,PK7 + +# Arduino Digital Pins +D0,PB7 +D1,PA9 +D2,PA3 +D3,PA2 +D4,PJ8 +D5,PA7 +D6,PD13 +D7,PB4 +D8,PB8 +D9,PB9 +D10,PK1 +D11,PJ10 +D12,PJ11 +D13,PH6 +D14,PG14 +D15,PC7 +D16,PH13 +D17,PI9 +D18,PD5 +D19,PD6 +D20,PB11 +D21,PH4 +D22,PJ12 +D23,PG13 +D24,PG12 +D25,PJ0 +D26,PJ14 +D27,PJ1 +D28,PJ15 +D29,PJ2 +D30,PK3 +D31,PJ3 +D32,PK4 +D33,PJ4 +D34,PK5 +D35,PJ5 +D36,PK6 +D37,PJ6 +D38,PJ7 +D39,PI14 +D40,PE6 +D41,PK7 +D42,PI15 +D43,PI10 +D44,PG10 +D45,PI13 +D46,PH15 +D47,PB2 +D48,PK0 +D49,PE4 +D50,PI11 +D51,PE5 +D52,PK2 +D53,PG7 +D54,PI5 +D55,PH8 +D56,PA6 +D57,PJ9 +D58,PI7 +D59,PI6 +D60,PI4 +D61,PH14 +D62,PG11 +D63,PH11 +D64,PH10 +D65,PH9 +D66,PA1 +D67,PD4 +D68,PC6 +D69,PI0 +D70,PI1 +D71,PI2 +D72,PI3 +D73,PC1 +D74,PB12 +D75,PD3 +D76,PC4 +D77,PC5 +D78,PB0 +D79,PB1 +D80,PC3 +D81,PC2 +D82,PC0 +D83,PA0 +D84,PA4 +D85,PA5 +D86,PI12 +D87,PJ13 +D88,PE3 +D89,PG9 +D90,PD7 +D91,PB3 +D92,PA15 +D93,PB5 +D94,PB13 +D100,PC13 +D101,PB6 +D102,PH12 + +# Arduino Analog Pins +A0,PC4 +A1,PC5 +A2,PB0 +A3,PB1 +A4,PC3 +A5,PC2 +A6,PC0 +A7,PA0 +A8,PC2_C +A9,PC3_C +A10,PA1_C +A11,PA0_C +A12,PA4 +A13,PA5 + UART1_TX,PA9 UART1_RX,PB7 UART2_TX,PD5 @@ -177,11 +294,12 @@ UART6_RX,PC7 -USB_DM,PA11 -USB_DP,PA12 #BOOT0,BOOT0 -DAC1,PA4 -DAC2,PA5 +DAC0,PA4 +DAC1,PA5 LEDR,PI12 LEDG,PJ13 LEDB,PE3 +LED_BUILTIN,PJ13 LED_RED,PI12 LED_GREEN,PJ13 LED_BLUE,PE3 diff --git a/ports/stm32/boards/ARDUINO_NICLA_VISION/pins.csv b/ports/stm32/boards/ARDUINO_NICLA_VISION/pins.csv index 72f57adf74234..7996e75496eda 100644 --- a/ports/stm32/boards/ARDUINO_NICLA_VISION/pins.csv +++ b/ports/stm32/boards/ARDUINO_NICLA_VISION/pins.csv @@ -166,6 +166,30 @@ PK4,PK4 PK5,PK5 PK6,PK6 PK7,PK7 + +# Arduino Digital Pins +D0,PG12 +D1,PA9 +D2,PA10 +D3,PG1 + +# Arduino Analog Pins +A0,PC4 +A1,PF13 +A2,PF3 + +SCKL,PE12 +CIPO,PE13 +COPI,PE14 +CS,PE11 +LPIO0,PG12 +LPIO1,PA9 +LPIO2,PA10 +LPIO3,PG1 +SCL,PB8 +SDA,PB9 +UART_RX,PA10 +UART_TX,PA9 UART1_TX,PA9 UART1_RX,PA10 UART4_TX,-PA0 diff --git a/ports/stm32/boards/ARDUINO_PORTENTA_H7/pins.csv b/ports/stm32/boards/ARDUINO_PORTENTA_H7/pins.csv index 3b93dcba73f91..64082d87b3d0e 100644 --- a/ports/stm32/boards/ARDUINO_PORTENTA_H7/pins.csv +++ b/ports/stm32/boards/ARDUINO_PORTENTA_H7/pins.csv @@ -166,6 +166,36 @@ PK4,PK4 PK5,PK5 PK6,PK6 PK7,PK7 + +# Arduino Digital Pins +D0,PH15 +D1,PK1 +D2,PJ11 +D3,PG7 +D4,PC7 +D5,PC6 +D6,PA8 +D7,PI0 +D8,PC3 +D9,PI1 +D10,PC2 +D11,PH8 +D12,PH7 +D13,PA10 +D14,PA9 +D20,PC3 +D21,PA4 + +# Arduino Analog Pins +A0,PA0_C +A1,PA1_C +A2,PC2_C +A3,PC3_C +A4,PC2 +A5,PC3 +A6,PA4 +A7,PA6 + UART1_TX,PA9 UART1_RX,PA10 UART4_TX,PA0 @@ -209,6 +239,7 @@ LEDB,PK7 LED_RED,PK5 LED_GREEN,PK6 LED_BLUE,PK7 +LED_BUILTIN,PK6 I2C1_SDA,PB7 I2C1_SCL,PB6 I2C3_SDA,PH8 From ed29a4123f626ea912880dc8ae4ca8d183382858 Mon Sep 17 00:00:00 2001 From: Sebastian Romero Date: Mon, 29 Jan 2024 15:53:46 -0300 Subject: [PATCH 191/408] rp2/boards: Add named digital pins for Arduino Nano RP2040 Connect. Signed-off-by: Sebastian Romero --- ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/pins.csv | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/pins.csv b/ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/pins.csv index 5f8aeaf447f77..450f57d723805 100644 --- a/ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/pins.csv +++ b/ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/pins.csv @@ -12,6 +12,10 @@ D10,GPIO5 D11,GPIO7 D12,GPIO4 D13,GPIO6 +D14,GPIO26 +D15,GPIO27 +D16,GPIO28 +D17,GPIO29 LED,GPIO6 LED_BUILTIN,GPIO6 A0,GPIO26 From 27c0992343fe270c7b2e5ea24d2e47c9d8eb2430 Mon Sep 17 00:00:00 2001 From: Sebastian Romero Date: Mon, 29 Jan 2024 15:54:00 -0300 Subject: [PATCH 192/408] esp32/boards: Add missing named digital pins for Arduino Nano ESP32. Signed-off-by: Sebastian Romero --- ports/esp32/boards/ARDUINO_NANO_ESP32/pins.csv | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ports/esp32/boards/ARDUINO_NANO_ESP32/pins.csv b/ports/esp32/boards/ARDUINO_NANO_ESP32/pins.csv index 5934ae7bf2a0c..fcd3d23004170 100644 --- a/ports/esp32/boards/ARDUINO_NANO_ESP32/pins.csv +++ b/ports/esp32/boards/ARDUINO_NANO_ESP32/pins.csv @@ -12,6 +12,14 @@ D10,GPIO21 D11,GPIO38 D12,GPIO47 D13,GPIO48 +D17,GPIO1 +D18,GPIO2 +D19,GPIO3 +D20,GPIO4 +D21,GPIO11 +D22,GPIO12 +D23,GPIO13 +D24,GPIO14 LEDR,GPIO46 LEDG,GPIO0 LEDB,GPIO45 From 5c5fe8782164057f13d2cb8a13ab6c933c5b90b7 Mon Sep 17 00:00:00 2001 From: Sebastian Romero Date: Mon, 29 Jan 2024 15:54:09 -0300 Subject: [PATCH 193/408] nrf/boards: Add named pins for Arduino Nano 33 BLE. Signed-off-by: Sebastian Romero --- .../boards/ARDUINO_NANO_33_BLE_SENSE/pins.csv | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/ports/nrf/boards/ARDUINO_NANO_33_BLE_SENSE/pins.csv b/ports/nrf/boards/ARDUINO_NANO_33_BLE_SENSE/pins.csv index 9d931634f627d..972dd9d3bdcb8 100644 --- a/ports/nrf/boards/ARDUINO_NANO_33_BLE_SENSE/pins.csv +++ b/ports/nrf/boards/ARDUINO_NANO_33_BLE_SENSE/pins.csv @@ -46,5 +46,37 @@ P44,P44 P45,P45 P46,P46 P47,P47 + +# Arduino Digital Pins +D2,P43 +D3,P44 +D4,P47 +D5,P45 +D6,P46 +D7,P23 +D8,P21 +D9,P27 +D10,P34 +D11,P33 +D12,P40 +D13,P13 + +# Arduino Analog Pins +A0,P4 +A1,P5 +A2,P30 +A3,P29 +A4,P31 +A5,P2 +A6,P28 +A7,P3 + +LEDR,P24 +LEDG,P16 +LEDB,P6 +LED_BUILTIN,P13 +LED_PWR,P41 +TX,P35 +RX,P42 I2C_SCL,P2 I2C_SDA,P31 From 4dc262c8fd1c4624ccbd76910c2578db1979e805 Mon Sep 17 00:00:00 2001 From: Sebastian Romero Date: Mon, 29 Jan 2024 15:54:20 -0300 Subject: [PATCH 194/408] renesas-ra/boards: Add named pins for Arduino Portenta C33. Signed-off-by: Sebastian Romero --- .../boards/ARDUINO_PORTENTA_C33/pins.csv | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/pins.csv b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/pins.csv index 77b5c3de52820..9c49fe3755e67 100644 --- a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/pins.csv +++ b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/pins.csv @@ -144,12 +144,29 @@ D2,P111 D3,P303 D4,P401 D5,P210 +D6,P601 +D7,P402 +D8,P900 +D9,P204 +D10,P315 +D11,P407 +D12,P408 +D13,P110 +D14,P602 LED1,P107 LED2,P400 LED3,P800 LEDR,P107 LEDG,P400 LEDB,P800 +LED_BUILTIN,P400 LED_RED,P107 LED_GREEN,P400 LED_BLUE,P800 +COPI,P900 +CIPO,P315 +SCK,P204 +CS,P402 +SS,P402 +UART_TX,P602 +UART_RX,P110 From 0b145fdc2d4857a77f9f0a3662646d52da61d5b2 Mon Sep 17 00:00:00 2001 From: MikeTeachman Date: Tue, 20 Feb 2024 21:37:30 -0800 Subject: [PATCH 195/408] esp32/machine_i2s: Integrate new I2S IDF driver. The legacy I2S "shim" is removed and replaced by the new I2S driver. The new driver fixes a bug where mono audio plays only in one channel. Application code size is reduced by 2672 bytes with this change. Tested on ESP32, ESP32+spiram, ESP32-S3 using example code from https://github.com/miketeachman/micropython-i2s-examples Signed-off-by: Mike Teachman --- extmod/machine_i2s.c | 25 +-- ports/esp32/boards/sdkconfig.base | 1 - ports/esp32/machine_i2s.c | 280 +++++++++++++++--------------- ports/esp32/mpconfigport.h | 6 +- 4 files changed, 150 insertions(+), 162 deletions(-) diff --git a/extmod/machine_i2s.c b/extmod/machine_i2s.c index 7e069c5d76cbf..9c92eb4c926b7 100644 --- a/extmod/machine_i2s.c +++ b/extmod/machine_i2s.c @@ -608,6 +608,7 @@ static mp_uint_t machine_i2s_stream_write(mp_obj_t self_in, const void *buf_in, #else uint32_t num_bytes_written = copy_appbuf_to_dma(self, &appbuf); #endif + return num_bytes_written; } } @@ -632,16 +633,8 @@ static mp_uint_t machine_i2s_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_ ret |= MP_STREAM_POLL_RD; } #else - // check event queue to determine if a DMA buffer has been filled - // (which is an indication that at least one DMA buffer is available to be read) - // note: timeout = 0 so the call is non-blocking - i2s_event_t i2s_event; - if (xQueueReceive(self->i2s_event_queue, &i2s_event, 0)) { - if (i2s_event.type == I2S_EVENT_RX_DONE) { - // getting here means that at least one DMA buffer is now full - // indicating that audio samples can be read from the I2S object - ret |= MP_STREAM_POLL_RD; - } + if (self->dma_buffer_status == DMA_MEMORY_NOT_EMPTY) { + ret |= MP_STREAM_POLL_RD; } #endif } @@ -657,16 +650,8 @@ static mp_uint_t machine_i2s_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_ ret |= MP_STREAM_POLL_WR; } #else - // check event queue to determine if a DMA buffer has been emptied - // (which is an indication that at least one DMA buffer is available to be written) - // note: timeout = 0 so the call is non-blocking - i2s_event_t i2s_event; - if (xQueueReceive(self->i2s_event_queue, &i2s_event, 0)) { - if (i2s_event.type == I2S_EVENT_TX_DONE) { - // getting here means that at least one DMA buffer is now empty - // indicating that audio samples can be written to the I2S object - ret |= MP_STREAM_POLL_WR; - } + if (self->dma_buffer_status == DMA_MEMORY_NOT_FULL) { + ret |= MP_STREAM_POLL_WR; } #endif } diff --git a/ports/esp32/boards/sdkconfig.base b/ports/esp32/boards/sdkconfig.base index 05624f0d7409b..fef25fe3087f5 100644 --- a/ports/esp32/boards/sdkconfig.base +++ b/ports/esp32/boards/sdkconfig.base @@ -112,7 +112,6 @@ CONFIG_UART_ISR_IN_IRAM=y # IDF 5 deprecated CONFIG_ADC_SUPPRESS_DEPRECATE_WARN=y CONFIG_RMT_SUPPRESS_DEPRECATE_WARN=y -CONFIG_I2S_SUPPRESS_DEPRECATE_WARN=y CONFIG_ETH_USE_SPI_ETHERNET=y CONFIG_ETH_SPI_ETHERNET_W5500=y diff --git a/ports/esp32/machine_i2s.c b/ports/esp32/machine_i2s.c index 574125ad6a0d9..6ba2f54c354c6 100644 --- a/ports/esp32/machine_i2s.c +++ b/ports/esp32/machine_i2s.c @@ -28,9 +28,7 @@ // extmod/machine_i2s.c via MICROPY_PY_MACHINE_I2S_INCLUDEFILE. #include "py/mphal.h" - -#include "driver/i2s.h" -#include "soc/i2s_reg.h" +#include "driver/i2s_std.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/queue.h" @@ -62,23 +60,32 @@ typedef struct _non_blocking_descriptor_t { direction_t direction; } non_blocking_descriptor_t; +typedef enum { + DMA_MEMORY_FULL, + DMA_MEMORY_NOT_FULL, + DMA_MEMORY_EMPTY, + DMA_MEMORY_NOT_EMPTY, +} dma_buffer_status_t; + typedef struct _machine_i2s_obj_t { mp_obj_base_t base; i2s_port_t i2s_id; + i2s_chan_handle_t i2s_chan_handle; mp_hal_pin_obj_t sck; mp_hal_pin_obj_t ws; mp_hal_pin_obj_t sd; - int8_t mode; - i2s_bits_per_sample_t bits; + i2s_dir_t mode; + i2s_data_bit_width_t bits; format_t format; int32_t rate; int32_t ibuf; mp_obj_t callback_for_non_blocking; io_mode_t io_mode; + bool is_deinit; uint8_t transform_buffer[SIZEOF_TRANSFORM_BUFFER_IN_BYTES]; - QueueHandle_t i2s_event_queue; QueueHandle_t non_blocking_mode_queue; TaskHandle_t non_blocking_mode_task; + dma_buffer_status_t dma_buffer_status; } machine_i2s_obj_t; static mp_obj_t machine_i2s_deinit(mp_obj_t self_in); @@ -87,10 +94,10 @@ static mp_obj_t machine_i2s_deinit(mp_obj_t self_in); // from DMA memory (32-bit stereo, with the L and R channels reversed) to the format specified // in the I2S constructor. e.g. 16-bit mono static const int8_t i2s_frame_map[NUM_I2S_USER_FORMATS][I2S_RX_FRAME_SIZE_IN_BYTES] = { - { 6, 7, -1, -1, -1, -1, -1, -1 }, // Mono, 16-bits - { 4, 5, 6, 7, -1, -1, -1, -1 }, // Mono, 32-bits - { 6, 7, 2, 3, -1, -1, -1, -1 }, // Stereo, 16-bits - { 4, 5, 6, 7, 0, 1, 2, 3 }, // Stereo, 32-bits + { 2, 3, -1, -1, -1, -1, -1, -1 }, // Mono, 16-bits + { 0, 1, 2, 3, -1, -1, -1, -1 }, // Mono, 32-bits + { 2, 3, 6, 7, -1, -1, -1, -1 }, // Stereo, 16-bits + { 0, 1, 2, 3, 4, 5, 6, 7 }, // Stereo, 32-bits }; void machine_i2s_init0() { @@ -99,49 +106,15 @@ void machine_i2s_init0() { } } -// The following function takes a sample buffer and swaps L/R channels -// -// Background: For 32-bit stereo, the ESP-IDF API has a L/R channel orientation that breaks -// convention with other ESP32 channel formats -// -// appbuf[] = [L_0-7, L_8-15, L_16-23, L_24-31, R_0-7, R_8-15, R_16-23, R_24-31] = [Left channel, Right channel] -// dma[] = [R_0-7, R_8-15, R_16-23, R_24-31, L_0-7, L_8-15, L_16-23, L_24-31] = [Right channel, Left channel] -// -// where: -// L_0-7 is the least significant byte of the 32 bit sample in the Left channel -// L_24-31 is the most significant byte of the 32 bit sample in the Left channel -// -// Example: -// -// appbuf[] = [0x99, 0xBB, 0x11, 0x22, 0x44, 0x55, 0xAB, 0x77] = [Left channel, Right channel] -// dma[] = [0x44, 0x55, 0xAB, 0x77, 0x99, 0xBB, 0x11, 0x22] = [Right channel, Left channel] -// where: -// LEFT Channel = 0x99, 0xBB, 0x11, 0x22 -// RIGHT Channel = 0x44, 0x55, 0xAB, 0x77 -// -// samples in appbuf are in little endian format: -// 0x77 is the most significant byte of the 32-bit sample -// 0x44 is the least significant byte of the 32-bit sample -static void swap_32_bit_stereo_channels(mp_buffer_info_t *bufinfo) { - int32_t swap_sample; - int32_t *sample = bufinfo->buf; - uint32_t num_samples = bufinfo->len / 4; - for (uint32_t i = 0; i < num_samples; i += 2) { - swap_sample = sample[i + 1]; - sample[i + 1] = sample[i]; - sample[i] = swap_sample; - } -} - -static int8_t get_frame_mapping_index(i2s_bits_per_sample_t bits, format_t format) { +static int8_t get_frame_mapping_index(i2s_data_bit_width_t bits, format_t format) { if (format == MONO) { - if (bits == I2S_BITS_PER_SAMPLE_16BIT) { + if (bits == I2S_DATA_BIT_WIDTH_16BIT) { return 0; } else { // 32 bits return 1; } } else { // STEREO - if (bits == I2S_BITS_PER_SAMPLE_16BIT) { + if (bits == I2S_DATA_BIT_WIDTH_16BIT) { return 2; } else { // 32 bits return 3; @@ -149,32 +122,32 @@ static int8_t get_frame_mapping_index(i2s_bits_per_sample_t bits, format_t forma } } -static i2s_bits_per_sample_t get_dma_bits(uint8_t mode, i2s_bits_per_sample_t bits) { - if (mode == (I2S_MODE_MASTER | I2S_MODE_TX)) { +static i2s_data_bit_width_t get_dma_bits(uint8_t mode, i2s_data_bit_width_t bits) { + if (mode == MICROPY_PY_MACHINE_I2S_CONSTANT_TX) { return bits; } else { // Master Rx // read 32 bit samples for I2S hardware. e.g. MEMS microphones - return I2S_BITS_PER_SAMPLE_32BIT; + return I2S_DATA_BIT_WIDTH_32BIT; } } -static i2s_channel_fmt_t get_dma_format(uint8_t mode, format_t format) { - if (mode == (I2S_MODE_MASTER | I2S_MODE_TX)) { +static i2s_slot_mode_t get_dma_format(uint8_t mode, format_t format) { + if (mode == MICROPY_PY_MACHINE_I2S_CONSTANT_TX) { if (format == MONO) { - return I2S_CHANNEL_FMT_ONLY_LEFT; + return I2S_SLOT_MODE_MONO; } else { // STEREO - return I2S_CHANNEL_FMT_RIGHT_LEFT; + return I2S_SLOT_MODE_STEREO; } } else { // Master Rx // read stereo frames for all I2S hardware - return I2S_CHANNEL_FMT_RIGHT_LEFT; + return I2S_SLOT_MODE_STEREO; } } -static uint32_t get_dma_buf_count(uint8_t mode, i2s_bits_per_sample_t bits, format_t format, int32_t ibuf) { +static uint32_t get_dma_buf_count(uint8_t mode, i2s_data_bit_width_t bits, format_t format, int32_t ibuf) { // calculate how many DMA buffers need to be allocated uint32_t dma_frame_size_in_bytes = - (get_dma_bits(mode, bits) / 8) * (get_dma_format(mode, format) == I2S_CHANNEL_FMT_RIGHT_LEFT ? 2: 1); + (get_dma_bits(mode, bits) / 8) * (get_dma_format(mode, format) == I2S_SLOT_MODE_STEREO ? 2: 1); uint32_t dma_buf_count = ibuf / (DMA_BUF_LEN_IN_I2S_FRAMES * dma_frame_size_in_bytes); @@ -204,18 +177,23 @@ static uint32_t fill_appbuf_from_dma(machine_i2s_obj_t *self, mp_buffer_info_t * TickType_t delay; if (self->io_mode == ASYNCIO) { - delay = 0; // stop i2s_read() operation if DMA memory becomes empty + delay = 0; // stop i2s_channel_read() operation if DMA memory becomes empty } else { delay = portMAX_DELAY; // block until supplied buffer is filled } - esp_err_t ret = i2s_read( - self->i2s_id, + esp_err_t ret = i2s_channel_read( + self->i2s_chan_handle, self->transform_buffer, num_bytes_requested_from_dma, &num_bytes_received_from_dma, delay); - check_esp_err(ret); + + // i2s_channel_read returns ESP_ERR_TIMEOUT when buffer cannot be filled by the timeout delay. + if ((self->io_mode != ASYNCIO) || + ((self->io_mode == ASYNCIO) && (ret != ESP_ERR_TIMEOUT))) { + check_esp_err(ret); + } // process the transform buffer one frame at a time. // copy selected bytes from the transform buffer into the user supplied appbuf. @@ -246,9 +224,7 @@ static uint32_t fill_appbuf_from_dma(machine_i2s_obj_t *self, mp_buffer_info_t * if ((self->io_mode == ASYNCIO) && (num_bytes_received_from_dma < num_bytes_requested_from_dma)) { // Unable to fill the entire app buffer from DMA memory. This indicates all DMA RX buffers are empty. - // Clear the I2S event queue so ioctl() indicates that the I2S object cannot currently - // supply more audio samples - xQueueReset(self->i2s_event_queue); + self->dma_buffer_status = DMA_MEMORY_EMPTY; break; } } @@ -257,34 +233,28 @@ static uint32_t fill_appbuf_from_dma(machine_i2s_obj_t *self, mp_buffer_info_t * } static size_t copy_appbuf_to_dma(machine_i2s_obj_t *self, mp_buffer_info_t *appbuf) { - if ((self->bits == I2S_BITS_PER_SAMPLE_32BIT) && (self->format == STEREO)) { - swap_32_bit_stereo_channels(appbuf); - } - size_t num_bytes_written = 0; TickType_t delay; if (self->io_mode == ASYNCIO) { - delay = 0; // stop i2s_write() operation if DMA memory becomes full + delay = 0; // stop i2s_channel_write() operation if DMA memory becomes full } else { delay = portMAX_DELAY; // block until supplied buffer is emptied } - esp_err_t ret = i2s_write(self->i2s_id, appbuf->buf, appbuf->len, &num_bytes_written, delay); - check_esp_err(ret); + esp_err_t ret = i2s_channel_write(self->i2s_chan_handle, appbuf->buf, appbuf->len, &num_bytes_written, delay); + + // i2s_channel_write returns ESP_ERR_TIMEOUT when buffer cannot be emptied by the timeout delay. + if ((self->io_mode != ASYNCIO) || + ((self->io_mode == ASYNCIO) && (ret != ESP_ERR_TIMEOUT))) { + check_esp_err(ret); + } if ((self->io_mode == ASYNCIO) && (num_bytes_written < appbuf->len)) { // Unable to empty the entire app buffer into DMA memory. This indicates all DMA TX buffers are full. - // Clear the I2S event queue so ioctl() indicates that the I2S object cannot currently - // accept more audio samples - xQueueReset(self->i2s_event_queue); - - // Undo the swap transformation as the buffer has not been completely emptied. - // The asyncio stream writer will use the same buffer in a future write call. - if ((self->bits == I2S_BITS_PER_SAMPLE_32BIT) && (self->format == STEREO)) { - swap_32_bit_stereo_channels(appbuf); - } + self->dma_buffer_status = DMA_MEMORY_FULL; } + return num_bytes_written; } @@ -306,6 +276,34 @@ static void task_for_non_blocking_mode(void *self_in) { } } +// callback indicating that a DMA buffer was just filled with samples received from an I2S port +static IRAM_ATTR bool i2s_rx_recv_callback(i2s_chan_handle_t handle, i2s_event_data_t *event, void *self_in) { + machine_i2s_obj_t *self = (machine_i2s_obj_t *)self_in; + self->dma_buffer_status = DMA_MEMORY_NOT_EMPTY; + return false; +} + +// callback indicating that samples in a DMA buffer were just transmitted to an I2S port +static IRAM_ATTR bool i2s_tx_sent_callback(i2s_chan_handle_t handle, i2s_event_data_t *event, void *self_in) { + machine_i2s_obj_t *self = (machine_i2s_obj_t *)self_in; + self->dma_buffer_status = DMA_MEMORY_NOT_FULL; + return false; +} + +i2s_event_callbacks_t i2s_callbacks = { + .on_recv = i2s_rx_recv_callback, + .on_recv_q_ovf = NULL, + .on_sent = i2s_tx_sent_callback, + .on_send_q_ovf = NULL, +}; + +i2s_event_callbacks_t i2s_callbacks_null = { + .on_recv = NULL, + .on_recv_q_ovf = NULL, + .on_sent = NULL, + .on_send_q_ovf = NULL, +}; + static void mp_machine_i2s_init_helper(machine_i2s_obj_t *self, mp_arg_val_t *args) { // are Pins valid? int8_t sck = args[ARG_sck].u_obj == MP_OBJ_NULL ? -1 : machine_pin_get_id(args[ARG_sck].u_obj); @@ -313,16 +311,16 @@ static void mp_machine_i2s_init_helper(machine_i2s_obj_t *self, mp_arg_val_t *ar int8_t sd = args[ARG_sd].u_obj == MP_OBJ_NULL ? -1 : machine_pin_get_id(args[ARG_sd].u_obj); // is Mode valid? - i2s_mode_t mode = args[ARG_mode].u_int; - if ((mode != (I2S_MODE_MASTER | I2S_MODE_RX)) && - (mode != (I2S_MODE_MASTER | I2S_MODE_TX))) { + int8_t mode = args[ARG_mode].u_int; + if ((mode != (MICROPY_PY_MACHINE_I2S_CONSTANT_RX)) && + (mode != (MICROPY_PY_MACHINE_I2S_CONSTANT_TX))) { mp_raise_ValueError(MP_ERROR_TEXT("invalid mode")); } // is Bits valid? - i2s_bits_per_sample_t bits = args[ARG_bits].u_int; - if ((bits != I2S_BITS_PER_SAMPLE_16BIT) && - (bits != I2S_BITS_PER_SAMPLE_32BIT)) { + i2s_data_bit_width_t bits = args[ARG_bits].u_int; + if ((bits != I2S_DATA_BIT_WIDTH_16BIT) && + (bits != I2S_DATA_BIT_WIDTH_32BIT)) { mp_raise_ValueError(MP_ERROR_TEXT("invalid bits")); } @@ -348,54 +346,57 @@ static void mp_machine_i2s_init_helper(machine_i2s_obj_t *self, mp_arg_val_t *ar self->rate = args[ARG_rate].u_int; self->ibuf = args[ARG_ibuf].u_int; self->callback_for_non_blocking = MP_OBJ_NULL; - self->i2s_event_queue = NULL; self->non_blocking_mode_queue = NULL; self->non_blocking_mode_task = NULL; self->io_mode = BLOCKING; + self->is_deinit = false; + + if (mode == MICROPY_PY_MACHINE_I2S_CONSTANT_TX) { + self->dma_buffer_status = DMA_MEMORY_NOT_FULL; + } else { // rx + self->dma_buffer_status = DMA_MEMORY_NOT_EMPTY; + } + + i2s_chan_config_t chan_config = I2S_CHANNEL_DEFAULT_CONFIG(self->i2s_id, I2S_ROLE_MASTER); + chan_config.dma_desc_num = get_dma_buf_count(mode, bits, format, self->ibuf); + chan_config.dma_frame_num = DMA_BUF_LEN_IN_I2S_FRAMES; + chan_config.auto_clear = true; + + if (mode == MICROPY_PY_MACHINE_I2S_CONSTANT_TX) { + ESP_ERROR_CHECK(i2s_new_channel(&chan_config, &self->i2s_chan_handle, NULL)); + } else { // rx + ESP_ERROR_CHECK(i2s_new_channel(&chan_config, NULL, &self->i2s_chan_handle)); + } - i2s_config_t i2s_config; - i2s_config.communication_format = I2S_COMM_FORMAT_STAND_I2S; - i2s_config.mode = mode; - i2s_config.bits_per_sample = get_dma_bits(mode, bits); - i2s_config.channel_format = get_dma_format(mode, format); - i2s_config.sample_rate = self->rate; - i2s_config.intr_alloc_flags = ESP_INTR_FLAG_LOWMED; - i2s_config.dma_desc_num = get_dma_buf_count(mode, bits, format, self->ibuf); - i2s_config.dma_frame_num = DMA_BUF_LEN_IN_I2S_FRAMES; - i2s_config.use_apll = false; - i2s_config.tx_desc_auto_clear = true; - i2s_config.fixed_mclk = 0; - i2s_config.mclk_multiple = I2S_MCLK_MULTIPLE_256; - i2s_config.bits_per_chan = 0; - - // I2S queue size equals the number of DMA buffers - check_esp_err(i2s_driver_install(self->i2s_id, &i2s_config, i2s_config.dma_desc_num, &self->i2s_event_queue)); - - // apply low-level workaround for bug in some ESP-IDF versions that swap - // the left and right channels - // https://github.com/espressif/esp-idf/issues/6625 - #if CONFIG_IDF_TARGET_ESP32S3 - REG_SET_BIT(I2S_TX_CONF_REG(self->i2s_id), I2S_TX_MSB_SHIFT); - REG_SET_BIT(I2S_TX_CONF_REG(self->i2s_id), I2S_RX_MSB_SHIFT); - #else - REG_SET_BIT(I2S_CONF_REG(self->i2s_id), I2S_TX_MSB_RIGHT); - REG_SET_BIT(I2S_CONF_REG(self->i2s_id), I2S_RX_MSB_RIGHT); - #endif - - i2s_pin_config_t pin_config; - pin_config.mck_io_num = I2S_PIN_NO_CHANGE; - pin_config.bck_io_num = self->sck; - pin_config.ws_io_num = self->ws; - - if (mode == (I2S_MODE_MASTER | I2S_MODE_RX)) { - pin_config.data_in_num = self->sd; - pin_config.data_out_num = I2S_PIN_NO_CHANGE; - } else { // TX - pin_config.data_in_num = I2S_PIN_NO_CHANGE; - pin_config.data_out_num = self->sd; + i2s_std_slot_config_t slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG(get_dma_bits(mode, bits), get_dma_format(mode, format)); + slot_cfg.slot_mask = I2S_STD_SLOT_BOTH; + + i2s_std_config_t std_cfg = { + .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(self->rate), + .slot_cfg = slot_cfg, + .gpio_cfg = { + .mclk = I2S_GPIO_UNUSED, + .bclk = self->sck, + .ws = self->ws, + .invert_flags = { + .mclk_inv = false, + .bclk_inv = false, + .ws_inv = false, + }, + }, + }; + + if (mode == MICROPY_PY_MACHINE_I2S_CONSTANT_TX) { + std_cfg.gpio_cfg.dout = self->sd; + std_cfg.gpio_cfg.din = I2S_GPIO_UNUSED; + } else { // rx + std_cfg.gpio_cfg.dout = I2S_GPIO_UNUSED; + std_cfg.gpio_cfg.din = self->sd; } - check_esp_err(i2s_set_pin(self->i2s_id, &pin_config)); + ESP_ERROR_CHECK(i2s_channel_init_std_mode(self->i2s_chan_handle, &std_cfg)); + ESP_ERROR_CHECK(i2s_channel_register_event_callback(self->i2s_chan_handle, &i2s_callbacks, self)); + ESP_ERROR_CHECK(i2s_channel_enable(self->i2s_chan_handle)); } static machine_i2s_obj_t *mp_machine_i2s_make_new_instance(mp_int_t i2s_id) { @@ -417,19 +418,22 @@ static machine_i2s_obj_t *mp_machine_i2s_make_new_instance(mp_int_t i2s_id) { } static void mp_machine_i2s_deinit(machine_i2s_obj_t *self) { - i2s_driver_uninstall(self->i2s_id); + if (!self->is_deinit) { + ESP_ERROR_CHECK(i2s_channel_disable(self->i2s_chan_handle)); + ESP_ERROR_CHECK(i2s_channel_register_event_callback(self->i2s_chan_handle, &i2s_callbacks_null, self)); + ESP_ERROR_CHECK(i2s_del_channel(self->i2s_chan_handle)); - if (self->non_blocking_mode_task != NULL) { - vTaskDelete(self->non_blocking_mode_task); - self->non_blocking_mode_task = NULL; - } + if (self->non_blocking_mode_task != NULL) { + vTaskDelete(self->non_blocking_mode_task); + self->non_blocking_mode_task = NULL; + } - if (self->non_blocking_mode_queue != NULL) { - vQueueDelete(self->non_blocking_mode_queue); - self->non_blocking_mode_queue = NULL; + if (self->non_blocking_mode_queue != NULL) { + vQueueDelete(self->non_blocking_mode_queue); + self->non_blocking_mode_queue = NULL; + } + self->is_deinit = true; } - - self->i2s_event_queue = NULL; } static void mp_machine_i2s_irq_update(machine_i2s_obj_t *self) { diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h index acf065384b7da..be02d45883bcd 100644 --- a/ports/esp32/mpconfigport.h +++ b/ports/esp32/mpconfigport.h @@ -9,7 +9,7 @@ #include "esp_random.h" #include "esp_system.h" #include "freertos/FreeRTOS.h" -#include "driver/i2s.h" +#include "driver/i2s_std.h" #include "esp_wifi_types.h" #ifndef MICROPY_CONFIG_ROM_LEVEL @@ -147,8 +147,8 @@ #endif #define MICROPY_PY_MACHINE_I2S_INCLUDEFILE "ports/esp32/machine_i2s.c" #define MICROPY_PY_MACHINE_I2S_FINALISER (1) -#define MICROPY_PY_MACHINE_I2S_CONSTANT_RX (I2S_MODE_MASTER | I2S_MODE_RX) -#define MICROPY_PY_MACHINE_I2S_CONSTANT_TX (I2S_MODE_MASTER | I2S_MODE_TX) +#define MICROPY_PY_MACHINE_I2S_CONSTANT_RX (I2S_DIR_RX) +#define MICROPY_PY_MACHINE_I2S_CONSTANT_TX (I2S_DIR_TX) #define MICROPY_PY_MACHINE_UART (1) #define MICROPY_PY_MACHINE_UART_INCLUDEFILE "ports/esp32/machine_uart.c" #define MICROPY_PY_MACHINE_UART_SENDBREAK (1) From c92683d67c8f8320bd2ddd604b9abee712575b08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20de=20Giessen?= Date: Thu, 29 Feb 2024 14:04:23 +0100 Subject: [PATCH 196/408] esp32: Add support for IDF version v5.0.5. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniël van de Giessen --- ports/esp32/README.md | 2 +- ports/esp32/modnetwork_globals.h | 2 +- ports/esp32/network_common.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ports/esp32/README.md b/ports/esp32/README.md index a7531b6eaa447..deed413f2560f 100644 --- a/ports/esp32/README.md +++ b/ports/esp32/README.md @@ -28,7 +28,7 @@ manage the ESP32 microcontroller, as well as a way to manage the required build environment and toolchains needed to build the firmware. The ESP-IDF changes quickly and MicroPython only supports certain versions. -Currently MicroPython supports v5.0.4, v5.1.2. +Currently MicroPython supports v5.0.4, v5.0.5, v5.1.2. To install the ESP-IDF the full instructions can be found at the [Espressif Getting Started guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html#installation-step-by-step). diff --git a/ports/esp32/modnetwork_globals.h b/ports/esp32/modnetwork_globals.h index 56e5341915bfc..38c192f9a6eb9 100644 --- a/ports/esp32/modnetwork_globals.h +++ b/ports/esp32/modnetwork_globals.h @@ -31,7 +31,7 @@ { MP_ROM_QSTR(MP_QSTR_AUTH_WPA2_WPA3_PSK), MP_ROM_INT(WIFI_AUTH_WPA2_WPA3_PSK) }, { MP_ROM_QSTR(MP_QSTR_AUTH_WAPI_PSK), MP_ROM_INT(WIFI_AUTH_WAPI_PSK) }, { MP_ROM_QSTR(MP_QSTR_AUTH_OWE), MP_ROM_INT(WIFI_AUTH_OWE) }, -#if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(5, 1, 1) +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 5) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 0) || ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 2) { MP_ROM_QSTR(MP_QSTR_AUTH_WPA3_ENT_192), MP_ROM_INT(WIFI_AUTH_WPA3_ENT_192) }, #endif { MP_ROM_QSTR(MP_QSTR_AUTH_MAX), MP_ROM_INT(WIFI_AUTH_MAX) }, diff --git a/ports/esp32/network_common.c b/ports/esp32/network_common.c index fb51656817153..a8c407b08c631 100644 --- a/ports/esp32/network_common.c +++ b/ports/esp32/network_common.c @@ -168,7 +168,7 @@ static mp_obj_t esp_phy_mode(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_network_phy_mode_obj, 0, 1, esp_phy_mode); -#if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(5, 1, 1) +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 5) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 0) || ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 2) _Static_assert(WIFI_AUTH_MAX == 11, "Synchronize WIFI_AUTH_XXX constants with the ESP-IDF. Look at esp-idf/components/esp_wifi/include/esp_wifi_types.h"); #else _Static_assert(WIFI_AUTH_MAX == 10, "Synchronize WIFI_AUTH_XXX constants with the ESP-IDF. Look at esp-idf/components/esp_wifi/include/esp_wifi_types.h"); From d6176c1f5e5556e25944ce52874ea2f2d82ccde5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20de=20Giessen?= Date: Thu, 29 Feb 2024 14:05:01 +0100 Subject: [PATCH 197/408] esp32: Add support for IDF version v5.2. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniël van de Giessen --- ports/esp32/README.md | 2 +- ports/esp32/machine_uart.c | 7 ++++++- ports/esp32/modnetwork_globals.h | 9 +++++++++ ports/esp32/mpthreadport.c | 14 ++++++++++---- ports/esp32/network_common.c | 4 +++- ports/esp32/network_wlan.c | 22 ++++++++++++++++++++++ ports/esp32/uart.c | 3 ++- 7 files changed, 53 insertions(+), 8 deletions(-) diff --git a/ports/esp32/README.md b/ports/esp32/README.md index deed413f2560f..2e03c55d3de18 100644 --- a/ports/esp32/README.md +++ b/ports/esp32/README.md @@ -28,7 +28,7 @@ manage the ESP32 microcontroller, as well as a way to manage the required build environment and toolchains needed to build the firmware. The ESP-IDF changes quickly and MicroPython only supports certain versions. -Currently MicroPython supports v5.0.4, v5.0.5, v5.1.2. +Currently MicroPython supports v5.0.4, v5.0.5, v5.1.2, v5.2.0. To install the ESP-IDF the full instructions can be found at the [Espressif Getting Started guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html#installation-step-by-step). diff --git a/ports/esp32/machine_uart.c b/ports/esp32/machine_uart.c index b7adbf81c7aa7..b5c5c016a5c69 100644 --- a/ports/esp32/machine_uart.c +++ b/ports/esp32/machine_uart.c @@ -306,7 +306,12 @@ static void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, } self->flowcontrol = args[ARG_flow].u_int; } - check_esp_err(uart_set_hw_flow_ctrl(self->uart_num, self->flowcontrol, UART_FIFO_LEN - UART_FIFO_LEN / 4)); + #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0) + uint8_t uart_fifo_len = UART_HW_FIFO_LEN(self->uart_num); + #else + uint8_t uart_fifo_len = UART_FIFO_LEN; + #endif + check_esp_err(uart_set_hw_flow_ctrl(self->uart_num, self->flowcontrol, uart_fifo_len - uart_fifo_len / 4)); } static mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { diff --git a/ports/esp32/modnetwork_globals.h b/ports/esp32/modnetwork_globals.h index 38c192f9a6eb9..7dd2ee9e66e7a 100644 --- a/ports/esp32/modnetwork_globals.h +++ b/ports/esp32/modnetwork_globals.h @@ -34,6 +34,10 @@ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 5) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 0) || ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 2) { MP_ROM_QSTR(MP_QSTR_AUTH_WPA3_ENT_192), MP_ROM_INT(WIFI_AUTH_WPA3_ENT_192) }, #endif +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0) +{ MP_ROM_QSTR(MP_QSTR_AUTH_WPA3_EXT_PSK), MP_ROM_INT(WIFI_AUTH_WPA3_EXT_PSK) }, +{ MP_ROM_QSTR(MP_QSTR_AUTH_WPA3_EXT_PSK_MIXED_MODE), MP_ROM_INT(WIFI_AUTH_WPA3_EXT_PSK_MIXED_MODE) }, +#endif { MP_ROM_QSTR(MP_QSTR_AUTH_MAX), MP_ROM_INT(WIFI_AUTH_MAX) }, #endif @@ -69,6 +73,11 @@ { MP_ROM_QSTR(MP_QSTR_STAT_GOT_IP), MP_ROM_INT(STAT_GOT_IP)}, // Errors from the ESP-IDF { MP_ROM_QSTR(MP_QSTR_STAT_NO_AP_FOUND), MP_ROM_INT(WIFI_REASON_NO_AP_FOUND)}, +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0) +{ MP_ROM_QSTR(MP_QSTR_STAT_NO_AP_FOUND_IN_RSSI_THRESHOLD), MP_ROM_INT(WIFI_REASON_NO_AP_FOUND_IN_RSSI_THRESHOLD)}, +{ MP_ROM_QSTR(MP_QSTR_STAT_NO_AP_FOUND_IN_AUTHMODE_THRESHOLD), MP_ROM_INT(WIFI_REASON_NO_AP_FOUND_IN_AUTHMODE_THRESHOLD)}, +{ MP_ROM_QSTR(MP_QSTR_STAT_NO_AP_FOUND_W_COMPATIBLE_SECURITY), MP_ROM_INT(WIFI_REASON_NO_AP_FOUND_W_COMPATIBLE_SECURITY)}, +#endif { MP_ROM_QSTR(MP_QSTR_STAT_WRONG_PASSWORD), MP_ROM_INT(WIFI_REASON_AUTH_FAIL)}, { MP_ROM_QSTR(MP_QSTR_STAT_BEACON_TIMEOUT), MP_ROM_INT(WIFI_REASON_BEACON_TIMEOUT)}, { MP_ROM_QSTR(MP_QSTR_STAT_ASSOC_FAIL), MP_ROM_INT(WIFI_REASON_ASSOC_FAIL)}, diff --git a/ports/esp32/mpthreadport.c b/ports/esp32/mpthreadport.c index 1c13e928d9722..12a6ede8668e6 100644 --- a/ports/esp32/mpthreadport.c +++ b/ports/esp32/mpthreadport.c @@ -41,6 +41,12 @@ #define MP_THREAD_DEFAULT_STACK_SIZE (MP_THREAD_MIN_STACK_SIZE + 1024) #define MP_THREAD_PRIORITY (ESP_TASK_PRIO_MIN + 1) +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0) && !CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP +#define FREERTOS_TASK_DELETE_HOOK vTaskPreDeletionHook +#else +#define FREERTOS_TASK_DELETE_HOOK vPortCleanUpTCB +#endif + // this structure forms a linked list, one node per active thread typedef struct _mp_thread_t { TaskHandle_t id; // system id of thread @@ -70,7 +76,7 @@ void mp_thread_init(void *stack, uint32_t stack_len) { // memory barrier to ensure above data is committed __sync_synchronize(); - // vPortCleanUpTCB needs the thread ready after thread_mutex is ready + // FREERTOS_TASK_DELETE_HOOK needs the thread ready after thread_mutex is ready thread = &thread_entry0; } @@ -179,7 +185,7 @@ void mp_thread_finish(void) { // This is called from the FreeRTOS idle task and is not within Python context, // so MP_STATE_THREAD is not valid and it does not have the GIL. -void vPortCleanUpTCB(void *tcb) { +void FREERTOS_TASK_DELETE_HOOK(void *tcb) { if (thread == NULL) { // threading not yet initialised return; @@ -235,7 +241,7 @@ void mp_thread_deinit(void) { // No tasks left to delete break; } else { - // Call FreeRTOS to delete the task (it will call vPortCleanUpTCB) + // Call FreeRTOS to delete the task (it will call FREERTOS_TASK_DELETE_HOOK) vTaskDelete(id); } } @@ -243,7 +249,7 @@ void mp_thread_deinit(void) { #else -void vPortCleanUpTCB(void *tcb) { +void FREERTOS_TASK_DELETE_HOOK(void *tcb) { } #endif // MICROPY_PY_THREAD diff --git a/ports/esp32/network_common.c b/ports/esp32/network_common.c index a8c407b08c631..223803a5d14ad 100644 --- a/ports/esp32/network_common.c +++ b/ports/esp32/network_common.c @@ -168,7 +168,9 @@ static mp_obj_t esp_phy_mode(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_network_phy_mode_obj, 0, 1, esp_phy_mode); -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 5) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 0) || ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 2) +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0) +_Static_assert(WIFI_AUTH_MAX == 13, "Synchronize WIFI_AUTH_XXX constants with the ESP-IDF. Look at esp-idf/components/esp_wifi/include/esp_wifi_types.h"); +#elif ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 5) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 0) || ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 2) _Static_assert(WIFI_AUTH_MAX == 11, "Synchronize WIFI_AUTH_XXX constants with the ESP-IDF. Look at esp-idf/components/esp_wifi/include/esp_wifi_types.h"); #else _Static_assert(WIFI_AUTH_MAX == 10, "Synchronize WIFI_AUTH_XXX constants with the ESP-IDF. Look at esp-idf/components/esp_wifi/include/esp_wifi_types.h"); diff --git a/ports/esp32/network_wlan.c b/ports/esp32/network_wlan.c index dfa3347c67953..ece88e705f942 100644 --- a/ports/esp32/network_wlan.c +++ b/ports/esp32/network_wlan.c @@ -113,6 +113,20 @@ static void network_wlan_wifi_event_handler(void *event_handler_arg, esp_event_b // AP may not exist, or it may have momentarily dropped out; try to reconnect. message = "no AP found"; break; + #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0) + case WIFI_REASON_NO_AP_FOUND_IN_RSSI_THRESHOLD: + // No AP with RSSI within given threshold exists, or it may have momentarily dropped out; try to reconnect. + message = "no AP with RSSI within threshold found"; + break; + case WIFI_REASON_NO_AP_FOUND_IN_AUTHMODE_THRESHOLD: + // No AP with authmode within given threshold exists, or it may have momentarily dropped out; try to reconnect. + message = "no AP with authmode within threshold found"; + break; + case WIFI_REASON_NO_AP_FOUND_W_COMPATIBLE_SECURITY: + // No AP with compatible security exists, or it may have momentarily dropped out; try to reconnect. + message = "no AP with compatible security found"; + break; + #endif case WIFI_REASON_AUTH_FAIL: // Password may be wrong, or it just failed to connect; try to reconnect. message = "authentication failed"; @@ -353,6 +367,14 @@ static mp_obj_t network_wlan_status(size_t n_args, const mp_obj_t *args) { return MP_OBJ_NEW_SMALL_INT(STAT_GOT_IP); } else if (wifi_sta_disconn_reason == WIFI_REASON_NO_AP_FOUND) { return MP_OBJ_NEW_SMALL_INT(WIFI_REASON_NO_AP_FOUND); + #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0) + } else if (wifi_sta_disconn_reason == WIFI_REASON_NO_AP_FOUND_IN_RSSI_THRESHOLD) { + return MP_OBJ_NEW_SMALL_INT(WIFI_REASON_NO_AP_FOUND_IN_RSSI_THRESHOLD); + } else if (wifi_sta_disconn_reason == WIFI_REASON_NO_AP_FOUND_IN_AUTHMODE_THRESHOLD) { + return MP_OBJ_NEW_SMALL_INT(WIFI_REASON_NO_AP_FOUND_IN_AUTHMODE_THRESHOLD); + } else if (wifi_sta_disconn_reason == WIFI_REASON_NO_AP_FOUND_W_COMPATIBLE_SECURITY) { + return MP_OBJ_NEW_SMALL_INT(WIFI_REASON_NO_AP_FOUND_W_COMPATIBLE_SECURITY); + #endif } else if ((wifi_sta_disconn_reason == WIFI_REASON_AUTH_FAIL) || (wifi_sta_disconn_reason == WIFI_REASON_CONNECTION_FAIL)) { // wrong password return MP_OBJ_NEW_SMALL_INT(WIFI_REASON_AUTH_FAIL); diff --git a/ports/esp32/uart.c b/ports/esp32/uart.c index 863301143d9ac..8336268509ecf 100644 --- a/ports/esp32/uart.c +++ b/ports/esp32/uart.c @@ -36,6 +36,7 @@ #include #include "driver/uart.h" // For uart_get_sclk_freq() #include "hal/uart_hal.h" +#include "soc/uart_periph.h" static void uart_irq_handler(void *arg); @@ -50,7 +51,7 @@ static void uart_irq_handler(void *arg); void uart_stdout_init(void) { uart_hal_context_t repl_hal = REPL_HAL_DEFN(); - #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 3, 0) + #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0) uart_sclk_t sclk; #else soc_module_clk_t sclk; From 27279e69b4d74b255bd8d8c5dd6668c97c942776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20de=20Giessen?= Date: Thu, 29 Feb 2024 13:05:00 +0100 Subject: [PATCH 198/408] esp32: Add IDF-version-specific sdkconfig. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new IDF v5.2 deprecated the task cleanup callback we use, so support for the new option has been implemented in the previous commit. This also requires a change in the sdkconfig, via a new variable ${SDKCONFIG_IDF_VERSION_SPECIFIC} which is used in all mpconfigboard.cmake files to include an extra sdkconfig file based on the IDF version in use. Signed-off-by: Daniël van de Giessen --- ports/esp32/CMakeLists.txt | 10 ++++++++++ .../boards/ARDUINO_NANO_ESP32/mpconfigboard.cmake | 1 + ports/esp32/boards/ESP32_GENERIC/mpconfigboard.cmake | 1 + .../esp32/boards/ESP32_GENERIC_C3/mpconfigboard.cmake | 1 + .../esp32/boards/ESP32_GENERIC_S2/mpconfigboard.cmake | 1 + .../esp32/boards/ESP32_GENERIC_S3/mpconfigboard.cmake | 1 + .../boards/LILYGO_TTGO_LORA32/mpconfigboard.cmake | 1 + ports/esp32/boards/LOLIN_C3_MINI/mpconfigboard.cmake | 1 + ports/esp32/boards/LOLIN_S2_MINI/mpconfigboard.cmake | 1 + ports/esp32/boards/LOLIN_S2_PICO/mpconfigboard.cmake | 1 + ports/esp32/boards/M5STACK_ATOM/mpconfigboard.cmake | 1 + .../esp32/boards/OLIMEX_ESP32_POE/mpconfigboard.cmake | 1 + ports/esp32/boards/SIL_WESP32/mpconfigboard.cmake | 1 + ports/esp32/boards/UM_FEATHERS2/mpconfigboard.cmake | 1 + ports/esp32/boards/UM_FEATHERS2NEO/mpconfigboard.cmake | 1 + ports/esp32/boards/UM_FEATHERS3/mpconfigboard.cmake | 1 + ports/esp32/boards/UM_NANOS3/mpconfigboard.cmake | 1 + ports/esp32/boards/UM_PROS3/mpconfigboard.cmake | 1 + ports/esp32/boards/UM_TINYPICO/mpconfigboard.cmake | 1 + ports/esp32/boards/UM_TINYS2/mpconfigboard.cmake | 1 + ports/esp32/boards/UM_TINYS3/mpconfigboard.cmake | 1 + ports/esp32/boards/UM_TINYWATCHS3/mpconfigboard.cmake | 1 + ports/esp32/boards/sdkconfig.idf52 | 2 ++ 23 files changed, 33 insertions(+) create mode 100644 ports/esp32/boards/sdkconfig.idf52 diff --git a/ports/esp32/CMakeLists.txt b/ports/esp32/CMakeLists.txt index 94047a0482d28..1537c1d723276 100644 --- a/ports/esp32/CMakeLists.txt +++ b/ports/esp32/CMakeLists.txt @@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 3.12) +# Retrieve IDF version +include($ENV{IDF_PATH}/tools/cmake/version.cmake) +set(IDF_VERSION "${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}.${IDF_VERSION_PATCH}") + # Set the board if it's not already set. if(NOT MICROPY_BOARD) set(MICROPY_BOARD ESP32_GENERIC) @@ -21,6 +25,12 @@ set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig) # Save the manifest file set from the cmake command line. set(MICROPY_USER_FROZEN_MANIFEST ${MICROPY_FROZEN_MANIFEST}) +# Specific options for IDF v5.2 and later +set(SDKCONFIG_IDF_VERSION_SPECIFIC "") +if (IDF_VERSION VERSION_GREATER_EQUAL "5.2.0") + set(SDKCONFIG_IDF_VERSION_SPECIFIC boards/sdkconfig.idf52) +endif() + # Include board config; this is expected to set (among other options): # - SDKCONFIG_DEFAULTS # - IDF_TARGET diff --git a/ports/esp32/boards/ARDUINO_NANO_ESP32/mpconfigboard.cmake b/ports/esp32/boards/ARDUINO_NANO_ESP32/mpconfigboard.cmake index 7ae4b38185353..40456f7c0b8a9 100644 --- a/ports/esp32/boards/ARDUINO_NANO_ESP32/mpconfigboard.cmake +++ b/ports/esp32/boards/ARDUINO_NANO_ESP32/mpconfigboard.cmake @@ -6,6 +6,7 @@ set(IDF_TARGET esp32s3) set(SDKCONFIG_DEFAULTS boards/sdkconfig.base + ${SDKCONFIG_IDF_VERSION_SPECIFIC} boards/sdkconfig.usb boards/sdkconfig.ble boards/sdkconfig.240mhz diff --git a/ports/esp32/boards/ESP32_GENERIC/mpconfigboard.cmake b/ports/esp32/boards/ESP32_GENERIC/mpconfigboard.cmake index 0e1945dd8c5a0..a3e8f616bc009 100644 --- a/ports/esp32/boards/ESP32_GENERIC/mpconfigboard.cmake +++ b/ports/esp32/boards/ESP32_GENERIC/mpconfigboard.cmake @@ -1,5 +1,6 @@ set(SDKCONFIG_DEFAULTS boards/sdkconfig.base + ${SDKCONFIG_IDF_VERSION_SPECIFIC} boards/sdkconfig.ble ) diff --git a/ports/esp32/boards/ESP32_GENERIC_C3/mpconfigboard.cmake b/ports/esp32/boards/ESP32_GENERIC_C3/mpconfigboard.cmake index 429366afac979..8c9d7c27a1174 100644 --- a/ports/esp32/boards/ESP32_GENERIC_C3/mpconfigboard.cmake +++ b/ports/esp32/boards/ESP32_GENERIC_C3/mpconfigboard.cmake @@ -2,6 +2,7 @@ set(IDF_TARGET esp32c3) set(SDKCONFIG_DEFAULTS boards/sdkconfig.base + ${SDKCONFIG_IDF_VERSION_SPECIFIC} boards/sdkconfig.ble boards/ESP32_GENERIC_C3/sdkconfig.c3usb ) diff --git a/ports/esp32/boards/ESP32_GENERIC_S2/mpconfigboard.cmake b/ports/esp32/boards/ESP32_GENERIC_S2/mpconfigboard.cmake index 76d185d90d5fc..c9bc60d4cb57b 100644 --- a/ports/esp32/boards/ESP32_GENERIC_S2/mpconfigboard.cmake +++ b/ports/esp32/boards/ESP32_GENERIC_S2/mpconfigboard.cmake @@ -2,6 +2,7 @@ set(IDF_TARGET esp32s2) set(SDKCONFIG_DEFAULTS boards/sdkconfig.base + ${SDKCONFIG_IDF_VERSION_SPECIFIC} boards/sdkconfig.usb boards/sdkconfig.spiram_sx ) diff --git a/ports/esp32/boards/ESP32_GENERIC_S3/mpconfigboard.cmake b/ports/esp32/boards/ESP32_GENERIC_S3/mpconfigboard.cmake index 36b4fe56240de..c60f1c280a3ee 100644 --- a/ports/esp32/boards/ESP32_GENERIC_S3/mpconfigboard.cmake +++ b/ports/esp32/boards/ESP32_GENERIC_S3/mpconfigboard.cmake @@ -2,6 +2,7 @@ set(IDF_TARGET esp32s3) set(SDKCONFIG_DEFAULTS boards/sdkconfig.base + ${SDKCONFIG_IDF_VERSION_SPECIFIC} boards/sdkconfig.usb boards/sdkconfig.ble boards/sdkconfig.spiram_sx diff --git a/ports/esp32/boards/LILYGO_TTGO_LORA32/mpconfigboard.cmake b/ports/esp32/boards/LILYGO_TTGO_LORA32/mpconfigboard.cmake index 5bbac10e22f10..42c431681ef11 100644 --- a/ports/esp32/boards/LILYGO_TTGO_LORA32/mpconfigboard.cmake +++ b/ports/esp32/boards/LILYGO_TTGO_LORA32/mpconfigboard.cmake @@ -1,5 +1,6 @@ set(SDKCONFIG_DEFAULTS boards/sdkconfig.base + ${SDKCONFIG_IDF_VERSION_SPECIFIC} boards/sdkconfig.ble ) diff --git a/ports/esp32/boards/LOLIN_C3_MINI/mpconfigboard.cmake b/ports/esp32/boards/LOLIN_C3_MINI/mpconfigboard.cmake index 0ce7f85e5d580..7767e3b8497fb 100644 --- a/ports/esp32/boards/LOLIN_C3_MINI/mpconfigboard.cmake +++ b/ports/esp32/boards/LOLIN_C3_MINI/mpconfigboard.cmake @@ -2,6 +2,7 @@ set(IDF_TARGET esp32c3) set(SDKCONFIG_DEFAULTS boards/sdkconfig.base + ${SDKCONFIG_IDF_VERSION_SPECIFIC} boards/sdkconfig.ble boards/LOLIN_C3_MINI/sdkconfig.board ) diff --git a/ports/esp32/boards/LOLIN_S2_MINI/mpconfigboard.cmake b/ports/esp32/boards/LOLIN_S2_MINI/mpconfigboard.cmake index dc9abd7478bca..8be4a69d72e75 100644 --- a/ports/esp32/boards/LOLIN_S2_MINI/mpconfigboard.cmake +++ b/ports/esp32/boards/LOLIN_S2_MINI/mpconfigboard.cmake @@ -2,6 +2,7 @@ set(IDF_TARGET esp32s2) set(SDKCONFIG_DEFAULTS boards/sdkconfig.base + ${SDKCONFIG_IDF_VERSION_SPECIFIC} boards/sdkconfig.spiram_sx boards/sdkconfig.usb ) diff --git a/ports/esp32/boards/LOLIN_S2_PICO/mpconfigboard.cmake b/ports/esp32/boards/LOLIN_S2_PICO/mpconfigboard.cmake index dc9abd7478bca..8be4a69d72e75 100644 --- a/ports/esp32/boards/LOLIN_S2_PICO/mpconfigboard.cmake +++ b/ports/esp32/boards/LOLIN_S2_PICO/mpconfigboard.cmake @@ -2,6 +2,7 @@ set(IDF_TARGET esp32s2) set(SDKCONFIG_DEFAULTS boards/sdkconfig.base + ${SDKCONFIG_IDF_VERSION_SPECIFIC} boards/sdkconfig.spiram_sx boards/sdkconfig.usb ) diff --git a/ports/esp32/boards/M5STACK_ATOM/mpconfigboard.cmake b/ports/esp32/boards/M5STACK_ATOM/mpconfigboard.cmake index f0355e2b0388b..19b55d1659786 100644 --- a/ports/esp32/boards/M5STACK_ATOM/mpconfigboard.cmake +++ b/ports/esp32/boards/M5STACK_ATOM/mpconfigboard.cmake @@ -1,5 +1,6 @@ set(SDKCONFIG_DEFAULTS boards/sdkconfig.base + ${SDKCONFIG_IDF_VERSION_SPECIFIC} boards/sdkconfig.ble boards/sdkconfig.240mhz boards/M5STACK_ATOM/sdkconfig.board diff --git a/ports/esp32/boards/OLIMEX_ESP32_POE/mpconfigboard.cmake b/ports/esp32/boards/OLIMEX_ESP32_POE/mpconfigboard.cmake index c460b07d5efac..59d2831b3e0d9 100644 --- a/ports/esp32/boards/OLIMEX_ESP32_POE/mpconfigboard.cmake +++ b/ports/esp32/boards/OLIMEX_ESP32_POE/mpconfigboard.cmake @@ -1,5 +1,6 @@ set(SDKCONFIG_DEFAULTS boards/sdkconfig.base + ${SDKCONFIG_IDF_VERSION_SPECIFIC} boards/sdkconfig.ble boards/OLIMEX_ESP32_POE/sdkconfig.board ) diff --git a/ports/esp32/boards/SIL_WESP32/mpconfigboard.cmake b/ports/esp32/boards/SIL_WESP32/mpconfigboard.cmake index a1460397b818b..9caef1123ccd6 100644 --- a/ports/esp32/boards/SIL_WESP32/mpconfigboard.cmake +++ b/ports/esp32/boards/SIL_WESP32/mpconfigboard.cmake @@ -1,5 +1,6 @@ set(SDKCONFIG_DEFAULTS boards/sdkconfig.base + ${SDKCONFIG_IDF_VERSION_SPECIFIC} boards/sdkconfig.ble boards/sdkconfig.240mhz boards/SIL_WESP32/sdkconfig.board diff --git a/ports/esp32/boards/UM_FEATHERS2/mpconfigboard.cmake b/ports/esp32/boards/UM_FEATHERS2/mpconfigboard.cmake index 5e570d513bb47..e3bcba9f509e7 100644 --- a/ports/esp32/boards/UM_FEATHERS2/mpconfigboard.cmake +++ b/ports/esp32/boards/UM_FEATHERS2/mpconfigboard.cmake @@ -1,6 +1,7 @@ set(IDF_TARGET esp32s2) set(SDKCONFIG_DEFAULTS boards/sdkconfig.base + ${SDKCONFIG_IDF_VERSION_SPECIFIC} boards/sdkconfig.spiram_sx boards/sdkconfig.usb boards/UM_FEATHERS2/sdkconfig.board diff --git a/ports/esp32/boards/UM_FEATHERS2NEO/mpconfigboard.cmake b/ports/esp32/boards/UM_FEATHERS2NEO/mpconfigboard.cmake index c98ef691769b5..fc7f246a7ee0f 100644 --- a/ports/esp32/boards/UM_FEATHERS2NEO/mpconfigboard.cmake +++ b/ports/esp32/boards/UM_FEATHERS2NEO/mpconfigboard.cmake @@ -1,6 +1,7 @@ set(IDF_TARGET esp32s2) set(SDKCONFIG_DEFAULTS boards/sdkconfig.base + ${SDKCONFIG_IDF_VERSION_SPECIFIC} boards/sdkconfig.spiram_sx boards/sdkconfig.usb boards/UM_FEATHERS2NEO/sdkconfig.board diff --git a/ports/esp32/boards/UM_FEATHERS3/mpconfigboard.cmake b/ports/esp32/boards/UM_FEATHERS3/mpconfigboard.cmake index 63d1af1da76ca..d7fcc34694853 100644 --- a/ports/esp32/boards/UM_FEATHERS3/mpconfigboard.cmake +++ b/ports/esp32/boards/UM_FEATHERS3/mpconfigboard.cmake @@ -2,6 +2,7 @@ set(IDF_TARGET esp32s3) set(SDKCONFIG_DEFAULTS boards/sdkconfig.base + ${SDKCONFIG_IDF_VERSION_SPECIFIC} boards/sdkconfig.usb boards/sdkconfig.ble boards/sdkconfig.240mhz diff --git a/ports/esp32/boards/UM_NANOS3/mpconfigboard.cmake b/ports/esp32/boards/UM_NANOS3/mpconfigboard.cmake index 6c7f34009e432..9030d837289c3 100644 --- a/ports/esp32/boards/UM_NANOS3/mpconfigboard.cmake +++ b/ports/esp32/boards/UM_NANOS3/mpconfigboard.cmake @@ -2,6 +2,7 @@ set(IDF_TARGET esp32s3) set(SDKCONFIG_DEFAULTS boards/sdkconfig.base + ${SDKCONFIG_IDF_VERSION_SPECIFIC} boards/sdkconfig.usb boards/sdkconfig.ble boards/sdkconfig.240mhz diff --git a/ports/esp32/boards/UM_PROS3/mpconfigboard.cmake b/ports/esp32/boards/UM_PROS3/mpconfigboard.cmake index 41a96f26e34c4..8bd67567ffdad 100644 --- a/ports/esp32/boards/UM_PROS3/mpconfigboard.cmake +++ b/ports/esp32/boards/UM_PROS3/mpconfigboard.cmake @@ -2,6 +2,7 @@ set(IDF_TARGET esp32s3) set(SDKCONFIG_DEFAULTS boards/sdkconfig.base + ${SDKCONFIG_IDF_VERSION_SPECIFIC} boards/sdkconfig.usb boards/sdkconfig.ble boards/sdkconfig.240mhz diff --git a/ports/esp32/boards/UM_TINYPICO/mpconfigboard.cmake b/ports/esp32/boards/UM_TINYPICO/mpconfigboard.cmake index 58b42b55eb7fb..c85fb9d723b06 100644 --- a/ports/esp32/boards/UM_TINYPICO/mpconfigboard.cmake +++ b/ports/esp32/boards/UM_TINYPICO/mpconfigboard.cmake @@ -1,5 +1,6 @@ set(SDKCONFIG_DEFAULTS boards/sdkconfig.base + ${SDKCONFIG_IDF_VERSION_SPECIFIC} boards/sdkconfig.ble boards/sdkconfig.240mhz boards/sdkconfig.spiram diff --git a/ports/esp32/boards/UM_TINYS2/mpconfigboard.cmake b/ports/esp32/boards/UM_TINYS2/mpconfigboard.cmake index 70cb4a814ff24..1c794baeed6a3 100644 --- a/ports/esp32/boards/UM_TINYS2/mpconfigboard.cmake +++ b/ports/esp32/boards/UM_TINYS2/mpconfigboard.cmake @@ -1,6 +1,7 @@ set(IDF_TARGET esp32s2) set(SDKCONFIG_DEFAULTS boards/sdkconfig.base + ${SDKCONFIG_IDF_VERSION_SPECIFIC} boards/sdkconfig.spiram_sx boards/sdkconfig.usb boards/UM_TINYS2/sdkconfig.board diff --git a/ports/esp32/boards/UM_TINYS3/mpconfigboard.cmake b/ports/esp32/boards/UM_TINYS3/mpconfigboard.cmake index 6c7f34009e432..9030d837289c3 100644 --- a/ports/esp32/boards/UM_TINYS3/mpconfigboard.cmake +++ b/ports/esp32/boards/UM_TINYS3/mpconfigboard.cmake @@ -2,6 +2,7 @@ set(IDF_TARGET esp32s3) set(SDKCONFIG_DEFAULTS boards/sdkconfig.base + ${SDKCONFIG_IDF_VERSION_SPECIFIC} boards/sdkconfig.usb boards/sdkconfig.ble boards/sdkconfig.240mhz diff --git a/ports/esp32/boards/UM_TINYWATCHS3/mpconfigboard.cmake b/ports/esp32/boards/UM_TINYWATCHS3/mpconfigboard.cmake index 089149c44c54d..e788dc965d150 100644 --- a/ports/esp32/boards/UM_TINYWATCHS3/mpconfigboard.cmake +++ b/ports/esp32/boards/UM_TINYWATCHS3/mpconfigboard.cmake @@ -2,6 +2,7 @@ set(IDF_TARGET esp32s3) set(SDKCONFIG_DEFAULTS boards/sdkconfig.base + ${SDKCONFIG_IDF_VERSION_SPECIFIC} boards/sdkconfig.usb boards/sdkconfig.ble boards/sdkconfig.240mhz diff --git a/ports/esp32/boards/sdkconfig.idf52 b/ports/esp32/boards/sdkconfig.idf52 new file mode 100644 index 0000000000000..49b7317d4d69f --- /dev/null +++ b/ports/esp32/boards/sdkconfig.idf52 @@ -0,0 +1,2 @@ +CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP=n +CONFIG_FREERTOS_TASK_PRE_DELETION_HOOK=y From 9fc450689b7505a44460bd6cc3a25961e1e4306e Mon Sep 17 00:00:00 2001 From: Trent Piepho Date: Sat, 2 Mar 2024 01:10:20 -0800 Subject: [PATCH 199/408] esp32/mpconfigport: Don't hang when machine.bootloader isn't supported. Currently only the Arduino Nano ESP32 defines a machine.bootloader handler for ESP32. All other boards will intentionally hang. There is no error message, nor is a NotImplementedError raised. There's no indication if Micropython has crashed, or if the bootloader was entered but USB is not working, which is a real problem the ESP32 bootloader has. It's not possible escape from this hang with ^C or any other means besides physical access to the reset pin or the ability to cycle power. Change this to only define an implementation of machine.bootloader() when there is a handler for it. Signed-off-by: Trent Piepho --- ports/esp32/modmachine.c | 2 ++ ports/esp32/mpconfigport.h | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) mode change 100755 => 100644 ports/esp32/modmachine.c diff --git a/ports/esp32/modmachine.c b/ports/esp32/modmachine.c old mode 100755 new mode 100644 index 6e6a57896814c..a61d381e03d96 --- a/ports/esp32/modmachine.c +++ b/ports/esp32/modmachine.c @@ -220,11 +220,13 @@ static mp_int_t mp_machine_reset_cause(void) { } } +#ifdef MICROPY_BOARD_ENTER_BOOTLOADER NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) { MICROPY_BOARD_ENTER_BOOTLOADER(n_args, args); for (;;) { } } +#endif void machine_init(void) { is_soft_reset = 0; diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h index be02d45883bcd..0474b7eafd3c0 100644 --- a/ports/esp32/mpconfigport.h +++ b/ports/esp32/mpconfigport.h @@ -115,7 +115,6 @@ #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MACHINE_INCLUDEFILE "ports/esp32/modmachine.c" #define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1) -#define MICROPY_PY_MACHINE_BOOTLOADER (1) #define MICROPY_PY_MACHINE_DISABLE_IRQ_ENABLE_IRQ (1) #define MICROPY_PY_MACHINE_ADC (1) #define MICROPY_PY_MACHINE_ADC_INCLUDEFILE "ports/esp32/machine_adc.c" @@ -269,8 +268,10 @@ typedef long mp_off_t; #define MICROPY_HW_ENABLE_MDNS_RESPONDER (1) #endif -#ifndef MICROPY_BOARD_ENTER_BOOTLOADER -#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args) +#ifdef MICROPY_BOARD_ENTER_BOOTLOADER +#define MICROPY_PY_MACHINE_BOOTLOADER (1) +#else +#define MICROPY_PY_MACHINE_BOOTLOADER (0) #endif #ifndef MICROPY_BOARD_STARTUP From af67be7adc4b76fead096fecd445ddeb6cc2c513 Mon Sep 17 00:00:00 2001 From: Trent Piepho Date: Sat, 2 Mar 2024 01:25:10 -0800 Subject: [PATCH 200/408] esp32/modmachine: Support bootloader on ESP32-S2/S3/C2/C3. On these targets it's possible to enter the bootloader by setting a bit in an RTC register before resetting. Structure it in a way that a board can still provide a custom bootloader handler. The handler here will be the default if none is provided, for any board based on the supported targets. Signed-off-by: Trent Piepho --- ports/esp32/modmachine.c | 8 ++++++++ ports/esp32/mpconfigport.h | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/ports/esp32/modmachine.c b/ports/esp32/modmachine.c index a61d381e03d96..759455a59a5d6 100644 --- a/ports/esp32/modmachine.c +++ b/ports/esp32/modmachine.c @@ -220,6 +220,14 @@ static mp_int_t mp_machine_reset_cause(void) { } } +#if MICROPY_ESP32_USE_BOOTLOADER_RTC +#include "soc/rtc_cntl_reg.h" +NORETURN static void machine_bootloader_rtc(void) { + REG_WRITE(RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT); + esp_restart(); +} +#endif + #ifdef MICROPY_BOARD_ENTER_BOOTLOADER NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args) { MICROPY_BOARD_ENTER_BOOTLOADER(n_args, args); diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h index 0474b7eafd3c0..f004c78b0aef9 100644 --- a/ports/esp32/mpconfigport.h +++ b/ports/esp32/mpconfigport.h @@ -268,6 +268,14 @@ typedef long mp_off_t; #define MICROPY_HW_ENABLE_MDNS_RESPONDER (1) #endif +#ifndef MICROPY_BOARD_ENTER_BOOTLOADER +// RTC has a register to trigger bootloader on these targets +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 +#define MICROPY_ESP32_USE_BOOTLOADER_RTC (1) +#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args) machine_bootloader_rtc() +#endif +#endif + #ifdef MICROPY_BOARD_ENTER_BOOTLOADER #define MICROPY_PY_MACHINE_BOOTLOADER (1) #else From cdfc6c159f6b51f67fd314a1dd4a61d5c18d5d93 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Sun, 3 Mar 2024 12:54:33 +0100 Subject: [PATCH 201/408] esp32/network_lan: Add a separate argument to set PHY power pin. Prior to this commit, the pin defined for power would be used by the esp_idf driver to reset the PHY. That worked, but sometimes the MDIO configuration started before the power was fully settled, leading to an error. With the change in this commit, the power for the PHY is independently enabled in network_lan.c with a 100ms delay to allow the power to settle. A separate define for a reset pin is provided, even if the PHY reset pin is rarely connected. Fixes issue #14013. Signed-off-by: robert-hh --- docs/esp32/quickref.rst | 1 + ports/esp32/network_lan.c | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/esp32/quickref.rst b/docs/esp32/quickref.rst index 9c77dc402ebef..6c07c584d325e 100644 --- a/docs/esp32/quickref.rst +++ b/docs/esp32/quickref.rst @@ -128,6 +128,7 @@ The keyword arguments for the constructor defining the PHY type and interface ar - mdc=pin-object # set the mdc and mdio pins. - mdio=pin-object +- reset=pin-object # set the reset pin of the PHY device. - power=pin-object # set the pin which switches the power of the PHY device. - phy_type= # Select the PHY device type. Supported devices are PHY_LAN8710, PHY_LAN8720, PH_IP101, PHY_RTL8201, PHY_DP83848 and PHY_KSZ8041 diff --git a/ports/esp32/network_lan.c b/ports/esp32/network_lan.c index d7d9a9f7ac540..570c9a4afdefb 100644 --- a/ports/esp32/network_lan.c +++ b/ports/esp32/network_lan.c @@ -51,6 +51,7 @@ typedef struct _lan_if_obj_t { bool initialized; int8_t mdc_pin; int8_t mdio_pin; + int8_t phy_reset_pin; int8_t phy_power_pin; int8_t phy_cs_pin; int8_t phy_int_pin; @@ -99,12 +100,13 @@ static mp_obj_t get_lan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar return MP_OBJ_FROM_PTR(&lan_obj); } - enum { ARG_id, ARG_mdc, ARG_mdio, ARG_power, ARG_phy_addr, ARG_phy_type, + enum { ARG_id, ARG_mdc, ARG_mdio, ARG_reset, ARG_power, ARG_phy_addr, ARG_phy_type, ARG_spi, ARG_cs, ARG_int, ARG_ref_clk_mode, ARG_ref_clk }; static const mp_arg_t allowed_args[] = { { MP_QSTR_id, MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_mdc, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_mdio, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, + { MP_QSTR_reset, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_power, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_phy_addr, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_INT }, { MP_QSTR_phy_type, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_INT }, @@ -128,6 +130,7 @@ static mp_obj_t get_lan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar self->mdc_pin = GET_PIN(ARG_mdc); self->mdio_pin = GET_PIN(ARG_mdio); + self->phy_reset_pin = GET_PIN(ARG_reset); self->phy_power_pin = GET_PIN(ARG_power); self->phy_cs_pin = GET_PIN(ARG_cs); self->phy_int_pin = GET_PIN(ARG_int); @@ -179,8 +182,15 @@ static mp_obj_t get_lan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); phy_config.phy_addr = self->phy_addr; - phy_config.reset_gpio_num = self->phy_power_pin; + phy_config.reset_gpio_num = self->phy_reset_pin; self->phy = NULL; + // Switch on the power before PHY is reset + if (self->phy_power_pin >= 0) { + mp_hal_pin_output(self->phy_power_pin); + mp_hal_pin_write(self->phy_power_pin, 1); + // let the power settle + mp_hal_delay_ms(100); + } #if CONFIG_ETH_USE_SPI_ETHERNET spi_device_interface_config_t devcfg = { .mode = 0, From 20f85fb26e2b08b2e6114f31ea05d3da759432eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20de=20Giessen?= Date: Tue, 12 Dec 2023 15:59:46 +0100 Subject: [PATCH 202/408] esp32/machine_uart: Always configure timeout_char setting in init(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the `timeout_char` parameter is not given, we should still configure the UART to ensure the UART is always initialized consistently. So the default of 0 gets applied correctly, or if, for example, the baudrate was changed the char timeout isn't still based on the old baudrate causing weird behaviour, etc. Signed-off-by: Daniël van de Giessen --- ports/esp32/machine_uart.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ports/esp32/machine_uart.c b/ports/esp32/machine_uart.c index b5c5c016a5c69..50c9a19bef1bb 100644 --- a/ports/esp32/machine_uart.c +++ b/ports/esp32/machine_uart.c @@ -277,17 +277,17 @@ static void mp_machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, } // set timeout_char - // make sure it is at least as long as a whole character (12 bits here) if (args[ARG_timeout_char].u_int != -1) { self->timeout_char = args[ARG_timeout_char].u_int; - uint32_t char_time_ms = 12000 / baudrate + 1; - uint32_t rx_timeout = self->timeout_char / char_time_ms; - if (rx_timeout < 1) { - check_esp_err(uart_set_rx_full_threshold(self->uart_num, 1)); - check_esp_err(uart_set_rx_timeout(self->uart_num, 1)); - } else { - check_esp_err(uart_set_rx_timeout(self->uart_num, rx_timeout)); - } + } + // make sure it is at least as long as a whole character (12 bits here) + uint32_t char_time_ms = 12000 / baudrate + 1; + uint32_t rx_timeout = self->timeout_char / char_time_ms; + if (rx_timeout < 1) { + check_esp_err(uart_set_rx_full_threshold(self->uart_num, 1)); + check_esp_err(uart_set_rx_timeout(self->uart_num, 1)); + } else { + check_esp_err(uart_set_rx_timeout(self->uart_num, rx_timeout)); } // set line inversion From bedb649edf9a4e0d451daccda72ae35634b80dde Mon Sep 17 00:00:00 2001 From: Stanislav Ponomarev Date: Tue, 27 Feb 2024 00:26:17 +0400 Subject: [PATCH 203/408] esp32/boards/ESP32_GENERIC_S3: Add 4MiB partitioning board variant. Added a 4MiB flash partitioning variant for ESP32S3: adds support for 4MiB discrete flash boards or ESP32-S3FH4R2 with embedded 4MiB flash based ones. Tested on the waveshare ESP32-S3 Mini w/ESP32-S3FH4R2. Signed-off-by: Stanislav Ponomarev --- ports/esp32/boards/ESP32_GENERIC_S3/board.json | 3 ++- ports/esp32/boards/ESP32_GENERIC_S3/board.md | 4 +++- ports/esp32/boards/ESP32_GENERIC_S3/mpconfigboard.cmake | 7 +++++++ ports/esp32/boards/ESP32_GENERIC_S3/sdkconfig.flash_4m | 4 ++++ 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 ports/esp32/boards/ESP32_GENERIC_S3/sdkconfig.flash_4m diff --git a/ports/esp32/boards/ESP32_GENERIC_S3/board.json b/ports/esp32/boards/ESP32_GENERIC_S3/board.json index 671936c922ce0..c9794dba86131 100644 --- a/ports/esp32/boards/ESP32_GENERIC_S3/board.json +++ b/ports/esp32/boards/ESP32_GENERIC_S3/board.json @@ -18,6 +18,7 @@ "url": "https://www.espressif.com/en/products/modules", "vendor": "Espressif", "variants": { - "SPIRAM_OCT": "Support for Octal-SPIRAM" + "SPIRAM_OCT": "Support for Octal-SPIRAM", + "FLASH_4M": "4MiB flash" } } diff --git a/ports/esp32/boards/ESP32_GENERIC_S3/board.md b/ports/esp32/boards/ESP32_GENERIC_S3/board.md index cc902eeb89fee..16930c9193c51 100644 --- a/ports/esp32/boards/ESP32_GENERIC_S3/board.md +++ b/ports/esp32/boards/ESP32_GENERIC_S3/board.md @@ -1,7 +1,9 @@ The following files are firmware that should work on most ESP32-S3-based -boards with 8MiB of flash, including WROOM and MINI modules. +boards with 4/8MiB of flash, including WROOM and MINI modules. This firmware supports configurations with and without SPIRAM (also known as PSRAM) and will auto-detect a connected SPIRAM chip at startup and allocate the MicroPython heap accordingly. However if your board has Octal SPIRAM, then use the "spiram-oct" variant. + +If your board has 4MiB flash (including ESP32-S3FH4R2 based ones with embedded flash), then use the "flash-4m" build. diff --git a/ports/esp32/boards/ESP32_GENERIC_S3/mpconfigboard.cmake b/ports/esp32/boards/ESP32_GENERIC_S3/mpconfigboard.cmake index c60f1c280a3ee..1f7440353b6cc 100644 --- a/ports/esp32/boards/ESP32_GENERIC_S3/mpconfigboard.cmake +++ b/ports/esp32/boards/ESP32_GENERIC_S3/mpconfigboard.cmake @@ -20,3 +20,10 @@ if(MICROPY_BOARD_VARIANT STREQUAL "SPIRAM_OCT") MICROPY_HW_BOARD_NAME="Generic ESP32S3 module with Octal-SPIRAM" ) endif() + +if(MICROPY_BOARD_VARIANT STREQUAL "FLASH_4M") + set(SDKCONFIG_DEFAULTS + ${SDKCONFIG_DEFAULTS} + boards/ESP32_GENERIC_S3/sdkconfig.flash_4m + ) +endif() diff --git a/ports/esp32/boards/ESP32_GENERIC_S3/sdkconfig.flash_4m b/ports/esp32/boards/ESP32_GENERIC_S3/sdkconfig.flash_4m new file mode 100644 index 0000000000000..c967c46ae6bed --- /dev/null +++ b/ports/esp32/boards/ESP32_GENERIC_S3/sdkconfig.flash_4m @@ -0,0 +1,4 @@ +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +CONFIG_ESPTOOLPY_FLASHSIZE_8MB= + +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-4MiB.csv" From d712feb68a3ac8ec181ff75a4ac55997141ad075 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 8 Mar 2024 22:51:28 +1100 Subject: [PATCH 204/408] stm32/sdram: Fix MPU config to use MPU_CONFIG_NOACCESS. Followup to 2345c1a04e6d8f8a7376c2c37c0f5248f7629bbb. Signed-off-by: Damien George --- ports/stm32/sdram.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/stm32/sdram.c b/ports/stm32/sdram.c index 1e1a08e4c63bd..e99f34d2262a8 100644 --- a/ports/stm32/sdram.c +++ b/ports/stm32/sdram.c @@ -263,7 +263,7 @@ static void sdram_init_seq(SDRAM_HandleTypeDef then enable access/caching for the size used */ uint32_t irq_state = mpu_config_start(); - mpu_config_region(MPU_REGION_SDRAM1, SDRAM_START_ADDRESS, MPU_CONFIG_DISABLE(0x00, MPU_REGION_SIZE_512MB)); + mpu_config_region(MPU_REGION_SDRAM1, SDRAM_START_ADDRESS, MPU_CONFIG_NOACCESS(0x00, MPU_REGION_SIZE_512MB)); mpu_config_region(MPU_REGION_SDRAM2, SDRAM_START_ADDRESS, MPU_CONFIG_SDRAM(SDRAM_MPU_REGION_SIZE)); mpu_config_end(irq_state); #endif From 8b4a21cd64c8199601629e6ae08c746f85fdd068 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Mon, 4 Mar 2024 12:11:27 +0100 Subject: [PATCH 205/408] extmod/network_ninaw10: Activate the NIC on demand. Activate the NIC on calls to connect() or config() if it's not already active. This change makes the NINA NIC more in line with CYW43 and other NICs, which allow configuring the NIC before or after it is activated. Signed-off-by: iabdalkader --- extmod/network_ninaw10.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/extmod/network_ninaw10.c b/extmod/network_ninaw10.c index e68a7a66e27d2..e53061557cd4e 100644 --- a/extmod/network_ninaw10.c +++ b/extmod/network_ninaw10.c @@ -193,8 +193,7 @@ static mp_obj_t network_ninaw10_active(size_t n_args, const mp_obj_t *args) { nina_obj_t *self = MP_OBJ_TO_PTR(args[0]); if (n_args == 2) { bool active = mp_obj_is_true(args[1]); - network_ninaw10_deinit(); - if (active) { + if (active && !self->active) { int error = 0; if ((error = nina_init()) != 0) { mp_raise_msg_varg(&mp_type_OSError, @@ -223,7 +222,8 @@ static mp_obj_t network_ninaw10_active(size_t n_args, const mp_obj_t *args) { semver[NINA_FW_VER_MINOR_OFFS] - 48, semver[NINA_FW_VER_PATCH_OFFS] - 48); } soft_timer_static_init(&mp_wifi_poll_timer, SOFT_TIMER_MODE_ONE_SHOT, 0, network_ninaw10_timer_callback); - } else { + } else if (!active && self->active) { + network_ninaw10_deinit(); nina_deinit(); } self->active = active; @@ -289,6 +289,11 @@ static mp_obj_t network_ninaw10_connect(mp_uint_t n_args, const mp_obj_t *pos_ar mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Key can't be empty!")); } + // Activate the interface if not active. + if (!self->active) { + network_ninaw10_active(2, (mp_obj_t [2]) { pos_args[0], mp_const_true }); + } + // Disconnect active connections first. if (nina_isconnected()) { nina_disconnect(); From 2b6f81f2b9d5135774d1b636802194f9666678d5 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Mon, 4 Mar 2024 12:13:37 +0100 Subject: [PATCH 206/408] extmod/network_ninaw10: Set the proper security mode if none provided. If no security mode is provided, use WPA for station and WEP for AP. Note only WEP is supported in AP mode. Signed-off-by: iabdalkader --- extmod/network_ninaw10.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/extmod/network_ninaw10.c b/extmod/network_ninaw10.c index e53061557cd4e..6a60faeae9881 100644 --- a/extmod/network_ninaw10.c +++ b/extmod/network_ninaw10.c @@ -260,7 +260,7 @@ static mp_obj_t network_ninaw10_connect(mp_uint_t n_args, const mp_obj_t *pos_ar static const mp_arg_t allowed_args[] = { { MP_QSTR_ssid, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_key, MP_ARG_OBJ, {.u_obj = mp_const_none} }, - { MP_QSTR_security, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = NINA_SEC_WPA_PSK} }, + { MP_QSTR_security, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, { MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} }, }; @@ -276,15 +276,21 @@ static mp_obj_t network_ninaw10_connect(mp_uint_t n_args, const mp_obj_t *pos_ar mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("SSID can't be empty!")); } - // get key and sec + // get encryption key const char *key = NULL; - mp_uint_t security = NINA_SEC_OPEN; - if (args[ARG_key].u_obj != mp_const_none) { key = mp_obj_str_get_str(args[ARG_key].u_obj); - security = args[ARG_security].u_int; } + // get security mode + mp_uint_t security = args[ARG_security].u_int; + if (security == -1 && self->itf == MOD_NETWORK_STA_IF) { + security = NINA_SEC_WPA_PSK; + } else if (security == -1 && self->itf == MOD_NETWORK_AP_IF) { + security = NINA_SEC_WEP; + } + + // Ensure that the key is not empty if a security mode is used. if (security != NINA_SEC_OPEN && strlen(key) == 0) { mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Key can't be empty!")); } @@ -316,7 +322,7 @@ static mp_obj_t network_ninaw10_connect(mp_uint_t n_args, const mp_obj_t *pos_ar mp_uint_t channel = args[ARG_channel].u_int; if (security != NINA_SEC_OPEN && security != NINA_SEC_WEP) { - mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("AP mode supports WEP security only.")); + mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("AP mode only supports WEP or OPEN security modes")); } // Initialize WiFi in AP mode. From c231c896519fa1b925d4465ed3d4bea437758854 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Thu, 14 Mar 2024 10:27:37 +0100 Subject: [PATCH 207/408] extmod/network_ninaw10: Fix error messages. Signed-off-by: iabdalkader --- extmod/network_ninaw10.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/extmod/network_ninaw10.c b/extmod/network_ninaw10.c index 6a60faeae9881..90cdafc7a430a 100644 --- a/extmod/network_ninaw10.c +++ b/extmod/network_ninaw10.c @@ -153,7 +153,7 @@ static void network_ninaw10_poll_connect(mp_sched_node_t *node) { debug_printf("poll_connect() status: %d reason %d\n", status, reason); if (nina_connect(self->ssid, self->security, self->key, 0) != 0) { mp_raise_msg_varg(&mp_type_OSError, - MP_ERROR_TEXT("could not connect to ssid=%s, sec=%d, key=%s\n"), + MP_ERROR_TEXT("could not connect to ssid=%s, sec=%d, key=%s"), self->ssid, self->security, self->key); } } else { @@ -197,14 +197,14 @@ static mp_obj_t network_ninaw10_active(size_t n_args, const mp_obj_t *args) { int error = 0; if ((error = nina_init()) != 0) { mp_raise_msg_varg(&mp_type_OSError, - MP_ERROR_TEXT("Failed to initialize Nina-W10 module, error: %d\n"), error); + MP_ERROR_TEXT("failed to initialize Nina-W10 module, error: %d"), error); } // check firmware version uint8_t semver[NINA_FW_VER_LEN]; if (nina_fw_version(semver) != 0) { nina_deinit(); mp_raise_msg_varg(&mp_type_OSError, - MP_ERROR_TEXT("Failed to read firmware version, error: %d\n"), error); + MP_ERROR_TEXT("failed to read firmware version, error: %d"), error); } // Check the minimum supported firmware version. uint32_t fwmin = (NINA_FW_VER_MIN_MAJOR * 100) + @@ -217,7 +217,7 @@ static mp_obj_t network_ninaw10_active(size_t n_args, const mp_obj_t *args) { if (fwver < fwmin) { mp_raise_msg_varg(&mp_type_OSError, - MP_ERROR_TEXT("Firmware version mismatch. Minimum supported firmware is v%d.%d.%d found v%d.%d.%d\n"), + MP_ERROR_TEXT("firmware version mismatch, minimum supported firmware is v%d.%d.%d found v%d.%d.%d"), NINA_FW_VER_MIN_MAJOR, NINA_FW_VER_MIN_MINOR, NINA_FW_VER_MIN_PATCH, semver[NINA_FW_VER_MAJOR_OFFS] - 48, semver[NINA_FW_VER_MINOR_OFFS] - 48, semver[NINA_FW_VER_PATCH_OFFS] - 48); } @@ -273,7 +273,7 @@ static mp_obj_t network_ninaw10_connect(mp_uint_t n_args, const mp_obj_t *pos_ar const char *ssid = mp_obj_str_get_str(args[ARG_ssid].u_obj); if (strlen(ssid) == 0) { - mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("SSID can't be empty!")); + mp_raise_ValueError(MP_ERROR_TEXT("SSID can't be empty")); } // get encryption key @@ -292,7 +292,7 @@ static mp_obj_t network_ninaw10_connect(mp_uint_t n_args, const mp_obj_t *pos_ar // Ensure that the key is not empty if a security mode is used. if (security != NINA_SEC_OPEN && strlen(key) == 0) { - mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Key can't be empty!")); + mp_raise_ValueError(MP_ERROR_TEXT("key can't be empty")); } // Activate the interface if not active. @@ -309,7 +309,7 @@ static mp_obj_t network_ninaw10_connect(mp_uint_t n_args, const mp_obj_t *pos_ar // Initialize WiFi in Station mode. if (nina_connect(ssid, security, key, 0) != 0) { mp_raise_msg_varg(&mp_type_OSError, - MP_ERROR_TEXT("could not connect to ssid=%s, sec=%d, key=%s\n"), ssid, security, key); + MP_ERROR_TEXT("could not connect to ssid=%s, sec=%d, key=%s"), ssid, security, key); } // Save connection info to re-connect if needed. From 23ccbcf23043be5e621a4e49b7dd4549af4239fc Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 14 Mar 2024 10:58:41 +1100 Subject: [PATCH 208/408] extmod/modmachine: Add MICROPY_PY_MACHINE_SIGNAL configuration option. Enabled by default. Signed-off-by: Damien George --- extmod/machine_signal.c | 9 ++++----- extmod/modmachine.c | 2 ++ py/mpconfig.h | 5 +++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/extmod/machine_signal.c b/extmod/machine_signal.c index 6295a496b3654..d2e7bc58cac07 100644 --- a/extmod/machine_signal.c +++ b/extmod/machine_signal.c @@ -24,12 +24,11 @@ * THE SOFTWARE. */ -#include "py/mpconfig.h" -#if MICROPY_PY_MACHINE - #include - #include "py/runtime.h" + +#if MICROPY_PY_MACHINE_SIGNAL + #include "extmod/modmachine.h" #include "extmod/virtpin.h" @@ -181,4 +180,4 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &signal_locals_dict ); -#endif // MICROPY_PY_MACHINE +#endif // MICROPY_PY_MACHINE_SIGNAL diff --git a/extmod/modmachine.c b/extmod/modmachine.c index 90e2a38a73cfc..6fb6b9eaf5b9b 100644 --- a/extmod/modmachine.c +++ b/extmod/modmachine.c @@ -186,7 +186,9 @@ static const mp_rom_map_elem_t machine_module_globals_table[] = { #if MICROPY_PY_MACHINE_PIN_BASE { MP_ROM_QSTR(MP_QSTR_PinBase), MP_ROM_PTR(&machine_pinbase_type) }, #endif + #if MICROPY_PY_MACHINE_SIGNAL { MP_ROM_QSTR(MP_QSTR_Signal), MP_ROM_PTR(&machine_signal_type) }, + #endif // Classes for software bus protocols. #if MICROPY_PY_MACHINE_SOFTI2C diff --git a/py/mpconfig.h b/py/mpconfig.h index 90f8e592bfe8b..8b49c9ca08e6f 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1702,6 +1702,11 @@ typedef double mp_float_t; #define MICROPY_PY_MACHINE_PULSE (0) #endif +// Whether to provide the "machine.Signal" class +#ifndef MICROPY_PY_MACHINE_SIGNAL +#define MICROPY_PY_MACHINE_SIGNAL (MICROPY_PY_MACHINE) +#endif + #ifndef MICROPY_PY_MACHINE_I2C #define MICROPY_PY_MACHINE_I2C (0) #endif From dd134e4836ceee23234b35279bb120259b350787 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 14 Mar 2024 11:01:33 +1100 Subject: [PATCH 209/408] extmod/modmachine: Add MICROPY_PY_MACHINE_MEMX configuration option. Enabled by default. Signed-off-by: Damien George --- extmod/machine_mem.c | 4 ++-- extmod/modmachine.c | 2 ++ py/mpconfig.h | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/extmod/machine_mem.c b/extmod/machine_mem.c index c8f0889b9a728..c34ece2454cab 100644 --- a/extmod/machine_mem.c +++ b/extmod/machine_mem.c @@ -27,7 +27,7 @@ #include "py/runtime.h" #include "extmod/modmachine.h" -#if MICROPY_PY_MACHINE +#if MICROPY_PY_MACHINE_MEMX // If you wish to override the functions for mapping the machine_mem read/write // address, then add a #define for MICROPY_MACHINE_MEM_GET_READ_ADDR and/or @@ -113,4 +113,4 @@ const machine_mem_obj_t machine_mem8_obj = {{&machine_mem_type}, 1}; const machine_mem_obj_t machine_mem16_obj = {{&machine_mem_type}, 2}; const machine_mem_obj_t machine_mem32_obj = {{&machine_mem_type}, 4}; -#endif // MICROPY_PY_MACHINE +#endif // MICROPY_PY_MACHINE_MEMX diff --git a/extmod/modmachine.c b/extmod/modmachine.c index 6fb6b9eaf5b9b..792652659a9ec 100644 --- a/extmod/modmachine.c +++ b/extmod/modmachine.c @@ -138,9 +138,11 @@ static const mp_rom_map_elem_t machine_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_machine) }, // Memory access objects. + #if MICROPY_PY_MACHINE_MEMX { MP_ROM_QSTR(MP_QSTR_mem8), MP_ROM_PTR(&machine_mem8_obj) }, { MP_ROM_QSTR(MP_QSTR_mem16), MP_ROM_PTR(&machine_mem16_obj) }, { MP_ROM_QSTR(MP_QSTR_mem32), MP_ROM_PTR(&machine_mem32_obj) }, + #endif // Miscellaneous functions. #if MICROPY_PY_MACHINE_BARE_METAL_FUNCS diff --git a/py/mpconfig.h b/py/mpconfig.h index 8b49c9ca08e6f..182115ed71a93 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1702,6 +1702,11 @@ typedef double mp_float_t; #define MICROPY_PY_MACHINE_PULSE (0) #endif +// Whether to provide the "machine.mem8/16/32" objects +#ifndef MICROPY_PY_MACHINE_MEMX +#define MICROPY_PY_MACHINE_MEMX (MICROPY_PY_MACHINE) +#endif + // Whether to provide the "machine.Signal" class #ifndef MICROPY_PY_MACHINE_SIGNAL #define MICROPY_PY_MACHINE_SIGNAL (MICROPY_PY_MACHINE) From bfc3dde2c9cee31c85f838d0e89780378170551d Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 14 Mar 2024 11:09:14 +1100 Subject: [PATCH 210/408] extmod/modmachine: Add MICROPY_PY_MACHINE_RESET configuration option. Disabled by default, but enabled on all boards that previously had `MICROPY_PY_MACHINE_BARE_METAL_FUNCS` enabled. Signed-off-by: Damien George --- extmod/modmachine.c | 25 ++++++++++++++++--------- ports/cc3200/mpconfigport.h | 1 + ports/esp32/mpconfigport.h | 1 + ports/esp8266/mpconfigport.h | 1 + ports/mimxrt/mpconfigport.h | 1 + ports/nrf/mpconfigport.h | 1 + ports/renesas-ra/mpconfigport.h | 1 + ports/rp2/mpconfigport.h | 1 + ports/samd/mpconfigport.h | 1 + ports/stm32/mpconfigport.h | 1 + py/mpconfig.h | 5 +++++ 11 files changed, 30 insertions(+), 9 deletions(-) diff --git a/extmod/modmachine.c b/extmod/modmachine.c index 792652659a9ec..d7e82b124dc76 100644 --- a/extmod/modmachine.c +++ b/extmod/modmachine.c @@ -43,10 +43,13 @@ static void mp_machine_idle(void); NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args); #endif -#if MICROPY_PY_MACHINE_BARE_METAL_FUNCS -static mp_obj_t mp_machine_unique_id(void); +#if MICROPY_PY_MACHINE_RESET NORETURN static void mp_machine_reset(void); static mp_int_t mp_machine_reset_cause(void); +#endif + +#if MICROPY_PY_MACHINE_BARE_METAL_FUNCS +static mp_obj_t mp_machine_unique_id(void); static mp_obj_t mp_machine_get_freq(void); static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args); static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args); @@ -77,12 +80,7 @@ static mp_obj_t machine_idle(void) { } static MP_DEFINE_CONST_FUN_OBJ_0(machine_idle_obj, machine_idle); -#if MICROPY_PY_MACHINE_BARE_METAL_FUNCS - -static mp_obj_t machine_unique_id(void) { - return mp_machine_unique_id(); -} -MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id); +#if MICROPY_PY_MACHINE_RESET NORETURN static mp_obj_t machine_reset(void) { mp_machine_reset(); @@ -94,6 +92,15 @@ static mp_obj_t machine_reset_cause(void) { } MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause); +#endif + +#if MICROPY_PY_MACHINE_BARE_METAL_FUNCS + +static mp_obj_t machine_unique_id(void) { + return mp_machine_unique_id(); +} +MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id); + static mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) { if (n_args == 0) { return mp_machine_get_freq(); @@ -154,7 +161,7 @@ static const mp_rom_map_elem_t machine_module_globals_table[] = { #if MICROPY_PY_MACHINE_BOOTLOADER { MP_ROM_QSTR(MP_QSTR_bootloader), MP_ROM_PTR(&machine_bootloader_obj) }, #endif - #if MICROPY_PY_MACHINE_BARE_METAL_FUNCS + #if MICROPY_PY_MACHINE_RESET { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) }, { MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) }, #endif diff --git a/ports/cc3200/mpconfigport.h b/ports/cc3200/mpconfigport.h index 9cbc1afc0b092..f1ba4bedd002e 100644 --- a/ports/cc3200/mpconfigport.h +++ b/ports/cc3200/mpconfigport.h @@ -127,6 +127,7 @@ #define MICROPY_PY_VFS (1) #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MACHINE_INCLUDEFILE "ports/cc3200/mods/modmachine.c" +#define MICROPY_PY_MACHINE_RESET (1) #define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1) #define MICROPY_PY_MACHINE_DISABLE_IRQ_ENABLE_IRQ (1) #define MICROPY_PY_MACHINE_WDT (1) diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h index f004c78b0aef9..0afb12f85c1ac 100644 --- a/ports/esp32/mpconfigport.h +++ b/ports/esp32/mpconfigport.h @@ -114,6 +114,7 @@ #define MICROPY_PY_OS_URANDOM (1) #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MACHINE_INCLUDEFILE "ports/esp32/modmachine.c" +#define MICROPY_PY_MACHINE_RESET (1) #define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1) #define MICROPY_PY_MACHINE_DISABLE_IRQ_ENABLE_IRQ (1) #define MICROPY_PY_MACHINE_ADC (1) diff --git a/ports/esp8266/mpconfigport.h b/ports/esp8266/mpconfigport.h index bbfab64fba8c9..6504127755e85 100644 --- a/ports/esp8266/mpconfigport.h +++ b/ports/esp8266/mpconfigport.h @@ -66,6 +66,7 @@ #define MICROPY_PY_LWIP_SOCK_RAW (1) #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MACHINE_INCLUDEFILE "ports/esp8266/modmachine.c" +#define MICROPY_PY_MACHINE_RESET (1) #define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1) #define MICROPY_PY_MACHINE_DISABLE_IRQ_ENABLE_IRQ (1) #define MICROPY_PY_MACHINE_ADC (1) diff --git a/ports/mimxrt/mpconfigport.h b/ports/mimxrt/mpconfigport.h index c67b010c01acb..540357fa84209 100644 --- a/ports/mimxrt/mpconfigport.h +++ b/ports/mimxrt/mpconfigport.h @@ -79,6 +79,7 @@ uint32_t trng_random_u32(void); #define MICROPY_PY_RANDOM_SEED_INIT_FUNC (trng_random_u32()) #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MACHINE_INCLUDEFILE "ports/mimxrt/modmachine.c" +#define MICROPY_PY_MACHINE_RESET (1) #define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1) #define MICROPY_PY_MACHINE_BOOTLOADER (1) #define MICROPY_PY_MACHINE_DISABLE_IRQ_ENABLE_IRQ (1) diff --git a/ports/nrf/mpconfigport.h b/ports/nrf/mpconfigport.h index 30625382e43c2..37fbdf1eb3b29 100644 --- a/ports/nrf/mpconfigport.h +++ b/ports/nrf/mpconfigport.h @@ -174,6 +174,7 @@ #define MICROPY_PY_TIME (1) #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MACHINE_INCLUDEFILE "ports/nrf/modules/machine/modmachine.c" +#define MICROPY_PY_MACHINE_RESET (1) #define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1) #define MICROPY_PY_MACHINE_BOOTLOADER (1) #define MICROPY_PY_MACHINE_PULSE (0) diff --git a/ports/renesas-ra/mpconfigport.h b/ports/renesas-ra/mpconfigport.h index ebd055f2ee9bb..52effd64f9295 100644 --- a/ports/renesas-ra/mpconfigport.h +++ b/ports/renesas-ra/mpconfigport.h @@ -131,6 +131,7 @@ #ifndef MICROPY_PY_MACHINE #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MACHINE_INCLUDEFILE "ports/renesas-ra/modmachine.c" +#define MICROPY_PY_MACHINE_RESET (1) #define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1) #define MICROPY_PY_MACHINE_BOOTLOADER (1) #define MICROPY_PY_MACHINE_ADC (1) diff --git a/ports/rp2/mpconfigport.h b/ports/rp2/mpconfigport.h index 8f073002e8632..c11d2fa69d5a9 100644 --- a/ports/rp2/mpconfigport.h +++ b/ports/rp2/mpconfigport.h @@ -115,6 +115,7 @@ #define MICROPY_PY_RANDOM_SEED_INIT_FUNC (rosc_random_u32()) #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MACHINE_INCLUDEFILE "ports/rp2/modmachine.c" +#define MICROPY_PY_MACHINE_RESET (1) #define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1) #define MICROPY_PY_MACHINE_BOOTLOADER (1) #define MICROPY_PY_MACHINE_DISABLE_IRQ_ENABLE_IRQ (1) diff --git a/ports/samd/mpconfigport.h b/ports/samd/mpconfigport.h index 160442a4006b8..28a99333d35b9 100644 --- a/ports/samd/mpconfigport.h +++ b/ports/samd/mpconfigport.h @@ -73,6 +73,7 @@ #define MICROPY_PY_TIME_INCLUDEFILE "ports/samd/modtime.c" #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MACHINE_INCLUDEFILE "ports/samd/modmachine.c" +#define MICROPY_PY_MACHINE_RESET (1) #define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1) #define MICROPY_PY_MACHINE_BOOTLOADER (1) #define MICROPY_PY_MACHINE_DISABLE_IRQ_ENABLE_IRQ (1) diff --git a/ports/stm32/mpconfigport.h b/ports/stm32/mpconfigport.h index 300ad086bf473..9e1e24cf23828 100644 --- a/ports/stm32/mpconfigport.h +++ b/ports/stm32/mpconfigport.h @@ -111,6 +111,7 @@ #ifndef MICROPY_PY_MACHINE #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MACHINE_INCLUDEFILE "ports/stm32/modmachine.c" +#define MICROPY_PY_MACHINE_RESET (1) #define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1) #define MICROPY_PY_MACHINE_BOOTLOADER (1) #define MICROPY_PY_MACHINE_ADC (1) diff --git a/py/mpconfig.h b/py/mpconfig.h index 182115ed71a93..85b9e2c9cd104 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1692,6 +1692,11 @@ typedef double mp_float_t; #define MICROPY_PY_MACHINE (0) #endif +// Whether to include: reset, reset_cause +#ifndef MICROPY_PY_MACHINE_RESET +#define MICROPY_PY_MACHINE_RESET (0) +#endif + // Whether to include: bitstream #ifndef MICROPY_PY_MACHINE_BITSTREAM #define MICROPY_PY_MACHINE_BITSTREAM (0) From 58a596f4a9b11a4043a96e5b90b2cff982d2a48c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20de=20Giessen?= Date: Tue, 12 Mar 2024 15:11:23 +0100 Subject: [PATCH 211/408] extmod/nimble: Check for active before setting address mode. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `BLE().config(addr_mode=...)` is not safe to call if the NimBLE stack is not yet active (because it tries to acquire mutexes which should be initialized first). Signed-off-by: Daniël van de Giessen --- extmod/nimble/modbluetooth_nimble.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/extmod/nimble/modbluetooth_nimble.c b/extmod/nimble/modbluetooth_nimble.c index 92bc6764edc63..8d555f1124f9a 100644 --- a/extmod/nimble/modbluetooth_nimble.c +++ b/extmod/nimble/modbluetooth_nimble.c @@ -728,6 +728,9 @@ void mp_bluetooth_get_current_address(uint8_t *addr_type, uint8_t *addr) { } void mp_bluetooth_set_address_mode(uint8_t addr_mode) { + if (!mp_bluetooth_is_active()) { + mp_raise_OSError(ERRNO_BLUETOOTH_NOT_ACTIVE); + } switch (addr_mode) { case MP_BLUETOOTH_ADDRESS_MODE_PUBLIC: if (!has_public_address()) { From fff66c3069dd2f2b1152cf3412dfbcb073ea804b Mon Sep 17 00:00:00 2001 From: "Kwabena W. Agyeman" Date: Thu, 14 Mar 2024 11:25:56 -0700 Subject: [PATCH 212/408] mimxrt/mpconfigport: Enable cryptolib and hashlib md5. Signed-off-by: Kwabena W. Agyeman --- ports/mimxrt/mpconfigport.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/mimxrt/mpconfigport.h b/ports/mimxrt/mpconfigport.h index 540357fa84209..637c38f432c12 100644 --- a/ports/mimxrt/mpconfigport.h +++ b/ports/mimxrt/mpconfigport.h @@ -131,9 +131,9 @@ uint32_t trng_random_u32(void); #define MICROPY_PY_WEBSOCKET (MICROPY_PY_LWIP) #define MICROPY_PY_WEBREPL (MICROPY_PY_LWIP) #define MICROPY_PY_LWIP_SOCK_RAW (MICROPY_PY_LWIP) -// #define MICROPY_PY_HASHLIB_MD5 (MICROPY_PY_SSL) +#define MICROPY_PY_HASHLIB_MD5 (MICROPY_PY_SSL) #define MICROPY_PY_HASHLIB_SHA1 (MICROPY_PY_SSL) -// #define MICROPY_PY_CRYPTOLIB (MICROPY_PY_SSL) +#define MICROPY_PY_CRYPTOLIB (MICROPY_PY_SSL) #ifndef MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE #define MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE (1) From 47e84751fb55fb522557ca3f2349c8a25295498a Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 23 Nov 2023 09:43:06 +1100 Subject: [PATCH 213/408] py/objstr: Add a macro to define a bytes object at compile time. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- py/objstr.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/py/objstr.h b/py/objstr.h index 72fe1cfef01a6..028fc9597ffc8 100644 --- a/py/objstr.h +++ b/py/objstr.h @@ -100,6 +100,8 @@ const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, s mp_obj_t index, bool is_slice); const byte *find_subbytes(const byte *haystack, size_t hlen, const byte *needle, size_t nlen, int direction); +#define MP_DEFINE_BYTES_OBJ(obj_name, target, len) mp_obj_str_t obj_name = {{&mp_type_bytes}, 0, (len), (const byte *)(target)} + mp_obj_t mp_obj_bytes_hex(size_t n_args, const mp_obj_t *args, const mp_obj_type_t *type); mp_obj_t mp_obj_bytes_fromhex(mp_obj_t type_in, mp_obj_t data); From 43904acea8b2087fdf9f283c0f8ce7d92d16e605 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 13 Mar 2024 12:17:20 +1100 Subject: [PATCH 214/408] mimxrt: Define the MICROPY_HW_ENABLE_USBDEV macro. Previously USB was always enabled, but this created some conflicts when adding guards to other files on other ports. Note the configuration with USB disabled hasn't been tested and probably won't build or run without further work. Signed-off-by: Angus Gratton --- ports/mimxrt/main.c | 2 ++ ports/mimxrt/mpconfigport.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/ports/mimxrt/main.c b/ports/mimxrt/main.c index 761c491742bcf..dddf44e605f05 100644 --- a/ports/mimxrt/main.c +++ b/ports/mimxrt/main.c @@ -115,7 +115,9 @@ int main(void) { // Execute user scripts. int ret = pyexec_file_if_exists("boot.py"); + #if MICROPY_HW_ENABLE_USBDEV mp_usbd_init(); + #endif if (ret & PYEXEC_FORCED_EXIT) { goto soft_reset_exit; diff --git a/ports/mimxrt/mpconfigport.h b/ports/mimxrt/mpconfigport.h index 637c38f432c12..a4c6d6e2060b9 100644 --- a/ports/mimxrt/mpconfigport.h +++ b/ports/mimxrt/mpconfigport.h @@ -147,6 +147,8 @@ uint32_t trng_random_u32(void); #define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-mimxrt" #endif +#define MICROPY_HW_ENABLE_USBDEV (1) + // Hooks to add builtins #if defined(IOMUX_TABLE_ENET) From 9d0d262be069089f01da6b40d2cd78f1da14de0f Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 23 Nov 2023 09:48:41 +1100 Subject: [PATCH 215/408] extmod/machine_usb_device: Add support for Python USB devices. This new machine-module driver provides a "USBDevice" singleton object and a shim TinyUSB "runtime" driver that delegates the descriptors and all of the TinyUSB callbacks to Python functions. This allows writing arbitrary USB devices in pure Python. It's also possible to have a base built-in USB device implemented in C (eg CDC, or CDC+MSC) and a Python USB device added on top of that. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- docs/library/machine.USBDevice.rst | 286 ++++++++++++++ docs/library/machine.rst | 1 + extmod/extmod.cmake | 1 + extmod/extmod.mk | 1 + extmod/machine_usb_device.c | 335 +++++++++++++++++ extmod/modmachine.c | 3 + extmod/modmachine.h | 5 + py/runtime.c | 4 + shared/tinyusb/mp_usbd.c | 34 +- shared/tinyusb/mp_usbd.h | 101 ++++- shared/tinyusb/mp_usbd_descriptor.c | 112 +++--- shared/tinyusb/mp_usbd_internal.h | 34 -- shared/tinyusb/mp_usbd_runtime.c | 554 ++++++++++++++++++++++++++++ shared/tinyusb/tusb_config.h | 31 +- 14 files changed, 1384 insertions(+), 118 deletions(-) create mode 100644 docs/library/machine.USBDevice.rst create mode 100644 extmod/machine_usb_device.c delete mode 100644 shared/tinyusb/mp_usbd_internal.h create mode 100644 shared/tinyusb/mp_usbd_runtime.c diff --git a/docs/library/machine.USBDevice.rst b/docs/library/machine.USBDevice.rst new file mode 100644 index 0000000000000..82897b280d0fe --- /dev/null +++ b/docs/library/machine.USBDevice.rst @@ -0,0 +1,286 @@ +.. currentmodule:: machine +.. _machine.USBDevice: + +class USBDevice -- USB Device driver +==================================== + +.. note:: ``machine.USBDevice`` is currently only supported on the rp2 and samd + ports. + +USBDevice provides a low-level Python API for implementing USB device functions using +Python code. This low-level API assumes familiarity with the USB standard. It's +not recommended to use this API directly, instead install the high-level usbd +module from micropython-lib. + +.. warning:: This functionality is very new and the high-level usbd module is + not yet merged into micropython-lib. It can be found `here on + GitHub `_. + +Terminology +----------- + +- A "Runtime" USB device interface or driver is one which is defined using this + Python API after MicroPython initially starts up. + +- A "Built-in" USB device interface or driver is one that is compiled into the + MicroPython firmware, and is always available. Examples are USB-CDC (serial + port) which is usually enabled by default. Built-in USB-MSC (Mass Storage) is an + option on some ports. + +Lifecycle +--------- + +Managing a runtime USB interface can be tricky, especially if you are communicating +with MicroPython over a built-in USB-CDC serial port that's part of the same USB +device. + +- A MicroPython soft reset will always clear all runtime USB interfaces, which + results in the entire USB device disconnecting from the host. If MicroPython + is also providing a built-in USB-CDC serial port then this will re-appear + after the soft reset. + + This means some functions (like ``mpremote run``) that target the USB-CDC + serial port will immediately fail if a runtime USB interface is active, + because the port goes away when ``mpremote`` triggers a soft reset. The + operation should succeed on the second try, as after the soft reset there is + no more runtime USB interface. + +- To configure a runtime USB device on every boot, it's recommended to place the + configuration code in the ``boot.py`` file on the :ref:`device VFS + `. On each reset this file is executed before the USB subsystem is + initialised (and before ``main.py``), so it allows the board to come up with the runtime + USB device immediately. + +- For development or debugging, it may be convenient to connect a hardware + serial REPL and disable the built-in USB-CDC serial port entirely. Not all ports + support this (currently only ``rp2``). The custom build should be configured + with ``#define MICROPY_HW_USB_CDC (0)`` and ``#define + MICROPY_HW_ENABLE_UART_REPL (1)``. + +Constructors +------------ + +.. class:: USBDevice() + + Construct a USBDevice object. + + .. note:: This object is a singleton, each call to this constructor + returns the same object reference. + +Methods +------- + +.. method:: USBDevice.config(desc_dev, desc_cfg, desc_strs=None, open_itf_cb=None, reset_cb=None, control_xfer_cb=None, xfer_cb=None) + + Configures the ``USBDevice`` singleton object with the USB runtime device + state and callback functions: + + - ``desc_dev`` - A bytes-like object containing + the new USB device descriptor. + + - ``desc_cfg`` - A bytes-like object containing the + new USB configuration descriptor. + + - ``desc_strs`` - Optional object holding strings or bytes objects + containing USB string descriptor values. Can be a list, a dict, or any + object which supports subscript indexing with integer keys (USB string + descriptor index). + + Strings are an optional USB feature, and this parameter can be unset + (default) if no strings are referenced in the device and configuration + descriptors, or if only built-in strings should be used. + + Apart from index 0, all the string values should be plain ASCII. Index 0 + is the special "languages" USB descriptor, represented as a bytes object + with a custom format defined in the USB standard. ``None`` can be + returned at index 0 in order to use a default "English" language + descriptor. + + To fall back to providing a built-in string value for a given index, a + subscript lookup can return ``None``, raise ``KeyError``, or raise + ``IndexError``. + + - ``open_itf_cb`` - This callback is called once for each interface + or Interface Association Descriptor in response to a Set + Configuration request from the USB Host (the final stage before + the USB device is available to the host). + + The callback takes a single argument, which is a memoryview of the + interface or IAD descriptor that the host is accepting (including + all associated descriptors). It is a view into the same + ``desc_cfg`` object that was provided as a separate + argument to this function. The memoryview is only valid until the + callback function returns. + + - ``reset_cb`` - This callback is called when the USB host performs + a bus reset. The callback takes no arguments. Any in-progress + transfers will never complete. The USB host will most likely + proceed to re-enumerate the USB device by calling the descriptor + callbacks and then ``open_itf_cb()``. + + - ``control_xfer_cb`` - This callback is called one or more times + for each USB control transfer (device Endpoint 0). It takes two + arguments. + + The first argument is the control transfer stage. It is one of: + + - ``1`` for SETUP stage. + - ``2`` for DATA stage. + - ``3`` for ACK stage. + + Second argument is a memoryview to read the USB control request + data for this stage. The memoryview is only valid until the + callback function returns. + + The callback should return one of the following values: + + - ``False`` to stall the endpoint and reject the transfer. + - ``True`` to continue the transfer to the next stage. + - A buffer object to provide data for this stage of the transfer. + This should be a writable buffer for an ``OUT`` direction transfer, or a + readable buffer with data for an ``IN`` direction transfer. + + - ``xfer_cb`` - This callback is called whenever a non-control + transfer submitted by calling :func:`USBDevice.submit_xfer` completes. + + The callback has three arguments: + + 1. The Endpoint number for the completed transfer. + 2. Result value: ``True`` if the transfer succeeded, ``False`` + otherwise. + 3. Number of bytes successfully transferred. In the case of a + "short" transfer, The result is ``True`` and ``xferred_bytes`` + will be smaller than the length of the buffer submitted for the + transfer. + + .. note:: If a bus reset occurs (see :func:`USBDevice.reset`), + ``xfer_cb`` is not called for any transfers that have not + already completed. + +.. method:: USBDevice.active(self, [value] /) + + Returns the current active state of this runtime USB device as a + boolean. The runtime USB device is "active" when it is available to + interact with the host, it doesn't mean that a USB Host is actually + present. + + If the optional ``value`` argument is set to a truthy value, then + the USB device will be activated. + + If the optional ``value`` argument is set to a falsey value, then + the USB device is deactivated. While the USB device is deactivated, + it will not be detected by the USB Host. + + To simulate a disconnect and a reconnect of the USB device, call + ``active(False)`` followed by ``active(True)``. This may be + necessary if the runtime device configuration has changed, so that + the host sees the new device. + +.. attribute:: USDBD.builtin_driver + + This attribute holds the current built-in driver configuration, and must be + set to one of the ``USBDevice.BUILTIN_`` named constants defined on this object. + + By default it holds the value :data:`USBDevice.BUILTIN_NONE`. + + Runtime USB device must be inactive when setting this field. Call the + :func:`USBDevice.active` function to deactivate before setting if necessary + (and again to activate after setting). + + If this value is set to any value other than :data:`USBDevice.BUILTIN_NONE` then + the following restrictions apply to the :func:`USBDevice.config` arguments: + + - ``desc_cfg`` should begin with the built-in USB interface descriptor data + accessible via :data:`USBDevice.builtin_driver` attribute ``desc_cfg``. + Descriptors appended after the built-in configuration descriptors should use + interface, string and endpoint numbers starting from the max built-in values + defined in :data:`USBDevice.builtin_driver` attributes ``itf_max``, ``str_max`` and + ``ep_max``. + + - The ``bNumInterfaces`` field in the built-in configuration + descriptor will also need to be updated if any new interfaces + are appended to the end of ``desc_cfg``. + + - ``desc_strs`` should either be ``None`` or a list/dictionary where index + values less than ``USBDevice.builtin_driver.str_max`` are missing or have + value ``None``. This reserves those string indexes for the built-in + drivers. Placing a different string at any of these indexes overrides that + string in the built-in driver. + +.. method:: USBDevice.submit_xfer(self, ep, buffer /) + + Submit a USB transfer on endpoint number ``ep``. ``buffer`` must be + an object implementing the buffer interface, with read access for + ``IN`` endpoints and write access for ``OUT`` endpoints. + + .. note:: ``ep`` cannot be the control Endpoint number 0. Control + transfers are built up through successive executions of + ``control_xfer_cb``, see above. + + Returns ``True`` if successful, ``False`` if the transfer could not + be queued (as USB device is not configured by host, or because + another transfer is queued on this endpoint.) + + When the USB host completes the transfer, the ``xfer_cb`` callback + is called (see above). + + Raises ``OSError`` with reason ``MP_EINVAL`` If the USB device is not + active. + +.. method:: USBDevice.stall(self, ep, [stall] /) + + Calling this function gets or sets the STALL state of a device endpoint. + + ``ep`` is the number of the endpoint. + + If the optional ``stall`` parameter is set, this is a boolean flag + for the STALL state. + + The return value is the current stall state of the endpoint (before + any change made by this function). + + An endpoint that is set to STALL may remain stalled until this + function is called again, or STALL may be cleared automatically by + the USB host. + + Raises ``OSError`` with reason ``MP_EINVAL`` If the USB device is not + active. + +Constants +--------- + +.. data:: USBDevice.BUILTIN_NONE +.. data:: USBDevice.BUILTIN_DEFAULT +.. data:: USBDevice.BUILTIN_CDC +.. data:: USBDevice.BUILTIN_MSC +.. data:: USBDevice.BUILTIN_CDC_MSC + + These constant objects hold the built-in descriptor data which is + compiled into the MicroPython firmware. ``USBDevice.BUILTIN_NONE`` and + ``USBDevice.BUILTIN_DEFAULT`` are always present. Additional objects may be present + depending on the firmware build configuration and the actual built-in drivers. + + .. note:: Currently at most one of ``USBDevice.BUILTIN_CDC``, + ``USBDevice.BUILTIN_MSC`` and ``USBDevice.BUILTIN_CDC_MSC`` is defined + and will be the same object as ``USBDevice.BUILTIN_DEFAULT``. + These constants are defined to allow run-time detection of + the built-in driver (if any). Support for selecting one of + multiple built-in driver configurations may be added in the + future. + + These values are assigned to :data:`USBDevice.builtin_driver` to get/set the + built-in configuration. + + Each object contains the following read-only fields: + + - ``itf_max`` - One more than the highest bInterfaceNumber value used + in the built-in configuration descriptor. + - ``ep_max`` - One more than the highest bEndpointAddress value used + in the built-in configuration descriptor. Does not include any + ``IN`` flag bit (0x80). + - ``str_max`` - One more than the highest string descriptor index + value used by any built-in descriptor. + - ``desc_dev`` - ``bytes`` object containing the built-in USB device + descriptor. + - ``desc_cfg`` - ``bytes`` object containing the complete built-in USB + configuration descriptor. diff --git a/docs/library/machine.rst b/docs/library/machine.rst index 3f5cd6f13c72b..532266d1d9102 100644 --- a/docs/library/machine.rst +++ b/docs/library/machine.rst @@ -265,3 +265,4 @@ Classes machine.WDT.rst machine.SD.rst machine.SDCard.rst + machine.USBDevice.rst diff --git a/extmod/extmod.cmake b/extmod/extmod.cmake index 53c774013236a..957580d15d36d 100644 --- a/extmod/extmod.cmake +++ b/extmod/extmod.cmake @@ -18,6 +18,7 @@ set(MICROPY_SOURCE_EXTMOD ${MICROPY_EXTMOD_DIR}/machine_signal.c ${MICROPY_EXTMOD_DIR}/machine_spi.c ${MICROPY_EXTMOD_DIR}/machine_uart.c + ${MICROPY_EXTMOD_DIR}/machine_usb_device.c ${MICROPY_EXTMOD_DIR}/machine_wdt.c ${MICROPY_EXTMOD_DIR}/modbluetooth.c ${MICROPY_EXTMOD_DIR}/modframebuf.c diff --git a/extmod/extmod.mk b/extmod/extmod.mk index f0428bcd05650..4f5f7d53ac4b8 100644 --- a/extmod/extmod.mk +++ b/extmod/extmod.mk @@ -15,6 +15,7 @@ SRC_EXTMOD_C += \ extmod/machine_spi.c \ extmod/machine_timer.c \ extmod/machine_uart.c \ + extmod/machine_usb_device.c \ extmod/machine_wdt.c \ extmod/modasyncio.c \ extmod/modbinascii.c \ diff --git a/extmod/machine_usb_device.c b/extmod/machine_usb_device.c new file mode 100644 index 0000000000000..69c3f38487006 --- /dev/null +++ b/extmod/machine_usb_device.c @@ -0,0 +1,335 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2024 Angus Gratton + * + * 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/mpconfig.h" + +#if MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE + +#include "mp_usbd.h" +#include "py/mperrno.h" +#include "py/objstr.h" + +// Implements the singleton runtime USB object +// +// Currently this implementation references TinyUSB directly. + +#ifndef NO_QSTR +#include "device/usbd_pvt.h" +#endif + +#define HAS_BUILTIN_DRIVERS (MICROPY_HW_USB_CDC || MICROPY_HW_USB_MSC) + +const mp_obj_type_t machine_usb_device_type; + +static mp_obj_t usb_device_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + (void)type; + (void)n_args; + (void)n_kw; + (void)args; + + if (MP_STATE_VM(usbd) == MP_OBJ_NULL) { + mp_obj_usb_device_t *o = m_new0(mp_obj_usb_device_t, 1); + o->base.type = &machine_usb_device_type; + o->desc_dev = mp_const_none; + o->desc_cfg = mp_const_none; + o->desc_strs = mp_const_none; + o->open_itf_cb = mp_const_none; + o->reset_cb = mp_const_none; + o->control_xfer_cb = mp_const_none; + o->xfer_cb = mp_const_none; + for (int i = 0; i < CFG_TUD_ENDPPOINT_MAX; i++) { + o->xfer_data[i][0] = mp_const_none; + o->xfer_data[i][1] = mp_const_none; + } + o->builtin_driver = MP_OBJ_FROM_PTR(&mp_type_usb_device_builtin_none); + o->active = false; // Builtin USB may be active already, but runtime is inactive + o->trigger = false; + o->control_data = MP_OBJ_TO_PTR(mp_obj_new_memoryview('B', 0, NULL)); + o->num_pend_excs = 0; + for (int i = 0; i < MP_USBD_MAX_PEND_EXCS; i++) { + o->pend_excs[i] = mp_const_none; + } + + MP_STATE_VM(usbd) = MP_OBJ_FROM_PTR(o); + } + + return MP_STATE_VM(usbd); +} + +// Utility helper to raise an error if USB device is not active +// (or if a change of active state is triggered but not processed.) +static void usb_device_check_active(mp_obj_usb_device_t *usbd) { + if (!usbd->active || usbd->trigger) { + mp_raise_OSError(MP_EINVAL); + } +} + +static mp_obj_t usb_device_submit_xfer(mp_obj_t self, mp_obj_t ep, mp_obj_t buffer) { + mp_obj_usb_device_t *usbd = (mp_obj_usb_device_t *)MP_OBJ_TO_PTR(self); + int ep_addr; + mp_buffer_info_t buf_info = { 0 }; + bool result; + + usb_device_check_active(usbd); + + // Unmarshal arguments, raises TypeError if invalid + ep_addr = mp_obj_get_int(ep); + mp_get_buffer_raise(buffer, &buf_info, ep_addr & TUSB_DIR_IN_MASK ? MP_BUFFER_READ : MP_BUFFER_RW); + + uint8_t ep_num = tu_edpt_number(ep_addr); + uint8_t ep_dir = tu_edpt_dir(ep_addr); + + if (ep_num == 0 || ep_num >= CFG_TUD_ENDPPOINT_MAX) { + // TinyUSB usbd API doesn't range check arguments, so this check avoids + // out of bounds array access, or submitting transfers on the control endpoint. + // + // This C layer doesn't otherwise keep track of which endpoints the host + // is aware of (or not). + mp_raise_ValueError("ep"); + } + + if (!usbd_edpt_claim(USBD_RHPORT, ep_addr)) { + mp_raise_OSError(MP_EBUSY); + } + + result = usbd_edpt_xfer(USBD_RHPORT, ep_addr, buf_info.buf, buf_info.len); + + if (result) { + // Store the buffer object until the transfer completes + usbd->xfer_data[ep_num][ep_dir] = buffer; + } + + return mp_obj_new_bool(result); +} +static MP_DEFINE_CONST_FUN_OBJ_3(usb_device_submit_xfer_obj, usb_device_submit_xfer); + +static mp_obj_t usb_device_active(size_t n_args, const mp_obj_t *args) { + mp_obj_usb_device_t *usbd = (mp_obj_usb_device_t *)MP_OBJ_TO_PTR(args[0]); + + bool result = usbd->active; + if (n_args == 2) { + bool value = mp_obj_is_true(args[1]); + + if (value != result) { + if (value + && !mp_usb_device_builtin_enabled(usbd) + && usbd->desc_dev == mp_const_none) { + // Only allow activating if config() has already been called to set some descriptors, or a + // built-in driver is enabled + mp_raise_OSError(MP_EINVAL); + } + + // Any change to active state is triggered here and processed + // from the TinyUSB task. + usbd->active = value; + usbd->trigger = true; + if (value) { + mp_usbd_init(); // Ensure TinyUSB has initialised by this point + } + mp_usbd_schedule_task(); + } + } + + return mp_obj_new_bool(result); +} +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(usb_device_active_obj, 1, 2, usb_device_active); + +static mp_obj_t usb_device_stall(size_t n_args, const mp_obj_t *args) { + mp_obj_usb_device_t *self = (mp_obj_usb_device_t *)MP_OBJ_TO_PTR(args[0]); + int epnum = mp_obj_get_int(args[1]); + + usb_device_check_active(self); + + mp_obj_t res = mp_obj_new_bool(usbd_edpt_stalled(USBD_RHPORT, epnum)); + + if (n_args == 3) { // Set stall state + mp_obj_t stall = args[2]; + if (mp_obj_is_true(stall)) { + usbd_edpt_stall(USBD_RHPORT, epnum); + } else { + usbd_edpt_clear_stall(USBD_RHPORT, epnum); + } + } + + return res; +} +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(usb_device_stall_obj, 2, 3, usb_device_stall); + +// Configure the singleton USB device with all of the relevant transfer and descriptor +// callbacks for dynamic devices. +static mp_obj_t usb_device_config(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + mp_obj_usb_device_t *self = (mp_obj_usb_device_t *)MP_OBJ_TO_PTR(pos_args[0]); + + enum { ARG_desc_dev, ARG_desc_cfg, ARG_desc_strs, ARG_open_itf_cb, + ARG_reset_cb, ARG_control_xfer_cb, ARG_xfer_cb, ARG_active }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_desc_dev, MP_ARG_OBJ | MP_ARG_REQUIRED }, + { MP_QSTR_desc_cfg, MP_ARG_OBJ | MP_ARG_REQUIRED }, + { MP_QSTR_desc_strs, MP_ARG_OBJ | MP_ARG_REQUIRED }, + { MP_QSTR_open_itf_cb, MP_ARG_OBJ, {.u_obj = mp_const_none} }, + { MP_QSTR_reset_cb, MP_ARG_OBJ, {.u_obj = mp_const_none} }, + { MP_QSTR_control_xfer_cb, MP_ARG_OBJ, {.u_obj = mp_const_none} }, + { MP_QSTR_xfer_cb, MP_ARG_OBJ, {.u_obj = mp_const_none} }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + // Check descriptor arguments + mp_obj_t desc_dev = args[ARG_desc_dev].u_obj; + mp_obj_t desc_cfg = args[ARG_desc_cfg].u_obj; + mp_obj_t desc_strs = args[ARG_desc_strs].u_obj; + if (!MP_OBJ_TYPE_HAS_SLOT(mp_obj_get_type(desc_dev), buffer)) { + mp_raise_ValueError(MP_ERROR_TEXT("desc_dev")); + } + if (!MP_OBJ_TYPE_HAS_SLOT(mp_obj_get_type(desc_cfg), buffer)) { + mp_raise_ValueError(MP_ERROR_TEXT("desc_cfg")); + } + if (desc_strs != mp_const_none + && !MP_OBJ_TYPE_HAS_SLOT(mp_obj_get_type(desc_strs), subscr)) { + mp_raise_ValueError(MP_ERROR_TEXT("desc_strs")); + } + + self->desc_dev = desc_dev; + self->desc_cfg = desc_cfg; + self->desc_strs = desc_strs; + self->open_itf_cb = args[ARG_open_itf_cb].u_obj; + self->reset_cb = args[ARG_reset_cb].u_obj; + self->control_xfer_cb = args[ARG_control_xfer_cb].u_obj; + self->xfer_cb = args[ARG_xfer_cb].u_obj; + + return mp_const_none; +} +static MP_DEFINE_CONST_FUN_OBJ_KW(usb_device_config_obj, 1, usb_device_config); + +static const MP_DEFINE_BYTES_OBJ(builtin_default_desc_dev_obj, + &mp_usbd_builtin_desc_dev, sizeof(tusb_desc_device_t)); + +#if HAS_BUILTIN_DRIVERS +// BUILTIN_DEFAULT Python object holds properties of the built-in USB configuration +// (i.e. values used by the C implementation of TinyUSB devices.) +static const MP_DEFINE_BYTES_OBJ(builtin_default_desc_cfg_obj, + mp_usbd_builtin_desc_cfg, MP_USBD_BUILTIN_DESC_CFG_LEN); + +static const mp_rom_map_elem_t usb_device_builtin_default_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_itf_max), MP_OBJ_NEW_SMALL_INT(USBD_ITF_BUILTIN_MAX) }, + { MP_ROM_QSTR(MP_QSTR_ep_max), MP_OBJ_NEW_SMALL_INT(USBD_EP_BUILTIN_MAX) }, + { MP_ROM_QSTR(MP_QSTR_str_max), MP_OBJ_NEW_SMALL_INT(USBD_STR_BUILTIN_MAX) }, + { MP_ROM_QSTR(MP_QSTR_desc_dev), MP_ROM_PTR(&builtin_default_desc_dev_obj) }, + { MP_ROM_QSTR(MP_QSTR_desc_cfg), MP_ROM_PTR(&builtin_default_desc_cfg_obj) }, +}; +static MP_DEFINE_CONST_DICT(usb_device_builtin_default_dict, usb_device_builtin_default_dict_table); + +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_usb_device_builtin_default, + MP_QSTR_BUILTIN_DEFAULT, + MP_TYPE_FLAG_NONE, + locals_dict, &usb_device_builtin_default_dict + ); +#endif // HAS_BUILTIN_DRIVERS + +// BUILTIN_NONE holds properties for no enabled built-in USB device support +static const mp_rom_map_elem_t usb_device_builtin_none_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_itf_max), MP_OBJ_NEW_SMALL_INT(0) }, + { MP_ROM_QSTR(MP_QSTR_ep_max), MP_OBJ_NEW_SMALL_INT(0) }, + { MP_ROM_QSTR(MP_QSTR_str_max), MP_OBJ_NEW_SMALL_INT(1) }, + { MP_ROM_QSTR(MP_QSTR_desc_dev), MP_ROM_PTR(&builtin_default_desc_dev_obj) }, + { MP_ROM_QSTR(MP_QSTR_desc_cfg), mp_const_empty_bytes }, +}; +static MP_DEFINE_CONST_DICT(usb_device_builtin_none_dict, usb_device_builtin_none_dict_table); + +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_usb_device_builtin_none, + MP_QSTR_BUILTIN_NONE, + MP_TYPE_FLAG_NONE, + locals_dict, &usb_device_builtin_none_dict + ); + +static const mp_rom_map_elem_t usb_device_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&usb_device_config_obj) }, + { MP_ROM_QSTR(MP_QSTR_submit_xfer), MP_ROM_PTR(&usb_device_submit_xfer_obj) }, + { MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&usb_device_active_obj) }, + { MP_ROM_QSTR(MP_QSTR_stall), MP_ROM_PTR(&usb_device_stall_obj) }, + + // Built-in driver constants + { MP_ROM_QSTR(MP_QSTR_BUILTIN_NONE), MP_ROM_PTR(&mp_type_usb_device_builtin_none) }, + + #if !HAS_BUILTIN_DRIVERS + // No builtin-in drivers, so BUILTIN_DEFAULT is BUILTIN_NONE + { MP_ROM_QSTR(MP_QSTR_BUILTIN_DEFAULT), MP_ROM_PTR(&mp_type_usb_device_builtin_none) }, + #else + { MP_ROM_QSTR(MP_QSTR_BUILTIN_DEFAULT), MP_ROM_PTR(&mp_type_usb_device_builtin_default) }, + + // Specific driver constant names are to support future switching of built-in drivers, + // but currently only one is present and it maps directly to BUILTIN_DEFAULT + #if MICROPY_HW_USB_CDC && !MICROPY_HW_USB_MSC + { MP_ROM_QSTR(MP_QSTR_BUILTIN_CDC), MP_ROM_PTR(&mp_type_usb_device_builtin_default) }, + #endif + #if MICROPY_HW_USB_MSC && !MICROPY_HW_USB_CDC + { MP_ROM_QSTR(MP_QSTR_BUILTIN_MSC), MP_ROM_PTR(&mp_type_usb_device_builtin_default) }, + #endif + #if MICROPY_HW_USB_CDC && MICROPY_HW_USB_MSC + { MP_ROM_QSTR(MP_QSTR_BUILTIN_CDC_MSC), MP_ROM_PTR(&mp_type_usb_device_builtin_default) }, + #endif + #endif // !HAS_BUILTIN_DRIVERS +}; +static MP_DEFINE_CONST_DICT(usb_device_locals_dict, usb_device_locals_dict_table); + +static void usb_device_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { + mp_obj_usb_device_t *self = MP_OBJ_TO_PTR(self_in); + if (dest[0] == MP_OBJ_NULL) { + // Load attribute. + if (attr == MP_QSTR_builtin_driver) { + dest[0] = self->builtin_driver; + } else { + // Continue lookup in locals_dict. + dest[1] = MP_OBJ_SENTINEL; + } + } else if (dest[1] != MP_OBJ_NULL) { + // Store attribute. + if (attr == MP_QSTR_builtin_driver) { + if (self->active) { + mp_raise_OSError(MP_EINVAL); // Need to deactivate first + } + // Note: this value should be one of the BUILTIN_nnn constants, + // but not checked here to save code size in a low level API + self->builtin_driver = dest[1]; + dest[0] = MP_OBJ_NULL; + } + } +} + +MP_DEFINE_CONST_OBJ_TYPE( + machine_usb_device_type, + MP_QSTR_USBDevice, + MP_TYPE_FLAG_NONE, + make_new, usb_device_make_new, + locals_dict, &usb_device_locals_dict, + attr, &usb_device_attr + ); + +MP_REGISTER_ROOT_POINTER(mp_obj_t usbd); + +#endif diff --git a/extmod/modmachine.c b/extmod/modmachine.c index d7e82b124dc76..2a7e315bbb0ce 100644 --- a/extmod/modmachine.c +++ b/extmod/modmachine.c @@ -232,6 +232,9 @@ static const mp_rom_map_elem_t machine_module_globals_table[] = { #if MICROPY_PY_MACHINE_UART { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&machine_uart_type) }, #endif + #if MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE + { MP_ROM_QSTR(MP_QSTR_USBDevice), MP_ROM_PTR(&machine_usb_device_type) }, + #endif #if MICROPY_PY_MACHINE_WDT { MP_ROM_QSTR(MP_QSTR_WDT), MP_ROM_PTR(&machine_wdt_type) }, #endif diff --git a/extmod/modmachine.h b/extmod/modmachine.h index e6b08b3fc9650..7c16ed302ee2f 100644 --- a/extmod/modmachine.h +++ b/extmod/modmachine.h @@ -213,6 +213,7 @@ extern const mp_obj_type_t machine_signal_type; extern const mp_obj_type_t machine_spi_type; extern const mp_obj_type_t machine_timer_type; extern const mp_obj_type_t machine_uart_type; +extern const mp_obj_type_t machine_usbd_type; extern const mp_obj_type_t machine_wdt_type; #if MICROPY_PY_MACHINE_SOFTI2C @@ -230,6 +231,10 @@ extern const mp_machine_spi_p_t mp_machine_soft_spi_p; extern const mp_obj_dict_t mp_machine_spi_locals_dict; #endif +#if MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE +extern const mp_obj_type_t machine_usb_device_type; +#endif + #if defined(MICROPY_MACHINE_MEM_GET_READ_ADDR) uintptr_t MICROPY_MACHINE_MEM_GET_READ_ADDR(mp_obj_t addr_o, uint align); #endif diff --git a/py/runtime.c b/py/runtime.c index f7e0abdb46009..1836f5d92a851 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -171,6 +171,10 @@ void mp_init(void) { MP_STATE_VM(bluetooth) = MP_OBJ_NULL; #endif + #if MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE + MP_STATE_VM(usbd) = MP_OBJ_NULL; + #endif + #if MICROPY_PY_THREAD_GIL mp_thread_mutex_init(&MP_STATE_VM(gil_mutex)); #endif diff --git a/shared/tinyusb/mp_usbd.c b/shared/tinyusb/mp_usbd.c index 74b3f074927b8..436314dcde5c8 100644 --- a/shared/tinyusb/mp_usbd.c +++ b/shared/tinyusb/mp_usbd.c @@ -24,42 +24,42 @@ * THE SOFTWARE. */ -#include - #include "py/mpconfig.h" -#include "py/runtime.h" #if MICROPY_HW_ENABLE_USBDEV +#include "mp_usbd.h" + #ifndef NO_QSTR -#include "tusb.h" // TinyUSB is not available when running the string preprocessor #include "device/dcd.h" -#include "device/usbd.h" -#include "device/usbd_pvt.h" #endif -// TinyUSB task function wrapper, as scheduled from the USB IRQ -static void mp_usbd_task_callback(mp_sched_node_t *node); - -extern void __real_dcd_event_handler(dcd_event_t const *event, bool in_isr); +#if !MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE void mp_usbd_task(void) { tud_task_ext(0, false); } +void mp_usbd_task_callback(mp_sched_node_t *node) { + (void)node; + mp_usbd_task(); +} + +#endif // !MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE + +extern void __real_dcd_event_handler(dcd_event_t const *event, bool in_isr); + // If -Wl,--wrap=dcd_event_handler is passed to the linker, then this wrapper // will be called and allows MicroPython to schedule the TinyUSB task when // dcd_event_handler() is called from an ISR. TU_ATTR_FAST_FUNC void __wrap_dcd_event_handler(dcd_event_t const *event, bool in_isr) { - static mp_sched_node_t usbd_task_node; - __real_dcd_event_handler(event, in_isr); - mp_sched_schedule_node(&usbd_task_node, mp_usbd_task_callback); + mp_usbd_schedule_task(); } -static void mp_usbd_task_callback(mp_sched_node_t *node) { - (void)node; - mp_usbd_task(); +TU_ATTR_FAST_FUNC void mp_usbd_schedule_task(void) { + static mp_sched_node_t usbd_task_node; + mp_sched_schedule_node(&usbd_task_node, mp_usbd_task_callback); } void mp_usbd_hex_str(char *out_str, const uint8_t *bytes, size_t bytes_len) { @@ -72,4 +72,4 @@ void mp_usbd_hex_str(char *out_str, const uint8_t *bytes, size_t bytes_len) { out_str[hex_len] = 0; } -#endif +#endif // MICROPY_HW_ENABLE_USBDEV diff --git a/shared/tinyusb/mp_usbd.h b/shared/tinyusb/mp_usbd.h index 89f8bf0ee953b..ef32348451391 100644 --- a/shared/tinyusb/mp_usbd.h +++ b/shared/tinyusb/mp_usbd.h @@ -27,25 +27,110 @@ #ifndef MICROPY_INCLUDED_SHARED_TINYUSB_MP_USBD_H #define MICROPY_INCLUDED_SHARED_TINYUSB_MP_USBD_H +#include "py/mpconfig.h" + +#if MICROPY_HW_ENABLE_USBDEV + #include "py/obj.h" -#include "tusb.h" +#include "py/objarray.h" +#include "py/runtime.h" -static inline void mp_usbd_init(void) { - // Currently this is a thin wrapper around tusb_init(), however - // runtime USB support will require this to be extended. - tusb_init(); -} +#ifndef NO_QSTR +#include "tusb.h" +#include "device/dcd.h" +#endif -// Call this to explicitly run the TinyUSB device task. +// Run the TinyUSB device task void mp_usbd_task(void); +// Schedule a call to mp_usbd_task(), even if no USB interrupt has occurred +void mp_usbd_schedule_task(void); + // Function to be implemented in port code. // Can write a string up to MICROPY_HW_USB_DESC_STR_MAX characters long, plus terminating byte. extern void mp_usbd_port_get_serial_number(char *buf); -// Most ports need to write a hexadecimal serial number from a byte array, this +// Most ports need to write a hexadecimal serial number from a byte array. This // is a helper function for this. out_str must be long enough to hold a string of total // length (2 * bytes_len + 1) (including NUL terminator). void mp_usbd_hex_str(char *out_str, const uint8_t *bytes, size_t bytes_len); +// Length of built-in configuration descriptor +#define MP_USBD_BUILTIN_DESC_CFG_LEN (TUD_CONFIG_DESC_LEN + \ + (CFG_TUD_CDC ? (TUD_CDC_DESC_LEN) : 0) + \ + (CFG_TUD_MSC ? (TUD_MSC_DESC_LEN) : 0) \ + ) + +// Built-in USB device and configuration descriptor values +extern const tusb_desc_device_t mp_usbd_builtin_desc_dev; +extern const uint8_t mp_usbd_builtin_desc_cfg[MP_USBD_BUILTIN_DESC_CFG_LEN]; + +void mp_usbd_task_callback(mp_sched_node_t *node); + +#if MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE +void mp_usbd_deinit(void); +void mp_usbd_init(void); + +const char *mp_usbd_runtime_string_cb(uint8_t index); + +// Maximum number of pending exceptions per single TinyUSB task execution +#define MP_USBD_MAX_PEND_EXCS 2 + +typedef struct { + mp_obj_base_t base; + + mp_obj_t desc_dev; // Device descriptor bytes + mp_obj_t desc_cfg; // Configuration descriptor bytes + mp_obj_t desc_strs; // List/dict/similar to look up string descriptors by index + + // Runtime device driver callback functions + mp_obj_t open_itf_cb; + mp_obj_t reset_cb; + mp_obj_t control_xfer_cb; + mp_obj_t xfer_cb; + + mp_obj_t builtin_driver; // Points to one of mp_type_usb_device_builtin_nnn + + bool active; // Has the user set the USB device active? + bool trigger; // Has the user requested the active state change (or re-activate)? + + // Temporary pointers for xfer data in progress on each endpoint + // Ensuring they aren't garbage collected until the xfer completes + mp_obj_t xfer_data[CFG_TUD_ENDPPOINT_MAX][2]; + + // Pointer to a memoryview that is reused to refer to various pieces of + // control transfer data that are pushed to USB control transfer + // callbacks. Python code can't rely on the memoryview contents + // to remain valid after the callback returns! + mp_obj_array_t *control_data; + + // Pointers to exceptions thrown inside Python callbacks. See + // usbd_callback_function_n(). + mp_uint_t num_pend_excs; + mp_obj_t pend_excs[MP_USBD_MAX_PEND_EXCS]; +} mp_obj_usb_device_t; + +// Built-in constant objects, possible values of builtin_driver +// +// (Currently not possible to change built-in drivers at runtime, just enable/disable.) +extern const mp_obj_type_t mp_type_usb_device_builtin_default; +extern const mp_obj_type_t mp_type_usb_device_builtin_none; + +// Return true if any built-in driver is enabled +inline static bool mp_usb_device_builtin_enabled(const mp_obj_usb_device_t *usbd) { + return usbd->builtin_driver != MP_OBJ_FROM_PTR(&mp_type_usb_device_builtin_none); +} + +#else // Static USBD drivers only + +static inline void mp_usbd_init(void) { + // Without runtime USB support, this can be a thin wrapper wrapper around tusb_init() + extern bool tusb_init(void); + tusb_init(); +} + +#endif + +#endif // MICROPY_HW_ENABLE_USBDEV + #endif // MICROPY_INCLUDED_SHARED_TINYUSB_USBD_H diff --git a/shared/tinyusb/mp_usbd_descriptor.c b/shared/tinyusb/mp_usbd_descriptor.c index 72a2652179869..be3473b6b9142 100644 --- a/shared/tinyusb/mp_usbd_descriptor.c +++ b/shared/tinyusb/mp_usbd_descriptor.c @@ -31,12 +31,11 @@ #include "tusb.h" #include "mp_usbd.h" -#include "mp_usbd_internal.h" #define USBD_CDC_CMD_MAX_SIZE (8) #define USBD_CDC_IN_OUT_MAX_SIZE ((CFG_TUD_MAX_SPEED == OPT_MODE_HIGH_SPEED) ? 512 : 64) -const tusb_desc_device_t mp_usbd_desc_device_static = { +const tusb_desc_device_t mp_usbd_builtin_desc_dev = { .bLength = sizeof(tusb_desc_device_t), .bDescriptorType = TUSB_DESC_DEVICE, .bcdUSB = 0x0200, @@ -53,8 +52,8 @@ const tusb_desc_device_t mp_usbd_desc_device_static = { .bNumConfigurations = 1, }; -const uint8_t mp_usbd_desc_cfg_static[USBD_STATIC_DESC_LEN] = { - TUD_CONFIG_DESCRIPTOR(1, USBD_ITF_STATIC_MAX, USBD_STR_0, USBD_STATIC_DESC_LEN, +const uint8_t mp_usbd_builtin_desc_cfg[MP_USBD_BUILTIN_DESC_CFG_LEN] = { + TUD_CONFIG_DESCRIPTOR(1, USBD_ITF_BUILTIN_MAX, USBD_STR_0, MP_USBD_BUILTIN_DESC_CFG_LEN, 0, USBD_MAX_POWER_MA), #if CFG_TUD_CDC @@ -69,51 +68,68 @@ const uint8_t mp_usbd_desc_cfg_static[USBD_STATIC_DESC_LEN] = { const uint16_t *tud_descriptor_string_cb(uint8_t index, uint16_t langid) { char serial_buf[MICROPY_HW_USB_DESC_STR_MAX + 1]; // Includes terminating NUL byte static uint16_t desc_wstr[MICROPY_HW_USB_DESC_STR_MAX + 1]; // Includes prefix uint16_t - const char *desc_str; + const char *desc_str = NULL; uint16_t desc_len; - switch (index) { - case 0: - desc_wstr[1] = 0x0409; // supported language is English - desc_len = 4; - break; - case USBD_STR_SERIAL: - // TODO: make a port-specific serial number callback - mp_usbd_port_get_serial_number(serial_buf); - desc_str = serial_buf; - break; - case USBD_STR_MANUF: - desc_str = MICROPY_HW_USB_MANUFACTURER_STRING; - break; - case USBD_STR_PRODUCT: - desc_str = MICROPY_HW_USB_PRODUCT_FS_STRING; - break; - #if CFG_TUD_CDC - case USBD_STR_CDC: - desc_str = MICROPY_HW_USB_CDC_INTERFACE_STRING; - break; - #endif - #if CFG_TUD_MSC - case USBD_STR_MSC: - desc_str = MICROPY_HW_USB_MSC_INTERFACE_STRING; - break; - #endif - default: - desc_str = NULL; - } + #if MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE + desc_str = mp_usbd_runtime_string_cb(index); + #endif - if (index != 0) { + if (index == 0) { + // String descriptor 0 is special, see USB 2.0 section 9.6.7 String + // + // Expect any runtime value in desc_str to be a fully formed descriptor if (desc_str == NULL) { - return NULL; // Will STALL the endpoint + desc_str = "\x04\x03\x09\x04"; // Descriptor for "English" } + if (desc_str[0] < sizeof(desc_wstr)) { + memcpy(desc_wstr, desc_str, desc_str[0]); + return desc_wstr; + } + return NULL; // Descriptor length too long (or malformed), stall endpoint + } - // Convert from narrow string to wide string - desc_len = 2; - for (int i = 0; i < MICROPY_HW_USB_DESC_STR_MAX && desc_str[i] != 0; i++) { - desc_wstr[1 + i] = desc_str[i]; - desc_len += 2; + // Otherwise, generate a "UNICODE" string descriptor from the C string + + if (desc_str == NULL) { + // Fall back to the "static" string + switch (index) { + case USBD_STR_SERIAL: + mp_usbd_port_get_serial_number(serial_buf); + desc_str = serial_buf; + break; + case USBD_STR_MANUF: + desc_str = MICROPY_HW_USB_MANUFACTURER_STRING; + break; + case USBD_STR_PRODUCT: + desc_str = MICROPY_HW_USB_PRODUCT_FS_STRING; + break; + #if CFG_TUD_CDC + case USBD_STR_CDC: + desc_str = MICROPY_HW_USB_CDC_INTERFACE_STRING; + break; + #endif + #if CFG_TUD_MSC + case USBD_STR_MSC: + desc_str = MICROPY_HW_USB_MSC_INTERFACE_STRING; + break; + #endif + default: + break; } } + + if (desc_str == NULL) { + return NULL; // No string, STALL the endpoint + } + + // Convert from narrow string to wide string + desc_len = 2; + for (int i = 0; i < MICROPY_HW_USB_DESC_STR_MAX && desc_str[i] != 0; i++) { + desc_wstr[1 + i] = desc_str[i]; + desc_len += 2; + } + // first byte is length (including header), second byte is string type desc_wstr[0] = (TUSB_DESC_STRING << 8) | desc_len; @@ -121,13 +137,21 @@ const uint16_t *tud_descriptor_string_cb(uint8_t index, uint16_t langid) { } +#if !MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE + const uint8_t *tud_descriptor_device_cb(void) { - return (const void *)&mp_usbd_desc_device_static; + return (const void *)&mp_usbd_builtin_desc_dev; } const uint8_t *tud_descriptor_configuration_cb(uint8_t index) { (void)index; - return mp_usbd_desc_cfg_static; + return mp_usbd_builtin_desc_cfg; } -#endif +#else + +// If runtime device support is enabled, descriptor callbacks are implemented in usbd.c + +#endif // !MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE + +#endif // MICROPY_HW_ENABLE_USBDEV diff --git a/shared/tinyusb/mp_usbd_internal.h b/shared/tinyusb/mp_usbd_internal.h deleted file mode 100644 index 8b8f50bae88ee..0000000000000 --- a/shared/tinyusb/mp_usbd_internal.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2022 Angus Gratton - * - * 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_SHARED_TINYUSB_MP_USBD_INTERNAL_H -#define MICROPY_INCLUDED_SHARED_TINYUSB_MP_USBD_INTERNAL_H -#include "tusb.h" - -// Static USB device descriptor values -extern const tusb_desc_device_t mp_usbd_desc_device_static; -extern const uint8_t mp_usbd_desc_cfg_static[USBD_STATIC_DESC_LEN]; - -#endif // MICROPY_INCLUDED_SHARED_TINYUSB_MP_USBD_INTERNAL_H diff --git a/shared/tinyusb/mp_usbd_runtime.c b/shared/tinyusb/mp_usbd_runtime.c new file mode 100644 index 0000000000000..a46c0f85e6bdd --- /dev/null +++ b/shared/tinyusb/mp_usbd_runtime.c @@ -0,0 +1,554 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2022 Blake W. Felt + * Copyright (c) 2022-2023 Angus Gratton + * + * 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 + +#include "mp_usbd.h" +#include "py/mpconfig.h" +#include "py/mperrno.h" +#include "py/mphal.h" +#include "py/obj.h" +#include "py/objarray.h" +#include "py/objstr.h" +#include "py/runtime.h" + +#if MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE + +#ifndef NO_QSTR +#include "tusb.h" // TinyUSB is not available when running the string preprocessor +#include "device/dcd.h" +#include "device/usbd.h" +#include "device/usbd_pvt.h" +#endif + +static bool in_usbd_task; // Flags if mp_usbd_task() is processing already + +// Some top-level functions that manage global TinyUSB USBD state, not the +// singleton object visible to Python +static void mp_usbd_disconnect(mp_obj_usb_device_t *usbd); +static void mp_usbd_task_inner(void); + +// Pend an exception raise in a USBD callback to print when safe. +// +// We can't raise any exceptions out of the TinyUSB task, as it may still need +// to do some state cleanup. +// +// The requirement for this becomes very similar to +// mp_call_function_x_protected() for interrupts, but it's more restrictive: if +// the C-based USB-CDC serial port is in use, we can't print from inside a +// TinyUSB callback as it might try to recursively call into TinyUSB to flush +// the CDC port and make room. Therefore, we have to store the exception and +// print it as we exit the TinyUSB task. +// +// (Worse, a single TinyUSB task can process multiple callbacks and therefore generate +// multiple exceptions...) +static void usbd_pend_exception(mp_obj_t exception) { + mp_obj_usb_device_t *usbd = MP_OBJ_TO_PTR(MP_STATE_VM(usbd)); + assert(usbd != NULL); + if (usbd->num_pend_excs < MP_USBD_MAX_PEND_EXCS) { + usbd->pend_excs[usbd->num_pend_excs] = exception; + } + usbd->num_pend_excs++; +} + +// Call a Python function from inside a TinyUSB callback. +// +// Handles any exception using usbd_pend_exception() +static mp_obj_t usbd_callback_function_n(mp_obj_t fun, size_t n_args, const mp_obj_t *args) { + nlr_buf_t nlr; + if (nlr_push(&nlr) == 0) { + mp_obj_t ret = mp_call_function_n_kw(fun, n_args, 0, args); + nlr_pop(); + return ret; + } else { + usbd_pend_exception(MP_OBJ_FROM_PTR(nlr.ret_val)); + return MP_OBJ_NULL; + } +} + +// Return a pointer to the data inside a Python buffer provided in a callback +static void *usbd_get_buffer_in_cb(mp_obj_t obj, mp_uint_t flags) { + mp_buffer_info_t buf_info; + if (obj == mp_const_none) { + // This is only if the user somehow + return NULL; + } else if (mp_get_buffer(obj, &buf_info, flags)) { + return buf_info.buf; + } else { + mp_obj_t exc = mp_obj_new_exception_msg(&mp_type_TypeError, + MP_ERROR_TEXT("object with buffer protocol required")); + usbd_pend_exception(exc); + return NULL; + } +} + +const uint8_t *tud_descriptor_device_cb(void) { + mp_obj_usb_device_t *usbd = MP_OBJ_TO_PTR(MP_STATE_VM(usbd)); + const void *result = NULL; + if (usbd) { + result = usbd_get_buffer_in_cb(usbd->desc_dev, MP_BUFFER_READ); + } + return result ? result : &mp_usbd_builtin_desc_dev; +} + +const uint8_t *tud_descriptor_configuration_cb(uint8_t index) { + (void)index; + mp_obj_usb_device_t *usbd = MP_OBJ_TO_PTR(MP_STATE_VM(usbd)); + const void *result = NULL; + if (usbd) { + result = usbd_get_buffer_in_cb(usbd->desc_cfg, MP_BUFFER_READ); + } + return result ? result : &mp_usbd_builtin_desc_cfg; +} + +const char *mp_usbd_runtime_string_cb(uint8_t index) { + mp_obj_usb_device_t *usbd = MP_OBJ_TO_PTR(MP_STATE_VM(usbd)); + nlr_buf_t nlr; + + if (usbd == NULL || usbd->desc_strs == mp_const_none) { + return NULL; + } + + if (nlr_push(&nlr) == 0) { + mp_obj_t res = mp_obj_subscr(usbd->desc_strs, mp_obj_new_int(index), MP_OBJ_SENTINEL); + nlr_pop(); + if (res != mp_const_none) { + return usbd_get_buffer_in_cb(res, MP_BUFFER_READ); + } + } else { + mp_obj_t exception = MP_OBJ_FROM_PTR(nlr.ret_val); + if (!(mp_obj_is_type(exception, &mp_type_KeyError) || mp_obj_is_type(exception, &mp_type_IndexError))) { + // Don't print KeyError or IndexError, allowing dicts or lists to have missing entries. + // but log any more exotic errors that pop up + usbd_pend_exception(exception); + } + } + + return NULL; +} + +bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request) { + return false; // Currently no support for Vendor control transfers on the Python side +} + +// Generic "runtime device" TinyUSB class driver, delegates everything to Python callbacks + +static void runtime_dev_init(void) { +} + +static void runtime_dev_reset(uint8_t rhport) { + mp_obj_usb_device_t *usbd = MP_OBJ_TO_PTR(MP_STATE_VM(usbd)); + if (!usbd) { + return; + } + + for (int epnum = 0; epnum < CFG_TUD_ENDPPOINT_MAX; epnum++) { + for (int dir = 0; dir < 2; dir++) { + usbd->xfer_data[epnum][dir] = mp_const_none; + } + } + + if (mp_obj_is_callable(usbd->reset_cb)) { + usbd_callback_function_n(usbd->reset_cb, 0, NULL); + } +} + +// Calculate how many interfaces TinyUSB expects us to claim from +// driver open(). +// +// Annoyingly, the calling function (process_set_config() in TinyUSB) knows +// this but doesn't pass the information to us. +// +// The answer is: +// - If an Interface Association Descriptor (IAD) is immediately before itf_desc +// in the configuration descriptor, then claim all of the associated interfaces. +// - Otherwise, claim exactly one interface +// +// Relying on the implementation detail that itf_desc is a pointer inside the +// tud_descriptor_configuration_cb() result. Therefore, we can iterate through +// from the beginning to check for an IAD immediately preceding it. +// +// Returns the number of associated interfaces to claim. +static uint8_t _runtime_dev_count_itfs(tusb_desc_interface_t const *itf_desc) { + const tusb_desc_configuration_t *cfg_desc = (const void *)tud_descriptor_configuration_cb(0); + const uint8_t *p_desc = (const void *)cfg_desc; + const uint8_t *p_end = p_desc + cfg_desc->wTotalLength; + assert(p_desc <= itf_desc && itf_desc < p_end); + while (p_desc != (const void *)itf_desc && p_desc < p_end) { + const uint8_t *next = tu_desc_next(p_desc); + + if (tu_desc_type(p_desc) == TUSB_DESC_INTERFACE_ASSOCIATION + && next == (const void *)itf_desc) { + const tusb_desc_interface_assoc_t *desc_iad = (const void *)p_desc; + return desc_iad->bInterfaceCount; + } + p_desc = next; + } + return 1; // No IAD found +} + +// Scan the other descriptors after these interface(s) to find the total associated length to claim +// from driver open(). +// +// Total number of interfaces to scan for is assoc_itf_count. +// +// Opens any associated endpoints so they can have transfers submitted against them. +// +// Returns the total number of descriptor bytes to claim. +static uint16_t _runtime_dev_claim_itfs(tusb_desc_interface_t const *itf_desc, uint8_t assoc_itf_count, uint16_t max_len) { + const uint8_t *p_desc = (const void *)itf_desc; + const uint8_t *p_end = p_desc + max_len; + while (p_desc < p_end) { + if (tu_desc_type(p_desc) == TUSB_DESC_INTERFACE) { + if (assoc_itf_count > 0) { + // Claim this interface descriptor + assoc_itf_count--; + } else { + // This is the end of the previous interface's associated descriptors + break; + } + } else if (tu_desc_type(p_desc) == TUSB_DESC_ENDPOINT) { + // Open any endpoints that we come across + if (tu_desc_type(p_desc) == TUSB_DESC_ENDPOINT) { + bool r = usbd_edpt_open(USBD_RHPORT, (const void *)p_desc); + if (!r) { + mp_obj_t exc = mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_ENODEV)); + usbd_pend_exception(exc); + break; + } + } + } + p_desc = tu_desc_next(p_desc); + } + return p_desc - (const uint8_t *)itf_desc; +} + +// TinyUSB "Application driver" open callback. Called when the USB host sets +// configuration. Returns number of bytes to claim from descriptors pointed to +// by itf_desc. +// +// This is a little fiddly as it's called before any compiled-in "static" +// TinyUSB drivers, but we don't want to override those. +// +// Also, TinyUSB expects us to know how many interfaces to claim for each time +// this function is called, and will behave unexpectedly if we claim the wrong +// number of interfaces. However, unlike a "normal" USB driver we don't know at +// compile time how many interfaces we've implemented. Instead, we have to look +// back through the configuration descriptor to figure this out. +static uint16_t runtime_dev_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len) { + mp_obj_usb_device_t *usbd = MP_OBJ_TO_PTR(MP_STATE_VM(usbd)); + + // Runtime USB isn't initialised + if (!usbd) { + return 0; + } + + // If TinyUSB built-in drivers are enabled, don't claim any interface in the static range + if (mp_usb_device_builtin_enabled(usbd) && itf_desc->bInterfaceNumber < USBD_ITF_BUILTIN_MAX) { + return 0; + } + + // Determine the total descriptor length of the interface(s) we are going to claim + uint8_t assoc_itf_count = _runtime_dev_count_itfs(itf_desc); + uint16_t claim_len = _runtime_dev_claim_itfs(itf_desc, assoc_itf_count, max_len); + + // Call the Python callback to allow the driver to start working with these interface(s) + + if (mp_obj_is_callable(usbd->open_itf_cb)) { + // Repurpose the control_data memoryview to point into itf_desc for this one call + usbd->control_data->items = (void *)itf_desc; + usbd->control_data->len = claim_len; + mp_obj_t args[] = { MP_OBJ_FROM_PTR(usbd->control_data) }; + usbd_callback_function_n(usbd->open_itf_cb, 1, args); + usbd->control_data->len = 0; + usbd->control_data->items = NULL; + } + + return claim_len; +} + +static bool runtime_dev_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request) { + mp_obj_t cb_res = mp_const_false; + mp_obj_usb_device_t *usbd = MP_OBJ_TO_PTR(MP_STATE_VM(usbd)); + tusb_dir_t dir = request->bmRequestType_bit.direction; + mp_buffer_info_t buf_info; + + if (!usbd) { + return false; + } + + if (mp_obj_is_callable(usbd->control_xfer_cb)) { + usbd->control_data->items = (void *)request; + usbd->control_data->len = sizeof(tusb_control_request_t); + mp_obj_t args[] = { + mp_obj_new_int(stage), + MP_OBJ_FROM_PTR(usbd->control_data), + }; + cb_res = usbd_callback_function_n(usbd->control_xfer_cb, MP_ARRAY_SIZE(args), args); + usbd->control_data->items = NULL; + usbd->control_data->len = 0; + + if (cb_res == MP_OBJ_NULL) { + // Exception occurred in the callback handler, stall this transfer + cb_res = mp_const_false; + } + } + + // Check if callback returned any data to submit + if (mp_get_buffer(cb_res, &buf_info, dir == TUSB_DIR_IN ? MP_BUFFER_READ : MP_BUFFER_RW)) { + bool result = tud_control_xfer(USBD_RHPORT, + request, + buf_info.buf, + buf_info.len); + + if (result) { + // Keep buffer object alive until the transfer completes + usbd->xfer_data[0][dir] = cb_res; + } + + return result; + } else { + // Expect True or False to stall or continue + + if (stage == CONTROL_STAGE_ACK) { + // Allow data to be GCed once it's no longer in use + usbd->xfer_data[0][dir] = mp_const_none; + } + return mp_obj_is_true(cb_res); + } +} + +static bool runtime_dev_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) { + mp_obj_t ep = mp_obj_new_int(ep_addr); + mp_obj_t cb_res = mp_const_false; + mp_obj_usb_device_t *usbd = MP_OBJ_TO_PTR(MP_STATE_VM(usbd)); + if (!usbd) { + return false; + } + + if (mp_obj_is_callable(usbd->xfer_cb)) { + mp_obj_t args[] = { + ep, + MP_OBJ_NEW_SMALL_INT(result), + MP_OBJ_NEW_SMALL_INT(xferred_bytes), + }; + cb_res = usbd_callback_function_n(usbd->xfer_cb, MP_ARRAY_SIZE(args), args); + } + + // Clear any xfer_data for this endpoint + usbd->xfer_data[tu_edpt_number(ep_addr)][tu_edpt_dir(ep_addr)] = mp_const_none; + + return cb_res != MP_OBJ_NULL && mp_obj_is_true(cb_res); +} + +static usbd_class_driver_t const _runtime_dev_driver = +{ + #if CFG_TUSB_DEBUG >= 2 + .name = "runtime_dev", + #endif + .init = runtime_dev_init, + .reset = runtime_dev_reset, + .open = runtime_dev_open, + .control_xfer_cb = runtime_dev_control_xfer_cb, + .xfer_cb = runtime_dev_xfer_cb, + .sof = NULL +}; + +usbd_class_driver_t const *usbd_app_driver_get_cb(uint8_t *driver_count) { + *driver_count = 1; + return &_runtime_dev_driver; +} + + +// Functions below here (named mp_usbd_xyz) apply to the whole TinyUSB C-based subsystem +// and not necessarily the USBD singleton object (named usbd_xyz). + +// To support soft reset clearing USB runtime state, we manage three TinyUSB states: +// +// - "Not initialised" - tusb_inited() returns false, no USB at all). Only way +// back to this state is hard reset. +// +// - "Activated" - tusb_inited() returns true, USB device "connected" at device +// end and available to host. +// +// - "Deactivated" - tusb_inited() returns true, but USB device "disconnected" +// at device end and host can't see it. + + +// Top-level USB device subsystem init. +// +// Makes an on-demand call to mp_usbd_activate(), if USB is needed. +// +// This is called on any soft reset after boot.py runs, or on demand if the +// user activates USB and it hasn't activated yet. +void mp_usbd_init(void) { + mp_obj_usb_device_t *usbd = MP_OBJ_TO_PTR(MP_STATE_VM(usbd)); + bool need_usb; + + if (usbd == NULL) { + // No runtime USB device + #if CFG_TUD_CDC || CFG_TUD_MSC + // Builtin drivers are available, so initialise as defaults + need_usb = true; + #else + // No static drivers, nothing to initialise + need_usb = false; + #endif + } else { + // Otherwise, initialise based on whether runtime USB is active + need_usb = usbd->active; + } + + if (need_usb) { + tusb_init(); // Safe to call redundantly + tud_connect(); // Reconnect if mp_usbd_deinit() has disconnected + } +} + +// Top-level USB device deinit. +// +// This variant is called from soft reset, NULLs out the USB device +// singleton instance from MP_STATE_VM, and disconnects the port. +void mp_usbd_deinit(void) { + mp_obj_usb_device_t *usbd = MP_OBJ_TO_PTR(MP_STATE_VM(usbd)); + MP_STATE_VM(usbd) = MP_OBJ_NULL; + if (usbd) { + // Disconnect if a runtime USB device was active + mp_usbd_disconnect(usbd); + } +} + +// Thin wrapper around tud_disconnect() that tells TinyUSB all endpoints +// have stalled, to prevent it getting confused if a transfer is in progress. +static void mp_usbd_disconnect(mp_obj_usb_device_t *usbd) { + if (!tusb_inited()) { + return; // TinyUSB hasn't initialised + } + + if (usbd) { + // There might be USB transfers in progress right now, so need to stall any live + // endpoints + // + // TODO: figure out if we really need this + for (int epnum = 0; epnum < CFG_TUD_ENDPPOINT_MAX; epnum++) { + for (int dir = 0; dir < 2; dir++) { + if (usbd->xfer_data[epnum][dir] != mp_const_none) { + usbd_edpt_stall(USBD_RHPORT, tu_edpt_addr(epnum, dir)); + usbd->xfer_data[epnum][dir] = mp_const_none; + } + } + } + } + + #if MICROPY_HW_USB_CDC + // Ensure no pending static CDC writes, as these can cause TinyUSB to crash + tud_cdc_write_clear(); + #endif + + bool was_connected = tud_connected(); + tud_disconnect(); + if (was_connected) { + mp_hal_delay_ms(50); // TODO: Always??? + } +} + +// Thjs callback is queued by mp_usbd_schedule_task() to process USB later. +void mp_usbd_task_callback(mp_sched_node_t *node) { + if (tud_inited() && !in_usbd_task) { + mp_usbd_task_inner(); + } + // If in_usbd_task is set, it means something else has already manually called + // mp_usbd_task() (most likely: C-based USB-CDC serial port). Now the MP + // scheduler is running inside there and triggering this callback. It's OK + // to skip, the already-running outer TinyUSB task will process all pending + // events before it returns. +} + +// Task function can be called manually to force processing of USB events +// (mostly from USB-CDC serial port when blocking.) +void mp_usbd_task(void) { + if (in_usbd_task) { + // If this exception triggers, it means a USB callback tried to do + // something that itself became blocked on TinyUSB (most likely: read or + // write from a C-based USB-CDC serial port.) + mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("TinyUSB callback can't recurse")); + } + + mp_usbd_task_inner(); +} + +static void mp_usbd_task_inner(void) { + in_usbd_task = true; + + tud_task_ext(0, false); + + mp_obj_usb_device_t *usbd = MP_OBJ_TO_PTR(MP_STATE_VM(usbd)); + + // Check for a triggered change to/from active state + if (usbd && usbd->trigger) { + if (usbd->active) { + if (tud_connected()) { + // If a SETUP packet has been received, first disconnect + // and wait for the host to recognise this and trigger a bus reset. + // + // Effectively this forces it to re-enumerate the device. + mp_usbd_disconnect(usbd); + } + tud_connect(); + } else { + mp_usbd_disconnect(usbd); + } + usbd->trigger = false; + } + + in_usbd_task = false; + + if (usbd) { + // Print any exceptions that were raised by Python callbacks + // inside tud_task_ext(). See usbd_callback_function_n. + + // As printing exceptions to USB-CDC may recursively call mp_usbd_task(), + // first copy out the pending data to the local stack + mp_uint_t num_pend_excs = usbd->num_pend_excs; + mp_obj_t pend_excs[MP_USBD_MAX_PEND_EXCS]; + for (mp_uint_t i = 0; i < MIN(MP_USBD_MAX_PEND_EXCS, num_pend_excs); i++) { + pend_excs[i] = usbd->pend_excs[i]; + usbd->pend_excs[i] = mp_const_none; + } + usbd->num_pend_excs = 0; + + // Now print the exceptions stored from this mp_usbd_task() call + for (mp_uint_t i = 0; i < MIN(MP_USBD_MAX_PEND_EXCS, num_pend_excs); i++) { + mp_obj_print_exception(&mp_plat_print, pend_excs[i]); + } + if (num_pend_excs > MP_USBD_MAX_PEND_EXCS) { + mp_printf(&mp_plat_print, "%u additional exceptions in USB callbacks\n", + num_pend_excs - MP_USBD_MAX_PEND_EXCS); + } + } +} + +#endif // MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE diff --git a/shared/tinyusb/tusb_config.h b/shared/tinyusb/tusb_config.h index 266cb88cc2fe6..c5644e3d583b2 100644 --- a/shared/tinyusb/tusb_config.h +++ b/shared/tinyusb/tusb_config.h @@ -31,6 +31,10 @@ #if MICROPY_HW_ENABLE_USBDEV +#ifndef MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE +#define MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE 0 +#endif + #ifndef MICROPY_HW_USB_MANUFACTURER_STRING #define MICROPY_HW_USB_MANUFACTURER_STRING "MicroPython" #endif @@ -86,12 +90,9 @@ #define CFG_TUD_MSC_BUFSIZE (MICROPY_FATFS_MAX_SS) #endif -// Define static descriptor size and interface count based on the above config +#define USBD_RHPORT (0) // Currently only one port is supported -#define USBD_STATIC_DESC_LEN (TUD_CONFIG_DESC_LEN + \ - (CFG_TUD_CDC ? (TUD_CDC_DESC_LEN) : 0) + \ - (CFG_TUD_MSC ? (TUD_MSC_DESC_LEN) : 0) \ - ) +// Define built-in interface, string and endpoint numbering based on the above config #define USBD_STR_0 (0x00) #define USBD_STR_MANUF (0x01) @@ -126,19 +127,19 @@ #endif // CFG_TUD_CDC #endif // CFG_TUD_MSC -/* Limits of statically defined USB interfaces, endpoints, strings */ +/* Limits of builtin USB interfaces, endpoints, strings */ #if CFG_TUD_MSC -#define USBD_ITF_STATIC_MAX (USBD_ITF_MSC + 1) -#define USBD_STR_STATIC_MAX (USBD_STR_MSC + 1) -#define USBD_EP_STATIC_MAX (EPNUM_MSC_OUT + 1) +#define USBD_ITF_BUILTIN_MAX (USBD_ITF_MSC + 1) +#define USBD_STR_BUILTIN_MAX (USBD_STR_MSC + 1) +#define USBD_EP_BUILTIN_MAX (EPNUM_MSC_OUT + 1) #elif CFG_TUD_CDC -#define USBD_ITF_STATIC_MAX (USBD_ITF_CDC + 2) -#define USBD_STR_STATIC_MAX (USBD_STR_CDC + 1) -#define USBD_EP_STATIC_MAX (((EPNUM_CDC_EP_IN)&~TUSB_DIR_IN_MASK) + 1) +#define USBD_ITF_BUILTIN_MAX (USBD_ITF_CDC + 2) +#define USBD_STR_BUILTIN_MAX (USBD_STR_CDC + 1) +#define USBD_EP_BUILTIN_MAX (((USBD_CDC_EP_IN)&~TUSB_DIR_IN_MASK) + 1) #else // !CFG_TUD_MSC && !CFG_TUD_CDC -#define USBD_ITF_STATIC_MAX (0) -#define USBD_STR_STATIC_MAX (0) -#define USBD_EP_STATIC_MAX (0) +#define USBD_ITF_BUILTIN_MAX (0) +#define USBD_STR_BUILTIN_MAX (0) +#define USBD_EP_BUILTIN_MAX (0) #endif #endif // MICROPY_HW_ENABLE_USBDEV From 0baa3b5528257d2d8c3ada5842885d83b9acbb75 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 13 Mar 2024 10:38:05 +1100 Subject: [PATCH 216/408] rp2: Enable support for Python USB devices. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- ports/rp2/CMakeLists.txt | 2 ++ ports/rp2/main.c | 4 ++++ ports/rp2/mpconfigport.h | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt index 392fed29b1ff4..b605faaf2100e 100644 --- a/ports/rp2/CMakeLists.txt +++ b/ports/rp2/CMakeLists.txt @@ -108,6 +108,7 @@ set(MICROPY_SOURCE_LIB ${MICROPY_DIR}/shared/tinyusb/mp_cdc_common.c ${MICROPY_DIR}/shared/tinyusb/mp_usbd.c ${MICROPY_DIR}/shared/tinyusb/mp_usbd_descriptor.c + ${MICROPY_DIR}/shared/tinyusb/mp_usbd_runtime.c ) set(MICROPY_SOURCE_DRIVERS @@ -146,6 +147,7 @@ set(MICROPY_SOURCE_QSTR ${MICROPY_DIR}/shared/readline/readline.c ${MICROPY_DIR}/shared/runtime/mpirq.c ${MICROPY_DIR}/shared/runtime/sys_stdio_mphal.c + ${MICROPY_DIR}/shared/tinyusb/mp_usbd_runtime.c ${MICROPY_PORT_DIR}/machine_adc.c ${MICROPY_PORT_DIR}/machine_i2c.c ${MICROPY_PORT_DIR}/machine_pin.c diff --git a/ports/rp2/main.c b/ports/rp2/main.c index 70a67066fc9d7..40374faff92e3 100644 --- a/ports/rp2/main.c +++ b/ports/rp2/main.c @@ -221,6 +221,10 @@ int main(int argc, char **argv) { mp_thread_deinit(); #endif soft_timer_deinit(); + #if MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE + mp_usbd_deinit(); + #endif + gc_sweep_all(); mp_deinit(); } diff --git a/ports/rp2/mpconfigport.h b/ports/rp2/mpconfigport.h index c11d2fa69d5a9..a29692d0be071 100644 --- a/ports/rp2/mpconfigport.h +++ b/ports/rp2/mpconfigport.h @@ -52,6 +52,10 @@ #ifndef MICROPY_HW_USB_MSC #define MICROPY_HW_USB_MSC (0) #endif + +#ifndef MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE +#define MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE (1) // Support machine.USBDevice +#endif #endif #ifndef MICROPY_CONFIG_ROM_LEVEL From 7f5d8c4605e9305b7d1dbb100d6704618f8f3b4b Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 23 Nov 2023 09:53:16 +1100 Subject: [PATCH 217/408] samd: Enable support for Python USB devices. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- ports/samd/Makefile | 1 + ports/samd/main.c | 3 +++ ports/samd/mpconfigport.h | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/ports/samd/Makefile b/ports/samd/Makefile index 5a7cb9916a349..b678cd9828c6b 100644 --- a/ports/samd/Makefile +++ b/ports/samd/Makefile @@ -136,6 +136,7 @@ SHARED_SRC_C += \ shared/tinyusb/mp_cdc_common.c \ shared/tinyusb/mp_usbd.c \ shared/tinyusb/mp_usbd_descriptor.c \ + shared/tinyusb/mp_usbd_runtime.c \ ASF4_SRC_C += $(addprefix lib/asf4/$(MCU_SERIES_LOWER)/,\ hal/src/hal_atomic.c \ diff --git a/ports/samd/main.c b/ports/samd/main.c index f051e961ffa24..9f213f27d41cf 100644 --- a/ports/samd/main.c +++ b/ports/samd/main.c @@ -93,6 +93,9 @@ void samd_main(void) { pwm_deinit_all(); #endif soft_timer_deinit(); + #if MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE + mp_usbd_deinit(); + #endif gc_sweep_all(); #if MICROPY_PY_MACHINE_I2C || MICROPY_PY_MACHINE_SPI || MICROPY_PY_MACHINE_UART sercom_deinit_all(); diff --git a/ports/samd/mpconfigport.h b/ports/samd/mpconfigport.h index 28a99333d35b9..0b47500bf7e7c 100644 --- a/ports/samd/mpconfigport.h +++ b/ports/samd/mpconfigport.h @@ -63,8 +63,13 @@ #ifndef MICROPY_HW_USB_DESC_STR_MAX #define MICROPY_HW_USB_DESC_STR_MAX (32) #endif +// Support machine.USBDevice +#ifndef MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE +#define MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE (1) #endif +#endif // MICROPY_HW_ENABLE_USBDEV + #define MICROPY_PY_SYS_PLATFORM "samd" // Extended modules From 5bed292c06ec712f501dda7e2cc202b7039c33b4 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Mon, 13 Nov 2023 17:17:57 +0100 Subject: [PATCH 218/408] lib/open-amp: Add OpenAMP submodule. OpenAMP framework provides a standard inter processor communications infrastructure for RTOS and bare metal environments. There are 3 major components in OpenAMP: libmetal, remoteproc and RPMsg. libmetal provides abstraction of the low-level underlying hardware, remoteproc is used for processor Life Cycle Management (LCM) like loading firmware, starting, stopping a core etc., and RPMsg is a bus infrastructure that enables Inter Processor Communications (IPC) between different cores. Signed-off-by: iabdalkader --- .gitmodules | 3 +++ lib/open-amp | 1 + 2 files changed, 4 insertions(+) create mode 160000 lib/open-amp diff --git a/.gitmodules b/.gitmodules index 75bffdadddeb8..39cf208412404 100644 --- a/.gitmodules +++ b/.gitmodules @@ -59,3 +59,6 @@ [submodule "lib/protobuf-c"] path = lib/protobuf-c url = https://github.com/protobuf-c/protobuf-c.git +[submodule "lib/open-amp"] + path = lib/open-amp + url = https://github.com/OpenAMP/open-amp.git diff --git a/lib/open-amp b/lib/open-amp new file mode 160000 index 0000000000000..1904dee18da85 --- /dev/null +++ b/lib/open-amp @@ -0,0 +1 @@ +Subproject commit 1904dee18da85400e72b8f55c5c99e872a486573 From f6213ffc5cb7ea1cb3c7ec10ccd9032035c12159 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Tue, 20 Feb 2024 12:28:36 +0100 Subject: [PATCH 219/408] lib/libmetal: Add libmetal submodule. libmetal provides an abstraction of the underlying hardware, to support other OpenAMP components. Signed-off-by: iabdalkader --- .gitmodules | 3 +++ lib/libmetal | 1 + 2 files changed, 4 insertions(+) create mode 160000 lib/libmetal diff --git a/.gitmodules b/.gitmodules index 39cf208412404..aa9bb3d6d94cd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -62,3 +62,6 @@ [submodule "lib/open-amp"] path = lib/open-amp url = https://github.com/OpenAMP/open-amp.git +[submodule "lib/libmetal"] + path = lib/libmetal + url = https://github.com/OpenAMP/libmetal.git diff --git a/lib/libmetal b/lib/libmetal new file mode 160000 index 0000000000000..0cb7d293a7f25 --- /dev/null +++ b/lib/libmetal @@ -0,0 +1 @@ +Subproject commit 0cb7d293a7f25394a06847a28d0f0ace9862936e From 61ee59ad8917d64f4f4a0e7a261fd838c5724014 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Tue, 20 Feb 2024 12:41:04 +0100 Subject: [PATCH 220/408] extmod/libmetal: Add MicroPython platform for libmetal. Add a MicroPython platform for libmetal, based on the generic platform. The MicroPython platform uses common mp_hal_xxx functions and allows ports to customize default configurations for libmetal. Signed-off-by: Jim Mussared Signed-off-by: iabdalkader --- extmod/libmetal/libmetal.mk | 51 ++++++++++++ extmod/libmetal/metal/config.h | 81 +++++++++++++++++++ .../libmetal/metal/system/micropython/alloc.h | 1 + .../libmetal/metal/system/micropython/log.h | 1 + .../libmetal/metal/system/micropython/sleep.h | 1 + .../libmetal/metal/system/micropython/sys.h | 5 ++ 6 files changed, 140 insertions(+) create mode 100644 extmod/libmetal/libmetal.mk create mode 100644 extmod/libmetal/metal/config.h create mode 100644 extmod/libmetal/metal/system/micropython/alloc.h create mode 100644 extmod/libmetal/metal/system/micropython/log.h create mode 100644 extmod/libmetal/metal/system/micropython/sleep.h create mode 100644 extmod/libmetal/metal/system/micropython/sys.h diff --git a/extmod/libmetal/libmetal.mk b/extmod/libmetal/libmetal.mk new file mode 100644 index 0000000000000..852b04289833b --- /dev/null +++ b/extmod/libmetal/libmetal.mk @@ -0,0 +1,51 @@ +# Makefile directives for libmetal + +# libmetal is intended to run through a pre-processor (as part of its CMake-based build system). +# This replicates the basic functionality of the pre-processor, including adding a "micropython" +# platform that is almost identical to the built-in "generic" platform with a few small changes +# provided by the files in extmod/libmetal. +$(BUILD)/openamp: $(BUILD) + $(MKDIR) -p $@ + +$(BUILD)/openamp/metal: $(BUILD)/openamp + $(MKDIR) -p $@ + +$(BUILD)/openamp/metal/config.h: $(BUILD)/openamp/metal $(TOP)/$(LIBMETAL_DIR)/lib/config.h + @$(ECHO) "GEN $@" + @for file in $(TOP)/$(LIBMETAL_DIR)/lib/*.c $(TOP)/$(LIBMETAL_DIR)/lib/*.h; do $(SED) -e "s/@PROJECT_SYSTEM@/micropython/g" -e "s/@PROJECT_PROCESSOR@/arm/g" $$file > $(BUILD)/openamp/metal/$$(basename $$file); done + $(MKDIR) -p $(BUILD)/openamp/metal/processor/arm + @$(CP) $(TOP)/$(LIBMETAL_DIR)/lib/processor/arm/*.h $(BUILD)/openamp/metal/processor/arm + $(MKDIR) -p $(BUILD)/openamp/metal/compiler/gcc + @$(CP) $(TOP)/$(LIBMETAL_DIR)/lib/compiler/gcc/*.h $(BUILD)/openamp/metal/compiler/gcc + $(MKDIR) -p $(BUILD)/openamp/metal/system/micropython + @$(CP) $(TOP)/$(LIBMETAL_DIR)/lib/system/generic/*.c $(TOP)/$(LIBMETAL_DIR)/lib/system/generic/*.h $(BUILD)/openamp/metal/system/micropython + @$(CP) $(TOP)/extmod/libmetal/metal/system/micropython/* $(BUILD)/openamp/metal/system/micropython + @$(CP) $(TOP)/extmod/libmetal/metal/config.h $(BUILD)/openamp/metal/config.h + +# libmetal's source files. +SRC_LIBMETAL_C := $(addprefix $(BUILD)/openamp/metal/,\ + device.c \ + dma.c \ + init.c \ + io.c \ + irq.c \ + log.c \ + shmem.c \ + softirq.c \ + version.c \ + device.c \ + system/micropython/condition.c \ + system/micropython/device.c \ + system/micropython/io.c \ + system/micropython/irq.c \ + system/micropython/shmem.c \ + system/micropython/time.c \ + ) + +# These files are generated by the rule above (along with config.h), so we need to make the .c +# files depend on that step -- can't use the .o files as the target because the .c files don't +# exist yet. +$(SRC_LIBMETAL_C): $(BUILD)/openamp/metal/config.h + +# Qstr processing will include the generated libmetal headers, so add them as a qstr requirement. +QSTR_GLOBAL_REQUIREMENTS += $(BUILD)/openamp/metal/config.h diff --git a/extmod/libmetal/metal/config.h b/extmod/libmetal/metal/config.h new file mode 100644 index 0000000000000..459a2f4ca424d --- /dev/null +++ b/extmod/libmetal/metal/config.h @@ -0,0 +1,81 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2024 Arduino SA + * + * 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. + * + * MicroPython libmetal config. + */ +#ifndef MICROPY_INCLUDED_METAL_MICROPYTHON_H +#define MICROPY_INCLUDED_METAL_MICROPYTHON_H + +#include + +// Port-specific config. +#include "mpmetalport.h" + +// Library major version number. +#define METAL_VER_MAJOR 1 + +// Library minor version number. +#define METAL_VER_MINOR 5 + +// Library patch level. +#define METAL_VER_PATCH 0 + +// Library version string. +#define METAL_VER "1.5.0" + +#if METAL_HAVE_STDATOMIC_H +#define HAVE_STDATOMIC_H +#endif + +#if METAL_HAVE_FUTEX_H +#define HAVE_FUTEX_H +#endif + +#ifndef METAL_MAX_DEVICE_REGIONS +#define METAL_MAX_DEVICE_REGIONS 1 +#endif + +// generic/log.h +#if METAL_LOG_HANDLER_ENABLE +#include "py/mphal.h" +#undef metal_log +#define metal_log(level, ...) mp_printf(&mp_plat_print, __VA_ARGS__) +#endif + +static inline void *__metal_allocate_memory(unsigned int size) { + return m_tracked_calloc(1, size); +} + +static inline void __metal_free_memory(void *ptr) { + m_tracked_free(ptr); +} + +// The following functions must be provided by the port (in mpmetalport.h / mpmetalport.c). +int __metal_sleep_usec(unsigned int usec); +void sys_irq_enable(unsigned int vector); +void sys_irq_disable(unsigned int vector); +void sys_irq_restore_enable(unsigned int flags); +unsigned int sys_irq_save_disable(void); +#endif // MICROPY_INCLUDED_METAL_MICROPYTHON_H diff --git a/extmod/libmetal/metal/system/micropython/alloc.h b/extmod/libmetal/metal/system/micropython/alloc.h new file mode 100644 index 0000000000000..dd0fdb13f9252 --- /dev/null +++ b/extmod/libmetal/metal/system/micropython/alloc.h @@ -0,0 +1 @@ +#include diff --git a/extmod/libmetal/metal/system/micropython/log.h b/extmod/libmetal/metal/system/micropython/log.h new file mode 100644 index 0000000000000..dd0fdb13f9252 --- /dev/null +++ b/extmod/libmetal/metal/system/micropython/log.h @@ -0,0 +1 @@ +#include diff --git a/extmod/libmetal/metal/system/micropython/sleep.h b/extmod/libmetal/metal/system/micropython/sleep.h new file mode 100644 index 0000000000000..dd0fdb13f9252 --- /dev/null +++ b/extmod/libmetal/metal/system/micropython/sleep.h @@ -0,0 +1 @@ +#include diff --git a/extmod/libmetal/metal/system/micropython/sys.h b/extmod/libmetal/metal/system/micropython/sys.h new file mode 100644 index 0000000000000..0f404dcd61284 --- /dev/null +++ b/extmod/libmetal/metal/system/micropython/sys.h @@ -0,0 +1,5 @@ +#include + +struct metal_state { + struct metal_common_state common; +}; From 85028aadab6763a0d899e71f54643840d9f8546d Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Mon, 20 Nov 2023 14:24:04 +0100 Subject: [PATCH 221/408] py/stream: Add mp_stream_seek() helper function. Signed-off-by: iabdalkader --- py/stream.c | 12 ++++++++++++ py/stream.h | 1 + 2 files changed, 13 insertions(+) diff --git a/py/stream.c b/py/stream.c index aa905ca8cc904..e008fb999ea32 100644 --- a/py/stream.c +++ b/py/stream.c @@ -82,6 +82,18 @@ mp_uint_t mp_stream_rw(mp_obj_t stream, void *buf_, mp_uint_t size, int *errcode return done; } +mp_uint_t mp_stream_seek(mp_obj_t stream, mp_off_t offset, int whence, int *errcode) { + struct mp_stream_seek_t seek_s; + seek_s.offset = offset; + seek_s.whence = whence; + const mp_stream_p_t *stream_p = mp_get_stream(stream); + mp_uint_t res = stream_p->ioctl(MP_OBJ_FROM_PTR(stream), MP_STREAM_SEEK, (mp_uint_t)(uintptr_t)&seek_s, errcode); + if (res == MP_STREAM_ERROR) { + return -1; + } + return seek_s.offset; +} + const mp_stream_p_t *mp_get_stream_raise(mp_obj_t self_in, int flags) { const mp_obj_type_t *type = mp_obj_get_type(self_in); if (MP_OBJ_TYPE_HAS_SLOT(type, protocol)) { diff --git a/py/stream.h b/py/stream.h index e6e6f283df177..7c2e87a87c47a 100644 --- a/py/stream.h +++ b/py/stream.h @@ -115,6 +115,7 @@ mp_obj_t mp_stream_write(mp_obj_t self_in, const void *buf, size_t len, byte fla mp_uint_t mp_stream_rw(mp_obj_t stream, void *buf, mp_uint_t size, int *errcode, byte flags); #define mp_stream_write_exactly(stream, buf, size, err) mp_stream_rw(stream, (byte *)buf, size, err, MP_STREAM_RW_WRITE) #define mp_stream_read_exactly(stream, buf, size, err) mp_stream_rw(stream, buf, size, err, MP_STREAM_RW_READ) +mp_uint_t mp_stream_seek(mp_obj_t stream, mp_off_t offset, int whence, int *errcode); void mp_stream_write_adaptor(void *self, const char *buf, size_t len); From b72602250929234dbdbba084ca0dc4fc94b056ae Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 29 Feb 2024 15:21:56 +1100 Subject: [PATCH 222/408] py/stream: Factor stream implementations. So there's only one location that does the ioctl(MP_STREAM_SEEK) call. Signed-off-by: Damien George --- py/stream.c | 31 ++++++++++++------------------- py/stream.h | 2 +- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/py/stream.c b/py/stream.c index e008fb999ea32..d7a8881e1a32d 100644 --- a/py/stream.c +++ b/py/stream.c @@ -82,14 +82,14 @@ mp_uint_t mp_stream_rw(mp_obj_t stream, void *buf_, mp_uint_t size, int *errcode return done; } -mp_uint_t mp_stream_seek(mp_obj_t stream, mp_off_t offset, int whence, int *errcode) { +mp_off_t mp_stream_seek(mp_obj_t stream, mp_off_t offset, int whence, int *errcode) { struct mp_stream_seek_t seek_s; seek_s.offset = offset; seek_s.whence = whence; const mp_stream_p_t *stream_p = mp_get_stream(stream); mp_uint_t res = stream_p->ioctl(MP_OBJ_FROM_PTR(stream), MP_STREAM_SEEK, (mp_uint_t)(uintptr_t)&seek_s, errcode); if (res == MP_STREAM_ERROR) { - return -1; + return (mp_off_t)-1; } return seek_s.offset; } @@ -457,28 +457,26 @@ static mp_obj_t mp_stream___exit__(size_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream___exit___obj, 4, 4, mp_stream___exit__); static mp_obj_t stream_seek(size_t n_args, const mp_obj_t *args) { - struct mp_stream_seek_t seek_s; // TODO: Could be uint64 - seek_s.offset = mp_obj_get_int(args[1]); - seek_s.whence = SEEK_SET; + mp_off_t offset = mp_obj_get_int(args[1]); + int whence = SEEK_SET; if (n_args == 3) { - seek_s.whence = mp_obj_get_int(args[2]); + whence = mp_obj_get_int(args[2]); } // In POSIX, it's error to seek before end of stream, we enforce it here. - if (seek_s.whence == SEEK_SET && seek_s.offset < 0) { + if (whence == SEEK_SET && offset < 0) { mp_raise_OSError(MP_EINVAL); } - const mp_stream_p_t *stream_p = mp_get_stream(args[0]); int error; - mp_uint_t res = stream_p->ioctl(args[0], MP_STREAM_SEEK, (mp_uint_t)(uintptr_t)&seek_s, &error); - if (res == MP_STREAM_ERROR) { + mp_off_t res = mp_stream_seek(args[0], offset, whence, &error); + if (res == (mp_off_t)-1) { mp_raise_OSError(error); } // TODO: Could be uint64 - return mp_obj_new_int_from_uint(seek_s.offset); + return mp_obj_new_int_from_uint(res); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_seek_obj, 2, 3, stream_seek); @@ -557,16 +555,11 @@ ssize_t mp_stream_posix_read(void *stream, void *buf, size_t len) { } off_t mp_stream_posix_lseek(void *stream, off_t offset, int whence) { - const mp_obj_base_t *o = stream; - const mp_stream_p_t *stream_p = MP_OBJ_TYPE_GET_SLOT(o->type, protocol); - struct mp_stream_seek_t seek_s; - seek_s.offset = offset; - seek_s.whence = whence; - mp_uint_t res = stream_p->ioctl(MP_OBJ_FROM_PTR(stream), MP_STREAM_SEEK, (mp_uint_t)(uintptr_t)&seek_s, &errno); - if (res == MP_STREAM_ERROR) { + mp_off_t res = mp_stream_seek(MP_OBJ_FROM_PTR(stream), offset, whence, &errno); + if (res == (mp_off_t)-1) { return -1; } - return seek_s.offset; + return res; } int mp_stream_posix_fsync(void *stream) { diff --git a/py/stream.h b/py/stream.h index 7c2e87a87c47a..7c4d38afa9b67 100644 --- a/py/stream.h +++ b/py/stream.h @@ -115,7 +115,7 @@ mp_obj_t mp_stream_write(mp_obj_t self_in, const void *buf, size_t len, byte fla mp_uint_t mp_stream_rw(mp_obj_t stream, void *buf, mp_uint_t size, int *errcode, byte flags); #define mp_stream_write_exactly(stream, buf, size, err) mp_stream_rw(stream, (byte *)buf, size, err, MP_STREAM_RW_WRITE) #define mp_stream_read_exactly(stream, buf, size, err) mp_stream_rw(stream, buf, size, err, MP_STREAM_RW_READ) -mp_uint_t mp_stream_seek(mp_obj_t stream, mp_off_t offset, int whence, int *errcode); +mp_off_t mp_stream_seek(mp_obj_t stream, mp_off_t offset, int whence, int *errcode); void mp_stream_write_adaptor(void *self, const char *buf, size_t len); From 162054be85a58466edea2297abba9aadc6c3d597 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Mon, 11 Dec 2023 13:19:07 +0100 Subject: [PATCH 223/408] stm32/mpu: Add MPU config for shared, uncached memory region. Signed-off-by: iabdalkader --- ports/stm32/mpu.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ports/stm32/mpu.h b/ports/stm32/mpu.h index 64880a85db75f..5ef1466184aac 100644 --- a/ports/stm32/mpu.h +++ b/ports/stm32/mpu.h @@ -36,6 +36,7 @@ #define MPU_REGION_QSPI3 (MPU_REGION_NUMBER3) #define MPU_REGION_SDRAM1 (MPU_REGION_NUMBER4) #define MPU_REGION_SDRAM2 (MPU_REGION_NUMBER5) +#define MPU_REGION_OPENAMP (MPU_REGION_NUMBER15) // Only relevant on CPUs with D-Cache, must be higher priority than SDRAM #define MPU_REGION_DMA_UNCACHED_1 (MPU_REGION_NUMBER6) @@ -94,6 +95,18 @@ | MPU_REGION_ENABLE << MPU_RASR_ENABLE_Pos \ ) +#define MPU_CONFIG_SHARED_UNCACHED(size) ( \ + MPU_INSTRUCTION_ACCESS_DISABLE << MPU_RASR_XN_Pos \ + | MPU_REGION_FULL_ACCESS << MPU_RASR_AP_Pos \ + | MPU_TEX_LEVEL1 << MPU_RASR_TEX_Pos \ + | MPU_ACCESS_SHAREABLE << MPU_RASR_S_Pos \ + | MPU_ACCESS_NOT_CACHEABLE << MPU_RASR_C_Pos \ + | MPU_ACCESS_NOT_BUFFERABLE << MPU_RASR_B_Pos \ + | 0x00 << MPU_RASR_SRD_Pos \ + | (size) << MPU_RASR_SIZE_Pos \ + | MPU_REGION_ENABLE << MPU_RASR_ENABLE_Pos \ + ) + static inline void mpu_init(void) { MPU->CTRL = MPU_PRIVILEGED_DEFAULT | MPU_CTRL_ENABLE_Msk; SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk; From 14dae42fe7a4c8c147d528e998e10a6a80d28ae5 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Tue, 20 Feb 2024 14:07:13 +0100 Subject: [PATCH 224/408] extmod/modopenamp: Add new OpenAMP module. This module implements OpenAMP's basic initialization and shared resources support, and provides support for OpenAMP's RPMsg component, by providing an `endpoint` type (a logical connection on top of RPMsg channel) which can be used to communicate with the remote core. Signed-off-by: iabdalkader --- extmod/extmod.mk | 42 +++++ extmod/modopenamp.c | 395 ++++++++++++++++++++++++++++++++++++++++++++ extmod/modopenamp.h | 81 +++++++++ 3 files changed, 518 insertions(+) create mode 100644 extmod/modopenamp.c create mode 100644 extmod/modopenamp.h diff --git a/extmod/extmod.mk b/extmod/extmod.mk index 4f5f7d53ac4b8..54689ef65e9d4 100644 --- a/extmod/extmod.mk +++ b/extmod/extmod.mk @@ -31,6 +31,7 @@ SRC_EXTMOD_C += \ extmod/modmachine.c \ extmod/modnetwork.c \ extmod/modonewire.c \ + extmod/modopenamp.c \ extmod/modos.c \ extmod/modplatform.c\ extmod/modrandom.c \ @@ -515,3 +516,44 @@ include $(TOP)/extmod/btstack/btstack.mk endif endif + +################################################################################ +# openamp + +ifeq ($(MICROPY_PY_OPENAMP),1) +OPENAMP_DIR = lib/open-amp +LIBMETAL_DIR = lib/libmetal +GIT_SUBMODULES += $(LIBMETAL_DIR) $(OPENAMP_DIR) +include $(TOP)/extmod/libmetal/libmetal.mk + +INC += -I$(TOP)/$(OPENAMP_DIR) +CFLAGS += -DMICROPY_PY_OPENAMP=1 + +CFLAGS_THIRDPARTY += \ + -I$(BUILD)/openamp \ + -I$(TOP)/$(OPENAMP_DIR) \ + -I$(TOP)/$(OPENAMP_DIR)/lib/include/ \ + -DMETAL_INTERNAL \ + -DVIRTIO_DRIVER_ONLY \ + -DNO_ATOMIC_64_SUPPORT \ + -DRPMSG_BUFFER_SIZE=512 \ + +# OpenAMP's source files. +SRC_OPENAMP_C += $(addprefix $(OPENAMP_DIR)/lib/,\ + rpmsg/rpmsg.c \ + rpmsg/rpmsg_virtio.c \ + virtio/virtio.c \ + virtio/virtqueue.c \ + virtio_mmio/virtio_mmio_drv.c \ + ) + +# Disable compiler warnings in OpenAMP (variables used only for assert). +$(BUILD)/$(OPENAMP_DIR)/lib/rpmsg/rpmsg_virtio.o: CFLAGS += -Wno-unused-but-set-variable +$(BUILD)/$(OPENAMP_DIR)/lib/virtio_mmio/virtio_mmio_drv.o: CFLAGS += -Wno-unused-but-set-variable + +# We need to have generated libmetal before compiling OpenAMP. +$(addprefix $(BUILD)/, $(SRC_OPENAMP_C:.c=.o)): $(BUILD)/openamp/metal/config.h + +SRC_THIRDPARTY_C += $(SRC_LIBMETAL_C) $(SRC_OPENAMP_C) + +endif # MICROPY_PY_OPENAMP diff --git a/extmod/modopenamp.c b/extmod/modopenamp.c new file mode 100644 index 0000000000000..b0c834c2819bf --- /dev/null +++ b/extmod/modopenamp.c @@ -0,0 +1,395 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023-2024 Arduino SA + * + * 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. + * + * OpenAMP's Python module. + */ + +#if MICROPY_PY_OPENAMP + +#include "py/obj.h" +#include "py/nlr.h" +#include "py/runtime.h" + +#include "metal/sys.h" +#include "metal/alloc.h" +#include "metal/errno.h" +#include "metal/io.h" +#include "metal/device.h" +#include "metal/utilities.h" + +#include "openamp/open_amp.h" +#include "openamp/remoteproc.h" +#include "openamp/remoteproc_loader.h" +#include "modopenamp.h" + +#if !MICROPY_ENABLE_FINALISER +#error "MICROPY_PY_OPENAMP requires MICROPY_ENABLE_FINALISER" +#endif + +#if MICROPY_PY_OPENAMP_RSC_TABLE_ENABLE +#define VIRTIO_DEV_ID 0xFF +#define VIRTIO_DEV_FEATURES (1 << VIRTIO_RPMSG_F_NS) + +#define VRING0_ID 0 // VRING0 ID (host to remote) fixed to 0 for linux compatibility +#define VRING1_ID 1 // VRING1 ID (remote to host) fixed to 1 for linux compatibility +#define VRING_NOTIFY_ID VRING0_ID + +#define VRING_COUNT 2 +#define VRING_ALIGNMENT 32 +// Note the number of buffers must be a power of 2 +#define VRING_NUM_BUFFS 64 + +// The following config should be enough for about 128 descriptors. +// See lib/include/openamp/virtio_ring.h for the layout of vrings +// and vring_size() to calculate the vring size. +#define VRING_RX_ADDR (METAL_SHM_ADDR) +#define VRING_TX_ADDR (METAL_SHM_ADDR + 0x1000) +#define VRING_BUFF_ADDR (METAL_SHM_ADDR + 0x2000) +#define VRING_BUFF_SIZE (METAL_SHM_SIZE - 0x2000) + +static const char openamp_trace_buf[128]; +#define MICROPY_PY_OPENAMP_TRACE_BUF ((uint32_t)openamp_trace_buf) +#define MICROPY_PY_OPENAMP_TRACE_BUF_LEN sizeof(MICROPY_PY_OPENAMP_TRACE_BUF) + +#endif // MICROPY_PY_OPENAMP_RSC_TABLE_ENABLE + +#define debug_printf(...) // mp_printf(&mp_plat_print, __VA_ARGS__) + +static struct metal_device shm_device = { + .name = METAL_SHM_NAME, + // The number of IO regions is fixed and must match the number and + // layout of the remote processor's IO regions. The first region is + // used for the vring shared memory, and the second one is used for + // the shared resource table. + .num_regions = METAL_MAX_DEVICE_REGIONS, + .regions = { { 0 } }, + .node = { NULL }, + .irq_num = 0, + .irq_info = NULL +}; +static metal_phys_addr_t shm_physmap[] = { 0 }; + +// ###################### Virtio device class ###################### +typedef struct _virtio_dev_obj_t { + mp_obj_base_t base; + struct rpmsg_virtio_device rvdev; + struct rpmsg_virtio_shm_pool shm_pool; + mp_obj_t ns_callback; +} virtio_dev_obj_t; + +static mp_obj_t virtio_dev_deinit(mp_obj_t self_in) { + virtio_dev_obj_t *virtio_device = MP_OBJ_TO_PTR(self_in); + rpmsg_deinit_vdev(&virtio_device->rvdev); + metal_finish(); + MP_STATE_PORT(virtio_device) = NULL; + return mp_const_none; +} +static MP_DEFINE_CONST_FUN_OBJ_1(virtio_dev_deinit_obj, virtio_dev_deinit); + +static const mp_rom_map_elem_t virtio_dev_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_VirtIODev) }, + { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&virtio_dev_deinit_obj) }, +}; +static MP_DEFINE_CONST_DICT(virtio_dev_locals_dict, virtio_dev_locals_dict_table); + +static MP_DEFINE_CONST_OBJ_TYPE( + virtio_dev_type, + MP_QSTR_VirtIODev, + MP_TYPE_FLAG_NONE, + locals_dict, &virtio_dev_locals_dict + ); + +// ###################### RPMsg Endpoint class ###################### +typedef struct _endpoint_obj_t { + mp_obj_base_t base; + mp_obj_t name; + mp_obj_t callback; + struct rpmsg_endpoint ep; +} endpoint_obj_t; + +static const mp_obj_type_t endpoint_type; + +static int endpoint_recv_callback(struct rpmsg_endpoint *ept, void *data, size_t len, uint32_t src, void *priv) { + debug_printf("endpoint_recv_callback() message received src: %lu msg len: %d\n", src, len); + endpoint_obj_t *self = metal_container_of(ept, endpoint_obj_t, ep); + if (self->callback != mp_const_none) { + mp_call_function_2(self->callback, mp_obj_new_int(src), mp_obj_new_bytearray_by_ref(len, data)); + } + return 0; +} + +static mp_obj_t endpoint_send(uint n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_src, ARG_dest, ARG_timeout }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_src, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1 } }, + { MP_QSTR_dest, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1 } }, + { MP_QSTR_timeout, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1 } }, + }; + + // Parse args. + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 2, pos_args + 2, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + endpoint_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + + if (is_rpmsg_ept_ready(&self->ep) == false) { + mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Endpoint not ready")); + } + + uint32_t src = self->ep.addr; + if (args[ARG_src].u_int != -1) { + src = args[ARG_src].u_int; + } + + uint32_t dest = self->ep.dest_addr; + if (args[ARG_dest].u_int != -1) { + dest = args[ARG_dest].u_int; + } + + mp_buffer_info_t rbuf; + mp_get_buffer_raise(pos_args[1], &rbuf, MP_BUFFER_READ); + debug_printf("endpoint_send() msg len: %d\n", rbuf.len); + + int bytes = 0; + mp_int_t timeout = args[ARG_timeout].u_int; + for (mp_uint_t start = mp_hal_ticks_ms(); ;) { + bytes = rpmsg_send_offchannel_raw(&self->ep, src, dest, rbuf.buf, rbuf.len, false); + if (bytes > 0 || timeout == 0) { + MICROPY_EVENT_POLL_HOOK + break; + } + if (timeout > 0 && (mp_hal_ticks_ms() - start > timeout)) { + mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("timeout waiting for a free buffer")); + } + MICROPY_EVENT_POLL_HOOK + } + return mp_obj_new_int(bytes); +} +static MP_DEFINE_CONST_FUN_OBJ_KW(endpoint_send_obj, 2, endpoint_send); + +static mp_obj_t endpoint_is_ready(mp_obj_t self_in) { + endpoint_obj_t *self = MP_OBJ_TO_PTR(self_in); + return is_rpmsg_ept_ready(&self->ep) ? mp_const_true : mp_const_false; +} +static MP_DEFINE_CONST_FUN_OBJ_1(endpoint_is_ready_obj, endpoint_is_ready); + +static mp_obj_t endpoint_deinit(mp_obj_t self_in) { + endpoint_obj_t *self = MP_OBJ_TO_PTR(self_in); + rpmsg_destroy_ept(&self->ep); + return mp_const_none; +} +static MP_DEFINE_CONST_FUN_OBJ_1(endpoint_deinit_obj, endpoint_deinit); + +static mp_obj_t endpoint_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { + enum { ARG_name, ARG_callback, ARG_src, ARG_dest }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_name, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_rom_obj = MP_ROM_NONE } }, + { MP_QSTR_callback, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_rom_obj = MP_ROM_NONE } }, + { MP_QSTR_src, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = RPMSG_ADDR_ANY } }, + { MP_QSTR_dest, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = RPMSG_ADDR_ANY } }, + }; + + // Parse args. + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + endpoint_obj_t *self = mp_obj_malloc_with_finaliser(endpoint_obj_t, &endpoint_type); + self->name = args[ARG_name].u_obj; + self->callback = args[ARG_callback].u_obj; + + if (MP_STATE_PORT(virtio_device) == NULL) { + openamp_init(); + } + + if (rpmsg_create_ept(&self->ep, &MP_STATE_PORT(virtio_device)->rvdev.rdev, mp_obj_str_get_str(self->name), + args[ARG_src].u_int, args[ARG_dest].u_int, endpoint_recv_callback, NULL) != 0) { + mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Failed to create RPMsg endpoint")); + } + + return MP_OBJ_FROM_PTR(self); +} + +static const mp_rom_map_elem_t endpoint_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_Endpoint) }, + { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&endpoint_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&endpoint_send_obj) }, + { MP_ROM_QSTR(MP_QSTR_is_ready), MP_ROM_PTR(&endpoint_is_ready_obj) }, +}; +static MP_DEFINE_CONST_DICT(endpoint_locals_dict, endpoint_locals_dict_table); + +static MP_DEFINE_CONST_OBJ_TYPE( + endpoint_type, + MP_QSTR_Endpoint, + MP_TYPE_FLAG_NONE, + make_new, endpoint_make_new, + locals_dict, &endpoint_locals_dict + ); + +// ###################### openamp module ###################### +void openamp_remoteproc_notified(mp_sched_node_t *node) { + (void)node; + rproc_virtio_notified(MP_STATE_PORT(virtio_device)->rvdev.vdev, VRING_NOTIFY_ID); +} + +static void openamp_ns_callback(struct rpmsg_device *rdev, const char *name, uint32_t dest) { + debug_printf("rpmsg_new_service_callback() new service request name: %s dest %lu\n", name, dest); + // The remote processor advertises its presence to the host by sending + // the Name Service (NS) announcement containing the name of the channel. + virtio_dev_obj_t *virtio_device = metal_container_of(rdev, virtio_dev_obj_t, rvdev); + if (virtio_device->ns_callback != mp_const_none) { + mp_call_function_2(virtio_device->ns_callback, mp_obj_new_int(dest), mp_obj_new_str(name, strlen(name))); + } +} + +#if MICROPY_PY_OPENAMP_RSC_TABLE_ENABLE +// The shared resource table must be initialized manually by the host here, +// because it's not located in the data region, so the startup code doesn't +// know about it. +static void openamp_rsc_table_init(openamp_rsc_table_t **rsc_table_out) { + openamp_rsc_table_t *rsc_table = METAL_RSC_ADDR; + memset(rsc_table, 0, METAL_RSC_SIZE); + + rsc_table->version = 1; + rsc_table->num = MP_ARRAY_SIZE(rsc_table->offset); + rsc_table->offset[0] = offsetof(openamp_rsc_table_t, vdev); + #if MICROPY_PY_OPENAMP_TRACE_BUF_ENABLE + rsc_table->offset[1] = offsetof(openamp_rsc_table_t, trace); + #endif + rsc_table->vdev = (struct fw_rsc_vdev) { + RSC_VDEV, VIRTIO_ID_RPMSG, 0, VIRTIO_DEV_FEATURES, 0, 0, 0, VRING_COUNT, {0, 0} + }; + rsc_table->vring0 = (struct fw_rsc_vdev_vring) { + VRING_TX_ADDR, VRING_ALIGNMENT, VRING_NUM_BUFFS, VRING0_ID, 0 + }; + rsc_table->vring1 = (struct fw_rsc_vdev_vring) { + VRING_RX_ADDR, VRING_ALIGNMENT, VRING_NUM_BUFFS, VRING1_ID, 0 + }; + #if MICROPY_PY_OPENAMP_TRACE_BUF_ENABLE + rsc_table->trace = (struct fw_rsc_trace) { + RSC_TRACE, MICROPY_PY_OPENAMP_TRACE_BUF, MICROPY_PY_OPENAMP_TRACE_BUF_LEN, 0, "trace_buf" + }; + #endif + #ifdef VIRTIO_USE_DCACHE + // Flush resource table. + metal_cache_flush((uint32_t *)rsc_table, sizeof(openamp_rsc_table_t)); + #endif + *rsc_table_out = rsc_table; +} +#endif // MICROPY_PY_OPENAMP_RSC_TABLE_ENABLE + +static mp_obj_t openamp_new_service_callback(mp_obj_t ns_callback) { + if (MP_STATE_PORT(virtio_device) == NULL) { + openamp_init(); + } + if (ns_callback != mp_const_none && !mp_obj_is_callable(ns_callback)) { + mp_raise_ValueError(MP_ERROR_TEXT("invalid callback")); + } + MP_STATE_PORT(virtio_device)->ns_callback = ns_callback; + return mp_const_none; +} +static MP_DEFINE_CONST_FUN_OBJ_1(openamp_new_service_callback_obj, openamp_new_service_callback); + +void openamp_init(void) { + if (MP_STATE_PORT(virtio_device) != NULL) { + // Already initialized. + return; + } + + struct metal_device *device; + struct metal_init_params metal_params = METAL_INIT_DEFAULTS; + + // Initialize libmetal. + metal_init(&metal_params); + + // Initialize the shared resource table. + openamp_rsc_table_t *rsc_table; + openamp_rsc_table_init(&rsc_table); + + if (metal_register_generic_device(&shm_device) != 0) { + mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Failed to register metal device")); + } + + if (metal_device_open("generic", METAL_SHM_NAME, &device) != 0) { + mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Failed to open metal device")); + } + + // Initialize shared memory IO region. + metal_io_init(&device->regions[0], (void *)METAL_SHM_ADDR, (void *)shm_physmap, METAL_SHM_SIZE, -1U, 0, NULL); + struct metal_io_region *shm_io = metal_device_io_region(device, 0); + if (shm_io == NULL) { + mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Failed to initialize device io region")); + } + + // Initialize resource table IO region. + metal_io_init(&device->regions[1], (void *)rsc_table, (void *)rsc_table, sizeof(*rsc_table), -1U, 0, NULL); + struct metal_io_region *rsc_io = metal_device_io_region(device, 1); + if (rsc_io == NULL) { + mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Failed to initialize device io region")); + } + + // Create virtio device. + struct virtio_device *vdev = rproc_virtio_create_vdev(RPMSG_HOST, VIRTIO_DEV_ID, + &rsc_table->vdev, rsc_io, NULL, metal_rproc_notify, NULL); + if (vdev == NULL) { + mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Failed to create virtio device")); + } + + // Initialize vrings. + struct fw_rsc_vdev_vring *vring_rsc = &rsc_table->vring0; + for (int i = 0; i < VRING_COUNT; i++, vring_rsc++) { + if (rproc_virtio_init_vring(vdev, vring_rsc->notifyid, vring_rsc->notifyid, + (void *)vring_rsc->da, shm_io, vring_rsc->num, vring_rsc->align) != 0) { + mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Failed to initialize vrings")); + } + } + + virtio_dev_obj_t *virtio_device = mp_obj_malloc_with_finaliser(virtio_dev_obj_t, &virtio_dev_type); + virtio_device->ns_callback = mp_const_none; + + // The remote processor detects that the virtio device is ready by polling + // the status field in the resource table. + rpmsg_virtio_init_shm_pool(&virtio_device->shm_pool, (void *)VRING_BUFF_ADDR, (size_t)VRING_BUFF_SIZE); + rpmsg_init_vdev(&virtio_device->rvdev, vdev, openamp_ns_callback, shm_io, &virtio_device->shm_pool); + + MP_STATE_PORT(virtio_device) = virtio_device; +} + +static const mp_rom_map_elem_t globals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_openamp) }, + { MP_ROM_QSTR(MP_QSTR_ENDPOINT_ADDR_ANY), MP_ROM_INT(RPMSG_ADDR_ANY) }, + { MP_ROM_QSTR(MP_QSTR_new_service_callback), MP_ROM_PTR(&openamp_new_service_callback_obj) }, + { MP_ROM_QSTR(MP_QSTR_Endpoint), MP_ROM_PTR(&endpoint_type) }, +}; +static MP_DEFINE_CONST_DICT(globals_dict, globals_dict_table); + +const mp_obj_module_t openamp_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_t)&globals_dict, +}; + +MP_REGISTER_ROOT_POINTER(struct _virtio_dev_obj_t *virtio_device); +MP_REGISTER_MODULE(MP_QSTR_openamp, openamp_module); + +#endif // MICROPY_PY_OPENAMP diff --git a/extmod/modopenamp.h b/extmod/modopenamp.h new file mode 100644 index 0000000000000..750f68929770f --- /dev/null +++ b/extmod/modopenamp.h @@ -0,0 +1,81 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023 Arduino SA + * + * 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. + * + * OpenAMP's Python module. + */ +#ifndef MICROPY_INCLUDED_MODOPENAMP_H +#define MICROPY_INCLUDED_MODOPENAMP_H + +// Include a port config file if one is defined. +#ifdef MICROPY_PY_OPENAMP_CONFIG_FILE +#include MICROPY_PY_OPENAMP_CONFIG_FILE +#endif + +// Use the default resource table layout and initialization code. +// Note ports and boards can override the default table and provide +// a custom one in openamp_rsc_table_t and openamp_rsc_table_init() +#ifndef MICROPY_PY_OPENAMP_RSC_TABLE_ENABLE +#define MICROPY_PY_OPENAMP_RSC_TABLE_ENABLE (1) +#endif + +// This enables a trace buffer that can be used by remote processor for +// writing trace logs. This is enabled by default to increase the default +// resource table's compatibility with common OpenAMP examples. +#ifndef MICROPY_PY_OPENAMP_TRACE_BUF_ENABLE +#define MICROPY_PY_OPENAMP_TRACE_BUF_ENABLE (1) +#endif + +// The resource table is used for sharing the configuration of the virtio +// device, vrings and other resources, between the host and remote cores. +// The layout and address the table structure must match the one used in +// the remote processor's firmware. +#if MICROPY_PY_OPENAMP_RSC_TABLE_ENABLE +typedef struct openamp_rsc_table { + unsigned int version; + unsigned int num; + unsigned int reserved[2]; + #if MICROPY_PY_OPENAMP_TRACE_BUF_ENABLE + unsigned int offset[2]; + #else + unsigned int offset[1]; + #endif + struct fw_rsc_vdev vdev; + struct fw_rsc_vdev_vring vring0; + struct fw_rsc_vdev_vring vring1; + #if MICROPY_PY_OPENAMP_TRACE_BUF_ENABLE + struct fw_rsc_trace trace; + #endif +} openamp_rsc_table_t; +#endif // MICROPY_PY_OPENAMP_RSC_TABLE_ENABLE + +// Performs low-level initialization of OpenAMP, such as initializing libmetal, +// the shared resource table, shared memory regions, vrings and virtio device. +void openamp_init(void); + +// Ports should run this callback in scheduler context, when +// the remote processor notifies the host of pending messages. +void openamp_remoteproc_notified(mp_sched_node_t *node); + +#endif // MICROPY_INCLUDED_MODOPENAMP_H From 81aba8253ae3be7090cc0fcb4702f38cdd0c50c8 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Tue, 20 Feb 2024 14:09:42 +0100 Subject: [PATCH 225/408] extmod/modopenamp_remoteproc: Add new OpenAMP RemoteProc class. RemoteProc provides an API to load firmware and control remote processors. Note: port-specific operations must be implemented to support this class. Signed-off-by: iabdalkader --- extmod/extmod.mk | 16 +++ extmod/modopenamp.c | 7 ++ extmod/modopenamp.h | 12 ++ extmod/modopenamp_remoteproc.c | 175 +++++++++++++++++++++++++++ extmod/modopenamp_remoteproc.h | 46 +++++++ extmod/modopenamp_remoteproc_store.c | 146 ++++++++++++++++++++++ 6 files changed, 402 insertions(+) create mode 100644 extmod/modopenamp_remoteproc.c create mode 100644 extmod/modopenamp_remoteproc.h create mode 100644 extmod/modopenamp_remoteproc_store.c diff --git a/extmod/extmod.mk b/extmod/extmod.mk index 54689ef65e9d4..bf686fbbb4d95 100644 --- a/extmod/extmod.mk +++ b/extmod/extmod.mk @@ -32,6 +32,8 @@ SRC_EXTMOD_C += \ extmod/modnetwork.c \ extmod/modonewire.c \ extmod/modopenamp.c \ + extmod/modopenamp_remoteproc.c \ + extmod/modopenamp_remoteproc_store.c \ extmod/modos.c \ extmod/modplatform.c\ extmod/modrandom.c \ @@ -529,6 +531,10 @@ include $(TOP)/extmod/libmetal/libmetal.mk INC += -I$(TOP)/$(OPENAMP_DIR) CFLAGS += -DMICROPY_PY_OPENAMP=1 +ifeq ($(MICROPY_PY_OPENAMP_REMOTEPROC),1) +CFLAGS += -DMICROPY_PY_OPENAMP_REMOTEPROC=1 +endif + CFLAGS_THIRDPARTY += \ -I$(BUILD)/openamp \ -I$(TOP)/$(OPENAMP_DIR) \ @@ -547,6 +553,16 @@ SRC_OPENAMP_C += $(addprefix $(OPENAMP_DIR)/lib/,\ virtio_mmio/virtio_mmio_drv.c \ ) +# OpenAMP's remoteproc source files. +ifeq ($(MICROPY_PY_OPENAMP_REMOTEPROC),1) +SRC_OPENAMP_C += $(addprefix $(OPENAMP_DIR)/lib/remoteproc/,\ + elf_loader.c \ + remoteproc.c \ + remoteproc_virtio.c \ + rsc_table_parser.c \ + ) +endif # MICROPY_PY_OPENAMP_REMOTEPROC + # Disable compiler warnings in OpenAMP (variables used only for assert). $(BUILD)/$(OPENAMP_DIR)/lib/rpmsg/rpmsg_virtio.o: CFLAGS += -Wno-unused-but-set-variable $(BUILD)/$(OPENAMP_DIR)/lib/virtio_mmio/virtio_mmio_drv.o: CFLAGS += -Wno-unused-but-set-variable diff --git a/extmod/modopenamp.c b/extmod/modopenamp.c index b0c834c2819bf..eb19c4b737ac1 100644 --- a/extmod/modopenamp.c +++ b/extmod/modopenamp.c @@ -77,6 +77,10 @@ static const char openamp_trace_buf[128]; #define debug_printf(...) // mp_printf(&mp_plat_print, __VA_ARGS__) +#if MICROPY_PY_OPENAMP_REMOTEPROC +extern mp_obj_type_t openamp_remoteproc_type; +#endif + static struct metal_device shm_device = { .name = METAL_SHM_NAME, // The number of IO regions is fixed and must match the number and @@ -381,6 +385,9 @@ static const mp_rom_map_elem_t globals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_ENDPOINT_ADDR_ANY), MP_ROM_INT(RPMSG_ADDR_ANY) }, { MP_ROM_QSTR(MP_QSTR_new_service_callback), MP_ROM_PTR(&openamp_new_service_callback_obj) }, { MP_ROM_QSTR(MP_QSTR_Endpoint), MP_ROM_PTR(&endpoint_type) }, + #if MICROPY_PY_OPENAMP_REMOTEPROC + { MP_ROM_QSTR(MP_QSTR_RemoteProc), MP_ROM_PTR(&openamp_remoteproc_type) }, + #endif }; static MP_DEFINE_CONST_DICT(globals_dict, globals_dict_table); diff --git a/extmod/modopenamp.h b/extmod/modopenamp.h index 750f68929770f..8f677788f90be 100644 --- a/extmod/modopenamp.h +++ b/extmod/modopenamp.h @@ -47,6 +47,18 @@ #define MICROPY_PY_OPENAMP_TRACE_BUF_ENABLE (1) #endif +// For ports that don't define a custom image store, this enables a generic +// VFS-based image store that supports loading elf files from storage. +#ifndef MICROPY_PY_OPENAMP_REMOTEPROC_STORE_ENABLE +#define MICROPY_PY_OPENAMP_REMOTEPROC_STORE_ENABLE (1) +#endif + +// Enable or disable support for loading elf files. This option saves +// around 7KBs when disabled. +#ifndef MICROPY_PY_OPENAMP_REMOTEPROC_ELFLD_ENABLE +#define MICROPY_PY_OPENAMP_REMOTEPROC_ELFLD_ENABLE (1) +#endif + // The resource table is used for sharing the configuration of the virtio // device, vrings and other resources, between the host and remote cores. // The layout and address the table structure must match the one used in diff --git a/extmod/modopenamp_remoteproc.c b/extmod/modopenamp_remoteproc.c new file mode 100644 index 0000000000000..6f43c71546bf2 --- /dev/null +++ b/extmod/modopenamp_remoteproc.c @@ -0,0 +1,175 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023-2024 Arduino SA + * + * 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. + * + * OpenAMP's remoteproc class. + */ + +#if MICROPY_PY_OPENAMP_REMOTEPROC + +#include "py/obj.h" +#include "py/nlr.h" +#include "py/runtime.h" +#include "py/stream.h" +#include "extmod/vfs.h" + +#include "metal/sys.h" +#include "metal/alloc.h" +#include "metal/errno.h" +#include "metal/io.h" + +#include "openamp/open_amp.h" +#include "openamp/remoteproc.h" +#include "openamp/remoteproc_loader.h" + +#include "modopenamp.h" +#include "modopenamp_remoteproc.h" + +#define DEBUG_printf(...) // mp_printf(&mp_plat_print, __VA_ARGS__) + +#if !MICROPY_PY_OPENAMP +#error "MICROPY_PY_OPENAMP_REMOTEPROC requires MICROPY_PY_OPENAMP" +#endif + +typedef struct openamp_remoteproc_obj { + mp_obj_base_t base; + struct remoteproc rproc; +} openamp_remoteproc_obj_t; + +const mp_obj_type_t openamp_remoteproc_type; + +// Port-defined image store operations. +extern struct image_store_ops openamp_remoteproc_store_ops; + +// Port-defined remote-proc operations. +const struct remoteproc_ops openamp_remoteproc_ops = { + .init = mp_openamp_remoteproc_init, + .mmap = mp_openamp_remoteproc_mmap, + .start = mp_openamp_remoteproc_start, + .stop = mp_openamp_remoteproc_stop, + .config = mp_openamp_remoteproc_config, + .remove = mp_openamp_remoteproc_remove, + .shutdown = mp_openamp_remoteproc_shutdown, +}; + +static mp_obj_t openamp_remoteproc_start(mp_obj_t self_in) { + openamp_remoteproc_obj_t *self = MP_OBJ_TO_PTR(self_in); + + // Start the processor to run the application. + int error = remoteproc_start(&self->rproc); + if (error != 0) { + self->rproc.state = RPROC_ERROR; + mp_raise_OSError(error); + } + return mp_const_none; +} +static MP_DEFINE_CONST_FUN_OBJ_1(openamp_remoteproc_start_obj, openamp_remoteproc_start); + +static mp_obj_t openamp_remoteproc_stop(mp_obj_t self_in) { + openamp_remoteproc_obj_t *self = MP_OBJ_TO_PTR(self_in); + + // Stop the processor, but the processor is not powered down. + int error = remoteproc_stop(&self->rproc); + if (error != 0) { + mp_raise_OSError(error); + } + return mp_const_none; +} +static MP_DEFINE_CONST_FUN_OBJ_1(openamp_remoteproc_stop_obj, openamp_remoteproc_stop); + +static mp_obj_t openamp_remoteproc_shutdown(mp_obj_t self_in) { + openamp_remoteproc_obj_t *self = MP_OBJ_TO_PTR(self_in); + + // Shutdown the remoteproc and release its resources. + int error = remoteproc_shutdown(&self->rproc); + if (error != 0) { + mp_raise_OSError(error); + } + return mp_const_none; +} +static MP_DEFINE_CONST_FUN_OBJ_1(openamp_remoteproc_shutdown_obj, openamp_remoteproc_shutdown); + +mp_obj_t openamp_remoteproc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { + enum { ARG_entry }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_entry, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_rom_obj = MP_ROM_NONE } }, + }; + + // Parse args. + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + openamp_remoteproc_obj_t *self = mp_obj_malloc_with_finaliser(openamp_remoteproc_obj_t, &openamp_remoteproc_type); + + // Make sure OpenAMP is initialized. + if (MP_STATE_PORT(virtio_device) == NULL) { + openamp_init(); + } + + // Create a remoteproc instance. + // NOTE: ports should use rproc->priv to allocate the image store, + // which gets passed to remoteproc_load(), and all of the store ops. + remoteproc_init(&self->rproc, &openamp_remoteproc_ops, NULL); + + // Configure the remote before loading applications (optional). + int error = remoteproc_config(&self->rproc, NULL); + if (error != 0) { + mp_raise_OSError(error); + } + + if (mp_obj_is_int(args[ARG_entry].u_obj)) { + self->rproc.bootaddr = mp_obj_get_int(args[ARG_entry].u_obj); + } else { + #if MICROPY_PY_OPENAMP_REMOTEPROC_ELFLD_ENABLE + // Load firmware. + const char *path = mp_obj_str_get_str(args[ARG_entry].u_obj); + int error = remoteproc_load(&self->rproc, path, self->rproc.priv, &openamp_remoteproc_store_ops, NULL); + if (error != 0) { + mp_raise_OSError(error); + } + #else + mp_raise_TypeError(MP_ERROR_TEXT("loading firmware is not supported.")); + #endif + } + return MP_OBJ_FROM_PTR(self); +} + +static const mp_rom_map_elem_t openamp_remoteproc_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_RemoteProc) }, + { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&openamp_remoteproc_shutdown_obj) }, + { MP_ROM_QSTR(MP_QSTR_start), MP_ROM_PTR(&openamp_remoteproc_start_obj) }, + { MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&openamp_remoteproc_stop_obj) }, + { MP_ROM_QSTR(MP_QSTR_shutdown), MP_ROM_PTR(&openamp_remoteproc_shutdown_obj) }, +}; +static MP_DEFINE_CONST_DICT(openamp_remoteproc_dict, openamp_remoteproc_dict_table); + +MP_DEFINE_CONST_OBJ_TYPE( + openamp_remoteproc_type, + MP_QSTR_RemoteProc, + MP_TYPE_FLAG_NONE, + make_new, openamp_remoteproc_make_new, + locals_dict, &openamp_remoteproc_dict + ); + +#endif // MICROPY_PY_OPENAMP_REMOTEPROC diff --git a/extmod/modopenamp_remoteproc.h b/extmod/modopenamp_remoteproc.h new file mode 100644 index 0000000000000..9bc2b07064b4b --- /dev/null +++ b/extmod/modopenamp_remoteproc.h @@ -0,0 +1,46 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023-2024 Arduino SA + * + * 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. + * + * OpenAMP's remoteproc class. + */ +#ifndef MICROPY_INCLUDED_MODOPENAMP_REMOTEPROC_H +#define MICROPY_INCLUDED_MODOPENAMP_REMOTEPROC_H + +#include "openamp/remoteproc.h" +#include "openamp/remoteproc_loader.h" + +void *mp_openamp_remoteproc_store_alloc(void); +struct remoteproc *mp_openamp_remoteproc_init(struct remoteproc *rproc, + const struct remoteproc_ops *ops, void *arg); +void *mp_openamp_remoteproc_mmap(struct remoteproc *rproc, metal_phys_addr_t *pa, + metal_phys_addr_t *da, size_t size, unsigned int attribute, + struct metal_io_region **io); +int mp_openamp_remoteproc_start(struct remoteproc *rproc); +int mp_openamp_remoteproc_stop(struct remoteproc *rproc); +int mp_openamp_remoteproc_config(struct remoteproc *rproc, void *data); +void mp_openamp_remoteproc_remove(struct remoteproc *rproc); +int mp_openamp_remoteproc_shutdown(struct remoteproc *rproc); + +#endif // MICROPY_INCLUDED_MODOPENAMP_REMOTEPROC_H diff --git a/extmod/modopenamp_remoteproc_store.c b/extmod/modopenamp_remoteproc_store.c new file mode 100644 index 0000000000000..857c133469d6e --- /dev/null +++ b/extmod/modopenamp_remoteproc_store.c @@ -0,0 +1,146 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023-2024 Arduino SA + * + * 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. + * + * OpenAMP's remoteproc store. + */ + +#if MICROPY_PY_OPENAMP_REMOTEPROC + +#include "py/obj.h" +#include "py/nlr.h" +#include "py/runtime.h" +#include "py/stream.h" +#include "extmod/vfs.h" + +#include "metal/sys.h" +#include "metal/alloc.h" +#include "metal/errno.h" +#include "metal/io.h" + +#include "openamp/remoteproc.h" +#include "openamp/remoteproc_loader.h" + +#include "modopenamp.h" +#include "modopenamp_remoteproc.h" + +#if MICROPY_PY_OPENAMP_REMOTEPROC_STORE_ENABLE + +#define DEBUG_printf(...) // mp_printf(&mp_plat_print, __VA_ARGS__) + +// Note the initial file buffer size needs to be at least 512 to read +// enough of the elf headers on the first call to store_open(), and on +// subsequent calls to store functions, it gets reallocated if needed. +#define RPROC_FILE_STORE_BUF_SIZE (1024) + +typedef struct openamp_remoteproc_filestore { + size_t len; + uint8_t *buf; + mp_obj_t file; +} openamp_remoteproc_filestore_t; + +void *mp_openamp_remoteproc_store_alloc(void) { + // Allocate an rproc filestore. + openamp_remoteproc_filestore_t *fstore; + fstore = metal_allocate_memory(sizeof(openamp_remoteproc_filestore_t)); + fstore->len = RPROC_FILE_STORE_BUF_SIZE; + fstore->buf = metal_allocate_memory(RPROC_FILE_STORE_BUF_SIZE); + return fstore; +} + +static int openamp_remoteproc_store_open(void *store, const char *path, const void **image_data) { + DEBUG_printf("store_open(): %s\n", path); + mp_obj_t args[2] = { + mp_obj_new_str(path, strlen(path)), + MP_OBJ_NEW_QSTR(MP_QSTR_rb), + }; + + openamp_remoteproc_filestore_t *fstore = store; + fstore->file = mp_vfs_open(MP_ARRAY_SIZE(args), args, (mp_map_t *)&mp_const_empty_map); + + int error = 0; + mp_uint_t bytes = mp_stream_read_exactly(fstore->file, fstore->buf, RPROC_FILE_STORE_BUF_SIZE, &error); + if (error != 0 || bytes != RPROC_FILE_STORE_BUF_SIZE) { + return -EINVAL; + } + *image_data = fstore->buf; + return bytes; +} + +static void openamp_remoteproc_store_close(void *store) { + DEBUG_printf("store_close()\n"); + openamp_remoteproc_filestore_t *fstore = store; + mp_stream_close(fstore->file); + metal_free_memory(fstore->buf); + metal_free_memory(fstore); +} + +static int openamp_remoteproc_store_load(void *store, size_t offset, size_t size, + const void **data, metal_phys_addr_t pa, + struct metal_io_region *io, + char is_blocking) { + + int error = 0; + openamp_remoteproc_filestore_t *fstore = store; + + if (mp_stream_seek(fstore->file, offset, MP_SEEK_SET, &error) == -1) { + return -EINVAL; + } + + if (pa == METAL_BAD_PHYS) { + if (size > fstore->len) { + // Note tracked allocs don't support realloc. + fstore->len = size; + fstore->buf = metal_allocate_memory(size); + DEBUG_printf("store_load() realloc to %lu\n", fstore->len); + } + *data = fstore->buf; + DEBUG_printf("store_load(): pa 0x%lx offset %u size %u \n", (uint32_t)pa, offset, size); + } else { + void *va = metal_io_phys_to_virt(io, pa); + if (va == NULL) { + return -EINVAL; + } + *data = va; + DEBUG_printf("store_load(): pa 0x%lx va 0x%p offset %u size %u \n", (uint32_t)pa, va, offset, size); + } + + mp_uint_t bytes = mp_stream_read_exactly(fstore->file, (void *)*data, size, &error); + if (bytes != size || error != 0) { + return -EINVAL; + } + + return bytes; +} + +const struct image_store_ops openamp_remoteproc_store_ops = { + .open = openamp_remoteproc_store_open, + .close = openamp_remoteproc_store_close, + .load = openamp_remoteproc_store_load, + .features = SUPPORT_SEEK, +}; + +#endif // MICROPY_PY_OPENAMP_REMOTEPROC_STORE_ENABLE + +#endif // MICROPY_PY_OPENAMP_REMOTEPROC From 13297d8c3a3cedbf5fd0d2817077270b284fe401 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Mon, 13 Nov 2023 17:24:41 +0100 Subject: [PATCH 226/408] stm32: Implement port backend for libmetal. Signed-off-by: iabdalkader --- ports/stm32/Makefile | 7 +++ ports/stm32/irq.h | 2 + ports/stm32/mpmetalport.c | 107 ++++++++++++++++++++++++++++++++++++++ ports/stm32/mpmetalport.h | 76 +++++++++++++++++++++++++++ 4 files changed, 192 insertions(+) create mode 100644 ports/stm32/mpmetalport.c create mode 100644 ports/stm32/mpmetalport.h diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile index d1694426d3529..75609031966d5 100644 --- a/ports/stm32/Makefile +++ b/ports/stm32/Makefile @@ -422,6 +422,13 @@ endif endif # MICROPY_PY_BLUETOOTH +# Add stm32-specific implementation of libmetal (and optionally OpenAMP's rproc). +# Note: libmetal code is generated via a pre-processor so ensure that runs first. +ifeq ($(MICROPY_PY_OPENAMP),1) +SRC_C += mpmetalport.c +$(BUILD)/mpmetalport.o: $(BUILD)/openamp/metal/config.h +endif + # SRC_O should be placed first to work around this LTO bug with binutils <2.35: # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83967 OBJ += $(addprefix $(BUILD)/, $(SRC_O)) diff --git a/ports/stm32/irq.h b/ports/stm32/irq.h index e3a204ec96a32..58e6d0a804854 100644 --- a/ports/stm32/irq.h +++ b/ports/stm32/irq.h @@ -174,6 +174,8 @@ static inline void restore_irq_pri(uint32_t state) { #define IRQ_PRI_SPI NVIC_EncodePriority(NVIC_PRIORITYGROUP_4, 8, 0) +#define IRQ_PRI_HSEM NVIC_EncodePriority(NVIC_PRIORITYGROUP_4, 10, 0) + // Interrupt priority for non-special timers. #define IRQ_PRI_TIMX NVIC_EncodePriority(NVIC_PRIORITYGROUP_4, 13, 0) diff --git a/ports/stm32/mpmetalport.c b/ports/stm32/mpmetalport.c new file mode 100644 index 0000000000000..72f5537ce5746 --- /dev/null +++ b/ports/stm32/mpmetalport.c @@ -0,0 +1,107 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023 Arduino SA + * + * 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. + * + * libmetal stm32 port. + */ + +#include "py/mperrno.h" +#include "py/mphal.h" + +#include "mpu.h" + +#include "metal/sys.h" +#include "metal/utilities.h" +#include "metal/device.h" + +struct metal_state _metal; +static mp_sched_node_t rproc_notify_node; + +int metal_sys_init(const struct metal_init_params *params) { + metal_unused(params); + + // Clear HSEM pending IRQ. + HSEM_COMMON->ICR |= (uint32_t)__HAL_HSEM_SEMID_TO_MASK(METAL_HSEM_MASTER_ID); + HAL_NVIC_ClearPendingIRQ(HSEM1_IRQn); + + // Enable and configure HSEM. + __HAL_RCC_HSEM_CLK_ENABLE(); + NVIC_SetPriority(HSEM1_IRQn, IRQ_PRI_HSEM); + HAL_NVIC_EnableIRQ(HSEM1_IRQn); + HAL_HSEM_ActivateNotification(__HAL_HSEM_SEMID_TO_MASK(METAL_HSEM_MASTER_ID)); + + #ifndef VIRTIO_USE_DCACHE + // If cache management is not enabled, configure the MPU to disable caching + // for the entire shared memory region. + uint32_t irq_state = mpu_config_start(); + mpu_config_region(MPU_REGION_OPENAMP, METAL_MPU_REGION_BASE, MPU_CONFIG_SHARED_UNCACHED(METAL_MPU_REGION_SIZE)); + mpu_config_end(irq_state); + #endif + + metal_bus_register(&metal_generic_bus); + return 0; +} + +void metal_sys_finish(void) { + HAL_NVIC_DisableIRQ(HSEM1_IRQn); + HAL_HSEM_DeactivateNotification(__HAL_HSEM_SEMID_TO_MASK(METAL_HSEM_MASTER_ID)); + __HAL_RCC_HSEM_CLK_DISABLE(); + metal_bus_unregister(&metal_generic_bus); +} + +unsigned int sys_irq_save_disable(void) { + return disable_irq(); +} + +void sys_irq_restore_enable(unsigned int state) { + enable_irq(state); +} + +void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa, + size_t size, unsigned int flags) { + metal_unused(pa); + metal_unused(size); + metal_unused(flags); + return va; +} + +void metal_machine_cache_flush(void *addr, unsigned int len) { + SCB_CleanDCache_by_Addr(addr, len); +} + +void metal_machine_cache_invalidate(void *addr, unsigned int len) { + SCB_InvalidateDCache_by_Addr(addr, len); +} + +int metal_rproc_notify(void *priv, uint32_t id) { + HAL_HSEM_FastTake(METAL_HSEM_REMOTE_ID); + HAL_HSEM_Release(METAL_HSEM_REMOTE_ID, 0); + return 0; +} + +void HSEM1_IRQHandler(void) { + HAL_HSEM_IRQHandler(); + mp_sched_schedule_node(&rproc_notify_node, openamp_remoteproc_notified); + HAL_HSEM_ActivateNotification(__HAL_HSEM_SEMID_TO_MASK(METAL_HSEM_MASTER_ID)); +} diff --git a/ports/stm32/mpmetalport.h b/ports/stm32/mpmetalport.h new file mode 100644 index 0000000000000..53f329d15b093 --- /dev/null +++ b/ports/stm32/mpmetalport.h @@ -0,0 +1,76 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023 Arduino SA + * + * 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. + * + * libmetal stm32 port. + */ +#ifndef MICROPY_INCLUDED_STM32_MPMETALPORT_H +#define MICROPY_INCLUDED_STM32_MPMETALPORT_H + +#include +#include "py/mphal.h" +#include "py/runtime.h" + +#define METAL_HAVE_STDATOMIC_H 0 +#define METAL_HAVE_FUTEX_H 0 + +#define METAL_MAX_DEVICE_REGIONS 2 + +#define METAL_HSEM_REMOTE_ID 0 +#define METAL_HSEM_MASTER_ID 1 + +// Set to 1 to enable log output. +#define METAL_LOG_HANDLER_ENABLE 0 + +#define metal_cpu_yield() + +// Shared memory config +#define METAL_SHM_NAME "OPENAMP_SHM" +// Note 1K must be reserved at the start of the openamp +// shared memory region, for the shared resource table. +#define METAL_RSC_ADDR ((void *)_openamp_shm_region_start) +#define METAL_RSC_SIZE (1024) + +#define METAL_SHM_ADDR ((metal_phys_addr_t)(_openamp_shm_region_start + METAL_RSC_SIZE)) +#define METAL_SHM_SIZE ((size_t)(_openamp_shm_region_end - _openamp_shm_region_start - METAL_RSC_SIZE)) + +#define METAL_MPU_REGION_BASE ((uint32_t)_openamp_shm_region_start) +#define METAL_MPU_REGION_SIZE (MPU_REGION_SIZE_64KB) + +extern const char _openamp_shm_region_start[]; +extern const char _openamp_shm_region_end[]; + +int metal_rproc_notify(void *priv, uint32_t id); +extern void openamp_remoteproc_notified(mp_sched_node_t *node); + +static inline int __metal_sleep_usec(unsigned int usec) { + mp_hal_delay_us(usec); + return 0; +} + +static inline void metal_generic_default_poll(void) { + MICROPY_EVENT_POLL_HOOK +} + +#endif // MICROPY_INCLUDED_STM32_METAL_PORT_H From 09eb4caccb34b16647a650ddd396bcdd318613dc Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Mon, 13 Nov 2023 17:25:11 +0100 Subject: [PATCH 227/408] stm32: Implement port backend for OpenAMP's remoteproc. Signed-off-by: iabdalkader --- ports/stm32/Makefile | 4 + ports/stm32/mpremoteprocport.c | 153 +++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 ports/stm32/mpremoteprocport.c diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile index 75609031966d5..50ac48e5a18eb 100644 --- a/ports/stm32/Makefile +++ b/ports/stm32/Makefile @@ -427,6 +427,10 @@ endif # MICROPY_PY_BLUETOOTH ifeq ($(MICROPY_PY_OPENAMP),1) SRC_C += mpmetalport.c $(BUILD)/mpmetalport.o: $(BUILD)/openamp/metal/config.h +ifeq ($(MICROPY_PY_OPENAMP_REMOTEPROC),1) +SRC_C += mpremoteprocport.c +$(BUILD)/mpremoteprocport.o: $(BUILD)/openamp/metal/config.h +endif endif # SRC_O should be placed first to work around this LTO bug with binutils <2.35: diff --git a/ports/stm32/mpremoteprocport.c b/ports/stm32/mpremoteprocport.c new file mode 100644 index 0000000000000..56dff43da4e73 --- /dev/null +++ b/ports/stm32/mpremoteprocport.c @@ -0,0 +1,153 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023-2024 Arduino SA + * + * 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. + * + * modremoteproc stm32 port. + */ + +#include +#include + +#include "py/obj.h" +#include "py/runtime.h" + +#include "metal/alloc.h" +#include "metal/errno.h" +#include "metal/io.h" +#include "metal/sys.h" +#include "metal/device.h" +#include "metal/utilities.h" +#include "extmod/modopenamp_remoteproc.h" + +#define DEBUG_printf(...) // mp_printf(&mp_plat_print, __VA_ARGS__) + +struct remoteproc *mp_openamp_remoteproc_init(struct remoteproc *rproc, + const struct remoteproc_ops *ops, void *arg) { + DEBUG_printf("rproc_init()\n"); + + rproc->ops = ops; + rproc->state = RPROC_OFFLINE; + // Allocate the image store and save it in private data. + rproc->priv = mp_openamp_remoteproc_store_alloc(); + return rproc; +} + +void *mp_openamp_remoteproc_mmap(struct remoteproc *rproc, metal_phys_addr_t *pa, + metal_phys_addr_t *da, size_t size, unsigned int attribute, + struct metal_io_region **io) { + DEBUG_printf("rproc_mmap(): pa 0x%p da 0x%p io 0x%p size %u\n", *pa, *da, *io, size); + + struct remoteproc_mem *mem; + metal_phys_addr_t lpa = *pa; + metal_phys_addr_t lda = *da; + + if (lda == METAL_BAD_PHYS) { + return NULL; + } + + if (lpa == METAL_BAD_PHYS) { + lpa = lda; + } + + // Currently this port doesn't support loading firmware to flash, + // only SD/SRAM images are supported. Check of load address is in + // the flash region, and if so return NULL. + if (lda >= FLASH_BASE && lda < FLASH_END) { + return NULL; + } + + mem = metal_allocate_memory(sizeof(*mem)); + if (!mem) { + return NULL; + } + + *io = metal_allocate_memory(sizeof(struct metal_io_region)); + if (!*io) { + metal_free_memory(mem); + return NULL; + } + + remoteproc_init_mem(mem, NULL, lpa, lda, size, *io); + + metal_io_init(*io, (void *)mem->da, &mem->pa, size, + sizeof(metal_phys_addr_t) << 3, attribute, NULL); + + remoteproc_add_mem(rproc, mem); + *pa = lpa; + *da = lda; + return metal_io_phys_to_virt(*io, mem->pa); +} + +int mp_openamp_remoteproc_start(struct remoteproc *rproc) { + DEBUG_printf("rproc_start()\n"); + if ((RCC->GCR & RCC_GCR_BOOT_C2) || (FLASH->OPTSR_CUR & FLASH_OPTSR_BCM4)) { + // The CM4 core has already been started manually, or auto-boot is enabled + // via the option bytes, in either case the core can't be restarted. + DEBUG_printf("rproc_start(): CM4 core is already booted.\n"); + return -1; + } + + // Flush M7 cache. + struct metal_list *node; + metal_list_for_each(&rproc->mems, node) { + struct remoteproc_mem *mem; + mem = metal_container_of(node, struct remoteproc_mem, node); + SCB_CleanDCache_by_Addr((uint32_t *)mem->pa, mem->size); + } + + HAL_SYSCFG_CM4BootAddConfig(SYSCFG_BOOT_ADDR0, (uint32_t)rproc->bootaddr); + HAL_RCCEx_EnableBootCore(RCC_BOOT_C2); + return 0; +} + +int mp_openamp_remoteproc_stop(struct remoteproc *rproc) { + DEBUG_printf("rproc_stop()\n"); + if (rproc->state == RPROC_RUNNING) { + // There's no straightforward way to reset or shut down + // the remote processor, so a full system reset is needed. + NVIC_SystemReset(); + } + return 0; +} + +int mp_openamp_remoteproc_config(struct remoteproc *rproc, void *data) { + DEBUG_printf("rproc_config()\n"); + (void)rproc; + return 0; +} + +void mp_openamp_remoteproc_remove(struct remoteproc *rproc) { + DEBUG_printf("rproc_remove()\n"); + (void)rproc; +} + +int mp_openamp_remoteproc_shutdown(struct remoteproc *rproc) { + DEBUG_printf("rproc_shutdown()\n"); + if (rproc->state == RPROC_RUNNING) { + // There's no straightforward way to reset or shut down + // the remote processor, so a full system reset is needed. + NVIC_SystemReset(); + } + return 0; +} From c859978da31bde0a43848490a4da339cdea22c2f Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Mon, 20 Nov 2023 10:03:22 +0100 Subject: [PATCH 228/408] stm32/boards/ARDUINO_GIGA: Enable OpenAMP. Signed-off-by: iabdalkader --- ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.mk | 2 ++ ports/stm32/boards/ARDUINO_GIGA/stm32h747.ld | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.mk b/ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.mk index b927388c5577a..46fe40c2a6a82 100644 --- a/ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.mk +++ b/ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.mk @@ -23,6 +23,8 @@ MICROPY_PY_LWIP = 1 MICROPY_PY_NETWORK_CYW43 = 1 MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 +MICROPY_PY_OPENAMP = 1 +MICROPY_PY_OPENAMP_REMOTEPROC = 1 FROZEN_MANIFEST = $(BOARD_DIR)/manifest.py MBEDTLS_CONFIG_FILE = '"$(BOARD_DIR)/mbedtls_config_board.h"' diff --git a/ports/stm32/boards/ARDUINO_GIGA/stm32h747.ld b/ports/stm32/boards/ARDUINO_GIGA/stm32h747.ld index d5bd9598f9820..793a76b970292 100644 --- a/ports/stm32/boards/ARDUINO_GIGA/stm32h747.ld +++ b/ports/stm32/boards/ARDUINO_GIGA/stm32h747.ld @@ -14,10 +14,10 @@ MEMORY SRAM4 (xrw) : ORIGIN = 0x38000000, LENGTH = 64K /* SRAM4 D3 */ FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2048K /* Total available flash */ FLASH_EXT (rx) : ORIGIN = 0x90000000, LENGTH = 16384K /* 16MBs external QSPI flash */ - FLASH_FS (r) : ORIGIN = 0x08020000, LENGTH = 128K /* sector 1 -> Flash storage */ - FLASH_TEXT (rx) : ORIGIN = 0x08040000, LENGTH = 1792K /* Sector 0 -> Arduino Bootloader - Sector 1 -> Reserved for CM4/FS - Sectors 2 -> 15 firmware */ + FLASH_BL (rx) : ORIGIN = 0x08000000, LENGTH = 128K /* Arduino bootloader */ + FLASH_FS (r) : ORIGIN = 0x08020000, LENGTH = 128K /* filesystem */ + FLASH_TEXT (rx) : ORIGIN = 0x08040000, LENGTH = 1280K /* CM7 firmware */ + FLASH_CM4 (rx) : ORIGIN = 0x08180000, LENGTH = 512K /* CM4 firmware */ } /* produce a link error if there is not this amount of RAM for these sections */ @@ -44,4 +44,8 @@ _micropy_hw_internal_flash_storage_ram_cache_end = ORIGIN(DTCM) + LENGTH(DTCM); _micropy_hw_internal_flash_storage_start = ORIGIN(FLASH_FS); _micropy_hw_internal_flash_storage_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS); +/* OpenAMP shared memory region */ +_openamp_shm_region_start = ORIGIN(SRAM4); +_openamp_shm_region_end = ORIGIN(SRAM4) + LENGTH(SRAM4); + INCLUDE common_blifs.ld From fc9734363919c1ecba1f9ae58f8c093e47e55d56 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Mon, 11 Mar 2024 09:31:11 +0100 Subject: [PATCH 229/408] stm32/boards/ARDUINO_NICLA_VISION: Enable OpenAMP. Signed-off-by: iabdalkader --- .../boards/ARDUINO_NICLA_VISION/mpconfigboard.mk | 2 ++ ports/stm32/boards/ARDUINO_NICLA_VISION/stm32h747.ld | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ports/stm32/boards/ARDUINO_NICLA_VISION/mpconfigboard.mk b/ports/stm32/boards/ARDUINO_NICLA_VISION/mpconfigboard.mk index 2c48c17f3805e..77d547bce05e9 100644 --- a/ports/stm32/boards/ARDUINO_NICLA_VISION/mpconfigboard.mk +++ b/ports/stm32/boards/ARDUINO_NICLA_VISION/mpconfigboard.mk @@ -23,6 +23,8 @@ MICROPY_PY_LWIP = 1 MICROPY_PY_NETWORK_CYW43 = 1 MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 +MICROPY_PY_OPENAMP = 1 +MICROPY_PY_OPENAMP_REMOTEPROC = 1 FROZEN_MANIFEST = $(BOARD_DIR)/manifest.py MBEDTLS_CONFIG_FILE = '"$(BOARD_DIR)/mbedtls_config_board.h"' diff --git a/ports/stm32/boards/ARDUINO_NICLA_VISION/stm32h747.ld b/ports/stm32/boards/ARDUINO_NICLA_VISION/stm32h747.ld index fcbfc94d46204..6d6ce279f299c 100644 --- a/ports/stm32/boards/ARDUINO_NICLA_VISION/stm32h747.ld +++ b/ports/stm32/boards/ARDUINO_NICLA_VISION/stm32h747.ld @@ -14,10 +14,10 @@ MEMORY SRAM4 (xrw) : ORIGIN = 0x38000000, LENGTH = 64K /* SRAM4 D3 */ FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2048K /* Total available flash */ FLASH_EXT (rx) : ORIGIN = 0x90000000, LENGTH = 16384K /* 16MBs external QSPI flash */ - FLASH_FS (r) : ORIGIN = 0x08020000, LENGTH = 128K /* sector 1 -> Flash storage */ - FLASH_TEXT (rx) : ORIGIN = 0x08040000, LENGTH = 1792K /* Sector 0 -> Arduino Bootloader - Sector 1 -> Reserved for CM4/FS - Sectors 2 -> 15 firmware */ + FLASH_BL (rx) : ORIGIN = 0x08000000, LENGTH = 128K /* Arduino bootloader */ + FLASH_FS (r) : ORIGIN = 0x08020000, LENGTH = 128K /* filesystem */ + FLASH_TEXT (rx) : ORIGIN = 0x08040000, LENGTH = 1280K /* CM7 firmware */ + FLASH_CM4 (rx) : ORIGIN = 0x08180000, LENGTH = 512K /* CM4 firmware */ } _cm4_ram_start = ORIGIN(SRAM4); @@ -46,4 +46,8 @@ _micropy_hw_internal_flash_storage_ram_cache_end = ORIGIN(DTCM) + LENGTH(DTCM); _micropy_hw_internal_flash_storage_start = ORIGIN(FLASH_FS); _micropy_hw_internal_flash_storage_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS); +/* OpenAMP shared memory region */ +_openamp_shm_region_start = ORIGIN(SRAM4); +_openamp_shm_region_end = ORIGIN(SRAM4) + LENGTH(SRAM4); + INCLUDE common_blifs.ld From 864e4596bf1c99112019b3d0d169f140ea9f2284 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Mon, 11 Mar 2024 09:32:10 +0100 Subject: [PATCH 230/408] stm32/boards/ARDUINO_PORTENTA_H7: Enable OpenAMP. Signed-off-by: iabdalkader --- .../boards/ARDUINO_PORTENTA_H7/mpconfigboard.mk | 2 ++ ports/stm32/boards/ARDUINO_PORTENTA_H7/stm32h747.ld | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.mk b/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.mk index cf4d40e5fe9b9..c56c8f005f72b 100644 --- a/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.mk +++ b/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.mk @@ -23,6 +23,8 @@ MICROPY_PY_LWIP = 1 MICROPY_PY_NETWORK_CYW43 = 1 MICROPY_PY_SSL = 1 MICROPY_SSL_MBEDTLS = 1 +MICROPY_PY_OPENAMP = 1 +MICROPY_PY_OPENAMP_REMOTEPROC = 1 FROZEN_MANIFEST = $(BOARD_DIR)/manifest.py MBEDTLS_CONFIG_FILE = '"$(BOARD_DIR)/mbedtls_config_board.h"' diff --git a/ports/stm32/boards/ARDUINO_PORTENTA_H7/stm32h747.ld b/ports/stm32/boards/ARDUINO_PORTENTA_H7/stm32h747.ld index d5bd9598f9820..793a76b970292 100644 --- a/ports/stm32/boards/ARDUINO_PORTENTA_H7/stm32h747.ld +++ b/ports/stm32/boards/ARDUINO_PORTENTA_H7/stm32h747.ld @@ -14,10 +14,10 @@ MEMORY SRAM4 (xrw) : ORIGIN = 0x38000000, LENGTH = 64K /* SRAM4 D3 */ FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2048K /* Total available flash */ FLASH_EXT (rx) : ORIGIN = 0x90000000, LENGTH = 16384K /* 16MBs external QSPI flash */ - FLASH_FS (r) : ORIGIN = 0x08020000, LENGTH = 128K /* sector 1 -> Flash storage */ - FLASH_TEXT (rx) : ORIGIN = 0x08040000, LENGTH = 1792K /* Sector 0 -> Arduino Bootloader - Sector 1 -> Reserved for CM4/FS - Sectors 2 -> 15 firmware */ + FLASH_BL (rx) : ORIGIN = 0x08000000, LENGTH = 128K /* Arduino bootloader */ + FLASH_FS (r) : ORIGIN = 0x08020000, LENGTH = 128K /* filesystem */ + FLASH_TEXT (rx) : ORIGIN = 0x08040000, LENGTH = 1280K /* CM7 firmware */ + FLASH_CM4 (rx) : ORIGIN = 0x08180000, LENGTH = 512K /* CM4 firmware */ } /* produce a link error if there is not this amount of RAM for these sections */ @@ -44,4 +44,8 @@ _micropy_hw_internal_flash_storage_ram_cache_end = ORIGIN(DTCM) + LENGTH(DTCM); _micropy_hw_internal_flash_storage_start = ORIGIN(FLASH_FS); _micropy_hw_internal_flash_storage_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS); +/* OpenAMP shared memory region */ +_openamp_shm_region_start = ORIGIN(SRAM4); +_openamp_shm_region_end = ORIGIN(SRAM4) + LENGTH(SRAM4); + INCLUDE common_blifs.ld From e5ca06a06fbb36b82dc50c118735cc1c10506080 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Thu, 29 Feb 2024 12:31:24 +0100 Subject: [PATCH 231/408] docs/library/openamp: Document the new openamp module. Signed-off-by: iabdalkader --- docs/library/index.rst | 1 + docs/library/openamp.rst | 115 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 docs/library/openamp.rst diff --git a/docs/library/index.rst b/docs/library/index.rst index eb29b7680542e..4209a0781a60e 100644 --- a/docs/library/index.rst +++ b/docs/library/index.rst @@ -103,6 +103,7 @@ the following libraries. micropython.rst neopixel.rst network.rst + openamp.rst uctypes.rst vfs.rst diff --git a/docs/library/openamp.rst b/docs/library/openamp.rst new file mode 100644 index 0000000000000..de4d51ad06b5e --- /dev/null +++ b/docs/library/openamp.rst @@ -0,0 +1,115 @@ +:mod:`openamp` -- provides standard Asymmetric Multiprocessing (AMP) support +============================================================================ + +.. module:: openamp + :synopsis: provides standard Asymmetric Multiprocessing (AMP) support + +The ``openamp`` module provides a standard inter-processor communications infrastructure +for MicroPython. The module handles all of the details of OpenAMP, such as setting up +the shared resource table, initializing vrings, etc. It provides an API for using the +RPMsg bus infrastructure with the `Endpoint` class, and provides processor Life Cycle +Management (LCM) support, such as loading firmware and starting and stopping a remote +core, via the `RemoteProc` class. + +Example usage:: + + import openamp + + def ept_recv_callback(src, data): + print("Received message on endpoint", data) + + # Create a new RPMsg endpoint to communicate with the remote core. + ept = openamp.Endpoint("vuart-channel", callback=ept_recv_callback) + + # Create a RemoteProc object, load its firmware and start it. + rproc = openamp.RemoteProc("virtual_uart.elf") # Or entry point address (ex 0x081E0000) + rproc.start() + + while True: + if ept.is_ready(): + ept.send("data") + +Functions +--------- + +.. function:: new_service_callback(ns_callback) + + Set the new service callback. + + The *ns_callback* argument is a function that will be called when the remote processor + announces new services. At that point the host processor can choose to create the + announced endpoint, if this particular service is supported, or ignore it if it's + not. If this function is not set, the host processor should first register the + endpoint locally, and it will be automatically bound when the remote announces + the service. + +Endpoint class +-------------- + +.. class:: Endpoint(name, callback, src=ENDPOINT_ADDR_ANY, dest=ENDPOINT_ADDR_ANY) + + Construct a new RPMsg Endpoint. An endpoint is a bidirectional communication + channel between two cores. + + Arguments are: + + - *name* is the name of the endpoint. + - *callback* is a function that is called when the endpoint receives data with the + source address of the remote point, and the data as bytes passed by reference. + - *src* is the endpoint source address. If none is provided one will be assigned + to the endpoint by the library. + - *dest* is the endpoint destination address. If the endpoint is created from the + new_service_callback, this must be provided and it must match the remote endpoint's + source address. If the endpoint is registered locally, before the announcement, the + destination address will be assigned by the library when the endpoint is bound. + +.. method:: Endpoint.deinit() + + Destroy the endpoint and release all of its resources. + +.. method:: Endpoint.is_ready() + + Returns True if the endpoint is ready to send (i.e., has both a source and destination addresses) + +.. method:: Endpoint.send(src=-1, dest=-1, timeout=-1) + + Send a message to the remote processor over this endpoint. + + Arguments are: + + - *src* is the source endpoint address of the message. If none is provided, the + source address the endpoint is bound to is used. + - *dest* is the destination endpoint address of the message. If none is provided, + the destination address the endpoint is bound to is used. + - *timeout* specifies the time in milliseconds to wait for a free buffer. By default + the function is blocking. + +RemoteProc class +---------------- + +.. class:: RemoteProc(entry) + + The RemoteProc object provides processor Life Cycle Management (LCM) support, such as + loading firmware, starting and stopping a remote core. + + The *entry* argument can be a path to firmware image, in which case the firmware is + loaded from file to its target memory, or an entry point address, in which case the + firmware must be loaded already at the given address. + +.. method:: RemoteProc.start() + + Starts the remote processor. + +.. method:: RemoteProc.stop() + + Stops the remote processor. The exact behavior is platform-dependent. On the STM32H7 for + example it's not possible to stop and then restart the Cortex-M4 core, so a complete + system reset is performed on a call to this function. + +.. method:: RemoteProc.shutdown() + + Shutdown stops the remote processor and releases all of its resources. The exact behavior + is platform-dependent, however typically it disables power and clocks to the remote core. + This function is also used as the finaliser (i.e., called when ``RemoteProc`` object is + collected). Note that on the STM32H7, it's not possible to stop and then restart the + Cortex-M4 core, so a complete system reset is performed on a call to this function. From 486ca3a688542f9f535522c29342e2dafe805d5a Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Thu, 14 Mar 2024 08:41:52 +0100 Subject: [PATCH 232/408] tools/ci.sh: Add Arduino GIGA to stm32 CI build. Signed-off-by: iabdalkader --- .github/workflows/ports_stm32.yml | 1 + tools/ci.sh | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/.github/workflows/ports_stm32.yml b/.github/workflows/ports_stm32.yml index 84d30b27f6e66..f5e01dc1f620e 100644 --- a/.github/workflows/ports_stm32.yml +++ b/.github/workflows/ports_stm32.yml @@ -25,6 +25,7 @@ jobs: ci_func: # names are functions in ci.sh - stm32_pyb_build - stm32_nucleo_build + - stm32_misc_build runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v4 diff --git a/tools/ci.sh b/tools/ci.sh index 3cbc51cfad625..f94f23893b710 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -366,6 +366,12 @@ function ci_stm32_nucleo_build { diff $BUILD_WB55/firmware.unpack.dfu $BUILD_WB55/firmware.unpack_no_sk.dfu } +function ci_stm32_misc_build { + make ${MAKEOPTS} -C mpy-cross + make ${MAKEOPTS} -C ports/stm32 BOARD=ARDUINO_GIGA submodules + make ${MAKEOPTS} -C ports/stm32 BOARD=ARDUINO_GIGA +} + ######################################################################################## # ports/unix From df2ff0c3553f67c3e8fe29f41013f27a75b608af Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 15 Mar 2024 17:51:47 +1100 Subject: [PATCH 233/408] LICENSE: Add libmetal and open-amp to 3rd-party license list. Signed-off-by: Damien George --- LICENSE | 2 ++ 1 file changed, 2 insertions(+) diff --git a/LICENSE b/LICENSE index b85f31808a483..9142c46045846 100644 --- a/LICENSE +++ b/LICENSE @@ -48,12 +48,14 @@ used during the build process and is not part of the compiled source code. /cmsis (BSD-3-clause) /crypto-algorithms (NONE) /libhydrogen (ISC) + /libmetal (BSD-3-clause) /littlefs (BSD-3-clause) /lwip (BSD-3-clause) /mynewt-nimble (Apache-2.0) /nrfx (BSD-3-clause) /nxp_driver (BSD-3-Clause) /oofatfs (BSD-1-clause) + /open-amp (BSD-3-clause) /pico-sdk (BSD-3-clause) /re15 (BSD-3-clause) /stm32lib (BSD-3-clause) From fb3820e3d62d284472420c68828a6b6443265b61 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 16 Mar 2024 00:40:39 +1100 Subject: [PATCH 234/408] nrf/boards: Enable MICROPY_HW_ENABLE_USBDEV on boards with USB CDC. These boards were broken by 9d0d262be069089f01da6b40d2cd78f1da14de0f. Signed-off-by: Damien George --- ports/nrf/boards/NRF52840_MDK_USB_DONGLE/mpconfigboard.h | 1 + ports/nrf/boards/PARTICLE_XENON/mpconfigboard.h | 1 + ports/nrf/boards/PCA10059/mpconfigboard.h | 1 + 3 files changed, 3 insertions(+) diff --git a/ports/nrf/boards/NRF52840_MDK_USB_DONGLE/mpconfigboard.h b/ports/nrf/boards/NRF52840_MDK_USB_DONGLE/mpconfigboard.h index 94624be028a17..499abbc4efc3c 100644 --- a/ports/nrf/boards/NRF52840_MDK_USB_DONGLE/mpconfigboard.h +++ b/ports/nrf/boards/NRF52840_MDK_USB_DONGLE/mpconfigboard.h @@ -37,6 +37,7 @@ #define MICROPY_HW_ENABLE_RNG (1) +#define MICROPY_HW_ENABLE_USBDEV (1) #define MICROPY_HW_USB_CDC (1) #define MICROPY_HW_HAS_LED (1) diff --git a/ports/nrf/boards/PARTICLE_XENON/mpconfigboard.h b/ports/nrf/boards/PARTICLE_XENON/mpconfigboard.h index 343fa4c2f3944..35b70d61290ff 100644 --- a/ports/nrf/boards/PARTICLE_XENON/mpconfigboard.h +++ b/ports/nrf/boards/PARTICLE_XENON/mpconfigboard.h @@ -37,6 +37,7 @@ #define MICROPY_HW_ENABLE_RNG (1) +#define MICROPY_HW_ENABLE_USBDEV (1) #define MICROPY_HW_USB_CDC (1) #define MICROPY_HW_HAS_LED (1) diff --git a/ports/nrf/boards/PCA10059/mpconfigboard.h b/ports/nrf/boards/PCA10059/mpconfigboard.h index 1c87731584de7..97f6ccb9410f0 100644 --- a/ports/nrf/boards/PCA10059/mpconfigboard.h +++ b/ports/nrf/boards/PCA10059/mpconfigboard.h @@ -37,6 +37,7 @@ #define MICROPY_HW_ENABLE_RNG (1) +#define MICROPY_HW_ENABLE_USBDEV (1) #define MICROPY_HW_USB_CDC (1) #define MICROPY_HW_HAS_LED (1) From 01c31ea804c7e2a034e1249b43c30673b4382116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20D=C3=B6rre?= Date: Sat, 24 Feb 2024 23:44:47 +0000 Subject: [PATCH 235/408] extmod/os_dupterm: Handle exception properly when it occurs in parallel. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When an exception is handled and the stream is closed, but while this happens, another exception occurs or dupterm is deactivated for another reason, the initial deactivation crashes, because its dupterm is removed. Co-authored-by: Damien George Signed-off-by: Felix Dörre --- extmod/os_dupterm.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/extmod/os_dupterm.c b/extmod/os_dupterm.c index 156766a43c508..399f2237fbb2f 100644 --- a/extmod/os_dupterm.c +++ b/extmod/os_dupterm.c @@ -45,6 +45,10 @@ void mp_os_deactivate(size_t dupterm_idx, const char *msg, mp_obj_t exc) { if (exc != MP_OBJ_NULL) { mp_obj_print_exception(&mp_plat_print, exc); } + if (term == MP_OBJ_NULL) { + // Dupterm was already closed. + return; + } nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { mp_stream_close(term); From 305707b281bc64aacb154e0165bd0a9ca3fedfe8 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 15 Mar 2024 18:39:23 +1100 Subject: [PATCH 236/408] lib/berkeley-db-1.xx: Update submodule URL and version. This updates the berkeley-db-1.xx submodule URL to a repository hosted under the micropython organisation, and makes the following changes: - Moves the berkeley-db header files to a single directory within the submodule, and references all these headers with a much fuller path, which prevents symbol clashes (eg with esp32 and queue.h). - Removes unused/non-working files from berkeley-db, which removes all symlinks in that repo (symlinks don't play well under Windows). - Allows injecting an external configuration header into berkeley-db, so the configuration doesn't have to be provided by -Dxx=yy flags to the compiler (and possibly clashing with other symbols). - Removes the advertising clause from the BSD 4-clause license of berkeley-db (see relevant commit and README.Impt.License.Change for details). Signed-off-by: Damien George --- .gitmodules | 2 +- lib/berkeley-db-1.xx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index aa9bb3d6d94cd..423d1bbeed8fb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -9,7 +9,7 @@ url = https://github.com/lwip-tcpip/lwip.git [submodule "lib/berkeley-db-1.xx"] path = lib/berkeley-db-1.xx - url = https://github.com/pfalcon/berkeley-db-1.xx + url = https://github.com/micropython/berkeley-db-1.xx [submodule "lib/stm32lib"] path = lib/stm32lib url = https://github.com/micropython/stm32lib diff --git a/lib/berkeley-db-1.xx b/lib/berkeley-db-1.xx index 35aaec4418ad7..85373b548f1fb 160000 --- a/lib/berkeley-db-1.xx +++ b/lib/berkeley-db-1.xx @@ -1 +1 @@ -Subproject commit 35aaec4418ad78628a3b935885dd189d41ce779b +Subproject commit 85373b548f1fb0119a463582570b44189dfb09ae From cd8eea2ae99542257a33b29c9dfdc02b63fc1bd6 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 8 Mar 2024 22:43:52 +1100 Subject: [PATCH 237/408] all: Update extmod, ports, examples to build with new berkeley-db lib. This provides a MicroPython-specific berkeley-db configuration in extmod/berkeley-db/berkeley_db_config_port.h, and cleans up the include path for this library. Fixes issue #13092. Signed-off-by: Damien George --- examples/natmod/btree/Makefile | 7 ++++--- examples/natmod/btree/btree_c.c | 4 ++++ extmod/berkeley-db/berkeley_db_config_port.h | 16 ++++++++++++++++ extmod/extmod.cmake | 16 ++++++++-------- extmod/extmod.mk | 10 +++++----- extmod/modbtree.c | 4 ++-- ports/esp8266/Makefile | 2 +- 7 files changed, 40 insertions(+), 19 deletions(-) create mode 100644 extmod/berkeley-db/berkeley_db_config_port.h diff --git a/examples/natmod/btree/Makefile b/examples/natmod/btree/Makefile index d795102b4aad8..218ec15a2a009 100644 --- a/examples/natmod/btree/Makefile +++ b/examples/natmod/btree/Makefile @@ -11,9 +11,10 @@ SRC = btree_c.c btree_py.py ARCH = x64 BTREE_DIR = $(MPY_DIR)/lib/berkeley-db-1.xx -BTREE_DEFS = -D__DBINTERFACE_PRIVATE=1 -Dmpool_error="(void)" -Dabort=abort_ "-Dvirt_fd_t=void*" $(BTREE_DEFS_EXTRA) -CFLAGS += -I$(BTREE_DIR)/PORT/include -CFLAGS += -Wno-old-style-definition -Wno-sign-compare -Wno-unused-parameter $(BTREE_DEFS) +BERKELEY_DB_CONFIG_FILE ?= \"extmod/berkeley-db/berkeley_db_config_port.h\" +CFLAGS += -I$(BTREE_DIR)/include +CFLAGS += -DBERKELEY_DB_CONFIG_FILE=$(BERKELEY_DB_CONFIG_FILE) +CFLAGS += -Wno-old-style-definition -Wno-sign-compare -Wno-unused-parameter SRC += $(addprefix $(realpath $(BTREE_DIR))/,\ btree/bt_close.c \ diff --git a/examples/natmod/btree/btree_c.c b/examples/natmod/btree/btree_c.c index 3c60e41b2d663..bbf51c731fbd1 100644 --- a/examples/natmod/btree/btree_c.c +++ b/examples/natmod/btree/btree_c.c @@ -39,6 +39,10 @@ void abort_(void) { nlr_raise(mp_obj_new_exception(mp_load_global(MP_QSTR_RuntimeError))); } +int puts(const char *s) { + return mp_printf(&mp_plat_print, "%s\n", s); +} + int native_errno; #if defined(__linux__) int *__errno_location (void) diff --git a/extmod/berkeley-db/berkeley_db_config_port.h b/extmod/berkeley-db/berkeley_db_config_port.h new file mode 100644 index 0000000000000..41e4acd81e80f --- /dev/null +++ b/extmod/berkeley-db/berkeley_db_config_port.h @@ -0,0 +1,16 @@ +// Berkeley-db configuration. + +#define __DBINTERFACE_PRIVATE 1 +#define mpool_error printf +#define abort abort_ +#define virt_fd_t void* + +#ifdef MICROPY_BERKELEY_DB_DEFPSIZE +#define DEFPSIZE MICROPY_BERKELEY_DB_DEFPSIZE +#endif + +#ifdef MICROPY_BERKELEY_DB_MINCACHE +#define MINCACHE MICROPY_BERKELEY_DB_MINCACHE +#endif + +__attribute__((noreturn)) void abort_(void); diff --git a/extmod/extmod.cmake b/extmod/extmod.cmake index 957580d15d36d..60f1a23ad6b22 100644 --- a/extmod/extmod.cmake +++ b/extmod/extmod.cmake @@ -132,27 +132,27 @@ if(MICROPY_PY_BTREE) ) target_include_directories(micropy_extmod_btree PRIVATE - ${MICROPY_LIB_BERKELEY_DIR}/PORT/include + ${MICROPY_LIB_BERKELEY_DIR}/include ) + if(NOT BERKELEY_DB_CONFIG_FILE) + set(BERKELEY_DB_CONFIG_FILE "${MICROPY_DIR}/extmod/berkeley-db/berkeley_db_config_port.h") + endif() + target_compile_definitions(micropy_extmod_btree PRIVATE - __DBINTERFACE_PRIVATE=1 - mpool_error=printf - abort=abort_ - "virt_fd_t=void*" + BERKELEY_DB_CONFIG_FILE="${BERKELEY_DB_CONFIG_FILE}" ) # The include directories and compile definitions below are needed to build # modbtree.c and should be added to the main MicroPython target. list(APPEND MICROPY_INC_CORE - "${MICROPY_LIB_BERKELEY_DIR}/PORT/include" + "${MICROPY_LIB_BERKELEY_DIR}/include" ) list(APPEND MICROPY_DEF_CORE MICROPY_PY_BTREE=1 - __DBINTERFACE_PRIVATE=1 - "virt_fd_t=void*" + BERKELEY_DB_CONFIG_FILE="${BERKELEY_DB_CONFIG_FILE}" ) list(APPEND MICROPY_SOURCE_EXTMOD diff --git a/extmod/extmod.mk b/extmod/extmod.mk index bf686fbbb4d95..f7c6f9988e675 100644 --- a/extmod/extmod.mk +++ b/extmod/extmod.mk @@ -381,8 +381,10 @@ endif ifeq ($(MICROPY_PY_BTREE),1) BTREE_DIR = lib/berkeley-db-1.xx -BTREE_DEFS = -D__DBINTERFACE_PRIVATE=1 -Dmpool_error=printf -Dabort=abort_ "-Dvirt_fd_t=void*" $(BTREE_DEFS_EXTRA) -INC += -I$(TOP)/$(BTREE_DIR)/PORT/include +BERKELEY_DB_CONFIG_FILE ?= \"extmod/berkeley-db/berkeley_db_config_port.h\" +CFLAGS_EXTMOD += -DBERKELEY_DB_CONFIG_FILE=$(BERKELEY_DB_CONFIG_FILE) +CFLAGS_EXTMOD += $(BTREE_DEFS_EXTRA) +INC += -I$(TOP)/$(BTREE_DIR)/include SRC_THIRDPARTY_C += $(addprefix $(BTREE_DIR)/,\ btree/bt_close.c \ btree/bt_conv.c \ @@ -401,9 +403,7 @@ SRC_THIRDPARTY_C += $(addprefix $(BTREE_DIR)/,\ ) CFLAGS_EXTMOD += -DMICROPY_PY_BTREE=1 # we need to suppress certain warnings to get berkeley-db to compile cleanly -# and we have separate BTREE_DEFS so the definitions don't interfere with other source code -$(BUILD)/$(BTREE_DIR)/%.o: CFLAGS += -Wno-old-style-definition -Wno-sign-compare -Wno-unused-parameter -Wno-deprecated-non-prototype -Wno-unknown-warning-option $(BTREE_DEFS) -$(BUILD)/extmod/modbtree.o: CFLAGS += $(BTREE_DEFS) +$(BUILD)/$(BTREE_DIR)/%.o: CFLAGS += -Wno-old-style-definition -Wno-sign-compare -Wno-unused-parameter -Wno-deprecated-non-prototype -Wno-unknown-warning-option endif ################################################################################ diff --git a/extmod/modbtree.c b/extmod/modbtree.c index f8c38e0ad4306..55c13ac911a73 100644 --- a/extmod/modbtree.c +++ b/extmod/modbtree.c @@ -57,8 +57,8 @@ #undef CIRCLEQ_INSERT_TAIL #undef CIRCLEQ_REMOVE -#include -#include <../../btree/btree.h> +#include "berkeley-db/db.h" +#include "berkeley-db/btree.h" typedef struct _mp_obj_btree_t { mp_obj_base_t base; diff --git a/ports/esp8266/Makefile b/ports/esp8266/Makefile index 32eb39a203e70..8af7aba0aa9de 100644 --- a/ports/esp8266/Makefile +++ b/ports/esp8266/Makefile @@ -38,7 +38,7 @@ MICROPY_ROM_TEXT_COMPRESSION ?= 1 MICROPY_PY_SSL = 1 MICROPY_SSL_AXTLS = 1 AXTLS_DEFS_EXTRA = -Dabort=abort_ -DRT_MAX_PLAIN_LENGTH=1024 -DRT_EXTRA=4096 -BTREE_DEFS_EXTRA = -DDEFPSIZE=1024 -DMINCACHE=3 +BTREE_DEFS_EXTRA = -DMICROPY_BERKELEY_DB_DEFPSIZE=1024 -DMICROPY_BERKELEY_DB_MINCACHE=3 FROZEN_MANIFEST ?= boards/manifest.py From 7dff38fdc190d7b731fad8319d2ae8aa13fde18a Mon Sep 17 00:00:00 2001 From: Dash Peters Date: Sat, 11 Feb 2023 18:49:15 -0800 Subject: [PATCH 238/408] py/objdeque: Expand implementation to be doubly-ended and support iter. Add `pop()`, `appendleft()`, and `extend()` methods, support iteration and indexing, and initializing from an existing sequence. Iteration and indexing (subscription) have independent configuration flags to enable them. They are enabled by default at the same level that collections.deque is enabled (the extra features level). Also add tests for checking new behavior. Signed-off-by: Damien George --- ports/windows/mpconfigport.h | 2 + py/mpconfig.h | 10 ++ py/objdeque.c | 183 +++++++++++++++++++++++++++++++---- tests/basics/deque1.py | 49 ++++++++++ tests/basics/deque2.py | 64 ++++++++++-- tests/basics/deque2.py.exp | 15 ++- tests/basics/deque_slice.py | 29 ++++++ 7 files changed, 324 insertions(+), 28 deletions(-) create mode 100644 tests/basics/deque_slice.py diff --git a/ports/windows/mpconfigport.h b/ports/windows/mpconfigport.h index dee5568c6225c..55e44c6f5c8c5 100644 --- a/ports/windows/mpconfigport.h +++ b/ports/windows/mpconfigport.h @@ -117,6 +117,8 @@ #define MICROPY_PY_SYS_STDFILES (1) #define MICROPY_PY_SYS_EXC_INFO (1) #define MICROPY_PY_COLLECTIONS_DEQUE (1) +#define MICROPY_PY_COLLECTIONS_DEQUE_ITER (1) +#define MICROPY_PY_COLLECTIONS_DEQUE_SUBSCR (1) #define MICROPY_PY_COLLECTIONS_ORDEREDDICT (1) #ifndef MICROPY_PY_MATH_SPECIAL_FUNCTIONS #define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (1) diff --git a/py/mpconfig.h b/py/mpconfig.h index 85b9e2c9cd104..cb0f050a74bd8 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1303,6 +1303,16 @@ typedef double mp_float_t; #define MICROPY_PY_COLLECTIONS_DEQUE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif +// Whether "collections.deque" supports iteration +#ifndef MICROPY_PY_COLLECTIONS_DEQUE_ITER +#define MICROPY_PY_COLLECTIONS_DEQUE_ITER (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) +#endif + +// Whether "collections.deque" supports subscription +#ifndef MICROPY_PY_COLLECTIONS_DEQUE_SUBSCR +#define MICROPY_PY_COLLECTIONS_DEQUE_SUBSCR (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) +#endif + // Whether to provide "collections.OrderedDict" type #ifndef MICROPY_PY_COLLECTIONS_ORDEREDDICT #define MICROPY_PY_COLLECTIONS_ORDEREDDICT (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) diff --git a/py/objdeque.c b/py/objdeque.c index 68e1621793116..583537017fdb2 100644 --- a/py/objdeque.c +++ b/py/objdeque.c @@ -25,13 +25,11 @@ */ #include // for ssize_t -#include - -#include "py/mpconfig.h" -#if MICROPY_PY_COLLECTIONS_DEQUE #include "py/runtime.h" +#if MICROPY_PY_COLLECTIONS_DEQUE + typedef struct _mp_obj_deque_t { mp_obj_base_t base; size_t alloc; @@ -42,15 +40,15 @@ typedef struct _mp_obj_deque_t { #define FLAG_CHECK_OVERFLOW 1 } mp_obj_deque_t; +static mp_obj_t mp_obj_deque_append(mp_obj_t self_in, mp_obj_t arg); +static mp_obj_t mp_obj_deque_extend(mp_obj_t self_in, mp_obj_t arg_in); +#if MICROPY_PY_COLLECTIONS_DEQUE_ITER +static mp_obj_t mp_obj_new_deque_it(mp_obj_t deque, mp_obj_iter_buf_t *iter_buf); +#endif + static mp_obj_t deque_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 2, 3, false); - /* Initialization from existing sequence is not supported, so an empty - tuple must be passed as such. */ - if (args[0] != mp_const_empty_tuple) { - mp_raise_ValueError(NULL); - } - // Protect against -1 leading to zero-length allocation and bad array access mp_int_t maxlen = mp_obj_get_int(args[1]); if (maxlen < 0) { @@ -66,21 +64,27 @@ static mp_obj_t deque_make_new(const mp_obj_type_t *type, size_t n_args, size_t o->flags = mp_obj_get_int(args[2]); } + mp_obj_deque_extend(MP_OBJ_FROM_PTR(o), args[0]); + return MP_OBJ_FROM_PTR(o); } +static size_t deque_len(mp_obj_deque_t *self) { + ssize_t len = self->i_put - self->i_get; + if (len < 0) { + len += self->alloc; + } + return len; +} + static mp_obj_t deque_unary_op(mp_unary_op_t op, mp_obj_t self_in) { mp_obj_deque_t *self = MP_OBJ_TO_PTR(self_in); switch (op) { case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->i_get != self->i_put); - case MP_UNARY_OP_LEN: { - ssize_t len = self->i_put - self->i_get; - if (len < 0) { - len += self->alloc; - } - return MP_OBJ_NEW_SMALL_INT(len); - } + case MP_UNARY_OP_LEN: + return MP_OBJ_NEW_SMALL_INT(deque_len(self)); + #if MICROPY_PY_SYS_GETSIZEOF case MP_UNARY_OP_SIZEOF: { size_t sz = sizeof(*self) + sizeof(mp_obj_t) * self->alloc; @@ -117,6 +121,45 @@ static mp_obj_t mp_obj_deque_append(mp_obj_t self_in, mp_obj_t arg) { } static MP_DEFINE_CONST_FUN_OBJ_2(deque_append_obj, mp_obj_deque_append); +static mp_obj_t mp_obj_deque_appendleft(mp_obj_t self_in, mp_obj_t arg) { + mp_obj_deque_t *self = MP_OBJ_TO_PTR(self_in); + + size_t new_i_get = self->i_get - 1; + if (self->i_get == 0) { + new_i_get = self->alloc - 1; + } + + if (self->flags & FLAG_CHECK_OVERFLOW && new_i_get == self->i_put) { + mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("full")); + } + + self->i_get = new_i_get; + self->items[self->i_get] = arg; + + // overwriting first element in deque + if (self->i_put == new_i_get) { + if (self->i_put == 0) { + self->i_put = self->alloc - 1; + } else { + self->i_put--; + } + } + + return mp_const_none; +} +static MP_DEFINE_CONST_FUN_OBJ_2(deque_appendleft_obj, mp_obj_deque_appendleft); + +static mp_obj_t mp_obj_deque_extend(mp_obj_t self_in, mp_obj_t arg_in) { + mp_obj_iter_buf_t iter_buf; + mp_obj_t iter = mp_getiter(arg_in, &iter_buf); + mp_obj_t item; + while ((item = mp_iternext(iter)) != MP_OBJ_STOP_ITERATION) { + mp_obj_deque_append(self_in, item); + } + return mp_const_none; +} +static MP_DEFINE_CONST_FUN_OBJ_2(deque_extend_obj, mp_obj_deque_extend); + static mp_obj_t deque_popleft(mp_obj_t self_in) { mp_obj_deque_t *self = MP_OBJ_TO_PTR(self_in); @@ -135,6 +178,51 @@ static mp_obj_t deque_popleft(mp_obj_t self_in) { } static MP_DEFINE_CONST_FUN_OBJ_1(deque_popleft_obj, deque_popleft); +static mp_obj_t deque_pop(mp_obj_t self_in) { + mp_obj_deque_t *self = MP_OBJ_TO_PTR(self_in); + + if (self->i_get == self->i_put) { + mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("empty")); + } + + if (self->i_put == 0) { + self->i_put = self->alloc - 1; + } else { + self->i_put--; + } + + mp_obj_t ret = self->items[self->i_put]; + self->items[self->i_put] = MP_OBJ_NULL; + + return ret; +} +static MP_DEFINE_CONST_FUN_OBJ_1(deque_pop_obj, deque_pop); + +#if MICROPY_PY_COLLECTIONS_DEQUE_SUBSCR +static mp_obj_t deque_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { + if (value == MP_OBJ_NULL) { + // delete not supported, fall back to mp_obj_subscr() error message + return MP_OBJ_NULL; + } + mp_obj_deque_t *self = MP_OBJ_TO_PTR(self_in); + + size_t offset = mp_get_index(self->base.type, deque_len(self), index, false); + size_t index_val = self->i_get + offset; + if (index_val > self->alloc) { + index_val -= self->alloc; + } + + if (value == MP_OBJ_SENTINEL) { + // load + return self->items[index_val]; + } else { + // store into deque + self->items[index_val] = value; + return mp_const_none; + } +} +#endif + #if 0 static mp_obj_t deque_clear(mp_obj_t self_in) { mp_obj_deque_t *self = MP_OBJ_TO_PTR(self_in); @@ -147,21 +235,80 @@ static MP_DEFINE_CONST_FUN_OBJ_1(deque_clear_obj, deque_clear); static const mp_rom_map_elem_t deque_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_append), MP_ROM_PTR(&deque_append_obj) }, + { MP_ROM_QSTR(MP_QSTR_appendleft), MP_ROM_PTR(&deque_appendleft_obj) }, + { MP_ROM_QSTR(MP_QSTR_extend), MP_ROM_PTR(&deque_extend_obj) }, #if 0 { MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&deque_clear_obj) }, #endif + { MP_ROM_QSTR(MP_QSTR_pop), MP_ROM_PTR(&deque_pop_obj) }, { MP_ROM_QSTR(MP_QSTR_popleft), MP_ROM_PTR(&deque_popleft_obj) }, }; static MP_DEFINE_CONST_DICT(deque_locals_dict, deque_locals_dict_table); +#if MICROPY_PY_COLLECTIONS_DEQUE_ITER +#define DEQUE_TYPE_FLAGS MP_TYPE_FLAG_ITER_IS_GETITER +#define DEQUE_TYPE_ITER iter, mp_obj_new_deque_it, +#else +#define DEQUE_TYPE_FLAGS MP_TYPE_FLAG_NONE +#define DEQUE_TYPE_ITER +#endif + +#if MICROPY_PY_COLLECTIONS_DEQUE_SUBSCR +#define DEQUE_TYPE_SUBSCR subscr, deque_subscr, +#else +#define DEQUE_TYPE_SUBSCR +#endif + MP_DEFINE_CONST_OBJ_TYPE( mp_type_deque, MP_QSTR_deque, - MP_TYPE_FLAG_NONE, + MP_TYPE_FLAG_ITER_IS_GETITER, make_new, deque_make_new, unary_op, deque_unary_op, + DEQUE_TYPE_SUBSCR + DEQUE_TYPE_ITER locals_dict, &deque_locals_dict ); +/******************************************************************************/ +/* deque iterator */ + +#if MICROPY_PY_COLLECTIONS_DEQUE_ITER + +typedef struct _mp_obj_deque_it_t { + mp_obj_base_t base; + mp_fun_1_t iternext; + mp_obj_t deque; + size_t cur; +} mp_obj_deque_it_t; + +static mp_obj_t deque_it_iternext(mp_obj_t self_in) { + mp_obj_deque_it_t *self = MP_OBJ_TO_PTR(self_in); + mp_obj_deque_t *deque = MP_OBJ_TO_PTR(self->deque); + if (self->cur != deque->i_put) { + mp_obj_t o_out = deque->items[self->cur]; + if (++self->cur == deque->alloc) { + self->cur = 0; + } + return o_out; + } else { + return MP_OBJ_STOP_ITERATION; + } +} + +static mp_obj_t mp_obj_new_deque_it(mp_obj_t deque, mp_obj_iter_buf_t *iter_buf) { + mp_obj_deque_t *deque_ = MP_OBJ_TO_PTR(deque); + size_t i_get = deque_->i_get; + assert(sizeof(mp_obj_deque_it_t) <= sizeof(mp_obj_iter_buf_t)); + mp_obj_deque_it_t *o = (mp_obj_deque_it_t *)iter_buf; + o->base.type = &mp_type_polymorph_iter; + o->iternext = deque_it_iternext; + o->deque = deque; + o->cur = i_get; + return MP_OBJ_FROM_PTR(o); +} + +#endif + #endif // MICROPY_PY_COLLECTIONS_DEQUE diff --git a/tests/basics/deque1.py b/tests/basics/deque1.py index 8b7874e2b1d37..188069bcbf30a 100644 --- a/tests/basics/deque1.py +++ b/tests/basics/deque1.py @@ -63,3 +63,52 @@ ~d except TypeError: print("TypeError") + + +# Same tests, but now with pop() and appendleft() + +d = deque((), 2) +print(len(d)) +print(bool(d)) + +try: + d.popleft() +except IndexError: + print("IndexError") + +print(d.append(1)) +print(len(d)) +print(bool(d)) +print(d.popleft()) +print(len(d)) + +d.append(2) +print(d.popleft()) + +d.append(3) +d.append(4) +print(len(d)) +print(d.popleft(), d.popleft()) +try: + d.popleft() +except IndexError: + print("IndexError") + +d.append(5) +d.append(6) +d.append(7) +print(len(d)) +print(d.popleft(), d.popleft()) +print(len(d)) +try: + d.popleft() +except IndexError: + print("IndexError") + +d = deque((), 2) +d.appendleft(1) +d.appendleft(2) +d.appendleft(3) +d.appendleft(4) +d.appendleft(5) +print(d.pop(), d.pop()) \ No newline at end of file diff --git a/tests/basics/deque2.py b/tests/basics/deque2.py index 80fcd66785663..743c040789d69 100644 --- a/tests/basics/deque2.py +++ b/tests/basics/deque2.py @@ -6,18 +6,50 @@ print("SKIP") raise SystemExit +# Initial sequence is supported +d = deque([1, 2, 3], 10) + +# iteration over sequence +for x in d: + print(x) + +# Iterables larger than maxlen have the beginnings removed, also tests +# iteration through conversion to list +d = deque([1, 2, 3, 4, 5], 3) +print(list(d)) + +# Empty iterables are also supported +deque([], 10) + +# Extending deques with iterables +d.extend([6, 7]) +print(list(d)) + +# Accessing queue elements via index +d = deque((0, 1, 2, 3), 5) +print(d[0], d[1], d[-1]) + +# Writing queue elements via index +d[3] = 5 +print(d[3]) + +# Accessing indices out of bounds raises IndexError +try: + d[4] +except IndexError: + print("IndexError") -# Initial sequence is not supported try: - deque([1, 2, 3], 10) -except ValueError: - print("ValueError") + d[4] = 0 +except IndexError: + print("IndexError") -# Not even empty list, only empty tuple +# Removing elements with del is not supported, fall back on mp_obj_subscr() error message try: - deque([], 10) -except ValueError: - print("ValueError") + del d[0] +except TypeError: + print("TypeError") + # Only fixed-size deques are supported, so length arg is mandatory try: @@ -32,6 +64,11 @@ except IndexError: print("IndexError") +try: + d.pop() +except IndexError: + print("IndexError") + print(d.append(1)) print(d.popleft()) @@ -46,6 +83,11 @@ except IndexError as e: print(repr(e)) +try: + d.pop() +except IndexError as e: + print(repr(e)) + d.append(5) d.append(6) print(len(d)) @@ -53,6 +95,12 @@ d.append(7) except IndexError as e: print(repr(e)) + +try: + d.appendleft(8) +except IndexError as e: + print(repr(e)) + print(len(d)) print(d.popleft(), d.popleft()) diff --git a/tests/basics/deque2.py.exp b/tests/basics/deque2.py.exp index 3df8acf405627..71f74ed6c4aaf 100644 --- a/tests/basics/deque2.py.exp +++ b/tests/basics/deque2.py.exp @@ -1,14 +1,25 @@ -ValueError -ValueError +1 +2 +3 +[3, 4, 5] +[5, 6, 7] +0 1 3 +5 +IndexError +IndexError TypeError +TypeError +IndexError IndexError None 1 2 3 4 IndexError('empty',) +IndexError('empty',) 2 IndexError('full',) +IndexError('full',) 2 5 6 0 diff --git a/tests/basics/deque_slice.py b/tests/basics/deque_slice.py new file mode 100644 index 0000000000000..367aeea3a171c --- /dev/null +++ b/tests/basics/deque_slice.py @@ -0,0 +1,29 @@ +try: + from collections import deque +except ImportError: + print("SKIP") + raise SystemExit + +d = deque((), 10) + +d.append(1) +d.append(2) +d.append(3) + +# Index slicing for reads is not supported in CPython +try: + d[0:1] +except TypeError: + print("TypeError") + +# Index slicing for writes is not supported in CPython +try: + d[0:1] = (-1, -2) +except TypeError: + print("TypeError") + +# Index slicing for writes is not supported in CPython +try: + del d[0:1] +except TypeError: + print("TypeError") From bf18ddd98930787c22b561884e0b3807b47d412b Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 19 Mar 2024 10:04:29 +1100 Subject: [PATCH 239/408] tools/mpy-tool.py: Fix merging of more than 128 mpy files. The argument to MP_BC_MAKE_FUNCTION (raw code index) was being encoded as a byte instead of a variable unsigned int. That meant that if there were more than 128 merged mpy files the encoding would be invalid. Fix that by using `mp_encode_uint(idx)` to encode the raw code index. And also use `Opcode` constants for the opcode values to make it easier to understand the code. Signed-off-by: Damien George --- tools/mpy-tool.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py index 35c06a30282e0..06ccd6a1da8f3 100755 --- a/tools/mpy-tool.py +++ b/tools/mpy-tool.py @@ -1730,10 +1730,13 @@ def copy_section(file, offset, offset2): bytecode.append(0b00000010) # prelude size (n_info=1, n_cell=0) bytecode.extend(b"\x00") # simple_name: qstr index 0 (will use source filename) for idx in range(len(compiled_modules)): - bytecode.append(0x32) # MP_BC_MAKE_FUNCTION - bytecode.append(idx) # index raw code - bytecode.extend(b"\x34\x00\x59") # MP_BC_CALL_FUNCTION, 0 args, MP_BC_POP_TOP - bytecode.extend(b"\x51\x63") # MP_BC_LOAD_NONE, MP_BC_RETURN_VALUE + bytecode.append(Opcode.MP_BC_MAKE_FUNCTION) + bytecode.extend(mp_encode_uint(idx)) # index of raw code + bytecode.append(Opcode.MP_BC_CALL_FUNCTION) + bytecode.append(0) # 0 arguments + bytecode.append(Opcode.MP_BC_POP_TOP) + bytecode.append(Opcode.MP_BC_LOAD_CONST_NONE) + bytecode.append(Opcode.MP_BC_RETURN_VALUE) merged_mpy.extend(mp_encode_uint(len(bytecode) << 3 | 1 << 2)) # length, has_children merged_mpy.extend(bytecode) From c9016b4979a718c7a66b2145e00fbdabfa2dc509 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 18 Mar 2024 22:41:28 +1100 Subject: [PATCH 240/408] tests/basics: Split MicroPython-specific deque tests to separate file. So that the MicroPython-specific behaviour can be isolated, and the CPython compatible test don't need a .exp file. Signed-off-by: Damien George --- tests/basics/deque2.py | 68 ----------------- tests/basics/deque_micropython.py | 75 +++++++++++++++++++ ...deque2.py.exp => deque_micropython.py.exp} | 11 +-- 3 files changed, 76 insertions(+), 78 deletions(-) create mode 100644 tests/basics/deque_micropython.py rename tests/basics/{deque2.py.exp => deque_micropython.py.exp} (75%) diff --git a/tests/basics/deque2.py b/tests/basics/deque2.py index 743c040789d69..3552d5be37abe 100644 --- a/tests/basics/deque2.py +++ b/tests/basics/deque2.py @@ -1,5 +1,3 @@ -# Tests for deques with "check overflow" flag and other extensions -# wrt to CPython. try: from collections import deque except ImportError: @@ -43,69 +41,3 @@ d[4] = 0 except IndexError: print("IndexError") - -# Removing elements with del is not supported, fall back on mp_obj_subscr() error message -try: - del d[0] -except TypeError: - print("TypeError") - - -# Only fixed-size deques are supported, so length arg is mandatory -try: - deque(()) -except TypeError: - print("TypeError") - -d = deque((), 2, True) - -try: - d.popleft() -except IndexError: - print("IndexError") - -try: - d.pop() -except IndexError: - print("IndexError") - -print(d.append(1)) -print(d.popleft()) - -d.append(2) -print(d.popleft()) - -d.append(3) -d.append(4) -print(d.popleft(), d.popleft()) -try: - d.popleft() -except IndexError as e: - print(repr(e)) - -try: - d.pop() -except IndexError as e: - print(repr(e)) - -d.append(5) -d.append(6) -print(len(d)) -try: - d.append(7) -except IndexError as e: - print(repr(e)) - -try: - d.appendleft(8) -except IndexError as e: - print(repr(e)) - -print(len(d)) - -print(d.popleft(), d.popleft()) -print(len(d)) -try: - d.popleft() -except IndexError as e: - print(repr(e)) diff --git a/tests/basics/deque_micropython.py b/tests/basics/deque_micropython.py new file mode 100644 index 0000000000000..5f32bbc496a3c --- /dev/null +++ b/tests/basics/deque_micropython.py @@ -0,0 +1,75 @@ +# Test MicroPython-specific features of collections.deque. + +try: + from collections import deque +except ImportError: + print("SKIP") + raise SystemExit + + +# Only fixed-size deques are supported, so length arg is mandatory. +try: + deque(()) +except TypeError: + print("TypeError") + +# Test third argument: flags when True means check for under/overflow +d = deque((), 2, True) + +try: + d.popleft() +except IndexError: + print("IndexError") + +try: + d.pop() +except IndexError: + print("IndexError") + +# Removing elements with del is not supported, fallback to +# mp_obj_subscr() error message. +try: + del d[0] +except TypeError: + print("TypeError") + +print(d.append(1)) +print(d.popleft()) + +d.append(2) +print(d.popleft()) + +d.append(3) +d.append(4) +print(d.popleft(), d.popleft()) +try: + d.popleft() +except IndexError as e: + print(repr(e)) + +try: + d.pop() +except IndexError as e: + print(repr(e)) + +d.append(5) +d.append(6) +print(len(d)) +try: + d.append(7) +except IndexError as e: + print(repr(e)) + +try: + d.appendleft(8) +except IndexError as e: + print(repr(e)) + +print(len(d)) + +print(d.popleft(), d.popleft()) +print(len(d)) +try: + d.popleft() +except IndexError as e: + print(repr(e)) diff --git a/tests/basics/deque2.py.exp b/tests/basics/deque_micropython.py.exp similarity index 75% rename from tests/basics/deque2.py.exp rename to tests/basics/deque_micropython.py.exp index 71f74ed6c4aaf..f1ff7b77ac880 100644 --- a/tests/basics/deque2.py.exp +++ b/tests/basics/deque_micropython.py.exp @@ -1,16 +1,7 @@ -1 -2 -3 -[3, 4, 5] -[5, 6, 7] -0 1 3 -5 -IndexError -IndexError -TypeError TypeError IndexError IndexError +TypeError None 1 2 From d92dff881ca99281893b1d77eee4bf2eca25d0c8 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 18 Mar 2024 22:42:33 +1100 Subject: [PATCH 241/408] docs/library/collections: Update deque docs to describe new features. Signed-off-by: Damien George --- docs/library/collections.rst | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/docs/library/collections.rst b/docs/library/collections.rst index 6cf2c096ffc62..6a23e456c66a7 100644 --- a/docs/library/collections.rst +++ b/docs/library/collections.rst @@ -18,7 +18,9 @@ Classes appends and pops from either side of the deque. New deques are created using the following arguments: - - *iterable* must be the empty tuple, and the new deque is created empty. + - *iterable* is an iterable used to populate the deque when it is + created. It can be an empty tuple or list to create a deque that + is initially empty. - *maxlen* must be specified and the deque will be bounded to this maximum length. Once the deque is full, any new items added will @@ -26,18 +28,37 @@ Classes - The optional *flags* can be 1 to check for overflow when adding items. - As well as supporting `bool` and `len`, deque objects have the following - methods: + Deque objects support `bool`, `len`, iteration and subscript load and store. + They also have the following methods: .. method:: deque.append(x) Add *x* to the right side of the deque. - Raises IndexError if overflow checking is enabled and there is no more room left. + Raises ``IndexError`` if overflow checking is enabled and there is + no more room in the queue. + + .. method:: deque.appendleft(x) + + Add *x* to the left side of the deque. + Raises ``IndexError`` if overflow checking is enabled and there is + no more room in the queue. + + .. method:: deque.pop() + + Remove and return an item from the right side of the deque. + Raises ``IndexError`` if no items are present. .. method:: deque.popleft() Remove and return an item from the left side of the deque. - Raises IndexError if no items are present. + Raises ``IndexError`` if no items are present. + + .. method:: deque.extend(iterable) + + Extend the deque by appending all the items from *iterable* to + the right of the deque. + Raises ``IndexError`` if overflow checking is enabled and there is + no more room in the deque. .. function:: namedtuple(name, fields) From f52b0d0ff1788225fd61a748e0786aa90e953481 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 18 Mar 2024 12:29:11 +1100 Subject: [PATCH 242/408] py/asm: Add ASM_NOT_REG and ASM_NEG_REG macros for unary ops. ASM_NOT_REG is optional, it can be synthesised by xor(reg, -1). ASM_NEG_REG can also be synthesised with a subtraction, but most architectures have a dedicated instruction for it. Signed-off-by: Damien George --- py/asmarm.c | 22 ++++++++++++++++++++++ py/asmarm.h | 4 ++++ py/asmthumb.h | 2 ++ py/asmx64.c | 10 ++++++++++ py/asmx64.h | 4 ++++ py/asmx86.c | 10 ++++++++++ py/asmx86.h | 4 ++++ py/asmxtensa.h | 5 +++++ 8 files changed, 61 insertions(+) diff --git a/py/asmarm.c b/py/asmarm.c index cd346949eb0db..6006490701251 100644 --- a/py/asmarm.c +++ b/py/asmarm.c @@ -77,6 +77,11 @@ static uint asm_arm_op_mvn_imm(uint rd, uint imm) { return 0x3e00000 | (rd << 12) | imm; } +static uint asm_arm_op_mvn_reg(uint rd, uint rm) { + // mvn rd, rm + return 0x1e00000 | (rd << 12) | rm; +} + static uint asm_arm_op_add_imm(uint rd, uint rn, uint imm) { // add rd, rn, #imm return 0x2800000 | (rn << 16) | (rd << 12) | (imm & 0xFF); @@ -97,6 +102,11 @@ static uint asm_arm_op_sub_reg(uint rd, uint rn, uint rm) { return 0x0400000 | (rn << 16) | (rd << 12) | rm; } +static uint asm_arm_op_rsb_imm(uint rd, uint rn, uint imm) { + // rsb rd, rn, #imm + return 0x2600000 | (rn << 16) | (rd << 12) | (imm & 0xFF); +} + static uint asm_arm_op_mul_reg(uint rd, uint rm, uint rs) { // mul rd, rm, rs assert(rd != rm); @@ -228,11 +238,23 @@ void asm_arm_setcc_reg(asm_arm_t *as, uint rd, uint cond) { emit(as, asm_arm_op_mov_imm(rd, 0) | (cond ^ (1 << 28))); // mov!COND rd, #0 } +void asm_arm_mvn_reg_reg(asm_arm_t *as, uint rd, uint rm) { + // mvn rd, rm + // computes: rd := ~rm + emit_al(as, asm_arm_op_mvn_reg(rd, rm)); +} + void asm_arm_add_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm) { // add rd, rn, rm emit_al(as, asm_arm_op_add_reg(rd, rn, rm)); } +void asm_arm_rsb_reg_reg_imm(asm_arm_t *as, uint rd, uint rn, uint imm) { + // rsb rd, rn, #imm + // computes: rd := #imm - rn + emit_al(as, asm_arm_op_rsb_imm(rd, rn, imm)); +} + void asm_arm_sub_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm) { // sub rd, rn, rm emit_al(as, asm_arm_op_sub_reg(rd, rn, rm)); diff --git a/py/asmarm.h b/py/asmarm.h index 81c3f7b1cf416..4a4253aef6878 100644 --- a/py/asmarm.h +++ b/py/asmarm.h @@ -94,8 +94,10 @@ void asm_arm_cmp_reg_i8(asm_arm_t *as, uint rd, int imm); void asm_arm_cmp_reg_reg(asm_arm_t *as, uint rd, uint rn); // arithmetic +void asm_arm_mvn_reg_reg(asm_arm_t *as, uint rd, uint rm); void asm_arm_add_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm); void asm_arm_sub_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm); +void asm_arm_rsb_reg_reg_imm(asm_arm_t *as, uint rd, uint rn, uint imm); void asm_arm_mul_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm); void asm_arm_and_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm); void asm_arm_eor_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm); @@ -188,6 +190,8 @@ void asm_arm_bx_reg(asm_arm_t *as, uint reg_src); #define ASM_MOV_REG_LOCAL_ADDR(as, reg_dest, local_num) asm_arm_mov_reg_local_addr((as), (reg_dest), (local_num)) #define ASM_MOV_REG_PCREL(as, reg_dest, label) asm_arm_mov_reg_pcrel((as), (reg_dest), (label)) +#define ASM_NOT_REG(as, reg_dest) asm_arm_mvn_reg_reg((as), (reg_dest), (reg_dest)) +#define ASM_NEG_REG(as, reg_dest) asm_arm_rsb_reg_reg_imm((as), (reg_dest), (reg_dest), 0) #define ASM_LSL_REG_REG(as, reg_dest, reg_shift) asm_arm_lsl_reg_reg((as), (reg_dest), (reg_shift)) #define ASM_LSR_REG_REG(as, reg_dest, reg_shift) asm_arm_lsr_reg_reg((as), (reg_dest), (reg_shift)) #define ASM_ASR_REG_REG(as, reg_dest, reg_shift) asm_arm_asr_reg_reg((as), (reg_dest), (reg_shift)) diff --git a/py/asmthumb.h b/py/asmthumb.h index 2829ac4c7e413..a9e68d7adbbea 100644 --- a/py/asmthumb.h +++ b/py/asmthumb.h @@ -406,6 +406,8 @@ void asm_thumb_b_rel12(asm_thumb_t *as, int rel); #define ASM_MOV_REG_LOCAL_ADDR(as, reg_dest, local_num) asm_thumb_mov_reg_local_addr((as), (reg_dest), (local_num)) #define ASM_MOV_REG_PCREL(as, rlo_dest, label) asm_thumb_mov_reg_pcrel((as), (rlo_dest), (label)) +#define ASM_NOT_REG(as, reg_dest) asm_thumb_mvn_rlo_rlo((as), (reg_dest), (reg_dest)) +#define ASM_NEG_REG(as, reg_dest) asm_thumb_neg_rlo_rlo((as), (reg_dest), (reg_dest)) #define ASM_LSL_REG_REG(as, reg_dest, reg_shift) asm_thumb_format_4((as), ASM_THUMB_FORMAT_4_LSL, (reg_dest), (reg_shift)) #define ASM_LSR_REG_REG(as, reg_dest, reg_shift) asm_thumb_format_4((as), ASM_THUMB_FORMAT_4_LSR, (reg_dest), (reg_shift)) #define ASM_ASR_REG_REG(as, reg_dest, reg_shift) asm_thumb_format_4((as), ASM_THUMB_FORMAT_4_ASR, (reg_dest), (reg_shift)) diff --git a/py/asmx64.c b/py/asmx64.c index abddc162696c0..d9f33cfb2ad7e 100644 --- a/py/asmx64.c +++ b/py/asmx64.c @@ -54,6 +54,8 @@ #define OPCODE_MOVZX_RM8_TO_R64 (0xb6) /* 0x0f 0xb6/r */ #define OPCODE_MOVZX_RM16_TO_R64 (0xb7) /* 0x0f 0xb7/r */ #define OPCODE_LEA_MEM_TO_R64 (0x8d) /* /r */ +#define OPCODE_NOT_RM64 (0xf7) /* /2 */ +#define OPCODE_NEG_RM64 (0xf7) /* /3 */ #define OPCODE_AND_R64_TO_RM64 (0x21) /* /r */ #define OPCODE_OR_R64_TO_RM64 (0x09) /* /r */ #define OPCODE_XOR_R64_TO_RM64 (0x31) /* /r */ @@ -362,6 +364,14 @@ void asm_x64_mov_i64_to_r64_optimised(asm_x64_t *as, int64_t src_i64, int dest_r } } +void asm_x64_not_r64(asm_x64_t *as, int dest_r64) { + asm_x64_generic_r64_r64(as, dest_r64, 2, OPCODE_NOT_RM64); +} + +void asm_x64_neg_r64(asm_x64_t *as, int dest_r64) { + asm_x64_generic_r64_r64(as, dest_r64, 3, OPCODE_NEG_RM64); +} + void asm_x64_and_r64_r64(asm_x64_t *as, int dest_r64, int src_r64) { asm_x64_generic_r64_r64(as, dest_r64, src_r64, OPCODE_AND_R64_TO_RM64); } diff --git a/py/asmx64.h b/py/asmx64.h index a8efc2bf60161..c63e31797ef54 100644 --- a/py/asmx64.h +++ b/py/asmx64.h @@ -97,6 +97,8 @@ void asm_x64_mov_mem8_to_r64zx(asm_x64_t *as, int src_r64, int src_disp, int des void asm_x64_mov_mem16_to_r64zx(asm_x64_t *as, int src_r64, int src_disp, int dest_r64); void asm_x64_mov_mem32_to_r64zx(asm_x64_t *as, int src_r64, int src_disp, int dest_r64); void asm_x64_mov_mem64_to_r64(asm_x64_t *as, int src_r64, int src_disp, int dest_r64); +void asm_x64_not_r64(asm_x64_t *as, int dest_r64); +void asm_x64_neg_r64(asm_x64_t *as, int dest_r64); void asm_x64_and_r64_r64(asm_x64_t *as, int dest_r64, int src_r64); void asm_x64_or_r64_r64(asm_x64_t *as, int dest_r64, int src_r64); void asm_x64_xor_r64_r64(asm_x64_t *as, int dest_r64, int src_r64); @@ -191,6 +193,8 @@ void asm_x64_call_ind(asm_x64_t *as, size_t fun_id, int temp_r32); #define ASM_MOV_REG_LOCAL_ADDR(as, reg_dest, local_num) asm_x64_mov_local_addr_to_r64((as), (local_num), (reg_dest)) #define ASM_MOV_REG_PCREL(as, reg_dest, label) asm_x64_mov_reg_pcrel((as), (reg_dest), (label)) +#define ASM_NOT_REG(as, reg) asm_x64_not_r64((as), (reg)) +#define ASM_NEG_REG(as, reg) asm_x64_neg_r64((as), (reg)) #define ASM_LSL_REG(as, reg) asm_x64_shl_r64_cl((as), (reg)) #define ASM_LSR_REG(as, reg) asm_x64_shr_r64_cl((as), (reg)) #define ASM_ASR_REG(as, reg) asm_x64_sar_r64_cl((as), (reg)) diff --git a/py/asmx86.c b/py/asmx86.c index 94e0213d65c0f..4acac1b46ac4f 100644 --- a/py/asmx86.c +++ b/py/asmx86.c @@ -54,6 +54,8 @@ #define OPCODE_MOVZX_RM8_TO_R32 (0xb6) /* 0x0f 0xb6/r */ #define OPCODE_MOVZX_RM16_TO_R32 (0xb7) /* 0x0f 0xb7/r */ #define OPCODE_LEA_MEM_TO_R32 (0x8d) /* /r */ +#define OPCODE_NOT_RM32 (0xf7) /* /2 */ +#define OPCODE_NEG_RM32 (0xf7) /* /3 */ #define OPCODE_AND_R32_TO_RM32 (0x21) /* /r */ #define OPCODE_OR_R32_TO_RM32 (0x09) /* /r */ #define OPCODE_XOR_R32_TO_RM32 (0x31) /* /r */ @@ -244,6 +246,14 @@ size_t asm_x86_mov_i32_to_r32(asm_x86_t *as, int32_t src_i32, int dest_r32) { return loc; } +void asm_x86_not_r32(asm_x86_t *as, int dest_r32) { + asm_x86_generic_r32_r32(as, dest_r32, 2, OPCODE_NOT_RM32); +} + +void asm_x86_neg_r32(asm_x86_t *as, int dest_r32) { + asm_x86_generic_r32_r32(as, dest_r32, 3, OPCODE_NEG_RM32); +} + void asm_x86_and_r32_r32(asm_x86_t *as, int dest_r32, int src_r32) { asm_x86_generic_r32_r32(as, dest_r32, src_r32, OPCODE_AND_R32_TO_RM32); } diff --git a/py/asmx86.h b/py/asmx86.h index ac98643a6a866..027d44151e82e 100644 --- a/py/asmx86.h +++ b/py/asmx86.h @@ -92,6 +92,8 @@ void asm_x86_mov_r32_to_mem32(asm_x86_t *as, int src_r32, int dest_r32, int dest void asm_x86_mov_mem8_to_r32zx(asm_x86_t *as, int src_r32, int src_disp, int dest_r32); void asm_x86_mov_mem16_to_r32zx(asm_x86_t *as, int src_r32, int src_disp, int dest_r32); void asm_x86_mov_mem32_to_r32(asm_x86_t *as, int src_r32, int src_disp, int dest_r32); +void asm_x86_not_r32(asm_x86_t *as, int dest_r32); +void asm_x86_neg_r32(asm_x86_t *as, int dest_r32); void asm_x86_and_r32_r32(asm_x86_t *as, int dest_r32, int src_r32); void asm_x86_or_r32_r32(asm_x86_t *as, int dest_r32, int src_r32); void asm_x86_xor_r32_r32(asm_x86_t *as, int dest_r32, int src_r32); @@ -186,6 +188,8 @@ void asm_x86_call_ind(asm_x86_t *as, size_t fun_id, mp_uint_t n_args, int temp_r #define ASM_MOV_REG_LOCAL_ADDR(as, reg_dest, local_num) asm_x86_mov_local_addr_to_r32((as), (local_num), (reg_dest)) #define ASM_MOV_REG_PCREL(as, reg_dest, label) asm_x86_mov_reg_pcrel((as), (reg_dest), (label)) +#define ASM_NOT_REG(as, reg) asm_x86_not_r32((as), (reg)) +#define ASM_NEG_REG(as, reg) asm_x86_neg_r32((as), (reg)) #define ASM_LSL_REG(as, reg) asm_x86_shl_r32_cl((as), (reg)) #define ASM_LSR_REG(as, reg) asm_x86_shr_r32_cl((as), (reg)) #define ASM_ASR_REG(as, reg) asm_x86_sar_r32_cl((as), (reg)) diff --git a/py/asmxtensa.h b/py/asmxtensa.h index 5bd6426a14481..aef9e74625d3a 100644 --- a/py/asmxtensa.h +++ b/py/asmxtensa.h @@ -211,6 +211,10 @@ static inline void asm_xtensa_op_mull(asm_xtensa_t *as, uint reg_dest, uint reg_ asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRR(0, 2, 8, reg_dest, reg_src_a, reg_src_b)); } +static inline void asm_xtensa_op_neg(asm_xtensa_t *as, uint reg_dest, uint reg_src) { + asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRR(0, 0, 6, reg_dest, 0, reg_src)); +} + static inline void asm_xtensa_op_or(asm_xtensa_t *as, uint reg_dest, uint reg_src_a, uint reg_src_b) { asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRR(0, 0, 2, reg_dest, reg_src_a, reg_src_b)); } @@ -371,6 +375,7 @@ void asm_xtensa_call_ind_win(asm_xtensa_t *as, uint idx); #define ASM_MOV_REG_LOCAL_ADDR(as, reg_dest, local_num) asm_xtensa_mov_reg_local_addr((as), (reg_dest), ASM_NUM_REGS_SAVED + (local_num)) #define ASM_MOV_REG_PCREL(as, reg_dest, label) asm_xtensa_mov_reg_pcrel((as), (reg_dest), (label)) +#define ASM_NEG_REG(as, reg_dest) asm_xtensa_op_neg((as), (reg_dest), (reg_dest)) #define ASM_LSL_REG_REG(as, reg_dest, reg_shift) \ do { \ asm_xtensa_op_ssl((as), (reg_shift)); \ From b50efbd0e319764dab3f49b64519cfea5f2c2bab Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 18 Mar 2024 12:30:09 +1100 Subject: [PATCH 243/408] py/asmxtensa: Optimise asm_xtensa_mov_reg_i32_optimised() for tiny ints. Signed-off-by: Damien George --- py/asmxtensa.c | 4 +++- py/asmxtensa.h | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/py/asmxtensa.c b/py/asmxtensa.c index 84018402f69e9..0fbe351dcf3c7 100644 --- a/py/asmxtensa.c +++ b/py/asmxtensa.c @@ -185,7 +185,9 @@ size_t asm_xtensa_mov_reg_i32(asm_xtensa_t *as, uint reg_dest, uint32_t i32) { } void asm_xtensa_mov_reg_i32_optimised(asm_xtensa_t *as, uint reg_dest, uint32_t i32) { - if (SIGNED_FIT12(i32)) { + if (-32 <= (int)i32 && (int)i32 <= 95) { + asm_xtensa_op_movi_n(as, reg_dest, i32); + } else if (SIGNED_FIT12(i32)) { asm_xtensa_op_movi(as, reg_dest, i32); } else { asm_xtensa_mov_reg_i32(as, reg_dest, i32); diff --git a/py/asmxtensa.h b/py/asmxtensa.h index aef9e74625d3a..f226624a82631 100644 --- a/py/asmxtensa.h +++ b/py/asmxtensa.h @@ -203,8 +203,9 @@ static inline void asm_xtensa_op_movi(asm_xtensa_t *as, uint reg_dest, int32_t i asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRI8(2, 10, (imm12 >> 8) & 0xf, reg_dest, imm12 & 0xff)); } -static inline void asm_xtensa_op_movi_n(asm_xtensa_t *as, uint reg_dest, int imm4) { - asm_xtensa_op16(as, ASM_XTENSA_ENCODE_RI7(12, reg_dest, imm4)); +// Argument must be in the range (-32 .. 95) inclusive. +static inline void asm_xtensa_op_movi_n(asm_xtensa_t *as, uint reg_dest, int imm7) { + asm_xtensa_op16(as, ASM_XTENSA_ENCODE_RI7(12, reg_dest, imm7)); } static inline void asm_xtensa_op_mull(asm_xtensa_t *as, uint reg_dest, uint reg_src_a, uint reg_src_b) { From 3c445f66369a49ba2dfa7e008d0a93c71fb1b6d3 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 18 Mar 2024 12:29:29 +1100 Subject: [PATCH 244/408] py/emitnative: Implement viper unary ops positive, negative and invert. Signed-off-by: Damien George --- py/emitnative.c | 33 +++++++++++++++++++++++----- tests/micropython/viper_error.py | 7 +++--- tests/micropython/viper_error.py.exp | 5 ++--- tests/micropython/viper_unop.py | 31 ++++++++++++++++++++++++++ tests/micropython/viper_unop.py.exp | 9 ++++++++ 5 files changed, 74 insertions(+), 11 deletions(-) create mode 100644 tests/micropython/viper_unop.py create mode 100644 tests/micropython/viper_unop.py.exp diff --git a/py/emitnative.c b/py/emitnative.c index f80461dd42f3b..0b84a2ec8a85d 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -2259,15 +2259,38 @@ static void emit_native_pop_except_jump(emit_t *emit, mp_uint_t label, bool with } static void emit_native_unary_op(emit_t *emit, mp_unary_op_t op) { - vtype_kind_t vtype; - emit_pre_pop_reg(emit, &vtype, REG_ARG_2); - if (vtype == VTYPE_PYOBJ) { + vtype_kind_t vtype = peek_vtype(emit, 0); + if (vtype == VTYPE_INT || vtype == VTYPE_UINT) { + if (op == MP_UNARY_OP_POSITIVE) { + // No-operation, just leave the argument on the stack. + } else if (op == MP_UNARY_OP_NEGATIVE) { + int reg = REG_RET; + emit_pre_pop_reg_flexible(emit, &vtype, ®, reg, reg); + ASM_NEG_REG(emit->as, reg); + emit_post_push_reg(emit, vtype, reg); + } else if (op == MP_UNARY_OP_INVERT) { + #ifdef ASM_NOT_REG + int reg = REG_RET; + emit_pre_pop_reg_flexible(emit, &vtype, ®, reg, reg); + ASM_NOT_REG(emit->as, reg); + #else + int reg = REG_RET; + emit_pre_pop_reg_flexible(emit, &vtype, ®, REG_ARG_1, reg); + ASM_MOV_REG_IMM(emit->as, REG_ARG_1, -1); + ASM_XOR_REG_REG(emit->as, reg, REG_ARG_1); + #endif + emit_post_push_reg(emit, vtype, reg); + } else { + EMIT_NATIVE_VIPER_TYPE_ERROR(emit, + MP_ERROR_TEXT("'not' not implemented"), mp_binary_op_method_name[op]); + } + } else if (vtype == VTYPE_PYOBJ) { + emit_pre_pop_reg(emit, &vtype, REG_ARG_2); emit_call_with_imm_arg(emit, MP_F_UNARY_OP, op, REG_ARG_1); emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } else { - adjust_stack(emit, 1); EMIT_NATIVE_VIPER_TYPE_ERROR(emit, - MP_ERROR_TEXT("unary op %q not implemented"), mp_unary_op_method_name[op]); + MP_ERROR_TEXT("can't do unary op of '%q'"), vtype_to_qstr(vtype)); } } diff --git a/tests/micropython/viper_error.py b/tests/micropython/viper_error.py index 80617af0c1f29..6c5c3ba200702 100644 --- a/tests/micropython/viper_error.py +++ b/tests/micropython/viper_error.py @@ -50,6 +50,9 @@ def f(): # incorrect return type test("@micropython.viper\ndef f() -> int: return []") +# can't do unary op of incompatible type +test("@micropython.viper\ndef f(x:ptr): -x") + # can't do binary op between incompatible types test("@micropython.viper\ndef f(): 1 + []") test("@micropython.viper\ndef f(x:int, y:uint): x < y") @@ -69,9 +72,7 @@ def f(): test("@micropython.viper\ndef f(): raise 1") # unary ops not implemented -test("@micropython.viper\ndef f(x:int): +x") -test("@micropython.viper\ndef f(x:int): -x") -test("@micropython.viper\ndef f(x:int): ~x") +test("@micropython.viper\ndef f(x:int): not x") # binary op not implemented test("@micropython.viper\ndef f(x:uint, y:uint): res = x // y") diff --git a/tests/micropython/viper_error.py.exp b/tests/micropython/viper_error.py.exp index 31c85b1d872af..51cbd6c7097cd 100644 --- a/tests/micropython/viper_error.py.exp +++ b/tests/micropython/viper_error.py.exp @@ -5,6 +5,7 @@ ViperTypeError("local 'x' used before type known",) ViperTypeError("local 'x' has type 'int' but source is 'object'",) ViperTypeError("can't implicitly convert 'ptr' to 'bool'",) ViperTypeError("return expected 'int' but got 'object'",) +ViperTypeError("can't do unary op of 'ptr'",) ViperTypeError("can't do binary op between 'int' and 'object'",) ViperTypeError('comparison of int and uint',) ViperTypeError("can't load from 'int'",) @@ -15,9 +16,7 @@ ViperTypeError("can't store to 'int'",) ViperTypeError("can't store 'None'",) ViperTypeError("can't store 'None'",) ViperTypeError('must raise an object',) -ViperTypeError('unary op __pos__ not implemented',) -ViperTypeError('unary op __neg__ not implemented',) -ViperTypeError('unary op __invert__ not implemented',) +ViperTypeError("'not' not implemented",) ViperTypeError('div/mod not implemented for uint',) ViperTypeError('div/mod not implemented for uint',) ViperTypeError('binary op not implemented',) diff --git a/tests/micropython/viper_unop.py b/tests/micropython/viper_unop.py new file mode 100644 index 0000000000000..61cbd5125f167 --- /dev/null +++ b/tests/micropython/viper_unop.py @@ -0,0 +1,31 @@ +# test unary operators + + +@micropython.viper +def pos(x: int) -> int: + return +x + + +print(pos(0)) +print(pos(1)) +print(pos(-2)) + + +@micropython.viper +def neg(x: int) -> int: + return -x + + +print(neg(0)) +print(neg(1)) +print(neg(-2)) + + +@micropython.viper +def inv(x: int) -> int: + return ~x + + +print(inv(0)) +print(inv(1)) +print(inv(-2)) diff --git a/tests/micropython/viper_unop.py.exp b/tests/micropython/viper_unop.py.exp new file mode 100644 index 0000000000000..6d93312caa136 --- /dev/null +++ b/tests/micropython/viper_unop.py.exp @@ -0,0 +1,9 @@ +0 +1 +-2 +0 +-1 +2 +-1 +-2 +1 From 9651046edd4ebf6e2141f889c6068f4ed565f13f Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 6 Mar 2024 19:01:46 +1100 Subject: [PATCH 245/408] stm32/mboot: Add support for a raw filesystem. This is enabled by default if MBOOT_FSLOAD is enabled, although a board can explicitly disable it by `#define MBOOT_VFS_RAW (0)`. Signed-off-by: Damien George --- ports/stm32/mboot/Makefile | 1 + ports/stm32/mboot/README.md | 16 ++++-- ports/stm32/mboot/fsload.c | 59 +++++++++++++++++++---- ports/stm32/mboot/fwupdate.py | 50 +++++++++++++------ ports/stm32/mboot/mboot.h | 26 ++++++++++ ports/stm32/mboot/vfs.h | 18 +++++++ ports/stm32/mboot/vfs_raw.c | 91 +++++++++++++++++++++++++++++++++++ 7 files changed, 232 insertions(+), 29 deletions(-) create mode 100644 ports/stm32/mboot/vfs_raw.c diff --git a/ports/stm32/mboot/Makefile b/ports/stm32/mboot/Makefile index 389f9f5d0f4ad..07053b3293907 100755 --- a/ports/stm32/mboot/Makefile +++ b/ports/stm32/mboot/Makefile @@ -120,6 +120,7 @@ SRC_C += \ ui.c \ vfs_fat.c \ vfs_lfs.c \ + vfs_raw.c \ drivers/bus/softspi.c \ drivers/bus/softqspi.c \ drivers/memory/spiflash.c \ diff --git a/ports/stm32/mboot/README.md b/ports/stm32/mboot/README.md index 73e32fcedcc97..221e3a7c3acad 100644 --- a/ports/stm32/mboot/README.md +++ b/ports/stm32/mboot/README.md @@ -71,13 +71,23 @@ How to use #define MBOOT_FSLOAD (1) and then enable one or more of the following depending on what filesystem - support is required in Mboot (note that the FAT driver is read-only and - quite compact, but littlefs supports both read and write so is rather - large): + support is required in Mboot: #define MBOOT_VFS_FAT (1) #define MBOOT_VFS_LFS1 (1) #define MBOOT_VFS_LFS2 (1) + #define MBOOT_VFS_RAW (1) + + Note that the FAT and LFS2 drivers are read-only and quite compact, but + LFS1 supports both read and write so is rather large. + + The raw filesystem type is enabled by default and is a flat section of + storage containing a single file without any metadata. The raw filesystem + can either be one regoin, or split over two separate, contiguous regions. + The latter is useful for wear levelling: given a chunk of flash, write the + firmware starting at a random block within that chunk and wrap around to + the beginning of the chunk when the end is reached. Then use a split + raw filesystem to inform mboot of this wrapping. 2. Build the board's main application firmware as usual. diff --git a/ports/stm32/mboot/fsload.c b/ports/stm32/mboot/fsload.c index abc3514ed146c..83905eb491070 100644 --- a/ports/stm32/mboot/fsload.c +++ b/ports/stm32/mboot/fsload.c @@ -39,7 +39,7 @@ #if MBOOT_FSLOAD -#if !(MBOOT_VFS_FAT || MBOOT_VFS_LFS1 || MBOOT_VFS_LFS2) +#if !(MBOOT_VFS_FAT || MBOOT_VFS_LFS1 || MBOOT_VFS_LFS2 || MBOOT_VFS_RAW) #error Must enable at least one VFS component #endif @@ -234,28 +234,51 @@ int fsload_process(void) { // End of elements. return -MBOOT_ERRNO_FSLOAD_NO_MOUNT; } + + // Extract element arguments based on the element length: + // - 10 bytes: mount_point fs_type uint32_t uint32_t + // - 14 bytes: mount_point fs_type uint32_t uint32_t uint32_t + // - 18 bytes: mount_point fs_type uint32_t uint32_t uint32_t uint32_t + // - 22 bytes: mount_point fs_type uint64_t uint64_t uint32_t + // - 34 bytes: mount_point fs_type uint64_t uint64_t uint64_t uint64_t mboot_addr_t base_addr; mboot_addr_t byte_len; - uint32_t block_size = MBOOT_FSLOAD_DEFAULT_BLOCK_SIZE; - if (elem[-1] == 10 || elem[-1] == 14) { + mboot_addr_t arg2 = 0; + mboot_addr_t arg3 = 0; + (void)arg2; + (void)arg3; + uint8_t elem_len = elem[-1]; + if (elem_len == 10 || elem_len == 14 || elem_len == 18) { // 32-bit base and length given, extract them. base_addr = get_le32(&elem[2]); byte_len = get_le32(&elem[6]); - if (elem[-1] == 14) { - // Block size given, extract it. - block_size = get_le32(&elem[10]); + if (elem_len >= 14) { + // Argument 2 given, extract it. + arg2 = get_le32(&elem[10]); + if (elem_len == 18) { + // Argument 3 given, extract it. + arg3 = get_le32(&elem[14]); + } } #if MBOOT_ADDRESS_SPACE_64BIT - } else if (elem[-1] == 22) { - // 64-bit base and length given, and block size, so extract them. + } else if (elem_len == 22 || elem_len == 34) { + // 64-bit base and length given, so extract them. base_addr = get_le64(&elem[2]); byte_len = get_le64(&elem[10]); - block_size = get_le32(&elem[18]); + if (elem_len == 22) { + // 32-bit argument 2 given, extract it. + arg2 = get_le32(&elem[18]); + } else { + // 64-bit argument 2 and 3 given, extract them. + arg2 = get_le64(&elem[18]); + arg3 = get_le64(&elem[26]); + } #endif } else { // Invalid MOUNT element. return -MBOOT_ERRNO_FSLOAD_INVALID_MOUNT; } + if (elem[0] == mount_point) { int ret; union { @@ -268,27 +291,43 @@ int fsload_process(void) { #if MBOOT_VFS_LFS2 vfs_lfs2_context_t lfs2; #endif + #if MBOOT_VFS_RAW + vfs_raw_context_t raw; + #endif } ctx; const stream_methods_t *methods; #if MBOOT_VFS_FAT if (elem[1] == ELEM_MOUNT_FAT) { - (void)block_size; ret = vfs_fat_mount(&ctx.fat, base_addr, byte_len); methods = &vfs_fat_stream_methods; } else #endif #if MBOOT_VFS_LFS1 if (elem[1] == ELEM_MOUNT_LFS1) { + uint32_t block_size = arg2; + if (block_size == 0) { + block_size = MBOOT_FSLOAD_DEFAULT_BLOCK_SIZE; + } ret = vfs_lfs1_mount(&ctx.lfs1, base_addr, byte_len, block_size); methods = &vfs_lfs1_stream_methods; } else #endif #if MBOOT_VFS_LFS2 if (elem[1] == ELEM_MOUNT_LFS2) { + uint32_t block_size = arg2; + if (block_size == 0) { + block_size = MBOOT_FSLOAD_DEFAULT_BLOCK_SIZE; + } ret = vfs_lfs2_mount(&ctx.lfs2, base_addr, byte_len, block_size); methods = &vfs_lfs2_stream_methods; } else #endif + #if MBOOT_VFS_RAW + if (elem[1] == ELEM_MOUNT_RAW) { + ret = vfs_raw_mount(&ctx.raw, base_addr, byte_len, arg2, arg3); + methods = &vfs_raw_stream_methods; + } else + #endif { // Unknown filesystem type return -MBOOT_ERRNO_FSLOAD_INVALID_MOUNT; diff --git a/ports/stm32/mboot/fwupdate.py b/ports/stm32/mboot/fwupdate.py index 47ceb19ba5dae..8578ff4fc9032 100644 --- a/ports/stm32/mboot/fwupdate.py +++ b/ports/stm32/mboot/fwupdate.py @@ -9,6 +9,7 @@ VFS_FAT = 1 VFS_LFS1 = 2 VFS_LFS2 = 3 +VFS_RAW = 4 # Constants for creating mboot elements. _ELEM_TYPE_END = const(1) @@ -226,28 +227,45 @@ def _create_element(kind, body): def update_app_elements( - filename, fs_base, fs_len, fs_type=VFS_FAT, fs_blocksize=0, status_addr=None, addr_64bit=False + filename, + fs_base, + fs_len, + fs_type=VFS_FAT, + fs_blocksize=0, + status_addr=None, + addr_64bit=False, + *, + fs_base2=0, + fs_len2=0, ): - # Check firmware is of .dfu or .dfu.gz type - try: - with open(filename, "rb") as f: - hdr = deflate.DeflateIO(f, deflate.GZIP).read(6) - except Exception: - with open(filename, "rb") as f: - hdr = f.read(6) - if hdr != b"DfuSe\x01": - print("Firmware must be a .dfu(.gz) file.") - return () + if fs_type != VFS_RAW: + # Check firmware is of .dfu or .dfu.gz type + try: + with open(filename, "rb") as f: + hdr = deflate.DeflateIO(f, deflate.GZIP).read(6) + except Exception: + with open(filename, "rb") as f: + hdr = f.read(6) + if hdr != b"DfuSe\x01": + print("Firmware must be a .dfu(.gz) file.") + return () if fs_type in (VFS_LFS1, VFS_LFS2) and not fs_blocksize: raise Exception("littlefs requires fs_blocksize parameter") mount_point = 1 - mount_encoding = "seg0_base_addr = seg0_base_addr; + ctx->seg0_byte_len = seg0_byte_len; + ctx->seg1_base_addr = seg1_base_addr; + ctx->seg1_byte_len = seg1_byte_len; + return 0; +} + +static int vfs_raw_stream_open(void *stream_in, const char *fname) { + vfs_raw_context_t *stream = stream_in; + (void)fname; + stream->file_pos = 0; + return 0; +} + +static void vfs_raw_stream_close(void *stream_in) { + (void)stream_in; +} + +static int vfs_raw_stream_read(void *stream_in, uint8_t *buf, size_t len) { + vfs_raw_context_t *stream = stream_in; + size_t orig_len = len; + while (len) { + mboot_addr_t addr; + mboot_addr_t remain; + if (stream->file_pos < stream->seg0_byte_len) { + // Reading from segment 0. + mboot_addr_t seg0_pos = stream->file_pos; + addr = stream->seg0_base_addr + seg0_pos; + remain = stream->seg0_byte_len - seg0_pos; + } else { + // Reading from segment 1. + mboot_addr_t seg1_pos = stream->file_pos - stream->seg0_byte_len; + addr = stream->seg1_base_addr + seg1_pos; + remain = stream->seg1_byte_len - seg1_pos; + if (!remain) { + // At the end of segment 1. + break; + } + } + size_t l = MIN(len, remain); + hw_read(addr, l, buf); + stream->file_pos += l; + buf += l; + len -= l; + } + return orig_len - len; +} + +const stream_methods_t vfs_raw_stream_methods = { + vfs_raw_stream_open, + vfs_raw_stream_close, + vfs_raw_stream_read, +}; + +#endif // MBOOT_FSLOAD && MBOOT_VFS_RAW From 899592ac341ed9f10ee554424f964f6880fc8c48 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 13 Mar 2024 18:03:19 +1100 Subject: [PATCH 246/408] stm32/boards/LEGO_HUB_NO6: Move robust logic to mboot. Signed-off-by: Damien George --- ports/stm32/boards/LEGO_HUB_NO6/appupdate.py | 12 ------------ ports/stm32/boards/LEGO_HUB_NO6/board_init.c | 9 ++++++++- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/ports/stm32/boards/LEGO_HUB_NO6/appupdate.py b/ports/stm32/boards/LEGO_HUB_NO6/appupdate.py index 02398e81243fc..9cfbc06e56590 100644 --- a/ports/stm32/boards/LEGO_HUB_NO6/appupdate.py +++ b/ports/stm32/boards/LEGO_HUB_NO6/appupdate.py @@ -7,9 +7,6 @@ _IOCTL_BLOCK_COUNT = const(4) _IOCTL_BLOCK_SIZE = const(5) -_SPIFLASH_UPDATE_KEY_ADDR = const(1020 * 1024) -_SPIFLASH_UPDATE_KEY_VALUE = const(0x12345678) - _FILESYSTEM_ADDR = const(0x8000_0000 + 1024 * 1024) # Roundabout way to get actual filesystem size from config. @@ -26,9 +23,6 @@ def update_app(filename): if not elems: return - # Create the update key. - key = struct.pack(" Date: Thu, 14 Mar 2024 10:28:00 +1100 Subject: [PATCH 247/408] stm32/boards/LEGO_HUB_NO6: Use a raw filesystem for mboot to update fw. The C-based SPI flash driver is needed because the `_copy_file_to_raw_filesystem()` function must copy from a filesystem (eg FAT) to another part of flash, and the same C code must be used for both reading (from FAT) and writing (to flash). Signed-off-by: Damien George --- ports/stm32/boards/LEGO_HUB_NO6/appupdate.py | 70 +++++--- ports/stm32/boards/LEGO_HUB_NO6/manifest.py | 1 - ports/stm32/boards/LEGO_HUB_NO6/spiflash.c | 166 +++++++++++++++++++ ports/stm32/boards/LEGO_HUB_NO6/spiflash.py | 90 ---------- 4 files changed, 212 insertions(+), 115 deletions(-) create mode 100644 ports/stm32/boards/LEGO_HUB_NO6/spiflash.c delete mode 100644 ports/stm32/boards/LEGO_HUB_NO6/spiflash.py diff --git a/ports/stm32/boards/LEGO_HUB_NO6/appupdate.py b/ports/stm32/boards/LEGO_HUB_NO6/appupdate.py index 9cfbc06e56590..8229004fbbd0e 100644 --- a/ports/stm32/boards/LEGO_HUB_NO6/appupdate.py +++ b/ports/stm32/boards/LEGO_HUB_NO6/appupdate.py @@ -1,39 +1,61 @@ # Application firmware update function for LEGO_HUB_NO6. -# MIT license; Copyright (c) 2022 Damien P. George +# MIT license; Copyright (c) 2022-2024 Damien P. George from micropython import const -import struct, machine, fwupdate, spiflash, pyb +import random, struct, machine, fwupdate, spiflash, pyb _IOCTL_BLOCK_COUNT = const(4) _IOCTL_BLOCK_SIZE = const(5) -_FILESYSTEM_ADDR = const(0x8000_0000 + 1024 * 1024) - -# Roundabout way to get actual filesystem size from config. -# This takes into account the 1M "reserved" section of the flash memory. -flash = pyb.Flash(start=0) -_FILESYSTEM_LEN = flash.ioctl(_IOCTL_BLOCK_COUNT, None) * flash.ioctl(_IOCTL_BLOCK_SIZE, None) +# Mboot addresses the external SPI flash at this location. +_MBOOT_SPIFLASH_BASE_ADDR = 0x80000000 + +# The raw filesystem is in the first 1MiB of external SPI flash, +# but skip the first and last flash sectors. +_RAW_FILESYSTEM_ADDR = const(4 * 1024) +_RAW_FILESYSTEM_LEN = const(1016 * 1024) + + +def _copy_file_to_raw_filesystem(filename, flash, block): + block_count = flash.ioctl(_IOCTL_BLOCK_COUNT, 0) + block_size = flash.ioctl(_IOCTL_BLOCK_SIZE, 0) + buf = bytearray(block_size) + with open(filename, "rb") as file: + while True: + n = file.readinto(buf) + if not n: + break + flash.writeblocks(block, buf) + block += 1 + if block >= block_count: + print("|", end="") + block = 0 + print(".", end="") + print() def update_app(filename): print(f"Updating application firmware from {filename}") - # Create the elements for the mboot filesystem-load operation. - elems = fwupdate.update_app_elements(filename, _FILESYSTEM_ADDR, _FILESYSTEM_LEN) - if not elems: - return - - # Create a SPI flash object. - spi = machine.SoftSPI( - sck=machine.Pin.board.FLASH_SCK, - mosi=machine.Pin.board.FLASH_MOSI, - miso=machine.Pin.board.FLASH_MISO, - baudrate=50_000_000, - ) - cs = machine.Pin(machine.Pin.board.FLASH_NSS, machine.Pin.OUT, value=1) - # We can't use pyb.Flash() because we need to write to the "reserved" 1M area. - flash = spiflash.SPIFlash(spi, cs) + flash = spiflash.SPIFlash(start=_RAW_FILESYSTEM_ADDR, len=_RAW_FILESYSTEM_LEN) + + # Partition the raw filesystem into two segments for wear levelling. + block_count = flash.ioctl(_IOCTL_BLOCK_COUNT, 0) + block_size = flash.ioctl(_IOCTL_BLOCK_SIZE, 0) + block_start = random.randrange(0, block_count) + print(f"Raw filesystem block layout: 0 .. {block_start} .. {block_count}") + + # Copy the file to the special raw filesystem. + _copy_file_to_raw_filesystem(filename, flash, block_start) # Enter mboot with a request to do a filesystem-load update. - machine.bootloader(elems) + # Note: the filename doesn't mean anything here, but still needs to be non-empty. + fwupdate.update_mpy( + filename, + fs_type=fwupdate.VFS_RAW, + fs_base=_MBOOT_SPIFLASH_BASE_ADDR + _RAW_FILESYSTEM_ADDR + block_start * block_size, + fs_len=(block_count - block_start) * block_size, + fs_base2=_MBOOT_SPIFLASH_BASE_ADDR + _RAW_FILESYSTEM_ADDR, + fs_len2=block_start * block_size, + ) diff --git a/ports/stm32/boards/LEGO_HUB_NO6/manifest.py b/ports/stm32/boards/LEGO_HUB_NO6/manifest.py index 1be4246e37882..afbfdc0a822ce 100644 --- a/ports/stm32/boards/LEGO_HUB_NO6/manifest.py +++ b/ports/stm32/boards/LEGO_HUB_NO6/manifest.py @@ -4,5 +4,4 @@ # Modules for application firmware update. module("fwupdate.py", base_path="$(PORT_DIR)/mboot", opt=3) -module("spiflash.py", opt=3) module("appupdate.py", opt=3) diff --git a/ports/stm32/boards/LEGO_HUB_NO6/spiflash.c b/ports/stm32/boards/LEGO_HUB_NO6/spiflash.c new file mode 100644 index 0000000000000..37df7c9530355 --- /dev/null +++ b/ports/stm32/boards/LEGO_HUB_NO6/spiflash.c @@ -0,0 +1,166 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2024 Damien P. George + * + * 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. + */ + +#if !BUILDING_MBOOT + +#include "py/runtime.h" +#include "extmod/vfs.h" + +#include "storage.h" + +// Expose the entire external SPI flash as an object with the block protocol. + +#define FLASH_SIZE (MICROPY_HW_SPIFLASH_OFFSET_BYTES + MICROPY_HW_SPIFLASH_SIZE_BITS / 8) +#define BLOCK_SIZE (4096) + +typedef struct _spi_flash_obj_t { + mp_obj_base_t base; + uint32_t start; // in bytes + uint32_t len; // in bytes +} spi_flash_obj_t; + +static const mp_obj_type_t spi_flash_type; + +static void spi_flash_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { + spi_flash_obj_t *self = MP_OBJ_TO_PTR(self_in); + mp_printf(print, "SPIFlash(start=%u, len=%u)", self->start, self->len); +} + +static mp_obj_t spi_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { + enum { ARG_start, ARG_len }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_start, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, + { MP_QSTR_len, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + spi_flash_obj_t *self = mp_obj_malloc(spi_flash_obj_t, &spi_flash_type); + + mp_int_t start = args[ARG_start].u_int; + if (!(0 <= start && start < FLASH_SIZE && start % BLOCK_SIZE == 0)) { + mp_raise_ValueError(NULL); + } + + mp_int_t len = args[ARG_len].u_int; + if (len == -1) { + len = FLASH_SIZE - start; + } else if (!(0 < len && start + len <= FLASH_SIZE && len % BLOCK_SIZE == 0)) { + mp_raise_ValueError(NULL); + } + + self->start = start; + self->len = len; + + return MP_OBJ_FROM_PTR(self); +} + +static mp_obj_t spi_flash_readblocks(size_t n_args, const mp_obj_t *args) { + spi_flash_obj_t *self = MP_OBJ_TO_PTR(args[0]); + uint32_t block_num = self->start / BLOCK_SIZE + mp_obj_get_int(args[1]); + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_WRITE); + int ret = spi_bdev_readblocks_raw(&spi_bdev, bufinfo.buf, block_num, 0, bufinfo.len); + return MP_OBJ_NEW_SMALL_INT(ret); +} +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(spi_flash_readblocks_obj, 3, 3, spi_flash_readblocks); + +static mp_obj_t spi_flash_writeblocks(size_t n_args, const mp_obj_t *args) { + spi_flash_obj_t *self = MP_OBJ_TO_PTR(args[0]); + uint32_t block_num = self->start / BLOCK_SIZE + mp_obj_get_int(args[1]); + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_READ); + int ret = spi_bdev_eraseblocks_raw(&spi_bdev, block_num, bufinfo.len); + if (ret == 0) { + ret = spi_bdev_writeblocks_raw(&spi_bdev, bufinfo.buf, block_num, 0, bufinfo.len); + } + return MP_OBJ_NEW_SMALL_INT(ret); +} +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(spi_flash_writeblocks_obj, 3, 3, spi_flash_writeblocks); + +static mp_obj_t spi_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_in) { + spi_flash_obj_t *self = MP_OBJ_TO_PTR(self_in); + + mp_int_t cmd = mp_obj_get_int(cmd_in); + switch (cmd) { + case MP_BLOCKDEV_IOCTL_INIT: + storage_init(); + return MP_OBJ_NEW_SMALL_INT(0); + + case MP_BLOCKDEV_IOCTL_DEINIT: + return MP_OBJ_NEW_SMALL_INT(0); + + case MP_BLOCKDEV_IOCTL_SYNC: + return MP_OBJ_NEW_SMALL_INT(0); + + case MP_BLOCKDEV_IOCTL_BLOCK_COUNT: { + mp_int_t n = self->len / BLOCK_SIZE; + return MP_OBJ_NEW_SMALL_INT(n); + } + + case MP_BLOCKDEV_IOCTL_BLOCK_SIZE: + return MP_OBJ_NEW_SMALL_INT(BLOCK_SIZE); + + default: + return mp_const_none; + } +} +static MP_DEFINE_CONST_FUN_OBJ_3(spi_flash_ioctl_obj, spi_flash_ioctl); + +static const mp_rom_map_elem_t spi_flash_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&spi_flash_readblocks_obj) }, + { MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&spi_flash_writeblocks_obj) }, + { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&spi_flash_ioctl_obj) }, +}; +static MP_DEFINE_CONST_DICT(spi_flash_locals_dict, spi_flash_locals_dict_table); + +static MP_DEFINE_CONST_OBJ_TYPE( + spi_flash_type, + MP_QSTR_SPIFlash, + MP_TYPE_FLAG_NONE, + make_new, spi_flash_make_new, + print, spi_flash_print, + locals_dict, &spi_flash_locals_dict + ); + +/******************************************************************************/ +// The `spiflash` module. + +static const mp_rom_map_elem_t spiflash_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_spiflash) }, + + { MP_ROM_QSTR(MP_QSTR_SPIFlash), MP_ROM_PTR(&spi_flash_type) }, +}; +static MP_DEFINE_CONST_DICT(spiflash_module_globals, spiflash_module_globals_table); + +const mp_obj_module_t spiflash_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&spiflash_module_globals, +}; + +MP_REGISTER_MODULE(MP_QSTR_spiflash, spiflash_module); + +#endif diff --git a/ports/stm32/boards/LEGO_HUB_NO6/spiflash.py b/ports/stm32/boards/LEGO_HUB_NO6/spiflash.py deleted file mode 100644 index e483ace950842..0000000000000 --- a/ports/stm32/boards/LEGO_HUB_NO6/spiflash.py +++ /dev/null @@ -1,90 +0,0 @@ -# MicroPython driver for SPI flash -# MIT license; Copyright (c) 2022 Damien P. George - -from micropython import const - -_PAGE_SIZE = const(256) # maximum bytes writable in one SPI transfer -_CMD_WRITE = const(0x02) -_CMD_READ = const(0x03) -_CMD_RDSR = const(0x05) -_CMD_WREN = const(0x06) -_CMD_WRITE_32 = const(0x12) -_CMD_READ_32 = const(0x13) -_CMD_SEC_ERASE = const(0x20) -_CMD_SEC_ERASE_32 = const(0x21) -_CMD_JEDEC_ID = const(0x9F) - - -class SPIFlash: - def __init__(self, spi, cs): - self.spi = spi - self.cs = cs - self.id = self._get_id() - # flash chip on Hub No. 6 uses 32-bit addressing - _32_bit = self.id == b"\xef\x40\x19" - self._READ = _CMD_READ_32 if _32_bit else _CMD_READ - self._WRITE = _CMD_WRITE_32 if _32_bit else _CMD_WRITE - self._ERASE = _CMD_SEC_ERASE_32 if _32_bit else _CMD_SEC_ERASE - - def _get_id(self): - self.cs(0) - self.spi.write(bytearray([_CMD_JEDEC_ID])) - buf = self.spi.read(3) - self.cs(1) - return buf - - def _wait_wel1(self): - # wait WEL=1 - self.cs(0) - self.spi.write(bytearray([_CMD_RDSR])) - buf = bytearray(1) - while True: - self.spi.readinto(buf) - if buf[0] & 2: - break - self.cs(1) - - def _wait_wip0(self): - # wait WIP=0 - self.cs(0) - self.spi.write(bytearray([_CMD_RDSR])) - buf = bytearray(1) - while True: - self.spi.readinto(buf) - if not (buf[0] & 1): - break - self.cs(1) - - def _flash_modify(self, cmd, addr, buf): - self.cs(0) - self.spi.write(bytearray([_CMD_WREN])) - self.cs(1) - self._wait_wel1() - self.cs(0) - self.spi.write(bytearray([cmd, addr >> 24, addr >> 16, addr >> 8, addr])) - if buf: - self.spi.write(buf) - self.cs(1) - self._wait_wip0() - - def erase_block(self, addr): - self._flash_modify(self._ERASE, addr, None) - - def readinto(self, addr, buf): - self.cs(0) - self.spi.write(bytearray([self._READ, addr >> 16, addr >> 8, addr])) - self.spi.readinto(buf) - self.cs(1) - - def write(self, addr, buf): - offset = addr & (_PAGE_SIZE - 1) - remain = len(buf) - buf = memoryview(buf) - buf_offset = 0 - while remain: - l = min(_PAGE_SIZE - offset, remain) - self._flash_modify(self._WRITE, addr, buf[buf_offset : buf_offset + l]) - remain -= l - addr += l - buf_offset += l - offset = 0 From 1c6012b0b5c62f18130217f30e73ad3ce4c8c9e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20D=C3=B6rre?= Date: Tue, 10 Oct 2023 16:13:24 +0000 Subject: [PATCH 248/408] extmod/modnetwork: Implement IPv6 API to set and get NIC configuration. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit implements a new .ipconfig() function for the NIC classes that use lwIP, to set and retrieve network configuration for a NIC. Currently this method supports: - ipconfig("addr4"): obtain a tuple (addr, netmask) of the currently configured ipv4 address - ipconfig("addr6"): obtain a list of tuples (addr, state, prefered_lifetime, valid_lifetime) of all currently active ipv6 addresses; this includes static, slaac and link-local addresses - ipconfig("has_dhcp4"): whether ipv4 dhcp has supplied an address - ipconfig("has_autoconf6"): if there is a valid, non-static ipv6 address - ipconfig(addr4="1.2.3.4/24"): to set the ipv4 address and netmask - ipconfig(addr6="2a01::2"): to set a static ipv6 address; note that this does not configure an interface route, as this does not seem supported by lwIP - ipconfig(autoconf6=True): to enable ipv6 network configuration with slaac - ipconfig(gw4="1.2.3.1"): to set the ipv4 gateway - ipconfig(dhcp4=True): enable ipv4 dhcp; this sets ipv4 address, netmask, gateway and a dns server - ipconfig(dhcp4=False): stops dhcp, releases the ip, and clears the configured ipv4 address. - ipconfig(dhcp6=True): enable stateless dhcpv6 to obtain a dns server There is also a new global configuration function network.ipconfig() that supports the following: - network.ipconfig(dns="2a01::2"): set the primary dns server (can be a ipv4 or ipv6 address) - network.ipconfig(prefer=6): to prefer ipv6 addresses to be returned as dns responses (falling back to ipv4 if the host does not have an ipv6 address); note that this does not flush the dns cache, so if a host is already in the dns cache with its v4 address, subsequent lookups will return that address even if prefer=6 is set This interface replaces NIC.ifconfig() completely, and ifconfig() should be marked as deprecated and removed in a future version. Signed-off-by: Felix Dörre --- extmod/modlwip.c | 11 +- extmod/modnetwork.c | 7 + extmod/modnetwork.h | 8 + extmod/network_cyw43.c | 7 + extmod/network_esp_hosted.c | 8 + extmod/network_lwip.c | 296 ++++++++++++++++++++++++++++++++++++ extmod/network_wiznet5k.c | 9 ++ 7 files changed, 345 insertions(+), 1 deletion(-) diff --git a/extmod/modlwip.c b/extmod/modlwip.c index 607143bb7e4c6..d4e25917a67b8 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -38,6 +38,7 @@ #if MICROPY_PY_LWIP #include "shared/netutils/netutils.h" +#include "modnetwork.h" #include "lwip/init.h" #include "lwip/tcp.h" @@ -353,8 +354,12 @@ static void lwip_socket_free_incoming(lwip_socket_obj_t *socket) { } } +#if LWIP_VERSION_MAJOR < 2 +#define IPADDR_STRLEN_MAX 46 +#endif mp_obj_t lwip_format_inet_addr(const ip_addr_t *ip, mp_uint_t port) { - char *ipstr = ipaddr_ntoa(ip); + char ipstr[IPADDR_STRLEN_MAX]; + ipaddr_ntoa_r(ip, ipstr, sizeof(ipstr)); mp_obj_t tuple[2] = { tuple[0] = mp_obj_new_str(ipstr, strlen(ipstr)), tuple[1] = mp_obj_new_int(port), @@ -1750,7 +1755,11 @@ static mp_obj_t lwip_getaddrinfo(size_t n_args, const mp_obj_t *args) { state.status = 0; MICROPY_PY_LWIP_ENTER + #if LWIP_VERSION_MAJOR < 2 err_t ret = dns_gethostbyname(host, (ip_addr_t *)&state.ipaddr, lwip_getaddrinfo_cb, &state); + #else + err_t ret = dns_gethostbyname_addrtype(host, (ip_addr_t *)&state.ipaddr, lwip_getaddrinfo_cb, &state, mp_mod_network_prefer_dns_use_ip_version == 4 ? LWIP_DNS_ADDRTYPE_IPV4_IPV6 : LWIP_DNS_ADDRTYPE_IPV6_IPV4); + #endif MICROPY_PY_LWIP_EXIT switch (ret) { diff --git a/extmod/modnetwork.c b/extmod/modnetwork.c index c8d2b9e3ff40a..aa237bd93c15f 100644 --- a/extmod/modnetwork.c +++ b/extmod/modnetwork.c @@ -141,10 +141,17 @@ mp_obj_t mod_network_hostname(size_t n_args, const mp_obj_t *args) { } static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_network_hostname_obj, 0, 1, mod_network_hostname); +#if LWIP_VERSION_MAJOR >= 2 +MP_DEFINE_CONST_FUN_OBJ_KW(mod_network_ipconfig_obj, 0, mod_network_ipconfig); +#endif + static const mp_rom_map_elem_t mp_module_network_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_network) }, { MP_ROM_QSTR(MP_QSTR_country), MP_ROM_PTR(&mod_network_country_obj) }, { MP_ROM_QSTR(MP_QSTR_hostname), MP_ROM_PTR(&mod_network_hostname_obj) }, + #if LWIP_VERSION_MAJOR >= 2 + { MP_ROM_QSTR(MP_QSTR_ipconfig), MP_ROM_PTR(&mod_network_ipconfig_obj) }, + #endif // Defined per port in mpconfigport.h #ifdef MICROPY_PORT_NETWORK_INTERFACES diff --git a/extmod/modnetwork.h b/extmod/modnetwork.h index 0a7897faaa90f..2ff9ce09dea18 100644 --- a/extmod/modnetwork.h +++ b/extmod/modnetwork.h @@ -69,10 +69,18 @@ extern char mod_network_hostname_data[MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN + 1]; mp_obj_t mod_network_hostname(size_t n_args, const mp_obj_t *args); #if MICROPY_PY_LWIP + +#include "lwip/init.h" + struct netif; void mod_network_lwip_init(void); void mod_network_lwip_poll_wrapper(uint32_t ticks_ms); mp_obj_t mod_network_nic_ifconfig(struct netif *netif, size_t n_args, const mp_obj_t *args); +#if LWIP_VERSION_MAJOR >= 2 +mp_obj_t mod_network_ipconfig(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs); +mp_obj_t mod_network_nic_ipconfig(struct netif *netif, size_t n_args, const mp_obj_t *args, mp_map_t *kwargs); +extern int mp_mod_network_prefer_dns_use_ip_version; +#endif #elif defined(MICROPY_PORT_NETWORK_INTERFACES) struct _mod_network_socket_obj_t; diff --git a/extmod/network_cyw43.c b/extmod/network_cyw43.c index 89e68e248836e..d3543c5260435 100644 --- a/extmod/network_cyw43.c +++ b/extmod/network_cyw43.c @@ -321,6 +321,12 @@ static mp_obj_t network_cyw43_ifconfig(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_cyw43_ifconfig_obj, 1, 2, network_cyw43_ifconfig); +static mp_obj_t network_cyw43_ipconfig(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { + network_cyw43_obj_t *self = MP_OBJ_TO_PTR(args[0]); + return mod_network_nic_ipconfig(&self->cyw->netif[self->itf], n_args - 1, args + 1, kwargs); +} +static MP_DEFINE_CONST_FUN_OBJ_KW(network_cyw43_ipconfig_obj, 1, network_cyw43_ipconfig); + static mp_obj_t network_cyw43_status(size_t n_args, const mp_obj_t *args) { network_cyw43_obj_t *self = MP_OBJ_TO_PTR(args[0]); (void)self; @@ -532,6 +538,7 @@ static const mp_rom_map_elem_t network_cyw43_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_disconnect), MP_ROM_PTR(&network_cyw43_disconnect_obj) }, { MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&network_cyw43_isconnected_obj) }, { MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&network_cyw43_ifconfig_obj) }, + { MP_ROM_QSTR(MP_QSTR_ipconfig), MP_ROM_PTR(&network_cyw43_ipconfig_obj) }, { MP_ROM_QSTR(MP_QSTR_status), MP_ROM_PTR(&network_cyw43_status_obj) }, { MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&network_cyw43_config_obj) }, diff --git a/extmod/network_esp_hosted.c b/extmod/network_esp_hosted.c index 14e8be8b6a4e4..f86eaad37ca0f 100644 --- a/extmod/network_esp_hosted.c +++ b/extmod/network_esp_hosted.c @@ -204,6 +204,13 @@ static mp_obj_t network_esp_hosted_ifconfig(size_t n_args, const mp_obj_t *args) } static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_esp_hosted_ifconfig_obj, 1, 2, network_esp_hosted_ifconfig); +static mp_obj_t network_esp_hosted_ipconfig(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { + esp_hosted_obj_t *self = MP_OBJ_TO_PTR(args[0]); + void *netif = esp_hosted_wifi_get_netif(self->itf); + return mod_network_nic_ipconfig(netif, n_args - 1, args + 1, kwargs); +} +static MP_DEFINE_CONST_FUN_OBJ_KW(network_esp_hosted_ipconfig_obj, 1, network_esp_hosted_ipconfig); + static mp_obj_t network_esp_hosted_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { esp_hosted_obj_t *self = MP_OBJ_TO_PTR(args[0]); @@ -299,6 +306,7 @@ static const mp_rom_map_elem_t network_esp_hosted_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_disconnect), MP_ROM_PTR(&network_esp_hosted_disconnect_obj) }, { MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&network_esp_hosted_isconnected_obj) }, { MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&network_esp_hosted_ifconfig_obj) }, + { MP_ROM_QSTR(MP_QSTR_ipconfig), MP_ROM_PTR(&network_esp_hosted_ipconfig_obj) }, { MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&network_esp_hosted_config_obj) }, { MP_ROM_QSTR(MP_QSTR_status), MP_ROM_PTR(&network_esp_hosted_status_obj) }, { MP_ROM_QSTR(MP_QSTR_OPEN), MP_ROM_INT(ESP_HOSTED_SEC_OPEN) }, diff --git a/extmod/network_lwip.c b/extmod/network_lwip.c index caa30f6fff4d2..97cb43902df63 100644 --- a/extmod/network_lwip.c +++ b/extmod/network_lwip.c @@ -26,6 +26,7 @@ #include "py/runtime.h" #include "py/mphal.h" +#include "py/parsenum.h" #if MICROPY_PY_NETWORK && MICROPY_PY_LWIP @@ -40,9 +41,19 @@ #include "lwip/timeouts.h" #include "lwip/dns.h" #include "lwip/dhcp.h" +#include "lwip/nd6.h" +#include "lwip/dhcp6.h" +#include "lwip/prot/dhcp.h" +#include "lwip/prot/dhcp6.h" +#include +#include + +int mp_mod_network_prefer_dns_use_ip_version = 4; // Implementations of network methods that can be used by any interface. +// This function provides the implementation of nic.ifconfig, is deprecated and will be removed. +// Use network.ipconfig and nic.ipconfig instead. mp_obj_t mod_network_nic_ifconfig(struct netif *netif, size_t n_args, const mp_obj_t *args) { if (n_args == 0) { // Get IP addresses @@ -90,6 +101,291 @@ mp_obj_t mod_network_nic_ifconfig(struct netif *netif, size_t n_args, const mp_o } } +// This function provides the common implementation of network.ipconfig +mp_obj_t mod_network_ipconfig(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { + if (kwargs->used == 0) { + // Get config value + if (n_args != 1) { + mp_raise_TypeError(MP_ERROR_TEXT("must query one param")); + } + + switch (mp_obj_str_get_qstr(args[0])) { + case MP_QSTR_dns: { + char addr_str[IPADDR_STRLEN_MAX]; + ipaddr_ntoa_r(dns_getserver(0), addr_str, sizeof(addr_str)); + return mp_obj_new_str(addr_str, strlen(addr_str)); + } + case MP_QSTR_prefer: { + return MP_OBJ_NEW_SMALL_INT(mp_mod_network_prefer_dns_use_ip_version); + } + default: { + mp_raise_ValueError(MP_ERROR_TEXT("unexpected key")); + break; + } + } + } else { + // Set config value(s) + if (n_args != 0) { + mp_raise_TypeError(MP_ERROR_TEXT("can't specify pos and kw args")); + } + + for (size_t i = 0; i < kwargs->alloc; ++i) { + if (MP_MAP_SLOT_IS_FILLED(kwargs, i)) { + mp_map_elem_t *e = &kwargs->table[i]; + switch (mp_obj_str_get_qstr(e->key)) { + case MP_QSTR_dns: { + ip_addr_t dns; + size_t addr_len; + const char *addr_str = mp_obj_str_get_data(e->value, &addr_len); + if (!ipaddr_aton(addr_str, &dns)) { + mp_raise_ValueError(MP_ERROR_TEXT("invalid arguments as dns server")); + } + dns_setserver(0, &dns); + break; + } + case MP_QSTR_prefer: { + int value = mp_obj_get_int(e->value); + if (value != 4 && value != 6) { + mp_raise_ValueError(MP_ERROR_TEXT("invalid prefer argument")); + } + mp_mod_network_prefer_dns_use_ip_version = value; + break; + } + default: { + mp_raise_ValueError(MP_ERROR_TEXT("unexpected key")); + break; + } + } + } + } + } + return mp_const_none; +} + +mp_obj_t mod_network_nic_ipconfig(struct netif *netif, size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { + + if (kwargs->used == 0) { + // Get config value + if (n_args != 1) { + mp_raise_TypeError(MP_ERROR_TEXT("must query one param")); + } + + switch (mp_obj_str_get_qstr(args[0])) { + case MP_QSTR_dhcp4: { + struct dhcp *dhcp = netif_dhcp_data(netif); + return mp_obj_new_bool(dhcp != NULL && dhcp->state != DHCP_STATE_OFF); + } + case MP_QSTR_has_dhcp4: { + return mp_obj_new_bool(dhcp_supplied_address(netif)); + } + #if LWIP_IPV6_DHCP6 + case MP_QSTR_dhcp6: { + struct dhcp6 *dhcp = netif_dhcp6_data(netif); + return mp_obj_new_bool(dhcp != NULL && dhcp->state != DHCP6_STATE_OFF); + } + #endif + #if LWIP_IPV6_AUTOCONFIG + case MP_QSTR_autoconf6: { + return netif->ip6_autoconfig_enabled ? mp_const_true : mp_const_false; + } + case MP_QSTR_has_autoconf6: { + int found = 0; + for (int i = 1; i < LWIP_IPV6_NUM_ADDRESSES; i++) { + if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) && + !netif_ip6_addr_isstatic(netif, i)) { + found = 1; + break; + } + } + if (found) { + break; + } + return mp_obj_new_bool(found); + } + #endif + case MP_QSTR_addr4: { + mp_obj_t tuple[2] = { + netutils_format_ipv4_addr((uint8_t *)&netif->ip_addr, NETUTILS_BIG), + netutils_format_ipv4_addr((uint8_t *)&netif->netmask, NETUTILS_BIG), + }; + return mp_obj_new_tuple(2, tuple); + } + #if LWIP_IPV6 + case MP_QSTR_addr6: { + mp_obj_t addrs[LWIP_IPV6_NUM_ADDRESSES]; + size_t n_addrs = 0; + for (int i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) { + if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i))) { + char addr_str[IPADDR_STRLEN_MAX]; + ipaddr_ntoa_r(netif_ip_addr6(netif, i), addr_str, sizeof(addr_str)); + mp_obj_t tuple[4] = { + mp_obj_new_str(addr_str, strlen(addr_str)), + MP_OBJ_NEW_SMALL_INT(netif_ip6_addr_state(netif, i)), + MP_OBJ_NEW_SMALL_INT(netif_ip6_addr_pref_life(netif, i)), // preferred + MP_OBJ_NEW_SMALL_INT(netif_ip6_addr_valid_life(netif, i)) + }; + addrs[n_addrs++] = mp_obj_new_tuple(4, tuple); + } + } + return mp_obj_new_list(n_addrs, addrs); + } + #endif + case MP_QSTR_gw4: { + return netutils_format_ipv4_addr((uint8_t *)&netif->gw, NETUTILS_BIG); + } + default: { + mp_raise_ValueError(MP_ERROR_TEXT("unexpected key")); + break; + } + } + return mp_const_none; + } else { + // Set config value(s) + if (n_args != 0) { + mp_raise_TypeError(MP_ERROR_TEXT("can't specify pos and kw args")); + } + + for (size_t i = 0; i < kwargs->alloc; ++i) { + if (MP_MAP_SLOT_IS_FILLED(kwargs, i)) { + mp_map_elem_t *e = &kwargs->table[i]; + switch (mp_obj_str_get_qstr(e->key)) { + case MP_QSTR_dhcp4: { + if (mp_obj_is_true(e->value)) { + if (dhcp_supplied_address(netif)) { + dhcp_renew(netif); + } else { + dhcp_release_and_stop(netif); + dhcp_start(netif); + } + } else { + dhcp_release_and_stop(netif); + } + break; + } + #if LWIP_IPV6_DHCP6 + case MP_QSTR_dhcp6: { + dhcp6_disable(netif); + dhcp6_enable_stateless(netif); + break; + } + #endif + #if LWIP_IPV6_AUTOCONFIG + case MP_QSTR_autoconf6: { + netif_set_ip6_autoconfig_enabled(netif, mp_obj_is_true(e->value)); + if (mp_obj_is_true(e->value)) { + nd6_restart_netif(netif); + } else { + // Clear out any non-static addresses, skip link-local address in slot 0 + for (i = 1; i < LWIP_IPV6_NUM_ADDRESSES; i++) { + if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) && + !netif_ip6_addr_isstatic(netif, i)) { + netif_ip6_addr_set_state(netif, i, IP6_ADDR_INVALID); + } + } + } + break; + } + #endif + case MP_QSTR_addr4: + case MP_QSTR_addr6: { + ip_addr_t ip_addr; + ip_addr_t netmask; + int prefix_bits = 32; + if (e->value != mp_const_none && mp_obj_is_str(e->value)) { + size_t addr_len; + const char *input_str = mp_obj_str_get_data(e->value, &addr_len); + char plain_ip[IPADDR_STRLEN_MAX]; + char *split = strchr(input_str, '/'); + const char *addr_str = input_str; + if (split) { + int to_copy = sizeof(plain_ip) - 1; + if (split - addr_str < to_copy) { + to_copy = split - addr_str; + } + memcpy(plain_ip, addr_str, to_copy); + mp_obj_t prefix_obj = mp_parse_num_integer(split + 1, strlen(split + 1), 10, NULL); + prefix_bits = mp_obj_get_int(prefix_obj); + } + if (mp_obj_str_get_qstr(args[0]) == MP_QSTR_addr4) { + uint32_t mask = -(1u << (32 - prefix_bits)); + ip_addr_set_ip4_u32_val(netmask, ((mask & 0xFF) << 24) | ((mask & 0xFF00) << 8) | ((mask >> 8) & 0xFF00) | ((mask >> 24) & 0xFF)); + } + if (!ipaddr_aton(addr_str, &ip_addr)) { + mp_raise_ValueError(MP_ERROR_TEXT("invalid arguments")); + } + if ((mp_obj_str_get_qstr(args[0]) == MP_QSTR_addr6) != IP_IS_V6(&ip_addr) + || (mp_obj_str_get_qstr(args[0]) == MP_QSTR_addr4) != IP_IS_V4(&ip_addr)) { + mp_raise_ValueError(MP_ERROR_TEXT("invalid address type")); + } + } else if (e->value != mp_const_none) { + mp_obj_t *items; + mp_obj_get_array_fixed_n(e->value, 2, &items); + size_t addr_len; + const char *ip_addr_str = mp_obj_str_get_data(items[0], &addr_len); + const char *netmask_str = mp_obj_str_get_data(items[1], &addr_len); + if (!ipaddr_aton(ip_addr_str, &ip_addr)) { + mp_raise_ValueError(MP_ERROR_TEXT("invalid arguments")); + } + if (!ipaddr_aton(netmask_str, &netmask)) { + mp_raise_ValueError(MP_ERROR_TEXT("invalid arguments")); + } + if (!IP_IS_V4(&ip_addr) || !IP_IS_V4(&netmask)) { + mp_raise_ValueError(MP_ERROR_TEXT("invalid address type")); + } + } + if (mp_obj_str_get_qstr(args[0]) == MP_QSTR_addr4) { + if (e->value != mp_const_none) { + netif->ip_addr = ip_addr; + netif->netmask = netmask; + } else { + ip4_addr_set_any(ip_2_ip4(&netif->ip_addr)); + ip4_addr_set_any(ip_2_ip4(&netif->netmask)); + } + #if LWIP_IPV6 + } else if (mp_obj_str_get_qstr(args[0]) == MP_QSTR_addr6) { + // Clear out any existing static addresses. Address 0 comes from autoconf. + for (i = 1; i < LWIP_IPV6_NUM_ADDRESSES; i++) { + if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) && + netif_ip6_addr_isstatic(netif, i)) { + netif_ip6_addr_set_state(netif, i, IP6_ADDR_INVALID); + } + } + if (e->value != mp_const_none) { + s8_t free_idx; + netif_add_ip6_address(netif, ip_2_ip6(&ip_addr), &free_idx); + netif_ip6_addr_set_valid_life(netif, free_idx, IP6_ADDR_LIFE_STATIC); + netif_ip6_addr_set_pref_life(netif, free_idx, IP6_ADDR_LIFE_STATIC); + netif_ip6_addr_set_state(netif, free_idx, IP6_ADDR_PREFERRED); + } + #endif + } + break; + } + case MP_QSTR_gw4: { + ip_addr_t ip_addr; + size_t addr_len; + const char *addr_str = mp_obj_str_get_data(e->value, &addr_len); + if (!ipaddr_aton(addr_str, &ip_addr)) { + mp_raise_ValueError(MP_ERROR_TEXT("invalid arguments")); + } + if (IP_IS_V4(&ip_addr)) { + netif->gw = ip_addr; + } else { + mp_raise_ValueError(MP_ERROR_TEXT("invalid address type")); + } + break; + } + default: { + mp_raise_ValueError(MP_ERROR_TEXT("unexpected key")); + break; + } + } + } + } + } + return mp_const_none; +} + #endif // LWIP_VERSION_MAJOR >= 2 #endif // MICROPY_PY_NETWORK && MICROPY_PY_LWIP diff --git a/extmod/network_wiznet5k.c b/extmod/network_wiznet5k.c index d1aadc3e15584..b550f8c1f45f2 100644 --- a/extmod/network_wiznet5k.c +++ b/extmod/network_wiznet5k.c @@ -915,6 +915,12 @@ static mp_obj_t wiznet5k_ifconfig(size_t n_args, const mp_obj_t *args) { } static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wiznet5k_ifconfig_obj, 1, 2, wiznet5k_ifconfig); +static mp_obj_t network_wiznet5k_ipconfig(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { + wiznet5k_obj_t *self = MP_OBJ_TO_PTR(args[0]); + return mod_network_nic_ipconfig(&self->netif, n_args - 1, args + 1, kwargs); +} +static MP_DEFINE_CONST_FUN_OBJ_KW(wiznet5k_ipconfig_obj, 1, network_wiznet5k_ipconfig); + static mp_obj_t send_ethernet_wrapper(mp_obj_t self_in, mp_obj_t buf_in) { wiznet5k_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_buffer_info_t buf; @@ -1008,6 +1014,9 @@ static const mp_rom_map_elem_t wiznet5k_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&wiznet5k_isconnected_obj) }, { MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&wiznet5k_active_obj) }, { MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&wiznet5k_ifconfig_obj) }, + #if WIZNET5K_WITH_LWIP_STACK + { MP_ROM_QSTR(MP_QSTR_ipconfig), MP_ROM_PTR(&wiznet5k_ipconfig_obj) }, + #endif { MP_ROM_QSTR(MP_QSTR_status), MP_ROM_PTR(&wiznet5k_status_obj) }, { MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&wiznet5k_config_obj) }, #if WIZNET5K_WITH_LWIP_STACK From 77f08b72caeb26c7e3be5975d976e77d44099d43 Mon Sep 17 00:00:00 2001 From: Nicko van Someren Date: Thu, 28 Dec 2023 14:22:40 -0700 Subject: [PATCH 249/408] docs/library/rp2.DMA: Add documentation for rp2 DMA support. Signed-off-by: Nicko van Someren --- docs/library/rp2.DMA.rst | 293 ++++++++++++++++++++++++++++++ docs/library/rp2.StateMachine.rst | 7 + docs/library/rp2.rst | 1 + 3 files changed, 301 insertions(+) create mode 100644 docs/library/rp2.DMA.rst diff --git a/docs/library/rp2.DMA.rst b/docs/library/rp2.DMA.rst new file mode 100644 index 0000000000000..c5e3f31aa2ed6 --- /dev/null +++ b/docs/library/rp2.DMA.rst @@ -0,0 +1,293 @@ +.. currentmodule:: rp2 +.. _rp2.DMA: + +class DMA -- access to the RP2040's DMA controller +================================================== + +The :class:`DMA` class offers access to the RP2040's Direct Memory Access (DMA) +controller, providing the ability move data between memory blocks and/or IO registers. The DMA +controller has its own, separate read and write bus master connections onto the bus fabric and +each DMA channel can independently read data from one address and write it back to another +address, optionally incrementing one or both pointers, allowing it to perform transfers on behalf +of the processor while the processor carries out other tasks or enters a low power state. The +RP2040's DMA controller has 12 independent DMA channels that can run concurrently. For full +details of the RP2040's DMA system see section 2.5 of the `RP2040 Datasheet +`_. + +Examples +-------- + +The simplest use of the DMA controller is to move data from one block of memory to another. +This can be accomplished with the following code:: + + a = bytearray(32*1024) + b = bytearray(32*1024) + d = rp2.DMA() + c = d.pack_ctrl() # Just use the default control value. + # The count is in 'transfers', which defaults to four-byte words, so divide length by 4 + d.config(read=a, write=b, count=len(a)//4, ctrl=c, trigger=True) + # Wait for completion + while d.active(): + pass + +Note that while this example sits in an idle loop while it waits for the transfer to complete, +the program could just as well do some useful work in this time instead. + +Another, perhaps more common use of the DMA controller is to transfer between memory and an IO +peripheral. In this situation the address of the IO register does not change for each transfer but +the memory address needs to be incremented. It is also necessary to control the pace of the +transfer so as to not write data before it can be accepted by a peripheral or read it before the +data is ready, and this can be controlled with the ``treq_sel`` field of the DMA channel's control +register. The various fields of the control register for each DMA channel can be packed +using the :meth:`DMA.pack_ctrl()` method and unpacked using the :meth:`DMA.unpack_ctrl()` +static method. Code to transfer data from a byte array to the TX FIFO of a PIO state machine, +one byte at a time, looks like this:: + + # pio_num is index of the PIO block being used, sm_num is the state machine in that block. + # my_state_machine is an rp2.PIO() instance. + DATA_REQUEST_INDEX = (pio_num << 3) + sm_num + + src_data = bytearray(1024) + d = rp2.DMA() + + # Transfer bytes, rather than words, don't increment the write address and pace the transfer. + c = d.pack_ctrl(size=0, inc_write=False, treq_sel=DATA_REQUEST_INDEX) + + d.config( + read=src_data, + write=my_state_machine, + count=len(src_data), + ctrl=c, + trigger=True + ) + +Note that in this example the value given for the write address is just the PIO state machine to +which we are sending the data. This works because PIO state machines present the buffer protocol, +allowing direct access to their data FIFO registers. + +Constructor +----------- + +.. class:: DMA() + + Claim one of the DMA controller channels for exclusive use. + +Methods +------- + +.. method:: DMA.config(read=None, write=None, count=None, ctrl=None, trigger=False) + + Configure the DMA registers for the channel and optionally start the transfer. + Parameters are: + + - *read*: The address from which the DMA controller will start reading data or + an object that will provide data to be read. It can be an integer or any + object that supports the buffer protocol. + - *write*: The address to which the DMA controller will start writing or an + object into which data will be written. It can be an integer or any object + that supports the buffer protocol. + - *count*: The number of bus transfers that will execute before this channel + stops. Note that this is the number of transfers, not the number of bytes. + If the transfers are 2 or 4 bytes wide then the total amount of data moved + (and thus the size of required buffer) needs to be multiplied accordingly. + - *ctrl*: The value for the DMA control register. This is an integer value + that is typically packed using the :meth:`DMA.pack_ctrl()`. + - *trigger*: Optionally commence the transfer immediately. + +.. method:: DMA.irq(handler=None, hard=False) + + Returns the IRQ object for this DMA channel and optionally configures it. + +.. method:: DMA.close() + + Release the claim on the underlying DMA channel and free the interrupt + handler. The :class:`DMA` object can not be used after this operation. + +.. method:: DMA.pack_ctrl(default=None, **kwargs) + + Pack the values provided in the keyword arguments into the named fields of a new control + register value. Any field that is not provided will be set to a default value. The + default will either be taken from the provided ``default`` value, or if that is not + given, a default suitable for the current channel; setting this to the current value + of the `DMA.ctrl` attribute provides an easy way to override a subset of the fields. + + The keys for the keyword arguments can be any key returned by the :meth:`DMA.unpack_ctrl()` + method. The writable values are: + + - *enable*: ``bool`` Set to enable the channel (default: ``True``). + + - *high_pri*: ``bool`` Make this channel's bus traffic high priority (default: ``False``). + + - *size*: ``int`` Transfer size: 0=byte, 1=half word, 2=word (default: 2). + + - *inc_read*: ``bool`` Increment the read address after each transfer (default: ``True``). + + - *inc_write*: ``bool`` Increment the write address after each transfer (default: ``True``). + + - *ring_size*: ``int`` If non-zero, only the bottom ``ring_size`` bits of one + address register will change when an address is incremented, causing the + address to wrap at the next ``1 << ring_size`` byte boundary. Which + address is wrapped is controlled by the ``ring_sel`` flag. A zero value + disables address wrapping. + + - *ring_sel*: ``bool`` Set to ``False`` to have the ``ring_size`` apply to the read address + or ``True`` to apply to the write address. + + - *chain_to*: ``int`` The channel number for a channel to trigger after this transfer + completes. Setting this value to this DMA object's own channel number + disables chaining (this is the default). + + - *treq_sel*: ``int`` Select a Transfer Request signal. See section 2.5.3 in the RP2040 + datasheet for details. + + - *irq_quiet*: ``bool`` Do not generate interrupt at the end of each transfer. Interrupts + will instead be generated when a zero value is written to the trigger + register, which will halt a sequence of chained transfers (default: + ``True``). + + - *bswap*: ``bool`` If set to true, bytes in words or half-words will be reversed before + writing (default: ``True``). + + - *sniff_en*: ``bool`` Set to ``True`` to allow data to be accessed by the chips sniff + hardware (default: ``False``). + + - *write_err*: ``bool`` Setting this to ``True`` will clear a previously reported write + error. + + - *read_err*: ``bool`` Setting this to ``True`` will clear a previously reported read + error. + + See the description of the ``CH0_CTRL_TRIG`` register in section 2.5.7 of the RP2040 + datasheet for details of all of these fields. + +.. method:: DMA.unpack_ctrl(value) + + Unpack a value for a DMA channel control register into a dictionary with key/value pairs + for each of the fields in the control register. *value* is the ``ctrl`` register value + to unpack. + + This method will return values for all the keys that can be passed to ``DMA.pack_ctrl``. + In addition, it will also return the read-only flags in the control register: ``busy``, + which goes high when a transfer starts and low when it ends, and ``ahb_err``, which is + the logical OR of the ``read_err`` and ``write_err`` flags. These values will be ignored + when packing, so that the dictionary created by unpacking a control register can be used + directly as the keyword arguments for packing. + +.. method:: DMA.active([value]) + + Gets or sets whether the DMA channel is currently running. + + >>> sm.active() + 0 + >>> sm.active(1) + >>> while sm.active(): + ... pass + +Attributes +---------- + +.. attribute:: DMA.read + + This attribute reflects the address from which the next bus transfer + will read. It may be written with either an integer or an object + that supports the buffer protocol and doing so has immediate effect. + +.. attribute:: DMA.write + + This attribute reflects the address to which the next bus transfer + will write. It may be written with either an integer or an object + that supports the buffer protocol and doing so has immediate effect. + +.. attribute:: DMA.count + + Reading this attribute will return the number of remaining bus + transfers in the *current* transfer sequence. Writing this attribute + sets the total number of transfers to be the *next* transfer sequence. + +.. attribute:: DMA.ctrl + + This attribute reflects DMA channel control register. It is typically written + with an integer packed using the :meth:`DMA.pack_ctrl()` method. The returned + register value can be unpacked using the :meth:`DMA.unpack_ctrl()` method. + +.. attribute:: DMA.channel + + The channel number of the DMA channel. This can be passed in the ``chain_to`` + argument of `DMA.pack_ctrl()` on another channel to allow DMA chaining. + +.. attribute:: DMA.registers + + This attribute is an array-like object that allows direct access to + the DMA channel's registers. The index is by word, rather than by byte, + so the register indices are the register address offsets divided by 4. + See the RP2040 data sheet for register details. + +Chaining and trigger register access +------------------------------------ + +The DMA controller in the RP2040 offers a couple advanced features to allow one DMA channel +to initiate a transfer on another channel. One is the use of the ``chain_to`` value in the +control register and the other is writing to one of the DMA channel's registers that has a +trigger effect. When coupled with the ability to have one DMA channel write directly to the +`DMA.registers` of another channel, this allows for complex transactions to be performed +without any CPU intervention. + +Below is an example of using both chaining and register +triggering to implement gathering of multiple blocks of data into a single destination. Full +details of these features can be found in section 2.5 of the RP2040 data sheet and the code +below is a Pythonic version of the example in sub-section 2.5.6.2. + +.. code-block:: python + + from rp2 import DMA + from uctypes import addressof + from array import array + + def gather_strings(string_list, buf): + # We use two DMA channels. The first sends lengths and source addresses from the gather + # list to the registers of the second. The second copies the data itself. + gather_dma = DMA() + buffer_dma = DMA() + + # Pack up length/address pairs to be sent to the registers. + gather_list = array("I") + + for s in string_list: + gather_list.append(len(s)) + gather_list.append(addressof(s)) + + gather_list.append(0) + gather_list.append(0) + + # When writing to the registers of the second DMA channel, we need to wrap the + # write address on an 8-byte (1<<3 bytes) boundary. We write to the ``TRANS_COUNT`` + # and ``READ_ADD_TRIG`` registers in the last register alias (registers 14 and 15). + gather_ctrl = gather_dma.pack_ctrl(ring_size=3, ring_sel=True) + gather_dma.config( + read=gather_list, write=buffer_dma.registers[14:16], + count=2, ctrl=gather_ctrl + ) + + # When copying the data, the transfer size is single bytes, and when completed we need + # to chain back to the start another gather DMA transaction. + buffer_ctrl = buffer_dma.pack_ctrl(size=0, chain_to=gather_dma.channel) + # The read and count values will be set by the other DMA channel. + buffer_dma.config(write=buf, ctrl=buffer_ctrl) + + # Set the transfer in motion. + gather_dma.active(1) + + # Wait until all the register values have been sent + end_address = addressof(gather_list) + 4 * len(gather_list) + while gather_dma.read != end_address: + pass + + input = ["This is ", "a ", "test", " of the scatter", " gather", " process"] + output = bytearray(64) + + print(output) + gather_strings(input, output) + print(output) + +This example idles while waiting for the transfer to complete; alternatively it could +set an interrupt handler and return immediately. diff --git a/docs/library/rp2.StateMachine.rst b/docs/library/rp2.StateMachine.rst index e8c167c09f573..1cb87e90b6e2d 100644 --- a/docs/library/rp2.StateMachine.rst +++ b/docs/library/rp2.StateMachine.rst @@ -140,3 +140,10 @@ Methods Optionally configure it. +Buffer protocol +--------------- + +The StateMachine class supports the `buffer protocol`, allowing direct access to the transmit +and receive FIFOs for each state machine. This is primarily in order to allow StateMachine +objects to be passed directly as the read or write parameters when configuring a `rp2.DMA()` +channel. diff --git a/docs/library/rp2.rst b/docs/library/rp2.rst index 7a473387b4a81..f0189327dfb77 100644 --- a/docs/library/rp2.rst +++ b/docs/library/rp2.rst @@ -241,6 +241,7 @@ Classes .. toctree:: :maxdepth: 1 + rp2.DMA.rst rp2.Flash.rst rp2.PIO.rst rp2.StateMachine.rst From e520fa2e0fb3cfafe27a1f9e7e9b230dd58d7a33 Mon Sep 17 00:00:00 2001 From: Matthias Urlichs Date: Wed, 25 Oct 2023 19:17:47 +0200 Subject: [PATCH 250/408] py/binary: Support half-float 'e' format in struct pack/unpack. This commit implements the 'e' half-float format: 10-bit mantissa, 5-bit exponent. It uses native _Float16 if supported by the compiler, otherwise uses custom bitshifting encoding/decoding routines. Signed-off-by: Matthias Urlichs Signed-off-by: Damien George --- docs/library/struct.rst | 2 + py/binary.c | 109 +++++++++++++++++++++++++++++++++++- py/mpconfig.h | 9 +++ tests/float/float_struct.py | 2 +- 4 files changed, 119 insertions(+), 3 deletions(-) diff --git a/docs/library/struct.rst b/docs/library/struct.rst index 026cb5e8ac3b4..c2357505960d7 100644 --- a/docs/library/struct.rst +++ b/docs/library/struct.rst @@ -45,6 +45,8 @@ The following data types are supported: +--------+--------------------+-------------------+---------------+ | Q | unsigned long long | integer (`1`) | 8 | +--------+--------------------+-------------------+---------------+ +| e | n/a (half-float) | float (`2`) | 2 | ++--------+--------------------+-------------------+---------------+ | f | float | float (`2`) | 4 | +--------+--------------------+-------------------+---------------+ | d | double | float (`2`) | 8 | diff --git a/py/binary.c b/py/binary.c index 4c8b6ffcdc49a..7c01cfa1c8284 100644 --- a/py/binary.c +++ b/py/binary.c @@ -74,11 +74,14 @@ size_t mp_binary_get_size(char struct_type, char val_type, size_t *palign) { case 'S': size = sizeof(void *); break; + case 'e': + size = 2; + break; case 'f': - size = sizeof(float); + size = 4; break; case 'd': - size = sizeof(double); + size = 8; break; } break; @@ -122,6 +125,10 @@ size_t mp_binary_get_size(char struct_type, char val_type, size_t *palign) { align = alignof(void *); size = sizeof(void *); break; + case 'e': + align = 2; + size = 2; + break; case 'f': align = alignof(float); size = sizeof(float); @@ -144,6 +151,99 @@ size_t mp_binary_get_size(char struct_type, char val_type, size_t *palign) { return size; } +#if MICROPY_PY_BUILTINS_FLOAT && MICROPY_FLOAT_USE_NATIVE_FLT16 + +static inline float mp_decode_half_float(uint16_t hf) { + union { + uint16_t i; + _Float16 f; + } fpu = { .i = hf }; + return fpu.f; +} + +static inline uint16_t mp_encode_half_float(float x) { + union { + uint16_t i; + _Float16 f; + } fp_sp = { .f = (_Float16)x }; + return fp_sp.i; +} + +#elif MICROPY_PY_BUILTINS_FLOAT + +static float mp_decode_half_float(uint16_t hf) { + union { + uint32_t i; + float f; + } fpu; + + uint16_t m = hf & 0x3ff; + int e = (hf >> 10) & 0x1f; + if (e == 0x1f) { + // Half-float is infinity. + e = 0xff; + } else if (e) { + // Half-float is normal. + e += 127 - 15; + } else if (m) { + // Half-float is subnormal, make it normal. + e = 127 - 15; + while (!(m & 0x400)) { + m <<= 1; + --e; + } + m -= 0x400; + ++e; + } + + fpu.i = ((hf & 0x8000) << 16) | (e << 23) | (m << 13); + return fpu.f; +} + +static uint16_t mp_encode_half_float(float x) { + union { + uint32_t i; + float f; + } fpu = { .f = x }; + + uint16_t m = (fpu.i >> 13) & 0x3ff; + if (fpu.i & (1 << 12)) { + // Round up. + ++m; + } + int e = (fpu.i >> 23) & 0xff; + + if (e == 0xff) { + // Infinity. + e = 0x1f; + } else if (e != 0) { + e -= 127 - 15; + if (e < 0) { + // Underflow: denormalized, or zero. + if (e >= -11) { + m = (m | 0x400) >> -e; + if (m & 1) { + m = (m >> 1) + 1; + } else { + m >>= 1; + } + } else { + m = 0; + } + e = 0; + } else if (e > 0x3f) { + // Overflow: infinity. + e = 0x1f; + m = 0; + } + } + + uint16_t bits = ((fpu.i >> 16) & 0x8000) | (e << 10) | m; + return bits; +} + +#endif + mp_obj_t mp_binary_get_val_array(char typecode, void *p, size_t index) { mp_int_t val = 0; switch (typecode) { @@ -240,6 +340,8 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte *p_base, byte * const char *s_val = (const char *)(uintptr_t)(mp_uint_t)val; return mp_obj_new_str(s_val, strlen(s_val)); #if MICROPY_PY_BUILTINS_FLOAT + } else if (val_type == 'e') { + return mp_obj_new_float_from_f(mp_decode_half_float(val)); } else if (val_type == 'f') { union { uint32_t i; @@ -309,6 +411,9 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte *p val = (mp_uint_t)val_in; break; #if MICROPY_PY_BUILTINS_FLOAT + case 'e': + val = mp_encode_half_float(mp_obj_get_float_to_f(val_in)); + break; case 'f': { union { uint32_t i; diff --git a/py/mpconfig.h b/py/mpconfig.h index cb0f050a74bd8..d9cff930d1485 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -830,6 +830,15 @@ typedef double mp_float_t; #define MICROPY_PY_BUILTINS_COMPLEX (MICROPY_PY_BUILTINS_FLOAT) #endif +// Whether to use the native _Float16 for 16-bit float support +#ifndef MICROPY_FLOAT_USE_NATIVE_FLT16 +#ifdef __FLT16_MAX__ +#define MICROPY_FLOAT_USE_NATIVE_FLT16 (1) +#else +#define MICROPY_FLOAT_USE_NATIVE_FLT16 (0) +#endif +#endif + // Whether to provide a high-quality hash for float and complex numbers. // Otherwise the default is a very simple but correct hashing function. #ifndef MICROPY_FLOAT_HIGH_QUALITY_HASH diff --git a/tests/float/float_struct.py b/tests/float/float_struct.py index 47fe405018038..6e282a6afe3ee 100644 --- a/tests/float/float_struct.py +++ b/tests/float/float_struct.py @@ -8,7 +8,7 @@ i = 1.0 + 1 / 2 # TODO: it looks like '=' format modifier is not yet supported # for fmt in ('f', 'd', '>f', '>d', 'f", ">d", "e", ">f", ">d", " Date: Tue, 19 Mar 2024 22:56:38 +1100 Subject: [PATCH 251/408] stm32/stm32.mk: Enable _Float16 support on MCUs with hardware floats. Signed-off-by: Damien George --- ports/stm32/stm32.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/stm32/stm32.mk b/ports/stm32/stm32.mk index b9f70db73e0a1..718fa8cf0679d 100644 --- a/ports/stm32/stm32.mk +++ b/ports/stm32/stm32.mk @@ -44,14 +44,14 @@ ifneq ($(BUILDING_MBOOT),1) SUPPORTS_HARDWARE_FP_SINGLE = 0 SUPPORTS_HARDWARE_FP_DOUBLE = 0 ifeq ($(CMSIS_MCU),$(filter $(CMSIS_MCU),STM32F765xx STM32F767xx STM32F769xx STM32H743xx STM32H747xx STM32H750xx STM32H7A3xx STM32H7A3xxQ STM32H7B3xx STM32H7B3xxQ)) -CFLAGS_CORTEX_M += -mfpu=fpv5-d16 -mfloat-abi=hard +CFLAGS_CORTEX_M += -mfpu=fpv5-d16 -mfloat-abi=hard -mfp16-format=ieee SUPPORTS_HARDWARE_FP_SINGLE = 1 SUPPORTS_HARDWARE_FP_DOUBLE = 1 else ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f0 g0 l0 l1 wl)) CFLAGS_CORTEX_M += -msoft-float else -CFLAGS_CORTEX_M += -mfpu=fpv4-sp-d16 -mfloat-abi=hard +CFLAGS_CORTEX_M += -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mfp16-format=ieee SUPPORTS_HARDWARE_FP_SINGLE = 1 endif endif From b80607ecafeb47664b35e4f255ed43171719ecf5 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 19 Mar 2024 23:09:11 +1100 Subject: [PATCH 252/408] unix/variants: Don't use native _Float16 type. Using it increases code size by about 2k. Signed-off-by: Damien George --- ports/unix/variants/mpconfigvariant_common.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ports/unix/variants/mpconfigvariant_common.h b/ports/unix/variants/mpconfigvariant_common.h index 981babca9f10b..2e34055bf773f 100644 --- a/ports/unix/variants/mpconfigvariant_common.h +++ b/ports/unix/variants/mpconfigvariant_common.h @@ -41,6 +41,11 @@ #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE) #endif +// Don't use native _Float16 because it increases code size by a lot. +#ifndef MICROPY_FLOAT_USE_NATIVE_FLT16 +#define MICROPY_FLOAT_USE_NATIVE_FLT16 (0) +#endif + // Enable arbitrary precision long-int by default. #ifndef MICROPY_LONGINT_IMPL #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ) From 9d27183bde0a70521a0d189636e53975df2260eb Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 20 Mar 2024 13:30:22 +1100 Subject: [PATCH 253/408] tests/float/float_struct_e.py: Add specific test for struct 'e' type. Signed-off-by: Damien George --- tests/float/float_struct_e.py | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/float/float_struct_e.py diff --git a/tests/float/float_struct_e.py b/tests/float/float_struct_e.py new file mode 100644 index 0000000000000..403fbc5db4cde --- /dev/null +++ b/tests/float/float_struct_e.py @@ -0,0 +1,43 @@ +# Test struct pack/unpack with 'e' typecode. + +try: + import struct +except ImportError: + print("SKIP") + raise SystemExit + +test_values = ( + 1e-7, + 2e-7, + 1e-6, + 1e-5, + 1e-4, + 1e-3, + 1e-2, + 0.1, + 0, + 1, + 2, + 4, + 8, + 10, + 100, + 1e3, + 1e4, + 6e4, + float("inf"), +) + +for j in test_values: + for i in (j, -j): + x = struct.pack(" Date: Wed, 20 Mar 2024 16:19:33 +1100 Subject: [PATCH 254/408] py/parse: Zero out dangling parse tree pointer to fix potential GC leak. This fixes a bug where a random Python object may become un-garbage-collectable until an enclosing Python file (compiled on device) finishes executing. Details: The mp_parse_tree_t structure is stored on the stack in top-level functions such as parse_compile_execute() in pyexec.c (and others). Although it quickly falls out of scope in these functions, it is usually still in the current stack frame when the compiled code executes. (Compiler dependent, but usually it's one stack push per function.) This means if any Python object happens to allocate at the same address as the (freed) root parse tree chunk, it's un-garbage-collectable as there's a (dangling) pointer up the stack referencing this same address. As reported by @GitHubsSilverBullet here: https://github.com/orgs/micropython/discussions/14116#discussioncomment-8837214 This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- py/parse.c | 1 + 1 file changed, 1 insertion(+) diff --git a/py/parse.c b/py/parse.c index 54be8b97d092d..1392303e6ff97 100644 --- a/py/parse.c +++ b/py/parse.c @@ -1386,6 +1386,7 @@ void mp_parse_tree_clear(mp_parse_tree_t *tree) { m_del(byte, chunk, sizeof(mp_parse_chunk_t) + chunk->alloc); chunk = next; } + tree->chunk = NULL; // Avoid dangling pointer that may live on stack } #endif // MICROPY_ENABLE_COMPILER From acbdbcd95e6d953b08f0642a844c1808323e0b7c Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Thu, 21 Mar 2024 15:46:41 +1100 Subject: [PATCH 255/408] esp32: Workaround IDF issue placing ISR ringbuf functions in IRAM. This workaround makes sure that all ringbuf functions that may be called from an ISR are placed in IRAM. See https://github.com/espressif/esp-idf/issues/13378 Note that this means that all esp32-og builds get non-ISR ringbuf functions placed in flash now, whereas previously it was just the spiram variant. This might be a good thing (e.g. free up some IRAM for native/viper). Fixes issue #14005. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- ports/esp32/boards/sdkconfig.spiram | 2 +- ports/esp32/esp32_common.cmake | 2 ++ ports/esp32/main_esp32/linker.lf | 39 +++++++++++++++++++++++++++++ ports/esp32/main_esp32c3/linker.lf | 1 + ports/esp32/main_esp32s2/linker.lf | 1 + ports/esp32/main_esp32s3/linker.lf | 1 + 6 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 ports/esp32/main_esp32/linker.lf create mode 100644 ports/esp32/main_esp32c3/linker.lf create mode 100644 ports/esp32/main_esp32s2/linker.lf create mode 100644 ports/esp32/main_esp32s3/linker.lf diff --git a/ports/esp32/boards/sdkconfig.spiram b/ports/esp32/boards/sdkconfig.spiram index f5503d554149c..35fe3c676ddf4 100644 --- a/ports/esp32/boards/sdkconfig.spiram +++ b/ports/esp32/boards/sdkconfig.spiram @@ -13,6 +13,6 @@ CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=8192 # to PSRAM bug workarounds. Apply some options to reduce the firmware size. CONFIG_COMPILER_OPTIMIZATION_SIZE=y CONFIG_COMPILER_OPTIMIZATION_CHECKS_SILENT=y -CONFIG_RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y +# CONFIG_RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y # Workaround required: see main_esp32/linker.lf CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH=y CONFIG_FREERTOS_PLACE_SNAPSHOT_FUNS_INTO_FLASH=y diff --git a/ports/esp32/esp32_common.cmake b/ports/esp32/esp32_common.cmake index a3637870f4fe3..89e46f9cfb3df 100644 --- a/ports/esp32/esp32_common.cmake +++ b/ports/esp32/esp32_common.cmake @@ -151,6 +151,8 @@ idf_component_register( ${MICROPY_PORT_DIR} ${MICROPY_BOARD_DIR} ${CMAKE_BINARY_DIR} + LDFRAGMENTS + linker.lf REQUIRES ${IDF_COMPONENTS} ) diff --git a/ports/esp32/main_esp32/linker.lf b/ports/esp32/main_esp32/linker.lf new file mode 100644 index 0000000000000..e00cd63f5548d --- /dev/null +++ b/ports/esp32/main_esp32/linker.lf @@ -0,0 +1,39 @@ +# This fixes components/esp_ringbuf/linker.lf to allow us to put non-ISR ringbuf functions in flash. + +# Requires that both RINGBUF_PLACE_FUNCTIONS_INTO_FLASH and RINGBUF_PLACE_ISR_FUNCTIONS_INTO_FLASH +# are set to "n" (which is the default), otherwise this would result in duplicate section config +# when resolving the linker fragments. + +# The effect of this file is to leave the ISR functions in RAM (which we require), but apply a fixed +# version of RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y (leaving out prvGetFreeSize and prvGetCurMaxSizeByteBuf) +# See https://github.com/espressif/esp-idf/issues/13378 + +[mapping:esp_ringbuf_fix] +archive: libesp_ringbuf.a +entries: + # This is exactly the list of functions from RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y, + # but with prvGetFreeSize and prvGetCurMaxSizeByteBuf removed. + ringbuf: prvGetCurMaxSizeNoSplit (default) + ringbuf: prvGetCurMaxSizeAllowSplit (default) + ringbuf: prvInitializeNewRingbuffer (default) + ringbuf: prvReceiveGeneric (default) + ringbuf: vRingbufferDelete (default) + ringbuf: vRingbufferGetInfo (default) + ringbuf: vRingbufferReturnItem (default) + ringbuf: xRingbufferAddToQueueSetRead (default) + ringbuf: xRingbufferCanRead (default) + ringbuf: xRingbufferCreate (default) + ringbuf: xRingbufferCreateStatic (default) + ringbuf: xRingbufferCreateNoSplit (default) + ringbuf: xRingbufferReceive (default) + ringbuf: xRingbufferReceiveSplit (default) + ringbuf: xRingbufferReceiveUpTo (default) + ringbuf: xRingbufferRemoveFromQueueSetRead (default) + ringbuf: xRingbufferSend (default) + ringbuf: xRingbufferSendAcquire (default) + ringbuf: xRingbufferSendComplete (default) + ringbuf: xRingbufferPrintInfo (default) + ringbuf: xRingbufferGetMaxItemSize (default) + ringbuf: xRingbufferGetCurFreeSize (default) + + # Everything else will have the default rule already applied (i.e. noflash_text). diff --git a/ports/esp32/main_esp32c3/linker.lf b/ports/esp32/main_esp32c3/linker.lf new file mode 100644 index 0000000000000..31c5b4563ca9a --- /dev/null +++ b/ports/esp32/main_esp32c3/linker.lf @@ -0,0 +1 @@ +# Empty linker fragment (no workaround required for C3, see main_esp32/linker.lf). diff --git a/ports/esp32/main_esp32s2/linker.lf b/ports/esp32/main_esp32s2/linker.lf new file mode 100644 index 0000000000000..3c496fa878b3f --- /dev/null +++ b/ports/esp32/main_esp32s2/linker.lf @@ -0,0 +1 @@ +# Empty linker fragment (no workaround required for S2, see main_esp32/linker.lf). diff --git a/ports/esp32/main_esp32s3/linker.lf b/ports/esp32/main_esp32s3/linker.lf new file mode 100644 index 0000000000000..81d27906be0e4 --- /dev/null +++ b/ports/esp32/main_esp32s3/linker.lf @@ -0,0 +1 @@ +# Empty linker fragment (no workaround required for S3, see main_esp32/linker.lf). From 2b8e88c563e4bab53e3183d15f04795d645eea28 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 24 Jun 2023 17:02:58 +1000 Subject: [PATCH 256/408] py/compile: Add option to allow compiling top-level await. Enabled by MICROPY_COMPILE_ALLOW_TOP_LEVEL_AWAIT. When enabled, this means that scope such as module-level functions and REPL statements can yield. The outer C code must then handle this yielded generator. Signed-off-by: Damien George --- py/compile.c | 13 +++++++++++-- py/compile.h | 5 +++++ py/mpconfig.h | 5 +++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/py/compile.c b/py/compile.c index 7a359e662e731..62757de3c083c 100644 --- a/py/compile.c +++ b/py/compile.c @@ -196,6 +196,10 @@ typedef struct _compiler_t { mp_emit_common_t emit_common; } compiler_t; +#if MICROPY_COMP_ALLOW_TOP_LEVEL_AWAIT +bool mp_compile_allow_top_level_await = false; +#endif + /******************************************************************************/ // mp_emit_common_t helper functions // These are defined here so they can be inlined, to reduce code size. @@ -2759,8 +2763,13 @@ static void compile_yield_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { #if MICROPY_PY_ASYNC_AWAIT static void compile_atom_expr_await(compiler_t *comp, mp_parse_node_struct_t *pns) { if (comp->scope_cur->kind != SCOPE_FUNCTION && comp->scope_cur->kind != SCOPE_LAMBDA) { - compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("'await' outside function")); - return; + #if MICROPY_COMP_ALLOW_TOP_LEVEL_AWAIT + if (!mp_compile_allow_top_level_await) + #endif + { + compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("'await' outside function")); + return; + } } compile_atom_expr_normal(comp, pns); compile_yield_from(comp); diff --git a/py/compile.h b/py/compile.h index 5e0fd8b31c4a8..f9970a521d644 100644 --- a/py/compile.h +++ b/py/compile.h @@ -30,6 +30,11 @@ #include "py/parse.h" #include "py/emitglue.h" +#if MICROPY_COMP_ALLOW_TOP_LEVEL_AWAIT +// set to `true` to allow top-level await expressions +extern bool mp_compile_allow_top_level_await; +#endif + // the compiler will raise an exception if an error occurred // the compiler will clear the parse tree before it returns // mp_globals_get() will be used for the context diff --git a/py/mpconfig.h b/py/mpconfig.h index d9cff930d1485..af2480266bcab 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -446,6 +446,11 @@ #define MICROPY_DYNAMIC_COMPILER (0) #endif +// Whether the compiler allows compiling top-level await expressions +#ifndef MICROPY_COMP_ALLOW_TOP_LEVEL_AWAIT +#define MICROPY_COMP_ALLOW_TOP_LEVEL_AWAIT (0) +#endif + // Whether to enable constant folding; eg 1+2 rewritten as 3 #ifndef MICROPY_COMP_CONST_FOLDING #define MICROPY_COMP_CONST_FOLDING (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES) From ff15dfcaa84dc7d29b9e791f01eaba21dbc2fd72 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 15 Apr 2023 09:27:43 +1000 Subject: [PATCH 257/408] webassembly: Include lib in sys.path. Following other ports. Signed-off-by: Damien George --- ports/webassembly/main.c | 1 + ports/webassembly/qstrdefsport.h | 1 + 2 files changed, 2 insertions(+) diff --git a/ports/webassembly/main.c b/ports/webassembly/main.c index 0aacf1ee095be..1b053046bfb99 100644 --- a/ports/webassembly/main.c +++ b/ports/webassembly/main.c @@ -105,6 +105,7 @@ void mp_js_init(int heap_size) { mp_vfs_mount(2, args, (mp_map_t *)&mp_const_empty_map); MP_STATE_VM(vfs_cur) = MP_STATE_VM(vfs_mount_table); } + mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib)); #endif } diff --git a/ports/webassembly/qstrdefsport.h b/ports/webassembly/qstrdefsport.h index 00d3e2ae3c555..472d05f4375f6 100644 --- a/ports/webassembly/qstrdefsport.h +++ b/ports/webassembly/qstrdefsport.h @@ -1,2 +1,3 @@ // qstrs specific to this port // *FORMAT-OFF* +Q(/lib) From 8282bd93a2381dcc235ee89093832bb5e76e8102 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 30 May 2023 13:13:39 +1000 Subject: [PATCH 258/408] webassembly: Move MP_JS_EPOCH init to library postset. This eliminates the need for wrapper.js to run to set up the time. Signed-off-by: Damien George --- ports/webassembly/library.js | 7 ++++--- ports/webassembly/wrapper.js | 2 -- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/ports/webassembly/library.js b/ports/webassembly/library.js index 009b0a4dcc20c..f554f681c9332 100644 --- a/ports/webassembly/library.js +++ b/ports/webassembly/library.js @@ -35,9 +35,10 @@ mergeInto(LibraryManager.library, { } }, - mp_js_ticks_ms: function() { - return Date.now() - MP_JS_EPOCH; - }, + // This string will be emitted directly into the output file by Emscripten. + mp_js_ticks_ms__postset: "var MP_JS_EPOCH = Date.now()", + + mp_js_ticks_ms: () => Date.now() - MP_JS_EPOCH, mp_js_hook: function() { if (ENVIRONMENT_IS_NODE) { diff --git a/ports/webassembly/wrapper.js b/ports/webassembly/wrapper.js index e63abfffe4ae9..399801b7afcb9 100644 --- a/ports/webassembly/wrapper.js +++ b/ports/webassembly/wrapper.js @@ -33,8 +33,6 @@ var mainProgram = function() mp_js_init_repl = Module.cwrap('mp_js_init_repl', 'null', ['null']); mp_js_process_char = Module.cwrap('mp_js_process_char', 'number', ['number'], {async: true}); - MP_JS_EPOCH = Date.now(); - if (typeof window === 'undefined' && require.main === module) { var fs = require('fs'); var heap_size = 128 * 1024; From 76898cbfa1b8c48ec5f2ac75bc060675895bb67a Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 13 Dec 2023 13:10:03 +1100 Subject: [PATCH 259/408] webassembly: Implement MICROPY_PY_RANDOM_SEED_INIT_FUNC. Signed-off-by: Damien George --- ports/webassembly/library.h | 1 + ports/webassembly/library.js | 7 +++++++ ports/webassembly/mpconfigport.h | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/ports/webassembly/library.h b/ports/webassembly/library.h index 47982e064007a..21027c1372f0e 100644 --- a/ports/webassembly/library.h +++ b/ports/webassembly/library.h @@ -29,3 +29,4 @@ extern void mp_js_write(const char *str, mp_uint_t len); extern int mp_js_ticks_ms(void); extern void mp_js_hook(void); +extern uint32_t mp_js_random_u32(void); diff --git a/ports/webassembly/library.js b/ports/webassembly/library.js index f554f681c9332..4a17942bb4e83 100644 --- a/ports/webassembly/library.js +++ b/ports/webassembly/library.js @@ -63,4 +63,11 @@ mergeInto(LibraryManager.library, { } } }, + + // Node prior to v19 did not expose "crypto" as a global, so make sure it exists. + mp_js_random_u32__postset: + "if (globalThis.crypto === undefined) { globalThis.crypto = require('crypto'); }", + + mp_js_random_u32: () => + globalThis.crypto.getRandomValues(new Uint32Array(1))[0], }); diff --git a/ports/webassembly/mpconfigport.h b/ports/webassembly/mpconfigport.h index e0d1af0cce2bd..43a029c530ca8 100644 --- a/ports/webassembly/mpconfigport.h +++ b/ports/webassembly/mpconfigport.h @@ -49,6 +49,8 @@ #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE) #define MICROPY_USE_INTERNAL_ERRNO (1) #define MICROPY_USE_INTERNAL_PRINTF (0) + +#define MICROPY_PY_RANDOM_SEED_INIT_FUNC (mp_js_random_u32()) #ifndef MICROPY_VFS #define MICROPY_VFS (1) #endif @@ -95,3 +97,5 @@ typedef long mp_off_t; // _GNU_SOURCE must be defined to get definitions of DT_xxx symbols from dirent.h. #define _GNU_SOURCE #endif + +uint32_t mp_js_random_u32(void); From 8e3b701dee944582739adfa9a97de8ea76911a80 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 13 Dec 2023 13:48:32 +1100 Subject: [PATCH 260/408] webassembly: Enable time localtime, gmtime, time, time_ns. Signed-off-by: Damien George --- ports/webassembly/Makefile | 1 + ports/webassembly/library.h | 1 + ports/webassembly/library.js | 2 ++ ports/webassembly/modtime.c | 51 ++++++++++++++++++++++++++++++++ ports/webassembly/mpconfigport.h | 4 +++ ports/webassembly/mphalport.c | 9 ++++++ ports/webassembly/mphalport.h | 1 + 7 files changed, 69 insertions(+) create mode 100644 ports/webassembly/modtime.c diff --git a/ports/webassembly/Makefile b/ports/webassembly/Makefile index c5ee80fe0046f..4e1d53b0ccfdf 100644 --- a/ports/webassembly/Makefile +++ b/ports/webassembly/Makefile @@ -23,6 +23,7 @@ SRC_SHARED = $(addprefix shared/,\ runtime/stdout_helpers.c \ runtime/pyexec.c \ readline/readline.c \ + timeutils/timeutils.c \ ) SRC_C = \ diff --git a/ports/webassembly/library.h b/ports/webassembly/library.h index 21027c1372f0e..04b408d71a25a 100644 --- a/ports/webassembly/library.h +++ b/ports/webassembly/library.h @@ -29,4 +29,5 @@ extern void mp_js_write(const char *str, mp_uint_t len); extern int mp_js_ticks_ms(void); extern void mp_js_hook(void); +extern double mp_js_time_ms(void); extern uint32_t mp_js_random_u32(void); diff --git a/ports/webassembly/library.js b/ports/webassembly/library.js index 4a17942bb4e83..d1266598da93e 100644 --- a/ports/webassembly/library.js +++ b/ports/webassembly/library.js @@ -64,6 +64,8 @@ mergeInto(LibraryManager.library, { } }, + mp_js_time_ms: () => Date.now(), + // Node prior to v19 did not expose "crypto" as a global, so make sure it exists. mp_js_random_u32__postset: "if (globalThis.crypto === undefined) { globalThis.crypto = require('crypto'); }", diff --git a/ports/webassembly/modtime.c b/ports/webassembly/modtime.c new file mode 100644 index 0000000000000..1b1e63d4ddf3a --- /dev/null +++ b/ports/webassembly/modtime.c @@ -0,0 +1,51 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023 Damien P. George + * + * 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/obj.h" +#include "shared/timeutils/timeutils.h" +#include "library.h" + +// Return the localtime as an 8-tuple. +static mp_obj_t mp_time_localtime_get(void) { + timeutils_struct_time_t tm; + timeutils_seconds_since_epoch_to_struct_time(mp_hal_time_ms() / 1000, &tm); + mp_obj_t tuple[8] = { + mp_obj_new_int(tm.tm_year), + mp_obj_new_int(tm.tm_mon), + mp_obj_new_int(tm.tm_mday), + mp_obj_new_int(tm.tm_hour), + mp_obj_new_int(tm.tm_min), + mp_obj_new_int(tm.tm_sec), + mp_obj_new_int(tm.tm_wday), + mp_obj_new_int(tm.tm_yday), + }; + return mp_obj_new_tuple(8, tuple); +} + +// Returns the number of seconds, as a float, since the Epoch. +static mp_obj_t mp_time_time_get(void) { + return mp_obj_new_float((mp_float_t)mp_hal_time_ms() / 1000); +} diff --git a/ports/webassembly/mpconfigport.h b/ports/webassembly/mpconfigport.h index 43a029c530ca8..79537dd72de4c 100644 --- a/ports/webassembly/mpconfigport.h +++ b/ports/webassembly/mpconfigport.h @@ -50,7 +50,11 @@ #define MICROPY_USE_INTERNAL_ERRNO (1) #define MICROPY_USE_INTERNAL_PRINTF (0) +#define MICROPY_EPOCH_IS_1970 (1) #define MICROPY_PY_RANDOM_SEED_INIT_FUNC (mp_js_random_u32()) +#define MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME (1) +#define MICROPY_PY_TIME_TIME_TIME_NS (1) +#define MICROPY_PY_TIME_INCLUDEFILE "ports/webassembly/modtime.c" #ifndef MICROPY_VFS #define MICROPY_VFS (1) #endif diff --git a/ports/webassembly/mphalport.c b/ports/webassembly/mphalport.c index f91a509013a3c..72a326e30d1f9 100644 --- a/ports/webassembly/mphalport.c +++ b/ports/webassembly/mphalport.c @@ -56,6 +56,15 @@ mp_uint_t mp_hal_ticks_cpu(void) { return 0; } +uint64_t mp_hal_time_ms(void) { + double mm = mp_js_time_ms(); + return (uint64_t)mm; +} + +uint64_t mp_hal_time_ns(void) { + return mp_hal_time_ms() * 1000000ULL; +} + extern int mp_interrupt_char; int mp_hal_get_interrupt_char(void) { diff --git a/ports/webassembly/mphalport.h b/ports/webassembly/mphalport.h index 1b3179698644b..a90de8ec5fb0e 100644 --- a/ports/webassembly/mphalport.h +++ b/ports/webassembly/mphalport.h @@ -35,6 +35,7 @@ void mp_hal_delay_us(mp_uint_t us); mp_uint_t mp_hal_ticks_ms(void); mp_uint_t mp_hal_ticks_us(void); mp_uint_t mp_hal_ticks_cpu(void); +uint64_t mp_hal_time_ms(void); int mp_hal_get_interrupt_char(void); From ae6bcc9d2345d73016fd22f9cc22b56c73bae432 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 31 May 2023 11:44:45 +1000 Subject: [PATCH 261/408] webassembly: Use POSIX write for output and add stderr. All output is now handled by Emscripten's stdio facility. Signed-off-by: Damien George --- ports/webassembly/library.js | 10 ---------- ports/webassembly/mpconfigport.h | 4 +++- ports/webassembly/mphalport.c | 11 +++++++++-- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/ports/webassembly/library.js b/ports/webassembly/library.js index d1266598da93e..db5bac2691443 100644 --- a/ports/webassembly/library.js +++ b/ports/webassembly/library.js @@ -25,16 +25,6 @@ */ mergeInto(LibraryManager.library, { - mp_js_write: function(ptr, len) { - const buffer = HEAPU8.subarray(ptr, ptr + len) - if (ENVIRONMENT_IS_NODE) { - process.stdout.write(buffer); - } else { - const printEvent = new CustomEvent('micropython-print', { detail: buffer }); - document.dispatchEvent(printEvent); - } - }, - // This string will be emitted directly into the output file by Emscripten. mp_js_ticks_ms__postset: "var MP_JS_EPOCH = Date.now()", diff --git a/ports/webassembly/mpconfigport.h b/ports/webassembly/mpconfigport.h index 79537dd72de4c..6b0f2753a960a 100644 --- a/ports/webassembly/mpconfigport.h +++ b/ports/webassembly/mpconfigport.h @@ -46,6 +46,7 @@ #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ) #define MICROPY_ENABLE_DOC_STRING (1) #define MICROPY_WARNINGS (1) +#define MICROPY_ERROR_PRINTER (&mp_stderr_print) #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE) #define MICROPY_USE_INTERNAL_ERRNO (1) #define MICROPY_USE_INTERNAL_PRINTF (0) @@ -60,7 +61,6 @@ #endif #define MICROPY_VFS_POSIX (MICROPY_VFS) #define MICROPY_PY_SYS_PLATFORM "webassembly" -#define MICROPY_PY_SYS_STDFILES (0) #define MICROPY_EVENT_POLL_HOOK \ do { \ @@ -102,4 +102,6 @@ typedef long mp_off_t; #define _GNU_SOURCE #endif +extern const struct _mp_print_t mp_stderr_print; + uint32_t mp_js_random_u32(void); diff --git a/ports/webassembly/mphalport.c b/ports/webassembly/mphalport.c index 72a326e30d1f9..9ab47762e3e97 100644 --- a/ports/webassembly/mphalport.c +++ b/ports/webassembly/mphalport.c @@ -24,12 +24,19 @@ * THE SOFTWARE. */ +#include #include "library.h" #include "mphalport.h" +static void stderr_print_strn(void *env, const char *str, size_t len) { + (void)env; + write(2, str, len); +} + +const mp_print_t mp_stderr_print = {NULL, stderr_print_strn}; + mp_uint_t mp_hal_stdout_tx_strn(const char *str, size_t len) { - mp_js_write(str, len); - return len; + return write(1, str, len); } void mp_hal_delay_ms(mp_uint_t ms) { From 98a8ff7a1a42211acc62e5c41a445a9d6f256e70 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 22 Jun 2023 17:31:40 +1000 Subject: [PATCH 262/408] webassembly: Add support for enabling MICROPY_GC_SPLIT_HEAP_AUTO. When enabled the GC will not reclaim any memory on a call to `gc_collect()`. Instead it will grow the heap. Signed-off-by: Damien George --- ports/webassembly/main.c | 15 +++++++++++++++ ports/webassembly/mpconfigport.h | 1 + 2 files changed, 16 insertions(+) diff --git a/ports/webassembly/main.c b/ports/webassembly/main.c index 1b053046bfb99..ebde8ac7008ba 100644 --- a/ports/webassembly/main.c +++ b/ports/webassembly/main.c @@ -113,6 +113,19 @@ void mp_js_init_repl() { pyexec_event_repl_init(); } +#if MICROPY_GC_SPLIT_HEAP_AUTO + +// The largest new region that is available to become Python heap. +size_t gc_get_max_new_split(void) { + return 128 * 1024 * 1024; +} + +// Don't collect anything. Instead require the heap to grow. +void gc_collect(void) { +} + +#else + static void gc_scan_func(void *begin, void *end) { gc_collect_root((void **)begin, (void **)end - (void **)begin + 1); } @@ -124,6 +137,8 @@ void gc_collect(void) { gc_collect_end(); } +#endif + #if !MICROPY_VFS mp_lexer_t *mp_lexer_new_from_file(qstr filename) { mp_raise_OSError(MP_ENOENT); diff --git a/ports/webassembly/mpconfigport.h b/ports/webassembly/mpconfigport.h index 6b0f2753a960a..d0261362390fa 100644 --- a/ports/webassembly/mpconfigport.h +++ b/ports/webassembly/mpconfigport.h @@ -26,6 +26,7 @@ */ #include +#include // for malloc, for MICROPY_GC_SPLIT_HEAP_AUTO // options to control how MicroPython is built From 691cd3a56d74354bf2cb3d6f46dc226760134297 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 30 May 2023 13:15:58 +1000 Subject: [PATCH 263/408] webassembly: Clean up Makefile and add variant support. This commit cleans up and generalises the Makefile, adds support for variants (following the unix port) and adds the "standard" variant as the default variant. Signed-off-by: Damien George --- ports/webassembly/Makefile | 78 +++++++++++++++---- ports/webassembly/mpconfigport.h | 21 +++-- .../variants/standard/mpconfigvariant.h | 1 + .../variants/standard/mpconfigvariant.mk | 1 + 4 files changed, 82 insertions(+), 19 deletions(-) create mode 100644 ports/webassembly/variants/standard/mpconfigvariant.h create mode 100644 ports/webassembly/variants/standard/mpconfigvariant.mk diff --git a/ports/webassembly/Makefile b/ports/webassembly/Makefile index 4e1d53b0ccfdf..e8f27d862bb8a 100644 --- a/ports/webassembly/Makefile +++ b/ports/webassembly/Makefile @@ -1,23 +1,67 @@ -include ../../py/mkenv.mk +################################################################################ +# Initial setup of Makefile environment. + +# Select the variant to build for: +ifdef VARIANT_DIR +# Custom variant path - remove trailing slash and get the final component of +# the path as the variant name. +VARIANT ?= $(notdir $(VARIANT_DIR:/=)) +else +# If not given on the command line, then default to standard. +VARIANT ?= standard +VARIANT_DIR ?= variants/$(VARIANT) +endif + +ifeq ($(wildcard $(VARIANT_DIR)/.),) +$(error Invalid VARIANT specified: $(VARIANT_DIR)) +endif + +# If the build directory is not given, make it reflect the variant name. +BUILD ?= build-$(VARIANT) -CROSS = 0 +include ../../py/mkenv.mk +include $(VARIANT_DIR)/mpconfigvariant.mk +# Qstr definitions (must come before including py.mk). QSTR_DEFS = qstrdefsport.h +# Include py core make definitions. include $(TOP)/py/py.mk include $(TOP)/extmod/extmod.mk +################################################################################ +# Project specific settings and compiler/linker flags. + CC = emcc LD = emcc +TERSER ?= npx terser INC += -I. INC += -I$(TOP) INC += -I$(BUILD) +INC += -I$(VARIANT_DIR) CFLAGS += -std=c99 -Wall -Werror -Wdouble-promotion -Wfloat-conversion CFLAGS += -Os -DNDEBUG CFLAGS += $(INC) +JSFLAGS += -s EXPORTED_FUNCTIONS="\ + _mp_js_init,\ + _mp_js_init_repl,\ + _mp_js_do_str,\ + _mp_js_process_char,\ + _mp_hal_get_interrupt_char,\ + _mp_sched_keyboard_interrupt$(EXPORTED_FUNCTIONS_EXTRA)" +JSFLAGS += -s EXPORTED_RUNTIME_METHODS="\ + ccall,\ + cwrap,\ + FS$(EXPORTED_RUNTIME_METHODS_EXTRA)" +JSFLAGS += --js-library library.js +JSFLAGS += -s SUPPORT_LONGJMP=emscripten + +################################################################################ +# Source files and libraries. + SRC_SHARED = $(addprefix shared/,\ runtime/interrupt_char.c \ runtime/stdout_helpers.c \ @@ -26,33 +70,41 @@ SRC_SHARED = $(addprefix shared/,\ timeutils/timeutils.c \ ) -SRC_C = \ +SRC_C += \ main.c \ mphalport.c \ +# List of sources for qstr extraction. SRC_QSTR += $(SRC_C) $(SRC_SHARED) +SRC_JS ?= wrapper.js + OBJ += $(PY_O) OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) -JSFLAGS += -s ASYNCIFY -JSFLAGS += -s EXPORTED_FUNCTIONS="['_mp_js_init', '_mp_js_init_repl', '_mp_js_do_str', '_mp_js_process_char', '_mp_hal_get_interrupt_char', '_mp_sched_keyboard_interrupt']" -JSFLAGS += -s EXPORTED_RUNTIME_METHODS="['ccall', 'cwrap', 'FS']" -JSFLAGS += --js-library library.js +################################################################################ +# Main targets. + +.PHONY: all min test all: $(BUILD)/micropython.js -$(BUILD)/micropython.js: $(OBJ) library.js wrapper.js - $(ECHO) "LINK $(BUILD)/firmware.js" - $(Q)emcc $(LDFLAGS) -o $(BUILD)/firmware.js $(OBJ) $(JSFLAGS) - cat wrapper.js $(BUILD)/firmware.js > $@ +$(BUILD)/micropython.js: $(OBJ) library.js $(SRC_JS) + $(ECHO) "LINK $@" + $(Q)emcc $(LDFLAGS) -o $@ $(OBJ) $(JSFLAGS) + $(Q)cat $(SRC_JS) >> $@ -min: $(BUILD)/micropython.js - uglifyjs $< -c -o $(BUILD)/micropython.min.js +$(BUILD)/micropython.min.js: $(BUILD)/micropython.js + $(TERSER) $< --compress --module -o $@ + +min: $(BUILD)/micropython.min.js test: $(BUILD)/micropython.js $(TOP)/tests/run-tests.py $(eval DIRNAME=ports/$(notdir $(CURDIR))) cd $(TOP)/tests && MICROPY_MICROPYTHON=../ports/webassembly/node_run.sh ./run-tests.py -j1 +################################################################################ +# Remaining make rules. + include $(TOP)/py/mkrules.mk diff --git a/ports/webassembly/mpconfigport.h b/ports/webassembly/mpconfigport.h index d0261362390fa..abfbbca7941f8 100644 --- a/ports/webassembly/mpconfigport.h +++ b/ports/webassembly/mpconfigport.h @@ -25,17 +25,18 @@ * THE SOFTWARE. */ +// Options to control how MicroPython is built for this port, overriding +// defaults in py/mpconfig.h. + #include #include // for malloc, for MICROPY_GC_SPLIT_HEAP_AUTO -// options to control how MicroPython is built +// Variant-specific definitions. +#include "mpconfigvariant.h" +#ifndef MICROPY_CONFIG_ROM_LEVEL #define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_EXTRA_FEATURES) - -// You can disable the built-in MicroPython compiler by setting the following -// config option to 0. If you do this then you won't get a REPL prompt, but you -// will still be able to execute pre-compiled scripts, compiled with mpy-cross. -#define MICROPY_ENABLE_COMPILER (1) +#endif #define MICROPY_ALLOC_PATH_MAX (256) #define MICROPY_READER_VFS (MICROPY_VFS) @@ -69,6 +70,13 @@ mp_handle_pending(true); \ } while (0); +// Whether the VM will periodically call mp_js_hook(), which checks for +// interrupt characters on stdin (or equivalent input). +#ifndef MICROPY_VARIANT_ENABLE_JS_HOOK +#define MICROPY_VARIANT_ENABLE_JS_HOOK (0) +#endif + +#if MICROPY_VARIANT_ENABLE_JS_HOOK #define MICROPY_VM_HOOK_COUNT (10) #define MICROPY_VM_HOOK_INIT static uint vm_hook_divisor = MICROPY_VM_HOOK_COUNT; #define MICROPY_VM_HOOK_POLL if (--vm_hook_divisor == 0) { \ @@ -78,6 +86,7 @@ } #define MICROPY_VM_HOOK_LOOP MICROPY_VM_HOOK_POLL #define MICROPY_VM_HOOK_RETURN MICROPY_VM_HOOK_POLL +#endif // type definitions for the specific machine diff --git a/ports/webassembly/variants/standard/mpconfigvariant.h b/ports/webassembly/variants/standard/mpconfigvariant.h new file mode 100644 index 0000000000000..7be62ea7f4f3f --- /dev/null +++ b/ports/webassembly/variants/standard/mpconfigvariant.h @@ -0,0 +1 @@ +#define MICROPY_VARIANT_ENABLE_JS_HOOK (1) diff --git a/ports/webassembly/variants/standard/mpconfigvariant.mk b/ports/webassembly/variants/standard/mpconfigvariant.mk new file mode 100644 index 0000000000000..62ee161907de2 --- /dev/null +++ b/ports/webassembly/variants/standard/mpconfigvariant.mk @@ -0,0 +1 @@ +JSFLAGS += -s ASYNCIFY From 39bd0b8a0a18d7bfc499acc7a11028da12f43edc Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 31 May 2023 11:45:34 +1000 Subject: [PATCH 264/408] webassembly: Add JavaScript proxying, and js and jsffi modules. This commit improves the webassembly port by adding: - Proxying of Python objects to JavaScript with a PyProxy type that lives on the JavaScript side. PyProxy implements JavaScript Proxy traps such as has, get, set and ownKeys, to make Python objects have functionality on the JavaScript side. - Proxying of JavaScript objects to Python with a JsProxy type that lives on the Python side. JsProxy passes through calls, attributes, subscription and iteration from Python to JavaScript. - A top-level API on the JavaScript side to construct a MicroPython interpreter instance via `loadMicroPython()`. That function returns an object that can be used to execute Python code, access the Python globals dict, access the Emscripten filesystem, and other things. This API is based on the API provided by Pyodide (https://pyodide.org/). As part of this, the top-level file is changed from `micropython.js` to `micropython.mjs`. - A Python `js` module which can be used to access all JavaScript-side symbols, for example the DOM when run within a browser. - A Python `jsffi` module with various helper functions like `create_proxy()` and `to_js()`. - A dedenting lexer which automatically dedents Python source code if every non-empty line in that source starts with a common whitespace prefix. This is very helpful when Python source code is indented within a string within HTML or JavaScript for formatting reasons. Signed-off-by: Damien George --- ports/webassembly/Makefile | 56 +++++- ports/webassembly/api.js | 146 ++++++++++++++ ports/webassembly/lexer_dedent.c | 105 ++++++++++ ports/webassembly/lexer_dedent.h | 36 ++++ ports/webassembly/main.c | 56 ++++++ ports/webassembly/modjs.c | 55 ++++++ ports/webassembly/modjsffi.c | 80 ++++++++ ports/webassembly/mpconfigport.h | 8 + ports/webassembly/objjsproxy.c | 330 +++++++++++++++++++++++++++++++ ports/webassembly/objpyproxy.js | 191 ++++++++++++++++++ ports/webassembly/proxy_c.c | 281 ++++++++++++++++++++++++++ ports/webassembly/proxy_c.h | 58 ++++++ ports/webassembly/proxy_js.js | 222 +++++++++++++++++++++ 13 files changed, 1615 insertions(+), 9 deletions(-) create mode 100644 ports/webassembly/api.js create mode 100644 ports/webassembly/lexer_dedent.c create mode 100644 ports/webassembly/lexer_dedent.h create mode 100644 ports/webassembly/modjs.c create mode 100644 ports/webassembly/modjsffi.c create mode 100644 ports/webassembly/objjsproxy.c create mode 100644 ports/webassembly/objpyproxy.js create mode 100644 ports/webassembly/proxy_c.c create mode 100644 ports/webassembly/proxy_c.h create mode 100644 ports/webassembly/proxy_js.js diff --git a/ports/webassembly/Makefile b/ports/webassembly/Makefile index e8f27d862bb8a..2a5669392eb41 100644 --- a/ports/webassembly/Makefile +++ b/ports/webassembly/Makefile @@ -45,7 +45,34 @@ CFLAGS += -std=c99 -Wall -Werror -Wdouble-promotion -Wfloat-conversion CFLAGS += -Os -DNDEBUG CFLAGS += $(INC) +EXPORTED_FUNCTIONS_EXTRA += ,\ + _mp_js_do_exec,\ + _mp_js_do_import,\ + _mp_js_register_js_module,\ + _proxy_c_init,\ + _proxy_c_to_js_call,\ + _proxy_c_to_js_delete_attr,\ + _proxy_c_to_js_dir,\ + _proxy_c_to_js_get_array,\ + _proxy_c_to_js_get_dict,\ + _proxy_c_to_js_get_type,\ + _proxy_c_to_js_has_attr,\ + _proxy_c_to_js_lookup_attr,\ + _proxy_c_to_js_store_attr,\ + _proxy_convert_mp_to_js_obj_cside + +EXPORTED_RUNTIME_METHODS_EXTRA += ,\ + PATH,\ + PATH_FS,\ + UTF8ToString,\ + getValue,\ + lengthBytesUTF8,\ + setValue,\ + stringToUTF8 + JSFLAGS += -s EXPORTED_FUNCTIONS="\ + _free,\ + _malloc,\ _mp_js_init,\ _mp_js_init_repl,\ _mp_js_do_str,\ @@ -58,6 +85,7 @@ JSFLAGS += -s EXPORTED_RUNTIME_METHODS="\ FS$(EXPORTED_RUNTIME_METHODS_EXTRA)" JSFLAGS += --js-library library.js JSFLAGS += -s SUPPORT_LONGJMP=emscripten +JSFLAGS += -s MODULARIZE -s EXPORT_NAME=_createMicroPythonModule ################################################################################ # Source files and libraries. @@ -71,13 +99,21 @@ SRC_SHARED = $(addprefix shared/,\ ) SRC_C += \ + lexer_dedent.c \ main.c \ + modjs.c \ + modjsffi.c \ mphalport.c \ + objjsproxy.c \ + proxy_c.c \ # List of sources for qstr extraction. SRC_QSTR += $(SRC_C) $(SRC_SHARED) -SRC_JS ?= wrapper.js +SRC_JS += \ + api.js \ + objpyproxy.js \ + proxy_js.js \ OBJ += $(PY_O) OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED:.c=.o)) @@ -86,23 +122,25 @@ OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) ################################################################################ # Main targets. -.PHONY: all min test +.PHONY: all min test test_min -all: $(BUILD)/micropython.js +all: $(BUILD)/micropython.mjs -$(BUILD)/micropython.js: $(OBJ) library.js $(SRC_JS) +$(BUILD)/micropython.mjs: $(OBJ) library.js $(SRC_JS) $(ECHO) "LINK $@" $(Q)emcc $(LDFLAGS) -o $@ $(OBJ) $(JSFLAGS) $(Q)cat $(SRC_JS) >> $@ -$(BUILD)/micropython.min.js: $(BUILD)/micropython.js +$(BUILD)/micropython.min.mjs: $(BUILD)/micropython.mjs $(TERSER) $< --compress --module -o $@ -min: $(BUILD)/micropython.min.js +min: $(BUILD)/micropython.min.mjs + +test: $(BUILD)/micropython.mjs $(TOP)/tests/run-tests.py + cd $(TOP)/tests && MICROPY_MICROPYTHON_MJS=../ports/webassembly/$< ./run-tests.py --target webassembly -test: $(BUILD)/micropython.js $(TOP)/tests/run-tests.py - $(eval DIRNAME=ports/$(notdir $(CURDIR))) - cd $(TOP)/tests && MICROPY_MICROPYTHON=../ports/webassembly/node_run.sh ./run-tests.py -j1 +test_min: $(BUILD)/micropython.min.mjs $(TOP)/tests/run-tests.py + cd $(TOP)/tests && MICROPY_MICROPYTHON_MJS=../ports/webassembly/$< ./run-tests.py --target webassembly ################################################################################ # Remaining make rules. diff --git a/ports/webassembly/api.js b/ports/webassembly/api.js new file mode 100644 index 0000000000000..dfe7561768a4f --- /dev/null +++ b/ports/webassembly/api.js @@ -0,0 +1,146 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023-2024 Damien P. George + * + * 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. + */ + +// Options: +// - heapsize: size in bytes of the MicroPython GC heap. +// - url: location to load `micropython.mjs`. +// - stdin: function to return input characters. +// - stdout: function that takes one argument, and is passed lines of stdout +// output as they are produced. By default this is handled by Emscripten +// and in a browser goes to console, in node goes to process.stdout.write. +// - stderr: same behaviour as stdout but for error output. +// - linebuffer: whether to buffer line-by-line to stdout/stderr. +export async function loadMicroPython(options) { + const { heapsize, url, stdin, stdout, stderr, linebuffer } = Object.assign( + { heapsize: 1024 * 1024, linebuffer: true }, + options, + ); + const Module = {}; + Module.locateFile = (path, scriptDirectory) => + url || scriptDirectory + path; + Module._textDecoder = new TextDecoder(); + if (stdin !== undefined) { + Module.stdin = stdin; + } + if (stdout !== undefined) { + if (linebuffer) { + Module._stdoutBuffer = []; + Module.stdout = (c) => { + if (c === 10) { + stdout( + Module._textDecoder.decode( + new Uint8Array(Module._stdoutBuffer), + ), + ); + Module._stdoutBuffer = []; + } else { + Module._stdoutBuffer.push(c); + } + }; + } else { + Module.stdout = (c) => stdout(new Uint8Array([c])); + } + } + if (stderr !== undefined) { + if (linebuffer) { + Module._stderrBuffer = []; + Module.stderr = (c) => { + if (c === 10) { + stderr( + Module._textDecoder.decode( + new Uint8Array(Module._stderrBuffer), + ), + ); + Module._stderrBuffer = []; + } else { + Module._stderrBuffer.push(c); + } + }; + } else { + Module.stderr = (c) => stderr(new Uint8Array([c])); + } + } + const moduleLoaded = new Promise((r) => { + Module.postRun = r; + }); + _createMicroPythonModule(Module); + await moduleLoaded; + globalThis.Module = Module; + proxy_js_init(); + const pyimport = (name) => { + const value = Module._malloc(3 * 4); + Module.ccall( + "mp_js_do_import", + "null", + ["string", "pointer"], + [name, value], + ); + return proxy_convert_mp_to_js_obj_jsside_with_free(value); + }; + Module.ccall("mp_js_init", "null", ["number"], [heapsize]); + Module.ccall("proxy_c_init", "null", [], []); + return { + _module: Module, + PyProxy: PyProxy, + FS: Module.FS, + globals: { + __dict__: pyimport("__main__").__dict__, + get(key) { + return this.__dict__[key]; + }, + set(key, value) { + this.__dict__[key] = value; + }, + delete(key) { + delete this.__dict__[key]; + }, + }, + registerJsModule(name, module) { + const value = Module._malloc(3 * 4); + proxy_convert_js_to_mp_obj_jsside(module, value); + Module.ccall( + "mp_js_register_js_module", + "null", + ["string", "pointer"], + [name, value], + ); + Module._free(value); + }, + pyimport: pyimport, + runPython(code) { + const value = Module._malloc(3 * 4); + Module.ccall( + "mp_js_do_exec", + "number", + ["string", "pointer"], + [code, value], + ); + return proxy_convert_mp_to_js_obj_jsside_with_free(value); + }, + }; +} + +globalThis.loadMicroPython = loadMicroPython; diff --git a/ports/webassembly/lexer_dedent.c b/ports/webassembly/lexer_dedent.c new file mode 100644 index 0000000000000..555caea89692b --- /dev/null +++ b/ports/webassembly/lexer_dedent.c @@ -0,0 +1,105 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023 Damien P. George + * + * 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 "lexer_dedent.h" + +typedef struct _mp_reader_mem_dedent_t { + size_t free_len; // if >0 mem is freed on close by: m_free(beg, free_len) + const byte *beg; + const byte *cur; + const byte *end; + size_t dedent_prefix; +} mp_reader_mem_dedent_t; + +// Work out the amount of common whitespace among all non-empty lines. +static size_t dedent(const byte *text, size_t len) { + size_t min_prefix = -1; + size_t cur_prefix = 0; + bool start_of_line = true; + for (const byte *t = text; t < text + len; ++t) { + if (*t == '\n') { + start_of_line = true; + cur_prefix = 0; + } else if (start_of_line) { + if (unichar_isspace(*t)) { + ++cur_prefix; + } else { + if (cur_prefix < min_prefix) { + min_prefix = cur_prefix; + if (min_prefix == 0) { + return min_prefix; + } + } + start_of_line = false; + } + } + } + return min_prefix; +} + +static mp_uint_t mp_reader_mem_dedent_readbyte(void *data) { + mp_reader_mem_dedent_t *reader = (mp_reader_mem_dedent_t *)data; + if (reader->cur < reader->end) { + byte c = *reader->cur++; + if (c == '\n') { + for (size_t i = 0; i < reader->dedent_prefix; ++i) { + if (*reader->cur == '\n') { + break; + } + ++reader->cur; + } + } + return c; + } else { + return MP_READER_EOF; + } +} + +static void mp_reader_mem_dedent_close(void *data) { + mp_reader_mem_dedent_t *reader = (mp_reader_mem_dedent_t *)data; + if (reader->free_len > 0) { + m_del(char, (char *)reader->beg, reader->free_len); + } + m_del_obj(mp_reader_mem_dedent_t, reader); +} + +static void mp_reader_new_mem_dedent(mp_reader_t *reader, const byte *buf, size_t len, size_t free_len) { + mp_reader_mem_dedent_t *rm = m_new_obj(mp_reader_mem_dedent_t); + rm->free_len = free_len; + rm->beg = buf; + rm->cur = buf; + rm->end = buf + len; + rm->dedent_prefix = dedent(buf, len); + reader->data = rm; + reader->readbyte = mp_reader_mem_dedent_readbyte; + reader->close = mp_reader_mem_dedent_close; +} + +mp_lexer_t *mp_lexer_new_from_str_len_dedent(qstr src_name, const char *str, size_t len, size_t free_len) { + mp_reader_t reader; + mp_reader_new_mem_dedent(&reader, (const byte *)str, len, free_len); + return mp_lexer_new(src_name, reader); +} diff --git a/ports/webassembly/lexer_dedent.h b/ports/webassembly/lexer_dedent.h new file mode 100644 index 0000000000000..a8cc2526b4f53 --- /dev/null +++ b/ports/webassembly/lexer_dedent.h @@ -0,0 +1,36 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023-2024 Damien P. George + * + * 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_WEBASSEMBLY_LEXER_DEDENT_H +#define MICROPY_INCLUDED_WEBASSEMBLY_LEXER_DEDENT_H + +#include "py/lexer.h" + +// This function creates a new "dedenting lexer" which automatically dedents the input +// source code if every non-empty line in that source starts with a common whitespace +// prefix. It does this dedenting inplace as the memory is read. +mp_lexer_t *mp_lexer_new_from_str_len_dedent(qstr src_name, const char *str, size_t len, size_t free_len); + +#endif // MICROPY_INCLUDED_WEBASSEMBLY_LEXER_DEDENT_H diff --git a/ports/webassembly/main.c b/ports/webassembly/main.c index ebde8ac7008ba..c1c7a88840ec3 100644 --- a/ports/webassembly/main.c +++ b/ports/webassembly/main.c @@ -40,7 +40,9 @@ #include "shared/runtime/pyexec.h" #include "emscripten.h" +#include "lexer_dedent.h" #include "library.h" +#include "proxy_c.h" #if MICROPY_ENABLE_COMPILER int do_str(const char *src, mp_parse_input_kind_t input_kind) { @@ -113,6 +115,60 @@ void mp_js_init_repl() { pyexec_event_repl_init(); } +void mp_js_register_js_module(const char *name, uint32_t *value) { + mp_obj_t module_name = MP_OBJ_NEW_QSTR(qstr_from_str(name)); + mp_obj_t module = proxy_convert_js_to_mp_obj_cside(value); + mp_map_t *mp_loaded_modules_map = &MP_STATE_VM(mp_loaded_modules_dict).map; + mp_map_lookup(mp_loaded_modules_map, module_name, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = module; +} + +void mp_js_do_import(const char *name, uint32_t *out) { + nlr_buf_t nlr; + if (nlr_push(&nlr) == 0) { + mp_obj_t ret = mp_import_name(qstr_from_str(name), mp_const_none, MP_OBJ_NEW_SMALL_INT(0)); + // Return the leaf of the import, eg for "a.b.c" return "c". + const char *m = name; + const char *n = name; + for (;; ++n) { + if (*n == '\0' || *n == '.') { + if (m != name) { + ret = mp_load_attr(ret, qstr_from_strn(m, n - m)); + } + m = n + 1; + if (*n == '\0') { + break; + } + } + } + nlr_pop(); + proxy_convert_mp_to_js_obj_cside(ret, out); + } else { + // uncaught exception + proxy_convert_mp_to_js_exc_cside(nlr.ret_val, out); + } +} + +void mp_js_do_exec(const char *src, uint32_t *out) { + // Collect at the top-level, where there are no root pointers from stack/registers. + gc_collect_start(); + gc_collect_end(); + + mp_parse_input_kind_t input_kind = MP_PARSE_FILE_INPUT; + nlr_buf_t nlr; + if (nlr_push(&nlr) == 0) { + mp_lexer_t *lex = mp_lexer_new_from_str_len_dedent(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0); + qstr source_name = lex->source_name; + mp_parse_tree_t parse_tree = mp_parse(lex, input_kind); + mp_obj_t module_fun = mp_compile(&parse_tree, source_name, false); + mp_obj_t ret = mp_call_function_0(module_fun); + nlr_pop(); + proxy_convert_mp_to_js_obj_cside(ret, out); + } else { + // uncaught exception + proxy_convert_mp_to_js_exc_cside(nlr.ret_val, out); + } +} + #if MICROPY_GC_SPLIT_HEAP_AUTO // The largest new region that is available to become Python heap. diff --git a/ports/webassembly/modjs.c b/ports/webassembly/modjs.c new file mode 100644 index 0000000000000..bed09086ab7cf --- /dev/null +++ b/ports/webassembly/modjs.c @@ -0,0 +1,55 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023-2024 Damien P. George + * + * 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/objmodule.h" +#include "py/runtime.h" +#include "proxy_c.h" + +#if MICROPY_PY_JS + +/******************************************************************************/ +// js module + +void mp_module_js_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { + mp_obj_jsproxy_t global_this; + global_this.ref = 0; + mp_obj_jsproxy_attr(MP_OBJ_FROM_PTR(&global_this), attr, dest); +} + +static const mp_rom_map_elem_t mp_module_js_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_js) }, +}; +static MP_DEFINE_CONST_DICT(mp_module_js_globals, mp_module_js_globals_table); + +const mp_obj_module_t mp_module_js = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&mp_module_js_globals, +}; + +MP_REGISTER_MODULE(MP_QSTR_js, mp_module_js); +MP_REGISTER_MODULE_DELEGATION(mp_module_js, mp_module_js_attr); + +#endif // MICROPY_PY_JS diff --git a/ports/webassembly/modjsffi.c b/ports/webassembly/modjsffi.c new file mode 100644 index 0000000000000..d4e61e368f009 --- /dev/null +++ b/ports/webassembly/modjsffi.c @@ -0,0 +1,80 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023-2024 Damien P. George + * + * 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 "emscripten.h" +#include "py/objmodule.h" +#include "py/runtime.h" +#include "proxy_c.h" + +#if MICROPY_PY_JSFFI + +/******************************************************************************/ +// jsffi module + +EM_JS(void, proxy_convert_mp_to_js_then_js_to_mp_obj_jsside, (uint32_t * out), { + const ret = proxy_convert_mp_to_js_obj_jsside(out); + proxy_convert_js_to_mp_obj_jsside_force_double_proxy(ret, out); +}); + +static mp_obj_t mp_jsffi_create_proxy(mp_obj_t arg) { + uint32_t out[3]; + proxy_convert_mp_to_js_obj_cside(arg, out); + proxy_convert_mp_to_js_then_js_to_mp_obj_jsside(out); + return proxy_convert_js_to_mp_obj_cside(out); +} +static MP_DEFINE_CONST_FUN_OBJ_1(mp_jsffi_create_proxy_obj, mp_jsffi_create_proxy); + +EM_JS(void, proxy_convert_mp_to_js_then_js_to_js_then_js_to_mp_obj_jsside, (uint32_t * out), { + const ret = proxy_convert_mp_to_js_obj_jsside(out); + const js_obj = PyProxy.toJs(ret); + proxy_convert_js_to_mp_obj_jsside(js_obj, out); +}); + +static mp_obj_t mp_jsffi_to_js(mp_obj_t arg) { + uint32_t out[3]; + proxy_convert_mp_to_js_obj_cside(arg, out); + proxy_convert_mp_to_js_then_js_to_js_then_js_to_mp_obj_jsside(out); + return proxy_convert_js_to_mp_obj_cside(out); +} +static MP_DEFINE_CONST_FUN_OBJ_1(mp_jsffi_to_js_obj, mp_jsffi_to_js); + +static const mp_rom_map_elem_t mp_module_jsffi_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_jsffi) }, + + { MP_ROM_QSTR(MP_QSTR_JsProxy), MP_ROM_PTR(&mp_type_jsproxy) }, + { MP_ROM_QSTR(MP_QSTR_create_proxy), MP_ROM_PTR(&mp_jsffi_create_proxy_obj) }, + { MP_ROM_QSTR(MP_QSTR_to_js), MP_ROM_PTR(&mp_jsffi_to_js_obj) }, +}; +static MP_DEFINE_CONST_DICT(mp_module_jsffi_globals, mp_module_jsffi_globals_table); + +const mp_obj_module_t mp_module_jsffi = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&mp_module_jsffi_globals, +}; + +MP_REGISTER_MODULE(MP_QSTR_jsffi, mp_module_jsffi); + +#endif // MICROPY_PY_JSFFI diff --git a/ports/webassembly/mpconfigport.h b/ports/webassembly/mpconfigport.h index abfbbca7941f8..fc7ba2f82d33c 100644 --- a/ports/webassembly/mpconfigport.h +++ b/ports/webassembly/mpconfigport.h @@ -64,6 +64,14 @@ #define MICROPY_VFS_POSIX (MICROPY_VFS) #define MICROPY_PY_SYS_PLATFORM "webassembly" +#ifndef MICROPY_PY_JS +#define MICROPY_PY_JS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) +#endif + +#ifndef MICROPY_PY_JSFFI +#define MICROPY_PY_JSFFI (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) +#endif + #define MICROPY_EVENT_POLL_HOOK \ do { \ extern void mp_handle_pending(bool); \ diff --git a/ports/webassembly/objjsproxy.c b/ports/webassembly/objjsproxy.c new file mode 100644 index 0000000000000..a28b791cf23d4 --- /dev/null +++ b/ports/webassembly/objjsproxy.c @@ -0,0 +1,330 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023-2024 Damien P. George + * + * 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 +#include + +#include "emscripten.h" +#include "py/objmodule.h" +#include "py/runtime.h" +#include "proxy_c.h" + +// *FORMAT-OFF* +EM_JS(bool, lookup_attr, (int jsref, const char *str, uint32_t * out), { + const base = proxy_js_ref[jsref]; + const attr = UTF8ToString(str); + if (attr in base) { + let value = base[attr]; + if (typeof value == "function") { + if (base !== globalThis) { + value = value.bind(base); + } + } + proxy_convert_js_to_mp_obj_jsside(value, out); + return true; + } else { + return false; + } +}); +// *FORMAT-ON* + +EM_JS(void, store_attr, (int jsref, const char *attr_ptr, uint32_t * value_ref), { + const attr = UTF8ToString(attr_ptr); + const value = proxy_convert_mp_to_js_obj_jsside(value_ref); + proxy_js_ref[jsref][attr] = value; +}); + +EM_JS(void, call0, (int f_ref, uint32_t * out), { + // Because of JavaScript "this" semantics, we must extract the target function + // to a variable before calling it, so "this" is bound to the correct value. + // + // In detail: + // In JavaScript, proxy_js_ref[f_ref] acts like a function call + // proxy_js_ref.at(f_ref), and "this" will be bound to proxy_js_ref if + // there is a chain of calls, such as proxy_js_ref.at(f_ref)(). + // But proxy_js_ref is not "this" in the context of the call, so we + // must extract the function to an independent variable and then call + // that variable, so that "this" is correct (it will be "undefined"). + + const f = proxy_js_ref[f_ref]; + const ret = f(); + proxy_convert_js_to_mp_obj_jsside(ret, out); +}); + +EM_JS(int, call1, (int f_ref, uint32_t * a0, uint32_t * out), { + const a0_js = proxy_convert_mp_to_js_obj_jsside(a0); + const f = proxy_js_ref[f_ref]; + const ret = f(a0_js); + proxy_convert_js_to_mp_obj_jsside(ret, out); +}); + +EM_JS(int, call2, (int f_ref, uint32_t * a0, uint32_t * a1, uint32_t * out), { + const a0_js = proxy_convert_mp_to_js_obj_jsside(a0); + const a1_js = proxy_convert_mp_to_js_obj_jsside(a1); + const f = proxy_js_ref[f_ref]; + const ret = f(a0_js, a1_js); + proxy_convert_js_to_mp_obj_jsside(ret, out); +}); + +EM_JS(int, calln, (int f_ref, uint32_t n_args, uint32_t * value, uint32_t * out), { + const f = proxy_js_ref[f_ref]; + const a = []; + for (let i = 0; i < n_args; ++i) { + const v = proxy_convert_mp_to_js_obj_jsside(value + i * 3 * 4); + a.push(v); + } + const ret = f(... a); + proxy_convert_js_to_mp_obj_jsside(ret, out); +}); + +EM_JS(void, call0_kwarg, (int f_ref, uint32_t n_kw, uint32_t * key, uint32_t * value, uint32_t * out), { + const f = proxy_js_ref[f_ref]; + const a = {}; + for (let i = 0; i < n_kw; ++i) { + const k = UTF8ToString(getValue(key + i * 4, "i32")); + const v = proxy_convert_mp_to_js_obj_jsside(value + i * 3 * 4); + a[k] = v; + } + const ret = f(a); + proxy_convert_js_to_mp_obj_jsside(ret, out); +}); + +EM_JS(void, call1_kwarg, (int f_ref, uint32_t * arg0, uint32_t n_kw, uint32_t * key, uint32_t * value, uint32_t * out), { + const f = proxy_js_ref[f_ref]; + const a0 = proxy_convert_mp_to_js_obj_jsside(arg0); + const a = {}; + for (let i = 0; i < n_kw; ++i) { + const k = UTF8ToString(getValue(key + i * 4, "i32")); + const v = proxy_convert_mp_to_js_obj_jsside(value + i * 3 * 4); + a[k] = v; + } + const ret = f(a0, a); + proxy_convert_js_to_mp_obj_jsside(ret, out); +}); + +EM_JS(void, js_reflect_construct, (int f_ref, uint32_t n_args, uint32_t * args, uint32_t * out), { + const f = proxy_js_ref[f_ref]; + const as = []; + for (let i = 0; i < n_args; ++i) { + as.push(proxy_convert_mp_to_js_obj_jsside(args + i * 4)); + } + const ret = Reflect.construct(f, as); + proxy_convert_js_to_mp_obj_jsside(ret, out); +}); + +EM_JS(int, js_get_len, (int f_ref), { + return proxy_js_ref[f_ref].length; +}); + +EM_JS(void, js_subscr_int, (int f_ref, int idx, uint32_t * out), { + const f = proxy_js_ref[f_ref]; + const ret = f[idx]; + proxy_convert_js_to_mp_obj_jsside(ret, out); +}); + +EM_JS(void, js_subscr_load, (int f_ref, uint32_t * index_ref, uint32_t * out), { + const target = proxy_js_ref[f_ref]; + const index = python_index_semantics(target, proxy_convert_mp_to_js_obj_jsside(index_ref)); + const ret = target[index]; + proxy_convert_js_to_mp_obj_jsside(ret, out); +}); + +EM_JS(void, js_subscr_store, (int f_ref, uint32_t * idx, uint32_t * value), { + const f = proxy_js_ref[f_ref]; + f[proxy_convert_mp_to_js_obj_jsside(idx)] = proxy_convert_mp_to_js_obj_jsside(value); +}); + +static void jsproxy_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { + mp_obj_jsproxy_t *self = MP_OBJ_TO_PTR(self_in); + mp_printf(print, "", self->ref); +} + +static mp_obj_t jsproxy_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_obj_jsproxy_t *self = MP_OBJ_TO_PTR(self_in); + + if (n_kw == 0) { + mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, false); + } else { + mp_arg_check_num(n_args, n_kw, 0, 1, true); + uint32_t key[n_kw]; + uint32_t value[PVN * n_kw]; + for (int i = 0; i < n_kw; ++i) { + key[i] = (uintptr_t)mp_obj_str_get_str(args[n_args + i * 2]); + proxy_convert_mp_to_js_obj_cside(args[n_args + i * 2 + 1], &value[i * PVN]); + } + uint32_t out[3]; + if (n_args == 0) { + call0_kwarg(self->ref, n_kw, key, value, out); + } else { + // n_args == 1 + uint32_t arg0[PVN]; + proxy_convert_mp_to_js_obj_cside(args[0], arg0); + call1_kwarg(self->ref, arg0, n_kw, key, value, out); + } + return proxy_convert_js_to_mp_obj_cside(out); + } + + if (n_args == 0) { + uint32_t out[3]; + call0(self->ref, out); + return proxy_convert_js_to_mp_obj_cside(out); + } else if (n_args == 1) { + uint32_t arg0[PVN]; + uint32_t out[PVN]; + proxy_convert_mp_to_js_obj_cside(args[0], arg0); + call1(self->ref, arg0, out); + return proxy_convert_js_to_mp_obj_cside(out); + } else if (n_args == 2) { + uint32_t arg0[PVN]; + proxy_convert_mp_to_js_obj_cside(args[0], arg0); + uint32_t arg1[PVN]; + proxy_convert_mp_to_js_obj_cside(args[1], arg1); + uint32_t out[3]; + call2(self->ref, arg0, arg1, out); + return proxy_convert_js_to_mp_obj_cside(out); + } else { + uint32_t value[PVN * n_args]; + for (int i = 0; i < n_args; ++i) { + proxy_convert_mp_to_js_obj_cside(args[i], &value[i * PVN]); + } + uint32_t out[3]; + calln(self->ref, n_args, value, out); + return proxy_convert_js_to_mp_obj_cside(out); + } +} + +static mp_obj_t jsproxy_reflect_construct(size_t n_args, const mp_obj_t *args) { + int arg0 = mp_obj_jsproxy_get_ref(args[0]); + n_args -= 1; + args += 1; + uint32_t args_conv[n_args]; + for (unsigned int i = 0; i < n_args; ++i) { + proxy_convert_mp_to_js_obj_cside(args[i], &args_conv[i * PVN]); + } + uint32_t out[3]; + js_reflect_construct(arg0, n_args, args_conv, out); + return proxy_convert_js_to_mp_obj_cside(out); +} +static MP_DEFINE_CONST_FUN_OBJ_VAR(jsproxy_reflect_construct_obj, 1, jsproxy_reflect_construct); + +static mp_obj_t jsproxy_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { + mp_obj_jsproxy_t *self = MP_OBJ_TO_PTR(self_in); + if (value == MP_OBJ_SENTINEL) { + // Load subscript. + uint32_t idx[PVN], out[PVN]; + proxy_convert_mp_to_js_obj_cside(index, idx); + js_subscr_load(self->ref, idx, out); + return proxy_convert_js_to_mp_obj_cside(out); + } else if (value == MP_OBJ_NULL) { + // Delete subscript. + return MP_OBJ_NULL; // not supported + } else { + // Store subscript. + uint32_t idx[PVN], val[PVN]; + proxy_convert_mp_to_js_obj_cside(index, idx); + proxy_convert_mp_to_js_obj_cside(value, val); + js_subscr_store(self->ref, idx, val); + return mp_const_none; + } +} + +void mp_obj_jsproxy_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { + mp_obj_jsproxy_t *self = MP_OBJ_TO_PTR(self_in); + if (dest[0] == MP_OBJ_NULL) { + // Load attribute. + uint32_t out[PVN]; + if (lookup_attr(self->ref, qstr_str(attr), out)) { + dest[0] = proxy_convert_js_to_mp_obj_cside(out); + } else if (attr == MP_QSTR_new) { + // Special case to handle construction of JS objects. + // JS objects don't have a ".new" attribute, doing "Obj.new" is a Pyodide idiom for "new Obj". + // It translates to the JavaScript "Reflect.construct(Obj, Array(...args))". + dest[0] = MP_OBJ_FROM_PTR(&jsproxy_reflect_construct_obj); + dest[1] = self_in; + } + } else if (dest[1] == MP_OBJ_NULL) { + // Delete attribute. + } else { + // Store attribute. + uint32_t value[PVN]; + proxy_convert_mp_to_js_obj_cside(dest[1], value); + store_attr(self->ref, qstr_str(attr), value); + dest[0] = MP_OBJ_NULL; + } +} + +/******************************************************************************/ +// jsproxy iterator + +typedef struct _jsproxy_it_t { + mp_obj_base_t base; + mp_fun_1_t iternext; + int ref; + uint16_t cur; + uint16_t len; +} jsproxy_it_t; + +static mp_obj_t jsproxy_it_iternext(mp_obj_t self_in) { + jsproxy_it_t *self = MP_OBJ_TO_PTR(self_in); + if (self->cur < self->len) { + uint32_t out[3]; + js_subscr_int(self->ref, self->cur, out); + self->cur += 1; + return proxy_convert_js_to_mp_obj_cside(out); + } else { + return MP_OBJ_STOP_ITERATION; + } +} + +static mp_obj_t jsproxy_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) { + assert(sizeof(jsproxy_it_t) <= sizeof(mp_obj_iter_buf_t)); + jsproxy_it_t *o = (jsproxy_it_t *)iter_buf; + o->base.type = &mp_type_polymorph_iter; + o->iternext = jsproxy_it_iternext; + o->ref = mp_obj_jsproxy_get_ref(o_in); + o->cur = 0; + o->len = js_get_len(o->ref); + return MP_OBJ_FROM_PTR(o); +} + +/******************************************************************************/ + +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_jsproxy, + MP_QSTR_JsProxy, + MP_TYPE_FLAG_ITER_IS_GETITER, + print, jsproxy_print, + call, jsproxy_call, + attr, mp_obj_jsproxy_attr, + subscr, jsproxy_subscr, + iter, jsproxy_getiter + ); + +mp_obj_t mp_obj_new_jsproxy(int ref) { + mp_obj_jsproxy_t *o = mp_obj_malloc(mp_obj_jsproxy_t, &mp_type_jsproxy); + o->ref = ref; + return MP_OBJ_FROM_PTR(o); +} diff --git a/ports/webassembly/objpyproxy.js b/ports/webassembly/objpyproxy.js new file mode 100644 index 0000000000000..52670b66e9542 --- /dev/null +++ b/ports/webassembly/objpyproxy.js @@ -0,0 +1,191 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023-2024 Damien P. George + * + * 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. + */ + +class PyProxy { + constructor(ref) { + this._ref = ref; + } + + // Convert js_obj -- which is possibly a PyProxy -- to a JavaScript object. + static toJs(js_obj) { + if (!(js_obj instanceof PyProxy)) { + return js_obj; + } + + const type = Module.ccall( + "proxy_c_to_js_get_type", + "number", + ["number"], + [js_obj._ref], + ); + + if (type === 1 || type === 2) { + // List or tuple. + const array_ref = Module._malloc(2 * 4); + const item = Module._malloc(3 * 4); + Module.ccall( + "proxy_c_to_js_get_array", + "null", + ["number", "pointer"], + [js_obj._ref, array_ref], + ); + const len = Module.getValue(array_ref, "i32"); + const items_ptr = Module.getValue(array_ref + 4, "i32"); + const js_array = []; + for (let i = 0; i < len; ++i) { + Module.ccall( + "proxy_convert_mp_to_js_obj_cside", + "null", + ["pointer", "pointer"], + [Module.getValue(items_ptr + i * 4, "i32"), item], + ); + const js_item = proxy_convert_mp_to_js_obj_jsside(item); + js_array.push(PyProxy.toJs(js_item)); + } + Module._free(array_ref); + Module._free(item); + return js_array; + } + + if (type === 3) { + // Dict. + const map_ref = Module._malloc(2 * 4); + const item = Module._malloc(3 * 4); + Module.ccall( + "proxy_c_to_js_get_dict", + "null", + ["number", "pointer"], + [js_obj._ref, map_ref], + ); + const alloc = Module.getValue(map_ref, "i32"); + const table_ptr = Module.getValue(map_ref + 4, "i32"); + const js_dict = {}; + for (let i = 0; i < alloc; ++i) { + const mp_key = Module.getValue(table_ptr + i * 8, "i32"); + if (mp_key > 8) { + // Convert key to JS object. + Module.ccall( + "proxy_convert_mp_to_js_obj_cside", + "null", + ["pointer", "pointer"], + [mp_key, item], + ); + const js_key = proxy_convert_mp_to_js_obj_jsside(item); + + // Convert value to JS object. + const mp_value = Module.getValue( + table_ptr + i * 8 + 4, + "i32", + ); + Module.ccall( + "proxy_convert_mp_to_js_obj_cside", + "null", + ["pointer", "pointer"], + [mp_value, item], + ); + const js_value = proxy_convert_mp_to_js_obj_jsside(item); + + // Populate JS dict. + js_dict[js_key] = PyProxy.toJs(js_value); + } + } + Module._free(map_ref); + Module._free(item); + return js_dict; + } + + // Cannot convert to JS, leave as a PyProxy. + return js_obj; + } +} + +// This handler's goal is to allow minimal introspection +// of Python references from the JS world/utilities. +const py_proxy_handler = { + isExtensible() { + return true; + }, + ownKeys(target) { + const value = Module._malloc(3 * 4); + Module.ccall( + "proxy_c_to_js_dir", + "null", + ["number", "pointer"], + [target._ref, value], + ); + const dir = proxy_convert_mp_to_js_obj_jsside_with_free(value); + return PyProxy.toJs(dir).filter((attr) => !attr.startsWith("__")); + }, + getOwnPropertyDescriptor(target, prop) { + return { + value: target[prop], + enumerable: true, + writable: true, + configurable: true, + }; + }, + has(target, prop) { + return Module.ccall( + "proxy_c_to_js_has_attr", + "number", + ["number", "string"], + [target._ref, prop], + ); + }, + get(target, prop) { + if (prop === "_ref") { + return target._ref; + } + const value = Module._malloc(3 * 4); + Module.ccall( + "proxy_c_to_js_lookup_attr", + "number", + ["number", "string", "pointer"], + [target._ref, prop, value], + ); + return proxy_convert_mp_to_js_obj_jsside_with_free(value); + }, + set(target, prop, value) { + const value_conv = Module._malloc(3 * 4); + proxy_convert_js_to_mp_obj_jsside(value, value_conv); + const ret = Module.ccall( + "proxy_c_to_js_store_attr", + "number", + ["number", "string", "number"], + [target._ref, prop, value_conv], + ); + Module._free(value_conv); + return ret; + }, + deleteProperty(target, prop) { + return Module.ccall( + "proxy_c_to_js_delete_attr", + "number", + ["number", "string"], + [target._ref, prop], + ); + }, +}; diff --git a/ports/webassembly/proxy_c.c b/ports/webassembly/proxy_c.c new file mode 100644 index 0000000000000..809dd44ddefd1 --- /dev/null +++ b/ports/webassembly/proxy_c.c @@ -0,0 +1,281 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023-2024 Damien P. George + * + * 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 +#include + +#include "py/builtin.h" +#include "py/runtime.h" +#include "proxy_c.h" + +// These constants should match the constants in proxy_js.js. + +enum { + PROXY_KIND_MP_EXCEPTION = -1, + PROXY_KIND_MP_NULL = 0, + PROXY_KIND_MP_NONE = 1, + PROXY_KIND_MP_BOOL = 2, + PROXY_KIND_MP_INT = 3, + PROXY_KIND_MP_FLOAT = 4, + PROXY_KIND_MP_STR = 5, + PROXY_KIND_MP_CALLABLE = 6, + PROXY_KIND_MP_OBJECT = 7, + PROXY_KIND_MP_JSPROXY = 8, +}; + +enum { + PROXY_KIND_JS_NULL = 1, + PROXY_KIND_JS_BOOLEAN = 2, + PROXY_KIND_JS_INTEGER = 3, + PROXY_KIND_JS_DOUBLE = 4, + PROXY_KIND_JS_STRING = 5, + PROXY_KIND_JS_OBJECT = 6, + PROXY_KIND_JS_PYPROXY = 7, +}; + +void proxy_c_init(void) { + MP_STATE_PORT(proxy_c_ref) = mp_obj_new_list(0, NULL); + mp_obj_list_append(MP_STATE_PORT(proxy_c_ref), MP_OBJ_NULL); +} + +MP_REGISTER_ROOT_POINTER(mp_obj_t proxy_c_ref); + +static inline mp_obj_t proxy_c_get_obj(uint32_t c_ref) { + return ((mp_obj_list_t *)MP_OBJ_TO_PTR(MP_STATE_PORT(proxy_c_ref)))->items[c_ref]; +} + +mp_obj_t proxy_convert_js_to_mp_obj_cside(uint32_t *value) { + if (value[0] == PROXY_KIND_JS_NULL) { + return mp_const_none; + } else if (value[0] == PROXY_KIND_JS_BOOLEAN) { + return mp_obj_new_bool(value[1]); + } else if (value[0] == PROXY_KIND_JS_INTEGER) { + return mp_obj_new_int(value[1]); + } else if (value[0] == PROXY_KIND_JS_DOUBLE) { + return mp_obj_new_float_from_d(*(double *)&value[1]); + } else if (value[0] == PROXY_KIND_JS_STRING) { + mp_obj_t s = mp_obj_new_str((void *)value[2], value[1]); + free((void *)value[2]); + return s; + } else if (value[0] == PROXY_KIND_JS_PYPROXY) { + return proxy_c_get_obj(value[1]); + } else { + // PROXY_KIND_JS_OBJECT + return mp_obj_new_jsproxy(value[1]); + } +} + +void proxy_convert_mp_to_js_obj_cside(mp_obj_t obj, uint32_t *out) { + uint32_t kind; + if (obj == MP_OBJ_NULL) { + kind = PROXY_KIND_MP_NULL; + } else if (obj == mp_const_none) { + kind = PROXY_KIND_MP_NONE; + } else if (mp_obj_is_bool(obj)) { + kind = PROXY_KIND_MP_BOOL; + out[1] = mp_obj_is_true(obj); + } else if (mp_obj_is_int(obj)) { + kind = PROXY_KIND_MP_INT; + out[1] = mp_obj_get_int_truncated(obj); // TODO support big int + } else if (mp_obj_is_float(obj)) { + kind = PROXY_KIND_MP_FLOAT; + *(double *)&out[1] = mp_obj_get_float(obj); + } else if (mp_obj_is_str(obj)) { + kind = PROXY_KIND_MP_STR; + size_t len; + const char *str = mp_obj_str_get_data(obj, &len); + out[1] = len; + out[2] = (uintptr_t)str; + } else if (mp_obj_is_jsproxy(obj)) { + kind = PROXY_KIND_MP_JSPROXY; + out[1] = mp_obj_jsproxy_get_ref(obj); + } else { + if (mp_obj_is_callable(obj)) { + kind = PROXY_KIND_MP_CALLABLE; + } else { + kind = PROXY_KIND_MP_OBJECT; + } + size_t id = ((mp_obj_list_t *)MP_OBJ_TO_PTR(MP_STATE_PORT(proxy_c_ref)))->len; + mp_obj_list_append(MP_STATE_PORT(proxy_c_ref), obj); + out[1] = id; + } + out[0] = kind; +} + +void proxy_convert_mp_to_js_exc_cside(void *exc, uint32_t *out) { + out[0] = PROXY_KIND_MP_EXCEPTION; + vstr_t vstr; + mp_print_t print; + vstr_init_print(&vstr, 64, &print); + vstr_add_str(&vstr, qstr_str(mp_obj_get_type(MP_OBJ_FROM_PTR(exc))->name)); + vstr_add_char(&vstr, '\x04'); + mp_obj_print_exception(&print, MP_OBJ_FROM_PTR(exc)); + char *s = malloc(vstr_len(&vstr) + 1); + memcpy(s, vstr_str(&vstr), vstr_len(&vstr)); + out[1] = vstr_len(&vstr); + out[2] = (uintptr_t)s; + vstr_clear(&vstr); +} + +void proxy_c_to_js_call(uint32_t c_ref, uint32_t n_args, uint32_t *args_value, uint32_t *out) { + nlr_buf_t nlr; + if (nlr_push(&nlr) == 0) { + mp_obj_t args[4] = { mp_const_none, mp_const_none, mp_const_none, mp_const_none }; + for (size_t i = 0; i < n_args; ++i) { + args[i] = proxy_convert_js_to_mp_obj_cside(args_value + i * 3); + } + mp_obj_t obj = proxy_c_get_obj(c_ref); + mp_obj_t member = mp_call_function_n_kw(obj, n_args, 0, args); + nlr_pop(); + proxy_convert_mp_to_js_obj_cside(member, out); + } else { + // uncaught exception + proxy_convert_mp_to_js_exc_cside(nlr.ret_val, out); + } +} + +void proxy_c_to_js_dir(uint32_t c_ref, uint32_t *out) { + nlr_buf_t nlr; + if (nlr_push(&nlr) == 0) { + mp_obj_t obj = proxy_c_get_obj(c_ref); + mp_obj_t dir; + if (mp_obj_is_dict_or_ordereddict(obj)) { + mp_map_t *map = mp_obj_dict_get_map(obj); + dir = mp_obj_new_list(0, NULL); + for (size_t i = 0; i < map->alloc; i++) { + if (mp_map_slot_is_filled(map, i)) { + mp_obj_list_append(dir, map->table[i].key); + } + } + } else { + mp_obj_t args[1] = { obj }; + dir = mp_builtin_dir_obj.fun.var(1, args); + } + nlr_pop(); + return proxy_convert_mp_to_js_obj_cside(dir, out); + } else { + // uncaught exception + return proxy_convert_mp_to_js_exc_cside(nlr.ret_val, out); + } +} + +bool proxy_c_to_js_has_attr(uint32_t c_ref, const char *attr_in) { + mp_obj_t obj = proxy_c_get_obj(c_ref); + qstr attr = qstr_from_str(attr_in); + if (mp_obj_is_dict_or_ordereddict(obj)) { + mp_map_t *map = mp_obj_dict_get_map(obj); + mp_map_elem_t *elem = mp_map_lookup(map, MP_OBJ_NEW_QSTR(attr), MP_MAP_LOOKUP); + return elem != NULL; + } else { + mp_obj_t dest[2]; + mp_load_method_protected(obj, attr, dest, true); + if (dest[0] != MP_OBJ_NULL) { + return true; + } + } + return false; +} + +void proxy_c_to_js_lookup_attr(uint32_t c_ref, const char *attr_in, uint32_t *out) { + nlr_buf_t nlr; + if (nlr_push(&nlr) == 0) { + mp_obj_t obj = proxy_c_get_obj(c_ref); + qstr attr = qstr_from_str(attr_in); + mp_obj_t member; + if (mp_obj_is_dict_or_ordereddict(obj)) { + member = mp_obj_dict_get(obj, MP_OBJ_NEW_QSTR(attr)); + } else { + member = mp_load_attr(obj, attr); + } + nlr_pop(); + return proxy_convert_mp_to_js_obj_cside(member, out); + } else { + // uncaught exception + return proxy_convert_mp_to_js_exc_cside(nlr.ret_val, out); + } +} + +static bool proxy_c_to_js_store_helper(uint32_t c_ref, const char *attr_in, mp_obj_t value) { + mp_obj_t obj = proxy_c_get_obj(c_ref); + qstr attr = qstr_from_str(attr_in); + + nlr_buf_t nlr; + if (nlr_push(&nlr) == 0) { + if (mp_obj_is_dict_or_ordereddict(obj)) { + if (value == MP_OBJ_NULL) { + mp_obj_dict_delete(obj, MP_OBJ_NEW_QSTR(attr)); + } else { + mp_obj_dict_store(obj, MP_OBJ_NEW_QSTR(attr), value); + } + } else { + mp_store_attr(obj, attr, value); + } + nlr_pop(); + return true; + } else { + // uncaught exception + return false; + } +} + +bool proxy_c_to_js_store_attr(uint32_t c_ref, const char *attr_in, uint32_t *value_in) { + mp_obj_t value = proxy_convert_js_to_mp_obj_cside(value_in); + return proxy_c_to_js_store_helper(c_ref, attr_in, value); +} + +bool proxy_c_to_js_delete_attr(uint32_t c_ref, const char *attr_in) { + return proxy_c_to_js_store_helper(c_ref, attr_in, MP_OBJ_NULL); +} + +uint32_t proxy_c_to_js_get_type(uint32_t c_ref) { + mp_obj_t obj = proxy_c_get_obj(c_ref); + const mp_obj_type_t *type = mp_obj_get_type(obj); + if (type == &mp_type_tuple) { + return 1; + } else if (type == &mp_type_list) { + return 2; + } else if (type == &mp_type_dict) { + return 3; + } else { + return 4; + } +} + +void proxy_c_to_js_get_array(uint32_t c_ref, uint32_t *out) { + mp_obj_t obj = proxy_c_get_obj(c_ref); + size_t len; + mp_obj_t *items; + mp_obj_get_array(obj, &len, &items); + out[0] = len; + out[1] = (uintptr_t)items; +} + +void proxy_c_to_js_get_dict(uint32_t c_ref, uint32_t *out) { + mp_obj_t obj = proxy_c_get_obj(c_ref); + mp_map_t *map = mp_obj_dict_get_map(obj); + out[0] = map->alloc; + out[1] = (uintptr_t)map->table; +} diff --git a/ports/webassembly/proxy_c.h b/ports/webassembly/proxy_c.h new file mode 100644 index 0000000000000..3e68d2504958c --- /dev/null +++ b/ports/webassembly/proxy_c.h @@ -0,0 +1,58 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023-2024 Damien P. George + * + * 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_WEBASSEMBLY_PROXY_C_H +#define MICROPY_INCLUDED_WEBASSEMBLY_PROXY_C_H + +#include "py/obj.h" + +// proxy value number of items +#define PVN (3) + +typedef struct _mp_obj_jsproxy_t { + mp_obj_base_t base; + int ref; +} mp_obj_jsproxy_t; + +extern const mp_obj_type_t mp_type_jsproxy; + +void proxy_c_init(void); +mp_obj_t proxy_convert_js_to_mp_obj_cside(uint32_t *value); +void proxy_convert_mp_to_js_obj_cside(mp_obj_t obj, uint32_t *out); +void proxy_convert_mp_to_js_exc_cside(void *exc, uint32_t *out); + +mp_obj_t mp_obj_new_jsproxy(int ref); +void mp_obj_jsproxy_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest); + +static inline bool mp_obj_is_jsproxy(mp_obj_t o) { + return mp_obj_get_type(o) == &mp_type_jsproxy; +} + +static inline int mp_obj_jsproxy_get_ref(mp_obj_t o) { + mp_obj_jsproxy_t *self = MP_OBJ_TO_PTR(o); + return self->ref; +} + +#endif // MICROPY_INCLUDED_WEBASSEMBLY_PROXY_C_H diff --git a/ports/webassembly/proxy_js.js b/ports/webassembly/proxy_js.js new file mode 100644 index 0000000000000..1835bdfdfadaa --- /dev/null +++ b/ports/webassembly/proxy_js.js @@ -0,0 +1,222 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023-2024 Damien P. George + * + * 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. + */ + +// These constants should match the constants in proxy_c.c. + +const PROXY_KIND_MP_EXCEPTION = -1; +const PROXY_KIND_MP_NULL = 0; +const PROXY_KIND_MP_NONE = 1; +const PROXY_KIND_MP_BOOL = 2; +const PROXY_KIND_MP_INT = 3; +const PROXY_KIND_MP_FLOAT = 4; +const PROXY_KIND_MP_STR = 5; +const PROXY_KIND_MP_CALLABLE = 6; +const PROXY_KIND_MP_OBJECT = 7; +const PROXY_KIND_MP_JSPROXY = 8; + +const PROXY_KIND_JS_NULL = 1; +const PROXY_KIND_JS_BOOLEAN = 2; +const PROXY_KIND_JS_INTEGER = 3; +const PROXY_KIND_JS_DOUBLE = 4; +const PROXY_KIND_JS_STRING = 5; +const PROXY_KIND_JS_OBJECT = 6; +const PROXY_KIND_JS_PYPROXY = 7; + +class PythonError extends Error { + constructor(exc_type, exc_details) { + super(exc_details); + this.name = "PythonError"; + this.type = exc_type; + } +} + +function proxy_js_init() { + globalThis.proxy_js_ref = [globalThis]; +} + +function proxy_call_python(target, argumentsList) { + let args = 0; + + // Strip trailing "undefined" arguments. + while ( + argumentsList.length > 0 && + argumentsList[argumentsList.length - 1] === undefined + ) { + argumentsList.pop(); + } + + if (argumentsList.length > 0) { + // TODO use stackAlloc/stackRestore? + args = Module._malloc(argumentsList.length * 3 * 4); + for (const i in argumentsList) { + proxy_convert_js_to_mp_obj_jsside( + argumentsList[i], + args + i * 3 * 4, + ); + } + } + const value = Module._malloc(3 * 4); + Module.ccall( + "proxy_c_to_js_call", + "null", + ["number", "number", "number", "pointer"], + [target, argumentsList.length, args, value], + ); + if (argumentsList.length > 0) { + Module._free(args); + } + return proxy_convert_mp_to_js_obj_jsside_with_free(value); +} + +function proxy_convert_js_to_mp_obj_jsside(js_obj, out) { + let kind; + if (js_obj === null) { + kind = PROXY_KIND_JS_NULL; + } else if (typeof js_obj === "boolean") { + kind = PROXY_KIND_JS_BOOLEAN; + Module.setValue(out + 4, js_obj, "i32"); + } else if (typeof js_obj === "number") { + if (Number.isInteger(js_obj)) { + kind = PROXY_KIND_JS_INTEGER; + Module.setValue(out + 4, js_obj, "i32"); + } else { + kind = PROXY_KIND_JS_DOUBLE; + // double must be stored to an address that's a multiple of 8 + const temp = (out + 4) & ~7; + Module.setValue(temp, js_obj, "double"); + const double_lo = Module.getValue(temp, "i32"); + const double_hi = Module.getValue(temp + 4, "i32"); + Module.setValue(out + 4, double_lo, "i32"); + Module.setValue(out + 8, double_hi, "i32"); + } + } else if (typeof js_obj === "string") { + kind = PROXY_KIND_JS_STRING; + const len = Module.lengthBytesUTF8(js_obj); + const buf = Module._malloc(len + 1); + Module.stringToUTF8(js_obj, buf, len + 1); + Module.setValue(out + 4, len, "i32"); + Module.setValue(out + 8, buf, "i32"); + } else if (js_obj instanceof PyProxy) { + kind = PROXY_KIND_JS_PYPROXY; + Module.setValue(out + 4, js_obj._ref, "i32"); + } else { + kind = PROXY_KIND_JS_OBJECT; + const id = proxy_js_ref.length; + proxy_js_ref[id] = js_obj; + Module.setValue(out + 4, id, "i32"); + } + Module.setValue(out + 0, kind, "i32"); +} + +function proxy_convert_js_to_mp_obj_jsside_force_double_proxy(js_obj, out) { + if (js_obj instanceof PyProxy) { + const kind = PROXY_KIND_JS_OBJECT; + const id = proxy_js_ref.length; + proxy_js_ref[id] = js_obj; + Module.setValue(out + 4, id, "i32"); + Module.setValue(out + 0, kind, "i32"); + } else { + proxy_convert_js_to_mp_obj_jsside(js_obj, out); + } +} + +function proxy_convert_mp_to_js_obj_jsside(value) { + const kind = Module.getValue(value, "i32"); + let obj; + if (kind === PROXY_KIND_MP_EXCEPTION) { + // Exception + const str_len = Module.getValue(value + 4, "i32"); + const str_ptr = Module.getValue(value + 8, "i32"); + const str = Module.UTF8ToString(str_ptr, str_len); + Module._free(str_ptr); + const str_split = str.split("\x04"); + throw new PythonError(str_split[0], str_split[1]); + } + if (kind === PROXY_KIND_MP_NULL) { + // MP_OBJ_NULL + throw new Error("NULL object"); + } + if (kind === PROXY_KIND_MP_NONE) { + // None + obj = null; + } else if (kind === PROXY_KIND_MP_BOOL) { + // bool + obj = Module.getValue(value + 4, "i32") ? true : false; + } else if (kind === PROXY_KIND_MP_INT) { + // int + obj = Module.getValue(value + 4, "i32"); + } else if (kind === PROXY_KIND_MP_FLOAT) { + // float + // double must be loaded from an address that's a multiple of 8 + const temp = (value + 4) & ~7; + const double_lo = Module.getValue(value + 4, "i32"); + const double_hi = Module.getValue(value + 8, "i32"); + Module.setValue(temp, double_lo, "i32"); + Module.setValue(temp + 4, double_hi, "i32"); + obj = Module.getValue(temp, "double"); + } else if (kind === PROXY_KIND_MP_STR) { + // str + const str_len = Module.getValue(value + 4, "i32"); + const str_ptr = Module.getValue(value + 8, "i32"); + obj = Module.UTF8ToString(str_ptr, str_len); + } else if (kind === PROXY_KIND_MP_JSPROXY) { + // js proxy + const id = Module.getValue(value + 4, "i32"); + obj = proxy_js_ref[id]; + } else { + // obj + const id = Module.getValue(value + 4, "i32"); + if (kind === PROXY_KIND_MP_CALLABLE) { + obj = (...args) => { + return proxy_call_python(id, args); + }; + } else { + // PROXY_KIND_MP_OBJECT + const target = new PyProxy(id); + obj = new Proxy(target, py_proxy_handler); + } + } + return obj; +} + +function proxy_convert_mp_to_js_obj_jsside_with_free(value) { + const ret = proxy_convert_mp_to_js_obj_jsside(value); + Module._free(value); + return ret; +} + +function python_index_semantics(target, index_in) { + let index = index_in; + if (typeof index === "number") { + if (index < 0) { + index += target.length; + } + if (index < 0 || index >= target.length) { + throw new PythonError("IndexError", "index out of range"); + } + } + return index; +} From 9b090603a04e69ec710e14f6c8bd93011516c5a1 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 24 Jun 2023 17:19:05 +1000 Subject: [PATCH 265/408] webassembly: Implement runPythonAsync() for top-level async code. With this commit, `interpreter.runPythonAsync(code)` can now be used to run Python code that uses `await` at the top level. That will yield up to JavaScript and produce a thenable, which the JavaScript runtime can then resume. Also implemented is the ability for Python code to await on JavaScript promises/thenables. For example, outer JavaScript code can await on `runPythonAsync(code)` which then runs Python code that does `await js.fetch(url)`. The entire chain of calls will be suspended until the fetch completes. Signed-off-by: Damien George --- ports/webassembly/Makefile | 2 + ports/webassembly/api.js | 10 ++ ports/webassembly/main.c | 6 ++ ports/webassembly/mpconfigport.h | 1 + ports/webassembly/objjsproxy.c | 163 ++++++++++++++++++++++++++++++- ports/webassembly/objpyproxy.js | 23 +++++ ports/webassembly/proxy_c.c | 83 +++++++++++++++- ports/webassembly/proxy_js.js | 10 +- 8 files changed, 291 insertions(+), 7 deletions(-) diff --git a/ports/webassembly/Makefile b/ports/webassembly/Makefile index 2a5669392eb41..05e0c1f0f9085 100644 --- a/ports/webassembly/Makefile +++ b/ports/webassembly/Makefile @@ -47,6 +47,7 @@ CFLAGS += $(INC) EXPORTED_FUNCTIONS_EXTRA += ,\ _mp_js_do_exec,\ + _mp_js_do_exec_async,\ _mp_js_do_import,\ _mp_js_register_js_module,\ _proxy_c_init,\ @@ -58,6 +59,7 @@ EXPORTED_FUNCTIONS_EXTRA += ,\ _proxy_c_to_js_get_type,\ _proxy_c_to_js_has_attr,\ _proxy_c_to_js_lookup_attr,\ + _proxy_c_to_js_resume,\ _proxy_c_to_js_store_attr,\ _proxy_convert_mp_to_js_obj_cside diff --git a/ports/webassembly/api.js b/ports/webassembly/api.js index dfe7561768a4f..ec0601c612ade 100644 --- a/ports/webassembly/api.js +++ b/ports/webassembly/api.js @@ -140,6 +140,16 @@ export async function loadMicroPython(options) { ); return proxy_convert_mp_to_js_obj_jsside_with_free(value); }, + runPythonAsync(code) { + const value = Module._malloc(3 * 4); + Module.ccall( + "mp_js_do_exec_async", + "number", + ["string", "pointer"], + [code, value], + ); + return proxy_convert_mp_to_js_obj_jsside_with_free(value); + }, }; } diff --git a/ports/webassembly/main.c b/ports/webassembly/main.c index c1c7a88840ec3..5bb4222aaa726 100644 --- a/ports/webassembly/main.c +++ b/ports/webassembly/main.c @@ -169,6 +169,12 @@ void mp_js_do_exec(const char *src, uint32_t *out) { } } +void mp_js_do_exec_async(const char *src, uint32_t *out) { + mp_compile_allow_top_level_await = true; + mp_js_do_exec(src, out); + mp_compile_allow_top_level_await = false; +} + #if MICROPY_GC_SPLIT_HEAP_AUTO // The largest new region that is available to become Python heap. diff --git a/ports/webassembly/mpconfigport.h b/ports/webassembly/mpconfigport.h index fc7ba2f82d33c..ae5dfa6fa50b8 100644 --- a/ports/webassembly/mpconfigport.h +++ b/ports/webassembly/mpconfigport.h @@ -39,6 +39,7 @@ #endif #define MICROPY_ALLOC_PATH_MAX (256) +#define MICROPY_COMP_ALLOW_TOP_LEVEL_AWAIT (1) #define MICROPY_READER_VFS (MICROPY_VFS) #define MICROPY_ENABLE_GC (1) #define MICROPY_ENABLE_PYSTACK (1) diff --git a/ports/webassembly/objjsproxy.c b/ports/webassembly/objjsproxy.c index a28b791cf23d4..5e2aeb6a36e4b 100644 --- a/ports/webassembly/objjsproxy.c +++ b/ports/webassembly/objjsproxy.c @@ -32,6 +32,16 @@ #include "py/runtime.h" #include "proxy_c.h" +EM_JS(bool, has_attr, (int jsref, const char *str), { + const base = proxy_js_ref[jsref]; + const attr = UTF8ToString(str); + if (attr in base) { + return true; + } else { + return false; + } +}); + // *FORMAT-OFF* EM_JS(bool, lookup_attr, (int jsref, const char *str, uint32_t * out), { const base = proxy_js_ref[jsref]; @@ -299,19 +309,166 @@ static mp_obj_t jsproxy_it_iternext(mp_obj_t self_in) { } } -static mp_obj_t jsproxy_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t jsproxy_new_it(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { assert(sizeof(jsproxy_it_t) <= sizeof(mp_obj_iter_buf_t)); + mp_obj_jsproxy_t *self = MP_OBJ_TO_PTR(self_in); jsproxy_it_t *o = (jsproxy_it_t *)iter_buf; o->base.type = &mp_type_polymorph_iter; o->iternext = jsproxy_it_iternext; - o->ref = mp_obj_jsproxy_get_ref(o_in); + o->ref = self->ref; o->cur = 0; - o->len = js_get_len(o->ref); + o->len = js_get_len(self->ref); + return MP_OBJ_FROM_PTR(o); +} + +/******************************************************************************/ +// jsproxy generator + +enum { + JSOBJ_GEN_STATE_WAITING, + JSOBJ_GEN_STATE_COMPLETED, + JSOBJ_GEN_STATE_EXHAUSTED, +}; + +typedef struct _jsproxy_gen_t { + mp_obj_base_t base; + mp_obj_t thenable; + int state; +} jsproxy_gen_t; + +mp_vm_return_kind_t jsproxy_gen_resume(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t throw_value, mp_obj_t *ret_val) { + jsproxy_gen_t *self = MP_OBJ_TO_PTR(self_in); + switch (self->state) { + case JSOBJ_GEN_STATE_WAITING: + self->state = JSOBJ_GEN_STATE_COMPLETED; + *ret_val = self->thenable; + return MP_VM_RETURN_YIELD; + + case JSOBJ_GEN_STATE_COMPLETED: + self->state = JSOBJ_GEN_STATE_EXHAUSTED; + *ret_val = send_value; + return MP_VM_RETURN_NORMAL; + + case JSOBJ_GEN_STATE_EXHAUSTED: + default: + // Trying to resume an already stopped generator. + // This is an optimised "raise StopIteration(None)". + *ret_val = mp_const_none; + return MP_VM_RETURN_NORMAL; + } +} + +static mp_obj_t jsproxy_gen_resume_and_raise(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t throw_value, bool raise_stop_iteration) { + mp_obj_t ret; + switch (jsproxy_gen_resume(self_in, send_value, throw_value, &ret)) { + case MP_VM_RETURN_NORMAL: + default: + // A normal return is a StopIteration, either raise it or return + // MP_OBJ_STOP_ITERATION as an optimisation. + if (ret == mp_const_none) { + ret = MP_OBJ_NULL; + } + if (raise_stop_iteration) { + mp_raise_StopIteration(ret); + } else { + return mp_make_stop_iteration(ret); + } + + case MP_VM_RETURN_YIELD: + return ret; + + case MP_VM_RETURN_EXCEPTION: + nlr_raise(ret); + } +} + +static mp_obj_t jsproxy_gen_instance_iternext(mp_obj_t self_in) { + return jsproxy_gen_resume_and_raise(self_in, mp_const_none, MP_OBJ_NULL, false); +} + +static mp_obj_t jsproxy_gen_instance_send(mp_obj_t self_in, mp_obj_t send_value) { + return jsproxy_gen_resume_and_raise(self_in, send_value, MP_OBJ_NULL, true); +} +static MP_DEFINE_CONST_FUN_OBJ_2(jsproxy_gen_instance_send_obj, jsproxy_gen_instance_send); + +static mp_obj_t jsproxy_gen_instance_throw(size_t n_args, const mp_obj_t *args) { + // The signature of this function is: throw(type[, value[, traceback]]) + // CPython will pass all given arguments through the call chain and process them + // at the point they are used (native generators will handle them differently to + // user-defined generators with a throw() method). To save passing multiple + // values, MicroPython instead does partial processing here to reduce it down to + // one argument and passes that through: + // - if only args[1] is given, or args[2] is given but is None, args[1] is + // passed through (in the standard case it is an exception class or instance) + // - if args[2] is given and not None it is passed through (in the standard + // case it would be an exception instance and args[1] its corresponding class) + // - args[3] is always ignored + + mp_obj_t exc = args[1]; + if (n_args > 2 && args[2] != mp_const_none) { + exc = args[2]; + } + + return jsproxy_gen_resume_and_raise(args[0], mp_const_none, exc, true); +} +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(jsproxy_gen_instance_throw_obj, 2, 4, jsproxy_gen_instance_throw); + +static mp_obj_t jsproxy_gen_instance_close(mp_obj_t self_in) { + mp_obj_t ret; + switch (jsproxy_gen_resume(self_in, mp_const_none, MP_OBJ_FROM_PTR(&mp_const_GeneratorExit_obj), &ret)) { + case MP_VM_RETURN_YIELD: + mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("generator ignored GeneratorExit")); + + // Swallow GeneratorExit (== successful close), and re-raise any other + case MP_VM_RETURN_EXCEPTION: + // ret should always be an instance of an exception class + if (mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(mp_obj_get_type(ret)), MP_OBJ_FROM_PTR(&mp_type_GeneratorExit))) { + return mp_const_none; + } + nlr_raise(ret); + + default: + // The only choice left is MP_VM_RETURN_NORMAL which is successful close + return mp_const_none; + } +} +static MP_DEFINE_CONST_FUN_OBJ_1(jsproxy_gen_instance_close_obj, jsproxy_gen_instance_close); + +static const mp_rom_map_elem_t jsproxy_gen_instance_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&jsproxy_gen_instance_close_obj) }, + { MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&jsproxy_gen_instance_send_obj) }, + { MP_ROM_QSTR(MP_QSTR_throw), MP_ROM_PTR(&jsproxy_gen_instance_throw_obj) }, +}; +static MP_DEFINE_CONST_DICT(jsproxy_gen_instance_locals_dict, jsproxy_gen_instance_locals_dict_table); + +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_jsproxy_gen, + MP_QSTR_generator, + MP_TYPE_FLAG_ITER_IS_ITERNEXT, + iter, jsproxy_gen_instance_iternext, + locals_dict, &jsproxy_gen_instance_locals_dict + ); + +static mp_obj_t jsproxy_new_gen(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { + assert(sizeof(jsproxy_gen_t) <= sizeof(mp_obj_iter_buf_t)); + jsproxy_gen_t *o = (jsproxy_gen_t *)iter_buf; + o->base.type = &mp_type_jsproxy_gen; + o->thenable = self_in; + o->state = JSOBJ_GEN_STATE_WAITING; return MP_OBJ_FROM_PTR(o); } /******************************************************************************/ +static mp_obj_t jsproxy_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { + mp_obj_jsproxy_t *self = MP_OBJ_TO_PTR(self_in); + if (has_attr(self->ref, "then")) { + return jsproxy_new_gen(self_in, iter_buf); + } else { + return jsproxy_new_it(self_in, iter_buf); + } +} + MP_DEFINE_CONST_OBJ_TYPE( mp_type_jsproxy, MP_QSTR_JsProxy, diff --git a/ports/webassembly/objpyproxy.js b/ports/webassembly/objpyproxy.js index 52670b66e9542..9ba06283ea2b0 100644 --- a/ports/webassembly/objpyproxy.js +++ b/ports/webassembly/objpyproxy.js @@ -159,6 +159,9 @@ const py_proxy_handler = { if (prop === "_ref") { return target._ref; } + if (prop === "then") { + return null; + } const value = Module._malloc(3 * 4); Module.ccall( "proxy_c_to_js_lookup_attr", @@ -189,3 +192,23 @@ const py_proxy_handler = { ); }, }; + +// PyProxy of a Python generator, that implements the thenable interface. +class PyProxyThenable { + constructor(ref) { + this._ref = ref; + } + + then(resolve, reject) { + const values = Module._malloc(3 * 3 * 4); + proxy_convert_js_to_mp_obj_jsside(resolve, values + 3 * 4); + proxy_convert_js_to_mp_obj_jsside(reject, values + 2 * 3 * 4); + Module.ccall( + "proxy_c_to_js_resume", + "null", + ["number", "pointer"], + [this._ref, values], + ); + return proxy_convert_mp_to_js_obj_jsside_with_free(values); + } +} diff --git a/ports/webassembly/proxy_c.c b/ports/webassembly/proxy_c.c index 809dd44ddefd1..1e4573ce0ba55 100644 --- a/ports/webassembly/proxy_c.c +++ b/ports/webassembly/proxy_c.c @@ -27,6 +27,7 @@ #include #include +#include "emscripten.h" #include "py/builtin.h" #include "py/runtime.h" #include "proxy_c.h" @@ -42,8 +43,9 @@ enum { PROXY_KIND_MP_FLOAT = 4, PROXY_KIND_MP_STR = 5, PROXY_KIND_MP_CALLABLE = 6, - PROXY_KIND_MP_OBJECT = 7, - PROXY_KIND_MP_JSPROXY = 8, + PROXY_KIND_MP_GENERATOR = 7, + PROXY_KIND_MP_OBJECT = 8, + PROXY_KIND_MP_JSPROXY = 9, }; enum { @@ -115,6 +117,8 @@ void proxy_convert_mp_to_js_obj_cside(mp_obj_t obj, uint32_t *out) { } else { if (mp_obj_is_callable(obj)) { kind = PROXY_KIND_MP_CALLABLE; + } else if (mp_obj_is_type(obj, &mp_type_gen_instance)) { + kind = PROXY_KIND_MP_GENERATOR; } else { kind = PROXY_KIND_MP_OBJECT; } @@ -279,3 +283,78 @@ void proxy_c_to_js_get_dict(uint32_t c_ref, uint32_t *out) { out[0] = map->alloc; out[1] = (uintptr_t)map->table; } + +/******************************************************************************/ +// Bridge Python generator to JavaScript thenable. + +static const mp_obj_fun_builtin_var_t resume_obj; + +EM_JS(void, js_then_resolve, (uint32_t * resolve, uint32_t * reject), { + const resolve_js = proxy_convert_mp_to_js_obj_jsside(resolve); + const reject_js = proxy_convert_mp_to_js_obj_jsside(reject); + resolve_js(null); +}); + +EM_JS(void, js_then_reject, (uint32_t * resolve, uint32_t * reject), { + const resolve_js = proxy_convert_mp_to_js_obj_jsside(resolve); + const reject_js = proxy_convert_mp_to_js_obj_jsside(reject); + reject_js(null); +}); + +// *FORMAT-OFF* +EM_JS(void, js_then_continue, (int jsref, uint32_t * py_resume, uint32_t * resolve, uint32_t * reject, uint32_t * out), { + const py_resume_js = proxy_convert_mp_to_js_obj_jsside(py_resume); + const resolve_js = proxy_convert_mp_to_js_obj_jsside(resolve); + const reject_js = proxy_convert_mp_to_js_obj_jsside(reject); + const ret = proxy_js_ref[jsref].then((x) => {py_resume_js(x, resolve_js, reject_js);}, reject_js); + proxy_convert_js_to_mp_obj_jsside(ret, out); +}); +// *FORMAT-ON* + +static mp_obj_t proxy_resume_execute(mp_obj_t self_in, mp_obj_t value, mp_obj_t resolve, mp_obj_t reject) { + mp_obj_t ret_value; + mp_vm_return_kind_t ret_kind = mp_resume(self_in, value, MP_OBJ_NULL, &ret_value); + + uint32_t out_resolve[PVN]; + uint32_t out_reject[PVN]; + proxy_convert_mp_to_js_obj_cside(resolve, out_resolve); + proxy_convert_mp_to_js_obj_cside(reject, out_reject); + + if (ret_kind == MP_VM_RETURN_NORMAL) { + js_then_resolve(out_resolve, out_reject); + return mp_const_none; + } else if (ret_kind == MP_VM_RETURN_YIELD) { + // ret_value should be a JS thenable + mp_obj_t py_resume = mp_obj_new_bound_meth(MP_OBJ_FROM_PTR(&resume_obj), self_in); + int ref = mp_obj_jsproxy_get_ref(ret_value); + uint32_t out_py_resume[PVN]; + proxy_convert_mp_to_js_obj_cside(py_resume, out_py_resume); + uint32_t out[PVN]; + js_then_continue(ref, out_py_resume, out_resolve, out_reject, out); + return proxy_convert_js_to_mp_obj_cside(out); + } else { + // MP_VM_RETURN_EXCEPTION; + js_then_reject(out_resolve, out_reject); + nlr_raise(ret_value); + } +} + +static mp_obj_t resume_fun(size_t n_args, const mp_obj_t *args) { + return proxy_resume_execute(args[0], args[1], args[2], args[3]); +} +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(resume_obj, 4, 4, resume_fun); + +void proxy_c_to_js_resume(uint32_t c_ref, uint32_t *args) { + nlr_buf_t nlr; + if (nlr_push(&nlr) == 0) { + mp_obj_t obj = proxy_c_get_obj(c_ref); + mp_obj_t resolve = proxy_convert_js_to_mp_obj_cside(args + 1 * 3); + mp_obj_t reject = proxy_convert_js_to_mp_obj_cside(args + 2 * 3); + mp_obj_t ret = proxy_resume_execute(obj, mp_const_none, resolve, reject); + nlr_pop(); + return proxy_convert_mp_to_js_obj_cside(ret, args); + } else { + // uncaught exception + return proxy_convert_mp_to_js_exc_cside(nlr.ret_val, args); + } +} diff --git a/ports/webassembly/proxy_js.js b/ports/webassembly/proxy_js.js index 1835bdfdfadaa..7a0a1bbe8932d 100644 --- a/ports/webassembly/proxy_js.js +++ b/ports/webassembly/proxy_js.js @@ -34,8 +34,9 @@ const PROXY_KIND_MP_INT = 3; const PROXY_KIND_MP_FLOAT = 4; const PROXY_KIND_MP_STR = 5; const PROXY_KIND_MP_CALLABLE = 6; -const PROXY_KIND_MP_OBJECT = 7; -const PROXY_KIND_MP_JSPROXY = 8; +const PROXY_KIND_MP_GENERATOR = 7; +const PROXY_KIND_MP_OBJECT = 8; +const PROXY_KIND_MP_JSPROXY = 9; const PROXY_KIND_JS_NULL = 1; const PROXY_KIND_JS_BOOLEAN = 2; @@ -122,6 +123,9 @@ function proxy_convert_js_to_mp_obj_jsside(js_obj, out) { } else if (js_obj instanceof PyProxy) { kind = PROXY_KIND_JS_PYPROXY; Module.setValue(out + 4, js_obj._ref, "i32"); + } else if (js_obj instanceof PyProxyThenable) { + kind = PROXY_KIND_JS_PYPROXY; + Module.setValue(out + 4, js_obj._ref, "i32"); } else { kind = PROXY_KIND_JS_OBJECT; const id = proxy_js_ref.length; @@ -193,6 +197,8 @@ function proxy_convert_mp_to_js_obj_jsside(value) { obj = (...args) => { return proxy_call_python(id, args); }; + } else if (kind === PROXY_KIND_MP_GENERATOR) { + obj = new PyProxyThenable(id); } else { // PROXY_KIND_MP_OBJECT const target = new PyProxy(id); From 625b17a410f9e26d6c1ab0b81e475848d70af236 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 1 Feb 2024 17:46:34 +1100 Subject: [PATCH 266/408] webassembly: Implement runCLI() for a Node-based CLI. This allows running MicroPython webassembly from the command line using: node micropython.mjs Signed-off-by: Damien George --- ports/webassembly/api.js | 92 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/ports/webassembly/api.js b/ports/webassembly/api.js index ec0601c612ade..2a5522dfb0d9e 100644 --- a/ports/webassembly/api.js +++ b/ports/webassembly/api.js @@ -154,3 +154,95 @@ export async function loadMicroPython(options) { } globalThis.loadMicroPython = loadMicroPython; + +async function runCLI() { + const fs = await import("fs"); + let heap_size = 128 * 1024; + let contents = ""; + let repl = true; + + for (let i = 2; i < process.argv.length; i++) { + if (process.argv[i] === "-X" && i < process.argv.length - 1) { + if (process.argv[i + 1].includes("heapsize=")) { + heap_size = parseInt(process.argv[i + 1].split("heapsize=")[1]); + const suffix = process.argv[i + 1].substr(-1).toLowerCase(); + if (suffix === "k") { + heap_size *= 1024; + } else if (suffix === "m") { + heap_size *= 1024 * 1024; + } + ++i; + } + } else { + contents += fs.readFileSync(process.argv[i], "utf8"); + repl = false; + } + } + + if (process.stdin.isTTY === false) { + contents = fs.readFileSync(0, "utf8"); + repl = false; + } + + const mp = await loadMicroPython({ + heapsize: heap_size, + stdout: (data) => process.stdout.write(data), + linebuffer: false, + }); + + if (repl) { + mp_js_init_repl(); + process.stdin.setRawMode(true); + process.stdin.on("data", (data) => { + for (let i = 0; i < data.length; i++) { + mp_js_process_char(data[i]).then((result) => { + if (result) { + process.exit(); + } + }); + } + }); + } else { + try { + mp.runPython(contents); + } catch (error) { + if (error.name === "PythonError") { + if (error.type === "SystemExit") { + // SystemExit, this is a valid exception to successfully end a script. + } else { + // An unhandled Python exception, print in out. + console.error(error.message); + } + } else { + // A non-Python exception. Re-raise it. + throw error; + } + } + } +} + +// Check if Node is running (equivalent to ENVIRONMENT_IS_NODE). +if ( + typeof process === "object" && + typeof process.versions === "object" && + typeof process.versions.node === "string" +) { + // Check if this module is ron from the command line. + // + // See https://stackoverflow.com/questions/6398196/detect-if-called-through-require-or-directly-by-command-line/66309132#66309132 + // + // Note: + // - `resolve()` is used to handle symlinks + // - `includes()` is used to handle cases where the file extension was omitted when passed to node + + const path = await import("path"); + const url = await import("url"); + + const pathToThisFile = path.resolve(url.fileURLToPath(import.meta.url)); + const pathPassedToNode = path.resolve(process.argv[1]); + const isThisFileBeingRunViaCLI = pathToThisFile.includes(pathPassedToNode); + + if (isThisFileBeingRunViaCLI) { + runCLI(); + } +} From 6ff3e356e2cef310ea5e6481d60163a8138c3d66 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 6 Mar 2024 10:16:52 +1100 Subject: [PATCH 267/408] webassembly: Implement replInit() and replProcessChar(). This is the JavaScript API for starting and running a REPL. Signed-off-by: Damien George --- ports/webassembly/Makefile | 11 +++-- ports/webassembly/api.js | 25 ++++++++++- ports/webassembly/main.c | 52 ++++------------------ ports/webassembly/wrapper.js | 85 ------------------------------------ 4 files changed, 38 insertions(+), 135 deletions(-) delete mode 100644 ports/webassembly/wrapper.js diff --git a/ports/webassembly/Makefile b/ports/webassembly/Makefile index 05e0c1f0f9085..d0a8aa99243ca 100644 --- a/ports/webassembly/Makefile +++ b/ports/webassembly/Makefile @@ -34,6 +34,7 @@ include $(TOP)/extmod/extmod.mk CC = emcc LD = emcc +NODE ?= node TERSER ?= npx terser INC += -I. @@ -76,9 +77,8 @@ JSFLAGS += -s EXPORTED_FUNCTIONS="\ _free,\ _malloc,\ _mp_js_init,\ - _mp_js_init_repl,\ - _mp_js_do_str,\ - _mp_js_process_char,\ + _mp_js_repl_init,\ + _mp_js_repl_process_char,\ _mp_hal_get_interrupt_char,\ _mp_sched_keyboard_interrupt$(EXPORTED_FUNCTIONS_EXTRA)" JSFLAGS += -s EXPORTED_RUNTIME_METHODS="\ @@ -124,7 +124,7 @@ OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) ################################################################################ # Main targets. -.PHONY: all min test test_min +.PHONY: all repl min test test_min all: $(BUILD)/micropython.mjs @@ -136,6 +136,9 @@ $(BUILD)/micropython.mjs: $(OBJ) library.js $(SRC_JS) $(BUILD)/micropython.min.mjs: $(BUILD)/micropython.mjs $(TERSER) $< --compress --module -o $@ +repl: $(BUILD)/micropython.mjs + $(NODE) $< + min: $(BUILD)/micropython.min.mjs test: $(BUILD)/micropython.mjs $(TOP)/tests/run-tests.py diff --git a/ports/webassembly/api.js b/ports/webassembly/api.js index 2a5522dfb0d9e..7d1832af4f2ba 100644 --- a/ports/webassembly/api.js +++ b/ports/webassembly/api.js @@ -150,6 +150,27 @@ export async function loadMicroPython(options) { ); return proxy_convert_mp_to_js_obj_jsside_with_free(value); }, + replInit() { + Module.ccall("mp_js_repl_init", "null", ["null"]); + }, + replProcessChar(chr) { + return Module.ccall( + "mp_js_repl_process_char", + "number", + ["number"], + [chr], + ); + }, + // Needed if the GC/asyncify is enabled. + async replProcessCharWithAsyncify(chr) { + return Module.ccall( + "mp_js_repl_process_char", + "number", + ["number"], + [chr], + { async: true }, + ); + }, }; } @@ -191,11 +212,11 @@ async function runCLI() { }); if (repl) { - mp_js_init_repl(); + mp.replInit(); process.stdin.setRawMode(true); process.stdin.on("data", (data) => { for (let i = 0; i < data.length; i++) { - mp_js_process_char(data[i]).then((result) => { + mp.replProcessCharWithAsyncify(data[i]).then((result) => { if (result) { process.exit(); } diff --git a/ports/webassembly/main.c b/ports/webassembly/main.c index 5bb4222aaa726..441c6d67e350a 100644 --- a/ports/webassembly/main.c +++ b/ports/webassembly/main.c @@ -44,46 +44,6 @@ #include "library.h" #include "proxy_c.h" -#if MICROPY_ENABLE_COMPILER -int do_str(const char *src, mp_parse_input_kind_t input_kind) { - int ret = 0; - nlr_buf_t nlr; - if (nlr_push(&nlr) == 0) { - mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0); - qstr source_name = lex->source_name; - mp_parse_tree_t parse_tree = mp_parse(lex, input_kind); - mp_obj_t module_fun = mp_compile(&parse_tree, source_name, false); - mp_call_function_0(module_fun); - nlr_pop(); - } else { - // uncaught exception - if (mp_obj_is_subclass_fast(mp_obj_get_type((mp_obj_t)nlr.ret_val), &mp_type_SystemExit)) { - mp_obj_t exit_val = mp_obj_exception_get_value(MP_OBJ_FROM_PTR(nlr.ret_val)); - if (exit_val != mp_const_none) { - mp_int_t int_val; - if (mp_obj_get_int_maybe(exit_val, &int_val)) { - ret = int_val & 255; - } else { - ret = 1; - } - } - } else { - mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val); - ret = 1; - } - } - return ret; -} -#endif - -int mp_js_do_str(const char *code) { - return do_str(code, MP_PARSE_FILE_INPUT); -} - -int mp_js_process_char(int c) { - return pyexec_event_repl_process_char(c); -} - void mp_js_init(int heap_size) { #if MICROPY_ENABLE_GC char *heap = (char *)malloc(heap_size * sizeof(char)); @@ -111,10 +71,6 @@ void mp_js_init(int heap_size) { #endif } -void mp_js_init_repl() { - pyexec_event_repl_init(); -} - void mp_js_register_js_module(const char *name, uint32_t *value) { mp_obj_t module_name = MP_OBJ_NEW_QSTR(qstr_from_str(name)); mp_obj_t module = proxy_convert_js_to_mp_obj_cside(value); @@ -175,6 +131,14 @@ void mp_js_do_exec_async(const char *src, uint32_t *out) { mp_compile_allow_top_level_await = false; } +void mp_js_repl_init(void) { + pyexec_event_repl_init(); +} + +int mp_js_repl_process_char(int c) { + return pyexec_event_repl_process_char(c); +} + #if MICROPY_GC_SPLIT_HEAP_AUTO // The largest new region that is available to become Python heap. diff --git a/ports/webassembly/wrapper.js b/ports/webassembly/wrapper.js deleted file mode 100644 index 399801b7afcb9..0000000000000 --- a/ports/webassembly/wrapper.js +++ /dev/null @@ -1,85 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017, 2018 Rami Ali - * - * 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. - */ - -var Module = {}; - -var mainProgram = function() -{ - mp_js_init = Module.cwrap('mp_js_init', 'null', ['number']); - mp_js_do_str = Module.cwrap('mp_js_do_str', 'number', ['string'], {async: true}); - mp_js_init_repl = Module.cwrap('mp_js_init_repl', 'null', ['null']); - mp_js_process_char = Module.cwrap('mp_js_process_char', 'number', ['number'], {async: true}); - - if (typeof window === 'undefined' && require.main === module) { - var fs = require('fs'); - var heap_size = 128 * 1024; - var contents = ''; - var repl = true; - - for (var i = 0; i < process.argv.length; i++) { - if (process.argv[i] === '-X' && i < process.argv.length - 1) { - if (process.argv[i + 1].includes('heapsize=')) { - heap_size = parseInt(process.argv[i + 1].split('heapsize=')[1]); - if (process.argv[i + 1].substr(-1).toLowerCase() === 'k') { - heap_size *= 1024; - } else if (process.argv[i + 1].substr(-1).toLowerCase() === 'm') { - heap_size *= 1024 * 1024; - } - } - } else if (process.argv[i].includes('.py')) { - contents += fs.readFileSync(process.argv[i], 'utf8'); - repl = false;; - } - } - - if (process.stdin.isTTY === false) { - contents = fs.readFileSync(0, 'utf8'); - repl = 0; - } - - mp_js_init(heap_size); - - if (repl) { - mp_js_init_repl(); - process.stdin.setRawMode(true); - process.stdin.on('data', function (data) { - for (var i = 0; i < data.length; i++) { - mp_js_process_char(data[i]).then(result => { - if (result) { - process.exit() - } - }) - } - }); - } else { - mp_js_do_str(contents).then(exitCode => { - process.exitCode = exitCode - }) - } - } -} - -Module["onRuntimeInitialized"] = mainProgram; From b9eb74e73b8ad7be7c3d3d2eca2b1755041f03e6 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 31 May 2023 11:45:34 +1000 Subject: [PATCH 268/408] webassembly/variants/pyscript: Add pyscript variant. This commit adds a pyscript variant for use in https://pyscript.net/. The configuration is: - No ASYNCIFY, in order to keep the WASM size down and have good performance. - MICROPY_CONFIG_ROM_LEVEL_FULL_FEATURES to enable most features. - Custom manifest that includes many of the python-stdlib libraries. - MICROPY_GC_SPLIT_HEAP_AUTO to increase GC heap size instead of doing a collection when memory is exhausted. This is needed because ASYNCIFY is disabled. Instead the GC collection is run at the top-level before executing any Python code. - No MICROPY_VARIANT_ENABLE_JS_HOOK because there is no asynchronous keyboard input to interrupt a running script. Signed-off-by: Damien George --- .../webassembly/variants/pyscript/manifest.py | 27 +++++++++++++++++++ .../variants/pyscript/mpconfigvariant.h | 3 +++ .../variants/pyscript/mpconfigvariant.mk | 3 +++ 3 files changed, 33 insertions(+) create mode 100644 ports/webassembly/variants/pyscript/manifest.py create mode 100644 ports/webassembly/variants/pyscript/mpconfigvariant.h create mode 100644 ports/webassembly/variants/pyscript/mpconfigvariant.mk diff --git a/ports/webassembly/variants/pyscript/manifest.py b/ports/webassembly/variants/pyscript/manifest.py new file mode 100644 index 0000000000000..0646e1d897f0c --- /dev/null +++ b/ports/webassembly/variants/pyscript/manifest.py @@ -0,0 +1,27 @@ +require("abc") +require("base64") +require("collections") +require("collections-defaultdict") +require("copy") +require("datetime") +require("fnmatch") +require("functools") +require("gzip") +require("hmac") +require("html") +require("inspect") +require("io") +require("itertools") +require("locale") +require("logging") +require("operator") +require("os") +require("os-path") +require("pathlib") +require("stat") +require("tarfile") +require("tarfile-write") +require("time") +require("unittest") +require("uu") +require("zlib") diff --git a/ports/webassembly/variants/pyscript/mpconfigvariant.h b/ports/webassembly/variants/pyscript/mpconfigvariant.h new file mode 100644 index 0000000000000..ed8e812803533 --- /dev/null +++ b/ports/webassembly/variants/pyscript/mpconfigvariant.h @@ -0,0 +1,3 @@ +#define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_FULL_FEATURES) +#define MICROPY_GC_SPLIT_HEAP (1) +#define MICROPY_GC_SPLIT_HEAP_AUTO (1) diff --git a/ports/webassembly/variants/pyscript/mpconfigvariant.mk b/ports/webassembly/variants/pyscript/mpconfigvariant.mk new file mode 100644 index 0000000000000..016b96a99af0a --- /dev/null +++ b/ports/webassembly/variants/pyscript/mpconfigvariant.mk @@ -0,0 +1,3 @@ +JSFLAGS += -s ALLOW_MEMORY_GROWTH + +FROZEN_MANIFEST ?= variants/pyscript/manifest.py From 26d6969fefa18c1dbbb7bc852588fa00ae253d74 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 6 Mar 2024 10:27:54 +1100 Subject: [PATCH 269/408] webassembly: Update README.md to describe latest changes. Signed-off-by: Damien George --- ports/webassembly/README.md | 147 +++++++++++++++++++++++------------- 1 file changed, 96 insertions(+), 51 deletions(-) diff --git a/ports/webassembly/README.md b/ports/webassembly/README.md index abd2864a56cb3..af395778a748e 100644 --- a/ports/webassembly/README.md +++ b/ports/webassembly/README.md @@ -6,22 +6,22 @@ MicroPython for [WebAssembly](https://webassembly.org/). Dependencies ------------ -Building webassembly port bears the same requirements as the standard -MicroPython ports with the addition of Emscripten (and uglify-js for the -minified file). +Building the webassembly port bears the same requirements as the standard +MicroPython ports with the addition of Emscripten, and optionally terser for +the minified file. -The output includes `micropython.js` (a JavaScript wrapper for the -MicroPython runtime) and `firmware.wasm` (actual MicroPython compiled to +The output includes `micropython.mjs` (a JavaScript wrapper for the +MicroPython runtime) and `micropython.wasm` (actual MicroPython compiled to WASM). Build instructions ------------------ -In order to build micropython.js, run: +In order to build `micropython.mjs`, run: $ make -To generate the minified file micropython.min.js, run: +To generate the minified file `micropython.min.mjs`, run: $ make min @@ -30,55 +30,90 @@ Running with Node.js Access the repl with: - $ node build/micropython.js + $ make repl -Stack size may be modified using: +This is the same as running: - $ node build/micropython.js -X stack=64K + $ node build-standard/micropython.mjs -Where stack size may be represented in Bytes, KiB or MiB. +The initial MicroPython GC heap size may be modified using: + + $ node build-standard/micropython.mjs -X heapsize=64k + +Where stack size may be represented in bytes, or have a `k` or `m` suffix. MicroPython scripts may be executed using: - $ node build/micropython.js hello.py + $ node build-standard/micropython.mjs hello.py -Alternatively micropython.js may by accessed by other javascript programs in node +Alternatively `micropython.mjs` may by accessed by other JavaScript programs in node using the require command and the general API outlined below. For example: ```javascript -var mp_js = require('./build/micropython.js'); +const mp_mjs = await import("micropython.mjs"); +const mp = await mp_mjs.loadMicroPython(); + +mp.runPython("print('hello world')"); +``` -mp_js_init(64 * 1024); -await mp_js_do_str("print('hello world')\n"); +Or without await notation: + +```javascript +import("micropython.mjs").then((mp_mjs) => { + mp_mjs.loadMicroPython().then((mp) => { + mp.runPython("print('hello world')"); + }); +}); ``` Running with HTML ----------------- -The prerequisite for browser operation of micropython.js is to listen to the -`micropython-print` event, which is passed data when MicroPython code prints -something to stdout. The following code demonstrates basic functionality: +The following code demonstrates the simplest way to load `micropython.mjs` in a +browser, create an interpreter context, and run some Python code: + +```html + + + + + + + + + +``` + +The output in the above example will go to the JavaScript console. It's possible +to instead capture the output and print it somewhere else, for example in an +HTML element. The following example shows how to do this, and also demonstrates +the use of top-level await and the `js` module: ```html - +

-    
   
 
@@ -98,31 +133,41 @@ Run the test suite using:
 API
 ---
 
-The following functions have been exposed to javascript.
+The following functions have been exposed to JavaScript through the interpreter
+context, created and returned by `loadMicroPython()`.
 
-```
-mp_js_init(stack_size)
-```
+- `PyProxy`: the type of the object that proxies Python objects.
 
-Initialize MicroPython with the given stack size in bytes. This must be
-called before attempting to interact with MicroPython.
+- `FS`: the Emscripten filesystem object.
 
-```
-await mp_js_do_str(code)
-```
+- `globals`: an object exposing the globals from the Python `__main__` module,
+  with methods `get(key)`, `set(key, value)` and `delete(key)`.
 
-Execute the input code. `code` must be a `string`.
+- `registerJsModule(name, module)`: register a JavaScript object as importable
+  from Python with the given name.
 
-```
-mp_js_init_repl()
-```
+- `pyimport`: import a Python module and return it.
 
-Initialize MicroPython repl. Must be called before entering characters into
-the repl.
+- `runPython(code)`: execute Python code and return the result.
 
-```
-await mp_js_process_char(char)
-```
+- `runPythonAsync(code)`: execute Python code and return the result, allowing for
+  top-level await expressions (this call must be await'ed on the JavaScript side).
+
+- `replInit()`: initialise the REPL.
+
+- `replProcessChar(chr)`: process an incoming character at the REPL.
+
+- `replProcessCharWithAsyncify(chr)`: process an incoming character at the REPL,
+  for use when ASYNCIFY is enabled.
+
+Proxying
+--------
+
+A Python `dict` instance is proxied such that:
+
+    for (const key in dict) {
+        print(key, dict[key]);
+    }
 
-Input character into MicroPython repl. `char` must be of type `number`. This
-will execute MicroPython code when necessary.
+works as expected on the JavaScript side and iterates through the keys of the
+Python `dict`.

From c2cf58befcfd54d886fca879f05d8af2368d6cbe Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Mon, 11 Mar 2024 15:02:41 +1100
Subject: [PATCH 270/408] webassembly/library: Fix formatting and style for
 Biome.

Signed-off-by: Damien George 
---
 ports/webassembly/library.js | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/ports/webassembly/library.js b/ports/webassembly/library.js
index db5bac2691443..3f6c9cb61f189 100644
--- a/ports/webassembly/library.js
+++ b/ports/webassembly/library.js
@@ -30,23 +30,33 @@ mergeInto(LibraryManager.library, {
 
     mp_js_ticks_ms: () => Date.now() - MP_JS_EPOCH,
 
-    mp_js_hook: function() {
+    mp_js_hook: () => {
         if (ENVIRONMENT_IS_NODE) {
-            var mp_interrupt_char = Module.ccall('mp_hal_get_interrupt_char', 'number', ['number'], ['null']);
-            var fs = require('fs');
+            const mp_interrupt_char = Module.ccall(
+                "mp_hal_get_interrupt_char",
+                "number",
+                ["number"],
+                ["null"],
+            );
+            const fs = require("fs");
 
-            var buf = Buffer.alloc(1);
+            const buf = Buffer.alloc(1);
             try {
-                var n = fs.readSync(process.stdin.fd, buf, 0, 1);
+                const n = fs.readSync(process.stdin.fd, buf, 0, 1);
                 if (n > 0) {
-                    if (buf[0] == mp_interrupt_char) {
-                        Module.ccall('mp_sched_keyboard_interrupt', 'null', ['null'], ['null']);
+                    if (buf[0] === mp_interrupt_char) {
+                        Module.ccall(
+                            "mp_sched_keyboard_interrupt",
+                            "null",
+                            ["null"],
+                            ["null"],
+                        );
                     } else {
                         process.stdout.write(String.fromCharCode(buf[0]));
                     }
                 }
             } catch (e) {
-                if (e.code === 'EAGAIN') {
+                if (e.code === "EAGAIN") {
                 } else {
                     throw e;
                 }

From e41b571a297bd1682edf6fd98121512bc14ed60d Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Thu, 1 Feb 2024 17:40:59 +1100
Subject: [PATCH 271/408] tests/run-tests.py: Support running webassembly tests
 via node.

This allows running tests with a .js/.mjs suffix, and also .py tests using
node and the webassembly port.

Signed-off-by: Damien George 
---
 tests/run-tests.py | 77 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 75 insertions(+), 2 deletions(-)

diff --git a/tests/run-tests.py b/tests/run-tests.py
index 70279d379df60..83af61c83d20b 100755
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -308,7 +308,9 @@ def send_get(what):
 
     else:
         # run via pyboard interface
-        had_crash, output_mupy = run_script_on_remote_target(pyb, args, test_file, is_special)
+        had_crash, output_mupy = pyb.run_script_on_remote_target(
+            args, test_file_abspath, is_special
+        )
 
     # canonical form for all ports/platforms is to use \n for end-of-line
     output_mupy = output_mupy.replace(b"\r\n", b"\n")
@@ -393,6 +395,51 @@ def value(self):
         return self._value
 
 
+class PyboardNodeRunner:
+    def __init__(self):
+        mjs = os.getenv("MICROPY_MICROPYTHON_MJS")
+        if mjs is None:
+            mjs = base_path("../ports/webassembly/build-standard/micropython.mjs")
+        else:
+            mjs = os.path.abspath(mjs)
+        self.micropython_mjs = mjs
+
+    def close(self):
+        pass
+
+    def run_script_on_remote_target(self, args, test_file, is_special):
+        cwd = os.path.dirname(test_file)
+
+        # Create system command list.
+        cmdlist = ["node"]
+        if test_file.endswith(".py"):
+            # Run a Python script indirectly via "node micropython.mjs ".
+            cmdlist.append(self.micropython_mjs)
+            if args.heapsize is not None:
+                cmdlist.extend(["-X", "heapsize=" + args.heapsize])
+            cmdlist.append(test_file)
+        else:
+            # Run a js/mjs script directly with Node, passing in the path to micropython.mjs.
+            cmdlist.append(test_file)
+            cmdlist.append(self.micropython_mjs)
+
+        # Run the script.
+        try:
+            had_crash = False
+            output_mupy = subprocess.check_output(
+                cmdlist, stderr=subprocess.STDOUT, timeout=TEST_TIMEOUT, cwd=cwd
+            )
+        except subprocess.CalledProcessError as er:
+            had_crash = True
+            output_mupy = er.output + b"CRASH"
+        except subprocess.TimeoutExpired as er:
+            had_crash = True
+            output_mupy = (er.output or b"") + b"TIMEOUT"
+
+        # Return the results.
+        return had_crash, output_mupy
+
+
 def run_tests(pyb, tests, args, result_dir, num_threads=1):
     test_count = ThreadSafeCounter()
     testcase_count = ThreadSafeCounter()
@@ -631,6 +678,20 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1):
             )  # RA fsp rtc function doesn't support nano sec info
         elif args.target == "qemu-arm":
             skip_tests.add("misc/print_exception.py")  # requires sys stdfiles
+        elif args.target == "webassembly":
+            skip_tests.add("basics/string_format_modulo.py")  # can't print nulls to stdout
+            skip_tests.add("basics/string_strip.py")  # can't print nulls to stdout
+            skip_tests.add("extmod/binascii_a2b_base64.py")
+            skip_tests.add("extmod/re_stack_overflow.py")
+            skip_tests.add("extmod/time_res.py")
+            skip_tests.add("extmod/vfs_posix.py")
+            skip_tests.add("extmod/vfs_posix_enoent.py")
+            skip_tests.add("extmod/vfs_posix_paths.py")
+            skip_tests.add("extmod/vfs_userfs.py")
+            skip_tests.add("micropython/emg_exc.py")
+            skip_tests.add("micropython/extreme_exc.py")
+            skip_tests.add("micropython/heapalloc_exc_compressed_emg_exc.py")
+            skip_tests.add("micropython/import_mpy_invalid.py")
 
     # Some tests are known to fail on 64-bit machines
     if pyb is None and platform.architecture()[0] == "64bit":
@@ -977,6 +1038,7 @@ def main():
     LOCAL_TARGETS = (
         "unix",
         "qemu-arm",
+        "webassembly",
     )
     EXTERNAL_TARGETS = (
         "pyboard",
@@ -997,6 +1059,8 @@ def main():
                 args.mpy_cross_flags = "-march=host"
             elif args.target == "qemu-arm":
                 args.mpy_cross_flags = "-march=armv7m"
+        if args.target == "webassembly":
+            pyb = PyboardNodeRunner()
     elif args.target in EXTERNAL_TARGETS:
         global pyboard
         sys.path.append(base_path("../tools"))
@@ -1015,6 +1079,7 @@ def main():
                 args.mpy_cross_flags = "-march=armv7m"
 
         pyb = pyboard.Pyboard(args.device, args.baudrate, args.user, args.password)
+        pyboard.Pyboard.run_script_on_remote_target = run_script_on_remote_target
         pyb.enter_raw_repl()
     else:
         raise ValueError("target must be one of %s" % ", ".join(LOCAL_TARGETS + EXTERNAL_TARGETS))
@@ -1032,6 +1097,10 @@ def main():
         else:
             tests = []
     elif len(args.files) == 0:
+        test_extensions = ("*.py",)
+        if args.target == "webassembly":
+            test_extensions += ("*.js", "*.mjs")
+
         if args.test_dirs is None:
             test_dirs = (
                 "basics",
@@ -1072,12 +1141,16 @@ def main():
                     "inlineasm",
                     "ports/qemu-arm",
                 )
+            elif args.target == "webassembly":
+                test_dirs += ("float",)
         else:
             # run tests from these directories
             test_dirs = args.test_dirs
         tests = sorted(
             test_file
-            for test_files in (glob("{}/*.py".format(dir)) for dir in test_dirs)
+            for test_files in (
+                glob(os.path.join(dir, ext)) for dir in test_dirs for ext in test_extensions
+            )
             for test_file in test_files
         )
     else:

From c1513a078dcde3eba74c4572b62b354aed404e21 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Thu, 1 Feb 2024 17:43:25 +1100
Subject: [PATCH 272/408] tests/ports/webassembly: Add webassembly JS tests.

Signed-off-by: Damien George 
---
 tests/ports/webassembly/basic.js              |   8 ++
 tests/ports/webassembly/basic.js.exp          |   3 +
 tests/ports/webassembly/filesystem.mjs        |   9 ++
 tests/ports/webassembly/filesystem.mjs.exp    |   3 +
 tests/ports/webassembly/float.mjs             |  43 +++++++
 tests/ports/webassembly/float.mjs.exp         |  14 +++
 tests/ports/webassembly/fun_call.mjs          |  17 +++
 tests/ports/webassembly/fun_call.mjs.exp      |   7 ++
 tests/ports/webassembly/globals.mjs           |  13 ++
 tests/ports/webassembly/globals.mjs.exp       |   4 +
 tests/ports/webassembly/heap_expand.mjs       |  15 +++
 tests/ports/webassembly/heap_expand.mjs.exp   |  48 ++++++++
 .../ports/webassembly/jsffi_create_proxy.mjs  |  15 +++
 .../webassembly/jsffi_create_proxy.mjs.exp    |   6 +
 tests/ports/webassembly/jsffi_to_js.mjs       |  28 +++++
 tests/ports/webassembly/jsffi_to_js.mjs.exp   |  11 ++
 tests/ports/webassembly/override_new.mjs      |  33 +++++
 tests/ports/webassembly/override_new.mjs.exp  |   7 ++
 .../webassembly/promise_with_resolvers.mjs    |  23 ++++
 .../promise_with_resolvers.mjs.exp            |   1 +
 tests/ports/webassembly/py_proxy_delete.mjs   |  30 +++++
 .../ports/webassembly/py_proxy_delete.mjs.exp |   2 +
 tests/ports/webassembly/py_proxy_dict.mjs     |  34 ++++++
 tests/ports/webassembly/py_proxy_dict.mjs.exp |  11 ++
 tests/ports/webassembly/py_proxy_has.mjs      |  11 ++
 tests/ports/webassembly/py_proxy_has.mjs.exp  |   2 +
 tests/ports/webassembly/py_proxy_own_keys.mjs |  11 ++
 .../webassembly/py_proxy_own_keys.mjs.exp     |   9 ++
 tests/ports/webassembly/py_proxy_set.mjs      |  27 ++++
 tests/ports/webassembly/py_proxy_set.mjs.exp  |   2 +
 tests/ports/webassembly/py_proxy_to_js.mjs    |  20 +++
 .../ports/webassembly/py_proxy_to_js.mjs.exp  |   4 +
 tests/ports/webassembly/register_js_module.js |   6 +
 .../webassembly/register_js_module.js.exp     |   2 +
 tests/ports/webassembly/run_python_async.mjs  | 115 ++++++++++++++++++
 .../webassembly/run_python_async.mjs.exp      |  38 ++++++
 tests/ports/webassembly/run_python_async2.mjs |  42 +++++++
 .../webassembly/run_python_async2.mjs.exp     |   8 ++
 tests/ports/webassembly/this_behaviour.mjs    |  24 ++++
 .../ports/webassembly/this_behaviour.mjs.exp  |   4 +
 tests/ports/webassembly/various.js            |  38 ++++++
 tests/ports/webassembly/various.js.exp        |   8 ++
 tests/run-tests.py                            |   2 +-
 43 files changed, 757 insertions(+), 1 deletion(-)
 create mode 100644 tests/ports/webassembly/basic.js
 create mode 100644 tests/ports/webassembly/basic.js.exp
 create mode 100644 tests/ports/webassembly/filesystem.mjs
 create mode 100644 tests/ports/webassembly/filesystem.mjs.exp
 create mode 100644 tests/ports/webassembly/float.mjs
 create mode 100644 tests/ports/webassembly/float.mjs.exp
 create mode 100644 tests/ports/webassembly/fun_call.mjs
 create mode 100644 tests/ports/webassembly/fun_call.mjs.exp
 create mode 100644 tests/ports/webassembly/globals.mjs
 create mode 100644 tests/ports/webassembly/globals.mjs.exp
 create mode 100644 tests/ports/webassembly/heap_expand.mjs
 create mode 100644 tests/ports/webassembly/heap_expand.mjs.exp
 create mode 100644 tests/ports/webassembly/jsffi_create_proxy.mjs
 create mode 100644 tests/ports/webassembly/jsffi_create_proxy.mjs.exp
 create mode 100644 tests/ports/webassembly/jsffi_to_js.mjs
 create mode 100644 tests/ports/webassembly/jsffi_to_js.mjs.exp
 create mode 100644 tests/ports/webassembly/override_new.mjs
 create mode 100644 tests/ports/webassembly/override_new.mjs.exp
 create mode 100644 tests/ports/webassembly/promise_with_resolvers.mjs
 create mode 100644 tests/ports/webassembly/promise_with_resolvers.mjs.exp
 create mode 100644 tests/ports/webassembly/py_proxy_delete.mjs
 create mode 100644 tests/ports/webassembly/py_proxy_delete.mjs.exp
 create mode 100644 tests/ports/webassembly/py_proxy_dict.mjs
 create mode 100644 tests/ports/webassembly/py_proxy_dict.mjs.exp
 create mode 100644 tests/ports/webassembly/py_proxy_has.mjs
 create mode 100644 tests/ports/webassembly/py_proxy_has.mjs.exp
 create mode 100644 tests/ports/webassembly/py_proxy_own_keys.mjs
 create mode 100644 tests/ports/webassembly/py_proxy_own_keys.mjs.exp
 create mode 100644 tests/ports/webassembly/py_proxy_set.mjs
 create mode 100644 tests/ports/webassembly/py_proxy_set.mjs.exp
 create mode 100644 tests/ports/webassembly/py_proxy_to_js.mjs
 create mode 100644 tests/ports/webassembly/py_proxy_to_js.mjs.exp
 create mode 100644 tests/ports/webassembly/register_js_module.js
 create mode 100644 tests/ports/webassembly/register_js_module.js.exp
 create mode 100644 tests/ports/webassembly/run_python_async.mjs
 create mode 100644 tests/ports/webassembly/run_python_async.mjs.exp
 create mode 100644 tests/ports/webassembly/run_python_async2.mjs
 create mode 100644 tests/ports/webassembly/run_python_async2.mjs.exp
 create mode 100644 tests/ports/webassembly/this_behaviour.mjs
 create mode 100644 tests/ports/webassembly/this_behaviour.mjs.exp
 create mode 100644 tests/ports/webassembly/various.js
 create mode 100644 tests/ports/webassembly/various.js.exp

diff --git a/tests/ports/webassembly/basic.js b/tests/ports/webassembly/basic.js
new file mode 100644
index 0000000000000..19b1881faf5ca
--- /dev/null
+++ b/tests/ports/webassembly/basic.js
@@ -0,0 +1,8 @@
+import(process.argv[2]).then((mp) => {
+    mp.loadMicroPython().then((py) => {
+        py.runPython("1");
+        py.runPython("print('hello')");
+        py.runPython("import sys; print(f'hello from {sys.platform}')");
+        py.runPython("import collections; print(collections.OrderedDict)");
+    });
+});
diff --git a/tests/ports/webassembly/basic.js.exp b/tests/ports/webassembly/basic.js.exp
new file mode 100644
index 0000000000000..6459b2492cf86
--- /dev/null
+++ b/tests/ports/webassembly/basic.js.exp
@@ -0,0 +1,3 @@
+hello
+hello from webassembly
+
diff --git a/tests/ports/webassembly/filesystem.mjs b/tests/ports/webassembly/filesystem.mjs
new file mode 100644
index 0000000000000..e9e2920a16105
--- /dev/null
+++ b/tests/ports/webassembly/filesystem.mjs
@@ -0,0 +1,9 @@
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+mp.FS.mkdir("/lib/");
+mp.FS.writeFile("/lib/testmod.py", "x = 1; print(__name__, x)");
+mp.runPython("import testmod");
+
+mp.runPython("import sys; sys.modules.clear()");
+const testmod = mp.pyimport("testmod");
+console.log("testmod:", testmod, testmod.x);
diff --git a/tests/ports/webassembly/filesystem.mjs.exp b/tests/ports/webassembly/filesystem.mjs.exp
new file mode 100644
index 0000000000000..25a48b10832c5
--- /dev/null
+++ b/tests/ports/webassembly/filesystem.mjs.exp
@@ -0,0 +1,3 @@
+testmod 1
+testmod 1
+testmod: PyProxy { _ref: 3 } 1
diff --git a/tests/ports/webassembly/float.mjs b/tests/ports/webassembly/float.mjs
new file mode 100644
index 0000000000000..53bb8b1c4d0ad
--- /dev/null
+++ b/tests/ports/webassembly/float.mjs
@@ -0,0 +1,43 @@
+// Test passing floats between JavaScript and Python.
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+globalThis.a = 1 / 2;
+globalThis.b = Infinity;
+globalThis.c = NaN;
+
+mp.runPython(`
+import js
+
+# Test retrieving floats from JS.
+print(js.a)
+print(js.b)
+print(js.c)
+
+# Test calling JS which returns a float.
+r = js.Math.random()
+print(type(r), 0 < r < 1)
+
+x = 1 / 2
+y = float("inf")
+z = float("nan")
+
+# Test passing floats to a JS function.
+js.console.log(x)
+js.console.log(x, y)
+js.console.log(x, y, z)
+`);
+
+// Test retrieving floats from Python.
+console.log(mp.globals.get("x"));
+console.log(mp.globals.get("y"));
+console.log(mp.globals.get("z"));
+
+// Test passing floats to a Python function.
+const mp_print = mp.pyimport("builtins").print;
+mp_print(globalThis.a);
+mp_print(globalThis.a, globalThis.b);
+mp_print(globalThis.a, globalThis.b, globalThis.c);
+
+// Test calling Python which returns a float.
+console.log(mp.pyimport("math").sqrt(0.16));
diff --git a/tests/ports/webassembly/float.mjs.exp b/tests/ports/webassembly/float.mjs.exp
new file mode 100644
index 0000000000000..57eff74acd8af
--- /dev/null
+++ b/tests/ports/webassembly/float.mjs.exp
@@ -0,0 +1,14 @@
+0.5
+inf
+nan
+ True
+0.5
+0.5 Infinity
+0.5 Infinity NaN
+0.5
+Infinity
+NaN
+0.5
+0.5 inf
+0.5 inf nan
+0.4
diff --git a/tests/ports/webassembly/fun_call.mjs b/tests/ports/webassembly/fun_call.mjs
new file mode 100644
index 0000000000000..295745d2e2e34
--- /dev/null
+++ b/tests/ports/webassembly/fun_call.mjs
@@ -0,0 +1,17 @@
+// Test calling JavaScript functions from Python.
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+globalThis.f = (a, b, c, d, e) => {
+    console.log(a, b, c, d, e);
+};
+mp.runPython(`
+import js
+js.f()
+js.f(1)
+js.f(1, 2)
+js.f(1, 2, 3)
+js.f(1, 2, 3, 4)
+js.f(1, 2, 3, 4, 5)
+js.f(1, 2, 3, 4, 5, 6)
+`);
diff --git a/tests/ports/webassembly/fun_call.mjs.exp b/tests/ports/webassembly/fun_call.mjs.exp
new file mode 100644
index 0000000000000..e9ed5f6ddf9de
--- /dev/null
+++ b/tests/ports/webassembly/fun_call.mjs.exp
@@ -0,0 +1,7 @@
+undefined undefined undefined undefined undefined
+1 undefined undefined undefined undefined
+1 2 undefined undefined undefined
+1 2 3 undefined undefined
+1 2 3 4 undefined
+1 2 3 4 5
+1 2 3 4 5
diff --git a/tests/ports/webassembly/globals.mjs b/tests/ports/webassembly/globals.mjs
new file mode 100644
index 0000000000000..3d5ecb4167878
--- /dev/null
+++ b/tests/ports/webassembly/globals.mjs
@@ -0,0 +1,13 @@
+// Test accessing Python globals dict via mp.globals.
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+mp.runPython("x = 1");
+console.log(mp.globals.get("x"));
+
+mp.globals.set("y", 2);
+mp.runPython("print(y)");
+
+mp.runPython("print('y' in globals())");
+mp.globals.delete("y");
+mp.runPython("print('y' in globals())");
diff --git a/tests/ports/webassembly/globals.mjs.exp b/tests/ports/webassembly/globals.mjs.exp
new file mode 100644
index 0000000000000..a118c13fecba9
--- /dev/null
+++ b/tests/ports/webassembly/globals.mjs.exp
@@ -0,0 +1,4 @@
+1
+2
+True
+False
diff --git a/tests/ports/webassembly/heap_expand.mjs b/tests/ports/webassembly/heap_expand.mjs
new file mode 100644
index 0000000000000..2cf7c07b0b823
--- /dev/null
+++ b/tests/ports/webassembly/heap_expand.mjs
@@ -0,0 +1,15 @@
+// Test expanding the MicroPython GC heap.
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+mp.runPython(`
+import gc
+bs = []
+for i in range(24):
+    b = bytearray(1 << i)
+    bs.append(b)
+    gc.collect()
+    print(gc.mem_free())
+for b in bs:
+    print(len(b))
+`);
diff --git a/tests/ports/webassembly/heap_expand.mjs.exp b/tests/ports/webassembly/heap_expand.mjs.exp
new file mode 100644
index 0000000000000..ee14908409d86
--- /dev/null
+++ b/tests/ports/webassembly/heap_expand.mjs.exp
@@ -0,0 +1,48 @@
+135241360
+135241328
+135241296
+135241264
+135241216
+135241168
+135241088
+135240944
+135240640
+135240112
+135239072
+135237008
+135232896
+135224688
+135208288
+135175504
+135109888
+134978800
+134716640
+135216848
+136217216
+138218032
+142219616
+150222864
+1
+2
+4
+8
+16
+32
+64
+128
+256
+512
+1024
+2048
+4096
+8192
+16384
+32768
+65536
+131072
+262144
+524288
+1048576
+2097152
+4194304
+8388608
diff --git a/tests/ports/webassembly/jsffi_create_proxy.mjs b/tests/ports/webassembly/jsffi_create_proxy.mjs
new file mode 100644
index 0000000000000..5f04bf44d7e21
--- /dev/null
+++ b/tests/ports/webassembly/jsffi_create_proxy.mjs
@@ -0,0 +1,15 @@
+// Test jsffi.create_proxy().
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+mp.runPython(`
+import jsffi
+x = jsffi.create_proxy(1)
+print(x)
+y = jsffi.create_proxy([2])
+print(y)
+`);
+console.log(mp.globals.get("x"));
+console.log(mp.PyProxy.toJs(mp.globals.get("x")));
+console.log(mp.globals.get("y"));
+console.log(mp.PyProxy.toJs(mp.globals.get("y")));
diff --git a/tests/ports/webassembly/jsffi_create_proxy.mjs.exp b/tests/ports/webassembly/jsffi_create_proxy.mjs.exp
new file mode 100644
index 0000000000000..a3b38a78b1132
--- /dev/null
+++ b/tests/ports/webassembly/jsffi_create_proxy.mjs.exp
@@ -0,0 +1,6 @@
+1
+
+1
+1
+PyProxy { _ref: 3 }
+[ 2 ]
diff --git a/tests/ports/webassembly/jsffi_to_js.mjs b/tests/ports/webassembly/jsffi_to_js.mjs
new file mode 100644
index 0000000000000..714af6b629937
--- /dev/null
+++ b/tests/ports/webassembly/jsffi_to_js.mjs
@@ -0,0 +1,28 @@
+// Test jsffi.to_js().
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+mp.runPython(`
+import jsffi
+x = jsffi.to_js(1)
+print(x)
+y = jsffi.to_js([2])
+print(y)
+z = jsffi.to_js({"three":3})
+print(z)
+`);
+
+const x = mp.globals.get("x");
+const y = mp.globals.get("y");
+const z = mp.globals.get("z");
+
+console.log(Array.isArray(x));
+console.log(x);
+
+console.log(Array.isArray(y));
+console.log(y);
+console.log(Reflect.ownKeys(y));
+
+console.log(Array.isArray(z));
+console.log(z);
+console.log(Reflect.ownKeys(z));
diff --git a/tests/ports/webassembly/jsffi_to_js.mjs.exp b/tests/ports/webassembly/jsffi_to_js.mjs.exp
new file mode 100644
index 0000000000000..399dd0aa8c9cb
--- /dev/null
+++ b/tests/ports/webassembly/jsffi_to_js.mjs.exp
@@ -0,0 +1,11 @@
+1
+
+
+false
+1
+true
+[ 2 ]
+[ '0', 'length' ]
+false
+{ three: 3 }
+[ 'three' ]
diff --git a/tests/ports/webassembly/override_new.mjs b/tests/ports/webassembly/override_new.mjs
new file mode 100644
index 0000000000000..f5d64d7d11379
--- /dev/null
+++ b/tests/ports/webassembly/override_new.mjs
@@ -0,0 +1,33 @@
+// Test overriding .new() on a JavaScript class.
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+globalThis.MyClass1 = class {
+    new() {
+        console.log("MyClass1 new");
+        return 1;
+    }
+};
+
+globalThis.MyClass2 = class {
+    static new() {
+        console.log("MyClass2 static new");
+        return 2;
+    }
+    new() {
+        console.log("MyClass2 new");
+        return 3;
+    }
+};
+
+globalThis.myClass2Instance = new globalThis.MyClass2();
+
+mp.runPython(`
+    import js
+
+    print(type(js.MyClass1.new()))
+    print(js.MyClass1.new().new())
+
+    print(js.MyClass2.new())
+    print(js.myClass2Instance.new())
+`);
diff --git a/tests/ports/webassembly/override_new.mjs.exp b/tests/ports/webassembly/override_new.mjs.exp
new file mode 100644
index 0000000000000..2efb669714ed4
--- /dev/null
+++ b/tests/ports/webassembly/override_new.mjs.exp
@@ -0,0 +1,7 @@
+
+MyClass1 new
+1
+MyClass2 static new
+2
+MyClass2 new
+3
diff --git a/tests/ports/webassembly/promise_with_resolvers.mjs b/tests/ports/webassembly/promise_with_resolvers.mjs
new file mode 100644
index 0000000000000..a2c6d509a6095
--- /dev/null
+++ b/tests/ports/webassembly/promise_with_resolvers.mjs
@@ -0,0 +1,23 @@
+// Test polyfill of a method on a built-in.
+
+// Implement Promise.withResolvers, and make sure it has a unique name so
+// the test below is guaranteed to use this version.
+Promise.withResolversCustom = function withResolversCustom() {
+    let a;
+    let b;
+    const c = new this((resolve, reject) => {
+        a = resolve;
+        b = reject;
+    });
+    return { resolve: a, reject: b, promise: c };
+};
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+mp.runPython(`
+    from js import Promise
+
+    deferred = Promise.withResolversCustom()
+    deferred.promise.then(print)
+    deferred.resolve('OK')
+`);
diff --git a/tests/ports/webassembly/promise_with_resolvers.mjs.exp b/tests/ports/webassembly/promise_with_resolvers.mjs.exp
new file mode 100644
index 0000000000000..d86bac9de59ab
--- /dev/null
+++ b/tests/ports/webassembly/promise_with_resolvers.mjs.exp
@@ -0,0 +1 @@
+OK
diff --git a/tests/ports/webassembly/py_proxy_delete.mjs b/tests/ports/webassembly/py_proxy_delete.mjs
new file mode 100644
index 0000000000000..2afea0b9f2221
--- /dev/null
+++ b/tests/ports/webassembly/py_proxy_delete.mjs
@@ -0,0 +1,30 @@
+// Test `delete .` on the JavaScript side, which tests PyProxy.deleteProperty.
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+mp.runPython(`
+class A:
+    pass
+x = A()
+x.foo = 1
+y = []
+`);
+
+const x = mp.globals.get("x");
+const y = mp.globals.get("y");
+
+// Should pass.
+// biome-ignore lint/performance/noDelete: test delete statement
+delete x.foo;
+
+mp.runPython(`
+print(hasattr(x, "foo"))
+`);
+
+// Should fail, can't delete attributes on MicroPython lists.
+try {
+    // biome-ignore lint/performance/noDelete: test delete statement
+    delete y.sort;
+} catch (error) {
+    console.log(error.message);
+}
diff --git a/tests/ports/webassembly/py_proxy_delete.mjs.exp b/tests/ports/webassembly/py_proxy_delete.mjs.exp
new file mode 100644
index 0000000000000..8eb9ad1501419
--- /dev/null
+++ b/tests/ports/webassembly/py_proxy_delete.mjs.exp
@@ -0,0 +1,2 @@
+False
+'deleteProperty' on proxy: trap returned falsish for property 'sort'
diff --git a/tests/ports/webassembly/py_proxy_dict.mjs b/tests/ports/webassembly/py_proxy_dict.mjs
new file mode 100644
index 0000000000000..201f179ef377b
--- /dev/null
+++ b/tests/ports/webassembly/py_proxy_dict.mjs
@@ -0,0 +1,34 @@
+// Test passing a Python dict into JavaScript, it should act like a JS object.
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+mp.runPython(`
+x = {"a": 1, "b": 2}
+`);
+
+const x = mp.globals.get("x");
+
+// Test has, get, keys/iteration.
+console.log("a" in x, "b" in x, "c" in x);
+console.log(x.a, x.b);
+for (const k in x) {
+    console.log(k, x[k]);
+}
+console.log(Object.keys(x));
+console.log(Reflect.ownKeys(x));
+
+// Test set.
+x.c = 3;
+console.log(Object.keys(x));
+
+// Test delete.
+// biome-ignore lint/performance/noDelete: test delete statement
+delete x.b;
+console.log(Object.keys(x));
+
+// Make sure changes on the JavaScript side are reflected in Python.
+mp.runPython(`
+print(x["a"])
+print("b" in x)
+print(x["c"])
+`);
diff --git a/tests/ports/webassembly/py_proxy_dict.mjs.exp b/tests/ports/webassembly/py_proxy_dict.mjs.exp
new file mode 100644
index 0000000000000..f0e15034bd71c
--- /dev/null
+++ b/tests/ports/webassembly/py_proxy_dict.mjs.exp
@@ -0,0 +1,11 @@
+true true false
+1 2
+a 1
+b 2
+[ 'a', 'b' ]
+[ 'a', 'b' ]
+[ 'a', 'c', 'b' ]
+[ 'a', 'c' ]
+1
+False
+3
diff --git a/tests/ports/webassembly/py_proxy_has.mjs b/tests/ports/webassembly/py_proxy_has.mjs
new file mode 100644
index 0000000000000..8881776fdbe51
--- /dev/null
+++ b/tests/ports/webassembly/py_proxy_has.mjs
@@ -0,0 +1,11 @@
+// Test ` in ` on the JavaScript side, which tests PyProxy.has.
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+mp.runPython(`
+x = []
+`);
+
+const x = mp.globals.get("x");
+console.log("no_exist" in x);
+console.log("sort" in x);
diff --git a/tests/ports/webassembly/py_proxy_has.mjs.exp b/tests/ports/webassembly/py_proxy_has.mjs.exp
new file mode 100644
index 0000000000000..1d474d5255713
--- /dev/null
+++ b/tests/ports/webassembly/py_proxy_has.mjs.exp
@@ -0,0 +1,2 @@
+false
+true
diff --git a/tests/ports/webassembly/py_proxy_own_keys.mjs b/tests/ports/webassembly/py_proxy_own_keys.mjs
new file mode 100644
index 0000000000000..bbf5b4f01c056
--- /dev/null
+++ b/tests/ports/webassembly/py_proxy_own_keys.mjs
@@ -0,0 +1,11 @@
+// Test `Reflect.ownKeys()` on the JavaScript side, which tests PyProxy.ownKeys.
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+mp.runPython(`
+x = []
+y = {"a": 1}
+`);
+
+console.log(Reflect.ownKeys(mp.globals.get("x")));
+console.log(Reflect.ownKeys(mp.globals.get("y")));
diff --git a/tests/ports/webassembly/py_proxy_own_keys.mjs.exp b/tests/ports/webassembly/py_proxy_own_keys.mjs.exp
new file mode 100644
index 0000000000000..313d06d4d75da
--- /dev/null
+++ b/tests/ports/webassembly/py_proxy_own_keys.mjs.exp
@@ -0,0 +1,9 @@
+[
+  'append', 'clear',
+  'copy',   'count',
+  'extend', 'index',
+  'insert', 'pop',
+  'remove', 'reverse',
+  'sort'
+]
+[ 'a' ]
diff --git a/tests/ports/webassembly/py_proxy_set.mjs b/tests/ports/webassembly/py_proxy_set.mjs
new file mode 100644
index 0000000000000..30360a847d806
--- /dev/null
+++ b/tests/ports/webassembly/py_proxy_set.mjs
@@ -0,0 +1,27 @@
+// Test `. = ` on the JavaScript side, which tests PyProxy.set.
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+mp.runPython(`
+class A:
+    pass
+x = A()
+y = []
+`);
+
+const x = mp.globals.get("x");
+const y = mp.globals.get("y");
+
+// Should pass.
+x.foo = 1;
+
+mp.runPython(`
+print(x.foo)
+`);
+
+// Should fail, can't set attributes on MicroPython lists.
+try {
+    y.bar = 1;
+} catch (error) {
+    console.log(error.message);
+}
diff --git a/tests/ports/webassembly/py_proxy_set.mjs.exp b/tests/ports/webassembly/py_proxy_set.mjs.exp
new file mode 100644
index 0000000000000..e1d995156341e
--- /dev/null
+++ b/tests/ports/webassembly/py_proxy_set.mjs.exp
@@ -0,0 +1,2 @@
+1
+'set' on proxy: trap returned falsish for property 'bar'
diff --git a/tests/ports/webassembly/py_proxy_to_js.mjs b/tests/ports/webassembly/py_proxy_to_js.mjs
new file mode 100644
index 0000000000000..f9fce606f1fdf
--- /dev/null
+++ b/tests/ports/webassembly/py_proxy_to_js.mjs
@@ -0,0 +1,20 @@
+// Test PyProxy.toJs().
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+mp.runPython(`
+a = 1
+b = (1, 2, 3)
+c = [None, True, 1.2]
+d = {"one": 1, "tuple": b, "list": c}
+`);
+
+const py_a = mp.globals.get("a");
+const py_b = mp.globals.get("b");
+const py_c = mp.globals.get("c");
+const py_d = mp.globals.get("d");
+
+console.log(py_a instanceof mp.PyProxy, mp.PyProxy.toJs(py_a));
+console.log(py_b instanceof mp.PyProxy, mp.PyProxy.toJs(py_b));
+console.log(py_c instanceof mp.PyProxy, mp.PyProxy.toJs(py_c));
+console.log(py_d instanceof mp.PyProxy, mp.PyProxy.toJs(py_d));
diff --git a/tests/ports/webassembly/py_proxy_to_js.mjs.exp b/tests/ports/webassembly/py_proxy_to_js.mjs.exp
new file mode 100644
index 0000000000000..279df7bdfbb84
--- /dev/null
+++ b/tests/ports/webassembly/py_proxy_to_js.mjs.exp
@@ -0,0 +1,4 @@
+false 1
+true [ 1, 2, 3 ]
+true [ null, true, 1.2 ]
+true { tuple: [ 1, 2, 3 ], one: 1, list: [ null, true, 1.2 ] }
diff --git a/tests/ports/webassembly/register_js_module.js b/tests/ports/webassembly/register_js_module.js
new file mode 100644
index 0000000000000..b512f2c0dd465
--- /dev/null
+++ b/tests/ports/webassembly/register_js_module.js
@@ -0,0 +1,6 @@
+import(process.argv[2]).then((mp) => {
+    mp.loadMicroPython().then((py) => {
+        py.registerJsModule("js_module", { y: 2 });
+        py.runPython("import js_module; print(js_module); print(js_module.y)");
+    });
+});
diff --git a/tests/ports/webassembly/register_js_module.js.exp b/tests/ports/webassembly/register_js_module.js.exp
new file mode 100644
index 0000000000000..bb45f4ce00285
--- /dev/null
+++ b/tests/ports/webassembly/register_js_module.js.exp
@@ -0,0 +1,2 @@
+
+2
diff --git a/tests/ports/webassembly/run_python_async.mjs b/tests/ports/webassembly/run_python_async.mjs
new file mode 100644
index 0000000000000..44f2a90ab175d
--- /dev/null
+++ b/tests/ports/webassembly/run_python_async.mjs
@@ -0,0 +1,115 @@
+// Test runPythonAsync() and top-level await in Python.
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+/**********************************************************/
+// Using only promise objects, no await's.
+
+console.log("= TEST 1 ==========");
+
+globalThis.p = new Promise((resolve, reject) => {
+    resolve(123);
+});
+
+console.log(1);
+
+mp.runPython(`
+import js
+print(js.p)
+print("py 1")
+print(js.p.then(lambda x: print("resolved", x)))
+print("py 2")
+`);
+
+console.log(2);
+
+// Let the promise resolve.
+await globalThis.p;
+
+console.log(3);
+
+/**********************************************************/
+// Using setTimeout to resolve the promise.
+
+console.log("= TEST 2 ==========");
+
+globalThis.p = new Promise((resolve, reject) => {
+    setTimeout(() => {
+        resolve(123);
+        console.log("setTimeout resolved");
+    }, 100);
+});
+
+console.log(1);
+
+mp.runPython(`
+import js
+print(js.p)
+print("py 1")
+print(js.p.then(lambda x: print("resolved", x)))
+print("py 2")
+`);
+
+console.log(2);
+
+// Let the promise resolve.
+await globalThis.p;
+
+console.log(3);
+
+/**********************************************************/
+// Using setTimeout and await within Python.
+
+console.log("= TEST 3 ==========");
+
+globalThis.p = new Promise((resolve, reject) => {
+    setTimeout(() => {
+        resolve(123);
+        console.log("setTimeout resolved");
+    }, 100);
+});
+
+console.log(1);
+
+const ret3 = await mp.runPythonAsync(`
+import js
+print("py 1")
+print("resolved value:", await js.p)
+print("py 2")
+`);
+
+console.log(2, ret3);
+
+/**********************************************************/
+// Multiple setTimeout's and await's within Python.
+
+console.log("= TEST 4 ==========");
+
+globalThis.p1 = new Promise((resolve, reject) => {
+    setTimeout(() => {
+        resolve(123);
+        console.log("setTimeout A resolved");
+    }, 100);
+});
+
+globalThis.p2 = new Promise((resolve, reject) => {
+    setTimeout(() => {
+        resolve(456);
+        console.log("setTimeout B resolved");
+    }, 200);
+});
+
+console.log(1);
+
+const ret4 = await mp.runPythonAsync(`
+import js
+print("py 1")
+print("resolved value:", await js.p1)
+print("py 2")
+print("resolved value:", await js.p1)
+print("py 3")
+print("resolved value:", await js.p2)
+print("py 4")
+`);
+
+console.log(2, ret4);
diff --git a/tests/ports/webassembly/run_python_async.mjs.exp b/tests/ports/webassembly/run_python_async.mjs.exp
new file mode 100644
index 0000000000000..f441bc5cf1db6
--- /dev/null
+++ b/tests/ports/webassembly/run_python_async.mjs.exp
@@ -0,0 +1,38 @@
+= TEST 1 ==========
+1
+
+py 1
+
+py 2
+2
+resolved 123
+3
+= TEST 2 ==========
+1
+
+py 1
+
+py 2
+2
+setTimeout resolved
+resolved 123
+3
+= TEST 3 ==========
+1
+py 1
+setTimeout resolved
+resolved value: 123
+py 2
+2 null
+= TEST 4 ==========
+1
+py 1
+setTimeout A resolved
+resolved value: 123
+py 2
+resolved value: 123
+py 3
+setTimeout B resolved
+resolved value: 456
+py 4
+2 null
diff --git a/tests/ports/webassembly/run_python_async2.mjs b/tests/ports/webassembly/run_python_async2.mjs
new file mode 100644
index 0000000000000..87067e6e8c403
--- /dev/null
+++ b/tests/ports/webassembly/run_python_async2.mjs
@@ -0,0 +1,42 @@
+// Test runPythonAsync() and top-level await in Python, with multi-level awaits.
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+// simulate a 2-step resolution of the string "OK".
+await mp.runPythonAsync(`
+import js
+
+def _timeout(resolve, _):
+    js.setTimeout(resolve, 100)
+
+def _fetch():
+    return js.Promise.new(_timeout)
+
+async def _text(promise):
+    if not promise._response:
+        print("_text await start")
+        await promise
+        print("_text awaited end")
+    ret = await promise._response.text()
+    return ret
+
+class _Response:
+    async def text(self):
+        print('_Response.text start')
+        await js.Promise.new(_timeout)
+        print('_Response.text end')
+        return "OK"
+
+def _response(promise):
+    promise._response = _Response()
+    return promise._response
+
+def fetch(url):
+    promise = _fetch().then(lambda *_: _response(promise))
+    promise._response = None
+    promise.text = lambda: _text(promise)
+    return promise
+
+print(await fetch("config.json").text())
+print(await (await fetch("config.json")).text())
+`);
diff --git a/tests/ports/webassembly/run_python_async2.mjs.exp b/tests/ports/webassembly/run_python_async2.mjs.exp
new file mode 100644
index 0000000000000..60d68c5d3b55c
--- /dev/null
+++ b/tests/ports/webassembly/run_python_async2.mjs.exp
@@ -0,0 +1,8 @@
+_text await start
+_text awaited end
+_Response.text start
+_Response.text end
+OK
+_Response.text start
+_Response.text end
+OK
diff --git a/tests/ports/webassembly/this_behaviour.mjs b/tests/ports/webassembly/this_behaviour.mjs
new file mode 100644
index 0000000000000..6411b6ce63485
--- /dev/null
+++ b/tests/ports/webassembly/this_behaviour.mjs
@@ -0,0 +1,24 @@
+// Test "this" behaviour.
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+// "this" should be undefined.
+globalThis.func0 = function () {
+    console.log("func0", this);
+};
+mp.runPython("import js; js.func0()");
+
+globalThis.func1 = function (a) {
+    console.log("func1", a, this);
+};
+mp.runPython("import js; js.func1(123)");
+
+globalThis.func2 = function (a, b) {
+    console.log("func2", a, b, this);
+};
+mp.runPython("import js; js.func2(123, 456)");
+
+globalThis.func3 = function (a, b, c) {
+    console.log("func3", a, b, c, this);
+};
+mp.runPython("import js; js.func3(123, 456, 789)");
diff --git a/tests/ports/webassembly/this_behaviour.mjs.exp b/tests/ports/webassembly/this_behaviour.mjs.exp
new file mode 100644
index 0000000000000..4762026ab2027
--- /dev/null
+++ b/tests/ports/webassembly/this_behaviour.mjs.exp
@@ -0,0 +1,4 @@
+func0 undefined
+func1 123 undefined
+func2 123 456 undefined
+func3 123 456 789 undefined
diff --git a/tests/ports/webassembly/various.js b/tests/ports/webassembly/various.js
new file mode 100644
index 0000000000000..e2fa9362c4f3d
--- /dev/null
+++ b/tests/ports/webassembly/various.js
@@ -0,0 +1,38 @@
+import(process.argv[2]).then((mp) => {
+    mp.loadMicroPython().then((py) => {
+        globalThis.jsadd = (x, y) => {
+            return x + y;
+        };
+        py.runPython("import js; print(js); print(js.jsadd(4, 9))");
+
+        py.runPython(
+            "def set_timeout_callback():\n print('set_timeout_callback')",
+        );
+        py.runPython("import js; js.setTimeout(set_timeout_callback, 100)");
+
+        py.runPython("obj = js.Object(a=1)");
+        console.log("main", py.pyimport("__main__").obj);
+
+        console.log("=======");
+        py.runPython(`
+            from js import Array, Promise, Reflect
+
+            def callback(resolve, reject):
+                resolve('OK1')
+
+            p = Reflect.construct(Promise, Array(callback))
+            p.then(print)
+        `);
+
+        console.log("=======");
+        py.runPython(`
+            from js import Promise
+
+            def callback(resolve, reject):
+                resolve('OK2')
+
+            p = Promise.new(callback)
+            p.then(print)
+        `);
+    });
+});
diff --git a/tests/ports/webassembly/various.js.exp b/tests/ports/webassembly/various.js.exp
new file mode 100644
index 0000000000000..502ab2cccf000
--- /dev/null
+++ b/tests/ports/webassembly/various.js.exp
@@ -0,0 +1,8 @@
+
+13
+main { a: 1 }
+=======
+=======
+OK1
+OK2
+set_timeout_callback
diff --git a/tests/run-tests.py b/tests/run-tests.py
index 83af61c83d20b..4f55cdd39842e 100755
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1142,7 +1142,7 @@ def main():
                     "ports/qemu-arm",
                 )
             elif args.target == "webassembly":
-                test_dirs += ("float",)
+                test_dirs += ("float", "ports/webassembly")
         else:
             # run tests from these directories
             test_dirs = args.test_dirs

From badc0106bdc20e95d427184395c43ffd9d9beea8 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Fri, 2 Feb 2024 12:03:25 +1100
Subject: [PATCH 273/408] tools/ci.sh: Update webassembly CI tests.

Signed-off-by: Damien George 
---
 tools/ci.sh | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/ci.sh b/tools/ci.sh
index f94f23893b710..ad5e79c4ad07c 100755
--- a/tools/ci.sh
+++ b/tools/ci.sh
@@ -178,18 +178,19 @@ function ci_esp8266_build {
 # ports/webassembly
 
 function ci_webassembly_setup {
+    npm install terser
     git clone https://github.com/emscripten-core/emsdk.git
     (cd emsdk && ./emsdk install latest && ./emsdk activate latest)
 }
 
 function ci_webassembly_build {
     source emsdk/emsdk_env.sh
-    make ${MAKEOPTS} -C ports/webassembly
+    make ${MAKEOPTS} -C ports/webassembly VARIANT=pyscript submodules
+    make ${MAKEOPTS} -C ports/webassembly VARIANT=pyscript
 }
 
 function ci_webassembly_run_tests {
-    # This port is very slow at running, so only run a few of the tests.
-    (cd tests && MICROPY_MICROPYTHON=../ports/webassembly/node_run.sh ./run-tests.py -j1 basics/builtin_*.py)
+    make -C ports/webassembly VARIANT=pyscript test_min
 }
 
 ########################################################################################

From 35b2edfc240050fc5310093db29927f6226c3157 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Wed, 21 Feb 2024 13:00:50 +1100
Subject: [PATCH 274/408] github/workflows: Add Biome workflow for JavaScript
 formatting/linting.

Enable Biome on all of webassembly port and tests.

Signed-off-by: Damien George 
---
 .github/workflows/biome.yml | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 .github/workflows/biome.yml

diff --git a/.github/workflows/biome.yml b/.github/workflows/biome.yml
new file mode 100644
index 0000000000000..88744f16ca7d6
--- /dev/null
+++ b/.github/workflows/biome.yml
@@ -0,0 +1,16 @@
+name: JavaScript code lint and formatting with Biome
+
+on: [push, pull_request]
+
+jobs:
+  eslint:
+    runs-on: ubuntu-latest
+    steps:
+    - name: Checkout
+      uses: actions/checkout@v4
+    - name: Setup Biome
+      uses: biomejs/setup-biome@v2
+      with:
+        version: 1.5.3
+    - name: Run Biome
+      run: biome ci --indent-style=space --indent-width=4 tests/ ports/webassembly

From 35f3f0a87db2580041dd0f7dfd4361df48887796 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Tue, 19 Mar 2024 15:08:42 +1100
Subject: [PATCH 275/408] py/nlr: Add "memory" to asm clobbers list in
 nlr_jump.

Newer versions of gcc (14 and up) have more sophisticated dead-code
detection, and the asm clobbers list needs to contain "memory" to inform
the compiler that the asm code actually does something.

Tested that adding this "memory" line does not change the generated code on
ARM Thumb2, x86-64 and Xtensa targets (using gcc 13.2).

Fixes issue #14115.

Signed-off-by: Damien George 
---
 py/nlraarch64.c | 2 +-
 py/nlrmips.c    | 2 +-
 py/nlrpowerpc.c | 4 ++--
 py/nlrthumb.c   | 2 +-
 py/nlrx64.c     | 2 +-
 py/nlrx86.c     | 2 +-
 py/nlrxtensa.c  | 2 +-
 7 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/py/nlraarch64.c b/py/nlraarch64.c
index fcc318f2dc182..d6d87ebc50db8 100644
--- a/py/nlraarch64.c
+++ b/py/nlraarch64.c
@@ -75,7 +75,7 @@ NORETURN void nlr_jump(void *val) {
         "ret                     \n"
         :
         : "r" (top)
-        :
+        : "memory"
         );
 
     MP_UNREACHABLE
diff --git a/py/nlrmips.c b/py/nlrmips.c
index bd5d73b6f767b..cba52b16a266a 100644
--- a/py/nlrmips.c
+++ b/py/nlrmips.c
@@ -78,7 +78,7 @@ NORETURN void nlr_jump(void *val) {
         "nop            \n"
         :
         : "r" (top)
-        :
+        : "memory"
         );
     MP_UNREACHABLE
 }
diff --git a/py/nlrpowerpc.c b/py/nlrpowerpc.c
index 448459216b6e8..8a69fe1eeca6b 100644
--- a/py/nlrpowerpc.c
+++ b/py/nlrpowerpc.c
@@ -114,7 +114,7 @@ NORETURN void nlr_jump(void *val) {
         "blr ;"
         :
         : "r" (&top->regs)
-        :
+        : "memory"
         );
 
     MP_UNREACHABLE;
@@ -203,7 +203,7 @@ NORETURN void nlr_jump(void *val) {
         "blr ;"
         :
         : "r" (&top->regs)
-        :
+        : "memory"
         );
 
     MP_UNREACHABLE;
diff --git a/py/nlrthumb.c b/py/nlrthumb.c
index a8ffecc470335..a22c5df5b9418 100644
--- a/py/nlrthumb.c
+++ b/py/nlrthumb.c
@@ -132,7 +132,7 @@ NORETURN void nlr_jump(void *val) {
         "bx     lr                  \n" // return
         :                           // output operands
         : "r" (top)                 // input operands
-        :                           // clobbered registers
+        : "memory"                  // clobbered registers
         );
 
     MP_UNREACHABLE
diff --git a/py/nlrx64.c b/py/nlrx64.c
index 6b7d0262f5491..d1ad91ff7d718 100644
--- a/py/nlrx64.c
+++ b/py/nlrx64.c
@@ -123,7 +123,7 @@ NORETURN void nlr_jump(void *val) {
         "ret                        \n" // return
         :                           // output operands
         : "r" (top)                 // input operands
-        :                           // clobbered registers
+        : "memory"                  // clobbered registers
         );
 
     MP_UNREACHABLE
diff --git a/py/nlrx86.c b/py/nlrx86.c
index f658d41910c8d..085e30d2034a1 100644
--- a/py/nlrx86.c
+++ b/py/nlrx86.c
@@ -95,7 +95,7 @@ NORETURN void nlr_jump(void *val) {
         "ret                        \n" // return
         :                           // output operands
         : "r" (top)                 // input operands
-        :                           // clobbered registers
+        : "memory"                  // clobbered registers
         );
 
     MP_UNREACHABLE
diff --git a/py/nlrxtensa.c b/py/nlrxtensa.c
index abe9042af9f17..ff7af6edeef98 100644
--- a/py/nlrxtensa.c
+++ b/py/nlrxtensa.c
@@ -74,7 +74,7 @@ NORETURN void nlr_jump(void *val) {
         "ret.n                      \n" // return
         :                           // output operands
         : "r" (top)                 // input operands
-        :                           // clobbered registers
+        : "memory"                  // clobbered registers
         );
 
     MP_UNREACHABLE

From a0efe2d368456ec35c32d439d121cf8d7557bbd0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dani=C3=ABl=20van=20de=20Giessen?= 
Date: Mon, 11 Mar 2024 17:32:13 +0100
Subject: [PATCH 276/408] esp32/main: Check if main GC heap allocation failed.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

If the heap allocation fails we will crash if we continue, so at least we
can show a clear error message so one can figure out memory allocation was
the problem (instead of just seeing some arbitrary null pointer error
later).

Signed-off-by: Daniël van de Giessen 
---
 ports/esp32/main.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/ports/esp32/main.c b/ports/esp32/main.c
index 6fb15d3cc8906..62dd7ae3cccf6 100644
--- a/ports/esp32/main.c
+++ b/ports/esp32/main.c
@@ -116,6 +116,10 @@ void mp_task(void *pvParameter) {
     }
 
     void *mp_task_heap = MP_PLAT_ALLOC_HEAP(MICROPY_GC_INITIAL_HEAP_SIZE);
+    if (mp_task_heap == NULL) {
+        printf("mp_task_heap allocation failed!\n");
+        esp_restart();
+    }
 
 soft_reset:
     // initialise the stack pointer for the main thread

From fcaf10991727bdf125b2b4f21e4557dd4f74d255 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dani=C3=ABl=20van=20de=20Giessen?= 
Date: Fri, 15 Mar 2024 16:51:18 +0100
Subject: [PATCH 277/408] top: Skip codespell for IDF managed components.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

During a build the ESP-IDF downloads managed components in the
ports/esp32/managed_components directory, which shouldn't be spellchecked.

Signed-off-by: Daniël van de Giessen 
---
 pyproject.toml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/pyproject.toml b/pyproject.toml
index 0b3a40d9c95f7..e44afe37e0ebb 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -13,6 +13,7 @@ skip = """
 ./ports/cc3200/hal,\
 ./ports/cc3200/simplelink,\
 ./ports/cc3200/telnet,\
+./ports/esp32/managed_components,\
 ./ports/nrf/drivers/bluetooth/s1*,\
 ./ports/stm32/usbhost,\
 ./tests,\

From 086d4d127d2b85d8e04c73f7f54fc90c0a2e5c57 Mon Sep 17 00:00:00 2001
From: Jared Hancock 
Date: Wed, 20 Mar 2024 09:04:49 -0500
Subject: [PATCH 278/408] extmod/network_wiznet5k: Properly enable interrupt
 signal on w5100s.

According to the datasheet, the IEN bit to enable the interrupt is in the
MR2 register, not the MR register.

This is just cleanup as the interrupt appears to be enabled by default
after resetting the chip.

Tested on W5100S_EVB_PICO.
---
 extmod/network_wiznet5k.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/extmod/network_wiznet5k.c b/extmod/network_wiznet5k.c
index b550f8c1f45f2..b8ca075b3d14f 100644
--- a/extmod/network_wiznet5k.c
+++ b/extmod/network_wiznet5k.c
@@ -221,7 +221,7 @@ static void wiznet5k_init(void) {
         setSn_IMR(0, Sn_IR_RECV);
         #if _WIZCHIP_ == W5100S
         // Enable interrupt pin
-        setMR(MR2_G_IEN);
+        setMR2(getMR2() | MR2_G_IEN);
         #endif
 
         mp_hal_pin_input(wiznet5k_obj.pin_intn);

From 51d05c442afca147d225f99fcec5f66b89b1c525 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Mon, 25 Mar 2024 13:36:30 +1100
Subject: [PATCH 279/408] tools/manifestfile.py: Fix freeze() when script is an
 empty iterable.

The documentation for `freeze()` says that:
- If `script` is `None`, all files in `path` will be frozen.
- If `script` is an iterable then `freeze()` is called on all items of the
  iterable.

This commit makes sure this behaviour is followed when an empty tuple/list
is passed in for `script` (previously an empty tuple/list froze all files).

Fixes issue #14125.

Signed-off-by: Damien George 
---
 tools/manifestfile.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/manifestfile.py b/tools/manifestfile.py
index c1fc836585fb9..beaa36d0f5fc2 100644
--- a/tools/manifestfile.py
+++ b/tools/manifestfile.py
@@ -291,7 +291,7 @@ def _add_file(self, full_path, target_path, kind=KIND_AUTO, opt=None):
     def _search(self, base_path, package_path, files, exts, kind, opt=None, strict=False):
         base_path = self._resolve_path(base_path)
 
-        if files:
+        if files is not None:
             # Use explicit list of files (relative to package_path).
             for file in files:
                 if package_path:

From d1a3e7d292b63fe4307c3bd417b6df8efe7c6700 Mon Sep 17 00:00:00 2001
From: Christian Walther 
Date: Sun, 26 Nov 2023 17:05:44 +0100
Subject: [PATCH 280/408] nrf/Makefile: Allow external board definitions.

Trying to use an external board definition according to
https://github.com/micropython/micropython-example-boards on the nrf port
failed with "Invalid BOARD specified".  Replacing all ocurrences of
"boards/$(BOARD)" with "$(BOARD_DIR)" following the example of
stm32/Makefile fixes that.

Signed-off-by: Christian Walther 
---
 ports/nrf/Makefile | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile
index 7150aa6399b01..31d0bc7668342 100644
--- a/ports/nrf/Makefile
+++ b/ports/nrf/Makefile
@@ -9,8 +9,8 @@ BOARD ?= PCA10040
 BOARD_DIR ?= boards/$(BOARD)
 endif
 
-ifeq ($(wildcard boards/$(BOARD)/.),)
-$(error Invalid BOARD specified)
+ifeq ($(wildcard $(BOARD_DIR)/.),)
+$(error Invalid BOARD specified: $(BOARD_DIR))
 endif
 
 # If SoftDevice is selected, try to use that one.
@@ -19,7 +19,7 @@ SD_LOWER = $(shell echo $(SD) | tr '[:upper:]' '[:lower:]')
 
 # TODO: Verify that it is a valid target.
 
-include boards/$(BOARD)/mpconfigboard.mk
+include $(BOARD_DIR)/mpconfigboard.mk
 
 ifeq ($(SD), )
 	# If the build directory is not given, make it reflect the board name.
@@ -48,7 +48,7 @@ ifneq ($(LD_FILE),)
 	LD_FILES = $(LD_FILE)
 endif
 
--include boards/$(BOARD)/modules/boardmodules.mk
+-include $(BOARD_DIR)/modules/boardmodules.mk
 
 # qstr definitions (must come before including py.mk)
 QSTR_DEFS = qstrdefsport.h
@@ -113,7 +113,7 @@ NRF_DEFINES += -D$(MCU_SUB_VARIANT_UPPER)
 NRF_DEFINES += -DCONFIG_GPIO_AS_PINRESET
 
 MAKE_PINS = boards/make-pins.py
-BOARD_PINS = boards/$(BOARD)/pins.csv
+BOARD_PINS = $(BOARD_DIR)/pins.csv
 AF_FILE = $(MCU_VARIANT)_af.csv
 PREFIX_FILE = boards/$(MCU_VARIANT)_prefix.c
 GEN_PINS_SRC = $(BUILD)/pins_gen.c
@@ -139,7 +139,7 @@ endif
 CFLAGS += $(CFLAGS_MCU_$(MCU_SERIES))
 CFLAGS += $(INC) -Wall -Werror -ansi -std=c11 -nostdlib $(COPT) $(NRF_DEFINES) $(CFLAGS_EXTRA)
 CFLAGS += -fno-strict-aliasing
-CFLAGS += -Iboards/$(BOARD)
+CFLAGS += -I$(BOARD_DIR)
 CFLAGS += -DNRF5_HAL_H='<$(MCU_VARIANT)_hal.h>'
 
 LDFLAGS += $(CFLAGS)
@@ -481,7 +481,7 @@ $(OBJ): | $(HEADER_BUILD)/pins.h
 
 # Use a pattern rule here so that make will only call make-pins.py once to make
 # both pins_gen.c and pins.h
-$(BUILD)/%_gen.c $(HEADER_BUILD)/%.h $(HEADER_BUILD)/%_af_const.h: boards/$(BOARD)/%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD)
+$(BUILD)/%_gen.c $(HEADER_BUILD)/%.h $(HEADER_BUILD)/%_af_const.h: $(BOARD_DIR)/%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD)
 	$(ECHO) "Create $@"
 	$(Q)$(PYTHON) $(MAKE_PINS) --board-csv $(BOARD_PINS) --af-csv $(AF_FILE) --prefix $(PREFIX_FILE) \
 	    --output-source $(GEN_PINS_SRC) --output-header $(GEN_PINS_HDR) --output-af-const $(GEN_PINS_AF_CONST)

From be89d4376b810dcaf5b3d26526f0207b6eb0e570 Mon Sep 17 00:00:00 2001
From: Christian Walther 
Date: Fri, 5 Jan 2024 15:52:09 +0100
Subject: [PATCH 281/408] nrf/modules/machine: Enable code formatting.

It destroys a few manual alignments, but these seem minor compared to
the benefit of automated code style consistency.

Signed-off-by: Christian Walther 
---
 ports/nrf/modules/machine/adc.c        | 89 +++++++++++++-------------
 ports/nrf/modules/machine/adc.h        |  2 +-
 ports/nrf/modules/machine/i2c.c        |  5 +-
 ports/nrf/modules/machine/modmachine.c | 20 +++---
 ports/nrf/modules/machine/pin.c        | 20 +++---
 ports/nrf/modules/machine/pin.h        | 46 ++++++-------
 ports/nrf/modules/machine/rtcounter.c  | 38 +++++------
 ports/nrf/modules/machine/soft_pwm.c   |  4 +-
 ports/nrf/modules/machine/spi.c        | 50 +++++++--------
 ports/nrf/modules/machine/spi.h        |  8 +--
 ports/nrf/modules/machine/temp.c       |  4 +-
 ports/nrf/modules/machine/timer.c      | 46 ++++++-------
 ports/nrf/modules/machine/uart.c       | 24 +++----
 tools/codeformat.py                    |  2 -
 14 files changed, 177 insertions(+), 181 deletions(-)

diff --git a/ports/nrf/modules/machine/adc.c b/ports/nrf/modules/machine/adc.c
index c45d0ba5ffdab..9fa8005a22809 100644
--- a/ports/nrf/modules/machine/adc.c
+++ b/ports/nrf/modules/machine/adc.c
@@ -38,14 +38,14 @@
 
 typedef struct _machine_adc_obj_t {
     mp_obj_base_t base;
-    uint8_t       id;
-#if NRF51
-    uint8_t       ain;
-#endif
+    uint8_t id;
+    #if NRF51
+    uint8_t ain;
+    #endif
 } machine_adc_obj_t;
 
 static const machine_adc_obj_t machine_adc_obj[] = {
-#if NRF51
+    #if NRF51
     {{&machine_adc_type}, .id = 0, .ain = NRF_ADC_CONFIG_INPUT_0},
     {{&machine_adc_type}, .id = 1, .ain = NRF_ADC_CONFIG_INPUT_1},
     {{&machine_adc_type}, .id = 2, .ain = NRF_ADC_CONFIG_INPUT_2},
@@ -54,7 +54,7 @@ static const machine_adc_obj_t machine_adc_obj[] = {
     {{&machine_adc_type}, .id = 5, .ain = NRF_ADC_CONFIG_INPUT_5},
     {{&machine_adc_type}, .id = 6, .ain = NRF_ADC_CONFIG_INPUT_6},
     {{&machine_adc_type}, .id = 7, .ain = NRF_ADC_CONFIG_INPUT_7},
-#else
+    #else
     {{&machine_adc_type}, .id = 0},
     {{&machine_adc_type}, .id = 1},
     {{&machine_adc_type}, .id = 2},
@@ -63,14 +63,14 @@ static const machine_adc_obj_t machine_adc_obj[] = {
     {{&machine_adc_type}, .id = 5},
     {{&machine_adc_type}, .id = 6},
     {{&machine_adc_type}, .id = 7},
-#endif
+    #endif
 };
 
 void adc_init0(void) {
-#if defined(NRF52_SERIES)
+    #if defined(NRF52_SERIES)
     const uint8_t interrupt_priority = 6;
     nrfx_saadc_init(interrupt_priority);
-#endif
+    #endif
 }
 
 static int adc_find(mp_obj_t id) {
@@ -124,49 +124,49 @@ static mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args
     int adc_id = adc_find(args[ARG_id].u_obj);
     const machine_adc_obj_t *self = &machine_adc_obj[adc_id];
 
-#if defined(NRF52_SERIES)
+    #if defined(NRF52_SERIES)
     const nrfx_saadc_channel_t config = {                                                           \
         .channel_config =
         {
             .resistor_p = NRF_SAADC_RESISTOR_DISABLED,
             .resistor_n = NRF_SAADC_RESISTOR_DISABLED,
-            .gain       = NRF_SAADC_GAIN1_4,
-            .reference  = NRF_SAADC_REFERENCE_VDD4,
-            .acq_time   = NRF_SAADC_ACQTIME_3US,
-            .mode       = NRF_SAADC_MODE_SINGLE_ENDED,
-            .burst      = NRF_SAADC_BURST_DISABLED,
+            .gain = NRF_SAADC_GAIN1_4,
+            .reference = NRF_SAADC_REFERENCE_VDD4,
+            .acq_time = NRF_SAADC_ACQTIME_3US,
+            .mode = NRF_SAADC_MODE_SINGLE_ENDED,
+            .burst = NRF_SAADC_BURST_DISABLED,
         },
-        .pin_p          = (nrf_saadc_input_t)(1 + self->id), // pin_p=0 is AIN0, pin_p=8 is AIN7
-        .pin_n          = NRF_SAADC_INPUT_DISABLED,
-        .channel_index  = self->id,
+        .pin_p = (nrf_saadc_input_t)(1 + self->id),          // pin_p=0 is AIN0, pin_p=8 is AIN7
+        .pin_n = NRF_SAADC_INPUT_DISABLED,
+        .channel_index = self->id,
     };
     nrfx_saadc_channels_config(&config, 1);
-#endif
+    #endif
 
     return MP_OBJ_FROM_PTR(self);
 }
 
-int16_t machine_adc_value_read(machine_adc_obj_t * adc_obj) {
+int16_t machine_adc_value_read(machine_adc_obj_t *adc_obj) {
 
-#if NRF51
+    #if NRF51
     nrf_adc_value_t value = 0;
 
     nrfx_adc_channel_t channel_config = {
         .config.resolution = NRF_ADC_CONFIG_RES_8BIT,
-        .config.input      = NRF_ADC_CONFIG_SCALING_INPUT_TWO_THIRDS,
-        .config.reference  = NRF_ADC_CONFIG_REF_VBG,
-        .config.input      = adc_obj->ain,
-        .config.extref     = ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos // Currently not defined in nrfx/hal.
+        .config.input = NRF_ADC_CONFIG_SCALING_INPUT_TWO_THIRDS,
+        .config.reference = NRF_ADC_CONFIG_REF_VBG,
+        .config.input = adc_obj->ain,
+        .config.extref = ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos     // Currently not defined in nrfx/hal.
     };
 
     nrfx_adc_sample_convert(&channel_config, &value);
-#else // NRF52
+    #else // NRF52
     nrf_saadc_value_t value = 0;
 
     nrfx_saadc_simple_mode_set((1 << adc_obj->id), NRF_SAADC_RESOLUTION_8BIT, NRF_SAADC_INPUT_DISABLED, NULL);
     nrfx_saadc_buffer_set(&value, 1);
     nrfx_saadc_mode_trigger();
-#endif
+    #endif
     return value;
 }
 
@@ -209,10 +209,9 @@ static MP_DEFINE_CONST_FUN_OBJ_1(mp_machine_adc_value_obj, machine_adc_value);
 #define DIODE_VOLT_DROP_MILLIVOLT    (270)  // Voltage drop over diode.
 
 #define BATTERY_MILLIVOLT(VALUE) \
-        ((((VALUE) * ADC_REF_VOLTAGE_IN_MILLIVOLT) / 255) * ADC_PRE_SCALING_MULTIPLIER)
+    ((((VALUE)*ADC_REF_VOLTAGE_IN_MILLIVOLT) / 255) * ADC_PRE_SCALING_MULTIPLIER)
 
-static uint8_t battery_level_in_percent(const uint16_t mvolts)
-{
+static uint8_t battery_level_in_percent(const uint16_t mvolts) {
     uint8_t battery_level;
 
     if (mvolts >= 3000) {
@@ -236,19 +235,19 @@ static uint8_t battery_level_in_percent(const uint16_t mvolts)
 /// Get battery level in percentage.
 mp_obj_t machine_adc_battery_level(void) {
 
-#if NRF51
+    #if NRF51
     nrf_adc_value_t value = 0;
 
     nrfx_adc_channel_t channel_config = {
         .config.resolution = NRF_ADC_CONFIG_RES_8BIT,
-        .config.input      = NRF_ADC_CONFIG_SCALING_SUPPLY_ONE_THIRD,
-        .config.reference  = NRF_ADC_CONFIG_REF_VBG,
-        .config.input      = NRF_ADC_CONFIG_INPUT_DISABLED,
-        .config.extref     = ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos // Currently not defined in nrfx/hal.
+        .config.input = NRF_ADC_CONFIG_SCALING_SUPPLY_ONE_THIRD,
+        .config.reference = NRF_ADC_CONFIG_REF_VBG,
+        .config.input = NRF_ADC_CONFIG_INPUT_DISABLED,
+        .config.extref = ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos     // Currently not defined in nrfx/hal.
     };
 
     nrfx_adc_sample_convert(&channel_config, &value);
-#else // NRF52
+    #else // NRF52
     nrf_saadc_value_t value = 0;
 
     const nrfx_saadc_channel_t config = {                                                           \
@@ -256,22 +255,22 @@ mp_obj_t machine_adc_battery_level(void) {
         {
             .resistor_p = NRF_SAADC_RESISTOR_DISABLED,
             .resistor_n = NRF_SAADC_RESISTOR_DISABLED,
-            .gain       = NRF_SAADC_GAIN1_6,
-            .reference  = NRF_SAADC_REFERENCE_INTERNAL,
-            .acq_time   = NRF_SAADC_ACQTIME_3US,
-            .mode       = NRF_SAADC_MODE_SINGLE_ENDED,
-            .burst      = NRF_SAADC_BURST_DISABLED,
+            .gain = NRF_SAADC_GAIN1_6,
+            .reference = NRF_SAADC_REFERENCE_INTERNAL,
+            .acq_time = NRF_SAADC_ACQTIME_3US,
+            .mode = NRF_SAADC_MODE_SINGLE_ENDED,
+            .burst = NRF_SAADC_BURST_DISABLED,
         },
-        .pin_p          = NRF_SAADC_INPUT_VDD,
-        .pin_n          = NRF_SAADC_INPUT_DISABLED,
-        .channel_index  = 0,
+        .pin_p = NRF_SAADC_INPUT_VDD,
+        .pin_n = NRF_SAADC_INPUT_DISABLED,
+        .channel_index = 0,
     };
     nrfx_saadc_channels_config(&config, 1);
 
     nrfx_saadc_simple_mode_set((1 << 0), NRF_SAADC_RESOLUTION_8BIT, NRF_SAADC_INPUT_DISABLED, NULL);
     nrfx_saadc_buffer_set(&value, 1);
     nrfx_saadc_mode_trigger();
-#endif
+    #endif
 
     uint16_t batt_lvl_in_milli_volts = BATTERY_MILLIVOLT(value) + DIODE_VOLT_DROP_MILLIVOLT;
     uint16_t batt_in_percent = battery_level_in_percent(batt_lvl_in_milli_volts);
diff --git a/ports/nrf/modules/machine/adc.h b/ports/nrf/modules/machine/adc.h
index 84e5cdbb85f3e..9ef1b470447b7 100644
--- a/ports/nrf/modules/machine/adc.h
+++ b/ports/nrf/modules/machine/adc.h
@@ -31,6 +31,6 @@ typedef struct _machine_adc_obj_t machine_adc_obj_t;
 
 void adc_init0(void);
 
-int16_t machine_adc_value_read(machine_adc_obj_t * adc_obj);
+int16_t machine_adc_value_read(machine_adc_obj_t *adc_obj);
 
 #endif // ADC_H__
diff --git a/ports/nrf/modules/machine/i2c.c b/ports/nrf/modules/machine/i2c.c
index 7e488366d70ba..6c2b3e94838e5 100644
--- a/ports/nrf/modules/machine/i2c.c
+++ b/ports/nrf/modules/machine/i2c.c
@@ -68,7 +68,7 @@
 
 typedef struct _machine_hard_i2c_obj_t {
     mp_obj_base_t base;
-    nrfx_twi_t    p_twi;  // Driver instance
+    nrfx_twi_t p_twi;     // Driver instance
 } machine_hard_i2c_obj_t;
 
 static const machine_hard_i2c_obj_t machine_hard_i2c_obj[] = {
@@ -159,8 +159,7 @@ int machine_hard_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, size
     if (err_code != NRFX_SUCCESS) {
         if (err_code == NRFX_ERROR_DRV_TWI_ERR_ANACK) {
             return -MP_ENODEV;
-        }
-        else if (err_code == NRFX_ERROR_DRV_TWI_ERR_DNACK) {
+        } else if (err_code == NRFX_ERROR_DRV_TWI_ERR_DNACK) {
             return -MP_EIO;
         }
         return -MP_ETIMEDOUT;
diff --git a/ports/nrf/modules/machine/modmachine.c b/ports/nrf/modules/machine/modmachine.c
index 9ad8d606a2654..de1d0e31246b4 100644
--- a/ports/nrf/modules/machine/modmachine.c
+++ b/ports/nrf/modules/machine/modmachine.c
@@ -116,16 +116,16 @@ void machine_init(void) {
         reset_cause = PYB_RESET_LOCKUP;
     } else if (state & POWER_RESETREAS_OFF_Msk) {
         reset_cause = PYB_RESET_POWER_ON;
-#if !defined(NRF9160_XXAA)
+    #if !defined(NRF9160_XXAA)
     } else if (state & POWER_RESETREAS_LPCOMP_Msk) {
         reset_cause = PYB_RESET_LPCOMP;
-#endif
+    #endif
     } else if (state & POWER_RESETREAS_DIF_Msk) {
         reset_cause = PYB_RESET_DIF;
-#if defined(NRF52_SERIES)
+    #if defined(NRF52_SERIES)
     } else if (state & POWER_RESETREAS_NFC_Msk) {
         reset_cause = PYB_RESET_NFC;
-#endif
+    #endif
     }
 
     // clear reset reason
@@ -216,22 +216,22 @@ static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
 }
 
 static mp_obj_t machine_enable_irq(void) {
-#ifndef BLUETOOTH_SD
+    #ifndef BLUETOOTH_SD
     __enable_irq();
-#else
+    #else
 
-#endif
+    #endif
     return mp_const_none;
 }
 MP_DEFINE_CONST_FUN_OBJ_0(machine_enable_irq_obj, machine_enable_irq);
 
 // Resets the board in a manner similar to pushing the external RESET button.
 static mp_obj_t machine_disable_irq(void) {
-#ifndef BLUETOOTH_SD
+    #ifndef BLUETOOTH_SD
     __disable_irq();
-#else
+    #else
 
-#endif
+    #endif
     return mp_const_none;
 }
 MP_DEFINE_CONST_FUN_OBJ_0(machine_disable_irq_obj, machine_disable_irq);
diff --git a/ports/nrf/modules/machine/pin.c b/ports/nrf/modules/machine/pin.c
index e72a16eee7c29..f86d878d17d7e 100644
--- a/ports/nrf/modules/machine/pin.c
+++ b/ports/nrf/modules/machine/pin.c
@@ -234,9 +234,9 @@ static void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
     }
 
     mp_printf(print, "Pin(%d, mode=%s, pull=%s)",
-            self->pin,
-            (nrf_gpio_pin_dir_get(self->pin) == NRF_GPIO_PIN_DIR_OUTPUT) ? "OUT" : "IN",
-            pull);
+        self->pin,
+        (nrf_gpio_pin_dir_get(self->pin) == NRF_GPIO_PIN_DIR_OUTPUT) ? "OUT" : "IN",
+        pull);
 }
 
 static mp_obj_t pin_obj_init_helper(const pin_obj_t *pin, mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args);
@@ -375,11 +375,11 @@ static mp_obj_t pin_obj_init_helper(const pin_obj_t *self, mp_uint_t n_args, con
 
     if (mode == NRF_GPIO_PIN_DIR_OUTPUT || mode == NRF_GPIO_PIN_DIR_INPUT) {
         nrf_gpio_cfg(self->pin,
-                     mode,
-                     input,
-                     pull,
-                     NRF_GPIO_PIN_S0S1,
-                     NRF_GPIO_PIN_NOSENSE);
+            mode,
+            input,
+            pull,
+            NRF_GPIO_PIN_S0S1,
+            NRF_GPIO_PIN_NOSENSE);
     } else {
         mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("invalid pin mode: %d"), mode);
     }
@@ -496,7 +496,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_obj, pin_af);
 static void pin_common_irq_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
     mp_obj_t pin_handler = MP_STATE_PORT(pin_irq_handlers)[pin];
     mp_obj_t pin_number = MP_OBJ_NEW_SMALL_INT(pin);
-    const pin_obj_t *pin_obj  = pin_find(pin_number);
+    const pin_obj_t *pin_obj = pin_find(pin_number);
 
     mp_call_function_1(pin_handler, (mp_obj_t)pin_obj);
 }
@@ -591,7 +591,7 @@ static const mp_rom_map_elem_t pin_locals_dict_table[] = {
     { MP_ROM_QSTR(MP_QSTR_AF_OD),     MP_ROM_INT(GPIO_MODE_AF_OD) },
     { MP_ROM_QSTR(MP_QSTR_PULL_NONE), MP_ROM_INT(GPIO_NOPULL) },
 */
-#include "genhdr/pins_af_const.h"
+    #include "genhdr/pins_af_const.h"
 };
 
 static MP_DEFINE_CONST_DICT(pin_locals_dict, pin_locals_dict_table);
diff --git a/ports/nrf/modules/machine/pin.h b/ports/nrf/modules/machine/pin.h
index 7004b320b1b6b..41579011b5d84 100644
--- a/ports/nrf/modules/machine/pin.h
+++ b/ports/nrf/modules/machine/pin.h
@@ -34,43 +34,43 @@
 #include "py/obj.h"
 
 typedef struct {
-  mp_obj_base_t base;
-  qstr name;
-  uint8_t idx;
-  uint8_t fn;
-  uint8_t unit;
-  uint8_t type;
-
-  union {
-    void          *reg;
-
-    PIN_DEFS_PORT_AF_UNION
-  };
+    mp_obj_base_t base;
+    qstr name;
+    uint8_t idx;
+    uint8_t fn;
+    uint8_t unit;
+    uint8_t type;
+
+    union {
+        void *reg;
+
+        PIN_DEFS_PORT_AF_UNION
+    };
 } pin_af_obj_t;
 
 typedef struct {
-  mp_obj_base_t base;
-  qstr name;
-  uint32_t pin : 8;
-  uint32_t num_af : 4;
-  uint32_t adc_channel : 5; // Some ARM processors use 32 bits/PORT
-  uint32_t adc_num  : 3;    // 1 bit per ADC
-  const pin_af_obj_t *af;
-  uint32_t pull;
+    mp_obj_base_t base;
+    qstr name;
+    uint32_t pin : 8;
+    uint32_t num_af : 4;
+    uint32_t adc_channel : 5; // Some ARM processors use 32 bits/PORT
+    uint32_t adc_num  : 3;  // 1 bit per ADC
+    const pin_af_obj_t *af;
+    uint32_t pull;
 } pin_obj_t;
 
 extern const mp_obj_type_t pin_type;
 extern const mp_obj_type_t pin_af_type;
 
 typedef struct {
-  const char *name;
-  const pin_obj_t *pin;
+    const char *name;
+    const pin_obj_t *pin;
 } pin_named_pin_t;
 
 extern const pin_named_pin_t pin_board_pins[];
 extern const pin_named_pin_t pin_cpu_pins[];
 
-//extern pin_map_obj_t pin_map_obj;
+// extern pin_map_obj_t pin_map_obj;
 
 typedef struct {
     mp_obj_base_t base;
diff --git a/ports/nrf/modules/machine/rtcounter.c b/ports/nrf/modules/machine/rtcounter.c
index d85db9b9b7aa1..08d31f61d0f9e 100644
--- a/ports/nrf/modules/machine/rtcounter.c
+++ b/ports/nrf/modules/machine/rtcounter.c
@@ -49,18 +49,18 @@ typedef struct {
 
 // Non-volatile part of the RTCounter object.
 typedef struct _machine_rtc_obj_t {
-    mp_obj_base_t          base;
-    const nrfx_rtc_t     * p_rtc;   // Driver instance
-    nrfx_rtc_handler_t     handler; // interrupt callback
-    machine_rtc_config_t * config;  // pointer to volatile part
+    mp_obj_base_t base;
+    const nrfx_rtc_t *p_rtc;        // Driver instance
+    nrfx_rtc_handler_t handler;     // interrupt callback
+    machine_rtc_config_t *config;   // pointer to volatile part
 } machine_rtc_obj_t;
 
 static const nrfx_rtc_t machine_rtc_instances[] = {
     NRFX_RTC_INSTANCE(0),
     NRFX_RTC_INSTANCE(1),
-#if defined(NRF52_SERIES)
+    #if defined(NRF52_SERIES)
     NRFX_RTC_INSTANCE(2),
-#endif
+    #endif
 };
 
 static machine_rtc_config_t configs[MP_ARRAY_SIZE(machine_rtc_instances)];
@@ -72,15 +72,15 @@ static void interrupt_handler2(nrfx_rtc_int_type_t int_type);
 #endif
 
 static const machine_rtc_obj_t machine_rtc_obj[] = {
-    {{&machine_rtcounter_type}, .p_rtc = &machine_rtc_instances[0], .handler=interrupt_handler0, .config=&configs[0]},
-    {{&machine_rtcounter_type}, .p_rtc = &machine_rtc_instances[1], .handler=interrupt_handler1, .config=&configs[1]},
-#if defined(NRF52_SERIES)
-    {{&machine_rtcounter_type}, .p_rtc = &machine_rtc_instances[2], .handler=interrupt_handler2, .config=&configs[2]},
-#endif
+    {{&machine_rtcounter_type}, .p_rtc = &machine_rtc_instances[0], .handler = interrupt_handler0, .config = &configs[0]},
+    {{&machine_rtcounter_type}, .p_rtc = &machine_rtc_instances[1], .handler = interrupt_handler1, .config = &configs[1]},
+    #if defined(NRF52_SERIES)
+    {{&machine_rtcounter_type}, .p_rtc = &machine_rtc_instances[2], .handler = interrupt_handler2, .config = &configs[2]},
+    #endif
 };
 
 static void interrupt_handler(size_t instance_id) {
-    const machine_rtc_obj_t * self = &machine_rtc_obj[instance_id];
+    const machine_rtc_obj_t *self = &machine_rtc_obj[instance_id];
     machine_rtc_config_t *config = self->config;
     if (config->callback != NULL) {
         mp_call_function_1((mp_obj_t)config->callback, (mp_obj_t)self);
@@ -128,8 +128,8 @@ static void rtc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
 /* MicroPython bindings for machine API                                       */
 
 const nrfx_rtc_config_t machine_rtc_config = {
-    .prescaler    = RTC_FREQ_TO_PRESCALER(RTC_FREQUENCY),
-    .reliable     = 0,
+    .prescaler = RTC_FREQ_TO_PRESCALER(RTC_FREQUENCY),
+    .reliable = 0,
     .tick_latency = 0, // ignored when reliable == 0
     #ifdef NRF51
     .interrupt_priority = 3,
@@ -161,7 +161,7 @@ static mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, s
     #endif
 
     // const and non-const part of the RTC object.
-    const machine_rtc_obj_t * self = &machine_rtc_obj[rtc_id];
+    const machine_rtc_obj_t *self = &machine_rtc_obj[rtc_id];
     machine_rtc_config_t *config = self->config;
 
     if (args[ARG_callback].u_obj == mp_const_none) {
@@ -202,7 +202,7 @@ static mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, s
 /// in the configured frequency has been reached.
 ///
 static mp_obj_t machine_rtc_start(mp_obj_t self_in) {
-    machine_rtc_obj_t * self = MP_OBJ_TO_PTR(self_in);
+    machine_rtc_obj_t *self = MP_OBJ_TO_PTR(self_in);
 
     nrfx_rtc_enable(self->p_rtc);
 
@@ -214,7 +214,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(machine_rtc_start_obj, machine_rtc_start);
 /// Stop the RTCounter.
 ///
 static mp_obj_t machine_rtc_stop(mp_obj_t self_in) {
-    machine_rtc_obj_t * self = MP_OBJ_TO_PTR(self_in);
+    machine_rtc_obj_t *self = MP_OBJ_TO_PTR(self_in);
 
     nrfx_rtc_disable(self->p_rtc);
 
@@ -227,7 +227,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(machine_rtc_stop_obj, machine_rtc_stop);
 /// with the current prescaler (2^24 / 8 = 2097152 seconds).
 ///
 static mp_obj_t machine_rtc_counter(mp_obj_t self_in) {
-    machine_rtc_obj_t * self = MP_OBJ_TO_PTR(self_in);
+    machine_rtc_obj_t *self = MP_OBJ_TO_PTR(self_in);
 
     uint32_t counter = nrfx_rtc_counter_get(self->p_rtc);
 
@@ -239,7 +239,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(machine_rtc_counter_obj, machine_rtc_counter);
 /// Free resources associated with this RTC.
 ///
 static mp_obj_t machine_rtc_deinit(mp_obj_t self_in) {
-    machine_rtc_obj_t * self = MP_OBJ_TO_PTR(self_in);
+    machine_rtc_obj_t *self = MP_OBJ_TO_PTR(self_in);
 
     nrfx_rtc_uninit(self->p_rtc);
 
diff --git a/ports/nrf/modules/machine/soft_pwm.c b/ports/nrf/modules/machine/soft_pwm.c
index c61e1f86baa37..2fa3362658986 100644
--- a/ports/nrf/modules/machine/soft_pwm.c
+++ b/ports/nrf/modules/machine/soft_pwm.c
@@ -102,7 +102,7 @@ static mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args
         mp_raise_ValueError(MP_ERROR_TEXT("Pin number >31"));
     }
 
-    machine_pwm_obj_t *self = mp_obj_malloc(machine_pwm_obj_t, &machine_pwm_type);;
+    machine_pwm_obj_t *self = mp_obj_malloc(machine_pwm_obj_t, &machine_pwm_type);
     self->defer_start = false;
     self->pwm_pin = pwm_pin;
     self->duty_mode = DUTY_NOT_SET;
@@ -197,7 +197,7 @@ static void machine_soft_pwm_start(machine_pwm_obj_t *self) {
             duty_width = self->duty * DUTY_FULL_SCALE / 100;
         } else if (self->duty_mode == DUTY_U16) {
             duty_width = self->duty * DUTY_FULL_SCALE / 65536;
-        }if (self->duty_mode == DUTY_NS) {
+        } else if (self->duty_mode == DUTY_NS) {
             duty_width = (uint64_t)self->duty * self->freq * DUTY_FULL_SCALE / 1000000000ULL;
         }
         pwm_set_duty_cycle(self->pwm_pin, duty_width);
diff --git a/ports/nrf/modules/machine/spi.c b/ports/nrf/modules/machine/spi.c
index 4baee39d01dc3..b00a5706c66c0 100644
--- a/ports/nrf/modules/machine/spi.c
+++ b/ports/nrf/modules/machine/spi.c
@@ -98,20 +98,20 @@
 #endif // NRFX_SPIM_ENABLED
 
 typedef struct _machine_hard_spi_obj_t {
-    mp_obj_base_t       base;
-    const nrfx_spi_t   * p_spi;    // Driver instance
-    nrfx_spi_config_t  * p_config; // pointer to volatile part
+    mp_obj_base_t base;
+    const nrfx_spi_t *p_spi;       // Driver instance
+    nrfx_spi_config_t *p_config;   // pointer to volatile part
 } machine_hard_spi_obj_t;
 
 static const nrfx_spi_t machine_spi_instances[] = {
     NRFX_SPI_INSTANCE(0),
     NRFX_SPI_INSTANCE(1),
-#if defined(NRF52_SERIES)
+    #if defined(NRF52_SERIES)
     NRFX_SPI_INSTANCE(2),
-#if defined(NRF52840_XXAA) && NRFX_SPIM_ENABLED
+    #if defined(NRF52840_XXAA) && NRFX_SPIM_ENABLED
     NRFX_SPI_INSTANCE(3),
-#endif // NRF52840_XXAA && NRFX_SPIM_ENABLED
-#endif // NRF52_SERIES
+    #endif // NRF52840_XXAA && NRFX_SPIM_ENABLED
+    #endif // NRF52_SERIES
 };
 
 static nrfx_spi_config_t configs[MP_ARRAY_SIZE(machine_spi_instances)];
@@ -119,12 +119,12 @@ static nrfx_spi_config_t configs[MP_ARRAY_SIZE(machine_spi_instances)];
 static const machine_hard_spi_obj_t machine_hard_spi_obj[] = {
     {{&machine_spi_type}, .p_spi = &machine_spi_instances[0], .p_config = &configs[0]},
     {{&machine_spi_type}, .p_spi = &machine_spi_instances[1], .p_config = &configs[1]},
-#if defined(NRF52_SERIES)
+    #if defined(NRF52_SERIES)
     {{&machine_spi_type}, .p_spi = &machine_spi_instances[2], .p_config = &configs[2]},
-#if defined(NRF52840_XXAA) && NRFX_SPIM_ENABLED
+    #if defined(NRF52840_XXAA) && NRFX_SPIM_ENABLED
     {{&machine_spi_type}, .p_spi = &machine_spi_instances[3], .p_config = &configs[3]},
-#endif // NRF52840_XXAA && NRFX_SPIM_ENABLED
-#endif // NRF52_SERIES
+    #endif // NRF52840_XXAA && NRFX_SPIM_ENABLED
+    #endif // NRF52_SERIES
 };
 
 void spi_init0(void) {
@@ -151,12 +151,12 @@ static int spi_find(mp_obj_t id) {
     }
 }
 
-void spi_transfer(const machine_hard_spi_obj_t * self, size_t len, const void * src, void * dest) {
+void spi_transfer(const machine_hard_spi_obj_t *self, size_t len, const void *src, void *dest) {
     nrfx_spi_xfer_desc_t xfer_desc = {
         .p_tx_buffer = src,
-        .tx_length   = len,
+        .tx_length = len,
         .p_rx_buffer = dest,
-        .rx_length   = len
+        .rx_length = len
     };
 
     nrfx_spi_xfer(self->p_spi, &xfer_desc, 0);
@@ -220,11 +220,11 @@ static mp_obj_t machine_hard_spi_make_new(const mp_obj_type_t *type, size_t n_ar
         && args[ARG_NEW_mosi].u_obj != MP_OBJ_NULL
         && args[ARG_NEW_miso].u_obj != MP_OBJ_NULL) {
 
-        self->p_config->sck_pin  = mp_hal_get_pin_obj(args[ARG_NEW_sck].u_obj)->pin;
+        self->p_config->sck_pin = mp_hal_get_pin_obj(args[ARG_NEW_sck].u_obj)->pin;
         self->p_config->mosi_pin = mp_hal_get_pin_obj(args[ARG_NEW_mosi].u_obj)->pin;
         self->p_config->miso_pin = mp_hal_get_pin_obj(args[ARG_NEW_miso].u_obj)->pin;
     } else {
-        self->p_config->sck_pin  = MICROPY_HW_SPI0_SCK;
+        self->p_config->sck_pin = MICROPY_HW_SPI0_SCK;
         self->p_config->mosi_pin = MICROPY_HW_SPI0_MOSI;
         self->p_config->miso_pin = MICROPY_HW_SPI0_MISO;
     }
@@ -232,11 +232,11 @@ static mp_obj_t machine_hard_spi_make_new(const mp_obj_type_t *type, size_t n_ar
     // Manually trigger slave select from upper layer.
     self->p_config->ss_pin = NRFX_SPI_PIN_NOT_USED;
 
-#ifdef NRF51
+    #ifdef NRF51
     self->p_config->irq_priority = 3;
-#else
+    #else
     self->p_config->irq_priority = 6;
-#endif
+    #endif
 
     machine_hard_spi_init_helper(self, &args[1]); // Skip instance id param.
 
@@ -260,18 +260,18 @@ static void machine_hard_spi_init_helper(const machine_hard_spi_obj_t *self, mp_
         self->p_config->frequency = NRF_SPI_FREQ_4M;
     } else if (baudrate <= 8000000) {
         self->p_config->frequency = NRF_SPI_FREQ_8M;
-#if defined(NRF52840_XXAA) && NRFX_SPIM_ENABLED
+    #if defined(NRF52840_XXAA) && NRFX_SPIM_ENABLED
     } else if (baudrate <= 16000000) {
         self->p_config->frequency = NRF_SPIM_FREQ_16M;
     } else if (baudrate <= 32000000) {
         self->p_config->frequency = NRF_SPIM_FREQ_32M;
-#endif // NRF52840_XXAA && NRFX_SPIM_ENABLED
+    #endif // NRF52840_XXAA && NRFX_SPIM_ENABLED
     } else { // Default
         self->p_config->frequency = NRF_SPI_FREQ_1M;
     }
 
-    // Active high
     if (args[ARG_INIT_polarity].u_int == 0) {
+        // Active high
         if (args[ARG_INIT_phase].u_int == 0) {
             // First clock edge
             self->p_config->mode = NRF_SPI_MODE_0;
@@ -279,8 +279,8 @@ static void machine_hard_spi_init_helper(const machine_hard_spi_obj_t *self, mp_
             // Second clock edge
             self->p_config->mode = NRF_SPI_MODE_1;
         }
-    // Active low
     } else {
+        // Active low
         if (args[ARG_INIT_phase].u_int == 0) {
             // First clock edge
             self->p_config->mode = NRF_SPI_MODE_2;
@@ -290,7 +290,7 @@ static void machine_hard_spi_init_helper(const machine_hard_spi_obj_t *self, mp_
         }
     }
 
-    self->p_config->orc  = 0xFF; // Overrun character
+    self->p_config->orc = 0xFF;  // Overrun character
     self->p_config->bit_order = (args[ARG_INIT_firstbit].u_int == 0) ? NRF_SPI_BIT_ORDER_MSB_FIRST : NRF_SPI_BIT_ORDER_LSB_FIRST;
 
     // Set context to this instance of SPI
@@ -327,7 +327,7 @@ static void machine_hard_spi_deinit(mp_obj_base_t *self_in) {
 }
 
 static void machine_hard_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) {
-    const machine_hard_spi_obj_t *self = (machine_hard_spi_obj_t*)self_in;
+    const machine_hard_spi_obj_t *self = (machine_hard_spi_obj_t *)self_in;
     spi_transfer(self, len, src, dest);
 }
 
diff --git a/ports/nrf/modules/machine/spi.h b/ports/nrf/modules/machine/spi.h
index 1a1998d25aefe..602829869fd24 100644
--- a/ports/nrf/modules/machine/spi.h
+++ b/ports/nrf/modules/machine/spi.h
@@ -29,7 +29,7 @@
 typedef struct _machine_hard_spi_obj_t machine_hard_spi_obj_t;
 
 void spi_init0(void);
-void spi_transfer(const machine_hard_spi_obj_t * self,
-                  size_t                         len,
-                  const void *                   src,
-                  void *                         dest);
+void spi_transfer(const machine_hard_spi_obj_t *self,
+    size_t len,
+    const void *src,
+    void *dest);
diff --git a/ports/nrf/modules/machine/temp.c b/ports/nrf/modules/machine/temp.c
index 0d206fee47a66..aa20087c6cd1c 100644
--- a/ports/nrf/modules/machine/temp.c
+++ b/ports/nrf/modules/machine/temp.c
@@ -91,13 +91,13 @@ int32_t temp_read(void) {
 /// Get temperature.
 static mp_obj_t machine_temp_read(mp_uint_t n_args, const mp_obj_t *args) {
 
-#if BLUETOOTH_SD
+    #if BLUETOOTH_SD
     if (BLUETOOTH_STACK_ENABLED() == 1) {
         int32_t temp;
         (void)sd_temp_get(&temp);
         return MP_OBJ_NEW_SMALL_INT(temp / 4); // resolution of 0.25 degree celsius
     }
-#endif // BLUETOOTH_SD
+    #endif // BLUETOOTH_SD
 
     return MP_OBJ_NEW_SMALL_INT(temp_read());
 }
diff --git a/ports/nrf/modules/machine/timer.c b/ports/nrf/modules/machine/timer.c
index 3c2a039b84dfa..42a40ad2f26ae 100644
--- a/ports/nrf/modules/machine/timer.c
+++ b/ports/nrf/modules/machine/timer.c
@@ -37,32 +37,32 @@ enum {
 };
 
 typedef struct _machine_timer_obj_t {
-    mp_obj_base_t  base;
-    nrfx_timer_t   p_instance;
+    mp_obj_base_t base;
+    nrfx_timer_t p_instance;
 } machine_timer_obj_t;
 
 static mp_obj_t machine_timer_callbacks[] = {
     NULL,
     NULL,
     NULL,
-#if defined(NRF52_SERIES)
+    #if defined(NRF52_SERIES)
     NULL,
     NULL,
-#endif
+    #endif
 };
 
 static const machine_timer_obj_t machine_timer_obj[] = {
     {{&machine_timer_type}, NRFX_TIMER_INSTANCE(0)},
-#if MICROPY_PY_MACHINE_SOFT_PWM
+    #if MICROPY_PY_MACHINE_SOFT_PWM
     { },
-#else
+    #else
     {{&machine_timer_type}, NRFX_TIMER_INSTANCE(1)},
-#endif
+    #endif
     {{&machine_timer_type}, NRFX_TIMER_INSTANCE(2)},
-#if defined(NRF52_SERIES)
+    #if defined(NRF52_SERIES)
     {{&machine_timer_type}, NRFX_TIMER_INSTANCE(3)},
     {{&machine_timer_type}, NRFX_TIMER_INSTANCE(4)},
-#endif
+    #endif
 };
 
 void timer_init0(void) {
@@ -112,19 +112,19 @@ static mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args,
     // get static peripheral object
     int timer_id = timer_find(args[ARG_id].u_obj);
 
-#if BLUETOOTH_SD
+    #if BLUETOOTH_SD
     if (timer_id == 0) {
         mp_raise_ValueError(MP_ERROR_TEXT("Timer reserved by Bluetooth LE stack"));
     }
-#endif
+    #endif
 
-#if MICROPY_PY_MACHINE_SOFT_PWM
+    #if MICROPY_PY_MACHINE_SOFT_PWM
     if (timer_id == 1) {
         mp_raise_ValueError(MP_ERROR_TEXT("Timer reserved by ticker driver"));
     }
-#endif
+    #endif
 
-    machine_timer_obj_t *self = (machine_timer_obj_t*)&machine_timer_obj[timer_id];
+    machine_timer_obj_t *self = (machine_timer_obj_t *)&machine_timer_obj[timer_id];
 
     if (mp_obj_is_fun(args[ARG_callback].u_obj)) {
         machine_timer_callbacks[timer_id] = args[ARG_callback].u_obj;
@@ -163,11 +163,11 @@ static mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args,
         ((args[ARG_mode].u_int == TIMER_MODE_ONESHOT) ? NRF_TIMER_SHORT_COMPARE0_STOP_MASK : 0);
     bool enable_interrupts = true;
     nrfx_timer_extended_compare(
-            &self->p_instance,
-            NRF_TIMER_CC_CHANNEL0,
-            args[ARG_period].u_int,
-            short_mask,
-            enable_interrupts);
+        &self->p_instance,
+        NRF_TIMER_CC_CHANNEL0,
+        args[ARG_period].u_int,
+        short_mask,
+        enable_interrupts);
 
     return MP_OBJ_FROM_PTR(self);
 }
@@ -176,7 +176,7 @@ static mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args,
 /// Return counter value, which is currently in us.
 ///
 static mp_obj_t machine_timer_period(mp_obj_t self_in) {
-    machine_timer_obj_t * self = MP_OBJ_TO_PTR(self_in);
+    machine_timer_obj_t *self = MP_OBJ_TO_PTR(self_in);
 
     uint32_t period = nrfx_timer_capture(&self->p_instance, NRF_TIMER_CC_CHANNEL1);
 
@@ -188,7 +188,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_period_obj, machine_timer_period)
 /// Start the timer.
 ///
 static mp_obj_t machine_timer_start(mp_obj_t self_in) {
-    machine_timer_obj_t * self = MP_OBJ_TO_PTR(self_in);
+    machine_timer_obj_t *self = MP_OBJ_TO_PTR(self_in);
 
     nrfx_timer_enable(&self->p_instance);
 
@@ -200,7 +200,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_start_obj, machine_timer_start);
 /// Stop the timer.
 ///
 static mp_obj_t machine_timer_stop(mp_obj_t self_in) {
-    machine_timer_obj_t * self = MP_OBJ_TO_PTR(self_in);
+    machine_timer_obj_t *self = MP_OBJ_TO_PTR(self_in);
 
     nrfx_timer_disable(&self->p_instance);
 
@@ -212,7 +212,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_stop_obj, machine_timer_stop);
 /// Free resources associated with the timer.
 ///
 static mp_obj_t machine_timer_deinit(mp_obj_t self_in) {
-    machine_timer_obj_t * self = MP_OBJ_TO_PTR(self_in);
+    machine_timer_obj_t *self = MP_OBJ_TO_PTR(self_in);
 
     nrfx_timer_uninit(&self->p_instance);
 
diff --git a/ports/nrf/modules/machine/uart.c b/ports/nrf/modules/machine/uart.c
index 6da797df1f559..9e502941ab68e 100644
--- a/ports/nrf/modules/machine/uart.c
+++ b/ports/nrf/modules/machine/uart.c
@@ -88,8 +88,8 @@ typedef struct _machine_uart_buf_t {
 #endif
 
 typedef struct _machine_uart_obj_t {
-    mp_obj_base_t       base;
-    const nrfx_uart_t * p_uart;      // Driver instance
+    mp_obj_base_t base;
+    const nrfx_uart_t *p_uart;       // Driver instance
     machine_uart_buf_t buf;
     uint16_t timeout;       // timeout waiting for first char (in ms)
     uint16_t timeout_char;  // timeout waiting between chars (in ms)
@@ -206,19 +206,19 @@ static mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_arg
     nrfx_uart_config_t config;
 
     // flow control
-#if MICROPY_HW_UART1_HWFC
+    #if MICROPY_HW_UART1_HWFC
     config.hal_cfg.hwfc = NRF_UART_HWFC_ENABLED;
-#else
+    #else
     config.hal_cfg.hwfc = NRF_UART_HWFC_DISABLED;
-#endif
+    #endif
 
     config.hal_cfg.parity = NRF_UART_PARITY_EXCLUDED;
 
-#if (BLUETOOTH_SD == 100)
+    #if (BLUETOOTH_SD == 100)
     config.interrupt_priority = 3;
-#else
+    #else
     config.interrupt_priority = 6;
-#endif
+    #endif
 
     // These baudrates are not supported, it seems.
     if (args[ARG_baudrate].u_int < 1200 || args[ARG_baudrate].u_int > 1000000) {
@@ -239,10 +239,10 @@ static mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_arg
     config.pseltxd = MICROPY_HW_UART1_TX;
     config.pselrxd = MICROPY_HW_UART1_RX;
 
-#if MICROPY_HW_UART1_HWFC
+    #if MICROPY_HW_UART1_HWFC
     config.pselrts = MICROPY_HW_UART1_RTS;
     config.pselcts = MICROPY_HW_UART1_CTS;
-#endif
+    #endif
     self->timeout = args[ARG_timeout].u_int;
     self->timeout_char = args[ARG_timeout_char].u_int;
 
@@ -259,9 +259,9 @@ static mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_arg
     nrfx_uart_init(self->p_uart, &config, uart_event_handler);
     nrfx_uart_rx(self->p_uart, &self->buf.rx_buf[0], 1);
 
-#if NRFX_UART_ENABLED
+    #if NRFX_UART_ENABLED
     nrfx_uart_rx_enable(self->p_uart);
-#endif
+    #endif
 
     return MP_OBJ_FROM_PTR(self);
 }
diff --git a/tools/codeformat.py b/tools/codeformat.py
index bd37aec467f18..c65174ddc1278 100755
--- a/tools/codeformat.py
+++ b/tools/codeformat.py
@@ -59,11 +59,9 @@
     "ports/nrf/drivers/*.[ch]",
     "ports/nrf/modules/ble/*.[ch]",
     "ports/nrf/modules/board/*.[ch]",
-    "ports/nrf/modules/machine/*.[ch]",
     "ports/nrf/modules/music/*.[ch]",
     "ports/nrf/modules/ubluepy/*.[ch]",
     "ports/nrf/modules/os/*.[ch]",
-    "ports/nrf/modules/time/*.[ch]",
     # STM32 USB dev/host code is mostly 3rd party.
     "ports/stm32/usbdev/**/*.[ch]",
     "ports/stm32/usbhost/**/*.[ch]",

From b10182bbcc0ee78ce5d12902bc8da68bdc4429c5 Mon Sep 17 00:00:00 2001
From: Christian Walther 
Date: Mon, 1 Jan 2024 18:21:39 +0100
Subject: [PATCH 282/408] nrf: Fix non-running LFCLK.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Under some circumstances, after a hard reset, the low-frequency clock would
not be running.  This caused time.ticks_ms() to return 0, time.sleep_ms()
to get stuck, and other misbehavior.  A soft reboot would return it to a
working state.

The cause was a race condition that was hit when the bootloader would
itself turn LFCLK on, but turn it off again shortly before launching the
main application (this apparently happens with the Adafruit bootloader
from https://github.com/fanoush/ds-d6/tree/master/micropython).  Stopping
the clock is an asynchronous operation and it continues running for a short
time after the stop command is given.  When MicroPython checked whether to
start it by looking at the LFCLKSTAT register (nrf_clock_lf_is_running)
during that time, it would mistakenly not be started again.  What
MicroPython should be looking at is not whether the clock is running at
this time, but whether a start/stop command has been given, which is
indicated by the LFCLKRUN register (nrf_clock_lf_start_task_status_get).
It is not clearly documented, but empirically LFCLKRUN is not just set when
the LFCLKSTART task is triggered, but also cleared when the LFCLKSTOP task
is triggered, which is exactly what we need.

The matter is complicated by the fact that the nRF52832 has an anomaly
(see [errata](https://infocenter.nordicsemi.com/topic/errata_nRF52832_Rev3/ERR/nRF52832/Rev3/latest/anomaly_832_132.html?cp=5_2_1_0_1_33))
where starting the LFCLK will not work between 66µs and 138µs after it last
stopped. Apply a workaround for that.  See nrfx_clock_lfclk_start() in
micropython/lib/nrfx/drivers/src/nrfx_clock.c for reference, but we are not
using that because it also does other things and makes the code larger.

Signed-off-by: Christian Walther 
---
 ports/nrf/modules/machine/rtcounter.c |  5 ++--
 ports/nrf/mphalport.c                 | 34 ++++++++++++++++++++++++---
 ports/nrf/mphalport.h                 |  2 ++
 3 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/ports/nrf/modules/machine/rtcounter.c b/ports/nrf/modules/machine/rtcounter.c
index 08d31f61d0f9e..c1ef1b4dd977d 100644
--- a/ports/nrf/modules/machine/rtcounter.c
+++ b/ports/nrf/modules/machine/rtcounter.c
@@ -27,6 +27,7 @@
 
 #include "py/nlr.h"
 #include "py/runtime.h"
+#include "mphalport.h"
 #include "rtcounter.h"
 #include "nrfx_rtc.h"
 #include "nrf_clock.h"
@@ -182,9 +183,7 @@ static mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, s
     }
 
     // Start the low-frequency clock (if it hasn't been started already)
-    if (!nrf_clock_lf_is_running(NRF_CLOCK)) {
-        nrf_clock_task_trigger(NRF_CLOCK, NRF_CLOCK_TASK_LFCLKSTART);
-    }
+    mp_nrf_start_lfclk();
 
     // Make sure it's uninitialized.
     nrfx_rtc_uninit(self->p_rtc);
diff --git a/ports/nrf/mphalport.c b/ports/nrf/mphalport.c
index 2a1a4cb13ba36..06c6ba5cc2e76 100644
--- a/ports/nrf/mphalport.c
+++ b/ports/nrf/mphalport.c
@@ -40,6 +40,36 @@
 #include "nrf_clock.h"
 #endif
 
+#if !defined(USE_WORKAROUND_FOR_ANOMALY_132) && \
+    (defined(NRF52832_XXAA) || defined(NRF52832_XXAB))
+// ANOMALY 132 - LFCLK needs to avoid frame from 66us to 138us after LFCLK stop.
+#define USE_WORKAROUND_FOR_ANOMALY_132 1
+#endif
+
+#if USE_WORKAROUND_FOR_ANOMALY_132
+#include "soc/nrfx_coredep.h"
+#endif
+
+void mp_nrf_start_lfclk(void) {
+    if (!nrf_clock_lf_start_task_status_get(NRF_CLOCK)) {
+        // Check if the clock was recently stopped but is still running.
+        #if USE_WORKAROUND_FOR_ANOMALY_132
+        bool was_running = nrf_clock_lf_is_running(NRF_CLOCK);
+        // If so, wait for it to stop. This ensures that the delay for anomaly 132 workaround does
+        // not land us in the middle of the forbidden interval.
+        while (nrf_clock_lf_is_running(NRF_CLOCK)) {
+        }
+        // If the clock just stopped, we can start it again right away as we are certainly before
+        // the forbidden 66-138us interval. Otherwise, apply a delay of 138us to make sure we are
+        // after the interval.
+        if (!was_running) {
+            nrfx_coredep_delay_us(138);
+        }
+        #endif
+        nrf_clock_task_trigger(NRF_CLOCK, NRF_CLOCK_TASK_LFCLKSTART);
+    }
+}
+
 #if MICROPY_PY_TIME_TICKS
 
 // Use RTC1 for time ticks generation (ms and us) with 32kHz tick resolution
@@ -99,9 +129,7 @@ static void rtc_irq_time(nrfx_rtc_int_type_t event) {
 
 void rtc1_init_time_ticks(void) {
     // Start the low-frequency clock (if it hasn't been started already)
-    if (!nrf_clock_lf_is_running(NRF_CLOCK)) {
-        nrf_clock_task_trigger(NRF_CLOCK, NRF_CLOCK_TASK_LFCLKSTART);
-    }
+    mp_nrf_start_lfclk();
     // Uninitialize first, then set overflow IRQ and first CC event
     nrfx_rtc_uninit(&rtc1);
     nrfx_rtc_init(&rtc1, &rtc_config_time_ticks, rtc_irq_time);
diff --git a/ports/nrf/mphalport.h b/ports/nrf/mphalport.h
index 1ba4b6e70f081..7efe05a15fc8e 100644
--- a/ports/nrf/mphalport.h
+++ b/ports/nrf/mphalport.h
@@ -54,6 +54,8 @@ void mp_hal_delay_us(mp_uint_t us);
 
 const char *nrfx_error_code_lookup(uint32_t err_code);
 
+void mp_nrf_start_lfclk(void);
+
 #define MP_HAL_PIN_FMT           "%q"
 #define mp_hal_pin_obj_t const pin_obj_t *
 #define mp_hal_get_pin_obj(o)    pin_find(o)

From 5e926b222259cb38db5c044b2f7656e2bdba2513 Mon Sep 17 00:00:00 2001
From: Christian Walther 
Date: Fri, 5 Jan 2024 16:17:55 +0100
Subject: [PATCH 283/408] nrf/modules/machine: Catch exceptions from pin
 interrupts.

Exceptions in pin interrupt handlers would end up crashing MicroPython with
a "FATAL: uncaught exception".

In addition, MicroPython would get stuck trying to output this error
message, or generally any print output from inside a pin interrupt handler,
through the UART after the first character, so that only "F" was visible.
The reason was a matching interrupt priority between the running pin
interrupt and the UARTE interrupt signaling completion of the output
operation.  Fix that by increasing the UARTE interrupt priority.

Code taken from the stm32 port and adapted.

Signed-off-by: Christian Walther 
---
 ports/nrf/modules/machine/pin.c  | 25 ++++++++++++++++++++++++-
 ports/nrf/modules/machine/uart.c |  8 +++-----
 2 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/ports/nrf/modules/machine/pin.c b/ports/nrf/modules/machine/pin.c
index f86d878d17d7e..2191cc9521d01 100644
--- a/ports/nrf/modules/machine/pin.c
+++ b/ports/nrf/modules/machine/pin.c
@@ -33,6 +33,7 @@
 #include "py/nlr.h"
 #include "py/runtime.h"
 #include "py/mphal.h"
+#include "py/gc.h"
 #include "pin.h"
 #include "nrf_gpio.h"
 #include "nrfx_gpiote.h"
@@ -498,7 +499,29 @@ static void pin_common_irq_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t
     mp_obj_t pin_number = MP_OBJ_NEW_SMALL_INT(pin);
     const pin_obj_t *pin_obj = pin_find(pin_number);
 
-    mp_call_function_1(pin_handler, (mp_obj_t)pin_obj);
+    if (pin_handler != mp_const_none) {
+        #if MICROPY_ENABLE_SCHEDULER
+        mp_sched_lock();
+        #endif
+        // When executing code within a handler we must lock the GC to prevent
+        // any memory allocations.  We must also catch any exceptions.
+        gc_lock();
+        nlr_buf_t nlr;
+        if (nlr_push(&nlr) == 0) {
+            mp_call_function_1(pin_handler, (mp_obj_t)pin_obj);
+            nlr_pop();
+        } else {
+            // Uncaught exception; disable the callback so it doesn't run again.
+            MP_STATE_PORT(pin_irq_handlers)[pin] = mp_const_none;
+            nrfx_gpiote_in_uninit(pin);
+            mp_printf(MICROPY_ERROR_PRINTER, "uncaught exception in interrupt handler for Pin('%q')\n", pin_obj->name);
+            mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val));
+        }
+        gc_unlock();
+        #if MICROPY_ENABLE_SCHEDULER
+        mp_sched_unlock();
+        #endif
+    }
 }
 
 static mp_obj_t pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
diff --git a/ports/nrf/modules/machine/uart.c b/ports/nrf/modules/machine/uart.c
index 9e502941ab68e..de26fa1b12787 100644
--- a/ports/nrf/modules/machine/uart.c
+++ b/ports/nrf/modules/machine/uart.c
@@ -214,11 +214,9 @@ static mp_obj_t mp_machine_uart_make_new(const mp_obj_type_t *type, size_t n_arg
 
     config.hal_cfg.parity = NRF_UART_PARITY_EXCLUDED;
 
-    #if (BLUETOOTH_SD == 100)
-    config.interrupt_priority = 3;
-    #else
-    config.interrupt_priority = 6;
-    #endif
+    // Higher priority than pin interrupts, otherwise printing exceptions from
+    // interrupt handlers gets stuck.
+    config.interrupt_priority = NRFX_GPIOTE_DEFAULT_CONFIG_IRQ_PRIORITY - 1;
 
     // These baudrates are not supported, it seems.
     if (args[ARG_baudrate].u_int < 1200 || args[ARG_baudrate].u_int > 1000000) {

From 4dd288ff62a14d973166ef3b041ab0fe7c78863c Mon Sep 17 00:00:00 2001
From: robert-hh 
Date: Mon, 22 Jan 2024 18:04:44 +0100
Subject: [PATCH 284/408] nrf/modules/machine/pwm: Tag a PWM device as used in
 the constructor.

When PWM constructor was created without specifying a device or setting
both freq and duty rate, it was not tagged as used, and further calls to
get a PWM object may get the same PWM device assigned.

Fixes #13494.

Signed-off-by: robert-hh 
---
 ports/nrf/modules/machine/pwm.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/ports/nrf/modules/machine/pwm.c b/ports/nrf/modules/machine/pwm.c
index 393d1061799dd..8145509c76284 100644
--- a/ports/nrf/modules/machine/pwm.c
+++ b/ports/nrf/modules/machine/pwm.c
@@ -233,6 +233,11 @@ static mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args
     self->p_config->mode[pwm_channel] = MODE_HIGH_LOW;
     self->p_config->defer_start = false;
 
+    // Allocate the device if it was not used before.
+    if (hard_configs[pwm_id].active == FREE) {
+        hard_configs[pwm_id].active = STOPPED;
+    }
+
     // start the PWM running for this channel
     mp_map_t kw_args;
     mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args);

From 34c4625dcc52aa3f8284a43e86ca7f39e11c15f1 Mon Sep 17 00:00:00 2001
From: Andrew Leech 
Date: Thu, 21 Mar 2024 10:23:14 +1100
Subject: [PATCH 285/408] nrf/main: Fix build of microbit when SD is enabled.

Signed-off-by: Andrew Leech 
---
 ports/nrf/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ports/nrf/main.c b/ports/nrf/main.c
index dd9f232b80c55..07bf3e8adb5c6 100644
--- a/ports/nrf/main.c
+++ b/ports/nrf/main.c
@@ -262,7 +262,7 @@ void NORETURN _start(void) {
     led_state(1, 0);
 
     #if MICROPY_VFS || MICROPY_MBFS || MICROPY_MODULE_FROZEN
-    ret = pyexec_file_if_exists("boot.py");
+    ret_code = pyexec_file_if_exists("boot.py");
     #endif
 
     #if MICROPY_HW_USB_CDC
@@ -270,7 +270,7 @@ void NORETURN _start(void) {
     #endif
 
     #if MICROPY_VFS || MICROPY_MBFS || MICROPY_MODULE_FROZEN
-    if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL && ret != 0) {
+    if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL && ret_code != 0) {
         pyexec_file_if_exists("main.py");
     }
     #endif

From 994021e1e063c69ff79ea1d6c8ac263420ec3809 Mon Sep 17 00:00:00 2001
From: Andrew Leech 
Date: Fri, 22 Mar 2024 13:55:03 +1100
Subject: [PATCH 286/408] nrf/Makefile: Clean up dangling LIBS declaration.

Signed-off-by: Andrew Leech 
---
 ports/nrf/Makefile | 2 --
 1 file changed, 2 deletions(-)

diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile
index 31d0bc7668342..4fe921f0fad88 100644
--- a/ports/nrf/Makefile
+++ b/ports/nrf/Makefile
@@ -163,8 +163,6 @@ CFLAGS += -Os -DNDEBUG
 LDFLAGS += -Os
 endif
 
-LIBS = \
-
 ifeq ($(MCU_VARIANT), nrf52)
 
 SRC_LIB_C += $(SRC_LIB_LIBM_C)

From 438e5229115f18644b1cb463701fb6c8689d8ab5 Mon Sep 17 00:00:00 2001
From: iabdalkader 
Date: Wed, 13 Mar 2024 09:12:03 +0100
Subject: [PATCH 287/408] lib/arduino-lib: Add Arduino's external library.

This library contains external modules for Arduino boards.

Signed-off-by: iabdalkader 
---
 .gitmodules     | 3 +++
 lib/arduino-lib | 1 +
 2 files changed, 4 insertions(+)
 create mode 160000 lib/arduino-lib

diff --git a/.gitmodules b/.gitmodules
index 423d1bbeed8fb..e6712c1f9f40e 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -65,3 +65,6 @@
 [submodule "lib/libmetal"]
 	path = lib/libmetal
 	url = https://github.com/OpenAMP/libmetal.git
+[submodule "lib/arduino-lib"]
+	path = lib/arduino-lib
+	url = https://github.com/arduino/arduino-lib-mpy.git
diff --git a/lib/arduino-lib b/lib/arduino-lib
new file mode 160000
index 0000000000000..277efd50fcc63
--- /dev/null
+++ b/lib/arduino-lib
@@ -0,0 +1 @@
+Subproject commit 277efd50fcc637e2e2e87c9aa50c06acc9080970

From 27aa3c19bf347945fcd867095353b9b7df4af871 Mon Sep 17 00:00:00 2001
From: iabdalkader 
Date: Tue, 13 Feb 2024 08:48:34 +0100
Subject: [PATCH 288/408] stm32/boards/ARDUINO_GIGA: Add Arduino's external
 library.

Signed-off-by: iabdalkader 
---
 ports/stm32/boards/ARDUINO_GIGA/manifest.py      | 6 ++++++
 ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.mk | 3 +++
 2 files changed, 9 insertions(+)

diff --git a/ports/stm32/boards/ARDUINO_GIGA/manifest.py b/ports/stm32/boards/ARDUINO_GIGA/manifest.py
index b3c6b02e5ba07..b7b9a2b470d02 100644
--- a/ports/stm32/boards/ARDUINO_GIGA/manifest.py
+++ b/ports/stm32/boards/ARDUINO_GIGA/manifest.py
@@ -10,3 +10,9 @@
 
 # Bluetooth
 require("aioble")
+
+# Register external library
+add_library("arduino-lib", "$(ARDUINO_LIB_DIR)")
+
+# RPC
+require("msgpackrpc", library="arduino-lib")
diff --git a/ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.mk b/ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.mk
index 46fe40c2a6a82..f58c98af83cfd 100644
--- a/ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.mk
+++ b/ports/stm32/boards/ARDUINO_GIGA/mpconfigboard.mk
@@ -26,5 +26,8 @@ MICROPY_SSL_MBEDTLS = 1
 MICROPY_PY_OPENAMP = 1
 MICROPY_PY_OPENAMP_REMOTEPROC = 1
 
+ARDUINO_LIB_DIR = lib/arduino-lib
+GIT_SUBMODULES += $(ARDUINO_LIB_DIR)
 FROZEN_MANIFEST = $(BOARD_DIR)/manifest.py
+MICROPY_MANIFEST_ARDUINO_LIB_DIR = $(TOP)/$(ARDUINO_LIB_DIR)
 MBEDTLS_CONFIG_FILE = '"$(BOARD_DIR)/mbedtls_config_board.h"'

From 723cd03aeb2803dbeeb7d654202964c076043f54 Mon Sep 17 00:00:00 2001
From: iabdalkader 
Date: Wed, 13 Mar 2024 09:09:01 +0100
Subject: [PATCH 289/408] stm32/boards/ARDUINO_NICLA_VISION: Add Arduino's
 external library.

Signed-off-by: iabdalkader 
---
 ports/stm32/boards/ARDUINO_NICLA_VISION/manifest.py      | 6 ++++++
 ports/stm32/boards/ARDUINO_NICLA_VISION/mpconfigboard.mk | 3 +++
 2 files changed, 9 insertions(+)

diff --git a/ports/stm32/boards/ARDUINO_NICLA_VISION/manifest.py b/ports/stm32/boards/ARDUINO_NICLA_VISION/manifest.py
index b3c6b02e5ba07..b7b9a2b470d02 100644
--- a/ports/stm32/boards/ARDUINO_NICLA_VISION/manifest.py
+++ b/ports/stm32/boards/ARDUINO_NICLA_VISION/manifest.py
@@ -10,3 +10,9 @@
 
 # Bluetooth
 require("aioble")
+
+# Register external library
+add_library("arduino-lib", "$(ARDUINO_LIB_DIR)")
+
+# RPC
+require("msgpackrpc", library="arduino-lib")
diff --git a/ports/stm32/boards/ARDUINO_NICLA_VISION/mpconfigboard.mk b/ports/stm32/boards/ARDUINO_NICLA_VISION/mpconfigboard.mk
index 77d547bce05e9..0e8ff0e82d388 100644
--- a/ports/stm32/boards/ARDUINO_NICLA_VISION/mpconfigboard.mk
+++ b/ports/stm32/boards/ARDUINO_NICLA_VISION/mpconfigboard.mk
@@ -26,5 +26,8 @@ MICROPY_SSL_MBEDTLS = 1
 MICROPY_PY_OPENAMP = 1
 MICROPY_PY_OPENAMP_REMOTEPROC = 1
 
+ARDUINO_LIB_DIR = lib/arduino-lib
+GIT_SUBMODULES += $(ARDUINO_LIB_DIR)
 FROZEN_MANIFEST = $(BOARD_DIR)/manifest.py
+MICROPY_MANIFEST_ARDUINO_LIB_DIR = $(TOP)/$(ARDUINO_LIB_DIR)
 MBEDTLS_CONFIG_FILE = '"$(BOARD_DIR)/mbedtls_config_board.h"'

From da09646eabe7ac605d1bc5fe55c671a9856e1137 Mon Sep 17 00:00:00 2001
From: iabdalkader 
Date: Wed, 13 Mar 2024 09:09:42 +0100
Subject: [PATCH 290/408] stm32/boards/ARDUINO_PORTENTA_H7: Add Arduino's
 external library.

Signed-off-by: iabdalkader 
---
 ports/stm32/boards/ARDUINO_PORTENTA_H7/manifest.py      | 7 +++++++
 ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.mk | 3 +++
 2 files changed, 10 insertions(+)

diff --git a/ports/stm32/boards/ARDUINO_PORTENTA_H7/manifest.py b/ports/stm32/boards/ARDUINO_PORTENTA_H7/manifest.py
index b3c6b02e5ba07..eb53df0fbdeb2 100644
--- a/ports/stm32/boards/ARDUINO_PORTENTA_H7/manifest.py
+++ b/ports/stm32/boards/ARDUINO_PORTENTA_H7/manifest.py
@@ -10,3 +10,10 @@
 
 # Bluetooth
 require("aioble")
+
+# Register external library
+add_library("arduino-lib", "$(ARDUINO_LIB_DIR)")
+
+# RPC
+require("cmwx1", library="arduino-lib")
+require("msgpackrpc", library="arduino-lib")
diff --git a/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.mk b/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.mk
index c56c8f005f72b..3b173b3acdb92 100644
--- a/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.mk
+++ b/ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.mk
@@ -26,5 +26,8 @@ MICROPY_SSL_MBEDTLS = 1
 MICROPY_PY_OPENAMP = 1
 MICROPY_PY_OPENAMP_REMOTEPROC = 1
 
+ARDUINO_LIB_DIR = lib/arduino-lib
+GIT_SUBMODULES += $(ARDUINO_LIB_DIR)
 FROZEN_MANIFEST = $(BOARD_DIR)/manifest.py
+MICROPY_MANIFEST_ARDUINO_LIB_DIR = $(TOP)/$(ARDUINO_LIB_DIR)
 MBEDTLS_CONFIG_FILE = '"$(BOARD_DIR)/mbedtls_config_board.h"'

From fa6ccc7e722a4516a173087cd0812711f8452da7 Mon Sep 17 00:00:00 2001
From: iabdalkader 
Date: Fri, 15 Mar 2024 12:05:30 +0100
Subject: [PATCH 291/408] renesas-ra/boards/ARDUINO_PORTENTA_C33: Add Arduino's
 external library.

Signed-off-by: iabdalkader 
---
 ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/manifest.py    | 6 ++++++
 .../renesas-ra/boards/ARDUINO_PORTENTA_C33/mpconfigboard.mk | 3 +++
 2 files changed, 9 insertions(+)

diff --git a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/manifest.py b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/manifest.py
index b3c6b02e5ba07..7b35b54c7a90b 100644
--- a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/manifest.py
+++ b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/manifest.py
@@ -10,3 +10,9 @@
 
 # Bluetooth
 require("aioble")
+
+# Register external library
+add_library("arduino-lib", "$(ARDUINO_LIB_DIR)")
+
+# CMWX1 Lora module.
+require("cmwx1", library="arduino-lib")
diff --git a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/mpconfigboard.mk b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/mpconfigboard.mk
index de9902c16cf7f..9bb336d65e9d5 100644
--- a/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/mpconfigboard.mk
+++ b/ports/renesas-ra/boards/ARDUINO_PORTENTA_C33/mpconfigboard.mk
@@ -18,5 +18,8 @@ MICROPY_SSL_MBEDTLS = 1
 MICROPY_PY_NETWORK = 1
 MICROPY_PY_NETWORK_ESP_HOSTED = 1
 
+ARDUINO_LIB_DIR = lib/arduino-lib
+GIT_SUBMODULES += $(ARDUINO_LIB_DIR)
 FROZEN_MANIFEST = $(BOARD_DIR)/manifest.py
+MICROPY_MANIFEST_ARDUINO_LIB_DIR = $(TOP)/$(ARDUINO_LIB_DIR)
 MBEDTLS_CONFIG_FILE = '"$(BOARD_DIR)/mbedtls_config_board.h"'

From a0d31e54ae5219a2794784311b6df45b680007d2 Mon Sep 17 00:00:00 2001
From: Jim Mussared 
Date: Tue, 26 Mar 2024 13:10:45 +1100
Subject: [PATCH 292/408] esp8266/Makefile: Add support for C++ user C modules.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared 
---
 ports/esp8266/Makefile | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/ports/esp8266/Makefile b/ports/esp8266/Makefile
index 8af7aba0aa9de..1b9e9623b6297 100644
--- a/ports/esp8266/Makefile
+++ b/ports/esp8266/Makefile
@@ -96,6 +96,9 @@ COPT += -Os -DNDEBUG
 LDFLAGS += --gc-sections
 endif
 
+# Flags for optional C++ source code
+CXXFLAGS += $(filter-out -Wmissing-prototypes -Wold-style-definition -std=gnu99,$(CFLAGS))
+
 # Options for mpy-cross
 MPY_CROSS_FLAGS += -march=xtensa
 

From 57de9da35233b4120a00386c52485e68bbc931fb Mon Sep 17 00:00:00 2001
From: Amirreza Hamzavi 
Date: Sun, 1 Oct 2023 14:30:15 +0330
Subject: [PATCH 293/408] docs/library/machine.RTC: Add docs for RTC.memory()
 method.

Co-Authored-By: glenn20 

Signed-off-by: Amirreza Hamzavi 
---
 docs/library/machine.RTC.rst | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/docs/library/machine.RTC.rst b/docs/library/machine.RTC.rst
index be2be2eee5eea..fcd78f1c39863 100644
--- a/docs/library/machine.RTC.rst
+++ b/docs/library/machine.RTC.rst
@@ -75,6 +75,21 @@ Methods
       - ``wake`` specifies the sleep mode from where this interrupt can wake
         up the system.
 
+.. method:: RTC.memory([data])
+
+   ``RTC.memory(data)`` will write *data* to the RTC memory, where *data* is any
+   object which supports the buffer protocol (including `bytes`, `bytearray`,
+   `memoryview` and `array.array`). ``RTC.memory()`` reads RTC memory and returns
+   a `bytes` object.
+
+   Data written to RTC user memory is persistent across restarts, including
+   `machine.soft_reset()` and `machine.deepsleep()`.
+
+   The maximum length of RTC user memory is 2048 bytes by default on esp32,
+   and 492 bytes on esp8266.
+
+   Availability: esp32, esp8266 ports.
+
 Constants
 ---------
 

From d694ac6e1b316ad3aaed2589eb261a52aa6e22c9 Mon Sep 17 00:00:00 2001
From: Jim Mussared 
Date: Tue, 26 Mar 2024 15:23:21 +1100
Subject: [PATCH 294/408] py/makeqstrdata.py: Ensure that scope names get low
 qstr values.

Originally implemented in a patch file provided by @ironss-iotec.

Fixes issue #14093.

Signed-off-by: Jim Mussared 
---
 py/makeqstrdata.py | 17 ++++++++++++-----
 py/objtype.c       |  4 ++++
 py/qstr.c          |  2 +-
 py/scope.c         |  2 ++
 4 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/py/makeqstrdata.py b/py/makeqstrdata.py
index 3e5e7930a5b88..480344180a88a 100644
--- a/py/makeqstrdata.py
+++ b/py/makeqstrdata.py
@@ -223,11 +223,11 @@
     "zip",
 ]
 
-# Additional QSTRs that must have index <255 because they are stored in
-# `mp_binary_op_method_name` and `mp_unary_op_method_name` (see py/objtype.c).
+# Additional QSTRs that must have index <255 because they are stored as `byte` values.
 # These are not part of the .mpy compatibility list, but we place them in the
 # fixed unsorted pool (i.e. QDEF0) to ensure their indices are small.
-operator_qstr_list = {
+unsorted_qstr_list = {
+    # From py/objtype.c: used in the `mp_binary_op_method_name` and `mp_unary_op_method_name` tables.
     "__bool__",
     "__pos__",
     "__neg__",
@@ -286,6 +286,13 @@
     "__get__",
     "__set__",
     "__delete__",
+    # From py/scope.c: used in `scope_simple_name_table` table.
+    # Note: "" is already in `static_qstr_list`.
+    "",
+    "",
+    "",
+    "",
+    "",
 }
 
 
@@ -404,10 +411,10 @@ def print_qstr_data(qcfgs, qstrs):
         print("QDEF0(MP_QSTR_%s, %s)" % (qstr_escape(qstr), qbytes))
 
     # add remaining qstrs to the sorted (by value) pool (unless they're in
-    # operator_qstr_list, in which case add them to the unsorted pool)
+    # unsorted_qstr_list, in which case add them to the unsorted pool)
     for ident, qstr in sorted(qstrs.values(), key=lambda x: x[1]):
         qbytes = make_bytes(cfg_bytes_len, cfg_bytes_hash, qstr)
-        pool = 0 if qstr in operator_qstr_list else 1
+        pool = 0 if qstr in unsorted_qstr_list else 1
         print("QDEF%d(MP_QSTR_%s, %s)" % (pool, ident, qbytes))
 
 
diff --git a/py/objtype.c b/py/objtype.c
index 8b2eb6de04eec..b6d600e9434d7 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -370,6 +370,8 @@ static mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_arg
 
 // Qstrs for special methods are guaranteed to have a small value, so we use byte
 // type to represent them.
+// The (unescaped) names appear in `unsorted_str_list` in the QSTR
+// generator script py/makeqstrdata.py to ensure they are assigned low numbers.
 const byte mp_unary_op_method_name[MP_UNARY_OP_NUM_RUNTIME] = {
     [MP_UNARY_OP_BOOL] = MP_QSTR___bool__,
     [MP_UNARY_OP_LEN] = MP_QSTR___len__,
@@ -468,6 +470,8 @@ static mp_obj_t instance_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
 // fail).  They can be added at the expense of code size for the qstr.
 // Qstrs for special methods are guaranteed to have a small value, so we use byte
 // type to represent them.
+// The (unescaped) names appear in `unsorted_str_list` in the QSTR
+// generator script py/makeqstrdata.py to ensure they are assigned low numbers.
 const byte mp_binary_op_method_name[MP_BINARY_OP_NUM_RUNTIME] = {
     [MP_BINARY_OP_LESS] = MP_QSTR___lt__,
     [MP_BINARY_OP_MORE] = MP_QSTR___gt__,
diff --git a/py/qstr.c b/py/qstr.c
index 3720932250ca8..fea7f44fe13bf 100644
--- a/py/qstr.c
+++ b/py/qstr.c
@@ -79,7 +79,7 @@ size_t qstr_compute_hash(const byte *data, size_t len) {
 // it is part of the .mpy ABI. See the top of py/persistentcode.c and
 // static_qstr_list in makeqstrdata.py. This pool is unsorted (although in a
 // future .mpy version we could re-order them and make it sorted). It also
-// contains additional qstrs that must have IDs <256, see operator_qstr_list
+// contains additional qstrs that must have IDs <256, see unsorted_qstr_list
 // in makeqstrdata.py.
 #if MICROPY_QSTR_BYTES_IN_HASH
 const qstr_hash_t mp_qstr_const_hashes_static[] = {
diff --git a/py/scope.c b/py/scope.c
index 1a4c6cc77f156..4893e7cc4e5e1 100644
--- a/py/scope.c
+++ b/py/scope.c
@@ -31,6 +31,8 @@
 #if MICROPY_ENABLE_COMPILER
 
 // These low numbered qstrs should fit in 8 bits.  See assertions below.
+// The (unescaped) names appear in `unsorted_str_list` in the QSTR
+// generator script py/makeqstrdata.py to ensure they are assigned low numbers.
 static const uint8_t scope_simple_name_table[] = {
     [SCOPE_MODULE] = MP_QSTR__lt_module_gt_,
     [SCOPE_LAMBDA] = MP_QSTR__lt_lambda_gt_,

From 79edaddf501f30b44c544fd9dbef8b073c63cd0f Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Tue, 26 Mar 2024 18:57:18 +1100
Subject: [PATCH 295/408] rp2/CMakeLists: Apply O2 optimisation to map, mpz and
 vm source code.

Enabling this optimisation increases the RPI_PICO firmware by +3344 bytes.

Performace change is:

diff of scores (higher is better)
N=100 M=100             rpi-base -> rpi-opt      diff      diff% (error%)
bm_chaos.py               196.56 ->  215.26 :  +18.70 =  +9.514% (+/-0.05%)
bm_fannkuch.py             52.47 ->   54.37 :   +1.90 =  +3.621% (+/-0.05%)
bm_fft.py                1476.74 -> 1530.06 :  +53.32 =  +3.611% (+/-0.01%)
bm_float.py              2305.65 -> 2444.11 : +138.46 =  +6.005% (+/-0.08%)
bm_hexiom.py               32.83 ->   35.09 :   +2.26 =  +6.884% (+/-0.05%)
bm_nqueens.py            2335.85 -> 2259.78 :  -76.07 =  -3.257% (+/-0.06%)
bm_pidigits.py            366.23 ->  465.81 :  +99.58 = +27.191% (+/-0.04%)
bm_wordcount.py            41.20 ->   41.87 :   +0.67 =  +1.626% (+/-0.01%)
core_import_mpy_multi.py  327.44 ->  335.24 :   +7.80 =  +2.382% (+/-0.08%)
core_import_mpy_single.py  63.41 ->   64.98 :   +1.57 =  +2.476% (+/-0.21%)
core_locals.py             27.24 ->   29.19 :   +1.95 =  +7.159% (+/-0.01%)
core_qstr.py              137.31 ->  140.84 :   +3.53 =  +2.571% (+/-0.03%)
core_str.py                18.44 ->   18.10 :   -0.34 =  -1.844% (+/-0.03%)
core_yield_from.py        221.69 ->  211.72 :   -9.97 =  -4.497% (+/-0.01%)
misc_aes.py               303.38 ->  308.72 :   +5.34 =  +1.760% (+/-0.02%)
misc_mandel.py           1501.00 -> 1746.60 : +245.60 = +16.362% (+/-0.04%)
misc_pystone.py          1348.22 -> 1456.75 : +108.53 =  +8.050% (+/-0.07%)
misc_raytrace.py          223.81 ->  246.16 :  +22.35 =  +9.986% (+/-0.07%)
viper_call0.py            331.05 ->  331.10 :   +0.05 =  +0.015% (+/-0.00%)
viper_call1a.py           323.34 ->  323.39 :   +0.05 =  +0.015% (+/-0.00%)
viper_call1b.py           241.01 ->  241.04 :   +0.03 =  +0.012% (+/-0.00%)
viper_call1c.py           242.88 ->  242.92 :   +0.04 =  +0.016% (+/-0.00%)
viper_call2a.py           318.41 ->  318.46 :   +0.05 =  +0.016% (+/-0.00%)
viper_call2b.py           211.27 ->  211.30 :   +0.03 =  +0.014% (+/-0.00%)

And the test `tests/basics/builtin_pow3_intbig.py` now passes (it uses a
lot of mpz code and previously took longer than 10 seconds to run on
RPI_PICO, which would lead to a timeout in the test runner).

Signed-off-by: Damien George 
---
 ports/rp2/CMakeLists.txt | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt
index b605faaf2100e..fcc435b7b9f34 100644
--- a/ports/rp2/CMakeLists.txt
+++ b/ports/rp2/CMakeLists.txt
@@ -455,6 +455,15 @@ target_link_options(${MICROPY_TARGET} PRIVATE
     -Wl,--wrap=dcd_event_handler
 )
 
+# Apply optimisations to performance-critical source code.
+set_source_files_properties(
+    ${MICROPY_PY_DIR}/map.c
+    ${MICROPY_PY_DIR}/mpz.c
+    ${MICROPY_PY_DIR}/vm.c
+    PROPERTIES
+    COMPILE_OPTIONS "-O2"
+)
+
 set_source_files_properties(
     ${PICO_SDK_PATH}/src/rp2_common/pico_double/double_math.c
     ${PICO_SDK_PATH}/src/rp2_common/pico_float/float_math.c

From 935f5391b51fb1e9f998cd7a38622296e3a79815 Mon Sep 17 00:00:00 2001
From: Angus Gratton 
Date: Wed, 27 Mar 2024 14:52:09 +1100
Subject: [PATCH 296/408] shared/tinyusb: Don't disconnect on soft reset unless
 USB was active.

Previously, constructing the singleton USBDevice object was enough to
trigger a USB disconnect on soft reset. Now it also has to be active.

The only case where this changes the behaviour is if the USBDevice object
has been constructed but never set to active (no more disconnect in this
case). Otherwise, behaviour is the same.

This change was requested by hippy on the raspberrypi forums.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton 
---
 shared/tinyusb/mp_usbd_runtime.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/shared/tinyusb/mp_usbd_runtime.c b/shared/tinyusb/mp_usbd_runtime.c
index a46c0f85e6bdd..2e2f7b75e406c 100644
--- a/shared/tinyusb/mp_usbd_runtime.c
+++ b/shared/tinyusb/mp_usbd_runtime.c
@@ -431,11 +431,12 @@ void mp_usbd_init(void) {
 // Top-level USB device deinit.
 //
 // This variant is called from soft reset, NULLs out the USB device
-// singleton instance from MP_STATE_VM, and disconnects the port.
+// singleton instance from MP_STATE_VM, and disconnects the port if a
+// runtime device was active.
 void mp_usbd_deinit(void) {
     mp_obj_usb_device_t *usbd = MP_OBJ_TO_PTR(MP_STATE_VM(usbd));
     MP_STATE_VM(usbd) = MP_OBJ_NULL;
-    if (usbd) {
+    if (usbd && usbd->active) {
         // Disconnect if a runtime USB device was active
         mp_usbd_disconnect(usbd);
     }

From 0f16ae92c0cf1e18d9612d0e2b29475a4d6719d8 Mon Sep 17 00:00:00 2001
From: Angus Gratton 
Date: Wed, 27 Mar 2024 14:55:16 +1100
Subject: [PATCH 297/408] shared/tinyusb: Update some code comments for runtime
 USB.

Updates a few code comments that were out of date or poorly worded. No code
changes.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton 
---
 shared/tinyusb/mp_usbd_runtime.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/shared/tinyusb/mp_usbd_runtime.c b/shared/tinyusb/mp_usbd_runtime.c
index 2e2f7b75e406c..0b4c79831becd 100644
--- a/shared/tinyusb/mp_usbd_runtime.c
+++ b/shared/tinyusb/mp_usbd_runtime.c
@@ -44,7 +44,7 @@
 #include "device/usbd_pvt.h"
 #endif
 
-static bool in_usbd_task; // Flags if mp_usbd_task() is processing already
+static bool in_usbd_task; // Flags if mp_usbd_task() is currently running
 
 // Some top-level functions that manage global TinyUSB USBD state, not the
 // singleton object visible to Python
@@ -250,8 +250,8 @@ static uint16_t _runtime_dev_claim_itfs(tusb_desc_interface_t const *itf_desc, u
 // configuration. Returns number of bytes to claim from descriptors pointed to
 // by itf_desc.
 //
-// This is a little fiddly as it's called before any compiled-in "static"
-// TinyUSB drivers, but we don't want to override those.
+// This is a little fiddly as it's called before any built-in TinyUSB drivers,
+// but we don't want to override those.
 //
 // Also, TinyUSB expects us to know how many interfaces to claim for each time
 // this function is called, and will behave unexpectedly if we claim the wrong
@@ -266,7 +266,7 @@ static uint16_t runtime_dev_open(uint8_t rhport, tusb_desc_interface_t const *it
         return 0;
     }
 
-    // If TinyUSB built-in drivers are enabled, don't claim any interface in the static range
+    // If TinyUSB built-in drivers are enabled, don't claim any interface in the built-in range
     if (mp_usb_device_builtin_enabled(usbd) && itf_desc->bInterfaceNumber < USBD_ITF_BUILTIN_MAX) {
         return 0;
     }
@@ -400,7 +400,7 @@ usbd_class_driver_t const *usbd_app_driver_get_cb(uint8_t *driver_count) {
 
 // Top-level USB device subsystem init.
 //
-// Makes an on-demand call to mp_usbd_activate(), if USB is needed.
+// Initialises TinyUSB and/or re-activates it, provided USB is needed.
 //
 // This is called on any soft reset after boot.py runs, or on demand if the
 // user activates USB and it hasn't activated yet.
@@ -414,7 +414,7 @@ void mp_usbd_init(void) {
         // Builtin  drivers are available, so initialise as defaults
         need_usb = true;
         #else
-        // No static drivers, nothing to initialise
+        // No builtin drivers, nothing to initialise
         need_usb = false;
         #endif
     } else {
@@ -472,7 +472,10 @@ static void mp_usbd_disconnect(mp_obj_usb_device_t *usbd) {
     bool was_connected = tud_connected();
     tud_disconnect();
     if (was_connected) {
-        mp_hal_delay_ms(50); // TODO: Always???
+        // Need to ensure a long enough delay before TinyUSB re-connects that
+        // the host triggers a bus reset. This may happen anyway, but delaying here
+        // lets us be "belt and braces" sure.
+        mp_hal_delay_ms(50);
     }
 }
 

From 35e8d184b1456ae0ed6f1df60e5559462179ded1 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Wed, 27 Mar 2024 15:00:37 +1100
Subject: [PATCH 298/408] shared/tinyusb: Increase default string descr max
 length to 40 chars.

When defining custom USB devices, longer strings may be needed.  Eventually
the memory for string descriptors can be allocated on demand, but for now
this bigger value should be reasonable.

Signed-off-by: Damien George 
---
 shared/tinyusb/tusb_config.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/shared/tinyusb/tusb_config.h b/shared/tinyusb/tusb_config.h
index c5644e3d583b2..ab47321afdc04 100644
--- a/shared/tinyusb/tusb_config.h
+++ b/shared/tinyusb/tusb_config.h
@@ -104,7 +104,7 @@
 #define USBD_MAX_POWER_MA (250)
 
 #ifndef MICROPY_HW_USB_DESC_STR_MAX
-#define MICROPY_HW_USB_DESC_STR_MAX (20)
+#define MICROPY_HW_USB_DESC_STR_MAX (40)
 #endif
 
 #if CFG_TUD_CDC

From db1b5df16c193190aa2f86ccfad97f6d014bd4c1 Mon Sep 17 00:00:00 2001
From: Matt Trentini 
Date: Wed, 27 Mar 2024 10:53:33 +1100
Subject: [PATCH 299/408] stm32/README: Update list of supported STM32 series.

Signed-off-by: Matt Trentini 
---
 ports/stm32/README.md | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/ports/stm32/README.md b/ports/stm32/README.md
index 15025c5ae15cc..cd9e291396efe 100644
--- a/ports/stm32/README.md
+++ b/ports/stm32/README.md
@@ -2,9 +2,9 @@ MicroPython port to STM32 MCUs
 ==============================
 
 This directory contains the port of MicroPython to ST's line of STM32
-microcontrollers.  Supported MCU series are: STM32F0, STM32F4, STM32F7,
-STM32H7, STM32L0, STM32L4 and STM32WB.  Parts of the code here utilise the
-STM32Cube HAL library.
+microcontrollers.  Supported MCU series are: STM32F0, STM32F4, STM32F7, STM32G0,
+STM32G4, STM32H5, STM32H7, STM32L0, STM32L1, STM32L4, STM32WL and STM32WB.
+Parts of the code here utilise the STM32Cube HAL library.
 
 The officially supported boards are the line of pyboards: PYBv1.0 and PYBv1.1
 (both with STM32F405), PYBLITEv1.0 (with STM32F411) and PYBD-SFx (with
@@ -16,12 +16,6 @@ Other boards that are supported include ST Discovery and Nucleo boards.
 See the boards/ subdirectory, which contains the configuration files used
 to build each individual board.
 
-The STM32H7 series has preliminary support: there is a working REPL via
-USB and UART, as well as very basic peripheral support, but some things do
-not work and none of the advanced features of the STM32H7 are yet supported,
-such as the clock tree.  At this point the STM32H7 should be considered as a
-fast version of the STM32F7.
-
 Build instructions
 ------------------
 

From 5a7d78c732f5bdf608298c261549ab605ca5c338 Mon Sep 17 00:00:00 2001
From: iabdalkader 
Date: Sun, 3 Mar 2024 16:25:45 +0100
Subject: [PATCH 300/408] mimxrt,stm32: Set the security mode for the default
 WiFi AP.

The default CYW43 WiFi AP settings were missing the security mode, leaving
the AP in open mode by default.  That's changed by this commit to use
WPA/WPA2 by default.

Signed-off-by: iabdalkader 
---
 ports/mimxrt/main.c | 1 +
 ports/stm32/main.c  | 1 +
 2 files changed, 2 insertions(+)

diff --git a/ports/mimxrt/main.c b/ports/mimxrt/main.c
index dddf44e605f05..adb071a7fee8f 100644
--- a/ports/mimxrt/main.c
+++ b/ports/mimxrt/main.c
@@ -87,6 +87,7 @@ int main(void) {
         memcpy(&buf[0], "PYBD", 4);
         mp_hal_get_mac_ascii(MP_HAL_MAC_WLAN0, 8, 4, (char *)&buf[4]);
         cyw43_wifi_ap_set_ssid(&cyw43_state, 8, buf);
+        cyw43_wifi_ap_set_auth(&cyw43_state, CYW43_AUTH_WPA2_MIXED_PSK);
         cyw43_wifi_ap_set_password(&cyw43_state, 8, (const uint8_t *)"pybd0123");
     }
     #endif
diff --git a/ports/stm32/main.c b/ports/stm32/main.c
index 802a884d87d7f..90a62c024427e 100644
--- a/ports/stm32/main.c
+++ b/ports/stm32/main.c
@@ -477,6 +477,7 @@ void stm32_main(uint32_t reset_mode) {
         memcpy(&buf[0], "PYBD", 4);
         mp_hal_get_mac_ascii(MP_HAL_MAC_WLAN0, 8, 4, (char *)&buf[4]);
         cyw43_wifi_ap_set_ssid(&cyw43_state, 8, buf);
+        cyw43_wifi_ap_set_auth(&cyw43_state, CYW43_AUTH_WPA2_MIXED_PSK);
         cyw43_wifi_ap_set_password(&cyw43_state, 8, (const uint8_t *)"pybd0123");
     }
     #endif

From 7753045a8febc69e9476f0985573575a05938c71 Mon Sep 17 00:00:00 2001
From: iabdalkader 
Date: Sun, 3 Mar 2024 16:13:55 +0100
Subject: [PATCH 301/408] extmod: Add interface and security constants at WLAN
 class level.

Other constants such as `machine.Pin.OUT` are defined on the class that
uses them, rather than at the module level.  This commit makes that the
case for WLAN network interfaces, adding IF_xxx and SEC_xxx constants.

The SEC_xxx constants are named as such to match the `security` keyword
that they are used with.  And the IF_xxx constants have IF as a prefix so
they are grouped together as names.

This scheme of putting constants on the class means that only the available
features (eg security configurations) are made available as constants.  It
also means that different network interfaces (eg WLAN vs LAN) can keep
their own specific constants within their class, such as PHY_xxx for LAN.

Signed-off-by: iabdalkader 
---
 extmod/network_cyw43.c      |  5 +++++
 extmod/network_esp_hosted.c |  9 +++++++++
 extmod/network_ninaw10.c    | 12 +++++++++---
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/extmod/network_cyw43.c b/extmod/network_cyw43.c
index d3543c5260435..3066cac75d3b7 100644
--- a/extmod/network_cyw43.c
+++ b/extmod/network_cyw43.c
@@ -543,6 +543,11 @@ static const mp_rom_map_elem_t network_cyw43_locals_dict_table[] = {
     { MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&network_cyw43_config_obj) },
 
     // Class constants.
+    { MP_ROM_QSTR(MP_QSTR_IF_STA), MP_ROM_INT(MOD_NETWORK_STA_IF) },
+    { MP_ROM_QSTR(MP_QSTR_IF_AP), MP_ROM_INT(MOD_NETWORK_AP_IF) },
+    { MP_ROM_QSTR(MP_QSTR_SEC_OPEN), MP_ROM_INT(CYW43_AUTH_OPEN) },
+    { MP_ROM_QSTR(MP_QSTR_SEC_WPA_WPA2), MP_ROM_INT(CYW43_AUTH_WPA2_MIXED_PSK) },
+
     { MP_ROM_QSTR(MP_QSTR_PM_NONE), MP_ROM_INT(PM_NONE) },
     { MP_ROM_QSTR(MP_QSTR_PM_PERFORMANCE), MP_ROM_INT(PM_PERFORMANCE) },
     { MP_ROM_QSTR(MP_QSTR_PM_POWERSAVE), MP_ROM_INT(PM_POWERSAVE) },
diff --git a/extmod/network_esp_hosted.c b/extmod/network_esp_hosted.c
index f86eaad37ca0f..0747343d87ea6 100644
--- a/extmod/network_esp_hosted.c
+++ b/extmod/network_esp_hosted.c
@@ -309,6 +309,15 @@ static const mp_rom_map_elem_t network_esp_hosted_locals_dict_table[] = {
     { MP_ROM_QSTR(MP_QSTR_ipconfig),            MP_ROM_PTR(&network_esp_hosted_ipconfig_obj) },
     { MP_ROM_QSTR(MP_QSTR_config),              MP_ROM_PTR(&network_esp_hosted_config_obj) },
     { MP_ROM_QSTR(MP_QSTR_status),              MP_ROM_PTR(&network_esp_hosted_status_obj) },
+
+    // Class constants.
+    { MP_ROM_QSTR(MP_QSTR_IF_STA),              MP_ROM_INT(MOD_NETWORK_STA_IF) },
+    { MP_ROM_QSTR(MP_QSTR_IF_AP),               MP_ROM_INT(MOD_NETWORK_AP_IF) },
+    { MP_ROM_QSTR(MP_QSTR_SEC_OPEN),            MP_ROM_INT(ESP_HOSTED_SEC_OPEN) },
+    { MP_ROM_QSTR(MP_QSTR_SEC_WEP),             MP_ROM_INT(ESP_HOSTED_SEC_WEP) },
+    { MP_ROM_QSTR(MP_QSTR_SEC_WPA_WPA2),        MP_ROM_INT(ESP_HOSTED_SEC_WPA_WPA2_PSK) },
+
+    // For backwards compatibility.
     { MP_ROM_QSTR(MP_QSTR_OPEN),                MP_ROM_INT(ESP_HOSTED_SEC_OPEN) },
     { MP_ROM_QSTR(MP_QSTR_WEP),                 MP_ROM_INT(ESP_HOSTED_SEC_WEP) },
     { MP_ROM_QSTR(MP_QSTR_WPA_PSK),             MP_ROM_INT(ESP_HOSTED_SEC_WPA_WPA2_PSK) },
diff --git a/extmod/network_ninaw10.c b/extmod/network_ninaw10.c
index 90cdafc7a430a..926e228a35b88 100644
--- a/extmod/network_ninaw10.c
+++ b/extmod/network_ninaw10.c
@@ -860,11 +860,17 @@ static const mp_rom_map_elem_t nina_locals_dict_table[] = {
     { MP_ROM_QSTR(MP_QSTR_status),              MP_ROM_PTR(&network_ninaw10_status_obj) },
     { MP_ROM_QSTR(MP_QSTR_ioctl),               MP_ROM_PTR(&network_ninaw10_ioctl_obj) },
 
-    // Network is not secured.
+    // Class constants.
+    { MP_ROM_QSTR(MP_QSTR_IF_STA),              MP_ROM_INT(MOD_NETWORK_STA_IF) },
+    { MP_ROM_QSTR(MP_QSTR_IF_AP),               MP_ROM_INT(MOD_NETWORK_AP_IF) },
+
+    { MP_ROM_QSTR(MP_QSTR_SEC_OPEN),            MP_ROM_INT(NINA_SEC_OPEN) },
+    { MP_ROM_QSTR(MP_QSTR_SEC_WEP),             MP_ROM_INT(NINA_SEC_WEP) },
+    { MP_ROM_QSTR(MP_QSTR_SEC_WPA_WPA2),        MP_ROM_INT(NINA_SEC_WPA_PSK) },
+
+    // For backwards compatibility.
     { MP_ROM_QSTR(MP_QSTR_OPEN),                MP_ROM_INT(NINA_SEC_OPEN) },
-    // Security type WEP (40 or 104).
     { MP_ROM_QSTR(MP_QSTR_WEP),                 MP_ROM_INT(NINA_SEC_WEP) },
-    // Network secured with WPA/WPA2 personal(PSK).
     { MP_ROM_QSTR(MP_QSTR_WPA_PSK),             MP_ROM_INT(NINA_SEC_WPA_PSK) },
 };
 

From 81dff08bf24c78bdb06413a8e459b6dd305111da Mon Sep 17 00:00:00 2001
From: iabdalkader 
Date: Thu, 14 Mar 2024 14:39:20 +0100
Subject: [PATCH 302/408] esp8266/network_wlan: Add interface and security WLAN
 constants.

Following the same change to extmod network interfaces.

Signed-off-by: iabdalkader 
---
 ports/esp8266/network_wlan.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/ports/esp8266/network_wlan.c b/ports/esp8266/network_wlan.c
index 5838cc8bc6a86..af1611a2496ed 100644
--- a/ports/esp8266/network_wlan.c
+++ b/ports/esp8266/network_wlan.c
@@ -516,6 +516,15 @@ static const mp_rom_map_elem_t wlan_if_locals_dict_table[] = {
     { MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&esp_ifconfig_obj) },
 
     // Constants
+    { MP_ROM_QSTR(MP_QSTR_IF_STA), MP_ROM_INT(STATION_IF)},
+    { MP_ROM_QSTR(MP_QSTR_IF_AP), MP_ROM_INT(SOFTAP_IF)},
+
+    { MP_ROM_QSTR(MP_QSTR_SEC_OPEN), MP_ROM_INT(AUTH_OPEN) },
+    { MP_ROM_QSTR(MP_QSTR_SEC_WEP), MP_ROM_INT(AUTH_WEP) },
+    { MP_ROM_QSTR(MP_QSTR_SEC_WPA), MP_ROM_INT(AUTH_WPA_PSK) },
+    { MP_ROM_QSTR(MP_QSTR_SEC_WPA2), MP_ROM_INT(AUTH_WPA2_PSK) },
+    { MP_ROM_QSTR(MP_QSTR_SEC_WPA_WPA2), MP_ROM_INT(AUTH_WPA_WPA2_PSK) },
+
     { MP_ROM_QSTR(MP_QSTR_PM_NONE), MP_ROM_INT(NONE_SLEEP_T) },
     { MP_ROM_QSTR(MP_QSTR_PM_PERFORMANCE), MP_ROM_INT(MODEM_SLEEP_T) },
     { MP_ROM_QSTR(MP_QSTR_PM_POWERSAVE), MP_ROM_INT(LIGHT_SLEEP_T) },

From e8dd519e2dfb5c33cb7c304cd94ad24757bec0d3 Mon Sep 17 00:00:00 2001
From: iabdalkader 
Date: Thu, 14 Mar 2024 14:39:53 +0100
Subject: [PATCH 303/408] esp32/network_wlan: Add interface and security WLAN
 constants.

Following the same change to extmod network interfaces.

Signed-off-by: iabdalkader 
---
 ports/esp32/network_wlan.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/ports/esp32/network_wlan.c b/ports/esp32/network_wlan.c
index ece88e705f942..eb2bcda03e1b8 100644
--- a/ports/esp32/network_wlan.c
+++ b/ports/esp32/network_wlan.c
@@ -730,6 +730,20 @@ static const mp_rom_map_elem_t wlan_if_locals_dict_table[] = {
     { MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&esp_network_ifconfig_obj) },
 
     // Constants
+    { MP_ROM_QSTR(MP_QSTR_IF_STA), MP_ROM_INT(WIFI_IF_STA)},
+    { MP_ROM_QSTR(MP_QSTR_IF_AP), MP_ROM_INT(WIFI_IF_AP)},
+
+    { MP_ROM_QSTR(MP_QSTR_SEC_OPEN), MP_ROM_INT(WIFI_AUTH_OPEN) },
+    { MP_ROM_QSTR(MP_QSTR_SEC_WEP), MP_ROM_INT(WIFI_AUTH_WEP) },
+    { MP_ROM_QSTR(MP_QSTR_SEC_WPA), MP_ROM_INT(WIFI_AUTH_WPA_PSK) },
+    { MP_ROM_QSTR(MP_QSTR_SEC_WPA2), MP_ROM_INT(WIFI_AUTH_WPA2_PSK) },
+    { MP_ROM_QSTR(MP_QSTR_SEC_WPA_WPA2), MP_ROM_INT(WIFI_AUTH_WPA_WPA2_PSK) },
+    { MP_ROM_QSTR(MP_QSTR_SEC_WPA2_ENT), MP_ROM_INT(WIFI_AUTH_WPA2_ENTERPRISE) },
+    { MP_ROM_QSTR(MP_QSTR_SEC_WPA3), MP_ROM_INT(WIFI_AUTH_WPA3_PSK) },
+    { MP_ROM_QSTR(MP_QSTR_SEC_WPA2_WPA3), MP_ROM_INT(WIFI_AUTH_WPA2_WPA3_PSK) },
+    { MP_ROM_QSTR(MP_QSTR_SEC_WAPI), MP_ROM_INT(WIFI_AUTH_WAPI_PSK) },
+    { MP_ROM_QSTR(MP_QSTR_SEC_OWE), MP_ROM_INT(WIFI_AUTH_OWE) },
+
     { MP_ROM_QSTR(MP_QSTR_PM_NONE), MP_ROM_INT(WIFI_PS_NONE) },
     { MP_ROM_QSTR(MP_QSTR_PM_PERFORMANCE), MP_ROM_INT(WIFI_PS_MIN_MODEM) },
     { MP_ROM_QSTR(MP_QSTR_PM_POWERSAVE), MP_ROM_INT(WIFI_PS_MAX_MODEM) },

From 328b6df0581cdc1bd72bf2624a5cc31d86ba7693 Mon Sep 17 00:00:00 2001
From: robert-hh 
Date: Sun, 3 Mar 2024 20:24:31 +0100
Subject: [PATCH 304/408] samd/README: Fix incorrect port directory name.

At a single place, STM32 was used instead of SAMD.

Signed-off-by: robert-hh 
---
 ports/samd/README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ports/samd/README.md b/ports/samd/README.md
index 49e967102ecd9..8a7f121b66d30 100644
--- a/ports/samd/README.md
+++ b/ports/samd/README.md
@@ -23,7 +23,7 @@ bytecode.  The cross-compiler is built and run on the host machine, using:
     $ make -C mpy-cross
 
 This command should be executed from the root directory of this repository.
-All other commands below should be executed from the ports/stm32/ directory.
+All other commands below should be executed from the ports/samd/ directory.
 
 An ARM compiler is required for the build, along with the associated binary
 utilities.  The default compiler is `arm-none-eabi-gcc`, which is available for

From b41360d11920ae0bc97262bbfc20f3ab1572fae2 Mon Sep 17 00:00:00 2001
From: robert-hh 
Date: Tue, 19 Mar 2024 07:54:43 +0100
Subject: [PATCH 305/408] samd/boards: Enable MICROPY_HW_DFLL_USB_SYNC on
 appropriate boards.

For the boards ADAFRUIT_TRINKET_M0 and MINISAM_M4.

Signed-off-by: robert-hh 
---
 ports/samd/boards/ADAFRUIT_TRINKET_M0/mpconfigboard.h | 2 ++
 ports/samd/boards/MINISAM_M4/mpconfigboard.h          | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/ports/samd/boards/ADAFRUIT_TRINKET_M0/mpconfigboard.h b/ports/samd/boards/ADAFRUIT_TRINKET_M0/mpconfigboard.h
index d3a6ba2d8687e..5732a20e3adc4 100644
--- a/ports/samd/boards/ADAFRUIT_TRINKET_M0/mpconfigboard.h
+++ b/ports/samd/boards/ADAFRUIT_TRINKET_M0/mpconfigboard.h
@@ -1,2 +1,4 @@
 #define MICROPY_HW_BOARD_NAME "Trinket M0"
 #define MICROPY_HW_MCU_NAME   "SAMD21E18A"
+
+#define MICROPY_HW_DFLL_USB_SYNC    (1)
diff --git a/ports/samd/boards/MINISAM_M4/mpconfigboard.h b/ports/samd/boards/MINISAM_M4/mpconfigboard.h
index 2dc403bad60fe..87acf301e36b5 100644
--- a/ports/samd/boards/MINISAM_M4/mpconfigboard.h
+++ b/ports/samd/boards/MINISAM_M4/mpconfigboard.h
@@ -1,4 +1,6 @@
 #define MICROPY_HW_BOARD_NAME "Mini SAM M4"
 #define MICROPY_HW_MCU_NAME   "SAMD51G19A"
 
+#define MICROPY_HW_DFLL_USB_SYNC    (1)
+
 #define MICROPY_HW_QSPIFLASH   GD25Q16C

From e8e9a39a6df11dbac0c2ffa1d863e6763e818165 Mon Sep 17 00:00:00 2001
From: robert-hh 
Date: Tue, 19 Mar 2024 17:16:41 +0100
Subject: [PATCH 306/408] samd/mcu: Update clock config after changes to USB.

For all MCUs: run the test for USB clock recovery mode fallback after USB
has been started.

For samd21: change DFLL48 config from the open loop mode variant to sync
with the XOSC32KULP.  Matches better the 48MHz value.

Signed-off-by: robert-hh 
---
 ports/samd/clock_config.h            |  2 +-
 ports/samd/main.c                    |  2 +
 ports/samd/mcu/samd21/clock_config.c | 74 +++++++++++++++++++---------
 ports/samd/mcu/samd51/clock_config.c |  6 +--
 ports/samd/samd_soc.c                |  1 -
 5 files changed, 56 insertions(+), 29 deletions(-)

diff --git a/ports/samd/clock_config.h b/ports/samd/clock_config.h
index 35b7e532814b4..b045299396b1f 100644
--- a/ports/samd/clock_config.h
+++ b/ports/samd/clock_config.h
@@ -30,5 +30,5 @@ void init_clocks(uint32_t cpu_freq);
 void set_cpu_freq(uint32_t cpu_freq);
 uint32_t get_cpu_freq(void);
 uint32_t get_peripheral_freq(void);
-void check_usb_recovery_mode(void);
+void check_usb_clock_recovery_mode(void);
 void enable_sercom_clock(int id);
diff --git a/ports/samd/main.c b/ports/samd/main.c
index 9f213f27d41cf..2bbaf63e6e4c5 100644
--- a/ports/samd/main.c
+++ b/ports/samd/main.c
@@ -34,6 +34,7 @@
 #include "shared/runtime/pyexec.h"
 #include "shared/runtime/softtimer.h"
 #include "shared/tinyusb/mp_usbd.h"
+#include "clock_config.h"
 
 extern uint8_t _sstack, _estack, _sheap, _eheap;
 extern void adc_deinit_all(void);
@@ -59,6 +60,7 @@ void samd_main(void) {
         int ret = pyexec_file_if_exists("boot.py");
 
         mp_usbd_init();
+        check_usb_clock_recovery_mode();
 
         if (ret & PYEXEC_FORCED_EXIT) {
             goto soft_reset_exit;
diff --git a/ports/samd/mcu/samd21/clock_config.c b/ports/samd/mcu/samd21/clock_config.c
index d84ee526767c9..033d0f7c1b1eb 100644
--- a/ports/samd/mcu/samd21/clock_config.c
+++ b/ports/samd/mcu/samd21/clock_config.c
@@ -111,8 +111,29 @@ void set_cpu_freq(uint32_t cpu_freq_arg) {
     SysTick_Config(cpu_freq / 1000);
 }
 
-void check_usb_recovery_mode(void) {
-    #if !MICROPY_HW_XOSC32K
+static void sync_dfll48_with_xosc32kulp(void) {
+    SYSCTRL->DFLLCTRL.reg = SYSCTRL_DFLLCTRL_ENABLE;
+    while (!SYSCTRL->PCLKSR.bit.DFLLRDY) {
+    }
+    // Connect GCLK4 to the DFLL input.
+    GCLK->CLKCTRL.reg = GCLK_CLKCTRL_GEN_GCLK4 | GCLK_CLKCTRL_ID_DFLL48 | GCLK_CLKCTRL_CLKEN;
+    while (GCLK->STATUS.bit.SYNCBUSY) {
+    }
+    // Set the multiplication values. The offset of 16384 to the freq is for rounding.
+    SYSCTRL->DFLLMUL.reg = SYSCTRL_DFLLMUL_MUL((CPU_FREQ + 16384) / 32768) |
+        SYSCTRL_DFLLMUL_FSTEP(1) | SYSCTRL_DFLLMUL_CSTEP(1);
+    while (SYSCTRL->PCLKSR.bit.DFLLRDY == 0) {
+    }
+    // Start the DFLL and wait for the PLL lock. We just wait for the fine lock, since
+    // coarse adjusting is bypassed.
+    SYSCTRL->DFLLCTRL.reg |= SYSCTRL_DFLLCTRL_MODE | SYSCTRL_DFLLCTRL_WAITLOCK | SYSCTRL_DFLLCTRL_STABLE |
+        SYSCTRL_DFLLCTRL_BPLCKC | SYSCTRL_DFLLCTRL_ENABLE;
+    while (!SYSCTRL->PCLKSR.bit.DFLLLCKF) {
+    }
+}
+
+void check_usb_clock_recovery_mode(void) {
+    #if MICROPY_HW_DFLL_USB_SYNC
     // Check USB status for up to 1 second. If not connected,
     // switch DFLL48M back to open loop
     for (int i = 0; i < 100; i++) {
@@ -121,10 +142,9 @@ void check_usb_recovery_mode(void) {
         }
         mp_hal_delay_ms(10);
     }
-    // Set/keep the open loop mode of the device.
-    SYSCTRL->DFLLVAL.reg = dfll48m_calibration;
-    SYSCTRL->DFLLCTRL.reg = SYSCTRL_DFLLCTRL_CCDIS | SYSCTRL_DFLLCTRL_ENABLE;
-    #endif // MICROPY_HW_XOSC32K
+    // No USB sync. Use XOSC32KULP as clock reference for DFLL48M
+    sync_dfll48_with_xosc32kulp();
+    #endif
 }
 
 // Purpose of the #defines for the clock configuration.
@@ -178,12 +198,12 @@ void init_clocks(uint32_t cpu_freq) {
     // GCLK1: 32kHz, source: XOSC32K or OSCULP32K, usage: FDPLL96M reference
     // GCLK2: 1-48MHz, source: DFLL48M, usage: Peripherals
     // GCLK3: 2Mhz,  source: DFLL48M, usage: us-counter (TC4/TC5)
-    // GCLK4: 32kHz, source: XOSC32K, if crystal present, usage: DFLL48M reference
+    // GCLK4: 32kHz, source: XOSC32K or OSCULP32K, usage: DFLL48M reference
     // GCLK5: 48MHz, source: DFLL48M, usage: USB
     // GCLK8: 1kHz,  source: XOSC32K or OSCULP32K, usage: WDT and RTC
     // DFLL48M: Reference sources:
-    //          - in closed loop mode: either XOSC32K or OSCULP32K or USB clock
-    //            from GCLK4.
+    //          - in closed loop mode: either XOSC32K or OSCULP32K from GCLK4
+    //            or USB clock.
     //          - in open loop mode: None
     // FDPLL96M: Reference source GCLK1
     //           Used for the CPU clock for freq >= 48Mhz
@@ -256,6 +276,17 @@ void init_clocks(uint32_t cpu_freq) {
 
     #else // MICROPY_HW_XOSC32K
 
+    // Connect the GCLK1 to the XOSC32KULP
+    GCLK->GENDIV.reg = GCLK_GENDIV_ID(1) | GCLK_GENDIV_DIV(1);
+    GCLK->GENCTRL.reg = GCLK_GENCTRL_GENEN | GCLK_GENCTRL_SRC_OSCULP32K | GCLK_GENCTRL_ID(1);
+    while (GCLK->STATUS.bit.SYNCBUSY) {
+    }
+    // Connect the GCLK4 to the XOSC32KULP
+    GCLK->GENDIV.reg = GCLK_GENDIV_ID(4) | GCLK_GENDIV_DIV(1);
+    GCLK->GENCTRL.reg = GCLK_GENCTRL_GENEN | GCLK_GENCTRL_SRC_OSCULP32K | GCLK_GENCTRL_ID(4);
+    while (GCLK->STATUS.bit.SYNCBUSY) {
+    }
+
     // Enable DFLL48M
     SYSCTRL->DFLLCTRL.reg = SYSCTRL_DFLLCTRL_ENABLE;
     while (!SYSCTRL->PCLKSR.bit.DFLLRDY) {
@@ -263,35 +294,30 @@ void init_clocks(uint32_t cpu_freq) {
 
     uint32_t coarse = (*((uint32_t *)FUSES_DFLL48M_COARSE_CAL_ADDR) & FUSES_DFLL48M_COARSE_CAL_Msk)
         >> FUSES_DFLL48M_COARSE_CAL_Pos;
+    uint32_t fine = (*((uint32_t *)FUSES_DFLL48M_FINE_CAL_ADDR) & FUSES_DFLL48M_FINE_CAL_Msk)
+        >> FUSES_DFLL48M_COARSE_CAL_Pos;
     if (coarse == 0x3f) {
         coarse = 0x1f;
     }
-    SYSCTRL->DFLLVAL.reg = SYSCTRL_DFLLVAL_COARSE(coarse) | SYSCTRL_DFLLVAL_FINE(511);
+    SYSCTRL->DFLLVAL.reg = SYSCTRL_DFLLVAL_COARSE(coarse) | SYSCTRL_DFLLVAL_FINE(fine);
+    dfll48m_calibration = SYSCTRL_DFLLVAL_COARSE(coarse) | SYSCTRL_DFLLVAL_FINE(fine);
 
     #if MICROPY_HW_DFLL_USB_SYNC
-    // Configure the DFLL48M for USB clock recovery.
-    // Will have to switch back if no USB
-    SYSCTRL->DFLLSYNC.bit.READREQ = 1;
-    dfll48m_calibration = SYSCTRL->DFLLVAL.reg;
     // Set the Multiplication factor.
     SYSCTRL->DFLLMUL.reg = SYSCTRL_DFLLMUL_CSTEP(1) | SYSCTRL_DFLLMUL_FSTEP(1)
         | SYSCTRL_DFLLMUL_MUL(48000);
     // Set the mode to closed loop USB Recovery mode
     SYSCTRL->DFLLCTRL.reg = SYSCTRL_DFLLCTRL_USBCRM | SYSCTRL_DFLLCTRL_CCDIS
         | SYSCTRL_DFLLCTRL_MODE | SYSCTRL_DFLLCTRL_ENABLE;
-    #else
-    // Set/keep the open loop mode of the device.
-    SYSCTRL->DFLLCTRL.reg = SYSCTRL_DFLLCTRL_CCDIS | SYSCTRL_DFLLCTRL_ENABLE;
-    #endif
-
     while (!SYSCTRL->PCLKSR.bit.DFLLRDY) {
     }
 
-    // Connect the GCLK1 to the XOSC32KULP
-    GCLK->GENDIV.reg = GCLK_GENDIV_ID(1) | GCLK_GENDIV_DIV(1);
-    GCLK->GENCTRL.reg = GCLK_GENCTRL_GENEN | GCLK_GENCTRL_SRC_OSCULP32K | GCLK_GENCTRL_ID(1);
-    while (GCLK->STATUS.bit.SYNCBUSY) {
-    }
+    #else  // MICROPY_HW_DFLL_USB_SYNC
+
+    sync_dfll48_with_xosc32kulp();
+
+    #endif  // MICROPY_HW_DFLL_USB_SYNC
+
     // Set GCLK8 to 1 kHz.
     GCLK->GENDIV.reg = GCLK_GENDIV_ID(8) | GCLK_GENDIV_DIV(32);
     GCLK->GENCTRL.reg = GCLK_GENCTRL_GENEN | GCLK_GENCTRL_SRC_OSCULP32K | GCLK_GENCTRL_ID(8);
diff --git a/ports/samd/mcu/samd51/clock_config.c b/ports/samd/mcu/samd51/clock_config.c
index b30cc46f24596..77b6e4c632cd8 100644
--- a/ports/samd/mcu/samd51/clock_config.c
+++ b/ports/samd/mcu/samd51/clock_config.c
@@ -115,8 +115,8 @@ void set_cpu_freq(uint32_t cpu_freq_arg) {
     SysTick_Config(cpu_freq / 1000);
 }
 
-void check_usb_recovery_mode(void) {
-    #if !MICROPY_HW_XOSC32K
+void check_usb_clock_recovery_mode(void) {
+    #if MICROPY_HW_DFLL_USB_SYNC
     // Check USB status for up to 1 second. If not connected,
     // switch DFLL48M back to open loop
     for (int i = 0; i < 100; i++) {
@@ -144,7 +144,7 @@ void check_usb_recovery_mode(void) {
     OSCCTRL->DFLLCTRLB.reg = 0;
     while (OSCCTRL->DFLLSYNC.bit.DFLLCTRLB == 1) {
     }
-    #endif // MICROPY_HW_XOSC32K
+    #endif
 }
 
 // Purpose of the #defines for the clock configuration.
diff --git a/ports/samd/samd_soc.c b/ports/samd/samd_soc.c
index 5e6c5c4fc2407..1c8d49d1573db 100644
--- a/ports/samd/samd_soc.c
+++ b/ports/samd/samd_soc.c
@@ -116,7 +116,6 @@ void samd_init(void) {
     init_clocks(get_cpu_freq());
     init_us_counter();
     usb_init();
-    check_usb_recovery_mode();
     #if defined(MCU_SAMD51)
     mp_hal_ticks_cpu_enable();
     #endif

From 3980b361730a4d3313f6456fca1697db96b73870 Mon Sep 17 00:00:00 2001
From: robert-hh 
Date: Wed, 20 Mar 2024 20:23:49 +0100
Subject: [PATCH 307/408] samd/samd_spiflash: Allow configuring the flash SPI
 baudrate.

Using a define for MICROPY_HW_SPIFLASH_BAUDRATE in mpconfigboard.h.  If not
defined the default is 24MHz.

Signed-off-by: robert-hh 
---
 ports/samd/samd_spiflash.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/ports/samd/samd_spiflash.c b/ports/samd/samd_spiflash.c
index 1313a6fd9d0d0..cd4f10640dbf1 100644
--- a/ports/samd/samd_spiflash.c
+++ b/ports/samd/samd_spiflash.c
@@ -49,6 +49,9 @@ const uint8_t _COMMANDS_32BIT[] = {0x13, 0x12, 0x21};  // READ, PROGRAM_PAGE, ER
 #define COMMAND_READ_SFDP (0x5A)
 #define PAGE_SIZE (256)
 #define SECTOR_SIZE (4096)
+#ifndef MICROPY_HW_SPIFLASH_BAUDRATE
+#define MICROPY_HW_SPIFLASH_BAUDRATE (24000000)
+#endif
 
 typedef struct _spiflash_obj_t {
     mp_obj_base_t base;
@@ -136,7 +139,7 @@ static mp_obj_t spiflash_make_new(const mp_obj_type_t *type, size_t n_args, size
 
     mp_obj_t spi_args[] = {
         MP_OBJ_NEW_SMALL_INT(MICROPY_HW_SPIFLASH_ID),
-        MP_OBJ_NEW_SMALL_INT(24000000),  // baudrate
+        MP_OBJ_NEW_SMALL_INT(MICROPY_HW_SPIFLASH_BAUDRATE),
         MP_OBJ_NEW_QSTR(MP_QSTR_mosi), MP_OBJ_NEW_QSTR(MP_QSTR_FLASH_MOSI),
         MP_OBJ_NEW_QSTR(MP_QSTR_miso), MP_OBJ_NEW_QSTR(MP_QSTR_FLASH_MISO),
         MP_OBJ_NEW_QSTR(MP_QSTR_sck), MP_OBJ_NEW_QSTR(MP_QSTR_FLASH_SCK),

From d9b9e88899df86fec5679138f5f60ed62df0975f Mon Sep 17 00:00:00 2001
From: robert-hh 
Date: Wed, 27 Mar 2024 10:53:29 +0100
Subject: [PATCH 308/408] samd/samd_qspiflash: Avoid reading status byte 2 when
 not available.

Change provided by @ironss-iotec.

Tested with Adafruit, SEEED and MiniFig boards for non-interference.

Fixes issue #14190.

Signed-off-by: robert-hh 
---
 ports/samd/samd_qspiflash.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/ports/samd/samd_qspiflash.c b/ports/samd/samd_qspiflash.c
index 60aa434dcfdaa..d027a0495f3c0 100644
--- a/ports/samd/samd_qspiflash.c
+++ b/ports/samd/samd_qspiflash.c
@@ -337,9 +337,13 @@ static mp_obj_t samd_qspiflash_make_new(const mp_obj_type_t *type, size_t n_args
     // The write in progress bit should be low.
     while (read_status() & 0x01) {
     }
-    // The suspended write/erase bit should be low.
-    while (read_status2() & 0x80) {
+
+    if (!flash_device->single_status_byte) {
+        // The suspended write/erase bit should be low.
+        while (read_status2() & 0x80) {
+        }
     }
+
     run_command(QSPI_CMD_ENABLE_RESET);
     run_command(QSPI_CMD_RESET);
     // Wait 30us for the reset

From 4662a71f44bd8a0f8ff96d12e43f69be3bff8488 Mon Sep 17 00:00:00 2001
From: robert-hh 
Date: Wed, 27 Mar 2024 11:11:57 +0100
Subject: [PATCH 309/408] drivers/memory: Add IS25LPWP064D chip to list of
 external flash devices.

Confirguration provided by by @ironss-iotec.

Signed-off-by: robert-hh 
---
 drivers/memory/external_flash_device.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/drivers/memory/external_flash_device.h b/drivers/memory/external_flash_device.h
index 03798446036aa..b5cf4a8877ff5 100644
--- a/drivers/memory/external_flash_device.h
+++ b/drivers/memory/external_flash_device.h
@@ -442,6 +442,23 @@ typedef struct {
         .single_status_byte = false, \
 }
 
+// Settings for the ISSI devices
+#define IS25LPWP064D { \
+        .total_size = (1 << 23), /* 8 MiB */ \
+        .start_up_time_us = 5000, \
+        .manufacturer_id = 0x9D, \
+        .memory_type = 0x60, \
+        .capacity = 0x17, \
+        .max_clock_speed_mhz = 80, \
+        .quad_enable_bit_mask = 0x40, \
+        .has_sector_protection = false, \
+        .supports_fast_read = true, \
+        .supports_qspi = true, \
+        .supports_qspi_writes = true, \
+        .write_status_register_split = false, \
+        .single_status_byte = true, \
+}
+
 // Settings for a GENERIC device with the most common setting
 #define GENERIC { \
         .total_size = (1 << 21), /* 2 MiB */ \

From d2276f0d41c2fa66a224725fdb2411846c91cf1a Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Mon, 25 Mar 2024 13:10:12 +1100
Subject: [PATCH 310/408] py/dynruntime: Add
 mp_binary_get_size/get_val_array/set_val_array.

These are needed to read/write array.array objects, which is useful in
native code to provide fast extensions that work with big arrays of data.

Signed-off-by: Damien George 
---
 py/dynruntime.h | 5 +++++
 py/nativeglue.c | 4 ++++
 py/nativeglue.h | 5 +++++
 tools/mpy_ld.py | 3 ++-
 4 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/py/dynruntime.h b/py/dynruntime.h
index 7765fca40d598..d07b1dce2c4e5 100644
--- a/py/dynruntime.h
+++ b/py/dynruntime.h
@@ -29,6 +29,7 @@
 // This header file contains definitions to dynamically implement the static
 // MicroPython runtime API defined in py/obj.h and py/runtime.h.
 
+#include "py/binary.h"
 #include "py/nativeglue.h"
 #include "py/objfun.h"
 #include "py/objstr.h"
@@ -184,6 +185,10 @@ static inline void *mp_obj_malloc_helper_dyn(size_t num_bytes, const mp_obj_type
 /******************************************************************************/
 // General runtime functions
 
+#define mp_binary_get_size(struct_type, val_type, palign) (mp_fun_table.binary_get_size((struct_type), (val_type), (palign)))
+#define mp_binary_get_val_array(typecode, p, index) (mp_fun_table.binary_get_val_array((typecode), (p), (index)))
+#define mp_binary_set_val_array(typecode, p, index, val_in) (mp_fun_table.binary_set_val_array((typecode), (p), (index), (val_in)))
+
 #define mp_load_name(qst)                 (mp_fun_table.load_name((qst)))
 #define mp_load_global(qst)               (mp_fun_table.load_global((qst)))
 #define mp_load_attr(base, attr)          (mp_fun_table.load_attr((base), (attr)))
diff --git a/py/nativeglue.c b/py/nativeglue.c
index 4cd090c0a2a78..ba3d93f760707 100644
--- a/py/nativeglue.c
+++ b/py/nativeglue.c
@@ -29,6 +29,7 @@
 #include 
 #include 
 
+#include "py/binary.h"
 #include "py/runtime.h"
 #include "py/smallint.h"
 #include "py/nativeglue.h"
@@ -330,6 +331,9 @@ const mp_fun_table_t mp_fun_table = {
     mp_obj_get_float_to_d,
     mp_get_buffer,
     mp_get_stream_raise,
+    mp_binary_get_size,
+    mp_binary_get_val_array,
+    mp_binary_set_val_array,
     &mp_plat_print,
     &mp_type_type,
     &mp_type_str,
diff --git a/py/nativeglue.h b/py/nativeglue.h
index 113f5fde6528f..1fa85933452cb 100644
--- a/py/nativeglue.h
+++ b/py/nativeglue.h
@@ -156,7 +156,12 @@ typedef struct _mp_fun_table_t {
     double (*obj_get_float_to_d)(mp_obj_t o);
     bool (*get_buffer)(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
     const mp_stream_p_t *(*get_stream_raise)(mp_obj_t self_in, int flags);
+    size_t (*binary_get_size)(char struct_type, char val_type, size_t *palign);
+    mp_obj_t (*binary_get_val_array)(char typecode, void *p, size_t index);
+    void (*binary_set_val_array)(char typecode, void *p, size_t index, mp_obj_t val_in);
     const mp_print_t *plat_print;
+    // The following entries start at index 70 and are referenced by tools-mpy_ld.py,
+    // see constant MP_FUN_TABLE_MP_TYPE_TYPE_OFFSET.
     const mp_obj_type_t *type_type;
     const mp_obj_type_t *type_str;
     const mp_obj_type_t *type_list;
diff --git a/tools/mpy_ld.py b/tools/mpy_ld.py
index d7d0b945c5db1..b768b109a8425 100755
--- a/tools/mpy_ld.py
+++ b/tools/mpy_ld.py
@@ -52,6 +52,7 @@
 MP_SCOPE_FLAG_VIPERRODATA = 0x20
 MP_SCOPE_FLAG_VIPERBSS = 0x40
 MP_SMALL_INT_BITS = 31
+MP_FUN_TABLE_MP_TYPE_TYPE_OFFSET = 70
 
 # ELF constants
 R_386_32 = 1
@@ -754,7 +755,7 @@ def link_objects(env, native_qstr_vals_len):
     # Resolve unknown symbols
     mp_fun_table_sec = Section(".external.mp_fun_table", b"", 0)
     fun_table = {
-        key: 67 + idx
+        key: MP_FUN_TABLE_MP_TYPE_TYPE_OFFSET + idx
         for idx, key in enumerate(
             [
                 "mp_type_type",

From 8b0efde927afb8409314ddf16f16a78b44b93d7a Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Mon, 25 Mar 2024 13:12:08 +1100
Subject: [PATCH 311/408] examples/natmod/framebuf: Enable FrameBuffer.poly
 method.

Signed-off-by: Damien George 
---
 examples/natmod/framebuf/framebuf.c | 10 ++++++----
 extmod/modframebuf.c                |  7 +++----
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/examples/natmod/framebuf/framebuf.c b/examples/natmod/framebuf/framebuf.c
index e8f99b3b20cdd..1ba702e33d907 100644
--- a/examples/natmod/framebuf/framebuf.c
+++ b/examples/natmod/framebuf/framebuf.c
@@ -1,3 +1,4 @@
+#define MICROPY_PY_ARRAY (1)
 #define MICROPY_PY_FRAMEBUF (1)
 
 #include "py/dynruntime.h"
@@ -12,7 +13,7 @@ mp_obj_full_type_t mp_type_framebuf;
 
 #include "extmod/modframebuf.c"
 
-mp_map_elem_t framebuf_locals_dict_table[11];
+mp_map_elem_t framebuf_locals_dict_table[12];
 static MP_DEFINE_CONST_DICT(framebuf_locals_dict, framebuf_locals_dict_table);
 
 mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) {
@@ -30,9 +31,10 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *a
     framebuf_locals_dict_table[5] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_rect), MP_OBJ_FROM_PTR(&framebuf_rect_obj) };
     framebuf_locals_dict_table[6] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_line), MP_OBJ_FROM_PTR(&framebuf_line_obj) };
     framebuf_locals_dict_table[7] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_ellipse), MP_OBJ_FROM_PTR(&framebuf_ellipse_obj) };
-    framebuf_locals_dict_table[8] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_blit), MP_OBJ_FROM_PTR(&framebuf_blit_obj) };
-    framebuf_locals_dict_table[9] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_scroll), MP_OBJ_FROM_PTR(&framebuf_scroll_obj) };
-    framebuf_locals_dict_table[10] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_text), MP_OBJ_FROM_PTR(&framebuf_text_obj) };
+    framebuf_locals_dict_table[8] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_poly), MP_OBJ_FROM_PTR(&framebuf_poly_obj) };
+    framebuf_locals_dict_table[9] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_blit), MP_OBJ_FROM_PTR(&framebuf_blit_obj) };
+    framebuf_locals_dict_table[10] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_scroll), MP_OBJ_FROM_PTR(&framebuf_scroll_obj) };
+    framebuf_locals_dict_table[11] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_text), MP_OBJ_FROM_PTR(&framebuf_text_obj) };
     MP_OBJ_TYPE_SET_SLOT(&mp_type_framebuf, locals_dict, (void*)&framebuf_locals_dict, 2);
 
     mp_store_global(MP_QSTR_FrameBuffer, MP_OBJ_FROM_PTR(&mp_type_framebuf));
diff --git a/extmod/modframebuf.c b/extmod/modframebuf.c
index 693e837f786a0..f3ce5b5ef0ec6 100644
--- a/extmod/modframebuf.c
+++ b/extmod/modframebuf.c
@@ -577,9 +577,7 @@ static mp_obj_t framebuf_ellipse(size_t n_args, const mp_obj_t *args_in) {
 }
 static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_ellipse_obj, 6, 8, framebuf_ellipse);
 
-#if MICROPY_PY_ARRAY && !MICROPY_ENABLE_DYNRUNTIME
-// TODO: poly needs mp_binary_get_size & mp_binary_get_val_array which aren't
-// available in dynruntime.h yet.
+#if MICROPY_PY_ARRAY
 
 static mp_int_t poly_int(mp_buffer_info_t *bufinfo, size_t index) {
     return mp_obj_get_int(mp_binary_get_val_array(bufinfo->typecode, bufinfo->buf, index));
@@ -696,7 +694,8 @@ static mp_obj_t framebuf_poly(size_t n_args, const mp_obj_t *args_in) {
     return mp_const_none;
 }
 static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_poly_obj, 5, 6, framebuf_poly);
-#endif // MICROPY_PY_ARRAY && !MICROPY_ENABLE_DYNRUNTIME
+
+#endif // MICROPY_PY_ARRAY
 
 static mp_obj_t framebuf_blit(size_t n_args, const mp_obj_t *args_in) {
     mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args_in[0]);

From bdbc869f9ea200c0d28b2bc7bfb60acd9d884e1b Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Mon, 25 Mar 2024 12:25:01 +1100
Subject: [PATCH 312/408] py/persistentcode: Bump .mpy sub-version to 6.3.

This is required because the .mpy native ABI was changed by the
introduction of `mp_proto_fun_t`, see commits:
- 416465d81e911b088836f4e7c37fac2bc0f67917
- 5e3006f1172d0eabbbefeb3268dfb942ec7cf9cd
- e2ff00e81113d7a3f32f860652017644b5d68bf1

And three `mp_binary` functions were added to `mp_fun_table` in
commit d2276f0d41c2fa66a224725fdb2411846c91cf1a.

Signed-off-by: Damien George 
---
 py/persistentcode.h                       | 2 +-
 tests/micropython/import_mpy_native_gc.py | 4 ++--
 tools/mpy-tool.py                         | 2 +-
 tools/mpy_ld.py                           | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/py/persistentcode.h b/py/persistentcode.h
index 45a268d63fb91..d2b310f241f8d 100644
--- a/py/persistentcode.h
+++ b/py/persistentcode.h
@@ -35,7 +35,7 @@
 // set) must also match MPY_SUB_VERSION. This allows 3 additional updates to
 // the native ABI per bytecode revision.
 #define MPY_VERSION 6
-#define MPY_SUB_VERSION 2
+#define MPY_SUB_VERSION 3
 
 // Macros to encode/decode sub-version to/from the feature byte. This replaces
 // the bits previously used to encode the flags (map caching and unicode)
diff --git a/tests/micropython/import_mpy_native_gc.py b/tests/micropython/import_mpy_native_gc.py
index 6b8d7ddd632e2..7f4b2aefd59f4 100644
--- a/tests/micropython/import_mpy_native_gc.py
+++ b/tests/micropython/import_mpy_native_gc.py
@@ -52,9 +52,9 @@ def open(self, path, mode):
 # cat features0.mpy | python -c 'import sys; print(sys.stdin.buffer.read())'
 features0_file_contents = {
     # -march=x64
-    0x806: b'M\x06\x0a\x1f\x02\x004build/features0.native.mpy\x00\x12factorial\x00\x8a\x02\xe9/\x00\x00\x00SH\x8b\x1d\x83\x00\x00\x00\xbe\x02\x00\x00\x00\xffS\x18\xbf\x01\x00\x00\x00H\x85\xc0u\x0cH\x8bC \xbe\x02\x00\x00\x00[\xff\xe0H\x0f\xaf\xf8H\xff\xc8\xeb\xe6ATUSH\x8b\x1dQ\x00\x00\x00H\x8bG\x08L\x8bc(H\x8bx\x08A\xff\xd4H\x8d5+\x00\x00\x00H\x89\xc5H\x8b\x059\x00\x00\x00\x0f\xb7x\x02\xffShH\x89\xefA\xff\xd4H\x8b\x03[]A\\\xc3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x11$\r&\xa3 \x01"\xff',
+    0x806: b'M\x06\x0b\x1f\x02\x004build/features0.native.mpy\x00\x12factorial\x00\x8a\x02\xe9/\x00\x00\x00SH\x8b\x1d\x83\x00\x00\x00\xbe\x02\x00\x00\x00\xffS\x18\xbf\x01\x00\x00\x00H\x85\xc0u\x0cH\x8bC \xbe\x02\x00\x00\x00[\xff\xe0H\x0f\xaf\xf8H\xff\xc8\xeb\xe6ATUSH\x8b\x1dQ\x00\x00\x00H\x8bG\x08L\x8bc(H\x8bx\x08A\xff\xd4H\x8d5+\x00\x00\x00H\x89\xc5H\x8b\x059\x00\x00\x00\x0f\xb7x\x02\xffShH\x89\xefA\xff\xd4H\x8b\x03[]A\\\xc3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x11$\r&\xa9 \x01"\xff',
     # -march=armv6m
-    0x1006: b"M\x06\x12\x1f\x02\x004build/features0.native.mpy\x00\x12factorial\x00\x88\x02\x18\xe0\x00\x00\x10\xb5\tK\tJ{D\x9cX\x02!\xe3h\x98G\x03\x00\x01 \x00+\x02\xd0XC\x01;\xfa\xe7\x02!#i\x98G\x10\xbd\xc0Fj\x00\x00\x00\x00\x00\x00\x00\xf8\xb5\nN\nK~D\xf4XChgiXh\xb8G\x05\x00\x07K\x08I\xf3XyDX\x88ck\x98G(\x00\xb8G h\xf8\xbd\xc0F:\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x1e\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x11<\r>\xa38\x01:\xff",
+    0x1006: b"M\x06\x13\x1f\x02\x004build/features0.native.mpy\x00\x12factorial\x00\x88\x02\x18\xe0\x00\x00\x10\xb5\tK\tJ{D\x9cX\x02!\xe3h\x98G\x03\x00\x01 \x00+\x02\xd0XC\x01;\xfa\xe7\x02!#i\x98G\x10\xbd\xc0Fj\x00\x00\x00\x00\x00\x00\x00\xf8\xb5\nN\nK~D\xf4XChgiXh\xb8G\x05\x00\x07K\x08I\xf3XyDX\x88ck\x98G(\x00\xb8G h\xf8\xbd\xc0F:\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x1e\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x11<\r>\xa98\x01:\xff",
 }
 
 # Populate armv7m-derived archs based on armv6m.
diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py
index 06ccd6a1da8f3..86c4ba7579358 100755
--- a/tools/mpy-tool.py
+++ b/tools/mpy-tool.py
@@ -88,7 +88,7 @@ def __str__(self):
 
 class Config:
     MPY_VERSION = 6
-    MPY_SUB_VERSION = 2
+    MPY_SUB_VERSION = 3
     MICROPY_LONGINT_IMPL_NONE = 0
     MICROPY_LONGINT_IMPL_LONGLONG = 1
     MICROPY_LONGINT_IMPL_MPZ = 2
diff --git a/tools/mpy_ld.py b/tools/mpy_ld.py
index b768b109a8425..2e3da53eb57e0 100755
--- a/tools/mpy_ld.py
+++ b/tools/mpy_ld.py
@@ -36,7 +36,7 @@
 
 # MicroPython constants
 MPY_VERSION = 6
-MPY_SUB_VERSION = 2
+MPY_SUB_VERSION = 3
 MP_CODE_BYTECODE = 2
 MP_CODE_NATIVE_VIPER = 4
 MP_NATIVE_ARCH_X86 = 1

From 628a37e6cf157bab048f8d43b0e68f65a1e917f4 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Mon, 25 Mar 2024 13:18:38 +1100
Subject: [PATCH 313/408] docs/reference/mpyfiles: Document change in .mpy
 sub-version.

Signed-off-by: Damien George 
---
 docs/reference/mpyfiles.rst | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/docs/reference/mpyfiles.rst b/docs/reference/mpyfiles.rst
index 02bac3d411e02..8e8284928dacb 100644
--- a/docs/reference/mpyfiles.rst
+++ b/docs/reference/mpyfiles.rst
@@ -86,7 +86,8 @@ and .mpy version.
 =================== ============
 MicroPython release .mpy version
 =================== ============
-v1.22.0 and up      6.2
+v1.23.0 and up      6.3
+v1.22.x             6.2
 v1.20 - v1.21.0     6.1
 v1.19.x             6
 v1.12 - v1.18       5
@@ -102,6 +103,7 @@ MicroPython repository at which the .mpy version was changed.
 =================== ========================================
 .mpy version change Git commit
 =================== ========================================
+6.2 to 6.3          bdbc869f9ea200c0d28b2bc7bfb60acd9d884e1b
 6.1 to 6.2          6967ff3c581a66f73e9f3d78975f47528db39980
 6 to 6.1            d94141e1473aebae0d3c63aeaa8397651ad6fa01
 5 to 6              f2040bfc7ee033e48acef9f289790f3b4e6b74e5

From c3e37d1fac380721b20f968bd33cb6633a53d126 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Thu, 28 Mar 2024 17:28:06 +1100
Subject: [PATCH 314/408] extmod/modtls_axtls: Add verify_mode and CERT_NONE
 constant.

Supporting `verify_mode` and `CERT_NONE` is required for the new `ssl.py`
code, as well as `requests` to work.

Signed-off-by: Damien George 
---
 extmod/modtls_axtls.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/extmod/modtls_axtls.c b/extmod/modtls_axtls.c
index 08a355cddb605..0e49fde2d84c5 100644
--- a/extmod/modtls_axtls.c
+++ b/extmod/modtls_axtls.c
@@ -39,6 +39,8 @@
 #define PROTOCOL_TLS_CLIENT (0)
 #define PROTOCOL_TLS_SERVER (1)
 
+#define CERT_NONE (0)
+
 // This corresponds to an SSLContext object.
 typedef struct _mp_obj_ssl_context_t {
     mp_obj_base_t base;
@@ -155,6 +157,25 @@ static mp_obj_t ssl_context_make_new(const mp_obj_type_t *type_in, size_t n_args
     return MP_OBJ_FROM_PTR(self);
 }
 
+static void ssl_context_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
+    if (dest[0] == MP_OBJ_NULL) {
+        // Load attribute.
+        if (attr == MP_QSTR_verify_mode) {
+            // CERT_NONE is the only supported verify_mode value.
+            dest[0] = MP_OBJ_NEW_SMALL_INT(CERT_NONE);
+        } else {
+            // Continue lookup in locals_dict.
+            dest[1] = MP_OBJ_SENTINEL;
+        }
+    } else if (dest[1] != MP_OBJ_NULL) {
+        // Store attribute.
+        if (attr == MP_QSTR_verify_mode) {
+            // CERT_NONE is the only supported verify_mode value, so no need to store anything.
+            dest[0] = MP_OBJ_NULL;
+        }
+    }
+}
+
 static void ssl_context_load_key(mp_obj_ssl_context_t *self, mp_obj_t key_obj, mp_obj_t cert_obj) {
     self->key = key_obj;
     self->cert = cert_obj;
@@ -199,6 +220,7 @@ static MP_DEFINE_CONST_OBJ_TYPE(
     MP_QSTR_SSLContext,
     MP_TYPE_FLAG_NONE,
     make_new, ssl_context_make_new,
+    attr, ssl_context_attr,
     locals_dict, &ssl_context_locals_dict
     );
 
@@ -429,6 +451,7 @@ static const mp_rom_map_elem_t mp_module_tls_globals_table[] = {
     // Constants.
     { MP_ROM_QSTR(MP_QSTR_PROTOCOL_TLS_CLIENT), MP_ROM_INT(PROTOCOL_TLS_CLIENT) },
     { MP_ROM_QSTR(MP_QSTR_PROTOCOL_TLS_SERVER), MP_ROM_INT(PROTOCOL_TLS_SERVER) },
+    { MP_ROM_QSTR(MP_QSTR_CERT_NONE), MP_ROM_INT(CERT_NONE) },
 };
 static MP_DEFINE_CONST_DICT(mp_module_tls_globals, mp_module_tls_globals_table);
 

From 20a86eff5382d874f8f95a8009f76155c43a6aa9 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Thu, 28 Mar 2024 17:59:56 +1100
Subject: [PATCH 315/408] tests/net_inet: Add simpler tls sites test, and skip
 existing on axtls.

Ports that use axtls cannot run the `test_tls_sites.py` test because the
sites it connects to use advanced ciphers.  So skip this test on such
ports, and add a new, simpler test that doesn't require certificate
verification and works with axtls.

Signed-off-by: Damien George 
---
 tests/net_inet/test_tls_sites.py        |  7 ++++
 tests/net_inet/test_tls_sites_simple.py | 43 +++++++++++++++++++++++++
 2 files changed, 50 insertions(+)
 create mode 100644 tests/net_inet/test_tls_sites_simple.py

diff --git a/tests/net_inet/test_tls_sites.py b/tests/net_inet/test_tls_sites.py
index d60f4872b6c52..3637194ad7998 100644
--- a/tests/net_inet/test_tls_sites.py
+++ b/tests/net_inet/test_tls_sites.py
@@ -1,8 +1,15 @@
+# Test making HTTPS requests to sites that may require advanced ciphers.
+
 import sys
 import select
 import socket
 import ssl
 
+# Don't run if ssl doesn't support required certificates (eg axtls).
+if not hasattr(ssl, "CERT_REQUIRED"):
+    print("SKIP")
+    raise SystemExit
+
 
 def test_one(site, opts):
     ai = socket.getaddrinfo(site, 443, socket.AF_INET)
diff --git a/tests/net_inet/test_tls_sites_simple.py b/tests/net_inet/test_tls_sites_simple.py
new file mode 100644
index 0000000000000..9dece9d99c792
--- /dev/null
+++ b/tests/net_inet/test_tls_sites_simple.py
@@ -0,0 +1,43 @@
+# Test making HTTPS requests to sites that allow simple ciphers.
+
+import sys
+import socket
+import ssl
+
+SITES = (
+    ("micropython.org", "/ks/test.html"),
+    ("pypi.org", "/"),
+)
+
+
+def test_one(site, path):
+    ai = socket.getaddrinfo(site, 443, socket.AF_INET)
+    addr = ai[0][-1]
+
+    # Create SSLContext.
+    ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
+    if sys.implementation.name != "micropython":
+        # CPython compatibility: disable check_hostname
+        ssl_context.check_hostname = False
+    ssl_context.verify_mode = ssl.CERT_NONE
+
+    s = socket.socket(socket.AF_INET)
+    s.connect(addr)
+    s = ssl_context.wrap_socket(s)
+
+    s.write(b"GET %s HTTP/1.0\r\nHost: %s\r\n\r\n" % (bytes(path, "ascii"), bytes(site, "ascii")))
+    resp = s.read(4096)
+    s.close()
+
+    if resp.startswith(b"HTTP/1."):
+        print(site, "ok")
+    else:
+        print(site, "response doesn't start with HTTP/1.")
+
+
+def main():
+    for site, path in SITES:
+        test_one(site, path)
+
+
+main()

From b82945035954e7f28c64f1f962e17b280cdf7ea5 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Fri, 29 Mar 2024 17:48:06 +1100
Subject: [PATCH 316/408] samd/mcu: Guard static function with appropriate #if.

Signed-off-by: Damien George 
---
 ports/samd/mcu/samd21/clock_config.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ports/samd/mcu/samd21/clock_config.c b/ports/samd/mcu/samd21/clock_config.c
index 033d0f7c1b1eb..5ce127ec83ace 100644
--- a/ports/samd/mcu/samd21/clock_config.c
+++ b/ports/samd/mcu/samd21/clock_config.c
@@ -111,6 +111,7 @@ void set_cpu_freq(uint32_t cpu_freq_arg) {
     SysTick_Config(cpu_freq / 1000);
 }
 
+#if !MICROPY_HW_XOSC32K || MICROPY_HW_DFLL_USB_SYNC
 static void sync_dfll48_with_xosc32kulp(void) {
     SYSCTRL->DFLLCTRL.reg = SYSCTRL_DFLLCTRL_ENABLE;
     while (!SYSCTRL->PCLKSR.bit.DFLLRDY) {
@@ -131,6 +132,7 @@ static void sync_dfll48_with_xosc32kulp(void) {
     while (!SYSCTRL->PCLKSR.bit.DFLLLCKF) {
     }
 }
+#endif
 
 void check_usb_clock_recovery_mode(void) {
     #if MICROPY_HW_DFLL_USB_SYNC

From aa0f3ebe93b7e621a1852da21744d7763db27611 Mon Sep 17 00:00:00 2001
From: iabdalkader 
Date: Thu, 21 Mar 2024 12:02:24 +0100
Subject: [PATCH 317/408] extmod/modopenamp: Set a default log handler for
 ports.

Use the existing metal log handling mechanism instead of overriding the
metal_log, which causes build issues when logging is enabled.

Signed-off-by: iabdalkader 
---
 extmod/libmetal/metal/config.h |  7 -------
 extmod/modopenamp.c            | 18 +++++++++++++++++-
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/extmod/libmetal/metal/config.h b/extmod/libmetal/metal/config.h
index 459a2f4ca424d..e553f107837b0 100644
--- a/extmod/libmetal/metal/config.h
+++ b/extmod/libmetal/metal/config.h
@@ -57,13 +57,6 @@
 #define METAL_MAX_DEVICE_REGIONS 1
 #endif
 
-// generic/log.h
-#if METAL_LOG_HANDLER_ENABLE
-#include "py/mphal.h"
-#undef metal_log
-#define metal_log(level, ...) mp_printf(&mp_plat_print, __VA_ARGS__)
-#endif
-
 static inline void *__metal_allocate_memory(unsigned int size) {
     return m_tracked_calloc(1, size);
 }
diff --git a/extmod/modopenamp.c b/extmod/modopenamp.c
index eb19c4b737ac1..1392f5427e5f5 100644
--- a/extmod/modopenamp.c
+++ b/extmod/modopenamp.c
@@ -28,9 +28,11 @@
 
 #if MICROPY_PY_OPENAMP
 
+#include 
 #include "py/obj.h"
 #include "py/nlr.h"
 #include "py/runtime.h"
+#include "py/mpprint.h"
 
 #include "metal/sys.h"
 #include "metal/alloc.h"
@@ -315,6 +317,13 @@ static mp_obj_t openamp_new_service_callback(mp_obj_t ns_callback) {
 }
 static MP_DEFINE_CONST_FUN_OBJ_1(openamp_new_service_callback_obj, openamp_new_service_callback);
 
+void openamp_metal_log_handler(enum metal_log_level level, const char *fmt, ...) {
+    va_list args;
+    va_start(args, fmt);
+    mp_vprintf(&mp_plat_print, fmt, args);
+    va_end(args);
+}
+
 void openamp_init(void) {
     if (MP_STATE_PORT(virtio_device) != NULL) {
         // Already initialized.
@@ -322,7 +331,14 @@ void openamp_init(void) {
     }
 
     struct metal_device *device;
-    struct metal_init_params metal_params = METAL_INIT_DEFAULTS;
+    struct metal_init_params metal_params = { 0 };
+
+    #if METAL_LOG_HANDLER_ENABLE
+    // If logging is enabled, set the default log level and handler before
+    // calling metal_init, to allow ports to override them in metal_sys_init.
+    metal_params.log_level = METAL_LOG_DEBUG;
+    metal_params.log_handler = openamp_metal_log_handler;
+    #endif
 
     // Initialize libmetal.
     metal_init(&metal_params);

From 8936d3af468d922d284ebe8dbf831f5a25d84882 Mon Sep 17 00:00:00 2001
From: iabdalkader 
Date: Thu, 28 Mar 2024 08:22:55 +0100
Subject: [PATCH 318/408] extmod/modopenamp: Use metal logging functions
 exclusively.

Signed-off-by: iabdalkader 
---
 extmod/modopenamp.c                  |  8 +++-----
 extmod/modopenamp_remoteproc.c       |  2 --
 extmod/modopenamp_remoteproc_store.c | 12 +++++-------
 3 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/extmod/modopenamp.c b/extmod/modopenamp.c
index 1392f5427e5f5..7a19e55a660d9 100644
--- a/extmod/modopenamp.c
+++ b/extmod/modopenamp.c
@@ -77,8 +77,6 @@ static const char openamp_trace_buf[128];
 
 #endif // MICROPY_PY_OPENAMP_RSC_TABLE_ENABLE
 
-#define debug_printf(...)       // mp_printf(&mp_plat_print, __VA_ARGS__)
-
 #if MICROPY_PY_OPENAMP_REMOTEPROC
 extern mp_obj_type_t openamp_remoteproc_type;
 #endif
@@ -138,7 +136,7 @@ typedef struct _endpoint_obj_t {
 static const mp_obj_type_t endpoint_type;
 
 static int endpoint_recv_callback(struct rpmsg_endpoint *ept, void *data, size_t len, uint32_t src, void *priv) {
-    debug_printf("endpoint_recv_callback() message received src: %lu msg len: %d\n", src, len);
+    metal_log(METAL_LOG_DEBUG, "endpoint_recv_callback() message received src: %lu msg len: %d\n", src, len);
     endpoint_obj_t *self = metal_container_of(ept, endpoint_obj_t, ep);
     if (self->callback != mp_const_none) {
         mp_call_function_2(self->callback, mp_obj_new_int(src), mp_obj_new_bytearray_by_ref(len, data));
@@ -176,7 +174,7 @@ static mp_obj_t endpoint_send(uint n_args, const mp_obj_t *pos_args, mp_map_t *k
 
     mp_buffer_info_t rbuf;
     mp_get_buffer_raise(pos_args[1], &rbuf, MP_BUFFER_READ);
-    debug_printf("endpoint_send() msg len: %d\n", rbuf.len);
+    metal_log(METAL_LOG_DEBUG, "endpoint_send() msg len: %d\n", rbuf.len);
 
     int bytes = 0;
     mp_int_t timeout = args[ARG_timeout].u_int;
@@ -260,7 +258,7 @@ void openamp_remoteproc_notified(mp_sched_node_t *node) {
 }
 
 static void openamp_ns_callback(struct rpmsg_device *rdev, const char *name, uint32_t dest) {
-    debug_printf("rpmsg_new_service_callback() new service request name: %s dest %lu\n", name, dest);
+    metal_log(METAL_LOG_DEBUG, "rpmsg_new_service_callback() new service request name: %s dest %lu\n", name, dest);
     // The remote processor advertises its presence to the host by sending
     // the Name Service (NS) announcement containing the name of the channel.
     virtio_dev_obj_t *virtio_device = metal_container_of(rdev, virtio_dev_obj_t, rvdev);
diff --git a/extmod/modopenamp_remoteproc.c b/extmod/modopenamp_remoteproc.c
index 6f43c71546bf2..20e4a47c18718 100644
--- a/extmod/modopenamp_remoteproc.c
+++ b/extmod/modopenamp_remoteproc.c
@@ -46,8 +46,6 @@
 #include "modopenamp.h"
 #include "modopenamp_remoteproc.h"
 
-#define DEBUG_printf(...)   // mp_printf(&mp_plat_print, __VA_ARGS__)
-
 #if !MICROPY_PY_OPENAMP
 #error "MICROPY_PY_OPENAMP_REMOTEPROC requires MICROPY_PY_OPENAMP"
 #endif
diff --git a/extmod/modopenamp_remoteproc_store.c b/extmod/modopenamp_remoteproc_store.c
index 857c133469d6e..262e6f2ec79b1 100644
--- a/extmod/modopenamp_remoteproc_store.c
+++ b/extmod/modopenamp_remoteproc_store.c
@@ -47,8 +47,6 @@
 
 #if MICROPY_PY_OPENAMP_REMOTEPROC_STORE_ENABLE
 
-#define DEBUG_printf(...)   // mp_printf(&mp_plat_print, __VA_ARGS__)
-
 // Note the initial file buffer size needs to be at least 512 to read
 // enough of the elf headers on the first call to store_open(), and on
 // subsequent calls to store functions, it gets reallocated if needed.
@@ -70,7 +68,7 @@ void *mp_openamp_remoteproc_store_alloc(void) {
 }
 
 static int openamp_remoteproc_store_open(void *store, const char *path, const void **image_data) {
-    DEBUG_printf("store_open(): %s\n", path);
+    metal_log(METAL_LOG_DEBUG, "store_open(): %s\n", path);
     mp_obj_t args[2] = {
         mp_obj_new_str(path, strlen(path)),
         MP_OBJ_NEW_QSTR(MP_QSTR_rb),
@@ -89,7 +87,7 @@ static int openamp_remoteproc_store_open(void *store, const char *path, const vo
 }
 
 static void openamp_remoteproc_store_close(void *store) {
-    DEBUG_printf("store_close()\n");
+    metal_log(METAL_LOG_DEBUG, "store_close()\n");
     openamp_remoteproc_filestore_t *fstore = store;
     mp_stream_close(fstore->file);
     metal_free_memory(fstore->buf);
@@ -113,17 +111,17 @@ static int openamp_remoteproc_store_load(void *store, size_t offset, size_t size
             // Note tracked allocs don't support realloc.
             fstore->len = size;
             fstore->buf = metal_allocate_memory(size);
-            DEBUG_printf("store_load() realloc to %lu\n", fstore->len);
+            metal_log(METAL_LOG_DEBUG, "store_load() realloc to %lu\n", fstore->len);
         }
         *data = fstore->buf;
-        DEBUG_printf("store_load(): pa 0x%lx offset %u size %u \n", (uint32_t)pa, offset, size);
+        metal_log(METAL_LOG_DEBUG, "store_load(): pa 0x%lx offset %u size %u \n", (uint32_t)pa, offset, size);
     } else {
         void *va = metal_io_phys_to_virt(io, pa);
         if (va == NULL) {
             return -EINVAL;
         }
         *data = va;
-        DEBUG_printf("store_load(): pa 0x%lx va 0x%p offset %u size %u \n", (uint32_t)pa, va, offset, size);
+        metal_log(METAL_LOG_DEBUG, "store_load(): pa 0x%lx va 0x%p offset %u size %u \n", (uint32_t)pa, va, offset, size);
     }
 
     mp_uint_t bytes = mp_stream_read_exactly(fstore->file, (void *)*data, size, &error);

From 23d7a915c1a2a5a9114640feba836ce57529a2e1 Mon Sep 17 00:00:00 2001
From: iabdalkader 
Date: Sun, 24 Mar 2024 16:10:41 +0100
Subject: [PATCH 319/408] stm32/mpremoteprocport: Use metal logging functions.

Signed-off-by: iabdalkader 
---
 ports/stm32/mpremoteprocport.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/ports/stm32/mpremoteprocport.c b/ports/stm32/mpremoteprocport.c
index 56dff43da4e73..11369e7aa00f5 100644
--- a/ports/stm32/mpremoteprocport.c
+++ b/ports/stm32/mpremoteprocport.c
@@ -40,11 +40,9 @@
 #include "metal/utilities.h"
 #include "extmod/modopenamp_remoteproc.h"
 
-#define DEBUG_printf(...)   // mp_printf(&mp_plat_print, __VA_ARGS__)
-
 struct remoteproc *mp_openamp_remoteproc_init(struct remoteproc *rproc,
     const struct remoteproc_ops *ops, void *arg) {
-    DEBUG_printf("rproc_init()\n");
+    metal_log(METAL_LOG_DEBUG, "rproc_init()\n");
 
     rproc->ops = ops;
     rproc->state = RPROC_OFFLINE;
@@ -56,7 +54,7 @@ struct remoteproc *mp_openamp_remoteproc_init(struct remoteproc *rproc,
 void *mp_openamp_remoteproc_mmap(struct remoteproc *rproc, metal_phys_addr_t *pa,
     metal_phys_addr_t *da, size_t size, unsigned int attribute,
     struct metal_io_region **io) {
-    DEBUG_printf("rproc_mmap(): pa 0x%p da 0x%p io 0x%p size %u\n", *pa, *da, *io, size);
+    metal_log(METAL_LOG_DEBUG, "rproc_mmap(): pa 0x%p da 0x%p io 0x%p size %u\n", *pa, *da, *io, size);
 
     struct remoteproc_mem *mem;
     metal_phys_addr_t lpa = *pa;
@@ -100,11 +98,11 @@ void *mp_openamp_remoteproc_mmap(struct remoteproc *rproc, metal_phys_addr_t *pa
 }
 
 int mp_openamp_remoteproc_start(struct remoteproc *rproc) {
-    DEBUG_printf("rproc_start()\n");
+    metal_log(METAL_LOG_DEBUG, "rproc_start()\n");
     if ((RCC->GCR & RCC_GCR_BOOT_C2) || (FLASH->OPTSR_CUR & FLASH_OPTSR_BCM4)) {
         // The CM4 core has already been started manually, or auto-boot is enabled
         // via the option bytes, in either case the core can't be restarted.
-        DEBUG_printf("rproc_start(): CM4 core is already booted.\n");
+        metal_log(METAL_LOG_DEBUG, "rproc_start(): CM4 core is already booted.\n");
         return -1;
     }
 
@@ -122,7 +120,7 @@ int mp_openamp_remoteproc_start(struct remoteproc *rproc) {
 }
 
 int mp_openamp_remoteproc_stop(struct remoteproc *rproc) {
-    DEBUG_printf("rproc_stop()\n");
+    metal_log(METAL_LOG_DEBUG, "rproc_stop()\n");
     if (rproc->state == RPROC_RUNNING) {
         // There's no straightforward way to reset or shut down
         // the remote processor, so a full system reset is needed.
@@ -132,18 +130,18 @@ int mp_openamp_remoteproc_stop(struct remoteproc *rproc) {
 }
 
 int mp_openamp_remoteproc_config(struct remoteproc *rproc, void *data) {
-    DEBUG_printf("rproc_config()\n");
+    metal_log(METAL_LOG_DEBUG, "rproc_config()\n");
     (void)rproc;
     return 0;
 }
 
 void mp_openamp_remoteproc_remove(struct remoteproc *rproc) {
-    DEBUG_printf("rproc_remove()\n");
+    metal_log(METAL_LOG_DEBUG, "rproc_remove()\n");
     (void)rproc;
 }
 
 int mp_openamp_remoteproc_shutdown(struct remoteproc *rproc) {
-    DEBUG_printf("rproc_shutdown()\n");
+    metal_log(METAL_LOG_DEBUG, "rproc_shutdown()\n");
     if (rproc->state == RPROC_RUNNING) {
         // There's no straightforward way to reset or shut down
         // the remote processor, so a full system reset is needed.

From 87d821ab495cc409d2da91f261474b8b72f2c483 Mon Sep 17 00:00:00 2001
From: iabdalkader 
Date: Sat, 23 Mar 2024 16:11:15 +0100
Subject: [PATCH 320/408] mimxrt: Add support for OpenAMP.

Signed-off-by: iabdalkader 
---
 ports/mimxrt/Makefile                         |  14 +-
 .../boards/MIMXRT1170_EVK/mpconfigboard.mk    |   2 +
 ports/mimxrt/boards/MIMXRT1176.ld             |   4 +
 ports/mimxrt/mpmetalport.c                    | 111 ++++++++++++
 ports/mimxrt/mpmetalport.h                    |  73 ++++++++
 ports/mimxrt/mpremoteprocport.c               | 161 ++++++++++++++++++
 6 files changed, 364 insertions(+), 1 deletion(-)
 create mode 100644 ports/mimxrt/mpmetalport.c
 create mode 100644 ports/mimxrt/mpmetalport.h
 create mode 100644 ports/mimxrt/mpremoteprocport.c

diff --git a/ports/mimxrt/Makefile b/ports/mimxrt/Makefile
index dd1f5aa7c6ca5..96abb11bff433 100644
--- a/ports/mimxrt/Makefile
+++ b/ports/mimxrt/Makefile
@@ -172,7 +172,8 @@ SRC_HAL_IMX_C += \
 	$(MCU_DIR)/drivers/fsl_common_arm.c \
 	$(MCU_DIR)/drivers/fsl_anatop_ai.c \
 	$(MCU_DIR)/drivers/fsl_caam.c \
-	$(MCU_DIR)/drivers/fsl_lpadc.c
+	$(MCU_DIR)/drivers/fsl_lpadc.c \
+	$(MCU_DIR)/drivers/fsl_mu.c
 else
 SRC_HAL_IMX_C += \
 	$(MCU_DIR)/drivers/fsl_adc.c \
@@ -267,6 +268,17 @@ ifeq ($(MICROPY_BLUETOOTH_NIMBLE),1)
 SRC_C += mpnimbleport.c
 endif
 
+# Add mimxrt-specific implementation of libmetal (and optionally OpenAMP's rproc).
+# Note: libmetal code is generated via a pre-processor so ensure that runs first.
+ifeq ($(MICROPY_PY_OPENAMP),1)
+SRC_C += mpmetalport.c
+$(BUILD)/mpmetalport.o: $(BUILD)/openamp/metal/config.h
+ifeq ($(MICROPY_PY_OPENAMP_REMOTEPROC),1)
+SRC_C += mpremoteprocport.c
+$(BUILD)/mpremoteprocport.o: $(BUILD)/openamp/metal/config.h
+endif
+endif
+
 # Math library source files
 ifeq ($(MICROPY_FLOAT_IMPL),double)
     LIBM_SRC_C += $(SRC_LIB_LIBM_DBL_C)
diff --git a/ports/mimxrt/boards/MIMXRT1170_EVK/mpconfigboard.mk b/ports/mimxrt/boards/MIMXRT1170_EVK/mpconfigboard.mk
index 1488730f7c7cf..6e5ee56aa1081 100644
--- a/ports/mimxrt/boards/MIMXRT1170_EVK/mpconfigboard.mk
+++ b/ports/mimxrt/boards/MIMXRT1170_EVK/mpconfigboard.mk
@@ -13,6 +13,8 @@ MICROPY_HW_SDRAM_SIZE  = 0x4000000  # 64MB
 MICROPY_PY_LWIP = 1
 MICROPY_PY_SSL = 1
 MICROPY_SSL_MBEDTLS = 1
+MICROPY_PY_OPENAMP = 1
+MICROPY_PY_OPENAMP_REMOTEPROC = 1
 
 FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py
 
diff --git a/ports/mimxrt/boards/MIMXRT1176.ld b/ports/mimxrt/boards/MIMXRT1176.ld
index d66c86a046024..4d114ef96fa4a 100644
--- a/ports/mimxrt/boards/MIMXRT1176.ld
+++ b/ports/mimxrt/boards/MIMXRT1176.ld
@@ -57,3 +57,7 @@ _gc_heap_end = ORIGIN(m_sdram) + LENGTH(m_sdram);
 _gc_heap_start = ORIGIN(m_ocrm);
 _gc_heap_end = ORIGIN(m_ocrm) + LENGTH(m_ocrm);
 #endif
+
+/* CM4 DTCM */
+_openamp_shm_region_start = 0x20220000;
+_openamp_shm_region_end  = 0x20230000;
diff --git a/ports/mimxrt/mpmetalport.c b/ports/mimxrt/mpmetalport.c
new file mode 100644
index 0000000000000..ca0c30fb2a56a
--- /dev/null
+++ b/ports/mimxrt/mpmetalport.c
@@ -0,0 +1,111 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2024 Arduino SA
+ *
+ * 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.
+ *
+ * libmetal mimxrt port.
+ */
+
+#include "py/mperrno.h"
+#include "py/mphal.h"
+
+#include "fsl_common.h"
+#include "fsl_mu.h"
+#include CPU_HEADER_H
+
+#include "metal/sys.h"
+#include "metal/utilities.h"
+#include "metal/device.h"
+
+struct metal_state _metal;
+static mp_sched_node_t rproc_notify_node;
+
+#define IRQ_PRI_MU  NVIC_EncodePriority(NVIC_PRIORITYGROUP_4, 10, 0)
+
+int metal_sys_init(const struct metal_init_params *params) {
+    metal_unused(params);
+
+    // Init MU.
+    MU_Init(MUA);
+
+    // Configure and enable MU IRQs.
+    MU_ClearStatusFlags(MUA, kMU_GenInt0Flag);
+    NVIC_SetPriority(MUA_IRQn, IRQ_PRI_MU);
+    NVIC_EnableIRQ(MUA_IRQn);
+    MU_EnableInterrupts(MUA, kMU_GenInt0InterruptEnable);
+
+    #ifndef VIRTIO_USE_DCACHE
+    // If cache management is not enabled, configure the MPU to disable caching
+    // for the entire shared memory region.
+    ARM_MPU_Disable();
+    MPU->RBAR = ARM_MPU_RBAR(10, METAL_MPU_REGION_BASE);
+    // Normal type, not shareable, non-cacheable
+    MPU->RASR = ARM_MPU_RASR(0, ARM_MPU_AP_FULL, 1, 0, 0, 0, 0, METAL_MPU_REGION_SIZE);
+    ARM_MPU_Enable(MPU_CTRL_PRIVDEFENA_Msk | MPU_CTRL_HFNMIENA_Msk);
+    #endif
+
+    metal_bus_register(&metal_generic_bus);
+    return 0;
+}
+
+void metal_sys_finish(void) {
+    NVIC_DisableIRQ(MUA_IRQn);
+    metal_bus_unregister(&metal_generic_bus);
+}
+
+unsigned int sys_irq_save_disable(void) {
+    return disable_irq();
+}
+
+void sys_irq_restore_enable(unsigned int state) {
+    enable_irq(state);
+}
+
+void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
+    size_t size, unsigned int flags) {
+    metal_unused(pa);
+    metal_unused(size);
+    metal_unused(flags);
+    return va;
+}
+
+void metal_machine_cache_flush(void *addr, unsigned int len) {
+    SCB_CleanDCache_by_Addr(addr, len);
+}
+
+void metal_machine_cache_invalidate(void *addr, unsigned int len) {
+    SCB_InvalidateDCache_by_Addr(addr, len);
+}
+
+int metal_rproc_notify(void *priv, uint32_t id) {
+    MU_TriggerInterrupts(MUA, kMU_GenInt0InterruptTrigger);
+    return 0;
+}
+
+void MUA_IRQHandler(void) {
+    if (MU_GetStatusFlags(MUA) & kMU_GenInt0Flag) {
+        MU_ClearStatusFlags(MUA, kMU_GenInt0Flag);
+        mp_sched_schedule_node(&rproc_notify_node, openamp_remoteproc_notified);
+    }
+    __DSB();
+}
diff --git a/ports/mimxrt/mpmetalport.h b/ports/mimxrt/mpmetalport.h
new file mode 100644
index 0000000000000..994d57cc39fb4
--- /dev/null
+++ b/ports/mimxrt/mpmetalport.h
@@ -0,0 +1,73 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2024 Arduino SA
+ *
+ * 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.
+ *
+ * libmetal mimxrt port.
+ */
+#ifndef MICROPY_INCLUDED_MIMXRT_MPMETALPORT_H
+#define MICROPY_INCLUDED_MIMXRT_MPMETALPORT_H
+
+#include 
+#include "py/mphal.h"
+#include "py/runtime.h"
+
+#define METAL_HAVE_STDATOMIC_H      0
+#define METAL_HAVE_FUTEX_H          0
+
+#define METAL_MAX_DEVICE_REGIONS    2
+
+// Set to 1 to enable the default log handler.
+#define METAL_LOG_HANDLER_ENABLE    0
+
+#define metal_cpu_yield()
+
+// Shared memory config
+#define METAL_SHM_NAME              "OPENAMP_SHM"
+// Note 1K must be reserved at the start of the openamp
+// shared memory region, for the shared resource table.
+#define METAL_RSC_ADDR              ((void *)_openamp_shm_region_start)
+#define METAL_RSC_SIZE              (1024)
+
+#define METAL_SHM_ADDR              ((metal_phys_addr_t)(_openamp_shm_region_start + METAL_RSC_SIZE))
+#define METAL_SHM_SIZE              ((size_t)(_openamp_shm_region_end - _openamp_shm_region_start - METAL_RSC_SIZE))
+
+#define METAL_MPU_REGION_BASE       ((uint32_t)_openamp_shm_region_start)
+#define METAL_MPU_REGION_SIZE       (ARM_MPU_REGION_SIZE_64KB)
+
+extern const char _openamp_shm_region_start[];
+extern const char _openamp_shm_region_end[];
+
+int metal_rproc_notify(void *priv, uint32_t id);
+extern void openamp_remoteproc_notified(mp_sched_node_t *node);
+
+static inline int __metal_sleep_usec(unsigned int usec) {
+    mp_hal_delay_us(usec);
+    return 0;
+}
+
+static inline void metal_generic_default_poll(void) {
+    MICROPY_EVENT_POLL_HOOK
+}
+
+#endif // MICROPY_INCLUDED_MIMXRT_METAL_PORT_H
diff --git a/ports/mimxrt/mpremoteprocport.c b/ports/mimxrt/mpremoteprocport.c
new file mode 100644
index 0000000000000..1e2cefc7ea69a
--- /dev/null
+++ b/ports/mimxrt/mpremoteprocport.c
@@ -0,0 +1,161 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2024 Arduino SA
+ *
+ * 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.
+ *
+ * modremoteproc mimxrt port.
+ */
+
+#include "py/obj.h"
+#include "py/runtime.h"
+
+#include "fsl_common.h"
+#include "fsl_mu.h"
+
+#include "metal/alloc.h"
+#include "metal/errno.h"
+#include "metal/io.h"
+#include "metal/sys.h"
+#include "metal/device.h"
+#include "metal/utilities.h"
+#include "extmod/modopenamp_remoteproc.h"
+
+struct remoteproc *mp_openamp_remoteproc_init(struct remoteproc *rproc,
+    const struct remoteproc_ops *ops, void *arg) {
+    metal_log(METAL_LOG_DEBUG, "rproc_init()\n");
+
+    rproc->ops = ops;
+    rproc->state = RPROC_OFFLINE;
+    // Allocate the image store and save it in private data.
+    rproc->priv = mp_openamp_remoteproc_store_alloc();
+    return rproc;
+}
+
+void *mp_openamp_remoteproc_mmap(struct remoteproc *rproc, metal_phys_addr_t *pa,
+    metal_phys_addr_t *da, size_t size, unsigned int attribute,
+    struct metal_io_region **io) {
+    metal_log(METAL_LOG_DEBUG, "rproc_mmap(): pa 0x%p da 0x%p io 0x%p size %u\n", *pa, *da, *io, size);
+
+    struct remoteproc_mem *mem;
+    metal_phys_addr_t lpa = *pa;
+    metal_phys_addr_t lda = *da;
+
+    if (lda == METAL_BAD_PHYS) {
+        return NULL;
+    }
+
+    if (lpa == METAL_BAD_PHYS) {
+        lpa = lda;
+    }
+
+    if (lpa >= 0x1FFE0000 && lpa < 0x1FFFFFFF) {
+        // Map CM4 ITCM to CM7 address space.
+        lpa = 0x20200000 | (((uint32_t)lpa) & 0x1FFFF);
+        metal_log(METAL_LOG_DEBUG, "rproc_mmap(): remap 0x%p -> 0x%p\n", lda, lpa);
+    } else if (lpa >= 0x20000000 && lpa < 0x20020000) {
+        // Map CM4 DTCM to CM7 address space.
+        lpa = 0x20220000 | (((uint32_t)lpa) & 0x1FFFF);
+        metal_log(METAL_LOG_DEBUG, "rproc_mmap(): remap 0x%p -> 0x%p\n", lda, lpa);
+    }
+
+    mem = metal_allocate_memory(sizeof(*mem));
+    if (!mem) {
+        return NULL;
+    }
+
+    *io = metal_allocate_memory(sizeof(struct metal_io_region));
+    if (!*io) {
+        metal_free_memory(mem);
+        return NULL;
+    }
+
+    remoteproc_init_mem(mem, NULL, lpa, lda, size, *io);
+
+    metal_io_init(*io, (void *)lpa, &mem->pa, size,
+        sizeof(metal_phys_addr_t) << 3, attribute, NULL);
+
+    remoteproc_add_mem(rproc, mem);
+    *pa = lpa;
+    *da = lda;
+    return metal_io_phys_to_virt(*io, mem->pa);
+}
+
+int mp_openamp_remoteproc_start(struct remoteproc *rproc) {
+    metal_log(METAL_LOG_DEBUG, "rproc_start()\n");
+    if (SRC->SCR & SRC_SCR_BT_RELEASE_M4_MASK) {
+        // The CM4 core is already running.
+        metal_log(METAL_LOG_DEBUG, "rproc_start(): CM4 core is already booted.\n");
+        return -1;
+    }
+
+    // Flush M7 cache.
+    struct metal_list *node;
+    metal_list_for_each(&rproc->mems, node) {
+        struct remoteproc_mem *mem;
+        mem = metal_container_of(node, struct remoteproc_mem, node);
+        metal_log(METAL_LOG_DEBUG, "rproc_start() clean: pa 0x%p size %u\n", (uint32_t *)mem->pa, mem->size);
+        SCB_CleanDCache_by_Addr((uint32_t *)mem->pa, mem->size);
+    }
+
+    unsigned long offset = 0;
+    struct metal_io_region *io = remoteproc_get_io_with_da(rproc, rproc->bootaddr, &offset);
+    if (!io) {
+        return -1;
+    }
+
+    IOMUXC_LPSR_GPR->GPR0 = IOMUXC_LPSR_GPR_GPR0_CM4_INIT_VTOR_LOW(((uint32_t)io->virt) >> 3);
+    (void)IOMUXC_LPSR_GPR->GPR0;
+    IOMUXC_LPSR_GPR->GPR1 = IOMUXC_LPSR_GPR_GPR1_CM4_INIT_VTOR_HIGH(((uint32_t)io->virt) >> 16);
+    (void)IOMUXC_LPSR_GPR->GPR1;
+
+    SRC->CTRL_M4CORE = SRC_CTRL_M4CORE_SW_RESET_MASK;
+    SRC->SCR |= SRC_SCR_BT_RELEASE_M4_MASK;
+    return 0;
+}
+
+int mp_openamp_remoteproc_stop(struct remoteproc *rproc) {
+    metal_log(METAL_LOG_DEBUG, "rproc_stop()\n");
+    if (rproc->state == RPROC_RUNNING) {
+        NVIC_SystemReset();
+    }
+    return 0;
+}
+
+int mp_openamp_remoteproc_config(struct remoteproc *rproc, void *data) {
+    metal_log(METAL_LOG_DEBUG, "rproc_config()\n");
+    (void)rproc;
+    return 0;
+}
+
+void mp_openamp_remoteproc_remove(struct remoteproc *rproc) {
+    metal_log(METAL_LOG_DEBUG, "rproc_remove()\n");
+    (void)rproc;
+}
+
+int mp_openamp_remoteproc_shutdown(struct remoteproc *rproc) {
+    metal_log(METAL_LOG_DEBUG, "rproc_shutdown()\n");
+    if (rproc->state == RPROC_RUNNING) {
+        NVIC_SystemReset();
+    }
+    return 0;
+}

From 3997532186016c14753098294e4f3fcfad77ac2f Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Fri, 29 Mar 2024 23:07:32 +1100
Subject: [PATCH 321/408] webassembly/proxy_c: Ensure return value of async fun
 is passed to JS.

Signed-off-by: Damien George 
---
 ports/webassembly/proxy_c.c                   |  9 +++--
 tests/ports/webassembly/await_js_async_py.mjs | 35 +++++++++++++++++++
 .../webassembly/await_js_async_py.mjs.exp     | 12 +++++++
 3 files changed, 53 insertions(+), 3 deletions(-)
 create mode 100644 tests/ports/webassembly/await_js_async_py.mjs
 create mode 100644 tests/ports/webassembly/await_js_async_py.mjs.exp

diff --git a/ports/webassembly/proxy_c.c b/ports/webassembly/proxy_c.c
index 1e4573ce0ba55..8d137f6271297 100644
--- a/ports/webassembly/proxy_c.c
+++ b/ports/webassembly/proxy_c.c
@@ -289,10 +289,11 @@ void proxy_c_to_js_get_dict(uint32_t c_ref, uint32_t *out) {
 
 static const mp_obj_fun_builtin_var_t resume_obj;
 
-EM_JS(void, js_then_resolve, (uint32_t * resolve, uint32_t * reject), {
+EM_JS(void, js_then_resolve, (uint32_t * ret_value, uint32_t * resolve, uint32_t * reject), {
+    const ret_value_js = proxy_convert_mp_to_js_obj_jsside(ret_value);
     const resolve_js = proxy_convert_mp_to_js_obj_jsside(resolve);
     const reject_js = proxy_convert_mp_to_js_obj_jsside(reject);
-    resolve_js(null);
+    resolve_js(ret_value_js);
 });
 
 EM_JS(void, js_then_reject, (uint32_t * resolve, uint32_t * reject), {
@@ -321,7 +322,9 @@ static mp_obj_t proxy_resume_execute(mp_obj_t self_in, mp_obj_t value, mp_obj_t
     proxy_convert_mp_to_js_obj_cside(reject, out_reject);
 
     if (ret_kind == MP_VM_RETURN_NORMAL) {
-        js_then_resolve(out_resolve, out_reject);
+        uint32_t out_ret_value[PVN];
+        proxy_convert_mp_to_js_obj_cside(ret_value, out_ret_value);
+        js_then_resolve(out_ret_value, out_resolve, out_reject);
         return mp_const_none;
     } else if (ret_kind == MP_VM_RETURN_YIELD) {
         // ret_value should be a JS thenable
diff --git a/tests/ports/webassembly/await_js_async_py.mjs b/tests/ports/webassembly/await_js_async_py.mjs
new file mode 100644
index 0000000000000..953a7b783d5dc
--- /dev/null
+++ b/tests/ports/webassembly/await_js_async_py.mjs
@@ -0,0 +1,35 @@
+// Test JavaScript await'ing on Python async functions.
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+globalThis.asyncTimeout = (ms) =>
+    new Promise((resolve) => setTimeout(resolve, ms));
+
+mp.runPython(`
+import js
+
+def f0():
+    print("f0 run")
+    return 1
+
+async def f1():
+    print("f1 run")
+    return 2
+
+async def f2():
+    print("f2 start")
+    await js.asyncTimeout(0)
+    print("f2 end")
+    return 3
+
+async def f3():
+    print("f3 start")
+    ret = await f2()
+    print("f3 end")
+    return ret + 1
+`);
+
+console.log("f0 return:", await mp.globals.get("f0")());
+console.log("f1 return:", await mp.globals.get("f1")());
+console.log("f2 return:", await mp.globals.get("f2")());
+console.log("f3 return:", await mp.globals.get("f3")());
diff --git a/tests/ports/webassembly/await_js_async_py.mjs.exp b/tests/ports/webassembly/await_js_async_py.mjs.exp
new file mode 100644
index 0000000000000..ab8cbabebb31f
--- /dev/null
+++ b/tests/ports/webassembly/await_js_async_py.mjs.exp
@@ -0,0 +1,12 @@
+f0 run
+f0 return: 1
+f1 run
+f1 return: 2
+f2 start
+f2 end
+f2 return: 3
+f3 start
+f2 start
+f2 end
+f3 end
+f3 return: 4

From 7c62fbe3f227eb87c21295efddbb7dcf101a4bab Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Fri, 29 Mar 2024 23:07:39 +1100
Subject: [PATCH 322/408] webassembly/proxy_js: Promote Python thenable to a
 Promise.

Signed-off-by: Damien George 
---
 ports/webassembly/proxy_js.js                 | 17 +++++++++-
 .../ports/webassembly/fun_py_callback_js.mjs  | 31 +++++++++++++++++++
 .../webassembly/fun_py_callback_js.mjs.exp    |  8 +++++
 3 files changed, 55 insertions(+), 1 deletion(-)
 create mode 100644 tests/ports/webassembly/fun_py_callback_js.mjs
 create mode 100644 tests/ports/webassembly/fun_py_callback_js.mjs.exp

diff --git a/ports/webassembly/proxy_js.js b/ports/webassembly/proxy_js.js
index 7a0a1bbe8932d..1f60bf41e81a0 100644
--- a/ports/webassembly/proxy_js.js
+++ b/ports/webassembly/proxy_js.js
@@ -89,7 +89,22 @@ function proxy_call_python(target, argumentsList) {
     if (argumentsList.length > 0) {
         Module._free(args);
     }
-    return proxy_convert_mp_to_js_obj_jsside_with_free(value);
+    const ret = proxy_convert_mp_to_js_obj_jsside_with_free(value);
+    if (ret instanceof PyProxyThenable) {
+        // In Python when an async function is called it creates the
+        // corresponding "generator", which must then be executed at
+        // the top level by an asyncio-like scheduler.  In JavaScript
+        // the semantics for async functions is that they are started
+        // immediately (their non-async prefix code is executed immediately)
+        // and only if they await do they return a Promise to delay the
+        // execution of the remainder of the function.
+        //
+        // Emulate the JavaScript behaviour here by resolving the Python
+        // async function.  We assume that the caller who gets this
+        // return is JavaScript.
+        return Promise.resolve(ret);
+    }
+    return ret;
 }
 
 function proxy_convert_js_to_mp_obj_jsside(js_obj, out) {
diff --git a/tests/ports/webassembly/fun_py_callback_js.mjs b/tests/ports/webassembly/fun_py_callback_js.mjs
new file mode 100644
index 0000000000000..5541e7a4617fe
--- /dev/null
+++ b/tests/ports/webassembly/fun_py_callback_js.mjs
@@ -0,0 +1,31 @@
+// Test using Python functions as JS callbacks.
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+globalThis.asyncTimeout = (ms) =>
+    new Promise((resolve) => setTimeout(resolve, ms));
+
+mp.runPython(`
+import js
+
+def f0():
+    print("f0 run")
+
+async def f1():
+    print("f1 run")
+
+async def f2():
+    print("f2 start")
+    await js.asyncTimeout(0)
+    print("f2 end")
+
+async def f3():
+    print("f3 start")
+    await f2()
+    print("f3 end")
+
+js.setTimeout(f0, 0)
+js.setTimeout(f1, 50)
+js.setTimeout(f2, 100)
+js.setTimeout(f3, 150)
+`);
diff --git a/tests/ports/webassembly/fun_py_callback_js.mjs.exp b/tests/ports/webassembly/fun_py_callback_js.mjs.exp
new file mode 100644
index 0000000000000..732062c840e2a
--- /dev/null
+++ b/tests/ports/webassembly/fun_py_callback_js.mjs.exp
@@ -0,0 +1,8 @@
+f0 run
+f1 run
+f2 start
+f2 end
+f3 start
+f2 start
+f2 end
+f3 end

From 5114f2c1ea7c05fc7ab920299967595cfc5307de Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Fri, 29 Mar 2024 23:58:50 +1100
Subject: [PATCH 323/408] webassembly/proxy_js: Allow a Python proxy of a
 function to be undone.

This optimises the case where a Python function is, for example, stored to
a JavaScript attribute and then later retrieved from Python.  The Python
function no longer needs to be a proxy with double proxying needed for the
call from Python -> JavaScript -> Python.

Signed-off-by: Damien George 
---
 ports/webassembly/objjsproxy.c            | 12 +++++-
 ports/webassembly/proxy_js.js             | 16 ++++---
 tests/ports/webassembly/fun_proxy.mjs     | 52 +++++++++++++++++++++++
 tests/ports/webassembly/fun_proxy.mjs.exp | 19 +++++++++
 4 files changed, 92 insertions(+), 7 deletions(-)
 create mode 100644 tests/ports/webassembly/fun_proxy.mjs
 create mode 100644 tests/ports/webassembly/fun_proxy.mjs.exp

diff --git a/ports/webassembly/objjsproxy.c b/ports/webassembly/objjsproxy.c
index 5e2aeb6a36e4b..098f4e75f5466 100644
--- a/ports/webassembly/objjsproxy.c
+++ b/ports/webassembly/objjsproxy.c
@@ -48,9 +48,17 @@ EM_JS(bool, lookup_attr, (int jsref, const char *str, uint32_t * out), {
     const attr = UTF8ToString(str);
     if (attr in base) {
         let value = base[attr];
-        if (typeof value == "function") {
+        if (typeof value === "function") {
             if (base !== globalThis) {
-                value = value.bind(base);
+                if ("_ref" in value) {
+                    // This is a proxy of a Python function, it doesn't need
+                    // binding.  And not binding it means if it's passed back
+                    // to Python then it can be extracted from the proxy as a
+                    // true Python function.
+                } else {
+                    // A function that is not a Python function.  Bind it.
+                    value = value.bind(base);
+                }
             }
         }
         proxy_convert_js_to_mp_obj_jsside(value, out);
diff --git a/ports/webassembly/proxy_js.js b/ports/webassembly/proxy_js.js
index 1f60bf41e81a0..042deb7b05c7f 100644
--- a/ports/webassembly/proxy_js.js
+++ b/ports/webassembly/proxy_js.js
@@ -135,10 +135,11 @@ function proxy_convert_js_to_mp_obj_jsside(js_obj, out) {
         Module.stringToUTF8(js_obj, buf, len + 1);
         Module.setValue(out + 4, len, "i32");
         Module.setValue(out + 8, buf, "i32");
-    } else if (js_obj instanceof PyProxy) {
-        kind = PROXY_KIND_JS_PYPROXY;
-        Module.setValue(out + 4, js_obj._ref, "i32");
-    } else if (js_obj instanceof PyProxyThenable) {
+    } else if (
+        js_obj instanceof PyProxy ||
+        (typeof js_obj === "function" && "_ref" in js_obj) ||
+        js_obj instanceof PyProxyThenable
+    ) {
         kind = PROXY_KIND_JS_PYPROXY;
         Module.setValue(out + 4, js_obj._ref, "i32");
     } else {
@@ -151,7 +152,11 @@ function proxy_convert_js_to_mp_obj_jsside(js_obj, out) {
 }
 
 function proxy_convert_js_to_mp_obj_jsside_force_double_proxy(js_obj, out) {
-    if (js_obj instanceof PyProxy) {
+    if (
+        js_obj instanceof PyProxy ||
+        (typeof js_obj === "function" && "_ref" in js_obj) ||
+        js_obj instanceof PyProxyThenable
+    ) {
         const kind = PROXY_KIND_JS_OBJECT;
         const id = proxy_js_ref.length;
         proxy_js_ref[id] = js_obj;
@@ -212,6 +217,7 @@ function proxy_convert_mp_to_js_obj_jsside(value) {
             obj = (...args) => {
                 return proxy_call_python(id, args);
             };
+            obj._ref = id;
         } else if (kind === PROXY_KIND_MP_GENERATOR) {
             obj = new PyProxyThenable(id);
         } else {
diff --git a/tests/ports/webassembly/fun_proxy.mjs b/tests/ports/webassembly/fun_proxy.mjs
new file mode 100644
index 0000000000000..87cce44f2bc49
--- /dev/null
+++ b/tests/ports/webassembly/fun_proxy.mjs
@@ -0,0 +1,52 @@
+// Test proxying of functions between Python and JavaScript.
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+// Create JS functions living on the JS and Py sides.
+globalThis.jsFunAdd = (x, y) => x + y;
+mp.globals.set("js_fun_sub", (x, y) => x - y);
+
+console.log("== JavaScript side ==");
+
+// JS function living on the JS side, should be a function.
+console.log(globalThis.jsFunAdd);
+console.log(globalThis.jsFunAdd(1, 2));
+
+// JS function living on the Py side, should be a function.
+console.log(mp.globals.get("js_fun_sub"));
+console.log(mp.globals.get("js_fun_sub")(1, 2));
+
+mp.runPython(`
+import js
+
+print("== Python side ==")
+
+py_fun_mul = lambda x, y: x * y
+js.pyFunDiv = lambda x, y: x / y
+
+# JS function living on the JS side, should be a JsProxy.
+print(type(js.jsFunAdd))
+print(js.jsFunAdd(1, 2))
+
+# JS function living on the Py side, should be a JsProxy.
+print(type(js_fun_sub))
+print(js_fun_sub(1, 2))
+
+# Py function living on the Py side, should be a function.
+print(type(py_fun_mul))
+print(py_fun_mul(2, 3))
+
+# Py function living on the JS side, should be a function.
+print(type(js.pyFunDiv))
+print(js.pyFunDiv(6, 2))
+`);
+
+console.log("== JavaScript side ==");
+
+// Py function living on the Py side, should be a proxy function.
+console.log(mp.globals.get("py_fun_mul"));
+console.log(mp.globals.get("py_fun_mul")(2, 3));
+
+// Py function living on the JS side, should be a proxy function.
+console.log(globalThis.pyFunDiv);
+console.log(globalThis.pyFunDiv(6, 2));
diff --git a/tests/ports/webassembly/fun_proxy.mjs.exp b/tests/ports/webassembly/fun_proxy.mjs.exp
new file mode 100644
index 0000000000000..4aeaa47b22517
--- /dev/null
+++ b/tests/ports/webassembly/fun_proxy.mjs.exp
@@ -0,0 +1,19 @@
+== JavaScript side ==
+[Function (anonymous)]
+3
+[Function (anonymous)]
+-1
+== Python side ==
+
+3
+
+-1
+
+6
+
+3.0
+== JavaScript side ==
+[Function: obj] { _ref: 4 }
+6
+[Function: obj] { _ref: 3 }
+3

From 53d0050255ef92df5adc9255380f170eb33bd2c9 Mon Sep 17 00:00:00 2001
From: iabdalkader 
Date: Thu, 11 Apr 2024 17:03:57 +0200
Subject: [PATCH 324/408] lib/arduino-lib: Update submodule to the latest.

Signed-off-by: iabdalkader 
---
 lib/arduino-lib | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/arduino-lib b/lib/arduino-lib
index 277efd50fcc63..89424753e18ed 160000
--- a/lib/arduino-lib
+++ b/lib/arduino-lib
@@ -1 +1 @@
-Subproject commit 277efd50fcc637e2e2e87c9aa50c06acc9080970
+Subproject commit 89424753e18ed58b7d8041085c9d2e1d162f09ca

From d11ca092f75d2652df403dda7448fe1bc8f98cf7 Mon Sep 17 00:00:00 2001
From: Angus Gratton 
Date: Fri, 5 Apr 2024 14:46:45 +1100
Subject: [PATCH 325/408] shared/tinyusb: Fix dynamic USB control callbacks for
 wLength==0.

In the case where an OUT control transfer triggers with wLength==0 (i.e.
all data sent in the SETUP phase, and no additional data phase) the
callbacks were previously implemented to return b"" (i.e. an empty buffer
for the data phase).

However this didn't actually work as intended because b"" can't provide a
RW buffer (needed for OUT transfers with a data phase to write data into),
so actually the endpoint would stall.

The symptom was often that the device process the request (if processing
it in the SETUP phase when all information was already available), but the
host sees the endpoint stall and eventually returns an error.

This commit changes the behaviour so returning True from the SETUP phase of
a control transfer queues a zero length status response.

Signed-off-by: Angus Gratton 
---
 docs/library/machine.USBDevice.rst | 20 +++++++++++++++-----
 shared/tinyusb/mp_usbd_runtime.c   | 15 ++++++++++-----
 2 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/docs/library/machine.USBDevice.rst b/docs/library/machine.USBDevice.rst
index 82897b280d0fe..e02d3c02df336 100644
--- a/docs/library/machine.USBDevice.rst
+++ b/docs/library/machine.USBDevice.rst
@@ -130,15 +130,25 @@ Methods
 
       Second argument is a memoryview to read the USB control request
       data for this stage. The memoryview is only valid until the
-      callback function returns.
+      callback function returns. Data in this memoryview will be the same
+      across each of the three stages of a single transfer.
+
+      A successful transfer consists of this callback being called in sequence
+      for the three stages. Generally speaking, if a device wants to do
+      something in response to a control request then it's best to wait until
+      the ACK stage to confirm the host controller completed the transfer as
+      expected.
 
       The callback should return one of the following values:
 
-      - ``False`` to stall the endpoint and reject the transfer.
+      - ``False`` to stall the endpoint and reject the transfer. It won't
+        proceed to any remaining stages.
       - ``True`` to continue the transfer to the next stage.
-      - A buffer object to provide data for this stage of the transfer.
-        This should be a writable buffer for an ``OUT`` direction transfer, or a
-        readable buffer with data for an ``IN`` direction transfer.
+      - A buffer object can be returned at the SETUP stage when the transfer
+        will send or receive additional data. Typically this is the case when
+        the ``wLength`` field in the request has a non-zero value. This should
+        be a writable buffer for an ``OUT`` direction transfer, or a readable
+        buffer with data for an ``IN`` direction transfer.
 
     - ``xfer_cb`` - This callback is called whenever a non-control
       transfer submitted by calling :func:`USBDevice.submit_xfer` completes.
diff --git a/shared/tinyusb/mp_usbd_runtime.c b/shared/tinyusb/mp_usbd_runtime.c
index 0b4c79831becd..7ff7dd4ab2ff0 100644
--- a/shared/tinyusb/mp_usbd_runtime.c
+++ b/shared/tinyusb/mp_usbd_runtime.c
@@ -295,6 +295,7 @@ static bool runtime_dev_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_cont
     mp_obj_usb_device_t *usbd = MP_OBJ_TO_PTR(MP_STATE_VM(usbd));
     tusb_dir_t dir = request->bmRequestType_bit.direction;
     mp_buffer_info_t buf_info;
+    bool result;
 
     if (!usbd) {
         return false;
@@ -319,7 +320,7 @@ static bool runtime_dev_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_cont
 
     // Check if callback returned any data to submit
     if (mp_get_buffer(cb_res, &buf_info, dir == TUSB_DIR_IN ? MP_BUFFER_READ : MP_BUFFER_RW)) {
-        bool result = tud_control_xfer(USBD_RHPORT,
+        result = tud_control_xfer(USBD_RHPORT,
             request,
             buf_info.buf,
             buf_info.len);
@@ -328,17 +329,21 @@ static bool runtime_dev_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_cont
             // Keep buffer object alive until the transfer completes
             usbd->xfer_data[0][dir] = cb_res;
         }
-
-        return result;
     } else {
         // Expect True or False to stall or continue
+        result = mp_obj_is_true(cb_res);
 
-        if (stage == CONTROL_STAGE_ACK) {
+        if (stage == CONTROL_STAGE_SETUP && result) {
+            // If no additional data but callback says to continue transfer then
+            // queue a status response.
+            tud_control_status(rhport, request);
+        } else if (stage == CONTROL_STAGE_ACK) {
             // Allow data to be GCed once it's no longer in use
             usbd->xfer_data[0][dir] = mp_const_none;
         }
-        return mp_obj_is_true(cb_res);
     }
+
+    return result;
 }
 
 static bool runtime_dev_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) {

From f76cf2940288f699b8c6346beabdf4de65ddfa31 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=2E=20Neusch=C3=A4fer?= 
Date: Sat, 20 Apr 2024 19:36:03 +0200
Subject: [PATCH 326/408] github/workflows: Update coverage workflow to
 codecov-action@v4.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Fixes: https://github.com/micropython/micropython/issues/14340

Signed-off-by: J. Neuschäfer 
---
 .github/workflows/ports_unix.yml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/ports_unix.yml b/.github/workflows/ports_unix.yml
index 2367eddbe6ea5..4473847db61ef 100644
--- a/.github/workflows/ports_unix.yml
+++ b/.github/workflows/ports_unix.yml
@@ -88,10 +88,11 @@ jobs:
         (cd ports/unix && gcov -o build-coverage/py ../../py/*.c || true)
         (cd ports/unix && gcov -o build-coverage/extmod ../../extmod/*.c || true)
     - name: Upload coverage to Codecov
-      uses: codecov/codecov-action@v3
+      uses: codecov/codecov-action@v4
       with:
         fail_ci_if_error: true
         verbose: true
+        token: ${{ secrets.CODECOV_TOKEN }}
     - name: Print failures
       if: failure()
       run: tests/run-tests.py --print-failures

From 19844b4983066c5771cb60a341c3fce52bca2a87 Mon Sep 17 00:00:00 2001
From: Simon Wood 
Date: Thu, 28 Mar 2024 09:27:25 -0600
Subject: [PATCH 327/408] rp2/modmachine: Prevent lock-up when lightsleep()
 called within thread.

When `lightsleep()` is called from within a thread the interrupts may not
be enabled on current core, and thus the call to `lightsleep()` never
completes.

Fixes issue #14092.

Signed-off-by: Simon Wood 
---
 ports/rp2/modmachine.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/ports/rp2/modmachine.c b/ports/rp2/modmachine.c
index 6189e7dc53796..5551bf723a797 100644
--- a/ports/rp2/modmachine.c
+++ b/ports/rp2/modmachine.c
@@ -127,10 +127,10 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
 
     const uint32_t xosc_hz = XOSC_MHZ * 1000000;
 
-    uint32_t my_interrupts = save_and_disable_interrupts();
+    uint32_t my_interrupts = mp_thread_begin_atomic_section();
     #if MICROPY_PY_NETWORK_CYW43
     if (cyw43_has_pending && cyw43_poll != NULL) {
-        restore_interrupts(my_interrupts);
+        mp_thread_end_atomic_section(my_interrupts);
         return;
     }
     #endif
@@ -165,8 +165,15 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
     } else {
         uint32_t sleep_en0 = clocks_hw->sleep_en0;
         uint32_t sleep_en1 = clocks_hw->sleep_en1;
+        bool timer3_enabled = irq_is_enabled(3);
+
         clocks_hw->sleep_en0 = CLOCKS_SLEEP_EN0_CLK_RTC_RTC_BITS;
         if (use_timer_alarm) {
+            // Make sure ALARM3/IRQ3 is enabled on _this_ core
+            timer_hw->inte |= 1 << 3;
+            if (!timer3_enabled) {
+                irq_set_enabled(3, true);
+            }
             // Use timer alarm to wake.
             clocks_hw->sleep_en1 = CLOCKS_SLEEP_EN1_CLK_SYS_TIMER_BITS;
             timer_hw->alarm[3] = timer_hw->timerawl + delay_ms * 1000;
@@ -177,6 +184,9 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
         scb_hw->scr |= M0PLUS_SCR_SLEEPDEEP_BITS;
         __wfi();
         scb_hw->scr &= ~M0PLUS_SCR_SLEEPDEEP_BITS;
+        if (!timer3_enabled) {
+            irq_set_enabled(3, false);
+        }
         clocks_hw->sleep_en0 = sleep_en0;
         clocks_hw->sleep_en1 = sleep_en1;
     }
@@ -186,7 +196,7 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
 
     // Bring back all clocks.
     clocks_init();
-    restore_interrupts(my_interrupts);
+    mp_thread_end_atomic_section(my_interrupts);
 }
 
 NORETURN static void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) {

From 3129b69e0f990d9f9bf8cc73d7650ddd8a5e06a3 Mon Sep 17 00:00:00 2001
From: "Michiel W. Beijen" 
Date: Tue, 2 Apr 2024 21:58:29 +0200
Subject: [PATCH 328/408] rp2/README: Fix typo, improve sentence about building
 with other boards.

Signed-off-by: Michiel W. Beijen 
---
 ports/rp2/README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ports/rp2/README.md b/ports/rp2/README.md
index e22fb3093d72b..c2f3771cd313f 100644
--- a/ports/rp2/README.md
+++ b/ports/rp2/README.md
@@ -37,7 +37,7 @@ You can also build the standard CMake way.  The final firmware is found in
 the top-level of the CMake build directory (`build` by default) and is
 called `firmware.uf2`.
 
-If you are using a different board other than a Rasoberry Pi Pico, then you should
+If you are using a board other than a Raspberry Pi Pico, you should
 pass the board name to the build; e.g. for Raspberry Pi Pico W:
 
     $ make BOARD=RPI_PICO_W submodules

From 40f7e9ce20e845ce2372347e5b5fd4dbff69ef6e Mon Sep 17 00:00:00 2001
From: stijn 
Date: Thu, 18 Apr 2024 12:01:45 +0200
Subject: [PATCH 329/408] py/objfun: Fix C++ compatibility with casting in
 inline functions.

Explicit casts are needed.

Fixes recent changes from 648a7578da21cc7ddb4046fc59891144e797b983 and
9400229766624e80db6a6f95af287a5542dc1b43.

Signed-off-by: stijn 
---
 py/objfun.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/py/objfun.h b/py/objfun.h
index af7c334858836..f16ef76b80e70 100644
--- a/py/objfun.h
+++ b/py/objfun.h
@@ -56,14 +56,14 @@ void mp_obj_fun_bc_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest);
 #if MICROPY_EMIT_NATIVE
 
 static inline mp_obj_t mp_obj_new_fun_native(const mp_obj_t *def_args, const void *fun_data, const mp_module_context_t *mc, struct _mp_raw_code_t *const *child_table) {
-    mp_obj_fun_bc_t *o = MP_OBJ_TO_PTR(mp_obj_new_fun_bc(def_args, (const byte *)fun_data, mc, child_table));
+    mp_obj_fun_bc_t *o = (mp_obj_fun_bc_t *)MP_OBJ_TO_PTR(mp_obj_new_fun_bc(def_args, (const byte *)fun_data, mc, child_table));
     o->base.type = &mp_type_fun_native;
     return MP_OBJ_FROM_PTR(o);
 }
 
 static inline mp_obj_t mp_obj_new_fun_viper(const void *fun_data, const mp_module_context_t *mc, struct _mp_raw_code_t *const *child_table) {
     mp_obj_fun_bc_t *o = mp_obj_malloc(mp_obj_fun_bc_t, &mp_type_fun_viper);
-    o->bytecode = fun_data;
+    o->bytecode = (const byte *)fun_data;
     o->context = mc;
     o->child_table = child_table;
     return MP_OBJ_FROM_PTR(o);
@@ -101,9 +101,9 @@ static inline void *mp_obj_fun_native_get_generator_resume(const mp_obj_fun_bc_t
 
 #if MICROPY_EMIT_INLINE_ASM
 static inline mp_obj_t mp_obj_new_fun_asm(size_t n_args, const void *fun_data, mp_uint_t type_sig) {
-    mp_obj_fun_asm_t *o = mp_obj_malloc(mp_obj_fun_asm_t, &mp_type_fun_asm);
+    mp_obj_fun_asm_t *o = (mp_obj_fun_asm_t *)mp_obj_malloc(mp_obj_fun_asm_t, &mp_type_fun_asm);
     o->n_args = n_args;
-    o->fun_data = fun_data;
+    o->fun_data = (const byte *)fun_data;
     o->type_sig = type_sig;
     return MP_OBJ_FROM_PTR(o);
 }

From ce491ab0d168a8278062e1fc7ebed3ca47ab89d2 Mon Sep 17 00:00:00 2001
From: Vonasmic 
Date: Wed, 3 Apr 2024 10:35:58 +0200
Subject: [PATCH 330/408] py/obj: Fix initialiser order in
 MP_DEFINE_CONST_OBJ_TYPE_NARGS_ macros.

This commit swaps the order of the `flags` and `name` struct initialisers
for `mp_obj_type_t`, to fix an incompatibility with C++.  The original
order of the initialiser didn't match the definition of the type, and
although that's still legal C, it's not legal C++.

Signed-off-by: Vonasmic 
---
 py/obj.h | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/py/obj.h b/py/obj.h
index 9f2bb46e41d74..86952565c55d6 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -753,20 +753,20 @@ typedef struct _mp_obj_full_type_t {
 // Do not use these directly, instead use MP_DEFINE_CONST_OBJ_TYPE.
 // Generated with:
 // for i in range(13):
-//     print(f"#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_{i}(_struct_type, _typename, _name, _flags{''.join(f', f{j+1}, v{j+1}' for j in range(i))}) const _struct_type _typename = {{ .base = {{ &mp_type_type }}, .name = _name, .flags = _flags{''.join(f', .slot_index_##f{j+1} = {j+1}' for j in range(i))}{', .slots = { ' + ''.join(f'v{j+1}, ' for j in range(i)) + '}' if i else '' } }}")
-#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_0(_struct_type, _typename, _name, _flags) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags }
-#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_1(_struct_type, _typename, _name, _flags, f1, v1) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slots = { v1, } }
-#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_2(_struct_type, _typename, _name, _flags, f1, v1, f2, v2) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slots = { v1, v2, } }
-#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_3(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slots = { v1, v2, v3, } }
-#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_4(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slots = { v1, v2, v3, v4, } }
-#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_5(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slots = { v1, v2, v3, v4, v5, } }
-#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_6(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slots = { v1, v2, v3, v4, v5, v6, } }
-#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_7(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slots = { v1, v2, v3, v4, v5, v6, v7, } }
-#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_8(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, } }
-#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_9(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, } }
-#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_10(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9, f10, v10) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slot_index_##f10 = 10, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, } }
-#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_11(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9, f10, v10, f11, v11) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slot_index_##f10 = 10, .slot_index_##f11 = 11, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, } }
-#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_12(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9, f10, v10, f11, v11, f12, v12) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slot_index_##f10 = 10, .slot_index_##f11 = 11, .slot_index_##f12 = 12, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, } }
+//     print(f"#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_{i}(_struct_type, _typename, _name, _flags{''.join(f', f{j+1}, v{j+1}' for j in range(i))}) const _struct_type _typename = {{ .base = {{ &mp_type_type }}, .flags = _flags, .name = _name{''.join(f', .slot_index_##f{j+1} = {j+1}' for j in range(i))}{', .slots = { ' + ''.join(f'v{j+1}, ' for j in range(i)) + '}' if i else '' } }}")
+#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_0(_struct_type, _typename, _name, _flags) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name }
+#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_1(_struct_type, _typename, _name, _flags, f1, v1) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slots = { v1, } }
+#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_2(_struct_type, _typename, _name, _flags, f1, v1, f2, v2) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slots = { v1, v2, } }
+#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_3(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slots = { v1, v2, v3, } }
+#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_4(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slots = { v1, v2, v3, v4, } }
+#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_5(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slots = { v1, v2, v3, v4, v5, } }
+#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_6(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slots = { v1, v2, v3, v4, v5, v6, } }
+#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_7(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slots = { v1, v2, v3, v4, v5, v6, v7, } }
+#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_8(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, } }
+#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_9(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, } }
+#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_10(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9, f10, v10) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slot_index_##f10 = 10, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, } }
+#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_11(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9, f10, v10, f11, v11) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slot_index_##f10 = 10, .slot_index_##f11 = 11, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, } }
+#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_12(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9, f10, v10, f11, v11, f12, v12) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slot_index_##f10 = 10, .slot_index_##f11 = 11, .slot_index_##f12 = 12, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, } }
 
 // Because the mp_obj_type_t instances are in (zero-initialised) ROM, we take
 // slot_index_foo=0 to mean that the slot is unset. This also simplifies checking

From 4bed614e707c0644c06e117f848fa12605c711cd Mon Sep 17 00:00:00 2001
From: Angus Gratton 
Date: Tue, 13 Feb 2024 09:24:36 +1100
Subject: [PATCH 331/408] py/objarray: Fix use-after-free if extending a
 bytearray from itself.

Two cases, one assigning to a slice.
Closes https://github.com/micropython/micropython/issues/13283

Second is extending a slice from itself, similar logic.

In both cases the problem occurs when m_renew causes realloc to move the
buffer, leaving a dangling pointer behind.

There are more complex and hard to fix cases when either argument is a
memoryview into the buffer, currently resizing to a new address breaks
memoryviews into that object.

Reproducing this bug and confirming the fix was done by running the unix
port under valgrind with GC-aware extensions.

Note in default configurations with GIL this bug exists but has no impact
(the free buffer won't be reused while the function is still executing, and
is no longer referenced after it returns).

Signed-off-by: Angus Gratton 
---
 py/objarray.c                          | 20 ++++++++++++++++----
 tests/basics/bytearray_add.py          |  9 ++++++++-
 tests/basics/bytearray_add_self.py     |  8 ++++++++
 tests/basics/bytearray_add_self.py.exp |  1 +
 tests/basics/bytearray_slice_assign.py | 18 ++++++++++++------
 5 files changed, 45 insertions(+), 11 deletions(-)
 create mode 100644 tests/basics/bytearray_add_self.py
 create mode 100644 tests/basics/bytearray_add_self.py.exp

diff --git a/py/objarray.c b/py/objarray.c
index 1fff234822521..803af2cd270c7 100644
--- a/py/objarray.c
+++ b/py/objarray.c
@@ -424,6 +424,13 @@ static mp_obj_t array_extend(mp_obj_t self_in, mp_obj_t arg_in) {
     if (self->free < len) {
         self->items = m_renew(byte, self->items, (self->len + self->free) * sz, (self->len + len) * sz);
         self->free = 0;
+
+        if (self_in == arg_in) {
+            // Get arg_bufinfo again in case self->items has moved
+            //
+            // (Note not possible to handle case that arg_in is a memoryview into self)
+            mp_get_buffer_raise(arg_in, &arg_bufinfo, MP_BUFFER_READ);
+        }
     } else {
         self->free -= len;
     }
@@ -456,7 +463,8 @@ static mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
                 #if MICROPY_PY_ARRAY_SLICE_ASSIGN
                 // Assign
                 size_t src_len;
-                void *src_items;
+                uint8_t *src_items;
+                size_t src_offs = 0;
                 size_t item_sz = mp_binary_get_size('@', o->typecode & TYPECODE_MASK, NULL);
                 if (mp_obj_is_obj(value) && MP_OBJ_TYPE_GET_SLOT_OR_NULL(((mp_obj_base_t *)MP_OBJ_TO_PTR(value))->type, subscr) == array_subscr) {
                     // value is array, bytearray or memoryview
@@ -469,7 +477,7 @@ static mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
                     src_items = src_slice->items;
                     #if MICROPY_PY_BUILTINS_MEMORYVIEW
                     if (mp_obj_is_type(value, &mp_type_memoryview)) {
-                        src_items = (uint8_t *)src_items + (src_slice->memview_offset * item_sz);
+                        src_offs = src_slice->memview_offset * item_sz;
                     }
                     #endif
                 } else if (mp_obj_is_type(value, &mp_type_bytes)) {
@@ -504,13 +512,17 @@ static mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
                         // TODO: alloc policy; at the moment we go conservative
                         o->items = m_renew(byte, o->items, (o->len + o->free) * item_sz, (o->len + len_adj) * item_sz);
                         o->free = len_adj;
+                        // m_renew may have moved o->items
+                        if (src_items == dest_items) {
+                            src_items = o->items;
+                        }
                         dest_items = o->items;
                     }
                     mp_seq_replace_slice_grow_inplace(dest_items, o->len,
-                        slice.start, slice.stop, src_items, src_len, len_adj, item_sz);
+                        slice.start, slice.stop, src_items + src_offs, src_len, len_adj, item_sz);
                 } else {
                     mp_seq_replace_slice_no_grow(dest_items, o->len,
-                        slice.start, slice.stop, src_items, src_len, item_sz);
+                        slice.start, slice.stop, src_items + src_offs, src_len, item_sz);
                     // Clear "freed" elements at the end of list
                     // TODO: This is actually only needed for typecode=='O'
                     mp_seq_clear(dest_items, o->len + len_adj, o->len, item_sz);
diff --git a/tests/basics/bytearray_add.py b/tests/basics/bytearray_add.py
index a7e2b57374255..1f30a3b740e95 100644
--- a/tests/basics/bytearray_add.py
+++ b/tests/basics/bytearray_add.py
@@ -15,4 +15,11 @@
 
 # this inplace add tests the code when the buffer doesn't need to be increased
 b = bytearray()
-b += b''
+b += b""
+
+# extend a bytearray from itself
+b = bytearray(b"abcdefgh")
+for _ in range(4):
+    c = bytearray(b)  # extra allocation, as above
+    b.extend(b)
+print(b)
diff --git a/tests/basics/bytearray_add_self.py b/tests/basics/bytearray_add_self.py
new file mode 100644
index 0000000000000..94ae8689fd16c
--- /dev/null
+++ b/tests/basics/bytearray_add_self.py
@@ -0,0 +1,8 @@
+# add a bytearray to itself
+# This is not supported by CPython as of 3.11.18.
+
+b = bytearray(b"123456789")
+for _ in range(4):
+    c = bytearray(b)  # extra allocation increases chance 'b' has to relocate
+    b += b
+print(b)
diff --git a/tests/basics/bytearray_add_self.py.exp b/tests/basics/bytearray_add_self.py.exp
new file mode 100644
index 0000000000000..5ef948157ac0f
--- /dev/null
+++ b/tests/basics/bytearray_add_self.py.exp
@@ -0,0 +1 @@
+bytearray(b'123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789')
diff --git a/tests/basics/bytearray_slice_assign.py b/tests/basics/bytearray_slice_assign.py
index fa7878e10ddbb..4de0819042a13 100644
--- a/tests/basics/bytearray_slice_assign.py
+++ b/tests/basics/bytearray_slice_assign.py
@@ -18,7 +18,7 @@
 l[1:3] = bytearray()
 print(l)
 l = bytearray(x)
-#del l[1:3]
+# del l[1:3]
 print(l)
 
 l = bytearray(x)
@@ -28,7 +28,7 @@
 l[:3] = bytearray()
 print(l)
 l = bytearray(x)
-#del l[:3]
+# del l[:3]
 print(l)
 
 l = bytearray(x)
@@ -38,7 +38,7 @@
 l[:-3] = bytearray()
 print(l)
 l = bytearray(x)
-#del l[:-3]
+# del l[:-3]
 print(l)
 
 # slice assignment that extends the array
@@ -61,8 +61,14 @@
 print(b)
 
 # Growth of bytearray via slice extension
-b = bytearray(b'12345678')
-b.append(57) # expand and add a bit of unused space at end of the bytearray
+b = bytearray(b"12345678")
+b.append(57)  # expand and add a bit of unused space at end of the bytearray
 for i in range(400):
-    b[-1:] = b'ab' # grow slowly into the unused space
+    b[-1:] = b"ab"  # grow slowly into the unused space
+print(len(b), b)
+
+# Growth of bytearray via slice extension from itself
+b = bytearray(b"1234567")
+for i in range(3):
+    b[-1:] = b
 print(len(b), b)

From 6877987002684465d30b349759285648824553da Mon Sep 17 00:00:00 2001
From: Angus Gratton 
Date: Wed, 27 Mar 2024 17:25:25 +1100
Subject: [PATCH 332/408] tests/cpydiff: Add a note about risk of resizing
 memoryview targets.

This a stop-gap until there is a proper fix for this.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton 
---
 tests/cpydiff/types_memoryview_invalid.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)
 create mode 100644 tests/cpydiff/types_memoryview_invalid.py

diff --git a/tests/cpydiff/types_memoryview_invalid.py b/tests/cpydiff/types_memoryview_invalid.py
new file mode 100644
index 0000000000000..c995a2e8991c6
--- /dev/null
+++ b/tests/cpydiff/types_memoryview_invalid.py
@@ -0,0 +1,12 @@
+"""
+categories: Types,memoryview
+description: memoryview can become invalid if its target is resized
+cause: CPython prevents a ``bytearray`` or ``io.bytesIO`` object from changing size while there is a ``memoryview`` object that references it. MicroPython requires the programmer to manually ensure that an object is not resized while any ``memoryview`` references it.
+
+In the worst case scenario, resizing an object which is the target of a memoryview can cause the memoryview(s) to reference invalid freed memory (a use-after-free bug) and corrupt the MicroPython runtime.
+workaround: Do not change the size of any ``bytearray`` or ``io.bytesIO`` object that has a ``memoryview`` assigned to it.
+"""
+b = bytearray(b"abcdefg")
+m = memoryview(b)
+b.extend(b"hijklmnop")
+print(b, bytes(m))

From 49ce7a607517dc0152a4f8768f5d03b3e5613e02 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Mon, 22 Apr 2024 12:35:31 +1000
Subject: [PATCH 333/408] github/workflows: Run code size workflow on shared or
 port code changes.

To get more insight to firmware size changes when code changes.

Signed-off-by: Damien George 
---
 .github/workflows/code_size.yml | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/.github/workflows/code_size.yml b/.github/workflows/code_size.yml
index a65a00201a7d2..1ef43d1fd396c 100644
--- a/.github/workflows/code_size.yml
+++ b/.github/workflows/code_size.yml
@@ -8,9 +8,15 @@ on:
       - 'tools/**'
       - 'py/**'
       - 'extmod/**'
+      - 'shared/**'
       - 'lib/**'
       - 'ports/bare-arm/**'
+      - 'ports/mimxrt/**'
       - 'ports/minimal/**'
+      - 'ports/rp2/**'
+      - 'ports/samd/**'
+      - 'ports/stm32/**'
+      - 'ports/unix/**'
 
 concurrency:
   group: ${{ github.workflow }}-${{ github.ref }}

From 45848f77cac07dac1c77680041862ba444c1f3a3 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Wed, 24 Apr 2024 13:00:20 +1000
Subject: [PATCH 334/408] webassembly/api: Fix waiting for Emscripten module to
 be loaded.

In modularize mode, the `_createMicroPythonModule()` constructor must be
await'ed on, before `Module` is ready to use.

Signed-off-by: Damien George 
---
 ports/webassembly/api.js | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/ports/webassembly/api.js b/ports/webassembly/api.js
index 7d1832af4f2ba..2459075fc5848 100644
--- a/ports/webassembly/api.js
+++ b/ports/webassembly/api.js
@@ -38,7 +38,7 @@ export async function loadMicroPython(options) {
         { heapsize: 1024 * 1024, linebuffer: true },
         options,
     );
-    const Module = {};
+    let Module = {};
     Module.locateFile = (path, scriptDirectory) =>
         url || scriptDirectory + path;
     Module._textDecoder = new TextDecoder();
@@ -83,11 +83,7 @@ export async function loadMicroPython(options) {
             Module.stderr = (c) => stderr(new Uint8Array([c]));
         }
     }
-    const moduleLoaded = new Promise((r) => {
-        Module.postRun = r;
-    });
-    _createMicroPythonModule(Module);
-    await moduleLoaded;
+    Module = await _createMicroPythonModule(Module);
     globalThis.Module = Module;
     proxy_js_init();
     const pyimport = (name) => {

From 9c7f0659e2a6db37125fa092ebe5150125eb14b3 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Wed, 17 Apr 2024 14:25:48 +1000
Subject: [PATCH 335/408] webassembly/api: Allocate code data on C heap when
 running Python code.

Otherwise Emscripten allocates it on the Emscripten C stack, which will
overflow for large amounts of code.

Fixes issue #14307.

Signed-off-by: Damien George 
---
 ports/webassembly/api.js | 16 ++++++++++++----
 ports/webassembly/main.c |  8 ++++----
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/ports/webassembly/api.js b/ports/webassembly/api.js
index 2459075fc5848..2f2ad95221ccd 100644
--- a/ports/webassembly/api.js
+++ b/ports/webassembly/api.js
@@ -127,23 +127,31 @@ export async function loadMicroPython(options) {
         },
         pyimport: pyimport,
         runPython(code) {
+            const len = Module.lengthBytesUTF8(code);
+            const buf = Module._malloc(len + 1);
+            Module.stringToUTF8(code, buf, len + 1);
             const value = Module._malloc(3 * 4);
             Module.ccall(
                 "mp_js_do_exec",
                 "number",
-                ["string", "pointer"],
-                [code, value],
+                ["pointer", "number", "pointer"],
+                [buf, len, value],
             );
+            Module._free(buf);
             return proxy_convert_mp_to_js_obj_jsside_with_free(value);
         },
         runPythonAsync(code) {
+            const len = Module.lengthBytesUTF8(code);
+            const buf = Module._malloc(len + 1);
+            Module.stringToUTF8(code, buf, len + 1);
             const value = Module._malloc(3 * 4);
             Module.ccall(
                 "mp_js_do_exec_async",
                 "number",
-                ["string", "pointer"],
-                [code, value],
+                ["pointer", "number", "pointer"],
+                [buf, len, value],
             );
+            Module._free(buf);
             return proxy_convert_mp_to_js_obj_jsside_with_free(value);
         },
         replInit() {
diff --git a/ports/webassembly/main.c b/ports/webassembly/main.c
index 441c6d67e350a..23d12b6dbbc76 100644
--- a/ports/webassembly/main.c
+++ b/ports/webassembly/main.c
@@ -104,7 +104,7 @@ void mp_js_do_import(const char *name, uint32_t *out) {
     }
 }
 
-void mp_js_do_exec(const char *src, uint32_t *out) {
+void mp_js_do_exec(const char *src, size_t len, uint32_t *out) {
     // Collect at the top-level, where there are no root pointers from stack/registers.
     gc_collect_start();
     gc_collect_end();
@@ -112,7 +112,7 @@ void mp_js_do_exec(const char *src, uint32_t *out) {
     mp_parse_input_kind_t input_kind = MP_PARSE_FILE_INPUT;
     nlr_buf_t nlr;
     if (nlr_push(&nlr) == 0) {
-        mp_lexer_t *lex = mp_lexer_new_from_str_len_dedent(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
+        mp_lexer_t *lex = mp_lexer_new_from_str_len_dedent(MP_QSTR__lt_stdin_gt_, src, len, 0);
         qstr source_name = lex->source_name;
         mp_parse_tree_t parse_tree = mp_parse(lex, input_kind);
         mp_obj_t module_fun = mp_compile(&parse_tree, source_name, false);
@@ -125,9 +125,9 @@ void mp_js_do_exec(const char *src, uint32_t *out) {
     }
 }
 
-void mp_js_do_exec_async(const char *src, uint32_t *out) {
+void mp_js_do_exec_async(const char *src, size_t len, uint32_t *out) {
     mp_compile_allow_top_level_await = true;
-    mp_js_do_exec(src, out);
+    mp_js_do_exec(src, len, out);
     mp_compile_allow_top_level_await = false;
 }
 

From 4c3f5f552b15f74984e906db799812df6b3e9555 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Thu, 18 Apr 2024 17:19:56 +1000
Subject: [PATCH 336/408] webassembly/objjsproxy: Fix handling of thrown value
 into JS generator.

Signed-off-by: Damien George 
---
 ports/webassembly/objjsproxy.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/ports/webassembly/objjsproxy.c b/ports/webassembly/objjsproxy.c
index 098f4e75f5466..65c806536dea2 100644
--- a/ports/webassembly/objjsproxy.c
+++ b/ports/webassembly/objjsproxy.c
@@ -346,6 +346,12 @@ typedef struct _jsproxy_gen_t {
 
 mp_vm_return_kind_t jsproxy_gen_resume(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t throw_value, mp_obj_t *ret_val) {
     jsproxy_gen_t *self = MP_OBJ_TO_PTR(self_in);
+
+    if (throw_value) {
+        *ret_val = throw_value;
+        return MP_VM_RETURN_EXCEPTION;
+    }
+
     switch (self->state) {
         case JSOBJ_GEN_STATE_WAITING:
             self->state = JSOBJ_GEN_STATE_COMPLETED;

From 92b3b69648304b292fb59e734fc9a61a188ba419 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Thu, 18 Apr 2024 17:20:28 +1000
Subject: [PATCH 337/408] webassembly/proxy_c: Fix proxy then reject handling.

An exception on the Python side should be passed to the Promise reject
callback on the JavaScript side.

Signed-off-by: Damien George 
---
 ports/webassembly/proxy_c.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/ports/webassembly/proxy_c.c b/ports/webassembly/proxy_c.c
index 8d137f6271297..fc863c06be5e3 100644
--- a/ports/webassembly/proxy_c.c
+++ b/ports/webassembly/proxy_c.c
@@ -296,10 +296,11 @@ EM_JS(void, js_then_resolve, (uint32_t * ret_value, uint32_t * resolve, uint32_t
     resolve_js(ret_value_js);
 });
 
-EM_JS(void, js_then_reject, (uint32_t * resolve, uint32_t * reject), {
+EM_JS(void, js_then_reject, (uint32_t * ret_value, uint32_t * resolve, uint32_t * reject), {
+    const ret_value_js = proxy_convert_mp_to_js_obj_jsside(ret_value);
     const resolve_js = proxy_convert_mp_to_js_obj_jsside(resolve);
     const reject_js = proxy_convert_mp_to_js_obj_jsside(reject);
-    reject_js(null);
+    reject_js(ret_value_js);
 });
 
 // *FORMAT-OFF*
@@ -335,10 +336,12 @@ static mp_obj_t proxy_resume_execute(mp_obj_t self_in, mp_obj_t value, mp_obj_t
         uint32_t out[PVN];
         js_then_continue(ref, out_py_resume, out_resolve, out_reject, out);
         return proxy_convert_js_to_mp_obj_cside(out);
-    } else {
-        // MP_VM_RETURN_EXCEPTION;
-        js_then_reject(out_resolve, out_reject);
-        nlr_raise(ret_value);
+    } else { // ret_kind == MP_VM_RETURN_EXCEPTION;
+        // Pass the exception through as an object to reject the promise (don't raise/throw it).
+        uint32_t out_ret_value[PVN];
+        proxy_convert_mp_to_js_obj_cside(ret_value, out_ret_value);
+        js_then_reject(out_ret_value, out_resolve, out_reject);
+        return mp_const_none;
     }
 }
 

From d998ca78c8abb975ba00a658544a1b72575f9732 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Thu, 18 Apr 2024 17:20:57 +1000
Subject: [PATCH 338/408] webassembly/proxy_c: Fix then-continue to convert
 reason to throw value.

When a Promise is rejected on the JavaScript side, the reject reason should
be thrown into the encapsulating generator on the Python side.

Signed-off-by: Damien George 
---
 ports/webassembly/proxy_c.c | 32 ++++++++++++++++++++++++++------
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/ports/webassembly/proxy_c.c b/ports/webassembly/proxy_c.c
index fc863c06be5e3..ebf670b56ec5b 100644
--- a/ports/webassembly/proxy_c.c
+++ b/ports/webassembly/proxy_c.c
@@ -308,14 +308,34 @@ EM_JS(void, js_then_continue, (int jsref, uint32_t * py_resume, uint32_t * resol
     const py_resume_js = proxy_convert_mp_to_js_obj_jsside(py_resume);
     const resolve_js = proxy_convert_mp_to_js_obj_jsside(resolve);
     const reject_js = proxy_convert_mp_to_js_obj_jsside(reject);
-    const ret = proxy_js_ref[jsref].then((x) => {py_resume_js(x, resolve_js, reject_js);}, reject_js);
+    const ret = proxy_js_ref[jsref].then(
+        (result) => {
+            // The Promise is fulfilled on the JavaScript side.  Take the result and
+            // send it to the encapsulating generator on the Python side, so it
+            // becomes the result of the "yield from" that deferred to this Promise.
+            py_resume_js(result, null, resolve_js, reject_js);
+        },
+        (reason) => {
+            // The Promise is rejected on the JavaScript side.  Take the reason and
+            // throw it into the encapsulating generator on the Python side.
+            py_resume_js(null, reason, resolve_js, reject_js);
+        },
+    );
     proxy_convert_js_to_mp_obj_jsside(ret, out);
 });
 // *FORMAT-ON*
 
-static mp_obj_t proxy_resume_execute(mp_obj_t self_in, mp_obj_t value, mp_obj_t resolve, mp_obj_t reject) {
+static mp_obj_t proxy_resume_execute(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t throw_value, mp_obj_t resolve, mp_obj_t reject) {
+    if (throw_value != MP_OBJ_NULL && throw_value != mp_const_none) {
+        if (send_value == mp_const_none) {
+            send_value = MP_OBJ_NULL;
+        }
+    } else {
+        throw_value = MP_OBJ_NULL;
+    }
+
     mp_obj_t ret_value;
-    mp_vm_return_kind_t ret_kind = mp_resume(self_in, value, MP_OBJ_NULL, &ret_value);
+    mp_vm_return_kind_t ret_kind = mp_resume(self_in, send_value, throw_value, &ret_value);
 
     uint32_t out_resolve[PVN];
     uint32_t out_reject[PVN];
@@ -346,9 +366,9 @@ static mp_obj_t proxy_resume_execute(mp_obj_t self_in, mp_obj_t value, mp_obj_t
 }
 
 static mp_obj_t resume_fun(size_t n_args, const mp_obj_t *args) {
-    return proxy_resume_execute(args[0], args[1], args[2], args[3]);
+    return proxy_resume_execute(args[0], args[1], args[2], args[3], args[4]);
 }
-static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(resume_obj, 4, 4, resume_fun);
+static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(resume_obj, 5, 5, resume_fun);
 
 void proxy_c_to_js_resume(uint32_t c_ref, uint32_t *args) {
     nlr_buf_t nlr;
@@ -356,7 +376,7 @@ void proxy_c_to_js_resume(uint32_t c_ref, uint32_t *args) {
         mp_obj_t obj = proxy_c_get_obj(c_ref);
         mp_obj_t resolve = proxy_convert_js_to_mp_obj_cside(args + 1 * 3);
         mp_obj_t reject = proxy_convert_js_to_mp_obj_cside(args + 2 * 3);
-        mp_obj_t ret = proxy_resume_execute(obj, mp_const_none, resolve, reject);
+        mp_obj_t ret = proxy_resume_execute(obj, mp_const_none, mp_const_none, resolve, reject);
         nlr_pop();
         return proxy_convert_mp_to_js_obj_cside(ret, args);
     } else {

From 967ad38ac7e09270e9f5734c59baebf2d1eb3723 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Fri, 19 Apr 2024 12:14:49 +1000
Subject: [PATCH 339/408] extmod/modasyncio: Make mp_asyncio_context variable
 public.

So it can be accessed by a port if needed, for example to see if asyncio
has been imported.

Signed-off-by: Damien George 
---
 extmod/modasyncio.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/extmod/modasyncio.c b/extmod/modasyncio.c
index 61dd707223ff1..4f82370d238a9 100644
--- a/extmod/modasyncio.c
+++ b/extmod/modasyncio.c
@@ -156,7 +156,7 @@ static MP_DEFINE_CONST_OBJ_TYPE(
 // Task class
 
 // This is the core asyncio context with cur_task, _task_queue and CancelledError.
-static mp_obj_t asyncio_context = MP_OBJ_NULL;
+mp_obj_t mp_asyncio_context = MP_OBJ_NULL;
 
 static mp_obj_t task_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
     mp_arg_check_num(n_args, n_kw, 1, 2, false);
@@ -168,7 +168,7 @@ static mp_obj_t task_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
     self->state = TASK_STATE_RUNNING_NOT_WAITED_ON;
     self->ph_key = MP_OBJ_NEW_SMALL_INT(0);
     if (n_args == 2) {
-        asyncio_context = args[1];
+        mp_asyncio_context = args[1];
     }
     return MP_OBJ_FROM_PTR(self);
 }
@@ -186,7 +186,7 @@ static mp_obj_t task_cancel(mp_obj_t self_in) {
         return mp_const_false;
     }
     // Can't cancel self (not supported yet).
-    mp_obj_t cur_task = mp_obj_dict_get(asyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR_cur_task));
+    mp_obj_t cur_task = mp_obj_dict_get(mp_asyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR_cur_task));
     if (self_in == cur_task) {
         mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("can't cancel self"));
     }
@@ -195,7 +195,7 @@ static mp_obj_t task_cancel(mp_obj_t self_in) {
         self = MP_OBJ_TO_PTR(self->data);
     }
 
-    mp_obj_t _task_queue = mp_obj_dict_get(asyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR__task_queue));
+    mp_obj_t _task_queue = mp_obj_dict_get(mp_asyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR__task_queue));
 
     // Reschedule Task as a cancelled task.
     mp_obj_t dest[3];
@@ -218,7 +218,7 @@ static mp_obj_t task_cancel(mp_obj_t self_in) {
         task_queue_push(2, dest);
     }
 
-    self->data = mp_obj_dict_get(asyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR_CancelledError));
+    self->data = mp_obj_dict_get(mp_asyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR_CancelledError));
 
     return mp_const_true;
 }
@@ -278,7 +278,7 @@ static mp_obj_t task_iternext(mp_obj_t self_in) {
         nlr_raise(self->data);
     } else {
         // Put calling task on waiting queue.
-        mp_obj_t cur_task = mp_obj_dict_get(asyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR_cur_task));
+        mp_obj_t cur_task = mp_obj_dict_get(mp_asyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR_cur_task));
         mp_obj_t args[2] = { self->state, cur_task };
         task_queue_push(2, args);
         // Set calling task's data to this task that it waits on, to double-link it.

From 84d6f8e8cb993e82f03e209ffd49d5c44fc780e0 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Fri, 19 Apr 2024 12:16:27 +1000
Subject: [PATCH 340/408] webassembly/modjsffi: Add jsffi.async_timeout_ms.

This function exposes `setTimeout()` as an async function.

Signed-off-by: Damien George 
---
 ports/webassembly/modjsffi.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/ports/webassembly/modjsffi.c b/ports/webassembly/modjsffi.c
index d4e61e368f009..cb2f578f8f593 100644
--- a/ports/webassembly/modjsffi.c
+++ b/ports/webassembly/modjsffi.c
@@ -61,12 +61,27 @@ static mp_obj_t mp_jsffi_to_js(mp_obj_t arg) {
 }
 static MP_DEFINE_CONST_FUN_OBJ_1(mp_jsffi_to_js_obj, mp_jsffi_to_js);
 
+// *FORMAT-OFF*
+EM_JS(void, promise_with_timeout_ms, (double ms, uint32_t * out), {
+    const ret = new Promise((resolve) => setTimeout(resolve, ms));
+    proxy_convert_js_to_mp_obj_jsside(ret, out);
+});
+// *FORMAT-ON*
+
+static mp_obj_t mp_jsffi_async_timeout_ms(mp_obj_t arg) {
+    uint32_t out[PVN];
+    promise_with_timeout_ms(mp_obj_get_float_to_d(arg), out);
+    return proxy_convert_js_to_mp_obj_cside(out);
+}
+static MP_DEFINE_CONST_FUN_OBJ_1(mp_jsffi_async_timeout_ms_obj, mp_jsffi_async_timeout_ms);
+
 static const mp_rom_map_elem_t mp_module_jsffi_globals_table[] = {
     { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_jsffi) },
 
     { MP_ROM_QSTR(MP_QSTR_JsProxy), MP_ROM_PTR(&mp_type_jsproxy) },
     { MP_ROM_QSTR(MP_QSTR_create_proxy), MP_ROM_PTR(&mp_jsffi_create_proxy_obj) },
     { MP_ROM_QSTR(MP_QSTR_to_js), MP_ROM_PTR(&mp_jsffi_to_js_obj) },
+    { MP_ROM_QSTR(MP_QSTR_async_timeout_ms), MP_ROM_PTR(&mp_jsffi_async_timeout_ms_obj) },
 };
 static MP_DEFINE_CONST_DICT(mp_module_jsffi_globals, mp_module_jsffi_globals_table);
 

From 8a3546b3bd71dbc6d79900afbe58767e09b82c3e Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Fri, 19 Apr 2024 12:17:11 +1000
Subject: [PATCH 341/408] webassembly: Add JavaScript-based asyncio support.

This commit adds a significant portion of the existing MicroPython asyncio
module to the webassembly port, using parts of the existing asyncio code
and some custom JavaScript parts.

The key difference to the standard asyncio is that this version uses the
JavaScript runtime to do the actual scheduling and waiting on events, eg
Promise fulfillment, timeouts, fetching URLs.

This implementation does not include asyncio.run(). Instead one just uses
asyncio.create_task(..) to start tasks and then returns to the JavaScript.
Then JavaScript will run the tasks.

The implementation here tries to reuse as much existing asyncio code as
possible, and gets all the semantics correct for things like cancellation
and asyncio.wait_for.  An alternative approach would reimplement Task,
Event, etc using JavaScript Promise's.  That approach is very difficult to
get right when trying to implement cancellation (because it's not possible
to cancel a JavaScript Promise).

Signed-off-by: Damien George 
---
 ports/webassembly/Makefile                    |   3 +
 ports/webassembly/asyncio/__init__.py         |   9 +
 ports/webassembly/asyncio/core.py             | 249 ++++++++++++++++++
 ports/webassembly/objjsproxy.c                |  20 ++
 ports/webassembly/variants/manifest.py        |  24 ++
 .../webassembly/variants/pyscript/manifest.py |   2 +
 .../ports/webassembly/asyncio_create_task.mjs |  44 ++++
 .../webassembly/asyncio_create_task.mjs.exp   |  14 +
 tests/ports/webassembly/asyncio_sleep.mjs     |  25 ++
 tests/ports/webassembly/asyncio_sleep.mjs.exp |   6 +
 tests/run-tests.py                            |  11 +
 11 files changed, 407 insertions(+)
 create mode 100644 ports/webassembly/asyncio/__init__.py
 create mode 100644 ports/webassembly/asyncio/core.py
 create mode 100644 ports/webassembly/variants/manifest.py
 create mode 100644 tests/ports/webassembly/asyncio_create_task.mjs
 create mode 100644 tests/ports/webassembly/asyncio_create_task.mjs.exp
 create mode 100644 tests/ports/webassembly/asyncio_sleep.mjs
 create mode 100644 tests/ports/webassembly/asyncio_sleep.mjs.exp

diff --git a/ports/webassembly/Makefile b/ports/webassembly/Makefile
index d0a8aa99243ca..93b92ef583989 100644
--- a/ports/webassembly/Makefile
+++ b/ports/webassembly/Makefile
@@ -22,6 +22,9 @@ BUILD ?= build-$(VARIANT)
 include ../../py/mkenv.mk
 include $(VARIANT_DIR)/mpconfigvariant.mk
 
+# Use the default frozen manifest, variants may override this.
+FROZEN_MANIFEST ?= variants/manifest.py
+
 # Qstr definitions (must come before including py.mk).
 QSTR_DEFS = qstrdefsport.h
 
diff --git a/ports/webassembly/asyncio/__init__.py b/ports/webassembly/asyncio/__init__.py
new file mode 100644
index 0000000000000..ba1ca635148f4
--- /dev/null
+++ b/ports/webassembly/asyncio/__init__.py
@@ -0,0 +1,9 @@
+# MicroPython asyncio module, for use with webassembly port
+# MIT license; Copyright (c) 2024 Damien P. George
+
+from .core import *
+from .funcs import wait_for, wait_for_ms, gather
+from .event import Event
+from .lock import Lock
+
+__version__ = (3, 0, 0)
diff --git a/ports/webassembly/asyncio/core.py b/ports/webassembly/asyncio/core.py
new file mode 100644
index 0000000000000..a128bb6055058
--- /dev/null
+++ b/ports/webassembly/asyncio/core.py
@@ -0,0 +1,249 @@
+# MicroPython asyncio module, for use with webassembly port
+# MIT license; Copyright (c) 2019-2024 Damien P. George
+
+from time import ticks_ms as ticks, ticks_diff, ticks_add
+import sys, js, jsffi
+
+# Import TaskQueue and Task from built-in C code.
+from _asyncio import TaskQueue, Task
+
+
+################################################################################
+# Exceptions
+
+
+class CancelledError(BaseException):
+    pass
+
+
+class TimeoutError(Exception):
+    pass
+
+
+# Used when calling Loop.call_exception_handler.
+_exc_context = {"message": "Task exception wasn't retrieved", "exception": None, "future": None}
+
+
+################################################################################
+# Sleep functions
+
+
+# "Yield" once, then raise StopIteration
+class SingletonGenerator:
+    def __init__(self):
+        self.state = None
+        self.exc = StopIteration()
+
+    def __iter__(self):
+        return self
+
+    def __next__(self):
+        if self.state is not None:
+            _task_queue.push(cur_task, self.state)
+            self.state = None
+            return None
+        else:
+            self.exc.__traceback__ = None
+            raise self.exc
+
+
+# Pause task execution for the given time (integer in milliseconds, uPy extension)
+# Use a SingletonGenerator to do it without allocating on the heap
+def sleep_ms(t, sgen=SingletonGenerator()):
+    if cur_task is None:
+        # Support top-level asyncio.sleep, via a JavaScript Promise.
+        return jsffi.async_timeout_ms(t)
+    assert sgen.state is None
+    sgen.state = ticks_add(ticks(), max(0, t))
+    return sgen
+
+
+# Pause task execution for the given time (in seconds)
+def sleep(t):
+    return sleep_ms(int(t * 1000))
+
+
+################################################################################
+# Main run loop
+
+asyncio_timer = None
+
+
+class ThenableEvent:
+    def __init__(self, thenable):
+        self.result = None  # Result of the thenable
+        self.waiting = None  # Task waiting on completion of this thenable
+        thenable.then(self.set)
+
+    def set(self, value):
+        # Thenable/Promise is fulfilled, set result and schedule any waiting task.
+        self.result = value
+        if self.waiting:
+            _task_queue.push(self.waiting)
+            self.waiting = None
+            _schedule_run_iter(0)
+
+    def remove(self, task):
+        self.waiting = None
+
+    # async
+    def wait(self):
+        # Set the calling task as the task waiting on this thenable.
+        self.waiting = cur_task
+        # Set calling task's data to this object so it can be removed if needed.
+        cur_task.data = self
+        # Wait for the thenable to fulfill.
+        yield
+        # Return the result of the thenable.
+        return self.result
+
+
+# Ensure the awaitable is a task
+def _promote_to_task(aw):
+    return aw if isinstance(aw, Task) else create_task(aw)
+
+
+def _schedule_run_iter(dt):
+    global asyncio_timer
+    if asyncio_timer is not None:
+        js.clearTimeout(asyncio_timer)
+    asyncio_timer = js.setTimeout(_run_iter, dt)
+
+
+def _run_iter():
+    global cur_task
+    excs_all = (CancelledError, Exception)  # To prevent heap allocation in loop
+    excs_stop = (CancelledError, StopIteration)  # To prevent heap allocation in loop
+    while True:
+        # Wait until the head of _task_queue is ready to run
+        t = _task_queue.peek()
+        if t:
+            # A task waiting on _task_queue; "ph_key" is time to schedule task at
+            dt = max(0, ticks_diff(t.ph_key, ticks()))
+        else:
+            # No tasks can be woken so finished running
+            cur_task = None
+            return
+
+        if dt > 0:
+            # schedule to call again later
+            cur_task = None
+            _schedule_run_iter(dt)
+            return
+
+        # Get next task to run and continue it
+        t = _task_queue.pop()
+        cur_task = t
+        try:
+            # Continue running the coroutine, it's responsible for rescheduling itself
+            exc = t.data
+            if not exc:
+                t.coro.send(None)
+            else:
+                # If the task is finished and on the run queue and gets here, then it
+                # had an exception and was not await'ed on.  Throwing into it now will
+                # raise StopIteration and the code below will catch this and run the
+                # call_exception_handler function.
+                t.data = None
+                t.coro.throw(exc)
+        except excs_all as er:
+            # Check the task is not on any event queue
+            assert t.data is None
+            # This task is done.
+            if t.state:
+                # Task was running but is now finished.
+                waiting = False
+                if t.state is True:
+                    # "None" indicates that the task is complete and not await'ed on (yet).
+                    t.state = None
+                elif callable(t.state):
+                    # The task has a callback registered to be called on completion.
+                    t.state(t, er)
+                    t.state = False
+                    waiting = True
+                else:
+                    # Schedule any other tasks waiting on the completion of this task.
+                    while t.state.peek():
+                        _task_queue.push(t.state.pop())
+                        waiting = True
+                    # "False" indicates that the task is complete and has been await'ed on.
+                    t.state = False
+                if not waiting and not isinstance(er, excs_stop):
+                    # An exception ended this detached task, so queue it for later
+                    # execution to handle the uncaught exception if no other task retrieves
+                    # the exception in the meantime (this is handled by Task.throw).
+                    _task_queue.push(t)
+                # Save return value of coro to pass up to caller.
+                t.data = er
+            elif t.state is None:
+                # Task is already finished and nothing await'ed on the task,
+                # so call the exception handler.
+
+                # Save exception raised by the coro for later use.
+                t.data = exc
+
+                # Create exception context and call the exception handler.
+                _exc_context["exception"] = exc
+                _exc_context["future"] = t
+                Loop.call_exception_handler(_exc_context)
+
+
+# Create and schedule a new task from a coroutine.
+def create_task(coro):
+    if not hasattr(coro, "send"):
+        raise TypeError("coroutine expected")
+    t = Task(coro, globals())
+    _task_queue.push(t)
+    _schedule_run_iter(0)
+    return t
+
+
+################################################################################
+# Event loop wrapper
+
+
+cur_task = None
+
+
+class Loop:
+    _exc_handler = None
+
+    def create_task(coro):
+        return create_task(coro)
+
+    def close():
+        pass
+
+    def set_exception_handler(handler):
+        Loop._exc_handler = handler
+
+    def get_exception_handler():
+        return Loop._exc_handler
+
+    def default_exception_handler(loop, context):
+        print(context["message"], file=sys.stderr)
+        print("future:", context["future"], "coro=", context["future"].coro, file=sys.stderr)
+        sys.print_exception(context["exception"], sys.stderr)
+
+    def call_exception_handler(context):
+        (Loop._exc_handler or Loop.default_exception_handler)(Loop, context)
+
+
+def get_event_loop():
+    return Loop
+
+
+def current_task():
+    if cur_task is None:
+        raise RuntimeError("no running event loop")
+    return cur_task
+
+
+def new_event_loop():
+    global _task_queue
+    _task_queue = TaskQueue()  # TaskQueue of Task instances.
+    return Loop
+
+
+# Initialise default event loop.
+new_event_loop()
diff --git a/ports/webassembly/objjsproxy.c b/ports/webassembly/objjsproxy.c
index 65c806536dea2..15fbb57523fc7 100644
--- a/ports/webassembly/objjsproxy.c
+++ b/ports/webassembly/objjsproxy.c
@@ -474,9 +474,29 @@ static mp_obj_t jsproxy_new_gen(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) {
 
 /******************************************************************************/
 
+#if MICROPY_PY_ASYNCIO
+extern mp_obj_t mp_asyncio_context;
+#endif
+
 static mp_obj_t jsproxy_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) {
     mp_obj_jsproxy_t *self = MP_OBJ_TO_PTR(self_in);
     if (has_attr(self->ref, "then")) {
+        #if MICROPY_PY_ASYNCIO
+        // When asyncio is running and the caller here is a task, wrap the JavaScript
+        // thenable in a ThenableEvent, and get the task to wait on that event.  This
+        // decouples the task from the thenable and allows cancelling the task.
+        if (mp_asyncio_context != MP_OBJ_NULL) {
+            mp_obj_t cur_task = mp_obj_dict_get(mp_asyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR_cur_task));
+            if (cur_task != mp_const_none) {
+                mp_obj_t thenable_event_class = mp_obj_dict_get(mp_asyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR_ThenableEvent));
+                mp_obj_t thenable_event = mp_call_function_1(thenable_event_class, self_in);
+                mp_obj_t dest[2];
+                mp_load_method(thenable_event, MP_QSTR_wait, dest);
+                mp_obj_t wait_gen = mp_call_method_n_kw(0, 0, dest);
+                return mp_getiter(wait_gen, iter_buf);
+            }
+        }
+        #endif
         return jsproxy_new_gen(self_in, iter_buf);
     } else {
         return jsproxy_new_it(self_in, iter_buf);
diff --git a/ports/webassembly/variants/manifest.py b/ports/webassembly/variants/manifest.py
new file mode 100644
index 0000000000000..b2ee8cd640d68
--- /dev/null
+++ b/ports/webassembly/variants/manifest.py
@@ -0,0 +1,24 @@
+# The asyncio package is built from the standard implementation but with the
+# core scheduler replaced with a custom scheduler that uses the JavaScript
+# runtime (with setTimeout an Promise's) to contrtol the scheduling.
+
+package(
+    "asyncio",
+    (
+        "event.py",
+        "funcs.py",
+        "lock.py",
+    ),
+    base_path="$(MPY_DIR)/extmod",
+    opt=3,
+)
+
+package(
+    "asyncio",
+    (
+        "__init__.py",
+        "core.py",
+    ),
+    base_path="$(PORT_DIR)",
+    opt=3,
+)
diff --git a/ports/webassembly/variants/pyscript/manifest.py b/ports/webassembly/variants/pyscript/manifest.py
index 0646e1d897f0c..db088e70d0ccd 100644
--- a/ports/webassembly/variants/pyscript/manifest.py
+++ b/ports/webassembly/variants/pyscript/manifest.py
@@ -1,3 +1,5 @@
+include("$(PORT_DIR)/variants/manifest.py")
+
 require("abc")
 require("base64")
 require("collections")
diff --git a/tests/ports/webassembly/asyncio_create_task.mjs b/tests/ports/webassembly/asyncio_create_task.mjs
new file mode 100644
index 0000000000000..e388ade4f1228
--- /dev/null
+++ b/tests/ports/webassembly/asyncio_create_task.mjs
@@ -0,0 +1,44 @@
+// Test asyncio.create_task(), and tasks waiting on a Promise.
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+globalThis.p0 = new Promise((resolve, reject) => {
+    resolve(123);
+});
+
+globalThis.p1 = new Promise((resolve, reject) => {
+    setTimeout(() => {
+        console.log("setTimeout resolved");
+        resolve(456);
+    }, 200);
+});
+
+mp.runPython(`
+import js
+import asyncio
+
+async def task(id, promise):
+    print("task start", id)
+    print("task await", id, await promise)
+    print("task await", id, await promise)
+    print("task end", id)
+
+print("start")
+t1 = asyncio.create_task(task(1, js.p0))
+t2 = asyncio.create_task(task(2, js.p1))
+print("t1", t1.done(), t2.done())
+print("end")
+`);
+
+// Wait for p1 to fulfill so t2 can continue.
+await globalThis.p1;
+
+// Wait a little longer so t2 can complete.
+await new Promise((resolve, reject) => {
+    setTimeout(resolve, 10);
+});
+
+mp.runPython(`
+print("restart")
+print("t1", t1.done(), t2.done())
+`);
diff --git a/tests/ports/webassembly/asyncio_create_task.mjs.exp b/tests/ports/webassembly/asyncio_create_task.mjs.exp
new file mode 100644
index 0000000000000..c1958bba5930b
--- /dev/null
+++ b/tests/ports/webassembly/asyncio_create_task.mjs.exp
@@ -0,0 +1,14 @@
+start
+t1 False False
+end
+task start 1
+task start 2
+task await 1 123
+task await 1 123
+task end 1
+setTimeout resolved
+task await 2 456
+task await 2 456
+task end 2
+restart
+t1 True True
diff --git a/tests/ports/webassembly/asyncio_sleep.mjs b/tests/ports/webassembly/asyncio_sleep.mjs
new file mode 100644
index 0000000000000..74d22ee1f854a
--- /dev/null
+++ b/tests/ports/webassembly/asyncio_sleep.mjs
@@ -0,0 +1,25 @@
+// Test asyncio.sleep(), both at the top level and within a task.
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+await mp.runPythonAsync(`
+import time
+import asyncio
+
+print("main start")
+t0 = time.time()
+await asyncio.sleep(0.25)
+dt = time.time() - t0
+print(0.2 <= dt <= 0.3)
+
+async def task():
+    print("task start")
+    t0 = time.time()
+    await asyncio.sleep(0.25)
+    dt = time.time() - t0
+    print(0.2 <= dt <= 0.3)
+    print("task end")
+
+asyncio.create_task(task())
+print("main end")
+`);
diff --git a/tests/ports/webassembly/asyncio_sleep.mjs.exp b/tests/ports/webassembly/asyncio_sleep.mjs.exp
new file mode 100644
index 0000000000000..619ba175f6c00
--- /dev/null
+++ b/tests/ports/webassembly/asyncio_sleep.mjs.exp
@@ -0,0 +1,6 @@
+main start
+True
+main end
+task start
+True
+task end
diff --git a/tests/run-tests.py b/tests/run-tests.py
index 4f55cdd39842e..8acdcd2b36204 100755
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -681,6 +681,17 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1):
         elif args.target == "webassembly":
             skip_tests.add("basics/string_format_modulo.py")  # can't print nulls to stdout
             skip_tests.add("basics/string_strip.py")  # can't print nulls to stdout
+            skip_tests.add("extmod/asyncio_basic2.py")
+            skip_tests.add("extmod/asyncio_cancel_self.py")
+            skip_tests.add("extmod/asyncio_current_task.py")
+            skip_tests.add("extmod/asyncio_exception.py")
+            skip_tests.add("extmod/asyncio_gather_finished_early.py")
+            skip_tests.add("extmod/asyncio_get_event_loop.py")
+            skip_tests.add("extmod/asyncio_heaplock.py")
+            skip_tests.add("extmod/asyncio_loop_stop.py")
+            skip_tests.add("extmod/asyncio_new_event_loop.py")
+            skip_tests.add("extmod/asyncio_threadsafeflag.py")
+            skip_tests.add("extmod/asyncio_wait_for_fwd.py")
             skip_tests.add("extmod/binascii_a2b_base64.py")
             skip_tests.add("extmod/re_stack_overflow.py")
             skip_tests.add("extmod/time_res.py")

From 49af8cad49415521813bda6d756dbe50a125f472 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Thu, 18 Apr 2024 16:36:34 +1000
Subject: [PATCH 342/408] webassembly/api: Inject asyncio.run if needed by the
 script.

This allows a simple way to run the existing asyncio tests under the
webassembly port, which doesn't support `asyncio.run()`.

Signed-off-by: Damien George 
---
 ports/webassembly/api.js | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/ports/webassembly/api.js b/ports/webassembly/api.js
index 2f2ad95221ccd..2be82e890705f 100644
--- a/ports/webassembly/api.js
+++ b/ports/webassembly/api.js
@@ -228,6 +228,16 @@ async function runCLI() {
             }
         });
     } else {
+        // If the script to run ends with a running of the asyncio main loop, then inject
+        // a simple `asyncio.run` hook that starts the main task.  This is primarily to
+        // support running the standard asyncio tests.
+        if (contents.endsWith("asyncio.run(main())\n")) {
+            const asyncio = mp.pyimport("asyncio");
+            asyncio.run = async (task) => {
+                await asyncio.create_task(task);
+            };
+        }
+
         try {
             mp.runPython(contents);
         } catch (error) {

From 7b050b366b7dacfb43779c51702a892d8f1873d0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=2E=20Neusch=C3=A4fer?= 
Date: Sun, 2 Apr 2023 19:58:42 +0200
Subject: [PATCH 343/408] py/nlrthumb: Make non-Thumb2 long-jump workaround
 opt-in.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Although the original motivation given for the workaround[1] is correct,
nlr.o and nlrthumb.o are linked with a small enough distance that the
problem does not occur, and the workaround isn't necessary. The distance
between the b instruction and its target (nlr_push_tail) is just 64
bytes[2], well within the ±2046 byte range addressable by an
unconditional branch instruction in Thumb mode.

The workaround induces a relocation in the text section (textrel), which
isn't supported everywhere, notably not on musl-libc[3], where it causes
a crash on start-up. With the workaround removed, micropython works on an
ARMv5T Linux system built with musl-libc.

This commit changes nlrthumb.c to use a direct jump by default, but
leaves the long jump workaround as an option for those cases where it's
actually needed.

[1]: commit dd376a239dc4f47b0ee7866810fcda151f3cf6dd

Author: Damien George 
Date:   Fri Sep 1 15:25:29 2017 +1000

    py/nlrthumb: Get working again on standard Thumb arch (ie not Thumb2).

    "b" on Thumb might not be long enough for the jump to nlr_push_tail so
    it must be done indirectly.

[2]: Excerpt from objdump -d micropython:

000095c4 :
    95c4:       b510            push    {r4, lr}
    95c6:       0004            movs    r4, r0
    95c8:       f02d fd42       bl      37050 
    95cc:       6943            ldr     r3, [r0, #20]
    95ce:       6023            str     r3, [r4, #0]
    95d0:       6144            str     r4, [r0, #20]
    95d2:       2000            movs    r0, #0
    95d4:       bd10            pop     {r4, pc}

000095d6 :
    95d6:       b510            push    {r4, lr}
    95d8:       f02d fd3a       bl      37050 
    95dc:       6943            ldr     r3, [r0, #20]
    95de:       681b            ldr     r3, [r3, #0]
    95e0:       6143            str     r3, [r0, #20]
    95e2:       bd10            pop     {r4, pc}

000095e4 :
    95e4:       60c4            str     r4, [r0, #12]
    95e6:       6105            str     r5, [r0, #16]
    95e8:       6146            str     r6, [r0, #20]
    95ea:       6187            str     r7, [r0, #24]
    95ec:       4641            mov     r1, r8
    95ee:       61c1            str     r1, [r0, #28]
    95f0:       4649            mov     r1, r9
    95f2:       6201            str     r1, [r0, #32]
    95f4:       4651            mov     r1, sl
    95f6:       6241            str     r1, [r0, #36]   @ 0x24
    95f8:       4659            mov     r1, fp
    95fa:       6281            str     r1, [r0, #40]   @ 0x28
    95fc:       4669            mov     r1, sp
    95fe:       62c1            str     r1, [r0, #44]   @ 0x2c
    9600:       4671            mov     r1, lr
    9602:       6081            str     r1, [r0, #8]
    9604:       e7de            b.n     95c4 

[3]: https://www.openwall.com/lists/musl/2020/09/25/4

Signed-off-by: J. Neuschäfer 
---
 py/mpconfig.h |  6 ++++++
 py/nlrthumb.c | 10 +++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/py/mpconfig.h b/py/mpconfig.h
index af2480266bcab..1aa3e06994d3f 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -587,6 +587,12 @@
 /*****************************************************************************/
 /* Python internal features                                                  */
 
+// Use a special long jump in nlrthumb.c, which may be necessary if nlr.o and
+// nlrthumb.o are linked far apart from each other.
+#ifndef MICROPY_NLR_THUMB_USE_LONG_JUMP
+#define MICROPY_NLR_THUMB_USE_LONG_JUMP (0)
+#endif
+
 // Whether to enable import of external modules
 // When disabled, only importing of built-in modules is supported
 // When enabled, a port must implement mp_import_stat (among other things)
diff --git a/py/nlrthumb.c b/py/nlrthumb.c
index a22c5df5b9418..e7b24f242bc52 100644
--- a/py/nlrthumb.c
+++ b/py/nlrthumb.c
@@ -38,6 +38,14 @@
 
 __attribute__((naked)) unsigned int nlr_push(nlr_buf_t *nlr) {
 
+    // If you get a linker error here, indicating that a relocation doesn't
+    // fit, try the following (in that order):
+    //
+    // 1. Ensure that nlr.o nlrthumb.o are linked closely together, i.e.
+    //    there aren't too many other files between them in the linker list
+    //    (PY_CORE_O_BASENAME in py/py.mk)
+    // 2. Set -DMICROPY_NLR_THUMB_USE_LONG_JUMP=1 during the build
+    //
     __asm volatile (
         "str    r4, [r0, #12]       \n" // store r4 into nlr_buf
         "str    r5, [r0, #16]       \n" // store r5 into nlr_buf
@@ -71,7 +79,7 @@ __attribute__((naked)) unsigned int nlr_push(nlr_buf_t *nlr) {
         "str    lr, [r0, #8]        \n" // store lr into nlr_buf
         #endif
 
-        #if !defined(__thumb2__)
+        #if MICROPY_NLR_THUMB_USE_LONG_JUMP
         "ldr    r1, nlr_push_tail_var \n"
         "bx     r1                  \n" // do the rest in C
         ".align 2                   \n"

From e60e8079a7e1f6edd308e2e8981096e42ec6a78c Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Fri, 26 Apr 2024 11:15:59 +1000
Subject: [PATCH 344/408] nrf/mpconfigport: Enable
 MICROPY_NLR_THUMB_USE_LONG_JUMP on nRF51xx.

Signed-off-by: Damien George 
---
 ports/nrf/mpconfigport.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/ports/nrf/mpconfigport.h b/ports/nrf/mpconfigport.h
index 37fbdf1eb3b29..6e92fa876ef4b 100644
--- a/ports/nrf/mpconfigport.h
+++ b/ports/nrf/mpconfigport.h
@@ -59,6 +59,12 @@
 
 // options to control how MicroPython is built
 
+// Due to the use of LTO and the unknown distance between nlr.o and nlrthumb.o code,
+// MCUs using the Thumb 1 instruction set must enable this NLR long jump feature.
+#if defined(NRF51822)
+#define MICROPY_NLR_THUMB_USE_LONG_JUMP    (1)
+#endif
+
 #ifndef MICROPY_VFS
 #define MICROPY_VFS                        (CORE_FEAT)
 #endif

From b1ac266bb5cd0fcfa53539cb3230e7b3f323a09b Mon Sep 17 00:00:00 2001
From: Matt Trentini 
Date: Mon, 29 Apr 2024 09:18:03 +1000
Subject: [PATCH 345/408] docs/develop/optimizations: Fix typo identified in
 issue 14391.

Signed-off-by: Matt Trentini 
---
 docs/develop/optimizations.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/docs/develop/optimizations.rst b/docs/develop/optimizations.rst
index 7f2c8cbe7282c..533dd64116f03 100644
--- a/docs/develop/optimizations.rst
+++ b/docs/develop/optimizations.rst
@@ -33,7 +33,7 @@ Variables
 MicroPython processes local and global variables differently. Global variables
 are stored and looked up from a global dictionary that is allocated on the heap
 (note that each module has its own separate dict, so separate namespace).
-Local variables on the other hand are are stored on the Python value stack, which may
+Local variables on the other hand are stored on the Python value stack, which may
 live on the C stack or on the heap.  They are accessed directly by their offset
 within the Python stack, which is more efficient than a global lookup in a dict.
 

From b896fa9b1f5f17d9f92901dd9a75a0efdec39a92 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Sun, 28 Apr 2024 15:37:40 +1000
Subject: [PATCH 346/408] stm32/boards/LEGO_HUB_NO6: Write key after writing
 elements.

In case there is a power failure after during this operation, the key must
be the last thing that is written, to indicate valid data.

Signed-off-by: Damien George 
---
 ports/stm32/boards/LEGO_HUB_NO6/board_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ports/stm32/boards/LEGO_HUB_NO6/board_init.c b/ports/stm32/boards/LEGO_HUB_NO6/board_init.c
index 5e4e7791b50d3..3a785859af2f4 100644
--- a/ports/stm32/boards/LEGO_HUB_NO6/board_init.c
+++ b/ports/stm32/boards/LEGO_HUB_NO6/board_init.c
@@ -198,9 +198,9 @@ void board_mboot_state_change(int state, uint32_t arg) {
         // The FS-load update is about to start.  Program the update key and FS-load elements
         // into the flash so they can be retrieved if there is a power failure during the update.
         mp_spiflash_erase_block(MBOOT_SPIFLASH_SPIFLASH, SPIFLASH_UPDATE_KEY_ADDR);
+        mp_spiflash_write(MBOOT_SPIFLASH_SPIFLASH, SPIFLASH_UPDATE_KEY_ADDR + 4, ELEM_DATA_SIZE, ELEM_DATA_START);
         uint32_t key = SPIFLASH_UPDATE_KEY_VALUE;
         mp_spiflash_write(MBOOT_SPIFLASH_SPIFLASH, SPIFLASH_UPDATE_KEY_ADDR, 4, (const uint8_t *)&key);
-        mp_spiflash_write(MBOOT_SPIFLASH_SPIFLASH, SPIFLASH_UPDATE_KEY_ADDR + 4, ELEM_DATA_SIZE, ELEM_DATA_START);
     } else if (state == MBOOT_STATE_FSLOAD_END) {
         // The FS-load update completed (either with success or failure), so erase the
         // update key and write the result of the FS-load operation into flash.

From 64f28dc1eb542c90e38e89cd55b5452ed59290d0 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Sun, 28 Apr 2024 15:39:00 +1000
Subject: [PATCH 347/408] stm32/boards/LEGO_HUB_NO7: Add robust update logic to
 mboot.

Following change in 899592ac341ed9f10ee554424f964f6880fc8c48

Signed-off-by: Damien George 
---
 ports/stm32/boards/LEGO_HUB_NO7/board_init.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/ports/stm32/boards/LEGO_HUB_NO7/board_init.c b/ports/stm32/boards/LEGO_HUB_NO7/board_init.c
index 7b155b1c3cea8..4f7b36c295437 100644
--- a/ports/stm32/boards/LEGO_HUB_NO7/board_init.c
+++ b/ports/stm32/boards/LEGO_HUB_NO7/board_init.c
@@ -199,7 +199,14 @@ int board_mboot_get_reset_mode(uint32_t *initial_r0) {
 }
 
 void board_mboot_state_change(int state, uint32_t arg) {
-    if (state == MBOOT_STATE_FSLOAD_END) {
+    if (state == MBOOT_STATE_FSLOAD_START) {
+        // The FS-load update is about to start.  Program the update key and FS-load elements
+        // into the flash so they can be retrieved if there is a power failure during the update.
+        mp_spiflash_erase_block(MBOOT_SPIFLASH_SPIFLASH, SPIFLASH_UPDATE_KEY_ADDR);
+        mp_spiflash_write(MBOOT_SPIFLASH_SPIFLASH, SPIFLASH_UPDATE_KEY_ADDR + 4, ELEM_DATA_SIZE, ELEM_DATA_START);
+        uint32_t key = SPIFLASH_UPDATE_KEY_VALUE;
+        mp_spiflash_write(MBOOT_SPIFLASH_SPIFLASH, SPIFLASH_UPDATE_KEY_ADDR, 4, (const uint8_t *)&key);
+    } else if (state == MBOOT_STATE_FSLOAD_END) {
         // The FS-load update completed (either with success or failure), so erase the
         // update key and write the result of the FS-load operation into flash.
         mp_spiflash_erase_block(MBOOT_SPIFLASH_SPIFLASH, SPIFLASH_UPDATE_KEY_ADDR);

From d3fe0a06e8799ef95716aaada0a95505aebab48c Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Sun, 28 Apr 2024 15:35:38 +1000
Subject: [PATCH 348/408] stm32/flash: Fix writing final words to flash on H5
 and H7 MCUs.

The calculations `num_word32 / 4` and `num_word32 / 8` were rounding down
the number of words to program to flash, and therefore possibly truncating
the data (eg mboot could miss writing the final few words of the firmware).

That's fixed in this commit by adding extra logic to program any remaining
words.  And the logic for H5 and H7 is combined.

Signed-off-by: Damien George 
---
 ports/stm32/flash.c | 47 ++++++++++++++++++++++++++++-----------------
 1 file changed, 29 insertions(+), 18 deletions(-)

diff --git a/ports/stm32/flash.c b/ports/stm32/flash.c
index 10c5f296a28c8..7668b53a43b58 100644
--- a/ports/stm32/flash.c
+++ b/ports/stm32/flash.c
@@ -24,6 +24,7 @@
  * THE SOFTWARE.
  */
 
+#include 
 #include "py/mpconfig.h"
 #include "py/misc.h"
 #include "py/mphal.h"
@@ -450,28 +451,38 @@ int flash_write(uint32_t flash_dest, const uint32_t *src, uint32_t num_word32) {
         #endif
     }
 
-    #elif defined(STM32H5)
+    #elif defined(STM32H5) || defined(STM32H7)
 
-    // program the flash 128 bits (4 words) at a time
-    for (int i = 0; i < num_word32 / 4; i++) {
-        status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_QUADWORD, flash_dest, (uint64_t)(uint32_t)src);
-        if (status != HAL_OK) {
-            break;
-        }
-        flash_dest += 16;
-        src += 4;
-    }
+    #if defined(STM32H5)
+    static const unsigned int WORD32_PER_FLASHWORD = 4;
+    static const unsigned int PROGRAM_TYPE = FLASH_TYPEPROGRAM_QUADWORD;
+    #else
+    static const unsigned int WORD32_PER_FLASHWORD = FLASH_NB_32BITWORD_IN_FLASHWORD;
+    static const unsigned int PROGRAM_TYPE = FLASH_TYPEPROGRAM_FLASHWORD;
+    #endif
 
-    #elif defined(STM32H7)
+    if (flash_dest % (WORD32_PER_FLASHWORD * sizeof(uint32_t))) {
+        // The flash_dest address is not aligned correctly.
+        status = HAL_ERROR;
+    } else {
+        // Program the flash WORD32_PER_FLASHWORD words at a time.
+        for (int i = 0; i < num_word32 / WORD32_PER_FLASHWORD; i++) {
+            status = HAL_FLASH_Program(PROGRAM_TYPE, flash_dest, (uint32_t)src);
+            if (status != HAL_OK) {
+                break;
+            }
+            flash_dest += WORD32_PER_FLASHWORD * sizeof(uint32_t);
+            src += WORD32_PER_FLASHWORD;
+        }
 
-    // program the flash 256 bits at a time
-    for (int i = 0; i < num_word32 / 8; i++) {
-        status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_FLASHWORD, flash_dest, (uint64_t)(uint32_t)src);
-        if (status != HAL_OK) {
-            break;
+        // Program any remaining words from src.
+        // Additional bytes beyond that are programmed to 0xff.
+        if (num_word32 % WORD32_PER_FLASHWORD) {
+            uint32_t buf[WORD32_PER_FLASHWORD];
+            memset(buf, 0xff, sizeof(buf));
+            memcpy(buf, src, (num_word32 % WORD32_PER_FLASHWORD) * sizeof(uint32_t));
+            status = HAL_FLASH_Program(PROGRAM_TYPE, flash_dest, (uint32_t)buf);
         }
-        flash_dest += 32;
-        src += 8;
     }
 
     #else

From a7d34b6f7c48cd5920ae52b2e6fb35cc196a606b Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Sun, 28 Apr 2024 15:36:08 +1000
Subject: [PATCH 349/408] stm32/mboot: Buffer the correct amount of bytes for a
 flash write.

Different MCUs have different requirements for the minimum number of bytes
that can be written to internal flash.

Signed-off-by: Damien George 
---
 ports/stm32/mboot/pack.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/ports/stm32/mboot/pack.c b/ports/stm32/mboot/pack.c
index 7d4adf4780d5b..719cfce3202c7 100644
--- a/ports/stm32/mboot/pack.c
+++ b/ports/stm32/mboot/pack.c
@@ -42,6 +42,17 @@
 #define MBOOT_PACK_GZIP_BUFFER_SIZE (2048)
 #endif
 
+// Configure the minimum number of bytes that can be written at once to the internal flash.
+#if defined(STM32H5)
+#define FLASH_MIN_WRITE_BYTES (16)
+#elif defined(STM32H7)
+#define FLASH_MIN_WRITE_BYTES (4 * FLASH_NB_32BITWORD_IN_FLASHWORD)
+#else
+// This default is 8 bytes due to STM32WB MCUs requiring that a double-word write
+// to flash can only be done once (due to ECC).
+#define FLASH_MIN_WRITE_BYTES (8)
+#endif
+
 // State to manage automatic flash erasure.
 static uint32_t erased_base_addr;
 static uint32_t erased_top_addr;
@@ -57,9 +68,8 @@ static uint8_t decrypted_buf[MBOOT_PACK_DFU_CHUNK_BUF_SIZE] __attribute__((align
 static uint8_t uncompressed_buf[MBOOT_PACK_GZIP_BUFFER_SIZE] __attribute__((aligned(8)));
 
 // Buffer to hold the start of the firmware, which is only written once the
-// entire firmware is validated.  This is 8 bytes due to STM32WB MCUs requiring
-// that a double-word write to flash can only be done once (due to ECC).
-static uint8_t firmware_head[8] __attribute__((aligned(8)));
+// entire firmware is validated.
+static uint8_t firmware_head[FLASH_MIN_WRITE_BYTES] __attribute__((aligned(FLASH_MIN_WRITE_BYTES)));
 
 // Flag to indicate that firmware_head contains valid data.
 static bool firmware_head_valid;
@@ -100,7 +110,7 @@ static int mboot_pack_commit_chunk(uint32_t addr, uint8_t *data, size_t len) {
         return ret;
     }
 
-    if (addr == APPLICATION_ADDR) {
+    if (addr == APPLICATION_ADDR && len >= sizeof(firmware_head)) {
         // Don't write the very start of the firmware, just copy it into a temporary buffer.
         // It will be written only if the full firmware passes the checksum/signature.
         memcpy(firmware_head, data, sizeof(firmware_head));

From a521df27dc483c5376ef7e348aa9fbbd0c4e67a9 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Thu, 28 Mar 2024 13:53:24 +1100
Subject: [PATCH 350/408] stm32/i2c: Fix clock enable for I2C4 on STM32F7 MCUs.

This was broken by 5aec051f9f0e1be9750ca4f08478275f298087a3 when adding
support for I2C4 on H7 MCUs.

Signed-off-by: Damien George 
---
 ports/stm32/i2c.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/ports/stm32/i2c.c b/ports/stm32/i2c.c
index 9d128acc3cdd2..a1fde7e6ba114 100644
--- a/ports/stm32/i2c.c
+++ b/ports/stm32/i2c.c
@@ -312,19 +312,15 @@ int i2c_init(i2c_t *i2c, mp_hal_pin_obj_t scl, mp_hal_pin_obj_t sda, uint32_t fr
     // Enable I2C peripheral clock
     volatile uint32_t tmp;
     (void)tmp;
-    switch (i2c_id) {
-        case 0:
-        case 1:
-        case 2:
-            RCC->APB1ENR |= RCC_APB1ENR_I2C1EN << i2c_id;
-            tmp = RCC->APB1ENR; // delay after RCC clock enable
-            break;
-        #if defined(STM32H7)
-        case 3:
-            RCC->APB4ENR |= RCC_APB4ENR_I2C4EN;
-            tmp = RCC->APB4ENR; // delay after RCC clock enable
-            break;
-        #endif
+    #if defined(STM32H7)
+    if (i2c_id == 3) {
+        RCC->APB4ENR |= RCC_APB4ENR_I2C4EN;
+        tmp = RCC->APB4ENR; // delay after RCC clock enable
+    } else
+    #endif
+    {
+        RCC->APB1ENR |= RCC_APB1ENR_I2C1EN << i2c_id;
+        tmp = RCC->APB1ENR; // delay after RCC clock enable
     }
 
     // Initialise I2C peripheral

From 9681a66c6b79a5f4721c74b756256336c47c9879 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Thu, 2 May 2024 16:29:39 +1000
Subject: [PATCH 351/408] webassembly/api: Fix importing micropython.mjs module
 from node REPL.

Fixes issue #14363.

Signed-off-by: Damien George 
---
 ports/webassembly/api.js | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/ports/webassembly/api.js b/ports/webassembly/api.js
index 2be82e890705f..f3245451e4ad0 100644
--- a/ports/webassembly/api.js
+++ b/ports/webassembly/api.js
@@ -262,7 +262,7 @@ if (
     typeof process.versions === "object" &&
     typeof process.versions.node === "string"
 ) {
-    // Check if this module is ron from the command line.
+    // Check if this module is run from the command line via `node micropython.mjs`.
     //
     // See https://stackoverflow.com/questions/6398196/detect-if-called-through-require-or-directly-by-command-line/66309132#66309132
     //
@@ -270,14 +270,17 @@ if (
     // - `resolve()` is used to handle symlinks
     // - `includes()` is used to handle cases where the file extension was omitted when passed to node
 
-    const path = await import("path");
-    const url = await import("url");
+    if (process.argv.length > 1) {
+        const path = await import("path");
+        const url = await import("url");
 
-    const pathToThisFile = path.resolve(url.fileURLToPath(import.meta.url));
-    const pathPassedToNode = path.resolve(process.argv[1]);
-    const isThisFileBeingRunViaCLI = pathToThisFile.includes(pathPassedToNode);
+        const pathToThisFile = path.resolve(url.fileURLToPath(import.meta.url));
+        const pathPassedToNode = path.resolve(process.argv[1]);
+        const isThisFileBeingRunViaCLI =
+            pathToThisFile.includes(pathPassedToNode);
 
-    if (isThisFileBeingRunViaCLI) {
-        runCLI();
+        if (isThisFileBeingRunViaCLI) {
+            runCLI();
+        }
     }
 }

From 9da63a343e08c2a453ff32801bb0d9545e538497 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Mon, 6 May 2024 12:26:20 +1000
Subject: [PATCH 352/408] webassembly/proxy_c: Reject promises with a
 PythonError instance.

The `reason` in a rejected promise should be an instance of `Error`.  That
leads to better error messages on the JavaScript side.

Signed-off-by: Damien George 
---
 ports/webassembly/proxy_c.c                           | 11 +++++++++--
 tests/ports/webassembly/run_python_async_error.mjs    | 11 +++++++++++
 .../ports/webassembly/run_python_async_error.mjs.exp  |  5 +++++
 3 files changed, 25 insertions(+), 2 deletions(-)
 create mode 100644 tests/ports/webassembly/run_python_async_error.mjs
 create mode 100644 tests/ports/webassembly/run_python_async_error.mjs.exp

diff --git a/ports/webassembly/proxy_c.c b/ports/webassembly/proxy_c.c
index ebf670b56ec5b..9b32b6450a489 100644
--- a/ports/webassembly/proxy_c.c
+++ b/ports/webassembly/proxy_c.c
@@ -297,7 +297,14 @@ EM_JS(void, js_then_resolve, (uint32_t * ret_value, uint32_t * resolve, uint32_t
 });
 
 EM_JS(void, js_then_reject, (uint32_t * ret_value, uint32_t * resolve, uint32_t * reject), {
-    const ret_value_js = proxy_convert_mp_to_js_obj_jsside(ret_value);
+    // The ret_value object should be a Python exception.  Convert it to a
+    // JavaScript PythonError and pass it as the reason to reject the promise.
+    let ret_value_js;
+    try {
+        ret_value_js = proxy_convert_mp_to_js_obj_jsside(ret_value);
+    } catch(error) {
+        ret_value_js = error;
+    }
     const resolve_js = proxy_convert_mp_to_js_obj_jsside(resolve);
     const reject_js = proxy_convert_mp_to_js_obj_jsside(reject);
     reject_js(ret_value_js);
@@ -359,7 +366,7 @@ static mp_obj_t proxy_resume_execute(mp_obj_t self_in, mp_obj_t send_value, mp_o
     } else { // ret_kind == MP_VM_RETURN_EXCEPTION;
         // Pass the exception through as an object to reject the promise (don't raise/throw it).
         uint32_t out_ret_value[PVN];
-        proxy_convert_mp_to_js_obj_cside(ret_value, out_ret_value);
+        proxy_convert_mp_to_js_exc_cside(ret_value, out_ret_value);
         js_then_reject(out_ret_value, out_resolve, out_reject);
         return mp_const_none;
     }
diff --git a/tests/ports/webassembly/run_python_async_error.mjs b/tests/ports/webassembly/run_python_async_error.mjs
new file mode 100644
index 0000000000000..ce4db0ff07880
--- /dev/null
+++ b/tests/ports/webassembly/run_python_async_error.mjs
@@ -0,0 +1,11 @@
+// Test raising an exception in async Python code running in runPythonAsync,
+// that the JavaScript-level promise is rejected with a PythonError.
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+try {
+    await mp.runPythonAsync("await fail");
+} catch (error) {
+    console.log(error.name, error.type);
+    console.log(error.message);
+}
diff --git a/tests/ports/webassembly/run_python_async_error.mjs.exp b/tests/ports/webassembly/run_python_async_error.mjs.exp
new file mode 100644
index 0000000000000..c77de4bb345fe
--- /dev/null
+++ b/tests/ports/webassembly/run_python_async_error.mjs.exp
@@ -0,0 +1,5 @@
+PythonError NameError
+Traceback (most recent call last):
+  File "", line 1, in 
+NameError: name 'fail' isn't defined
+

From 50b43fec1a01710a08e1b56c1cf312877457bfa1 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Mon, 6 May 2024 12:33:16 +1000
Subject: [PATCH 353/408] webassembly/proxy_c: Only proxy across resolve/reject
 funs when needed.

To improve efficiency.

Signed-off-by: Damien George 
---
 ports/webassembly/proxy_c.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/ports/webassembly/proxy_c.c b/ports/webassembly/proxy_c.c
index 9b32b6450a489..ade9d36dee847 100644
--- a/ports/webassembly/proxy_c.c
+++ b/ports/webassembly/proxy_c.c
@@ -289,14 +289,13 @@ void proxy_c_to_js_get_dict(uint32_t c_ref, uint32_t *out) {
 
 static const mp_obj_fun_builtin_var_t resume_obj;
 
-EM_JS(void, js_then_resolve, (uint32_t * ret_value, uint32_t * resolve, uint32_t * reject), {
+EM_JS(void, js_then_resolve, (uint32_t * ret_value, uint32_t * resolve), {
     const ret_value_js = proxy_convert_mp_to_js_obj_jsside(ret_value);
     const resolve_js = proxy_convert_mp_to_js_obj_jsside(resolve);
-    const reject_js = proxy_convert_mp_to_js_obj_jsside(reject);
     resolve_js(ret_value_js);
 });
 
-EM_JS(void, js_then_reject, (uint32_t * ret_value, uint32_t * resolve, uint32_t * reject), {
+EM_JS(void, js_then_reject, (uint32_t * ret_value, uint32_t * reject), {
     // The ret_value object should be a Python exception.  Convert it to a
     // JavaScript PythonError and pass it as the reason to reject the promise.
     let ret_value_js;
@@ -305,7 +304,6 @@ EM_JS(void, js_then_reject, (uint32_t * ret_value, uint32_t * resolve, uint32_t
     } catch(error) {
         ret_value_js = error;
     }
-    const resolve_js = proxy_convert_mp_to_js_obj_jsside(resolve);
     const reject_js = proxy_convert_mp_to_js_obj_jsside(reject);
     reject_js(ret_value_js);
 });
@@ -344,30 +342,33 @@ static mp_obj_t proxy_resume_execute(mp_obj_t self_in, mp_obj_t send_value, mp_o
     mp_obj_t ret_value;
     mp_vm_return_kind_t ret_kind = mp_resume(self_in, send_value, throw_value, &ret_value);
 
-    uint32_t out_resolve[PVN];
-    uint32_t out_reject[PVN];
-    proxy_convert_mp_to_js_obj_cside(resolve, out_resolve);
-    proxy_convert_mp_to_js_obj_cside(reject, out_reject);
-
     if (ret_kind == MP_VM_RETURN_NORMAL) {
         uint32_t out_ret_value[PVN];
+        uint32_t out_resolve[PVN];
         proxy_convert_mp_to_js_obj_cside(ret_value, out_ret_value);
-        js_then_resolve(out_ret_value, out_resolve, out_reject);
+        proxy_convert_mp_to_js_obj_cside(resolve, out_resolve);
+        js_then_resolve(out_ret_value, out_resolve);
         return mp_const_none;
     } else if (ret_kind == MP_VM_RETURN_YIELD) {
         // ret_value should be a JS thenable
         mp_obj_t py_resume = mp_obj_new_bound_meth(MP_OBJ_FROM_PTR(&resume_obj), self_in);
         int ref = mp_obj_jsproxy_get_ref(ret_value);
         uint32_t out_py_resume[PVN];
+        uint32_t out_resolve[PVN];
+        uint32_t out_reject[PVN];
         proxy_convert_mp_to_js_obj_cside(py_resume, out_py_resume);
+        proxy_convert_mp_to_js_obj_cside(resolve, out_resolve);
+        proxy_convert_mp_to_js_obj_cside(reject, out_reject);
         uint32_t out[PVN];
         js_then_continue(ref, out_py_resume, out_resolve, out_reject, out);
         return proxy_convert_js_to_mp_obj_cside(out);
     } else { // ret_kind == MP_VM_RETURN_EXCEPTION;
         // Pass the exception through as an object to reject the promise (don't raise/throw it).
         uint32_t out_ret_value[PVN];
+        uint32_t out_reject[PVN];
         proxy_convert_mp_to_js_exc_cside(ret_value, out_ret_value);
-        js_then_reject(out_ret_value, out_resolve, out_reject);
+        proxy_convert_mp_to_js_obj_cside(reject, out_reject);
+        js_then_reject(out_ret_value, out_reject);
         return mp_const_none;
     }
 }

From e860e32e24e1c32db48f1d8b6f260c27aeb75657 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Mon, 6 May 2024 12:35:23 +1000
Subject: [PATCH 354/408] webassembly/objjsproxy: Fix proxying in arguments to
 JS new function.

Signed-off-by: Damien George 
---
 ports/webassembly/objjsproxy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ports/webassembly/objjsproxy.c b/ports/webassembly/objjsproxy.c
index 15fbb57523fc7..b575839d982e5 100644
--- a/ports/webassembly/objjsproxy.c
+++ b/ports/webassembly/objjsproxy.c
@@ -147,7 +147,7 @@ EM_JS(void, js_reflect_construct, (int f_ref, uint32_t n_args, uint32_t * args,
     const f = proxy_js_ref[f_ref];
     const as = [];
     for (let i = 0; i < n_args; ++i) {
-        as.push(proxy_convert_mp_to_js_obj_jsside(args + i * 4));
+        as.push(proxy_convert_mp_to_js_obj_jsside(args + i * 3 * 4));
     }
     const ret = Reflect.construct(f, as);
     proxy_convert_js_to_mp_obj_jsside(ret, out);
@@ -242,7 +242,7 @@ static mp_obj_t jsproxy_reflect_construct(size_t n_args, const mp_obj_t *args) {
     for (unsigned int i = 0; i < n_args; ++i) {
         proxy_convert_mp_to_js_obj_cside(args[i], &args_conv[i * PVN]);
     }
-    uint32_t out[3];
+    uint32_t out[PVN];
     js_reflect_construct(arg0, n_args, args_conv, out);
     return proxy_convert_js_to_mp_obj_cside(out);
 }

From c056840ee8f7a154ff437a335eb4a83f14d47f0f Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Mon, 6 May 2024 13:47:48 +1000
Subject: [PATCH 355/408] webassembly/objpyproxy: Implement JS iterator
 protocol for Py iterables.

This allows using JavaScript for..of on Python iterables.

Signed-off-by: Damien George 
---
 ports/webassembly/Makefile               |  2 ++
 ports/webassembly/objpyproxy.js          | 29 +++++++++++++++-
 ports/webassembly/proxy_c.c              | 42 ++++++++++++++++++++++--
 tests/ports/webassembly/iterator.mjs     | 21 ++++++++++++
 tests/ports/webassembly/iterator.mjs.exp |  7 ++++
 5 files changed, 97 insertions(+), 4 deletions(-)
 create mode 100644 tests/ports/webassembly/iterator.mjs
 create mode 100644 tests/ports/webassembly/iterator.mjs.exp

diff --git a/ports/webassembly/Makefile b/ports/webassembly/Makefile
index 93b92ef583989..fddfb5094aac5 100644
--- a/ports/webassembly/Makefile
+++ b/ports/webassembly/Makefile
@@ -60,8 +60,10 @@ EXPORTED_FUNCTIONS_EXTRA += ,\
 	_proxy_c_to_js_dir,\
 	_proxy_c_to_js_get_array,\
 	_proxy_c_to_js_get_dict,\
+	_proxy_c_to_js_get_iter,\
 	_proxy_c_to_js_get_type,\
 	_proxy_c_to_js_has_attr,\
+	_proxy_c_to_js_iternext,\
 	_proxy_c_to_js_lookup_attr,\
 	_proxy_c_to_js_resume,\
 	_proxy_c_to_js_store_attr,\
diff --git a/ports/webassembly/objpyproxy.js b/ports/webassembly/objpyproxy.js
index 9ba06283ea2b0..3b94f8aadc782 100644
--- a/ports/webassembly/objpyproxy.js
+++ b/ports/webassembly/objpyproxy.js
@@ -162,10 +162,37 @@ const py_proxy_handler = {
         if (prop === "then") {
             return null;
         }
+
+        if (prop === Symbol.iterator) {
+            // Get the Python object iterator, and return a JavaScript generator.
+            const iter_ref = Module.ccall(
+                "proxy_c_to_js_get_iter",
+                "number",
+                ["number"],
+                [target._ref],
+            );
+            return function* () {
+                const value = Module._malloc(3 * 4);
+                while (true) {
+                    const valid = Module.ccall(
+                        "proxy_c_to_js_iternext",
+                        "number",
+                        ["number", "pointer"],
+                        [iter_ref, value],
+                    );
+                    if (!valid) {
+                        break;
+                    }
+                    yield proxy_convert_mp_to_js_obj_jsside(value);
+                }
+                Module._free(value);
+            };
+        }
+
         const value = Module._malloc(3 * 4);
         Module.ccall(
             "proxy_c_to_js_lookup_attr",
-            "number",
+            "null",
             ["number", "string", "pointer"],
             [target._ref, prop, value],
         );
diff --git a/ports/webassembly/proxy_c.c b/ports/webassembly/proxy_c.c
index ade9d36dee847..b874b36c02c6b 100644
--- a/ports/webassembly/proxy_c.c
+++ b/ports/webassembly/proxy_c.c
@@ -65,6 +65,12 @@ void proxy_c_init(void) {
 
 MP_REGISTER_ROOT_POINTER(mp_obj_t proxy_c_ref);
 
+static inline size_t proxy_c_add_obj(mp_obj_t obj) {
+    size_t id = ((mp_obj_list_t *)MP_OBJ_TO_PTR(MP_STATE_PORT(proxy_c_ref)))->len;
+    mp_obj_list_append(MP_STATE_PORT(proxy_c_ref), obj);
+    return id;
+}
+
 static inline mp_obj_t proxy_c_get_obj(uint32_t c_ref) {
     return ((mp_obj_list_t *)MP_OBJ_TO_PTR(MP_STATE_PORT(proxy_c_ref)))->items[c_ref];
 }
@@ -122,9 +128,7 @@ void proxy_convert_mp_to_js_obj_cside(mp_obj_t obj, uint32_t *out) {
         } else {
             kind = PROXY_KIND_MP_OBJECT;
         }
-        size_t id = ((mp_obj_list_t *)MP_OBJ_TO_PTR(MP_STATE_PORT(proxy_c_ref)))->len;
-        mp_obj_list_append(MP_STATE_PORT(proxy_c_ref), obj);
-        out[1] = id;
+        out[1] = proxy_c_add_obj(obj);
     }
     out[0] = kind;
 }
@@ -284,6 +288,38 @@ void proxy_c_to_js_get_dict(uint32_t c_ref, uint32_t *out) {
     out[1] = (uintptr_t)map->table;
 }
 
+/******************************************************************************/
+// Bridge Python iterator to JavaScript iterator protocol.
+
+uint32_t proxy_c_to_js_get_iter(uint32_t c_ref) {
+    mp_obj_t obj = proxy_c_get_obj(c_ref);
+    mp_obj_t iter = mp_getiter(obj, NULL);
+    return proxy_c_add_obj(iter);
+}
+
+bool proxy_c_to_js_iternext(uint32_t c_ref, uint32_t *out) {
+    mp_obj_t obj = proxy_c_get_obj(c_ref);
+    nlr_buf_t nlr;
+    if (nlr_push(&nlr) == 0) {
+        mp_obj_t iter = mp_iternext_allow_raise(obj);
+        if (iter == MP_OBJ_STOP_ITERATION) {
+            nlr_pop();
+            return false;
+        }
+        nlr_pop();
+        proxy_convert_mp_to_js_obj_cside(iter, out);
+        return true;
+    } else {
+        if (mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(((mp_obj_base_t *)nlr.ret_val)->type), MP_OBJ_FROM_PTR(&mp_type_StopIteration))) {
+            return false;
+        } else {
+            // uncaught exception
+            proxy_convert_mp_to_js_exc_cside(nlr.ret_val, out);
+            return true;
+        }
+    }
+}
+
 /******************************************************************************/
 // Bridge Python generator to JavaScript thenable.
 
diff --git a/tests/ports/webassembly/iterator.mjs b/tests/ports/webassembly/iterator.mjs
new file mode 100644
index 0000000000000..91415d530f93c
--- /dev/null
+++ b/tests/ports/webassembly/iterator.mjs
@@ -0,0 +1,21 @@
+// Test accessing Python iterables from JavaScript via the JavaScript iterator protocol.
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+mp.runPython(`
+    s = "abc"
+    l = [1, 2, 3]
+`);
+
+// Iterate a Python string.
+for (const value of mp.globals.get("s")) {
+    console.log(value);
+}
+
+// Iterate a Python list.
+for (const value of mp.globals.get("l")) {
+    console.log(value);
+}
+
+// Iterate a Python list from a built-in JavaScript constructor.
+mp.runPython("import js; print(js.Set.new([1, 2, 3]).has(3))");
diff --git a/tests/ports/webassembly/iterator.mjs.exp b/tests/ports/webassembly/iterator.mjs.exp
new file mode 100644
index 0000000000000..9d1aaac117d84
--- /dev/null
+++ b/tests/ports/webassembly/iterator.mjs.exp
@@ -0,0 +1,7 @@
+a
+b
+c
+1
+2
+3
+True

From be1ecb54e6be1ee5017a1a8aeca83d9e12ad16c9 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Tue, 7 May 2024 11:33:05 +1000
Subject: [PATCH 356/408] webassembly/api: Resolve thenables returned from
 runPythonAsync.

JavaScript semantics are such that the caller of an async function does not
need to await that function for it to run to completion.  This commit makes
that behaviour also apply to top-level async Python code run via
`runPythonAsync()`.

Signed-off-by: Damien George 
---
 ports/webassembly/api.js                      |  6 ++++-
 .../webassembly/run_python_async_no_await.mjs | 24 +++++++++++++++++++
 .../run_python_async_no_await.mjs.exp         |  6 +++++
 3 files changed, 35 insertions(+), 1 deletion(-)
 create mode 100644 tests/ports/webassembly/run_python_async_no_await.mjs
 create mode 100644 tests/ports/webassembly/run_python_async_no_await.mjs.exp

diff --git a/ports/webassembly/api.js b/ports/webassembly/api.js
index f3245451e4ad0..c00edf575fa96 100644
--- a/ports/webassembly/api.js
+++ b/ports/webassembly/api.js
@@ -152,7 +152,11 @@ export async function loadMicroPython(options) {
                 [buf, len, value],
             );
             Module._free(buf);
-            return proxy_convert_mp_to_js_obj_jsside_with_free(value);
+            const ret = proxy_convert_mp_to_js_obj_jsside_with_free(value);
+            if (ret instanceof PyProxyThenable) {
+                return Promise.resolve(ret);
+            }
+            return ret;
         },
         replInit() {
             Module.ccall("mp_js_repl_init", "null", ["null"]);
diff --git a/tests/ports/webassembly/run_python_async_no_await.mjs b/tests/ports/webassembly/run_python_async_no_await.mjs
new file mode 100644
index 0000000000000..19462d6e7f628
--- /dev/null
+++ b/tests/ports/webassembly/run_python_async_no_await.mjs
@@ -0,0 +1,24 @@
+// Test runPythonAsync() without await'ing it.
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+globalThis.p = new Promise((resolve, reject) => {
+    setTimeout(() => {
+        resolve(123);
+        console.log("setTimeout resolved");
+    }, 100);
+});
+
+console.log(1);
+
+const ret = mp.runPythonAsync(`
+import js
+print("py 1")
+print("resolved value:", await js.p)
+print("py 2")
+`);
+
+// `ret` should be a Promise.
+console.log(2, ret);
+
+// Here, the Python async code should continue to run until completed.
diff --git a/tests/ports/webassembly/run_python_async_no_await.mjs.exp b/tests/ports/webassembly/run_python_async_no_await.mjs.exp
new file mode 100644
index 0000000000000..1dbf7f95f4d78
--- /dev/null
+++ b/tests/ports/webassembly/run_python_async_no_await.mjs.exp
@@ -0,0 +1,6 @@
+1
+2 Promise {  }
+py 1
+setTimeout resolved
+resolved value: 123
+py 2

From 595f86155aa76c4fd7c9b46a848023a93f6ddd32 Mon Sep 17 00:00:00 2001
From: Rick Sorensen 
Date: Tue, 26 Dec 2023 12:57:46 -0600
Subject: [PATCH 357/408] docs/esp32/quickref: Add note about different ESP32
 varieties.

Signed-off-by: Rick Sorensen 
---
 docs/esp32/quickref.rst | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/docs/esp32/quickref.rst b/docs/esp32/quickref.rst
index 6c07c584d325e..3f0db22861d3a 100644
--- a/docs/esp32/quickref.rst
+++ b/docs/esp32/quickref.rst
@@ -18,6 +18,9 @@ working with this board it may be useful to get an overview of the microcontroll
    general.rst
    tutorial/index.rst
 
+Note that there are several varieties of ESP32 -- ESP32, ESP32C3, ESP32S2, ESP32S3 --
+supported by MicroPython, with some differences in functionality between them.
+
 Installing MicroPython
 ----------------------
 
@@ -58,7 +61,7 @@ The :mod:`esp32` module::
     import esp32
 
     esp32.raw_temperature() # read the internal temperature of the MCU, in Fahrenheit
-    esp32.ULP()             # access to the Ultra-Low-Power Co-processor
+    esp32.ULP()             # access to the Ultra-Low-Power Co-processor, not on ESP32C3
 
 Note that the temperature sensor in the ESP32 will typically read higher than
 ambient due to the IC getting warm while it runs.  This effect can be minimised

From 63c30a2dfc3118f2f82693dd96114b1efebf071c Mon Sep 17 00:00:00 2001
From: Rick Sorensen 
Date: Tue, 26 Dec 2023 12:57:46 -0600
Subject: [PATCH 358/408] esp32/modesp32: Add mcu_temperature() function for
 C3/S2/S3 devices.

For ESP32C3/S2/S3 IDFv5 exposes new internal temperature API which is
different to the base ESP32, IDFv4.

Thanks to @robert-hh for cleaner code and testing sensor capability in
these devices.

See discussion #10443.

Signed-off-by: Rick Sorensen 
---
 docs/esp32/quickref.rst |  6 ++++++
 ports/esp32/modesp32.c  | 22 ++++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/docs/esp32/quickref.rst b/docs/esp32/quickref.rst
index 3f0db22861d3a..2be1dbadc353a 100644
--- a/docs/esp32/quickref.rst
+++ b/docs/esp32/quickref.rst
@@ -67,6 +67,12 @@ Note that the temperature sensor in the ESP32 will typically read higher than
 ambient due to the IC getting warm while it runs.  This effect can be minimised
 by reading the temperature sensor immediately after waking up from sleep.
 
+ESP32C3, ESP32S2, and ESP32S3 also have an internal temperature sensor available.
+It is implemented a bit differently to the ESP32 and returns the temperature in
+Celsius::
+
+    esp32.mcu_temperature() # read the internal temperature of the MCU, in Celsius
+
 Networking
 ----------
 
diff --git a/ports/esp32/modesp32.c b/ports/esp32/modesp32.c
index f363939483c6c..1ee9153d7d620 100644
--- a/ports/esp32/modesp32.c
+++ b/ports/esp32/modesp32.c
@@ -168,6 +168,26 @@ static mp_obj_t esp32_raw_temperature(void) {
 }
 static MP_DEFINE_CONST_FUN_OBJ_0(esp32_raw_temperature_obj, esp32_raw_temperature);
 
+#else
+
+// IDF 5 exposes new internal temperature interface, and the ESP32C3/S2/S3
+// now have calibrated temperature settings in 5 discrete ranges.
+#include "driver/temperature_sensor.h"
+
+static mp_obj_t esp32_mcu_temperature(void) {
+    static temperature_sensor_handle_t temp_sensor = NULL;
+    float tvalue;
+    if (temp_sensor == NULL) {
+        temperature_sensor_config_t temp_sensor_config = TEMPERATURE_SENSOR_CONFIG_DEFAULT(-10, 80);
+        ESP_ERROR_CHECK(temperature_sensor_install(&temp_sensor_config, &temp_sensor));
+    }
+    ESP_ERROR_CHECK(temperature_sensor_enable(temp_sensor));
+    ESP_ERROR_CHECK(temperature_sensor_get_celsius(temp_sensor, &tvalue));
+    ESP_ERROR_CHECK(temperature_sensor_disable(temp_sensor));
+    return mp_obj_new_int((int)(tvalue + 0.5));
+}
+static MP_DEFINE_CONST_FUN_OBJ_0(esp32_mcu_temperature_obj, esp32_mcu_temperature);
+
 #endif
 
 static mp_obj_t esp32_idf_heap_info(const mp_obj_t cap_in) {
@@ -202,6 +222,8 @@ static const mp_rom_map_elem_t esp32_module_globals_table[] = {
     { MP_ROM_QSTR(MP_QSTR_gpio_deep_sleep_hold), MP_ROM_PTR(&esp32_gpio_deep_sleep_hold_obj) },
     #if CONFIG_IDF_TARGET_ESP32
     { MP_ROM_QSTR(MP_QSTR_raw_temperature), MP_ROM_PTR(&esp32_raw_temperature_obj) },
+    #else
+    { MP_ROM_QSTR(MP_QSTR_mcu_temperature), MP_ROM_PTR(&esp32_mcu_temperature_obj) },
     #endif
     { MP_ROM_QSTR(MP_QSTR_idf_heap_info), MP_ROM_PTR(&esp32_idf_heap_info_obj) },
 

From 8762fe8b4c6a7608d48daa8458e6501fafd3eafc Mon Sep 17 00:00:00 2001
From: Jared Hancock 
Date: Mon, 1 Apr 2024 09:10:49 -0500
Subject: [PATCH 359/408] extmod/network_wiznet5k: Properly enable socket
 buffers for W5100(S).

The W5100 and W5100S only have 4 available sockets and 16kB of socket
buffer.  Allocating 16kB to either the receive or transmit buffer of a
single socket is not allowed, so the current setup does not change the
allocation for socket 0 from the reset default.  ctlwizchip is returning -1
to indicate the error, but the response isn't being inspected and probably
doesn't need to be.

Signed-off-by: Jared Hancock 
---
 extmod/network_wiznet5k.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/extmod/network_wiznet5k.c b/extmod/network_wiznet5k.c
index b8ca075b3d14f..1eaabe9ebeac3 100644
--- a/extmod/network_wiznet5k.c
+++ b/extmod/network_wiznet5k.c
@@ -211,7 +211,11 @@ static void wiznet5k_init(void) {
     // Configure wiznet for raw ethernet frame usage.
 
     // Configure 16k buffers for fast MACRAW
+    #if _WIZCHIP_ < W5200
+    uint8_t sn_size[8] = {8, 0, 0, 0, 8, 0, 0, 0};
+    #else
     uint8_t sn_size[16] = {16, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0};
+    #endif
     ctlwizchip(CW_INIT_WIZCHIP, sn_size);
 
     if (wiznet5k_obj.use_interrupt) {

From 9a43989a8651dacc004f9bb8df6574c814ec98ca Mon Sep 17 00:00:00 2001
From: Angus Gratton 
Date: Tue, 7 May 2024 17:02:11 +1000
Subject: [PATCH 360/408] shared/tinyusb: Stall the CDC IN endpoint while
 disconnecting.

Only when dynamic USB devices are enabled.

The issue here is that when the USB reset triggers, the dynamic USB device
reset callback is called from inside the TinyUSB task.

If that callback tries to print something then it'll call through to
tud_cdc_write_flush(), but TinyUSB hasn't finished updating state yet to
know it's no longer configured. Subsequently it may try to queue a transfer
and then the low-level DCD layer panics.

By explicitly stalling the endpoint first, usbd_edpt_claim() will fail and
tud_cdc_write_flush() returns immediately.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton 
---
 shared/tinyusb/mp_usbd_runtime.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/shared/tinyusb/mp_usbd_runtime.c b/shared/tinyusb/mp_usbd_runtime.c
index 7ff7dd4ab2ff0..e10d1cb3f62d2 100644
--- a/shared/tinyusb/mp_usbd_runtime.c
+++ b/shared/tinyusb/mp_usbd_runtime.c
@@ -472,6 +472,8 @@ static void mp_usbd_disconnect(mp_obj_usb_device_t *usbd) {
     #if MICROPY_HW_USB_CDC
     // Ensure no pending static CDC writes, as these can cause TinyUSB to crash
     tud_cdc_write_clear();
+    // Prevent cdc write flush from initiating any new transfers while disconnecting
+    usbd_edpt_stall(USBD_RHPORT, USBD_CDC_EP_IN);
     #endif
 
     bool was_connected = tud_connected();

From c3301da17626663d7d6e5fc79a1010842528c9b1 Mon Sep 17 00:00:00 2001
From: Angus Gratton 
Date: Thu, 2 May 2024 13:37:33 +1000
Subject: [PATCH 361/408] docs/library/machine.USBDevice: Update note about
 packages in mp-lib.

Also fix a small typo.

Signed-off-by: Angus Gratton 
---
 docs/library/machine.USBDevice.rst | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/docs/library/machine.USBDevice.rst b/docs/library/machine.USBDevice.rst
index e02d3c02df336..5fc71651612b1 100644
--- a/docs/library/machine.USBDevice.rst
+++ b/docs/library/machine.USBDevice.rst
@@ -8,13 +8,11 @@ class USBDevice -- USB Device driver
           ports.
 
 USBDevice provides a low-level Python API for implementing USB device functions using
-Python code. This low-level API assumes familiarity with the USB standard. It's
-not recommended to use this API directly, instead install the high-level usbd
-module from micropython-lib.
+Python code.
 
-.. warning:: This functionality is very new and the high-level usbd module is
-             not yet merged into micropython-lib. It can be found `here on
-             GitHub `_.
+.. warning:: This low-level API assumes familiarity with the USB standard. There
+   are high-level `usb driver modules in micropython-lib`_ which provide a
+   simpler interface and more built-in functionality.
 
 Terminology
 -----------
@@ -186,7 +184,7 @@ Methods
     necessary if the runtime device configuration has changed, so that
     the host sees the new device.
 
-.. attribute:: USDBD.builtin_driver
+.. attribute:: USBDevice.builtin_driver
 
    This attribute holds the current built-in driver configuration, and must be
    set to one of the ``USBDevice.BUILTIN_`` named constants defined on this object.
@@ -294,3 +292,5 @@ Constants
             descriptor.
           - ``desc_cfg`` - ``bytes`` object containing the complete built-in USB
             configuration descriptor.
+
+.. _usb driver modules in micropython-lib: https://github.com/micropython/micropython-lib/tree/master/micropython/usb#readme

From b2df89c417841a7db18120fb40e1dee96cf71865 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Tue, 30 Apr 2024 11:33:39 +1000
Subject: [PATCH 362/408] examples/usb: Add a very simple USBDevice example
 with host.

Signed-off-by: Damien George 
---
 examples/usb/usb_simple_device.py     | 144 ++++++++++++++++++++++++++
 examples/usb/usb_simple_host_pyusb.py |  47 +++++++++
 2 files changed, 191 insertions(+)
 create mode 100644 examples/usb/usb_simple_device.py
 create mode 100755 examples/usb/usb_simple_host_pyusb.py

diff --git a/examples/usb/usb_simple_device.py b/examples/usb/usb_simple_device.py
new file mode 100644
index 0000000000000..0b0921f547325
--- /dev/null
+++ b/examples/usb/usb_simple_device.py
@@ -0,0 +1,144 @@
+# Implementation of a very simple, custom USB device in Python.  The device has an
+# IN and OUT endpoint, accepts up to 64 bytes of data on the OUT endpoint, and echos
+# that data back to the IN endpoint.
+#
+# To run, just execute this file on a device with machine.USBDevice support.  The device
+# will then change to the custom USB device.
+#
+# For example, use `mpremote` (the `--no-follow` option starts the script running
+# without waiting for a response, because there won't be a response after the device
+# changes its USB mode):
+#
+# $ mpremote run --no-follow usb_simple_device.py
+#
+# Then, run the host side of the example on your PC using:
+#
+# $ sudo python usb_simple_host_pyusb.py
+#
+# You'll need to have `pyusb` installed via `pip install pyusb` to run the host PC code.
+# And `sudo` is most likely needed to access the custom USB device.
+#
+# Once you have finished running the code, you will need to reset or unplug the USB
+# device to stop it.
+
+import machine
+
+# VID and PID of the USB device.
+VID = 0xF055
+PID = 0x9999
+
+# USB endpoints used by the device.
+EP_OUT = 0x01
+EP_IN = 0x81
+
+# USB device descriptor.
+_desc_dev = bytes(
+    [
+        0x12,  # bLength
+        0x01,  # bDescriptorType: Device
+        0x00,
+        0x02,  # USB version: 2.00
+        0xFF,  # bDeviceClass: vendor
+        0x00,  # bDeviceSubClass
+        0x01,  # bDeviceProtocol
+        0x40,  # bMaxPacketSize
+        VID & 0xFF,
+        VID >> 8 & 0xFF,  # VID
+        PID & 0xFF,
+        PID >> 8 & 0xFF,  # PID
+        0x00,
+        0x01,  # bcdDevice: 1.00
+        0x11,  # iManufacturer
+        0x12,  # iProduct
+        0x13,  # iSerialNumber
+        0x01,  # bNumConfigurations: 1
+    ]
+)
+
+# USB configuration descriptor.
+_desc_cfg = bytes(
+    [
+        # Configuration Descriptor.
+        0x09,  # bLength
+        0x02,  # bDescriptorType: configuration
+        0x20,
+        0x00,  # wTotalLength: 32
+        0x01,  # bNumInterfaces
+        0x01,  # bConfigurationValue
+        0x14,  # iConfiguration
+        0xA0,  # bmAttributes
+        0x96,  # bMaxPower
+        # Interface Descriptor.
+        0x09,  # bLength
+        0x04,  # bDescriptorType: interface
+        0x00,  # bInterfaceNumber
+        0x00,  # bAlternateSetting
+        0x02,  # bNumEndpoints
+        0xFF,  # bInterfaceClass
+        0x03,  # bInterfaceSubClass
+        0x00,  # bInterfaceProtocol
+        0x15,  # iInterface
+        # Endpoint IN1.
+        0x07,  # bLength
+        0x05,  # bDescriptorType: endpoint
+        EP_IN,  # bEndpointAddress
+        0x03,  # bmAttributes: interrupt
+        0x40,
+        0x00,  # wMaxPacketSize
+        0x0A,  # bInterval
+        # Endpoint OUT1.
+        0x07,  # bLength
+        0x05,  # bDescriptorType: endpoint
+        EP_OUT,  # bEndpointAddress
+        0x02,  # bmAttributes: bulk
+        0x40,
+        0x00,  # wMaxPacketSize
+        0x00,  # bInterval
+    ]
+)
+
+# USB strings.
+_desc_strs = {
+    0x11: b"iManufacturer",
+    0x12: b"iProduct",
+    0x13: b"iSerial",
+    0x14: b"iInterface",
+    0x15: b"iInterface",
+    0x16: b"Extra information",
+}
+
+
+# USB callback for when our custom USB interface is opened by the host.
+def _open_itf_cb(interface_desc_view):
+    print("_open_itf_cb", bytes(interface_desc_view))
+    # Prepare to receive first data packet on the OUT endpoint.
+    usbd.submit_xfer(EP_OUT, usbd_buf)
+
+
+# USB callback for when a data transfer (IN or OUT) has completed.
+def _xfer_cb(ep_addr, result, xferred_bytes):
+    print("_xfer_cb", ep_addr, result, xferred_bytes)
+    if ep_addr == EP_OUT:
+        # Received data packet from the host, print it out.
+        print(usbd_buf)
+        # And then echo the data back to the host.
+        usbd.submit_xfer(EP_IN, memoryview(usbd_buf)[:xferred_bytes])
+    elif ep_addr == EP_IN:
+        # Host got our data, prepare to receive the next data packet.
+        usbd.submit_xfer(EP_OUT, usbd_buf)
+
+
+# USB data buffer, for IN and OUT transfers.
+usbd_buf = bytearray(64)
+
+# Switch the USB device to our custom USB driver.
+usbd = machine.USBDevice()
+usbd.builtin_driver = usbd.BUILTIN_NONE
+usbd.config(
+    desc_dev=_desc_dev,
+    desc_cfg=_desc_cfg,
+    desc_strs=_desc_strs,
+    open_itf_cb=_open_itf_cb,
+    xfer_cb=_xfer_cb,
+)
+usbd.active(1)
diff --git a/examples/usb/usb_simple_host_pyusb.py b/examples/usb/usb_simple_host_pyusb.py
new file mode 100755
index 0000000000000..d8ac2dd9c3e34
--- /dev/null
+++ b/examples/usb/usb_simple_host_pyusb.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python3
+#
+# Host side of the `usb_simple_device.py` example.  This must be run using standard
+# Python on a PC.  See further instructions in `usb_simple_device.py`.
+
+import sys
+import usb.core
+import usb.util
+
+# VID and PID of the custom USB device.
+VID = 0xF055
+PID = 0x9999
+
+# USB endpoints used by the device.
+EP_OUT = 0x01
+EP_IN = 0x81
+
+
+def main():
+    # Search for the custom USB device by VID/PID.
+    dev = usb.core.find(idVendor=VID, idProduct=PID)
+
+    if dev is None:
+        print("No USB device found")
+        sys.exit(1)
+
+    # Claim the USB device.
+    usb.util.claim_interface(dev, 0)
+
+    # Read the device's strings.
+    for i in range(0x11, 0x17):
+        print(f"str{i}:", usb.util.get_string(dev, i))
+
+    # Test writing to the device.
+    ret = dev.write(EP_OUT, b"01234567", timeout=1000)
+    print(ret)
+
+    # Test reading from the device.
+    print(dev.read(EP_IN, 64))
+
+    # Release the USB device.
+    usb.util.release_interface(dev, 0)
+    usb.util.dispose_resources(dev)
+
+
+if __name__ == "__main__":
+    main()

From eb517a0a12c09b2ca8958c7481344c187a91b48f Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Tue, 30 Apr 2024 11:33:58 +1000
Subject: [PATCH 363/408] examples/usb: Add a USBDevice example implementing
 the DFU protocol.

Signed-off-by: Damien George 
---
 examples/usb/usb_dfu_device.py | 327 +++++++++++++++++++++++++++++++++
 1 file changed, 327 insertions(+)
 create mode 100644 examples/usb/usb_dfu_device.py

diff --git a/examples/usb/usb_dfu_device.py b/examples/usb/usb_dfu_device.py
new file mode 100644
index 0000000000000..5158befd40482
--- /dev/null
+++ b/examples/usb/usb_dfu_device.py
@@ -0,0 +1,327 @@
+# Implementation of USB DFU device in Python.
+#
+# To run, just execute this file on a device with machine.USBDevice support.  The device
+# will then change to DFU mode.
+#
+# For example, use `mpremote` (the `--no-follow` option starts the script running
+# without waiting for a response, because there won't be a response, the USB will change
+# to a DFU device):
+#
+# $ mpremote run --no-follow usb_dfu_device.py
+#
+# Then you can access the DFU device using the `pydfu.py` script in this repository, to
+# list DFU device, copy a file to the device, then exit DFU mode:
+#
+# $ ../../tools/pydfu.py -l
+# $ ../../tools/pydfu.py -u 
+#
+# After running the last command above, the USB CDC device and REPL should reappear.
+
+import struct, machine
+
+# USB constants for bmRequestType.
+USB_REQ_RECIP_INTERFACE = 0x01
+USB_REQ_TYPE_CLASS = 0x20
+USB_DIR_OUT = 0x00
+USB_DIR_IN = 0x80
+
+# String describing the memory layout of the DFU device.
+MEMORY_LAYOUT = b"@Internal Flash  /0x08000000/16*128Kg"
+
+# VID and PID of the DFU device (these are the ST values).
+VID = 0x0483
+PID = 0xDF11
+
+# Maximum transfer size for RX and TX.
+wTransferSize = 2048
+
+# DFU device descriptor.
+_desc_dev = bytes(
+    [
+        0x12,  # bLength
+        0x01,  # bDescriptorType: Device
+        0x00,
+        0x02,  # USB version: 2.00
+        0x00,  # bDeviceClass
+        0x00,  # bDeviceSubClass
+        0x00,  # bDeviceProtocol
+        0x40,  # bMaxPacketSize
+        VID & 0xFF,
+        VID >> 8,  # VID
+        PID & 0xFF,
+        PID >> 8,  # PID
+        0x00,
+        0x01,  # bcdDevice: 1.00
+        0x11,  # iManufacturer
+        0x12,  # iProduct
+        0x13,  # iSerialNumber
+        0x01,  # bNumConfigurations: 1
+    ]
+)
+
+# DFU configuration descriptor.
+_desc_cfg = bytes(
+    [
+        # Configuration Descriptor.
+        0x09,  # bLength
+        0x02,  # bDescriptorType
+        0x1B,
+        0x00,  # wTotalLength: 27
+        0x01,  # bNumInterfaces
+        0x01,  # bConfigurationValue
+        0x00,  # iConfiguration
+        0x80,  # bmAttributes (bus powered)
+        0x32,  # bMaxPower
+        # Interface Descriptor.
+        0x09,  # bLength
+        0x04,  # bDescriptorType
+        0x00,  # bInterfaceNumber
+        0x00,  # bNumEndpointns
+        0x00,  # bAlternateSetting
+        0xFE,  # bInterfaceClass: application specific interface
+        0x01,  # bInterfaceSubClasse: device firmware update
+        0x02,  # bInterfaceProtocol
+        0x14,  # iInterface
+        # Device Firmware Upgrade Interface Descriptor.
+        0x09,  # bLength
+        0x21,  # bDescriptorType
+        0x0B,  # bmAttributes (will detach, upload supported, download supported)
+        0xFF,
+        0x00,  # wDetatchTimeout
+        wTransferSize & 0xFF,
+        wTransferSize >> 8,  # wTransferSize
+        0x1A,
+        0x01,  # bcdDFUVersion
+    ]
+)
+
+# DFU strings.
+_desc_strs = {
+    0x11: b"iManufacturer",
+    0x12: b"iProduct",
+    0x13: b"iSerialNumber",
+    0x14: MEMORY_LAYOUT,
+}
+
+
+# This class handles the DFU USB device logic.
+class DFUOverUSB:
+    def __init__(self, dfu):
+        # USB buffer for transfers.
+        self.usb_buf = bytearray(wTransferSize)
+        # Instance of the DFU state machine.
+        self.dfu = dfu
+
+    def _control_xfer_cb(self, stage, request):
+        bmRequestType, bRequest, wValue, wIndex, wLength = struct.unpack("= 2:
+                self.cmd = DFU.CMD_UPLOAD
+                addr = (arg - 2) * len(buf) + self.addr
+                self.do_read(addr, buf)
+                return buf
+            return None
+        elif cmd == DFU.GETSTATUS and len(buf) == 6:
+            if self.cmd == DFU.CMD_NONE:
+                pass
+            elif self.cmd == DFU.CMD_EXIT:
+                self.state = DFU.STATE_MANIFEST
+            elif self.cmd == DFU.CMD_UPLOAD:
+                self.state = DFU.STATE_UPLOAD_IDLE
+            elif self.cmd == DFU.CMD_DNLOAD:
+                self.state = DFU.STATE_BUSY
+            else:
+                self.state = DFU.STATE_BUSY
+
+            # Populate the buffer to return to the host.
+            buf[0] = self.status
+            buf[1] = 0
+            buf[2] = 0
+            buf[3] = 0
+            buf[4] = self.state
+            buf[5] = self.error
+
+            # Clear errors now they've been sent to host.
+            self.status = DFU.STATUS_OK
+            self.error = 0
+
+            return buf
+        else:
+            return None
+
+    def process(self):
+        # Transition the DFU state machine.
+        if self.state == DFU.STATE_MANIFEST:
+            self.leave_dfu = True
+        elif self.state == DFU.STATE_BUSY:
+            if self.cmd == DFU.CMD_DNLOAD:
+                self.cmd = DFU.CMD_NONE
+                self.state = self.process_dnload()
+
+    def process_dnload(self):
+        ret = -1  # Assume error.
+        if self.dnload_block_num == 0:
+            # Download control commands.
+            if self.dnload_len >= 1 and self.dnload_buf[0] == DFU.CMD_DNLOAD_ERASE:
+                if self.dnload_len == 1:
+                    # Mass erase.
+                    ret = self.do_mass_erase()
+                    if ret != 0:
+                        self.cmd = DFU.CMD_NONE
+                elif self.dnload_len == 5:
+                    # Erase page.
+                    addr = struct.unpack_from("= 1 and self.dnload_buf[0] == DFU.CMD_DNLOAD_SET_ADDRESS:
+                if self.dnload_len == 5:
+                    # Set address.
+                    self.addr = struct.unpack_from(" 1:
+            # Write data to memory.
+            addr = (self.dnload_block_num - 2) * wTransferSize + self.addr
+            ret = self.do_write(addr, self.dnload_len, self.dnload_buf)
+        if ret == 0:
+            return DFU.STATE_DNLOAD_IDLE
+        else:
+            return DFU.STATE_ERROR
+
+    def do_mass_erase(self):
+        # This function would implement a mass erase of flash memory.
+        return 0  # indicate success
+
+    def do_page_erase(self, addr):
+        # This function would implement an erase of a page in flash memory.
+        return 0  # indicate success
+
+    def do_read(self, addr, buf):
+        # This function would implement a read at the given address of flash memory.
+        # Return some dummy bytes.
+        for i in range(len(buf)):
+            buf[i] = i & 0xFF
+        return 0  # indicate success
+
+    def do_write(self, addr, size, buf):
+        # This function would implement a write of the given data to flash memory.
+        return 0  # indicate success
+
+
+# Create an instance of the DFU state machine.
+dfu = DFU()
+
+# Create an instance of the DFU USB handler.
+dfu_usb = DFUOverUSB(dfu)
+
+# Switch the USB device to the custom DFU driver.
+usbd = machine.USBDevice()
+usbd.active(0)
+usbd.builtin_driver = usbd.BUILTIN_NONE
+usbd.config(
+    desc_dev=_desc_dev,
+    desc_cfg=_desc_cfg,
+    desc_strs=_desc_strs,
+    control_xfer_cb=dfu_usb._control_xfer_cb,
+)
+usbd.active(1)
+
+# Wait for the DFU state machine to complete.
+while not dfu.leave_dfu:
+    machine.idle()
+
+# Switch the USB device back to the default built-in driver.
+usbd.active(0)
+usbd.builtin_driver = usbd.BUILTIN_DEFAULT
+usbd.config(
+    desc_dev=usbd.builtin_driver.desc_dev,
+    desc_cfg=usbd.builtin_driver.desc_cfg,
+    desc_strs=(),
+)
+usbd.active(1)

From bd610ff0160f8dad2b4a3592d5351b6029af5caa Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Sat, 27 Apr 2024 13:39:57 +1000
Subject: [PATCH 364/408] examples/network: Rename SSL examples to start with
 https.

It's better for discoverability to have these examples named `https_xxx.py`
rather than `http_xxx_ssl.py`.

Signed-off-by: Damien George 
---
 examples/network/{http_client_ssl.py => https_client.py} | 0
 examples/network/{http_server_ssl.py => https_server.py} | 0
 2 files changed, 0 insertions(+), 0 deletions(-)
 rename examples/network/{http_client_ssl.py => https_client.py} (100%)
 rename examples/network/{http_server_ssl.py => https_server.py} (100%)

diff --git a/examples/network/http_client_ssl.py b/examples/network/https_client.py
similarity index 100%
rename from examples/network/http_client_ssl.py
rename to examples/network/https_client.py
diff --git a/examples/network/http_server_ssl.py b/examples/network/https_server.py
similarity index 100%
rename from examples/network/http_server_ssl.py
rename to examples/network/https_server.py

From cc3550eeeff011f98361b8318447faf57bbac036 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Sat, 27 Apr 2024 13:42:21 +1000
Subject: [PATCH 365/408] examples/network: Add example of HTTPS client using
 non-blocking socket.

Non-blocking SSL streams can be difficult to get right, so provide a
working example, of a HTTPS client.

Signed-off-by: Damien George 
---
 examples/network/https_client_nonblocking.py | 75 ++++++++++++++++++++
 1 file changed, 75 insertions(+)
 create mode 100644 examples/network/https_client_nonblocking.py

diff --git a/examples/network/https_client_nonblocking.py b/examples/network/https_client_nonblocking.py
new file mode 100644
index 0000000000000..6e6b7f37bc7b1
--- /dev/null
+++ b/examples/network/https_client_nonblocking.py
@@ -0,0 +1,75 @@
+# Example of a HTTPS client working with non-blocking sockets.
+#
+# Non-blocking SSL streams works differently in MicroPython compared to CPython.  In
+# CPython a write to an SSLSocket may raise ssl.SSLWantReadError.  In MicroPython an
+# SSLSocket behaves like a normal socket/stream and can be polled for reading/writing.
+
+from errno import EINPROGRESS
+import select
+import socket
+import ssl
+
+
+def connect_nonblocking(sock, addr):
+    sock.setblocking(False)
+    try:
+        sock.connect(addr)
+    except OSError as er:
+        if er.errno != EINPROGRESS:
+            raise er
+
+
+def write_nonblocking(poller, sock, data):
+    poller.register(sock, select.POLLOUT)
+    while data:
+        poller.poll()
+        n = sock.write(data)
+        print("Wrote:", n)
+        if n is not None:
+            data = data[n:]
+
+
+def read_nonblocking(poller, sock, n):
+    poller.register(sock, select.POLLIN)
+    poller.poll()
+    data = sock.read(n)
+    print("Read:", len(data))
+    return data
+
+
+def main(url):
+    # Split the given URL into components.
+    proto, _, host, path = url.split(b"/", 3)
+    assert proto == b"https:"
+
+    # Note: this getaddrinfo() call is blocking!
+    ai = socket.getaddrinfo(host, 443)[0]
+    addr = ai[-1]
+    print("Connect address:", addr)
+
+    # Create a TCP socket and connect to the server in non-blocking mode.
+    sock = socket.socket(ai[0], ai[1], ai[2])
+    connect_nonblocking(sock, addr)
+
+    # Wrap the TCP socket in an SSL stream in non-blocking mode.
+    ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
+    sock = ctx.wrap_socket(sock, server_hostname=host, do_handshake_on_connect=False)
+    sock.setblocking(False)
+
+    # Create an object to poll the SSL stream for readability/writability.
+    poller = select.poll()
+
+    # Send the HTTP request on the SSL stream.
+    request = b"GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n" % (path, host)
+    write_nonblocking(poller, sock, request)
+
+    # Receive the HTTP response from the SSL stream.
+    response = read_nonblocking(poller, sock, 1000)
+    for line in response.split(b"\n"):
+        print(line)
+
+    # Close the SSL stream.  This will also close the underlying TCP socket.
+    sock.close()
+
+
+main(b"https://micropython.org/ks/test.html")

From c37eb93f2dd75bf49c6cc5105494c5f176c3d541 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Thu, 9 May 2024 15:03:55 +1000
Subject: [PATCH 366/408] webassembly/proxy_c: Support more than 4 args when JS
 calls Py func.

Signed-off-by: Damien George 
---
 ports/webassembly/proxy_c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ports/webassembly/proxy_c.c b/ports/webassembly/proxy_c.c
index b874b36c02c6b..4e2fdc8f2a34d 100644
--- a/ports/webassembly/proxy_c.c
+++ b/ports/webassembly/proxy_c.c
@@ -151,7 +151,7 @@ void proxy_convert_mp_to_js_exc_cside(void *exc, uint32_t *out) {
 void proxy_c_to_js_call(uint32_t c_ref, uint32_t n_args, uint32_t *args_value, uint32_t *out) {
     nlr_buf_t nlr;
     if (nlr_push(&nlr) == 0) {
-        mp_obj_t args[4] = { mp_const_none, mp_const_none, mp_const_none, mp_const_none };
+        mp_obj_t args[n_args];
         for (size_t i = 0; i < n_args; ++i) {
             args[i] = proxy_convert_js_to_mp_obj_cside(args_value + i * 3);
         }

From 3f34be69c77dfbd1533af1f04ea460d7da2d118a Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Thu, 9 May 2024 15:07:11 +1000
Subject: [PATCH 367/408] webassembly/asyncio: Fix case where a Promise is
 resolved with no arg.

Signed-off-by: Damien George 
---
 ports/webassembly/asyncio/core.py             |  2 +-
 .../asyncio_await_resolve_no_arg.mjs          | 21 +++++++++++++++++++
 .../asyncio_await_resolve_no_arg.mjs.exp      |  5 +++++
 3 files changed, 27 insertions(+), 1 deletion(-)
 create mode 100644 tests/ports/webassembly/asyncio_await_resolve_no_arg.mjs
 create mode 100644 tests/ports/webassembly/asyncio_await_resolve_no_arg.mjs.exp

diff --git a/ports/webassembly/asyncio/core.py b/ports/webassembly/asyncio/core.py
index a128bb6055058..f6f9d19e5c154 100644
--- a/ports/webassembly/asyncio/core.py
+++ b/ports/webassembly/asyncio/core.py
@@ -75,7 +75,7 @@ def __init__(self, thenable):
         self.waiting = None  # Task waiting on completion of this thenable
         thenable.then(self.set)
 
-    def set(self, value):
+    def set(self, value=None):
         # Thenable/Promise is fulfilled, set result and schedule any waiting task.
         self.result = value
         if self.waiting:
diff --git a/tests/ports/webassembly/asyncio_await_resolve_no_arg.mjs b/tests/ports/webassembly/asyncio_await_resolve_no_arg.mjs
new file mode 100644
index 0000000000000..0334a14f11891
--- /dev/null
+++ b/tests/ports/webassembly/asyncio_await_resolve_no_arg.mjs
@@ -0,0 +1,21 @@
+// Test an asyncio task await'ing on a Promise that's resolved without an argument.
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+globalThis.foo = new Promise((resolve) => {
+    console.log(1);
+    resolve(); // resolve without an argument
+    console.log(2);
+});
+
+mp.runPython(`
+import asyncio
+import js
+
+async def task():
+    print(3)
+    print(await js.foo)
+    print(4)
+
+asyncio.create_task(task())
+`);
diff --git a/tests/ports/webassembly/asyncio_await_resolve_no_arg.mjs.exp b/tests/ports/webassembly/asyncio_await_resolve_no_arg.mjs.exp
new file mode 100644
index 0000000000000..f3ca0f268af6a
--- /dev/null
+++ b/tests/ports/webassembly/asyncio_await_resolve_no_arg.mjs.exp
@@ -0,0 +1,5 @@
+1
+2
+3
+None
+4

From a67e326cb9753f53e14a42b347133a571f972140 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Thu, 9 May 2024 15:11:21 +1000
Subject: [PATCH 368/408] webassembly/proxy_c: Ensure objs thrown into
 generators are exceptions.

This commit defines a new `JsException` exception type which is used on the
Python side to wrap JavaScript errors.  That's then used when a JavaScript
Promise is rejected, and the reason is then converted to a `JsException`
for the Python side to handle.

This new exception is exposed as `jsffi.JsException`.

Signed-off-by: Damien George 
---
 ports/webassembly/modjsffi.c                  |  1 +
 ports/webassembly/proxy_c.c                   | 35 +++++++++++++++++++
 ports/webassembly/proxy_c.h                   |  1 +
 .../webassembly/await_error_handling.mjs      | 22 ++++++++++++
 .../webassembly/await_error_handling.mjs.exp  |  5 +++
 5 files changed, 64 insertions(+)
 create mode 100644 tests/ports/webassembly/await_error_handling.mjs
 create mode 100644 tests/ports/webassembly/await_error_handling.mjs.exp

diff --git a/ports/webassembly/modjsffi.c b/ports/webassembly/modjsffi.c
index cb2f578f8f593..c77d899fb7f8c 100644
--- a/ports/webassembly/modjsffi.c
+++ b/ports/webassembly/modjsffi.c
@@ -79,6 +79,7 @@ static const mp_rom_map_elem_t mp_module_jsffi_globals_table[] = {
     { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_jsffi) },
 
     { MP_ROM_QSTR(MP_QSTR_JsProxy), MP_ROM_PTR(&mp_type_jsproxy) },
+    { MP_ROM_QSTR(MP_QSTR_JsException), MP_ROM_PTR(&mp_type_JsException) },
     { MP_ROM_QSTR(MP_QSTR_create_proxy), MP_ROM_PTR(&mp_jsffi_create_proxy_obj) },
     { MP_ROM_QSTR(MP_QSTR_to_js), MP_ROM_PTR(&mp_jsffi_to_js_obj) },
     { MP_ROM_QSTR(MP_QSTR_async_timeout_ms), MP_ROM_PTR(&mp_jsffi_async_timeout_ms_obj) },
diff --git a/ports/webassembly/proxy_c.c b/ports/webassembly/proxy_c.c
index 4e2fdc8f2a34d..3097d6d3a4693 100644
--- a/ports/webassembly/proxy_c.c
+++ b/ports/webassembly/proxy_c.c
@@ -58,6 +58,8 @@ enum {
     PROXY_KIND_JS_PYPROXY = 7,
 };
 
+MP_DEFINE_EXCEPTION(JsException, Exception)
+
 void proxy_c_init(void) {
     MP_STATE_PORT(proxy_c_ref) = mp_obj_new_list(0, NULL);
     mp_obj_list_append(MP_STATE_PORT(proxy_c_ref), MP_OBJ_NULL);
@@ -120,6 +122,15 @@ void proxy_convert_mp_to_js_obj_cside(mp_obj_t obj, uint32_t *out) {
     } else if (mp_obj_is_jsproxy(obj)) {
         kind = PROXY_KIND_MP_JSPROXY;
         out[1] = mp_obj_jsproxy_get_ref(obj);
+    } else if (mp_obj_get_type(obj) == &mp_type_JsException) {
+        mp_obj_exception_t *exc = MP_OBJ_TO_PTR(obj);
+        if (exc->args->len > 0 && mp_obj_is_jsproxy(exc->args->items[0])) {
+            kind = PROXY_KIND_MP_JSPROXY;
+            out[1] = mp_obj_jsproxy_get_ref(exc->args->items[0]);
+        } else {
+            kind = PROXY_KIND_MP_OBJECT;
+            out[1] = proxy_c_add_obj(obj);
+        }
     } else {
         if (mp_obj_is_callable(obj)) {
             kind = PROXY_KIND_MP_CALLABLE;
@@ -288,6 +299,24 @@ void proxy_c_to_js_get_dict(uint32_t c_ref, uint32_t *out) {
     out[1] = (uintptr_t)map->table;
 }
 
+EM_JS(void, js_get_error_info, (int jsref, uint32_t * out_name, uint32_t * out_message), {
+    const error = proxy_js_ref[jsref];
+    proxy_convert_js_to_mp_obj_jsside(error.name, out_name);
+    proxy_convert_js_to_mp_obj_jsside(error.message, out_message);
+});
+
+mp_obj_t mp_obj_jsproxy_make_js_exception(mp_obj_t error) {
+    uint32_t out_name[PVN];
+    uint32_t out_message[PVN];
+    js_get_error_info(mp_obj_jsproxy_get_ref(error), out_name, out_message);
+    mp_obj_t args[3] = {
+        error,
+        proxy_convert_js_to_mp_obj_cside(out_name),
+        proxy_convert_js_to_mp_obj_cside(out_message),
+    };
+    return mp_obj_new_exception_args(&mp_type_JsException, MP_ARRAY_SIZE(args), args);
+}
+
 /******************************************************************************/
 // Bridge Python iterator to JavaScript iterator protocol.
 
@@ -371,6 +400,12 @@ static mp_obj_t proxy_resume_execute(mp_obj_t self_in, mp_obj_t send_value, mp_o
         if (send_value == mp_const_none) {
             send_value = MP_OBJ_NULL;
         }
+        // Ensure that the `throw_value` is a proper Python exception instance.
+        if (mp_obj_is_jsproxy(throw_value)) {
+            throw_value = mp_obj_jsproxy_make_js_exception(throw_value);
+        } else {
+            throw_value = mp_make_raise_obj(throw_value);
+        }
     } else {
         throw_value = MP_OBJ_NULL;
     }
diff --git a/ports/webassembly/proxy_c.h b/ports/webassembly/proxy_c.h
index 3e68d2504958c..751d14332b4b3 100644
--- a/ports/webassembly/proxy_c.h
+++ b/ports/webassembly/proxy_c.h
@@ -37,6 +37,7 @@ typedef struct _mp_obj_jsproxy_t {
 } mp_obj_jsproxy_t;
 
 extern const mp_obj_type_t mp_type_jsproxy;
+extern const mp_obj_type_t mp_type_JsException;
 
 void proxy_c_init(void);
 mp_obj_t proxy_convert_js_to_mp_obj_cside(uint32_t *value);
diff --git a/tests/ports/webassembly/await_error_handling.mjs b/tests/ports/webassembly/await_error_handling.mjs
new file mode 100644
index 0000000000000..067bc2513818e
--- /dev/null
+++ b/tests/ports/webassembly/await_error_handling.mjs
@@ -0,0 +1,22 @@
+// Test await'ing on a JavaScript async function that throws a JavaScript Error.
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+globalThis.foo = async () => {
+    console.log(2);
+    throw Error("test");
+};
+
+await mp.runPythonAsync(`
+import js, jsffi
+print(1)
+try:
+    await js.foo()
+except jsffi.JsException as er:
+    error = er
+print(error)
+print(3)
+`);
+
+const error = mp.globals.get("error");
+console.log(error instanceof Error, error.name, error.message);
diff --git a/tests/ports/webassembly/await_error_handling.mjs.exp b/tests/ports/webassembly/await_error_handling.mjs.exp
new file mode 100644
index 0000000000000..149f8914d488e
--- /dev/null
+++ b/tests/ports/webassembly/await_error_handling.mjs.exp
@@ -0,0 +1,5 @@
+1
+2
+(, 'Error', 'test')
+3
+true Error test

From fa23e4b093f81f03a24187c7ea0c928a9b4a661b Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Thu, 9 May 2024 15:36:30 +1000
Subject: [PATCH 369/408] webassembly/proxy_js: Convert JS undefined and JS
 null to Py None.

And change Py None conversion so it converts to JS undefined.

The semantics for conversion of these objects are then:
- Python None           -> JavaScript undefined
- JavaScript undefined  -> Python None
- JavaScript null       -> Python None

This follows Pyodide:
https://pyodide.org/en/stable/usage/type-conversions.html

Signed-off-by: Damien George 
---
 ports/webassembly/proxy_c.c                      | 5 ++++-
 ports/webassembly/proxy_js.js                    | 7 +++++--
 tests/ports/webassembly/py_proxy_to_js.mjs.exp   | 4 ++--
 tests/ports/webassembly/run_python_async.mjs.exp | 4 ++--
 4 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/ports/webassembly/proxy_c.c b/ports/webassembly/proxy_c.c
index 3097d6d3a4693..f8d6d85303e76 100644
--- a/ports/webassembly/proxy_c.c
+++ b/ports/webassembly/proxy_c.c
@@ -49,6 +49,7 @@ enum {
 };
 
 enum {
+    PROXY_KIND_JS_UNDEFINED = 0,
     PROXY_KIND_JS_NULL = 1,
     PROXY_KIND_JS_BOOLEAN = 2,
     PROXY_KIND_JS_INTEGER = 3,
@@ -78,7 +79,9 @@ static inline mp_obj_t proxy_c_get_obj(uint32_t c_ref) {
 }
 
 mp_obj_t proxy_convert_js_to_mp_obj_cside(uint32_t *value) {
-    if (value[0] == PROXY_KIND_JS_NULL) {
+    if (value[0] == PROXY_KIND_JS_UNDEFINED) {
+        return mp_const_none;
+    } else if (value[0] == PROXY_KIND_JS_NULL) {
         return mp_const_none;
     } else if (value[0] == PROXY_KIND_JS_BOOLEAN) {
         return mp_obj_new_bool(value[1]);
diff --git a/ports/webassembly/proxy_js.js b/ports/webassembly/proxy_js.js
index 042deb7b05c7f..05d0f2da4d8ae 100644
--- a/ports/webassembly/proxy_js.js
+++ b/ports/webassembly/proxy_js.js
@@ -38,6 +38,7 @@ const PROXY_KIND_MP_GENERATOR = 7;
 const PROXY_KIND_MP_OBJECT = 8;
 const PROXY_KIND_MP_JSPROXY = 9;
 
+const PROXY_KIND_JS_UNDEFINED = 0;
 const PROXY_KIND_JS_NULL = 1;
 const PROXY_KIND_JS_BOOLEAN = 2;
 const PROXY_KIND_JS_INTEGER = 3;
@@ -109,7 +110,9 @@ function proxy_call_python(target, argumentsList) {
 
 function proxy_convert_js_to_mp_obj_jsside(js_obj, out) {
     let kind;
-    if (js_obj === null) {
+    if (js_obj === undefined) {
+        kind = PROXY_KIND_JS_UNDEFINED;
+    } else if (js_obj === null) {
         kind = PROXY_KIND_JS_NULL;
     } else if (typeof js_obj === "boolean") {
         kind = PROXY_KIND_JS_BOOLEAN;
@@ -185,7 +188,7 @@ function proxy_convert_mp_to_js_obj_jsside(value) {
     }
     if (kind === PROXY_KIND_MP_NONE) {
         // None
-        obj = null;
+        obj = undefined;
     } else if (kind === PROXY_KIND_MP_BOOL) {
         // bool
         obj = Module.getValue(value + 4, "i32") ? true : false;
diff --git a/tests/ports/webassembly/py_proxy_to_js.mjs.exp b/tests/ports/webassembly/py_proxy_to_js.mjs.exp
index 279df7bdfbb84..3fd38c2b5672e 100644
--- a/tests/ports/webassembly/py_proxy_to_js.mjs.exp
+++ b/tests/ports/webassembly/py_proxy_to_js.mjs.exp
@@ -1,4 +1,4 @@
 false 1
 true [ 1, 2, 3 ]
-true [ null, true, 1.2 ]
-true { tuple: [ 1, 2, 3 ], one: 1, list: [ null, true, 1.2 ] }
+true [ undefined, true, 1.2 ]
+true { tuple: [ 1, 2, 3 ], one: 1, list: [ undefined, true, 1.2 ] }
diff --git a/tests/ports/webassembly/run_python_async.mjs.exp b/tests/ports/webassembly/run_python_async.mjs.exp
index f441bc5cf1db6..827f853b99b4a 100644
--- a/tests/ports/webassembly/run_python_async.mjs.exp
+++ b/tests/ports/webassembly/run_python_async.mjs.exp
@@ -23,7 +23,7 @@ py 1
 setTimeout resolved
 resolved value: 123
 py 2
-2 null
+2 undefined
 = TEST 4 ==========
 1
 py 1
@@ -35,4 +35,4 @@ py 3
 setTimeout B resolved
 resolved value: 456
 py 4
-2 null
+2 undefined

From 154d602b6e92cd5781d87291fa0e7455a14af334 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Tue, 14 May 2024 15:18:48 +1000
Subject: [PATCH 370/408] webassembly/mpconfigport: Enable importing of .mpy
 files.

Signed-off-by: Damien George 
---
 ports/webassembly/mpconfigport.h | 1 +
 tests/run-tests.py               | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/ports/webassembly/mpconfigport.h b/ports/webassembly/mpconfigport.h
index ae5dfa6fa50b8..ece7868fb95ab 100644
--- a/ports/webassembly/mpconfigport.h
+++ b/ports/webassembly/mpconfigport.h
@@ -39,6 +39,7 @@
 #endif
 
 #define MICROPY_ALLOC_PATH_MAX      (256)
+#define MICROPY_PERSISTENT_CODE_LOAD (1)
 #define MICROPY_COMP_ALLOW_TOP_LEVEL_AWAIT (1)
 #define MICROPY_READER_VFS          (MICROPY_VFS)
 #define MICROPY_ENABLE_GC           (1)
diff --git a/tests/run-tests.py b/tests/run-tests.py
index 8acdcd2b36204..1e1bd160af3c9 100755
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -702,7 +702,6 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1):
             skip_tests.add("micropython/emg_exc.py")
             skip_tests.add("micropython/extreme_exc.py")
             skip_tests.add("micropython/heapalloc_exc_compressed_emg_exc.py")
-            skip_tests.add("micropython/import_mpy_invalid.py")
 
     # Some tests are known to fail on 64-bit machines
     if pyb is None and platform.architecture()[0] == "64bit":

From 025d10a702c0815946418f37300f64fdba43f371 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Tue, 14 May 2024 15:19:30 +1000
Subject: [PATCH 371/408] tests/micropython/import_mpy_invalid.py: Skip if
 target cant import mpy.

Signed-off-by: Damien George 
---
 tests/micropython/import_mpy_invalid.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/micropython/import_mpy_invalid.py b/tests/micropython/import_mpy_invalid.py
index c7f0a2c1a1c61..89fdf44839bb1 100644
--- a/tests/micropython/import_mpy_invalid.py
+++ b/tests/micropython/import_mpy_invalid.py
@@ -3,6 +3,7 @@
 try:
     import sys, io, vfs
 
+    sys.implementation._mpy
     io.IOBase
 except (ImportError, AttributeError):
     print("SKIP")

From 85c85e8f0d6e44827553f67a4ab67c2cb3078fdd Mon Sep 17 00:00:00 2001
From: Olivier Lenoir 
Date: Wed, 13 Mar 2024 21:51:22 +0100
Subject: [PATCH 372/408] tools/mpremote: Add support to mip install from
 GitLab.

Changes are:
- main.py: Add gitlab:org/repo, gitlab:org/repo@branch.
- mip.py: Implement install from GitLab.
- README.md: Add mip install gitlab:org/repo@branch example.

Signed-off-by: Olivier Lenoir 
---
 tools/mpremote/README.md        |  1 +
 tools/mpremote/mpremote/main.py |  2 +-
 tools/mpremote/mpremote/mip.py  | 13 +++++++++++++
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/tools/mpremote/README.md b/tools/mpremote/README.md
index 4eb1b86fb4dbf..3d428f12874d8 100644
--- a/tools/mpremote/README.md
+++ b/tools/mpremote/README.md
@@ -80,3 +80,4 @@ Examples:
     mpremote cp -r dir/ :
     mpremote mip install aioble
     mpremote mip install github:org/repo@branch
+    mpremote mip install gitlab:org/repo@branch
diff --git a/tools/mpremote/mpremote/main.py b/tools/mpremote/mpremote/main.py
index eeb9cbd989389..e4d15fb47c69b 100644
--- a/tools/mpremote/mpremote/main.py
+++ b/tools/mpremote/mpremote/main.py
@@ -214,7 +214,7 @@ def argparse_mip():
     cmd_parser.add_argument(
         "packages",
         nargs="+",
-        help="list package specifications, e.g. name, name@version, github:org/repo, github:org/repo@branch",
+        help="list package specifications, e.g. name, name@version, github:org/repo, github:org/repo@branch, gitlab:org/repo, gitlab:org/repo@branch",
     )
     return cmd_parser
 
diff --git a/tools/mpremote/mpremote/mip.py b/tools/mpremote/mpremote/mip.py
index f42c7a0b4293b..46c9686ad1987 100644
--- a/tools/mpremote/mpremote/mip.py
+++ b/tools/mpremote/mpremote/mip.py
@@ -65,6 +65,18 @@ def _rewrite_url(url, branch=None):
             + "/"
             + "/".join(url[2:])
         )
+    elif url.startswith("gitlab:"):
+        url = url[7:].split("/")
+        url = (
+            "https://gitlab.com/"
+            + url[0]
+            + "/"
+            + url[1]
+            + "/-/raw/"
+            + branch
+            + "/"
+            + "/".join(url[2:])
+        )
     return url
 
 
@@ -116,6 +128,7 @@ def _install_package(transport, package, index, target, version, mpy):
         package.startswith("http://")
         or package.startswith("https://")
         or package.startswith("github:")
+        or package.startswith("gitlab:")
     ):
         if package.endswith(".py") or package.endswith(".mpy"):
             print(f"Downloading {package} to {target}")

From e816b49c44f70ec2ca28cb5a2caefc7446a6c8e5 Mon Sep 17 00:00:00 2001
From: Olivier Lenoir 
Date: Wed, 13 Mar 2024 21:57:06 +0100
Subject: [PATCH 373/408] docs/reference: Document how to mip install packages
 from GitLab.

Signed-off-by: Olivier Lenoir 
---
 docs/reference/mpremote.rst |  7 +++++++
 docs/reference/packages.rst | 17 ++++++++++++-----
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/docs/reference/mpremote.rst b/docs/reference/mpremote.rst
index 08ef5d31ff572..bf25e29d93d9c 100644
--- a/docs/reference/mpremote.rst
+++ b/docs/reference/mpremote.rst
@@ -682,6 +682,13 @@ See :ref:`packages`.
 Install the package from the specified branch at org/repo on GitHub to the
 device. See :ref:`packages`.
 
+.. code-block:: bash
+
+  mpremote mip install gitlab:org/repo@branch
+
+Install the package from the specified branch at org/repo on GitLab to the
+device. See :ref:`packages`.
+
 .. code-block:: bash
 
   mpremote mip install --target /flash/third-party functools
diff --git a/docs/reference/packages.rst b/docs/reference/packages.rst
index c9deedea771c3..e47c226b24187 100644
--- a/docs/reference/packages.rst
+++ b/docs/reference/packages.rst
@@ -7,7 +7,7 @@ Installing packages with ``mip``
 --------------------------------
 
 Network-capable boards include the ``mip`` module, which can install packages
-from :term:`micropython-lib` and from third-party sites (including GitHub).
+from :term:`micropython-lib` and from third-party sites (including GitHub, GitLab).
 
 ``mip`` ("mip installs packages") is similar in concept to Python's ``pip`` tool,
 however it does not use the PyPI index, rather it uses :term:`micropython-lib`
@@ -38,24 +38,28 @@ install third-party libraries. The simplest way is to download a file directly::
 When installing a file directly, the ``target`` argument is still supported to set
 the destination path, but ``mpy`` and ``version`` are ignored.
 
-The URL can also start with ``github:`` as a simple way of pointing to content
-hosted on GitHub::
+The URL can also start with ``github:`` or ``gitlab:`` as a simple way of pointing to content
+hosted on GitHub or GitLab::
 
     >>> mip.install("github:org/repo/path/foo.py")  # Uses default branch
     >>> mip.install("github:org/repo/path/foo.py", version="branch-or-tag")  # Optionally specify the branch or tag
+    >>> mip.install("gitlab:org/repo/path/foo.py")  # Uses default branch
+    >>> mip.install("gitlab:org/repo/path/foo.py", version="branch-or-tag")  # Optionally specify the branch or tag
 
 More sophisticated packages (i.e. with more than one file, or with dependencies)
 can be downloaded by specifying the path to their ``package.json``.
 
     >>> mip.install("http://example.com/x/package.json")
     >>> mip.install("github:org/user/path/package.json")
+    >>> mip.install("gitlab:org/user/path/package.json")
 
 If no json file is specified, then "package.json" is implicitly added::
 
     >>> mip.install("http://example.com/x/")
     >>> mip.install("github:org/repo")  # Uses default branch of that repo
     >>> mip.install("github:org/repo", version="branch-or-tag")
-
+    >>> mip.install("gitlab:org/repo")  # Uses default branch of that repo
+    >>> mip.install("gitlab:org/repo", version="branch-or-tag")
 
 Using ``mip`` on the Unix port
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -83,6 +87,8 @@ can be used from a host PC to install packages to a locally connected device
     $ mpremote mip install http://example.com/x/y/foo.py
     $ mpremote mip install github:org/repo
     $ mpremote mip install github:org/repo@branch-or-tag
+    $ mpremote mip install gitlab:org/repo
+    $ mpremote mip install gitlab:org/repo@branch-or-tag
 
 The ``--target=path``, ``--no-mpy``, and ``--index`` arguments can be set::
 
@@ -120,7 +126,8 @@ A typical ``package.json`` for an example ``mlx90640`` library looks like::
       "deps": [
         ["collections-defaultdict", "latest"],
         ["os-path", "latest"],
-        ["github:org/micropython-additions", "main"]
+        ["github:org/micropython-additions", "main"],
+        ["gitlab:org/micropython-otheradditions", "main"]
       ],
       "version": "0.2"
     }

From abd1f28bc20a220658cfec8f03169edfd0097421 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Wed, 15 May 2024 14:13:30 +1000
Subject: [PATCH 374/408] docs/library/asyncio: Document that ThreadSafeFlag
 now works on unix.

ThreadSafeFlag works on the unix port since commit
df08c38c286561c08d5ac354428074817eb0c163.

Signed-off-by: Damien George 
---
 docs/library/asyncio.rst | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/docs/library/asyncio.rst b/docs/library/asyncio.rst
index b57f1ee04eaec..51ad8a2876a34 100644
--- a/docs/library/asyncio.rst
+++ b/docs/library/asyncio.rst
@@ -149,8 +149,7 @@ class ThreadSafeFlag
 
     Create a new flag which can be used to synchronise a task with code running
     outside the asyncio loop, such as other threads, IRQs, or scheduler
-    callbacks.  Flags start in the cleared state.  The class does not currently
-    work under the Unix build of MicroPython.
+    callbacks.  Flags start in the cleared state.
 
 .. method:: ThreadSafeFlag.set()
 

From 47ae73940983caa2d109e7c4e5192db8294748f2 Mon Sep 17 00:00:00 2001
From: Angus Gratton 
Date: Tue, 14 May 2024 10:24:11 +1000
Subject: [PATCH 375/408] examples/usb: Add README that points out the
 alternative usb modules.

If someone starts from this directory then they won't know they exist,
otherwise.

Signed-off-by: Angus Gratton 
---
 examples/usb/README.md | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 examples/usb/README.md

diff --git a/examples/usb/README.md b/examples/usb/README.md
new file mode 100644
index 0000000000000..b3dad17633231
--- /dev/null
+++ b/examples/usb/README.md
@@ -0,0 +1,16 @@
+## USBDevice Examples
+
+These are examples of how to use the low-level `machine.USBDevice` class to create custom
+USB device functionality.
+
+Alternatively, there are [usb driver modules in
+micropython-lib](https://github.com/micropython/micropython-lib/tree/master/micropython/usb#readme)
+which provide a simpler interface and more built-in functionality.
+
+In this directory:
+
+* `usb_dfu_device.py` implements the USB Device Firmware Update protocol.
+* `usb_simple_device.py` implements a custom USB protocol, with a matching host
+  program to run on a PC.
+
+See comments at the top of each Python file for more details.

From a0d4fdcce0aa332770065707a63be6b9b1aa1617 Mon Sep 17 00:00:00 2001
From: Angus Gratton 
Date: Wed, 15 May 2024 11:19:21 +1000
Subject: [PATCH 376/408] stm32/pyb_can: Fix STM32G4 FDCAN source clock
 frequency.

Fixes automatic baudrate calculation results.

Default clock source on this SoC is HSE not PCLK1.  We could fix this by
switching to PCLK1 instead, but two extra complications:

- PCLK1 on this board is a 42.5MHz and the Pyboard CAN sample_point
  calculation requires an exact match, which is harder to hit with this
  source frequency.

- Would be a breaking change for any existing Python code on this board,
  i.e. specifying brp, bs1, bs2 to initialise CAN.

In the future it might be worth looking switching to the PLL source on this
SoC instead, as this is a much higher frequency that would give higher
quality BRS bitrate matches (probably too high without using the second
divider going into the CAN peripheral though, so more code changes needed
also).

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton 
---
 ports/stm32/pyb_can.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/ports/stm32/pyb_can.c b/ports/stm32/pyb_can.c
index 71c717782449f..563758831cc5e 100644
--- a/ports/stm32/pyb_can.c
+++ b/ports/stm32/pyb_can.c
@@ -182,7 +182,10 @@ static uint32_t pyb_can_get_source_freq() {
             break;
         }
     }
-    #else // F4 and F7 and assume other MCUs too.
+    #elif defined(STM32G4)
+    // STM32G4 CAN clock from reset is HSE, unchanged by MicroPython
+    can_kern_clk = HSE_VALUE;
+    #else // G0, F4, F7 and assume other MCUs too.
     // CAN1/CAN2/CAN3 on APB1 use GetPCLK1Freq, alternatively use the following:
     // can_kern_clk = ((HSE_VALUE / osc_config.PLL.PLLM ) * osc_config.PLL.PLLN) /
     //  (osc_config.PLL.PLLQ * clk_init.AHBCLKDivider * clk_init.APB1CLKDivider);

From c10a74b1625f668edddf9e76719584165473143b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dani=C3=ABl=20van=20de=20Giessen?= 
Date: Wed, 13 Mar 2024 18:23:17 +0100
Subject: [PATCH 377/408] esp32/panichandler: Print support information on
 panic.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When a fatal error occurs it's important to know which precise version it
occurred on in order to be able to decode the crash dump information such
as the backtrace.

By wrapping around the built-in IDF panic handler we can print some extra
information whenever a fatal error occurs.  The message links to a new wiki
page which contains additional information on how to debug ESP32 issues,
and links to the bug reporting issue template.

Signed-off-by: Daniël van de Giessen 
---
 ports/esp32/CMakeLists.txt     |  3 ++
 ports/esp32/esp32_common.cmake |  1 +
 ports/esp32/panichandler.c     | 68 ++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+)
 create mode 100644 ports/esp32/panichandler.c

diff --git a/ports/esp32/CMakeLists.txt b/ports/esp32/CMakeLists.txt
index 1537c1d723276..3fe0830025579 100644
--- a/ports/esp32/CMakeLists.txt
+++ b/ports/esp32/CMakeLists.txt
@@ -59,5 +59,8 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake)
 # Set the location of the main component for the project (one per target).
 list(APPEND EXTRA_COMPONENT_DIRS main_${IDF_TARGET})
 
+# Enable the panic handler wrapper
+idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=esp_panic_handler" APPEND)
+
 # Define the project.
 project(micropython)
diff --git a/ports/esp32/esp32_common.cmake b/ports/esp32/esp32_common.cmake
index 89e46f9cfb3df..e928fb439da5e 100644
--- a/ports/esp32/esp32_common.cmake
+++ b/ports/esp32/esp32_common.cmake
@@ -53,6 +53,7 @@ list(APPEND MICROPY_SOURCE_DRIVERS
 )
 
 list(APPEND MICROPY_SOURCE_PORT
+    panichandler.c
     adc.c
     main.c
     ppp_set_auth.c
diff --git a/ports/esp32/panichandler.c b/ports/esp32/panichandler.c
new file mode 100644
index 0000000000000..e6ff98ded272e
--- /dev/null
+++ b/ports/esp32/panichandler.c
@@ -0,0 +1,68 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2024 Mindhash B.V.
+ *
+ * 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 "genhdr/mpversion.h"
+#include "py/mpconfig.h"
+
+#ifdef MICROPY_BUILD_TYPE
+#define MICROPY_BUILD_TYPE_PAREN " (" MICROPY_BUILD_TYPE ")"
+#else
+#define MICROPY_BUILD_TYPE_PAREN
+#endif
+
+#ifdef CONFIG_ESP_PANIC_HANDLER_IRAM
+#define MICROPY_WRAP_PANICHANDLER_FUN(f) IRAM_ATTR f
+#define MICROPY_WRAP_PANICHANDLER_STR(s) DRAM_STR(s)
+#else
+#define MICROPY_WRAP_PANICHANDLER_FUN(f) f
+#define MICROPY_WRAP_PANICHANDLER_STR(s) (s)
+#endif
+
+void __real_esp_panic_handler(void *);
+void esp_panic_handler_reconfigure_wdts(uint32_t timeout_ms);
+void panic_print_str(const char *str);
+
+void MICROPY_WRAP_PANICHANDLER_FUN(__wrap_esp_panic_handler)(void *info) {
+    esp_panic_handler_reconfigure_wdts(1000);
+
+    const static char *msg = MICROPY_WRAP_PANICHANDLER_STR(
+        "\r\n"
+        "A fatal error occurred. The crash dump printed below may be used to help\r\n"
+        "determine what caused it. If you are not already running the most recent\r\n"
+        "version of MicroPython, consider upgrading. New versions often fix bugs.\r\n"
+        "\r\n"
+        "To learn more about how to debug and/or report this crash visit the wiki\r\n"
+        "page at: https://github.com/micropython/micropython/wiki/ESP32-debugging\r\n"
+        "\r\n"
+        "MPY version : " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE MICROPY_BUILD_TYPE_PAREN "\r\n"
+        "IDF version : " IDF_VER "\r\n"
+        "Machine     : " MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME "\r\n"
+        "\r\n"
+        );
+    panic_print_str(msg);
+
+    __real_esp_panic_handler(info);
+}

From 0148bbb495d6bacf66c00e730818cbb8eca45ffb Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Tue, 14 May 2024 21:54:14 +1000
Subject: [PATCH 378/408] webassembly/proxy_js: Revert back to converting Py
 None to JS null.

This reverts part of commit fa23e4b093f81f03a24187c7ea0c928a9b4a661b, to
make it so that Python `None` converts to JavaScript `null` (and JavaScript
`null` already converts to Python `None`).  That's consistent with how the
`json` module converts these values back and forth.

Signed-off-by: Damien George 
---
 ports/webassembly/proxy_js.js                    | 2 +-
 tests/ports/webassembly/py_proxy_to_js.mjs.exp   | 4 ++--
 tests/ports/webassembly/run_python_async.mjs.exp | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/ports/webassembly/proxy_js.js b/ports/webassembly/proxy_js.js
index 05d0f2da4d8ae..f1f273d6b30a5 100644
--- a/ports/webassembly/proxy_js.js
+++ b/ports/webassembly/proxy_js.js
@@ -188,7 +188,7 @@ function proxy_convert_mp_to_js_obj_jsside(value) {
     }
     if (kind === PROXY_KIND_MP_NONE) {
         // None
-        obj = undefined;
+        obj = null;
     } else if (kind === PROXY_KIND_MP_BOOL) {
         // bool
         obj = Module.getValue(value + 4, "i32") ? true : false;
diff --git a/tests/ports/webassembly/py_proxy_to_js.mjs.exp b/tests/ports/webassembly/py_proxy_to_js.mjs.exp
index 3fd38c2b5672e..279df7bdfbb84 100644
--- a/tests/ports/webassembly/py_proxy_to_js.mjs.exp
+++ b/tests/ports/webassembly/py_proxy_to_js.mjs.exp
@@ -1,4 +1,4 @@
 false 1
 true [ 1, 2, 3 ]
-true [ undefined, true, 1.2 ]
-true { tuple: [ 1, 2, 3 ], one: 1, list: [ undefined, true, 1.2 ] }
+true [ null, true, 1.2 ]
+true { tuple: [ 1, 2, 3 ], one: 1, list: [ null, true, 1.2 ] }
diff --git a/tests/ports/webassembly/run_python_async.mjs.exp b/tests/ports/webassembly/run_python_async.mjs.exp
index 827f853b99b4a..f441bc5cf1db6 100644
--- a/tests/ports/webassembly/run_python_async.mjs.exp
+++ b/tests/ports/webassembly/run_python_async.mjs.exp
@@ -23,7 +23,7 @@ py 1
 setTimeout resolved
 resolved value: 123
 py 2
-2 undefined
+2 null
 = TEST 4 ==========
 1
 py 1
@@ -35,4 +35,4 @@ py 3
 setTimeout B resolved
 resolved value: 456
 py 4
-2 undefined
+2 null

From aa2e3880c13036c65aa3381ed5f104c59ebad86e Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Tue, 14 May 2024 21:56:36 +1000
Subject: [PATCH 379/408] webassembly/proxy_js: Create a special "undefined"
 type for Python.

This adds a new undefined singleton to Python, that corresponds directly to
JavaScript `undefined`.  It's accessible via `js.undefined`.

Signed-off-by: Damien George 
---
 ports/webassembly/README.md                       | 12 ++++++++++++
 ports/webassembly/proxy_c.c                       | 15 ++++++++++++++-
 ports/webassembly/proxy_js.js                     |  2 +-
 .../webassembly/await_error_handling.mjs.exp      |  2 +-
 .../ports/webassembly/jsffi_create_proxy.mjs.exp  |  2 +-
 tests/ports/webassembly/jsffi_to_js.mjs.exp       |  2 +-
 tests/ports/webassembly/register_js_module.js.exp |  2 +-
 tests/ports/webassembly/run_python_async.mjs.exp  |  8 ++++----
 8 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/ports/webassembly/README.md b/ports/webassembly/README.md
index af395778a748e..97cb397fd495d 100644
--- a/ports/webassembly/README.md
+++ b/ports/webassembly/README.md
@@ -160,6 +160,18 @@ context, created and returned by `loadMicroPython()`.
 - `replProcessCharWithAsyncify(chr)`: process an incoming character at the REPL,
   for use when ASYNCIFY is enabled.
 
+Type conversions
+----------------
+
+Read-only objects (booleanns, numbers, strings, etc) are converted when passed between
+Python and JavaScript.  The conversions are:
+
+- JavaScript `null` converts to/from Python `None`.
+- JavaScript `undefined` converts to/from Python `js.undefined`.
+
+The conversion between `null` and `None` matches the behaviour of the Python `json`
+module.
+
 Proxying
 --------
 
diff --git a/ports/webassembly/proxy_c.c b/ports/webassembly/proxy_c.c
index f8d6d85303e76..b55740175b283 100644
--- a/ports/webassembly/proxy_c.c
+++ b/ports/webassembly/proxy_c.c
@@ -59,6 +59,16 @@ enum {
     PROXY_KIND_JS_PYPROXY = 7,
 };
 
+MP_DEFINE_CONST_OBJ_TYPE(
+    mp_type_undefined,
+    MP_QSTR_undefined,
+    MP_TYPE_FLAG_NONE
+    );
+
+static const mp_obj_base_t mp_const_undefined_obj = {&mp_type_undefined};
+
+#define mp_const_undefined (MP_OBJ_FROM_PTR(&mp_const_undefined_obj))
+
 MP_DEFINE_EXCEPTION(JsException, Exception)
 
 void proxy_c_init(void) {
@@ -80,7 +90,7 @@ static inline mp_obj_t proxy_c_get_obj(uint32_t c_ref) {
 
 mp_obj_t proxy_convert_js_to_mp_obj_cside(uint32_t *value) {
     if (value[0] == PROXY_KIND_JS_UNDEFINED) {
-        return mp_const_none;
+        return mp_const_undefined;
     } else if (value[0] == PROXY_KIND_JS_NULL) {
         return mp_const_none;
     } else if (value[0] == PROXY_KIND_JS_BOOLEAN) {
@@ -122,6 +132,9 @@ void proxy_convert_mp_to_js_obj_cside(mp_obj_t obj, uint32_t *out) {
         const char *str = mp_obj_str_get_data(obj, &len);
         out[1] = len;
         out[2] = (uintptr_t)str;
+    } else if (obj == mp_const_undefined) {
+        kind = PROXY_KIND_MP_JSPROXY;
+        out[1] = 1;
     } else if (mp_obj_is_jsproxy(obj)) {
         kind = PROXY_KIND_MP_JSPROXY;
         out[1] = mp_obj_jsproxy_get_ref(obj);
diff --git a/ports/webassembly/proxy_js.js b/ports/webassembly/proxy_js.js
index f1f273d6b30a5..2a34f01a7b511 100644
--- a/ports/webassembly/proxy_js.js
+++ b/ports/webassembly/proxy_js.js
@@ -56,7 +56,7 @@ class PythonError extends Error {
 }
 
 function proxy_js_init() {
-    globalThis.proxy_js_ref = [globalThis];
+    globalThis.proxy_js_ref = [globalThis, undefined];
 }
 
 function proxy_call_python(target, argumentsList) {
diff --git a/tests/ports/webassembly/await_error_handling.mjs.exp b/tests/ports/webassembly/await_error_handling.mjs.exp
index 149f8914d488e..0c8eb52f20fdb 100644
--- a/tests/ports/webassembly/await_error_handling.mjs.exp
+++ b/tests/ports/webassembly/await_error_handling.mjs.exp
@@ -1,5 +1,5 @@
 1
 2
-(, 'Error', 'test')
+(, 'Error', 'test')
 3
 true Error test
diff --git a/tests/ports/webassembly/jsffi_create_proxy.mjs.exp b/tests/ports/webassembly/jsffi_create_proxy.mjs.exp
index a3b38a78b1132..5e541f0b0d8a5 100644
--- a/tests/ports/webassembly/jsffi_create_proxy.mjs.exp
+++ b/tests/ports/webassembly/jsffi_create_proxy.mjs.exp
@@ -1,5 +1,5 @@
 1
-
+
 1
 1
 PyProxy { _ref: 3 }
diff --git a/tests/ports/webassembly/jsffi_to_js.mjs.exp b/tests/ports/webassembly/jsffi_to_js.mjs.exp
index 399dd0aa8c9cb..6cfd123c01777 100644
--- a/tests/ports/webassembly/jsffi_to_js.mjs.exp
+++ b/tests/ports/webassembly/jsffi_to_js.mjs.exp
@@ -1,6 +1,6 @@
 1
-
 
+
 false
 1
 true
diff --git a/tests/ports/webassembly/register_js_module.js.exp b/tests/ports/webassembly/register_js_module.js.exp
index bb45f4ce00285..6e2bad3ce56fb 100644
--- a/tests/ports/webassembly/register_js_module.js.exp
+++ b/tests/ports/webassembly/register_js_module.js.exp
@@ -1,2 +1,2 @@
-
+
 2
diff --git a/tests/ports/webassembly/run_python_async.mjs.exp b/tests/ports/webassembly/run_python_async.mjs.exp
index f441bc5cf1db6..ad6c49e336e5c 100644
--- a/tests/ports/webassembly/run_python_async.mjs.exp
+++ b/tests/ports/webassembly/run_python_async.mjs.exp
@@ -1,17 +1,17 @@
 = TEST 1 ==========
 1
-
+
 py 1
-
+
 py 2
 2
 resolved 123
 3
 = TEST 2 ==========
 1
-
+
 py 1
-
+
 py 2
 2
 setTimeout resolved

From cfd5a8ea3a80930a79dbae6a6aff54587393d0b8 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Tue, 14 May 2024 22:15:48 +1000
Subject: [PATCH 380/408] webassembly/proxy_c: Return undefined if dict lookup
 failed on JS side.

Instead of raising KeyError.  These semantics match JavaScript behaviour
and make it much more seamless to pass Python dicts through to JavaScript
as though they were JavaScript {} objects.

Signed-off-by: Damien George 
---
 ports/webassembly/README.md                   |  4 ++-
 ports/webassembly/proxy_c.c                   | 11 +++++-
 .../webassembly/py_proxy_dict_undefined.mjs   | 34 +++++++++++++++++++
 .../py_proxy_dict_undefined.mjs.exp           | 11 ++++++
 4 files changed, 58 insertions(+), 2 deletions(-)
 create mode 100644 tests/ports/webassembly/py_proxy_dict_undefined.mjs
 create mode 100644 tests/ports/webassembly/py_proxy_dict_undefined.mjs.exp

diff --git a/ports/webassembly/README.md b/ports/webassembly/README.md
index 97cb397fd495d..8a3029aa07610 100644
--- a/ports/webassembly/README.md
+++ b/ports/webassembly/README.md
@@ -182,4 +182,6 @@ A Python `dict` instance is proxied such that:
     }
 
 works as expected on the JavaScript side and iterates through the keys of the
-Python `dict`.
+Python `dict`.  Furthermore, when JavaScript accesses a key that does not exist
+in the Python dict, the JavaScript code receives `undefined` instead of a
+`KeyError` exception being raised.
diff --git a/ports/webassembly/proxy_c.c b/ports/webassembly/proxy_c.c
index b55740175b283..7d5b623686b58 100644
--- a/ports/webassembly/proxy_c.c
+++ b/ports/webassembly/proxy_c.c
@@ -241,8 +241,17 @@ void proxy_c_to_js_lookup_attr(uint32_t c_ref, const char *attr_in, uint32_t *ou
         qstr attr = qstr_from_str(attr_in);
         mp_obj_t member;
         if (mp_obj_is_dict_or_ordereddict(obj)) {
-            member = mp_obj_dict_get(obj, MP_OBJ_NEW_QSTR(attr));
+            // Lookup the requested attribute as a key in the target dict, and
+            // return `undefined` if not found (instead of raising `KeyError`).
+            mp_obj_dict_t *self = MP_OBJ_TO_PTR(obj);
+            mp_map_elem_t *elem = mp_map_lookup(&self->map, MP_OBJ_NEW_QSTR(attr), MP_MAP_LOOKUP);
+            if (elem == NULL) {
+                member = mp_const_undefined;
+            } else {
+                member = elem->value;
+            }
         } else {
+            // Lookup the requested attribute as a member/method of the target object.
             member = mp_load_attr(obj, attr);
         }
         nlr_pop();
diff --git a/tests/ports/webassembly/py_proxy_dict_undefined.mjs b/tests/ports/webassembly/py_proxy_dict_undefined.mjs
new file mode 100644
index 0000000000000..d47a6a028b61f
--- /dev/null
+++ b/tests/ports/webassembly/py_proxy_dict_undefined.mjs
@@ -0,0 +1,34 @@
+// Test passing a Python dict into JavaScript, how it behaves with undefined keys.
+// If JavaScript accesses a key that does not exist, `undefined` should be returned.
+// This is different to Python-side behaviour, where `KeyError` is raised.
+
+const mp = await (await import(process.argv[2])).loadMicroPython();
+
+// Create a JavaScript function with default arguments.
+// When `value` is `undefined` it will receive its default.
+function withDefault({ value = "OK" } = {}) {
+    console.log(value);
+}
+
+globalThis.withDefault = withDefault;
+
+// Call the function from JavaScript with various arguments.
+withDefault();
+withDefault({});
+withDefault({ value: null });
+withDefault({ value: undefined });
+withDefault({ value: () => {} });
+
+console.log("====");
+
+// Call the function from Python with the same arguments as above.
+// The results should be the same.
+mp.runPython(`
+import js
+
+js.withDefault()
+js.withDefault({})
+js.withDefault({"value": None})
+js.withDefault({"value": js.undefined})
+js.withDefault({"value": (lambda: {})})
+`);
diff --git a/tests/ports/webassembly/py_proxy_dict_undefined.mjs.exp b/tests/ports/webassembly/py_proxy_dict_undefined.mjs.exp
new file mode 100644
index 0000000000000..6cf5b9fa128f9
--- /dev/null
+++ b/tests/ports/webassembly/py_proxy_dict_undefined.mjs.exp
@@ -0,0 +1,11 @@
+OK
+OK
+null
+OK
+[Function: value]
+====
+OK
+OK
+null
+OK
+[Function: obj] { _ref: 7 }

From d7f031397d9e793de5c05184a4957dc4e3a4bacb Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Tue, 21 May 2024 11:37:37 +1000
Subject: [PATCH 381/408] webassembly/objjsproxy: Make jsproxy_it keep ref to
 jsproxy.

So that there is a one-to-one correspondence between js_ref and
JsProxy objects.

Signed-off-by: Damien George 
---
 ports/webassembly/objjsproxy.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/ports/webassembly/objjsproxy.c b/ports/webassembly/objjsproxy.c
index b575839d982e5..05fe715162a74 100644
--- a/ports/webassembly/objjsproxy.c
+++ b/ports/webassembly/objjsproxy.c
@@ -300,7 +300,7 @@ void mp_obj_jsproxy_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
 typedef struct _jsproxy_it_t {
     mp_obj_base_t base;
     mp_fun_1_t iternext;
-    int ref;
+    mp_obj_jsproxy_t *obj;
     uint16_t cur;
     uint16_t len;
 } jsproxy_it_t;
@@ -309,7 +309,7 @@ static mp_obj_t jsproxy_it_iternext(mp_obj_t self_in) {
     jsproxy_it_t *self = MP_OBJ_TO_PTR(self_in);
     if (self->cur < self->len) {
         uint32_t out[3];
-        js_subscr_int(self->ref, self->cur, out);
+        js_subscr_int(self->obj->ref, self->cur, out);
         self->cur += 1;
         return proxy_convert_js_to_mp_obj_cside(out);
     } else {
@@ -323,7 +323,7 @@ static mp_obj_t jsproxy_new_it(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) {
     jsproxy_it_t *o = (jsproxy_it_t *)iter_buf;
     o->base.type = &mp_type_polymorph_iter;
     o->iternext = jsproxy_it_iternext;
-    o->ref = self->ref;
+    o->obj = self;
     o->cur = 0;
     o->len = js_get_len(self->ref);
     return MP_OBJ_FROM_PTR(o);

From ed2885facbf0393046bd9560a8912c52d47f2aab Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Tue, 21 May 2024 11:38:46 +1000
Subject: [PATCH 382/408] webassembly/proxy_c: Don't return value of a void
 function.

Signed-off-by: Damien George 
---
 ports/webassembly/proxy_c.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/ports/webassembly/proxy_c.c b/ports/webassembly/proxy_c.c
index 7d5b623686b58..2ab92303d2db3 100644
--- a/ports/webassembly/proxy_c.c
+++ b/ports/webassembly/proxy_c.c
@@ -210,10 +210,10 @@ void proxy_c_to_js_dir(uint32_t c_ref, uint32_t *out) {
             dir = mp_builtin_dir_obj.fun.var(1, args);
         }
         nlr_pop();
-        return proxy_convert_mp_to_js_obj_cside(dir, out);
+        proxy_convert_mp_to_js_obj_cside(dir, out);
     } else {
         // uncaught exception
-        return proxy_convert_mp_to_js_exc_cside(nlr.ret_val, out);
+        proxy_convert_mp_to_js_exc_cside(nlr.ret_val, out);
     }
 }
 
@@ -255,10 +255,10 @@ void proxy_c_to_js_lookup_attr(uint32_t c_ref, const char *attr_in, uint32_t *ou
             member = mp_load_attr(obj, attr);
         }
         nlr_pop();
-        return proxy_convert_mp_to_js_obj_cside(member, out);
+        proxy_convert_mp_to_js_obj_cside(member, out);
     } else {
         // uncaught exception
-        return proxy_convert_mp_to_js_exc_cside(nlr.ret_val, out);
+        proxy_convert_mp_to_js_exc_cside(nlr.ret_val, out);
     }
 }
 
@@ -482,9 +482,9 @@ void proxy_c_to_js_resume(uint32_t c_ref, uint32_t *args) {
         mp_obj_t reject = proxy_convert_js_to_mp_obj_cside(args + 2 * 3);
         mp_obj_t ret = proxy_resume_execute(obj, mp_const_none, mp_const_none, resolve, reject);
         nlr_pop();
-        return proxy_convert_mp_to_js_obj_cside(ret, args);
+        proxy_convert_mp_to_js_obj_cside(ret, args);
     } else {
         // uncaught exception
-        return proxy_convert_mp_to_js_exc_cside(nlr.ret_val, args);
+        proxy_convert_mp_to_js_exc_cside(nlr.ret_val, args);
     }
 }

From cdaf2de80cd875da4644455673e81af261f1f3ee Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Tue, 21 May 2024 11:36:41 +1000
Subject: [PATCH 383/408] webassembly: Track the current depth of calls to
 external C functions.

So it's possible to know when an external C function is being called at the
top-level, eg by JavaScript without any intermediate C->JS->C calls.

Signed-off-by: Damien George 
---
 ports/webassembly/main.c    | 24 ++++++++++++++++++++++-
 ports/webassembly/proxy_c.c | 39 +++++++++++++++++++++++++++++--------
 ports/webassembly/proxy_c.h |  3 +++
 3 files changed, 57 insertions(+), 9 deletions(-)

diff --git a/ports/webassembly/main.c b/ports/webassembly/main.c
index 23d12b6dbbc76..fd331f8dcb486 100644
--- a/ports/webassembly/main.c
+++ b/ports/webassembly/main.c
@@ -44,6 +44,19 @@
 #include "library.h"
 #include "proxy_c.h"
 
+// This counter tracks the current depth of calls into C code that originated
+// externally, ie from JavaScript.  When the counter is 0 that corresponds to
+// the top-level call into C.
+static size_t external_call_depth = 0;
+
+void external_call_depth_inc(void) {
+    ++external_call_depth;
+}
+
+void external_call_depth_dec(void) {
+    --external_call_depth;
+}
+
 void mp_js_init(int heap_size) {
     #if MICROPY_ENABLE_GC
     char *heap = (char *)malloc(heap_size * sizeof(char));
@@ -79,6 +92,7 @@ void mp_js_register_js_module(const char *name, uint32_t *value) {
 }
 
 void mp_js_do_import(const char *name, uint32_t *out) {
+    external_call_depth_inc();
     nlr_buf_t nlr;
     if (nlr_push(&nlr) == 0) {
         mp_obj_t ret = mp_import_name(qstr_from_str(name), mp_const_none, MP_OBJ_NEW_SMALL_INT(0));
@@ -97,9 +111,11 @@ void mp_js_do_import(const char *name, uint32_t *out) {
             }
         }
         nlr_pop();
+        external_call_depth_dec();
         proxy_convert_mp_to_js_obj_cside(ret, out);
     } else {
         // uncaught exception
+        external_call_depth_dec();
         proxy_convert_mp_to_js_exc_cside(nlr.ret_val, out);
     }
 }
@@ -109,6 +125,7 @@ void mp_js_do_exec(const char *src, size_t len, uint32_t *out) {
     gc_collect_start();
     gc_collect_end();
 
+    external_call_depth_inc();
     mp_parse_input_kind_t input_kind = MP_PARSE_FILE_INPUT;
     nlr_buf_t nlr;
     if (nlr_push(&nlr) == 0) {
@@ -118,9 +135,11 @@ void mp_js_do_exec(const char *src, size_t len, uint32_t *out) {
         mp_obj_t module_fun = mp_compile(&parse_tree, source_name, false);
         mp_obj_t ret = mp_call_function_0(module_fun);
         nlr_pop();
+        external_call_depth_dec();
         proxy_convert_mp_to_js_obj_cside(ret, out);
     } else {
         // uncaught exception
+        external_call_depth_dec();
         proxy_convert_mp_to_js_exc_cside(nlr.ret_val, out);
     }
 }
@@ -136,7 +155,10 @@ void mp_js_repl_init(void) {
 }
 
 int mp_js_repl_process_char(int c) {
-    return pyexec_event_repl_process_char(c);
+    external_call_depth_inc();
+    int ret = pyexec_event_repl_process_char(c);
+    external_call_depth_dec();
+    return ret;
 }
 
 #if MICROPY_GC_SPLIT_HEAP_AUTO
diff --git a/ports/webassembly/proxy_c.c b/ports/webassembly/proxy_c.c
index 2ab92303d2db3..22f879177a92d 100644
--- a/ports/webassembly/proxy_c.c
+++ b/ports/webassembly/proxy_c.c
@@ -176,6 +176,7 @@ void proxy_convert_mp_to_js_exc_cside(void *exc, uint32_t *out) {
 }
 
 void proxy_c_to_js_call(uint32_t c_ref, uint32_t n_args, uint32_t *args_value, uint32_t *out) {
+    external_call_depth_inc();
     nlr_buf_t nlr;
     if (nlr_push(&nlr) == 0) {
         mp_obj_t args[n_args];
@@ -185,14 +186,17 @@ void proxy_c_to_js_call(uint32_t c_ref, uint32_t n_args, uint32_t *args_value, u
         mp_obj_t obj = proxy_c_get_obj(c_ref);
         mp_obj_t member = mp_call_function_n_kw(obj, n_args, 0, args);
         nlr_pop();
+        external_call_depth_dec();
         proxy_convert_mp_to_js_obj_cside(member, out);
     } else {
         // uncaught exception
+        external_call_depth_dec();
         proxy_convert_mp_to_js_exc_cside(nlr.ret_val, out);
     }
 }
 
 void proxy_c_to_js_dir(uint32_t c_ref, uint32_t *out) {
+    external_call_depth_inc();
     nlr_buf_t nlr;
     if (nlr_push(&nlr) == 0) {
         mp_obj_t obj = proxy_c_get_obj(c_ref);
@@ -210,9 +214,11 @@ void proxy_c_to_js_dir(uint32_t c_ref, uint32_t *out) {
             dir = mp_builtin_dir_obj.fun.var(1, args);
         }
         nlr_pop();
+        external_call_depth_dec();
         proxy_convert_mp_to_js_obj_cside(dir, out);
     } else {
         // uncaught exception
+        external_call_depth_dec();
         proxy_convert_mp_to_js_exc_cside(nlr.ret_val, out);
     }
 }
@@ -235,6 +241,7 @@ bool proxy_c_to_js_has_attr(uint32_t c_ref, const char *attr_in) {
 }
 
 void proxy_c_to_js_lookup_attr(uint32_t c_ref, const char *attr_in, uint32_t *out) {
+    external_call_depth_inc();
     nlr_buf_t nlr;
     if (nlr_push(&nlr) == 0) {
         mp_obj_t obj = proxy_c_get_obj(c_ref);
@@ -255,19 +262,27 @@ void proxy_c_to_js_lookup_attr(uint32_t c_ref, const char *attr_in, uint32_t *ou
             member = mp_load_attr(obj, attr);
         }
         nlr_pop();
+        external_call_depth_dec();
         proxy_convert_mp_to_js_obj_cside(member, out);
     } else {
         // uncaught exception
+        external_call_depth_dec();
         proxy_convert_mp_to_js_exc_cside(nlr.ret_val, out);
     }
 }
 
-static bool proxy_c_to_js_store_helper(uint32_t c_ref, const char *attr_in, mp_obj_t value) {
-    mp_obj_t obj = proxy_c_get_obj(c_ref);
-    qstr attr = qstr_from_str(attr_in);
-
+static bool proxy_c_to_js_store_helper(uint32_t c_ref, const char *attr_in, uint32_t *value_in) {
+    external_call_depth_inc();
     nlr_buf_t nlr;
     if (nlr_push(&nlr) == 0) {
+        mp_obj_t obj = proxy_c_get_obj(c_ref);
+        qstr attr = qstr_from_str(attr_in);
+
+        mp_obj_t value = MP_OBJ_NULL;
+        if (value_in != NULL) {
+            value = proxy_convert_js_to_mp_obj_cside(value_in);
+        }
+
         if (mp_obj_is_dict_or_ordereddict(obj)) {
             if (value == MP_OBJ_NULL) {
                 mp_obj_dict_delete(obj, MP_OBJ_NEW_QSTR(attr));
@@ -278,20 +293,21 @@ static bool proxy_c_to_js_store_helper(uint32_t c_ref, const char *attr_in, mp_o
             mp_store_attr(obj, attr, value);
         }
         nlr_pop();
+        external_call_depth_dec();
         return true;
     } else {
         // uncaught exception
+        external_call_depth_dec();
         return false;
     }
 }
 
 bool proxy_c_to_js_store_attr(uint32_t c_ref, const char *attr_in, uint32_t *value_in) {
-    mp_obj_t value = proxy_convert_js_to_mp_obj_cside(value_in);
-    return proxy_c_to_js_store_helper(c_ref, attr_in, value);
+    return proxy_c_to_js_store_helper(c_ref, attr_in, value_in);
 }
 
 bool proxy_c_to_js_delete_attr(uint32_t c_ref, const char *attr_in) {
-    return proxy_c_to_js_store_helper(c_ref, attr_in, MP_OBJ_NULL);
+    return proxy_c_to_js_store_helper(c_ref, attr_in, NULL);
 }
 
 uint32_t proxy_c_to_js_get_type(uint32_t c_ref) {
@@ -352,18 +368,22 @@ uint32_t proxy_c_to_js_get_iter(uint32_t c_ref) {
 }
 
 bool proxy_c_to_js_iternext(uint32_t c_ref, uint32_t *out) {
-    mp_obj_t obj = proxy_c_get_obj(c_ref);
+    external_call_depth_inc();
     nlr_buf_t nlr;
     if (nlr_push(&nlr) == 0) {
+        mp_obj_t obj = proxy_c_get_obj(c_ref);
         mp_obj_t iter = mp_iternext_allow_raise(obj);
         if (iter == MP_OBJ_STOP_ITERATION) {
+            external_call_depth_dec();
             nlr_pop();
             return false;
         }
         nlr_pop();
+        external_call_depth_dec();
         proxy_convert_mp_to_js_obj_cside(iter, out);
         return true;
     } else {
+        external_call_depth_dec();
         if (mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(((mp_obj_base_t *)nlr.ret_val)->type), MP_OBJ_FROM_PTR(&mp_type_StopIteration))) {
             return false;
         } else {
@@ -475,6 +495,7 @@ static mp_obj_t resume_fun(size_t n_args, const mp_obj_t *args) {
 static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(resume_obj, 5, 5, resume_fun);
 
 void proxy_c_to_js_resume(uint32_t c_ref, uint32_t *args) {
+    external_call_depth_inc();
     nlr_buf_t nlr;
     if (nlr_push(&nlr) == 0) {
         mp_obj_t obj = proxy_c_get_obj(c_ref);
@@ -482,9 +503,11 @@ void proxy_c_to_js_resume(uint32_t c_ref, uint32_t *args) {
         mp_obj_t reject = proxy_convert_js_to_mp_obj_cside(args + 2 * 3);
         mp_obj_t ret = proxy_resume_execute(obj, mp_const_none, mp_const_none, resolve, reject);
         nlr_pop();
+        external_call_depth_dec();
         proxy_convert_mp_to_js_obj_cside(ret, args);
     } else {
         // uncaught exception
+        external_call_depth_dec();
         proxy_convert_mp_to_js_exc_cside(nlr.ret_val, args);
     }
 }
diff --git a/ports/webassembly/proxy_c.h b/ports/webassembly/proxy_c.h
index 751d14332b4b3..d3567c195e7ac 100644
--- a/ports/webassembly/proxy_c.h
+++ b/ports/webassembly/proxy_c.h
@@ -39,6 +39,9 @@ typedef struct _mp_obj_jsproxy_t {
 extern const mp_obj_type_t mp_type_jsproxy;
 extern const mp_obj_type_t mp_type_JsException;
 
+void external_call_depth_inc(void);
+void external_call_depth_dec(void);
+
 void proxy_c_init(void);
 mp_obj_t proxy_convert_js_to_mp_obj_cside(uint32_t *value);
 void proxy_convert_mp_to_js_obj_cside(mp_obj_t obj, uint32_t *out);

From c0ca4bb85f4f1307cbd34fe499035b16bcd22637 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Tue, 21 May 2024 11:36:41 +1000
Subject: [PATCH 384/408] webassembly: Set GC threshold and do top-level GC
 collect when possible.

Signed-off-by: Damien George 
---
 ports/webassembly/main.c | 33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)

diff --git a/ports/webassembly/main.c b/ports/webassembly/main.c
index fd331f8dcb486..6502ed16d3aae 100644
--- a/ports/webassembly/main.c
+++ b/ports/webassembly/main.c
@@ -49,8 +49,17 @@
 // the top-level call into C.
 static size_t external_call_depth = 0;
 
+#if MICROPY_GC_SPLIT_HEAP_AUTO
+static void gc_collect_top_level(void);
+#endif
+
 void external_call_depth_inc(void) {
     ++external_call_depth;
+    #if MICROPY_GC_SPLIT_HEAP_AUTO
+    if (external_call_depth == 1) {
+        gc_collect_top_level();
+    }
+    #endif
 }
 
 void external_call_depth_dec(void) {
@@ -63,6 +72,14 @@ void mp_js_init(int heap_size) {
     gc_init(heap, heap + heap_size);
     #endif
 
+    #if MICROPY_GC_SPLIT_HEAP_AUTO
+    // When MICROPY_GC_SPLIT_HEAP_AUTO is enabled, set the GC threshold to a low
+    // value so that a collection is triggered before the heap fills up.  The actual
+    // garbage collection will happen later when control returns to the top-level,
+    // via the `gc_collect_pending` flag and `gc_collect_top_level()`.
+    MP_STATE_MEM(gc_alloc_threshold) = 16 * 1024 / MICROPY_BYTES_PER_GC_BLOCK;
+    #endif
+
     #if MICROPY_ENABLE_PYSTACK
     static mp_obj_t pystack[1024];
     mp_pystack_init(pystack, &pystack[MP_ARRAY_SIZE(pystack)]);
@@ -121,10 +138,6 @@ void mp_js_do_import(const char *name, uint32_t *out) {
 }
 
 void mp_js_do_exec(const char *src, size_t len, uint32_t *out) {
-    // Collect at the top-level, where there are no root pointers from stack/registers.
-    gc_collect_start();
-    gc_collect_end();
-
     external_call_depth_inc();
     mp_parse_input_kind_t input_kind = MP_PARSE_FILE_INPUT;
     nlr_buf_t nlr;
@@ -163,6 +176,8 @@ int mp_js_repl_process_char(int c) {
 
 #if MICROPY_GC_SPLIT_HEAP_AUTO
 
+static bool gc_collect_pending = false;
+
 // The largest new region that is available to become Python heap.
 size_t gc_get_max_new_split(void) {
     return 128 * 1024 * 1024;
@@ -170,6 +185,16 @@ size_t gc_get_max_new_split(void) {
 
 // Don't collect anything.  Instead require the heap to grow.
 void gc_collect(void) {
+    gc_collect_pending = true;
+}
+
+// Collect at the top-level, where there are no root pointers from stack/registers.
+static void gc_collect_top_level(void) {
+    if (gc_collect_pending) {
+        gc_collect_pending = false;
+        gc_collect_start();
+        gc_collect_end();
+    }
 }
 
 #else

From 5c7a414574f06cf50ee9edec449f35f6740a1261 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Tue, 21 May 2024 11:41:46 +1000
Subject: [PATCH 385/408] webassembly: Add C-level finaliser to JsProxy object.

And clear the corresponding `proxy_js_ref[js_ref]` entry when the finaliser
runs.  This then allows the JavaScript side to (eventually) free the
corresponding JavaScript object.

Signed-off-by: Damien George 
---
 ports/webassembly/objjsproxy.c | 24 ++++++++++++++++++++++--
 ports/webassembly/proxy_js.js  | 31 +++++++++++++++++++++++++++----
 2 files changed, 49 insertions(+), 6 deletions(-)

diff --git a/ports/webassembly/objjsproxy.c b/ports/webassembly/objjsproxy.c
index 05fe715162a74..5c09e003fdccc 100644
--- a/ports/webassembly/objjsproxy.c
+++ b/ports/webassembly/objjsproxy.c
@@ -234,6 +234,22 @@ static mp_obj_t jsproxy_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const
     }
 }
 
+EM_JS(void, proxy_js_free_obj, (int js_ref), {
+    if (js_ref >= PROXY_JS_REF_NUM_STATIC) {
+        proxy_js_ref[js_ref] = undefined;
+        if (js_ref < proxy_js_ref_next) {
+            proxy_js_ref_next = js_ref;
+        }
+    }
+});
+
+static mp_obj_t jsproxy___del__(mp_obj_t self_in) {
+    mp_obj_jsproxy_t *self = MP_OBJ_TO_PTR(self_in);
+    proxy_js_free_obj(self->ref);
+    return mp_const_none;
+}
+static MP_DEFINE_CONST_FUN_OBJ_1(jsproxy___del___obj, jsproxy___del__);
+
 static mp_obj_t jsproxy_reflect_construct(size_t n_args, const mp_obj_t *args) {
     int arg0 = mp_obj_jsproxy_get_ref(args[0]);
     n_args -= 1;
@@ -274,7 +290,11 @@ void mp_obj_jsproxy_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
     if (dest[0] == MP_OBJ_NULL) {
         // Load attribute.
         uint32_t out[PVN];
-        if (lookup_attr(self->ref, qstr_str(attr), out)) {
+        if (attr == MP_QSTR___del__) {
+            // For finaliser.
+            dest[0] = MP_OBJ_FROM_PTR(&jsproxy___del___obj);
+            dest[1] = self_in;
+        } else if (lookup_attr(self->ref, qstr_str(attr), out)) {
             dest[0] = proxy_convert_js_to_mp_obj_cside(out);
         } else if (attr == MP_QSTR_new) {
             // Special case to handle construction of JS objects.
@@ -515,7 +535,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
     );
 
 mp_obj_t mp_obj_new_jsproxy(int ref) {
-    mp_obj_jsproxy_t *o = mp_obj_malloc(mp_obj_jsproxy_t, &mp_type_jsproxy);
+    mp_obj_jsproxy_t *o = mp_obj_malloc_with_finaliser(mp_obj_jsproxy_t, &mp_type_jsproxy);
     o->ref = ref;
     return MP_OBJ_FROM_PTR(o);
 }
diff --git a/ports/webassembly/proxy_js.js b/ports/webassembly/proxy_js.js
index 2a34f01a7b511..20f13f1d7423b 100644
--- a/ports/webassembly/proxy_js.js
+++ b/ports/webassembly/proxy_js.js
@@ -24,6 +24,9 @@
  * THE SOFTWARE.
  */
 
+// Number of static entries at the start of proxy_js_ref.
+const PROXY_JS_REF_NUM_STATIC = 2;
+
 // These constants should match the constants in proxy_c.c.
 
 const PROXY_KIND_MP_EXCEPTION = -1;
@@ -57,6 +60,28 @@ class PythonError extends Error {
 
 function proxy_js_init() {
     globalThis.proxy_js_ref = [globalThis, undefined];
+    globalThis.proxy_js_ref_next = PROXY_JS_REF_NUM_STATIC;
+}
+
+// js_obj cannot be undefined
+function proxy_js_add_obj(js_obj) {
+    // Search for the first free slot in proxy_js_ref.
+    while (proxy_js_ref_next < proxy_js_ref.length) {
+        if (proxy_js_ref[proxy_js_ref_next] === undefined) {
+            // Free slot found, reuse it.
+            const id = proxy_js_ref_next;
+            ++proxy_js_ref_next;
+            proxy_js_ref[id] = js_obj;
+            return id;
+        }
+        ++proxy_js_ref_next;
+    }
+
+    // No free slots, so grow proxy_js_ref by one (append at the end of the array).
+    const id = proxy_js_ref.length;
+    proxy_js_ref[id] = js_obj;
+    proxy_js_ref_next = proxy_js_ref.length;
+    return id;
 }
 
 function proxy_call_python(target, argumentsList) {
@@ -147,8 +172,7 @@ function proxy_convert_js_to_mp_obj_jsside(js_obj, out) {
         Module.setValue(out + 4, js_obj._ref, "i32");
     } else {
         kind = PROXY_KIND_JS_OBJECT;
-        const id = proxy_js_ref.length;
-        proxy_js_ref[id] = js_obj;
+        const id = proxy_js_add_obj(js_obj);
         Module.setValue(out + 4, id, "i32");
     }
     Module.setValue(out + 0, kind, "i32");
@@ -161,8 +185,7 @@ function proxy_convert_js_to_mp_obj_jsside_force_double_proxy(js_obj, out) {
         js_obj instanceof PyProxyThenable
     ) {
         const kind = PROXY_KIND_JS_OBJECT;
-        const id = proxy_js_ref.length;
-        proxy_js_ref[id] = js_obj;
+        const id = proxy_js_add_obj(js_obj);
         Module.setValue(out + 4, id, "i32");
         Module.setValue(out + 0, kind, "i32");
     } else {

From 57a9ffa6320bc9e5c7979a7f35c7de7a18f74720 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Tue, 21 May 2024 11:42:51 +1000
Subject: [PATCH 386/408] webassembly: Register PyProxy objects for JS-side
 finalisation.

And clear the corresponding `proxy_c_ref[c_ref]` entry when the finaliser
runs.  This then allows the C side to (eventually) garbage collect the
corresponding Python object.

Signed-off-by: Damien George 
---
 ports/webassembly/Makefile    |  1 +
 ports/webassembly/proxy_c.c   | 32 +++++++++++++++++++++++++++++++-
 ports/webassembly/proxy_js.js |  6 ++++++
 3 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/ports/webassembly/Makefile b/ports/webassembly/Makefile
index fddfb5094aac5..435636531cc26 100644
--- a/ports/webassembly/Makefile
+++ b/ports/webassembly/Makefile
@@ -54,6 +54,7 @@ EXPORTED_FUNCTIONS_EXTRA += ,\
 	_mp_js_do_exec_async,\
 	_mp_js_do_import,\
 	_mp_js_register_js_module,\
+	_proxy_c_free_obj,\
 	_proxy_c_init,\
 	_proxy_c_to_js_call,\
 	_proxy_c_to_js_delete_attr,\
diff --git a/ports/webassembly/proxy_c.c b/ports/webassembly/proxy_c.c
index 22f879177a92d..6e6f928a2ee4b 100644
--- a/ports/webassembly/proxy_c.c
+++ b/ports/webassembly/proxy_c.c
@@ -32,6 +32,9 @@
 #include "py/runtime.h"
 #include "proxy_c.h"
 
+// Number of static entries at the start of proxy_c_ref.
+#define PROXY_C_REF_NUM_STATIC (1)
+
 // These constants should match the constants in proxy_js.js.
 
 enum {
@@ -71,16 +74,36 @@ static const mp_obj_base_t mp_const_undefined_obj = {&mp_type_undefined};
 
 MP_DEFINE_EXCEPTION(JsException, Exception)
 
+// Index to start searching for the next available slot in proxy_c_ref.
+static size_t proxy_c_ref_next;
+
 void proxy_c_init(void) {
     MP_STATE_PORT(proxy_c_ref) = mp_obj_new_list(0, NULL);
     mp_obj_list_append(MP_STATE_PORT(proxy_c_ref), MP_OBJ_NULL);
+    proxy_c_ref_next = PROXY_C_REF_NUM_STATIC;
 }
 
 MP_REGISTER_ROOT_POINTER(mp_obj_t proxy_c_ref);
 
+// obj cannot be MP_OBJ_NULL.
 static inline size_t proxy_c_add_obj(mp_obj_t obj) {
-    size_t id = ((mp_obj_list_t *)MP_OBJ_TO_PTR(MP_STATE_PORT(proxy_c_ref)))->len;
+    // Search for the first free slot in proxy_c_ref.
+    mp_obj_list_t *l = (mp_obj_list_t *)MP_OBJ_TO_PTR(MP_STATE_PORT(proxy_c_ref));
+    while (proxy_c_ref_next < l->len) {
+        if (l->items[proxy_c_ref_next] == MP_OBJ_NULL) {
+            // Free slot found, reuse it.
+            size_t id = proxy_c_ref_next;
+            ++proxy_c_ref_next;
+            l->items[id] = obj;
+            return id;
+        }
+        ++proxy_c_ref_next;
+    }
+
+    // No free slots, so grow proxy_c_ref by one (append at the end of the list).
+    size_t id = l->len;
     mp_obj_list_append(MP_STATE_PORT(proxy_c_ref), obj);
+    proxy_c_ref_next = l->len;
     return id;
 }
 
@@ -88,6 +111,13 @@ static inline mp_obj_t proxy_c_get_obj(uint32_t c_ref) {
     return ((mp_obj_list_t *)MP_OBJ_TO_PTR(MP_STATE_PORT(proxy_c_ref)))->items[c_ref];
 }
 
+void proxy_c_free_obj(uint32_t c_ref) {
+    if (c_ref >= PROXY_C_REF_NUM_STATIC) {
+        ((mp_obj_list_t *)MP_OBJ_TO_PTR(MP_STATE_PORT(proxy_c_ref)))->items[c_ref] = MP_OBJ_NULL;
+        proxy_c_ref_next = MIN(proxy_c_ref_next, c_ref);
+    }
+}
+
 mp_obj_t proxy_convert_js_to_mp_obj_cside(uint32_t *value) {
     if (value[0] == PROXY_KIND_JS_UNDEFINED) {
         return mp_const_undefined;
diff --git a/ports/webassembly/proxy_js.js b/ports/webassembly/proxy_js.js
index 20f13f1d7423b..fe92b5725a049 100644
--- a/ports/webassembly/proxy_js.js
+++ b/ports/webassembly/proxy_js.js
@@ -61,6 +61,11 @@ class PythonError extends Error {
 function proxy_js_init() {
     globalThis.proxy_js_ref = [globalThis, undefined];
     globalThis.proxy_js_ref_next = PROXY_JS_REF_NUM_STATIC;
+    globalThis.pyProxyFinalizationRegistry = new FinalizationRegistry(
+        (cRef) => {
+            Module.ccall("proxy_c_free_obj", "null", ["number"], [cRef]);
+        },
+    );
 }
 
 // js_obj cannot be undefined
@@ -251,6 +256,7 @@ function proxy_convert_mp_to_js_obj_jsside(value) {
             const target = new PyProxy(id);
             obj = new Proxy(target, py_proxy_handler);
         }
+        globalThis.pyProxyFinalizationRegistry.register(obj, id);
     }
     return obj;
 }

From a919ce26d325b0169a5cfaf65fe4a71ece9dfa1f Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Tue, 21 May 2024 11:43:00 +1000
Subject: [PATCH 387/408] webassembly/modjsffi: Add mem_info function to get
 detailed stats.

This allows querying the GC heap size/used/free values, as well as the
number of alive JsProxy and PyProxy objects, referenced by proxy_c_ref and
proxy_js_ref.

Signed-off-by: Damien George 
---
 ports/webassembly/modjsffi.c | 40 ++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/ports/webassembly/modjsffi.c b/ports/webassembly/modjsffi.c
index c77d899fb7f8c..202e1d7ec0149 100644
--- a/ports/webassembly/modjsffi.c
+++ b/ports/webassembly/modjsffi.c
@@ -25,6 +25,7 @@
  */
 
 #include "emscripten.h"
+#include "py/gc.h"
 #include "py/objmodule.h"
 #include "py/runtime.h"
 #include "proxy_c.h"
@@ -75,6 +76,44 @@ static mp_obj_t mp_jsffi_async_timeout_ms(mp_obj_t arg) {
 }
 static MP_DEFINE_CONST_FUN_OBJ_1(mp_jsffi_async_timeout_ms_obj, mp_jsffi_async_timeout_ms);
 
+// *FORMAT-OFF*
+EM_JS(void, js_get_proxy_js_ref_info, (uint32_t * out), {
+    let used = 0;
+    for (const elem of proxy_js_ref) {
+        if (elem !== undefined) {
+            ++used;
+        }
+    }
+    Module.setValue(out, proxy_js_ref.length, "i32");
+    Module.setValue(out + 4, used, "i32");
+});
+// *FORMAT-ON*
+
+static mp_obj_t mp_jsffi_mem_info(void) {
+    mp_obj_list_t *l = (mp_obj_list_t *)MP_OBJ_TO_PTR(MP_STATE_PORT(proxy_c_ref));
+    mp_int_t used = 0;
+    for (size_t i = 0; i < l->len; ++i) {
+        if (l->items[i] != MP_OBJ_NULL) {
+            ++used;
+        }
+    }
+    uint32_t proxy_js_ref_info[2];
+    js_get_proxy_js_ref_info(proxy_js_ref_info);
+    gc_info_t info;
+    gc_info(&info);
+    mp_obj_t elems[] = {
+        MP_OBJ_NEW_SMALL_INT(info.total), // GC heap total bytes
+        MP_OBJ_NEW_SMALL_INT(info.used), // GC heap used bytes
+        MP_OBJ_NEW_SMALL_INT(info.free), // GC heap free bytes
+        MP_OBJ_NEW_SMALL_INT(l->len), // proxy_c_ref allocated size
+        MP_OBJ_NEW_SMALL_INT(used), // proxy_c_ref used
+        MP_OBJ_NEW_SMALL_INT(proxy_js_ref_info[0]), // proxy_js_ref allocated size
+        MP_OBJ_NEW_SMALL_INT(proxy_js_ref_info[1]), // proxy_js_ref used
+    };
+    return mp_obj_new_tuple(MP_ARRAY_SIZE(elems), elems);
+}
+static MP_DEFINE_CONST_FUN_OBJ_0(mp_jsffi_mem_info_obj, mp_jsffi_mem_info);
+
 static const mp_rom_map_elem_t mp_module_jsffi_globals_table[] = {
     { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_jsffi) },
 
@@ -83,6 +122,7 @@ static const mp_rom_map_elem_t mp_module_jsffi_globals_table[] = {
     { MP_ROM_QSTR(MP_QSTR_create_proxy), MP_ROM_PTR(&mp_jsffi_create_proxy_obj) },
     { MP_ROM_QSTR(MP_QSTR_to_js), MP_ROM_PTR(&mp_jsffi_to_js_obj) },
     { MP_ROM_QSTR(MP_QSTR_async_timeout_ms), MP_ROM_PTR(&mp_jsffi_async_timeout_ms_obj) },
+    { MP_ROM_QSTR(MP_QSTR_mem_info), MP_ROM_PTR(&mp_jsffi_mem_info_obj) },
 };
 static MP_DEFINE_CONST_DICT(mp_module_jsffi_globals, mp_module_jsffi_globals_table);
 

From 482292cc664be63af985b5bde3a5c83ddcc9180a Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Fri, 17 May 2024 10:43:34 +1000
Subject: [PATCH 388/408] py/dynruntime: Add mp_obj_exception_init function to
 create C exception.

Signed-off-by: Damien George 
---
 py/dynruntime.h | 15 +++++++++++++++
 py/nativeglue.c |  1 +
 py/nativeglue.h |  1 +
 tools/mpy_ld.py |  1 +
 4 files changed, 18 insertions(+)

diff --git a/py/dynruntime.h b/py/dynruntime.h
index d07b1dce2c4e5..5503a1014f12b 100644
--- a/py/dynruntime.h
+++ b/py/dynruntime.h
@@ -90,6 +90,7 @@ static inline void *m_realloc_dyn(void *ptr, size_t new_num_bytes) {
 #define mp_type_bytes                       (*(mp_obj_type_t *)(mp_load_global(MP_QSTR_bytes)))
 #define mp_type_tuple                       (*((mp_obj_base_t *)mp_const_empty_tuple)->type)
 #define mp_type_list                        (*mp_fun_table.type_list)
+#define mp_type_Exception                   (*mp_fun_table.type_Exception)
 #define mp_type_EOFError                    (*(mp_obj_type_t *)(mp_load_global(MP_QSTR_EOFError)))
 #define mp_type_IndexError                  (*(mp_obj_type_t *)(mp_load_global(MP_QSTR_IndexError)))
 #define mp_type_KeyError                    (*(mp_obj_type_t *)(mp_load_global(MP_QSTR_KeyError)))
@@ -236,6 +237,10 @@ static inline void *mp_obj_malloc_helper_dyn(size_t num_bytes, const mp_obj_type
 /******************************************************************************/
 // Exceptions
 
+#define mp_obj_exception_make_new               (MP_OBJ_TYPE_GET_SLOT(&mp_type_Exception, make_new))
+#define mp_obj_exception_print                  (MP_OBJ_TYPE_GET_SLOT(&mp_type_Exception, print))
+#define mp_obj_exception_attr                   (MP_OBJ_TYPE_GET_SLOT(&mp_type_Exception, attr))
+
 #define mp_obj_new_exception(o)                 ((mp_obj_t)(o)) // Assumes returned object will be raised, will create instance then
 #define mp_obj_new_exception_arg1(e_type, arg)  (mp_obj_new_exception_arg1_dyn((e_type), (arg)))
 
@@ -263,6 +268,16 @@ static inline void mp_raise_OSError_dyn(int er) {
     nlr_raise(mp_call_function_n_kw(mp_load_global(MP_QSTR_OSError), 1, 0, &args[0]));
 }
 
+static inline void mp_obj_exception_init(mp_obj_full_type_t *exc, qstr name, const mp_obj_type_t *base) {
+    exc->base.type = &mp_type_type;
+    exc->flags = MP_TYPE_FLAG_NONE;
+    exc->name = name;
+    MP_OBJ_TYPE_SET_SLOT(exc, make_new, mp_obj_exception_make_new, 0);
+    MP_OBJ_TYPE_SET_SLOT(exc, print, mp_obj_exception_print, 1);
+    MP_OBJ_TYPE_SET_SLOT(exc, attr, mp_obj_exception_attr, 2);
+    MP_OBJ_TYPE_SET_SLOT(exc, parent, base, 3);
+}
+
 /******************************************************************************/
 // Floating point
 
diff --git a/py/nativeglue.c b/py/nativeglue.c
index ba3d93f760707..ad2483caed787 100644
--- a/py/nativeglue.c
+++ b/py/nativeglue.c
@@ -344,6 +344,7 @@ const mp_fun_table_t mp_fun_table = {
     &mp_type_fun_builtin_2,
     &mp_type_fun_builtin_3,
     &mp_type_fun_builtin_var,
+    &mp_type_Exception,
     &mp_stream_read_obj,
     &mp_stream_readinto_obj,
     &mp_stream_unbuffered_readline_obj,
diff --git a/py/nativeglue.h b/py/nativeglue.h
index 1fa85933452cb..4c114de421667 100644
--- a/py/nativeglue.h
+++ b/py/nativeglue.h
@@ -171,6 +171,7 @@ typedef struct _mp_fun_table_t {
     const mp_obj_type_t *type_fun_builtin_2;
     const mp_obj_type_t *type_fun_builtin_3;
     const mp_obj_type_t *type_fun_builtin_var;
+    const mp_obj_type_t *type_Exception;
     const mp_obj_fun_builtin_var_t *stream_read_obj;
     const mp_obj_fun_builtin_var_t *stream_readinto_obj;
     const mp_obj_fun_builtin_var_t *stream_unbuffered_readline_obj;
diff --git a/tools/mpy_ld.py b/tools/mpy_ld.py
index 2e3da53eb57e0..029b02fa42e4d 100755
--- a/tools/mpy_ld.py
+++ b/tools/mpy_ld.py
@@ -767,6 +767,7 @@ def link_objects(env, native_qstr_vals_len):
                 "mp_type_fun_builtin_2",
                 "mp_type_fun_builtin_3",
                 "mp_type_fun_builtin_var",
+                "mp_type_Exception",
                 "mp_stream_read_obj",
                 "mp_stream_readinto_obj",
                 "mp_stream_unbuffered_readline_obj",

From d532f960a4c40e4e6661ddc1d9eced18c37e3377 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Fri, 17 May 2024 10:43:51 +1000
Subject: [PATCH 389/408] examples/natmod/features4: Create custom
 FactorialError as exc example.

Signed-off-by: Damien George 
---
 examples/natmod/features4/features4.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/examples/natmod/features4/features4.c b/examples/natmod/features4/features4.c
index a52e9e45662aa..e64c7f759213c 100644
--- a/examples/natmod/features4/features4.c
+++ b/examples/natmod/features4/features4.c
@@ -1,5 +1,6 @@
 /*
-  This example extends on features0 but demonstrates how to define a class.
+  This example extends on features0 but demonstrates how to define a class,
+  and a custom exception.
 
   The Factorial class constructor takes an integer, and then the calculate
   method can be called to get the factorial.
@@ -8,6 +9,9 @@
   >>> f = features4.Factorial(4)
   >>> f.calculate()
   24
+
+  If the argument to the Factorial class constructor is less than zero, a
+  FactorialError is raised.
 */
 
 // Include the header file to get access to the MicroPython API
@@ -22,6 +26,8 @@ typedef struct {
     mp_int_t n;
 } mp_obj_factorial_t;
 
+mp_obj_full_type_t mp_type_FactorialError;
+
 // Essentially Factorial.__new__ (but also kind of __init__).
 // Takes a single argument (the number to find the factorial of)
 static mp_obj_t factorial_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args_in) {
@@ -30,6 +36,10 @@ static mp_obj_t factorial_make_new(const mp_obj_type_t *type, size_t n_args, siz
     mp_obj_factorial_t *o = mp_obj_malloc(mp_obj_factorial_t, type);
     o->n = mp_obj_get_int(args_in[0]);
 
+    if (o->n < 0) {
+        mp_raise_msg((mp_obj_type_t *)&mp_type_FactorialError, "argument must be zero or above");
+    }
+
     return MP_OBJ_FROM_PTR(o);
 }
 
@@ -68,6 +78,12 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *a
     // Make the Factorial type available on the module.
     mp_store_global(MP_QSTR_Factorial, MP_OBJ_FROM_PTR(&mp_type_factorial));
 
+    // Initialise the exception type.
+    mp_obj_exception_init(&mp_type_FactorialError, MP_QSTR_FactorialError, &mp_type_Exception);
+
+    // Make the FactorialError type available on the module.
+    mp_store_global(MP_QSTR_FactorialError, MP_OBJ_FROM_PTR(&mp_type_FactorialError));
+
     // This must be last, it restores the globals dict
     MP_DYNRUNTIME_INIT_EXIT
 }

From b1e960270213a88eb02219d85201198c4a8671c6 Mon Sep 17 00:00:00 2001
From: Jared Hancock 
Date: Mon, 18 Mar 2024 16:38:15 -0500
Subject: [PATCH 390/408] extmod/modlwip: Use Nagle algorithm and add support
 for TCP_NODELAY.

This adds support to use the Nagle algorithm implemented already in lwIP to
determine when TCP data should be sent.

As currently written, MicroPython will only create packets if there is <25%
remaining in the send buffer.  Using it, sending a small message of ~50
bytes will not trigger output of the message on the network.  So it will
remained queued until the TCP interval timer expires, which can be up to
500ms.

Using Nagle's algorithm, the first write, no matter how small, will
generate a packet on the network.  And sending lots of data still makes
efficient use of the link.

In addition to this, an application designer may choose to always create
packets for every write by setting the TCP_NODELAY socket option.  That's
also implemented in this commit.
---
 extmod/modlwip.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/extmod/modlwip.c b/extmod/modlwip.c
index d4e25917a67b8..afac512e834de 100644
--- a/extmod/modlwip.c
+++ b/extmod/modlwip.c
@@ -69,6 +69,8 @@
 #define IP_ADD_MEMBERSHIP 0x400
 #define IP_DROP_MEMBERSHIP 0x401
 
+#define TCP_NODELAY TF_NODELAY
+
 // For compatibilily with older lwIP versions.
 #ifndef ip_set_option
 #define ip_set_option(pcb, opt)   ((pcb)->so_options |= (opt))
@@ -76,6 +78,12 @@
 #ifndef ip_reset_option
 #define ip_reset_option(pcb, opt) ((pcb)->so_options &= ~(opt))
 #endif
+#ifndef tcp_set_flags
+#define tcp_set_flags(pcb, set_flags) do { (pcb)->flags |= (set_flags); } while (0)
+#endif
+#ifndef tcp_clear_flags
+#define tcp_clear_flags(pcb, clear_flags) do { (pcb)->flags &= ~(clear_flags); } while (0)
+#endif
 
 // A port can define these hooks to provide concurrency protection
 #ifndef MICROPY_PY_LWIP_ENTER
@@ -742,9 +750,10 @@ static mp_uint_t lwip_tcp_send(lwip_socket_obj_t *socket, const byte *buf, mp_ui
         MICROPY_PY_LWIP_REENTER
     }
 
-    // If the output buffer is getting full then send the data to the lower layers
-    if (err == ERR_OK && tcp_sndbuf(socket->pcb.tcp) < TCP_SND_BUF / 4) {
-        err = tcp_output(socket->pcb.tcp);
+    // Use nagle algorithm to determine when to send segment buffer (can be
+    // disabled with TCP_NODELAY socket option)
+    if (err == ERR_OK) {
+        err = tcp_output_nagle(socket->pcb.tcp);
     }
 
     MICROPY_PY_LWIP_EXIT
@@ -1440,6 +1449,17 @@ static mp_obj_t lwip_socket_setsockopt(size_t n_args, const mp_obj_t *args) {
             break;
         }
 
+        // level: IPPROTO_TCP
+        case TCP_NODELAY: {
+            mp_int_t val = mp_obj_get_int(args[3]);
+            if (val) {
+                tcp_set_flags(socket->pcb.tcp, opt);
+            } else {
+                tcp_clear_flags(socket->pcb.tcp, opt);
+            }
+            break;
+        }
+
         default:
             printf("Warning: lwip.setsockopt() not implemented\n");
     }
@@ -1829,6 +1849,9 @@ static const mp_rom_map_elem_t mp_module_lwip_globals_table[] = {
     { MP_ROM_QSTR(MP_QSTR_IPPROTO_IP), MP_ROM_INT(0) },
     { MP_ROM_QSTR(MP_QSTR_IP_ADD_MEMBERSHIP), MP_ROM_INT(IP_ADD_MEMBERSHIP) },
     { MP_ROM_QSTR(MP_QSTR_IP_DROP_MEMBERSHIP), MP_ROM_INT(IP_DROP_MEMBERSHIP) },
+
+    { MP_ROM_QSTR(MP_QSTR_IPPROTO_TCP), MP_ROM_INT(IP_PROTO_TCP) },
+    { MP_ROM_QSTR(MP_QSTR_TCP_NODELAY), MP_ROM_INT(TCP_NODELAY) },
 };
 
 static MP_DEFINE_CONST_DICT(mp_module_lwip_globals, mp_module_lwip_globals_table);

From a196468c4752997a11cf06b65cb2147465b7f8eb Mon Sep 17 00:00:00 2001
From: Jared Hancock 
Date: Thu, 23 May 2024 20:37:55 -0500
Subject: [PATCH 391/408] esp32: Add support for TCP_NODELAY.

This adds support for the TCP_NODELAY socket option for lwIP sockets.
Generally, TCP sockets use the Nagle algorithm and will send data when
an ACK is received or after all previously-sent data has already been
ACKed.

If the TCP_NODELAY option is set for a socket, every write to the socket
will trigger a packet to be sent.

Signed-off-by: Jared Hancock 
---
 ports/esp32/modsocket.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/ports/esp32/modsocket.c b/ports/esp32/modsocket.c
index 507609dfef6b1..44f945c4503b0 100644
--- a/ports/esp32/modsocket.c
+++ b/ports/esp32/modsocket.c
@@ -528,6 +528,16 @@ static mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) {
         }
             #endif
 
+        // level: IPPROTO_TCP
+        case TCP_NODELAY: {
+            int val = mp_obj_get_int(args[3]);
+            int ret = lwip_setsockopt(self->fd, IPPROTO_TCP, opt, &val, sizeof(int));
+            if (ret != 0) {
+                mp_raise_OSError(errno);
+            }
+            break;
+        }
+
         // level: IPPROTO_IP
         case IP_ADD_MEMBERSHIP: {
             mp_buffer_info_t bufinfo;
@@ -995,6 +1005,7 @@ static const mp_rom_map_elem_t mp_module_socket_globals_table[] = {
     { MP_ROM_QSTR(MP_QSTR_SO_BROADCAST), MP_ROM_INT(SO_BROADCAST) },
     { MP_ROM_QSTR(MP_QSTR_SO_BINDTODEVICE), MP_ROM_INT(SO_BINDTODEVICE) },
     { MP_ROM_QSTR(MP_QSTR_IP_ADD_MEMBERSHIP), MP_ROM_INT(IP_ADD_MEMBERSHIP) },
+    { MP_ROM_QSTR(MP_QSTR_TCP_NODELAY), MP_ROM_INT(TCP_NODELAY) },
 };
 
 static MP_DEFINE_CONST_DICT(mp_module_socket_globals, mp_module_socket_globals_table);

From c624a5c0c4d02fd67e2ad5a0f36a141d2a6ef2ff Mon Sep 17 00:00:00 2001
From: Brian Pugh 
Date: Fri, 19 Apr 2024 16:37:51 -0700
Subject: [PATCH 392/408] py/dynruntime: Export mp_load_method_maybe and
 mp_arg_parse_all* funcs.

Also define `mp_type_bytearray`.  These all help to write native modules.

Signed-off-by: Brian Pugh 
Signed-off-by: Damien George 
---
 py/dynruntime.h                           | 8 ++++++++
 py/nativeglue.c                           | 3 +++
 py/nativeglue.h                           | 5 ++++-
 tests/micropython/import_mpy_native_gc.py | 4 ++--
 tools/mpy_ld.py                           | 2 +-
 5 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/py/dynruntime.h b/py/dynruntime.h
index 5503a1014f12b..d360d824ac39c 100644
--- a/py/dynruntime.h
+++ b/py/dynruntime.h
@@ -88,6 +88,7 @@ static inline void *m_realloc_dyn(void *ptr, size_t new_num_bytes) {
 #define mp_type_int                         (*(mp_obj_type_t *)(mp_load_global(MP_QSTR_int)))
 #define mp_type_str                         (*mp_fun_table.type_str)
 #define mp_type_bytes                       (*(mp_obj_type_t *)(mp_load_global(MP_QSTR_bytes)))
+#define mp_type_bytearray                   (*(mp_obj_type_t *)(mp_load_global(MP_QSTR_bytearray)))
 #define mp_type_tuple                       (*((mp_obj_base_t *)mp_const_empty_tuple)->type)
 #define mp_type_list                        (*mp_fun_table.type_list)
 #define mp_type_Exception                   (*mp_fun_table.type_Exception)
@@ -194,6 +195,7 @@ static inline void *mp_obj_malloc_helper_dyn(size_t num_bytes, const mp_obj_type
 #define mp_load_global(qst)               (mp_fun_table.load_global((qst)))
 #define mp_load_attr(base, attr)          (mp_fun_table.load_attr((base), (attr)))
 #define mp_load_method(base, attr, dest)  (mp_fun_table.load_method((base), (attr), (dest)))
+#define mp_load_method_maybe(base, attr, dest) (mp_fun_table.load_method_maybe((base), (attr), (dest)))
 #define mp_load_super_method(attr, dest)  (mp_fun_table.load_super_method((attr), (dest)))
 #define mp_store_name(qst, obj)           (mp_fun_table.store_name((qst), (obj)))
 #define mp_store_global(qst, obj)         (mp_fun_table.store_global((qst), (obj)))
@@ -211,6 +213,12 @@ static inline void *mp_obj_malloc_helper_dyn(size_t num_bytes, const mp_obj_type
 #define mp_arg_check_num(n_args, n_kw, n_args_min, n_args_max, takes_kw) \
     (mp_fun_table.arg_check_num_sig((n_args), (n_kw), MP_OBJ_FUN_MAKE_SIG((n_args_min), (n_args_max), (takes_kw))))
 
+#define mp_arg_parse_all(n_pos, pos, kws, n_allowed, allowed, out_vals) \
+    (mp_fun_table.arg_parse_all((n_pos), (pos), (kws), (n_allowed), (allowed), (out_vals)))
+
+#define mp_arg_parse_all_kw_array(n_pos, n_kw, args, n_allowed, allowed, out_vals) \
+    (mp_fun_table.arg_parse_all_kw_array((n_pos), (n_kw), (args), (n_allowed), (allowed), (out_vals)))
+
 #define MP_DYNRUNTIME_INIT_ENTRY \
     mp_obj_t old_globals = mp_fun_table.swap_globals(self->context->module.globals); \
     mp_raw_code_truncated_t rc; \
diff --git a/py/nativeglue.c b/py/nativeglue.c
index ad2483caed787..6bf16f1acc29a 100644
--- a/py/nativeglue.c
+++ b/py/nativeglue.c
@@ -329,8 +329,11 @@ const mp_fun_table_t mp_fun_table = {
     mp_obj_new_float_from_d,
     mp_obj_get_float_to_f,
     mp_obj_get_float_to_d,
+    mp_load_method_maybe,
     mp_get_buffer,
     mp_get_stream_raise,
+    mp_arg_parse_all,
+    mp_arg_parse_all_kw_array,
     mp_binary_get_size,
     mp_binary_get_val_array,
     mp_binary_set_val_array,
diff --git a/py/nativeglue.h b/py/nativeglue.h
index 4c114de421667..e96fd7b66a03f 100644
--- a/py/nativeglue.h
+++ b/py/nativeglue.h
@@ -154,13 +154,16 @@ typedef struct _mp_fun_table_t {
     mp_obj_t (*obj_new_float_from_d)(double d);
     float (*obj_get_float_to_f)(mp_obj_t o);
     double (*obj_get_float_to_d)(mp_obj_t o);
+    void (*load_method_maybe)(mp_obj_t base, qstr attr, mp_obj_t *dest);
     bool (*get_buffer)(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
     const mp_stream_p_t *(*get_stream_raise)(mp_obj_t self_in, int flags);
+    void (*arg_parse_all)(size_t n_pos, const mp_obj_t *pos, mp_map_t *kws, size_t n_allowed, const mp_arg_t *allowed, mp_arg_val_t *out_vals);
+    void (*arg_parse_all_kw_array)(size_t n_pos, size_t n_kw, const mp_obj_t *args, size_t n_allowed, const mp_arg_t *allowed, mp_arg_val_t *out_vals);
     size_t (*binary_get_size)(char struct_type, char val_type, size_t *palign);
     mp_obj_t (*binary_get_val_array)(char typecode, void *p, size_t index);
     void (*binary_set_val_array)(char typecode, void *p, size_t index, mp_obj_t val_in);
     const mp_print_t *plat_print;
-    // The following entries start at index 70 and are referenced by tools-mpy_ld.py,
+    // The following entries start at index 73 and are referenced by tools-mpy_ld.py,
     // see constant MP_FUN_TABLE_MP_TYPE_TYPE_OFFSET.
     const mp_obj_type_t *type_type;
     const mp_obj_type_t *type_str;
diff --git a/tests/micropython/import_mpy_native_gc.py b/tests/micropython/import_mpy_native_gc.py
index 7f4b2aefd59f4..4b7acd9c652e0 100644
--- a/tests/micropython/import_mpy_native_gc.py
+++ b/tests/micropython/import_mpy_native_gc.py
@@ -52,9 +52,9 @@ def open(self, path, mode):
 # cat features0.mpy | python -c 'import sys; print(sys.stdin.buffer.read())'
 features0_file_contents = {
     # -march=x64
-    0x806: b'M\x06\x0b\x1f\x02\x004build/features0.native.mpy\x00\x12factorial\x00\x8a\x02\xe9/\x00\x00\x00SH\x8b\x1d\x83\x00\x00\x00\xbe\x02\x00\x00\x00\xffS\x18\xbf\x01\x00\x00\x00H\x85\xc0u\x0cH\x8bC \xbe\x02\x00\x00\x00[\xff\xe0H\x0f\xaf\xf8H\xff\xc8\xeb\xe6ATUSH\x8b\x1dQ\x00\x00\x00H\x8bG\x08L\x8bc(H\x8bx\x08A\xff\xd4H\x8d5+\x00\x00\x00H\x89\xc5H\x8b\x059\x00\x00\x00\x0f\xb7x\x02\xffShH\x89\xefA\xff\xd4H\x8b\x03[]A\\\xc3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x11$\r&\xa9 \x01"\xff',
+    0x806: b'M\x06\x0b\x1f\x02\x004build/features0.native.mpy\x00\x12factorial\x00\x8a\x02\xe9/\x00\x00\x00SH\x8b\x1d\x83\x00\x00\x00\xbe\x02\x00\x00\x00\xffS\x18\xbf\x01\x00\x00\x00H\x85\xc0u\x0cH\x8bC \xbe\x02\x00\x00\x00[\xff\xe0H\x0f\xaf\xf8H\xff\xc8\xeb\xe6ATUSH\x8b\x1dQ\x00\x00\x00H\x8bG\x08L\x8bc(H\x8bx\x08A\xff\xd4H\x8d5+\x00\x00\x00H\x89\xc5H\x8b\x059\x00\x00\x00\x0f\xb7x\x02\xffShH\x89\xefA\xff\xd4H\x8b\x03[]A\\\xc3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x11$\r&\xaf \x01"\xff',
     # -march=armv6m
-    0x1006: b"M\x06\x13\x1f\x02\x004build/features0.native.mpy\x00\x12factorial\x00\x88\x02\x18\xe0\x00\x00\x10\xb5\tK\tJ{D\x9cX\x02!\xe3h\x98G\x03\x00\x01 \x00+\x02\xd0XC\x01;\xfa\xe7\x02!#i\x98G\x10\xbd\xc0Fj\x00\x00\x00\x00\x00\x00\x00\xf8\xb5\nN\nK~D\xf4XChgiXh\xb8G\x05\x00\x07K\x08I\xf3XyDX\x88ck\x98G(\x00\xb8G h\xf8\xbd\xc0F:\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x1e\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x11<\r>\xa98\x01:\xff",
+    0x1006: b"M\x06\x13\x1f\x02\x004build/features0.native.mpy\x00\x12factorial\x00\x88\x02\x18\xe0\x00\x00\x10\xb5\tK\tJ{D\x9cX\x02!\xe3h\x98G\x03\x00\x01 \x00+\x02\xd0XC\x01;\xfa\xe7\x02!#i\x98G\x10\xbd\xc0Fj\x00\x00\x00\x00\x00\x00\x00\xf8\xb5\nN\nK~D\xf4XChgiXh\xb8G\x05\x00\x07K\x08I\xf3XyDX\x88ck\x98G(\x00\xb8G h\xf8\xbd\xc0F:\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x1e\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x11<\r>\xaf8\x01:\xff",
 }
 
 # Populate armv7m-derived archs based on armv6m.
diff --git a/tools/mpy_ld.py b/tools/mpy_ld.py
index 029b02fa42e4d..7046b6a8556f0 100755
--- a/tools/mpy_ld.py
+++ b/tools/mpy_ld.py
@@ -52,7 +52,7 @@
 MP_SCOPE_FLAG_VIPERRODATA = 0x20
 MP_SCOPE_FLAG_VIPERBSS = 0x40
 MP_SMALL_INT_BITS = 31
-MP_FUN_TABLE_MP_TYPE_TYPE_OFFSET = 70
+MP_FUN_TABLE_MP_TYPE_TYPE_OFFSET = 73
 
 # ELF constants
 R_386_32 = 1

From df419137821a07a382eb78ce528c700870a4351c Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Fri, 24 May 2024 13:19:47 +1000
Subject: [PATCH 393/408] examples/natmod/btree: Make btree.open use
 mp_arg_parse_all for kwargs.

Python code is no longer needed to implement keyword arguments in
`btree.open()`, it can now be done in C.

Signed-off-by: Damien George 
---
 examples/natmod/btree/Makefile    |  2 +-
 examples/natmod/btree/btree_c.c   | 36 ++++++++++++++++++++++---------
 examples/natmod/btree/btree_py.py |  7 ------
 3 files changed, 27 insertions(+), 18 deletions(-)
 delete mode 100644 examples/natmod/btree/btree_py.py

diff --git a/examples/natmod/btree/Makefile b/examples/natmod/btree/Makefile
index 218ec15a2a009..b5846f90065ee 100644
--- a/examples/natmod/btree/Makefile
+++ b/examples/natmod/btree/Makefile
@@ -5,7 +5,7 @@ MPY_DIR = ../../..
 MOD = btree_$(ARCH)
 
 # Source files (.c or .py)
-SRC = btree_c.c btree_py.py
+SRC = btree_c.c
 
 # Architecture to build for (x86, x64, armv7m, xtensa, xtensawin)
 ARCH = x64
diff --git a/examples/natmod/btree/btree_c.c b/examples/natmod/btree/btree_c.c
index bbf51c731fbd1..4f494817e7bc0 100644
--- a/examples/natmod/btree/btree_c.c
+++ b/examples/natmod/btree/btree_c.c
@@ -106,23 +106,39 @@ mp_getiter_iternext_custom_t btree_getiter_iternext;
 mp_map_elem_t btree_locals_dict_table[8];
 static MP_DEFINE_CONST_DICT(btree_locals_dict, btree_locals_dict_table);
 
-static mp_obj_t btree_open(size_t n_args, const mp_obj_t *args) {
+static mp_obj_t btree_open(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
+    // The allowed_args array must have its qstr's populated at runtime.
+    enum { ARG_flags, ARG_cachesize, ARG_pagesize, ARG_minkeypage };
+    mp_arg_t allowed_args[] = {
+        { MP_QSTR_, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
+        { MP_QSTR_, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
+        { MP_QSTR_, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
+        { MP_QSTR_, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
+    };
+    allowed_args[0].qst = MP_QSTR_flags;
+    allowed_args[1].qst = MP_QSTR_cachesize;
+    allowed_args[2].qst = MP_QSTR_pagesize;
+    allowed_args[3].qst = MP_QSTR_minkeypage;
+
     // Make sure we got a stream object
-    mp_get_stream_raise(args[0], MP_STREAM_OP_READ | MP_STREAM_OP_WRITE | MP_STREAM_OP_IOCTL);
+    mp_get_stream_raise(pos_args[0], MP_STREAM_OP_READ | MP_STREAM_OP_WRITE | MP_STREAM_OP_IOCTL);
+
+    mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
+    mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
 
     BTREEINFO openinfo = {0};
-    openinfo.flags = mp_obj_get_int(args[1]);
-    openinfo.cachesize = mp_obj_get_int(args[2]);
-    openinfo.psize = mp_obj_get_int(args[3]);
-    openinfo.minkeypage = mp_obj_get_int(args[4]);
-    DB *db = __bt_open(MP_OBJ_TO_PTR(args[0]), &btree_stream_fvtable, &openinfo, 0);
+    openinfo.flags = args[ARG_flags].u_int;
+    openinfo.cachesize = args[ARG_cachesize].u_int;
+    openinfo.psize = args[ARG_pagesize].u_int;
+    openinfo.minkeypage = args[ARG_minkeypage].u_int;
+    DB *db = __bt_open(MP_OBJ_TO_PTR(pos_args[0]), &btree_stream_fvtable, &openinfo, 0);
     if (db == NULL) {
         mp_raise_OSError(native_errno);
     }
 
-    return MP_OBJ_FROM_PTR(btree_new(db, args[0]));
+    return MP_OBJ_FROM_PTR(btree_new(db, pos_args[0]));
 }
-static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(btree_open_obj, 5, 5, btree_open);
+static MP_DEFINE_CONST_FUN_OBJ_KW(btree_open_obj, 1, btree_open);
 
 mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) {
     MP_DYNRUNTIME_INIT_ENTRY
@@ -147,7 +163,7 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *a
     btree_locals_dict_table[7] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_items), MP_OBJ_FROM_PTR(&btree_items_obj) };
     MP_OBJ_TYPE_SET_SLOT(&btree_type, locals_dict, (void*)&btree_locals_dict, 4);
 
-    mp_store_global(MP_QSTR__open, MP_OBJ_FROM_PTR(&btree_open_obj));
+    mp_store_global(MP_QSTR_open, MP_OBJ_FROM_PTR(&btree_open_obj));
     mp_store_global(MP_QSTR_INCL, MP_OBJ_NEW_SMALL_INT(FLAG_END_KEY_INCL));
     mp_store_global(MP_QSTR_DESC, MP_OBJ_NEW_SMALL_INT(FLAG_DESC));
 
diff --git a/examples/natmod/btree/btree_py.py b/examples/natmod/btree/btree_py.py
deleted file mode 100644
index 461b045c98dfc..0000000000000
--- a/examples/natmod/btree/btree_py.py
+++ /dev/null
@@ -1,7 +0,0 @@
-# Implemented in Python to support keyword arguments
-
-# ruff: noqa: F821 - this file is evaluated with C-defined names in scope
-
-
-def open(stream, *, flags=0, cachesize=0, pagesize=0, minkeypage=0):
-    return _open(stream, flags, cachesize, pagesize, minkeypage)

From 5d07d0c7b0b2b3601d69a74da837d77e65941f75 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Mon, 27 May 2024 11:44:54 +1000
Subject: [PATCH 394/408] tests/run-natmodtests.py: Fix search for supported
 native tests.

Signed-off-by: Damien George 
---
 tests/run-natmodtests.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/run-natmodtests.py b/tests/run-natmodtests.py
index e61cf09933f0c..f1a2a974690ee 100755
--- a/tests/run-natmodtests.py
+++ b/tests/run-natmodtests.py
@@ -97,8 +97,9 @@ def run_script(self, script):
 def run_tests(target_truth, target, args, stats):
     for test_file in args.files:
         # Find supported test
+        test_file_basename = os.path.basename(test_file)
         for k, v in TEST_MAPPINGS.items():
-            if test_file.find(k) != -1:
+            if test_file_basename.startswith(k):
                 test_module = k
                 test_mpy = v.replace("$(ARCH)", args.arch)
                 break

From fbf811474af1c5a7c4c03743b11b248151199a36 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Mon, 27 May 2024 11:45:59 +1000
Subject: [PATCH 395/408] tools/ci.sh: Simplify selection of natmod tests to
 run.

The `run-natmodtests.py` script now properly excludes tests that don't use
the corresponding native module.

Signed-off-by: Damien George 
---
 tools/ci.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/ci.sh b/tools/ci.sh
index ad5e79c4ad07c..bac225caa4df1 100755
--- a/tools/ci.sh
+++ b/tools/ci.sh
@@ -517,7 +517,7 @@ function ci_unix_coverage_run_mpy_merge_tests {
 
 function ci_unix_coverage_run_native_mpy_tests {
     MICROPYPATH=examples/natmod/features2 ./ports/unix/build-coverage/micropython -m features2
-    (cd tests && ./run-natmodtests.py "$@" extmod/{btree*,deflate*,framebuf*,heapq*,random*,re*}.py)
+    (cd tests && ./run-natmodtests.py "$@" extmod/*.py)
 }
 
 function ci_unix_32bit_setup {

From c0a25a69eb9532396c7ff06dd8ab506403aba4a2 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Mon, 27 May 2024 11:49:06 +1000
Subject: [PATCH 396/408] extmod/modos: Only sync FAT filesystems using
 disk_ioctl.

Eventually this needs to be made a generic call to the underlying VFS.  But
for now this prevents `disk_ioctl()` crashing on non-FAT filesystems.

Signed-off-by: Damien George 
---
 extmod/modos.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/extmod/modos.c b/extmod/modos.c
index eda359b97b1b0..7f1e31fba7793 100644
--- a/extmod/modos.c
+++ b/extmod/modos.c
@@ -76,8 +76,9 @@
 static mp_obj_t mp_os_sync(void) {
     #if MICROPY_VFS_FAT
     for (mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table); vfs != NULL; vfs = vfs->next) {
-        // this assumes that vfs->obj is fs_user_mount_t with block device functions
-        disk_ioctl(MP_OBJ_TO_PTR(vfs->obj), CTRL_SYNC, NULL);
+        if (mp_obj_is_type(vfs->obj, &mp_fat_vfs_type)) {
+            disk_ioctl(MP_OBJ_TO_PTR(vfs->obj), CTRL_SYNC, NULL);
+        }
     }
     #endif
     return mp_const_none;

From 1ea06b99d8cc0cbcdb6d136eee607db67d12b37c Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Mon, 27 May 2024 12:01:05 +1000
Subject: [PATCH 397/408] tests/extmod: Fix regex strings to be of r"" type.

Otherwise escape characters like \s and \W won't work correctly.

Signed-off-by: Damien George 
---
 tests/extmod/re_namedclass.py | 6 +++---
 tests/extmod/re_sub.py        | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/tests/extmod/re_namedclass.py b/tests/extmod/re_namedclass.py
index 442172f4ab0c7..e71256671923d 100644
--- a/tests/extmod/re_namedclass.py
+++ b/tests/extmod/re_namedclass.py
@@ -31,6 +31,6 @@ def print_groups(match):
 print_groups(m)
 
 # named class within a class set
-print_groups(re.match("([^\s]+)\s*([^\s]+)", "1 23"))
-print_groups(re.match("([\s\d]+)([\W]+)", "1  2-+="))
-print_groups(re.match("([\W]+)([^\W]+)([^\S]+)([^\D]+)", " a_1 23"))
+print_groups(re.match(r"([^\s]+)\s*([^\s]+)", "1 23"))
+print_groups(re.match(r"([\s\d]+)([\W]+)", "1  2-+="))
+print_groups(re.match(r"([\W]+)([^\W]+)([^\S]+)([^\D]+)", " a_1 23"))
diff --git a/tests/extmod/re_sub.py b/tests/extmod/re_sub.py
index 229c0e63eed3d..2c7c6c10f1a49 100644
--- a/tests/extmod/re_sub.py
+++ b/tests/extmod/re_sub.py
@@ -15,9 +15,9 @@ def multiply(m):
     return str(int(m.group(0)) * 2)
 
 
-print(re.sub("\d+", multiply, "10 20 30 40 50"))
+print(re.sub(r"\d+", multiply, "10 20 30 40 50"))
 
-print(re.sub("\d+", lambda m: str(int(m.group(0)) // 2), "10 20 30 40 50"))
+print(re.sub(r"\d+", lambda m: str(int(m.group(0)) // 2), "10 20 30 40 50"))
 
 
 def A():

From 2e852522b178e6e9b2f0cdb954ba44aa9e7d7c0d Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Mon, 27 May 2024 12:27:22 +1000
Subject: [PATCH 398/408] tests/extmod: Add .exp test files for
 asyncio.get_event_loop tests.

And use `asyncio.new_event_loop()` where possible.  This change is needed
because CPython 3.12 deprecated the `get_event_loop()` function.

Signed-off-by: Damien George 
---
 tests/extmod/asyncio_get_event_loop.py     | 1 +
 tests/extmod/asyncio_get_event_loop.py.exp | 2 ++
 tests/extmod/asyncio_loop_stop.py          | 2 +-
 tests/extmod/asyncio_new_event_loop.py     | 1 +
 tests/extmod/asyncio_new_event_loop.py.exp | 6 ++++++
 5 files changed, 11 insertions(+), 1 deletion(-)
 create mode 100644 tests/extmod/asyncio_get_event_loop.py.exp
 create mode 100644 tests/extmod/asyncio_new_event_loop.py.exp

diff --git a/tests/extmod/asyncio_get_event_loop.py b/tests/extmod/asyncio_get_event_loop.py
index b2d50e3cba7a0..bbc1a6b2dce95 100644
--- a/tests/extmod/asyncio_get_event_loop.py
+++ b/tests/extmod/asyncio_get_event_loop.py
@@ -1,4 +1,5 @@
 # Test get_event_loop()
+# Note: CPython deprecated get_event_loop() so this test needs a .exp
 
 try:
     import asyncio
diff --git a/tests/extmod/asyncio_get_event_loop.py.exp b/tests/extmod/asyncio_get_event_loop.py.exp
new file mode 100644
index 0000000000000..5d0fb3b2d2edd
--- /dev/null
+++ b/tests/extmod/asyncio_get_event_loop.py.exp
@@ -0,0 +1,2 @@
+start
+end
diff --git a/tests/extmod/asyncio_loop_stop.py b/tests/extmod/asyncio_loop_stop.py
index b4bd0c74ad90a..e2a4cdc1af853 100644
--- a/tests/extmod/asyncio_loop_stop.py
+++ b/tests/extmod/asyncio_loop_stop.py
@@ -34,7 +34,7 @@ async def main():
     loop.stop()
 
 
-loop = asyncio.get_event_loop()
+loop = asyncio.new_event_loop()
 loop.create_task(main())
 
 for i in range(3):
diff --git a/tests/extmod/asyncio_new_event_loop.py b/tests/extmod/asyncio_new_event_loop.py
index a3feb02126c70..5bb31f1292bb1 100644
--- a/tests/extmod/asyncio_new_event_loop.py
+++ b/tests/extmod/asyncio_new_event_loop.py
@@ -1,4 +1,5 @@
 # Test Loop.new_event_loop()
+# Note: CPython deprecated get_event_loop() so this test needs a .exp
 
 try:
     import asyncio
diff --git a/tests/extmod/asyncio_new_event_loop.py.exp b/tests/extmod/asyncio_new_event_loop.py.exp
new file mode 100644
index 0000000000000..9e104fda39c94
--- /dev/null
+++ b/tests/extmod/asyncio_new_event_loop.py.exp
@@ -0,0 +1,6 @@
+start
+task 0
+stop
+start
+task 0
+stop

From 1a2fdcac0d3f38146286e8fc3a504648f499c215 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Mon, 27 May 2024 12:38:55 +1000
Subject: [PATCH 399/408] tests/basics: Split out generator.throw tests that
 pass multiple args.

The three-argument form of `.throw()` is deprecated since CPython 3.12.  So
split out into separate tests (with .exp files) the parts of the generator
tests that test more than one argument.

Signed-off-by: Damien George 
---
 tests/basics/gen_yield_from_throw.py          | 18 ----------
 .../basics/gen_yield_from_throw_multi_arg.py  | 34 +++++++++++++++++++
 .../gen_yield_from_throw_multi_arg.py.exp     |  8 +++++
 tests/basics/generator_throw.py               | 10 ------
 tests/basics/generator_throw_multi_arg.py     | 21 ++++++++++++
 tests/basics/generator_throw_multi_arg.py.exp |  6 ++++
 6 files changed, 69 insertions(+), 28 deletions(-)
 create mode 100644 tests/basics/gen_yield_from_throw_multi_arg.py
 create mode 100644 tests/basics/gen_yield_from_throw_multi_arg.py.exp
 create mode 100644 tests/basics/generator_throw_multi_arg.py
 create mode 100644 tests/basics/generator_throw_multi_arg.py.exp

diff --git a/tests/basics/gen_yield_from_throw.py b/tests/basics/gen_yield_from_throw.py
index 1f76e13f3c34c..063bed25e200b 100644
--- a/tests/basics/gen_yield_from_throw.py
+++ b/tests/basics/gen_yield_from_throw.py
@@ -17,24 +17,6 @@ def gen2():
 except TypeError:
     print("got TypeError from downstream!")
 
-# passing None as second argument to throw
-g = gen2()
-print(next(g))
-print(g.throw(ValueError, None))
-try:
-    print(next(g))
-except TypeError:
-    print("got TypeError from downstream!")
-
-# passing an exception instance as second argument to throw
-g = gen2()
-print(next(g))
-print(g.throw(ValueError, ValueError(123)))
-try:
-    print(next(g))
-except TypeError:
-    print("got TypeError from downstream!")
-
 # thrown value is caught and then generator returns normally
 def gen():
     try:
diff --git a/tests/basics/gen_yield_from_throw_multi_arg.py b/tests/basics/gen_yield_from_throw_multi_arg.py
new file mode 100644
index 0000000000000..86d580a6d5332
--- /dev/null
+++ b/tests/basics/gen_yield_from_throw_multi_arg.py
@@ -0,0 +1,34 @@
+# Test generator .throw() with multiple arguments.
+# Using multiple arguments is deprecated since CPython 3.12.
+
+
+def gen():
+    try:
+        yield 1
+    except ValueError as e:
+        print("got ValueError from upstream!", repr(e.args))
+    yield "str1"
+    raise TypeError
+
+
+def gen2():
+    print((yield from gen()))
+
+
+# Passing None as second argument to throw.
+g = gen2()
+print(next(g))
+print(g.throw(ValueError, None))
+try:
+    print(next(g))
+except TypeError:
+    print("got TypeError from downstream!")
+
+# Passing an exception instance as second argument to throw.
+g = gen2()
+print(next(g))
+print(g.throw(ValueError, ValueError(123)))
+try:
+    print(next(g))
+except TypeError:
+    print("got TypeError from downstream!")
diff --git a/tests/basics/gen_yield_from_throw_multi_arg.py.exp b/tests/basics/gen_yield_from_throw_multi_arg.py.exp
new file mode 100644
index 0000000000000..218e332e5017a
--- /dev/null
+++ b/tests/basics/gen_yield_from_throw_multi_arg.py.exp
@@ -0,0 +1,8 @@
+1
+got ValueError from upstream! ()
+str1
+got TypeError from downstream!
+1
+got ValueError from upstream! (123,)
+str1
+got TypeError from downstream!
diff --git a/tests/basics/generator_throw.py b/tests/basics/generator_throw.py
index 067ab2b8eb2a1..536f500823647 100644
--- a/tests/basics/generator_throw.py
+++ b/tests/basics/generator_throw.py
@@ -41,13 +41,3 @@ def gen():
 g = gen()
 print(next(g))
 print(g.throw(GeneratorExit()))
-
-# thrown an instance with None as second arg
-g = gen()
-print(next(g))
-print(g.throw(GeneratorExit(), None))
-
-# thrown a class and instance
-g = gen()
-print(next(g))
-print(g.throw(GeneratorExit, GeneratorExit(123)))
diff --git a/tests/basics/generator_throw_multi_arg.py b/tests/basics/generator_throw_multi_arg.py
new file mode 100644
index 0000000000000..acdb6a06c96d0
--- /dev/null
+++ b/tests/basics/generator_throw_multi_arg.py
@@ -0,0 +1,21 @@
+# Test generator .throw() with multiple arguments.
+# Using multiple arguments is deprecated since CPython 3.12.
+
+# Generator ignores a thrown GeneratorExit (this is allowed).
+def gen():
+    try:
+        yield 123
+    except GeneratorExit as e:
+        print("GeneratorExit", repr(e.args))
+    yield 456
+
+
+# Thrown an instance with None as second arg.
+g = gen()
+print(next(g))
+print(g.throw(GeneratorExit(), None))
+
+# Thrown a class and instance.
+g = gen()
+print(next(g))
+print(g.throw(GeneratorExit, GeneratorExit(123)))
diff --git a/tests/basics/generator_throw_multi_arg.py.exp b/tests/basics/generator_throw_multi_arg.py.exp
new file mode 100644
index 0000000000000..6e976eab1db23
--- /dev/null
+++ b/tests/basics/generator_throw_multi_arg.py.exp
@@ -0,0 +1,6 @@
+123
+GeneratorExit ()
+456
+123
+GeneratorExit (123,)
+456

From e1111d873aaa342df9e0b121cacf9f5184e41a58 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Mon, 27 May 2024 11:46:56 +1000
Subject: [PATCH 400/408] tests/net_hosted/ssl_verify_callback.py: Make exp
 match actual output.

The `cert` argument passed to the verify callback is actually a memoryview.
And the `depth` argument seems to start at 1 for the tested URL.

Signed-off-by: Damien George 
---
 tests/net_hosted/ssl_verify_callback.py.exp | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/tests/net_hosted/ssl_verify_callback.py.exp b/tests/net_hosted/ssl_verify_callback.py.exp
index e27dcbb9d5f70..e4564ce5abaa9 100644
--- a/tests/net_hosted/ssl_verify_callback.py.exp
+++ b/tests/net_hosted/ssl_verify_callback.py.exp
@@ -1,5 +1,4 @@
-verify_callback:  True 2
-verify_callback:  True 1
-verify_callback:  True 0
-verify_callback_fail:  True 2
+verify_callback:  True 1
+verify_callback:  True 0
+verify_callback_fail:  True 1
 MBEDTLS_ERR_ERROR_GENERIC_ERROR

From a34b5d1b7950a01582e20f2ec602d08794c2a83e Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Mon, 27 May 2024 13:56:04 +1000
Subject: [PATCH 401/408] tests/net_inet/tls_text_errors.py: Tweak test for
 newer CPython version.

Signed-off-by: Damien George 
---
 tests/net_inet/tls_text_errors.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tests/net_inet/tls_text_errors.py b/tests/net_inet/tls_text_errors.py
index 034cc8d36e7aa..f7c8014d75c28 100644
--- a/tests/net_inet/tls_text_errors.py
+++ b/tests/net_inet/tls_text_errors.py
@@ -17,10 +17,12 @@ def test(addr):
         # mbedtls produces "mbedtls -0x7200: SSL - An invalid SSL record was received"
         # axtls produces "RECORD_OVERFLOW" but also prints "TLS buffer overflow,..."
         # CPython produces "[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1108)"
+        # CPython newer version produces "[SSL] record layer failure (_ssl.c:1000)"
         ok = (
             "SSL_INVALID_RECORD" in str(e)
             or "RECORD_OVERFLOW" in str(e)
             or "wrong version" in str(e)
+            or "record layer failure" in str(e)
         )
         print("wrap:", ok)
         if not ok:

From 03cf4d4980af604ebae6928f51a311b53d98e2c8 Mon Sep 17 00:00:00 2001
From: Matt Trentini 
Date: Sun, 26 May 2024 19:39:26 +1000
Subject: [PATCH 402/408] rp2/boards/W5500_EVB_PICO: Update incorrect url in
 board.json.

Fixes issue #15122.

Signed-off-by: Matt Trentini 
---
 ports/rp2/boards/W5500_EVB_PICO/board.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ports/rp2/boards/W5500_EVB_PICO/board.json b/ports/rp2/boards/W5500_EVB_PICO/board.json
index 93598255599bf..e7625c343698e 100644
--- a/ports/rp2/boards/W5500_EVB_PICO/board.json
+++ b/ports/rp2/boards/W5500_EVB_PICO/board.json
@@ -15,6 +15,6 @@
     "mcu": "rp2040",
     "product": "Wiznet W5500-EVB-Pico",
     "thumbnail": "",
-    "url": "https://www.wiznet.io/product-item/w5500-evb-pico/",
+    "url": "https://docs.wiznet.io/Product/iEthernet/W5500/w5500-evb-pico",
     "vendor": "Wiznet"
 }

From 8a8c65f309a39e99b3bd5a74c5da313d8a5ec5fd Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Mon, 27 May 2024 16:05:31 +1000
Subject: [PATCH 403/408] lib/micropython-lib: Update submodule to latest.

This brings in:
- fixes to: aiohttp, tarfile, lora, gzip
- fixes and improvements to aioble
- deprecation of cbor2 decoder and encoder modules
- new usb package
- new pyusb package

Signed-off-by: Damien George 
---
 lib/micropython-lib | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/micropython-lib b/lib/micropython-lib
index ddb1a279578bf..50ed36fbeb919 160000
--- a/lib/micropython-lib
+++ b/lib/micropython-lib
@@ -1 +1 @@
-Subproject commit ddb1a279578bfff8c1b18aff3baa668620684f64
+Subproject commit 50ed36fbeb919753bcc26ce13a8cffd7691d06ef

From 5f6e6891245c5c766801bb6c0a62395fefae132c Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Mon, 27 May 2024 23:39:16 +1000
Subject: [PATCH 404/408] LICENSE,docs: Update copyright year range to include
 2024.

Signed-off-by: Damien George 
---
 LICENSE      | 2 +-
 docs/conf.py | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/LICENSE b/LICENSE
index 9142c46045846..469ae1927396d 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
 The MIT License (MIT)
 
-Copyright (c) 2013-2023 Damien P. George
+Copyright (c) 2013-2024 Damien P. George
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
diff --git a/docs/conf.py b/docs/conf.py
index 728e3c4285d82..32cc2be10e343 100755
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -68,7 +68,7 @@
 
 # General information about the project.
 project = "MicroPython"
-copyright = "- The MicroPython Documentation is Copyright © 2014-2023, Damien P. George, Paul Sokolovsky, and contributors"
+copyright = "- The MicroPython Documentation is Copyright © 2014-2024, Damien P. George, Paul Sokolovsky, and contributors"
 
 # The version info for the project you're documenting, acts as replacement for
 # |version| and |release|, also used in various other places throughout the

From ad6750b22ef160a233acf0fbf52619d13bcf273e Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Tue, 28 May 2024 10:49:22 +1000
Subject: [PATCH 405/408] tests/float: Use "not" instead of ~ to invert bool
 value.

Otherwise CPython gives a deprecation warning.

This test is not actually testing inversion of bools, rather that bit of
the test is used to compute the pass/fail result.

Signed-off-by: Damien George 
---
 tests/float/float2int_doubleprec_intbig.py | 2 +-
 tests/float/float2int_fp30_intbig.py       | 2 +-
 tests/float/float2int_intbig.py            | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tests/float/float2int_doubleprec_intbig.py b/tests/float/float2int_doubleprec_intbig.py
index 402966cace271..565698d8770b5 100644
--- a/tests/float/float2int_doubleprec_intbig.py
+++ b/tests/float/float2int_doubleprec_intbig.py
@@ -59,7 +59,7 @@
 def fp2int_test(num, name, should_fail):
     try:
         x = int(num)
-        passed = ~should_fail
+        passed = not should_fail
     except:
         passed = should_fail
     print("%s: %s" % (name, passed and "passed" or "failed"))
diff --git a/tests/float/float2int_fp30_intbig.py b/tests/float/float2int_fp30_intbig.py
index 1b22fe9646f5a..eb65f89502512 100644
--- a/tests/float/float2int_fp30_intbig.py
+++ b/tests/float/float2int_fp30_intbig.py
@@ -56,7 +56,7 @@
 def fp2int_test(num, name, should_fail):
     try:
         x = int(num)
-        passed = ~should_fail
+        passed = not should_fail
     except:
         passed = should_fail
     print("%s: %s" % (name, passed and "passed" or "failed"))
diff --git a/tests/float/float2int_intbig.py b/tests/float/float2int_intbig.py
index d047f247f2777..17414501c619f 100644
--- a/tests/float/float2int_intbig.py
+++ b/tests/float/float2int_intbig.py
@@ -59,7 +59,7 @@
 def fp2int_test(num, name, should_fail):
     try:
         x = int(num)
-        passed = ~should_fail
+        passed = not should_fail
     except:
         passed = should_fail
     print("%s: %s" % (name, passed and "passed" or "failed"))

From dd4767a7d1ba57f107a652310fdfbd0f0274a0c8 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Tue, 28 May 2024 10:50:57 +1000
Subject: [PATCH 406/408] tests/basics: Add .exp file for slice_op test.

CPython 3.12 implemented hashing for slices, so now differs to MicroPython.

Signed-off-by: Damien George 
---
 tests/basics/slice_op.py     | 2 ++
 tests/basics/slice_op.py.exp | 1 +
 2 files changed, 3 insertions(+)
 create mode 100644 tests/basics/slice_op.py.exp

diff --git a/tests/basics/slice_op.py b/tests/basics/slice_op.py
index f1e83c5e27dca..0bb6e365bfd85 100644
--- a/tests/basics/slice_op.py
+++ b/tests/basics/slice_op.py
@@ -1,3 +1,5 @@
+# Test slice unary operations.
+# CPython allows hashing slices, but MicroPython does not.
 
 try:
     t = [][:]
diff --git a/tests/basics/slice_op.py.exp b/tests/basics/slice_op.py.exp
new file mode 100644
index 0000000000000..6002b71c56ea0
--- /dev/null
+++ b/tests/basics/slice_op.py.exp
@@ -0,0 +1 @@
+TypeError

From 30a9ccf4caa72c62cb8656a1572518fef34b08a4 Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Tue, 28 May 2024 10:52:12 +1000
Subject: [PATCH 407/408] tests/basics: Move str/bytes tests that give
 SyntaxWarning to sep file.

In CPython 3.12 these invalid str/bytes/fstring escapes will issue a
SyntaxWarning, and so differ to MicroPython.

Signed-off-by: Damien George 
---
 tests/basics/bytes.py                      |  1 -
 tests/basics/bytes_escape_unicode.py       |  3 +++
 tests/basics/bytes_escape_unicode.py.exp   |  1 +
 tests/basics/string1.py                    |  1 -
 tests/basics/string_escape_invalid.py      |  4 ++++
 tests/basics/string_escape_invalid.py.exp  |  1 +
 tests/basics/string_fstring.py             | 15 ---------------
 tests/basics/string_fstring_invalid.py     | 13 +++++++++++++
 tests/basics/string_fstring_invalid.py.exp |  4 ++++
 9 files changed, 26 insertions(+), 17 deletions(-)
 create mode 100644 tests/basics/bytes_escape_unicode.py
 create mode 100644 tests/basics/bytes_escape_unicode.py.exp
 create mode 100644 tests/basics/string_escape_invalid.py
 create mode 100644 tests/basics/string_escape_invalid.py.exp
 create mode 100644 tests/basics/string_fstring_invalid.py
 create mode 100644 tests/basics/string_fstring_invalid.py.exp

diff --git a/tests/basics/bytes.py b/tests/basics/bytes.py
index 0b6b14fa55bb2..ba14c26da8dea 100644
--- a/tests/basics/bytes.py
+++ b/tests/basics/bytes.py
@@ -2,7 +2,6 @@
 print(b'123')
 print(br'123')
 print(rb'123')
-print(b'\u1234')
 
 # construction
 print(bytes())
diff --git a/tests/basics/bytes_escape_unicode.py b/tests/basics/bytes_escape_unicode.py
new file mode 100644
index 0000000000000..1e450696f4f4f
--- /dev/null
+++ b/tests/basics/bytes_escape_unicode.py
@@ -0,0 +1,3 @@
+# Coverage test for unicode escape in a bytes literal.
+# CPython issues a SyntaxWarning for this.
+print(b"\u1234")
diff --git a/tests/basics/bytes_escape_unicode.py.exp b/tests/basics/bytes_escape_unicode.py.exp
new file mode 100644
index 0000000000000..6affe51896eb1
--- /dev/null
+++ b/tests/basics/bytes_escape_unicode.py.exp
@@ -0,0 +1 @@
+b'\\u1234'
diff --git a/tests/basics/string1.py b/tests/basics/string1.py
index b3abfb9c608bd..ca8dfd5399a5d 100644
--- a/tests/basics/string1.py
+++ b/tests/basics/string1.py
@@ -5,7 +5,6 @@
 print(r'abc')
 print(u'abc')
 print(repr('\a\b\t\n\v\f\r'))
-print('\z') # unrecognised escape char
 
 # construction
 print(str())
diff --git a/tests/basics/string_escape_invalid.py b/tests/basics/string_escape_invalid.py
new file mode 100644
index 0000000000000..d9fdd6e546588
--- /dev/null
+++ b/tests/basics/string_escape_invalid.py
@@ -0,0 +1,4 @@
+# Test invalid escape characters.
+# CPython issues a SyntaxWarning for this.
+
+print("\z")
diff --git a/tests/basics/string_escape_invalid.py.exp b/tests/basics/string_escape_invalid.py.exp
new file mode 100644
index 0000000000000..c642929c6e846
--- /dev/null
+++ b/tests/basics/string_escape_invalid.py.exp
@@ -0,0 +1 @@
+\z
diff --git a/tests/basics/string_fstring.py b/tests/basics/string_fstring.py
index 1a3960680e4f8..42d093b37b508 100644
--- a/tests/basics/string_fstring.py
+++ b/tests/basics/string_fstring.py
@@ -29,21 +29,6 @@ def foo(a, b):
 # Nested '{' and '}' characters.
 print(f"a{ {0,1,2}}")
 
-# PEP-0498 specifies that '\\' and '#' must be disallowed explicitly, whereas
-# MicroPython relies on the syntax error as a result of the substitution.
-
-print(f"\\")
-print(f'#')
-try:
-    eval("f'{\}'")
-except SyntaxError:
-    print('SyntaxError')
-try:
-    eval("f'{#}'")
-except SyntaxError:
-    print('SyntaxError')
-
-
 # PEP-0498 specifies that handling of double braces '{{' or '}}' should
 # behave like str.format.
 print(f'{{}}')
diff --git a/tests/basics/string_fstring_invalid.py b/tests/basics/string_fstring_invalid.py
new file mode 100644
index 0000000000000..6fce323c5bce4
--- /dev/null
+++ b/tests/basics/string_fstring_invalid.py
@@ -0,0 +1,13 @@
+# PEP-0498 specifies that '\\' and '#' must be disallowed explicitly, whereas
+# MicroPython relies on the syntax error as a result of the substitution.
+
+print(f"\\")
+print(f"#")
+try:
+    eval("f'{\}'")
+except SyntaxError:
+    print("SyntaxError")
+try:
+    eval("f'{#}'")
+except SyntaxError:
+    print("SyntaxError")
diff --git a/tests/basics/string_fstring_invalid.py.exp b/tests/basics/string_fstring_invalid.py.exp
new file mode 100644
index 0000000000000..bcb7f259e5567
--- /dev/null
+++ b/tests/basics/string_fstring_invalid.py.exp
@@ -0,0 +1,4 @@
+\
+#
+SyntaxError
+SyntaxError

From a61c446c0b34e82aeb54b9770250d267656f2b7f Mon Sep 17 00:00:00 2001
From: Damien George 
Date: Fri, 31 May 2024 14:19:55 +1000
Subject: [PATCH 408/408] all: Bump version to 1.23.0.

Signed-off-by: Damien George 
---
 py/mpconfig.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/py/mpconfig.h b/py/mpconfig.h
index 1aa3e06994d3f..0ea52b1d8bbad 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -32,7 +32,7 @@
 #define MICROPY_VERSION_MAJOR 1
 #define MICROPY_VERSION_MINOR 23
 #define MICROPY_VERSION_MICRO 0
-#define MICROPY_VERSION_PRERELEASE 1
+#define MICROPY_VERSION_PRERELEASE 0
 
 // Combined version as a 32-bit number for convenience to allow version
 // comparison. Doesn't include prerelease state.