Allen-Bradley 1784-KTX Reference Manual page 113

Table of Contents

Advertisement

Appendix B
Programming Examples
/* If user did not request direct download to dual port, go through
the iterations of downloading through the already download loadpcl.bin */
if (file_into_dp == FALSE) {
while(!eof(loadfile)) {
/* read up to 0x780 bytes into dual port offset 0x80, which is where
the loadpcl.bin program expects to find the binary */
length = read(loadfile, &base[LOADPCL_DATA_WINDOW], 0x780);
/* Put the length (number of bytes just read) into appropriate location
in dual port */
* (int *) (&base[LOADPCL_SIZE]) = length;
/* On first pass through LOADPCL.BIN, need to release the KTX from
reset, subsequent passes through LOADPCL.BIN the procedure is
different */
if (firstpass) {
base[KTX_RELEASE] = 1; /* Release the KTX from reset */
firstpass = 0;
}
else base[LOADPCL_HANDSHAKE] = 0; /* Not the first pass through, so set byte to */
/* Wait for loadpcl.bin to indicate it is done with this chunk, or user */
/* presses a key.
while(base[LOADPCL_HANDSHAKE] == 0) if (kbhit()) exit(1);
/* Check status byte for errors */
switch(base[LOADPCL_STATUS]) {
case 0:
/* OK – no error */
break;
case 1:
printf("\nDownload error: Block too large.\n");
exit(2);
break;
case 2:
printf("\nDownload error: RAM full.\n");
exit(2);
break;
default:
printf("\nDownload error: Unknown – %02x.\n", base[LOADPCL_STATUS]);
exit(2);
break;
}
}
printf("\nTotal bytes downloaded: %04x\n", *(int *) (&base[LOADPCL_LENGTH]));
base[KTX_RESET] = 1;
return(0);
}
else {
/* user requested a direct load into dual port */
/* do the read directly from the file into dual port */
length = read(loadfile, base, 0x800);
/* Check to see if user requested a file which was too long to fit in
dual port.
if (length == 0x800) {
printf("\nFile is too long to fit in dual port.\n");
exit(1);
Allen-Bradley Parts
}
B-34
/* loop until end of file */
/* set flag so next pass through is different */
/* zero to tell loadpcl.bin that another chunk*/
/* of data is ready to be transferred.
*/
*/
*/

Advertisement

Table of Contents
loading

This manual is also suitable for:

1784-ktxd1784-kts

Table of Contents