📄 udp.s
字号:
movw R18,R2
ldi R16,17
xcall _IP_StartPacket
.dbline 121
; //
; UDP_len = MainBufferWr_Tx; //
lds R2,_MainBufferWr_Tx
lds R3,_MainBufferWr_Tx+1
sts _UDP_len+1,R3
sts _UDP_len,R2
.dbline 123
; //
; UDP_Header = (T_UDP_Header*)(MainBuffer + MainBufferWr_Tx); // point to the UDP header
ldi R24,<_MainBuffer
ldi R25,>_MainBuffer
add R2,R24
adc R3,R25
sts _UDP_Header+1,R3
sts _UDP_Header,R2
.dbline 124
; memset(UDP_Header, 0, sizeof(T_UDP_Header)); //
ldi R24,8
ldi R25,0
std y+1,R25
std y+0,R24
clr R18
clr R19
movw R16,R2
xcall _memset
.dbline 125
; UDP_Header->SourcePort = htons(SourcePort); //
ldd R16,y+10
ldd R17,y+11
xcall _htons
lds R30,_UDP_Header
lds R31,_UDP_Header+1
std z+1,R17
std z+0,R16
.dbline 126
; UDP_Header->DestPort = htons(DestPort); //
ldd R16,y+12
ldd R17,y+13
xcall _htons
lds R30,_UDP_Header
lds R31,_UDP_Header+1
std z+3,R17
std z+2,R16
.dbline 127
; MainBufferWr_Tx += sizeof(T_UDP_Header); // update index
lds R24,_MainBufferWr_Tx
lds R25,_MainBufferWr_Tx+1
adiw R24,8
sts _MainBufferWr_Tx+1,R25
sts _MainBufferWr_Tx,R24
.dbline 129
; //
; return true; //
ldi R16,1
.dbline -2
L25:
adiw R28,2
xcall pop_gset2
adiw R28,4
.dbline 0 ; func end
ret
.dbsym l DestPort 12 s
.dbsym l SourcePort 10 s
.dbsym l IP 6 l
.dbend
.dbfunc e UDP_EndPacket _UDP_EndPacket fc
; w -> R22,R23
; w2 -> R20,R21
.even
_UDP_EndPacket::
xcall push_gset2
.dbline -1
.dbline 133
; }
;
; bool UDP_EndPacket(void)
; {
.dbline 136
; u16 w, w2; //
; //
; w2 = MainBufferWr_Tx; //
lds R20,_MainBufferWr_Tx
lds R21,_MainBufferWr_Tx+1
.dbline 138
; //
; UDP_len = MainBufferWr_Tx - UDP_len; //
lds R2,_UDP_len
lds R3,_UDP_len+1
movw R4,R20
sub R4,R2
sbc R5,R3
sts _UDP_len+1,R5
sts _UDP_len,R4
.dbline 140
; //
; IP_Header->TotalLength += UDP_len; // update the IP header
lds R24,_IP_Header
lds R25,_IP_Header+1
adiw R24,2
movw R30,R24
ldd R6,z+0
ldd R7,z+1
add R6,R4
adc R7,R5
std z+1,R7
std z+0,R6
.dbline 142
; //
; UDP_Header->Length = htons(UDP_len); //
lds R16,_UDP_len
lds R17,_UDP_len+1
xcall _htons
lds R30,_UDP_Header
lds R31,_UDP_Header+1
std z+5,R17
std z+4,R16
.dbline 144
; //
; w = IP_Checksum2((char*)UDP_Header, UDP_len); // update the UDP header checksum
lds R18,_UDP_len
lds R19,_UDP_len+1
movw R16,R30
xcall _IP_Checksum2
movw R22,R16
.dbline 145
; if (!w) w = 0xffff; //
cpi R16,0
cpc R16,R17
brne L33
X1:
.dbline 145
ldi R22,65535
ldi R23,255
L33:
.dbline 146
; UDP_Header->Checksum = htons(w); //
movw R16,R22
xcall _htons
lds R30,_UDP_Header
lds R31,_UDP_Header+1
std z+7,R17
std z+6,R16
.dbline 148
; //
; IP_EndPacket(); //
xcall _IP_EndPacket
.dbline 150
; //
; if (!PPP_SendPacket(false)) return false; // send it
clr R16
xcall _PPP_SendPacket
tst R16
brne L35
.dbline 150
clr R16
xjmp L32
L35:
.dbline 153
; //
; #ifdef Debug //
; IP_DisplayProtocol(true, (int)w2); //
movw R18,R20
ldi R16,1
xcall _IP_DisplayProtocol
.dbline 154
; IP_DisplayHeader(4, (int)w2); //
movw R18,R20
ldi R16,4
ldi R17,0
xcall _IP_DisplayHeader
.dbline 155
; UDP_DisplayHeader(4 + sizeof(T_IP_Header), (int)w2); //
movw R18,R20
ldi R16,24
ldi R17,0
xcall _UDP_DisplayHeader
.dbline 158
; #endif //
; //
; return true; //
ldi R16,1
.dbline -2
L32:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r w 22 s
.dbsym r w2 20 s
.dbend
.dbfunc e UDP_In _UDP_In fV
; w -> R22,R23
; len -> R20,R21
.even
_UDP_In::
xcall push_gset2
.dbline -1
.dbline 165
; }
;
; //*********************************************************************************************************************
; // this is called when we have received a UDP packet
;
; void UDP_In(void)
; {
.dbline 168
; u16 len, w;
;
; len = MainBufferWr_Rx - MainBufferRd_Rx; // length of data left
lds R2,_MainBufferRd_Rx
lds R3,_MainBufferRd_Rx+1
lds R20,_MainBufferWr_Rx
lds R21,_MainBufferWr_Rx+1
sub R20,R2
sbc R21,R3
.dbline 173
;
; // *******************
; // UDP header
;
; UDP_Header = (T_UDP_Header*)(MainBuffer + MainBufferRd_Rx); // point to the UDP header
ldi R24,<_MainBuffer
ldi R25,>_MainBuffer
add R2,R24
adc R3,R25
sts _UDP_Header+1,R3
sts _UDP_Header,R2
.dbline 175
; //
; if ((!UDP_Header->Checksum) || (IP_Checksum2((char*)UDP_Header, len))) //
movw R30,R2
ldd R2,z+6
ldd R3,z+7
tst R2
brne X2
tst R3
breq L40
X2:
movw R18,R20
lds R16,_UDP_Header
lds R17,_UDP_Header+1
xcall _IP_Checksum2
cpi R16,0
cpc R16,R17
breq L38
X3:
L40:
.dbline 176
; { // invalid checksum
.dbline 178
; #ifdef Debug
; SendDebugRStr(udp_str7); //
ldi R16,<_udp_str7
ldi R17,>_udp_str7
xcall _SendDebugRStr
.dbline 180
; #endif
; return; //
xjmp L37
L38:
.dbline 183
; }
; //
; w = ntohs(UDP_Header->Length); //
lds R30,_UDP_Header
lds R31,_UDP_Header+1
ldd R16,z+4
ldd R17,z+5
xcall _ntohs
movw R22,R16
.dbline 184
; if (w < sizeof(T_UDP_Header)) return; // hmmmmm
cpi R16,8
ldi R30,0
cpc R17,R30
brsh L41
.dbline 184
xjmp L37
L41:
.dbline 185
; if (w > len) return; // hmmmmm
cp R20,R22
cpc R21,R23
brsh L43
.dbline 185
xjmp L37
L43:
.dbline 188
lds R18,_MainBufferWr_Rx
lds R19,_MainBufferWr_Rx+1
lds R16,_MainBufferRd_Rx
lds R17,_MainBufferRd_Rx+1
xcall _UDP_DisplayHeader
.dbline 191
lds R24,_MainBufferRd_Rx
lds R25,_MainBufferRd_Rx+1
adiw R24,8
sts _MainBufferRd_Rx+1,R25
sts _MainBufferRd_Rx,R24
.dbline 192
lds R20,_MainBufferWr_Rx
lds R21,_MainBufferWr_Rx+1
sub R20,R24
sbc R21,R25
.dbline 196
xcall _IP_FireWalled
tst R16
breq L45
.dbline 197
.dbline 199
ldi R16,<_udp_str6
ldi R17,>_udp_str6
xcall _SendDebugRStr
.dbline 201
L45:
.dbline -2
L37:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r w 22 s
.dbsym r len 20 s
.dbend
.dbfunc e UDP_10ms_Timer _UDP_10ms_Timer fV
.even
_UDP_10ms_Timer::
.dbline -1
.dbline 221
; //
; #ifdef Debug
; UDP_DisplayHeader((int)MainBufferRd_Rx, (int)MainBufferWr_Rx); //
; #endif
;
; MainBufferRd_Rx += sizeof(T_UDP_Header); // update index
; len = MainBufferWr_Rx - MainBufferRd_Rx; // length of data left
; //
; // *******************
;
; if (IP_FireWalled())
; {
; #ifdef Debug
; SendDebugRStr(udp_str6);
; #endif
; return; // firewalled
; }
;
; // *******************
; // data
;
; #ifdef IncludeNTP
; if (ntohs(UDP_Header->DestPort) == 123)
; { // most likely an NTP reply then
; if (len >= sizeof(T_NTP)) NTP_DecodeSNTP(IP_Header->SourceIP.ip32, (T_NTP*)(MainBuffer + MainBufferRd_Rx));
; return;
; }
; #endif
;
; // *******************
; }
; // **************************************************************************
; // this is called every 10ms from the IP module
;
; void UDP_10ms_Timer(void)
; {
.dbline -2
L47:
.dbline 0 ; func end
ret
.dbend
.area bss(ram, con, rel)
.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\udp.c
_UDP_len::
.blkb 2
.dbsym e UDP_len _UDP_len s
.area data(ram, con, rel)
.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\udp.c
L22:
.blkb 4
.area idata
.byte 37,'u,10,0
.area data(ram, con, rel)
.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\udp.c
L17:
.blkb 5
.area idata
.byte 37,48,52,'x,0
.area data(ram, con, rel)
.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\udp.c
L4:
.blkb 3
.area idata
.byte 37,'u,0
.area data(ram, con, rel)
.dbfile C:\AVR\AT-Modem__PPP__UDP__IC\udp.c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -