www.pudn.com > SMSC USB2.0.zip > fmc.h


/*============================================================================ 
  ____________________________________________________________________________ 
                                ______________________________________________ 
   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. 
  ____________________________________________________________________________ 
  ____________________________________________________________________________ 
  fmcdev.h - USB97210 device specific hardware interface definitions and 
             functions that are external to the MCU (ergo external to minimos). 
  ____________________________________________________________________________ 
  comments tbd 
  ____________________________________________________________________________ 
  Revision History 
  Date      Who  Comment 
  ________  ___  _____________________________________________________________ 
  09/17/01  cds  initial version - all xdata registers are initially defined 
                 here.  I've had mixed feelings about splitting up these 
                 registers into the various controller specific headers, but 
                 that may prove confusing and/or difficult to maintain, so 
                 I think it would be best to have all the registers defined 
                 here, then access to registers (via macros or whatever) 
                 can be defined by a file specifically for the controller 
  11/26/01  cds  moved lun config into options.h 
  02/26/02  tbh  added intra-burst callback, g_fmc_options, _fmc_set_options() 
  03/05/02  ds   added another option to g_fmc_options, to receive 512 bytes is 1.1 speed 
  06/21/02  cds  added fmc_select_nand()  
============================================================================*/ 
 
//------------------------------------------------------------------------------ 
// flash memory controller registers 
 
#ifndef __fmc_dot_c__ 
  #define t_fmc_register extern unsigned char volatile xdata 
  #define at_fmc(__addr) 
#else 
  #define t_fmc_register unsigned char volatile xdata 
  #define at_fmc(__addr)    _at_ 0x##__addr 
#endif 
typedef t_xdata_ref t_fmc_register_ref; 
 
//------------------------------------------------------------------------------ 
// ecc & crc config registers 
// !!! move these to sm.h??? 
t_fmc_register ecc_a_add_l      at_fmc(34F0);  // rw ecc address register for part A of data (lo byte) 
t_fmc_register ecc_a_add_h      at_fmc(34F1);  // rw ecc address register for part A of data (hi byte) 
t_fmc_register ecc_a_data_0     at_fmc(34F8);  // rw ecc data in PIO transfer of SMC 
t_fmc_register ecc_a_data_1     at_fmc(34F9);  // rw ecc data in PIO transfer of SMC 
t_fmc_register ecc_a_data_2     at_fmc(34FA);  // rw ecc data in PIO transfer of SMC 
t_fmc_register ecc_b_add_l      at_fmc(34FE);  // rw ecc address register for part B of data (lo byte) 
t_fmc_register ecc_b_add_h      at_fmc(34FF);  // rw ecc address register for part B of data (hi byte) 
t_fmc_register ecc_b_data_0     at_fmc(34F5);  // rw ecc data in PIO transfer of SMC 
t_fmc_register ecc_b_data_1     at_fmc(34F6);  // rw ecc data in PIO transfer of SMC 
t_fmc_register ecc_b_data_2     at_fmc(34F7);  // rw ecc data in PIO transfer of SMC 
t_fmc_register ecc_crc_ctl      at_fmc(34F2);  // rw ecc & crc control register 
t_fmc_register ecc_crc_stat     at_fmc(34F3);  // rw ecc & crc status register 
t_fmc_register ecc_crc_stat_msk at_fmc(34F4);  // rw ecc & crc status mask register 
// special smsc hardware debug registers 
t_fmc_register x_smsc_dbg       at_fmc(3f10); 
 
//------------------------------------------------------------------------------ 
// fmc callback function 
typedef t_result (code *t_fmc_callback)(void) reentrant; 
 
//+----------------------------------------------------------------------------- 
// Name: 
//   _fmc_set_start_lb_8 
// 
// Declaration: 
//   void _fmc_set_start_lb_8(uint8 mswmsb, uint8 mswlsb, uint8 lswmsb, uint8 lswlsb); 
// 
// Purpose: 
//   Set the starting logical block for an fmc transfer 
//   as four 8 bit numbers. 
// 
// Arguments: 
//   mswmsb - a uint8, the most significant word, most significant byte. 
//   mswlsb - a uint8, the most significant word, least significant byte. 
//   lswmsb - a uint8, the least significant word, most significant byte. 
//   lswlsb - a uint8, the least significant word, least significant byte. 
// 
// Return: 
//   None. 
// 
// Notes: 
//   None. 
// 
// Since: 
//   fmc-1.0 
//------------------------------------------------------------------------------ 
#define _fmc_set_start_lb_8(__mswmsb, __mswlsb, __lswmsb, __lswlsb)            \ 
{                                                                              \ 
  g_start_lb_this_xfer.u8.hi = (__mswmsb);                                     \ 
  g_start_lb_this_xfer.u8.lh = (__mswlsb);                                     \ 
  g_start_lb_this_xfer.u8.hl = (__lswmsb);                                     \ 
  g_start_lb_this_xfer.u8.lo = (__lswlsb);                                     \ 
} 
 
//+----------------------------------------------------------------------------- 
// Name: 
//   _fmc_set_lb_count_8 
// 
// Declaration: 
//   void _fmc_set_lb_count_8(uint8 mswmsb, uint8 mswlsb, uint8 lswmsb, uint8 lswlsb); 
// 
// Purpose: 
//   Set the logical block count for an fmc transfer 
//   as four 8 bit numbers. 
// 
// Arguments: 
//   mswmsb - a uint8, the most significant word, most significant byte. 
//   mswlsb - a uint8, the most significant word, least significant byte. 
//   lswmsb - a uint8, the least significant word, most significant byte. 
//   lswlsb - a uint8, the least significant word, least significant byte. 
// 
// Return: 
//   None. 
// 
// Notes: 
//   None. 
// 
// Since: 
//   fmc-1.0 
//------------------------------------------------------------------------------ 
#define _fmc_set_lb_count_8(__mswmsb, __mswlsb, __lswmsb, __lswlsb)            \ 
{                                                                              \ 
  g_n_lb_this_split.u8.hi = g_n_lb_this_xfer.u8.hi = (__mswmsb);               \ 
  g_n_lb_this_split.u8.lh = g_n_lb_this_xfer.u8.lh = (__mswlsb);               \ 
  g_n_lb_this_split.u8.hl = g_n_lb_this_xfer.u8.hl = (__lswmsb);               \ 
  g_n_lb_this_split.u8.lo = g_n_lb_this_xfer.u8.lo = (__lswlsb);               \ 
} 
 
//+----------------------------------------------------------------------------- 
// Name: 
//   _fmc_get_start_lb_8 
// 
// Declaration: 
//   void _fmc_get_start_lb_8(uint8 mswmsb, uint8 mswlsb, uint8 lswmsb, uint8 lswlsb); 
// 
// Purpose: 
//   Get the current starting logical block for the current fmc transfer 
//   as four 8 bit numbers. 
// 
// Arguments: 
//   mswmsb - a uint8, the most significant word, most significant byte. 
//   mswlsb - a uint8, the most significant word, least significant byte. 
//   lswmsb - a uint8, the least significant word, most significant byte. 
//   lswlsb - a uint8, the least significant word, least significant byte. 
// 
// Return: 
//   None.  BUT its a macro that overwrites its arguments... 
// 
// Notes: 
//   None. 
// 
// Since: 
//   fmc-1.0 
//------------------------------------------------------------------------------ 
#define _fmc_get_start_lb_8(__mswmsb, __mswlsb, __lswmsb, __lswlsb)            \ 
{                                                                              \ 
  (__mswmsb) = g_start_lb_this_xfer.u8.hi;                                     \ 
  (__mswlsb) = g_start_lb_this_xfer.u8.lh;                                     \ 
  (__lswmsb) = g_start_lb_this_xfer.u8.hl;                                     \ 
  (__lswlsb) = g_start_lb_this_xfer.u8.lo;                                     \ 
} 
 
//+----------------------------------------------------------------------------- 
// Name: 
//   _fmc_get_lb_count_8 
// 
// Declaration: 
//   void _fmc_get_lb_count_8(uint8 mswmsb, uint8 mswlsb, uint8 lswmsb, uint8 lswlsb); 
// 
// Purpose: 
//   Get the remaining logical block count for the current fmc transfer 
//   as four 8 bit numbers. 
// 
// Arguments: 
//   mswmsb - a uint8, the most significant word, most significant byte. 
//   mswlsb - a uint8, the most significant word, least significant byte. 
//   lswmsb - a uint8, the least significant word, most significant byte. 
//   lswlsb - a uint8, the least significant word, least significant byte. 
// 
// Return: 
//   None.  BUT its a macro that overwrites its arguments... 
// 
// Notes: 
//   None. 
// 
// Since: 
//   fmc-1.0 
//------------------------------------------------------------------------------ 
#define _fmc_get_lb_count_8(__mswmsb, __mswlsb, __lswmsb, __lswlsb)            \ 
{                                                                              \ 
  (__mswmsb) = g_n_lb_this_split.u8.hi;                                        \ 
  (__mswlsb) = g_n_lb_this_split.u8.lh;                                        \ 
  (__lswmsb) = g_n_lb_this_split.u8.hl;                                        \ 
  (__lswlsb) = g_n_lb_this_split.u8.lo;                                        \ 
} 
 
//+----------------------------------------------------------------------------- 
// Name: 
//   _fmc_set_timeout 
// 
// Declaration: 
//   void _fmc_set_timeout(uint16 ticks); 
// 
// Purpose: 
//   Set the timeout for an fmc transfer. 
// 
// Arguments: 
//   ticks - a uint16 specifying the timeout. 
// 
// Return: 
//   None. 
// 
// Notes: 
//   None. 
// 
// Since: 
//   fmc-1.0 
//------------------------------------------------------------------------------ 
#define _fmc_set_timeout(__ticks)                                              \ 
{                                                                              \ 
  g_fmc_timeout = (uint16)(__ticks);                                           \ 
} 
 
//+----------------------------------------------------------------------------- 
// Name: 
//   _fmc_set_options 
// 
// Declaration: 
//   void _fmc_set_options(uint8 options); 
// 
// Purpose: 
//   Set the options for an fmc transfer. 
// 
// Arguments: 
//   options - a uint8 containing bitmask: 
//     kbm_fmc_disable_auto_xfer       - don't turn on the autoxfer bit 
//     kbm_fmc_end_burst_on_count_down - end burst when count hits zero, instead of on irq 
//     kbm_fmc_xfer_512_byte_pkt       - Set this to receive a 512 byte pkt in 1.1 speed 
// 
// Return: 
//   None. 
// 
// Notes: 
//   None. 
// 
// Since: 
//   fmc-1.0 
//------------------------------------------------------------------------------ 
#define _fmc_set_options(__options)                                            \ 
{                                                                              \ 
  g_fmc_options = (uint8)(__options);                                          \ 
} 
 
//+----------------------------------------------------------------------------- 
// Name: 
//   _fmc_set_callback 
// 
// Declaration: 
//   void _fmc_set_callback(t_fmc_callback begin_xfer, t_fmc_callback end_xfer, 
//                          t_fmc_callback begin_split, t_fmc_callback end_split, 
//                          t_fmc_callback begin_burst, t_fmc_callback intra_burst, 
//                          t_fmc_callback end_burst); 
// 
// Purpose: 
//   Set the callback functions for an fmc transfer. 
// 
// Arguments: 
//   begin_xfer  - a t_fmc_callback at the beginning of the transfer. 
//   end_xfer    - a t_fmc_callback at the end of the transfer. 
//   begin_split - a t_fmc_callback that issues a command to the drive. 
//   end_split   - a t_fmc_callback that cleans up after a split, if necessary. 
//   begin_burst - a t_fmc_callback that waits for the drive to be ready for a burst. 
//   intra_burst - a t_fmc_callback as soon as the transfer has started. 
//   end_burst   - a t_fmc_callback that cleans up after a burst, if necessary. 
// 
// Return: 
//   None. 
// 
// Notes: 
//   The callback functions must return a t_result. 
//   Any return value other that k_success from a callback aborts the fmc transfer. 
// 
// Since: 
//   fmc-1.0 
//------------------------------------------------------------------------------ 
#define _fmc_set_callback(__begin_xfer, __end_xfer, __begin_split, __end_split, __begin_burst, __intra_burst, __end_burst) \ 
{                                                                              \ 
  g_fmc_begin_xfer_callback = (t_fmc_callback)(__begin_xfer);                  \ 
  g_fmc_end_xfer_callback = (t_fmc_callback)(__end_xfer);                      \ 
  g_fmc_begin_split_callback = (t_fmc_callback)(__begin_split);                \ 
  g_fmc_end_split_callback = (t_fmc_callback)(__end_split);                    \ 
  g_fmc_begin_burst_callback = (t_fmc_callback)(__begin_burst);                \ 
  g_fmc_intra_burst_callback = (t_fmc_callback)(__intra_burst);                \ 
  g_fmc_end_burst_callback = (t_fmc_callback)(__end_burst);                    \ 
} 
 
//+----------------------------------------------------------------------------- 
// Name: 
//   _fmc_set_start_lb_32 
// 
// Declaration: 
//   void _fmc_set_start_lb_32(uint32 val); 
// 
// Purpose: 
//   Set the starting logical block for an fmc transfer 
//   as a 32 bit number. 
// 
// Arguments: 
//   val - a uint32 representing the starting logical block. 
// 
// Return: 
//   None. 
// 
// Notes: 
//   None. 
// 
// Since: 
//   fmc-1.0 
//------------------------------------------------------------------------------ 
#define _fmc_set_start_lb_32(__val)                                            \ 
{                                                                              \ 
  g_start_lb_this_xfer.u32 = (uint32)(__val);                                  \ 
} 
 
//+----------------------------------------------------------------------------- 
// Name: 
//   _fmc_set_lb_count_32 
// 
// Declaration: 
//   void _fmc_set_lb_count_32(uint32 val); 
// 
// Purpose: 
//   Set the logical block count for an fmc transfer 
//   as a 32 bit number. 
// 
// Arguments: 
//   val - a uint32 representing the logical block count. 
// 
// Return: 
//   None. 
// 
// Notes: 
//   None. 
// 
// Since: 
//   fmc-1.0 
//------------------------------------------------------------------------------ 
#define _fmc_set_lb_count_32(__val)                                            \ 
{                                                                              \ 
  g_n_lb_this_split.u32 = g_n_lb_this_xfer.u32 = (uint32)(__val);              \ 
} 
 
//+----------------------------------------------------------------------------- 
// Name: 
//   _fmc_get_start_lb_32 
// 
// Declaration: 
//   uint32 _fmc_get_start_lb_32(void); 
// 
// Purpose: 
//   Get the current starting logical block for the current fmc transfer 
//   as a 32 bit number. 
// 
// Arguments: 
//   None. 
// 
// Return: 
//   A uint32. 
// 
// Notes: 
//   None. 
// 
// Since: 
//   fmc-1.0 
//------------------------------------------------------------------------------ 
#define _fmc_get_start_lb_32() g_start_lb_this_xfer.u32 
 
//+----------------------------------------------------------------------------- 
// Name: 
//   _fmc_get_lb_count_32 
// 
// Declaration: 
//   uint32 _fmc_get_lb_count_32(void); 
// 
// Purpose: 
//   Get the remaining logical block count for the current fmc transfer 
//   as a 32 bit number. 
// 
// Arguments: 
//   None. 
// 
// Return: 
//   A uint32. 
// 
// Notes: 
//   None. 
// 
// Since: 
//   fmc-1.0 
//------------------------------------------------------------------------------ 
#define _fmc_get_lb_count_32() g_n_lb_this_split.u32 
 
//+----------------------------------------------------------------------------- 
// Name: 
//   _fmc_get_result 
// 
// Declaration: 
//   t_result _fmc_get_result(void); 
// 
// Purpose: 
//   Get result of the transfer.  Typically used by the end_xfer callback. 
// 
// Arguments: 
//   None. 
// 
// Return: 
//   A t_result. 
// 
// Notes: 
//   None. 
// 
// Since: 
//   fmc-1.0 
//------------------------------------------------------------------------------ 
#define _fmc_get_result() g_fmc_rslt 
 
//------------------------------------------------------------------------------ 
// prototypes 
t_result fmc_wait_count_down_with_timeout(uint16) reentrant; 
t_result fmc_wait_blk_irq_with_timeout(uint16 ticks) reentrant; 
void fmc_dump_registers(void) reentrant; 
void fmc_select_cfc(void) reentrant; 
void fmc_select_smc(void) reentrant; 
void fmc_select_msc(void) reentrant; 
void fmc_select_sdc(void) reentrant; 
void fmc_select_nand(void) reentrant; 
t_result fmc_transfer(void) reentrant; 
 
//------------------------------------------------------------------------------ 
// externs 
extern xdata t_result g_fmc_rslt; 
extern xdata uint16 g_fmc_timeout; 
#define kbm_fmc_disable_auto_xfer       0x01 
#define kbm_fmc_end_burst_on_count_down 0x02 
#define kbm_fmc_xfer_512_byte_pkt       0x04 
 
// TRENTON WAS HERE - used with the temporary MS_TEST code in fmc.c 
//_fmc_set_options(0); 
#define kbm_fmc_hack_me                 0x08 
 
extern xdata uint8 g_fmc_options; 
extern xdata t_udw32 g_start_lb_this_xfer; 
extern xdata t_udw32 g_n_lb_this_xfer; 
extern xdata t_udw32 g_n_lb_this_split; 
extern xdata t_fmc_callback g_fmc_begin_xfer_callback; 
extern xdata t_fmc_callback g_fmc_end_xfer_callback; 
extern xdata t_fmc_callback g_fmc_begin_split_callback; 
extern xdata t_fmc_callback g_fmc_end_split_callback; 
extern xdata t_fmc_callback g_fmc_begin_burst_callback; 
// extern xdata t_fmc_callback g_fmc_intra_burst_callback; 
extern idata t_fmc_callback g_fmc_intra_burst_callback; 
extern xdata t_fmc_callback g_fmc_end_burst_callback; 
 
// prototype for a new default callback - to eliminate need to test for existence 
t_result fmc_dflt_callback(void) reentrant; 
 
//---eof------------------------------------------------------------------------