www.pudn.com > SMSC USB2.0.zip > mscbot.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. 
  ____________________________________________________________________________ 
  ____________________________________________________________________________ 
 
  mscbot.h - mass storage class bulk only transport 
  ____________________________________________________________________________ 
 
  comments tbd 
  ____________________________________________________________________________ 
 
  Revision History 
  Date      Who  Comment 
  ________  ___  _____________________________________________________________ 
  05/31/00  tbh  initial version 
  07/27/01  tbh  removed prototype for wait_create entry point 
  10/04/01  tbh  tweaked during performance optimizations of '201 mass storage 
  03/11/02  tbh  added bit g_force_card_establish.  then i removed it. 
  03/18/02  tbh  _mscbot_has_residue was returning the opposite truth value 
  03/22/02  tbh  added _mscbot_residue_8 _mscbot_residue_32 
  06/10/02  tbh  changed prototypes for non bot layer entry points for hpthreads 
  07/30/02  ds   Moved _endpoint_unmask_innak(k_rx_pipe) macro to mscbot.h so that sd.c can access it.                
  09/26/02  cds  exported mscbot_tx_data_buffer() as a single function which 
                 can be used to transmit a buffer of up to 64 bytes as the  
                 entire data portion of an xfer. 
  10/01/02  ds   Added prototype for function mscbot_rx_data_buffer     
  10/02/02  ds   Changed the prototype for function mscbot_rx_data_buffer, so as to return a value.            
  10/02/02  cds  moved g_bot_cbw into xdata to regain data/stack space to prevent   
                 stack overflows on hierarchy-heavy media protocols.              
============================================================================*/ 
 
//------------------------------------------------------------------------------ 
// transfer directions 
#define k_dir_read (1==1) 
#define k_dir_write !k_dir_read 
typedef t_bool t_xfer_dir; 
 
//------------------------------------------------------------------------------ 
// data direction 
#define k_data_in  k_dir_read 
#define k_data_out k_dir_write 
 
//------------------------------------------------------------------------------ 
// command descriptor block 
typedef uint8 t_cdb[16]; 
//typedef struct s_cdb 
//{ 
// tbh says "hmmmmm..." 
// some enterprising youth should create all of the unions of all of 
// the commands so values can be accessed by field name instead of offset, 
// then go retrofit the code to reference the fields.  the proof is left 
// to the reader. 
//} t_cdb; 
 
//------------------------------------------------------------------------------ 
// command block wrapper 
typedef struct s_cbw 
{ 
  uint8 dwCBWSignatureLo;   // dwCBWSignature: the constant 0x55 
  uint8 dwCBWSignatureHl;   // dwCBWSignature: the constant 0x53 
  uint8 dwCBWSignatureLh;   // dwCBWSignature: the constant 0x42 
  uint8 dwCBWSignatureHi;   // dwCBWSignature: the constant 0x43 
  uint8 dwCBWtagLo;         // dwCBWtag: (lsw lsb) 
  uint8 dwCBWtagHl;         // dwCBWtag: (lsw msb) 
  uint8 dwCBWtagLh;         // dwCBWtag: (msw lsb) 
  uint8 dwCBWtagHi;         // dwCBWtag: (msw msb) 
  uint8 dwCBWXferLengthLo;  // dwCBWXferLength: (lsw lsb) number of bytes to transfer 
  uint8 dwCBWXferLengthHl;  // dwCBWXferLength: (lsw msb) 
  uint8 dwCBWXferLengthLh;  // dwCBWXferLength: (msw lsb) 
  uint8 dwCBWXferLengthHi;  // dwCBWXferLength: (msw msb) 
  uint8 bCBWFlags;          // bmCBWFlags: 
                            //  Bit 7: direction - the device shall ignore this bit if the 
                            //  dCBWDataTransferLength field is zero, otherwise: 
                            //   0 = Data-Out from host to the device, 
                            //   1 = Data-In from the device to the host. 
                            //  Bit 6: obsolete. The host shall set this bit to zero. 
                            //  Bits 5..0: reserved - the host shall set these bits to zero. 
  uint8 bCBWlun;            // bmCBWFlags: 
  uint8 bCBWCBLength;       // bCBWLength: 0x01..0x10 
  t_cdb cdb;                // CBWCB: the command descriptor block 
} t_cbw; 
// bCBWFlags values 
#define kbm_cbw_dir_d2h 0x80 
 
//------------------------------------------------------------------------------ 
// command status wrapper 
typedef struct s_csw 
{ 
  uint8 dwCSWSignatureLo;  // dwCSWSignature: the constant 0x53 
  uint8 dwCSWSignatureHl;  // dwCSWSignature: the constant 0x42 
  uint8 dwCSWSignatureLh;  // dwCSWSignature: the constant 0x53 
  uint8 dwCSWSignatureHi;  // dwCSWSignature: the constant 0x55 
  uint8 dwCSWtagLo;        // dwCSWtag: (lsw lsb) 
  uint8 dwCSWtagHl;        // dwCSWtag: (lsw msb) 
  uint8 dwCSWtagLh;        // dwCSWtag: (msw lsb) 
  uint8 dwCSWtagHi;        // dwCSWtag: (msw msb) 
  uint8 dwCSWResidueLo;    // dwCBWXferLength: (lsw lsb) number of bytes not transferred 
  uint8 dwCSWResidueHl;    // dwCBWXferLength: (lsw msb) 
  uint8 dwCSWResidueLh;    // dwCBWXferLength: (msw lsb) 
  uint8 dwCSWResidueHi;    // dwCBWXferLength: (msw msb) 
  uint8 bCSWStatus;        // bCSWStatus: 
                           //  00h command Passed ("good status") 
                           //  01h command failed 
                           //  02h phase error 
                           //  03h to FFh reserved 
} t_csw; 
// a type for function returns of csw status values 
typedef uint8 t_csw_status; 
// bCSWStatus values 
#define k_command_passed 0x00 
#define k_command_failed 0x01 
#define k_phase_error    0x02 
 
//------------------------------------------------------------------------------ 
#define k_tx_pipe 2 
#define k_rx_pipe 2 
 
//------------------------------------------------------------------------------ 
// mscbot class specific requests 
#define k_hci_mscbot_reset     0x21FF 
#define k_hci_mscbot_getmaxlun 0xA1FE 
 
//------------------------------------------------------------------------------ 
// macros 
#define _mscbot_has_residue() (!_u32_equ_0(g_bot_data_len)) 
#define _mscbot_set_residue(__n); { g_bot_data_len.u32 = (uint32)(__n); } 
#define _mscbot_zero_residue(); { g_bot_data_len.u32 = 0; } 
#define _mscbot_decr_residue(__n); { g_bot_data_len.u32 -= (uint32)(__n); } 
#define _mscbot_incr_residue(__n); { g_bot_data_len.u32 += (uint32)(__n); } 
#define _mscbot_residue_32() g_bot_data_len.u32 
#define _mscbot_residue_8(__mswmsb, __mswlsb, __lswmsb, __lswlsb)              \ 
{                                                                              \ 
  (__mswmsb) = g_bot_data_len.u8.hi;                                           \ 
  (__mswlsb) = g_bot_data_len.u8.lh;                                           \ 
  (__lswmsb) = g_bot_data_len.u8.hl;                                           \ 
  (__lswlsb) = g_bot_data_len.u8.lo;                                           \ 
} 
 
//------------------------------------------------------------------------------ 
// prototypes 
uint8 mscbot_mngr(t_message *msgp) reentrant; 
uint8 mscbot_cpex(t_message *msgp) reentrant; 
void mscbot_thread_wait_create(void) reentrant; 
 
//------------------------------------------------------------------------------ 
// prototypes from mscbot.c used by the mscbot's helper dfa's 
void fgnd_hpbot_wait_create(void) reentrant; 
void fgnd_hpbot_wait_status_start(uint8) reentrant; 
 
//------------------------------------------------------------------------------ 
// externs from device.c (in here cause device.h is part of minimos...) 
extern uint8 g_ix_dev_thread; 
 
//------------------------------------------------------------------------------ 
// externs from mscbot.c used by the mscbot's helper dfa's 
extern xdata t_cbw g_bot_cbw;            // command block wrapper 
extern t_udw32 g_bot_data_len;     // number of bytes to transfer 
extern t_xfer_dir g_bot_xfer_dir;  // k_dir_read or k_dir_write 
#if 0 
extern bit g_ndp2_tx_stalled;      // set when ndp2 is tx stalled 
#endif 
 
//------------------------------------------------------------------------------ 
//------------------------------------------------------------------------------ 
#define _endpoint_unmask_innak(k_rx_pipe);                                     \ 
{                                                                              \ 
  _mcu_register_wr(x_isr_nak, (1 << (2 * k_rx_pipe + 1)));                     \ 
  _mcu_register_clrbit(x_imr_nak, 2 * k_rx_pipe + 1);                          \ 
} 
 
//------------------------------------------------------------------------------ 
//------------------------------------------------------------------------------ 
void mscbot_tx_data_buffer(uint8* buffer, uint8 length) reentrant ; 
uint8 mscbot_rx_data_buffer(uint8* buffer, uint8 length) reentrant ; 
 
 
//---eof------------------------------------------------------------------------