📄 device.c
字号:
/*============================================================================
____________________________________________________________________________
______________________________________________
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
06/24/02 tbh clear sync_abort in wait_cbw to prevent the case where
the host enumerates the device, then sends get-max-lun
(causing the sync-abort to be delivered) then the check media
dfa runs, then the reset media dfa runs (each time pusing the
thread context preserving the abort sync) then the media handler
sees the abort, clears the abort, and exits. after that the
thread pop (from the end dfa) restores the preserved abort
and we end up in a vicious loop. so clear the abort in wait cbw
-before- any dfa's are run.
06/25/02 ds The sd_blk_ovrrun and sdc_stat_crc_err interrupts shall only be masked here and
cleared in the lun layer.
06/25/02 cds modified eeprom code to pull vid/pid/config info from
eeprom, nand flash media.
06/27/02 tbh clear stale sync abort and sync reset in wait_cbw.
07/01/02 tbh added a call to fgnd_hpbot_wait_create(0 from dfv_mngr(k_msg_suspend)
to ensure bot state machine is ready even in the problematic case
of suspended W98 host, SMSC Driver (remains loaded) and there is
no usb reset upon resume.
07/10/02 tbh modified cpex to handle dfu requests
07/18/02 tbh modified for k_pfm_led to correctly handle the "card present" led
for SD when host is W98, W2K, WME.
because these drivers are "old 'n busted" they do not send TUR periodically.
because the SD card detect hardware is "old 'n busted" it cant tell between
insert and eject (the card has to be probed).
the (original) firmware only probes the SD card when a cbw arrives for SD's lun.
only then did it probe the card (power it up, see if a card is there).
therefore, the power led and the SD activity led are both inactive until you
click the icon (send a cbw) (for all but XP and OSX, which send periodic TURs).
this is as it was designed from the beginning.
the per-lun activity leds are a "new requirement".
so, i had to add the "new hotness" to watch for SD events and cause
the card discovery process for SD.
Later that same day...: added polling so it will work on the
new sockets with the STEWPUD p.o.s. switches.
07/19/02 cds - updated nvstore_validate() to always set g_password_validated to true,
if k_opt_password is NOT defined
- protected all code to do sd polling with guard (#if/#end) to prevent
poller from running if no SD is included in the project
07/23/02 baw inside dev_thread_wait_cbw
- Moved password handling code above the checks for media present
- modified checks for media present to use media present macro
when password support is requested.
07/23/02 baw moved nand removable initialization into dev_validate_nvstore
this is required because nand removability depends on
password validation which is done in dev_validate_nvstore.
It can not be in nand_initialize_controller because at that point
g_password_validated has not been initialized.
07/24/02 tbh -SD power was coming on at por. this was legacy code from before
the addition of _lun_reset_controller() and _lun_initialize_controller().
it is fine to have the SD power off at por, so now it is off at por.
-moved the _lun_log2phy call out of the ifdef SD so builds w/out
sd will route packets to the proper luns. (was a construction error)
07/25/02 baw Added three more password commands, they are
- Password Supported
- Is Locked
- Is Password Validated
These commands will give the application access to more information
so it doesn't have to make assuptions based on media present.
07/30/02 ds Since on a POR the sd_insert_eject interrupt is fired, the LED is turned on even before
the USB cable is plugged in. Removed the line of code that turns the media light on.
08/05/02 tbh if k_opt_password is turned off default g_password_validated to k_yes
so nand will not appear to have no media.
08/06/02 tbh enhanced the nvstore support to include otprom (flash).
changed the k_support_xxxx to k_opt_xxxx to select from
build script / makefile, *not* from knlcfg.h (removed from there)
08/09/02 cds added attribute flag to force smart media-compatible timing to
nand-chip type devices. smart media luns always use the compatible timing
08/13/02 tbh moved g_dev_attr_xx to xdata
08/19/02 cds updated dev_initialize to select the klsi phy for all k_20x_family
mcu's, instead of just k_mcu_97201
08/22/02 cds - updated dev_power_up() to set gpio 5 (the HS indicator) if configured
for high speed, and to clear it if not.
- updated dev_power_dn() to clear gpio 5 to turn off led when
suspended or disconnected.
08/27/02 ds The first on IoData's wish list. By setting a particular byte in nvstore to zero or
non-zero value we can force the iSerialNumber in Device descriptor to change to zero or not respectively.
08/27/02 ds The second on Iodata ( and generic) wish list. The bmattributes value and maxpower value
in the cfg dscr is fetched from the nvstore is it is present.
08/29/02 ds The default (no nvstore) values for bmattributes and maxpwr in cfg descriptors, are set to
Buspowered (0x80) and 500ma (0xfa).
08/29/02 ds Corrected the previous check-in. Left out one of the cfg descriptors.
09/05/02 ds Fixed a typo, that caused the maxpwr to not update correctly.
09/06/02 ds Implemented the code for 'custom' blinking light on access. The customer can set the frequency
in multiples of 10ms and the led(gpio0) will blink accordingly. Default is blink every 10ms.
Also the blinking will continue after the access for xx seconds as specified by the customer in the nvstore.
This is implemented using the timer1, which ticks every 10ms.
-- Also implemented the iodata requirement of an insert switch. The polling og the sd card
will happen only if card is know to be in. ( gpio5). Thus we will not have a HS indicator in
iodata compilation.
09/06/02 ds made all iodata specific mods to generic
09/07/02 tbh updated otprom nvstore to function correctly. only supports sst39vf010.
also tweaked dev_validate_nvstore() to check additional values
from the nvstore. cleaned up various checks to simplify them.
09/09/02 ds Our Initial requirement was that we report bus-powered and a max power of 500ma.
But as soon as we report this in the config descriptor, the GET_STATUS arrives which is
answered by the hardware and always reports "self-powered", even when we are not. So, this confuses the host
as we claim to draw more than 100ms while self-powered and hence fails the chapter 9 tests.
So, our max power shall not be >100ma, and so set the default to 0x31 ( 98ma).
09/10/02 tbh Changed nvstore signature because nvstore data format changed.
Later that day... Don't declare the nvstore invalid if the max power
is out of range, but do declare it invalid if bmAttributes is not
a legitimate value.
09/11/02 tbh dev_validate_nvstore was copying lun strings into the _lun_data
table even though there were fewer than 4 luns, causing a crash.
fixed it to only copy for the number of luns in the build.
09/12/02 ds Noted that the led should be set to idle state after the post access blinks. Curently it
is being done in the bot layer, but it is not sufficient.
09/12/02 tbh moved g_post_access_blink_secs, g_blink_interval, _seconds_counter,
and _blink_counter 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/16/02 tbh do not reserve the 768 byte hole in code space for the 242.
that part has a masked rom, and cannot make use of dfu, so
there is no need to reserve the hole. with the hole present
the code does not fit inthe 242's 48K address range... it extends
a little beyond the highest available address. without the hole
the code all fits into the 48K range.
09/16/02 cds updated names of ata0/ata1 constant names to avoid future confustion
09/20/02 tbh added dev_indicate_bus_speed, dev_turn_off_activity_indicator,
dev_gpio_power_down, dev_toggle_activity_indicator
to facilitate variant builds with activity indication on various gpios.
09/22/02 tbh eliminated unused code on 242 builds
09/23/02 cds protected initialization of g_active_media to be called only when
a lun using a mapper (ms, sm, nand) is in the build
09/25/02 cds added code to password switch to forward unknown vendor commands
on to the lun_process_cb processor.
09/30/02 ds Fixed the bug where the activity led goes to its idle state on suspend. This caused
it to stay on if the idle state is to be ON. Changes to code:
-Moved the assignment of g_blink_interval and g_activity_led_idle_bright from dev_power_up to
dev_validate_nvstore along woth the rest of the led specific variables.
-Mask the timer1 interrupt on dev_power_dn
10/01/02 ds Added two new functions nvstore_write_disable and nvstore_write_enable. Also added
eeprom_write to the implementation of nvstore_write
10/02/02 ds Fixed nvstore_write_enable and nvstore_write_disable, where they should return void.
10/03/02 ds Removed the check for !defined(k_opt_otprom) that causes us not to reserve the 768 bytes
if we have an otprom build. If we do dfu this we will have to reserve this code space irrespective
of the otprom option being set.
10/03/02 ds Removed the #if 0 around password implementation, which was done for development of
secure memory implementation, and got left behind.
10/04/02 ds Modified the USB Version field of the Full Speed Device Descriptors, to say 2.0
10/10/02 cds removed password cb processing from here. revealed some other security holes (i.e. "g_password_validated"
bit being exposed), but most end-users won't be able to compile their own firmware.
Updated the cb processor to 3 steps:
1) let security module handle it
2) check if lun is ready for r/w access
3) if r/w dispatch immediately thru call
otherwise dispatch through dfa
- allowed vendor commands to tunnel through media access check
10/11/02 cds - fixed cut-n-paste error that stopped all enumeration for the previous security tunnel
- updated pid for various mcu's. 97210=>20FC, k_mcu_97211 = 211A, k_mcu_97223=223a, k_mcu_97242=242a, etc.
10/15/02 cds - added globals g_inq_vid & g_inq_pid_hdr to hold values to be reported during inquiry so as to work
with the icon-replacement tool and previous firmware eeprom.dat files.
- added code to fill g_inq_* values directly within nvstore_validate, instead of in the inquiry handler
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
- fixed nvstore_validate() device id loop to copy device id strings to the correct luns
10/24/02 ds Reversed the logic of checking Gpio5- SD Card Insert as per the request from IODATA
10/24/02 ds Modified the handler for the interrupt k_irq_fmc_err_sd_blk_ovrun, in dev_intr to set
kbm_sync_fmc_irq, so that the SD code can retry the reads instead of aborting.
10/30/02 ds Modidfied dev_gpio_power_dn to drive the activity-led gpio high or low depending on an
attribute bit ( new feature per Iodata's request)
11/19/02 ds Set the gpio dirs for interleave demo
11/20/02 ds Intialized the gpio direction registers to suit 97211 and 97242, and for the interleave demo.
===========================================================================*/
#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
///////////////////////////////////////
//EXPERIMENTAL - DO NOT STAND TOO CLOSE
#define k_opt_idle_on_timer
#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_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
//------------------------------------------------------------------------------
// 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.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -