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

📄 device.c

📁 U盘控制器USB97C223的固件代码,对2kPAGE NAND FLASH 有很好的支持.
💻 C
📖 第 1 页 / 共 5 页
字号:
  0,                              // total length hi
  1,                              // number of interfaces
  0x01,                           // configuration value
  0x00,                           // index of string descriptor
  0x80,                           // attributes: bus powered, no remote wakeup
  //  0xFA,                           // max power: 500ma
  0x31,                           // max power: 98ma
  // interface descriptor: BOT mass storage
  k_usb_ifcdscrsz,                // length of descriptor in bytes
  k_usb_dscr_typ_interface,       // descriptor type: interface
  0,                              // interface number
  0,                              // alternate interface
  2,                              // number of endpoints
  0x08,                           // usb interface class: mass storage
  0x06,                           // usb interface subclass: scsi
  0x50,                           // interface protocol: BOT (bulk only transport)
  0x00,                           // interface string index
  // endpoint descriptor: bulk out
  k_usb_ndpdscrsz,                // length of descriptor in bytes
  0x05,                           // descriptor type: endpoint
  0x02,                           // endpoint 2, out
  0x02,                           // bulk
  _l(k_hs_maxpktsz),              // max packet size lo
  _h(k_hs_maxpktsz),              // max packet size hi
  0x01,                           // polling interval
  // endpoint descriptor: bulk in
  k_usb_ndpdscrsz,                // length of descriptor in bytes
  0x05,                           // descriptor type: endpoint
  0x82,                           // endpoint 2, in
  0x02,                           // bulk
  _l(k_hs_maxpktsz),              // max packet size lo
  _h(k_hs_maxpktsz),              // max packet size hi
  0x00,                           // polling interval
  // dfu functional descriptor
  k_dfu_funcdscrsz,               // length of descriptor in bytes
  k_dfu_dscr_typ_functional,      // dfu functional descriptor type
  0x07,                           // manifest, upload, dnload tolerant
  _l(k_dfu_detach_timeout),       // detach timeout lo
  _h(k_dfu_detach_timeout),       // detach timeout hi
  _l(k_dfu_max_xfer_sz),          // max transfer size lo
  _h(k_dfu_max_xfer_sz)           // max transfer size hi
};
//------------------------------------------------------------------------------
// globals
uint8 g_ix_dev_thread;
#define g_ix_mscbot_thread g_ix_dev_thread
#define k_counts_per_sec 100
//------------------------------------------------------------------------------
// nvstore ghost values
xdata uint8 g_inq_vid[k_sz_inq_vid];
xdata uint8 g_inq_pid_hdr[k_sz_inq_pid_hdr];
//variables to store these custom values
uint8 g_blink_interval;
static uint8 _blink_counter;
//just a temp storage so that we will remember the value
xdata uint8 g_nvstore_post_access_blink_secs;
uint8 g_post_access_blink_secs;   //in seconds
bit g_activity_led_idle_bright = k_true;
static uint8 _seconds_counter;
// attribute & global attribute flags
uint8 xdata g_dev_attr_lo;
uint8 xdata g_dev_attr_hl;
// uint8 xdata g_dev_attr_lh;
// uint8 xdata g_dev_attr_hi;
// locals
static bit _nvstore_data_valid;
static bit _nvstore_insert_vidpid;
static bit _nvstore_insert_bmattrib_and_maxpwr;
static bit _serial_number_valid;
// cannot be located in k_ram_base to k_ram_base+k_flash_sector_sz range.
static xdata uint8  _nvstore_ix _at_ 0x4000;
static xdata uint16 _nvstore_sz _at_ 0x4001;
static void dev_sd_poller(void) reentrant;
#define k_sd_poll_interval 65000
static xdata uint16 _sd_poll_counter = k_sd_poll_interval;
//hm 11/18/02 new sd card detection method
#define k_opt_new_sd_detect
#ifdef k_opt_new_sd_detect
static uint8 dev_sd_gpio5_status() reentrant;
#endif
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// internal reserved bytes.  for 223, g_dev_rsvd_lo is for smart media
xdata g_dev_rsvd_hi;
xdata g_dev_rsvd_lo;
//------------------------------------------------------------------------------
// must store a copy of config so it can be checked after the usbrst arrives
// since on the 20x family the configuration is cleared by hardware.
static uint8 _most_recent_config = 0;
//------------------------------------------------------------------------------
// Name:
//
// Declaration:
//
// Purpose:
//
// Arguments:
//
// Return:
//   None.
//
// Notes:
//   It is safe to call this function from interrupt handlers.
//
// Since:
//   fmc.10 ver .97
//------------------------------------------------------------------------------
void dev_indicate_bus_speed() reentrant
{
  // be sure to validate the nvstore before calling this
  if (g_dev_attr_lo & kbm_attr_lo_gpio5_as_sd_insert)
  {
    gpio_bit_is_input(5);
    return;
  }
  gpio_bit_is_output(5);
  if (sie_is_high_speed())
    gpio_setbit(5);
  else
    gpio_clrbit(5);
}
// these functions must be callable from interupt service routines
#pragma NOAREGS
//------------------------------------------------------------------------------
// Name:
//
// Declaration:
//
// Purpose:
//
// Arguments:
//
// Return:
//   None.
//
// Notes:
//   It is safe to call this function from interrupt handlers.
//   Call during initialization so the direction bits will be correct.
//
// Since:
//   fmc.10 ver .97
//------------------------------------------------------------------------------
void dev_turn_off_activity_indicator() reentrant
{
  #ifdef k_mcu_97210
  gpio_bit_is_output(0);
  #endif
  #ifdef k_mcu_97211
  gpio_bit_is_output(0);
  gpio_bit_is_output(1);
  #endif
  #ifdef k_mcu_97223
  gpio_bit_is_output(1);
  #endif
  #ifdef k_mcu_97242
  gpio_bit_is_output(1);
  #endif
  
  //keep activity LED on if there is any media present and the
  //common media led attribute is set.
  if (g_dev_attr_hl & kbm_attr_hl_gpio1_common_led)
  {
    if ((_mcu_register_rd(x_crd_ps) & (kbm_crd_ps_cf  | 
                                       kbm_crd_ps_sm  | 
                                       kbm_crd_ps_ms  | 
                                       kbm_crd_ps_mmc | 
                                       kbm_crd_ps_sd  )))
    {
      dev_common_media_led_on();
    }
    else
    {
      dev_common_media_led_off();
    }

  }
  else
  {
    // no activity, return the led to its idle state as defined in the nvstore
    if (g_activity_led_idle_bright)
    {
      // turn on the led
      #ifdef k_mcu_97210
      gpio_setbit(0);
      #endif
      #ifdef k_mcu_97211
      gpio_setbit(0);
      gpio_setbit(1);
      #endif
      #ifdef k_mcu_97223
      gpio_setbit(1);
      #endif
      #ifdef k_mcu_97242
      gpio_setbit(1);
      #endif
    }
    else                            // idle dim
    {
      // turn off the led
      #ifdef k_mcu_97210
      gpio_clrbit(0);
      #endif
      #ifdef k_mcu_97211
      gpio_clrbit(0);
      gpio_clrbit(1);
      #endif
      #ifdef k_mcu_97223
      gpio_clrbit(1);
      #endif
      #ifdef k_mcu_97242
      gpio_clrbit(1);
      #endif
    }
  }
}
//------------------------------------------------------------------------------
// Name:
//
// Declaration:
//
// Purpose:
//
// Arguments:
//
// Return:
//   None.
//
// Notes:
//   It is safe to call this function from interrupt handlers.
//
// Since:
//   fmc.10 ver .97
//------------------------------------------------------------------------------
void dev_toggle_activity_indicator() reentrant
{
  #ifdef k_mcu_97210
  gpio_togglebit(0);
  #endif
  #ifdef k_mcu_97211
  gpio_togglebit(0);
  gpio_togglebit(1);
  #endif
  #ifdef k_mcu_97223
  gpio_togglebit(1);
  #endif
  #ifdef k_mcu_97242
  gpio_togglebit(1);
  #endif
}
//------------------------------------------------------------------------------
// Name: dev_common_media_led_on
//
// Declaration: void dev_common_media_led_on() reentrant using 1
//
// Purpose: turns on GPIO1(USB97C223)/GPIO0(USB97C210) if common media LED
//          attribute bit is set
//
// Arguments:
//   None.
//
// Return:
//   None.
//

⌨️ 快捷键说明

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