示例#1
0
/*
 * Implements the /sys/class/pcmcia_socket/??/status file.
 *
 * Returns: the number of characters added to the buffer
 */
static ssize_t show_status(
	struct device *dev, struct device_attribute *attr, char *buf)
{
	struct soc_pcmcia_socket *skt =
		container_of(dev, struct soc_pcmcia_socket, socket.dev);
	char *p = buf;

	p += sprintf(p, "slot     : %d\n", skt->nr);

	dump_bits(&p, "status", skt->status,
		  status_bits, ARRAY_SIZE(status_bits));
	dump_bits(&p, "csc_mask", skt->cs_state.csc_mask,
		  status_bits, ARRAY_SIZE(status_bits));
	dump_bits(&p, "cs_flags", skt->cs_state.flags,
		  conf_bits, ARRAY_SIZE(conf_bits));

	p += sprintf(p, "Vcc      : %d\n", skt->cs_state.Vcc);
	p += sprintf(p, "Vpp      : %d\n", skt->cs_state.Vpp);
	p += sprintf(p, "IRQ      : %d (%d)\n", skt->cs_state.io_irq,
		skt->socket.pci_irq);
	if (skt->ops->show_timing)
		p += skt->ops->show_timing(skt, p);

	return p-buf;
}
示例#2
0
int main() {
/*
    S2 s2;
    s2.a = (1 << 23) - 1;
    s2.b = 1;
    s2.c = 1;
    s2.r = 0;
    dump_bits(*(unsigned long long*)&s2);
    printf("%d\n", s2.a);
*/

    S s;
    //s.a = 0;
    //s.ll = (1ULL << 50) -  1;
    s.ll = 0x123456789aULL;
    printf("%llx\n", s.ll);
    printf("%llx\n", s.ll++);
    s.r = 0;
    //s.ll = 0x123456789a;
    //s.r = 0;

    //printf("%llu\n", 0xffffffffffffffffULL);
    //printf("%llu\n", 0xffffffffffffULL);
    dump_bits(s.ll);
    printf("%llx\n", s.ll);
    dump_bits(*(unsigned long long*)&s);
}
示例#3
0
文件: bits.c 项目: Distrotech/dirac
int
main (int argc, char *argv[])
{
  int i;
  SchroBuffer *buffer = schro_buffer_new_and_alloc (100);
  SchroBits *bits;
  int value;
  int fail = 0;
  int n;

  schro_init();

  printf("unsigned int\n");
  for(i=0;i<21;i++) {
    bits = schro_bits_new();
    schro_bits_encode_init (bits, buffer);
    schro_bits_encode_uint(bits,i);
    schro_bits_flush (bits);
    n = schro_bits_get_offset (bits);
    schro_bits_free (bits);

    bits = schro_bits_new();
    schro_bits_decode_init (bits, buffer);
    printf("%3d:", i);
    dump_bits (bits, n);
    value = schro_bits_decode_uint (bits);
    if (value != i) {
      printf("decode failed (%d != %d)\n", value, i);
      fail = 1;
    }
    schro_bits_free (bits);
  }
  printf("\n");

  printf("signed int\n");
  for(i=-5;i<6;i++) {
    bits = schro_bits_new();
    schro_bits_encode_init (bits, buffer);
    schro_bits_encode_sint(bits,i);
    schro_bits_flush (bits);
    n = schro_bits_get_offset (bits);
    schro_bits_free (bits);

    bits = schro_bits_new();
    schro_bits_decode_init (bits, buffer);
    printf("%3d:", i);
    dump_bits (bits, n);
    value = schro_bits_decode_sint (bits);
    if (value != i) {
      printf("decode failed (%d != %d)\n", value, i);
      fail = 1;
    }
    schro_bits_free (bits);
  }
  printf("\n");

  return fail;
}
示例#4
0
int merge_check(Puzzle *puz, Solution *sol)
{
    MergeElem *m;
    //dir_t z;
    int found= 0;
    
    for (m= merge_list; m != NULL; m= m->next)
    {
        if (m->maxc == merge_no && m->cell != NULL)
        {
            if (VM)
            {
                printf("M: FOUND MERGED CONSEQUENCE ON CELL (%d,%d) BITS ",
                       m->cell->line[0], m->cell->line[1]);
                dump_bits(stdout, puz, m->bit);
                printf("\n");
            }
            
            /* Add to history as a necessary consequence */
            add_hist(puz, m->cell, 0);
            
            /* Set the new value in the cell */
#ifdef LIMITCOLORS
            oldval[0]= m->cell->bit[0];
            m->cell->bit[0]&= ~m->bit[0];
#else
            for (z= 0; z < fbit_size; z++)
            {
                oldval[z]= m->cell->bit[z];
                m->cell->bit[z]&= ~m->bit[z];
            }
#endif
            if (puz->ncolor <= 2)
                m->cell->n= 1;
            else
                count_cell(puz,m->cell);
            
            if (m->cell->n == 1) solved_a_cell(puz, m->cell,1);
            
            /* Add rows/columns containing this cell to the job list */
            add_jobs(puz, sol, -1, m->cell, 0, oldval);
            
            found= 1;
        }
        /* Reset to unused state */
        m->cell= NULL;
    }
    if (VM && !found) printf("M: NO MERGE CONSEQUENCES\n");
    
    merge_list= NULL;
    merge_no= -1;
    merging= 0;
    
    return found;
}
示例#5
0
void dump_merge(Puzzle *puz)
{
    MergeElem *m;
    int n= 0;
    
    for (m= merge_list; m != NULL; m= m->next)
    {
        if (n++ > 1000) {printf("Yicks!\n"); /*exit(1);*/ return;}
        if (m->cell)
        {
            printf("  %d: CELL (%d,%d) BITS ",n,
                   m->cell->line[0], m->cell->line[1]);
            dump_bits(stdout, puz, m->bit);
            printf("\n");
        }
        else
            printf("  %d: NULL\n",n);
    }
}
示例#6
0
static struct trace *blkiomon_do_trace(struct trace *t)
{
	struct trace *t_stored, *t_old, *t_young;

	/* store trace if there is no match yet */
	t_stored = blkiomon_fetch_trace(&t->bit);
	if (!t_stored) {
		blkiomon_store_trace(t);
		return blkiomon_alloc_trace();
	}

	/* figure out older trace and younger trace */
	if (t_stored->bit.time < t->bit.time) {
		t_old = t_stored;
		t_young = t;
	} else {
		t_old = t;
		t_young = t_stored;
	}

	/* we need an older D trace and a younger C trace */
	if (t_old->bit.action & BLK_TC_ACT(BLK_TC_ISSUE) &&
	    t_young->bit.action & BLK_TC_ACT(BLK_TC_COMPLETE)) {
		/* matching D and C traces - update statistics */
		match++;
		blkiomon_account(&t_old->bit, &t_young->bit);
		blkiomon_free_trace(t_stored);
		return t;
	}

	/* no matching D and C traces - keep more recent trace */
	dump_bits(t_old, t_young, "mismatch");
	mismatch++;
	blkiomon_store_trace(t_young);
	return t_old;
}
示例#7
0
int backtrack(Puzzle *puz, Solution *sol)
{
    Hist *h;
    //color_t z, oldn, newn;
    //dir_t k;

    if (VB) printf("B: BACKTRACKING TO LAST GUESS\n");

    /* Undo up to, but not including, the most recent branch point */
    if (undo(puz,sol, 1))
    {
        if (VB) printf("B: CANNOT BACKTRACK\n");
        return 1;
    }

    if (VB) print_solution(stdout,puz,sol);

    /* This will be the branch point since undo() backed us up to it */
    h= HIST(puz, puz->nhist-1);

    if (VB || WC(h->cell))
    {
        printf("B: LAST GUESS WAS ");
        print_coord(stdout,puz,h->cell);
        printf(" |");
        dump_bits(stdout,puz,h->bit);
        printf("| -> |");
        dump_bits(stdout,puz,h->cell->bit);
        printf("|\n");
    }

    /* If undoing a solved cell, uncount it */
    if (h->cell->n == 1) solved_a_cell(puz, h->cell, -1);

    /* Reset any bits previously set */
#ifdef LIMITCOLORS
    h->cell->bit[0]= ((~h->cell->bit[0]) & h->bit[0]);
#else
    for (z= 0; z < fbit_size; z++)
        h->cell->bit[z]= ((~h->cell->bit[z]) & h->bit[z]);
#endif
    h->cell->n= h->n - h->cell->n;  /* Since the bits set in h are always
				       a superset of those in h->cell,
				       this should always work */

    /* If inverted cell is solved, count it */
    if (h->cell->n == 1) solved_a_cell(puz, h->cell, 1);

    if (VB || WC(h->cell))
    {
        printf("B: INVERTING GUESS TO |");
        dump_bits(stdout,puz,h->cell->bit);
        printf("| (%d)\n",h->cell->n);
    }

    /* Now that we've backtracked to it and inverted it, it is no
     * longer a branch point.  If there is no previous history, delete
     * this node.  Otherwise, convert it into a non-branch point.
     * Next time we backtrack we will just delete it.
     */
    if (puz->nhist == 1)
        puz->nhist= 0;
    else
        h->branch= 0;

    /* Remove everything from the job list except the lines containing
     * the inverted cell.
     */
    if (maylinesolve)
    {
        flush_jobs(puz);
        add_jobs(puz, sol, -1, h->cell, 0, h->bit);
    }

    backtracks++;

    return 0;
}
示例#8
0
int undo(Puzzle *puz, Solution *sol, int leave_branch)
{
    Hist *h;
    Clue *clue;
    Cell **line;
    dir_t k;
    int is_branch;
    line_t i;

    while (puz->nhist > 0)
    {
        h= HIST(puz, puz->nhist-1);

        /* Invalidate any saved positions for lines crossing undone cell.
         * We can't just have the fact that nhist < stamp mean the line is
         * invalid, because we might backtrack and then advance past stamp
         * again before we recheck the line.
         */
        for (k= 0; k < puz->nset; k++)
        {

            i= h->cell->line[k];
            clue= &(puz->clue[k][i]);
            line= sol->line[k][i];

            if ((VL && VU) || WL(*clue))
                printf("U: CHECK %s %d", CLUENAME(puz->type,k),i);

            left_undo(puz, clue, line, h->cell->index[k], h->bit);
            right_undo(puz, clue, line,  h->cell->index[k], h->bit);

            if ((VL && VU) || WL(*clue)) printf("\n");
        }

        is_branch= h->branch;

        if (!is_branch || !leave_branch)
        {
            /* If undoing a solved cell, decrement completion count */
            if (h->cell->n == 1) solved_a_cell(puz, h->cell, -1);

            /* Restore saved value */
            h->cell->n= h->n;
            fbit_cpy(h->cell->bit, h->bit);

            if (VU || WC(h->cell))
            {
                printf("U: UNDOING CELL ");
                for (k= 0; k < puz->nset; k++)
                    printf(" %d",h->cell->line[k]);
                printf(" TO ");
                dump_bits(stdout,puz,h->cell->bit);
                printf(" (%d)\n",h->cell->n);
            }

            puz->nhist--;
        }

        if (is_branch)
            return 0;
    }
    return 1;
}
示例#9
0
int main(int argc, char *argv[])
{
	int fd;
	int res, x;
	struct dahdi_params tp;
	struct dahdi_bufferinfo bi;
	int bs = BLOCK_SIZE;
	int pos = 0;
	unsigned char inbuf[BLOCK_SIZE];
	unsigned char outbuf[BLOCK_SIZE];
	int bytes = 0;
	int out;
	unsigned int olddata1;
	int oldones1;
	int oldbits1;
	unsigned int olddata = 0;
	int oldones = 0;
	int oldbits = 0;
	int hdlcmode = 0;
	struct fasthdlc_state fs;
	if (argc < 2) {
		fprintf(stderr, "Usage: %s <DAHDI device>\n", argv[0]);
		exit(1);
	}
	fd = open(argv[1], O_RDWR, 0600);
	if (fd < 0) {
		fprintf(stderr, "Unable to open %s: %s\n", argv[1], strerror(errno));
		exit(1);
	}
	if (ioctl(fd, DAHDI_SET_BLOCKSIZE, &bs)) {
		fprintf(stderr, "Unable to set block size to %d: %s\n", bs, strerror(errno));
		exit(1);
	}
	if (ioctl(fd, DAHDI_GET_PARAMS, &tp)) {
		fprintf(stderr, "Unable to get channel parameters\n");
		exit(1);
	}
	if ((tp.sigtype & DAHDI_SIG_HDLCRAW) == DAHDI_SIG_HDLCRAW) {
		printf("In HDLC mode\n");
		hdlcmode = 1;
	} else if ((tp.sigtype & DAHDI_SIG_CLEAR) == DAHDI_SIG_CLEAR) {
		printf("In CLEAR mode\n");
		hdlcmode = 0;
	} else {
		fprintf(stderr, "Not in a reasonable mode\n");
		exit(1);
	}
	res = ioctl(fd, DAHDI_GET_BUFINFO, &bi);
	if (!res) {
		bi.txbufpolicy = DAHDI_POLICY_IMMEDIATE;
		bi.rxbufpolicy = DAHDI_POLICY_IMMEDIATE;
		bi.numbufs = 4;
		res = ioctl(fd, DAHDI_SET_BUFINFO, &bi);
		if (res < 0) {
			fprintf(stderr, "Unable to set buf info: %s\n", strerror(errno));
			exit(1);
		}
	} else {
		fprintf(stderr, "Unable to get buf info: %s\n", strerror(errno));
		exit(1);
	}
	ioctl(fd, DAHDI_GETEVENT);
	fasthdlc_precalc();
	fasthdlc_init(&fs, FASTHDLC_MODE_64);
	for (;;) {
		res = read(fd, outbuf, sizeof(outbuf));
		if (hdlcmode) {
			if (res < 0) {
				if (errno == ELAST) {
					if (ioctl(fd, DAHDI_GETEVENT, &x) < 0) {
						fprintf(stderr, "Unaable to get event: %s\n", strerror(errno));
						exit(1);
					}
					fprintf(stderr, "Event: %d (%d bytes since last error)\n", x, bytes);
					bytes = 0;
					continue;
				} else {
					fprintf(stderr, "Error: %s\n", strerror(errno));
					exit(1);
				}
			}
#if 0
			printf("Res is %d, buf0 is %d, buf1 is %d\n", res, outbuf[0], outbuf[1]);
#endif
			if (res < 2) {
				fprintf(stderr, "Too small?  Only got %d bytes\n", res);
			}
			check_frame(outbuf, res);
		} else {
			for (x = 0; x < res; x++) {
				oldones1 = oldones;
				oldbits1 = oldbits;
				olddata1 = olddata;
				oldones = fs.ones;
				oldbits = fs.bits;
				olddata = fs.data;
				fasthdlc_rx_load(&fs, outbuf[x]);
				out = fasthdlc_rx_run(&fs);
				if (out & RETURN_EMPTY_FLAG) {
					/* Empty */
				} else if (out & RETURN_COMPLETE_FLAG) {
					if (pos && (pos < 2)) {
						printf("Too short? (%d)\n", pos);
					} else if (pos) {
						check_frame(inbuf, pos);
					}
					pos = 0;
				} else if (out & RETURN_DISCARD_FLAG) {
					printf("Discard (search = %d, len = %d, buf = %d, x=%d, res=%d, oldones: %d, oldbits: %d)\n",
						   c, pos, inbuf[0], x, res, oldones, oldbits);
					dump_bitslong(olddata, oldbits);
					printf("Discard                                                 oldones: %d, oldbits: %d)\n",
						   oldones1, oldbits1);
					dump_bitslong(olddata1, oldbits1);
					if (x > 64) {
						dump_bits(outbuf + x - 64, 64);
						dump_bits(outbuf + x, 64);
					}
					pos = 0;
				} else {
					if ((out != c) && (pos < c) && !pos) {
						printf("Warning: Expecting %d at pos %d, got %d (x =%d)\n", c, pos, out, x);
						if (x > 64) {
							dump_bits(outbuf + x - 64, 64);
							dump_bits(outbuf + x, 64);
						}
					}
					inbuf[pos++] = out;
				}
			}
		}
	}

}
示例#10
0
void merge_set(Puzzle *puz, Cell *cell, bit_type *bit)
{
    MergeElem *m;
    //    MergeElem *p;
    //    color_t z;
    //    int zero;
    
    /* Get the merge element for this cell */
    m= &mergegrid[cell->id];
    
    if (m->cell == NULL)
    {
        /* If this is not the first guess, and the cell is not already on the
         * list, do nothing.  */
    	if (merge_no > 0) return;
        
        /* Otherwise, make a new merge list entry */
        m->cell= cell;
        m->maxc= merge_no;
#ifdef LIMITCOLORS
        m->bit[0]= cell->bit[0] & ~bit[0];
#else
        for (z= 0; z < fbit_size; z++)
            m->bit[z]= cell->bit[z] & ~bit[z];
#endif
        m->next= merge_list;
        merge_list= m;
        if (VM)
        {
            printf("M: NEW MERGE CELL (%d,%d) L%d BITS ",
                   m->cell->line[0], m->cell->line[1], merge_no);
            dump_bits(stdout, puz, m->bit);
            printf("\n");
        }
        return;
    }
    
    if (m->maxc == merge_no)
    {
    	/* If cell has already been updated on this pass, and this is not
         * pass zero, then we can't record the change correctly, so we don't
         * record them.  We might miss some merges this way, but this is a
         * really rare occurance that happens only on really successful probes,
         * which are likely to be our next guess anyway.
         */
        if (merge_no == 0)
	    /* If this is pass zero, the we can OR the changes in because
	     * we haven't ANDed it with anything else yet */
            m->bit[0]|= cell->bit[0] & ~bit[0];
        
        if (VM)
        {
            printf("M: REVISITING MERGE CELL (%d,%d) L%d BITS ",
                   m->cell->line[0], m->cell->line[1], merge_no);
            dump_bits(stdout, puz, m->bit);
            printf("\n");
        }
        
        return;
    }
    
    /* If the cell is on the list from previous probe, intersect the changes */
#ifdef LIMITCOLORS
    m->bit[0]&= cell->bit[0] & ~bit[0];
    if (m->bit[0] == 0)
#else
        zero= 1;
    for (z= 0; z < fbit_size; z++)
    {
    	m->bit[z]&= cell->bit[z] & ~bit[z];
        if (m->bit[z]) zero= 0;
        
    }
    if (zero)
#endif
    {
    	/* No intersection - mark the node for deletion. Actual
         * deletion from linked list happens during merge_guess. */
        
        if (VM) printf("M: DROPPING MERGE CELL (%d,%d) L%d\n",
                       m->cell->line[0], m->cell->line[1], merge_no);
        
        m->cell= NULL;
    }
    else
    {
    	/* Had some intersection - keep the node */
        m->maxc= merge_no;
        
        if (VM)
        {
            printf("M: UPDATING MERGE CELL (%d,%d) L%d BITS ",
                   m->cell->line[0], m->cell->line[1], merge_no);
            dump_bits(stdout, puz, m->bit);
            printf("\n");
        }
    }
}