rtc: Remove old rtc functionality
Remove the old rtc functionality as its been deprecated for 2 releases now. Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
parent
a0136b9850
commit
29e55d74e8
69 changed files with 4 additions and 1259 deletions
|
@ -15,7 +15,6 @@ supported:
|
||||||
- hts221
|
- hts221
|
||||||
- lps22hb
|
- lps22hb
|
||||||
- lsm6dsl
|
- lsm6dsl
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
- spi
|
- spi
|
||||||
- vl53l0x
|
- vl53l0x
|
||||||
|
|
|
@ -10,7 +10,6 @@ supported:
|
||||||
- gpio
|
- gpio
|
||||||
- ble
|
- ble
|
||||||
- i2c
|
- i2c
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
- spi
|
- spi
|
||||||
- usb_device
|
- usb_device
|
||||||
|
|
|
@ -12,5 +12,4 @@ supported:
|
||||||
- gpio
|
- gpio
|
||||||
- i2c
|
- i2c
|
||||||
- spi
|
- spi
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
|
|
|
@ -11,5 +11,4 @@ supported:
|
||||||
- gpio
|
- gpio
|
||||||
- i2c
|
- i2c
|
||||||
- spi
|
- spi
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
|
|
|
@ -14,4 +14,3 @@ supported:
|
||||||
- i2c
|
- i2c
|
||||||
- spi
|
- spi
|
||||||
- gpio
|
- gpio
|
||||||
- rtc
|
|
||||||
|
|
|
@ -14,6 +14,5 @@ supported:
|
||||||
- spi
|
- spi
|
||||||
- gpio
|
- gpio
|
||||||
- pwm
|
- pwm
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
- adc
|
- adc
|
||||||
|
|
|
@ -18,7 +18,6 @@ supported:
|
||||||
- i2c
|
- i2c
|
||||||
- spi
|
- spi
|
||||||
- pwm
|
- pwm
|
||||||
- rtc
|
|
||||||
- watchdog
|
- watchdog
|
||||||
- counter
|
- counter
|
||||||
- nvs
|
- nvs
|
||||||
|
|
|
@ -10,7 +10,6 @@ supported:
|
||||||
- arduino_gpio
|
- arduino_gpio
|
||||||
- arduino_i2c
|
- arduino_i2c
|
||||||
- pwm
|
- pwm
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
- gpio
|
- gpio
|
||||||
- i2c
|
- i2c
|
||||||
|
|
|
@ -9,7 +9,6 @@ toolchain:
|
||||||
supported:
|
supported:
|
||||||
- arduino_gpio
|
- arduino_gpio
|
||||||
- arduino_i2c
|
- arduino_i2c
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
- gpio
|
- gpio
|
||||||
- spi
|
- spi
|
||||||
|
|
|
@ -15,5 +15,4 @@ supported:
|
||||||
- spi
|
- spi
|
||||||
- gpio
|
- gpio
|
||||||
- usb_device
|
- usb_device
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
|
|
|
@ -15,5 +15,4 @@ supported:
|
||||||
- spi
|
- spi
|
||||||
- gpio
|
- gpio
|
||||||
- usb_device
|
- usb_device
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
|
|
|
@ -15,7 +15,6 @@ supported:
|
||||||
- spi
|
- spi
|
||||||
- gpio
|
- gpio
|
||||||
- pwm
|
- pwm
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
- usb_device
|
- usb_device
|
||||||
- watchdog
|
- watchdog
|
||||||
|
|
|
@ -8,7 +8,6 @@ toolchain:
|
||||||
- xtools
|
- xtools
|
||||||
supported:
|
supported:
|
||||||
- arduino_i2c
|
- arduino_i2c
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
- gpio
|
- gpio
|
||||||
- spi
|
- spi
|
||||||
|
|
|
@ -18,7 +18,6 @@ supported:
|
||||||
- pwm
|
- pwm
|
||||||
- spi
|
- spi
|
||||||
- watchdog
|
- watchdog
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
- can
|
- can
|
||||||
- adc
|
- adc
|
||||||
|
|
|
@ -12,6 +12,5 @@ supported:
|
||||||
- nvs
|
- nvs
|
||||||
- pwm
|
- pwm
|
||||||
- can
|
- can
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
- spi
|
- spi
|
||||||
|
|
|
@ -12,7 +12,6 @@ supported:
|
||||||
- gpio
|
- gpio
|
||||||
- spi
|
- spi
|
||||||
- i2c
|
- i2c
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
- adc
|
- adc
|
||||||
ram: 96
|
ram: 96
|
||||||
|
|
|
@ -12,7 +12,6 @@ supported:
|
||||||
- i2c
|
- i2c
|
||||||
- spi
|
- spi
|
||||||
- pwm
|
- pwm
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
- watchdog
|
- watchdog
|
||||||
testing:
|
testing:
|
||||||
|
|
|
@ -14,7 +14,6 @@ supported:
|
||||||
- gpio
|
- gpio
|
||||||
- usb device
|
- usb device
|
||||||
- nvs
|
- nvs
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
ram: 640
|
ram: 640
|
||||||
flash: 2048
|
flash: 2048
|
||||||
|
|
|
@ -9,6 +9,5 @@ toolchain:
|
||||||
ram: 128
|
ram: 128
|
||||||
flash: 1024
|
flash: 1024
|
||||||
supported:
|
supported:
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
- usb_device
|
- usb_device
|
||||||
|
|
|
@ -9,5 +9,4 @@ toolchain:
|
||||||
ram: 128
|
ram: 128
|
||||||
flash: 1024
|
flash: 1024
|
||||||
supported:
|
supported:
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
|
|
|
@ -9,5 +9,4 @@ toolchain:
|
||||||
ram: 128
|
ram: 128
|
||||||
flash: 1024
|
flash: 1024
|
||||||
supported:
|
supported:
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
|
|
|
@ -8,6 +8,5 @@ toolchain:
|
||||||
- xtools
|
- xtools
|
||||||
ram: 32
|
ram: 32
|
||||||
supported:
|
supported:
|
||||||
- rtc
|
|
||||||
- watchdog
|
- watchdog
|
||||||
- counter
|
- counter
|
||||||
|
|
|
@ -10,7 +10,6 @@ ram: 40
|
||||||
supported:
|
supported:
|
||||||
- gpio
|
- gpio
|
||||||
- i2c
|
- i2c
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
- spi
|
- spi
|
||||||
- usb_device
|
- usb_device
|
||||||
|
|
|
@ -7,5 +7,4 @@ toolchain:
|
||||||
- gnuarmemb
|
- gnuarmemb
|
||||||
- xtools
|
- xtools
|
||||||
supported:
|
supported:
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
|
|
|
@ -7,5 +7,4 @@ toolchain:
|
||||||
- gnuarmemb
|
- gnuarmemb
|
||||||
- xtools
|
- xtools
|
||||||
supported:
|
supported:
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
|
|
|
@ -9,6 +9,5 @@ toolchain:
|
||||||
ram: 192
|
ram: 192
|
||||||
flash: 2048
|
flash: 2048
|
||||||
supported:
|
supported:
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
- i2c
|
- i2c
|
||||||
|
|
|
@ -10,7 +10,6 @@ ram: 320
|
||||||
flash: 2048
|
flash: 2048
|
||||||
supported:
|
supported:
|
||||||
- arduino_i2c
|
- arduino_i2c
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
- i2c
|
- i2c
|
||||||
- spi
|
- spi
|
||||||
|
|
|
@ -10,6 +10,5 @@ ram: 128
|
||||||
flash: 1024
|
flash: 1024
|
||||||
supported:
|
supported:
|
||||||
- pwm
|
- pwm
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
- usb
|
- usb
|
||||||
|
|
|
@ -15,6 +15,5 @@ supported:
|
||||||
- spi
|
- spi
|
||||||
- gpio
|
- gpio
|
||||||
- pwm
|
- pwm
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
- usb_device
|
- usb_device
|
||||||
|
|
|
@ -10,5 +10,4 @@ ram: 96
|
||||||
flash: 1024
|
flash: 1024
|
||||||
supported:
|
supported:
|
||||||
- gpio
|
- gpio
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
|
|
|
@ -14,5 +14,4 @@ supported:
|
||||||
- i2c
|
- i2c
|
||||||
- spi
|
- spi
|
||||||
- gpio
|
- gpio
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
|
|
|
@ -9,7 +9,6 @@ toolchain:
|
||||||
ram: 32
|
ram: 32
|
||||||
flash: 512
|
flash: 512
|
||||||
supported:
|
supported:
|
||||||
- rtc
|
|
||||||
- counter
|
- counter
|
||||||
- i2c
|
- i2c
|
||||||
- hwinfo
|
- hwinfo
|
||||||
|
|
|
@ -45,8 +45,6 @@ source "drivers/pinmux/Kconfig"
|
||||||
|
|
||||||
source "drivers/adc/Kconfig"
|
source "drivers/adc/Kconfig"
|
||||||
|
|
||||||
source "drivers/rtc/Kconfig"
|
|
||||||
|
|
||||||
source "drivers/watchdog/Kconfig"
|
source "drivers/watchdog/Kconfig"
|
||||||
|
|
||||||
source "drivers/clock_control/Kconfig"
|
source "drivers/clock_control/Kconfig"
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
zephyr_library()
|
|
||||||
|
|
||||||
zephyr_library_sources_ifdef(CONFIG_RTC_MCUX rtc_mcux.c)
|
|
||||||
zephyr_library_sources_ifdef(CONFIG_RTC_STM32 rtc_ll_stm32.c)
|
|
|
@ -1,35 +0,0 @@
|
||||||
# Kconfig - RTC configuration options
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# Copyright (c) 2015 Intel Corporation
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
|
||||||
#
|
|
||||||
|
|
||||||
#
|
|
||||||
# Real-Time Clock (RTC) options
|
|
||||||
#
|
|
||||||
menuconfig RTC
|
|
||||||
bool "Real-Time Clock"
|
|
||||||
help
|
|
||||||
Enable options for Real-Time Clock drivers.
|
|
||||||
|
|
||||||
if RTC
|
|
||||||
|
|
||||||
module = RTC
|
|
||||||
module-str = rtc
|
|
||||||
source "subsys/logging/Kconfig.template.log_config"
|
|
||||||
|
|
||||||
config RTC_0_NAME
|
|
||||||
string "Driver instance name"
|
|
||||||
default "RTC_0"
|
|
||||||
depends on !HAS_DTS
|
|
||||||
help
|
|
||||||
RTC driver instance name
|
|
||||||
|
|
||||||
comment "RTC drivers"
|
|
||||||
|
|
||||||
source "drivers/rtc/Kconfig.mcux_rtc"
|
|
||||||
source "drivers/rtc/Kconfig.stm32_rtc"
|
|
||||||
|
|
||||||
endif # RTC
|
|
|
@ -1,12 +0,0 @@
|
||||||
# Kconfig - MCUXpresso SDK RTC
|
|
||||||
#
|
|
||||||
# Copyright (c) 2018, blik GmbH
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
|
||||||
#
|
|
||||||
|
|
||||||
menuconfig RTC_MCUX
|
|
||||||
bool "MCUX RTC driver"
|
|
||||||
depends on HAS_MCUX_RTC
|
|
||||||
help
|
|
||||||
Enable support for mcux rtc driver.
|
|
|
@ -1,67 +0,0 @@
|
||||||
# Kconfig - STM32 RTC configuration options
|
|
||||||
#
|
|
||||||
# Copyright (c) 2018 Workaround GmbH
|
|
||||||
# Copyright (c) 2018 Allterco Robotics
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
|
||||||
#
|
|
||||||
|
|
||||||
config RTC_STM32
|
|
||||||
bool "STM32 RTC Driver"
|
|
||||||
depends on SOC_FAMILY_STM32
|
|
||||||
select USE_STM32_LL_RTC
|
|
||||||
select USE_STM32_LL_PWR
|
|
||||||
select USE_STM32_LL_RCC
|
|
||||||
select USE_STM32_LL_EXTI
|
|
||||||
select NEWLIB_LIBC
|
|
||||||
help
|
|
||||||
Build RTC driver for STM32 SoCs. Tested on STM32 F3, F4, L4, F7 series.
|
|
||||||
|
|
||||||
choice RTC_STM32_CLOCK_SRC
|
|
||||||
bool "RTC clock source"
|
|
||||||
depends on RTC_STM32
|
|
||||||
|
|
||||||
config RTC_STM32_CLOCK_LSI
|
|
||||||
bool "LSI"
|
|
||||||
help
|
|
||||||
Use LSI as RTC clock
|
|
||||||
|
|
||||||
config RTC_STM32_CLOCK_LSE
|
|
||||||
bool "LSE"
|
|
||||||
help
|
|
||||||
Use LSE as RTC clock
|
|
||||||
|
|
||||||
endchoice #RTC_STM32_CLOCK_SRC
|
|
||||||
|
|
||||||
choice RTC_STM32_LSE_DRIVE
|
|
||||||
prompt "LSE oscillator drive capability"
|
|
||||||
depends on RTC_STM32_CLOCK_LSE
|
|
||||||
|
|
||||||
config RTC_STM32_LSE_DRIVE_LOW
|
|
||||||
bool "Low"
|
|
||||||
help
|
|
||||||
Xtal mode lower driving capability
|
|
||||||
|
|
||||||
config RTC_STM32_LSE_DRIVE_MEDIUMLOW
|
|
||||||
bool "Medium Low"
|
|
||||||
help
|
|
||||||
Xtal mode medium low driving capability
|
|
||||||
|
|
||||||
config RTC_STM32_LSE_DRIVE_MEDIUMHIGH
|
|
||||||
bool "Medium High"
|
|
||||||
help
|
|
||||||
Xtal mode medium high driving capability
|
|
||||||
|
|
||||||
config RTC_STM32_LSE_DRIVE_HIGH
|
|
||||||
bool "High"
|
|
||||||
help
|
|
||||||
Xtal mode higher driving capability
|
|
||||||
|
|
||||||
endchoice
|
|
||||||
|
|
||||||
config RTC_STM32_LSE_DRIVE_STRENGTH
|
|
||||||
hex
|
|
||||||
default 0x00000000 if RTC_STM32_LSE_DRIVE_LOW
|
|
||||||
default 0x00000008 if RTC_STM32_LSE_DRIVE_MEDIUMLOW
|
|
||||||
default 0x00000010 if RTC_STM32_LSE_DRIVE_MEDIUMHIGH
|
|
||||||
default 0x00000018 if RTC_STM32_LSE_DRIVE_HIGH
|
|
|
@ -1,47 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2017 Intel Corporation
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <syscall_handler.h>
|
|
||||||
#include <drivers/rtc.h>
|
|
||||||
|
|
||||||
static inline u32_t z_vrfy_rtc_read(struct device *dev)
|
|
||||||
{
|
|
||||||
Z_OOPS(Z_SYSCALL_DRIVER_RTC(dev, read));
|
|
||||||
return z_impl_rtc_read((struct device *)dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void z_vrfy_rtc_enable(struct device *dev)
|
|
||||||
{
|
|
||||||
Z_OOPS(Z_SYSCALL_DRIVER_RTC(dev, enable));
|
|
||||||
z_impl_rtc_enable((struct device *)dev);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void z_vrfy_rtc_disable(struct device *dev)
|
|
||||||
{
|
|
||||||
Z_OOPS(Z_SYSCALL_DRIVER_RTC(dev, disable));
|
|
||||||
z_impl_rtc_disable((struct device *)dev);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int z_vrfy_rtc_set_alarm(struct device *dev,
|
|
||||||
const u32_t alarm_val)
|
|
||||||
{
|
|
||||||
Z_OOPS(Z_SYSCALL_DRIVER_RTC(dev, set_alarm));
|
|
||||||
return z_impl_rtc_set_alarm((struct device *)dev, alarm_val);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int z_vrfy_rtc_get_pending_int(struct device *dev)
|
|
||||||
{
|
|
||||||
Z_OOPS(Z_SYSCALL_DRIVER_RTC(dev, get_pending_int));
|
|
||||||
return z_impl_rtc_get_pending_int((struct device *)dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <syscalls/rtc_read_mrsh.c>
|
|
||||||
#include <syscalls/rtc_enable_mrsh.c>
|
|
||||||
#include <syscalls/rtc_disable_mrsh.c>
|
|
||||||
#include <syscalls/rtc_set_alarm_mrsh.c>
|
|
||||||
#include <syscalls/rtc_get_pending_int_mrsh.c>
|
|
|
@ -1,314 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2018 Workaround GmbH
|
|
||||||
* Copyright (c) 2018 Allterco Robotics
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Source file for the STM32 RTC driver
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#include <clock_control/stm32_clock_control.h>
|
|
||||||
#include <drivers/clock_control.h>
|
|
||||||
#include <sys/util.h>
|
|
||||||
#include <kernel.h>
|
|
||||||
#include <soc.h>
|
|
||||||
#include <drivers/rtc.h>
|
|
||||||
|
|
||||||
#if defined(CONFIG_SOC_SERIES_STM32L4X)
|
|
||||||
#define EXTI_LINE LL_EXTI_LINE_18
|
|
||||||
#elif defined(CONFIG_SOC_SERIES_STM32F4X) \
|
|
||||||
|| defined(CONFIG_SOC_SERIES_STM32F3X) \
|
|
||||||
|| defined(CONFIG_SOC_SERIES_STM32F7X)
|
|
||||||
#define EXTI_LINE LL_EXTI_LINE_17
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define EPOCH_OFFSET 946684800
|
|
||||||
|
|
||||||
struct rtc_stm32_config {
|
|
||||||
struct stm32_pclken pclken;
|
|
||||||
LL_RTC_InitTypeDef ll_rtc_config;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct rtc_stm32_data {
|
|
||||||
void (*cb_fn)(struct device *dev);
|
|
||||||
struct k_sem sem;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#define DEV_DATA(dev) ((struct rtc_stm32_data *const)(dev)->driver_data)
|
|
||||||
#define DEV_SEM(dev) (&DEV_DATA(dev)->sem)
|
|
||||||
#define DEV_CFG(dev) \
|
|
||||||
((const struct rtc_stm32_config * const)(dev)->config->config_info)
|
|
||||||
|
|
||||||
static int rtc_stm32_set_alarm(struct device *dev, const u32_t alarm_val);
|
|
||||||
static void rtc_stm32_irq_config(struct device *dev);
|
|
||||||
|
|
||||||
static void rtc_stm32_enable(struct device *dev)
|
|
||||||
{
|
|
||||||
LL_RCC_EnableRTC();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rtc_stm32_disable(struct device *dev)
|
|
||||||
{
|
|
||||||
LL_RCC_DisableRTC();
|
|
||||||
}
|
|
||||||
|
|
||||||
static u32_t rtc_stm32_read(struct device *dev)
|
|
||||||
{
|
|
||||||
struct tm now = { 0 };
|
|
||||||
time_t ts;
|
|
||||||
u32_t rtc_date, rtc_time;
|
|
||||||
|
|
||||||
/* Read time and date registers */
|
|
||||||
rtc_time = LL_RTC_TIME_Get(RTC);
|
|
||||||
rtc_date = LL_RTC_DATE_Get(RTC);
|
|
||||||
|
|
||||||
/* Convert calendar datetime to UNIX timestamp */
|
|
||||||
now.tm_year = 100 + __LL_RTC_CONVERT_BCD2BIN(
|
|
||||||
__LL_RTC_GET_YEAR(rtc_date));
|
|
||||||
/* tm_mon starts from 0 */
|
|
||||||
now.tm_mon = __LL_RTC_CONVERT_BCD2BIN(__LL_RTC_GET_MONTH(rtc_date)) - 1;
|
|
||||||
now.tm_mday = __LL_RTC_CONVERT_BCD2BIN(__LL_RTC_GET_DAY(rtc_date));
|
|
||||||
|
|
||||||
now.tm_hour = __LL_RTC_CONVERT_BCD2BIN(__LL_RTC_GET_HOUR(rtc_time));
|
|
||||||
now.tm_min = __LL_RTC_CONVERT_BCD2BIN(__LL_RTC_GET_MINUTE(rtc_time));
|
|
||||||
now.tm_sec = __LL_RTC_CONVERT_BCD2BIN(__LL_RTC_GET_SECOND(rtc_time));
|
|
||||||
|
|
||||||
ts = mktime(&now);
|
|
||||||
|
|
||||||
/* Return number of seconds since 2000-01-01 00:00:00 */
|
|
||||||
ts -= EPOCH_OFFSET;
|
|
||||||
|
|
||||||
return (u32_t)ts;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int rtc_stm32_set_alarm(struct device *dev, const u32_t alarm_val)
|
|
||||||
{
|
|
||||||
struct tm alarm_tm;
|
|
||||||
time_t alarm_ts;
|
|
||||||
LL_RTC_AlarmTypeDef rtc_alarm;
|
|
||||||
|
|
||||||
u32_t now = rtc_stm32_read(dev);
|
|
||||||
|
|
||||||
/* The longest period we can match for universally is the
|
|
||||||
duration of the shortest month */
|
|
||||||
if ((alarm_val - now) > (RTC_ALARM_DAY * 28)) {
|
|
||||||
return -ENOTSUP;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Convert seconds since 2000-01-01 00:00:00 to calendar datetime */
|
|
||||||
alarm_ts = alarm_val;
|
|
||||||
alarm_ts += EPOCH_OFFSET;
|
|
||||||
gmtime_r(&alarm_ts, &alarm_tm);
|
|
||||||
|
|
||||||
/* Apply ALARM_A */
|
|
||||||
rtc_alarm.AlarmTime.TimeFormat = LL_RTC_TIME_FORMAT_AM_OR_24;
|
|
||||||
rtc_alarm.AlarmTime.Hours = alarm_tm.tm_hour;
|
|
||||||
rtc_alarm.AlarmTime.Minutes = alarm_tm.tm_min;
|
|
||||||
rtc_alarm.AlarmTime.Seconds = alarm_tm.tm_sec;
|
|
||||||
|
|
||||||
rtc_alarm.AlarmMask = LL_RTC_ALMA_MASK_NONE;
|
|
||||||
rtc_alarm.AlarmDateWeekDaySel = LL_RTC_ALMA_DATEWEEKDAYSEL_DATE;
|
|
||||||
rtc_alarm.AlarmDateWeekDay = alarm_tm.tm_mday;
|
|
||||||
|
|
||||||
LL_RTC_DisableWriteProtection(RTC);
|
|
||||||
LL_RTC_ALMA_Disable(RTC);
|
|
||||||
|
|
||||||
if (LL_RTC_ALMA_Init(RTC, LL_RTC_FORMAT_BIN, &rtc_alarm) != SUCCESS) {
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
LL_RTC_DisableWriteProtection(RTC);
|
|
||||||
|
|
||||||
LL_RTC_ALMA_Enable(RTC);
|
|
||||||
LL_RTC_ClearFlag_ALRA(RTC);
|
|
||||||
LL_RTC_EnableIT_ALRA(RTC);
|
|
||||||
|
|
||||||
LL_RTC_EnableWriteProtection(RTC);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int rtc_stm32_set_config(struct device *dev, struct rtc_config *cfg)
|
|
||||||
{
|
|
||||||
int result = 0;
|
|
||||||
time_t init_ts = 0;
|
|
||||||
struct tm init_tm = { 0 };
|
|
||||||
|
|
||||||
LL_RTC_DateTypeDef rtc_date = { 0 };
|
|
||||||
LL_RTC_TimeTypeDef rtc_time = { 0 };
|
|
||||||
|
|
||||||
/* Convert seconds since 2000-01-01 00:00:00 to calendar datetime */
|
|
||||||
init_ts = cfg->init_val;
|
|
||||||
init_ts += EPOCH_OFFSET;
|
|
||||||
|
|
||||||
gmtime_r(&init_ts, &init_tm);
|
|
||||||
|
|
||||||
rtc_date.Year = init_tm.tm_year % 100;
|
|
||||||
/* tm_mon starts from 0 */
|
|
||||||
rtc_date.Month = init_tm.tm_mon + 1;
|
|
||||||
rtc_date.Day = init_tm.tm_mday;
|
|
||||||
rtc_date.WeekDay = init_tm.tm_wday + 1;
|
|
||||||
|
|
||||||
rtc_time.TimeFormat = LL_RTC_TIME_FORMAT_AM_OR_24;
|
|
||||||
rtc_time.Hours = init_tm.tm_hour;
|
|
||||||
rtc_time.Minutes = init_tm.tm_min;
|
|
||||||
rtc_time.Seconds = init_tm.tm_sec;
|
|
||||||
|
|
||||||
k_sem_take(DEV_SEM(dev), K_FOREVER);
|
|
||||||
|
|
||||||
if (cfg->cb_fn != NULL) {
|
|
||||||
DEV_DATA(dev)->cb_fn = cfg->cb_fn;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (LL_RTC_DATE_Init(RTC, LL_RTC_FORMAT_BIN, &rtc_date) != SUCCESS) {
|
|
||||||
result = -EIO;
|
|
||||||
goto fin;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (LL_RTC_TIME_Init(RTC, LL_RTC_FORMAT_BIN, &rtc_time) != SUCCESS) {
|
|
||||||
result = -EIO;
|
|
||||||
goto fin;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cfg->alarm_enable) {
|
|
||||||
rtc_stm32_set_alarm(dev, cfg->alarm_val);
|
|
||||||
}
|
|
||||||
|
|
||||||
fin:
|
|
||||||
k_sem_give(DEV_SEM(dev));
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static u32_t rtc_stm32_get_pending_int(struct device *dev)
|
|
||||||
{
|
|
||||||
return LL_RTC_IsActiveFlag_ALRA(RTC) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void rtc_stm32_isr(void *arg)
|
|
||||||
{
|
|
||||||
struct device *const dev = (struct device *)arg;
|
|
||||||
|
|
||||||
if (LL_RTC_IsActiveFlag_ALRA(RTC) != 0) {
|
|
||||||
|
|
||||||
if (DEV_DATA(dev)->cb_fn != NULL) {
|
|
||||||
DEV_DATA(dev)->cb_fn(dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
LL_RTC_ClearFlag_ALRA(RTC);
|
|
||||||
LL_RTC_DisableIT_ALRA(RTC);
|
|
||||||
}
|
|
||||||
|
|
||||||
LL_EXTI_ClearFlag_0_31(EXTI_LINE);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int rtc_stm32_init(struct device *dev)
|
|
||||||
{
|
|
||||||
struct device *clk = device_get_binding(STM32_CLOCK_CONTROL_NAME);
|
|
||||||
const struct rtc_stm32_config *cfg = DEV_CFG(dev);
|
|
||||||
|
|
||||||
__ASSERT_NO_MSG(clk);
|
|
||||||
|
|
||||||
k_sem_init(DEV_SEM(dev), 1, UINT_MAX);
|
|
||||||
DEV_DATA(dev)->cb_fn = NULL;
|
|
||||||
|
|
||||||
if (clock_control_on(clk,
|
|
||||||
(clock_control_subsys_t *) &cfg->pclken) != 0) {
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
LL_PWR_EnableBkUpAccess();
|
|
||||||
LL_RCC_ForceBackupDomainReset();
|
|
||||||
LL_RCC_ReleaseBackupDomainReset();
|
|
||||||
|
|
||||||
#if defined(CONFIG_RTC_STM32_CLOCK_LSI)
|
|
||||||
|
|
||||||
LL_RCC_LSI_Enable();
|
|
||||||
while (LL_RCC_LSI_IsReady() != 1) {
|
|
||||||
}
|
|
||||||
|
|
||||||
LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSI);
|
|
||||||
|
|
||||||
#else /* CONFIG_RTC_STM32_CLOCK_LSE */
|
|
||||||
|
|
||||||
LL_RCC_LSE_SetDriveCapability(CONFIG_RTC_STM32_LSE_DRIVE_STRENGTH);
|
|
||||||
LL_RCC_LSE_Enable();
|
|
||||||
|
|
||||||
/* Wait until LSE is ready */
|
|
||||||
while (LL_RCC_LSE_IsReady() != 1) {
|
|
||||||
}
|
|
||||||
|
|
||||||
LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSE);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
LL_RCC_EnableRTC();
|
|
||||||
|
|
||||||
if (LL_RTC_DeInit(RTC) != SUCCESS) {
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (LL_RTC_Init(RTC, ((LL_RTC_InitTypeDef *)
|
|
||||||
&cfg->ll_rtc_config)) != SUCCESS) {
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
LL_RTC_EnableShadowRegBypass(RTC);
|
|
||||||
|
|
||||||
LL_EXTI_EnableIT_0_31(EXTI_LINE);
|
|
||||||
LL_EXTI_EnableRisingTrig_0_31(EXTI_LINE);
|
|
||||||
|
|
||||||
rtc_stm32_irq_config(dev);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct rtc_stm32_data rtc_data;
|
|
||||||
|
|
||||||
static const struct rtc_stm32_config rtc_config = {
|
|
||||||
.pclken = {
|
|
||||||
.enr = LL_APB1_GRP1_PERIPH_PWR,
|
|
||||||
.bus = STM32_CLOCK_BUS_APB1,
|
|
||||||
},
|
|
||||||
.ll_rtc_config = {
|
|
||||||
.HourFormat = LL_RTC_HOURFORMAT_24HOUR,
|
|
||||||
|
|
||||||
#if defined(CONFIG_RTC_STM32_CLOCK_LSI)
|
|
||||||
|
|
||||||
/* prescaler values for LSI @ 32 KHz */
|
|
||||||
.AsynchPrescaler = 0x7F,
|
|
||||||
.SynchPrescaler = 0x00F9,
|
|
||||||
|
|
||||||
#else /* CONFIG_RTC_STM32_CLOCK_LSE */
|
|
||||||
|
|
||||||
/* prescaler values for LSE @ 32768 Hz */
|
|
||||||
.AsynchPrescaler = 0x7F,
|
|
||||||
.SynchPrescaler = 0x00FF,
|
|
||||||
#endif
|
|
||||||
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
static const struct rtc_driver_api rtc_api = {
|
|
||||||
.enable = rtc_stm32_enable,
|
|
||||||
.disable = rtc_stm32_disable,
|
|
||||||
.read = rtc_stm32_read,
|
|
||||||
.set_config = rtc_stm32_set_config,
|
|
||||||
.set_alarm = rtc_stm32_set_alarm,
|
|
||||||
.get_pending_int = rtc_stm32_get_pending_int,
|
|
||||||
};
|
|
||||||
|
|
||||||
DEVICE_AND_API_INIT(rtc_stm32, CONFIG_RTC_0_NAME, &rtc_stm32_init,
|
|
||||||
&rtc_data, &rtc_config, PRE_KERNEL_1,
|
|
||||||
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &rtc_api);
|
|
||||||
|
|
||||||
static void rtc_stm32_irq_config(struct device *dev)
|
|
||||||
{
|
|
||||||
IRQ_CONNECT(DT_RTC_0_IRQ, DT_RTC_0_IRQ_PRI,
|
|
||||||
rtc_stm32_isr, DEVICE_GET(rtc_stm32), 0);
|
|
||||||
irq_enable(DT_RTC_0_IRQ);
|
|
||||||
}
|
|
|
@ -1,207 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2018 blik GmbH
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define LOG_LEVEL CONFIG_RTC_LOG_LEVEL
|
|
||||||
#include <logging/log.h>
|
|
||||||
LOG_MODULE_REGISTER(rtc_mcux);
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <device.h>
|
|
||||||
#include <init.h>
|
|
||||||
#include <kernel.h>
|
|
||||||
#include <drivers/rtc.h>
|
|
||||||
#include <power/power.h>
|
|
||||||
#include <soc.h>
|
|
||||||
#include <sys/util.h>
|
|
||||||
#include <fsl_rtc.h>
|
|
||||||
|
|
||||||
struct mcux_rtc_config {
|
|
||||||
RTC_Type *base;
|
|
||||||
void (*irq_config_func)(struct device *dev);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct mcux_rtc_data {
|
|
||||||
struct k_sem sync;
|
|
||||||
rtc_config_t config;
|
|
||||||
|
|
||||||
/* callback information */
|
|
||||||
void (*callback)(void *data);
|
|
||||||
void *callback_data;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void mcux_rtc_enable(struct device *dev)
|
|
||||||
{
|
|
||||||
const struct mcux_rtc_config *config = dev->config->config_info;
|
|
||||||
|
|
||||||
RTC_StartTimer(config->base);
|
|
||||||
RTC_EnableInterrupts(config->base,
|
|
||||||
kRTC_AlarmInterruptEnable |
|
|
||||||
kRTC_TimeOverflowInterruptEnable |
|
|
||||||
kRTC_TimeInvalidInterruptEnable);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mcux_rtc_disable(struct device *dev)
|
|
||||||
{
|
|
||||||
const struct mcux_rtc_config *config = dev->config->config_info;
|
|
||||||
|
|
||||||
RTC_DisableInterrupts(config->base,
|
|
||||||
kRTC_AlarmInterruptEnable |
|
|
||||||
kRTC_TimeOverflowInterruptEnable |
|
|
||||||
kRTC_TimeInvalidInterruptEnable);
|
|
||||||
RTC_StopTimer(config->base);
|
|
||||||
|
|
||||||
/* clear out any set alarms */
|
|
||||||
config->base->TAR = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int mcux_rtc_set_alarm(struct device *dev, const u32_t alarm_val)
|
|
||||||
{
|
|
||||||
const struct mcux_rtc_config *config = dev->config->config_info;
|
|
||||||
|
|
||||||
if (alarm_val < config->base->TSR) {
|
|
||||||
LOG_ERR("alarm cannot be earlier than current time");
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
config->base->TAR = alarm_val;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int mcux_rtc_set_config(struct device *dev, struct rtc_config *cfg)
|
|
||||||
{
|
|
||||||
const struct mcux_rtc_config *config = dev->config->config_info;
|
|
||||||
struct mcux_rtc_data *data = dev->driver_data;
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
/* only allow one modifier at a time */
|
|
||||||
k_sem_take(&data->sync, K_FOREVER);
|
|
||||||
|
|
||||||
if (cfg->alarm_enable) {
|
|
||||||
/* set up callback information */
|
|
||||||
data->callback = (void *) cfg->cb_fn;
|
|
||||||
data->callback_data = dev;
|
|
||||||
|
|
||||||
RTC_StopTimer(config->base);
|
|
||||||
config->base->TSR = cfg->init_val;
|
|
||||||
RTC_StartTimer(config->base);
|
|
||||||
ret = mcux_rtc_set_alarm(dev, cfg->alarm_val);
|
|
||||||
} else {
|
|
||||||
/* clear any existing alarm setting */
|
|
||||||
config->base->TAR = 0;
|
|
||||||
|
|
||||||
/* clear callbacks */
|
|
||||||
data->callback = NULL;
|
|
||||||
data->callback_data = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
k_sem_give(&data->sync);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static u32_t mcux_rtc_read(struct device *dev)
|
|
||||||
{
|
|
||||||
const struct mcux_rtc_config *config = dev->config->config_info;
|
|
||||||
u32_t val = config->base->TSR;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Read TSR seconds twice in case it glitches during an update.
|
|
||||||
* This can happen when a read occurs at the time the register is
|
|
||||||
* incrementing.
|
|
||||||
*/
|
|
||||||
if (config->base->TSR == val) {
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
val = config->base->TSR;
|
|
||||||
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
static u32_t mcux_rtc_get_pending_int(struct device *dev)
|
|
||||||
{
|
|
||||||
const struct mcux_rtc_config *config = dev->config->config_info;
|
|
||||||
|
|
||||||
return RTC_GetStatusFlags(config->base) & RTC_SR_TAF_MASK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct rtc_driver_api mcux_rtc_driver_api = {
|
|
||||||
.enable = mcux_rtc_enable,
|
|
||||||
.disable = mcux_rtc_disable,
|
|
||||||
.read = mcux_rtc_read,
|
|
||||||
.set_config = mcux_rtc_set_config,
|
|
||||||
.set_alarm = mcux_rtc_set_alarm,
|
|
||||||
.get_pending_int = mcux_rtc_get_pending_int,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void mcux_rtc_isr(void *arg)
|
|
||||||
{
|
|
||||||
struct device *dev = arg;
|
|
||||||
const struct mcux_rtc_config *config = dev->config->config_info;
|
|
||||||
struct mcux_rtc_data *data = dev->driver_data;
|
|
||||||
|
|
||||||
/* perform any registered callbacks */
|
|
||||||
if (data->callback) {
|
|
||||||
data->callback(data->callback_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Clear any conditions to ack the IRQ
|
|
||||||
*
|
|
||||||
* callback may have already reset the alarm flag if a new
|
|
||||||
* alarm value was programmed to the TAR
|
|
||||||
*/
|
|
||||||
RTC_StopTimer(config->base);
|
|
||||||
if (RTC_GetStatusFlags(config->base) & RTC_SR_TAF_MASK) {
|
|
||||||
RTC_ClearStatusFlags(config->base, kRTC_AlarmFlag);
|
|
||||||
} else if (RTC_GetStatusFlags(config->base) & RTC_SR_TIF_MASK) {
|
|
||||||
RTC_ClearStatusFlags(config->base, kRTC_TimeInvalidFlag);
|
|
||||||
} else if (RTC_GetStatusFlags(config->base) & RTC_SR_TOF_MASK) {
|
|
||||||
RTC_ClearStatusFlags(config->base, kRTC_TimeOverflowFlag);
|
|
||||||
}
|
|
||||||
RTC_StartTimer(config->base);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int mcux_rtc_init(struct device *dev)
|
|
||||||
{
|
|
||||||
const struct mcux_rtc_config *config = dev->config->config_info;
|
|
||||||
struct mcux_rtc_data *data = dev->driver_data;
|
|
||||||
|
|
||||||
k_sem_init(&data->sync, 1, UINT_MAX);
|
|
||||||
|
|
||||||
/* Create default configuration and store it off */
|
|
||||||
RTC_GetDefaultConfig(&data->config);
|
|
||||||
RTC_Init(config->base, &data->config);
|
|
||||||
|
|
||||||
/* Enable 32kHz oscillator and wait for 1ms to settle */
|
|
||||||
config->base->CR |= 0x100;
|
|
||||||
k_busy_wait(USEC_PER_MSEC);
|
|
||||||
|
|
||||||
/* connect and enable the IRQ line */
|
|
||||||
config->irq_config_func(dev);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct mcux_rtc_data rtc_mcux_data_0;
|
|
||||||
|
|
||||||
static void rtc_mcux_irq_config_0(struct device *dev);
|
|
||||||
|
|
||||||
static struct mcux_rtc_config rtc_mcux_config_0 = {
|
|
||||||
.base = (RTC_Type *)DT_RTC_MCUX_0_BASE_ADDRESS,
|
|
||||||
.irq_config_func = rtc_mcux_irq_config_0,
|
|
||||||
};
|
|
||||||
|
|
||||||
DEVICE_DEFINE(rtc, DT_RTC_MCUX_0_NAME,
|
|
||||||
&mcux_rtc_init, NULL, &rtc_mcux_data_0, &rtc_mcux_config_0,
|
|
||||||
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
|
|
||||||
&mcux_rtc_driver_api);
|
|
||||||
|
|
||||||
static void rtc_mcux_irq_config_0(struct device *dev)
|
|
||||||
{
|
|
||||||
IRQ_CONNECT(DT_RTC_MCUX_0_IRQ, DT_RTC_MCUX_0_IRQ_PRI,
|
|
||||||
mcux_rtc_isr, DEVICE_GET(rtc), 0);
|
|
||||||
irq_enable(DT_RTC_MCUX_0_IRQ);
|
|
||||||
}
|
|
|
@ -1,158 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2015 Intel Corporation.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef ZEPHYR_INCLUDE_DRIVERS_RTC_H_
|
|
||||||
#define ZEPHYR_INCLUDE_DRIVERS_RTC_H_
|
|
||||||
#include <zephyr/types.h>
|
|
||||||
#include <device.h>
|
|
||||||
#include <sys/util.h>
|
|
||||||
#include <drivers/counter.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** Number of RTC ticks in a second */
|
|
||||||
#define RTC_ALARM_SECOND (32768 / CONFIG_RTC_PRESCALER)
|
|
||||||
|
|
||||||
/** Number of RTC ticks in a minute */
|
|
||||||
#define RTC_ALARM_MINUTE (RTC_ALARM_SECOND * 60)
|
|
||||||
|
|
||||||
/** Number of RTC ticks in an hour */
|
|
||||||
#define RTC_ALARM_HOUR (RTC_ALARM_MINUTE * 60)
|
|
||||||
|
|
||||||
/** Number of RTC ticks in a day */
|
|
||||||
#define RTC_ALARM_DAY (RTC_ALARM_HOUR * 24)
|
|
||||||
|
|
||||||
typedef void (*rtc_callback_t)(struct device *dev);
|
|
||||||
|
|
||||||
struct rtc_config {
|
|
||||||
u32_t init_val;
|
|
||||||
/*!< enable/disable alarm */
|
|
||||||
u8_t alarm_enable;
|
|
||||||
/*!< initial configuration value for the 32bit RTC alarm value */
|
|
||||||
u32_t alarm_val;
|
|
||||||
/*!< Pointer to function to call when alarm value
|
|
||||||
* matches current RTC value */
|
|
||||||
rtc_callback_t cb_fn;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef void (*rtc_api_enable)(struct device *dev);
|
|
||||||
typedef void (*rtc_api_disable)(struct device *dev);
|
|
||||||
typedef int (*rtc_api_set_config)(struct device *dev,
|
|
||||||
struct rtc_config *config);
|
|
||||||
typedef int (*rtc_api_set_alarm)(struct device *dev,
|
|
||||||
const u32_t alarm_val);
|
|
||||||
typedef u32_t (*rtc_api_read)(struct device *dev);
|
|
||||||
typedef u32_t (*rtc_api_get_pending_int)(struct device *dev);
|
|
||||||
|
|
||||||
struct rtc_driver_api {
|
|
||||||
rtc_api_enable enable;
|
|
||||||
rtc_api_disable disable;
|
|
||||||
rtc_api_read read;
|
|
||||||
rtc_api_set_config set_config;
|
|
||||||
rtc_api_set_alarm set_alarm;
|
|
||||||
rtc_api_get_pending_int get_pending_int;
|
|
||||||
};
|
|
||||||
|
|
||||||
__deprecated __syscall u32_t rtc_read(struct device *dev);
|
|
||||||
|
|
||||||
static inline u32_t z_impl_rtc_read(struct device *dev)
|
|
||||||
{
|
|
||||||
return counter_read(dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
__deprecated __syscall void rtc_enable(struct device *dev);
|
|
||||||
|
|
||||||
static inline void z_impl_rtc_enable(struct device *dev)
|
|
||||||
{
|
|
||||||
counter_start(dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
__deprecated __syscall void rtc_disable(struct device *dev);
|
|
||||||
|
|
||||||
static inline void z_impl_rtc_disable(struct device *dev)
|
|
||||||
{
|
|
||||||
counter_stop(dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void rtc_counter_top_callback(struct device *dev,
|
|
||||||
void *user_data)
|
|
||||||
{
|
|
||||||
rtc_callback_t cb_fn = (rtc_callback_t)user_data;
|
|
||||||
|
|
||||||
if (cb_fn) {
|
|
||||||
cb_fn(dev);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
__deprecated static inline int rtc_set_config(struct device *dev,
|
|
||||||
struct rtc_config *cfg)
|
|
||||||
{
|
|
||||||
struct counter_top_cfg top_cfg = {
|
|
||||||
.ticks = cfg->alarm_val,
|
|
||||||
.callback = rtc_counter_top_callback,
|
|
||||||
.user_data = cfg->cb_fn,
|
|
||||||
.flags = 0
|
|
||||||
};
|
|
||||||
int err;
|
|
||||||
|
|
||||||
if (cfg->init_val) {
|
|
||||||
return -ENOTSUP;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = counter_set_top_value(dev, &top_cfg);
|
|
||||||
|
|
||||||
if (err == 0 && cfg->alarm_enable != 0U) {
|
|
||||||
err = counter_start(dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
__deprecated __syscall int rtc_set_alarm(struct device *dev,
|
|
||||||
const u32_t alarm_val);
|
|
||||||
|
|
||||||
static inline int z_impl_rtc_set_alarm(struct device *dev,
|
|
||||||
const u32_t alarm_val)
|
|
||||||
{
|
|
||||||
struct counter_top_cfg top_cfg = {
|
|
||||||
.ticks = alarm_val,
|
|
||||||
.callback = rtc_counter_top_callback,
|
|
||||||
.user_data = counter_get_user_data(dev),
|
|
||||||
.flags = 0
|
|
||||||
};
|
|
||||||
|
|
||||||
return counter_set_top_value(dev, &top_cfg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Function to get pending interrupts
|
|
||||||
*
|
|
||||||
* The purpose of this function is to return the interrupt
|
|
||||||
* status register for the device.
|
|
||||||
* This is especially useful when waking up from
|
|
||||||
* low power states to check the wake up source.
|
|
||||||
*
|
|
||||||
* @param dev Pointer to the device structure for the driver instance.
|
|
||||||
*
|
|
||||||
* @retval 1 if the rtc interrupt is pending.
|
|
||||||
* @retval 0 if no rtc interrupt is pending.
|
|
||||||
*/
|
|
||||||
__deprecated __syscall int rtc_get_pending_int(struct device *dev);
|
|
||||||
|
|
||||||
static inline int z_impl_rtc_get_pending_int(struct device *dev)
|
|
||||||
{
|
|
||||||
return counter_get_pending_int(dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <syscalls/rtc.h>
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,15 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Intel Corporation
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
#ifndef ZEPHYR_INCLUDE_RTC_H_
|
|
||||||
#define ZEPHYR_INCLUDE_RTC_H_
|
|
||||||
|
|
||||||
#ifndef CONFIG_COMPAT_INCLUDES
|
|
||||||
#warning "This header file has moved, include <drivers/rtc.h> instead."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <drivers/rtc.h>
|
|
||||||
|
|
||||||
#endif /* ZEPHYR_INCLUDE_RTC_H_ */
|
|
|
@ -1,8 +0,0 @@
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.13.1)
|
|
||||||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
|
||||||
project(rtc)
|
|
||||||
|
|
||||||
FILE(GLOB app_sources src/*.c)
|
|
||||||
target_sources(app PRIVATE ${app_sources})
|
|
|
@ -1,2 +0,0 @@
|
||||||
CONFIG_PRINTK=y
|
|
||||||
CONFIG_RTC=y
|
|
|
@ -1,13 +0,0 @@
|
||||||
sample:
|
|
||||||
name: RTC Driver Sample
|
|
||||||
tests:
|
|
||||||
sample.driver.rtc:
|
|
||||||
tags: drivers
|
|
||||||
harness: console
|
|
||||||
harness_config:
|
|
||||||
type: multi_line
|
|
||||||
ordered: true
|
|
||||||
regex:
|
|
||||||
- "Test RTC driver"
|
|
||||||
- "Alarm"
|
|
||||||
depends_on: rtc
|
|
|
@ -1,43 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2015 Intel Corporation
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <zephyr.h>
|
|
||||||
|
|
||||||
#include <device.h>
|
|
||||||
#include <drivers/rtc.h>
|
|
||||||
#include <sys/printk.h>
|
|
||||||
|
|
||||||
#define ALARM (RTC_ALARM_SECOND)
|
|
||||||
|
|
||||||
void test_rtc_interrupt_fn(struct device *rtc_dev)
|
|
||||||
{
|
|
||||||
u32_t now = rtc_read(rtc_dev);
|
|
||||||
|
|
||||||
printk("Alarm\n");
|
|
||||||
rtc_set_alarm(rtc_dev, now + ALARM);
|
|
||||||
}
|
|
||||||
|
|
||||||
void main(void)
|
|
||||||
{
|
|
||||||
struct rtc_config config;
|
|
||||||
struct device *rtc_dev;
|
|
||||||
|
|
||||||
printk("Test RTC driver\n");
|
|
||||||
rtc_dev = device_get_binding(CONFIG_RTC_0_NAME);
|
|
||||||
|
|
||||||
config.init_val = 0U;
|
|
||||||
config.alarm_enable = 1U;
|
|
||||||
config.alarm_val = ALARM;
|
|
||||||
config.cb_fn = test_rtc_interrupt_fn;
|
|
||||||
|
|
||||||
rtc_enable(rtc_dev);
|
|
||||||
|
|
||||||
rtc_set_config(rtc_dev, &config);
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
/* do nothing */
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -107,7 +107,6 @@ subsystems = [
|
||||||
"pinmux_driver_api",
|
"pinmux_driver_api",
|
||||||
"pwm_driver_api",
|
"pwm_driver_api",
|
||||||
"entropy_driver_api",
|
"entropy_driver_api",
|
||||||
"rtc_driver_api",
|
|
||||||
"sensor_driver_api",
|
"sensor_driver_api",
|
||||||
"spi_driver_api",
|
"spi_driver_api",
|
||||||
"uart_driver_api",
|
"uart_driver_api",
|
||||||
|
|
|
@ -84,13 +84,6 @@ config PWM_MCUX_FTM
|
||||||
|
|
||||||
endif # PWM
|
endif # PWM
|
||||||
|
|
||||||
if RTC
|
|
||||||
|
|
||||||
config RTC_MCUX
|
|
||||||
default y
|
|
||||||
|
|
||||||
endif # RTC
|
|
||||||
|
|
||||||
if SERIAL
|
if SERIAL
|
||||||
|
|
||||||
config UART_MCUX_LPUART
|
config UART_MCUX_LPUART
|
||||||
|
|
|
@ -83,8 +83,6 @@
|
||||||
#define DT_I2C_MCUX_3_IRQ_PRI DT_NXP_KINETIS_I2C_400E7000_IRQ_0_PRIORITY
|
#define DT_I2C_MCUX_3_IRQ_PRI DT_NXP_KINETIS_I2C_400E7000_IRQ_0_PRIORITY
|
||||||
#define DT_I2C_MCUX_3_BITRATE DT_NXP_KINETIS_I2C_400E7000_CLOCK_FREQUENCY
|
#define DT_I2C_MCUX_3_BITRATE DT_NXP_KINETIS_I2C_400E7000_CLOCK_FREQUENCY
|
||||||
|
|
||||||
#define CONFIG_RTC_0_NAME DT_NXP_KINETIS_RTC_4003D000_LABEL
|
|
||||||
#define CONFIG_RTC_PRESCALER DT_NXP_KINETIS_RTC_4003D000_PRESCALER
|
|
||||||
#define DT_RTC_0_NAME DT_NXP_KINETIS_RTC_4003D000_LABEL
|
#define DT_RTC_0_NAME DT_NXP_KINETIS_RTC_4003D000_LABEL
|
||||||
#define DT_RTC_MCUX_0_NAME DT_NXP_KINETIS_RTC_4003D000_LABEL
|
#define DT_RTC_MCUX_0_NAME DT_NXP_KINETIS_RTC_4003D000_LABEL
|
||||||
#define DT_RTC_MCUX_0_BASE_ADDRESS DT_NXP_KINETIS_RTC_4003D000_BASE_ADDRESS
|
#define DT_RTC_MCUX_0_BASE_ADDRESS DT_NXP_KINETIS_RTC_4003D000_BASE_ADDRESS
|
||||||
|
|
|
@ -42,13 +42,6 @@ config WDT_MCUX_WDOG32
|
||||||
|
|
||||||
endif # WATCHDOG
|
endif # WATCHDOG
|
||||||
|
|
||||||
if RTC
|
|
||||||
|
|
||||||
config RTC_MCUX
|
|
||||||
default y
|
|
||||||
|
|
||||||
endif # RTC
|
|
||||||
|
|
||||||
if COUNTER
|
if COUNTER
|
||||||
|
|
||||||
config COUNTER_MCUX_RTC
|
config COUNTER_MCUX_RTC
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
#define DT_MCUX_PCC_0_NAME DT_NXP_KINETIS_PCC_40065000_LABEL
|
#define DT_MCUX_PCC_0_NAME DT_NXP_KINETIS_PCC_40065000_LABEL
|
||||||
#define DT_MCUX_PCC_0_BASE_ADDRESS DT_NXP_KINETIS_PCC_40065000_BASE_ADDRESS
|
#define DT_MCUX_PCC_0_BASE_ADDRESS DT_NXP_KINETIS_PCC_40065000_BASE_ADDRESS
|
||||||
|
|
||||||
#define CONFIG_RTC_0_NAME DT_NXP_KINETIS_RTC_4003D000_LABEL
|
|
||||||
#define CONFIG_RTC_PRESCALER DT_NXP_KINETIS_RTC_4003D000_PRESCALER
|
|
||||||
#define DT_RTC_0_NAME DT_NXP_KINETIS_RTC_4003D000_LABEL
|
#define DT_RTC_0_NAME DT_NXP_KINETIS_RTC_4003D000_LABEL
|
||||||
#define DT_RTC_MCUX_0_NAME DT_NXP_KINETIS_RTC_4003D000_LABEL
|
#define DT_RTC_MCUX_0_NAME DT_NXP_KINETIS_RTC_4003D000_LABEL
|
||||||
#define DT_RTC_MCUX_0_BASE_ADDRESS DT_NXP_KINETIS_RTC_4003D000_BASE_ADDRESS
|
#define DT_RTC_MCUX_0_BASE_ADDRESS DT_NXP_KINETIS_RTC_4003D000_BASE_ADDRESS
|
||||||
|
|
|
@ -15,13 +15,6 @@ config NUM_IRQS
|
||||||
int
|
int
|
||||||
default 32
|
default 32
|
||||||
|
|
||||||
if RTC
|
|
||||||
|
|
||||||
config RTC_MCUX
|
|
||||||
default y
|
|
||||||
|
|
||||||
endif # RTC
|
|
||||||
|
|
||||||
if ADC
|
if ADC
|
||||||
|
|
||||||
config ADC_MCUX_ADC16
|
config ADC_MCUX_ADC16
|
||||||
|
|
|
@ -35,8 +35,6 @@
|
||||||
#define DT_RTC_MCUX_0_IRQ_PRI DT_NXP_KINETIS_RTC_4003D000_IRQ_0_PRIORITY
|
#define DT_RTC_MCUX_0_IRQ_PRI DT_NXP_KINETIS_RTC_4003D000_IRQ_0_PRIORITY
|
||||||
#define DT_RTC_MCUX_0_IRQ DT_NXP_KINETIS_RTC_4003D000_IRQ_0
|
#define DT_RTC_MCUX_0_IRQ DT_NXP_KINETIS_RTC_4003D000_IRQ_0
|
||||||
#define DT_RTC_MCUX_0_NAME DT_NXP_KINETIS_RTC_4003D000_LABEL
|
#define DT_RTC_MCUX_0_NAME DT_NXP_KINETIS_RTC_4003D000_LABEL
|
||||||
#define CONFIG_RTC_PRESCALER DT_NXP_KINETIS_RTC_4003D000_PRESCALER
|
|
||||||
#define CONFIG_RTC_0_NAME DT_NXP_KINETIS_RTC_4003D000_LABEL
|
|
||||||
|
|
||||||
#if defined(CONFIG_SOC_MKW22D5) || defined(CONFIG_SOC_MKW24D5)
|
#if defined(CONFIG_SOC_MKW22D5) || defined(CONFIG_SOC_MKW24D5)
|
||||||
#define DT_NUM_IRQ_PRIO_BITS DT_ARM_V7M_NVIC_E000E100_ARM_NUM_IRQ_PRIORITY_BITS
|
#define DT_NUM_IRQ_PRIO_BITS DT_ARM_V7M_NVIC_E000E100_ARM_NUM_IRQ_PRIORITY_BITS
|
||||||
|
|
|
@ -77,13 +77,6 @@ config USB_DC_STM32
|
||||||
|
|
||||||
endif # USB
|
endif # USB
|
||||||
|
|
||||||
if RTC
|
|
||||||
|
|
||||||
config RTC_STM32
|
|
||||||
default y
|
|
||||||
|
|
||||||
endif # RTC
|
|
||||||
|
|
||||||
if COUNTER
|
if COUNTER
|
||||||
|
|
||||||
config COUNTER_RTC_STM32
|
config COUNTER_RTC_STM32
|
||||||
|
|
|
@ -259,9 +259,7 @@
|
||||||
#define DT_RTC_0_BASE_ADDRESS DT_ST_STM32_RTC_40002800_BASE_ADDRESS
|
#define DT_RTC_0_BASE_ADDRESS DT_ST_STM32_RTC_40002800_BASE_ADDRESS
|
||||||
#define DT_RTC_0_IRQ_PRI DT_ST_STM32_RTC_40002800_IRQ_0_PRIORITY
|
#define DT_RTC_0_IRQ_PRI DT_ST_STM32_RTC_40002800_IRQ_0_PRIORITY
|
||||||
#define DT_RTC_0_IRQ DT_ST_STM32_RTC_40002800_IRQ_0
|
#define DT_RTC_0_IRQ DT_ST_STM32_RTC_40002800_IRQ_0
|
||||||
#define CONFIG_RTC_0_NAME DT_ST_STM32_RTC_40002800_LABEL
|
|
||||||
#define DT_RTC_0_NAME DT_ST_STM32_RTC_40002800_LABEL
|
#define DT_RTC_0_NAME DT_ST_STM32_RTC_40002800_LABEL
|
||||||
#define CONFIG_RTC_PRESCALER DT_ST_STM32_RTC_40002800_PRESCALER
|
|
||||||
#define DT_RTC_0_CLOCK_BITS DT_ST_STM32_RTC_40002800_CLOCK_BITS
|
#define DT_RTC_0_CLOCK_BITS DT_ST_STM32_RTC_40002800_CLOCK_BITS
|
||||||
#define DT_RTC_0_CLOCK_BUS DT_ST_STM32_RTC_40002800_CLOCK_BUS
|
#define DT_RTC_0_CLOCK_BUS DT_ST_STM32_RTC_40002800_CLOCK_BUS
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@
|
||||||
#include <stm32f3xx_ll_wwdg.h>
|
#include <stm32f3xx_ll_wwdg.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_RTC_STM32) || defined(CONFIG_COUNTER_RTC_STM32)
|
#if defined(CONFIG_COUNTER_RTC_STM32)
|
||||||
#include <stm32f3xx_ll_rtc.h>
|
#include <stm32f3xx_ll_rtc.h>
|
||||||
#include <stm32f3xx_ll_exti.h>
|
#include <stm32f3xx_ll_exti.h>
|
||||||
#include <stm32f3xx_ll_pwr.h>
|
#include <stm32f3xx_ll_pwr.h>
|
||||||
|
|
|
@ -392,9 +392,7 @@
|
||||||
#define DT_RTC_0_BASE_ADDRESS DT_ST_STM32_RTC_40002800_BASE_ADDRESS
|
#define DT_RTC_0_BASE_ADDRESS DT_ST_STM32_RTC_40002800_BASE_ADDRESS
|
||||||
#define DT_RTC_0_IRQ_PRI DT_ST_STM32_RTC_40002800_IRQ_0_PRIORITY
|
#define DT_RTC_0_IRQ_PRI DT_ST_STM32_RTC_40002800_IRQ_0_PRIORITY
|
||||||
#define DT_RTC_0_IRQ DT_ST_STM32_RTC_40002800_IRQ_0
|
#define DT_RTC_0_IRQ DT_ST_STM32_RTC_40002800_IRQ_0
|
||||||
#define CONFIG_RTC_0_NAME DT_ST_STM32_RTC_40002800_LABEL
|
|
||||||
#define DT_RTC_0_NAME DT_ST_STM32_RTC_40002800_LABEL
|
#define DT_RTC_0_NAME DT_ST_STM32_RTC_40002800_LABEL
|
||||||
#define CONFIG_RTC_PRESCALER DT_ST_STM32_RTC_40002800_PRESCALER
|
|
||||||
#define DT_RTC_0_CLOCK_BITS DT_ST_STM32_RTC_40002800_CLOCK_BITS
|
#define DT_RTC_0_CLOCK_BITS DT_ST_STM32_RTC_40002800_CLOCK_BITS
|
||||||
#define DT_RTC_0_CLOCK_BUS DT_ST_STM32_RTC_40002800_CLOCK_BUS
|
#define DT_RTC_0_CLOCK_BUS DT_ST_STM32_RTC_40002800_CLOCK_BUS
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@
|
||||||
#include <stm32f4xx_ll_wwdg.h>
|
#include <stm32f4xx_ll_wwdg.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_RTC_STM32) || defined(CONFIG_COUNTER_RTC_STM32)
|
#if defined(CONFIG_COUNTER_RTC_STM32)
|
||||||
#include <stm32f4xx_ll_rtc.h>
|
#include <stm32f4xx_ll_rtc.h>
|
||||||
#include <stm32f4xx_ll_exti.h>
|
#include <stm32f4xx_ll_exti.h>
|
||||||
#include <stm32f4xx_ll_pwr.h>
|
#include <stm32f4xx_ll_pwr.h>
|
||||||
|
|
|
@ -368,9 +368,7 @@
|
||||||
#define DT_RTC_0_BASE_ADDRESS DT_ST_STM32_RTC_40002800_BASE_ADDRESS
|
#define DT_RTC_0_BASE_ADDRESS DT_ST_STM32_RTC_40002800_BASE_ADDRESS
|
||||||
#define DT_RTC_0_IRQ_PRI DT_ST_STM32_RTC_40002800_IRQ_0_PRIORITY
|
#define DT_RTC_0_IRQ_PRI DT_ST_STM32_RTC_40002800_IRQ_0_PRIORITY
|
||||||
#define DT_RTC_0_IRQ DT_ST_STM32_RTC_40002800_IRQ_0
|
#define DT_RTC_0_IRQ DT_ST_STM32_RTC_40002800_IRQ_0
|
||||||
#define CONFIG_RTC_0_NAME DT_ST_STM32_RTC_40002800_LABEL
|
|
||||||
#define DT_RTC_0_NAME DT_ST_STM32_RTC_40002800_LABEL
|
#define DT_RTC_0_NAME DT_ST_STM32_RTC_40002800_LABEL
|
||||||
#define CONFIG_RTC_PRESCALER DT_ST_STM32_RTC_40002800_PRESCALER
|
|
||||||
#define DT_RTC_0_CLOCK_BITS DT_ST_STM32_RTC_40002800_CLOCK_BITS
|
#define DT_RTC_0_CLOCK_BITS DT_ST_STM32_RTC_40002800_CLOCK_BITS
|
||||||
#define DT_RTC_0_CLOCK_BUS DT_ST_STM32_RTC_40002800_CLOCK_BUS
|
#define DT_RTC_0_CLOCK_BUS DT_ST_STM32_RTC_40002800_CLOCK_BUS
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@
|
||||||
#include <stm32f7xx_ll_rng.h>
|
#include <stm32f7xx_ll_rng.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_RTC_STM32) || defined(CONFIG_COUNTER_RTC_STM32)
|
#if defined(CONFIG_COUNTER_RTC_STM32)
|
||||||
#include <stm32f7xx_ll_rtc.h>
|
#include <stm32f7xx_ll_rtc.h>
|
||||||
#include <stm32f7xx_ll_exti.h>
|
#include <stm32f7xx_ll_exti.h>
|
||||||
#include <stm32f7xx_ll_pwr.h>
|
#include <stm32f7xx_ll_pwr.h>
|
||||||
|
|
|
@ -182,9 +182,7 @@
|
||||||
#define DT_RTC_0_BASE_ADDRESS DT_ST_STM32_RTC_40002800_BASE_ADDRESS
|
#define DT_RTC_0_BASE_ADDRESS DT_ST_STM32_RTC_40002800_BASE_ADDRESS
|
||||||
#define DT_RTC_0_IRQ_PRI DT_ST_STM32_RTC_40002800_IRQ_0_PRIORITY
|
#define DT_RTC_0_IRQ_PRI DT_ST_STM32_RTC_40002800_IRQ_0_PRIORITY
|
||||||
#define DT_RTC_0_IRQ DT_ST_STM32_RTC_40002800_IRQ_0
|
#define DT_RTC_0_IRQ DT_ST_STM32_RTC_40002800_IRQ_0
|
||||||
#define CONFIG_RTC_0_NAME DT_ST_STM32_RTC_40002800_LABEL
|
|
||||||
#define DT_RTC_0_NAME DT_ST_STM32_RTC_40002800_LABEL
|
#define DT_RTC_0_NAME DT_ST_STM32_RTC_40002800_LABEL
|
||||||
#define CONFIG_RTC_PRESCALER DT_ST_STM32_RTC_40002800_PRESCALER
|
|
||||||
#define DT_RTC_0_CLOCK_BITS DT_ST_STM32_RTC_40002800_CLOCK_BITS
|
#define DT_RTC_0_CLOCK_BITS DT_ST_STM32_RTC_40002800_CLOCK_BITS
|
||||||
#define DT_RTC_0_CLOCK_BUS DT_ST_STM32_RTC_40002800_CLOCK_BUS
|
#define DT_RTC_0_CLOCK_BUS DT_ST_STM32_RTC_40002800_CLOCK_BUS
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@
|
||||||
#include <stm32l4xx_ll_rng.h>
|
#include <stm32l4xx_ll_rng.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_RTC_STM32) || defined(CONFIG_COUNTER_RTC_STM32)
|
#if defined(CONFIG_COUNTER_RTC_STM32)
|
||||||
#include <stm32l4xx_ll_rtc.h>
|
#include <stm32l4xx_ll_rtc.h>
|
||||||
#include <stm32l4xx_ll_exti.h>
|
#include <stm32l4xx_ll_exti.h>
|
||||||
#include <stm32l4xx_ll_pwr.h>
|
#include <stm32l4xx_ll_pwr.h>
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.13.1)
|
|
||||||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
|
||||||
project(rtc_basic_api)
|
|
||||||
|
|
||||||
FILE(GLOB app_sources src/*.c)
|
|
||||||
target_sources(app PRIVATE ${app_sources})
|
|
|
@ -1,2 +0,0 @@
|
||||||
CONFIG_RTC=y
|
|
||||||
CONFIG_ZTEST=y
|
|
|
@ -1,22 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2016 Intel Corporation
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @addtogroup t_driver_rtc
|
|
||||||
* @{
|
|
||||||
* @defgroup t_rtc_basic_api test_rtc_basic_api
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "test_rtc.h"
|
|
||||||
|
|
||||||
void test_main(void)
|
|
||||||
{
|
|
||||||
ztest_test_suite(rtc_basic_test,
|
|
||||||
ztest_unit_test(test_rtc_alarm),
|
|
||||||
ztest_unit_test(test_rtc_calendar));
|
|
||||||
ztest_run_test_suite(rtc_basic_test);
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2016 Intel Corporation
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file
|
|
||||||
* @brief RTC cases header file
|
|
||||||
*
|
|
||||||
* Header file for RTC cases
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __TEST_RTC_H__
|
|
||||||
#define __TEST_RTC_H__
|
|
||||||
|
|
||||||
#include <drivers/rtc.h>
|
|
||||||
#include <zephyr.h>
|
|
||||||
#include <ztest.h>
|
|
||||||
|
|
||||||
#define RTC_DEVICE_NAME CONFIG_RTC_0_NAME
|
|
||||||
|
|
||||||
void test_rtc_calendar(void);
|
|
||||||
void test_rtc_alarm(void);
|
|
||||||
|
|
||||||
#endif /* __TEST_RTC_H__ */
|
|
|
@ -1,116 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2016 Intel Corporation.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @addtogroup t_rtc_basic_api
|
|
||||||
* @{
|
|
||||||
* @defgroup t_rtc_alarm test_rtc_alarm
|
|
||||||
* @brief TestPurpose: verify RTC alarm work and pending interrupt detected
|
|
||||||
* @details
|
|
||||||
* - Test Steps
|
|
||||||
* -# Enable RTC internal counter
|
|
||||||
* -# Configure RTC with init_val, alarm_val, cb_fn and enable RTC alarm
|
|
||||||
* -# Sleep for while waiting for RTC alarm
|
|
||||||
* -# Reconfigure RTC to alarm 1 second later using rtc_set_alarm()
|
|
||||||
* -# Sleep for while waiting for RTC alarm
|
|
||||||
* -# Disable RTC internal counter and repeat previous operations
|
|
||||||
* - Expected Results
|
|
||||||
* -# When RTC internal counter is enabled, RTC alarm can be invoked using
|
|
||||||
* both rtc_set_config() and rtc_set_alarm()
|
|
||||||
* -# When RTC internal counter is disabled, RTC alarm won't be invoked.
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "test_rtc.h"
|
|
||||||
|
|
||||||
static bool rtc_alarm_up;
|
|
||||||
|
|
||||||
static void rtc_alarm_callback(struct device *rtc_dev)
|
|
||||||
{
|
|
||||||
|
|
||||||
TC_PRINT("%s: Invoked\n", __func__);
|
|
||||||
TC_PRINT("RTC counter: %u\n", rtc_read(rtc_dev));
|
|
||||||
|
|
||||||
/* Verify rtc_get_pending_int() */
|
|
||||||
if (rtc_get_pending_int(rtc_dev)) {
|
|
||||||
TC_PRINT("Catch pending RTC interrupt\n");
|
|
||||||
} else {
|
|
||||||
TC_PRINT("Fail to catch pending RTC interrupt\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
rtc_alarm_up = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int test_alarm(void)
|
|
||||||
{
|
|
||||||
struct rtc_config config;
|
|
||||||
struct device *rtc = device_get_binding(RTC_DEVICE_NAME);
|
|
||||||
|
|
||||||
if (!rtc) {
|
|
||||||
TC_PRINT("Cannot get RTC device\n");
|
|
||||||
return TC_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
config.init_val = 0U;
|
|
||||||
config.alarm_enable = 1U;
|
|
||||||
config.alarm_val = RTC_ALARM_SECOND;
|
|
||||||
config.cb_fn = rtc_alarm_callback;
|
|
||||||
|
|
||||||
rtc_enable(rtc);
|
|
||||||
|
|
||||||
/* 1. Verify rtc_set_config() */
|
|
||||||
rtc_alarm_up = false;
|
|
||||||
if (rtc_set_config(rtc, &config)) {
|
|
||||||
TC_ERROR("Failed to config RTC alarm\n");
|
|
||||||
return TC_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
k_sleep(2000);
|
|
||||||
|
|
||||||
if (!rtc_alarm_up) {
|
|
||||||
TC_PRINT("RTC alarm doesn't work well\n");
|
|
||||||
return TC_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 2. Verify rtc_set_alarm() */
|
|
||||||
rtc_alarm_up = false;
|
|
||||||
if (rtc_set_alarm(rtc, rtc_read(rtc) + RTC_ALARM_SECOND)) {
|
|
||||||
TC_PRINT("Failed to set RTC Alarm\n");
|
|
||||||
return TC_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
k_sleep(2000);
|
|
||||||
|
|
||||||
if (!rtc_alarm_up) {
|
|
||||||
TC_PRINT("RTC alarm doesn't work well\n");
|
|
||||||
return TC_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 3. Verify RTC Alarm disabled after disable internal counter */
|
|
||||||
rtc_disable(rtc);
|
|
||||||
rtc_alarm_up = false;
|
|
||||||
|
|
||||||
if (rtc_set_alarm(rtc, rtc_read(rtc) + RTC_ALARM_SECOND)) {
|
|
||||||
TC_PRINT("Failed to set RTC Alarm\n");
|
|
||||||
return TC_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
k_sleep(1500);
|
|
||||||
|
|
||||||
if (rtc_alarm_up) {
|
|
||||||
TC_PRINT("Failed to disable RTC Alarm\n");
|
|
||||||
return TC_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
TC_PRINT("RTC alarm works well\n");
|
|
||||||
|
|
||||||
return TC_PASS;
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_rtc_alarm(void)
|
|
||||||
{
|
|
||||||
zassert_true(test_alarm() == TC_PASS, NULL);
|
|
||||||
}
|
|
|
@ -1,73 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2016 Intel Corporation.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @addtogroup t_rtc_basic_api
|
|
||||||
* @{
|
|
||||||
* @defgroup t_rtc_calendar test_rtc_calendar
|
|
||||||
* @brief TestPurpose: verify RTC internal counter enable/disable/read work
|
|
||||||
* @details
|
|
||||||
* - Test Steps
|
|
||||||
* -# Enable RTC internal counter
|
|
||||||
* -# Read RTC internal counter and sleep for a while
|
|
||||||
* -# Read RTC internal counter again and compare it with the previous value
|
|
||||||
* -# Disable RTC internal counter and repeat previous operations
|
|
||||||
* - Expected Results
|
|
||||||
* -# When enabled, the values read from RTC internal counter increase.
|
|
||||||
* -# When disabled, the values read from RTC internal counter don't change.
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "test_rtc.h"
|
|
||||||
|
|
||||||
static int test_task(void)
|
|
||||||
{
|
|
||||||
u32_t val_1 = 0U;
|
|
||||||
u32_t val_2 = 0U;
|
|
||||||
struct device *rtc = device_get_binding(RTC_DEVICE_NAME);
|
|
||||||
|
|
||||||
if (!rtc) {
|
|
||||||
TC_PRINT("Cannot get RTC device\n");
|
|
||||||
return TC_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 1. Verify rtc_enable() */
|
|
||||||
rtc_enable(rtc);
|
|
||||||
|
|
||||||
/* 2. Verify rtc_enable() */
|
|
||||||
val_1 = rtc_read(rtc);
|
|
||||||
k_sleep(2000);
|
|
||||||
val_2 = rtc_read(rtc);
|
|
||||||
|
|
||||||
TC_PRINT("val_1: %u, val_2: %u, delta: %u:%u\n",
|
|
||||||
val_1, val_2,
|
|
||||||
(val_2 - val_1) / RTC_ALARM_SECOND,
|
|
||||||
(val_2 - val_1) % RTC_ALARM_SECOND);
|
|
||||||
|
|
||||||
if (val_2 <= val_1) {
|
|
||||||
TC_PRINT("RTC doesn't work well\n");
|
|
||||||
return TC_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 3. Verify rtc_disable() */
|
|
||||||
rtc_disable(rtc);
|
|
||||||
|
|
||||||
val_1 = rtc_read(rtc);
|
|
||||||
k_sleep(1000);
|
|
||||||
val_2 = rtc_read(rtc);
|
|
||||||
|
|
||||||
if (val_2 != val_1) {
|
|
||||||
TC_PRINT("Fail to disable RTC\n");
|
|
||||||
return TC_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TC_PASS;
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_rtc_calendar(void)
|
|
||||||
{
|
|
||||||
zassert_true((test_task() == TC_PASS), NULL);
|
|
||||||
}
|
|
|
@ -1,4 +0,0 @@
|
||||||
tests:
|
|
||||||
peripheral.rtc:
|
|
||||||
tags: drivers
|
|
||||||
depends_on: rtc
|
|
Loading…
Add table
Add a link
Reference in a new issue