📄 testanalog.c
字号:
/*
* description: Analog Test
* Maker : Mie.Ono
* Copyright : (C)2003,SEIKO EPSON Corp. All Rights Reserved.
*/
//=============================================================================
// Include Files
//=============================================================================
#include <string.h>
#include <stdlib.h>
#include <SPRDEF.h>
#include <SPRSTS.h>
#include <OSCall.h>
#include <DebugTask.h>
#include <Reg72V05.h>
#include <TestAnalog.h>
#include <TestOpposing.h>
#include <led_if.h>
//=============================================================================
//Constants declaration
//=============================================================================
#define FLOW_LV 3
#ifdef LITTLE_ENDIAN_C
#define REG08_HTM_Config (volatile UCHAR *)(REG_BASE + 0x1EE) /* HTM Configration */
#else /* #ifdef LITTLE_ENDIAN_C */
#define REG08_HTM_Config (volatile UCHAR *)(REG_BASE + 0x1EE) /* HTM Configration */
#endif /* #ifdef LITTLE_ENDIAN_C */
#define V05_CHIP_INT (10) // IRQ 10
#define TEST_STOP (0) // Stop evaluation
#define TEST_START (1) // Start evaluation
#define SINGLE_STEP (0x00) // Single Step ( only issue once )
#define LOOP_STEP (0x01) // Loop Step ( specify issue times-> 1-255 times )
#define UNKNOWN_STEP (0xFF) // Reserved
#define OFF (0) // OFF
#define ON (1) // ON
#define TEST_INIT "弶婜壔偵幐攕"
/* Data transfer direction */
#define DIR_HOST_TO_DEVICE (0x00)
#define DIR_DEVICE_TO_HOST (0x80)
/* Type */
#define TYPE_STANDARD (0x00)
#define TYPE_CLASS (0x20)
/* Standard Request Codes */
#define SREQ_GET_STATUS (0x00)
#define SREQ_CLEAR_FEATURE (0x01)
#define SREQ_SET_FEATURE (0x03)
#define SREQ_SET_ADDRESS (0x05)
#define SREQ_GET_DESCRIPTOR (0x06)
#define SREQ_SET_DESCRIPTOR (0x07)
#define SREQ_GET_CONFIGURATION (0x08)
#define SREQ_SET_CONFIGURATION (0x09)
#define SREQ_GET_INTERFACE (0x0A)
#define SREQ_SET_INTERFACE (0x0B)
#define SREQ_SYNCH_FRAME (0x0C)
/* Class Request Codes */
#define CREQ_GET_STATUS (0x00)
#define CREQ_CLEAR_FEATURE (0x01)
#define CREQ_SET_FEATURE (0x03)
#define CREQ_GET_DESCRIPTOR (0x06)
#define CREQ_CLEAR_TT_BUFFER (0x08)
#define CREQ_RESET_TT (0x09)
#define CREQ_GET_TT_STATE (0x0A)
#define CREQ_STOP_TT (0x0B)
/* Request Data Length */
#define GET_STATUS_DATA_LENGTH (0x02)
#define GET_CONFIG_DATA_LENGTH (0x01)
#define GET_INTERFACE_DATA_LENGTH (0x01)
#define CLASS_GET_STATUS_DATA_LENGTH (0x04)
#define CLASS_GET_TT_STATE_DATA_LENGTH (0x04)
/* Descriptor Types */
#define DTYPE_DEVICE (0x01)
#define DTYPE_CONFIGURATION (0x02)
#define DTYPE_STRING (0x03)
#define DTYPE_INTERFACE (0x04)
#define DTYPE_ENDPOINT (0x05)
#define DTYPE_DEVICE_QUALIFIER (0x06)
#define DTYPE_OTHER_SPEED_CONFIGURATION (0x07)
#define DTYPE_INTERFACE_POWER (0x08)
#define DTYPE_HUB (0x29)
/* Standard Feature Selector */
#define SFEA_ENDPOINT_HALT (0x00)
#define SFEA_DEVICE_REMOTE_WAKEUP (0x01)
#define SFEA_TEST_MODE (0x02)
/* Get Port Status - Port Status */
#define PORTSTS_PORT_CONNECTION (0x0001)
#define PORTSTS_PORT_ENABLE (0x0002)
#define PORTSTS_PORT_SUSPEND (0x0004)
#define PORTSTS_PORT_OVER_CURRENT (0x0008)
#define PORTSTS_PORT_RESET (0x0010)
#define PORTSTS_PORT_POWER (0x0100)
#define PORTSTS_PORT_LOW_SPEED (0x0200)
#define PORTSTS_PORT_HIGH_SPEED (0x0400)
#define PORTSTS_PORT_TEST (0x0800)
#define PORTSTS_PORT_INDICATOR (0x1000)
/* Get Port Status - Change Port Status */
#define PORTSTS_C_PORT_CONNECTION (0x0001)
#define PORTSTS_C_PORT_ENABLE (0x0002)
#define PORTSTS_C_PORT_SUSPEND (0x0004)
#define PORTSTS_C_PORT_OVER_CURRENT (0x0008)
#define PORTSTS_C_PORT_RESET (0x0010)
/* Class Feature Selector */
#define CFEA_C_HUB_LOCAL_POWER (0x00)
#define CFEA_C_HUB_OVER_CURRENT (0x01)
#define CFEA_PORT_ENABLE (0x01)
#define CFEA_PORT_SUSPEND (0x02)
#define CFEA_PORT_RESET (0x04)
#define CFEA_PORT_POWER (0x08)
#define CFEA_PORT_TEST (0x15)
#define CFEA_PORT_INDICATOR (0x16)
#define CFEA_C_PORT_CONNECTION (0x10)
#define CFEA_C_PORT_RESET (0x14)
#define CFEA_C_PORT_ENABLE (0x11)
#define CFEA_C_PORT_SUSPEND (0x12)
#define CFEA_C_PORT_OVER_CURRENT (0x13)
/* Set Feature Request */
#define TEST_J (0)
#define TEST_K (1)
#define TEST_SE0_NAK (2)
#define TEST_PACKET (3)
#define TEST_FORCE_ENABLE (4)
//Test API evaluate items
#define TEST_API_LS_SIGNAL (1) // Host LS Signal Quality ( Legacy USB Compliance Test )
#define TEST_API_FS_SIGNAL (2) // Host FS Signal Quality ( Legacy USB Compliance Test )
#define TEST_API_HS_SIGNAL (3) // Host HS Signal Quality ( Host High-speed Electrical Test )
#define TEST_API_SINGLE_STEP_GDES (4) // Single Step Get Descriptor( Host High-speed Electrical Test )
#define TEST_API_DROP_DROOP (5) // Drop/Droop ( Legacy USB Compliance Test )
#define TEST_API_DISCON_DET (6) // Host Disconnect Detect ( Host High-speed Electrical Test )
#define TEST_API_J_K_SE0_NAK (7) // Host Test J/K, SE0_NAK ( Host High-speed Electrical Test )
#define TEST_API_CHIRP (8) // Host CHIRP Timing ( Host High-speed Electrical Test )
#define TEST_API_SUSPEND_RESUME (9) // Host Suspend/Resume Timing ( Host High-speed Electrical Test )
#define TEST_API_TEST_DATA_RCV (10) // Test Data Receive ( Option )
#define TEST_API_SET_TERMSLOPE_VALUE (11) //Term/Slope Value modification
#define TEST_API_INITIALIZE (0x00) // Initial status
#define TEST_API_COMPLETE (0xFE) // Complete normally
#define TEST_API_ERROR (0xFF) // Complete with error
#define TEST_API_TEST_J (1) // Test J
#define TEST_API_TEST_K (2) // Test K
#define TEST_API_TEST_SE0_NAK (3) // Test SE0_NAK
#define TEST_API_DISCON_DET_NORMAL (1) // Disconnect test after the device is connected
#define TEST_API_DISCON_DET_FORCE (2) // Disconnect test when set to the HS compulsorily .
#define QUIT_BIG ('Q') // Complete
#define QUIT_LITTLE ('q') // Complete
#define DEVICE_DESC_SIZE (0x12) // Device Descriptor Size
#define MASK_RD_REMAIN_VALID (0x8000)
#define MASK_FRACTION (0x01)
#define NEGO_AUTO_MODE_CANCEL (0x80)
/* Recipient */
#define RECIPIENT_DEVICE (0x00)
#define RECIPIENT_INTERFACE (0x01)
#define RECIPIENT_ENDPOINT (0x02)
#define RECIPIENT_OTHER (0x03)
/* USB Host State */
#define RESERVED_STATE (0) // reserved
#define IDLE_STATE (1) // IDLE
#define WAIT_CONNECT_STATE (2) // WAIT_CONNECT
#define DISABLED_STATE (3) // DISABLED
#define RESET_STATE (4) // RESET
#define OPERATIONAL_STATE (5) // OPERATIONAL
#define SUSPEND_STATE (6) // SUSPEND
#define RESUME_STATE (7) // RESUME
/* USB Auto Mode Command */
#define GoRESERVED (0x00) // reserved
#define GoIDLE (0x01) // IDLE
#define GoWAIT_CONNECT (0x02) // WAIT_CONNECT
#define GoDISABLED (0x03) // DISABLED
#define GoRESET (0x04) // RESET
#define GoOPERATIONAL (0x05) // OPERATIONAL
#define GoSUSPEND (0x06) // SUSPEND
#define GoRESUME (0x07) // RESUME
#define GoWAIT_CONNECTtoDIS (0x09) // WAIT_CONNECT - DISABLE
#define GoWAIT_CONNECTtoOP (0x0A) // WAIT_CONNECT - OPERATIONAL
#define GoRESETtoOP (0x0C) // RESET - OPERATIONAL
#define GoSUSPENDtoOP (0x0E) // RESUME - OPERATIONAL
#define GoRESUMEtoOP (0x0F) // SUSPEND - OPERATIONAL
/* USB Speed Mode */
#define HIGH_SPEED_MODE (0) // High Speed Mode
#define FULL_SPEED_MODE (1) // Full Speed Mode
#define RESERVED_SPEED_MODE (2) // Reserved
#define LOW_SPEED_MODE (3) // Low Speed Mode
/* USB Channel Number 0 - E */
#define CH0_MAX_PKT_SIZE (0x40) // Channel 0 Max Packet Size ( 64Byte )
#define CHA_MAX_PKT_SIZE (0x0200) // Channel a Max Packet Size ( 512Byte )
#define CHB_MAX_PKT_SIZE (0x0200) // Channel b Max Packet Size ( 512Byte )
#define CHC_MAX_PKT_SIZE (0x0200) // Channel c Max Packet Size ( 512Byte )
#define CHD_MAX_PKT_SIZE (0x0200) // Channel d Max Packet Size ( 512Byte )
#define CHE_MAX_PKT_SIZE (0x0200) // Channel e Max Packet Size ( 512Byte )
/* USB Line State */
#define LINE_STATE_SE0 (0) // SE0
#define LINE_STATE_J (1) // J
#define LINE_STATE_K (2) // K
#define LINE_STATE_SE1 (3) // SE1
#define REMOTE_WAKEUP_DISABLE (0)
#define REMOTE_WAKEUP_ENABLE (1)
//=============================================================================
//Macros declaration
//=============================================================================
//=============================================================================
//Structures declaration
//=============================================================================
// Channel information
typedef struct tagCHANNEL_DATA {
unsigned short tranSize; // Transfer Size
unsigned char channelNum; // Channel Number ( CH0=0x00, CHa=0x10, CHb=0x20, CHc=0x30, CHd=0x40, CHe=0x50 )
unsigned char speedMode : 2; // Speed Mode ( 0=High, 1=Full, 2=Reserved, 3=Low )
unsigned char tidType : 2; // TID Type ( 0=Setup, 1=Out, 2=In, 3=Reserved )
unsigned char reserved : 4;
} CHANNEL_DATA;
// Device Descriptor information.
typedef struct tagDEVICE_DESC_DATA {
unsigned char bLength;
unsigned char bDescriptorType;
unsigned short bcdUSB;
unsigned char bDeviceClass;
unsigned char bDeviceSubClass;
unsigned char bDeviceProtocol;
unsigned char bMaxPacketSize0;
unsigned short idVendor;
unsigned short idProduct;
unsigned short bcdDevice;
unsigned char iManufacturer;
unsigned char iProduct;
unsigned char iSerialNumber;
unsigned char bNumConfigurations;
} DEVICE_DESC_DATA;
//=============================================================================
// Variables declaration
//=============================================================================
volatile long SuspendResult; // Suspend result
volatile long ResumeResult; // Resume result
volatile long DetectDisconResult; //The disconnect detect result
volatile long HCD_InitResult; //HCD initialization result
volatile long KeyResult; // Key input interrupt notify
volatile unsigned char TermValue; // TermValue value
volatile unsigned char SlopeValue; //SlopeValue value
//=============================================================================
// Static functions
//=============================================================================
static long TestMain( unsigned char testMenu ); // TestMain
static void Test_1( void ); // Test1 : Host LS Signal Quality ( Legacy USB Compliance Test )
static void Test_2( void ); // Test2 : Host FS Signal Quality ( Legacy USB Compliance Test )
static void Test_3( void ); // Test3 : Host HS Signal Quality ( Host High-speed Electrical Test )
static void Test_4 ( void ); // Test4 : Signe Step Get Descriptor ( Host High-speed Electrical Test )
static void Test_5( void ); // Test5 : Drop/Droop ( Legacy USB Compliance Test )
static void Test_6( void ); // Test6 : Host Disconnect Detect ( Host High-speed Electrical Test )
static void Test_7( void ); // Test7 : Host Test J/K, SE0_NAK ( Host High-speed Electrical Test )
static void Test_8( void ); // Test8 : Host CHIRP Timing ( Host High-speed Electrical Test )
static void Test_9( void ); // Test9 : Host Suspend/Resume Timing ( Host High-speed Electrical Test )
static void Test_10( void ); // Test10: Test Data Receive ( Option )
static void Test_11 ( void ); // Test11: Set Term/Slope Value
static void DropDroop( void ); // VBUS supply
static long SendReset ( void ); // Send reset
static void SendTestPacket ( void ); // Send Test Packet
static void SendTest_J ( void ); // Send Test_J
static void SendTest_K ( void ); // Send Test_K
static void SendTest_SE0_NAK ( void ); // Send Test_SE0_NAK
static void SendSuspend ( unsigned char remoteWakeupControl ); // Send Suspend
static void SendResume ( void ); // Send Resume
static void HighSpeedHandShake ( void ); // Execute HS HandShake
static void DeviceDisconnectDetect ( void ); // Device Disconnect detect
static void SendGetDeviceDescriptorReq ( void ); // Send GetDescriptor(Device) request
static void ReceiveTestPacket ( void ); // Receive Test Packet
static void ChipReset ( void ); // Initialization
static void TestDevConnect( void ); // Device connection handler
static void TestHitAnyKey ( void ); // Waiting for key input
static void DescriptorPrint ( DEVICE_DESC_DATA *pDescData ); //Device Descriptor Express
static void SendRequest ( unsigned char *pReqData, unsigned char *pDataBuf ); // Send request
static long SingleStepSendRequest ( unsigned char *pReqData ); //Send request
static void SetTermSlopeValue ( unsigned char termValue, unsigned char slopeValue ); //Set Term/Slope Value
static void TestAnalogErr ( CHAR* chapter, int fileLine ); // Test Analog Proc Error
static void KeyCmpCallback( void ); // Key input notify
static unsigned long ReadFIFOData( unsigned char chNum, unsigned char *pBufAdrs );
/*
//=============================================================================
// Function_Name: TestStart
// description : Start the evaluation
// argument :
// return :
//=============================================================================
*/
void AnalogTestStart ( void )
{
unsigned short inputDataSize;
char inputData[80];
unsigned char testResult;
unsigned long inputNumber;
// Initialize the variables
testResult = TEST_API_INITIALIZE;
TermValue = 0;
SlopeValue = 0;
//Main loop
while(1) {
// Test Menu judgment
DBG_FlowStrPrint("\r\n[ Please select the evaluation item ]", FLOW_LV);
DBG_FlowStrPrint("\r\n[ in the alphanumeric character of 1-11 and q. ]\r\n", FLOW_LV);
DBG_FlowStrPrint(" 1: Host LS Signal Quality (Get Device Descriptor transmission)\r\n", FLOW_LV);
DBG_FlowStrPrint(" 2: Host FS Signal Quality (Get Device Descriptor transmission)\r\n", FLOW_LV);
DBG_FlowStrPrint(" 3: Host HS Signal Quality (Test Packet transmission)\r\n", FLOW_LV);
DBG_FlowStrPrint(" 4: Single Step Get Descriptor Test( Packet Parameter)\r\n", FLOW_LV);
DBG_FlowStrPrint(" 5: Drop/Droop(VBUS supply)\r\n", FLOW_LV);
DBG_FlowStrPrint(" 6: Host Disconnect Detect (Device disconnect detection)\r\n", FLOW_LV);
DBG_FlowStrPrint(" 7: Host Test J/K, SE0_NAK (Test J / K / SE0_NAK issue)\r\n", FLOW_LV);
DBG_FlowStrPrint(" 8: Host CHIRP Timing (CHIRP execution)\r\n", FLOW_LV);
DBG_FlowStrPrint(" 9: Host Suspend/Resume Timing (Suspend / Resume execution)\r\n", FLOW_LV);
DBG_FlowStrPrint("10: Test Data reception Test\r\n (Option and opposition examination device necessity)\r\n", FLOW_LV);
DBG_FlowStrPrint("11: Term/Slope Value change\r\n", FLOW_LV);
DBG_FlowStrPrint("q : End Test Menu (Select Host/Device Mode)\r\n", FLOW_LV);
// Keyboard input loop
while(1) {
memset( inputData, 0x00, sizeof(inputData) );
FlowGetStr( inputData, &inputDataSize, 0 );
if( inputData[0] == QUIT_BIG || inputData[0] == QUIT_LITTLE ){
break;
}
inputNumber = atol((const char *)inputData);
switch( inputNumber ) {
case TEST_API_LS_SIGNAL:
case TEST_API_FS_SIGNAL:
case TEST_API_HS_SIGNAL:
case TEST_API_SINGLE_STEP_GDES:
case TEST_API_DROP_DROOP:
case TEST_API_DISCON_DET:
case TEST_API_J_K_SE0_NAK:
case TEST_API_CHIRP:
case TEST_API_SUSPEND_RESUME:
case TEST_API_TEST_DATA_RCV:
case TEST_API_SET_TERMSLOPE_VALUE:
testResult = TestMain( (unsigned char)inputNumber );
break;
// Nothing
case QUIT_BIG :
case QUIT_LITTLE :
break;
//Should not run into here
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -