📄 xhdl_std_ulogic.vhdl
字号:
---- Copyright Notice and Proprietary Information---- Copyright (C) 1997-2000 X-Tek Corporation. All rights reserved. This Software -- and documentation are owned by X-Tek Corporation, and may be used only as -- authorized in the license agreement controlling such use. No part of this -- publication may be reproduced, transmitted, or translated, in any form or by -- any means, electronic, mechanical, manual, optical, or otherwise, without prior -- written permission of X-Tek Corporation, or as expressly provided by the license -- agreement.---- Disclaimer---- X-Tek Corporation makes no warranty of any kind, express or implied, with regard -- to this material, including, but not limited to, the implied warranties of -- merchantability and fitness for a particular purpose.---- X-Tek Corporation reserves the right to make changes without further notice to -- the products described herein. X-Tek Corporation does not assume any liability -- arising out of the application or use of any product or circuit described -- herein. The X-Tek products described herein are not authorized for use as -- components in life-support devices.------ Rev 2001.0226---- Rev 2001.0324-- a) Added function -- FUNCTION conv_std_ulogic_vector (-- val : IN boolean;-- len : IN integer) RETURN std_ulogic_vector;----LIBRARY ieee;USE ieee.std_logic_1164.all;LIBRARY std;USE std.textio.all;PACKAGE xhdl_std_ulogic IS FUNCTION conv_std_ulogic ( val : IN boolean) RETURN std_ulogic; FUNCTION conv_std_ulogic ( val : IN integer) RETURN std_ulogic; FUNCTION conv_std_ulogic_vector ( val : IN boolean; len : IN integer) RETURN std_ulogic_vector; FUNCTION conv_std_ulogic_vector ( val : IN integer; len : IN integer) RETURN std_ulogic_vector; FUNCTION to_stdulogic ( val : IN boolean) RETURN std_ulogic; FUNCTION to_stdulogicvector ( val : IN integer; len : IN integer) RETURN std_ulogic_vector; FUNCTION to_stdulogicvector ( val : IN boolean; len : IN integer) RETURN std_ulogic_vector; FUNCTION to_integer ( val : std_ulogic_vector) RETURN integer; FUNCTION "SRL" ( l : std_ulogic_vector; r : integer) RETURN std_ulogic_vector; FUNCTION ShiftRight ( val : std_ulogic_vector; shft : integer) RETURN std_ulogic_vector; FUNCTION "SLL" ( l : std_ulogic_vector; r : integer) RETURN std_ulogic_vector; FUNCTION ShiftLeft ( val : std_ulogic_vector; shft : integer) RETURN std_ulogic_vector; FUNCTION "+" ( l : std_ulogic; r : std_ulogic) RETURN std_ulogic_vector; FUNCTION or_br ( val : std_ulogic_vector) RETURN std_ulogic; FUNCTION and_br ( val : std_ulogic_vector) RETURN std_ulogic; FUNCTION xor_br ( val : std_ulogic_vector) RETURN std_ulogic; FUNCTION xnor_br ( val : std_ulogic_vector) RETURN std_ulogic; FUNCTION nor_br ( val : std_ulogic_vector) RETURN std_ulogic; FUNCTION nand_br ( val : std_ulogic_vector) RETURN std_ulogic; FUNCTION select_expr ( sel : boolean; op1 : std_ulogic_vector; op2 : std_ulogic_vector) RETURN std_ulogic_vector; FUNCTION select_expr ( sel : boolean; op1 : std_ulogic; op2 : std_ulogic) RETURN std_ulogic; FUNCTION to_time ( val : std_ulogic_vector) RETURN time; FUNCTION to_string ( val : std_ulogic_vector) RETURN string; FUNCTION to_string ( val : std_ulogic) RETURN character; FUNCTION to_octstring ( val : IN std_ulogic_vector) RETURN string; FUNCTION to_decstring ( val : IN std_ulogic_vector) RETURN string; FUNCTION to_hexstring ( val : IN std_ulogic_vector) RETURN string; END;PACKAGE BODY xhdl_std_ulogic IS -- -- internally used functions -- FUNCTION make_string ( val : integer; size : integer) RETURN string is VARIABLE r : integer := val; VARIABLE digit : integer; VARIABLE rtn : string(size DOWNTO 1); BEGIN FOR index IN 1 TO size LOOP digit := r REM 10; r := r/10; CASE digit IS WHEN 0 => rtn(index) := '0'; WHEN 1 => rtn(index) := '1'; WHEN 2 => rtn(index) := '2'; WHEN 3 => rtn(index) := '3'; WHEN 4 => rtn(index) := '4'; WHEN 5 => rtn(index) := '5'; WHEN 6 => rtn(index) := '6'; WHEN 7 => rtn(index) := '7'; WHEN 8 => rtn(index) := '8'; WHEN 9 => rtn(index) := '9'; WHEN OTHERS => rtn(index) := 'X'; END CASE; END LOOP; RETURN(rtn); END make_string; -- -- -- FUNCTION conv_std_ulogic ( val : IN boolean) RETURN std_ulogic IS BEGIN RETURN(to_stdulogic(val)); END conv_std_ulogic; FUNCTION conv_std_ulogic ( val : IN integer) RETURN std_ulogic IS BEGIN IF (val = 1) THEN RETURN('1'); ELSE RETURN('0'); END IF; END conv_std_ulogic; FUNCTION conv_std_ulogic_vector ( val : IN boolean; len : IN integer) RETURN std_ulogic_vector IS VARIABLE rtn : std_ulogic_vector(len-1 DOWNTO 0) := (OTHERS => '0'); VARIABLE b : std_ulogic; BEGIN IF (val) THEN b := '1'; ELSE b := '0'; END IF; FOR index IN 0 TO len-1 LOOP rtn(index) := b; END LOOP; RETURN(rtn); END conv_std_ulogic_vector; FUNCTION conv_std_ulogic_vector ( val : IN integer; len : IN integer) RETURN std_ulogic_vector IS BEGIN RETURN(to_stdulogicvector(val, len)); END conv_std_ulogic_vector; -- FUNCTION to_stdulogicvector ( val : IN integer; len : IN integer) RETURN std_ulogic_vector IS VARIABLE rtn : std_ulogic_vector(len-1 DOWNTO 0) := (OTHERS => '0'); VARIABLE num : integer := val; VARIABLE r : integer; BEGIN FOR index IN 0 TO len-1 LOOP r := num rem 2; num := num/2; IF (r = 1) THEN rtn(index) := '1'; ELSE rtn(index) := '0'; END IF; END LOOP; RETURN(rtn); END to_stdulogicvector; -- FUNCTION to_stdulogicvector ( val : IN boolean; len : IN integer) RETURN std_ulogic_vector IS VARIABLE rtn : std_ulogic_vector(len-1 DOWNTO 0) := (OTHERS => '0'); BEGIN rtn(0) := to_stdulogic(val); RETURN(rtn); END to_stdulogicvector; -- FUNCTION to_stdulogic ( val : IN boolean) RETURN std_ulogic IS BEGIN IF (val) THEN RETURN('1'); ELSE RETURN('0'); END IF; END to_stdulogic; -- FUNCTION to_integer ( val : std_ulogic_vector) RETURN integer IS CONSTANT vec : std_ulogic_vector(val'high-val'low DOWNTO 0) := val; VARIABLE rtn : integer := 0; BEGIN FOR index IN vec'RANGE LOOP IF (vec(index) = '1') THEN rtn := rtn + (2**index); END IF; END LOOP; RETURN(rtn); END to_integer; FUNCTION "SRL" ( l : std_ulogic_vector; r : integer) RETURN std_ulogic_vector IS BEGIN RETURN(ShiftRight(l, r)); END "SRL"; FUNCTION ShiftRight ( val : std_ulogic_vector; shft : integer) RETURN std_ulogic_vector IS VARIABLE int : std_ulogic_vector(val'LENGTH+shft-1 DOWNTO 0); VARIABLE rtn : std_ulogic_vector(val'RANGE); VARIABLE fill : std_ulogic_vector(shft-1 DOWNTO 0) := (others => '0'); BEGIN int := fill & val; rtn := int(val'LENGTH+shft-1 DOWNTO shft); RETURN(rtn); END ShiftRight; --
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -