Add RTC functionality

This commit is contained in:
rcitach
2026-07-01 12:25:19 +08:00
committed by Rbb666
parent a9917f1572
commit e1b3a192f6
9 changed files with 939 additions and 1 deletions
@@ -41,6 +41,9 @@ if GetDepend('BSP_USING_EPWM'):
if GetDepend('BSP_USING_I2C'):
src += ['drv_i2c.c']
if GetDepend('BSP_USING_RTC'):
src += ['drv_rtc.c']
group = DefineGroup('HAL_Drivers', src, depend = [''], CPPPATH = path)
Return('group')
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2006-2026, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#ifndef __DRV_RTC_H__
#define __DRV_RTC_H__
#include <rtthread.h>
#include <time.h>
#ifdef __cplusplus
extern "C" {
#endif
struct ns800_rtc_ops
{
rt_err_t (*init)(void *user_data);
rt_err_t (*get_time)(void *user_data, struct tm *time);
rt_err_t (*set_time)(void *user_data, const struct tm *time);
};
rt_err_t ns800_rtc_register(const char *name,
const struct ns800_rtc_ops *ops,
void *user_data);
int rt_hw_rtc_init(void);
#ifdef __cplusplus
}
#endif
#endif /* __DRV_RTC_H__ */
@@ -184,6 +184,70 @@ menu "On-chip Peripheral Drivers"
endif
menuconfig BSP_USING_RTC
bool "Enable external RTC"
select RT_USING_RTC
default n
help
Enable the board-level RTC framework for an external RTC chip.
if BSP_USING_RTC
choice
prompt "External RTC backend"
default BSP_RTC_USING_DS1307
config BSP_RTC_USING_DS1307
bool "DS1307 over I2C"
select BSP_USING_I2C
select BSP_USING_HARD_I2C1
select RT_USING_I2C
config BSP_RTC_USING_SOFT
bool "Software RTC"
endchoice
if BSP_RTC_USING_DS1307
config BSP_RTC_DS1307_I2C_BUS_NAME
string "DS1307 I2C bus name"
default "hwi2c1"
config BSP_RTC_DS1307_I2C_ADDR
hex "DS1307 I2C address"
default 0x68
endif
if BSP_RTC_USING_SOFT
config BSP_RTC_SOFT_DEFAULT_YEAR
int "Software RTC default year"
default 2026
config BSP_RTC_SOFT_DEFAULT_MONTH
int "Software RTC default month"
range 1 12
default 1
config BSP_RTC_SOFT_DEFAULT_DAY
int "Software RTC default day"
range 1 31
default 1
config BSP_RTC_SOFT_DEFAULT_HOUR
int "Software RTC default hour"
range 0 23
default 0
config BSP_RTC_SOFT_DEFAULT_MIN
int "Software RTC default minute"
range 0 59
default 0
config BSP_RTC_SOFT_DEFAULT_SEC
int "Software RTC default second"
range 0 59
default 0
endif
endif
menuconfig BSP_USING_SPI
bool "Enable SPI"
select RT_USING_SPI
@@ -3,7 +3,13 @@ from building import *
cwd = GetCurrentDir()
src = ['board.c']
path = [cwd]
path = [cwd, cwd + '/port']
if GetDepend('BSP_RTC_USING_DS1307'):
src += ['port/ds1307.c']
if GetDepend('BSP_RTC_USING_SOFT'):
src += ['port/soft_rtc.c']
cppdefines = ['NS800RT7P65X', 'USE_HAL_DRIVER', 'DUAL_CORE_ENABLE=0',
'SYSCLK_USE_PLL', 'SYSCLK_SOURCE_USE_HXTL', 'PLLCLK_SOURCE_USE_HXTL']
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2006-2026, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2026-06-24 wenzhi346 first version
*/
#ifndef __DS1307_H__
#define __DS1307_H__
#include <rtthread.h>
#include <time.h>
rt_err_t ds1307_init(void);
rt_err_t ds1307_get_time(struct tm *time);
rt_err_t ds1307_set_time(const struct tm *time);
int rt_hw_ds1307_init(void);
#endif
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2006-2026, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2026-06-30 rcitach first version
*/
#ifndef __SOFT_RTC_H__
#define __SOFT_RTC_H__
#include <rtthread.h>
#include <time.h>
rt_err_t soft_rtc_init(void);
rt_err_t soft_rtc_get_time(struct tm *time);
rt_err_t soft_rtc_set_time(const struct tm *time);
int rt_hw_soft_rtc_init(void);
#endif /* __SOFT_RTC_H__ */