⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testanalog.c

📁 epson usb2.0 控制芯片 S1R72V05 固件程序。
💻 C
📖 第 1 页 / 共 5 页
字号:
	setupData[0] = DIR_DEVICE_TO_HOST | RECIPIENT_DEVICE;
	setupData[1] = SREQ_GET_DESCRIPTOR;
	setupData[2] = 0;
	setupData[3] = DTYPE_DEVICE;
	setupData[4] = 0;
	setupData[5] = 0;
	setupData[6] = 0x08;
	setupData[7] = 0;

	memset( getDescData, 0, sizeof( getDescData ) );

	// Send request
	SendRequest( setupData, getDescData );

	// Set the MaxPacketSize of CH0
	RegWrite(REG08_H_CH0MaxPktSize, getDescData[7]);

	// Display the message of start to send Get Device Descriptor request
	DBG_FlowStrPrint("[Send GetDeviceDescriptor Request Start]\r\n", FLOW_LV);

	// Display the message of Test Mode select
	DBG_FlowStrPrint("[Please select Test Mode.]\r\n", FLOW_LV);
	DBG_FlowStrPrint("[0 : Single Step]\r\n[1 : Loop Step]\r\n", FLOW_LV);
	while(1) {
		memset( inputData, 0x00, sizeof(inputData) );
		FlowGetStr( inputData, &inputDataSize, 0 );
		inputNumber = atol((const char *)inputData);
		if( inputNumber == SINGLE_STEP ) {
			DBG_FlowStrPrint("[Single Step Mode Mode select]\r\n", FLOW_LV);
			endFlag = SINGLE_STEP;
			break;
		} else {
			if( inputNumber == LOOP_STEP ) {
				DBG_FlowStrPrint("[Loop Step Mode Mode select]\r\n", FLOW_LV);
				endFlag = LOOP_STEP;
				break;
			} else {
				DBG_FlowStrPrint("[It is an input value error. Try to input it.]\r\n", FLOW_LV);
			}
		}
	}

	// Set GetDeviceDescriptor data
	setupData[0] = DIR_DEVICE_TO_HOST | RECIPIENT_DEVICE;
	setupData[1] = SREQ_GET_DESCRIPTOR;
	setupData[2] = 0;
	setupData[3] = DTYPE_DEVICE;
	setupData[4] = 0;
	setupData[5] = 0;
	setupData[6] = 0x12;
	setupData[7] = 0;

	DBG_FlowStrPrint("\r\n[The evaluation begins.", FLOW_LV);
	TestHitAnyKey ();

	KeyResult = STATUS_UNSUCCESSFUL;

	if( endFlag == LOOP_STEP ){
		DBG_FlowStrPrint("[Please push any key when you want to end the evaluation.\r\n", FLOW_LV);
		FlowKeyHit( (CALLBACK_PROC)KeyCmpCallback );

		DBG_FlowStrPrint("[Send GetDeviceDescriptor Request Running]\r\n", FLOW_LV);
	}

	// Send GetDeviceDescriptor
	RegWrite(REG08_H_SIE_IntStat_0, BIT_DetectDiscon); // Clear DetectDiscon

	do {
		if( (RegRead(REG08_H_SIE_IntStat_0) & MASK_DetectDiscon) == BIT_DetectDiscon ){
			// The device was disconnected

			RegWrite(REG08_H_SIE_IntStat_0, BIT_DetectDiscon); // Clear DetectDiscon.

			DBG_FlowStrPrint("\r\n[The device was disconnected. ]\r\n", FLOW_LV);
			DBG_FlowStrPrint("[Please push any key when you want to end the evaluation.", FLOW_LV);
			while( KeyResult != STATUS_SUCCESS );
			break;
		}

		memset( getDescData, 0, sizeof( getDescData ) );

		// Send request
		SendRequest( setupData, getDescData );

		if( endFlag == SINGLE_STEP ){
			DescriptorPrint( (DEVICE_DESC_DATA *)getDescData );
			DBG_FlowStrPrint("\r\n[When you want to end the evaluation", FLOW_LV);
			TestHitAnyKey();
			DBG_FlowStrPrint("\r\n", FLOW_LV);
		}

		// Eveluatation complete adjudgement
		if( KeyResult == STATUS_SUCCESS ) {
			KeyResult = STATUS_UNSUCCESSFUL;
			break;
		}

	} while( endFlag == LOOP_STEP );

	// End of the process
	// Cancel the Auto mode temporarily
	RegWrite(REG08_H_NegoControl_0,BIT_AutoModeCancel);
	while((RegRead(REG08_H_NegoControl_0) & MASK_AutoModeCancel) == BIT_AutoModeCancel);

	RegModify(REG08_H_NegoControl_0,MASK_AutoMode,BIT_AutoMode_GoIDLE);
	while((RegRead(REG08_H_NegoControl_0) & MASK_HostState) != BIT_HostState_IDLE);
}

/*
//=============================================================================
// Function_Name: ReceiveTestPacket
// description	: REceive Test Packet (Test10)
//				  SetFeature(TEST_MODE) request is issued to the connected device through Default PIPE
//				  Test Packet sent from the device is received, and the number of errors and the number of reception packets are displayed.
// argument		: none
// return		: none
//=============================================================================
*/
static void ReceiveTestPacket ( void )
{
	unsigned short inputDataSize;
	char	inputData[80];
	unsigned long inputNumber;
	TEST_REQUEST setupData;
	TEST_SETTING_REQUEST setData[2];
	TEST_START_REQUEST startData[1];
	TEST_RESULT_REQUEST resultData;
	unsigned long errorCount;
	unsigned char *receiveData;
	unsigned char dataType;
	unsigned short copyCount;
	unsigned char *pbDataBuf;
	unsigned long remainDataCount;
	long result;
	unsigned long tranErrCount;


	// Initialize the variables
	tranErrCount = 0;
	errorCount = 0x00;

	// Display the start to send packet message
	DBG_FlowStrPrint("[Receive Test Packet Start]\r\n\r\n", FLOW_LV);

	//For opposing examination: Set up the test environment request data
	setupData.bmRequestType = DATA_OUT | VENDOR_REQUEST | RECIPIENT_OTHER;
	setupData.bRequest		= TEST_TYPE_SETTING_REQ;
	setupData.wValue_L		= 0;
	setupData.wValue_H		= 0;
	setupData.wIndex_L		= 0;
	setupData.wIndex_H		= 0;
	setupData.wLength_L 	= TEST_TYPE_SETTING_REQ_LEN;
	setupData.wLength_H 	= 0;

	setData[0].epAddress   = (DATA_IN | ENDPOINT_A);
	setData[0].tranType    = TEST_BULK;
	setData[0].maxPktSizeL = (unsigned char)( CHA_MAX_PKT_SIZE & 0x00FF );
	setData[0].maxPktSizeH = (unsigned char)( CHA_MAX_PKT_SIZE >> 8 );

	//For opposing examination: Send the test environment setting request
	result = TestOpposingRequest( setupData, (unsigned short *)setData );
	if( result != STATUS_SUCCESS ){
		DBG_FlowStrPrint("[The opposing examination device is abnormal!!]\r\n", FLOW_LV);
		return;
	}

	//For opposing examination: Set up the test start request data

	// loop for key board input
	while(1) {
		memset( inputData, 0x00, sizeof(inputData) );

		DBG_FlowStrPrint("[Please select the data pattern.]\r\n", FLOW_LV);
		DBG_FlowStrPrint("1: Increment\r\n", FLOW_LV);
		DBG_FlowStrPrint("2: ALL 0x00\r\n", FLOW_LV);
		DBG_FlowStrPrint("3: ALL 0xFF\r\n", FLOW_LV);
		DBG_FlowStrPrint("4: ALL 0x7C\r\n", FLOW_LV);
		DBG_FlowStrPrint("5: ALL 0x7E\r\n", FLOW_LV);
		FlowGetStr( inputData, &inputDataSize, 0 );
		inputNumber = atol((const char *)inputData);
		if( inputNumber == 1 ){
			dataType = TEST_DATA_INC;
			break;
		} else if( inputNumber == 2 ){
			dataType = TEST_DATA_ALL_00;
			break;
		} else if( inputNumber == 3 ){
			dataType = TEST_DATA_ALL_FF;
			break;
		} else if( inputNumber == 4 ){
			dataType = TEST_DATA_ALL_7C;
			break;
		} else if( inputNumber == 5 ){
			dataType = TEST_DATA_ALL_7E;
			break;
		}
	}
	startData[0].dataType = dataType;
	startData[0].compareDis   = OFF;

	DBG_FlowStrPrint("[Please push any key when you want to end the evaluation.]\r\n", FLOW_LV);
	KeyResult = STATUS_UNSUCCESSFUL;
	FlowKeyHit( (CALLBACK_PROC)KeyCmpCallback );

	RegWrite(REG16_H_CHaStartAdrs, 0x0100);
	RegWrite(REG16_H_CHaEndAdrs, 0x1200);

	while(1) {
		setupData.bmRequestType = DATA_OUT | VENDOR_REQUEST | RECIPIENT_OTHER;
		setupData.bRequest		= TEST_TYPE_START_REQ;
		setupData.wValue_L		= 0;
		setupData.wValue_H		= 0;
		setupData.wIndex_L		= 0;
		setupData.wIndex_H		= 0;
		setupData.wLength_L 	= TEST_TYPE_START_REQ_LEN;
		setupData.wLength_H 	= 0;

		startData[0].epAddress	  = (DATA_IN | ENDPOINT_A);
		startData[0].incStartData = 0;
		startData[0].access.tranSize = TEST_BULK_XFER_SIZE;

		//For opposing examination: Send the start test request data
		result = TestOpposingRequest( setupData, (unsigned short *)startData );
		if( result != STATUS_SUCCESS ){
			DBG_FlowStrPrint("[The opposing examination device is abnormal!!]\r\n", FLOW_LV);
			return;
		}

		/* Start transfer*/
		RegWrite(REG16_H_CHaStartAdrs, 0x0100);
		RegWrite(REG16_H_CHaEndAdrs, 0x1200);
		RegSet(REG08_H_CHrFIFO_Clr, BIT_CHaFIFO_Clr);
		RegModify(REG08_H_CHaConfig_0, MASK_ACK_Cnt, 0);

		RegModify(REG08_H_CHaConfig_0, MASK_SpeedMode, (RegRead(REG08_H_NegoControl_1) & MASK_PortSpeed)>>SHIFT_SpeedMode);

		RegClear(REG08_H_CHaConfig_0, BIT_Toggle);
		RegModify(REG08_H_CHaConfig_1, MASK_TID, TID_IN_DATA);
		RegWrite(REG16_H_CHaMaxPktSize, CHA_MAX_PKT_SIZE);
		RegWrite(REG08_H_CHaTotalSize_LL, startData[0].access.byte.tranSizeLL);
		RegWrite(REG08_H_CHaTotalSize_LH, startData[0].access.byte.tranSizeLH);
		RegWrite(REG08_H_CHaTotalSize_HL, startData[0].access.byte.tranSizeHL);
		RegWrite(REG08_H_CHaTotalSize_HH, startData[0].access.byte.tranSizeHH);
		RegModify(REG08_H_CHaFuncAdrs, MASK_EP_Number, ENDPOINT_A);
		RegSet(REG08_H_CHaConfig_0, BIT_TranGo);

		receiveData = (unsigned char *)TEST_BULK_XFER_BUF_ADDR;

		memset( receiveData, 0, TEST_BULK_XFER_SIZE );
		remainDataCount = (unsigned long)TEST_BULK_XFER_SIZE;
		pbDataBuf = receiveData;

		// Transfer process
		while(1) {
			copyCount = ReadFIFOData(1, pbDataBuf);
			if( copyCount != 0 ){
				/* Receive data */
				remainDataCount -= copyCount;
				pbDataBuf += copyCount;

				if( remainDataCount == 0 ){
					/* Complete receiv all the data */

					break;
				}
			}
			if( (RegRead(REG08_H_CHaIntStat) & MASK_ChangeCondition) == BIT_ChangeCondition ){
				RegWrite(REG08_H_CHaIntStat, 0x10);
				DBG_FlowStrPrint("[ChangeConditionInterrupt reception]", FLOW_LV);
				DBG_FlowStrPrint("\r\n[TranErr frequency: ", FLOW_LV);
				DBG_FlowValPrint( PRINT_DECIMAL_MODE, DBG_STORE_DWORD, tranErrCount, FLOW_LV);
				DBG_FlowStrPrint("]\r\n", FLOW_LV);
				return;
			} else if( (RegRead(REG08_H_CHaIntStat) & MASK_TranErr) == BIT_TranErr ){
				RegWrite(REG08_H_CHaIntStat, 0x20);
				tranErrCount++;
				DBG_FlowStrPrint("[TranErr interrupt reception]\r\n", FLOW_LV);
			}
		}

		//For opposing examination: Set up  data for test result reques
		setupData.bmRequestType = DATA_IN | VENDOR_REQUEST | RECIPIENT_OTHER;
		setupData.bRequest		= TEST_TYPE_RESULT_REQ;
		setupData.wValue_L		= 0;
		setupData.wValue_H		= 0;
		setupData.wIndex_L		= (DATA_IN | ENDPOINT_A);
		setupData.wIndex_H		= 0;
		setupData.wLength_L 	= TEST_TYPE_RESULT_REQ_LEN;
		setupData.wLength_H 	= 0;
		result = TestOpposingRequest( setupData, (unsigned short *)&resultData );
		if( result != STATUS_SUCCESS ){
			DBG_FlowStrPrint("[The opposing examination device is abnormal!!]\r\n", FLOW_LV);
			return;
		}

		if( resultData.tranResult != TEST_RESULT_COMPLETE ){
			DBG_FlowStrPrint("[Does not the opposing examination operate well?]\r\n", FLOW_LV);
		}


		DBG_FlowStrPrint("\r\n[Test Packet was received. The error check is begun.]\r\n\r\n", FLOW_LV);

		//For opposing examination: Start the compare check
		errorCount = TestOpposingCompare( receiveData, (unsigned long)TEST_BULK_XFER_SIZE, dataType, 0 );

		// Display the error count
		DBG_FlowStrPrint("\r\n[Error Count = ", FLOW_LV);
		DBG_FlowValPrint( PRINT_DECIMAL_MODE, DBG_STORE_DWORD, errorCount, FLOW_LV);
		DBG_FlowStrPrint("]\r\n\r\n", FLOW_LV);

		// Eveluatation complete adjudgement
		if( KeyResult == STATUS_SUCCESS ) {
				DBG_FlowStrPrint("\r\n[TranErr frequency: ", FLOW_LV);
				DBG_FlowValPrint( PRINT_DECIMAL_MODE, DBG_STORE_DWORD, tranErrCount, FLOW_LV);
				DBG_FlowStrPrint("]\r\n", FLOW_LV);
			KeyResult = STATUS_UNSUCCESSFUL;
			break;
		}
	}

	// Display the complete receive the Test Packet message
	DBG_FlowStrPrint("\r\n[Receive Test Packet Complete]\r\n\r\n", FLOW_LV);

	return;
}

/*
//=============================================================================
// Function_Name: ChipReset
// description	: initialize the Test mode
// argument		: none
// return		: none
//=============================================================================
*/
static void ChipReset ( void )
{
	volatile unsigned char bTemp;

	//======================================================================
	// Reset IC
	//======================================================================
	RegWrite(REG16_ChipReset, CHIP_RESET);
	OS_DlyTsk(1);										// Waiting for the reset completion
	bTemp = RegRead(REG08_CPU_ChgEndian);				// Dummy read

	//======================================================================
	// Set the bus for access it
	//======================================================================
	// The value of ChipConfig is initialized when ChipReset,set the value to ChipConfig again.
	RegSet(REG08_ChipConfig, 0x06);						// Chip config set
	bTemp = RegRead(REG08_CPU_ChgEndian);				// Read and do nothing
	RegWrite(REG08_ClkSelect,0x01);
	RegWrite(REG08_ModeProtect,0x00);

	RegSet(REG08_HostDeviceSel, BIT_HOSTxDEVICE_HOST);	// Change the host register
	RegClear(REG08_H_Reset, BIT_ResetHTM);

	SetTermSlopeValue(TermValue, SlopeValue);

	// Activate
	if ((RegRead(REG08_PM_Control_1) & MASK_PM_State) != BIT_PMState_ACT_HOST) {
		RegSet(REG08_PM_Control_0, BIT_GoActHost);
#ifdef FPGA_DEBUG_C
		OS_DlyTsk(100);
#endif
		while ((RegRead(REG08_PM_Control_1) & MASK_PM_State) != BIT_PMState_ACT_HOST);
	}

	return;
}

/*
//=============================================================================
// Function_Name: TestDevConnect
// description	: Process the connect of device
// argument		: none
// return		: none
//=============================================================================
*/
static void TestDevConnect ( void )
{
	// Check the initial state
	if((RegRead(REG08_H_NegoControl_0) & MASK_HostState) != BIT_HostState_IDLE) {
		TestAnalogErr( TEST_INIT, __LINE__ );
	}

	// GoWAIT_CONNECT
	RegModify(REG08_H_NegoControl_0,MASK_AutoMode,BIT_AutoMode_GoWAIT_CONNECT);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -