Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of webserverBlinky by
Diff: PPP-Blinky/ppp-blinky.cpp
- Revision:
- 145:098b6ed2f7f2
- Parent:
- 144:01d98cf7738e
- Child:
- 146:a45f49a2b29c
--- a/PPP-Blinky/ppp-blinky.cpp Tue Aug 29 18:42:20 2017 +0000 +++ b/PPP-Blinky/ppp-blinky.cpp Tue Aug 29 18:57:04 2017 +0000 @@ -157,7 +157,7 @@ struct pppType { int online; // we hunt for a PPP connection if this is zero int hostIP; // ip address of host - int crc; // for calculating IP and TCP CRCs + int fcs; // PPP "frame check sequence" - a 16-bit HDLC-like checksum used in all PPP frames int ledState; // state of LED1 int httpPageCount; int firstFrame; // cleared after first frame @@ -270,28 +270,28 @@ if ( pc.readable() ) putsWhileCheckingInput( "Character available!\n" ); } -/// Initialize the PPP CRC total -void crcReset() +/// Initialize the PPP FCS (frame check sequence) total +void fcsReset() { - ppp.crc=0xffff; // crc restart + ppp.fcs=0xffff; // crc restart } -/// update the cumulative PPP CRC -void crcDo(int x) +/// update the cumulative PPP FCS (frame check sequence) +void fcsDo(int x) { for (int i=0; i<8; i++) { - ppp.crc=((ppp.crc&1)^(x&1))?(ppp.crc>>1)^0x8408:ppp.crc>>1; // crc calculator + ppp.fcs=((ppp.fcs&1)^(x&1))?(ppp.fcs>>1)^0x8408:ppp.fcs>>1; // crc calculator x>>=1; } checkPc(); // handle input } -/// calculate the PPP CRC on an entire block of memory -int crcBuf(char * buf, int size) // crc on an entire block of memory +/// calculate the PPP FCS (frame check sequence) on an entire block of memory +int fcsBuf(char * buf, int size) // crc on an entire block of memory { - crcReset(); - for(int i=0; i<size; i++)crcDo(*buf++); - return ppp.crc; + fcsReset(); + for(int i=0; i<size; i++)fcsDo(*buf++); + return ppp.fcs; } /// Get one character from our received PPP buffer @@ -329,7 +329,7 @@ if(start==end) { return; // empty frame } - crcReset(); + fcsReset(); char * dest = ppp.pkt.buf; ppp.pkt.len=0; int unstuff=0; @@ -342,19 +342,19 @@ *dest = ppp.rx.buf[idx]; ppp.pkt.len++; dest++; - crcDo(ppp.rx.buf[idx]); + fcsDo(ppp.rx.buf[idx]); } } else { // unstuff characters prefixed with 0x7d *dest = ppp.rx.buf[idx]^0x20; ppp.pkt.len++; dest++; - crcDo(ppp.rx.buf[idx]^0x20); + fcsDo(ppp.rx.buf[idx]^0x20); unstuff=0; } idx = (idx+1) & (RXBUFLEN-1); if (idx == end) break; } - ppp.pkt.crc = ppp.crc & 0xffff; + ppp.pkt.crc = ppp.fcs & 0xffff; if(0) dumpPPPFrame(); // set to 1 to dump ALL ppp frames if (ppp.pkt.crc == 0xf0b8) { // check for good CRC determinePacketType(); @@ -393,7 +393,7 @@ /// send a PPP frame in HDLC format void sendPppFrame() { - int crc = crcBuf(ppp.pkt.buf, ppp.pkt.len-2); // update crc + int crc = fcsBuf(ppp.pkt.buf, ppp.pkt.len-2); // update crc ppp.pkt.buf[ ppp.pkt.len-2 ] = (~crc>>0); // fcs lo (crc) ppp.pkt.buf[ ppp.pkt.len-1 ] = (~crc>>8); // fcs hi (crc) pcPutcWhileCheckingInput(0x7e); // hdlc start-of-frame "flag"