📄 rtl8019.s
字号:
.module rtl8019.c
.area text(rom, con, rel)
.dbfile D:\hexok项目\AVRNET项目\AVRNET光盘\AVRuIP\rtl8019.c
.dbfunc e rtl8019SetupPorts _rtl8019SetupPorts fV
.even
_rtl8019SetupPorts::
.dbline -1
.dbline 163
; #include "rtl8019.h"
;
; /*****************************************************************************
; * Module Name: Realtek 8019AS Driver
; *
; * Created By: Louis Beaudoin (www.embedded-creations.com)
; *
; * Original Release: September 21, 2002
; *
; * Module Description:
; * Provides functions to initialize the Realtek 8019AS, and send and retreive
; * packets
; *
; * November 16, 2003 - Louis Beaudoin
; * The rtl8019Write and Read functions/macros were changed to support
; * three methods of communcating with the NIC
; * Interfacing with the AVR ports changed from sbi/cbi/etc functions
; * to direct port names
; * Renamed functions to be more consistant with the two NIC drivers
; * Overrun function now retransmits if resend is set (thanks Krzysztof)
; *
; * November 15, 2002 - Louis Beaudoin
; * processRTL8019Interrupt() - bit mask mistake fixed
; *
; * November 8, 2003 - Louis Beaudoin
; * Changed delay library function calls
; *
; * September 30, 2002 - Louis Beaudoin
; * Receive functions modified to handle errors encountered when receiving a
; * fast data stream. Functions now manually retreive data instead of
; * using the send packet command. Interface improved by checking for
; * overruns and data in the buffer internally.
; * Corrected the overrun function - overrun flag was not reset after overrun
; * Added support for the Imagecraft Compiler
; * Added support to communicate with the NIC using general I/O ports
; *
; *****************************************************************************/
;
;
; /*****************************************************************************
; * rtl8019Write( RTL_ADDRESS, RTL_DATA )
; * Args: 1. unsigned char RTL_ADDRESS - register offset of RTL register
; * 2. unsigned char RTL_DATA - data to write to register
; * Created By: Louis Beaudoin
; * Date: September 21, 2002
; * Description: Writes byte to RTL8019 register.
; *
; * Notes - If using the External SRAM Interface, performs a write to
; * address MEMORY_MAPPED_RTL8019_OFFSET + (RTL_ADDRESS<<8)
; * The address is sent in the non-multiplxed upper address port so
; * no latch is required.
; *
; * If using general I/O ports, the data port is left in the input
; * state with pullups enabled
; *
; *****************************************************************************/
; #if NIC_CONNECTION == MEMORY_MAPPED_HIGHADDR
; #define rtl8019Write(RTL_ADDRESS,RTL_DATA) do{ *(volatile unsigned char *) \
; (MEMORY_MAPPED_RTL8019_OFFSET \
; + (((unsigned char)(RTL_ADDRESS)) << 8)) = \
; (unsigned char)(RTL_DATA); } while(0)
;
; #endif
;
; #if NIC_CONNECTION == MEMORY_MAPPED
; #define rtl8019Write(RTL_ADDRESS,RTL_DATA) do{ *(volatile unsigned char *) \
; (MEMORY_MAPPED_RTL8019_OFFSET \
; + (unsigned char)(RTL_ADDRESS)) = \
; (unsigned char)(RTL_DATA); } while(0)
;
; #endif
;
; #if NIC_CONNECTION == GENERAL_IO
;
; void rtl8019Write(unsigned char address, unsigned char data)
; {
; // assert the address, leaving the non-address pins intact
; address |= (RTL8019_ADDRESS_PORT & ~RTL8019_ADDRESS_MASK);
; RTL8019_ADDRESS_PORT = address;
;
; // set data bus as output and place data on bus
; RTL8019_DATA_DDR = 0xFF;
; RTL8019_DATA_PORT = data;
;
; // toggle write pin
; RTL8019_CONTROL_PORT &= ~_BV(RTL8019_CONTROL_WRITEPIN);
; nop();
; RTL8019_CONTROL_PORT |= _BV(RTL8019_CONTROL_WRITEPIN);
;
;
; // set data port back to input with pullups enabled
; RTL8019_DATA_DDR = 0x00;
; RTL8019_DATA_PORT = 0xFF;
; }
;
; #endif
;
; /*****************************************************************************
; * rtl8019Read(RTL_ADDRESS)
; * Args: unsigned char RTL_ADDRESS - register offset of RTL register
; * Created By: Louis Beaudoin
; * Date: September 21, 2002
; * Description: Reads byte from RTL8019 register
; *
; * Notes - If using the External SRAM Interface, performs a read from
; * address MEMORY_MAPPED_RTL8019_OFFSET + (RTL_ADDRESS<<8)
; * The address is sent in the non-multiplxed upper address port so
; * no latch is required.
; *
; * If using general I/O ports, the data port is assumed to already be
; * an input, and is left as an input port when done
; *
; *****************************************************************************/
; #if NIC_CONNECTION == MEMORY_MAPPED_HIGHADDR
; #define rtl8019Read(RTL_ADDRESS) (*(volatile unsigned char *) \
; (MEMORY_MAPPED_RTL8019_OFFSET \
; + (((unsigned char)(RTL_ADDRESS)) << 8)) )
; #endif
;
; #if NIC_CONNECTION == MEMORY_MAPPED
;
; #define rtl8019Read(RTL_ADDRESS) (*(volatile unsigned char *) \
; (MEMORY_MAPPED_RTL8019_OFFSET \
; + (unsigned char)(RTL_ADDRESS)) )
; #endif
;
; #if NIC_CONNECTION == GENERAL_IO
;
; unsigned char rtl8019Read(unsigned char address)
; {
; unsigned char byte;
;
; // assert the address, leaving the non-address pins intact
; address |= (RTL8019_ADDRESS_PORT & ~RTL8019_ADDRESS_MASK);
; RTL8019_ADDRESS_PORT = address;
;
; // assert read
; RTL8019_CONTROL_PORT &= ~_BV(RTL8019_CONTROL_READPIN);
; nop();
;
; // read in the data
; byte = RTL8019_DATA_PIN;
;
; // negate read
; RTL8019_CONTROL_PORT |= _BV(RTL8019_CONTROL_READPIN);
;
; return byte;
; }
;
; #endif
;
;
;
; /*****************************************************************************
; * rtl8019SetupPorts(void);
; *
; * Created By: Louis Beaudoin
; * Date: September 21, 2002
; * Description: Sets up the ports used for communication with the RTL8019 NIC
; * (data bus, address bus, read, write, and reset)
; *****************************************************************************/
; void rtl8019SetupPorts(void)
; {
.dbline 183
;
; #if NIC_CONNECTION == GENERAL_IO
;
; // make the address port output
; RTL8019_ADDRESS_DDR = RTL8019_ADDRESS_MASK;
;
; // make the data port input with pull-ups
; RTL8019_DATA_PORT = 0xFF;
;
; // make the control port read and write pins outputs and asserted
; RTL8019_CONTROL_DDR |= _BV(RTL8019_CONTROL_READPIN);
; RTL8019_CONTROL_DDR |= _BV(RTL8019_CONTROL_WRITEPIN);
;
; RTL8019_CONTROL_PORT |= _BV(RTL8019_CONTROL_READPIN);
; RTL8019_CONTROL_PORT |= _BV(RTL8019_CONTROL_WRITEPIN);
;
; #else
;
; // enable external SRAM interface - no wait states
; MCUCR |= _BV(SRE);
in R24,0x35
ori R24,128
out 0x35,R24
.dbline 188
;
; #endif
;
; // enable output pin for Resetting the RTL8019
; RTL8019_RESET_DDR |= _BV(RTL8019_RESET_PIN);
lds R24,100
ori R24,8
sts 100,R24
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e rtl8019BeginPacketSend _rtl8019BeginPacketSend fV
; sendPacketLength -> R10,R11
; packetLength -> R16,R17
.even
_rtl8019BeginPacketSend::
xcall push_gset4x
.dbline -1
.dbline 304
; }
;
;
;
; /*****************************************************************************
; * HARD_RESET_RTL8019()
; *
; * Created By: Louis Beaudoin
; * Date: September 21, 2002
; * Description: Simply toggles the pin that resets the NIC
; *****************************************************************************/
; #define HARD_RESET_RTL8019() do{ RTL8019_RESET_PORT |= _BV(RTL8019_RESET_PIN);\
; delay_ms(10); \
; RTL8019_RESET_PORT &= ~_BV(RTL8019_RESET_PIN);}\
; while(0)
;
;
;
; /*****************************************************************************
; * rtl8019Overrun(void);
; *
; * Created By: Louis Beaudoin
; * Date: September 21, 2002
; * Description: "Canned" receive buffer overrun function originally from
; * a National Semiconductor appnote
; * Notes: This function must be called before retreiving packets from
; * the NIC if there is a buffer overrun
; *****************************************************************************/
; void rtl8019Overrun(void);
;
;
;
;
; //******************************************************************
; //* REALTEK CONTROL REGISTER OFFSETS
; //* All offsets in Page 0 unless otherwise specified
; //* All functions accessing CR must leave CR in page 0 upon exit
; //******************************************************************
; #define CR 0x00
; #define PSTART 0x01
; #define PAR0 0x01 // Page 1
; #define CR9346 0x01 // Page 3
; #define PSTOP 0x02
; #define BNRY 0x03
; #define TSR 0x04
; #define TPSR 0x04
; #define TBCR0 0x05
; #define NCR 0x05
; #define TBCR1 0x06
; #define ISR 0x07
; #define CURR 0x07 // Page 1
; #define RSAR0 0x08
; #define CRDA0 0x08
; #define RSAR1 0x09
; #define CRDA1 0x09
; #define RBCR0 0x0A
; #define RBCR1 0x0B
; #define RSR 0x0C
; #define RCR 0x0C
; #define TCR 0x0D
; #define CNTR0 0x0D
; #define DCR 0x0E
; #define CNTR1 0x0E
; #define IMR 0x0F
; #define CNTR2 0x0F
; #define RDMAPORT 0x10
; #define RSTPORT 0x18
; #define CONFIG2 0x05 // page 3
; #define CONFIG3 0x06 // page 3
; #define RTL_EECR 0x01 // page 3
;
;
;
; /*****************************************************************************
; *
; * RTL ISR Register Bits
; *
; *****************************************************************************/
; #define ISR_RST 7
; #define ISR_OVW 4
; #define ISR_PRX 0
; #define ISR_RDC 6
; #define ISR_PTX 1
;
;
; /*****************************************************************************
; *
; * RTL Register Initialization Values
; *
; *****************************************************************************/
; // RCR : accept broadcast packets and packets destined to this MAC
; // drop short frames and receive errors
; #define RCR_INIT 0x04
;
; // TCR : default transmit operation - CRC is generated
; #define TCR_INIT 0x00
;
; // DCR : allows send packet to be used for packet retreival
; // FIFO threshold: 8-bits (works)
; // 8-bit transfer mode
; #define DCR_INIT 0x58
;
; // IMR : interrupt enabled for receive and overrun events
; #define IMR_INIT 0x11
;
; // buffer boundaries - transmit has 6 256-byte pages
; // receive has 26 256-byte pages
; // entire available packet buffer space is allocated
; #define TXSTART_INIT 0x40
; #define RXSTART_INIT 0x46
; #define RXSTOP_INIT 0x60
;
;
;
; void rtl8019BeginPacketSend(unsigned int packetLength)
; {
.dbline 306
; unsigned int sendPacketLength;
; sendPacketLength = (packetLength>=ETHERNET_MIN_PACKET_LENGTH) ?
cpi R16,60
ldi R30,0
cpc R17,R30
brlo L3
movw R12,R16
xjmp L4
L3:
ldi R24,60
ldi R25,0
movw R12,R24
L4:
movw R10,R12
L5:
.dbline 310
; packetLength : ETHERNET_MIN_PACKET_LENGTH ;
;
; //start the NIC
; rtl8019Write(CR,0x22);
.dbline 310
ldi R24,34
sts 49152,R24
.dbline 310
.dbline 310
L8:
.dbline 313
L9:
.dbline 313
;
; // still transmitting a packet - wait for it to finish
; while( rtl8019Read(CR) & 0x04 );
lds R2,49152
sbrc R2,2
rjmp L8
L11:
.dbline 316
.dbline 316
ldi R24,64
sts 50176,R24
.dbline 316
L12:
.dbline 316
;
; //load beginning page for transmit buffer
; rtl8019Write(TPSR,TXSTART_INIT);
L14:
.dbline 319
.dbline 319
clr R2
sts 51200,R2
.dbline 319
L15:
.dbline 319
;
; //set start address for remote DMA operation
; rtl8019Write(RSAR0,0x00);
L17:
.dbline 320
.dbline 320
ldi R24,64
sts 51456,R24
.dbline 320
L18:
.dbline 320
; rtl8019Write(RSAR1,0x40);
L20:
.dbline 323
.dbline 323
ldi R24,2
sts 50944,R24
.dbline 323
L21:
.dbline 323
;
; //clear the packet stored interrupt
; rtl8019Write(ISR,(1<<ISR_PTX));
L23:
.dbline 326
.dbline 326
sts 51712,R16
.dbline 326
L24:
.dbline 326
;
; //load data byte count for remote DMA
; rtl8019Write(RBCR0, (unsigned char)(packetLength));
L26:
.dbline 327
.dbline 327
movw R2,R16
mov R2,R3
clr R3
sts 51968,R2
.dbline 327
L27:
.dbline 327
; rtl8019Write(RBCR1, (unsigned char)(packetLength>>8));
L29:
.dbline 329
.dbline 329
sts 50432,R10
.dbline 329
L30:
.dbline 329
;
; rtl8019Write(TBCR0, (unsigned char)(sendPacketLength));
L32:
.dbline 330
.dbline 330
movw R2,R10
mov R2,R3
clr R3
sts 50688,R2
.dbline 330
L33:
.dbline 330
; rtl8019Write(TBCR1, (unsigned char)((sendPacketLength)>>8));
L35:
.dbline 333
.dbline 333
ldi R24,18
sts 49152,R24
.dbline 333
L36:
.dbline 333
;
; //do remote write operation
; rtl8019Write(CR,0x12);
.dbline -2
L2:
xcall pop_gset4x
.dbline 0 ; func end
ret
.dbsym r sendPacketLength 10 i
.dbsym r packetLength 16 i
.dbend
.dbfunc e rtl8019SendPacketData _rtl8019SendPacketData fV
; i -> R10,R11
; length -> R18,R19
; localBuffer -> R16,R17
.even
_rtl8019SendPacketData::
xcall push_gset3x
.dbline -1
.dbline 339
; }
;
;
;
; void rtl8019SendPacketData(unsigned char * localBuffer, unsigned int length)
; {
.dbline 342
; unsigned int i;
;
; for(i=0;i<length;i++)
clr R10
clr R11
xjmp L42
L39:
L43:
.dbline 343
.dbline 343
movw R30,R10
add R30,R16
adc R31,R17
ldd R2,z+0
sts 53248,R2
.dbline 343
L44:
.dbline 343
L40:
.dbline 342
movw R24,R10
adiw R24,1
movw R10,R24
L42:
.dbline 342
cp R10,R18
cpc R11,R19
brlo L39
.dbline -2
L38:
xcall pop_gset3x
.dbline 0 ; func end
ret
.dbsym r i 10 i
.dbsym r length 18 i
.dbsym r localBuffer 16 pc
.dbend
.dbfunc e rtl8019EndPacketSend _rtl8019EndPacketSend fV
.even
_rtl8019EndPacketSend::
.dbline -1
.dbline 349
; rtl8019Write(RDMAPORT, localBuffer[i]);
; }
;
;
;
; void rtl8019EndPacketSend(void)
; {
L47:
.dbline 351
.dbline 351
ldi R24,36
sts 49152,R24
.dbline 351
L48:
.dbline 351
; //send the contents of the transmit buffer onto the network
; rtl8019Write(CR,0x24);
L50:
.dbline 354
.dbline 354
ldi R24,64
sts 50944,R24
.dbline 354
L51:
.dbline 354
;
; // clear the remote DMA interrupt
; rtl8019Write(ISR, (1<<ISR_RDC));
.dbline -2
L46:
.dbline 0 ; func end
ret
.dbend
.dbfunc e rtl8019BeginPacketRetreive _rtl8019BeginPacketRetreive fi
; rxlen -> R10,R11
; pageheader -> y+0
; bnry -> R12
; i -> R10
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -