水风山月的个人空间 https://blog.eetop.cn/?1724654 [收藏] [复制] [分享] [RSS]

日志

python srcipt ex1

已有 17 次阅读| 2025-12-17 11:05 |系统分类:芯片设计

import pandas as pd

import time


local_time = time.strftime("//        %Y-%m-%d %H:%M:%S", time.localtime())

excel = "XXX.xlsx"

sheet = 0

output = "XXX.v"


# Columns A–D = index 0–3:

COL_ADDR = 0

COL_NAME = 1

COL_RESET = 2

COL_LATCH = 3


def is_dual_latch(x):

    if (x=='aev'):

        return True

    else:

        return False

def is_zero(x):

    if (x==0):

        return True

    else:

        return False

df = pd.read_excel(excel, sheet_name=sheet)


df_filtered = df.iloc[3:][df.iloc[3:,COL_NAME] != 0][df.iloc[3:,COL_NAME].notna()].copy()


reg_defs = []

reg_lat = []

lat_blocks = []

dff_blocks = []

dff2_blocks = []

assign_lines = []

readcase_lines = []

reg_table = []


# ------------------------------------------------------------

# PROCESS EACH REGISTER

# ------------------------------------------------------------

for _, row in df_filtered.iterrows():

    name = str(row[COL_NAME]).strip()

    addr = int(row[COL_ADDR])

    rstv = str(row[COL_RESET]).strip()

    aev  = str(row[COL_LATCH]).strip()

    #rstv = int(row[COL_RESET], 16) if isinstance(row[COL_RESET], str) else int(row[COL_RESET])

    dual = is_dual_latch(row[COL_LATCH])


    if dual:

        reg_table.append(f"{addr} {name} {rstv} {aev}")

    else:

        reg_table.append(f"{addr} {name} {rstv}")

    dff = f"dff_{addr}"

    defi = f"def_{addr}"

    lat = f"lat_{addr}"


    # output port name

    port = f"{name}"


    # --------------------------------------------

    # Declarations (same as your file)

    # --------------------------------------------

    reg_defs.append(f" reg [15:0] {dff} ; wire [15:0] {defi} = {rstv} ; /// {port}")


    if dual:

        reg_lat.append(f" reg [15:0] {lat} ;")


    # --------------------------------------------

    # Dual latch stage (lat_x)

    # --------------------------------------------

    if dual:


        # second stage


    # --------------------------------------------

    # Normal single-stage register

    # --------------------------------------------

    else:

        dff_blocks.append(f" always @(posedge sclk , negedge rstb_async) begin")

        dff_blocks.append(f"   if (!rstb_async) {dff} <= {defi};")

        dff_blocks.append(f"   else if (addr == 7'd{addr} && !wen) {dff} <= wdata;")

        dff_blocks.append(f" end\n")


    # --------------------------------------------

    # Output assign and read-case

    # --------------------------------------------

    assign_lines.append(f"  assign  {port} = {dff};")

    readcase_lines.append(f"       7'd{addr}: rdata = {dff};")

reg_ports[-1] = reg_ports[-1].rstrip(',')

# ------------------------------------------------------------

# BUILD FILE CONTENT

# ------------------------------------------------------------


out = []

out.append("//////////////////////////////////////")

out.append(local_time)

out.append("//////////////////////////////////////")

out.append("// define initial value //////////\n")

out.extend(reg_lat)

out.extend(reg_defs)


out.append("\n//////////////////////////////////")

out.append("// lat define ////////////////////\n")

out.extend(lat_blocks)


out.append("//////////////////////////////////")

out.append("// dff define ////////////////////\n")

out.append("// 2nd stage define //////////////\n")

out.extend(dff2_blocks)

out.append("//////////////////////////////////\n")

out.extend(dff_blocks)


out.append("//////////////////////////////////")

out.append("// create bus ////////////////////\n")

out.extend(assign_lines)

out.append("")


out.append("//////////////////////////////////")

out.append("// abus read /////////////////////\n")

out.append("  always @(*) begin")

out.append("    case (addr)")

out.extend(readcase_lines)

out.append("       default: rdata = 0;")

out.append("    endcase")

out.append("  end\n")


with open(output, "w") as f:

    f.write("\n".join(out))


print("Generated:", output)



点赞

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 1

    粉丝
  • 3

    好友
  • 0

    获赞
  • 0

    评论
  • 29

    访问数
关闭

站长推荐 上一条 /1 下一条


手机版| 小黑屋| 关于我们| 联系我们| 用户协议&隐私声明| 版权投诉通道| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 ) |网站地图

GMT+8, 2025-12-18 10:59 , Processed in 0.022410 second(s), 14 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部