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

📄 8025.c

📁 RX8025 linux 驱动程序 RX8025 linux 驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
 *
 *参数:TIME *times :用来存放时间的结构体 *功能:对时间的数据进行判断,调用8025芯片写寄存器函数:把要设置的时间存放在 *		 0(秒)1(分)2(时)寄存器中。设置时间前必须现设置 e寄存器 *		选择 12 /24 显示方法,每次写入寄存器,立即读出寄存器的值,确保写入正确		 *
 *返回直:没有意义
********************************************************************************/
int settime(TIME *times)
 {		
	char ch[2];
  		/* 第一步、设置 秒 寄存器 */
	ch[0] = 0x00;
	ch[1] = rec(times->sec) ;	//转换要写入的数据		if(ch[1] > 0x59) 			//判断 秒 数值 是否 超出 	{		printk("The Sceond is Wrong\n");		return 1;	}	do{			setEreg();			//设置 时间格式寄存器 E 寄存器 			while(T11_TWI_WriteMultiple(ch,2) != 0);		// 写寄存器	}while(compile(ch[1],2));	//读取写入 判断 写入是否成功 	/* 第二步、设置 分 寄存器 */	/* 日期寄存器 是 1号 寄存器 ,把转换后的数据 存放进 1号寄存器*/	/* 每次写入在读出比较,确保日期设置正确 */
 	ch[0] = 0x10;
 	ch[1] = rec(times->min);		if(ch[1] > 0x59)			 	{		printk("The Minute is Wrong\n");		return 1;	}	do{		setEreg();					while(T11_TWI_WriteMultiple(ch,2) != 0);		}while(compile(ch[1],3));
	/* 第三步、设置 小时 寄存器 */	/* 小时 寄存器 是 2号 寄存器 ,把转换后的数据 存放进 2号寄存器*/	/*	每次写入在读出比较,确保日期设置正确 */
	ch[0] = 0x20;
	ch[1] = rec(times->hour);	if(((ch[1] > 0x24) && (hourmode == 1)) || ((ch[1] > 0x12) && (hourmode == 0)))	{		printk("The Hour is Wrong\n");				return 1;	}                                                               	do{		setEreg();				while(T11_TWI_WriteMultiple(ch,2) != 0);	}while(compile(ch[1],4));			return 0;       
}/*******************************************************************************
 *函数:设置日期的函数			 * *参数:TIME *times :用来存放时间的结构体 *功能:对时间的数据进行判断,调用8025芯片写寄存器函数:把要设置的时间存放在 *		 4(秒)5(分)6(时)寄存器中。设置时间前必须现设置 e寄存器 *		选择 12 /24 显示方法,每次写入寄存器,立即读出寄存器的值,确保写入正确		 *		 *
 *返回直:没有意义
********************************************************************************/
int setdate(TIME * times)
 {	char ch[2];				/* 日期寄存器 是 4号 寄存器 ,把转换后的数据 存放进 4号寄存器*/	 /*	每次写入在读出比较,确保日期设置正确 */	
	ch[0] = 0x40;			
	ch[1] = rec(times->day);				/* 判断 数据的 正确性 */	if(ch[1] > 0x31 || ((times->day > 29) && (times->month == 2)))	{		printk("The Day is Wrong\n");		return 1;	}	/* 设置 日期 */
	do{		setEreg();						while(T11_TWI_WriteMultiple(ch,2) != 0);	}while(compile(ch[1],6));	
       
	/* 月 寄存器 是 5号 寄存器 ,把转换后的数据 存放进 5 号寄存器	 *	每次写入在读出比较,确保日期设置正确 */
	ch[0] = 0x50;
	ch[1] = rec(times->month);	if(ch[1] > 0x12)	{		printk("The Month is Wrong\n");		return 1;	}	do{		setEreg();			while(T11_TWI_WriteMultiple(ch,2) != 0);	}while(compile(ch[1],7));

 	/* 年 寄存器 是 6 号 寄存器 ,把转换后的数据 存放进 6 号寄存器	 *	每次写入在读出比较,确保日期设置正确 */  
	ch[0] = 0x60;
	ch[1] = rec(times->year);	if(ch[1] > 0x99)	{		printk("The Year is Wrong\n");		return 1;	}	do{			setEreg();	
		while(T11_TWI_WriteMultiple(ch,2) != 0);	}while(compile(ch[1],8));	return 0;      
}/*******************************************************************************
 *函数:设置星期哦的函数
 *参数:TIME *times :用来存放星期的结构体 *功能:调用8025芯片写寄存器函数:把要设置的时间存放在 3(星期) *		寄存器中。设置时间前必须现设置 e寄存器选择 12 /24 显示方法。		 *
 *返回直:没有意义
********************************************************************************/
int setweek(TIME *times)
{
 	char ch[2];		/* 星期 寄存器 是 3 号 寄存器 ,把转换后的数据 存放进 3 号寄存器	 *	每次写入在读出比较,确保日期设置正确 */
	ch[0] = 0x30;
	ch[1] = rec(times->week) ;		if(ch[1] > 0x6)	{		printk("The Week is Wrong\n");		return 1;	}
	do{		setEreg();			while(T11_TWI_WriteMultiple(ch,2) != 0);	}while(compile(ch[1],5));	return 0;
}/*******************************************************************************
 *函数:驱动open函数
 *参数: *功能:初始化TWI 保证能于8025芯片通信正常。被用户应用程序open()调用 *		。		 *
 *返回直:没有意义
********************************************************************************/static int R8025_open(struct inode *inode, struct file *filp){	AT9_TWI_init();		//TWI 初始化 函数#ifdef R8025_DEBUG	printk(KERN_ALERT"OPEN:entry open fun \n");#endif	return 0;	}/*******************************************************************************
 *函数:驱动write函数
 *参数: *功能:用来设置时间日期的,把用户传来的结构体指针 buf 拷贝到内核空间, *		调用设置时间的函数,把时间日期等写到寄存器上,通过。		 *
 *返回直:没有意义
********************************************************************************/static ssize_t R8025_write(struct file *file, const char __user *buf, size_t count, loff_t *f_pos){		TIME set;	if(copy_from_user((void *) &set, (void *)buf, 28))	{#ifdef R8025_DEBUG		printk("Copy_form_user: Error\n");#endif				return 0;	}	/* 通过设置标志控制,来设置 时间日子 星期 */	switch(flag)	{		case Settime: 			//设置 时间			if(settime(&set))					{				return 0;			}			break;		case Setweek: 			//设置 星期			if(setweek(&set))					{				return 0;			}			break;		case Setdate: 			//设置  日子			if(setdate(&set))					{				return 0;			}			break;			case Setall:				//全部设置 年月 星期 时间		default: 			if(setdate(&set) || setweek(&set) || settime(&set))			{				return 0;			}			break;			}	/* 时间格式 设置标志 清零 */	flag = 0;	hourmode = 0;		return 1;}/*******************************************************************************
 *函数:驱动read函数
 *参数: *功能:用来读出时间日期的,存放在结构题read上。把该的结构体指针 read传给用户, *				
 *返回直:没有意义
********************************************************************************/static ssize_t R8025_read(struct file *file,  char __user *buf, size_t count, loff_t *f_pos){			TIME read;	/* 读取 时间 */	if(get_8025_data(&read))	{		printk(KERN_ALERT" read the data: error \n");		return 0;	}	/* 将读取的数据 传会用户程序 */	if(copy_to_user(buf,(void*)&read,28))	{		printk(KERN_ALERT "copy_to_user:error\n");		return 0;	}	return 1;}/*******************************************************************************
 *函数:驱动close函数
 *参数: *功能:没有意义, *				
 *返回直:没有意义
********************************************************************************/static int R8025_release(struct inode *inode, struct file *filp){	#ifdef R8025_DEBUG	printk(KERN_ALERT "R8025:  release \n");#endif	return 0;}/*******************************************************************************
 *函数:驱动close函数
 *参数:cmd:是时间格式跟设置时间标志的参数:格式为:时间格式 | 设置时间标志 *			其中前4位为时间格式。后四位为设置选择标志			 *功能:配合write()实现,独立设置日期或者时间等功能, *				
 *返回直:没有意义
********************************************************************************/static int R8025_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg){	flag = (cmd & 0xf);		//设置时间的标志 							//1表示 单独设置时间  2表示 单独设置 星期 3表示 单独设置年月日	hourmode = cmd >> 4;		//设置时间的格式			1表示 24小时制  0表示 12小时制#ifdef R8025_DEBUG	printk(KERN_ALERT "The Flag :%d;\nThe Hourmode :%d \n",flag,hourmode);	printk(KERN_ALERT "This is ioctl fun \n");#endif	return 0;}/************************************************************************** **************** 时钟芯片驱动操作结构体 ***************************** **************************************************************************/struct file_operations R8025_fops = {	 read:R8025_read,	 write:R8025_write,	 open:R8025_open,	 release:R8025_release,	 ioctl:R8025_ioctl,};/* 模块 初始化函数 */ static int init_8025_init(void){	int rc;		/* 映射 TWI PMC */	twi_base = ioremap (AT91SAM9261_BASE_TWI,0x4);	pmc_base = ioremap (AT91_PMC_BASE,0x4);	/* 注册字符设备 */	if ((rc = register_chrdev(R8025_MAJOR, DEVICENAME , &R8025_fops)) < 0){		printk("R8025 driver: can't get major %d\n", R8025_MAJOR);		return 1;	}	printk("The R8025_MAJOR:%d \n",R8025_MAJOR);	printk (KERN_ALERT"Init R8025 chip.\n");		/* 初始化 TWI */	AT9_TWI_init();	return 0;}/* 模块 退出 函数 */void cleanup_8025_exit(void){	printk(KERN_ALERT "Unregister 8025.\n");		/* 注销字符设备 */	unregister_chrdev(R8025_MAJOR, DEVICENAME);	/* 取消 ioremap */		iounmap (twi_base);	iounmap (aic_base);}/*******************************************************************************
 *函数:初始化TWI的函数
 *参数:void *功能:对TWI 的初始化,是7其能正常与8025芯片通信。其中8025为从器件 *		。		 *
 *返回直:没有意义
********************************************************************************/void AT9_TWI_init (void){	/* Init the twi pin */	at91_set_A_periph (AT91_PIN_PA7, 1);	at91_set_A_periph (AT91_PIN_PA8, 1);	/*使能 TWI 时钟 */	AT91_PMC_EnableTWIClock ();	/* 复位 */	AT91_TWI_Reset();	/*配置 TWI 寄存器 */	AT91_TWI_Configure ();	/* 设置 TWI 时钟 */	AT91_TWI_SetClock ();	//printk("_______________IN:init\n");}/*使能 TWI 时钟 */void AT91_PMC_EnableTWIClock(void){	at91_pmc_write (0x10, AT91_PMC_PCK3);}/* 复位 */void AT91_TWI_Reset(void){	at91_twi_write (AT91_TWI_CR, AT91_TWI_SWRST);}/*配置 TWI 寄存器 */void AT91_TWI_Configure(void){	at91_twi_write (AT91_TWI_IDR, 0xffffffff);	at91_twi_write (AT91_TWI_CR, AT91_TWI_SWRST);	at91_twi_write (AT91_TWI_CR, AT91_TWI_MSEN);}/* 设置 TWI 时钟 */void AT91_TWI_SetClock (void){	at91_twi_write(AT91_TWI_CWGR, 0x1f6f6);}module_init(init_8025_init);module_exit(cleanup_8025_exit);MODULE_LICENSE("GPL");MODULE_AUTHOR("Karsten Jeppesen <karsten@jeppesens.com>");MODULE_DESCRIPTION("Driver for the Total Impact briQ front panel");

⌨️ 快捷键说明

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