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

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

parents f16e1a9f 4f97cc47
No related branches found
No related tags found
No related merge requests found
Showing with 1498 additions and 0 deletions
File added
File added
kernel//home/pi/Desktop/project/led2/led2_dev.ko
sudo rmmod led2_dev
sudo rm /dev/led2_dev
make
sudo insmod led2_dev.ko
sudo mknod -m 666 /dev/led2_dev c 502 0
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
cmd_/home/pi/Desktop/project/sound/sound_dev.ko := ld -r -EL -T ./scripts/module-common.lds -T ./arch/arm/kernel/module.lds --build-id -o /home/pi/Desktop/project/sound/sound_dev.ko /home/pi/Desktop/project/sound/sound_dev.o /home/pi/Desktop/project/sound/sound_dev.mod.o ; true
This diff is collapsed.
This diff is collapsed.
/home/pi/Desktop/project/sound/sound_dev.ko
/home/pi/Desktop/project/sound/sound_dev.o
KERNEL_DIR = /lib/modules/4.19.97-v7+/build
obj-m := sound_dev.o
PWD := $(shell pwd)
all:
make -C $(KERNEL_DIR) M=$(PWD) modules
clean:
make -C $(KERNEL_DIR) M=$(PWD) clean
in:
sudo insmod sound_dev.ko
out:
sudo rmmod sound_dev
in2:
sudo mknod -m 666 /dev/sound_dev c 502 0
sound/app 0 → 100755
File added
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <math.h>
#include <errno.h>
#include <time.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/sysmacros.h>
//#define TEMP_DEV_PATH "/dev/temp_dev"
#define SOUND_DEV_PATH "/dev/sound_dev"
#define LED_DEV_PATH "/dev/led_dev"
#define LED2_DEV_PATH "/dev/led2_dev"
#define INTERVAL 50000
int main() {
int sound_fd = open(SOUND_DEV_PATH, O_RDWR);
int sound_data = 0;
int led_fd, led2_fd;
int led_data, led2_data;
//led_fd = open(LED_DEV_PATH, O_RDONLY);
//led2_fd = open(LED2_DEV_PATH, O_RDONLY);
char config[3] = {0, };
int data[2] = {0, };
float result[2] = {0, };
char reg = 0x03;
if(sound_fd < 0) {
printf("fail to open SOUND sensor device\n");
return 1;
}
while(1){
read(sound_fd, &sound_data, sizeof(int));
printf("%d\n", sound_data);
sleep(1);
}
close(sound_fd);
//close(led_fd);
//close(led2_fd);
return 0;
}
kernel//home/pi/Desktop/project/sound/sound_dev.ko
sudo rmmod sound_dev
sudo rm /dev/sound_dev
make
sudo insmod sound_dev.ko
sudo mknod -m 666 /dev/sound_dev c 502 0
#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 SOUND_MAJOR_NUMBER 502
#define SOUND_DEV_NAME "/dev/sound_dev"
#define GPIO_BASE_ADDR 0x3F200000
#define SPI_BASE_ADDR 0x3F204000
#define GPFSEL0 0x00
#define GPFSEL1 0x04
#define CS 0x00
#define FIFO 0x04
static void __iomem *gpio_base;
static void __iomem *spi_base;
volatile unsigned int *gpfsel0, *gpfsel1;
volatile unsigned int *cs, *fifo;
int sound_open(struct inode *inode, struct file *filp){
printk(KERN_ALERT "sound 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);
cs = (volatile unsigned int*)(spi_base + CS);
fifo = (volatile unsigned int*)(spi_base + FIFO);
*gpfsel0 &= ~(0x1FF << 21);
*gpfsel0 |= (0x24 << 24);
*gpfsel1 &= ~(0x3F);
*gpfsel1 |= (0x24);
*cs &= ~(0xFFFF);
*cs &= ~(0x01<<2);
*cs &= ~(0x01<<3);
*cs |= (0x03<<4);
return 0;
}
int sound_release(struct inode *inode, struct file *filp){
printk(KERN_ALERT "sound detection sensor driver closed!!\n");
*gpfsel0 &= ~(0x1FF << 21);
*gpfsel1 &= ~(0x3F);
*cs &= ~(0xFFFF);
iounmap((void*)gpio_base);
iounmap((void*)spi_base);
return 0;
}
ssize_t sound_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;
int data = 0;
transmit_Data[0] = 1;
transmit_Data[1] = (0x08) << 4;
transmit_Data[2] = 0;
*cs |= (0x03<<4);
*cs |= (0x01<<7);
while((transmit_Count < 3) || (receive_Count < 3)){
while((*cs & (1<<18)) && (transmit_Count < 3)){
*fifo = transmit_Data[transmit_Count];
transmit_Count++;
}
while((*cs & (1<<17)) && (receive_Count < 3)){
receive_Data[receive_Count] = *fifo;
receive_Count++;
}
}
while((!(*cs)) & (1<<16));
*cs |= (0x03<<4);
*cs &= ~(1<<7);
data = ((receive_Data[1]&0x03)<<8) + receive_Data[2];
copy_to_user(buf, &data, sizeof(int));
return count;
}
static struct file_operations sound_fops = {
.owner = THIS_MODULE,
.open = sound_open,
.release = sound_release,
.read = sound_read
};
int __init sound_init(void){
if(register_chrdev(SOUND_MAJOR_NUMBER, SOUND_DEV_NAME, &sound_fops) < 0)
printk(KERN_ALERT "sound detection sensor initialization failed!!\n");
else
printk(KERN_ALERT "sound detection sensor initialization success!!!\n");
return 0;
}
void __exit sound_exit(void){
unregister_chrdev(SOUND_MAJOR_NUMBER, SOUND_DEV_NAME);
printk(KERN_ALERT "sound detection sensor driver exit done!!!!");
}
module_init(sound_init);
module_exit(sound_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("joreka");
MODULE_DESCRIPTION("SOUND_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, "52BC8781B97C9DBB22F9BCA");
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment