summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usb/device/dfu/dfu.h4
-rw-r--r--usb/device/dfu/dfu_driver.c88
2 files changed, 46 insertions, 46 deletions
diff --git a/usb/device/dfu/dfu.h b/usb/device/dfu/dfu.h
index 3cbcac5..ad64c99 100644
--- a/usb/device/dfu/dfu.h
+++ b/usb/device/dfu/dfu.h
@@ -112,14 +112,14 @@ const USBDDriverDescriptors dfu_descriptors;
/* The API between the core DFU handler and the board/soc specific code */
-struct dfu {
+struct dfudata {
uint8_t status;
uint32_t state;
int past_manifest;
unsigned int total_bytes;
};
-extern struct dfu dfu;
+extern struct dfudata g_dfu;
void set_usb_serial_str(const uint8_t *serial_usbstr);
/* call-backs by the board/SOC */
diff --git a/usb/device/dfu/dfu_driver.c b/usb/device/dfu/dfu_driver.c
index f97073d..832ccbb 100644
--- a/usb/device/dfu/dfu_driver.c
+++ b/usb/device/dfu/dfu_driver.c
@@ -39,7 +39,7 @@
static USBDDriver usbdDriver;
static unsigned char if_altsettings[1];
-__dfudata struct dfu dfu = {
+__dfudata struct dfudata g_dfu = {
.state = DFU_STATE_appIDLE,
.past_manifest = 0,
.total_bytes = 0,
@@ -53,8 +53,8 @@ static __dfufunc void handle_getstatus(void)
dfu_drv_updstatus();
/* send status response */
- dstat.bStatus = dfu.status;
- dstat.bState = dfu.state;
+ dstat.bStatus = g_dfu.status;
+ dstat.bState = g_dfu.state;
dstat.iString = 0;
/* FIXME: set dstat.bwPollTimeout */
@@ -65,9 +65,9 @@ static __dfufunc void handle_getstatus(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);
}
@@ -100,15 +100,15 @@ static void dnload_cb(void *arg, unsigned char status, unsigned int transferred,
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) {
case DFU_RET_ZLP:
- dfu.total_bytes += transferred;
- dfu.state = DFU_STATE_dfuDNLOAD_IDLE;
+ g_dfu.total_bytes += transferred;
+ g_dfu.state = DFU_STATE_dfuDNLOAD_IDLE;
TerminateCtrlInWithNull(0,0,0,0);
break;
case DFU_RET_STALL:
- dfu.state = DFU_STATE_dfuERROR;
+ g_dfu.state = DFU_STATE_dfuERROR;
USBD_Stall(0);
break;
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) {
TRACE_ERROR("DFU length exceeds flash page size\n\r");
- dfu.state = DFU_STATE_dfuERROR;
- dfu.status = DFU_STATUS_errADDRESS;
+ g_dfu.state = DFU_STATE_dfuERROR;
+ g_dfu.status = DFU_STATUS_errADDRESS;
return DFU_RET_STALL;
}
if (len & 0x03) {
TRACE_ERROR("DFU length not four-byte-aligned\n\r");
- dfu.state = DFU_STATE_dfuERROR;
- dfu.status = DFU_STATUS_errADDRESS;
+ g_dfu.state = DFU_STATE_dfuERROR;
+ g_dfu.status = DFU_STATUS_errADDRESS;
return DFU_RET_STALL;
}
if (first)
- dfu.total_bytes = 0;
+ g_dfu.total_bytes = 0;
if (len == 0) {
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;
}
@@ -166,7 +166,7 @@ static void upload_cb(void *arg, unsigned char status, unsigned int transferred,
return;
}
- dfu.total_bytes += transferred;
+ g_dfu.total_bytes += transferred;
}
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;
if (first)
- dfu.total_bytes = 0;
+ g_dfu.total_bytes = 0;
if (len > BOARD_DFU_PAGE_SIZE) {
TRACE_ERROR("DFU length exceeds flash page size\n\r");
- dfu.state = DFU_STATE_dfuERROR;
- dfu.status = DFU_STATUS_errADDRESS;
+ g_dfu.state = DFU_STATE_dfuERROR;
+ g_dfu.status = DFU_STATUS_errADDRESS;
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) {
TRACE_ERROR("application handle_upload() returned %d\n\r", rc);
return DFU_RET_STALL;
@@ -235,7 +235,7 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
USBDDriver_RequestHandler(&usbdDriver, request);
}
- switch (dfu.state) {
+ switch (g_dfu.state) {
case DFU_STATE_appIDLE:
switch (req) {
case USB_REQ_DFU_GETSTATUS:
@@ -246,7 +246,7 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
break;
case USB_REQ_DFU_DETACH:
TRACE_DEBUG("\r\n====dfu_detach\n\r");
- dfu.state = DFU_STATE_appDETACH;
+ g_dfu.state = DFU_STATE_appDETACH;
ret = DFU_RET_ZLP;
goto out;
break;
@@ -263,7 +263,7 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
handle_getstate();
break;
default:
- dfu.state = DFU_STATE_appIDLE;
+ g_dfu.state = DFU_STATE_appIDLE;
ret = DFU_RET_STALL;
goto out;
break;
@@ -274,15 +274,15 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
switch (req) {
case USB_REQ_DFU_DNLOAD:
if (len == 0) {
- dfu.state = DFU_STATE_dfuERROR;
+ g_dfu.state = DFU_STATE_dfuERROR;
ret = DFU_RET_STALL;
goto out;
}
- dfu.state = DFU_STATE_dfuDNLOAD_SYNC;
+ g_dfu.state = DFU_STATE_dfuDNLOAD_SYNC;
ret = handle_dnload(val, len, 1);
break;
case USB_REQ_DFU_UPLOAD:
- dfu.state = DFU_STATE_dfuUPLOAD_IDLE;
+ g_dfu.state = DFU_STATE_dfuUPLOAD_IDLE;
handle_upload(val, len, 1);
break;
case USB_REQ_DFU_ABORT:
@@ -296,7 +296,7 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
handle_getstate();
break;
default:
- dfu.state = DFU_STATE_dfuERROR;
+ g_dfu.state = DFU_STATE_dfuERROR;
ret = DFU_RET_STALL;
goto out;
break;
@@ -312,7 +312,7 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
handle_getstate();
break;
default:
- dfu.state = DFU_STATE_dfuERROR;
+ g_dfu.state = DFU_STATE_dfuERROR;
ret = DFU_RET_STALL;
goto out;
}
@@ -325,7 +325,7 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
handle_getstatus();
break;
default:
- dfu.state = DFU_STATE_dfuERROR;
+ g_dfu.state = DFU_STATE_dfuERROR;
ret = DFU_RET_STALL;
goto out;
}
@@ -333,11 +333,11 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
case DFU_STATE_dfuDNLOAD_IDLE:
switch (req) {
case USB_REQ_DFU_DNLOAD:
- dfu.state = DFU_STATE_dfuDNLOAD_SYNC;
+ g_dfu.state = DFU_STATE_dfuDNLOAD_SYNC;
ret = handle_dnload(val, len, 0);
break;
case USB_REQ_DFU_ABORT:
- dfu.state = DFU_STATE_dfuIDLE;
+ g_dfu.state = DFU_STATE_dfuIDLE;
ret = DFU_RET_ZLP;
break;
case USB_REQ_DFU_GETSTATUS:
@@ -347,7 +347,7 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
handle_getstate();
break;
default:
- dfu.state = DFU_STATE_dfuERROR;
+ g_dfu.state = DFU_STATE_dfuERROR;
ret = DFU_RET_STALL;
break;
}
@@ -361,7 +361,7 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
handle_getstate();
break;
default:
- dfu.state = DFU_STATE_dfuERROR;
+ g_dfu.state = DFU_STATE_dfuERROR;
ret = DFU_RET_STALL;
break;
}
@@ -376,16 +376,16 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
* that we've already been through MANIFST in
* the global variable 'past_manifest'.
*/
- //dfu.state = DFU_STATE_dfuMANIFEST_WAIT_RST;
- dfu.state = DFU_STATE_dfuIDLE;
- dfu.past_manifest = 1;
+ //g_dfu.state = DFU_STATE_dfuMANIFEST_WAIT_RST;
+ g_dfu.state = DFU_STATE_dfuIDLE;
+ g_dfu.past_manifest = 1;
handle_getstatus();
break;
case USB_REQ_DFU_GETSTATE:
handle_getstate();
break;
default:
- dfu.state = DFU_STATE_dfuERROR;
+ g_dfu.state = DFU_STATE_dfuERROR;
ret = DFU_RET_STALL;
break;
}
@@ -399,10 +399,10 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
/* state transition if less data then requested */
rc = handle_upload(val, len, 0);
if (rc >= 0 && rc < len)
- dfu.state = DFU_STATE_dfuIDLE;
+ g_dfu.state = DFU_STATE_dfuIDLE;
break;
case USB_REQ_DFU_ABORT:
- dfu.state = DFU_STATE_dfuIDLE;
+ g_dfu.state = DFU_STATE_dfuIDLE;
/* no zlp? */
ret = DFU_RET_ZLP;
break;
@@ -413,7 +413,7 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
handle_getstate();
break;
default:
- dfu.state = DFU_STATE_dfuERROR;
+ g_dfu.state = DFU_STATE_dfuERROR;
ret = DFU_RET_STALL;
break;
}
@@ -427,13 +427,13 @@ void USBDFU_DFU_RequestHandler(const USBGenericRequest *request)
handle_getstate();
break;
case USB_REQ_DFU_CLRSTATUS:
- dfu.state = DFU_STATE_dfuIDLE;
- dfu.status = DFU_STATUS_OK;
+ g_dfu.state = DFU_STATE_dfuIDLE;
+ g_dfu.status = DFU_STATUS_OK;
/* no zlp? */
ret = DFU_RET_ZLP;
break;
default:
- dfu.state = DFU_STATE_dfuERROR;
+ g_dfu.state = DFU_STATE_dfuERROR;
ret = DFU_RET_STALL;
break;
}
@@ -456,7 +456,7 @@ out:
void USBDFU_Initialize(const USBDDriverDescriptors *pDescriptors)
{
/* We already start in DFU idle mode */
- dfu.state = DFU_STATE_dfuIDLE;
+ g_dfu.state = DFU_STATE_dfuIDLE;
USBDDriver_Initialize(&usbdDriver, pDescriptors, if_altsettings);
personal git repositories of Harald Welte. Your mileage may vary