summaryrefslogtreecommitdiff
path: root/ports/litex
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2020-03-31 17:52:23 -0700
committerScott Shawcroft <scott@tannewt.org>2020-03-31 17:52:23 -0700
commit75b7f583d2a7eba4890373f2f75b159b01a86308 (patch)
tree6aaa25219c3a9432924153a2e5fd329d5dcddf40 /ports/litex
parent10719247010c958f4bc2227aa9f98577580688e1 (diff)
Update LiteX APIs for new tick
Diffstat (limited to 'ports/litex')
-rw-r--r--ports/litex/.gitignore1
-rw-r--r--ports/litex/Makefile1
-rw-r--r--ports/litex/README.rst13
-rw-r--r--ports/litex/mphalport.c20
-rw-r--r--ports/litex/supervisor/internal_flash.c3
-rw-r--r--ports/litex/supervisor/port.c52
-rw-r--r--ports/litex/supervisor/usb.c2
-rw-r--r--ports/litex/tick.c82
-rw-r--r--ports/litex/tick.h46
9 files changed, 67 insertions, 153 deletions
diff --git a/ports/litex/.gitignore b/ports/litex/.gitignore
new file mode 100644
index 000000000..414487d53
--- /dev/null
+++ b/ports/litex/.gitignore
@@ -0,0 +1 @@
+build-*/
diff --git a/ports/litex/Makefile b/ports/litex/Makefile
index 51cb18635..596eaf2bb 100644
--- a/ports/litex/Makefile
+++ b/ports/litex/Makefile
@@ -116,7 +116,6 @@ SRC_C += \
background.c \
fatfs_port.c \
mphalport.c \
- tick.c \
boards/$(BOARD)/board.c \
boards/$(BOARD)/pins.c \
lib/libc/string0.c \
diff --git a/ports/litex/README.rst b/ports/litex/README.rst
new file mode 100644
index 000000000..d3c66b22c
--- /dev/null
+++ b/ports/litex/README.rst
@@ -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.
diff --git a/ports/litex/mphalport.c b/ports/litex/mphalport.c
index 005a65aac..12eaaac3c 100644
--- a/ports/litex/mphalport.c
+++ b/ports/litex/mphalport.c
@@ -40,26 +40,6 @@
void hal_dcd_isr(uint8_t rhport);
#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);
__attribute__((section(".ramtext")))
diff --git a/ports/litex/supervisor/internal_flash.c b/ports/litex/supervisor/internal_flash.c
index 93aeda8cb..2dbf46b3a 100644
--- a/ports/litex/supervisor/internal_flash.c
+++ b/ports/litex/supervisor/internal_flash.c
@@ -37,6 +37,7 @@
#include "py/runtime.h"
#include "lib/oofatfs/ff.h"
+#include "supervisor/flash.h"
#include "supervisor/usb.h"
#include "csr.h"
@@ -270,7 +271,7 @@ uint32_t supervisor_flash_get_block_count(void) {
}
__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
if (_flash_page_addr == NO_CACHE)
return;
diff --git a/ports/litex/supervisor/port.c b/ports/litex/supervisor/port.c
index 9688c7bae..c2af0d2a9 100644
--- a/ports/litex/supervisor/port.c
+++ b/ports/litex/supervisor/port.c
@@ -27,11 +27,43 @@
#include <stdint.h>
#include "supervisor/port.h"
+#include "supervisor/shared/tick.h"
#include "boards/board.h"
-#include "tick.h"
#include "irq.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) {
irq_setmask(0);
irq_setie(1);
@@ -83,3 +115,21 @@ void port_set_saved_word(uint32_t value) {
uint32_t port_get_saved_word(void) {
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) {
+}
diff --git a/ports/litex/supervisor/usb.c b/ports/litex/supervisor/usb.c
index 182360b71..b626aaf49 100644
--- a/ports/litex/supervisor/usb.c
+++ b/ports/litex/supervisor/usb.c
@@ -25,8 +25,6 @@
* THE SOFTWARE.
*/
-
-#include "tick.h"
#include "supervisor/usb.h"
#include "lib/utils/interrupt_char.h"
#include "lib/mp-readline/readline.h"
diff --git a/ports/litex/tick.c b/ports/litex/tick.c
deleted file mode 100644
index 8ba06044a..000000000
--- a/ports/litex/tick.c
+++ /dev/null
@@ -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) {}
-}
diff --git a/ports/litex/tick.h b/ports/litex/tick.h
deleted file mode 100644
index b4d27b841..000000000
--- a/ports/litex/tick.h
+++ /dev/null
@@ -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