diff options
Diffstat (limited to 'FPGA/vhdl/codec_config.vhd')
-rw-r--r-- | FPGA/vhdl/codec_config.vhd | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/FPGA/vhdl/codec_config.vhd b/FPGA/vhdl/codec_config.vhd new file mode 100644 index 0000000..2ae71f8 --- /dev/null +++ b/FPGA/vhdl/codec_config.vhd | |||
@@ -0,0 +1,92 @@ | |||
1 | library ieee; | ||
2 | use ieee.std_logic_1164.all; | ||
3 | use ieee.numeric_std.all; | ||
4 | |||
5 | entity codec_config is | ||
6 | generic ( | ||
7 | system_frequency : real := 50.0E6; -- 50 MHz | ||
8 | i2c_rate : real := 20.0E3 -- 20 kHz | ||
9 | ); | ||
10 | port ( | ||
11 | clk : in std_logic; | ||
12 | resetn : in std_logic; | ||
13 | end_config : out std_logic; | ||
14 | i2c_scl : out std_logic; | ||
15 | i2c_sda : inout std_logic | ||
16 | ); | ||
17 | end entity; | ||
18 | |||
19 | architecture rtl of codec_config is | ||
20 | type t_config is array(natural range 0 to 10) of std_logic_vector(23 downto 0); | ||
21 | constant config_data : t_config := | ||
22 | (X"34001A", | ||
23 | X"34021A", | ||
24 | X"34047B", | ||
25 | X"34067B", | ||
26 | X"3408F8", | ||
27 | X"340A06", | ||
28 | X"340C00", | ||
29 | X"340E01", | ||
30 | X"341002", | ||
31 | X"341201", | ||
32 | X"000000" | ||
33 | ); | ||
34 | type state is (init, config, finished); | ||
35 | signal i2c_data : std_logic_vector(23 downto 0); | ||
36 | signal i2c_go : std_logic; | ||
37 | signal i2c_ack : std_logic; | ||
38 | signal i2c_ready : std_logic; | ||
39 | signal ctr_data : natural range 0 to 10; | ||
40 | signal current_state : state; | ||
41 | |||
42 | begin | ||
43 | |||
44 | i2c_data <= config_data(ctr_data); | ||
45 | |||
46 | process(resetn, clk) is | ||
47 | begin | ||
48 | if resetn = '0' then | ||
49 | ctr_data <= 0; | ||
50 | current_state <= init; | ||
51 | i2c_go <= '0'; | ||
52 | end_config <= '0'; | ||
53 | elsif rising_edge(clk) then | ||
54 | case current_state is | ||
55 | when init => i2c_go <= '1'; | ||
56 | if i2c_ready = '0' then | ||
57 | current_state <= config; | ||
58 | ctr_data <= ctr_data+1; | ||
59 | end if; | ||
60 | |||
61 | when config => i2c_go <= '0'; | ||
62 | if i2c_ready = '1' then | ||
63 | if ctr_data<10 then | ||
64 | current_state <= init; | ||
65 | else | ||
66 | current_state <= finished; | ||
67 | end if; | ||
68 | end if; | ||
69 | when finished => end_config <= '1'; | ||
70 | i2c_go <= '0'; | ||
71 | end case; | ||
72 | |||
73 | end if; | ||
74 | end process; | ||
75 | |||
76 | |||
77 | i2c_ctrl : entity work.i2C_master | ||
78 | generic map ( | ||
79 | system_frequency => system_frequency, | ||
80 | i2c_rate => i2c_rate | ||
81 | ) | ||
82 | port map ( | ||
83 | clk => clk, | ||
84 | resetn => resetn, | ||
85 | go => i2c_go, | ||
86 | ready => i2c_ready, | ||
87 | data_in => i2c_data, | ||
88 | i2c_scl => i2c_scl, | ||
89 | i2c_sda => i2c_sda, | ||
90 | ack => i2c_ack | ||
91 | ); | ||
92 | end architecture; \ No newline at end of file | ||