-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcdda_fifo.v
107 lines (95 loc) · 2.5 KB
/
cdda_fifo.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
//
// cdda_fifo.v
//
// CDDA FIFO for the MiST board
// https://github.com/mist-devel
//
// Copyright (c) 2022 Gyorgy Szombathelyi
//
// This source file 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 3 of the License, or
// (at your option) any later version.
//
// This source file 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, see <http://www.gnu.org/licenses/>.
//
///////////////////////////////////////////////////////////////////////
module cdda_fifo
(
input clk_sys,
input clk_en, // set to 1 when using the stock data_io
input cen_44100, // 44100 HZ clock enable
input reset,
// data_io interface
output hdd_cdda_req,
input hdd_cdda_wr,
input [15:0] hdd_data_out,
// sample output
output reg [15:0] cdda_l,
output reg [15:0] cdda_r
);
// 4k x 16bit default FIFO size
parameter FIFO_DEPTH = 12;
reg [15:0] fifo[2**FIFO_DEPTH];
reg [FIFO_DEPTH-1:0] inptr;
reg [FIFO_DEPTH-1:0] outptr;
reg [15:0] fifo_out;
wire [FIFO_DEPTH:0] fifo_used = inptr >= outptr ?
inptr - outptr :
inptr - outptr + (2'd2**FIFO_DEPTH);
assign hdd_cdda_req = fifo_used < ((2'd2**FIFO_DEPTH) - 16'd2352);
always @(posedge clk_sys) begin
if (reset)
inptr <= 0;
else if (clk_en && hdd_cdda_wr) begin
fifo[inptr] <= {hdd_data_out[7:0], hdd_data_out[15:8]};
inptr <= inptr + 1'd1;
end
end
always @(posedge clk_sys) fifo_out <= fifo[outptr];
reg left = 0;
reg mute = 1;
reg fifo_active = 0;
always @(posedge clk_sys) begin
if (reset) begin
outptr <= 0;
fifo_active <= 0;
mute <= 1;
left <= 0;
cdda_l <= 0;
cdda_r <= 0;
end else begin
if (cen_44100) begin
if (fifo_used >= 2352)
fifo_active <= 1;
if (outptr + 2'd2 == inptr)
fifo_active <= 0;
if (fifo_active) begin
outptr <= outptr + 1'd1;
left <= 1;
mute <= 0;
end else
mute <= 1;
end
if (left) begin
outptr <= outptr + 1'd1;
left <= 0;
end
if (mute) begin
cdda_l <= 0;
cdda_r <= 0;
end else begin
if (left)
cdda_l <= fifo_out;
else
cdda_r <= fifo_out;
end
end
end
endmodule