Beispiel #1
0
/***************************************************************************

Routine:           LinkReset

Inputs:
    None

Returns:
    void

Description:
    Resets the OPTOTRAK system.

***************************************************************************/
NDI_DECL1 boolean NDI_DECL2 LinkReset( void )
{
	if( s_hndl )
	{
		FT_ResetPort( s_hndl );
		FT_Close( s_hndl );
		Sleep( s_nResetDelay );

		s_hndl = OpenUSBDevice( s_nUsbType, s_nUsbId );
		if( s_hndl )
		{
			return TRUE;
		}
	}
	return FALSE;
}
static void FTClassicPort_resetPort(FTClassicPort *self){
	self->status = FT_ResetPort(self->handle);
}
Beispiel #3
0
void image_transfer(FILE *fp, ftdi_context_t *c, u8 dump, u8 type, u32 addr, u32 size)
{	
	u32		ram_addr = addr;
	int		bytes_left = size;
	int		bytes_done = 0;
	int		bytes_do;
	int		trunc_flag = 0;
	int		i; 
	int		chunk = 0;
        struct timespec time_start;
        struct timespec time_stop;
        double          time_duration;
        time_t          time_diff_seconds;
        long            time_diff_nanoseconds;
	dev_cmd_resp_t	r;
  
	// make sure handle is valid
	if(!c->handle) die(err[DEV_ERR_NULL_HANDLE], __FUNCTION__);

	// decide a better, more optimized chunk size
	if(size > 16 * 1024 * 1024) 
		chunk = 32;
	else if( size > 2 * 1024 * 1024)
		chunk = 16;
	else 
		chunk = 4;

	// convert to megabytes
	chunk *= 128 * 1024;
	if(c->verbose) _printf(info[INFO_CHUNK], CHUNK_SIZE);
	if(c->verbose) _printf(info[INFO_OPT_CHUNK], chunk);

	// get initial time count
// 	QueryPerformanceFrequency(&time_freq);
// 	QueryPerformanceCounter(&time_start);
        clock_gettime(CLOCK_MONOTONIC, &time_start);

	while(1){
		if(bytes_left >= chunk) 
			bytes_do = chunk;
		else
			bytes_do = bytes_left;
		if(bytes_do % 512 != 0) {
			trunc_flag = 1;
			bytes_do -= (bytes_do % 512);
		}
		if(bytes_do <= 0) break;
		
		for(i = 0; i < 2; i++){
			if(i == 1) {
				printf("\n");
				_printf("Retrying\n");

				FT_ResetPort(c->handle);
				FT_ResetDevice(c->handle);
				_printf("Retrying FT_ResetDevice() success\n");
				// set synchronous FIFO mode
				//FT_SetBitMode(c->handle, 0xff, 0x40);
				_printf("Retrying FT_SetBitMode() success\n");
				FT_Purge(c->handle, FT_PURGE_RX | FT_PURGE_TX);
				_printf("Retrying FT_Purge() success\n");

			}
			device_sendcmd(c, &r, dump ? DEV_CMD_DUMPRAM : DEV_CMD_LOADRAM, 2, 0, 1, 
				ram_addr, (bytes_do & 0xffffff) | type << 24);

			if(dump){
				c->status = FT_Read(c->handle, buffer, bytes_do, &c->bytes_written);
				fwrite(buffer, bytes_do, 1, fp);
			}else{
				fread(buffer, bytes_do, 1, fp);
				c->status = FT_Write(c->handle, buffer, bytes_do, &c->bytes_written);
			}
			if(c->bytes_written) break;
		}
		// check for a timeout
		if(c->bytes_written == 0) die(err[DEV_ERR_TIMED_OUT], __FUNCTION__);
		// dump success response
		c->status = FT_Read(c->handle, buffer, 4, &c->bytes_read);

		bytes_left -= bytes_do;
		bytes_done += bytes_do;
		ram_addr += bytes_do;

		// progress bar
		prog_draw(bytes_done, size);

		c->status = FT_GetStatus(c->handle, &c->bytes_read, &c->bytes_written, &c->event_status);
	}
	// stop the timer
// 	QueryPerformanceCounter(&time_stop);
        clock_gettime(CLOCK_MONOTONIC, &time_stop);
        // get the difference of the timer
        time_diff_seconds = time_stop.tv_sec - time_start.tv_sec;
        time_diff_nanoseconds = time_stop.tv_nsec - time_start.tv_nsec;
	time_duration = (double)time_diff_seconds + (double)(time_diff_nanoseconds/1000000000.0f);
        
	// erase progress bar
	prog_erase();
	if(c->verbose && trunc_flag) 
		_printf(info[INFO_TRUNCATED]);
	if(c->verbose) 
		_printf(info[INFO_COMPLETED_TIME],	time_duration, (float)size/1048576.0f/(float)time_duration);
}