当前位置: 首页 > article >正文

fmql之Linux RTC

模拟i2c,连接rtc芯片。

dts:

/{ // 根节点
    i2c_gpio: i2c-gpio {
		#address-cells = <1>;
		#size-cells = <0>;

		compatible = "i2c-gpio";
		// MIO56-SDA, MIO55-SCL        // 引脚编号
		gpios = <&portc 2 0
			 &portc 1 0 >;
		i2c-gpio,delay-us = <5>; // 100k Hz
			
		rtc@68 {
			compatible = "maxim,ds3231"; // rtc型号
			reg = <0x68>;	//ID
			status = "okay";
		};
	};
};  // 根节点end

APP代码:

介绍Linux下时间处理的相关操作(RTC、延时、闹钟、转换)-腾讯云开发者社区-腾讯云

linux rtc set time_mb60179b8f89f61的技术博客_51CTO博客

 

/***************************************************************
 Copyright © ALIENTEK Co., Ltd. 1998-2029. All rights reserved.
 文件名                 : rtcAPP.c
 作者                   : Skylar
 版本                   : V1.0
 描述                   : rtc测试
 其他                   : /dev/rtc0
 使用方法                : 
 论坛                   : www.openedv.com
 日志                   : 初版V1.0 2024/10/24 创建
 ***************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/rtc.h>
#include <string.h>

#define RTC_DEV     "/dev/rtc0"

struct rtc_time time;

int main(int argc,char **argv)
{
/*
    if(argc!=2)
    {
        printf("./app /dev/rtcX\n");
        return 0;
    }
*/
    //1.打开设备文件
    int fd=open(RTC_DEV,O_RDWR);
    if(fd < 0)
    {
        printf("%s 设备文件打开失败.\n",RTC_DEV);
        return 0;
    }
    
    //2.获取RTC驱动的时间
    ioctl(fd,RTC_RD_TIME,&time);
    printf("应用层读取的时间: %d-%d-%d %d:%d:%d\n",
            time.tm_year+1900,
            time.tm_mon+1,
            time.tm_mday,
            time.tm_hour,
            time.tm_min,
            time.tm_sec);
    
    //3.设置RTC驱动的时间
    time.tm_year=2024-1900;        //2024年
    time.tm_mon=10-1;              //10月
    time.tm_mday=24;               //24日
    time.tm_hour=14;               //14点
    time.tm_min=17;                //17分
    time.tm_sec=20;                //20秒
    ioctl(fd,RTC_SET_TIME,&time);

/*
    sleep(1);
    // 再次读取
    ioctl(fd,RTC_RD_TIME,&time);
    printf("应用层读取的时间: %d-%d-%d %d:%d:%d\n",
            time.tm_year+1900,
            time.tm_mon+1,
            time.tm_mday,
            time.tm_hour,
            time.tm_min,
            time.tm_sec);
*/    
    //4. 关闭驱动
    close(fd);
    return 0;
}

成功!


http://www.kler.cn/news/364304.html

相关文章:

  • Java项目-基于springboot框架的智慧外贸系统项目实战(附源码+文档)
  • Tomcat隐藏版本号和报错信息
  • 电脑必备快捷键大全
  • linux压缩与解压缩
  • 信发软件之电脑版拖动——未来之窗行业应用跨平台架构
  • 报表工具怎么选?山海鲸VS帆软,哪个更适合你?
  • 关闭CPU C State 解决卡屏死机问题
  • 音视频:安防监控
  • SIP 业务举例之 Call Hold(呼叫保持)
  • 【AIGC】2023-ICCV-为文本到图像的传播模型添加条件控制
  • 使用预训练的BERT进行金融领域问答
  • 忘记7-zip文件7-zip文件,还可以解压zip文件吗?
  • cosine_with_warmup_scheduler(lrgb文件中的cosine_scheduler.py)
  • Electron 离线环境打包解决方案(electron-forge)
  • 堆(堆排序,TOP K, 优先级队列)
  • AI图片生成3D物体和2D视频提取3D动画
  • vr头显都是什么操作系统
  • SpringColoud GateWay 核心组件
  • 纷享销客生态大会成都站成功举办:携手精英伙伴,共话CRM新纪元
  • RTC(Real-Time Clock)简介
  • Flutter 12 实现双击屏幕显示点赞爱心多种动画(AnimationIcon)效果
  • 《Python游戏编程入门》注-第3章3
  • OpenCV 图像去畸变(相机标定)
  • VoLTE 微信令:VoLTE 打 VoLTE,被叫号码不存在的信令流程
  • C语言——求解一元二次方程
  • 机器学习中的图像处理与计算机视觉