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

Subversion Repositories mips_enhanced

[/] [mips_enhanced/] [trunk/] [grlib-gpl-1.0.19-b3188/] [lib/] [gleichmann/] [spi/] [spi_xmit_ea.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dimamali
-------------------------------------------------------------------------------
2
-- Title      : SPI Transmit Core
3
-- Project    : LEON3MINI
4
-------------------------------------------------------------------------------
5
-- $Id: spi_xmit.vhd,v 1.1 2006/08/11 08:55:39 tame Exp $
6
-------------------------------------------------------------------------------
7
-- Author     : Thomas Ameseder
8
-- Company    : Gleichmann Electronics
9
-- Standard   : VHDL'87
10
-------------------------------------------------------------------------------
11
-- Description:
12
--
13
-- This core is an SPI master that was created in order to be able to
14
-- access the configuration interface of the Texas Instruments audio
15
-- codec TLV320AIC23B on the Hpe_mini board.
16
-------------------------------------------------------------------------------
17
-- Copyright (c) 2005 
18
-------------------------------------------------------------------------------
19
 
20
 
21
library ieee;
22
use ieee.std_logic_1164.all;
23
 
24
 
25
entity spi_xmit is
26
  generic (
27
    data_width : integer := 16);
28
  port(
29
    clk_i      : in  std_ulogic;
30
    rst_i      : in  std_ulogic;
31
    data_i     : in  std_logic_vector(data_width-1 downto 0);
32
    CODEC_SDIN : out std_ulogic;
33
    CODEC_CS   : out std_ulogic
34
    );
35
end spi_xmit;
36
 
37
 
38
architecture rtl of spi_xmit is
39
  type state_t is (none_e, transmit_e);
40
 
41
  signal state, nextstate     : state_t;
42
  signal counter, nextcounter : integer range -1 to data_width-1;
43
  signal cs                   : std_ulogic;
44
  signal data_reg             : std_logic_vector(data_width-1 downto 0);
45
 
46
begin  -- rtl
47
 
48
  -- hard wired signals
49
  CODEC_CS   <= cs;
50
 
51
  -- SPI transmit state machine
52
  comb : process (counter, data_reg, state)
53
  begin
54
    nextstate   <= state;
55
    nextcounter <= counter;
56
 
57
    cs         <= '1';
58
    CODEC_SDIN <= '-';
59
 
60
    case state is
61
      when none_e =>
62
        nextstate   <= transmit_e;
63
        nextcounter <= data_width-1;
64
 
65
      when transmit_e =>
66
        cs <= '0';
67
 
68
        if counter = -1 then
69
          nextstate   <= none_e;
70
          nextcounter <= data_width-1;
71
          cs          <= '1';
72
          CODEC_SDIN  <= '-';
73
        else
74
          CODEC_SDIN  <= data_reg(counter);
75
          nextcounter <= counter - 1;
76
        end if;
77
 
78
      when others =>
79
        nextstate   <= none_e;
80
        nextcounter <= data_width-1;
81
    end case;
82
  end process comb;
83
 
84
 
85
  seq : process (clk_i, rst_i)
86
  begin
87
    if rst_i = '0' then
88
      state    <= none_e;
89
      counter  <= data_width-1;
90
      data_reg <= (others => '0');
91
    elsif falling_edge(clk_i) then
92
      state   <= nextstate;
93
      counter <= nextcounter;
94
      -- only accept new data when not transmitting
95
      if state = none_e then
96
        data_reg <= data_i;
97
      end if;
98
    end if;
99
  end process seq;
100
 
101
end rtl;

powered by: WebSVN 2.1.0

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