forked from TinyTapeout/tinyqv-byte-peripheral-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperipheral.v
More file actions
51 lines (40 loc) · 2.1 KB
/
peripheral.v
File metadata and controls
51 lines (40 loc) · 2.1 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
/*
* Copyright (c) 2025 Your Name
* SPDX-License-Identifier: Apache-2.0
*/
`default_nettype none
// Change the name of this module to something that reflects its functionality and includes your name for uniqueness
// For example tqvp_yourname_spi for an SPI peripheral.
// Then edit tt_wrapper.v line 38 and change tqvp_example to your chosen module name.
module tqvp_example (
input clk, // Clock - the TinyQV project clock is normally set to 64MHz.
input rst_n, // Reset_n - low to reset.
input [7:0] ui_in, // The input PMOD, always available. Note that ui_in[7] is normally used for UART RX.
// The inputs are synchronized to the clock, note this will introduce 2 cycles of delay on the inputs.
output [7:0] uo_out, // The output PMOD. Each wire is only connected if this peripheral is selected.
// Note that uo_out[0] is normally used for UART TX.
input [3:0] address, // Address within this peripheral's address space
input data_write, // Data write request from the TinyQV core.
input [7:0] data_in, // Data in to the peripheral, valid when data_write is high.
output [7:0] data_out // Data out from the peripheral, set this in accordance with the supplied address
);
// Example: Implement an 8-bit read/write register at address 0
reg [7:0] example_data;
always @(posedge clk) begin
if (!rst_n) begin
example_data <= 0;
end else begin
if (address == 4'h0) begin
if (data_write) example_data <= data_in;
end
end
end
// All output pins must be assigned. If not used, assign to 0.
assign uo_out = ui_in + example_data; // Example: uo_out is the sum of ui_in and the example register
// Address 0 reads the example data register.
// Address 1 reads ui_in
// All other addresses read 0.
assign data_out = (address == 4'h0) ? example_data :
(address == 4'h1) ? ui_in :
8'h0;
endmodule