From 2f95cc95a494395658eefed6130b9a8732117482 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Thu, 24 Dec 2020 14:06:57 +0800 Subject: [PATCH] litex: move more critical code to RAM The XIP SPI flash on Fomu is slow, which results in certain operations taking a long time. This becomes a problem for time-critical operations such as USB. Move various calls into RAM to improve performance. This includes the call to __modsi3 and __udivsi3 which are used by the supervisor handler to determine if periodic callbacks need to be run. This finishes fixing #3841 Signed-off-by: Sean Cross --- ports/litex/boards/fomu/fomu-spi.ld | 5 +++++ ports/litex/common-hal/microcontroller/__init__.c | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ports/litex/boards/fomu/fomu-spi.ld b/ports/litex/boards/fomu/fomu-spi.ld index 9b6443c673..e7db25b0c5 100644 --- a/ports/litex/boards/fomu/fomu-spi.ld +++ b/ports/litex/boards/fomu/fomu-spi.ld @@ -51,6 +51,11 @@ SECTIONS *(.text.tu_edpt_dir) *(.text.tu_fifo_empty) *(.text.usbd_edpt_busy) + *(.text.usb_irq_handler) + *(.text.supervisor_tick) + *(.text.port_get_raw_ticks) + *(.text.__modsi3) + *(.text.__udivsi3) *(.text.irq_getmask) *(.text.irq_setmask) *(.text.irq_pending) diff --git a/ports/litex/common-hal/microcontroller/__init__.c b/ports/litex/common-hal/microcontroller/__init__.c index 3c91661144..522a41e2e3 100644 --- a/ports/litex/common-hal/microcontroller/__init__.c +++ b/ports/litex/common-hal/microcontroller/__init__.c @@ -59,12 +59,15 @@ void common_hal_mcu_delay_us(uint32_t delay) { volatile uint32_t nesting_count = 0; +__attribute__((section(".ramtext"))) void common_hal_mcu_disable_interrupts(void) { - irq_setie(0); - // __DMB(); + if (nesting_count == 0) { + irq_setie(0); + } nesting_count++; } +__attribute__((section(".ramtext"))) void common_hal_mcu_enable_interrupts(void) { if (nesting_count == 0) { // This is very very bad because it means there was mismatched disable/enables so we