Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
12 years ago

Conditional when statement with port map

Hi,

I am trying to write a conditional concurrent port map without success. Here it is.


   map_gen: for i in 0 to N-1 generate
                    map_0: entity work.my_tff(arch) port map('1', '1', clk, s_q_out(0), s_en_out(0)) when i=0 else
                    map_g: entity work.my_tff(arch) port map(s_q_out(i-1), s_en_out(i-1), clk, s_q_out(i), s_en_out(i));
            end generate;

What´s is wrong?

Regards

Jaraqui

3 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Hi,

    I am trying to write a conditional concurrent port map without success. Here it is.

    
       map_gen: for i in 0 to N-1 generate
                        map_0: entity work.my_tff(arch) port map('1', '1', clk, s_q_out(0), s_en_out(0)) when i=0 else
                        map_g: entity work.my_tff(arch) port map(s_q_out(i-1), s_en_out(i-1), clk, s_q_out(i), s_en_out(i));
                end generate;
    

    What´s is wrong?

    Regards

    Jaraqui

    --- Quote End ---

    why don't you just port map for case 0 directly then generate for case i in 1 to N-1

    anyway you can't use if like that. each generate is written with its condition being true
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Just trying to write compact code... only for curiosity.

    Looking at the when/else examples of the books, I allways observed that a just single statement is presented.

    What happens if someone is interested to write something like the code bellow? Is it possible?

    
        statement_a_1; statement_a_2; ... when signal = a else
        statement_b_1; statement_b_2; ... when signal = b else
       ...
        statement_z_1; statement_z_2;
    

    Regards

    Jaraqui
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    you code isnt quite right, because it has too many ; in it. I think you mean something like:

    
    a <=      b when x = '1' 
         else c when y = '1'
         else d when z = '1'
         else e;
    

    Remember to have the final else, otherwise you generate a latch.