📄 pe_usb.c
字号:
u8fifo_n = mUsbEPMapRd(u8ep_n); // get the relatived FIFO number
if (bdir == 1)
u8fifo_n &= 0x0F;
else
u8fifo_n >>= 4;
if (u8fifo_n >= FOTG200_Periph_MAX_FIFO) // over the Max. fifo count ?
return FALSE;
// Check the FIFO had been enable ?
if ((mUsbFIFOConfigRd(u8fifo_n) & FIFOEnBit) == 0)
return FALSE;
if (bdir == 1) // IN direction ?
RecipientStatusLow = mUsbEPinStallST(u8ep_n);
else
RecipientStatusLow = mUsbEPoutStallST(u8ep_n);
}
}
break;
default :
return FALSE;
}
// return RecipientStatus;
u8Tmp[0] = RecipientStatusLow;
u8Tmp[1] = RecipientStatusHigh;
vOTGCxFWr( u8Tmp, 2);
eOTGCxFinishAction = ACT_DONE;
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
// bClear_OTGfeature()
// Description:
// 1. Send 2 bytes status to host.
// input: none
// output: TRUE or FALSE (BOOLEAN)
///////////////////////////////////////////////////////////////////////////////
BOOLEAN bClear_OTGfeature(void)
{
INT8U u8ep_n;
INT8U u8fifo_n;
BOOLEAN bdir;
switch (ControlOTGCmd.Value) // FeatureSelector
{
case 0: // ENDPOINT_HALE
// Clear "Endpoint_Halt", Turn off the "STALL" bit in Endpoint Control Function Register
if(ControlOTGCmd.Index == 0x00)
bOTGEP0HaltSt = FALSE;
else
{
u8ep_n = ControlOTGCmd.Index & 0x7F; // which ep will be clear
bdir = ControlOTGCmd.Index >> 7; // the direction of this ep
if (u8ep_n > FOTG200_Periph_MAX_EP) // over the Max. ep count ?
return FALSE;
else
{
u8fifo_n = mUsbEPMapRd(u8ep_n); // get the relatived FIFO number
if (bdir == 1)
u8fifo_n &= 0x0F;
else
u8fifo_n >>= 4;
if (u8fifo_n >= FOTG200_Periph_MAX_FIFO) // over the Max. fifo count ?
return FALSE;
// Check the FIFO had been enable ?
if ((mUsbFIFOConfigRd(u8fifo_n) & FIFOEnBit) == 0)
return FALSE;
if (bdir == 1) // IN direction ?
{
mUsbEPinRsTgSet(u8ep_n); // Set Rst_Toggle Bit
mUsbEPinRsTgClr(u8ep_n); // Clear Rst_Toggle Bit
mUsbEPinStallClr(u8ep_n); // Clear Stall Bit
}
else
{
mUsbEPoutRsTgSet(u8ep_n); // Set Rst_Toggle Bit
mUsbEPoutRsTgClr(u8ep_n); // Clear Rst_Toggle Bit
mUsbEPoutStallClr(u8ep_n); // Clear Stall Bit
}
}
}
break;
case 1 : // Device Remote Wakeup
// Clear "Device_Remote_Wakeup", Turn off the"RMWKUP" bit in Main Control Register
mUsbRmWkupClr();
break;
case 2 : // Test Mode
return FALSE;
default :
return FALSE;
}
eOTGCxFinishAction = ACT_DONE;
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
// bSet_OTGfeature()
// Description:
// 1. Process Cx Set feature command.
// input: none
// output: TRUE or FALSE (BOOLEAN)
///////////////////////////////////////////////////////////////////////////////
BOOLEAN bSet_OTGfeature(void)
{
INT8U i;
INT8U u8ep_n;
INT8U u8fifo_n;
INT8U u8Tmp[52];
INT8U * pp;
BOOLEAN bdir;
switch (ControlOTGCmd.Value) // FeatureSelector
{
case 0: // ENDPOINT_HALE
// Set "Endpoint_Halt", Turn on the "STALL" bit in Endpoint Control Function Register
if(ControlOTGCmd.Index == 0x00)
bOTGEP0HaltSt = TRUE;
else
{
u8ep_n = ControlOTGCmd.Index & 0x7F; // which ep will be clear
bdir = ControlOTGCmd.Index >> 7; // the direction of this ep
if (u8ep_n > FOTG200_Periph_MAX_EP) // over the Max. ep count ?
return FALSE;
else
{
u8fifo_n = mUsbEPMapRd(u8ep_n); // get the relatived FIFO number
if (bdir == 1)
u8fifo_n &= 0x0F;
else
u8fifo_n >>= 4;
if (u8fifo_n >= FOTG200_Periph_MAX_FIFO) // over the Max. fifo count ?
return FALSE;
// Check the FIFO had been enable ?
if ((mUsbFIFOConfigRd(u8fifo_n) & FIFOEnBit) == 0)
return FALSE;
if (bdir == 1) // IN direction ?
mUsbEPinStallSet(u8ep_n); // Clear Stall Bit
else
mUsbEPoutStallSet(u8ep_n); // Set Stall Bit
}
}
break;
case 1 : // Device Remote Wakeup
// Set "Device_Remote_Wakeup", Turn on the"RMWKUP" bit in Mode Register
mUsbRmWkupSet();
eOTGCxFinishAction = ACT_DONE;
break;
case 2 : // Test Mode
switch ((ControlOTGCmd.Index >> 8)) // TestSelector
{
case 0x1: // Test_J
mUsbTsMdWr(TEST_J);
eOTGCxFinishAction = ACT_DONE;
break;
case 0x2: // Test_K
mUsbTsMdWr(TEST_K);
eOTGCxFinishAction = ACT_DONE;
break;
case 0x3: // TEST_SE0_NAK
mUsbTsMdWr(TEST_SE0_NAK);
eOTGCxFinishAction = ACT_DONE;
break;
case 0x4: // Test_Packet
mUsbTsMdWr(TEST_PKY);
mUsbEP0DoneSet(); // special case: follow the test sequence
//////////////////////////////////////////////
// Jay ask to modify, 91-6-5 (Begin) //
//////////////////////////////////////////////
pp = u8Tmp;
for (i=0; i<9; i++) // JKJKJKJK x 9
{
(*pp) = (0x00);
pp ++;
}
(*pp) = (0xAA);
pp ++;
(*pp) = (0x00);
pp ++;
for (i=0; i<8; i++) // 8*AA
{
(*pp) = (0xAA);
pp ++;
}
for (i=0; i<8; i++) // 8*EE
{
(*pp) = (0xEE);
pp ++;
}
(*pp) = (0xFE);
pp ++;
for (i=0; i<11; i++) // 11*FF
{
(*pp) = (0xFF);
pp ++;
}
(*pp) = (0x7F);
pp ++;
(*pp) = (0xBF);
pp ++;
(*pp) = (0xDF);
pp ++;
(*pp) = (0xEF);
pp ++;
(*pp) = (0xF7);
pp ++;
(*pp) = (0xFB);
pp ++;
(*pp) = (0xFD);
pp ++;
(*pp) = (0xFC);
pp ++;
(*pp) = (0x7E);
pp ++;
(*pp) = (0xBF);
pp ++;
(*pp) = (0xDF);
pp ++;
(*pp) = (0xFB);
pp ++;
(*pp) = (0xFD);
pp ++;
(*pp) = (0xFB);
pp ++;
(*pp) = (0xFD);
pp ++;
(*pp) = (0x7E);
vOTGCxFWr( u8Tmp, 52);
//////////////////////////////////////////////
// Jay ask to modify, 91-6-5 (End) //
//////////////////////////////////////////////
// Turn on "r_test_packet_done" bit(flag) (Bit 5)
mUsbTsPkDoneSet();
break;
case 0x5: // Test_Force_Enable
//FUSBPort[0x08] = 0x20; //Start Test_Force_Enable
break;
default:
return FALSE;
}
break;
case 3 : //For OTG => b_hnp_enable
OTGP_HNP_Enable();
eOTGCxFinishAction = ACT_DONE;
break;
case 4 : //For OTG => b_hnp_enable
eOTGCxFinishAction = ACT_DONE;
break;
case 5 : //For OTG => b_hnp_enable
printf(">>> Please Connect to an alternate port on the A-device for HNP...\n");
eOTGCxFinishAction = ACT_DONE;
break;
default :
return FALSE;
}
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
// bSet_OTGaddress()
// Description:
// 1. Set USB bus addr to FOTG200 Device register.
// input: none
// output: TRUE or FALSE (BOOLEAN)
///////////////////////////////////////////////////////////////////////////////
BOOLEAN bSet_OTGaddress(void)
{
if (ControlOTGCmd.Value >= 0x0100)
return FALSE;
else
{
mUsbDevAddrSet(ControlOTGCmd.Value);
eOTGCxFinishAction = ACT_DONE;
return TRUE;
}
}
///////////////////////////////////////////////////////////////////////////////
// bGet_OTGdescriptor()
// Description:
// 1. Point to the start location of the correct descriptor.
// 2. set the transfer length and return descriptor information back to host
// input: none
// output: TRUE or FALSE (BOOLEAN)
///////////////////////////////////////////////////////////////////////////////
BOOLEAN bGet_OTGdescriptor(void)
{
//////////////// Decide the display descriptor length(range) //////////////
switch ((INT8U)(ControlOTGCmd.Value >> 8))
{
case 1: // device descriptor
pu8OTGDescriptorEX = &u8OTGDeviceDescriptorEX[0];
u16OTGTxRxCounter = u8OTGDeviceDescriptorEX[0];
break;
case 2: // configuration descriptor
// It includes Configuration, Interface and Endpoint Table
switch ((INT8U)ControlOTGCmd.Value)
{
case 0x00: // configuration no: 0
pu8OTGDescriptorEX = &u8ConfigOTGDescriptorEX[0];
u16OTGTxRxCounter = u8ConfigOTGDescriptorEX[2] + (u8ConfigOTGDescriptorEX[3] << 8);
break;
default:
return FALSE;
}
break;
case 3: // string descriptor
// DescriptorIndex = low_byte of wValue
switch ((INT8U)ControlOTGCmd.Value)
{
case 0x00:
pu8OTGDescriptorEX = &u8OTGString00DescriptorEX[0];
u16OTGTxRxCounter = u8OTGString00DescriptorEX[0];
break;
case 0x10:
pu8OTGDescriptorEX = &u8OTGString10DescriptorEX[0];
u16OTGTxRxCounter = u8OTGString10DescriptorEX[0];
break;
case 0x20:
pu8OTGDescriptorEX = &u8OTGString20DescriptorEX[0];
u16OTGTxRxCounter = u8OTGString20DescriptorEX[0];
break;
case 0x30:
pu8OTGDescriptorEX = &u8OTGString30DescriptorEX[0];
u16OTGTxRxCounter = u8OTGString30DescriptorEX[0];
break;
case 0x40:
pu8OTGDescriptorEX = &u8OTGString40DescriptorEX[0];
u16OTGTxRxCounter = u8OTGString40DescriptorEX[0];
break;
case 0x50:
pu8OTGDescriptorEX = &u8OTGString50DescriptorEX[0];
u16OTGTxRxCounter = u8OTGString50DescriptorEX[0];
break;
default:
return FALSE;
}
break;
case 4: // interface descriptor
// It cannot be accessed individually, it must follow "Configuraton"
break;
case 5: // endpoint descriptor
// It cannot be accessed individually, it must follow "Configuraton"
break;
case 6: // Device_Qualifier descritor
pu8OTGDescriptorEX = &u8OTGDeviceQualifierDescriptorEX[0];
u16OTGTxRxCounter = u8OTGDeviceQualifierDescriptorEX[0];
break;
case 7: // Other_Speed_Configuration
// It includes Configuration, Interface and Endpoint Table
pu8OTGDescriptorEX = &u8OtherSpeedConfigOTGDescriptorEX[0];
u16OTGTxRxCounter = u8OtherSpeedConfigOTGDescriptorEX[2] +
(u8OtherSpeedConfigOTGDescriptorEX[3] << 8);
break;
default:
return FALSE;
}
if (u16OTGTxRxCounter > ControlOTGCmd.Length)
u16OTGTxRxCounter = ControlOTGCmd.Length;
//if (u16OTGTxRxCounter==0)//Bruce;;Add;;Test
// {mUsbEP0DoneSet();//Bruce;;Add;;Test
// return TRUE;//Bruce;;Add;;Test
// }//Bruce;;Add;;Test
eOTGCxCommand = CMD_GET_DESCRIPTOR;
vOTGEP0TxData();
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
// bSet_OTGdescriptor()
// Description:
// 1. Point to the start location of the correct descriptor.
// 2. Set the transfer length, and we will save data into sdram when Rx interrupt occure
// input: none
// output: TRUE or FALSE (BOOLEAN)
///////////////////////////////////////////////////////////////////////////////
BOOLEAN bSet_OTGdescriptor(void)
{
switch ((INT8U)(ControlOTGCmd.Value >> 8))
{
case 1: // device descriptor
pu8OTGDescriptorEX = &u8OTGDeviceDescriptorEX[0];
u16OTGTxRxCounter = u8OTGDeviceDescriptorEX[0];
break;
case 2: // configuration descriptor
// It includes Configuration, Interface and Endpoint Table
// DescriptorIndex = low_byte of wValue
switch ((INT8U)ControlOTGCmd.Value)
{
case 0x00: // configuration no: 0
pu8OTGDescriptorEX = &u8ConfigOTGDescriptorEX[0];
u16OTGTxRxCounter = u8ConfigOTGDescriptorEX[0];
break;
default:
return FALSE;
}
break;
case 3: // string descriptor
// DescriptorIndex = low_byte of wValue
switch ((INT8U)ControlOTGCmd.Value)
{
case 0x00:
pu8OTGDescriptorEX = &u8OTGString00DescriptorEX[0];
u16OTGTxRxCounter = u8OTGString00DescriptorEX[0];
break;
case 0x10:
pu8OTGDescriptorEX = &u8OTGString10DescriptorEX[0];
u16OTGTxRxCounter = u8OTGString10DescriptorEX[0];
break;
case 0x20:
pu8OTGDescriptorEX = &u8OTGString20DescriptorEX[0];
u16OTGTxRxCounter = u8OTGString20DescriptorEX[0];
break;
case 0x30:
pu8OTGDescriptorEX = &u8OTGString30DescriptorEX[0];
u16OTGTxRxCounter = u8OTGString30DescriptorEX[0];
break;
case 0x40:
pu8OTGDescriptorEX = &u8OTGString40DescriptorEX[0];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -