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

📄 media.h

📁 <B>SMSC USB2.0 Flash硬盘驱动源码</B>
💻 H
📖 第 1 页 / 共 2 页
字号:
/*============================================================================
  ____________________________________________________________________________
                                ______________________________________________
   SSSS  M   M          CCCC          Standard Microsystems Corporation
  S      MM MM   SSSS  C                    Austin Design Center
   SSS   M M M  S      C                 11000 N. Mopac Expressway
      S  M   M   SSS   C                Stonelake Bldg. 6, Suite 500
  SSSS   M   M      S   CCCC                Austin, Texas 78759
                SSSS            ______________________________________________
  ____________________________________________________________________________

  Copyright(C) 1999, Standard Microsystems Corporation
  All Rights Reserved.

  This program code listing is proprietary to SMSC and may not be copied,
  distributed, or used without a license to do so.  Such license may have
  Limited or Restricted Rights. Please refer to the license for further
  clarification.
  ____________________________________________________________________________

  Notice: The program contained in this listing is a proprietary trade
  secret of SMSC, Hauppauge, New York, and is copyrighted
  under the United States Copyright Act of 1976 as an unpublished work,
  pursuant to Section 104 and Section 408 of Title XVII of the United
  States code. Unauthorized copying, adaption, distribution, use, or
  display is prohibited by this law.
  ____________________________________________________________________________

  Use, duplication, or disclosure by the Government is subject to
  restrictions as set forth in subparagraph(c)(1)(ii) of the Rights
  in Technical Data and Computer Software clause at DFARS 52.227-7013.
  Contractor/Manufacturer is Standard Microsystems Corporation,
  80 Arkay Drive, Hauppauge, New York, 1178-8847.
  ____________________________________________________________________________
  ____________________________________________________________________________

  lun.h - defines the root object for the media class hierarchy

    media
     +-sm_media
     | +-nand_media
     +-ms_media
  ____________________________________________________________________________

  comments tbd
  ____________________________________________________________________________

  Revision History
  Date      Who  Comment
  ________  ___  _____________________________________________________________
  03/01/02  cds  initial version
  04/19/02  cds  added new virtual method "media_resolve_conflict()" to 
                 allow media-specific algorithms for determining which log2phy
                 binding to use. 
  06/21/02  cds  - added nand_media index.
                 - removed obsolete 'nil_media' class definition
  06/27/02  cds  - added new virtual methods media_set_read_addr(), 
                   media_set_write_addr(), and media_set_erase_addr()
                 - added new address variable 'g_addr_page' for media-specific
                   usage.  smart media needs this for ancient 256+8 byte per page.
  07/09/02  cds  _media_data(sectors_per_block) and g_addr_sector 8->16 bit conversion                                      
  07/16/02  cds  added media_nand_2k class to hierarchy
  07/29/02  cds  removed g_media_err_code & constants (left over from smil library)
  07/31/02  cds  - altered the media_data table to be a buffer equal in size to
                   a s_media struct, with one such buffer for each media type.
                 - altered the _media_data() macro to access new global xdata
                   variables to avoid bloated and slow array lookups at run time
                 - added media_set_active() function which should be called when
                   selecting a new media object to use.  This function will ensure
                   that changes made to the global variables are safely stored, 
                   and that the new globals will contain the new media objects' data
  09/04/02  cds  - address name & usage change-over
                    g_addr_sector => g_addr_page,
                    g_addr_page   => g_addr_segment,
                    _media_data(sectors_per_block)  => _media_data(pages_per_block)
                    _media_data(cis_phy_block)      => _media_data(boot_block)
                    _media_data(cis_sector)         => _media_data(boot_sector)
                    (new item)                      => _media_data(segments_per_page)
  09/18/02  cds  added _media_data(options) field, with 3 masks:  
                  kbm_media_data_opts_none, opts_erase_cache, opts_write_cache
  09/22/02  cds  - added erase cache variables to media instance data
  09/23/02  cds  - moved mode sense dfa for fmt dev page from lun to media so that
                   luns w/o the mapper will be able to link
  09/25/02  cds  - added support for erase_flash and report_media_geometry to lun vtable
                 - deleted mode sense dfa
  10/23/02  cds  added e_media_result enumerated type to report copy read/write errors.                 
  10/29/02  cds  added media_block_has_bad_data() virtual function
  11/03/02  cds  added media_is_phyblock_reserved() virtual function to allow media subclasses
                 to "protect" areas on a per-block basis from use by the mapper.
                  
==============================================================================*/
#ifndef __media_dot_h__
#define __media_dot_h__

//------------------------------------------------------------------------------
// class definitions

typedef t_result (code *t_media_entry)(void) reentrant;

//------------------------------------------------------------------------------
// media indices
typedef enum e_media_index
{
  k_ix_media_sm=0,
  k_ix_media_ms,
  k_ix_media_nand,
  k_ix_media_nand_2k,
  k_ix_media_nand_int,
  k_max_media
} t_ix_media ;

//------------------------------------------------------------------------------
// media error codes
typedef enum e_media_result
{
  k_media_success=k_success,
  k_media_error=k_error,
  k_media_copy_error_src,
  k_media_copy_error_dst,
  k_media_error_wp
} t_media_result;

//------------------------------------------------------------------------------
// mapping table typedefs and construction helper macros
typedef uint16 xdata* t_log2phy_map_ref;
typedef uint8  xdata* t_assign_map_ref; 
typedef uint8  xdata* t_erase_cache_ref;

typedef struct s_media
{
  // media parameters
  uint8               num_zones ;
  uint16              physical_blocks_per_zone ;
  uint16              logical_blocks_per_zone ;
  uint16              logical_blocks_per_boot_zone ;
  uint8               pages_per_block ; 
  uint16              bytes_per_page ;

  // mapping parameters
  t_log2phy_map_ref   log2phy_map ; 
  t_assign_map_ref    assign_map ;
  t_erase_cache_ref   erase_cache;
  uint16  assign_zone;
  uint16  assign_start[2];
  uint16  erase_start[2];

  // boot block location (first usable block)
  uint16  boot_block ;  
  uint16  boot_page ;

  // media optional behavior
  uint8   options ;

  // a 1 sector buffer
  t_xdata_ref sector_buffer ;

} t_media_data ;

// active media "page"
extern xdata uint8  g_media_data_num_zones ;
extern xdata uint16 g_media_data_physical_blocks_per_zone ;
extern xdata uint16 g_media_data_logical_blocks_per_zone ;
extern xdata uint16 g_media_data_logical_blocks_per_boot_zone ;
extern xdata uint8  g_media_data_pages_per_block ;
extern xdata uint8  g_media_data_segments_per_page ;
extern xdata t_log2phy_map_ref  g_media_data_log2phy_map ; 
extern xdata t_assign_map_ref   g_media_data_assign_map ;
extern xdata t_erase_cache_ref  g_media_data_erase_cache;
extern xdata uint16 g_media_data_assign_zone;
extern xdata uint16 g_media_data_assign_start[2];
extern xdata uint16 g_media_data_erase_start[2];
extern xdata uint16 g_media_data_boot_block ;  
extern xdata uint16 g_media_data_boot_page ;
extern xdata uint8  g_media_data_options;
extern xdata t_xdata_ref g_media_data_sector_buffer ;

// active media page size
#define k_media_data_sz sizeof(t_media_data)


// a single instance of address information.  it saves a lot of code space to remove
// this from the structure, and serialize media addressing

// mapping address 
extern xdata uint8   g_addr_zone;       // Zone Number
extern xdata uint16  g_addr_page;     // Sector (512byte) Number on Block
extern xdata uint16  g_addr_rd_phy_blk; // physical block for reading sectors
extern xdata uint16  g_addr_wr_phy_blk; // physical block allocated for writing
extern xdata uint16  g_addr_log_blk;    // Logical Block Number of Zone
extern xdata uint8   g_addr_segment;       // tbd - may be used instead of sector in cases where page size & sector size differ

//------------------------------------------------------------------------------
// media options that must be set by the controller & may be used by media, map, or luns
#define kbm_media_data_opt_none        (0x00)
#define kbm_media_data_opt_erase_cache (0x01)
#define kbm_media_data_opt_write_cache (0x02)

//------------------------------------------------------------------------------
// macro to wrap instancing of the lun data
// #define _media_data(__field)             g_media_data[g_active_media].##__field
#define _media_data(__field)  g_media_data_##__field

#define k_media_err_illegal_lba k_error

//+-----------------------------------------------------------------------------
// Name:
//   media_set_active()
//
// Declaration:
//   void media_set_active(uint8 media) reentrant
//
// Purpose:
//
// Arguments:
//
// Return:
//
// Notes:
//
// Since:
//   fmc-1.0
//------------------------------------------------------------------------------
void media_set_active(uint8 media) reentrant ;


//+-----------------------------------------------------------------------------
// Name:
//   media_dump_addr()
//
// Declaration:
//   void media_dump_addr() reentrant
//
// Purpose:
//
// Arguments:
//
// Return:
//
// Notes:
//
// Since:
//   fmc-1.0
//------------------------------------------------------------------------------
void media_dump_addr(void) reentrant;


//+-----------------------------------------------------------------------------
// Name:
//   media_copy_block_head()
//
// Declaration:
//   t_result media_copy_block_head(void) reentrant
//
// Purpose:
//
// Arguments:
//
// Return:
//
// Notes:
//
// Since:
//   fmc-1.0
//------------------------------------------------------------------------------
t_result media_copy_block_head(void) reentrant ;

//+-----------------------------------------------------------------------------
// Name:
//   media_copy_block_tail()
//
// Declaration:
//  static t_result media_copy_block_tail(void) reentrant
//
// Purpose:
//
// Arguments:
//
// Return:
//
// Notes:
//
// Since:
//   fmc-1.0
//------------------------------------------------------------------------------
t_result media_copy_block_tail(void) reentrant ;


//+-----------------------------------------------------------------------------
// Name:
//   media_write_one_sector()
//
// Declaration:
//   t_result sm_media_write_one_sect(uint8 *buf) reentrant
//
// Purpose:
//
// Arguments:
//
// Return:
//
// Notes:
//
// Since:
//   fmc-1.0
//------------------------------------------------------------------------------
t_result media_write_one_sector(uint8 *buf) reentrant ;


// media methods
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------

//+-----------------------------------------------------------------------------
// Name:
//   media_erase_block()
//
// Declaration:
//   t_result media_erase_block(void) reentrant
//
// Purpose:
//
// Arguments:
//
// Return:
//
// Notes:
//
// Since:
//   fmc-1.0
//------------------------------------------------------------------------------
t_result media_erase_block(void) reentrant;     // build sector map 

//+-----------------------------------------------------------------------------
// Name:
//   media_read_sector()
//
// Declaration:
//   t_result media_read_sector(void) reentrant
//
// Purpose:
//
// Arguments:
//
// Return:
//
// Notes:
//
// Since:
//   fmc-1.0
//------------------------------------------------------------------------------
t_result  media_read_sector(void) reentrant ; 

//+-----------------------------------------------------------------------------
// Name:
//   media_write_sector()
//
// Declaration:
//   t_result media_write_sector(void) reentrant
//
// Purpose:
//
// Arguments:
//
// Return:
//
// Notes:
//
// Since:
//   fmc-1.0
//------------------------------------------------------------------------------
t_result  media_write_sector(void) reentrant ;

//+-----------------------------------------------------------------------------
// Name:
//   media_copy_sector()
//
// Declaration:
//   t_result media_copy_sector(void) reentrant
//
// Purpose:
//
// Arguments:
//
// Return:
//
// Notes:
//
// Since:
//   fmc-1.0
//------------------------------------------------------------------------------
t_result media_copy_sector(void) reentrant ;

//+-----------------------------------------------------------------------------
// Name:
//   media_read_cis()
//
// Declaration:
//   t_result media_read_cis(void) reentrant
//
// Purpose:
//
// Arguments:
//
// Return:
//
// Notes:
//
// Since:
//   fmc-1.0
//------------------------------------------------------------------------------
t_result  media_read_cis(void) reentrant ;

//+-----------------------------------------------------------------------------
// Name:
//   media_phy2log()
//
// Declaration:
//   t_result media_phy2log(void) reentrant
//
// Purpose:
//
// Arguments:
//
// Return:
//
// Notes:
//
// Since:
//   fmc-1.0
//------------------------------------------------------------------------------
t_result  media_phy2log(void) reentrant ;

//+-----------------------------------------------------------------------------
// Name:
//   media_bind_log2phy()
//
// Declaration:
//   t_result media_bind_log2phy(void) reentrant
//
// Purpose:
//
// Arguments:
//
// Return:
//
// Notes:
//
// Since:
//   fmc-1.0
//------------------------------------------------------------------------------
t_result  media_bind_log2phy(void) reentrant ;

//+-----------------------------------------------------------------------------
// Name:
//   media_set_phyblock_failed()
//
// Declaration:
//   t_result media_set_phyblock_failed(void) reentrant
//
// Purpose:
//
// Arguments:
//
// Return:
//
// Notes:
//
// Since:
//   fmc-1.0
//------------------------------------------------------------------------------
t_result  media_set_phyblock_failed(void) reentrant ;

//+-----------------------------------------------------------------------------
// Name:
//   media_is_phyblock_ok()
//
// Declaration:
//   t_result media_is_phyblock_ok(void) reentrant
//
// Purpose:
//
// Arguments:

⌨️ 快捷键说明

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