将驱动放入/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. How tomcat works学习笔记

    最近在看Tomcat的源码, 所以找了一本相关的书籍<How tomcat works>. 博客内容多为 学习该书时所记录的笔记.(如有侵权行为,请联系我:eviltomorrow@163 ...

  2. Laravel5.1 响应

    上篇笔记刚刚记录完请求 这节就来说说响应,一般来说啊 一个请求对应一个响应,用户都请求咱了 咱必须做一些逻辑后给人家反馈是不是,这就是响应. 1 基本的响应 我们前几篇笔记已经用过很多响应了,其中包括 ...

  3. nginx访问css js 图片等静态资源,报404或无法定向访问到

    配置完nginx,把php的项目放上去后,发现css,js和图片全部访问不到,一直重定向到根目录执行index.php,郁闷的在网上查了半天,原来不同后缀名的文件访问时都要在nginx.conf中声明 ...

  4. python资源网站

    whl安装包资源网站:http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy

  5. Android--去除EditText边框,加入下划线

    <span style="font-family: Arial, Helvetica, sans-serif;"><?xml version="1.0& ...

  6. 【BZOJ2044】三维导弹拦截 DP+(有上下界的)网络流

    [BZOJ2044]三维导弹拦截 Description 一场战争正在A国与B国之间如火如荼的展开. B国凭借其强大的经济实力开发出了无数的远程攻击导弹,B国的领导人希望,通过这些导弹直接毁灭A国的指 ...

  7. (六)通过solr7的API实现商品的列表查询

    (六)通过solr7的API实现商品的列表查询 工具类: 获取 HttpSolrClient public class Constant { public static HttpSolrClient ...

  8. UI auto程序结构组织方式

    UI Auto分三个layer: 1. Object finding – 单独一个类,寻找到控件.因为UI auto最容易改动的就是UI界面,这样全部放到一起就便于统一修改. 2. Task - 对控 ...

  9. 信息搜集之常见的web组合

    环境: Win2003或Win7 Asp解析环境搭建 小旋风 Php解析环境搭建 phpstudy aspx解析环境搭建 IIS jsp解析环境搭建 jspstudy 常规渗透环境网络环境解析 1.操 ...

  10. Python3 不能直接导入reduce

    python 3.0以后, reduce已经不在built-in function里了, 要用它就得from functools import reduce. reduce的用法 reduce(fun ...