RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
+ RTC 的协作图:

结构体

struct  rt_rtc_wkalarm
 
struct  rt_rtc_ops
 
struct  rt_rtc_device
 

宏定义

#define RT_DEVICE_CTRL_RTC_GET_TIME   (RT_DEVICE_CTRL_BASE(RTC) + 0x01)
 
#define RT_DEVICE_CTRL_RTC_SET_TIME   (RT_DEVICE_CTRL_BASE(RTC) + 0x02)
 
#define RT_DEVICE_CTRL_RTC_GET_TIMEVAL   (RT_DEVICE_CTRL_BASE(RTC) + 0x03)
 
#define RT_DEVICE_CTRL_RTC_SET_TIMEVAL   (RT_DEVICE_CTRL_BASE(RTC) + 0x04)
 
#define RT_DEVICE_CTRL_RTC_GET_ALARM   (RT_DEVICE_CTRL_BASE(RTC) + 0x05)
 
#define RT_DEVICE_CTRL_RTC_SET_ALARM   (RT_DEVICE_CTRL_BASE(RTC) + 0x06)
 
#define RT_DEVICE_CTRL_RTC_GET_TIMESPEC   (RT_DEVICE_CTRL_BASE(RTC) + 0x07)
 
#define RT_DEVICE_CTRL_RTC_SET_TIMESPEC   (RT_DEVICE_CTRL_BASE(RTC) + 0x08)
 
#define RT_DEVICE_CTRL_RTC_GET_TIMERES   (RT_DEVICE_CTRL_BASE(RTC) + 0x09)
 

类型定义

typedef struct rt_rtc_device rt_rtc_dev_t
 

函数

rt_err_t rt_hw_rtc_register (rt_rtc_dev_t *rtc, const char *name, rt_uint32_t flag, void *data)
 
rt_err_t set_date (rt_uint32_t year, rt_uint32_t month, rt_uint32_t day)
 
rt_err_t set_time (rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t second)
 
rt_err_t set_timestamp (time_t timestamp)
 
rt_err_t get_timestamp (time_t *timestamp)
 

详细描述

RTC driver api

Example

#include <rtthread.h>
#include <rtdevice.h>
#define RTC_NAME "rtc"
static int rtc_sample(int argc, char *argv[])
{
rt_err_t ret = RT_EOK;
time_t now;
rt_device_t device = RT_NULL;
device = rt_device_find(RTC_NAME);
if (!device)
{
LOG_E("find %s failed!", RTC_NAME);
return RT_ERROR;
}
if(rt_device_open(device, 0) != RT_EOK)
{
LOG_E("open %s failed!", RTC_NAME);
return RT_ERROR;
}
ret = set_date(2018, 12, 3);
if (ret != RT_EOK)
{
rt_kprintf("set RTC date failed\n");
return ret;
}
ret = set_time(11, 15, 50);
if (ret != RT_EOK)
{
rt_kprintf("set RTC time failed\n");
return ret;
}
now = time(RT_NULL);
rt_kprintf("%s\n", ctime(&now));
return ret;
}
MSH_CMD_EXPORT(rtc_sample, rtc sample);
rt_device_t rt_device_find(const char *name)
struct rt_device * rt_device_t
rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
#define rt_kprintf(...)
rt_err_t set_date(rt_uint32_t year, rt_uint32_t month, rt_uint32_t day)
set date
rt_err_t set_time(rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t second)
set time
rt_err_t rt_thread_mdelay(rt_int32_t ms)
This function will let current thread delay for some milliseconds.
#define MSH_CMD_EXPORT(...)
#define LOG_E(fmt,...)
rt_base_t rt_err_t
#define RT_NULL

宏定义说明

◆ RT_DEVICE_CTRL_RTC_GET_TIME

#define RT_DEVICE_CTRL_RTC_GET_TIME   (RT_DEVICE_CTRL_BASE(RTC) + 0x01)

get second time

在文件 dev_rtc.h87 行定义.

◆ RT_DEVICE_CTRL_RTC_SET_TIME

#define RT_DEVICE_CTRL_RTC_SET_TIME   (RT_DEVICE_CTRL_BASE(RTC) + 0x02)

set second time

在文件 dev_rtc.h88 行定义.

◆ RT_DEVICE_CTRL_RTC_GET_TIMEVAL

#define RT_DEVICE_CTRL_RTC_GET_TIMEVAL   (RT_DEVICE_CTRL_BASE(RTC) + 0x03)

get timeval for gettimeofday

在文件 dev_rtc.h89 行定义.

◆ RT_DEVICE_CTRL_RTC_SET_TIMEVAL

#define RT_DEVICE_CTRL_RTC_SET_TIMEVAL   (RT_DEVICE_CTRL_BASE(RTC) + 0x04)

set timeval for gettimeofday

在文件 dev_rtc.h90 行定义.

◆ RT_DEVICE_CTRL_RTC_GET_ALARM

#define RT_DEVICE_CTRL_RTC_GET_ALARM   (RT_DEVICE_CTRL_BASE(RTC) + 0x05)

get alarm

在文件 dev_rtc.h91 行定义.

◆ RT_DEVICE_CTRL_RTC_SET_ALARM

#define RT_DEVICE_CTRL_RTC_SET_ALARM   (RT_DEVICE_CTRL_BASE(RTC) + 0x06)

set alarm

在文件 dev_rtc.h92 行定义.

◆ RT_DEVICE_CTRL_RTC_GET_TIMESPEC

#define RT_DEVICE_CTRL_RTC_GET_TIMESPEC   (RT_DEVICE_CTRL_BASE(RTC) + 0x07)

get timespec for clock_gettime

在文件 dev_rtc.h93 行定义.

◆ RT_DEVICE_CTRL_RTC_SET_TIMESPEC

#define RT_DEVICE_CTRL_RTC_SET_TIMESPEC   (RT_DEVICE_CTRL_BASE(RTC) + 0x08)

set timespec for clock_settime

在文件 dev_rtc.h94 行定义.

◆ RT_DEVICE_CTRL_RTC_GET_TIMERES

#define RT_DEVICE_CTRL_RTC_GET_TIMERES   (RT_DEVICE_CTRL_BASE(RTC) + 0x09)

get resolution for clock_getres

在文件 dev_rtc.h95 行定义.

类型定义说明

◆ rt_rtc_dev_t

typedef struct rt_rtc_device rt_rtc_dev_t

RTC device structure

函数说明

◆ rt_hw_rtc_register()

rt_err_t rt_hw_rtc_register ( rt_rtc_dev_t * rtc,
const char * name,
rt_uint32_t flag,
void * data )

Register a RTC device

参数
rtcRTC device
nameRTC device name
flagRTC device flag
dataRTC device data
返回
rt_err_t error code

◆ set_date()

rt_err_t set_date ( rt_uint32_t year,
rt_uint32_t month,
rt_uint32_t day )

set date

参数
yearyear
monthmonth
dayday
返回
rt_err_t error code

◆ set_time()

rt_err_t set_time ( rt_uint32_t hour,
rt_uint32_t minute,
rt_uint32_t second )

set time

参数
hourhour
minuteminute
secondsecond
返回
rt_err_t error code

◆ set_timestamp()

rt_err_t set_timestamp ( time_t timestamp)

set timestamp

参数
timestampA pointer to time
返回
rt_err_t error code

◆ get_timestamp()

rt_err_t get_timestamp ( time_t * timestamp)

get timestamp

参数
timestampA secondary pointer to time
返回
rt_err_t error code