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

Subversion Repositories aic1106_avalon_ip

[/] [aic1106_avalon_ip/] [trunk/] [AIC1106_PCM.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 AlexO
module AIC1106_PCM(
2
        // Avalon clock 
3
        csi_avalon_clk,
4
        csi_reset,
5
 
6
        // Avalon stream audio clock 2.048 MHz
7
        csi_audio_clk,
8
 
9
         // Control/status reg Avalon slave
10
                avs_creg_address,
11
                avs_creg_chipselect,
12
                avs_creg_write,
13
                avs_creg_read,
14
                avs_creg_writedata,
15
                avs_creg_readdata,
16
 
17
         // Avalon stream sink
18
        asi_data,
19
        asi_valid,
20
        asi_ready,
21
 
22
         // Avalon stream source
23
        aso_data,
24
        aso_valid,
25
 
26
                        // TLV320AIC1106 signal
27
        coe_mclk,
28
        coe_pcmsyn,
29
        coe_pcmi,
30
        coe_pcmo,
31
        coe_reset_n,
32
        coe_mute,
33
        coe_linsel   // always 0 (linear mode)
34
         );
35
 
36
input                   csi_avalon_clk;
37
input                   csi_reset;
38
 
39
input                   csi_audio_clk;
40
 
41
output   [ 31:0]        avs_creg_readdata;
42
input    [  1:0]        avs_creg_address;
43
input                   avs_creg_chipselect;
44
input                   avs_creg_read;
45
input                   avs_creg_write;
46
input    [ 31:0]        avs_creg_writedata;
47
 
48
input    [ 31:0]        asi_data;
49
input                   asi_valid;
50
output                  asi_ready;
51
 
52
output                  aso_valid;
53
output   [31:0]         aso_data;
54
 
55
output                  coe_mclk;
56
output                  coe_pcmsyn;
57
output                  coe_pcmi;
58
input                   coe_pcmo;
59
output                  coe_reset_n;
60
output                  coe_mute;
61
output   wire           coe_linsel = 1'b0;  // linear mode
62
 
63
reg                     enable_r;
64
reg                     loopback_r;
65
reg                     reset_req_r;
66
reg                     pcmsyn_r;
67
reg                     mute_r;
68
reg                     underflow_r;
69
reg      [31:0]         tx_latch_r;
70
reg      [31:0]         rx_latch_r;
71
reg      [15:0]         tx_shft_r;
72
reg      [15:0]         rx_shft_r;
73
reg      [2:0]          volume_r;
74
reg                     asi_ready_r;
75
reg                     aso_valid_r;
76
reg                                             reset_r;
77
reg      [8:0]          main_cnt;
78
 
79
wire                    asi_ready = asi_ready_r;
80
 
81
wire                    aso_valid = aso_valid_r;
82
assign                  aso_data[31:0] = rx_latch_r[31:0];
83
 
84
wire                    coe_mclk = csi_audio_clk & enable_r;
85
wire                    coe_pcmsyn = pcmsyn_r & enable_r;
86
wire                    coe_pcmi = tx_shft_r[15] & enable_r;
87
wire                    coe_mute = mute_r;
88
wire                    coe_reset_n = reset_r;//~(reset_req_r | csi_reset); 
89
 
90
wire                    rx_shft_in = (loopback_r)?(coe_pcmi):(coe_pcmo);
91
 
92
assign                  avs_creg_readdata = (avs_creg_address[1:0] == 2'h0)?(state):(0);
93
wire     [31:0]         state = {25'b0, underflow_r, coe_mute, ~coe_reset_n, 1'b0, volume_r[2:0]};
94
wire                    creg_reg_sel_w      = avs_creg_write & avs_creg_chipselect & (avs_creg_address[1:0] == 2'h0);
95
 
96
// NIOS control interface
97
always @(posedge csi_avalon_clk or posedge csi_reset)
98
begin
99
  if (csi_reset)
100
  begin
101
     reset_req_r <= 0;
102
     mute_r <= 0;
103
     volume_r[2:0] <= 1;  // 0 db gain
104
     loopback_r <= 0;
105
         enable_r <= 0;
106
  end
107
  else if (creg_reg_sel_w)
108
  begin
109
     volume_r[2:0] <= avs_creg_writedata[2:0];
110
     mute_r        <= avs_creg_writedata[3];
111
         enable_r      <= avs_creg_writedata[4];
112
     loopback_r    <= avs_creg_writedata[5];
113
     reset_req_r   <= avs_creg_writedata[6];
114
  end
115
end
116
 
117
// PCM state decoder
118
wire     fs_avalon_rdy_on   = (main_cnt == 9'd0);
119
wire     fs_avalon_rdy_off  = (main_cnt == 9'd1);
120
wire     fs_txlatch         = (main_cnt == 9'd2);
121
wire     fs_pcmsyn1_on      = (main_cnt == 9'd3);
122
wire     fs_pcmsyn1_off     = (main_cnt == 9'd4);
123
wire     fs_shift1          = ((main_cnt > 9'd4) && (main_cnt <= 9'd20));
124
wire     fs_rxlatch1        = (main_cnt == 9'd21);//21
125
wire     fs_pcmsyn2_on      = (main_cnt == 9'd259);
126
wire     fs_pcmsyn2_off     = (main_cnt == 9'd260);
127
wire     fs_shift2          = ((main_cnt > 9'd260) && (main_cnt <= 9'd276));
128
wire     fs_rxlatch2        = (main_cnt == 9'd277);//277
129
wire     fs_rxvalid_off     = (main_cnt == 9'd278);
130
 
131
 
132
// PCM receive shift register; clocked by negedge
133
always @(negedge csi_audio_clk or posedge reset_req_r)
134
begin
135
   if (reset_req_r)
136
   begin
137
      rx_shft_r <= 0;
138
   end
139
   else begin
140
      if (fs_shift1 || fs_shift2)
141
      begin
142
         rx_shft_r[15:0] <= {rx_shft_r[14:0], rx_shft_in};
143
      end
144
   end
145
end
146
 
147
// PCM receive path and AVALON stream source logic
148
always @(posedge csi_audio_clk or posedge reset_req_r)
149
begin
150
   if (reset_req_r)
151
   begin
152
      rx_latch_r <= 0;
153
      aso_valid_r <= 0;
154
   end
155
   else begin
156
      if (fs_rxlatch1)
157
      begin
158
         rx_latch_r[15:0] <= rx_shft_r[15:0];
159
      end
160
      else if (fs_rxlatch2)
161
      begin
162
         rx_latch_r[31:16] <= rx_shft_r[15:0];
163
         aso_valid_r <= 1;
164
      end
165
      else if (fs_rxvalid_off)
166
      begin
167
         aso_valid_r <= 0;
168
      end
169
   end
170
end
171
 
172
// PCM transmit path and AVALON stream sink logic
173
always @(posedge csi_audio_clk or posedge reset_req_r)
174
begin
175
   if (reset_req_r)
176
   begin
177
      main_cnt <= 0;
178
      underflow_r <= 0;
179
      asi_ready_r <= 0;
180
      pcmsyn_r <= 0;
181
   end
182
   else begin
183
      main_cnt <= main_cnt + 1'b1;
184
      if (fs_avalon_rdy_on)
185
      begin
186
         asi_ready_r <= 1;
187
      end
188
      else if (fs_avalon_rdy_off)
189
      begin
190
         asi_ready_r <= 0;
191
      end
192
      else if (fs_txlatch)
193
      begin
194
         if (asi_valid)
195
         begin
196
            tx_latch_r[31:0] <= asi_data[31:0];
197
         end
198
         else begin
199
            underflow_r <= 1;
200
            tx_latch_r[31:0] <= 0;
201
         end
202
      end
203
      else if (fs_pcmsyn1_on)
204
      begin
205
         pcmsyn_r <= 1;
206
         tx_shft_r[15:0] <= {tx_latch_r[12:0], volume_r[2:0]}; //!!
207
      end
208
      else if (fs_pcmsyn1_off)
209
      begin
210
         pcmsyn_r <= 0;
211
      end
212
      else if (fs_shift1)
213
      begin
214
         tx_shft_r[15:0] <= {tx_shft_r[14:0], 1'b0};
215
      end
216
      else if (fs_pcmsyn2_on)
217
      begin
218
         pcmsyn_r <= 1;
219
         tx_shft_r[15:0] <= {tx_latch_r[28:16], volume_r[2:0]};   //!!
220
      end
221
      else if (fs_pcmsyn2_off)
222
      begin
223
         pcmsyn_r <= 0;
224
      end
225
      else if (fs_shift2)
226
      begin
227
         tx_shft_r[15:0] <= {tx_shft_r[14:0], 1'b0};
228
      end
229
   end
230
end
231
 
232
// resync reset to csi_audio_clk
233
always @(posedge csi_audio_clk)
234
begin
235
        reset_r <= ~(reset_req_r | csi_reset);
236
end
237
 
238
endmodule
239
 
240
 

powered by: WebSVN 2.1.0

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