diff options
| author | hathach <[email protected]> | 2021-07-22 01:00:06 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2021-07-22 01:00:06 +0700 |
| commit | 9542fcdbcda23a08fb4d7901bbb01333b6465bfc (patch) | |
| tree | 31511110dadbc664464b8f4878f12813181bac59 /src/class | |
| parent | 4e817ae6d47e3e0636358179ba0d3570fa47c2b0 (diff) | |
rename CFG_TUD_DFU_TRANSFER_BUFSIZE to CFG_TUD_DFU_XFER_BUFSIZE
Diffstat (limited to 'src/class')
| -rw-r--r-- | src/class/dfu/dfu_device.c | 243 | ||||
| -rw-r--r-- | src/class/dfu/dfu_device.h | 4 |
2 files changed, 7 insertions, 240 deletions
diff --git a/src/class/dfu/dfu_device.c b/src/class/dfu/dfu_device.c index 222795bec..ad87092e0 100644 --- a/src/class/dfu/dfu_device.c +++ b/src/class/dfu/dfu_device.c @@ -52,7 +52,7 @@ typedef struct uint16_t block; uint16_t length; - CFG_TUSB_MEM_ALIGN uint8_t transfer_buf[CFG_TUD_DFU_TRANSFER_BUFSIZE]; + CFG_TUSB_MEM_ALIGN uint8_t transfer_buf[CFG_TUD_DFU_XFER_BUFSIZE]; } dfu_state_ctx_t; // Only a single dfu state is allowed @@ -189,9 +189,9 @@ uint16_t dfu_moded_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, _dfu_ctx.attrs = func_desc->bAttributes; - // CFG_TUD_DFU_TRANSFER_BUFSIZE has to be set to the buffer size used in TUD_DFU_DESCRIPTOR + // CFG_TUD_DFU_XFER_BUFSIZE has to be set to the buffer size used in TUD_DFU_DESCRIPTOR uint16_t const transfer_size = tu_le16toh( tu_unaligned_read16(&func_desc->wTransferSize) ); - TU_ASSERT(transfer_size <= CFG_TUD_DFU_TRANSFER_BUFSIZE, drv_len); + TU_ASSERT(transfer_size <= CFG_TUD_DFU_XFER_BUFSIZE, drv_len); return drv_len; } @@ -281,7 +281,7 @@ bool dfu_moded_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_reque { TU_VERIFY(_dfu_ctx.attrs & DFU_ATTR_CAN_UPLOAD); TU_VERIFY(tud_dfu_upload_cb); - TU_VERIFY(request->wLength <= CFG_TUD_DFU_TRANSFER_BUFSIZE); + TU_VERIFY(request->wLength <= CFG_TUD_DFU_XFER_BUFSIZE); uint16_t const xfer_len = tud_dfu_upload_cb(_dfu_ctx.alt, request->wValue, _dfu_ctx.transfer_buf, request->wLength); @@ -294,7 +294,7 @@ bool dfu_moded_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_reque { TU_VERIFY(_dfu_ctx.attrs & DFU_ATTR_CAN_DOWNLOAD); TU_VERIFY(_dfu_ctx.state == DFU_IDLE || _dfu_ctx.state == DFU_DNLOAD_IDLE); - TU_VERIFY(request->wLength <= CFG_TUD_DFU_TRANSFER_BUFSIZE); + TU_VERIFY(request->wLength <= CFG_TUD_DFU_XFER_BUFSIZE); // set to true for both download and manifest _dfu_ctx.flashing_in_progress = true; @@ -455,237 +455,4 @@ static bool reply_getstatus(uint8_t rhport, tusb_control_request_t const * reque return tud_control_xfer(rhport, request, &resp, sizeof(dfu_status_response_t)); } - -#if 0 - -static void dfu_req_dnload_setup(uint8_t rhport, tusb_control_request_t const * request); -static void dfu_req_dnload_reply(uint8_t rhport, tusb_control_request_t const * request); -static bool dfu_state_machine(uint8_t rhport, tusb_control_request_t const * request); - -static void dfu_req_dnload_setup(uint8_t rhport, tusb_control_request_t const * request) -{ - // TODO: add "zero" copy mode so the buffer we read into can be provided by the user - // if they wish, there still will be the internal control buffer copy to this buffer - // but this mode would provide zero copy from the class driver to the application - - TU_VERIFY( request->wLength <= CFG_TUD_DFU_TRANSFER_BUFSIZE, ); - // setup for data phase - tud_control_xfer(rhport, request, _dfu_ctx.transfer_buf, request->wLength); -} - -static void dfu_req_dnload_reply(uint8_t rhport, tusb_control_request_t const * request) -{ - (void) rhport; - TU_VERIFY( request->wLength <= CFG_TUD_DFU_TRANSFER_BUFSIZE, ); - tud_dfu_download_cb(_dfu_ctx.alt,_dfu_ctx.block, (uint8_t *)_dfu_ctx.transfer_buf, _dfu_ctx.length); - _dfu_ctx.flashing_in_progress = false; -} - -static bool dfu_state_machine(uint8_t rhport, tusb_control_request_t const * request) -{ - TU_LOG2(" DFU Request: %s\r\n", tu_lookup_find(&_dfu_request_table, request->bRequest)); - TU_LOG2(" DFU State Machine: %s\r\n", tu_lookup_find(&_dfu_state_table, _dfu_ctx.state)); - - switch (_dfu_ctx.state) - { - case DFU_IDLE: - { - switch (request->bRequest) - { - case DFU_REQUEST_DNLOAD: - { - if( ((_dfu_ctx.attrs & DFU_ATTR_CAN_DOWNLOAD) != 0) - && (request->wLength > 0) ) - { - _dfu_ctx.state = DFU_DNLOAD_SYNC; - _dfu_ctx.flashing_in_progress = true; - dfu_req_dnload_setup(rhport, request); - } else { - _dfu_ctx.state = DFU_ERROR; - } - } - break; - - case DFU_REQUEST_GETSTATUS: - reply_getstatus(rhport, request); - break; - - default: - _dfu_ctx.state = DFU_ERROR; - return false; // stall on all other requests - break; - } - } - break; - - case DFU_DNLOAD_SYNC: - { - switch (request->bRequest) - { - case DFU_REQUEST_GETSTATUS: - { - if ( _dfu_ctx.flashing_in_progress ) - { - _dfu_ctx.state = DFU_DNBUSY; - reply_getstatus(rhport, request); - dfu_req_dnload_reply(rhport, request); - } else { - _dfu_ctx.state = DFU_DNLOAD_IDLE; - reply_getstatus(rhport, request); - } - } - break; - - default: - _dfu_ctx.state = DFU_ERROR; - return false; // stall on all other requests - break; - } - } - break; - - case DFU_DNBUSY: - { - switch (request->bRequest) - { - default: - _dfu_ctx.state = DFU_ERROR; - return false; // stall on all other requests - break; - } - } - break; - - case DFU_DNLOAD_IDLE: - { - switch (request->bRequest) - { - case DFU_REQUEST_DNLOAD: - { - if( ((_dfu_ctx.attrs & DFU_ATTR_CAN_DOWNLOAD) != 0) - && (request->wLength > 0) ) - { - _dfu_ctx.state = DFU_DNLOAD_SYNC; - _dfu_ctx.flashing_in_progress = true; - dfu_req_dnload_setup(rhport, request); - } else { - if ( tud_dfu_download_complete_cb(_dfu_ctx.alt) ) - { - _dfu_ctx.state = DFU_MANIFEST_SYNC; - tud_control_status(rhport, request); - } else { - _dfu_ctx.state = DFU_ERROR; - return false; // stall - } - } - } - break; - - case DFU_REQUEST_GETSTATUS: - reply_getstatus(rhport, request); - break; - - default: - _dfu_ctx.state = DFU_ERROR; - return false; // stall on all other requests - break; - } - } - break; - - case DFU_MANIFEST_SYNC: - { - switch (request->bRequest) - { - case DFU_REQUEST_GETSTATUS: - { - if ((_dfu_ctx.attrs & DFU_ATTR_MANIFESTATION_TOLERANT) == 0) - { - _dfu_ctx.state = DFU_MANIFEST; - reply_getstatus(rhport, request); - } else - { - if ( tud_dfu_manifest_cb(_dfu_ctx.alt) ) - { - _dfu_ctx.state = DFU_IDLE; - } - reply_getstatus(rhport, request); - } - } - break; - - default: - _dfu_ctx.state = DFU_ERROR; - return false; // stall on all other requests - break; - } - } - break; - - case DFU_MANIFEST: - { - switch (request->bRequest) - { - // stall on all other requests - default: - return false; - break; - } - } - break; - - case DFU_MANIFEST_WAIT_RESET: - { - // technically we should never even get here, but we will handle it just in case - TU_LOG2(" DFU was in DFU_MANIFEST_WAIT_RESET and got unexpected request: %u\r\n", request->bRequest); - switch (request->bRequest) - { - default: - return false; // stall on all other requests - break; - } - } - break; - - case DFU_UPLOAD_IDLE: - { - switch (request->bRequest) - { - case DFU_REQUEST_GETSTATUS: - reply_getstatus(rhport, request); - break; - - default: - return false; // stall on all other requests - break; - } - } - break; - - case DFU_ERROR: - { - switch (request->bRequest) - { - case DFU_REQUEST_GETSTATUS: - reply_getstatus(rhport, request); - break; - - default: - return false; // stall on all other requests - break; - } - } - break; - - default: - _dfu_ctx.state = DFU_ERROR; - TU_LOG2(" DFU ERROR: Unexpected state\r\nStalling control pipe\r\n"); - return false; // Unexpected state, stall and change to error - } - - return true; -} - -#endif - #endif diff --git a/src/class/dfu/dfu_device.h b/src/class/dfu/dfu_device.h index 2d398aada..fecf8596f 100644 --- a/src/class/dfu/dfu_device.h +++ b/src/class/dfu/dfu_device.h @@ -37,8 +37,8 @@ // Class Driver Default Configure & Validation //--------------------------------------------------------------------+ -#if !defined(CFG_TUD_DFU_TRANSFER_BUFSIZE) - #error "CFG_TUD_DFU_TRANSFER_BUFSIZE must be defined, it has to be set to the buffer size used in TUD_DFU_DESCRIPTOR" +#if !defined(CFG_TUD_DFU_XFER_BUFSIZE) + #error "CFG_TUD_DFU_XFER_BUFSIZE must be defined, it has to be set to the buffer size used in TUD_DFU_DESCRIPTOR" #endif //--------------------------------------------------------------------+ |
