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

📄 i82527.c

📁 CANOPen通信的一些源码
💻 C
📖 第 1 页 / 共 5 页
字号:
		    }    	if((pDev->pCtrl->chnMode[channelNum] != WNCAN_CHN_TRANSMIT) &&		(pDev->pCtrl->chnMode[channelNum] != WNCAN_CHN_RTR_REQUESTER))    {        errnoSet(S_can_illegal_config);        		goto exit;    }		if(len > 8)    {        errnoSet(S_can_illegal_data_length);        goto exit;    }    		/* check if tx request is set before modifying contents */	value = pDev->pBrd->canInByte(pDev, (I82527_R_XMT +		(I82527_OFFS_MSG * channelNum) + I82527_OFFS_CTRL1));		if(value & 0x20)	{		errnoSet(S_can_busy);		goto exit;	}		/*Check if EnableChannel has been called earlier and channel	  marked as valid. If yes, store state to restore later */	prevState = pDev->pBrd->canInByte(pDev, (I82527_R_XMT +		(I82527_OFFS_MSG * channelNum) + I82527_OFFS_CTRL0));		/*	mark message object as invalid:            MsgVal   = 0 1	unchanged transmit interrupt enable:       TXIE     = 1 1 	unchanged receive interrrupt enable:       RXIE     = 1 1	unchanged   interrupt pending:             IntPnd   = 0 1	7 6      5 4   3 2   1 0	MsgVal   TXIE  RXIE  IntPnd	*/    pDev->pBrd->canOutByte(pDev, (I82527_R_XMT +		(I82527_OFFS_MSG * channelNum) + I82527_OFFS_CTRL0), 0x7d);		/* 	reset remote transmission pending      RmtPnd = 0 1	reset transmit request:                TxRqst = 0 1	reset new data:                        NewDat = 0 1	set CPU update :                       CPUUpd = 1 0		7 6      5 4      3 2      1 0	RmtPnd   TxRqst   NewDat   CPUUpd 	*/		pDev->pBrd->canOutByte(pDev, (I82527_R_XMT +		(I82527_OFFS_MSG * channelNum) + I82527_OFFS_CTRL1), 0x56);		/* Read the message configuration register */	value = pDev->pBrd->canInByte(pDev,(I82527_R_XMT +		(I82527_OFFS_MSG * channelNum) + I82527_OFFS_MCR));		/* Set direction to receive if remote requester; otherwise, transmit */	if (pDev->pCtrl->chnMode[channelNum] != WNCAN_CHN_RTR_REQUESTER)		value |= 0x8;	else		value &= ~0x8;		/* Clear the data length code of the message config register */	value &= 0x0f;		value |= (len << 4);		/* Set the type of message: standard or extended */	if (ext == FALSE)		value &= ~0x4;	else		value |= 0x4;		/* Output new value to message config. register */	pDev->pBrd->canOutByte(pDev,(I82527_R_XMT +		(I82527_OFFS_MSG * channelNum) + I82527_OFFS_MCR),value);		/* Write the CAN Id */	if (ext == FALSE)	{		/* standard message */		value = canId >> 3;		pDev->pBrd->canOutByte(pDev,(I82527_R_XMT +			(I82527_OFFS_MSG * channelNum) + I82527_OFFS_ARBIT), value);				value = canId << 5;		pDev->pBrd->canOutByte(pDev, (I82527_R_XMT +			(I82527_OFFS_MSG * channelNum) +			I82527_OFFS_ARBIT + 0x1),value);	}	else	{		/* extended message */		value = canId >> (24-3);		pDev->pBrd->canOutByte(pDev, (I82527_R_XMT +			(I82527_OFFS_MSG * channelNum) + I82527_OFFS_ARBIT), value);				value = canId >> (16-3);		pDev->pBrd->canOutByte(pDev, (I82527_R_XMT +			(I82527_OFFS_MSG * channelNum) +			I82527_OFFS_ARBIT + 1), value);				value = canId >> (8-3);		pDev->pBrd->canOutByte(pDev, (I82527_R_XMT +			(I82527_OFFS_MSG * channelNum) +			I82527_OFFS_ARBIT + 2), value);				value = canId << 3;		pDev->pBrd->canOutByte(pDev, (I82527_R_XMT +			(I82527_OFFS_MSG * channelNum) +			I82527_OFFS_ARBIT + 0x3), value);	}		/* write up to 8 bytes of data if not remote message*/	if (pDev->pCtrl->chnMode[channelNum] != WNCAN_CHN_RTR_REQUESTER)	{		for(i = 0 ; i < len ; i++)			pDev->pBrd->canOutByte(pDev,(I82527_R_XMT +			(I82527_OFFS_MSG * channelNum) +			I82527_OFFS_DATA + i), data[i]);	}			/*	Enable Transmit message:	reset remote pending:      RmtPnd = 0 1	set transmit request:      TxRqst = 1 0	reset cpu upate:           CpuUdt = 0 1   	set new data bit:          NewDat = 1 0	*/  		pDev->pBrd->canOutByte(pDev, (I82527_R_XMT +		(I82527_OFFS_MSG * channelNum) + I82527_OFFS_CTRL1),0x66);	/* If EnableChannel is called earlier, state of channel is restored to valid*/	/* Else transmit request is set but channel is not marked as valid */	if(prevState & 0x80)		pDev->pBrd->canOutByte(pDev, (I82527_R_XMT +			(I82527_OFFS_MSG * channelNum) + I82527_OFFS_CTRL0), 0xbf);		retCode = OK;	exit:	return retCode;}    /************************************************************************** I82527_SetGlobalRxFilter - set the global receive filter** This routine sets the global HW filter mask for incoming messages on the* device controller. If the controller does not have a global filter this* function is a no-op. If the ext parameter is TRUE, the mask value applies* to extended messages; otherwise, the mask values applies to standard * messages. A value of "0" for a particular bit position of the mask means * don't care (i.e. the incoming message Id could have a value of zero or one* for this bit position){}; otherwise, a value of 1 means the corresponding * bit of the message Id must match identically.** RETURNS:        OK always*   * ERRNO:          N/A**/static STATUS I82527_SetGlobalRxFilter      (	  struct WNCAN_Device *pDev,	  long inputMask,	  BOOL ext	  ){	ULONG mask;    UCHAR value;        if (ext == 0)    {		mask = (ULONG)inputMask;        value = mask >> 3;        pDev->pBrd->canOutByte(pDev,I82527_R_GMS,value);                 value = mask << 5;        pDev->pBrd->canOutByte(pDev, I82527_R_GMS + 1,value);    }    else    {		mask = (ULONG)inputMask;        value = mask >> (24 - 3);        pDev->pBrd->canOutByte(pDev,I82527_R_GME,value);        value = mask >> (16 - 3);        pDev->pBrd->canOutByte(pDev,I82527_R_GME+1,value);        value = mask >> (8 - 3);        pDev->pBrd->canOutByte(pDev,I82527_R_GME+2,value);        value = mask << 3;        pDev->pBrd->canOutByte(pDev,I82527_R_GME+3,value);    }    return OK;}/************************************************************************** I82527_GetGlobalRxFilter - get the global receive filter** This routine reads the global HW filter mask for incoming messages on the* device controller. If the controller does not have a global filter this* function returns -1** RETURNS:        long: mask or -1 if not supported*   * ERRNO:          N/A**/static long I82527_GetGlobalRxFilter      (	  struct WNCAN_Device *pDev,	  BOOL ext	  ){	ULONG  mask;	UCHAR  value;    		if(ext == 0)	{		value = pDev->pBrd->canInByte(pDev,I82527_R_GMS);		mask  = (UINT)(value) << 3;        		value = pDev->pBrd->canInByte(pDev, I82527_R_GMS + 1);        mask  |= (UINT)(value) >> 5;			}	else	{		value = pDev->pBrd->canInByte(pDev,I82527_R_GME+3);		mask  = (UINT)(value) >> 3;		value = pDev->pBrd->canInByte(pDev,I82527_R_GME+2);		mask  |= (UINT)(value) << (8 - 3);		value = pDev->pBrd->canInByte(pDev,I82527_R_GME+1);		mask  |= (UINT)(value) << (16 - 3);		                		        value = pDev->pBrd->canInByte(pDev,I82527_R_GME);        		mask |= (UINT)(value) << (24 - 3);		        	}			return (long)mask; }/************************************************************************* I82527_SetLocalMsgFilter -  set local message object 15 filter. Message*                             objects are 0-based indices, so this translates*                             to msg obj 14 here.*                           * This routine sets a local message object filter for incoming messages on a * particular channel. ** If the controller does not support a local message object filter this * function is a no-op. If the ext parameter is TRUE, the mask value applies* to extended messages; otherwise, the mask values applies to standard * messages. A value of "0" for a particular bit position of the mask means * don't care (i.e. the incoming message Id could have a value of zero or * one for this bit position); otherwise, a value of 1 means the * corresponding bit of the message Id must match identically. Channel number* is provided for controllers that have more than one local message object * filter** RETURNS: OK, ERROR*   * ERRNO: S_can_illegal_channel_no**/     static STATUS I82527_SetLocalMsgFilter      (	  struct WNCAN_Device *pDev,	  UCHAR channel,	  long  inputMask,	  BOOL ext	  ){	ULONG  mask;    UCHAR  value;	STATUS retCode = OK;	mask = (ULONG)inputMask;	if(channel!=14)	{		errnoSet(S_can_illegal_channel_no);				retCode=ERROR;		return retCode;	}	if(ext==0){		/* standard message */		pDev->pBrd->canOutByte(pDev,I82527_R_M15M, 0);				pDev->pBrd->canOutByte(pDev,I82527_R_M15M + 1, 0);		value = mask  >> 3;		pDev->pBrd->canOutByte(pDev,I82527_R_M15M + 2, value);				value = mask << 5;		pDev->pBrd->canOutByte(pDev,I82527_R_M15M + 3, value);			}	else {		value = mask >> (24 -3);		pDev->pBrd->canOutByte(pDev,I82527_R_M15M, value);				value = mask >> (16 -3);		pDev->pBrd->canOutByte(pDev,I82527_R_M15M + 1, value);				value = mask >> (8 -3);		pDev->pBrd->canOutByte(pDev,I82527_R_M15M + 2 , value);				value = mask << 3;		pDev->pBrd->canOutByte(pDev,I82527_R_M15M + 3, value);	}	     return retCode;}/************************************************************************** I82527_GetLocalMsgFilter - get the local receive filter** This routine reads the local HW filter mask for incoming messages on the* specified channel. If the channel does not have a local filter this* function is a no-op. ** RETURNS:        long: maskValue or -1 if error*   * ERRNO:          N/A**/static long I82527_GetLocalMsgFilter      (	  struct WNCAN_Device *pDev,	  UCHAR  channel,	  BOOL   ext	  ){	UINT   mask=0xffffffff;	UCHAR  value;	if(channel!=14)	{		errnoSet(S_can_illegal_channel_no);						goto exit;	}    		if(ext == 0)	{		value = pDev->pBrd->canInByte(pDev,I82527_R_M15M);		mask  = (UINT)(value) << 3;        		value = pDev->pBrd->canInByte(pDev, I82527_R_M15M + 1);        mask  |= (UINT)(value) >> 5;			}	else	{		value = pDev->pBrd->canInByte(pDev,I82527_R_M15M+3);		mask  = (UINT)(value) >> 3;		value = pDev->pBrd->canInByte(pDev,I82527_R_M15M+2);		mask  |= (UINT)(value) << (8 - 3);		value = pDev->pBrd->canInByte(pDev,I82527_R_M15M+1);		mask  |= (UINT)(value) << (16 - 3);		                		        value = pDev->pBrd->canInByte(pDev,I82527_R_M15M);        		mask |= (UINT)(value) << (24 - 3);		        	}	exit:		return (long)mask; }/************************************************************************** I82527_IsMessageLost - test if a message was lost** This routine tests if the current message data in the channel overwrote* the old message data before I82527_ReadData() was called. Valid only for* channels with mode = WNCAN_CHN_RECEIVE.** RETURNS:        0 if FALSE, 1 if TRUE, or -1 if ERROR*   * ERRNO:          S_can_illegal_channel_no, S_can_illegal_config**/static int I82527_IsMessageLost      (	  struct WNCAN_Device *pDev,	  UCHAR channelNum	  ){    int retCode = -1; /* pessimistic */    UCHAR  value;        if (channelNum >= I82527_MAX_MSG_OBJ)    {        errnoSet(S_can_illegal_channel_no);    }    else if((pDev->pCtrl->chnMode[channelNum] != WNCAN_CHN_RECEIVE) &&        (pDev->pCtrl->chnMode[channelNum] != WNCAN_CHN_RTR_REQUESTER))    {        errnoSet(S_can_illegal_config);            }    else    {        value = pDev->pBrd->canInByte(pDev, (I82527_R_XMT +            (I82527_OFFS_MSG * channelNum) + I82527_OFFS_CTRL1));		        if (value & 0x08)            retCode = 1;        else            retCode = 0;    }	    return retCode;}/************************************************************************** I82527_ClearMessageLost - Clear message lost indication ** This function clears data overrun flag for a particular channel* Valid only for channels with mode = WNCAN_CHN_RECEIVE or* WNCAN_CHN_RTR_REQUESTER** RETURNS:        Ok or ERROR** ERRNO:          S_can_illegal_channel_no,*                 S_can_illegal_config**/static STATUS I82527_ClearMessageLost      (	  struct WNCAN_Device *pDev,	  UCHAR channelNum	  ){	STATUS retCode = ERROR;	    if (channelNum >= I82527_MAX_MSG_OBJ)    {        errnoSet(S_can_illegal_channel_no);    }

⌨️ 快捷键说明

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