📄 xmodem_specs.txt
字号:
The Xmodem Protocol Specification MODEM PROTOCOL OVERVIEW1/1/82 by Ward Christensen. I will maintain a master copy ofthis. Please pass on changes or suggestions via CBBS/Chicagoat (312) 545-8086, or by voice at (312) 849-6279.NOTE this does not include things which I am not familiar with,such as the CRC option implemented by John Mahr.Last Rev: (none)At the request of Rick Mallinak on behalf of the guys atStandard Oil with IBM P.C.s, as well as several previousrequests, I finally decided to put my modem protocol intowriting. It had been previously formally published only in theAMRAD newsletter.Table of Contents1. DEFINITIONS2. TRANSMISSION MEDIUM LEVEL PROTOCOL3. MESSAGE BLOCK LEVEL PROTOCOL4. FILE LEVEL PROTOCOL5. DATA FLOW EXAMPLE INCLUDING ERROR RECOVERY6. PROGRAMMING TIPS.-------- 1. DEFINITIONS.<soh> 01H<eot> 04H<ack> 05H<nak> 15H<can> 18H-------- 2. TRANSMISSION MEDIUM LEVEL PROTOCOLAsynchronous, 8 data bits, no parity, one stop bit.The protocol imposes no restrictions on the contents of thedata being transmitted. No control characters are looked forin the 128-byte data messages. Absolutely any kind of data maybe sent - binary, ASCII, etc. The protocol has not formallybeen adopted to a 7-bit environment for the transmission ofASCII-only (or unpacked-hex) data , although it could be simplyby having both ends agree to AND the protocol-dependent datawith 7F hex before validating it. I specifically am referringto the checksum, and the block numbers and their ones-complement.Those wishing to maintain compatibility of the CP/M filestructure, i.e. to allow modemming ASCII files to or from CP/Msystems should follow this data format:* ASCII tabs used (09H); tabs set every 8.* Lines terminated by CR/LF (0DH 0AH)* End-of-file indicated by ^Z, 1AH. (one or more)* Data is variable length, i.e. should be considered acontinuous stream of data bytes, broken into 128-bytechunks purely for the purpose of transmission. * A CP/M "peculiarity": If the data ends exactly on a128-byte boundary, i.e. CR in 127, and LF in 128, asubsequent sector containing the ^Z EOF character(s)is optional, but is preferred. Some utilities oruser programs still do not handle EOF without ^Zs.* The last block sent is no different from others, i.e.there is no "short block". -------- 3. MESSAGE BLOCK LEVEL PROTOCOLEach block of the transfer looks like:<SOH><blk #><255-blk #><--128 data bytes--><cksum>in which:<SOH> = 01 hex<blk #> = binary number, starts at 01 increments by 1, andwraps 0FFH to 00H (not to 01)<255-blk #> = blk # after going thru 8080 "CMA" instr, i.e.each bit complemented in the 8-bit block number.Formally, this is the "ones complement".<cksum> = the sum of the data bytes only. Toss any carry.-------- 4. FILE LEVEL PROTOCOL---- 4A. COMMON TO BOTH SENDER AND RECEIVER:All errors are retried 10 times. For versions running withan operator (i.e. NOT with XMODEM), a message is typed after 10errors asking the operator whether to "retry or quit".Some versions of the protocol use <can>, ASCII ^X, tocancel transmission. This was never adopted as a standard, ashaving a single "abort" character makes the transmissionsusceptible to false termination due to an <ack> <nak> or <soh>being corrupted into a <can> and canceling transmission.The protocol may be considered "receiver driven", that is,the sender need not automatically re-transmit, although it doesin the current implementations.---- 4B. RECEIVE PROGRAM CONSIDERATIONS:The receiver has a 10-second timeout. It sends a <nak>every time it times out. The receiver's first timeout, whichsends a <nak>, signals the transmitter to start. Optionally,the receiver could send a <nak> immediately, in case the senderwas ready. This would save the initial 10 second timeout. However, the receiver MUST continue to timeout every 10 secondsin case the sender wasn't ready.Once into a receiving a block, the receiver goes into aone-second timeout for each character and the checksum. If thereceiver wishes to <nak> a block for any reason (invalidheader, timeout receiving data), it must wait for the line toclear. See "programming tips" for ideasSynchronizing: If a valid block number is received, itwill be: 1) the expected one, in which case everything is fine;or 2) a repeat of the previously received block. This shouldbe considered OK, and only indicates that the receivers <ack>got glitched, and the sender re-transmitted; 3) any other blocknumber indicates a fatal loss of synchronization, such as therare case of the sender getting a line-glitch that looked likean <ack>. Abort the transmission, sending a <can>---- 4C. SENDING PROGRAM CONSIDERATIONS.While waiting for transmission to begin, the sender hasonly a single very long timeout, say one minute. In thecurrent protocol, the sender has a 10 second timeout beforeretrying. I suggest NOT doing this, and letting the protocolbe completely receiver-driven. This will be compatible withexisting programs.When the sender has no more data, it sends an <eot>, andawaits an <ack>, resending the <eot> if it doesn't get one. Again, the protocol could be receiver-driven, with the senderonly having the high-level 1-minute timeout to abort.-------- 5. DATA FLOW EXAMPLE INCLUDING ERROR RECOVERYHere is a sample of the data flow, sending a 3-block message.It includes the two most common line hits - a garbaged block,and an <ack> reply getting garbaged. <xx> represents thechecksum byte.SENDER RECEIVERtimes out after 10 seconds, <--- <nak><soh> 01 FE -data- <xx> ---> <--- <ack><soh> 02 FD -data- xx ---> (data gets line hit) <--- <nak><soh> 02 FD -data- xx ---> <--- <ack><soh> 03 FC -data- xx ---> (ack gets garbaged) <--- <ack><soh> 03 FC -data- xx ---> <ack><eot> ---> <--- <ack>-------- 6. PROGRAMMING TIPS.* The character-receive subroutine should be called with aparameter specifying the number of seconds to wait. Thereceiver should first call it with a time of 10, then <nak> andtry again, 10 times.After receiving the <soh>, the receiver should call thecharacter receive subroutine with a 1-second timeout, for theremainder of the message and the <cksum>. Since they are sentas a continuous stream, timing out of this implies a seriouslike glitch that caused, say, 127 characters to be seen insteadof 128.* When the receiver wishes to <nak>, it should call a "PURGE"subroutine, to wait for the line to clear. Recall the sendertosses any characters in its UART buffer immediately uponcompleting sending a block, to ensure no glitches were mis-interpreted.The most common technique is for "PURGE" to call thecharacter receive subroutine, specifying a 1-second timeout,and looping back to PURGE until a timeout occurs. The <nak> isthen sent, ensuring the other end will see it.* You may wish to add code recommended by Jonh Mahr to yourcharacter receive routine - to set an error flag if the UARTshows framing error, or overrun. This will help catch a fewmore glitches - the most common of which is a hit in the highbits of the byte in two consecutive bytes. The <cksum> comesout OK since counting in 1-byte produces the same result ofadding 80H + 80H as with adding 00H + 00H.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -