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
cmd_/home/pi/lcd/lcd_dev.ko := ld -r -EL -T ./scripts/module-common.lds -T ./arch/arm/kernel/module.lds --build-id -o /home/pi/lcd/lcd_dev.ko /home/pi/lcd/lcd_dev.o /home/pi/lcd/lcd_dev.mod.o ; true
This diff is collapsed.
This diff is collapsed.
/home/pi/lcd/lcd_dev.ko
/home/pi/lcd/lcd_dev.o
Makefile 0 → 100644
KERNEL_VER := $(shell uname -r)
KERNEL_DIR = '/lib/modules/$(KERNEL_VER)/build'
obj-m := lcd_dev.o
PWD := $(shell pwd)
all :
make -C $(KERNEL_DIR) M=$(PWD) modules
clean :
make -C $(KERNEL_DIR) M=$(PWD) clean
# system_programming
\ No newline at end of file
app2 0 → 100755
File added
app2.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 <arpa/inet.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/sysmacros.h>
#include <sys/socket.h>
#define LCD_DEV_PATH "/dev/lcd_dev"
#define BUFF_SIZE 50
#define INTERVAL 50000
void lcd_convert(char* input, int row) {
unsigned char hex = 0x00;
unsigned char cursor = 0x00;
instr(0x06);
cursor = 0x80 | (row + row * 0x40);
instr(cursor);
for (int i = 0; i < strlen(input); i++) {
hex=0xFF & input[i];
writedata(hex);
}
}
void writedata(unsigned char data) {
unsigned char instr[2] = { 0x00, 0x00 };
instr[0] = data & 0xF0;
instr[1] = (data & 0x0F) << 4; //data shift
int lcd_dev;
lcd_dev = open(LCD_DEV_PATH, O_RDWR);
usleep(40);
char buf[0];
for (int i = 0; i < 2; i++) {
instr[i] |= (1 << 3);
instr[i] |= (1 << 0);
instr[i] &= ~(1 << 1);
instr[i] |= (1 << 2);
buf[0]=instr[i];
write(lcd_dev, buf, 1);
instr[i] &= ~(1 << 2);
buf[0]=instr[i];
write(lcd_dev, buf, 1);
}
}
void instr(unsigned char instr) {
int k=0;
unsigned char instr1[2] = { 0x00, 0x00 };
instr1[0] = instr & 0xF0;
instr1[1] = (instr & 0x0F) << 4;
int lcd_dev;
lcd_dev = open(LCD_DEV_PATH, O_RDWR);
usleep(40);
char buf[1];
for (int i = 0; i < 2; i++) {
instr1[i] &= ~(1 << 3);
instr1[i] &= ~(1 << 0);
instr1[i] &= ~(1 << 1);
instr1[i] |= (1 << 2);
buf[0]=instr1[i];
write(lcd_dev, buf, 1);
instr1[i] &= ~(1 << 2);
buf[0]=instr1[i];
write(lcd_dev, buf, 1);
}
}
int main(void)
{
int server_socket;
int client_socket;
int client_addr_size;
struct sockaddr_in server_addr;
struct sockaddr_in client_addr;
char buff_r[BUFF_SIZE+5];
char buff_s[BUFF_SIZE+5];
int lcd_fd;
char lcd_data;
lcd_fd = open(LCD_DEV_PATH, O_RDWR);
if(lcd_fd < 0){
printf("fail to open LCD sensor device\n");
return 1;
}
server_socket = socket(PF_INET, SOCK_STREAM, 0);
if(server_socket == -1) {
printf("server socket fail\n");
exit(1);
}
memset(&server_addr, 0, sizeof(server_addr));
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(4029);
server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
if(bind(server_socket, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1) {
printf("cannot bind server\n");
exit(1);
}
if(listen(server_socket, 1024) == -1) {
printf("cannot listen\n");
exit(1);
}
listen(server_socket, 3);
client_addr_size = sizeof(client_addr);
client_socket = accept(server_socket, (struct sockaddr *)&client_addr, &client_addr_size);
if(client_socket == -1) {
printf("cannot connect to client\n");
exit(1);
}
char a[32]={
0x34, 0x30, 0x34, 0x30, 0x34, 0x30, 0x24, 0x20, 0x24, 0x20, 0x84, 0x80, 0x4, 0x0,
0x84, 0x80, 0x4, 0x0, 0xE4, 0xE0, 0x4, 0x0, 0x64, 0x60, 0x84, 0x80, 0x4, 0x0, 0x2D,
0x29, 0x1D, 0x19};
char buf[1];
int data=0;
for(int i=0;i<32;i++){
buf[0]=a[i];
lcd_data = buf[0];
write(lcd_fd, buf, 1);
lcd_data = '\0';
}
while(1){
recv(client_socket, buff_r, BUFF_SIZE, 0);
recv(client_socket, buff_s, BUFF_SIZE, 0);
lcd_convert(buff_r,0);
lcd_convert(buff_s,1);
printf("%s %s\n", buff_r, buff_s);
sleep(2);
memset(buff_r, '\0', sizeof(buff_r));
memset(buff_s, '\0', sizeof(buff_s));
}
sleep(1);
close(client_socket);
close(server_socket);
close(lcd_fd);
return 0;
}
app3 0 → 100755
File added
app3.c 0 → 100644
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <math.h>
#include <errno.h>
#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 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
#define IOCTL_MAGIC_NUMBER 'K'
#define IOCTL_MAGIC_NUMBER2 'J'
#define IOCTL_CMD_SET_TEMP_BLINK _IOWR(IOCTL_MAGIC_NUMBER,1,int)
#define IOCTL_CMD_SET_TEMP_OFF _IOWR(IOCTL_MAGIC_NUMBER,2,int)
#define IOCTL_CMD_SET_SOUND_BLINK _IOWR(IOCTL_MAGIC_NUMBER2, 1, int)
#define IOCTL_CMD_SET_SOUND_OFF _IOWR(IOCTL_MAGIC_NUMBER2, 2, int)
int main() {
int temp_fd = open(TEMP_DEV_PATH, O_RDWR);
int sound_fd = open(SOUND_DEV_PATH, O_RDWR);
int sound_data = 0;
int led_fd, led2_fd;
int led_data = 1, led2_data = 1;
__pid_t pid;
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(temp_fd < 0) {
printf("fail to open TEMP sensor device\n");
return 1;
}
config[0] = 0x02;
config[1] = 0x15;
config[2] = 0x40;
for(int i = 0; i < 3; i++) {
write(temp_fd, &config[i], 1);
sleep(1);
}
sleep(1);
int temp = 0, j = 0;
float cTemp = 0, fTemp = 0;
write(temp_fd, &reg, 1);
pid = fork();
if(pid == 0) {
while(1) {
read(sound_fd, &sound_data, sizeof(int));
if(sound_data > 660) {
ioctl(led2_fd, IOCTL_CMD_SET_SOUND_BLINK, &led2_data);
}
printf("data : %d\n", sound_data);
sleep(3);
ioctl(led2_fd, IOCTL_CMD_SET_SOUND_OFF, &led2_data);
}
}
else {
while(1) {
for(int i = 0; i < 2; i++) {
read(temp_fd, &(data[i]), 1);
sleep(1);
}
printf("%d %d\n", data[0], data[1]);
temp = (data[0] * 256 + (data[1] & 0xFC)) / 4;
if(temp > 8191)
{
temp -= 16384;
}
cTemp = temp * 0.03125;
/*
if(j == 0) {
result[0] = cTemp;
j++;
}
else{
if(result[0] != cTemp) {
j = 0;
}
else {
result[0] = cTemp;
j++;
}
}
*/
printf("Temperature in Celsius is : %.2f C \n", cTemp);
if(cTemp > 50) {
ioctl(led_fd, IOCTL_CMD_SET_TEMP_BLINK, &led_data);
}
sleep(3);
ioctl(led_fd, IOCTL_CMD_SET_TEMP_OFF, &led_data);
}
}
close(temp_fd);
close(sound_fd);
close(led_fd);
close(led2_fd);
}
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
lcd_dev.o 0 → 100644
File added
cmd_/home/pi/Desktop/project/led/led_dev.ko := ld -r -EL -T ./scripts/module-common.lds -T ./arch/arm/kernel/module.lds --build-id -o /home/pi/Desktop/project/led/led_dev.ko /home/pi/Desktop/project/led/led_dev.o /home/pi/Desktop/project/led/led_dev.mod.o ; true
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment