Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions include/unicore-mx/usbd/class/msc.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,17 @@ typedef struct usbd_msc_backend usbd_msc_backend;
* @param lock Lock. Optional - can be NULL
* @param unlock Unlock. Optional - can be NULL
*/
typedef uint32_t msc_lba_t;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look ok to me but,

Tab between "uint32_t" "msc_lba_t;"
(Not nitpicking) but a space is sufficient.
In other part of the code (was a typedef), you use a space instead.
Please read more code of the project and maintain the same pattern/code style.


struct usbd_msc_backend {
const char *vendor_id;
const char *product_id;
const char *product_rev;
uint32_t block_count;
msc_lba_t block_count;
int (*read_block)(const usbd_msc_backend *backend,
uint32_t lba, void *copy_to);
msc_lba_t lba, void *copy_to);
int (*write_block)(const usbd_msc_backend *backend,
uint32_t lba, const void *copy_from);
msc_lba_t lba, const void *copy_from);
int (*format_unit)(const usbd_msc_backend *backend);
int (*lock)(void);
int (*unlock)(void);
Expand All @@ -91,6 +93,12 @@ void usbd_msc_set_config(usbd_msc *ms,

void usbd_msc_start(usbd_msc *ms);

static inline
msc_lba_t usbd_msc_blocks(const usbd_msc_backend *u)
{
return u->block_count;
}

#endif

/**@}*/
6 changes: 4 additions & 2 deletions lib/usbd/class/usbd_msc.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ struct sbc_sense_info {
uint8_t ascq;
};


#define USBD_MSC_SEC_SIZE 512
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea 👍

struct usb_msc_trans {
struct usb_msc_cbw cbw;

Expand All @@ -103,7 +105,7 @@ struct usb_msc_trans {
uint32_t block_count;
uint32_t current_block;

uint8_t msd_buf[512];
uint8_t msd_buf[USBD_MSC_SEC_SIZE];

struct usb_msc_csw csw;
};
Expand Down Expand Up @@ -257,7 +259,7 @@ static void scsi_read_capacity(usbd_msc *ms,
enum trans_event event)
{
if (EVENT_CBW_VALID == event) {
uint32_t last_logical_addr = ms->backend->block_count - 1;
msc_lba_t last_logical_addr = usbd_msc_blocks(ms->backend)-1;
trans->msd_buf[0] = last_logical_addr >> 24;
trans->msd_buf[1] = 0xff & (last_logical_addr >> 16);
trans->msd_buf[2] = 0xff & (last_logical_addr >> 8);
Expand Down