fix download bitstream and add json convert for jtag status reg
This commit is contained in:
parent
2b5154062d
commit
42ddd0fcdb
|
@ -36,4 +36,13 @@ public class CommonTest
|
|||
};
|
||||
Assert.Equal(Number.ReverseBytes(bytesArray, 4).Value, rev4Bytes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToBitTest()
|
||||
{
|
||||
Assert.Equal(Number.ToBit(0xFF, 3).Value, true);
|
||||
Assert.Equal(Number.ToBit(0x00, 3).Value, false);
|
||||
Assert.Equal(Number.ToBit(0xAA, 3).Value, true);
|
||||
Assert.Equal(Number.ToBit(0xAA, 2).Value, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ try
|
|||
|
||||
// Services Settings
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllersWithViews();
|
||||
// builder.Services.AddControllersWithViews();
|
||||
|
||||
// NLog: Setup NLog for Dependency injection
|
||||
builder.Logging.ClearProviders();
|
||||
|
|
|
@ -158,7 +158,7 @@ namespace Common
|
|||
return new(new ArgumentException(
|
||||
"Location can't be negetive", nameof(location)));
|
||||
|
||||
return (srcBits & (1 << location)) == 1;
|
||||
return ((srcBits >> location) & ((UInt32)0b1)) == 1;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -217,8 +217,8 @@ public class JtagController : ControllerBase
|
|||
return TypedResults.Ok(new
|
||||
{
|
||||
original = ret.Value,
|
||||
binary = binaryValue,
|
||||
decode = decodeValue,
|
||||
binaryValue,
|
||||
decodeValue,
|
||||
});
|
||||
}
|
||||
else
|
||||
|
@ -291,6 +291,7 @@ public class JtagController : ControllerBase
|
|||
|
||||
// 定义缓冲区大小: 32KB
|
||||
byte[] buffer = new byte[32 * 1024];
|
||||
byte[] revBuffer = new byte[32 * 1024];
|
||||
long totalBytesRead = 0;
|
||||
|
||||
// 使用异步流读取文件
|
||||
|
@ -299,12 +300,17 @@ public class JtagController : ControllerBase
|
|||
int bytesRead;
|
||||
while ((bytesRead = await fileStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
|
||||
{
|
||||
var revBuffer = Common.Number.ReverseBytes(buffer, 4);
|
||||
// 反转 32bits
|
||||
var retBuffer = Common.Number.ReverseBytes(buffer, 4);
|
||||
if (!retBuffer.IsSuccessful)
|
||||
return TypedResults.InternalServerError(retBuffer.Error);
|
||||
revBuffer = retBuffer.Value;
|
||||
for (int i = 0; i < buffer.Length; i++)
|
||||
{
|
||||
revBuffer[i] = BinaryPrimitives.ReverseEndianness(revBuffer[i]);
|
||||
}
|
||||
|
||||
if (!revBuffer.IsSuccessful)
|
||||
return TypedResults.InternalServerError(revBuffer.Error);
|
||||
|
||||
await memoryStream.WriteAsync(revBuffer.Value, 0, bytesRead);
|
||||
await memoryStream.WriteAsync(revBuffer, 0, bytesRead);
|
||||
totalBytesRead += bytesRead;
|
||||
}
|
||||
|
||||
|
|
|
@ -222,107 +222,107 @@ public class JtagStatusReg
|
|||
/// <summary>
|
||||
/// ID 错误标志
|
||||
/// </summary>
|
||||
public bool id_err;
|
||||
public bool id_err { get; set; }
|
||||
/// <summary>
|
||||
/// CRC 错误标志
|
||||
/// </summary>
|
||||
public bool crc_err;
|
||||
public bool crc_err { get; set; }
|
||||
/// <summary>
|
||||
/// 自动测试错误标志
|
||||
/// </summary>
|
||||
public bool aut_err;
|
||||
public bool aut_err { get; set; }
|
||||
/// <summary>
|
||||
/// 回读 CRC 错误标志
|
||||
/// </summary>
|
||||
public bool rbcrc_err;
|
||||
public bool rbcrc_err { get; set; }
|
||||
/// <summary>
|
||||
/// 超时标志
|
||||
/// </summary>
|
||||
public bool timeout;
|
||||
public bool timeout { get; set; }
|
||||
/// <summary>
|
||||
/// 唤醒完成标志
|
||||
/// </summary>
|
||||
public bool wakeup_over;
|
||||
public bool wakeup_over { get; set; }
|
||||
/// <summary>
|
||||
/// 休眠完成标志
|
||||
/// </summary>
|
||||
public bool wakedown_over;
|
||||
public bool wakedown_over { get; set; }
|
||||
/// <summary>
|
||||
/// 模式位
|
||||
/// </summary>
|
||||
public byte m;
|
||||
public string m { get; set; }
|
||||
/// <summary>
|
||||
/// 初始化完成标志
|
||||
/// </summary>
|
||||
public bool init_complete;
|
||||
public bool init_complete { get; set; }
|
||||
/// <summary>
|
||||
/// 初始化状态(低电平有效)
|
||||
/// </summary>
|
||||
public bool init_n;
|
||||
public bool init_n { get; set; }
|
||||
/// <summary>
|
||||
/// 完成标志
|
||||
/// </summary>
|
||||
public bool done;
|
||||
public bool done { get; set; }
|
||||
/// <summary>
|
||||
/// 内部完成标志
|
||||
/// </summary>
|
||||
public bool done_i;
|
||||
public bool done_i { get; set; }
|
||||
/// <summary>
|
||||
/// 全局逻辑使能标志
|
||||
/// </summary>
|
||||
public bool glogen;
|
||||
public bool glogen { get; set; }
|
||||
/// <summary>
|
||||
/// 全局逻辑反馈标志
|
||||
/// </summary>
|
||||
public bool glogen_fb;
|
||||
public bool glogen_fb { get; set; }
|
||||
/// <summary>
|
||||
/// 全局输出使能标志
|
||||
/// </summary>
|
||||
public bool gouten;
|
||||
public bool gouten { get; set; }
|
||||
/// <summary>
|
||||
/// 全局复位标志
|
||||
/// </summary>
|
||||
public bool grsn;
|
||||
public bool grsn { get; set; }
|
||||
/// <summary>
|
||||
/// 全局写使能标志
|
||||
/// </summary>
|
||||
public bool gwen;
|
||||
public bool gwen { get; set; }
|
||||
/// <summary>
|
||||
/// PLL 锁定标志
|
||||
/// </summary>
|
||||
public bool pll_lock;
|
||||
public bool pll_lock { get; set; }
|
||||
/// <summary>
|
||||
/// 回退标志
|
||||
/// </summary>
|
||||
public bool fallback;
|
||||
public bool fallback { get; set; }
|
||||
/// <summary>
|
||||
/// IPAL 模式位
|
||||
/// </summary>
|
||||
public byte ipal_m;
|
||||
public string ipal_m { get; set; }
|
||||
/// <summary>
|
||||
/// 8 位标志
|
||||
/// </summary>
|
||||
public bool flg_x8;
|
||||
public bool flg_x8 { get; set; }
|
||||
/// <summary>
|
||||
/// 16 位标志
|
||||
/// </summary>
|
||||
public bool flg_x16;
|
||||
public bool flg_x16 { get; set; }
|
||||
/// <summary>
|
||||
/// 32 位标志
|
||||
/// </summary>
|
||||
public bool flg_x32;
|
||||
public bool flg_x32 { get; set; }
|
||||
/// <summary>
|
||||
/// 过温标志
|
||||
/// </summary>
|
||||
public bool over_temp;
|
||||
public bool over_temp { get; set; }
|
||||
/// <summary>
|
||||
/// 配置错误标志
|
||||
/// </summary>
|
||||
public bool prcfg_err;
|
||||
public bool prcfg_err { get; set; }
|
||||
/// <summary>
|
||||
/// 配置完成标志
|
||||
/// </summary>
|
||||
public bool prcfg_over;
|
||||
public bool prcfg_over { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数,从 32 位代码解析 JTAG 状态寄存器
|
||||
|
@ -337,7 +337,7 @@ public class JtagStatusReg
|
|||
this.timeout = Common.Number.ToBit(code, 4).Value;
|
||||
this.wakeup_over = Common.Number.ToBit(code, 5).Value;
|
||||
this.wakedown_over = Common.Number.ToBit(code, 6).Value;
|
||||
this.m = ((byte)(code & (0b111 << 7)));
|
||||
this.m = Convert.ToString(((code >> 7) & 0b111), 2);
|
||||
this.init_complete = Common.Number.ToBit(code, 10).Value;
|
||||
this.init_n = Common.Number.ToBit(code, 11).Value;
|
||||
this.done = Common.Number.ToBit(code, 12).Value;
|
||||
|
@ -349,7 +349,7 @@ public class JtagStatusReg
|
|||
this.gwen = Common.Number.ToBit(code, 18).Value;
|
||||
this.pll_lock = Common.Number.ToBit(code, 19).Value;
|
||||
this.fallback = Common.Number.ToBit(code, 21).Value;
|
||||
this.ipal_m = ((byte)(code & (0b11 << 22)));
|
||||
this.ipal_m = Convert.ToString(((code >> 22) & 0b11), 2);
|
||||
this.flg_x8 = Common.Number.ToBit(code, 24).Value;
|
||||
this.flg_x16 = Common.Number.ToBit(code, 25).Value;
|
||||
this.flg_x32 = Common.Number.ToBit(code, 26).Value;
|
||||
|
@ -887,6 +887,12 @@ public class Jtag
|
|||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag IDLE Delay Failed"));
|
||||
|
||||
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"));
|
||||
|
||||
ret = await CloseTest();
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag Close Test Failed"));
|
||||
|
|
Loading…
Reference in New Issue