1 /*
2 * File : rtc_test.c
3 * This file is part of RT-Thread RTOS
4 * COPYRIGHT (C) 2017, RT-Thread Development Team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Change Logs:
21 * Date Author Notes
22 * 2018-01-15 Liu2guang the first version.
23 */
24 #include <rtthread.h>
25 #include <rtdevice.h>
26
rtc_test(void)27 int rtc_test(void)
28 {
29 uint8_t i;
30 time_t now;
31
32 rt_err_t ret = RT_EOK;
33
34 rt_kprintf("[RTC Test]RTC Test Start...\n");
35 rt_thread_delay(RT_TICK_PER_SECOND);
36 rt_kprintf("[RTC Test]Set RTC 2017-04-01 12:30:46\n\n");
37 rt_thread_delay(RT_TICK_PER_SECOND);
38
39 ret = set_date(2017, 4, 1);
40 if(ret != RT_EOK)
41 {
42 rt_kprintf("[RTC Test]Set RTC Date failed\n");
43 return RT_ERROR;
44 }
45
46 rt_thread_delay(RT_TICK_PER_SECOND);
47
48 ret = set_time(12, 30, 46);
49 if(ret != RT_EOK)
50 {
51 rt_kprintf("[RTC Test]Set RTC Time failed\n");
52 return RT_ERROR;
53 }
54
55 rt_thread_delay(RT_TICK_PER_SECOND);
56
57 for(i = 0; i < 10; i++)
58 {
59 rt_kprintf("[RTC Test]Read RTC Date and Time: ");
60 now = time(RT_NULL);
61 rt_kprintf("%s", ctime(&now));
62
63 rt_thread_delay(RT_TICK_PER_SECOND);
64 }
65
66 rt_kprintf("\n");
67
68 return RT_EOK;
69 }
70 #ifdef RT_USING_FINSH
71 #include <finsh.h>
72 FINSH_FUNCTION_EXPORT(rtc_test, rtc drive test. e.g: rtc_test());
73 MSH_CMD_EXPORT(rtc_test, rtc drive test. e.g: rtc_test());
74 #endif
75