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

Subversion Repositories z80control

[/] [z80control/] [trunk/] [CII_Starter_USB_API_v1/] [HW/] [I2C_AV_Config.v] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 tylerapohl
//Legal Notice: (C)2006 Altera Corporation. All rights reserved. Your
2
//use of Altera Corporation's design tools, logic functions and other
3
//software and tools, and its AMPP partner logic functions, and any
4
//output files any of the foregoing (including device programming or
5
//simulation files), and any associated documentation or information are
6
//expressly subject to the terms and conditions of the Altera Program
7
//License Subscription Agreement or other applicable license agreement,
8
//including, without limitation, that your use is for the sole purpose
9
//of programming logic devices manufactured by Altera and sold by Altera
10
//or its authorized distributors.  Please refer to the applicable
11
//agreement for further details.
12
 
13
module I2C_AV_Config (  //      Host Side
14
                                                iCLK,
15
                                                iRST_N,
16
                                                //      I2C Side
17
                                                I2C_SCLK,
18
                                                I2C_SDAT        );
19
//      Host Side
20
input           iCLK;
21
input           iRST_N;
22
//      I2C Side
23
output          I2C_SCLK;
24
inout           I2C_SDAT;
25
//      Internal Registers/Wires
26
reg     [15:0]   mI2C_CLK_DIV;
27
reg     [23:0]   mI2C_DATA;
28
reg                     mI2C_CTRL_CLK;
29
reg                     mI2C_GO;
30
wire            mI2C_END;
31
wire            mI2C_ACK;
32
reg     [15:0]   LUT_DATA;
33
reg     [3:0]    LUT_INDEX;
34
reg     [1:0]    mSetup_ST;
35
 
36
//      Clock Setting
37
parameter       CLK_Freq        =       50000000;       //      50      MHz
38
parameter       I2C_Freq        =       20000;          //      20      KHz
39
//      LUT Data Number
40
parameter       LUT_SIZE        =       11;
41
//      Audio Data Index
42
parameter       Dummy_DATA      =       0;
43
parameter       SET_LIN_L       =       1;
44
parameter       SET_LIN_R       =       2;
45
parameter       SET_HEAD_L      =       3;
46
parameter       SET_HEAD_R      =       4;
47
parameter       A_PATH_CTRL     =       5;
48
parameter       D_PATH_CTRL     =       6;
49
parameter       POWER_ON        =       7;
50
parameter       SET_FORMAT      =       8;
51
parameter       SAMPLE_CTRL     =       9;
52
parameter       SET_ACTIVE      =       10;
53
 
54
/////////////////////   I2C Control Clock       ////////////////////////
55
always@(posedge iCLK or negedge iRST_N)
56
begin
57
        if(!iRST_N)
58
        begin
59
                mI2C_CTRL_CLK   <=      0;
60
                mI2C_CLK_DIV    <=      0;
61
        end
62
        else
63
        begin
64
                if( mI2C_CLK_DIV        < (CLK_Freq/I2C_Freq) )
65
                mI2C_CLK_DIV    <=      mI2C_CLK_DIV+1;
66
                else
67
                begin
68
                        mI2C_CLK_DIV    <=      0;
69
                        mI2C_CTRL_CLK   <=      ~mI2C_CTRL_CLK;
70
                end
71
        end
72
end
73
////////////////////////////////////////////////////////////////////
74
I2C_Controller  u0      (       .CLOCK(mI2C_CTRL_CLK),          //      Controller Work Clock
75
                                                .I2C_SCLK(I2C_SCLK),            //      I2C CLOCK
76
                                                .I2C_SDAT(I2C_SDAT),            //      I2C DATA
77
                                                .I2C_DATA(mI2C_DATA),           //      DATA:[SLAVE_ADDR,SUB_ADDR,DATA]
78
                                                .GO(mI2C_GO),                           //      GO transfor
79
                                                .END(mI2C_END),                         //      END transfor 
80
                                                .ACK(mI2C_ACK),                         //      ACK
81
                                                .RESET(iRST_N)  );
82
////////////////////////////////////////////////////////////////////
83
//////////////////////  Config Control  ////////////////////////////
84
always@(posedge mI2C_CTRL_CLK or negedge iRST_N)
85
begin
86
        if(!iRST_N)
87
        begin
88
                LUT_INDEX       <=      0;
89
                mSetup_ST       <=      0;
90
                mI2C_GO         <=      0;
91
        end
92
        else
93
        begin
94
                if(LUT_INDEX<LUT_SIZE)
95
                begin
96
                        case(mSetup_ST)
97
                        0:       begin
98
                                        mI2C_DATA       <=      {8'h34,LUT_DATA};
99
                                        mI2C_GO         <=      1;
100
                                        mSetup_ST       <=      1;
101
                                end
102
                        1:      begin
103
                                        if(mI2C_END)
104
                                        begin
105
                                                if(!mI2C_ACK)
106
                                                mSetup_ST       <=      2;
107
                                                else
108
                                                mSetup_ST       <=      0;
109
                                                mI2C_GO         <=      0;
110
                                        end
111
                                end
112
                        2:      begin
113
                                        LUT_INDEX       <=      LUT_INDEX+1;
114
                                        mSetup_ST       <=      0;
115
                                end
116
                        endcase
117
                end
118
        end
119
end
120
////////////////////////////////////////////////////////////////////
121
/////////////////////   Config Data LUT   //////////////////////////    
122
always
123
begin
124
        case(LUT_INDEX)
125
        //      Audio Config Data
126
        Dummy_DATA      :       LUT_DATA        <=      16'h0000;
127
        SET_LIN_L       :       LUT_DATA        <=      16'h001A;
128
        SET_LIN_R       :       LUT_DATA        <=      16'h021A;
129
        SET_HEAD_L      :       LUT_DATA        <=      16'h047B;
130
        SET_HEAD_R      :       LUT_DATA        <=      16'h067B;
131
        A_PATH_CTRL     :       LUT_DATA        <=      16'h08F8;
132
        D_PATH_CTRL     :       LUT_DATA        <=      16'h0A06;
133
        POWER_ON        :       LUT_DATA        <=      16'h0C00;
134
        SET_FORMAT      :       LUT_DATA        <=      16'h0E01;
135
        SAMPLE_CTRL     :       LUT_DATA        <=      16'h1002;
136
        SET_ACTIVE      :       LUT_DATA        <=      16'h1201;
137
        default         :       LUT_DATA        <=      16'h0000;
138
        endcase
139
end
140
////////////////////////////////////////////////////////////////////
141
endmodule

powered by: WebSVN 2.1.0

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