unit main; interface uses System.Classes, mr.trinity.types; type TcmdMain = class private procedure doCmdList( Functions: TCapabilities = []); procedure doCmdListFX2 ( Functions: TCapabilities = []); procedure doCmdListJTAG; procedure DoCmdListJTAGDevices( id: string); procedure doCmdProgramFX2( const Location : string; const Filename : string; Permanent : boolean=false); procedure doCmdProgramJTAG( const ID : string; const FileName : string; const Verbose : string=''); public procedure Execute( Module: string; CommandLine: string); end; implementation uses System.SysUtils, System.StrUtils, System.RegularExpressions, prgLexer, prgParser, Vcl.Forms, mr.drv.usb.winusb, mr.trinity, mr.dev.manager, m.lcd.types, m.led.types, m.jtag.types; { TcmdMain } // ================================================================================================ // execute // ================================================================================================ procedure TcmdMain.Execute(Module: string; CommandLine: string); var lex : TprgLexer; par : TprgParser; stm : TMemoryStream; cmd : AnsiString; jtg : IJTAG; begin cmd := AnsiString(CommandLine); stm := TMemoryStream.Create; stm.Write( cmd[1], Length(cmd)); stm.Seek( 0, soFromBeginning); try lex := TprgLexer .Create( stm); par := TprgParser .Create( lex, 3); par.prg; case par.Command of cmdList : doCmdList; cmdListFX2s : doCmdListFX2; cmdListJTAGs : doCmdListJTAG; cmdListJTAG : DoCmdListJTAGDevices( par.DeviceID); cmdProgramFX2 : doCmdProgramFX2( par.DeviceID, par.Files[0], false); cmdProgramFX2Perm : doCmdProgramFX2( par.DeviceID, par.Files[0], true); cmdProgramJTAG : doCmdProgramJTAG( par.DeviceID, par.Files[0]); end; par.Free except writeln( Module +': Syntax error') end; stm.Free end; // ================================================================================================ // /list // ================================================================================================ procedure TcmdMain.doCmdList( Functions: TCapabilities = []); var c: TCapabilities; s: string; begin if Functions = [] then begin writeln; writeln('--------------------------------------------------------------------'); writeln(' VID PID Description Location '); writeln('--------------------------------------------------------------------'); end else begin writeln; writeln('--------------------------------------------------------------------'); writeln(' Device Functions Location '); writeln('--------------------------------------------------------------------'); end; GetDeviceList ( function( VID: word; PID: word; Desc: string; Loc: string; DevicePath: string): boolean begin var key := (VID shl 16) + PID; if key = $16D00712 then begin var dev := AllocateDevice( DevicePath); if dev is TTrinity then with TTrinity(dev) do begin Open; c := TTrinity(dev).Capabilities; if (Functions = []) or ( (c * Functions) = Functions) then s := Caps2String( c) else s := ''; if s <> '' then Desc := Desc +' ['+ s +']'; Close end; dev.Free; end; writeln( Format(' %4.4X %4.4X %-40.40s %s', [VID, PID, Desc, Loc])); exit( true) end ) end; // ================================================================================================ // fx2 /list // ================================================================================================ procedure TcmdMain.doCmdListFx2( Functions : TCapabilities); var c : TCapabilities; s : string; begin writeln; writeln('------------------------------------------------------------------------------'); writeln(' Device Functions Location Serial '); writeln('------------------------------------------------------------------------------'); GetDeviceList ( function( VID: word; PID: word; Desc: string; Loc: string; DevicePath: string): boolean begin var key := (vid shl 16) +pid; var dev := AllocateDevice( DevicePath); if dev is TTrinity then with TTrinity(dev) do begin Open; c := TTrinity(dev).Capabilities; if (Functions = []) or ( (c * Functions) = Functions) then s := Caps2String( c); Loc := Loc + ' '+ Format('%-8.8s',[TTrinity(dev).SerialNumber]); writeln( Format(' Trinity %-41.41s %s', [ s, Loc])); Close end; dev.Free; exit( true) end, $16D0, $0712 ) end; // ================================================================================================ // fx2 /loc:xxxx=file.hex [/perm] // ================================================================================================ procedure TcmdMain.doCmdProgramFX2( const Location: string; const Filename: string; Permanent: boolean); begin GetDeviceList ( function( VID: word; PID: word; Desc: string; Loc: string; DevicePath: string): boolean begin if Length( Location) <= Length( Loc) then begin var re := TRegEx.Create( Location+'$'); if re.IsMatch( Loc) then begin writeln(Format('Programming "%s" @ %s', [Desc, Loc])); var dev := AllocateDevice( DevicePath); if dev is TTrinity then with TTrinity(dev) do begin Open; if not Permanent then DownloadFirmware( FileName) else DownloadFirmwarePerm( FileName); Close end; dev.Free; exit(false) end; end; exit( true) end ) end; // @@@: JTAG ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // // JTAG // // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // ================================================================================================ // jtag /list // ================================================================================================ procedure TcmdMain.doCmdListJtag; begin doCmdListFx2( [capJTAG]); end; // ================================================================================================ // jtag /id:xxxx /list // ================================================================================================ procedure TcmdMain.DoCmdListJTAGDevices(ID: string); var tri: ITrinity; jtg: IJTAG; ids: array [0..9] of cardinal; s : string; begin writeln; writeln('------------------------------------------------------------------------------'); writeln(' Device JTAG chain Location Serial '); writeln('------------------------------------------------------------------------------'); GetDeviceList ( function( VID: word; PID: word; Desc: string; Loc: string; DevicePath: string): boolean begin var key := (vid shl 16) +pid; var dev := AllocateDevice( DevicePath); if Supports( dev, ITrinity, tri) then begin tri.Open; if tri.SerialNumber = ID then begin if Supports( dev, IJTAG, jtg) then begin jtg.scan( @ids[0], 10); s := ''; for var i := 0 to 9 do begin if ids[i] <> 0 then begin if s <> '' then s := s+ ', '; s := s + Format( '%8.8X', [ids[i]]); end else break end; end; Loc := Loc + ' '+ Format('%-8.8s',[tri.SerialNumber]); if capJTAG in tri.Capabilities then writeln( Format(' %-9.9s %-41.41s %s', [ Desc, s, Loc])); end; tri.Close end; exit( true) end, $16D0, $0712 ) end; // ================================================================================================ // jtag /id:xxx=file[svf,vme] // ================================================================================================ procedure TcmdMain.doCmdProgramJTAG(const ID, FileName, Verbose: string); var tri: ITrinity; jtg: IJTAG; led: ILED; lcd: ILCD; ids: array [0..9] of cardinal; s : string; begin GetDeviceList ( function( VID: word; PID: word; Desc: string; Loc: string; DevicePath: string): boolean begin result := true; var dev := AllocateDevice( DevicePath); if Supports( dev, ITrinity, tri) then begin tri.Open; if ID = tri.SerialNumber then begin Supports( tri, ILED, led); Supports( tri, ILCD, lcd); if Supports( tri, IJTAG, jtg) then begin if led <> nil then begin led.LedOn(0); led.LedOff(3) end; if lcd <> nil then begin lcd.Cls; lcd.GotoXY(0,0); lcd.putc('<'); end; jtg.scan( @ids[0], 10); writeln( Format('Programming %-8.8X', [ids[0]])); jtg.play( FileName); if lcd <> nil then lcd.putc('>'); if led <> nil then begin led.LedOff(0); led.LedOn(3) end; result := false end end; tri.Close end; end, $16D0, $0712 ) end; end.