1 |
3 |
uson |
-- Converted from AHBMASTER_FIC.v
|
2 |
|
|
-- by Verilog2VHDL ver1.00(2004/05/06) Copyright(c) S.Morioka (http://www02.so-net.ne.jp/~morioka/v2v.htm)
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
-- AHBMASTER_FIC.v
|
6 |
|
|
--`timescale 1 ns / 100 ps
|
7 |
|
|
-------------------------------------------------------------------------------
|
8 |
|
|
-- Title : Custom AHB slave
|
9 |
|
|
-------------------------------------------------------------------------------
|
10 |
|
|
-- File : AHBMASTER_FIC.v
|
11 |
|
|
-- Author : Mir Ali
|
12 |
|
|
-- Company : Microsemi Corporation
|
13 |
|
|
-- Device : SmartFusion
|
14 |
|
|
-- Standard : Verilog
|
15 |
|
|
-- Special Notes: This is code is for refernce only. You shouldn't use it in real
|
16 |
|
|
-- design as it is
|
17 |
|
|
-------------------------------------------------------------------------------
|
18 |
|
|
-- Description: This code creates an AHB-Lite master wrapper to FIC on SamrtFusion
|
19 |
|
|
-- The AHB interface to Logic will initaite AMBA transaction by sending write/read signals.
|
20 |
|
|
-------------------------------------------------------------------------------
|
21 |
|
|
-- Copyright (c) 2011 Microsemi Corporation
|
22 |
|
|
-- All rights reserved.
|
23 |
|
|
-------------------------------------------------------------------------------
|
24 |
|
|
-- Revisions : V1.0
|
25 |
|
|
-------------------------------------------------------------------------------*/
|
26 |
|
|
|
27 |
|
|
library ieee;
|
28 |
|
|
use ieee.std_logic_1164.all;
|
29 |
|
|
use ieee.std_logic_arith.all;
|
30 |
|
|
use ieee.std_logic_unsigned.all;
|
31 |
|
|
|
32 |
|
|
entity AHBMASTER_FIC is
|
33 |
|
|
port (
|
34 |
|
|
HCLK : in std_logic;
|
35 |
|
|
HRESETn : in std_logic;
|
36 |
|
|
|
37 |
|
|
--AHB interface to Logic
|
38 |
|
|
LREAD : in std_logic;
|
39 |
|
|
LWRITE : in std_logic;
|
40 |
|
|
ADDR : in std_logic_vector(31 downto 0);
|
41 |
|
|
DATAIN : in std_logic_vector(31 downto 0);
|
42 |
|
|
DATAOUT : out std_logic_vector(31 downto 0);
|
43 |
|
|
|
44 |
|
|
-- AHB Side Interfacing with FIC
|
45 |
|
|
HADDR : out std_logic_vector(31 downto 0);
|
46 |
|
|
HTRANS : out std_logic_vector(1 downto 0);
|
47 |
|
|
HWRITE : out std_logic;
|
48 |
|
|
HSIZE : out std_logic_vector(2 downto 0);
|
49 |
|
|
HBURST : out std_logic_vector(2 downto 0);
|
50 |
|
|
HPROT : out std_logic_vector(3 downto 0);
|
51 |
|
|
HWDATA : out std_logic_vector(31 downto 0);
|
52 |
|
|
|
53 |
|
|
HRDATA : in std_logic_vector(31 downto 0);
|
54 |
|
|
HREADY : in std_logic;
|
55 |
|
|
HRESP : in std_logic_vector(1 downto 0);
|
56 |
|
|
|
57 |
|
|
RESP_err : out std_logic_vector(1 downto 0);
|
58 |
|
|
ahb_busy : out std_logic
|
59 |
|
|
);
|
60 |
|
|
end AHBMASTER_FIC;
|
61 |
|
|
|
62 |
|
|
architecture RTL of AHBMASTER_FIC is
|
63 |
|
|
-- AHB FSM States
|
64 |
|
|
signal ahb_fsm_current_state : std_logic_vector(2 downto 0);
|
65 |
|
|
constant Idle : std_logic_vector(2 downto 0) := "000";
|
66 |
|
|
constant Write_FIC_0 : std_logic_vector(2 downto 0) := "001";
|
67 |
|
|
constant Write_FIC_1 : std_logic_vector(2 downto 0) := "010";
|
68 |
|
|
constant Write_FIC_2 : std_logic_vector(2 downto 0) := "011";
|
69 |
|
|
constant Read_FIC_0 : std_logic_vector(2 downto 0) := "100";
|
70 |
|
|
constant Read_FIC_1 : std_logic_vector(2 downto 0) := "101";
|
71 |
|
|
constant Read_FIC_2 : std_logic_vector(2 downto 0) := "110";
|
72 |
|
|
|
73 |
|
|
signal HADDR_int : std_logic_vector(31 downto 0); --temporary hold the address
|
74 |
|
|
signal HWDATA_int : std_logic_vector(31 downto 0); --temporary hold the data
|
75 |
|
|
signal HSIZE_int : std_logic_vector(2 downto 0);
|
76 |
|
|
|
77 |
|
|
-- since the current coreahblite is 32 bit, we are using Hsize=10 (32-bit), but can be changed
|
78 |
|
|
|
79 |
|
|
-- WARNING(5) in line 54: Please write a signal width part in the following sentence, manually.
|
80 |
|
|
constant Data_size : std_logic_vector(7 downto 0) := x"20"; -- 32
|
81 |
|
|
|
82 |
|
|
begin
|
83 |
|
|
RESP_err <= HRESP;
|
84 |
|
|
HBURST <= "000";
|
85 |
|
|
HPROT <= "0011";
|
86 |
|
|
|
87 |
|
|
HSIZE_int <= "010";
|
88 |
|
|
|
89 |
|
|
--generate
|
90 |
|
|
-- if (Data_size == 32) begin
|
91 |
|
|
-- assign HSIZE_int = 2'b10;
|
92 |
|
|
-- end
|
93 |
|
|
-- else if (Data_size == 16) begin
|
94 |
|
|
-- assign HSIZE_int = 2'b01;
|
95 |
|
|
-- end
|
96 |
|
|
-- else if (Data_size == 8) begin
|
97 |
|
|
-- assign HSIZE_int = 2'b00;
|
98 |
|
|
-- end
|
99 |
|
|
--endgenerate
|
100 |
|
|
|
101 |
|
|
-- FSM That Acts as Master on AHB Bus
|
102 |
|
|
-- Assuming only Non-Sequential & Idle
|
103 |
|
|
v2v_pr_0:process (HCLK, HRESETn)
|
104 |
|
|
|
105 |
|
|
begin
|
106 |
|
|
if (HRESETn = '0') then
|
107 |
|
|
HADDR <= x"00000000";
|
108 |
|
|
HTRANS <= "00"; --Idle
|
109 |
|
|
HWRITE <= '0';
|
110 |
|
|
HSIZE <= "010"; -- 32 Bit Mode
|
111 |
|
|
HWDATA <= x"00000000";
|
112 |
|
|
DATAOUT <= x"00000000";
|
113 |
|
|
ahb_fsm_current_state <= Idle;
|
114 |
|
|
ahb_busy <= '0';
|
115 |
|
|
elsif (HCLK'event and HCLK = '1') then
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
case (ahb_fsm_current_state) is
|
119 |
|
|
when Idle =>
|
120 |
|
|
--0x00
|
121 |
|
|
if (LWRITE = '1') then
|
122 |
|
|
ahb_fsm_current_state <= Write_FIC_0;
|
123 |
|
|
HADDR <= ADDR;
|
124 |
|
|
HADDR_int <= ADDR;
|
125 |
|
|
HWDATA_int <= DATAIN;
|
126 |
|
|
ahb_busy <= '1';
|
127 |
|
|
elsif (LREAD = '1') then
|
128 |
|
|
ahb_fsm_current_state <= Read_FIC_0;
|
129 |
|
|
HADDR <= ADDR;
|
130 |
|
|
HADDR_int <= ADDR;
|
131 |
|
|
ahb_busy <= '1';
|
132 |
|
|
else
|
133 |
|
|
ahb_fsm_current_state <= Idle;
|
134 |
|
|
end if;
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
when Write_FIC_0 =>
|
138 |
|
|
--0x01 store the address+control signals and apply to coreahblite
|
139 |
|
|
HTRANS <= "10";
|
140 |
|
|
HSIZE <= HSIZE_int;
|
141 |
|
|
HWRITE <= '1';
|
142 |
|
|
ahb_fsm_current_state <= Write_FIC_1;
|
143 |
|
|
ahb_busy <= '1';
|
144 |
|
|
when Write_FIC_1 =>
|
145 |
|
|
--0x02
|
146 |
|
|
if (HREADY = '0') then --keep the address+control signals when slave is not ready yet
|
147 |
|
|
HTRANS <= "10";
|
148 |
|
|
HSIZE <= HSIZE_int;
|
149 |
|
|
HWRITE <= '1';
|
150 |
|
|
HADDR <= HADDR_int;
|
151 |
|
|
ahb_fsm_current_state <= Write_FIC_1;
|
152 |
|
|
ahb_busy <= '1';
|
153 |
|
|
else
|
154 |
|
|
HWDATA <= HWDATA_int; --send the data+go to next state, doesn't need to keep the address+other controls active
|
155 |
|
|
HADDR <= x"00000000";
|
156 |
|
|
HTRANS <= "00";
|
157 |
|
|
HWRITE <= '0';
|
158 |
|
|
ahb_fsm_current_state <= Write_FIC_2;
|
159 |
|
|
ahb_busy <= '1';
|
160 |
|
|
end if;
|
161 |
|
|
when Write_FIC_2 =>
|
162 |
|
|
--0x03
|
163 |
|
|
if (HREADY = '0') then --keep the data when slave is not ready yet
|
164 |
|
|
ahb_fsm_current_state <= Write_FIC_2;
|
165 |
|
|
ahb_busy <= '1';
|
166 |
|
|
else
|
167 |
|
|
ahb_fsm_current_state <= Idle; --finish the write transfer
|
168 |
|
|
ahb_busy <= '0';
|
169 |
|
|
end if;
|
170 |
|
|
when Read_FIC_0 =>
|
171 |
|
|
--0x04 store the address+control signals and apply to coreahblite
|
172 |
|
|
HTRANS <= "10";
|
173 |
|
|
HSIZE <= HSIZE_int;
|
174 |
|
|
HWRITE <= '0';
|
175 |
|
|
ahb_fsm_current_state <= Read_FIC_1;
|
176 |
|
|
ahb_busy <= '1';
|
177 |
|
|
when Read_FIC_1 =>
|
178 |
|
|
--0x05
|
179 |
|
|
if (HREADY = '1') then -- go to next state
|
180 |
|
|
ahb_fsm_current_state <= Read_FIC_2;
|
181 |
|
|
else
|
182 |
|
|
HTRANS <= "10"; --keep the address+control signals when slave is not ready yet
|
183 |
|
|
HSIZE <= HSIZE_int;
|
184 |
|
|
HWRITE <= '0';
|
185 |
|
|
HADDR <= HADDR_int;
|
186 |
|
|
ahb_fsm_current_state <= Read_FIC_1;
|
187 |
|
|
ahb_busy <= '1';
|
188 |
|
|
end if;
|
189 |
|
|
when Read_FIC_2 =>
|
190 |
|
|
--0x06
|
191 |
|
|
if (HREADY = '1') then --read the data+finish the read transfer
|
192 |
|
|
DATAOUT <= HRDATA;
|
193 |
|
|
ahb_fsm_current_state <= Idle;
|
194 |
|
|
ahb_busy <= '0';
|
195 |
|
|
else
|
196 |
|
|
ahb_fsm_current_state <= Read_FIC_2; --waiting slave to be ready
|
197 |
|
|
ahb_busy <= '1';
|
198 |
|
|
end if;
|
199 |
|
|
HADDR <= x"00000000"; --doesn't need to keep the address+other controls any more
|
200 |
|
|
HTRANS <= "00";
|
201 |
|
|
|
202 |
|
|
end case;
|
203 |
|
|
end if;
|
204 |
|
|
end process;
|
205 |
|
|
|
206 |
|
|
end RTL;
|