-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_circle.v
More file actions
144 lines (116 loc) · 2.82 KB
/
Copy pathplot_circle.v
File metadata and controls
144 lines (116 loc) · 2.82 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
module plot_circle
(
input clk,
input reset,
// custom instruction (ended up not being used!)
input start,
input[31:0] A,
input[31:0] B,
output[31:0] result,
output done,
// mem mapped slave
// read
input read,
input [17:0]address ,
output[31:0] readdata,
output waitrequest,
output readdatavalid,
// write
input write,
input[31:0] writedata
);
reg[511:0] pixmem [511:0];
reg[511:0] _pixmem [511:0];
//wire[511:0] _pixword;
wire[8:0] addrx = address[8:0];
wire[8:0] addry = address[17:9];
wire[9:0] y = A[9:0];
wire[9:0] x = A[19:10];
wire[9:0] cy = A[29:20];
wire[9:0] cx = {B[7:0],A[31:30]};
reg[8:0] sum_cx_x;
reg[8:0] sum_cy_y;
reg[8:0] diff_cy_y;
reg[8:0] diff_cx_x;
reg[8:0] sum_cx_y;
reg[8:0] sum_cy_x;
reg[8:0] diff_cy_x;
reg[8:0] diff_cx_y;
reg writebit;
// mem mapped read
assign waitrequest = 1'b0;
assign readdata = (read) ? ({31'h0, pixmem[addrx][addry]}) : (32'h0);
assign readdatavalid = read ? 1'b1 : 1'b0;
integer i = 0;
assign done = 1'b1;
// internal memory
always@(posedge clk, posedge reset)
begin
if (reset)
begin
for(i=0; i<512; i=i+1)
begin
pixmem[i] <= 512'h0;
end
end
else
begin
for(i=0; i<512; i=i+1)
begin
pixmem[i] <= _pixmem[i];
end
end
end
// custom instruction
always@*
begin
done = 1'b0;
for(i=0; i<512; i=i+1)
begin
_pixmem[i] = pixmem[i];
end
// todo complete
if (write)
begin
sum_cx_x = addrx;
sum_cx_y = addrx;
diff_cx_x = addrx;
diff_cx_y = addrx;
sum_cy_y = addry;
sum_cy_x = addry;
diff_cy_y = addry;
diff_cy_x = addry;
writebit = writedata[0];
end
else
begin
sum_cx_x = cx[8:0] + x[8:0];
sum_cy_y = cy[8:0] + y[8:0];
diff_cy_y = cy[8:0] - y[8:0];
diff_cx_x = cx[8:0] - x[8:0];
sum_cx_y = cx[8:0] + y[8:0];
sum_cy_x = cy[8:0] + x[8:0];
diff_cy_x = cy[8:0] - x[8:0];
diff_cx_y = cx[8:0] - y[8:0];
writebit = 1'b1;
end
// Note this is incorrect because it's describing an 8 port memory.
// This is tough to synthesis. I changed this later on to a 2 port memory
// which is an Altera built in memory and will synthesis easily.
if (start)
begin
_pixmem[sum_cx_x][sum_cy_y] = writebit;
_pixmem[sum_cx_x][diff_cy_y] = writebit;
_pixmem[diff_cx_x][sum_cy_y] = writebit;
_pixmem[diff_cx_x][diff_cy_y] = writebit;
_pixmem[sum_cx_y][sum_cy_x] = writebit;
_pixmem[sum_cx_y][diff_cy_x] = writebit;
_pixmem[diff_cx_y][sum_cy_x] = writebit;
_pixmem[diff_cx_y][diff_cy_x] = writebit;
end
else
begin
end
done = 1'b1;
end
endmodule