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

Subversion Repositories dmt_tx

[/] [dmt_tx/] [trunk/] [myhdl/] [rtl/] [const_encoder.py] - Blame information for rev 28

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 28 dannori
 
2
from myhdl import *
3
 
4
 
5
def const_encoder( clk, reset, wen_i, const_size_i, data_i,
6
                  data_valid_o, x_o, y_o):
7
  '''Constellation encoder
8
 
9
  I/O pins:
10
  =========
11
  clk           : clock input
12
  reset         : reset input
13
 
14
  wen_i         : write enable for the const_size_i and data_i
15
  const_size_i  : select the constellation size
16
  data_i        : data word to be encoded
17
  data_valid_o  : signal that the output data x_o and y_o are valid
18
                  after an applied wen_i
19
  x_o           : real part of the constellation point
20
  y_o           : imaginary part of the constellation point
21
 
22
  parameters:
23
  ===========
24
 
25
  '''
26
 
27
  din_reg = Signal(intbv(0)[15:])
28
  const_size_i_reg = Signal(intbv(0)[4:])
29
  dvalid_reg = Signal(intbv(0)[1:])
30
 
31
  x,y = [Signal(intbv(0,min=-256,max=256)) for i in range(2)]
32
 
33
  XY = [0,0,0,0, 3,3,3,3, 12,12,12,12, 15,15,15,15, 4,4, 8,8,
34
      1,2,1,2, 13,14,13,14, 7,7,11,11]
35
 
36
  @always(clk.posedge, reset.posedge)
37
  def reg_input():
38
 
39
    if reset:
40
      din_reg.next = 0
41
      const_size_i_reg.next = const_size_i
42
    else:
43
 
44
      if wen_i:
45
        #print "data_i: %d size: %d at %d"%(data_i, const_size_i, now())
46
        din_reg.next = data_i
47
        const_size_i_reg.next = const_size_i
48
 
49
 
50
  @always(clk.posedge, reset.posedge)
51
  def reg_output():
52
 
53
    if reset:
54
      x_o.next = 0
55
      y_o.next = 0
56
      dvalid_reg.next = 0
57
      data_valid_o.next = 0
58
    else:
59
      x_o.next = x
60
      y_o.next = y
61
      #print "x_o: %d y_o: %d at %d"%(x_o,y_o,now())
62
 
63
      dvalid_reg.next[0] = wen_i
64
      data_valid_o.next = dvalid_reg[0]
65
 
66
 
67
  @always_comb
68
  def const_enc():
69
 
70
    if const_size_i_reg[0] == 0:    # even constellation
71
 
72
      if const_size_i_reg == 2:
73
        x.next = concat(din_reg[1], True).signed()
74
        y.next = concat(din_reg[0], True).signed()
75
        #x.next = concat(din_reg[1], True)
76
        #y.next = concat(din_reg[0], True)
77
      elif const_size_i_reg == 4:
78
        x.next = concat(din_reg[3], din_reg[1], True).signed()
79
        y.next = concat(din_reg[2], din_reg[0], True).signed()
80
        #x.next = concat(din_reg[3], din_reg[1], True)
81
        #y.next = concat(din_reg[2], din_reg[0], True)
82
 
83
    else:                           # odd constellation
84
 
85
      if const_size_i_reg == 3:
86
        if din_reg == 4:
87
          x.next = -3
88
          y.next = 1
89
        elif din_reg == 5:
90
          x.next = 1
91
          y.next = 3
92
        elif din_reg == 6:
93
          x.next = -1
94
          y.next = -3
95
        elif din_reg == 7:
96
          x.next =  3
97
          y.next = -1
98
        else:
99
          x.next = concat(din_reg[1], True).signed()
100
          y.next = concat(din_reg[0], True).signed()
101
 
102
      else:
103
        addr = concat(  din_reg[const_size_i_reg-1],
104
                        din_reg[const_size_i_reg-2],
105
                        din_reg[const_size_i_reg-3],
106
                        din_reg[const_size_i_reg-4],
107
                        din_reg[const_size_i_reg-5])
108
 
109
        xy = intbv(XY[int(addr)])[4:]
110
        top2X = xy[4:2]
111
        top2Y = xy[2:0]
112
 
113
        if const_size_i_reg == 5:
114
          x.next = concat(top2X, din_reg[1], True).signed()
115
          y.next = concat(top2Y, din_reg[0], True).signed()
116
 
117
  return instances()
118
 
119
 
120
########################################################################
121
def convert():
122
 
123
  clk, reset, \
124
      wen_i, data_valid_o \
125
      = [Signal(bool(0)) for i in range(4)]
126
 
127
  const_size_i = Signal(intbv(0)[4:])
128
  data_i = Signal(intbv(0)[15:])
129
  x_o, y_o = [Signal(intbv(0, min=-256, max=256)) for i in range(2)]
130
 
131
  toVerilog(const_encoder,
132
            clk, reset,
133
            wen_i, const_size_i,
134
            data_i,
135
            data_valid_o, x_o, y_o)
136
 
137
 
138
if __name__ == '__main__':
139
  convert()

powered by: WebSVN 2.1.0

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