Update LiteX APIs for new tick
This commit is contained in:
parent
1071924701
commit
75b7f583d2
1
ports/litex/.gitignore
vendored
Normal file
1
ports/litex/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
build-*/
|
@ -116,7 +116,6 @@ SRC_C += \
|
|||||||
background.c \
|
background.c \
|
||||||
fatfs_port.c \
|
fatfs_port.c \
|
||||||
mphalport.c \
|
mphalport.c \
|
||||||
tick.c \
|
|
||||||
boards/$(BOARD)/board.c \
|
boards/$(BOARD)/board.c \
|
||||||
boards/$(BOARD)/pins.c \
|
boards/$(BOARD)/pins.c \
|
||||||
lib/libc/string0.c \
|
lib/libc/string0.c \
|
||||||
|
13
ports/litex/README.rst
Normal file
13
ports/litex/README.rst
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
You'll need `dfu-util` to install CircuitPython on the Fomu.
|
||||||
|
|
||||||
|
Make sure the foboot bootloader is updated. Instructions are here: https://github.com/im-tomu/fomu-workshop/blob/master/docs/bootloader.rst
|
||||||
|
|
||||||
|
Once you've updated the bootloader, you should know how to use `dfu-util`. It's pretty easy!
|
||||||
|
|
||||||
|
To install CircuitPython do:
|
||||||
|
|
||||||
|
.. code-block:: shell
|
||||||
|
|
||||||
|
dfu-util -D adafruit-circuitpython-fomu-en_US-<version>.dfu
|
||||||
|
|
||||||
|
It will install and then restart. CIRCUITPY should appear as it usually does and work the same.
|
@ -40,26 +40,6 @@
|
|||||||
void hal_dcd_isr(uint8_t rhport);
|
void hal_dcd_isr(uint8_t rhport);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
|
||||||
/* delay
|
|
||||||
*------------------------------------------------------------------*/
|
|
||||||
void mp_hal_delay_ms(mp_uint_t delay) {
|
|
||||||
uint64_t start_tick = supervisor_ticks_ms64();
|
|
||||||
uint64_t duration = 0;
|
|
||||||
while (duration < delay) {
|
|
||||||
#ifdef MICROPY_VM_HOOK_LOOP
|
|
||||||
MICROPY_VM_HOOK_LOOP
|
|
||||||
#endif
|
|
||||||
// Check to see if we've been CTRL-Ced by autoreload or the user.
|
|
||||||
if(MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)) ||
|
|
||||||
MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception))) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
duration = (supervisor_ticks_ms64() - start_tick);
|
|
||||||
// TODO(tannewt): Go to sleep for a little while while we wait.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extern void SysTick_Handler(void);
|
extern void SysTick_Handler(void);
|
||||||
|
|
||||||
__attribute__((section(".ramtext")))
|
__attribute__((section(".ramtext")))
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
#include "py/runtime.h"
|
#include "py/runtime.h"
|
||||||
#include "lib/oofatfs/ff.h"
|
#include "lib/oofatfs/ff.h"
|
||||||
|
|
||||||
|
#include "supervisor/flash.h"
|
||||||
#include "supervisor/usb.h"
|
#include "supervisor/usb.h"
|
||||||
|
|
||||||
#include "csr.h"
|
#include "csr.h"
|
||||||
@ -270,7 +271,7 @@ uint32_t supervisor_flash_get_block_count(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((section(".ramtext")))
|
__attribute__((section(".ramtext")))
|
||||||
void supervisor_flash_flush(void) {
|
void port_internal_flash_flush(void) {
|
||||||
// Skip if data is the same, or if there is no data in the cache
|
// Skip if data is the same, or if there is no data in the cache
|
||||||
if (_flash_page_addr == NO_CACHE)
|
if (_flash_page_addr == NO_CACHE)
|
||||||
return;
|
return;
|
||||||
|
@ -27,11 +27,43 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "supervisor/port.h"
|
#include "supervisor/port.h"
|
||||||
|
#include "supervisor/shared/tick.h"
|
||||||
#include "boards/board.h"
|
#include "boards/board.h"
|
||||||
#include "tick.h"
|
|
||||||
#include "irq.h"
|
#include "irq.h"
|
||||||
#include "csr.h"
|
#include "csr.h"
|
||||||
|
|
||||||
|
// Global millisecond tick count. 1024 per second because most RTCs are clocked with 32.768khz
|
||||||
|
// crystals.
|
||||||
|
volatile uint64_t raw_ticks = 0;
|
||||||
|
volatile int subsecond = 0;
|
||||||
|
__attribute__((section(".ramtext")))
|
||||||
|
void SysTick_Handler(void) {
|
||||||
|
timer0_ev_pending_write(1);
|
||||||
|
raw_ticks += 1;
|
||||||
|
subsecond += 1;
|
||||||
|
// We track subsecond ticks so that we can increment raw_ticks one extra every 40 ms. We do this
|
||||||
|
// every 40 except 0 to make it 24 increments and not 25.
|
||||||
|
if (subsecond == 1000) {
|
||||||
|
subsecond = 0;
|
||||||
|
} else if (subsecond % 40 == 0) {
|
||||||
|
raw_ticks += 1;
|
||||||
|
}
|
||||||
|
supervisor_tick();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void tick_init(void) {
|
||||||
|
int t;
|
||||||
|
|
||||||
|
timer0_en_write(0);
|
||||||
|
t = CONFIG_CLOCK_FREQUENCY / 1000; // 1000 kHz tick
|
||||||
|
timer0_reload_write(t);
|
||||||
|
timer0_load_write(t);
|
||||||
|
timer0_en_write(1);
|
||||||
|
timer0_ev_enable_write(1);
|
||||||
|
timer0_ev_pending_write(1);
|
||||||
|
irq_setmask(irq_getmask() | (1 << TIMER0_INTERRUPT));
|
||||||
|
}
|
||||||
|
|
||||||
safe_mode_t port_init(void) {
|
safe_mode_t port_init(void) {
|
||||||
irq_setmask(0);
|
irq_setmask(0);
|
||||||
irq_setie(1);
|
irq_setie(1);
|
||||||
@ -83,3 +115,21 @@ void port_set_saved_word(uint32_t value) {
|
|||||||
uint32_t port_get_saved_word(void) {
|
uint32_t port_get_saved_word(void) {
|
||||||
return _ebss;
|
return _ebss;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t port_get_raw_ticks(uint8_t* subticks) {
|
||||||
|
return raw_ticks;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable 1/1024 second tick.
|
||||||
|
void port_enable_tick(void) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable 1/1024 second tick.
|
||||||
|
void port_disable_tick(void) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void port_interrupt_after_ticks(uint32_t ticks) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void port_sleep_until_interrupt(void) {
|
||||||
|
}
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "tick.h"
|
|
||||||
#include "supervisor/usb.h"
|
#include "supervisor/usb.h"
|
||||||
#include "lib/utils/interrupt_char.h"
|
#include "lib/utils/interrupt_char.h"
|
||||||
#include "lib/mp-readline/readline.h"
|
#include "lib/mp-readline/readline.h"
|
||||||
|
@ -1,82 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of the MicroPython project, http://micropython.org/
|
|
||||||
*
|
|
||||||
* The MIT License (MIT)
|
|
||||||
*
|
|
||||||
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
|
|
||||||
*
|
|
||||||
* 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 "csr.h"
|
|
||||||
#include "tick.h"
|
|
||||||
#include "irq.h"
|
|
||||||
|
|
||||||
#include "supervisor/shared/autoreload.h"
|
|
||||||
#include "supervisor/filesystem.h"
|
|
||||||
#include "supervisor/shared/tick.h"
|
|
||||||
#include "shared-module/gamepad/__init__.h"
|
|
||||||
#include "shared-bindings/microcontroller/Processor.h"
|
|
||||||
|
|
||||||
// Global millisecond tick count
|
|
||||||
// volatile uint64_t ticks_ms = 0;
|
|
||||||
|
|
||||||
__attribute__((section(".ramtext")))
|
|
||||||
void SysTick_Handler(void) {
|
|
||||||
timer0_ev_pending_write(1);
|
|
||||||
supervisor_tick();
|
|
||||||
}
|
|
||||||
|
|
||||||
void tick_init() {
|
|
||||||
int t;
|
|
||||||
|
|
||||||
timer0_en_write(0);
|
|
||||||
t = CONFIG_CLOCK_FREQUENCY / 1000; // 1000 kHz tick
|
|
||||||
timer0_reload_write(t);
|
|
||||||
timer0_load_write(t);
|
|
||||||
timer0_en_write(1);
|
|
||||||
timer0_ev_enable_write(1);
|
|
||||||
timer0_ev_pending_write(1);
|
|
||||||
irq_setmask(irq_getmask() | (1 << TIMER0_INTERRUPT));
|
|
||||||
}
|
|
||||||
|
|
||||||
void tick_delay(uint32_t us) {
|
|
||||||
// uint32_t ticks_per_us = SystemCoreClock / 1000 / 1000;
|
|
||||||
// uint32_t us_between_ticks = SysTick->VAL / ticks_per_us;
|
|
||||||
// uint64_t start_ms = ticks_ms;
|
|
||||||
// while (us > 1000) {
|
|
||||||
// while (ticks_ms == start_ms) {}
|
|
||||||
// us -= us_between_ticks;
|
|
||||||
// start_ms = ticks_ms;
|
|
||||||
// us_between_ticks = 1000;
|
|
||||||
// }
|
|
||||||
// while (SysTick->VAL > ((us_between_ticks - us) * ticks_per_us)) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// us counts down!
|
|
||||||
void current_tick(uint64_t* ms, uint32_t* us_until_ms) {
|
|
||||||
// uint32_t ticks_per_us = SystemCoreClock / 1000 / 1000;
|
|
||||||
// *ms = ticks_ms;
|
|
||||||
// *us_until_ms = SysTick->VAL / ticks_per_us;
|
|
||||||
}
|
|
||||||
|
|
||||||
void wait_until(uint64_t ms, uint32_t us_until_ms) {
|
|
||||||
// uint32_t ticks_per_us = SystemCoreClock / 1000 / 1000;
|
|
||||||
// while(ticks_ms <= ms && SysTick->VAL / ticks_per_us >= us_until_ms) {}
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of the MicroPython project, http://micropython.org/
|
|
||||||
*
|
|
||||||
* The MIT License (MIT)
|
|
||||||
*
|
|
||||||
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
|
|
||||||
*
|
|
||||||
* 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_LITEX_TICK_H
|
|
||||||
#define MICROPY_INCLUDED_LITEX_TICK_H
|
|
||||||
|
|
||||||
#include "py/mpconfig.h"
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
extern volatile uint64_t ticks_ms;
|
|
||||||
|
|
||||||
extern struct timer_descriptor ms_timer;
|
|
||||||
|
|
||||||
void tick_init(void);
|
|
||||||
|
|
||||||
void tick_delay(uint32_t us);
|
|
||||||
|
|
||||||
void current_tick(uint64_t* ms, uint32_t* us_until_ms);
|
|
||||||
// Do not call this with interrupts disabled because it may be waiting for
|
|
||||||
// ticks_ms to increment.
|
|
||||||
void wait_until(uint64_t ms, uint32_t us_until_ms);
|
|
||||||
|
|
||||||
#endif // MICROPY_INCLUDED_LITEX_TICK_H
|
|
Loading…
Reference in New Issue
Block a user