mms.vhd

来自「一个航天航空用的Sparc处理器(配美国欧洲宇航局用的R_tems嵌入式操作系统」· VHDL 代码 · 共 1,831 行 · 第 1/5 页

VHD
1,831
字号
		variable L : line;
		variable Success : boolean;
		variable Res : time := 0 ns;
	begin
		Write(L, S);
		Read(L, Res, Success);
		assert Success report "Not a time string !" severity error;
		return Res;
	end FromString;	-- function

	----------------------------

	function FromString (S : string) return boolean is
		variable Si : string (1 to S'length) := S;
		variable Res : boolean := FALSE;
	begin
		Shift(Si, LeadBlank(Si));
		if StrLen(Si) >= 4 and Si(1 to 4) = "TRUE" then
			Res := TRUE;
			Shift(Si, 4);
		elsif StrLen(Si) >= 5 and Si(1 to 5) = "FALSE" then
			Res := FALSE;
			Shift(Si, 5);
		else
			assert FALSE report "Not a boolean string !" severity error;
		end if;
		assert StrLen(Si) = 0 or Si(1) = ' ' or Si(1) = HT
			report "Not an boolean string !" severity error;
		return Res;
	end FromString;	-- function

	----------------------------

	function ToBit(VALUE : character) return bit is
		variable Res : bit := '0';
	begin
		case VALUE is
			when '0' => Res := '0';
			when '1' => Res := '1';
			when others => assert FALSE
					report "character is not a bit value !" severity error;
		end case;
	return Res;
	end ToBit;	-- local function

	----------------------------

	function ToStdUlogic(VALUE : character) return std_ulogic is
		variable Res : std_ulogic := 'U';
	begin
		case VALUE is
			when 'U' => Res := 'U';
			when 'X' => Res := 'X';
			when '0' => Res := '0';
			when '1' => Res := '1';
			when 'Z' => Res := 'Z';
			when 'L' => Res := 'L';
			when 'H' => Res := 'H';
			when 'W' => Res := 'W';
			when '-' => Res := '-';
			when others => assert FALSE
					report "character is not a std_ulogic value !" severity error;
		end case;
	return Res;
	end ToStdUlogic;	-- local function

	----------------------------

	function FromString (S : string) return bit is
		alias Si : string (1 to S'length) is S;
	begin
		assert not IsBlank(Si) report "Empty or blank string !" severity error;
		return ToBit(Si(LeadBlank(Si) + 1));
	end FromString;	-- function

	----------------------------
	
	function FromString (S : string) return std_ulogic is
		alias Si : string (1 to S'length) is S;
	begin
		assert not IsBlank(Si) report "Empty or blank string !" severity error;
		return ToStdUlogic(Si(LeadBlank(Si) + 1));
	end FromString;	-- function

	----------------------------

	function FromString (S : string; N : natural) return bit_vector is
		alias Si : string (1 to S'length) is S;
		variable Res : bit_vector (0 to N - 1) := (others => '0');
		variable Index : integer := LeadBlank(Si) + 1;
	begin
		if N > StrLen(Si) - Index + 1 then
			assert FALSE report "String too small !" severity error;
		else
			for i in 0 to N - 1 loop
				Res(i) := ToBit(Si(Index));
				Index := Index + 1;
			end loop;
		end if;
		return Res;
	end FromString;	-- function

	----------------------------

	function FromString (S : string; N : natural) return std_ulogic_vector is
		alias Si : string (1 to S'length) is S;
		variable Res : std_ulogic_vector (0 to N - 1) := (others => 'U');
		variable Index : integer := LeadBlank(Si) + 1;
	begin
		if N > StrLen(Si) - Index + 1 then
			assert FALSE report "String too small !" severity error;
		else
			for i in 0 to N - 1 loop
				Res(i) := ToStdUlogic(Si(Index));
				Index := Index + 1;
			end loop;
		end if;
		return Res;
	end FromString;	-- function

	----------------------------

	function FromString (S : string; N : natural) return std_logic_vector is
		alias Si : string (1 to S'length) is S;
		variable Res : std_logic_vector (0 to N - 1) := (others => 'U');
		variable Index : integer := LeadBlank(Si) + 1;
	begin
		if N > StrLen(Si) - Index + 1 then
			assert FALSE report "String too small !" severity error;
		else
			for i in 0 to N - 1 loop
				Res(i) := ToStdUlogic(Si(Index));
				Index := Index + 1;
			end loop;
		end if;
		return Res;
	end FromString;	-- function

	----------------------------

	procedure Print (S : string) is
	begin
		Print(OUTPUT, S);
	end Print;	-- procedure

	----------------------------

	procedure Print (F : out text; S : string) is
		alias Si : string (1 to S'length) is S;
		variable L : line := new string'(Si(1 to Strlen(Si)));
	begin
		writeline(F, L);
	end Print;	-- procedure

	----------------------------

	procedure Scan (S : out string) is
	begin
		Scan(INPUT, S);
	end Scan;	-- procedure

	----------------------------

	procedure Scan (variable F : in text; S : out string) is 
		alias Si : string (1 to S'length) is S;
		variable L : line;
		constant S_LENGTH : natural := S'length;
		variable LLength : natural;
	begin
	 	readline(F, L);
	 	if L = NULL then
	 		assert FALSE report "Read error !" severity error;
	 		return;
	 	end if;
	 	LLength := L'length;
		if LLength < S_LENGTH then Si(1 to LLength + 1) := L.all & NUL;
		elsif LLength = S_LENGTH then Si(1 to LLength) := L.all;
		else
			Si := L(1 to S_LENGTH);
	 		assert FALSE report "String too short to contain input line !" 
	 			severity error;
	 	end if;
	end Scan;	-- procedure

	----------------------------

	---------------
	-- NbWord returns the number of words in a string (separator : blank)
	---------------
	function NbWord(S : string) return integer is
		variable InBlank : boolean := TRUE;
		variable Res : integer := 0;
	begin
		for i in S'range loop
			case S(i) is
				when NUL 			=> exit;	-- respect string convention
				when ' ' | HT => InBlank := TRUE;
				when others 	=> 
					if InBlank then Res := Res + 1; end if;
					InBlank := FALSE;
			end case;
		end loop;
		return Res;
	end NbWord;	-- local function

	---------------

	function GetTiming (	TP_NAME : string;
												N : natural;
												FILE_NAME : string) return tp_array is
		file F : text is in FILE_NAME;
		constant TP_NAME_L : natural := TP_NAME'length;
		alias TpName : string (1 to TP_NAME_L) is TP_NAME;
		variable MyLine : string(1 to BUF_SIZE);
		variable IndexS : natural := LeadBlank(TpName) + 1;
		variable IndexTp, OldIndexTp : natural := 1;
		variable NextTpLength : integer;
		variable Res : tp_array (1 to N) := (others => 0 ns);
		variable WriteCount : bit_vector(1 to N) := (others => '0');
		constant ALL_WRITTEN : bit_vector(1 to N) := (others => '1');
		variable Found : boolean;
	begin
		if N /= NbWord(TpName) then
			assert FALSE report "TP_NAME string incorrect !" severity error;
			return Res;
		end if;
		ForeachLineInFile : while not endfile(F) loop
			Scan(F, MyLine);
			Shift(MyLine, LeadBlank(MyLine));
			next when MyLine(1) = NUL or MyLine(1 to 2) = "--";
			OldIndexTp := IndexTp;
			ForeachTpInTpName : loop
				NextTpLength := WordLen(MyLine);
				Found := StrNcEqu(MyLine, TpName(IndexS to TP_NAME_L), NextTpLength);
				if Found then
					if WriteCount(IndexTp) > '0' then
						assert FALSE report "Field " & MyLine(1 to NextTpLength) & 
							" already loaded !" severity error;
						exit;
					end if;
					Shift(MyLine, NextTpLength);
					Res(IndexTp) := FromString(MyLine);
					WriteCount(IndexTp) := '1';
				end if;
				IndexTp := IndexTp mod N + 1;
				IndexS := NextWord(TpName, IndexS);
				exit when Found or IndexTp = OldIndexTp;
				-- if the line not relevant, it is skipped
			end loop ForeachTpInTpName;
		end loop ForeachLineInFile;
		if WriteCount /= ALL_WRITTEN then
			Diagnosis : for i in 1 to N loop
				assert WriteCount(i) /= '0' report "TP number " & ToString(i) & 
					" not found !" severity error;
			end loop Diagnosis;
		end if;
		return Res;
	end GetTiming;	-- function

	----------------------------

	function GetVal (FILE_NAME, FIELD : string) return integer is
		file F : text is in FILE_NAME;
		variable S : string(1 to BUF_SIZE);
		variable MyVal : integer := 0;
		constant L : integer := StrLen(FIELD);
	begin
		loop
			if endfile(F) then
				assert FALSE report FIELD & " not found in file " & FILE_NAME
					severity error;
				exit;
			end if;
			Scan(F, S);
			Shift(S, LeadBlank(S));
			if StrNcEqu(S, FIELD, L) then
				Shift(S, L);
				MyVal := FromString(S);
				exit;
			end if;
		end loop;
		return MyVal;
	end GetVal;	-- function

	----------------------------

	function GetVal (	FILE_NAME, FIELD : string; 
										INF, SUP : integer) return integer is
		file F : text is in FILE_NAME;
		variable S : string(1 to BUF_SIZE);
		variable MyVal : integer := INF;
		constant L : integer := StrLen(FIELD);
	begin
		loop
			if endfile(F) then
				assert FALSE report FIELD & " not found in file " & FILE_NAME
					severity error;
				exit;
			end if;
			Scan(F, S);
			Shift(S, LeadBlank(S));
			if StrNcEqu(S, FIELD, L) then
				Shift(S, L);
				MyVal := FromString(S);
				if MyVal < INF or MyVal > SUP then
					assert FALSE report "Value " & ToString(MyVal) & " out of range [" & 
						ToString(INF) & ", " & ToString(SUP) & "] in file " & FILE_NAME
						severity error;
					MyVal := INF;
				end if;
				exit;
			end if;
		end loop;
		return MyVal;
	end GetVal;	-- function

	----------------------------

end StdIoImp;	-- package body

------------------------------------------------------------
-- File name : stdsim.vhd
-- Title : StdSim
-- project : SPARC
-- Library : MMS
-- Author(s) : E. Laubacher
-- Purpose : package for standard simulations declarations
-- notes :  to change the simulation conditions, alter 
-- 	the stdsim.dft file in your working directory
------------------------------------------------------------
-- Modification history :
------------------------------------------------------------
-- Version No : | Author | Mod. Date : | Changes made :
------------------------------------------------------------
-- v 1.0        | EL     | 92/08/11    | first version
------------------------------------------------------------
-- Copyright MATRA MARCONI SPACE FRANCE
------------------------------------------------------------

package StdSim is

	----------------------------------
	-- definition of types necessary for simulation control
	----------------------------------

	type environment is (COMMERCIAL, INDUSTRIAL, MILITARY);
	type sim_type is (SPECIFIC, MINIMUM, TYPICAL, MAXIMUM);
	type proces_type is (TYPICAL, BEST, WORST);
	type temperature is range -55 to +125
		units
			Celsius;
		end units;
	type voltage is range 4500 to 5500
		units
			mV;
			V = 1000 mV;
		end units;
	type capacitance is range integer'low to integer'high
		units
			fF;
			pF = 1000 fF;
			nF = 1000 pF;
			uF = 1000 nF;
		end units;

	----------------------------------
	-- Deferred constants

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?