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

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [rtl/] [misclib/] [nasti_pnp.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      Plug'n'Play support device with AXI4 interface.
6
------------------------------------------------------------------------------
7
 
8
library ieee;
9
use ieee.std_logic_1164.all;
10
library techmap;
11
use techmap.gencomp.all;
12
library commonlib;
13
use commonlib.types_common.all;
14
--! AMBA system bus specific library.
15
library ambalib;
16
--! AXI4 configuration constants.
17
use ambalib.types_amba4.all;
18
 
19
 
20
--! @brief Hardware Configuration storage with the AMBA AXI4 interface.
21
entity nasti_pnp is
22
  generic (
23
    xaddr   : integer := 0;
24
    xmask   : integer := 16#fffff#;
25
    tech    : integer := 0;
26
    hw_id   : std_logic_vector(31 downto 0) := X"20170101"
27
  );
28
  port (
29
    sys_clk : in  std_logic;
30
    adc_clk : in  std_logic;
31
    nrst   : in  std_logic;
32
    mstcfg : in  nasti_master_cfg_vector;
33
    slvcfg : in  nasti_slave_cfg_vector;
34
    cfg    : out  nasti_slave_config_type;
35
    i      : in  nasti_slave_in_type;
36
    o      : out nasti_slave_out_type
37
  );
38
end;
39
 
40
architecture arch_nasti_pnp of nasti_pnp is
41
 
42
  constant xconfig : nasti_slave_config_type := (
43
     descrsize => PNP_CFG_SLAVE_DESCR_BYTES,
44
     descrtype => PNP_CFG_TYPE_SLAVE,
45
     irq_idx => 0,
46
     xaddr => conv_std_logic_vector(xaddr, CFG_NASTI_CFG_ADDR_BITS),
47
     xmask => conv_std_logic_vector(xmask, CFG_NASTI_CFG_ADDR_BITS),
48
     vid => VENDOR_GNSSSENSOR,
49
     did => GNSSSENSOR_PNP
50
  );
51
 
52
  type local_addr_array_type is array (0 to CFG_WORDS_ON_BUS-1)
53
       of integer;
54
 
55
  type master_config_map is array (0 to 2*CFG_NASTI_MASTER_TOTAL-1)
56
       of std_logic_vector(31 downto 0);
57
 
58
  type slave_config_map is array (0 to 4*CFG_NASTI_SLAVES_TOTAL-1)
59
       of std_logic_vector(31 downto 0);
60
 
61
  type bank_type is record
62
    fw_id : std_logic_vector(31 downto 0);
63
    idt : std_logic_vector(63 downto 0); --! debug counter
64
    malloc_addr : std_logic_vector(63 downto 0); --! dynamic allocation addr
65
    malloc_size : std_logic_vector(63 downto 0); --! dynamic allocation size
66
    fwdbg1 : std_logic_vector(63 downto 0); --! FW marker for the debug porposes
67
    adc_detect : std_logic_vector(7 downto 0);
68
  end record;
69
 
70
  type registers is record
71
    bank_axi : nasti_slave_bank_type;
72
    bank0 : bank_type;
73
  end record;
74
 
75
  constant RESET_VALUE : registers := (
76
        NASTI_SLAVE_BANK_RESET,
77
        ((others => '0'), (others => '0'), (others => '0'),
78
         (others => '0'), (others => '0'), (others => '0'))
79
  );
80
 
81
  signal r, rin : registers;
82
  --! @brief   Detector of the ADC clock.
83
  --! @details If this register won't equal to 0xFF, then we suppose RF front-end
84
  --!          not connected and FW should print message to enable 'i_int_clkrf'
85
  --!          jumper to make possible generation of the 1 msec interrupts.
86
  signal r_adc_detect : std_logic_vector(7 downto 0);
87
 
88
begin
89
 
90
  comblogic : process(i, slvcfg, mstcfg, r, r_adc_detect, nrst)
91
    variable v : registers;
92
    variable mstmap : master_config_map;
93
    variable slvmap : slave_config_map;
94
    variable raddr_reg : local_addr_array_type;
95
    variable waddr_reg : local_addr_array_type;
96
    variable rdata : std_logic_vector(CFG_NASTI_DATA_BITS-1 downto 0);
97
    variable rtmp : std_logic_vector(31 downto 0);
98
    variable wtmp : std_logic_vector(31 downto 0);
99
    variable wstrb : std_logic_vector(CFG_ALIGN_BYTES-1 downto 0);
100
  begin
101
 
102
    v := r;
103
    v.bank0.adc_detect := r_adc_detect;
104
 
105
    for k in 0 to CFG_NASTI_MASTER_TOTAL-1 loop
106
      mstmap(2*k) := "00" & X"00000" & mstcfg(k).descrtype & mstcfg(k).descrsize;
107
      mstmap(2*k+1) := mstcfg(k).vid & mstcfg(k).did;
108
    end loop;
109
 
110
    for k in 0 to CFG_NASTI_SLAVES_TOTAL-1 loop
111
      slvmap(4*k) := X"00" &
112
                     conv_std_logic_vector(slvcfg(k).irq_idx,8) & "000000" &
113
                     slvcfg(k).descrtype & slvcfg(k).descrsize;
114
      slvmap(4*k+1) := slvcfg(k).vid & slvcfg(k).did;
115
      slvmap(4*k+2)   := slvcfg(k).xmask & X"000";
116
      slvmap(4*k+3) := slvcfg(k).xaddr & X"000";
117
    end loop;
118
 
119
 
120
    procedureAxi4(i, xconfig, r.bank_axi, v.bank_axi);
121
 
122
    for n in 0 to CFG_WORDS_ON_BUS-1 loop
123
       raddr_reg(n) := conv_integer(r.bank_axi.raddr(n)(11 downto 2));
124
 
125
       rtmp := (others => '0');
126
       if raddr_reg(n) = 0 then
127
          rtmp := hw_id;
128
       elsif raddr_reg(n) = 1 then
129
          rtmp := r.bank0.fw_id;
130
       elsif raddr_reg(n) = 2 then
131
          rtmp := r.bank0.adc_detect
132
              & conv_std_logic_vector(CFG_NASTI_MASTER_TOTAL,8)
133
              & conv_std_logic_vector(CFG_NASTI_SLAVES_TOTAL,8)
134
              & conv_std_logic_vector(tech,8);
135
       elsif raddr_reg(n) = 3 then
136
          -- reserved
137
       elsif raddr_reg(n) = 4 then
138
          rtmp := r.bank0.idt(31 downto 0);
139
       elsif raddr_reg(n) = 5 then
140
          rtmp := r.bank0.idt(63 downto 32);
141
       elsif raddr_reg(n) = 6 then
142
          rtmp := r.bank0.malloc_addr(31 downto 0);
143
       elsif raddr_reg(n) = 7 then
144
          rtmp := r.bank0.malloc_addr(63 downto 32);
145
       elsif raddr_reg(n) = 8 then
146
          rtmp := r.bank0.malloc_size(31 downto 0);
147
       elsif raddr_reg(n) = 9 then
148
          rtmp := r.bank0.malloc_size(63 downto 32);
149
       elsif raddr_reg(n) = 10 then
150
          rtmp := r.bank0.fwdbg1(31 downto 0);
151
       elsif raddr_reg(n) = 11 then
152
          rtmp := r.bank0.fwdbg1(63 downto 32);
153
       elsif raddr_reg(n) >= 16 and raddr_reg(n) < 16+2*CFG_NASTI_MASTER_TOTAL then
154
          rtmp := mstmap(raddr_reg(n) - 16);
155
       elsif raddr_reg(n) >= 16+2*CFG_NASTI_MASTER_TOTAL
156
             and raddr_reg(n) < 16+2*CFG_NASTI_MASTER_TOTAL+4*CFG_NASTI_SLAVES_TOTAL then
157
          rtmp := slvmap(raddr_reg(n) - 16 - 2*CFG_NASTI_MASTER_TOTAL);
158
       end if;
159
 
160
       rdata(32*(n+1)-1 downto 32*n) := rtmp;
161
    end loop;
162
 
163
 
164
    if i.w_valid = '1' and
165
       r.bank_axi.wstate = wtrans and
166
       r.bank_axi.wresp = NASTI_RESP_OKAY then
167
 
168
      for n in 0 to CFG_WORDS_ON_BUS-1 loop
169
         waddr_reg(n) := conv_integer(r.bank_axi.waddr(n)(11 downto 2));
170
         wtmp := i.w_data(32*(n+1)-1 downto 32*n);
171
         wstrb := i.w_strb(CFG_ALIGN_BYTES*(n+1)-1 downto CFG_ALIGN_BYTES*n);
172
 
173
         if conv_integer(wstrb) /= 0 then
174
           case waddr_reg(n) is
175
             when 1 => v.bank0.fw_id := wtmp;
176
             when 4 => v.bank0.idt(31 downto 0) := wtmp;
177
             when 5 => v.bank0.idt(63 downto 32) := wtmp;
178
             when 6 => v.bank0.malloc_addr(31 downto 0) := wtmp;
179
             when 7 => v.bank0.malloc_addr(63 downto 32) := wtmp;
180
             when 8 => v.bank0.malloc_size(31 downto 0) := wtmp;
181
             when 9 => v.bank0.malloc_size(63 downto 32) := wtmp;
182
             when 10 => v.bank0.fwdbg1(31 downto 0) := wtmp;
183
             when 11 => v.bank0.fwdbg1(63 downto 32) := wtmp;
184
             when others =>
185
           end case;
186
         end if;
187
      end loop;
188
    end if;
189
 
190
    o <= functionAxi4Output(r.bank_axi, rdata);
191
 
192
    if nrst = '0' then
193
        v := RESET_VALUE;
194
    end if;
195
 
196
    rin <= v;
197
  end process;
198
 
199
  cfg <= xconfig;
200
 
201
  -- registers:
202
  regs : process(sys_clk)
203
  begin
204
     if rising_edge(sys_clk) then
205
        r <= rin;
206
     end if;
207
  end process;
208
 
209
  -- ADC clock detector:
210
  regsadc : process(adc_clk)
211
  begin
212
     if rising_edge(adc_clk) then
213
        if nrst = '0' then
214
            r_adc_detect <= (others => '0');
215
        else
216
            r_adc_detect <= r_adc_detect(6 downto 0) & nrst;
217
        end if;
218
     end if;
219
  end process;
220
 
221
end;

powered by: WebSVN 2.1.0

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