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

📄 main.s

📁 uIP是免费的TCP/IP协议栈,我们将它移植到我们的AVR以太网开发板中
💻 S
字号:
	.module main.c
	.area text(rom, con, rel)
	.dbfile D:\hexok项目\AVRNET项目\AVRNET光盘\AVRuIP\main.c
	.dbfunc e initTimer _initTimer fV
	.even
_initTimer::
	.dbline -1
	.dbline 57
; /*****************************************************************************
; *  Module Name:       uIP-AVR Port - main control loop shell
; *  
; *  Created By:        Louis Beaudoin (www.embedded-creations.com)
; *
; *  Original Release:  September 21, 2002 
; *
; *  Module Description:  
; *  This main control loop shell provides everything required for a basic uIP
; *  application using the RTL8019AS NIC
; *
; *   
; *  November 16, 2003
; *    Changed NIC interface from RTL8019 specific to general NIC calls
; *    Calls the uip_arp_timer function every 10 seconds
; *    
; *  September 30, 2002
; *    Added support for Imagecraft Compiler
; *****************************************************************************/
; 
; 
; #include "uip.h"
; #include "nic.h"
; #include "uip_arp.h"
; #include "httpd.h"
; 
; #include "fs.h"
; #include "fsdata.h"
; #include "cgi.h"
; #include "filelist.h"
; #include "compiler.h"
; 
; 
; #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
; 
; 
; 
; /*****************************************************************************
; *  Periodic Timout Functions and variables
; *
; *  The periodic timeout rate can be changed depeding on your application
; *  Modify these functions and variables based on your AVR device and clock
; *    rate
; *  The current setup will interrupt every 256 timer ticks when the timer
; *    counter overflows.  timerCounter must count until 0.5 seconds have
; *    alapsed
; *****************************************************************************/
; 
; #define TIMER_PRESCALE    1024
; #define F_CPU             12000000
; 
; #define TIMERCOUNTER_PERIODIC_TIMEOUT (F_CPU / TIMER_PRESCALE / 2 / 256)
; 
; static unsigned char timerCounter;
; 
; void initTimer(void)
; {
	.dbline 58
;   outp( 7, TCCR0 ) ;  // timer0 prescale 1/1024 (7)
	ldi R24,7
	out 0x33,R24
	.dbline 61
; 
;   // interrupt on overflow
;   sbi( TIMSK, TOIE0 ) ;
	in R24,0x37
	ori R24,1
	out 0x37,R24
	.dbline 63
; 	
;   timerCounter = 0;
	clr R2
	sts _timerCounter,R2
	.dbline -2
L7:
	.dbline 0 ; func end
	ret
	.dbend
	.area vector(rom, abs)
	.org 64
	jmp _SIG_OVERFLOW0
	.area text(rom, con, rel)
	.dbfile D:\hexok项目\AVRNET项目\AVRNET光盘\AVRuIP\main.c
	.dbfunc e SIG_OVERFLOW0 _SIG_OVERFLOW0 fV
	.even
_SIG_OVERFLOW0::
	st -y,R24
	st -y,R25
	in R24,0x3f
	st -y,R24
	.dbline -1
	.dbline 73
; }
; 
; 
; 
; #ifdef __IMAGECRAFT__
; #pragma interrupt_handler SIG_OVERFLOW0:iv_TIMER0_OVF
; #endif
; 
; SIGNAL(SIG_OVERFLOW0)
; {
	.dbline 74
;   timerCounter++;
	lds R24,_timerCounter
	subi R24,255    ; addi 1
	sts _timerCounter,R24
	.dbline -2
L8:
	ld R24,y+
	out 0x3f,R24
	ld R25,y+
	ld R24,y+
	.dbline 0 ; func end
	reti
	.dbend
	.dbfunc e main _main fI
;       arptimer -> R10
;              i -> R12
	.even
_main::
	.dbline -1
	.dbline 85
; }
; 
; 
; 
; /*****************************************************************************
; *  Main Control Loop
; *
; *  
; *****************************************************************************/
; int main(void)
; {
	.dbline 87
;   unsigned char i;
;   unsigned char arptimer=0;
	clr R10
	.dbline 88
;   PORTD = 0x02;
	ldi R24,2
	out 0x12,R24
	.dbline 89
;   DDRD  = 0x30;
	ldi R24,48
	out 0x11,R24
	.dbline 91
;   // init NIC device driver
;   nic_init();
	xcall _nic_init
	.dbline 94
; 
;   // init uIP
;   uip_init();
	xcall _uip_init
	.dbline 97
; 
;   // init http
;   httpd_init();
	xcall _httpd_init
	.dbline 100
; 
;   // init ARP cache
;   uip_arp_init();
	xcall _uip_arp_init
	.dbline 103
; 
;   // init periodic timer
;   initTimer();
	xcall _initTimer
	.dbline 105
;   
;   sei();
	sei
	xjmp L11
L10:
	.dbline 108
;   
;   while(1)
;   {
	.dbline 110
;     // look for a packet
;     uip_len = nic_poll();
	xcall _nic_poll
	sts _uip_len+1,R17
	sts _uip_len,R16
	.dbline 111
;     if(uip_len == 0)
	lds R2,_uip_len
	lds R3,_uip_len+1
	tst R2
	breq X5
	xjmp L13
X5:
	tst R3
	breq X6
	xjmp L13
X6:
X0:
	.dbline 112
;     {
	.dbline 114
;       // if timed out, call periodic function for each connection
;       if(timerCounter > TIMERCOUNTER_PERIODIC_TIMEOUT)
	ldi R24,22
	ldi R25,0
	ldi R26,0
	ldi R27,0
	lds R2,_timerCounter
	clr R3
	clr R4
	clr R5
	cp R24,R2
	cpc R25,R3
	cpc R26,R4
	cpc R27,R5
	brlt X7
	xjmp L14
X7:
	.dbline 115
;       {
	.dbline 116
;         timerCounter = 0;
	clr R2
	sts _timerCounter,R2
	.dbline 118
;         
;         for(i = 0; i < UIP_CONNS; i++)
	clr R12
	xjmp L20
L17:
	.dbline 119
;         {
L21:
	.dbline 120
	.dbline 120
	ldi R24,35
	mul R24,R12
	movw R2,R0
	ldi R24,<_uip_conns
	ldi R25,>_uip_conns
	add R2,R24
	adc R3,R25
	sts _uip_conn+1,R3
	sts _uip_conn,R2
	.dbline 120
	ldi R16,2
	xcall _uip_process
	.dbline 120
L22:
	.dbline 120
;           uip_periodic(i);
	.dbline 123
; 		
;           // transmit a packet, if one is ready
;           if(uip_len > 0)
	lds R2,_uip_len
	lds R3,_uip_len+1
	tst R2
	brne X1
	tst R3
	breq L24
X1:
	.dbline 124
;           {
	.dbline 125
;             uip_arp_out();
	xcall _uip_arp_out
	.dbline 126
;             nic_send();
	xcall _nic_send
	.dbline 127
;           }
L24:
	.dbline 128
L18:
	.dbline 118
	inc R12
L20:
	.dbline 118
	mov R24,R12
	cpi R24,10
	brlo L17
	.dbline 131
;         }
; 
;         /* Call the ARP timer function every 10 seconds. */
;         if(++arptimer == 20)
	mov R24,R10
	subi R24,255    ; addi 1
	mov R10,R24
	cpi R24,20
	brne L14
	.dbline 132
;         {	
	.dbline 133
;           uip_arp_timer();
	xcall _uip_arp_timer
	.dbline 134
;           arptimer = 0;
	clr R10
	.dbline 135
;         }
	.dbline 136
;       }
	.dbline 137
;     }
	xjmp L14
L13:
	.dbline 139
;     else  // packet received
;     {
	.dbline 141
;       // process an IP packet
;       if(BUF->type == htons(UIP_ETHTYPE_IP))
	ldi R16,2048
	ldi R17,8
	xcall _htons
	lds R2,_uip_buf+12
	lds R3,_uip_buf+12+1
	cp R2,R16
	cpc R3,R17
	brne L28
	.dbline 142
;       {
	.dbline 145
;         // add the source to the ARP cache
;         // also correctly set the ethernet packet length before processing
;         uip_arp_ipin();
	xcall _uip_arp_ipin
	.dbline 146
;         uip_input();
	ldi R16,1
	xcall _uip_process
	.dbline 149
; 
;         // transmit a packet, if one is ready
;         if(uip_len > 0)
	lds R2,_uip_len
	lds R3,_uip_len+1
	tst R2
	brne X2
	tst R3
	breq L29
X2:
	.dbline 150
;         {
	.dbline 151
;           uip_arp_out();
	xcall _uip_arp_out
	.dbline 152
;           nic_send();
	xcall _nic_send
	.dbline 153
;         }
	.dbline 154
;       }
	xjmp L29
L28:
	.dbline 156
;       // process an ARP packet
;       else if(BUF->type == htons(UIP_ETHTYPE_ARP))
	ldi R16,2054
	ldi R17,8
	xcall _htons
	lds R2,_uip_buf+12
	lds R3,_uip_buf+12+1
	cp R2,R16
	cpc R3,R17
	brne L33
	.dbline 157
;       {
	.dbline 158
;         uip_arp_arpin();
	xcall _uip_arp_arpin
	.dbline 161
; 
;         // transmit a packet, if one is ready
;         if(uip_len > 0)
	lds R2,_uip_len
	lds R3,_uip_len+1
	tst R2
	brne X3
	tst R3
	breq L36
X3:
	.dbline 162
;           nic_send();
	xcall _nic_send
L36:
	.dbline 163
;       }
L33:
L29:
	.dbline 164
;     }
L14:
	.dbline 165
L11:
	.dbline 107
	xjmp L10
X4:
	.dbline 167
;   }
; 
;   return 1;
	ldi R16,1
	ldi R17,0
	.dbline -2
L9:
	.dbline 0 ; func end
	ret
	.dbsym r arptimer 10 c
	.dbsym r i 12 c
	.dbend
	.area bss(ram, con, rel)
	.dbfile D:\hexok项目\AVRNET项目\AVRNET光盘\AVRuIP\main.c
_timerCounter:
	.blkb 1
	.dbsym s timerCounter _timerCounter c

⌨️ 快捷键说明

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