Esempio n. 1
0
static int r9701_get_datetime(struct device *dev, struct rtc_time *dt)
{
	int ret;
	unsigned char buf[] = { RSECCNT, RMINCNT, RHRCNT,
				RDAYCNT, RMONCNT, RYRCNT };

	ret = read_regs(dev, buf, ARRAY_SIZE(buf));
	if (ret)
		return ret;

	memset(dt, 0, sizeof(*dt));

	dt->tm_sec = bcd2bin(buf[0]); /* RSECCNT */
	dt->tm_min = bcd2bin(buf[1]); /* RMINCNT */
	dt->tm_hour = bcd2bin(buf[2]); /* RHRCNT */

	dt->tm_mday = bcd2bin(buf[3]); /* RDAYCNT */
	dt->tm_mon = bcd2bin(buf[4]) - 1; /* RMONCNT */
	dt->tm_year = bcd2bin(buf[5]) + 100; /* RYRCNT */

	/* the rtc device may contain illegal values on power up
	 * according to the data sheet. make sure they are valid.
	 */

	return rtc_valid_tm(dt);
}
Esempio n. 2
0
static int stop(struct file *filp)
{
   int ret;

   ret = bcm_drv_unlocked_ioctl(filp, BCMPH_IOCTL_STOP, 0);

   if (!ret) {
      read_regs(filp);
   }
   else {
      fprintf(stderr, "Error stopping.\n");
   }

   return (ret);
}
Esempio n. 3
0
int init( FILE * pFile )
{
  int i;

  instcount = 0;
  WB = EMPTY;
  WB_count = 0;
  MEM3 = EMPTY;
  MEM3_count = 0;
  MEM2 = EMPTY;
  MEM2_count = 0;
  MEM1 = EMPTY;
  MEM1_count = 0;
  EX = EMPTY;
  EX_count = 0;
  ID = EMPTY;
  ID_count = 0;
  IF2 = EMPTY;
  IF2_count = 0;
  IF1 = EMPTY;
  IF1_count = 1;
  inst_counter = 0;
  flush = FALSE;
  cycle = 1;
  inst_cycle = 1;
  
  IF1_stall  = IF2_stall = ID_stall = EX_stall = MEM1_stall = MEM2_stall = MEM3_stall = WB_stall = NOSTALL;
  
 /* init the registers and memory file */
  for( i = 0; i < NUMREGS; ++i )
    Registers[i] = 0;
  for( i = 0; i < MEMSZ; ++i )
    Memory[i] = 0;
  for( i = 0; i < MAXINST; ++i )
    Instructions[i] = NULL;

  if( read_regs( pFile ) ) return 1;
  if( read_mem( pFile ) ) return 1;
  if( read_insts( pFile ) ) return 1;

  if( instcount == 0 ) return 1;

  return 0;
}
Esempio n. 4
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);


    QObject::connect(&mb,  SIGNAL(error(QModBus::ModBusError)),
                     this, SLOT(process_error(QModBus::ModBusError)));



    QObject::connect(&mb,  SIGNAL(connected()),
                     this, SLOT(change_status()));

    QObject::connect(&mb,  SIGNAL(disconnected()),
                     this, SLOT(change_status()));



    QObject::connect(ui->connect_button, SIGNAL(clicked()),
                     this,  SLOT(connect_btn_clicked()));



    //read button
    QObject::connect(ui->rd_button, SIGNAL(clicked()),
                     this, SLOT(read_regs()));


    QObject::connect(&mb,  SIGNAL(response_to_read_regs(int)),
                     this, SLOT(response_to_read_regs(int)));



    //write button
    QObject::connect(ui->wr_button, SIGNAL(clicked()),
                     this, SLOT(write_reg()));


    QObject::connect(&mb,  SIGNAL(response_to_write_reg(int)),
                     this, SLOT(response_to_write_reg(int)));
}
Esempio n. 5
0
void
output_ioctl(int nr)
{
	struct syscall_regs r;
	read_regs(r);
	int fd = r.ebx;
	int cmd = r.ecx;
	int arg = r.edx;
	printf("ioctl:\t fd=%d, cmd=0x%x, arg=0x%x\n",
			fd, cmd, arg);

	switch (_IOC_TYPE(cmd)) {
		case 'T':
			return output_tty_ioctl(fd, cmd, arg);
		case 0x12:
			return output_blk_ioctl(fd, cmd, arg);
		default:
			INJ_ERROR("no such ioctl command: 0x%x\n", cmd);
			__exit(-1);
	}
}
Esempio n. 6
0
static int __devinit r9701_probe(struct spi_device *spi)
{
	struct rtc_device *rtc;
	unsigned char tmp;
	int res;

	tmp = R100CNT;
	res = read_regs(&spi->dev, &tmp, 1);
	if (res || tmp != 0x20) {
		dev_err(&spi->dev, "cannot read RTC register\n");
		return -ENODEV;
	}

	rtc = rtc_device_register("r9701",
				&spi->dev, &r9701_rtc_ops, THIS_MODULE);
	if (IS_ERR(rtc))
		return PTR_ERR(rtc);

	dev_set_drvdata(&spi->dev, rtc);

	return 0;
}
Esempio n. 7
0
////////////////////////////////////////////////////////////////////////////////
// Functions
////////////////////////////////////////////////////////////////////////////////
static int vga_generic_set_mode(vgageneric_handle_t *dev, int width, int height, int bpp)
{
	dev->regs = malloc(128);
	read_regs(dev->regs);

	write_regs(g_640x480x16);

	dev->mem0 = malloc(128*1024);
	dev->mem1 = malloc(128*1024);
	dev->mem2 = malloc(128*1024);
	dev->mem3 = malloc(128*1024);

	set_plane(0);
	memcpy(dev->mem0, 0xC00A0000, 128*1024);
	set_plane(1);
	memcpy(dev->mem1, 0xC00A0000, 128*1024);
	set_plane(2);
	memcpy(dev->mem2, 0xC00A0000, 128*1024);
	set_plane(3);	
	memcpy(dev->mem3, 0xC00A0000, 128*1024);

	return 1;
}
Esempio n. 8
0
static int test_loopback(void)
{
   int ret = 0;

   ret = bcm_drv_init();

   if (!ret) {
      struct file fil;
      fil.private_data = NULL;

      do { // Empty loop
         size_t todo;
         size_t delay;
         size_t total_done_tx;
         size_t done_tx;
         size_t done_rx;
         ssize_t len;

         // Open device
         ret = bcm_drv_open(NULL, &(fil));
         if (ret) {
            fprintf(stderr, "Error opening device.\n");
            break;
         }
         fil.f_flags = O_RDWR | O_NONBLOCK;

         read_regs(&(fil));

         for (done_tx = 0; (done_tx < sizeof(buf_tx)); done_tx += 1) {
            buf_tx[done_tx] = (__u8)(done_tx);
         }
         memset(buf_rx, 0, sizeof(buf_rx));

         // We configure
         ret = start(&(fil));
         if (ret) {
            break;
         }

         // We fill TX buffers before starting PCM
         total_done_tx = 0;
         done_tx = 0;
         todo = sizeof(buf_tx) - done_tx;
         len = bcm_drv_write(&(fil), (const char *)(&(buf_tx[done_tx])), todo, NULL);
         if (len < 0) {
            if (-EAGAIN != len) {
               fprintf(stderr, "Error writing to the device.\n");
               break;
            }
         }
         else {
            total_done_tx += len;
            done_tx += len;
         }

         // Then we start PCM
         ret = start_pcm(&(fil));
         if (ret) {
            break;
         }

         ret = set_line_mode(&(fil), 0, BCMPH_MODE_OFF_TALKING);
         if (ret) {
            break;
         }

         done_rx = 0;
         delay = 0;
         while (done_rx < sizeof(buf_rx)) {
            int pause = 1;
            todo = sizeof(buf_rx) - done_rx;
            len = bcm_drv_read(&(fil), (char *)(&(buf_rx[done_rx])), todo, NULL);
            if (len < 0) {
               if (-EAGAIN != len) {
                  fprintf(stderr, "Error reading from the device.\n");
                  break;
               }
            }
            else if (len > 0) {
               done_rx += len;
               pause = 0;
            }

            if (done_tx >= sizeof(buf_tx)) {
               done_tx = 0;
            }
            todo = sizeof(buf_tx) - done_tx;
            len = bcm_drv_write(&(fil), (const char *)(&(buf_tx[done_tx])), todo, NULL);
            if (len < 0) {
               if (-EAGAIN != len) {
                  fprintf(stderr, "Error writing to the device.\n");
                  break;
               }
            }
            else if (len > 0) {
               total_done_tx += len;
               done_tx += len;
               pause = 0;
            }
            if (pause) {
               delay += 1;
               usleep(10000);
               if (delay > 100) {
                  delay = 0;
                  fprintf(stdout, "%lu bytes written and %lu bytes read...\n", (unsigned long)(total_done_tx), (unsigned long)(done_rx));
               }
            }
         }
         fprintf(stdout, "%ld bytes written to the device\n", (long)(total_done_tx));

         sleep(3);

         // We stop PCM
         stop_pcm(&(fil));

         // We read remaining bytes
         todo = sizeof(buf_rx) - done_rx;
         len = bcm_drv_read(&(fil), (char *)(&(buf_rx[done_rx])), todo, NULL);
         if (len < 0) {
            if (-EAGAIN != len) {
               fprintf(stderr, "Error reading from the device.\n");
               break;
            }
         }
         done_rx += len;

         // We stop
         stop(&(fil));

         // Dump the buffer received
         dump_buf("Bytes received", buf_rx, done_rx);

         read_stats(&(fil));

         for (todo = 0; ((todo < done_tx) && (todo < done_rx)); todo += 1) {
            if (buf_tx[todo] != buf_rx[todo]) {
               break;
            }
         }
         if ((todo >= done_tx) || (todo >= done_rx)) {
            fprintf(stdout, "Bytes received are the same as those sent.\n");
         }
         else {
            fprintf(stdout, "Byte %lu received differ from the one sent : %x vs %x.\n", (unsigned long)(todo), (unsigned int)(buf_rx[todo]), (unsigned int)(buf_tx[todo]));
         }
      } while (0);

      if (NULL != fil.private_data) {
         bcm_drv_release(NULL, &(fil));
         fil.private_data = NULL;
      }

      bcm_drv_exit();
   }

   return (ret);
}
Esempio n. 9
0
int main(int argc,char *argv[]) {

char *cp, *ep;
char host[49];
char tmpb[CMD_BUF_SIZE];

   printf("vmeiotest: See <news> command\n");
   printf("vmeiotest: Type h for help\n");

   pname = argv[0];
   printf("%s: Compiled %s %s\n",pname,__DATE__,__TIME__);

   bzero((void *) host,49);
   gethostname(host,48);

   if (argc > 1)
      strcat(dev_name,argv[1]);
   else
      strcat(dev_name,"vmeio");

   if ((vmeio[lun] = __vsl_open_name(lun,dev_name)) == NULL) {
      printf("Warning: Can't open support library\n");
      perror(DRV_NAME);
      exit(1);
   }

   memlen = 1024;
   mem = malloc(memlen);
   get_window_parameters(lun);
   read_regs(dev_name);

   while (True) {

      cmdbuf = &(history[cmdindx][0]);
      if (strlen(cmdbuf)) printf("{%s} ",cmdbuf);
      fflush(stdout);

      if (vmeio) sprintf(prompt,"%s:%s[%02d]",host,dev_name,cmdindx+1);
      else     sprintf(prompt,"%s:NoDriver:Vmeio[%02d]",host,cmdindx+1);
      printf("%s",prompt);

      bzero((void *) tmpb,CMD_BUF_SIZE);
      if (fgets(tmpb,CMD_BUF_SIZE,stdin)==NULL) exit(1);

      cp = tmpb;
      if (*cp == '!') {
	 cmdindx = strtoul(++cp,&ep,0) -1;
	 cp = ep;
	 if (cmdindx >= HISTORIES) cmdindx = 0;
	 cmdbuf = &(history[cmdindx][0]);
	 continue;
      } else if (*cp == '.') {
	 printf("Execute:%s\n",cmdbuf); fflush(stdout);
      } else if ((*cp == '\n') || (*cp == '\0')) {
	 cmdindx++;
	 if (cmdindx >= HISTORIES) { printf("\n"); cmdindx = 0; }
	 cmdbuf = &(history[cmdindx][0]);
	 continue;
      } else if (*cp == '?') {
	 printf("History:\n");
	 printf("\t!<1..24> Goto command\n");
	 printf("\tCR       Goto next command\n");
	 printf("\t.        Execute current command\n");
	 printf("\this      Show command history\n");
	 continue;
      } else {
	 cmdindx++; if (cmdindx >= HISTORIES) { printf("\n"); cmdindx = 0; }
	 strcpy(cmdbuf,tmpb);
      }
      bzero((void *) val_bufs,sizeof(val_bufs));
      GetAtoms(cmdbuf);
      DoCmd(0);
   }
}
Esempio n. 10
0
static const struct rtc_class_ops r9701_rtc_ops = {
	.read_time	= r9701_get_datetime,
	.set_time	= r9701_set_datetime,
};

static int __devinit r9701_probe(struct spi_device *spi)
{
	struct rtc_device *rtc;
<<<<<<< HEAD
<<<<<<< HEAD
	struct rtc_time dt;
	unsigned char tmp;
	int res;

	tmp = R100CNT;
	res = read_regs(&spi->dev, &tmp, 1);
	if (res || tmp != 0x20) {
		dev_err(&spi->dev, "cannot read RTC register\n");
		return -ENODEV;
	}

	/*
	 * The device seems to be present. Now check if the registers
	 * contain invalid values. If so, try to write a default date:
	 * 2000/1/1 00:00:00
	 */
	r9701_get_datetime(&spi->dev, &dt);
	if (rtc_valid_tm(&dt)) {
		dev_info(&spi->dev, "trying to repair invalid date/time\n");
		dt.tm_sec  = 0;
		dt.tm_min  = 0;