📄 usbh_storage_api.c
字号:
/*
* description: USBH Mass Storage Class APIs
* Maker : Shuichi Yanagihara
* Copyright : (C)2005,SEIKO EPSON Corp. All Rights Reserved.
*/
#include "SPRDEF.h"
#include "SPRSTS.h"
#include "kernel_id.h"
#include "drvacs.h"
#include "usbh_storage_api.h"
#include "usbh_storage_if.h"
#include "led_if.h"
/*****************************************
* Constants declaration
*****************************************/
#define CLOSE (0) /* PASS Interface Module Close */
#define OPEN (1) /* PASS Interface Module Open */
#define NO_ID (0) /* ID Not Allocated */
// Information of activating cycle handler
#define CYC_TIME (1) /* The interval for activating cycle handler */
/*****************************************
* Structures declaration
*****************************************/
DRIVEACCESS_FUNCTIONTABLE MSFuncAccessTable = { USBH_STRG_FuncReset,
USBH_STRG_FuncOpen,
USBH_STRG_FuncClose,
USBH_STRG_FuncAllocId,
USBH_STRG_FuncFreeId,
USBH_STRG_FuncDeviceReset,
USBH_STRG_FuncGetDeviceList,
USBH_STRG_FuncGetDeviceParameter,
USBH_STRG_FuncCommandOut,
USBH_STRG_FuncCommandStop,
USBH_STRG_FuncDMAStartA,
USBH_STRG_FuncDMAStop,
USBH_STRG_FuncGetDMAStatus,
USBH_STRG_FuncSoftDataTransfer,
USBH_STRG_FuncGetStatus,
USBH_STRG_FuncSyncCommand,
USBH_STRG_FuncRegisterCBRDMAComp,
USBH_STRG_FuncUnregisterCBRDMAComp,
USBH_STRG_FuncRegisterCBRIntrqComp,
USBH_STRG_FuncUnregisterCBRIntrqComp,
};
typedef struct devicestatus{
USHORT id; /* The ID of the upper layer*/
USHORT cmdStatus; /* Command Status (STOP, COMP, EXEC) */
USHORT dmaStatus; /* Data transfer status*/
}USBH_STRG_DEVICESTS;
typedef struct tagUSBH_STRG_CBR_ID{
USHORT cbrID;
USHORT allocID;
}USBH_STRG_CBR_ID;
/*****************************************
* Function prototype declaration
*****************************************/
LONG USBH_STRG_FuncNotifyDMAComp(ULONG deviceNo, ULONG result, VOID *pReserve );
LONG USBH_STRG_FuncNotifyIntrqComp(ULONG deviceNo, ULONG result, VOID *pReserve );
/*****************************************
* Macro declaration
*****************************************/
/*****************************************
* Constants declaration
*****************************************/
static UCHAR OpenFlag; /* PASS Interface Module OPEN Flag */
static UCHAR IdTable[USBH_STRG_MAX_ID]; /* ID allocation management table*/
static USHORT USBH_STRG_DMACompCbrID[MAX_DEVICE][MAX_ID]; /* DMA Complete CALLBACK ID */
static USHORT USBH_STRG_IntrqCompCbrID[MAX_DEVICE][MAX_ID]; /* Intrq CALLBACK ID */
static CALLBACK_PROC USBH_STRG_DMACompCBR[USBH_STRG_MAX_DEVICE][USBH_STRG_MAX_ID]; /* DMA CALLBACK TABLE */
static CALLBACK_PROC USBH_STRG_IntrqCompCBR[USBH_STRG_MAX_DEVICE][USBH_STRG_MAX_ID]; /* INTRQ CALLBACK TABLE */
static USBH_STRG_DEVICESTS deviceStatus[USBH_STRG_MAX_DEVICE]; /* Device Status management*/
static USBH_STRG_CBR_ID storageCbrID;
/*=============================================================================================
// Function_Name: USBH_STRG_FuncReset
//
// description : Initialize this module
//
// Initialize the variables used by this module.
//
// argument : void
//
// return : STATUS_SUCCESS The process complete successfully.
// STATUS_UNSUCCESSFUL Error ocure during the process.
//
// flag : OpenFlag It is used to indicate if the module is usable.
//
// global : IdTable ID management table allocated in high-ranking layer
===============================================================================================*/
LONG USBH_STRG_FuncReset( void )
{
UCHAR i,j;
LONG result;
OpenFlag = CLOSE;
/* ID Table Initialize */
for(i = 0; i < USBH_STRG_MAX_ID; i++){
IdTable[i] = FREE_ID;
}
/* Device Status Table Initialize */
for(i = 0; i < USBH_STRG_MAX_DEVICE; i++){
deviceStatus[i].id = NO_ID;
deviceStatus[i].cmdStatus = DRV_FUNC_CMD_COMP;
deviceStatus[i].dmaStatus = DRV_DMA_FUNC_COMP;
}
/* CALLBACK Table Initialize */
for(i = 0; i < USBH_STRG_MAX_DEVICE; i++){
for(j = 0; j < USBH_STRG_MAX_ID; j++){
USBH_STRG_DMACompCBR[i][j] = NULL;
USBH_STRG_IntrqCompCBR[i][j] = NULL;
}
}
OS_ActTsk( TSKID_USBH_STRGEVENT ); // Activate the USBH_STRGEvent Task
result = USBH_STRG_IFReset();
return result;
}
/*=============================================================================================
// Function_Name: USBH_STRG_FuncOpen
//
// description : Open this module
//
// After open this module,it is posible to use this module.If not execute the Open operation,
Can not process the APIs other than below API
// USBH_STRG_FuncReset
// USBH_STRG_FuncOpen
//
// argument : void
//
// return : STATUS_SUCCESS Complete successfully
// STATUS_UNSUCCESSFUL Error occured during the process
//
// flag : OpenFlag It is used to indicate if the module is usable.
===============================================================================================*/
LONG USBH_STRG_FuncOpen( void )
{
OS_BOOL bCpuState; // CPU lock state
/* OpenFlag Check */
if(OpenFlag != OPEN){
/* OPEN Flag Set */
OpenFlag = OPEN;
}
// Check CPU lock state
bCpuState = OS_SnsLoc();
if( bCpuState != OS_TRUE )
{
// If CPU is not locked, lock it.
OS_LocCpu();
}
if( bCpuState != OS_TRUE )
{
// If CPU is locked, unlock it
OS_UnlCpu();
}
return STATUS_SUCCESS;
}
/*=============================================================================================
// Function_Name: USBH_STRG_FuncClose
//
// description : Close this module
//
// After close this module,it is in the state of unusable. After close,if not execute the Open operation again
Can not process the APIs other than below API
// USBH_STRG_FuncReset
// USBH_STRG_FuncOpen
//
// argument : void
//
// return : STATUS_SUCCESS Complete successfully
// STATUS_UNSUCCESSFUL Error occured during the process
// STATUS_NOT_OPENED This module is not opened
//
// flag : OpenFlag It is used to indicate if the module is usable.
===============================================================================================*/
LONG USBH_STRG_FuncClose( void )
{
UCHAR i,j;
OS_BOOL bCpuState; // CPU儘僢僋忬懺
/* OpenFlag Check */
if(OpenFlag != OPEN){
/* Not Opened Error */
return STATUS_NOT_OPENED;
}
/* OPEN Flag Clear */
OpenFlag = CLOSE;
/* Device Status Table Initialize */
for(i = 0; i < USBH_STRG_MAX_DEVICE; i++){
deviceStatus[i].id = NO_ID;
deviceStatus[i].cmdStatus = DRV_FUNC_CMD_COMP;
deviceStatus[i].dmaStatus = DRV_DMA_FUNC_COMP;
}
/* CALLBACK Table Initialize */
for(i = 0; i < USBH_STRG_MAX_DEVICE; i++){
for(j = 0; j < USBH_STRG_MAX_ID; j++){
USBH_STRG_DMACompCBR[i][j] = NULL;
USBH_STRG_IntrqCompCBR[i][j] = NULL;
}
}
// Check CPU lock state
bCpuState = OS_SnsLoc();
if( bCpuState != OS_TRUE )
{
// If CPU is not locked, lock it.
OS_LocCpu();
}
OS_TerTsk( TSKID_USBH_STRGEVENT ); /* Terminate USBH_STRGEvent Task */
if( bCpuState != OS_TRUE )
{
// If CPU is locked, unlock it
OS_UnlCpu();
}
/* Complete */
return STATUS_SUCCESS;
}
/*=============================================================================================
// Function_Name: USBH_STRG_FuncAllocId
//
// description : Allocate ID for the upper layer.
//
// Allocate ID for the upper layer of this module.
//
// argument : *pAllocId (in)The pointer pointt to the ID
//
// return : STATUS_SUCCESS Complete successfully
// STATUS_UNSUCCESSFUL Error occured during the process
// STATUS_NOT_OPENED This module is not opened
// STATUS_NOT_ALLOCATE_ID Can not alocate ID
//
// flag : OpenFlag It is used to indicate if the module is usable.
//
// global : IdTable ID management table allocated in high-ranking layer
===============================================================================================*/
LONG USBH_STRG_FuncAllocId( USHORT *pAllocId )
{
USHORT i;
/* OpenFlag Check */
if(OpenFlag != OPEN){
/* Not Opened Error */
return STATUS_NOT_OPENED;
}
for(i = 0; i < USBH_STRG_MAX_ID; i++){
if(IdTable[i] == FREE_ID){
IdTable[i] = ALLOC_ID; /* Allocate ID OK */
*pAllocId = (i + 1); /* Set ID*/
/* Complete */
return STATUS_SUCCESS;
}
}
/* No emperty ID */
return STATUS_NOT_ALLOCATE_ID;
}
/*=============================================================================================
// Function_Name: USBH_STRG_FuncFreeId
//
// description : Release the ID that allocated for the upper layer
//
// Release the ID that allocateed for the upper layer of this module.
//
// argument : id (in)ID value
//
// return : STATUS_SUCCESS Complete successfully
// STATUS_UNSUCCESSFUL Error occured during the process
// STATUS_NOT_OPENED This module is not opened
// STATUS_INVALID_PARAMETER Parameter error
// STATUS_NOT_FREE_ID Can not free the specified ID
//
// flag : OpenFlag It is used to indicate if the module is usable.
//
// global : IdTable ID management table allocated in high-ranking layer
===============================================================================================*/
LONG USBH_STRG_FuncFreeId( USHORT id )
{
UCHAR i;
/* OpenFlag Check */
if(OpenFlag != OPEN){
/* Not Opened Error */
return STATUS_NOT_OPENED;
}
/* Check the ID value */
if((id - 1) > USBH_STRG_MAX_ID || (IdTable[id-1] == FREE_ID)){
/* Parameter error*/
return STATUS_INVALID_PARAMETER;
}
/* Check the action of the device */
for(i = 0; i < USBH_STRG_MAX_DEVICE; i++) {
if( (deviceStatus[i].cmdStatus == DRV_FUNC_CMD_EXEC) || (deviceStatus[i].dmaStatus == DRV_FUNC_CMD_EXEC) ) {
/* The device with the specified ID is working*/
return STATUS_NOT_FREE_ID;
}
}
IdTable[(id -1)] = FREE_ID; /* Free the ID */
/* Complete */
return STATUS_SUCCESS;
}
/*=============================================================================================
// Function_Name: USBH_STRG_FuncDeviceReset
//
// description : The specified device is reset.
//
// The reset demand of the specified device is detected by the subordinate position module.
// When exceuting the process to the device, the processing of the device is interrupted.
//
// argument : id (in)ID value
// deviceNo (in)Device No.
//
// return : STATUS_SUCCESS Complete successfully
// STATUS_UNSUCCESSFUL Error occured during the process
// STATUS_NOT_OPENED This module is not opened
// STATUS_INVALID_PARAMETER Parameter error
// STATUS_EXECUTION_PORT The specified port is running
//
// flag : OpenFlag It is used to indicate if the module is usable.
//
// global : IdTable ID management table allocated in high-ranking layer
===============================================================================================*/
LONG USBH_STRG_FuncDeviceReset( USHORT id, USHORT deviceNo )
{
LONG result;
/* OpenFlag Check */
if(OpenFlag != OPEN){
/* Not Opened Error */
return STATUS_NOT_OPENED;
}
/* Check the ID value */
if((id - 1) > USBH_STRG_MAX_ID || (IdTable[id-1] == FREE_ID)){
/* Parameter error */
return STATUS_INVALID_PARAMETER;
}
/* Check the DeviceNo */
if( deviceNo >= USBH_STRG_MAX_DEVICE ){
/* Parameter error */
return STATUS_INVALID_PARAMETER;
}
/* Check whether other ID is using Device. */
if(deviceStatus[deviceNo].id != id && deviceStatus[deviceNo].id != NO_ID ) {
/* Device is operating. */
return STATUS_EXECUTION_PORT;
}
/* Command Status Set */
deviceStatus[deviceNo].id = id;
deviceStatus[deviceNo].cmdStatus = DRV_FUNC_CMD_EXEC;
result = USBH_STRG_IFDeviceReset(deviceNo);
/* Command Status Clear */
deviceStatus[deviceNo].id = NO_ID;
deviceStatus[deviceNo].cmdStatus = DRV_FUNC_CMD_COMP;
return result;
}
/*=============================================================================================
// Function_Name: USBH_STRG_FuncGetDeviceList
//
// description : Informs the upper layer of the number of connected devices and each device type.
//
// Informs the upper layer of the number of connected devices and each device type.
//
// argument : id (in)ID value
// *pList (in)pointer that points to the device list
//
// return : STATUS_SUCCESS Complete successfully
// STATUS_UNSUCCESSFUL Error occured during the process
// STATUS_NOT_OPENED This module is not opened
// STATUS_INVALID_PARAMETER Parameter error
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -