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

Subversion Repositories dmt_tx

[/] [dmt_tx/] [trunk/] [myhdl/] [rtl/] [fifo_sync.py] - Blame information for rev 30

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 dannori
 
2
from myhdl import *
3
 
4
 
5
 
6
def fifo_sync(clk, reset,
7
              full_o, wen_i, data_i,
8
              data_avail_o, rden_i, data_o,
9
              DWIDTH=8, SIZE=8):
10
  '''FIFO with clock synchronous read and write
11
 
12
  I/O pins:
13
  =========
14
  clk           : clock signal
15
  reset         : reset will empty the memory and reset full_o and
16
                  data_avail_o signals
17
  full_o        : signal that the FIFO is full. No further input data
18
                  are taken.
19
  wen_i         : write enable for the data_i data
20
  data_i        : input data with data width as specified by DWIDTH
21
 
22
  data_avail_o  : signal that there are data in the FIFO available for
23
                  reading out
24
  rden_i        : read enable for the data_o signal
25
  data_o        : output data. Only valid if the data_avail_o signal is
26
                  active
27
 
28
  parameters:
29
  ===========
30
 
31
  DWIDTH  : data width
32
  SIZE    : size of the FIFO
33
  '''
34
 
35
  mem = [Signal(intbv(0)[DWIDTH:]) for i in range(SIZE)]
36
  wp, rp = [Signal(int(0)) for i in range(2)]
37
  fill_ctr = Signal(intbv(0, min=0, max=SIZE+1))
38
 
39
  @always(clk.posedge, reset.posedge)
40
  def write_data():
41
 
42
    if reset:
43
      data_o.next = 0
44
      rp.next = 0
45
 
46
    else:
47
      if wen_i and not full_o:
48
        mem[wp.val].next = data_i
49
        if wp < SIZE-1:
50
          wp.next = wp + 1
51
        else:
52
          wp.next = 0
53
 
54
  @always(clk.posedge, reset.posedge)
55
  def read_data():
56
 
57
    if reset:
58
      data_o.next = 0
59
      rp.next = 0
60
 
61
    else:
62
      if rden_i and data_avail_o:
63
        data_o.next = mem[rp.val]
64
        if rp < SIZE-1:
65
          rp.next = rp + 1
66
        else:
67
          rp.next = 0
68
 
69
 
70
  @always(clk.posedge, reset.posedge)
71
  def count_load():
72
 
73
    if reset:
74
      fill_ctr.next = 0
75
    else:
76
 
77
      if (rden_i and data_avail_o) and not (wen_i and not full_o) \
78
          and (fill_ctr > 0):
79
 
80
            fill_ctr.next = fill_ctr - 1
81
 
82
      elif (wen_i and not full_o) and not (rden_i and data_avail_o) \
83
          and (fill_ctr < SIZE):
84
 
85
            fill_ctr.next = fill_ctr + 1
86
 
87
 
88
  @always_comb
89
  def comb():
90
    if fill_ctr == SIZE:
91
      full_o.next = 1
92
    else:
93
      full_o.next = 0
94
 
95
    if fill_ctr > 0:
96
      data_avail_o.next = 1
97
    else:
98
      data_avail_o.next = 0
99
 
100
  return instances()

powered by: WebSVN 2.1.0

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