- UID
- 1029342
- 性别
- 男
|
include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/fs.h>
#include <linux/proc_fs.h>
#include <linux/errno.h>
#include <linux/cdev.h>
#include <linux/ioctl.h>
#include <linux/fcntl.h>
#include <linux/sched.h>
#include <linux/poll.h>
#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/device.h>
#include <linux/mm.h>
#include <linux/spinlock.h>
#include <plat/map.h>
#include <asm/io.h>
#include <asm/delay.h>
#include <asm/memory.h>
#include <asm/uaccess.h>
#include <asm/mach/map.h>
#include <asm/uaccess.h>
#include <mach/regs-gpio.h>
#include <mach/map.h>
MODULE_LICENSE("GPL"); #define GPHCON (*(volatile unsigned int *)S3C2410_GPHCON)
#define GPHDAT (*(volatile unsigned int *)S3C2410_GPHDAT)
#define GPHUP (*(volatile unsigned int *)S3C2410_GPHUP)
static int ds18b20_major = 230; /*静态申请设备号*/
struct cdev cdev;
struct class *my_class;
spinlock_t lock;
dev_t dev = 0;
int number_of_devices = 1;
/*配置为输入模式*/
void set_conIN(void)
{
GPHCON &= ~(1<<19);
GPHCON &= ~(1<<18);
}
/*配置为输出模式*/
void set_conOUT(void)
{
GPHCON |= (1<<18);
GPHCON &= ~(1<<19);
}
/*引脚置位*/
void set_data(int i)
{
if( i == 0 ){
GPHDAT &= ~(1<<9);
}else if( i == 1 ){
GPHDAT |= (1<<9);
}
}
/*复位ds18b20*/
unsigned int reset_ds18b20(void)
{
unsigned int retValue;
set_conOUT();
set_data(1);
__udelay(1);
set_data(0);
__udelay(600);
set_data(1);
__udelay(20);
set_conIN();
__udelay(100);
/*稍做延时后 如果x=0则初始化成功
x=1则初始化失*/
retValue = (GPHDAT >> 9) & 0x01;
printk("init is %d\n",retValue);
return retValue;
}
/*读取一位温度*/
unsigned int read_bit(void)
{
spin_lock(&lock);
set_conOUT();
//set_data(1);
//__udelay(2);
set_data(0);
__udelay(2);
set_conIN();
__udelay(1);
spin_unlock(&lock);
return ((GPHDAT >> 9) & 0x01);
}
/*写一位命令*/
void write_bit(char bitValue)
{
spin_lock(&lock);
set_conOUT();
set_data(0);
__udelay(15);
if( bitValue == 1 ){
set_data(1);
}else{
set_data(0);
}
spin_unlock(&lock);
__udelay(45);
set_conIN();
__udelay(2);
} |
|