Exemple #1
0
int write_flash(unsigned long address, unsigned short *src, unsigned short n)
{ 
  int i,z;
  unsigned long sector_address = SECTOR_START(ALIGN(address));

  //reset_flash();

  write_flash_unlock_sequence();
  
  /* sadly xmodem requires silence to operate */
  /* print_string("Writing Sector Address: "); */
  /* print_hex_unsigned(sector_address); */

  /* Write*/ 
  *( (volatile unsigned short *) (FLASH_BASE + sector_address)) = FLASH_CMD_WRITE_BUFFER_LOAD;
  *( (volatile unsigned short *) (FLASH_BASE + sector_address)) = n-1;

  unsigned short *write_address = (unsigned short *) (FLASH_BASE + ALIGN(address));
  for (i = 0; i < n; i++)
  {
    *write_address++ = *src++;
    /* print_string("+"); */
  }
  
  *((volatile unsigned short *) (FLASH_BASE + sector_address)) = FLASH_CMD_WRITE_CONFIRM; 
  /* print_string("done\r\n"); */
  DELAY(20);
  if (poll_status(FLASH_OP_WRITE_BUFFER, *(write_address-1), *(src-1)) != 0)
  {
    //write_flash_command((unsigned char) FLASH_CMD_RESET);
    return -1;
  }
  
  return 0;
}
Exemple #2
0
int erase_sector_flash(unsigned int start_sector, unsigned int end_sector)
{
  //reset_flash();
  int i, z;

  print_string("Erasing ... ");

  write_flash_unlock_sequence();
  write_flash_command((unsigned char) FLASH_CMD_ERASE_SETUP);
  write_flash_unlock_sequence();
  
  /* Sector erase */
  for (i = start_sector; i <= end_sector; i++)
  {
    //print_string("Erasing sector at address: ");
    //print_hex_unsigned(FLASH_BASE + SECTOR_ADDRESS(i));
    //print_string("\r\n");
    *((volatile unsigned short *) (FLASH_BASE + SECTOR_ADDRESS(i))) = FLASH_CMD_SECTOR_ERASE;
  }
  DELAY(500);
  if (poll_status(FLASH_OP_ERASE, SECTOR_ADDRESS(i), 0) != 0)
  {
    write_flash_command((unsigned char) FLASH_CMD_RESET);
    return -1;
  }
  print_string("ok\r\n");
  return 0;
}
Exemple #3
0
int do_motor() {
	int res;
	led_state state_to_set = LED_SOLID_RED;
	int tilt = -30;

	libusb_context* ctx = NULL;
	libusb_init(&ctx);

	libusb_device_handle* dev = NULL;
	dev = libusb_open_device_with_vid_pid(ctx, 0x045e, 0x02ad);
	if (dev == NULL) {
		LOG("Failed to open audio device\n");
		libusb_exit(ctx);
		exit(1);
	}

	res = libusb_claim_interface(dev, 0);
	if (res != 0) {
		LOG("Failed to claim interface 1: %d\n", res);
		goto cleanup;
	}

	res = set_led(dev, state_to_set);
	if (res != 0) {
		LOG("set_led failed\n");
		goto cleanup;
	}

	res = set_tilt(dev, tilt);
	if (res != 0) {
		LOG("set_tilt failed\n");
		goto cleanup;
	}

	int i;
	for (i = 0; i < 10; i++) {
		res = poll_status(dev);
		if (res != 0) {
			LOG("poll_status failed\n");
			goto cleanup;
		}
		usleep(100000);
	}
	
    res = set_tilt(dev, -tilt);
	if (res != 0) {
		LOG("set_tilt failed\n");
		goto cleanup;
	}
    
cleanup:
	libusb_close(dev);
	libusb_exit(ctx);

	return 0;
}
Exemple #4
0
static int
assert_status(int fd, int kqueue_fd, int assert_readable,
              int assert_writable, int assert_exception, const char *testname,
              const char *conditionname, const char *fdname)
{
    int readable, writable, exception;

    if (poll_status(fd, &readable, &writable, &exception, testname) < 0)
        return (-1);

    if (readable != assert_readable || writable != assert_writable ||
            exception != assert_exception) {
        warnx("%s: %s polls r:%d, w:%d, e:%d on %s", testname,
              fdname, readable, writable, exception, conditionname);
        return (-1);
    }

    if (select_status(fd, &readable, &writable, &exception, testname) < 0)
        return (-1);

    if (readable != assert_readable || writable != assert_writable ||
            exception != assert_exception) {
        warnx("%s: %s selects r:%d, w:%d, e:%d on %s", testname,
              fdname, readable, writable, exception, conditionname);
        return (-1);
    }

    if (kqueue_status(kqueue_fd, fd, &readable, &writable, &exception,
                      testname) < 0)
        return (-1);

    if (readable != assert_readable || writable != assert_writable ||
            exception != assert_exception) {
        warnx("%s: %s kevent r:%d, w:%d, e:%d on %s", testname,
              fdname, readable, writable, exception, conditionname);
        return (-1);
    }

    if (fionread_status(fd, &readable, __func__) < 0)
        return (-1);

    if (readable != assert_readable) {
        warnx("%s: %s fionread r:%d on %s", testname, fdname,
              readable, conditionname);
        return (-1);
    }

    return (0);
}
Exemple #5
0
static int docg4_load_block_reliable(uint32_t flash_offset, void *dest_addr)
{
	void __iomem *docptr = (void *)CONFIG_SYS_NAND_BASE;
	unsigned int g4_page = flash_offset >> 11; /* 2k page */
	const unsigned int last_g4_page = g4_page + 0x80; /* last in block */
	int g4_index = 0;
	uint16_t flash_status;
	uint16_t *buf;
	uint16_t discard, magic_high, magic_low;

	/* flash_offset must be aligned to the start of a block */
	if (flash_offset & 0x3ffff)
		return -1;

	writew(DOC_SEQ_RESET, docptr + DOC_FLASHSEQUENCE);
	writew(DOC_CMD_RESET, docptr + DOC_FLASHCOMMAND);
	write_nop(docptr);
	write_nop(docptr);
	poll_status(docptr);
	write_nop(docptr);
	writew(0x45, docptr + DOC_FLASHSEQUENCE);
	writew(0xa3, docptr + DOC_FLASHCOMMAND);
	write_nop(docptr);
	writew(0x22, docptr + DOC_FLASHCOMMAND);
	write_nop(docptr);

	/* read 1st 4 oob bytes of first subpage of block */
	address_sequence(g4_page, 0x0100, docptr); /* index at oob */
	write_nop(docptr);
	flash_status = readw(docptr + DOC_FLASHCONTROL);
	flash_status = readw(docptr + DOC_FLASHCONTROL);
	if (flash_status & 0x06) /* sequence or protection errors */
		return -1;
	writew(DOCG4_CMD_READ2, docptr + DOC_FLASHCOMMAND);
	write_nop(docptr);
	write_nop(docptr);
	poll_status(docptr);
	writew(DOC_ECCCONF0_READ_MODE | 4, docptr + DOC_ECCCONF0);
	write_nop(docptr);
	write_nop(docptr);
	write_nop(docptr);
	write_nop(docptr);
	write_nop(docptr);

	/*
	 * Here we read the first four oob bytes of the first page of the block.
	 * The IPL on the palmtreo680 requires that this contain a 32 bit magic
	 * number, or the load aborts.  We'll ignore it.
	 */
	discard = readw(docptr + 0x103c); /* hw quirk; 1st read discarded */
	magic_low = readw(docptr + 0x103c);
	magic_high = readw(docptr + DOCG4_MYSTERY_REG);
	writew(0, docptr + DOC_DATAEND);
	write_nop(docptr);
	write_nop(docptr);

	/* load contents of block to memory */
	buf = (uint16_t *)dest_addr;
	do {
		int i;

		address_sequence(g4_page, g4_index, docptr);
		writew(DOCG4_CMD_READ2,
		       docptr + DOC_FLASHCOMMAND);
		write_nop(docptr);
		write_nop(docptr);
		poll_status(docptr);
		writew(DOC_ECCCONF0_READ_MODE |
		       DOC_ECCCONF0_ECC_ENABLE |
		       DOCG4_BCH_SIZE,
		       docptr + DOC_ECCCONF0);
		write_nop(docptr);
		write_nop(docptr);
		write_nop(docptr);
		write_nop(docptr);
		write_nop(docptr);

		/* read the 512 bytes of page data, 2 bytes at a time */
		discard = readw(docptr + 0x103c);
		for (i = 0; i < 256; i++)
			*buf++ = readw(docptr + 0x103c);

		/* read oob, but discard it */
		for (i = 0; i < 7; i++)
			discard = readw(docptr + 0x103c);
		discard = readw(docptr + DOCG4_OOB_6_7);
		discard = readw(docptr + DOCG4_OOB_6_7);

		writew(0, docptr + DOC_DATAEND);
		write_nop(docptr);
		write_nop(docptr);

		if (!(g4_index & 0x100)) {
			/* not redundant subpage read; check for ecc error */
			write_nop(docptr);
			flash_status = readw(docptr + DOC_ECCCONF1);
			flash_status = readw(docptr + DOC_ECCCONF1);
			if (flash_status & 0x80) { /* ecc error */
				g4_index += 0x108; /* read redundant subpage */
				buf -= 256;        /* back up ram ptr */
				continue;
			} else                       /* no ecc error */
				g4_index += 0x210; /* skip redundant subpage */
		} else  /* redundant page was just read; skip ecc error check */
			g4_index += 0x108;

		if (g4_index == 0x420) { /* finished with 2k page */
			g4_index = 0;
			g4_page += 2; /* odd-numbered 2k pages skipped */
		}

	} while (g4_page != last_g4_page); /* while still on same block */

	return 0;
}