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

Subversion Repositories turbocodes

[/] [turbocodes/] [trunk/] [src/] [myhdl/] [interleaver.py] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 dbrochart
######################################################################
2
####                                                              ####
3
####  interleaver.py                                              ####
4
####                                                              ####
5
####  This file is part of the turbo decoder IP core project      ####
6
####  http://www.opencores.org/projects/turbocodes/               ####
7
####                                                              ####
8
####  Author(s):                                                  ####
9
####      - David Brochart(dbrochart@opencores.org)               ####
10
####                                                              ####
11
####  All additional information is available in the README.txt   ####
12
####  file.                                                       ####
13
####                                                              ####
14
######################################################################
15
####                                                              ####
16
#### Copyright (C) 2005 Authors                                   ####
17
####                                                              ####
18
#### This source file may be used and distributed without         ####
19
#### restriction provided that this copyright statement is not    ####
20
#### removed from the file and that any derivative work contains  ####
21
#### the original copyright notice and the associated disclaimer. ####
22
####                                                              ####
23
#### This source file is free software; you can redistribute it   ####
24
#### and/or modify it under the terms of the GNU Lesser General   ####
25
#### Public License as published by the Free Software Foundation; ####
26
#### either version 2.1 of the License, or (at your option) any   ####
27
#### later version.                                               ####
28
####                                                              ####
29
#### This source is distributed in the hope that it will be       ####
30
#### useful, but WITHOUT ANY WARRANTY; without even the implied   ####
31
#### warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ####
32
#### PURPOSE. See the GNU Lesser General Public License for more  ####
33
#### details.                                                     ####
34
####                                                              ####
35
#### You should have received a copy of the GNU Lesser General    ####
36
#### Public License along with this source; if not, download it   ####
37
#### from http://www.opencores.org/lgpl.shtml                     ####
38
####                                                              ####
39
######################################################################
40
 
41
 
42
 
43
from myhdl import Signal, intbv, posedge, negedge, always
44
 
45
def interleaver(clk, rst, d, q, frSize = 48, delay = 0, minVal = 0, maxVal = 2, dim = 2, way = 0):
46
    """ DVB-RCS (de)interleaver.
47
 
48
    frSize          -- frame size
49
    delay           -- number of clock cycles to wait before starting the (de)interleaver
50
    minVal, maxVal  -- min and max values of the stored signals
51
    dim             -- number of dimensions of the stored signals
52
    way             -- 0 for interleaving, 1 for deinterleaving
53
    clk, rst        -- in  : clock and negative reset
54
    d               -- in  : input data
55
    q               -- out : interleaved data
56
 
57
    """
58
    array1 = [[Signal(intbv(0, minVal, maxVal)) for l in range(dim)] for k in range(frSize)]
59
    array2 = [[Signal(intbv(0, minVal, maxVal)) for l in range(dim)] for k in range(frSize)]
60
    full = Signal(bool(0))
61
    i = Signal(intbv(0, 0, frSize))
62
    j = Signal(intbv(0, 0, frSize))
63
    iTmp = Signal(intbv(0, 0, frSize))
64
    iTmp1 = intbv(0, 0, 2 * frSize)
65
    iTmp2 = intbv(0, 0, 2 * frSize)
66
    iTmp3 = intbv(0, 0, 2 * frSize)
67
    cnt = Signal(intbv(0, 0, delay + 1))
68
    if frSize == 48:
69
        p0 = 11
70
        p1 = 24
71
        p2 = 0
72
        p3 = 24
73
    elif frSize == 64:
74
        p0 = 7
75
        p1 = 34
76
        p2 = 32
77
        p3 = 2
78
    elif frSize == 212:
79
        p0 = 13
80
        p1 = 106
81
        p2 = 108
82
        p3 = 2
83
    elif frSize == 220:
84
        p0 = 23
85
        p1 = 112
86
        p2 = 4
87
        p3 = 116
88
    elif frSize == 228:
89
        p0 = 17
90
        p1 = 116
91
        p2 = 72
92
        p3 = 188
93
    elif frSize == 424:
94
        p0 = 11
95
        p1 = 6
96
        p2 = 8
97
        p3 = 2
98
    elif frSize == 432:
99
        p0 = 13
100
        p1 = 0
101
        p2 = 4
102
        p3 = 8
103
    elif frSize == 440:
104
        p0 = 13
105
        p1 = 10
106
        p2 = 4
107
        p3 = 2
108
    elif frSize == 848:
109
        p0 = 19
110
        p1 = 2
111
        p2 = 16
112
        p3 = 6
113
    elif frSize == 856:
114
        p0 = 19
115
        p1 = 428
116
        p2 = 224
117
        p3 = 652
118
    elif frSize == 864:
119
        p0 = 19
120
        p1 = 2
121
        p2 = 16
122
        p3 = 6
123
    elif frSize == 752:
124
        p0 = 19
125
        p1 = 376
126
        p2 = 224
127
        p3 = 600
128
    else:
129
        print "ERROR: interleaver does not have a valid DVB-RCS frame size!"
130
    @always(clk.posedge, rst.negedge)
131
    def interleaverLogic():
132
        if rst.val == 0:
133
            iTmp.next = 0
134
            i.next = 0
135
            j.next = 0
136
            cnt.next = 0
137
            full.next = 0
138
            for l in range(dim):
139
                q[l].next = 0
140
            for k in range(frSize):
141
                for l in range(dim):
142
                    array1[k][l].next = 0
143
                    array2[k][l].next = 0
144
        else:
145
            if cnt.val < delay:
146
                cnt.next = cnt.val + 1
147
            else:
148
                if j.val[2:0] == 0:
149
                    p = 0
150
                elif j.val[2:0] == 1:
151
                    p = frSize / 2 + p1
152
                elif j.val[2:0] == 2:
153
                    p = p2
154
                else:   # if j.val[2:0] == 3:
155
                    p = frSize / 2 + p3
156
                iTmp1 = iTmp.val + p0
157
                if iTmp1 >= frSize:
158
                    iTmp2 = iTmp1 - frSize
159
                else:
160
                    iTmp2 = iTmp1
161
                iTmp.next = iTmp2
162
                iTmp3 = iTmp2 + p + 1
163
                if iTmp3 >= 2 * frSize:
164
                    i.next = iTmp3 - 2 * frSize
165
                elif iTmp3 >= frSize:
166
                    i.next = iTmp3 - frSize
167
                else:
168
                    i.next = iTmp3
169
#                i.next = intbv((p0 * j.val + p + 1) % frSize)
170
                if j.val == (frSize - 1):
171
                    j.next = 0
172
                    full.next = not full.val
173
                else:
174
                    j.next = j.val + 1
175
                if way == 0:
176
                    ii = i.val
177
                    jj = j.val
178
                else:
179
                    ii = j.val
180
                    jj = i.val
181
                if full.val == 0:
182
                    for l in range(dim):
183
                        array1[int(jj)][l].next = d[l].val
184
                        q[l].next = array2[int(ii)][l].val
185
                else:
186
                    for l in range(dim):
187
                        array2[int(jj)][l].next = d[l].val
188
                        q[l].next = array1[int(ii)][l].val
189
    return interleaverLogic

powered by: WebSVN 2.1.0

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