summaryrefslogtreecommitdiff
path: root/src/class/msc/msc_device.h
diff options
context:
space:
mode:
authorhathach <[email protected]>2025-07-01 20:13:21 +0700
committerhathach <[email protected]>2025-07-01 20:13:21 +0700
commitd22cbe4cb5b88c869754e91c97eff513ed8b7b33 (patch)
tree2d5312398e83924ffa50af2242d4dd443c104ed1 /src/class/msc/msc_device.h
parent77e142ed76e87ee1f0cda14155b623eeaedc1546 (diff)
refactor async io, add in_isr argument to tud_msc_async_io_done()
use cbw.command[0] for pending IO command
Diffstat (limited to 'src/class/msc/msc_device.h')
-rw-r--r--src/class/msc/msc_device.h70
1 files changed, 24 insertions, 46 deletions
diff --git a/src/class/msc/msc_device.h b/src/class/msc/msc_device.h
index 7162b11e4..2ad31c245 100644
--- a/src/class/msc/msc_device.h
+++ b/src/class/msc/msc_device.h
@@ -49,10 +49,11 @@
#endif
// Return value of callback functions
-// Error
-#define TUD_MSC_RET_ERROR -1
-// Asynchronous IO
-#define TUD_MSC_RET_ASYNC -16
+enum {
+ TUD_MSC_RET_BUSY = 0, // Busy, e.g disk I/O is not ready
+ TUD_MSC_RET_ERROR = -1,
+ TUD_MSC_RET_ASYNC = -2, // Asynchronous IO
+};
TU_VERIFY_STATIC(CFG_TUD_MSC_EP_BUFSIZE < UINT16_MAX, "Size is not correct");
@@ -63,54 +64,31 @@ TU_VERIFY_STATIC(CFG_TUD_MSC_EP_BUFSIZE < UINT16_MAX, "Size is not correct");
// Set SCSI sense response
bool tud_msc_set_sense(uint8_t lun, uint8_t sense_key, uint8_t add_sense_code, uint8_t add_sense_qualifier);
-// Called once asynchronous read/write operation is done
-// bytes_processed has the same meaning of tud_msc_read10_cb() /
-// tud_msc_write10_cb() return value
-void tud_msc_async_io_done(int32_t bytes_processed);
+// Called by Application once asynchronous I/O operation is done
+// bytes_io is number of bytes in I/O op, typically the bufsize in read/write_cb() or
+// TUD_MSC_RET_ERROR (-1) for error. Note TUD_MSC_RET_BUSY (0) will be treated as error as well.
+bool tud_msc_async_io_done(int32_t bytes_io, bool in_isr);
//--------------------------------------------------------------------+
// Application Callbacks (WEAK is optional)
//--------------------------------------------------------------------+
-// Invoked when received SCSI READ10 command
-// - Address = lba * BLOCK_SIZE + offset
-// - offset is only needed if CFG_TUD_MSC_EP_BUFSIZE is smaller than BLOCK_SIZE.
-//
-// - Application fill the buffer (up to bufsize) with address contents and return number of bytes read or status.
-//
-// - ret < bufsize : These bytes are transferred first and callback will be invoked again for remaining data.
-//
-// - ret == 0 : Indicate application is not ready yet e.g disk I/O busy.
-// Callback will be invoked again with the same parameters later on.
-//
-// - ret == TUD_MSC_RET_ERROR (-1)
-// : Indicate application error e.g invalid address. This request will be STALLed
-// and return failed status in command status wrapper phase.
-//
-// - ret == TUD_MSC_RET_ASYNC (-16)
-// : Data reading will be done asynchronously in a background task. Application should return immediately.
-// tud_msc_async_io_done() must be called once reading is done to signal completion.
+/*
+ Invoked when received SCSI READ10/WRITE10 command
+ - Address = lba * BLOCK_SIZE + offset
+ - offset is only needed if CFG_TUD_MSC_EP_BUFSIZE is smaller than BLOCK_SIZE.
+ - Application fill the buffer (up to bufsize) with address contents and return number of bytes read or status.
+ - 0 < ret < bufsize: These bytes are transferred first and callback will be invoked again for remaining data.
+ - ret == TUD_MSC_RET_BUSY
+ Application is buys e.g disk I/O not ready.
+ Callback will be invoked again with the same parameters later on.
+ - ret == TUD_MSC_RET_ERROR
+ error such as invalid address. This request will be STALLed and scsi command will be failed
+ - ret == TUD_MSC_RET_ASYNC
+ Data I/O will be done asynchronously in a background task. Application should return immediately.
+ tud_msc_async_io_done() must be called once IO/ is done to signal completion.
+*/
int32_t tud_msc_read10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize);
-
-// Invoked when received SCSI WRITE10 command
-// - Address = lba * BLOCK_SIZE + offset
-// - offset is only needed if CFG_TUD_MSC_EP_BUFSIZE is smaller than BLOCK_SIZE.
-//
-// - Application writes data from buffer to address contents (up to bufsize) and returns the number of bytes written or status.
-//
-// - ret < bufsize : Callback will be invoked again with remaining data later on.
-//
-// - ret == 0 : Indicate application is not ready yet e.g disk I/O busy.
-// Callback will be invoked again with the same parameters later on.
-//
-// - ret == TUD_MSC_RET_ERROR (-1)
-// : Indicate application error e.g invalid address. This request will be STALLed
-// and return failed status in command status wrapper phase.
-//
-// - ret == TUD_MSC_RET_ASYNC (-16)
-// : Data writing will be done asynchronously in a background task. Application should return immediately.
-// tud_msc_async_io_done() must be called once writing is done to signal completion.
-// TODO change buffer to const uint8_t*
int32_t tud_msc_write10_cb (uint8_t lun, uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize);
// Invoked when received SCSI_CMD_INQUIRY