📄 usb.c
字号:
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.DSEN = 1;
//check for status
while(!USB_Int_Flag.BITS.EP0TX)
{
if(USB_Int_Flag.BITS.SUSP ||
Kernel_Flag.BITS.Bus_Reset)
return;
}
USB_Int_Flag.BITS.EP0TX = 0;
D14_Cntrl_Reg.D14_ENDPT_INDEX = 0;
D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.STATUS = 1;
}
}
//***********************************************************************
//* *
//* Routine : *
//* Input : None *
//* Output : None *
//* Function : *
//* *
//***********************************************************************
void Send_Device_Qualifier_Descriptor(void)
{
Descriptor_Ptr = &HS_Device_Qualifier[0]; //set pointer to High Speed device descriptor
D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
if(USB_Device_Request.wLength < 10)
{
D14_Cntrl_Reg.D14_BUFFER_LENGTH_LSB = (UC) USB_Device_Request.wLength;
D14_Cntrl_Reg.D14_BUFFER_LENGTH_MSB = 0;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr; //fill up FIFO
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr; //fill up FIFO
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr; //fill up FIFO
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr; //fill up FIFO
}
else
{
D14_Cntrl_Reg.D14_BUFFER_LENGTH_LSB = 10;
D14_Cntrl_Reg.D14_BUFFER_LENGTH_MSB = 0;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr; //fill up FIFO
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr; //fill up FIFO
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr; //fill up FIFO
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr; //fill up FIFO
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr; //fill up FIFO
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr; //fill up FIFO
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr; //fill up FIFO
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr; //fill up FIFO
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr; //fill up FIFO
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr; //fill up FIFO
}
D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.DSEN = 1;
//check for status stage
while(!USB_Int_Flag.BITS.EP0TX)
{
if(USB_Int_Flag.BITS.SUSP ||
Kernel_Flag.BITS.Bus_Reset)
return;
}
USB_Int_Flag.BITS.EP0TX = 0;
D14_Cntrl_Reg.D14_ENDPT_INDEX = 0;
D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.STATUS = 1;
}
//***********************************************************************
//* *
//* Routine : *
//* Input : None *
//* Output : None *
//* Function : *
//* *
//***********************************************************************
void Send_Other_Speed_Config_Descriptor(void)
{
Descriptor_Ptr = &Other_Speed_Config_Descriptor[0]; //set pointer to configuration descriptor
D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
if(USB_Device_Request.wLength <= 9) //Send only Configuration descriptor
{
D14_Cntrl_Reg.D14_BUFFER_LENGTH_LSB = (UC) USB_Device_Request.wLength;
D14_Cntrl_Reg.D14_BUFFER_LENGTH_MSB = 0;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.DSEN = 1;
//check for status stage
while(!USB_Int_Flag.BITS.EP0TX)
{
if(USB_Int_Flag.BITS.SUSP ||
Kernel_Flag.BITS.Bus_Reset)
return;
}
USB_Int_Flag.BITS.EP0TX = 0;
D14_Cntrl_Reg.D14_ENDPT_INDEX = 0;
D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.STATUS = 1;
}
else //send Configuration,Interface and Endpoint descriptor
{
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
if(Kernel_Flag.BITS.HS_FS_State == FULL_SPEED)
Descriptor_Ptr = &HS_Default_Interface_Descriptor[0]; //set pointer to interface descriptor
if(Kernel_Flag.BITS.HS_FS_State == HIGH_SPEED)
Descriptor_Ptr = &FS_Default_Interface_Descriptor[0]; //set pointer to interface descriptor
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr; //Set to ATAPI interface subclass
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr;
if(Kernel_Flag.BITS.HS_FS_State == FULL_SPEED)
Descriptor_Ptr = &HS_Bulk_In_Descriptor[0]; //set pointer to interface descriptor
if(Kernel_Flag.BITS.HS_FS_State == HIGH_SPEED)
Descriptor_Ptr = &Bulk_In_Descriptor[0]; //set pointer to interface descriptor
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
if(Kernel_Flag.BITS.HS_FS_State == FULL_SPEED)
Descriptor_Ptr = &HS_Bulk_Out_Descriptor[0]; //set pointer to interface descriptor
if(Kernel_Flag.BITS.HS_FS_State == HIGH_SPEED)
Descriptor_Ptr = &Bulk_Out_Descriptor[0]; //set pointer to interface descriptor
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
Descriptor_Ptr++;
D14_Cntrl_Reg.D14_DATA_PORT_MSB = *Descriptor_Ptr;
D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.VENDP = 1; //validate FIFO
D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.DSEN = 1;
//check for status stage
while(!USB_Int_Flag.BITS.EP0TX)
{
if(USB_Int_Flag.BITS.SUSP ||
Kernel_Flag.BITS.Bus_Reset)
return;
}
USB_Int_Flag.BITS.EP0TX = 0;
D14_Cntrl_Reg.D14_ENDPT_INDEX = 0;
D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.STATUS = 1;
}
}
//***********************************************************************
//* *
//* Routine : *
//* Input : None *
//* Output : None *
//* Function : *
//* *
//***********************************************************************
void Set_Device_Address(void)
{
switch(USB_Device.BITS.State)
{
default :
case USB_Default :
if(USB_Device_Request.wValue > 0)
USB_Device.BITS.State = USB_Addressed;
D14_Cntrl_Reg.D14_ADDRESS.BITS.DEVADDR = (USB_Device_Request.wValue >> 8);
D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.STATUS = 1;
break;
case USB_Configured :
case USB_Addressed :
if(USB_Device_Request.wValue == 0)
USB_Device.BITS.State = USB_Default;
D14_Cntrl_Reg.D14_ADDRESS.BITS.DEVADDR = (USB_Device_Request.wValue >> 8);
D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.STATUS = 1;
break;
}
}
//***********************************************************************
//* *
//* Routine : *
//* Input : None *
//* Output : None *
//* Function : *
//* *
//***********************************************************************
void Set_Config_Value(void)
{
switch(USB_Device.BITS.State)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -