将驱动放入/extdrv中编译

部分驱动如下:

#include <linux/module.h>

#include <linux/miscdevice.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/string.h>
#include <linux/rtc.h>
#include <linux/bcd.h>
#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/fcntl.h>
#include <linux/mm.h>
#include <linux/miscdevice.h>
#include <linux/proc_fs.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/smp_lock.h>
#include <linux/init.h>
#include <asm/uaccess.h>
#include <asm/hardware.h>
#include <asm/io.h>
#include <asm/system.h>
#include <linux/interrupt.h>
#include <linux/ioport.h>
#include <linux/string.h>
#include <linux/list.h>
#include <asm/semaphore.h>
#include <asm/delay.h>
#include <linux/timer.h>
#include <linux/delay.h>
#include <linux/proc_fs.h>
#include <linux/poll.h>
#include <asm/hardware.h>
#include <asm/bitops.h>
#include <asm/uaccess.h>
#include <asm/irq.h>
#include <linux/moduleparam.h>
#include <linux/ioport.h>
#include <linux/interrupt.h>
#include "gpio_i2c.h"
#include "gpio_i2c1.h"
#include "rtc-ds1339.h"
#define ENABLE_TEST

#define DS1339_BIT_CENTURY 0x80/* in REG_MONTH */

static unsigned char rtc1339_byte_read(unsigned char chip_addr, unsigned char addr);

static unsigned char rtc1339_byte_write(unsigned char chip_addr,
                       unsigned char addr, unsigned char data) 
{
    #ifdef ENABLE_TEST
    unsigned char reg_val;
    #endif
    
    gpio_i2c_write(chip_addr, addr, data);  
    #ifdef ENABLE_TEST
    reg_val = rtc1339_byte_read(chip_addr, addr);
    if(reg_val != data)
    {
        printk("ec6214_byte_write error: addr:%x, reg:%x, val:%x, read:%x\r\n", chip_addr, addr, data, reg_val);
    }
    #endif
    return 0;
}

static unsigned char rtc1339_byte_read(unsigned char chip_addr, unsigned char addr)
{   
    unsigned char reg_val;
    reg_val = gpio_i2c_read(chip_addr, addr);
    return reg_val;
}

///////////////////////////////////////////////////////////////////////////////
//***********open the ds1339*****************************************//
int ds1339_open(struct inode * inode,struct file *file)
{
 return 0;
}
///////////////////////////////////////////////////////////////////////////////
//***********close the ds1339*****************************************//
int ds1339_close(struct inode * inode,struct file *file)
{
 return 0;
}

... ...

示例如下:

#include <stdio.h>
#include <stdlib.h> /* getenv() */
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <error.h>
#include <sys/time.h>
#include <unistd.h>
#include <time.h>
#include <getopt.h>
#include <linux/rtc.h>
#include "rtc-ds1339.h"

int Init()
{
int fd;
//open device file
fd = open("/dev/rtc-ds1339",O_RDWR);
if(fd < 0)
{
printf("device open fail\n");
return -1;
}

return fd;
}

int main(int agc,char **agv)
{
int fd,ch;
struct rtc_time 
{
  unsigned int tm_sec;
  unsigned int tm_min;
  unsigned int tm_hour;
  unsigned int tm_wday;
  unsigned int tm_date;
  unsigned int tm_month;
  unsigned int tm_year;
};
struct rtc_time tm;

tm.tm_year=2013;
tm.tm_month=03;
tm.tm_date=14;
tm.tm_wday=4;
tm.tm_hour=16;
tm.tm_min=18;

fd=Init();
if (fd>0)
{
if (ioctl(fd,CMD_SET_TIME,&tm)<0)
printf ("ioctl eo\n");
while(1)
{
ioctl(fd,CMD_GET_TIME,&tm);
printf("%02d.%02d.%02d,%01d,%02d:%02d:%02d\n"
,tm.tm_year,tm.tm_month,tm.tm_date,tm.tm_wday,tm.tm_hour,tm.tm_min,tm.tm_sec);
sleep(1);
}
close(fd);
}

return 0;
}

运行结果如下:

hi3515 rtc驱动(ds1307/1339)驱动和示例的更多相关文章

  1. RTC是DS1339,驱动采用的是rtc-ds1307.c

    我的外部RTC是DS1339,驱动采用的是rtc-ds1307.c在内核里选上了 <*> I2C support 以及 [*]   Set system time from RTC on  ...

  2. Windows网络驱动、NDIS驱动(微端口驱动、中间层驱动、协议驱动)、TDI驱动(网络传输层过滤)、WFP(Windows Filtering Platform)

    catalog . 引言 . Windows 2000网络结构和OSI模型 . NDIS驱动 . NDIS微端口驱动编程实例 . NDIS中间层驱动编程实例 . NDIS协议层驱动编程实例 . TDI ...

  3. 字符设备驱动、平台设备驱动、设备驱动模型、sysfs的比较和关联

    转载自:http://www.kancloud.cn/yueqian_scut/emlinux/106829 学习Linux设备驱动开发的过程中自然会遇到字符设备驱动.平台设备驱动.设备驱动模型和sy ...

  4. [kernel]字符设备驱动、平台设备驱动、设备驱动模型、sysfs几者之间的比较和关联

    转自:http://www.2cto.com/kf/201510/444943.html Linux驱动开发经验总结,绝对干货! 学习Linux设备驱动开发的过程中自然会遇到字符设备驱动.平台设备驱动 ...

  5. 二十、网卡框架分析、虚拟网卡驱动和DM9621驱动分析

    一.网络设备驱动的结构 网卡设备不同于字符设备和块设备, 网络设备并不对应于/dev目录下的文件,它存放在/sys/class/net目录下. Linux系统对网络设备驱动定义了四个层次: 1. 网络 ...

  6. 《连载 | 物联网框架ServerSuperIO教程》- 14.配制工具介绍,以及设备驱动、视图驱动、服务实例的挂载

    注:ServerSuperIO二次开发套件授权码申请---截止到:2016-12-09 1.C#跨平台物联网通讯框架ServerSuperIO(SSIO)介绍 <连载 | 物联网框架Server ...

  7. WDM驱动和NT驱动之我见

    WDM驱动是NT驱动的进化版.我个人觉得它的主要好处有两个 1.能检测到设备的插入,系统能自动分配设备的硬件信息,如中断号.IO端口.设备物理地址等 2.支持设备的开机状态拔出 之前的NT驱动和硬件关 ...

  8. LinuxI2C核心、总线驱动与设备驱动

    I2C体系结构分为三个部分:I2C核心.总线驱动.设备驱动 I2C核心: I2C核心提供了一组不依赖硬件的接口函数,I2C总线驱动和设备驱动之间依赖于I2C核心作为纽带 (1)增加/删除i2c_ada ...

  9. [windows驱动]内核态驱动架构

    1.windows驱动简介: 1.1 windows组件简介: 1.2 windows驱动类型: windows驱动分为两种基本类型: 用户态驱动在用户态下执行.它们一般提供一套win32应用程序和内 ...

  10. 【驱动】USB驱动·入门

    [驱动]USB驱动·入门 Preface USB是目前最流行的系统总线之一.随着计算机周围硬件的不断扩展,各种设备使用不同的总线接口,导致计算机外部总线种类繁多,管理困难.USB总线正是因此而诞生的. ...

随机推荐

  1. tp 大致执行流程

    http://www.thinkphp.cn/code/305.html http://document.thinkphp.cn/manual_3_2.html#wechat

  2. 第一百七十六节,jQuery,插件

    jQuery,插件 学习要点: 1.插件概述 2.验证插件 3.自动完成插件 4.自定义插件 插件(Plugin)也成为 jQuery 扩展(Extension),是一种遵循一定规范的应用程序接口编 ...

  3. Python 爬虫实战2 百度贴吧帖子

    爬取百度贴吧的帖子.与上一篇不同的是,这次我们需要用到文件的相关操作. 本篇目标 对百度贴吧的任意帖子进行抓取 指定是否只抓取楼主发帖内容 将抓取到的内容分析并保存到文件 1.URL格式的确定 首先, ...

  4. 加载Chrome&Firefox配置

    一.加载Chrome配置 分析: Chrome加载配置的方法,只需要改下面一个地方,就是将username改成你本机电脑的名字(不要用中文) '--user-data-dir=C:\Users\use ...

  5. antd拖拽排序

    https://segmentfault.com/a/1190000004006185?_ea=457266 https://react-dnd.github.io/react-dnd/

  6. TOC之关键链项目管理遇到软件project7原则

    编著者:张克强    微博:张克强-敏捷307 软件project7原则简单介绍 美国著名软件project专家鲍伊姆(B.W.Boehm,也又另译为勃姆)在总结软件project准则和信条的基础上, ...

  7. CodeIgniter 入门教程第一篇:信息发布

    一.MVC CodeIgniter 采用MVC架构即:控制层.模型层和视图层. 对应Application下面的文件夹   (图1): 所有新建文件以.php结尾 视图层 view 文件夹放入HTML ...

  8. hdu 5452(树链刨分)

    看到题目,想了挺长时间,发现不会,然后看着样子像是树上成段操作,所以查了下树链刨分,结果真的就是这个东西... Minimum Cut Time Limit: 3000/2000 MS (Java/O ...

  9. [转]C#静态方法与非静态方法的比较

    http://wenku.baidu.com/view/4e1704084a7302768e9939e0.html C#的类中可以包含两种方法:C#静态方法与非静态方法.那么他们的定义有什么不同呢?他 ...

  10. python系列九:python3迭代器和生成器

    #!/usr/bin/python import sys '''迭代器是一个可以记住遍历的位置的对象.迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束.迭代器只能往前不会后退.迭代器有 ...