[ion] Sharing millis & micros for blackbox and simulator

This commit is contained in:
Damien Nicolet
2018-11-08 23:54:11 +01:00
parent bc8d9746c8
commit f93bf97182
13 changed files with 33 additions and 49 deletions

View File

@@ -4,13 +4,15 @@ extern "C" {
#include "mphalport.h"
}
bool micropython_port_should_interrupt() {
bool micropython_port_should_interrupt(bool force) {
static int c = 0;
c++;
if (c%20000 != 0) {
return false;
if(!force) {
c++;
if (c%20000 != 0) {
return false;
}
c = 0;
}
c = 0;
Ion::Keyboard::State scan = Ion::Keyboard::scan();
if (scan.keyDown((Ion::Keyboard::Key)mp_interrupt_char)) {
mp_keyboard_interrupt();

View File

@@ -8,7 +8,7 @@ extern "C" {
/* should_interrupt effectively does something once every 20000 calls. It checks
* if a key is down to raise an interruption flag. */
bool micropython_port_should_interrupt();
bool micropython_port_should_interrupt(bool);
#ifdef __cplusplus
}

View File

@@ -90,7 +90,7 @@
// (This scheme won't work if we want to mix Thumb and normal ARM code.)
#define MICROPY_MAKE_POINTER_CALLABLE(p) (p)
#define MICROPY_VM_HOOK_LOOP micropython_port_should_interrupt();
#define MICROPY_VM_HOOK_LOOP micropython_port_should_interrupt(false);
typedef intptr_t mp_int_t; // must be pointer size
typedef uintptr_t mp_uint_t; // must be pointer size

View File

@@ -34,13 +34,15 @@
void delay_ms(mp_uint_t delay) {
uint32_t start = millis();
while (millis() - start < delay && !micropython_port_should_interrupt()) {
while (millis() - start < delay && !micropython_port_should_interrupt(true)) {
msleep(1);
}
}
void delay_us(mp_uint_t delay) {
uint32_t start = micros();
while (micros() - start < delay && !micropython_port_should_interrupt()) {
while (micros() - start < delay && !micropython_port_should_interrupt(false)) {
usleep(1);
}
}