2008년 8월 14일 목요일

maxpaper for scrapbook

maxpaper is the freeware with any restriction. keyword : maxpaper,id photo, scrapbook,baby album, photofinishing, 맥스페이퍼,사진인화,

2008년 6월 23일 월요일

maxpaper photo album, idphoto editor software

maxpaper photo album, idphoto editor software

2008년 4월 11일 금요일

dpcutil for delphi [Source code included]

This program is pascal version for Nexys 2 FPGA Board


 


Memory Transfer [ PC <-> Memory, Flash ]


To use this program , You must download and install Digilent Acept Suite


 







  

  • http://www.digilentinc.com
  • Xilinx Spartan-3E FPGA, 500K or 1200K gate
  • USB2 port providing board power, device configuration, and high-speed data transfers
  • Works with ISE/Webpack and EDK
  • 16MB fast Micron PSDRAM
  • 16MB Intel StrataFlash Flash R
  • Xilinx Platform Flash ROM
  • High-efficiency switching power supplies (good for battery-powered applications
  • 50MHz oscillator, plus a socket for a second oscillator
  • 59 FPGA I/O’s routed to expansion connectors (one high-speed Hirose FX2 connector with 21 differential pairs and four 2x6-pin headers)
  • All I/O signals are ESD and short-circuit protected, ensuring a long operating life in any environment.
  • On-board I/O includes eight LEDs, four-digit seven-segment display, four pushbuttons, eight slide switches
  • Ships in a DVD case with a high-speed USB2 cable


 


dpcutil.pas







//------------------------------------------------------------------------------
//
// dpcutil.dll Interface Code
// ----------------------------------------------------------------------------
//
// Original Code : http://www.digilentinc.com/
//                 dpcdefs.h
//                 dpcutil.h
//                 dpcutil.lib
//
//                 dpcuitl.dll [Ver 1.9.0.0]
//
// Delphi Code   : Translated and Modified
//                 Simon, Choi
//                 http://www.kredix.com , http://www.maxpaper.com
//                 simonsayz@naver.com
//               
//
// History       : 2008.04.09 1st Translation [Ver 0.1]
//
//
// Known Bugs    : dpcutil.dll [Ver 1.7] : Error in Data Transfer
//
//------------------------------------------------------------------------------


Unit DpcUtil;


interface


Uses
 Windows;


Type
 TTrID    = Word;    // Transaction ID type
 PTrID    = ^TTrID;  //
 TErc     = Integer; // Error code type
 TTrt     = Integer; // Transaction type
 TSts     = Integer; // Transaction status type
 TIfd     = Integer; // Interface ID
 TIfp     = LongInt;
 TDvct    = Integer; // Interface device type


 // Transaction status structure,
 TTrs     = Packed Record  // typedef struct tagTRS {
             trt  : TTrt;  // transaction type
             TrID : TTrID; // transaction ID
             sts  : TSts;  // status of transaction
             erc  : TErc;  // error code for transaction
            end;
 TDpcMsg = (dmTrc,   // Transaction Type   Message
            dmDvct,  // Device Type        Message
            dmErc,   // Error Code         Message
            dmSts);  // Transaction Status Message


Const
  cchDevNameMax       = 32;
  cbBlockSize         = 1000;
  // Transaction type codes
  trtOpenJtag         : TTrt  = $01;
  trtCloseJtag        : TTrt  = $02;
  trtSetTmsTdiTck     : TTrt  = $03;
  trtPutTdiBits       : TTrt  = $04;
  trtPutTmsTdiBits    : TTrt  = $05;
  trtGetTdoBits       : TTrt  = $06;
  trtSetJtsel         : TTrt  = $07;
  trtOpenSpi          : TTrt  = $21;
  trtCloseSpi         : TTrt  = $22;
  trtEnableSpi        : TTrt  = $23;
  trtDisableSpi       : TTrt  = $24;
  trtSetSpiSelect     : TTrt  = $25;
  trtSetSpiMode       : TTrt  = $26;
  trtPutSpiByte       : TTrt  = $27;
  trtPutSpi           : TTrt  = $28;
  trtGetSpi           : TTrt  = $29;
  trtOpenData         : TTrt  = $81;
  trtCloseData        : TTrt  = $82;
  trtSetDataPins      : TTrt  = $83;
  trtGetDataPins      : TTrt  = $84;
  trtSendDataByte     : TTrt  = $85;
  trtGetDataByte      : TTrt  = $86;
  trtSendDataBytes    : TTrt  = $87;
  trtGetDataBytes     : TTrt  = $88;
  trtSendDataStream   : TTrt  = $89;
  trtGetDataStream    : TTrt  = $8a;
  trtSendGetDataBytes : TTrt  = $8b;
  trtGetVersion       : TTrt  = $8c;
  trtStreamWrite      : TTrt  = $8d;
  trtStreamRead       : TTrt  = $8e;


  dvctEthernet        : TDVCT = $00;
  dvctUSB             : TDVCT = $01;
  dvctSerial          : TDVCT = $02;
  dvctParallel        : TDVCT = $03;


  // Error codes
  ercNoError          : TErc = 0000;
  ercConnReject       : TErc = 3001;
  ercConnType         : TErc = 3002;
  ercConnNoMode       : TErc = 3003;
  ercInvParam         : TErc = 3004;
  ercInvCmd           : TErc = 3005;
  ercUnknown          : TErc = 3006;
  ercJtagConflict     : TErc = 3007;
  ercNotImp           : TErc = 3008;
  ercNoMem            : TErc = 3009;
  ercTimeout          : TErc = 3010;
  ercConflict         : TErc = 3011;
  ercBadPacket        : TErc = 3012;
  ercInvOption        : TErc = 3013;
  ercAlreadyCon       : TErc = 3014;
  ercConnected        : TErc = 3101;
  ercNotInit          : TErc = 3102;
  ercCantConnect      : TErc = 3103;
  ercAlreadyConnect   : TErc = 3104;
  ercSendError        : TErc = 3105;
  ercRcvError         : TErc = 3106;
  ercAbort            : TErc = 3107;
  ercTimeOutEx        : TErc = 3108; // ??
  ercOutOfOrder       : TErc = 3109;
  ercExtraData        : TErc = 3110;
  ercMissingData      : TErc = 3111;
  ercTrIDNotFound     : TErc = 3201;
  ercNotComplete      : TErc = 3202;
  ercNotConnected     : TErc = 3203;
  ercWrongMode        : TErc = 3204;
  ercWrongVersion     : TErc = 3205;
  ercDvctableDne      : TErc = 3301;
  ercDvctableCorrupt  : TErc = 3302;
  ercDvcDne           : TErc = 3303;
  ercDpcutilInitFail  : TErc = 3304;
  ercUnknownErr       : TErc = 3305;
  ercDvcTableOpen     : TErc = 3306;
  ercRegError         : TErc = 3307;
  ercNotifyRegFull    : TErc = 3308;
  ercNotifyNotFound   : TErc = 3309;
  ercOldDriverNewFw   : TErc = 3310;
  ercInvHandle        : TErc = 3311;


  // Transaction status codes
  stsNew              : TSts = 1;
  stsComplete         : TSts = 2;


Const
 DPCModule = 'dpcutil.dll';


Var
 gDPCLoaded  : Boolean;
 gDPCHandle  : THandle;                             // Global Variable
 gDPCDevName : Array[0..cchDevNameMax-1] of Char;   // Global Variable
 gDPCDrvVer  : Array[0..cchDevNameMax-1] of Char;   // Global Variable


 // Function Description for Dynamic Loading
 DpcInit          : Function (Var Erc : TErc) : Boolean; cdecl;
 DpcTerm          : Procedure ; cdecl;


 DpcGetDpcVersion : Function (szVersion : PChar; Var Erc : TErc) : Boolean; cdecl;
 DpcStartNotify   : Function (hwndTemp : THandle; idNotifyTemp : Word; Var Erc : TErc) : Boolean; cdecl;
 DpcEndNotify     : Function (hwndTemp : THandle; Var Erc : TErc) : Boolean; cdecl;


 DpcGetVersion    : Function (hif : THandle; rgbVersion : PByte; cbVersion : Integer;
                              Var Erc : TErc; Var TrID : TTrID) : Boolean; cdecl;


 DpcWaitForTransaction     : Function (hif : THandle; TrID_  : TTrID; Var Erc : TErc) : Boolean; cdecl;
 DpcPendingTransactions    : Function (hif : THandle; pctran : PInteger; Var Erc : TErc) : Boolean; cdecl;
 DpcQueryConfigStatus      : Function (hif : THandle; TrID_  : TTrID; Var Trs : TTrs ;  Var Erc : TErc) : Boolean; cdecl;
 DpcAbortConfigTransaction : Function (hif : THandle; TrID_  : TTrID; Var Erc : TErc) : Boolean; cdecl;
 DpcClearConfigStatus      : Function (hif : THandle; TrID_  : TTrID; Var Erc : TErc) : Boolean; cdecl;


 DpcGetFirstError          : Function (hif : THandle) : TErc; cdecl;


 DpcOpenJtag               : Function(Var phif: THandle; szdvc : PChar; Var Erc : TErc; Var TrID : TTrID)  : Boolean; cdecl;
 DpcCloseJtag              : Function(hif : THandle; Var Erc : TErc )  : Boolean; cdecl;
 DpcEnableJtag             : Function(hif : THandle; Var Erc : TErc; Var TrID : TTrID) : Boolean; cdecl;
 DpcDisableJtag            : Function(hif : THandle; Var Erc : TErc; Var TrID : TTrID) : Boolean; cdecl;


 DpcSetTmsTdiTck  : Function (hif : THANDLE; fTms,fTDi,fTck : Boolean; Var Erc: TErc; Var TrID : TTrID) : Boolean; cdecl;
 DpcPutTdiBits    : Function (hif : THANDLE; cbit : Integer; rgbSnd : PChar; bitTms : Boolean;
                              fReturnTdo : Boolean; rgbRcv : PChar; Var Erc : TErc; Var TrID : TTrID) : Boolean; cdecl;


 DpcPutTmsTdiBits : Function (hif : THandle; cbit : Integer; rgbSnd : PChar;
                              fReturnTdo : Boolean; rgbRcv : PChar; Var Erc : TErc; Var TrID : TTrID) : Boolean; cdecl;


 DpcGetTdoBits    : Function (hif : THandle; cbits : Integer; bitTdi : Boolean; bitTms : Boolean;
                              rgbRcv : PChar; Var Erc : TErc; Var TrID : TTrID) : Boolean; cdecl;
 DpcOpenData      : Function (Var phif : THandle; szdvc : PChar; Var Erc : TErc; pTrID_ : pTrID) : Boolean; cdecl;
 DpcCloseData     : Function (hif : THandle; Var Erc : TErc) : Boolean; cdecl;
 DpcPutReg        : Function (hif : THandle; bAddr : Byte;     Data : Byte; Var Erc : TErc; pTrID_ : pTrID) : Boolean; cdecl;
 DpcGetReg        : Function (hif : THandle; bAddr : Byte; Var Data : Byte; Var Erc : TErc; pTrID_ : PTrID) : Boolean; cdecl;
 DpcPutRegSet     : Function (hif : THandle; rgbAddr : PByte;  rgbData : PByte; cbData : Integer; Var Erc : TErc; Var TrID : TTrID) : Boolean; cdecl;
 DpcGetRegSet     : Function (hif : THandle; rgbAddr : PByte;  rgbData : PByte; cbData : Integer; Var Erc : TErc; Var TrID : TTrID) : Boolean; cdecl;
 DpcPutRegRepeat  : Function (hif : THandle; bAddr : Byte; rgbData : PByte; cbData : Integer; Var Erc : TErc; pTrID_ : pTrID) : Boolean; cdecl;
 DpcGetRegRepeat  : Function (hif : THandle; bAddr : Byte; rgbData : PByte; cbData : Integer; Var Erc : TErc; pTrID_ : pTrID) : Boolean; cdecl;
 DpcStreamWrite   : Function (hif : THandle; rgbData: PByte; cbData : Integer; Var Erc : TErc; Var TrID : TTrID): Boolean; cdecl;
 DpcStreamRead    : Function (hif : THandle; rgbData: PByte; cbData : Integer; Var Erc : TErc; Var TrID : TTrID): Boolean; cdecl;


 // Device Manager Functions.
 // The device manager is used to maintain the table of Digilent
 // interface modules installed in the system.


 DvmgStartConfigureDevices : Procedure (hWnd : THandle; Var Erc: TErc); cdecl;


 DvmgGetDevCount  : Function (Var Erc : TErc) : Integer; cdecl;
 DvmgGetDevName   : Function (idvc : Integer; szdvcTemp : PChar; Var Erc : TErc) : Boolean; cdecl;
 DvmgGetDevType   : Function (idvc : Integer; dvtp : PInteger; perc_ : TErc) : Boolean; cdecl;
 DvmgGetDefaultDev: Function (Var Erc : TErc) : Integer; cdecl;


 //
 Function DpcEx_Msg (DpcMsgType : TDpcMsg; MsgID : Integer ) : String;


implementation


//------------------------------------------------------------------------------
//
// For Convenience
// DpcEx
//
//------------------------------------------------------------------------------


// Result Code to Msg Translation Function
Function DpcEx_Msg( DpcMsgType : TDpcMsg; MsgID : Integer ) : String;
 begin
  Case DpcMsgType of
   dmTrc : // Transaction Type   Message
           Case MsgID of
            $01 : Result := 'OpenJtag';
            $02 : Result := 'CloseJtag';
            $03 : Result := 'SetTmsTdiTck';
            $04 : Result := 'PutTdiBits';
            $05 : Result := 'PutTmsTdiBits';
            $06 : Result := 'GetTdoBits';
            $07 : Result := 'SetJtsel';
            $21 : Result := 'OpenSpi';
            $22 : Result := 'CloseSpi';
            $23 : Result := 'EnableSpi';
            $24 : Result := 'DisableSpi';
            $25 : Result := 'SetSpiSelect';
            $26 : Result := 'SetSpiMode';
            $27 : Result := 'PutSpiByte';
            $28 : Result := 'PutSpi';
            $29 : Result := 'GetSpi';
            $81 : Result := 'OpenData';
            $82 : Result := 'CloseData';
            $83 : Result := 'SetDataPins';
            $84 : Result := 'GetDataPins';
            $85 : Result := 'SendDataByte';
            $86 : Result := 'GetDataByte';
            $87 : Result := 'SendDataBytes';
            $88 : Result := 'GetDataBytes';
            $89 : Result := 'SendDataStream';
            $8a : Result := 'GetDataStream';
            $8b : Result := 'SendGetDataBytes';
            $8c : Result := 'GetVersion';
            $8d : Result := 'StreamWrite';
            $8e : Result := 'StreamRead';
            else  Result := 'Unknown';
           end;
   dmDvct : // Device Type        Message
           Case MsgID of
            $00 : Result := 'Ethernet';
            $01 : Result := 'USB';
            $02 : Result := 'Serial';
            $03 : Result := 'Parallel';
            else  Result := 'Unknown';
           End;
   dmErc  : // Error Code         Message
           Case MsgID of
            0000 : Result := 'NoError';
            3001 : Result := 'ConnReject';
            3002 : Result := 'ConnType';
            3003 : Result := 'ConnNoMode';
            3004 : Result := 'InvParam';
            3005 : Result := 'InvCmd';
            3006 : Result := 'Unknown';
            3007 : Result := 'JtagConflict';
            3008 : Result := 'NotImp';
            3009 : Result := 'NoMem';
            3010 : Result := 'Timeout';
            3011 : Result := 'Conflict';
            3012 : Result := 'BadPacket';
            3013 : Result := 'InvOption';
            3014 : Result := 'AlreadyCon';
            3101 : Result := 'Connected';
            3102 : Result := 'NotInit';
            3103 : Result := 'CantConnect';
            3104 : Result := 'AlreadyConnect';
            3105 : Result := 'SendError';
            3106 : Result := 'RcvError';
            3107 : Result := 'Abort';
            3108 : Result := 'TimeOutEx';
            3109 : Result := 'OutOfOrder';
            3110 : Result := 'ExtraData';
            3111 : Result := 'MissingData';
            3201 : Result := 'TrIDNotFound';
            3202 : Result := 'NotComplete';
            3203 : Result := 'NotConnected';
            3204 : Result := 'WrongMode';
            3205 : Result := 'WrongVersion';
            3301 : Result := 'DvctableDne';
            3302 : Result := 'DvctableCorrupt';
            3303 : Result := 'DvcDne';
            3304 : Result := 'DpcutilInitFail';
            3305 : Result := 'UnknownErr';
            3306 : Result := 'DvcTableOpen';
            3307 : Result := 'RegError';
            3308 : Result := 'NotifyRegFull';
            3309 : Result := 'NotifyNotFound';
            3310 : Result := 'OldDriverNewFw';
            3311 : Result := 'InvHandle';
            else   Result := 'UnKnown';
           end;
   dmSts  : // Transaction Status Message
            Case MsgId of
               1 : Result := 'New';
               2 : Result := 'Complete';
            End;
  end;
 end;


//
Function DllInit : Boolean;
 Var
  ErcCode : TErc;
  DevID   : Integer;
 begin
  // Initialize
  If gDpcLoaded then
   begin
    Result := True;
    Exit;
   end;
  //
  gDPCHandle := LoadLibrary(DPCModule);
  Case (gDPCHandle <= 0) of
   True  : begin
            Result := False;
            Exit;
           end;
   False : begin
            Result := True;
            gDpcLoaded := True;
           end;
  End;
  //
  DpcInit                   := GetProcAddress(gDPCHandle,'DpcInit');
  DpcTerm                   := GetProcAddress(gDPCHandle,'DpcTerm');
  DpcGetDpcVersion          := GetProcAddress(gDPCHandle,'DpcGetDpcVersion');
  DpcStartNotify            := GetProcAddress(gDPCHandle,'DpcStartNotify');
  DpcEndNotify              := GetProcAddress(gDPCHandle,'DpcEndNotify');
  DpcGetVersion             := GetProcAddress(gDPCHandle,'DpcGetVersion');
  DpcWaitForTransaction     := GetProcAddress(gDPCHandle,'DpcWaitForTransaction');
  DpcPendingTransactions    := GetProcAddress(gDPCHandle,'DpcPendingTransactions');
  DpcQueryConfigStatus      := GetProcAddress(gDPCHandle,'DpcQueryConfigStatus');
  DpcAbortConfigTransaction := GetProcAddress(gDPCHandle,'DpcAbortConfigTransaction');
  DpcClearConfigStatus      := GetProcAddress(gDPCHandle,'DpcClearConfigStatus');
  DpcGetFirstError          := GetProcAddress(gDPCHandle,'DpcGetFirstError');
  DpcOpenJtag               := GetProcAddress(gDPCHandle,'DpcOpenJtag');
  DpcCloseJtag              := GetProcAddress(gDPCHandle,'DpcCloseJtag');
  DpcEnableJtag             := GetProcAddress(gDPCHandle,'DpcEnableJtag');
  DpcDisableJtag            := GetProcAddress(gDPCHandle,'DpcDisableJtag');
  DpcSetTmsTdiTck           := GetProcAddress(gDPCHandle,'DpcSetTmsTdiTck');
  DpcPutTdiBits             := GetProcAddress(gDPCHandle,'DpcPutTdiBits');
  DpcPutTmsTdiBits          := GetProcAddress(gDPCHandle,'DpcPutTmsTdiBits');
  DpcGetTdoBits             := GetProcAddress(gDPCHandle,'DpcGetTdoBits');
  DpcOpenData               := GetProcAddress(gDPCHandle,'DpcOpenData');
  DpcCloseData              := GetProcAddress(gDPCHandle,'DpcCloseData');
  DpcPutReg                 := GetProcAddress(gDPCHandle,'DpcPutReg');
  DpcGetReg                 := GetProcAddress(gDPCHandle,'DpcGetReg');
  DpcPutRegSet              := GetProcAddress(gDPCHandle,'DpcPutRegSet');
  DpcGetRegSet              := GetProcAddress(gDPCHandle,'DpcGetRegSet');
  DpcPutRegRepeat           := GetProcAddress(gDPCHandle,'DpcPutRegRepeat');
  DpcGetRegRepeat           := GetProcAddress(gDPCHandle,'DpcGetRegRepeat');
  DpcStreamWrite            := GetProcAddress(gDPCHandle,'DpcStreamWrite');
  DpcStreamRead             := GetProcAddress(gDPCHandle,'DpcStreamRead');
  DvmgStartConfigureDevices := GetProcAddress(gDPCHandle,'DvmgStartConfigureDevices');
  DvmgGetDevCount           := GetProcAddress(gDPCHandle,'DvmgGetDevCount');
  DvmgGetDevName            := GetProcAddress(gDPCHandle,'DvmgGetDevName');
  DvmgGetDevType            := GetProcAddress(gDPCHandle,'DvmgGetDevType');
  DvmgGetDefaultDev         := GetProcAddress(gDPCHandle,'DvmgGetDefaultDev');
  //
 end;


//
Initialization
 gDPCLoaded := False; // Driver Not Loaded
 gDPCHandle := 0;     // No Handle
 FillChar(gDPCDevName,SizeOf(gDPCDevName),#0);
 DllInit;


Finalization
 // Clean Up
 If (gDPCLoaded)and(gDPCHandle <> 0) then
  FreeLibrary(gDpcHandle);
end. 


 


 


dpcutilex.pas







//
//  Encapsulate DpcUtil
//
//
//  Ref. PhoenixOnBoardMemCtrl.vhd
//
//     -- EPP Register Interface
//     --  Register Function
//     --  -------- --------
//     --     0     Memory control register (read/write)
//     --     1     Memory address bits 0-7 (read/write)
//     --     2     Memory address bits 8-15 (read/write)
//     --     3     Memory address bits 16-18 (read/write)
//     --     4     Memory data write holding register (read/write) -see Note 1
//     --     5     Memory data read register (read) - see Note 2
//     -- Registers 6 and 7 are used for block transfers
//     --     6     RAM auto read/write register (read/write) - see Note 3
//     --     7     Flash auto read/write register (read/write) - see Note 4
//
//
unit DpcUtilex;


Interface


Uses
 Types,Windows,SysUtils,StdCtrls,Forms;


Const
 cMaxBuf          = 1024*1024*16; // 16MB
 cXferBlockMemory = 1024*8; // Default  1000;
 cXferBlockFlash  = 1024*8; // Default  1000;


Type
 TDpcXferType = (xtMemory,xtFlash);
 TDpcXferDir  = (xdPut,xdGet);
 TDpcBuf      = Array[0..cMaxBuf-1] of Byte;


Var
 gDevName  : String;
 gDrvVer   : String;
 gDpcBuf   : TDpcBuf;
 gRptTotal : Single; // mSec
 gRptSpeed : Single; // MBytes/Sec


Function  DpcUtil_Init : Boolean;
Procedure DpcUtil_ShowSetupDlg;
Function  DpcUtil_GetReg  (grAddress : Byte;  Var grData : Byte   ) : Boolean;
Function  DpcUtil_PutReg  (grAddress : Byte;      grData : Byte   ) : Boolean;
Function  DpcUtil_Xfer    (XferType  : TDpcXferType;
                           XferDir   : TDpcXferDir;
                           dpAddress : DWord;
                           Size      : DWord;
                           Var dpBuf : TDpcBuf;
                           InfoLabel : TLabel) : Boolean;
Function  DpcUtil_File2Buf(gfFileName : String; Var gfBuf : TDpcBuf; Var Size : DWord) : Boolean;
Function  DpcUtil_Buf2File(Var gfBuf : TDpcBuf;gfFileName : String; Var Size : DWord) : Boolean;



Implementation


Uses
 DpcUtil;


Type
 TStopWatchMode = (swStart,swStop);


Var
 FStopWatch : TDateTime;


// 0.1 Sec
Function Time_StopWatch(sw_mode : TStopWatchMode) : Integer;
 Var
  SWTime            : TDateTime;
  Hour,Min,Sec,MSec :Word;
  Total             : Integer;
 begin
  Case sw_mode of
   swStart : begin
              FStopWatch := Now;
              Time_StopWatch  := 0;
             end;
   swStop  : begin
              SWTime := FStopWatch-Now;
              DecodeTime(SWTime,Hour,Min,Sec,MSec);
              Total := Hour*1000*60*60+
                       Min *1000*60+
                       Sec *1000+
                       MSec;
              Time_StopWatch := Total;
             end;
  end;
 end;


Function DpcUtil_Init : Boolean;
 Var
  ErcCode : TErc;
  DevID   : Integer;
 begin
  Case DpcInit(ErcCode) of
   False : Begin
            Result := False;
            Exit;
           End;
   True  : Begin
            DevID := DvmgGetDefaultDev(ErcCode); // Get Default Device ID
            Case DvmgGetDevName(DevID,gDpcDevName,ErcCode) of
             True  : begin
                      gDevName := String(gDpcDevName);
                      DpcGetDpcVersion(gDpcDrvVer,ErcCode);
                      gDrvVer  := String(gDpcDrvVer );
                      Result := True;
                     end;
             False : Result := False;
            End;
           End;
  End;
 end;


//
Procedure DpcUtil_ShowSetupDlg;
 Var
  Erc : TErc;
 begin
  DvmgStartConfigureDevices(0,Erc);
 end;


//
Function  DpcUtil_GetReg(grAddress : Byte; Var grData : Byte ) : Boolean;
 Var
  Erc    : TErc;
  TrID   : TTrid;
  hif    : THandle;
 begin
  //
  If Not(DpcOpenData(hif,@gDpcDevName,Erc,nil)) then
   begin
    Result := False;
    Exit;
   end;
  //
  If Not(DpcGetReg(hif,grAddress,grData,Erc,nil)) then
   begin
    Result := False;
    Exit;
   end;
  //
  Erc := DpcGetFirstError(hif);
  Result := (erc = ercNoError);
  //
  DpcCloseData(hif,Erc);
 end;


//
Function  DpcUtil_PutReg(grAddress : Byte;     grData : Byte ) : Boolean;
 Var
  Erc    : TErc;
  TrID   : TTrid;
  hif    : THandle;
 begin
  //
  If Not(DpcOpenData(hif,@gDpcDevName,Erc,nil)) then
   begin
    Result := False;
    Exit;
   end;
  //
  If Not(DpcPutReg(hif,grAddress,grData,Erc,nil)) then
   begin
    Result := False;
    Exit;
   end;
  //
  Erc := DpcGetFirstError(hif);
  Result := (erc = ercNoError);
  //
  DpcCloseData(hif,Erc);
 end;


//
Function  DpcUtil_Xfer    (XferType  : TDpcXferType;
                           XferDir   : TDpcXferDir;
                           dpAddress : DWord;
                           Size      : DWord;
                           Var dpBuf : TDpcBuf;
                           InfoLabel : TLabel) : Boolean;
 Var
  Erc              : TErc;
  TrID             : TTrid;
  idReg            : Byte;
  cbGet,cbGetTotal : Integer;
  cb               : DWord;
  hif              : THandle;
  Lp               : Integer;
  RstStr           : String;
  MemPtr           : DWord;
  XferBlockSize    : DWord;
  AddrBuf          : Array[0..3] of Byte;
 begin
  //
  hif    := 0;
  Case XferType of
   xtMemory : begin
               idReg         := 6; // to Memory
               XferBlockSize := cXferBlockMemory;
              end;
   xtFlash  : begin
               idReg         := 7; // to Flash
               XferBlockSize := cXferBlockFlash;
              end;
  End;
  cb     := Size;        // Data Size
  MemPtr := 0;
  Move(dpAddress,AddrBuf,SizeOf(dpAddress));
  //
  Time_StopWatch(swStart);
  //
  If Not(DpcOpenData(hif,@gDpcDevName,Erc,nil)) then
   begin
    Result := False;
    Exit;
   end;
  // -------------------------------------------------------------------------
  DpcPutReg(hif,0,$FF,Erc,nil); // Init


  DpcPutReg(hif,1,AddrBuf[0],Erc,nil); // Address
  DpcPutReg(hif,2,AddrBuf[1],Erc,nil);
  DpcPutReg(hif,3,AddrBuf[2],Erc,nil);


  // -------------------------------------------------------------------------
  cbGet := 0;
  cbGetTotal := cb;
  While (cbGetTotal > 0) do
   begin
    Case ((cbGetTotal - XferBlockSize) <= 0) of
     True  : begin
              cbGet      := cbGetTotal;
              cbGetTotal := 0;
             end;
     False : begin
              cbGet      := XferBlockSize;
              Dec(cbGetTotal,XferBlockSize);
             end;
    end;
    //
    Case XferDir of
     xdGet : If Not(DpcGetRegRepeat(hif,idReg,@dpBuf[MemPtr],cbGet,Erc,nil)) then
                begin
                 DpcCloseData(hif,Erc);
                 Result := False;
                 Exit;
                end;
     xdPut : If Not(DpcPutRegRepeat(hif,idReg,@dpBuf[MemPtr],cbGet,Erc,nil)) then
                begin
                 DpcCloseData(hif,Erc);
                 Result := False;
                 Exit;
                end;
    End;
    //
    Inc(MemPtr,cbGet);
    //
    InfoLabel.Caption := IntToStr(MemPtr);
    Application.ProcessMessages;
   end;
  //
  DpcCloseData(hif,Erc);
  //
  gRptTotal := Time_StopWatch (swStop); // mSec
  If gRptTotal = 0 then gRptTotal := 1;
  gRptSpeed := Size / (gRptTotal/1000); // Byte/Sec
  //
  Result := True;
 end;


//
Function  DpcUtil_File2Buf(gfFileName : String; Var gfBuf : TDpcBuf; Var Size : DWord) : Boolean;
 Var
  Fp : File;
 begin
  //
  If Not(FileExists(gfFileName)) then
   begin
    Result := False;
    Exit;
   end;
  //
  AssignFile(Fp,gfFileName);
  Reset(Fp,1);
  Size := FileSize(Fp);
  If Size > cMaxBuf then Size := cMaxBuf;
  BlockRead(Fp,gfBuf,Size);
  CloseFile(Fp);
  //
 end;


//
Function  DpcUtil_Buf2File(Var gfBuf : TDpcBuf;gfFileName : String; Var Size : DWord) : Boolean;
 Var
  Fp : File;
 begin
  //
  AssignFile(Fp,gfFileName);
  Rewrite(Fp,1);
  If Size > cMaxBuf then Size := cMaxBuf;
  BlockWrite(Fp,gfBuf,Size);
  CloseFile(Fp);
  //
 end;


initialization


finalization


end. 


 


 

2008년 1월 17일 목요일

Delphi Interface for Cypress FX2 CY7C68013

//
// Delphi Interface for Cypress FX2 CY7C68013
//
//
// 1. Why ?
// CyAPI.lib [Cypress USB DevStudio] for BC6,VC6_7
// No Dll. Directory Control needed for Delphi
//
//
// 2. ID VID : 0x0547
// PID : 0x1002
// Product : EZ-USB FX2 GPIF to Ext FIFO Example using FIFO Transactions
// TGUID '{AE18AA60-7F6A-11d4-97DD-00010229B959}'
//
// 3. EndPoint
// PIPE00 : Control End Point [Max Pkt Size 64]
// PIPE02 : Bulk Out [Max Pkt Size 512]
// PIPE86 : Bulk In [Max Pkt Size 512]
//
// 4. History
// First Date : 2007.10.26
// Last Modified : 2008.01.17
//
// 5. Version
// 0.1 : 2008.01.17
//
//
// 6. Bugs
//
//
// 7. Writer Simon,choi (simon@kredix.com)
// e-mail : simon@kredix.com
// simon@maxpaper.com
// simonsayz@naver.com
// blog : http://blog.naver.com/simonsayz
// http://s193382.blogspot.com/
//
//
unit UsbLibrary;

interface

Uses
Windows,Types,Classes,SysUtils,StdCtrls;

Const
cSetupAPI_dll = 'setupapi.dll';
cGUID_CLASS_CYUSBDRV : TGUID = '{AE18AA60-7F6A-11d4-97DD-00010229B959}';
//
Cmd_Usb_Reset = $B2;
Cmd_Usb_Ready = $B5;
//

Type
HDevInfo = Pointer;
ULONG_PTR = DWORD;
//
PSPDeviceInterfaceData = ^SP_DEVICE_INTERFACE_DATA;
SP_DEVICE_INTERFACE_DATA = packed record
cbSize : DWORD;
InterfaceClassGuid : TGUID;
Flags : DWORD;
Reserved : ULONG_PTR;
end;
PSPDeviceInterfaceDetailDataA = ^SP_DEVICE_INTERFACE_DETAIL_DATA_A;
SP_DEVICE_INTERFACE_DETAIL_DATA_A = packed record
cbSize: DWORD;
DevicePath: array [0..0] of AnsiChar;
end;
PSPDevInfoData = ^SP_DEVINFO_DATA;
SP_DEVINFO_DATA = packed record
cbSize: DWORD;
ClassGuid: TGUID;
DevInst: DWORD; // DEVINST handle
Reserved: ULONG_PTR;
end;
Var
memo_Rcv : TMemo; //

//
Function _USB_Init : Boolean;
Function _USB_Device (DeviceList : TStrings) : Integer;
Function _USB_Open (sDeviceName : String ) : Boolean;
Function _USB_Close : Boolean;
//
Function _USB_Cmd (USBCmd : Byte;
Var USBRcv : Word) : Boolean;
Function _USB_Write (pBuffer : Pointer;
ulBufferSize : DWord;
Var pByteWritten : DWord) : Boolean;
Function _USB_Read (pBuffer : Pointer;
ulBufferSize : DWord;
Var ulByteRead : DWord) : Boolean;

Implementation

Const
DIGCF_PRESENT = $00000002;
DIGCF_DEVICEINTERFACE = $00000010;

FILE_SHARE_READ = $1;
FILE_SHARE_WRITE = $2;
OPEN_EXISTING = 3;

FILE_DEVICE_UNKNOWN = $22;

METHOD_BUFFERED = 0;
METHOD_IN_DIRECT = 1;
METHOD_OUT_DIRECT = 2;
METHOD_NEITHER = 3;

FILE_ANY_ACCESS = 0;
FILE_READ_ACCESS = 1;
FILE_WRITE_ACCESS = 2;

Func_Vendor_Request = 8; // EZ FX2
Cmd_Buf_Max = 40;

Var
// Handle
cSetupAPI_Handle : THandle;
m_hPipeCtrl : THandle; // PIPE00
m_hPipeBulkIn : THandle; // PIPE02
m_hPipeBulkOut : THandle; // PIPE86
//
IOCTL_Vendor_Request : DWord;
Cmd_Buf : Packed Array[0..Cmd_Buf_Max-1] of Byte;

//------------------------------------------------------------------------------
//
// USB Device Enumernation & Find
//
// 1. Function _USB_Init : Boolean;
// 2. GetDeviceName
// 3. Function _USB_Device(DeviceList : TStrings) : Integer;
//
//------------------------------------------------------------------------------


Var
SetupDiGetDeviceInterfaceDetail : Function
(DeviceInfoSet : HDEVINFO;
DeviceInterfaceData : PSPDeviceInterfaceData;
DeviceInterfaceDetailData : PSPDeviceInterfaceDetailDataA;
DeviceInterfaceDetailDataSize: DWORD; RequiredSize: PDWORD;
Device : PSPDevInfoData): LongBool; stdcall;

SetupDiGetClassDevs : Function
(ClassGuid : PGUID; const Enumerator: PChar;
hwndParent: HWND; Flags: DWORD): HDEVINFO; stdcall;
SetupDiEnumDeviceInterfaces : Function
(DeviceInfoSet: HDEVINFO;
DeviceInfoData: PSPDevInfoData; var InterfaceClassGuid: TGUID;
MemberIndex: DWORD;
var DeviceInterfaceData: SP_DEVICE_INTERFACE_DATA): LongBool; stdcall;
SetupDiDestroyDeviceInfoList : Function
(DeviceInfoSet: HDEVINFO): LongBool; stdcall;

//
Function _USB_Init : Boolean;
begin
cSetupAPI_Handle := LoadLibrary(cSetupAPI_dll);
If cSetupAPI_Handle <> 0 then
begin
@SetupDiGetDeviceInterfaceDetail := GetProcAddress(cSetupAPI_Handle,
'SetupDiGetDeviceInterfaceDetailA');
@SetupDiGetClassDevs := GetProcAddress(cSetupAPI_Handle,
'SetupDiGetClassDevsA');
@SetupDiEnumDeviceInterfaces := GetProcAddress(cSetupAPI_Handle,
'SetupDiEnumDeviceInterfaces');
@SetupDiDestroyDeviceInfoList := GetProcAddress(cSetupAPI_Handle,
'SetupDiDestroyDeviceInfoList');
end;
//
m_hPipeCtrl := Invalid_Handle_Value;
m_hPipeBulkIn := Invalid_Handle_Value;
m_hPipeBulkOut := Invalid_Handle_Value;
//
_USB_Init := (cSetupAPI_Handle <> 0);
end;

Function GetDeviceName( HardwareDeviceInfo : HDevInfo;
DeviceInfoData : PSPDeviceInterfaceData;
DevName : TStrings) : Boolean;
Var
FunctionClassDeviceData : PSPDeviceInterfaceDetailDataA;
predictedLength : DWord;
requiredLength : DWord;
hOut : THandle;
begin
//
functionClassDeviceData := nil;
predictedLength := 0;
requiredLength := 0;
hOut := Invalid_Handle_Value;
//
SetupDiGetDeviceInterfaceDetail(HardwareDeviceInfo,
DeviceInfoData,
nil, // probing so no output buffer yet
0, // probing so output buffer length of zero
@requiredLength,
nil); // not interested in the specific dev-node

predictedLength := requiredLength;

GetMem(functionClassDeviceData,predictedLength);
functionClassDeviceData.cbSize := Sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A);

// Retrieve the information from Plug and Play.
if (Not SetupDiGetDeviceInterfaceDetail(HardwareDeviceInfo,
DeviceInfoData,
functionClassDeviceData,
predictedLength,
@requiredLength,
nil)) then
begin
FreeMem(functionClassDeviceData);
GetDeviceName := False;
Exit;
end;

//
DevName.Add( StrPas (functionClassDeviceData.DevicePath) );

FreeMem(functionClassDeviceData);
GetDeviceName := True;
end;

Function _USB_Device(DeviceList : TStrings) : Integer;
Var
NumberDevices : DWord;
HardwareDeviceInfo : HDevInfo;
DeviceInfoData : SP_Device_Interface_Data;
GUID_Var : TGUID;
DeviceEnd : Boolean;
DeviceCnt : Integer;
begin
//
hardwareDeviceInfo := SetupDiGetClassDevs(@cGUID_CLASS_CYUSBDRV,
nil,
0,
DIGCF_DEVICEINTERFACE or DIGCF_PRESENT);
NumberDevices := 0;
DeviceInfoData.cbSize := SizeOf(SP_DEVICE_INTERFACE_DATA);
GUID_Var := cGUID_CLASS_CYUSBDRV;

DeviceEnd := False;
DeviceCnt := 0;
Repeat
Inc(DeviceCnt);
If (SetupDiEnumDeviceInterfaces(HardwareDeviceInfo,
nil,
GUID_Var,
NumberDevices,
DeviceInfoData)) then
GetDeviceName(hardwareDeviceInfo,
@deviceInfoData,
DeviceList)
else
DeviceEnd := True;
Until (ERROR_NO_MORE_ITEMS <> GetLastError ) or ( DeviceCnt < m_hpipectrl =" Invalid_Handle_Value)" m_hpipebulkout =" Invalid_Handle_Value)" m_hpipebulkin =" Invalid_Handle_Value)"> Invalid_Handle_Value then CloseHandle(m_hPipeCtrl );
If m_hPipeBulkOut <> Invalid_Handle_Value then CloseHandle(m_hPipeBulkOut);
If m_hPipeBulkIn <> Invalid_Handle_Value then CloseHandle(m_hPipeBulkIn );
//
Exit;
end;
//
_USB_Open := True;
end;

//
Function _USB_Close : Boolean;
begin
If m_hPipeCtrl <> Invalid_Handle_Value then CloseHandle(m_hPipeCtrl );
If m_hPipeBulkIn <> Invalid_Handle_Value then CloseHandle(m_hPipeBulkIn );
If m_hPipeBulkOut <> Invalid_Handle_Value then CloseHandle(m_hPipeBulkOut );
//
m_hPipeCtrl := Invalid_Handle_Value;
m_hPipeBulkIn := Invalid_Handle_Value;
m_hPipeBulkOut := Invalid_Handle_Value;
//
_USB_Close := True;
end;


//------------------------------------------------------------------------------
//
// USB Device Function
//
// 1. Function _USB_Cmd (USBCmd : Byte; Var USBRcv : Word) : Boolean;
// 2. Function _USB_Write (pBuffer : Pointer;
// ulBufferSize : DWord;
// Var pByteWritten : DWord) : Boolean;
// 3. Function _USB_Write (pBuffer : Pointer;
// ulBufferSize : DWord;
// Var pByteWritten : DWord) : Boolean;
//
//------------------------------------------------------------------------------

Type
// C0 B2 03 0D 00 00 02 00
// ^ Request Type 1100:000
// ^ Direction : Device To Host
// ^ Type : Vendor
// ^ Recipient : Device
// ^ Request B2 [Value]
// ^ Value 030D
// ^ Index 0000
// ^ Length 0200
TCtl_Request = Record
Target : Byte; // 0x00 TGT_Device
ReqType : Byte; // 0x02 Req_Vendor
Direction : Byte; // 0x01 DIR_From_Device
ReqCode : Byte; // 0xB2 [Value]
Value : Word; // 0x0D03
Index : Word; // 0
End;

//
Function _USB_Cmd (USBCmd : Byte; Var USBRcv : Word) : Boolean;
Var
Inx : Integer;
Rst : Boolean;
nByte : DWord;
begin
FillChar(Cmd_Buf,SizeOf(Cmd_Buf),#0);
Inx := 0;
Cmd_Buf[Inx] := $C0; Inc(Inx);
Cmd_Buf[Inx] := USBCmd; Inc(Inx);
Cmd_Buf[Inx] := $00; Inc(Inx);
Cmd_Buf[Inx] := $0D; Inc(Inx);
Cmd_Buf[Inx] := $00; Inc(Inx);
Cmd_Buf[Inx] := $00; Inc(Inx);
Cmd_Buf[Inx] := $02; Inc(Inx);
Cmd_Buf[Inx] := $00; Inc(Inx);
//
rst := DeviceIOControl(m_hPipeCtrl,
IOCTL_Vendor_Request,
@Cmd_Buf, // Send Buf
Cmd_Buf_Max, // Send Buf Size
@Cmd_Buf, // Recv Buf
Cmd_Buf_Max, // Recv Buf Size
nByte, // Recv Bytes
nil);
Move(Cmd_Buf,USBRcv,2);
Result := Rst;
end;

//
Function _USB_Write(pBuffer : Pointer;
ulBufferSize : DWord;
Var pByteWritten : DWord) : Boolean;
begin
If m_hPipeBulkOut = Invalid_Handle_Value then
begin
_USB_Write := False;
Exit;
end;
//
If Not(Windows.WriteFile(m_hPipeBulkOut,pBuffer^,ulBufferSize,pByteWritten,nil)) then
begin
_USB_Write := False;
Exit;
end;
//
_USB_Write := True;
end;

//
Function _USB_Read (pBuffer : Pointer;
ulBufferSize : DWord;
Var ulByteRead : DWord) : Boolean;
Var
Tmp : Array[0..1024] of Byte;
TmpStr : String;
TmpLp : Integer;
begin
If m_hPipeBulkIn = Invalid_Handle_Value then
begin
_USB_Read := False;
Exit;
end;
//
If Not(Windows.ReadFile(m_hPipeBulkIn,pBuffer^,ulBufferSize,ulByteRead,nil)) then
begin
_USB_Read := False;
Exit;
end;
//
_USB_Read := (ulByteRead <> 0);
end;

Initialization
IOCTL_Vendor_Request := CTL_Code(FILE_DEVICE_UNKNOWN,
Func_Vendor_Request,
Method_Buffered,
File_Any_Access);
end.

2008년 1월 7일 월요일

Photo Finishing Software

Hi !

I am simon,choi

It's first day on blogger.com


Software Programmer in seoul, south korea.

Programming related photo is my specialty.

simonsayz@naver.com