Skip to content

Commit 7c5bc79

Browse files
authored
Merge pull request #163 from yrabbit/gw1ns-2-1
stage2. Add PLL support for GW1NS-2 chips
2 parents 8405842 + be4af17 commit 7c5bc79

File tree

4 files changed

+43
-9
lines changed

4 files changed

+43
-9
lines changed

apycula/chipdb.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ def fse_pll(device, fse, ttyp):
182182
bel = bels.setdefault('RPLLA', Bel())
183183
elif ttyp == 89:
184184
bel = bels.setdefault('RPLLB', Bel())
185+
elif device in {'GW1NS-2'}:
186+
if ttyp in {87}:
187+
bel = bels.setdefault('RPLLA', Bel())
185188
elif device in {'GW1NS-4'}:
186189
if ttyp in {88, 89}:
187190
bel = bels.setdefault('PLLVR', Bel())
@@ -453,6 +456,9 @@ def fse_fill_logic_tables(dev, fse):
453456
'GW1NZ-1':
454457
{'TRPLL0CLK0': (0, 17, 'F4'), 'TRPLL0CLK1': (0, 17, 'F5'),
455458
'TRPLL0CLK2': (0, 17, 'F6'), 'TRPLL0CLK3': (0, 17, 'F7'), },
459+
'GW1NS-2':
460+
{'TRPLL0CLK0': (5, 19, 'F4'), 'TRPLL0CLK1': (5, 19, 'F7'),
461+
'TRPLL0CLK2': (5, 19, 'F5'), 'TRPLL0CLK3': (5, 19, 'F6'), },
456462
'GW1N-4':
457463
{'TLPLL0CLK0': (0, 9, 'F4'), 'TLPLL0CLK1': (0, 9, 'F7'),
458464
'TLPLL0CLK2': (0, 9, 'F6'), 'TLPLL0CLK3': (0, 9, 'F5'),
@@ -482,7 +488,7 @@ def fse_create_pll_clock_aliases(db, device):
482488
for w_dst, w_srcs in db.grid[row][col].clock_pips.items():
483489
for w_src in w_srcs.keys():
484490
# XXX
485-
if device in {'GW1N-1', 'GW1NZ-1', 'GW1NS-4', 'GW1N-4', 'GW1N-9C', 'GW1N-9'}:
491+
if device in {'GW1N-1', 'GW1NZ-1', 'GW1NS-2', 'GW1NS-4', 'GW1N-4', 'GW1N-9C', 'GW1N-9'}:
486492
if w_src in _pll_loc[device].keys():
487493
db.aliases[(row, col, w_src)] = _pll_loc[device][w_src]
488494

@@ -692,7 +698,14 @@ def dat_portmap(dat, dev, device):
692698
for idx, nam in _pll_inputs:
693699
wire = wirenames[dat['PllIn'][idx]]
694700
off = dat['PllInDlt'][idx] * offx
695-
if off == 0:
701+
if device in {'GW1NS-2'}:
702+
# NS-2 is a strange thingy
703+
if nam in {'RESET', 'RESET_P', 'IDSEL1', 'IDSEL2', 'ODSEL5'}:
704+
bel.portmap[nam] = f'rPLL{nam}{wire}'
705+
dev.aliases[row, col, f'rPLL{nam}{wire}'] = (9, col, wire)
706+
else:
707+
bel.portmap[nam] = wire
708+
elif off == 0:
696709
bel.portmap[nam] = wire
697710
else:
698711
# not our cell, make an alias
@@ -701,7 +714,7 @@ def dat_portmap(dat, dev, device):
701714
for idx, nam in _pll_outputs:
702715
wire = wirenames[dat['PllOut'][idx]]
703716
off = dat['PllOutDlt'][idx] * offx
704-
if off == 0:
717+
if off == 0 or device in {'GW1NS-2'}:
705718
bel.portmap[nam] = wire
706719
else:
707720
# not our cell, make an alias

examples/Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ all: attosoc-tec0117.fs nanolcd-tangnano.fs blinky-tec0117.fs blinky-runber.fs \
1919
pll-52-tangnano.fs pll-80-tangnano.fs \
2020
pll-54-tangnano1k.fs pll-81-tangnano1k.fs \
2121
pll-dyn-tangnano.fs pll-dyn-tangnano1k.fs \
22-
pll-tangnano4k.fs pll2-tangnano9k.fs pll2-tec0117.fs pll2-runber.fs \
22+
pll-tangnano4k.fs pll2-tangnano9k.fs pll2-tec0117.fs pll2-runber.fs pll-dyn-honeycomb.fs \
2323
pll-nanolcd-tangnano.fs pll-nanolcd-tangnano9k.fs
2424

2525
unpacked: attosoc-tec0117-unpacked.v nanolcd-tangnano-unpacked.v blinky-tec0117-unpacked.v blinky-runber-unpacked.v \
@@ -39,7 +39,7 @@ unpacked: attosoc-tec0117-unpacked.v nanolcd-tangnano-unpacked.v blinky-tec0117-
3939
pll-52-tangnano-unpacked.v pll-80-tangnano-unpacked.v \
4040
pll-54-tangnano1k-unpacked.v pll-81-tangnano1k-unpacked.v \
4141
pll-dyn-tangnano-unpacked.v pll-dyn-tangnano1k-unpacked.v \
42-
pll2-tangnano9k-unpacked.v pll2-tec0117-unpacked.v pll2-runber-unpacked.v \
42+
pll2-tangnano9k-unpacked.v pll2-tec0117-unpacked.v pll2-runber-unpacked.v pll-dyn-honeycomb-unpacked.v \
4343
pll-nanolcd-tangnano-unpacked.v pll-nanolcd-tangnano9k-unpacked.v pll-tangnano4k-unpacked.v
4444

4545
clean:
@@ -96,7 +96,7 @@ pll-nanolcd-tangnano9k.fs: pll-nanolcd-tangnano9k.json
9696
gowin_pack -d GW1NS-2 -o $@ $<
9797

9898
%-honeycomb.json: %-honeycomb-synth.json honeycomb.cst
99-
$(NEXTPNR) --json $< --write $@ --device GW1NS-UX2CQN48C5/I4 --cst honeycomb.cst
99+
$(NEXTPNR) -v --debug --json $< --write $@ --device GW1NS-UX2CQN48C5/I4 --cst honeycomb.cst
100100

101101
attosoc-tec0117-synth.json: attosoc/attosoc.v attosoc/picorv32.v
102102
$(YOSYS) -p "read_verilog $^; synth_gowin -json $@"
@@ -155,6 +155,9 @@ pll-tangnano4k-synth.json: pll-tangnano4k.v pll/pllvr.v
155155
%-tangnano9k-synth.json: %.v
156156
$(YOSYS) -D LEDS_NR=6 -D OSC_TYPE_OSC -p "read_verilog $^; synth_gowin -json $@"
157157

158+
pll-%-honeycomb-synth.json: pll/GW1NS-2C-%.vh pll.v pll/rpll.v
159+
$(YOSYS) -D LEDS_NR=3 -D OSC_TYPE_OSCF -p "read_verilog $^; synth_gowin -json $@"
160+
158161
%-honeycomb-synth.json: %.v
159162
$(YOSYS) -D LEDS_NR=3 -D OSC_TYPE_OSCF -p "read_verilog $^; synth_gowin -json $@"
160163

examples/pll.v

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
`default_nettype none
2-
module top(input wire clk, input wire key, output wire [`LEDS_NR-1:0]led);
2+
`ifndef KEY
3+
`define KEY key
4+
`endif
5+
module top(input wire clk, input wire KEY, output wire [`LEDS_NR-1:0]led);
36
wire VCC;
47
wire GND;
58
assign VCC = 1'b1;
@@ -44,7 +47,7 @@ module top(input wire clk, input wire key, output wire [`LEDS_NR-1:0]led);
4447
// dynamic
4548
`ifdef PLL_DYN
4649
always @ (posedge clk) begin
47-
if (key) begin
50+
if (KEY) begin
4851
fdiv <= ~`PLL_FBDIV_SEL;
4952
idiv <= ~`PLL_IDIV_SEL;
5053
end else begin
@@ -54,7 +57,7 @@ module top(input wire clk, input wire key, output wire [`LEDS_NR-1:0]led);
5457
end
5558
`else
5659
always @ (posedge clk) begin
57-
reset = ~key;
60+
reset = ~KEY;
5861
end
5962
`endif
6063
endmodule

examples/pll/GW1NS-2C-dyn.vh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
`define PLL_DYN
2+
`define PLL_DEVICE "GW1NS-2C"
3+
`define PLL_FCLKIN "24"
4+
`define PLL_ODIV_SEL 8
5+
6+
`define PLL_FBDIV_SEL 12
7+
`define PLL_IDIV_SEL 5
8+
9+
`define PLL_FBDIV_SEL_1 9
10+
`define PLL_IDIV_SEL_1 2
11+
12+
`define PLL_FBDIV_SEL_LCD 29
13+
`define PLL_IDIV_SEL_LCD 7
14+
15+
`define KEY rst

0 commit comments

Comments
 (0)