| 1 | ---------------------------------------------------------------------------------- |
|---|
| 2 | -- Company: |
|---|
| 3 | -- Engineer: |
|---|
| 4 | -- |
|---|
| 5 | -- Create Date: 17:03:41 10/22/2012 |
|---|
| 6 | -- Design Name: |
|---|
| 7 | -- Module Name: Proto_receiv - ReceiveProto |
|---|
| 8 | -- Project Name: |
|---|
| 9 | -- Target Devices: |
|---|
| 10 | -- Tool versions: |
|---|
| 11 | -- Description: |
|---|
| 12 | -- |
|---|
| 13 | -- Dependencies: |
|---|
| 14 | -- |
|---|
| 15 | -- Revision: |
|---|
| 16 | -- Revision 0.01 - File Created |
|---|
| 17 | -- Additional Comments: |
|---|
| 18 | -- |
|---|
| 19 | ---------------------------------------------------------------------------------- |
|---|
| 20 | library IEEE; |
|---|
| 21 | use IEEE.STD_LOGIC_1164.ALL; |
|---|
| 22 | USE ieee.numeric_std.ALL; |
|---|
| 23 | use work.CoreTypes.all; |
|---|
| 24 | -- Uncomment the following library declaration if using |
|---|
| 25 | -- arithmetic functions with Signed or Unsigned values |
|---|
| 26 | --use IEEE.NUMERIC_STD.ALL; |
|---|
| 27 | |
|---|
| 28 | -- Uncomment the following library declaration if instantiating |
|---|
| 29 | -- any Xilinx primitives in this code. |
|---|
| 30 | --library UNISIM; |
|---|
| 31 | --use UNISIM.VComponents.all; |
|---|
| 32 | |
|---|
| 33 | entity Proto_receiv is |
|---|
| 34 | generic (sizemem : natural := 64); |
|---|
| 35 | port ( |
|---|
| 36 | clk,reset : in std_logic; |
|---|
| 37 | fifo_empty,fifo_full : in std_logic; |
|---|
| 38 | rcv_start : in std_logic; --début de la réception |
|---|
| 39 | rcv_ack :in std_logic; -- acquittement de la réception |
|---|
| 40 | rcv_comp : out std_logic; -- fin de la réception |
|---|
| 41 | pop : out std_logic:='0'; |
|---|
| 42 | fifo_out : in std_logic_vector(Word-1 downto 0); |
|---|
| 43 | mem :out memory(0 to sizemem-1)); |
|---|
| 44 | end Proto_receiv; |
|---|
| 45 | |
|---|
| 46 | architecture ReceiveProto of Proto_receiv is |
|---|
| 47 | type typ_receiv is (r_wait,r_head,r_len,r_glen,r_data,r_pulse,r_end); |
|---|
| 48 | |
|---|
| 49 | signal spush,spop : std_logic:='0'; |
|---|
| 50 | SIGNAL data_in: std_logic_vector(7 downto 0); |
|---|
| 51 | signal etrec :typ_receiv; |
|---|
| 52 | begin |
|---|
| 53 | |
|---|
| 54 | proc_receiv : process (clk,reset) |
|---|
| 55 | variable dlen,i: natural range 0 to 255 :=0; |
|---|
| 56 | |
|---|
| 57 | begin |
|---|
| 58 | if reset='1' then |
|---|
| 59 | etrec<=r_wait; |
|---|
| 60 | |
|---|
| 61 | else |
|---|
| 62 | if rising_edge(clk) then -- le process s'exécute sur chaque front |
|---|
| 63 | -- montant de l'horloge |
|---|
| 64 | case etrec is |
|---|
| 65 | when r_wait => |
|---|
| 66 | |
|---|
| 67 | i:=0; |
|---|
| 68 | if fifo_empty='0' and rcv_start='1' then |
|---|
| 69 | |
|---|
| 70 | etrec<=r_head; |
|---|
| 71 | mem(0)<=fifo_out; |
|---|
| 72 | |
|---|
| 73 | end if; |
|---|
| 74 | when r_head => |
|---|
| 75 | mem(0)<=fifo_out; --l'en-tête |
|---|
| 76 | |
|---|
| 77 | etrec<=r_len; |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | when r_len => |
|---|
| 81 | dlen:=to_integer(unsigned(fifo_out)); |
|---|
| 82 | mem(1)<=fifo_out; -- la longueur |
|---|
| 83 | |
|---|
| 84 | if dlen>2 then |
|---|
| 85 | etrec<=r_data; |
|---|
| 86 | else |
|---|
| 87 | etrec<=r_end; |
|---|
| 88 | end if; |
|---|
| 89 | i:=1; |
|---|
| 90 | |
|---|
| 91 | when r_data => |
|---|
| 92 | if fifo_empty='0' then |
|---|
| 93 | if i<dlen-2 then |
|---|
| 94 | i:=i+1; |
|---|
| 95 | mem(i)<=fifo_out; |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | else |
|---|
| 99 | etrec<=r_pulse; |
|---|
| 100 | |
|---|
| 101 | mem(i+1)<=fifo_out; |
|---|
| 102 | end if; |
|---|
| 103 | -- time out à prévoir ici |
|---|
| 104 | end if; |
|---|
| 105 | when r_pulse => |
|---|
| 106 | etrec<=r_end; |
|---|
| 107 | |
|---|
| 108 | when r_end => |
|---|
| 109 | if rcv_ack='1' then |
|---|
| 110 | etrec<=r_wait; |
|---|
| 111 | end if; |
|---|
| 112 | |
|---|
| 113 | when others => |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | etrec<=r_wait; |
|---|
| 117 | end case; |
|---|
| 118 | end if; |
|---|
| 119 | end if; |
|---|
| 120 | end process; |
|---|
| 121 | |
|---|
| 122 | pop<=spop; |
|---|
| 123 | |
|---|
| 124 | rec_value : process (etrec) |
|---|
| 125 | begin |
|---|
| 126 | case etrec is |
|---|
| 127 | when r_wait => |
|---|
| 128 | spop<='0'; |
|---|
| 129 | rcv_comp<='0'; |
|---|
| 130 | when r_head => |
|---|
| 131 | |
|---|
| 132 | spop<='1'; |
|---|
| 133 | rcv_comp<='0'; |
|---|
| 134 | -- when r_sync => |
|---|
| 135 | -- spop<='1'; |
|---|
| 136 | -- rcv_comp<='0'; |
|---|
| 137 | when r_len => |
|---|
| 138 | spop<='1'; |
|---|
| 139 | when r_data => |
|---|
| 140 | spop<='1'; |
|---|
| 141 | when r_pulse => |
|---|
| 142 | spop<='0'; |
|---|
| 143 | rcv_comp<='1'; |
|---|
| 144 | when r_end => |
|---|
| 145 | spop<='0'; |
|---|
| 146 | rcv_comp<='1'; |
|---|
| 147 | when others => |
|---|
| 148 | spop<='0'; |
|---|
| 149 | rcv_comp<='0'; |
|---|
| 150 | end case; |
|---|
| 151 | end process; |
|---|
| 152 | end ReceiveProto; |
|---|
| 153 | |
|---|