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

📄 device.c

📁 U盘控制器USB97C223的固件代码,对2kPAGE NAND FLASH 有很好的支持.
💻 C
📖 第 1 页 / 共 5 页
字号:
  12/17/02  cds  - protected pwr_XXX fn's w/ #ifdef k_mcu_97223 for now
  12/20/02  rcc  - modified dev_power_up and dev_power_down to turn on and off crystal so that if we are
                   unconfigured we only run from the ring oscillator
  01/03/03  cds  - turned off crystal oscillator after reading/validating nvstore, if using power mgmt
                 - turned crystal oscillator frequency down to 1.875 MHz before switching to ring oscillator
                 - permanently disabled pwr mgmt for 97210
  01/08/03  ds   -Added a new variable for the mcu clk frequency that is read from the nvstore. This is used to
                  set the clk frequency for operating in low power mode.
                 -Removed the code that sets the device to the ring oscillator in low power mode.
                 -Moved the code to set the freq to be done only when power management is enabled.
  01/13/03  ds   Protected the declaration and assignment of g_mcu_clk_freq to be done only for 223.
  03/04/03  cds  - added g_dev_attr_hl to hold new bit for ignoring sm seek_cis failure
                 - removed all parens from return statements (i.e. return(xxx); -> return xxx;
  03/11/03  ds   Implemented the new LUN MUXing scheme, where 1 or more physical luns can be assigned to one logical lun.
                 The typical case but not limited to is having one drive icon with CF and another with the rest of the devices.
                 The physical luns are dynamically assigned to the logical lun based on a lookup table, on detection of that new
                 media. The functions affected are dev_set_lun_cfg()( to do the mappings), dev_validate_nvstore()
                 (to assign the new values from the nvstore, dev_intr() ( dynamically assign the phy luns) and
                 also the handler for the message "Initialize".
  03/14/03  ds   The Max Lun's value in Eeprom was initally only protected from,0xff and 0x00. We decided that we will not
                 have any checks at all as it is not protected from other bad values anyway. But the lastest requirement is
                 that the test for 0xff is needed as some costumers are using this as default. Added the check.
  03/17/03  ds   Handled the special case where an SD Insert interrupt happens on POR. If there is any other, card
                 in the slot then the sync set in the sd interrupt handler, overrides the values set by
                 other media mapped to the same logical lun. This is fixed by a logic in dev_wait_cbw() to not
                 really probe the sd slot even when a kbm_sync_probe_sd is set, given that we know another insert has been detected,
                 in a slot associated with this lun.
  03/21/03  ds   Changed the way the handler for Resume works, to the way it was. Now it is reading the most_recent_config
                 value, to decide if it needs to power_up the device.Don't know why it was changed in the first place. Please read
                 the notes I have written on the code.
  04/08/03  hm   changed if (g_blink_interval & 0x7f)==0 then the activity
                 led (gpio0) is enabled but not blinked.
  04/29/03  ds   - Temporary fix for the Crd_stat_msk register issue in 223. This code is not comprehensive.
                   Please the read the explanation in the function.
                 - Added a check for the rsvd_hi byte in nvstore to take care of the default value 0xff
  05/01/03  ds   Protected the fix above to be compiled for only 223.
  05/01/03  cds  - Added dev_mngr k_msg_bootstrap handler to initialize power management code
                   and to power up all registers if power management features are not to be used. (223 and future mcus)
  05/02/03  ds   Protected the sd_probe code in thread_wait_cbw from interrupts, to prevent the alteration
                 of the phy2log lun table from underneath. This makes the code more robust.
  05/07/03  ds   Protected the handler for k_msg_bootstrap, to compile only for usb97223. This code makes a call
                 to a pwr_mgmt fn and they are not compiled for 210.
  05/15/03  ds   The hole in the code for dfu was being reserved based on what chip it is. It should be based
                 on the dfu option being set. Fixed it.
  05/30/03  sbs  Added a delay of 5msec before powering on the CF card.
  06/03/03  sbs  During a MSPRO eject reset the flag g_mspro_format_flag , this required to avoid a failure during a
                 media pull out when the Format is in process.
  06/04/03  sbs   GPIO is seven is now used to Indicate the the device status,a Led is turned on after a Set Configuration
                 and turned off on a suspend.The same physical pin is shared by the EEPROM clk.The state of the pin is
                 always set to high after a EEPROM access.
  06/06/03  ds    -Added a new flag g_app_suspended to track the suspended state of the application layer.
                 This is for battery powered devices, where the app needs to relinquish control of the flash interface
                 and go to sleep, while the kernel is still not suspended.
                 -Also disconnect all fmc interfaces irrespective of on a power down, irrespective of
                 the kind of power management.
  06/11/03  ds   Changed to unmask the rx pipe when we are done processing the set_config.
  06/12/03  sbs  The high speed led turn on code is now also addded in dev_wait_cbw
                 this was done give enough setteling time for the SIE bit.
  06/13/03  ds   More changes for the Reboot issue with MSI Boards.
                 - Added code to return the wait_create state of the device thread, on a usb_reset or abort condition.
                  from both wait_cbw and wait_csw.
                 - Bound the device thread to receive abort synchronizers.
                 All the above are in reference to the handling of mscbot_reset. This Bios issues multiple
                 cbw-mscbot_reset commands once every 20 to 30 reboots. The error has been currently moved
                 to once every 320 boots i.e. it is 99.65% stable.
  06/13/03  ds   Added code to make thread_wait_cbw to wakeup on a kbm_sync_abort. This is to cover the case
                 when the state is past wait_csw and waiting to wakeup in wait_cbw. A sync_abort arrives and
                 the dev thread is not in a state to reset the hpbot layer, because it has not registered for the sync.
  06/17/03  ds   Enable and disconnect the pull up resistors on the flash blocks (in pwr_mgmt_ctl) irrespective
                 of the power management state.
  06/19/03  sbs  The LED turn on in DEV_PWR_UP seems too be opposite of what is required.
  06/24/03  am   dev_power_up(): moved CF power-up after all other slot power-up
                 to minimize the 3.3V bus transient when a microDrive is used.
  06/25/03  tbh  cleaned up inappropriate/unprofessional comments per defect br717.
  06/26/03  cl   removed blank lines and added indentations to comply with
                 SMSC coding standards.
  07/01/03  pjc  added kbm_attr_hl_bus_pwr_report and kbm_attr_hl_report_full_speed
                 attribute checking in dev_validate_nvstore(). See full descriptions
                 of these bits in dev.h. Also added defines for k_ix_dev_usb_lo
                 and k_ix_dev_usb_hi for use in dev_cpex() source payload.                 
  08/04/03  sbs  Added a sony specific MSPRO formatter flag clear during MS media eject.  
  08/13/03  sbs  Fixed bug-789-794, All this bugs are related to LED operations
  08/13/03  am   turn off SD activity LED on gpio15 in dev_power_up() to fix bug br763.
  09/02/03  cl   Added dev_common_media_led_off() and dev_common_media_led_on() to
                 implement fr803
  09/10/03  sbs  fix for br809. in dev_thread_wait_cbw() upon reset or abort
                 yield instead of transitioning to dev_thread_wait_create().
 =============================================================================================*/
#include <ctype.h>
#define __device_dot_c__
#include "project.h"
#include "dev.h"
// if any of these are supported, then we want to have device.c
// attempt to use custom configuration information stored in the
// particular form of rom/nvram
#if defined(k_opt_eeprom) || defined(k_opt_otprom) || defined(k_opt_nand)
  #include "flash.h"
  #define k_opt_nvstore
#endif
// define to activate periodic idle processing
#define k_opt_idle_on_timer
// time interval in msec for periodic idle processing
#define k_idle_timer 100
//------------------------------------------------------------------------------
// 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_usb_lo  2   // usb version lo
#define k_ix_dev_usb_hi  3   // usb version hi
#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
// offset into the config descriptor
#define k_ix_cfg_bmattrib 7
#define k_ix_cfg_maxpwr   8
#ifdef k_mcu_97223
//global variable for the value of mcu clk frequency
xdata uint8 g_mcu_clk_freq = kbm_clksel_mcu_clk_1dot875_mhz;
#endif
extern bit g_mspro_format_flag;
extern bit  g_sony_mspro_format_flag;
// Indexes into lun_info
extern xdata uint8 g_max_dyn_lun;
/*
extern xdata uint8 g_dyn_lun_cf;
extern xdata uint8 g_dyn_lun_ms;
extern xdata uint8 g_dyn_lun_sm;
extern xdata uint8 g_dyn_lun_sd;
extern xdata uint8 g_dyn_lun_nand;
*/
extern xdata uint8 g_lun_phy2log_map[];
//------------------------------------------------------------------------------
// vendor id and product id (SMSC -> 0106 dec = 0424 hex)
#define k_vendorhi         0x04  // vendor id hi
#define k_vendorlo         0x24  // vendor id lo
#ifdef k_mcu_97210
   #define k_dev_producthi    0x20  // product id hi
   #define k_dev_productlo    0xFC  // product id lo
#elif defined(k_mcu_97211)
   #define k_dev_producthi    0x21  // product id hi
   #define k_dev_productlo    0x1A  // product id hi
#elif defined(k_mcu_97223)
   #define k_dev_producthi    0x22  // product id hi
   #define k_dev_productlo    0x3A  // product id hi
#elif defined(k_mcu_97242)
   #define k_dev_producthi    0x24  // product id hi
   #define k_dev_productlo    0x2A  // product id hi
#endif
//------------------------------------------------------------------------------
// 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 20x...
// except the masked rom parts aren't dfu-able...
//DS removed the check for !defined(k_opt_otprom) because we will have to reserve this code space anyway
//if we do dfu this we will have to reserve this code space irrespective of the otprom option being set.
#ifdef k_opt_dfu
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
  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
};
// 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
  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
};
//------------------------------------------------------------------------------
// high speed device descriptor
uint8 code g_hs_dev_dscr[] =
{

⌨️ 快捷键说明

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