PYCPLD的IP设计规范

PYCPLD的IP 设计规范

 

1. 如何将IP做成python 模块

IP开发者需要提供以下文件:

这个文件命名是python定义本地文件包的标准做法,在本文件中内容如下

__init__.py
from enc_partial import get_ip_name
from enc_partial import ENC

 enc_partial 是这个文件包的名字

get_ip_name 是这个IP的程序名函数

ENC 是这个IP的python 类的名字

 

2. <ip name>.v

IP的具体实现verilog文件,参考以下链接:

https://github.com/hakehuang/pycpld/blob/master/ips/ip/enc/enc.v

 

3. env_partial.py

https://github.com/hakehuang/pycpld/blob/master/ips/ip/enc/enc_partial.py

enc_partial.py 写道
from .. import base_ip
import os
'''
#an example of io_dic of enc io
{
  ("", 50, "//comments", "pha_out", "enc")
}
'''
#return the class name for query
def get_ip_name():
  return "ENC"
class ENC(base_ip.base_ip):
  ID = "__ENC"
  count = 0
  def __init__(self, io_hash):
    self.dicts = io_hash
    self.count = 1
  def set_alt(self, in_alt):
    return ''
  def matched_id(self, in_key):
    return in_key == self.ID
  def get_pinmux_setting(self):
    return ''
  def get_v_file_list(self):
   #set_global_assignment -name VERILOG_FILE enc.v
    pkgpath = os.path.dirname(__file__)
    return [ os.path.join(pkgpath,"enc.v")]
  def get_module_caller(self):
    return """
enc  enc( .rst_n(rst_n),
          .freq_clk(clk),
          .enable(enable_enc),
       .pha(pha_out),
       .phb(phb_out),
       .home(home_out),
       .index(index_out)
        );
            """
  def get_wire_defines(self):
    return """
wire pha_out;
wire phb_out;
wire home_out;
wire index_out;
          """
  def get_reg_defines(self):
   #additional reg definition
   return "reg enable_enc;\n"
  def module_rest_codes():
    return "enable_enc <= 1'b0;"
  def get_cmd_case_text(self):
    return "enable_enc <= 1'b1;"
  def get_rst_case_text(self):
    return "enable_enc <= 1'b0;"
  def get_dft_case_text(self):
    return "enable_enc <= 1'b0;"
 

在这个文件中实现了对verilog IP到IP应用平台需要开放的接口的脚本化,里面的每一个函数都需要实现对应的接口功能, 这里verilog 语句就是python中的脚本。

 

3. 如何实现IP的引脚的参数化配置,我们用了一个yaml文件来做:

enc_example.yml

 

ENC:
    IP: __ENC
    CMD: ENC
    pha_out:
        PIN: A34
        DIRECTION: out
    phb_out:
        PIN: A33
        DIRECTION: out
    index_out:
        PIN: CPLD_IO50
        DIRECTION: out

 

ENC: 是这个的IP 的开始 对应get_ip_name

IP: __ENC 表示应用ENC这个IP, 对应  ID = "__ENC"

CMD: 表示系统集成平台里面通过什么串口命令来使能IP

        PIN: A34 表示CPLD IO 文件中定义的管脚
        DIRECTION: out 管脚的方向

 

https://github.com/hakehuang/pycpld

 

 

 

猜你喜欢

转载自hakehuang.iteye.com/blog/2344082