add class jtag status reg
This commit is contained in:
		@@ -152,6 +152,15 @@ namespace Common
 | 
			
		||||
            return (srcBits & mask) == dstBits;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static Result<bool> ToBit(UInt32 srcBits, int location)
 | 
			
		||||
        {
 | 
			
		||||
            if (location < 0)
 | 
			
		||||
                return new(new ArgumentException(
 | 
			
		||||
                    "Location can't be negetive", nameof(location)));
 | 
			
		||||
 | 
			
		||||
            return (srcBits & (1 << location)) == 1;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 字符串转二进制字节数组
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
using System.Buffers.Binary;
 | 
			
		||||
using System.Net;
 | 
			
		||||
using Common;
 | 
			
		||||
using Microsoft.AspNetCore.Cors;
 | 
			
		||||
using Microsoft.AspNetCore.Mvc;
 | 
			
		||||
using Newtonsoft.Json;
 | 
			
		||||
using WebProtocol;
 | 
			
		||||
@@ -212,37 +212,13 @@ public class JtagController : ControllerBase
 | 
			
		||||
        if (ret.IsSuccessful)
 | 
			
		||||
        {
 | 
			
		||||
            var binaryValue = Common.String.Reverse(Convert.ToString(ret.Value, 2).PadLeft(32, '0'));
 | 
			
		||||
            logger.Info($"Read device {address} Status Register: 0b{binaryValue}");
 | 
			
		||||
            var decodeValue = new JtagClient.JtagStatusReg(ret.Value);
 | 
			
		||||
            logger.Info($"Read device {address} Status Register: \n\t 0b{binaryValue} \n\t {decodeValue}");
 | 
			
		||||
            return TypedResults.Ok(new
 | 
			
		||||
            {
 | 
			
		||||
                original = ret.Value,
 | 
			
		||||
                binary = binaryValue,
 | 
			
		||||
                id_err = binaryValue[0],
 | 
			
		||||
                crc_err = binaryValue[1],
 | 
			
		||||
                aut_err = binaryValue[2],
 | 
			
		||||
                rbcrc_err = binaryValue[3],
 | 
			
		||||
                timeout = binaryValue[4],
 | 
			
		||||
                wakeup_over = binaryValue[5],
 | 
			
		||||
                wakedown_over = binaryValue[6],
 | 
			
		||||
                m = Common.String.Reverse(binaryValue[7..10]),
 | 
			
		||||
                init_complete = binaryValue[10],
 | 
			
		||||
                init_n = binaryValue[11],
 | 
			
		||||
                done = binaryValue[12],
 | 
			
		||||
                done_i = binaryValue[13],
 | 
			
		||||
                glogen = binaryValue[14],
 | 
			
		||||
                glogen_fb = binaryValue[15],
 | 
			
		||||
                gouten = binaryValue[16],
 | 
			
		||||
                grsn = binaryValue[17],
 | 
			
		||||
                gwen = binaryValue[18],
 | 
			
		||||
                pll_lock = binaryValue[19],
 | 
			
		||||
                fallback = binaryValue[21],
 | 
			
		||||
                ipal_m = Common.String.Reverse(binaryValue[22..24]),
 | 
			
		||||
                flg_x8 = binaryValue[24],
 | 
			
		||||
                flg_x16 = binaryValue[25],
 | 
			
		||||
                flg_x32 = binaryValue[26],
 | 
			
		||||
                over_temp = binaryValue[27],
 | 
			
		||||
                prcfg_err = binaryValue[28],
 | 
			
		||||
                prcfg_over = binaryValue[29],
 | 
			
		||||
                decode = decodeValue,
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
@@ -324,6 +300,7 @@ public class JtagController : ControllerBase
 | 
			
		||||
                    while ((bytesRead = await fileStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
 | 
			
		||||
                    {
 | 
			
		||||
                        var revBuffer = Common.Number.ReverseBytes(buffer, 4);
 | 
			
		||||
 | 
			
		||||
                        if (!revBuffer.IsSuccessful)
 | 
			
		||||
                            return TypedResults.InternalServerError(revBuffer.Error);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
using System.Net;
 | 
			
		||||
using DotNext;
 | 
			
		||||
using Newtonsoft.Json;
 | 
			
		||||
using WebProtocol;
 | 
			
		||||
 | 
			
		||||
namespace JtagClient;
 | 
			
		||||
@@ -213,6 +214,160 @@ public static class JtagCmd
 | 
			
		||||
    public const UInt32 CMD_JTAG_IDLE_DELAY = 0b0101;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// <summary>
 | 
			
		||||
/// JTAG 状态寄存器
 | 
			
		||||
/// </summary>
 | 
			
		||||
public class JtagStatusReg
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// ID 错误标志
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool id_err;
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// CRC 错误标志
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool crc_err;
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 自动测试错误标志
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool aut_err;
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 回读 CRC 错误标志
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool rbcrc_err;
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 超时标志
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool timeout;
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 唤醒完成标志
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool wakeup_over;
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 休眠完成标志
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool wakedown_over;
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 模式位
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public byte m;
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 初始化完成标志
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool init_complete;
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 初始化状态(低电平有效)
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool init_n;
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 完成标志
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool done;
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 内部完成标志
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool done_i;
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 全局逻辑使能标志
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool glogen;
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 全局逻辑反馈标志
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool glogen_fb;
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 全局输出使能标志
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool gouten;
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 全局复位标志
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool grsn;
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 全局写使能标志
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool gwen;
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// PLL 锁定标志
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool pll_lock;
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 回退标志
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool fallback;
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// IPAL 模式位
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public byte ipal_m;
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 8 位标志
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool flg_x8;
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 16 位标志
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool flg_x16;
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 32 位标志
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool flg_x32;
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 过温标志
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool over_temp;
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 配置错误标志
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool prcfg_err;
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 配置完成标志
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public bool prcfg_over;
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 构造函数,从 32 位代码解析 JTAG 状态寄存器
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="code">32 位状态寄存器值</param>
 | 
			
		||||
    public JtagStatusReg(UInt32 code)
 | 
			
		||||
    {
 | 
			
		||||
        this.id_err = Common.Number.ToBit(code, 0).Value;
 | 
			
		||||
        this.crc_err = Common.Number.ToBit(code, 1).Value;
 | 
			
		||||
        this.aut_err = Common.Number.ToBit(code, 2).Value;
 | 
			
		||||
        this.rbcrc_err = Common.Number.ToBit(code, 3).Value;
 | 
			
		||||
        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.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;
 | 
			
		||||
        this.done_i = Common.Number.ToBit(code, 13).Value;
 | 
			
		||||
        this.glogen = Common.Number.ToBit(code, 14).Value;
 | 
			
		||||
        this.glogen_fb = Common.Number.ToBit(code, 15).Value;
 | 
			
		||||
        this.gouten = Common.Number.ToBit(code, 16).Value;
 | 
			
		||||
        this.grsn = Common.Number.ToBit(code, 17).Value;
 | 
			
		||||
        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.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;
 | 
			
		||||
        this.over_temp = Common.Number.ToBit(code, 27).Value;
 | 
			
		||||
        this.prcfg_err = Common.Number.ToBit(code, 28).Value;
 | 
			
		||||
        this.prcfg_over = Common.Number.ToBit(code, 29).Value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 转换为Json字符串
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <returns>Json字符串</returns>
 | 
			
		||||
    public override string ToString()
 | 
			
		||||
    {
 | 
			
		||||
        return JsonConvert.SerializeObject(this);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// <summary>
 | 
			
		||||
/// Jtag控制器
 | 
			
		||||
/// </summary>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user