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

Subversion Repositories sd_mmc_emulator

[/] [sd_mmc_emulator/] [trunk/] [rtl/] [flancter_pack.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jclaytons
--------------------------------------------------------------------------
2
-- Package of flancter components
3
--
4
--
5
 
6
library ieee;
7
use ieee.std_logic_1164.all;
8
use ieee.numeric_std.all;
9
 
10
package flancter_pack is
11
 
12
  component flancter
13
  port (
14
    async_rst_n : in  std_logic;
15
    set_clk     : in  std_logic;
16
    set_ce      : in  std_logic;
17
    reset_clk   : in  std_logic;
18
    reset_ce    : in  std_logic;
19
    flag_s_o    : out std_logic;
20
    flag_r_o    : out std_logic;
21
    flag_o      : out std_logic
22
    );
23
  end component;
24
 
25
  component flancter_fastflag
26
  port (
27
    async_rst_n : in  std_logic;
28
    set_clk     : in  std_logic;
29
    set_ce      : in  std_logic;
30
    reset_clk   : in  std_logic;
31
    reset_ce    : in  std_logic;
32
    flag_s_o    : out std_logic;
33
    flag_r_o    : out std_logic;
34
    flag_o      : out std_logic
35
    );
36
  end component;
37
 
38
  component flancter_rising
39
  port (
40
    async_rst_n : in  std_logic;
41
    set_clk     : in  std_logic;
42
    set         : in  std_logic;
43
    reset_clk   : in  std_logic;
44
    reset       : in  std_logic;
45
    flag_s_o    : out std_logic;
46
    flag_r_o    : out std_logic;
47
    flag_o      : out std_logic
48
    );
49
  end component;
50
 
51
  component flancter_rising_pulseout
52
  port (
53
    async_rst_n : in  std_logic;
54
    set_clk     : in  std_logic;
55
    set         : in  std_logic;
56
    reset_clk   : in  std_logic;
57
    reset       : in  std_logic;
58
    pulse_s_o   : out std_logic;
59
    pulse_r_o   : out std_logic;
60
    flag_o      : out std_logic
61
    );
62
  end component;
63
 
64
end flancter_pack;
65
 
66
package body flancter_pack is
67
end flancter_pack;
68
 
69
-------------------------------------------------------------------------------
70
-- Basic Flancter Component
71
-------------------------------------------------------------------------------
72
--
73
-- Author: John Clayton
74
-- Update: May   1, 2013 Copied code from Rob Weinstein's MEMEC flancter
75
--                       app note.  Formatted it, and wrote a short
76
--                       description.
77
--
78
-- Description
79
-------------------------------------------------------------------------------
80
-- This is a simple set/reset flag that crosses clock domains in a safe
81
-- manner.
82
-- For further details, see Rob Weinstein's MEMEC app. note
83
-- (Which probably was a Xilinx app. note at one time...)
84
--
85
--
86
 
87
 
88
library IEEE;
89
use IEEE.STD_LOGIC_1164.ALL;
90
 
91
  entity flancter is
92
  port (
93
    async_rst_n : in  std_logic;
94
    set_clk     : in  std_logic;
95
    set_ce      : in  std_logic;
96
    reset_clk   : in  std_logic;
97
    reset_ce    : in  std_logic;
98
    flag_s_o    : out std_logic;
99
    flag_r_o    : out std_logic;
100
    flag_o      : out std_logic
101
    );
102
  end flancter;
103
 
104
architecture beh of flancter is
105
 
106
-- Signals
107
signal setflop : std_logic;
108
signal rstflop : std_logic;
109
signal flag    : std_logic;
110
 
111
begin
112
 
113
  --The Set flip-flop
114
  set_proc:process(async_rst_n, set_clk)
115
  begin
116
    if async_rst_n='0' then
117
      setflop <= '0';
118
      flag_s_o <= '0';
119
    elsif rising_edge(set_clk) then
120
      if set_ce = '1' then
121
        -- Flops get opposite logic levels.
122
        setflop <= not rstflop;
123
      end if;
124
      flag_s_o <= flag;
125
    end if;
126
  end process;
127
 
128
  --The Reset flip-flop
129
  reset_proc:process(async_rst_n, reset_clk)
130
  begin
131
    if async_rst_n='0' then
132
      rstflop <= '0';
133
      flag_r_o <= '0';
134
    elsif rising_edge(reset_clk) then
135
      if reset_ce = '1' then
136
        -- Flops get the same logic levels.
137
        rstflop <= setflop;
138
      end if;
139
      flag_r_o <= flag;
140
    end if;
141
  end process;
142
 
143
flag <= setflop xor rstflop;
144
flag_o <= flag;
145
 
146
end beh;
147
 
148
 
149
-------------------------------------------------------------------------------
150
-- Flancter Component - "Fast Flag" version
151
-------------------------------------------------------------------------------
152
--
153
-- Author: John Clayton
154
-- Update: May   1, 2013 Copied code from flancter, updated it to set and
155
--                       clear flags as early as possible!  The original
156
--                       has a one clock cycle delay before the synchronized
157
--                       flags reflect the state of the raw flag.
158
--
159
-- Description
160
-------------------------------------------------------------------------------
161
-- This is a simple set/reset flag that crosses clock domains in a safe
162
-- manner.
163
-- For further details, see Rob Weinstein's MEMEC app. note
164
-- (Which probably was a Xilinx app. note at one time...)
165
--
166
--
167
 
168
 
169
library IEEE;
170
use IEEE.STD_LOGIC_1164.ALL;
171
 
172
  entity flancter_fastflag is
173
  port (
174
    async_rst_n : in  std_logic;
175
    set_clk     : in  std_logic;
176
    set_ce      : in  std_logic;
177
    reset_clk   : in  std_logic;
178
    reset_ce    : in  std_logic;
179
    flag_s_o    : out std_logic;
180
    flag_r_o    : out std_logic;
181
    flag_o      : out std_logic
182
    );
183
  end flancter_fastflag;
184
 
185
architecture beh of flancter_fastflag is
186
 
187
-- Signals
188
signal setflop : std_logic;
189
signal rstflop : std_logic;
190
signal flag    : std_logic;
191
 
192
begin
193
 
194
  --The Set flip-flop
195
  set_proc:process(async_rst_n, set_clk)
196
  begin
197
    if async_rst_n='0' then
198
      setflop <= '0';
199
      flag_s_o <= '0';
200
    elsif rising_edge(set_clk) then
201
      flag_s_o <= flag;
202
      if set_ce = '1' then
203
        -- Flops get opposite logic levels.
204
        setflop <= not rstflop;
205
        flag_s_o <= '1'; -- Fast action!
206
      end if;
207
    end if;
208
  end process;
209
 
210
  --The Reset flip-flop
211
  reset_proc:process(async_rst_n, reset_clk)
212
  begin
213
    if async_rst_n='0' then
214
      rstflop <= '0';
215
      flag_r_o <= '0';
216
    elsif rising_edge(reset_clk) then
217
      flag_r_o <= flag;
218
      if reset_ce = '1' then
219
        -- Flops get the same logic levels.
220
        rstflop <= setflop;
221
        flag_r_o <= '0'; -- Fast action!
222
      end if;
223
    end if;
224
  end process;
225
 
226
flag <= setflop xor rstflop;
227
flag_o <= flag;
228
 
229
end beh;
230
 
231
 
232
-------------------------------------------------------------------------------
233
-- Flancter Component with rising edge detection on set/reset inputs
234
-------------------------------------------------------------------------------
235
--
236
-- Author: John Clayton
237
-- Update: May   2, 2013 Copied code from basic flancter, and added rising
238
--                       edge detectors.
239
--
240
-- Description
241
-------------------------------------------------------------------------------
242
-- This is a simple set/reset flag that crosses clock domains in a safe
243
-- manner.
244
-- For further details, see Rob Weinstein's MEMEC app. note
245
-- (Which probably was a Xilinx app. note at one time...)
246
--
247
--
248
 
249
 
250
library IEEE;
251
use IEEE.STD_LOGIC_1164.ALL;
252
 
253
  entity flancter_rising is
254
  port (
255
    async_rst_n : in  std_logic;
256
    set_clk     : in  std_logic;
257
    set         : in  std_logic;
258
    reset_clk   : in  std_logic;
259
    reset       : in  std_logic;
260
    flag_s_o    : out std_logic;
261
    flag_r_o    : out std_logic;
262
    flag_o      : out std_logic
263
    );
264
  end flancter_rising;
265
 
266
architecture beh of flancter_rising is
267
 
268
-- Signals
269
signal setflop   : std_logic;
270
signal rstflop   : std_logic;
271
signal flag      : std_logic;
272
signal set_ce    : std_logic;
273
signal reset_ce  : std_logic;
274
signal set_r1    : std_logic;
275
signal reset_r1  : std_logic;
276
 
277
begin
278
 
279
  --The Set flip-flop
280
  set_proc:process(async_rst_n, set_clk)
281
  begin
282
    if async_rst_n='0' then
283
      setflop <= '0';
284
      flag_s_o <= '0';
285
      set_r1 <= '1';
286
    elsif rising_edge(set_clk) then
287
      set_r1 <= set;
288
      if set_ce = '1' then
289
        -- Flops get opposite logic levels.
290
        setflop <= not rstflop;
291
      end if;
292
      flag_s_o <= flag;
293
    end if;
294
  end process;
295
  set_ce <= '1' when set='1' and set_r1='0' else '0';
296
 
297
  --The Reset flip-flop
298
  reset_proc:process(async_rst_n, reset_clk)
299
  begin
300
    if async_rst_n='0' then
301
      rstflop <= '0';
302
      flag_r_o <= '0';
303
      reset_r1 <= '0';
304
    elsif rising_edge(reset_clk) then
305
      reset_r1 <= reset;
306
      if reset_ce = '1' then
307
        -- Flops get the same logic levels.
308
        rstflop <= setflop;
309
      end if;
310
      flag_r_o <= flag;
311
    end if;
312
  end process;
313
  reset_ce <= '1' when reset='1' and reset_r1='0' else '0';
314
 
315
flag <= setflop xor rstflop;
316
flag_o <= flag;
317
 
318
end beh;
319
 
320
 
321
-------------------------------------------------------------------------------
322
-- Flancter Component with rising edge detection on set/reset inputs,
323
-- and outputs which go high for a single clock pulse.
324
-------------------------------------------------------------------------------
325
--
326
-- Author: John Clayton
327
-- Update: May   2, 2013 Copied code from flancter_rising, and added rising
328
--                       edge detectors to the outputs, changing them from
329
--                       "flags" to "pulses".
330
--
331
-- Description
332
-------------------------------------------------------------------------------
333
-- This is a simple set/reset flag that crosses clock domains in a safe
334
-- manner.
335
-- For further details, see Rob Weinstein's MEMEC app. note
336
-- (Which probably was a Xilinx app. note at one time...)
337
--
338
--
339
 
340
 
341
library IEEE;
342
use IEEE.STD_LOGIC_1164.ALL;
343
 
344
  entity flancter_rising_pulseout is
345
  port (
346
    async_rst_n : in  std_logic;
347
    set_clk     : in  std_logic;
348
    set         : in  std_logic;
349
    reset_clk   : in  std_logic;
350
    reset       : in  std_logic;
351
    pulse_s_o   : out std_logic;
352
    pulse_r_o   : out std_logic;
353
    flag_o      : out std_logic
354
    );
355
  end flancter_rising_pulseout;
356
 
357
architecture beh of flancter_rising_pulseout is
358
 
359
-- Signals
360
signal setflop    : std_logic;
361
signal rstflop    : std_logic;
362
signal flag       : std_logic;
363
signal set_ce     : std_logic;
364
signal reset_ce   : std_logic;
365
signal set_r1     : std_logic;
366
signal reset_r1   : std_logic;
367
signal pulse_s_r1 : std_logic;
368
signal pulse_s_r2 : std_logic;
369
signal pulse_r_r1 : std_logic;
370
signal pulse_r_r2 : std_logic;
371
 
372
begin
373
 
374
  --The Set flip-flop
375
  set_proc:process(async_rst_n, set_clk)
376
  begin
377
    if async_rst_n='0' then
378
      setflop <= '0';
379
      pulse_s_r1 <= '0';
380
      pulse_s_r2 <= '0';
381
      set_r1 <= '1';
382
    elsif rising_edge(set_clk) then
383
      set_r1 <= set;
384
      if set_ce = '1' then
385
        -- Flops get opposite logic levels.
386
        setflop <= not rstflop;
387
      end if;
388
      pulse_s_r1 <= flag;
389
      pulse_s_r2 <= pulse_s_r1;
390
    end if;
391
  end process;
392
  set_ce <= '1' when set='1' and set_r1='0' else '0';
393
  pulse_s_o <= '1' when pulse_s_r1='1' and pulse_s_r2='0' else '0';
394
 
395
  --The Reset flip-flop
396
  reset_proc:process(async_rst_n, reset_clk)
397
  begin
398
    if async_rst_n='0' then
399
      rstflop <= '0';
400
      pulse_r_r1 <= '0';
401
      pulse_r_r2 <= '0';
402
      reset_r1 <= '0';
403
    elsif rising_edge(reset_clk) then
404
      reset_r1 <= reset;
405
      if reset_ce = '1' then
406
        -- Flops get the same logic levels.
407
        rstflop <= setflop;
408
      end if;
409
      pulse_r_r1 <= flag;
410
      pulse_r_r2 <= pulse_r_r1;
411
    end if;
412
  end process;
413
  reset_ce <= '1' when reset='1' and reset_r1='0' else '0';
414
  pulse_r_o <= '1' when pulse_r_r1='1' and pulse_r_r2='0' else '0';
415
 
416
flag <= setflop xor rstflop;
417
flag_o <= flag;
418
 
419
end beh;
420
 
421
 

powered by: WebSVN 2.1.0

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