OpenCores
URL https://opencores.org/ocsvn/riscv_vhdl/riscv_vhdl/trunk

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [rtl/] [misclib/] [nasti_gpio.vhd] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 sergeykhbr
-----------------------------------------------------------------------------
2
--! @file
3
--! @copyright Copyright 2017 GNSS Sensor Ltd. All right reserved.
4
--! @author    Sergey Khabarov - sergeykhbr@gmail.com
5
--! @brief     Controller of the GPIOs with the AMBA AXI4 interface.
6
------------------------------------------------------------------------------
7
 
8
library ieee;
9
use ieee.std_logic_1164.all;
10
library commonlib;
11
use commonlib.types_common.all;
12
--! AMBA system bus specific library.
13
library ambalib;
14
--! AXI4 configuration constants.
15
use ambalib.types_amba4.all;
16
 
17
 
18
entity nasti_gpio is
19
  generic (
20
    xaddr    : integer := 0;
21
    xmask    : integer := 16#fffff#;
22
         xirq     : integer := 0
23
  );
24
  port (
25
    clk  : in std_logic;
26
    nrst : in std_logic;
27
    cfg  : out nasti_slave_config_type;
28
    i    : in  nasti_slave_in_type;
29
    o    : out nasti_slave_out_type;
30
    i_dip : in std_logic_vector(3 downto 0);
31
    o_led : out std_logic_vector(7 downto 0)
32
  );
33
end;
34
 
35
architecture arch_nasti_gpio of nasti_gpio is
36
 
37
  constant xconfig : nasti_slave_config_type := (
38
     descrtype => PNP_CFG_TYPE_SLAVE,
39
     descrsize => PNP_CFG_SLAVE_DESCR_BYTES,
40
     irq_idx => xirq,
41
     xaddr => conv_std_logic_vector(xaddr, CFG_NASTI_CFG_ADDR_BITS),
42
     xmask => conv_std_logic_vector(xmask, CFG_NASTI_CFG_ADDR_BITS),
43
     vid => VENDOR_GNSSSENSOR,
44
     did => GNSSSENSOR_GPIO
45
  );
46
 
47
  type local_addr_array_type is array (0 to CFG_WORDS_ON_BUS-1)
48
       of integer;
49
 
50
  type bank_type is record
51
    led : std_logic_vector(31 downto 0);
52
    dip : std_logic_vector(31 downto 0);
53
    reg32_2 : std_logic_vector(31 downto 0);
54
    reg32_3 : std_logic_vector(31 downto 0);
55
    reg32_4 : std_logic_vector(31 downto 0);
56
    reg32_5 : std_logic_vector(31 downto 0);
57
    reg32_6 : std_logic_vector(31 downto 0);
58
  end record;
59
 
60
  type registers is record
61
    bank_axi : nasti_slave_bank_type;
62
    bank0 : bank_type;
63
  end record;
64
 
65
  constant RESET_VALUE : registers := (
66
        NASTI_SLAVE_BANK_RESET,
67
        ((others => '0'), (others => '0'),
68
         (others => '0'), (others => '0'), (others => '0'),
69
         (others => '0'), (others => '0'))
70
  );
71
 
72
  signal r, rin : registers;
73
 
74
 
75
begin
76
 
77
  comblogic : process(i, i_dip, r, nrst)
78
    variable v : registers;
79
    variable raddr_reg : local_addr_array_type;
80
    variable waddr_reg : local_addr_array_type;
81
    variable rdata : std_logic_vector(CFG_NASTI_DATA_BITS-1 downto 0);
82
    variable tmp : std_logic_vector(31 downto 0);
83
    variable wstrb : std_logic_vector(CFG_NASTI_DATA_BYTES-1 downto 0);
84
  begin
85
 
86
    v := r;
87
 
88
    procedureAxi4(i, xconfig, r.bank_axi, v.bank_axi);
89
 
90
    for n in 0 to CFG_WORDS_ON_BUS-1 loop
91
      raddr_reg(n) := conv_integer(r.bank_axi.raddr(n)(11 downto 2));
92
      tmp := (others => '0');
93
 
94
      case raddr_reg(n) is
95
        when 0 => tmp := r.bank0.led;
96
        when 1 => tmp := r.bank0.dip;
97
        when 2 => tmp := r.bank0.reg32_2;
98
        when 3 => tmp := r.bank0.reg32_3;
99
        when 4 => tmp := r.bank0.reg32_4;
100
        when 5 => tmp := r.bank0.reg32_5;
101
        when 6 => tmp := r.bank0.reg32_6;
102
        when others =>
103
      end case;
104
      rdata(8*CFG_ALIGN_BYTES*(n+1)-1 downto 8*CFG_ALIGN_BYTES*n) := tmp;
105
    end loop;
106
 
107
 
108
    if i.w_valid = '1' and
109
       r.bank_axi.wstate = wtrans and
110
       r.bank_axi.wresp = NASTI_RESP_OKAY then
111
 
112
       wstrb := i.w_strb;
113
       for n in 0 to CFG_WORDS_ON_BUS-1 loop
114
         waddr_reg(n) := conv_integer(r.bank_axi.waddr(n)(11 downto 2));
115
         tmp := i.w_data(32*(n+1)-1 downto 32*n);
116
 
117
         if conv_integer(wstrb(CFG_ALIGN_BYTES*(n+1)-1 downto CFG_ALIGN_BYTES*n)) /= 0 then
118
           case waddr_reg(n) is
119
             when 0 => v.bank0.led := tmp;
120
             --when 1 => v.bank0.dip := tmp;
121
             when 2 => v.bank0.reg32_2 := tmp;
122
             when 3 => v.bank0.reg32_3 := tmp;
123
             when 4 => v.bank0.reg32_4 := tmp;
124
             when 5 => v.bank0.reg32_5 := tmp;
125
             when 6 => v.bank0.reg32_6 := tmp;
126
             when others =>
127
           end case;
128
         end if;
129
       end loop;
130
    end if;
131
 
132
    o <= functionAxi4Output(r.bank_axi, rdata);
133
 
134
    v.bank0.dip(3 downto 0) := i_dip;
135
 
136
    if nrst = '0' then
137
        v := RESET_VALUE;
138
    end if;
139
 
140
    rin <= v;
141
  end process;
142
 
143
  cfg  <= xconfig;
144
 
145
  o_led <= r.bank0.led(7 downto 0);
146
 
147
  -- registers:
148
  regs : process(clk)
149
  begin
150
     if rising_edge(clk) then
151
        r <= rin;
152
     end if;
153
  end process;
154
 
155
end;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.