Beispiel #1
0
TIEXPORT3 int TICALL dusb_recv_acknowledge(CalcHandle *h)
{
	DUSBRawPacket raw;

	if (h == NULL)
	{
		ticalcs_critical("%s: h is NULL", __FUNCTION__);
		return ERR_INVALID_HANDLE;
	}

	memset(&raw, 0, sizeof(raw));
	TRYF(dusb_recv(h, &raw));
#if (VPKT_DBG == 2)
	ticalcs_info("  TI->PC: Virtual Packet Data Acknowledgement");
#endif

	raw.size = raw.size;
	if(raw.size != 2 && raw.size != 4)
		return ERR_INVALID_PACKET;

	if(raw.type == DUSB_RPKT_BUF_SIZE_REQ)
	{
		uint32_t size;

		if(raw.size != 4)
			return ERR_INVALID_PACKET;

		size = (raw.data[0] << 24) | (raw.data[1] << 16) | (raw.data[2] << 8) | (raw.data[3] << 0);
		ticalcs_info("  TI->PC: Buffer Size Request (%i bytes)", size);

		TRYF(dusb_send_buf_size_alloc(h, size));

		TRYF(dusb_recv(h, &raw));
	}

	if(raw.type != DUSB_RPKT_VIRT_DATA_ACK)
		return ERR_INVALID_PACKET;

	if(raw.data[0] != 0xE0 && raw.data[1] != 0x00)
		return ERR_INVALID_PACKET;

	return 0;
}
Beispiel #2
0
int dusb_recv_acknowledge(CalcHandle *h)
{
	RawPacket raw = { 0 };

	TRYF(dusb_recv(h, &raw));
#if (VPKT_DBG == 2)
	ticalcs_info("  TI->PC: Virtual Packet Data Acknowledgement");
#endif
	
	raw.size = raw.size;
	if(raw.size != 2 && raw.size != 4)
		return ERR_INVALID_PACKET;

	if(raw.type == RPKT_BUF_SIZE_REQ)
	{
		uint32_t size;

		if(raw.size != 4)
			return ERR_INVALID_PACKET;

		size = (raw.data[0] << 24) | (raw.data[1] << 16) | (raw.data[2] << 8) | (raw.data[3] << 0);
		ticalcs_info("  TI->PC: Buffer Size Request (%i bytes)", size);
		
		TRYF(dusb_send_buf_size_alloc(h, size));

		TRYF(dusb_recv(h, &raw));
	}
	
	if(raw.type != RPKT_VIRT_DATA_ACK)
		return ERR_INVALID_PACKET;

	if(raw.data[0] != 0xE0 && raw.data[1] != 0x00)
		return ERR_INVALID_PACKET;

	return 0;
}
Beispiel #3
0
TIEXPORT3 int TICALL dusb_recv_acknowledge(CalcHandle *handle)
{
	DUSBRawPacket raw;
	int ret = 0;

	VALIDATE_HANDLE(handle);

	memset(&raw, 0, sizeof(raw));

	do
	{
		ret = dusb_recv(handle, &raw);
		if (ret)
		{
			break;
		}
#if (VPKT_DBG == 2)
		ticalcs_info("  TI->PC: Virtual Packet Data Acknowledgement");
#endif

		if (raw.size != 2 && raw.size != 4)
		{
			ret = ERR_INVALID_PACKET;
			break;
		}

		if (raw.type == DUSB_RPKT_BUF_SIZE_REQ)
		{
			uint32_t size;

			if (raw.size != 4)
			{
				ret = ERR_INVALID_PACKET;
				break;
			}

			size = (((uint32_t)raw.data[0]) << 24) | (((uint32_t)raw.data[1]) << 16) | (((uint32_t)raw.data[2]) << 8) | (((uint32_t)raw.data[3]) << 0);
			ticalcs_info("  TI->PC: Buffer Size Request (%i bytes)", size);

			ret = dusb_send_buf_size_alloc(handle, size);
			if (ret)
			{
				break;
			}

			ret = dusb_recv(handle, &raw);
			if (ret)
			{
				break;
			}
		}

		if (raw.type != DUSB_RPKT_VIRT_DATA_ACK)
		{
			ret = ERR_INVALID_PACKET;
			break;
		}

		if (raw.data[0] != 0xE0 && raw.data[1] != 0x00)
		{
			ret = ERR_INVALID_PACKET;
			break;
		}
	} while(0);

	return ret;
}
Beispiel #4
0
static int		send_os    (CalcHandle* handle, FlashContent* content)
{
	ModeSet mode = { 2, 1, 0, 0, 0x0fa0 }; //MODE_BASIC;
	uint32_t pkt_size = 266;
	uint32_t os_size = 0;
	FlashContent *ptr;
	int i, j;
	int boot = 0;

	// search for data header
	for (ptr = content; ptr != NULL; ptr = ptr->next)
		if(ptr->data_type == TI83p_AMS || ptr->data_type == TI83p_APPL)
			break;
	if(ptr == NULL)
		return -1;
	if(ptr->data_type != TI83p_AMS)
		return -1;

#if 0
	printf("#pages: %i\n", ptr->num_pages);
	printf("type: %02x\n", ptr->data_type);
	for (i = 0; i < ptr->num_pages; i++) 
	{
		FlashPage *fp = ptr->pages[i];

		printf("page #%i: %04x %02x %02x %04x\n", i,
			fp->addr, fp->page, fp->flag, fp->size);
		//tifiles_hexdump(fp->data, 16);
	}
	printf("data length = %08x %i\n", ptr->data_length, ptr->data_length);
#endif

	for(i = 0; i < ptr->num_pages; i++)
	{
		FlashPage *fp = ptr->pages[i];

		if(fp->size < 256)
			os_size += 4;
		else
			os_size += 4*(fp->size / 260);
	}
	printf("os_size overhead = %i\n", os_size);
	os_size += ptr->data_length;
	printf("os_size new = %i\n", os_size);

	// switch to BASIC mode
	TRYF(cmd_s_mode_set(handle, mode));
	TRYF(cmd_r_mode_ack(handle));

	// test for boot mode
	{
		uint16_t pids[] = { PID_OS_MODE };
		const int size = sizeof(pids) / sizeof(uint16_t);
		CalcParam **params;

		params = cp_new_array(size);
		TRYF(cmd_s_param_request(handle, size, pids));
		TRYF(cmd_r_param_data(handle, size, params));
		boot = !params[0]->data[0];
	}

	// start OS transfer
	TRYF(cmd_s_os_begin(handle, os_size));
	if(!boot)
	{
		TRYF(dusb_recv_buf_size_request(handle, &pkt_size));
		TRYF(dusb_send_buf_size_alloc(handle, pkt_size));
	}
	TRYF(cmd_r_os_ack(handle, &pkt_size));	// this pkt_size is important

	// send OS header/signature
	TRYF(cmd_s_os_header(handle, 0x4000, 0x7A, 0x80, pkt_size-4, ptr->pages[0]->data));
	TRYF(cmd_r_os_ack(handle, &pkt_size));

	// send OS data
	update_->cnt2 = 0;
	update_->max2 = ptr->num_pages;

	for(i = 0; i < ptr->num_pages; i++)
	{
		FlashPage *fp = ptr->pages[i];

		fp->addr = 0x4000;

		if(i == 0)	// need relocation
		{
			TRYF(cmd_s_os_data(handle, 0x4000, 0x7A, 0x80, pkt_size-4, fp->data));
			TRYF(cmd_r_data_ack(handle));
		}
		else if(i == ptr->num_pages-1)	// idem
		{
			TRYF(cmd_s_os_data(handle, 0x4100, 0x7A, 0x80, pkt_size-4, fp->data));
			TRYF(cmd_r_data_ack(handle));
		}
		else
		{
			for(j = 0; j < fp->size; j += 256/*(pkt_size-4)*/)
			{
				TRYF(cmd_s_os_data(handle, 
					(uint16_t)(fp->addr + j), (uint8_t)fp->page, fp->flag, 
					pkt_size-4, fp->data + j));
				TRYF(cmd_r_data_ack(handle));
			}
		}

		update_->cnt2 = i;
		update_->pbar();
	}
	
	TRYF(cmd_s_eot(handle));
	PAUSE(500);
	TRYF(cmd_r_eot_ack(handle));

	return 0;
}