Guest User

Untitled

a guest
May 17th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.44 KB | None | 0 0
  1.  
  2. entity led_driver is
  3.     generic (ROW_BYTES : integer := 32);
  4.    
  5.     port (
  6.         rst_in  : in  STD_LOGIC;                     -- reset
  7.         clk_in  : in  STD_LOGIC;                     -- input clock
  8.  
  9.         -- TODO memory interface
  10.        
  11.         -- SPI writer interface
  12.         spi_data_out : out  STD_LOGIC_VECTOR(8 downto 0); -- output data
  13.         spi_we_out   : out  STD_LOGIC;                    -- write enable
  14.         spi_rdy_in   : in   STD_LOGIC;                    -- ready signal
  15.  
  16.         row_out      : out STD_LOGIC_VECTOR(1 downto 0);  -- active row counter
  17.     );
  18. end led_driver;
  19.  
  20. architecture Behaviour of led_driver is
  21.     type state_t is (
  22.         st_init,  -- initial state
  23.         st_fetch_data,
  24.         st_spi_wait,
  25.         st_spi_push,
  26.         st_next
  27.     );
  28.    
  29.     signal state : state_t := st_init;
  30. begin
  31.  
  32.             -- 1. fetch the next byte from the memory
  33.             -- 2. wait until SPI became ready
  34.             -- 3. push the data to the SPI writer
  35.             -- 4. increment the counters
  36.  
  37.     process (clk_in, rst_in)
  38.         variable current_row : integer from 0 to 3 := 0; -- current row
  39.         variable current_byte : integer from 0 to ROW_BYTES-1;
  40.     begin
  41.         if rst_in = '1' then
  42.             -- reset the device
  43.             current_row := 0;
  44.             current_byte := 0;
  45.             spi_we_out <= '0';
  46.             spi_data_out <= (others => '0');
  47.             row_out <= "00";
  48.             state <= st_init
  49.  
  50.         elsif clk_in'event and clk_in = '1' then
  51.             spi_we_out <= '0';
  52.  
  53.             case state is
  54.                 when st_init =>
  55.                     current_row := 0;
  56.                     current_byte := 0;
  57.                     row_out <= "00";
  58.                     state <= st_fetch_data;
  59.  
  60.                 when st_fetch_data =>
  61.                     -- TODO read data from the memory
  62.                     state <= st_spi_push;
  63.                    
  64.                 when st_spi_push =>
  65.                     -- spi_data_out <= buffer(current_byte);
  66.                     spi_we_out <= '1';
  67.                     state <= st_spi_wait;
  68.  
  69.                 when st_spi_wait =>
  70.                     if spi_rdy_in = '1' then
  71.                         state <= st_next;
  72.                     end if;
  73.                
  74.                 -- when st_next =>
  75.                     -- incrementing counters
  76.  
  77.             end case;
  78.         end if;
  79.     end process;
  80.  
  81. end Behaviour;
Add Comment
Please, Sign In to add comment