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

Subversion Repositories dmt_tx

[/] [dmt_tx/] [trunk/] [myhdl/] [rtl/] [queue.py] - Blame information for rev 33

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 33 dannori
 
2
from myhdl import *
3
 
4
def queue(clk, reset, shift, d_i, d_o, qlen=3):
5
  '''Queue of specified length consists of registers that will shift
6
  their content and enter input data when the shift signal is activ.
7
  When inactive content of the current registers will be kept.
8
 
9
  I/O pins:
10
  =========
11
  clk     : shifting and registering input data happens synchronous to
12
            the clock signal
13
  reset   : reset all registers to 0
14
  shift   : input data at d_i will be registered to the first register
15
            and content of each register will be shifted to the next
16
            register. The content of the last register will be dropped
17
  d_i     : input data, will be registered to the first register if
18
            the shift signal is active
19
  d_o     : output data, resembles the data of the last register
20
 
21
  parameter:
22
  ==========
23
  qlen  :   number of registers in the queue
24
 
25
  '''
26
  m = 2**(len(d_i)-1)
27
  chain = [Signal(intbv(0, min=-m, max=m)) for i in range(qlen-1)]
28
 
29
  reg_inst = [None for i in range(qlen)]
30
 
31
 
32
  for i in range(qlen):
33
    if i == 0:
34
      reg_inst[i] = simple_reg(clk, reset, shift, d_i, chain[i])
35
    elif i > 0 and i < (qlen-1):
36
      reg_inst[i] = simple_reg(clk, reset, shift, chain[i-1], chain[i])
37
    elif i == (qlen-1):
38
      reg_inst[i] = simple_reg(clk, reset, shift, chain[i-1], d_o)
39
 
40
  return instances()
41
 
42
 
43
 
44
def simple_reg(clk, reset, w_en, d_i, d_o):
45
  '''Simple register is the unit of the queue. It will register the
46
  input when w_en is active, remain the current value on inactive w_en
47
  and reset the value on active reset.
48
  '''
49
  @always (clk.posedge)
50
  def reg_logic():
51
    if reset == 1:
52
      d_o.next = 0
53
    else:
54
 
55
      if w_en:
56
        d_o.next = d_i
57
      else:
58
        d_o.next = d_o
59
  return instances()

powered by: WebSVN 2.1.0

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