1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

sys/usbus/msc: use MTD pointers in XFA for LUN handling

This commit is contained in:
Gunar Schorcht 2023-04-11 18:43:27 +02:00
parent d535277ebb
commit a783a159af
2 changed files with 11 additions and 19 deletions

View File

@ -50,17 +50,6 @@ extern "C" {
*/
#define USBUS_MSC_EP_OUT_REQUIRED_NUMOF 1
/**
* @brief USBUS MSC Number of exported MTD device through USB
*/
#ifndef USBUS_MSC_EXPORTED_NUMOF
#ifdef MTD_NUMOF
#define USBUS_MSC_EXPORTED_NUMOF MTD_NUMOF
#else
#define USBUS_MSC_EXPORTED_NUMOF 0
#endif
#endif /* USBUS_MSC_EXPORTED_NUMOF */
/**
* @brief USBUS MSC internal state machine enum
*/
@ -102,8 +91,7 @@ typedef struct usbus_msc_device {
uint16_t block_nb; /**< Number of block to transfer for READ and
WRITE operations */
uint16_t block_offset; /**< Internal offset for endpoint size chunk transfer */
usbus_msc_lun_t lun_dev[USBUS_MSC_EXPORTED_NUMOF]; /**< Array holding exported logical
unit descriptor */
usbus_msc_lun_t *lun_dev; /**< Array holding exported logical unit descriptor */
} usbus_msc_device_t;
/**

View File

@ -198,7 +198,7 @@ static unsigned _get_lun(usbus_msc_device_t *msc)
/* Count only registered MTD devices as USB LUN, (using usbus_msc_add_lun)
* not every MTD devices available on board */
for (int i = 0; i < USBUS_MSC_EXPORTED_NUMOF; i++) {
for (unsigned i = 0; i < MTD_NUMOF; i++) {
if (msc->lun_dev[i].mtd != NULL) {
count++;
}
@ -217,14 +217,14 @@ int usbus_msc_add_lun(usbus_t *usbus, mtd_dev_t *dev)
}
/* Check if MTD isn't already registered */
for (int i = 0; i < USBUS_MSC_EXPORTED_NUMOF; i++) {
for (unsigned i = 0; i < MTD_NUMOF; i++) {
if (dev == msc->lun_dev[i].mtd) {
return -EBUSY;
}
}
/* Store new MTD device in first slot available
Also re alloc internal buffer if needed */
for (int i = 0; i < USBUS_MSC_EXPORTED_NUMOF; i++) {
for (unsigned i = 0; i < MTD_NUMOF; i++) {
if (msc->lun_dev[i].mtd == NULL) {
int ret = mtd_init(dev);
if (ret != 0) {
@ -283,7 +283,7 @@ int usbus_msc_remove_lun(usbus_t *usbus, mtd_dev_t *dev)
usbus_msc_device_t *msc = _get_msc_handler(usbus);
/* Identify the LUN to unexport */
for (int i = 0; i < USBUS_MSC_EXPORTED_NUMOF; i++) {
for (unsigned i = 0; i < MTD_NUMOF; i++) {
if (dev == msc->lun_dev[i].mtd) {
/* Wait for any pending transaction to end */
@ -329,7 +329,11 @@ static void _init(usbus_t *usbus, usbus_handler_t *handler)
msc->block = 0;
msc->state = WAITING;
for (int i = 0; i < USBUS_MSC_EXPORTED_NUMOF; i++) {
/* allocate the array holding exported logical unit descriptors */
msc->lun_dev = malloc(sizeof(usbus_msc_lun_t) * MTD_NUMOF);
assert(msc->lun_dev);
for (unsigned i = 0; i < MTD_NUMOF; i++) {
msc->lun_dev[i].mtd = NULL;
msc->lun_dev[i].block_size = 0;
msc->lun_dev[i].block_nb = 0;
@ -369,7 +373,7 @@ static void _init(usbus_t *usbus, usbus_handler_t *handler)
/* Auto-configure all MTD devices */
if (CONFIG_USBUS_MSC_AUTO_MTD) {
for (int i = 0; i < USBUS_MSC_EXPORTED_NUMOF; i++) {
for (unsigned i = 0; i < MTD_NUMOF; i++) {
usbus_msc_add_lun(usbus, mtd_default_get_dev(i));
}
}