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

📄 device_new.c

📁 <B>SMSC USB2.0 Flash硬盘驱动源码</B>
💻 C
📖 第 1 页 / 共 5 页
字号:

/*============================================================================
  ____________________________________________________________________________
                                ______________________________________________
   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.
  ____________________________________________________________________________
  ____________________________________________________________________________

  device.c - the device manager implementarion
  ____________________________________________________________________________

  comments tbd
  ____________________________________________________________________________

  Revision History
  Date      Who  Comment
  ________  ___  _____________________________________________________________
  05/31/00  tbh  initial version
  09/04/01  tbh  auto version the product string.
                 add reserved space to work with dfu on the 201
  09/05/01  tbh  changed set_config arg to value instead of reference since cannot
                 use address of sfr.  (building with registers as sfr instead
                 of xdata reveled this compilation issue)
  09/##/01  tbh  optimized for speed
  11/07/01  rcc  added phy #define below to choose your klsi phy rev see dev_intitilize
  11/26/01  cds  fixed dev_source_eeprom to return correct string length in
                 response to a 2-byte get_descriptor (string) request.
  11/28/01  tbh  modified eeprom source/sink to work with writeee.exe.
  12/01/01  tbh  added all 210 interrupts.  added code to probe cards.
  01/15/02  cds  fixed version string generation to use two digits when the
                 version constant is >= 0x10, not > 0x10.
  02/26/02  tbh  added logical to physical lun mapping
                 changed strcpy to strncpy for safety
  03/11/02  tbh  added usage of in dev_intr bit g_force_media_changed.  then removed it.
  03/12/02  tbh  changed card establish to media change handler.
  03/28/02  tbh  make sure phy lun for mmc is init'd on power up.
  04/01/02  ds   Enabled proper handling of the k_irq_fmc_err_sd_blk_ovrun intr, instead of handling it in
                 case k_irq_fmc_err
  04/01/02  tbh  only init logical luns < k_max_log_lun
  04/15/02  tbh  remembed previous configuration so on usb reset can check to
                 see if had been configured
  04/18/02  cds  added thread_set_sync(g_ix_dev_thread, kbm_sync_fmc_blk) to the
                 dev_intr handlers which intercept the smart media ecc detection bits so that
                 it can stop the fmc_xfer and allow a resume.
  04/24/02  tbh  added k_dvd_inq_devid, upgraded eeprom support to use new 201 scheme
  04/25/02  tbh  top level device thread now does not attempt to scan card slots
                 for media change until after the device has fully enumerated
                 through set-config(1) (which results in a dev_pwr_up()) so that
                 the dev_pwr_up() does not cause re-initialization of all of the
                 cards.  this fixes the bug with wp-sd card on pwr on, and speeds
                 up enumeration.
  06/19/02  tbh  the mscbot dfa has been replaced with a high priority thread.
                 so the device thread had to be rewritten essentially from the
                 ground up to accomodate it.
                 added handler for k_irq_fmc_sdc_flash_prg_err,
                 enhanced handler for k_irq_fmc_sdc_crc_err
  06/20/02  cds  added nand hd lun initialization, if it is included in the build options.
  06/20/02  tbh  fixed a problem of powering on with no media and havinf the host
                 try to do a read even avter seeing a no-media sense code.
  06/21/02  tbh  don't probe cards on an inquiry command, to make working
                 when plugin with 4 cards laded on MacOS X 10.1.5
============================================================================*/
#define __device_dot_c__
#include "project.h"
#include "dev.h"

//------------------------------------------------------------------------------
// required global constant to communicate desired settings to minimos
#ifdef k_pfm_6126
code t_dev_attribute_mask k_dev_attributes = kbm_hub_enabled;
#else
code t_dev_attribute_mask k_dev_attributes = kbm_none;
#endif

//------------------------------------------------------------------------------
// device id to avoid use of driver with roque devices
static code uint8 _devid[] = {'C','o','p','y','r','i','g','h','t',' ','(','C',')',' ','2','0','0','2',' ','S','M','S','C',0};

//------------------------------------------------------------------------------
// offset into the device descriptor for sundry items
#define k_ix_dev_vid_lo  8
#define k_ix_dev_vid_hi  9
#define k_ix_dev_pid_lo  10
#define k_ix_dev_pid_hi  11
#define k_ix_dev_ver_lo  12
#define k_ix_dev_ver_hi  13

//------------------------------------------------------------------------------
// vendor id and product id (SMSC -> 0106 dec = 0424 hex)
#define k_vendorhi         0x04  // vendor id hi
#define k_vendorlo         0x24  // vendor id lo
#define k_dev_producthi    0x20  // product id hi
// #define k_dev_productlo    0xFC  // product id lo
#define k_dev_productlo    0xCD  // product id lo

//------------------------------------------------------------------------------
// version descriptor (not a usb thing, its used by the smsc romset utility)
// $$$ note that romset as is wont work on this because there are now multiple
// device and configuration descriptors.  romset needs to be updated.
uint8 code g_version[] = {k_vendorhi, k_vendorlo, k_dev_producthi, k_dev_productlo, kbcd_dev_version_major, kbcd_dev_version_minor};

//------------------------------------------------------------------------------
// this app is downloadable via dfu, so we must reserve a hole in code space
// to make dfu work properly on the 201...
#if !defined(k_ram_isr) && !defined(k_support_otprom)
uint8 code reserved[768] _at_ 0x0400;
#endif

//------------------------------------------------------------------------------
// string descriptors (in a form that the smsc romset utility can use)
#define _hi_digit(b) ((uint8) (((uint8)(b>>4)&0x0F) + (uint8)'0')),0
#define _lo_digit(b) ((uint8) (((uint8)(b   )&0x0F) + (uint8)'0')),0
uint8 code g_str_lng[4] = {4, 3, 0x09, 0x04};  // (English lo 0x09, hi 0x04)
uint8 code g_str_mfg[17][2] = {10, 3, "S", "M", "S", "C"};
uint8 code g_str_prd[63][2] =
{
  62, 3,
  "F", "l", "a", "s", "h",
  " ", "M", "e", "d", "i",
  "a", " ", "C", "o", "n",
  "t", "r", "o", "l", "l",
  "e", "r", " ",
#if (kbcd_dev_version_major>=0x10)
  _hi_digit(kbcd_dev_version_major),
#endif
  _lo_digit(kbcd_dev_version_major), ".",

#if (kbcd_dev_version_minor>=0x10)
  _hi_digit(kbcd_dev_version_minor),
#endif
  _lo_digit(kbcd_dev_version_minor), ".",

#if (kbcd_dev_version_external_change>=0x10)
  _hi_digit(kbcd_dev_version_external_change),
#endif
  _lo_digit(kbcd_dev_version_external_change), ".",

#if (kbcd_dev_version_internal_change>=0x10)
  _hi_digit(kbcd_dev_version_internal_change),
#endif
  _lo_digit(kbcd_dev_version_internal_change)
};
uint8 code g_str_ser[41][2] = {64, 3, " "};
uint8 code *code g_str_dscr[k_dev_max_string] = {g_str_lng, g_str_mfg, g_str_prd, g_str_ser};

//------------------------------------------------------------------------------
// string descriptor indicies
#define k_dev_idx_str_dscr_lng 0
#define k_dev_idx_str_dscr_mfg 1
#define k_dev_idx_str_dscr_prd 2
#define k_dev_idx_str_dscr_ser 3

//------------------------------------------------------------------------------
// device descriptor
//------------------------------------------------------------------------------
// full speed device descriptor
uint8 code g_fs_dev_dscr[] =
{
  k_usb_devdscrsz,                // length of descriptor in bytes
  k_usb_dscr_typ_device,          // descriptor type: device
  0x10,                           // usb version lo
  0x01,                           // usb version hi
  0x00,                           // device class: see interfaces
  0x00,                           // subclass:  see interfaces
  0x00,                           // protocol:  see interfaces
  k_maxpktsz,                     // ndp 0 max packet size (8,16,32,64)
  k_vendorlo,                     // vendor lo
  k_vendorhi,                     // vendor hi
  k_dev_productlo,                // product lo
  k_dev_producthi,                // product hi
  kbcd_dev_version_minor,         // device release lo
  kbcd_dev_version_major,         // device release hi
  k_dev_idx_str_dscr_mfg,         // manufacturer string index
  k_dev_idx_str_dscr_prd,         // product string index
  0,                              // serial string index
  k_dev_max_configuration         // number of configurations
};
// full speed device descriptor with serial number - cds
uint8 code g_fs_dev_dscr_w_ser[] =
{
  k_usb_devdscrsz,                // length of descriptor in bytes
  k_usb_dscr_typ_device,          // descriptor type: device
  0x10,                           // usb version lo
  0x01,                           // usb version hi
  0x00,                           // device class: see interfaces
  0x00,                           // subclass:  see interfaces
  0x00,                           // protocol:  see interfaces
  k_maxpktsz,                     // ndp 0 max packet size (8,16,32,64)
  k_vendorlo,                     // vendor lo
  k_vendorhi,                     // vendor hi
  k_dev_productlo,                // product lo
  k_dev_producthi,                // product hi
  kbcd_dev_version_minor,         // device release lo
  kbcd_dev_version_major,         // device release hi
  k_dev_idx_str_dscr_mfg,         // manufacturer string index
  k_dev_idx_str_dscr_prd,         // product string index
  k_dev_idx_str_dscr_ser,         // cds - serial string index
  k_dev_max_configuration         // number of configurations
};

//------------------------------------------------------------------------------
// high speed device descriptor
uint8 code g_hs_dev_dscr[] =
{
  k_usb_devdscrsz,                // length of descriptor in bytes
  k_usb_dscr_typ_device,          // descriptor type: device
  0x00,                           // usb version lo
  0x02,                           // usb version hi
  0x00,                           // device class: see interfaces
  0x00,                           // subclass:  see interfaces
  0x00,                           // protocol:  see interfaces
  k_maxpktsz,                     // ndp 0 max packet size (8,16,32,64)
  k_vendorlo,                     // vendor lo
  k_vendorhi,                     // vendor hi
  k_dev_productlo,                // product lo
  k_dev_producthi,                // product hi
  kbcd_dev_version_minor,         // device release lo
  kbcd_dev_version_major,         // device release hi
  k_dev_idx_str_dscr_mfg,         // manufacturer string index
  k_dev_idx_str_dscr_prd,         // product string index
  0,                              // serial string index
  k_dev_max_configuration         // number of configurations
};
// high speed device descriptor with serial number - cds
uint8 code g_hs_dev_dscr_w_ser[] =
{
  k_usb_devdscrsz,                // length of descriptor in bytes
  k_usb_dscr_typ_device,          // descriptor type: device
  0x00,                           // usb version lo
  0x02,                           // usb version hi
  0x00,                           // device class: see interfaces
  0x00,                           // subclass:  see interfaces
  0x00,                           // protocol:  see interfaces
  k_maxpktsz,                     // ndp 0 max packet size (8,16,32,64)
  k_vendorlo,                     // vendor lo
  k_vendorhi,                     // vendor hi
  k_dev_productlo,                // product lo
  k_dev_producthi,                // product hi
  kbcd_dev_version_minor,         // device release lo
  kbcd_dev_version_major,         // device release hi
  k_dev_idx_str_dscr_mfg,         // manufacturer string index
  k_dev_idx_str_dscr_prd,         // product string index
  k_dev_idx_str_dscr_ser,         // cds - serial string index
  k_dev_max_configuration         // number of configurations
};

//------------------------------------------------------------------------------
// device qualifier descriptor
//------------------------------------------------------------------------------
// full speed device qualifier descriptor
uint8 code g_fs_devqual_dscr[] =
{
  k_usb_devqualdscrsz,            // length of descriptor in bytes
  k_usb_dscr_typ_devqual,         // descriptor type: device qualifier
  0x00,                           // usb version lo
  0x02,                           // usb version hi
  0x00,                           // device class: see interfaces
  0x00,                           // subclass:  see interfaces
  0x00,                           // protocol:  see interfaces
  k_maxpktsz,                     // ndp 0 max packet size, other speed
  k_dev_max_configuration,        // number of other speed configurations
  0                               // reserved
};

//------------------------------------------------------------------------------
// high speed device qualifier descriptor
uint8 code g_hs_devqual_dscr[] =
{
  k_usb_devqualdscrsz,            // length of descriptor in bytes
  k_usb_dscr_typ_devqual,         // descriptor type: device qualifier
  0x00,                           // usb version lo
  0x02,                           // usb version hi
  0x00,                           // device class: see interfaces
  0x00,                           // subclass:  see interfaces
  0x00,                           // protocol:  see interfaces
  k_maxpktsz,                     // ndp 0 max packet size, other speed
  k_dev_max_configuration,        // number of other speed configurations
  0                               // reserved
};

//------------------------------------------------------------------------------
// configuration descriptor
//------------------------------------------------------------------------------
// full speed configuration descriptor
uint8 code g_fs_cfg_dscr[] =
{
  k_usb_cfgdscrsz,                // length of descriptor in bytes
  k_usb_dscr_typ_config,          // descriptor type: configuration
  k_usb_cfgdscrsz +
  k_usb_ifcdscrsz +
  k_usb_ndpdscrsz +
  k_usb_ndpdscrsz,                // total length lo
  0,                              // total length hi
  1,                              // number of interfaces   2 to accomodate the DFU
  0x01,                           // configuration value
  0x00,                           // index of string descriptor
  0xC0,                           // attributes: self powered, no remote wakeup
  0x01,                           // _max power: 2ma
  // interface descriptor: BOT mass storage
  k_usb_ifcdscrsz,                // length of descriptor in bytes
  k_usb_dscr_typ_interface,       // descriptor type: interface
  0,                              // interface number

⌨️ 快捷键说明

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