Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 7 May 1996 23:02:12 -0700 (PDT)
From:      Cameron Slye <cslye@info.infosite.com>
To:        freebsd-hackers@freebsd.org
Subject:   serial errors
Message-ID:  <199605080602.XAA25101@info.infosite.com>

next in thread | raw e-mail | index | archive | help
Seem to be getting these errors with some software we are tring to use... 
It is using the port at 115200, and I have set the speed of the device to
115200 and still seems to happen... This is on a p133 with 32mb, doing
nothing else.  So I don't think IO is a problem.  Any ideas ?
And I have pages of these errors...  TIA.


May  4 06:51:38 nfs1 /kernel: sio0 at 0x3f8-0x3ff irq 4 on isa
May  4 06:51:38 nfs1 /kernel: sio0: type 16550A
May  4 06:51:38 nfs1 /kernel: sio1 at 0x2f8-0x2ff irq 3 on isa
May  4 06:51:39 nfs1 /kernel: sio1: type 16550A

May  7 15:41:59 nfs1 /kernel: sio0: 168 more tty-level buffer overflows (total 43853)
May  7 15:45:21 nfs1 /kernel: sio0: 3051 more tty-level buffer overflows (total 46904)
May  7 15:45:37 nfs1 /kernel: sio0: 184 more tty-level buffer overflows (total 47088)
May  7 15:45:47 nfs1 /kernel: sio0: 72 more tty-level buffer overflows (total 47160)


This is the code of the software I am working with...
It compiles cleanly

/*
TODO:  handle frame length changing occasionally.
*/



/*
  Receive frames from PageSat HS satellite transmissions.
  Mark Lottor, November 1995.

  usage: psfrx [-v]

  -v will put it in visual frame display mode
     it will output status characters as frames come in,
     as follows.
       s   [re]syncing
       .   got a good frame
       c   got a frame with crc error
       l   lost a frame
       #   got a whole block
     nothing will be saved to disk. count of good vs bad frames
     will be displayed after each block.

  Data is read from a tty port, deframed and CRC'd.  
  Complete blocks of frames are written to disk for later processing.

  The TTY port and PageSat receiver must run be set at 115,200 baud.
  Data is 8 bits and there is no flow control.
*/

#define FALSE        0
#define TRUE         1

/* select an OS */
#define BSDI   TRUE
#define SUNOS  FALSE
#define SVR4   FALSE
#define LINUX  FALSE

/* set your local path names */
#define LOG_DIR      "/common/pagesat/log"
#define OUTPUT_PATH  "/common/pagesat/data"
#define TTY          "/dev/cuaa0"

#include <stdio.h>
#include <string.h>
#if SVR4
#include <termio.h>
#endif
#if (BSDI || SUNOS || LINUX)
#include <termios.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#if BSDI
#include <sys/ioctl.h>
#endif
#include <time.h>
#include <sys/time.h>
#include <sys/fcntl.h>

typedef unsigned char byte;
typedef unsigned long ulg;

#define VMINCHARS          128	 /* wait for N chars on a read (<256)*/

/* framing protocol constants */
#define FRAMEFLAG1         0x0a5
#define FRAMEFLAG2         0x5a
#define FRAMETYPE          0x01   /* pagesat news batches */
#define DATAFRAMESPERBLOCK 240
#define MAXFRAMELEN        246

int flentable[4] = { 62, 122, 242, 482 };  /* will not use 482 */
ulg updcrc();
ulg crc_32_tab[];
int interframelen = 0;
int framelen = 0;

#define BIGBUF_LEN   32768
#define MAX_READ_LEN  8192
#define MAX_LAST     (BIGBUF_LEN - (MAX_READ_LEN + MAXFRAMELEN + 2))

/* set TRUE for debugging output */
int debug = FALSE;
int monitor = FALSE;  /* set with -v flag to monitor frames*/

#if (SUNOS || LINUX)
#define TIOCGETA TCGETS
#define TIOCSETA TCSETS
#endif

#if SVR4
#define TIOCGETA TCGETA
#define TIOCSETA TCSETA
#endif

int port;

byte bigbuf[BIGBUF_LEN];
long bb_size, bb_write, bb_last;
long bb_read, bb_header;

struct frameinfo {
  byte *ptr;
  int lenflag;
  int len;
  int type;
  int count;
  ulg crc;
};
struct frameinfo f;

FILE *logp;
int last_day = -1;
char logname[256];

/* statistic counters */
long bytes_seen, total_frames_lost, last_total_frame_count;
long total_frame_count, total_frame_errors, total_frames_unwanted;
long total_block_count;

main(argc,argv)
  int argc;
  char *argv[];
{
  int i;

  if (argc > 1)
    if (!strcmp(argv[1],"-v"))
      monitor = TRUE;

  /* detach from terminal if not debugging */
  if ((!debug) && (!monitor))
  {
    if (fork())
      exit(0);
    for (i = 10; i >= 0; i--)
      (void) close(i);
    (void) open("/dev/null", O_RDONLY);
    (void) dup2(0, 1);
    (void) dup2(0, 2);
    i = open("/dev/tty", O_RDWR);
    if (i > 0)
    {
      (void) ioctl(i, TIOCNOTTY, (char *)NULL);
      (void) close(i);
    }
  }

  umask(002);
  open_tty_port(TTY);
  init_bigbuf();
  logp = NULL;
  for (;;)
  {
    new_log_file();		/* if needed */
    if (rx_data())
      process_data();
  }  
  close_tty_port();
  exit(0);
}

/* if day is over, close log file and create a new one */
new_log_file()
{
  time_t now;
  struct tm *tms;

  now = time(NULL);
  tms = localtime(&now);
  if (tms->tm_yday == last_day)
    return;
  last_day = tms->tm_yday;

  if (logp != NULL)
  {
    report_stats();
    fclose(logp);
  }
  sprintf(logname,"%s/psfrx.%04d%02d%02d",LOG_DIR,
	    1900+tms->tm_year,1+tms->tm_mon,tms->tm_mday);
  if ((logp = fopen(logname,"a")) == NULL)
  {
    fprintf(stderr,"psfrx: can't open logfile %s\n",logname);
    exit(1);
  }
}

/* dump statistics to log file */
report_stats()
{
  fprintf(logp,"\nEnd of day statistics:\n");
  fprintf(logp,"Total bytes  received: %d\n",bytes_seen);
  fprintf(logp,"Total frames received: %d\n",total_frame_count);
  fprintf(logp,"      unwanted frames: %d\n",total_frames_unwanted);
  fprintf(logp,"     bad (crc) frames: %d\n",total_frame_errors);
  fprintf(logp,"          lost frames: %d\n",total_frames_lost);
  fprintf(logp,"           error rate: %.6f\n",
	  ((float) total_frame_errors / (float) total_frame_count));
  fprintf(logp,"Total blocks received: %d\n",total_block_count);

  bytes_seen            = 0;
  total_frame_count     = 0;
  total_frame_errors    = 0;
  total_frames_unwanted = 0;
  total_frames_lost     = 0;
  total_block_count     = 0;
}

/* initialize receive buffer pointers */
init_bigbuf()
{
  bb_size   = 0;
  bb_write  = 0;
  bb_read   = 0;
  bb_header = 0;
  bb_last   = MAX_LAST;
}

/* get stuff from tty port, add to bigbuf */
rx_data()
{
  int len;
  fd_set ttyfdset;
  struct timeval ttytout;

  ttytout.tv_sec =  1;
  ttytout.tv_usec = 0;
  FD_ZERO(&ttyfdset);
  FD_SET(port,&ttyfdset);
  if (select(FD_SETSIZE,&ttyfdset,NULL,NULL,&ttytout) <= 0)
    return(FALSE);
  len = read(port,bigbuf+bb_write,MAX_READ_LEN);
  if (len <= 0) return(FALSE);

  bytes_seen +=len;
  bb_write += len;
  if (bb_write >= MAX_LAST)
  {
    bb_last = bb_write - 1;
    bb_write = 0;
  }
  bb_size += len;
  if (debug)
    printf("read %d bytes (write %06d, last %06d read %06d size %06d)\n",
           len,bb_write,bb_last,bb_read,bb_size);
  return(TRUE);
}

/* process any received data */
process_data()
{
  int extended = FALSE;

  /* is there at least a frame worth? */
  while (bb_size >= (MAXFRAMELEN + 4))
  {
    if (monitor) fflush(stdout);

    /* make sure we don't read past buffer */
    if ((bb_read + MAXFRAMELEN + 4) >= bb_last)
    {
      if (!extended)
      {
	memcpy(bigbuf+bb_last+1,bigbuf,MAXFRAMELEN+3);
      }
      extended = TRUE;
    }
      
    /* is there a good frame? */
    if (isvalidframe(bigbuf+bb_read))
    {
      save_frame();
      if (monitor) putchar('.');
      /* update pointers for next frame */
      bb_size -= interframelen;
      bb_read += interframelen;
      if (bb_read > bb_last)
      {
	bb_read = bb_read - bb_last - 1;
	extended = FALSE;
      }
      continue;
    }

    /* otherwise find possible start of a frame */
    if (monitor) putchar('s');
    while (bb_size >= (MAXFRAMELEN + 4))
    {
      bb_size--;
      bb_read++;
      if (bb_read > bb_last)
      {
	bb_read = 0;
	extended = FALSE;
      }

      if (bigbuf[bb_read] == FRAMEFLAG1)
	break;
    }
  }
}

/* decode a frame and return TRUE if valid */
isvalidframe(ptr)
  byte *ptr;
{
  ulg crc;

  if (*ptr                   != FRAMEFLAG1) return(FALSE);
  if (*(ptr+1)               != FRAMEFLAG2) return(FALSE);
  f.ptr = ptr + 2;
  f.lenflag = (*(ptr+2) & 0xc0) >> 6;
  f.len = flentable[f.lenflag];
  f.type = *(ptr+2) & 0x3f;
  f.count = *(ptr+3);
  if (interframelen == 0)
    interframelen = 2+ f.len + 4;
  if (*(ptr+interframelen)   != FRAMEFLAG1) return(FALSE);
  if (*(ptr+interframelen+1) != FRAMEFLAG2) return(FALSE);
  total_frame_count++;
  f.crc = (((long) *(ptr+interframelen-4)) << 24) +
          (((long) *(ptr+interframelen-3)) << 16) +
          (((long) *(ptr+interframelen-2)) << 8) +
           ((long) *(ptr+interframelen-1));
  crc = updcrc(f.ptr,f.len);
  if (debug) printf("frame type %d, len %d, count %d, crc %08x (%08x)\n",
		    f.type,f.len,f.count,f.crc,crc);
  if (crc != f.crc) 
  {
    if (monitor) putchar('c');
    total_frame_errors++;
    return(FALSE);
  }
  return(TRUE);
}

/* return next file number to use */
long nextfilecount()
{
  char fname[256];
  FILE *fp;
  long num;

  sprintf(fname,"%s/fcount",OUTPUT_PATH);
  if ((fp = fopen(fname,"r+")) == NULL)
  {
    if ((fp = fopen(fname,"w")) == NULL)
    {
      fprintf(stderr,"psfrx: can't create output file %s\n",fname);
      exit(1);
    }
    fprintf(fp,"0\n");
    rewind(fp);
  }
  if (fscanf(fp,"%d",&num) != 1)
  {
    fclose(fp);
    return((long) 0);
  }
  num++;
  rewind(fp);
  fprintf(fp,"%d\n",num);
  fclose(fp);
  return(num);
}

/* save the frame to disk, creating a new file for each block */
save_frame()
{
  int i, lost;
  static FILE *ofp = NULL;
  static lastframecount = 256;
  char fname[256], tname[256];

  /* is it something we want? */
  if (f.type != FRAMETYPE)
  {
    total_frames_unwanted++;
    return;
  }

  /* count (most) lost frames */
  if (f.count > 0)
    if (f.count != (lastframecount+1))
    {
      lost = f.count - lastframecount - 1;
      if (lost < 0) lost = 1;
      total_frames_lost += lost;
      for (i = 0; i < lost; i++)
	putchar('l');
    }

  /* if new block, need new file */
  if (f.count <= lastframecount)
  {
    if (monitor)
    {
      printf("# (%d/%d frames, %d crc, %d lost)",
	     (total_frame_count-last_total_frame_count),total_frame_count,
	     total_frame_errors,total_frames_lost);
      last_total_frame_count = total_frame_count;
      fflush(stdout);
    }

    if (ofp != NULL)
    {
      fclose(ofp);
      ofp = NULL;
      sprintf(tname,"%s/tmp",OUTPUT_PATH);
      sprintf(fname,"%s/%08d",OUTPUT_PATH,nextfilecount());
      rename(tname,fname);
      total_block_count++;
    }

    sprintf(tname,"%s/tmp",OUTPUT_PATH);
    if ((ofp = fopen(tname,"w")) == NULL)
    {
      fprintf(stderr,"psfrx: can't create output file %s\n",tname);
      return;
    }
  }

  fwrite(f.ptr,f.len,1,ofp);
  lastframecount = f.count;
}


int open_tty_port(portname)
  char *portname;
{
  struct termios tio;
  int bps;

  if (debug) printf("trying_tty(%s)...\n",portname);
  if ((port = open(portname,O_RDONLY)) < 0) 
  {
    fprintf(stderr,"psfrx: can't open port %s\n",portname);
    exit(1);
  }

#if (BSDI || SVR4)
  if (fcntl(port,O_NONBLOCK,0) == -1)
#endif
#if SUNOS
  if (fcntl(port,O_NDELAY,0) == -1)
#endif
#if LINUX
  if (fcntl(port,F_SETFL,O_NONBLOCK) == -1)
#endif
  {
    fprintf(stderr,"psfrx: can't set port for non-blocking i/o\n");
    exit(1);
  }

  if (ioctl(port, TIOCGETA, &tio) == -1)
  {
    fprintf(stderr,"psfrx: can't get port settings\n");
    exit(1);
  }

  tio.c_cflag = (CS8 | CREAD | CLOCAL);
#if BSDI
  tio.c_ispeed = B115200;
  tio.c_ospeed = tio.c_ispeed;
#endif
#if (SVR4 || LINUX)
  tio.c_cflag |= B115200;
#endif
#if SUNOS
  tio.c_cflag |= B38400;
#endif
  tio.c_iflag = 0;
  tio.c_oflag = 0;
  tio.c_lflag = 0;
 
  tio.c_cc[VMIN]  = VMINCHARS;	/* wait for VMINCHARS chars on a read */
  tio.c_cc[VTIME] = 10;		/* wait up to 1.0 seconds */
			
  if (ioctl(port, TIOCSETA, &tio) == -1)
  {
    fprintf(stderr,"psfrx: can't set port settings\n");
    exit(1);
  }
#if ANTARES
  bps = 115200;
  if (ioctl(port, AZS_SPEED_SET, &bps) == -1)
    {
    fprintf(stderr,"txuplink: can't set azs port speed\n");
    exit(1);
  }
#endif
  if (debug) printf("opened_tty(%s)\n",portname);
}

close_tty_port()
{
  close(port);
}


/* CRC-32 routines stolen from gzip */

/* ===========================================================================
 * Run a set of bytes through the crc shift register. 
 * Return the current crc.
 */
ulg updcrc(s, n)
    unsigned char *s;       /* pointer to bytes to pump through */
    unsigned n;             /* number of bytes in s[] */
{
    register ulg c;         /* temporary variable */

    ulg crc = (ulg)0xffffffffL; /* shift register contents */

    c = crc;
    if (n) do {
      c = crc_32_tab[((int)c ^ (*s++)) & 0xff] ^ (c >> 8);
    } while (--n);

    return c ^ 0xffffffffL;       /* (instead of ~c for 64-bit machines) */
}

/* ========================================================================
 * Table of CRC-32's of all single-byte values (made by makecrc.c)
 */
ulg crc_32_tab[] = {
  0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
  0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
  0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
  0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
  0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
  0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
  0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
  0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
  0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
  0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
  0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
  0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
  0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
  0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
  0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
  0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
  0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
  0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
  0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
  0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
  0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
  0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
  0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
  0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
  0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
  0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
  0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
  0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
  0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
  0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
  0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
  0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
  0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
  0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
  0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
  0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
  0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
  0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
  0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
  0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
  0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
  0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
  0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
  0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
  0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
  0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
  0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
  0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
  0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
  0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
  0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
  0x2d02ef8dL
};



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199605080602.XAA25101>