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

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

?? s3c2410-can-mcp2510.c

?? CAN總線設備驅動
?? C
?? 第 1 頁 / 共 2 頁
字號:
/* * s3c2410-can-mcp2510.c * * can driver for SAMSUNG UP-NETARM2410 * * Author: ZOU JIAN GUO <zounix@126.com> * Updated : WANG BIN <wbinbuaa@163.com> * based on threewater <threewater@up-tech.com> * Date  : $Date: 2004/09/29 13:22:00 $  * * $Revision: 1.1.0.0 $ * * * This file is subject to the terms and conditions of the GNU General Public * License.  See the file COPYING in the main directory of this archive * for more details. * * History: * *  */#include <linux/config.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/miscdevice.h>#include <linux/sched.h>#include <linux/delay.h>#include <linux/poll.h>#include <linux/spinlock.h>#include <linux/delay.h>#include <asm/hardware.h>#include <asm/arch/spi.h>#include "mcp2510.h"#include "up-can.h"#include <asm/arch/S3C2410.h>/* debug macros */#undef DEBUG//#define DEBUG#ifdef DEBUG#define DPRINTK( x... )	printk("s3c2410-mcp2510: " ##x)#else#define DPRINTK( x... )#endif/********************** MCP2510 Pin *********************************/#define MCP2510_IRQ		IRQ_EINT4	//IRQ_EINT6#define MCP2510_PIN_CS		(1)  //GPIO_H0#define GPIO_MCP2510_CS		(GPIO_MODE_OUT | GPIO_PULLUP_DIS | GPIO_H0)#define MCP2510_Enable()	do {GPHDAT &= ~MCP2510_PIN_CS;udelay(1000);}while(0);#define MCP2510_Disable()	do {GPHDAT |= MCP2510_PIN_CS;}while(0);#define MCP2510_OPEN_INT()		enable_irq(MCP2510_IRQ)		//added by wb#define MCP2510_CLOSE_INT()		disable_irq(MCP2510_IRQ)////////////////////////////////////////////////////////////////////////////// Start the transmission from one of the tx buffers.#define MCP2510_transmit(address)		do{MCP2510_WriteBits(address, TXB_TXREQ_M, TXB_TXREQ_M);}while(0)#define MCP2510_CanRevBuffer	128	//CAN接收緩沖區大小/********************** MCP2510 Candata *********************************/typedef struct {	CanData MCP2510_Candata[MCP2510_CanRevBuffer];	//recieve data buffer	int nCanRevpos;	//recieve buffer pos for queued events	int nCanReadpos;	//read buffer pos for queued events	int loopbackmode;	wait_queue_head_t wq;	spinlock_t lock;}Mcp2510_DEV;static Mcp2510_DEV mcp2510dev;#define NextCanDataPos(pos)		do{(pos)=((pos)+1>=MCP2510_CanRevBuffer? 0: (pos)+1);}while(0)#define DEVICE_NAME		"s3c2410-mcp2510"#define SPIRAW_MINOR	1static int Major = 0;static int opencount=0;#define TRUE 1#define FALSE 0//#define SendSIOData(data) SPISend(data,0)//#define ReadSIOData()	SPIRecv(0)///////////////////////////////////////////////////////////////////static void printRegisters(void){  DPRINTK ("GPFCON:%x\tGPFUP:%x\tGPFDAT:%x\n",	  GPFCON, GPFUP, GPFDAT );  DPRINTK ("GPGCON:%x\tGPGUP:%x\tGPGDAT:%x\n",	  GPGCON, GPGUP, GPGDAT );  DPRINTK ("INTMOD:%x\tINTMSK:%x\tINTPND:%x\tSRCPND:%x\n",	  INTMOD, INTMSK, INTPND, SRCPND);  DPRINTK ("EXTINT0:%x\tEINTMASK:%x\tEINTPEND:%x\n",	  EXTINT0, EINTMASK, EINTPEND );}static void printGPE (void){  DPRINTK ("GPECON:%x\tGPEUP:%x\tGPEDAT:%x\n",	  GPECON, GPEUP, GPEDAT );}static void printSPI (void){  DPRINTK ("SPPRE0:%d\tSPCON0:%x\tSPSTA0:%x\n", SPPRE0, SPCON0, SPSTA0 );  DPRINTK ("SPTDAT0:%x\tSPRDAT0:%x\n", SPTDAT0, SPRDAT0 );  DPRINTK ("SPPIN0:%x\n", SPPIN0);}///////////////////////////////////////////////////////////////////////static void  SendSIOData(unsigned int data){	SPISend(data,0);}	static unsigned int ReadSIOData(){	return SPIRecv(0);	}static inline void MCP2510_Reset(void){	MCP2510_Enable();	SendSIOData(MCP2510INSTR_RESET);	MCP2510_Disable();}static void MCP2510_Write(int address, int value){	int flags;	local_irq_save(flags);	MCP2510_Enable();	SendSIOData(MCP2510INSTR_WRITE);	SendSIOData((unsigned char)address);	SendSIOData((unsigned char)value);	MCP2510_Disable();	local_irq_restore(flags);}static unsigned char MCP2510_Read(int address){	unsigned char result;	int flags;	local_irq_save(flags);	MCP2510_Enable();	SendSIOData(MCP2510INSTR_READ);	SendSIOData((unsigned char)address);	SendSIOData(0);	result=ReadSIOData();	MCP2510_Disable();	local_irq_restore(flags);	return result;}static unsigned char MCP2510_ReadStatus(void){	unsigned char result;	int flags;	local_irq_save(flags);	MCP2510_Enable();	SendSIOData(MCP2510INSTR_RDSTAT);	SendSIOData(0);	result=ReadSIOData();	MCP2510_Disable();	local_irq_restore(flags);	return result;}static void MCP2510_WriteBits( int address, int data, int mask ){	int flags;	local_irq_save(flags);	MCP2510_Enable();	SendSIOData(MCP2510INSTR_BITMDFY);	SendSIOData((unsigned char)address);	SendSIOData((unsigned char)mask);	SendSIOData((unsigned char)data);	MCP2510_Disable();	local_irq_restore(flags);}/*******************************************\*	序列讀取MCP2510數據				*\*******************************************/static void MCP2510_SRead( int address, unsigned char* pdata, int nlength ){	int i;	int flags;	local_irq_save(flags);	MCP2510_Enable();	SendSIOData(MCP2510INSTR_READ);	SendSIOData((unsigned char)address);	for (i=0; i<nlength; i++) {		SendSIOData(0);		*pdata=ReadSIOData();		pdata++;	}	MCP2510_Disable();	local_irq_restore(flags);}/*******************************************\*	序列寫入MCP2510數據				*\*******************************************/static void MCP2510_Swrite(int address, unsigned char* pdata, int nlength){	int i;	int flags;	local_irq_save(flags);	MCP2510_Enable();	SendSIOData(MCP2510INSTR_WRITE);	SendSIOData((unsigned char)address);	for (i=0; i < nlength; i++) {		SendSIOData((unsigned char)*pdata);		pdata++;	}	MCP2510_Disable();	local_irq_restore(flags);}/************************************************************\*	設置MCP2510 CAN總線波特率						**	參數: bandrate為所設置的波特率				**			IsBackNormal為是否要返回Normal模式		*\************************************************************/static void MCP2510_SetBandRate(CanBandRate bandrate, int IsBackNormal){	//	// Bit rate calculations.	//	//Input clock fre=16MHz	// In this case, we'll use a speed of 125 kbit/s, 250 kbit/s, 500 kbit/s.	// If we set the length of the propagation segment to 7 bit time quanta,	// and we set both the phase segments to 4 quanta each,	// one bit will be 1+7+4+4 = 16 quanta in length.	//	// setting the prescaler (BRP) to 0 => 500 kbit/s.	// setting the prescaler (BRP) to 1 => 250 kbit/s.	// setting the prescaler (BRP) to 3 => 125 kbit/s.	//	// If we set the length of the propagation segment to 3 bit time quanta,	// and we set both the phase segments to 1 quanta each,	// one bit will be 1+3+2+2 = 8 quanta in length.	// setting the prescaler (BRP) to 0 => 1 Mbit/s.	// Go into configuration mode	MCP2510_Write(MCP2510REG_CANCTRL, MODE_CONFIG);	switch(bandrate){	case BandRate_125kbps:		MCP2510_Write(CNF1, SJW1|BRP4);	//Synchronization Jump Width Length =1 TQ		MCP2510_Write(CNF2, BTLMODE_CNF3|(SEG4<<3)|SEG7); // Phase Seg 1 = 4, Prop Seg = 7		MCP2510_Write(CNF3, SEG4);// Phase Seg 2 = 4		break;	case BandRate_250kbps:		MCP2510_Write(CNF1, SJW1|BRP2);	//Synchronization Jump Width Length =1 TQ		MCP2510_Write(CNF2, BTLMODE_CNF3|(SEG4<<3)|SEG7); // Phase Seg 1 = 4, Prop Seg = 7		MCP2510_Write(CNF3, SEG4);// Phase Seg 2 = 4		break;	case BandRate_500kbps:		MCP2510_Write(CNF1, SJW1|BRP1);	//Synchronization Jump Width Length =1 TQ		MCP2510_Write(CNF2, BTLMODE_CNF3|(SEG4<<3)|SEG7); // Phase Seg 1 = 4, Prop Seg = 7		MCP2510_Write(CNF3, SEG4);// Phase Seg 2 = 4		break;	case BandRate_1Mbps:		MCP2510_Write(CNF1, SJW1|BRP1);	//Synchronization Jump Width Length =1 TQ		MCP2510_Write(CNF2, BTLMODE_CNF3|(SEG3<<3)|SEG2); // Phase Seg 1 = 2, Prop Seg = 3		MCP2510_Write(CNF3, SEG2);// Phase Seg 2 = 1		break;	}	if(IsBackNormal){		//Enable clock output		MCP2510_Write(CLKCTRL, MODE_NORMAL | CLKEN | CLK1);	}}/*******************************************\*	讀取MCP2510 CAN總線ID				**	參數: address為MCP2510寄存器地址**			can_id為返回的ID值			**	返回值								**	TRUE,表示是擴展ID(29位)			**	FALSE,表示非擴展ID(11位)		*\*******************************************/static int MCP2510_Read_Can_ID( int address, __u32* can_id){	__u32 tbufdata;	unsigned char* p=(unsigned char*)&tbufdata;	MCP2510_SRead(address, p, 4);	*can_id = (tbufdata<<3)|((tbufdata>>13)&0x7);	*can_id &= 0x7ff;	if ( (p[MCP2510LREG_SIDL] & TXB_EXIDE_M) ==  TXB_EXIDE_M ) {		*can_id = (*can_id<<2) | (p[MCP2510LREG_SIDL] & 0x03);		*can_id <<= 16;		*can_id |= tbufdata>>16;		return TRUE;	}	return FALSE;}/***********************************************************\*	讀取MCP2510 接收的數據							**	參數: 													**		nbuffer為第幾個緩沖區可以為3或者4		**		CanData為CAN數據結構							*\***********************************************************/static void MCP2510_Read_Can(unsigned char nbuffer, PCanData candata){	unsigned char mcp_addr = (nbuffer<<4) + 0x31, ctrl;	int IsExt;	char dlc;	IsExt=MCP2510_Read_Can_ID( mcp_addr, &(candata->id));	ctrl=MCP2510_Read(mcp_addr-1);	dlc=MCP2510_Read( mcp_addr+4);	if ((ctrl & 0x08)) {		candata->rxRTR = TRUE;	}	else{		candata->rxRTR = FALSE;	}	dlc &= DLC_MASK;	MCP2510_SRead(mcp_addr+5, candata->data, dlc);	candata->dlc=dlc;}/*******************************************\*	設置MCP2510 CAN總線ID				**	參數: address為MCP2510寄存器地址**			can_id為設置的ID值			**			IsExt表示是否為擴展ID	*\*******************************************/static void MCP2510_Write_Can_ID(int address, __u32 can_id, int IsExt){	__u32 tbufdata;	if (IsExt) {		can_id &= 0x1fffffff;	//29位		tbufdata=can_id &0xffff;		tbufdata<<=16;		tbufdata|=((can_id>>(18-5))&(~0x1f));		tbufdata |= TXB_EXIDE_M;	}	else{		can_id&=0x7ff;	//11位		tbufdata= (can_id>>3)|((can_id&0x7)<<13);	}	MCP2510_Swrite(address, (unsigned char*)&tbufdata, 4);	MCP2510_Read_Can_ID(address, &tbufdata);	DPRINTK("write can id=%x, result id=%x\n",can_id, tbufdata);}/***********************************************************\*	寫入MCP2510 發送的數據							**	參數: 													**		nbuffer為第幾個緩沖區可以為0、1、2		**		CanData為CAN數據結構							*\***********************************************************/static void MCP2510_Write_Can( unsigned char nbuffer, PCanData candata){	unsigned char dlc;	unsigned char mcp_addr = (nbuffer<<4) + 0x31;	dlc=candata->dlc;	MCP2510_Swrite(mcp_addr+5, candata->data, dlc);  // write data bytes	MCP2510_Write_Can_ID( mcp_addr, candata->id,candata->IsExt);  // write CAN id	if (candata->rxRTR)		dlc |= RTR_MASK;  // if RTR set bit in byte	MCP2510_Write((mcp_addr+4), dlc);            // write the RTR and DLC}/***********************************************************\*	write and send Can data									**	we must set can id first.										**	parament:												**		nbuffer: which buffer, should be: 0, 1, 2					**		pbuffer: send data 										**		nbuffer: size of data 									*\***********************************************************/static void MCP2510_Write_CanData( unsigned char nbuffer, char *pbuffer, int nsize){	unsigned char dlc;	unsigned char mcp_addr = (nbuffer<<4) + 0x31;	dlc=nsize&DLC_MASK;	//nbuffer must <= 8	MCP2510_Swrite(mcp_addr+5, pbuffer, dlc);  // write data bytes	MCP2510_Write((mcp_addr+4), dlc);            // write the RTR and DLC}/***********************************************************\*	write and send Remote Can Frame							**	we must set can id first.										**	parament:												**		nbuffer: which buffer, should be: 0, 1, 2					*\***********************************************************/static void MCP2510_Write_CanRTR( unsigned char nbuffer){	unsigned char dlc=0;	unsigned char mcp_addr = (nbuffer<<4) + 0x31;	dlc |= RTR_MASK;  // if RTR set bit in byte	MCP2510_Write((mcp_addr+4), dlc);            // write the RTR and DLC

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩手机在线导航| 日韩av二区在线播放| 中文字幕人成不卡一区| 国产欧美一区二区精品久导航 | 欧美性猛交xxxx黑人交| 在线这里只有精品| 欧美午夜片在线观看| 欧美日韩视频在线一区二区| 欧美性受xxxx黑人xyx性爽| 欧美无砖砖区免费| 欧美日韩精品欧美日韩精品一| 欧美私人免费视频| 在线电影欧美成精品| 欧美一区二区免费| 久久久三级国产网站| 国产欧美日韩不卡免费| 自拍偷拍欧美激情| 亚洲国产精品麻豆| 美女一区二区在线观看| 国产一二精品视频| 99久久精品免费看国产| 在线一区二区观看| 91精品国产免费| 久久久精品国产免大香伊| 国产精品久久久久久久久免费樱桃| 日韩毛片精品高清免费| 五月天激情综合| 精品一区二区在线播放| 9色porny自拍视频一区二区| 欧美性猛交xxxx黑人交| 日韩一区二区三区免费观看| 国产女人aaa级久久久级| 亚洲人成网站色在线观看| 五月天国产精品| 国产激情精品久久久第一区二区| 菠萝蜜视频在线观看一区| 欧美日韩一区久久| 久久亚洲精精品中文字幕早川悠里| 国产精品美女久久久久aⅴ| 亚洲一二三四区不卡| 精品一区二区三区视频| 97久久精品人人澡人人爽| 欧美另类久久久品| 欧美激情综合网| 亚洲二区视频在线| 国产盗摄女厕一区二区三区| 欧美日韩在线免费视频| 久久精品一区二区三区四区| 亚洲一区二区三区四区在线观看 | 91在线视频观看| 日韩欧美中文一区| 亚洲欧美日韩国产综合在线| 蜜臀av性久久久久av蜜臀妖精| www.亚洲在线| 精品粉嫩超白一线天av| 亚洲欧美另类综合偷拍| 韩国欧美国产1区| 欧美日韩亚洲高清一区二区| 国产片一区二区三区| 日韩不卡一二三区| 91免费看视频| 国产视频一区二区在线| 视频一区二区欧美| 91麻豆高清视频| 国产亚洲欧美中文| 免费成人av资源网| 91福利在线观看| 国产精品三级久久久久三级| 久久国产精品免费| 欧美日韩1区2区| 亚洲免费观看高清完整| 成人免费视频国产在线观看| 日韩美一区二区三区| 午夜精品久久久久久久99樱桃| av在线播放一区二区三区| 久久久不卡影院| 丝袜美腿亚洲综合| 91精品1区2区| 中文字幕一区二区三区视频 | 欧美亚洲国产怡红院影院| 欧美激情一区二区三区四区| 国内精品在线播放| 日韩欧美在线1卡| 日本视频免费一区| 欧美美女直播网站| 亚洲一区电影777| 在线看不卡av| 亚洲精品一二三区| 91网站黄www| 国产精品精品国产色婷婷| 国产成人精品一区二| 久久免费午夜影院| 国产一区视频网站| 久久这里只有精品视频网| 精品亚洲欧美一区| 欧美成人a在线| 激情欧美一区二区| www激情久久| 国产电影一区在线| 国产欧美一区二区三区鸳鸯浴 | 色94色欧美sute亚洲线路一久| 日本一区二区三区四区| 国产成人免费av在线| 久久嫩草精品久久久精品| 国产精品一线二线三线| 国产日韩欧美制服另类| 国产91色综合久久免费分享| 国产欧美日韩综合精品一区二区| 福利一区福利二区| 国产精品电影一区二区| 色噜噜狠狠色综合欧洲selulu| 一区二区免费看| 欧美日韩和欧美的一区二区| 视频精品一区二区| 日韩女优av电影| 国产美女主播视频一区| 国产精品高潮久久久久无| 99re这里都是精品| 亚洲尤物视频在线| 欧美一卡在线观看| 国产在线国偷精品产拍免费yy| 久久精品人人做人人综合 | 国产色91在线| 成人激情视频网站| 亚洲综合久久久| 91精品国产欧美一区二区18| 激情国产一区二区| 国产精品美女久久久久久久网站| 色婷婷精品久久二区二区蜜臂av| 日日夜夜免费精品| 久久众筹精品私拍模特| 91蜜桃网址入口| 天天色综合成人网| 欧美激情一区二区三区| 欧美视频精品在线观看| 狠狠久久亚洲欧美| 亚洲免费观看高清完整| 日韩一区二区免费电影| 丁香婷婷综合激情五月色| 亚洲自拍偷拍九九九| 欧美电影免费观看高清完整版在线| 国产成人在线观看| 亚洲成人在线观看视频| 久久久久一区二区三区四区| 91网站最新地址| 久久成人羞羞网站| 亚洲免费视频中文字幕| 精品人伦一区二区色婷婷| 91丨porny丨首页| 玖玖九九国产精品| 亚洲另类春色国产| 久久九九久精品国产免费直播| 欧美色综合网站| 国产福利精品一区二区| 亚洲午夜电影在线观看| 国产日本欧美一区二区| 欧美日韩卡一卡二| 99精品欧美一区二区三区综合在线| 日本视频一区二区| 一区二区三区在线视频免费| 26uuu精品一区二区三区四区在线| 色94色欧美sute亚洲13| 国产精品99久久久久久宅男| 亚洲动漫第一页| 国产精品麻豆视频| 精品免费99久久| 欧美午夜片在线看| 99riav久久精品riav| 国产高清精品久久久久| 肉色丝袜一区二区| 一区二区三区不卡视频| 国产精品免费视频网站| 日韩精品一区二区三区在线| 欧美视频精品在线观看| 97久久人人超碰| 丰满亚洲少妇av| 精品一区二区三区免费观看| 天天综合色天天| 亚洲无线码一区二区三区| 自拍视频在线观看一区二区| 国产无遮挡一区二区三区毛片日本| 日韩午夜精品电影| 欧美久久免费观看| 欧美性一级生活| 欧美在线999| 91捆绑美女网站| 成人av动漫在线| 国产成人av一区二区三区在线| 久国产精品韩国三级视频| 首页欧美精品中文字幕| 亚洲自拍偷拍综合| 一个色在线综合| 亚洲综合久久久| 亚洲午夜激情网站| 亚洲综合网站在线观看| 亚洲精品久久7777| 亚洲免费观看视频| 伊人开心综合网| 一区二区三区久久久| 一区二区三区四区在线|