Skip to content

Commit f234c63

Browse files
Godziltrapierm
authored andcommitted
First Commit
1 parent f33130c commit f234c63

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+76850
-0
lines changed

board/gameduino.brd

61 KB
Binary file not shown.

board/gameduino.sch

147 KB
Binary file not shown.

doc/Gameduino_Reference_Manual_v0.pdf

1.74 MB
Binary file not shown.

fpga/ck_div.v

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
module ck_div(
2+
input ck_in,
3+
output ck_out,
4+
input sys_rst_i
5+
//output locked;
6+
);
7+
parameter DIV_BY = 1;
8+
parameter MULT_BY = 1;
9+
10+
wire ck_fb;
11+
12+
//DCM #(
13+
// .CLKDV_DIVIDE(DIV_BY),
14+
// .DFS_FREQUENCY_MODE("LOW"), // HIGH or LOW frequency mode for frequency synthesis
15+
// .DUTY_CYCLE_CORRECTION("TRUE"), // Duty cycle correction, TRUE or FALSE
16+
// .STARTUP_WAIT("TRUE") // Delay configuration DONE until DCM LOCK, TRUE/FALSE
17+
//) DCM_inst (
18+
// .CLK0(ck_fb),
19+
// .CLKDV(ck_out),
20+
// .CLKFB(ck_fb), // DCM clock feedback
21+
// .CLKIN(ck_in), // Clock input (from IBUFG, BUFG or DCM)
22+
// .RST(0)
23+
//);
24+
25+
DCM #(
26+
.CLKFX_MULTIPLY(MULT_BY),
27+
.CLKFX_DIVIDE(DIV_BY),
28+
.DFS_FREQUENCY_MODE("LOW"), // HIGH or LOW frequency mode for frequency synthesis
29+
.DUTY_CYCLE_CORRECTION("TRUE"), // Duty cycle correction, TRUE or FALSE
30+
.STARTUP_WAIT("TRUE") // Delay configuration DONE until DCM LOCK, TRUE/FALSE
31+
) DCM_inst (
32+
.CLK0(ck_fb),
33+
.CLKFX(ck_out),
34+
.CLKFB(ck_fb), // DCM clock feedback
35+
.CLKIN(ck_in), // Clock input (from IBUFG, BUFG or DCM)
36+
.RST(0)
37+
);
38+
39+
//BUFG BUFG_inst(.I(ck_int), .O(ck_out));
40+
41+
endmodule

fpga/ck_div.vhd

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
module ck_div(
2+
input ck_in,
3+
output ck_out,
4+
input sys_rst_i
5+
//output locked;
6+
);
7+
parameter DIV_BY = 1;
8+
parameter MULT_BY = 1;
9+
10+
wire ck_fb;
11+
12+
//DCM #(
13+
// .CLKDV_DIVIDE(DIV_BY),
14+
// .DFS_FREQUENCY_MODE("LOW"), // HIGH or LOW frequency mode for frequency synthesis
15+
// .DUTY_CYCLE_CORRECTION("TRUE"), // Duty cycle correction, TRUE or FALSE
16+
// .STARTUP_WAIT("TRUE") // Delay configuration DONE until DCM LOCK, TRUE/FALSE
17+
//) DCM_inst (
18+
// .CLK0(ck_fb),
19+
// .CLKDV(ck_out),
20+
// .CLKFB(ck_fb), // DCM clock feedback
21+
// .CLKIN(ck_in), // Clock input (from IBUFG, BUFG or DCM)
22+
// .RST(0)
23+
//);
24+
25+
DCM #(
26+
.CLKFX_MULTIPLY(MULT_BY),
27+
.CLKFX_DIVIDE(DIV_BY),
28+
.DFS_FREQUENCY_MODE("LOW"), // HIGH or LOW frequency mode for frequency synthesis
29+
.DUTY_CYCLE_CORRECTION("TRUE"), // Duty cycle correction, TRUE or FALSE
30+
.STARTUP_WAIT("TRUE") // Delay configuration DONE until DCM LOCK, TRUE/FALSE
31+
) DCM_inst (
32+
.CLK0(ck_fb),
33+
.CLKFX(ck_out),
34+
.CLKFB(ck_fb), // DCM clock feedback
35+
.CLKIN(ck_in), // Clock input (from IBUFG, BUFG or DCM)
36+
.RST(0)
37+
);
38+
39+
//BUFG BUFG_inst(.I(ck_int), .O(ck_out));
40+
41+
endmodule

fpga/fifo.v

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module fifo ( clk, datain, wr, dataout, rd, fullness);
2+
parameter WIDTH = 1;
3+
4+
input clk;
5+
input [WIDTH-1:0] datain;
6+
input wr;
7+
output [WIDTH-1:0] dataout;
8+
input rd;
9+
output reg [4:0] fullness;
10+
11+
always @(posedge clk)
12+
begin
13+
fullness <= (fullness + wr - rd);
14+
end
15+
wire [3:0] readaddr = (fullness - 1);
16+
17+
genvar i;
18+
19+
generate
20+
for (i = 0; i < WIDTH; i=i+1) begin : srl16
21+
SRL16E fifo16(
22+
.CLK(clk),
23+
.CE(wr),
24+
.D(datain[i]),
25+
.A0(readaddr[0]),
26+
.A1(readaddr[1]),
27+
.A2(readaddr[2]),
28+
.A3(readaddr[3]),
29+
.Q(dataout[i]));
30+
end
31+
endgenerate
32+
33+
endmodule

fpga/generated.v

Lines changed: 1590 additions & 0 deletions
Large diffs are not rendered by default.

fpga/j0.v

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
// J0 is a stripped-down J1.
2+
// Major changes:
3+
// stacks are only 16 deep
4+
// program counter is only 7 bits (128 instructions)
5+
// DEPTH and LSHIFT instructions removed
6+
// multiply and swab instructions added
7+
8+
module j0(
9+
input sys_clk_i, input sys_rst_i,
10+
11+
output [6:0] insn_addr,
12+
input [15:0] insn,
13+
14+
output mem_rd,
15+
output mem_wr,
16+
output [15:0] mem_addr,
17+
output [15:0] mem_dout,
18+
input [15:0] mem_din,
19+
input pause
20+
);
21+
22+
wire [15:0] immediate = { 1'b0, insn[14:0] };
23+
24+
wire [15:0] ramrd;
25+
26+
reg [4:0] dsp; // Data stack pointer
27+
reg [4:0] _dsp;
28+
reg [15:0] st0; // Top of data stack
29+
reg [15:0] _st0;
30+
wire dstkW; // D stack write
31+
32+
reg [6:0] pc;
33+
reg [6:0] _pc;
34+
reg [4:0] rsp;
35+
reg [4:0] _rsp;
36+
reg rstkW; // R stack write
37+
reg [15:0] rstkD; // R stack write value
38+
39+
wire [6:0] pc_plus_1 = pc + 1;
40+
41+
// The D and R stacks
42+
reg [15:0] dstack[0:31];
43+
reg [15:0] rstack[0:31];
44+
45+
wire [15:0] st1 = dstack[dsp];
46+
wire [15:0] rst0 = rstack[rsp];
47+
48+
// st0sel is the ALU operation. For branch and call the operation
49+
// is T, for 0branch it is N. For ALU ops it is loaded from the instruction
50+
// field.
51+
reg [4:0] st0sel;
52+
always @*
53+
begin
54+
case (insn[14:13])
55+
2'b00: st0sel <= 0; // ubranch
56+
2'b10: st0sel <= 0; // call
57+
2'b01: st0sel <= 1; // 0branch
58+
2'b11: st0sel <= {insn[4], insn[11:8]}; // ALU
59+
default: st0sel <= 4'bxxxx;
60+
endcase
61+
62+
// Compute the new value of T.
63+
if (insn[15])
64+
_st0 <= immediate;
65+
else
66+
case (st0sel)
67+
5'b00000: _st0 <= st0;
68+
5'b00001: _st0 <= st1;
69+
5'b00010: _st0 <= st0 + st1;
70+
5'b00011: _st0 <= st0 & st1;
71+
5'b00100: _st0 <= st0 | st1;
72+
5'b00101: _st0 <= st0 ^ st1;
73+
5'b00110: _st0 <= ~st0;
74+
5'b00111: _st0 <= {16{(st1 == st0)}};
75+
5'b01000: _st0 <= {16{($signed(st1) < $signed(st0))}};
76+
5'b01001: _st0 <= st1 >> st0[3:0];
77+
5'b01010: _st0 <= st0 - 1;
78+
5'b01011: _st0 <= rst0;
79+
5'b01100: _st0 <= mem_din;
80+
5'b01101: _st0 <= st1 * st0;
81+
5'b01110: _st0 <= {st0[7:0], st0[15:8]};
82+
5'b01111: _st0 <= {16{(st1 < st0)}};
83+
default: _st0 <= 16'hxxxx;
84+
endcase
85+
end
86+
87+
wire is_alu = (insn[15:13] == 3'b011);
88+
wire is_lit = (insn[15]);
89+
90+
// assign mem_rd = (is_alu & (insn[11:8] == 4'hc));
91+
assign mem_rd = (st0sel == 5'hc);
92+
assign mem_wr = is_alu & insn[5];
93+
assign mem_addr = st0;
94+
assign mem_dout = st1;
95+
96+
assign dstkW = is_lit | (is_alu & insn[7]);
97+
98+
wire [1:0] dd = insn[1:0]; // D stack delta
99+
wire [1:0] rd = insn[3:2]; // R stack delta
100+
101+
always @*
102+
begin
103+
if (is_lit) begin // literal
104+
_dsp = dsp + 1;
105+
_rsp = rsp;
106+
rstkW = 0;
107+
rstkD = _pc;
108+
end else if (is_alu) begin // ALU
109+
_dsp = dsp + {dd[1], dd[1], dd[1], dd};
110+
_rsp = rsp + {rd[1], rd[1], rd[1], rd};
111+
rstkW = insn[6];
112+
rstkD = st0;
113+
end else begin // jump/call
114+
// predicated jump is like DROP
115+
if (insn[15:13] == 3'b001) begin
116+
_dsp = dsp - 1;
117+
end else begin
118+
_dsp = dsp;
119+
end
120+
if (insn[15:13] == 3'b010) begin // call
121+
_rsp = rsp + 1;
122+
rstkW = 1;
123+
rstkD = {pc_plus_1, 1'b0};
124+
end else begin
125+
_rsp = rsp;
126+
rstkW = 0;
127+
rstkD = _pc;
128+
end
129+
end
130+
131+
if (sys_rst_i)
132+
_pc = pc;
133+
else
134+
if ((insn[15:13] == 3'b000) |
135+
((insn[15:13] == 3'b001) & (|st0 == 0)) |
136+
(insn[15:13] == 3'b010))
137+
_pc = insn[6:0];
138+
else if (is_alu & insn[12])
139+
_pc = rst0[7:1];
140+
else
141+
_pc = pc_plus_1;
142+
end
143+
144+
assign insn_addr = pause ? pc : _pc;
145+
always @(posedge sys_clk_i)
146+
begin
147+
if (sys_rst_i) begin
148+
pc <= 0;
149+
dsp <= 0;
150+
st0 <= 0;
151+
rsp <= 0;
152+
end else if (!pause) begin
153+
pc <= _pc;
154+
dsp <= _dsp;
155+
st0 <= _st0;
156+
rsp <= _rsp;
157+
if (dstkW)
158+
dstack[_dsp] = st0;
159+
if (rstkW)
160+
rstack[_rsp] = rstkD;
161+
end
162+
end
163+
164+
endmodule // j1

fpga/revision.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`define REVISION 8'h11

fpga/testtop.v

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
module top(
3+
input SCK, // arduino 13
4+
input MOSI, // arduino 11
5+
inout MISO, // arduino 12
6+
input SSEL, // arduino 9
7+
8+
output flashMOSI,
9+
input flashMISO,
10+
output flashSCK,
11+
output flashSSEL
12+
13+
);
14+
15+
assign flashMOSI = MOSI;
16+
assign MISO = flashMISO;
17+
assign flashSCK = SCK;
18+
assign flashSSEL = SSEL;
19+
20+
endmodule // top

0 commit comments

Comments
 (0)