Exemplo n.º 1
0
int ec727___init(struct descriptor *niddsc, InInitStruct *setup)
{
  int status;
  pio(24,0)
  pio(25,15)
  return status;
}
Exemplo n.º 2
0
int l2415___store(struct descriptor *niddsc, InStoreStruct *setup)
{
  static int polarity_nid;
  static int range_nid;
  static int volt_out_nid;
  static int curr_out_nid;
  static DESCRIPTOR_NID(polarity_dsc,&polarity_nid);
  static DESCRIPTOR_NID(range_dsc,&range_nid);
  static struct descriptor_xd out_xd = {0, DTYPE_DSC, CLASS_XD, 0, 0};
  int status=1;
  static short voltage;
  static struct descriptor voltage_dsc = {sizeof(short), DTYPE_W, CLASS_S, (char *)&voltage};
  static DESCRIPTOR(volt_expr, "BUILD_WITH_UNITS($ * $ * ($ == 3500. ? 1. : 2.), 'Volts')");
  static short current;
  static struct descriptor current_dsc = {sizeof(short), DTYPE_W, CLASS_S, (char *)&current};
  static DESCRIPTOR(current_expr, "BUILD_WITH_UNITS($ * ( $ == 3500. ? .0025/4096. : .001/4096.) , 'Amps')");
  polarity_nid = setup->head_nid + L2415_N_POLARITY;
  range_nid = setup->head_nid + L2415_N_RANGE;
  pio(26,0,0);   /* convert output voltage to digital */
  qrep(0,0,1,&voltage); /* read it when we get q back */
  TdiCompile(&volt_expr, &voltage_dsc, &polarity_dsc, &range_dsc, &out_xd MDS_END_ARG);
  volt_out_nid = setup->head_nid + L2415_N_VOLT_OUT;
  return_on_error(TreePutRecord(volt_out_nid, (struct descriptor *)&out_xd, 0), status);
  pio(26,1,0);   /* convert output current to digital */
  qrep(0,0,1,&current); /* read it when we get q back */
  TdiCompile(&current_expr, &current_dsc, &range_dsc, &out_xd MDS_END_ARG);
  curr_out_nid = setup->head_nid + L2415_N_CURR_OUT;
  return_on_error(TreePutRecord(curr_out_nid, (struct descriptor *)&out_xd, 0), status);
  /* turn it off */
/*
  pio(16,0,0)
  pio(16,1,0)
*/
  return 1;
}
Exemplo n.º 3
0
int
comclose(dev_t dev, int flag, int mode, struct lwp *l)
{
	struct com_softc *sc = device_lookup_private(&xcom_cd, COMUNIT(dev));
	struct tty *tp = sc->sc_tty;
	int iobase = sc->sc_iobase;
	int s;

	/* XXX This is for cons.c. */
	if (!ISSET(tp->t_state, TS_ISOPEN))
		return 0;

	(*tp->t_linesw->l_close)(tp, flag);
	s = spltty();
	CLR(sc->sc_lcr, LCR_SBREAK);
	outb(pio(iobase , com_lcr), sc->sc_lcr);
	outb(pio(iobase , com_ier), 0);
	if (ISSET(tp->t_cflag, HUPCL) &&
	    !ISSET(sc->sc_swflags, COM_SW_SOFTCAR)) {
		/* XXX perhaps only clear DTR */
		outb(pio(iobase , com_mcr), 0);
	}
	CLR(tp->t_state, TS_BUSY | TS_FLUSH);
	if (--comsopen == 0)
		callout_stop(&com_poll_ch);
	splx(s);
	ttyclose(tp);
#ifdef notyet /* XXXX */
	if (unit != comconsole) {
		ttyfree(tp);
		sc->sc_tty = 0;
	}
#endif
	return 0;
}
Exemplo n.º 4
0
int l2256___init(struct descriptor *niddsc, InInitStruct *setup)
{
  int status;
  pio(9,0)
  pio(26,0)
  return status;
}
Exemplo n.º 5
0
int l8590___store(struct descriptor_s *niddsc_ptr, InStoreStruct *setup)
{
  int samples = 0;
  int status;
  static DESCRIPTOR_A_BOUNDS(raw,sizeof(unsigned short),DTYPE_WU,0,1,0);
  static DESCRIPTOR(counts_str,"counts");
  static DESCRIPTOR_WITH_UNITS(counts,&raw,&counts_str);
  static int latch_nid;
  static DESCRIPTOR_NID(latch,&latch_nid);
  static FUNCTION(1) value = {2,DTYPE_FUNCTION,CLASS_R,(unsigned char *)&OpcValue,0,0};
  static DESCRIPTOR_SIGNAL_1(signal,&value,&counts,&latch);
  latch_nid = setup->head_nid + L8590_N_LATCH;
  pio(setup->name,2,0,&samples);
  if (samples > 32766)
  {
    printf("Got large sample count from L8590: %s --- %d\n",setup->name,samples);
    samples=32766;
  }
  if (samples)
  {
    int samps_per_chan = samples/setup->num_active;
    unsigned short *values = calloc(samples * 2,sizeof(*values));
    unsigned short *cdata = values + samples;
    int chan;
    int i;
    int min_idx = 0;
    int max_idx = samps_per_chan - 1;
    pio(setup->mem_cts_name,19,0,&zero);
    pio(setup->mem_cts_name,18,0,&zero);
    pio(setup->mem_cts_name,25,0,0);
    pio(setup->mem_cts_name,2,0,&values[0]);
    stop(setup->mem_cts_name,2,0,samples,values);
    for (i=0;i<samples;i++) cdata[i/setup->num_active + (i % setup->num_active) * samps_per_chan] = values[i];
    for (chan=0;chan<setup->num_active;chan++)
    {
      int data_nid = setup->head_nid+L8590_N_INPUT_1+(L8590_N_INPUT_2 - L8590_N_INPUT_1)*chan;
      int start_nid = data_nid + L8590_N_INPUT_1_STARTIDX - L8590_N_INPUT_1;
      int end_nid = data_nid + L8590_N_INPUT_1_ENDIDX - L8590_N_INPUT_1;
      if (TreeIsOn(data_nid) & 1) {
        status = DevLong(&start_nid,(int *)&raw.bounds[0].l);
        if (status&1) raw.bounds[0].l = min(max_idx,max(min_idx,raw.bounds[0].l));
        else raw.bounds[0].l = min_idx;

        status = DevLong(&end_nid, (int *)&raw.bounds[0].u);
        if (status&1) raw.bounds[0].u = min(max_idx,max(min_idx,raw.bounds[0].u));
        else raw.bounds[0].u = max_idx;
        raw.m[0] = raw.bounds[0].u - raw.bounds[0].l + 1;
        if (raw.m[0] > 0)
        {
          raw.pointer = (char *)(cdata + chan * samps_per_chan + raw.bounds[0].l);
          raw.a0 = raw.pointer - raw.bounds[0].l * sizeof(*cdata);
          raw.arsize = raw.m[0] * 2;
          status = TreePutRecord(data_nid,(struct descriptor *)&signal,0);
        }
      }
    }
    free(values);
  }
  return status;
}
Exemplo n.º 6
0
int joerger_adcp___store(struct descriptor *nid_dsc, InStoreStruct *setup)
{
  int status;
  int chan;
  static int c_nids[JOERGER_ADCP_K_CONG_NODES];
  static DESCRIPTOR(output_expr, "$*$");
  static short int buffer[16];
  static DESCRIPTOR_A(buffer_dsc, sizeof(short int), DTYPE_W, &buffer, sizeof(buffer));
  static float coef;
  static DESCRIPTOR_FLOAT(coef_dsc, &coef);
  static struct descriptor_xd output_xd = {0, DTYPE_DSC, CLASS_XD, 0, 0};
  static float coefs[] = {20.48/4096, 10.24/4096, 10.24/4096, 5.12/4096};
  struct _op_mode {
    unsigned int mode:2;
    unsigned int coef:2;
    unsigned int cont:1;
    unsigned int :11;
  } operating_mode;

  return_on_error(DevNids(nid_dsc,sizeof(c_nids),c_nids));
  if (setup->no_trig) {
    float wait = 10E-6*16;
    pio(26, 0, 0);
    return_on_error(DevWait(wait));
  }
  for (chan=0; chan<16; chan++)
    pio(0,chan,&buffer[chan]);
  pio(1,15, (short *)&operating_mode);
  coef = coefs[operating_mode.coef];
  return_on_error(TdiCompile(&output_expr, &buffer_dsc, &coef_dsc, &output_xd MDS_END_ARG));
  status = TreePutRecord(c_nids[JOERGER_ADCP_N_INPUTS], (struct descriptor *)&output_xd,0);  
  return status;
}
Exemplo n.º 7
0
int l8201___init(struct descriptor *niddsc_ptr, InInitStruct *setup)
{
  int status;
  return_on_error(TdiData(setup->download,&data MDS_END_ARG),status);
  pio(9,0);
  stop(16);
  pio(11,&zero);
  pio(26,0);
  return status;
}
Exemplo n.º 8
0
int l8590_mem___init(struct descriptor_s *niddsc_ptr, InInitStruct *setup)
{
  static DESCRIPTOR(sclr_wild, "L8590_%");
  int status;
  int old_def;
  void *ctx;
  int setup_status = 0;
  static InGet_setupStruct sclr_setup;
  static int sclr_nid;
  static DESCRIPTOR_NID(sclr_niddsc,&sclr_nid);
  TreeGetDefaultNid(&old_def);
  TreeSetDefaultNid(*(int *)niddsc_ptr->pointer);
  for (ctx=0; TreeFindNodeWild("L85090_%", &sclr_nid, &ctx, -1)&1;) {
    setup_status = l8590_sclr___get_setup(&sclr_niddsc,&sclr_setup);
    if (setup_status & 1)
    {
      pio(sclr_setup.name,9,0,0);
      pio(sclr_setup.name,10,0,0);
      pio(sclr_setup.name,18,0,&sclr_setup.num_active_convert);
      pio(sclr_setup.name,26,0,0);
      pio(sclr_setup.name,18,0,&sclr_setup.num_active_convert);
      pio(sclr_setup.name,26,0,0);
      GenDeviceFree(&sclr_setup);
    }
    else
    {
      return_on_error(setup_status,status);
    }
  }
  pio(setup->name,9,0,0);
  pio(setup->name,25,0,0);
  pio(setup->name,11,0,0);
  TreeSetDefaultNid(old_def);
  return status;
}
Exemplo n.º 9
0
int l8201___store(struct descriptor *niddsc_ptr, InStoreStruct *setup)
{
  int status;
  int upload_nid = setup->head_nid + L8201_N_UPLOAD;
  pio(9,0);
  pio(2,&buffer[0]);
  stop(2);
  pio(11,&zero);
  pio(26,0);
  if (TreeIsOn(upload_nid)&1) 
    status = TreePutRecord(upload_nid,(struct descriptor *)&data,0);
  return status;
}
Exemplo n.º 10
0
static int
comprobe1(int iobase)
{

	if (badbaddr((void *)pio(iobase, com_lcr)))
		return 0;
	/* force access to id reg */
	outb(pio(iobase , com_lcr), 0);
	outb(pio(iobase , com_iir), 0);
	if (inb(pio(iobase , com_iir)) & 0x38)
		return 0;

	return 1;
}
Exemplo n.º 11
0
void czk80_state::czk80(machine_config &config)
{
	/* basic machine hardware */
	Z80(config, m_maincpu, 16_MHz_XTAL / 4);
	m_maincpu->set_addrmap(AS_PROGRAM, &czk80_state::czk80_mem);
	m_maincpu->set_addrmap(AS_IO, &czk80_state::czk80_io);
	m_maincpu->set_daisy_config(daisy_chain);

	GENERIC_TERMINAL(config, m_terminal, 0);
	m_terminal->set_keyboard_callback(FUNC(czk80_state::kbd_put));
	UPD765A(config, m_fdc, 8_MHz_XTAL, true, true);
	FLOPPY_CONNECTOR(config, "fdc:0", czk80_floppies, "525dd", floppy_image_device::default_floppy_formats);

	z80ctc_device& ctc(Z80CTC(config, "ctc", 16_MHz_XTAL / 4));
	ctc.intr_callback().set_inputline(m_maincpu, INPUT_LINE_IRQ0);
	ctc.zc_callback<0>().set(FUNC(czk80_state::ctc_z0_w));
	ctc.zc_callback<1>().set(FUNC(czk80_state::ctc_z1_w));
	ctc.zc_callback<2>().set(FUNC(czk80_state::ctc_z2_w));

	z80dart_device& dart(Z80DART(config, "dart", 16_MHz_XTAL / 4));
	//dart.out_txda_callback().set("rs232", FUNC(rs232_port_device::write_txd));
	//dart.out_dtra_callback().set("rs232", FUNC(rs232_port_device::write_dtr));
	//dart.out_rtsa_callback().set("rs232", FUNC(rs232_port_device::write_rts));
	dart.out_int_callback().set_inputline("maincpu", INPUT_LINE_IRQ0);

	z80pio_device& pio(Z80PIO(config, "pio", 16_MHz_XTAL / 4));
	pio.out_int_callback().set_inputline(m_maincpu, INPUT_LINE_IRQ0);
}
Exemplo n.º 12
0
int h911___store(struct descriptor *nid_d_ptr, InStoreStruct *in)
{

    struct _status_reg {
        unsigned mode:2;
        unsigned over:1;
        unsigned full:1;
        unsigned :20;
    } status_reg;
    short mems;
    short chans;
    int samples;
    int status;
    int i;
    short *buffer;
    pio(0,2,(short *)&status_reg)            /* read back the status register */
    if (! status_reg.full)   return DEV$_NOT_TRIGGERED;
    pio(0,3,&mems);
    mems++;
    pio(0,4,&chans);
    chans++;
    samples = mems*32768/chans -1;
    buffer = malloc(samples*sizeof(short));
    {

        static DESCRIPTOR_A(data_dsc, sizeof(short), DTYPE_W, 0, 0);
        static DESCRIPTOR(counts_str,"counts");
        static DESCRIPTOR_WITH_UNITS(counts, &data_dsc, &counts_str);
        static int clk_nid;
        static DESCRIPTOR_NID(clock_dsc,&clk_nid);
        static DESCRIPTOR_SIGNAL_1(sig, &counts, 0, &clock_dsc);
        data_dsc.pointer = (char *)buffer;
        data_dsc.arsize = samples * sizeof(short);
        clk_nid = in->head_nid+H911_N_EXT_CLOCK;
        for (i=0,status=1; ((status&1) && (i<chans)); i++) {
            int nid = in->head_nid+H911_N_CHANNEL_01 + i;
            if (TreeIsOn(nid)) {
                short addr = i;
                pio(17,1,&addr);   /* readback mode 1 chan at a time starting with  sample 1 of this channel */
                stop(0,0,samples,buffer);
                status = TreePutRecord(nid, (struct descriptor *)&sig,0);
            }
        }
    }
    free(buffer);
    return(status);
}
Exemplo n.º 13
0
static int ReadChannel(char *name, int chan, int *samples_ptr, short *data_ptr)
{
  int tries;
  int status;
  int samples_read = 0;
  int samples_to_read = *samples_ptr;
  int read_size;
  short int dummy;
  pio(16,5,&zero,1);
  pio(16,6,&zero,1);
  pio(16,7,&zero,1);
  {
    short int a = chan+1;
    pio(18,a, &zero, 1);
  }
  wait;
  pio(2,0,&dummy,1);       /* throw one out for good measure */
  for(samples_to_read = *samples_ptr; samples_to_read; samples_to_read -= read_size)
  {
    read_size = min(32767, samples_to_read);
    return_on_error(DevCamChk(CamQstopw(name,0,2,read_size,data_ptr+samples_read,16,0),&one,0));
    samples_read += read_size;
  }
  pio(25,1,0,1);      /* abort the read of this channel */
  pio(2,0,&dummy,0);       /* throw one out for good measure */
  return 1;
}
Exemplo n.º 14
0
int joerger_dac16___init(struct descriptor *nid_dsc, InInitStruct *setup)
{
  int i;
  static int c_nids[JOERGER_DAC16_K_CONG_NODES];
  int status;
  unsigned int module_id;
  int range;
  short int bad_chans = 0;
  float *outputs;
  outputs = &setup->output_01;
  return_on_error(DevNids(nid_dsc,sizeof(c_nids),c_nids));
  pio24(1, 15, &module_id);
  range = module_id & 3;      
  for (i=0; i < 16; i++) {
    if (TreeIsOn(c_nids[JOERGER_DAC16_N_OUTPUT_01+i])&1) {
      switch (range) {
      case 0: if ((outputs[i] >= 0) && (outputs[i] <= 10)) {
                short int data = outputs[i]/10.0*4096;
                pio(16, i, &data);
              }
              else bad_chans |= 1<<i;
              break;
      case 1: if ((outputs[i] >= 0) && (outputs[i] <= 5)) {
                short int data = outputs[i]/5.0*4096;
                pio(16, i, &data);
              }
              else bad_chans |= 1<<i;
              break;
      case 2: if ((outputs[i] >= -10) && (outputs[i] <= 10)) {
                short int data = (outputs[i]+10)/20.0*4096;
                pio(16, i, &data);
              }
              else bad_chans |= 1<<i;
              break;
      case 3: if ((outputs[i] >= -5) && (outputs[i] <= 5)) {
                short int data = (outputs[i]+5)/10.0*4096;
                pio(16, i, &data);
              }
              else bad_chans |= 1<<i;
              break;
      }
    }
  }
  return (bad_chans != 0) ? J_DAC$_OUTRNG : 1;
}
Exemplo n.º 15
0
static unsigned int Input(InStoreStruct *setup,int code)
{
  int status;
  unsigned short i;
  AccessTraq(setup,code,16,0,0);
  DevWait((float).005);
  pio(0,0,&i);
  return i;
}
Exemplo n.º 16
0
int l8206___init(struct descriptor *niddsc_ptr, InInitStruct *setup)
{
  int status;
  int download_nid = setup->head_nid + L8206_N_DOWNLOAD;
  pio(9,0);
  if (TreeIsOn(download_nid) & 1)
  {
    data.arsize = sizeof(buffer);
    return_on_error(TdiData(setup->download,&data MDS_END_ARG),status);
    stop(16,16384,buffer);
    stop(16,16384,&buffer[16384]);
    stop(16,16384,&buffer[32768]);
    stop(16,16384,&buffer[49152]);
  }
  pio(18,&zero);
  pio(11,&zero);
  pio(26,&zero);
  return status;
}
Exemplo n.º 17
0
int l2415___init(struct descriptor *niddsc, InInitStruct *setup)
{
  int status=1;
  unsigned short int word_out;
  word_out = setup->voltage * setup->polarity / (setup->range == 3500. ? .25 : .5);
  pio(16,0,&word_out)
  word_out = setup->current / ((setup->range == 3500.)?.0025:.001) * 255;
  pio(16,1,&word_out)
  return status;
}
Exemplo n.º 18
0
int l4202___store(struct descriptor *niddsc, InStoreStruct *setup)
{ 
  struct { unsigned first : 12;
           unsigned second : 12;
           unsigned fill : 8;
         } in_data[16384];
  unsigned short out_data[32768];
  int status;
  int i;
  pio(setup->memory_name,19,0,&zero);     /* Disable port for external histogram */
  pio(setup->memory_name,18,1,&zero);     /* Set memory to location 0 for reads */
  stop(setup->memory_name,2,0,8192,&in_data[0]);
  stop(setup->memory_name,2,0,8192,&in_data[8192]);
  {
    static DESCRIPTOR_A_COEFF_2(raw, 2, DTYPE_W, 0, 0, 0, 0);
    static DESCRIPTOR_FUNCTION_1(value,(unsigned char *)&OpcValue,0);
    static int zero_val = 0;
    static DESCRIPTOR_LONG(zero, &zero_val);
    static int endrange_val;
    static DESCRIPTOR_LONG(endrange, &endrange_val);
    static int delta_val = 1;
    static DESCRIPTOR_FLOAT(delta, &delta_val);
    static DESCRIPTOR_RANGE(dim1, &zero, &endrange, &delta);
    static int ext_clock_nid;
    static DESCRIPTOR_NID(dim2,&ext_clock_nid);
    static DESCRIPTOR_SIGNAL_2(signal, &value, &raw, &dim1, &dim2);
    int spectra_nid = setup->head_nid + L4202_N_SPECTRA;
    value.ndesc = 0;
    ext_clock_nid = setup->head_nid + L4202_N_EXT_CLOCK;
    raw.pointer = raw.a0 = (char *)out_data;
    raw.arsize = min(65536, setup->router_inc * setup->num_spectra * sizeof(short));
    raw.m[0] = setup->router_inc;
    raw.m[1] = setup->num_spectra;
    endrange_val = setup->router_inc - 1;
    for (i=0;i<16384;i++)
    {
      out_data[i]   = in_data[i].first;
      out_data[i+16384] = in_data[i].second;
    }
    status = TreePutRecord(spectra_nid, (struct descriptor *)&signal,0);
  }
  return status;
}
Exemplo n.º 19
0
int l8206___store(struct descriptor *niddsc_ptr, InStoreStruct *setup)
{
  int status;
  int savstatus;
  int upload_nid = setup->head_nid + L8206_N_UPLOAD;
  pio(19,&zero);
  if (TreeIsOn(upload_nid)&1)
  { 
    int numpoints = 0;
    short *bptr;
    int pread;
    pio(8,0);
    if (CamQ(0) & 1)
    {
      numpoints = 65536;
    }
    else
    {
      pio(0,&numpoints);
    }
    pio(25,0);
    pio(18,&zero);
    pio(2,&buffer[0]); /* junk word */
    for (pread = 0,bptr = buffer; pread < numpoints;)
    {
      int num = numpoints - pread;
      if (num > 32767) num = 32767;
      stop(2,num,bptr);
      pread += num;
      bptr += num;
    }
    if (numpoints > 0)
    {
      data.arsize = numpoints * sizeof(short);
      status = TreePutRecord(upload_nid,(struct descriptor *)&data,0);
    }
    else
      status = L8206$_NODATA;
  }
  savstatus = status;
  pio(18,&zero);
  pio(11,&zero);
  pio(26,&zero);
  if (status & 1) status = savstatus;
  return status;
}
Exemplo n.º 20
0
int l8590___init(struct descriptor_s *niddsc_ptr, InInitStruct *setup)
{
  int status;
  pio(setup->name,9,0,0);
  pio(setup->name,10,0,0);
  pio(setup->name,18,0,&setup->num_active_convert);
  pio(setup->name,26,0,0);
  pio(setup->mem_cts_name,9,0,0);
  pio(setup->mem_cts_name,25,0,0);
  pio(setup->mem_cts_name,11,0,0);
  return status;
}
Exemplo n.º 21
0
void a5105_state::a5105(machine_config &config)
{
	/* basic machine hardware */
	Z80(config, m_maincpu, XTAL(15'000'000) / 4);
	m_maincpu->set_addrmap(AS_PROGRAM, &a5105_state::a5105_mem);
	m_maincpu->set_addrmap(AS_IO, &a5105_state::a5105_io);
	m_maincpu->set_daisy_config(a5105_daisy_chain);

	/* video hardware */
	SCREEN(config, m_screen, SCREEN_TYPE_RASTER);
	m_screen->set_refresh_hz(50);
	m_screen->set_vblank_time(ATTOSECONDS_IN_USEC(2500)); /* not accurate */
	m_screen->set_screen_update("upd7220", FUNC(upd7220_device::screen_update));
	m_screen->set_size(40*8, 32*8);
	m_screen->set_visarea(0, 40*8-1, 0, 25*8-1);
	GFXDECODE(config, m_gfxdecode, m_palette, gfx_a5105);
	PALETTE(config, m_palette, FUNC(a5105_state::a5105_palette), 16);

	/* sound hardware */
	SPEAKER(config, "mono").front_center();
	WAVE(config, "wave", "cassette").add_route(ALL_OUTPUTS, "mono", 0.25);
	BEEP(config, "beeper", 500).add_route(ALL_OUTPUTS, "mono", 0.50);

	/* Devices */
	UPD7220(config, m_hgdc, XTAL(15'000'000) / 16); // unk clock
	m_hgdc->set_addrmap(0, &a5105_state::upd7220_map);
	m_hgdc->set_display_pixels(FUNC(a5105_state::hgdc_display_pixels));
	m_hgdc->set_draw_text(FUNC(a5105_state::hgdc_draw_text));

	z80ctc_device& ctc(Z80CTC(config, "z80ctc", XTAL(15'000'000) / 4));
	ctc.intr_callback().set_inputline(m_maincpu, 0);
	ctc.zc_callback<0>().set("z80ctc", FUNC(z80ctc_device::trg2));
	ctc.zc_callback<2>().set("z80ctc", FUNC(z80ctc_device::trg3));

	z80pio_device& pio(Z80PIO(config, "z80pio", XTAL(15'000'000) / 4));
	pio.in_pb_callback().set(FUNC(a5105_state::pio_pb_r));
	pio.out_int_callback().set_inputline(m_maincpu, 0);

	CASSETTE(config, m_cass);

	UPD765A(config, m_fdc, 8'000'000, true, true);
	FLOPPY_CONNECTOR(config, "upd765a:0", a5105_floppies, "525qd", a5105_state::floppy_formats);
	FLOPPY_CONNECTOR(config, "upd765a:1", a5105_floppies, "525qd", a5105_state::floppy_formats);
	FLOPPY_CONNECTOR(config, "upd765a:2", a5105_floppies, "525qd", a5105_state::floppy_formats);
	FLOPPY_CONNECTOR(config, "upd765a:3", a5105_floppies, "525qd", a5105_state::floppy_formats);

	/* internal ram */
	RAM(config, RAM_TAG).set_default_size("64K");
}
Exemplo n.º 22
0
int hv1440___init(struct descriptor *niddsc, InInitStruct *setup)
{
  int pods[HV1440_K_MAX_PODS];
  int status = 1;
  int pod;
  int ind;
  int i;
  int j;
  int vmax;
  int vfmax=0;
  int nfmax=0;

  static int settings[HV1440_K_MAX_CHANNELS];


  vmax = ((setup->range == 1.0) || 
          (setup->range == .625)) ? 2500 : (setup->range == .5) ? 2046 : (setup->range == .375) ? 1534 : 0;
  if (! vmax) return HV1440$_BAD_RANGE;

  for (pod=0,ind=0; pod<HV1440_K_MAX_PODS; pod++, ind+= HV1440_K_CHANS_PER_POD)  
    pods[pod] = GetPodSettings(setup->head_nid + HV1440_N_POD_01+pod, &settings[ind]);

  for (i=0; i<HV1440_K_MAX_CHANNELS; i++) {
    int abset = abs(settings[i]);
    if (abset > vmax) return HV1440$_OUTRNG;
    if (abset > vfmax) {
      vfmax  = abset;
      nfmax = i;
    }
  }
  pio(9,0,0);		       		/* clear the interface */
/*  pio(10,0,0); */                		/* enable lam1 */
/*   pio(26,1,0); */               		/* enable lam2 */
  send_hv (0, nfmax, setup->frame*2, 0);   /* select the frame */
  for (i=0; i<HV1440_K_MAX_PODS; i++) {
    if (pods[i]) {
      int i0 = i*16;
      send_hv(0, i0, 2, 1)
      for (j = 0; j<HV1440_K_CHANS_PER_POD; j++) {
        int iv = abs(settings[i*HV1440_K_CHANS_PER_POD+j])/setup->range + .5;
        int sign = (iv>0);
        send_hv(sign, 0, iv, 2);
      }
/*       wait_hv;  */
    }
  }
  return 1;
}
Exemplo n.º 23
0
int ec727___store(struct descriptor *niddsc_ptr, InStoreStruct *setup)
{
  static DESCRIPTOR(sigdef,"BUILD_SIGNAL(BUILD_WITH_UNITS($,'counts'),*,$[ $ : $ ])");
  static DESCRIPTOR_A_BOUNDS(raw,sizeof(int),DTYPE_L,0,1,0);
  static DESCRIPTOR_LONG(start_d,&raw.bounds[0].l);
  static DESCRIPTOR_LONG(end_d,&raw.bounds[0].u);
  static EMPTYXD(signal);
  static int xfer_in;
  static DESCRIPTOR_NID(xfer_in_d,&xfer_in);
  int data[1024][32];
  int cdata[1024];
  int *dptr = (int *)data;
  int status;
  int i;
  int chan;
  xfer_in = setup->head_nid + EC727_N_XFER_IN;
  pio(17,0);
  for (i=0;i<4;i++,dptr += 8192) stop(0,0,8192,dptr);
  for (chan=0;((chan < 32) && (status & 1));chan++)
  {
    int c_nid = setup->head_nid + EC727_N_INPUT_01 + chan * (EC727_N_INPUT_02 - EC727_N_INPUT_01);
    int s_nid = c_nid + EC727_N_INPUT_01_STARTIDX - EC727_N_INPUT_01;
    int e_nid = c_nid + EC727_N_INPUT_01_ENDIDX - EC727_N_INPUT_01;
    if (TreeIsOn(c_nid) & 1)
    {
      status = DevLong(&s_nid,(int *)&raw.bounds[0].l);
      if (status&1) raw.bounds[0].l = min(1023,max(0,raw.bounds[0].l));
      else raw.bounds[0].l = 0;

      status = DevLong(&e_nid, (int *)&raw.bounds[0].u);
      if (status&1) raw.bounds[0].u = min(1023,max(0,raw.bounds[0].u));
      else raw.bounds[0].u = 1023;

      raw.m[0] = raw.bounds[0].u - raw.bounds[0].l + 1;
      if (raw.m[0] > 0)
      {
        for (i=0;i<1024;i++) cdata[i] = data[i][chan];
        raw.pointer = (char *)(cdata + (raw.bounds[0].l));
        raw.a0 = (char *)cdata;
        raw.arsize = raw.m[0] * 4;
        TdiCompile(&sigdef,&raw,&xfer_in_d,&start_d,&end_d,&signal MDS_END_ARG);
        status = TreePutRecord(c_nid,(struct descriptor *)signal.pointer,0);
      }
    }
  }
  return status;
}
Exemplo n.º 24
0
static int ReadSetup(InStoreStruct *setup, int *mem_ptr, char *head_ptr, int *samples_ptr, int *min_idx_ptr, int *max_idx_ptr,
                     float *freq_ptr, int *noc_ptr)
{
  struct l8210_setup { unsigned l8210_setup_v_pts : 3;
  		       unsigned l8210_setup_v_period : 3;
		       unsigned l8210_setup_v_noc : 2;
		     } l8210_setup;
  int pts[8];        							/* post trigger samples */
  static float freq[8] = {0, 1.E-4, 4.E-5, 2.E-5, 1.E-5, 4.E-6, 2.E-6, 1.E-6 };
  int status;
  pio(1,0,(short *)&l8210_setup);
  if (status & 1)
  {
    *noc_ptr = l8210_setup.l8210_setup_v_noc + 1;
    *freq_ptr = freq[l8210_setup.l8210_setup_v_period];
    *samples_ptr = 32768 * *mem_ptr / *noc_ptr;
    L8210HeaderToPTS(head_ptr,(char *)mem_ptr,pts);
    *min_idx_ptr = pts[7-l8210_setup.l8210_setup_v_pts] - *samples_ptr;
    *max_idx_ptr = pts[7-l8210_setup.l8210_setup_v_pts] - 1;
  }
  return status;
}
Exemplo n.º 25
0
void Executor::waitForInput(double pidSetpoint) {
  PhysicalInput pio(_pioPin);
  DigitalPot digiPot(_csPin);
  FiveFiveFive five(_fivePin);
  VoltageMeter vMeter(_adsAddress);
  double InputRaw = 0;
  double OutputRaw = 0;
  double SetpointRaw = 0;
  PID myPIDRaw(&InputRaw, &OutputRaw, &SetpointRaw, _KpRaw, _KiRaw, _KdRaw, DIRECT);
  myPIDRaw.SetMode(AUTOMATIC);
  myPIDRaw.SetOutputLimits(0, 255);
  myPIDRaw.SetSampleTime(1);

  if(pio.readInput()) {
    Serial.print("after"); Serial.println(pio.readInput());
    // Used in order for raspberry pi monitoring device to get "up to speed"
    delay(500);
    while(pio.readInput()) {
      five.fiveEnable();
      InputRaw = vMeter.voltage(_probe);
      SetpointRaw = pidSetpoint;
      myPIDRaw.Compute();
      int intOutput = OutputRaw;
      digiPot.writeToPot(intOutput);
      // debuging led on arduino
      digitalWrite(13, 1);
    }
    digiPot.killPot();
    five.fiveKill();
    // debuging led on arduino
    digitalWrite(13, 0);
  }
  digiPot.killPot();
  five.fiveKill();
  // debuging led on arduino
  digitalWrite(13, 0);

}
Exemplo n.º 26
0
static int ReadChannel(InStoreStruct *setup, int *max_samps_ptr, int chan, int *samples_ptr, short	*data_ptr)
{
  short *in_ptr = data_ptr;
  short *end_ptr = data_ptr + *samples_ptr;
  int pnts_to_read;
  struct { unsigned short	status;
           unsigned short	bytcnt;
  	   unsigned short fill[2];
         } iosb;
  int lamchks = 10;
  unsigned short dum_read;
  int status;
  pio(10,0,0);
  pio(16,chan,&zero);
  while (pnts_to_read = max(0,min(32767,end_ptr-in_ptr)))
  {
    return_on_error(DevCamChk(CamQrepw(setup->name,0,2,pnts_to_read,in_ptr,16,0),&one,0),status);
    CamGetStat((short *)&iosb);
    if ((!(CamQ((short *)&iosb)&1)) && (iosb.bytcnt == 0)) 
      in_ptr = end_ptr;
    else 
      in_ptr += iosb.bytcnt/2;
  }
  if (*max_samps_ptr != *samples_ptr)
  {
    pio(24,0,0);
    pio(2,0,&dum_read);
    pio(26,0,0);
  }
  while (lamchks)
  {
    pio(8,0,0);
    if (CamQ(0)&1)
      lamchks = 0;
    else
      lamchks--;
  }
  return 1;
}
Exemplo n.º 27
0
int
fixfault(Segment *s, uintptr addr, int read, int doputmmu)
{
	int type;
	int ref;
	Pte **p, *etp;
	uintptr mmuphys=0, soff;
	Page **pg, *lkp, *new;
	Page *(*fn)(Segment*, uintptr);

	addr &= ~(BY2PG-1);
	soff = addr-s->base;
	p = &s->map[soff/PTEMAPMEM];
	if(*p == 0)
		*p = ptealloc();

	etp = *p;
	pg = &etp->pages[(soff&(PTEMAPMEM-1))/BY2PG];
	type = s->type&SG_TYPE;

	if(pg < etp->first)
		etp->first = pg;
	if(pg > etp->last)
		etp->last = pg;

	switch(type) {
	default:
		panic("fault");
		break;

	case SG_TEXT: 			/* Demand load */
		if(pagedout(*pg))
			pio(s, addr, soff, pg);

		mmuphys = PPN((*pg)->pa) | PTERONLY|PTEVALID;
		(*pg)->modref = PG_REF;
		break;

	case SG_BSS:
	case SG_SHARED:			/* Zero fill on demand */
	case SG_STACK:
		if(*pg == 0) {
			new = newpage(1, &s, addr);
			if(s == 0)
				return -1;

			*pg = new;
		}
		goto common;

	case SG_DATA:
	common:			/* Demand load/pagein/copy on write */
		if(pagedout(*pg))
			pio(s, addr, soff, pg);

		/*
		 *  It's only possible to copy on write if
		 *  we're the only user of the segment.
		 */
		if(read && conf.copymode == 0 && s->ref == 1) {
			mmuphys = PPN((*pg)->pa)|PTERONLY|PTEVALID;
			(*pg)->modref |= PG_REF;
			break;
		}

		lkp = *pg;
		lock(lkp);

		if(lkp->image == &swapimage)
			ref = lkp->ref + swapcount(lkp->daddr);
		else
			ref = lkp->ref;
		if(ref == 1 && lkp->image){
			/* save a copy of the original for the image cache */
			duppage(lkp);
			ref = lkp->ref;
		}
		unlock(lkp);
		if(ref > 1){
			new = newpage(0, &s, addr);
			if(s == 0)
				return -1;
			*pg = new;
			copypage(lkp, *pg);
			putpage(lkp);
		}
Exemplo n.º 28
0
int l8590_mem___store(struct descriptor_s *niddsc_ptr, InStoreStruct *setup)
{
  int total_chans = 0;
  int total_samps = 0;
  void  *ctx;
  int sclrs;
  int sclr_nids[L8590_MEM_K_MAX_SCALERS];
  int active[L8590_MEM_K_MAX_SCALERS];
  int samples[L8590_MEM_K_MAX_SCALERS];
  int old_def;
  int status;
  static DESCRIPTOR_A_BOUNDS(raw,sizeof(unsigned short),DTYPE_WU,0,1,0);
  static DESCRIPTOR(counts_str,"counts");
  static DESCRIPTOR_WITH_UNITS(counts,&raw,&counts_str);
  static InGet_setupStruct sclr_setup;
  static DESCRIPTOR_NID(sclr_niddsc,0);
  static int latch_nid;
  static DESCRIPTOR_NID(latch,&latch_nid);
  static FUNCTION(1) dvalue = {2,DTYPE_FUNCTION,CLASS_R,(unsigned char *)&OpcValue,0,0};
  static DESCRIPTOR_SIGNAL_1(signal,&dvalue,&counts,&latch);
  int setup_status = 0;
  latch_nid = setup->head_nid + L8590_MEM_N_LATCH;
  TreeGetDefaultNid(&old_def);
  TreeSetDefaultNid(*(int *)niddsc_ptr->pointer);
  for (ctx=0,sclrs=0; TreeFindNodeWild("L8590_%", &sclr_nids[sclrs], &ctx, -1)&1;sclrs++) {
    sclr_niddsc.pointer = (char *)&sclr_nids[sclrs];
    setup_status = l8590_sclr___get_setup(&sclr_niddsc,&sclr_setup);
    if (setup_status & 1)
    {
      samples[sclrs] = 0;
      active[sclrs] = sclr_setup.num_active;
      pio(sclr_setup.name,2,0,&samples[sclrs]);
      total_samps += samples[sclrs];
      total_chans += active[sclrs];
      GenDeviceFree(&sclr_setup);
    }
    else
    {
      return_on_error(setup_status,status);
    }
  }
  if (total_samps > 32766)
  {
    printf("Total samples too large for L8590_MEM: %s --- %d\n",setup->name,total_samps);
    total_samps = 32767;
  }

  if (!(TreeIsOn(setup->head_nid + L8590_MEM_N_COMMENT) & 1)) {
    total_samps = total_chans*2000;
  }

  if (total_samps) {
    int chan;
    int chan_idx;
    unsigned short *values = calloc(total_samps * 2,sizeof(*values));
    unsigned short *cdata = values + total_samps;
    int samps_per_chan = total_samps/total_chans;
    int min_idx = 0;
    int max_idx = samps_per_chan - 1;
    int i;
    int sclr;
    pio(setup->name,19,0,&zero);
    pio(setup->name,18,0,&zero);
    pio(setup->name,25,0,0);
    pio(setup->name,2,0,&values[0]);
    pio(setup->name,19,0,&zero);
    stop(setup->name,2,0,total_samps,values);
    for (i=0;i<total_samps;i++) cdata[i/total_chans + (i % total_chans) * samps_per_chan] = values[i];
    for (chan_idx=0, sclr=0; sclr<sclrs; sclr++) {
      for (chan=0; chan<active[sclr]; chan++, chan_idx++) {
        int data_nid = sclr_nids[sclr]+L8590_SCLR_N_INPUT_1+(L8590_SCLR_N_INPUT_2 - L8590_SCLR_N_INPUT_1)*chan;
        int start_nid = data_nid + L8590_SCLR_N_INPUT_1_STARTIDX - L8590_SCLR_N_INPUT_1;
        int end_nid = data_nid + L8590_SCLR_N_INPUT_1_ENDIDX - L8590_SCLR_N_INPUT_1;
        if (TreeIsOn(data_nid) & 1) {
          status = DevLong(&start_nid,(int *)&raw.bounds[0].l);
          if (status&1) raw.bounds[0].l = min(max_idx,max(min_idx,raw.bounds[0].l));
          else raw.bounds[0].l = min_idx;
          status = DevLong(&end_nid, (int *)&raw.bounds[0].u);
          if (status&1) raw.bounds[0].u = min(max_idx,max(min_idx,raw.bounds[0].u));
          else raw.bounds[0].u = max_idx;
          raw.m[0] = raw.bounds[0].u - raw.bounds[0].l + 1;
          if (raw.m[0] > 0)
          {
            raw.pointer = (char *)(cdata + chan_idx * samps_per_chan + raw.bounds[0].l);
            raw.a0 = raw.pointer - raw.bounds[0].l * sizeof(*cdata);
            raw.arsize = raw.m[0] * 2;
            status = TreePutRecord(data_nid,(struct descriptor *)&signal,0);
          }
        }
      }
    }
    free(values);
  }
  TreeSetDefaultNid(old_def);
  return status;
}
Exemplo n.º 29
0
static int ReadChannel(InStoreStruct *setup, int chunk,int samples,unsigned short *buffer,int *samples_read,int *nid,float *calib)
{
  int chunk_address =  0x0B000 | chunk;
  int points_to_read;
  int status=1;
  int tries;
  for (points_to_read = chunksize; status & 1 && points_to_read; points_to_read = chunksize)
  {
    struct { unsigned short status;
             unsigned short bytcnt;
             unsigned int   dummy;} iosb = {0,0};
    int try;
    static DESCRIPTOR_A(calib_a, sizeof(*calib), DTYPE_NATIVE_FLOAT, 0, 2*sizeof(*calib));
    static DESCRIPTOR_NID(nid_dsc,0);
    void *arglist[] = {0,&nid_dsc,&calib_a MDS_END_ARG};
    calib_a.pointer = (char *)calib;
    nid_dsc.pointer = (char *)nid;
    arglist[0] = (void *)(sizeof(arglist)/sizeof(arglist[0]));
    AccessTraq(setup,chunk_address,24,arglist,TdiData);
    pio(8,0,0);
    for (try = 0;(try < 20) && (!(CamQ(0)&1)) && (status & 1);try++) {pio(8,0,0);}
    pio(10,0,0);
    return_on_error(DevCamChk(CamQstopw(setup->name,0,2,points_to_read,buffer + *samples_read,16,(short *)&iosb),&one,0),status);
    status = status & 1 ? iosb.status : status;
    *samples_read += iosb.bytcnt/2;
    if (iosb.bytcnt/2 != points_to_read) break;
    chunk_address += max_chunks_per_io;
  }
  return status;
}

static int AccessTraq(InStoreStruct *setup, int data,int memsize,void *arglist,int (*routine)())
{ int try;
  int status;
  int called = 0;
  if (max_time > 0) {
    if ((time(0)-start_time) > max_time) {
      printf("T4012 AccessTraq timeout, data=%d\n",data);
      return DEV$_BAD_MODE;
    }
  }
  piomem(17,0,&data,memsize);
  for (try = 0;(try < 30) && (!(CamQ(0)&1)) && (status &1);try++) 
  {
    if (arglist && !called) {
      called = 1;
      LibCallg(arglist,routine);
    }
    else
      DevWait((float).001);
    piomem(17,0,&data,memsize);
  }
  if (try == 30) status = DEV$_CAM_NOSQ;
  if (arglist &&!called) LibCallg(arglist,routine);
  return status;
}

int t4012__dw_setup( struct descriptor *niddsc, struct descriptor *methoddsc, Widget parent)
{ 
  static String uids[] = {"T4012.uid"};
  static int nid;
  static MrmRegisterArg uilnames[] = {{"nid",(XtPointer)0},{"Load",(XtPointer)Load}};
  static NCI_ITM   nci[] = {{4, NciCONGLOMERATE_NIDS, (unsigned char *)&nid, 0}, {0, NciEND_OF_LIST, 0, 0}};
  TreeGetNci(*(int *)niddsc->pointer, nci);
  uilnames[0].value = (char *)0+nid;
  return XmdsDeviceSetup(parent, (int *)niddsc->pointer, uids, XtNumber(uids), "T4012", uilnames, XtNumber(uilnames), 0);
}

static void Load(Widget w)
{
  char *t4012name;
  char dignam[512];
  int i;
  XtPointer user_data;
  int nid;
  int found = False;
  XtVaGetValues(w, XmNuserData, &user_data, NULL);
  nid = (intptr_t)user_data;
  t4012name = TreeGetPath(nid);
  strcpy(dignam,t4012name);
  strcat(dignam,":T28%%_");
  TreeFree(t4012name);
  XmListDeleteAllItems(w);
  for (i=1;i<17;i++)
  {
    int dig_nid;
    int status;
    XmString item;
    int len = strlen(dignam);
    dignam[len++]=i<10 ? '0' : '1';
    dignam[len++]='0'+(i % 10);
    dignam[len++]=0;
    status = TreeFindNode(dignam,&dig_nid);
    if (status & 1)
    {
      NCI_ITM itmlst[] = {{512,NciNODE_NAME,0,0},{0,0,0,0}};
      itmlst[0].pointer = dignam;
      TreeGetNci(dig_nid,itmlst);
      item = XmStringCreateSimple(dignam);
      XmListAddItem(w, item, 0);
      XmStringFree(item);
      found = True;
    }
    else
      break;
  }
  if (!found)
  {
    XmString item = XmStringCreateSimple("Add T28xx_01");
    XmListAddItem(w, item, 0);
    XmStringFree(item);
  }
}
Exemplo n.º 30
0
int t4012___store(int *niddsc, InStoreStruct *setup)
{ 
  int channels;
  int pts;
  int memPerChannel;
  int channels_read;
  int dig;
  int dig_nid;
  static int memsize=0;
  static unsigned short *mem;
  int idxmin;
  int idxmax;
  char digname[512];
  char *nodename;
  int chan_nid = 0;
  struct _t4012_status { unsigned    sampling  : 1;
                         unsigned    calibrate : 1;
                         unsigned    master_armed : 1;
                         unsigned    master_enabled : 1;
                         unsigned    stop_received : 1;
                         unsigned    triggered : 1;
                         unsigned    t4012p : 1;
                         unsigned    cal_mem : 1;
                         unsigned : 24;
                       } dig_status;
  int status;
  static short offset;
  static float coefficient;
  static float f[2];
  static DESCRIPTOR_A_BOUNDS(raw,sizeof(short),DTYPE_W,0,1,0);
  static int *lbound = &raw.bounds[0].l;
  static int *ubound = &raw.bounds[0].u;
  static unsigned int *acoef  = &raw.m[0];
  static DESCRIPTOR_A(f2_d,sizeof(f[0]),DTYPE_NATIVE_FLOAT,f,8);
  static DESCRIPTOR(counts_str,"counts");
  static DESCRIPTOR(volts_str,"volts");
  static DESCRIPTOR(seconds_str,"seconds");
  static DESCRIPTOR_LONG(start_d,&raw.bounds[0].l);
  static DESCRIPTOR_LONG(end_d,&raw.bounds[0].u);
  static int trigger_nid;
  static DESCRIPTOR_NID(stop_d,&trigger_nid);
  static int switch_trig_nid;
  static DESCRIPTOR_NID(swi_d,&switch_trig_nid);
  static int extern_clock_nid;
  static DESCRIPTOR_NID(ext_clock_d,&extern_clock_nid);
  static struct descriptor offset_d = {2,DTYPE_W, CLASS_S, (char *)&offset};
  static DESCRIPTOR_FLOAT(coef_d,&coefficient);
  static DESCRIPTOR_FLOAT(f1_d,f);
  static int _roprand = 32768;
  static DESCRIPTOR_FLOAT(roprand,&_roprand);
  static FUNCTION(1) value = {2,DTYPE_FUNCTION,CLASS_R,(unsigned char *)&OpcValue,0,0};
  static DESCRIPTOR_FUNCTION_2(subtract_exp,(unsigned char *)&OpcSubtract,&value,&offset_d);
  static DESCRIPTOR_FUNCTION_2(mult_exp,(unsigned char *)&OpcMultiply,&coef_d,&subtract_exp);
  static DESCRIPTOR_WITH_UNITS(counts,&raw,&counts_str);
  static DESCRIPTOR_WITH_UNITS(volts,&mult_exp,&volts_str);
  static DESCRIPTOR_FUNCTION_2(rangesub,(unsigned char *)&OpcSubtract,0,&f1_d);
  static DESCRIPTOR_WINDOW(window,&start_d,&end_d,&stop_d);
  static struct descriptor *begin_ptrs[] = {&roprand,0};
  static struct descriptor *end_ptrs[] = {(struct descriptor *)&rangesub,&roprand};
  static DESCRIPTOR_APD(begin_apd,0,begin_ptrs,2);
  static DESCRIPTOR_APD(end_apd,0,end_ptrs,2);
  static DESCRIPTOR_RANGE(int_clock1_d,0,0,&f1_d);
  static DESCRIPTOR_RANGE(int_clock2_d,&begin_apd,&end_apd,&f2_d);
  static int clock_out_nid;
  static DESCRIPTOR_NID(clock_out_d,&clock_out_nid);
  static DESCRIPTOR_DIMENSION(dimension,&window,&clock_out_d);
  static DESCRIPTOR_WITH_UNITS(seconds,&dimension,&seconds_str);
  static DESCRIPTOR_SIGNAL_1(signal,&volts,&counts,&seconds);
  void *ctx = 0;
  max_time=-1;
  trigger_nid = setup->head_nid + T4012_N_TRIGGER;
  switch_trig_nid = setup->head_nid + T4012_N_SWITCH_TRIG;
  extern_clock_nid = setup->head_nid + T4012_N_EXTERN_CLOCK;
  clock_out_nid = setup->head_nid + T4012_N_CLOCK_OUT;
  pio(8,0,0);
  status = Input(setup,14);
  dig_status = *(struct _t4012_status *)&status;
  if (dig_status.sampling)
  {
    return DEV$_NOT_TRIGGERED;
  }
  channels = Input(setup,1);
  pts = Input(setup,2);
  memPerChannel = Input(setup,3) * 1024;

  if (Input(setup,7) == 1)
    TreePutRecord(clock_out_nid,(struct descriptor *)&ext_clock_d,0);
  else
  {
    int shift = Input(setup,6);
    f[0] = freqs[Input(setup,4)];
    if (shift)
    {
      f[1] = freqs[Input(setup,5)];
      rangesub.arguments[0] = begin_ptrs[1] = (shift == 1) ? &swi_d : &stop_d;
      TreePutRecord(clock_out_nid,(struct descriptor *)&int_clock2_d,0);
    }
    else
      TreePutRecord(clock_out_nid,(struct descriptor *)&int_clock1_d,0);
  }
  idxmin = (pts - 8.)/8. * memPerChannel;
  idxmax = idxmin + memPerChannel - 1;
  if (memsize < (memPerChannel * 2))
  {
    if (memsize) free(mem);
    memsize = memPerChannel * 2;
    mem = malloc(memsize);
  }
  return_on_error(AccessTraq(setup,0x8001,16,0,0),status); /* Remote control */
  nodename = TreeGetPath(setup->head_nid);
  strcpy(digname,nodename);
  TreeFree(nodename);
  strcat(digname,":T28%%_%%");
  status = TreeFindNodeWild(digname,&dig_nid,&ctx,1 << TreeUSAGE_DEVICE);
  for (dig=1,channels_read=0;(channels_read < channels) && (status & 1);dig++)
  {
    static int dig_nids[1+8*T28XX_K_NODES_PER_INP];
    static int nidlen;
    static NCI_ITM itmlst[] = {{sizeof(dig_nids),NciCONGLOMERATE_NIDS,(unsigned char *)&dig_nids,&nidlen},
                               {0,NciEND_OF_LIST,0,0}};
    if (status & 1)
    {
      int i;
      int digchannels;
      status = TreeGetNci(dig_nid,itmlst);
      digchannels = (nidlen/sizeof(dig_nid)-1)/T28XX_K_NODES_PER_INP;
      for (i=0;i<digchannels && (status & 1) && channels_read < channels;i++)
      {
        if (TreeIsOn(CNID(i,HEAD))&1)
        {
          int channel_select = 0x0A000 | (channels_read + 1);
          AccessTraq(setup,channel_select,24,0,0);
          if (chan_nid && (*acoef > 1))
          {
            return_on_error(TreePutRecord(chan_nid,(struct descriptor *)&signal,0),status);
            chan_nid = 0;
          }
          else
            DevWait((float).005);

          chan_nid = CNID(i,HEAD);
          *lbound = (DevLong(&CNID(i,STARTIDX),(int *)lbound) & 1) ? min(idxmax,max(idxmin,*lbound)) : idxmin;
          *ubound = (DevLong(&CNID(i,ENDIDX), (int *)ubound) & 1) ?  min(idxmax,max(idxmin,*ubound)) : idxmax;
          *acoef = *ubound - *lbound + 1;
          if (*acoef > 0)
          {
            int points_read = 0;
            int first_sample_offset = *lbound-idxmin;
            int chunk = first_sample_offset/1024;
            int chunk_offset = first_sample_offset % 1024;
            float calib[]={0,0};
            status = ReadChannel(setup, chunk,*acoef+chunk_offset,mem,&points_read,&CNID(i,CALIBRATION),calib);
            if (status & 1)
            {
              offset = calib[0];
              if (calib[0] == calib[1])
                coefficient = (offset > 1000) ? 10./4096 : 5./4096.;
              else
                coefficient = calib[1];
              raw.pointer = (char *)(mem + chunk_offset);
              raw.a0 = raw.pointer - *lbound * sizeof(*mem);
              *ubound = (points_read - chunk_offset) + *lbound - 1;
              *acoef = (points_read - chunk_offset);
              raw.arsize = *acoef * 2;
            }
          }
        }
        channels_read++;
      }
    }
    if (channels_read < channels  && (status & 1)) status = TreeFindNodeWild(digname,&dig_nid,&ctx,1 << TreeUSAGE_DEVICE);
  }
  TreeFindNodeEnd(&ctx);
  if (chan_nid && (*acoef > 1)) return_on_error(TreePutRecord(chan_nid,(struct descriptor *)&signal,0),status);
  return status;
}