-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathring-oscillator-01.xml
More file actions
199 lines (149 loc) · 5.22 KB
/
ring-oscillator-01.xml
File metadata and controls
199 lines (149 loc) · 5.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?xml version="1.0"?>
<Graphs xmlns="https://poets-project.org/schemas/virtual-graph-schema-v2">
<GraphType id="ro">
<Documentation>Ring Oscillator</Documentation>
<MetaData>"native_dimension":2</MetaData>
<Properties/>
<SharedCode>
<![CDATA[
#define SOFTWARE_BUFF_SIZE 1024
// (Queue) send functions
// Note: buffer pointers point to the next available slot
struct toggle_msg {
uint32_t src;
uint32_t dst;
};
void send_toggle(ro_node_state_t *deviceState, toggle_msg *msg) {
uint32_t ind = (deviceState->toggle_buffer_ptr)++;
if (ind >= SOFTWARE_BUFF_SIZE ) {
handler_log(1, "Error, outgoing toggle message buffer is full");
handler_exit(1);
}
deviceState->toggle_buffer_dst[ind] = msg->dst;
}
]]>
</SharedCode>
<MessageTypes>
<MessageType id="__init__">
<Documentation>Initialize state</Documentation>
</MessageType>
<MessageType id="toggle">
<Documentation>Toggle next node</Documentation>
<Message>
<Scalar type="uint32_t" name="src">
<Documentation>Source node id</Documentation>
</Scalar>
<Scalar type="uint32_t" name="dst">
<Documentation>Destination node id</Documentation>
</Scalar>
</Message>
</MessageType>
</MessageTypes>
<DeviceTypes>
<!-- Generated Block -->
<DeviceType id="node">
<Properties>
<Scalar name="id" type="uint32_t"></Scalar>
<Scalar name="outdegree" type="uint32_t"></Scalar>
</Properties>
<State>
<!-- Device state fields: -->
<Scalar name="state" type="uint32_t"></Scalar>
<Scalar name="counter" type="uint32_t"></Scalar>
<!-- Software buffer for (outgoing) toggle messages: -->
<Array name="toggle_buffer_dst" type="uint32_t" length="1024"></Array>
<Scalar name="toggle_buffer_ptr" type="uint32_t"></Scalar>
</State>
<ReadyToSend>
<![CDATA[
bool pending_toggle_messages = deviceState->toggle_buffer_ptr > 0;
*readyToSend =
(pending_toggle_messages ? RTS_FLAG_toggle_out : 0);
]]>
</ReadyToSend>
<InputPin messageTypeId="__init__" name="__init__">
<OnReceive>
<![CDATA[
bool is_root = deviceProperties->id == 0;
deviceState->state = is_root ? 1 : 0;
deviceState->counter = 0;
if (is_root) {
handler_log(1, "counter = %d", ++(deviceState->counter));
// send initial message
toggle_msg outgoing;
outgoing.dst = 0xFFFFFFFF; // broadcast
send_toggle(deviceState, &outgoing);
}
]]>
</OnReceive>
</InputPin>
<InputPin messageTypeId="toggle" name="toggle_in">
<OnReceive>
<![CDATA[
bool finished = deviceState->counter >= 10;
if (finished) {
handler_exit(0);
} else {
handler_log(1, "counter = %d", ++(deviceState->counter));
// toggle state:
deviceState->state = 1 - deviceState->state;
// send message to next node:
toggle_msg outgoing;
outgoing.dst = 0xFFFFFFFF; // broadcast
send_toggle(deviceState, &outgoing);
}
]]>
</OnReceive>
</InputPin>
<OutputPin messageTypeId="toggle" name="toggle_out">
<OnSend>
<![CDATA[
if (deviceState->toggle_buffer_ptr == 0) {
// If this is executed, it is most likely due to an error in ready_to_send
handler_log(1, "Error, attempted to send while buffer is empty");
handler_exit(1);
}
uint32_t ind = --(deviceState->toggle_buffer_ptr);
message->src = deviceProperties->id;
message->dst = deviceState->toggle_buffer_dst[ind];
]]>
</OnSend>
</OutputPin>
</DeviceType>
</DeviceTypes>
</GraphType>
<GraphInstance id="graph1" graphTypeId="ro">
<DeviceInstances>
<DevI id="n0" type="node">
<P>
"id": 0,
"outdegree": 1
</P>
</DevI>
<DevI id="n1" type="node">
<P>
"id": 1,
"outdegree": 1
</P>
</DevI>
<DevI id="n2" type="node">
<P>
"id": 2,
"outdegree": 1
</P>
</DevI>
<DevI id="n3" type="node">
<P>
"id": 3,
"outdegree": 1
</P>
</DevI>
</DeviceInstances>
<EdgeInstances>
<EdgeI path="n1:toggle_in-n0:toggle_out"/>
<EdgeI path="n2:toggle_in-n1:toggle_out"/>
<EdgeI path="n3:toggle_in-n2:toggle_out"/>
<EdgeI path="n0:toggle_in-n3:toggle_out"/>
</EdgeInstances>
</GraphInstance>
</Graphs>