micropython/ports
Christian Walther e1a6da0f9d nrf: Implement time.time() and machine.RTC.
Optionally adds time() and time_ns() to the time module, as well as a
machine.RTC class that only implements the datetime() method (following the
example of the rp2 port), whose sole purpose is to provide the ability to
set the time. Also provides the basis for enabling gmtime(), localtime(),
mktime() in the time module.

The nRF52 does not have a dedicated real-time clock peripheral, but
timekeeping can be done by the same real-time counter that already powers
the time.ticks_* and related functions. For reasonable accuracy, a suitable
LFCLK source is required: The internal RC oscillator (BLUETOOTH_LFCLK_RC)
by itself is insufficient, but any of the following work fine:
- external 32kHz crystal (default)
- synthesis from HFCLK (BLUETOOTH_LFCLK_SYNTH) when HFXO (external 32MHz
  crystal) is enabled
- BLUETOOTH_LFCLK_RC + periodical calibration from HFXO (automatically done
  by the SoftDevice while enabled using ble.enable())

Boards can enable this by defining both configuration options
MICROPY_PY_TIME_TICKS and MICROPY_PY_TIME_TIME_TIME_NS. Additionally, they
may want to enable MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME.

This includes a generic implementation of mp_time_localtime_get() and
mp_time_time_get() in terms of mp_hal_time_ns(), which could also be used
by other ports. In particular by the embed port, for which I originally
wrote it, noting the following:

"I'm unsure where to put modtime_mphal.h, it could also be in extmod. The
important thing is that for MICROPY_PY_TIME_INCLUDEFILE to work it must be
at the same path in both the port build (original source tree) and the
application build (micropython_embed distribution), therefore not in
ports/embed/port.

It is named .h, mismatching the corresponding ports/*/modtime.c, because it
must not be compiled separately, which naming it .c would make harder for
users of the embed port - they would need to explicitly exclude it, whereas
this way they can continue to just compile all the .c files found in the
micropython_embed distribution except those in lib."

Signed-off-by: Christian Walther <cwalther@gmx.ch>
2024-03-29 18:37:57 +01:00
..
bare-arm shared/libc/string0: Don't deref args for n==0 case. 2023-11-07 16:01:50 +11:00
cc3200 extmod/modmachine: Add MICROPY_PY_MACHINE_RESET configuration option. 2024-03-15 12:04:37 +11:00
embed all: Prune trailing whitespace. 2024-03-07 16:25:17 +11:00
esp32 esp32/network_wlan: Add interface and security WLAN constants. 2024-03-28 13:01:55 +11:00
esp8266 esp8266/network_wlan: Add interface and security WLAN constants. 2024-03-28 13:01:55 +11:00
mimxrt mimxrt: Add support for OpenAMP. 2024-03-29 17:59:29 +11:00
minimal minimal: Use printf instead of echo -e. 2024-02-15 16:36:22 +11:00
nrf nrf: Implement time.time() and machine.RTC. 2024-03-29 18:37:57 +01:00
pic16bit all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
powerpc py/mpconfig: Disable qstr hashing at minimum feature level. 2024-01-25 16:38:17 +11:00
qemu-arm all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
renesas-ra renesas-ra/boards/ARDUINO_PORTENTA_C33: Add Arduino's external library. 2024-03-26 17:03:56 +11:00
rp2 rp2/CMakeLists: Apply O2 optimisation to map, mpz and vm source code. 2024-03-27 12:16:30 +11:00
samd samd/mcu: Guard static function with appropriate #if. 2024-03-29 17:48:06 +11:00
stm32 stm32/mpremoteprocport: Use metal logging functions. 2024-03-29 17:59:18 +11:00
unix unix/variants: Don't use native _Float16 type. 2024-03-20 14:13:49 +11:00
webassembly webassembly/library: Fix formatting and style for Biome. 2024-03-22 14:31:25 +11:00
windows py/objdeque: Expand implementation to be doubly-ended and support iter. 2024-03-18 14:10:14 +11:00
zephyr all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00