📄 dfu.c
字号:
//*----------------------------------------------------------------------------
//* ATMEL Microcontroller Software Support - ROUSSET -
//*----------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*----------------------------------------------------------------------------
//* File Name : dfu_c
//* Object : USB peripheral validation.
//*
//* 1.0 07/24/01 ODi : Creation
//*----------------------------------------------------------------------------
#include "appli/includes/dfu.h"
/* =================================================================== */
/* DFU mode Descriptor set */
/* =================================================================== */
//extern void BranchAppli();
//#pragma pack(1)
typedef __packed struct {
USBDeviceDesc dfuModeDevDesc;
USBConfigurationDesc dfuModeCfgDesc;
USBInterfaceDesc dfuModeItfDesc;
USBDfuFDesc dfuModeFctDesc;
} USBDfuModeDesc;
//#pragma pack()
/* DFU descriptor sent during the enumeration */
const USBDfuModeDesc USB_DFU_DESC = {
/* ============== DFU Mode Device Descriptor =========== */
{
0x12, // bLength
0x01, // bDescriptorType
0x0100, // bcdUSBL
0xFE, // bDeviceClass
0x01, // bDeviceSubclass
0x00, // bDeviceProtocol
0x08, // bMaxPacketSize0
0x03EB, // idVendorL
0x6120, // idProductL
0x0001, // bcdDeviceL
0x00, // iManufacturer
0x00, // iProduct
0x00, // SerialNumber
0x01 // bNumConfigs
},
/* ============== DFU Mode Configuration Descriptor =========== */
{
/* Configuration 1 descriptor */
0x09, // CbLength
0x02, // CbDescriptorType
0x0019, // CwTotalLength 2 EP + Control
0x01, // CbNumInterfaces
0x01, // CbConfigurationValue
0x00, // CiConfiguration
0xC0, // CbmAttributes 0xA0
0x00 // CMaxPower
},
/* ============== DFU Mode Interface Descriptor =========== */
{
0x09, // bLength
0x04, // bDescriptorType
0x00, // bInterfaceNumber
0x00, // bAlternateSetting
0x00, // bNumEndpoints
0xFE, // bInterfaceClass
0x01, // bInterfaceSubclass
0x00, // bInterfaceProtocol
0x00 // iInterface
},
/* ============== DFU Mode Functional Descriptor =========== */
{
0x07, // bLength
0x21, // bDescriptorType
0x07, // bmAttributes
0x0100, // wDetachTimeOut: Device will wait for 100 ms
(short)0xFFFF // wTransferSize
}
};
USBDfu USB_DFU = { // This instance will be used by usbDfuDispatchRequest()
{ /* Status descriptor */
DFU_OK,
{0,0,0},
DFU_dfuIDLE,
0
},
&(USB_DFU_DESC.dfuModeFctDesc), /* DFU functional descriptor handle */
(void *)0, /* Timer handle */
(void *)0, /* memory handle */
0, /* This function is called at the end of the DFU initialization */
0 /* Manifest complete */
};
const USBDesc USB_DFU_HDL = { // This instance is used by usbDescDispatchRequest()
usbDfuDispatchRequest, /* dispatchClassRequest() */
0, /* dispatchVendorRequest() */
0, /* clearFeature() */
getConfiguration, /* getConfiguration() */
getDescriptor, /* getDescriptor() */
0, /* getInterface() */
getStatus, /* getStatus() */
0, /* setAddress() */
setConfiguration, /* setConfiguration() */
0, /* setDescriptor() */
0, /* setFeature() */
0, /* setInterface() */
0, /* synchFrame() */
(void *) &USB_DFU, /* Private data used by usbDfuDispatchRequest() */
(void *) 0
};
/* ====================================================================== */
/* STANDARD REQUEST DESCRIPTION */
/* ====================================================================== */
char currentCfg;
/* ************************************ */
/* usbGetConfiguration */
/* */
/* Arguments: */
/* pPipe: pointer to default pipe */
/* handler */
/* Return: */
/* Nothing */
/* Description: */
/* This request returns the current */
/* device configuration value */
/* ************************************ */
void getConfiguration(SPipe *pPipe) /* Default Pipe Handler */
{
pPipe->Write(pPipe, ¤tCfg, 1);
}
/* ************************************ */
/* usbGetDescriptor */
/* */
/* Arguments: */
/* pPipe: pointer to default pipe */
/* handler */
/* Return: */
/* Nothing */
/* Description: */
/* This request returns the */
/* specified descriptor if the */
/* descriptor exists */
/* ************************************ */
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
void getDescriptor(
SPipe *pPipe, /* Default Pipe Handler */
char type, /* Descriptor type */
char index, /* Descriptor index */
short langID, /* Language ID */
short length) /* Desriptor length */
{
if (type == USB_DEVICE) {
pPipe->Write(
pPipe,
// (char const *) &(USB_DFU_DESC.dfuModeDevDesc),
(char * const) &(USB_DFU_DESC.dfuModeDevDesc),
MIN(sizeof(USBDeviceDesc), length));
}
else if (type == USB_CONFIGURATION) {
if (index == 0) {
pPipe->Write(
pPipe,
// (char const *) &(USB_DFU_DESC.dfuModeCfgDesc),
(char * const) &(USB_DFU_DESC.dfuModeCfgDesc),
MIN( length, wTotalLength((char const *) &(USB_DFU_DESC.dfuModeCfgDesc))) );
}
else
usbDescRequestError(pPipe);
}
else if (type == USB_STRING)
usbDescRequestError(pPipe);
else
usbDescRequestError(pPipe);
}
/* ************************************ */
/* getStatus */
/* */
/* Arguments: */
/* pPipe: pointer to default pipe */
/* handler */
/* pSetup: pointer to setup datas */
/* Return: */
/* Nothing */
/* Description: */
/* This request returns status for */
/* the specified endpoint */
/* ************************************ */
void getStatus (
SPipe *pPipe, /* Default Pipe Handler */
char recipient, /* device, interface, endpoint */
short index) /* interface or endpoint index */
{
short status = 0;
if (recipient == 0) {
status = 1;
pPipe->Write(pPipe, &status, 2);
}
else if (recipient == 1) {
if (index == 0) {
status = 0;
pPipe->Write(pPipe, &status, 2);
}
else
usbDescRequestError(pPipe);
}
else
usbDescRequestError(pPipe);
}
/* ************************************ */
/* setConfiguration */
/* */
/* Arguments: */
/* pPipe: pointer to default pipe */
/* handler */
/* pSetup: pointer to setup datas */
/* Return: */
/* Nothing */
/* Description: */
/* This request sets the device */
/* configuration */
/* ************************************ */
void setConfiguration(
SPipe *pPipe, /* Default Pipe Handler */
short configurationValue) /* Configuration value */
{
if (configurationValue == 1) {
currentCfg = 1;
at91_usb_set_state(USB_PIPE_REF(pPipe), USB_CONFG);
usbDescSendStatus(pPipe);
}
else {
usbDescRequestError(pPipe);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -