📄 usbh_ide_api.c
字号:
/*
* description: USBH IDE APIs
* Maker : Shuichi Yanagihara
* Copyright : (C)2005,SEIKO EPSON Corp. All Rights Reserved.
*/
#include "SPRDEF.h"
#include "SPRSTS.h"
#include "drvacs.h"
#include "usbh_ide_api.h"
#include "usbh_ide_if.h"
/*****************************************
* Define definition
*****************************************/
#define CLOSE (0) /* PASS Interface Module Close */
#define OPEN (1) /* PASS Interface Module Open */
#define NO_ID (0) /* ID Not Allocated */
/*****************************************
* Structures definition
*****************************************/
DRIVEACCESS_FUNCTIONTABLE IDEFuncAccessTable = { USBH_IDE_FuncReset,
USBH_IDE_FuncOpen,
USBH_IDE_FuncClose,
USBH_IDE_FuncAllocId,
USBH_IDE_FuncFreeId,
USBH_IDE_FuncDeviceReset,
USBH_IDE_FuncGetDeviceList,
USBH_IDE_FuncGetDeviceParameter,
USBH_IDE_FuncCommandOut,
USBH_IDE_FuncCommandStop,
USBH_IDE_FuncDMAStartA,
USBH_IDE_FuncDMAStop,
USBH_IDE_FuncGetDMAStatus,
USBH_IDE_FuncSoftDataTransfer,
USBH_IDE_FuncGetStatus,
USBH_IDE_FuncSyncCommand,
USBH_IDE_FuncRegisterCBRDMAComp,
USBH_IDE_FuncUnregisterCBRDMAComp,
USBH_IDE_FuncRegisterCBRIntrqComp,
USBH_IDE_FuncUnregisterCBRIntrqComp,
};
typedef struct devicestatus{
USHORT id; /* Upper layer ID */
USHORT cmdStatus; /* Command Status (STOP, COMP, EXEC) */
USHORT dmaStatus; /* Data transfer Status(STOP, COMP, EXEC) */
}USBH_IDE_DEVICESTS;
typedef struct tagUSBH_IDE_CBR_ID{
USHORT cbrID;
USHORT allocID;
}USBH_IDE_CBR_ID;
/*****************************************
* Function prototype declaration
*****************************************/
LONG USBH_IDE_FuncNotifyDMAComp(ULONG deviceNo, ULONG lReserve1, VOID *pReserve );
LONG USBH_IDE_FuncNotifyIntrqComp(ULONG deviceNo, ULONG lReserve1, VOID *pReserve );
/*****************************************
* Macro definition
*****************************************/
/*****************************************
* Variables definition
*****************************************/
static UCHAR OpenFlag; /* PASS Interface Module OPEN Flag */
static UCHAR IdTable[USBH_IDE_MAX_ID]; /* ID allocation management table */
static USHORT USBH_IDE_DMACompCbrID[MAX_DEVICE][MAX_ID]; /* DMA Complete CALLBACK ID */
static USHORT USBH_IDE_IntrqCompCbrID[MAX_DEVICE][MAX_ID]; /* Intrq CALLBACK ID */
static CALLBACK_PROC USBH_IDE_DMACompCBR[USBH_IDE_MAX_DEVICE][USBH_IDE_MAX_ID]; /* DMA CALLBACK TABLE */
static CALLBACK_PROC USBH_IDE_IntrqCompCBR[USBH_IDE_MAX_DEVICE][USBH_IDE_MAX_ID]; /* INTRQ CALLBACK TABLE */
static USBH_IDE_DEVICESTS deviceStatus[USBH_IDE_MAX_DEVICE]; /* Device State Management */
static USBH_IDE_CBR_ID ideCbrID;
/*=============================================================================================
// Function_Name: USBH_IDE_FuncReset
//
// description : Initialize this module
//
// Initialize the internal variables used in this module.
//
// argument : void
//
// return : STATUS_SUCCESS Process completed normally
// STATUS_UNSUCCESSFUL Error occured during the process
//
// flag : OpenFlag Indicate whether the module is usable.
//
// global : IdTable ID management table allocated in upper layer
===============================================================================================*/
LONG USBH_IDE_FuncReset( void )
{
UCHAR i,j;
LONG result;
OpenFlag = CLOSE;
/* ID Table Initialize */
for(i = 0; i < USBH_IDE_MAX_ID; i++){
IdTable[i] = FREE_ID;
}
/* Device Status Table Initialize */
for(i = 0; i < USBH_IDE_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_IDE_MAX_DEVICE; i++){
for(j = 0; j < USBH_IDE_MAX_ID; j++){
USBH_IDE_DMACompCBR[i][j] = NULL;
USBH_IDE_IntrqCompCBR[i][j] = NULL;
}
}
result = USBH_IDE_IFReset();
return result;
}
/*=============================================================================================
// Function_Name: USBH_IDE_FuncOpen
//
// description : Open this module
//
// After open this module,enter the usable state.If the module is not opened,
// except for the below API,can not execut any other API
// USBH_IDE_FuncReset
// USBH_IDE_FuncOpen
//
// argument : void
//
// return : STATUS_SUCCESS Process completed normally
// STATUS_UNSUCCESSFUL Error occured during the process
//
// flag : OpenFlag Indicate whether the module is usable.
===============================================================================================*/
LONG USBH_IDE_FuncOpen( void )
{
/* OpenFlag Check */
if(OpenFlag != OPEN){
/* OPEN Flag Set */
OpenFlag = OPEN;
}
return STATUS_SUCCESS;
}
/*=============================================================================================
// Function_Name: USBH_IDE_FuncClose
//
// description : Close this module.
//
// After close this module,enter the unusable state.If do not open again after close ,
// exept for the below API,can not execut any other API
// USBH_IDE_FuncReset
// USBH_IDE_FuncOpen
//
// argument : void
//
// return : STATUS_SUCCESS Process completed normally
// STATUS_UNSUCCESSFUL Error occured during the process
// STATUS_NOT_OPENED This module had not been opened
//
// flag : OpenFlag Indicate whether the module is usable.
===============================================================================================*/
LONG USBH_IDE_FuncClose( void )
{
UCHAR i,j;
/* 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_IDE_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_IDE_MAX_DEVICE; i++){
for(j = 0; j < USBH_IDE_MAX_ID; j++){
USBH_IDE_DMACompCBR[i][j] = NULL;
USBH_IDE_IntrqCompCBR[i][j] = NULL;
}
}
/* Complete */
return STATUS_SUCCESS;
}
/*=============================================================================================
// Function_Name: USBH_IDE_FuncAllocId
//
// description : Allocate ID correspond to the upper layer
//
// Allocate ID to the upper layer of this module
//
// argument : *pAllocId (in)Pointer of ID
//
// return : STATUS_SUCCESS Process completed normally
// STATUS_UNSUCCESSFUL Error occured during the process
// STATUS_NOT_OPENED This module had not been opened
// STATUS_NOT_ALLOCATE_ID Can not allocate ID
//
// flag : OpenFlag Indicate whether the module is usable.
//
// global : IdTable ID management table allocated in upper layer
===============================================================================================*/
LONG USBH_IDE_FuncAllocId( USHORT *pAllocId )
{
USHORT i;
/* OpenFlag Check */
if(OpenFlag != OPEN){
/* Not Opened Error */
return STATUS_NOT_OPENED;
}
for(i = 0; i < USBH_IDE_MAX_ID; i++){
if(IdTable[i] == FREE_ID){
IdTable[i] = ALLOC_ID; /* ID has been allocated. */
*pAllocId = (i + 1); /* Set ID */
/* Complete */
return STATUS_SUCCESS;
}
}
/* There is no free ID */
return STATUS_NOT_ALLOCATE_ID;
}
/*=============================================================================================
// Function_Name: USBH_IDE_FuncFreeId
//
// description : Free the ID that allocated to the corresponding upper layer
//
// Free the ID that allocated to the upper layer of this module
//
// argument : id (in)ID value
//
// return : STATUS_SUCCESS Process completed normally
// STATUS_UNSUCCESSFUL Error occured during the process
// STATUS_NOT_OPENED This module had not been opened
// STATUS_INVALID_PARAMETER Parameter error
// STATUS_NOT_FREE_ID Can not free thespecified ID
//
// flag : OpenFlag Indicate whether the module is usable.
//
// global : IdTable ID management table allocated in upper layer
===============================================================================================*/
LONG USBH_IDE_FuncFreeId( USHORT id )
{
UCHAR i;
/* OpenFlag Check */
if(OpenFlag != OPEN){
/* Not Opened Error */
return STATUS_NOT_OPENED;
}
/* Check ID value */
if((id - 1) > USBH_IDE_MAX_ID || (IdTable[id-1] == FREE_ID)){
/* Parameter error */
return STATUS_INVALID_PARAMETER;
}
/* Check the device operation */
for(i = 0; i < USBH_IDE_MAX_DEVICE; i++) {
if( (deviceStatus[i].cmdStatus == DRV_FUNC_CMD_EXEC) || (deviceStatus[i].dmaStatus == DRV_FUNC_CMD_EXEC) ) {
/* The device that specified by the ID is working . */
return STATUS_NOT_FREE_ID;
}
}
IdTable[(id -1)] = FREE_ID; /* Free the ID */
/* Complete */
return STATUS_SUCCESS;
}
/*=============================================================================================
// Function_Name: USBH_IDE_FuncDeviceReset
//
// description : Reset the specified device
//
// Output the reset request of the specified device to the corresponding lowerlayer.
// When processing it to the device, the processing of device is interrupted.
//
// argument : id (in)ID value
// deviceNo (in)Device No.
//
// return : STATUS_SUCCESS Process completed normally
// STATUS_UNSUCCESSFUL Error occured during the process
// STATUS_NOT_OPENED This module had not been opened
// STATUS_INVALID_PARAMETER Parameter error
// STATUS_EXECUTION_PORT The specified port is operating
//
// flag : OpenFlag Indicate whether the module is usable.
//
// global : IdTable ID management table allocated in upper layer
===============================================================================================*/
LONG USBH_IDE_FuncDeviceReset( USHORT id, USHORT deviceNo )
{
LONG result;
/* OpenFlag Check */
if(OpenFlag != OPEN){
/* Not Opened Error */
return STATUS_NOT_OPENED;
}
/* Check ID value */
if((id - 1) > USBH_IDE_MAX_ID || (IdTable[id-1] == FREE_ID)){
/* Parameter error */
return STATUS_INVALID_PARAMETER;
}
/* Check deviceNo value */
if( deviceNo >= USBH_IDE_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_IDE_IFDeviceReset(deviceNo);
/* Command Status Clear */
deviceStatus[deviceNo].id = NO_ID;
deviceStatus[deviceNo].cmdStatus = DRV_FUNC_CMD_COMP;
return result;
}
/*=============================================================================================
// Function_Name: USBH_IDE_FuncGetDeviceList
//
// description : It informs the number of connected devices and each device type to the upper layer
//
// It informs the number of connected devices and each device type to the upper layer
//
// argument : id (in)ID value
// *pList (in)pointer of device list
//
// return : STATUS_SUCCESS Process completed normally
// STATUS_UNSUCCESSFUL Error occured during the process
// STATUS_NOT_OPENED This module had not been opened
// STATUS_INVALID_PARAMETER Parameter error
===============================================================================================*/
LONG USBH_IDE_FuncGetDeviceList( USHORT id, UCHAR *pList )
{
LONG result;
/* OpenFlag Check */
if(OpenFlag != OPEN){
/* Not Opened Error */
return STATUS_NOT_OPENED;
}
/* Check ID value */
if((id - 1) > USBH_IDE_MAX_ID || (IdTable[id-1] == FREE_ID)){
/* Parameter error */
return STATUS_INVALID_PARAMETER;
}
result = USBH_IDE_IFGetDeviceList(pList);
return result;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -