home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gdb-4.16-base.tgz / gdb-4.16-base.tar / fsf / gdb / utils / amd-udi / montip / parallel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-23  |  5.0 KB  |  191 lines

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