Skip to content

Commit 75b7f58

Browse files
committed
Update LiteX APIs for new tick
1 parent 1071924 commit 75b7f58

9 files changed

Lines changed: 67 additions & 153 deletions

File tree

ports/litex/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build-*/

ports/litex/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ SRC_C += \
116116
background.c \
117117
fatfs_port.c \
118118
mphalport.c \
119-
tick.c \
120119
boards/$(BOARD)/board.c \
121120
boards/$(BOARD)/pins.c \
122121
lib/libc/string0.c \

ports/litex/README.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
You'll need `dfu-util` to install CircuitPython on the Fomu.
2+
3+
Make sure the foboot bootloader is updated. Instructions are here: https://github.com/im-tomu/fomu-workshop/blob/master/docs/bootloader.rst
4+
5+
Once you've updated the bootloader, you should know how to use `dfu-util`. It's pretty easy!
6+
7+
To install CircuitPython do:
8+
9+
.. code-block:: shell
10+
11+
dfu-util -D adafruit-circuitpython-fomu-en_US-<version>.dfu
12+
13+
It will install and then restart. CIRCUITPY should appear as it usually does and work the same.

ports/litex/mphalport.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,6 @@
4040
void hal_dcd_isr(uint8_t rhport);
4141
#endif
4242

43-
/*------------------------------------------------------------------*/
44-
/* delay
45-
*------------------------------------------------------------------*/
46-
void mp_hal_delay_ms(mp_uint_t delay) {
47-
uint64_t start_tick = supervisor_ticks_ms64();
48-
uint64_t duration = 0;
49-
while (duration < delay) {
50-
#ifdef MICROPY_VM_HOOK_LOOP
51-
MICROPY_VM_HOOK_LOOP
52-
#endif
53-
// Check to see if we've been CTRL-Ced by autoreload or the user.
54-
if(MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)) ||
55-
MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception))) {
56-
break;
57-
}
58-
duration = (supervisor_ticks_ms64() - start_tick);
59-
// TODO(tannewt): Go to sleep for a little while while we wait.
60-
}
61-
}
62-
6343
extern void SysTick_Handler(void);
6444

6545
__attribute__((section(".ramtext")))

ports/litex/supervisor/internal_flash.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "py/runtime.h"
3838
#include "lib/oofatfs/ff.h"
3939

40+
#include "supervisor/flash.h"
4041
#include "supervisor/usb.h"
4142

4243
#include "csr.h"
@@ -270,7 +271,7 @@ uint32_t supervisor_flash_get_block_count(void) {
270271
}
271272

272273
__attribute__((section(".ramtext")))
273-
void supervisor_flash_flush(void) {
274+
void port_internal_flash_flush(void) {
274275
// Skip if data is the same, or if there is no data in the cache
275276
if (_flash_page_addr == NO_CACHE)
276277
return;

ports/litex/supervisor/port.c

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,43 @@
2727

2828
#include <stdint.h>
2929
#include "supervisor/port.h"
30+
#include "supervisor/shared/tick.h"
3031
#include "boards/board.h"
31-
#include "tick.h"
3232
#include "irq.h"
3333
#include "csr.h"
3434

35+
// Global millisecond tick count. 1024 per second because most RTCs are clocked with 32.768khz
36+
// crystals.
37+
volatile uint64_t raw_ticks = 0;
38+
volatile int subsecond = 0;
39+
__attribute__((section(".ramtext")))
40+
void SysTick_Handler(void) {
41+
timer0_ev_pending_write(1);
42+
raw_ticks += 1;
43+
subsecond += 1;
44+
// We track subsecond ticks so that we can increment raw_ticks one extra every 40 ms. We do this
45+
// every 40 except 0 to make it 24 increments and not 25.
46+
if (subsecond == 1000) {
47+
subsecond = 0;
48+
} else if (subsecond % 40 == 0) {
49+
raw_ticks += 1;
50+
}
51+
supervisor_tick();
52+
}
53+
54+
static void tick_init(void) {
55+
int t;
56+
57+
timer0_en_write(0);
58+
t = CONFIG_CLOCK_FREQUENCY / 1000; // 1000 kHz tick
59+
timer0_reload_write(t);
60+
timer0_load_write(t);
61+
timer0_en_write(1);
62+
timer0_ev_enable_write(1);
63+
timer0_ev_pending_write(1);
64+
irq_setmask(irq_getmask() | (1 << TIMER0_INTERRUPT));
65+
}
66+
3567
safe_mode_t port_init(void) {
3668
irq_setmask(0);
3769
irq_setie(1);
@@ -83,3 +115,21 @@ void port_set_saved_word(uint32_t value) {
83115
uint32_t port_get_saved_word(void) {
84116
return _ebss;
85117
}
118+
119+
uint64_t port_get_raw_ticks(uint8_t* subticks) {
120+
return raw_ticks;
121+
}
122+
123+
// Enable 1/1024 second tick.
124+
void port_enable_tick(void) {
125+
}
126+
127+
// Disable 1/1024 second tick.
128+
void port_disable_tick(void) {
129+
}
130+
131+
void port_interrupt_after_ticks(uint32_t ticks) {
132+
}
133+
134+
void port_sleep_until_interrupt(void) {
135+
}

ports/litex/supervisor/usb.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
* THE SOFTWARE.
2626
*/
2727

28-
29-
#include "tick.h"
3028
#include "supervisor/usb.h"
3129
#include "lib/utils/interrupt_char.h"
3230
#include "lib/mp-readline/readline.h"

ports/litex/tick.c

Lines changed: 0 additions & 82 deletions
This file was deleted.

ports/litex/tick.h

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)