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

📄 uip.s

📁 uIP是免费的TCP/IP协议栈,我们将它移植到我们的AVR以太网开发板中
💻 S
📖 第 1 页 / 共 5 页
字号:
	.module uip.c
	.area lit(rom, con, rel)
_uip_hostaddr::
	.word 43200
	.word 25344
	.dbfile D:\hexok项目\AVRNET项目\AVRNET光盘\AVRuIP\uip.c
	.dbsym e uip_hostaddr _uip_hostaddr A[4:2]ks
_uip_arp_draddr::
	.word 43200
	.word 256
	.dbsym e uip_arp_draddr _uip_arp_draddr A[4:2]ks
_uip_arp_netmask::
	.word 65535
	.word 255
	.dbsym e uip_arp_netmask _uip_arp_netmask A[4:2]ks
	.area text(rom, con, rel)
	.dbfile D:\hexok项目\AVRNET项目\AVRNET光盘\AVRuIP\uip.c
	.dbfunc e uip_init _uip_init fV
	.even
_uip_init::
	.dbline -1
	.dbline 179
; /**
;  * \addtogroup uip
;  * @{
;  */
; 
; /**
;  * \file
;  * The uIP TCP/IP stack code.
;  * \author Adam Dunkels <adam@dunkels.com>
;  */
; 
; /*
;  * Copyright (c) 2001-2003, Adam Dunkels.
;  * All rights reserved. 
;  *
;  * 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. The name of the author may not be used to endorse or promote
;  *    products derived from this software without specific prior
;  *    written permission.  
;  *
;  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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.  
;  *
;  * This file is part of the uIP TCP/IP stack.
;  *
;  * $Id: uip.c,v 1.1 2004/05/09 00:24:47 Louis Exp $
;  *
;  */
; 
; /*
; This is a small implementation of the IP and TCP protocols (as well as
; some basic ICMP stuff). The implementation couples the IP, TCP and the
; application layers very tightly. To keep the size of the compiled code
; down, this code also features heavy usage of the goto statement.
; 
; The principle is that we have a small buffer, called the uip_buf, in
; which the device driver puts an incoming packet. The TCP/IP stack
; parses the headers in the packet, and calls upon the application. If
; the remote host has sent data to the application, this data is present
; in the uip_buf and the application read the data from there. It is up
; to the application to put this data into a byte stream if needed. The
; application will not be fed with data that is out of sequence.
; 
; If the application whishes to send data to the peer, it should put its
; data into the uip_buf, 40 bytes from the start of the buffer. The
; TCP/IP stack will calculate the checksums, and fill in the necessary
; header fields and finally send the packet back to the peer.
; */
; 
; #include "uip.h"
; #include "uipopt.h"
; #include "uip_arch.h"
; 
; /*-----------------------------------------------------------------------------------*/
; /* Variable definitions. */
; 
; 
; /* The IP address of this host. If it is defined to be fixed (by setting UIP_FIXEDADDR to 1 in uipopt.h), the address is set here. Otherwise, the address */
; #if UIP_FIXEDADDR > 0
; const u16_t uip_hostaddr[2] =
;   {HTONS((UIP_IPADDR0 << 8) | UIP_IPADDR1),
;    HTONS((UIP_IPADDR2 << 8) | UIP_IPADDR3)};
; const u16_t uip_arp_draddr[2] =
;   {HTONS((UIP_DRIPADDR0 << 8) | UIP_DRIPADDR1),
;    HTONS((UIP_DRIPADDR2 << 8) | UIP_DRIPADDR3)};
; const u16_t uip_arp_netmask[2] =
;   {HTONS((UIP_NETMASK0 << 8) | UIP_NETMASK1),
;    HTONS((UIP_NETMASK2 << 8) | UIP_NETMASK3)};
; #else
; u16_t uip_hostaddr[2];       
; u16_t uip_arp_draddr[2], uip_arp_netmask[2];
; #endif /* UIP_FIXEDADDR */
; 
; u8_t uip_buf[UIP_BUFSIZE+2];   /* The packet buffer that contains
; 				incoming packets. */
; volatile u8_t *uip_appdata;  /* The uip_appdata pointer points to
; 				application data. */
; volatile u8_t *uip_sappdata;  /* The uip_appdata pointer points to the
; 				 application data which is to be sent. */
; #if UIP_URGDATA > 0
; volatile u8_t *uip_urgdata;  /* The uip_urgdata pointer points to
; 				urgent data (out-of-band data), if
; 				present. */
; volatile u8_t uip_urglen, uip_surglen;
; #endif /* UIP_URGDATA > 0 */
; 
; volatile u16_t uip_len, uip_slen;
;                              /* The uip_len is either 8 or 16 bits,
; 				depending on the maximum packet
; 				size. */
; 
; volatile u8_t uip_flags;     /* The uip_flags variable is used for
; 				communication between the TCP/IP stack
; 				and the application program. */
; struct uip_conn *uip_conn;   /* uip_conn always points to the current
; 				connection. */
; 
; struct uip_conn uip_conns[UIP_CONNS];
;                              /* The uip_conns array holds all TCP
; 				connections. */
; u16_t uip_listenports[UIP_LISTENPORTS];
;                              /* The uip_listenports list all currently
; 				listning ports. */
; #if UIP_UDP
; struct uip_udp_conn *uip_udp_conn;
; struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
; #endif /* UIP_UDP */
; 
; 
; static u16_t ipid;           /* Ths ipid variable is an increasing
; 				number that is used for the IP ID
; 				field. */
; 
; static u8_t iss[4];          /* The iss variable is used for the TCP
; 				initial sequence number. */
; 
; #if UIP_ACTIVE_OPEN
; static u16_t lastport;       /* Keeps track of the last port used for
; 				a new connection. */
; #endif /* UIP_ACTIVE_OPEN */
; 
; /* Temporary variables. */
; volatile u8_t uip_acc32[4];
; static u8_t c, opt;
; static u16_t tmp16;
; 
; /* Structures and definitions. */
; #define TCP_FIN 0x01
; #define TCP_SYN 0x02
; #define TCP_RST 0x04
; #define TCP_PSH 0x08
; #define TCP_ACK 0x10
; #define TCP_URG 0x20
; #define TCP_CTL 0x3f
; 
; #define ICMP_ECHO_REPLY 0
; #define ICMP_ECHO       8     
; 
; /* Macros. */
; #define BUF ((uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
; #define FBUF ((uip_tcpip_hdr *)&uip_reassbuf[0])
; #define ICMPBUF ((uip_icmpip_hdr *)&uip_buf[UIP_LLH_LEN])
; #define UDPBUF ((uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])
; 
; #if UIP_STATISTICS == 1
; struct uip_stats uip_stat;
; #define UIP_STAT(s) s
; #else
; #define UIP_STAT(s)
; #endif /* UIP_STATISTICS == 1 */
; 
; #if UIP_LOGGING == 1
; #include <stdio.h>
; void uip_log(char *msg);
; #define UIP_LOG(m) uip_log(m)
; #else
; #define UIP_LOG(m)
; #endif /* UIP_LOGGING == 1 */
; 
; /*-----------------------------------------------------------------------------------*/
; void
; uip_init(void)
; {
	.dbline 180
	clr R2
	sts _c,R2
	xjmp L11
L8:
	.dbline 180
	.dbline 181
	lds R2,_c
	ldi R24,2
	mul R24,R2
	movw R30,R0
	ldi R24,<_uip_listenports
	ldi R25,>_uip_listenports
	add R30,R24
	adc R31,R25
	clr R2
	clr R3
	std z+1,R3
	std z+0,R2
	.dbline 182
L9:
	.dbline 180
	lds R24,_c
	subi R24,255    ; addi 1
	sts _c,R24
L11:
	.dbline 180
;   for(c = 0; c < UIP_LISTENPORTS; ++c) {
	lds R24,_c
	cpi R24,10
	brlo L8
	.dbline 183
	clr R2
	sts _c,R2
	xjmp L15
L12:
	.dbline 183
	.dbline 184
	lds R2,_c
	ldi R24,35
	mul R24,R2
	movw R30,R0
	ldi R24,<_uip_conns+25
	ldi R25,>_uip_conns+25
	add R30,R24
	adc R31,R25
	clr R2
	std z+0,R2
	.dbline 185
L13:
	.dbline 183
	lds R24,_c
	subi R24,255    ; addi 1
	sts _c,R24
L15:
	.dbline 183
;     uip_listenports[c] = 0;
;   }
;   for(c = 0; c < UIP_CONNS; ++c) {
	lds R24,_c
	cpi R24,10
	brlo L12
	.dbline 187
;     uip_conns[c].tcpstateflags = CLOSED;
;   }
; #if UIP_ACTIVE_OPEN
;   lastport = 1024;
	ldi R24,1024
	ldi R25,4
	sts _lastport+1,R25
	sts _lastport,R24
	.dbline -2
L7:
	.dbline 0 ; func end
	ret
	.dbend
	.dbstruct 0 35 uip_conn
	.dbfield 0 ripaddr A[4:2]s
	.dbfield 4 lport s
	.dbfield 6 rport s
	.dbfield 8 rcv_nxt A[4:4]c
	.dbfield 12 snd_nxt A[4:4]c
	.dbfield 16 len s
	.dbfield 18 mss s
	.dbfield 20 initialmss s
	.dbfield 22 sa c
	.dbfield 23 sv c
	.dbfield 24 rto c
	.dbfield 25 tcpstateflags c
	.dbfield 26 timer c
	.dbfield 27 nrtx c
	.dbfield 28 appstate A[7:7]c
	.dbend
	.dbfunc e uip_connect _uip_connect fpS[uip_conn]
;          cconn -> R12,R13
;           conn -> R10,R11
;          rport -> R14,R15
;        ripaddr -> y+6
	.even
_uip_connect::
	xcall push_arg4
	xcall push_gset5x
	movw R14,R18
	.dbline -1
	.dbline 207
; #endif /* UIP_ACTIVE_OPEN */
; 
; #if UIP_UDP
;   for(c = 0; c < UIP_UDP_CONNS; ++c) {
;     uip_udp_conns[c].lport = 0;
;   }
; #endif /* UIP_UDP */
;   
; 
;   /* IPv4 initialization. */
; #if UIP_FIXEDADDR == 0
;   uip_hostaddr[0] = uip_hostaddr[1] = 0;
; #endif /* UIP_FIXEDADDR */
; 
; }
; /*-----------------------------------------------------------------------------------*/
; #if UIP_ACTIVE_OPEN
; struct uip_conn *
; uip_connect(u16_t *ripaddr, u16_t rport)
; {
L18:
	.dbline 212
;   register struct uip_conn *conn, *cconn;
;   
;   /* Find an unused local port. */
;  again:
;   ++lastport;
	lds R24,_lastport
	lds R25,_lastport+1
	adiw R24,1
	sts _lastport+1,R25
	sts _lastport,R24
	.dbline 214
; 
;   if(lastport >= 32000) {
	cpi R24,0
	ldi R30,125
	cpc R25,R30
	brlo L19
	.dbline 214
	.dbline 215
;     lastport = 4096;
	ldi R24,4096
	ldi R25,16
	sts _lastport+1,R25
	sts _lastport,R24
	.dbline 216
;   }
L19:
	.dbline 220
	clr R2
	sts _c,R2
	xjmp L24
L21:
	.dbline 220
; 
;   /* Check if this port is already in use, and if so try to find
;      another one. */
;   for(c = 0; c < UIP_CONNS; ++c) {
	.dbline 221
;     conn = &uip_conns[c];
	lds R2,_c
	ldi R24,35
	mul R24,R2
	movw R10,R0
	ldi R24,<_uip_conns
	ldi R25,>_uip_conns
	add R10,R24
	adc R11,R25
	.dbline 222
;     if(conn->tcpstateflags != CLOSED &&
	movw R30,R10
	ldd R2,z+25
	tst R2
	breq L25
	lds R16,_lastport
	lds R17,_lastport+1
	xcall _htons
	movw R30,R10
	ldd R2,z+4
	ldd R3,z+5
	cp R2,R16
	cpc R3,R17
	brne L25
	.dbline 223
;        conn->lport == htons(lastport)) {
	.dbline 224
;       goto again;
	xjmp L18
L25:
	.dbline 226
L22:
	.dbline 220
	lds R24,_c
	subi R24,255    ; addi 1
	sts _c,R24
L24:
	.dbline 220
	lds R24,_c
	cpi R24,10
	brlo L21
	.dbline 229
;     }
;   }
; 
; 
;   conn = 0;
	clr R10
	clr R11
	.dbline 230
	clr R2
	sts _c,R2
	xjmp L30
L27:
	.dbline 230
;   for(c = 0; c < UIP_CONNS; ++c) {
	.dbline 231
;     cconn = &uip_conns[c]; 
	lds R2,_c
	ldi R24,35
	mul R24,R2
	movw R12,R0
	ldi R24,<_uip_conns
	ldi R25,>_uip_conns
	add R12,R24
	adc R13,R25
	.dbline 232
;     if(cconn->tcpstateflags == CLOSED) {
	movw R30,R12
	ldd R2,z+25
	tst R2
	brne L31
	.dbline 232
	.dbline 233
;       conn = cconn;
	movw R10,R12
	.dbline 234
;       break;
	xjmp L29
L31:
	.dbline 236
;     }
;     if(cconn->tcpstateflags == TIME_WAIT) {
	movw R30,R12
	ldd R24,z+25
	cpi R24,7
	brne L33
	.dbline 236
	.dbline 237
;       if(conn == 0 ||
	tst R10
	brne X0
	tst R11
	breq L37
X0:
	lds R30,_uip_conn
	lds R31,_uip_conn+1
	ldd R2,z+26
	movw R30,R12
	ldd R3,z+26
	cp R2,R3
	brsh L35
L37:
	.dbline 238
; 	 cconn->timer > uip_conn->timer) {
	.dbline 239
; 	conn = cconn;
	movw R10,R12
	.dbline 240
;       }
L35:
	.dbline 241
;     }
L33:
	.dbline 242
L28:
	.dbline 230
	lds R24,_c
	subi R24,255    ; addi 1
	sts _c,R24
L30:
	.dbline 230
	lds R24,_c
	cpi R24,10
	brsh X2
	xjmp L27
X2:
L29:
	.dbline 244
;   }
; 
;   if(conn == 0) {
	tst R10
	brne L38
	tst R11
	brne L38
X1:
	.dbline 244
	.dbline 245
;     return 0;
	clr R16
	clr R17
	xjmp L17
L38:
	.dbline 248
;   }
;   
;   conn->tcpstateflags = SYN_SENT;
	ldi R24,2
	movw R30,R10
	std z+25,R24
	.dbline 250
; 
;   conn->snd_nxt[0] = iss[0];
	lds R2,_iss
	movw R30,R10
	std z+12,R2
	.dbline 251
;   conn->snd_nxt[1] = iss[1];
	lds R2,_iss+1
	movw R30,R10
	std z+13,R2
	.dbline 252
;   conn->snd_nxt[2] = iss[2];
	lds R2,_iss+2
	movw R30,R10
	std z+14,R2
	.dbline 253
;   conn->snd_nxt[3] = iss[3];
	lds R2,_iss+3
	movw R30,R10
	std z+15,R2
	.dbline 255
; 
;   conn->initialmss = conn->mss = UIP_TCP_MSS;
	ldi R24,1446
	ldi R25,5
	movw R30,R10
	std z+19,R25
	std z+18,R24
	movw R30,R10
	std z+21,R25
	std z+20,R24
	.dbline 257
;   
;   conn->len = 1;   /* TCP length of the SYN is one. */
	ldi R24,1
	ldi R25,0
	movw R30,R10
	std z+17,R25
	std z+16,R24
	.dbline 258
;   conn->nrtx = 0;
	clr R2
	movw R30,R10
	std z+27,R2
	.dbline 259
;   conn->timer = 1; /* Send the SYN next time around. */
	movw R30,R10
	std z+26,R24
	.dbline 260
;   conn->rto = UIP_RTO;
	ldi R24,3
	movw R30,R10
	std z+24,R24
	.dbline 261
;   conn->sa = 0;
	movw R30,R10
	std z+22,R2
	.dbline 262
;   conn->sv = 16;
	ldi R24,16
	movw R30,R10
	std z+23,R24
	.dbline 263
;   conn->lport = htons(lastport);
	lds R16,_lastport
	lds R17,_lastport+1
	xcall _htons
	movw R30,R10
	std z+5,R17
	std z+4,R16
	.dbline 264
;   conn->rport = rport;
	movw R30,R10
	std z+7,R15
	std z+6,R14
	.dbline 265
;   conn->ripaddr[0] = ripaddr[0];
	ldd R30,y+6
	ldd R31,y+7
	ldd R2,z+0
	ldd R3,z+1
	movw R30,R10
	std z+1,R3
	std z+0,R2
	.dbline 266
;   conn->ripaddr[1] = ripaddr[1];
	ldd R30,y+6
	ldd R31,y+7
	ldd R2,z+2
	ldd R3,z+3
	movw R30,R10
	std z+3,R3

⌨️ 快捷键说明

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