|
|
|
|
@@ -380,7 +380,7 @@ public class JtagStatusReg
|
|
|
|
|
public class Jtag
|
|
|
|
|
{
|
|
|
|
|
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
|
|
|
|
private readonly ProgressTracker? _progressTracker;
|
|
|
|
|
private readonly ProgressTracker _progressTracker = MsgBus.ProgressTracker;
|
|
|
|
|
|
|
|
|
|
private const int CLOCK_FREQ = 50; // MHz
|
|
|
|
|
|
|
|
|
|
@@ -400,14 +400,12 @@ public class Jtag
|
|
|
|
|
/// <param name="address">目标 IP 地址</param>
|
|
|
|
|
/// <param name="port">目标 UDP 端口</param>
|
|
|
|
|
/// <param name="timeout">超时时间(毫秒)</param>
|
|
|
|
|
/// <param name="progressTracker">进度追踪器</param>
|
|
|
|
|
public Jtag(string address, int port, int timeout = 2000, ProgressTracker? progressTracker = null)
|
|
|
|
|
public Jtag(string address, int port, int timeout = 2000)
|
|
|
|
|
{
|
|
|
|
|
this.address = address;
|
|
|
|
|
this.port = port;
|
|
|
|
|
this.ep = new IPEndPoint(IPAddress.Parse(address), port);
|
|
|
|
|
this.timeout = timeout;
|
|
|
|
|
this._progressTracker = progressTracker;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async ValueTask<Result<uint>> ReadFIFO(uint devAddr)
|
|
|
|
|
@@ -472,7 +470,8 @@ public class Jtag
|
|
|
|
|
UInt32 resultMask = 0xFF_FF_FF_FF, UInt32 delayMilliseconds = 0, string progressId = "")
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
var ret = await UDPClientPool.WriteAddr(this.ep, 0, devAddr, data, this.timeout, progressId);
|
|
|
|
|
var ret = await UDPClientPool.WriteAddr(
|
|
|
|
|
this.ep, 0, devAddr, data, this.timeout, progressId);
|
|
|
|
|
if (!ret.IsSuccessful) return new(ret.Error);
|
|
|
|
|
if (!ret.Value) return new(new Exception("Write FIFO failed"));
|
|
|
|
|
}
|
|
|
|
|
@@ -483,7 +482,7 @@ public class Jtag
|
|
|
|
|
{
|
|
|
|
|
var ret = await UDPClientPool.ReadAddrWithWait(this.ep, 0, JtagAddr.STATE, result, resultMask, 0, this.timeout);
|
|
|
|
|
if (!ret.IsSuccessful) return new(ret.Error);
|
|
|
|
|
_progressTracker?.AdvanceProgress(progressId, 10);
|
|
|
|
|
_progressTracker.AdvanceProgress(progressId, 10);
|
|
|
|
|
return ret.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -583,7 +582,7 @@ public class Jtag
|
|
|
|
|
else if (!ret.Value) return new(new Exception("Write CMD_JTAG_LOAD_DR_CAREI Failed"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_progressTracker?.AdvanceProgress(progressId, 10);
|
|
|
|
|
_progressTracker.AdvanceProgress(progressId, 10);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
var ret = await WriteFIFO(
|
|
|
|
|
@@ -724,41 +723,43 @@ public class Jtag
|
|
|
|
|
|
|
|
|
|
logger.Trace($"Clear up udp server {this.address,0} receive data");
|
|
|
|
|
|
|
|
|
|
_progressTracker.AdvanceProgress(progressId, 10);
|
|
|
|
|
|
|
|
|
|
Result<bool> ret;
|
|
|
|
|
|
|
|
|
|
ret = await CloseTest();
|
|
|
|
|
if (!ret.IsSuccessful) return new(ret.Error);
|
|
|
|
|
else if (!ret.Value) return new(new Exception("Jtag Close Test Failed"));
|
|
|
|
|
_progressTracker?.AdvanceProgress(progressId, 10);
|
|
|
|
|
_progressTracker.AdvanceProgress(progressId, 10);
|
|
|
|
|
|
|
|
|
|
ret = await RunTest();
|
|
|
|
|
if (!ret.IsSuccessful) return new(ret.Error);
|
|
|
|
|
else if (!ret.Value) return new(new Exception("Jtag Run Test Failed"));
|
|
|
|
|
_progressTracker?.AdvanceProgress(progressId, 10);
|
|
|
|
|
_progressTracker.AdvanceProgress(progressId, 10);
|
|
|
|
|
|
|
|
|
|
logger.Trace("Jtag initialize");
|
|
|
|
|
|
|
|
|
|
ret = await ExecRDCmd(JtagCmd.JTAG_DR_JRST);
|
|
|
|
|
if (!ret.IsSuccessful) return new(ret.Error);
|
|
|
|
|
else if (!ret.Value) return new(new Exception("Jtag Execute Command JTAG_DR_JRST Failed"));
|
|
|
|
|
_progressTracker?.AdvanceProgress(progressId, 10);
|
|
|
|
|
_progressTracker.AdvanceProgress(progressId, 10);
|
|
|
|
|
|
|
|
|
|
ret = await RunTest();
|
|
|
|
|
if (!ret.IsSuccessful) return new(ret.Error);
|
|
|
|
|
else if (!ret.Value) return new(new Exception("Jtag Run Test Failed"));
|
|
|
|
|
_progressTracker?.AdvanceProgress(progressId, 10);
|
|
|
|
|
_progressTracker.AdvanceProgress(progressId, 10);
|
|
|
|
|
|
|
|
|
|
ret = await ExecRDCmd(JtagCmd.JTAG_DR_CFGI);
|
|
|
|
|
if (!ret.IsSuccessful) return new(ret.Error);
|
|
|
|
|
else if (!ret.Value) return new(new Exception("Jtag Execute Command JTAG_DR_CFGI Failed"));
|
|
|
|
|
_progressTracker?.AdvanceProgress(progressId, 10);
|
|
|
|
|
_progressTracker.AdvanceProgress(progressId, 10);
|
|
|
|
|
|
|
|
|
|
logger.Trace("Jtag ready to write bitstream");
|
|
|
|
|
|
|
|
|
|
ret = await IdleDelay(100000);
|
|
|
|
|
if (!ret.IsSuccessful) return new(ret.Error);
|
|
|
|
|
else if (!ret.Value) return new(new Exception("Jtag IDLE Delay Failed"));
|
|
|
|
|
_progressTracker?.AdvanceProgress(progressId, 10);
|
|
|
|
|
_progressTracker.AdvanceProgress(progressId, 10);
|
|
|
|
|
|
|
|
|
|
ret = await LoadDRCareInput(bitstream, progressId: progressId);
|
|
|
|
|
if (!ret.IsSuccessful) return new(ret.Error);
|
|
|
|
|
@@ -769,40 +770,40 @@ public class Jtag
|
|
|
|
|
ret = await CloseTest();
|
|
|
|
|
if (!ret.IsSuccessful) return new(ret.Error);
|
|
|
|
|
else if (!ret.Value) return new(new Exception("Jtag Close Test Failed"));
|
|
|
|
|
_progressTracker?.AdvanceProgress(progressId, 10);
|
|
|
|
|
_progressTracker.AdvanceProgress(progressId, 10);
|
|
|
|
|
|
|
|
|
|
ret = await RunTest();
|
|
|
|
|
if (!ret.IsSuccessful) return new(ret.Error);
|
|
|
|
|
else if (!ret.Value) return new(new Exception("Jtag Run Test Failed"));
|
|
|
|
|
_progressTracker?.AdvanceProgress(progressId, 10);
|
|
|
|
|
_progressTracker.AdvanceProgress(progressId, 10);
|
|
|
|
|
|
|
|
|
|
ret = await ExecRDCmd(JtagCmd.JTAG_DR_JWAKEUP);
|
|
|
|
|
if (!ret.IsSuccessful) return new(ret.Error);
|
|
|
|
|
else if (!ret.Value) return new(new Exception("Jtag Execute Command JTAG_DR_JWAKEUP Failed"));
|
|
|
|
|
_progressTracker?.AdvanceProgress(progressId, 10);
|
|
|
|
|
_progressTracker.AdvanceProgress(progressId, 10);
|
|
|
|
|
|
|
|
|
|
logger.Trace("Jtag reset device");
|
|
|
|
|
|
|
|
|
|
ret = await IdleDelay(10000);
|
|
|
|
|
if (!ret.IsSuccessful) return new(ret.Error);
|
|
|
|
|
else if (!ret.Value) return new(new Exception("Jtag IDLE Delay Failed"));
|
|
|
|
|
_progressTracker?.AdvanceProgress(progressId, 10);
|
|
|
|
|
_progressTracker.AdvanceProgress(progressId, 10);
|
|
|
|
|
|
|
|
|
|
var retCode = await ReadStatusReg();
|
|
|
|
|
if (!retCode.IsSuccessful) return new(retCode.Error);
|
|
|
|
|
var jtagStatus = new JtagStatusReg(retCode.Value);
|
|
|
|
|
if (!(jtagStatus.done && jtagStatus.wakeup_over && jtagStatus.init_complete))
|
|
|
|
|
return new(new Exception("Jtag download bitstream failed"));
|
|
|
|
|
_progressTracker?.AdvanceProgress(progressId, 10);
|
|
|
|
|
_progressTracker.AdvanceProgress(progressId, 10);
|
|
|
|
|
|
|
|
|
|
ret = await CloseTest();
|
|
|
|
|
if (!ret.IsSuccessful) return new(ret.Error);
|
|
|
|
|
else if (!ret.Value) return new(new Exception("Jtag Close Test Failed"));
|
|
|
|
|
logger.Trace("Jtag download bitstream successfully");
|
|
|
|
|
_progressTracker?.AdvanceProgress(progressId, 10);
|
|
|
|
|
_progressTracker.AdvanceProgress(progressId, 10);
|
|
|
|
|
|
|
|
|
|
// Finish
|
|
|
|
|
_progressTracker?.AdvanceProgress(progressId, 10);
|
|
|
|
|
_progressTracker.AdvanceProgress(progressId, 10);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|