Advertisement
Guest User

Untitled

a guest
May 26th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 12.30 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date:    13:45:07 04/10/2010
  6. -- Design Name:
  7. -- Module Name:    downlink - Behavioral
  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.  
  24. ---- Uncomment the following library declaration if instantiating
  25. ---- any Xilinx primitives in this code.
  26. --library UNISIM;
  27. --use UNISIM.VComponents.all;
  28.  
  29. library work;
  30.     use work.NG.all;
  31.  
  32. entity downlink is
  33.     port
  34.     (
  35.         clock              : IN  std_logic;
  36.         reset              : IN  std_logic;
  37.  
  38.         jpeg_ram_wren      : IN std_logic;
  39.         jpeg_ram_byte      : IN std_logic_vector(7 downto 0);
  40.         jpeg_done          : IN std_logic;
  41.  
  42.         WLAN1_SSEL          : OUT  std_logic;
  43.         WLAN1_SCK           : OUT  std_logic;
  44.         WLAN1_MOSI          : OUT  std_logic;
  45.         WLAN1_MISO          : IN  std_logic;
  46.         WLAN1_RESET         : OUT  std_logic;
  47.  
  48.         WLAN2_SSEL          : OUT  std_logic;
  49.         WLAN2_SCK           : OUT  std_logic;
  50.         WLAN2_MOSI          : OUT  std_logic;
  51.         WLAN2_MISO          : IN  std_logic;
  52.         WLAN2_RESET         : OUT  std_logic;
  53.  
  54.         quality             : OUT std_logic;
  55.         fast                : OUT std_logic;
  56.         channels            : OUT CHANNELS_T;
  57.         channels_available      : OUT std_logic;
  58.  
  59.         DOWNLINK_RDY            : OUT std_logic;
  60.         DOWNLINK_ALMOST_FULL    : OUT std_logic;
  61.  
  62.         switches            : IN std_logic_vector(5 downto 0);
  63.        
  64.         debug               : out std_logic_vector(8 downto 0)
  65.  
  66.     );
  67. end downlink;
  68.  
  69. architecture Behavioral of downlink is
  70.  
  71.     signal device            : std_logic;
  72.     signal WLAN_RDY1         : std_logic;
  73.     signal WLAN_RDY2         : std_logic;
  74.     signal WLAN_ALMOST_FULL1 : std_logic;
  75.     signal WLAN_ALMOST_FULL2 : std_logic;
  76.     signal wlan_done1        : std_logic;
  77.     signal wlan_done2        : std_logic;
  78.  
  79.     signal payload_available : payload_available_t;
  80.  
  81.     signal frame_payload_out : frame_payload_t;
  82.     signal frame_payload     : frame_payload_t;
  83.     signal frame_payload_debug : PAYLOAD_T;
  84.  
  85.     signal wlan_debug1       : std_logic_vector(8 downto 0);
  86.     signal wlan_debug2       : std_logic_vector(8 downto 0);
  87.     signal rc_debug1         : std_logic_vector(8 downto 0);
  88.     signal rc_debug2         : std_logic_vector(8 downto 0);
  89.     signal self_debug        : std_logic_vector(8 downto 0);
  90.  
  91.     signal jpeg_ram_wren1    : std_logic;
  92.     signal jpeg_ram_byte1    : std_logic_vector(7 downto 0);
  93.  
  94.     signal jpeg_ram_wren2    : std_logic;
  95.     signal jpeg_ram_byte2    : std_logic_vector(7 downto 0);
  96.  
  97.     signal payload_debug     : std_logic_vector(8 downto 0);
  98.    
  99.     signal debug_switches : std_logic_vector(4 downto 0);
  100.    
  101.     signal jpeg_done_reg : std_logic;
  102.  
  103.     signal cbc_start, cbc_direction : asl;
  104.     signal cbc_busy, cbc_data_available : asl;
  105.     signal data_in, cbc_crypto_key_in, cbc_cipher_in, cbc_data_in, cbc_auth_key_in, cbc_mac_in : aslv128;
  106.     signal cbc_data_out, cbc_mac_out : std_logic_vector(127 downto 0);
  107.  
  108. -- unfortunately we can't assign to an array from within different instances, even if there is no contention
  109. -- so we have to introduce dedicated signals and assign them in only one process
  110.     signal channels_available0, quality0, fast0 : std_logic;
  111.     signal channels0 : CHANNELS_T;
  112.  
  113.     signal channels_available1, quality1, fast1 : std_logic;
  114.     signal channels1 : CHANNELS_T;
  115.  
  116.     signal cbc_start0, cbc_direction0 : std_logic;
  117.     signal
  118.         cbc_crypto_key_in0,
  119.         cbc_cipher_in0,
  120.         cbc_data_in0,
  121.         cbc_auth_key_in0,
  122.         cbc_mac_in0 : std_logic_vector(127 downto 0);
  123.  
  124.     signal cbc_start1, cbc_direction1 : std_logic;
  125.     signal
  126.         cbc_crypto_key_in1,
  127.         cbc_cipher_in1,
  128.         cbc_data_in1,
  129.         cbc_auth_key_in1,
  130.         cbc_mac_in1 : std_logic_vector(127 downto 0);
  131.  
  132.     signal cbc_start2, cbc_direction2 : std_logic;
  133.     signal
  134.         cbc_crypto_key_in2,
  135.         cbc_cipher_in2,
  136.         cbc_data_in2,
  137.         cbc_auth_key_in2,
  138.         cbc_mac_in2 : std_logic_vector(127 downto 0);
  139.  
  140.     signal cbc_start3, cbc_direction3 : std_logic;
  141.     signal
  142.         cbc_crypto_key_in3,
  143.         cbc_cipher_in3,
  144.         cbc_data_in3,
  145.         cbc_auth_key_in3,
  146.         cbc_mac_in3 : std_logic_vector(127 downto 0);
  147.  
  148.     signal aes_rc_running : au;
  149.  
  150.     signal channels_reg : CHANNELS_T;
  151.  
  152. begin
  153.  
  154.     Inst_video_stream1: entity work.stream
  155.     generic MAP
  156.     (
  157.     subnet => to_unsigned(0, 8)
  158.     )
  159.     PORT MAP(
  160.         clock => clock,
  161.         reset => reset,
  162.  
  163.         jpeg_ram_wren => jpeg_ram_wren1,
  164.         jpeg_ram_byte => jpeg_ram_byte1,
  165.  
  166.         WLAN_SSEL => WLAN1_SSEL,
  167.         WLAN_SCK => WLAN1_SCK,
  168.         WLAN_MOSI => WLAN1_MOSI,
  169.         WLAN_MISO => WLAN1_MISO,
  170.         WLAN_RESET => WLAN1_RESET,
  171.  
  172.         wlan_rdy => wlan_rdy1,
  173.         wlan_almost_full => wlan_almost_full1,
  174.  
  175.         frame_payload => frame_payload_out(0),
  176.         data_available => payload_available(0),
  177.  
  178.         done => wlan_done1,
  179.  
  180.         cbc_start => cbc_start2,
  181.         cbc_direction_in => cbc_direction2,
  182.         cbc_busy => cbc_busy(2),
  183.         cbc_data_available => cbc_data_available(2),
  184.  
  185.         cbc_crypto_key_in => cbc_crypto_key_in2,
  186.         cbc_cipher_in => cbc_cipher_in2,
  187.         cbc_data_in => cbc_data_in2,
  188.         cbc_auth_key_in => cbc_auth_key_in2,
  189.         cbc_mac_in => cbc_mac_in2,
  190.  
  191.         cbc_data_out => cbc_data_out,
  192.         cbc_mac_out => cbc_mac_out,
  193.  
  194.         switches => switches,
  195.         debug => wlan_debug1
  196.     );
  197.  
  198. -- DISABLE FOR SIMULATION TO SAVE STATEMENTS
  199.     Inst_video_stream2: entity work.stream
  200.     generic MAP
  201.     (
  202.     subnet => to_unsigned(1, 8)
  203.     )
  204.     PORT MAP(
  205.         clock => clock,
  206.         reset => reset,
  207.  
  208.         jpeg_ram_wren => jpeg_ram_wren2,
  209.         jpeg_ram_byte => jpeg_ram_byte2,
  210.  
  211.         WLAN_SSEL => WLAN2_SSEL,
  212.         WLAN_SCK => WLAN2_SCK,
  213.         WLAN_MOSI => WLAN2_MOSI,
  214.         WLAN_MISO => WLAN2_MISO,
  215.         WLAN_RESET => WLAN2_RESET,
  216.  
  217.         wlan_rdy => wlan_rdy2,
  218.         wlan_almost_full => wlan_almost_full2,
  219.  
  220.         frame_payload => frame_payload_out(1),
  221.         data_available => payload_available(1),
  222.  
  223.         done => wlan_done2,
  224.  
  225.         cbc_start => cbc_start3,
  226.         cbc_direction_in => cbc_direction3,
  227.         cbc_busy => cbc_busy(3),
  228.         cbc_data_available => cbc_data_available(3),
  229.  
  230.         cbc_crypto_key_in => cbc_crypto_key_in3,
  231.         cbc_cipher_in => cbc_cipher_in3,
  232.         cbc_data_in => cbc_data_in3,
  233.         cbc_auth_key_in => cbc_auth_key_in3,
  234.         cbc_mac_in => cbc_mac_in3,
  235.  
  236.         cbc_data_out => cbc_data_out,
  237.         cbc_mac_out => cbc_mac_out,
  238.  
  239.         switches => switches,
  240.         debug => wlan_debug2
  241.     );
  242.  
  243.     Inst_rc_stream1: entity work.rc_stream
  244.     PORT MAP(
  245.         clock => clock,
  246.         reset => reset,
  247.  
  248.         frame_payload_out => frame_payload_out(0),
  249.         payload_available => payload_available(0),
  250.  
  251.         cbc_start => cbc_start0,
  252.         cbc_direction => cbc_direction0,
  253.         cbc_busy => cbc_busy(0),
  254.         cbc_data_available => cbc_data_available(0),
  255.  
  256.         cbc_crypto_key_in => cbc_crypto_key_in0,
  257.         cbc_cipher_in => cbc_cipher_in0,
  258.         cbc_data_in => cbc_data_in0,
  259.         cbc_auth_key_in => cbc_auth_key_in0,
  260.         cbc_mac_in => cbc_mac_in0,
  261.  
  262.         cbc_data_out => cbc_data_out,
  263.         cbc_mac_out => cbc_mac_out,
  264.  
  265.         -- data output
  266.         quality             => quality0,
  267.         fast                => fast0,
  268.         channels            => channels0,
  269.         channels_available  => channels_available0,
  270.  
  271.         switches => switches,
  272.         debug => rc_debug1
  273.     );
  274.  
  275.     Inst_rc_stream2: entity work.rc_stream
  276.     PORT MAP(
  277.         clock => clock,
  278.         reset => reset,
  279.  
  280.         frame_payload_out => frame_payload_out(1),
  281.         payload_available => payload_available(1),
  282.  
  283.         cbc_start => cbc_start1,
  284.         cbc_direction => cbc_direction1,
  285.         cbc_busy => cbc_busy(1),
  286.         cbc_data_available => cbc_data_available(1),
  287.  
  288.         cbc_crypto_key_in => cbc_crypto_key_in1,
  289.         cbc_cipher_in => cbc_cipher_in1,
  290.         cbc_data_in => cbc_data_in1,
  291.         cbc_auth_key_in => cbc_auth_key_in1,
  292.         cbc_mac_in => cbc_mac_in1,
  293.  
  294.         cbc_data_out => cbc_data_out,
  295.         cbc_mac_out => cbc_mac_out,
  296.  
  297.         -- data output
  298.         quality             => quality1,
  299.         fast                => fast1,
  300.         channels            => channels1,
  301.         channels_available  => channels_available1,
  302.  
  303.         switches => switches,
  304.         debug => rc_debug2
  305.     );
  306.  
  307.  
  308.     Inst_cbc : entity work.cbc
  309.         port map
  310.         (
  311.             clock => clock,
  312.             reset => reset,
  313.  
  314.             start => cbc_start,
  315.             direction_in => cbc_direction,
  316.             busy_out => cbc_busy,
  317.             data_available => cbc_data_available,
  318.  
  319.             crypto_key_in => cbc_crypto_key_in,
  320.             cipher_in => cbc_cipher_in,
  321.             data_in => cbc_data_in,
  322.             auth_key_in => cbc_auth_key_in,
  323.             mac_in => cbc_mac_in,
  324.  
  325.             data_out => cbc_data_out,
  326.             mac_out => cbc_mac_out
  327.         );
  328.  
  329.     process (
  330.         cbc_start0, cbc_direction0, cbc_crypto_key_in0, cbc_cipher_in0, cbc_data_in0, cbc_auth_key_in0, cbc_mac_in0,
  331.         cbc_start1, cbc_direction1, cbc_crypto_key_in1, cbc_cipher_in1, cbc_data_in1, cbc_auth_key_in1, cbc_mac_in1,
  332.         cbc_start2, cbc_direction2, cbc_crypto_key_in2, cbc_cipher_in2, cbc_data_in2, cbc_auth_key_in2, cbc_mac_in2,
  333.         cbc_start3, cbc_direction3, cbc_crypto_key_in3, cbc_cipher_in3, cbc_data_in3, cbc_auth_key_in3, cbc_mac_in3
  334.     )
  335.     begin
  336. -- unfortunately we can't assign to an array from within different instances, even if there is no contention
  337. -- so we have to introduce dedicated signals and assign them in only one instance
  338.         cbc_start(0) <= cbc_start0;
  339.         cbc_direction(0) <= cbc_direction0;
  340.         cbc_crypto_key_in(0) <= cbc_crypto_key_in0;
  341.         cbc_cipher_in(0) <= cbc_cipher_in0;
  342.         cbc_data_in(0) <= cbc_data_in0;
  343.         cbc_auth_key_in(0) <= cbc_auth_key_in0;
  344.         cbc_mac_in(0) <= cbc_mac_in0;
  345.  
  346.         cbc_start(1) <= cbc_start1;
  347.         cbc_direction(1) <= cbc_direction1;
  348.         cbc_crypto_key_in(1) <= cbc_crypto_key_in1;
  349.         cbc_cipher_in(1) <= cbc_cipher_in1;
  350.         cbc_data_in(1) <= cbc_data_in1;
  351.         cbc_auth_key_in(1) <= cbc_auth_key_in1;
  352.         cbc_mac_in(1) <= cbc_mac_in1;
  353.  
  354.         cbc_start(2) <= cbc_start2;
  355.         cbc_direction(2) <= cbc_direction2;
  356.         cbc_crypto_key_in(2) <= cbc_crypto_key_in2;
  357.         cbc_cipher_in(2) <= cbc_cipher_in2;
  358.         cbc_data_in(2) <= cbc_data_in2;
  359.         cbc_auth_key_in(2) <= cbc_auth_key_in2;
  360.         cbc_mac_in(2) <= cbc_mac_in2;
  361.  
  362.         cbc_start(3) <= cbc_start3;
  363.         cbc_direction(3) <= cbc_direction3;
  364.         cbc_crypto_key_in(3) <= cbc_crypto_key_in3;
  365.         cbc_cipher_in(3) <= cbc_cipher_in3;
  366.         cbc_data_in(3) <= cbc_data_in3;
  367.         cbc_auth_key_in(3) <= cbc_auth_key_in3;
  368.         cbc_mac_in(3) <= cbc_mac_in3;
  369.     end process;
  370.  
  371.     -- decrypting remote control
  372.     channels <= channels_reg;
  373.     process (clock, reset)
  374.     begin
  375.         if rising_edge(clock) then
  376.             channels_available <= channels_available0 or channels_available1;
  377.             if channels_available0 = '1' then
  378.                 channels <= channels0;
  379.                 quality <= quality0;
  380.                 fast <= fast0;
  381.             elsif channels_available1 = '1' then
  382.                 channels <= channels1;
  383.                 quality <= quality1;
  384.                 fast <= fast1;
  385.             end if;
  386.         end if;
  387.        
  388.         if reset='1' then
  389.             channels_available <= '0';
  390.             quality <= '0';
  391.             fast <= '0';
  392.             payload_debug <= (others => '0');
  393.         end if;
  394.     end process;
  395.  
  396.     process (clock, reset)
  397.     begin
  398.         if rising_edge(clock) then
  399.  
  400.             if wlan_rdy1 = '1' or wlan_rdy2 = '1' then -- both wlans are powered up and configured, activate forever
  401.                 downlink_rdy <= '1';
  402.             end if;
  403.  
  404.             if jpeg_done = '1' then
  405.                 device <= not device;
  406.             end if;
  407.  
  408.             jpeg_ram_wren1 <= '0';
  409.             jpeg_ram_wren2 <= '0';
  410.             if device = '0' then
  411.                 downlink_almost_full <= wlan_almost_full1;
  412.                 jpeg_ram_wren1 <= jpeg_ram_wren;
  413.                 jpeg_ram_byte1 <= jpeg_ram_byte;
  414.                 wlan_done1 <= '0';
  415.                 wlan_done2 <= '1';
  416.             else
  417.                 downlink_almost_full <= wlan_almost_full2;
  418.                 jpeg_ram_wren2 <= jpeg_ram_wren;
  419.                 jpeg_ram_byte2 <= jpeg_ram_byte;
  420.                 wlan_done2 <= '0';
  421.                 wlan_done1 <= '1';
  422.             end if;
  423.         end if;
  424.        
  425.         if reset = '1' then
  426.             device <= '0';
  427.             wlan_done1 <= '0';
  428.             wlan_done2 <= '0';
  429.             jpeg_ram_wren1 <= '0';
  430.             jpeg_ram_wren2 <= '0';
  431.             downlink_rdy <= '0';
  432.             self_debug <= (others => '0');
  433.         end if;
  434.     end process;
  435.  
  436.     process (clock, reset)
  437.     begin
  438.         if rising_edge(clock) then
  439. -- DISABLE FOR SIMULATION TO SAVE STATEMENTS
  440.             case to_integer(unsigned(switches(0) & switches(1) & switches(2) & switches(3) & switches(4))) is
  441.                 when 0 => debug <= '0' & channels_reg(1);
  442.                 when 1 => debug <= '0' & channels_reg(2);
  443.                 when 2 => debug <= '0' & channels_reg(3);
  444.                 when 3 => debug <= '0' & channels_reg(4);
  445.                 when 4 => debug <= '0' & channels_reg(5);
  446.                 when 5 => debug <= '0' & channels_reg(6);
  447.                 when 6 => debug <= '0' & channels_reg(7);
  448.                 when 7 => debug <= '0' & channels_reg(8);
  449.                 when others => debug <= (others => '0');
  450.             end case;
  451.  
  452.         end if;
  453.     end process;
  454.  
  455.  
  456. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement