summaryrefslogtreecommitdiffstats
path: root/test_rrobin_problem/rtl/led_control_ahb.vhd
blob: b1105a190ffce4ed8d5156e766abf8097d67b5f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
--------------------------------------------------------------------------------
-- $Date$
-- $Author$
-- $Revision$
--------------------------------------------------------------------------------

library ieee;
use ieee.std_logic_1164.all;

library grlib;
use grlib.amba.all;
use grlib.stdlib.all;
use grlib.devices.all;

library hzdr;
use hzdr.devices_hzdr.all;


entity led_control_ahb is
    generic(
        hindex    : integer := 0;
        count     : natural := 0;
        gpio_data : std_logic_vector(31 downto 0)
    );
    port ( 
        -- system
        clk       : in  std_ulogic;
        -- ahb
        ahbi      : in  ahb_mst_in_type; 
        ahbo      : out ahb_mst_out_type
    );
end entity led_control_ahb;


architecture rtl of led_control_ahb is
    
    constant revision_c : integer           := 0;
    constant hconfig_c  : ahb_config_type   := (
        0      => ahb_device_reg ( VENDOR_HZDR, 255, 0, revision_c, 0),
        others => (others => '0') 
    );

    constant gpio_addr_c : std_ulogic_vector(31 downto 0) := x"80000404";

    constant default_ahb_mst_out_c : ahb_mst_out_type := (
        hbusreq => '0',
        hlock   => '0',
        htrans  => HTRANS_IDLE, 
        haddr   => (others => '0'),
        hwrite  => '0',
        hsize   => HSIZE_WORD,
        hburst  => HBURST_SINGLE,
        hprot   => "0001",
        hwdata  => (others => '0'),
        hirq    => (others => '0'), 
        hconfig => hconfig_c,
        hindex  => hindex
    );

    type state_t is (IDLE, ADDR_PHASE, DATA_PHASE);

    type reg_t is record
        state   : state_t;
        counter : natural;
        ahbo    : ahb_mst_out_type;
    end record;
    constant default_reg_c : reg_t := (
        state   => IDLE,
        counter => 0,
        ahbo    => default_ahb_mst_out_c
    );

    signal r    : reg_t := default_reg_c;
    signal r_in : reg_t;

begin

    comb: process(r, ahbi)
        variable v : reg_t;
    begin
        ahbo <= r.ahbo; 
        v    := r;

        case v.state is
            when IDLE =>
                -- have reach right time?
                if v.counter < count then
                    v.counter      := v.counter + 1;
                else
                    -- bus write request
                    v.ahbo.hbusreq := '1';
                    v.ahbo.htrans  := HTRANS_NONSEQ;
                    v.ahbo.haddr   := std_logic_vector( gpio_addr_c);
                    v.ahbo.hwrite  := '1';
                    -- have grant?
                    if ahbi.hgrant( hindex) = '1' then
                        v.state    := ADDR_PHASE;
                    end if;
                end if;

            when ADDR_PHASE =>
                v.ahbo.hbusreq     := '0';
                v.ahbo.htrans      := HTRANS_IDLE;
                v.ahbo.haddr       := (others => '0');
                v.ahbo.hwrite      := '0';
                v.ahbo.hwdata      := gpio_data;
                v.state            := DATA_PHASE;


            when DATA_PHASE =>
                v.ahbo.hwdata      := (others => '0');
                v.counter          := 0;
                v.state            := IDLE;

        end case;

        r_in <= v;
    end process comb;


    seq: process
    begin
        wait until rising_edge( clk);
        r <= r_in;
    end process seq;


    -- pragma translate_off
    bootmsg : report_version
    generic map (
        "led_control_ahb" & tost( hindex) & ": rev " & tost( revision_c) & ", gpio_data: " & tost( gpio_data)
    );
    -- pragma translate_on


end architecture rtl;

OpenPOWER on IntegriCloud