Example #1
0
/* Seek zip->fp to compressed data
   return:
	==0 success
	<0 error
*/
int seekcompresszip(ZIP* zip, struct zipent* ent) {
	char buf[ZIPNAME];
	long offset;

	if (!zip->fp) {
		if (!revivezip(zip))
			return -1;
	}

	if (osd_fseek(zip->fp, ent->offset_lcl_hdr_frm_frst_disk, SEEK_SET)!=0) {
		errormsg ("Seeking to header", ERROR_CORRUPT, zip->zip);
		return -1;
	}

	if (osd_fread(zip->fp, buf, ZIPNAME)!=ZIPNAME) {
		errormsg ("Reading header", ERROR_CORRUPT, zip->zip);
		return -1;
	}

	{
		UINT16 filename_length = read_word (buf+ZIPFNLN);
		UINT16 extra_field_length = read_word (buf+ZIPXTRALN);

		/* calculate offset to data and osd_fseek() there */
		offset = ent->offset_lcl_hdr_frm_frst_disk + ZIPNAME + filename_length + extra_field_length;

		if (osd_fseek(zip->fp, offset, SEEK_SET) != 0) {
			errormsg ("Seeking to compressed data", ERROR_CORRUPT, zip->zip);
			return -1;
		}

	}

	return 0;
}
Example #2
0
void vbe_biosfn_restore_video_state(uint16_t ES, uint16_t BX)
{
    uint16_t    enable, i;

    enable = read_word(ES, BX);
    BX += 2;

    if (!(enable & VBE_DISPI_ENABLED)) {
        outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_ENABLE);
        outw(VBE_DISPI_IOPORT_DATA, enable);
    } else {
        outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_XRES);
        outw(VBE_DISPI_IOPORT_DATA, read_word(ES, BX));
        BX += 2;
        outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_YRES);
        outw(VBE_DISPI_IOPORT_DATA, read_word(ES, BX));
        BX += 2;
        outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_BPP);
        outw(VBE_DISPI_IOPORT_DATA, read_word(ES, BX));
        BX += 2;
        outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_ENABLE);
        outw(VBE_DISPI_IOPORT_DATA, enable);

        for(i = VBE_DISPI_INDEX_BANK; i <= VBE_DISPI_INDEX_Y_OFFSET; i++) {
            outw(VBE_DISPI_IOPORT_INDEX, i);
            outw(VBE_DISPI_IOPORT_DATA, read_word(ES, BX));
            BX += 2;
        }
    }
}
Example #3
0
File: fat.c Project: carld/interim
void read_fat_bs(uint8_t* buf, struct fat_BS* bs) {
  memcpy(bs->bootjmp,buf,3);
  memcpy(bs->oem_name,buf+3,8);
  
  bs->bytes_per_sector      = read_halfword(buf, 11);
  bs->sectors_per_cluster   = read_byte(buf, 13);
  bs->reserved_sector_count = read_halfword(buf, 14);
  bs->table_count           = read_byte(buf, 16);
  bs->root_entry_count      = read_halfword(buf, 17);
  bs->total_sectors_16      = read_halfword(buf, 19);
  bs->media_type            = read_byte(buf, 21);
  bs->table_size_16         = read_halfword(buf, 22);
  bs->sectors_per_track     = read_halfword(buf, 24);
  bs->head_side_count       = read_halfword(buf, 26);
  bs->hidden_sector_count   = read_word(buf, 28);
  bs->total_sectors_32      = read_word(buf, 32);

  if (bs->table_size_16==0) {
    memcpy(&bs->ext,buf+36,sizeof(struct fat_extBS_32));
  } else {
    bs->ext.fat16.bios_drive_num = read_byte(buf,36);
    bs->ext.fat16.reserved1 = read_byte(buf,37);
    bs->ext.fat16.boot_signature = read_byte(buf,38);
    bs->ext.fat16.volume_id = read_word(buf,39);
    memcpy(&bs->ext.fat16.volume_label,buf+43,11);
    memcpy(&bs->ext.fat16.fat_type_label,buf+54,8);
  }
}
Example #4
0
static void reset_registers(void) {
	uint32_t vectortable = read_word(VECTOR_TABLE_OFFSET);

	// R[0..12] = bits(32) UNKNOWN {nop}

	SW(&sp_main,read_word(vectortable) & 0xfffffffc);

	// sp_process = ((bits(30) UNKNOWN):'00')
	SW(&sp_process, SR(&sp_process) & ~0x3);

	CORE_reg_write(LR_REG, 0xFFFFFFFF);

	uint32_t tmp = read_word(vectortable+4);
	bool tbit = tmp & 0x1;
	CORE_reg_write(PC_REG, tmp & 0xfffffffe);
	if (! (tmp & 0x1) ) {
		WARN("Reset vector %08x at %08x invalid\n", tmp, vectortable+4);
		CORE_ERR_unpredictable("Thumb bit must be set for M-series\n");
	}

	// ASPR = bits(32) UNKNOWN {nop}

	union ipsr_t ipsr = CORE_ipsr_read();
	ipsr.bits.exception = 0;
	CORE_ipsr_write(ipsr);

	union epsr_t epsr = CORE_epsr_read();
	epsr.bits.T = tbit;
	epsr.bits.ICI_IT_top = 0;
	epsr.bits.ICI_IT_bot = 0;
	CORE_epsr_write(epsr);
}
Example #5
0
Elf32_Shdr *
elf_find_next_higher_section(Elf32_Word offset)
{
  Elf32_Shdr *section;
  Elf32_Shdr *higher;
  Elf32_Word sectionsize;
  int numsections;
  int i = 0;

  section = (Elf32_Shdr *)FILE_OFFSET(read_word(elf_header->e_shoff));
  sectionsize = read_half(elf_header->e_shentsize);
  numsections = read_half(elf_header->e_shnum);

  higher = NULL;

  for (i=0;i<numsections;i++) {
    if (read_word(section->sh_offset) >= offset) {
      if (higher == NULL) {
	higher = section;
      } else if (read_word(section->sh_offset) < read_word(higher->sh_offset)) {
	higher = section;
      }
    }
    
    section = (Elf32_Shdr *)((char *)section + sectionsize);
  }
  
  return higher;
}
unsigned int enqueue_key(uint8_t scan_code, uint8_t ascii_code)
{
    uint16_t    buffer_start, buffer_end, buffer_head, buffer_tail, temp_tail;

#if BX_CPU < 2
    buffer_start = 0x001E;
    buffer_end   = 0x003E;
#else
    buffer_start = read_word(0x0040, 0x0080);
    buffer_end   = read_word(0x0040, 0x0082);
#endif

    buffer_head = read_word(0x0040, 0x001A);
    buffer_tail = read_word(0x0040, 0x001C);

    temp_tail = buffer_tail;
    buffer_tail += 2;
    if (buffer_tail >= buffer_end)
        buffer_tail = buffer_start;

    if (buffer_tail == buffer_head)
        return(0);

    write_byte(0x0040, temp_tail, ascii_code);
    write_byte(0x0040, temp_tail+1, scan_code);
    write_word(0x0040, 0x001C, buffer_tail);
    return(1);
}
Example #7
0
/* emu8k_detect:
 *  Locate the EMU8000. This tries to extract the base port from the E section
 *  of the BLASTER environment variable, and then does some test reads to check
 *  that there is an EMU8000 there.
 */
int emu8k_detect() {
 char *envvar;
 if (!(envvar=getenv("BLASTER"))) {
  sprintf(allegro_error,"BLASTER environment variable not set");
  return 0;
 }

 _emu8k_baseport=0;
 while (*envvar) {
  if (*envvar=='E') _emu8k_baseport=strtol(envvar+1,NULL,16);
  while ((*envvar!=' ')&&(*envvar!=0)) envvar++;
  if (*envvar) envvar++;
 }
 if (!_emu8k_baseport) {
  sprintf(allegro_error,"BLASTER environment variable has no E section");
  return 0;
 }

 sprintf(allegro_error,"AWE32 detection failed on port 0x%04x",_emu8k_baseport);

 if ((read_word(7, 0,3)&0x000f)!=0x000c) return 0;
 if ((read_word(1,29,1)&0x007e)!=0x0058) return 0;
 if ((read_word(1,30,1)&0x0003)!=0x0003) return 0;

 *allegro_error=0;
 return 1;
}
Example #8
0
static zip_error get_compressed_data_offset(zip_file *zip, UINT64 *offset)
{
	file_error error;
	UINT32 read_length;

	/* make sure the file handle is open */
	if (zip->file == nullptr)
	{
		int filerr = osd_open(zip->filename, OPEN_FLAG_READ, &zip->file, &zip->length);
		if (filerr != FILERR_NONE)
			return ZIPERR_FILE_ERROR;
	}

	/* now go read the fixed-sized part of the local file header */
	error = osd_read(zip->file, zip->buffer, zip->header.local_header_offset, ZIPNAME, &read_length);
	if (error != FILERR_NONE || read_length != ZIPNAME)
		return (error == FILERR_NONE) ? ZIPERR_FILE_TRUNCATED : ZIPERR_FILE_ERROR;

	/* compute the final offset */
	*offset = zip->header.local_header_offset + ZIPNAME;
	*offset += read_word(zip->buffer + ZIPFNLN);
	*offset += read_word(zip->buffer + ZIPXTRALN);

	return ZIPERR_NONE;
}
Example #9
0
void opcode_dict_unserialize(opcode_dict_t od, reader_t r, void* dl_handle) {
	long i,j,tot,typtot;
	const char* name;

	/* read dict header and check it against "DIC" */
	name = read_string(r);
	assert(!strcmp(name,"DIC"));
	
	/* read number of arrays, check it against OpcodeTypeMax */
	typtot = read_word(r);
	assert(typtot==OpcodeTypeMax);

	/* now for each array */
	for(i=0;i<OpcodeTypeMax;i+=1) {
		/* read number of records in array */
		tot = read_word(r);
		/* now for each record */
		for(j=0;j<tot;j+=1) {
			/* retrieve name */
			typtot = read_word(r);
			name = read_string(r);
			assert(typtot == 1+strlen(name));
			opcode_dict_add(od, i, name, opcode_stub_resolve(i,name,dl_handle));
		}
		/* read END OF RECORD */
		typtot = read_word(r);
		assert(typtot==0xFFFFFFFF);
	}
}
Example #10
0
RegExp::RegExp(char* expression) {
	this->operations.reserve(64);
	this->transducers.reserve(64);
	this->expression = expression;
	
	for (ui i = 0; i < strlen(expression); i++) {
		switch(expression[i]) {
			case '<': {
					char* input = read_word(i);
					char* output = read_word(++i);
					i+=2;
					ui weight = read_number(i);
					Monoid monoid(input, output, weight);
					this->transducers.push_back(new Transducer(monoid));
				}
				break;
			case '|':
				this->operations.push_back(UNION);
				break;
			case '*':
				this->operations.push_back(STAR);
				break;
			case '.':
				this->operations.push_back(CONCAT);
				break;
		}
	}
}
Example #11
0
void show_heap(void) {
  // TODO: change the code, since i change the heap_tail to one byte after
  void* p = heap_head;
  DebugStr("-----------------\n");
  DebugStr("heap_head = %x, heap size = %u\n",
           p, (char*)heap_tail  - (char*)heap_head);
  DebugStr("-----------------\n");
  DebugStr("%x\n", (char*)p + WSIZE);
  DebugStr("%x\n", (char*)p + 2 * WSIZE);
  DebugStr("-----------------\n");
  p = (char*)p + 3 * WSIZE;
  assert(p < heap_tail);
  while (get_size(p) > 0) {
    assert(p < heap_tail);
    DebugStr("hdrp:%x val = ", p);
    to_hex_str(*(size_t*)p, 1);
    DebugStr("size = %u, ALLOC = %d, PREV_ALLOC = %d\n",
             get_size(p), !!get_alloc(p), !!get_prev_alloc(p));
    void *ftrp = (char*)p + get_size(p) - WSIZE;
    DebugStr("ftrp:%x val = ", ftrp);
    to_hex_str(*(size_t*)ftrp, 1);
    if (!get_alloc(p)) { // if current block is not allocated, header = footer
      assert(read_word(p) == read_word(ftrp));
    }
    DebugStr("-----------------\n");
    p += get_size(p);
  }
  DebugStr("heap_tail = %x\n", p);
  DebugStr("-----------------\n");
}
Example #12
0
void EEPROM::loadCalibration(int16_t * xMin, int16_t * xMax, int16_t * yMin, int16_t * yMax)
{
  *xMin = read_word(EEPROM_CAL_XMIN);
  *xMax = read_word(EEPROM_CAL_XMAX);
  *yMin = read_word(EEPROM_CAL_YMIN);
  *yMax = read_word(EEPROM_CAL_YMAX);
}
Example #13
0
Elf32_Shdr *
elf_find_section_named(char *name)
{
  Elf32_Shdr *section;
  Elf32_Shdr *strtab_section;
  Elf32_Word sectionsize;
  int numsections;
  char *strtab;
  int i = 0;

  section = (Elf32_Shdr *)FILE_OFFSET(read_word(elf_header->e_shoff));

  strtab_section = elf_find_section_num(read_half(elf_header->e_shstrndx));
  
  strtab = (char *)FILE_OFFSET(read_word(strtab_section->sh_offset));
  
  sectionsize = read_half(elf_header->e_shentsize);
  numsections = read_half(elf_header->e_shnum);

  for (i=0;i<numsections;i++) {
    if (strcmp(&strtab[read_word(section->sh_name)], name) == 0) {
      return section;
    }
    section = (Elf32_Shdr *)((char *)section + sectionsize);
  }
  return NULL;
}
Example #14
0
/*
 * read_images: Reads the images from and mnist image db file and puts the
 *              images into and array of vectors.
 *
 * Parameters:
 *  - train: boolean value, read from training db if 0, test db if 1
 *
 * Return value:
 *  - array of vectors containing mnist images
 */ 
mnist_images_t read_images(uint32_t train)
{
    // Set the filename based the mode (train or test)
    char *full_path;
    if (train) {
        full_path = concat_fname(mnist_path, train_image_fname);
    } else {
        full_path = concat_fname(mnist_path, test_image_fname);
    }

    // Open the file for reading
    char *mode = FILE_MODE;
    FILE *fp = Fopen(full_path, mode); 

    // Read the header of the file
    uint8_t header[IMAGE_HEADER_SIZE];
    Fread(header, sizeof(uint8_t), IMAGE_HEADER_SIZE, fp);

    // Extract size info from mnist db header
    uint32_t num_images = read_word(header, NUM_ITEMS_OFFSET);
    uint32_t rows = read_word(header, ROW_OFFSET);
    uint32_t cols = read_word(header, COL_OFFSET);
    uint32_t img_size = rows * cols;

    // Create array of mnist image vectors
    vector_t *mnist_data = (vector_t*) Calloc(num_images, sizeof(vector_t));
    
    // Populate vectors with one image each
    for (uint32_t i = 0; i < num_images; i++) {
        mnist_data[i] = Vector((size_t) img_size);

        uint8_t *image_bytes = (uint8_t*) Calloc(img_size, sizeof(uint8_t));
        uint32_t actual_size;
        // Read img_size bytes from the db file into the byte array
        if ((actual_size = fread(image_bytes, sizeof(uint8_t), img_size, fp)) < img_size) {
            Free(image_bytes);
            for (uint32_t i = 0; i < num_images; i++) vector_destroy(mnist_data[i]);
            return NULL;
        }

        // Move 8 bit data to 32 bit integer for more precision
        uint32_t *vector_data = (uint32_t*) Calloc(img_size, sizeof(uint32_t));
        for (uint32_t j = 0; j < img_size; j++) {
            vector_data[j] = (uint32_t) image_bytes[j];
        }
        mnist_data[i]->data = vector_data;
        Free(image_bytes);
    }

    // Create the mnist_images_t pointer and populate the struct it points to
    mnist_images_t mnist_imgs = Mnist_images((size_t) num_images); 
    mnist_imgs->imgs = mnist_data;

    Free(full_path);
    Fclose(fp);
    return mnist_imgs;
}
Example #15
0
print_bin(){
	if(dbg.flag != 0)puts("");
	return;
	printf(" |%04X %04X %04X %04X\n", 
			read_word(PC-2),
			read_word(PC),
			read_word(PC+2),
			read_word(PC+4));
}
Example #16
0
uint32_t PCI::pciCheckVendor(uint32_t bus, uint32_t slot)
{
	uint32_t vendor, device;
	/* check if device is valid */
	if ((vendor = read_word(bus, slot, 0, 0)) != 0xFFFF)
	{
		device = read_word(bus, slot, 0, 2);
		/* valid device */
	} return (vendor);
}
Example #17
0
static int
read_flash(Environ *e, Self *s, int offset, uByte *data, int len)
{
	int actual = 0;
	int width = s->meths->width;
	int mask = width - 1;
	int i;

	DPRINTF(("read_flash: offset %#x, data %#x, len %d\n", offset, data, len));

	if (offset & mask)
	{
		int n = width - (offset & mask);
		DPRINTF(("read_flash: %d unaligned bytes at %#x\n", n, offset));

		if (n > len)
			n = len;

		read_word(e, s, offset, s->buf);

		for (i = 0; i < n; i++)
			data[i] = s->buf[(offset & mask) + i];

		data += n;
		len -= n;
		actual += n;
		offset += n;
	}

	while (len >= width)
	{
		read_word(e, s, offset, data);
#if 0
		DPRINTF(("read_flash: %d bytes at %#x, %#x %#x\n", width, offset, data[0], data[1]));
#endif
		data += width;
		len -= width;
		actual += width;
		offset += width;
	}

	if (len)
	{
		read_word(e, s, offset, s->buf);
		DPRINTF(("read_flash: %d trailing bytes at %#x, %#x\n", len, offset, s->buf[0]));

		for (i = 0; i < len; i++)
			data[i] = s->buf[i];

		actual += len;
	}

	DPRINTF(("read_flash: actual = %d\n", actual));
	return actual;
}
Example #18
0
/*---------------------------------------------------------------------------*/
static void
thread_rollback(int fd)
{
#if INCLUDE_RAM
  unsigned char *addr;
  uint16_t size = 0;
  unsigned char *thread_mem_start = (unsigned char *)&checkpoint_thread.thread.stack;
  unsigned char *thread_mem_end = thread_mem_start + sizeof(checkpoint_thread.thread.stack);
  unsigned char *coffee_mem_start = cfs_coffee_get_protected_mem(&size);
  unsigned char *coffee_mem_end = coffee_mem_start + size;
#endif /* INCLUDE_RAM */

  /*PRINTF("protected thread memory: %u, size=%u\n", (uint16_t) thread_mem_start, sizeof(checkpoint_thread.thread.stack));*/
  /*PRINTF("protected coffee memory: %u, size=%u\n", (uint16_t) coffee_mem_start, size);*/

  /* RAM */
#if INCLUDE_RAM
  if (coffee_mem_start < thread_mem_start) {
    read(fd, RAM_START, coffee_mem_start-RAM_START);
    read(fd, coffee_mem_end, thread_mem_start-coffee_mem_end);
    read(fd, thread_mem_end, RAM_END-thread_mem_end);
  } else {
    read(fd, RAM_START, thread_mem_start-RAM_START);
    read(fd, thread_mem_end, coffee_mem_start-thread_mem_end);
    read(fd, coffee_mem_end, RAM_END-coffee_mem_end);
  }
#endif /* INCLUDE_RAM */

  /* Timers */
#if INCLUDE_TIMERS
  TACTL = read_word(fd);
  TACCTL1 = read_word(fd);
  TACCR1 = read_word(fd);
  TAR = read_word(fd);

  TBCTL = read_word(fd);
  TBCCTL1 = read_word(fd);
  TBCCR1 = read_word(fd);
  TBR = read_word(fd);
#endif /* INCLUDE_TIMERS */

  /* LEDs */
#if INCLUDE_LEDS
  leds_arch_set(read_byte(fd));
#endif /* INCLUDE_LEDS */

  /* UART DMA */
#if INCLUDE_UART_DMA
  read_word(fd); /* DMA0SZ ignored */
  uart1_reset_dma();
#endif /* INCLUDE_UART_DMA */

  /* Radio */
  /* ADC */
  /* ... */

#if INCLUDE_PADDING
  read_byte(fd);
#endif /* INCLUDE_PADDING */
}
bool are_anagrams(const char *str1,const char *str2)
{
	int cnt1[26]={0},cnt2[26]={0};
	int i;
	read_word(cnt1,str1);
	read_word(cnt2,str2);
	for(i=0;i<26;i++){
		if(cnt1[i]!=cnt2[i])
			return false;
	}
	return true;
}
Example #20
0
static int
read_user_entry(FILE *secrets_file, user_entry_t *user_entry)
{
    int rc;

retry:
    if (feof(secrets_file)) {
        return -1;
    }

    rc = read_word(secrets_file, user_entry->name);
    if ('#' == rc || -1 == rc) {
        seek_eoln(secrets_file);
        goto retry;
    }

    if ('\n' == rc) {
        goto retry;
    }

    rc = read_word(secrets_file, user_entry->server);
    if ('#' == rc || -1 == rc) {
        seek_eoln(secrets_file);
        goto retry;
    }

    if ('\n' == rc) {
        goto retry;
    }

    rc = read_word(secrets_file, user_entry->secret);
    if ('#' == rc || -1 == rc) {
        seek_eoln(secrets_file);
        goto retry;
    }

    if ('\n' == rc) {
        goto retry;
    }

    rc = read_word(secrets_file, user_entry->addr);
    if (-1 == rc) {
        seek_eoln(secrets_file);
        goto retry;
    }

    if ('\n' != rc) {
        seek_eoln(secrets_file);
    }

    return 0;
}
Example #21
0
int read_long(uint32_t *data)
{
	uint16_t l,h;
	if (read_word(&h)) {
		return 1;
	}
	if (read_word(&l)) {
		return 1;
	}
	((uint16_t*)data)[0] = l;
	((uint16_t*)data)[1] = h;
	return 0;
}
Example #22
0
void ulcd_wait_event(ulcd_dev *dev, ulcd_event *event) {
    // Get coords
    write_char(dev, 0x6F);
    write_char(dev, 0x00);
    event->x = read_word(dev);
    event->y = read_word(dev);

    // Get type
    write_char(dev, 0x6F);
    write_char(dev, 0x04);
    event->type = read_word(dev);
    read_word(dev);
}
Example #23
0
int main( void )
{
  int counts1[26] = {};
  int counts2[26] = {};

  read_word( counts1 );
  read_word( counts2 );

  // "empty" strings introduce whitespace
  printf("The words are%s anagrams.", equal_array(counts1, counts2) ? "" : " not");

  return 0;
}
Example #24
0
static int read_end_of_cent_dir (FILE *fp, t_end_of_cent_dir *ecd)
{
	int	count, read;
	int	sigoffset;
	int	err;

	sigoffset=0;

	/* determine how many bytes to read */
	if (gZipLen > BUFSIZE)
		count = BUFSIZE;
	else
		count = gZipLen;

	/* seek to end of file - count */
	err = fseek (fp, -count, SEEK_END);
	if (err!=0){
		ERRORMSG ("Error in zipfile: fseek failed\n");
		return err;
	}

	/* read entire file or BUFSIZE bytes into buffer */
	read = fread (input_buffer, 1, count, fp);

	if (read == count){
		/* locate end-of-central-dir sig */
		err = find_ecd_sig (input_buffer, count, &sigoffset);
		if (err==0){
			char *p = input_buffer+sigoffset;

			/* read end-of-central-dir */
			ecd->end_of_cent_dir_sig = read_dword (p+ZIPESIG);
			ecd->number_of_this_disk = read_word (p+ZIPEDSK);
			ecd->number_of_disk_start_cent_dir = read_word (p+ZIPECEN);
			ecd->total_entries_cent_dir_this_disk = read_word (p+ZIPENUM);
			ecd->total_entries_cent_dir = read_word (p+ZIPECENN);
			ecd->size_of_cent_dir = read_dword (p+ZIPECSZ);
			ecd->offset_to_start_of_cent_dir = read_dword (p+ZIPEOFST);
			ecd->zipfile_comment_length = read_word (p+ZIPECOML);
		}
		else{
			ERRORMSG ("Error in zipfile: couldn't find 'end of central dir' signature\n");
		}
	}
	else{
		ERRORMSG ("Error in zipfile: couldn't read %d bytes from end of file\n", count);
		err = -1;
	}
	return err;
}
Example #25
0
void ADC0Seq0_Handler()
{
	int ADCdata = 0;
	ADCdata = read_word(ADC0, 0x048);
	if(ADCdata < 1024)
	{
		__disable_irq();
		turnOffMotorPower();
		while(read_word(ADC0, 0x048) < 1024){};
			__enable_irq();	
	}
	write_word(ADC0, 0x00C, 0xFF); // clear interrupt

}
Example #26
0
int main(void)
{
	int counts1[N_LETTERS] = {0}, counts2[N_LETTERS] = {0};

	read_word(counts1);
	read_word(counts2);

	if (equal_array(counts1, counts2)) {
		printf("The words are anagrams.\n");
	} else {
		printf("The words are not anagrams.\n");
	}

	return 0;
}
Example #27
0
void *
dynamic_find_tag(Elf32_Shdr *dynamic, Elf32_Sword d_tag)
{
  int i;
  Elf32_Dyn *element;

  element = (Elf32_Dyn *)FILE_OFFSET(read_word(dynamic->sh_offset));
  for (i=0; read_sword(element[i].d_tag) != DT_NULL; i++) {
    if (read_sword(element[i].d_tag) == d_tag) {
      return FILE_OFFSET(read_word(element[i].d_un.d_ptr));
    }
  }
  
  return NULL;
}
void AP_BattMonitor_SMBus_Maxell::timer()
{
	// check if PEC is supported
    if (!check_pec_support()) {
        return;
    }

    uint16_t data;
    uint32_t tnow = AP_HAL::micros();

    // read voltage (V)
    if (read_word(BATTMONITOR_SMBUS_MAXELL_VOLTAGE, data)) {
        _state.voltage = (float)data / 1000.0f;
        _state.last_time_micros = tnow;
        _state.healthy = true;
    }

    // read cell voltages
    for (uint8_t i = 0; i < BATTMONITOR_SMBUS_MAXELL_NUM_CELLS; i++) {
        if (read_word(maxell_cell_ids[i], data)) {
            _has_cell_voltages = true;
            _state.cell_voltages.cells[i] = data;
        } else {
            _state.cell_voltages.cells[i] = UINT16_MAX;
        }
    }

    // timeout after 5 seconds
    if ((tnow - _state.last_time_micros) > AP_BATTMONITOR_SMBUS_TIMEOUT_MICROS) {
        _state.healthy = false;
        return;
    }

    // read current (A)
    if (read_word(BATTMONITOR_SMBUS_MAXELL_CURRENT, data)) {
        _state.current_amps = -(float)((int16_t)data) / 1000.0f;
        _state.last_time_micros = tnow;
    }

    read_full_charge_capacity();

    // FIXME: Preform current integration if the remaining capacity can't be requested
    read_remaining_capacity();

    read_temp();

    read_serial_number();
}
Example #29
0
/*---------------------------------------------------------------------------*/
static void
thread_rollback(int fd)
{
#if INCLUDE_RAM
  unsigned char *addr;
  uint16_t size = 0;
  unsigned char *thread_mem_start = (unsigned char *)&checkpoint_thread.thread.stack;
  unsigned char *thread_mem_end = thread_mem_start + sizeof(checkpoint_thread.thread.stack) - 1;
  unsigned char *coffee_mem_start = cfs_coffee_get_protected_mem(&size);
  unsigned char *coffee_mem_end = coffee_mem_start + size - 1;
#endif /* INCLUDE_RAM */

  /*PRINTF("protected thread memory: %u, size=%u\n", (uint16_t) thread_mem_start, sizeof(checkpoint_thread.thread.stack));*/
  /*PRINTF("protected coffee memory: %u, size=%u\n", (uint16_t) coffee_mem_start, size);*/

  /* RAM */
#if INCLUDE_RAM
  for(addr = (unsigned char *)RAM_START;
  addr < (unsigned char *)RAM_END;
  addr++) {
    if((addr >= thread_mem_start && addr <= thread_mem_end)) {
      /* Skip */
      continue;
    }

    if((addr >= coffee_mem_start && addr <= coffee_mem_end)) {
      /* Skip */
      continue;
    }

    *addr = read_byte(fd);
  }
#endif /* INCLUDE_RAM */

  /* Timers */
#if INCLUDE_TIMERS
  TACTL = read_word(fd);
  TACCTL1 = read_word(fd);
  TACCR1 = read_word(fd);
  TAR = read_word(fd);

  TBCTL = read_word(fd);
  TBCCTL1 = read_word(fd);
  TBCCR1 = read_word(fd);
  TBR = read_word(fd);
#endif /* INCLUDE_TIMERS */

  /* LEDs */
#if INCLUDE_LEDS
  leds_arch_set(read_byte(fd));
#endif /* INCLUDE_LEDS */

  /* Radio */
  /* ADC */
  /* ... */

  read_byte(fd); /* Coffee padding byte */
}
Example #30
0
static int read(struct proc *p, int addr)
{
	char temp[5];
	int i;

	if (addr < 0 || addr > 89) {
		fprintf(stderr, "read: invalid addresss\n");
		return -1;
	}
	for (i=0; i<10; i++) {
		read_word(temp);
		/* FIXME: this fails to read full words that begin with 'END' */
		if (strncasecmp(temp, "END", 3) == 0) {
			fprintf(stderr, "read: Out of input data\n");
			return -1;
		}
		if (feof(stdin) != 0) {
			fprintf(stderr, "read: Unexpected EOF\n");
			return -1;
		}
		if (store(temp, addr++) == -1) {
			fprintf(stderr, "read: store failed\n");
			return -1;
		}
	}
	return 0;
}