Commit graph

156 commits

Author SHA1 Message Date
cyliang tw 183edd2549 drivers: rtc: support for Nuvoton numaker m46x
Add Nuvoton numaker RTC driver including RTC alarm feature.

Signed-off-by: cyliang tw <cyliang@nuvoton.com>
2024-04-30 14:31:29 -04:00
Andrew Featherstone 1c50ba489f drivers: rtc: rpi_pico: Add alarm support to RPi Pico RTC driver
This adds support for the alarm functionality of the RPi Pico RTC.

Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
2024-03-06 10:08:48 +00:00
Andrew Featherstone df8c89b528 drivers: rtc: rpi_pico: Add support for the Raspberry Pi Pico RTC
This adds the minimal get_time/set_time support for the rp2040 and
enables support by default on the Pico boards. This doesn't support
configuring the clock source or alarm interrupts yet.

Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
2024-03-06 10:08:48 +00:00
Andrew Featherstone 4c880f4b0a drivers: rtc: Create utility function for time validation
RTC drivers should validate the `struct rtc_time`'s contents against the
provided `mask`. Promote this common code to a new rtc_utils file and
modify existing drivers to use this functionality. Extend the test
coverage to include verifying this behaviour.

This is groundwork ahead of adding support for the RP2040's (as used in
the Raspberry Pi Pico) RTC and alarm.

Signed-off-by: Andrew Featherstone <andrew.featherstone@gmail.com>
2024-03-06 10:08:48 +00:00
Mustafa Abdullah Kus c9e908d7f3 drivers: rtc: rtc_ll_stm32: add rtc calibration out support
implementation rtc calibration output
frequency set routine.

Signed-off-by: Mustafa Abdullah Kus <mustafa.kus@sparsetechnology.com>
2024-02-27 14:47:31 +01:00
Alberto Escolar Piedras 7369bb56e3 drivers rtc: Do not treat the host libC differently
This code was using strptime from the C library in some cases,
but this function is an extension which many embedded libCs do
not provide, and which is not provided by default unless
_XOPEN_SOURCE or a similar macro is defined before the system headers
are included.

We could define _XOPEN_SOURCE for the libraries that provide it,
but instead of treating the host C library differently than
embedded libraries, let's just build the provided version always,
as that should provide better coverage of this code.

Note: It seems picolibc's strptime is broken,
until this very recent patch:
https://github.com/picolibc/picolibc/pull/657
so we should not select it when building for this library
for a while either.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-01-26 07:48:55 -05:00
Martin Jäger 2effad3b11 drivers: rtc: pcf8563: fix ifdef for alarm_set_callback
The callback should only be available when CONFIG_RTC_ALARM is defined.

Signed-off-by: Martin Jäger <martin@libre.solar>
2024-01-16 20:49:19 -05:00
Petr Hlineny 0ed8f10d8a drivers: rtc: stm32: Updated scope of hsem
This commit updates the scope of  hsem.

Signed-off-by: Petr Hlineny <development@hlineny.cz>
2024-01-04 15:32:47 +01:00
Petr Hlineny 784a5b82e7 drivers: rtc: stm32: Replaces Enter init mode function with LL function
Use LL_RTC_EnterInitMode and LL_RTC_DisableInitMode instead
of rtc_stm32_enter_initialization_mode and
rtc_stm32_leave_initialization_mode.

Signed-off-by: Petr Hlineny <development@hlineny.cz>
2024-01-04 15:32:47 +01:00
Petr Hlineny 4a4543569e drivers: rtc: stm32: Fixes RTC issues related to device runtime pm
When device runtime pm is enabled, Backup Domain protection is active
most of the time. RTC driver need this protection to be disabled in
order to set the time or calibration. This fix disable the protection in
set time and set calibration functions.

Fixes: 62843
Signed-off-by: Petr Hlineny <development@hlineny.cz>
2024-01-04 15:32:47 +01:00
Pisit Sawangvonganan 250d50e8b6 drivers: rtc: set 'rtc_driver_api' as 'static const'
This change marks each instance of the 'rtc_driver_api' as 'static const'.
The rationale is that 'rtc_driver_api' is used for declaring internal
module interfaces and is not intended to be modified at runtime.
By using 'static const', we ensure immutability, leading to usage of only
.rodata and a reduction in the .data area.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2023-12-27 16:12:06 +00:00
Adrien Bruant 9e8c00f28c drivers: stm32-rtc: return -ENODATA when RTC is uninitialized
rtc_get_time() on STM32 does not implement the -ENODATA return code.
This prevents testing the initialisation status of the RTC.

Fixed by reading INITS flag and adding a error path in
rtc_stm32_get_time().

Signed-off-by: Adrien Bruant <adrien.bruant@aalberts-hfc.com>
2023-12-18 09:31:23 +01:00
Anas Nashif a08bfeb49c syscall: rename Z_OOPS -> K_OOPS
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif 1a9de05767 syscall: rename Z_SYSCALL_DRIVER_ -> K_SYSCALL_DRIVER_
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif 9c4d881183 syscall: rename Z_SYSCALL_ to K_SYSCALL_
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif 4e396174ce kernel: move syscall_handler.h to internal include directory
Move the syscall_handler.h header, used internally only to a dedicated
internal folder that should not be used outside of Zephyr.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Benedikt Schmidt a03f1010b8 drivers: fix thread function signatures
Fix thread function signatures to avoid stack corruption on thread exit.

Signed-off-by: Benedikt Schmidt <benedikt.schmidt@embedded-solutions.at>
2023-10-30 12:24:34 +01:00
Arunmani Alagarsamy e9ecc83eea drivers: rtc: new maxim ds1307 rtc driver
Added rtc driver for ds1307. It allows to read and set the date and time

Signed-off-by: Arunmani Alagarsamy <arunmani27100@gmail.com>
2023-10-27 10:50:46 +02:00
Bjarki Arge Andreasen 99ce7d071f drivers: rtc: Add atmel sam series RTC driver
This commit adds an RTC device driver for the atmel SAM
series chips.

Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
2023-10-23 10:49:11 +01:00
Ioannis Karachalios 9f76879a0b drivers: rtc: smartbond: Support RTC peripheral.
Add support for the RTC peripheral.

Signed-off-by: Ioannis Karachalios <ioannis.karachalios.px@renesas.com>
2023-10-20 15:10:44 +02:00
Anas Nashif 85c4703a46 drivers: fake: now just check for CONFIG_ZTEST
Old ztest API is deprecated, so only check for CONFIG_ZTEST.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-10-20 15:04:29 +02:00
Sri Surya 049aaac696 drivers: rtc: new ambiq am1805 rtc driver
Added RTC driver for am1805 with rtc time, alarm set/get,
callback and calibration.

Signed-off-by: Sri Surya <srisurya@linumiz.com>
2023-09-25 09:47:46 +02:00
Johan Lafon 469ba4e367 driver: rtc: stm23: fix build for STM32L1 Cat.1
The Cat.1 STM32L1 MCUs do not provide the subsecond feature. This disable
subsecond related code for these MCUs.

Signed-off-by: Johan Lafon <johan.lafon@syslinbit.com>
2023-09-20 11:34:52 +01:00
Johan Lafon a63bb6317c drivers: rtc: stm32: allow new RTC driver to work with BBRAM
STM32 BBRAM depends on RTC to work. This changes STM32 RTC init stage to
PRE_KERNEL_1 to allow RTC driver to initialize before BBRAM driver.

Some adjustments are made so that kernel API is not used during the init
procedure.

Signed-off-by: Johan Lafon <johan.lafon@syslinbit.com>
2023-09-20 11:34:52 +01:00
Brett Witherspoon e363c5e26d drivers: rtc: stm32: use single instance driver
This driver only supports a single instance. This commit cleans up the
device definition and indicates this.

Signed-off-by: Brett Witherspoon <brett@witherspoon.engineering>
2023-09-18 10:54:04 +01:00
Brett Witherspoon 462a7262be drivers: rtc: stm32: add build assertion for source clock
Assert the source clock is defined in the device tree to ensure the
reference is valid.

Signed-off-by: Brett Witherspoon <brett@witherspoon.engineering>
2023-09-18 10:54:04 +01:00
Brett Witherspoon 0e8e7a0189 drivers: rtc: stm32: fix cell index of source clock
The DT_INST_CLOCKS_CELL macro takes as the first argument the device
instance and not the cell index. This change correctly gets the second
index of the first device as intended.

Signed-off-by: Brett Witherspoon <brett@witherspoon.engineering>
2023-09-18 10:54:04 +01:00
Benjamin Cabé 6be960ae71 drivers: rtc: drop printk statement from RTC Shell
Remove a printk forgotten in rtc get command.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2023-09-15 12:11:24 +01:00
Johan Lafon 24a2b6b004 drivers: rtc: stm32: fix build warning
Use a mem_addr_t cast to avoid build warning.

Signed-off-by: Johan Lafon <johan.lafon@syslinbit.com>
2023-09-14 14:35:19 +02:00
Johan Lafon 244b437a0d drivers: rtc: stm32: disable calibration for STM32F2 and some STM32L1
STM32F2 and STM32L1 Cat. 1 only provide the coarse calibration feature
which is not supported by the code yet.

Signed-off-by: Johan Lafon <johan.lafon@syslinbit.com>
2023-09-12 17:23:47 +01:00
Johan Lafon b06a119f2f drivers: rtc: stm32: fill all rtc_time fields
Set tm_yday and tm_isdst to -1 as theses values are unknown.

Signed-off-by: Johan Lafon <johan.lafon@syslinbit.com>
2023-09-12 17:23:47 +01:00
Johan Lafon 961c465efb drivers: rtc: stm32: use Zephyr BCD<->bin conversion functions
This replaces the verbose LL_RTC_CONVERT_BCD2BIN and LL_RTC_CONVERT_BIN2BCD
by the bcd2bin and bin2bcd Zephyr provided equivalent

Signed-off-by: Johan Lafon <johan.lafon@syslinbit.com>
2023-09-12 17:23:47 +01:00
Johan Lafon a8b7076099 drivers: rtc: stm32: ensure thread safe operations
This adds mutex a lock in rtc_stm32_set_time and rtc_stm32_get_time to
ensure consistent data reading. Also performs register reading in a single
operation in rtc_stm32_get_calibration for the same reason.

Signed-off-by: Johan Lafon <johan.lafon@syslinbit.com>
2023-09-12 17:23:47 +01:00
Johan Lafon e46aff5902 drivers: rtc: stm32: avoid using LL_RTC_Init
LL_RTC_Init() internally uses LL_RTC_EnterInitMode() wich uses a blocking
while loop. This rewrite uses the less CPU time wasteful local
rtc_stm32_enter_initialization_mode() instead. As a side effect
LL_RTC_InitTypeDef in rtc_stm32_config is not needed anymore.

Signed-off-by: Johan Lafon <johan.lafon@syslinbit.com>
2023-09-12 17:23:47 +01:00
Johan Lafon a4f5f87e29 drivers: rtc: stm32: avoid infinite blocking loop
Use the less CPU intensive and timeout capable WAIT_FOR zephyr provided
macro

Signed-off-by: Johan Lafon <johan.lafon@syslinbit.com>
2023-09-12 17:23:47 +01:00
Johan Lafon cdab80eece drivers: rtc: stm32: avoid reset induced time drift
Calling LL_RTC_Init causes the RTC to stop while being configured thus
inducing time drift. This commit avoids doing it at each reset if the RTC
is already properly configured.

Signed-off-by: Johan Lafon <johan.lafon@syslinbit.com>
2023-09-12 17:23:47 +01:00
Johan Lafon 9e202e57e9 drivers: rtc: stm32: avoid potential erroneous readings
As shadow registers bypass is enabled, an erroneous reading may occur at
each day or second increment. This commit fixes this issue.

Signed-off-by: Johan Lafon <johan.lafon@syslinbit.com>
2023-09-12 17:23:47 +01:00
Johan Lafon 4eac3db1b9 drivers: rtc: stm32: check if tm_wday is set
tm/rtc_time structure allow for tm_wday to be set to -1 if unknown but RTC
is expecting it

Signed-off-by: Johan Lafon <johan.lafon@syslinbit.com>
2023-09-12 17:23:47 +01:00
Johan Lafon f0b3e4e850 drivers: rtc: stm32: check if year is supported by RTC
RTC does not support year before 2000 while tm/rtc_time structure
reference year is 1900

Signed-off-by: Johan Lafon <johan.lafon@syslinbit.com>
2023-09-12 17:23:47 +01:00
Johan Lafon 16de401e79 drivers: rtc: stm32: fix day of the week conversion
The conversion used was working but not consistent with values given by
reference manuals.

Signed-off-by: Johan Lafon <johan.lafon@syslinbit.com>
2023-09-12 17:23:47 +01:00
Johan Lafon 29fa718941 drivers: rtc: stm32: fix wrong nanosecond value
SSR register does not contain direct nanosecond value. This adds the
necessary conversion.

Signed-off-by: Johan Lafon <johan.lafon@syslinbit.com>
2023-09-12 17:23:47 +01:00
Johan Lafon 8aa6531aed drivers: rtc: stm32: add calibration feature
This adds the set_calibration and get_calibration API functions to the
STM32 RTC driver

Signed-off-by: Johan Lafon <johan.lafon@syslinbit.com>
2023-09-12 17:23:47 +01:00
Kim Bøndergaard 44e18e8d47 drivers: rtc: rtc_fake: fff rtc driver added
Can be valuable for unit testing modules accessing the RTC

Signed-off-by: Kim Bøndergaard <kim.bondergaard@prevas.dk>
2023-08-24 22:06:51 +01:00
Kim Bøndergaard eed23e8cb3 drivers: rtc: rtc_shell: rtc shell command suite
For now clock can be read and written.

Clock can be set in full iso8601 time format, like 2023-12-24T12:45:56
or by just providing either data or time

Alarms not accessible

Signed-off-by: Kim Bøndergaard <kim.bondergaard@prevas.dk>
2023-08-24 22:06:51 +01:00
Bjarki Arge Andreasen 2c2f1c4576 drivers/rtc/rtc_mc146818.c: Add input clock config to driver
This commit adds input clock selection to the RTC driver. This
is required to allow for the real hardware to operate. The
QEMU emulated hardware ignores the input clock settings.

Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
2023-08-09 07:27:40 -04:00
Bjarki Arge Andreasen 588d39112d drivers/rtc/mc146818: Patch MC146818 driver
The MC146818 driver was not properly initialized
by the driver, interrupts where not handled correctly,
and the alarm feature was not implemented properly.

This commit fixes these issues, while removing some
code which became redundant as the MC146818 driver
was patched.

Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
2023-08-09 07:27:40 -04:00
Erwan Gouriou 00a9cb81c0 drivers: rtc: stm32: Exclude STM32F1 from current RTC driver
STM32F1 series RTC is not compatible with other STM32F1 series,
and it uses a different LL API.
Current implementation of the driver doesn't take this into account,
so we need to explicitly exclude STM32F1 series support until
some changes are made.

Signed-off-by: Erwan Gouriou <erwan.gouriou@st.com>
2023-07-24 14:38:47 +00:00
Kim Bøndergaard b3c46083fb drivers: rtc: stm32: New stm32 RTC driver
STM32 RTC driver for the new RTC API.
Can't coexist with old COUNTER based RTC

Though supported by HW, RTC_ALARM still to be supported by driver

Signed-off-by: Kim Bøndergaard <kim.bondergaard@prevas.dk>
2023-07-18 11:05:23 +00:00
Florian Grandel 5c4ec518ab driver: rtc: rtc_emul: remove redundant brackets
Change due to review comment: remove redundant brackets for pointer
value access.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-12 09:26:16 +02:00
Florian Grandel ff2b5cebb7 drivers: rtc: rtc_emul: replace mutex with spinlock
Replaces the mutex with a lightweight spinlock.

Fixes: #59901

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-12 09:26:16 +02:00