⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atapitest.c

📁 STi5518机顶盒ATAPI源代码!绝对超值!
💻 C
📖 第 1 页 / 共 5 页
字号:
/***********************************************************************COPYRIGHT (C) STMicroelectronics 2000Source file name : atapitest.c Test Harness for the ATA/ATAPI driver.************************************************************************/#include <stdio.h>#include <stdlib.h>#include <stdarg.h>#include <string.h>#include <time.h>#include <math.h>#define STTBX_INPUT#include "stlite.h"#include "stddefs.h"#include "stdevice.h"#include "stack.h"#include "stpio.h"#include "stsys.h"#include "debug.h"#include "sttbx.h"#include "stboot.h"#include "stevt.h"#include "stcommon.h"#include "statapi.h"#if defined(ATAPI_GPDMA)#include "stgpdma.h"#endif#if defined(ST_5514)#include "stcfg.h"#endif#include "stfpga.h"#include "atapitest.h"/* Test configuration information ------------------------------------------*//* Temporary variable; used to turn on and off some tracing in driver * (eg commands written to registers echoed, etc.) */extern BOOL Trace;/* Other Private types/constants ------------------------------------------ */#pragma ST_device(DU32)typedef volatile U32 DU32;/* We seem to need to reset the interconnect; see DoTheTests() for more  * detail. Define these if they don't already exist.  */#if defined(ST_5514)#if !defined(INTERCONNECT_BASE)    #define INTERCONNECT_BASE                   0x20010000#endif#if !defined(INTERCONNECT_CONFIG_CONTROL_REG_D)    #define INTERCONNECT_CONFIG_CONTROL_REG_D   0x0C#endif#if !defined(INTERCONNECT_REG_D_SOFT_RESET_HDDI)    #define INTERCONNECT_REG_D_SOFT_RESET_HDDI  0x00040000#endif#endif#define K   1024#if (defined(ST_5508) | defined(ST_5518))    #define     ATA_INTERRUPT_NUMBER                EXTERNAL_1_INTERRUPT    #define     ATA_BASE_ADDRESS      (volatile U32 *)             0x50000000    #define     ATA_HRD_RST           (volatile U16 *)             0x50000000#elif defined(ST_5512)#if defined(STATAPI_OLD_FPGA)    #define     ATA_INTERRUPT_NUMBER                EXTERNAL_0_INTERRUPT    #define     ATA_BASE_ADDRESS      (volatile U32 *)             0x60000000    #define     ATA_HRD_RST           (volatile U16 *)             0x60100000#else    #define     ATA_INTERRUPT_NUMBER                EXTERNAL_0_INTERRUPT    #define     ATA_BASE_ADDRESS      (volatile U32 *)             0x70B00000    #define     ATA_HRD_RST           (volatile U16 *)             0x70A00000#endif#elif defined(ST_5514)    #define     ATA_BASE_ADDRESS      (volatile U32 *)ST5514_HDDI_BASE_ADDRESS    #define     ATA_INTERRUPT_NUMBER    ST5514_HDDI_INTERRUPT    #define     ATA_HRD_RST           (volatile U16 *)ST5514_HDDI_BASE_ADDRESS + 0x84#endif#if defined(ST_5514)    #define DMA_PRESENT    #undef ATA_INTERRUPT_LEVEL    #define ATA_INTERRUPT_LEVEL		5#endif/*#define     ATA_INTERRUPT_LEVEL                7*//* Sizes of partitions */#define INTERNAL_PARTITION_SIZE          (ST20_INTERNAL_MEMORY_SIZE-1200)#define SYSTEM_PARTITION_SIZE            2*K*K#if defined(ST_5514) && !defined(UNIFIED_MEMORY)#define TINY_PARTITION_SIZE              2*K*K  /* 5514 emi */#else#define TINY_PARTITION_SIZE              512*K  /* 5514 um + all other  */#endif#define TEST_PARTITION_1       &the_system_partition#define TEST_PARTITION_2       &the_internal_partition#define TINY_PARTITION_1       &the_tiny_partition#define BLOCK_SIZE  512#define MEMTEST_STACK_SIZE      20480#define NUMBER_MEMTEST          17typedef struct {    task_t      TestTask;    tdesc_t     TestDesc;    U8          TestStack[MEMTEST_STACK_SIZE];    U8          FunctionNumber;    semaphore_t Semaphore;} TestBlock_t;/* Private variables ------------------------------------------------------ */ATAPI_Address_t     AddressTable[36]={   /*    Ch   Cl   H     S  */                                     {FALSE,{0x02,0x02,0x01,0x10}},  /* Sector variation*/                                     {FALSE,{0x02,0x02,0x01,0x13}},                                     {FALSE,{0x02,0x02,0x01,0x15}},                                     {FALSE,{0x02,0x02,0x01,0x19}},                                     {FALSE,{0x02,0x02,0x01,0x20}},                                     {FALSE,{0x02,0x02,0x01,0x23}},                                     {FALSE,{0x02,0x02,0x01,0x10}}, /* Head & Sector variation */                                     {FALSE,{0x02,0x02,0x01,0x13}},                                     {FALSE,{0x02,0x02,0x02,0x15}},                                     {FALSE,{0x02,0x02,0x03,0x19}},                                     {FALSE,{0x02,0x02,0x04,0x20}},                                     {FALSE,{0x02,0x02,0x05,0x10}},                                     {FALSE,{0x02,0x02,0x06,0x13}},                                     {FALSE,{0x02,0x02,0x07,0x15}},                                     {FALSE,{0x02,0x02,0x08,0x19}},                                     {FALSE,{0x02,0x02,0x09,0x20}},                                     {FALSE,{0x02,0x02,0x0A,0x23}},                                     {FALSE,{0x02,0x02,0x0B,0x10}},                                     {FALSE,{0x02,0x02,0x0B,0x13}},                                     {FALSE,{0x02,0x02,0x0C,0x15}},                                     {FALSE,{0x02,0x02,0x0D,0x19}},                                     {FALSE,{0x02,0x02,0x0E,0x20}},                                     {FALSE,{0x02,0x02,0x0E,0x19}},/* Cyl, Head & Sector variation*/                                     {FALSE,{0x02,0x02,0x04,0x20}},                                     {FALSE,{0x02,0x04,0x05,0x10}},                                     {FALSE,{0x02,0x07,0x06,0x13}},                                     {FALSE,{0x02,0x08,0x07,0x15}},                                     {FALSE,{0x02,0x0C,0x08,0x19}},                                     {FALSE,{0x02,0x0F,0x09,0x20}},                                     {FALSE,{0x02,0x20,0x0A,0x23}},                                     {FALSE,{0x02,0x10,0x0B,0x10}},                                     {FALSE,{0x02,0x30,0x0B,0x13}},                                     {FALSE,{0x02,0x40,0x0C,0x15}},                                     {FALSE,{0x02,0x50,0x0D,0x19}},                                     {FALSE,{0x02,0x60,0x0E,0x20}},                                     {FALSE,{0x02,0x70,0x02,0x23}}                                    };#define BUFFER_SIZES    6    U32 BuffSizes[BUFFER_SIZES]={1*K,2*K,4*K,8*K,16*K,32*K};                                        /* Test harness revision number */static U8 Revision[] = "1.3.0";/* Info to know what we have in the bus  */static ATAPI_Drive_t  Drives[2];/* Declarations for memory partitions */static U8               internal_block [INTERNAL_PARTITION_SIZE];static partition_t      the_internal_partition;#pragma ST_section      ( internal_block, "internal_section")static U8               system_block [SYSTEM_PARTITION_SIZE];static partition_t      the_system_partition;#pragma ST_section      ( system_block,   "system_section")static U8               tiny_block [TINY_PARTITION_SIZE];static partition_t      the_tiny_partition;#pragma ST_section      ( tiny_block,     "ncache_section")/* Temporary, for compatibility with old drivers (EVT) */partition_t             *system_partition = &the_system_partition;partition_t             *internal_partition = &the_internal_partition;semaphore_t		StepSemaphore;static U32 ClocksPerSec;static U32 ClockSpeed;static    ST_DeviceName_t         AtapiDevName           = "ATAPI0"; static    ATAPI_DeviceInfo_t      HardInfo;/* Event driver parameters */  static void ATAPI_Callback( STEVT_CallReason_t Reason,                            const ST_DeviceName_t RegistrantName,                            STEVT_EventConstant_t Event,                            const void *EventData,                            const void *SubscriberData_p );    static    STEVT_InitParams_t    EVTInitParams;static    STEVT_TermParams_t    EVTTermParams;static    ST_DeviceName_t       EVTDevName  = "EVT0";static    STEVT_OpenParams_t    EVTOpenParams;static    STEVT_Handle_t        EVTHandle;#if defined(ATAPI_GPDMA)static    ST_DeviceName_t       GPDMADevName = "GPDMA0";#endifstatic    STEVT_DeviceSubscribeParams_t SubsParams={ATAPI_Callback,                                            NULL,                                            NULL,                                            NULL};#if defined(ST_5518) | defined(ST_5508)static    ST_DeviceName_t         PIODevName           = "PIO_0"; #endif#if defined(ATAPI_MEMTEST)U8                      MemTestDataBuffer[1024];#endif#if defined(ST_5514)static U32 ClockFrequency = 0;static BOOL IsUDMA = FALSE;#endif/* Private function prototypes -------------------------------------------- */void DumpCmdStatus(STATAPI_CmdStatus_t CmdStatus);static void DoTheTests (void);static ST_ErrorCode_t SetTransferModePio(STATAPI_Handle_t Handle,                                          STATAPI_PioMode_t PioMode);#if defined(DMA_PRESENT)static ST_ErrorCode_t ClearSectors(STATAPI_Handle_t Handle,                                   ATAPI_Address_t *Addr,                                   U8 BlockNo);static ST_ErrorCode_t SetTransferModeDma(STATAPI_Handle_t Handle,                                          STATAPI_DmaMode_t DmaMode);#endif#if defined(ST_5514)static ST_ErrorCode_t DoCfg(void);#endif#if defined(MEDIAREF)static ST_ErrorCode_t ATAPI_UndoClkGen(void);#endif/* Ancillary Test routines */static void  ParseAndShow(ATAPI_DeviceInfo_t *Out,U8 *Data);static ST_ErrorCode_t SeekTime(STATAPI_Handle_t Handle,U16 Iter,U32 *Acum);static ST_ErrorCode_t WriteSeekTime(STATAPI_Handle_t Handle,U16 Iter,U32 *Acum);static ST_ErrorCode_t ReadSeekTime(STATAPI_Handle_t Handle,U16 Iter,U32 *Acum);static ST_ErrorCode_t ThrPutReadSimple(STATAPI_Handle_t Handle,U16 Iter,U32 *Acum);static ST_ErrorCode_t ThrPutWriteSimple(STATAPI_Handle_t Handle,U16 Iter,U32 *Acum);static ST_ErrorCode_t ThrPutWriteMultiple(STATAPI_Handle_t Handle,U8 Mode,U32 *Acum);static ST_ErrorCode_t ThrPutReadMultiple(STATAPI_Handle_t Handle,U8 Mode,U32 *Acum);#if defined(DMA_PRESENT)static ST_ErrorCode_t ThrPutReadSimpleDma(STATAPI_Handle_t Handle,U16 Iter,U32 *Acum);static ST_ErrorCode_t ThrPutReadMultipleDma(STATAPI_Handle_t Handle,U8 Mode,U32 *Acum);static ST_ErrorCode_t ThrPutWriteMultipleDma(STATAPI_Handle_t Handle,U8 Mode,U32 *Acum);#endifST_ErrorCode_t  SimpleRWTest(STATAPI_Handle_t Handle,                             ATAPI_Address_t *Addr,                             U8 BlockNo);ST_ErrorCode_t  SimpleRWTestDma(STATAPI_Handle_t Handle,                                ATAPI_Address_t *Addr,                                U8 BlockNo);ST_ErrorCode_t  MultipleRWTest(STATAPI_Handle_t Handle,                             ATAPI_Address_t *Addr,                             U8 BlockNo, U8 Mode);  ST_ErrorCode_t  ReadTOCTest(STATAPI_Handle_t Handle);ST_ErrorCode_t  DoLBA48Test(STATAPI_Handle_t Handle);ST_ErrorCode_t  DoSetGetTimingTests(STATAPI_Handle_t Handle);/* Test Routines */static ATAPI_TestResult_t ATAPI_TestSimpleAPI(ATAPI_TestParams_t * TestParams);                                                        static ATAPI_TestResult_t ATAPI_TestAPINormal(ATAPI_TestParams_t * TestParams);static ATAPI_TestResult_t ATAPI_TestAPIErrant(ATAPI_TestParams_t * TestParams);static ATAPI_TestResult_t ATAPI_TestIdentify(ATAPI_TestParams_t * TestParams);static ATAPI_TestResult_t ATAPI_TestPerformance(ATAPI_TestParams_t * TestParams);static ATAPI_TestResult_t ATAPI_TestPacket(ATAPI_TestParams_t * TestParams);#ifdef SOAK_TESTstatic ATAPI_TestResult_t ATAPI_SoakTest(ATAPI_TestParams_t * TestParams);#endif#ifdef ATAPI_MEMTESTstatic ATAPI_TestResult_t   ATAPI_MemoryTest(ATAPI_TestParams_t *TestParams);void MemoryTest_Task (void *Data);#endif/* ------------------------------------------------------------------------- *//* Test table */static ATAPI_TestEntry_t ATAPITestTable[] ={#ifdef ATAPI_MEMTEST    {        ATAPI_MemoryTest,        "Test memory usage",        1    },#endif    {        ATAPI_TestIdentify,        "Retrieve informaton about the device connected",        1                                  },    {        ATAPI_TestPacket,        "Test the packet command interface (only ATAPI)",        1                                  },    {        ATAPI_TestSimpleAPI,        "Basical API functionality test",        1                                   },    {        ATAPI_TestAPINormal,        "Normal Use of the API",        1                                 },    {        ATAPI_TestAPIErrant,        "Errant use of the API",        1                                   },    {        ATAPI_TestPerformance,        "Calculate some timing parameters (Only ATA) ",        1                                  },    #ifdef SOAK_TEST    {        ATAPI_SoakTest,        "SOAK TEST:Check all sectors using (only ATA)",        1    },    #endif    { 0, "", 0 }};/* Globally used function prototypes */static void DisplayError( ST_ErrorCode_t ErrorCode );static void DisplayErrorNew(ST_ErrorCode_t error);static BOOL CompareData (const U8 *b1, const U8 *b2, U32 size);ST_ErrorCode_t EvtError;static BOOL     Quiet=TRUE;/***********************************************************************   TEST HARNESS - A call to DoTheTests() is made from within    main. This effectively isolates the 5512 init code within main().    This allows easy reuse as your own custom tests can be added to    this function without altering the setup code.***********************************************************************/#if defined(ST_5514)/****************************************************************************Name         : SwapStringDescription  :     Byte-swaps N words into a string; intended for use with    info block on the STi5514 (since bytes come out byteswapped)Parameters   :     U16     *Info           Pointer to source block    U8      *String         Pointer to destination buffer    U32     LengthInWords   How many words to swap                   Return Value :     void ****************************************************************************/static void SwapString(U16 *Info, U8 *String, U32 LengthInWords){    U32 i, j;    for (i = 0, j = 0; i < LengthInWords; i++)    {        String[j++] = (Info[i] >> 8) & 0xff;        String[j++] = Info[i] & 0xff;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -