Ik ben bezich met een driver te schrijven voor een LM4550 (op een virtex 4, ml403 dev-board).
Het probleem waarmee ik nu zit is dat in de slot 3 (ADC_l) bijna alleen maar rommel zit. Onregelmatig worden alle bits in dat slot hoog. Dit is zowel als er audio aangesloten is, dan wel als er niets aangesloten zit.
Daarnaast zijn de laagste 4 bits van slot 3 en slot 4 altijd hoog (ADC-L en ADC-R). Ook als er audio op de line-in gezet wordt komt deze niet uit de ADC, terwijl deze wel uit de analoge loopback uit de line-out komt.
Dit is wat ik tot nu toe heb
///////////////////////////////////////////////////////////////////////////////
//
// bi-directional monaural interface to AC97
//
///////////////////////////////////////////////////////////////////////////////
module pheriperal_AC97 (clk, reset, ADC, DAC, ready, reset_b, sdata_out, sdata_in, synch, bit_clk);
input clk;
input reset;
output [19:0] ADC;
input [19:0] DAC;
output ready;
//ac97 interface signals
output reset_b;
output sdata_out;
input sdata_in;
output synch;
input bit_clk;
wire [7:0] command_address;
wire [15:0] command_data;
wire command_valid;
wire [19:0] ADC_L, ADC_R;
wire [19:0] DAC_L, DAC_R;
reg reset_b;
reg [9:0] reset_count;
initial reset_count = 0;
initial reset_b = 1'b0;
//wait a little before enabling the AC97 codec
always @(posedge clk) begin
if (reset) begin
reset_b = 1'b0;
reset_count = 0;
end else if (reset_count == 1023)
reset_b = 1'b1;
else
reset_count = reset_count+1;
end
ac97 ac97(ready, command_address, command_data,
command_valid, DAC_L, 1'b1, DAC_R, 1'b1, ADC_L, ADC_R,
sdata_out, sdata_in, synch, bit_clk);
ac97commands ac97commands(clk, ready, command_address, command_data, command_valid);
// assign DAC_L = {DAC, 12'b000000000000};
assign DAC_L = DAC;
assign DAC_R = DAC_L;
//arbitrarily choose left input
// assign ADC = ADC_L[19:12];
assign ADC = ADC_L;
endmodule
// assemble/disassemble AC97 serial frames
module ac97 (ready,
command_address, command_data, command_valid,
DAC_L, DAC_L_valid,
DAC_R, DAC_R_valid,
ADC_L, ADC_R,
sdata_out, sdata_in, synch, bit_clk);
output ready;
input [7:0] command_address;
input [15:0] command_data;
input command_valid;
input [19:0] DAC_L, DAC_R;
input DAC_L_valid, DAC_R_valid;
output [19:0] ADC_L, ADC_R;
input sdata_in;
input bit_clk;
output sdata_out;
output synch;
reg ready;
reg sdata_out;
reg synch;
reg [7:0] bit_count;
reg [19:0] l_cmd_addr;
reg [19:0] l_cmd_data;
reg [19:0] l_DAC_L, l_DAC_R;
reg l_cmd_v, l_left_v, l_right_v;
reg [19:0] ADC_L, ADC_R;
initial begin
ready <= 1'b0;
// syntheses attribute init of ready is "0";
sdata_out <= 1'b0;
// syntheses attribute init of sdata_out is "0";
synch <= 1'b0;
// syntheses attribute init of synch is "0";
bit_count <= 8'h00;
// syntheses attribute init of bit_count is "0000";
l_cmd_v <= 1'b0;
// syntheses attribute init of l_cmd_v is "0";
l_left_v <= 1'b0;
// syntheses attribute init of l_left_v is "0";
l_right_v <= 1'b0;
// syntheses attribute init of l_right_v is "0";
ADC_L <= 20'h00000;
// syntheses attribute init of ADC_L is "00000";
ADC_R <= 20'h00000;
// syntheses attribute init of ADC_R is "00000";
end
always @(posedge bit_clk) begin
// Generate the sync signal
if (bit_count == 255)
synch <= 1'b1;
if (bit_count == 15)
synch <= 1'b0;
// Generate the ready signal
if (bit_count == 128)
ready <= 1'b1;
if (bit_count == 2)
ready <= 1'b0;
// Latch user data at the end of each frame. This ensures that the
// first frame after reset will be empty.
if (bit_count == 255)
begin
l_cmd_addr <= {command_address, 12'h000};
l_cmd_data <= {command_data, 4'h0};
l_cmd_v <= command_valid;
l_DAC_L <= DAC_L;
l_left_v <= DAC_L_valid;
l_DAC_R <= DAC_R;
l_right_v <= DAC_R_valid;
end
if ((bit_count >= 0) && (bit_count <= 15))
// Slot 0: Tags
case (bit_count[3:0])
4'h0: sdata_out <= 1'b1; // Frame valid
4'h1: sdata_out <= l_cmd_v; // Command address valid
4'h2: sdata_out <= l_cmd_v; // Command data valid
4'h3: sdata_out <= l_left_v; // Left data valid
4'h4: sdata_out <= l_right_v; // Right data valid
default: sdata_out <= 1'b0;
endcase
else if ((bit_count >= 16) && (bit_count <= 35))
// Slot 1: Command address (8-bits, left justified)
sdata_out <= l_cmd_v ? l_cmd_addr[35-bit_count] : 1'b0;
else if ((bit_count >= 36) && (bit_count <= 55))
// Slot 2: Command data (16-bits, left justified)
sdata_out <= l_cmd_v ? l_cmd_data[55-bit_count] : 1'b0;
else if ((bit_count >= 56) && (bit_count <= 75))
begin
// Slot 3: Left channel
sdata_out <= l_left_v ? l_DAC_L[19] : 1'b0;
l_DAC_L <= { l_DAC_L[18:0], l_DAC_L[19] };
end
else if ((bit_count >= 76) && (bit_count <= 95))
// Slot 4: Right channel
sdata_out <= l_right_v ? l_DAC_R[95-bit_count] : 1'b0;
else
sdata_out <= 1'b0;
bit_count <= bit_count+1;
end // always @ (posedge bit_clk)
always @(negedge bit_clk) begin
if ((bit_count >= 57) && (bit_count <= 76))
// Slot 3: Left channel
ADC_L <= { ADC_L[18:0], sdata_in };
else if ((bit_count >= 77) && (bit_count <= 96))
// Slot 4: Right channel
ADC_R <= { ADC_R[18:0], sdata_in };
end
endmodule
// issue initialization commands to AC97
module ac97commands (clk, ready, command_address, command_data, command_valid);
input clk;
input ready;
output [7:0] command_address;
output [15:0] command_data;
output command_valid;
reg [23:0] command;
reg command_valid;
reg old_ready;
reg done;
reg [3:0] state;
initial begin
command <= 4'h0;
// syntheses attribute init of command is "0";
command_valid <= 1'b0;
// syntheses attribute init of command_valid is "0";
done <= 1'b0;
// syntheses attribute init of done is "0";
old_ready <= 1'b0;
// syntheses attribute init of old_ready is "0";
state <= 16'h0000;
// syntheses attribute init of state is "0000";
end
assign command_address = command[23:16];
assign command_data = command[15:0];
always @(posedge clk) begin
if (ready && (!old_ready) && state < 3)
state <= state+1;
case (state)
4'h0: command = 24'h02_0000; // Unmute line outputs
4'h1: command = 24'h04_0000; // Unmute headphones
4'h2: command = 24'h10_0808; // Unmute line inputs
4'h3: command = 24'h1A_0404; // select line-in
4'h4: command = 24'h1C_0000; // Record gain +0dB
default: command = 24'hFC_0000; // Read vendor ID
/* 4'h0: // Read ID
begin
command <= 24'h80_0000;
command_valid <= 1'b1;
end
4'h1: // Read ID
command <= 24'h80_0000;
4'h3: // headphone volume
command <= { 8'h04, 3'b000, 3'b111, 3'b000, 3'b111 };
4'h5: // PCM volume
command <= 24'h18_0808;
4'h6: // Record source select
command <= 24'h1A_0404; // microphone
4'h7: // Record gain = max
command <= 24'h1C_0F0F;
4'h9: // set +20db mic gain
command <= 24'h0E_8048;
4'hA: // Set beep volume
command <= 24'h0A_0000;
4'hB: // PCM out bypass mix1
command <= 24'h20_8000;
default:
command <= 24'h80_0000;*/
endcase // case(state)
old_ready <= ready;
end // always @ (posedge clk)
endmodule // ac97commands