1 |
7 |
dbrochart |
######################################################################
|
2 |
|
|
#### ####
|
3 |
|
|
#### punct.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, always_comb, always, posedge, negedge
|
44 |
|
|
|
45 |
|
|
def punct(clk, rst, y1, y2, y1Int, y2Int, y1Punct, y2Punct, y1IntPunct, y2IntPunct, rate = 13):
|
46 |
|
|
""" Puncturing mechanism.
|
47 |
|
|
|
48 |
|
|
rate -- code rate (e.g. 13 for rate 1/3)
|
49 |
|
|
clk, rst -- in : clock and negative reset
|
50 |
|
|
y1, y2, y1Int, y2Int -- in : original data
|
51 |
|
|
y1Punct, y2Punct, y1IntPunct, y2IntPunct -- out : punctured data
|
52 |
|
|
|
53 |
|
|
"""
|
54 |
|
|
y1Sel = Signal(bool(0))
|
55 |
|
|
y2Sel = Signal(bool(0))
|
56 |
|
|
punctSel_i0 = punctSel(clk, rst, y1Sel, y2Sel, rate)
|
57 |
|
|
punctMux_i0 = punctMux(y1Sel, y2Sel, y1, y2, y1Int, y2Int, y1Punct, y2Punct, y1IntPunct, y2IntPunct)
|
58 |
|
|
|
59 |
|
|
return punctSel_i0, punctMux_i0
|
60 |
|
|
|
61 |
|
|
def punctSel(clk, rst, y1Sel, y2Sel, rate = 13):
|
62 |
|
|
""" Puncturing selection (between original data (1) and 0 (0)).
|
63 |
|
|
|
64 |
|
|
clk, rst -- in : clock and negative reset
|
65 |
|
|
y1Sel, y2Sel -- out : selection signals (1 -> original data, 0 -> 0)
|
66 |
|
|
|
67 |
|
|
"""
|
68 |
|
|
if rate == 13:
|
69 |
|
|
pattern = [[1], [1]]
|
70 |
|
|
elif rate == 25:
|
71 |
|
|
pattern = [[1, 1], [1, 0]]
|
72 |
|
|
elif rate == 12:
|
73 |
|
|
pattern = [[1], [0]]
|
74 |
|
|
elif rate == 23:
|
75 |
|
|
pattern = [[1, 0], [0, 0]]
|
76 |
|
|
elif rate == 34:
|
77 |
|
|
pattern = [[1, 0, 0], [0, 0, 0]]
|
78 |
|
|
elif rate == 45:
|
79 |
|
|
pattern = [[1, 0, 0, 0], [0, 0, 0, 0]]
|
80 |
|
|
elif rate == 67:
|
81 |
|
|
pattern = [[1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]
|
82 |
|
|
else:
|
83 |
|
|
print "ERROR: the code rate you specified is not valid!"
|
84 |
|
|
cntMax = len(pattern[0])
|
85 |
|
|
cnt = Signal(intbv(0, 0, cntMax))
|
86 |
|
|
@always(clk.posedge, rst.negedge)
|
87 |
|
|
def punctSelLogic():
|
88 |
|
|
if rst.val == 0:
|
89 |
|
|
y1Sel.next = 0
|
90 |
|
|
y2Sel.next = 0
|
91 |
|
|
cnt.next = 0
|
92 |
|
|
else:
|
93 |
|
|
if cnt.val < cntMax - 1:
|
94 |
|
|
cnt.next = cnt.val + 1
|
95 |
|
|
else:
|
96 |
|
|
cnt.next = 0
|
97 |
|
|
y1Sel.next = pattern[0][int(cnt.val)]
|
98 |
|
|
y2Sel.next = pattern[1][int(cnt.val)]
|
99 |
|
|
return punctSelLogic
|
100 |
|
|
|
101 |
|
|
def punctMux(y1Sel, y2Sel, y1, y2, y1Int, y2Int, y1Punct, y2Punct, y1IntPunct, y2IntPunct):
|
102 |
|
|
""" Puncturing mux.
|
103 |
|
|
|
104 |
|
|
y1Sel, y2Sel -- in : selection signals (1 -> original data, 0 -> 0)
|
105 |
|
|
y1, y2, y1Int, y2Int -- in : original data
|
106 |
|
|
y1Punct, y2Punct, y1IntPunct, y2IntPunct -- out : punctured data
|
107 |
|
|
|
108 |
|
|
"""
|
109 |
|
|
@always_comb
|
110 |
|
|
def punctMuxLogic():
|
111 |
|
|
if y1Sel.val == 1:
|
112 |
|
|
y1Punct.next = y1.val
|
113 |
|
|
y1IntPunct.next = y1Int.val
|
114 |
|
|
else:
|
115 |
|
|
y1Punct.next = 0
|
116 |
|
|
y1IntPunct.next = 0
|
117 |
|
|
if y2Sel.val == 1:
|
118 |
|
|
y2Punct.next = y2.val
|
119 |
|
|
y2IntPunct.next = y2Int.val
|
120 |
|
|
else:
|
121 |
|
|
y2Punct.next = 0
|
122 |
|
|
y2IntPunct.next = 0
|
123 |
|
|
return punctMuxLogic
|