www.pudn.com > SMSC USB2.0.zip > dev.h


/*============================================================================ 
  ____________________________________________________________________________ 
                                ______________________________________________ 
   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. 
  ____________________________________________________________________________ 
  ____________________________________________________________________________ 
 
  dev.h - the device manager implementarion 
  ____________________________________________________________________________ 
 
  comments tbd 
  ____________________________________________________________________________ 
 
  Revision History 
  Date      Who  Comment 
  ________  ___  _____________________________________________________________ 
  04/08/02  tbh  initial version 
  05/09/02  cds  added _dev_soft_reset() macro 
  06/21/02  cds  added _nand_pwr_on() and _nand_pwr_off() macros 
  08/09/02  cds  added attribute flag variables, default constants, and 
                 our very own first usable attribute flag on the 211:  attr_lo_sm_timing 
                 to force nand chips to use the slower smart media spec compatible timing. 
  08/13/02  tbh  moved g_dev_attr_xx to xdata 
  08/27/02  cds  added attribute bit to force nand hd to enum as removable media always. 
  09/06/02  ds   added references to the new variables used for the 'custom' blinking light code. 
  09/06/02  ds   added an attribute bit to indicate the behavior of gpio5 
  09/07/02  tbh  added the force iSerial to zero attrib bit 
  09/12/02  tbh  moved g_post_access_blink_secs and g_blink_interval into 
                 data space.  this should prevent access to xdata during MS and SD 
                 transfers.  had to convert all strncpy's into memcpy's. 
                 (MS hdw bug: corrupts data if xdata accessed during xfer. 
                 same happens on SD?  cannot prove or disprove yet...) 
  09/20/02  tbh  added prototypes for dev_indicate_bus_speed, dev_turn_off_activity_indicator, 
                 dev_gpio_power_down, dev_toggle_activity_indicator 
  10/01/02  ds   Moved the index definitions for nvstore, to dev.h so that it could be accessed from 
                 other files. Also added definition k_ix_secure_mem   
  10/07/02  ds   Added k_ix_inq_pid_hdr and k_ix_inq_vid to support custom fields in the Inquiry data                                
  10/15/02  cds  - added k_sz_inq_pid_hdr and k_sz_inq_vid to denote size of the fields 
                 - added globals g_inq_vid, g_inq_pid_hdr to hold contents to be used during inquiry 
                 - added attribute bit 4:  1, use IMIDS/IPIDS fields, 0, default, build inq vid/pid from mfr/prd strings 
  10/17/02  cds  - project-wide lun data & vtbl paging to reduce code space.            
                 - removed g_active_media from _lun_data, _lun_() virtual functions     
                 - added _lun_data_rd() and _lun_data_wr() macros to bypass lun paging  
                 - added lun_set_active(log_lun) function to switch luns                
  10/30/02  ds   Added a new attribute bit that specifies state of the activity-led on Suspend               
============================================================================*/ 
 
//------------------------------------------------------------------------------ 
//------------------------------------------------------------------------------ 
#define _cf_pwr_on()                                                           \ 
{                                                                              \ 
  _mcu_register_set_bits(x_fmc_out_ctl, kbm_fmc_out_ctl_cf);                   \ 
  _mcu_register_clr_bits(x_gpiob_out, kbm_gpio9);                              \ 
} 
 
//------------------------------------------------------------------------------ 
//------------------------------------------------------------------------------ 
#define _cf_pwr_off()                                                          \ 
{                                                                              \ 
  _mcu_register_clr_bits(x_fmc_out_ctl, kbm_fmc_out_ctl_cf);                   \ 
  _mcu_register_set_bits(x_gpiob_out, kbm_gpio9);                              \ 
} 
 
//------------------------------------------------------------------------------ 
//------------------------------------------------------------------------------ 
#define _ms_pwr_on()                                                           \ 
{                                                                              \ 
  _mcu_register_set_bits(x_fmc_out_ctl, kbm_fmc_out_ctl_ms);                   \ 
  _mcu_register_clr_bits(x_gpiob_out, kbm_gpio8);                              \ 
} 
 
//------------------------------------------------------------------------------ 
//------------------------------------------------------------------------------ 
#define _ms_pwr_off()                                                          \ 
{                                                                              \ 
  _mcu_register_clr_bits(x_fmc_out_ctl, kbm_fmc_out_ctl_ms);                   \ 
  _mcu_register_set_bits(x_gpiob_out, kbm_gpio8);                              \ 
} 
 
//------------------------------------------------------------------------------ 
//------------------------------------------------------------------------------ 
#define _sm_pwr_on()                                                           \ 
{                                                                              \ 
  _mcu_register_set_bits(x_fmc_out_ctl, kbm_fmc_out_ctl_sm);                   \ 
  _mcu_register_clr_bits(x_gpiob_out, kbm_gpio10);                             \ 
} 
 
//------------------------------------------------------------------------------ 
//------------------------------------------------------------------------------ 
#define _sm_pwr_off()                                                          \ 
{                                                                              \ 
  _mcu_register_clr_bits(x_fmc_out_ctl, kbm_fmc_out_ctl_sm);                   \ 
  _mcu_register_set_bits(x_gpiob_out, kbm_gpio10);                             \ 
} 
 
//------------------------------------------------------------------------------ 
//------------------------------------------------------------------------------ 
#define _sd_pwr_on()                                                           \ 
{                                                                              \ 
  _mcu_register_set_bits(x_fmc_out_ctl, kbm_fmc_out_ctl_sd);                   \ 
  _mcu_register_clr_bits(x_gpiob_out, kbm_gpio11);                             \ 
} 
 
//------------------------------------------------------------------------------ 
//------------------------------------------------------------------------------ 
#define _sd_pwr_off()                                                          \ 
{                                                                              \ 
  _mcu_register_clr_bits(x_fmc_out_ctl, kbm_fmc_out_ctl_sd);                   \ 
  _mcu_register_set_bits(x_gpiob_out, kbm_gpio11);                             \ 
} 
 
//------------------------------------------------------------------------------ 
//------------------------------------------------------------------------------ 
#define _nand_pwr_on()                                                         \ 
{                                                                              \ 
  _mcu_register_set_bits(x_fmc_out_ctl, kbm_fmc_out_ctl_sm);                   \ 
  _mcu_register_clr_bits(x_gpiob_out, kbm_gpio10);                             \ 
} 
 
//------------------------------------------------------------------------------ 
//------------------------------------------------------------------------------ 
#define _nand_pwr_off()                                                        \ 
{                                                                              \ 
  _mcu_register_clr_bits(x_fmc_out_ctl, kbm_fmc_out_ctl_sm);                   \ 
  _mcu_register_set_bits(x_gpiob_out, kbm_gpio10);                             \ 
} 
 
//------------------------------------------------------------------------------ 
//------------------------------------------------------------------------------ 
#define _inserted(__lun) _lun_data_wr((__lun), media, (_lun_data_rd((__lun), media)|(kbm_lun_media_present|kbm_lun_media_unknown|kbm_lun_media_changed))) 
 
//------------------------------------------------------------------------------ 
//------------------------------------------------------------------------------ 
#define _ejected(__lun) _lun_data_wr((__lun), media, (_lun_data_rd((__lun),media)&~(kbm_lun_media_present|kbm_lun_media_unknown|kbm_lun_media_changed))) 
 
//------------------------------------------------------------------------------ 
//------------------------------------------------------------------------------ 
#define _sd_ejected()                                                          \ 
{ TRACE0(446, dev, 0, "_sd_ejected()");                                         \ 
  _lun_data_wr(k_lun_sd, media, (_lun_data_rd(k_lun_sd,media)&~(kbm_lun_media_present|kbm_lun_media_unknown|kbm_lun_media_changed)));\ 
  _mcu_register_clr_bits(x_crd_ps, kbm_crd_ps_sd);                             \ 
} 
 
//------------------------------------------------------------------------------ 
//------------------------------------------------------------------------------ 
#define _mmc_ejected()                                                         \ 
{ TRACE0(447, dev, 0, "_mmc_ejected()");                                        \ 
  _lun_data_wr(k_lun_mmc, media, (_lun_data_rd(k_lun_mmc, media)&~(kbm_lun_media_present|kbm_lun_media_unknown|kbm_lun_media_changed)));\ 
  _mcu_register_clr_bits(x_crd_ps, kbm_crd_ps_mmc);                            \ 
} 
 
//------------------------------------------------------------------------------ 
//------------------------------------------------------------------------------ 
#define _sd_inserted_ejected()                                                 \ 
{ TRACE0(448, dev, 0, "_sd_inserted_ejected()");                                \ 
  _lun_data_wr(k_lun_sd, media, (_lun_data_rd(k_lun_sd, media)|(kbm_lun_media_present|kbm_lun_media_unknown|kbm_lun_media_changed)));\ 
  _mcu_register_clr_bits(x_crd_ps, kbm_crd_ps_sd);                             \ 
  _lun_data_wr(k_lun_mmc, media, (_lun_data_rd(k_lun_mmc, media)|(kbm_lun_media_present|kbm_lun_media_unknown|kbm_lun_media_changed)));\ 
  _mcu_register_clr_bits(x_crd_ps, kbm_crd_ps_mmc);                            \ 
} 
 
//------------------------------------------------------------------------------ 
//------------------------------------------------------------------------------ 
#define _dev_soft_reset()                                                 \ 
{                                                                         \ 
  TRACE0(449, dev, 0, "_dev_soft_reset()");                                \ 
  /* XBYTE[0x3F22] |= 0x01; */                                           \ 
  _mcu_register_set_bits(x_util_config, 0x40);                           \ 
} 
 
//------------------------------------------------------------------------------ 
//------------------------------------------------------------------------------ 
#define _dev_sense_vbus() ((_mcu_register_rd(x_gpioa_in) & kbm_gpio3) ? k_true : k_false) 
 
//------------------------------------------------------------------------------ 
// prototypes 
void dev_indicate_bus_speed(void) reentrant; 
void dev_gpio_power_down(void) reentrant; 
void dev_turn_off_activity_indicator(void) reentrant; 
void dev_toggle_activity_indicator(void) reentrant; 
uint8 dev_rd_most_recent_config(void) reentrant; 
void dev_wr_most_recent_config(uint8 cfg) reentrant; 
 
//------------------------------------------------------------------------------ 
// attributes 
extern xdata uint8 g_dev_attr_lo; 
// extern xdata uint8 g_dev_attr_hl; 
// extern xdata uint8 g_dev_attr_lh; 
// extern xdata uint8 g_dev_attr_hi; 
 
// lsw lsb bit 0: sm_timing 
//            1 - nand flash chips will use the slower, smart media compatible r/w cycle time 
//  (default) 0 - nand flash chips will use the faster 50ns r/w cycle timing for chips that are capable 
#define kbm_attr_lo_sm_timing           0x01 
 
// lsw lsb bit 1: enum_hd_as_rm 
//            1 - nand flash hard drives to always enumerate as removable media.  */ 
//  (default) 0 - nand flash hd's enum as removable when write protected, as fixed when not-write protected */ 
#define kbm_attr_lo_hd_as_rm            0x02 
 
// lsw lsb bit 2: Behavior of gpio5 
//            1 - Use the bit as a sd insert indicator 
//  (default) 0 - Use as a HS indicator 
#define kbm_attr_lo_gpio5_as_sd_insert  0x04 
 
// lsw lsb bit 3: Behavior of iSerial byte in device descriptor 
//            1 - Always report iSerial as zero in the device descriptor 
//  (default) 0 - Report non-zero iSerial in device descriptor if serial number is valid 
#define kbm_attr_lo_force_zero_iserial  0x08 
 
// lsw lsb bit 4: Specifies which fields to use when building inquiry string 
//            1 - Use IMIDS (offset 228, size 8) and IPIDS (offset 236, size 5) for inquiry 
//  (default) 0 - Build IMIDS and IPIDS from MFR (offset 94, size 60) and PRD (offset 94, size 60) by converting from UNICODE->printable ascii. 
#define kbm_attr_lo_use_inq_mfr_prd_ids 0x10 
 
// lsw lsb bit 5: Specifies state of the activity led on Suspend 
//            1 - The gpio for the activity led is set to high on a suspend, irrespective of the idle state. 
//  (default) 0 - The gpio for the activity led is set to low on a suspend, irrespective of the idle state. 
#define kbm_attr_lo_activity_led_gpio_hi_on_spd 0x20 
 
 
/* default to use fastest mode available.  Reads/Writes to the nand */ 
/* nvstore use PIO, not FMDU, so we'll always be able to use WriteEE to */ 
/* force nand to use Smart Media compatible timings should there be a problem. */ 
#define k_attr_lo_default 0x00 
#define k_attr_hl_default 0x00 
#define k_attr_lh_default 0x00 
#define k_attr_hi_default 0x00 
 
 
//------------------------------------------------------------------------------ 
//------------------------------------------------------------------------------ 
// nvstore parameter indexes and sizes 
 
// usb/mass storage serial number string descriptor 
#define k_ix_ser          0 
#define k_sz_ser          26 
 
// usb vid/pid 
#define k_ix_vid_lo       26 
#define k_ix_vid_hi       27 
#define k_ix_pid_lo       28 
#define k_ix_pid_hi       29 
 
// usb language string descriptor 
#define k_ix_lng          30 
#define k_sz_lng          4 
 
// usb manufacturer string descriptor 
#define k_ix_mfr          34 
#define k_sz_mfr          60 
 
// usb product string descriptor 
#define k_ix_prd          94 
#define k_sz_prd          60 
 
#define k_ix_attr_lo      154 
#define k_ix_attr_hl      155 
#define k_ix_attr_lh      156 
#define k_ix_attr_hi      157 
 
#define k_ix_password     158 
#define k_sz_password     14 
 
//Locations for the cfg dscr mods 
#define k_ix_bmattrib     172 
#define k_ix_maxpwr       173 
 
//locations for the blinking media access lights 
#define k_ix_blink_interval      174 
#define k_ix_blinks_after_access 175 
 
#define k_sz_lun_id       7 
#define k_ix_lun0_id      176 
#define k_ix_lun1_id      183 
#define k_ix_lun2_id      190 
#define k_ix_lun3_id      197 
 
//vendor specific secure memory 
#define k_ix_secure_mem   204 
 
//vendor info for inquiry 
#define k_ix_inq_vid      228 
#define k_sz_inq_vid      8 
 
//product info header for inquiry 
#define k_ix_inq_pid_hdr  236  
#define k_sz_inq_pid_hdr  5 
 
// 241<->251 reserved 
 
// structure signature index 
#define k_ix_sig_hi       252 
#define k_ix_sig_lh       253 
#define k_ix_sig_hl       254 
#define k_ix_sig_lo       255 
 
// ata0 format signature 
#define k_sig_ata0_hi     0x61 // 'a' 
#define k_sig_ata0_lh     0x74 // 't' 
#define k_sig_ata0_hl     0x61 // 'a' 
#define k_sig_ata0_lo     0x30 // '0' 
 
// ata1 format signature 
#define k_sig_ata1_hi     0x61 // 'a' 
#define k_sig_ata1_lh     0x74 // 't' 
#define k_sig_ata1_hl     0x61 // 'a' 
#define k_sig_ata1_lo     0x31 // '1' 
//------------------------------------------------------------------------------ 
//------------------------------------------------------------------------------ 
 
 
extern xdata uint8 g_led_state; 
extern uint8 g_blink_interval; 
extern bit g_activity_led_idle_bright; 
extern uint8 g_post_access_blink_secs; 
extern xdata uint8 g_nvstore_post_access_blink_secs; 
extern xdata uint8 g_inq_vid[k_sz_inq_vid]; 
extern xdata uint8 g_inq_pid_hdr[k_sz_inq_pid_hdr]; 
extern void nvstore_write_enable() reentrant; 
extern void nvstore_write_disable() reentrant; 
extern void nvstore_write(uint8 addr, uint8 value) reentrant; 
extern uint8 nvstore_read(uint8 addr) reentrant; 
extern void dev_toggle_led(void) reentrant; 
 
//---eof------------------------------------------------------------------------