基于S3C2440嵌入式Linux系统下的一个DS18B20驱动和命令行测试程序(二)

2014-11-24 03:20:04 · 作者: · 浏览: 7
;
DS18b20_write_byte(0x44);

udelay(5);

while(DS18b20_reset());
udelay(200);

DS18b20_write_byte(0xcc);
DS18b20_write_byte(0xbe);

data[0] = DS18b20_read_byte();
data[1] = DS18b20_read_byte();
}


static ssize_t s3c2440_18b20_read(struct file *filp, char *buf, size_t len, loff_t *off)
{
DS18b20_proc();


buf[0] = data[0];
buf[1] = data[1];

return 1;
}


static struct file_operations s3c2440_18b20_fops =
{
.owner = THIS_MODULE,
.read = s3c2440_18b20_read,
};


static int __init s3c2440_18b20_init(void)
{
if (register_chrdev(DEV_MAJOR, DEV_NAME, &s3c2440_18b20_fops) < 0)
{
printk(DEV_NAME ": Register major failed.\r\n");
return -1;
}

devfs_mk_cdev(MKDEV(DEV_MAJOR, 0),S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP, DEV_NAME);

while(DS18b20_reset());
}


static void __exit s3c2440_18b20_exit(void)
{
devfs_remove(DEV_NAME);
unregister_chrdev(DEV_MAJOR, DEV_NAME);
}
module_init(s3c2440_18b20_init);
module_exit(s3c2440_18b20_exit);


/************************* s3c2440_ds18b20.c文件结束 **************************/