rp2: Integrate RP2350 and use aon_timer instead of rtc API.
This commit separates various build settings and include files that are specific to RP2040 and RP2350, and uses the aon_timer interface instead of rtc, to work across both MCU variants. Signed-off-by: Damien George <damien@micropython.org> Signed-off-by: Phil Howard <phil@gadgetoid.com>
This commit is contained in:
parent
27aeade832
commit
d2c85c74da
@ -191,19 +191,26 @@ set(PICO_SDK_COMPONENTS
|
|||||||
hardware_pll
|
hardware_pll
|
||||||
hardware_pwm
|
hardware_pwm
|
||||||
hardware_regs
|
hardware_regs
|
||||||
hardware_rtc
|
hardware_resets
|
||||||
hardware_spi
|
hardware_spi
|
||||||
hardware_structs
|
hardware_structs
|
||||||
hardware_sync
|
hardware_sync
|
||||||
|
hardware_sync_spin_lock
|
||||||
hardware_timer
|
hardware_timer
|
||||||
hardware_uart
|
hardware_uart
|
||||||
hardware_watchdog
|
hardware_watchdog
|
||||||
hardware_xosc
|
hardware_xosc
|
||||||
|
pico_aon_timer
|
||||||
pico_base_headers
|
pico_base_headers
|
||||||
pico_binary_info
|
pico_binary_info
|
||||||
pico_bootrom
|
pico_bootrom
|
||||||
pico_multicore
|
pico_multicore
|
||||||
pico_platform
|
pico_platform
|
||||||
|
pico_platform_compiler
|
||||||
|
pico_platform_panic
|
||||||
|
pico_platform_sections
|
||||||
|
pico_runtime
|
||||||
|
pico_runtime_init
|
||||||
pico_stdio
|
pico_stdio
|
||||||
pico_stdlib
|
pico_stdlib
|
||||||
pico_sync
|
pico_sync
|
||||||
@ -224,14 +231,24 @@ pico_add_library(pico_float_micropython)
|
|||||||
|
|
||||||
# pico_float_micropython: add pico-sdk float and our libm source files.
|
# pico_float_micropython: add pico-sdk float and our libm source files.
|
||||||
target_sources(pico_float_micropython INTERFACE
|
target_sources(pico_float_micropython INTERFACE
|
||||||
${PICO_SDK_PATH}/src/rp2_common/pico_float/float_aeabi.S
|
|
||||||
${PICO_SDK_PATH}/src/rp2_common/pico_float/float_init_rom.c
|
|
||||||
${PICO_SDK_PATH}/src/rp2_common/pico_float/float_v1_rom_shim.S
|
|
||||||
${MICROPY_SOURCE_LIB_LIBM}
|
${MICROPY_SOURCE_LIB_LIBM}
|
||||||
${MICROPY_SOURCE_LIB_LIBM_SQRT_SW}
|
${MICROPY_SOURCE_LIB_LIBM_SQRT_SW}
|
||||||
${MICROPY_PORT_DIR}/libm_extra.c
|
${MICROPY_PORT_DIR}/libm_extra.c
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(PICO_RP2040)
|
||||||
|
target_sources(pico_float_micropython INTERFACE
|
||||||
|
${PICO_SDK_PATH}/src/rp2_common/pico_float/float_aeabi_rp2040.S
|
||||||
|
${PICO_SDK_PATH}/src/rp2_common/pico_float/float_init_rom_rp2040.c
|
||||||
|
${PICO_SDK_PATH}/src/rp2_common/pico_float/float_v1_rom_shim_rp2040.S
|
||||||
|
)
|
||||||
|
elseif(PICO_RP2350)
|
||||||
|
target_sources(pico_float_micropython INTERFACE
|
||||||
|
${PICO_SDK_PATH}/src/rp2_common/pico_float/float_aeabi_dcp.S
|
||||||
|
${PICO_SDK_PATH}/src/rp2_common/pico_float/float_conv_m33.S
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
# pico_float_micropython: wrap low-level floating-point ops, to call the pico-sdk versions.
|
# pico_float_micropython: wrap low-level floating-point ops, to call the pico-sdk versions.
|
||||||
pico_wrap_function(pico_float_micropython __aeabi_fdiv)
|
pico_wrap_function(pico_float_micropython __aeabi_fdiv)
|
||||||
pico_wrap_function(pico_float_micropython __aeabi_fmul)
|
pico_wrap_function(pico_float_micropython __aeabi_fmul)
|
||||||
@ -253,7 +270,9 @@ pico_wrap_function(pico_float_micropython __aeabi_ul2f)
|
|||||||
pico_wrap_function(pico_float_micropython __aeabi_f2iz)
|
pico_wrap_function(pico_float_micropython __aeabi_f2iz)
|
||||||
pico_wrap_function(pico_float_micropython __aeabi_f2lz)
|
pico_wrap_function(pico_float_micropython __aeabi_f2lz)
|
||||||
pico_wrap_function(pico_float_micropython __aeabi_f2uiz)
|
pico_wrap_function(pico_float_micropython __aeabi_f2uiz)
|
||||||
pico_wrap_function(pico_float_micropython __aeabi_f2ulz)
|
if(PICO_RP2040)
|
||||||
|
pico_wrap_function(pico_float_micropython __aeabi_f2ulz)
|
||||||
|
endif()
|
||||||
pico_wrap_function(pico_float_micropython __aeabi_f2d)
|
pico_wrap_function(pico_float_micropython __aeabi_f2d)
|
||||||
|
|
||||||
if (MICROPY_PY_LWIP)
|
if (MICROPY_PY_LWIP)
|
||||||
@ -507,9 +526,18 @@ target_compile_definitions(${MICROPY_TARGET} PRIVATE
|
|||||||
PICO_NO_PROGRAM_VERSION_STRING=1 # do it ourselves in main.c
|
PICO_NO_PROGRAM_VERSION_STRING=1 # do it ourselves in main.c
|
||||||
MICROPY_BUILD_TYPE="${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION} ${CMAKE_BUILD_TYPE}"
|
MICROPY_BUILD_TYPE="${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION} ${CMAKE_BUILD_TYPE}"
|
||||||
PICO_NO_BI_STDIO_UART=1 # we call it UART REPL
|
PICO_NO_BI_STDIO_UART=1 # we call it UART REPL
|
||||||
PICO_RP2040_USB_DEVICE_ENUMERATION_FIX=1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(PICO_RP2040)
|
||||||
|
target_compile_definitions(${MICROPY_TARGET} PRIVATE
|
||||||
|
PICO_RP2040_USB_DEVICE_ENUMERATION_FIX=1
|
||||||
|
)
|
||||||
|
elseif(PICO_RP2350)
|
||||||
|
target_compile_definitions(${MICROPY_TARGET} PRIVATE
|
||||||
|
PICO_EMBED_XIP_SETUP=1 # to put flash into continuous read mode
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
target_link_libraries(${MICROPY_TARGET}
|
target_link_libraries(${MICROPY_TARGET}
|
||||||
${PICO_SDK_COMPONENTS}
|
${PICO_SDK_COMPONENTS}
|
||||||
)
|
)
|
||||||
@ -525,7 +553,11 @@ endif()
|
|||||||
# a linker script modification) until we explicitly add macro calls around the function
|
# a linker script modification) until we explicitly add macro calls around the function
|
||||||
# defs to move them into RAM.
|
# defs to move them into RAM.
|
||||||
if (PICO_ON_DEVICE AND NOT PICO_NO_FLASH AND NOT PICO_COPY_TO_RAM)
|
if (PICO_ON_DEVICE AND NOT PICO_NO_FLASH AND NOT PICO_COPY_TO_RAM)
|
||||||
pico_set_linker_script(${MICROPY_TARGET} ${CMAKE_CURRENT_LIST_DIR}/memmap_mp_${PICO_PLATFORM}.ld)
|
if(PICO_RP2040)
|
||||||
|
pico_set_linker_script(${MICROPY_TARGET} ${CMAKE_CURRENT_LIST_DIR}/memmap_mp_rp2040.ld)
|
||||||
|
elseif(PICO_RP2350)
|
||||||
|
pico_set_linker_script(${MICROPY_TARGET} ${CMAKE_CURRENT_LIST_DIR}/memmap_mp_rp2350.ld)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
pico_add_extra_outputs(${MICROPY_TARGET})
|
pico_add_extra_outputs(${MICROPY_TARGET})
|
||||||
@ -544,6 +576,9 @@ foreach(comp ${PICO_SDK_COMPONENTS})
|
|||||||
micropy_gather_target_properties(${comp}_headers)
|
micropy_gather_target_properties(${comp}_headers)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
set(MICROPY_CPP_FLAGS_EXTRA ${PICO_COMMON_LANG_FLAGS})
|
||||||
|
separate_arguments(MICROPY_CPP_FLAGS_EXTRA)
|
||||||
|
|
||||||
# Include the main MicroPython cmake rules.
|
# Include the main MicroPython cmake rules.
|
||||||
include(${MICROPY_DIR}/py/mkrules.cmake)
|
include(${MICROPY_DIR}/py/mkrules.cmake)
|
||||||
|
|
||||||
|
|||||||
@ -1,2 +1,3 @@
|
|||||||
# cmake file for Raspberry Pi Pico
|
# cmake file for Raspberry Pi Pico
|
||||||
set(PICO_BOARD "pico")
|
set(PICO_BOARD "pico")
|
||||||
|
set(PICO_PLATFORM "rp2040")
|
||||||
|
|||||||
@ -25,10 +25,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "lib/oofatfs/ff.h"
|
#include "lib/oofatfs/ff.h"
|
||||||
#include "hardware/rtc.h"
|
#include "pico/aon_timer.h"
|
||||||
|
#include "shared/timeutils/timeutils.h"
|
||||||
|
|
||||||
MP_WEAK DWORD get_fattime(void) {
|
MP_WEAK DWORD get_fattime(void) {
|
||||||
datetime_t t;
|
struct timespec ts;
|
||||||
rtc_get_datetime(&t);
|
timeutils_struct_time_t tm;
|
||||||
return ((t.year - 1980) << 25) | ((t.month) << 21) | ((t.day) << 16) | ((t.hour) << 11) | ((t.min) << 5) | (t.sec / 2);
|
aon_timer_get_time(&ts);
|
||||||
|
timeutils_seconds_since_epoch_to_struct_time(ts.tv_sec, &tm);
|
||||||
|
return ((tm.tm_year - 1980) << 25) | ((tm.tm_mon) << 21) | ((tm.tm_mday) << 16) | ((tm.tm_hour) << 11) | ((tm.tm_min) << 5) | (tm.tm_sec / 2);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,6 +30,8 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
#include "pico/aon_timer.h"
|
||||||
|
|
||||||
#include "py/nlr.h"
|
#include "py/nlr.h"
|
||||||
#include "py/obj.h"
|
#include "py/obj.h"
|
||||||
#include "py/runtime.h"
|
#include "py/runtime.h"
|
||||||
@ -37,8 +39,6 @@
|
|||||||
#include "py/mperrno.h"
|
#include "py/mperrno.h"
|
||||||
#include "extmod/modmachine.h"
|
#include "extmod/modmachine.h"
|
||||||
#include "shared/timeutils/timeutils.h"
|
#include "shared/timeutils/timeutils.h"
|
||||||
#include "hardware/rtc.h"
|
|
||||||
#include "pico/util/datetime.h"
|
|
||||||
|
|
||||||
typedef struct _machine_rtc_obj_t {
|
typedef struct _machine_rtc_obj_t {
|
||||||
mp_obj_base_t base;
|
mp_obj_base_t base;
|
||||||
@ -50,14 +50,12 @@ static const machine_rtc_obj_t machine_rtc_obj = {{&machine_rtc_type}};
|
|||||||
static mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
static mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||||
// check arguments
|
// check arguments
|
||||||
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
||||||
bool r = rtc_running();
|
bool r = aon_timer_is_running();
|
||||||
|
|
||||||
if (!r) {
|
if (!r) {
|
||||||
// This shouldn't happen as rtc_init() is already called in main so
|
// This shouldn't happen. it's here just in case
|
||||||
// it's here just in case
|
struct timespec ts = { 0, 0 };
|
||||||
rtc_init();
|
aon_timer_start(&ts);
|
||||||
datetime_t t = { .month = 1, .day = 1 };
|
|
||||||
rtc_set_datetime(&t);
|
|
||||||
mp_hal_time_ns_set_from_rtc();
|
mp_hal_time_ns_set_from_rtc();
|
||||||
}
|
}
|
||||||
// return constant object
|
// return constant object
|
||||||
@ -66,47 +64,36 @@ static mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, s
|
|||||||
|
|
||||||
static mp_obj_t machine_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) {
|
static mp_obj_t machine_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) {
|
||||||
if (n_args == 1) {
|
if (n_args == 1) {
|
||||||
bool ret;
|
struct timespec ts;
|
||||||
datetime_t t;
|
timeutils_struct_time_t tm;
|
||||||
|
aon_timer_get_time(&ts);
|
||||||
ret = rtc_get_datetime(&t);
|
timeutils_seconds_since_epoch_to_struct_time(ts.tv_sec, &tm);
|
||||||
if (!ret) {
|
|
||||||
mp_raise_OSError(MP_EIO);
|
|
||||||
}
|
|
||||||
|
|
||||||
mp_obj_t tuple[8] = {
|
mp_obj_t tuple[8] = {
|
||||||
mp_obj_new_int(t.year),
|
mp_obj_new_int(tm.tm_year),
|
||||||
mp_obj_new_int(t.month),
|
mp_obj_new_int(tm.tm_mon),
|
||||||
mp_obj_new_int(t.day),
|
mp_obj_new_int(tm.tm_mday),
|
||||||
mp_obj_new_int(t.dotw),
|
mp_obj_new_int(tm.tm_wday),
|
||||||
mp_obj_new_int(t.hour),
|
mp_obj_new_int(tm.tm_hour),
|
||||||
mp_obj_new_int(t.min),
|
mp_obj_new_int(tm.tm_min),
|
||||||
mp_obj_new_int(t.sec),
|
mp_obj_new_int(tm.tm_sec),
|
||||||
mp_obj_new_int(0)
|
mp_obj_new_int(0),
|
||||||
};
|
};
|
||||||
|
|
||||||
return mp_obj_new_tuple(8, tuple);
|
return mp_obj_new_tuple(8, tuple);
|
||||||
} else {
|
} else {
|
||||||
mp_obj_t *items;
|
mp_obj_t *items;
|
||||||
|
|
||||||
mp_obj_get_array_fixed_n(args[1], 8, &items);
|
mp_obj_get_array_fixed_n(args[1], 8, &items);
|
||||||
|
timeutils_struct_time_t tm = {
|
||||||
datetime_t t = {
|
.tm_year = mp_obj_get_int(items[0]),
|
||||||
.year = mp_obj_get_int(items[0]),
|
.tm_mon = mp_obj_get_int(items[1]),
|
||||||
.month = mp_obj_get_int(items[1]),
|
.tm_mday = mp_obj_get_int(items[2]),
|
||||||
.day = mp_obj_get_int(items[2]),
|
.tm_hour = mp_obj_get_int(items[4]),
|
||||||
.hour = mp_obj_get_int(items[4]),
|
.tm_min = mp_obj_get_int(items[5]),
|
||||||
.min = mp_obj_get_int(items[5]),
|
.tm_sec = mp_obj_get_int(items[6]),
|
||||||
.sec = mp_obj_get_int(items[6]),
|
|
||||||
};
|
};
|
||||||
// Deliberately ignore the weekday argument and compute the proper value
|
struct timespec ts = { 0, 0 };
|
||||||
t.dotw = timeutils_calc_weekday(t.year, t.month, t.day);
|
ts.tv_sec = timeutils_seconds_since_epoch(tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
|
||||||
|
aon_timer_set_time(&ts);
|
||||||
if (!rtc_set_datetime(&t)) {
|
|
||||||
mp_raise_OSError(MP_EINVAL);
|
|
||||||
}
|
|
||||||
mp_hal_time_ns_set_from_rtc();
|
mp_hal_time_ns_set_from_rtc();
|
||||||
|
|
||||||
}
|
}
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,11 +47,9 @@
|
|||||||
#include "genhdr/mpversion.h"
|
#include "genhdr/mpversion.h"
|
||||||
#include "mp_usbd.h"
|
#include "mp_usbd.h"
|
||||||
|
|
||||||
#include "RP2040.h" // cmsis, for PendSV_IRQn and SCB/SCB_SCR_SEVONPEND_Msk
|
|
||||||
#include "pico/stdlib.h"
|
#include "pico/stdlib.h"
|
||||||
#include "pico/binary_info.h"
|
#include "pico/binary_info.h"
|
||||||
#include "pico/unique_id.h"
|
#include "pico/unique_id.h"
|
||||||
#include "hardware/rtc.h"
|
|
||||||
#include "hardware/structs/rosc.h"
|
#include "hardware/structs/rosc.h"
|
||||||
#if MICROPY_PY_LWIP
|
#if MICROPY_PY_LWIP
|
||||||
#include "lwip/init.h"
|
#include "lwip/init.h"
|
||||||
@ -60,6 +58,15 @@
|
|||||||
#if MICROPY_PY_NETWORK_CYW43
|
#if MICROPY_PY_NETWORK_CYW43
|
||||||
#include "lib/cyw43-driver/src/cyw43.h"
|
#include "lib/cyw43-driver/src/cyw43.h"
|
||||||
#endif
|
#endif
|
||||||
|
#if PICO_RP2040
|
||||||
|
#include "RP2040.h" // cmsis, for PendSV_IRQn and SCB/SCB_SCR_SEVONPEND_Msk
|
||||||
|
#elif PICO_RP2350
|
||||||
|
#include "RP2350.h" // cmsis, for PendSV_IRQn and SCB/SCB_SCR_SEVONPEND_Msk
|
||||||
|
#else
|
||||||
|
#error Unknown processor
|
||||||
|
#endif
|
||||||
|
#include "pico/aon_timer.h"
|
||||||
|
#include "shared/timeutils/timeutils.h"
|
||||||
|
|
||||||
extern uint8_t __StackTop, __StackBottom;
|
extern uint8_t __StackTop, __StackBottom;
|
||||||
extern uint8_t __GcHeapStart, __GcHeapEnd;
|
extern uint8_t __GcHeapStart, __GcHeapEnd;
|
||||||
@ -106,17 +113,9 @@ int main(int argc, char **argv) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Start and initialise the RTC
|
// Start and initialise the RTC
|
||||||
datetime_t t = {
|
struct timespec ts = { 0, 0 };
|
||||||
.year = 2021,
|
ts.tv_sec = timeutils_seconds_since_epoch(2021, 1, 1, 0, 0, 0);
|
||||||
.month = 1,
|
aon_timer_start(&ts);
|
||||||
.day = 1,
|
|
||||||
.dotw = 4, // 0 is Monday, so 4 is Friday
|
|
||||||
.hour = 0,
|
|
||||||
.min = 0,
|
|
||||||
.sec = 0,
|
|
||||||
};
|
|
||||||
rtc_init();
|
|
||||||
rtc_set_datetime(&t);
|
|
||||||
mp_hal_time_ns_set_from_rtc();
|
mp_hal_time_ns_set_from_rtc();
|
||||||
|
|
||||||
// Initialise stack extents and GC heap.
|
// Initialise stack extents and GC heap.
|
||||||
|
|||||||
@ -29,9 +29,9 @@
|
|||||||
|
|
||||||
#include "mbedtls_config_port.h"
|
#include "mbedtls_config_port.h"
|
||||||
|
|
||||||
#include "hardware/rtc.h"
|
|
||||||
#include "shared/timeutils/timeutils.h"
|
#include "shared/timeutils/timeutils.h"
|
||||||
#include "mbedtls/platform_time.h"
|
#include "mbedtls/platform_time.h"
|
||||||
|
#include "pico/aon_timer.h"
|
||||||
|
|
||||||
extern uint8_t rosc_random_u8(size_t cycles);
|
extern uint8_t rosc_random_u8(size_t cycles);
|
||||||
|
|
||||||
@ -44,9 +44,9 @@ int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len, size_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
time_t rp2_rtctime_seconds(time_t *timer) {
|
time_t rp2_rtctime_seconds(time_t *timer) {
|
||||||
datetime_t t;
|
struct timespec ts;
|
||||||
rtc_get_datetime(&t);
|
aon_timer_get_time(&ts);
|
||||||
return timeutils_seconds_since_epoch(t.year, t.month, t.day, t.hour, t.min, t.sec);
|
return ts.tv_sec;
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_ms_time_t mbedtls_ms_time(void) {
|
mbedtls_ms_time_t mbedtls_ms_time(void) {
|
||||||
|
|||||||
@ -41,6 +41,7 @@
|
|||||||
#include "pico/bootrom.h"
|
#include "pico/bootrom.h"
|
||||||
#include "pico/stdlib.h"
|
#include "pico/stdlib.h"
|
||||||
#include "pico/unique_id.h"
|
#include "pico/unique_id.h"
|
||||||
|
#include "pico/runtime_init.h"
|
||||||
#if MICROPY_PY_NETWORK_CYW43
|
#if MICROPY_PY_NETWORK_CYW43
|
||||||
#include "lib/cyw43-driver/src/cyw43.h"
|
#include "lib/cyw43-driver/src/cyw43.h"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -26,28 +26,30 @@
|
|||||||
|
|
||||||
#include "py/obj.h"
|
#include "py/obj.h"
|
||||||
#include "shared/timeutils/timeutils.h"
|
#include "shared/timeutils/timeutils.h"
|
||||||
#include "hardware/rtc.h"
|
#include "pico/aon_timer.h"
|
||||||
|
|
||||||
// Return the localtime as an 8-tuple.
|
// Return the localtime as an 8-tuple.
|
||||||
static mp_obj_t mp_time_localtime_get(void) {
|
static mp_obj_t mp_time_localtime_get(void) {
|
||||||
datetime_t t;
|
struct timespec ts;
|
||||||
rtc_get_datetime(&t);
|
aon_timer_get_time(&ts);
|
||||||
|
timeutils_struct_time_t tm;
|
||||||
|
timeutils_seconds_since_epoch_to_struct_time(ts.tv_sec, &tm);
|
||||||
mp_obj_t tuple[8] = {
|
mp_obj_t tuple[8] = {
|
||||||
mp_obj_new_int(t.year),
|
mp_obj_new_int(tm.tm_year),
|
||||||
mp_obj_new_int(t.month),
|
mp_obj_new_int(tm.tm_mon),
|
||||||
mp_obj_new_int(t.day),
|
mp_obj_new_int(tm.tm_mday),
|
||||||
mp_obj_new_int(t.hour),
|
mp_obj_new_int(tm.tm_hour),
|
||||||
mp_obj_new_int(t.min),
|
mp_obj_new_int(tm.tm_min),
|
||||||
mp_obj_new_int(t.sec),
|
mp_obj_new_int(tm.tm_sec),
|
||||||
mp_obj_new_int(t.dotw),
|
mp_obj_new_int(tm.tm_wday),
|
||||||
mp_obj_new_int(timeutils_year_day(t.year, t.month, t.day)),
|
mp_obj_new_int(tm.tm_yday),
|
||||||
};
|
};
|
||||||
return mp_obj_new_tuple(8, tuple);
|
return mp_obj_new_tuple(8, tuple);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the number of seconds since the Epoch.
|
// Return the number of seconds since the Epoch.
|
||||||
static mp_obj_t mp_time_time_get(void) {
|
static mp_obj_t mp_time_time_get(void) {
|
||||||
datetime_t t;
|
struct timespec ts;
|
||||||
rtc_get_datetime(&t);
|
aon_timer_get_time(&ts);
|
||||||
return mp_obj_new_int_from_ull(timeutils_seconds_since_epoch(t.year, t.month, t.day, t.hour, t.min, t.sec));
|
return mp_obj_new_int_from_ull(ts.tv_sec);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,16 +37,18 @@
|
|||||||
#include "tusb.h"
|
#include "tusb.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
#include "hardware/irq.h"
|
#include "hardware/irq.h"
|
||||||
#include "hardware/rtc.h"
|
|
||||||
#include "pico/unique_id.h"
|
#include "pico/unique_id.h"
|
||||||
|
#include "pico/aon_timer.h"
|
||||||
|
|
||||||
#if MICROPY_PY_NETWORK_CYW43
|
#if MICROPY_PY_NETWORK_CYW43
|
||||||
#include "lib/cyw43-driver/src/cyw43.h"
|
#include "lib/cyw43-driver/src/cyw43.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if PICO_RP2040
|
||||||
// This needs to be added to the result of time_us_64() to get the number of
|
// This needs to be added to the result of time_us_64() to get the number of
|
||||||
// microseconds since the Epoch.
|
// microseconds since the Epoch.
|
||||||
static uint64_t time_us_64_offset_from_epoch;
|
static uint64_t time_us_64_offset_from_epoch;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if MICROPY_HW_ENABLE_UART_REPL || MICROPY_HW_USB_CDC
|
#if MICROPY_HW_ENABLE_UART_REPL || MICROPY_HW_USB_CDC
|
||||||
|
|
||||||
@ -145,27 +147,35 @@ void mp_hal_delay_ms(mp_uint_t ms) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void mp_hal_time_ns_set_from_rtc(void) {
|
void mp_hal_time_ns_set_from_rtc(void) {
|
||||||
|
#if PICO_RP2040
|
||||||
// Outstanding RTC register writes need at least two RTC clock cycles to
|
// Outstanding RTC register writes need at least two RTC clock cycles to
|
||||||
// update. (See RP2040 datasheet section 4.8.4 "Reference clock").
|
// update. (See RP2040 datasheet section 4.8.4 "Reference clock").
|
||||||
mp_hal_delay_us(44);
|
mp_hal_delay_us(44);
|
||||||
|
|
||||||
// Sample RTC and time_us_64() as close together as possible, so the offset
|
// Sample RTC and time_us_64() as close together as possible, so the offset
|
||||||
// calculated for the latter can be as accurate as possible.
|
// calculated for the latter can be as accurate as possible.
|
||||||
datetime_t t;
|
struct timespec ts;
|
||||||
rtc_get_datetime(&t);
|
aon_timer_get_time(&ts);
|
||||||
uint64_t us = time_us_64();
|
uint64_t us = time_us_64();
|
||||||
|
|
||||||
// Calculate the difference between the RTC Epoch seconds and time_us_64().
|
// Calculate the difference between the RTC Epoch and time_us_64().
|
||||||
uint64_t s = timeutils_seconds_since_epoch(t.year, t.month, t.day, t.hour, t.min, t.sec);
|
time_us_64_offset_from_epoch = ((uint64_t)ts.tv_sec * 1000000ULL) + ((uint64_t)ts.tv_nsec / 1000ULL) - us;
|
||||||
time_us_64_offset_from_epoch = (uint64_t)s * 1000000ULL - us;
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t mp_hal_time_ns(void) {
|
uint64_t mp_hal_time_ns(void) {
|
||||||
// The RTC only has seconds resolution, so instead use time_us_64() to get a more
|
#if PICO_RP2040
|
||||||
|
// The RTC probably has limited resolution, so instead use time_us_64() to get a more
|
||||||
// precise measure of Epoch time. Both these "clocks" are clocked from the same
|
// precise measure of Epoch time. Both these "clocks" are clocked from the same
|
||||||
// source so they remain synchronised, and only differ by a fixed offset (calculated
|
// source so they remain synchronised, and only differ by a fixed offset (calculated
|
||||||
// in mp_hal_time_ns_set_from_rtc).
|
// in mp_hal_time_ns_set_from_rtc).
|
||||||
return (time_us_64_offset_from_epoch + time_us_64()) * 1000ULL;
|
return (time_us_64_offset_from_epoch + time_us_64()) * 1000ULL;
|
||||||
|
#else
|
||||||
|
// aon timer has ms resolution
|
||||||
|
struct timespec ts;
|
||||||
|
aon_timer_get_time(&ts);
|
||||||
|
return ((uint64_t)ts.tv_sec * 1000000000ULL) + (uint64_t)ts.tv_nsec;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate a random locally administered MAC address (LAA)
|
// Generate a random locally administered MAC address (LAA)
|
||||||
|
|||||||
@ -43,7 +43,14 @@ static soft_timer_entry_t mp_network_soft_timer;
|
|||||||
#include "lib/cyw43-driver/src/cyw43.h"
|
#include "lib/cyw43-driver/src/cyw43.h"
|
||||||
#include "lib/cyw43-driver/src/cyw43_stats.h"
|
#include "lib/cyw43-driver/src/cyw43_stats.h"
|
||||||
#include "hardware/irq.h"
|
#include "hardware/irq.h"
|
||||||
|
|
||||||
|
#if PICO_RP2040
|
||||||
#include "RP2040.h" // cmsis, for NVIC_SetPriority and PendSV_IRQn
|
#include "RP2040.h" // cmsis, for NVIC_SetPriority and PendSV_IRQn
|
||||||
|
#elif PICO_RP2350
|
||||||
|
#include "RP2350.h" // cmsis, for NVIC_SetPriority and PendSV_IRQn
|
||||||
|
#else
|
||||||
|
#error Unknown processor
|
||||||
|
#endif
|
||||||
|
|
||||||
#define CYW43_IRQ_LEVEL GPIO_IRQ_LEVEL_HIGH
|
#define CYW43_IRQ_LEVEL GPIO_IRQ_LEVEL_HIGH
|
||||||
#define CYW43_SHARED_IRQ_HANDLER_PRIORITY PICO_SHARED_IRQ_HANDLER_HIGHEST_ORDER_PRIORITY
|
#define CYW43_SHARED_IRQ_HANDLER_PRIORITY PICO_SHARED_IRQ_HANDLER_HIGHEST_ORDER_PRIORITY
|
||||||
|
|||||||
@ -28,7 +28,14 @@
|
|||||||
#include "py/mpconfig.h"
|
#include "py/mpconfig.h"
|
||||||
#include "mutex_extra.h"
|
#include "mutex_extra.h"
|
||||||
#include "pendsv.h"
|
#include "pendsv.h"
|
||||||
|
|
||||||
|
#if PICO_RP2040
|
||||||
#include "RP2040.h"
|
#include "RP2040.h"
|
||||||
|
#elif PICO_RP2350
|
||||||
|
#include "RP2350.h"
|
||||||
|
#else
|
||||||
|
#error Unknown chip
|
||||||
|
#endif
|
||||||
|
|
||||||
#if MICROPY_PY_NETWORK_CYW43
|
#if MICROPY_PY_NETWORK_CYW43
|
||||||
#include "lib/cyw43-driver/src/cyw43_stats.h"
|
#include "lib/cyw43-driver/src/cyw43_stats.h"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user