entity spi_ltc2600 is
+ generic(
+ BITS : integer range 8 to 32 := 32;
+ WAITCYCLES : integer range 2 to 1024 := 7
+ );
port(
CLK_IN : in std_logic;
RESET_IN : in std_logic;
signal spi_sck : std_logic;
signal spi_sd : std_logic;
- signal word_count : integer range 0 to 31;
- signal bit_count : integer range 0 to 31;
- signal time_count : integer range 0 to 7;
+ signal word_count : integer range 0 to BITS-1;
+ signal bit_count : integer range 0 to BITS-1;
+ signal time_count : integer range 0 to WAITCYCLES;
signal readback : std_logic_vector(31 downto 0);
type fsm_t is (IDLE, WAIT_STATE, SET, TOGGLE_CS, TOGGLE_CS_0, TOGGLE_CS_1, TOGGLE_CS_2, FINISH);
if start = '1' then
ram_addr <= 0;
word_count <= to_integer(unsigned(ctrl_reg(4 downto 0)));
- bit_count <= 31;
- time_count <= 7;
+ bit_count <= BITS-1;
+ time_count <= WAITCYCLES;
fsm_state <= WAIT_STATE;
spi_cs <= not chipselect_reg;
spi_sck <= '1';
end if;
when SET =>
- time_count <= 7;
+ time_count <= WAITCYCLES;
spi_sck <= not spi_sck;
if spi_sck = '1' then
spi_sd <= ram_data(bit_count);
fsm_state <= WAIT_STATE;
else
ram_addr <= ram_addr + 1;
- bit_count <= 31;
+ bit_count <= BITS-1;
if ram_addr /= word_count -1 then
if ctrl_reg(7) = '0' then --one CS phase
fsm_state <= WAIT_STATE;
time_count <= time_count - 1;
if time_count = 0 then
spi_cs <= not chipselect_reg;
- bit_count <= 31;
+ bit_count <= BITS-1;
fsm_state <= WAIT_STATE;
- time_count <= 7;
+ time_count <= WAITCYCLES;
end if;
when TOGGLE_CS_2 =>
time_count <= time_count - 1;
if time_count = 0 then
spi_sck <= not spi_sck;
fsm_state <= WAIT_STATE;
- time_count <= 7;
+ time_count <= WAITCYCLES;
end if;
when FINISH =>
if time_count = 0 and spi_sck = '0' then
- time_count <= 7;
+ time_count <= WAITCYCLES;
spi_sck <= not spi_sck;
readback <= readback(30 downto 0) & SPI_SDI_IN;
elsif time_count = 0 and spi_sck = '1' then