📄 ppp.s
字号:
ldi R17,>_PPPStageStr4
xcall _SendDebugRStr
xjmp L140
L150:
.dbline 374
; case PPPS_LogOn : return SendDebugRStr(PPPStageStr5);
ldi R16,<_PPPStageStr5
ldi R17,>_PPPStageStr5
xcall _SendDebugRStr
xjmp L140
L151:
.dbline 375
; case PPPS_IP_Addr : return SendDebugRStr(PPPStageStr6);
ldi R16,<_PPPStageStr6
ldi R17,>_PPPStageStr6
xcall _SendDebugRStr
xjmp L140
L152:
.dbline 376
; case PPPS_IP : return SendDebugRStr(PPPStageStr7);
ldi R16,<_PPPStageStr7
ldi R17,>_PPPStageStr7
xcall _SendDebugRStr
xjmp L140
L153:
.dbline 377
; case PPPS_Disc : return SendDebugRStr(PPPStageStr8);
ldi R16,<_PPPStageStr8
ldi R17,>_PPPStageStr8
xcall _SendDebugRStr
xjmp L140
L143:
.dbline 378
; default : return SendDebugRStr(PPPStageStr9);
ldi R16,<_PPPStageStr9
ldi R17,>_PPPStageStr9
xcall _SendDebugRStr
.dbline -2
L140:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbend
.dbfunc e PPP_Stage _PPP_Stage fV
; Stage -> R20
.even
_PPP_Stage::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 387
; }
; }
;
; #endif
;
; //****************************************************************************
;
; void PPP_Stage(T_PPPStage Stage)
; {
.dbline 388
; if (PPP.Stage == Stage) return; // no change
lds R2,_PPP+9
cp R2,R20
brne L155
.dbline 388
xjmp L154
L155:
.dbline 391
; //
; #ifdef Debug
; PPP_DisplayStage(); // display current stage
xcall _PPP_DisplayStage
.dbline 394
; #endif
; //
; PPP.Stage = Stage; // set the new PPP stage/state
sts _PPP+9,R20
.dbline 395
; PPP.Retries = 0; // reset the send retry counter
clr R2
sts _PPP+8,R2
.dbline 396
; u16_Put(&PPP.SendTick, PPP_Timeout); // send next packet asap
ldi R18,3000
ldi R19,11
ldi R16,<_PPP+6
ldi R17,>_PPP+6
xcall _u16_Put
.dbline 397
; PPP.NAK_REJ_Count = 0; // reset the rejection counter
clr R2
sts _PPP+56,R2
.dbline 400
;
; #ifdef Debug
; PPP_DisplayStage();
xcall _PPP_DisplayStage
.dbline -2
L154:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r Stage 20 c
.dbend
.dbfunc e PPP_SendByte _PPP_SendByte fc
; c -> R10
.even
_PPP_SendByte::
xcall push_gset3
mov R10,R16
.dbline -1
.dbline 414
; #endif
; }
;
; //****************************************************************************
; // send the PPP buffer to the server.
; //
; // This is where we add the byte stuffing and also calculate the fcs on the fly.
; //
; // Byte stuffing is used to make sure the start/stop flag (a single byte) never
; // appears in the packet data - so ensuring we can 100% reliably detect the packet boundries from
; // one packet to the next.
;
; bool PPP_SendByte(u8 c)
; {
.dbline 415
; PPP.TxBytes++; // update byte counter
ldi R20,1
ldi R21,0
ldi R22,0
ldi R23,0
lds R4,_PPP+121+2
lds R5,_PPP+121+2+1
lds R2,_PPP+121
lds R3,_PPP+121+1
add R2,R20
adc R3,R21
adc R4,R22
adc R5,R23
sts _PPP+121+1,R3
sts _PPP+121,R2
sts _PPP+121+2+1,R5
sts _PPP+121+2,R4
.dbline 416
; return SendModemByte(c); // send byte
mov R16,R10
xcall _SendModemByte
.dbline -2
L162:
xcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r c 10 c
.dbend
.dbfunc e PPP_TxByte _PPP_TxByte fc
; MustByteStuff -> R12
; c -> R10
.even
_PPP_TxByte::
xcall push_gset4
mov R12,R18
mov R10,R16
.dbline -1
.dbline 421
; }
;
;
; bool PPP_TxByte(u8 c, bool MustByteStuff)
; { // send byte with byte stuffing
.dbline 422
; if (!WatchdogCounter) WatchdogCounter++; //
lds R2,_WatchdogCounter
tst R2
brne L165
.dbline 422
lds R24,_WatchdogCounter
subi R24,255 ; addi 1
sts _WatchdogCounter,R24
L165:
.dbline 424
; //
; if (c == PPP_Flag) goto Stuff; // stuff the byte
mov R24,R10
cpi R24,126
brne L167
.dbline 424
xjmp L169
L167:
.dbline 425
; if (c == PPP_EscapeFlag) goto Stuff; // stuff the byte
mov R24,R10
cpi R24,125
brne L170
.dbline 425
xjmp L169
L170:
.dbline 426
; if (c > 31) goto NoStuff; // no need to stuff the byte
ldi R24,31
cp R24,R10
brsh L172
.dbline 426
xjmp L174
L172:
.dbline 427
; if (MustByteStuff) goto Stuff; // must use byte stuffing - for now
tst R12
breq L175
.dbline 427
xjmp L169
L175:
.dbline 428
; if (!(PPP.TxACCM & (1 << c))) goto NoStuff; // no need to stuff the byte
mov R18,R10
clr R19
ldi R16,1
ldi R17,0
xcall lsl16
movw R2,R16
clr R4
sbrc R3,7
com R4
clr R5
sbrc R4,7
com R5
lds R8,_PPP+37+2
lds R9,_PPP+37+2+1
lds R6,_PPP+37
lds R7,_PPP+37+1
and R6,R2
and R7,R3
and R8,R4
and R9,R5
ldi R20,0
ldi R21,0
ldi R22,0
ldi R23,0
cp R6,R20
cpc R7,R21
cpc R8,R22
cpc R9,R23
brne L177
.dbline 428
xjmp L174
L177:
L169:
.dbline 430
; Stuff:
; if (!PPP_SendByte(PPP_EscapeFlag)) return false; // send byte
ldi R16,125
xcall _PPP_SendByte
tst R16
brne L180
.dbline 430
clr R16
xjmp L164
L180:
.dbline 431
; c ^= PPP_Stuff; // modify the byte
ldi R24,32
eor R10,R24
L174:
.dbline 433
; NoStuff:
; return PPP_SendByte(c); // send byte
mov R16,R10
xcall _PPP_SendByte
.dbline -2
L164:
xcall pop_gset4
.dbline 0 ; func end
ret
.dbsym r MustByteStuff 12 c
.dbsym r c 10 c
.dbend
.dbfunc e PPP_SendPacket _PPP_SendPacket fc
; Buffer -> R22,R23
; Len -> R10,R11
; fcs -> R20,R21
; c -> R14
; MustByteStuff -> R12
.even
_PPP_SendPacket::
xcall push_gset5
mov R12,R16
.dbline -1
.dbline 437
; }
;
; bool PPP_SendPacket(bool MustByteStuff)
; {
.dbline 443
; u8 c;
; u16 fcs;
; u8 *Buffer;
; u16 Len;
;
; Buffer = MainBuffer; //
ldi R22,<_MainBuffer
ldi R23,>_MainBuffer
.dbline 444
; Len = MainBufferWr_Tx; //
lds R10,_MainBufferWr_Tx
lds R11,_MainBufferWr_Tx+1
.dbline 446
;
; if (Len == 0) return true; // no data to send
tst R10
brne L183
tst R11
brne L183
X28:
.dbline 446
ldi R16,1
xjmp L182
L183:
.dbline 448
;
; fcs = HDLC_PPP_INIT_FCS_16; // init the fcs
ldi R20,65535
ldi R21,255
.dbline 450
;
; if (!PPP_SendByte(PPP_Flag)) return false; // start flag
ldi R16,126
xcall _PPP_SendByte
tst R16
brne L190
.dbline 450
clr R16
xjmp L182
X29:
.dbline 452
;
; for (; Len; Len--)
L187:
.dbline 453
; {
.dbline 454
; c = *Buffer++; // byte to send
movw R30,R22
ld R14,Z+
movw R22,R30
.dbline 455
; fcs = UpdateFCS_16(fcs, c); // update the FCS
mov R18,R14
movw R16,R20
xcall _UpdateFCS_16
movw R20,R16
.dbline 456
; if (!PPP_TxByte(c, MustByteStuff)) return false; // data
mov R18,R12
mov R16,R14
xcall _PPP_TxByte
tst R16
brne L191
.dbline 456
clr R16
xjmp L182
L191:
.dbline 457
L188:
.dbline 452
movw R24,R10
sbiw R24,1
movw R10,R24
L190:
.dbline 452
tst R10
brne L187
tst R11
brne L187
X30:
.dbline 459
; }
;
; fcs = ~fcs; // finalize the fcs
com R20
com R21
.dbline 461
;
; if (!PPP_TxByte((u8)(fcs & 0xff), MustByteStuff)) return false; // fcs LS-Byte
mov R18,R12
mov R16,R20
andi R17,0
xcall _PPP_TxByte
tst R16
brne L193
.dbline 461
clr R16
xjmp L182
L193:
.dbline 462
; if (!PPP_TxByte((u8)((fcs >> 8) & 0xff), MustByteStuff)) return false; // fcs MS-Byte
mov R18,R12
movw R16,R20
mov R16,R17
clr R17
andi R17,0
xcall _PPP_TxByte
tst R16
brne L195
.dbline 462
clr R16
xjmp L182
L195:
.dbline 464
;
; MainBufferWr_Tx = 0; //
clr R2
clr R3
sts _MainBufferWr_Tx+1,R3
sts _MainBufferWr_Tx,R2
.dbline 466
;
; return PPP_SendByte(PPP_Flag); // stop flag
ldi R16,126
xcall _PPP_SendByte
.dbline -2
L182:
xcall pop_gset5
.dbline 0 ; func end
ret
.dbsym r Buffer 22 pc
.dbsym r Len 10 s
.dbsym r fcs 20 s
.dbsym r c 14 c
.dbsym r MustByteStuff 12 c
.dbend
.dbfunc e PPP_StartPacket _PPP_StartPacket fV
; Protocol -> R20,R21
.even
_PPP_StartPacket::
xcall push_gset1
movw R20,R16
.dbline -1
.dbline 472
; }
;
; //****************************************************************************
;
; void PPP_StartPacket(u16 Protocol)
; { // start a PPP packet off
.dbline 473
; MainBufferWr_Tx = 0; //
clr R2
clr R3
sts _MainBufferWr_Tx+1,R3
sts _MainBufferWr_Tx,R2
.dbline 474
; PPPHeader = (T_PPP_Header1*)(MainBuffer + MainBufferWr_Tx); // get address of the ppp header in the packet
ldi R24,<_MainBuffer
ldi R25,>_MainBuffer
add R2,R24
adc R3,R25
sts _PPPHeader+1,R3
sts _PPPHeader,R2
.dbline 475
; PPPHeader->AddressField = 0xff; //
ldi R24,255
movw R30,R2
std z+0,R24
.dbline 476
; PPPHeader->ControlField = 0x03; //
ldi R24,3
lds R30,_PPPHeader
lds R31,_PPPHeader+1
std z+1,R24
.dbline 477
; PPPHeader->Protocol = htons(Protocol); //
movw R16,R20
xcall _htons
lds R30,_PPPHeader
lds R31,_PPPHeader+1
std z+3,R17
std z+2,R16
.dbline 478
; MainBufferWr_Tx += sizeof(T_PPP_Header1); // update index
lds R24,_MainBufferWr_Tx
lds R25,_MainBufferWr_Tx+1
adiw R24,4
sts _MainBufferWr_Tx+1,R25
sts _MainBufferWr_Tx,R24
.dbline -2
L197:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r Protocol 20 s
.dbend
.dbfunc e PPP_AddCodeHeader _PPP_AddCodeHeader fI
; Code -> R16
.even
_PPP_AddCodeHeader::
.dbline -1
.dbline 482
; }
;
; int PPP_AddCodeHeader(u8 Code)
; { // add the code header into the PPP packet
.dbline 483
; CodeHeader = (T_CodeHeader*)(MainBuffer + MainBufferWr_Tx); // get address of the code header in the packet
ldi R24,<_MainBuffer
ldi R25,>_MainBuffer
lds R2,_MainBufferWr_Tx
lds R3,_MainBufferWr_Tx+1
add R2,R24
adc R3,R25
sts _CodeHeader+1,R3
sts _CodeHeader,R2
.dbline 484
; CodeHeader->Code = Code; // code
movw R30,R2
std z+0,R16
.dbline 485
; CodeHeader->ID = PPP.OurID; // ID
lds R2,_PPP+29
lds R30,_CodeHeader
lds R31,_CodeHeader+1
std z+1,R2
.dbline 486
; CodeHeader->Len = sizeof(T_CodeHeader); // length - update this as data is added to the packet
ldi R24,4
ldi R25,0
lds R30,_CodeHeader
lds R31,_CodeHeader+1
std z+3,R25
std z+2,R24
.dbline 487
; MainBufferWr_Tx += sizeof(T_CodeHeader); // update index
lds R24,_MainBufferWr_Tx
lds R25,_MainBufferWr_Tx+1
adiw R24,4
sts _MainBufferWr_Tx+1,R25
sts _MainBufferWr_Tx,R24
.dbline 488
; return CodeHeader->Len; // size of data we have added
ldd R16,z+2
ldd R17,z+3
.dbline -2
L198:
.dbline 0 ; func end
ret
.dbsym r Code 16 c
.dbend
.dbfunc e PPP_Add8 _PPP_Add8 fV
; b -> R16
.even
_PPP_Add8::
.dbline -1
.dbline 492
; }
;
; void PPP_Add8(u8 b)
; { // add a byte into the PPP packet
.dbline 493
; MainBuffer[MainBufferWr_Tx++] = b; // 8-bit
lds R2,_MainBufferWr_Tx
lds R3,_MainBufferWr_Tx+1
movw R24,R2
adiw R24,1
sts _MainBufferWr_Tx+1,R25
sts _MainBufferWr_Tx,R24
ldi R24,<_MainBuffer
ldi R25,>_MainBuffer
movw R30,R2
add R30,R24
adc R31,R25
std z+0,R16
.dbline 494
; CodeHeader->Len++; // update length
lds R24,_CodeHeader
lds R25,_CodeHeader+1
adiw R24,2
movw R30,R24
ldd R24,z+0
ldd R25,z+1
adiw R24,1
std z+1,R25
std z+0,R24
.dbline -2
L200:
.dbline 0 ; func end
ret
.dbsym r b 16 c
.dbend
.dbfunc e PPP_Add16 _PPP_Add16 fV
; w -> R20,R21
.even
_PPP_Add16::
xcall push_gset1
movw R20,R16
.dbline -1
.dbline 498
; }
;
; void PPP_Add16(u16 w)
; { // add a 16-bit value into the PPP packet
.dbline 499
; *(u16*)(MainBuffer + MainBufferWr_Tx) = htons(w); // 16-bit
movw R16,R20
xcall _htons
ldi R24,<_MainBuffer
ldi R25,>_MainBuffer
lds R30,_MainBufferWr_Tx
lds R31,_MainBufferWr_Tx+1
add R30,R24
adc R31,R25
std z+1,R17
std z+0,R16
.dbline 500
; MainBufferWr_Tx += 2; // update index
lds R24,_MainBufferWr_Tx
lds R25,_MainBufferWr_Tx+1
adiw R24,2
sts _MainBufferWr_Tx+1,R25
sts _MainBufferWr_Tx,R24
.dbline 501
; CodeHeader->Len += 2; // update length
lds R24,_CodeHeader
lds R25,_CodeHeader+1
adiw R24,2
movw R30,R24
ldd R24,z+0
ldd R25,z+1
adiw R24,2
std z+1,R25
std z+0,R24
.dbline -2
L201:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r w 20 s
.dbend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -