1 | library IEEE;
|
2 | use IEEE.std_logic_1164.all;
|
3 | use IEEE.numeric_std.all;
|
4 |
|
5 |
|
6 | entity apb_register is
|
7 | port (
|
8 | clk: in std_logic;
|
9 | resetn: in std_logic;
|
10 | PENABLE: in std_logic;
|
11 | PSELx: in std_logic;
|
12 | PREADY: out std_logic;
|
13 | PSLVERR: out std_logic;
|
14 | PADDR: in std_logic_vector(7 downto 0);
|
15 | PWRITE: in std_logic;
|
16 | PWDATA: in std_logic_vector(7 downto 0);
|
17 | PRDATA: out std_logic_vector(7 downto 0)
|
18 | );
|
19 | end entity apb_register;
|
20 |
|
21 |
|
22 | architecture one of apb_register is
|
23 |
|
24 | type t_array_apb_regs is array(0 to 4-1) of std_logic_vector(7 downto 0);
|
25 | signal apb_regs: t_array_apb_regs;
|
26 |
|
27 | begin
|
28 | PREADY<='1';
|
29 | PSLVERR<='0';
|
30 |
|
31 | APB_REGISTER_APB_REGISTER_CLCKED: process (clk) is
|
32 | begin
|
33 | if rising_edge(clk) then
|
34 | if (not(resetn))='1' then
|
35 | for k in 0 to 4-1 loop
|
36 | apb_regs(k) <= "00000000";
|
37 | end loop;
|
38 | else
|
39 | if ((PWRITE) and (PSELx) and (PENABLE))='1' then
|
40 | apb_regs(to_integer(unsigned(PADDR(8-1 downto 2)))) <= PWDATA;
|
41 | end if;
|
42 | end if;
|
43 | if ((not (PWRITE)) and (PSELx))='1' then
|
44 | PRDATA <= apb_regs(to_integer(unsigned(PADDR(8-1 downto 2))));
|
45 | end if;
|
46 | end if;
|
47 | end process APB_REGISTER_APB_REGISTER_CLCKED;
|
48 |
|
49 | end architecture one;
|