'------------------------------------------------------------------------------------ ' WebTiger / Ethernut 1.3F - Atmega128 and RTL8019AS - ARP - UDP - PING - HTML '------------------------------------------------------------------------------------ ' ' january 2006 - Ben Zijlstra - Netherlands - https://benshobbycorner.nl/bzijlstra ' Lockbits: ' Lockbit 54 : 11 ' Lockbit 32 : 11 ' Lockbit 10 : 11 ' Fusebits: ' Fusebit 7 : 0 ' Fusebit 6 : 0 ' Fusebit 98 : 11 ' Fusebit DCBA : 1111 ' Fusebits High ' Fusebits E : 1 ' Fusebits F : 0 ' Fusebits G : 0 ' Fusebits H : 0 ' Fusebits I : 0 ' Fusebits KL : 01 ' Fusebits M : 1 ' Fusebits Extended ' Fusebits P : 1 ' Fusebits Q : 1 $regfile "m128def.dat" $crystal = 14745600 $baud = 57600 $waitstate 'XRAM wait state $xa 'External Access enabled $default Xram 'memory map: 'The ATMEGA128 works in normal-mode (fuse-settings) 'Data Memory '$0000-$001F 32 registers '$0020-$005F 64 I/O reg. '$0060-$00FF 160 Ext I/O reg. '$0100-$10FF Internal SRAM '$1100-$7FFF External SRAM '$8300-$831F RTL8019as $hwstack = 128 $swstack = 128 $framesize = 128 Dim Regaddr As Byte Dim Regdata As Byte Dim Byte_read As Byte Dim Whulp0 As Word Dim Bhulp0 As Byte Dim Hulp1 As Byte Dim Mymac(6) As Byte 'NIC_CR page 0/1/2/3 (ps1=x, ps0=x) x = depending on page ' Const Nic_cr = &H00 ' Const Nic_cr_stp = &B0000_0001 'stop command - Power up default Const Nic_cr_sta = &B0000_0010 'start command Const Nic_cr_txp = &B0000_0100 'transmit a packet Const Nic_cr_rd0 = &B0000_1000 'remote read Const Nic_cr_rd1 = &B0001_0000 'remote write Const Nic_cr_rd2 = &B0010_0000 'abort/complete remote DMA Const Nic_cr_ps0 = &B0100_0000 'register page 0 Const Nic_cr_ps1 = &B1000_0000 'register page 1 Const Nic_rdmaport = &H10 'all pages Const Nic_rstport = &H18 'all pages 'NIC_PSTART page 0 (ps1=0, ps0=0) ' Const Nic_pstart = &H01 ' 'NIC_PSTOP page 0 (ps1=0, ps0=0) ' Const Nic_pstop = &H02 ' 'NIC_BNRY page 0 (ps1=0, ps0=0) ' Const Nic_bnry = &H03 ' 'NIC_TPSR page 0 (ps1=0, ps0=0) ' Const Nic_tpsr = &H04 ' 'NIC_TBCR0 page 0 (ps1=0, ps0=0) ' Const Nic_tbcr0 = &H05 ' 'NIC_TBCR1 page 0 (ps1=0, ps0=0) ' Const Nic_tbcr1 = &H06 ' 'NIC_ISR page 0 (ps1=0, ps0=0) ' Const Nic_isr = &H07 ' Const Nic_rdc = &B0100_0000 'NIC_RSAR0 page 0 (ps1=0, ps0=0) ' Const Nic_rsar0 = &H08 ' 'NIC_RSAR1 page 0 (ps1=0, ps0=0) ' Const Nic_rsar1 = &H09 ' 'NIC_rbcr0 page 0 (ps1=0, ps0=0) ' Const Nic_rbcr0 = &H0A ' 'NIC_rbcr0 page 0 (ps1=0, ps0=0) ' Const Nic_rbcr1 = &H0B ' 'NIC_rcr page 0 (ps1=0, ps0=0) receive configuration register ' Const Nic_rcr = &H0C ' 'NIC_tcr page 0 (ps1=0, ps0=0) transmit configuration register ' Const Nic_tcr = &H0D ' 'NIC_DCR page 0 (ps1=0, ps0=0) ' Const Nic_dcr = &H0E ' 'NIC_IMR page 0 (ps1=0, ps0=0) interrupt mask register ' Const Nic_imr = &H0F ' 'NIC_CURR page 1 (ps1=0, ps0=1) ' Const Nic_curr = &H07 ' 'NIC_9346CR page 3 (ps1=1, ps0=1) ' Const Nic_9346cr = &H01 ' Const Nic_9346cr_eem1 = &B1000_0000 Const Nic_9346cr_eem0 = &B0100_0000 Const Nic_config2_bselb = &B0010_0000 'NIC_CONFIG2 page 3 (ps1=1, ps0=1) ' Const Nic_config2 = &H05 'NIC_CONFIG3 page 3 (ps1=1, ps0=1) ' Const Nic_config3 = &H06 Const Msg_initfail = "Init failed" Const Dcrval = &H58 Const Txstart = &H40 Const Rxstart = &H46 Const Rxstop = &H60 Const Imrval = &H11 Const Tcrval = &H00 Declare Sub Write_rtl8019as(byval Regaddr As Byte , Byval Regdata As Byte) Declare Sub Read_rtl8019as(byval Regaddr As Byte) Declare Sub Init_rtl8019as Config Int5 = Falling Const Debug = 1 #if Debug = 1 Print "Hello world" #endif Mymac(1) = 00 Mymac(2) = 10 Mymac(3) = 20 Mymac(4) = 30 Mymac(5) = 40 Mymac(6) = 50 Call Init_rtl8019as ' Sit and wait for an Interrupt from the RTL8019as Enable Interrupts Enable Int5 On Int5 Rtl8019as_interrupt 'start the NIC Bhulp0 = Nic_cr_rd2 Or Nic_cr_sta Call Write_rtl8019as(nic_cr , Bhulp0) Do Loop End ' Routine to Write to NIC Control register ' Sub Write_rtl8019as(regaddr , Regdata) Whulp0 = Regaddr + &H8300 Out Whulp0 , Regdata End Sub ' Routine to read from NIC Control register ' Sub Read_rtl8019as(regaddr) Whulp0 = Regaddr + &H8300 Byte_read = Inp(whulp0) End Sub ' Routine to initialize the RTL8019AS ethernetchip ' Sub Init_rtl8019as #if Debug = 1 Print "Sub Init_RTL8019as" #endif Call Read_rtl8019as(nic_rstport) Call Write_rtl8019as(nic_rstport , Byte_read) Waitms 10 'check for good soft reset Call Write_rtl8019as(nic_imr , 0) 'interrupt mask register Call Write_rtl8019as(nic_isr , &HFF) Call Read_rtl8019as(nic_isr) 'page 0 RST If Byte_read.7 = 0 Then Print Msg_initfail End If 'switch to page 3 Bhulp0 = Nic_cr_rd2 Or Nic_cr_stp Bhulp0 = Bhulp0 Or Nic_cr_ps0 Bhulp0 = Bhulp0 Or Nic_cr_ps1 Call Write_rtl8019as(nic_cr , Bhulp0) Bhulp0 = Nic_9346cr_eem0 Or Nic_9346cr_eem1 Call Write_rtl8019as(nic_9346cr , Bhulp0) Call Write_rtl8019as(nic_config3 , 0) Call Write_rtl8019as(nic_config2 , Nic_config2_bselb) Call Write_rtl8019as(nic_9346cr , 0) Waitms 255 Bhulp0 = Nic_cr_rd2 Or Nic_cr_stp Call Write_rtl8019as(nic_cr , Bhulp0) Waitms 2 Call Write_rtl8019as(nic_dcr , Dcrval) '58 Call Write_rtl8019as(nic_rbcr0 , &H00) Call Write_rtl8019as(nic_rbcr1 , &H00) '0000_0100 packets with broadcast destination address are accepted Call Write_rtl8019as(nic_rcr , &H04) 'receive configuration register Call Write_rtl8019as(nic_tpsr , Txstart) '&H40 '0000_0010 internal loopback Call Write_rtl8019as(nic_tcr , &H02) 'transmit configuration register Call Write_rtl8019as(nic_pstart , Rxstart) '&H46 Call Write_rtl8019as(nic_bnry , Rxstart) '&H46 Call Write_rtl8019as(nic_pstop , Rxstop) Call Write_rtl8019as(nic_isr , &HFF) Call Write_rtl8019as(nic_cr , &H61) Waitms 2 Call Write_rtl8019as(nic_curr , Rxstart) '&H46 For Hulp1 = 1 To 6 Call Write_rtl8019as(hulp1 , Mymac(hulp1)) Next Hulp1 Call Write_rtl8019as(nic_cr , &H21) Call Write_rtl8019as(nic_dcr , Dcrval) '58 Call Write_rtl8019as(nic_cr , &H22) Call Write_rtl8019as(nic_isr , &HFF) Call Write_rtl8019as(nic_imr , Imrval) 'interrupt mask register / 0001_0001 Call Write_rtl8019as(nic_tcr , Tcrval) 'transmit configuration register / 0000_0000 Bhulp0 = Nic_cr_sta Or Nic_cr_rd2 Call Write_rtl8019as(nic_cr , Bhulp0) End Sub 'Routine to handle an interrupt from the RTL8019as ' Rtl8019as_interrupt: Print "Interrupt from RTL8019as" 'reset the interrupt bits Call Write_rtl8019as(nic_isr , &HFF) 'start the NIC again Bhulp0 = Nic_cr_rd2 Or Nic_cr_sta Call Write_rtl8019as(nic_cr , Bhulp0) Return