Esempio n. 1
0
static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br)
{
	int node = prom_getchild(isa_br->prom_node);

	while (node != 0) {
		struct linux_prom_registers regs[PROMREG_MAX];
		struct sparc_isa_device *isa_dev;
		int prop_len;

		isa_dev = kmalloc(sizeof(*isa_dev), GFP_KERNEL);
		if (!isa_dev) {
			fatal_err("cannot allocate isa_dev");
			prom_halt();
		}

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

		/* Link it in. */
		isa_dev->next = NULL;
		if (isa_br->devices == NULL) {
			isa_br->devices = isa_dev;
		} else {
			struct sparc_isa_device *tmp = isa_br->devices;

			while (tmp->next)
				tmp = tmp->next;

			tmp->next = isa_dev;
		}

		isa_dev->bus = isa_br;
		isa_dev->prom_node = node;
		prop_len = prom_getproperty(node, "name",
					    (char *) isa_dev->prom_name,
					    sizeof(isa_dev->prom_name));
		if (prop_len <= 0) {
			fatal_err("cannot get isa_dev OBP node name");
			prom_halt();
		}

		prop_len = prom_getproperty(node, "compatible",
					    (char *) isa_dev->compatible,
					    sizeof(isa_dev->compatible));

		/* Not having this is OK. */
		if (prop_len <= 0)
			isa_dev->compatible[0] = '\0';

		isa_dev_get_resource(isa_dev, regs, sizeof(regs));
		isa_dev_get_irq(isa_dev, regs);

		report_dev(isa_dev, 0);

		isa_fill_children(isa_dev);

		printk("]");

		node = prom_getsibling(node);
	}
}
Esempio n. 2
0
static void __init isa_fill_children(struct sparc_isa_device *parent_isa_dev)
{
	int node = prom_getchild(parent_isa_dev->prom_node);

	if (node == 0)
		return;

	printk(" ->");
	while (node != 0) {
		struct linux_prom_registers regs[PROMREG_MAX];
		struct sparc_isa_device *isa_dev;
		int prop_len;

		isa_dev = kmalloc(sizeof(*isa_dev), GFP_KERNEL);
		if (!isa_dev) {
			fatal_err("cannot allocate child isa_dev");
			prom_halt();
		}

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

		/* Link it in to parent. */
		isa_dev->next = parent_isa_dev->child;
		parent_isa_dev->child = isa_dev;

		isa_dev->bus = parent_isa_dev->bus;
		isa_dev->prom_node = node;
		prop_len = prom_getproperty(node, "name",
					    (char *) isa_dev->prom_name,
					    sizeof(isa_dev->prom_name));
		if (prop_len <= 0) {
			fatal_err("cannot get child isa_dev OBP node name");
			prom_halt();
		}

		prop_len = prom_getproperty(node, "compatible",
					    (char *) isa_dev->compatible,
					    sizeof(isa_dev->compatible));

		/* Not having this is OK. */
		if (prop_len <= 0)
			isa_dev->compatible[0] = '\0';

		isa_dev_get_resource(isa_dev, regs, sizeof(regs));
		isa_dev_get_irq(isa_dev, regs);

		report_dev(isa_dev, 1);

		node = prom_getsibling(node);
	}
}
Esempio n. 3
0
int main(int argc, char *argv[])
{
    if (argc!=5)
        fatal_err(usage);
    
    double a=conv_segmend(argv[1]);
    double b=conv_segmend(argv[2]);
    if (b<a)
        fatal_err(order);
    
    long int total_segnum=conv_segnum(argv[3]);
    int calcnum=conv_calcnum(argv[4]);
    
    int brdsockfd=init_brd_socket();
    calcmsg_t *calcs=detect_calcs(brdsockfd, &calcnum);
    close(brdsockfd);
    int *confds=distr_task(a, b, total_segnum, calcnum, calcs);
    double res=get_res(calcnum, confds);
    
    printf("%lf\n", res);

    return 0;
}
Esempio n. 4
0
void
debugger_init( void )
{
	struct sockaddr_un addr;

	/* only enable the debugger nub when it is explicitely requested by the user */
	if( !debugger_enabled() )
		return;
	printm("Debugger nub enabled\n");
	sv.sock = -1;

	/* create a unix socket for the debugger */
	socket_name = molsocket_name();		/* malloced */

	unlink( socket_name );
	if( (sv.sock_listen=socket(PF_UNIX, SOCK_STREAM, 0)) < 0 )
		fatal_err("socket");

	addr.sun_family = AF_UNIX;
	strcpy( addr.sun_path, socket_name );
	if( bind(sv.sock_listen, (struct sockaddr*)&addr, sizeof(addr)) < 0 )
		fatal_err("bind");

	if( listen(sv.sock_listen, 2) < 0 )
		fatal_err("listen");

	sv.hup_count = 0;
	sv.async_listener_id = add_async_handler( sv.sock_listen, POLLIN,
						  nub_rcv_connection, 1 /* SIGIO */ );
	/* initialize debugger */
	nub_inited = 1;
	if( debugger_enabled() ) {
		breakpoints_init();
		add_mmu_cmds();
	}
	set_print_hook( debugger_print );
}
Esempio n. 5
0
int
load_macho( const char *image_name )
{
    load_command_t cmd;
    mach_header_t hd;
    int i, pos, fd;

    if( (fd=open(image_name, O_RDONLY)) < 0 )
        fatal_err("opening %s", image_name );

    if( !is_macho(fd) ) {
        close( fd );
        return 1;
    }

    if( read(fd, &hd, sizeof(hd)) != sizeof(hd) )
        fatal("failed to read Mach-O header");

    pos = sizeof(hd);
    for( i=0; i<hd.ncmds; i++, pos+=cmd.cmdsize ) {
        if( pread(fd, &cmd, sizeof(cmd), pos) != sizeof(cmd) )
            break;
        lseek( fd, pos, SEEK_SET );

        if( cmd.cmd == LC_SYMTAB )
            continue;

        /* printm("\nLoad-CMD [%d]: %ld\n", i, cmd.cmd ); */
        switch( cmd.cmd ) {
        case LC_SEGMENT:
            read_segment( fd );
            break;

        case LC_THREAD:
        case LC_UNIXTHREAD:
            read_thread( fd );
            break;
        }
    }
    close( fd );
    return 0;
}
Esempio n. 6
0
int receive_file(EZS *E, char *info) 
{
   char *s;
   int siz;
   int nr = 0;
   int nb;
   char buf[4096];
   FILE *fp;
   while (isspace(*info)) info++;
   for (s=info; *s && !isspace(*s); s++);
   *s++ = '\0';
   while (isspace(*s)) s++;
   siz = atoi(s);
   printf("receiving file '%s' (%d bytes)\n", info, siz);
   if (fp=fopen(info, "w")) {
      while (nr<siz) {
         int n = siz-nr;
         if (n>4096) n = 4096;
         nb = ezs_read(E, buf, n);
         if (nb>0) {
            printf("recv %d bytes\n", nb);
            fwrite(buf, 1, nb, fp);
            nr += nb;
         } else {
            if (ezs_wouldblock(E)) {
               printf("read blocked.  retry in 5 sec\n");
               sleep(5);
            } else fatal_err(E, "readfile");
         }
      }
   } else {
     perror(info);
     exit (1);
   }
   fclose(fp);
   printf("readfile done\n");

}
Esempio n. 7
0
File: lich.c Progetto: mtmiron/lich
static void sigtermexit() { fatal_err(SIGTERM, 1, "lich: caught SIGTERM, exiting.\n"); }
Esempio n. 8
0
File: lich.c Progetto: mtmiron/lich
static void sigintexit() { fatal_err(SIGINT, 1, "lich: caught SIGINT, exiting.\n"); }
Esempio n. 9
0
File: lich.c Progetto: mtmiron/lich
static void sigabrtexit() { fatal_err(SIGABRT, 0, "lich: caught SIGABRT, aborting.\n"); }
Esempio n. 10
0
File: lich.c Progetto: mtmiron/lich
static void sigsegvexit() { fatal_err(SIGSEGV, 0, "lich: caught SIGSEGV, aborting.\n"); }
Esempio n. 11
0
int coll (struct object *objects, struct list *list, double *t_last, double t_now, double dt, int n1_sph, int n1, int n2, int last)
{
	double  x1, y1, z1, x2, y2, z2, x12, y12, z12, r12, sig;
	double  ux1, uy1, uz1, ux2, uy2, uz2;
	double  urx, ury, urz, ur, u12, ur2, t12;
	int     n2_sph, n2_obj, f1, f2, n;


	f1  =(objects[n1_sph].move_flag+1)/2;
	ux1 = objects[n1_sph].u.x*f1;
	uy1 = objects[n1_sph].u.y*f1;
	uz1 = objects[n1_sph].u.z*f1;
	x1  = objects[n1_sph].r.x + ux1*(t_now-t_last[n1_sph]);
	y1  = objects[n1_sph].r.y + uy1*(t_now-t_last[n1_sph]);
	z1  = objects[n1_sph].r.z + uz1*(t_now-t_last[n1_sph]);

	for (n = 1; n <= objects[n1_sph].list[0]; n++)
	{	
		n2_sph = objects[n1_sph].list[n];
		if (range(n2_sph, n1, n2))
		{
			f2  =(objects[n2_sph].move_flag+1)/2;
			ux2 = objects[n2_sph].u.x*f2;
			uy2 = objects[n2_sph].u.y*f2;
			uz2 = objects[n2_sph].u.z*f2;
			x2  = objects[n2_sph].r.x + ux2*(t_now-t_last[n2_sph]);
			y2  = objects[n2_sph].r.y + uy2*(t_now-t_last[n2_sph]);
			z2  = objects[n2_sph].r.z + uz2*(t_now-t_last[n2_sph]);
			x12 = n_image(x1 - x2, max_x);
			y12 = n_image(y1 - y2, max_y);
			z12 = n_image(z1 - z2, max_z);
			urx = ux1 - ux2;
			ury = uy1 - uy2;
			urz = uz1 - uz2;
			sig = objects[n1_sph].r_a + objects[n2_sph].r_a;
			r12 = x12*x12 + y12*y12 + z12*z12 - sig*sig;
			if (r12 < -Tol)  warning ("particle-particle overlap");
			
			ur  = urx*x12 + ury*y12 + urz*z12;
			if (ur < 0.0)
			{
				u12 = urx*urx + ury*ury + urz*urz;
				ur2 = u12*r12;
				if (ur*ur >= ur2)
				{
					t12 = - ur - sqrt(ur*ur - ur2);
					t12 = t12/u12 + t_now;
					if (t12 < dt)
					{
						list[last].t_coll = t12;
						list[last].coll_1 = n1_sph;
						list[last].coll_2 = n2_sph;
						list[last].next   = last + 1;
						last++;
						if (last > MAX_C)  fatal_err("too many collisions: MAX_C exceeded", -1);
					}
				}
			}
		}
	}
	
	
	if (objects[n1_sph].move_flag > 0)
	{
		for (n2_obj = num_sph; n2_obj < num_obj; n2_obj++)
		{
			x12 = (x1 - objects[n2_obj].r.x)*objects[n2_obj].e.x;
			y12 = (y1 - objects[n2_obj].r.y)*objects[n2_obj].e.y;
			z12 = (z1 - objects[n2_obj].r.z)*objects[n2_obj].e.z;

			sig =  objects[n1_sph].r_a;
			r12 = x12 + y12 + z12 - sig;
			if (r12 < -Tol)  warning ("particle-wall overlap");
		
			urx = objects[n1_sph].u.x*objects[n2_obj].e.x;
			ury = objects[n1_sph].u.y*objects[n2_obj].e.y;
			urz = objects[n1_sph].u.z*objects[n2_obj].e.z;
			ur	= urx + ury + urz;
			if (ur < 0.0)
			{
				t12 = -r12/ur + t_now;
				if (t12 < dt)
				{
					list[last].t_coll = t12;
					list[last].coll_1 = n1_sph;
					list[last].coll_2 = n2_obj;
					list[last].next   = last + 1;
					last++;
					if (last > MAX_C)  fatal_err("too many collisions: MAX_C exceeded", -1);
				}
			}
		}
	}
	return (last);
}
static
void scale_and_orient_image (
  int *scale, int *density,
  int width, int height, int left, int top,  /* in 300ths of an inch */
  const char *header, const char *trailer,
  enum orientation *orient,
  int position_on_page,
  enum device device)
{
  Area usable;

  /* Determine printable area expressed in centipoints.  There are 7200
   * centipoints to the inch.  The width and height parameters passed in
   * are expressed in 300ths of an inch, therefore a 24x conversion factor
   * is used on the parameter values.  The default page dimensions STDWIDTH
   * and STDHEIGHT are expressed in inches so must be multiplied by 7200
   * to convert to centipoints.
   */
  page.width = (width >= 0) ? width * 24 : STDWIDTH * 7200;
  page.height = (height >= 0) ? height * 24 : STDHEIGHT * 7200;

  /* Paintjet Xl has a mechanical form feed, not a strip feed. It has
   * a slop of about 1/4 to 1/2 of an inch at the top and bottom.
   * deduct it from the page height.
   */
  if (device == PJETXL)
     page.height = page.height - 7200;

  /* Determine the area usable for the image.  This area will be smaller
   * than the total printable area if margins or header/trailer strings
   * have been specified.  Margins, like width and height discussed above,
   * are expressed in 300ths of an inch and must be converted to centipoints.
   * Header and trailer strings each reduce the available image height
   * by 1/6 inch, or 1200 centipoints (aka CHARHEIGHT).
   */
  usable.width = page.width - ((left > 0) ? (left * 24) : 0);
  usable.height = page.height - ((top > 0) ? (top * 24) : 0)
		  - ((header) ? CHARHEIGHT : 0)
		  - ((trailer) ? CHARHEIGHT : 0);

  /* Quit here if there is no usable image space. */
  if ((usable.width <= 0) || (usable.height <= 0)) {
    fatal_err((catgets(nlmsg_fd,NL_SETN,4,
				"No space available on page for image.")));
  }

  /* Determine image orientation.  The orientation will only be changed if
   * it was not specified by a command line option.  Portrait mode will be
   * used if either the usable printing area or the image area are square.
   * Portrait mode will also be used if the long dimensions of the usable
   * printing area and the image area match, otherwise landscape mode is
   * used.  Portrait mode really means "don't rotate" and landscape mode
   * means "rotate".
   */
  if (*orient == UNSPECIFIED) {
    if ((usable.width == usable.height)
	|| (xwd_header.pixmap_width == xwd_header.pixmap_height))
      *orient = PORTRAIT;
    else
      *orient = ((usable.width < usable.height)
		 == (xwd_header.pixmap_width < xwd_header.pixmap_height))
	? PORTRAIT : LANDSCAPE;
  }

  /* Set the dots-per-inch print density if it was not specified */
  if (*density <= 0) {
    switch(device) {
       case   LJET: *density = 300;
                    break;
       case   PJET: *density = 90;
                    break;
       case PJETXL:
       default:	    *density = 180;
                    break;
    }
  }

  /* Fit image to available area if scale was not specified */
  if (*scale <= 0)
    *scale = scale_raster(*density, *orient, usable);

  /* Determine image clipping limits */
  set_image_limits(*scale, *density, *orient, usable);

  /* Determine header/trailer string length clipping */
  set_header_trailer_limits((char *)header, (char *)trailer, usable.width);

  /* Calculate locations for page layout */
  set_print_locations(*scale, *density, top, left,
		      header, trailer, *orient, position_on_page);

}
Esempio n. 13
0
/* Hydrodynamic forces */
void  hi_force(struct monomer *mon, Float ***velcs_df, double fric, double tau, double dt, int num_beads, Float mon_mass, VSLStreamStatePtr rngstream)
{
  extern struct vector f_ext;
  extern int n_proc, num_proc, num_x;
  extern int max_x, max_y, max_z;
  extern int wall_flag;
  extern int add_noise;
  extern int backflow_flag;
  static int MD_tau=0;

  int mon_proc;
  int i, j, k, q, d;
  long n, nxy, n1;
  int x[DIMS], x1[27][DIMS];
  int qxp, qyp, qzp;
  int qxm, qym, qzm;
  int maxsize[DIMS];
  double x2[DIMS], x3[DIMS], x4[DIMS];
  double **vel, *tmp_pp;
  double weight[27], vel_node[27][DIMS], rho_node[27];
  double temp[DIMS], temp1[DIMS];
  double radius = mon[0].radius;
  double sigma = 2.0*radius;
  double vol;
  double dmass, dmom[3];
  Float dmomentum[Num_Dir], dj_temp[DIMS];
  Float *force, *fforce;

  maxsize[0]=max_x;
  maxsize[1]=max_y;
  maxsize[2]=max_z;

  vol=max_x*max_y*max_z;
 
  force=(Float *)calloc(DIMS, sizeof(Float));
  if(force == 0) fatal_err("cannot allocate force", -1);

  fforce=(Float *)calloc(DIMS*num_beads, sizeof(Float));
  if(fforce == 0) fatal_err("cannot allocate force", -1);

  vel = (double **)calloc (num_beads, sizeof(*vel));
  if (vel == 0)  fatal_err ("cannot allocate vel[][]", -1);
  
  tmp_pp = (double *)calloc (num_beads*DIMS, sizeof(*tmp_pp));
  if (tmp_pp == 0)  fatal_err ("cannot allocate vel[][]", -1);
  for (n1 = 0; n1 < num_beads; n1++)                          /* Assign pointers to pointers */
    {
      vel[n1] = tmp_pp;
      tmp_pp += DIMS;
    }

  /* calculate drag force */
  /* calculate fluid velocity at the monomer coords. */
  for(n1=0; n1< num_beads; n1++) {
    for(d=0; d<DIMS; d++) {
      x[d] = mon[n1].pos[d];
      if(mon[n1].pos[d]-x[d] > 0.5)
	x[d]++;
    }

    fluid_vel(n1, vel, x, velcs_df, mon, weight);
    
    //    if(MD_tau == tau)
    for(d=0; d<DIMS; d++) 
      mon[n1].fluid_vel[d]=vel[n1][d];

    for(d=0; d<DIMS; d++) 
      mon[n1].fricforce[d]=-fric*(mon[n1].vel[d]-vel[n1][d]);
      //mon[n1].fricforce[d]=-fric*(mon[n1].vel[d]);
  }

  /* Generate the random force */
  if(add_noise >= 1 && add_noise !=3)
    fluc_force(fforce, num_beads*DIMS, rngstream);

  /* redistribute momentum to the surrounding lattice */
  n1=0;
  while(n1<num_beads) {
    for(d=0; d<DIMS; d++) {
      x[d] = (int)mon[n1].pos[d];
      if(mon[n1].pos[d]-x[d] > 0.5)
	x[d]=x[d]+1;
    }

    mon_proc = box(x[0],maxsize[0])/num_x;
    if(n_proc == mon_proc) {
      for(i=0; i<DIMS; i++) {
	force[i] = Rho_Fl*mon[n1].fricforce[i];
	force[i] += fforce[n1*DIMS+i];
      }
      
      for(i=0; i<DIMS; i++) {
	mon[n1].f_fluc[i]=fforce[n1*DIMS+i];
	mon[n1].force[i] +=force[i];
      }
      
      dmass = 0.0;
      for(i=0; i<DIMS; i++) {
	dmom[i] = 0.0;
	//	dj_temp[i]=-force[i]/(tau*mon_mass*CS2*Rho_Fl);
	dj_temp[i]=-force[i]*dt/(mon_mass*CS2*Rho_Fl);
	//dj_temp[i]=-force[i]*dt/(CS2*Rho_Fl);
      }
      
      // printf("vel=%le fluidvel=%le force=%le friction=%le\n", mon[n1].vel[0], mon[n1].fluid_vel[0], mon[n1].force[0], force[0]);
      // printf("%le %le %le %le\n", mon[n1].vel[0], mon[n1].fluid_vel[0], mon[n1].force[0], force[0]);
      
      for(q=0; q<Num_Dir; q++) 
	dmomentum[q] = fac[q]*(c_x[q] * dj_temp[0] + c_y[q] * dj_temp[1] + c_z[q] * dj_temp[2]);
      
      /* Use trilinear interpolation to get the fluid velocity at the monomer position */
      for(i=0; i<=2; i++) { 
	for(j=0; j<=2; j++) {
	  for(k=0; k<=2; k++) {
	    n = 9*i+3*j+k;
	    x1[n][2] = box(x[2]+(k-1), maxsize[2])+1;
	    x1[n][1] = box(x[1]+(j-1), maxsize[1])+1;
	    x1[n][0] = box((x[0]+(i-1)), maxsize[0])%num_x+1.0;
	    
	    nxy = x1[n][0]*(maxsize[1]+2)+(x1[n][1]);
	    
	    for(q=0; q<Num_Dir; q++) 
	      velcs_df[nxy][q][x1[n][2]] += dmomentum[q]*weight[n]; 
       
/* 	    for(d=0; d<DIMS; d++) */
/* 	      vel_node[n1][d] = 0.0; */
/* 	    for(q=0; q<Num_Dir; q++) { */
/* 	      vel_node[n1][0] += c_x[q]*velcs_df[nxy][q][x1[2]]; */
/* 	      vel_node[n1][1] += c_y[q]*velcs_df[nxy][q][x1[2]]; */
/* 	      vel_node[n1][2] += c_z[q]*velcs_df[nxy][q][x1[2]]; */

/*       	      dmass += velcs_df[nxy][q][x1[2]]; */
/* 	    } */

/* 	    dmom[0] += vel_node[n1][0]; */
/* 	    dmom[1] += vel_node[n1][1]; */
/* 	    dmom[2] += vel_node[n1][2]; */
	  
/* 	    printf("node (%d %d %d) vel (%le %le %le)\n", x1[0], x1[1], x1[2], vel_node[n1][0], vel_node[n1][1], vel_node[n1][2]); */
  	  } 
 	} 
      }
      /*       printf("dmass=%le dmom=(%le %le %le), djtemp=(%le %le %le)\n", dmass, dmom[0], dmom[1], dmom[2], dj_temp[0], dj_temp[1], dj_temp[2]); */
    }
    n1++;
  }

  if(MD_tau == tau)
    MD_tau =1;
  else 
    MD_tau++;

  free(force);
  free(fforce);
  free(vel[0]);
  free(vel);
}
Esempio n. 14
0
term_t proc_main(process_t *proc, int reductions, term_t *retval)
{
	int allocated_reductions = reductions;		//save initial value to update global counter on return
	apr_time_t main_started = apr_time_now();	//NB: possible performance hit
	apr_interval_time_t elapsed;

	term_t exc_class;
	term_t reason;

	apr_array_header_t *cs = proc->cstack;
	apr_array_header_t *ds = proc->dstack;

	while (reductions > 0)
	{
		apr_byte_t opcode;

resume_after_catch:

		if (proc->stopped_on_breakpoint)
		{
			opcode = proc->breakpoint_command;
			proc->stopped_on_breakpoint = 0;
		}
		else
		{
			opcode = (apr_byte_t)*proc->ip++;
		} 

		switch (opcode)
		{
#include "run_cases.inc"
		default:
			fatal_err("Bad opcode");
		}
	}
	
	// update global reductions counts
	g_reductions += (allocated_reductions - reductions);
	g_reductions0 += (allocated_reductions - reductions);
	
	// update global runtime measures
	elapsed = apr_time_now() - main_started;
	g_runtime += elapsed;
	g_runtime0 += elapsed;

	return AI_YIELD;

cellar:
	// before we forget many stack frames, should be done even outside catch
	proc_trace_stack(proc);
	proc_trace_locals(proc);

	if (proc->catches->nelts > 0)
	{
		catch_t *cat = ((catch_t *)proc->catches->elts)+ proc->catches->nelts-1;

		proc->cstack->nelts = cat->csp;
		proc->dstack->nelts = cat->dsp;
		proc->ebp = cat->ebp;

		proc->mod_index = cat->mod_index;
		proc->code = code_base_starts(proc->base, proc->mod_index);
		proc->ip = cat->ip;

		apr_array_pop(proc->catches);

		push(exc_class);
		push(reason);
		
		// NB: yielding now may cause a performance hit as compiler invisibly
		// generates helluva catches in guards, try to continue without yielding
		//return AI_YIELD;
		
		goto resume_after_catch;
	}
	else
	{
		g_reductions += (allocated_reductions - reductions);
		g_reductions0 += (allocated_reductions - reductions);

		elapsed = apr_time_now() - main_started;
		g_runtime += elapsed;
		g_runtime0 += elapsed;
		
		*retval = reason;
		return exc_class;
	}
}
Esempio n. 15
0
int main(int argc,char *argv[]) {
    int argno;

    fprintf(stderr, "SPI decoder, V%s\n", VERSION);

    argno = HandleOptions(argc,argv);

    if (fileread) {
        if ((datfile = fopen(DATFILENAME,"r")) == NULL) // opne to read from .dat file
            fatal_err(DATFILENAME " open for read failed");
        fprintf(stderr, "Reading from " DATFILENAME "\n");
    }
    else {
        char dev_name[80];
        sprintf(dev_name, "\\\\.\\COM%d", comport);
        fprintf(stderr, "Opening serial port on %s...", dev_name);
        handle_serial = CreateFile(dev_name, GENERIC_READ | GENERIC_WRITE, 0, 0,
            OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
        if (handle_serial!=INVALID_HANDLE_VALUE) {
            dcbSerialParams.BaudRate = 115200;
            dcbSerialParams.ByteSize = 8;
            dcbSerialParams.StopBits = ONESTOPBIT;
            dcbSerialParams.Parity = NOPARITY;
            dcbSerialParams.DCBlength = sizeof(DCB);
            if(SetCommState(handle_serial, &dcbSerialParams) == 0) fatal_err("Error setting serial port parameters");
            timeouts.ReadIntervalTimeout =  100;  		// msec
            timeouts.ReadTotalTimeoutConstant = 200;    // msec
            timeouts.ReadTotalTimeoutMultiplier = 0;  // msec
            timeouts.WriteTotalTimeoutConstant = 50;
            timeouts.WriteTotalTimeoutMultiplier = 10;
            if(SetCommTimeouts(handle_serial, &timeouts) == 0) fatal_err("Error setting serial port timeouts");
            fprintf(stderr,"OK\n");
        }
        else fatal_err("Failed");
        if ((datfile = fopen(DATFILENAME,"a")) == NULL) // open to append to .dat file
            fatal_err(DATFILENAME " open for append failed");
    }

    if ((outfile = fopen(OUTFILENAME,"a")) == NULL) fatal_err(OUTFILENAME " open failed");
    if ((pktfile = fopen(PKTFILENAME,"a")) == NULL) fatal_err(PKTFILENAME " open failed");
    fprintf(pktfile, "\n");

    // atexit(cleanup);
    fprintf(stderr, "Starting.\n");

    while(!kbhit()) {
more_data:
        if (fileread) { // read from .dat file
            if (!fgets(line, MAX_LINE, datfile)) {
                output("***end of file");
                fprintf(stderr, "***end of file");
                cleanup();
                exit(0);
            }
            ++linecnt;
            bytes_read = strlen(line);
            output("got %d bytes from the file\n", bytes_read);
        }
        else {  // read from serial port
            // printf("reading serial port com%d...\n", comport);
            ReadFile(handle_serial, line, MAX_LINE, &bytes_read, NULL);
            line[bytes_read]='\0';
            if (bytes_read != 0) {
                output("got %d bytes from serial port\n", bytes_read);
                fprintf(stderr, "got %d bytes from the serial port\n", bytes_read);
                fprintf(datfile, "%s\n", line);
            }
        }

        if (strcmp(line, "SPI Sniffer\n") == 0) {
            fprintf(stderr, "\"SPI Sniffer\" header line read\n");
            continue;
        }
        // output("decode %n bytes: %s\n", bytes_read, line);
        lineptr = line;
        while (*lineptr != '\0') {
            skip_to_next_data();  // process input up to next master/slave data pair
            if (*lineptr == '\0')break;
next_command:
            if (!read_data_pair()) goto more_data;
            isread = master_data & 0x80; 	// "read register" flag bit
            isburst = master_data & 0x40;	// "burst" flag bit
            regnum = master_data & 0x3f;  	// register number 0 to 63

            if (isread) { //  config register read
                if (regnum >= 0x30 && regnum <= 0x3d && !isburst) { // no, is really command strobe
                    command_strobe();
                }
                else {
                    if(isburst){
                        if (regnum == 0x3f) { // read RX FIFO: receive packet
                            if (!chip_selected) exit_msg("burst RX FIFO write without chip selected", regnum);
                            show_config_reg("read", true);
                            packet.xmit = false;
                            while (1) { // show all burst read data from FIFO
                                if (!skip_timestamp()) goto next_command;
                                if (*lineptr == ']') break; // ends with chip unselect
                                if (!read_data_pair()) goto next_command;
                                output(" %02X", slave_data);
                                if (packet.length < MAX_PKT)	{
                                    packet.data[packet.length++] = slave_data;
                                }
                            }
                            output("\n");
                            packet_decode();
                        }
                        else  { // burst read of other than FIFO: consecutive config registers
                            if (!skip_to_next_data()) goto next_command;
                            while (1) {
                                if (!skip_timestamp()) goto next_command;
                                if (*lineptr == ']') break; // ends with chip unselect
                                if (!read_data_pair()) goto next_command;
                                regval = slave_data;
                                show_config_reg("read", false);
                                if (++regnum >= 0x40) exit_msg("burst read of too many config registers", regnum);
                            }
                        }
                    }
                    else { // regular single-register read
                        if (!read_data_pair()) goto next_command;
                        regval = slave_data;
                        show_config_reg("read", false);
                    }
                }
            }
            else { // register write
                if (regnum >= 0x30 && regnum <= 0x3d && !isburst) { // no, is really command strobe
                    command_strobe();
                }
                else if (regnum == 0x3e) { // write power table
                    if (isburst) {
                        if (!chip_selected) exit_msg("burst power table write without chip selected", regnum);
                        show_config_reg("write", true);
                        while (1) { // show all burst write data to power table
                            if (!skip_timestamp()) goto next_command;
                            if (*lineptr == ']') break; // ends with chip unselect
                            if (!read_data_pair()) goto next_command;
                            output(" %02X", master_data);
                        }
                        output("\n");
                    }
                    else { // non-burst write to power table
                        if (!read_data_pair()) goto next_command;
                        regval = master_data;
                        show_config_reg("write", false);
                    }
                }
                else if (regnum == 0x3f) { // write TX FIFO: transmit packet
                    if (!isburst) exit_msg("implement non-burst TX FIFO write", regnum);
                    if (!chip_selected) exit_msg("burst TX FIFO write without chip selected", regnum);
                    show_config_reg("write", true);
                    packet.xmit = true;
                    while (1) { // show all burst write data to FIFO
                        if (!skip_timestamp()) goto next_command;
                        if (*lineptr == ']') break; // ends with chip unselect
                        if (!read_data_pair()) goto next_command;
                        output(" %02X", master_data);
                        if (packet.length < MAX_PKT) {
                            packet.data[packet.length++] = master_data;
                        }
                    }
                    output("\n");
                    packet_decode();
                }
                else { // writing config register(s)
                    if (isburst) { // burst config register write
                        int bytes_bursted, bytes_changed, start_reg, end_reg;
                        bytes_bursted = 0;
                        bytes_changed = 0;
                        start_reg = regnum;
                        // output("burst config write\n");
                        if (!chip_selected) output("burst write without chip selected at reg %02X", regnum);
                        while (1) { // read all the burst write data
                            if (!skip_timestamp()) goto next_command;
                            if (*lineptr == ']') break; // ends with chip unselect
                            if (regnum > 0x2e) exit_msg("too much burst data", regnum);
                            if (!read_data_pair()) goto next_command;
                            new_config_regs[regnum++] = master_data;
                            ++bytes_bursted;
                        }
                        end_reg = regnum-1;
                        for (regnum=start_reg; regnum<end_reg; ++regnum) {  // show only those that changed
                            if ((new_config_regs[regnum] != current_config_regs[regnum])) {
                                regval = new_config_regs[regnum];
                                show_config_reg(" wrote", false);
                                current_config_regs[regnum] = new_config_regs[regnum];
                                ++bytes_changed;
                            }
                        }
                        show_delta_time();
                        output(" burst wrote %d registers, and %d changed\n", bytes_bursted, bytes_changed);
                    }
                    else {  // single register write
                        if (!read_data_pair()) goto next_command;
                        regval = master_data;
                        show_config_reg("write", false);
                        current_config_regs[regnum] = regval;
                    }
                }
            }
        }
    }
    return 0;
}
Esempio n. 16
0
void __init isa_init(void)
{
	struct pci_dev *pdev;
	unsigned short vendor, device;
	int index = 0;

	vendor = PCI_VENDOR_ID_AL;
	device = PCI_DEVICE_ID_AL_M1533;

	pdev = NULL;
	while ((pdev = pci_get_device(vendor, device, pdev)) != NULL) {
		struct pcidev_cookie *pdev_cookie;
		struct pci_pbm_info *pbm;
		struct sparc_isa_bridge *isa_br;
		int prop_len;

		pdev_cookie = pdev->sysdata;
		if (!pdev_cookie) {
			printk("ISA: Warning, ISA bridge ignored due to "
			       "lack of OBP data.\n");
			continue;
		}
		pbm = pdev_cookie->pbm;

		isa_br = kmalloc(sizeof(*isa_br), GFP_KERNEL);
		if (!isa_br) {
			fatal_err("cannot allocate sparc_isa_bridge");
			prom_halt();
		}

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

		/* Link it in. */
		isa_br->next = isa_chain;
		isa_chain = isa_br;

		isa_br->parent = pbm;
		isa_br->self = pdev;
		isa_br->index = index++;
		isa_br->prom_node = pdev_cookie->prom_node;
		strncpy(isa_br->prom_name, pdev_cookie->prom_name,
			sizeof(isa_br->prom_name));

		prop_len = prom_getproperty(isa_br->prom_node,
					    "ranges",
					    (char *) isa_br->isa_ranges,
					    sizeof(isa_br->isa_ranges));
		if (prop_len <= 0)
			isa_br->num_isa_ranges = 0;
		else
			isa_br->num_isa_ranges =
				(prop_len / sizeof(struct linux_prom_isa_ranges));

		prop_len = prom_getproperty(isa_br->prom_node,
					    "interrupt-map",
					    (char *) isa_br->isa_intmap,
					    sizeof(isa_br->isa_intmap));
		if (prop_len <= 0)
			isa_br->num_isa_intmap = 0;
		else
			isa_br->num_isa_intmap =
				(prop_len / sizeof(struct linux_prom_isa_intmap));

		prop_len = prom_getproperty(isa_br->prom_node,
					    "interrupt-map-mask",
					    (char *) &(isa_br->isa_intmask),
					    sizeof(isa_br->isa_intmask));

		printk("isa%d:", isa_br->index);

		isa_fill_devices(isa_br);

		printk("\n");
	}
}
Esempio n. 17
0
void hs3d (struct object *objects, double dt)
{
  struct list *list;
  double  x12, y12, z12, r12, sum_ke1, sum_ke2;
  double  *t_last, t_next, t_now;
  double  m1, m2, m, t1, t2, w1, w2, sig;
  double  ux1, uy1, uz1, ux2, uy2, uz2;
  double  ur, urx, ury, urz, prx, pry, prz;
  int     n1_sph, n2_sph, f1, f2;
  int     num_sph_coll, num_wall_coll;
  int     first, last, now, next, n_cycle;
	
	   
	
  dt /= (double) Num_Hs3d_Step;
  for (n_cycle = 0; n_cycle < Num_Hs3d_Step; n_cycle++)
    {
      t_last = (double *) calloc (num_sph, sizeof(*t_last));
      list   = (struct list *) calloc (MAX_C, sizeof(struct list));
      if (t_last == 0)  fatal_err ("cannot allocate t_last", num_sph);
      if (list == 0)    fatal_err ("cannot allocate list", MAX_C);
	   
      /*  Create initial collision list    */
	   
      last = 0;   t_now = 0.0;   sum_ke1 = 0.0;
      for (n1_sph = 0; n1_sph < num_sph; n1_sph++)
	{
	  m1  = objects[n1_sph].mass*objects[n1_sph].mass_flag;
	  ux1 = objects[n1_sph].u.x;
	  uy1 = objects[n1_sph].u.y;
	  uz1 = objects[n1_sph].u.z;
	  sum_ke1 += 0.5*m1*(ux1*ux1 + uy1*uy1 + uz1*uz1);
	  last = coll (objects, list, t_last, t_now, dt, n1_sph, 0, n1_sph, last);
	}

      /*  Do all collisions for next dt  */
	   
      first = 0;   t_next = 0.0;   num_sph_coll = 0;  num_wall_coll = 0;
      sum_ke2 = 0.0;
      while (t_next < dt)
	{
	  t_next = dt + 0.1;                                    /* Find next collision */
	  now    = first;
	  while (now < last)
	    {
	      if (list[now].t_coll < t_next)
		{
		  n1_sph = list[now].coll_1;
		  n2_sph = list[now].coll_2;
		  t_next = list[now].t_coll;
		}
	      now = list[now].next;
	    }
		
	  if (t_next < dt)
	    {
	      t_now = t_next;
		
	      m1  = objects[n1_sph].mass;
	      f1  =(objects[n1_sph].move_flag+1)/2;
	      t1  = t_now - t_last[n1_sph];
	      ux1 = objects[n1_sph].u.x*f1;
	      uy1 = objects[n1_sph].u.y*f1;
	      uz1 = objects[n1_sph].u.z*f1;
	      objects[n1_sph].r.x += ux1*t1;
	      objects[n1_sph].r.y += uy1*t1;
	      objects[n1_sph].r.z += uz1*t1;
	      objects[n1_sph].p_str.xx -= m1*ux1*ux1*t1;
	      objects[n1_sph].p_str.yy -= m1*uy1*uy1*t1;
	      objects[n1_sph].p_str.zz -= m1*uz1*uz1*t1;
	      objects[n1_sph].p_str.yz -= m1*uy1*uz1*t1;
	      objects[n1_sph].p_str.zx -= m1*uz1*ux1*t1;
	      objects[n1_sph].p_str.xy -= m1*ux1*uy1*t1;
	      t_last[n1_sph] = t_now;
			
	      if (n2_sph < num_sph)	                          /* Update particle-particle velocities */
		{
		  m2  = objects[n2_sph].mass;
		  f2  =(objects[n2_sph].move_flag+1)/2;
		  t2  = t_now - t_last[n2_sph];
		  ux2 = objects[n2_sph].u.x*f2;
		  uy2 = objects[n2_sph].u.y*f2;
		  uz2 = objects[n2_sph].u.z*f2;
		  objects[n2_sph].r.x += ux2*t2;
		  objects[n2_sph].r.y += uy2*t2;
		  objects[n2_sph].r.z += uz2*t2;
		  objects[n2_sph].p_str.xx -= m2*ux2*ux2*t2;
		  objects[n2_sph].p_str.yy -= m2*uy2*uy2*t2;
		  objects[n2_sph].p_str.zz -= m2*uz2*uz2*t2;
		  objects[n2_sph].p_str.yz -= m2*uy2*uz2*t2;
		  objects[n2_sph].p_str.zx -= m2*uz2*ux2*t2;
		  objects[n2_sph].p_str.xy -= m2*ux2*uy2*t2;
		  t_last[n2_sph] = t_now;
					
		  x12 = n_image(objects[n1_sph].r.x - objects[n2_sph].r.x, max_x);
		  y12 = n_image(objects[n1_sph].r.y - objects[n2_sph].r.y, max_y);
		  z12 = n_image(objects[n1_sph].r.z - objects[n2_sph].r.z, max_z);
		  r12 = x12*x12 + y12*y12 + z12*z12;
		  sig = objects[n1_sph].r_a + objects[n2_sph].r_a;
		  if (fabs(r12-sig*sig) > Tol)  warning ("illegal collision");
		  urx = ux1 - ux2;
		  ury = uy1 - uy2;
		  urz = uz1 - uz2;
		  ur  = (urx*x12 + ury*y12 + urz*z12)/sig;

		  if (objects[n1_sph].move_flag == 2)  f1 = 0;  /* Wall particles unaffected by collisions */
		  if (objects[n2_sph].move_flag == 2)  f2 = 0;

		  m   = 1.0/(f1/m1 + f2/m2);                    /* Reduced mass */
		  prx = m*ur*(1.0 + Elas_C)*x12/sig;            /* Inelastic collision */
		  pry = m*ur*(1.0 + Elas_C)*y12/sig;
		  prz = m*ur*(1.0 + Elas_C)*z12/sig;
		  objects[n1_sph].u.x -= prx*f1/m1;
		  objects[n1_sph].u.y -= pry*f1/m1;
		  objects[n1_sph].u.z -= prz*f1/m1;
		  objects[n2_sph].u.x += prx*f2/m2;
		  objects[n2_sph].u.y += pry*f2/m2;
		  objects[n2_sph].u.z += prz*f2/m2;
		  objects[n1_sph].p.x -= prx;
		  objects[n1_sph].p.y -= pry;
		  objects[n1_sph].p.z -= prz;
		  objects[n2_sph].p.x += prx;
		  objects[n2_sph].p.y += pry;
		  objects[n2_sph].p.z += prz;

		  w1 = (f1/m1)/(f1/m1+f2/m2);
		  w2 = (f2/m2)/(f1/m1+f2/m2);
		  objects[n1_sph].pc_str.xx += prx*x12*w1;
		  objects[n1_sph].pc_str.yy += pry*y12*w1;
		  objects[n1_sph].pc_str.zz += prz*z12*w1;
		  objects[n1_sph].pc_str.yz += pry*z12*w1;
		  objects[n1_sph].pc_str.zx += prz*x12*w1;
		  objects[n1_sph].pc_str.xy += prx*y12*w1;
		  objects[n2_sph].pc_str.xx += prx*x12*w2;
		  objects[n2_sph].pc_str.yy += pry*y12*w2;
		  objects[n2_sph].pc_str.zz += prz*z12*w2;
		  objects[n2_sph].pc_str.yz += pry*z12*w2;
		  objects[n2_sph].pc_str.zx += prz*x12*w2;
		  objects[n2_sph].pc_str.xy += prx*y12*w2;
		  objects[n1_sph].e_diss.c  += 0.5*m*(1.0 - Elas_C*Elas_C)*ur*ur*w1;
		  objects[n2_sph].e_diss.c  += 0.5*m*(1.0 - Elas_C*Elas_C)*ur*ur*w2;
		  if (f1 == 0)  sum_ke2 -= ux1*prx + uy1*pry + uz1*prz;
		  if (f2 == 0)  sum_ke2 += ux2*prx + uy2*pry + uz2*prz;
		  objects[n1_sph].num_coll++;
		  objects[n2_sph].num_coll++;
		  num_sph_coll++;
		}
	      else
		{
		  x12 =(objects[n1_sph].r.x - objects[n2_sph].r.x)*objects[n2_sph].e.x*objects[n2_sph].e.x;
		  y12 =(objects[n1_sph].r.y - objects[n2_sph].r.y)*objects[n2_sph].e.y*objects[n2_sph].e.y;
		  z12 =(objects[n1_sph].r.z - objects[n2_sph].r.z)*objects[n2_sph].e.z*objects[n2_sph].e.z;
		  sig = objects[n1_sph].r_a;
		  if (x12+y12+z12-sig > Tol)  warning ("illegal wall collision");
		  urx = ux1;
		  ury = uy1;
		  urz = uz1;
		  ur  = (urx*x12 + ury*y12 + urz*z12)/sig;
		  m   = m1;                                     /* Reduced mass */
		  prx = m*ur*(1.0 + Elas_C)*x12/sig;            /* Inelastic collision */
		  pry = m*ur*(1.0 + Elas_C)*y12/sig;
		  prz = m*ur*(1.0 + Elas_C)*z12/sig;
		  objects[n1_sph].u.x -= prx/m1;
		  objects[n1_sph].u.y -= pry/m1;
		  objects[n1_sph].u.z -= prz/m1;
		  objects[n1_sph].p.x -= prx;
		  objects[n1_sph].p.y -= pry;
		  objects[n1_sph].p.z -= prz;
		  objects[n2_sph].p.x += prx;
		  objects[n2_sph].p.y += pry;
		  objects[n2_sph].p.z += prz;
		  objects[n1_sph].pc_str.xx += prx*x12;
		  objects[n1_sph].pc_str.yy += pry*y12;
		  objects[n1_sph].pc_str.zz += prz*z12;
		  objects[n1_sph].e_diss.c  += 0.5*m*(1.0 - Elas_C*Elas_C)*ur*ur;
		  objects[n1_sph].num_coll++;
					
		  num_wall_coll++;
		}
			
	      /*	update collision time table  */
			
	      if (n2_sph < num_sph)
		{
		  now  = first;
		  next = list[now].next;
		  while (next < last)
		    {
		      if ((list[next].coll_1 == n1_sph) || (list[next].coll_2 == n1_sph)
			  ||	(list[next].coll_1 == n2_sph) || (list[next].coll_2 == n2_sph))  list[now].next  = list[next].next;
		      else  now  = next;
		      next = list[next].next;
		    }
		  if ((list[first].coll_1 == n1_sph) || (list[first].coll_2 == n1_sph)
		      ||	(list[first].coll_1 == n2_sph) || (list[first].coll_2 == n2_sph))  first = list[first].next;
		  last = coll (objects, list, t_last, t_now, dt, n1_sph, 0, num_sph, last);
		  last = coll (objects, list, t_last, t_now, dt, n2_sph, 0, num_sph, last);
		}
	      else 
		{
		  now  = first;
		  next = list[now].next;
		  while (next < last)
		    {
		      next = list[now].next;
		      if ((list[next].coll_1 == n1_sph) || (list[next].coll_2 == n1_sph))  list[now].next  = list[next].next;
		      else  now  = next;
		      next = list[next].next;
		    }
		  if ((list[first].coll_1 == n1_sph) || (list[first].coll_2 == n1_sph))  first = list[first].next;
		  last = coll (objects, list, t_last, t_now, dt, n1_sph, 0, num_sph, last);
		}
	    }
	}

      /*	 return new coordinates  */

      for (n1_sph = 0; n1_sph < num_sph; n1_sph++)
	{
	  m1  = objects[n1_sph].mass*objects[n1_sph].mass_flag;
	  ux1 = objects[n1_sph].u.x;
	  uy1 = objects[n1_sph].u.y;
	  uz1 = objects[n1_sph].u.z;
	  sum_ke2 += 0.5*m1*(ux1*ux1 + uy1*uy1 + uz1*uz1) + objects[n1_sph].e_diss.c;
	  if (ux1*ux1+uy1*uy1+uz1*uz1 > 1.0) fatal_err ("Particle moving too fast", n1_sph);

	  m1  = objects[n1_sph].mass;
	  f1  =(objects[n1_sph].move_flag+1)/2;
	  t1  = dt-t_last[n1_sph];
	  ux1 *= f1;
	  uy1 *= f1;
	  uz1 *= f1;
	  objects[n1_sph].r.x += ux1*t1;
	  objects[n1_sph].r.y += uy1*t1;
	  objects[n1_sph].r.z += uz1*t1;
	  objects[n1_sph].p_str.xx -= m1*ux1*ux1*t1;
	  objects[n1_sph].p_str.yy -= m1*uy1*uy1*t1;
	  objects[n1_sph].p_str.zz -= m1*uz1*uz1*t1;
	  objects[n1_sph].p_str.yz -= m1*uy1*uz1*t1;
	  objects[n1_sph].p_str.zx -= m1*uz1*ux1*t1;
	  objects[n1_sph].p_str.xy -= m1*ux1*uy1*t1;
	}

      free (t_last);
      free (list);

      if (fabs(sum_ke2-sum_ke1)/(sum_ke1 + Tol) > Tol)
	{
	  fprintf (stdout, "Initial KE = % .5e: Final KE = % .5e\n", sum_ke1, sum_ke2);
	  fatal_err ("Energy conservation error", -1);
	}
      /*		if (n_proc == 0)  fprintf (stdout, " %d particle-particle collision(s): %d particle-wall collision(s)\n", num_sph_coll, num_wall_coll);  */
    }

	

}