Fix up Spresense build. It doesn't sleep.

This commit is contained in:
Scott Shawcroft 2020-03-17 14:21:45 -07:00
parent d9e68156b2
commit 6db11cf68b
No known key found for this signature in database
GPG Key ID: 9349BC7E64B1921E
13 changed files with 72 additions and 186 deletions

View File

@ -34,9 +34,8 @@
#include "supervisor/shared/tick.h"
// Global millisecond tick count (driven by SysTick interrupt).
static inline mp_uint_t mp_hal_ticks_ms(void) {
return supervisor_ticks_ms32();
}
#define mp_hal_ticks_ms() ((mp_uint_t) supervisor_ticks_ms32())
// Number of bytes in receive buffer
volatile uint8_t usb_rx_count;
volatile bool mp_cdc_enabled;

View File

@ -152,7 +152,6 @@ SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE))
SRC_S = supervisor/cpu.s
SRC_C = \
tick.c \
background.c \
fatfs_port.c \
mphalport.c \
@ -184,7 +183,7 @@ OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
# List of sources for qstr extraction
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)
# Sources that only hold QSTRs after pre-processing.
SRC_QSTR_PREPROCESSOR +=
SRC_QSTR_PREPROCESSOR +=
all: $(BUILD)/firmware.spk
@ -197,7 +196,7 @@ $(FIRMWARE):
$(ECHO) "run make flash-bootloader again to flash bootloader."
exit 1
$(BUILD)/libmpy.a: $(SPRESENSE_SDK) $(OBJ)
$(BUILD)/libmpy.a: $(SPRESENSE_SDK) $(OBJ)
$(ECHO) "AR $@"
$(Q)$(AR) rcs $(BUILD)/libmpy.a $(OBJ)

View File

@ -24,6 +24,8 @@
* THE SOFTWARE.
*/
#include <stdbool.h> // for cxd56_clock.h
#include <cxd56_clock.h>
#include <sys/boardctl.h>
// For NAN: remove when not needed.
@ -31,7 +33,7 @@
#include "py/mphal.h"
uint32_t common_hal_mcu_processor_get_frequency(void) {
return mp_hal_ticks_cpu();
return cxd56_get_cpu_baseclk();
}
float common_hal_mcu_processor_get_temperature(void) {

View File

@ -24,6 +24,8 @@
* THE SOFTWARE.
*/
#include <stdbool.h> // for cxd56_clock.h
#include <cxd56_clock.h>
#include <sys/boardctl.h>
#include "py/mphal.h"
@ -42,8 +44,20 @@ const mcu_processor_obj_t common_hal_mcu_processor_obj = {
},
};
#define DELAY_CORRECTION (700)
void common_hal_mcu_delay_us(uint32_t delay) {
mp_hal_delay_us(delay);
if (delay) {
unsigned long long ticks = cxd56_get_cpu_baseclk() / 1000000L * delay;
if (ticks < DELAY_CORRECTION) return; // delay time already used in calculation
ticks -= DELAY_CORRECTION;
ticks /= 6;
// following loop takes 6 cycles
do {
__asm__ __volatile__("nop");
} while(--ticks);
}
}
void common_hal_mcu_disable_interrupts(void) {

View File

@ -25,6 +25,7 @@
*/
#include <arch/board/board.h>
#include <sys/time.h>
#include "py/runtime.h"
#include "py/mphal.h"
@ -51,7 +52,9 @@ static int pulsein_set_config(pulseio_pulsein_obj_t *self, bool first_edge) {
static int pulsein_interrupt_handler(int irq, FAR void *context, FAR void *arg) {
// Grab the current time first.
uint32_t current_us = mp_hal_ticks_us();
struct timeval tv;
gettimeofday(&tv, NULL);
uint32_t current_us = tv.tv_sec * 1000000 + tv.tv_usec;
pulseio_pulsein_obj_t *self = pulsein_objects[irq - CXD56_IRQ_EXDEVICE_0];

View File

@ -1,45 +0,0 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright 2019 Sony Semiconductor Solutions Corporation
*
* 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 <sys/time.h>
#include "py/mphal.h"
#include "supervisor/shared/tick.h"
uint64_t common_hal_time_monotonic(void) {
return supervisor_ticks_ms64();
}
uint64_t common_hal_time_monotonic_ns(void) {
struct timeval tv;
gettimeofday(&tv, NULL);
return 1000 * ((uint64_t) tv.tv_sec * 1000000 + (uint64_t) tv.tv_usec);
}
void common_hal_time_delay_ms(uint32_t delay) {
mp_hal_delay_ms(delay);
}

View File

@ -23,66 +23,3 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <stdbool.h>
#include <sys/time.h>
#include <cxd56_clock.h>
#include <sys/boardctl.h>
#include "py/mpstate.h"
#include "supervisor/shared/tick.h"
#define DELAY_CORRECTION (700)
#define DELAY_INTERVAL (50)
void mp_hal_init(void) {
boardctl(BOARDIOC_INIT, 0);
}
mp_uint_t mp_hal_ticks_ms(void) {
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
}
mp_uint_t mp_hal_ticks_us(void) {
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000000 + tv.tv_usec;
}
mp_uint_t mp_hal_ticks_cpu(void) {
return cxd56_get_cpu_baseclk();
}
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.
}
}
void mp_hal_delay_us(uint32_t us) {
if (us) {
unsigned long long ticks = mp_hal_ticks_cpu() / 1000000L * us;
if (ticks < DELAY_CORRECTION) return; // delay time already used in calculation
ticks -= DELAY_CORRECTION;
ticks /= 6;
// following loop takes 6 cycles
do {
__asm__ __volatile__("nop");
} while(--ticks);
}
}

View File

@ -30,5 +30,8 @@
#include <sys/types.h>
#include "lib/utils/interrupt_char.h"
#include "supervisor/shared/tick.h"
#define mp_hal_ticks_ms() ((mp_uint_t) supervisor_ticks_ms32())
#endif // MICROPY_INCLUDED_CXD56_MPHALPORT_H

View File

@ -59,7 +59,7 @@ uint32_t supervisor_flash_get_block_count(void) {
return CXD56_SPIFLASHSIZE >> PAGE_SHIFT;
}
void supervisor_flash_flush(void) {
void port_internal_flash_flush(void) {
if (flash_sector == NO_SECTOR) {
return;
}

View File

@ -25,13 +25,16 @@
*/
#include <stdint.h>
#include <sys/boardctl.h>
#include <sys/time.h>
#include "sched/sched.h"
#include "boards/board.h"
#include "supervisor/port.h"
#include "supervisor/shared/tick.h"
#include "common-hal/microcontroller/Pin.h"
#include "common-hal/analogio/AnalogIn.h"
@ -103,3 +106,41 @@ void port_set_saved_word(uint32_t value) {
uint32_t port_get_saved_word(void) {
return _ebss;
}
volatile bool _tick_enabled;
void board_timerhook(void)
{
// Do things common to all ports when the tick occurs
if (_tick_enabled) {
supervisor_tick();
}
}
uint64_t port_get_raw_ticks(uint8_t* subticks) {
struct timeval tv;
gettimeofday(&tv, NULL);
long computed_subticks = tv.tv_usec * 1024 * 32 / 1000000;
if (subticks != NULL) {
*subticks = computed_subticks % 32;
}
return tv.tv_sec * 1024 + computed_subticks / 32;
}
// Enable 1/1024 second tick.
void port_enable_tick(void) {
_tick_enabled = true;
}
// Disable 1/1024 second tick.
void port_disable_tick(void) {
_tick_enabled = false;
}
void port_interrupt_after_ticks(uint32_t ticks) {
}
void port_sleep_until_interrupt(void) {
// TODO: Implement sleep.
}

View File

@ -1,36 +0,0 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright 2019 Sony Semiconductor Solutions Corporation
*
* 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 "tick.h"
#include "supervisor/shared/autoreload.h"
#include "supervisor/shared/tick.h"
void board_timerhook(void)
{
// Do things common to all ports when the tick occurs
supervisor_tick();
}

View File

@ -1,32 +0,0 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright 2019 Sony Semiconductor Solutions Corporation
*
* 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_CXD56_TICK_H
#define MICROPY_INCLUDED_CXD56_TICK_H
#include "py/mpconfig.h"
#endif // MICROPY_INCLUDED_CXD56_TICK_H

View File

@ -26,6 +26,7 @@
#include "py/mphal.h"
#include "supervisor/port.h"
#include "supervisor/shared/tick.h"
uint64_t common_hal_time_monotonic(void) {
return supervisor_ticks_ms64();