diff --git a/smoke/smoke_dev.c b/smoke/smoke_dev.c index f4d08cd399f2c1ae954150601b827411661195a5..6e5c3203d1a49348ac7633b1719990c009283984 100644 --- a/smoke/smoke_dev.c +++ b/smoke/smoke_dev.c @@ -17,14 +17,14 @@ #define GPFSEL0 0x00 #define GPFSEL1 0x04 -#define SPI_CS 0x00 -#define SPI_FIFO 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 *spi_cs, *spi_fifo; +volatile unsigned int *cs, *fifo; int smoke_open(struct inode *inode, struct file *filp){ printk(KERN_ALERT "smoke detection sensor driver open!!\n"); @@ -34,19 +34,19 @@ int smoke_open(struct inode *inode, struct file *filp){ 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); + cs = (volatile unsigned int*)(spi_base + CS); + fifo = (volatile unsigned int*)(spi_base + FIFO); *gpfsel0 &= ~(0x1FF << 21); *gpfsel0 |= (0x24 << 24); *gpfsel1 &= ~(0x3F); *gpfsel1 |= (0x24); - *spi_cs &= ~(0xFFFF); + *cs &= ~(0xFFFF); - *spi_cs &= ~(0x01<<2); - *spi_cs &= ~(0x01<<3); - *spi_cs |= (0x03<<4); + *cs &= ~(0x01<<2); + *cs &= ~(0x01<<3); + *cs |= (0x03<<4); return 0; } @@ -56,7 +56,7 @@ int smoke_release(struct inode *inode, struct file *filp){ *gpfsel0 &= ~(0x1FF << 21); *gpfsel1 &= ~(0x3F); - *spi_cs &= ~(0xFFFF); + *cs &= ~(0xFFFF); iounmap((void*)gpio_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){ 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 transmit_Count = 0, receive_Count = 0, data = 0; + transmit_Data[0] = 1; transmit_Data[1] = (0x08) << 4; 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((*spi_cs & (1<<18)) && (transmit_Count < 3)){ - *spi_fifo = transmit_Data[transmit_Count]; + while((*cs & (1<<18)) && (transmit_Count < 3)){ + *fifo = transmit_Data[transmit_Count]; transmit_Count++; } - while((*spi_cs & (1<<17)) && (receive_Count < 3)){ - receive_Data[receive_Count] = *spi_fifo; + while((*cs & (1<<17)) && (receive_Count < 3)){ + receive_Data[receive_Count] = *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]; + while((!(*cs)) & (1<<16)); - printk(KERN_ALERT "reading input : %d \n", data); + *cs |= (0x03<<4); + *cs &= ~(1<<7); + data = ((receive_Data[1]&0x03)<<8) + receive_Data[2]; copy_to_user(buf, &data, sizeof(int)); return count; diff --git a/smoke/smoke_dev.ko b/smoke/smoke_dev.ko index 46ea2a6e2b6f38b6fe4b9dcccca4485527d6780e..48bf9127b20fce0f817289d3011ca95827bebc64 100644 Binary files a/smoke/smoke_dev.ko and b/smoke/smoke_dev.ko differ diff --git a/smoke/smoke_dev.mod.c b/smoke/smoke_dev.mod.c index e70a1933b1cc76249e855cedf3b604902cddd13f..28ad916f22400e500daf11170e73610755d8ba99 100644 --- a/smoke/smoke_dev.mod.c +++ b/smoke/smoke_dev.mod.c @@ -44,4 +44,4 @@ __attribute__((section(".modinfo"))) = "depends="; -MODULE_INFO(srcversion, "194BCBE501BF825F76154FB"); +MODULE_INFO(srcversion, "167423B1A2B88E719EB6620"); diff --git a/smoke/smoke_dev.mod.o b/smoke/smoke_dev.mod.o index e401880a933fd15ad1ef28a017eb706004b3f0fe..8d67c23ce067eb58f090d74da96d97e7b46260ff 100644 Binary files a/smoke/smoke_dev.mod.o and b/smoke/smoke_dev.mod.o differ diff --git a/smoke/smoke_dev.o b/smoke/smoke_dev.o index cb7d48810a79fdddc6e5ef299873721e8ec8b187..35286893ecc9a281dcfa0de256d385b21667011c 100644 Binary files a/smoke/smoke_dev.o and b/smoke/smoke_dev.o differ