Exemple #1
0
static void print_ptable(offset_manager_t *mngr) {
  offset_poly_table_t *table;
  uint32_t i, n;

  table = &mngr->ptable;
  printf("===== ptable ====\n");
  n = table->npolys;
  for (i=0; i<n; i++) {
    printf("poly[%"PRIu32"] := ", i);
    show_poly(table->def[i]);
    printf("        (eterm: t!%"PRId32, table->eterm[i]);
    printf(", active: ");
    print_flag(tst_bit(table->active, i));
    printf(", mark: ");
    print_flag(tst_bit(table->mark, i));
    printf(")\n");
    printf("   normal form: ");
    print_normal_form(&mngr->vtable, table->def[i]);
    printf("\n");
    printf("   vars: ");
    print_var_array(table->vars[i]);
    printf("\n");
  }
  printf("\n");
}
/*
 * Resize the array to at least nb blocks
 * - nb must be more than a->nblocks
 */
static void resize_sparse_array(sparse_array_t *a, uint32_t nb) {
  uint32_t i, nblocks, n;
  uint32_t *tmp;

  if (nb > MAX_NBLOCKS) {
    out_of_memory();
  }

  n = a->nblocks;
  nblocks = n;
  nblocks += nblocks>>1; // try 50% larger
  if (nb > nblocks) {
    nblocks = nb;
  } else if (nblocks > MAX_NBLOCKS) {
    nblocks = MAX_NBLOCKS;
  }

  // n = current size, nblocks = new size
  // we avoid realloc here (to save the cost of copying the full array)
  tmp = (uint32_t *) safe_malloc(nblocks * (BSIZE * sizeof(uint32_t)));
  a->clean = extend_bitvector0(a->clean, n, nblocks);

  // copy all clean blocks from a->data to tmp
  n = a->nblocks;
  for (i=0; i<n; i++) {
    if (tst_bit(a->clean, i)) {
      copy_block(tmp, a->data, i);
    }
  }

  safe_free(a->data);
  a->data = tmp;
  a->nblocks = nblocks;
}
Exemple #3
0
imap()
{
  char buf[BLKSIZE];
  int  imap, ninodes;
  int  i;

  printf("\t\t IMAP \n\n");

  // read SUPER block
  get_block(fd, 1, buf);
  sp = (SUPER *)buf;

  ninodes = sp->s_inodes_count;
  printf("ninodes = %d\n", ninodes);

  // read Group Descriptor 0
  get_block(fd, 2, buf);
  gp = (GD *)buf;

  imap = gp->bg_inode_bitmap;
  printf("imap = %d\n", imap);

  // read inode_bitmap block
  get_block(fd, imap, buf);

  for (i=0; i < ninodes; i++){
    (tst_bit(buf, i)) ?	putchar('1') : putchar('0');
    if (i && ((i+1) % 8)==0)
       printf(" ");
    if(i && ((i+1) % 40) == 0)
	printf("\n");
  }
  printf("\n\n");
}
Exemple #4
0
/*
 * Print the content of set s
 */
static void print_bvset(large_bvset_t *s) {
  uint32_t i, n;

  printf("set %p\n", s);
  printf("  size = %"PRIu32"\n", s->size);
  printf("  nelems = %"PRIu32"\n", s->nelems);
  printf("  max_val = %"PRIu32"\n", s->max_val);
  printf("  fsize = %"PRIu32"\n", s->fsize);
  printf("  nfresh = %"PRIu32"\n", s->nfresh);

  if (s->nelems > 0) {
    printf("  bits:");
    n = s->size;
    for (i=0; i<n; i++) {
      if (tst_bit(s->set, i)) {
	printf(" %"PRIu32, i);
      }
    }
    printf("\n");
  }

  n = s->nfresh;
  if (n > 0) {
    printf("  fresh elements:");
    for (i=0; i<n; i++) {
      printf(" %"PRIu32, s->fresh_vals[i]);
    }
    printf("\n");
  }
}
Exemple #5
0
bmap()
{
  char buf[BLKSIZE];
  int  bmap, blocks;
  int  i;
  
  printf("\t\t BMAP \n\n");  

  // read SUPER block
  get_block(fd, 1, buf);
  sp = (SUPER *)buf;

  blocks = sp->s_blocks_count;
  printf("blocks = %d\n", blocks);

  // read Group Descriptor 0
  get_block(fd, 2, buf);
  gp = (GD *)buf;

  bmap = gp->bg_block_bitmap;
  printf("bmap = %d\n", bmap);

  // read block_bitmap block
  get_block(fd, bmap, buf);

  for (i=0; i < blocks; i++){
    (tst_bit(buf, i)) ?	putchar('1') : putchar('0');
    if (i && ((i+1) % 8)==0)
       printf(" ");
    if(i && ((i+1) % 48) == 0)
	printf("\n");
  }
  printf("\n\n");
}
/*
 * Go through all elements i with a positive ref counter and call f(aux, i)
 */
void sparse_array_iterate(sparse_array_t *a, void *aux, sparse_array_iterator_t f) {
  uint32_t i, n;

  n = a->nblocks;
  for (i=0; i<n; i++) {
    if (tst_bit(a->clean, i)) {
      iterate_in_block(a->data, i, aux, f);
    }
  }
}
/*
 * Read the value mapped to i:
 * - return 0 if i is in a dirty block or outside the array
 */
uint32_t sparse_array_read(sparse_array_t *a, uint32_t i) {
  uint32_t k, y;

  k = block_of_index(i);
  y = 0;
  if (k < a->nblocks && tst_bit(a->clean, k)) {
    y = a->data[i];
  }
  return y;
}
Exemple #8
0
int printBitmap(int fd, int bitmapSize, int bitmapBlock) {
    char * blockBitmap = getBlock(fd, bitmapBlock);
    for (int i = 0; i < bitmapSize; i++) {
        if ((i % 8) == 0)
            printf(" ");
        if ((i % 64) == 0)
            printf("\n");
        (tst_bit(blockBitmap, i)) ? putchar('1') : putchar('0');
    }
    printf("\n");
    return 0;
}
/*
 * Decrement a[i]: the current count must be positive
 */
void sparse_array_decr(sparse_array_t *a, uint32_t i) {
#ifndef NDEBUG
  uint32_t k;

  k = block_of_index(i);
  assert(k < a->nblocks && tst_bit(a->clean, k) && a->data[i] > 0);
#endif

  a->data[i] --;
  if (a->data[i] == 0) {
    assert(a->nelems > 0);
    a->nelems --;
  }
}
int main(void)
{
	/* desabilita os pinos de RX e TX */
	UCSR0B=0x00;
				
	/* Para uso do botão */
	DDRB &= (~(1 << PB0));
	PORTB |= (1 << PB0);
	
	LCD_inicia_4bits();
	
	SPI_MasterInit();
		
    while(1)
    {
		if(!tst_bit(PINB, PB0)) {
			SPI_HABILITA_SLAVE();	
			_delay_ms(20);
			SPI_Transmit('A');
			SPI_DESABILITA_SLAVE();
			while(!tst_bit(PINB, PB0));
		}		
    }
}
Exemple #11
0
/*
 * Increment a[i]
 */
void sparse_array_incr(sparse_array_t *a, uint32_t i) {
  uint32_t k;

  k = block_of_index(i);
  if (k >= a->nblocks) {
    resize_sparse_array(a, k+1);
  }
  if (tst_bit(a->clean, k) && a->data[i] < UINT32_MAX) {
    if (a->data[i] == 0) {
      a->nelems ++;
    }
    a->data[i] ++;
  } else {
    set_bit(a->clean, k);
    clean_block(a->data, k);
    a->data[i] = 1;
    a->nelems ++;
  }
}
int balloc(int devId) {
	int  i;
	char buf[BLKSIZE];

	// read block_bitmap block
	get_block(devId, getBMap(devId), buf);

	for (i=0; i < getNBlocks(devId); i++){
		if (tst_bit(buf, i)==0){
			set_bit(buf,i);
			updateFreeBlocks(devId, -1);

			put_block(devId, getBMap(devId), buf);

			return i+1;
		}
	}
	
	printf("balloc(): no more free inodes\n");
	return 0;
}
//allocates a free block number
int balloc(int dev)
{
	int i;
	char buf[BLKSIZE];

	//read block_map block
	get_block(dev, bmap, buf);

	for(i = 0; i < nblocks; i++)
	{
		if(tst_bit(buf, i) == 0)
		{
			set_bit(buf, i);
			decFreeInodes(dev);

			put_block(dev, bmap, buf);

			return i + 1;
		}
	}
	printf("ERROR: no more free blocks\n");
	return 0;
}
Exemple #14
0
int ialloc(int fd) {
    fputs("ialloc: ##################################################", stdout);
    char buf[BLOCK_SIZE];
    _get_block(fd, 1, buf);
    Super * super = (Super *) buf;
    int ninodes = (int) super->s_inodes_count;
    printf("ninodes = %d\n", ninodes);
    _get_block(fd, 2, buf);
    GroupDesc * gp = (GroupDesc *) buf;
    int imap = (int) gp->bg_inode_bitmap;
    printf("imap = %d\n", imap);
    // read inode_bitmap block
    _get_block(fd, imap, buf);
    for (int i = 0; i < ninodes; i++) {
        if (tst_bit(buf, i) == 0) {
            set_bit(buf, i);
            decFreeInodes(fd);
            put_block(fd, imap, buf);
            return i + 1;
        }
    }
    printf("ialloc(): no more free inodes\n");
    return 0;
}
Exemple #15
0
/*
 * Check color of node x
 */
static inline bool is_red(rba_buffer_t *b, uint32_t x) {
  assert(x < b->num_nodes);
  return tst_bit(b->isred, x);
}
Exemple #16
0
uint8 GPIO_input_state(regPin *pin)
{
    return(tst_bit(*pin->out, pin->pin));
}
int main()
{
    DDRC	= 0xFF;			
	PORTC	= 0x00;			
	DDRD	= 0x00;			
	PORTD	= 0xFF;	
	
	UCSR0B	= 0x00;
			
	while(1)
	{
		while(tst_bit(PIND, B_ENABLE));
		_delay_ms(10);
		set_bit(PORTC, ENA);
		set_bit(PORTC, ENB);		
		while(!tst_bit(PIND, B_ENABLE))
		{
			if(!tst_bit(PIND, B_FORWARD))
			{
				_delay_ms(10);
				FORWARD();		
				while(!tst_bit(PIND, B_FORWARD));
				_delay_ms(10);		
			}			
			if(!tst_bit(PIND, B_BACKWARD))
			{
				_delay_ms(10);
				BACKWARD();
				while(!tst_bit(PIND, B_BACKWARD));	
				_delay_ms(10);			
			}				
			if(!tst_bit(PIND, B_STOP))
			{
				_delay_ms(10);
				STOP();
				while(!tst_bit(PIND, B_STOP));		
				_delay_ms(10);		
			}				
			if(!tst_bit(PIND, B_RIGHT))
			{
				_delay_ms(10);
				RIGHT();
				while(!tst_bit(PIND, B_RIGHT));		
				_delay_ms(10);		
			}				
			if(!tst_bit(PIND, B_LEFT))
			{
				_delay_ms(10);
				LEFT();
				while(!tst_bit(PIND, B_LEFT));		
				_delay_ms(10);		
			}				
			if(!tst_bit(PIND, B_MOVE_ON))
			{
				_delay_ms(10);
				MOVE_ON();
				while(!tst_bit(PIND, B_MOVE_ON));		
				_delay_ms(10);		
			}				
		}
		_delay_ms(10);
		clr_bit(PORTC, ENA);
		clr_bit(PORTC, ENB);		
	}	
} /*MAIN*/