📄 fmcapp.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.
____________________________________________________________________________
____________________________________________________________________________
fmcapp.c - the application interface manager and main application thread.
____________________________________________________________________________
comments tbd
____________________________________________________________________________
Revision History
Date Who Comment
________ ___ _____________________________________________________________
09/14/01 cds moved from atapi.c to help isolate the stages. this abstraction
could cost some performance, however.
05/31/00 tbh initial version
============================================================================*/
///////////////////////////////////////////////////////////////////////////////
//
// USER INTERFACE MODULE
//
// mass storage, bulk only, atapi
//
////////////////////////////////////////////////////////////////////////////////
#include "fmc.h"
// -----------------------------------------------------------------------------
// Begin Source
// -----------------------------------------------------------------------------
//------------------------------------------------------------------------------
// special smsc hardware debug registers
//------------------------------------------------------------------------------
bit g_device_present ;
bit g_poll_for_drq ;
bit g_use_dma ;
bit g_disable_iordy ;
bit g_data_direction ; /* 1 = k_data_in, 0 = k_data_out */
bit g_prevent_reset ; /* 1=k_true, 0=k_false. Don't keep resetting the device during enumeration */
bit g_device_present ; /* 1=k_true, 0=k_false. This doesn't mean the device is an ATAPI device! */
bit g_forced_phase_error;
bit g_tx_missed_ack;
bit g_doing_dma ;
// device type
#define k_device_type_ata 0
#define k_device_type_atapi 1
#define k_device_type_floppy 2
// ata device characteristics
uint8 g_dev_max_dma_mode ; /* represents max DMA mode supported by the device */
//------------------------------------------------------------------------------
// global variables - these can be cleaned up, and probably placed into
// our x_data buffer, freeing up ram for some other optimization
//------------------------------------------------------------------------------
uint8 g_ix_ata_thread;
uint32 g_original_request_length ;
// pio DRQ-block transfer variables
uint32 g_remaining_drq_length ;
uint16 g_available_pkt_length ;
uint16 g_available_pkt ; // offset of next available byte. k_data_in: next free, k_data_out: next valid
uint8 g_available_buffer ; // start sending to host on.... 0 = A , 1 = B
uint8 g_last_packet ;
uint16 g_ata_data_xfer_length ; /* Data Transfer Length for use ONLY with the Ata state machine */
static void fmcapp_cfc_init_done() reentrant ;
//------------------------------------------------------------------------------
// <<< ATA INTERFACE - MANAGER >>>
// Target MCU:
// 200
// Declaration:
// uint8 ata_mngr(t_message *msgp);
// Purpose:
// This is the manager for all things related to the ata interface.
// Arguments:
// None.
// Return:
// k_success
// K-error
// Note:
// Do NOT yield from this routine. It is NOT part of any thread. It does
// not execute in an any thread's context. Yielding from within this function
// will cause your firmware to crash.
//------------------------------------------------------------------------------
uint8 fmcapp_mngr(t_message *msgp) reentrant
{
uint8 i ;
TRACE1(328, fmc, 0, "+fmcapp_mngr() msg_id:%d", message_rd_id(msgp));
switch(message_rd_id(msgp))
{
//--------------------------------------------------------------------------
// always return k_success for these.
//--------------------------------------------------------------------------
case k_msg_initialize:
TRACE0(329, fmcapp, 1, "k_msg_initialize");
#ifdef TRACE
// print out compile-time options
fmcapp_trace_compiled_opts() ;
#endif
// create thread
g_ix_ata_thread = thread_create(fmcapp_create_thread, NULL, k_true);
// register endpoints - do nothing here as only the default control pipe is used
ctl_bind_endpoint(2, g_ix_ata_thread, NULL);
ctl_bind_endpoint(2, g_ix_ata_thread, NULL);
// register interfaces - must jive with the configuration descriptor...
ctl_bind_interface(0, fmcapp_cpex);
// set up the gpio interface
gpio_initialize();
// application initializations
for(i=0;i<k_sz_ata_dev_str_prd;i++)
{
x_ata_dev_str_prd[i]=0;
}
for(i=0;i<k_sz_ata_dev_str_ser;i++)
{
x_ata_dev_str_ser[i]=0;
}
#ifdef k_support_eeprom
atapi_program_eeprom() ;
#endif
return k_success;
case k_msg_usbrst:
trace0(0, atapi, 1, "k_msg_usbrst (USB RESET)");
// If ATA/ATAPI Device is not powered up, power it up here
thread_set_sync(g_ix_ata_thread, kbm_sync_usbrst);
g_available_pkt_length = 0x0000;
x_busy_count = 0;
return k_success;
case k_msg_resume:
TRACE0(330, fmcapp, 0, "k_msg_resume");
// Signal ATA/ATAPI Device to power up here
if(x_ata_dev_cmdset_support_1&kbm_ata_iddev_fs_power_mgmt)
{
/* do bad bad things here... */
TRACE0(331, fmcapp, 0, "resuming thread by restarting the thread") ;
g_thread[g_ix_ata_thread].bits_got = (kbm_sync_create);
g_thread[g_ix_ata_thread].bits_reg = (kbm_sync_create);
g_thread[g_ix_ata_thread].entry = fmcapp_create_thread ;
}
return k_success;
case k_msg_suspend:
trace0(0, atapi, 0, "k_msg_suspend");
// Signal ATA/ATAPI Device to power down here
if(x_ata_dev_cmdset_support_1&kbm_ata_iddev_fs_power_mgmt)
{
/* not a DFA! */
ata_sleep() ;
}
// process the usb suspend notificaion
// propagate to the app specific ndp mngrs - in this case, there are none
return k_success;
default:
trace0(0, atapi, 1, "error: ata_mngr(unexpected message)");
// unexpected message
return k_error;
}
// unexpected message
return k_error;
}
//------------------------------------------------------------------------------
// <<< ATA INTERFACE - CONTROL PIPE EXTENSION >>>
// Target MCU:
// 200
// Declaration:
// uint8 ata_cpex(t_message *msgp);
// Purpose:
// Handles requests targeted to its interface: standard, class, vendor.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -