📄 ethernet.asm
字号:
*
*hit651 voice platform software
*=================== ethernet.asm ======================
*2004.2.1 hit651
*
.mmregs
.include macro.inc
.include netcard.inc
.include ref.inc
.include union.inc
.def send_packet,check_new_packet
.text
*
************************ send packet ***********************
*ST #xxxx,send_packet_len ----------->packet length of to transmit
send_packet:
PSHM AL
PSHM AH
PSHM AG
PSHM AR1
PSHM AR2
PAGE 0
;--------------------------------------------------------
LD *(send_packet_len),A
SUB #60,A
NOP
NOP
XC 2,ALT
ST #60,*(send_packet_len)
*netcard DMA transmit
STM send_packet_x,AR1
BITF *(txbuf_select),#0x80
BC s_p_b,TC ;TC=1 goto s_p_b
ST #0x40,*AR1
MOV send_packet_len,a_len,1
ORM #0x80,*(txbuf_select)
B s_p_setdma
s_p_b: ST #0x46,*AR1
MOV send_packet_len,b_len,1
ORM 0x40,*(txbuf_select)
s_p_setdma:
PORTW *AR1,NET_REG_RSAR1 ;remote DMA start address high
DELAY 20
ST #0,*AR1
PORTW *AR1,NET_REG_RSAR0 ;remote DMA start address low
DELAY 20
LD *(send_packet_len),A
AND #0xffff,A
STL A,-8,*AR1
AND #0xff,A
PORTW *AR1,NET_REG_RBCR1 ;remote DMA byte count register
DELAY 20
STL A,*AR1
NOP
NOP
PORTW *AR1,NET_REG_RBCR0
DELAY 20
ST #0x12,*AR1
PORTW *AR1,NET_REG_CR ;write DMA start 8019as
DELAY 20
STM txbuf.ethernet.destnodeid,AR1
LD *(send_packet_len),-1,A
SUB #1,A
NOP
NOP
STLM A,AR2
s_p_writedma:
PORTW *AR1+,NET_PORT_DMA
DELAY 10 ;****debug speed*******
BANZ s_p_writedma,*AR2-
B s_p_exit
s_p_err:
ORM #0x02,*(txbuf_select)
s_p_exit:
POPM AR2
POPM AR1
POPM AG
POPM AH
POPM AL
RET
*
******************* check new packet *********************
*call in interrupt
check_new_packet:
DELAY 50
PSHD *(cr_reg)
PSHD *(read_reg)
PSHD *(write_reg)
STM rx_bnry,AR1
PAGE 1
PORTR NET_REG_CURR,*(rx_curr)
ANDM #0xff,*(rx_curr)
DELAY 20
PAGE 0
WRITE #0x01,NET_REG_ISR;****************
DELAY 80
PORTR NET_REG_BNRY,*AR1
ANDM #0xff,*AR1
DELAY 20
ADDM #0x01,*AR1
PORTR NET_REG_BNRY,*(rx_next)
ANDM #0xff,*(rx_next)
DELAY 20
LDU *AR1,A
SUB #0x7f,A
NOP
NOP
XC 2,AGT ;A>0
ST #0x4c,*AR1
LDU *AR1,A
SUB *(rx_curr),A
NOP
NOP
BC c_p_exit,AEQ ;A=0 :curr=bnry+1 have not packet
*have one or more packet
PORTW *AR1,NET_REG_RSAR1
DELAY 20
WRITE 0x00,NET_REG_RSAR0
WRITE 0x00,NET_REG_RBCR1
WRITE 18,NET_REG_RBCR0 ;18 byte ethernet head
WRITE 0x0a,NET_REG_CR
DELAY 20
STM rxbuf,AR1
STM #(9-1),AR2 ;9 word
c_p_3:
PORTR NET_PORT_DMA,*AR1+
DELAY 20
BANZ c_p_3,*AR2-
WRITE 0x22,NET_REG_CR ;complete DMA page 0
LD *(rxbuf.ethernet.len),A
SUB #4,A
STL A,*(rxbuf.ethernet.len)
PAGE 0
**************************
LDU *(rxbuf.ethernet.status),A
STL A,-8,*(rx_curr)
AND #0x01,A
BC c_p_err,AEQ
LD *(rxbuf.ethernet.status),-8,A
SUB #0x7f, A
NOP
NOP
BC c_p_err,AGT
LD *(rxbuf.ethernet.status),-8,A
SUB #0x4c,A
NOP
NOP
BC c_p_err,ALT
LD *(rxbuf.ethernet.len),-8,A
SUB #0x06,A
NOP
NOP
BC c_p_err,AGT
STM (rxbuf.ethernet.protocal),AR1
CMPM *AR1,#0x0008
BC c_p_ip_arp,TC
CMPM *AR1,#0x0608
BC c_p_no_ip_arp,NTC
c_p_ip_arp:
PORTW *(rx_bnry),NET_REG_RSAR1
WRITE #0x04,NET_REG_RSAR0
LD *(rxbuf.ethernet.len),-1,A
SUB #1,A
STLM A,AR2 ;loop #(n-1)
LD *(rxbuf.ethernet.len),A
STL A,-8,*(write_reg)
STM rxbuf.ethernet.destnodeid,AR1
PORTW *(write_reg),NET_REG_RBCR1
ANDM #0x0ff,*(rxbuf.ethernet.len)
PORTW *(rxbuf.ethernet.len),NET_REG_RBCR0
WRITE #0x0a,NET_REG_CR
DELAY 20
c_p_loop:
PORTR NET_PORT_DMA,*AR1+
DELAY 10 ;****debug speed****
BANZ c_p_loop,*AR2-
WRITE #0x22,NET_REG_CR
ST #reveice_process,*(task) ;*******!!!!********
c_p_no_ip_arp:
LDU *(rx_curr),A
SUB #1,A
STL A,*(rx_bnry)
SUB #0x4c,A
NOP
NOP
XC 2,ALT
ST #0x7f,*(rx_bnry)
PORTW *(rx_bnry),NET_REG_BNRY
DELAY 20
WRITE #0x01,NET_REG_ISR
B c_p_exit
c_p_err:
STM rx_bnry,AR1
PAGE 1
PORTR NET_REG_CURR,*AR1
DELAY 20
PAGE 0
LD *AR1,A
SUB #1,A
STL A,*AR1
SUB #0x4c,A
NOP
NOP
XC 2,ALT ;bnry<0x4c
ST #0x7f,*AR1
PORTW *AR1,NET_REG_BNRY
WRITE #0x01,NET_REG_ISR
B c_p_exit
c_p_exit:
DELAY 50
POPD *(write_reg)
POPD *(read_reg)
POPD *(cr_reg)
RET
.end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -