1 | --
|
---|
2 | -- VHDL Architecture FACT_FAD_lib.spi_distributor.beha
|
---|
3 | --
|
---|
4 | -- Created:
|
---|
5 | -- by - Benjamin Krumm.UNKNOWN (EEPC8)
|
---|
6 | -- at - 09:24:21 23.04.2010
|
---|
7 | --
|
---|
8 | -- using Mentor Graphics HDL Designer(TM) 2009.1 (Build 12)
|
---|
9 | --
|
---|
10 | LIBRARY ieee;
|
---|
11 | USE ieee.std_logic_1164.all;
|
---|
12 | USE ieee.std_logic_arith.all;
|
---|
13 | USE ieee.std_logic_unsigned.all;
|
---|
14 | LIBRARY FACT_FAD_lib;
|
---|
15 | USE FACT_FAD_lib.fad_definitions.all;
|
---|
16 |
|
---|
17 | ENTITY spi_distributor IS
|
---|
18 | GENERIC(
|
---|
19 | CLK_DIVIDER : integer := 10**6
|
---|
20 | );
|
---|
21 | PORT(
|
---|
22 | clk : IN std_logic;
|
---|
23 | config_start : IN std_logic;
|
---|
24 | config_ready, config_started : OUT std_logic := '0';
|
---|
25 | sensor_valid : OUT std_logic := '0';
|
---|
26 | dac_array : IN dac_array_type;
|
---|
27 | sensor_array : OUT sensor_array_type;
|
---|
28 | dac_config_start : OUT std_logic := '0';
|
---|
29 | dac_config_ready : IN std_logic;
|
---|
30 | sensor_read_start : OUT std_logic := '0';
|
---|
31 | sensor_read_valid : IN std_logic;
|
---|
32 | dac_id : OUT std_logic_vector(2 downto 0) := (others => '0');
|
---|
33 | sensor_id : OUT std_logic_vector(1 downto 0) := (others => '0');
|
---|
34 | data : INOUT std_logic_vector(15 downto 0) := (others => 'Z')
|
---|
35 | );
|
---|
36 | END ENTITY spi_distributor;
|
---|
37 |
|
---|
38 | ARCHITECTURE beha OF spi_distributor IS
|
---|
39 |
|
---|
40 | type TYPE_SPI_DISTRIBUTION_STATE is (INIT, IDLE, READ_SENSOR, CONFIG_DAC);
|
---|
41 |
|
---|
42 | signal spi_distr_state : TYPE_SPI_DISTRIBUTION_STATE := INIT;
|
---|
43 | signal int_sensor_read_start : std_logic := '0';
|
---|
44 | signal int_sensor_valid : std_logic := '0';
|
---|
45 | signal int_sensor_array : sensor_array_type;
|
---|
46 | signal sensor_id_cnt : integer range 0 to 4 := 0;
|
---|
47 | signal dac_id_cnt : integer range 0 to 7 := 0;
|
---|
48 |
|
---|
49 |
|
---|
50 | BEGIN
|
---|
51 |
|
---|
52 | spi_distribute_proc: process (clk)
|
---|
53 | begin
|
---|
54 |
|
---|
55 | if rising_edge(clk) then
|
---|
56 | data <= (others => 'Z');
|
---|
57 | case spi_distr_state is
|
---|
58 | when INIT =>
|
---|
59 | data <= (others => 'Z');
|
---|
60 | int_sensor_valid <= '0';
|
---|
61 | spi_distr_state <= READ_SENSOR;
|
---|
62 | when IDLE =>
|
---|
63 | if (int_sensor_valid = '1') then
|
---|
64 | sensor_array <= int_sensor_array;
|
---|
65 | sensor_valid <= '1';
|
---|
66 | end if;
|
---|
67 | data <= (others => 'Z');
|
---|
68 | -- start DAC configuration
|
---|
69 | if (config_start = '1' AND int_sensor_valid = '1') then
|
---|
70 | config_started <= '1';
|
---|
71 | config_ready <= '0';
|
---|
72 | dac_config_start <= '1';
|
---|
73 | dac_id <= conv_std_logic_vector(dac_id_cnt, dac_id'length);
|
---|
74 | data <= conv_std_logic_vector(dac_array(dac_id_cnt),data'length);
|
---|
75 | spi_distr_state <= CONFIG_DAC;
|
---|
76 | -- start temperature sensor reading
|
---|
77 | elsif (dac_config_ready <= '1' AND int_sensor_read_start = '1') then
|
---|
78 | int_sensor_valid <= '0';
|
---|
79 | sensor_read_start <= '1';
|
---|
80 | sensor_id <= conv_std_logic_vector(sensor_id_cnt, sensor_id'length);
|
---|
81 | spi_distr_state <= READ_SENSOR;
|
---|
82 | end if;
|
---|
83 |
|
---|
84 | -- sensor reading
|
---|
85 | when READ_SENSOR =>
|
---|
86 | sensor_read_start <= '1';
|
---|
87 | sensor_id <= conv_std_logic_vector(sensor_id_cnt, sensor_id'length);
|
---|
88 | if (sensor_read_valid = '1') then
|
---|
89 | int_sensor_array(sensor_id_cnt) <= conv_integer(data);
|
---|
90 | sensor_read_start <= '0';
|
---|
91 | if (sensor_id_cnt < 3) then
|
---|
92 | sensor_id_cnt <= sensor_id_cnt + 1;
|
---|
93 | sensor_read_start <= '1';
|
---|
94 | spi_distr_state <= READ_SENSOR;
|
---|
95 | else
|
---|
96 | sensor_id_cnt <= 0;
|
---|
97 | sensor_valid <= '0';
|
---|
98 | int_sensor_valid <= '1';
|
---|
99 | spi_distr_state <= IDLE;
|
---|
100 | end if;
|
---|
101 | end if;
|
---|
102 |
|
---|
103 | -- DAC configuration
|
---|
104 | when CONFIG_DAC =>
|
---|
105 | dac_config_start <= '1';
|
---|
106 | dac_id <= conv_std_logic_vector(dac_id_cnt, dac_id'length);
|
---|
107 | data <= conv_std_logic_vector(dac_array(dac_id_cnt),data'length);
|
---|
108 | if (dac_config_ready = '1') then
|
---|
109 | dac_config_start <= '0';
|
---|
110 | if (dac_id_cnt < 7) then
|
---|
111 | dac_id_cnt <= dac_id_cnt + 1;
|
---|
112 | dac_config_start <= '1';
|
---|
113 | spi_distr_state <= CONFIG_DAC;
|
---|
114 | else
|
---|
115 | dac_id_cnt <= 0;
|
---|
116 | config_started <= '0';
|
---|
117 | config_ready <= '1';
|
---|
118 | spi_distr_state <= IDLE;
|
---|
119 | end if;
|
---|
120 | end if;
|
---|
121 | end case;
|
---|
122 | end if;
|
---|
123 |
|
---|
124 | end process spi_distribute_proc;
|
---|
125 |
|
---|
126 | sensor_tmr_proc: process (clk)
|
---|
127 | variable Z: integer range 0 to (CLK_DIVIDER - 1);
|
---|
128 | begin
|
---|
129 | if rising_edge(clk) then
|
---|
130 | int_sensor_read_start <= '0';
|
---|
131 | if (Z < CLK_DIVIDER - 1) then
|
---|
132 | Z := Z + 1;
|
---|
133 | else
|
---|
134 | Z := 0;
|
---|
135 | end if;
|
---|
136 | if (Z = 0) then
|
---|
137 | int_sensor_read_start <= '1';
|
---|
138 | end if;
|
---|
139 | end if;
|
---|
140 | end process sensor_tmr_proc;
|
---|
141 |
|
---|
142 |
|
---|
143 | END ARCHITECTURE beha;
|
---|
144 |
|
---|