blob: b9d017690bfe4bed6101497572b34d36188cdc0d [file] [log] [blame]
Rupert Swarbrick10184102021-03-31 09:12:42 +01001# Copyright lowRISC contributors.
2# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3# SPDX-License-Identifier: Apache-2.0
4
5import logging as log
Cindy Chenc8389ed2021-11-04 10:53:07 -07006from typing import List, Optional, Tuple
Rupert Swarbrick10184102021-03-31 09:12:42 +01007
8from mako import exceptions # type: ignore
9from mako.lookup import TemplateLookup # type: ignore
10from pkg_resources import resource_filename
11
12from reggen.gen_dv import gen_core_file
13
14from .top import Top
15
16
17def sv_base_addr(top: Top, if_name: Tuple[str, Optional[str]]) -> str:
18 '''Get the base address of a device interface in SV syntax'''
19 return "{}'h{:x}".format(top.regwidth, top.if_addrs[if_name])
20
21
22def gen_dv(top: Top,
Cindy Chenc8389ed2021-11-04 10:53:07 -070023 dv_base_names: List[str],
Rupert Swarbrick10184102021-03-31 09:12:42 +010024 outdir: str) -> int:
25 '''Generate DV RAL model for a Top'''
26 # Read template
27 lookup = TemplateLookup(directories=[resource_filename('topgen', '.'),
28 resource_filename('reggen', '.')])
29 uvm_reg_tpl = lookup.get_template('top_uvm_reg.sv.tpl')
30
31 # Expand template
32 try:
33 to_write = uvm_reg_tpl.render(top=top,
Cindy Chene16009b2021-11-01 19:35:51 -070034 dv_base_names=dv_base_names)
Rupert Swarbrick10184102021-03-31 09:12:42 +010035 except: # noqa: E722
36 log.error(exceptions.text_error_template().render())
37 return 1
38
39 # Dump to output file
40 dest_path = '{}/chip_ral_pkg.sv'.format(outdir)
41 with open(dest_path, 'w') as fout:
42 fout.write(to_write)
43
Cindy Chene16009b2021-11-01 19:35:51 -070044 gen_core_file(outdir, 'chip', dv_base_names, ['chip_ral_pkg.sv'])
Rupert Swarbrick10184102021-03-31 09:12:42 +010045
46 return 0