📄 microblaze_types_pkg_body.vhd
字号:
--------------------------------------------------------------------------------- $Id: microblaze_types_pkg_body.vhd,v 1.1 2007/10/12 09:11:36 stefana Exp $--------------------------------------------------------------------------------- MicroBlaze_Types - package body----------------------------------------------------------------------------------- ****************************-- ** Copyright Xilinx, Inc. **-- ** All rights reserved. **-- ****************************----------------------------------------------------------------------------------- Filename: microblaze_types_pkg_body.vhd-- Version: v1.00a-- Description: A package with type definition and help functions for-- different implementations of the MicroBlaze family-- --------------------------------------------------------------------------------- Structure: -- microblaze_types_pkg_body.vhd----------------------------------------------------------------------------------- Author: goran-- History:-- goran 01-29-2001 -- First version-- BLT 04-12-2001 -- Fixed itoa function-- ^^^^^^-- Fixed itoa function to accept negative numbers, modified Get_RLOC_Name-- to swap .S0 and .S1 since in Virtex S1 is on left-- ~~~~~~--------------------------------------------------------------------------------- Naming Conventions:-- active low signals: "*_n"-- clock signals: "clk", "clk_div#", "clk_#x" -- reset signals: "rst", "rst_n" -- generics: "C_*" -- user defined types: "*_TYPE" -- state machine next state: "*_ns" -- state machine current state: "*_cs" -- combinatorial signals: "*_com" -- pipelined or register delay signals: "*_d#" -- counter signals: "*cnt*"-- clock enable signals: "*_ce" RLOC_POS.X := Module_Start(Target)(Module)(I);-- internal version of output port "*_i"-- device pins: "*_pin" -- ports: - Names begin with Uppercase -- processes: "*_PROCESS" -- component instantiations: "<ENTITY_>I_<#|FUNC>-------------------------------------------------------------------------------library IEEE;use IEEE.std_logic_1164.all;use IEEE.numeric_std.all;package body MicroBlaze_Types is function conv_index (I : integer) return integer is begin case I is when 0 => return 0; when 1 => return 2; when 2 => return 8; when 3 => return 10; when 4 => return 16; when 5 => return 18; when 6 => return 24; when 7 => return 26; when 8 => return 1; when 9 => return 3; when 10 => return 9; when 11 => return 11; when 12 => return 17; when 13 => return 19; when 14 => return 25; when 15 => return 27; when 16 => return 4; when 17 => return 6; when 18 => return 12; when 19 => return 14; when 20 => return 20; when 21 => return 22; when 22 => return 28; when 23 => return 30; when 24 => return 5; when 25 => return 7; when 26 => return 13; when 27 => return 15; when 28 => return 21; when 29 => return 23; when 30 => return 29; when 31 => return 31; when others => return -1; end case; end function conv_index; -- log2 function returns the number of bits required to encode x choices function log2(x : natural) return integer is variable i : integer := 0; begin if x = 0 then return 0; else while 2**i < x loop i := i+1; end loop; return i; end if; end function log2; --itoa function converts integer to a text string --this function is required since 'image doesn't work --in synplicity -- valid range for input to the function is -9999 to 9999 function itoa (int : integer) return string is type table is array (0 to 9) of string (1 to 1); constant LUT : table := ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"); variable str1 : string(1 to 1); variable str2 : string(1 to 2); variable str3 : string(1 to 3); variable str4 : string(1 to 4); variable str5 : string(1 to 5); variable abs_int : natural; variable thousands_place : natural; variable hundreds_place : natural; variable tens_place : natural; variable ones_place : natural; variable sign : integer; begin abs_int := abs(int); if abs_int > int then sign := -1; else sign := 1; end if; thousands_place := abs_int/1000; hundreds_place := (abs_int-thousands_place*1000)/100; tens_place := (abs_int-thousands_place*1000-hundreds_place*100)/10; ones_place := (abs_int-thousands_place*1000-hundreds_place*100-tens_place*10); if sign>0 then if thousands_place>0 then str4 := LUT(thousands_place) & LUT(hundreds_place) & LUT(tens_place) & LUT(ones_place); return str4; elsif hundreds_place>0 then str3 := LUT(hundreds_place) & LUT(tens_place) & LUT(ones_place); return str3; elsif tens_place>0 then str2 := LUT(tens_place) & LUT(ones_place); return str2; else str1 := LUT(ones_place); return str1; end if; else if thousands_place>0 then str5 := "-" & LUT(thousands_place) & LUT(hundreds_place) & LUT(tens_place) & LUT(ones_place); return str5; elsif hundreds_place>0 then str4 := "-" & LUT(hundreds_place) & LUT(tens_place) & LUT(ones_place); return str4; elsif tens_place>0 then str3 := "-" & LUT(tens_place) & LUT(ones_place); return str3; else str2 := "-" & LUT(ones_place); return str2; end if; end if; end function itoa; ----------------------------------------------------------------------------- -- ----------------------------------------------------------------------------- type CHAR_TO_INT_TYPE is array (character) of integer; constant STRHEX_TO_INT_TABLE : CHAR_TO_INT_TYPE := ('0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A'|'a' => 10, 'B'|'b' => 11, 'C'|'c' => 12, 'D'|'d' => 13, 'E'|'e' => 14, 'F'|'f' => 15, others => -1); ----------------------------------------------------------------------------- -- Converts a string of hex character to an integer -- accept negative numbers ----------------------------------------------------------------------------- function String_To_Int(S : String) return Integer is variable Result : integer := 0; variable Temp : integer := S'Left; variable Negative : integer := 1; begin for I in S'Left to S'Right loop -- ASCII value - 42 TBD if (S(I) = '-') then Temp := 0; Negative := -1; else Temp := STRHEX_TO_INT_TABLE(S(I)); if (Temp = -1) then assert false report "Wrong value in String_To_Int conversion " & S(I) severity error; end if; end if; Result := Result * 16 + Temp; end loop; return (Negative * Result); end function String_To_Int; -- Function for resolved boolean -- If any boolean in the array is false, then the result is false function resolve_boolean( values : in boolean_array ) return boolean is variable result: boolean := TRUE; begin if (values'length = 1) then result := values(values'low); else for I in values'range loop if values(I) = FALSE then result := FALSE; end if; end loop; end if; return result; end function resolve_boolean; -- Function to or two integer booleans function intbool_or( constant a : integer; constant b : integer) return integer is variable result : integer := 0; begin if a /= 0 then result := 1; end if; if b /= 0 then result := 1; end if; return result; end function intbool_or; function LowerCase_Char(char : character) return character is begin -- If char is not an upper case letter then return char if char < 'A' or char > 'Z' then return char; end if; -- Otherwise map char to its corresponding lower case character and -- return that case char is when 'A' => return 'a'; when 'B' => return 'b'; when 'C' => return 'c'; when 'D' => return 'd'; when 'E' => return 'e'; when 'F' => return 'f'; when 'G' => return 'g'; when 'H' => return 'h'; when 'I' => return 'i'; when 'J' => return 'j'; when 'K' => return 'k'; when 'L' => return 'l'; when 'M' => return 'm'; when 'N' => return 'n'; when 'O' => return 'o'; when 'P' => return 'p'; when 'Q' => return 'q'; when 'R' => return 'r'; when 'S' => return 's'; when 'T' => return 't'; when 'U' => return 'u'; when 'V' => return 'v'; when 'W' => return 'w'; when 'X' => return 'x'; when 'Y' => return 'y'; when 'Z' => return 'z'; when others => return char; end case; end LowerCase_Char; function LowerCase_String (s : string) return string is variable res : string(s'range); begin -- function LowerCase_String for I in s'range loop res(I) := LowerCase_Char(s(I)); end loop; -- I return res; end function LowerCase_String; -- Returns true if case insensitive string comparison determines that -- str1 and str2 are equal function Equal_String( str1, str2 : STRING ) RETURN BOOLEAN IS CONSTANT len1 : INTEGER := str1'length; CONSTANT len2 : INTEGER := str2'length; VARIABLE equal : BOOLEAN := TRUE; BEGIN IF NOT (len1=len2) THEN equal := FALSE; ELSE FOR i IN str1'range LOOP IF NOT (LowerCase_Char(str1(i)) = LowerCase_Char(str2(i))) THEN equal := FALSE; END IF; END LOOP; END IF; RETURN equal; END Equal_String; function String_To_Family (S : string; Select_RTL : boolean) return TARGET_FAMILY_TYPE is begin -- function String_To_Family if ((Select_RTL) or Equal_String(S, "rtl")) then return RTL; elsif Equal_String(S, "spartan2") then return SPARTANII; elsif Equal_String(S, "spartan3") then return SPARTAN3; elsif Equal_String(S, "spartan3E") then return SPARTAN3E; elsif Equal_String(S, "spartan3A") then return SPARTAN3A; elsif Equal_String(S, "spartan3AN") then return SPARTAN3AN; elsif Equal_String(S, "spartan3Adsp") then return SPARTAN3Adsp; elsif Equal_String(S, "spartan2e") then return SPARTANIIE; elsif Equal_String(S, "virtex") then return VIRTEX; elsif Equal_String(S, "virtexe") then return VIRTEXE; elsif Equal_String(S, "virtex2") or Equal_String(S, "qvirtex2") or Equal_String(S, "qrvirtex2") then return VIRTEX2; elsif Equal_String(S, "virtex2p") then return VIRTEX2PRO; elsif Equal_String(S, "virtex4") then return VIRTEX4; elsif Equal_String(S, "virtex5") then return VIRTEX5; else assert (false) report "No known target family" severity failure; return RTL; end if; end function String_To_Family; function Family_To_LUT_Size(Family : TARGET_FAMILY_TYPE) return integer is begin -- function String_To_Family if( Family = VIRTEX5 ) then return 6; end if; return 4; end function Family_To_LUT_Size; end package body MicroBlaze_Types;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -