📄 sram.vhd
字号:
PROCEDURE power_up (mem: inout memory_array; clear: boolean) IS VARIABLE init_value: std_logic; BEGIN IF clear THEN init_value := '0'; write(output, string'("Initializing SRAM with zero ...") ); ELSE init_value := 'X'; END IF; FOR add IN low_address TO high_address LOOP FOR j IN (width-1) DOWNTO 0 LOOP mem(add)(j) := init_value; END LOOP; END LOOP; END power_up; PROCEDURE load (mem: INOUT memory_array; download_filename: IN string) IS FILE source : text IS IN download_filename; VARIABLE inline, outline : line; VARIABLE add: natural; VARIABLE c : character; VARIABLE source_line_nr: integer := 1; VARIABLE init_value: std_logic := 'U'; BEGIN write(output, string'("Loading SRAM from file ") & download_filename & string'(" ... ") ); WHILE NOT endfile(source) LOOP readline(source, inline); read(inline, add); read(inline, c); IF (c /= ' ') THEN write(outline, string'("Syntax error in file '")); write(outline, download_filename); write(outline, string'("', line ")); write(outline, source_line_nr); writeline(output, outline); ASSERT FALSE REPORT "RAM loader aborted." SEVERITY FAILURE; END IF; FOR i IN (width -1) DOWNTO 0 LOOP read(inline, c); IF (c = '1') THEN mem(add)(i) := '1'; ELSE IF (c /= '0') THEN write(outline, string'("-W- Invalid character '")); write(outline, c); write(outline, string'("' in Bitstring in '")); write(outline, download_filename); write(outline, '('); write(outline, source_line_nr); write(outline, string'(") is set to '0'")); writeline(output, outline); END IF; mem(add)(i) := '0'; END IF; END LOOP; IF (trace_ram_load) THEN write(outline, string'("RAM[")); write(outline, add); write(outline, string'("] := ")); write(outline, mem(add)); writeline(output, outline ); END IF; source_line_nr := source_line_nr +1; END LOOP; -- WHILE END load; -- PROCEDURE PROCEDURE do_dump (mem: INOUT memory_array; dump_start, dump_end: IN natural; dump_filename: IN string) IS FILE dest : text IS OUT dump_filename; VARIABLE l : line; VARIABLE c : character; BEGIN IF (dump_start > dump_end) OR (dump_end >= size) THEN ASSERT FALSE REPORT "Invalid addresses for memory dump. Cancelled." SEVERITY ERROR; ELSE FOR add IN dump_start TO dump_end LOOP write(l, add); write(l, ' '); FOR i IN (width-1) downto 0 LOOP write(l, mem(add)(i)); END LOOP; writeline(dest, l); END LOOP; END IF; END do_dump; -- PROCEDURE BEGIN power_up(mem, clear_on_power_up); IF download_on_power_up THEN load(mem, download_filename); END IF; LOOP IF do_write'EVENT and (do_write = '1') then IF NOT Check_For_Valid_Data(D) THEN IF D'EVENT AND Check_For_Valid_Data(D'DELAYED) THEN write(output, "-W- Data changes exactly at end-of-write to SRAM."); write_data := D'delayed; ELSE write(output, "-E- Data not valid at end-of-write to SRAM."); write_data := undef_vec; END IF; ELSIF NOT D'DELAYED(tHD_min)'STABLE(tSD_min) THEN write(output, "-E- tSD violation: Data input changes within setup-time at end-of-write to SRAM."); write_data := undef_vec; ELSIF NOT D'STABLE(tHD_min) THEN write(output, "-E- tHD violation: Data input changes within hold-time at end-of-write to SRAM."); write_data := undef_vec; ELSIF nWE'DELAYED(tHD_min)'STABLE(tPWE_min) THEN write(output, "-E- tPWE violation: Pulse width of nWE too short at SRAM."); write_data := undef_vec; ELSE write_data := D; END IF; mem(CONV_INTEGER(valid_adr)) := write_data; END IF; IF Check_For_Valid_Data(valid_adr) THEN read_data <= mem(CONV_INTEGER(valid_adr)); ELSE read_data <= undef_vec; END IF; IF dump AND dump'EVENT THEN do_dump(mem, dump_start, dump_end, dump_filename); END IF; IF download AND download'EVENT THEN load(mem, download_filename); END IF; WAIT ON do_write, valid_adr, dump, download; END LOOP; END PROCESS memory; adr_setup <= TRANSPORT A AFTER tAA_max; adr_hold <= TRANSPORT A AFTER tOHA_min; valid_adr <= adr_setup WHEN Check_For_Valid_Data(adr_setup) AND (adr_setup = adr_hold) AND adr_hold'STABLE(tAA_max - tOHA_min) ELSE undef_adr_vec; read_active <= ( (nOE = '0') AND (nOE'DELAYED(tLZOE_min) = '0') AND nOE'STABLE(tLZOE_min) AND ((nWE = '1') OR (nWE'DELAYED(tHZWE_max) = '0')) AND (nCE = '0') AND (CE2 = '1') AND nCE'STABLE(tLZCE_min) AND CE2'STABLE(tLZCE_min)) OR (read_active AND (nOE'DELAYED(tHZOE_max) = '0') AND (nWE'DELAYED(tHZWE_max) = '1') AND (nCE'DELAYED(tHZCE_max) = '0') AND (CE2'DELAYED(tHZCE_max) = '1')); read_valid <= ( (nOE = '0') AND nOE'STABLE(tDOE_max) AND (nWE = '1') AND (nWE'DELAYED(tHZWE_max) = '1') AND (nCE = '0') AND (CE2 = '1') AND nCE'STABLE(tACE_max) AND CE2'STABLE(tACE_max)) OR (read_valid AND read_active); D <= read_data WHEN read_valid and read_active ELSE undef_vec WHEN not read_valid and read_active ELSE tristate_vec; PROCESS (nWE, nCE, CE2) BEGIN IF ((nCE = '1') OR (nWE = '1') OR (CE2 = '0')) AND (nCE'DELAYED = '0') AND (CE2'DELAYED = '1') AND (nWE'DELAYED = '0') -- End of Write THEN do_write <= '1' AFTER tHD_min; ELSE IF (Now > 10 NS) AND (nCE = '0') AND (CE2 = '1') AND (nWE = '0') -- Start of Write THEN ASSERT Check_For_Valid_Data(A) REPORT "Address not valid at start-of-write to RAM." SEVERITY FAILURE; ASSERT A'STABLE(tSA_min) REPORT "tSA violation: Address changed within setup-time at start-of-write to SRAM." SEVERITY ERROR; ASSERT enable_nWE_only_control OR ((nOE = '1') AND nOE'STABLE(tSA_min)) REPORT "tSA violation: nOE not inactive at start-of-write to RAM." SEVERITY ERROR; END IF; do_write <= '0'; END IF; END PROCESS; -- The following processes check for validity of the control signals at the-- SRAM interface. Removing them to speed up simulation will not affect the-- functionality of the SRAM model. PROCESS (A) -- Checks that an address change is allowed BEGIN IF (Now > 0 NS) THEN -- suppress obsolete error message at time 0 ASSERT (nCE = '1') OR (CE2 = '0') OR (nWE = '1') REPORT "Address not stable while write-to-SRAM active" SEVERITY FAILURE; ASSERT (nCE = '1') OR (CE2 = '0') OR (nWE = '1') OR (nCE'DELAYED(tHA_min) = '1') OR (CE2'DELAYED(tHA_min) = '0') OR (nWE'DELAYED(tHA_min) = '1') REPORT "tHA violation: Address changed within hold-time at end-of-write to SRAM." SEVERITY FAILURE; END IF; END PROCESS; PROCESS (nOE, nWE, nCE, CE2) -- Checks that control signals at RAM are valid all the time BEGIN IF (Now > 0 NS) AND (nCE /= '1') AND (CE2 /= '0') THEN IF (nCE = '0') AND (CE2 = '1') THEN ASSERT (nWE = '0') OR (nWE = '1') REPORT "Invalid nWE-signal at SRAM while nCE is active" SEVERITY WARNING; ELSE IF (nCE /= '0') THEN ASSERT (nOE = '1') REPORT "Invalid nCE-signal at SRAM while nOE not inactive" SEVERITY WARNING; ASSERT (nWE = '1') REPORT "Invalid nCE-signal at SRAM while nWE not inactive" SEVERITY ERROR; END IF; IF (CE2 /= '1') THEN ASSERT (nOE = '1') REPORT "Invalid CE2-signal at SRAM while nOE not inactive" SEVERITY WARNING; ASSERT (nWE = '1') REPORT "Invalid CE2-signal at SRAM while nWE not inactive" SEVERITY ERROR; END IF; END IF; END IF; END PROCESS;END behavior;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -