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

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

?? conn1.c

?? microchip公司的DeviceNet協議桟源碼
?? C
?? 第 1 頁 / 共 2 頁
字號:
/*****************************************************************************
 *
 * Microchip DeviceNet Stack (Explicit Messaging Connection Object Source)
 *
 *****************************************************************************
 * FileName:        conn1.c
 * Dependencies:    
 * Processor:       PIC18F with CAN
 * Compiler:       	C18 02.20.00 or higher
 * Linker:          MPLINK 03.40.00 or higher
 * Company:         Microchip Technology Incorporated
 *
 * Software License Agreement
 *
 * The software supplied herewith by Microchip Technology Incorporated
 * (the "Company") is intended and supplied to you, the Company's
 * customer, for use solely and exclusively with products manufactured
 * by the Company. 
 *
 * The software is owned by the Company and/or its supplier, and is 
 * protected under applicable copyright laws. All rights are reserved. 
 * Any use in violation of the foregoing restrictions may subject the 
 * user to criminal sanctions under applicable laws, as well as to 
 * civil liability for the breach of the terms and conditions of this 
 * license.
 *
 * THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES, 
 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED 
 * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
 * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, 
 * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR 
 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 *
 *
 * This file contains Explicit messaging support for the Connection Object 
 * described in Section 5-4 and Chapter 7 of Volume 1 of the DeviceNet 
 * specification.
 * 
 *
 *
 * Author               Date        Comment
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * Ross Fosler			04/28/03	...	
 * 
 *****************************************************************************/

#include	"dnet.def"			// Global definitions file

#include 	"typedefs.h"

#include	"conn.h"			// Connection prototypes and symbols

#include	"services.h"		// Service codes
#include	"errors.h"			// Error codes
#include	"class.h"			// Class codes

#include	"route.h"			// Global symbols defined by the router
#include	"dnet.h"			// DeviceNet prototypes and symbols
#include	"frag.h"			// Fragmentation control

#include	"CAN.h"				// CAN driver


#define		_FRAG_SUCCESS	0
#define		_FRAG_TOO_MUCH	1





#define		RXFLAG_FIRST_FRAG		b0
#define		TXFLAG_SEND_ACK			b0
#define		TXFLAG_ACK_STAT			b1
#define		TXFLAG_TX_START			b2
#define		TXFLAG_TX_TIMER_EN		b3
#define		TXFLAG_TX_AGAIN			b4
#define		TXFLAG_TX_FIN			b5



#pragma 	udata
/*********************************************************************
 * Connection related variables
 ********************************************************************/
CONN_EXPL 		uConn1;

unsigned char	uConn1RxBuffer[CONN_EXPLICIT_RX_SIZE];
unsigned char	uConn1TxBuffer[CONN_EXPLICIT_TX_SIZE];



/*********************************************************************
 * Function:        unsigned char _Conn1Create(void)
 *
 * PreCondition:    none
 *
 * Input:       	none	
 *                  
 * Output:      	handle to connection
 *
 * Side Effects:    none
 *
 * Overview:        Returns a handle to the connection 
 *
 * Note:            none
 ********************************************************************/
unsigned char _Conn1Create(void)
{
	//Initialize the connection attributes
	uConn1.attrib.state = _STATE_ESTABLISHED;
	uConn1.attrib.produced_cid.bytes.MSB = uDNet.MACID | 0x80;
	uConn1.attrib.produced_cid.bytes.LSB = 0x60;
	uConn1.attrib.consumed_cid.bytes.MSB = uDNet.MACID | 0x80; 
	uConn1.attrib.consumed_cid.bytes.LSB = 0x80;
	uConn1.attrib.expected_packet_rate.word = 2500;
	uConn1.attrib.wdt_action = _WDT_ACTION_DEFERRED;
	
	_establishFlags.bits.expl = 1;
	_existentFlags.bits.expl = 1;
	
	// Setup the pointer and other info for the receiving side
	uConn1.rx.pMsg = uConn1RxBuffer;
	uConn1.rx.lenMax = CONN_EXPLICIT_RX_SIZE;
	uConn1.rx.fragFlags.byte = 0;
	uConn1.rx.oldFrag = 0;
	
	// Setup the pointer and other info for the transmitting side
	uConn1.tx.pMsg = uConn1TxBuffer;
	uConn1.tx.lenMax = CONN_EXPLICIT_TX_SIZE;
	uConn1.tx.fragFlags.byte = 0;
	uConn1.tx.oldFrag = 0;

	// Put 10000 or (rate)x(4), whichever is greater
	uConn1.timer.word = (uConn1.attrib.expected_packet_rate.word << 2);
	if (uConn1.timer.word < 10000) uConn1.timer.word = 10000;
	
	// Set the time
	uConn1.ack_tmr.word = EXPLICIT_ACK_TIMER;		
			
	//Issue a request to start receiving the CID
	CANSetFilter(uConn1.attrib.consumed_cid.word);
	return (1);
}


/*********************************************************************
 * Function:        unsigned char _Conn1Close(void)
 *
 * PreCondition:    
 *
 * Input:       	none		
 *                  
 * Output:      	status of the close
 *
 * Side Effects:    
 *
 * Overview:        Closes the specified connection 
 *
 * Note:            None
 ********************************************************************/
unsigned char _Conn1Close(void)
{	
	// Transition to the non-existent state
	uConn1.attrib.state = _STATE_NON_EXISTENT;
	
	_establishFlags.bits.expl = 0;
	_existentFlags.bits.expl = 0;
	
	// Issue a request to the driver to stop receiving the message
	CANClrFilter(uConn1.attrib.consumed_cid.word);

	return(1);
}





/*********************************************************************
 * Function:        void _Conn1TimerEvent(void)
 *
 * PreCondition:    
 *
 * Input:       	none		
 *                  
 * Output:      	none
 *
 * Side Effects:    
 *
 * Overview:        Update timer and process any timer events.
 *
 * Note:            None
 ********************************************************************/
void _Conn1TimerEvent(void)
{		
	// Process the watchdog if the packet rate is other than 0
	if (uConn1.attrib.expected_packet_rate.word)
	{
		// Adjust the time
		uConn1.timer.word -= TICK_RESOLUTION;

		// If the wdt expires then change the state of the connection
		if (uConn1.timer.word == 0) 
		{
			// Auto delete the connection
			if (uConn1.attrib.wdt_action == _WDT_ACTION_AUTO_DELETE)
			{ 
				uConn1.attrib.state = _STATE_NON_EXISTENT;
			}
			else 
			
			// Deferred delete (full release is determined outside 
			// of this instance)
			if (uConn1.attrib.wdt_action == _WDT_ACTION_DEFERRED) 
			{
				uConn1.attrib.state = _STATE_DEFERED_DELETE;
			}
		}
	}

#if	FRAGMENTATION_ACK
	// Process fragmentation timer for acknowledged transmission
	if (uConn1.tx.fragFlags.bits.TXFLAG_TX_TIMER_EN == 1)
	{
		// Adjust ack timer
		uConn1.ack_tmr.word -= TICK_RESOLUTION;

		// If the ack timer expires then change the frag state
		if (uConn1.ack_tmr.word == 0)
		{	
			// Disable the timer
			uConn1.tx.fragFlags.bits.TXFLAG_TX_TIMER_EN = 0;
			
			// Reset the time
			uConn1.ack_tmr.word = EXPLICIT_ACK_TIMER;

			// If a resend has been requested
			if (uConn1.tx.fragFlags.bits.TXFLAG_TX_AGAIN == 1)
			{
				// Kill the message
				// Reset the transmit state
				uConn1.tx.fragFlags.bits.TXFLAG_TX_START = 0;
				uConn1.tx.fragFlags.bits.TXFLAG_TX_FIN = 0;
				uConn1.tx.fragFlags.bits.TXFLAG_TX_AGAIN = 0;

				// Set flag indicating completion
				_txFinFlags.bits.expl = 1;
			}
			else
			{
				// Issue a resend
				uConn1.tx.fragFlags.bits.TXFLAG_TX_AGAIN = 1;
				_txFlag.bits.expl = 1;
			}
		}
	}
#endif
}




/*********************************************************************
 * Function:        void _Conn1RxEvent(void)
 *
 * PreCondition:    
 *
 * Input:       	none	
 *                  
 * Output:      	none
 *
 * Side Effects:    
 *
 * Overview:        Process data for this connection.
 *
 * Note:            This event occures when data has been received
 *					for this connection instance.
 ********************************************************************/
void _Conn1RxEvent(void)
{
	BYTE header, service, frag, count, type, len;
	unsigned char *pRxData;

	// Set the size of classId depending on what has been specified
	#if (CLASS_WIDTH_16BIT)
	UINT classId;
	#else
	BYTE classId;
	#endif
	
	// Get the pointer to the buffer
	pRxData = CANGetRxDataPtr();
	len.byte = CANGetRxCnt();
	
	// Extract the header	
	header.byte = *pRxData; 
		
#if	FRAGMENTATION_ACK				
	// If fragmented
	if (header.bits.b7)
	{
		// Process only if there is sufficient data to process the connection
		if (len.byte > 2)
		{
			// Point to the frag byte and copy it
			pRxData++;
			frag.byte = *pRxData; 
			
			// Point to the service
			pRxData++; 
			
			// Get the fragment type and count
			type.byte = frag.byte & 0xC0;
			count.byte = frag.byte & 0x3F;
		
			// If the header MAC equals the allocated MasterMACID then 
			// process the message fragment	
			if (((header.byte ^ uDNet.AllocInfo.MasterMACID) & 0x3F) == 0)
			{			
				// Remember the header
				uConn1.rx.header = header.byte; 
					
				// Process the fragment
				switch (type.byte)
				{
					// Received first fragment
					case 0x00:
						// The first fragment must always have a frag byte of 0
						if (frag.byte == 0)
						{
							// Copy the fragment to the buffer
							CANGetRxDataTyp2(uConn1.rx.pMsg + 1);
							
							// Store the header
							*uConn1.rx.pMsg = header.byte;
				
							// Adjust the length minus the fragment control byte
							uConn1.rx.len = len.byte - 1;
												
							// Request to issue an ACK with status	
							uConn1.tx.fragFlags.bits.TXFLAG_SEND_ACK = 1;
							uConn1.tx.fragFlags.bits.TXFLAG_ACK_STAT = 0;
							_txFlag.bits.expl = 1;
											
							// Reset the old fragment
							uConn1.rx.oldFrag = 0;
				
							// Indicate the first fragment has been received
							uConn1.rx.fragFlags.bits.RXFLAG_FIRST_FRAG = 1;
						}
						break;
						
					// Received a middle or last fragment
					case 0x40:
					case 0x80:
						// If this frag is the same as the previous then re-ack
						if (uConn1.rx.oldFrag == frag.byte)
						{
							// Set the status & request the hardware to send the ACK
							uConn1.tx.fragFlags.bits.TXFLAG_SEND_ACK = 1;
							uConn1.tx.fragFlags.bits.TXFLAG_ACK_STAT = 0;
							_txFlag.bits.expl = 1;
						}
						else
					
						// Continue if the first fragment has been received
						if (uConn1.rx.fragFlags.bits.RXFLAG_FIRST_FRAG)
						{						
							// Process the current fragment
							if (((uConn1.rx.oldFrag + 1) & 0x3F) == count.byte)
							{
								// if the buffer is large enough
								if ((uConn1.rx.len + (len.byte - 1)) < uConn1.rx.lenMax)
								{
						
									// Copy this fragment to the buffer
									CANGetRxDataTyp2(uConn1.rx.pMsg + uConn1.rx.len);
					
									// Store the length minus the fragment control byte and header
									uConn1.rx.len += (len.byte - 2);
								
									// Save the current fragment information
									uConn1.rx.oldFrag = frag.byte;
									
									// If this the last fragment in the sequence
									if (type.byte == 0x80)
									{
										// Indicate message has been received
										_rxFlag.bits.expl = 1;
									}
								
									// Set the status & request the hardware to send the ACK				
									uConn1.tx.fragFlags.bits.TXFLAG_SEND_ACK = 1;
									uConn1.tx.fragFlags.bits.TXFLAG_ACK_STAT = 0;
									_txFlag.bits.expl = 1;
								}
							
								//else send an error ack indicating too much data		
								else
								{
									// Set the status & request the hardware to send the ACK				
									uConn1.tx.fragFlags.bits.TXFLAG_SEND_ACK = 1;
									uConn1.tx.fragFlags.bits.TXFLAG_ACK_STAT = 1;
									_txFlag.bits.expl = 1;
								
									// Reset to the initial state
									uConn1.rx.fragFlags.bits.RXFLAG_FIRST_FRAG = 0;
								}
							}
						
							// Toss the fragment and reset to the first state
							else
							{
								// Reset to the initial state
								uConn1.rx.fragFlags.bits.RXFLAG_FIRST_FRAG = 0;
							}
						}
					
						// Fragment not expected
						else
						{
							// Reset to the initial state	
							uConn1.rx.fragFlags.bits.RXFLAG_FIRST_FRAG = 0;	
						}
						break;
						
										
					// Received an ACK
					case 0xC0:
						// Process ack if expecting it
						if (uConn1.tx.fragFlags.bits.TXFLAG_TX_START == 1)
						{
							// Stop the acknowledge timer if it was running
							uConn1.tx.fragFlags.bits.TXFLAG_TX_TIMER_EN = 0;

							// Reset the retry flag if it was set
							uConn1.tx.fragFlags.bits.TXFLAG_TX_AGAIN = 0;

							// If the last transmission has been sent
							if (uConn1.tx.fragFlags.bits.TXFLAG_TX_FIN == 1)
							{
								// Reset the transmit state
								uConn1.tx.fragFlags.bits.TXFLAG_TX_START = 0;
								uConn1.tx.fragFlags.bits.TXFLAG_TX_FIN = 0;
							}
							else
							{
								// Start up the next transmission
								_txFlag.bits.expl = 1;
							}
						}
						break;
					}
							
							
							
				
				// Put the connection into the established state
				uConn1.attrib.state = _STATE_ESTABLISHED;
				_establishFlags.bits.expl = 1;
				
				// Reset the connection wdt
				uConn1.timer.word = uConn1.attrib.expected_packet_rate.word << 2;
			}
		}
	}
#else
	// If fragmented
	if (header.bits.b7)
	{
		// Process only if there is sufficient data to process the connection
		if (len.byte > 2)
		{
			// If the header MAC equals the allocated MasterMACID then 
			// process the message fragment	
			if (((header.byte ^ uDNet.AllocInfo.MasterMACID) & 0x3F) == 0)
			{
				// Request to issue an ACK with error status	
				uConn1.tx.fragFlags.bits.TXFLAG_SEND_ACK = 1;
				uConn1.tx.fragFlags.bits.TXFLAG_ACK_STAT = 1;
				_txFlag.bits.expl = 1;
			}
		}
	}
#endif

	// else process a non-fragmented message
	else
	{ 
		// Process only if there is sufficient data to process the connection
		if (len.byte > 1)
		{
			// Extract the service ID  
			service.byte = *(pRxData + 1);
		
			// If the header MAC equals the allocated MasterMACID or if the release
			// connection service is requested then process the message.
			// (refer to section 5-5.4.2)
			#if (CLASS_WIDTH_16BIT)
			classId.bytes.LSB = *(pRxData + 2);
			classId.bytes.MSB = *(pRxData + 3);	
			if (((classId.word == CLASS_DEVICENET) && (service.byte == SRVS_RELEASE_CONN)) ||
				(header.byte ^ uDNet.AllocInfo.MasterMACID & 0x3F) == 0)
			#else
			classId.byte = *(pRxData + 2);
			if (((classId.byte == CLASS_DEVICENET) && (service.byte == SRVS_RELEASE_CONN)) ||
				(header.byte ^ uDNet.AllocInfo.MasterMACID & 0x3F) == 0)
			#endif

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品大尺度| 亚洲国产成人一区二区三区| 91视频在线观看| 国产一区二区三区在线观看免费| 日韩中文字幕不卡| 日韩av一区二区三区| 青椒成人免费视频| 激情六月婷婷久久| 国产在线精品一区二区夜色| 国产在线精品一区二区三区不卡 | 蜜臂av日日欢夜夜爽一区| 亚洲女爱视频在线| 亚洲在线观看免费| 亚洲成人免费影院| 日本美女视频一区二区| 久久成人免费电影| 国产精品亚洲午夜一区二区三区| 国产成人综合自拍| 成人小视频在线| 欧美在线看片a免费观看| 欧美日韩一区国产| 精品国精品自拍自在线| 精品国产一区二区三区不卡| 国产亚洲欧美日韩在线一区| 国产精品色婷婷| 一二三四区精品视频| 天天色天天爱天天射综合| 久久精品国产亚洲aⅴ| 国产东北露脸精品视频| 91女神在线视频| 欧美电影一区二区| 中文一区一区三区高中清不卡| 亚洲精品成人少妇| 美女网站一区二区| 91亚洲国产成人精品一区二三| 欧美片在线播放| 国产网站一区二区| 午夜视黄欧洲亚洲| 成人免费高清在线| 欧美一二三四在线| 亚洲免费三区一区二区| 精品一区二区三区香蕉蜜桃| 国产成人av福利| 欧美精品精品一区| 亚洲日本青草视频在线怡红院 | 久久久夜色精品亚洲| 国产精品久久久久久久浪潮网站| 亚洲电影视频在线| 高清beeg欧美| 日韩三级视频在线观看| 樱花草国产18久久久久| 国产v综合v亚洲欧| 日韩免费高清电影| 午夜精品福利在线| 色综合久久综合| 亚洲色图欧洲色图| 成人精品一区二区三区四区| 日韩区在线观看| 亚洲国产人成综合网站| 99久久亚洲一区二区三区青草| 国产成人在线影院| 欧美二区乱c少妇| 一区二区在线观看免费| av一区二区不卡| 欧美激情一区不卡| 粉嫩av一区二区三区粉嫩| 欧美mv和日韩mv的网站| 美女视频黄免费的久久| 欧美精品久久99久久在免费线 | 美女高潮久久久| 7777精品伊人久久久大香线蕉的| 亚洲欧美日韩国产综合| jiyouzz国产精品久久| 国产视频一区在线播放| 国产精品99久久久久久宅男| 精品国产一二三| 激情综合五月婷婷| 26uuu亚洲| 国产在线麻豆精品观看| 欧美国产激情二区三区| 懂色一区二区三区免费观看| 国产亚洲欧美在线| 99久久99精品久久久久久| 国产精品国产a| 欧美午夜影院一区| 日日嗨av一区二区三区四区| 91麻豆精品国产无毒不卡在线观看 | 美女网站视频久久| 久久亚洲精精品中文字幕早川悠里| 日本不卡免费在线视频| 欧美电影免费观看高清完整版在线观看| 视频在线观看国产精品| 26uuu精品一区二区在线观看| 国产老肥熟一区二区三区| 久久精品亚洲精品国产欧美| 成人午夜私人影院| 亚洲免费毛片网站| 欧美日韩午夜精品| 国产河南妇女毛片精品久久久| 国产精品久久久久久久久久免费看| 96av麻豆蜜桃一区二区| 亚洲第一av色| 久久综合九色综合97婷婷女人| 国产999精品久久久久久| 亚洲色图.com| 欧美成人精精品一区二区频| 成人性生交大片| 香港成人在线视频| 久久久久国产精品麻豆| 91国偷自产一区二区三区成为亚洲经典 | 伊人婷婷欧美激情| 日韩欧美一区电影| av电影一区二区| 麻豆国产精品视频| 一区二区久久久| 精品少妇一区二区三区视频免付费 | 日韩欧美123| 色94色欧美sute亚洲线路一ni| 日本一区中文字幕| 中文字幕字幕中文在线中不卡视频| 欧美天堂一区二区三区| 国产高清精品久久久久| 亚洲国产日韩a在线播放| 国产精品人成在线观看免费 | 韩国视频一区二区| 午夜一区二区三区在线观看| 中文字幕av在线一区二区三区| 欧美一区二区视频观看视频| 一本色道久久综合亚洲精品按摩| 久久国产综合精品| 一区二区三区欧美激情| 精品国产乱码久久久久久夜甘婷婷| 99re热这里只有精品免费视频| 国内精品写真在线观看| 午夜精品久久久久久久久久| 中文字幕视频一区二区三区久| 日韩精品一区国产麻豆| 高清不卡在线观看| 国产乱妇无码大片在线观看| 久久精品国产精品青草| 欧美aaa在线| 亚洲成国产人片在线观看| 亚洲老妇xxxxxx| 中文字幕一区二区三区不卡在线| 日韩欧美精品三级| 日韩一区二区精品| 这里只有精品99re| 欧美一区二区大片| 欧美高清视频www夜色资源网| 欧美亚洲一区二区在线| 欧美伊人久久大香线蕉综合69 | 成人三级在线视频| 国产成人啪免费观看软件| 国产一区二区h| 国产成人av自拍| 国产福利一区二区三区视频在线| 久久丁香综合五月国产三级网站| 日本女优在线视频一区二区| 美脚の诱脚舐め脚责91| 看电视剧不卡顿的网站| 国产麻豆视频精品| 粗大黑人巨茎大战欧美成人| 99久久er热在这里只有精品66| caoporn国产一区二区| 91视频国产观看| 欧美日韩视频一区二区| 91麻豆精品国产91久久久久久久久| 91精品国产综合久久小美女| 日韩精品中文字幕在线一区| 国产欧美精品在线观看| 中文字幕一区二区三区在线不卡| 亚洲黄色尤物视频| 日本网站在线观看一区二区三区| 九色|91porny| 成人动漫av在线| 欧美三级日韩三级| 精品国产一二三区| 亚洲免费成人av| 青青青爽久久午夜综合久久午夜 | 日韩一区欧美小说| 亚洲一本大道在线| 国产精品一级片在线观看| 91色.com| 日韩精品一区二区在线| 中文字幕亚洲一区二区av在线 | 久久精品人人做人人爽人人| 最新国产精品久久精品| 日韩 欧美一区二区三区| 国产福利视频一区二区三区| 欧美日韩综合一区| 欧美精品一区二区高清在线观看| 自拍偷在线精品自拍偷无码专区| 美美哒免费高清在线观看视频一区二区| 国产成人免费视频网站高清观看视频 | 精品国精品国产| 亚洲精品欧美激情| 国产乱子伦一区二区三区国色天香| 91在线视频播放| 久久众筹精品私拍模特| 舔着乳尖日韩一区|