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

📄 icmp.s

📁 AVR单片机系统开发经典实例部分源程序
💻 S
📖 第 1 页 / 共 2 页
字号:
	rol R19
	movw R16,R30
	xcall _IP_Checksum1
	xcall _htons
	lds R30,_IP_Header
	lds R31,_IP_Header+1
	std z+11,R17
	std z+10,R16
	.dbline 177
; 																	//
; 		MainBufferWr_Tx = MainBufferWr_Rx;							// number of bytes to the packet we are sending back
	lds R2,_MainBufferWr_Rx
	lds R3,_MainBufferWr_Rx+1
	sts _MainBufferWr_Tx+1,R3
	sts _MainBufferWr_Tx,R2
	.dbline 179
; 
; 		len = MainBufferWr_Tx;										//
	lds R10,_MainBufferWr_Tx
	lds R11,_MainBufferWr_Tx+1
	.dbline 181
; 
; 		if (!PPP_SendPacket(false)) return;							// send it
	clr R16
	xcall _PPP_SendPacket
	tst R16
	brne L38
	.dbline 181
	xjmp L29
L38:
	.dbline 184
; 
; 		#ifdef Debug
; 			IP_DisplayProtocol(true, len);							//
	movw R18,R10
	ldi R16,1
	xcall _IP_DisplayProtocol
	.dbline 185
; 			IP_DisplayHeader(4, len);								//
	movw R18,R10
	ldi R16,4
	ldi R17,0
	xcall _IP_DisplayHeader
	.dbline 186
; 			ICMP_DisplayHeader(4 + sizeof(T_IP_Header), len);		//
	movw R18,R10
	ldi R16,24
	ldi R17,0
	xcall _ICMP_DisplayHeader
	.dbline 189
; 		#endif
; 
; 		return;
	xjmp L29
L34:
	.dbline 194
	lds R30,_ICMP_Header
	lds R31,_ICMP_Header+1
	ldd R2,z+0
	tst R2
	breq X4
	xjmp L40
X4:
	.dbline 195
	.dbline 197
	ldi R16,<L42
	ldi R17,>L42
	xcall _SendDebugStr
	.dbline 200
	lds R2,_ICMP_SeqNum
	lds R3,_ICMP_SeqNum+1
	tst R2
	brne X2
	tst R3
	brne X5
	xjmp L29
X5:
X2:
	lds R30,_ICMP_Header
	lds R31,_ICMP_Header+1
	ldd R16,z+6
	ldd R17,z+7
	xcall _ntohs
	lds R2,_ICMP_SeqNum
	lds R3,_ICMP_SeqNum+1
	cp R16,R2
	cpc R17,R3
	brne L29
	lds R4,_ICMP_IP+2
	lds R5,_ICMP_IP+2+1
	lds R2,_ICMP_IP
	lds R3,_ICMP_IP+1
	lds R30,_IP_Header
	lds R31,_IP_Header+1
	ldd R6,z+12
	ldd R7,z+13
	ldd R8,z+14
	ldd R9,z+15
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brne L29
	.dbline 201
	.dbline 202
	clr R2
	clr R3
	sts _ICMP_SeqNum+1,R3
	sts _ICMP_SeqNum,R2
	.dbline 203
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	sts _ICMP_IP+1,R21
	sts _ICMP_IP,R20
	sts _ICMP_IP+2+1,R23
	sts _ICMP_IP+2,R22
	.dbline 205
	lds R2,_ICMP_Timer
	lds R3,_ICMP_Timer+1
	std y+1,R3
	std y+0,R2
	ldi R18,<L45
	ldi R19,>L45
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _sprintf
	.dbline 206
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _SendConsoleStr
	.dbline 207
	.dbline 209
L40:
	.dbline -2
L29:
	adiw R28,6
	xcall pop_gset3
	.dbline 0 ; func end
	ret
	.dbsym l dw 2 l
	.dbsym r len 10 s
	.dbend
	.dbfunc e ICMP_Out _ICMP_Out fc
;             w2 -> y+2
;            len -> R14,R15
;        RandNum -> R12,R13
;              w -> R10,R11
;             IP -> y+14
	.even
_ICMP_Out::
	xcall push_arg4
	xcall push_gset5
	sbiw R28,4
	.dbline -1
	.dbline 219
; 	}
; 
; 	// **********************
; 
; 	if (ICMP_Header->Type == ICMP_ECHO_REPLY)
; 	{	// PONG
; 		#ifdef Debug
; 			SendDebugStr("\n");
; 		#endif
; 
; 		if ((ICMP_SeqNum) && (ntohs(ICMP_Header->SeqNum) == ICMP_SeqNum) && (IP_Header->SourceIP.ip32 == ICMP_IP.ip32))
; 		{																	//
; 			ICMP_SeqNum = 0;												//
; 			ICMP_IP.ip32 = 0;												//
; 																			//
; 			sprintf((char*)ScratchPad, "   pong: %ums\n", ICMP_Timer);		//
; 			SendConsoleStr((char*)ScratchPad);								//
; 		}																	//
; 
; 		return;
; 	}
; 
; 	// **********************
; }
; 
; // **************************************************************************
; // send a ping out
; 
; bool ICMP_Out(u32 IP)
; {
	.dbline 222
; 	u16	w, w2, RandNum, len;
; 
; 	if (!IP) return false;															// no IP supplied
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R30,R28
	ldd R2,z+14
	ldd R3,z+15
	ldd R4,z+16
	ldd R5,z+17
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L47
	.dbline 222
	clr R16
	xjmp L46
L47:
	.dbline 223
; 	if (MainBufferWr_Rx > 0) return false;											// buffer is not yet free
	clr R2
	clr R3
	lds R4,_MainBufferWr_Rx
	lds R5,_MainBufferWr_Rx+1
	cp R2,R4
	cpc R3,R5
	brge L49
	.dbline 223
	clr R16
	xjmp L46
L49:
	.dbline 224
; 	if (MainBufferWr_Tx) return false;												// buffer is not yet free
	lds R2,_MainBufferWr_Tx
	lds R3,_MainBufferWr_Tx+1
	tst R2
	brne X6
	tst R3
	breq L51
X6:
	.dbline 224
	clr R16
	xjmp L46
L51:
	.dbline 226
	clr R12
	clr R13
	xjmp L56
L53:
	.dbline 226
	xcall _rand
	movw R12,R16
L54:
	.dbline 226
L56:
	.dbline 226
; 
; 	for (RandNum = 0; !RandNum; ) RandNum = (u16)rand();							//
	tst R12
	brne X7
	tst R13
	breq L53
X7:
	.dbline 229
; 
; 	// start the packet off (IP header etc)
; 	IP_StartPacket(IP_PROTO_ICMP, IP);												// start the IP packet off
	movw R30,R28
	ldd R2,z+14
	ldd R3,z+15
	ldd R4,z+16
	ldd R5,z+17
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldi R16,1
	xcall _IP_StartPacket
	.dbline 231
; 
; 	len = MainBufferWr_Tx;															//
	lds R14,_MainBufferWr_Tx
	lds R15,_MainBufferWr_Tx+1
	.dbline 234
; 
; 	// add the ICMP header
; 	ICMP_Header = (T_ICMP_Header*)(MainBuffer + MainBufferWr_Tx);					// point to the ICMP header
	ldi R24,<_MainBuffer
	ldi R25,>_MainBuffer
	movw R2,R14
	add R2,R24
	adc R3,R25
	sts _ICMP_Header+1,R3
	sts _ICMP_Header,R2
	.dbline 235
; 	memset(ICMP_Header, 0, sizeof(T_ICMP_Header));									// clear it
	ldi R24,8
	ldi R25,0
	std y+1,R25
	std y+0,R24
	clr R18
	clr R19
	movw R16,R2
	xcall _memset
	.dbline 236
; 	ICMP_Header->Type = ICMP_ECHO_REQUEST;											//
	ldi R24,8
	lds R30,_ICMP_Header
	lds R31,_ICMP_Header+1
	std z+0,R24
	.dbline 237
; 	ICMP_Header->Code = 0;															//
	clr R2
	lds R30,_ICMP_Header
	lds R31,_ICMP_Header+1
	std z+1,R2
	.dbline 238
; 	ICMP_Header->ID = htons(IP_ID++);												// use the IP ID - for now
	lds R2,_IP_ID
	lds R3,_IP_ID+1
	movw R24,R2
	adiw R24,1
	sts _IP_ID+1,R25
	sts _IP_ID,R24
	movw R16,R2
	xcall _htons
	lds R30,_ICMP_Header
	lds R31,_ICMP_Header+1
	std z+5,R17
	std z+4,R16
	.dbline 239
; 	ICMP_Header->SeqNum = htons(RandNum);											// sequence number
	movw R16,R12
	xcall _htons
	lds R30,_ICMP_Header
	lds R31,_ICMP_Header+1
	std z+7,R17
	std z+6,R16
	.dbline 240
; 	MainBufferWr_Tx += sizeof(T_ICMP_Header);										// update index
	lds R24,_MainBufferWr_Tx
	lds R25,_MainBufferWr_Tx+1
	adiw R24,8
	sts _MainBufferWr_Tx+1,R25
	sts _MainBufferWr_Tx,R24
	.dbline 243
	clr R10
	clr R11
	xjmp L60
L57:
	.dbline 243
	lds R2,_MainBufferWr_Tx
	lds R3,_MainBufferWr_Tx+1
	movw R24,R2
	adiw R24,1
	sts _MainBufferWr_Tx+1,R25
	sts _MainBufferWr_Tx,R24
	ldi R24,<_MainBuffer
	ldi R25,>_MainBuffer
	movw R30,R2
	add R30,R24
	adc R31,R25
	std z+0,R10
L58:
	.dbline 243
	movw R24,R10
	adiw R24,1
	movw R10,R24
L60:
	.dbline 243
; 																					//
; 	// add the ICMP data															//
; 	for (w = 0; w < 47; w++) MainBuffer[MainBufferWr_Tx++] = (u8)w;					// add some data - any data
	movw R24,R10
	cpi R24,47
	ldi R30,0
	cpc R25,R30
	brlo L57
	.dbline 245
; 																					//
; 	len = MainBufferWr_Tx - len;													//
	lds R2,_MainBufferWr_Tx
	lds R3,_MainBufferWr_Tx+1
	sub R2,R14
	sbc R3,R15
	movw R14,R2
	.dbline 247
; 																					//
; 	w2 = MainBufferWr_Tx;															//
	lds R2,_MainBufferWr_Tx
	lds R3,_MainBufferWr_Tx+1
	std y+3,R3
	std y+2,R2
	.dbline 249
; 																					//
; 	w = IP_Checksum1((char*)ICMP_Header, len);										// update the ICMP header checksum
	movw R18,R14
	lds R16,_ICMP_Header
	lds R17,_ICMP_Header+1
	xcall _IP_Checksum1
	movw R10,R16
	.dbline 251
; //	if (!w) w = 0xffff;																//
; 	ICMP_Header->Checksum = htons(w);												//
	xcall _htons
	lds R30,_ICMP_Header
	lds R31,_ICMP_Header+1
	std z+3,R17
	std z+2,R16
	.dbline 253
; 																					//
; 	IP_Header->TotalLength += len;													// update the IP header
	lds R24,_IP_Header
	lds R25,_IP_Header+1
	adiw R24,2
	movw R30,R24
	ldd R4,z+0
	ldd R5,z+1
	add R4,R14
	adc R5,R15
	std z+1,R5
	std z+0,R4
	.dbline 255
; 																					//
; 	IP_EndPacket();																	//
	xcall _IP_EndPacket
	.dbline 257
; 																					//
; 	if (!PPP_SendPacket(false)) return false;										// send it
	clr R16
	xcall _PPP_SendPacket
	tst R16
	brne L61
	.dbline 257
	clr R16
	xjmp L46
L61:
	.dbline 259
; 																					//
; 	ICMP_Timer = 0;																	// reset the timer
	clr R2
	clr R3
	sts _ICMP_Timer+1,R3
	sts _ICMP_Timer,R2
	.dbline 260
; 	ICMP_SeqNum = RandNum;															// remember the sequence number
	sts _ICMP_SeqNum+1,R13
	sts _ICMP_SeqNum,R12
	.dbline 261
; 	ICMP_IP.ip32 = IP;																// and the ip
	movw R30,R28
	ldd R2,z+14
	ldd R3,z+15
	ldd R4,z+16
	ldd R5,z+17
	sts _ICMP_IP+1,R3
	sts _ICMP_IP,R2
	sts _ICMP_IP+2+1,R5
	sts _ICMP_IP+2,R4
	.dbline 264
; 
; 	#ifdef Debug
; 		IP_DisplayProtocol(true, (int)w2);											//
	ldd R18,y+2
	ldd R19,y+3
	ldi R16,1
	xcall _IP_DisplayProtocol
	.dbline 265
; 		IP_DisplayHeader(4, (int)w2);												//
	ldd R18,y+2
	ldd R19,y+3
	ldi R16,4
	ldi R17,0
	xcall _IP_DisplayHeader
	.dbline 266
; 		ICMP_DisplayHeader(4 + sizeof(T_IP_Header), (int)w2);						//
	ldd R18,y+2
	ldd R19,y+3
	ldi R16,24
	ldi R17,0
	xcall _ICMP_DisplayHeader
	.dbline 269
; 	#endif
; 
; 	return true;
	ldi R16,1
	.dbline -2
L46:
	adiw R28,4
	xcall pop_gset5
	adiw R28,4
	.dbline 0 ; func end
	ret
	.dbsym l w2 2 s
	.dbsym r len 14 s
	.dbsym r RandNum 12 s
	.dbsym r w 10 s
	.dbsym l IP 14 l
	.dbend
	.dbfunc e ICMP_10ms_Timer _ICMP_10ms_Timer fV
	.even
_ICMP_10ms_Timer::
	xcall push_gset2
	.dbline -1
	.dbline 276
; }
; 
; // **************************************************************************
; // this is called from the ip module - every 10ms
; 
; void ICMP_10ms_Timer(void)
; {
	.dbline 277
; 	if (ICMP_Timer < 5000)										//
	lds R24,_ICMP_Timer
	lds R25,_ICMP_Timer+1
	cpi R24,136
	ldi R30,19
	cpc R25,R30
	brsh L64
	.dbline 278
; 		ICMP_Timer += 10;										// update the timer
	lds R24,_ICMP_Timer
	lds R25,_ICMP_Timer+1
	adiw R24,10
	sts _ICMP_Timer+1,R25
	sts _ICMP_Timer,R24
	xjmp L65
L64:
	.dbline 280
	.dbline 281
	clr R2
	clr R3
	sts _ICMP_SeqNum+1,R3
	sts _ICMP_SeqNum,R2
	.dbline 282
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	sts _ICMP_IP+1,R21
	sts _ICMP_IP,R20
	sts _ICMP_IP+2+1,R23
	sts _ICMP_IP+2,R22
	.dbline 283
L65:
	.dbline -2
L63:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbend
	.area bss(ram, con, rel)
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\icmp.c
_ICMP_IP::
	.blkb 4
	.dbunion 0 4 TIPAddr
	.dbfield 0 ip8 A[4:4]c
	.dbfield 0 ip32 l
	.dbend
	.dbsym e ICMP_IP _ICMP_IP S[TIPAddr]
_ICMP_SeqNum::
	.blkb 2
	.dbsym e ICMP_SeqNum _ICMP_SeqNum s
_ICMP_Timer::
	.blkb 2
	.dbsym e ICMP_Timer _ICMP_Timer s
	.area data(ram, con, rel)
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\icmp.c
L45:
	.blkb 15
	.area idata
	.byte 32,32,32,'p,'o,'n,'g,58,32,37,'u,'m,'s,10,0
	.area data(ram, con, rel)
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\icmp.c
L42:
	.blkb 2
	.area idata
	.byte 10,0
	.area data(ram, con, rel)
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\icmp.c
L26:
	.blkb 4
	.area idata
	.byte 37,'u,10,0
	.area data(ram, con, rel)
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\icmp.c
L13:
	.blkb 5
	.area idata
	.byte 37,48,52,'X,0
	.area data(ram, con, rel)
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\icmp.c
L4:
	.blkb 3
	.area idata
	.byte 37,'u,0
	.area data(ram, con, rel)
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\icmp.c

⌨️ 快捷键说明

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