📄 usbhost_lpc17xx.c
字号:
//PRINT_Err(rc);
return (rc);
}
Host_DelayMS(2);
EDCtrl->Control = (EDCtrl->Control) | 1; /* Modify control pipe with address 1 */
/* Get the configuration descriptor */
rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_CONFIGURATION, 0, TDBuffer, 9);
if (rc != OK) {
//PRINT_Err(rc);
return (rc);
}
/* Get the first configuration data */
rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_CONFIGURATION, 0, TDBuffer, ReadLE16U(&TDBuffer[2]));
if (rc != OK) {
//PRINT_Err(rc);
return (rc);
}
rc = MS_ParseConfiguration(); /* Parse the configuration */
if (rc != OK) {
//PRINT_Err(rc);
return (rc);
}
rc = USBH_SET_CONFIGURATION(1); /* Select device configuration 1 */
if (rc != OK) {
//PRINT_Err(rc);
}
Host_DelayMS(100); /* Some devices may require this delay */
return (rc);
}
/*
**************************************************************************************************************
* RECEIVE THE CONTROL INFORMATION
*
* Description: This function is used to receive the control information
*
* Arguments : bm_request_type
* b_request
* w_value
* w_index
* w_length
* buffer
*
* Returns : OK if Success
* ERROR if Failed
*
**************************************************************************************************************
*/
int32_t Host_CtrlRecv ( uint8_t bm_request_type,
uint8_t b_request,
uint16_t w_value,
uint16_t w_index,
uint16_t w_length,
volatile uint8_t *buffer)
{
int32_t rc;
Host_FillSetup(bm_request_type, b_request, w_value, w_index, w_length);
rc = Host_ProcessTD(EDCtrl, TD_SETUP, TDBuffer, 8);
if (rc == OK) {
if (w_length) {
rc = Host_ProcessTD(EDCtrl, TD_IN, TDBuffer, w_length);
}
if (rc == OK) {
rc = Host_ProcessTD(EDCtrl, TD_OUT, NULL, 0);
}
}
return (rc);
}
/*
**************************************************************************************************************
* SEND THE CONTROL INFORMATION
*
* Description: This function is used to send the control information
*
* Arguments : None
*
* Returns : OK if Success
* ERR_INVALID_BOOTSIG if Failed
*
**************************************************************************************************************
*/
int32_t Host_CtrlSend ( uint8_t bm_request_type,
uint8_t b_request,
uint16_t w_value,
uint16_t w_index,
uint16_t w_length,
volatile uint8_t *buffer)
{
int32_t rc;
Host_FillSetup(bm_request_type, b_request, w_value, w_index, w_length);
rc = Host_ProcessTD(EDCtrl, TD_SETUP, TDBuffer, 8);
if (rc == OK) {
if (w_length) {
rc = Host_ProcessTD(EDCtrl, TD_OUT, TDBuffer, w_length);
}
if (rc == OK) {
rc = Host_ProcessTD(EDCtrl, TD_IN, NULL, 0);
}
}
return (rc);
}
/*
**************************************************************************************************************
* FILL SETUP PACKET
*
* Description: This function is used to fill the setup packet
*
* Arguments : None
*
* Returns : OK if Success
* ERR_INVALID_BOOTSIG if Failed
*
**************************************************************************************************************
*/
void Host_FillSetup (uint8_t bm_request_type,
uint8_t b_request,
uint16_t w_value,
uint16_t w_index,
uint16_t w_length)
{
int i;
for (i=0;i<w_length;i++)
TDBuffer[i] = 0;
TDBuffer[0] = bm_request_type;
TDBuffer[1] = b_request;
WriteLE16U(&TDBuffer[2], w_value);
WriteLE16U(&TDBuffer[4], w_index);
WriteLE16U(&TDBuffer[6], w_length);
}
/*
**************************************************************************************************************
* INITIALIZE THE TRANSFER DESCRIPTOR
*
* Description: This function initializes transfer descriptor
*
* Arguments : Pointer to TD structure
*
* Returns : None
*
**************************************************************************************************************
*/
void Host_TDInit (volatile HCTD *td)
{
td->Control = 0;
td->CurrBufPtr = 0;
td->Next = 0;
td->BufEnd = 0;
}
/*
**************************************************************************************************************
* INITIALIZE THE ENDPOINT DESCRIPTOR
*
* Description: This function initializes endpoint descriptor
*
* Arguments : Pointer to ED strcuture
*
* Returns : None
*
**************************************************************************************************************
*/
void Host_EDInit (volatile HCED *ed)
{
ed->Control = 0;
ed->TailTd = 0;
ed->HeadTd = 0;
ed->Next = 0;
}
/*
**************************************************************************************************************
* INITIALIZE HOST CONTROLLER COMMUNICATIONS AREA
*
* Description: This function initializes host controller communications area
*
* Arguments : Pointer to HCCA
*
* Returns :
*
**************************************************************************************************************
*/
void Host_HCCAInit (volatile HCCA *hcca)
{
uint32_t i;
for (i = 0; i < 32; i++) {
hcca->IntTable[i] = 0;
hcca->FrameNumber = 0;
hcca->DoneHead = 0;
}
}
/*
**************************************************************************************************************
* WAIT FOR WDH INTERRUPT
*
* Description: This function is infinite loop which breaks when ever a WDH interrupt rises
*
* Arguments : None
*
* Returns : None
*
**************************************************************************************************************
*/
void Host_WDHWait (void)
{
while (!HOST_WdhIntr) {
;
}
HOST_WdhIntr = 0;
}
/*
**************************************************************************************************************
* READ LE 32U
*
* Description: This function is used to read an unsigned integer from a charecter buffer in the platform
* containing little endian processor
*
* Arguments : pmem Pointer to the charecter buffer
*
* Returns : val Unsigned integer
*
**************************************************************************************************************
*/
uint32_t ReadLE32U (volatile uint8_t *pmem)
{
uint32_t val;
((uint8_t *)&val)[0] = pmem[0];
((uint8_t *)&val)[1] = pmem[1];
((uint8_t *)&val)[2] = pmem[2];
((uint8_t *)&val)[3] = pmem[3];
return (val);
}
/*
**************************************************************************************************************
* WRITE LE 32U
*
* Description: This function is used to write an unsigned integer into a charecter buffer in the platform
* containing little endian processor.
*
* Arguments : pmem Pointer to the charecter buffer
* val Integer value to be placed in the charecter buffer
*
* Returns : None
*
**************************************************************************************************************
*/
void WriteLE32U (volatile uint8_t *pmem,
uint32_t val)
{
pmem[0] = ((uint8_t *)&val)[0];
pmem[1] = ((uint8_t *)&val)[1];
pmem[2] = ((uint8_t *)&val)[2];
pmem[3] = ((uint8_t *)&val)[3];
}
/*
**************************************************************************************************************
* READ LE 16U
*
* Description: This function is used to read an unsigned short integer from a charecter buffer in the platform
* containing little endian processor
*
* Arguments : pmem Pointer to the charecter buffer
*
* Returns : val Unsigned short integer
*
**************************************************************************************************************
*/
uint16_t ReadLE16U (volatile uint8_t *pmem)
{
uint16_t val;
((uint8_t *)&val)[0] = pmem[0];
((uint8_t *)&val)[1] = pmem[1];
return (val);
}
/*
**************************************************************************************************************
* WRITE LE 16U
*
* Description: This function is used to write an unsigned short integer into a charecter buffer in the
* platform containing little endian processor
*
* Arguments : pmem Pointer to the charecter buffer
* val Value to be placed in the charecter buffer
*
* Returns : None
*
**************************************************************************************************************
*/
void WriteLE16U (volatile uint8_t *pmem,
uint16_t val)
{
pmem[0] = ((uint8_t *)&val)[0];
pmem[1] = ((uint8_t *)&val)[1];
}
/*
**************************************************************************************************************
* READ BE 32U
*
* Description: This function is used to read an unsigned integer from a charecter buffer in the platform
* containing big endian processor
*
* Arguments : pmem Pointer to the charecter buffer
*
* Returns : val Unsigned integer
*
**************************************************************************************************************
*/
uint32_t ReadBE32U (volatile uint8_t *pmem)
{
uint32_t val;
((uint8_t *)&val)[0] = pmem[3];
((uint8_t *)&val)[1] = pmem[2];
((uint8_t *)&val)[2] = pmem[1];
((uint8_t *)&val)[3] = pmem[0];
return (val);
}
/*
**************************************************************************************************************
* WRITE BE 32U
*
* Description: This function is used to write an unsigned integer into a charecter buffer in the platform
* containing big endian processor
*
* Arguments : pmem Pointer to the charecter buffer
* val Value to be placed in the charecter buffer
*
* Returns : None
*
**************************************************************************************************************
*/
void WriteBE32U (volatile uint8_t *pmem,
uint32_t val)
{
pmem[0] = ((uint8_t *)&val)[3];
pmem[1] = ((uint8_t *)&val)[2];
pmem[2] = ((uint8_t *)&val)[1];
pmem[3] = ((uint8_t *)&val)[0];
}
/*
**************************************************************************************************************
* READ BE 16U
*
* Description: This function is used to read an unsigned short integer from a charecter buffer in the platform
* containing big endian processor
*
* Arguments : pmem Pointer to the charecter buffer
*
* Returns : val Unsigned short integer
*
**************************************************************************************************************
*/
uint16_t ReadBE16U (volatile uint8_t *pmem)
{
uint16_t val;
((uint8_t *)&val)[0] = pmem[1];
((uint8_t *)&val)[1] = pmem[0];
return (val);
}
/*
**************************************************************************************************************
* WRITE BE 16U
*
* Description: This function is used to write an unsigned short integer into the charecter buffer in the
* platform containing big endian processor
*
* Arguments : pmem Pointer to the charecter buffer
* val Value to be placed in the charecter buffer
*
* Returns : None
*
**************************************************************************************************************
*/
void WriteBE16U (volatile uint8_t *pmem,
uint16_t val)
{
pmem[0] = ((uint8_t *)&val)[1];
pmem[1] = ((uint8_t *)&val)[0];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -