Exemplo n.º 1
0
/*
 * mii_bitbang_sync:
 *
 *	Synchronize the MII.
 */
void
mii_bitbang_sync(device_t dev, mii_bitbang_ops_t ops)
{
	int i;
	uint32_t v;

	v = MDIRPHY | MDO;

	MWRITE(v);
	for (i = 0; i < 32; i++) {
		MWRITE(v | MDC);
		MWRITE(v);
	}
}
Exemplo n.º 2
0
/*
 * mii_bitbang_sendbits:
 *
 *	Send a series of bits to the MII.
 */
static void
mii_bitbang_sendbits(device_t dev, mii_bitbang_ops_t ops, uint32_t data,
    int nbits)
{
	int i;
	uint32_t v;

	v = MDIRPHY;
	MWRITE(v);

	for (i = 1 << (nbits - 1); i != 0; i >>= 1) {
		if (data & i)
			v |= MDO;
		else
			v &= ~MDO;
		MWRITE(v);
		MWRITE(v | MDC);
		MWRITE(v);
	}
}
Exemplo n.º 3
0
/*
 * mii_bitbang_writereg:
 *
 *	Write a PHY register by bit-bang'ing the MII.
 */
void
mii_bitbang_writereg(device_t dev, mii_bitbang_ops_t ops, int phy, int reg,
    int val)
{

	mii_bitbang_sync(dev, ops);

	mii_bitbang_sendbits(dev, ops, MII_COMMAND_START, 2);
	mii_bitbang_sendbits(dev, ops, MII_COMMAND_WRITE, 2);
	mii_bitbang_sendbits(dev, ops, phy, 5);
	mii_bitbang_sendbits(dev, ops, reg, 5);
	mii_bitbang_sendbits(dev, ops, MII_COMMAND_ACK, 2);
	mii_bitbang_sendbits(dev, ops, val, 16);

	MWRITE(MDIRPHY);
}
Exemplo n.º 4
0
/*
 * mii_bitbang_readreg:
 *
 *	Read a PHY register by bit-bang'ing the MII.
 */
int
mii_bitbang_readreg(device_t dev, mii_bitbang_ops_t ops, int phy, int reg)
{
	int i, error, val;

	mii_bitbang_sync(dev, ops);

	mii_bitbang_sendbits(dev, ops, MII_COMMAND_START, 2);
	mii_bitbang_sendbits(dev, ops, MII_COMMAND_READ, 2);
	mii_bitbang_sendbits(dev, ops, phy, 5);
	mii_bitbang_sendbits(dev, ops, reg, 5);

	/* Switch direction to PHY->host, without a clock transition. */
	MWRITE(MDIRHOST);

	/* Turnaround clock. */
	MWRITE(MDIRHOST | MDC);
	MWRITE(MDIRHOST);

	/* Check for error. */
	error = MREAD & MDI;

	/* Idle clock. */
	MWRITE(MDIRHOST | MDC);
	MWRITE(MDIRHOST);

	val = 0;
	for (i = 0; i < 16; i++) {
		val <<= 1;
		/* Read data prior to clock low-high transition. */
		if (error == 0 && (MREAD & MDI) != 0)
			val |= 1;

		MWRITE(MDIRHOST | MDC);
		MWRITE(MDIRHOST);
	}

	/* Set direction to host->PHY, without a clock transition. */
	MWRITE(MDIRPHY);

	return (error != 0 ? 0 : val);
}
Exemplo n.º 5
0
int main(int argc, char* argv[])
{
    int i, iter, niter, p[6][2], status, *mask;
    float *buf, *buf2, *wht;
    double rn, rnp, alpha, beta;
    pid_t pid[6]={1,1,1,1,1,1};
    off_t nm, nd, msiz, dsiz, pos;
    size_t nbuf, mbuf, dbuf;
    FILE *xfile, *Rfile, *gfile, *sfile, *Sfile;
    char *x, *R, *g, *s, *S, *prog;
    sf_file mod, dat, from, mwt, x0, known;  /* input */
    sf_file to, out; /* output */

    extern int fseeko(FILE *stream, off_t offset, int whence);
    extern off_t ftello (FILE *stream);

    sf_init(argc,argv);

    dat = sf_input("in");
    mod = sf_input("mod");

    if (SF_FLOAT != sf_gettype(mod) ||
	SF_FLOAT != sf_gettype(dat)) 
	sf_error("Need float type in mod and dat");

    for (i=0; i < argc-1; i++) {
	argv[i]=argv[i+1];
    }
    for (i=0; i < argc-1; i++) {	
	/* find the program to run */
	if (NULL == strchr(argv[i],'=')) {
	    /* first one without the '=' */
	    prog = argv[0];
	    argv[0] = argv[i];
	    argv[i] = prog;
	    break;
	}
    }

    argv[argc-1] = sf_charalloc(6);
    snprintf(argv[argc-1],6,"adj=X");

    if (!sf_getint("niter",&niter)) niter=1;
    /* number of iterations */

    Rfile = sf_tempfile(&R,"w+b"); 
    xfile = sf_tempfile(&x,"w+b"); 
    gfile = sf_tempfile(&g,"w+b");
    sfile = sf_tempfile(&s,"w+b");
    Sfile = sf_tempfile(&S,"w+b");

    fclose(Rfile);
    fclose(xfile);
    fclose(gfile);
    fclose(sfile);
    fclose(Sfile);

    nm = sf_filesize(mod);
    nd = sf_filesize(dat);

    /* I/O buffers */
    nbuf = BUFSIZ/sizeof(float);
    buf  = sf_floatalloc(nbuf);
    buf2 = sf_floatalloc(nbuf);

    if (NULL != sf_getstring("mwt")) {
	mwt = sf_input("mwt"); /* model weight */
	wht = sf_floatalloc(nbuf);
    } else {
	mwt = NULL;
	wht = NULL;
    }

    if (NULL != sf_getstring("known")) {
	known = sf_input("known"); /* known model mask */
	if (SF_INT != sf_gettype(known)) sf_error("Need int type in known");
	mask = sf_intalloc(nbuf);
    } else {
	known = NULL;
	mask = NULL;
    }

    if (NULL != sf_getstring("x0")) {
	x0 = sf_input("x0"); /* initial model */
    } else {
	x0 = NULL;
    }

    for (i=0; i < 6; i++) { /* make six pipes */
	if (pipe(p[i]) < 0) sf_error("pipe error:");
    }

    for (iter=0; iter < niter; iter++) {
	for (i=0; i < 6; i++) { /* fork six children */
	    if ((pid[i] = fork()) < 0) sf_error("fork error:");
	    if (0 == pid[i]) break;
	}
	
	if (0 == pid[0]) {	
	    /* feeds rr to p[0] */
	    close(p[0][0]);
	    close(STDOUT_FILENO);
	    DUP(p[0][1]);

	    to = sf_output("out");

	    if (0 == iter) {
		xfile = fopen(x,"wb");

		if (NULL == x0) {
		    for (i=0; i < nbuf; i++) { buf[i] = 0.0f; }
		}
		
		MLOOP( if (NULL != x0) sf_floatread(buf,mbuf,x0);
		       MWRITE(xfile); );
		
		fclose(xfile);

		Rfile = fopen(R,"wb");
		DLOOP( sf_floatread(buf,dbuf,dat); 
		       for (i=0; i < dbuf; i++) { buf[i] = -buf[i]; }
		       sf_floatwrite(buf,dbuf,to);
		       DWRITE (Rfile); );
Exemplo n.º 6
0
int main(int argc, char* argv[])
{
    int i, iter, niter;
    sf_complex *buf, *buf2;
    double rn, rnp, alpha, beta;
    off_t nm, nd, msiz, dsiz, pos;
    size_t nbuf, mbuf, dbuf, len, iolen, cmdlen;
    FILE *xfile, *Rfile, *gfile, *Gfile, *sfile, *Sfile;
    char *x, *R, *g, *G, *s, *S, *prog, *cmdline, *iostring, *arg;
    sf_file mod, dat, x0;  /* input */
    sf_file Rrsf, Grsf, grsf, out; /* output */

    extern int fseeko(FILE *stream, off_t offset, int whence);
    extern off_t ftello (FILE *stream);

    sf_init(argc,argv);

    dat = sf_input("--input");
    mod = sf_input("mod");

    out = sf_output("--output");
    sf_fileflush(out,mod);
    sf_settype(out,SF_COMPLEX);

    if (SF_COMPLEX != sf_gettype(mod) ||
	SF_COMPLEX != sf_gettype(dat)) 
	sf_error("Need complex type in mod and dat");

    for (i=0; i < argc-1; i++) {
	argv[i]=argv[i+1];
    }
    for (i=0; i < argc-1; i++) {	
	/* find the program to run */
	if (NULL == strchr(argv[i],'=')) {
	    /* first one without the '=' */
	    prog = argv[0];
	    argv[0] = argv[i];
	    argv[i] = prog;
	    break;
	}
    }

    argv[argc-1] = sf_charalloc(6);
    snprintf(argv[argc-1],6,"adj=X");

    if (!sf_getint("niter",&niter)) niter=1;
    /* number of iterations */

    Rfile = sf_tempfile(&R,"w+"); 
    xfile = sf_tempfile(&x,"w+b"); 
    gfile = sf_tempfile(&g,"w+");
    Gfile = sf_tempfile(&G,"w+");
    sfile = sf_tempfile(&s,"w+b");
    Sfile = sf_tempfile(&S,"w+b");

    fclose(Rfile); Rrsf = sf_output(R); sf_readwrite(Rrsf,true); sf_fileflush(Rrsf,dat);
    fclose(xfile);
    fclose(gfile); 
    fclose(Gfile); 
    fclose(sfile);
    fclose(Sfile);

    nm = sf_filesize(mod);
    nd = sf_filesize(dat);

    /* I/O buffers */
    nbuf = BUFSIZ/sizeof(sf_complex);
    buf  = sf_complexalloc(nbuf);
    buf2 = sf_complexalloc(nbuf);

    cmdline = sf_charalloc(SF_CMDLEN);
    iostring = sf_charalloc(SF_CMDLEN);
    cmdlen = 0;
    for (i=0; i < argc; i++) {
	arg = argv[i];
	len = strlen(arg);
	if (cmdlen+len > SF_CMDLEN-2) sf_error("command line is too long");

	strncpy(cmdline+cmdlen,arg,len);
	cmdline[cmdlen+len]=' ';
	cmdlen += len+1;
    }

    if (NULL != sf_getstring("x0")) {
	x0 = sf_input("x0"); /* initial model */
    } else {
	x0 = NULL;
    }

    for (iter=0; iter < niter; iter++) {
	if (0 == iter) {
	    xfile = fopen(x,"wb");
	    
	    if (NULL == x0) {
		for (i=0; i < nbuf; i++) { buf[i] = sf_cmplx(0.0f,0.0f); }
	    }
	    
	    MLOOP( if (NULL != x0) sf_complexread(buf,mbuf,x0);
		   MWRITE(xfile); );
	    
	    fclose(xfile);
#ifdef SF_HAS_COMPLEX_H 
	    DLOOP( sf_complexread(buf,dbuf,dat); 
		   for (i=0; i < dbuf; i++) { buf[i] = -buf[i]; }
		   sf_complexwrite(buf,dbuf,Rrsf); );