| 1 |
5 |
sergeykhbr |
-----------------------------------------------------------------------------
|
| 2 |
|
|
--! @file
|
| 3 |
|
|
--! @copyright Copyright 2015 GNSS Sensor Ltd. All right reserved.
|
| 4 |
|
|
--! @author Sergey Khabarov - sergeykhbr@gmail.com
|
| 5 |
|
|
--! @brief General Purpose Timers with the AXI4 interface.
|
| 6 |
|
|
------------------------------------------------------------------------------
|
| 7 |
|
|
|
| 8 |
|
|
|
| 9 |
|
|
library ieee;
|
| 10 |
|
|
use ieee.std_logic_1164.all;
|
| 11 |
|
|
library commonlib;
|
| 12 |
|
|
use commonlib.types_common.all;
|
| 13 |
|
|
--! AMBA system bus specific library.
|
| 14 |
|
|
library ambalib;
|
| 15 |
|
|
--! AXI4 configuration constants.
|
| 16 |
|
|
use ambalib.types_amba4.all;
|
| 17 |
|
|
library misclib;
|
| 18 |
|
|
use misclib.types_misc.all;
|
| 19 |
|
|
|
| 20 |
|
|
entity nasti_gptimers is
|
| 21 |
|
|
generic (
|
| 22 |
|
|
xaddr : integer := 0;
|
| 23 |
|
|
xmask : integer := 16#fffff#;
|
| 24 |
|
|
xirq : integer := 0;
|
| 25 |
|
|
tmr_total : integer := 2
|
| 26 |
|
|
);
|
| 27 |
|
|
port (
|
| 28 |
|
|
clk : in std_logic;
|
| 29 |
|
|
nrst : in std_logic;
|
| 30 |
|
|
cfg : out nasti_slave_config_type;
|
| 31 |
|
|
i_axi : in nasti_slave_in_type;
|
| 32 |
|
|
o_axi : out nasti_slave_out_type;
|
| 33 |
|
|
o_irq : out std_logic
|
| 34 |
|
|
);
|
| 35 |
|
|
end;
|
| 36 |
|
|
|
| 37 |
|
|
architecture arch_nasti_gptimers of nasti_gptimers is
|
| 38 |
|
|
|
| 39 |
|
|
constant xconfig : nasti_slave_config_type := (
|
| 40 |
|
|
descrtype => PNP_CFG_TYPE_SLAVE,
|
| 41 |
|
|
descrsize => PNP_CFG_SLAVE_DESCR_BYTES,
|
| 42 |
|
|
irq_idx => xirq,
|
| 43 |
|
|
xaddr => conv_std_logic_vector(xaddr, CFG_NASTI_CFG_ADDR_BITS),
|
| 44 |
|
|
xmask => conv_std_logic_vector(xmask, CFG_NASTI_CFG_ADDR_BITS),
|
| 45 |
|
|
vid => VENDOR_GNSSSENSOR,
|
| 46 |
|
|
did => GNSSSENSOR_GPTIMERS
|
| 47 |
|
|
);
|
| 48 |
|
|
|
| 49 |
|
|
constant zero64 : std_logic_vector(63 downto 0) := (others => '0');
|
| 50 |
|
|
|
| 51 |
|
|
type timer_type is record
|
| 52 |
|
|
count_ena : std_logic;
|
| 53 |
|
|
irq_ena : std_logic;
|
| 54 |
|
|
value : std_logic_vector(63 downto 0);
|
| 55 |
|
|
init_value : std_logic_vector(63 downto 0);
|
| 56 |
|
|
end record;
|
| 57 |
|
|
|
| 58 |
|
|
constant timer_type_reset : timer_type :=
|
| 59 |
|
|
('0', '0', (others => '0'), (others => '0'));
|
| 60 |
|
|
|
| 61 |
|
|
type vector_timer_type is array (0 to tmr_total-1) of timer_type;
|
| 62 |
|
|
|
| 63 |
|
|
type bank_type is record
|
| 64 |
|
|
tmr : vector_timer_type;
|
| 65 |
|
|
highcnt : std_logic_vector(63 downto 0);
|
| 66 |
|
|
pending : std_logic_vector(tmr_total-1 downto 0);
|
| 67 |
|
|
end record;
|
| 68 |
|
|
|
| 69 |
|
|
type registers is record
|
| 70 |
|
|
bank_axi : nasti_slave_bank_type;
|
| 71 |
|
|
bank0 : bank_type;
|
| 72 |
|
|
end record;
|
| 73 |
|
|
|
| 74 |
|
|
signal r, rin : registers;
|
| 75 |
|
|
|
| 76 |
|
|
begin
|
| 77 |
|
|
|
| 78 |
|
|
comblogic : process(nrst, i_axi, r)
|
| 79 |
|
|
variable v : registers;
|
| 80 |
|
|
variable rdata : std_logic_vector(CFG_NASTI_DATA_BITS-1 downto 0);
|
| 81 |
|
|
variable wstrb : std_logic_vector(CFG_NASTI_DATA_BYTES-1 downto 0);
|
| 82 |
|
|
variable tmp : std_logic_vector(31 downto 0);
|
| 83 |
|
|
variable raddr : integer;
|
| 84 |
|
|
variable waddr : integer;
|
| 85 |
|
|
|
| 86 |
|
|
variable irq_ena : std_logic;
|
| 87 |
|
|
begin
|
| 88 |
|
|
|
| 89 |
|
|
v := r;
|
| 90 |
|
|
|
| 91 |
|
|
procedureAxi4(i_axi, xconfig, r.bank_axi, v.bank_axi);
|
| 92 |
|
|
|
| 93 |
|
|
v.bank0.highcnt := r.bank0.highcnt + 1;
|
| 94 |
|
|
|
| 95 |
|
|
irq_ena := '0';
|
| 96 |
|
|
for n in 0 to tmr_total-1 loop
|
| 97 |
|
|
if r.bank0.tmr(n).count_ena = '1' then
|
| 98 |
|
|
if r.bank0.tmr(n).value = zero64 then
|
| 99 |
|
|
irq_ena := irq_ena or r.bank0.tmr(n).irq_ena;
|
| 100 |
|
|
v.bank0.pending(n) := r.bank0.tmr(n).irq_ena;
|
| 101 |
|
|
v.bank0.tmr(n).value := r.bank0.tmr(n).init_value;
|
| 102 |
|
|
else
|
| 103 |
|
|
v.bank0.tmr(n).value := r.bank0.tmr(n).value - 1;
|
| 104 |
|
|
end if;
|
| 105 |
|
|
else
|
| 106 |
|
|
v.bank0.tmr(n).value := r.bank0.tmr(n).init_value;
|
| 107 |
|
|
end if;
|
| 108 |
|
|
end loop;
|
| 109 |
|
|
|
| 110 |
|
|
|
| 111 |
|
|
for n in 0 to CFG_WORDS_ON_BUS-1 loop
|
| 112 |
|
|
tmp := (others => '0');
|
| 113 |
|
|
raddr := conv_integer(r.bank_axi.raddr(n)(11 downto 2));
|
| 114 |
|
|
case raddr is
|
| 115 |
|
|
when 0 =>
|
| 116 |
|
|
tmp := r.bank0.highcnt(31 downto 0);
|
| 117 |
|
|
when 1 =>
|
| 118 |
|
|
tmp := r.bank0.highcnt(63 downto 32);
|
| 119 |
|
|
when 2 =>
|
| 120 |
|
|
tmp(tmr_total-1 downto 0) := r.bank0.pending;
|
| 121 |
|
|
when others =>
|
| 122 |
|
|
for k in 0 to tmr_total-1 loop
|
| 123 |
|
|
if raddr = (16 + 8*k) then
|
| 124 |
|
|
tmp(0) := r.bank0.tmr(k).count_ena;
|
| 125 |
|
|
tmp(1) := r.bank0.tmr(k).irq_ena;
|
| 126 |
|
|
elsif raddr = (16 + 8*k + 2) then
|
| 127 |
|
|
tmp := r.bank0.tmr(k).value(31 downto 0);
|
| 128 |
|
|
elsif raddr = (16 + 8*k + 3) then
|
| 129 |
|
|
tmp := r.bank0.tmr(k).value(63 downto 32);
|
| 130 |
|
|
elsif raddr = (16 + 8*k + 4) then
|
| 131 |
|
|
tmp := r.bank0.tmr(k).init_value(31 downto 0);
|
| 132 |
|
|
elsif raddr = (16 + 8*k + 5) then
|
| 133 |
|
|
tmp := r.bank0.tmr(k).init_value(63 downto 32);
|
| 134 |
|
|
end if;
|
| 135 |
|
|
end loop;
|
| 136 |
|
|
end case;
|
| 137 |
|
|
rdata(8*CFG_ALIGN_BYTES*(n+1)-1 downto 8*CFG_ALIGN_BYTES*n) := tmp;
|
| 138 |
|
|
end loop;
|
| 139 |
|
|
|
| 140 |
|
|
|
| 141 |
|
|
if i_axi.w_valid = '1' and
|
| 142 |
|
|
r.bank_axi.wstate = wtrans and
|
| 143 |
|
|
r.bank_axi.wresp = NASTI_RESP_OKAY then
|
| 144 |
|
|
|
| 145 |
|
|
wstrb := i_axi.w_strb;
|
| 146 |
|
|
for n in 0 to CFG_WORDS_ON_BUS-1 loop
|
| 147 |
|
|
|
| 148 |
|
|
if conv_integer(wstrb(CFG_ALIGN_BYTES*(n+1)-1 downto CFG_ALIGN_BYTES*n)) /= 0 then
|
| 149 |
|
|
tmp := i_axi.w_data(8*CFG_ALIGN_BYTES*(n+1)-1 downto 8*CFG_ALIGN_BYTES*n);
|
| 150 |
|
|
waddr := conv_integer(r.bank_axi.waddr(n)(11 downto 2));
|
| 151 |
|
|
case waddr is
|
| 152 |
|
|
when 2 =>
|
| 153 |
|
|
v.bank0.pending := tmp(tmr_total-1 downto 0);
|
| 154 |
|
|
when others =>
|
| 155 |
|
|
for k in 0 to tmr_total-1 loop
|
| 156 |
|
|
if waddr = (16 + 8*k) then
|
| 157 |
|
|
v.bank0.tmr(k).count_ena := tmp(0);
|
| 158 |
|
|
v.bank0.tmr(k).irq_ena := tmp(1);
|
| 159 |
|
|
elsif waddr = (16 + 8*k + 2) then
|
| 160 |
|
|
v.bank0.tmr(k).value(31 downto 0) := tmp;
|
| 161 |
|
|
elsif waddr = (16 + 8*k + 3) then
|
| 162 |
|
|
v.bank0.tmr(k).value(63 downto 32) := tmp;
|
| 163 |
|
|
elsif waddr = (16 + 8*k + 4) then
|
| 164 |
|
|
v.bank0.tmr(k).init_value(31 downto 0) := tmp;
|
| 165 |
|
|
elsif waddr = (16 + 8*k + 5) then
|
| 166 |
|
|
v.bank0.tmr(k).init_value(63 downto 32) := tmp;
|
| 167 |
|
|
end if;
|
| 168 |
|
|
end loop;
|
| 169 |
|
|
end case;
|
| 170 |
|
|
end if;
|
| 171 |
|
|
end loop;
|
| 172 |
|
|
end if;
|
| 173 |
|
|
|
| 174 |
|
|
if nrst = '0' then
|
| 175 |
|
|
v.bank_axi := NASTI_SLAVE_BANK_RESET;
|
| 176 |
|
|
v.bank0.highcnt := (others => '0');
|
| 177 |
|
|
v.bank0.pending := (others => '0');
|
| 178 |
|
|
for k in 0 to tmr_total-1 loop
|
| 179 |
|
|
v.bank0.tmr(k) := timer_type_reset;
|
| 180 |
|
|
end loop;
|
| 181 |
|
|
end if;
|
| 182 |
|
|
|
| 183 |
|
|
o_axi <= functionAxi4Output(r.bank_axi, rdata);
|
| 184 |
|
|
o_irq <= irq_ena;
|
| 185 |
|
|
rin <= v;
|
| 186 |
|
|
end process;
|
| 187 |
|
|
|
| 188 |
|
|
cfg <= xconfig;
|
| 189 |
|
|
|
| 190 |
|
|
-- registers:
|
| 191 |
|
|
regs : process(clk)
|
| 192 |
|
|
begin
|
| 193 |
|
|
if rising_edge(clk) then
|
| 194 |
|
|
r <= rin;
|
| 195 |
|
|
end if;
|
| 196 |
|
|
end process;
|
| 197 |
|
|
end;
|