Ejemplo n.º 1
0
//==============================================================================
void CC_UnitDriver::flash_read_near(uint16_t address, size_t size, ByteVector &data)
{
    const uint8_t load_dtpr[] = { 0xBE, 0x57, 0x90, HIBYTE(address), LOBYTE(address) };
    usb_device_.bulk_write(endpoint_out_, sizeof(load_dtpr), load_dtpr);

    size_t offset = data.size();
    data.resize(offset + size, FLASH_EMPTY_BYTE);

    ByteVector command;
    for (size_t i = 0; i < size / FLASH_READ_CHUNK_SIZE; i++)
    {
        if (command.empty())
            create_read_proc(FLASH_READ_CHUNK_SIZE, command);

        usb_device_.bulk_write(endpoint_out_, command.size(), &command[0]);
        usb_device_.bulk_read(endpoint_in_, FLASH_READ_CHUNK_SIZE, &data[offset]);
        offset += FLASH_READ_CHUNK_SIZE;

        pw_.read_progress(FLASH_READ_CHUNK_SIZE);
    }

    if ((size % FLASH_READ_CHUNK_SIZE))
    {
        create_read_proc(size % FLASH_READ_CHUNK_SIZE, command);

        usb_device_.bulk_write(endpoint_out_, command.size(), &command[0]);
        usb_device_.bulk_read(endpoint_in_, size - offset, &data[offset]);

        pw_.read_progress(size - offset);
    }
}
Ejemplo n.º 2
0
//==============================================================================
void CC_UnitDriver::flash_read_32k(size_t address, size_t size, ByteVector &data)
{
	if (((address % 0x8000) + size) > 0x8000)
		throw std::runtime_error("flash_read_32k, incorrect parameters");

	const uint8_t load_dtpr[] = { 0xBE, 0x57, 0x90, address >> 8, address };
	usb_device_.bulk_write(ENDPOINT_OUT, sizeof(load_dtpr), load_dtpr);

	size_t offset = data.size();
	data.resize(offset + size, 0xFF);

	ByteVector command;
	for (size_t i = 0; i < size / FLASH_READ_CHUNK_SIZE; i++)
	{
		if (command.empty())
			create_read_proc(FLASH_READ_CHUNK_SIZE, command);

		usb_device_.bulk_write(ENDPOINT_OUT, command.size(), &command[0]);
		usb_device_.bulk_read(ENDPOINT_IN, FLASH_READ_CHUNK_SIZE, &data[offset]);
		offset += FLASH_READ_CHUNK_SIZE;

		pw_.read_progress(FLASH_READ_CHUNK_SIZE);
	}

	if ((size % FLASH_READ_CHUNK_SIZE))
	{
		create_read_proc(size % FLASH_READ_CHUNK_SIZE, command);

		usb_device_.bulk_write(ENDPOINT_OUT, command.size(), &command[0]);
		usb_device_.bulk_read(ENDPOINT_IN, size - offset, &data[offset]);

		pw_.read_progress(size - offset);
	}
}