⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 s3c2410_spi_cc1100-driver.c~

📁 s3c2410开发板中使用cc1100无线模块的linux驱动
💻 C~
字号:
#include "CC1100.h"MODULE_DESCRIPTION("My kernel module");MODULE_AUTHOR("root (root@Figo)");MODULE_LICENSE("GPL");int CC1100_MAJOR=0;int CC1100_MINOR=0;//static struct tasklet_struct tasklet;static int cc1100_open(struct inode * inode,struct file *filp);static int cc1100_release(struct inode * inode,struct file *filp);static ssize_t cc1100_write(struct file *filp,const char *buf,size_t count,loff_t *ppos);static ssize_t cc1100_read(struct file *filp,char __user *buf,size_t count,loff_t *ppos);static int s3c2410_spi_cc1100_probe(struct device *dev);static int s3c2410_spi_cc1100_remove(struct device *dev);static unsigned char rxbuf[8]={0};static struct file_operations cc1100_fops={	.owner=		THIS_MODULE,	.open=		cc1100_open,	.write=		cc1100_write,	.read=		cc1100_read,	.release=	cc1100_release,};static struct device_driver  s3c2410_spi_cc1100_driver={	.name=		"s3c2410_spi_cc1100",	.bus=		&platform_bus_type,	.probe=		s3c2410_spi_cc1100_probe,	.remove=	s3c2410_spi_cc1100_remove,};static int cc1100_open(struct inode * inode,struct file *filp){			CpuInit();	POWER_UP_RESET_CC1100();	halRfWriteRfSettings();	halSpiWriteBurstReg(CCxxx0_PATABLE, PaTabel, 8);	halSpiStrobe(CCxxx0_SRX);	return 0;}static int cc1100_release(struct inode * inode,struct file *filp){	return 0;}static ssize_t cc1100_write(struct file *filp,const char *buf,size_t count,loff_t *ppos){	char kbuf[8]={0};	copy_from_user(kbuf,buf,count);	halRfSendPacket(kbuf,count);	halSpiStrobe(CCxxx0_SRX);	return count;	}static ssize_t cc1100_read(struct file *filp,char __user *buf,size_t count,loff_t *ppos){	char kbuf[8]={0};	unsigned char length=count;	if(halRfReceivePacket(kbuf,&length))	{			copy_to_user(buf,kxbuf,count);		halSpiStrobe(CCxxx0_SRX);		return count;	}	halSpiStrobe(CCxxx0_SRX);	return 0;}dev_t cc1100_devt;static struct cdev * cc1100_cdev;static int s3c2410_spi_cc1100_probe(struct device *dev){	int result;	printk("s3c2410_spi_cc1100_probe!\n");	/*register the driver to system*/	result=alloc_chrdev_region(&cc1100_devt,CC1100_MINOR,1,"s3c2410_spi_cc1100");	CC1100_MAJOR=MAJOR(cc1100_devt);		if(result<0)	{		printk(KERN_ERR"Can`t get the major number %d for CC1100\n",CC1100_MAJOR);		return -1;	}	cc1100_cdev=cdev_alloc();	if(cc1100_cdev!=NULL)	{		cdev_init(cc1100_cdev,&cc1100_fops);		cc1100_cdev->ops=&cc1100_fops;		cc1100_cdev->owner=THIS_MODULE;		if(cdev_add(cc1100_cdev,cc1100_devt,1))			printk(KERN_NOTICE"Can`t add this driver to system!\n");		else			printk(KERN_NOTICE" add this driver to system succefully!\n");	}	else 	{		printk(KERN_ERR"cdev_alloc error!\n");		return -1;	}	devfs_mk_cdev(MKDEV(CC1100_MAJOR,CC1100_MINOR),S_IFCHR|S_IRUSR|S_IWUSR,"cc1100");	s3c2410_gpio_cfgpin(SCK,S3C2410_GPE13_OUTP);	s3c2410_gpio_cfgpin(CSN,S3C2410_GPE14_OUTP);	s3c2410_gpio_cfgpin(MOSI,S3C2410_GPE12_OUTP);	s3c2410_gpio_cfgpin(MISO,S3C2410_GPE11_INP);	s3c2410_gpio_cfgpin(GDO0,S3C2410_GPE15_INP);	return 0;}static int s3c2410_spi_cc1100_remove(struct device *dev){	unregister_chrdev_region(cc1100_devt,1);	return 0;}static int __init s3c2410_spi_cc1100_init_module(void){	printk( KERN_DEBUG "Module s3c2410_spi_cc1100 init\n" );	driver_register(&s3c2410_spi_cc1100_driver);	return 0;}static void __exit s3c2410_spi_cc1100_exit_module(void){	printk( KERN_DEBUG "Module s3c2410_spi_cc1100 exit\n" );	driver_unregister(&s3c2410_spi_cc1100_driver);	cdev_del(cc1100_cdev);	devfs_remove("cc1100");}module_init(s3c2410_spi_cc1100_init_module);module_exit(s3c2410_spi_cc1100_exit_module);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -