executing mux or decode in register - vhdl
Mux alone works , Decoder alone works
Now I want to choose which one to use based on my write_ena in code.
I tried making process and if-else but didn't work and errors in it
My code:
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 16:49:06 04/01/2018
-- Design Name:
-- Module Name: RegisterFile - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_LOGIC_arith.all;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_unsigned.all;
USE WORK.mux_pkg.ALL;
USE WORK.decoder_pkg.all;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity RegisterFile is
Port ( read_sel1 : in STD_LOGIC_VECTOR (4 downto 0);
read_sel2 : in STD_LOGIC_VECTOR (4 downto 0);
write_sel : in STD_LOGIC_VECTOR (4 downto 0);
write_ena : in STD_LOGIC;
clk : in STD_LOGIC;
write_data : in STD_LOGIC_VECTOR (31 downto 0);
data1 : out STD_LOGIC_VECTOR (31 downto 0);
data2 : out STD_LOGIC_VECTOR (31 downto 0)
);
end RegisterFile;
architecture Behavioral of RegisterFile is
begin
process (write_ena)
variable r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16,r17,
r18,r19,r20,r21,r22,r23,r24,r25,r26,r27,r28,r29,r30,r31: STD_LOGIC_VECTOR (31 downto 0);
variable temp : STD_LOGIC_VECTOR (31 downto 0);
begin
if (write_ena = '1') then
D1: decoder PORT MAP (write_sel,temp);
elsif (write_ena = '0') then
M1: mux PORT MAP (r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16,r17,
r18,r19,r20,r21,r22,r23,r24,r25,r26,r27,r28,r29,r30,r31,read_sel1,data1);
M2: mux PORT MAP (r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16,r17,
r18,r19,r20,r21,r22,r23,r24,r25,r26,r27,r28,r29,r30,r31,read_sel2,data2);
end if;
end process;
end Behavioral;
I have package for mux and package for decoder
Errors i get:
ERROR:HDLCompiler:806 -Line 66: Syntax error near "PORT"
ERROR:HDLCompiler:806 -Line 70: Syntax error near "PORT"
ERROR:HDLCompiler:806 -Line 71: Syntax error near ";"
and so on till the end of my process
QUESTION:
I understand that I cannot initiate port inside process so my question is:
How to choose just one to work (either mux or decoder) inside my architecture
Related
Internal signal type error in Test Bench VHDL
I want use internal signal of tag_mem entity in vivado in Test Bench. Line with error in TB_tag_mem.vhd: alias chTagMem is << signal .tag_mem.chTagMem : chTagMem_line >>; Signal in tag_mem (tag_mem.vhd): type chTagMem_line is array (natural range <>) of std_logic_vector (TAG_WIDTH downto 0); signal chTagMem : chTagMem_line(CHAN_CNT - 1 downto 0); When I run simulation, I see error in elaborate.log: Starting static elaboration ERROR: [VRFC 10-3763] type error near 'chtagmem' ; expected type 'chtagmem_line' [C:/Users/Mixen/CBDD/tag_mem/tag_mem.srcs/sim_1/new/TB_tag_mem.vhd:68] ERROR: [XSIM 43-3321] Static elaboration of top level VHDL design unit tb_tag_mem in library work failed. How fix this? Reproduce TB_tag_mem.vhd library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.NUMERIC_STD.all; entity TB_tag_mem is -- Port ( ); end TB_tag_mem; architecture Test of TB_tag_mem is component tag_mem is Port ( clk : in STD_LOGIC ); end component; -- for check type chTagMem_line is array (natural range <>) of std_logic_vector (5 downto 0); alias chTagMem is << signal .tag_mem.chTagMem : chTagMem_line >>; begin sim: process begin report "TEST: Init"; wait; end process sim; end Test; tag_mem.vhd library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.std_logic_unsigned.all; entity tag_mem is Generic ( WIDTH: integer := 5 ); Port ( clk : in STD_LOGIC ); end tag_mem; architecture Behavioral of tag_mem is type chTagMem_line is array (natural range <>) of std_logic_vector (WIDTH downto 0); signal chTagMem : chTagMem_line(4 downto 0); begin end Behavioral;
Don't understand error messages for numeric_std to_unsigned function call, selected signal assignment
I designed a simple shifter but I got an error, I applied different lots of things to solve, then it hasn't been fixed. library IEEE; use IEEE.STD_LOGIC_1164.ALL; --use IEEE.STD_LOGIC_UNSIGNED.ALL; use IEEE.NUMERIC_STD.ALL; --use ieee.std_logic_unsigned.all; entity shifter is Port ( inp : in STD_LOGIC_VECTOR(7 downto 0); shift_cntrl : in STD_LOGIC_VECTOR(1 downto 0); shift_out : out STD_LOGIC_VECTOR(15 downto 0)); end shifter; architecture Behavioral of shifter is begin process(shift_cntrl, inp) begin with shift_cntrl select shift_out <= STD_LOGIC_VECTOR(to_unsigned(inp, shift_out'LENGTH) sll 4) when "01", STD_LOGIC_VECTOR(to_unsigned(inp, shift_out'LENGTH) sll 8) when "10", inp when others; end process; end Behavioral; VHDL error messages: [Synth 8-2778] type error near inp ; expected type natural [shifter.vhd:18] [Synth 8-2778] type error near inp ; expected type natural [shifter.vhd:19] [Synth 8-2757] this construct is only supported in VHDL 1076-2008 [shifter.vhd:20]
with..select is only supported inside a process when the file mode is set to VHDL 2008. Either set the file mode in Vivado to 2008 or simply remove the process around the with..select statement as it is not needed. In addition, there is no function to_unsigned for a std_logic_vector. Because it is a similar type, you can do a type conversion: STD_LOGIC_VECTOR(unsigned(inp) sll 4);
Vivado 2016.3 unconstrained array of record with unconstrained std_logic_vector
I am experimenting to synthesise some VHDL 2008 code in Vivado 2016.3 (the same situation is in 2016.4) The idea is to be able to have unconstrained array in record and at the same time have unconstrained array of these records. Relevant code: (axi_pkg.vhd) -- axi_pkg.vhd -- Author: Bruno Kremel (CERN BE-RF-FB) -- Date: 2016-01-23 -- Description: AXI4 Package library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; use work.misc_pkg.all; package axi_pkg is type axis_in is record tdata : std_logic_vector; tvalid : std_logic; tlast : std_logic; tuser : std_logic_vector; end record; type axis_out is record tready : std_logic; end record; type axis_in_vector is array (natural range <>) of axis_in; type axis_out_vector is array (natural range <>) of axis_out; end package; (axis_reg.vhd) -- axis_reg.vhd -- Author: Bruno Kremel (CERN BE-RF-FB) -- Date: 2016-11-22 -- Description: AXI4 Stream register library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; use work.misc_pkg.all; use work.axi_pkg.all; entity axis_reg is generic ( DATA_TYPE : string := "signed" ); port ( aresetn : in std_logic; aclk : in std_logic; -- Input stream in_axis_in : in axis_in; in_axis_out : out axis_out; -- Output stream out_axis_in : out axis_in; out_axis_out : in axis_out ); end entity axis_reg; architecture basic of axis_reg is constant OUT_DATA_W :natural := out_axis_in.tdata'length; constant IN_DATA_W :natural := in_axis_in.tdata'length; signal in_tdata_conv : std_logic_vector(OUT_DATA_W-1 downto 0); signal in_tuser_conv : std_logic_vector(OUT_DATA_W/8-1 downto 0); signal in_tdata_shd : std_logic_vector(IN_DATA_W-1 downto 0); signal in_tuser_shd : std_logic_vector(IN_DATA_W/8-1 downto 0); begin gen_signed: if DATA_TYPE = "signed" generate in_tdata_conv <= std_logic_vector(resize(signed(in_tdata_shd), OUT_DATA_W)); in_tuser_conv <= std_logic_vector(resize(signed(in_tuser_shd), OUT_DATA_W/8)); end generate; gen_unsigned: if DATA_TYPE = "unsigned" generate in_tdata_conv <= std_logic_vector(resize(unsigned(in_tdata_shd), OUT_DATA_W)); in_tuser_conv <= std_logic_vector(resize(unsigned(in_tuser_shd), OUT_DATA_W/8)); end generate; reg_ctrl_inst : entity work.axis_reg_ctrl port map ( aresetn => aresetn, aclk => aclk, next_tdata => in_tdata_conv, next_tuser => in_tuser_conv, next_update => open, in_tvalid => in_axis_in.tvalid, in_tready => in_axis_out.tready, in_tlast => in_axis_in.tlast, out_tdata => out_axis_in.tdata, out_tvalid => out_axis_in.tvalid, out_tready => out_axis_out.tready, out_tlast => out_axis_in.tlast, out_tuser => out_axis_in.tuser ); end architecture; (test_entity.vhd) library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; use work.axi_pkg.all; entity test_entity is port ( aresetn : std_logic; aclk : std_logic; -- Input stream in_axis_in : in axis_in_vector; in_axis_out : out axis_out_vector; -- Output stream out_axis_in : out axis_in_vector; out_axis_out : in axis_out_vector ); end entity; architecture test of test_entity is begin gen_reg : for i in 0 to in_axis_in'length-1 generate begin reg_i : entity work.axis_reg generic map ( DATA_TYPE => "signed" ) port map (aresetn => aresetn, aclk => aclk, in_axis_in => in_axis_in(i), in_axis_out => in_axis_out(i), out_axis_in => out_axis_in(i), out_axis_out => out_axis_out(i)); end generate; end architecture; And finally test_entity_top.vhd which basically constraints the sizes for synthesis: library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; use work.axi_pkg.all; entity test_entity_top is end entity; architecture test of test_entity_top is constant SIZE : natural := 10; constant DATA_W : natural := 16; signal test_axis_in : axis_in(tdata(DATA_W-1 downto 0), tuser(DATA_W/8-1 downto 0)); signal test_axis_out : axis_out; signal in_axis_in : axis_in_vector(SIZE-1 downto 0)(tdata(DATA_W-1 downto 0), tuser(DATA_W/8-1 downto 0)); signal in_axis_out : axis_out_vector(SIZE-1 downto 0); signal out_axis_in : axis_in_vector(SIZE-1 downto 0)(tdata(DATA_W-1 downto 0), tuser(DATA_W/8-1 downto 0)); signal out_axis_out : axis_out_vector(SIZE-1 downto 0); signal aresetn : std_logic; signal aclk : std_logic; begin tst : entity work.test_entity port map (aresetn => aresetn, aclk => aclk, in_axis_in => in_axis_in, in_axis_out => in_axis_out, out_axis_in => out_axis_in, out_axis_out => out_axis_out ); end architecture; This all nicely compiles in ModelSim. But Vivado is reluctant to sythesise it... With this error: ERROR: [Synth 8-2190] illegal syntax for subtype indication [/home/bkremel/test_vivado/test_entity_top.vhd:15] ERROR: [Synth 8-2235] indexed name prefix type axis_in_vector expects 1 dimensions [/home/bkremel/test_vivado/test_entity_top.vhd:15] ERROR: [Synth 8-2190] illegal syntax for subtype indication [/home/bkremel/test_vivado/test_entity_top.vhd:18] ERROR: [Synth 8-2235] indexed name prefix type axis_in_vector expects 1 dimensions [/home/bkremel/test_vivado/test_entity_top.vhd:18] ERROR: [Synth 8-1031] in_axis_in is not declared [/home/bkremel/test_vivado/test_entity_top.vhd:28] ERROR: [Synth 8-1031] out_axis_in is not declared [/home/bkremel/test_vivado/test_entity_top.vhd:30] ERROR: [Synth 8-1568] actual of formal out port out_axis_in cannot be an expression [/home/bkremel/test_vivado/test_entity_top.vhd:30] INFO: [Synth 8-2810] unit test ignored due to previous errors [/home/bkremel/test_vivado/test_entity_top.vhd:9] Which indicate it does actually accept the syntax of record constraint: signal test_axis_in : axis_in(tdata(DATA_W-1 downto 0), tuser(DATA_W/8-1 downto 0)); While it does not like: signal in_axis_in : axis_in_vector(SIZE-1 downto 0)(tdata(DATA_W-1 downto 0), tuser(DATA_W/8-1 downto 0)); What would you suggest to use intead of unconstrained arrays and records? The thing is that my design quite often changes the bit size of the stream.. So using generic packages would be quite inelegant (especially this register is nice example when in one file you have the bus with different sizes of data bus) So far I have used one dimensional slv without records with manual indexing using functions/procedures, but that is quite messy to maintain... I also add edaplayground example of relevant code https://www.edaplayground.com/x/eiC (to demonstrate that it works in simulator)... Edit: What is interesting is, that it actually synthesise if I do following: library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; use work.axi_pkg.all; entity test_entity_top is end entity; architecture test of test_entity_top is constant SIZE : natural := 4; constant DATA_W : natural := 16; subtype axis_in_constr is axis_in(tdata(DATA_W-1 downto 0), tuser(DATA_W/8-1 downto 0)); subtype axis_out_constr is axis_out; signal ch0, ch1, ch2, ch3 : axis_in_constr; signal out0, out1, out2, out3 : axis_in_constr; signal in_axis_in : axis_in_vector := (ch0, ch1, ch2, ch3); signal out_axis_in : axis_in_vector := (out0, out1, out2, out3); signal in_axis_out : axis_out_vector(SIZE-1 downto 0); signal out_axis_out : axis_out_vector(SIZE-1 downto 0); signal aresetn : std_logic; signal aclk : std_logic; begin tst : entity work.test_entity port map (aresetn => aresetn, aclk => aclk, in_axis_in => in_axis_in, in_axis_out => in_axis_out, out_axis_in => out_axis_in, out_axis_out => out_axis_out ); end architecture; So that means that the array of records with unconstrained array is actually supported, but the direct constraint syntax is not. Any ideas how to define it less elaboratively? Although it's not big deal to define top-level like this.. Still I would not mind to avoid it, it looks a bit hacky... Thanks Bruno
With Xilinx SR we had come to working example of desired behaviour, so I post it here as it works in Vivado as well as ModelSim/Edaplayground. -- axi_pkg.vhd -- Author: Bruno Kremel (CERN BE-RF-FB) -- Date: 2016-01-23 -- Description: AXI4 Package library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; package axi_pkg is type axis_downstream is record tdata : std_logic_vector; tvalid : std_logic; tlast : std_logic; tuser : std_logic_vector; end record; type axis_upstream is record tready : std_logic; end record; type axis_downstream_vector is array (natural range <>) of axis_downstream; type axis_upstream_vector is array (natural range <>) of axis_upstream; end package; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; use work.axi_pkg.all; entity test_entity_top is end entity; architecture test of test_entity_top is constant SIZE : natural := 4; constant DATA_W : natural := 16; signal axis_downstream : axis_downstream_vector(SIZE-1 downto 0)(tdata(DATA_W-1 downto 0), tuser(DATA_W/8-1 downto 0)); signal axis_upstream : axis_upstream_vector(SIZE-1 downto 0); begin assert axis_downstream'length = SIZE report "SIZE is not correct" severity failure; assert axis_downstream(0).tdata'length = DATA_W report "TDATA width is not correct" severity failure; assert axis_downstream(0).tuser'length = (DATA_W/8) report "TUSER width is not correct" severity failure; end architecture; The problem is that not all files were marked as 2008 in Vivado (my fault). But I post this minimal example so that it nicely fit the question. Also Edaplayground link: https://www.edaplayground.com/x/3sKr
" top level design entity is undefined" ... what does it mean?
this is the code and saved it as IR.vhd, while the name of the project is saved as "8051" when i try to compile a vhdl program in altera it is showing "Error (12007): Top-level design entity "8051" is undefined " ... what does it mean ? library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; use ieee.std_logic_arith.all; entity IR is port(clk,rst,pb1:in std_logic; irreg:in std_logic_vector(15 downto 0); ops:out std_logic_vector(2 downto 0); modes:out std_logic; loc1:out std_logic_vector(3 downto 0); loc2ordata:out std_logic_vector(7 downto 0)); end IR; architecture rtl of IR is signal ireg: std_logic_vector(15 downto 0); begin process (pb1) begin if(pb1='0')then --I am going to set up to feed in one instruction at a time ireg<=irreg; --the instruction is executed when pb1 is pressed end if; end process; ops<=ireg(15 downto 13); modes<=ireg(12); loc1<=ireg(11 downto 8); loc2ordata<=ireg(7 downto 0); end rtl;
Something I have noticed is that the top level entity name needs to be the same as the file name and module name. So if you called the top level IR, the file probably needs to be IR.v. Now I never capitalize my file names so I don't actually know if capitalization matching is important.
how to solve "symbol does not have visible declaration error"
My vhdl code is as follows: library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity pc is port( inp : in std_logic_vector(31 downto 0); oup : out std_logic_vector(31 downto 0)); end pc ; architecture behv of pc is signal programcounter : std_logic_vector(31 downto 0); begin process(inp) begin programcounter<=inp; oup<=programcounter; end process; end behv; library ieee; use ieee.std_logic_1164.all; entity ins_memory is port( inp1 : in std_logic_vector(31 downto 0); oup1 : out std_logic_vector (4 downto 0)); end ins_memory; architecture behv1 of ins_memory is type ROM_Array is array (0 to 14) of std_logic_vector(4 downto 0); constant Content: ROM_Array := ( 0 => "00001", -- Suppose ROM has 1 => "00010", -- prestored value 2 => "00011", -- like this table 3 => "00100", -- 4 => "00101", -- 5 => "00110", -- 6 => "00111", -- 7 => "01000", -- 8 => "01001", -- 9 => "01010", -- 10 => "01011", -- 11 => "01100", -- 12 => "01101", -- 13 => "01110", -- 14 => "01111", -- OTHERS => "11111" -- ); component pc is port( inp : in std_logic_vector(31 downto 0); oup : out std_logic_vector(31 downto 0)); end component ; begin D1: pc port map(inp1); process(inp1) begin oup1<= Content (to_integer(inp1)); end process; end behv1; Here basically, I am trying to instantiate pc in entity ins_memory which is a ROM The error I am getting is : oup1<= Content (to_integer(inp1)); The symbol 'TO_INTEGER' does not have a visible declaration. so, How can I solve this error?
There are two entity/architecture declarations, but only the first uses std_logic_arith/unsigned packages, thus these are not known to the second. So add it before ins_memory the entity: use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; Next, the to_integer is from the numeric_std package. The std_logic_vector to integer convert in the std_logic_unsigned package is named conv_integer, so update the oup1 assign to: oup1<= Content (conv_integer(inp1)); Btw, you can get ridge of the component declaration if you instantiate the pc entity directly with: D1 : entity work.pc port map(inp1); Another btw., consider using the VHDL standard numeric_std package instead of the proprietary Synopsys std_logic_arith/unsigned packages.