OpenCores
URL https://opencores.org/ocsvn/artec_dongle_ii_fpga/artec_dongle_ii_fpga/trunk

Subversion Repositories artec_dongle_ii_fpga

[/] [artec_dongle_ii_fpga/] [trunk/] [src/] [lpc_proto/] [lpc_byte.vhd] - Diff between revs 6 and 9

Show entire file | Details | Blame | View Log

Rev 6 Rev 9
Line 25... Line 25...
library ieee;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
use IEEE.std_logic_unsigned.all;
use IEEE.std_logic_arith.all;
use IEEE.std_logic_arith.all;
 
 
 
 
entity lpc_iow is
entity lpc_iow is
  port (
  port (
     --system signals
     --system signals
    lreset_n   : in  std_logic;
    lreset_n   : in  std_logic;
    lclk       : in  std_logic;
    lclk       : in  std_logic;
    lena_mem_r : in  std_logic;  --enable lpc regular memory read cycles also (default is only LPC firmware read)
    lena_mem_r : in  std_logic;  --enable lpc regular memory read cycles also (default is only LPC firmware read)
        lena_reads : in  std_logic;  --enable read capabilities
        lena_reads : in  std_logic;  --enable read capabilities
 
                uart_addr  : in  std_logic_vector(15 downto 0); -- define UART address to listen to              
        --LPC bus from host
        --LPC bus from host
    lad_i      : in  std_logic_vector(3 downto 0);
    lad_i      : in  std_logic_vector(3 downto 0);
    lad_o      : out std_logic_vector(3 downto 0);
    lad_o      : out std_logic_vector(3 downto 0);
    lad_oe     : out std_logic;
    lad_oe     : out std_logic;
    lframe_n   : in  std_logic;
    lframe_n   : in  std_logic;
        --memory interface
        --memory interface
    lpc_addr   : out std_logic_vector(23 downto 0); --shared address
    lpc_addr   : out std_logic_vector(23 downto 0); --shared address
    lpc_wr     : out std_logic;         --shared write not read
    lpc_wr     : out std_logic;         --shared write not read
 
                lpc_io     : out std_logic;     --io access not mem access select
 
                lpc_uart   : out std_logic;     --uart mapped cycle coming
 
                lpc_gpioled: out std_logic;     --gpio led cycle coming
    lpc_data_i : in  std_logic_vector(7 downto 0);
    lpc_data_i : in  std_logic_vector(7 downto 0);
    lpc_data_o : out std_logic_vector(7 downto 0);
    lpc_data_o : out std_logic_vector(7 downto 0);
    lpc_val    : out std_logic;
    lpc_val    : out std_logic;
    lpc_ack    : in  std_logic
    lpc_ack    : in  std_logic
    );
    );
end lpc_iow;
end lpc_iow;
 
 
architecture rtl of lpc_iow is
architecture rtl of lpc_iow is
type state is (RESETs,STARTs,ADDRs,TARs,SYNCs,DATAs,LOCAL_TARs);  -- simple LCP states
type state is (RESETs,STARTs,ADDRs,TARs,SYNCs,DATAs,LOCAL_TARs);  -- simple LCP states
type cycle is (LPC_IO_W,LPC_MEM_R,LPC_FW_R);  -- simple LPC bus cycle types
        type cycle is (LPC_IO_W, LPC_IO_R, LPC_MEM_R, LPC_FW_R); -- simple LPC bus cycle types
 
 
signal CS : state;
signal CS : state;
signal r_lad   : std_logic_vector(3 downto 0);
signal r_lad   : std_logic_vector(3 downto 0);
signal r_addr  : std_logic_vector(31 downto 0);  --should consider saving max
signal r_addr  : std_logic_vector(31 downto 0);  --should consider saving max
                                                --adress 23 bits on flash
                                                --adress 23 bits on flash
Line 77... Line 80...
constant SYNC_WAIT     : std_logic_vector(3 downto 0):="0101";  --sync wait device holds the bus
constant SYNC_WAIT     : std_logic_vector(3 downto 0):="0101";  --sync wait device holds the bus
constant SYNC_LWAIT    : std_logic_vector(3 downto 0):="0110";  --sync long wait expected device holds the bus
constant SYNC_LWAIT    : std_logic_vector(3 downto 0):="0110";  --sync long wait expected device holds the bus
constant TAR_OK            : std_logic_vector(3 downto 0):="1111";  --accepted tar constant for master and slave
constant TAR_OK            : std_logic_vector(3 downto 0):="1111";  --accepted tar constant for master and slave
 
 
 
 
 
 
 
 
begin  -- rtl
begin  -- rtl
 
 
lad_o<= lad_rising_o;
lad_o<= lad_rising_o;
lad_oe <= lad_rising_oe;
lad_oe <= lad_rising_oe;
 
 
 
 
 
 
--Pass the whole LPC address to the system
--Pass the whole LPC address to the system
lpc_addr <= r_addr(23 downto 0);
lpc_addr <= r_addr(23 downto 0);
lpc_data_o<= r_data;
lpc_data_o<= r_data;
 
 
 
 
 
 
 
 
-- purpose: LPC IO write/LPC MEM read/LPC FW read  handler
-- purpose: LPC IO write/LPC MEM read/LPC FW read  handler
-- type   : sequential
-- type   : sequential
-- inputs : lclk, lreset_n
-- inputs : lclk, lreset_n
-- outputs: 
-- outputs: 
LPC: process (lclk, lreset_n)
LPC: process (lclk, lreset_n)
Line 105... Line 101...
    CS<= RESETs;
    CS<= RESETs;
    lad_rising_oe<='0';
    lad_rising_oe<='0';
    data_valid <='1';
    data_valid <='1';
    lad_rising_o<="0000";
    lad_rising_o<="0000";
    lpc_val <='0';
    lpc_val <='0';
 
                        lpc_uart          <= '0';
 
                        lpc_gpioled       <= '0';
 
                        lpc_io            <= '0';
        lpc_wr <='0';
        lpc_wr <='0';
        r_lad <= (others=>'0');
        r_lad <= (others=>'0');
        cycle_type <= LPC_IO_W; --initial value 
        cycle_type <= LPC_IO_W; --initial value 
        r_addr <= (others=>'0');
        r_addr <= (others=>'0');
        r_cnt <= (others=>'0');
        r_cnt <= (others=>'0');
   elsif lclk'event and lclk = '1' then  -- rising clock edge
   elsif lclk'event and lclk = '1' then  -- rising clock edge
    case CS is
    case CS is
      when RESETs => ----------------------------------------------------------
      when RESETs => ----------------------------------------------------------
        lpc_wr <='0';
        lpc_wr <='0';
        lpc_val <='0';
        lpc_val <='0';
 
                                        lpc_uart<= '0';
 
                                        lpc_gpioled<= '0';
 
                                        r_addr<=(others => '0');
 
                                        lpc_io<='0';
        if lframe_n='0' then
        if lframe_n='0' then
          CS <= STARTs;
          CS <= STARTs;
          r_lad <= lad_i;
          r_lad <= lad_i;
        else
        else
          CS <= RESETs;
          CS <= RESETs;
Line 131... Line 134...
              --must identify CYCTYPE
              --must identify CYCTYPE
                  if lad_i(3 downto 1)="001" then --IO WRITE WILL HAPPEN
                  if lad_i(3 downto 1)="001" then --IO WRITE WILL HAPPEN
                    --next 4 states must be address states
                    --next 4 states must be address states
                    CS<=ADDRs;
                    CS<=ADDRs;
                                cycle_type <= LPC_IO_W;
                                cycle_type <= LPC_IO_W;
 
                                                        lpc_io<='1';
 
                                                        r_cnt      <= "000";
 
                                                elsif lad_i(3 downto 1) = "000" then --IO READ WILL HAPPEN
 
                                                        --next 4 states must be address states
 
                                                        CS         <= ADDRs;
 
                                                        cycle_type <= LPC_IO_R;
 
                                                        lpc_io<='1';
                    r_cnt <= "000";
                    r_cnt <= "000";
                  elsif lad_i(3 downto 1)="010"  and lena_mem_r='1' and lena_reads='1' then --MEM READ ALLOWED
                  elsif lad_i(3 downto 1)="010"  and lena_mem_r='1' and lena_reads='1' then --MEM READ ALLOWED
                    CS<=ADDRs;
                    CS<=ADDRs;
                                cycle_type <= LPC_MEM_R;
                                cycle_type <= LPC_MEM_R;
 
                                                        lpc_io<='0';
                    r_cnt <= "000";
                    r_cnt <= "000";
                  else
                  else
                    CS<= RESETs;
                    CS<= RESETs;
                  end if;
                  end if;
        elsif r_lad = START_FW_READ then    --FW READ is always allowed
        elsif r_lad = START_FW_READ then    --FW READ is always allowed
                        if lad_i = IDSEL_FW_BOOT and lena_reads='1'  then
                        if lad_i = IDSEL_FW_BOOT and lena_reads='1'  then
 
                                                        lpc_io<='0';
                    CS<=ADDRs;
                    CS<=ADDRs;
                                cycle_type <= LPC_FW_R;
                                cycle_type <= LPC_FW_R;
                    r_cnt <= "000";
                    r_cnt <= "000";
                        else
                        else
                                CS<= RESETs;
                                CS<= RESETs;
                    end if;
                    end if;
        end if;
        end if;
      when ADDRs => -----------------------------------------------------------
      when ADDRs => -----------------------------------------------------------
       case cycle_type is
       case cycle_type is
         when LPC_IO_W =>                   --IO write cycle
                                                when LPC_IO_W | LPC_IO_R => --IO write cycle or IO read cycle
          if r_cnt ="011" then
          if r_cnt ="011" then
             if r_addr(11 downto 0)=x"008" and lad_i(3 downto 2)="00" then
                                                                if r_addr(11 downto 0) = x"008" and lad_i(3 downto 2) = "00" and cycle_type=LPC_IO_W then
              r_addr<= r_addr(27 downto 0)&lad_i;
 
              r_cnt <= "000";
 
              CS<=DATAs;
              CS<=DATAs;
            elsif r_addr(11 downto 0)=x"008" and lad_i(3 downto 0)=x"8" then  --for debug switch
                                                                elsif r_addr(11 downto 0) = x"008" and lad_i(3 downto 0) = x"4" then  --LED and jumpers
              r_addr<= r_addr(27 downto 0)&lad_i;
                                                                        lpc_gpioled<='1'; --must decode 
 
                                                                        if cycle_type=LPC_IO_W then
 
                                                                                CS <= DATAs;
 
                                                                        else
              r_cnt <= "000";
              r_cnt <= "000";
 
                                                                    lpc_wr     <= '0'; --IO read must accure
 
                                                                    lpc_val    <= '1';
 
                                                                    data_valid <= '0';
 
                                                                                CS <= TARs; --on read we must do sync for read over clock grossing
 
                                                                        end if;
 
                                                                elsif r_addr(11 downto 0) = x"008" and lad_i(3 downto 0) = x"8" and cycle_type=LPC_IO_W then --for debug switch
 
                                                                        CS <= DATAs;
 
                                                                elsif uart_addr(3)='1' and r_addr(11 downto 0)=uart_addr(15 downto 4) and uart_addr(3)=lad_i(3) then --UART selected and enabled by leagal uart addr
 
                                                                        lpc_uart<='1'; --decoded an uart cycle
 
                                                                        if cycle_type=LPC_IO_W then
              CS<=DATAs;
              CS<=DATAs;
            else
            else
 
                                                                    r_cnt      <= "000";
 
                                                                    lpc_wr     <= '0'; --IO read must accure
 
                                                                    lpc_val    <= '1';
 
                                                                    data_valid <= '0';
 
                                                                                CS <= TARs; --on read we must do sync for read over clock grossing
 
                                                                        end if;
 
                                                                else
              --not for this device
              --not for this device
               CS<=RESETs;
               CS<=RESETs;
            end if;
            end if;
 
                                                                r_addr <= r_addr(27 downto 0) & lad_i;
 
                                                                r_cnt  <= "000";
          else
          else
            r_addr<= r_addr(27 downto 0)&lad_i;
            r_addr<= r_addr(27 downto 0)&lad_i;
            r_cnt<=r_cnt + 1;
            r_cnt<=r_cnt + 1;
            CS<=ADDRs;
            CS<=ADDRs;
          end if;
          end if;
Line 217... Line 249...
          else
          else
            r_data <= lad_i&r_data(7 downto 4); --LSB first from io cycle
            r_data <= lad_i&r_data(7 downto 4); --LSB first from io cycle
            r_cnt<=r_cnt + 1;
            r_cnt<=r_cnt + 1;
            CS <= DATAs;
            CS <= DATAs;
          end if;
          end if;
        when LPC_MEM_R | LPC_FW_R =>                    --Memory/FW read cycle
                                                when LPC_MEM_R | LPC_FW_R | LPC_IO_R => --Memory/FW/IO read cycle
          if r_cnt ="001" then
          if r_cnt ="001" then
            lad_rising_o<= r_data(7 downto 4);
            lad_rising_o<= r_data(7 downto 4);
            r_cnt <= "000";
            r_cnt <= "000";
            CS <= LOCAL_TARs;
            CS <= LOCAL_TARs;
          else
          else
Line 262... Line 294...
       case cycle_type is
       case cycle_type is
        when LPC_IO_W =>                   --IO write cycle   
        when LPC_IO_W =>                   --IO write cycle   
          -- just passing r_lad on bus again
          -- just passing r_lad on bus again
          lad_rising_o<= TAR_OK;
          lad_rising_o<= TAR_OK;
          CS <= LOCAL_TARs;
          CS <= LOCAL_TARs;
        when LPC_MEM_R | LPC_FW_R =>                    --Memory/FW read cycle
                                                when LPC_MEM_R | LPC_FW_R | LPC_IO_R => --Memory/FW/IO read cycle
          if data_valid ='1' then
          if data_valid ='1' then
            lad_rising_o<=SYNC_OK;
            lad_rising_o<=SYNC_OK;
            CS <= DATAs;
            CS <= DATAs;
          else
          else
            if lpc_ack='1' then
            if lpc_ack='1' then
Line 283... Line 315...
       case cycle_type is
       case cycle_type is
        when LPC_IO_W =>                   --IO write cycle   
        when LPC_IO_W =>                   --IO write cycle   
            lpc_wr <='0';
            lpc_wr <='0';
            lad_rising_oe <='0';
            lad_rising_oe <='0';
            CS <= RESETs;
            CS <= RESETs;
        when LPC_MEM_R | LPC_FW_R =>                    --Memory read cycle
                                                when LPC_MEM_R | LPC_FW_R | LPC_IO_R => -- read cycle
          if r_cnt ="000" then
          if r_cnt ="000" then
            lad_rising_o<= TAR_OK;
            lad_rising_o<= TAR_OK;
            r_cnt <= r_cnt + 1;
            r_cnt <= r_cnt + 1;
          else
          else
            lad_rising_oe <= '0';
            lad_rising_oe <= '0';

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.