port_status=readl(GPECON);
port_status&=~GPE_DEFAULT;
port_status|=GPE_DEFAULT;
writel(port_status,GPECON);//GPE control
port_status=0x0;
port_status=readl(GPEUP);
port_status&=~(1<<13|1<<12|1<<11);
writel(port_status,GPEUP);//GPE_UP
port_status=0x0;
port_status=readl(GPGUP);
port_status&=~(1<<2|1<<3|1<<6);
writel(port_status,GPGUP);//GPG_UP
//disable_irq(IRQ_SPI0);
port_status=readl(SPPRE0);//SPI Baud speed
port_status=0x31;//PCLK=50MHz SPICLK=PCLK/2/(value+1)=1MHz,对于CC2500最大支持500K,一般采用250K
writel(port_status,SPPRE0);
port_status=readl(SPCON0);
port_status=SPI_CON_DEFAULT;
writel(port_status,SPCON0);//SPI control
port_status=readl(SPPIN0);
port_status&=~(0<<0|1<<1|1<<2);
port_status|=(1<<2|1<<1|0<<0);
writel(port_status,SPPIN0);//SPI pin setting
port_status=readl(SCRPND);
port_status|=(1<<22);
writel(port_status,SCRPND);
port_status=readl(INTPND);
port_status|=(1<<22);
writel(port_status,INTPND);
//enable_irq(IRQ_SPI0);
}
//-----------------------------------------------------------------------------------------------------------------
static int spi_open(struct inode *inode,struct file *filp)
{
filp->private_data=spi_devp;
mini2440_spi_config();
//filep->private_data=spi_devp;
s3c2410_gpio_setpin(S3C2410_GPG(2),0);
printk("-----------------------------------\n");
printk("MINI2440 SPI GPG GPE CLK set over\n");
printk("-----------------------------------\n");
return 0;
}
static int spi_release(struct inode *inode,struct file *filp)
{
printk("-----------------------------\n");
printk("S3C2440-mini2440_spi closed\n");
printk("------------------------------\n");
return 0;
}
//-----------------------------------------------------------------------------------------------------------
static ssize_t spi_read(struct file *filp,char __user *buf,size_t count)
{
//char *spiRxData;
struct spi_dev *dev=filp->private_data;
copy_to_user(buf,dev->dataRx,count);
return 0;
}
static ssize_t spi_write(struct file *filp,char __user *buf,size_t count)
{
volatile int endSpiTx=0;
volatile char spiTxData[4];
//int config;
int i=0;
//char str[20];
//char *txStr,*rxStr;
//volatile char *spiTxStr,*spiRxStr;
unsigned char string;
unsigned int port_status;
struct spi_dev *dev=filp->private_data;
//filp->private_data;
//获得设备结构体的指针
copy_from_user(dev->dataTx,buf,count);
for(i=0;i<4;i++)
{
spiTxData[i]=dev->dataTx[i];
}
printk("receive form user is %s\n",spiTxData);
while(endSpiTx==0)
{
//if(*spiTxData!='\0')
while(!SPI_TXRX_READY)
printk("SPI TXRX unready\n");
for(i=0;i<4;i++)
{
//s3c2410_gpio_setpin(S3C2410_GPG(2),0);//使能从SPI
writeb(spiTxData[i],SPTDAT0);//=*(spiTxData++);
string=readb(SPTDAT0);
printk("transfer char=%c\n",string);
//while(!SPI_TXRX_READY);
dev->dataRx[i]=readb(SPRDAT0);
printk("----------------------------\n");
printk("receive char=%c\n",dev->dataRx[i]);
printk("----------------------------\n");
//s3c2410_gpio_setpin(S3C2410_GPG(2),1);//解除使能从SPI
//i++;
}
endSpiTx=1;
}
port_status=readl(SPCON0);
port_status|=((0<<5)|(0<<4)|(1<<3)|(1<<2)|(0<<1)|(0<<0));
writel(port_status,SPCON0);
return 0;
}
//---------------------------------------------------------------------------------------------------------------
static const struct file_operations spi_fops={
.owner=THIS_MODULE,
.open=spi_open,
.release=spi_release,
.read=spi_read,
.write=spi_write,
};
static void spi_interrupt(int irq,void *dev_id,struct pt_regs *reg)
{
unsigned int port_status;
unsigned int i=0;
volatile int endSpiRx=0;