Fix bug with static values for saturate/threshold values

This commit is contained in:
Dennis Potter 2021-11-06 18:24:42 -07:00
parent b44813e0c5
commit 17c1b9b9a0
Signed by: Dennis
GPG Key ID: 186A8AD440942BAF
2 changed files with 23 additions and 17 deletions

View File

@ -262,48 +262,54 @@ class Field(Component):
self.rtl_footer.append(Field.templ_dict['counter_comment']['rtl'])
# Determine saturation values
if isinstance(self.obj.get_property('incrsaturate'), bool):
if self.obj.get_property('incrsaturate'):
if isinstance(saturate := self.obj.get_property('incrsaturate'), bool):
if saturate:
incr_sat_value = f"{self.obj.width}'d{2**self.obj.width-1}"
overflow_value = incr_sat_value
else:
incr_sat_value = False
overflow_value = 2**self.obj.width-1
elif isinstance(saturate, int):
incr_sat_value = f"{self.obj.width}'d{saturate}"
underflow_value = incr_sat_value
else:
incr_sat_value = self.get_signal_name(
self.obj.get_property('incrsaturate'))
incr_sat_value = self.get_signal_name(saturate)
overflow_value = incr_sat_value
if isinstance(self.obj.get_property('decrsaturate'), bool):
if self.obj.get_property('decrsaturate'):
if isinstance(saturate := self.obj.get_property('decrsaturate'), bool):
if saturate:
decr_sat_value = f"{self.obj.width}'d0"
underflow_value = decr_sat_value
else:
decr_sat_value = False
underflow_value = 0
elif isinstance(saturate, int):
decr_sat_value = f"{self.obj.width}'d{saturate}"
underflow_value = decr_sat_value
else:
decr_sat_value = self.get_signal_name(
self.obj.get_property('decrsaturate'))
decr_sat_value = self.get_signal_name(saturate)
underflow_value = decr_sat_value
# Determine threshold values
if isinstance(self.obj.get_property('incrthreshold'), bool):
if self.obj.get_property('incrthreshold'):
if isinstance(threshold := self.obj.get_property('incrthreshold'), bool):
if threshold:
incr_thr_value = f"{self.obj.width}'d{2**self.obj.width-1}"
else:
incr_thr_value = False
elif isinstance(threshold, int):
incr_thr_value = f"{self.obj.width}'d{threshold}"
else:
incr_thr_value = self.get_signal_name(
self.obj.get_property('incrthreshold'))
incr_thr_value = self.get_signal_name(threshold)
if isinstance(self.obj.get_property('decrthreshold'), bool):
if self.obj.get_property('decrthreshold'):
if isinstance(threshold := self.obj.get_property('decrthreshold'), bool):
if threshold:
decr_thr_value = f"{self.obj.width}'d{2**self.obj.width-1}"
else:
decr_thr_value = False
elif isinstance(threshold, int):
decr_thr_value = f"{self.obj.width}'d{threshold}"
else:
decr_thr_value = self.get_signal_name(
self.obj.get_property('decrthreshold'))
decr_thr_value = self.get_signal_name(threshold)
# Determine with what value the counter is incremented
# According to the spec, the incrvalue/decrvalue default to '1'

View File

@ -397,7 +397,7 @@ counter_incr_thr:
signal_type: 'logic'
counter_decr_thr:
rtl: |-
assign {path}_decr_thr{genvars} = {{1'b0, {path}_q{genvars}}} + ({{{width_plus_1}{{{path}_incr}}}} & {{{incr_sat_zero_pad}{path}_incr_val}}) <= {{1'b0, {sat_value}}} + ({{{width_plus_1}{{{path}_decr}}}} & {{{decr_sat_zero_pad}{path}_decr_val}}) ;
assign {path}_decr_thr{genvars} = {{1'b0, {path}_q{genvars}}} + ({{{width_plus_1}{{{path}_incr}}}} & {{{incr_sat_zero_pad}{path}_incr_val}}) <= {{1'b0, {thr_value}}} + ({{{width_plus_1}{{{path}_decr}}}} & {{{decr_sat_zero_pad}{path}_decr_val}}) ;
output_ports:
- name: '{path}_decr_thr'
signal_type: 'logic'