Skip to content

Commit db4c401

Browse files
committed
wip
1 parent 97182a6 commit db4c401

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

chipflow_lib/common/sim/models.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,16 +284,16 @@ void gpio_model::step(unsigned timestamp) {
284284
if (action.event == "set") {
285285
auto bin = std::string(action.payload);
286286
input_data = 0;
287-
for (unsigned i = 0; i < width; i++) {
288-
if (bin.at((width - 1) - i) == '1')
287+
for (unsigned i = 0; i < pin_count; i++) {
288+
if (bin.at((pin_count - 1) - i) == '1')
289289
input_data |= (1U << i);
290290
}
291291
}
292292
}
293293

294294
if (o_value != s.o_last || oe_value != s.oe_last) {
295295
std::string formatted_value;
296-
for (int i = width - 1; i >= 0; i--) {
296+
for (int i = pin_count - 1; i >= 0; i--) {
297297
if (oe_value & (1U << unsigned(i)))
298298
formatted_value += (o_value & (1U << unsigned(i))) ? '1' : '0';
299299
else

chipflow_lib/common/sim/models.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,21 @@ struct uart_model {
8383
};
8484

8585
struct gpio_model {
86-
static constexpr unsigned width = 8;
8786
std::string name;
88-
gpio_model(const std::string &name, const value<width> &o, const value<width> &oe, value<width> &i) : name(name), o(o), oe(oe), i(i) {};
87+
struct parameters {
88+
unsigned pin_count;
89+
};
90+
parameters parameters;
91+
92+
gpio_model(const std::string &name, parameters, const value<paramters.pin_count> &o, const value<parameters.pin_count> &oe, value<parameters.pin_count> &i) : name(name), parameters(parameters), o(o), oe(oe), i(i) {};
8993

9094
void step(unsigned timestamp);
9195

9296
private:
9397
uint32_t input_data = 0;
94-
const value<width> &o;
95-
const value<width> &oe;
96-
value<width> &i;
98+
const value<pin_count> &o;
99+
const value<pin_count> &oe;
100+
value<pin_count> &i;
97101
struct {
98102
uint32_t o_last = 0;
99103
uint32_t oe_last = 0;

chipflow_lib/platforms/_signatures.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,19 @@ def decorate(klass):
2323
dec = amaranth_annotate(SimInterface, SIM_ANNOTATION_SCHEMA)
2424
klass = dec(klass)
2525

26-
original_init = klass.__init__
2726
def new_init(self,*args, **kwargs):
27+
print("called new_init")
2828
original_init(self, *args, **kwargs)
2929
self.__chipflow_annotation__ = {
3030
"uid": klass.__chipflow_uid__,
3131
"parameters": self.__chipflow_parameters__(),
3232
}
3333

34+
original_init = klass.__init__
3435
klass.__init__ = new_init
3536
klass.__chipflow_uid__ = f"{base}.{klass.__name__}"
36-
klass.__chipflow_parameters__ = lambda self: {}
37+
if not hasattr(klass, '__chipflow_parameters__'):
38+
klass.__chipflow_parameters__ = lambda self: {}
3739
return klass
3840
return decorate
3941

@@ -98,6 +100,7 @@ def __init__(self, pin_count=1, **kwargs: Unpack[IOModelOptions]):
98100
})
99101

100102
def __chipflow_parameters__(self):
103+
print("called GPIOSignature.__chipflow_parameters__")
101104
return {'pin_count': self._pin_count}
102105

103106
def __repr__(self) -> str:

chipflow_lib/platforms/sim.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ def uid_to_c(self, uid: str) -> str:
107107
return uid.replace('.','__')
108108

109109
def instantiate_model(self, interface: str, sim_interface: SimInterface, interface_desc: Interface, ports: Dict[str, io.SimulationPort]) -> str:
110-
#TODO cache if this gets slow
111-
112110
uid = sim_interface['uid']
113111
parameters = sim_interface['parameters']
114112
if uid not in self._table:
@@ -127,6 +125,11 @@ def instantiate_model(self, interface: str, sim_interface: SimInterface, interfa
127125
params = [f"top.{cxxrtlmangle(n)}" for n in names]
128126

129127
out = f"{model.name} {interface}(\"{interface}\", "
128+
if len(parameters):
129+
cpp_params = []
130+
for p,v in parameters.items():
131+
cpp_params.append(f"{p} = {v}")
132+
out += '{' + ', '.join(cpp_params) + '}, '
130133
out += ', '.join(list(params))
131134
out += ')\n'
132135
return out

0 commit comments

Comments
 (0)