Merge pull request #3878 from xobs/fomu-fixes-6.0.0
Fomu fixes for 6.0.0
This commit is contained in:
commit
f9d9c031a9
@ -51,6 +51,11 @@ SECTIONS
|
|||||||
*(.text.tu_edpt_dir)
|
*(.text.tu_edpt_dir)
|
||||||
*(.text.tu_fifo_empty)
|
*(.text.tu_fifo_empty)
|
||||||
*(.text.usbd_edpt_busy)
|
*(.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_getmask)
|
||||||
*(.text.irq_setmask)
|
*(.text.irq_setmask)
|
||||||
*(.text.irq_pending)
|
*(.text.irq_pending)
|
||||||
|
@ -59,12 +59,15 @@ void common_hal_mcu_delay_us(uint32_t delay) {
|
|||||||
|
|
||||||
volatile uint32_t nesting_count = 0;
|
volatile uint32_t nesting_count = 0;
|
||||||
|
|
||||||
|
__attribute__((section(".ramtext")))
|
||||||
void common_hal_mcu_disable_interrupts(void) {
|
void common_hal_mcu_disable_interrupts(void) {
|
||||||
irq_setie(0);
|
if (nesting_count == 0) {
|
||||||
// __DMB();
|
irq_setie(0);
|
||||||
|
}
|
||||||
nesting_count++;
|
nesting_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__attribute__((section(".ramtext")))
|
||||||
void common_hal_mcu_enable_interrupts(void) {
|
void common_hal_mcu_enable_interrupts(void) {
|
||||||
if (nesting_count == 0) {
|
if (nesting_count == 0) {
|
||||||
// This is very very bad because it means there was mismatched disable/enables so we
|
// This is very very bad because it means there was mismatched disable/enables so we
|
||||||
|
@ -44,16 +44,31 @@ void mp_hal_delay_us(mp_uint_t delay) {
|
|||||||
|
|
||||||
extern void SysTick_Handler(void);
|
extern void SysTick_Handler(void);
|
||||||
|
|
||||||
|
// This value contains the number of times "common_hal_mcu_disable_interrupts()"
|
||||||
|
// has been called without calling "common_hal_mcu_enable_interrupts()". Since
|
||||||
|
// this is the interrupt handler, that means we're handling an interrupt, so
|
||||||
|
// this value should be `0`.
|
||||||
|
//
|
||||||
|
// Interrupts should already be disabled when this handler is running, which means
|
||||||
|
// this value is logically already `1`. If we didn't do this, then interrupts would
|
||||||
|
// be prematurely enabled by interrupt handlers that enable and disable interrupts.
|
||||||
|
extern volatile uint32_t nesting_count;
|
||||||
|
|
||||||
__attribute__((section(".ramtext")))
|
__attribute__((section(".ramtext")))
|
||||||
void isr(void) {
|
void isr(void) {
|
||||||
uint8_t irqs = irq_pending() & irq_getmask();
|
uint8_t irqs = irq_pending() & irq_getmask();
|
||||||
|
|
||||||
|
// Increase the "nesting count". Note: This should be going from 0 -> 1.
|
||||||
|
nesting_count += 1;
|
||||||
#ifdef CFG_TUSB_MCU
|
#ifdef CFG_TUSB_MCU
|
||||||
if (irqs & (1 << USB_INTERRUPT))
|
if (irqs & (1 << USB_INTERRUPT))
|
||||||
usb_irq_handler();
|
usb_irq_handler();
|
||||||
#endif
|
#endif
|
||||||
if (irqs & (1 << TIMER0_INTERRUPT))
|
if (irqs & (1 << TIMER0_INTERRUPT))
|
||||||
SysTick_Handler();
|
SysTick_Handler();
|
||||||
|
|
||||||
|
// Decrease the "nesting count". Note: This should be going from 1 -> 0.
|
||||||
|
nesting_count -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_uint_t cpu_get_regs_and_sp(mp_uint_t *regs) {
|
mp_uint_t cpu_get_regs_and_sp(mp_uint_t *regs) {
|
||||||
|
@ -32,6 +32,8 @@
|
|||||||
#include "irq.h"
|
#include "irq.h"
|
||||||
#include "csr.h"
|
#include "csr.h"
|
||||||
|
|
||||||
|
#include "shared-bindings/microcontroller/__init__.h"
|
||||||
|
|
||||||
// Global millisecond tick count. 1024 per second because most RTCs are clocked with 32.768khz
|
// Global millisecond tick count. 1024 per second because most RTCs are clocked with 32.768khz
|
||||||
// crystals.
|
// crystals.
|
||||||
volatile uint64_t raw_ticks = 0;
|
volatile uint64_t raw_ticks = 0;
|
||||||
@ -129,9 +131,9 @@ uint32_t port_get_saved_word(void) {
|
|||||||
|
|
||||||
uint64_t port_get_raw_ticks(uint8_t* subticks) {
|
uint64_t port_get_raw_ticks(uint8_t* subticks) {
|
||||||
// Reading 64 bits may take two loads, so turn of interrupts while we do it.
|
// Reading 64 bits may take two loads, so turn of interrupts while we do it.
|
||||||
irq_setie(false);
|
common_hal_mcu_disable_interrupts();
|
||||||
uint64_t raw_tick_snapshot = raw_ticks;
|
uint64_t raw_tick_snapshot = raw_ticks;
|
||||||
irq_setie(true);
|
common_hal_mcu_enable_interrupts();
|
||||||
return raw_tick_snapshot;
|
return raw_tick_snapshot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user