1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
static char _[] = "@(#)parallel.c 1.4 93/09/08 14:14:32, Srini, AMD.";
/******************************************************************************
* Copyright 1992 Advanced Micro Devices, Inc.
*
* This software is the property of Advanced Micro Devices, Inc (AMD) which
* specifically grants the user the right to modify, use and distribute this
* software provided this notice is not removed or altered. All other rights
* are reserved by AMD.
*
* AMD MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS
* SOFTWARE. IN NO EVENT SHALL AMD BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL
* DAMAGES IN CONNECTION WITH OR ARISING FROM THE FURNISHING, PERFORMANCE, OR
* USE OF THIS SOFTWARE.
*
* So that all may benefit from your experience, please report any problems
* or suggestions about this software to the 29K Technical Support Center at
* 800-29-29-AMD (800-292-9263) in the USA, or 0800-89-1131 in the UK, or
* 0031-11-1129 in Japan, toll free. The direct dial number is 512-462-4118.
*
* Advanced Micro Devices, Inc.
* 29K Systems Engineering
* Mail Stop 573
* 5204 E. Ben White Blvd.
* Austin, TX 78741
* 800-292-9263
* 29k-support@AMD.COM
****************************************************************************
* Engineer: Srini Subramanian.
****************************************************************************
*/
#include <bios.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include "types.h"
#include "memspcs.h"
#include "messages.h"
#include "mtip.h"
#include "tdfunc.h"
void endian_cvt PARAMS((union msg_t *, int));
extern FILE *MsgFile; /* for logging error retries */
unsigned _bios_printer(unsigned service, unsigned printer, unsigned data);
INT32 par_write( char *buffer, INT32 length);
static unsigned portID=0;
#define LPT1 0
#define LPT2 1
#define CHECKSUM_FAIL -1
INT32
init_parport(portname)
char *portname;
{
unsigned status;
if (strncmp(portname, "lpt1", 4) == 0) {
status = _bios_printer( _PRINTER_INIT, LPT1, 0);
portID = LPT1;
} else if (strncmp(portname, "lpt2", 4) == 0) {
status = _bios_printer( _PRINTER_INIT, LPT2, 0);
portID = LPT2;
}
#if 0
if (status != 0x90) {
printf("parallel port status 0x%.4x\n", status);
return ((INT32) -1);
} else {
return ((INT32) 0);
}
#endif
return ((INT32) 0);
}
INT32
msg_send_parport(msg_ptr, port_base)
union msg_t *msg_ptr;
INT32 port_base;
{
INT32 result, i, ack, comm_err;
UINT32 checksum;
unsigned int timeout;
INT32 Rx_ack[2];
INT32 header_size = (2 * sizeof(INT32));
BYTE *bfr_ptr = (BYTE *) msg_ptr;
/* Save length before doing endian conversion */
INT32 length = msg_ptr->generic_msg.length;
INT32 total_length;
total_length = header_size + length;
/* Endian conversion */
if (tip_target_config.TipEndian != tip_target_config.P29KEndian)
endian_cvt(msg_ptr, OUTGOING_MSG);
/* calc checksum for msg */
checksum = 0;
for (i=0; i < total_length; i++)
checksum = checksum + bfr_ptr[i];
/* Append checksum to the end of the message. Do not update the
* "length" field of the message header.
*/
bfr_ptr[total_length] = (BYTE) ((checksum >> 24) & 0xff);
bfr_ptr[total_length+1] = (BYTE) ((checksum >> 16) & 0xff);
bfr_ptr[total_length+2] = (BYTE) ((checksum >> 8) & 0xff);
bfr_ptr[total_length+3] = (BYTE) ((checksum >> 0) & 0xff);
/* send msg */
comm_err = (INT32) 0;
/* send msg */
result = par_write((char *)bfr_ptr, total_length+4 /* +4 */);
if (result != (INT32) 0)
return((INT32) FAILURE);
/* get ack */
timeout = 0;
result = (INT32) -1;
comm_err = (INT32) 0;
while ((timeout < 600) && (result == (INT32) -1)
&& (comm_err == (INT32) 0)) {
/* Poll for user interrupt */
timeout=timeout+1;
result = recv_bfr_serial((BYTE *) Rx_ack, (2 * sizeof(INT32)),
BLOCK, port_base, &comm_err);
}
if (comm_err != (INT32) 0) {
reset_comm_serial((INT32) -1, (INT32) -1);
return ((INT32) MSGRETRY);
}
/* check if timed out */
if (timeout >= 10000) {
if (MsgFile) {
fprintf(MsgFile,"Timed out before ACK received. Reset comm. timeout=%ld\n",timeout);
fflush(MsgFile);
}
(void) reset_comm_serial((INT32) 0, (INT32) 0);
return ((INT32) MSGRETRY);
}
ack = (INT32) Rx_ack[1];
/* endian convert Ack */
if (tip_target_config.TipEndian != tip_target_config.P29KEndian)
tip_convert32((BYTE *) &ack);
if (ack != CHECKSUM_FAIL) {
return(0); /* successful send */
}
else {
if (MsgFile) { /* log the error */
fprintf(MsgFile,
"\n** Checksum: Nack Received, Resending.\n");
fflush(MsgFile);
};
}
return ((INT32) FAILURE);
}
INT32
par_write(buffer, length)
char *buffer;
INT32 length;
{
unsigned status;
for ( ; length > (INT32) 0; length=length-1)
{
status = _bios_printer(_PRINTER_WRITE, portID, (unsigned) *buffer);
/* printf("status 0x%.4x \n", status); */
buffer++;
}
return ((INT32) 0);
}
|