/******************************************************************************/
/*                                                                            */
/*  Copyright (C), 1995-2007, SanDisk IL Ltd. All rights reserved.            */
/*                                                                            */
/*  Redistribution and use in source and binary forms, with or without        */
/*  modification, are permitted provided that the following conditions are    */
/*  met:                                                                      */
/*  1. Redistributions of source code must retain the above copyright notice, */
/*     this list of conditions and the following disclaimer.                  */
/*  2. Redistributions in binary form must reproduce the above copyright      */
/*     notice, this list of conditions and the following disclaimer in the    */
/*     documentation and/or other materials provided with the distribution.   */
/*  3. Neither the name of SanDisk IL nor the names of its contributors may be*/
/*     used to endorse or promote products derived from this software without */
/*     specific prior written permission.                                     */
/*                                                                            */
/*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       */
/*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED */
/*  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR             */
/*  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT      */
/*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,     */
/*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED  */
/*  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR    */
/*  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    */
/*  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      */
/*  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        */
/*  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              */
/*                                                                            */
/*  NOTWITHSTANDING ANYTHING STATED TO THE CONTRARY, SANDISK'S TOTAL LIABILITY*/
/*  ARISING OUT OF OR RELATED TO THE SOFTWARE OR ANY SUPPORT SERVICES         */
/*  PROVIDED WITH RESPECT THERETO SHALL NOT EXCEED $100.                      */
/*                                                                            */
/*  The laws of the State of California, United States of America, exclusive  */
/*  of conflict-of-laws provisions, shall govern this license in all respects.*/
/*  The the federal or state courts of competent jurisdiction in the State    */ 
/*  of California shall have exclusive jurisdiction with respect to all       */
/*  actions commenced in relation to the software. Licensee agrees not        */ 
/*  to export or re-export, directly or indirectly any technical data         */ 
/*  acquired from SanDisk or any products utilizing such data in violation    */
/*  of applicable export laws and regulations.                                */
/*                                                                            */
/******************************************************************************/
/*
 * $Log:   V:/PVCSDB/DiskOnChip/archives/DocDriver/TrueFFS BD/src/defs.h-arc  $
 * 
 *    Rev 1.6   Oct 22 2007 11:34:48   einat.avidan
 * update copyrights header
 * 
 *    Rev 1.5   Oct 11 2007 18:47:46   Einat.Avidan
 * remove unused or duplicated definitions
 * 
 *    Rev 1.4   Jul 01 2007 13:47:28   einat.avidan
 * bug fix: SCR 2964 compilation flag FL_VERIFY_WRITE should exclude \ include code for write verification
 * 
 *    Rev 1.3   Oct 09 2006 14:05:18   yaniv.iarovici
 * Removed legacy devices related code and definitions
 * 
 *    Rev 1.2   Sep 11 2006 13:45:12   yaniv.iarovici
 * Legal header added
 * 
 *    Rev 1.1   Aug 22 2006 13:22:40   Yaniv.Iarovici
 * 1) Remove decleration fo 'void flInitGlobalVars(void)'
 * 2) Add 'extern "c"' on:
 * 	- flIdentifyFlash() external definition
 * 	- flHandleConversionTable[] external definition
 * 	- _flInit() definition
 * 
 *    Rev 1.0   Aug 08 2006 15:47:24   Polina.Marimont
 * Initial revision.
 */

#ifndef _DEFS_H
#define _DEFS_H


/*=============================================================*/
/* from flsocket.h */
#include "flbuffer.h"

#define ATTRIBUTE_SPACE_MAPPED   0x8000
#define UNDEFINED_MAPPING        0x7fff


typedef enum {PowerOff, PowerGoingOff, PowerOn} PowerState;

extern FLByte noOfSockets;    /* No. of drives actually registered */

typedef struct tSocket FLSocket;
/*=============================================================*/

/*=============================================================*/
/* from _flsoc.h */
struct tSocket {
  unsigned        volNo;         /* Volume no. of socket */

  PowerState      DPDState;      /* Actual DPD state */
  FLBoolean       remapped;      /* set to TRUE whenever the socket window is moved */

  void            (*powerOnCallback)(void *flash); /* Notification routine for Vcc on */
  void *          flash;         /* Flash object for callback */

  struct {                       /* Window state                     */
    unsigned int  baseAddress;   /* Physical base as a 4K page       */
    unsigned int  currentPage;   /* Our current window page mapping  */
    void FAR0 *   base;          /* Pointer to window base           */
    FLSDword      size;          /* Window size (must by power of 2) */
    unsigned      speed;         /* in nsec.                         */
    unsigned      busWidth;      /* 8 or 16 bits                     */
  } window;
  FLBoolean (*cardDetected)(FLSocket * pVol);
  void (*VccOn)(FLSocket * pVol);
  void (*VccOff)(FLSocket * pVol);
  FLStatus (*initSocket)(FLSocket * pVol);
  void (*setWindow)(FLSocket * pVol);
  void (*setMappingContext)(FLSocket * pVol, unsigned page);
  FLBoolean (*getAndClearCardChangeIndicator)(FLSocket * pVol);
  FLBoolean (*writeProtected)(FLSocket * pVol);
  void (*updateSocketParams)(FLSocket * pVol, void FAR1 *params);
#ifdef FL_EXIT
  void (*freeSocket)(FLSocket * pVol);
#endif
};


/* See interface documentation of functions in socket.c */

extern FLStatus updateSocketParameters(FLSocket *, void FAR1 *);


extern FLSocket* flSocketOf(unsigned volNo);


/*=============================================================*/

/*=============================================================*/
/* from flflash.h */

/* Some useful types for mapped Flash locations */

typedef volatile FLByte FAR0 * FlashPTR;
typedef volatile unsigned short int FAR0 * FlashWPTR;
typedef volatile FLDword FAR0 * FlashDPTR;
typedef FLWord FlashType;        /* JEDEC id */
typedef volatile FLByte FAR0* NDOC2window;

typedef FLByte Reg8bitType;
typedef FLWord Reg16bitType;


/* Media types */
#define H3_TYPE                   15

/* protection specific defintions */
#define PROTECTION_KEY_LENGTH    8 /* Size of protection key in bytes    */  
#define DEFAULT_KEY              "00000000"


/****************************/
/*   Special services API   */
/****************************/


/* Flash array identification structure */
typedef struct tFlash FLFlash;                /* Forward definition */

/*=============================================================*/


/*=============================================================*/
/* from _flflash.h */

struct tFlash {
  FLBoolean		wasIdentified;
  FlashType		type;                   
  FlashType		subType;
  FLByte		mediaType;              
  FLDword		busAccessType;            
  FLByte      if_cfg;  
  FLByte      bBusType;          
  FLWord      flags;             
  void *    mtdVars;             
  FLSocket * socket;             
  NDOC2window win;               
  void (*setPowerOnCallback)(FLFlash *);
  FLStatus (*flashRead)(FLFlash *);
  FLStatus (*setCallBack)(FLFlash *);
  FLStatus (*dismount)(FLFlash *);
  FLStatus (*prepareForPowerChanges) (FLFlash *,FLByte) ;
  FLStatus (*clearCallBack)(FLFlash *);
  FLStatus (*enterDeepPowerDownMode)(FLFlash *,FLWord state);

#ifndef FL_NO_USE_FUNC
  FLMemWindowSize FAR1* memWindowSize; /* Doc memory window size          */
  FLMemRead       FAR1* memRead;       /* Doc memory read routine         */
  FLMemWrite      FAR1* memWrite;      /* Doc memory write routine        */
  FLMemSet        FAR1* memSet;        /* Doc memory set routine          */
  FLMemRead8bit   FAR1* memRead8bit;   /* Doc memory 8 bit read routine   */
  FLMemWrite8bit  FAR1* memWrite8bit;  /* Doc memory 8 bit write routine  */
  FLMemRead16bit  FAR1* memRead16bit;  /* Doc memory 16 bit read routine  */
  FLMemWrite16bit FAR1* memWrite16bit; /* Doc memory 16 bit write routine */
  FLMemSetGetMode FAR1* memSetGetMode; /* Interleave change event -       */
                                       /* call back to plant new routines */
#endif /* FL_NO_USE_FUNC */
};

#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */

extern TFFS_DLL_API FLFlash * NAMING_CONVENTION flFlashOf(FLByte volNo);

#ifdef __cplusplus
}
#endif /* __cplusplus */

/*=============================================================*/


/*=============================================================*/
/*=== from nandefs.h */

/*=============================================================*/

#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
FLStatus _flInit(void);
void flInitGlobalVars(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */


#endif /*_DEFS_H*/


