-- +-----------------------------+ -- | Copyright 2008 DOULOS | -- | Library: memory | -- | designer : Tim Pagden | -- +-----------------------------+ -- -- Ram write Ram Read -- -- ___ ___ ___________ -- nCS \______________/ \_____________/ -- _______ ____________________________________ -- nWE \___/ -- ____________________________ _______________ -- nOE \___/ -- ____ _______________ __________________ ________ -- Addr ____X_______________X__________________X________ -- -- ____ _______________ __ -- Data ____X_______________X------- X__X--------------- -- library IEEE; use IEEE.std_logic_1164.all; use WORK.RamPack.all; entity BigRam is port (Address: in AddrType; Data: inout DataType; nCS, nWE, nOE: in Std_logic); end; architecture Lists of BigRam is -- Model using single linked list begin process (Address, nCS, nWE, nOE) type Item; type ItemPtr is access Item; type Item is record NextItem: ItemPtr; Address: AddrType; Word: DataType; end record; variable Head: ItemPtr; procedure Get (Addr: in AddrType; Word: out DataType) is -- Get the contents of the ram with address = Addr variable Ptr: ItemPtr; begin Ptr := Head; while Ptr /= null loop if Ptr.Address = Addr then Word := Ptr.Word; return; end if; Ptr := Ptr.NextItem; end loop; Word := (others => 'U'); end Get; procedure Set (Addr: in AddrType; Word: in DataType) is -- Set the contents of the ram with address = Addr to Word variable Ptr, PreviousPtr: ItemPtr; begin Ptr := Head; PreviousPtr := null; while Ptr /= null loop if Ptr.Address = Addr then if Word = DataType'(others => 'U') then -- Delete item from list... if PreviousPtr = null then Head := Ptr.NextItem; else PreviousPtr.NextItem := Ptr.NextItem; end if; DEALLOCATE (Ptr); else Ptr.Word := Word; end if; return; end if; PreviousPtr := Ptr; Ptr := Ptr.NextItem; end loop; if Word /= DataType'(others => 'U') then -- Insert new item into list... Ptr := new Item'(NextItem => null, Address => Addr, Word => Word); if PreviousPtr = null then Head := Ptr; else PreviousPtr.NextItem := Ptr; end if; end if; end Set; procedure Diagnose is variable Ptr: ItemPtr; variable Count: NATURAL := 0; begin if Diagnostics then Ptr := Head; while Ptr /= null loop Count := Count + 1; Ptr := Ptr.NextItem; end loop; assert FALSE report "List length = " & INTEGER'IMAGE(Count) severity Note; end if; end Diagnose; variable D: DataType; begin Data <= (others => 'Z'); if nCS = '0' then if nOE = '0' then -- Read operation Get(Address, D); Data <= D; Diagnose; elsif nWE = '0' then -- Write operation Set (Address, Data); Diagnose; end if; end if; end process; end;