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

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

?? sja1000.c

?? CANOPen通信的一些源碼
?? C
?? 第 1 頁 / 共 4 頁
字號:
/* sja1000.c - implementation of CAN API for Philips SJA1000 *//* Copyright 2001 Wind River Systems, Inc. *//*modification history--------------------22aug02,lsg modified for WindNet CAN 1,209nov01,dnb modified for integration into Tornado12jul01,jac written*//*DESCRIPTIONThis module contains the functions, specific to the Philips SJA1000 CANcontroller, that implement the interface defined in the wnCAN.hheader file.*//* includes */#include <vxWorks.h>#include <errnoLib.h>#include <taskLib.h>#include <intLib.h>#include <iv.h>#include <sysLib.h>#include <CAN/wnCAN.h>#include <CAN/canController.h>#include <CAN/canBoard.h>#ifdef INCLUDE_SJA1000#include <CAN/sja1000.h>#include <CAN/sja1000Offsets.h>/* forward declarations */const WNCAN_ChannelType g_sja1000chnType[SJA1000_MAX_MSG_OBJ] = { WNCAN_CHN_RECEIVE,WNCAN_CHN_TRANSMIT};/*   In Pelican mode, the addresses of the transmit and receive buffers are   identical. Access to the correct register depends on the access operation:   write for accessing the transmit buffer, and read for accessing the receive   buffer. Also, the address of the start of the msg data changes depending   on whether the CAN Id is standard or extended; therefore, a SJA1000_WriteData()   operation requires a copy of the data until SJA1000_Tx() is called at which   time the frame format is known. Because read operations on the transmit   buffer (SJA1000_ReadData(), SJA1000_ReadID()) are also not possible,   a local tranmit message data stucture is necessary to store the transmit data.   Copies to and from this data structure represents additional overhead.*//************************************************************************** SJA1000_Init - intitialize the CAN controller** This function initializes the CAN controller and makes default selections.* 1. Puts the CAN controller into reset mode* 2. Disables interrupts at the CAN controller level as well as channel level* 3. Sets bit timing values according to values stored in the CAN controller*    struct. If user has changed these values before init is called, the*    default bit timing values are set to a baud rate of 250K* 4. Clears error counters* 5. Sets local and global receive masks to don't care (accept all)* 6. Makes all channels inactive in hardware* 7. The CAN controller has now been initialized but will not participate*    in CAN bus communication. In order to bring the CAN controller online,*    and enable active participation in CAN bus activity, CAN_Start must*    be called following CAN_Init.** Call these functions in this order:* 1. CAN_Open* 2. CAN_Init* 3. CAN_Start** RETURNS: OK, or ERROR** ERRNO:   N/A**/static STATUS SJA1000_Init(struct WNCAN_Device *pDev){    UCHAR        value;    STATUS       retCode = OK;    unsigned int i;	/* Put the controller into reset mode */	pDev->pBrd->canOutByte(pDev, SJA1000_MOD, MOD_RM);		/* set controller to Pelican mode */	value = pDev->pBrd->canInByte(pDev, SJA1000_CDR);	value |= 0x80;	pDev->pBrd->canOutByte(pDev, SJA1000_CDR, value);		/* set the mode register: 0001001 (0x9)	reset             = 1   (reset mode)	listen only       = 0   (normal)	self test         = 0   (ack required for successful TX)	acceptance filter = 1   (single 32 bit filter)	sleep mode        = 0   */	pDev->pBrd->canOutByte(pDev, SJA1000_MOD, 0x09);		/* set command register to zero */	pDev->pBrd->canOutByte(pDev, SJA1000_CMR ,0);		/* set the error warning limit to 96 */	pDev->pBrd->canOutByte(pDev, SJA1000_EWLR, 0x60);		/* disable all interrupts */	pDev->pBrd->canOutByte(pDev, SJA1000_IER, 0x0);		/* btr0 and btr1 */	value = (pDev->pCtrl->sjw << 6) | pDev->pCtrl->brp;	pDev->pBrd->canOutByte(pDev, SJA1000_BTR0, value);	if(pDev->pCtrl->samples)		value = 0x80 | (pDev->pCtrl->tseg2 << 4) | pDev->pCtrl->tseg1;		else		value = (pDev->pCtrl->tseg2 << 4) | pDev->pCtrl->tseg1;			pDev->pBrd->canOutByte(pDev, SJA1000_BTR1, value);    		/* set output control */	pDev->pBrd->canOutByte(pDev, SJA1000_OCR, 0xfb);		/* reset receive error counter */	pDev->pBrd->canOutByte(pDev, SJA1000_RXERR, 0x0);		/* reset transmit error counter */	pDev->pBrd->canOutByte(pDev, SJA1000_TXERR, 0x0);		/* Set all acceptance code registers to 0xFF. Received messages must	have these bits set. */	pDev->pBrd->canOutByte(pDev, SJA1000_ACR0, 0xff);	pDev->pBrd->canOutByte(pDev, SJA1000_ACR1, 0xff);	pDev->pBrd->canOutByte(pDev, SJA1000_ACR2, 0xff);	pDev->pBrd->canOutByte(pDev, SJA1000_ACR3, 0xff);		/* Set the acceptance mask registers to don't care. The acceptance 	mask register defines which bits of the acceptance code register 	matter:	1 = don't care (message bit may be one or zero), 0 = must match . 	*/	pDev->pBrd->canOutByte(pDev, SJA1000_AMR0, 0xff);	pDev->pBrd->canOutByte(pDev, SJA1000_AMR1, 0xff);	pDev->pBrd->canOutByte(pDev, SJA1000_AMR2, 0xff);	pDev->pBrd->canOutByte(pDev, SJA1000_AMR3, 0xff);		/*	* The controller is not brought out of reset here. CAN_Start must	* be called in order to do that and enable CAN communication on the	* bus	*/		/* free all channels */	for (i = 0; i < SJA1000_MAX_MSG_OBJ; i++)		pDev->pCtrl->chnMode[i] = WNCAN_CHN_INVALID;		     return retCode;}/************************************************************************** SJA1000_GetBusStatus - get the bus status** This function returns the status of the CAN bus. The bus is * either in a WNCAN_BUS_OFF, WNCAN_BUS_WARN, or WNCAN_BUS_OK state.** WNCAN_BUS_OFF: CAN controller is in BUS OFF state* A CAN node is bus off when the transmit error count is greater than* or equal to 256* WNCAN_BUS_WARN: CAN controller is in ERROR WARNING state* A CAN node is in error warning state when the number of transmit errors* equals or exceeds 96, or the number of receive errors equals or exceeds* 96* WNCAN_BUS_OK: CAN controller is in ERROR ACTIVE state* A CAN node in error active state can normally take part in bus communication* and sends an ACTIVE ERROR FLAG when an error has been detected. ** RETURNS: status of the CAN bus = WNCAN_BUS_OK, WNCAN_BUSWARN, * WNCAN_BUS_OFF** ERRNO: N/A**/static WNCAN_BusStatus SJA1000_GetBusStatus(struct WNCAN_Device *pDev){    UCHAR regStatus;    WNCAN_BusStatus retStat;    /* read the status register */    regStatus = pDev->pBrd->canInByte(pDev, SJA1000_SR);    if(regStatus & SR_BS)        retStat = WNCAN_BUS_OFF;    else if(regStatus & SR_ES)        retStat = WNCAN_BUS_WARN;    else        retStat = WNCAN_BUS_OK;    return retStat;}/************************************************************************** SJA1000_Start - Bring CAN controller online** This function is called to bring the CAN controller online. The CAN controller* can now participate in transmissions and receptions on the CAN bus.* This function must be called after CAN_Init has been called to initialize and* bring the CAN controller up in a known state.** RETURNS: OK always** ERRNO:   N/A**/static void SJA1000_Start(struct WNCAN_Device *pDev){	struct TxMsg *pTxMsg;	UCHAR value;	UCHAR i;    	/* Clear the controller reset */	value = pDev->pBrd->canInByte(pDev, SJA1000_MOD);	value &= ~0x1;	pDev->pBrd->canOutByte(pDev, SJA1000_MOD, value);	/* Wait until the controller comes out of reset */	while(pDev->pBrd->canInByte(pDev, SJA1000_MOD) != value) {};	/* Wait for Bus OK or taskDelay(1)*/	if(SJA1000_GetBusStatus != WNCAN_BUS_OK)		taskDelay(1);	/* Initialize the TX frame info. This can only be done when	the controller is not in reset. */	pDev->pBrd->canOutByte(pDev, SJA1000_SFF, 0);	/* Initialize the TX msg data structure */	pTxMsg = (struct TxMsg *)pDev->pCtrl->csData;	pTxMsg->id  = 0;	pTxMsg->ext = 0;	pTxMsg->rtr = 0;	pTxMsg->len = 0;	for(i = 0 ; i < 8 ; i++)		pTxMsg->data[i] = 0;}/************************************************************************** SJA1000_Stop - Put CAN controller offline** Disables communication between CAN controller and the CAN bus** RETURNS: OK always** ERRNO:   N/A**/static void SJA1000_Stop(struct WNCAN_Device *pDev){    /* Stop the SJA1000 controller*/	/* Put the controller into reset mode */	pDev->pBrd->canOutByte(pDev, SJA1000_MOD, MOD_RM);}/************************************************************************** SJA1000_SetBitTiming - Set bit timing** This function sets the baud rate of the controller. The selection* of the input parameters should be based on an established set of * recommendations for the particular application.* This function sets the bit timing values in the hardware as well as the* controller structure, so that the bit timing values are not lost if Init* is called again. The function will preserve the state of the CAN controller.* i.e. if the CAN controller is online when the function is called, then the * CAN controller will be online when the function exits. ** bit time = 1 + (tseg1 + 1) + (tseg2+1) time quanta * The interpretation of tseg1 are tseg2 are according to the controller's * definition and hence can be written to directly using this function.** In all cases so far, tseg2 refers to the segment of bit time after the sample* point. However, in some controllers tseg1 refers to the segment of bit time* after the end of sync seg upto the sample point.                     *  ---------------------------------------------------------* |    |                    |                              |  *  sync <--------tseg1 --->^|^<---------tseg2 ------------->*                          sample point * ** RETURNS: OK, or ERROR** ERRNO:   S_can_invalid_parameter**/static STATUS SJA1000_SetBitTiming(    struct WNCAN_Device *pDev,    UCHAR tseg1,    UCHAR tseg2,    UCHAR brp,    UCHAR sjw,    BOOL  samples){    UCHAR       value;    STATUS      retCode;	    retCode = OK;  /* assume success */	    /* qualify parameters */    if((sjw > 0x03) || (brp > 0x3f) || (tseg1 > 15) ||		(tseg1 < 2) || (tseg2 > 7) || (tseg2 < 1))    {        errnoSet(S_can_invalid_parameter);        retCode = ERROR;    }    else    {		/* Check if controller is in reset mode */        /* if not, enable change configuration */        value = pDev->pBrd->canInByte(pDev, SJA1000_MOD);						if((value & 0x01) == 0)			pDev->pBrd->canOutByte(pDev, SJA1000_MOD, value | 0x01);		        pDev->pCtrl->brp = brp;        pDev->pCtrl->sjw = sjw;        pDev->pBrd->canOutByte(pDev, SJA1000_BTR0, (sjw << 6) | brp);		        pDev->pCtrl->tseg1 = tseg1;        pDev->pCtrl->tseg2 = tseg2;		        if(samples)		{			/*three sample mode*/			pDev->pCtrl->samples = 1;			pDev->pBrd->canOutByte(pDev, SJA1000_BTR1, (0x80 | (tseg2 << 4) | 				tseg1));		}        else					{			/*one sample mode*/			pDev->pCtrl->samples = 0;			pDev->pBrd->canOutByte(pDev, SJA1000_BTR1, (tseg2 << 4) | tseg1);		}						/*restore original state of controller*/		if((value & 0x01) == 0)		{			pDev->pBrd->canOutByte(pDev, SJA1000_MOD, value);						/* Wait until the controller comes out of reset */			while(pDev->pBrd->canInByte(pDev, SJA1000_MOD) != value) {};						/* Wait for Bus OK or a task delay of 1*/						if(SJA1000_GetBusStatus != WNCAN_BUS_OK)				taskDelay(1);								}		    }	    return retCode;}/**************************************************************************** SJA1000_GetBaudRate: Returns baud rate by recalculating bit timing * parameters** RETURNS: baud rate in bps** ERRNO:   N/A*/static UINT SJA1000_GetBaudRate      (      struct WNCAN_Device *pDev,	  UINT   *samplePoint      ){	ULONG             sysClkFreq;                USHORT            num_time_quanta;	UCHAR		  brp, tseg1, tseg2;        UCHAR 		  value;	value = pDev->pBrd->canInByte(pDev, SJA1000_CDR);	value = value & 0x7;		sysClkFreq = (pDev->pBrd->xtalFreq / (2 + 2*value));	brp = (pDev->pBrd->canInByte(pDev, SJA1000_BTR0) & 0x3f) + 1;	tseg1 = pDev->pBrd->canInByte(pDev, SJA1000_BTR1);	tseg2 = ((tseg1 & 0xf0) >> 4) + 1;	tseg1 = (tseg1 & 0x0f) + 1;	/*Calculate baud rate*/	num_time_quanta = 1 + tseg1 + tseg2;	 *samplePoint = ((1 + tseg1) * 100)/num_time_quanta;	return( sysClkFreq / (num_time_quanta * brp));}/************************************************************************** SJA1000_SetIntMask - enable controller level interrupts on the CAN*                      controller** This function enables the specified list of controller level interrupts* on the CAN controller. Interrupts are not enabled at the CAN board level* or at the CPU level.* The interrupt masks available are:* WNCAN_INT_ERROR : enables interrupts due to errors on the CAN bus*                   This may be implemented as a single or multiple*                   interrupt sources on the CAN controller.* WNCAN_INT_BUS_OFF: enables interrupt indicating bus off condition  * WNCAN_INT_WAKE_UP: enables interrupt on wake up* All interrupt masks that need to be enabled must be specified in the list* passed to the function, in order to be set, every time the function* is called. ** RETURNS: OK or ERROR** ERRNO:   S_can_invalid_parameter**/static STATUS SJA1000_SetIntMask(struct WNCAN_Device *pDev, WNCAN_IntType intMask){    int         oldLevel;    UCHAR       value=0;	STATUS      retCode = OK;	/*	return error if masks other than error, busoff and wakeup	are passed to the function	*/	if((intMask > (WNCAN_INT_ERROR | WNCAN_INT_BUS_OFF | WNCAN_INT_WAKE_UP)) &&		(intMask != WNCAN_INT_ALL)) 	{		errnoSet(S_can_invalid_parameter);		retCode = ERROR;        	}	else	{		value = pDev->pBrd->canInByte(pDev, SJA1000_IER);				/*Enable all error interreupts. Bus error,  data overrun*/		if(intMask & WNCAN_INT_ERROR)			value |= IER_BEIE;		else			value &= ~IER_BEIE;						if(intMask & WNCAN_INT_WAKE_UP)			value |= IER_WUIE;		else			value &= ~IER_WUIE;							/*			The error warning interrupt is generated when errors on the bus exceed			warning limits and if the controller becomes bus off. The interrupt 			is also raised when the controller goes into error active state from 			being bus offf		*/		if(intMask & WNCAN_INT_BUS_OFF)			value |= IER_EIE;		else			value &= ~IER_EIE;						oldLevel = intLock();				pDev->pBrd->canOutByte(pDev, SJA1000_IER, value);				intUnlock(oldLevel);	}    return retCode;}/***************************************************************************   * SJA1000_EnableInt - enable interrupts from the CAN device to the CPU.** This function enables interrupts from the CAN controller to reach the* CPU. Typically, enables a global interrupt mask bit at the CPU level.** RETURNS: N/A** ERRNO:   N/A**/static void SJA1000_EnableInt(struct WNCAN_Device *pDev){    int         oldLevel;    UCHAR       value=0;	value = pDev->pBrd->canInByte(pDev, SJA1000_IER);	/*Enable RxIE*/	value |= 0x01;	        oldLevel = intLock();    pDev->pBrd->canOutByte(pDev, SJA1000_IER, value);    intUnlock(oldLevel);    return;}/************************************************************************** SJA1000_DisableInt -  disable interrupts from the CAN device to the CPU** This function disables interrupts from the CAN controller from reaching the* CPU. Typically, disables a global interrupt mask bit at the CPU level.** RETURNS: N/A

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
在线播放一区二区三区| 欧美浪妇xxxx高跟鞋交| 日韩国产精品久久久| 国产午夜精品一区二区三区嫩草 | 亚洲柠檬福利资源导航| 日韩视频一区二区三区在线播放 | 2020国产精品| 欧美少妇性性性| 99久久国产免费看| 国产一区二区中文字幕| 婷婷综合另类小说色区| 亚洲欧美日韩一区| 国产女人18毛片水真多成人如厕| 欧美一区二区三区免费| 91国产福利在线| 99久久精品免费| 高清不卡在线观看| 国产一区啦啦啦在线观看| 日韩精品福利网| 亚洲一区二区四区蜜桃| 亚洲精品视频在线观看免费| 久久久久久麻豆| 精品成人一区二区三区四区| 日韩午夜电影av| 日韩欧美三级在线| 欧美理论片在线| 欧美日韩国产三级| 欧美三区在线观看| 欧美综合亚洲图片综合区| 99精品欧美一区二区三区综合在线| 成人综合在线观看| 处破女av一区二区| 不卡av在线网| 91浏览器在线视频| 色就色 综合激情| 在线欧美日韩精品| 精品视频在线看| 欧美日韩性生活| 91精品国产aⅴ一区二区| 欧美一区二区成人| 欧美v日韩v国产v| xnxx国产精品| 国产欧美综合在线观看第十页| 久久精品亚洲麻豆av一区二区 | 日韩成人免费电影| 热久久国产精品| 毛片不卡一区二区| 国产精品亚洲人在线观看| 国产精品亚洲一区二区三区妖精 | 国产白丝精品91爽爽久久| 国产成人日日夜夜| av电影天堂一区二区在线| 91色porny| 欧美日韩一区二区在线观看视频| 欧美美女一区二区| 日韩三级av在线播放| 久久精品一级爱片| 成人免费小视频| 亚洲成a人在线观看| 另类小说视频一区二区| 国产成人av电影在线观看| 岛国精品在线观看| 欧美无砖砖区免费| 精品第一国产综合精品aⅴ| 亚洲国产激情av| 亚洲一级片在线观看| 男人的天堂亚洲一区| 国产激情一区二区三区四区 | 亚洲成人在线观看视频| 久久精品国产99国产| 99热这里都是精品| 欧美日韩国产a| 久久精品一区四区| 亚洲国产精品久久久久秋霞影院| 美女www一区二区| av在线不卡网| 欧美一级视频精品观看| 亚洲国产高清在线观看视频| 亚洲成人av电影| 岛国精品在线观看| 884aa四虎影成人精品一区| 中文字幕 久热精品 视频在线| 夜夜夜精品看看| 国产99一区视频免费| 欧美精品少妇一区二区三区 | 日本成人在线电影网| 丁香五精品蜜臀久久久久99网站 | 国产福利91精品一区二区三区| 在线一区二区视频| 久久久影视传媒| 亚洲a一区二区| 高清国产一区二区三区| 欧美一级免费大片| 亚洲精品中文在线影院| 国产一区二区三区在线观看免费视频| 99久久国产综合精品麻豆| 精品国产欧美一区二区| 亚洲午夜精品久久久久久久久| 国产+成+人+亚洲欧洲自线| 777a∨成人精品桃花网| 亚洲欧美另类在线| 国产精品亚洲а∨天堂免在线| 制服.丝袜.亚洲.中文.综合| 综合久久久久久| 国产精品66部| 日韩一区二区三区精品视频| 亚洲美女视频在线观看| 国产精品2024| 日韩欧美激情一区| 亚洲国产精品久久久久秋霞影院| 成人免费看视频| 精品国产乱码久久久久久1区2区| 亚洲.国产.中文慕字在线| 99久久久国产精品免费蜜臀| 国产欧美久久久精品影院| 激情图区综合网| 日韩欧美国产不卡| 日韩中文字幕亚洲一区二区va在线| 色综合久久精品| 中文字幕一区三区| 国产.欧美.日韩| 国产欧美日韩综合| 国产福利一区在线观看| 亚洲精品一区二区精华| 紧缚奴在线一区二区三区| 欧美一卡二卡三卡四卡| 青草国产精品久久久久久| 91精品国产综合久久蜜臀 | 99精品热视频| 亚洲欧洲国产专区| 白白色亚洲国产精品| 国产精品伦一区| www.66久久| 亚洲美女在线国产| 日本韩国一区二区三区视频| 一区二区三区四区乱视频| 91久久精品一区二区| 《视频一区视频二区| av中文字幕在线不卡| 亚洲精品中文在线影院| 欧美性欧美巨大黑白大战| 亚洲午夜免费视频| 欧美日韩成人激情| 免费久久99精品国产| 精品99一区二区三区| 狠狠色伊人亚洲综合成人| 久久伊99综合婷婷久久伊| 国产激情一区二区三区| 成人欧美一区二区三区视频网页 | 亚洲国产日韩精品| 欧美日韩亚洲高清一区二区| 蜜臀av一区二区| 国产午夜精品一区二区| 91女人视频在线观看| 亚洲在线成人精品| 日韩一区二区免费在线观看| 国产精品18久久久久久vr| 国产精品久久久久久一区二区三区 | 久久aⅴ国产欧美74aaa| 国产欧美精品一区二区色综合| 91在线精品一区二区| 午夜影视日本亚洲欧洲精品| 欧美精品一区在线观看| www.av精品| 丝袜美腿一区二区三区| 欧美精品一区在线观看| 99re成人精品视频| 日韩精品一二区| 欧美国产精品久久| 在线观看免费一区| 免费看日韩精品| 国产精品亲子乱子伦xxxx裸| 欧美日韩视频在线一区二区| 国内精品免费**视频| 综合欧美亚洲日本| 日韩精品在线一区二区| 91在线国产观看| 美腿丝袜亚洲色图| 136国产福利精品导航| 日韩精品一区二区三区四区| aaa国产一区| 蜜桃视频在线观看一区| 亚洲免费电影在线| 日韩免费视频一区| 欧美亚洲一区二区三区四区| 国产一区二区在线视频| 亚洲一区在线电影| 国产欧美日韩亚州综合 | 色综合色狠狠综合色| 免费看日韩精品| 亚洲综合成人网| 国产清纯白嫩初高生在线观看91| 欧美日本一道本| av在线不卡观看免费观看| 精品一区二区三区在线观看| 亚洲精品第一国产综合野| 久久综合久久综合久久综合| 欧美视频中文字幕| 91在线云播放| 国产成人激情av|