10000 Merge pull request #3878 from xobs/fomu-fixes-6.0.0 · nmorse/circuitpython@f9d9c03 · GitHub
[go: up one dir, main page]

Skip to content

Commit f9d9c03

Browse files
authored
Merge pull request adafruit#3878 from xobs/fomu-fixes-6.0.0
Fomu fixes for 6.0.0
2 parents c3396e4 + 2f95cc9 commit f9d9c03

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

ports/litex/boards/fomu/fomu-spi.ld

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ SECTIONS
5151
*(.text.tu_edpt_dir)
5252
*(.text.tu_fifo_empty)
5353
*(.text.usbd_edpt_busy)
54+
*(.text.usb_irq_handler)
55+
*(.text.supervisor_tick)
56+
*(.text.port_get_raw_ticks)
57+
*(.text.__modsi3)
58+
*(.text.__udivsi3)
5459
*(.text.irq_getmask)
5560
*(.text.irq_setmask)
5661
*(.text.irq_pending)

ports/litex/common-hal/microcontroller/__init__.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,15 @@ void common_hal_mcu_delay_us(uint32_t delay) {
5959

6060
volatile uint32_t nesting_count = 0;
6161

62+
__attribute__((section(".ramtext")))
6263
void common_hal_mcu_disable_interrupts(void) {
63-
irq_setie(0);
64-
// __DMB();
64+
if (nesting_count == 0) {
65+
irq_setie(0);
66+
}
6567
nesting_count++;
6668
}
6769

70+
__attribute__((section(".ramtext")))
6871
void common_hal_mcu_enable_interrupts(void) {
6972
if (nesting_count == 0) {
7073
// This is very very bad because it means there was mismatched disable/enables so we

ports/litex/mphalport.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,31 @@ void mp_hal_delay_us(mp_uint_t delay) {
4444

4545
extern void SysTick_Handler(void);
4646

47+
// This value contains the number of times "common_hal_mcu_disable_interrupts()"
48+
// has been called without calling "common_hal_mcu_enable_interrupts()". Since
49+
// this is the interrupt handler, that means we're handling an interrupt, so
50+
// this value should be `0`.
51+
//
52+
// Interrupts should already be disabled when this handler is running, which means
53+
// this value is logically already `1`. If we didn't do this, then interrupts would
54+
// be prematurely enabled by interrupt handlers that enable and disable interrupts.
55+
extern volatile uint32_t nesting_count;
56+
4757
__attribute__((section(".ramtext")))
4858
void isr(void) {
4959
uint8_t irqs = irq_pending() & irq_getmask();
5060

61+
// Increase the "nesting count". Note: This should be going from 0 -> 1.
62+
nesting_count += 1;
5163
#ifdef CFG_TUSB_MCU
5264
if (irqs & (1 << USB_INTERRUPT))
5365
usb_irq_handler();
5466
#endif
5567
if (irqs & (1 << TIMER0_INTERRUPT))
5668
SysTick_Handler();
69+
70+
// Decrease the "nesting count". Note: This should be going from 1 -> 0.
71+
nesting_count -= 1;
5772
}
5873

5974
mp_uint_t cpu_get_regs_and_sp(mp_uint_t *regs) {

ports/litex/supervisor/port.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "irq.h"
3333
#include "csr.h"
3434

35+
#include "shared-bindings/microcontroller/__init__.h"
36+
3537
// Global millisecond tick count. 1024 per second because most RTCs are clocked with 32.768khz
3638
// crystals.
3739
volatile uint64_t raw_ticks = 0;
@@ -129,9 +131,9 @@ uint32_t port_get_saved_word(void) {
129131

130132
uint64_t port_get_raw_ticks(uint8_t* subticks) {
131133
// Reading 64 bits may take two loads, so turn of interrupts while we do it.
132-
irq_setie(false);
134+
common_hal_mcu_disable_interrupts();
133135
uint64_t raw_tick_snapshot = raw_ticks;
134-
irq_setie(true);
136+
common_hal_mcu_enable_interrupts();
135137
return raw_tick_snapshot;
136138
}
137139

0 commit comments

Comments
 (0)
0