Skip to content
Snippets Groups Projects
Commit 06766f75 authored by Damin Lee's avatar Damin Lee
Browse files

project

parent 7db77abe
No related branches found
No related tags found
No related merge requests found
KERNEL_VER := $(shell uname -r)
KERNEL_DIR = '/lib/modules/$(KERNEL_VER)/build'
obj-m := temp_dev.o
PWD := $(shell pwd)
all:
make -C $(KERNEL_DIR) M=$(PWD) modules
clean:
make -C $(KERNEL_DIR) M=$(PWD) clean
kernel//home/pi/Desktop/project/temp/temp_dev.ko
make clean
make
sudo rmmod temp_dev
sudo insmod temp_dev.ko
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
#include <linux/slab.h>
#include <linux/ktime.h>
#include <linux/timer.h>
#include <linux/delay.h>
#include <asm/mach/map.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#define MAX_TIME 87
#define TEMP_MAJOR_NUMBER 502
#define TEMP_MINOR_NUMBER 102
#define TEMP_DEV_NAME "temp"
#define GPIO_BASE_ADDR 0x3F200000
#define GPFSEL0 0x00
#define GPSET0 0x1C
#define GPCLR0 0x28
#define GPLEV0 0x34
static void __iomem *gpio_base;
volatile unsigned int *gpsel0;
volatile unsigned int *gpset1;
volatile unsigned int *gpclr1;
volatile unsigned int *gplev1;
int temp_open(struct inode *inode, struct file *filp){
printk(KERN_ALERT "temp driver open!!\n");
gpio_base = ioremap(GPIO_BASE_ADDR, 0x60);
gpsel0 = (volatile unsigned int *)(gpio_base + GPFSEL0);
gpset1 = (volatile unsigned int *)(gpio_base + GPSET0);
gpclr1 = (volatile unsigned int *)(gpio_base + GPCLR0);
gplev1 = (volatile unsigned int *)(gpio_base + GPLEV0);
return 0;
}
int temp_release(struct inode *inode, struct file *filp){
printk(KERN_ALERT "temp driver closed!!\n");
iounmap((void *)gpio_base);
return 0;
}
ssize_t temp_read(struct file *filp, char *buf, size_t size, loff_t *f_pos){
int dht11_dat[5] = {0, };
int count=0;
int j=0;
int i=0;
int laststate = 1;
dht11_dat[0] = dht11_dat[1] = dht11_dat[2] = dht11_dat[3] = dht11_dat[4] = 0;
*gpsel0 |= (1<<12);
*gpclr1 |= (1<<4);
mdelay(18);
*gpset1 |= (1<<4);
udelay(40);
*gpsel0 &= (0<<12);
for (i = 0; i < MAX_TIME; i++) {
count = 0 ;
while (((*gplev1 >> 4) & 1) == laststate) {
count++;
udelay(1);
if (count > 200) break;
}
laststate = ((*gplev1 >> 4) & 1);
if (count > 200) break ;
if ((i >= 4) && (i % 2 == 0)) {
dht11_dat[j / 8] <<= 1 ;
if (count > 20) dht11_dat[j / 8] |= 1 ;
j++ ;
}
//printk(KERN_ALERT "j:%d\n",j);
}
if ((j == 40) && (dht11_dat[4] == ((dht11_dat[0] + dht11_dat[1] + dht11_dat[2] + dht11_dat[3]) & 0xff))) {
printk(KERN_ALERT "humidity = %d.%d %% Temperature = %d.%d *C \n", dht11_dat[0], dht11_dat[1], dht11_dat[2], dht11_dat[3]) ;
}
else{
printk(KERN_ALERT "Data get failed\n");
}
copy_to_user(buf, &dht11_dat, sizeof(dht11_dat));
return size;
}
static struct file_operations temp_fops={
.owner = THIS_MODULE,
.read = temp_read,
.open = temp_open,
.release = temp_release
};
int __init temp_init(void){
if(register_chrdev(TEMP_MAJOR_NUMBER, TEMP_DEV_NAME, &temp_fops) < 0)
printk(KERN_ALERT "temp driver initialization fail\n");
else
printk(KERN_ALERT "temp driver initialization success\n");
return 0;
}
void __exit temp_exit(void){
unregister_chrdev(TEMP_MAJOR_NUMBER, TEMP_DEV_NAME);
printk(KERN_ALERT "temp driver exit done\n");
}
module_init(temp_init);
module_exit(temp_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Damin");
MODULE_DESCRIPTION("des");
File added
#include <linux/build-salt.h>
#include <linux/module.h>
#include <linux/vermagic.h>
#include <linux/compiler.h>
BUILD_SALT;
MODULE_INFO(vermagic, VERMAGIC_STRING);
MODULE_INFO(name, KBUILD_MODNAME);
__visible struct module __this_module
__attribute__((section(".gnu.linkonce.this_module"))) = {
.name = KBUILD_MODNAME,
.init = init_module,
#ifdef CONFIG_MODULE_UNLOAD
.exit = cleanup_module,
#endif
.arch = MODULE_ARCH_INIT,
};
#ifdef CONFIG_RETPOLINE
MODULE_INFO(retpoline, "Y");
#endif
static const struct modversion_info ____versions[]
__used
__attribute__((section("__versions"))) = {
{ 0xad1a7def, "module_layout" },
{ 0x6bc3fbc0, "__unregister_chrdev" },
{ 0xcfc78319, "__register_chrdev" },
{ 0xdb7305a1, "__stack_chk_fail" },
{ 0xf4fa543b, "arm_copy_to_user" },
{ 0x8e865d3c, "arm_delay_ops" },
{ 0x8f678b07, "__stack_chk_guard" },
{ 0xedc03953, "iounmap" },
{ 0x2e5810c6, "__aeabi_unwind_cpp_pr1" },
{ 0xe97c4103, "ioremap" },
{ 0x7c32d0f0, "printk" },
{ 0xb1ad28e0, "__gnu_mcount_nc" },
};
static const char __module_depends[]
__used
__attribute__((section(".modinfo"))) =
"depends=";
MODULE_INFO(srcversion, "1BF1E24B9057F508627EE8F");
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment