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

📄 uipavr.lst

📁 uIP是免费的TCP/IP协议栈,我们将它移植到我们的AVR以太网开发板中
💻 LST
📖 第 1 页 / 共 5 页
字号:
(0267) #define ISR_RST	7
(0268) #define ISR_OVW 4
(0269) #define ISR_PRX 0
(0270) #define ISR_RDC 6
(0271) #define ISR_PTX 1
(0272) 
(0273) 
(0274) /*****************************************************************************
(0275) *
(0276) *  RTL Register Initialization Values
(0277) *
(0278) *****************************************************************************/
(0279) // RCR : accept broadcast packets and packets destined to this MAC
(0280) //         drop short frames and receive errors
(0281) #define RCR_INIT		0x04
(0282) 
(0283) // TCR : default transmit operation - CRC is generated 
(0284) #define TCR_INIT		0x00
(0285) 
(0286) // DCR : allows send packet to be used for packet retreival
(0287) //         FIFO threshold: 8-bits (works)
(0288) //         8-bit transfer mode
(0289) #define DCR_INIT		0x58
(0290) 
(0291) // IMR : interrupt enabled for receive and overrun events
(0292) #define IMR_INIT		0x11
(0293) 
(0294) // buffer boundaries - transmit has 6 256-byte pages
(0295) //   receive has 26 256-byte pages
(0296) //   entire available packet buffer space is allocated
(0297) #define TXSTART_INIT   	0x40
(0298) #define RXSTART_INIT   	0x46
(0299) #define RXSTOP_INIT    	0x60
(0300) 
(0301) 
(0302) 
(0303) void rtl8019BeginPacketSend(unsigned int packetLength)
(0304) {
(0305) 	unsigned int sendPacketLength;
(0306) 	sendPacketLength = (packetLength>=ETHERNET_MIN_PACKET_LENGTH) ?
    1554 330C      CPI	R16,0x3C
    1555 E0E0      LDI	R30,0
    1556 071E      CPC	R17,R30
    1557 F010      BCS	0x155A
    1558 0168      MOVW	R12,R16
    1559 C003      RJMP	0x155D
    155A E38C      LDI	R24,0x3C
    155B E090      LDI	R25,0
    155C 016C      MOVW	R12,R24
    155D 0156      MOVW	R10,R12
(0307) 	                 packetLength : ETHERNET_MIN_PACKET_LENGTH ;
(0308) 	
(0309) 	//start the NIC
(0310) 	rtl8019Write(CR,0x22);
    155E E282      LDI	R24,0x22
    155F 9380C000  STS	0xC000,R24
(0311) 	
(0312) 	// still transmitting a packet - wait for it to finish
(0313) 	while( rtl8019Read(CR) & 0x04 );
    1561 9020C000  LDS	R2,0xC000
    1563 FC22      SBRC	R2,2
    1564 CFFC      RJMP	0x1561
(0314) 
(0315) 	//load beginning page for transmit buffer
(0316) 	rtl8019Write(TPSR,TXSTART_INIT);
    1565 E480      LDI	R24,0x40
    1566 9380C400  STS	0xC400,R24
(0317) 	
(0318) 	//set start address for remote DMA operation
(0319) 	rtl8019Write(RSAR0,0x00);
    1568 2422      CLR	R2
    1569 9220C800  STS	0xC800,R2
(0320) 	rtl8019Write(RSAR1,0x40);
    156B E480      LDI	R24,0x40
    156C 9380C900  STS	0xC900,R24
(0321) 	
(0322) 	//clear the packet stored interrupt
(0323) 	rtl8019Write(ISR,(1<<ISR_PTX));
    156E E082      LDI	R24,2
    156F 9380C700  STS	0xC700,R24
(0324) 
(0325) 	//load data byte count for remote DMA
(0326) 	rtl8019Write(RBCR0, (unsigned char)(packetLength));
    1571 9300CA00  STS	0xCA00,R16
(0327) 	rtl8019Write(RBCR1, (unsigned char)(packetLength>>8));
    1573 0118      MOVW	R2,R16
    1574 2C23      MOV	R2,R3
    1575 2433      CLR	R3
    1576 9220CB00  STS	0xCB00,R2
(0328) 
(0329) 	rtl8019Write(TBCR0, (unsigned char)(sendPacketLength));
    1578 92A0C500  STS	0xC500,R10
(0330) 	rtl8019Write(TBCR1, (unsigned char)((sendPacketLength)>>8));
    157A 0115      MOVW	R2,R10
    157B 2C23      MOV	R2,R3
    157C 2433      CLR	R3
    157D 9220C600  STS	0xC600,R2
(0331) 	
(0332) 	//do remote write operation
(0333) 	rtl8019Write(CR,0x12);
    157F E182      LDI	R24,0x12
    1580 9380C000  STS	0xC000,R24
    1582 940E2E66  CALL	pop_gset4x
    1584 9508      RET
_rtl8019SendPacketData:
  i                    --> R10
  length               --> R18
  localBuffer          --> R16
    1585 940E2E6C  CALL	push_gset3x
(0334) }
(0335) 
(0336) 
(0337) 
(0338) void rtl8019SendPacketData(unsigned char * localBuffer, unsigned int length)
(0339) {
(0340) 	unsigned int i;
(0341) 	
(0342) 	for(i=0;i<length;i++)
    1587 24AA      CLR	R10
    1588 24BB      CLR	R11
    1589 C009      RJMP	0x1593
(0343) 		rtl8019Write(RDMAPORT, localBuffer[i]);
    158A 01F5      MOVW	R30,R10
    158B 0FE0      ADD	R30,R16
    158C 1FF1      ADC	R31,R17
    158D 8020      LDD	R2,Z+0
    158E 9220D000  STS	0xD000,R2
    1590 01C5      MOVW	R24,R10
    1591 9601      ADIW	R24,1
    1592 015C      MOVW	R10,R24
    1593 16A2      CP	R10,R18
    1594 06B3      CPC	R11,R19
    1595 F3A0      BCS	0x158A
    1596 940E2E5A  CALL	pop_gset3x
    1598 9508      RET
(0344) }
(0345) 
(0346) 
(0347) 
(0348) void rtl8019EndPacketSend(void)
(0349) {
(0350) 	//send the contents of the transmit buffer onto the network
(0351) 	rtl8019Write(CR,0x24);
_rtl8019EndPacketSend:
    1599 E284      LDI	R24,0x24
    159A 9380C000  STS	0xC000,R24
(0352) 	
(0353) 	// clear the remote DMA interrupt
(0354) 	rtl8019Write(ISR, (1<<ISR_RDC));
    159C E480      LDI	R24,0x40
    159D 9380C700  STS	0xC700,R24
    159F 9508      RET
_rtl8019BeginPacketRetreive:
  rxlen                --> R10
  pageheader           --> Y+0
  bnry                 --> R12
  i                    --> R10
    15A0 940E2E6F  CALL	push_gset4x
    15A2 9724      SBIW	R28,4
(0355) }
(0356) 
(0357) 
(0358) 
(0359) 
(0360) // pointers to locations in the RTL8019 receive buffer
(0361) static unsigned char nextPage;
(0362) static unsigned int currentRetreiveAddress;
(0363) 
(0364) // location of items in the RTL8019's page header
(0365) #define  enetpacketstatus     0x00
(0366) #define  nextblock_ptr        0x01
(0367) #define	 enetpacketLenL		  0x02
(0368) #define	 enetpacketLenH		  0x03
(0369) 
(0370) unsigned int rtl8019BeginPacketRetreive(void)
(0371) {
(0372) 	unsigned char i;
(0373) 	unsigned char bnry;
(0374) 	
(0375) 	unsigned char pageheader[4];
(0376) 	unsigned int rxlen;
(0377) 	
(0378) 	// check for and handle an overflow
(0379) 	rtl8019ProcessInterrupt();
    15A3 D19D      RCALL	_rtl8019ProcessInterrupt
(0380) 	
(0381) 	// read CURR from page 1
(0382) 	rtl8019Write(CR,0x62);
    15A4 E682      LDI	R24,0x62
    15A5 9380C000  STS	0xC000,R24
(0383) 	i = rtl8019Read(CURR);
    15A7 90A0C700  LDS	R10,0xC700
(0384) 	
(0385) 	// return to page 0
(0386) 	rtl8019Write(CR,0x22);
    15A9 E282      LDI	R24,0x22
    15AA 9380C000  STS	0xC000,R24
(0387) 	
(0388) 	// read the boundary register - pointing to the beginning of the packet
(0389) 	bnry = rtl8019Read(BNRY) ;
    15AC 90C0C300  LDS	R12,0xC300
(0390) 	
(0391) 	// return if there is no packet in the buffer
(0392) 	if( bnry == i )
    15AE 14CA      CP	R12,R10
    15AF F419      BNE	0x15B3
(0393) 		return 0;
    15B0 2700      CLR	R16
    15B1 2711      CLR	R17
    15B2 C05E      RJMP	0x1611
(0394) 	
(0395) 
(0396) 	// clear the packet received interrupt flag
(0397) 	rtl8019Write(ISR, (1<<ISR_PRX));
    15B3 E081      LDI	R24,1
    15B4 9380C700  STS	0xC700,R24
(0398) 	
(0399) 	// the boundary pointer is invalid, reset the contents of the buffer and exit
(0400) 	if( (bnry >= RXSTOP_INIT) || (bnry < RXSTART_INIT) )
    15B6 2D8C      MOV	R24,R12
    15B7 3680      CPI	R24,0x60
    15B8 F410      BCC	0x15BB
    15B9 3486      CPI	R24,0x46
    15BA F478      BCC	0x15CA
(0401) 	{
(0402) 		rtl8019Write(BNRY, RXSTART_INIT);
    15BB E486      LDI	R24,0x46
    15BC 9380C300  STS	0xC300,R24
(0403) 		rtl8019Write(CR, 0x62);
    15BE E682      LDI	R24,0x62
    15BF 9380C000  STS	0xC000,R24
(0404) 		rtl8019Write(CURR, RXSTART_INIT);
    15C1 E486      LDI	R24,0x46
    15C2 9380C700  STS	0xC700,R24
(0405) 		rtl8019Write(CR, 0x22);
    15C4 E282      LDI	R24,0x22
    15C5 9380C000  STS	0xC000,R24
(0406) 		
(0407) 		return 0;
    15C7 2700      CLR	R16
    15C8 2711      CLR	R17
    15C9 C047      RJMP	0x1611
(0408) 	}
(0409) 
(0410) 	// initiate DMA to transfer the RTL8019 packet header
(0411)     rtl8019Write(RBCR0, 4);
    15CA E084      LDI	R24,4
    15CB 9380CA00  STS	0xCA00,R24
(0412)     rtl8019Write(RBCR1, 0);
    15CD 2422      CLR	R2
    15CE 9220CB00  STS	0xCB00,R2
(0413)     rtl8019Write(RSAR0, 0);
    15D0 2422      CLR	R2
    15D1 9220C800  STS	0xC800,R2
(0414)     rtl8019Write(RSAR1, bnry);
    15D3 92C0C900  STS	0xC900,R12
(0415)     rtl8019Write(CR, 0x0A);
    15D5 E08A      LDI	R24,0xA
    15D6 9380C000  STS	0xC000,R24
(0416) 	for(i=0;i<4;i++)
    15D8 24AA      CLR	R10
    15D9 C009      RJMP	0x15E3
(0417) 		pageheader[i] = rtl8019Read(RDMAPORT);
    15DA 01CE      MOVW	R24,R28
    15DB 2DEA      MOV	R30,R10
    15DC 27FF      CLR	R31
    15DD 0FE8      ADD	R30,R24
    15DE 1FF9      ADC	R31,R25
    15DF 9020D000  LDS	R2,0xD000
    15E1 8220      STD	Z+0,R2
    15E2 94A3      INC	R10
    15E3 2D8A      MOV	R24,R10
    15E4 3084      CPI	R24,4
    15E5 F3A0      BCS	0x15DA
(0418) 	
(0419) 	// end the DMA operation
(0420)     rtl8019Write(CR, 0x22);
    15E6 E282      LDI	R24,0x22
    15E7 9380C000  STS	0xC000,R24
(0421)     for(i = 0; i <= 20; i++)
    15E9 24AA      CLR	R10
    15EA C006      RJMP	0x15F1
(0422)         if(rtl8019Read(ISR) & 1<<6)
    15EB 9020C700  LDS	R2,0xC700
    15ED FE26      SBRS	R2,6
    15EE C001      RJMP	0x15F0
(0423)             break;
    15EF C004      RJMP	0x15F4
    15F0 94A3      INC	R10
    15F1 E184      LDI	R24,0x14
    15F2 158A      CP	R24,R10
    15F3 F7B8      BCC	0x15EB
(0424)     rtl8019Write(ISR, 1<<6);
    15F4 E480      LDI	R24,0x40
    15F5 9380C700  STS	0xC700,R24
(0425) 
(0426) 	
(0427) 	rxlen = (pageheader[enetpacketLenH]<<8) + pageheader[enetpacketLenL];
    15F7 802A      LDD	R2,Y+2
    15F8 803B      LDD	R3,Y+3
    15F9 2CB3      MOV	R11,R3
    15FA 2CA2      MOV	R10,R2
(0428) 	nextPage = pageheader[nextblock_ptr] ;
    15FB 8029      LDD	R2,Y+1
    15FC 92202A0A  STS	nextPage,R2
(0429) 	
(0430) 	currentRetreiveAddress = (bnry<<8) + 4;
    15FE E084      LDI	R24,4
    15FF 2C3C      MOV	R3,R12
    1600 2E28      MOV	R2,R24
    1601 92302A09  STS	currentRetreiveAddress+1,R3
    1603 92202A08  STS	currentRetreiveAddress,R2
(0431) 	
(0432) 	// if the nextPage pointer is invalid, the packet is not ready yet - exit
(0433) 	if( (nextPage >= RXSTOP_INIT) || (nextPage < RXSTART_INIT) )
    1605 91802A0A  LDS	R24,nextPage
    1607 3680      CPI	R24,0x60
    1608 F410      BCC	0x160B
    1609 3486      CPI	R24,0x46
    160A F418      BCC	0x160E
(0434) 		return 0;
    160B 2700      CLR	R16
    160C 2711      CLR	R17
    160D C003      RJMP	0x1611
(0435)     
(0436)     return rxlen-4;
    160E 0185      MOVW	R16,R10
    160F 5004      SUBI	R16,4
    1610 4010      SBCI	R17,0
    1611 9624      ADIW	R28,4
    1612 940E2E66  CALL	pop_gset4x
    1614 9508      RET
_rtl8019RetreivePacketData:
  i                    --> R10
  length               --> R18
  localBuffer          --> R16
    1615 940E2E6C  CALL	push_gset3x
(0437) }
(0438) 
(0439) 
(0440) void rtl8019RetreivePacketData(unsigned char * localBuffer, unsigned int length)
(0441) {
(0442) 	unsigned int i;
(0443) 	
(0444) 	// initiate DMA to transfer the data
(0445)     rtl8019Write(RBCR0, (unsigned char)length);
    1617 9320CA00  STS	0xCA00,R18
(0446)     rtl8019Write(RBCR1, (unsigned char)(length>>8));
    1619 0119      MOVW	R2,R18
    161A 2C23      MOV	R2,R3
    161B 2433      CLR	R3
    161C 9220CB00  STS	0xCB00,R2
(0447)     rtl8019Write(RSAR0, (unsigned char)currentRetreiveAddress);
    161E 90202A08  LDS	R2,currentRetreiveAddress
    1620 90302A09  LDS	R3,currentRetreiveAddress+1
    1622 9220C800  STS	0xC800,R2
(0448)     rtl8019Write(RSAR1, (unsigned char)(currentRetreiveAddress>>8));
    1624 90202A08  LDS	R2,currentRetreiveAddress
    1626 90302A09  LDS	R3,currentRetreiveAddress+1
    1628 2C23      MOV	R2,R3
    1629 2433      CLR	R3
    162A 9220C900  STS	0xC900,R2
(0449)     rtl8019Write(CR, 0x0A);
    162C E08A      LDI	R24

⌨️ 快捷键说明

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