Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #548: use == instead of in for string comparison in Python/.tpl #551

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 8 additions & 40 deletions hw/core-v-mini-mcu/peripheral_subsystem.sv.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,7 @@ module peripheral_subsystem
.reg_rsp_o(peripheral_slv_rsp[core_v_mini_mcu_pkg::RV_PLIC_IDX])
);

% for peripheral in peripherals.items():
% if peripheral[0] in ("rv_plic"):
% if peripheral[1]['is_included'] in ("yes"):
% if 'rv_plic' in peripherals and peripherals['rv_plic']['is_included'] == 'yes':
rv_plic rv_plic_i (
.clk_i(clk_cg),
.rst_ni,
Expand All @@ -315,12 +313,8 @@ module peripheral_subsystem
assign irq_plic_o = '0;
assign plic_tl_d2h = '0;
% endif
% endif
% endfor

% for peripheral in peripherals.items():
% if peripheral[0] in ("spi_host"):
% if peripheral[1]['is_included'] in ("yes"):
% if 'spi_host' in peripherals and peripherals['spi_host']['is_included'] == 'yes':
spi_host #(
.reg_req_t(reg_pkg::reg_req_t),
.reg_rsp_t(reg_pkg::reg_rsp_t)
Expand Down Expand Up @@ -357,14 +351,10 @@ module peripheral_subsystem
assign spi_rx_valid_o = '0;
assign spi_tx_ready_o = '0;
% endif
% endif
% endfor



% for peripheral in peripherals.items():
% if peripheral[0] in ("gpio"):
% if peripheral[1]['is_included'] in ("yes"):
% if 'gpio' in peripherals and peripherals['gpio']['is_included'] == 'yes':
gpio #(
.reg_req_t(reg_pkg::reg_req_t),
.reg_rsp_t(reg_pkg::reg_rsp_t)
Expand All @@ -386,8 +376,6 @@ module peripheral_subsystem
assign gpio_intr = '0;
assign peripheral_slv_rsp[core_v_mini_mcu_pkg::GPIO_IDX] = '0;
% endif
% endif
% endfor

reg_to_tlul #(
.req_t(reg_pkg::reg_req_t),
Expand All @@ -406,9 +394,7 @@ module peripheral_subsystem
.reg_rsp_o(peripheral_slv_rsp[core_v_mini_mcu_pkg::I2C_IDX])
);

% for peripheral in peripherals.items():
% if peripheral[0] in ("i2c"):
% if peripheral[1]['is_included'] in ("yes"):
% if 'i2c' in peripherals and peripherals['i2c']['is_included'] == 'yes':
i2c i2c_i (
.clk_i(clk_cg),
.rst_ni,
Expand Down Expand Up @@ -460,8 +446,6 @@ module peripheral_subsystem
assign i2c_intr_ack_stop = '0;
assign i2c_intr_host_timeout = '0;
% endif
% endif
% endfor

reg_to_tlul #(
.req_t(reg_pkg::reg_req_t),
Expand All @@ -480,9 +464,7 @@ module peripheral_subsystem
.reg_rsp_o(peripheral_slv_rsp[core_v_mini_mcu_pkg::RV_TIMER_IDX])
);

% for peripheral in peripherals.items():
% if peripheral[0] in ("rv_timer"):
% if peripheral[1]['is_included'] in ("yes"):
% if 'rv_timer' in peripherals and peripherals['rv_timer']['is_included'] == 'yes':
rv_timer rv_timer_2_3_i (
.clk_i(clk_cg),
.rst_ni,
Expand All @@ -496,12 +478,8 @@ module peripheral_subsystem
assign rv_timer_2_intr_o = '0;
assign rv_timer_3_intr_o = '0;
% endif
% endif
% endfor

% for peripheral in peripherals.items():
% if peripheral[0] in ("spi2"):
% if peripheral[1]['is_included'] in ("yes"):
% if 'spi2' in peripherals and peripherals['spi2']['is_included'] == 'yes':
spi_host #(
.reg_req_t(reg_pkg::reg_req_t),
.reg_rsp_t(reg_pkg::reg_rsp_t)
Expand Down Expand Up @@ -536,12 +514,8 @@ module peripheral_subsystem
assign spi2_sd_en_o = '0;
assign spi2_intr_event = '0;
% endif
% endif
% endfor

% for peripheral in peripherals.items():
% if peripheral[0] in ("pdm2pcm"):
% if peripheral[1]['is_included'] in ("yes"):
% if 'pdm2pcm' in peripherals and peripherals['pdm2pcm']['is_included'] == 'yes':
pdm2pcm #(
.reg_req_t(reg_pkg::reg_req_t),
.reg_rsp_t(reg_pkg::reg_rsp_t)
Expand All @@ -557,14 +531,10 @@ module peripheral_subsystem
assign peripheral_slv_rsp[core_v_mini_mcu_pkg::PDM2PCM_IDX] = '0;
assign pdm2pcm_clk_o = '0;
% endif
% endif
% endfor

assign pdm2pcm_clk_en_o = 1;

% for peripheral in peripherals.items():
% if peripheral[0] in ("i2s"):
% if peripheral[1]['is_included'] in ("yes"):
% if 'i2s' in peripherals and peripherals['i2s']['is_included'] == 'yes':
i2s #(
.reg_req_t(reg_pkg::reg_req_t),
.reg_rsp_t(reg_pkg::reg_rsp_t)
Expand Down Expand Up @@ -598,7 +568,5 @@ module peripheral_subsystem
assign i2s_intr_event = 1'b0;
assign i2s_rx_valid_o = 1'b0;
% endif
% endif
% endfor

endmodule : peripheral_subsystem
4 changes: 2 additions & 2 deletions pad_cfg.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
rst: {
num: 1,
active: low,
active: low
driven_manually: True
type: input
},
Expand All @@ -55,7 +55,7 @@
},
jtag_trst: {
num: 1,
active: low,
active: low
type: input
},
jtag_tdi: {
Expand Down
30 changes: 14 additions & 16 deletions util/mcu_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def __init__(self, name, cell_name, pad_type, pad_mapping, index, pad_active, pa
self.pad_mapping = pad_mapping
self.pad_mux_list = pad_mux_list

if('low' in pad_active):
if pad_active == 'low':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if there are commas , in the hjson file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There shouldn't. Not in a valid Hjson file at least.
https://hjson.github.io/syntax.html

Do not add commas or comments as they would become part of the string.

Note that I fixed the affected Hjson file in this commit, so that should not be an issue in this particular case.
(But feel free to ditch the second commit of the PR and pull only the first one if you're not sure about that yet.)

Also see issue #552 which I created just now, immediately after submitting this PR, as I realized about that issue while dealing with this one.

name_active = 'n'
else:
name_active = ''
Expand Down Expand Up @@ -474,7 +474,7 @@ def extract_peripherals(peripherals):
if isinstance(info, dict):
new_info = {}
for k, v in info.items():
if k not in ("is_included"):
if k != "is_included":
new_info[k] = string2int(v)
else:
new_info[k] = v
Expand All @@ -487,7 +487,7 @@ def discard_path(peripherals):
new = {}
for k,v in peripherals.items():
if isinstance(v, dict):
new[k] = {key:val for key,val in v.items() if key not in ("path")}
new[k] = {key:val for key,val in v.items() if key != "path"}
else:
new[k] = v
return new
Expand All @@ -496,10 +496,8 @@ def len_extracted_peripherals(peripherals):
len_ep = 0
for name, info in peripherals.items():
if isinstance(info, dict):
for k, v in info.items():
if k in ("is_included"):
if v in ("yes"):
len_ep += 1
if info['is_included'] == "yes":
len_ep += 1
return len_ep

ao_peripherals = extract_peripherals(discard_path(obj['ao_peripherals']))
Expand Down Expand Up @@ -598,23 +596,23 @@ def len_extracted_peripherals(peripherals):
pad_mux_list_hjson = []

try:
if ('True' in pads[key]['driven_manually']):
if pads[key]['driven_manually'] == 'True':
pad_driven_manually = True
else:
pad_driven_manually = False
except KeyError:
pad_driven_manually = False

try:
if ('True' in pads[key]['skip_declaration']):
if pads[key]['skip_declaration'] == 'True':
pad_skip_declaration = True
else:
pad_skip_declaration = False
except KeyError:
pad_skip_declaration = False

try:
if ('True' in pads[key]['keep_internal']):
if pads[key]['keep_internal'] == 'True':
pad_keep_internal = True
else:
pad_keep_internal = False
Expand All @@ -631,15 +629,15 @@ def len_extracted_peripherals(peripherals):
pad_active_mux = 'high'

try:
if ('True' in pads[key]['mux'][pad_mux]['driven_manually']):
if pads[key]['mux'][pad_mux]['driven_manually'] == 'True':
pad_driven_manually_mux = True
else:
pad_driven_manually_mux = False
except KeyError:
pad_driven_manually_mux = False

try:
if ('True' in pads[key]['mux'][pad_mux]['skip_declaration']):
if pads[key]['mux'][pad_mux]['skip_declaration'] == 'True':
pad_skip_declaration_mux = True
else:
pad_skip_declaration_mux = False
Expand Down Expand Up @@ -717,15 +715,15 @@ def len_extracted_peripherals(peripherals):
pad_mux_list_hjson = []

try:
if ('True' in external_pads[key]['driven_manually']):
if external_pads[key]['driven_manually'] == 'True':
pad_driven_manually = True
else:
pad_driven_manually = False
except KeyError:
pad_driven_manually = False

try:
if ('True' in external_pads[key]['skip_declaration']):
if external_pads[key]['skip_declaration'] == 'True':
pad_skip_declaration = True
else:
pad_skip_declaration = False
Expand All @@ -742,15 +740,15 @@ def len_extracted_peripherals(peripherals):
pad_active_mux = 'high'

try:
if ('True' in external_pads[key]['mux'][pad_mux]['driven_manually']):
if external_pads[key]['mux'][pad_mux]['driven_manually'] == 'True':
pad_driven_manually_mux = True
else:
pad_driven_manually_mux = False
except KeyError:
pad_driven_manually_mux = False

try:
if ('True' in external_pads[key]['mux'][pad_mux]['skip_declaration']):
if external_pads[key]['mux'][pad_mux]['skip_declaration'] == 'True':
pad_skip_declaration_mux = True
else:
pad_skip_declaration_mux = False
Expand Down