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

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [rtl/] [gnsslib/] [gnssengine_stub/] [nasti_gnssstub.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 2015 GNSS Sensor Ltd. All right reserved.
4
--! @author     Sergey Khabarov - sergeykhbr@gmail.com
5
--! @brief      Stub module of the real GNSS engine.
6
--! @details    This module is used for SoC sharing and it generates 1 msec
7
--!             interrupt. It implements AMBA AXI4 interface.
8
------------------------------------------------------------------------------
9
 
10
library ieee;
11
use ieee.std_logic_1164.all;
12
library techmap;
13
use techmap.gencomp.all;
14
library commonlib;
15
use commonlib.types_common.all;
16
--! AMBA system bus specific library
17
library ambalib;
18
--! AXI4 configuration constants.
19
use ambalib.types_amba4.all;
20
--! GNSS specific library.
21
library gnsslib;
22
use gnsslib.types_gnss.all;
23
 
24
 
25
entity gnssengine is
26
  generic (
27
    tech   : integer range 0 to NTECH := 0;
28
    xaddr   : integer := 0;
29
    xmask   : integer := 16#fffff#;
30
    xirq   : integer := 0
31
  );
32
  port (
33
    nrst         : in std_logic;
34
    clk_bus      : in std_logic;
35
    clk_adc      : in std_logic;
36
    o_cfg        : out nasti_slave_config_type;
37
    i_axi        : in  nasti_slave_in_type;
38
    o_axi        : out nasti_slave_out_type;
39
    i_gps_I      : in std_logic_vector(1 downto 0);
40
    i_gps_Q      : in std_logic_vector(1 downto 0);
41
    i_glo_I      : in std_logic_vector(1 downto 0);
42
    i_glo_Q      : in std_logic_vector(1 downto 0);
43
    o_ms_pulse   : out std_logic;
44
    o_pps        : out std_logic
45
  );
46
end;
47
 
48
architecture arch_gnssengine of gnssengine is
49
  constant xconfig : nasti_slave_config_type := (
50
     descrtype => PNP_CFG_TYPE_SLAVE,
51
     descrsize => PNP_CFG_SLAVE_DESCR_BYTES,
52
     irq_idx => xirq,
53
     xaddr => conv_std_logic_vector(xaddr, CFG_NASTI_CFG_ADDR_BITS),
54
     xmask => conv_std_logic_vector(xmask, CFG_NASTI_CFG_ADDR_BITS),
55
     vid => VENDOR_GNSSSENSOR,
56
     did => GNSSSENSOR_ENGINE_STUB
57
  );
58
 
59
  type local_addr_array_type is array (0 to CFG_WORDS_ON_BUS-1)
60
       of integer;
61
 
62
 
63
  type bank_tmr_stub_type is record
64
    MsCnt          : std_logic_vector(31 downto 0); --! 
65
    TOW            : std_logic_vector(31 downto 0); --! 
66
    TOD            : std_logic_vector(31 downto 0); --! 
67
  end record;
68
 
69
  type adc_registers is record
70
    tmr  : bank_tmr_stub_type;
71
    clk_cnt        : integer;
72
    irq : std_logic;
73
  end record;
74
 
75
  type bus_registers is record
76
    bank_axi : nasti_slave_bank_type;
77
    --! Registers clocked by system bus
78
    MsLength : std_logic_vector(31 downto 0); --! 
79
    CarrierNcoTh   : std_logic_vector(31 downto 0); --!
80
    CarrierNcoIF   : std_logic_vector(31 downto 0); --!
81
  end record;
82
 
83
signal ra, rain : adc_registers;
84
signal r, rin : bus_registers;
85
 
86
begin
87
 
88
  comblogic : process(nrst, i_axi, r, ra)
89
    variable v : bus_registers;
90
    variable raddr_reg : local_addr_array_type;
91
    variable waddr_reg : local_addr_array_type;
92
    variable rdata : std_logic_vector(CFG_NASTI_DATA_BITS-1 downto 0);
93
    variable wstrb : std_logic_vector(CFG_ALIGN_BYTES-1 downto 0);
94
    variable tmp : std_logic_vector(31 downto 0);
95
  begin
96
 
97
    v := r;
98
 
99
    procedureAxi4(i_axi, xconfig, r.bank_axi, v.bank_axi);
100
 
101
    for n in 0 to CFG_WORDS_ON_BUS-1 loop
102
       raddr_reg(n) := conv_integer(r.bank_axi.raddr(n)(11 downto 2));
103
       tmp := (others => '0');
104
 
105
       case raddr_reg(n) is
106
          --! Misc. bank (stub):
107
          when 0 => tmp := X"B00BCAFE";  --! hwid of the stub
108
          when 1 => tmp := X"00000021";  --! gnss channels configuration stub
109
          when 2 => tmp := r.CarrierNcoTh; --!
110
          when 3 => tmp := r.CarrierNcoIF; --!
111
          --! Global Timers bank (stub):
112
          when 16#10# => tmp := r.MsLength;
113
          when 16#11# => tmp := ra.tmr.MsCnt;
114
          when 16#12# => tmp := ra.tmr.TOW;
115
          when 16#13# => tmp := ra.tmr.TOD;
116
          when others =>
117
       end case;
118
       rdata(8*CFG_ALIGN_BYTES*(n+1)-1 downto 8*CFG_ALIGN_BYTES*n) := tmp;
119
    end loop;
120
 
121
 
122
    if i_axi.w_valid = '1' and
123
       r.bank_axi.wstate = wtrans and
124
       r.bank_axi.wresp = NASTI_RESP_OKAY then
125
 
126
      for n in 0 to CFG_WORDS_ON_BUS-1 loop
127
         waddr_reg(n) := conv_integer(r.bank_axi.waddr(n)(11 downto 2));
128
         tmp := i_axi.w_data(32*(n+1)-1 downto 32*n);
129
         wstrb := i_axi.w_strb(CFG_ALIGN_BYTES*(n+1)-1 downto CFG_ALIGN_BYTES*n);
130
 
131
         if conv_integer(wstrb) /= 0 then
132
           case waddr_reg(n) is
133
             when 2 => v.CarrierNcoTh := tmp;
134
             when 3 => v.CarrierNcoIF := tmp;
135
             when 16#10# => v.MsLength := tmp;
136
             when others =>
137
           end case;
138
         end if;
139
      end loop;
140
    end if;
141
 
142
    if nrst = '0' then
143
        v.bank_axi := NASTI_SLAVE_BANK_RESET;
144
        v.MsLength := (others => '0');
145
        v.CarrierNcoIF := (others => '0');
146
        v.CarrierNcoTh := (others => '0');
147
    end if;
148
 
149
    o_axi <= functionAxi4Output(r.bank_axi, rdata);
150
 
151
    rin <= v;
152
  end process;
153
 
154
  o_cfg  <= xconfig;
155
  o_pps <= '0';
156
  o_ms_pulse <= ra.irq;
157
 
158
  -- registers:
159
  regadc : process(clk_adc)
160
  begin
161
     if rising_edge(clk_adc) then
162
        ra.irq <= '0';
163
        if nrst = '0' then
164
            ra.tmr.TOW <= (others => '0');
165
            ra.tmr.TOD <= (others => '0');
166
            ra.tmr.MsCnt <= (others => '0');
167
            ra.clk_cnt <= 15000;
168
        elsif conv_integer(r.MsLength) /= 0 then
169
            if ra.clk_cnt = (conv_integer(r.MsLength) - 1) then
170
                ra.clk_cnt <= 0;
171
                ra.tmr.MsCnt <= ra.tmr.MsCnt + 1;
172
                ra.irq <= '1';
173
            else
174
                ra.clk_cnt <= ra.clk_cnt + 1;
175
            end if;
176
        end if;
177
     end if;
178
  end process;
179
 
180
  regs : process(clk_bus) begin
181
    if rising_edge(clk_bus) then
182
       r <= rin;
183
    end if;
184
  end process;
185
 
186
end;

powered by: WebSVN 2.1.0

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