reg.c 1.94 KB
#include <sys/types.h>
#ifdef __sgi__
#include <sys/sbd.h>
#endif
#include <sys/stat.h>
#include <sys/mman.h>
#ifdef __sgi__
#include <sys/sema.h>
#endif
#include <netinet/in.h>

#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <getopt.h>

#include "diag.h"
#include "dbg_comm.h"


int 
dgReg(struct diagcomm *pcomm)
{
  int c;
  static unsigned int address, data;
  int no_args = 1;

  extern char *optarg;
  extern int optind;

  while ((c = getopt(pGlobalComm->argc, pGlobalComm->argv, "ia:d:rwv:p:g"))!=EOF) {
    switch(c) {

    case 'i':
      if (dgInitComm()) return 1;
      no_args = 0;
      break;

    case 'a':
      address = atoi(optarg);
      no_args = 0;
      break;

    case 'd':
      data = atoi(optarg);
      no_args = 0;
      break;

    case 'r':
      if (dgInitialize) {
	if (dgInitComm()) return 1;
      }
      dgReadWord(address, &data);
      printf("read  address = 0x%08x, data = 0x%08x\n", address, data);
      no_args = 0;
      break;

    case 'w':
      if (dgInitialize) {
	if (dgInitComm()) return 1;
      }
      dgWriteWord(address, data);
      printf("write address = 0x%08x, data = 0x%08x\n", address, data);
      no_args = 0;
      break;

    case 'v':
      dgEnableVideo(address, atoi(optarg));
      break;

    case 'p':
      address = 0x80000000;
      data = atoi(optarg);

      if (dgInitialize) {
        if (dgInitComm()) return 1;
      }
      dgWriteWord(address, data);
      printf("write address = 0x%08x, data = 0x%08x\n", address, data);
      no_args = 0;
      break;

    case 'g':
      address = 0x80000000;

      if (dgInitialize) {
        if (dgInitComm()) return 1;
      }
      dgReadWord(address, &data);
      printf("read  address = 0x%08x, data = 0x%08x\n", address, data);
      no_args = 0;
      break;

    default:
      return(0);
      break;
    }
  }

  if (no_args) {
    printf("address = 0x%08x, data = 0x%08x\n", address, data);
  }
  return(0);
}