📄 testanalog.c
字号:
0xAA,0xEE,0xEE,0xEE,0xEE,0xEE,0xEE,0xEE,
0xEE,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0xBF,0xDF,
0xEF,0xF7,0xFB,0xFD,0xFC,0x7E,0xBF,0xDF,
0xEF,0xF7,0xFB,0xFD,0x7E };
unsigned char setupData[8], i;
// Initialize the variables
memset( setupData, 0, sizeof(setupData) );
RegWrite(REG16_H_CH0StartAdrs,0x0100);
RegWrite(REG16_H_CH0EndAdrs,0x0200);
RegSet(REG08_H_CHnControl, BIT_CH0FIFO_Clr);
// Set test data
RegSet(REG08_H_CH0Join, BIT_JoinCPU_Wr);
for( i = 0 ; i < (sizeof(testData) - 1) ; i += 2 ) {
RegWrite(REG08_FIFO_Wr_H,testData[i]);
RegWrite(REG08_FIFO_Wr_L,testData[i + 1]);
}
RegWrite(REG08_FIFO_Wr_H,testData[i]);
RegSet(REG08_H_ClrAllCHnJoin, BIT_ClrJoinCPU_Wr);
// Cancel the Auto mode temporarily
RegWrite(REG08_H_NegoControl_0,BIT_AutoModeCancel);
while((RegRead(REG08_H_NegoControl_0) & MASK_AutoModeCancel) == BIT_AutoModeCancel);
// Send TestPacket in the HS mode
RegSet(REG08_H_USB_Test, BIT_Test_Packet);
// Confirm the timing of Sendind TestPacket
DBG_FlowStrPrint("[Test_Packet is issued. If it is good", FLOW_LV);
TestHitAnyKey();
RegSet(REG08_H_USB_Test, BIT_EnHS_Test);
// Display the Sending TestPacket message
DBG_FlowStrPrint("[Send Test Packet Running]\r\n", FLOW_LV);
// Confirm the Timing of Sending TestPacket
DBG_FlowStrPrint("[When you stop the issue of Test Packet", FLOW_LV);
TestHitAnyKey();
// Terminate the test mode
RegWrite(REG08_H_USB_Test, 0x00);
RegModify(REG08_H_NegoControl_0,MASK_AutoMode,BIT_AutoMode_GoIDLE);
while((RegRead(REG08_H_NegoControl_0) & MASK_HostState) != BIT_HostState_IDLE);
// Display the message of Sent TestPacket normally
DBG_FlowStrPrint("[Send Test Packet Complete]\r\n", FLOW_LV);
return;
}
/*
//=============================================================================
// Function_Name: SendTest_J
// description : Send Test_J (Test9)
// argument : none
// return : none
//=============================================================================
*/
static void SendTest_J ( void )
{
// Display the message of start to send Test_J
DBG_FlowStrPrint("[Send Test_J Start]\r\n", FLOW_LV);
// Cancel the Auto mode temporarily
RegWrite(REG08_H_NegoControl_0,BIT_AutoModeCancel);
while((RegRead(REG08_H_NegoControl_0) & MASK_AutoModeCancel) == BIT_AutoModeCancel);
// Send 'J' in HS mode
RegSet(REG08_H_USB_Test, BIT_Test_J);
// Confirm the Timing of sending TestPacket
DBG_FlowStrPrint("[Test_J is issued. If it is good", FLOW_LV);
TestHitAnyKey();
//Display the message of sending TestPacket
DBG_FlowStrPrint("[Send Test_J Running]\r\n", FLOW_LV);
// start to send Test_J
RegSet(REG08_H_USB_Test, BIT_EnHS_Test);
// Confirm the Timing of sending TestPacket
DBG_FlowStrPrint("[When you stop the issue of Test_J", FLOW_LV);
TestHitAnyKey();
// Terminate the test mode
RegWrite(REG08_H_USB_Test, 0x00);
RegModify(REG08_H_NegoControl_0,MASK_AutoMode,BIT_AutoMode_GoIDLE);
while((RegRead(REG08_H_NegoControl_0) & MASK_HostState) != BIT_HostState_IDLE);
// Display the message of sent Test_J normally
DBG_FlowStrPrint("[Send Test_J Complete]\r\n", FLOW_LV);
return;
}
/*
//=============================================================================
// Function_Name: SendTest_K
// description : Send Test_K (Test9)
// argument : none
// return : none
//=============================================================================
*/
static void SendTest_K ( void )
{
// Display send Test_K start message
DBG_FlowStrPrint("[Send Test_K Start]\r\n", FLOW_LV);
// Cancel the Auto mode temporarily
RegWrite(REG08_H_NegoControl_0,BIT_AutoModeCancel);
while((RegRead(REG08_H_NegoControl_0) & MASK_AutoModeCancel) == BIT_AutoModeCancel);
// Send 'K' in HS mode
RegSet(REG08_H_USB_Test, BIT_Test_K);
// Confirm the Timing of sending TestPacket
DBG_FlowStrPrint("[Test_K is issued. If it is good", FLOW_LV);
TestHitAnyKey();
// Display the Sending TestPacket message
DBG_FlowStrPrint("[Send Test_K Running]\r\n", FLOW_LV);
// Start to send Test_K
RegSet(REG08_H_USB_Test, BIT_EnHS_Test);
// Confirm the Timing of sending TestPacket
DBG_FlowStrPrint("[When you stop the issue of Test_K", FLOW_LV);
TestHitAnyKey();
// Terminate the test mode
RegWrite(REG08_H_USB_Test, 0x00);
RegModify(REG08_H_NegoControl_0,MASK_AutoMode,BIT_AutoMode_GoIDLE);
while((RegRead(REG08_H_NegoControl_0) & MASK_HostState) != BIT_HostState_IDLE);
// Display the sent Test_K normally message
DBG_FlowStrPrint("[Send Test_K Complete]\r\n", FLOW_LV);
return;
}
/*
//=============================================================================
// Function_Name: SendTest_SE0_NAK
// description : Send Test_SE0_NAK (Test9)
// argument : none
// return : none
//=============================================================================
*/
static void SendTest_SE0_NAK ( void )
{
// Display start to send Test_SE0_NAK message
DBG_FlowStrPrint("[Send Test_SE0_NAK Start]\r\n", FLOW_LV);
// Cancel the Auto mode temporarily
RegWrite(REG08_H_NegoControl_0,BIT_AutoModeCancel);
while((RegRead(REG08_H_NegoControl_0) & MASK_AutoModeCancel) == BIT_AutoModeCancel);
// In the HS mode, enter receiving status.
RegSet(REG08_H_USB_Test, BIT_Test_SE0_NAK);
// Confirm the Timing of sending TestPacket
DBG_FlowStrPrint("[Test_SE0_NAK is issued. If it is good", FLOW_LV);
TestHitAnyKey();
// display the Sending TestPacket message
DBG_FlowStrPrint("[Send Test_SE0_NAK Running]\r\n", FLOW_LV);
// Start to send Test_SE0_NAK
RegSet(REG08_H_USB_Test, BIT_EnHS_Test);
// Confirm the Timing of sending TestPacket
DBG_FlowStrPrint("[When you stop the issue of Test_SE0_NAK", FLOW_LV);
TestHitAnyKey();
// Terminate the test mode
RegWrite(REG08_H_USB_Test, 0x00);
RegModify(REG08_H_NegoControl_0,MASK_AutoMode,BIT_AutoMode_GoIDLE);
while((RegRead(REG08_H_NegoControl_0) & MASK_HostState) != BIT_HostState_IDLE);
// Display the message of Test_SE0_NAK was sent normally
DBG_FlowStrPrint("[Send Test_SE0_NAK Complete]\r\n", FLOW_LV);
return;
}
/*
//=============================================================================
// Function_Name: SendSuspend
// description : Issue Suspend (Test8)
// argument : none
// return : none
//=============================================================================
*/
static void SendSuspend ( unsigned char remoteWakeupControl )
{
// Display the start to send uspend message
DBG_FlowStrPrint("[Send Suspend Start]\r\n", FLOW_LV);
if( remoteWakeupControl == REMOTE_WAKEUP_ENABLE ){
RegSet(REG08_H_NegoControl_1, BIT_RmtWkupDetEnb);
} else {
RegClear(REG08_H_NegoControl_1, BIT_RmtWkupDetEnb);
}
/*===========================/
Disable the port /
/===========================*/
RegWrite(REG08_H_SIE_IntStat_1, INT_ALL_CLEAR);
RegModify(REG08_H_NegoControl_0,MASK_AutoMode,BIT_AutoMode_GoSUSPEND);
while((RegRead(REG08_H_SIE_IntStat_1) & MASK_SuspendCmp) != BIT_SuspendCmp);
DBG_FlowStrPrint("[Send Suspend Complete]\r\n", FLOW_LV);
return;
}
/*
//=============================================================================
// Function_Name: SendResume
// description : Send Resume (Test8)
// argument : none
// return : none
//=============================================================================
*/
static void SendResume ( void )
{
// Display the start to send resume message
DBG_FlowStrPrint("[Send Resume Start]\r\n", FLOW_LV);
/*===========================/
disable the port /
/===========================*/
RegWrite(REG08_H_SIE_IntStat_1, INT_ALL_CLEAR);
RegModify(REG08_H_NegoControl_0,MASK_AutoMode,BIT_AutoMode_GoRESUMEtoOP);
while((RegRead(REG08_H_SIE_IntStat_1) & MASK_ResumeCmp) != BIT_ResumeCmp);
DBG_FlowStrPrint("[Send Resume Complete]\r\n", FLOW_LV);
return;
}
/*
//=============================================================================
// Function_Name: HighSpeedHandShake
// description : Execute High Speed HandShake (Test7)
// Execute HS HandShake, then display the resultSuccess/Fail).
// argument : none
// return : none
//=============================================================================
*/
static void HighSpeedHandShake ( void )
{
// Display the message of start to execute High Speed HandShake
DBG_FlowStrPrint("[High Speed HandShake Start]\r\n", FLOW_LV);
// Process according to the execute result
if( SendReset() == STATUS_SUCCESS ) {
// Complete normally
DBG_FlowStrPrint("[High Speed HandShake Complete]\r\n", FLOW_LV);
} else {
// Complete with Error.
DBG_FlowStrPrint("[High Speed HandShake Error]\r\n", FLOW_LV);
}
return;
}
/*
//=============================================================================
// Function_Name: DeviceDisconnectDetect
// description : Detect Device Disconnect (Test6)
// At the HS,LS and FS mode, when Device is detached,will detect the disconnection and Display the result.
// argument : none
// return : none
//=============================================================================
*/
static void DeviceDisconnectDetect ( void )
{
unsigned long inputNumber;
unsigned short inputDataSize;
char inputData[80];
RegWrite(REG08_H_SIE_IntStat_0, BIT_DetectDiscon);
// Display device disconnect detect start message
DBG_FlowStrPrint("[Device Disconnect Detect Start]\r\n", FLOW_LV);
// Decide Speed Mode
DBG_FlowStrPrint("[Please select Speed Mode.]\r\n", FLOW_LV);
DBG_FlowStrPrint("[0 : High Speed]\r\n[1 : Full Speed]\r\n[3 : Low Speed]\r\n", FLOW_LV);
while(1) {
memset( inputData, 0x00, sizeof(inputData) );
FlowGetStr( inputData, &inputDataSize, 0 );
inputNumber = atol((const char *)inputData);
if( inputNumber == HIGH_SPEED_MODE || inputNumber == FULL_SPEED_MODE || inputNumber == LOW_SPEED_MODE ) {
RegModify(REG08_H_CH0Config_0, MASK_SpeedMode, inputNumber<<2);
break;
} else {
DBG_FlowStrPrint("[It is an input value error. Try to input it.]\r\n", FLOW_LV);
}
}
switch( inputNumber ) {
case HIGH_SPEED_MODE :
// In HS mode, can detect the disconnection
// Cancel the Auto mode temporarily
RegWrite(REG08_H_NegoControl_0,BIT_AutoModeCancel);
while((RegRead(REG08_H_NegoControl_0) & MASK_AutoModeCancel) == BIT_AutoModeCancel);
RegSet(REG08_H_USB_Test, BIT_Test_Force_Enable);
RegSet(REG08_H_USB_Test, BIT_EnHS_Test);
DBG_FlowStrPrint("[High Speed Mode was selected. Please disconnect the device.]\r\n", FLOW_LV);
break;
case FULL_SPEED_MODE :
DBG_FlowStrPrint("[Full Speed Modewas selected. Please disconnect the device.]\r\n", FLOW_LV);
break;
case LOW_SPEED_MODE :
DBG_FlowStrPrint("[Low Speed Modewas selected. Please disconnect the device.]\r\n", FLOW_LV);
break;
default :
break;
}
// Waiting for disconnection
DetectDisconResult = STATUS_UNSUCCESSFUL;
while(1) {
if( (RegRead(REG08_H_SIE_IntStat_0) & MASK_DetectDiscon) == BIT_DetectDiscon ) break;
}
RegWrite(REG08_H_SIE_IntStat_0, BIT_DetectDiscon);
DetectDisconResult = STATUS_SUCCESS;
DBG_FlowStrPrint("[Disconnecting the device was detected.]\r\n", FLOW_LV);
// Terminate the test mode
RegWrite(REG08_H_USB_Test, 0x00);
// 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);
// Check the device disconnect detect result
if( DetectDisconResult == STATUS_SUCCESS ) {
// Complete normally
DBG_FlowStrPrint("[Device Disconnect Detect Complete]\r\n", FLOW_LV);
} else {
// Complete with Error.
DBG_FlowStrPrint("[Device Disconnect Detect Complete]\r\n", FLOW_LV);
}
return;
}
/*
//=============================================================================
// Function_Name: SendGetDeviceDescriptorReq
// description : Send GetDescriptor(Device) request (Test2, Test5)
// Issues GetDescriptor(Device)request to Default PIPE.
// SingleStep mode/Loop mode
// argument : none
// return : none
//=============================================================================
*/
static void SendGetDeviceDescriptorReq ( void )
{
unsigned long inputNumber;
unsigned short inputDataSize;
unsigned char getDescData[CH0_MAX_PKT_SIZE], setupData[8], endFlag;
char inputData[80];
// Initialize the variables
memset( setupData, 0, sizeof(setupData) );
// Set GetDeviceDescriptor data
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -