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

Merge branch 'master' of git.ajou.ac.kr:hyunjun/system_programming

parents 713f44cf 7fa5bcaa
Branches
No related tags found
No related merge requests found
Showing with 1484 additions and 0 deletions
KERNEL_VER := $(shell uname -r)
KERNEL_DIR = '/lib/modules/$(KERNEL_VER)/build'
obj-m := hydro_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 "humidity 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);
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 counter = 0;
int i = 0;
switch (cmd){
case IOCTL_CMD_HYDRO:
*gpsel0 |= (1 << 12);
*gpset1 |= (1 << 4);
mdelay(800);
*gpclr1 |= (1 << 4);
mdelay(18);
*gpset1 |= (1 << 4);
udelay(30);
*gpsel0 &= ~(1 << 12);
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;
}
}
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++;
}
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];
copy_to_user((void*)arg, (void*)&data, sizeof(data));
printk(KERN_ALERT "hydro done\n");
break;
default :
printk(KERN_ALERT "cannot hydro device driver\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 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, "5D363F4F7E70F2B2C459F60");
File added
File added
kernel//home/pi/Desktop/project/hydro/hydro_dev.ko
File added
File added
File added
cmd_/home/pi/Desktop/project/smoke/smoke_dev.ko := ld -r -EL -T ./scripts/module-common.lds -T ./arch/arm/kernel/module.lds --build-id -o /home/pi/Desktop/project/smoke/smoke_dev.ko /home/pi/Desktop/project/smoke/smoke_dev.o /home/pi/Desktop/project/smoke/smoke_dev.mod.o ; true
This diff is collapsed.
This diff is collapsed.
/home/pi/Desktop/project/smoke/smoke_dev.ko
/home/pi/Desktop/project/smoke/smoke_dev.o
KERNEL_VER := $(shell uname -r)
KERNEL_DIR = '/lib/modules/$(KERNEL_VER)/build'
obj-m := smoke_dev.o
PWD := $(shell pwd)
all:
make -C $(KERNEL_DIR) M=$(PWD) modules
clean:
make -C $(KERNEL_DIR) M=$(PWD) clean
smoke/app 0 → 100755
File added
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
int main() {
int fd = open("/dev/smoke_dev", O_RDWR);
int data = 0;
while(1) {
read(fd, &data, sizeof(data));
printf("%d\n", data);
sleep(1);
}
close(fd);
return 0;
}
kernel//home/pi/Desktop/project/smoke/smoke_dev.ko
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment