2016-11-15 7 views
0

저는 VHDL을 처음 사용합니다. VHDL을 사용하는 MP3 디코더를하고 있는데,이 허프만을 웹 사이트에서 코딩 할 때 우연히 만난다. 그러나 실제로 입력 된 비트 파일을 나타내는 줄을 알아내는 데 어려움이 있습니다. 아래는 소스 코드입니다VHDL로 비트 파일을 읽는 방법?

use IEEE.std_logic_1164.all; 
use IEEE.std_logic_unsigned.all; 
use IEEE.std_logic_arith.all; 
use work.all_types.all;   
use work.huffman_types.all; -- this file contains all the tables of huffman decoders 

entity huffman is 
port(clk : in std_logic;  -- input clock signal 
     rst : in std_logic;  -- reset signal ('1' = reset) 
     start : in std_logic;  -- start='1' means that this component is activated 
     done : out std_logic;  -- produce a done signal when process is finished 
     gr : in std_logic;  -- granule ('0'=granule0, '1'=granule1) 
     bin : in std_logic_vector(7 downto 0); -- input main data for huffman 
     addr : out std_logic_vector(9 downto 0); -- address for main data 
     dout : out std_logic_vector(31 downto 0); -- data to memory 
     memc : out mem_control_type; -- memeory controll signal 
     sco : out scalefac_type; -- output scale factors 
     frm : in frame_type  -- contains all header and side information for the current frame 
); 
end; 

architecture behavioral of huffman is 
type state_type is 
(IDLE1,IDLE2,IDLE3,READ,READ1,READ2,READREADY,SCALE,HUFFMAN,HUFFBIGVALUE,TABLELOOKUP1,HUFFCOUNT1,TABLELOOKUP2,HUFFEND,DATAREADY,READY); 
signal cs,ns:state_type; 
type is_type is array (0 to 575) of integer; 
signal isg : is_type; 
signal addrcount1:std_logic_vector(9 downto 0); 
signal valuebuffer : std_logic_vector(0 to 8191); 

begin 

process(cs, frm, gr, start) 

variable scalefac : integer; 
variable count : integer ; 
variable memaddrcount : std_logic_vector(9 downto 0); 
variable scout : scalefac_type; 
variable bitpos:std_logic_vector(12 downto 0); 
variable region1start,region2start,bigvalues,count1s,start_bit1,start_bit2,start_bit,tempbit: integer; 
variable line,line1,region,old_region : integer; 
variable u,w,x,y,linbits:integer; 
variable level,level1,value,temp,templevel:integer; 
variable tindex:integer range 0 to 33; 
variable tempvector : std_logic_vector(7 downto 0); 
variable tempvector1 : std_logic_vector(3 downto 0); 
variable slenval0,slenval1:integer; 
variable tempval,tempdata,temphuff,temphuff1,temppos:integer; 
variable tempcount1:std_logic; 

begin 

case cs is 
    when IDLE1 => 
        addrcount1 <= (others =>'0'); 
      ns<=IDLE2; 
    when IDLE2 => 
        done <= '0'; 
        count :=0; 
      line :=0; 
      line1 :=0; 
      bigvalues:=0; 
      count1s:=0; 
      start_bit:=0; 
      linbits:=0; 
      tempvector1:=(others =>'0'); 
      tempvector:=(others =>'0'); 
      tindex:=0; 
      temp:=0; 
      value:=0; 
      isg<=(others=>0); 
       ns<=IDLE3; 
    when IDLE3 => 
       if (start = '1') then 
      memaddrcount :=(others =>'0'); 
       end if; 
       ns<=READ; 
    when READ => 

       addr <= addrcount1; 
       ns<=READ1; 

    when READ1=> 
     ns<=READREADY; 

    when READREADY => 
      valuebuffer(count to count+7) <= bin; 
      count := count +8; 
       addrcount1 <= addrcount1 +1; 

        if count=8192 then 
         if gr='0' then 
       bitpos:=conv_std_logic_vector((conv_integer(frm.sideinfo.main_data)*8),13); 
        else 
        start_bit2:=conv_integer(bitpos); 
         end if; 
          ns<= SCALE; 
        else 
         ns<= READ; 
        end if; 
        . 
        . 
        . 

우리가 볼 수있는 바와 같이,이 라인은

bin : in std_logic_vector(7 downto 0); -- input main data for huffman 

이 라인은 비트 파일 버퍼에 공급 나타냅니다 입력 주요 데이터입니까?

valuebuffer(count to count+7) <= bin; 

나는 왜 read_mode 방법이 사용되지 않는지 궁금합니다. read_mode이 필요한 경우 어디에 삽입해야합니까?

+0

이 코드에는 아무 파일도 없습니다. 'bin'은 단일 바이트 입력입니다. –

+0

@BrianDrummond, 명확히 해 주셔서 감사합니다. 나는 .mp3 형식으로 변환 된 이진 파일을 가지고 있습니다. 비트 파일을 읽을 수 있도록 코드를 어떻게 수정해야합니까? – Cyan

+2

* 비트 파일을 읽을 수 있도록 코드를 수정해야합니까? *이 장소에서는 너무 광범위합니다. 하드웨어에는 일반적으로 프로세서가없는 파일 시스템이 없습니다. 파일을 (표시되지 않은) 메모리로로드하는 방법을 묻는 중입니까? OpenCores 프로젝트 [MP3 디코더] (http://opencores.org/project,decoder,downloads)에는 huffman.vhd의 기능을 설명하는 readme 파일이 있습니다. [멀티미디어 시스템을위한 MP3 디코딩 코어의 FPGA 기반 아키텍처] (http://www.nsl.hcmus.edu.vn/greenstone/collect/hnkhbk/archives/HASHe1da.dir/doc.pdf)는 이해에 도움이 될 수 있습니다. 코드가 표시됩니다 (그림 19 참조). – user1155120

답변

2

일반적으로 testbench에서만 파일을 읽습니다.

process 
    variable status_input : file_open_status; 
begin 
    -- Open files 
    file_open(status_input, file_input, "../your_text_file.txt", read_mode); ... 

파일의 내용을 읽은 후 데이터를 모듈의 I/O에 공급할 수 있습니다.

게시 한 코드가 끔찍합니다. 많은 문제들, 나는 결코 그것을 언급하지 않을 것이다.

+0

감사합니다. @ 피셔. 동일한 프로젝트 (VHDL을 사용하는 MP3 디코더)에서 작업하고 있습니까? – Cyan

+0

@ Cyan VHDL을 사용하고 있지만 다른 프로젝트입니다. – Fisher