Skip to content
Snippets Groups Projects
Commit bcbe1431 authored by Rohmindo's avatar Rohmindo
Browse files

library management Pi

parent f228d35d
Branches
No related tags found
No related merge requests found
No preview for this file type
...@@ -45,8 +45,8 @@ int main(void) ...@@ -45,8 +45,8 @@ int main(void)
memset(&server_addr, 0, sizeof(server_addr)); memset(&server_addr, 0, sizeof(server_addr));
server_addr.sin_family = AF_INET; server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(4026); server_addr.sin_port = htons(4029);
server_addr.sin_addr.s_addr = inet_addr("192.168.0.9"); server_addr.sin_addr.s_addr = inet_addr("192.168.10.6");
if(connect(client_socket, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1) { if(connect(client_socket, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1) {
printf("connect error\n"); printf("connect error\n");
......
cmd_/home/pi/Desktop/project/hum/hum_dev.ko := ld -r -EL -T ./scripts/module-common.lds -T ./arch/arm/kernel/module.lds --build-id -o /home/pi/Desktop/project/hum/hum_dev.ko /home/pi/Desktop/project/hum/hum_dev.o /home/pi/Desktop/project/hum/hum_dev.mod.o ; true
This diff is collapsed.
This diff is collapsed.
/home/pi/Desktop/project/hum/hum_dev.ko
/home/pi/Desktop/project/hum/hum_dev.o
KERNEL_VER := $(shell uname -r)
KERNEL_DIR = '/lib/modules/$(KERNEL_VER)/build'
obj-m := hum_dev.o
PWD := $(shell pwd)
all :
make -C $(KERNEL_DIR) M=$(PWD) modules
clean :
make -C $(KERNEL_DIR) M=$(PWD) clean
in :
sudo insmod hydro_dev.ko
sudo mknod -m 666 /dev/hydro c 505 0
out :
sudo rmmod hydro_dev
in2 :
sudo insmod hydro_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/delay.h>
#include <asm/mach/map.h>
#include <asm/uaccess.h>
typedef struct{
unsigned int hydro_integer;
unsigned int hydro_float;
unsigned int temp_integer;
unsigned int temp_float;
}Data;
#define HIGH 1
#define LOW 0
#define HYDRO_MAJOR_NUMBER 505
#define HYDRO_DEV_NAME "hydro_dev"
#define IOCTL_HYDRO_MAGIC_NUMBER 'h'
#define IOCTL_CMD_HYDRO _IOR(IOCTL_HYDRO_MAGIC_NUMBER, 0, Data)
#define GPIO_BASE_ADDRESS 0x3F200000
#define GPFSEL0 0x00
#define GPFSEL1 0x04
#define GPSET1 0x1C
#define GPCLR1 0x28
#define GPLEV1 0x34
static void __iomem* gpio_base;
volatile unsigned int* gpsel0;
volatile unsigned int* gpsel1;
volatile unsigned int* gpset1;
volatile unsigned int* gpclr1;
volatile unsigned int* gplev1;
int hydro_open(struct inode * inode, struct file * filp){
printk(KERN_ALERT "\nhumidity driver open\n");
gpio_base = ioremap(GPIO_BASE_ADDRESS, 0xFF);
gpsel0 = (volatile unsigned int*)(gpio_base + GPFSEL0);
gpsel1 = (volatile unsigned int*)(gpio_base + GPFSEL1);
gpset1 = (volatile unsigned int*)(gpio_base + GPSET1);
gpclr1 = (volatile unsigned int*)(gpio_base + GPCLR1);
gplev1 = (volatile unsigned int*)(gpio_base + GPLEV1);
/*
*gpsel0 |= (1<<26);
*gpsel0 |= (1<<29);
*gpsel1 |= (1<<2);
*gpsel1 |= (1<<5);*/
return 0;
}
int hydro_release(struct inode * inode, struct file * filp) {
printk(KERN_ALERT "humidity driver closed\n\n");
iounmap((void *)gpio_base);
return 0;
}
long hydro_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
Data data;
int result[5] = {0};
int index = 0;
int pre_data = HIGH;
int counter = 0;
int i = 0;
switch (cmd){
case IOCTL_CMD_HYDRO:
*gpsel0 |= (1 << 12); //GPIO 4 SET OUTPUT MODE
*gpset1 |= (1 << 4); //GPIO 4 SET HIGH
mdelay(800); //SLEEP FOR 800 miliseconds to synchronize bits from loop
*gpclr1 |= (1 << 4); //GPIO 4 SET LOW
mdelay(18); //SLEEP FOR 18 miliseconds
*gpset1 |= (1 << 4); //GPIO 4 SET HIGH
udelay(30); //SLEEP FOR 30 microseconds
*gpsel0 &= ~(1 << 12); //GPIO 4 SET INPUT MODE
//except first 3(wait, response, ready) signals
for(i = 0; i < 3; i++){
if(((*gplev1 >> 4) & 0x01) == LOW){
while(((*gplev1 >> 4) & 0x01) == LOW){} continue;
}
if(((*gplev1 >> 4) & 0x01) == HIGH){
while(((*gplev1 >> 4) & 0x01) == HIGH){} continue;
}
}
//interpret '0' and '1' bits
while(index < 40){
if(((*gplev1 >> 4) & 0x01) == LOW) continue;
counter = 0;
while(((*gplev1 >> 4) & 0x01) == HIGH){
counter++;
udelay(1);
}
if(counter > 80) break;
result[index / 8] <<= 1;
if(counter > 28) result[index / 8] |= 1;
index++;
}
//printk(KERN_INFO "data[0]: %x data[1]: %x data[2]: %x data[3]: %x data[4]: %x\n", data[0], data[1], data[2], data[3], data[4]);
if(result[4] != ((result[0] + result[1] + result[2] + result[3]) & 0xFF))
break;
data.hydro_integer = result[0];
data.hydro_float = result[1];
data.temp_integer = result[2];
data.temp_float = result[3];
//printk(KERN_INFO "humidity: %d.%d%% temperature: %d.%d%%\n", info.humidity_integer, info.humidity_float, info.temperature_integer, info.temperature_float);
copy_to_user((void*)arg, (void*)&data, sizeof(data));
printk(KERN_ALERT "hydro done\n");
break;
default :
printk(KERN_ALERT "ioctl : command error\n");
}
return 0;
}
static struct file_operations hydro_fops = {
.owner = THIS_MODULE,
.open = hydro_open,
.release = hydro_release,
.unlocked_ioctl = hydro_ioctl
};
int __init hydro_init (void) {
if(register_chrdev(HYDRO_MAJOR_NUMBER, HYDRO_DEV_NAME, &hydro_fops) < 0)
printk(KERN_ALERT "hydro driver initalization failed\n");
else
printk(KERN_ALERT "hydro driver initalization succeed\n");
return 0;
}
void __exit hydro_exit(void){
unregister_chrdev(HYDRO_MAJOR_NUMBER, HYDRO_DEV_NAME);
printk(KERN_ALERT "hydro driver exit");
}
module_init(hydro_init);
module_exit(hydro_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("joreka");
MODULE_DESCRIPTION("hydro_dev");
File deleted
#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, "848B380E4218A5ABA3C9C06");
File deleted
File deleted
kernel//home/pi/Desktop/project/hum/hum_dev.ko
...@@ -7,143 +7,141 @@ ...@@ -7,143 +7,141 @@
#include <linux/delay.h> #include <linux/delay.h>
#include <asm/mach/map.h> #include <asm/mach/map.h>
#include <asm/io.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
typedef struct{ typedef struct{
unsigned int tempi; unsigned int hydro_integer;
unsigned int tempf; unsigned int hydro_float;
unsigned int hydroi; unsigned int temp_integer;
unsigned int hydrof; unsigned int temp_float;
}Data; }Data;
#define HIGH 1
#define LOW 0
#define HYDRO_MAJOR_NUMBER 505 #define HYDRO_MAJOR_NUMBER 505
#define HYDRO_DEV_NAME "hydro_dev" #define HYDRO_DEV_NAME "hydro_dev"
#define GPIO_BASE_ADDR 0x3F200000 #define IOCTL_HYDRO_MAGIC_NUMBER 'h'
#define IOCTL_CMD_HYDRO _IOR(IOCTL_HYDRO_MAGIC_NUMBER, 0, Data)
#define GPIO_BASE_ADDRESS 0x3F200000
#define GPFSEL0 0x00 #define GPFSEL0 0x00
#define GPFSEL1 0x04 #define GPFSEL1 0x04
#define GPSET0 0x1C #define GPSET1 0x1C
#define GPCLR0 0x28 #define GPCLR1 0x28
#define GPLEV0 0x34 #define GPLEV1 0x34
#define HIGH 1
#define LOW 0
static void __iomem* gpio_base; static void __iomem* gpio_base;
volatile unsigned int* gpsel0; volatile unsigned int* gpsel0;
volatile unsigned int* gpsel1; volatile unsigned int* gpsel1;
volatile unsigned int* gpset1; volatile unsigned int* gpset1;
volatile unsigned int* gpclr1; volatile unsigned int* gpclr1;
volatile unsigned int* gplev1; volatile unsigned int* gplev1;
int hydro_open(struct inode *inode,struct file *flip){ int hydro_open(struct inode * inode, struct file * filp){
printk(KERN_ALERT "HYDRO driver open!!\n"); printk(KERN_ALERT "humidity driver open\n");
gpio_base = ioremap(GPIO_BASE_ADDRESS, 0xFF);
gpio_base = ioremap(GPIO_BASE_ADDR, 0x60);
gpsel0 = (volatile unsigned int*)(gpio_base + GPFSEL0); gpsel0 = (volatile unsigned int*)(gpio_base + GPFSEL0);
gpsel1 = (volatile unsigned int*)(gpio_base + GPFSEL1); gpsel1 = (volatile unsigned int*)(gpio_base + GPFSEL1);
gpset1 = (volatile unsigned int *)(gpio_base + GPSET0); gpset1 = (volatile unsigned int*)(gpio_base + GPSET1);
gpclr1 = (volatile unsigned int *)(gpio_base + GPCLR0); gpclr1 = (volatile unsigned int*)(gpio_base + GPCLR1);
gplev1 = (volatile unsigned int *)(gpio_base + GPLEV0); gplev1 = (volatile unsigned int*)(gpio_base + GPLEV1);
*gpsel0 |= (1<<26);
*gpsel0 |= (1<<29);
*gpsel1 |= (1<<2);
*gpsel1 |= (1<<5);
return 0; return 0;
} }
int hydro_release(struct inode *inode,struct file *flip){ int hydro_release(struct inode * inode, struct file * filp) {
printk(KERN_ALERT "HYDRO driver closed!!\n"); printk(KERN_ALERT "humidity driver closed\n\n");
iounmap((void *)gpio_base); iounmap((void *)gpio_base);
return 0; return 0;
} }
ssize_t hydro_read(struct file *filp, char* buf, size_t counts, loff_t *f_pos) {
printk(KERN_ALERT "read function called!!\n"); long hydro_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
Data data; Data data;
int result[5] = {0, }; int result[5] = {0};
int time = 0;
int prev = HIGH;
int index = 0; int index = 0;
int counter = 0;
int i = 0; int i = 0;
switch (cmd){
case IOCTL_CMD_HYDRO:
*gpsel0 |= (1 << 12); *gpsel0 |= (1 << 12);
*gpset1 |= (1 << 4); *gpset1 |= (1 << 4);
mdelay(800); mdelay(800);
*gpclr1 |= (1 << 4); *gpclr1 |= (1 << 4);
mdelay(18); mdelay(18);
*gpset1 |= (1 << 4); *gpset1 |= (1 << 4);
udelay(30); udelay(30);
*gpsel0 = (0<<24); *gpsel0 &= ~(1 << 12);
for(i = 0; i < 3; i++){ for(i = 0; i < 3; i++){
if(((*gplev1 >> 4) & HIGH) == LOW) { if(((*gplev1 >> 4) & 0x01) == LOW){
while(((*gplev1 >> 4) & HIGH) == LOW){} while(((*gplev1 >> 4) & 0x01) == LOW){} continue;
continue;
} }
if(((*gplev1 >> 4) & HIGH) == HIGH) { if(((*gplev1 >> 4) & 0x01) == HIGH){
while(((*gplev1 >> 4) & HIGH) ==HIGH){} while(((*gplev1 >> 4) & 0x01) == HIGH){} continue;
continue;
} }
} }
//int status = LOW;
while(index < 40){ while(index < 40){
if(((*gplev1 >> 4) & 0x01) == LOW) if(((*gplev1 >> 4) & 0x01) == LOW)
continue; continue;
time = 0; counter = 0;
while(((*gplev1 >> 4) & 0x01) == HIGH){ while(((*gplev1 >> 4) & 0x01) == HIGH){
time++; counter++;
udelay(1); udelay(1);
} }
if(time > 70) if(counter > 80)
break; break;
result[index / 8] <<= 1; result[index / 8] <<= 1;
if(time > 28) if(counter > 28) result[index / 8] |= 1;
result[index/8] |= 1; index++;
time++;
} }
int wrong = -1;
printk(KERN_ALERT "%d %d %d %d\n", result[0], result[1], result[2], result[3]); if(result[4] != ((result[0] + result[1] + result[2] + result[3]) & 0xFF))
break;
if((result[4] == (result[0] + result[1] + result[2] + result[3])& 0xFF) && result[0] != 0) { data.hydro_integer = result[0]; data.hydro_float = result[1];
data.hydroi = result[0]; data.temp_integer = result[2]; data.temp_float = result[3];
data.hydrof = result[1];
data.tempi = result[2]; copy_to_user((void*)arg, (void*)&data, sizeof(data));
data.tempf = result[3]; printk(KERN_ALERT "hydro done\n");
copy_to_user(buf, (const void*)&data, sizeof(data)); break;
default :
printk(KERN_ALERT "cannot hydro device driver\n");
} }
else
copy_to_user(buf, &wrong, sizeof(int));
return counts; return 0;
} }
static struct file_operations hydro_fops = { static struct file_operations hydro_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.open = hydro_open, .open = hydro_open,
.release = hydro_release, .release = hydro_release,
.read = hydro_read .unlocked_ioctl = hydro_ioctl
}; };
int __init hydro_init (void) { int __init hydro_init (void) {
if(register_chrdev(HYDRO_MAJOR_NUMBER, HYDRO_DEV_NAME, &hydro_fops) < 0) if(register_chrdev(HYDRO_MAJOR_NUMBER, HYDRO_DEV_NAME, &hydro_fops) < 0)
printk(KERN_ALERT "HYDRO driver initialization fail\n"); printk(KERN_ALERT "hydro driver initalization failed\n");
else else
printk(KERN_ALERT "HYDRO driver intialization success\n"); printk(KERN_ALERT "hydro driver initalization succeed\n");
return 0; return 0;
} }
void __exit hydro_exit(void){ void __exit hydro_exit(void){
unregister_chrdev(HYDRO_MAJOR_NUMBER, HYDRO_DEV_NAME); unregister_chrdev(HYDRO_MAJOR_NUMBER, HYDRO_DEV_NAME);
printk(KERN_ALERT "HYDRO driver exit doen\n"); printk(KERN_ALERT "hydro driver exit");
} }
module_init(hydro_init); module_init(hydro_init);
...@@ -151,7 +149,5 @@ module_exit(hydro_exit); ...@@ -151,7 +149,5 @@ module_exit(hydro_exit);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_AUTHOR("joreka"); MODULE_AUTHOR("joreka");
MODULE_DESCRIPTION("HYDRO_DEV"); MODULE_DESCRIPTION("hydro_dev");
No preview for this file type
...@@ -45,4 +45,4 @@ __attribute__((section(".modinfo"))) = ...@@ -45,4 +45,4 @@ __attribute__((section(".modinfo"))) =
"depends="; "depends=";
MODULE_INFO(srcversion, "CBED33CF7ABA6C5B93EA66B"); MODULE_INFO(srcversion, "5D363F4F7E70F2B2C459F60");
No preview for this file type
No preview for this file type
...@@ -689,6 +689,8 @@ deps_/home/pi/Desktop/project/smoke/smoke_dev.o := \ ...@@ -689,6 +689,8 @@ deps_/home/pi/Desktop/project/smoke/smoke_dev.o := \
$(wildcard include/config/slob.h) \ $(wildcard include/config/slob.h) \
include/linux/overflow.h \ include/linux/overflow.h \
include/linux/kasan.h \ include/linux/kasan.h \
include/linux/delay.h \
arch/arm/include/asm/delay.h \
arch/arm/include/asm/mach/map.h \ arch/arm/include/asm/mach/map.h \
$(wildcard include/config/debug/ll.h) \ $(wildcard include/config/debug/ll.h) \
arch/arm/include/asm/io.h \ arch/arm/include/asm/io.h \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment