home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xibm.zip / mpel / mpelFifo.c < prev    next >
C/C++ Source or Header  |  1990-04-07  |  6KB  |  220 lines

  1. /*
  2.  * Copyright IBM Corporation 1987,1988,1989
  3.  *
  4.  * All Rights Reserved
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for any purpose and without fee is hereby granted,
  8.  * provided that the above copyright notice appear in all copies and that 
  9.  * both that copyright notice and this permission notice appear in
  10.  * supporting documentation, and that the name of IBM not be
  11.  * used in advertising or publicity pertaining to distribution of the
  12.  * software without specific, written prior permission.
  13.  *
  14.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  15.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  16.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  17.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  18.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  19.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  20.  * SOFTWARE.
  21.  *
  22. */
  23. /***********************************************************
  24.         Copyright IBM Corporation 1987,1988
  25.  
  26.                       All Rights Reserved
  27.  
  28. Permission to use, copy, modify, and distribute this software and its
  29. documentation for any purpose and without fee is hereby granted,
  30. provided that the above copyright notice appear in all copies and that
  31. both that copyright notice and this permission notice appear in
  32. supporting documentation, and that the name of IBM not be
  33. used in advertising or publicity pertaining to distribution of the
  34. software without specific, written prior permission.
  35.  
  36. IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  37. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  38. IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  39. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  40. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  41. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  42. SOFTWARE.
  43.  
  44. ******************************************************************/
  45.  
  46. /* $Header: /andrew/X11/r3src/r3plus/server/ddx/ibm/mpel/RCS/mpelFifo.c,v 6.2 89/01/31 11:46:13 paul Exp $ */
  47. /* $Source: /andrew/X11/r3src/r3plus/server/ddx/ibm/mpel/RCS/mpelFifo.c,v $ */
  48.  
  49. #ifndef lint
  50. static char *rcsid = "$Header: /andrew/X11/r3src/r3plus/server/ddx/ibm/mpel/RCS/mpelFifo.c,v 6.2 89/01/31 11:46:13 paul Exp $" ;
  51. #endif
  52.  
  53. /***==================================================================***/
  54.  
  55. #include "Xmd.h"
  56.  
  57. #include "mpelHdwr.h"
  58. #include "mpelFifo.h"
  59.  
  60. #include "ibmTrace.h"
  61.  
  62. #define DELAY_ADDR    0xf00080E0        /* IOCC delay location */
  63. #define DELAY(n) \
  64.     { register int N = (n) ; \
  65.         while ( --N >= 0 ) \
  66.         * (volatile char *) DELAY_ADDR = 0xff ;    }
  67.  
  68. /***==================================================================***/
  69.  
  70. #ifdef    PORTABLE
  71. /*
  72.  *  mpelWFifo writes commands to the megapel fifo.
  73.  */
  74.  
  75. int
  76. mpelWFifo( nargs, command, arg1, arg2 )
  77.     int         nargs ;
  78.     unsigned short int command ;
  79.     unsigned long int arg1 ;
  80.     unsigned long int arg2 ;
  81. {
  82.     int         retry ;        /* Current RETRY count         */
  83.     unsigned short int tmp[2] ;
  84.     int         out_data ;        /* num of bytes in command */
  85.     register unsigned short int *data_ptr;
  86.     register volatile unsigned short *psr= &MPEL_PSR;
  87.     register volatile unsigned short *fifo= &MPEL_FIFO;
  88.     register             int     i;
  89.     register int data_len ;        /* num of bytes we have to send... */
  90.  
  91.  
  92.     TRACE(("mpelWFifo(%d,0x%x,0x%x,0x%x)\n",nargs,command,arg1,arg2)) ;
  93.  
  94.     if ( !command ) {
  95.     data_len = nargs ;
  96.     if ( data_len & 0x1 )
  97.         data_len++ ;
  98.     out_data = data_len ;
  99.     data_ptr = (unsigned short int *) arg1 ;
  100.     }
  101.     else if ( nargs <= 2 ) {
  102.     out_data = data_len = 4 + ( nargs * 2 ) ;
  103.     tmp[0] = (unsigned short int) arg1 ;
  104.     tmp[1] = (unsigned short int) arg2 ;
  105.     data_ptr = &tmp[0] ;
  106.     }
  107.     else {
  108.     data_len = nargs ;
  109.     out_data = nargs + arg2 ;
  110.     if ( out_data & 0x1 )
  111.         out_data++ ;
  112.     data_ptr = (unsigned short int *) arg1 ;
  113.     }
  114.  
  115.     if ( command ) {
  116.     while ( !( *psr & PSR_FIFO_NOT_FULL ) ) /* DO NOTHING */ ;
  117.     MPEL_FIFO = out_data ;
  118.  
  119.     while ( !( *psr & PSR_FIFO_NOT_FULL ) ) /* DO NOTHING */ ;
  120.     MPEL_FIFO = command ;
  121.     data_len -= 4 ;
  122.     }
  123.  
  124.     retry = 0 ;
  125.     while ( data_len > 0 ) {
  126.     /*
  127.      * figure out how many bytes we can safely write to the fifo.
  128.          */
  129.     if ( *psr & PSR_FIFO_NOT_HALF_FULL ) {
  130.         i = MIN( (MPEL_FIFO_LEN/2) , data_len ) ;
  131.         data_len -= i ;
  132.         while ( i > 0) {
  133.         *fifo= *data_ptr++ ;
  134.         i -= 2 ;
  135.         }
  136.     }
  137.     else if ( *psr & PSR_FIFO_NOT_FULL ) {
  138.         *fifo = *data_ptr++;
  139.         data_len -= 2;
  140.     }
  141.     else {
  142.         if ( retry > MPEL_MAXRETRY ) {
  143.         ErrorF("WSGO!! FIFO jammed -- MPEL_MAXRETRY reached\n") ;
  144.         return -1  ; /* give up */
  145.         }
  146.         DELAY( 1024 ) ;
  147.         retry++ ;
  148.         continue ;
  149.     }
  150.     } /* end of while loop */
  151.     return 0 ;
  152. }
  153.  
  154. #endif /* PORTABLE */
  155.  
  156. /***==================================================================***/
  157.  
  158. void mpelStartFifo()
  159. {
  160.     TRACE(("mpelStartFifo()\n")) ;
  161.  
  162.     MPEL_COMM_REQ = MPELCMD_ENTER_FIFO ;
  163.     MPEL_COMM_REASON = 0 ;
  164.     MPEL_PCR &= ~ PCR_INTR_TMS ;
  165.     MPEL_PCR |= PCR_INTR_TMS ;
  166.     return ;
  167. }
  168.  
  169. /***==================================================================***/
  170.  
  171. void mpelContFifo()
  172. {
  173.     TRACE(("mpelContFifo()\n")) ;
  174.  
  175.     MPEL_COMM_REQ = MPELCMD_CONT_FIFO ;
  176.     MPEL_COMM_REASON = 0 ;
  177.     MPEL_PCR &= ~ PCR_INTR_TMS ;
  178.     MPEL_PCR |= PCR_INTR_TMS ;
  179.     return ;
  180. }
  181.  
  182. #ifdef MPELINTR
  183. /* ---------------------------------------------------------------- */
  184. /* jfc@athena: expect a SIGIO whenever the megapel adapter send an
  185.    interrupt.  Knowing this, when the adapter is full instead of
  186.    looping waiting for the FIFO to empty, can save data elsewhere
  187.    and have the signal handler feed it to the FIFO */
  188.  
  189. #include <sys/signal.h>
  190.  
  191. #define SYS_mpelctl 194
  192. #define MIO_SET    1
  193. #define    MIO_CLR    2
  194.  
  195. static int mpel_intr_on = 0;
  196.  
  197. extern int mpelfeedfifo();
  198. int (*osigIO)();
  199.  
  200. int mpelintrinit()
  201. {
  202.   int xxx;
  203.   int (*osigSYS)();
  204.  
  205.   osigSYS = signal(SIGSYS, SIG_IGN);
  206.   if(syscall(194, MIO_SET, &xxx, ~0) == -1 ||
  207.      ((osigIO = signal(SIGIO, mpelfeedfifo)) != SIG_DFL && osigIO != SIG_IGN))
  208.     {
  209.       mpel_intr_on = 0;
  210.       signal(SIGSYS, osigSYS);
  211.       return -1;
  212.     } else {
  213.       mpel_intr_on = 1;
  214.       signal(SIGSYS, osigSYS);
  215.       return 0;
  216.     }
  217. }
  218.  
  219. #endif
  220.