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
Branches
No related tags found
No related merge requests found
Showing with 1670 additions and 0 deletions
File added
File added
kernel//home/pi/Desktop/project/buzzer/buzzer_dev.ko
cmd_/home/pi/Desktop/project/hydro/hydro_dev.ko := ld -r -EL -T ./scripts/module-common.lds -T ./arch/arm/kernel/module.lds --build-id -o /home/pi/Desktop/project/hydro/hydro_dev.ko /home/pi/Desktop/project/hydro/hydro_dev.o /home/pi/Desktop/project/hydro/hydro_dev.mod.o ; true
This diff is collapsed.
This diff is collapsed.
/home/pi/Desktop/project/hydro/hydro_dev.ko
/home/pi/Desktop/project/hydro/hydro_dev.o
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
lcd 0 → 100755
lcd_dev.c 0 → 100644
//#include "bcm2835.h"
#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 IR_MAJOR_NUMBER 504
#define IR_DEV_NAME "lcd_dev"
#define I2C_BASE_ADDR 0x3F804000
#define DLEN 0x08
#define FIFO 0x10
#define S 0x04
#define C 0x00
#define DIV 0x14
#define BSC_A 0x0C
static void __iomem *i2c_base;
volatile unsigned int *i2c, paddr;
int lcd_open(struct inode *inode, struct file *filp){
printk(KERN_ALERT "LCD sensor driver open!!\n");
i2c_base = ioremap(I2C_BASE_ADDR, 0xFF);
i2c=(volatile unsigned int*)(i2c_base);
return 0;
}
int lcd_release(struct inode *inode, struct file *filp){
printk(KERN_ALERT "Infrared distance sensor driver closed!!\n");
return 1;
}
ssize_t lcd_write(struct file* flip, const char* buf, size_t count, loff_t* f_pos){
char* kbuf;
kbuf=kmalloc(count, GFP_KERNEL);
copy_from_user(kbuf, buf, 1);
//printk(KERN_ALERT "SEX: %x\n", *kbuf);
//char buffer[1];
//buffer[0]=0x01;
unsigned int len=1;
volatile unsigned int* dlen = (volatile unsigned int*)(i2c_base + DLEN);
volatile unsigned int* fifo = (volatile unsigned int*)(i2c_base + FIFO);
volatile unsigned int* status = (volatile unsigned int*)(i2c_base + S);
volatile unsigned int* control = (volatile unsigned int*)(i2c_base + C);
volatile unsigned int* bsc_a = (volatile unsigned int*)(i2c_base + BSC_A);
*bsc_a = 0x3F;
unsigned int remaining=len;
unsigned int i=0;
unsigned int reason = 0;
*control |= 0x20;
*status = (0x200 | 0x100 | 0x02);
*dlen = len;
while(remaining &&(i<16)){
*fifo = kbuf[i];
i++;
remaining--;
}
*control = (0x8000|0x80);
while(!(*status & 0x02)){
while(remaining && (*status & 0x10)){
*fifo = kbuf[i];
i++;
remaining--;
}
}
if(*status & 0x100)
reason = 1;
else if(*status & 0x200)
reason = 2;
else if(remaining)
reason = 4;
*control |= 0x02;
printk(KERN_ALERT "reason: %d\n", reason);
//copy_to_user(buf, &reason, sizeof(int));
return 0;
}
/*
ssize_t lcd_read(struct file *filp, char *buf, size_t size, loff_t *f_pos){
int
char buffer[1];
buffer[0]=0x01;
unsigned int len=1;
volatile unsigned int* dlen = (volatile unsigned int*)(i2c_base + DLEN);
volatile unsigned int* fifo = (volatile unsigned int*)(i2c_base + FIFO);
volatile unsigned int* status = (volatile unsigned int*)(i2c_base + S);
volatile unsigned int* control = (volatile unsigned int*)(i2c_base + C);
unsigned int remaining=len;
unsigned int i=0;
unsigned int reason = 0;
*control |= 0x20;
*status = (0x200 | 0x100 | 0x02);
*dlen = len;
while(remaining &&(i<16)){
*fifo = buffer[i];
i++;
remaining--;
}
*control = (0x8000|0x80);
while(!(*status & 0x02)){
while(remaining && (*status & 0x10)){
*fifo = buffer[i];
i++;
remaining--;
}
}
if(*status & 0x100)
reason = 1;
else if(*status & 0x200)
reason = 2;
else if(remaining)
reason = 4;
*control |= 0x02;
printk(KERN_ALERT "reason: %d\n", reason);
copy_to_user(buf, &reason, sizeof(int));
return 0;
return size;
}
*/
static struct file_operations ir_fops = {
.owner = THIS_MODULE,
.open = lcd_open,
.release = lcd_release,
.write = lcd_write
};
int __init lcd_init(void){
if(register_chrdev(IR_MAJOR_NUMBER, IR_DEV_NAME, &ir_fops) < 0)
printk(KERN_ALERT "LCD initialization failed\n");
else
printk(KERN_ALERT "LCD initialization success\n");
return 0;
}
void __exit lcd_exit(void){
unregister_chrdev(IR_MAJOR_NUMBER, IR_DEV_NAME);
printk(KERN_ALERT "LCD driver exit done");
}
module_init(lcd_init);
module_exit(lcd_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("MW");
MODULE_DESCRIPTION("joreka");
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" },
{ 0x5f754e5a, "memset" },
{ 0x28cc25db, "arm_copy_from_user" },
{ 0x12da5bb2, "__kmalloc" },
{ 0xe97c4103, "ioremap" },
{ 0x2e5810c6, "__aeabi_unwind_cpp_pr1" },
{ 0x7c32d0f0, "printk" },
{ 0xb1ad28e0, "__gnu_mcount_nc" },
};
static const char __module_depends[]
__used
__attribute__((section(".modinfo"))) =
"depends=";
MODULE_INFO(srcversion, "26062333FCF0DFDA5362B37");
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment