新增4轮4转-补丁代码
This commit is contained in:
@@ -0,0 +1,382 @@
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* uC/USB-Device
|
||||
* The Embedded USB Device Stack
|
||||
*
|
||||
* Copyright (c) 2021 Semidrive Semiconductor
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*
|
||||
* USB DEVICE OPERATING SYSTEM LAYER
|
||||
* For CMSIS OS2
|
||||
*
|
||||
* Filename : usbd_msc_os.c
|
||||
* Version : V1.00.00
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* INCLUDE FILES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#include "../../usbd_msc.h"
|
||||
#include "../../usbd_msc_os.h"
|
||||
#if (USBD_MSC_CFG_FS_REFRESH_TASK_EN == DEF_ENABLED)
|
||||
#include "../../Storage/uC-FS/V4/usbd_storage.h"
|
||||
#endif
|
||||
#include <cmsis_os2.h>
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* CONFIGURATION ERRORS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#if (USBD_MSC_CFG_FS_REFRESH_TASK_EN == DEF_ENABLED)
|
||||
#error "USBD_MSC_CFG_FS_REFRESH_TASK_EN is not supported yet."
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL DEFINES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL CONSTANTS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL DATA TYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL TABLES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL GLOBAL VARIABLES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
static osSemaphoreId_t USBD_MSC_OS_TASK_SemTbl[USBD_MSC_CFG_MAX_NBR_DEV];
|
||||
|
||||
static osSemaphoreId_t USBD_MSC_OS_EnumSignal;
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL MACRO'S
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#define mscd_os_err(...) ssdk_printf(SSDK_CRIT, __VA_ARGS__)
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL FUNCTION PROTOTYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
static void USBD_MSC_OS_Task (void *p_arg);
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*********************************************************************************************************
|
||||
* GLOBAL FUNCTIONS
|
||||
*********************************************************************************************************
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_MSC_OS_Init()
|
||||
*
|
||||
* Description : Initialize MSC OS interface.
|
||||
*
|
||||
* Argument(s) : p_err Pointer to variable that will receive the return error code from this function :
|
||||
*
|
||||
* USBD_ERR_NONE OS initialization successful.
|
||||
* USBD_ERR_OS_FAIL OS objects NOT successfully initialized.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : None.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_MSC_OS_Init (USBD_ERR *p_err)
|
||||
{
|
||||
CPU_INT08U class_nbr;
|
||||
osThreadId_t thread;
|
||||
osThreadAttr_t attr = {
|
||||
.name = "USBD MSC Tsk",
|
||||
.stack_size = 4096,
|
||||
.priority = osPriorityAboveNormal3,
|
||||
};
|
||||
|
||||
/* Create sem for signal used for MSC comm. */
|
||||
for (class_nbr = 0u; class_nbr < USBD_MSC_CFG_MAX_NBR_DEV; class_nbr++) {
|
||||
USBD_MSC_OS_TASK_SemTbl[class_nbr] = osSemaphoreNew(10000u, 0, NULL);
|
||||
if (!USBD_MSC_OS_TASK_SemTbl[class_nbr]) {
|
||||
*p_err = USBD_ERR_OS_SIGNAL_CREATE;
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* Create sem for signal used for MSC enum. */
|
||||
USBD_MSC_OS_EnumSignal = osSemaphoreNew(10000u, 0, NULL);
|
||||
if (!USBD_MSC_OS_EnumSignal) {
|
||||
*p_err = USBD_ERR_OS_SIGNAL_CREATE;
|
||||
return;
|
||||
}
|
||||
|
||||
thread = osThreadNew(USBD_MSC_OS_Task, NULL, &attr);
|
||||
if (!thread) {
|
||||
*p_err = USBD_ERR_OS_INIT_FAIL;
|
||||
return;
|
||||
}
|
||||
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_MSC_OS_Task()
|
||||
*
|
||||
* Description : OS-dependent shell task to process MSC task
|
||||
*
|
||||
* Argument(s) : p_arg Pointer to task initialization argument (required by CMSIS OS2).
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : None.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
static void USBD_MSC_OS_Task (void *p_arg)
|
||||
{
|
||||
CPU_INT08U class_nbr;
|
||||
|
||||
|
||||
class_nbr = (CPU_INT08U)(CPU_ADDR)p_arg;
|
||||
|
||||
USBD_MSC_TaskHandler(class_nbr);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_MSC_OS_CommSignalPost()
|
||||
*
|
||||
* Description : Post a semaphore used for MSC communication.
|
||||
*
|
||||
* Argument(s) : class_nbr MSC instance class number
|
||||
*
|
||||
* p_err Pointer to variable that will receive the return error code from this function :
|
||||
*
|
||||
* USBD_ERR_NONE OS signal successfully posted.
|
||||
* USBD_ERR_OS_FAIL OS signal NOT successfully posted.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : None.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_MSC_OS_CommSignalPost (CPU_INT08U class_nbr,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
osStatus_t ret;
|
||||
|
||||
ret = osSemaphoreRelease(USBD_MSC_OS_TASK_SemTbl[class_nbr]);
|
||||
if (ret < 0) {
|
||||
mscd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
|
||||
*p_err = USBD_ERR_OS_FAIL;
|
||||
} else {
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_MSC_OS_CommSignalPend()
|
||||
*
|
||||
* Description : Wait on a semaphore to become available for MSC communication.
|
||||
*
|
||||
* Argument(s) : class_nbr MSC instance class number
|
||||
*
|
||||
* timeout Timeout in milliseconds.
|
||||
*
|
||||
* p_err Pointer to variable that will receive the return error code from this function :
|
||||
* USBD_ERR_NONE The call was successful and your task owns the resource
|
||||
* or, the event you are waiting for occurred.
|
||||
* USBD_ERR_OS_TIMEOUT The semaphore was not received within the specified timeout.
|
||||
* USBD_ERR_OS_FAIL otherwise.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : None.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_MSC_OS_CommSignalPend (CPU_INT08U class_nbr,
|
||||
CPU_INT32U timeout,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
osStatus_t ret;
|
||||
uint32_t tmo;
|
||||
|
||||
tmo = timeout ? timeout : osWaitForever;
|
||||
|
||||
ret = osSemaphoreAcquire(USBD_MSC_OS_TASK_SemTbl[class_nbr], tmo);
|
||||
switch (ret) {
|
||||
case osOK:
|
||||
*p_err = USBD_ERR_NONE;
|
||||
break;
|
||||
|
||||
case osErrorTimeout:
|
||||
*p_err = USBD_ERR_OS_TIMEOUT;
|
||||
break;
|
||||
|
||||
default:
|
||||
*p_err = USBD_ERR_OS_FAIL;
|
||||
mscd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_MSC_OS_CommSignalDel()
|
||||
*
|
||||
* Description : Delete a semaphore if no tasks are waiting on it for MSC communication.
|
||||
*
|
||||
* Argument(s) : class_nbr MSC instance class number
|
||||
*
|
||||
* p_err Pointer to variable that will receive the return error code from this function :
|
||||
* USBD_ERR_NONE The call was successful and the semaphore was destroyed
|
||||
* USBD_ERR_OS_FAIL otherwise.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : None.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_MSC_OS_CommSignalDel (CPU_INT08U class_nbr,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
osStatus_t ret;
|
||||
|
||||
ret = osSemaphoreDelete(USBD_MSC_OS_TASK_SemTbl[class_nbr]);
|
||||
if (ret < 0) {
|
||||
*p_err = USBD_ERR_OS_FAIL;
|
||||
mscd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
|
||||
} else {
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_MSC_OS_EnumSignalPost()
|
||||
*
|
||||
* Description : Post a semaphore for MSC enumeration process.
|
||||
*
|
||||
* Argument(s) : p_err Pointer to variable that will receive the return error code from this function :
|
||||
*
|
||||
* USBD_ERR_NONE OS signal successfully posted.
|
||||
* USBD_ERR_OS_FAIL OS signal NOT successfully posted.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : None.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_MSC_OS_EnumSignalPost (USBD_ERR *p_err)
|
||||
{
|
||||
osStatus_t ret;
|
||||
|
||||
ret = osSemaphoreRelease(USBD_MSC_OS_EnumSignal);
|
||||
if (ret < 0) {
|
||||
mscd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
|
||||
*p_err = USBD_ERR_OS_FAIL;
|
||||
} else {
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_MSC_OS_EnumSignalPend()
|
||||
*
|
||||
* Description : Wait on a semaphore to become available for MSC enumeration process.
|
||||
*
|
||||
* Argument(s) : timeout Timeout in milliseconds.
|
||||
*
|
||||
* p_err Pointer to variable that will receive the return error code from this function :
|
||||
* USBD_ERR_NONE The call was successful and your task owns the resource
|
||||
* or, the event you are waiting for occurred.
|
||||
* USBD_ERR_OS_TIMEOUT The semaphore was not received within the specified timeout.
|
||||
* USBD_ERR_OS_FAIL otherwise.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : None.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_MSC_OS_EnumSignalPend (CPU_INT32U timeout,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
osStatus_t ret;
|
||||
uint32_t tmo;
|
||||
|
||||
tmo = timeout ? timeout : osWaitForever;
|
||||
|
||||
ret = osSemaphoreAcquire(USBD_MSC_OS_EnumSignal, tmo);
|
||||
switch (ret) {
|
||||
case osOK:
|
||||
*p_err = USBD_ERR_NONE;
|
||||
break;
|
||||
|
||||
case osErrorTimeout:
|
||||
*p_err = USBD_ERR_OS_TIMEOUT;
|
||||
break;
|
||||
|
||||
default:
|
||||
*p_err = USBD_ERR_OS_FAIL;
|
||||
mscd_os_err("Err %d @%d, %s\n", ret, __LINE__, __func__);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,443 @@
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* uC/USB-Device
|
||||
* The Embedded USB Device Stack
|
||||
*
|
||||
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
|
||||
*
|
||||
* SPDX-License-Identifier: APACHE-2.0
|
||||
*
|
||||
* This software is subject to an open source license and is distributed by
|
||||
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
|
||||
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* NOTICE
|
||||
*
|
||||
* Semidrive modified this file to adapt it for ssdk platform.
|
||||
* The modifications are only intended for use with Semidrive chips.
|
||||
* Copyright of all the modifications belongs to Semidrive Semiconductor.
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*
|
||||
* USB DEVICE MSC CLASS STORAGE DRIVER
|
||||
*
|
||||
* RAMDISK
|
||||
*
|
||||
* Filename : usbd_storage.c
|
||||
* Version : V4.06.01
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* INCLUDE FILES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#define MICRIUM_SOURCE
|
||||
#include "usbd_storage.h"
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL DEFINES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#define USBD_RAMDISK_SIZE (USBD_RAMDISK_CFG_BLK_SIZE * \
|
||||
USBD_RAMDISK_CFG_NBR_BLKS)
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL CONSTANTS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL DATA TYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#if (USBD_RAMDISK_CFG_BASE_ADDR == 0)
|
||||
static CPU_INT08U *USBD_RAMDISK_DataArea[USBD_RAMDISK_CFG_NBR_UNITS];
|
||||
#else
|
||||
static CPU_INT08U *USBD_RAMDISK_DataArea[USBD_RAMDISK_CFG_NBR_UNITS];
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL TABLES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL GLOBAL VARIABLES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL FUNCTION PROTOTYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL CONFIGURATION ERRORS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*********************************************************************************************************
|
||||
* GLOBAL FUNCTIONS
|
||||
*********************************************************************************************************
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_StorageInit()
|
||||
*
|
||||
* Description : Initialize internal tables used by the storage layer.
|
||||
*
|
||||
* Argument(s) : p_err Pointer to variable that will receive error code from this function.
|
||||
*
|
||||
* USBD_ERR_NONE Storage successfully initialized.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : None.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageInit (USBD_ERR *p_err)
|
||||
{
|
||||
LIB_ERR err_lib;
|
||||
|
||||
USBD_RAMDISK_DataArea[0] = (CPU_INT08U *)Mem_HeapAlloc( USBD_RAMDISK_CFG_NBR_UNITS * USBD_RAMDISK_SIZE,
|
||||
USBD_RAMDISK_CFG_BLK_SIZE,
|
||||
(CPU_SIZE_T *)DEF_NULL,
|
||||
&err_lib);
|
||||
if (err_lib != LIB_MEM_ERR_NONE) {
|
||||
*p_err = USBD_ERR_ALLOC;
|
||||
return;
|
||||
}
|
||||
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_StorageAdd()
|
||||
*
|
||||
* Description : Initialize storage medium.
|
||||
*
|
||||
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
|
||||
*
|
||||
* p_err Pointer to variable that will receive error code from this function.
|
||||
*
|
||||
* USBD_ERR_NONE Storage successfully initialized.
|
||||
* USBD_ERR_SCSI_LOG_UNIT_NOTRDY Initiliazing RAM area failed.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : None.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageAdd (USBD_STORAGE_LUN *p_storage_lun,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
CPU_INT32U ix;
|
||||
CPU_INT08U lun_nbr;
|
||||
|
||||
|
||||
lun_nbr = p_storage_lun->LunNbr;
|
||||
/* Fill the RAM area with zeros. */
|
||||
#if (USBD_RAMDISK_CFG_BASE_ADDR != 0)
|
||||
USBD_RAMDISK_DataArea[lun_nbr] = (CPU_INT08U *)USBD_RAMDISK_CFG_BASE_ADDR + lun_nbr * USBD_RAMDISK_SIZE;
|
||||
#endif
|
||||
Mem_Clr((void *)&USBD_RAMDISK_DataArea[lun_nbr][0],
|
||||
USBD_RAMDISK_SIZE);
|
||||
|
||||
for (ix = 0; ix < USBD_RAMDISK_SIZE; ix++) { /* Chk if RAM area is cleared. */
|
||||
if (USBD_RAMDISK_DataArea[lun_nbr][ix] != 0) {
|
||||
*p_err = USBD_ERR_SCSI_LU_NOTRDY;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
p_storage_lun->MediumPresent = DEF_TRUE; /* RAMDisk medium is initially always present. */
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_StorageCapacityGet()
|
||||
*
|
||||
* Description : Get storage medium's capacity.
|
||||
*
|
||||
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
|
||||
*
|
||||
* p_nbr_blks Pointer to variable that will receive the number of logical blocks.
|
||||
*
|
||||
* p_blk_size Pointer to variable that will receive the size of each block, in bytes.
|
||||
*
|
||||
* p_err Pointer to variable that will receive error code from this function.
|
||||
*
|
||||
* USBD_ERR_NONE Medium capacity successfully gotten.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : None.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageCapacityGet (USBD_STORAGE_LUN *p_storage_lun,
|
||||
CPU_INT64U *p_nbr_blks,
|
||||
CPU_INT32U *p_blk_size,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
(void)p_storage_lun;
|
||||
|
||||
*p_nbr_blks = USBD_RAMDISK_CFG_NBR_BLKS;
|
||||
*p_blk_size = USBD_RAMDISK_CFG_BLK_SIZE;
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_StorageRd()
|
||||
*
|
||||
* Description : Read data from the storage medium.
|
||||
*
|
||||
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
|
||||
*
|
||||
* blk_addr Logical Block Address (LBA) of starting read block.
|
||||
*
|
||||
* nbr_blks Number of logical blocks to read.
|
||||
*
|
||||
* p_data_buf Pointer to buffer in which data will be stored.
|
||||
*
|
||||
* p_err Pointer to variable that will receive error code from this function.
|
||||
*
|
||||
* USBD_ERR_NONE Medium successfully read.
|
||||
* USBD_ERR_SCSI_LOG_UNIT_NOTSUPPORTED Logical unit not supported.
|
||||
* USBD_ERR_SCSI_LOG_UNIT_NOTRDY Logical unit cannot perform
|
||||
* operations.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : None.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageRd (USBD_STORAGE_LUN *p_storage_lun,
|
||||
CPU_INT64U blk_addr,
|
||||
CPU_INT32U nbr_blks,
|
||||
CPU_INT08U *p_data_buf,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
CPU_INT08U lun;
|
||||
CPU_INT64U mem_area_size;
|
||||
CPU_INT32U mem_size_copy;
|
||||
|
||||
|
||||
lun = (*p_storage_lun).LunNbr;
|
||||
|
||||
if (lun > USBD_RAMDISK_CFG_NBR_UNITS) {
|
||||
*p_err = USBD_ERR_SCSI_LU_NOTSUPPORTED;
|
||||
return;
|
||||
}
|
||||
|
||||
mem_area_size = ((blk_addr + nbr_blks) * USBD_RAMDISK_CFG_BLK_SIZE);
|
||||
if (mem_area_size > USBD_RAMDISK_SIZE) {
|
||||
*p_err = USBD_ERR_SCSI_LU_NOTRDY;
|
||||
return;
|
||||
}
|
||||
|
||||
mem_size_copy = nbr_blks * USBD_RAMDISK_CFG_BLK_SIZE;
|
||||
Mem_Copy((void *) p_data_buf,
|
||||
(void *)&USBD_RAMDISK_DataArea[lun][blk_addr * USBD_RAMDISK_CFG_BLK_SIZE],
|
||||
mem_size_copy);
|
||||
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_StorageWr()
|
||||
*
|
||||
* Description : Write data to the storage medium.
|
||||
*
|
||||
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
|
||||
*
|
||||
* blk_addr Logical Block Address (LBA) of starting write block.
|
||||
*
|
||||
* nbr_blks Number of logical blocks to write.
|
||||
*
|
||||
* p-data_buf Pointer to buffer in which data is stored.
|
||||
*
|
||||
* p_err Pointer to variable that will receive error code from this function.
|
||||
*
|
||||
* USBD_ERR_NONE Medium successfully written.
|
||||
* USBD_ERR_SCSI_LOG_UNIT_NOTSUPPORTED Logical unit not supported.
|
||||
* USBD_ERR_SCSI_LOG_UNIT_NOTRDY Logical unit cannot perform
|
||||
* operations.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : None.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageWr (USBD_STORAGE_LUN *p_storage_lun,
|
||||
CPU_INT64U blk_addr,
|
||||
CPU_INT32U nbr_blks,
|
||||
CPU_INT08U *p_data_buf,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
CPU_INT08U lun;
|
||||
CPU_INT64U mem_area_size;
|
||||
CPU_INT32U mem_size_copy;
|
||||
|
||||
|
||||
lun = (*p_storage_lun).LunNbr;
|
||||
|
||||
if (lun > USBD_RAMDISK_CFG_NBR_UNITS) {
|
||||
*p_err = USBD_ERR_SCSI_LU_NOTSUPPORTED;
|
||||
return;
|
||||
}
|
||||
|
||||
mem_area_size = ((blk_addr + nbr_blks) * USBD_RAMDISK_CFG_BLK_SIZE);
|
||||
if (mem_area_size > USBD_RAMDISK_SIZE) {
|
||||
*p_err = USBD_ERR_SCSI_LU_NOTRDY;
|
||||
return;
|
||||
}
|
||||
|
||||
mem_size_copy = nbr_blks * USBD_RAMDISK_CFG_BLK_SIZE;
|
||||
Mem_Copy((void *)&USBD_RAMDISK_DataArea[lun][blk_addr * USBD_RAMDISK_CFG_BLK_SIZE],
|
||||
(void *) p_data_buf,
|
||||
mem_size_copy);
|
||||
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_StorageStatusGet()
|
||||
*
|
||||
* Description : Get storage medium's status.
|
||||
*
|
||||
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
|
||||
*
|
||||
* p_err Pointer to variable that will receive error code from this function.
|
||||
*
|
||||
* USBD_ERR_NONE Medium present.
|
||||
* USB_ERR_SCSI_MEDIUM_NOTPRESENT Medium not present.
|
||||
* USBD_ERR_SCSI_LOG_UNIT_NOTSUPPORTED Logical unit not supported.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : None.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageStatusGet (USBD_STORAGE_LUN *p_storage_lun,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
CPU_INT08U lun;
|
||||
|
||||
lun = p_storage_lun->LunNbr;
|
||||
|
||||
if (lun > USBD_RAMDISK_CFG_NBR_UNITS) {
|
||||
*p_err = USBD_ERR_SCSI_LU_NOTSUPPORTED;
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_storage_lun->MediumPresent == DEF_FALSE) {
|
||||
*p_err = USBD_ERR_SCSI_MEDIUM_NOTPRESENT;
|
||||
} else {
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_StorageLock()
|
||||
*
|
||||
* Description : Lock storage medium.
|
||||
*
|
||||
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
|
||||
*
|
||||
* timeout_ms Timeout in milliseconds.
|
||||
*
|
||||
* p_err Pointer to variable that will receive error code from this function.
|
||||
*
|
||||
* USBD_ERR_NONE Medium successfully locked.
|
||||
* USBD_ERR_SCSI_LOCK_TIMEOUT Medium lock timed out.
|
||||
* USBD_ERR_SCSI_LOCK Medium lock failed.
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : None.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageLock (USBD_STORAGE_LUN *p_storage_lun,
|
||||
CPU_INT32U timeout_ms,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
(void)timeout_ms;
|
||||
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_StorageUnlock()
|
||||
*
|
||||
* Description : Unlock storage medium.
|
||||
*
|
||||
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
|
||||
*
|
||||
* p_err Pointer to variable that will receive error code from this function.
|
||||
*
|
||||
* USBD_ERR_NONE Medium successfully unlocked.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : None.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageUnlock (USBD_STORAGE_LUN *p_storage_lun,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* uC/USB-Device
|
||||
* The Embedded USB Device Stack
|
||||
*
|
||||
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
|
||||
*
|
||||
* SPDX-License-Identifier: APACHE-2.0
|
||||
*
|
||||
* This software is subject to an open source license and is distributed by
|
||||
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
|
||||
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*
|
||||
* USB DEVICE MSC CLASS STORAGE DRIVER
|
||||
*
|
||||
* RAMDISK
|
||||
*
|
||||
* Filename : usbd_storage.h
|
||||
* Version : V4.06.01
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* MODULE
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef USBF_STORAGE_H
|
||||
#define USBF_STORAGE_H
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* INCLUDE FILES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#include "../../../../Source/usbd_core.h"
|
||||
#include "../../usbd_scsi.h"
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* EXTERNS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* DEFINES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* DATA TYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* MACRO'S
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* FUNCTION PROTOTYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageInit (USBD_ERR *p_err);
|
||||
|
||||
void USBD_StorageAdd (USBD_STORAGE_LUN *p_storage_lun,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_StorageCapacityGet(USBD_STORAGE_LUN *p_storage_lun,
|
||||
CPU_INT64U *p_nbr_blks,
|
||||
CPU_INT32U *p_blk_size,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_StorageRd (USBD_STORAGE_LUN *p_storage_lun,
|
||||
CPU_INT64U blk_addr,
|
||||
CPU_INT32U nbr_blks,
|
||||
CPU_INT08U *p_data_buf,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_StorageWr (USBD_STORAGE_LUN *p_storage_lun,
|
||||
CPU_INT64U blk_addr,
|
||||
CPU_INT32U nbr_blks,
|
||||
CPU_INT08U *p_data_buf,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_StorageStatusGet (USBD_STORAGE_LUN *p_storage_lun,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_StorageLock (USBD_STORAGE_LUN *p_storage_lun,
|
||||
CPU_INT32U timeout_ms,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_StorageUnlock (USBD_STORAGE_LUN *p_storage_lun,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* CONFIGURATION ERRORS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef USBD_RAMDISK_CFG_BLK_SIZE
|
||||
#error "USBD_RAMDISK_CFG_BLK_SIZE not #defined'd in 'usbd_cfg.h' [MUST be > 0]"
|
||||
#elif (USBD_RAMDISK_CFG_BLK_SIZE < 1u)
|
||||
#error "USBD_RAMDISK_CFG_BLK_SIZE illegally #define'd in 'usbd_cfg.h' [MUST be > 0]"
|
||||
#endif
|
||||
|
||||
#ifndef USBD_RAMDISK_CFG_NBR_BLKS
|
||||
#error "USBD_RAMDISK_CFG_NBR_BLKS not #defined'd in 'usbd_cfg.h' [MUST be > 0]"
|
||||
#elif (USBD_RAMDISK_CFG_NBR_BLKS < 1u)
|
||||
#error "USBD_RAMDISK_CFG_NBR_BLKS illegally #define'd in 'usbd_cfg.h' [MUST be > 0]"
|
||||
#endif
|
||||
|
||||
#ifndef USBD_RAMDISK_CFG_NBR_UNITS
|
||||
#error "USBD_RAMDISK_CFG_NBR_UNITS not #defined'd in 'usbd_cfg.h' [MUST be > 0]"
|
||||
#elif (USBD_RAMDISK_CFG_NBR_UNITS < 1u)
|
||||
#error "USBD_RAMDISK_CFG_NBR_UNITS illegally #define'd in 'usbd_cfg.h' [MUST be > 0]"
|
||||
#endif
|
||||
|
||||
#ifndef USBD_RAMDISK_CFG_BASE_ADDR
|
||||
#error "USBD_RAMDISK_CFG_BASE_ADDR not #defined'd in 'usbd_cfg.h' [MUST be >= 0]"
|
||||
#elif (USBD_RAMDISK_CFG_BASE_ADDR < 0u)
|
||||
#error "USBD_RAMDISK_CFG_BASE_ADDR illegally #define'd in 'usbd_cfg.h' [MUST be >= 0]"
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* MODULE END
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,333 @@
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* uC/USB-Device
|
||||
* The Embedded USB Device Stack
|
||||
*
|
||||
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
|
||||
*
|
||||
* SPDX-License-Identifier: APACHE-2.0
|
||||
*
|
||||
* This software is subject to an open source license and is distributed by
|
||||
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
|
||||
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*
|
||||
* USB DEVICE MSC CLASS STORAGE DRIVER
|
||||
*
|
||||
* TEMPLATE
|
||||
*
|
||||
* Filename : usbd_storage.c
|
||||
* Version : V4.06.01
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* INCLUDE FILES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#define MICRIUM_SOURCE
|
||||
#include "usbd_storage.h"
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL DEFINES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL CONSTANTS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL DATA TYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL TABLES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL GLOBAL VARIABLES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL FUNCTION PROTOTYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL CONFIGURATION ERRORS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*********************************************************************************************************
|
||||
* GLOBAL FUNCTIONS
|
||||
*********************************************************************************************************
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_StorageInit()
|
||||
*
|
||||
* Description : Initialize the storage medium.
|
||||
*
|
||||
* Argument(s) : p_err Pointer to variable that will receive error code from this function.
|
||||
*
|
||||
* USBD_ERR_NONE Storage successfully initialized.
|
||||
* USBD_ERR_SCSI_LOG_UNIT_NOTRDY Initiliazing RAM area failed.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : None.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageInit (USBD_ERR *p_err)
|
||||
{
|
||||
/* $$$$ Insert code to initialize the storage medium. */
|
||||
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_StorageCapacityGet()
|
||||
*
|
||||
* Description : Get the capacity of the storage medium.
|
||||
*
|
||||
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
|
||||
*
|
||||
* p_nbr_blks Pointer to variable that will receive the number of logical blocks.
|
||||
*
|
||||
* p_blk_size Pointer to variable that will receive the size of each block, in bytes.
|
||||
*
|
||||
* p_err Pointer to variable that will receive error code from this function.
|
||||
*
|
||||
* USBD_ERR_NONE Medium capacity successfully gotten.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : None.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageCapacityGet (USBD_STORAGE_LUN *p_storage_lun,
|
||||
CPU_INT64U *p_nbr_blks,
|
||||
CPU_INT32U *p_blk_size,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
/* $$$$ Insert code to return the capacity of the storage medium in terms of number of blocks and default size of a block. */
|
||||
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_StorageRd()
|
||||
*
|
||||
* Description : Read the data from the storage medium.
|
||||
*
|
||||
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
|
||||
*
|
||||
* blk_addr Logical Block Address (LBA) of starting read block.
|
||||
*
|
||||
* nbr_blks Number of logical blocks to read.
|
||||
*
|
||||
* p_data_buf Pointer to buffer in which data will be stored.
|
||||
*
|
||||
* p_err Pointer to variable that will receive error code from this function.
|
||||
*
|
||||
* USBD_ERR_NONE Medium successfully read.
|
||||
* USBD_ERR_SCSI_LOG_UNIT_NOTSUPPORTED Logical unit not supported.
|
||||
* USBD_ERR_SCSI_LOG_UNIT_NOTRDY Logical unit cannot perform
|
||||
* operations.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : None.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageRd (USBD_STORAGE_LUN *p_storage_lun,
|
||||
CPU_INT64U blk_addr,
|
||||
CPU_INT32U nbr_blks,
|
||||
CPU_INT08U *p_data_buf,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
/* $$$$ Insert code to read data from the storage medium. */
|
||||
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_StorageWr()
|
||||
*
|
||||
* Description : Write the data to the storage medium.
|
||||
*
|
||||
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
|
||||
*
|
||||
* blk_addr Logical Block Address (LBA) of starting write block.
|
||||
*
|
||||
* nbr_blks Number of logical blocks to write.
|
||||
*
|
||||
* p-data_buf Pointer to buffer in which data is stored.
|
||||
*
|
||||
* p_err Pointer to variable that will receive error code from this function.
|
||||
*
|
||||
* USBD_ERR_NONE Medium successfully written.
|
||||
* USBD_ERR_SCSI_LOG_UNIT_NOTSUPPORTED Logical unit not supported.
|
||||
* USBD_ERR_SCSI_LOG_UNIT_NOTRDY Logical unit cannot perform
|
||||
* operations.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : None.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageWr (USBD_STORAGE_LUN *p_storage_lun,
|
||||
CPU_INT64U blk_addr,
|
||||
CPU_INT32U nbr_blks,
|
||||
CPU_INT08U *p_data_buf,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
/* $$$$ Insert code to write data to the storage medium. */
|
||||
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_StorageStatusGet()
|
||||
*
|
||||
* Description : Get the status of the storage medium.
|
||||
*
|
||||
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
|
||||
*
|
||||
* p_err Pointer to variable that will receive error code from this function.
|
||||
*
|
||||
* USBD_ERR_NONE Medium present.
|
||||
* USB_ERR_SCSI_MEDIUM_NOTPRESENT Medium not present.
|
||||
* USBD_ERR_SCSI_LOG_UNIT_NOTSUPPORTED Logical unit not supported.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : None.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageStatusGet (USBD_STORAGE_LUN *p_storage_lun,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
/* $$$$ Insert code to determine the presence or absence of the storage medium. */
|
||||
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_StorageLock()
|
||||
*
|
||||
* Description : Lock the storage medium.
|
||||
*
|
||||
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
|
||||
*
|
||||
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
|
||||
*
|
||||
* timeout_ms Timeout in milliseconds.
|
||||
*
|
||||
* p_err Pointer to variable that will receive error code from this function.
|
||||
*
|
||||
* USBD_ERR_NONE Medium successfully locked.
|
||||
* USBD_ERR_SCSI_LOCK_TIMEOUT Medium lock timed out.
|
||||
* USBD_ERR_SCSI_LOCK Medium lock failed.
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : None.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageLock (USBD_STORAGE_LUN *p_storage_lun,
|
||||
CPU_INT32U timeout_ms,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
/* $$$$ Insert code to lock access to the storage medium. This is useful to avoid an embedded file system accessing the same storage medium as the USB host. */
|
||||
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_StorageUnlock()
|
||||
*
|
||||
* Description : Unlock the storage medium.
|
||||
*
|
||||
* Argument(s) : p_storage_lun Pointer to the logical unit storage structure.
|
||||
*
|
||||
* p_err Pointer to variable that will receive error code from this function.
|
||||
*
|
||||
* USBD_ERR_NONE Medium successfully unlocked.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : None.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageUnlock (USBD_STORAGE_LUN *p_storage_lun,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
/* $$$$ Insert code to unlock access to the storage medium. */
|
||||
|
||||
*p_err = USBD_ERR_NONE;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*********************************************************************************************************
|
||||
* LOCAL FUNCTIONS
|
||||
*********************************************************************************************************
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* END
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* uC/USB-Device
|
||||
* The Embedded USB Device Stack
|
||||
*
|
||||
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
|
||||
*
|
||||
* SPDX-License-Identifier: APACHE-2.0
|
||||
*
|
||||
* This software is subject to an open source license and is distributed by
|
||||
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
|
||||
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*
|
||||
* USB DEVICE MSC CLASS STORAGE DRIVER
|
||||
*
|
||||
* TEMPLATE
|
||||
*
|
||||
* Filename : usbf_storage.h
|
||||
* Version : V4.06.01
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* MODULE
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef USBF_STORAGE_H
|
||||
#define USBF_STORAGE_H
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* INCLUDE FILES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#include "../../../../Source/usbd_core.h"
|
||||
#include "../../usbd_scsi.h"
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* EXTERNS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* DEVICE TYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#define USBD_DISK_DIRECT_ACCESS_DEVICE 0x00
|
||||
#define USBD_DISK_SEQUENTIAL_ACCESS_DEVICE 0x01
|
||||
#define USBD_DISK_PRINTER_DEVICE 0x02
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* DIRECT ACCESS MEDIUM TYPE
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#define USBD_DISK_MEMORY_MEDIA 0x00
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* DATA TYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* MACRO'S
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* FUNCTION PROTOTYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageInit (USBD_ERR *p_err);
|
||||
|
||||
void USBD_StorageCapacityGet(USBD_STORAGE_LUN *p_storage_lun,
|
||||
CPU_INT64U *p_nbr_blks,
|
||||
CPU_INT32U *p_blk_size,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_StorageRd (USBD_STORAGE_LUN *p_storage_lun,
|
||||
CPU_INT64U blk_addr,
|
||||
CPU_INT32U nbr_blks,
|
||||
CPU_INT08U *p_data_buf,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_StorageWr (USBD_STORAGE_LUN *p_storage_lun,
|
||||
CPU_INT64U blk_addr,
|
||||
CPU_INT32U nbr_blks,
|
||||
CPU_INT08U *p_data_buf,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_StorageStatusGet (USBD_STORAGE_LUN *p_storage_lun,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_StorageLock (USBD_STORAGE_LUN *p_storage_lun,
|
||||
CPU_INT32U timeout_ms,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_StorageUnlock (USBD_STORAGE_LUN *p_storage_lun,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* CONFIGURATION ERRORS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,571 @@
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* uC/USB-Device
|
||||
* The Embedded USB Device Stack
|
||||
*
|
||||
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
|
||||
*
|
||||
* SPDX-License-Identifier: APACHE-2.0
|
||||
*
|
||||
* This software is subject to an open source license and is distributed by
|
||||
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
|
||||
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*
|
||||
* USB DEVICE MSC CLASS STORAGE DRIVER
|
||||
*
|
||||
* uC/FS V4
|
||||
*
|
||||
* Filename : usbd_storage.c
|
||||
* Version : V4.06.01
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
**********************************************************************************************************
|
||||
* INCLUDE FILES
|
||||
**********************************************************************************************************
|
||||
*/
|
||||
|
||||
#define MICRIUM_SOURCE
|
||||
#include "usbd_storage.h"
|
||||
#include "../../../usbd_msc_os.h"
|
||||
#include <Source/fs.h>
|
||||
#include <Source/fs_dev.h>
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL DEFINES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL CONSTANTS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL DATA TYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL TABLES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL GLOBAL VARIABLES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#if (USBD_MSC_CFG_FS_REFRESH_TASK_EN == DEF_ENABLED)
|
||||
/* Tbl of dev to be polled. */
|
||||
static USBD_STORAGE_LUN *USBD_FS_StorageDevPollList[USBD_MSC_CFG_MAX_LUN];
|
||||
#endif
|
||||
/* Cached luns state. */
|
||||
static CPU_BOOLEAN USBD_FS_LunStatePresent[USBD_MSC_CFG_MAX_LUN];
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL FUNCTION PROTOTYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL CONFIGURATION ERRORS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#if (USBD_MSC_CFG_MICRIUM_FS == DEF_DISABLED)
|
||||
#error "USBD_MSC_CFG_MICRIUM_FS illegally #defined in 'usbd_cfg.h' [MUST be DEF_ENABLED] "
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*********************************************************************************************************
|
||||
* GLOBAL FUNCTIONS
|
||||
*********************************************************************************************************
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_StorageInit()
|
||||
*
|
||||
* Description : Initialize internal tables used by the storage layer.
|
||||
*
|
||||
* Argument(s) : p_err Pointer to variable that will receive error code from this function.
|
||||
*
|
||||
* USBD_ERR_NONE Storage successfully initialized.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : None.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageInit (USBD_ERR *p_err)
|
||||
{
|
||||
CPU_INT08U ix;
|
||||
|
||||
|
||||
for (ix = 0; ix < USBD_MSC_CFG_MAX_LUN; ix++) {
|
||||
#if (USBD_MSC_CFG_FS_REFRESH_TASK_EN == DEF_ENABLED)
|
||||
USBD_FS_StorageDevPollList[ix] = (USBD_STORAGE_LUN *)0u;
|
||||
#endif
|
||||
USBD_FS_LunStatePresent[ix] = DEF_FALSE;
|
||||
}
|
||||
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_StorageAdd()
|
||||
*
|
||||
* Description : Initialize storage medium.
|
||||
*
|
||||
* Argument(s) : p_storage_lun Pointer to logical unit storage structure.
|
||||
*
|
||||
* p_err Pointer to variable that will receive error code from this function.
|
||||
*
|
||||
* USBD_ERR_NONE Storage successfully initialized.
|
||||
* USBD_ERR_SCSI_LU_NOTRDY Querying storage information failed.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : (1) Querying a device returns information such as size, sector size, removable or not.
|
||||
* For fixed media (e.g. RAM, Flash NAND), all the information are always obtained.
|
||||
* For removable media (e.g. SD card), only some information can be obtained if the
|
||||
* media is not present. In this case, even if the device information structure contains
|
||||
* valid information, an error code may be returned and the execution continues normally.
|
||||
* The function USBD_StorageInit() should return immediately only when a fatal error
|
||||
* occurs.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageAdd (USBD_STORAGE_LUN *p_storage_lun,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
FS_ERR err_fs;
|
||||
#if (USBD_MSC_CFG_FS_REFRESH_TASK_EN == DEF_ENABLED)
|
||||
FS_DEV_INFO dev_info;
|
||||
#endif
|
||||
|
||||
|
||||
FSDev_Refresh(p_storage_lun->VolStrPtr, /* Obtain disk status. */
|
||||
&err_fs);
|
||||
if (err_fs == FS_ERR_NONE){ /* Initialize media present status. */
|
||||
p_storage_lun->MediumPresent = DEF_TRUE;
|
||||
USBD_FS_LunStatePresent[p_storage_lun->LunNbr] = DEF_TRUE;
|
||||
} else {
|
||||
p_storage_lun->MediumPresent = DEF_FALSE;
|
||||
USBD_FS_LunStatePresent[p_storage_lun->LunNbr] = DEF_FALSE;
|
||||
}
|
||||
|
||||
#if (USBD_MSC_CFG_FS_REFRESH_TASK_EN == DEF_ENABLED)
|
||||
FSDev_Query(p_storage_lun->VolStrPtr,
|
||||
&dev_info,
|
||||
&err_fs);
|
||||
switch (err_fs) {
|
||||
/* See Note #1. */
|
||||
case FS_ERR_NONE:
|
||||
case FS_ERR_DEV_NOT_PRESENT:
|
||||
case FS_ERR_DEV_IO:
|
||||
break;
|
||||
|
||||
default:
|
||||
*p_err = USBD_ERR_SCSI_LU_NOTRDY;
|
||||
return;
|
||||
}
|
||||
|
||||
if(dev_info.Fixed == DEF_NO) { /* Removable media. */
|
||||
USBD_FS_StorageDevPollList[p_storage_lun->LunNbr] = p_storage_lun;
|
||||
}
|
||||
#endif
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_StorageCapacityGet()
|
||||
*
|
||||
* Description : Get storage medium's capacity.
|
||||
*
|
||||
* Argument(s) : p_storage_lun Pointer to logical unit storage structure.
|
||||
*
|
||||
* p_nbr_blks Pointer to variable that will receive the number of logical blocks.
|
||||
*
|
||||
* p_blk_size Pointer to variable that will receive the size of each block, in bytes.
|
||||
*
|
||||
* p_err Pointer to variable that will receive error code from this function.
|
||||
*
|
||||
* USBD_ERR_NONE Medium capacity successfully gotten.
|
||||
* USBD_ERR_SCSI_MEDIUM_NOTPRESENT Medium not present.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : (1) On error set cached state to not present to prevent positive media presence
|
||||
* returned by USBD_StorageStatusGet() when the host sends a TEST_UNIT_READY SCSI
|
||||
* command.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageCapacityGet (USBD_STORAGE_LUN *p_storage_lun,
|
||||
CPU_INT64U *p_nbr_blks,
|
||||
CPU_INT32U *p_blk_size,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
FS_ERR err_fs;
|
||||
FS_DEV_INFO dev_info;
|
||||
CPU_SR_ALLOC();
|
||||
|
||||
|
||||
FSDev_Query(p_storage_lun->VolStrPtr,
|
||||
&dev_info,
|
||||
&err_fs);
|
||||
if (err_fs != FS_ERR_NONE) {
|
||||
*p_err = USBD_ERR_SCSI_MEDIUM_NOTPRESENT;
|
||||
/* See Note #1. */
|
||||
CPU_CRITICAL_ENTER();
|
||||
USBD_FS_LunStatePresent[p_storage_lun->LunNbr] = DEF_FALSE;
|
||||
CPU_CRITICAL_EXIT();
|
||||
return;
|
||||
}
|
||||
|
||||
*p_nbr_blks = dev_info.Size;
|
||||
*p_blk_size = dev_info.SecSize;
|
||||
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_StorageRd()
|
||||
*
|
||||
* Description : Read data from the storage medium.
|
||||
*
|
||||
* Argument(s) : p_storage_lun Pointer to logical unit storage structure.
|
||||
*
|
||||
* blk_addr Logical Block Address (LBA) of starting read block.
|
||||
*
|
||||
* nbr_blks Number of logical blocks to read.
|
||||
*
|
||||
* p_data_buf Pointer to buffer in which data will be stored.
|
||||
*
|
||||
* p_err Pointer to variable that will receive error code from this function.
|
||||
*
|
||||
* USBD_ERR_NONE Medium successfully read.
|
||||
* USBD_ERR_SCSI_MEDIUM_NOTPRESENT Medium not present.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : (1) On error set cached state to not present to prevent positive media presence
|
||||
* returned by USBD_StorageStatusGet() when the host sends a TEST_UNIT_READY SCSI
|
||||
* command.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageRd (USBD_STORAGE_LUN *p_storage_lun,
|
||||
CPU_INT64U blk_addr,
|
||||
CPU_INT32U nbr_blks,
|
||||
CPU_INT08U *p_data_buf,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
FS_ERR err_fs;
|
||||
CPU_SR_ALLOC();
|
||||
|
||||
|
||||
FSDev_Rd(p_storage_lun->VolStrPtr,
|
||||
p_data_buf,
|
||||
blk_addr,
|
||||
nbr_blks,
|
||||
&err_fs);
|
||||
if (err_fs != FS_ERR_NONE) {
|
||||
*p_err = USBD_ERR_SCSI_MEDIUM_NOTPRESENT;
|
||||
/* See Note #1. */
|
||||
CPU_CRITICAL_ENTER();
|
||||
USBD_FS_LunStatePresent[p_storage_lun->LunNbr] = DEF_FALSE;
|
||||
CPU_CRITICAL_EXIT();
|
||||
} else {
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_StorageWr()
|
||||
*
|
||||
* Description : Write data to the storage medium.
|
||||
*
|
||||
* Argument(s) : p_storage_lun Pointer to logical unit storage structure.
|
||||
*
|
||||
* blk_addr Logical Block Address (LBA) of starting write block.
|
||||
*
|
||||
* nbr_blks Number of logical blocks to write.
|
||||
*
|
||||
* p-data_buf Pointer to buffer in which data is stored.
|
||||
*
|
||||
* p_err Pointer to variable that will receive error code from this function.
|
||||
*
|
||||
* USBD_ERR_NONE Medium successfully written.
|
||||
* USBD_ERR_SCSI_MEDIUM_NOTPRESENT Medium not present.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : (1) On error set cached state to not present to prevent positive media presence
|
||||
* returned by USBD_StorageStatusGet() when the host sends a TEST_UNIT_READY SCSI
|
||||
* command.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageWr (USBD_STORAGE_LUN *p_storage_lun,
|
||||
CPU_INT64U blk_addr,
|
||||
CPU_INT32U nbr_blks,
|
||||
CPU_INT08U *p_data_buf,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
FS_ERR err_fs;
|
||||
CPU_SR_ALLOC();
|
||||
|
||||
|
||||
FSDev_Wr(p_storage_lun->VolStrPtr,
|
||||
p_data_buf,
|
||||
blk_addr,
|
||||
nbr_blks,
|
||||
&err_fs);
|
||||
if (err_fs != FS_ERR_NONE) {
|
||||
*p_err = USBD_ERR_SCSI_MEDIUM_NOTPRESENT;
|
||||
/* See Note #1. */
|
||||
CPU_CRITICAL_ENTER();
|
||||
USBD_FS_LunStatePresent[p_storage_lun->LunNbr] = DEF_FALSE;
|
||||
CPU_CRITICAL_EXIT();
|
||||
} else {
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_StorageStatusGet()
|
||||
*
|
||||
* Description : Get storage medium's status.
|
||||
*
|
||||
* Argument(s) : p_storage_lun Pointer to logical unit storage structure.
|
||||
*
|
||||
* p_err Pointer to variable that will receive error code from this function.
|
||||
*
|
||||
* USBD_ERR_NONE Medium present.
|
||||
* USBD_ERR_SCSI_MEDIUM_NOTPRESENT Medium not present.
|
||||
* USBD_ERR_SCSI_MEDIUM_NOT_RDY_TO_RDY Medium state from not ready to ready.
|
||||
* USBD_ERR_SCSI_MEDIUM_RDY_TO_NOT_RDY Medium state from ready to not ready.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : (1) Sometimes a removable device may fail since device may be removed, powered off or
|
||||
* suddenly unresponsive. The associated device states for the latter are: FS_DEV_STATE_CLOSED,
|
||||
* FS_DEV_STATE_CLOSING and FS_DEV_STATE_STARTING. The device will need to be refreshed
|
||||
* or closed and re-opened.
|
||||
*
|
||||
* (2) If the return error is neither FS_ERR_NONE nor FS_ERR_DEV_INVALID_LOW_FMT, then no
|
||||
* functioning device is present. The device must be refreshed at a later time.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageStatusGet (USBD_STORAGE_LUN *p_storage_lun,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
FS_STATE state;
|
||||
|
||||
|
||||
state = USBD_FS_LunStatePresent[p_storage_lun->LunNbr];
|
||||
|
||||
if (p_storage_lun->MediumPresent == DEF_FALSE) {
|
||||
|
||||
if (state == DEF_TRUE){ /* Media is inserted. */
|
||||
*p_err = USBD_ERR_SCSI_MEDIUM_NOT_RDY_TO_RDY;
|
||||
p_storage_lun->MediumPresent = DEF_TRUE;
|
||||
} else {
|
||||
*p_err = USBD_ERR_SCSI_MEDIUM_NOTPRESENT;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (state == DEF_FALSE){ /* Media is removed. */
|
||||
*p_err = USBD_ERR_SCSI_MEDIUM_RDY_TO_NOT_RDY;
|
||||
p_storage_lun->MediumPresent = DEF_FALSE;
|
||||
} else {
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_StorageLock()
|
||||
*
|
||||
* Description : Lock storage medium.
|
||||
*
|
||||
* Argument(s) : p_storage_lun Pointer to logical unit storage structure.
|
||||
*
|
||||
* timeout_ms Timeout in milliseconds.
|
||||
*
|
||||
* p_err Pointer to variable that will receive error code from this function.
|
||||
*
|
||||
* USBD_ERR_NONE Medium successfully locked.
|
||||
* USBD_ERR_SCSI_LOCK_TIMEOUT Medium lock timed out.
|
||||
* USBD_ERR_SCSI_LOCK Medium lock failed.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : None.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageLock (USBD_STORAGE_LUN *p_storage_lun,
|
||||
CPU_INT32U timeout_ms,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
FS_ERR err_fs;
|
||||
|
||||
|
||||
FSDev_AccessLock(p_storage_lun->VolStrPtr,
|
||||
timeout_ms,
|
||||
&err_fs);
|
||||
switch (err_fs) {
|
||||
case FS_ERR_NONE:
|
||||
*p_err = USBD_ERR_NONE;
|
||||
break;
|
||||
|
||||
case FS_ERR_OS_LOCK_TIMEOUT:
|
||||
*p_err = USBD_ERR_SCSI_LOCK_TIMEOUT;
|
||||
break;
|
||||
|
||||
default:
|
||||
*p_err = USBD_ERR_SCSI_LOCK;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_StorageUnlock()
|
||||
*
|
||||
* Description : Unlock storage medium.
|
||||
*
|
||||
* Argument(s) : p_storage_lun Pointer to logical unit storage structure.
|
||||
*
|
||||
* p_err Pointer to variable that will receive error code from this function.
|
||||
*
|
||||
* USBD_ERR_NONE Medium successfully unlocked.
|
||||
* USBD_ERR_SCSI_UNLOCK Medium unlock failed.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : (1) If an embedded file system application manipulates files on a medium shared with
|
||||
* uC/USB-Device, a lock mechanism is used to ensure an exclusive access to the mediunm.
|
||||
* uC/USB-Device can try to obtain the lock on the medium between each file system
|
||||
* operation. In that case, the file system operations sequence can be interrupted at
|
||||
* any time by uC/USB-Device. When uC/USB-Device releases the lock, files which were
|
||||
* manipulated by uC/FS are invalidated because the computer host may have altered them.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageUnlock (USBD_STORAGE_LUN *p_storage_lun,
|
||||
USBD_ERR *p_err)
|
||||
{
|
||||
FS_ERR err_fs;
|
||||
|
||||
|
||||
FSDev_Invalidate(p_storage_lun->VolStrPtr, &err_fs); /* Invalidate files opened on logical unit (see Note #1)*/
|
||||
if (err_fs != FS_ERR_NONE) {
|
||||
*p_err = USBD_ERR_SCSI_UNLOCK;
|
||||
return;
|
||||
}
|
||||
|
||||
FSDev_AccessUnlock(p_storage_lun->VolStrPtr, &err_fs);
|
||||
if (err_fs != FS_ERR_NONE) {
|
||||
*p_err = USBD_ERR_SCSI_UNLOCK;
|
||||
return;
|
||||
}
|
||||
|
||||
*p_err = USBD_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*********************************************************************************************************
|
||||
* LOCAL FUNCTIONS
|
||||
*********************************************************************************************************
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* USBD_StorageRefreshTaskHandler()
|
||||
*
|
||||
* Description : Device medium status refresh.
|
||||
*
|
||||
* Argument(s) : p_arg Pointer to task initialization argument.
|
||||
*
|
||||
* Return(s) : None.
|
||||
*
|
||||
* Note(s) : (1) This function must be called by the MSC OS layer periodically. The period is
|
||||
* configurable through the constant USBD_MSC_CFG_DEV_POLL_DLY_mS defined in usbd_cfg.h.
|
||||
*
|
||||
* (2) Polling list is used by removable media such as SD card whose insertion and removal
|
||||
* detection do NOT trigger an interrupt for the CPU. Hence, periodically, the presence
|
||||
* state (i.e. present or not) of each logical unit added to the polling list is
|
||||
* verified.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#if (USBD_MSC_CFG_FS_REFRESH_TASK_EN == DEF_ENABLED)
|
||||
void USBD_StorageRefreshTaskHandler (void *p_arg)
|
||||
{
|
||||
FS_ERR err_fs;
|
||||
CPU_INT32U i;
|
||||
|
||||
|
||||
(void)p_arg;
|
||||
/* ------ POLLING LIST PROCESSING (see Note #1) ------- */
|
||||
for (i = 0u; i < USBD_MSC_CFG_MAX_LUN; i++) {
|
||||
|
||||
if (USBD_FS_StorageDevPollList[i] != (USBD_STORAGE_LUN *)0u) {
|
||||
/* Get status of removable media. */
|
||||
FSDev_Refresh(USBD_FS_StorageDevPollList[i]->VolStrPtr, &err_fs);
|
||||
if(err_fs == FS_ERR_NONE) {
|
||||
USBD_FS_LunStatePresent[i] = DEF_TRUE;
|
||||
} else {
|
||||
USBD_FS_LunStatePresent[i] = DEF_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* uC/USB-Device
|
||||
* The Embedded USB Device Stack
|
||||
*
|
||||
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
|
||||
*
|
||||
* SPDX-License-Identifier: APACHE-2.0
|
||||
*
|
||||
* This software is subject to an open source license and is distributed by
|
||||
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
|
||||
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*
|
||||
* USB DEVICE MSC CLASS STORAGE DRIVER
|
||||
*
|
||||
* uC/FS V4
|
||||
*
|
||||
* Filename : usbd_storage.h
|
||||
* Version : V4.06.01
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
**********************************************************************************************************
|
||||
* MODULE
|
||||
**********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* INCLUDE FILES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#include "../../../../../Source/usbd_core.h"
|
||||
#include "../../../usbd_scsi.h"
|
||||
#include <fs_cfg.h>
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* EXTERNS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef STORAGE_MODULE
|
||||
#define STORAGE_EXT
|
||||
#else
|
||||
#define STORAGE_EXT extern
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* DEFINES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* DATA TYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* MACRO'S
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* FUNCTION PROTOTYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_StorageInit (USBD_ERR *p_err);
|
||||
|
||||
void USBD_StorageAdd (USBD_STORAGE_LUN *p_storage_lun,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_StorageCapacityGet (USBD_STORAGE_LUN *p_storage_lun,
|
||||
CPU_INT64U *p_nbr_blks,
|
||||
CPU_INT32U *p_blk_size,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_StorageRd (USBD_STORAGE_LUN *p_storage_lun,
|
||||
CPU_INT64U blk_addr,
|
||||
CPU_INT32U nbr_blks,
|
||||
CPU_INT08U *p_data_buf,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_StorageWr (USBD_STORAGE_LUN *p_storage_lun,
|
||||
CPU_INT64U blk_addr,
|
||||
CPU_INT32U nbr_blks,
|
||||
CPU_INT08U *p_data_buf,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_StorageStatusGet (USBD_STORAGE_LUN *p_storage_lun,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_StorageLock (USBD_STORAGE_LUN *p_storage_lun,
|
||||
CPU_INT32U timeout_ms,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_StorageUnlock (USBD_STORAGE_LUN *p_storage_lun,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
#if (USBD_MSC_CFG_FS_REFRESH_TASK_EN == DEF_ENABLED)
|
||||
void USBD_StorageRefreshTaskHandler(void *p_arg);
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* CONFIGURATION ERRORS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef USBD_MSC_CFG_FS_REFRESH_TASK_EN
|
||||
#error "USBD_MSC_CFG_FS_REFRESH_TASK_EN not #defined'd in 'usbd_cfg.h' [MUST be DEF_ENABLED or DEF_DISABLED]"
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
**********************************************************************************************************
|
||||
* MODULE END
|
||||
**********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
2279
e3_176_ref-补丁/middleware/usb/uC-USBD/Class/MSC/usbd_msc.c
Normal file
2279
e3_176_ref-补丁/middleware/usb/uC-USBD/Class/MSC/usbd_msc.c
Normal file
File diff suppressed because it is too large
Load Diff
177
e3_176_ref-补丁/middleware/usb/uC-USBD/Class/MSC/usbd_msc.h
Normal file
177
e3_176_ref-补丁/middleware/usb/uC-USBD/Class/MSC/usbd_msc.h
Normal file
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* uC/USB-Device
|
||||
* The Embedded USB Device Stack
|
||||
*
|
||||
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
|
||||
*
|
||||
* SPDX-License-Identifier: APACHE-2.0
|
||||
*
|
||||
* This software is subject to an open source license and is distributed by
|
||||
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
|
||||
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*
|
||||
* USB DEVICE MSC CLASS
|
||||
*
|
||||
* Filename : usbd_msc.h
|
||||
* Version : V4.06.01
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* MODULE
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef USBD_MSC_MODULE_PRESENT
|
||||
#define USBD_MSC_MODULE_PRESENT
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* INCLUDE FILES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#include "../../Source/usbd_core.h"
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* EXTERNS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef USBD_MSC_MODULE
|
||||
#define USBD_MSC_EXT
|
||||
#else
|
||||
#define USBD_MSC_EXT extern
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* DEFINES
|
||||
*
|
||||
* Note(s) : (1) The T10 VENDOR IDENTIFICATION field contains 8 bytes of left-aligned ASCII data
|
||||
* identifying the vendor of the product. The T10 vendor identification shall be one
|
||||
* assigned by INCITS.
|
||||
* The PRODUCT IDENTIFICATION field contains 16 bytes of left-aligned ASCII data
|
||||
* defined by the vendor.
|
||||
* See 'SCSI Primary Commands - 3 (SPC-3)', section 6.4.2 for more details about
|
||||
* Standard INQUIRY data format.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/* ---- STANDARD INQUIRY DATA FORMAT (see Note #1) ---- */
|
||||
#define USBD_MSC_DEV_MAX_VEND_ID_LEN 8u
|
||||
#define USBD_MSC_DEV_MAX_PROD_ID_LEN 16u
|
||||
|
||||
|
||||
/*
|
||||
**********************************************************************************************************
|
||||
* DATA TYPES
|
||||
**********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* MACROS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* FUNCTION PROTOTYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
void USBD_MSC_Init ( USBD_ERR *p_err);
|
||||
|
||||
CPU_INT08U USBD_MSC_Add ( USBD_ERR *p_err);
|
||||
|
||||
CPU_BOOLEAN USBD_MSC_CfgAdd ( CPU_INT08U class_nbr,
|
||||
CPU_INT08U dev_nbr,
|
||||
CPU_INT08U cfg_nbr,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_MSC_LunAdd (const CPU_CHAR *p_store_name,
|
||||
CPU_INT08U class_nbr,
|
||||
CPU_CHAR *p_vend_id,
|
||||
CPU_CHAR *p_prod_id,
|
||||
CPU_INT32U prod_rev_level,
|
||||
CPU_BOOLEAN rd_only,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
CPU_BOOLEAN USBD_MSC_IsConn ( CPU_INT08U class_nbr);
|
||||
|
||||
void USBD_MSC_TaskHandler( CPU_INT08U class_nbr);
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* CONFIGURATION ERRORS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef USBD_MSC_CFG_MAX_NBR_DEV
|
||||
#error "USBD_MSC_CFG_MAX_NBR_DEV not #define'd in 'usbd_cfg.h' [MUST be >= 1]"
|
||||
#endif
|
||||
|
||||
#if (USBD_MSC_CFG_MAX_NBR_DEV < 1u)
|
||||
#error "USBD_MSC_CFG_MAX_NBR_DEV illegally #define'd in 'usbd_cfg.h' [MUST be >= 1]"
|
||||
#endif
|
||||
|
||||
#ifndef USBD_MSC_CFG_MAX_NBR_CFG
|
||||
#error "USBD_MSC_CFG_MAX_NBR_CFG not #define'd in 'usbd_cfg.h' [MUST be >= 1]"
|
||||
#endif
|
||||
|
||||
#if (USBD_MSC_CFG_MAX_NBR_CFG < 1u)
|
||||
#error "USBD_MSC_CFG_MAX_NBR_CFG illegally #define'd in 'usbd_cfg.h' [MUST be >= 1]"
|
||||
#endif
|
||||
|
||||
#ifndef USBD_MSC_CFG_MAX_LUN
|
||||
#error "USBD_MSC_CFG_MAX_LUN not #define'd in 'usbd_cfg.h' [MUST be >= 1]"
|
||||
#endif
|
||||
|
||||
#if (USBD_MSC_CFG_MAX_LUN < 1u)
|
||||
#error "USBD_MSC_CFG_MAX_LUN illegally #define'd in 'usbd_cfg.h' [MUST be >= 1]"
|
||||
#endif
|
||||
|
||||
#ifndef USBD_MSC_CFG_DATA_LEN
|
||||
#error "USBD_MSC_CFG_DATA_LEN not #define'd in 'usbd_cfg.h' [MUST be >= 1]"
|
||||
#endif
|
||||
|
||||
#if (USBD_MSC_CFG_DATA_LEN < 1u)
|
||||
#error "USBD_MSC_CFG_DATA_LEN illegally #define'd in 'usbd_cfg.h' [MUST be >= 1]"
|
||||
#endif
|
||||
|
||||
#ifndef USBD_MSC_CFG_MICRIUM_FS
|
||||
#error "USBD_MSC_CFG_MICRIUM_FS not #define'd in 'usbd_cfg.h' [MUST be DEF_ENABLED or DEF_DISABLED]"
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* MODULE END
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#endif
|
||||
117
e3_176_ref-补丁/middleware/usb/uC-USBD/Class/MSC/usbd_msc_os.h
Normal file
117
e3_176_ref-补丁/middleware/usb/uC-USBD/Class/MSC/usbd_msc_os.h
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* uC/USB-Device
|
||||
* The Embedded USB Device Stack
|
||||
*
|
||||
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
|
||||
*
|
||||
* SPDX-License-Identifier: APACHE-2.0
|
||||
*
|
||||
* This software is subject to an open source license and is distributed by
|
||||
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
|
||||
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*
|
||||
* USB MSC CLASS OPERATING SYSTEM LAYER
|
||||
*
|
||||
* Filename : usbd_msc_os.h
|
||||
* Version : V4.06.01
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* MODULE
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef USBD_MSC_OS_MODULE_PRESENT
|
||||
#define USBD_MSC_OS_MODULE_PRESENT
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* INCLUDE FILES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#include "../../Source/usbd_core.h"
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* EXTERNS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* DEFINES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* DATA TYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* MACRO'S
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* FUNCTION PROTOTYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_MSC_OS_Init (USBD_ERR *p_err);
|
||||
|
||||
void USBD_MSC_OS_CommSignalPost(CPU_INT08U class_nbr,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_MSC_OS_CommSignalPend(CPU_INT08U class_nbr,
|
||||
CPU_INT32U timeout,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_MSC_OS_CommSignalDel (CPU_INT08U class_nbr,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_MSC_OS_EnumSignalPost(USBD_ERR *p_err);
|
||||
|
||||
void USBD_MSC_OS_EnumSignalPend(CPU_INT32U timeout,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* CONFIGURATION ERRORS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* MODULE END
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#endif
|
||||
1859
e3_176_ref-补丁/middleware/usb/uC-USBD/Class/MSC/usbd_scsi.c
Normal file
1859
e3_176_ref-补丁/middleware/usb/uC-USBD/Class/MSC/usbd_scsi.c
Normal file
File diff suppressed because it is too large
Load Diff
182
e3_176_ref-补丁/middleware/usb/uC-USBD/Class/MSC/usbd_scsi.h
Normal file
182
e3_176_ref-补丁/middleware/usb/uC-USBD/Class/MSC/usbd_scsi.h
Normal file
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* uC/USB-Device
|
||||
* The Embedded USB Device Stack
|
||||
*
|
||||
* Copyright 2004-2021 Silicon Laboratories Inc. www.silabs.com
|
||||
*
|
||||
* SPDX-License-Identifier: APACHE-2.0
|
||||
*
|
||||
* This software is subject to an open source license and is distributed by
|
||||
* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
|
||||
* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*
|
||||
* USB DEVICE MSC SCSI
|
||||
*
|
||||
* Filename : usbd_scsi.h
|
||||
* Version : V4.06.01
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
**********************************************************************************************************
|
||||
* MODULE
|
||||
**********************************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef USBD_SCSI_H
|
||||
#define USBD_SCSI_H
|
||||
|
||||
|
||||
/*
|
||||
**********************************************************************************************************
|
||||
* INCLUDE FILES
|
||||
**********************************************************************************************************
|
||||
*/
|
||||
|
||||
#include "../../Source/usbd_core.h"
|
||||
#include "usbd_msc.h"
|
||||
|
||||
|
||||
/*
|
||||
**********************************************************************************************************
|
||||
* EXTERNS
|
||||
**********************************************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef USBD_SCSI_MODULE
|
||||
#define USBD_SCSI_EXT
|
||||
#else
|
||||
#define USBD_SCSI_EXT extern
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
**********************************************************************************************************
|
||||
* DEFINES
|
||||
**********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
**********************************************************************************************************
|
||||
* DATA TYPES
|
||||
**********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
**********************************************************************************************************
|
||||
* STORAGE UNIT CONTROL
|
||||
**********************************************************************************************************
|
||||
*/
|
||||
|
||||
typedef struct usbd_storage_lun {
|
||||
CPU_INT08U LunNbr; /* Logical Unit Number. */
|
||||
CPU_CHAR *VolStrPtr; /* String uniquely identifying a logical unit. */
|
||||
CPU_BOOLEAN MediumPresent; /* Flag indicating presence of logical unit. */
|
||||
CPU_BOOLEAN LockFlag; /* Flag indicating logical unit locked or not. */
|
||||
CPU_BOOLEAN EjectFlag; /* Flag indicating logical unit ejected by host or not. */
|
||||
} USBD_STORAGE_LUN;
|
||||
|
||||
|
||||
/*
|
||||
**********************************************************************************************************
|
||||
* LOGICAL UNIT CHARACTERISTICS
|
||||
**********************************************************************************************************
|
||||
*/
|
||||
|
||||
typedef struct usbd_lun_info {
|
||||
CPU_INT08U VendorId[USBD_MSC_DEV_MAX_VEND_ID_LEN]; /* Dev vendor info. */
|
||||
CPU_INT08U ProdId[USBD_MSC_DEV_MAX_PROD_ID_LEN]; /* Dev prod ID. */
|
||||
CPU_INT32U ProdRevisionLevel; /* Revision level of product. */
|
||||
CPU_BOOLEAN ReadOnly; /* Wr protected or not. */
|
||||
} USBD_LUN_INFO;
|
||||
|
||||
|
||||
/*
|
||||
**********************************************************************************************************
|
||||
* LOGICAL UNIT CONTROL
|
||||
**********************************************************************************************************
|
||||
*/
|
||||
|
||||
typedef struct usbd_msc_lun_ctrl {
|
||||
CPU_INT08U LunNbr; /* LUN given by MSC IF. */
|
||||
USBD_LUN_INFO LunInfo; /* Logical unit info. */
|
||||
CPU_INT64U NbrBlocks; /* Nbr of blks supported by logical unit. */
|
||||
CPU_INT32U BlockSize; /* Blk size supported by logical unit. */
|
||||
void *LunArgPtr; /* Ptr to the LUN specific argument. */
|
||||
} USBD_MSC_LUN_CTRL;
|
||||
|
||||
|
||||
/*
|
||||
**********************************************************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
**********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
**********************************************************************************************************
|
||||
* MACRO'S
|
||||
**********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
**********************************************************************************************************
|
||||
* FUNCTION PROTOTYPES
|
||||
**********************************************************************************************************
|
||||
*/
|
||||
|
||||
void USBD_SCSI_Init ( USBD_ERR *p_err);
|
||||
|
||||
void USBD_SCSI_LunAdd ( CPU_INT08U lun_nbr,
|
||||
CPU_CHAR *p_vol_str,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_SCSI_CmdProcess( USBD_MSC_LUN_CTRL *p_lun,
|
||||
const CPU_INT08U *p_cbwcb,
|
||||
CPU_INT32U *p_resp_len,
|
||||
CPU_INT08U *p_data_dir,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_SCSI_DataRd (const USBD_MSC_LUN_CTRL *p_lun,
|
||||
CPU_INT08U scsi_cmd,
|
||||
CPU_INT08U *p_data_buf,
|
||||
CPU_INT32U data_len,
|
||||
CPU_INT32U *p_ret_len,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_SCSI_DataWr (const USBD_MSC_LUN_CTRL *p_lun,
|
||||
CPU_INT08U scsi_cmd,
|
||||
void *p_data_buf,
|
||||
CPU_INT32U data_len,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
void USBD_SCSI_Reset ( void);
|
||||
|
||||
void USBD_SCSI_Conn (const USBD_MSC_LUN_CTRL *p_lun);
|
||||
|
||||
void USBD_SCSI_Unlock (const USBD_MSC_LUN_CTRL *p_lun,
|
||||
USBD_ERR *p_err);
|
||||
|
||||
|
||||
/*
|
||||
**********************************************************************************************************
|
||||
* CONFIGURATION ERRORS
|
||||
**********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
**********************************************************************************************************
|
||||
* MODULE END
|
||||
**********************************************************************************************************
|
||||
*/
|
||||
#endif
|
||||
Reference in New Issue
Block a user