1 |
222 |
jshamlet |
-- Copyright (c)2011, 2019, 2020 Jeremy Seth Henry
|
2 |
|
|
-- All rights reserved.
|
3 |
|
|
--
|
4 |
|
|
-- Redistribution and use in source and binary forms, with or without
|
5 |
|
|
-- modification, are permitted provided that the following conditions are met:
|
6 |
|
|
-- * Redistributions of source code must retain the above copyright
|
7 |
|
|
-- notice, this list of conditions and the following disclaimer.
|
8 |
|
|
-- * Redistributions in binary form must reproduce the above copyright
|
9 |
|
|
-- notice, this list of conditions and the following disclaimer in the
|
10 |
|
|
-- documentation and/or other materials provided with the distribution,
|
11 |
|
|
-- where applicable (as part of a user interface, debugging port, etc.)
|
12 |
|
|
--
|
13 |
|
|
-- THIS SOFTWARE IS PROVIDED BY JEREMY SETH HENRY ``AS IS'' AND ANY
|
14 |
|
|
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
15 |
|
|
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
16 |
|
|
-- DISCLAIMED. IN NO EVENT SHALL JEREMY SETH HENRY BE LIABLE FOR ANY
|
17 |
|
|
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
18 |
|
|
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
19 |
|
|
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
20 |
|
|
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
21 |
|
|
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
22 |
|
|
-- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
23 |
|
|
--
|
24 |
|
|
-- VHDL Units : o8_epoch_timer_ii
|
25 |
|
|
-- Description: Provides a 32-bit, 1uS resolution elapsed timer with
|
26 |
|
|
-- : alarm and interrupt for the Open8 CPU.
|
27 |
|
|
--
|
28 |
|
|
-- Notes : Requires an externally provided uSec tick input - one clock
|
29 |
|
|
-- : per microsecond.
|
30 |
|
|
--
|
31 |
|
|
-- Register Map:
|
32 |
|
|
-- Offset Bitfield Description Read/Write
|
33 |
|
|
-- 0x0 AAAAAAAA B0 of Buffered Setpoint (W) or Current Setpoint(R)
|
34 |
|
|
-- 0x1 AAAAAAAA B1 of Buffered Setpoint (W) or Current Setpoint(R)
|
35 |
|
|
-- 0x2 AAAAAAAA B2 of Buffered Setpoint (W) or Current Setpoint(R)
|
36 |
|
|
-- 0x3 AAAAAAAA B3 of Buffered Setpoint (W) or Current Setpoint(R)
|
37 |
|
|
-- 0x4 AAAAAAAA B0 of Current Epoch Time(RO)
|
38 |
|
|
-- 0x5 AAAAAAAA B1 of Current Epoch Time(RO)
|
39 |
|
|
-- 0x6 AAAAAAAA B2 of Current Epoch Time(RO)
|
40 |
|
|
-- 0x7 AAAAAAAA B3 of Current Epoch Time(RO)
|
41 |
|
|
-- 0x8 xxxxxxxx (not used - returns 0x00)
|
42 |
|
|
-- 0x9 xxxxxxxx (not used - returns 0x00)
|
43 |
|
|
-- 0xA xxxxxxxx (not used - returns 0x00)
|
44 |
|
|
-- 0xB xxxxxxxx (not used - returns 0x00)
|
45 |
|
|
-- 0xC xxxxxxxx (not used - returns 0x00)
|
46 |
|
|
-- 0xD xxxxxxxx (not used - returns 0x00)
|
47 |
|
|
-- 0xE -------- Epoch Time Latch/Clear Control Register
|
48 |
|
|
-- Any write to 0xE will clear/reset the all timer regs
|
49 |
|
|
-- 0xF BA------ Status of buffer/alarm (1 = pending, 0 = current)
|
50 |
|
|
-- A = Pending status (R)
|
51 |
|
|
-- B = Alarm status (R)
|
52 |
|
|
-- Note that any write will update the internal set point
|
53 |
|
|
-- and clear the alarm
|
54 |
|
|
-- Note that any write to 0x04,0x05, or 0x06 will copy the
|
55 |
|
|
-- current epoch time to a readable output buffer
|
56 |
|
|
--
|
57 |
|
|
-- Revision History
|
58 |
|
|
-- Author Date Change
|
59 |
|
|
------------------ -------- ---------------------------------------------------
|
60 |
|
|
-- Seth Henry 04/15/20 Created from o8_epoch_timer due to requirement
|
61 |
|
|
-- change.
|
62 |
224 |
jshamlet |
-- Seth Henry 04/16/20 Modifiefd to make use of Open8 bus record
|
63 |
222 |
jshamlet |
|
64 |
|
|
library ieee;
|
65 |
|
|
use ieee.std_logic_1164.all;
|
66 |
|
|
use ieee.std_logic_unsigned.all;
|
67 |
|
|
use ieee.std_logic_arith.all;
|
68 |
|
|
use ieee.std_logic_misc.all;
|
69 |
|
|
|
70 |
|
|
library work;
|
71 |
|
|
use work.open8_pkg.all;
|
72 |
|
|
|
73 |
|
|
entity o8_epoch_timer_ii is
|
74 |
|
|
generic(
|
75 |
|
|
Address : ADDRESS_TYPE
|
76 |
|
|
);
|
77 |
|
|
port(
|
78 |
223 |
jshamlet |
Open8_Bus : in OPEN8_BUS_TYPE;
|
79 |
222 |
jshamlet |
Rd_Data : out DATA_TYPE;
|
80 |
|
|
Interrupt : out std_logic
|
81 |
|
|
);
|
82 |
|
|
end entity;
|
83 |
|
|
|
84 |
|
|
architecture behave of o8_epoch_timer_ii is
|
85 |
|
|
|
86 |
224 |
jshamlet |
alias Clock is Open8_Bus.Clock;
|
87 |
|
|
alias Reset is Open8_Bus.Reset;
|
88 |
|
|
alias uSec_Tick is Open8_Bus.uSec_Tick;
|
89 |
|
|
|
90 |
222 |
jshamlet |
constant User_Addr : std_logic_vector(15 downto 4)
|
91 |
|
|
:= Address(15 downto 4);
|
92 |
|
|
|
93 |
223 |
jshamlet |
alias Comp_Addr is Open8_Bus.Address(15 downto 4);
|
94 |
222 |
jshamlet |
signal Addr_Match : std_logic := '0';
|
95 |
|
|
|
96 |
223 |
jshamlet |
alias Reg_Addr is Open8_Bus.Address(3 downto 0);
|
97 |
222 |
jshamlet |
signal Reg_Addr_q : std_logic_vector(3 downto 0) :=
|
98 |
|
|
(others => '0');
|
99 |
|
|
|
100 |
|
|
signal Wr_En : std_logic := '0';
|
101 |
|
|
signal Wr_Data_q : DATA_TYPE := x"00";
|
102 |
|
|
signal Rd_En : std_logic := '0';
|
103 |
|
|
|
104 |
|
|
signal setpt_buffer : std_logic_vector(31 downto 0) :=
|
105 |
|
|
(others => '0');
|
106 |
|
|
|
107 |
|
|
alias setpt_buffer_b0 is setpt_buffer( 7 downto 0);
|
108 |
|
|
alias setpt_buffer_b1 is setpt_buffer(15 downto 8);
|
109 |
|
|
alias setpt_buffer_b2 is setpt_buffer(23 downto 16);
|
110 |
|
|
alias setpt_buffer_b3 is setpt_buffer(31 downto 24);
|
111 |
|
|
|
112 |
|
|
signal buffer_pending : std_logic := '0';
|
113 |
|
|
signal buffer_update : std_logic := '0';
|
114 |
|
|
|
115 |
|
|
signal epoch_buffer : std_logic_vector(31 downto 0) :=
|
116 |
|
|
(others => '0');
|
117 |
|
|
|
118 |
|
|
alias epoch_buffer_b0 is epoch_buffer( 7 downto 0);
|
119 |
|
|
alias epoch_buffer_b1 is epoch_buffer(15 downto 8);
|
120 |
|
|
alias epoch_buffer_b2 is epoch_buffer(23 downto 16);
|
121 |
|
|
alias epoch_buffer_b3 is epoch_buffer(31 downto 24);
|
122 |
|
|
|
123 |
|
|
signal capture_epoch : std_logic := '0';
|
124 |
|
|
|
125 |
|
|
signal timer_clear : std_logic := '0';
|
126 |
|
|
|
127 |
|
|
signal epoch_tmr : std_logic_vector(31 downto 0) :=
|
128 |
|
|
(others => '0');
|
129 |
|
|
|
130 |
|
|
alias epoch_tmrcmp is epoch_tmr(31 downto 2);
|
131 |
|
|
signal epoch_setpt : std_logic_vector(31 downto 0) :=
|
132 |
|
|
(others => '0');
|
133 |
|
|
|
134 |
|
|
alias epoch_setpt_b0 is epoch_setpt( 7 downto 0);
|
135 |
|
|
alias epoch_setpt_b1 is epoch_setpt(15 downto 8);
|
136 |
|
|
alias epoch_setpt_b2 is epoch_setpt(23 downto 16);
|
137 |
|
|
alias epoch_setpt_b3 is epoch_setpt(31 downto 24);
|
138 |
|
|
|
139 |
|
|
signal epoch_alarm : std_logic := '0';
|
140 |
|
|
signal epoch_alarm_q : std_logic := '0';
|
141 |
|
|
|
142 |
|
|
begin
|
143 |
|
|
|
144 |
|
|
Addr_Match <= '1' when Comp_Addr = User_Addr else '0';
|
145 |
|
|
|
146 |
|
|
io_reg: process( Clock, Reset )
|
147 |
|
|
begin
|
148 |
|
|
if( Reset = Reset_Level )then
|
149 |
|
|
Wr_Data_q <= (others => '0');
|
150 |
|
|
Reg_Addr_q <= (others => '0');
|
151 |
|
|
Wr_En <= '0';
|
152 |
|
|
Rd_En <= '0';
|
153 |
|
|
Rd_Data <= OPEN8_NULLBUS;
|
154 |
|
|
setpt_buffer <= (others => '0');
|
155 |
|
|
buffer_pending <= '0';
|
156 |
|
|
buffer_update <= '0';
|
157 |
|
|
capture_epoch <= '0';
|
158 |
|
|
timer_clear <= '0';
|
159 |
|
|
elsif( rising_edge( Clock ) )then
|
160 |
|
|
|
161 |
|
|
Reg_Addr_q <= Reg_Addr;
|
162 |
223 |
jshamlet |
Wr_En <= Addr_Match and Open8_Bus.Wr_En;
|
163 |
|
|
Wr_Data_q <= Open8_Bus.Wr_Data;
|
164 |
222 |
jshamlet |
|
165 |
|
|
buffer_update <= '0';
|
166 |
|
|
timer_clear <= '0';
|
167 |
|
|
capture_epoch <= '0';
|
168 |
|
|
|
169 |
|
|
if( Wr_En = '1' )then
|
170 |
|
|
case( Reg_Addr_q )is
|
171 |
|
|
when x"0" =>
|
172 |
|
|
setpt_buffer_b0 <= Wr_Data_q;
|
173 |
|
|
buffer_pending <= '1';
|
174 |
|
|
|
175 |
|
|
when x"1" =>
|
176 |
|
|
setpt_buffer_b1 <= Wr_Data_q;
|
177 |
|
|
buffer_pending <= '1';
|
178 |
|
|
|
179 |
|
|
when x"2" =>
|
180 |
|
|
setpt_buffer_b2 <= Wr_Data_q;
|
181 |
|
|
buffer_pending <= '1';
|
182 |
|
|
|
183 |
|
|
when x"3" =>
|
184 |
|
|
setpt_buffer_b3 <= Wr_Data_q;
|
185 |
|
|
buffer_pending <= '1';
|
186 |
|
|
|
187 |
|
|
when x"4" | x"5" | x"6" | x"7" =>
|
188 |
|
|
capture_epoch <= '1';
|
189 |
|
|
|
190 |
|
|
when x"E" =>
|
191 |
|
|
timer_clear <= '1';
|
192 |
|
|
|
193 |
|
|
when x"F" =>
|
194 |
|
|
buffer_update <= '1';
|
195 |
|
|
buffer_pending <= '0';
|
196 |
|
|
|
197 |
|
|
when others => null;
|
198 |
|
|
end case;
|
199 |
|
|
end if;
|
200 |
|
|
|
201 |
|
|
Rd_Data <= OPEN8_NULLBUS;
|
202 |
223 |
jshamlet |
Rd_En <= Addr_Match and Open8_Bus.Rd_En;
|
203 |
222 |
jshamlet |
if( Rd_En = '1' )then
|
204 |
|
|
case( Reg_Addr_q )is
|
205 |
|
|
when x"0" =>
|
206 |
|
|
Rd_Data <= epoch_setpt_b0;
|
207 |
|
|
when x"1" =>
|
208 |
|
|
Rd_Data <= epoch_setpt_b1;
|
209 |
|
|
when x"2" =>
|
210 |
|
|
Rd_Data <= epoch_setpt_b2;
|
211 |
|
|
when x"3" =>
|
212 |
|
|
Rd_Data <= epoch_setpt_b3;
|
213 |
|
|
when x"4" =>
|
214 |
|
|
Rd_Data <= epoch_buffer_b0;
|
215 |
|
|
when x"5" =>
|
216 |
|
|
Rd_Data <= epoch_buffer_b1;
|
217 |
|
|
when x"6" =>
|
218 |
|
|
Rd_Data <= epoch_buffer_b2;
|
219 |
|
|
when x"7" =>
|
220 |
|
|
Rd_Data <= epoch_buffer_b3;
|
221 |
|
|
when x"F" =>
|
222 |
|
|
Rd_Data <= epoch_alarm & buffer_pending & "000000";
|
223 |
|
|
when others => null;
|
224 |
|
|
end case;
|
225 |
|
|
end if;
|
226 |
|
|
end if;
|
227 |
|
|
end process;
|
228 |
|
|
|
229 |
|
|
timer_proc: process( Clock, Reset )
|
230 |
|
|
begin
|
231 |
|
|
if( Reset = Reset_Level )then
|
232 |
|
|
epoch_setpt <= (others => '0');
|
233 |
|
|
epoch_buffer <= (others => '0');
|
234 |
|
|
epoch_tmr <= (others => '0');
|
235 |
|
|
epoch_alarm <= '0';
|
236 |
|
|
epoch_alarm_q <= '0';
|
237 |
|
|
Interrupt <= '0';
|
238 |
|
|
|
239 |
|
|
elsif( rising_edge(Clock) )then
|
240 |
|
|
|
241 |
|
|
epoch_tmr <= epoch_tmr + uSec_Tick;
|
242 |
|
|
|
243 |
|
|
if( epoch_tmr > epoch_setpt )then
|
244 |
|
|
epoch_alarm <= or_reduce(epoch_setpt);
|
245 |
|
|
end if;
|
246 |
|
|
|
247 |
|
|
if( buffer_update = '1' )then
|
248 |
|
|
epoch_setpt <= setpt_buffer;
|
249 |
|
|
epoch_alarm <= '0';
|
250 |
|
|
end if;
|
251 |
|
|
|
252 |
|
|
if( timer_clear = '1' )then
|
253 |
|
|
epoch_setpt <= (others => '0');
|
254 |
|
|
epoch_tmr <= (others => '0');
|
255 |
|
|
epoch_alarm <= '0';
|
256 |
|
|
end if;
|
257 |
|
|
|
258 |
|
|
epoch_alarm_q <= epoch_alarm;
|
259 |
|
|
Interrupt <= epoch_alarm and not epoch_alarm_q;
|
260 |
|
|
|
261 |
|
|
if( capture_epoch = '1' )then
|
262 |
|
|
epoch_buffer <= epoch_tmr;
|
263 |
|
|
end if;
|
264 |
|
|
|
265 |
|
|
end if;
|
266 |
|
|
end process;
|
267 |
|
|
|
268 |
|
|
end architecture;
|