| 1 |
7 |
dbrochart |
######################################################################
|
| 2 |
|
|
#### ####
|
| 3 |
|
|
#### limiter.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, always_comb
|
| 44 |
|
|
|
| 45 |
|
|
def limiter(a, b, y1, y2, y1Int, y2Int, aLim, bLim, y1Lim, y2Lim, y1IntLim, y2IntLim, n = 4):
|
| 46 |
|
|
""" Limiter [-2**(n - 1) + 1, 2**(n - 1) - 1].
|
| 47 |
|
|
|
| 48 |
|
|
n -- number of bits for the coding of the decoder input signals
|
| 49 |
|
|
a, b, y1, y2, y1Int, y2Int -- in : decoder input signals, coded with n bits
|
| 50 |
|
|
aLim, bLim, y1Lim, y2Lim, y1IntLim, y2IntLim -- out : limited signals
|
| 51 |
|
|
|
| 52 |
|
|
"""
|
| 53 |
|
|
@always_comb
|
| 54 |
|
|
def limitLogic():
|
| 55 |
|
|
if a.val <= -2**(n - 1):
|
| 56 |
|
|
aLim.next = -2**(n - 1) + 1
|
| 57 |
|
|
elif a.val >= 2**(n - 1):
|
| 58 |
|
|
aLim.next = 2**(n - 1) - 1
|
| 59 |
|
|
else:
|
| 60 |
|
|
aLim.next = a.val
|
| 61 |
|
|
if b.val <= -2**(n - 1):
|
| 62 |
|
|
bLim.next = -2**(n - 1) + 1
|
| 63 |
|
|
elif b.val >= 2**(n - 1):
|
| 64 |
|
|
bLim.next = 2**(n - 1) - 1
|
| 65 |
|
|
else:
|
| 66 |
|
|
bLim.next = b.val
|
| 67 |
|
|
if y1.val <= -2**(n - 1):
|
| 68 |
|
|
y1Lim.next = -2**(n - 1) + 1
|
| 69 |
|
|
elif y1.val >= 2**(n - 1):
|
| 70 |
|
|
y1Lim.next = 2**(n - 1) - 1
|
| 71 |
|
|
else:
|
| 72 |
|
|
y1Lim.next = y1.val
|
| 73 |
|
|
if y2.val <= -2**(n - 1):
|
| 74 |
|
|
y2Lim.next = -2**(n - 1) + 1
|
| 75 |
|
|
elif y2.val >= 2**(n - 1):
|
| 76 |
|
|
y2Lim.next = 2**(n - 1) - 1
|
| 77 |
|
|
else:
|
| 78 |
|
|
y2Lim.next = y2.val
|
| 79 |
|
|
if y1Int.val <= -2**(n - 1):
|
| 80 |
|
|
y1IntLim.next = -2**(n - 1) + 1
|
| 81 |
|
|
elif y1Int.val >= 2**(n - 1):
|
| 82 |
|
|
y1IntLim.next = 2**(n - 1) - 1
|
| 83 |
|
|
else:
|
| 84 |
|
|
y1IntLim.next = y1Int.val
|
| 85 |
|
|
if y2Int.val <= -2**(n - 1):
|
| 86 |
|
|
y2IntLim.next = -2**(n - 1) + 1
|
| 87 |
|
|
elif y2Int.val >= 2**(n - 1):
|
| 88 |
|
|
y2IntLim.next = 2**(n - 1) - 1
|
| 89 |
|
|
else:
|
| 90 |
|
|
y2IntLim.next = y2Int.val
|
| 91 |
|
|
return limitLogic
|