📄 common.s
字号:
ldi R25,0
std y+1,R25
std y+0,R24
movw R18,R20
ldi R16,<_Unit_ID
ldi R17,>_Unit_ID
xcall _EPROMRead_Data
.dbline -2
L51:
adiw R28,2
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r buf 20 pc
.dbend
.dbfunc e SRAM_Test _SRAM_Test fs
; j -> R16
; p -> R18,R19
; b -> R20
; i -> R22,R23
.even
_SRAM_Test::
xcall push_gset2
.dbline -1
.dbline 460
; }
;
; #endif
;
; // *********************************************************************************
; // test the 32K SRAM
;
; #ifdef CPU_ATmega128
;
; u16 SRAM_Test(void)
; {
.dbline 466
; u8 j;
; register u16 i;
; register u8 b;
; register u8 *p;
;
; for (j = 0; j < 8; j++) // do it 16 times
clr R16
xjmp L56
L53:
.dbline 467
; {
.dbline 468
; Reset_WD();
wdr
.dbline 471
;
; // fill the ram up with data
; p = &SRAM;
ldi R18,<_SRAM
ldi R19,>_SRAM
.dbline 472
; b = j;
mov R20,R16
.dbline 473
; SRAM_Enable;
cbi 0x15,7
.dbline 474
clr R22
clr R23
xjmp L60
L57:
.dbline 474
mov R2,R20
subi R20,1
movw R30,R18
st Z+,R2
movw R18,R30
L58:
.dbline 474
subi R22,255 ; offset = 1
sbci R23,255
L60:
.dbline 474
; for (i = 0; i < 32768; i++) *p++ = b--;
cpi R22,0
ldi R30,128
cpc R23,R30
brlo L57
.dbline 475
; SRAM_Disable;
sbi 0x15,7
.dbline 477
;
; Reset_WD();
wdr
.dbline 480
;
; // now see if the data is as should be
; p = &SRAM;
ldi R18,<_SRAM
ldi R19,>_SRAM
.dbline 481
; b = j;
mov R20,R16
.dbline 482
; SRAM_Enable;
cbi 0x15,7
.dbline 483
; for (i = 0; i < 32768; i++)
clr R22
clr R23
xjmp L64
L61:
.dbline 484
; {
.dbline 485
; if (*p++ != b--)
mov R2,R20
clr R3
subi R20,1
movw R30,R18
ld R4,Z+
movw R18,R30
clr R5
cp R4,R2
cpc R5,R3
breq L65
.dbline 486
; {
.dbline 487
; SRAM_Disable;
sbi 0x15,7
.dbline 488
; Reset_WD();
wdr
.dbline 489
; return i; // return the bad address
movw R16,R22
xjmp L52
L65:
.dbline 491
L62:
.dbline 483
subi R22,255 ; offset = 1
sbci R23,255
L64:
.dbline 483
cpi R22,0
ldi R30,128
cpc R23,R30
brlo L61
.dbline 492
sbi 0x15,7
.dbline 494
wdr
.dbline 495
L54:
.dbline 466
inc R16
L56:
.dbline 466
cpi R16,8
brsh X9
xjmp L53
X9:
.dbline 497
; }
; }
; SRAM_Disable;
;
; Reset_WD();
; }
;
; return 0xffff; // past it's test
ldi R16,65535
ldi R17,255
.dbline -2
L52:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r j 16 c
.dbsym r p 18 pc
.dbsym r b 20 c
.dbsym r i 22 s
.dbend
.dbfunc e htonl _htonl fl
; hostlong -> y+4
.even
_htonl::
xcall push_arg4
xcall push_gset2
.dbline -1
.dbline 505
; }
;
; #endif
;
; // *********************************************************************************
;
; u32 htonl(u32 hostlong)
; {
.dbline 507
; #ifdef CPU_ATmega128
; return ByteSwap4(hostlong);
ldi R20,0
ldi R21,255
ldi R22,0
ldi R23,0
movw R30,R28
ldd R2,z+4
ldd R3,z+5
ldd R4,z+6
ldd R5,z+7
and R2,R20
and R3,R21
and R4,R22
and R5,R23
ldi R24,8
ldi R25,0
st -y,R24
movw R16,R2
movw R18,R4
xcall lsl32
movw R2,R16
movw R4,R18
ldi R20,255
ldi R21,0
ldi R22,0
ldi R23,0
movw R30,R28
ldd R6,z+4
ldd R7,z+5
ldd R8,z+6
ldd R9,z+7
and R6,R20
and R7,R21
and R8,R22
and R9,R23
ldi R24,24
ldi R25,0
st -y,R24
movw R16,R6
movw R18,R8
xcall lsl32
movw R6,R16
movw R8,R18
or R6,R2
or R7,R3
or R8,R4
or R9,R5
ldi R20,0
ldi R21,0
ldi R22,255
ldi R23,0
movw R30,R28
ldd R2,z+4
ldd R3,z+5
ldd R4,z+6
ldd R5,z+7
and R2,R20
and R3,R21
and R4,R22
and R5,R23
ldi R24,8
ldi R25,0
st -y,R24
movw R16,R2
movw R18,R4
xcall lsr32
or R6,R16
or R7,R17
or R8,R18
or R9,R19
ldi R20,0
ldi R21,0
ldi R22,0
ldi R23,255
movw R30,R28
ldd R2,z+4
ldd R3,z+5
ldd R4,z+6
ldd R5,z+7
and R2,R20
and R3,R21
and R4,R22
and R5,R23
ldi R24,24
ldi R25,0
st -y,R24
movw R16,R2
movw R18,R4
xcall lsr32
or R6,R16
or R7,R17
or R8,R18
or R9,R19
movw R16,R6
movw R18,R8
.dbline -2
L67:
xcall pop_gset2
adiw R28,4
.dbline 0 ; func end
ret
.dbsym l hostlong 4 l
.dbend
.dbfunc e htons _htons fs
; hostshort -> R16,R17
.even
_htons::
.dbline -1
.dbline 514
; #else
; return hostlong;
; #endif
; }
;
; u16 htons(u16 hostshort)
; {
.dbline 516
; #ifdef CPU_ATmega128
; return ByteSwap2(hostshort);
movw R24,R16
andi R24,0
mov R24,R25
clr R25
andi R17,0
mov R17,R16
clr R16
or R16,R24
or R17,R25
.dbline -2
L68:
.dbline 0 ; func end
ret
.dbsym r hostshort 16 s
.dbend
.dbfunc e ntohl _ntohl fl
; netlong -> y+0
.even
_ntohl::
xcall push_arg4
.dbline -1
.dbline 523
; #else
; return hostshort;
; #endif
; }
;
; u32 ntohl(u32 netlong)
; {
.dbline 524
; return htonl(netlong);
movw R30,R28
ldd R16,z+0
ldd R17,z+1
ldd R18,z+2
ldd R19,z+3
xcall _htonl
.dbline -2
L69:
adiw R28,4
.dbline 0 ; func end
ret
.dbsym l netlong 0 l
.dbend
.dbfunc e ntohs _ntohs fs
; netshort -> R20,R21
.even
_ntohs::
xcall push_gset1
movw R20,R16
.dbline -1
.dbline 528
; }
;
; u16 ntohs(u16 netshort)
; {
.dbline 529
; return htons(netshort);
movw R16,R20
xcall _htons
.dbline -2
L70:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r netshort 20 s
.dbend
.dbfunc e IP_Str _IP_Str fI
; ip -> y+8
; IP -> y+14
; buf -> R20,R21
.even
_IP_Str::
st -y,r19
st -y,r18
xcall push_gset1
movw R20,R16
sbiw R28,12
.dbline -1
.dbline 536
; }
;
; // *********************************************************************************
; // convert an IP into a string
;
; int IP_Str(char *buf, u32 IP)
; {
.dbline 539
; T_IP_Addr ip;
;
; if (!buf) return 0;
cpi R20,0
cpc R20,R21
brne L72
X10:
.dbline 539
clr R16
clr R17
xjmp L71
L72:
.dbline 541
;
; ip.ip32 = IP;
movw R30,R28
ldd R2,z+14
ldd R3,z+15
ldd R4,z+16
ldd R5,z+17
movw R30,R28
std z+8,R2
std z+9,R3
std z+10,R4
std z+11,R5
.dbline 543
;
; return sprintf(buf, "%u.%u.%u.%u", ip.ip8[0], ip.ip8[1], ip.ip8[2], ip.ip8[3]);
ldd R2,y+11
clr R3
std y+7,R3
std y+6,R2
ldd R2,y+10
clr R3
std y+5,R3
std y+4,R2
ldd R2,y+9
clr R3
std y+3,R3
std y+2,R2
ldd R2,y+8
clr R3
std y+1,R3
std y+0,R2
ldi R18,<L74
ldi R19,>L74
movw R16,R20
xcall _sprintf
.dbline -2
L71:
adiw R28,12
xcall pop_gset1
adiw R28,2
.dbline 0 ; func end
ret
.dbsym l ip 8 S[TIPAddr]
.dbsym l IP 14 l
.dbsym r buf 20 pc
.dbend
.dbfunc e RingBufBytesFree _RingBufBytesFree fI
; Wr -> R20,R21
; Rd -> R18,R19
; BufSize -> R16,R17
.even
_RingBufBytesFree::
xcall push_gset1
ldd R20,y+2
ldd R21,y+3
.dbline -1
.dbline 551
; }
;
; // *********************************************************************************
; // Work out how many bytes are free in a RING BUFFER.
; // We must always leave 1 free byte for a ring buffer to work
;
; int RingBufBytesFree(int BufSize, int Rd, int Wr)
; {
.dbline 552
; if (BufSize <= 0) return 0; // doh!
clr R2
clr R3
cp R2,R16
cpc R3,R17
brlt L82
.dbline 552
clr R16
clr R17
xjmp L78
L81:
.dbline 553
sub R18,R16
sbc R19,R17
L82:
.dbline 553
; while (Rd >= BufSize) Rd -= BufSize; // rap around
cp R18,R16
cpc R19,R17
brge L81
xjmp L85
L84:
.dbline 554
sub R20,R16
sbc R21,R17
L85:
.dbline 554
; while (Wr >= BufSize) Wr -= BufSize; // " "
cp R20,R16
cpc R21,R17
brge L84
.dbline 555
; if (Wr == Rd) return BufSize - 1; // buffer is empty
cp R20,R18
cpc R21,R19
brne L90
.dbline 555
subi R16,1
sbci R17,0
xjmp L78
L89:
.dbline 556
sub R20,R16
sbc R21,R17
L90:
.dbline 556
; while (Wr > Rd) Wr -= BufSize; //
cp R18,R20
cpc R19,R21
brlt L89
.dbline 557
; return (Rd - Wr) - 1; // number of bytes free
movw R16,R18
sub R16,R20
sbc R17,R21
subi R16,1
sbci R17,0
.dbline -2
L78:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r Wr 20 I
.dbsym r Rd 18 I
.dbsym r BufSize 16 I
.dbend
.dbfunc e RingBufBytes _RingBufBytes fI
; Wr -> R20,R21
; Rd -> R18,R19
; BufSize -> R16,R17
.even
_RingBufBytes::
xcall push_gset1
ldd R20,y+2
ldd R21,y+3
.dbline -1
.dbline 564
; }
;
; // *********************************************************************************
; // Work out how many bytes are present in a RING BUFFER.
;
; int RingBufBytes(int BufSize, int Rd, int Wr)
; {
.dbline 565
; if (BufSize <= 0) return 0; // doh!
clr R2
clr R3
cp R2,R16
cpc R3,R17
brlt L96
.dbline 565
clr R16
clr R17
xjmp L92
L95:
.dbline 566
sub R18,R16
sbc R19,R17
L96:
.dbline 566
; while (Rd >= BufSize) Rd -= BufSize; // rap around
cp R18,R16
cpc R19,R17
brge L95
xjmp L99
L98:
.dbline 567
sub R20,R16
sbc R21,R17
L99:
.dbline 567
; while (Wr >= BufSize) Wr -= BufSize; // " "
cp R20,R16
cpc R21,R17
brge L98
.dbline 568
; if (Wr == Rd) return 0; // buffer is empty
cp R20,R18
cpc R21,R19
brne L104
.dbline 568
clr R16
clr R17
xjmp L92
L103:
.dbline 569
add R20,R16
adc R21,R17
L104:
.dbline 569
; while (Wr < Rd) Wr += BufSize; //
cp R20,R18
cpc R21,R19
brlt L103
.dbline 570
; return Wr - Rd; // number of bytes present
movw R16,R20
sub R16,R18
sbc R17,R19
.dbline -2
L92:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r Wr 20 I
.dbsym r Rd 18 I
.dbsym r BufSize 16 I
.dbend
.dbfunc e rstrlen _rstrlen fI
; len -> R20,R21
; s -> R16,R17
.even
_rstrlen::
xcall push_gset1
.dbline -1
.dbline 577
; }
;
; // *********************************************************************************
; // flash (rom) stuff
;
; int rstrlen(RomChar *s)
; { // return the length of a string in rom
.dbline 578
; int len = 0;
clr R20
clr R21
.dbline 579
; if (s)
cpi R16,0
cpc R16,R17
breq L107
X11:
.dbline 580
; {
.dbline 581
xjmp L112
L109:
.dbline 581
subi R20,255 ; offset = 1
sbci R21,255
L110:
.dbline 581
subi R16,255 ; offset = 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -