nand2/06_IO_Devices/SRAM_D.v
2024-10-25 13:47:27 -04:00

48 lines
1.2 KiB
Verilog

/**
* SRAM controller:
* If load[t] == 1 then out[t+1] = in[t]
* OEX[t+1] = 1
* WEX[t+1] = 0
* DATA[t+1] = in[t] (DATA is configured as output)
* At any other time:
* out = DATA (DATA is configured as input)
* CSX =0;
*/
`default_nettype none
module SRAM_D(
input clk,
input load,
input [15:0] in,
output [15:0] out,
inout [15:0] DATA, // SRAM data 16 Bit
output CSX, // SRAM chip_enable_not
output OEX, // SRAM output_enable_not
output WEX // SRAM write_enable_not
);
// Put your code here:
wire LOAD;
wire [15:0] to_sram;
// always @(posedge clk) begin
// if (load) begin
// OEX <= 1;
// WEX <= 0;
// //to_sram <= in;
// end else begin
// OEX <= 0;
// WEX <= 1;
// end
// end
assign CSX = 0;
assign OEX = (LOAD) ? 1 : 0;
assign WEX = (LOAD) ? 0 : 1;
DFF DFF(clk, load, LOAD);
Register Register(clk, in, load, to_sram);
//if (dir == 0) IN: PIN are set to High-Z, dataR = external PIN
//if (dir == 1) OUTPUT: dataW is output to external PIN, dataR = dataW
InOut InOut(DATA, to_sram, out, OEX);
endmodule