-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexternal_device.v
68 lines (57 loc) · 2.05 KB
/
external_device.v
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
/*************************************************
* external_device module (external_device.v)
* input: data (offset) to read from the device
* output: interrupt to request data write to the CPU
* data that will be written to the memory
* You should NOT change the name of the I/O ports and the module name.
*************************************************/
`define WORD_SIZE 16
`define DATA_SIZE 3
`define DEVICE_BIT_LEN 2
`define FIRE_TIME 89600 // steal: 89600, default: 2600
`define INTTERRUPT_DURATION 100
module external_device(
input wire [`DEVICE_BIT_LEN - 1 :0] offset,
output reg interrupt,
output reg [4 * `WORD_SIZE - 1 : 0] data);
reg [4 * `WORD_SIZE - 1 : 0] storage [`DATA_SIZE - 1 : 0];
initial begin
/* Randomized storage initialization.
* You may want to change these for the
* debugging */
storage[0] <= $random;
storage[1] <= $random;
storage[2] <= $random;
// storage[0] <= 'hC2C2C2C2C2C2;
// storage[1] <= 'hC2C2C2C2C2C2;
// storage[2] <= 'hC2C2C2C2C2C2;
interrupt <= 0;
/* Fire interrupt. You may want to change */
#(`FIRE_TIME);
interrupt <= 1;
/* Interrupt duration. You may want to change */
#(`INTTERRUPT_DURATION);
interrupt <= 0;
/* Randomized storage initialization.
* You may want to change these for the
* debugging */
storage[0] <= $random;
storage[1] <= $random;
storage[2] <= $random;
// storage[0] <= 'hC2C2C2C2C2C2;
// storage[1] <= 'hC2C2C2C2C2C2;
// storage[2] <= 'hC2C2C2C2C2C2;
/* Another interrupt. You may want to change */
#(`FIRE_TIME);
interrupt <= 1;
/* Interrupt duration. You may want to change */
#(`INTTERRUPT_DURATION);
interrupt <= 0;
// $finish;
end
/* Data to be send */
always @(offset) begin
if (offset < 3) data <= storage[offset];
else data <= 16'hzzzz;
end
endmodule