hi3515 RTC Driver (ds1307/1339) driver and example

Source: Internet
Author: User

Compiling the driver into the/extdrv

Some drivers are as follows:

#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;
}

... ...

Examples are as follows:

#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,&AMP;TM) <0)
printf ("IOCTL eo\n");
while (1)
{
IOCTL (FD,CMD_GET_TIME,&AMP;TM);
printf ("%02d.%0 2d.%0 2d,%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;
}

The results of the operation are as follows:

hi3515 RTC Driver (ds1307/1339) driver and example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.