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

📄 udp.s

📁 AVR单片机系统开发经典实例部分源程序
💻 S
📖 第 1 页 / 共 2 页
字号:
	.module udp.c
	.area lit(rom, con, rel)
_udp_str1::
	.byte 32,32,32,32,'U,'D,'P,'H,'d,'r,58,32,'S,'r,'c,'P
	.byte 'r,'t,58,0
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\udp.c
	.dbsym e udp_str1 _udp_str1 A[20:20]kc
_udp_str2::
	.byte 32,'D,'e,'s,'t,'P,'r,'t,58,0
	.dbsym e udp_str2 _udp_str2 A[10:10]kc
_udp_str3::
	.byte 32,'L,'e,'n,58,0
	.dbsym e udp_str3 _udp_str3 A[6:6]kc
_udp_str4::
	.byte 32,'C,'h,'k,'s,'u,'m,58,0
	.dbsym e udp_str4 _udp_str4 A[9:9]kc
_udp_str5::
	.byte 32,'D,'a,'t,'a,'B,'y,'t,'e,'s,58,0
	.dbsym e udp_str5 _udp_str5 A[12:12]kc
_udp_str6::
	.byte 32,45,32,'B,'L,'O,'C,'K,'E,'D,10,0
	.dbsym e udp_str6 _udp_str6 A[12:12]kc
_udp_str7::
	.byte 42,42,42,32,'U,'D,'P,32,'c,'h,'k,'s,'u,'m,32,'e
	.byte 'r,'r,10,0
	.dbsym e udp_str7 _udp_str7 A[20:20]kc
	.area data(ram, con, rel)
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\udp.c
_UDP_Header::
	.blkb 2
	.area idata
	.word 0
	.area data(ram, con, rel)
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\udp.c
	.dbstruct 0 8 TUDPHeader
	.dbfield 0 SourcePort s
	.dbfield 2 DestPort s
	.dbfield 4 Length s
	.dbfield 6 Checksum s
	.dbend
	.dbsym e UDP_Header _UDP_Header pS[TUDPHeader]
	.area text(rom, con, rel)
	.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\udp.c
	.dbfunc e UDP_DisplayHeader _UDP_DisplayHeader fV
;     TotalBytes -> R20,R21
;      HeaderIdx -> R22,R23
	.even
_UDP_DisplayHeader::
	xcall push_gset2
	movw R20,R18
	movw R22,R16
	sbiw R28,2
	.dbline -1
	.dbline 74
; 
; /*
;  * Copyright (C) 2003-2004 by Clive Moss All rights reserved.
;  *
;  * Help & Contributions from D.J.Armstrong
; 
;  * Redistribution and use in source and binary forms, with or without
;  * modification, are permitted provided that the following conditions
;  * are met:
;  *
;  * 1. Redistributions of source code must retain the above copyright
;  *    notice, this list of conditions and the following disclaimer.
;  * 2. Redistributions in binary form must reproduce the above copyright
;  *    notice, this list of conditions and the following disclaimer in the
;  *    documentation and/or other materials provided with the distribution.
;  * 3. Neither the name of the copyright holders nor the names of
;  *    contributors may be used to endorse or promote products derived
;  *    from this software without specific prior written permission.
;  *
;  * THIS SOFTWARE IS PROVIDED BY CLIVE MOSS 'AS IS' AND ANY EXPRESS OR
;  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
;  * ARE DISCLAIMED.
;  * IN NO EVENT SHALL CLIVE MOSS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
;  * INDIRECT, INCIDENTAL,SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
;  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
;  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
;  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
;  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
;  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
;  * SUCH DAMAGE.
;  */
; 
; //#ifdef CPU_eZ8
; //	#pragma stkck									// enable stack checking
; //#endif
; #include <iom128v.h>
; #include <string.h>
; #include <stdio.h>
; 
; #include "common.h"
; #include "ppp.h"
; #include "ip.h"
; #include "udp.h"
; 
; #ifdef IncludeNTP
; #include "ntp.h"
; #endif
; 
; #ifdef Debug
; flash char	udp_str1[]	=	"    UDPHdr: SrcPrt:";
; flash char	udp_str2[]	=	" DestPrt:";
; flash char	udp_str3[]	=	" Len:";
; flash char	udp_str4[]	=	" Chksum:";
; flash char	udp_str5[]	=	" DataBytes:";
; flash char	udp_str6[]	=	" - BLOCKED\n";
; flash char	udp_str7[]	=	"*** UDP chksum err\n";
; #endif
; 
; #ifdef CPU_eZ8
; near u16			UDP_len;
; #endif
; #ifdef CPU_ATmega128
; u16					UDP_len;
; #endif
; 
; T_UDP_Header		*UDP_Header = NULL;
; 
; //*********************************************************************************************************************
; 
; #ifdef Debug
; 
; void UDP_DisplayHeader(int HeaderIdx, int TotalBytes)
; {
	.dbline 86
; /*
; 	 0                   1                   2                   3
; 	 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
; 	+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
; 	|          Source Port          |       Destination Port        |
; 	+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
; 	|           Length              |         Checksum              |
; 	+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
; */
; 	// display the header
; 
; 	if (!SendDebugRStr(udp_str1)) return;
	ldi R16,<_udp_str1
	ldi R17,>_udp_str1
	xcall _SendDebugRStr
	tst R16
	brne L2
	.dbline 86
	xjmp L1
L2:
	.dbline 87
; 	sprintf((char*)ScratchPad, "%u", ntohs(UDP_Header->SourcePort));
	lds R30,_UDP_Header
	lds R31,_UDP_Header+1
	ldd R16,z+0
	ldd R17,z+1
	xcall _ntohs
	std y+1,R17
	std y+0,R16
	ldi R18,<L4
	ldi R19,>L4
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _sprintf
	.dbline 88
; 	if (!SendDebugStr((char*)ScratchPad)) return;
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _SendDebugStr
	tst R16
	brne L5
	.dbline 88
	xjmp L1
L5:
	.dbline 90
; 
; 	if (!SendDebugRStr(udp_str2)) return;
	ldi R16,<_udp_str2
	ldi R17,>_udp_str2
	xcall _SendDebugRStr
	tst R16
	brne L7
	.dbline 90
	xjmp L1
L7:
	.dbline 91
; 	sprintf((char*)ScratchPad, "%u", ntohs(UDP_Header->DestPort));
	lds R30,_UDP_Header
	lds R31,_UDP_Header+1
	ldd R16,z+2
	ldd R17,z+3
	xcall _ntohs
	std y+1,R17
	std y+0,R16
	ldi R18,<L4
	ldi R19,>L4
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _sprintf
	.dbline 92
; 	if (!SendDebugStr((char*)ScratchPad)) return;
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _SendDebugStr
	tst R16
	brne L9
	.dbline 92
	xjmp L1
L9:
	.dbline 94
; 
; 	if (!SendDebugRStr(udp_str3)) return;
	ldi R16,<_udp_str3
	ldi R17,>_udp_str3
	xcall _SendDebugRStr
	tst R16
	brne L11
	.dbline 94
	xjmp L1
L11:
	.dbline 95
; 	sprintf((char*)ScratchPad, "%u", ntohs(UDP_Header->Length));
	lds R30,_UDP_Header
	lds R31,_UDP_Header+1
	ldd R16,z+4
	ldd R17,z+5
	xcall _ntohs
	std y+1,R17
	std y+0,R16
	ldi R18,<L4
	ldi R19,>L4
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _sprintf
	.dbline 96
; 	if (!SendDebugStr((char*)ScratchPad)) return;
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _SendDebugStr
	tst R16
	brne L13
	.dbline 96
	xjmp L1
L13:
	.dbline 98
; 
; 	if (!SendDebugRStr(udp_str4)) return;
	ldi R16,<_udp_str4
	ldi R17,>_udp_str4
	xcall _SendDebugRStr
	tst R16
	brne L15
	.dbline 98
	xjmp L1
L15:
	.dbline 99
; 	sprintf((char*)ScratchPad, "%04x", ntohs(UDP_Header->Checksum));
	lds R30,_UDP_Header
	lds R31,_UDP_Header+1
	ldd R16,z+6
	ldd R17,z+7
	xcall _ntohs
	std y+1,R17
	std y+0,R16
	ldi R18,<L17
	ldi R19,>L17
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _sprintf
	.dbline 100
; 	if (!SendDebugStr((char*)ScratchPad)) return;
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _SendDebugStr
	tst R16
	brne L18
	.dbline 100
	xjmp L1
L18:
	.dbline 104
; 
; 	// done
; 
; 	if (!SendDebugRStr(udp_str5)) return;
	ldi R16,<_udp_str5
	ldi R17,>_udp_str5
	xcall _SendDebugRStr
	tst R16
	brne L20
	.dbline 104
	xjmp L1
L20:
	.dbline 105
	movw R24,R22
	adiw R24,8
	movw R2,R20
	sub R2,R24
	sbc R3,R25
	std y+1,R3
	std y+0,R2
	ldi R18,<L22
	ldi R19,>L22
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _sprintf
	.dbline 106
	ldi R16,<_ScratchPad
	ldi R17,>_ScratchPad
	xcall _SendDebugStr
	tst R16
	brne L23
	.dbline 106
L23:
	.dbline -2
L1:
	adiw R28,2
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r TotalBytes 20 I
	.dbsym r HeaderIdx 22 I
	.dbend
	.dbfunc e UDP_StartPacket _UDP_StartPacket fc
;       DestPort -> y+12
;     SourcePort -> y+10
;             IP -> y+6
	.even
_UDP_StartPacket::
	xcall push_arg4
	xcall push_gset2
	sbiw R28,2
	.dbline -1
	.dbline 114
; 	sprintf((char*)ScratchPad, "%u\n", TotalBytes - (HeaderIdx + sizeof(T_UDP_Header)));
; 	if (!SendDebugStr((char*)ScratchPad)) return;
; }
; 
; #endif
; 
; //*********************************************************************************************************************
; 
; bool UDP_StartPacket(u32 IP, u16 SourcePort, u16 DestPort)
; {
	.dbline 115
; 	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+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brne L26
	.dbline 115
	clr R16
	xjmp L25
L26:
	.dbline 116
; 	if (MainBufferWr_Rx > 0) return false;												//
	clr R2
	clr R3
	lds R4,_MainBufferWr_Rx
	lds R5,_MainBufferWr_Rx+1
	cp R2,R4
	cpc R3,R5
	brge L28
	.dbline 116
	clr R16
	xjmp L25
L28:
	.dbline 117
; 	if (MainBufferWr_Tx) return false;													//
	lds R2,_MainBufferWr_Tx
	lds R3,_MainBufferWr_Tx+1
	tst R2
	brne X0
	tst R3
	breq L30
X0:
	.dbline 117
	clr R16
	xjmp L25
L30:
	.dbline 119
; 																						//
; 	IP_StartPacket(IP_PROTO_UDP, IP);													// start the IP packet off
	movw R30,R28
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	std y+0,R4
	std y+1,R5

⌨️ 快捷键说明

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