VHDL之std_logic_1164

This packages defines a standard for designers to use in describing the interconnection data types used in vhdl modeling.

1  std_logic_1164

  1 PACKAGE std_logic_1164 IS
  2
  3     -------------------------------------------------------------------
  4     -- logic state system  (unresolved)
  5     -------------------------------------------------------------------
  6     TYPE std_ulogic IS ( ‘U‘,  -- Uninitialized
  7                          ‘X‘,  -- Forcing  Unknown
  8                          ‘0‘,  -- Forcing  0
  9                          ‘1‘,  -- Forcing  1
 10                          ‘Z‘,  -- High Impedance
 11                          ‘W‘,  -- Weak     Unknown
 12                          ‘L‘,  -- Weak     0
 13                          ‘H‘,  -- Weak     1
 14                          ‘-‘   -- Don‘t care
 15                        );
 16     --------------------------------------------------------------------------
 17     -- unconstrained array of std_ulogic for use with the resolution function
 18     --------------------------------------------------------------------------
 19     TYPE std_ulogic_vector IS ARRAY ( NATURAL RANGE <> ) OF std_ulogic;
 20
 21     -------------------------------------------------------------------
 22     -- resolution function
 23     -------------------------------------------------------------------
 24     FUNCTION resolved ( s : std_ulogic_vector ) RETURN std_ulogic;
 25
 26     -------------------------------------------------------------------
 27     -- *** industry standard logic type ***
 28     -------------------------------------------------------------------
 29     SUBTYPE std_logic IS resolved std_ulogic;
 30
 31     -----------------------------------------------------------------------
 32     -- unconstrained array of std_logic for use in declaring signal arrays
 33     -----------------------------------------------------------------------
 34     TYPE std_logic_vector IS ARRAY ( NATURAL RANGE <>) OF std_logic;
 35
 36     -----------------------------------------------------------------------------
 37     -- common subtypes
 38     -----------------------------------------------------------------------------
 39     SUBTYPE X01     IS resolved std_ulogic RANGE ‘X‘ TO ‘1‘; -- (‘X‘,‘0‘,‘1‘)
 40     SUBTYPE X01Z    IS resolved std_ulogic RANGE ‘X‘ TO ‘Z‘; -- (‘X‘,‘0‘,‘1‘,‘Z‘)
 41     SUBTYPE UX01    IS resolved std_ulogic RANGE ‘U‘ TO ‘1‘; -- (‘U‘,‘X‘,‘0‘,‘1‘)
 42     SUBTYPE UX01Z   IS resolved std_ulogic RANGE ‘U‘ TO ‘Z‘; -- (‘U‘,‘X‘,‘0‘,‘1‘,‘Z‘)
 43
 44     -------------------------------------------------------------------
 45     -- overloaded logical operators
 46     -------------------------------------------------------------------
 47
 48     FUNCTION "and"  ( l : std_ulogic; r : std_ulogic ) RETURN UX01;
 49     FUNCTION "nand" ( l : std_ulogic; r : std_ulogic ) RETURN UX01;
 50     FUNCTION "or"   ( l : std_ulogic; r : std_ulogic ) RETURN UX01;
 51     FUNCTION "nor"  ( l : std_ulogic; r : std_ulogic ) RETURN UX01;
 52     FUNCTION "xor"  ( l : std_ulogic; r : std_ulogic ) RETURN UX01;
 53     function "xnor" ( l : std_ulogic; r : std_ulogic ) return ux01;
 54     FUNCTION "not"  ( l : std_ulogic                 ) RETURN UX01;
 55
 56     -----------------------------------------------------------------------
 57     -- vectorized overloaded logical operators
 58     -----------------------------------------------------------------------
 59     FUNCTION "and"  ( l, r : std_logic_vector  ) RETURN std_logic_vector;
 60     FUNCTION "and"  ( l, r : std_ulogic_vector ) RETURN std_ulogic_vector;
 61
 62     FUNCTION "nand" ( l, r : std_logic_vector  ) RETURN std_logic_vector;
 63     FUNCTION "nand" ( l, r : std_ulogic_vector ) RETURN std_ulogic_vector;
 64
 65     FUNCTION "or"   ( l, r : std_logic_vector  ) RETURN std_logic_vector;
 66     FUNCTION "or"   ( l, r : std_ulogic_vector ) RETURN std_ulogic_vector;
 67
 68     FUNCTION "nor"  ( l, r : std_logic_vector  ) RETURN std_logic_vector;
 69     FUNCTION "nor"  ( l, r : std_ulogic_vector ) RETURN std_ulogic_vector;
 70
 71     FUNCTION "xor"  ( l, r : std_logic_vector  ) RETURN std_logic_vector;
 72     FUNCTION "xor"  ( l, r : std_ulogic_vector ) RETURN std_ulogic_vector;
 73
 74 --  -----------------------------------------------------------------------
 75 --  Note : The declaration and implementation of the "xnor" function is
 76 --  specifically commented until at which time the VHDL language has been
 77 --  officially adopted as containing such a function. At such a point,
 78 --  the following comments may be removed along with this notice without
 79 --  further "official" ballotting of this std_logic_1164 package. It is
 80 --  the intent of this effort to provide such a function once it becomes
 81 --  available in the VHDL standard.
 82 --  -----------------------------------------------------------------------
 83     function "xnor" ( l, r : std_logic_vector  ) return std_logic_vector;
 84     function "xnor" ( l, r : std_ulogic_vector ) return std_ulogic_vector;
 85
 86     FUNCTION "not"  ( l : std_logic_vector  ) RETURN std_logic_vector;
 87     FUNCTION "not"  ( l : std_ulogic_vector ) RETURN std_ulogic_vector;
 88
 89     -------------------------------------------------------------------
 90     -- conversion functions
 91     -------------------------------------------------------------------
 92     FUNCTION To_bit       ( s : std_ulogic;        xmap : BIT := ‘0‘)
 93                           RETURN BIT;
 94     FUNCTION To_bitvector ( s : std_logic_vector ; xmap : BIT := ‘0‘)
 95                           RETURN BIT_VECTOR;
 96     FUNCTION To_bitvector ( s : std_ulogic_vector; xmap : BIT := ‘0‘)
 97                           RETURN BIT_VECTOR;
 98
 99     FUNCTION To_StdULogic      (b : BIT              ) RETURN std_ulogic;
100     FUNCTION To_StdLogicVector (b : BIT_VECTOR       ) RETURN std_logic_vector;
101     FUNCTION To_StdLogicVector (s : std_ulogic_vector) RETURN std_logic_vector;
102     FUNCTION To_StdULogicVector(b : BIT_VECTOR      ) RETURN std_ulogic_vector;
103     FUNCTION To_StdULogicVector(s : std_logic_vector) RETURN std_ulogic_vector;
104
105     -------------------------------------------------------------------
106     -- strength strippers and type convertors
107     -------------------------------------------------------------------
108
109     FUNCTION To_X01  ( s : std_logic_vector  ) RETURN  std_logic_vector;
110     FUNCTION To_X01  ( s : std_ulogic_vector ) RETURN  std_ulogic_vector;
111     FUNCTION To_X01  ( s : std_ulogic        ) RETURN  X01;
112     FUNCTION To_X01  ( b : BIT_VECTOR        ) RETURN  std_logic_vector;
113     FUNCTION To_X01  ( b : BIT_VECTOR        ) RETURN  std_ulogic_vector;
114     FUNCTION To_X01  ( b : BIT               ) RETURN  X01;
115
116     FUNCTION To_X01Z ( s : std_logic_vector  ) RETURN  std_logic_vector;
117     FUNCTION To_X01Z ( s : std_ulogic_vector ) RETURN  std_ulogic_vector;
118     FUNCTION To_X01Z ( s : std_ulogic        ) RETURN  X01Z;
119     FUNCTION To_X01Z ( b : BIT_VECTOR        ) RETURN  std_logic_vector;
120     FUNCTION To_X01Z ( b : BIT_VECTOR        ) RETURN  std_ulogic_vector;
121     FUNCTION To_X01Z ( b : BIT               ) RETURN  X01Z;
122
123     FUNCTION To_UX01  ( s : std_logic_vector  ) RETURN  std_logic_vector;
124     FUNCTION To_UX01  ( s : std_ulogic_vector ) RETURN  std_ulogic_vector;
125     FUNCTION To_UX01  ( s : std_ulogic        ) RETURN  UX01;
126     FUNCTION To_UX01  ( b : BIT_VECTOR        ) RETURN  std_logic_vector;
127     FUNCTION To_UX01  ( b : BIT_VECTOR        ) RETURN  std_ulogic_vector;
128     FUNCTION To_UX01  ( b : BIT               ) RETURN  UX01;
129
130     -------------------------------------------------------------------
131     -- edge detection
132     -------------------------------------------------------------------
133     FUNCTION rising_edge  (SIGNAL s : std_ulogic) RETURN BOOLEAN;
134     FUNCTION falling_edge (SIGNAL s : std_ulogic) RETURN BOOLEAN;
135
136     -------------------------------------------------------------------
137     -- object contains an unknown
138     -------------------------------------------------------------------
139     FUNCTION Is_X ( s : std_ulogic_vector ) RETURN  BOOLEAN;
140     FUNCTION Is_X ( s : std_logic_vector  ) RETURN  BOOLEAN;
141     FUNCTION Is_X ( s : std_ulogic        ) RETURN  BOOLEAN;
142
143 END std_logic_1164;

2  resolution function  

 1     function resolved ( s : std_ulogic_vector ) return std_ulogic;
 2         variable result : std_ulogic := ‘Z‘;  -- weakest state default
 3     begin
 4         -- the test for a single driver is essential otherwise the
 5         -- loop would return ‘X‘ for a single driver of ‘-‘ and that
 6         -- would conflict with the value of a single driver unresolved signal.
 8         if  s‘length = 1 then
 9             return s(s‘low);
10         else
11             for i in s‘range loop
12                 result := resolution_table(result, s(i));
13             end loop;
14         end if;
15         return result;
16     end resolved;
17
18
19     constant resolution_table : stdlogic_table := (
20     --      ---------------------------------------------------------
21     --      |  U    X    0    1    Z    W    L    H    -        |   |
22     --      ---------------------------------------------------------
23             ( ‘U‘, ‘U‘, ‘U‘, ‘U‘, ‘U‘, ‘U‘, ‘U‘, ‘U‘, ‘U‘ ), -- | U |
24             ( ‘U‘, ‘X‘, ‘X‘, ‘X‘, ‘X‘, ‘X‘, ‘X‘, ‘X‘, ‘X‘ ), -- | X |
25             ( ‘U‘, ‘X‘, ‘0‘, ‘X‘, ‘0‘, ‘0‘, ‘0‘, ‘0‘, ‘X‘ ), -- | 0 |
26             ( ‘U‘, ‘X‘, ‘X‘, ‘1‘, ‘1‘, ‘1‘, ‘1‘, ‘1‘, ‘X‘ ), -- | 1 |
27             ( ‘U‘, ‘X‘, ‘0‘, ‘1‘, ‘Z‘, ‘W‘, ‘L‘, ‘H‘, ‘X‘ ), -- | Z |
28             ( ‘U‘, ‘X‘, ‘0‘, ‘1‘, ‘W‘, ‘W‘, ‘W‘, ‘W‘, ‘X‘ ), -- | W |
29             ( ‘U‘, ‘X‘, ‘0‘, ‘1‘, ‘L‘, ‘W‘, ‘L‘, ‘W‘, ‘X‘ ), -- | L |
30             ( ‘U‘, ‘X‘, ‘0‘, ‘1‘, ‘H‘, ‘W‘, ‘W‘, ‘H‘, ‘X‘ ), -- | H |
31             ( ‘U‘, ‘X‘, ‘X‘, ‘X‘, ‘X‘, ‘X‘, ‘X‘, ‘X‘, ‘X‘ )  -- | - |
32         );
时间: 2024-10-07 12:58:12

VHDL之std_logic_1164的相关文章

有限状态机VHDL模板

逻辑设计, 顾名思义, 只要理清了逻辑和时序, 剩下的设计就是做填空题了. 简单总结了有限状态机的一种设计方式, 详细参见 <<Circuit Design with VHDL>>  chapter 8  State Machines 1  有限状态机 2  VHDL模板之一 1)  端口定义 library IEEE; use ieee.std_logic_1164.all; --! 端口定义 entity <entity_name> is port ( INPUT

分频器VHDL描述

在数字电路中,常需要对较高频率的时钟进行分频操作,得到较低频率的时钟信号.我们知道,在硬件电路设计中时钟信号时非常重要的.    下面我们介绍分频器的VHDL描述,在源代码中完成对时钟信号CLK的2分频,4分频,8分频,16分频.LIBRARY  IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_ARITH.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL; ENTITY  clkdiv  IS         PORT

VHDL学习之TEXTIO在仿真中的应用

TEXTIO 在VHDL 仿真与磁盘文件之间架起了桥梁,使用文本文件扩展VHDL 的仿真功能.本文介绍TEXTIO 程序包,以一个加法器实例说明TEXTIO 的使用方法,最后使用ModelSim 对设计进行仿真,并分析仿真结果.在对VHDL 源程序进行仿真时, 由于有的输入输出关系仅仅靠输入波形或编写testbench 中的信号输入是难以验证结果正确性的,例如, 设计8 位加法器,如果将所有的输入都验证一遍, 是非常麻烦的,因为要全面判断输出是否正确需要一个个的验证.此外,若用VHDL 设计一个

VHDL之Serial-Parallel Multiplier

1 Serial-parallel multiplier Figure 12.1 shows the RTL diagram of a serial-parallel multiplier. One of the input vectors (a) is applied serially to the circuit (one bit at a time, starting from the LSB), while the other (b) is applied in parallel (al

3. 戏说VHDL之入门游戏一:流水灯

一.   流水灯 1.1流水灯原理 流水灯是每个学电子的入门“游戏” ,示意图如图1,其原理极其简单,但是可玩性却极强,可以就8个LED写出不同花样的程序.在1.2中我们列出两个不同思路的代码作为VHDL的入门例程. 图1 流水灯电路图 1.2 流水灯例程 这里提供两个不同的代码. 第一个代码的思路是先对系统时钟分频,产生1s信号(即变量count取值到25000000,这样分频时间=20ns*25000000*2=1s),然后使用移位操作符指令进行操作.该指令是在VHDL93中引入的,包括sl

VHDL之FSM

1 Intro The figure shows the block diagram of a single-phase state machine. The lower section contains sequential logic (?ip-?ops), while the upper section contains combinational logic. The combinational section has two inputs, pr_state (present stat

VHDL数据类型的转换

在VHDL程序中,不同类型的对象不能代入,因此要进行类型转换.类型转换的方法有:(1)类型标记法.用类型名称来实现关系密切的标量类型之间的转换.例如: VARIABLE x:INTEGER;VARIABLE y:REAL;使用类型标记(即类型名)实现类型转换时,可采用赋值语句:x :=INTEGER(y); y :=REAL(x).(2)类型函数法.VHDL程序包中提供了多种转换函数,使得某些类型的数据之间可以相互转换,以实现正确的赋值操作.常用的类型转换函数有:★CONV_INTEGER (

VHDL 学习

近期在接触 VHDL,首先要本好书,个人觉得 1)<VHDL for engineer>  VHDL 大学实用教程 (这个名字翻译的无语...) 2)估计verilog的作者的 bhasker的VHDL也不错 <A VHDL primeer>,因为我喜欢他的verilog <A Verilog Primer, Third Edition> Std_ulogic 中u的含义,unresovled,表示不能多信号重复驱动同一个net Std_logic则是resolved,

VHDL与Verilog硬件描述语言TestBench的编写

VHDL与Verilog硬件描述语言在数字电路的设计中使用的非常普遍,无论是哪种语言,仿真都是必不可少的.而且随着设计复杂度的提高,仿真工具的重要性就越来越凸显出来.在一些小的设计中,用TestBench来进行仿真是一个很不错的选择.VHDL与Verilog语言的语法规则不同,它们的TestBench的具体写法也不同,但是应包含的基本结构大体相似,在VHDL的仿真文件中应包含以下几点:实体和结构体声明.信号声明.顶层设计实例化.提供激励:Verilog的仿真文件应包括:模块声明.信号声明.顶层设