문제점 좀 지적해 주세요...
글쓴이: pdjj14 / 작성시간: 목, 2005/10/20 - 3:32오후
spi 모듈을 작성했습니다...
그런데 크로스 컴파일 해서 올리면...
insert 까지는 되는데...
오픈하는 순간 다시 릴리즈 되어 버리네요...
문제점 좀 해결해 주세요...
코드 올립니다...
다른 문제점도 발견되면 말씀해 주세요...
참...리드도 인식이 안되더군요...ㅠㅠ...
컴파일 할 때, initialization from incompatible pointer type 라는 메시지가 나오더군요...
롸이트는 아직 코딩 안 했구요...
----------------------------------------------------------------
/********************************************************************************* * * SPI Standalone Microwire Device Driver for LINUX based on PXA255 * by Jae Joong Han * ********************************************************************************* */ #ifndef __KERNEL__ # define __KERNEL__ #endif #ifndef MODULE # define MODULE #endif #include <linux/config.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/slab.h> #include <linux/fs.h> #include <linux/errno.h> #include <linux/types.h> #include <linux/proc_fs.h> #include <linux/fcntl.h> #include <linux/ioport.h> #include <linux/vmalloc.h> #include <linux/ioctl.h> #include <linux/init.h> #include <asm/system.h> #include <asm/irq.h> #include <asm/io.h> #include <asm/uaccess.h> #include <asm/hardware.h> #include <asm/arch-pxa/pxa-regs.h> #define SSP 0x41000000 #define SSCR0_OFFSET 0x00 #define SSCR1_OFFSET 0x04 #define SSDR_OFFSET 0x10 #define SSSR_OFFSET 0x08 static void *ssp_base; #define MODULE_VERSION "1.0" #define MODULE_NAME "SPI" #define SPI_MAJOR 114 #define DEVICE_NAME "spi" static int tiny_spi_usage = 0; int tiny_spi_open(struct inode *inode, struct file *file) { int b; if( tiny_spi_usage != 0 ) return -EBUSY; /* already use? */ MOD_INC_USE_COUNT; tiny_spi_usage = 1; printk("TINY SPI DEVICE OPEN\n"); for(b=0;b<9;b++) printk("count = %d\n", b); return 0; } int tiny_spi_release(struct inode *inode, struct file *file) { tiny_spi_usage = 0; printk("TINY SPI DEVICE CLOSE\n"); MOD_DEC_USE_COUNT; return 0; } ssize_t tiny_spi_write(struct file *file, const char *data, size_t len, loff_t *offset) { return(1); } ssize_t tiny_spi_read(struct file *file, const char *data, size_t len, loff_t *offset) { int sspdata, status, temp; u8 buffer[20]; u8 *w_data; u8 k_data; unsigned int i,j; i = 0; j = 0; printk("check1\n"); while((status = readl(ssp_base + SSSR_OFFSET)) != 0 ) /* read the status register */ { printk("check2\n"); temp = readl(ssp_base + SSDR_OFFSET); buffer[j++] = (u8)(temp >> 8); /* read the receive FIFO to clear out old stuff */ } printk("check3\n"); #ifdef M_DEBUG printk("old Data [ "); for(i=0 ; i<j ;i++) printk(" 0x%02X ", buffer[i]); printk("], i:%d\n",i); i=j=0; #endif printk("check4\n"); // w_data = data; for(i=0 ; i<len ; i++) { printk("check5\n"); k_data = w_data[i]; writel(k_data << 8, ssp_base + SSDR_OFFSET); } printk("check6\n"); #ifdef M_DEBUG printk("Written Data [ "); for(j=0 ; j<i ;j++) printk(" 0x%02X ", w_data[j]); printk("], j:%d\n",j); j=0; #endif printk("check7\n"); while((status = readl(ssp_base + SSSR_OFFSET)) != 0) { printk("check8\n"); sspdata = readl(ssp_base + SSDR_OFFSET); buffer[j++] = (u8)sspdata; } printk("check9\n"); #ifdef M_DEBUG printk("Read Data [ "); for(i=0 ; i<j ;i++) printk(" 0x%02X ", buffer[i]); printk("], j:%d\n",j); #endif printk("check10\n"); for(i=0 ; i<j ; i++) {printk("check11\n"); // *data++ = buffer[i]; } return (1); } static struct file_operations tiny_spi_fops = { read: tiny_spi_read, write: tiny_spi_write, open: tiny_spi_open, release: tiny_spi_release, }; int init_module(void) { int result; unsigned int r; ssp_base = ioremap_nocache(SSP,0x2000000); printk("ssp_base = 0x%08X\n",ssp_base); /* * SSCR1 binary value 0000 0000 0000 0000 = 0x0000 * External Clock Select (ECS), 0 uses internal clock * Serial Clock Phase (SPH), 0 adds 1 clock cycle delay * Serial Clock Polarity (SPO), 0 holds SC low during idle * Loopback Mode (LBM), 0 diables loopback mode * Transmit FIFO Interrupt Enable (TIE), 0 masks interrupt * Receive FIFO Interrupt Enable (RIE), 0 masks interrupt */ writel(0x0020, ssp_base + SSCR1_OFFSET); /* * SSCR0 binary value 1111 1111 1000 0111 = 0xFF87 * Data Size Select (DSS), 0111 selects 8 bit length * Frame Format (FRF), 00 selects Motorola SPI * Synchronous Serial Port Enable (SSE), 1 for enable * Serial Clock Rate (SCR), 11111111 selects slowest clock */ writel(0xFFA0, ssp_base + SSCR0_OFFSET); /* read the registers and printout results */ r = readl(ssp_base + SSCR1_OFFSET); printk("SSCR1 = 0x%04X\n",r); r = readl(ssp_base + SSCR0_OFFSET); printk("SSCR0 = 0x%04X\n",r); /* everything initialized */ printk(KERN_INFO "%s %s initialized\n", MODULE_NAME, MODULE_VERSION); /* Register the character driver */ result = register_chrdev( SPI_MAJOR, DEVICE_NAME, &tiny_spi_fops ); printk("%d....\n", result); if (result < 0) { printk(KERN_WARNING "SPI: Can't get Major Number [%d]\n", SPI_MAJOR); return result; } printk(" Init madule, Succeed. This Device is [%s] and Major Number is [%d]\n", DEVICE_NAME, SPI_MAJOR); return 0; } void cleanup_module(void) { iounmap(ssp_base); if ( !unregister_chrdev( SPI_MAJOR, DEVICE_NAME) ) { printk(KERN_INFO "%s %s removed\n", MODULE_NAME, MODULE_VERSION); } else { printk("SPI Device EXIT FAIL.\n"); } }
Forums:
댓글 달기