| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- /* Copyright Canaan Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #include <rtthread.h>
- #include <rtdevice.h>
- static rt_device_t rtc_dev;
- static int rtc_sample(int argc, char *argv[])
- {
- rt_err_t ret = RT_EOK;
- time_t now;
- rtc_dev = rt_device_find("rtc");
- /* 设置日期 */
- ret = set_date(2022, 7, 15);
- if (ret != RT_EOK)
- {
- rt_kprintf("set RTC date failed\n");
- return ret;
- }
- /* 设置时间 */
- ret = set_time(16, 15, 50);
- if (ret != RT_EOK)
- {
- rt_kprintf("set RTC time failed\n");
- return ret;
- }
- /* 延时3秒 */
- rt_thread_mdelay(3000);
- /* 获取时间 */
- now = time(RT_NULL);
- //ret = rt_device_control(rtc_dev, RT_DEVICE_CTRL_RTC_GET_TIME, &now);
- rt_kprintf("%s\n", ctime(&now));
- rt_kprintf("%d\n", now);
- return ret;
- }
- /* 导出到 msh 命令列表中 */
- MSH_CMD_EXPORT(rtc_sample, rtc sample);
|