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

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

parents 8a8b2544 d6456341
No related branches found
No related tags found
No related merge requests found
Showing with 1461 additions and 0 deletions
lcd_dev.o 0 → 100644
File added
kernel//home/pi/lcd/lcd_dev.ko
sudo rmmod lcd_dev
sudo rm /dev/lcd_dev
make clean
make
sudo insmod lcd_dev.ko
sudo mknod -m 666 /dev/lcd_dev c 509 0
gcc -o lcd lcd.c
sudo ./lcd
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
make clean
make
sudo rmmod smoke_dev
sudo insmod smoke_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>
#define SMOKE_MAJOR_NUMBER 500
#define SMOKE_DEV_NAME "/dev/smoke_dev"
#define GPIO_BASE_ADDR 0x3F200000
#define SPI_BASE_ADDR 0x3F204000
#define GPFSEL0 0x00
#define GPFSEL1 0x04
#define SPI_CS 0x00
#define SPI_FIFO 0x04
static void __iomem *gpio_base;
static void __iomem *spi_base;
volatile unsigned int *gpfsel0, *gpfsel1;
volatile unsigned int *spi_cs, *spi_fifo;
int smoke_open(struct inode *inode, struct file *filp){
printk(KERN_ALERT "smoke detection sensor driver open!!\n");
gpio_base = ioremap(GPIO_BASE_ADDR, 0xFF);
spi_base = ioremap(SPI_BASE_ADDR, 0xFF);
gpfsel0 = (volatile unsigned int*)(gpio_base + GPFSEL0);
gpfsel1 = (volatile unsigned int*)(gpio_base + GPFSEL1);
spi_cs = (volatile unsigned int*)(spi_base + SPI_CS);
spi_fifo = (volatile unsigned int*)(spi_base + SPI_FIFO);
*gpfsel0 &= ~(0x1FF << 21);
*gpfsel0 |= (0x24 << 24);
*gpfsel1 &= ~(0x3F);
*gpfsel1 |= (0x24);
*spi_cs &= ~(0xFFFF);
*spi_cs &= ~(0x01<<2);
*spi_cs &= ~(0x01<<3);
*spi_cs |= (0x03<<4);
return 0;
}
int smoke_release(struct inode *inode, struct file *filp){
printk(KERN_ALERT "smoke detection sensor driver closed!!\n");
*gpfsel0 &= ~(0x1FF << 21);
*gpfsel1 &= ~(0x3F);
*spi_cs &= ~(0xFFFF);
iounmap((void*)gpio_base);
iounmap((void*)spi_base);
return 0;
}
ssize_t smoke_read(struct file* flip, char* buf, size_t count, loff_t* f_pos){
printk(KERN_ALERT "read function called!!\n");
unsigned char transmit_Data[3];
unsigned char receive_Data[3];
int transmit_Count = 0;
int receive_Count = 0;
transmit_Data[0] = 1;
transmit_Data[1] = (0x08) << 4;
transmit_Data[2] = 0;
*spi_cs |= (0x03<<4);
*spi_cs |= (0x01<<7);
while((transmit_Count < 3) || (receive_Count < 3)){
while((*spi_cs & (1<<18)) && (transmit_Count < 3)){
*spi_fifo = transmit_Data[transmit_Count];
transmit_Count++;
}
while((*spi_cs & (1<<17)) && (receive_Count < 3)){
receive_Data[receive_Count] = *spi_fifo;
receive_Count++;
}
}
while((!(*spi_cs)) & (1<<16));
*spi_cs |= (0x03<<4);
*spi_cs &= ~(1<<7);
int data = ((receive_Data[1]&0x03)<<8) + receive_Data[2];
printk(KERN_ALERT "reading input : %d \n", data);
copy_to_user(buf, &data, sizeof(int));
return count;
}
static struct file_operations smoke_fops = {
.owner = THIS_MODULE,
.open = smoke_open,
.release = smoke_release,
.read = smoke_read
};
int __init smoke_init(void){
if(register_chrdev(SMOKE_MAJOR_NUMBER, SMOKE_DEV_NAME, &smoke_fops) < 0)
printk(KERN_ALERT "smoke detection sensor initialization failed!!\n");
else
printk(KERN_ALERT "smoke detection sensor initialization success!!!\n");
return 0;
}
void __exit smoke_exit(void){
unregister_chrdev(SMOKE_MAJOR_NUMBER, SMOKE_DEV_NAME);
printk(KERN_ALERT "smoke detection sensor driver exit done!!!!");
}
module_init(smoke_init);
module_exit(smoke_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("joreka");
MODULE_DESCRIPTION("SMOKE_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" },
{ 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, "194BCBE501BF825F76154FB");
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment