rt-thread-official/examples/test/rtc_test.c

62 lines
1.3 KiB
C
Raw Normal View History

/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-01-15 Liu2guang the first version.
*/
2021-03-07 08:34:04 +08:00
#include <rtthread.h>
#include <rtdevice.h>
int rtc_test(void)
2021-03-07 08:34:04 +08:00
{
uint8_t i;
time_t now;
2021-03-07 08:34:04 +08:00
rt_err_t ret = RT_EOK;
rt_kprintf("[RTC Test]RTC Test Start...\n");
rt_thread_delay(RT_TICK_PER_SECOND);
2021-07-06 18:03:12 +08:00
rt_kprintf("[RTC Test]Set RTC 2017-04-01 12:30:46\n");
rt_thread_delay(RT_TICK_PER_SECOND);
2021-03-07 08:34:04 +08:00
ret = set_date(2017, 4, 1);
if(ret != RT_EOK)
{
2021-03-07 08:34:04 +08:00
rt_kprintf("[RTC Test]Set RTC Date failed\n");
return RT_ERROR;
}
2021-03-07 08:34:04 +08:00
rt_thread_delay(RT_TICK_PER_SECOND);
2021-03-07 08:34:04 +08:00
ret = set_time(12, 30, 46);
if(ret != RT_EOK)
{
2021-03-07 08:34:04 +08:00
rt_kprintf("[RTC Test]Set RTC Time failed\n");
return RT_ERROR;
}
2021-03-07 08:34:04 +08:00
rt_thread_delay(RT_TICK_PER_SECOND);
2021-03-07 08:34:04 +08:00
for(i = 0; i < 10; i++)
{
2021-03-07 08:34:04 +08:00
rt_kprintf("[RTC Test]Read RTC Date and Time: ");
now = time(RT_NULL);
2021-07-06 18:03:12 +08:00
rt_kprintf("%s\n", ctime(&now));
2021-03-07 08:34:04 +08:00
rt_thread_delay(RT_TICK_PER_SECOND);
}
2021-03-07 08:34:04 +08:00
rt_kprintf("\n");
return RT_EOK;
}
#ifdef RT_USING_FINSH
#include <finsh.h>
2021-07-06 18:03:12 +08:00
FINSH_FUNCTION_EXPORT(rtc_test, rtc driver test. e.g: rtc_test());
MSH_CMD_EXPORT(rtc_test, rtc driver test. e.g: rtc_test());
#endif