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

📄 pccard.cpp

📁 通过PCCARD SPEC测试笔记本的外部接口的电压是正常
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include <dpmi.h>
#include <sys\segments.h>
#include <pc.h>
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <signal.h>
#include <setjmp.h>
#include <time.h>
#include <debug\dbgcom.h>
#include <debug\v2load.h>
#include <sys\dxe.h>
#include <conio.h>

#include <common.h>
#include <misc.h>
#include <gfx.h>
#include <files.h>
#include <stl.h>
#include <ftrt.h>

#include "usd\pccard.h"


FT_ST PCCardList[] = 
{ 
  { "32 bit CardBus Test", CardBusTest }
};

FT_NAME PCCardDsc =
{
  "PCCard",
  "v1.00.01",
  "This program will test the PCMCIA socket & controller."
};

FT_START(PCCardApp,PCCardDsc,PCCardList,1);


static PCI_DEVICE CardBusBridge[] =
{
    { 0x1217 , 0x7134 , "O2 Oz711Mp1"   } 
};    

const int CardBusBridgeNum = ASIZE(CardBusBridge); /* supported cardbus bridge number */

static char *RcFile[6] = { NULL };   //PCI resource comparison data filename 
static char *PciCfgFile = NULL;  //PCI configuration space comparison filename
static DWORD PciCfgBase = 0;     //PCI configuration space comparison data offset base
static DWORD PciCfgLimit = 0;    //PCI configuration space comparison data offset limit
static DWORD RcBase[6] = { 0 };  //PCI resource comparison data offset base
static DWORD RcLimit[6] = { 0 }; //PCI resource comparison data offset limit


void PCCardApp::help()
{
  FTRT::help();

  printf(HELP_MSG);
}


PCCardApp::PCCardApp(FT_NAME _ft_name,FT_ST* _ft_tab,int _tab_size)
:FTRT(_ft_name,_ft_tab,_tab_size)
{
}



BOOL PCCardApp::param(int argc,char** argv)
{
   BOOL rc1 = FTRT::param(argc,argv);

   BOOL rc2 = TRUE;

   for(int i=1;i<argc;i++)
   {
      rc2 = FALSE;
   }

   if(!rc1 && !rc2)
   {
        printf("Invalid parameter!\n");
        return FALSE;
   }
   else 
        return TRUE;
}


BOOL StartCard(DWORD& bus,DWORD& dev,DWORD& func)
{
   CardBus cb;

   if(!cb.bOK)
   {
      printf("Unknown CardBus bridge type!\n");
      return FALSE;  
   }

   printf("CardBus controller is %s\n\n",cb.BridgeName);

   BOOL rc = cb.InitBridge();
   if(!rc)
   {
       printf("Initialize CardBus bridge failed!\n");
       return FALSE;  
   }

   rc = cb.DetectCard();
   if(!rc)
       return FALSE;  

   rc = cb.PowerOn();
   if(!rc)
       return FALSE;  

   rc = cb.InitCard();
   if(!rc)
       return FALSE;  

   bus = cb.cdev[0]->bus;
   dev = cb.cdev[0]->dev;
   func = cb.cdev[0]->func;

   return TRUE; 
}


BOOL PCCardApp::Configure(int type)
{
  BOOL rc = FTRT::Configure(type);
  if(!rc ||!ini)
     return FALSE; 

  if(type==RUN_CONFIG_NEW)
  {
     ini->AppendBlock("PC Card");
     ini->AppendComment("(Manual) PCI configuration space comparison data filename (NA/filename).");
     ini->AppendString("PCI CFG","card_pci.dat");
     ini->AppendComment("(Manual) PCI CFG space test range. (XX,XX)");
     ini->AppendString("PCI CFG Range","0,0xFF");
     ini->AppendComment("(Manual) PCI resource 1 comparison data filename (NA/filename).");
     ini->AppendString("PCI RC1","NA");
     ini->AppendComment("(Manual) PCI resource 1 test range. (XX,XX)");
     ini->AppendString("PCI RC1 Range","0,0xFF");
     ini->AppendComment("(Manual) PCI resource 2 comparison data filename (NA/filename).");
     ini->AppendString("PCI RC2","NA");
     ini->AppendComment("(Manual) PCI resource 2 test range. (XX,XX)");
     ini->AppendString("PCI RC2 Range","0,0xFF");
     ini->AppendComment("(Manual) PCI resource 3 comparison data filename (NA/filename).");
     ini->AppendString("PCI RC3","NA");
     ini->AppendComment("(Manual) PCI resource 3 test range. (XX,XX)");
     ini->AppendString("PCI RC3 Range","0,0xFF");
     ini->AppendComment("(Manual) PCI resource 4 comparison data filename (NA/filename).");
     ini->AppendString("PCI RC4","NA");
     ini->AppendComment("(Manual) PCI resource 4 test range. (XX,XX)");
     ini->AppendString("PCI RC4 Range","0,0xFF");
     ini->AppendComment("(Manual) PCI resource 5 comparison data filename (NA/filename).");
     ini->AppendString("PCI RC5","NA");
     ini->AppendComment("(Manual) PCI resource 5 test range. (XX,XX)");
     ini->AppendString("PCI RC5 Range","0,0xFF");
     ini->AppendComment("(Manual) PCI resource 6 comparison data filename (NA/filename).");
     ini->AppendString("PCI RC6","NA");
     ini->AppendComment("(Manual) PCI resource 6 test range. (XX,XX)");
     ini->AppendString("PCI RC6 Range","0,0xFF");

#if FT_MODE == FT_SINGLE

     printf("Generating new INI file %s...\n",ini->filename);   
     RedirectStdoutEx("NUL",FALSE);   

#endif

     DWORD bus,dev,func;
   
     rc = StartCard(bus,dev,func);
     if(!rc)
        return FALSE;      

     DevPCI cdev(bus,dev,func,FALSE); 

     FileItem pci_cfg("card_pci.dat");

     rc = pci_cfg.CreateNew();   
     if(!rc)
        return FALSE;   

     for(int i=0;i<=0xFF;i++)
     {
        char item[25];
        sprintf(item,"OFFSET 0x%08lX",i);

        pci_cfg.AppendHEX(item,cdev.GetB(i));
     }      

#if FT_MODE == FT_SINGLE

     RestoreStdoutEx();

#endif
  
     return TRUE;   
  }
  else if(type==RUN_CONFIG_OLD)
  {
#if FT_MODE == FT_SINGLE

     printf("Reconfiguring old INI file %s...\n",ini->filename);   
     RedirectStdoutEx("NUL",TRUE);   

#endif

     DWORD bus,dev,func;   

     rc = StartCard(bus,dev,func);
     if(!rc)
        return FALSE;

     DevPCI cdev(bus,dev,func,FALSE);   

     if(PciCfgFile)
     {
        FileItem pci_cfg(PciCfgFile);

        rc = pci_cfg.CreateNew();   
        if(!rc)
            return FALSE;   

        for(int i=PciCfgBase;i<=PciCfgLimit;i++)
        {
           char item[25];
           sprintf(item,"OFFSET 0x%08lX",i);
           pci_cfg.AppendHEX(item,cdev.GetB(i));
        }      
     }   
     
     for(int i=0;i<6;i++)
        if(RcFile[i])
        {
           FileItem pci_rc(RcFile[i]);

           rc = pci_rc.CreateNew();
           if(!rc)
               return FALSE;      

           if(cdev.rc[i].type==PCI_RC_NA)
               return FALSE;

           for(int j=RcBase[i];j<=RcLimit[i];j++)
           {
               char item[25];
               sprintf(item,"OFFSET 0x%08lX",j);
               pci_rc.AppendHEX(item,cdev.RcGetB(i,j));
           }      
        }   

     RestoreStdoutEx();

     return TRUE;            
  }
  else if(type==RUN_CONFIG_LOAD)
  {
#if FT_MODE == FT_SINGLE

     if(!FileExist(ini->filename))
     {
         printf("Can not find initialize file %s!\n",ini->filename);
         return FALSE; 
     }           

#endif

     PciCfgFile = new char [20];
     if(!PciCfgFile)
        return FALSE;   

     rc = ini->GetString("PC Card","PCI CFG",PciCfgFile);
     if(!rc || !stricmp(PciCfgFile,"NA"))
     {
        delete PciCfgFile;
        PciCfgFile = NULL;
     }   

     char pBase[20],pLimit[20];
           
     ini->GetStrColumn("PC Card","PCI CFG Range",0,pBase);
     ini->GetStrColumn("PC Card","PCI CFG Range",1,pLimit);
     PciCfgBase = strtoul(pBase,NULL,16);
     PciCfgLimit = strtoul(pLimit,NULL,16);       

     for(int i=0;i<6;i++)
     {
        RcFile[i] = new char [20];
        if(!RcFile[i])
           return FALSE;

        char item[20];
        sprintf(item,"PCI RC%d",i);

        rc = ini->GetString("PC Card",item,RcFile[i]);
        if(!rc || !stricmp(RcFile[i],"NA"))
        {
           delete RcFile[i];
           RcFile[i] = NULL;
        }   
         
        sprintf(item,"PCI RC%d Range",i);
        ini->GetStrColumn("PC Card",item,0,pBase);
        ini->GetStrColumn("PC Card",item,1,pLimit);
        RcBase[i] = strtoul(pBase,NULL,16);
        RcLimit[i] = strtoul(pLimit,NULL,16);       
     }//for   

     return TRUE;   
  }//else if

  return FALSE;
}

           
int CardBusTest(int sub)
{
   printf("Test CardBus Socket %d :\n\n",sub+1);

   CardBus cb;

   if(!cb.bOK)
   {
      printf("Unknown CardBus bridge type!\n");
      return FT_FAIL;  
   }

   printf("CardBus controller is %s\n\n",cb.BridgeName);

   BOOL rc = cb.InitBridge();
   if(!rc)
   {
       printf("Initialize CardBus bridge failed!\n");
       return FT_FAIL;
   }

   rc = cb.DetectCard();
   if(!rc)
       return FT_FAIL;

   rc = cb.PowerOn();
   if(!rc)
       return FT_FAIL;

   rc = cb.InitCard();

⌨️ 快捷键说明

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