[dm][rtc] update rtc and new drivers (#11033)

* [dd][rtc] set the RTC alarm thread stack size default.

Signed-off-by: GuEe-GUI <2991707448@qq.com>

* [dm][rtc] make Kconfig import for DM

Signed-off-by: GuEe-GUI <2991707448@qq.com>

* [dm][rtc] support DM API for RTC

1. rtc_dev_set_name for RTC device init the name auto.
2. rtc_wkalarm_to_timestamp and rtc_timestamp_to_wkalarm for
   rt_rtc_wkalarm/time_t convert.

Signed-off-by: GuEe-GUI <2991707448@qq.com>

* [dm][rtc] add new drivers

1. Dallas/Maxim DS1302
2. Dallas/Maxim DS1307/37/38/39/40, ST M41T11
3. Goldfish Real Time Clock
4. Haoyu Microelectronics HYM8563
5. NXP PCF8523
6. Philips PCF8563/Epson RTC8564
7. ARM PL031
8. Epson RX8010SJ

Signed-off-by: GuEe-GUI <2991707448@qq.com>

---------

Signed-off-by: GuEe-GUI <2991707448@qq.com>
This commit is contained in:
GUI
2025-12-10 17:03:20 +08:00
committed by GitHub
parent 3ff3fc3948
commit e465ec567d
12 changed files with 4250 additions and 2 deletions
+60 -2
View File
@@ -1,4 +1,4 @@
config RT_USING_RTC
menuconfig RT_USING_RTC
bool "Using RTC device drivers"
default n
@@ -10,7 +10,7 @@ config RT_USING_RTC
if RT_USING_ALARM
config RT_ALARM_STACK_SIZE
int "stack size for alarm thread"
default 2048
default IDLE_THREAD_STACK_SIZE
config RT_ALARM_TIMESLICE
int "timeslice for alarm thread"
@@ -30,3 +30,61 @@ config RT_USING_RTC
bool "Using software simulation RTC device"
default n
endif
config RT_RTC_DS1302
bool "Dallas/Maxim DS1302"
depends on RT_USING_DM
depends on RT_USING_RTC
depends on RT_USING_SPI
default n
config RT_RTC_DS1307
bool "Dallas/Maxim DS1307/37/38/39/40, ST M41T11"
depends on RT_USING_DM
depends on RT_USING_RTC
depends on RT_USING_I2C
default n
config RT_RTC_GOLDFISH
bool "Goldfish Real Time Clock"
depends on RT_USING_DM
depends on RT_USING_RTC
default n
config RT_RTC_HYM8563
bool "Haoyu Microelectronics HYM8563"
depends on RT_USING_DM
depends on RT_USING_RTC
depends on RT_USING_I2C
default n
config RT_RTC_PCF8523
bool "NXP PCF8523"
depends on RT_USING_DM
depends on RT_USING_RTC
depends on RT_USING_I2C
default n
config RT_RTC_PCF8563
bool "Philips PCF8563/Epson RTC8564"
depends on RT_USING_DM
depends on RT_USING_RTC
depends on RT_USING_I2C
default n
config RT_RTC_PL031
bool "ARM PL031"
depends on RT_USING_DM
depends on RT_USING_RTC
default n
config RT_RTC_RX8010
bool "Epson RX8010SJ"
depends on RT_USING_DM
depends on RT_USING_RTC
depends on RT_USING_I2C
default n
if RT_USING_DM && RT_USING_RTC
osource "$(SOC_DM_RTC_DIR)/Kconfig"
endif
+27
View File
@@ -13,6 +13,33 @@ if GetDepend(['RT_USING_RTC']):
if GetDepend(['RT_USING_SOFT_RTC']):
src = src + ['dev_soft_rtc.c']
if GetDepend(['RT_USING_DM']):
src += ['rtc_dm.c']
if GetDepend(['RT_RTC_DS1302']):
src += ['rtc-ds1302.c']
if GetDepend(['RT_RTC_DS1307']):
src += ['rtc-ds1307.c']
if GetDepend(['RT_RTC_GOLDFISH']):
src += ['rtc-goldfish.c']
if GetDepend(['RT_RTC_HYM8563']):
src += ['rtc-hym8563.c']
if GetDepend(['RT_RTC_PCF8523']):
src += ['rtc-pcf8523.c']
if GetDepend(['RT_RTC_PCF8563']):
src += ['rtc-pcf8563.c']
if GetDepend(['RT_RTC_PL031']):
src += ['rtc-pl031.c']
if GetDepend(['RT_RTC_RX8010']):
src += ['rtc-rx8010.c']
group = DefineGroup('DeviceDrivers', src, depend = ['RT_USING_RTC'], CPPPATH = CPPPATH)
Return('group')
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+61
View File
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-12-06 GuEe-GUI first version
*/
#include <rtatomic.h>
#include "rtc_dm.h"
#define DBG_TAG "rtc.dm"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
int rtc_dev_set_name(struct rt_device *rtc_dev)
{
int id;
static volatile rt_atomic_t uid = 1;
RT_ASSERT(rtc_dev != RT_NULL)
if (rt_device_find("rtc"))
{
id = (int)rt_atomic_add(&uid, 1);
return rt_dm_dev_set_name(rtc_dev, "rtc%u", id);
}
else
{
return rt_dm_dev_set_name(rtc_dev, "rtc");
}
}
time_t rtc_wkalarm_to_timestamp(struct rt_rtc_wkalarm *alarm)
{
struct tm tm_time;
time_t current_time;
current_time = time(RT_NULL);
localtime_r(&current_time, &tm_time);
tm_time.tm_sec = alarm->tm_sec;
tm_time.tm_min = alarm->tm_min;
tm_time.tm_hour = alarm->tm_hour;
return timegm(&tm_time);
}
void rtc_timestamp_to_wkalarm(time_t timestamp, struct rt_rtc_wkalarm *alarm)
{
struct tm tm_time;
localtime_r(&timestamp, &tm_time);
alarm->tm_sec = tm_time.tm_sec;
alarm->tm_min = tm_time.tm_min;
alarm->tm_hour = tm_time.tm_hour;
}
+24
View File
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-12-06 GuEe-GUI first version
*/
#ifndef __RTC_DM_H__
#define __RTC_DM_H__
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <sys/time.h>
int rtc_dev_set_name(struct rt_device *rtc_dev);
time_t rtc_wkalarm_to_timestamp(struct rt_rtc_wkalarm *alarm);
void rtc_timestamp_to_wkalarm(time_t timestamp, struct rt_rtc_wkalarm *alarm);
#endif /* __RTC_DM_H__ */