亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? 1wire.c

?? freescale的關于Imax21的1wire程序,好用
?? C
字號:
/*! \brief file header
 *         the source file for 1wire driver  
 * 
 * File Name: onewire.c
 *
 * Programers: 
 *
 * Date of Creations:   20 Oct,2003
 *
 * Synopsis:
 *
 * Descirption:
 * 	Driver for the DB-MX21 OneWire 
 *
 * Modification History:
 * 
 *
 */

#include <linux/module.h>
#include <linux/version.h>

#include <linux/init.h>
#include <linux/fs.h>
#include <linux/delay.h>
#include <linux/poll.h>
#include <asm/uaccess.h>

#include <linux/string.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/types.h>
#include <linux/fcntl.h>
#include <linux/interrupt.h>
#include <linux/ptrace.h>
#include <linux/ioport.h>
#include <linux/in.h>
#include <linux/miscdevice.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/string.h>
#include <linux/init.h>
#include <asm/bitops.h>
#include <asm/io.h>
#include <linux/errno.h>
#include <linux/tqueue.h>
#include <linux/wait.h>

#include <asm/irq.h>
#include <asm/arch/hardware.h>
#include <asm/arch/irqs.h>
#include <asm/arch/mx2.h>
#include <linux/pm.h>


///register definition
#define _reg_OWIRE_CTRL0			(*((volatile u16*)(MX2_IO_ADDRESS(0x10009000))))	///  16bit owire control reg
#define _reg_OWIRE_TIME_DIV0		(*((volatile u16*)(MX2_IO_ADDRESS(0x10009002))))	///  16bit owire time divider reg
#define _reg_OWIRE_RESET0			(*((volatile u16*)(MX2_IO_ADDRESS(0x10009004))))	///  16bit owire reset reg


#define MODULE_NAME "Owire"
//#define DBMX_DEBUG 1
#ifdef DBMX_DEBUG
#define TRACE(fmt, args...) \
	{ \
		printk("\n %s:%d:%s:",__FILE__, __LINE__,__FUNCTION__); \
		printk(fmt, ## args);\
	}
#else
#define TRACE(fmt, args...)
#endif

#define FAILED(fmt, args...) \
	{ \
		printk("\n %s:%d:%s:",__FILE__, __LINE__,__FUNCTION__); \
		printk(fmt, ## args);\
	}

#define INFO(fmt, args...) \
	{ \
		printk("\n"); \
		printk(fmt, ## args);\
	}



///Private Function Declearation
static int Owire_open(struct inode * inode, 
		struct file * filp);
static int Owire_release(struct inode * inode, 
		struct file * filp);
static int Owire_fasync(int fd, 
		struct file *filp, 
		int mode);
ssize_t Owire_read(struct file * filp, 
					char * buf, 
					size_t count, 
					loff_t * l);
static ssize_t Owire_write(struct file *file, 
							const char *buffer, 
							size_t count, 
							loff_t *ppos);
static int Owire_ioctl(struct inode * inode, 
		struct file *filp,
		unsigned int cmd , 
		unsigned long arg);
static unsigned int Owire_poll(struct file * filp, 
		struct poll_table_struct * wait);



/// globale variables
struct file_operations g_Owire_fops = {
	open:           Owire_open,
	release:        Owire_release,
	write:          Owire_write,
	read:           Owire_read,
	poll:           Owire_poll,
	ioctl:          Owire_ioctl,
	fasync:         Owire_fasync,
};

static devfs_handle_t g_devfs_handle;
int g_Owire_major = 0;

struct pm_dev *g_Owire_pm;

static int g_Owire_status;
#define OWIRE_OPEN_STATUS		0x0001
#define OWIRE_SUSPEND_STATUS	0x0002

/**
 * Function Name: Owire_open
 *
 * Input: 		inode	:
 * 				filp	:
 * Value Returned:	int	: Return status.If no error, return 0.
 *
 * Description: allocate resource when open the inode
 *
 */
int Owire_open(struct inode * inode, struct file * filp)
{
	///set AIPI1_PSR0 bit[9] and clear AIPI1_PSR1bit[9] to match 1-wire bus width 16bits
	_reg_AIPI1_PSR0 |= 0x00200;
	_reg_AIPI1_PSR1 &= ~0x00200;
	
	TRACE("_reg_AIPI1_PSR0=%x, _reg_AIPI1_PSR1=%x \n",_reg_AIPI1_PSR0,_reg_AIPI1_PSR1);
	///enable clk
	_reg_CRM_PCCR1 |= 0x80000000;
	///GPIO config
	_reg_GPIO_GIUS(GPIOE) &= ~0x00010000;
	_reg_GPIO_GPR(GPIOE) |= 0x00010000;
	
   	///reset the 1-wire module
  	_reg_OWIRE_RESET0 |= 1;
  	_reg_OWIRE_RESET0 = 0;
 	
  	///set the time devider to get the 1M clk from the main clock
	_reg_OWIRE_TIME_DIV0 = 0x2B;


	_reg_OWIRE_CTRL0 |= 0x80;//control register bit 7 = 1;
	///check if PST is set
	udelay(610);
	TRACE("_reg_OWIRE_CTRL0 = %x \n",_reg_OWIRE_CTRL0);
	///check if RPP self cleared
	udelay(400);
	TRACE("_reg_OWIRE_CTRL0 = %x \n",_reg_OWIRE_CTRL0);
	g_Owire_status = OWIRE_OPEN_STATUS;

	MOD_INC_USE_COUNT;
	return 0;
}

/*!
 * Function Name: Owire_release
 *
 * Input: 		inode	:
 * 			filp	:
 * Value Returned:	int	: Return status.If no error, return 0.
 *
 * Description: release resource when close the inode
 *
 */
int Owire_release(struct inode * inode, struct file * filp)
{ 
	g_Owire_status &= ~OWIRE_OPEN_STATUS;
	//disable clk
	_reg_CRM_PCCR1 &= ~0x80000000;
	MOD_DEC_USE_COUNT;
	return 0;
}

/**
 * Function Name: Owire_read
 *
 * Input: 		filp	: the file 
 * 			buf	: data buffer
 * 			count	: number of chars to be readed
 * 			l	: offset of file
 * Value Returned:	int	: Return status.If no error, return 0.
 *
 * Description: read device driver
 *
 */
ssize_t Owire_read(struct file * filp, char * buf, size_t count, loff_t * l)
{
	int i,j;
	char tmp,value;
	char *pBuf;
	pBuf = buf;
	TRACE("count = %d \n",count);
	for(i=0;i<count;i++)
	{
		value = 0;
		for(j=0;j<8;j++)
		{
			///control register bit 4 = 1
			//_reg_OWIRE_CTRL0 &= 0xEF;
			_reg_OWIRE_CTRL0 |= 0x10;
			udelay(117);
			
			tmp = (_reg_OWIRE_CTRL0 & 0x08)? 1:0;
			value |= tmp<<j; 
		}
		TRACE("value %d = %x \n",i,value);
		__copy_to_user(pBuf,&value,1);
		pBuf++;
		
	}
	TRACE("read finished \n");
	return count;
}

/**
 * Function Name: Owire_write
 *
 * Input: 		filp	: the file
 * 			buf	: data buffer
 * 			count	: number of chars to be read
 * 			l	: offset of file
 * Value Returned:	int	: Return status.If no error, return 0.
 *
 * Description: write device driver
 *
 */
ssize_t Owire_write(struct file *file, const char *buffer, size_t count, loff_t *ppos)
{
	int 	i,j;
	char 	value,tmp;

	for(i=0;i<count;i++)
	{
		__copy_from_user(&value,buffer,1);
		TRACE("value = %x \n",value);
		for(j=0; j<8; j++)
		{
			tmp = value & 0x01;
			if(tmp == 0)
			{///control register bit 5 = 1
				_reg_OWIRE_CTRL0 |= 0x20;
				udelay(117);
			}
			else if(tmp == 1)
			{///control register bit 4 = 1
				_reg_OWIRE_CTRL0 |= 0x10;
				udelay(117);
			}
			value>>=1;
		}
		buffer++;
	}
	TRACE("write finished \n");
	return count;
}

/**
 * Function Name: Owire_fasync
 *
 * Input: 		fd	:
 * 			filp	:
 * 			mode	:
 * Value Returned:	int	: Return status.If no error, return 0.
 *
 * Description: provide fasync functionality for select system call
 *
 */
static int Owire_fasync(int fd, struct file *filp, int mode)
{	
	return 0;
}
/**
 * Function Name: check_device
 *
 * Input: 		inode	:
 * Value Returned:	int	: Return status.If no error, return 0.
 *
 * Description: verify if the inode is a correct inode
 *
 */
static int check_device(struct inode *pInode)
{
	int minor;
	kdev_t dev = pInode->i_rdev;
	
	if( MAJOR(dev) != g_Owire_major)
	{
		printk("Owire: check_device bad major = %d\n",MAJOR(dev) );
		return -1;
	}
	minor = MINOR(dev);
	
	if ( minor < 1 )
		return minor;
	else
	{       
		printk("Owire: check_device bad minor = %d\n",minor );
		return -1;
	}
}

/**
 * Function Name: Owire_ioctl
 *
 * Input: 	inode	:
 * 			filp	:
 * 			cmd	: command for ioctl
 * 			arg	: parameter for command
 * Value Returned:	int	: Return status.If no error, return 0.
 *
 * Description: ioctl for this device driver
 *
 * 	
 */
int Owire_ioctl(struct inode * inode, 
		struct file *filp,
		unsigned int cmd , 
		unsigned long arg)
{
	int ret = -EIO;
	int minor;	
	
	minor = check_device( inode );
	if ( minor == - 1)
	{
		printk("OneWire_ioctl:bad minor\n");
		return -ENODEV;
	}
	
	printk("OneWire_ioctl:minor=%08x cmd=%d\n",minor,cmd);
	
	return ret;
}

/**
 * Function Name: Owire_poll
 *
 * Input: 		filp	:
 * 			wait	: 
 * Value Returned:	int	: Return status.If no error, return 0.
 *
 * Description: support poll and select
 *
 */
unsigned int Owire_poll(struct file * filp, struct poll_table_struct * wait)
{	
	return 0;
}

int Owire_pm_handler(struct pm_dev *dev, pm_request_t rqst, void *data)
{
	switch(rqst){
		case PM_RESUME:
			if((g_Owire_status & OWIRE_SUSPEND_STATUS)!=0)
			{
				//enable clk
				_reg_CRM_PCCR1 |= 0x80000000;
				g_Owire_status &= ~OWIRE_SUSPEND_STATUS;
			}
			break;
		case PM_SUSPEND:
			if((g_Owire_status & OWIRE_OPEN_STATUS)!=0)
			{
				//disable clk
				_reg_CRM_PCCR1 &= ~0x80000000;
				g_Owire_status |= OWIRE_SUSPEND_STATUS;
			
			}
			break;
		default:
			break;
		}
	return 0;
}
/**
 * Function Name: init_module
 *
 * Input: 		void	:
 * Value Returned:	int	: Return status.If no error, return 0.
 *
 * Description: device driver initialization
 *
 */
 
#ifdef MODULE
int init_module(void)
#else
int __init Owire_init(void)
#endif
{
	/* register our character device */
    g_Owire_major = devfs_register_chrdev(0, MODULE_NAME, &g_Owire_fops);
 	if ( g_Owire_major < 0 )
 	{
		TRACE("%s driver: Unable to register driver\n",MODULE_NAME);
		return -ENODEV;
	}

	g_devfs_handle = devfs_register(NULL, MODULE_NAME, DEVFS_FL_DEFAULT,
				      g_Owire_major, 0,
				      S_IFCHR | S_IRUSR | S_IWUSR,
				      &g_Owire_fops, NULL);   	

	g_Owire_pm = pm_register(PM_SYS_DEV,PM_SYS_VGA,Owire_pm_handler);
	g_Owire_status = 0;
	INFO("Owire Driver 0.1.0\n");
	INFO("Motorols SPS-Suzhou\n");

	return 0;
}


/******************************************************************************
 * Function Name: Owire_cleanup
 *
 * Input: 		void	:
 * Value Returned:	void	: 
 *
 * Description: clean up and free all of resource for this MODULE
 *
 * Modification History:
 * 	
 *****************************************************************************/
#ifdef MODULE
void cleanup_module(void)
#else
void __exit Owire_cleanup(void)
#endif
{
	devfs_unregister_chrdev(g_Owire_major, MODULE_NAME);
    devfs_unregister(g_devfs_handle);
    pm_unregister(g_Owire_pm);
}

#ifndef MODULE
module_init(Owire_init);
module_exit(Owire_cleanup);
#endif
/* end of file */

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美肥大bbwbbw高潮| 亚洲男人天堂一区| 国产精品国产三级国产aⅴ入口| 亚洲色图欧洲色图| 精品一区二区三区日韩| 欧洲一区二区av| 国产精品第四页| 国产一区二区三区在线观看精品| 99精品视频在线观看| 精品国产不卡一区二区三区| 香蕉av福利精品导航| av激情综合网| 日本一区二区免费在线观看视频| 日本aⅴ亚洲精品中文乱码| 色偷偷久久一区二区三区| 国产精品色婷婷| 国产成人夜色高潮福利影视| 日韩一区二区三区视频在线观看| 亚洲国产一区二区在线播放| 91丨porny丨首页| 欧美激情在线一区二区三区| 国产自产高清不卡| 欧美va在线播放| 久久机这里只有精品| 日韩精品一区在线观看| 日韩国产一二三区| 制服丝袜亚洲色图| 日韩福利视频导航| 日韩一区二区三区电影| 蜜臀av性久久久久蜜臀av麻豆| 欧美日韩国产综合一区二区| 亚洲一区二区三区中文字幕| 欧洲日韩一区二区三区| 亚洲成av人片在线| 日韩一级免费观看| 国产在线观看一区二区| 久久在线免费观看| 福利一区福利二区| 亚洲色图丝袜美腿| 欧美日韩一区视频| 日本免费新一区视频| 日韩欧美在线不卡| 国产精品一区二区男女羞羞无遮挡| 26uuu亚洲综合色| 成人免费va视频| 伊人性伊人情综合网| 欧美老肥妇做.爰bbww| 老司机精品视频导航| 国产精品午夜免费| 色婷婷国产精品| 日韩精品一级二级| 久久久91精品国产一区二区三区| 成人中文字幕在线| 亚洲综合清纯丝袜自拍| 欧美一区二区三区爱爱| 国产91综合网| 亚洲国产欧美日韩另类综合| 在线成人av网站| 国产成人午夜精品影院观看视频| 自拍偷自拍亚洲精品播放| 91精品国产91久久综合桃花| 国产成人免费视| 亚洲国产视频在线| 国产亚洲综合色| 欧美老人xxxx18| 成人av网址在线| 男人的天堂亚洲一区| 亚洲欧洲韩国日本视频| 欧美精品三级日韩久久| 成人永久免费视频| 日本美女一区二区| 亚洲人成影院在线观看| 欧美一区二区三区播放老司机| 国产麻豆精品theporn| 一区在线观看免费| 精品欧美一区二区在线观看| 成人高清在线视频| 久久99精品国产| 性做久久久久久| 日本一区二区视频在线| 91精品国产免费| 91丝袜美腿高跟国产极品老师 | 精品福利一二区| 色婷婷国产精品| 国产成人精品一区二区三区网站观看 | 亚洲精品老司机| 久久精品免费在线观看| 777亚洲妇女| 欧美专区在线观看一区| 成人激情免费视频| 国产在线视频一区二区三区| 亚洲第四色夜色| 亚洲美女在线国产| 国产精品久久久久精k8| 久久综合九色综合欧美就去吻| 欧美日韩电影在线| 91国内精品野花午夜精品| www.亚洲在线| 成人福利电影精品一区二区在线观看| 奇米色777欧美一区二区| 亚洲国产aⅴ天堂久久| 亚洲免费资源在线播放| 亚洲视频一二三区| 成人免费一区二区三区在线观看| 久久久99精品久久| 国产欧美一二三区| 欧美国产日产图区| 国产精品麻豆网站| 国产女主播一区| 国产精品情趣视频| 亚洲视频综合在线| 一区二区三区美女| 亚洲成人av福利| 日精品一区二区三区| 日韩av在线免费观看不卡| 青娱乐精品在线视频| 奇米在线7777在线精品| 毛片av一区二区三区| 精品综合久久久久久8888| 精品午夜一区二区三区在线观看| 久久精品999| 国产黄色成人av| 99riav久久精品riav| 欧美性感一类影片在线播放| 欧美另类高清zo欧美| 精品国产一区二区三区不卡| 久久噜噜亚洲综合| 国产精品入口麻豆九色| ●精品国产综合乱码久久久久| 亚洲人成精品久久久久久| 一区二区三区在线播| 青青草伊人久久| 国产精品一区一区三区| 99re这里都是精品| 欧美高清精品3d| 国产午夜精品在线观看| 亚洲精品乱码久久久久久黑人| 天天亚洲美女在线视频| 久久精品久久精品| av激情综合网| 91精品国产麻豆国产自产在线| 久久久综合视频| 亚洲激情校园春色| 麻豆精品国产91久久久久久| 高清国产午夜精品久久久久久| 97久久超碰精品国产| 欧美一级免费大片| 中文字幕日本不卡| 蜜臀久久99精品久久久画质超高清| 激情小说亚洲一区| 色呦呦国产精品| 日韩美一区二区三区| 国产精品久久久久影院老司| 日韩激情视频在线观看| av午夜精品一区二区三区| 91精品国产色综合久久久蜜香臀| 国产亚洲一区二区三区在线观看| 亚洲在线一区二区三区| 国产一区二区三区四区在线观看| 在线视频欧美区| 中文字幕欧美激情| 久草中文综合在线| 在线观看日产精品| 欧美激情一区二区三区全黄| 亚洲国产综合人成综合网站| 成人a区在线观看| 日韩一级视频免费观看在线| 亚洲欧美福利一区二区| 国产麻豆精品95视频| 91精品国产一区二区三区香蕉| 亚洲视频在线观看一区| 国产精品一区二区你懂的| 日韩视频在线一区二区| 一区二区三区 在线观看视频| 粉嫩久久99精品久久久久久夜| 日韩亚洲欧美高清| 视频精品一区二区| 欧美视频在线观看一区二区| 国产欧美日韩不卡免费| 久草热8精品视频在线观看| 欧美日本一道本在线视频| 亚洲人吸女人奶水| 成人97人人超碰人人99| 久久久久久免费网| 国产一区中文字幕| 精品国产免费视频| 六月婷婷色综合| 欧美精品一二三四| 日韩电影在线一区二区| 欧美精品自拍偷拍| 亚洲bdsm女犯bdsm网站| 欧美日韩1区2区| 偷拍日韩校园综合在线| 91精品国产综合久久蜜臀| 日日摸夜夜添夜夜添亚洲女人| 欧美浪妇xxxx高跟鞋交| 免费在线成人网| 精品国产一区二区三区忘忧草| 久草在线在线精品观看| 久久香蕉国产线看观看99|