-
Notifications
You must be signed in to change notification settings - Fork 0
/
audio_I2S.v
128 lines (101 loc) · 3.58 KB
/
audio_I2S.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// audio_I2S.v
//
// HPSDR - High Performance Software Defined Radio
//
// Angelia code.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// (C) Phil Harman VK6PH - 2014
/*
LRCLK ---------------+ +-----------------------------------------+
| | |
+-----------------------------------------+ +-----
BCLK --+ +--+ +--+ +--+ +--+ +--+ +--+ +--+ +--+ +--+ +--+ +--+ +--+ +--+ +--+ +--+ +--+ +--+
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+--+ +--+ +--+ +--+ +--+ + + +--+ +--+ + + +--+ +--+ +--+ + + +--+ +--+ + + +--+ +--
DIN --------------------+-----+-----+-- --+-----+-----+ -- ----+-----+-- --+-----+-----+-----+------
(data bit) | 31 | 30 | // | 17 | 16 | 15 // | 15 | 14 | | 1 | 0 |
--------------------+-----+-----+-- --+-----+-----+ -- ----+-----+-----+-- --+-----+-----+------
<----------- left channel ---------------><----------- right channel -------------->
+-----+ +-----+
| | | |
get_data ---------+ +-----------------------------------------------------------------------------+ +-----------------
TLV320 is in slave, I2S mode.
NOTE: BCLK in PLL_IF is set at 180 degrees so that LRCLK changes on negative edge to comply with I2S format
*/
//
module audio_I2S
(
input [31:0]data_in,
input empty,
input BCLK,
input LRCLK,
output get_data,
output reg data_out
);
reg [4:0] state;
reg [4:0] data_count;
reg shift = 0;
always @ (posedge BCLK)
begin
if(!empty) // only run code if fifo has data available
begin
case (state)
0: begin
if (LRCLK) state <= 1; // loop until LRCLK is high
end
1: begin
if (!LRCLK) begin // loop until LRCLK is low
shift <= 1;
data_count <= 5'd31;
state <= 2;
end
end
2: begin
if (data_count == 16) begin
shift <= 0;
if(LRCLK) begin
data_count <= 15;
shift <= 1;
state <= 3;
end
end
else begin
data_count <= data_count - 5'd1;
end
end
3: begin
if (data_count == 0) begin
shift <= 0;
state <= 0;
end
else data_count <= data_count - 5'd1;
end
default: state <= 0;
endcase
end
end
// clock data out on negedge of BCLK so it can be read on postive edge by TLV320
// request data just before falling edge of LRCLK
reg [5:0] get_count;
always @ (negedge BCLK)
begin
if (shift) data_out <= data_in[data_count];
else data_out <= 0;
if (!LRCLK) get_count <= 0;
else get_count <= get_count + 6'd1;
end
assign get_data = (get_count == 6'd30); // & !empty); // only request data if fifo is not empty
endmodule