Vhdl 4先进先出和串行化

Vhdl 4先进先出和串行化,vhdl,fifo,Vhdl,Fifo,我已经实现了一个4 FIFO队列和一个搜索FIFO索引的块,当找到一个不为空的FIFO时,它将提取数据并串行发送 代码如下: library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity Serialize is port ( TX

我已经实现了一个4 FIFO队列和一个搜索FIFO索引的块,当找到一个不为空的FIFO时,它将提取数据并串行发送

代码如下:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity Serialize is
       port
       (
           TX                                                                  : out std_logic_vector(1 downto 0);
           RESET, CLK, We1, We2, We3, We4                                      : in std_logic;
           --
           DATA_IN_A, DATA_IN_B, DATA_IN_C, DATA_IN_D                          : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
           fifo_full1, fifo_full2, fifo_full3, fifo_full4                      : out std_logic;
           --
           SendPackage                                                         : out std_logic
       );
end Serialize;

architecture rtl of Serialize is
     signal step, nr : integer:=0;
     signal enl : std_logic := '0';
     signal temp : std_logic_vector(31 downto 0);
     --signal txx  : std_logic_vector(1 downto 0);
     TYPE sr_length IS ARRAY (0 to 3) OF STD_LOGIC_VECTOR(31 DOWNTO 0);
     SIGNAL queue, queue1, queue2, queue3 : sr_length;
     signal ptr, ptr1, ptr2, ptr3 : integer:= 0;
    -- signal tmp : std_logic_vector(1 downto 0);
     signal i_a, i_b : std_logic;
     signal q_a, q_b, q_c, q_d : std_logic_vector(31 downto 0);
     --signal nr : integer := 0;
begin

     process(CLK, RESET, We1, We2, We3, We4, DATA_IN_A, DATA_IN_B, DATA_IN_C, DATA_IN_D) is
          --variable step, nr : integer:=0;
          --variable enl : std_logic := '0';
          --variable temp : std_logic_vector(31 downto 0);
     begin
          if(RESET = '1') then
              SendPackage <= '0';
              TX<= "00";
             -- busy <= '0';
              --step:= 0;
              --temp := X"00000000";
              --enl := '0';
              step<= 1;
              temp <= X"00000000";
              enl <= '0';
               ptr <= 0;
               ptr1 <= 0;
               ptr2 <= 0;
               ptr3 <= 0;
               fifo_full1 <= '0';
               fifo_full2 <= '0';
               fifo_full3 <= '0';
               fifo_full4 <= '0';
               --nr := 0;
               nr <= 0;
               for i in 0 to 2 loop
                   queue(i)<=X"00000000";
                   queue1(i)<=X"00000000";
                   queue2(i)<=X"00000000";
                   queue3(i)<=X"00000000";
               end loop;
          end if;
          if(CLK'event) then
            if(CLK = '1')then
              --SendPackage <= '0';
            if(We1 = '1' or We2 = '1' or We3 = '1' or We4 = '1')then
               IF (We1 = '1' and ptr <= 3) THEN
                    for i in 0 to 2 loop
                        queue(i + 1) <= queue(i);
                    end loop;
                    queue(0) <= DATA_IN_A;
                    ptr <= ptr+ 1;
              END IF;
              IF (We2 = '1' and ptr1 <= 3) THEN
                    for i in 0 to 2 loop
                        queue1(i + 1) <= queue1(i);
                    end loop;
                    queue1(0) <= DATA_IN_B;
                    ptr1 <= ptr1+ 1;
              END IF;
              IF (We3 = '1' and ptr2 <= 3) THEN
                    for i in 0 to 2 loop
                        queue2(i + 1) <= queue2(i);
                    end loop;
                    queue2(0) <= DATA_IN_C;
                    ptr2 <= ptr2 + 1;
              END IF;
              IF (We4 = '1' and ptr3 <= 3) THEN
                    for i in 0 to 2 loop
                        queue3(i + 1) <= queue3(i);
                    end loop;
                    queue3(0) <= DATA_IN_D;
                   --if(ptr3<=3)then ptr3 <= ptr3 + 1;  end if;
                   ptr3 <= ptr3 + 1;
              END IF;
            elsif(enl = '1')then
                   SendPackage <= '0';
                   --if(step = 0) then step <= step + 1;   end if;
                   if(step = 1) then TX <= temp(1 downto 0); i_b <= '1'; step <= step + 1;   end if;
                   if(step = 2) then TX <= temp(3 downto 2);   i_b <= '0'; step <= step + 1;   end if;   --step <= step + 1;
                   if(step = 3) then TX <= temp(5 downto 4); step <= step + 1;   end if;
                   if(step = 4) then TX <= temp(7 downto 6); step <= step + 1;   end if;
                   if(step = 5) then TX <= temp(9 downto 8); step <= step + 1;   end if;
                   if(step = 6) then TX <= temp(11 downto 10); step <= step + 1;   end if;
                   if(step = 7) then TX <= temp(13 downto 12); step <= step + 1;   end if;
                   if(step = 8) then TX <= temp(15 downto 14); step <= step + 1;   end if;
                   if(step = 9) then TX <= temp(17 downto 16); step <= step + 1;   end if;
                   if(step = 10) then TX <= temp(19 downto 18); step <= step + 1;   end if;
                   if(step = 11) then TX <= temp(21 downto 20); step <= step + 1;   end if;
                   if(step = 12) then TX <= temp(23 downto 22); step <= step + 1;   end if;
                   if(step = 13) then TX <= temp(25 downto 24);  step <= step + 1;   end if;
                   if(step = 14) then TX <= temp(27 downto 26); step <= step + 1;   end if;
                   if(step = 15) then TX <= temp(29 downto 28); step <= step + 1;   end if;
                   if(step = 16) then--mai merg un pas pentru a putea transmite tot pachetul. Daca nu pierd 2 biti
                        TX <= temp(31 downto 30); step <= step + 1;   end if;
                   if(step = 17) then--dupa inca un pas initializez alta trasmitere
                        --step := 0;
                        --temp := X"00000000";
                        --enl := '0';
                        step <= 1;
                        temp <= X"00000000";
                        enl <= '0';
                        --step <= step + 1;
                   end if;
                   i_a <= '1';
                   --step <= step + 1;
            elsif(enl = '0')then
                if(nr = 0)then
                   if(ptr>=1)then
                        ptr <= ptr - 1;
                        --temp := queue(ptr-1);
                        temp <= queue(ptr-1);
                        q_a <= queue(ptr-1);
                        SendPackage <= '1';
                        enl <= '1';
                        step <= 1;
                        --enl := '1';
                        --step := 0;
                        TX <= "00";
                   end if;
                   nr <= nr + 1;
               end if;
               if(nr = 1)then
                   if(ptr1>=1)then
                        ptr1 <= ptr1 - 1;
                        temp <= queue1(ptr1-1);
                        q_b <= queue1(ptr1-1);
                        --temp := queue1(ptr1-1);
                        SendPackage <= '1';
                         enl <= '1';
                        step <= 1;
                        --enl := '1';
                        --step := 0;
                        TX <= "00";
                   end if;
                   nr <= nr + 1;
               end if;
               if(nr = 2)then
                   if(ptr2>=1)then
                        ptr2 <= ptr2 - 1;
                        --temp := queue2(ptr2-1);
                        temp <= queue2(ptr2-1);
                        q_c <= queue2(ptr2-1);
                        SendPackage <= '1';
                         enl <= '1';
                        step <= 1;
                        --enl := '1';
                        --step := 0;
                        TX <= "00";
                   end if;
                   nr <= nr + 1;
               end if;
               if(nr >= 3)then
                   if(ptr3>=1)then
                        ptr3 <= ptr3 - 1;
                        temp <= queue3(ptr3-1);
                        q_d <= queue3(ptr3-1);
                        --temp := queue3(ptr3-1);
                        SendPackage <= '1';
                         enl <= '1';
                        step <= 1;
                        nr <= nr  + 1;
                       -- nr := 0;
                        --enl := '1';
                        --step := 0;
                        TX <= "00";
                   end if;
                   nr <= 0;
                end if;
                --if(nr >= 3 )then nr <= 0; end if;
            end if;

          else
            SendPackage <= '0';
            i_a <= '0';
          end if;
         end if;
          if(ptr >= 4)then fifo_full1 <= '1'; else fifo_full1 <= '0'; end if;
          if(ptr1 >= 4)then fifo_full2 <= '1'; else fifo_full2 <= '0'; end if;
          if(ptr2 >= 4)then fifo_full3 <= '1'; else fifo_full3 <= '0'; end if;
          if(ptr3 >= 4)then fifo_full4 <= '1'; else fifo_full4 <= '0'; end if;
     end process;
end rtl;
IEEE库;
使用IEEE.STD_LOGIC_1164.ALL;
使用IEEE.STD_LOGIC_ARITH.ALL;
使用IEEE.STD_LOGIC_UNSIGNED.ALL;
实体序列化是
港口城市
(
TX:输出标准逻辑向量(1到0);
复位,时钟,We1,We2,We3,We4:标准逻辑;
--
A中的数据、B中的数据、C中的数据、D中的数据:标准逻辑向量(31到0);
fifo_full1、fifo_full2、fifo_full3、fifo_full4:输出标准逻辑;
--
SendPackage:out std_逻辑
);
结束序列化;
Serialize的rtl体系结构是
信号步长,nr:整数:=0;
信号enl:std_逻辑:='0';
信号温度:标准逻辑向量(31至0);
--信号txx:std_逻辑_向量(1到0);
类型sr_长度是标准_逻辑_向量(31到0)的数组(0到3);
信号队列,队列1,队列2,队列3:sr_长度;
信号ptr、ptr1、ptr2、ptr3:整数=0;
--信号tmp:std_逻辑_向量(1到0);
信号i_a,i_b:标准逻辑;
信号q_a、q_b、q_c、q_d:std_逻辑向量(31向下至0);
--信号个数:整数=0;
开始
过程(CLK、复位、We1、We2、We3、We4、数据_IN_A、数据_IN_B、数据_IN_C、数据_IN_D)为
--可变步长,nr:integer:=0;
--变量enl:std_逻辑:='0';
--变量温度:标准逻辑向量(31到0);
开始
如果(重置='1'),则

SendPackage我看你没有什么反应。。。你已经发布了大量的代码,希望潜在的回答者能够浏览!我想,在你得到更多帮助之前,你得把它分解一下。(并将其清理干净-例如,请移除所有注释掉的部分。)

为了调试您自己,我建议您首先让一个通道在它自己的实体中工作。如果您仍然有问题,请编辑您的问题,说明您尝试了哪些内容,哪些内容无效

一个通道工作后,您可以使用较小的控制过程实例化其中的4个,以整理这些元素的加载,并将正确的输出输出到正确的位置

把事情分小阶段进行

关于您的编码风格的一些评论:

注意:这些完全基于“风格分析”,而不是试图修复(或复制)任何功能


首先,删除这两个条款

use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
你没有使用它们。如果你需要对向量进行算术运算


实体
中,您有4个“版本”的多个信号-为什么不让它们成为
标准逻辑向量
s,向量的宽度由
通用
控制?您可以对
ptr
ptr1
等做类似的事情(创建一个整数数组-满分,用于使用
整数
,而不是试图在
标准逻辑向量
上执行所有算术)


敏感度列表太复杂:

process(CLK, RESET, We1, We2, We3, We4, DATA_IN_A, DATA_IN_B, DATA_IN_C, DATA_IN_D) is
您正在编写一个带有异步重置的同步进程,因此您只需要灵敏度列表中的
CLK
reset


您的时钟条件:

if (CLK'event) then
     if (CLK = '1') then
有一个更传统的习惯用语:

if rising_edge(clk) then
(在
if
的布尔条件周围不需要
()
s。这就是C编程:)


这个环路

 for i in 0 to 2 loop
     queue(i + 1) <= queue(i);
 end loop;
 queue(0) <= DATA_IN_A;
如果
ptr…
qu a
qu b
等是数组,则可以在
for
循环中完成

还有一个类似的循环

if(ptr >= 4)then fifo_full1 <= '1'; else fifo_full1 <= '0'; end if;

if(ptr>=4)那么fifo_full1
(if的布尔条件周围不需要()。这就是C编程:)
忍不住想到:)谢谢你的建议。我将1写入17,而不是0写入16,因为当ptr=0时,我丢失了数据。我喜欢用“()”来编码,因为我能更好地阅读代码。我才刚刚开始。再次感谢:@Martin指出,发布大量代码通常不会给您带来好的响应。尝试编写更好的代码片段:
queue <= data_in_a & queue(0 to sr_length'high-1);
 if(step = 1) then TX <= temp(1 downto 0); i_b <= '1'; step <= step + 1;   end if;
 if(step = 2) then TX <= temp(3 downto 2);   i_b <= '0'; step <= step + 1;   end if;   
 if(step = 3) then TX <= temp(5 downto 4); step <= step + 1;   end if;
if (step < 17) then 
    TX <= temp((step-1)*2+1 downto (step-1)*2);
    step <= step + 1;
end if;
i_b <= '0';
if step = 1 then 
   i_b <= '1';
end if;
if(nr = 0)then
  if(ptr>=1)then
if(ptr >= 4)then fifo_full1 <= '1'; else fifo_full1 <= '0'; end if;