www.pudn.com > SMSC USB2.0.zip > cf.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. 
  ____________________________________________________________________________ 
  ____________________________________________________________________________ 
   -  
  ____________________________________________________________________________ 
  comments tbd 
  ____________________________________________________________________________ 
  Revision History 
  Date      Who  Comment 
  ________  ___  _____________________________________________________________ 
  04/20/01  cds  initial version 
  11/28/01  cds  moved "select_cfc" call into "init device" 
  01/08/02  cds  moved device name into the "cf_init_controller" method 
  02/26/02  tbh  changed strcpy to strncpy for safety 
  03/12/02  tbh  minor renaming to fit the fmc project's idiom 
  07/12/02  tbh  lun string name change caued by mandate from on high 
  08/29/02  tbh  ensure ata mode is cleared to zero at card initialization time. 
  09/12/02  tbh  replaced strncpy() with memcpy() to save data space. 
  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                
                  
============================================================================*/ 
#define __cf_dot_c__ 
#include "project.h" 
 
code  _vtbl_defn(cf) ; 
 
//------------------------------------------------------------------------------- 
//------------------------------------------------------------------------------- 
void cf_dump_registers() reentrant 
{ 
  // dump contents of every compact flash register 
  trace0(0, cfc, 1, "cf_dump_registers()") ; 
  trace1(0, cfc, 1, "          x_msb_ata: %02x", x_msb_ata) ; 
  trace1(0, cfc, 1, "          x_lsb_ata: %02x", x_lsb_ata) ; 
  trace1(0, cfc, 1, "         x_cfc_stat: %02x", x_cfc_stat) ; 
  trace1(0, cfc, 1, "     x_cfc_stat_msk: %02x", x_cfc_stat_msk) ; 
  trace1(0, cfc, 1, " x_cfc_ata_mode_ctl: %02x", x_cfc_ata_mode_ctl) ; 
} 
 
// ---------------------------------------------------------------------- 
// ---------------------------------------------------------------------- 
void cf_dump_ata_taskfile() reentrant 
{ 
  uint8 val ; 
  // dump contents of the ata task file 
  trace0(0, cfc, 1, "cf_dump_ata_taskfile()") ; 
  val = cf_data ;       trace1(0, cfc, 1, "        cf_data:%02x", val) ; 
  val = cf_error ;      trace1(0, cfc, 1, "       cf_error:%02x", val) ; 
  val = cf_sector_cnt ; trace1(0, cfc, 1, "  cf_sector_cnt:%02x", val) ; 
  val = cf_sector_num ; trace1(0, cfc, 1, "  cf_sector_num:%02x", val) ; 
  val = cf_cylinder_lo ;trace1(0, cfc, 1, " cf_cylinder_lo:%02x", val) ; 
  val = cf_cylinder_hi ;trace1(0, cfc, 1, " cf_cylinder_hi:%02x", val) ; 
  val = cf_dev_select ; trace1(0, cfc, 1, "  cf_dev_select:%02x", val) ; 
  val = cf_status ;     trace1(0, cfc, 1, "      cf_status:%02x", val) ; 
} 
 
//+----------------------------------------------------------------------------- 
// Name: 
//   cf_init_controller 
// 
// Declaration: 
//   void cf_init_controller(void); 
// 
// Purpose: 
//   Called once at POR, initialize device_id and device_type, other controller 
//   specific initialization. 
// 
// Arguments: 
//   None. 
// 
// Return: 
//   None. 
// 
// Notes: 
//   This is a FUNCTION, not a DFA. 
// 
// Since: 
//   fmc-1.0 
//------------------------------------------------------------------------------ 
void cf_init_controller(void) reentrant 
{ 
  trace0(0, cf, 0, "cf_init_controller()") ; 
  memcpy(_lun_data(device_id), "CF", k_lun_max_devid_sz); 
  _lun_data(device_type) = k_device_type_ata; 
} 
 
//+----------------------------------------------------------------------------- 
// Name: 
//   dfa_cf_initialize_media 
// 
// Declaration: 
//   void dfa_cf_initialize_media(void); 
// 
// Purpose: 
//   Called once per media change.  Initialize hardware for inserted media. 
// 
// Arguments: 
//   None. 
// 
// Return: 
//   No return value. 
//   However, the DFA's argument pointer is written with a t_result indicating: 
//     k_success - command completed. 
//     k_usbrst  - usb reset signalling was detected while executing the command. 
//     k_aborted - traffic occurred on the control pipe while wexecuting the command (probably a mass storage reset). 
//     k_timeout - a timeout limit exceeded while executing the command. 
//   (This allows the caller to see the return value, via the argp, after the DFA terminates). 
// 
// Notes: 
//   This is a DFA, not a FUNCTION. 
// 
// Since: 
//   fmc-1.0 
//------------------------------------------------------------------------------ 
void dfa_cf_initialize_media() reentrant 
{ 
  trace0(0, cf, 0, "dfa_cf_initialize_media()") ; 
  //  - enable iordy sampling, set pio mode to 0 and enable cfc intrqs 
  _mcu_register_wr(x_cfc_ata_mode_ctl, 0); 
  _mcu_register_set_bits(x_cfc_ata_mode_ctl, kbm_cfc_ata_mode_ctl_iordy_en) ; 
  _mcu_register_clr_bits(x_cfc_stat_msk, kbm_cfc_stat_intrq) ; 
  // wait at least 2 milliseconds after the reset before accessing the device 
  thread_set_timer(3) ; 
  // chain into the ata init dfa as if it were an epsilon transition on the current dfa.... 
  thread_yield_ex(kbm_sync_none, kbm_sync_timer, dfa_ata_initialize_media) ; 
} 
 
//---eof------------------------------------------------------------------------