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

library control management Pi final

parent 7fa5bcaa
No related branches found
No related tags found
No related merge requests found
...@@ -17,14 +17,14 @@ ...@@ -17,14 +17,14 @@
#define GPFSEL0 0x00 #define GPFSEL0 0x00
#define GPFSEL1 0x04 #define GPFSEL1 0x04
#define SPI_CS 0x00 #define CS 0x00
#define SPI_FIFO 0x04 #define FIFO 0x04
static void __iomem *gpio_base; static void __iomem *gpio_base;
static void __iomem *spi_base; static void __iomem *spi_base;
volatile unsigned int *gpfsel0, *gpfsel1; volatile unsigned int *gpfsel0, *gpfsel1;
volatile unsigned int *spi_cs, *spi_fifo; volatile unsigned int *cs, *fifo;
int smoke_open(struct inode *inode, struct file *filp){ int smoke_open(struct inode *inode, struct file *filp){
printk(KERN_ALERT "smoke detection sensor driver open!!\n"); printk(KERN_ALERT "smoke detection sensor driver open!!\n");
...@@ -34,19 +34,19 @@ int smoke_open(struct inode *inode, struct file *filp){ ...@@ -34,19 +34,19 @@ int smoke_open(struct inode *inode, struct file *filp){
gpfsel0 = (volatile unsigned int*)(gpio_base + GPFSEL0); gpfsel0 = (volatile unsigned int*)(gpio_base + GPFSEL0);
gpfsel1 = (volatile unsigned int*)(gpio_base + GPFSEL1); gpfsel1 = (volatile unsigned int*)(gpio_base + GPFSEL1);
spi_cs = (volatile unsigned int*)(spi_base + SPI_CS); cs = (volatile unsigned int*)(spi_base + CS);
spi_fifo = (volatile unsigned int*)(spi_base + SPI_FIFO); fifo = (volatile unsigned int*)(spi_base + FIFO);
*gpfsel0 &= ~(0x1FF << 21); *gpfsel0 &= ~(0x1FF << 21);
*gpfsel0 |= (0x24 << 24); *gpfsel0 |= (0x24 << 24);
*gpfsel1 &= ~(0x3F); *gpfsel1 &= ~(0x3F);
*gpfsel1 |= (0x24); *gpfsel1 |= (0x24);
*spi_cs &= ~(0xFFFF); *cs &= ~(0xFFFF);
*spi_cs &= ~(0x01<<2); *cs &= ~(0x01<<2);
*spi_cs &= ~(0x01<<3); *cs &= ~(0x01<<3);
*spi_cs |= (0x03<<4); *cs |= (0x03<<4);
return 0; return 0;
} }
...@@ -56,7 +56,7 @@ int smoke_release(struct inode *inode, struct file *filp){ ...@@ -56,7 +56,7 @@ int smoke_release(struct inode *inode, struct file *filp){
*gpfsel0 &= ~(0x1FF << 21); *gpfsel0 &= ~(0x1FF << 21);
*gpfsel1 &= ~(0x3F); *gpfsel1 &= ~(0x3F);
*spi_cs &= ~(0xFFFF); *cs &= ~(0xFFFF);
iounmap((void*)gpio_base); iounmap((void*)gpio_base);
iounmap((void*)spi_base); iounmap((void*)spi_base);
...@@ -67,37 +67,33 @@ ssize_t smoke_read(struct file* flip, char* buf, size_t count, loff_t* f_pos){ ...@@ -67,37 +67,33 @@ ssize_t smoke_read(struct file* flip, char* buf, size_t count, loff_t* f_pos){
printk(KERN_ALERT "read function called!!\n"); printk(KERN_ALERT "read function called!!\n");
unsigned char transmit_Data[3]; unsigned char transmit_Data[3];
unsigned char receive_Data[3]; unsigned char receive_Data[3];
int transmit_Count = 0; int transmit_Count = 0, receive_Count = 0, data = 0;
int receive_Count = 0;
transmit_Data[0] = 1; transmit_Data[0] = 1;
transmit_Data[1] = (0x08) << 4; transmit_Data[1] = (0x08) << 4;
transmit_Data[2] = 0; transmit_Data[2] = 0;
*spi_cs |= (0x03<<4); *cs |= (0x03<<4);
*spi_cs |= (0x01<<7); *cs |= (0x01<<7);
while((transmit_Count < 3) || (receive_Count < 3)){ while((transmit_Count < 3) || (receive_Count < 3)){
while((*spi_cs & (1<<18)) && (transmit_Count < 3)){ while((*cs & (1<<18)) && (transmit_Count < 3)){
*spi_fifo = transmit_Data[transmit_Count]; *fifo = transmit_Data[transmit_Count];
transmit_Count++; transmit_Count++;
} }
while((*spi_cs & (1<<17)) && (receive_Count < 3)){ while((*cs & (1<<17)) && (receive_Count < 3)){
receive_Data[receive_Count] = *spi_fifo; receive_Data[receive_Count] = *fifo;
receive_Count++; receive_Count++;
} }
} }
while((!(*spi_cs)) & (1<<16)); while((!(*cs)) & (1<<16));
*spi_cs |= (0x03<<4); *cs |= (0x03<<4);
*spi_cs &= ~(1<<7); *cs &= ~(1<<7);
int data = ((receive_Data[1]&0x03)<<8) + receive_Data[2];
printk(KERN_ALERT "reading input : %d \n", data);
data = ((receive_Data[1]&0x03)<<8) + receive_Data[2];
copy_to_user(buf, &data, sizeof(int)); copy_to_user(buf, &data, sizeof(int));
return count; return count;
......
No preview for this file type
...@@ -44,4 +44,4 @@ __attribute__((section(".modinfo"))) = ...@@ -44,4 +44,4 @@ __attribute__((section(".modinfo"))) =
"depends="; "depends=";
MODULE_INFO(srcversion, "194BCBE501BF825F76154FB"); MODULE_INFO(srcversion, "167423B1A2B88E719EB6620");
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment