-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathppi.v
More file actions
401 lines (312 loc) · 7.46 KB
/
ppi.v
File metadata and controls
401 lines (312 loc) · 7.46 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
module ppi (wrb, rdb, cs, reset, a0, a1, data, portA, portB, portC);
// declaration of PPI inputs and outputs
input wrb, rdb, cs, reset, a0, a1;
inout [7:0] data, portA, portB, portC;
// declaration of internals of the ppi
// 1) Control Word Register
reg [7:0] cwr;
// 2) address bus
wire [1:0] address;
assign address = {a1,a0};
// 3) reset
wire int_reset;
assign int_reset = reset | ~cwr[7] | (~wrb & (address == 2'b11));
// 4) latching of data and ports
reg [7:0] latch_data, latch_portA, latch_portB, latch_portC;
// 5) tri-state output bus for data and ports
reg [7:0] out_data, out_portA, out_portB, out_portC;
assign data = out_data;
assign portA = out_portA;
assign portB = out_portB;
assign portC = out_portC;
// 6) ports enable for output
reg enable_portA, enable_portB, enable_upper_portC, enable_lower_portC;
// 7) groups control for mode 0
reg groupA_mode0, groupB_mode0;
// different modes of operations
// 1] mode 0 i/o
always @(posedge reset or negedge wrb)
begin
if (reset)
begin
/* if reset .. CWR is set to active mode 0 with all
ports as input */
cwr <= 8'b10011011;
end
else
// data is written to the control word register
begin
if (address == 2'b11)
cwr <= data;
end
end
always @ (posedge int_reset or negedge wrb)
// if falling edge of wrb is detected data is latched
begin
if (int_reset)
latch_data <= 8'h00;
else
latch_data <= data;
end
always @(posedge int_reset or negedge rdb)
//if falling edge or rb is detected ports are latched
begin
if (int_reset)
begin
latch_portA <= 8'h00;
latch_portB <= 8'h00;
latch_portC <= 8'h00;
end
else
begin
latch_portA <= portA;
latch_portB <= portB;
latch_portC <= portC;
end
end
always @(int_reset or cwr)
// enabling or disabling ports as output upon control word register
begin
if (int_reset)
begin
enable_portA = 0;
enable_portB = 0;
enable_upper_portC = 0;
enable_lower_portC = 0;
end
else
begin
if (cwr[7]==1)
//check if active flag for mode 0 operations
begin
if (cwr[6:5]==2'b00)
//check if group A mode is mode 0
begin
groupA_mode0 = 1;
//enabling port A
if (~cwr[4])
enable_portA = 1;
else enable_portA = 0;
//enabling port C upper
if (~cwr[3])
enable_upper_portC = 1;
else enable_upper_portC = 0;
end
if (cwr[2]==0)
//check if group B mode is mode 0
begin
groupB_mode0 = 1;
//enabling port B
if (~cwr[1])
enable_portB = 1;
else enable_portB = 0;
//enabling port C lower
if (~cwr[0])
enable_lower_portC = 1;
else enable_lower_portC = 0;
end
end
end
end
//driving of out_data when reading in mode 0
always @(int_reset or rdb or cwr or address
or latch_portA or enable_portA or groupA_mode0 or
latch_portB or enable_portB or groupB_mode0 or
latch_portC or enable_upper_portC or enable_lower_portC)
begin
if (int_reset)
out_data = 8'hzz;
//if port A is addressed and input
else if (~rdb & groupA_mode0 & ~enable_portA & (address==2'b00))
out_data = latch_portA;
//if port B is addressed and input
else if (~rdb & groupB_mode0 & ~enable_portB & (address==2'b01))
out_data = latch_portB;
//if port C is addressed and input
else if (~rdb & groupA_mode0 & groupB_mode0 & ~enable_upper_portC &
~enable_lower_portC & (address==2'b10))
out_data = latch_portC;
//if port C is addressed and upper pins are input
else if (~rdb & groupA_mode0 & ~enable_upper_portC & (address==2'b10))
out_data = {latch_portC[7:4],4'hz};
//if port C is addressed and lower pins are input
else if (~rdb & groupB_mode0 & ~enable_lower_portC & (address==2'b10))
out_data = {4'hz,latch_portC[3:0]};
else out_data = 8'hzz;
end
//writing to ports in mode 0
always @ (int_reset or wrb or address or cwr or
latch_data or enable_portA or enable_portB or enable_upper_portC
or enable_lower_portC or groupA_mode0 or groupB_mode0)
begin
if (int_reset)
begin
//BSR functionality
if (~cwr[7])
out_portC[cwr[3:1]] <= cwr[0];
else
begin
out_portA <= 8'hzz;
out_portB <= 8'hzz;
out_portC <= 8'hzz;
end
end
//if port A is addressed and output
else if (~wrb & groupA_mode0 & enable_portA & (address == 2'b00))
out_portA <=latch_data;
//if port B is addressed and output
else if (~wrb & groupB_mode0 & enable_portB & (address == 2'b01))
out_portB<= latch_data;
//if port C is addressed and output
else if (~wrb & groupA_mode0 & groupB_mode0 &
enable_upper_portC & enable_lower_portC & (address == 2'b10))
out_portC<= latch_data;
//if port C is addressed and upper pins are output
else if (~wrb & groupA_mode0 & enable_upper_portC & (address == 2'b10))
out_portC<= {latch_data[7:4],4'hz};
//if port C is addressed and lower pins are output
else if (~wrb & groupB_mode0 & enable_lower_portC & (address == 2'b10))
out_portC<= {4'hz, latch_data[3:0]};
else
begin
out_portA <= 8'hzz;
out_portB <= 8'hzz;
out_portC <= 8'hzz;
end
end
endmodule
// the test bench module
module ppi_testbench1();
wire[7:0] pA, pB, pC, D;
wire a1,a0;
reg rdb, wrb, rst, cs;
reg [7:0] drive_pA, drive_pB, drive_pC, drive_D, temp_D;
parameter cycle = 50;
assign pA = drive_pA;
assign pB = drive_pB;
assign pC = drive_pC;
assign D = drive_D;
reg [1:0] address;
assign a1 = address [1];
assign a0 = address [0];
initial
begin
// for reset
drive_pA = 8'hzz;
drive_pB = 8'hzz;
drive_pC = 8'hzz;
rdb = 1;
wrb = 1;
cs=0;
address = 0;
drive_D = 8'hzz;
rst = 0;
#cycle;
$monitor("portC - %b", pC);
task_reset;
// testing for mode 0 with all portA, portB,
// portCU, portCL
// input
temp_D = 8'b10011011;
CWR_write(temp_D);
drive_D = 8'hzz;
// read from portA
address = 0;
drive_pA = 8'ha5;
read_port;
drive_pA = 8'hzz;
// read portB
address = 1;
drive_pB = 8'h35;
read_port;
drive_pB = 8'hzz;
// read portC
address = 2;
drive_pC = 8'h98;
read_port;
drive_pC = 8'hzz;
// change portA to output
temp_D = 8'b10001011;
CWR_write(temp_D);
drive_D = 8'hzz;
// write to portA
address = 0;
drive_D = 8'hbc;
write_port;
drive_D = 8'hzz;
// change portB to output
temp_D = 8'b10001001;
CWR_write(temp_D);
drive_D = 8'hzz;
// write to portB
address = 1;
drive_D = 8'h67;
write_port;
drive_D = 8'hzz;
// change portC to output
temp_D = 8'b10000000;
CWR_write(temp_D);
drive_D = 8'hzz;
// write to portC
address = 2;
drive_D = 8'h32;
write_port;
drive_D = 8'hzz;
// bit set-reset of port C
//reset bit 1 of port C
temp_D = 8'b00000010;
CWR_write(temp_D);
end
task write_port;
begin
wrb = 1;
rdb = 1;
#cycle;
wrb = 0;
#cycle;
wrb = 1;
#cycle;
end
endtask
task read_port;
begin
wrb = 1;
rdb = 1;
#cycle;
rdb = 0;
#cycle;
rdb = 1;
#cycle;
end
endtask
task CWR_write;
input [7:0] temp_D;
begin
rst = 0;
address = 2'b11;
rdb = 1;
wrb = 1;
#cycle;
drive_D = temp_D;
wrb = 0;
#cycle;
wrb = 1;
#cycle;
end
endtask
task task_reset;
begin
rst = 0;
#cycle;
rst = 1;
#cycle;
rst = 0;
#cycle;
end
endtask
ppi ppi_instance (.portA(pA), .portB(pB),
.portC(pC), .rdb(rdb),
.wrb(wrb), .a1(a1), .a0(a0),
.reset(rst),
.data(D), .cs(cs));
endmodule