-
Set_System();
Set_USBClock();
USB_Init();
/* Main loop */
while (1)
{}
-
void USB_Init(void)
{
pInformation = &Device_Info;
pInformation->ControlState = 2;//此时Device_Info尚未负责
pProperty = &Device_Property; //在usbPro.c中定义时赋值
pUser_Standard_Requests = &User_Standard_Requests;
pProperty->Init();
}
-
pProperty->Init();
- void DFU_init(void)
{
DEVICE_INFO *pInfo = &Device_Info;
Get_SerialNum();//把UID赋给相应数组
pInfo->Current_Configuration = 0;
PowerOn();
/* USB interrupts initialization */
_SetISTR(0); /* clear pending interrupts */
wInterrupt_Mask = IMR_MSK;
_SetCNTR(wInterrupt_Mask); /* set interrupts mask */
/* Enable USB interrupts */
USB_Interrupts_Config();//配置中断向量
bDeviceState = UNCONNECTED;
}
-
其他事情都由中断完成
-
重要的宏定义了中断处理的类型
#define IMR_MSK 。。。
- CNTR_CTRM
- if (wIstr & ISTR_CTR & wInterrupt_Mask)
{
CTR_LP();
}
- CNTR_WKUPM
- CNTR_SUSPM
- CNTR_ERRM
- CNTR_SOFM
- CNTR_ESOFM
- CNTR_RESETM
- if (wIstr & ISTR_RESET & wInterrupt_Mask)
{
_SetISTR((uint16_t)CLR_RESET);
Device_Property.Reset();
#ifdef RESET_CALLBACK
RESET_Callback();
#endif
}
- void USB_Istr(void)
-
全局量
- uint8_t EPindex;当前终端号
uint16_t SaveState ;
uint16_t wInterrupt_Mask;
- DEVICE_PROP *pProperty
- DEVICE_INFO *pInformation
-
DEVICE_PROP Device_Property
- DEVICE_PROP Device_Property =
{
DFU_init, //具体函数
DFU_Reset,
DFU_Status_In,
DFU_Status_Out,
DFU_Data_Setup,
DFU_NoData_Setup,
DFU_Get_Interface_Setting,
DFU_GetDeviceDescriptor,
DFU_GetConfigDescriptor,
DFU_GetStringDescriptor,
0, /*DFU_EP0Buffer*/
bMaxPacketSize0 /*Max Packet size*/
};
- USER_STANDARD_REQUESTS *pUser_Standard_Requests
-
DEVICE Device_Table
- DEVICE Device_Table =
{
EP_NUM, //=1
1
};
-
ONE_DESCRIPTOR Device_Descriptor
- ONE_DESCRIPTOR Device_Descriptor =
{
(uint8_t*)DFU_DeviceDescriptor,
DFU_SIZ_DEVICE_DESC
};
-
ONE_DESCRIPTOR Config_Descriptor
- ONE_DESCRIPTOR Config_Descriptor =
{
(uint8_t*)DFU_ConfigDescriptor,
DFU_SIZ_CONFIG_DESC
};
-
USER_STANDARD_REQUESTS User_Standard_Requests
- USER_STANDARD_REQUESTS User_Standard_Requests =
{
DFU_GetConfiguration,
DFU_SetConfiguration,
DFU_GetInterface,
DFU_SetInterface,
DFU_GetStatus,
DFU_ClearFeature,
DFU_SetEndPointFeature,
DFU_SetDeviceFeature,
DFU_SetDeviceAddress
};
-
ONE_DESCRIPTOR DFU_String_Descriptor[6]
-
ONE_DESCRIPTOR DFU_String_Descriptor[6] =
{
{ (uint8_t*)DFU_StringLangId, DFU_SIZ_STRING_LANGID },
{ (uint8_t*)DFU_StringVendor, DFU_SIZ_STRING_VENDOR },
{ (uint8_t*)DFU_StringProduct, DFU_SIZ_STRING_PRODUCT },
{ (uint8_t*)DFU_StringSerial, DFU_SIZ_STRING_SERIAL },
{ (uint8_t*)DFU_StringInterface0, DFU_SIZ_STRING_INTERFACE0 },
{ (uint8_t*)DFU_StringInterface1, DFU_SIZ_STRING_INTERFACE1 }
};
- DEVICE_INFO Device_Info;
该变量没有在定义时赋值,
更像一个状态量
-
数据结构usbcore.h
-
DEVICE_PROP
-
typedef struct _DEVICE_PROP
{
void (*Init)(void); /* Initialize the device */
void (*Reset)(void); /* Reset routine of this device */
void (*Process_Status_IN)(void);
void (*Process_Status_OUT)(void);
RESULT (*Class_Data_Setup)(uint8_t RequestNo);
RESULT (*Class_NoData_Setup)(uint8_t RequestNo);
RESULT (*Class_Get_Interface_Setting)(uint8_t Interface, uint8_t AlternateSetting);
uint8_t* (*GetDeviceDescriptor)(uint16_t Length);
uint8_t* (*GetConfigDescriptor)(uint16_t Length);
uint8_t* (*GetStringDescriptor)(uint16_t Length);
uint8_t* RxEP_buffer;
uint8_t MaxPacketSize;
}DEVICE_PROP;
-
DEVICE_INFO
-
typedef struct _DEVICE_INFO
{
uint8_t USBbmRequestType; /* bmRequestType */
uint8_t USBbRequest; /* bRequest */
uint16_t_uint8_t USBwValues; /* wValue */
uint16_t_uint8_t USBwIndexs; /* wIndex */
uint16_t_uint8_t USBwLengths; /* wLength */
uint8_t ControlState; /* of type CONTROL_STATE */
uint8_t Current_Feature;
uint8_t Current_Configuration; /* Selected configuration */
uint8_t Current_Interface; /* Selected interface of current configuration */
uint8_t Current_AlternateSetting;/* Selected Alternate Setting of current*/
ENDPOINT_INFO Ctrl_Info;
}DEVICE_INFO;
-
ONE_DESCRIPTOR, *PONE_DESCRIPTOR;
- 数组指针;
数组大小;
- typedef struct OneDescriptor
{
uint8_t *Descriptor;
uint16_t Descriptor_Size;
}
-
USER_STANDARD_REQUESTS
- typedef struct _USER_STANDARD_REQUESTS
{
void (*User_GetConfiguration)(void); /* Get Configuration */
void (*User_SetConfiguration)(void); /* Set Configuration */
void (*User_GetInterface)(void); /* Get Interface */
void (*User_SetInterface)(void); /* Set Interface */
void (*User_GetStatus)(void); /* Get Status */
void (*User_ClearFeature)(void); /* Clear Feature */
void (*User_SetEndPointFeature)(void); /* Set Endpoint Feature */
void (*User_SetDeviceFeature)(void); /* Set Device Feature */
void (*User_SetDeviceAddress)(void); /* Set Device Address */
}
USER_STANDARD_REQUESTS;
-
ENDPOINT_INFO
- typedef struct _ENDPOINT_INFO
{
uint16_t Usb_wLength;
uint16_t Usb_wOffset;
uint16_t PacketSize;
uint8_t *(*CopyData)(uint16_t Length);
}ENDPOINT_INFO;