SE-VGA/primitives/primitives.sv

104 lines
2.4 KiB
Systemverilog
Raw Normal View History

2021-04-07 04:15:48 +00:00
/******************************************************************************
* SE-VGA
* Primitives
* techav
* 2021-04-06
******************************************************************************
* Basic modules to be used elsewhere
*****************************************************************************/
2021-04-12 04:46:29 +00:00
`ifndef PRIMS
`define PRIMS
2021-04-07 04:15:48 +00:00
// basic d-flipflop
2021-04-12 04:46:29 +00:00
module myDff (
2021-04-07 04:15:48 +00:00
input wire nReset,
input wire clk,
input wire d,
output reg q
);
2021-04-12 04:46:29 +00:00
always @(posedge clk or negedge nReset) begin
2021-04-07 04:15:48 +00:00
if(nReset == 1'b0) begin
q <= 1'b0;
end else begin
q <= d;
end
end
endmodule
// basic 8-bit mux
module mux8 (
input logic [7:0] inA,
input logic [7:0] inB,
input wire select,
output logic [7:0] out
);
always_comb begin
if(select == 1'b0) begin
out <= inA;
end else begin
out <= inB;
end
end
endmodule
// basic 8-to-1 mux
module mux8x1 (
input logic[7:0] in,
input logic[2:0] select,
output wire out
);
2021-04-12 04:46:29 +00:00
assign out = in[select];
2021-04-08 03:50:46 +00:00
endmodule
// basic 8-to-1 mux with transparent output latch
module mux8x1latch (
input logic[7:0] in,
input logic[2:0] select,
input wire clock,
input wire nReset,
output reg out
);
wire muxOut;
mux8x1 mux (in,select,muxOut);
// transparent latch -- when clock is low, output will
// follow the output of the mux. When clock is high,
// output will hold its last value.
2021-04-12 04:46:29 +00:00
always @(clock or nReset or muxOut or out) begin
2021-04-08 03:50:46 +00:00
if(nReset == 1'b0) begin
2021-04-12 04:46:29 +00:00
out = 1'b0;
2021-04-08 03:50:46 +00:00
end else if(clock == 1'b0) begin
2021-04-12 04:46:29 +00:00
out = muxOut;
end else begin
out = out;
2021-04-08 03:50:46 +00:00
end
2021-04-07 04:15:48 +00:00
end
endmodule
// basic 8-bit PISO shift register
module piso8 (
input wire nReset,
input wire clk,
input wire load,
input logic [7:0] parIn,
output wire out
);
logic [7:0] muxIns;
logic [7:0] muxOuts;
mux8 loader(muxIns[7:0],parIn[7:0],load,muxOuts[7:0]);
2021-04-12 04:46:29 +00:00
myDff u0(nReset,clk,muxOuts[0],muxIns[1]);
myDff u1(nReset,clk,muxOuts[1],muxIns[2]);
myDff u2(nReset,clk,muxOuts[2],muxIns[3]);
myDff u3(nReset,clk,muxOuts[3],muxIns[4]);
myDff u4(nReset,clk,muxOuts[4],muxIns[5]);
myDff u5(nReset,clk,muxOuts[5],muxIns[6]);
myDff u6(nReset,clk,muxOuts[6],muxIns[7]);
myDff u7(nReset,clk,muxOuts[7],muxIns[0]);
assign out = muxIns[0];
endmodule
2021-04-07 04:15:48 +00:00
2021-04-12 04:46:29 +00:00
`endif