rt-thread-official/bsp/essemi/es32f369x/drivers/bsp_driver_example/rtc_sample.c

56 lines
1.2 KiB
C
Raw Normal View History

2020-12-16 16:31:01 +08:00
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-30 misonyo first implementation.
*/
/*
* RTC 使
* rtc_sample
* rtc_sample
* RTC设备的日期和时间
*/
#include <rtthread.h>
#include <rtdevice.h>
#ifdef RT_USING_RTC
2020-12-16 16:31:01 +08:00
static int rtc_sample(int argc, char *argv[])
{
rt_err_t ret = RT_EOK;
time_t now;
/* 设置日期 */
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;
}
/* 延时3秒 */
rt_thread_mdelay(3000);
2020-12-16 16:31:01 +08:00
/* 获取时间 */
now = time(RT_NULL);
rt_kprintf("%s\n", ctime(&now));
return ret;
}
/* 导出到 msh 命令列表中 */
MSH_CMD_EXPORT(rtc_sample, rtc sample);
#endif