Debian Codegraph @

hdl/fpga/ip/nuand/synthesis/bladerf_rfic_spi_ctrl.vhd

raw
1 -- RFIC SPI Control
2 -- Copyright (c) 2020 Nuand LLC
3 --
4 -- Permission is hereby granted, free of charge, to any person obtaining a copy
5 -- of this software and associated documentation files (the "Software"), to deal
6 -- in the Software without restriction, including without limitation the rights
7 -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 -- copies of the Software, and to permit persons to whom the Software is
9 -- furnished to do so, subject to the following conditions:
10 --
11 -- The above copyright notice and this permission notice shall be included in
12 -- all copies or substantial portions of the Software.
13 --
14 -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 -- THE SOFTWARE.
21
22 library ieee;
23 use ieee.std_logic_1164.all;
24 use ieee.numeric_std.all;
25
26 entity bladerf_rfic_spi_ctrl is
27 generic(
28 CLOCK_DIV : positive range 2 to 16 := 2;
29 ADDR_WIDTH : positive := 16;
30 DATA_WIDTH : positive := 8
31 );
32 port (
33 -- Physical Interface
34 sclk : out std_logic;
35 miso : in std_logic;
36 mosi : out std_logic;
37 cs_n : out std_logic;
38
39 arbiter_req : out std_logic;
40 arbiter_grant : in std_logic;
41 arbiter_done : out std_logic;
42
43 -- Control Interface
44 clock : in std_logic;
45 reset : in std_logic;
46 tx_ota_req : in std_logic
47 );
48 end entity; -- pll_reset
49
50 architecture arch of bladerf_rfic_spi_ctrl is
51 type fsm_t is (
52 INIT,
53 GET_ARBITER,
54 WAIT_END_TX,
55 RELEASE_ARBITER,
56 WAIT_TO_WR,
57 WAIT_WR_DVALID,
58 WAIT_WR_DVALID_2,
59 WAIT_RD_DVALID,
60 WAIT_RD_DVALID_2
61 );
62
63 type state_t is record
64 state : fsm_t;
65 n_state : fsm_t;
66 mm_read : std_logic;
67 mm_write : std_logic;
68 mm_addr : std_logic_vector(ADDR_WIDTH-1 downto 0);
69 mm_din : std_logic_vector(DATA_WIDTH-1 downto 0);
70 mm_dout : std_logic_vector(DATA_WIDTH-1 downto 0);
71 counter : natural range 0 to 50000;
72 arbiter_req : std_logic;
73 arbiter_done : std_logic;
74 end record;
75
76 constant reset_value : state_t := (
77 state => INIT,
78 n_state => INIT,
79 mm_read => '0',
80 mm_write => '0',
81 mm_addr => ( others => '0' ),
82 mm_din => ( others => '0' ),
83 mm_dout => ( others => '0' ),
84 counter => 0,
85 arbiter_req => '0',
86 arbiter_done => '0'
87 );
88
89 signal current : state_t := reset_value;
90 signal future : state_t := reset_value;
91
92 signal mm_dout : std_logic_vector(DATA_WIDTH-1 downto 0);
93 signal mm_dvalid : std_logic ;
94 signal mm_busy : std_logic ;
95
96 begin
97 arbiter_req <= current.arbiter_req;
98 arbiter_done <= current.arbiter_done;
99
100 U_rfic_spi: entity work.rfic_spi_controller
101 port map(
102 -- Physical Interface
103 sclk => sclk,
104 miso => miso,
105 mosi => mosi,
106 cs_n => cs_n,
107
108 -- Avalon-MM Interface
109 mm_clock => clock,
110 mm_reset => reset,
111 mm_read => current.mm_read,
112 mm_write => current.mm_write,
113 mm_addr => current.mm_addr,
114 mm_din => current.mm_din,
115 mm_dout => mm_dout,
116 mm_dout_val => mm_dvalid,
117 mm_busy => mm_busy
118 );
119
120 sync_proc : process(clock)
121 begin
122 if(reset = '1') then
123 current <= reset_value;
124 elsif(rising_edge(clock)) then
125 current <= future;
126 end if;
127 end process sync_proc;
128
129 comb_proc : process(all)
130 begin
131 -- defaults
132 future <= current;
133 future.mm_read <= '0';
134 future.mm_write <= '0';
135
136 future.arbiter_req <= '0';
137 future.arbiter_done <= '0';
138
139 -- states
140 case current.state is
141 when INIT =>
142 if( tx_ota_req = '1' ) then
143 future.arbiter_req <= '1';
144 future.state <= GET_ARBITER;
145 end if;
146
147 when GET_ARBITER =>
148 future.arbiter_req <= '1';
149 if( arbiter_grant = '1' ) then
150 future.state <= WAIT_WR_DVALID;
151 future.n_state <= WAIT_END_TX;
152
153 future.mm_addr <= x"0051";
154 future.mm_din <= x"00";
155 future.mm_write <= '1';
156 end if;
157
158 when WAIT_END_TX =>
159 if( tx_ota_req = '0' ) then
160 future.state <= WAIT_TO_WR;
161 future.counter <= 550;
162 end if;
163
164
165 when WAIT_TO_WR =>
166 if( current.counter = 0) then
167 future.state <= WAIT_WR_DVALID;
168 future.n_state <= RELEASE_ARBITER;
169
170 future.mm_addr <= x"0051";
171 future.mm_din <= x"10";
172 future.mm_write <= '1';
173 else
174 future.counter <= current.counter - 1;
175 end if;
176
177
178 when RELEASE_ARBITER =>
179 future.arbiter_done <= '1';
180 future.state <= INIT;
181
182 when WAIT_WR_DVALID =>
183 future.state <= WAIT_WR_DVALID_2;
184
185 when WAIT_WR_DVALID_2 =>
186 if( mm_busy = '0' ) then
187 future.state <= WAIT_RD_DVALID;
188 future.mm_addr <= x"0051";
189 future.mm_din <= x"00";
190 future.mm_read <= '1';
191 end if;
192
193 when WAIT_RD_DVALID =>
194 future.state <= WAIT_RD_DVALID_2;
195
196 when WAIT_RD_DVALID_2 =>
197 if( mm_dvalid = '1' ) then
198 future.mm_dout <= mm_dout;
199 future.state <= current.n_state;
200 end if;
201 end case;
202
203 end process comb_proc;
204
205 end architecture arch;