Skip to content

Commit 22339ba

Browse files
committed
hello_led.py is updated
1 parent a720632 commit 22339ba

File tree

4 files changed

+75
-166
lines changed

4 files changed

+75
-166
lines changed

README.md

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -140,34 +140,24 @@ def mkLed():
140140
width = m.Parameter('WIDTH', 8)
141141
clk = m.Input('CLK')
142142
rst = m.Input('RST')
143-
led = m.OutputReg('LED', width)
144-
count = m.Reg('count', 32)
145-
146-
m.Always(Posedge(clk))(
147-
If(rst)(
148-
count(0)
149-
).Else(
150-
If(count == 1023)(
151-
count(0)
152-
).Else(
153-
count(count + 1)
154-
)
155-
))
156-
157-
m.Always(Posedge(clk))(
158-
If(rst)(
159-
led(0)
160-
).Else(
161-
If(count == 1024 - 1)(
162-
led(led + 1)
163-
)
164-
))
165-
166-
m.Always(Posedge(clk))(
167-
If(rst)(
168-
).Else(
169-
Systask('display', "LED:%d count:%d", led, count)
170-
))
143+
led = m.OutputReg('LED', width, initval=0)
144+
count = m.Reg('count', 32, initval=0)
145+
146+
seq = Seq(m, 'seq', clk, rst)
147+
148+
seq.If(count == 1024 - 1)(
149+
count(0)
150+
).Else(
151+
count.inc()
152+
)
153+
154+
seq.If(count == 1024 - 1)(
155+
led.inc()
156+
)
157+
158+
seq(
159+
Systask('display', "LED:%d count:%d", led, count)
160+
)
171161

172162
return m
173163

@@ -283,30 +273,16 @@ module blinkled #
283273
always @(posedge CLK) begin
284274
if(RST) begin
285275
count <= 0;
276+
LED <= 0;
286277
end else begin
287278
if(count == 1023) begin
288279
count <= 0;
289280
end else begin
290281
count <= count + 1;
291282
end
292-
end
293-
end
294-
295-
296-
always @(posedge CLK) begin
297-
if(RST) begin
298-
LED <= 0;
299-
end else begin
300283
if(count == 1023) begin
301284
LED <= LED + 1;
302285
end
303-
end
304-
end
305-
306-
307-
always @(posedge CLK) begin
308-
if(RST) begin
309-
end else begin
310286
$display("LED:%d count:%d", LED, count);
311287
end
312288
end

README.rst

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -162,34 +162,24 @@ Python as below. A blinking LED hardware is modeled in Python. Open
162162
width = m.Parameter('WIDTH', 8)
163163
clk = m.Input('CLK')
164164
rst = m.Input('RST')
165-
led = m.OutputReg('LED', width)
166-
count = m.Reg('count', 32)
167-
168-
m.Always(Posedge(clk))(
169-
If(rst)(
170-
count(0)
171-
).Else(
172-
If(count == 1023)(
173-
count(0)
174-
).Else(
175-
count(count + 1)
176-
)
177-
))
178-
179-
m.Always(Posedge(clk))(
180-
If(rst)(
181-
led(0)
182-
).Else(
183-
If(count == 1024 - 1)(
184-
led(led + 1)
185-
)
186-
))
187-
188-
m.Always(Posedge(clk))(
189-
If(rst)(
190-
).Else(
191-
Systask('display', "LED:%d count:%d", led, count)
192-
))
165+
led = m.OutputReg('LED', width, initval=0)
166+
count = m.Reg('count', 32, initval=0)
167+
168+
seq = Seq(m, 'seq', clk, rst)
169+
170+
seq.If(count == 1024 - 1)(
171+
count(0)
172+
).Else(
173+
count.inc()
174+
)
175+
176+
seq.If(count == 1024 - 1)(
177+
led.inc()
178+
)
179+
180+
seq(
181+
Systask('display', "LED:%d count:%d", led, count)
182+
)
193183
194184
return m
195185
@@ -306,30 +296,16 @@ which is generated by the source code generator.
306296
always @(posedge CLK) begin
307297
if(RST) begin
308298
count <= 0;
299+
LED <= 0;
309300
end else begin
310301
if(count == 1023) begin
311302
count <= 0;
312303
end else begin
313304
count <= count + 1;
314305
end
315-
end
316-
end
317-
318-
319-
always @(posedge CLK) begin
320-
if(RST) begin
321-
LED <= 0;
322-
end else begin
323306
if(count == 1023) begin
324307
LED <= LED + 1;
325308
end
326-
end
327-
end
328-
329-
330-
always @(posedge CLK) begin
331-
if(RST) begin
332-
end else begin
333309
$display("LED:%d count:%d", LED, count);
334310
end
335311
end

hello_led.ipynb

Lines changed: 19 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,25 @@
2828
" width = m.Parameter('WIDTH', 8)\n",
2929
" clk = m.Input('CLK')\n",
3030
" rst = m.Input('RST')\n",
31-
" led = m.OutputReg('LED', width)\n",
32-
" count = m.Reg('count', 32)\n",
31+
" led = m.OutputReg('LED', width, initval=0)\n",
32+
" count = m.Reg('count', 32, initval=0)\n",
33+
"\n",
34+
" seq = Seq(m, 'seq', clk, rst)\n",
35+
"\n",
36+
" seq.If(count == 1024 - 1)(\n",
37+
" count(0)\n",
38+
" ).Else(\n",
39+
" count.inc()\n",
40+
" )\n",
41+
"\n",
42+
" seq.If(count == 1024 - 1)(\n",
43+
" led.inc()\n",
44+
" )\n",
45+
"\n",
46+
" seq(\n",
47+
" Systask('display', \"LED:%d count:%d\", led, count)\n",
48+
" )\n",
3349
"\n",
34-
" m.Always(Posedge(clk))(\n",
35-
" If(rst)(\n",
36-
" count(0)\n",
37-
" ).Else(\n",
38-
" If(count == 1023)(\n",
39-
" count(0)\n",
40-
" ).Else(\n",
41-
" count(count + 1)\n",
42-
" )\n",
43-
" ))\n",
44-
" \n",
45-
" m.Always(Posedge(clk))(\n",
46-
" If(rst)(\n",
47-
" led(0)\n",
48-
" ).Else(\n",
49-
" If(count == 1024 - 1)(\n",
50-
" led(led + 1)\n",
51-
" )\n",
52-
" ))\n",
53-
" \n",
54-
" m.Always(Posedge(clk))(\n",
55-
" If(rst)(\n",
56-
" ).Else(\n",
57-
" Systask('display', \"LED:%d count:%d\", led, count)\n",
58-
" ))\n",
59-
" \n",
6050
" return m"
6151
]
6252
},
@@ -171,30 +161,16 @@
171161
" always @(posedge CLK) begin\n",
172162
" if(RST) begin\n",
173163
" count <= 0;\n",
164+
" LED <= 0;\n",
174165
" end else begin\n",
175166
" if(count == 1023) begin\n",
176167
" count <= 0;\n",
177168
" end else begin\n",
178169
" count <= count + 1;\n",
179170
" end\n",
180-
" end\n",
181-
" end\n",
182-
"\n",
183-
"\n",
184-
" always @(posedge CLK) begin\n",
185-
" if(RST) begin\n",
186-
" LED <= 0;\n",
187-
" end else begin\n",
188171
" if(count == 1023) begin\n",
189172
" LED <= LED + 1;\n",
190173
" end \n",
191-
" end\n",
192-
" end\n",
193-
"\n",
194-
"\n",
195-
" always @(posedge CLK) begin\n",
196-
" if(RST) begin\n",
197-
" end else begin\n",
198174
" $display(\"LED:%d count:%d\", LED, count);\n",
199175
" end\n",
200176
" end\n",
@@ -10231,15 +10207,6 @@
1023110207
"\n",
1023210208
" # sim.view_waveform()"
1023310209
]
10234-
},
10235-
{
10236-
"cell_type": "code",
10237-
"execution_count": null,
10238-
"metadata": {
10239-
"collapsed": true
10240-
},
10241-
"outputs": [],
10242-
"source": []
1024310210
}
1024410211
],
1024510212
"metadata": {

hello_led.py

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,24 @@ def mkLed():
1010
width = m.Parameter('WIDTH', 8)
1111
clk = m.Input('CLK')
1212
rst = m.Input('RST')
13-
led = m.OutputReg('LED', width)
14-
count = m.Reg('count', 32)
15-
16-
m.Always(Posedge(clk))(
17-
If(rst)(
18-
count(0)
19-
).Else(
20-
If(count == 1023)(
21-
count(0)
22-
).Else(
23-
count(count + 1)
24-
)
25-
))
26-
27-
m.Always(Posedge(clk))(
28-
If(rst)(
29-
led(0)
30-
).Else(
31-
If(count == 1024 - 1)(
32-
led(led + 1)
33-
)
34-
))
35-
36-
m.Always(Posedge(clk))(
37-
If(rst)(
38-
).Else(
39-
Systask('display', "LED:%d count:%d", led, count)
40-
))
13+
led = m.OutputReg('LED', width, initval=0)
14+
count = m.Reg('count', 32, initval=0)
15+
16+
seq = Seq(m, 'seq', clk, rst)
17+
18+
seq.If(count == 1024 - 1)(
19+
count(0)
20+
).Else(
21+
count.inc()
22+
)
23+
24+
seq.If(count == 1024 - 1)(
25+
led.inc()
26+
)
27+
28+
seq(
29+
Systask('display', "LED:%d count:%d", led, count)
30+
)
4131

4232
return m
4333

0 commit comments

Comments
 (0)