MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rtc_sample

Function rtc_sample

bsp/hc32/tests/test_rtc.c:76–263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74#endif /* RT_USING_ALARM */
75
76static int rtc_sample(int argc, char *argv[])
77{
78 rt_uint8_t idx;
79 rt_uint16_t temp1, temp2, temp3;
80 time_t now;
81#if defined(RT_USING_ALARM)
82 struct tm p_tm;
83#endif
84
85 if (argc < 2)
86 {
87 rt_kprintf("unkown rtc command, rtc [usage] as the following: \n");
88 rt_kprintf("\'0\': find and open rtc \n");
89 rt_kprintf("\'1 xx:xx:xx\': set time with \n");
90 rt_kprintf("\'2 xxxx-xx-xx\': set date with \n");
91 rt_kprintf("\'3\': get time and date \n");
92#if defined(RT_USING_ALARM)
93 rt_kprintf("\'4\': set current time + 10s as alarm \n");
94 rt_kprintf("\'5\': start alarm \n");
95 rt_kprintf("\'6\': stop alarm \n");
96 rt_kprintf("cmd-7 based on cmd-4\n");
97 rt_kprintf("\'7\' o: oneshot,\n\'7\' s: second,\n\'7\' m: minute \n");
98 rt_kprintf("\'8\': dump all alarm \n");
99 rt_kprintf("\'9\': delete all alarm \n");
100#endif /* RT_USING_ALARM */
101 return -RT_ERROR;
102 }
103
104 idx = *(argv[1]) - '0';
105 switch (idx)
106 {
107 case CMD_OPEN_RTC:
108 /* find and open device with standard interface */
109 rtc_dev = rt_device_find(SAMPLE_RTC_NAME);
110 if (!rtc_dev)
111 {
112 rt_kprintf("find %s failed\n", SAMPLE_RTC_NAME);
113 return -RT_ERROR;
114 }
115 if (RT_EOK != rt_device_open(rtc_dev, RT_NULL))
116 {
117 rt_kprintf("failed to open %s\n", SAMPLE_RTC_NAME);
118 return -RT_ERROR;
119 }
120 rt_kprintf("rtc opened\n");
121 break;
122 case CMD_SET_TIME:
123 /* set time with xx:xx:xx format characters */
124 if (argc < 3)
125 {
126 rt_kprintf("unsurpported command\n");
127 return -RT_ERROR;
128 }
129 temp1 = ((argv[2][0] - '0') * 10) + \
130 (argv[2][1] - '0');
131 temp2 = ((argv[2][3] - '0') * 10) + \
132 (argv[2][4] - '0');
133 temp3 = ((argv[2][6] - '0') * 10) + \

Callers

nothing calls this directly

Calls 15

rt_kprintfFunction · 0.85
rt_device_findFunction · 0.85
rt_device_openFunction · 0.85
set_timeFunction · 0.85
set_dateFunction · 0.85
timeFunction · 0.85
ctimeFunction · 0.85
rt_alarm_createFunction · 0.85
rt_alarm_dumpFunction · 0.85
rt_alarm_startFunction · 0.85
rt_alarm_stopFunction · 0.85
rt_alarm_controlFunction · 0.85

Tested by

no test coverage detected