⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdapi.h

📁 intel xscale pxa270的完整wince4.2 BSP包
💻 H
📖 第 1 页 / 共 3 页
字号:
/*****************************************************************************
* Filename: SDAPI.H - Defines & structures for HDTK API
*                     
* SanDisk Host Developer's Toolkit
*
* Copyright (c) 1996-2000 SanDisk Corporation
* Copyright EBS Inc. 1996
* All rights reserved.
* This code may not be redistributed in source or linkable object form
* without the consent of its author.
*
* Description: 
*       Provide FILE SYSTEM API as well as INTERFACE API to different
*       SANDISK products such as ATA PC Cards, CF, SPI, MMC, so on....
*
*       The API provides the initial state, transaction state,
*       device status andclosing state for IDE or PCMCIA, SPI and 
*       MMC controllers.
*
*****************************************************************************/

#ifndef __SDAPI_H__

#ifdef __cplusplus
extern "C" {
#endif


/* HDTK Version */
#define HDTK_MAJOR      4
#define HDTK_MINOR      00


#define HDTK_VERSION    ((HDTK_MAJOR << 8) + HDTK_MINOR)


/* Type Definitions of HDTK */
#include "sdtypes.h"

/* Include development environment settings */
#include "sdconfig.h"

/* Include kernel specific definitions */
#include "pckernel.h"


/* Error codes */

#define PCERR_FAT_FLUSH         0  /* Cant flush FAT */
#define PCERR_INITMEDI          1  /* Not a DOS disk */
#define PCERR_INITDRNO          2  /* Invalid driveno */
#define PCERR_INITCORE          3  /* Out of core */
#define PCERR_INITDEV           4  /* Can't initialize device */
#define PCERR_INITREAD          5  /* Can't read block 0 */
#define PCERR_INITWRITE         6  /* Can't write block 0 */
#define PCERR_BLOCKCLAIM        7  /* PANIC: Buffer Claim */
#define PCERR_BLOCKLOCK         8  /* Warning: freeing a locked buffer */
#define PCERR_REMINODE          9  /* Trying to remove inode with open > 1 */
#define PCERR_FATREAD           10  /* IO Error While Failed Reading FAT */
#define PCERR_DROBJALLOC        11 /* Memory Failure: Out of DROBJ Structures */
#define PCERR_FINODEALLOC       12 /* Memory Failure: Out of FINODE Structures */



/*********************** CRITICAL_ERROR_HANDLER ******************************/
/* Arguments to critical_error_handler() */
#define CRERR_BAD_FORMAT        301
#define CRERR_NO_CARD           302
#define CRERR_BAD_CARD          303
#define CRERR_CHANGED_CARD      304
#define CRERR_CARD_FAILURE      305
#define CRERR_ID_ERROR          306
#define CRERR_ECC_ERROR         307


/* Return code from critical_error_handler() */
#define CRITICAL_ERROR_ABORT    1
#define CRITICAL_ERROR_RETRY    2
#define CRITICAL_ERROR_FORMAT   3
#define CRITICAL_ERROR_CLEARECC 4



/* Drive geometry structure */
typedef struct drv_geometry_desc
{
    UINT32  totalLBA;       /* Total drive logical blocks */
    UINT16  dfltCyl;        /* Number of cylinders */
    UINT16  dfltHd;         /* Number of Heads */
    UINT16  dfltSct;        /* Sectors per track */
    UINT16  dfltBytesPerSect; /* Bytes per sector */
    UCHAR   serialNum[16];  /* Drive serial number in ASCII mode */
    UCHAR   modelNum[32];   /* Drive model number in ASCII mode */
} DRV_GEOMETRY_DESC, *PDRV_GEOMETRY_DESC;


#if (USE_FILE_SYSTEM)

/* Maximum path length. */
#define EMAXPATH        256


/* Date stamp structure */
typedef struct datestr {
    UINT16 date;            /* Current Date */
    UINT16 time;            /* Current time */
} DATESTR;


/* Structure for user to do recursive search for files in a selected drive */
typedef struct dstat {
    TEXT    fname[10];      /* Null terminated file and extension */
    TEXT    fext[4];
    UINT16  fattribute;     /* File attributes */
    UINT16  ftime;          /* Time & Date last modified. See date */
    UINT16  fdate;          /* and time handlers for getting info */
    ULONG   fsize;          /* File size */
    INT16   driveno;
    TEXT    pname[10];      /* Pattern. */
    TEXT    pext[4];
    TEXT    path[EMAXPATH];
    TEXT    longFileName[EMAXPATH];
} DSTAT;

#endif /* (USE_FILE_SYSTEM) */


/* OEM platform specific */
#include "oem.h"


#if (USE_SECURITY)
#include "ssmapi.h"

/* Security structure */
typedef struct _ssmservice {

    UINT16 driveno;             /* Drive number */
    UINT16 cmd_category;        /* 0=security, 1=sec file system */
    UINT16 ssm_cmd;             /* CMD operation code */
    UINT16 ret_status;          /* Status of the request */
    void  *call_back_addrs;     /* For future call back security implementation*/

    union _ssmargs {            /* Request's information */

#if (USE_FILE_SYSTEM)
    struct _openargs {
        PCFD   file_handle;             /* Returned file handle*/
        TEXT * filespec;                /* Pointer to path\file */
        UINT16 open_flags;              /* (e.g., PO_RDWR, etc. see HDTK docs)*/
        UINT16 open_mode;               /* (e.g., FS_IREAD, etc. see HDTK docs)*/
    } myopenfs;

    struct _closeargs {
        PCFD   cfile_handle;            /* Handle of file to close*/
    } myclosefs;                            

    struct _readargs {
        PCFD rfile_desc;                /* Handle obtained from po_open */
        UCHAR * read_buf;               /* Ptr to buffer which will hold returned data*/
        UCOUNT read_count;              /* Will attempt to read this specified amount*/
        UCOUNT ret_read_count;          /* Returned actual number was able to read*/
    } myrdfs; 

    struct _writeargs {
        PCFD wfile_desc;                /* Handle obtained from po_open */
        UCHAR * write_buf;              /* Ptr to buffer that contains data to write*/
        UCOUNT write_count;             /* Write this number of bytes*/
    } mywrfs; 

                        /* Used for creating and removing dirs*/
    struct _dirargs {                        /* Also use for set and get current dir*/
        TEXT * dir_name;                /* Directory name*/
    } mydirfs; 


    struct _lseekargs {                      /* Used for lseek*/
        PCFD lsfile_handle;             /* File handle of open file*/
        ULONG lsoffset;                 /* Offset within file to lseek to*/
        UINT16 lsmethod;                /* Method from (begin, current, or end)*/
        INT16  lerr_flag;               /* lseek error flags returned */
    } myseekfs; 

    struct _findfileargs {                   /* Used for find first dir entry*/
        DSTAT * dir_stat;               /* HDTK status struc */
        TEXT * dir_pattern;             /* Name or pattern to search for*/
    } myffilefs; 

    struct _getattrib {                      /* Used for get file attribute*/
        TEXT * agfile_path;             /* Path\name for file */
        UCHAR * attrib_ret;             /* Address of where to return attribute*/
    } mygetattrfs; 

    struct _setattrib {                      /* Used for set file attribute*/
        TEXT * asfile_path;             /* Path\name for file */
        UCHAR  file_attrib;             /* Attribute to apply to file */
    } mysetattrfs; 


    struct _delfile {                        /* Used for deleting files */
        TEXT * del_file_path;           /* Path\name of file to be deleted*/
    } mydelfs; 

    struct _renamefile {                     /* Used for renaming files */
        TEXT * rename_file_path;        /* Path\name of file to be renamed*/
        TEXT * new_name;                /* New name for file */
    } myrenfs; 

    struct _miscfile {                      /* Misc. */
        UCHAR   *buffer;                /* Data buffer */
        UINT32  lba;
        UINT16  noBlks;
    } mymiscfs;
#endif

#if (USE_SECURITY)
    struct secure_if {
        UCHAR   *sec_inbuf;             /* Data buffer for data to be encyrpted or decrypted */
        UCHAR   *sec_outbuf;            /* Buffer that will hold encyrpted or decrypted data */
        UINT32  lba;
        UINT16  sec_size;
    } mysecif;
#endif
    } ssinfo;  /* arg union */

#if (USE_SECURITY)
        UCHAR   SecCmd[8];              /* argument of secure command stuffed here */
#endif

} SSMSERVE;

/* Function prototype */
SDVOID ssmentry(SSMSERVE *reqPacket);

#endif /* (USE_SECURITY) */


#ifndef copybuff
SDVOID copybuff(SDVOID *vto, SDVOID *vfrom, INT16 size);
#endif

#ifndef compbuff
INT16 compbuff(SDVOID *vfrom, SDVOID *vto, INT16 size);
#endif

#ifndef pc_memfill
SDVOID pc_memfill(SDVOID *vto, INT16 size, UTINY c);
#endif

#ifndef pc_strcat
SDVOID pc_strcat(TEXT *to, TEXT *from);
#endif


#if (CHAR_16BIT)
SDVOID b_unpack(UTINY *to, UINT16 *from, UINT16 length, UINT16 offset);
#endif

/* Byte ordering conversion */
UINT16 to_WORD(UCHAR *buf);
ULONG to_DWORD(UCHAR *buf);
SDVOID fr_WORD ( UCHAR *to, UINT16 from );
SDVOID fr_DWORD ( UCHAR *to, UINT32 from );


UINT16 swap_hi_low_byte(UINT16 inword);


/****************************************************************************/
/************************** MEMORY or I/O ACCESS ****************************/
/****************************************************************************/

#if (USE_MEMMODE)

    /* Read/Write register access */ 
    #define SDREAD_DATA32(X)        *((FPTR32) (X))
    #define SDREAD_DATA16(X)        *((FPTR16) (X))   
    #define SDREAD_DATA08(X)        *((FPTR08) (X))

    #define SDWRITE_DATA32(X, Y)    (*((FPTR32) (X)) = (UINT32)(Y))
    #define SDWRITE_DATA16(X, Y)    (*((FPTR16) (X)) = (UINT16)(Y))
    #define SDWRITE_DATA08(X, Y)    (*((FPTR08) (X)) = (UINT08)(Y))

#else   /* I/O MODE */

    /* 8-bit interface */

    #define SDREAD_DATA08(X) (inpbyte((UINT32) (X) ))
    #define SDWRITE_DATA08(X,Y) outpbyte((UINT32)(X), (UINT16(Y))

   #if (WORD_ACCESS_ONLY)  /* 16-bit interface */

    #define SDREAD_DATA16(X) (inpword((UINT32) (X) ))
    #define SDWRITE_DATA16(X,Y) outpword((UINT32)(X), (UINT16)(Y))

   #endif


#endif  /* USE_MEMMODE */



/*****************************************************************************
* Name: pc_get_error
*
* Description
*       Get error code
*
* Entries:
*    if (USE_FILE_SYSTEM)
*       INT16  taskno     task number
*    else #(!USE_FILE_SYSTEM)
*       INT16  driveno    drive number
* Returns:
*    if (USE_FILE_SYSTEM)
*    {
*          0  No Error
*       otherwise, one of the following error code:
*           PEBADF          9    Invalid file descriptor
*           PENOENT         2    File not found or path to file not found
*           PEMFILE         24   No file descriptors available (too many files open)
*           PEEXIST         17   Exclusive access requested but file already exists.
*           PEACCES         13   Attempt to open a read only file or a special (directory)
*           PEINVAL         22   Seek to negative file pointer attempted.
*           PENOSPC         28   Write failed. Presumably because of no space
*           PESHARE         30   Open failed do to sharing
*           PEDEVICE        31   No Valid Disk Present
*    }
*    else #(!USE_FILE_SYSTEM)
*    {
*
*           0  No Error
*       otherwise, one of the following error code in controller_s:
*           BUS_ERC_DIAG     1   Drive diagnostic failed in initialize
*           BUS_ERC_ARGS     2   User supplied invalid arguments
*           BUS_ERC_DRQ      3   DRQ should be asserted but it isn't
*                                  or driver and controller are out of phase
*           BUS_ERC_TIMEOUT  4   Timeout during some operation 
*           BUS_ERC_STATUS   5   Controller reported an error
*                                  look in the error register
*    }
*
******************************************************************************/
INT16 pc_get_error (INT16 driveno_or_taskno);


INT16 pc_get_extended_error (INT16 driveno);



/****************************************************************************/
/**************************** FILE SYSTEM API *******************************/
/****************************************************************************/

#if (USE_FILE_SYSTEM)

#define PCDELETE (UTINY)0xE5    /* MS-DOS file deleted char */

#define ARDONLY         0x01    /* MS-DOS File attributes */
#define AHIDDEN         0x02
#define ASYSTEM         0x04
#define AVOLUME         0x08 
#define ADIRENT         0x10
#define ARCHIVE         0x20
#define ANORMAL         0x00
#define CHICAGO_EXT     0x0F    /* Chicago extended filename attribute */


/* 
** Structure for use by with file statistic.
** Portions of this structure and the macros were lifted from BSD sources.
** See the RTFS ANSI library for BSD terms & conditions. 
*/
typedef struct stat
{
    ULONG   st_mode;        /* (see S_xxxx below) */
    ULONG   st_size;        /* file size, in bytes */
        INT32   st_blksize;     /* optimal blocksize for I/O (cluster size) */
        INT32   st_blocks;      /* blocks allocated for file */
    DATESTR st_atime;       /* last access (all times are the same) */
    DATESTR st_mtime;       /* last modification */
    DATESTR st_ctime;       /* last file status change */
    INT16   st_dev;         /* (drive number, rtfs) */
    INT16   st_ino;         /* inode number (0) */
    INT16   st_nlink;       /* (always 1) */
    INT16   st_rdev;        /* (drive number, rtfs) */
    UINT16  fattribute;     /* File attributes - DOS attributes
                   (non standard but useful)
                */
    UINT16  padding;     
} STAT;


/* Values for the st_mode field */
#define S_IFMT   0170000        /* type of file mask */
#define S_IFCHR  0020000        /* character special (unused) */
#define S_IFDIR  0040000        /* directory */
#define S_IFBLK  0060000        /* block special  (unused) */
#define S_IFREG  0100000        /* regular */
#define S_IWRITE 0000400        /* Write permitted  */
#define S_IREAD  0000200        /* Read permitted. (Always true anyway)*/

#define DEFFILEMODE (S_IREAD|S_IWRITE)
#define S_ISDIR(m)  ((m & 0170000) == 0040000) /* directory */
#define S_ISCHR(m)  ((m & 0170000) == 0020000) /* char special */
#define S_ISBLK(m)  ((m & 0170000) == 0060000) /* block special */
#define S_ISREG(m)  ((m & 0170000) == 0100000) /* regular file */
#define S_ISFIFO(m) ((m & 0170000) == 0010000) /* fifo */



/* File creation permissions for open */
/* Note: OCTAL */
#define PS_IWRITE       0000400 /* Write permitted  */
#define PS_IREAD        0000200 /* Read permitted. (Always true anyway) */


/* File access flags */
#define PO_RDONLY       0x0000 /* Open for read only */
#define PO_WRONLY       0x0001 /* Open for write only */
#define PO_RDWR         0x0002 /* Read/write access allowed. */
#define PO_APPEND       0x0008 /* Seek to eof on each write */
#define PO_CREAT        0x0100 /* Create the file if it does not exist. */
#define PO_TRUNC        0x0200 /* Truncate the file if it already exists */
#define PO_EXCL         0x0400 /* Fail if creating and already exists */
#define PO_TEXT         0x4000 /* Ignored */
#define PO_BINARY       0x8000 /* Ignored. All file access is binary */
#define PO_NOSHAREANY   0x0004 /* Wants this open to fail if already open.
                    Other opens will fail while this open
                    is active
                   */
#define PO_NOSHAREWRITE 0x0800 /* Wants this opens to fail if already open
                  for write. Other open for write calls 
                  will fail while this open is active.
                   */

/* Arguments to extend file */
#define PC_FIRST_FIT    1
#define PC_BEST_FIT     2
#define PC_WORST_FIT    3



/* Errno values */
#define PEBADF          9       /* Invalid file descriptor */
#define PENOENT         2       /* File not found or path to file not found */
#define PEMFILE         24      /* No file descriptors available (too many files open) */
#define PEEXIST         17      /* Exclusive access requested but file already exists. */
#define PEACCES         13      /* Attempt to open a read only file or a special (directory) */
#define PEINVAL         22      /* Seek to negative file pointer attempted. */
#define PENOSPC         28      /* Write failed. Presumably because of no space */
#define PESHARE         30      /* Open failed do to sharing */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -