• Aucun résultat trouvé

Host Software Requirements for Formatted Transfers

Dans le document SYSTEM USERS MANUAL (Page 160-166)

Because formatted transfers require a formal protocol, a host computer used with the 8540 must be capable of

Fig. 4-6. Protocol for formatted downloads.

4-16

3936-27

fn!ersystem Commun!cat!cn-8540 System Users

satisfying that protocol. In particular, the following programs are required on the host computer:

1. A transmit program that will transfer Tekhex blocks to the 8540.

2. A receive program that will accept Tekhex blocks from the 8540.

3. If you have object files in non-Tekhex format that you would like to transfer and use on the 8540, you must have a conversion program that will translate the object files into Tekhex format.

Notice that without handshaking, the protocol for a formatted transfer is the same as for an unformatted ASCII transfer, as described eariier in this subsection. Therefore, a simple copy command could serve as a transmit or receive program. However, the 8540 generally takes longer to process a message block than the host requires to send the next one, so the transmit program must pause enough between lines that no data is lost.

One way for the host to achieve the necessary delay is to transmit "fill" characters at the beginning of each message block. COM finishes processing one message block while it receives (and ignores) the fill characters at the beginning of the next block. You may use any characters you want for fill, so long as they differ from the host's end-of-line characters(s) and from the leading character of the message block. For transfers at 2400 baud, four to six fill characters should be sufficient; the actual number required depends on your host and baud rate.

Transmit Program. This program downloads Tekhex-formatted files to the 8540, using the download protocol described earlier in this section. The general algorithm is as follows:

1. Read a Tekhex block from a file (error checking for valid format is optional).

2. Transmit the block followed by the predefined prompt sequence, and wait for an acknowledgement. The prompt sequence is defined in the COM command line, and the 8540 will not respond until it receives the prompt.

3. If the reply is a negative acknowledgement (NAK):

a. Increment the negative acknowledgement counter (this counter keeps track of how many successive transmission failures have occurred).

b. If the negative acknowledgement counter exceeds a maximum value that you have defined, terminate the transfer by sending an abort block.

c. Prepare to re-transmit the block that was incorrectly received and go to step 2.

4. If the reply is a positive acknowledgement (ACK):

a. If the block sent was a termination block, terminate the transfer.

b. Otherwise, go to step 1.

REV JAN 1983

Intersystem Communication-8540 System Users

This algorithm is presented in pseudo-code in Fig. 4-7.

Receive Program. This program receives Tekhex files from the 8540, using the upload protocol described earlier in this section. The general algorithm is as follows:

1. Read a Tekhex block from the 8540.

2. Verify proper format. A Standard Tekhex block must begin with a slash and must not exceed 71 characters in length (not counting the end-of-line). An Extended Tekhex block must begin with a percent sign and must not exceed 255 characters in length (not counting the end-of-line).

3. If the block is a termination block, a. Verify the checksum.

b. If an error is encountered, send a NAK followed by the pre-defined prompt sequence, and increment the NAK counter.

END-OF-FILE

=

FALSE

WHILE NOT END-OF-FILE

READ TEKHEX BLOCK FROM FILE

Formatted Transfers

c. If no error is encountered, write the block to a file, transmit an ACK followed by the predefined prompt sequence, and exit the receive program.

4. If the block is not a termination block, a. Verify the byte count.

b. Verify the checksum(s).

c. If an error is encountered, increment the NAK counter and test to see if it exceeds a maximum value that you've selected. If it exceeds that value, terminate the transmission with an abort block;

otherwise, send a NAK followed by the predefined prompt sequence to the 8540. The prompt sequence is defined in the COM command line, and is used by the 8540 to determine when the host computer is ready for input.

d. If no error is encountered, write the block to a file and send an ACK followed by the predefined prompt-sequence to the 8540.

IF TEKHEX BLOCK IS A TERMINATION BLOCK THEN END-OF-FILE

=

TRUE NUMBER-OF-NAKS

=

0

GOODTX

=

FALSE REPEAT

TRANSMIT BLOCK

TRANSMIT PROMPT SEQUENCE GET REPLY

IF REPLY IS AN ACK THEN GOODTX

=

TRUE ELSE

NUMBER-OF-NAKS

=

NUMBER-OF-NAKS + 1 IF NUMBER-OF-NAKS >= 5

END THEN

END

TRANSMIT ABORT BLOCK GOODTX

=

TRUE END-OF-FILE

=

TRUE

UNTIL GOODTX

=

TRUE

END EXIT

Fig. 4-7. Algorithm for Tekhex transmit program.

3936-28

FOimattad Transfers

This general algorithm is presented in pseudo-code in Fig.

4-8.

Conversion Programs. This discussion gives two algorith-ms for converting a file of object code into Tekhex format.

The first algorithm is for conversion to Standard Tekhex,

NAK-COUNTER

=

0

END-OF-TRANSMISSION

=

FALSE WHILE NOT END-OF-TRANSMISSION

CLEAR ERROR FLAG

READ A TEKHEX BLOCK FROM THE RECEIVE LINE

IF TriE BLOCK STARTS WITH A n / n AND BLOCK-LENGTH <= (.1

OR THE BLOCK STARTS WITH A "%" AND BLOCK-LENGTH <= 255 THEN

IF BLOCK IS A TERMINATION BLOCK THEN

VERIFY CHECKSUM IF ERROR

THEN SET ERROR FLAG

intersystem Communication-8540 System Users

and the second is for conversion to Extended Tekhex.

Because of the wide variation in object file formats from assembler to assembler, it is possible to give only very general algorithms.

ELSE **NO ERROR IN TERMINATION BLOCK**

END

END

WRITE BLOCK TO FILE END-OF-TRANSMISSION

=

TRUE TRANSMIT ACK, END-OF-LINE TRANSMIT PROMPT SEQUENCE

IF BLOCK IS A NOT A TERMINATION BLOCK THEN

VERIFY BYTE COUNT VERIFY CHECKSUM(S)

IF ERROR

THEN SET ERROR FLAG

ELSE **NO ERROR IN DATA OR SYMBOL BLOCK**

WRITE BLOCK TO FILE TRANSMIT ACK, END-OF-LINE TRANSMIT PROMPT SEQUENCE NAK-COUNTER

=

0

END END END

ELSE **BLOCK FORMAT IS BAD**

SET ERROR FLAG END

IF ERROR FLAG SET THEN

NAK-COUNTER

=

NAK-COUNTER + 1

END END EXIT

4-18

IF NAK-COUNTER >= NAK-LIMIT

THEN **IF NUMBER OF NAKS EXCEEDS NAK-LIMIT,

TRANSMIT ABORT BLOCK ABORT THE TRANSMISSION**

END-OF-TF_~NSMISSION TRl~

END ELSE

END

TRANSMIT NAK, END-OF-LINE TRANSMIT PROMPT SEQUENCE

Fig. 4-8. Algorithm for Tekhex receive program.

3936-29

@

Intersystem Communication-8540 System Users

Standard Tekhex Conversion Program.

1. Discard any header information and scan for the first block of code.

2. Read the block of code.

3. If there are no more blocks:

a. Generate a termination block.

b. Stop execution.

4. Strip off any non-object code information from the block.

5. Check the block for valid input format.

6. Start the output block with a slash.

7. Immediately after the slash, append the 4-digit load address for the block.

8. Determine the byte count n, where n is the number of bytes of object code in the block. Place the byte count in the output block immediately following the load address.

DISCARD HEADER INFORMATION END-OF-FILE

=

FALSE WHILE NOT END-OF-FILE

READ BLOCK FROM INPUT FILE IF NO MORE BLOCKS

THEN END-OF-FILE

=

TRUE ELSE

IF BLOCK IS A TERMINATION BLOCK THEN

Formatted Transfers

9. Calculate the first checksum as the sum of the individual hexadecimal digits of the load address and the byte count. Append this value immediately following the byte count.

10. Put the n bytes of object code into the block, immediately following the first checksum. While performing this step, calculate the second checksum as the sum, mod 256, of the 2n hexadecimal digits in the object code.

11. Write the block to the output file.

12. Go to step 2.

This general algorithm is presented in pseudo-code in Fig.

4-9.

SAVE TRANSFER ADDRESS FOR TEKHEX TERMINATION BLOCK END-OF-FILE

=

TRUE

END END

END ELSE

END

SAVE LOAD ADDRESS

STRIP NON OBJECT CODE INFORMATION FROM BLOCK CHECK FOR VALID FORMAT

IF ERROR THEN

OUTPUT ERROR MESSAGE END-OF-FILE

=

TRUE END

ELSE

END

OUTPUT-BLOCK [01

=

"1"

DETERMINE LOAD ADDRESS

OUTPUT-BLOCK [1 .. 4]

=

4-DIGIT LOAD ADDRESS DETERMINE BYTE COUNT

OUTPUT-BLOCK [5 .. 6]

=

2-DIGIT BYTE COUNT CALCULATE FIRST CHECKSUM

OUTPUT-BLOCK [7 .. 8]

=

2-DIGIT CHECKSUM OUTPUT-BLOCK [9 .. 2n+8]

=

OBJECT CODE CALCULATE SECOND CHECKSUM

OUTPUT-BLOCK [2n+9 .. 2n+10]

=

2-DIGIT CHECKSUM WRITE OUTPUT-BLOCK TO FILE

GENERATE TEKHEX TERMINATION BLOCK EXIT

Fig. 4-9. Algorithm for Standard Tekhex conversion program.

3936-30A

Formatted Transfers

Extended Tekhex Conversion Program. This algorithm makes the following assumptions:

• The object file may contain program symbols and section information as well as executable object code.

• All the usable information in each block is output to the Tekhex file before the next block is read from the object file. (You may find it more useful to save the program symbols in a table as you proceed through the object file, and generate your symbol blocks from the symbol table at the end of the program.)

• At most one data block and/or one symbol block is generated for each block read from the object file: there are no checks to verify that the maximum block length (255) has not been exceeded.

• The variable n is used to represent the number of digits in a variable-length number. The value of n may be constant throughout the program, or it may be different for each number you encode (for example, if you choose to eliminate leading zeros). Similarly, the variable 5 represents the number of characters in a variable-length symbol.

Here is the algorithm:

1. Discard any header information and scan for the first block of code or symbols.

2. Read the block.

3. If there are no more blocks:

a. For every undefined section, generate a symbol block with a section definition field.

b. Generate a termination block.

c. Stop execution.

DISCARD HEADER INFORMATION END-OF-FILE

=

FALSE

Intersystem Communication-8540 System Users

4. Strip off any extraneous information.

5. Check the block for valid input format.

e. Determine the block length and checksum and put them in the block header.

c. Place the name of the section that contains these symbols in the block. definition field containing the symbol, its type, and its value.

SAVE TRANSFER ADDRESS FOR TEKHEX TERMINATION BLOCK END-OF-FILE

=

TRUE

OUTPUT ERROR MESSAGE END-OF-FILE

=

TRUE

Fig. 4-10. Algorithm for Extended Tekhex conversion program. (part 1 of 2)

3936-31

@

Intersystem Communication-8540 System Users

END END

ELSE

END END

IF BLOCK CONTAINS EXECUTABLE CODE THEN **GENERATE DATA BLOCK**

OUTPUT-BLOCK [oJ

=

"%"

OUTPUT-BLOCK [3J

=

"6"

OUTPUT-BLOCK [6J

=

n

OUTPUT-BLOCK [7 .. 6+nJ = n-DIGIT LOAD ADDRESS OUTPUT-BLOCK [7+n .. 6+n+2mJ = m BYTES OF OBJECT CODE OUTPUT-BLOCK [1 .. 2J = 6+n+2m **2-DIGIT BLOCK LENGTH**

OUTPUT-BLOCK [4 .. 5J = 2-DIGIT CHECKSUM WRITE OUTPUT-BLOCK TO FILE

END

IF BLOCK CONTAINS SYMBOLS OR SECTION INFO~~TION

THEN **GENERATE SYMBOL BLOCK**

END

OUTPUT-BLOCK [oJ "%"

OUTPUT-BLOCK [3J

=

"3"

OUTPUT-BLOCK [6J = s

OUTPUT-BLOCK [7 .. 6+sJ = s-CHARACTER SECTION NAME

P = 7+s **p POINTS TO NEXT AVAILABLE SPOT IN OUTPUT-BLOCK**

IF SECTION NOT ALREADY DEFINED

THEN IF BASE ADDRESS AND LENGTH ARE AVAILABLE THEN **GENERATE SECTION DEFINITION FIELD**

END

OUTPUT-BLOCK [PJ = "0"

OUTPUT-BLOCK [p+lJ = n

OUTPUT-BLOCK [p+2 .. p+l+nJ = n-DIGIT BASE ADDRESS P = p+n+2

OUTPUT - BLOCK [p J = n

OUTPUT-BLOCK [p+l .. p+nJ = n-DIGIT SECTION LENGTH P = p+n+l

MARK SECTION AS DEFINED ELSE MARK SECTION AS UNDEFINED

**GENERATE SYMBOL DEFINITION FIELDS**

FOR EACH SYMBOL

END

OUTPUT-BLOCK [PJ = SYMBOL TYPE OUTPUT-BLOCK [p+lJ = s

OUTPUT-BLOCK [p+2 .. p+l+sJ = s-CHARACTER SYMBOL P = p+s+2

OUTPUT-BLOCK [PJ = n

OUTPUT-BLOCK [p+l .. p+nJ = n-DIGIT VALUE p=p+n+l

OUTPUT-BLOCK [1 .. 2J = p-l **2-DIGIT BLOCK LENGTH**

OUTPUT-BLOCK [4 .. 5J = 2-DIGIT CHECKSUM WRITE OUTPUT-BLOCK TO FILE

FOR EACH UNDEFINED SECTION

GENERATE SYMBOL BLOCK WITH SECTION DEFINITION FIELD GENERATE TEKHEX TERMINATION BLOCK

EXIT

Fig. 4-10. Algorithm for Extended Tekhex conversion program. (part 2 of 2)

Formatted Transfers

3939·31

Dans le document SYSTEM USERS MANUAL (Page 160-166)

Documents relatifs