Ignore:
Timestamp:
Nov 19, 2012, 2:38:16 PM (12 years ago)
Author:
chronos
Message:
  • Modified: Faster write in TPrestoProgrammer using delayed response check of sent commands.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ISPProgrammer/Dallas/UDallasProgrammer.pas

    r417 r438  
    99  UJobProgressView, SyncObjs, DateUtils, Dialogs, URegistry,
    1010  Forms, UISPProgrammer, Registry, UBinarySerializer, SpecializedList,
    11   UCommTelnet, UCommTCPClient, UCommTelnetComPortOption, UCommConnector;
     11  UCommTelnet, UCommTelnetComPortOption, UCommConnector;
    1212
    1313const
     
    3333    Mark: TListByte;
    3434    procedure ReceiveData(Sender: TCommPin; Stream: TListByte);
    35     function ReadResponse: string;
     35    function ReadResponse(Count: Integer = 0): string;
    3636    function ResponseCount: Integer;
    3737    procedure ResponseClear;
     
    6262resourcestring
    6363  STimeout = 'Timeout';
    64   SEmptyBuffer = 'Empty buffer';
     64  //SEmptyBuffer = 'Empty buffer';
    6565  SInvalidHexFormat = 'Invalid Intel Hex record format';
    6666  SFlashControllerError = 'Flash controller error';
     
    7979procedure TDallasProgrammer.ReceiveData(Sender: TCommPin; Stream: TListByte);
    8080var
    81   OldPosition: Integer;
    8281  NewList: TListByte;
    8382begin
     
    9291end;
    9392
    94 function TDallasProgrammer.ReadResponse: string;
     93function TDallasProgrammer.ReadResponse(Count: Integer = 0): string;
    9594var
    9695  Serializer: TBinarySerializer;
     
    10099  StartTime := Now;
    101100  repeat
    102     if ResponseCount > 0 then Break;
     101    if Count = 0 then begin
     102      if ResponseCount > 0 then Break;
     103    end else begin
     104      if ResponseCount >= Count then Break;
     105    end;
     106    Sleep(1);
    103107    ElapsedTime := Now - StartTime;
    104108  until (ElapsedTime > Timeout);
     
    109113    Serializer := TBinarySerializer.Create;
    110114    Serializer.List := TListByte(ResponseQueue.First);
    111     Result := Serializer.ReadString(Serializer.List.Count);
     115    if Count = 0 then
     116      Result := Serializer.ReadString(Serializer.List.Count)
     117      else Result := Serializer.ReadString(Count);
    112118    ResponseQueue.Delete(0);
    113119  finally
     
    140146var
    141147  SerialPort: TCommSerialPort;
    142   Telnet: TCommTelnet;
    143148  TelnetOption: TTelnetOptionComPort;
    144149begin
     
    217222      RootKey := Root;
    218223      OpenKey(Key + '\ISPProgrammer\Dallas', True);
    219       BaudRate := ReadIntegerWithDefault('FirmwareBaudRate', 57600);
     224      BaudRate := ReadIntegerWithDefault('FirmwareBaudRateNumeric', 57600);
    220225    finally
    221226      Free;
     
    229234      RootKey := Root;
    230235      OpenKey(Key + '\ISPProgrammer\Dallas', True);
    231       WriteInteger('FirmwareBaudRate', Integer(BaudRate));
     236      WriteInteger('FirmwareBaudRateNumeric', Integer(BaudRate));
    232237    finally
    233238      Free;
     
    321326    HexFile.SaveToStringList(HexData);
    322327    Job.Progress.Max := HexData.Count;
    323     for I := 0 to HexData.Count - 1 do begin
    324       Request.Clear;
    325       ResponseClear;
    326       Request.WriteString(HexData[I]);
    327       Request.WriteList(Mark, 0, Mark.Count);
    328       Pin.Send(Request.List);
    329       Value := ReadResponse;
    330       CheckWriteErrorCode(Value);
     328    // Delayed response check mechanism,
     329    // to avoid thread sleep(1) to context switch after 16 ms
     330    // During 16 ms delay: 57600 / 10 * 0.016 = 97 bytes can be transfered
     331    // One line of hex file is 74 bytes long
     332    // Then two during context switching next line should be written to output buffer
     333    // On I = 0 do not check response
     334    // On I = HexData.Count do not send data, only check response
     335    ResponseClear;
     336    for I := 0 to HexData.Count do begin
     337      if I < HexData.Count then begin
     338        Request.Clear;
     339        Request.WriteString(HexData[I]);
     340        Request.WriteList(Mark, 0, Mark.Count);
     341        Pin.Send(Request.List);
     342      end;
     343      if I > 0 then begin
     344        Value := ReadResponse;
     345        CheckWriteErrorCode(Value);
     346      end;
    331347      Job.Progress.Value := I;
    332348      if Job.Terminate then Break;
     
    353369function TDallasProgrammer.ReadIdentification: string;
    354370var
    355   InitTimeout: TDateTime;
    356371  Value: string;
    357372begin
    358373  Result := '';
    359   InitTimeout := 6000 * OneMillisecond;
    360374  Active := True;
    361375
     
    365379  Value := ReadResponse; // Empty line
    366380  Identification := ReadResponse;
     381
     382  // Make one empty command to clear possible previous data
     383  ResponseClear;
     384  Request.Clear;
     385  Pin.Send(Request.List);
     386  Value := ReadResponse; // Empty line
    367387
    368388  Log(SIdentification + ': ' + Identification);
Note: See TracChangeset for help on using the changeset viewer.