rename 'struct dfu' to 'struct dfudata' and 'dfu' symbol to 'g_dfu'
This avoids clashes with the -Ddfu caused by board MEMORIES
This commit is contained in:
parent
f912bc40dc
commit
49600087b9
|
@ -112,14 +112,14 @@ const USBDDriverDescriptors dfu_descriptors;
|
||||||
|
|
||||||
/* The API between the core DFU handler and the board/soc specific code */
|
/* The API between the core DFU handler and the board/soc specific code */
|
||||||
|
|
||||||
struct dfu {
|
struct dfudata {
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
uint32_t state;
|
uint32_t state;
|
||||||
int past_manifest;
|
int past_manifest;
|
||||||
unsigned int total_bytes;
|
unsigned int total_bytes;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct dfu dfu;
|
extern struct dfudata g_dfu;
|
||||||
void set_usb_serial_str(const uint8_t *serial_usbstr);
|
void set_usb_serial_str(const uint8_t *serial_usbstr);
|
||||||
|
|
||||||
/* call-backs by the board/SOC */
|
/* call-backs by the board/SOC */
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
static USBDDriver usbdDriver;
|
static USBDDriver usbdDriver;
|
||||||
static unsigned char if_altsettings[1];
|
static unsigned char if_altsettings[1];
|
||||||
|
|
||||||
__dfudata struct dfu dfu = {
|
__dfudata struct dfudata g_dfu = {
|
||||||
.state = DFU_STATE_appIDLE,
|
.state = DFU_STATE_appIDLE,
|
||||||
.past_manifest = 0,
|
.past_manifest = 0,
|
||||||
.total_bytes = 0,
|
.total_bytes = 0,
|
||||||
|
@ -53,8 +53,8 @@ static __dfufunc void handle_getstatus(void)
|
||||||
dfu_drv_updstatus();
|
dfu_drv_updstatus();
|
||||||
|
|
||||||
/* send status response */
|
/* send status response */
|
||||||
dstat.bStatus = dfu.status;
|
dstat.bStatus = g_dfu.status;
|
||||||
dstat.bState = dfu.state;
|
dstat.bState = g_dfu.state;
|
||||||
dstat.iString = 0;
|
dstat.iString = 0;
|
||||||
/* FIXME: set dstat.bwPollTimeout */
|
/* FIXME: set dstat.bwPollTimeout */
|
||||||
|
|
||||||
|
@ -65,9 +65,9 @@ static __dfufunc void handle_getstatus(void)
|
||||||
|
|
||||||
static void __dfufunc handle_getstate(void)
|
static void __dfufunc handle_getstate(void)
|
||||||
{
|
{
|
||||||
uint8_t u8 = dfu.state;
|
uint8_t u8 = g_dfu.state;
|
||||||
|
|
||||||
TRACE_DEBUG("handle_getstate(%u)\n\r", dfu.state);
|
TRACE_DEBUG("handle_getstate(%u)\n\r", g_dfu.state);
|
||||||
|
|
||||||
USBD_Write(0, (char *)&u8, sizeof(u8), NULL, 0);
|
USBD_Write(0, (char *)&u8, sizeof(u8), NULL, 0);
|
||||||
}
|
}
|
||||||
|
@ -100,15 +100,15 @@ static void dnload_cb(void *arg, unsigned char status, unsigned int transferred,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = USBDFU_handle_dnload(if_altsettings[0], dfu.total_bytes, dfu_buf, transferred);
|
rc = USBDFU_handle_dnload(if_altsettings[0], g_dfu.total_bytes, dfu_buf, transferred);
|
||||||
switch (rc) {
|
switch (rc) {
|
||||||
case DFU_RET_ZLP:
|
case DFU_RET_ZLP:
|
||||||
dfu.total_bytes += transferred;
|
g_dfu.total_bytes += transferred;
|
||||||
dfu.state = DFU_STATE_dfuDNLOAD_IDLE;
|
g_dfu.state = DFU_STATE_dfuDNLOAD_IDLE;
|
||||||
TerminateCtrlInWithNull(0,0,0,0);
|
TerminateCtrlInWithNull(0,0,0,0);
|
||||||
break;
|
break;
|
||||||
case DFU_RET_STALL:
|
case DFU_RET_STALL:
|
||||||
dfu.state = DFU_STATE_dfuERROR;
|
g_dfu.state = DFU_STATE_dfuERROR;
|
||||||
USBD_Stall(0);
|
USBD_Stall(0);
|
||||||
break;
|
break;
|
||||||
case DFU_RET_NOTHING:
|
case DFU_RET_NOTHING:
|
||||||
|
@ -123,24 +123,24 @@ static int handle_dnload(uint16_t val, uint16_t len, int first)
|
||||||
|
|
||||||
if (len > BOARD_DFU_PAGE_SIZE) {
|
if (len > BOARD_DFU_PAGE_SIZE) {
|
||||||
TRACE_ERROR("DFU length exceeds flash page size\n\r");
|
TRACE_ERROR("DFU length exceeds flash page size\n\r");
|
||||||
dfu.state = DFU_STATE_dfuERROR;
|
g_dfu.state = DFU_STATE_dfuERROR;
|
||||||
dfu.status = DFU_STATUS_errADDRESS;
|
g_dfu.status = DFU_STATUS_errADDRESS;
|
||||||
return DFU_RET_STALL;
|
return DFU_RET_STALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len & 0x03) {
|
if (len & 0x03) {
|
||||||
TRACE_ERROR("DFU length not four-byte-aligned\n\r");
|
TRACE_ERROR("DFU length not four-byte-aligned\n\r");
|
||||||
dfu.state = DFU_STATE_dfuERROR;
|
g_dfu.state = DFU_STATE_dfuERROR;
|
||||||
dfu.status = DFU_STATUS_errADDRESS;
|
g_dfu.status = DFU_STATUS_errADDRESS;
|
||||||
return DFU_RET_STALL;
|
return DFU_RET_STALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (first)
|
if (first)
|
||||||
dfu.total_bytes = 0;
|
g_dfu.total_bytes = 0;
|
||||||
|
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
TRACE_DEBUG("zero-size write -> MANIFEST_SYNC\n\r");
|
TRACE_DEBUG("zero-size write -> MANIFEST_SYNC\n\r");
|
||||||
dfu.state = DFU_STATE_dfuMANIFEST_SYNC;
|
g_dfu.state = DFU_STATE_dfuMANIFEST_SYNC;
|
||||||
return DFU_RET_ZLP;
|
return DFU_RET_ZLP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ static void upload_cb(void *arg, unsigned char status, unsigned int transferred,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dfu.total_bytes += transferred;
|
g_dfu.total_bytes += transferred;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handle_upload(uint16_t val, uint16_t len, int first)
|
static int handle_upload(uint16_t val, uint16_t len, int first)
|
||||||
|
@ -174,16 +174,16 @@ static int handle_upload(uint16_t val, uint16_t len, int first)
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (first)
|
if (first)
|
||||||
dfu.total_bytes = 0;
|
g_dfu.total_bytes = 0;
|
||||||
|
|
||||||
if (len > BOARD_DFU_PAGE_SIZE) {
|
if (len > BOARD_DFU_PAGE_SIZE) {
|
||||||
TRACE_ERROR("DFU length exceeds flash page size\n\r");
|
TRACE_ERROR("DFU length exceeds flash page size\n\r");
|
||||||
dfu.state = DFU_STATE_dfuERROR;
|
g_dfu.state = DFU_STATE_dfuERROR;
|
||||||
dfu.status = DFU_STATUS_errADDRESS;
|
g_dfu.status = DFU_STATUS_errADDRESS;
|
||||||
return DFU_RET_STALL;
|
return DFU_RET_STALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = USBDFU_handle_upload(if_altsettings[0], dfu.total_bytes, dfu_buf, len);
|
rc = USBDFU_handle_upload(if_altsettings[0], g_dfu.total_bytes, dfu_buf, len);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
TRACE_ERROR("application handle_upload() returned %d\n\r", rc);
|
TRACE_ERROR("application handle_upload() returned %d\n\r", rc);
|
||||||
return DFU_RET_STALL;
|
return DFU_RET_STALL;
|
||||||
|
@ -235,7 +235,7 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
|
||||||
USBDDriver_RequestHandler(&usbdDriver, request);
|
USBDDriver_RequestHandler(&usbdDriver, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (dfu.state) {
|
switch (g_dfu.state) {
|
||||||
case DFU_STATE_appIDLE:
|
case DFU_STATE_appIDLE:
|
||||||
switch (req) {
|
switch (req) {
|
||||||
case USB_REQ_DFU_GETSTATUS:
|
case USB_REQ_DFU_GETSTATUS:
|
||||||
|
@ -246,7 +246,7 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
|
||||||
break;
|
break;
|
||||||
case USB_REQ_DFU_DETACH:
|
case USB_REQ_DFU_DETACH:
|
||||||
TRACE_DEBUG("\r\n====dfu_detach\n\r");
|
TRACE_DEBUG("\r\n====dfu_detach\n\r");
|
||||||
dfu.state = DFU_STATE_appDETACH;
|
g_dfu.state = DFU_STATE_appDETACH;
|
||||||
ret = DFU_RET_ZLP;
|
ret = DFU_RET_ZLP;
|
||||||
goto out;
|
goto out;
|
||||||
break;
|
break;
|
||||||
|
@ -263,7 +263,7 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
|
||||||
handle_getstate();
|
handle_getstate();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dfu.state = DFU_STATE_appIDLE;
|
g_dfu.state = DFU_STATE_appIDLE;
|
||||||
ret = DFU_RET_STALL;
|
ret = DFU_RET_STALL;
|
||||||
goto out;
|
goto out;
|
||||||
break;
|
break;
|
||||||
|
@ -274,15 +274,15 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
|
||||||
switch (req) {
|
switch (req) {
|
||||||
case USB_REQ_DFU_DNLOAD:
|
case USB_REQ_DFU_DNLOAD:
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
dfu.state = DFU_STATE_dfuERROR;
|
g_dfu.state = DFU_STATE_dfuERROR;
|
||||||
ret = DFU_RET_STALL;
|
ret = DFU_RET_STALL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
dfu.state = DFU_STATE_dfuDNLOAD_SYNC;
|
g_dfu.state = DFU_STATE_dfuDNLOAD_SYNC;
|
||||||
ret = handle_dnload(val, len, 1);
|
ret = handle_dnload(val, len, 1);
|
||||||
break;
|
break;
|
||||||
case USB_REQ_DFU_UPLOAD:
|
case USB_REQ_DFU_UPLOAD:
|
||||||
dfu.state = DFU_STATE_dfuUPLOAD_IDLE;
|
g_dfu.state = DFU_STATE_dfuUPLOAD_IDLE;
|
||||||
handle_upload(val, len, 1);
|
handle_upload(val, len, 1);
|
||||||
break;
|
break;
|
||||||
case USB_REQ_DFU_ABORT:
|
case USB_REQ_DFU_ABORT:
|
||||||
|
@ -296,7 +296,7 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
|
||||||
handle_getstate();
|
handle_getstate();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dfu.state = DFU_STATE_dfuERROR;
|
g_dfu.state = DFU_STATE_dfuERROR;
|
||||||
ret = DFU_RET_STALL;
|
ret = DFU_RET_STALL;
|
||||||
goto out;
|
goto out;
|
||||||
break;
|
break;
|
||||||
|
@ -312,7 +312,7 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
|
||||||
handle_getstate();
|
handle_getstate();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dfu.state = DFU_STATE_dfuERROR;
|
g_dfu.state = DFU_STATE_dfuERROR;
|
||||||
ret = DFU_RET_STALL;
|
ret = DFU_RET_STALL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -325,7 +325,7 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
|
||||||
handle_getstatus();
|
handle_getstatus();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dfu.state = DFU_STATE_dfuERROR;
|
g_dfu.state = DFU_STATE_dfuERROR;
|
||||||
ret = DFU_RET_STALL;
|
ret = DFU_RET_STALL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -333,11 +333,11 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
|
||||||
case DFU_STATE_dfuDNLOAD_IDLE:
|
case DFU_STATE_dfuDNLOAD_IDLE:
|
||||||
switch (req) {
|
switch (req) {
|
||||||
case USB_REQ_DFU_DNLOAD:
|
case USB_REQ_DFU_DNLOAD:
|
||||||
dfu.state = DFU_STATE_dfuDNLOAD_SYNC;
|
g_dfu.state = DFU_STATE_dfuDNLOAD_SYNC;
|
||||||
ret = handle_dnload(val, len, 0);
|
ret = handle_dnload(val, len, 0);
|
||||||
break;
|
break;
|
||||||
case USB_REQ_DFU_ABORT:
|
case USB_REQ_DFU_ABORT:
|
||||||
dfu.state = DFU_STATE_dfuIDLE;
|
g_dfu.state = DFU_STATE_dfuIDLE;
|
||||||
ret = DFU_RET_ZLP;
|
ret = DFU_RET_ZLP;
|
||||||
break;
|
break;
|
||||||
case USB_REQ_DFU_GETSTATUS:
|
case USB_REQ_DFU_GETSTATUS:
|
||||||
|
@ -347,7 +347,7 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
|
||||||
handle_getstate();
|
handle_getstate();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dfu.state = DFU_STATE_dfuERROR;
|
g_dfu.state = DFU_STATE_dfuERROR;
|
||||||
ret = DFU_RET_STALL;
|
ret = DFU_RET_STALL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -361,7 +361,7 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
|
||||||
handle_getstate();
|
handle_getstate();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dfu.state = DFU_STATE_dfuERROR;
|
g_dfu.state = DFU_STATE_dfuERROR;
|
||||||
ret = DFU_RET_STALL;
|
ret = DFU_RET_STALL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -376,16 +376,16 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
|
||||||
* that we've already been through MANIFST in
|
* that we've already been through MANIFST in
|
||||||
* the global variable 'past_manifest'.
|
* the global variable 'past_manifest'.
|
||||||
*/
|
*/
|
||||||
//dfu.state = DFU_STATE_dfuMANIFEST_WAIT_RST;
|
//g_dfu.state = DFU_STATE_dfuMANIFEST_WAIT_RST;
|
||||||
dfu.state = DFU_STATE_dfuIDLE;
|
g_dfu.state = DFU_STATE_dfuIDLE;
|
||||||
dfu.past_manifest = 1;
|
g_dfu.past_manifest = 1;
|
||||||
handle_getstatus();
|
handle_getstatus();
|
||||||
break;
|
break;
|
||||||
case USB_REQ_DFU_GETSTATE:
|
case USB_REQ_DFU_GETSTATE:
|
||||||
handle_getstate();
|
handle_getstate();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dfu.state = DFU_STATE_dfuERROR;
|
g_dfu.state = DFU_STATE_dfuERROR;
|
||||||
ret = DFU_RET_STALL;
|
ret = DFU_RET_STALL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -399,10 +399,10 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
|
||||||
/* state transition if less data then requested */
|
/* state transition if less data then requested */
|
||||||
rc = handle_upload(val, len, 0);
|
rc = handle_upload(val, len, 0);
|
||||||
if (rc >= 0 && rc < len)
|
if (rc >= 0 && rc < len)
|
||||||
dfu.state = DFU_STATE_dfuIDLE;
|
g_dfu.state = DFU_STATE_dfuIDLE;
|
||||||
break;
|
break;
|
||||||
case USB_REQ_DFU_ABORT:
|
case USB_REQ_DFU_ABORT:
|
||||||
dfu.state = DFU_STATE_dfuIDLE;
|
g_dfu.state = DFU_STATE_dfuIDLE;
|
||||||
/* no zlp? */
|
/* no zlp? */
|
||||||
ret = DFU_RET_ZLP;
|
ret = DFU_RET_ZLP;
|
||||||
break;
|
break;
|
||||||
|
@ -413,7 +413,7 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
|
||||||
handle_getstate();
|
handle_getstate();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dfu.state = DFU_STATE_dfuERROR;
|
g_dfu.state = DFU_STATE_dfuERROR;
|
||||||
ret = DFU_RET_STALL;
|
ret = DFU_RET_STALL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -427,13 +427,13 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
|
||||||
handle_getstate();
|
handle_getstate();
|
||||||
break;
|
break;
|
||||||
case USB_REQ_DFU_CLRSTATUS:
|
case USB_REQ_DFU_CLRSTATUS:
|
||||||
dfu.state = DFU_STATE_dfuIDLE;
|
g_dfu.state = DFU_STATE_dfuIDLE;
|
||||||
dfu.status = DFU_STATUS_OK;
|
g_dfu.status = DFU_STATUS_OK;
|
||||||
/* no zlp? */
|
/* no zlp? */
|
||||||
ret = DFU_RET_ZLP;
|
ret = DFU_RET_ZLP;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dfu.state = DFU_STATE_dfuERROR;
|
g_dfu.state = DFU_STATE_dfuERROR;
|
||||||
ret = DFU_RET_STALL;
|
ret = DFU_RET_STALL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -456,7 +456,7 @@ out:
|
||||||
void USBDFU_Initialize(const USBDDriverDescriptors *pDescriptors)
|
void USBDFU_Initialize(const USBDDriverDescriptors *pDescriptors)
|
||||||
{
|
{
|
||||||
/* We already start in DFU idle mode */
|
/* We already start in DFU idle mode */
|
||||||
dfu.state = DFU_STATE_dfuIDLE;
|
g_dfu.state = DFU_STATE_dfuIDLE;
|
||||||
|
|
||||||
USBDDriver_Initialize(&usbdDriver, pDescriptors, if_altsettings);
|
USBDDriver_Initialize(&usbdDriver, pDescriptors, if_altsettings);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue