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