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/] [i2c/] [partoi2s.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dimamali
-------------------------------------------------------------------------------
2
-- Title      : ParToI2s
3
-- Project    : 
4
-------------------------------------------------------------------------------
5
-- File       : ParToI2s.vhd
6
-- Author     : Voggeneder Andreas, Truhlar Günther
7
-- Company    : 
8
-- Created    : 2002-11-20
9
-- Last update: 2006-02-01
10
-- Platform   : 
11
-- Standard   : VHDL'87
12
-------------------------------------------------------------------------------
13
-- Description: realizes the connection from the DSP to the I2s-interface
14
-------------------------------------------------------------------------------
15
-- Copyright (c) 2002 
16
-------------------------------------------------------------------------------
17
-- Revisions  :
18
-- Date        Version  Author  Description
19
-- 2002-11-20  1.0      hse00044        Created
20
-------------------------------------------------------------------------------
21
library IEEE;
22
use IEEE.std_logic_1164.all;
23
use IEEE.numeric_std.all;
24
--use IEEE.std_logic_arith.all;
25
--use work.DffGlobal.all;
26
 
27
 
28
entity ParToI2s is
29
  generic (
30
    SampleSize_g : natural := 16);
31
  port (
32
    Clk_i           : in  std_ulogic;
33
    Reset_i         : in  std_ulogic;
34
    SampleLeft_i    : in  std_ulogic_vector(SampleSize_g - 1 downto 0);
35
    SampleRight_i   : in  std_ulogic_vector(SampleSize_g - 1 downto 0);
36
    StrobeLeft_i    : in  std_ulogic;
37
    StrobeRight_i   : in  std_ulogic;
38
    SampleAck_o     : out std_ulogic;
39
    WaitForSample_o : out std_ulogic;
40
    SClk_i          : in  std_ulogic;
41
    LRClk_i         : in  std_ulogic;
42
    SdnyData_o      : out std_ulogic);
43
end ParToI2s;
44
 
45
architecture rtl of ParToI2s is
46
 
47
  constant activated_cn   : std_ulogic := '0';
48
  constant inactivated_cn : std_ulogic := '1';
49
  constant activated_c   : std_ulogic := '1';
50
  constant inactivated_c : std_ulogic := '0';
51
  constant ResetActive_c : std_ulogic := '0';
52
 
53
  type   state_t is (IDLE, WAITSAMPLE, WAITLRCLK0, TRANSMITLEFT, WAITLRCLK1, TRANSMITRIGHT);
54
  signal state, nextstate           : state_t;
55
  signal sReg                       : std_ulogic_vector(SampleSize_g-1 downto 0);
56
  signal Cnt                        : std_ulogic_vector(4 downto 0);
57
  signal LeftSampleReg              : std_ulogic_vector(SampleSize_g - 1 downto 0);
58
  signal RightSampleReg, tempReg    : std_ulogic_vector(SampleSize_g - 1 downto 0);
59
  signal LRClkOld                   : std_ulogic;
60
  signal SClkOld                    : std_ulogic;
61
  signal Finished, loaded           : std_ulogic;
62
  signal LSampleValid, RSampleValid : std_ulogic;
63
 
64
 
65
begin  -- rtl
66
 
67
--  Finished <= '1' when Cnt = "11111" else '0';
68
    Finished <= '1' when Cnt = std_ulogic_vector(to_unsigned(SampleSize_g,Cnt'high+1)) else '0';
69
 
70
  -- purpose: Sequential state of the statemachine
71
  seq : process (Clk_i, Reset_i)
72
  begin  -- process seq
73
    if Reset_i = ResetActive_c then
74
      state <= IDLE;
75
    elsif Clk_i'event and Clk_i = '1' then
76
      state <= nextstate;
77
    end if;
78
  end process seq;
79
 
80
 
81
  Comb : process (state, LSampleValid, RSampleValid, LRClk_i, LRClkOld, Finished, SClkOld, SClk_i)
82
  begin  -- process Comb
83
    nextstate   <= state;
84
    SampleAck_o <= '0';
85
    WaitForSample_o <= '0';
86
    case state is
87
      when IDLE       => nextstate   <= WAITSAMPLE;
88
      when WAITSAMPLE => WaitForSample_o <= '1';
89
                         if (LSampleValid and RSampleValid) = '1' then
90
                           nextstate   <= WAITLRCLK0;
91
                         end if;
92
      when WAITLRCLK0 => if ((LRClk_i xor LRClkOld) and LRClkOld) = '1' then
93
                           nextstate <= TRANSMITLEFT;
94
                           SampleAck_o <= '1';
95
                         end if;
96
      when TRANSMITLEFT => if Finished = '1' and ((SClkOld xor SClk_i) and SCLKOld)='1' then
97
                             nextstate <= WAITLRCLK1;
98
                           end if;
99
      when WAITLRCLK1 => if ((LRClk_i xor LRClkOld) and LRClk_i) = '1' then
100
                           nextstate <= TRANSMITRIGHT;
101
                         end if;
102
      when TRANSMITRIGHT => if Finished = '1' and ((SClkOld xor SClk_i) and SCLKOld)='1' then
103
                              nextstate <= WAITSAMPLE;
104
                            end if;
105
      when others => null;
106
    end case;
107
  end process Comb;
108
 
109
  shiftreg : process (Clk_i, Reset_i)
110
  begin  -- process shiftreg
111
    if Reset_i = ResetActive_c then
112
      SdnyData_o     <= '0';
113
      sReg           <= (others => '0');
114
      Cnt            <= (others => '0');
115
      LRClkOld       <= '0';
116
      LeftSampleReg  <= (others => '0');
117
      RightSampleReg <= (others => '0');
118
      tempReg        <= (others => '0');
119
      LSampleValid   <= '0';
120
      RSampleValid   <= '0';
121
      loaded         <= '0';
122
      SClkOld        <= '0';
123
    elsif Clk_i'event and Clk_i = '1' then
124
      LRClkOld     <= LRClk_i;
125
      SClkOld      <= SClk_i;
126
      if StrobeLeft_i = '1' then
127
        LeftSampleReg <= SampleLeft_i;
128
        LSampleValid  <= '1';
129
--        sReg(SampleSize_g - 1 downto 0) <= SampleLeft_i;
130
      end if;
131
      if StrobeRight_i = '1' then
132
        RightSampleReg <= SampleRight_i;
133
        RSampleValid   <= '1';
134
      end if;
135
 
136
      case state is
137
        when WAITSAMPLE =>
138
          loaded <= '0';
139
 
140
        when WAITLRCLK0 =>
141
          -- ensure the regs are only loaded once
142
          SdnyData_o <= '0';
143
          if loaded = '0' then
144
            loaded  <= '1';
145
            sReg    <= LeftSampleReg;
146
            LSampleValid  <= '0';
147
            RSampleValid  <= '0';
148
            tempReg <= RightSampleReg;
149
            Cnt     <= (others => '0');
150
 
151
--             Cnt <=std_ulogic_vector(to_unsigned(1,Cnt'high+1));
152
--             SdnyData_o <= LeftSampleReg(SampleSize_g-1);
153
--             sReg       <= LeftSampleReg(SampleSize_g-2 downto 0)&"0";
154
          end if;
155
        when TRANSMITLEFT | TRANSMITRIGHT =>
156
          if Finished = '0' and ((SClk_i xor SClkOld) and SClkOld) = '1' then
157
            SdnyData_o <= sReg(SampleSize_g-1);
158
            sReg       <= sReg(SampleSize_g-2 downto 0)&"0";
159
            Cnt        <= std_ulogic_vector(unsigned(Cnt) + 1);
160
          end if;
161
 
162
        when WAITLRCLK1 =>
163
          SdnyData_o <= '0';
164
          sReg <= tempReg;
165
          Cnt  <= (others => '0');
166
 
167
--           Cnt <=std_ulogic_vector(to_unsigned(1,Cnt'high+1));
168
--           SdnyData_o <= tempReg(SampleSize_g-1);
169
--           sReg       <= tempReg(SampleSize_g-2 downto 0)&"0";
170
        when others => null;
171
      end case;
172
 
173
    end if;
174
  end process shiftreg;
175
 
176
 
177
end rtl;
178
 
179
 

powered by: WebSVN 2.1.0

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