diff options
Diffstat (limited to 'ports')
| -rw-r--r-- | ports/atmel-samd/mphalport.h | 5 | ||||
| -rw-r--r-- | ports/cxd56/Makefile | 5 | ||||
| -rw-r--r-- | ports/cxd56/common-hal/microcontroller/Processor.c | 4 | ||||
| -rw-r--r-- | ports/cxd56/common-hal/microcontroller/__init__.c | 16 | ||||
| -rw-r--r-- | ports/cxd56/common-hal/pulseio/PulseIn.c | 5 | ||||
| -rw-r--r-- | ports/cxd56/common-hal/time/__init__.c | 45 | ||||
| -rw-r--r-- | ports/cxd56/mphalport.c | 63 | ||||
| -rw-r--r-- | ports/cxd56/mphalport.h | 3 | ||||
| -rw-r--r-- | ports/cxd56/supervisor/internal_flash.c | 2 | ||||
| -rw-r--r-- | ports/cxd56/supervisor/port.c | 41 | ||||
| -rw-r--r-- | ports/cxd56/tick.c | 36 | ||||
| -rw-r--r-- | ports/cxd56/tick.h | 32 |
12 files changed, 71 insertions, 186 deletions
diff --git a/ports/atmel-samd/mphalport.h b/ports/atmel-samd/mphalport.h index 8a762e258..f11971749 100644 --- a/ports/atmel-samd/mphalport.h +++ b/ports/atmel-samd/mphalport.h @@ -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; diff --git a/ports/cxd56/Makefile b/ports/cxd56/Makefile index e2fce976d..507d76331 100644 --- a/ports/cxd56/Makefile +++ b/ports/cxd56/Makefile @@ -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) diff --git a/ports/cxd56/common-hal/microcontroller/Processor.c b/ports/cxd56/common-hal/microcontroller/Processor.c index 3e6fc3b8a..1eddbb01d 100644 --- a/ports/cxd56/common-hal/microcontroller/Processor.c +++ b/ports/cxd56/common-hal/microcontroller/Processor.c @@ -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) { diff --git a/ports/cxd56/common-hal/microcontroller/__init__.c b/ports/cxd56/common-hal/microcontroller/__init__.c index 2be74b006..7aa3b839d 100644 --- a/ports/cxd56/common-hal/microcontroller/__init__.c +++ b/ports/cxd56/common-hal/microcontroller/__init__.c @@ -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) { diff --git a/ports/cxd56/common-hal/pulseio/PulseIn.c b/ports/cxd56/common-hal/pulseio/PulseIn.c index 65ca1d97e..f474c0a10 100644 --- a/ports/cxd56/common-hal/pulseio/PulseIn.c +++ b/ports/cxd56/common-hal/pulseio/PulseIn.c @@ -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]; diff --git a/ports/cxd56/common-hal/time/__init__.c b/ports/cxd56/common-hal/time/__init__.c deleted file mode 100644 index 31c63cbb2..000000000 --- a/ports/cxd56/common-hal/time/__init__.c +++ /dev/null @@ -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); -} diff --git a/ports/cxd56/mphalport.c b/ports/cxd56/mphalport.c index 1305706ca..5a76b83bd 100644 --- a/ports/cxd56/mphalport.c +++ b/ports/cxd56/mphalport.c @@ -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); - } -} diff --git a/ports/cxd56/mphalport.h b/ports/cxd56/mphalport.h index a2be10b8d..50e805cf5 100644 --- a/ports/cxd56/mphalport.h +++ b/ports/cxd56/mphalport.h @@ -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 diff --git a/ports/cxd56/supervisor/internal_flash.c b/ports/cxd56/supervisor/internal_flash.c index 0c9a61e06..2726fa4a2 100644 --- a/ports/cxd56/supervisor/internal_flash.c +++ b/ports/cxd56/supervisor/internal_flash.c @@ -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; } diff --git a/ports/cxd56/supervisor/port.c b/ports/cxd56/supervisor/port.c index 5d2957f35..73d6fb930 100644 --- a/ports/cxd56/supervisor/port.c +++ b/ports/cxd56/supervisor/port.c @@ -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. +} + diff --git a/ports/cxd56/tick.c b/ports/cxd56/tick.c deleted file mode 100644 index 671b82b74..000000000 --- a/ports/cxd56/tick.c +++ /dev/null @@ -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(); -} diff --git a/ports/cxd56/tick.h b/ports/cxd56/tick.h deleted file mode 100644 index d641d9cd4..000000000 --- a/ports/cxd56/tick.h +++ /dev/null @@ -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 |
