2011-11-08 6 views
1

난 8 비트를 이용하여 각 구성 요소로하는 signal bus : std_logic_vector(NUM-1 downto 0) 통해 다른 모듈과 연결 모듈은 가변 수있는 상태 '생성'되도록 :VHDL, FSM은

인스턴스를 생성하고 포트 하로서는
bus(7 downto 0) = first module 
bus(15 downto 8) = second module 

가 나는 FSM (너무 다른 일을해야하므로)를 통해 각 모듈과 인터페이스 할 수 있도록하고 싶습니다, 그래서 싶습니다 매핑은, 그는 쉽게

INST: for i in 0 to NUM-1 generate 
     Inst_module port map (bus => bus(i*8+7 downto i*8)); 
     end generate INST; 

내 질문으로 이루어집니다당신이 볼 수 있듯이, 많은 반복이

type state_type is (st0_idle, st1_work0, st1_work1 --,etc.) 
signal state : state_type; 
begin 
process(empty) 
    begin 
    if RESET = '1' then 
     --reset FSM 
     state <= st0_idle; 
    else 
     if CLK'event and CLK='1' then 
     case state is 
      when st0_idle => 
      if empty(0) = '0' then 
       state <= st1_work0; 
      elsif empty(1) = '1' then 
       state <= st1_work1; 
      --etc. 
      end if;    
      when st1_work0 => 
      bus(7 downto 0) <= SOMETHING; 
      state <= st0_idle; 
      when st1_work1 => 
       bus(15 downto 8) <= SOMETHINGELSE; 
       state <= st0_idle; 
      --etc.. 
     end if; 
    end if; 
end process; 

오히려 (signal empty : std_logic_vector(NUM-1 downto 0)이 상태 플래그는 각 모듈 인 경우) 수동으로 각 주를 쓸 필요없이, 다음 코드를 '생성'할 수 있어야합니다. 하지만 케이스에 for-generate을 넣을 수는 없으므로 어떻게해야합니까?

답변

4

상태 시스템으로 프로세스를보다 쉽게 ​​읽을 수있는 좋은 방법 중 하나는 공통 코드를 프로세스 내에서 정의 된 프로 시저에 병합하는 것입니다. 예 :

process (empty) is 

    procedure assign_something (
    index  : natural; 
    something : std_logic_vector(7 downto 0) 
    next_state : state_type 
) is 
    begin 
    bus(index*8+7 downto index*8) <= something; 
    state <= next_state; 
    end procedure; 

begin 
    wait until rising_edge(clk); 
    case state is 
    when st0_idle => ... 
    when st1_work0 => assign_something(0, something,  st0_idle); 
    when st1_work1 => assign_something(1, something_else, st0_idle); 
    -- ... etc ... 
    end case; 
    if reset = '1' then 
    state <= st0_idle; 
    end if; 
end procedure; 

잘하면 당신은 아이디어를 얻을. 상태 머신 구조의 규칙에 따라 각 인덱스에 해당하는 열거 형 상태 변수를 이름이 지정된 상태와 함께 추적하는 간단한 계수 또는 인덱스 변수로 바꿀 수도 있습니다.

모두 다 그렇지만, 일반적인 코드를 제거하는 절차를 사용하면 언제든지 VHDL을 작업하기가 훨씬 쉬워집니다.

이 같은 코드 봐 뭔가 만들 것이 변경 사항을 적용 :

architecture ... 

type state_type is (st_idle, st_work); 
signal state : state_type; 
signal index : integer range 0 to NUM-1; 

... 
begin 
... 

process (empty) is 

    procedure assign_something (
    index  : natural; 
    something : std_logic_vector(7 downto 0) 
    next_state : state_type 
) is 
    begin 
    bus(index*8+7 downto index*8) <= something; 
    state <= next_state; 
    end procedure; 

begin 
    wait until rising_edge(clk); 
    case state is 
    when st_idle => 
     for i in 0 to NUM-1 loop 
     if empty(i) = '1' then 
      index := i; 
      exit; 
     end if; 
     end loop; 
    when st_work => assign_something(index, something, st_idle); 
    end case; 
    if reset = '1' then 
    state <= st_idle; 
    end if; 
end procedure; 

을 분명히 이것은 정확히) = ...

+0

를 수행 할 작업을 일치하도록 변경되어야하지만 방법이 없습니다 when 절을 자동으로 생성합니까? –

+1

"when"절을 생성 할 수있는 방법은 없지만 각 NUM 할당 상태에 대한 상태 변수가 실제로는 없지만 열거 상태와 함께 별도의 "인덱스"상태 변수를 사용한다는 의미입니다. 그러면 "assign_something"으로 전달되는 when 문 대신 적절한 상태에서 "assign_something (index, ...)"을 직접 호출하게됩니다. 그래서 당신은'state_type is (st_idle, st_work)'와 또 다른'signal index : 정수 범위 0 ~ NUM-1' 또는 유사한 것을 가질 것입니다. – wjl

+0

아, 그래. 죄송합니다. 그 의미를 놓쳤습니다. 감사. –