home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 322_01 / ramtest2.c < prev    next >
C/C++ Source or Header  |  1990-08-06  |  16KB  |  465 lines

  1. /*
  2. ************************************************************
  3.  
  4.    Routines Programmed in C for Detecting Stuck-At Faults
  5.           in Semiconductor RAMs
  6.  
  7.                by
  8.  
  9.           Chaiyos Ruengsakulrach
  10.                          and
  11.                    Dean Lance Smith
  12.        Department of Electrical Engineering
  13.          Memphis State University
  14.             Memphis, TN 38152
  15.              (901)-678-3253
  16.              (901)-678-2175
  17.  
  18.  
  19.  
  20.        These test routines were written using the MATS and
  21.   MATS+ algorithms which are capable of detecting multiple
  22.   stuck-at faults in Random Access Memories (RAMs).  The
  23.   MATS (Modified Algorithmic Test Sequence) detects stuck-at
  24.   faults only for RAMs with wired-OR behavior.  The MATS+
  25.   detects stuck-at faults for RAMS with either wired-OR or
  26.   wired-AND behavior.
  27.  
  28.  
  29.                REFERENCE
  30.  
  31.   Nair, Ravindra, "Comments on 'An Optimal Algorithm for
  32.   Testing Stuck-at Faults in Random Access Memories,'"
  33.   IEEE Trans. on Computers, v. C-28, n. 3, Mar., 1979,
  34.   pp. 258-261.
  35.  
  36. ************************************************************
  37.  
  38.      These routines were compiled with a Turbo C compiler
  39.   (Version 2.01) that runs on MS-DOS on an IBM PC/XT clone.
  40.  
  41.      Huge pointers were chosen for this particular
  42.   application.  Huge pointers are 32 bits long and contain
  43.   both a segment address and an offset.  The segment address
  44.   ranges from 0000 to FFFF in hexadecimal.  The offset
  45.   ranges from 0000 to 000F in hexadecimal.
  46.  
  47.      The following functions used in this program are already
  48.   available in Turbo C.
  49.   - Function CLRSCR() in the library conio.h clears the
  50.     screen.
  51.   - Function GOTOXY(x,y) in the library conio.h puts the
  52.     cursor at column x, row y.
  53.   - Function WHEREX() in the library conio.h gives horizontal
  54.     cursor position within window.
  55.   - Function WHEREY() in the library conio.h gives vertical
  56.     cursor position within window.
  57.   - Function MK_FP(segment,offset) creates a huge pointer
  58.     from its component segment and offset parts.
  59.  
  60. ************************************************************
  61. */
  62.  
  63. #include<stdio.h>                      /* library stdio.h */
  64. #include<dos.h>                        /* library dos.h   */
  65. #include<conio.h>                      /* library conio.h */
  66. int chkloc(unsigned char huge *start,
  67.        unsigned char huge *end);  /* check whether input
  68.                      addresses valid  */
  69. unsigned char huge *getstart(void);    /* get the starting
  70.                       address         */
  71. unsigned char huge *getend(void);      /* get the ending
  72.                       address         */
  73. unsigned gethex(void);      /* get hexadecimal characters
  74.                    and convert them to a
  75.                    binary integer             */
  76. unsigned mats(unsigned char huge *start,
  77.           unsigned char huge *end);      /* test RAM
  78.                            using MATS */
  79. unsigned matsp(unsigned char huge *start,
  80.            unsigned char huge *end);     /* test RAM
  81.                           using MATS+ */
  82. void error(unsigned char huge *rptr, char stuck_at,
  83.        char stage, unsigned char flaw);   /* report
  84.                          fault result */
  85. /*
  86. ************************************************************
  87.              function MAIN
  88.  
  89.   displays the menu on the screen and lets the user select
  90.   a test option.
  91.  
  92. ************************************************************
  93. */
  94.  
  95. main()
  96. {
  97.  unsigned char huge *begin;        /*  starting address  */
  98.  unsigned char huge *final;        /*  ending address    */
  99.  unsigned num_fault;               /*  number of faults  */
  100.  char ch;                          /*  store the option  */
  101.  int okay;        /* check whether input addresses valid */
  102.  do
  103.  {
  104.   clrscr();                          /* clear the screen */
  105.   gotoxy(1,8);           /* put cursor at column 1,row 8 */
  106.   printf("    RAM TESTING : DETECTING STUCK-AT FAULTS  \n");
  107.   printf("    =======================================\n\n");
  108.   printf("    1.  MATS  ALGORITHM                      \n");
  109.   printf("    2.  MATS+  ALGORITHM                     \n");
  110.   printf("    3.  EXIT                             \n\n\n");
  111.   printf("    Please type number to select algorithm "
  112.      "to test RAM ");
  113.   ch =  getch();                       /* get the option */
  114.   okay = 0;
  115.   switch(ch)
  116.   {
  117.   case '1' :
  118.     while( okay != 1 )
  119.     {
  120.       clrscr();
  121.       printf("  RAM TESTING by using the MATS  \n");
  122.       printf("  =============================\n\n");
  123.       begin = getstart();       /* get starting adddress */
  124.       final = getend();         /*  get ending address   */
  125.       okay = chkloc(begin, final);      /* check starting
  126.                        and ending
  127.                        addresses OK? */
  128.     }
  129.     num_fault = mats(begin, final);         /* test RAM
  130.                           using MATS */
  131.     break;
  132.   case '2' :
  133.     while( okay != 1 )
  134.     {
  135.       clrscr();
  136.       printf("  RAM TESTING by using the MATS+  \n");
  137.       printf("  ==============================\n\n");
  138.       begin = getstart();       /* get starting address  */
  139.       final = getend();         /*  get ending address   */
  140.       okay = chkloc(begin, final);      /* check starting
  141.                        and ending
  142.                        addresses OK? */
  143.     }
  144.     num_fault = matsp(begin, final);       /* test RAM
  145.                          using MATS+ */
  146.     break;
  147.   }
  148.   if( ch == '1' || ch == '2' )
  149.   {
  150.     if( num_fault == 0 )                /*   no fault   */
  151.        printf("  There are no stuck-at faults in the RAM\n"
  152.           "  between %Fp and %Fp. \n",begin, final);
  153.     else                                /* faults exist */
  154.        printf("\n\n  Number of stuck-at faults occuring in"
  155.           " the RAM \n  between %Fp and %Fp is   %u.",
  156.         begin, final, num_fault);
  157.     printf("\n\n  Press any key to return to MENU \n");
  158.     getch();
  159.   }
  160.  }
  161.  while(ch != '3');
  162. }
  163.  
  164. /*
  165. ************************************************************
  166.             function CHKLOC
  167. ************************************************************
  168. */
  169. int chkloc( unsigned char huge *start,
  170.         unsigned char huge *end )
  171. {
  172.  int okay;
  173.  if( start > end )
  174.  {
  175.    okay = 0;
  176.    printf("\n\n\n");
  177.    printf("  **** INVALID ADDRESSES **** \n\n");
  178.    printf("  THE ENDING ADDRESS MUST BE GREATER THAN \n"
  179.       "  OR EQUAL TO THE STARTING ADDRESS !!! \n\n\n");
  180.    printf("  Press any key to reenter all the"
  181.       " addresses again... ");
  182.    getch();
  183.    return(okay);
  184.  }
  185.  else
  186.  {
  187.    okay = 1;
  188.    return(okay);
  189.  }
  190. }
  191.  
  192. /*
  193. ************************************************************
  194.             function GETSTART
  195.  
  196.   creates a huge pointer 'start' that points to the
  197.   first location to be tested in the RAM.  This pointer
  198.   is returned to the calling function.
  199.  
  200. ************************************************************
  201. */
  202.  
  203. unsigned char huge *getstart(void)
  204. {
  205.   unsigned char huge *start;
  206.   unsigned seg, off;    /* segment and offset of address  */
  207.   printf("  Please enter 4 hexadecimal characters for the"
  208.      " SEGMENT and\n  OFFSET addresses of the RAM to"
  209.      " be tested \n\n");
  210.   printf("  STARTING ADDRESS =>   SEGMENT =  ");
  211.   seg = gethex();
  212.   printf("                        OFFSET  =  ");
  213.   off = gethex();
  214.   start = MK_FP(seg, off);   /* make huge pointer 'start' */
  215.   return(start);
  216. }
  217.  
  218. /*
  219. ************************************************************
  220.              function GETEND
  221.  
  222.   creates a huge pointer 'end' that points to the last
  223.   location to be tested in the RAM.  This pointer is
  224.   returned to the calling function.
  225.  
  226. ************************************************************
  227. */
  228.  
  229. unsigned char huge *getend(void)
  230. {
  231.   unsigned char huge *end;         /*   ending address   */
  232.   unsigned seg, off;               /* segment and offset */
  233.   printf("  ENDING ADDRESS   =>   SEGMENT =  ");
  234.   seg = gethex();
  235.   printf("                        OFFSET  =  ");
  236.   off = gethex();
  237.   printf("\n\n");
  238.   end = MK_FP(seg, off);      /* make huge pointer 'end' */
  239.   return(end);
  240. }
  241.  
  242. /*
  243. ************************************************************
  244.             function GETHEX
  245. ************************************************************
  246. */
  247.  
  248. unsigned gethex(void)
  249. {
  250.     int prex, prey;        /* previous location of cursor */
  251.     unsigned num, n, i;
  252.     char s[10];
  253. /*--------------------------------------------------------*/
  254. /*  get an ASCII string of hexadecimal characters from    */
  255. /*  the keyboard ( maximum number of characters is 4 )    */
  256. /*  Note that '\r' (carriage return) may need to be       */
  257. /*  changed to '\n' (end of line) with some compilers     */
  258. /*  and operating systems.                                */
  259. /*--------------------------------------------------------*/
  260.     i = 0;
  261.     num = 0;
  262.     while(  (num < 4) && ((s[i] = getch()) != '\r')  )
  263.     {
  264.     if(  ( s[i] >= '0' && s[i] <= '9' ) ||
  265.          ( s[i] >= 'a' && s[i] <= 'f' ) ||
  266.          ( s[i] >= 'A' && s[i] <= 'F' )  )
  267.     {
  268.          printf("%c", s[i]);
  269.          i++;
  270.          num++;
  271.     }
  272.     else if( s[i] == '\b' )
  273.     {
  274.          i--;
  275.          num--;
  276.          s[i] = '0';
  277.          prex = wherex() - 1;
  278.          prey = wherey();
  279.          gotoxy( prex, prey );
  280.          printf(" ");
  281.          gotoxy( prex, prey );
  282.      }
  283.     }
  284.     s[i] = '\0';                 /* end the string with
  285.                     ' string terminator ' */
  286.     printf("\n");
  287. /*--------------------------------------------------------*/
  288. /*  convert the ASCII string 's[]' to a binary integer    */
  289. /*--------------------------------------------------------*/
  290.     i = 0;
  291.     n = 0;
  292.     while( s[i] != '\0' )
  293.     {
  294.       if( s[i] >= '0' && s[i] <= '9')
  295.       n = (16 * n) + s[i] - '0';
  296.       if( s[i] >= 'A' && s[i] <= 'F')
  297.       n = (16 * n) + 10 + s[i] - 'A';
  298.       if( s[i] >= 'a' && s[i] <= 'f')
  299.       n = (16 * n) + 10 + s[i] - 'a';
  300.       i++;
  301.     }
  302.     return(n);
  303. }
  304.  
  305.  
  306. /*
  307. ************************************************************
  308.              function MATS
  309. ************************************************************
  310. */
  311.  
  312. unsigned mats( unsigned char huge *start,
  313.            unsigned char huge *end )
  314. {
  315.    unsigned char huge *ramptr;   /* pointer to current RAM
  316.                     location              */
  317.    unsigned char flaw;           /* contents of a faulty
  318.                     memory word           */
  319.    unsigned num_fault;
  320.    num_fault = 0;
  321. /*--------------------------------------------------------*/
  322. /* begin stage A: write 0 into all locations.             */
  323. /*--------------------------------------------------------*/
  324.    for(ramptr = start; ramptr <= end; ramptr++)
  325.        *ramptr = 0x00;
  326. /*--------------------------------------------------------*/
  327. /* begin stage B: read each location and write 1's into   */
  328. /*                the location.                           */
  329. /*--------------------------------------------------------*/
  330.    for(ramptr = start; ramptr <= end; ramptr++)
  331.    {
  332.       if( (flaw = *ramptr) != 0x00 )      /* check the data
  333.                          read         */
  334.       {
  335.      num_fault++;          /* stuck-at-1 fault occurs */
  336.      error(ramptr, '1', 'B', flaw);   /* report error */
  337.       }
  338.       *ramptr = 0xFF;
  339.     }
  340. /*--------------------------------------------------------*/
  341. /* begin stage C: read all locations.                     */
  342. /*--------------------------------------------------------*/
  343.     for(ramptr = start; ramptr <= end; ramptr++)
  344.       if( (flaw = *ramptr) != 0xFF )      /* check the data
  345.                          read         */
  346.       {
  347.      num_fault++;          /* stuck-at-0 fault occurs */
  348.      error(ramptr, '0', 'C', flaw);   /* report error */
  349.       }
  350. /*------------------------------------------------------- */
  351.     return(num_fault);
  352. }
  353.  
  354. /*
  355. ************************************************************
  356.              function MATSP
  357. ************************************************************
  358. */
  359.  
  360. unsigned matsp( unsigned char huge *start,
  361.         unsigned char huge *end )
  362. {
  363.    unsigned char huge *ramptr;   /* pointer to current RAM
  364.                     location              */
  365.    unsigned char flaw;           /* contents of a faulty
  366.                     memory word           */
  367.    unsigned num_fault;
  368.    num_fault = 0;
  369. /*--------------------------------------------------------*/
  370. /* begin stage A: write 0 into all locations except       */
  371. /*                the first location.                     */
  372. /*--------------------------------------------------------*/
  373.    ramptr = start  + 1;
  374.    while( ramptr <= end )
  375.    {
  376.     *ramptr = 0x00;
  377.     ramptr++;
  378.    }
  379. /*--------------------------------------------------------*/
  380. /* begin stage B: write 1's into the first location.      */
  381. /*--------------------------------------------------------*/
  382.    ramptr = start;
  383.    *ramptr = 0xFF;
  384. /*--------------------------------------------------------*/
  385. /* begin stage C: read each location except the first     */
  386. /*                and write 1's into the location.        */
  387. /*--------------------------------------------------------*/
  388.    ramptr++;
  389.    while( ramptr <= end )
  390.    {
  391.       if( (flaw = *ramptr) != 0x00 )     /* check the data
  392.                         read          */
  393.       {
  394.      num_fault++;          /* stuck-at-1 fault occurs */
  395.      error(ramptr, '1', 'C', flaw);   /* report error */
  396.       }
  397.       *ramptr = 0xFF;
  398.       ramptr++;
  399.    }
  400. /*--------------------------------------------------------*/
  401. /* begin stage D: read each location except the last      */
  402. /*               and write 0 into the location.          */
  403. /*                Note that if the first location is the  */
  404. /*                same as the last location, the MATS+    */
  405. /*                read the first location and then write  */
  406. /*                0 into that location.                   */
  407. /*--------------------------------------------------------*/
  408.    ramptr = start;
  409.    do
  410.    {
  411.       if( (flaw = *ramptr) != 0xFF )     /* check the data
  412.                         read          */
  413.       {
  414.      num_fault++;          /* stuck-at-0 fault occurs */
  415.      error(ramptr, '0', 'D', flaw);   /* report error */
  416.       }
  417.       *ramptr = 0x00;
  418.       ramptr++;
  419.    }
  420.    while( ramptr < end );
  421. /*--------------------------------------------------------*/
  422. /* begin stage E: read the last location.  If the first   */
  423. /*                location is the same as the last        */
  424. /*                location, the MATS+ will skip this      */
  425. /*                stage.                                  */
  426. /*--------------------------------------------------------*/
  427.    if( start != end )
  428.      if( (flaw = *ramptr) != 0xFF )      /* check the data
  429.                         read          */
  430.      {
  431.        num_fault++;            /* stuck-at-0 fault occurs */
  432.        error(ramptr, '0', 'E', flaw);     /* report error */
  433.      }
  434. /*--------------------------------------------------------*/
  435. /* begin stage F: read the first location.                */
  436. /*--------------------------------------------------------*/
  437.    ramptr = start;
  438.    if( (flaw = *ramptr) != 0x00 )        /* check the data
  439.                         read          */
  440.    {
  441.        num_fault++;            /* stuck-at-1 fault occurs */
  442.        error(ramptr, '1', 'F', flaw);     /* report error */
  443.    }
  444. /*--------------------------------------------------------*/
  445.    return(num_fault);
  446. }
  447.  
  448. /*
  449. ************************************************************
  450.              function ERROR
  451. ************************************************************
  452. */
  453.  
  454. void error(unsigned char huge *rptr, char stuck_at,
  455.        char stage, unsigned char flaw)
  456. {
  457.    printf("  Stage %c in the algorithm \n",stage);
  458.    if( stuck_at == '1' )
  459.        printf("  RAM address %Fp is stuck-at-1. \n",rptr);
  460.    else
  461.        printf("  RAM address %Fp is stuck-at-0. \n",rptr);
  462.    printf("  The contents of RAM address %Fp is %x \n\n",
  463.          rptr, flaw);
  464. }
  465.