Skip to content
Snippets Groups Projects
Commit a5187150 authored by hyunjun_cho's avatar hyunjun_cho
Browse files

buzzer & smoke detection

parent 4a3c612b
Branches
No related tags found
No related merge requests found
Showing
with 2688 additions and 0 deletions
app.c 0 → 100644
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <errno.h>
#include <time.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/sysmacros.h>
#define SMOKE_DEV_PATH "/dev/smoke_dev"
#define BUZZER_DEV_PATH "/dev/buzzer_dev"
#define INTERVAL 50000
int main(void)
{
int smoke_dev, smoke_data;
int buzzer_dev, buzzer_data = 400;
smoke_dev = open(SMOKE_DEV_PATH, O_RDONLY);
buzzer_dev = open(BUZZER_DEV_PATH, O_RDWR);
if(smoke_dev < 0) {
printf("fail to open smoke detection sensor device\n");
return 1;
}
if(buzzer_dev < 0) {
printf("fail to open buzzer sensor device\n");
return 1;
}
int count = 0;
while(count < 200){
read(smoke_dev, &smoke_data, sizeof(int));
printf("data : %d\n", smoke_data);
if(smoke_data > 500) {
write(buzzer_dev, &buzzer_data, sizeof(int)*2);
}
sleep(3);
}
close(smoke_dev);
close(buzzer_dev);
return 0;
}
cmd_/home/pi/Desktop/project/buzzer/buzzer_dev.ko := ld -r -EL -T ./scripts/module-common.lds -T ./arch/arm/kernel/module.lds --build-id -o /home/pi/Desktop/project/buzzer/buzzer_dev.ko /home/pi/Desktop/project/buzzer/buzzer_dev.o /home/pi/Desktop/project/buzzer/buzzer_dev.mod.o ; true
This diff is collapsed.
This diff is collapsed.
/home/pi/Desktop/project/buzzer/buzzer_dev.ko
/home/pi/Desktop/project/buzzer/buzzer_dev.o
KERNEL_VER := $(shell uname -r)
KERNEL_DIR = '/lib/modules/$(KERNEL_VER)/build'
obj-m := buzzer_dev.o
PWD := $(shell pwd)
all :
make -C $(KERNEL_DIR) M=$(PWD) modules
clean :
make -C $(KERNEL_DIR) M=$(PWD) modules
in :
sudo insmod buzzer_dev.ko
sudo mknod -m 666 /dev/buzzer c 501 0
out :
sudo rmmod buzzer_dev
in2 :
sudo insmod buzzer_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 <linux/time.h>
#include <linux/ktime.h>
#include <linux/jiffies.h>
#include <asm/mach/map.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#define BUZZER_MAJOR_NUMBER 501
#define BUZZER_DEV_NAME "buzzer_dev"
#define GPIO_BASE_ADDR 0x3F200000
#define GPFSEL1 0x04
#define GPSET1 0x1C
#define GPCLR1 0x28
#define GPLEV1 0x34
static void __iomem *gpio_base;
volatile unsigned int* gpsel1;
volatile unsigned int* gpset1;
volatile unsigned int* gpclr1;
int buzzer_open(struct inode* inode, struct file* filp) {
printk(KERN_ALERT "buzzer open function called\n");
gpio_base = ioremap(GPIO_BASE_ADDR, 0x60);
gpsel1 = (volatile unsigned int*)(gpio_base + GPFSEL1);
gpset1 = (volatile unsigned int*)(gpio_base + GPSET1);
gpclr1 = (volatile unsigned int*)(gpio_base + GPCLR1);
return 0;
}
ssize_t buzzer_write(struct file *filp, const char* buf, size_t count, loff_t *f_pos) {
printk(KERN_ALERT "buzzer write function called\n");
*gpsel1 |= (1<<24);
int data = 0;
copy_from_user(&data, buf, 4);
printk(KERN_INFO "%d\n", data);
unsigned int duration = 500;
long bdelay = (long)(1000000/data);
long time = (long)(duration*1000)/(bdelay*2);
printk(KERN_ALERT "%ld %ld\n", bdelay, time);
int i;
for(i = 0; i < time*2; i++) {
*gpset1 |= (1<<18);
udelay(bdelay);
*gpclr1 |= (1<<18);
udelay(bdelay);
}
*gpsel1 |=(0<<24);
return count;
}
int buzzer_release(struct inode* inode, struct file* filp) {
printk(KERN_ALERT "buzzer device driver closed!!\n");
iounmap((void*)gpio_base);
return 0;
}
static struct file_operations buzzer_fops = {
.owner = THIS_MODULE,
.open = buzzer_open,
.release = buzzer_release,
.write = buzzer_write
};
int __init buzzer_init(void) {
if(register_chrdev(BUZZER_MAJOR_NUMBER, BUZZER_DEV_NAME, &buzzer_fops) < 0 )
printk(KERN_ALERT "[buzzer] driver init failed\n");
else
printk(KERN_ALERT "[buzzer] driver init successful\n");
return 0;
}
void __exit buzzer_exit(void) {
unregister_chrdev(BUZZER_MAJOR_NUMBER, BUZZER_DEV_NAME);
printk(KERN_ALERT "[buzzer] driver cleanup");
}
module_init(buzzer_init);
module_exit(buzzer_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("hyunjun cho");
MODULE_DESCRIPTION("BUZZER_DEVICE_DRIVER");
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" },
{ 0xedc03953, "iounmap" },
{ 0xdb7305a1, "__stack_chk_fail" },
{ 0x8e865d3c, "arm_delay_ops" },
{ 0x5f754e5a, "memset" },
{ 0x28cc25db, "arm_copy_from_user" },
{ 0x8f678b07, "__stack_chk_guard" },
{ 0x2196324, "__aeabi_idiv" },
{ 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, "99F105EF4A9D14F0CE2E7CC");
File added
File added
kernel//home/pi/Desktop/project/buzzer/buzzer_dev.ko
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_DIR = /lib/modules/4.19.97-v7+/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
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