Compare commits

..

269 Commits

Author SHA1 Message Date
Alexander Chemeris
2061843c3d osmo-trx-dec: Offline demodulation tool.
Change-Id: Ic5b59c7fe1a0c02d962b36de2fd5d7fc9a02f266
2017-06-01 21:19:53 +03:00
Alexander Chemeris
63d0f2a496 WIP:sigProcLib: Reduce burst detection window for NB.
Otherwise we detect bursts with search window far beyond specified.

Change-Id: If3cb40d2311504a13c03e1fbccad663ac201d9a4
2017-06-01 21:19:53 +03:00
Alexander Chemeris
6459ddc55c transceiver: RSSI was calculated reverse. 2017-06-01 21:19:53 +03:00
Alexander Chemeris
7a33c7221b osmo-trx-gen: generates waveform files aka IQ binary files in a number of formats.
Generated files can be used as an input to osmo-trx-dec or load them into signal
generators.

Change-Id: I555d99a632755b5bfcbaf3501a501613c2859d4e
2017-06-01 21:19:53 +03:00
Alexander Chemeris
dd62d4baa0 WIP:sigProcLib: Use a known PRBS to generate random Normal Bursts.
ToDo:
1) Add seed randomization.
2) An option to use a longer PRBS?
3) Use a known PRBS for other types of bursts.

Change-Id: Ib7fdf2f415457da38b78129532d5b80a4a94ecd3
2017-06-01 00:51:24 +03:00
Alexander Chemeris
09130c81a7 osmo-trx: Separate command line switch to enable EDGE filler.
Now -r comand line switch always enables GMSK filler even when EDGE mode is
enabled with -e switch. If you want to enable EDGE filler, use -E switch.

Change-Id: Ic8808bbe3f06740ef3fec1d1865ecb57fbcfabab
2017-06-01 00:51:24 +03:00
Alexander Chemeris
0c4e24d197 PRBS: a Pseudo-random binary sequence (PRBS) generator class.
Implemeted with a Galois LFSR for speed and flexibility compared to Fibonacci version.

Aliases for three popular PRBS' are added for convenience - PRBS9, PRBS15 and PRBS64.

Note that we can't test PRBS64 completely, because the sequence is too long to
be generated.

Change-Id: Ib5331ba5d0b5819929541686fdd87905e2177b74
2017-05-31 17:49:09 +03:00
Alexander Chemeris
15f9d95f5f BitVector: Remove Generator class.
It is not used in osmo-trx, because we're not doing FEC or CRC checks.

Change-Id: I1509e785c1187ebdafe5b2518bd298fbbd1cd036
2017-05-30 20:12:58 +00:00
Alexander Chemeris
73dbccda78 Configuration: Variables allocated with 'new' must be freed with 'delete'.
Thank you Valgrind.

Change-Id: I8477e4e37282947f9841cee9002565631ca0c0b6
2017-05-30 19:19:19 +00:00
Alexander Chemeris
5e65b531e0 sigProcLib: Fix number of tail bits in random Normal Bursts and zero Stealing Bits.
This bug only affects generation of normal bursts filled with random bits which
are used in test mode. It doesn't affect operation of osmo-trx during normal
operation. That's why it has stayed unnoticed for so long.

Each Normal Burst has 3 tail bits, not 4.
Also it's better to set stealing bits to 0 for maximum compatibility. We may want to
introduce a selector for each bit whether to set it to 0, to 1 or to a random number.

Change-Id: I0377029556c8b681b3ba3b635bf19572b34546ea
2017-05-29 15:15:36 +03:00
Max
b992d0a515 debian: remove obsolete dependency
This should fix package build for Ubuntu 17.04: obsolete package
hardening-wrapper was removed which cause .deb build failure.
The dependency on it is incorrect to begin with because we use
DEB_BUILD_MAINT_OPTIONS instead.

Change-Id: I3ea72b4123a280a846086d083c4f3189d611f8cf
2017-05-19 17:26:31 +00:00
Tom Tsou
d6ae8648ff radioInterface: Remove UmTRX 'diversity' option
The 'diversity' option was an experimental 2 antenna receiver
implementation for UmTRX. The implementation has not been
maintained and current working status is unknown.

In addition to code rot, Coverity is triggering errors in the
associated code sections.

Removal of code cleans up many cases of special handling that
were necessary to accommodate the implementation.

Change-Id: I46752ccf5dbcffbec806081dec03e69a0fbdcdb7
2017-05-19 17:25:44 +00:00
Philipp Maier
e51a8f029e cosmetic: Add info about SSE support
The osmo-trx binary outputs no info about its SSE support status.
This commits adds some putput that informs about the SSE of the
binary and also tells which of the SSE levels the CPU supports.

Change-Id: Iacc83fd668c31644e0efb3e18962cf2870ed1daf
2017-05-19 17:23:20 +00:00
Philipp Maier
e8ae9fcf38 buildenv: Split up SSE3 and SSE4.1 code
Currently we find SSE3 and SSE4.1 code mixed togehter along with
generic code in one file. This introduces the risk that the
compiler exidantly mixes SSE4.1 instructions into an SSE3, or
even worse into a generic code path.

This commit splits the SSE3 and SSE4.1 code into separate files
and compiles them with the matching target options.

Change-Id: I846e190e92f1258cd412d1b2d79b539e204e04b3
2017-05-19 17:21:45 +00:00
Philipp Maier
f5bf33b287 buildenv: Make build CPU invariant
Currently the build environment checks which extension the current
CPU supports and picks the compiler flags accordingly.

If the build is happening on a machine that does not support the
extensions we need (SSE3, SSE4.1), the binary will lack those
extensions, even if its intended to be used on a more powerful
machine that would support the extensions.

This commit removes the CPU tests from the build process.

Change-Id: Ic913aa13c23c348ae62e78c9dfd6ed8b0a62798c
2017-05-19 17:19:39 +00:00
Philipp Maier
fe9769833f cosmetic: remove code duplication
The ARM and the X86 implementation of the conversion functions share
the same, non cpu specific implementation in separate files.

This commit removes the code duplication by putting the generic
implementation into a convert_base.c, similar to to convolve_base.c

Change-Id: Ic8d8534a343e27cde79ddc85be4998ebd0cb6e5c
2017-05-19 17:16:37 +00:00
Philipp Maier
7e07cf2346 ssedetect: Add runtime CPU detection
The current implementation can select the SSE support level during
compiletime only.

This commit adds functionality to automatically detect and switch
the SSE support level and automatically switch the Implementation
if the CPU does not support the required SSE level.

Change-Id: Iba74f8a6e4e921ff31e4bd9f0c7c881fe547423a
2017-05-19 17:12:45 +00:00
Philipp Maier
dfe0aef184 Add test program to verify convolution implementation
Convolution is a complex process and we should be able to verify
if computing results change when the implementation is touched.

This commit adds a test program that executes some testcases.
The testcases are crafted in a way that every implmentation
(several different ones for SSE) is executed once. The output
can be compared against the included .ok file.

Change-Id: Ic702ecb356c652fbcd76bee689717fb5d3526fe9
2017-05-19 16:57:25 +00:00
Philipp Maier
131f82bfac cosmetic: Make parameter lists uniform
The non-sse implementation and the sse implementation of the convert
and convolve functions have different parameter lists. This makes it
difficult to use function pointers in order to select the right
function depending on the SSE-Level and CPU.

This commit uniformizes the parameter lists in preparation for
planned runtime cpu detection support

Change-Id: Ice063b89791537c4b591751f12f5ef5c413a2d27
2017-05-02 17:17:57 +00:00
Philipp Maier
78b5627fa1 buildenv: Turn off native architecture builds
The compiler option -march=native instructs the compiler to auto-optimize
the code for the current build architecture. This is fine for building
and using locally, but contraproductive when generating binary packages.

This commit replaces -march=native with $(SIMD_FLAGS), which contains a
collection of supported SIMD options, so we won't loose the SSE support.

Change-Id: I3df4b8db9692016115edbe2247beeec090715687
2017-05-02 10:21:25 +00:00
Tom Tsou
de116e90c0 config: Remove OpenBTS style sqlite configuration
OpenBTS relies on reading in configuration values from the OpenBTS.config
sqlite3 database. This configuration method is not maintained and not
recommended for Osmocom or OpenBTS use. Command line setup is the
recommended approach.

Note that when the osmo-trx logging mechanism is replaced, the sqlite
dependency will be removed.

Change-Id: I95d7b771fde976818bee76f89163e72c3a44ecdd
2017-04-10 06:54:40 +00:00
Tom Tsou
15da7e1f7e Configuration: Fix const and signedness compile warnings
Change-Id: I701559814b2aee6f84f10e612f128da40f6a51c1
2017-04-03 18:55:02 -07:00
Tom Tsou
6031734f44 Transceiver: Remove unsigned negative compares
Change-Id: I49f30699786c52736ef334dae61f7bbd65d878d5
Fixes: Coverity CID 149353, 149356
2017-04-03 18:06:48 +00:00
Tom Tsou
5d2a36a113 Resampler: Fix non-array delete for filter taps
Change-Id: I59cdb01809da5940c74aaae9d17f413aefbf04b2
Fixes: Coverity CID 149349
2017-04-03 18:06:48 +00:00
Tom Tsou
2af14407a8 sigProcLib: Fix negative value check on unsigned value
Convert negative value check on unsigned value to zero check
to avoid potential divide-by-zero error condition.

Change-Id: Ib0d7d1bceb5fe66e69345db93a74e3e0773a2257
Fixes: Coverity CID 165059
2017-03-31 21:43:31 +00:00
Tom Tsou
92bdfb86ac sigProcLib: Check return status on downsampling
Improper length values will cause the polyphase resampler
rotation to fail. Check return and return NULL on error.

Change-Id: I3ad22f9fd7a20754f589c04258dcca3770474a9b
Fixes: Coverity CID 165235
2017-03-31 21:41:04 +00:00
Tom Tsou
ae91f13ecb sigProcLib: Remove unreachable code and no-effect checks
Unreachable path and negative value inspection on unsigned
types.

Change-Id: If53b4b03550b0a7656c808cfe96806252153eb2f
Fixes: Coverity CID 165239, 165238, 165236
2017-03-31 21:41:03 +00:00
Tom Tsou
9d53ecf666 Resampler: Fix initialization return checking
Greater-than comparison was used on boolean type.

Change-Id: Ia3b71b3a06b34a6fd781bf197ecf9d5cc1711d13
2017-03-31 21:40:23 +00:00
Alexander Chemeris
e0c12189d4 sigProcLib: Constify demodulation functions burst argument.
demodCommon() used to scale input vector in place which changed original data.
That's a bad practice and is not really necessary, so I've changed the code to
scale burst after it's copied to a new vector during a delay operation.

Change-Id: Ic45f71b634e48808356d68925bb9f5783e0bf0d3
2017-03-28 14:24:22 +00:00
Alexander Chemeris
1470fcdb5a sigProcLib: constify signalVector arguments for detectBurst() functions.
Change-Id: Ic033371a387353eb12b1827a0eb16c00c07da88a
2017-03-28 14:24:07 +00:00
Alexander Chemeris
6e1dffd486 Move Transceiver::demodulate() to sigProcLib to make it reusable.
Change-Id: I2cad47160e53f65612bd1da8998c83a0a22bce9b
2017-03-28 14:23:56 +00:00
Alexander Chemeris
0229d22d2e sigProcLib.h: Fix whitespaces. No non-whitespace changes.
The file seem to be using "2 spaces" indent, bt some lines are using
tabs which breaks formatting.

Change-Id: I7718cca45c245c9e91250ab2877f5436d4029698
2017-03-28 14:23:44 +00:00
Alexander Chemeris
f7717acd0c sigProcLib: Add operator<< to print CorrType to a string.
Change-Id: I3d68cbdab8fb504d7f155029654a576d318a201e
2017-03-28 14:23:35 +00:00
Alexander Chemeris
b34e60c105 Move BURST_THRESH from Transceiver.cpp to sigProcLib.h to make it reusable.
Change-Id: I5a888890e26858c0fbb2ddb7ef23cb0fd66a64b4
2017-03-28 14:22:01 +00:00
Alexander Chemeris
4e6c938024 Move Transceiver::detectBurst() to sigProcLib to make it reusable.
Change-Id: I3cbe8e6e4f39dde02c945e6c9086c040e276845c
2017-03-24 14:59:24 -07:00
Alexander Chemeris
4aa548f0c2 sigProcLib: rename signalError type to SignalError.
Change-Id: I1a5ae6e87d4c69945053fdefec185d0fb1a26399
2017-03-24 19:54:04 +00:00
Alexander Chemeris
f9e78beea5 Move CorrType type from Transceiver to sigProcLib.
Required to move Transceiver::detectBurst to sigProcLib.

Change-Id: I3e0e74a98bbca4d19657f50a5fb447f078663c9b
2017-03-24 19:54:04 +00:00
Alexander Chemeris
f0189c47be vector: Introduce shrink() function to shrink vector size without loosing data.
Change-Id: I9c0ac2715aea1a90c9e6ebcd982522b80a547099
2017-03-24 01:25:06 +00:00
Alexander Chemeris
c708816be1 vector: Introduce segmentMove() method to move data inside of a vector.
Change-Id: I2f3f4267b4137a0bc031f27e0f896fba9b9f3433
2017-03-24 01:24:23 +00:00
Alexander Chemeris
e56bf3a0e5 signalVector: Implement segment().
Change-Id: I6fe3aae53fb2fa5bb7637e976de6059eabe08202
2017-03-24 01:22:40 +00:00
Alexander Chemeris
38b69871ae BitVector: Convert SoftVector from 0..1 to -1..+1 soft bits.
This makes code simpler and will allow us send -127..127 soft bits towards
osmo-bts instead of 0..255 bits.

Change-Id: I16ecc3d4c829dcf0f619ad995bc9d4a4ed8af0a4
2017-03-22 18:31:22 +00:00
Alexander Chemeris
7db522b6d9 BitVector: Remove convolutional codec - we don't use it in osmo-trx.
Now we have more fexibility in how we represent SoftVector, since we
no longer depend on the particular convolutional codec implementation.

Change-Id: I3006b6a26c5eff59dbe9c034f689961802f1d0d0
2017-03-22 18:31:17 +00:00
Alexander Chemeris
ae09b04e26 CommonLibs: Print soft bits with less confidence to console when printing a soft vector.
We use other symbols to show that these bits has less confidence:
o and . for 0 with less confidence
| and ' for 1 with less confidence

Change-Id: I747a17568ee48f1f3163e8dfab2e450af85e6435
2017-03-22 18:31:12 +00:00
Alexander Chemeris
b61c610cd9 Call vectorSlicer() right before packing bits for transmission to osmo-bts.
vectorSlicer() converts soft-bits from -1..+1 to 0..1 while we want
to keep SoftVector in -1..+1 mode until the last minute, because at some
point we'll want to transmit -1..+1 to osmo-bts instead of converting it
from 0..1 back to -1..+1 on the osmo-bts side.

Plus it removes code duplication - we call it once instead of twice.

Change-Id: Idd6ddd7ac219afb0df055a692632678b66373764
2017-03-22 18:31:07 +00:00
Alexander Chemeris
132fb247b1 sigProcLib: Slice SoftVector instead of signalVector for GMSK demod.
This makes it similar to 8-PSK demod and also saves a bit of lines ofcode and
should give us a tiny improvement in performance.

Ideally we need to remove vector slicing at all, because in osmo-bts-trx
we convert back to +-1.0 again (actually to +-127, but it doesn't mater).
So we should rather transmit +-1.0 values to avoid double conversion.

Change-Id: If9ed6f0f80fbe88c994b2f9c3cae91d0d57f4442
2017-03-22 18:31:03 +00:00
Alexander Chemeris
1c0b8b355c sigProcLib: Rename demodulateBurst() to demodGmskBurst() for clarity.
Change-Id: Ibcef8d7d4a2c06865bed7e4091ccc8dbbd494d77
2017-03-22 18:30:53 +00:00
Alexander Chemeris
1dd05cf35a sigProcLib: make energyDetect() simpler by returning actual energy.
Change-Id: I9bf97f2dc03fea9bebcf43198dfb05f6e4694e9c
2017-03-22 18:09:00 +00:00
Alexander Chemeris
14d13b67dc sigProcLib: Fix documentation, sync argument names in .cpp and .h files.
Documentation in sigProcLib.h was noticeably out of sync with the actual
implementation - e.g. not all arguments were documented and arguments
which are already removed are still in the documentation. Also argument
names were different between declaration in .h and implementation in .cpp
which was confusing.

I've fixed this for detect*Burst() functions.

Change-Id: I4dfd07125d9a1e9a42a78b79faff539f003deb16
2017-03-20 18:42:32 +00:00
Alexander Chemeris
89bca9b2de radioBuffer: Remove extra ; at the end of inline function definitions.
Change-Id: I8911adf0a0bb1ae828ac9cdf1a76c904639f6c06
2017-03-20 18:41:02 +00:00
Alexander Chemeris
9270a5aa2e sigProcLib: Typo sybols -> symbols
Change-Id: I8cbef852374d0458c4f4ad4be0df0aa998e3796a
2017-03-20 17:36:06 +00:00
Alexander Chemeris
4793f4679b CommonLibs: Remove unused files.
Change-Id: I2bfb45a1c7d01785bdb30204dba38c683a4288a9
2017-03-20 17:32:04 +00:00
Max
802b86502d Add autoconf-archive to dependencies
We use AX_EXT in ./configure for checking CPU features anyway, so it's
better to add it as explicit dependency.

Related: OS#1923
Change-Id: I7ba48e1df4ede8b477574da3faa15fd02e15c69b
2017-03-14 18:49:55 +01:00
Tom Tsou
a93f789e50 uhd: Increase MC-BTS FPGA clock rate to 51.2 MHz
Addresses following issues where UHD 3.9 and likely other UHD versions
would report a master clock (FPGA) rate error. Update MC-BTS FPGA clock
for B200 and B210 to 51.2 MHz, which is supported by all UHD versions.
Only B200/B210 is supported for MC-BTS operation.

https://osmocom.org/issues/1963
https://osmocom.org/issues/1648

ALERT UHDDevice.cpp:548:set_master_clk: Failed to set master clock rate
ALERT UHDDevice.cpp:549:set_master_clk: Requested clock rate 3.2e+06
ALERT UHDDevice.cpp:550:set_master_clk: Actual clock rate 5e+06

Change-Id: I78fb2c0959abd0e666628ba39f433162aafb067e
2017-03-07 17:54:06 -08:00
Tom Tsou
72bf762b42 uhd: Add support for UHD-3.11 logging control
The logging API changes in UHD-3.11, which causes build failure if
not properly handled.

Change-Id: I223ebb9fae3f4061e0cb37c05263c1b569e8f628
2017-03-07 14:25:05 -08:00
Max
2dee3e996e Fix building against sqlite3
* Explicitly check for sqlite3 at configure stage, remove old include
  dir, fix header inclusion.
* Use configure results for linking instead of hardcoded linker option
  for sqlite.
* Add dependency on -dev package for .deb

Change-Id: I6d7f697d67651f02ceb77fc4da4317b64fa47f9e
Fixes: OS#1928
2017-01-26 17:06:06 +01:00
Max
1f1cebb2e5 Remove embedded sqlite3
Previous patch switches to using system-wide sqlite3 so it's safe to
remove local copy now.

Change-Id: Ie8e751cc62132fe1f7748ccd78c5d48469027329
2017-01-24 15:15:30 +01:00
Ruben Undheim
d1b28bd766 Do not embed sqlite3 when building
Change-Id: If5edadc04c3ff953b451676e55ad3d00d4e43c82
2017-01-24 15:15:24 +01:00
Max
833e97e9ba Integrate Debian packaging changes
debian/control:
    * restructure to make it easier to incorporate further changes
    * update package descriptions
    * update project URL

debian/rules:
    * use proper hardening syntax

debian/copyright: update to match Debian format

Change-Id: I9a89e7311c8632ae26ac2e6c02d1e427d94b1608
Related: OS#1694
2017-01-24 15:14:32 +01:00
Max
e6d059f0c9 Add gerrit settings
Make it simple to setup and use this repo with 'git review' command.

Change-Id: I6bbe65cc09e086685995f084a07a646a7d60b93c
2017-01-24 15:03:48 +01:00
Holger Hans Peter Freyther
012a1b345b debian: Require fftw3 header files for osmo-trx
Install missing development package to get osmo-trx to build.

Change-Id: Id80937724d5e4da4ed555cbabfcd3e2457cb2a19
2017-01-24 14:47:10 +01:00
Tom Tsou
80cb08071b Revert "uhd: Set minimum supported version to 3.9.0"
This reverts commit 93ca09ea61.

Ettus Research recommends the use of 3.9 series of UHD releases,
but requiring this version has lead to issues with broken OBS and
packaged binaries by Debian, Ubuntu, and other distributions.

Change-Id: Ie6b175ac6d46d091937380c79fdd0125b16ec75f
Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2017-01-19 13:48:15 -08:00
Tom Tsou
44c7f41d75 uhd: Add X300 sample timing for 4 SPS
Previously only 4/1 and 1/1 configurations Tx/Tx samples-per-symbol
were supported.

Change-Id: I9153171fe3af95e1cb0d9d35a9287dfde155d184
2017-01-11 13:30:42 -08:00
pierre.baudry
9436fbbf3c transceiver: Fix mismatched allocations and deallocations
The behaviour of a mismatched pair of allocation and deallocation is undefined
Also fixes a memory leak if malloc fails (which stops the application anyway)

Change-Id: I9c8bbade8531e8c9c02dcd43bac38cb954b3c89f
2016-10-26 08:54:13 +02:00
Tom Tsou
93ca09ea61 uhd: Set minimum supported version to 3.9.0
Versions of UHD prior to 3.9.0 are no longer supported.

Rather then backport and ifdef UHD version specific API and
behavioral changes, set minimum support to the current LTS
release, which is 3.9.0.

Change-Id: Id7d15b52cd4e45f1d856a6ef3a84832a28f2dd04
Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-10-25 18:48:52 +00:00
Tom Tsou
365bc38bee transceiver: Fix command build warning
Place conditional brackets on handover table reset. Reset table
only on successful start or restart.

Change-Id: I74032b49785bd68835a0a68cb0f14cdaab4fcd26
2016-10-25 18:48:25 +00:00
Tom Tsou
43242efc85 uhd: Add missing B200 sample timing for 4 SPS receive
Only B210 timing was previously set in the timing table.

Change-Id: Idc8d1be8201ad086c57dd9b3d6d72d277306cd2b
2016-10-18 11:30:09 -07:00
Neels Hofmeyr
76b98cf236 add contrib/jenkins.sh, for gerrit build bot
Change-Id: If8887525b0062090e9445a35e32b03e3b8e7eede
2016-10-17 17:53:26 +02:00
Tom Tsou
aa15d62a8c sigproc: Match differential GMSK start/end bits to tail bits
Invert the initial and trailing diffential bits in the 4 sps
GMSK modulator to fix power-time mask irregularity at start
and end of burst. GSM tail bits are always zero, so we can
safely use fixed bit values.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-08-11 14:44:57 -07:00
Neels Hofmeyr
2e5e2c537b The INSTALL file is being overwritten by autoreconf, but it is committed
as empty file. As a result, the INSTALL file always shows as modified.
Instead, remove INSTALL from git and ignore it.
2016-08-08 11:55:41 -07:00
Tom Tsou
8f0ccf618d uhd: Update USRP2/N200/N210 for 4 SPS Rx
Requires changing the radioInterface API to pass in Rx side SPS
value. Update the (deprecated) diversity configuration to match
as well.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-07-20 16:36:27 -07:00
Tom Tsou
06676ead63 sigproc: Fix missing 8-PSK tail symbols
Agilent E4406A measurement of TSC synchronized RF envelope measurement.
showed failing power levels at the tail end of EDGE bursts. Regression
traced back to following commit.

Commit d2b070369d
"uhd: Correct timing alignment in 8-PSK and GMSK downlink bursts"

In the patch, the EDGE burst was delayed one symbol, but erroneously
truncated at the tail end causing the failing RF envelope measurement.

The missing tail symbol did not appear to affect end-to-end EGPRS tests.
This patch corrects the truncation.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-07-19 12:56:24 -07:00
Tom Tsou
4609f3285c transceiver: Fix 4 SPS receive TOA value
The time-of-arrival (TOA) value out of sigProc is specified
in symbols or, equivalently, 1 sample per symbol and does
not need to be normalized.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-07-19 11:30:49 -07:00
Tom Tsou
7c741ec6a6 transceiver: Fix mixed GSMK / 8-PSK transmission
Input burst construction was declared static causing the first
downlink burst from upstream to determine subsequent burst size
and modulation. Consequently, fixed sequence EGPRS tests would
pass, however, switching between 8-PSK and GMSK bursts would
fail with only one modulation type being transmitted.

Internally generated test sequences '-r' option were not affected
because the bursts are not received through the socket interface.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-07-19 11:26:05 -07:00
Tom Tsou
2f3e60bc1f uhd: Add command line option for GPS reference
Unlike earlier versions of UHD, the current release (3.9.2)
does not automatically select on-board GPSDO as the reference
source. Modify the command line settings to allow explicit
selection of GPS in addition to the external setting.

Simultaneous GPS and external reference settingis disallowed.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-07-17 19:34:22 -07:00
Alexander Chemeris
cbfef6e40a UHD: Initial LimeSDR support.
Only EDGE mode is currently supported. Traditional 1 SPS Rx / 4 SPS Tx
mode requires different sampling rates which is not currently working.

RF performance is also sub-optimal and requires more tuning.
2016-07-12 16:26:51 -07:00
Tom Tsou
b577ef014f radioInterface: Fix multi-channel buffer index bug
Discrete RF multi-channel was using hard coded buffer index
on the channel iteration for transmit sample conversion. End
result was segmentation fault on dual RF channel devices with
both channels active (Ettus B210 and UmTRX).

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-07-12 16:11:13 -07:00
Tom Tsou
c37594f3b9 mcbts: Allow out of order channel setup
Previous checks on multi-channel TSC and ARFCN settings would fail
if channels were initialized out of order. Namely, if channel 0
was not configured first, osmo-trx would error on the control
interface leading osmo-bts to fail.

Allow global TSC setting on all channels with added logging notice.
Notify if channel frequency is unexpected - which may happen if
channels are setup out of order - but do no report as error.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-07-08 14:46:25 -07:00
Tom Tsou
ffee30d190 transceiver: Remove HANDOVER warnings
These warnings simply echo the socket command arguments with no
indication of any unexpected or improper operation.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-07-07 19:39:18 -07:00
Neels Hofmeyr
24575a6530 configure.ac: check for boost/config.hpp header 2016-07-05 15:43:19 -07:00
Neels Hofmeyr
1e9801411b add basic .gitignore 2016-07-05 15:42:35 -07:00
Tom Tsou
64464e6c34 egprs: Enable 8-PSK burst detection when EDGE is enabled
The command line EDGE option will enable 8-PSK burst
detection on any slot where a normal burst is expected.
The burst search order is 8-PSK first followed by GMSK.

EDGE will force 4 SPS sampling on Tx and Rx. Along with
twice the search correlation from 8-PSK and GMSK, EDGE
will increase CPU utilization. Whether the increase is
notable or not is dependent on the particular machine.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-07-01 03:50:02 -07:00
Tom Tsou
e88710881b egprs: Enable 8-PSK length vectors on the Tx interface
Allow EGPRS 8-PSK length bit vectors of length 444 (148 * 3)
to pass in through the Tx socket interface. Length is the sole
factor in determining whether to modulate a bit vector using
GMSK or 8-PSK.

Tested with 8-PSK training sequences with random payload
originating from osmo-bts. Output verified with Agilent E4406A.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-07-01 03:16:03 -07:00
Tom Tsou
a84e162672 sigproc: Adjust burst detection threshold criteria
Reduce the burst detection threshold to pass more bursts to upper
layers, but force stricter requirements on the computation itself.
For the latter, we now require at least 5 samples (rather than 2)
to compute a peak-to-average value.

End result is increased burst detection at low SNR conditions with
a small increase in false positive bursts when no signal is present.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-07-01 03:14:29 -07:00
Tom Tsou
7676427816 mcbts: Add multi-ARFCN radio support
Add new radio interface "radioInterfaceMulti" for multi-carrier
support.

Only USRP B200/B210 devices are supported because of sample
rate requirements (3.2 Msps).

Only 4 SPS operation Tx/RX is supported.

8-PSK is supported.

Other options may be added at a later time

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-07-01 03:14:15 -07:00
Tom Tsou
35222296fe mcbts: Add multi-ARFCN channelizing filters
Introduce polyphase channelizer (Rx) and synthesis (Tx) filterbanks,
which serve as the signal processing backend for multi-carrier GSM.

Fast Fourier Transform (FFT) is used internally. FFTW is added as
a new build dependency.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-07-01 03:07:27 -07:00
Tom Tsou
28670fb5da iface: Add inner ring-buffer implementation
Two buffers, inner and outer, are used in the transceiver
implementation. The outer buffer interfaces with the device receive
interface to guarantee timestamp aligned and contiguously allocated
sample buffers. The inner buffer absorbs vector size differences between
GSM bursts (156 or 157 samples) and the resampler interface (typically
fixed multiples of 65).

Reimplement the inner buffer with a ring buffer that allows fixed size
segments on the outer (resampler) portion and variable lengths (GSM
side) on the inner side. Compared to the previous stack-like version,
this implementation removes unnecessary copying of buffer contents.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-07-01 03:03:11 -07:00
Tom Tsou
05c6feb71d radioInterface: Convert diversity argument to general type
Rather than a simple bool type, convert the diversity switch
to the device interface specifer:

  enum InterfaceType {
    NORMAL,
    RESAMP_64M,
    RESAMP_100M,
    DIVERSITY,
  };

The more general specifier allows passing in special cases
other then selection diversity such as multi-ARFCN support.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-07-01 03:03:03 -07:00
Tom Tsou
2e4ed10722 transceiver: Add Rx samples-per-symbol option
Previous approach was to enable 4 SPS on the receive path only
for EDGE use, which is not a requirement for 4 SPS operation.
Make the 4 SPS configuration setting directly settable.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-07-01 03:02:56 -07:00
Tom Tsou
c8c4eac55e transceiver: Do not report error on SETTSC when radio is on
OsmoTRX does not support the use of multiple TSC settings per
internal TRX instance. There should not be an error to modifiy
the TSC value after POWERON. Setting TSC value on TRX channels
other then 0 is a NOP operation that should only error if the
requested TSC differs from that of TRX channel 0.

Reported-by: Max <msuraev@sysmocom.de>
Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-06-28 17:08:34 -07:00
Alexander Chemeris
37c52c79cf transceiver: Add an option to emulate a RACH delay in random filler mode.
Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-06-22 15:18:13 -07:00
Alexander Chemeris
58e9591f9e transceiver: Log channel number in DEBUG output of demoded bursts.
Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-06-22 14:28:22 -07:00
Alexander Chemeris
19174f581b radioInterface: Initialize power scale with a meaningful default.
Right now if you forget to send "POWER" control command, osmo-trx
will transmitt zeros. This is counter-intuitive and I've spent several
hours debugging this "issue". The issue may happen easily, because
osmo-bts doesn't send "POWER" command if there is no "power" setting
in the configuration file. Given that "POWER" command actually sets
attenuation, it's percieved as optional and in absence of it should
default to "POWER 0" (no attenuation), which translates to power
scale being 1.0.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-06-22 14:28:07 -07:00
Alexander Chemeris
1ba69e7762 uhd: Fix comment.
It's osmo-trx, not OpenBTS anymore.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-06-22 14:27:38 -07:00
Alexander Chemeris
f931cf226b radioDevice: GSMRATE macro must have parentheses around its definition.
So we had the following define:
   #define GSMRATE       1625e3/6

Now, I wanted to use it in the following expression:
   3.0/GSMRATE
which turns into:
   3.0/1625e3/6
while what I really wanted is:
   3.0/(1625e3/6) = 3.0/1625e3*6

To avoid this, all macros with calculations must be enclosed in parentheses.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-06-22 14:27:24 -07:00
Alexander Chemeris
e476231deb makefile: Fix build from an external path.
When you build from an external path, compiler can't find convert.h
include, because it was specified relative to the current directory.
Change this to specify the include dit relative to the Makefile
location.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-06-22 14:27:00 -07:00
Tom Tsou
e90c24c8d5 sigproc: Expand RACH, TSC, and EDGE correlation windows
Slightly widen the search range to accommodate timing jitter
on certain classes of devices. The expanded range minimizes
the possibility of missing bursts that arrive too early or
too late due to timing error.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-06-21 16:19:54 -07:00
Tom Tsou
3b093bb13b uhd: Set minimum UHD version requirement for E3XX
Create runtime version check for minimum supported UHD driver
when using USRP E3XX devices. The minimum version, 3.9.0, matches
supported version on current E3XX release images.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-05-03 19:06:56 -07:00
Tom Tsou
3f4a13f049 uhd: Make device offset check a private method
Removes extra arguments and a static call.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-05-03 19:04:00 -07:00
Tom Tsou
0fe41a583c uhd: Set default Tx sampling to 4 sps
The majority of GSM host platforms are capable of operating with
the 4x oversampled modulator, which justifies the new default
setting. The small number exceptions (e.g. Raspberry Pi) can still
use the lower complexity 1 sps modulator with the '-s 1' command
line option if required.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-05-03 15:17:39 -07:00
Tom Tsou
a5e0f1cdba uhd: Update default E3XX settings
Tune timing values after testing on UHD 003.009.002 for E3XX.
Table value for 1 sps was off by 10 samples causing improper
operation. Table value for 4 sps was shifted by 1 sample for
more accurate timing.

Also update E3XX description string detection.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-05-03 15:14:06 -07:00
Tom Tsou
2c650a6895 common: Add mandatory length field to UDP receive calls
Current UDP receive reads up to MAX_UDP_LENGTH bytes into the
passed in buffer, which may lead to buffer overflow if the
write buffer is of insufficient size.

Add mandatory length argument to UDP socket receive calls.

Reported-by: Simone Margaritelli <simone@zimperium.com>
Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-05-02 17:37:05 -07:00
Tom Tsou
d4555f267e common: Restrict UDP binding to localhost only
Reported security vulnerability where control and data UDP
packets can be injected into the transceiver externally due
to socket binding to all interfaces using INADDR_ANY.

Existing socket interface does not allow specifying local
address; only the local port and remote address/port are
arguments.

Restrict socket bind to localhost with INADDR_LOOPBACK. If
external interfaces do need to be used, the API should be
modified to allow specifying the local socket address.

Reported-by: Simone Margaritelli <simone@zimperium.com>
Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-05-02 17:35:01 -07:00
Tom Tsou
047956259b EDGE: Fix demodulation slicer input
EDGE 8-PSK soft slicer was receiving input from the output of the
downsampler. Equalization and derotation were missing causing the
soft symbol output to be invalid.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-04-26 21:20:43 -07:00
Tom Tsou
d2b070369d uhd: Correct timing alignment in 8-PSK and GMSK downlink bursts
Delay the EDGE downlink bursts by one symbol in order to match GMSK
pulse shaping group delay. The difference in group delay arises from
the dual pulse filter combination of the GMSK Laurent represenation
whereas 8-PSK uses a single pulse linear filter.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-04-26 19:31:14 -07:00
Alexander Chemeris
9664c3a6e7 transceiver: Do not pass transceiver state struct to function where it's not used. 2016-04-26 12:03:20 -07:00
Alexander Chemeris
1ab5e7f7bc osmo-trx: Output Rx SPS as a part of configuration output. 2016-04-26 12:02:51 -07:00
Alexander Chemeris
5efe05021a transceiver: Add an option to generate random Access Bursts. 2016-04-20 13:46:02 -07:00
Alexander Chemeris
78d1fc9a13 transceiver: Properly handle MAXDLY.
Previously MAXDLY value was applied to Normal Bursts, which was nice
when working with sloppy test equipment like CMD57, but useless for
real world usage. At the same time documentation and de facto usage
of MAXDLY in OsmoBTS and OpenBTS assumed that it actually applies to
Access Bursts (RACH). So this patch changes osmo-rx behavior to apply
MAXDLY to RACH bursts and introduces a new command MAXDLYNB for the
old behavior.
2016-04-20 13:45:00 -07:00
Alexander Chemeris
a8cf208616 Common: Make sure gLogEarly() log to the same facilities as the normal log. 2016-04-20 12:33:41 -07:00
Alexander Chemeris
f84232d30a Common: Get rid of a compilation warning.
debugLogEarly was replaced to an empty space and arguments of the function
became operators, grouped together by ():
Configuration.cpp: In member function 'bool ConfigurationTable::defines(const string&)':
Configuration.cpp:272:28: warning: left operand of comma operator has no effect [-Wunused-value]
   debugLogEarly(LOG_ALERT, "configuration parameter %s not found", key.c_str());
                            ^

This fix removes debugLogEarly together with its arguments.
2016-04-20 12:26:57 -07:00
Tom Tsou
9bd649ec73 EDGE: Fix USRP B210 device support
Commit 871b8782 "EDGE: Add support for UmTRX" disabled B210 support
using EDGE. Add B210 explicitly to the timing offset table to avoid
this issue.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-03-23 17:20:08 -07:00
Alexander Chemeris
871b87829f EDGE: Add support for UmTRX.
Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-03-22 11:01:34 -07:00
Holger Hans Peter Freyther
d17b189cbc debian: Add packaging to master taken from fairwaves/master
There doesn't seem to be a reason why this shouldn't be in master.
The fairwaves/master branch is removing --march=native as well that
looks like a good idea as well.
2016-03-18 20:22:58 +01:00
Tom Tsou
7fec3030d4 EDGE: Combine shared GMSK and 8-PSK demodulator sections
Timing recovery and single tap channel compensation are identical
in both GMSK and EDGE receivers. This is the section ahead of and
including the optional 4-1 downsampler. GMSK and EDGE specific
sections operate at 1 SPS.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-03-08 17:45:53 -08:00
Tom Tsou
af717b2d3c EDGE: Add random burst generator filler option
When EDGE is enabled with the '-e' option, the random burst generator
switches from GMSK normal bursts to 8-PSK EDGE bursts.

  $ ./osmo-trx -e -r 7

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-03-08 17:45:53 -08:00
Tom Tsou
8ee2f38a87 sigproc: Add various GSM burst generators
Setup generators for empty, random, and dummy bursts. This moves error
prone burst length handling out of the Transceiver and into the signal
processing core.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-03-08 17:45:53 -08:00
Tom Tsou
4dfd64aa9e sigproc: Always use 625 sample length bursts with 4 SPS
At 4 samples per symbol, we don't need to maintain the 156/157 sample
slot structure to account for the GSM 156.25 sample burst length.
Set the 4 SPS Laurent modulator to ignore the guard interval setting
and always output 625 sample sized bursts. The EDGE 8-PSK modulator
already has this behavior.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-03-08 17:45:53 -08:00
Tom Tsou
b0aefcbf47 EDGE: Add interfaces to enable EDGE transceiver
Create EDGE slot type in the Transceiver. When EDGE mode is enabled
for a particular slot, blind detection will be performed by
correlating against EDGE followed by normal bursts if no EDGE burst
is found.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-03-08 17:44:53 -08:00
Tom Tsou
d325343ecc EDGE: Add 8-PSK modulator and demodulator
Setup correlator and detection process similar to the GMSK
receiver chain. Require 4 SPS sampling on both Rx and Tx paths
as 1 SPS sampling adds too much distoration for 8-PSK recovery.
Core receiver operations still run at 1 SPS with the exception
of fractional delay filtering, which runs at the higher rate.

Perform linear equalization to handle the Gaussian pulse
induced ISI. The fixed impulse response used for equalizer tap
calculation consists of combined EDGE pulse shape filter and
effects of the downsampling filter. Note that the non-adaptive
equalizer corrects for modulation induced band limiting and
does not account for or compensate for fading channel effects.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-03-06 20:29:27 -08:00
Tom Tsou
5cd70dc4ec EDGE: Setup variable sampling on receive path
Allow setting the device to non single SPS sample rates - mainly
running at 4 SPS as the signal processing library does not support
other rates. Wider bandwith support is required on the receive path
to avoid 8-PSK bandlimiting distortion for EDGE.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-03-06 19:11:05 -08:00
Tom Tsou
465694027b sigproc: Remove normal burst DFE equalizer
DFE equalizer is unused and has been experiencing code rot for
multiple years. The effect is a significant amount of baggage being
carried in the Transceiver and interfaces.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-03-06 19:10:59 -08:00
Tom Tsou
2079a3c664 sigproc: Remove dynamic SPS configuration
Samples per symbol used by the transceiver is not configurable through
the socket interface once running, so stop pretending like it could be.
Initialize all tables and midambles at start.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2016-03-06 19:10:46 -08:00
Tom Tsou
99cf930f9a Transceiver52M: Fix ARM build issues
Patch f147b174 "sigproc: Make convolution and convert input buffers
immutable" changed the internal conversion interface with the addition
of the const type qualifier. This change was not reflected on ARM builds
which led to build failure. Add const qualifier to resolve build issue.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-11-09 12:06:33 -08:00
Tom Tsou
283b22dbce uhd: Remove references to USRP B205
Certain pre-release versions of the B200mini used the B205 naming, which no
longer exists. Update device naming and detection to reflect current UHD
product names.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-10-21 17:13:24 -07:00
Tom Tsou
f147b17447 sigproc: Make convolution and convert input buffers immutable
For good practice, use const specifier when applicable.

Signed-off-by: Tom Tsou <tom@tsou.cc>
2015-08-21 19:31:24 -07:00
Tom Tsou
d4d3daa12e uhd: Use internal UHD tick conversions
UHD handles built in tick and floating point timestamp conversion
since version 003.005.004. This removes the need for separate UHD
timespec to tick conversion.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-08-21 19:29:38 -07:00
Tom Tsou
c312905f43 uhd: Add version 3.9.0 support
New functionality includes B200-mini device support and updated
timing values to match FPGA changes.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-08-21 19:20:32 -07:00
Alexander Chemeris
c4eab8795f uhd: Output Rx/Tx gain limits to log to make it more transparent.
Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-07-30 14:25:17 -07:00
Alexander Chemeris
cc6f79b1c0 Logger: Output ERR log messages to stderr as well.
Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-07-30 14:24:20 -07:00
Alexander Chemeris
5a0680655f Transceiver: Add support for OsmoBTS style handover.
Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-07-30 14:24:08 -07:00
Alexander Chemeris
3722920100 Transceiver: Fix whitespace.
Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-07-30 14:23:32 -07:00
Alexander Chemeris
f3b9af65ed uhd: Fix UmTRX tuning broken in commit 90f7a01d.
Commit 90f7a01d lost "return" statement. We also should account the fact that
offset can be negative.
We should return the tuning request immediately after

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-07-30 14:23:24 -07:00
Alexander Chemeris
e692ce986c transceiver: Add a debug option to dump selected timeslots to disk.
Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-07-30 14:22:59 -07:00
Alexander Chemeris
81c6873205 Transceiver: Do not update state->SNRestimate if equalization is disabled.
This also fix a bug of using bool type for noise instead of float.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-07-30 14:22:41 -07:00
Alexander Chemeris
c052aa1d4c uhd: Fix rounding error in timestamp conversion functions.
Rounding error introduced oscilating timing advance error by regularly
overwriting one bit and then skipping one bit.

This commit also adds an error message to show up in logs if this ever
happens again.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-07-30 14:22:28 -07:00
Alexander Chemeris
130a8007fa sigProcLib: Abstract out common part of Normal/RACH burst detection.
As a side change - get rid of passing toa and amp arguments as pointers and use
references instead.

The commit doesn't change behaviour, but makes the code cleaner.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-07-30 14:22:13 -07:00
Alexander Chemeris
72e8619632 Checking in clockdump.sh utility.
Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-07-30 14:20:22 -07:00
Alexander Chemeris
2beb1adcea Checking in a more relevant README.
This READMY is from the OpenBTS's TRXManager and actually describes the transceiver
API and behavior.
2015-07-30 14:19:51 -07:00
Alexander Chemeris
2b542100a0 Transceiver: Update noise level only when the timeslot is marked as IDLE.
We can't rely on an assumption that if we can't decode a burst - it's noise.
There are many rasons why we can't decode a burst even if it's well above the
noise level. Just one example is a RACH burst which can be overlapped with
another RACH burst up to a level both are completely unrecognizable. Another
example is when a burst is destroyed by bad multi-path.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-07-30 14:19:32 -07:00
Alexander Chemeris
2268c8558c transceiver: Remove noise/RSSI gating.
It does more harm than good. the current noise calculation is too error
prone, so we can't trust it. And we end up loosing perfectly good bursts
because of that.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-07-30 14:19:17 -07:00
Alexander Chemeris
50747dc65d osmo-trx: Add an option to swap channels on UmTRX.
Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-07-30 14:19:06 -07:00
Alexander Chemeris
1e9b4d57da sigProcLib: Check for bogus TOA before using it.
Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-07-30 14:18:31 -07:00
Alexander Chemeris
954b118bfa Transceiver: Fix clipping detection.
There are two primary changes in this commit:

1) Return values of detect functions changed form bool to int to actually pass
the return value from the inner function and notify higher levels about clipping.
Previously the information was lost due to conversion to bool.

2) Clipping level is not the final verdict now. We still try to demod a burst
and mark it as clipped only if the level is above the clipping level AND we can't
demod it. The reasoning for this is that in real life we want to do as much as
possible to demod the burst, because we want to get as much from our dynamic
range as possible. So a little bit of clipping is fine and is expected. We just
don't want too much of it to break our demod.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-07-30 14:17:59 -07:00
Alexander Chemeris
dbe26abcb9 Transceiver: Print noise level for each burst in debug mode.
Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-07-30 14:17:56 -07:00
Alexander Chemeris
e8905a03a5 osmo-trx: Add a command line option for the dBFS to dBm offset.
Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-07-30 14:14:33 -07:00
Alexander Chemeris
909ffbfd23 Common: Use a scoped lock in the Logger to avoid deadlock on thread cancel.
Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-07-30 14:14:23 -07:00
Alexander Chemeris
351fd76706 sigProcLib: Fix burst start phase.
R&S CMD57 complains about the start phase of bursts, particularly it shows
-15 to -30 deg of error for the bit 0.5 position (start tail bit). This patch
makes it happy. ETSI TS 145 004 section 2.2 describes this: "Before the first
bit of the bursts as defined in 3GPP TS 45.002 enters the modulator,
the modulator has an internal state as if a modulating bit stream consisting
of consecutive ones (di = 1) had entered the differential encoder."

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-06-01 16:06:11 -07:00
Alexander Chemeris
6a2bf0d87b transceiver: Drive clock indication form the receive thread.
Receive thread receives data from the device, which is a more stable source of
clocking than the transmit side. If transmit side has a hiccup, osmo-trx doesn't
send the clock indication, and transmit side is getting completely lost in time.
With this patch we ensure that clock indication keeps coming.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-06-01 16:06:02 -07:00
Alexander Chemeris
2966048b07 transceiver: Fix out-of-bounds acces in genRandNormalBurst().
We should read gTrainingSequence starting from 0 bit index, not 61 bit index.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-06-01 16:04:10 -07:00
Alexander Chemeris
f5fd578d60 osmo-trx: Fix random filler command line option.
Filler types was of "bool" type, which prevented it from taking values greter
than 1. And RAND filler type has integer value of 2, which was casted to 1 on
assigning, which led to a normal filler table being used instead of the RAND
one.
2015-05-24 20:35:13 -04:00
Alexander Chemeris
57ef87d061 Common: Log to console instead of loging to syslog by default. 2015-05-24 13:23:11 -04:00
Alexander Chemeris
5721920a08 Common: Introduce a global variable to disable syslog logging.
When we enable DEBUG logging level, syslog gets Gb's of data and can completely
exhaust the file system free space. Now we can just enable it. This is not to
say that logging to syslog it just not very useful in general.
2015-05-24 13:20:44 -04:00
Ivan Kluchnikov
194a9b1982 Transceiver52M: Change POWERON behavior to return success if the transceiver is already running, and only return fail on device
failure
2015-05-24 12:55:31 -04:00
Alexander Chemeris
1fe5282133 Transceiver: Check TSC values to be in [0..7] range.
Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-05-20 12:05:04 -07:00
Alexander Chemeris
4438a9fd8f Transceiver: Make error response to an unknown command on UDP command interface more understandable.
Previously we just repeated the last response which could confuse a command sender.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-05-20 12:03:30 -07:00
Tom Tsou
64ad712daa test: Add command line random normal burst option 2015-05-19 18:26:31 -07:00
Tom Tsou
5c7c178369 uhd: Pass UHD command line arguments to constructor
Previous behaviour used UHD command line args string for device search,
but did not apply the values to the device constructor. Now use the user
passed args string for both find and device construction.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-05-18 16:51:44 -07:00
Alexander Chemeris
90f7a01d1d umtrx: Don't use DSP tuning, because LMS6002D PLL steps are small enough.
We end up with DSP tuning just for 2-3Hz, which is meaningless and
only distort the signal.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-05-18 16:49:24 -07:00
Alexander Chemeris
e171425b99 uhd: Set RF frontend bandwidth for UmTRX to improve signal quality.
Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-05-18 16:49:05 -07:00
Alexander Chemeris
4d029d8965 UmTRX: Manually set Tx gain stages for the best signal quality.
New UHD versions support split configuration of Tx gain stages.
We utilize this to set the gain configuration, optimal for
the Tx signal quality. From our measurements, VGA1 must be
18dB plus-minus one and VGA2 is the best when 23dB or lower.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-05-18 16:48:17 -07:00
Tom Tsou
6613331459 build: Provide option for disabling SSE autodetection
Setup '--with-sse' option to check system capabilities by default, but
allow disabling by the user. Selective SSE build options can be
controlled by the user by defining specific HAVE_SSE options.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-05-18 16:35:44 -07:00
Tom Tsou
577cd020c1 sigproc: Add clipping detection on RACH and TSC input
Alert user of overdriven burst input indicated by a positive
threshold detector result. This indication serves as notification
that the receive RF gain level is too high for the configured
transceiver setup.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-05-18 16:35:35 -07:00
Alexander Chemeris
88bbf1aafd uhd: Use full DAC scale with UmTRX to improve signal quality.
Signed-off-by: Tom Tsou <tom@tsou.cc>
2015-05-18 16:35:25 -07:00
Tom Tsou
2cc2ddda41 build: Add 'subdir-objects' to AM_INIT_AUTOMAKE
This will shutup automake and make it stop complaining about the
following subdirectory warnings.

"warning: source file 'common/fft.c' is in a
subdirectory, but option 'subdir-objects' is disabled"

Signed-off-by: Tom Tsou <tom@tsou.cc>
2015-05-18 16:35:13 -07:00
Tom Tsou
d7610cf0b8 radioInterface: Reset sample buffer cursors on each start
Non-zero buffer indices may lead to uplink/downlink timing offset
during repeated start/stop cycles. Mainly affects USRP2 and other
resampled devices that rely on the buffer to absorb sample block
sizes that are not multiples of the burst size.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
2015-05-07 17:47:17 -07:00
Tom Tsou
722d4f70a4 usrp1: Update device API for frequency offset tuning
Commit 8e17df7374 "Add option for baseband frequency offset",
modified the base device API to allow for RF tuning, which was never
updated for the USRP1.

Update the implementation to match the API, however, note actual offset
in the USRP1 remains unsupported.

Signed-off-by: Tom Tsou <tom@tsou.cc>
2015-01-19 09:59:41 -08:00
Tom Tsou
93b7f37309 b210: Lock dual-channel tuning access
Frequency tuning is a multi-step process with RF and DDC/DUC protoimns
that can be corrupted if both channels attempt to tune at the same time.

Signed-off-by: Tom Tsou <tom@tsou.cc>
2014-12-15 20:25:27 -08:00
Tom Tsou
4ad9ea69ab Transceiver52M: Add X300/X310 and E310 USRP support
Treat X300 similar to N200 and resample with 100 MHz base clocking,
which provides some amount of oversampling for reduced phase error
compared to the 1 sample per symbol receiver. Treat E310 similar to 13
MHz rate devices for the lowest computational use.

Signed-off-by: Tom Tsou <tom@tsou.cc>
2014-12-15 18:59:45 -08:00
Tom Tsou
eb54bddf47 Transceiver52M: Implement POWEROFF command
Add stop and restart capability through the POWEROFF and POWERON
commands. Calling stop causes receive streaming to cease, and I/O
threads to shutdown leaving only the control handling thread running.
Upon receiving a POWERON command, I/O threads and device streaming are
restarted.

Proper shutdown of the transceiver is now initiated by the destructor,
which calls the stop command internally to wind down and deallocate
threads.

Signed-off-by: Tom Tsou <tom@tsou.cc>
2014-12-15 16:20:15 -07:00
Tom Tsou
a4d1a41244 Transceiver52M: Allow setting gain before POWERON
There is no reason gain settings should not be modifiable when the radio
is running or not.

Signed-off-by: Tom Tsou <tom@tsou.cc>
2014-12-15 16:20:15 -07:00
Tom Tsou
b999759175 CommonLibs: Add thread cancellation capability
For clean shutdown in the transceiver we need to cancel and join
running threads for orderly unwinding. Thread cancellation points
already exist, so we just need to be able to call on the threads to
exit out when stopping or shutting down.

Don't error when joining a NULL thread, which would be the case if a
thread was stopped before ever being started to begin with.

Signed-off-by: Tom Tsou <tom@tsou.cc>
2014-12-15 16:20:15 -07:00
Tom Tsou
1ae25561fa uhd: Display current timestamp with buffer status errors
Existing implementation outputs sample buffer parameters, but it is
helpful to know the submitted timestamp that led to the errant
condition.

Signed-off-by: Tom Tsou <tom@tsou.cc>
2014-12-15 16:19:38 -07:00
Thomas Tsou
187225cf33 Transceiver52M: Fix SSE convolution shuffle register
An errant shuffle register value used in complex-complex convolution
causes distorted correlation peak-to-average values for certain TSC
values. The error effect varies for different TSC sequences with the
most noticeable effect of degraded detection on TSC 1 and no effect on
TSC 7.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2014-05-08 13:57:36 -04:00
Thomas Tsou
ccb73e15f3 Transceiver52M: Fix retransmissions when filler table is enabled
Commit 15d743efaf "Disable filler table
retransmissions by default" made OpenBTS style filler table behavior
optional. When enabled, dummy bursts were automatically loaded into the
filler table, but the table was not updated and only filler busts were
retransmitted.

Enable the restransmit state flag when the filler table option is
specified. Only preload filler table and enable retransmissions on
channel zero.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2014-04-15 17:47:48 -04:00
Thomas Tsou
a5c83aeb56 Transceiver52M: Add E1XX USRP device id and timings
Device specific timing settings for the E100 and E110 were missing from
the Tx/Rx offset table. Add E1XX identifier and offsets to the device
list and offset table respectively.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2014-04-09 23:14:31 -04:00
Thomas Tsou
c283916e41 Transceiver52M: Allow startup delay for stream alignment
UHD requires a small amount of time to align multiple streams at
startup. Delay the startup by 100 ms relative to the queried device time
(actual delay inclusive of control latencies will be less).

The following error is only relevant to dual-channel UHD devices (e.g.
Fairwaves UmTRX and Ettus B210).

UHD Error:
    The receive packet handler failed to time-align packets.
    1002 received packets were processed by the handler.
    However, a timestamp match could not be determined.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2014-03-27 13:57:18 -04:00
Thomas Tsou
cecfb2e8f9 Transceiver52M: Set UHD rates before creating streamers
Recent versions of UHD require setting the sample rate before creating
streamers otherwise the following exception occurs.

Boost_105300; UHD_003.007.000-0-g7fef199d

terminate called after throwing an instance of
'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::math::rounding_error> >'
  what():  Error in function boost::math::round<d>(d): Value -nan can not be represented in the target integer type.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2014-03-27 13:49:51 -04:00
Thomas Tsou
8e17df7374 Transceivert52M: Add option for baseband frequency offset
Allow command line setting of the DSP frequency in UHD. All channels
will be tuned with the same offset. Dual-channel tuning with the B210,
which uses a single LO, will override the command line offset value
and set the DSP frequency automatically.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2014-03-06 15:52:49 -05:00
Thomas Tsou
3ebc772dc2 Transceiver52M: Enable B210 dual channel support
The main difference between existing UmTRX dual channel is the
single LO on B210 transmit and receive front-ends vs. independent
tuning paths. In order to support dual-ARFCN frequencies, baseband
offset conversion must be applied by tuning the FPGA CORDIC for
each channel. For B210, the following tuning order is applied.

1. If the new frequency of channel A is within the baseband range
   of channel B, then retune both channels with the RF centered
   and equal valued positive and negative baseband shifts.

2. If the new frequency of channel A is not with the baseband range
   of channel B, then retune channel A directly (without manual
   applied offset). Channel B will no longer be tuned to the
   previous frequency.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2014-03-03 23:17:57 -05:00
Thomas Tsou
18d3b833bc Transceiver52M: Disable initial device time reset
With dual-channels on B210, we lose the ability to reset both
channels to a synchronized state. Instead, let the timestamp
clock start with an arbitary value, which is the first
timestamp received from the device, instead of a near-zero
value. This approach also makes integration for device, in
general, with free-running timestamp clocks.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2014-03-03 23:16:59 -05:00
Thomas Tsou
e788239fba Transceiver52M: Split B200 and B210 identifiers
Differentiate between the two in order to provide enumeration
for dual-channel support.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2014-03-03 18:47:36 -05:00
Thomas Tsou
635f1bf2af Transceiver52M: Set B2XX clock frequency to 26 MHz
Change from the original USRP1 rate of 52 MHz. On B2XX we can use
26 MHz, which is closer to the default 32 MHz of the device.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2014-02-13 14:35:45 -05:00
Thomas Tsou
15d743efaf Transceiver52M: Disable filler table retransmissions by default
Burst selection at a particular time works in the following order
of priority.

1. Slot is disabled with channel combination set to NONE (default)
1. Burst exists in priority queue for the current time.
2. Filler table entry is used

This patch sets default behaviour to force all filler table entries
to zero and disallows filler table changes. This effectively means
that only bursts received from upper layers will be transmitted and
nothing will be automatically transmitted in the absence or delay
of incoming burts at a particular time.

New Command line option "Enable C0 filler table" allows reverting
to previous idle burst generation and retransmission behaviour on
TRX0. Retransmission cannot be enabled on non-C0 channels.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2014-01-26 21:52:46 -05:00
Thomas Tsou
af506441b3 Transceiver52M: Add missing scaling vector resize
Downlink scaling factors, which are stored in a vector for multiple
channels, was not being sized correctly.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-18 01:36:58 -05:00
Thomas Tsou
4de70be9a6 Transceiver52M: Remove database configuration file requirement
We don't require any parameters stored in the configuration table,
so don't bother with the existence of the persistent database file.
This also removes an unnecessary step during initial setup since
relevant parameters can be configured from the command line.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-17 18:57:45 -05:00
Thomas Tsou
fb827d04ba Transceiver52M: Ignore channel estimation if we are not equalizing
Equalization is currently disabled by default. As such, we don't need to
run channel estimates or even track the update state, which would
otherwise be allocating/decallocating the channel state vector at
regular intervals.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-16 16:16:36 -05:00
Thomas Tsou
2c79110969 Transceiver52M: UHD: Check running status before stopping stream
On startup errors we get a segfault if we stop and shutdown. This
is because we try to send a stop stream command to the device before
it has been created. Setup a check for running status before
attempting to stop the physical device.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-16 01:44:07 -05:00
Thomas Tsou
85b179d125 Transceiver52M: Create new osmo-trx executable
Create new main executable with full command line option parsing
of relevant parameters. Database configuration table still exists
(and must exist because of the global gConfig object), but can
be bypassed with command line options.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-16 01:44:07 -05:00
Thomas Tsou
2e622ff131 Transceiver52M: Output device and operating mode to stdout
Very useful user information at startup.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-16 01:43:46 -05:00
Thomas Tsou
3f32ab5afa Transceiver52M: Enable all warnings and resolve
Mainly basic signed vs unsigned comparisons and intializer ordering.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
8c33679fa5 Transceiver52M: Add virtual destructor for radio device
Empty destructor removes compile warning.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
477b77c558 Transceiver52M: Remove unused code
This includes unknown and unused variables, functions, and
non-relevant documentation.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
d3fccea05f Transceiver52M: Allow only channel zero to set TSC value
We support one TSC value per each transceiver object. Only channel
zero can set this value. Other channels can attempt to set the TSC
value, but will error if the TSC does not match the existing value.
In either case, non-zero channels do not manipulate the gloabl TSC
setting.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
cb269a32dd Transceiver52M: Use independent power scaling varables for each channel
Simply vectorize the existing power state variable.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
1882099d15 Transceiver52M: Set const qualifier on appropriate radio vector methods
Pointer accessor and noise average methods for radio and noise vectors
respectively.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
a0179e37f8 Transceiver52M: Use independent noise vectors for each channel
Each ARFCN channel may be independently configureted and possibly on
separate hardware, so don't share a single vector for noise estimate
calculations. Allow a non-pointer based iterator so we can get away
with using the default copy constructor.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
ef25dba4e7 Transceiver52M: Ignore detected bursts at the noise floor
The transceiver has the ability to detect bursts below the noise floor,
but little hope in successful decoding, so don't even try. We still use
the detected burst to differentiate against noise vs actual data.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
2d0c00bd3d Transceiver52M: Check time slot validity of incoming bursts
In errant cases, GSM core may send bursts with invalid slot values,
which is allowed by the GSM::Time object. If we find a burst like this
coming into the transceiver, then drop it immediately.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
e90a42becc Transceiver52M: Add dual channel diversity receiver option
This patch add support for dual channel diversity on the receive
path. This allows two antennas two shared antennas to be used for
each ARFCN handling channel in the receiver. This configuration
may improvde performance in multi-path fading environments,
however, noise andpotential interference levels are increased due
to the higher bandwidth used.

The receive path is oversampled by a factor of four for a rate
of 1.083333 Msps. If the receive paths are tuned within a
maximum channel spacing (currently set at 600 kHz), then both
ARFCN frequencies are processed by each channel of the receiver.
Otherwise, the frequency shifted diversity path is disabled and
standard non-diversity operation takes place.

Diversity processing is handled by selecting the path with the
higheset energy level and discarding the burst on the second
path. Selection occurs on a burst-by-burst basis.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
30421a7e25 Transceiver52M: Refactor receive path outer burst handling
Separate the large pullRadioVector() call, which forms the central
portion of the receive path burst processing. Break out RACH, normal
burst, and demodulation into separate methods. This makes the burst
handling from the FIFO read to soft bit output somewhat more
manageable.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
34bbef754f Transceiver52M: sigproc: Wrap internal phase on frequency shift
The call into table lookup will loop on values outside of the
table range. With continuously increasing phase, this leads
to an eventual permanent hard spin. Wrap the phase value to
prevent that from happening.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
2c1f85a10c Transceiver52M: UHD: Add string descriptors to device-offset pairs
As we add more channel combintions including but not limited to
new devices, signal processing schemes, and diversity, we'll
need to handle more special cases. Add string descriptions for
just a bit more sanity.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
a2fe91a688 Transceiver52M: Add vectorized radio burst capability
This patch allows multiple signalVectors to be stored within
a single radioVector object. The motivation is to provide
a facility for diversity and/or MIMO burst handling. When
no channel value is specified, single channel bevhaviour
is maintained.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
e1ce92599a Transceiver52M: Rearrange socket port assignemnts
Style change for clarity only.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
b075dd2f73 Transceiver52M: Dynamically allocate correlation vectors
Stack allocating the correlation output generates a call to the copy
constructor of an zero valued vector. We can avoid this extra copy
constructor with a pointer reference and dynamic allocation.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
94edaaeee6 Transceiver52M: Allow separate in/out vectors for delay and decimation
Allow non-in-place use of the delay setting. Internally, the delay call
creates a new vector and copies the contents back into the original.
Instead, provide the option to return the computed output vector
directly and remove an an extra copy in the process.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
0e0e1f4363 Transceiver52M: Setup sinc() call directly with table lookup
On Beagle Board the call into the sinc() function is generating a lot of
load on the peak interpolation. Simplify the sinc() function with a
dedicated table lookup. Eventually, this table may be removed in favour
of using a precomputed filterbank for fractional delay determination.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
d0f3ca3e94 Transceiver52M: Preallocate head room for burst correlation
Set a transceiver high level length value that specifies the largest
number of complex or real filter taps that we will encounter. This
allows preallocation of head room and prevents an extra allocation and
copy on every incoming receive burst.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
f8bc7c351f Transceiver52M: UHD: Continue on receive and send timeouts
With testing on current UHD releases, currently 003.005.xxx series,
timeout errors on both receive and transmit are recoverable on network
and USB based devices. Remove the fatal error conditions.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
a4cf48cf8b Transceiver52M: Set priority on downlink socket thread
Clock indications passed up to GSM core originate on the transciever
downlink side. Set priority to keep the flow of clock updates
consistent.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
7940335586 Transceiver52M: Default to 1 sample-per-symbol low powered devices
This includes ARM Cortex A8 and A15 powered device such as Beagle
Board, Gumstix driven E100 USRP, and Arndale board. Set the reduced
SPS value automatically for the user.

For x86, if we don't support SSE3, then the architecture is
probably ancient and not with using. Drop the sampling down anyways
to at least make an attempt. Non floating point SIMD devices (e.g.
Raspberry Pi) also fall in this category

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
f79c4d06ff Transceiver52M: Precompute fractional delay filters
Preallocate and compute a bank of fractional sample delay filters.
The number of filters to allocate is specified by the DELAYFILTS
preprocessor definition with a default value of 64. The filters
themselves are sinc pulse generated with 20 taps and Blackman-harris
windowed .

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
20eb6d64fd Transceiver52M: Separate signalVector into it's own file
Break out the signalVector object and clean up the interface in the
process.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
e0fa2bfd93 Transceiver52M: Remove extra copy in receive drive path
Currently the code allocations a signalVector and then copies
into a radioVector. This is unnecessary because the latter is
a derived class making the first allocation unnecessary.
Modify the radioVector constructor to allow direct use in the
case above.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
6f4906e375 Transceiver52M: Dynamically allocate convolution input vectors
This prevents the use of a copy constructor in the downlink
modulator and prevents a secondary memory allocation during
the convolution. Avoid both cases by dynamically allocating
with preloaded head room. The latter provides enough memory
before the first sample in the burst to cover the length
of the filter taps.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:35:07 -05:00
Thomas Tsou
0a3dc4c210 Transceiver52M: Add NEON complex-complex multiply
Complex-complex block multiples are used for phase rotation of
bursts. Optimization targeted from perf profiling.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:34:59 -05:00
Thomas Tsou
acc22fa3ff Transceiver52M: Use USRP1 type window for B2xx devices
B2xx is a USB based device so use the USRP1 based adaptive flow
control window for transmit bursts. This adds additional stability
primarily on ARM platforms.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:32:40 -05:00
Thomas Tsou
7553aa973f Transceiver52M: Set variable thread priority levels
The transceiver and underlying device drivers are threaded. use
the following priority levels.

0.50 - UHD driver internal threads
0.45 - Receive device drive thread
0.44 - Transmit device drive thread
0.43 - UHD asynchronous update thread (error reporting)
0.42 - Receive burst processing thread(s)

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:32:40 -05:00
Thomas Tsou
7e4e536b1b Transceiver52M: Add ARM NEON support
Similar to the existing Intel SSE cases, add support for NEON vector
floating point SIMD processing. In this case, use ARM assembly
directly as the NEON intrinsics do not generate preferential code
output.

Currently support NEON vectorized convolution and floating point
integer conversions.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 23:32:35 -05:00
Thomas Tsou
204a9f135a Transceiver52M: Add multi channel transceiver support
This patch primarily addresses devices with multiple RF front end
support. Currently device support is limited to UmTRX.

Vectorize transceiver variables to allow multiple asynchronous
threads on the upper layer with single downlink and uplink threads
driving the UHD I/O interface synchronously.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-15 14:45:20 -05:00
Thomas Tsou
0169b310de Transceiver52M: Remove unnecessary UHD clock setting call
There is no need to create this method. Just call the UHD interface
directly.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-08 11:33:31 -05:00
Thomas Tsou
66e2dd2543 Transceiver52M: Remove unused files and utilities
USRPping and sigProcLibTest are in an unmaintained state,
while the intended functionality remains unknown. Stored
filter taps are also unused and should also be removed.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-08 11:33:31 -05:00
Thomas Tsou
f078273a8a Transceiver52M: Separate transceiver per-slot state information
Collect the slot information into an indpendent state object. This
will allow us to easily create multiple instances of internal state
variables without having to replicate the transceiver object itself.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-08 11:33:31 -05:00
Thomas Tsou
d647ec5dc1 Transceiver52M: Delay socket allocation to heap
For multiple transceiver connections, it is inappropriate to
allocate all sockets in the transceiver constructor due to not
knowing how many connections are avaialble in advance and for
error checking purposes. Instead, store the base socket address
port combination and setup the sockets in the initialization
call.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-08 11:33:31 -05:00
Thomas Tsou
c289d7a409 Transceiver52M: Remove transmit logging option
The current status and operability of this compile option is
unknown. Remove due to lack of use, demand, and maintenance.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-08 11:33:31 -05:00
Thomas Tsou
035bee5c32 build: Remove subversion references
We do not use subversion. We do not need to refer to subversion
reference numbers.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-08 11:18:46 -05:00
Thomas Tsou
cf910dcdda Transceiver52M: Reset overrun and underrun indicators
Underruns are only explicitly set on the downlink side. Overruns
are logged but unused. In either case, reset indicators to false
to avoid sending false state information.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-07 23:07:49 -05:00
Thomas Tsou
69762fd7c6 Transceiver52M: Fix SSE preprocessor definition
Using non-SSE4.1 enabled architecture would cause undefined
reference to 'convert_si16_ps' call.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-07 22:57:21 -05:00
Thomas Tsou
fffd987f22 build: Set UHD driver as default configuration
Currently the default configuration is to not build the full
transceiver, which is pointless. Set the UHD driver, which
includes either Ettus or Fairwaves variants, as the default.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-04 10:23:24 -08:00
Thomas Tsou
17bbb9b755 Transceiver52M: Separate architecture specific files
Move x86 specific files into their own directory as this
area is about to get crowded with the addition of ARM
support.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-11-04 09:15:55 -08:00
Thomas Tsou
a1a3ab4bab Transceiver52M: Update RSSI calculation
Use the same measurement method for RSSI as the noise level. Previous
method was to use the peak correlation amplitude relative to the
expected value. This created two very different amplitude approaches
between the noise measurement and RSSI measurement, which would
throw off the upper layer MS power control loop.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:18 -04:00
Thomas Tsou
fa3a787ccb Transceiver52M: Update noise measurement calculation
Previous removal of the energy detector requirement broke
the noise level calculation loop. The previous adaptive
approach was finicky - noticably at high gain levels. Since
we no longer use the energy threshold for primary burst gating,
we can return to a simpler world.

In the new approach, we compute a running average of energy
levels and track them with a noise vector. A timeslot that
passes the correlator threshold is a valid burst. These are
not used in the noise calculation. Everything else is
considered noise and used to compute the noise level with
respect to full scale input level, which for almost all
supported devices is 2^15.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:18 -04:00
Thomas Tsou
010fff783b Transceiver52M: Move reference select from compile time to database
Enabling the external reference on UHD devices through the configure
time switch is awkward. Use a database variable "TRX.Reference" with
'0' or '1' value for internal and external references respectively.
Use internal reference is no entry is defined.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:18 -04:00
Thomas Tsou
61b4a6ad9f Transceiver52M: Delay UHD messaging registration until after start
We want to push UHD logs to the OpenBTS logging system, but most
device errors occur at startup, so keep the output on stdout until
after device initialization. That way obvious errors are easily
viewable before seeing the useless TRX timeout message.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:18 -04:00
Thomas Tsou
de1648ca6b Transceiver52M: Deallocate high level resources on shutdown
This primarily addresses the error case at initialization.
In the event that the transceiver fails to start, we should
be able cleanly shutdown and release while providing a useful
reason for exiting.

After the radio is started and threads launched, there
are no thread state variables or shutdown messaging between
threads, and the transceiver cannot be consistently
shutdown. This issue remains to be solved.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:18 -04:00
Thomas Tsou
3952d80d05 Transceiver52M: Reduce and place bounds checking on I/O buffers
Previous send and receive buffers at the radio interface were
arbitrarily set to a sufficient size. For normal (non-resampling)
devices, use a block (chunk) size of 625 samples. For 64 or 100
MHz resampling devices, use 4 times the reduced resampling
numerator or denominator and provide bounds checking where
appropriate.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:18 -04:00
Thomas Tsou
fe269fe31d Transceiver52M: Add 64 MHz resampling option with B100
Move B100 to the resampling interface with default
clocking. This temporarily resolves undetermined
FPGA clocking issues. This also provides extensible
support for multiple clocking rates and resampling
ratios.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:18 -04:00
Thomas Tsou
c064124429 Transceiver52M: Remove support for ancient libusrp versions
Current functionality with these old versions is questionable.
There is no reason to use any version of GNU Radio / libusrp older
than 3.3. Version 3.4.2 is the only recommended version for USRP1
users.

Non-USRP1 users must use UHD driver from Ettus Research.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:17 -04:00
Thomas Tsou
69d14c9a14 Transceiver52M: Add B210 support
Identical to B200 support, but explicitly check for the device type
name.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:17 -04:00
Thomas Tsou
c1f7c42a33 Transceiver52M: Setup dual sample rate transceiver
This patch applies oversampling, when selected with 4 sps,
to the downlink only, while running the receiver with
minimal sampling at 1 sps. These split sample rates allow
us to run a highly accurate downlink signal with minimal
distortion, while keeping receive path channel filtering
on the FPGA.

Without this patch, we oversample the receive path and
require a steep receive filter to get similar adjacent
channel suppression as the FPGA halfband / CIC filter
combination, which comes with a high computational cost.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:17 -04:00
Thomas Tsou
2c282f5e12 Transceiver52M: Generate delay filter with SSE memory alignment
This requires an additional memcpy() on the signal vector
constructor, but allows the interpolation filter to use
SSE optimzationed convolution.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:17 -04:00
Thomas Tsou
92c16df875 Transceiver52M: Separate main transmit and receive drive threads
This patch primarily addresses observed repeated overrun
conditions in embedded environments - namely ARM.

The heartbeat of the transceiver is derived from the receive
sample stream, which drives the main GSM clock. Detach the
transmit thread from the receive loop to avoid interfering with
the receive I/O, which is sensitive to overrun conditions if
pull process is interrupted.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:17 -04:00
Thomas Tsou
d5a80c3dc6 Transceiver52M: Disable equalization
Unsupported at 4 sps, and performance benefits remain
to be proven at 1 sps. Disable until further testing.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:17 -04:00
Thomas Tsou
dafb33700e Transceiver52M: Reduce RACH and TSC correlation windows
Start the correlation search window at 4 symbols before
the expected correlation peak. End the search at 10
symbols and 4 + maximum expected delay for RACH and TSC
bursts respectively.

This change lowers receive side cpu utilization while
maintaining reasonable timing jitter and accuracy tolerance.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:17 -04:00
Thomas Tsou
0e44ab360e Transceiver52M: Narrow resampling filter bandwidth
This patch only applies to resampling use at 4 samples-per-symbol.
By extention that means only USRP2 / N2xx devices are affected.
At 4 samples-per-symbol we restrict output bandwidth to roughly
roughly 700 MHz, which combined with the 2 pulse Laurent
approximation yields < 0.5 degrees of RMS phase error at the
resampler output.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:17 -04:00
Thomas Tsou
092f757ec2 Transceiver52M: Add B200 support
Set master clock rate to 52 MHz for B200. Also, we want to avoid
floating point comparison errors on clock rate settings, but we
expect to be able really set the rates we specify. Set the
offset limit to 1 Hz. If we can't set our rates with that level
of precision, then something is wrong.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:17 -04:00
Thomas Tsou
a57bc8a3b9 Transceiver52M: Setup dual Laurent pulse shaping filter
Provides substantially improved transmit phase error
performance when enabled. Requires use of 4 samples
per symbol, and is enabled by default when set.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:17 -04:00
Thomas Tsou
84c60f6679 Transceiver52M: Check that sample rates are sane before using
If there is an error in the sample rate determination, noted
by a negative return sample rate value, error directly and
don't try to set the device rate.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:17 -04:00
Thomas Tsou
865bca42d6 Transceiver52M: Refactor RACH and normal burst detection
Both RACH and normal bursts are detected with the same approach of
midamble correlation combined with peak-to-average ratio. The
difference is the midamble placements and lengths. Thus, there is
no reason to have independent implementations.

This patch creates a common call burstDetect(), while leaving the
correlation window indexing in the original calls.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:17 -04:00
Thomas Tsou
c88d8d53f8 Transceiver52M: Add UmTRX support
Requires Fairwaves UHD driver.

  https://github.com/chemeris/UHD-Fairwaves.git

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:17 -04:00
Thomas Tsou
9ccd9f2c3c Transceiver52M: Add 4 samples-per-symbol Laurent pulse shape
When 4 samples-per-symbol operation is selected, replace the
existing pulse approximation, which becomes inaccurate with
non-unit oversampling, with the primary pulse, C0, from the
Laurent linear pulse approximation.

Pierre Laurent, "Exact and Approximate Construction of Digital Phase
  Modulations by Superposition of Amplitude Modulated Pulses", IEEE
  Transactions of Communications, Vol. 34, No. 2, Feb 1986.

Octave pulse generation code for the first three pulses of the
linear approximation are included.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:17 -04:00
Thomas Tsou
8181b0104a Transceiver52M: Disable energy detector
The adaptive energy threshold gating suffers a near-far problem
at certain gain levels. This is due to exponential threshold
raising, but linear decreases. A large signal level followed by
a period low signal level causes (comparatively) weak signals to
go undetected. Additionally, the algorithm performs differently
at multiple RF gain levels.

This patch switches solely to correlation based gating for burst
detection. The main computational load with this approach is
sub-sample width peak interpolation, which we disable for intial
detection and run after threshold passing.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:17 -04:00
Thomas Tsou
9471d7635a Transceiver52M: Add SSE floating point / integer conversion
Convertions are performed in multiples of 4 or 8. All loads are
considered unaligned.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:17 -04:00
Thomas Tsou
03e6ecf977 Transceiver52M: Replace resampler with SSE enabled implementation
Replace the polyphase filter and resampler with a separate
implementation using SSE enabled convolution. The USRP2 (including
derived devices N200, N210) are the only supported devices that
require sample rate conversion, so set the default resampling
parameters for the 100 MHz FPGA clock. This changes the previous
resampling ratios.

  270.833 kHz -> 400 kHz      (65 / 96)
  270.833 kHz -> 390.625 kHz  (52 / 75)

The new resampling factor uses a USRP resampling factor of 256
instead of 250. On the device, this allows two halfband filters to
be used rather than one. The end result is reduced distortial and
aliasing effecits from CIC filter rolloff.

B100 and USRP1 will no be supported at 400 ksps with these changes.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:17 -04:00
Thomas Tsou
3eaae80c90 Transceiver52M: Replace convolve and related calls with SSE implementation
This large patch replaced the convolve() call with an SSE vector
enabled version. The lower C and SSE intrinsic based code operates
on fixed and aligned vectors for the filter taps. The storage format
of interleaved I/Q for both complex and real vectors is maintained.

SSE filter tap values must:

  1. Start 16-byte aligned
  2. Number with a multiple of 4 between 4 and 20 for real taps
  3. Number with a multiple of 4 for complex taps

Non-compliant values will fall back to non-SSE usage. Fixed length
iterators mean that head and tail cases may require reallocation of
the input vector, which is automatically handled by the upper C++
interface.

Other calls are affected by these changes and adjusted or rewritten
accordingly. The underlying algorithms, however, are unchanged.

  generateGSMPulse()
  analyzeTrafficBurst()
  detectRACHBurst()

Intel SSE configuration is automatically detected and configured at
build time with Autoconf macros.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:17 -04:00
Thomas Tsou
e57004d0c3 Transceiver52M: Generate RACH correlation sequence at initialization
There is no temporal dependency on when the RACH sequence is generated,
so there is no need for transceiver to create it in response to a
command from GSM core. If we power on the transceiver, we will need
the RACH sequence, so just allocate it during initialization.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:17 -04:00
Thomas Tsou
6aa1f18f41 Transceiver52M: Remove logging from signal processing core
The only logging outputs in the the signal processing library
are debug lines that generate copious amounts of output while
providing little useful information to the user. The relevant
information (time-of-arrival, channel gains, etc.) can and
should be logged from transceiver instance itself.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:17 -04:00
Thomas Tsou
e5dcfc4f80 Transceiver52M: Add destructors to correlation seqeunce objects
Add destructor calls so we can avoid the nested vector deallocations.
Also remove the unnecessary pointer NULL checks prior to destruction.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:17 -04:00
Thomas Tsou
83e0689e76 Transceiver52M: Make GSM pulse filter internal to implementation
There is no reason expose the pulse shaping filter outside of the
signal processing calls. The main transceiver object makes no use
of the filter and there's no reason to pass it around.

Initialize the pulse shape with the signal processing library, and
maintain an internal static member like many of the other library
variables. Similarly destroy the object when the library is closed.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:10:04 -04:00
Thomas Tsou
d24cc2cd96 Transceiver52M: Rename samples-per-symbol variable names
Because repeatedly typing mSamplesPerSymbol is giving me
carpal tunnel syndrome. Replace with the much shorter,
easier to type, and just as clear name of 'sps'.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:04:15 -04:00
Thomas Tsou
ddd6defb43 Transceiver52M: Verify global config sanity before using
The configuration table is instantiated as a global variable with
no means to check constructor status. This means various types
of database failure conditions (e.g. file existence, permissions,
etc.) are not reported. This patch performs a small number of
checks to make sure that the configuration is sane.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:04:13 -04:00
Thomas Tsou
96794cb746 Transceiver52M: Remove unused test code from main
The commented out test code is not maintained and behaviour is
unknown. Remove for clarity.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:03:41 -04:00
Thomas Tsou
7e06806ff0 Transceiver52M: Use exception blocks for rate changes
UHD will throw if something goes awry in these sensitive sections,
so we should catch and shutdown gracefully. There is no recovery
if we can't set rates.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:03:41 -04:00
Thomas Tsou
cb69f08410 Transceiver52M: Set resampling option automatically based on device
Remove the built time resampling selection and link both options.
Move the normal push/pullBuffer() calls back to the base class and
overload them in the inherited resampling class.

USRP2/N2xx devices are the only devices that require resampling so
return that resampling is necessary on the device open(), which is
the point at which the device type will be known.

The GSM transceiver only operates at a whole number multiple of
the GSM rate and doesn't care about the actual device rate and
if resampling is used. Therefore GSM specific portion of the
transceiver should only need to submit the samples-per-symbol
value to the device interface.

Then, the device should be able to determine the appropriate
sample rate (400 ksps or 270.833 ksps) and if resampling is
appropriate.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:03:41 -04:00
Thomas Tsou
312e387630 Transceiver52M: Remove and rename oversampling variables
The transceiver only uses a single integer oversampling value,
which is more simply referred to as samples-per-symbol.

mRadioOversampling --> mSPS
mTransceiverOversampling (removed)

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:03:41 -04:00
Thomas Tsou
f2293b8cfa Transceiver52M: Remove periodic alignment update from UHD build
Periodic timing alignment should never be required for UHD devices,
though the mechanism was used as a fallback mechanism should UHD
not properly recover after an underrun - as may occur in old
003.003.000 based revisions. This issue is not a concern in more
recent UHD releases and deprecates this code for legacy USRP1
use only.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:03:41 -04:00
Thomas Tsou
e3e8814948 Transceiver52M: Add device offset correction table
Previously, two timing correction values were used for UHD devices
depending on the sample rate of 270.833e3 or 400e3 for native GSM or
resampled device rate respectively. The correction values compensate
for residual timing effects due to analog component delays, filters
lag times, and general fudge factors. These values are device
specific and over-generalized by the two value configuration.

This patch adds the following struct to store these correction
values by device type and sample rate - through samples-per-symbol.

struct uhd_dev_offset {
        enum uhd_dev_type type;
        int sps;
        double offset;
};

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:03:41 -04:00
Thomas Tsou
02d88d1380 Transceiver52M: Add UHD device type checking
UHD device type was previously detected, but only categorized in
terms of bus type, USB or Ethernet, and sample rate capability.
With the number of supported device increasing, we can no longer
easily group devices since we need to handle more and more
device-specific peculiarities. Some of these factors are managed
internally by the UHD driver, but other factors (e.g. timing
offsets) are specific to a single device.

Start by maintaining an enumerated list of relevant device types
that we can use for applying device specific operations. Also
rename the USB/Ethernet grouping to transmit window type because
that's what it is.

enum uhd_dev_type {
        USRP1,
        USRP2,
        B100,
        NUM_USRP_TYPES,
};

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:03:41 -04:00
Thomas Tsou
b4cb4e23c0 Transceiver52M: Update to UHD streamer interface
This patch is long overdue and can now be merged after better understanding
of timestamp stability issues. UHD tick / timespec conversions were
generally used with the streamer interface, though these calls are actually
independent change sets. The combination would lead to internal rounding
errors and a timing drift most notably on B100 running at GSM symbol
rate multiples. There are no known issues, however, with the streamer code
itself.

The aforementioned issue was discovered in test code only, which was never
merged to mainline.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
2013-10-18 13:03:41 -04:00
131 changed files with 11440 additions and 152389 deletions

48
.gitignore vendored Normal file
View File

@@ -0,0 +1,48 @@
# build results
*.o
*.lo
*.la
Transceiver52M/osmo-trx
Transceiver52M/osmo-trx-gen
Transceiver52M/osmo-trx-dec
# tests
CommonLibs/BitVectorTest
CommonLibs/ConfigurationTest
CommonLibs/F16Test
CommonLibs/InterthreadTest
CommonLibs/LogTest
CommonLibs/RegexpTest
CommonLibs/SocketsTest
CommonLibs/TimevalTest
CommonLibs/URLEncodeTest
CommonLibs/VectorTest
CommonLibs/PRBSTest
# automake/autoconf
*.in
.deps
.libs
.dirstamp
*~
Makefile
config.log
config.status
config.h
config.guess
config.sub
config/*
configure
compile
aclocal.m4
autom4te.cache
depcomp
install-sh
libtool
ltmain.sh
missing
stamp-h1
INSTALL
# vim
*.sw?

3
.gitreview Normal file
View File

@@ -0,0 +1,3 @@
[gerrit]
host=gerrit.osmocom.org
project=osmo-trx

View File

@@ -30,6 +30,7 @@
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <math.h>
using namespace std;
@@ -199,49 +200,6 @@ void BitVector::LSB8MSB()
uint64_t BitVector::syndrome(Generator& gen) const
{
gen.clear();
const char *dp = mStart;
while (dp<mEnd) gen.syndromeShift(*dp++);
return gen.state();
}
uint64_t BitVector::parity(Generator& gen) const
{
gen.clear();
const char *dp = mStart;
while (dp<mEnd) gen.encoderShift(*dp++);
return gen.state();
}
void BitVector::encode(const ViterbiR2O4& coder, BitVector& target)
{
size_t sz = size();
assert(sz*coder.iRate() == target.size());
// Build a "history" array where each element contains the full history.
uint32_t history[sz];
uint32_t accum = 0;
for (size_t i=0; i<sz; i++) {
accum = (accum<<1) | bit(i);
history[i] = accum;
}
// Look up histories in the pre-generated state table.
char *op = target.begin();
for (size_t i=0; i<sz; i++) {
unsigned index = coder.cMask() & history[i];
for (unsigned g=0; g<coder.iRate(); g++) {
*op++ = coder.stateTable(g,index);
}
}
}
unsigned BitVector::sum() const
{
unsigned sum = 0;
@@ -287,148 +245,12 @@ ostream& operator<<(ostream& os, const BitVector& hv)
ViterbiR2O4::ViterbiR2O4()
{
assert(mDeferral < 32);
mCoeffs[0] = 0x019;
mCoeffs[1] = 0x01b;
computeStateTables(0);
computeStateTables(1);
computeGeneratorTable();
}
void ViterbiR2O4::initializeStates()
{
for (unsigned i=0; i<mIStates; i++) clear(mSurvivors[i]);
for (unsigned i=0; i<mNumCands; i++) clear(mCandidates[i]);
}
void ViterbiR2O4::computeStateTables(unsigned g)
{
assert(g<mIRate);
for (unsigned state=0; state<mIStates; state++) {
// 0 input
uint32_t inputVal = state<<1;
mStateTable[g][inputVal] = applyPoly(inputVal, mCoeffs[g], mOrder+1);
// 1 input
inputVal |= 1;
mStateTable[g][inputVal] = applyPoly(inputVal, mCoeffs[g], mOrder+1);
}
}
void ViterbiR2O4::computeGeneratorTable()
{
for (unsigned index=0; index<mIStates*2; index++) {
mGeneratorTable[index] = (mStateTable[0][index]<<1) | mStateTable[1][index];
}
}
void ViterbiR2O4::branchCandidates()
{
// Branch to generate new input states.
const vCand *sp = mSurvivors;
for (unsigned i=0; i<mNumCands; i+=2) {
// extend and suffix
const uint32_t iState0 = (sp->iState) << 1; // input state for 0
const uint32_t iState1 = iState0 | 0x01; // input state for 1
const uint32_t oStateShifted = (sp->oState) << mIRate; // shifted output
const float cost = sp->cost;
sp++;
// 0 input extension
mCandidates[i].cost = cost;
mCandidates[i].oState = oStateShifted | mGeneratorTable[iState0 & mCMask];
mCandidates[i].iState = iState0;
// 1 input extension
mCandidates[i+1].cost = cost;
mCandidates[i+1].oState = oStateShifted | mGeneratorTable[iState1 & mCMask];
mCandidates[i+1].iState = iState1;
}
}
void ViterbiR2O4::getSoftCostMetrics(const uint32_t inSample, const float *matchCost, const float *mismatchCost)
{
const float *cTab[2] = {matchCost,mismatchCost};
for (unsigned i=0; i<mNumCands; i++) {
vCand& thisCand = mCandidates[i];
// We examine input bits 2 at a time for a rate 1/2 coder.
const unsigned mismatched = inSample ^ (thisCand.oState);
thisCand.cost += cTab[mismatched&0x01][1] + cTab[(mismatched>>1)&0x01][0];
}
}
void ViterbiR2O4::pruneCandidates()
{
const vCand* c1 = mCandidates; // 0-prefix
const vCand* c2 = mCandidates + mIStates; // 1-prefix
for (unsigned i=0; i<mIStates; i++) {
if (c1[i].cost < c2[i].cost) mSurvivors[i] = c1[i];
else mSurvivors[i] = c2[i];
}
}
const ViterbiR2O4::vCand& ViterbiR2O4::minCost() const
{
int minIndex = 0;
float minCost = mSurvivors[0].cost;
for (unsigned i=1; i<mIStates; i++) {
const float thisCost = mSurvivors[i].cost;
if (thisCost>=minCost) continue;
minCost = thisCost;
minIndex=i;
}
return mSurvivors[minIndex];
}
const ViterbiR2O4::vCand& ViterbiR2O4::step(uint32_t inSample, const float *probs, const float *iprobs)
{
branchCandidates();
getSoftCostMetrics(inSample,probs,iprobs);
pruneCandidates();
return minCost();
}
uint64_t Parity::syndrome(const BitVector& receivedCodeword)
{
return receivedCodeword.syndrome(*this);
}
void Parity::writeParityWord(const BitVector& data, BitVector& parityTarget, bool invert)
{
uint64_t pWord = data.parity(*this);
if (invert) pWord = ~pWord;
parityTarget.fillField(0,pWord,size());
}
SoftVector::SoftVector(const BitVector& source)
{
resize(source.size());
for (size_t i=0; i<size(); i++) {
if (source.bit(i)) mStart[i]=1.0F;
else mStart[i]=0.0F;
else mStart[i]=-1.0F;
}
}
@@ -438,102 +260,20 @@ BitVector SoftVector::sliced() const
size_t sz = size();
BitVector newSig(sz);
for (size_t i=0; i<sz; i++) {
if (mStart[i]>0.5F) newSig[i]=1;
if (mStart[i]>0.0F) newSig[i]=1;
else newSig[i] = 0;
}
return newSig;
}
void SoftVector::decode(ViterbiR2O4 &decoder, BitVector& target) const
{
const size_t sz = size();
const unsigned deferral = decoder.deferral();
const size_t ctsz = sz + deferral*decoder.iRate();
assert(sz <= decoder.iRate()*target.size());
// Build a "history" array where each element contains the full history.
uint32_t history[ctsz];
{
BitVector bits = sliced();
uint32_t accum = 0;
for (size_t i=0; i<sz; i++) {
accum = (accum<<1) | bits.bit(i);
history[i] = accum;
}
// Repeat last bit at the end.
for (size_t i=sz; i<ctsz; i++) {
accum = (accum<<1) | (accum & 0x01);
history[i] = accum;
}
}
// Precompute metric tables.
float matchCostTable[ctsz];
float mismatchCostTable[ctsz];
{
const float *dp = mStart;
for (size_t i=0; i<sz; i++) {
// pVal is the probability that a bit is correct.
// ipVal is the probability that a bit is incorrect.
float pVal = dp[i];
if (pVal>0.5F) pVal = 1.0F-pVal;
float ipVal = 1.0F-pVal;
// This is a cheap approximation to an ideal cost function.
if (pVal<0.01F) pVal = 0.01;
if (ipVal<0.01F) ipVal = 0.01;
matchCostTable[i] = 0.25F/ipVal;
mismatchCostTable[i] = 0.25F/pVal;
}
// pad end of table with unknowns
for (size_t i=sz; i<ctsz; i++) {
matchCostTable[i] = 0.5F;
mismatchCostTable[i] = 0.5F;
}
}
{
decoder.initializeStates();
// Each sample of history[] carries its history.
// So we only have to process every iRate-th sample.
const unsigned step = decoder.iRate();
// input pointer
const uint32_t *ip = history + step - 1;
// output pointers
char *op = target.begin();
const char *const opt = target.end();
// table pointers
const float* match = matchCostTable;
const float* mismatch = mismatchCostTable;
size_t oCount = 0;
while (op<opt) {
// Viterbi algorithm
assert(match-matchCostTable<sizeof(matchCostTable)/sizeof(matchCostTable[0])-1);
assert(mismatch-mismatchCostTable<sizeof(mismatchCostTable)/sizeof(mismatchCostTable[0])-1);
const ViterbiR2O4::vCand &minCost = decoder.step(*ip, match, mismatch);
ip += step;
match += step;
mismatch += step;
// output
if (oCount>=deferral) *op++ = (minCost.iState >> deferral)&0x01;
oCount++;
}
}
}
// (pat) Added 6-22-2012
float SoftVector::getEnergy(float *plow) const
{
const SoftVector &vec = *this;
int len = vec.size();
float avg = 0; float low = 1;
for (int i = 0; i < len; i++) {
float bit = vec[i];
float energy = 2*((bit < 0.5) ? (0.5-bit) : (bit-0.5));
float energy = fabsf(vec[i]);
if (energy < low) low = energy;
avg += energy/len;
}
@@ -545,8 +285,12 @@ float SoftVector::getEnergy(float *plow) const
ostream& operator<<(ostream& os, const SoftVector& sv)
{
for (size_t i=0; i<sv.size(); i++) {
if (sv[i]<0.25) os << "0";
else if (sv[i]>0.75) os << "1";
if (sv[i]<-0.5) os << "0";
else if (sv[i]<-0.25) os << "o";
else if (sv[i]<0.0) os << ".";
else if (sv[i]>0.5) os << "1";
else if (sv[i]>0.25) os << "|";
else if (sv[i]>0.0) os << "'";
else os << "-";
}
return os;

View File

@@ -30,201 +30,6 @@
#include <stdint.h>
class BitVector;
class SoftVector;
/** Shift-register (LFSR) generator. */
class Generator {
private:
uint64_t mCoeff; ///< polynomial coefficients. LSB is zero exponent.
uint64_t mState; ///< shift register state. LSB is most recent.
uint64_t mMask; ///< mask for reading state
unsigned mLen; ///< number of bits used in shift register
unsigned mLen_1; ///< mLen - 1
public:
Generator(uint64_t wCoeff, unsigned wLen)
:mCoeff(wCoeff),mState(0),
mMask((1ULL<<wLen)-1),
mLen(wLen),mLen_1(wLen-1)
{ assert(wLen<64); }
void clear() { mState=0; }
/**@name Accessors */
//@{
uint64_t state() const { return mState & mMask; }
unsigned size() const { return mLen; }
//@}
/**
Calculate one bit of a syndrome.
This is in the .h for inlining.
*/
void syndromeShift(unsigned inBit)
{
const unsigned fb = (mState>>(mLen_1)) & 0x01;
mState = (mState<<1) ^ (inBit & 0x01);
if (fb) mState ^= mCoeff;
}
/**
Update the generator state by one cycle.
This is in the .h for inlining.
*/
void encoderShift(unsigned inBit)
{
const unsigned fb = ((mState>>(mLen_1)) ^ inBit) & 0x01;
mState <<= 1;
if (fb) mState ^= mCoeff;
}
};
/** Parity (CRC-type) generator and checker based on a Generator. */
class Parity : public Generator {
protected:
unsigned mCodewordSize;
public:
Parity(uint64_t wCoefficients, unsigned wParitySize, unsigned wCodewordSize)
:Generator(wCoefficients, wParitySize),
mCodewordSize(wCodewordSize)
{ }
/** Compute the parity word and write it into the target segment. */
void writeParityWord(const BitVector& data, BitVector& parityWordTarget, bool invert=true);
/** Compute the syndrome of a received sequence. */
uint64_t syndrome(const BitVector& receivedCodeword);
};
/**
Class to represent convolutional coders/decoders of rate 1/2, memory length 4.
This is the "workhorse" coder for most GSM channels.
*/
class ViterbiR2O4 {
private:
/**name Lots of precomputed elements so the compiler can optimize like hell. */
//@{
/**@name Core values. */
//@{
static const unsigned mIRate = 2; ///< reciprocal of rate
static const unsigned mOrder = 4; ///< memory length of generators
//@}
/**@name Derived values. */
//@{
static const unsigned mIStates = 0x01 << mOrder; ///< number of states, number of survivors
static const uint32_t mSMask = mIStates-1; ///< survivor mask
static const uint32_t mCMask = (mSMask<<1) | 0x01; ///< candidate mask
static const uint32_t mOMask = (0x01<<mIRate)-1; ///< ouput mask, all iRate low bits set
static const unsigned mNumCands = mIStates*2; ///< number of candidates to generate during branching
static const unsigned mDeferral = 6*mOrder; ///< deferral to be used
//@}
//@}
/** Precomputed tables. */
//@{
uint32_t mCoeffs[mIRate]; ///< polynomial for each generator
uint32_t mStateTable[mIRate][2*mIStates]; ///< precomputed generator output tables
uint32_t mGeneratorTable[2*mIStates]; ///< precomputed coder output table
//@}
public:
/**
A candidate sequence in a Viterbi decoder.
The 32-bit state register can support a deferral of 6 with a 4th-order coder.
*/
typedef struct candStruct {
uint32_t iState; ///< encoder input associated with this candidate
uint32_t oState; ///< encoder output associated with this candidate
float cost; ///< cost (metric value), float to support soft inputs
} vCand;
/** Clear a structure. */
void clear(vCand& v)
{
v.iState=0;
v.oState=0;
v.cost=0;
}
private:
/**@name Survivors and candidates. */
//@{
vCand mSurvivors[mIStates]; ///< current survivor pool
vCand mCandidates[2*mIStates]; ///< current candidate pool
//@}
public:
unsigned iRate() const { return mIRate; }
uint32_t cMask() const { return mCMask; }
uint32_t stateTable(unsigned g, unsigned i) const { return mStateTable[g][i]; }
unsigned deferral() const { return mDeferral; }
ViterbiR2O4();
/** Set all cost metrics to zero. */
void initializeStates();
/**
Full cycle of the Viterbi algorithm: branch, metrics, prune, select.
@return reference to minimum-cost candidate.
*/
const vCand& step(uint32_t inSample, const float *probs, const float *iprobs);
private:
/** Branch survivors into new candidates. */
void branchCandidates();
/** Compute cost metrics for soft-inputs. */
void getSoftCostMetrics(uint32_t inSample, const float *probs, const float *iprobs);
/** Select survivors from the candidate set. */
void pruneCandidates();
/** Find the minimum cost survivor. */
const vCand& minCost() const;
/**
Precompute the state tables.
@param g Generator index 0..((1/rate)-1)
*/
void computeStateTables(unsigned g);
/**
Precompute the generator outputs.
mCoeffs must be defined first.
*/
void computeGeneratorTable();
};
class BitVector : public Vector<char> {
@@ -282,16 +87,6 @@ class BitVector : public Vector<char> {
void zero() { fill(0); }
/**@name FEC operations. */
//@{
/** Calculate the syndrome of the vector with the given Generator. */
uint64_t syndrome(Generator& gen) const;
/** Calculate the parity word for the vector with the given Generator. */
uint64_t parity(Generator& gen) const;
/** Encode the signal with the GSM rate 1/2 convolutional encoder. */
void encode(const ViterbiR2O4& encoder, BitVector& target);
//@}
/** Invert 0<->1. */
void invert();
@@ -427,23 +222,20 @@ class SoftVector: public Vector<float> {
const SoftVector tail(size_t start) const { return segment(start,size()-start); }
//@}
/** Decode soft symbols with the GSM rate-1/2 Viterbi decoder. */
void decode(ViterbiR2O4 &decoder, BitVector& target) const;
// (pat) How good is the SoftVector in the sense of the bits being solid?
// Result of 1 is perfect and 0 means all the bits were 0.5
// How good is the SoftVector in the sense of the bits being solid?
// Result of 1 is perfect and 0 means all the bits were 0.0
// If plow is non-NULL, also return the lowest energy bit.
float getEnergy(float *low=0) const;
/** Fill with "unknown" values. */
void unknown() { fill(0.5F); }
void unknown() { fill(0.0F); }
/** Return a hard bit value from a given index by slicing. */
bool bit(size_t index) const
{
const float *dp = mStart+index;
assert(dp<mEnd);
return (*dp)>0.5F;
return (*dp)>0.0F;
}
/** Slice the whole signal into bits. */

View File

@@ -35,27 +35,6 @@ using namespace std;
int main(int argc, char *argv[])
{
BitVector v1("0000111100111100101011110000");
cout << v1 << endl;
v1.LSB8MSB();
cout << v1 << endl;
ViterbiR2O4 vCoder;
BitVector v2(v1.size()*2);
v1.encode(vCoder,v2);
cout << v2 << endl;
SoftVector sv2(v2);
cout << sv2 << endl;
for (unsigned i=0; i<sv2.size()/4; i++) sv2[random()%sv2.size()]=0.5;
cout << sv2 << endl;
BitVector v3(v1.size());
sv2.decode(vCoder,v3);
cout << v3 << endl;
cout << v3.segment(3,4) << endl;
BitVector v4(v3.segment(0,4),v3.segment(8,4));
cout << v4 << endl;
BitVector v5("000011110000");
int r1 = v5.peekField(0,8);
int r2 = v5.peekField(4,4);
@@ -70,13 +49,6 @@ int main(int argc, char *argv[])
v5.reverse8();
cout << v5 << endl;
BitVector mC = "000000000000111100000000000001110000011100001101000011000000000000000111000011110000100100001010000010100000101000001010000010100000010000000000000000000000000000000000000000000000001100001111000000000000000000000000000000000000000000000000000010010000101000001010000010100000101000001010000001000000000000000000000000110000111100000000000001110000101000001100000001000000000000";
SoftVector mCS(mC);
BitVector mU(mC.size()/2);
mCS.decode(vCoder,mU);
cout << "c=" << mCS << endl;
cout << "u=" << mU << endl;
unsigned char ts[9] = "abcdefgh";
BitVector tp(70);

View File

@@ -53,6 +53,23 @@ static const char* createConfigTable = {
")"
};
static std::string replaceAll(const std::string input, const std::string search, const std::string replace)
{
std::string output = input;
size_t index = 0;
while (true) {
index = output.find(search, index);
if (index == std::string::npos) {
break;
}
output.replace(index, replace.length(), replace);
index += replace.length();
}
return output;
}
float ConfigurationRecord::floatNumber() const
@@ -96,7 +113,7 @@ ConfigurationTable::ConfigurationTable(const char* filename, const char *wCmdNam
"Maximum number of alarms to remember inside the application."
);
mSchema[tmp->getName()] = *tmp;
free(tmp);
delete tmp;
tmp = new ConfigurationKey("Log.File","",
"",
@@ -110,7 +127,7 @@ ConfigurationTable::ConfigurationTable(const char* filename, const char *wCmdNam
"To disable again, execute \"unconfig Log.File\"."
);
mSchema[tmp->getName()] = *tmp;
free(tmp);
delete tmp;
tmp = new ConfigurationKey("Log.Level","NOTICE",
"",
@@ -128,7 +145,7 @@ ConfigurationTable::ConfigurationTable(const char* filename, const char *wCmdNam
"Default logging level when no other level is defined for a file."
);
mSchema[tmp->getName()] = *tmp;
free(tmp);
delete tmp;
// Add application specific schema
mSchema.insert(wSchema.begin(), wSchema.end());
@@ -259,8 +276,8 @@ string ConfigurationTable::getTeX(const std::string& program, const std::string&
ss << "% END AUTO-GENERATED CONTENT" << endl;
ss << endl;
string tmp = Utils::replaceAll(ss.str(), "^", "\\^");
return Utils::replaceAll(tmp, "_", "\\_");
string tmp = replaceAll(ss.str(), "^", "\\^");
return replaceAll(tmp, "_", "\\_");
}
bool ConfigurationTable::defines(const string& key)

View File

@@ -47,7 +47,7 @@ int main(int argc, char *argv[])
gConfig.setUpdateHook(purgeConfig);
char *keys[5] = {"key1", "key2", "key3", "key4", "key5"};
const char *keys[5] = {"key1", "key2", "key3", "key4", "key5"};
for (int i=0; i<5; i++) {
gConfig.set(keys[i],i);

View File

@@ -1,210 +0,0 @@
/*
* Copyright 2009 Free Software Foundation, Inc.
*
* This software is distributed under the terms of the GNU Affero Public License.
* See the COPYING file in the main directory for details.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef F16_H
#define F16_H
#include <stdint.h>
#include <ostream>
/** Round a float to the appropriate F16 value. */
inline int32_t _f16_round(float f)
{
if (f>0.0F) return (int32_t)(f+0.5F);
if (f<0.0F) return (int32_t)(f-0.5F);
return 0;
}
/** A class for F15.16 fixed point arithmetic with saturation. */
class F16 {
private:
int32_t mV;
public:
F16() {}
F16(int i) { mV = i<<16; }
F16(float f) { mV = _f16_round(f*65536.0F); }
F16(double f) { mV = _f16_round((float)f*65536.0F); }
int32_t& raw() { return mV; }
const int32_t& raw() const { return mV; }
float f() const { return mV/65536.0F; }
//operator float() const { return mV/65536.0F; }
//operator int() const { return mV>>16; }
F16 operator=(float f)
{
mV = _f16_round(f*65536.0F);
return *this;
}
F16 operator=(int i)
{
mV = i<<16;
return *this;
}
F16 operator=(const F16& other)
{
mV = other.mV;
return mV;
}
F16 operator+(const F16& other) const
{
F16 retVal;
retVal.mV = mV + other.mV;
return retVal;
}
F16& operator+=(const F16& other)
{
mV += other.mV;
return *this;
}
F16 operator-(const F16& other) const
{
F16 retVal;
retVal.mV = mV - other.mV;
return retVal;
}
F16& operator-=(const F16& other)
{
mV -= other.mV;
return *this;
}
F16 operator*(const F16& other) const
{
F16 retVal;
int64_t p = (int64_t)mV * (int64_t)other.mV;
retVal.mV = p>>16;
return retVal;
}
F16& operator*=(const F16& other)
{
int64_t p = (int64_t)mV * (int64_t)other.mV;
mV = p>>16;
return *this;
}
F16 operator*(float f) const
{
F16 retVal;
retVal.mV = mV * f;
return retVal;
}
F16& operator*=(float f)
{
mV *= f;
return *this;
}
F16 operator/(const F16& other) const
{
F16 retVal;
int64_t pV = (int64_t)mV << 16;
retVal.mV = pV / other.mV;
return retVal;
}
F16& operator/=(const F16& other)
{
int64_t pV = (int64_t)mV << 16;
mV = pV / other.mV;
return *this;
}
F16 operator/(float f) const
{
F16 retVal;
retVal.mV = mV / f;
return retVal;
}
F16& operator/=(float f)
{
mV /= f;
return *this;
}
bool operator>(const F16& other) const
{
return mV>other.mV;
}
bool operator<(const F16& other) const
{
return mV<other.mV;
}
bool operator==(const F16& other) const
{
return mV==other.mV;
}
bool operator>(float f) const
{
return (mV/65536.0F) > f;
}
bool operator<(float f) const
{
return (mV/65536.0F) < f;
}
bool operator==(float f) const
{
return (mV/65536.0F) == f;
}
};
inline std::ostream& operator<<(std::ostream& os, const F16& v)
{
os << v.f();
return os;
}
#endif

View File

@@ -1,55 +0,0 @@
/*
* Copyright 2009 Free Software Foundation, Inc.
*
*
* This software is distributed under the terms of the GNU Affero Public License.
* See the COPYING file in the main directory for details.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "F16.h"
#include <iostream>
using namespace std;
int main(int argc, char **argv)
{
F16 a = 2.5;
F16 b = 1.5;
F16 c = 2.5 * 1.5;
F16 d = c + a;
F16 e = 10;
cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << endl;
a *= 3;
b *= 0.3;
c *= e;
cout << a << ' ' << b << ' ' << c << ' ' << d << endl;
a /= 3;
b /= 0.3;
c = d * 0.05;
cout << a << ' ' << b << ' ' << c << ' ' << d << endl;
F16 f = a/d;
cout << f << ' ' << f+0.5 << endl;
}

View File

@@ -1,6 +1,5 @@
/*
* Copyright 2008, 2011 Free Software Foundation, Inc.
* Copyright 2013 Alexander Chemeris <Alexander.Chemeris@fairwaves.ru>
*
* This software is distributed under the terms of the GNU Affero Public License.
* See the COPYING file in the main directory for details.
@@ -42,7 +41,6 @@
//@{
// UNUSED in osmo-trx
/** Pointer FIFO for interthread operations. */
// (pat) The elements in the queue are type T*, and
// the Fifo class implements the underlying queue.
@@ -100,7 +98,7 @@ template <class T, class Fifo=PointerFIFO> class InterthreadQueue {
{
ScopedLock lock(mLock);
T* retVal = (T*)mQ.get();
if (retVal==NULL) {
while (retVal==NULL) {
mWriteSignal.wait(mLock);
retVal = (T*)mQ.get();
}
@@ -157,7 +155,6 @@ template <class T, class Fifo=PointerFIFO> class InterthreadQueue {
}
};
// UNUSED in osmo-trx
// (pat) Identical to above but with the threading problem fixed.
template <class T, class Fifo=PointerFIFO> class InterthreadQueue2 {
@@ -279,7 +276,6 @@ template <class T, class Fifo=PointerFIFO> class InterthreadQueue2 {
// UNUSED in osmo-trx
/** Pointer FIFO for interthread operations. */
template <class T> class InterthreadQueueWithWait {
@@ -384,7 +380,7 @@ template <class T> class InterthreadQueueWithWait {
// UNUSED in osmo-trx
/** Thread-safe map of pointers to class D, keyed by class K. */
template <class K, class D > class InterthreadMap {
@@ -648,7 +644,7 @@ template <class T, class C = std::vector<T*>, class Cmp = PointerCompare<T> > cl
// UNUSED in osmo-trx
class Semaphore {
private:

View File

@@ -1,6 +1,5 @@
/*
* Copyright 2008 Free Software Foundation, Inc.
* Copyright 2013 Alexander Chemeris <Alexander.Chemeris@fairwaves.ru>
*
*
* This software is distributed under the terms of the GNU Affero Public License.
@@ -28,91 +27,66 @@
#include "Threads.h"
#include "Interthread.h"
#include "Configuration.h"
#include <iostream>
using namespace std;
ConfigurationTable gConfig;
InterthreadQueue<int> gQ;
InterthreadMap<int,int> gMap;
class QueueWriter : public Thread
void* qWriter(void*)
{
public:
QueueWriter() : Thread("QueueWriter") {}
protected:
virtual void runThread()
{
int *p;
for (int i=0; i<20; i++) {
p = new int;
*p = i;
COUT("queue write " << *p);
gQ.write(p);
msleep(1);
}
int *p;
for (int i=0; i<20; i++) {
p = new int;
*p = -1;
*p = i;
COUT("queue write " << *p);
gQ.write(p);
if (random()%2) sleep(1);
}
};
p = new int;
*p = -1;
gQ.write(p);
return NULL;
}
class QueueReader : public Thread
void* qReader(void*)
{
public:
QueueReader() : Thread("QueueReader") {}
protected:
virtual void runThread()
{
bool done = false;
while (!done) {
int *p = gQ.read();
COUT("queue read " << *p);
if (*p<0) done=true;
delete p;
}
bool done = false;
while (!done) {
int *p = gQ.read();
COUT("queue read " << *p);
if (*p<0) done=true;
delete p;
}
};
return NULL;
}
class MapWriter : public Thread
void* mapWriter(void*)
{
public:
MapWriter() : Thread("MapWriter") {}
protected:
virtual void runThread()
{
int *p;
for (int i=0; i<20; i++) {
p = new int;
*p = i;
COUT("map write " << *p);
gMap.write(i,p);
msleep(1);
}
int *p;
for (int i=0; i<20; i++) {
p = new int;
*p = i;
COUT("map write " << *p);
gMap.write(i,p);
if (random()%2) sleep(1);
}
};
return NULL;
}
class MapReader : public Thread
void* mapReader(void*)
{
public:
MapReader() : Thread("MapReader") {}
protected:
virtual void runThread()
{
for (int i=0; i<20; i++) {
int *p = gMap.read(i);
COUT("map read " << *p);
// InterthreadMap will delete the pointers
}
for (int i=0; i<20; i++) {
int *p = gMap.read(i);
COUT("map read " << *p);
// InterthreadMap will delete the pointers
// delete p;
}
};
return NULL;
}
@@ -121,25 +95,20 @@ protected:
int main(int argc, char *argv[])
{
COUT("TEST 1: InterthreadQueue")
QueueReader qReaderThread;
QueueWriter qWriterThread;
qReaderThread.startThread();
qWriterThread.startThread();
// stopThread() will wait for a thread to stop for 5 seconds, which
// is more than enough for this test to finish.
qReaderThread.stopThread();
qWriterThread.stopThread();
Thread qReaderThread;
qReaderThread.start(qReader,NULL);
Thread mapReaderThread;
mapReaderThread.start(mapReader,NULL);
COUT("TEST 2: InterthreadMap")
MapReader mapReaderThread;
mapReaderThread.startThread();
MapWriter mapWriterThread;
mapWriterThread.startThread();
// stopThread() will wait for a thread to stop for 5 seconds, which
// is more than enough for this test to finish.
mapReaderThread.stopThread();
mapWriterThread.stopThread();
Thread qWriterThread;
qWriterThread.start(qWriter,NULL);
Thread mapWriterThread;
mapWriterThread.start(mapWriter,NULL);
qReaderThread.join();
qWriterThread.join();
mapReaderThread.join();
mapWriterThread.join();
}

View File

@@ -30,6 +30,7 @@
#include <fstream>
#include <string>
#include <stdarg.h>
#include <sys/time.h> // For gettimeofday
#include "Configuration.h"
#include "Logger.h"
@@ -38,6 +39,14 @@
using namespace std;
// Switches to enable/disable logging targets
// MUST BE DEFINED BEFORE gConfig FOR gLogEarly() TO WORK CORRECTLY
bool gLogToConsole = true;
bool gLogToSyslog = false;
FILE *gLogToFile = NULL;
Mutex gLogToLock;
// Reference to a global config table, used all over the system.
extern ConfigurationTable gConfig;
@@ -67,9 +76,6 @@ const char *levelNames[] = {
"EMERG", "ALERT", "CRIT", "ERR", "WARNING", "NOTICE", "INFO", "DEBUG"
};
int numLevels = 8;
bool gLogToConsole = 0;
FILE *gLogToFile = NULL;
Mutex gLogToLock;
int levelStringToInt(const string& name)
@@ -106,6 +112,31 @@ int lookupLevel(const string& key)
return level;
}
static std::string format(const char *fmt, ...)
{
va_list ap;
char buf[300];
va_start(ap,fmt);
int n = vsnprintf(buf,300,fmt,ap);
va_end(ap);
if (n >= (300-4)) { strcpy(&buf[(300-4)],"..."); }
return std::string(buf);
}
const std::string timestr()
{
struct timeval tv;
struct tm tm;
gettimeofday(&tv,NULL);
localtime_r(&tv.tv_sec,&tm);
unsigned tenths = tv.tv_usec / 100000; // Rounding down is ok.
return format(" %02d:%02d:%02d.%1d",tm.tm_hour,tm.tm_min,tm.tm_sec,tenths);
}
std::ostream& operator<<(std::ostream& os, std::ostringstream& ss)
{
return os << ss.str();
}
int getLoggingLevel(const char* filename)
{
@@ -192,18 +223,20 @@ Log::~Log()
if (mDummyInit) return;
// Anything at or above LOG_CRIT is an "alarm".
// Save alarms in the local list and echo them to stderr.
if (mPriority <= LOG_CRIT) {
if (mPriority <= LOG_ERR) {
if (sLoggerInited) addAlarm(mStream.str().c_str());
cerr << mStream.str() << endl;
}
// Current logging level was already checked by the macro.
// So just log.
syslog(mPriority, "%s", mStream.str().c_str());
// pat added for easy debugging.
// Current logging level was already checked by the macro. So just log.
// Log to syslog
if (gLogToSyslog) {
syslog(mPriority, "%s", mStream.str().c_str());
}
// Log to file and console
if (gLogToConsole||gLogToFile) {
int mlen = mStream.str().size();
int neednl = (mlen==0 || mStream.str()[mlen-1] != '\n');
gLogToLock.lock();
ScopedLock lock(gLogToLock);
if (gLogToConsole) {
// The COUT() macro prevents messages from stomping each other but adds uninteresting thread numbers,
// so just use std::cout.
@@ -215,7 +248,6 @@ Log::~Log()
if (neednl) {fputc('\n',gLogToFile);}
fflush(gLogToFile);
}
gLogToLock.unlock();
}
}
@@ -243,10 +275,9 @@ void gLogInit(const char* name, const char* level, int facility)
gConfig.set("Log.Level",level);
}
// Pat added, tired of the syslog facility.
// Both the transceiver and OpenBTS use this same facility, but only OpenBTS/OpenNodeB may use this log file:
string str = gConfig.getStr("Log.File");
if (gLogToFile==0 && str.length() && 0==strncmp(gCmdName,"Open",4)) {
if (gLogToFile==NULL && str.length() && 0==strncmp(gCmdName,"Open",4)) {
const char *fn = str.c_str();
if (fn && *fn && strlen(fn)>3) { // strlen because a garbage char is getting in sometimes.
gLogToFile = fopen(fn,"w"); // New log file each time we start.
@@ -268,9 +299,32 @@ void gLogInit(const char* name, const char* level, int facility)
void gLogEarly(int level, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
vsyslog(level | LOG_USER, fmt, args);
if (gLogToSyslog) {
va_list args_copy;
va_copy(args_copy, args);
vsyslog(level | LOG_USER, fmt, args_copy);
va_end(args_copy);
}
if (gLogToConsole) {
va_list args_copy;
va_copy(args_copy, args);
vprintf(fmt, args_copy);
printf("\n");
va_end(args_copy);
}
if (gLogToFile) {
va_list args_copy;
va_copy(args_copy, args);
vfprintf(gLogToFile, fmt, args_copy);
fprintf(gLogToFile, "\n");
va_end(args_copy);
}
va_end(args);
}

View File

@@ -83,7 +83,6 @@
#include "Threads.h" // must be after defines above, if these files are to be allowed to use LOG()
#include "Utils.h"
/**
A C++ stream-based thread-safe logger.
@@ -116,12 +115,15 @@ class Log {
std::ostringstream& get();
};
extern bool gLogToConsole; // Pat added for easy debugging.
extern bool gLogToConsole; // Output log messages to stdout
extern bool gLogToSyslog; // Output log messages to syslog
std::list<std::string> gGetLoggerAlarms(); ///< Get a copy of the recent alarm list.
const std::string timestr(); // A timestamp to print in messages.
std::ostream& operator<<(std::ostream& os, std::ostringstream& ss);
/**@ Global control and initialization of the logging system. */
//@{

View File

@@ -36,82 +36,62 @@ libcommon_la_SOURCES = \
Sockets.cpp \
Threads.cpp \
Timeval.cpp \
Reporting.cpp \
Logger.cpp \
Configuration.cpp \
sqlite3util.cpp \
URLEncode.cpp \
Utils.cpp
sqlite3util.cpp
noinst_PROGRAMS = \
ThreadsTest \
BitVectorTest \
PRBSTest \
InterthreadTest \
SocketsTest \
TimevalTest \
RegexpTest \
VectorTest \
ConfigurationTest \
LogTest \
URLEncodeTest \
F16Test
LogTest
# ReportingTest
noinst_HEADERS = \
BitVector.h \
PRBS.h \
Interthread.h \
LinkedLists.h \
Sockets.h \
Threads.h \
Timeval.h \
Regexp.h \
Vector.h \
Configuration.h \
Reporting.h \
F16.h \
URLEncode.h \
Utils.h \
Logger.h \
sqlite3util.h
URLEncodeTest_SOURCES = URLEncodeTest.cpp
URLEncodeTest_LDADD = libcommon.la
BitVectorTest_SOURCES = BitVectorTest.cpp
BitVectorTest_LDADD = libcommon.la $(SQLITE_LA)
BitVectorTest_LDADD = libcommon.la $(SQLITE3_LIBS)
ThreadsTest_SOURCES = ThreadsTest.cpp
ThreadsTest_LDADD = libcommon.la $(SQLITE_LA)
ThreadsTest_LDFLAGS = -lpthread
PRBSTest_SOURCES = PRBSTest.cpp
InterthreadTest_SOURCES = InterthreadTest.cpp
InterthreadTest_LDADD = libcommon.la $(SQLITE_LA)
InterthreadTest_LDADD = libcommon.la
InterthreadTest_LDFLAGS = -lpthread
SocketsTest_SOURCES = SocketsTest.cpp
SocketsTest_LDADD = libcommon.la $(SQLITE_LA)
SocketsTest_LDADD = libcommon.la
SocketsTest_LDFLAGS = -lpthread
TimevalTest_SOURCES = TimevalTest.cpp
TimevalTest_LDADD = libcommon.la
VectorTest_SOURCES = VectorTest.cpp
VectorTest_LDADD = libcommon.la $(SQLITE_LA)
RegexpTest_SOURCES = RegexpTest.cpp
RegexpTest_LDADD = libcommon.la
VectorTest_LDADD = libcommon.la $(SQLITE3_LIBS)
ConfigurationTest_SOURCES = ConfigurationTest.cpp
ConfigurationTest_LDADD = libcommon.la $(SQLITE_LA)
ConfigurationTest_LDADD = libcommon.la $(SQLITE3_LIBS)
# ReportingTest_SOURCES = ReportingTest.cpp
# ReportingTest_LDADD = libcommon.la $(SQLITE_LA)
LogTest_SOURCES = LogTest.cpp
LogTest_LDADD = libcommon.la $(SQLITE_LA)
F16Test_SOURCES = F16Test.cpp
LogTest_LDADD = libcommon.la $(SQLITE3_LIBS)
MOSTLYCLEANFILES += testSource testDestination

View File

@@ -1,111 +0,0 @@
/*
* Copyright 2011 Range Networks, Inc.
* All Rights Reserved.
*
* This software is distributed under multiple licenses;
* see the COPYING file in the main directory for licensing
* information for this specific distribuion.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef _MEMORYLEAK_
#define _MEMORYLEAK_ 1
#include <map>
#include "ScalarTypes.h"
#include "Logger.h"
namespace Utils {
struct MemStats {
// Enumerates the classes that are checked.
// Redundancies are ok, for example, we check BitVector and also
// several descendants of BitVector.
enum MemoryNames {
mZeroIsUnused,
mVector,
mVectorData,
mBitVector,
mByteVector,
mByteVectorData,
mRLCRawBlock,
mRLCUplinkDataBlock,
mRLCMessage,
mRLCMsgPacketDownlinkDummyControlBlock, // Redundant with RLCMessage
mTBF,
mLlcEngine,
mSgsnDownlinkMsg,
mRachInfo,
mPdpPdu,
mFECDispatchInfo,
mL3Frame,
msignalVector,
mSoftVector,
mScramblingCode,
mURlcDownSdu,
mURlcPdu,
// Must be last:
mMax,
};
int mMemTotal[mMax]; // In elements, not bytes.
int mMemNow[mMax];
const char *mMemName[mMax];
MemStats();
void memChkNew(MemoryNames memIndex, const char *id);
void memChkDel(MemoryNames memIndex, const char *id);
void text(std::ostream &os);
// We would prefer to use an unordered_map, but that requires special compile switches.
// What a super great language.
typedef std::map<std::string,Int_z> MemMapType;
MemMapType mMemMap;
};
extern struct MemStats gMemStats;
extern int gMemLeakDebug;
// This is a memory leak detector.
// Use by putting RN_MEMCHKNEW and RN_MEMCHKDEL in class constructors/destructors,
// or use the DEFINE_MEMORY_LEAK_DETECTOR class and add the defined class
// as an ancestor to the class to be memory leak checked.
struct MemLabel {
std::string mccKey;
virtual ~MemLabel() {
Int_z &tmp = Utils::gMemStats.mMemMap[mccKey]; tmp = tmp - 1;
}
};
#if RN_DISABLE_MEMORY_LEAK_TEST
#define RN_MEMCHKNEW(type)
#define RN_MEMCHKDEL(type)
#define RN_MEMLOG(type,ptr)
#define DEFINE_MEMORY_LEAK_DETECTOR_CLASS(subClass,checkerClass) \
struct checkerClass {};
#else
#define RN_MEMCHKNEW(type) { Utils::gMemStats.memChkNew(Utils::MemStats::m##type,#type); }
#define RN_MEMCHKDEL(type) { Utils::gMemStats.memChkDel(Utils::MemStats::m##type,#type); }
#define RN_MEMLOG(type,ptr) { \
static std::string key = format("%s_%s:%d",#type,__FILE__,__LINE__); \
(ptr)->/* MemCheck##type:: */ mccKey = key; \
Utils::gMemStats.mMemMap[key]++; \
}
// TODO: The above assumes that checkclass is MemCheck ## subClass
#define DEFINE_MEMORY_LEAK_DETECTOR_CLASS(subClass,checkerClass) \
struct checkerClass : public virtual Utils::MemLabel { \
checkerClass() { RN_MEMCHKNEW(subClass); } \
virtual ~checkerClass() { \
RN_MEMCHKDEL(subClass); \
} \
};
#endif
} // namespace Utils
#endif

110
CommonLibs/PRBS.h Normal file
View File

@@ -0,0 +1,110 @@
/*
* Copyright (C) 2017 Alexander Chemeris <Alexander.Chemeris@fairwaves.co>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef PRBS_H
#define PRBS_H
#include <stdint.h>
#include <assert.h>
/** Pseudo-random binary sequence (PRBS) generator (a Galois LFSR implementation). */
class PRBS {
public:
PRBS(unsigned wLen, uint64_t wCoeff, uint64_t wState = 0x01)
: mCoeff(wCoeff), mStartState(wState), mState(wState), mLen(wLen)
{ assert(wLen<=64); }
/**@name Accessors */
//@{
uint64_t coeff() const { return mCoeff; }
uint64_t state() const { return mState; }
void state(uint64_t state) { mState = state & mask(); }
unsigned size() const { return mLen; }
//@}
/**
Calculate one bit of a PRBS
*/
unsigned generateBit()
{
const unsigned result = mState & 0x01;
processBit(result);
return result;
}
/**
Update the generator state by one bit.
If you want to synchronize your PRBS to a known state, call this function
size() times passing your PRBS to it bit by bit.
*/
void processBit(unsigned inBit)
{
mState >>= 1;
if (inBit) mState ^= mCoeff;
}
/** Return true when PRBS is wrapping through initial state */
bool isFinished() const { return mStartState == mState; }
protected:
uint64_t mCoeff; ///< polynomial coefficients. LSB is zero exponent.
uint64_t mStartState; ///< initial shift register state.
uint64_t mState; ///< shift register state.
unsigned mLen; ///< number of bits used in shift register
/** Return mask for the state register */
uint64_t mask() const { return (mLen==64)?0xFFFFFFFFFFFFFFFFUL:((1<<mLen)-1); }
};
/**
A standard 9-bit based pseudorandom binary sequence (PRBS) generator.
Polynomial: x^9 + x^5 + 1
*/
class PRBS9 : public PRBS {
public:
PRBS9(uint64_t wState = 0x01)
: PRBS(9, 0x0110, wState)
{}
};
/**
A standard 15-bit based pseudorandom binary sequence (PRBS) generator.
Polynomial: x^15 + x^14 + 1
*/
class PRBS15 : public PRBS {
public:
PRBS15(uint64_t wState = 0x01)
: PRBS(15, 0x6000, wState)
{}
};
/**
A standard 64-bit based pseudorandom binary sequence (PRBS) generator.
Polynomial: x^64 + x^63 + x^61 + x^60 + 1
*/
class PRBS64 : public PRBS {
public:
PRBS64(uint64_t wState = 0x01)
: PRBS(64, 0xD800000000000000ULL, wState)
{}
};
#endif // PRBS_H

42
CommonLibs/PRBSTest.cpp Normal file
View File

@@ -0,0 +1,42 @@
/*
* Copyright (C) 2017 Alexander Chemeris <Alexander.Chemeris@fairwaves.co>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "PRBS.h"
#include <iostream>
#include <cstdlib>
#include <assert.h>
void testPrbs(PRBS &prbs, uint64_t expectedPeriod)
{
uint64_t period = 0;
do {
std::cout << prbs.generateBit();
period++;
} while (!prbs.isFinished());
std::cout << std::endl;
std::cout << "Period: " << period << std::endl;
assert(period == expectedPeriod);
}
int main(int argc, char *argv[])
{
PRBS9 prbs9(0x01);
testPrbs(prbs9, (1<<9)-1);
PRBS15 prbs15(0x01);
testPrbs(prbs15, (1<<15)-1);
}

View File

@@ -1,64 +0,0 @@
/*
* Copyright 2008 Free Software Foundation, Inc.
*
* This software is distributed under the terms of the GNU Affero Public License.
* See the COPYING file in the main directory for details.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef REGEXPW_H
#define REGEXPW_H
#include <regex.h>
#include <iostream>
#include <stdlib.h>
class Regexp {
private:
regex_t mRegex;
public:
Regexp(const char* regexp, int flags=REG_EXTENDED)
{
int result = regcomp(&mRegex, regexp, flags);
if (result) {
char msg[256];
regerror(result,&mRegex,msg,255);
std::cerr << "Regexp compilation of " << regexp << " failed: " << msg << std::endl;
abort();
}
}
~Regexp()
{ regfree(&mRegex); }
bool match(const char *text, int flags=0) const
{ return regexec(&mRegex, text, 0, NULL, flags)==0; }
};
#endif

View File

@@ -1,48 +0,0 @@
/*
* Copyright 2008 Free Software Foundation, Inc.
*
*
* This software is distributed under the terms of the GNU Affero Public License.
* See the COPYING file in the main directory for details.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Regexp.h"
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
Regexp email("^[[:graph:]]+@[[:graph:]]+ ");
Regexp simple("^dburgess@");
const char text1[] = "dburgess@jcis.net test message";
const char text2[] = "no address text message";
cout << email.match(text1) << " " << text1 << endl;
cout << email.match(text2) << " " << text2 << endl;
cout << simple.match(text1) << " " << text1 << endl;
cout << simple.match(text2) << " " << text2 << endl;
}

View File

@@ -1,145 +0,0 @@
/**@file Module for performance-reporting mechanisms. */
/*
* Copyright 2012 Range Networks, Inc.
*
* This software is distributed under the terms of the GNU Affero Public License.
* See the COPYING file in the main directory for details.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Reporting.h"
#include "Logger.h"
#include <stdio.h>
#include <string.h>
static const char* createReportingTable = {
"CREATE TABLE IF NOT EXISTS REPORTING ("
"NAME TEXT UNIQUE NOT NULL, "
"VALUE INTEGER DEFAULT 0, "
"CLEAREDTIME INTEGER NOT NULL, "
"UPDATETIME INTEGER DEFAULT 0 "
")"
};
ReportingTable::ReportingTable(const char* filename)
{
gLogEarly(LOG_INFO | mFacility, "opening reporting table from path %s", filename);
// Connect to the database.
int rc = sqlite3_open(filename,&mDB);
if (rc) {
gLogEarly(LOG_EMERG | mFacility, "cannot open reporting database at %s, error message: %s", filename, sqlite3_errmsg(mDB));
sqlite3_close(mDB);
mDB = NULL;
return;
}
// Create the table, if needed.
if (!sqlite3_command(mDB,createReportingTable)) {
gLogEarly(LOG_EMERG | mFacility, "cannot create reporting table in database at %s, error message: %s", filename, sqlite3_errmsg(mDB));
}
}
bool ReportingTable::create(const char* paramName)
{
char cmd[200];
sprintf(cmd,"INSERT OR IGNORE INTO REPORTING (NAME,CLEAREDTIME) VALUES (\"%s\",%ld)", paramName, time(NULL));
if (!sqlite3_command(mDB,cmd)) {
gLogEarly(LOG_CRIT|mFacility, "cannot create reporting parameter %s, error message: %s", paramName, sqlite3_errmsg(mDB));
return false;
}
return true;
}
bool ReportingTable::incr(const char* paramName)
{
char cmd[200];
sprintf(cmd,"UPDATE REPORTING SET VALUE=VALUE+1, UPDATETIME=%ld WHERE NAME=\"%s\"", time(NULL), paramName);
if (!sqlite3_command(mDB,cmd)) {
gLogEarly(LOG_CRIT|mFacility, "cannot increment reporting parameter %s, error message: %s", paramName, sqlite3_errmsg(mDB));
return false;
}
return true;
}
bool ReportingTable::max(const char* paramName, unsigned newVal)
{
char cmd[200];
sprintf(cmd,"UPDATE REPORTING SET VALUE=MAX(VALUE,%u), UPDATETIME=%ld WHERE NAME=\"%s\"", newVal, time(NULL), paramName);
if (!sqlite3_command(mDB,cmd)) {
gLogEarly(LOG_CRIT|mFacility, "cannot maximize reporting parameter %s, error message: %s", paramName, sqlite3_errmsg(mDB));
return false;
}
return true;
}
bool ReportingTable::clear(const char* paramName)
{
char cmd[200];
sprintf(cmd,"UPDATE REPORTING SET VALUE=0, UPDATETIME=0, CLEAREDTIME=%ld WHERE NAME=\"%s\"", time(NULL), paramName);
if (!sqlite3_command(mDB,cmd)) {
gLogEarly(LOG_CRIT|mFacility, "cannot clear reporting parameter %s, error message: %s", paramName, sqlite3_errmsg(mDB));
return false;
}
return true;
}
bool ReportingTable::create(const char* baseName, unsigned minIndex, unsigned maxIndex)
{
size_t sz = strlen(baseName);
for (unsigned i = minIndex; i<=maxIndex; i++) {
char name[sz+10];
sprintf(name,"%s.%u",baseName,i);
if (!create(name)) return false;
}
return true;
}
bool ReportingTable::incr(const char* baseName, unsigned index)
{
char name[strlen(baseName)+10];
sprintf(name,"%s.%u",baseName,index);
return incr(name);
}
bool ReportingTable::max(const char* baseName, unsigned index, unsigned newVal)
{
char name[strlen(baseName)+10];
sprintf(name,"%s.%u",baseName,index);
return max(name,newVal);
}
bool ReportingTable::clear(const char* baseName, unsigned index)
{
char name[strlen(baseName)+10];
sprintf(name,"%s.%u",baseName,index);
return clear(name);
}

View File

@@ -1,86 +0,0 @@
/**@file Module for performance-reporting mechanisms. */
/*
* Copyright 2012 Range Networks, Inc.
*
* This software is distributed under the terms of the GNU Affero Public License.
* See the COPYING file in the main directory for details.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef REPORTING_H
#define REPORTING_H
#include <sqlite3util.h>
#include <ostream>
/**
Collect performance statistics into a database.
Parameters are counters or max/min trackers, all integer.
*/
class ReportingTable {
private:
sqlite3* mDB; ///< database connection
int mFacility; ///< rsyslogd facility
public:
/**
Open the database connection;
create the table if it does not exist yet.
*/
ReportingTable(const char* filename);
/** Create a new parameter. */
bool create(const char* paramName);
/** Create an indexed parameter set. */
bool create(const char* baseBame, unsigned minIndex, unsigned maxIndex);
/** Increment a counter. */
bool incr(const char* paramName);
/** Increment an indexed counter. */
bool incr(const char* baseName, unsigned index);
/** Take a max of a parameter. */
bool max(const char* paramName, unsigned newVal);
/** Take a max of an indexed parameter. */
bool max(const char* paramName, unsigned index, unsigned newVal);
/** Clear a value. */
bool clear(const char* paramName);
/** Clear an indexed value. */
bool clear(const char* paramName, unsigned index);
/** Dump the database to a stream. */
void dump(std::ostream&) const;
};
#endif
// vim: ts=4 sw=4

View File

@@ -1,136 +0,0 @@
/*
* Copyright 2011 Range Networks, Inc.
* All Rights Reserved.
*
* This software is distributed under multiple licenses;
* see the COPYING file in the main directory for licensing
* information for this specific distribuion.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef SCALARTYPES_H
#define SCALARTYPES_H
#include <iostream> // For size_t
#include <stdint.h>
//#include "GSMCommon.h" // Was included for Z100Timer
// We dont bother to define *= /= etc.; you'll have to convert: a*=b; to: a=a*b;
#define _INITIALIZED_SCALAR_BASE_FUNCS(Classname,Basetype,Init) \
Classname() : value(Init) {} \
Classname(Basetype wvalue) { value = wvalue; } /* Can set from basetype. */ \
operator Basetype(void) const { return value; } /* Converts from basetype. */ \
Basetype operator=(Basetype wvalue) { return value = wvalue; } \
Basetype* operator&() { return &value; }
#define _INITIALIZED_SCALAR_ARITH_FUNCS(Basetype) \
Basetype operator++() { return ++value; } \
Basetype operator++(int) { return value++; } \
Basetype operator--() { return --value; } \
Basetype operator--(int) { return value--; } \
Basetype operator+=(Basetype wvalue) { return value = value + wvalue; } \
Basetype operator-=(Basetype wvalue) { return value = value - wvalue; }
#define _INITIALIZED_SCALAR_FUNCS(Classname,Basetype,Init) \
_INITIALIZED_SCALAR_BASE_FUNCS(Classname,Basetype,Init) \
_INITIALIZED_SCALAR_ARITH_FUNCS(Basetype)
#define _DECLARE_SCALAR_TYPE(Classname_i,Classname_z,Basetype) \
template <Basetype Init> \
struct Classname_i { \
Basetype value; \
_INITIALIZED_SCALAR_FUNCS(Classname_i,Basetype,Init) \
}; \
typedef Classname_i<0> Classname_z;
// Usage:
// Where 'classname' is one of the types listed below, then:
// classname_z specifies a zero initialized type;
// classname_i<value> initializes the type to the specified value.
// We also define Float_z.
_DECLARE_SCALAR_TYPE(Int_i, Int_z, int)
_DECLARE_SCALAR_TYPE(Char_i, Char_z, signed char)
_DECLARE_SCALAR_TYPE(Int16_i, Int16_z, int16_t)
_DECLARE_SCALAR_TYPE(Int32_i, Int32_z, int32_t)
_DECLARE_SCALAR_TYPE(UInt_i, UInt_z, unsigned)
_DECLARE_SCALAR_TYPE(UChar_i, UChar_z, unsigned char)
_DECLARE_SCALAR_TYPE(UInt16_i, UInt16_z, uint16_t)
_DECLARE_SCALAR_TYPE(UInt32_i, UInt32_z, uint32_t)
_DECLARE_SCALAR_TYPE(Size_t_i, Size_t_z, size_t)
// Bool is special because it cannot accept some arithmetic funcs
//_DECLARE_SCALAR_TYPE(Bool_i, Bool_z, bool)
template <bool Init>
struct Bool_i {
bool value;
_INITIALIZED_SCALAR_BASE_FUNCS(Bool_i,bool,Init)
};
typedef Bool_i<0> Bool_z;
// float is special, because C++ does not permit the template initalization:
struct Float_z {
float value;
_INITIALIZED_SCALAR_FUNCS(Float_z,float,0)
};
struct Double_z {
double value;
_INITIALIZED_SCALAR_FUNCS(Double_z,double,0)
};
class ItemWithValueAndWidth {
public:
virtual unsigned getValue() const = 0;
virtual unsigned getWidth() const = 0;
};
// A Range Networks Field with a specified width.
// See RLCMessages.h for examples.
template <int Width=32, unsigned Init=0>
class Field_i : public ItemWithValueAndWidth
{
public:
unsigned value;
_INITIALIZED_SCALAR_FUNCS(Field_i,unsigned,Init)
unsigned getWidth() const { return Width; }
unsigned getValue() const { return value; }
};
// Synonym for Field_i, but no way to do it.
template <int Width, unsigned Init=0>
class Field_z : public ItemWithValueAndWidth
{
public:
unsigned value;
_INITIALIZED_SCALAR_FUNCS(Field_z,unsigned,Init)
unsigned getWidth() const { return Width; }
unsigned getValue() const { return value; }
};
// This is an uninitialized field.
template <int Width=32, unsigned Init=0>
class Field : public ItemWithValueAndWidth
{
public:
unsigned value;
_INITIALIZED_SCALAR_FUNCS(Field,unsigned,Init)
unsigned getWidth() const { return Width; }
unsigned getValue() const { return value; }
};
// A Z100Timer with an initial value specified.
//template <int Init>
//class Z100Timer_i : public GSM::Z100Timer {
// public:
// Z100Timer_i() : GSM::Z100Timer(Init) {}
//};
#endif

View File

@@ -1,6 +1,5 @@
/*
* Copyright 2008, 2010 Free Software Foundation, Inc.
* Copyright 2013 Alexander Chemeris <Alexander.Chemeris@fairwaves.ru>
*
*
* This software is distributed under the terms of the GNU Affero Public License.
@@ -130,11 +129,6 @@ void DatagramSocket::close()
::close(mSocketFD);
}
void DatagramSocket::shutdown()
{
::shutdown(mSocketFD, SHUT_RDWR);
}
DatagramSocket::~DatagramSocket()
{
@@ -193,24 +187,20 @@ int DatagramSocket::send(const struct sockaddr* dest, const char * message)
return send(dest,message,length);
}
int DatagramSocket::read(char* buffer)
int DatagramSocket::read(char* buffer, size_t length)
{
socklen_t temp_len = sizeof(mSource);
int length = recvfrom(mSocketFD, (void*)buffer, MAX_UDP_LENGTH, 0,
(struct sockaddr*)&mSource,&temp_len);
if ((length==-1) && (errno!=EAGAIN)) {
socklen_t addr_len = sizeof(mSource);
int rd_length = recvfrom(mSocketFD, (void *) buffer, length, 0,
(struct sockaddr*) &mSource, &addr_len);
if ((rd_length==-1) && (errno!=EAGAIN)) {
perror("DatagramSocket::read() failed");
throw SocketError();
}
return length;
return rd_length;
}
int DatagramSocket::read(char* buffer, unsigned timeout)
int DatagramSocket::read(char* buffer, size_t length, unsigned timeout)
{
fd_set fds;
FD_ZERO(&fds);
@@ -224,7 +214,7 @@ int DatagramSocket::read(char* buffer, unsigned timeout)
throw SocketError();
}
if (sel==0) return -1;
if (FD_ISSET(mSocketFD,&fds)) return read(buffer);
if (FD_ISSET(mSocketFD,&fds)) return read(buffer, length);
return -1;
}
@@ -275,7 +265,7 @@ void UDPSocket::open(unsigned short localPort)
size_t length = sizeof(address);
bzero(&address,length);
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
address.sin_port = htons(localPort);
if (bind(mSocketFD,(struct sockaddr*)&address,length)<0) {
perror("bind() failed");

View File

@@ -1,6 +1,5 @@
/*
* Copyright 2008, 2010 Free Software Foundation, Inc.
* Copyright 2013 Alexander Chemeris <Alexander.Chemeris@fairwaves.ru>
*
* This software is distributed under the terms of the GNU Affero Public License.
* See the COPYING file in the main directory for details.
@@ -109,7 +108,7 @@ public:
@param buffer A char[MAX_UDP_LENGTH] procured by the caller.
@return The number of bytes received or -1 on non-blocking pass.
*/
int read(char* buffer);
int read(char* buffer, size_t length);
/**
Receive a packet with a timeout.
@@ -117,7 +116,7 @@ public:
@param maximum wait time in milliseconds
@return The number of bytes received or -1 on timeout.
*/
int read(char* buffer, unsigned timeout);
int read(char* buffer, size_t length, unsigned timeout);
/** Send a packet to a given destination, other than the default. */
@@ -135,11 +134,6 @@ public:
/** Close the socket. */
void close();
/** Shutdown the socket without destroying the descriptor
* Use this to interrupt blocking read()
*/
void shutdown();
};

View File

@@ -1,6 +1,5 @@
/*
* Copyright 2008 Free Software Foundation, Inc.
* Copyright 2013 Alexander Chemeris <Alexander.Chemeris@fairwaves.ru>
*
*
* This software is distributed under the terms of the GNU Affero Public License.
@@ -29,73 +28,59 @@
#include "Sockets.h"
#include "Threads.h"
#include "Configuration.h"
#include "Timeval.h"
#include <stdio.h>
#include <stdlib.h>
ConfigurationTable gConfig;
static const int gNumToSend = 10;
class TestReaderIP : public Thread
void *testReaderIP(void *)
{
public:
TestReaderIP() : Thread("TestReaderIP") {}
protected:
virtual void runThread()
{
UDPSocket readSocket(5934, "localhost", 5061);
readSocket.nonblocking();
int rc = 0;
while (rc<gNumToSend) {
char buf[MAX_UDP_LENGTH];
int count = readSocket.read(buf);
if (count>0) {
COUT("IP read: " << buf);
rc++;
} else {
COUT("IP sleeping...");
sleep(2);
}
UDPSocket readSocket(5934, "localhost", 5061);
readSocket.nonblocking();
int rc = 0;
while (rc<gNumToSend) {
char buf[MAX_UDP_LENGTH];
int count = readSocket.read(buf, MAX_UDP_LENGTH);
if (count>0) {
COUT("read: " << buf);
rc++;
} else {
sleep(2);
}
}
};
return NULL;
}
class TestReaderUnix : public Thread
void *testReaderUnix(void *)
{
public:
TestReaderUnix() : Thread("TestReaderUnix") {}
protected:
virtual void runThread()
{
UDDSocket readSocket("testDestination");
readSocket.nonblocking();
int rc = 0;
while (rc<gNumToSend) {
char buf[MAX_UDP_LENGTH];
int count = readSocket.read(buf);
if (count>0) {
COUT("UNIX read: " << buf);
rc++;
} else {
COUT("UNIX sleeping...");
sleep(2);
}
UDDSocket readSocket("testDestination");
readSocket.nonblocking();
int rc = 0;
while (rc<gNumToSend) {
char buf[MAX_UDP_LENGTH];
int count = readSocket.read(buf, MAX_UDP_LENGTH);
if (count>0) {
COUT("read: " << buf);
rc++;
} else {
sleep(2);
}
}
};
return NULL;
}
int main(int argc, char * argv[] )
{
TestReaderIP readerThreadIP;
TestReaderUnix readerThreadUnix;
readerThreadIP.startThread();
readerThreadUnix.startThread();
Thread readerThreadIP;
readerThreadIP.start(testReaderIP,NULL);
Thread readerThreadUnix;
readerThreadUnix.start(testReaderUnix,NULL);
UDPSocket socket1(5061, "127.0.0.1",5934);
UDDSocket socket1U("testSource","testDestination");
@@ -107,10 +92,12 @@ int main(int argc, char * argv[] )
for (int i=0; i<gNumToSend; i++) {
socket1.write("Hello IP land");
socket1U.write("Hello Unix domain");
msleep(1);
socket1U.write("Hello Unix domain");
sleep(1);
}
readerThreadIP.join();
readerThreadUnix.join();
}
// vim: ts=4 sw=4

View File

@@ -1,6 +1,5 @@
/*
* Copyright 2008 Free Software Foundation, Inc.
* Copyright 2013 Alexander Chemeris <Alexander.Chemeris@fairwaves.ru>
*
*
* This software is distributed under the terms of the GNU Affero Public License.
@@ -30,26 +29,11 @@
#include "Threads.h"
#include "Timeval.h"
#include "Logger.h"
#include <pthread.h>
#include <sys/types.h>
#include <errno.h> // for ETIMEDOUT
#include <sys/syscall.h> // for SYS_gettid
#include <sys/prctl.h> // Linux specific, for prctl(PR_SET_NAME)
// Make sure we get MCL_CURRENT and MCL_FUTURE (for mlockall) on OS X 10.3
#define _P1003_1B_VISIBLE
#include <sys/mman.h>
#undef _P1003_1B_VISIBLE
using namespace std;
#define POSIX_OK 0
#define POSIX_NO_WAIT 0
#define POSIX_WAIT_FOREVER (-1)
static inline int gettid() {return syscall(SYS_gettid);}
Mutex gStreamLock; ///< Global lock to control access to cout and cerr.
@@ -111,235 +95,27 @@ Mutex::~Mutex()
/** Block for the signal up to the cancellation timeout. */
int Signal::wait(Mutex& wMutex, unsigned timeout) const
void Signal::wait(Mutex& wMutex, unsigned timeout) const
{
Timeval then(timeout);
struct timespec waitTime = then.timespec();
return pthread_cond_timedwait(&mSignal,&wMutex.mMutex,&waitTime);
pthread_cond_timedwait(&mSignal,&wMutex.mMutex,&waitTime);
}
Thread::Thread(const string &name, size_t stackSize)
: mThreadId((pthread_t)0)
, mThreadName(name)
, mStackSize(stackSize)
, mThreadState(THREAD_STATE_IDLE)
, mThreadData(NULL)
void Thread::start(void *(*task)(void*), void *arg)
{
assert(mThread==((pthread_t)0));
bool res;
// (pat) Moved initialization to constructor to avoid crash in destructor.
//res = pthread_attr_init(&mAttrib);
//assert(!res);
res = pthread_attr_setstacksize(&mAttrib, mStackSize);
assert(!res);
res = pthread_create(&mThread, &mAttrib, task, arg);
assert(!res);
}
Thread::~Thread()
{
stopThread();
}
void *Thread::threadAdaptor(void *data)
{
Thread *pThread = (Thread*)data;
// If we ever receive a thread cancel request, it means that the Thread
// object is in the process of being destroyed. To avoid the situation
// where a thread attempts to run after its containing Thread object has
// been freed, we set the thread up so that the cancel takes effect
// immediately (as opposed to waiting until the next thread cancellation
// point).
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
// =====================================================================
// Synchronize with the start() in the parent thread.
{
// 1. Lock synchronization mutex.
ScopedLock lock(pThread->mThreadStartupMutex);
// 2. Btw, set the thread name, while we're inside the mutex.
// FIXME: This works on Linux with glibc >= 2.12. Under *BSD and MacOS X
// this function has different arguments.
// pthread_setname_np(pThread->mThreadId, pThread->mThreadName.c_str());
// FIXME: For some reason the previous call doesn't work on my Ubuntu 12.04,
// so we use this one which works.
prctl(PR_SET_NAME, pThread->mThreadName.c_str());
// 3. Signal that we've started.
pThread->mThreadStartStopEvent.signal();
// 4. Wait until start() finishes its initialization.
//
// The actual thread is created and started with pthread_create(), then
// start() does its housekeeping and sets mThreadState=THREAD_STATE_RUNNING.
// If we allow Thread::run() to start before this initialization completes,
// callers might think (among other things) that the thread is not started
// while it's actually started.
pThread->mThreadInitializedEvent.wait(pThread->mThreadStartupMutex);
}
// Synchronization with the parent thread is finished.
// =====================================================================
// Log Thread ID for debugging purposes
LOG(INFO) << "Thread started: " << pThread->mThreadName
<< " with lwp=" << gettid() << ", pid=" << getpid();
// Keep all memory locked into physical mem, to guarantee realtime-behaviour
int res = mlockall(MCL_CURRENT|MCL_FUTURE);
if (res != POSIX_OK) {
LOG(WARNING) << "Failed to lock memory for thread: " << pThread->mThreadName;
}
// Run the actual code
pThread->runThread();
// Huh, we're done. Signal to a (potentially) waiting stop()'s.
{
ScopedLock lock(pThread->mThreadStateMutex);
pThread->mThreadState = THREAD_STATE_IDLE;
pThread->mThreadStartStopEvent.broadcast();
}
return NULL;
}
Thread::ReturnStatus Thread::startThread(void *data)
{
pthread_attr_t attrib;
// timeval threadStartTime;
// timespec threadStartTimeout;
bool res;
// Lock startup synchronization mutex. It will be used in conjunction with
// mThreadInitializedEvent and mThreadStartStopEvent conditional variables.
ScopedLock lock(mThreadStartupMutex);
{
ScopedLock lock(mThreadStateMutex);
if (mThreadState != THREAD_STATE_IDLE)
return ALREADY_STARTED;
mThreadState = THREAD_STATE_STARTING;
}
// Save thread data pointer
mThreadData = data;
LOG(DEBUG) << "Starting thread " << mThreadName << " (" << this << ")";
// construct thread attribute
res = pthread_attr_init(&attrib);
if (res != POSIX_OK) {
LOG(ALERT) << "pthread_attr_init failed, returned " << res
<< " in " << mThreadName << " (" << this << ")";
}
// Set the thread stack size
res = pthread_attr_setstacksize(&attrib, mStackSize);
if (res != POSIX_OK)
{
LOG(ALERT) << "pthread_attr_setstacksize failed, returned " << res
<< " in " << mThreadName << " (" << this << ")";
}
// Create the thread detached
res = pthread_attr_setdetachstate(&attrib, PTHREAD_CREATE_DETACHED);
if (res != POSIX_OK)
{
LOG(ALERT) << "pthread_attr_setdetachstate failed, returned " << res
<< " in " << mThreadName << " (" << this << ")";
}
// =====================================================================
// Start the thread and synchronize with it
// Start the thread!
res = pthread_create(&mThreadId, &attrib, threadAdaptor, (void *)this);
// Attributes are no longer needed.
pthread_attr_destroy(&attrib);
if (res != POSIX_OK)
{
LOG(ALERT) << "pthread_create failed, returned " << res
<< " in " << mThreadName << " (" << this << ")";
return PTHREAD_ERROR;
}
// Wait for the thread to startup.
res = mThreadStartStopEvent.wait(mThreadStartupMutex, THREAD_STARTUP_TIMEOUT*1000);
// If the thread does not start in THREAD_STARTUP_TIMEOUT seconds,
// then something is terribly wrong here.
if (res == ETIMEDOUT)
{
LOG(ALERT) << "thread " << mThreadName << " (" << this << ") hasn't started up in "
<< THREAD_STARTUP_TIMEOUT << " seconds. Bailing out.";
return RETURN_TIMEOUT;
}
// We're done with the initialization.
ackThreadStart();
// ToDo: Add other initialization here, e.g. adding this thread to a list of all threads.
// Startup initialization finished. Signal this to started thread, so
// it could go on.
mThreadInitializedEvent.signal();
return RETURN_OK;
}
Thread::ReturnStatus Thread::stopThread()
{
int res;
LOG(DEBUG) << "Stopping thread " << mThreadName << " (" << this << ")";
while (1) {
ScopedLock lock(mThreadStateMutex);
switch (mThreadState) {
case THREAD_STATE_IDLE:
// Nothing to do.
return RETURN_OK;
case THREAD_STATE_STARTING:
// Something is wrong in thi world.
assert(mThreadState != THREAD_STATE_STARTING);
LOG(ALERT) << "Trying to stop thread " << mThreadName
<< " (" << this << ") while it's trying to start.";
return WRONG_STATE;
case THREAD_STATE_RUNNING:
// Request shudown
mThreadState = THREAD_STATE_STOPPING;
// no "break" here to fall through to the next case
case THREAD_STATE_STOPPING:
// Wait for the thread to stop.
LOG(DEBUG) << "Waiting for thread " << mThreadName << " (" << this << ") to stop.";
res = mThreadStartStopEvent.wait(mThreadStateMutex, THREAD_STOP_TIMEOUT*1000);
LOG(DEBUG) << "Thread " << mThreadName << " (" << this << ") signalled stop "
<< "with res=" << res << " and mThreadState=" << mThreadState;
// If the thread does not stop in THREAD_STOP_TIMEOUT seconds,
// return error. It may be waiting for something.
if (res == ETIMEDOUT)
{
LOG(ALERT) << "thread " << mThreadName << " (" << this << ") hasn't stopped in "
<< THREAD_STARTUP_TIMEOUT << " seconds. Bailing out.";
return RETURN_TIMEOUT;
}
// Conditional variable could return in case of a signal, so we should
// double check that the thread has indeed stopped.
if (mThreadState == THREAD_STATE_IDLE)
return RETURN_OK;
else
// Try again...
break;
}
}
// We should never reach this line
assert(false);
return RETURN_OK;
}
// vim: ts=4 sw=4

View File

@@ -1,6 +1,5 @@
/*
* Copyright 2008, 2011 Free Software Foundation, Inc.
* Copyright 2013 Alexander Chemeris <Alexander.Chemeris@fairwaves.ru>
*
* This software is distributed under the terms of the GNU Affero Public License.
* See the COPYING file in the main directory for details.
@@ -122,14 +121,14 @@ class Signal {
Block for the signal up to the cancellation timeout.
Under Linux, spurious returns are possible.
*/
int wait(Mutex& wMutex, unsigned timeout) const;
void wait(Mutex& wMutex, unsigned timeout) const;
/**
Block for the signal.
Under Linux, spurious returns are possible.
*/
int wait(Mutex& wMutex) const
{ return pthread_cond_wait(&mSignal,&wMutex.mMutex); }
void wait(Mutex& wMutex) const
{ pthread_cond_wait(&mSignal,&wMutex.mMutex); }
void signal() { pthread_cond_signal(&mSignal); }
@@ -138,105 +137,54 @@ class Signal {
};
#define START_THREAD(thread,function,argument) \
thread.start((void *(*)(void*))function, (void*)argument);
/** A C++ wrapper for pthread threads. */
class Thread {
public:
private:
typedef void *(*Adaptor)(void*);
enum ReturnStatus {
RETURN_OK = 0,
ALREADY_STARTED,
ALREADY_IDLE,
PTHREAD_ERROR,
WRONG_STATE,
RETURN_TIMEOUT
};
enum ThreadState {
THREAD_STATE_IDLE, ///< Thread is not started. On start() => STARTING
THREAD_STATE_STARTING, ///< Thread is about to start. When actually started => RUNNING
THREAD_STATE_RUNNING, ///< Thread is active. On stop() => STOPPING
THREAD_STATE_STOPPING ///< Thread is about to stop. When actually stopped => IDLE
};
enum {
THREAD_STARTUP_TIMEOUT=5, ///< Time to wait for thread startup (in seconds).
THREAD_STOP_TIMEOUT=5 ///< Time to wait for thread stop (in seconds).
};
pthread_t mThread;
pthread_attr_t mAttrib;
// FIXME -- Can this be reduced now?
size_t mStackSize;
/** Create a thread in a non-running state. */
Thread(const std::string &name, size_t stackSize = (65536*4));
public:
/** Destroy the Thread. */
virtual ~Thread();
/** Create a thread in a non-running state. */
Thread(size_t wStackSize = (65536*4)):mThread((pthread_t)0) {
pthread_attr_init(&mAttrib); // (pat) moved this here.
mStackSize=wStackSize;
}
/** Start the thread. */
ReturnStatus startThread(void *data=NULL);
/**
Destroy the Thread.
It should be stopped and joined.
*/
// (pat) If the Thread is destroyed without being started, then mAttrib is undefined. Oops.
~Thread() { pthread_attr_destroy(&mAttrib); }
/** Stop the thread. */
ReturnStatus stopThread();
ThreadState getThreadState() const
{
ScopedLock lock(mThreadStateMutex);
return mThreadState;
}
/** Start the thread on a task. */
void start(void *(*task)(void*), void *arg);
bool isThreadRunning() const
{
ScopedLock lock(mThreadStateMutex);
return mThreadState == THREAD_STATE_RUNNING;
}
void requestThreadStop()
{
ScopedLock lock(mThreadStateMutex);
if (mThreadState == THREAD_STATE_RUNNING)
mThreadState = THREAD_STATE_STOPPING;
}
bool isThreadStopping() const
{
ScopedLock lock(mThreadStateMutex);
return mThreadState == THREAD_STATE_STOPPING;
}
/** Join a thread that will stop on its own. */
void join() {
if (mThread) {
int s = pthread_join(mThread, NULL);
assert(!s);
}
}
const std::string &getThreadName() const {return mThreadName;}
protected:
pthread_t mThreadId; ///< OS id of the thread.
const std::string mThreadName; ///< Name of the thread.
size_t mStackSize; ///< Requested stack size for the thread.
ThreadState mThreadState; ///< The current state of the thread.
mutable Mutex mThreadStateMutex; ///< Mutex to protect ThreadState variable
void *mThreadData; ///< Data to be passed to the thread loop.
Mutex mThreadStartupMutex; ///< Mutex, used with the next two conditional
///< variables to synchronize thread startup.
Signal mThreadInitializedEvent; ///< Conditional variable, signaling
///< that this thread object initialization is completed
///< and the thread could go on.
Signal mThreadStartStopEvent; ///< Conditional variable, signaling
///< that the thread is started and start() method could
///< return to caller.
/** Function with the actual thread loop.
* Override this function in child classes to do real work.
*/
virtual void runThread() =0;
// Static funciton which actually starts the run() method.
static void *threadAdaptor(void *data);
void ackThreadStart() {
ScopedLock lock(mThreadStateMutex);
assert(mThreadState == THREAD_STATE_STARTING);
mThreadState = THREAD_STATE_RUNNING;
}
void ackThreadStop() {
ScopedLock lock(mThreadStateMutex);
assert(mThreadState == THREAD_STATE_STOPPING);
mThreadState = THREAD_STATE_IDLE;
}
/** Send cancelation to thread */
void cancel() { pthread_cancel(mThread); }
};
#endif
// vim: ts=4 sw=4

View File

@@ -1,94 +0,0 @@
/*
* Copyright 2013 Alexander Chemeris <Alexander.Chemeris@fairwaves.ru>
*
*
* This software is distributed under the terms of the GNU Affero Public License.
* See the COPYING file in the main directory for details.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Threads.h"
#include "Timeval.h"
#include "Configuration.h"
#include <iostream>
ConfigurationTable gConfig;
class SimpleThreadTest : public Thread
{
public:
SimpleThreadTest() : Thread("SimpleThreadTest") {}
void runThread()
{
COUT(getThreadName() << ": Started thread");
while (isThreadRunning()) {
COUT(getThreadName() << ": Sleeping...");
msleep(50);
}
COUT(getThreadName() << ": Stopped thread");
}
};
void testSimpleStartStop()
{
SimpleThreadTest simpleThreadTest;
COUT("Main: Starting thread " << simpleThreadTest.getThreadName());
simpleThreadTest.startThread();
COUT("Main: Started thread " << simpleThreadTest.getThreadName());
msleep(30);
COUT("Main: Stopping thread " << simpleThreadTest.getThreadName());
simpleThreadTest.stopThread();
COUT("Main: Stopped thread " << simpleThreadTest.getThreadName());
}
void testDoubleRequestStop()
{
SimpleThreadTest simpleThreadTest;
COUT("Main: Starting thread " << simpleThreadTest.getThreadName());
simpleThreadTest.startThread();
COUT("Main: Started thread " << simpleThreadTest.getThreadName());
msleep(30);
COUT("Main: Requesting stop for thread " << simpleThreadTest.getThreadName());
simpleThreadTest.requestThreadStop();
msleep(30);
COUT("Main: Requesting stop for thread " << simpleThreadTest.getThreadName());
simpleThreadTest.requestThreadStop();
msleep(30);
COUT("Main: Stopping thread " << simpleThreadTest.getThreadName());
simpleThreadTest.stopThread();
COUT("Main: Stopped thread " << simpleThreadTest.getThreadName());
}
int main(int argc, char *argv[])
{
std::cout<< std::endl << "Simple start/stop test" << std::endl << std::endl ;
testSimpleStartStop();
std::cout << std::endl << "Double requestThreadStop() test" << std::endl << std::endl ;
testDoubleRequestStop();
}
// vim: ts=4 sw=4

View File

@@ -1,28 +0,0 @@
/* Copyright 2011, Range Networks, Inc. */
#include <URLEncode.h>
#include <string>
#include <string.h>
#include <ctype.h>
using namespace std;
//based on javascript encodeURIComponent()
string URLEncode(const string &c)
{
static const char *digits = "01234567890ABCDEF";
string retVal="";
for (size_t i=0; i<c.length(); i++)
{
const char ch = c[i];
if (isalnum(ch) || strchr("-_.!~'()",ch)) {
retVal += ch;
} else {
retVal += '%';
retVal += digits[(ch>>4) & 0x0f];
retVal += digits[ch & 0x0f];
}
}
return retVal;
}

View File

@@ -1,30 +0,0 @@
/*
* Copyright 2011 Free Software Foundation, Inc.
*
*
* This software is distributed under the terms of the GNU Affero Public License.
* See the COPYING file in the main directory for details.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
# include <string>
std::string URLEncode(const std::string&);

View File

@@ -1,17 +0,0 @@
#include "URLEncode.h"
#include <string>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
string test = string("Testing: !@#$%^&*() " __DATE__ " " __TIME__);
cout << test << endl;
cout << URLEncode(test) << endl;
}

View File

@@ -1,211 +0,0 @@
/*
* Copyright 2011 Range Networks, Inc.
* All Rights Reserved.
*
* This software is distributed under multiple licenses;
* see the COPYING file in the main directory for licensing
* information for this specific distribuion.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <unistd.h> // For usleep
#include <sys/time.h> // For gettimeofday
#include <stdio.h> // For vsnprintf
#include <ostream> // For ostream
#include <sstream> // For ostringstream
#include <string.h> // For strcpy
//#include "GSMCommon.h"
#include "Utils.h"
#include "MemoryLeak.h"
namespace Utils {
MemStats gMemStats;
int gMemLeakDebug = 0;
MemStats::MemStats()
{
memset(mMemNow,0,sizeof(mMemNow));
memset(mMemTotal,0,sizeof(mMemTotal));
memset(mMemName,0,sizeof(mMemName));
}
void MemStats::text(std::ostream &os)
{
os << "Structs current total:\n";
for (int i = 0; i < mMax; i++) {
os << "\t" << (mMemName[i] ? mMemName[i] : "unknown") << " " << mMemNow[i] << " " << mMemTotal[i] << "\n";
}
}
void MemStats::memChkNew(MemoryNames memIndex, const char *id)
{
/*std::cout << "new " #type "\n";*/
mMemNow[memIndex]++;
mMemTotal[memIndex]++;
mMemName[memIndex] = id;
}
void MemStats::memChkDel(MemoryNames memIndex, const char *id)
{
/*std::cout << "del " #type "\n";*/
mMemNow[memIndex]--;
if (mMemNow[memIndex] < 0) {
LOG(ERR) << "Memory underflow on type "<<id;
if (gMemLeakDebug) assert(0);
mMemNow[memIndex] += 100; // Prevent another message for a while.
}
}
std::ostream& operator<<(std::ostream& os, std::ostringstream& ss)
{
return os << ss.str();
}
std::ostream &osprintf(std::ostream &os, const char *fmt, ...)
{
va_list ap;
char buf[300];
va_start(ap,fmt);
int n = vsnprintf(buf,300,fmt,ap);
va_end(ap);
if (n >= (300-4)) { strcpy(&buf[(300-4)],"..."); }
os << buf;
return os;
}
std::string format(const char *fmt, ...)
{
va_list ap;
char buf[300];
va_start(ap,fmt);
int n = vsnprintf(buf,300,fmt,ap);
va_end(ap);
if (n >= (300-4)) { strcpy(&buf[(300-4)],"..."); }
return std::string(buf);
}
// Return time in seconds with high resolution.
// Note: In the past I found this to be a surprisingly expensive system call in linux.
double timef()
{
struct timeval tv;
gettimeofday(&tv,NULL);
return tv.tv_usec / 1000000.0 + tv.tv_sec;
}
const std::string timestr()
{
struct timeval tv;
struct tm tm;
gettimeofday(&tv,NULL);
localtime_r(&tv.tv_sec,&tm);
unsigned tenths = tv.tv_usec / 100000; // Rounding down is ok.
return format(" %02d:%02d:%02d.%1d",tm.tm_hour,tm.tm_min,tm.tm_sec,tenths);
}
// High resolution sleep for the specified time.
// Return FALSE if time is already past.
void sleepf(double howlong)
{
if (howlong <= 0.00001) return; // Less than 10 usecs, forget it.
usleep((useconds_t) (1000000.0 * howlong));
}
//bool sleepuntil(double untilwhen)
//{
//double now = timef();
//double howlong = untilwhen - now; // Fractional time in seconds.
// We are not worrying about overflow because all times should be in the near future.
//if (howlong <= 0.00001) return false; // Less than 10 usecs, forget it.
//sleepf(sleeptime);
//}
std::string Text2Str::str() const
{
std::ostringstream ss;
text(ss);
return ss.str();
}
std::ostream& operator<<(std::ostream& os, const Text2Str *val)
{
std::ostringstream ss;
if (val) {
val->text(ss);
os << ss.str();
} else {
os << "(null)";
}
return os;
}
// Greatest Common Denominator.
// This is by Doug Brown.
int gcd(int x, int y)
{
if (x > y) {
return x % y == 0 ? y : gcd(y, x % y);
} else {
return y % x == 0 ? x : gcd(x, y % x);
}
}
// Split a C string into an argc,argv array in place; the input string is modified.
// Returns argc, and places results in argv, up to maxargc elements.
// The final argv receives the rest of the input string from maxargc on,
// even if it contains additional splitchars.
// The correct idiom for use is to make a copy of your string, like this:
// char *copy = strcpy((char*)alloca(the_string.length()+1),the_string.c_str());
// char *argv[2];
// int argc = cstrSplit(copy,argv,2,NULL);
// If you want to detect the error of too many arguments, add 1 to argv, like this:
// char *argv[3];
// int argc = cstrSplit(copy,argv,3,NULL);
// if (argc == 3) { error("too many arguments"; }
int cstrSplit(char *in, char **pargv,int maxargc, const char *splitchars)
{
if (splitchars == NULL) { splitchars = " \t\r\n"; } // Default is any space.
int argc = 0;
while (argc < maxargc) {
while (*in && strchr(splitchars,*in)) {in++;} // scan past any splitchars
if (! *in) return argc; // return if finished.
pargv[argc++] = in; // save ptr to start of arg.
in = strpbrk(in,splitchars); // go to end of arg.
if (!in) return argc; // return if finished.
*in++ = 0; // zero terminate this arg.
}
return argc;
}
std::ostream& operator<<(std::ostream& os, const Statistic<int> &stat) { stat.text(os); return os; }
std::ostream& operator<<(std::ostream& os, const Statistic<unsigned> &stat) { stat.text(os); return os; }
std::ostream& operator<<(std::ostream& os, const Statistic<float> &stat) { stat.text(os); return os; }
std::ostream& operator<<(std::ostream& os, const Statistic<double> &stat) { stat.text(os); return os; }
std::string replaceAll(const std::string input, const std::string search, const std::string replace)
{
std::string output = input;
int index = 0;
while (true) {
index = output.find(search, index);
if (index == std::string::npos) {
break;
}
output.replace(index, replace.length(), replace);
index += replace.length();
}
return output;
}
};

View File

@@ -1,148 +0,0 @@
/*
* Copyright 2011 Range Networks, Inc.
* All Rights Reserved.
*
* This software is distributed under multiple licenses;
* see the COPYING file in the main directory for licensing
* information for this specific distribuion.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef GPRSUTILS_H
#define GPRSUTILS_H
#include <stdint.h>
#include <stdarg.h>
#include <string>
#include <string.h>
#include <math.h> // for sqrtf
#include "Logger.h"
namespace Utils {
extern double timef(); // high resolution time
extern const std::string timestr(); // A timestamp to print in messages.
extern void sleepf(double howlong); // high resolution sleep
extern int gcd(int x, int y);
// It is irritating to create a string just to interface to the brain-damaged
// C++ stream class, but this is only used for debug messages.
std::string format(const char *fmt, ...) __attribute__((format (printf,1,2)));
int cstrSplit(char *in, char **pargv,int maxargc, const char *splitchars=NULL);
// For classes with a text() function, provide a function to return a String,
// and also a standard << stream function that takes a pointer to the object.
// We dont provide the function that takes a reference to the object
// because it is too highly overloaded and generally doesnt work.
class Text2Str {
public:
virtual void text(std::ostream &os) const = 0;
std::string str() const;
};
std::ostream& operator<<(std::ostream& os, const Text2Str *val);
#if 0
// Generic Activity Timer. Lots of controls to make everybody happy.
class ATimer {
double mStart;
//bool mActive;
double mLimitTime;
public:
ATimer() : mStart(0), mLimitTime(0) { }
ATimer(double wLimitTime) : mStart(0), mLimitTime(wLimitTime) { }
void start() { mStart=timef(); }
void stop() { mStart=0; }
bool active() { return !!mStart; }
double elapsed() { return timef() - mStart; }
bool expired() { return elapsed() > mLimitTime; }
};
#endif
struct BitSet {
unsigned mBits;
void setBit(unsigned whichbit) { mBits |= 1<<whichbit; }
void clearBit(unsigned whichbit) { mBits &= ~(1<<whichbit); }
unsigned getBit(unsigned whichbit) const { return mBits & (1<<whichbit); }
bool isSet(unsigned whichbit) const { return mBits & (1<<whichbit); }
unsigned bits() const { return mBits; }
operator int(void) const { return mBits; }
BitSet() { mBits = 0; }
};
// Store current, min, max and compute running average and standard deviation.
template<class Type> struct Statistic {
Type mCurrent, mMin, mMax; // min,max optional initialization so you can print before adding any values.
unsigned mCnt;
double mSum;
//double mSum2; // sum of squares.
// (Type) cast needed in case Type is an enum, stupid language.
Statistic() : mCurrent((Type)0), mMin((Type)0), mMax((Type)0), mCnt(0), mSum(0) /*,mSum2(0)*/ {}
// Set the current value and add a statisical point.
void addPoint(Type val) {
mCurrent = val;
if (mCnt == 0 || val < mMin) {mMin = val;}
if (mCnt == 0 || val > mMax) {mMax = val;}
mCnt++;
mSum += val;
//mSum2 += val * val;
}
Type getCurrent() const { // Return current value.
return mCnt ? mCurrent : 0;
}
double getAvg() const { // Return average.
return mCnt==0 ? 0 : mSum/mCnt;
};
//float getSD() const { // Return standard deviation. Use low precision square root function.
// return mCnt==0 ? 0 : sqrtf(mCnt * mSum2 - mSum*mSum) / mCnt;
//}
void text(std::ostream &os) const { // Print everything in parens.
os << "("<<mCurrent;
if (mMin != mMax) { // Not point in printing all this stuff if min == max.
os <<LOGVAR2("min",mMin)<<LOGVAR2("max",mMax)<<LOGVAR2("avg",getAvg());
if (mCnt <= 999999) {
os <<LOGVAR2("N",mCnt);
} else { // Shorten this up:
char buf[10], *ep;
sprintf(buf,"%.3g",round(mCnt));
if ((ep = strchr(buf,'e')) && ep[1] == '+') { strcpy(ep+1,ep+2); }
os << LOGVAR2("N",buf);
}
// os<<LOGVAR2("sd",getSD()) standard deviation not interesting
}
os << ")";
// " min="<<mMin <<" max="<<mMax <<format(" avg=%4g sd=%3g)",getAvg(),getSD());
}
// Not sure if this works:
//std::string statStr() const {
// return (std::string)mCurrent + " min=" + (std::string) mMin +" max="+(string)mMax+ format(" avg=%4g sd=%3g",getAvg(),getSD());
//}
};
// This I/O mechanism is so dumb:
std::ostream& operator<<(std::ostream& os, const Statistic<int> &stat);
std::ostream& operator<<(std::ostream& os, const Statistic<unsigned> &stat);
std::ostream& operator<<(std::ostream& os, const Statistic<float> &stat);
std::ostream& operator<<(std::ostream& os, const Statistic<double> &stat);
// Yes, they botched and left this out:
std::ostream& operator<<(std::ostream& os, std::ostringstream& ss);
std::ostream &osprintf(std::ostream &os, const char *fmt, ...) __attribute__((format (printf,2,3)));
std::string replaceAll(const std::string input, const std::string search, const std::string replace);
}; // namespace
using namespace Utils;
#endif

View File

@@ -92,6 +92,13 @@ template <class T> class Vector {
mEnd = mStart + newSize;
}
/** Reduce addressable size of the Vector, keeping content. */
void shrink(size_t newSize)
{
assert(newSize <= mEnd - mStart);
mEnd = mStart + newSize;
}
/** Release memory and clear pointers. */
void clear() { resize(0); }
@@ -222,6 +229,21 @@ template <class T> class Vector {
memcpy(other.mStart,base,span*sizeof(T));
}
/**
Move (copy) a segment of this vector into a different position in the vector
@param from Start point from which to copy.
@param to Start point to which to copy.
@param span The number of elements to copy.
*/
void segmentMove(size_t from, size_t to, size_t span)
{
const T* baseFrom = mStart + from;
T* baseTo = mStart + to;
assert(baseFrom+span<=mEnd);
assert(baseTo+span<=mEnd);
memmove(baseTo,baseFrom,span*sizeof(T));
}
void fill(const T& val)
{
T* dp=mStart;

View File

@@ -4,7 +4,7 @@
*/
#include "sqlite3.h"
#include <sqlite3.h>
#include "sqlite3util.h"
#include <string.h>

View File

@@ -41,10 +41,24 @@ const BitVector GSM::gTrainingSequence[] = {
BitVector("11101111000100101110111100"),
};
const BitVector GSM::gEdgeTrainingSequence[] = {
BitVector("111111001111111001111001001001111111111111001111111111001111111001111001001001"),
BitVector("111111001111001001111001001001111001001001001111111111001111001001111001001001"),
BitVector("111001111111111111001001001111001001001111001111111001111111111111001001001111"),
BitVector("111001111111111001001001001111001001111001111111111001111111111001001001001111"),
BitVector("111111111001001111001111001001001111111001111111111111111001001111001111001001"),
BitVector("111001111111001001001111001111001001111111111111111001111111001001001111001111"),
BitVector("001111001111111001001001001001111001001111111111001111001111111001001001001001"),
BitVector("001001001111001001001001111111111001111111001111001001001111001001001001111111"),
};
const BitVector GSM::gDummyBurst("0001111101101110110000010100100111000001001000100000001111100011100010111000101110001010111010010100011001100111001111010011111000100101111101010000");
const BitVector GSM::gRACHSynchSequence("01001011011111111001100110101010001111000");
// |-head-||---------midamble----------------------||--------------data----------------||t|
const BitVector GSM::gRACHBurst("0011101001001011011111111001100110101010001111000110111101111110000111001001010110011000");
int32_t GSM::FNDelta(int32_t v1, int32_t v2)
{

View File

@@ -46,12 +46,15 @@ namespace GSM {
/** GSM Training sequences from GSM 05.02 5.2.3. */
extern const BitVector gTrainingSequence[];
extern const BitVector gEdgeTrainingSequence[];
/** C0T0 filler burst, GSM 05.02, 5.2.6 */
extern const BitVector gDummyBurst;
/** Random access burst synch. sequence */
extern const BitVector gRACHSynchSequence;
/** Random access burst synch. sequence, GSM 05.02 5.2.7 */
extern const BitVector gRACHBurst;
/**@name Modulus operations for frame numbers. */

View File

View File

@@ -20,14 +20,14 @@
include $(top_srcdir)/Makefile.common
AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) $(USB_INCLUDES) $(WITH_INCLUDES)
ACLOCAL_AMFLAGS = -I config
AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) $(USB_INCLUDES) $(WITH_INCLUDES) $(SQLITE3_CFLAGS)
AM_CXXFLAGS = -Wall -pthread -ldl
#AM_CXXFLAGS = -Wall -O2 -NDEBUG -pthread -ldl
#AM_CFLAGS = -Wall -O2 -NDEBUG -pthread -ldl
# Order must be preserved
SUBDIRS = \
sqlite3 \
CommonLibs \
GSM \
Transceiver52M

View File

@@ -18,17 +18,18 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
top_srcdir = $(abs_top_srcdir)
top_builddir = $(abs_top_builddir)
COMMON_INCLUDEDIR = $(top_srcdir)/CommonLibs
GSM_INCLUDEDIR = $(top_srcdir)/GSM
SQLITE_INCLUDEDIR = $(top_srcdir)/sqlite3
STD_DEFINES_AND_INCLUDES = \
$(SVNDEV) \
-I$(COMMON_INCLUDEDIR) \
-I$(GSM_INCLUDEDIR) \
-I$(SQLITE_INCLUDEDIR)
-I$(GSM_INCLUDEDIR)
COMMON_LA = $(top_builddir)/CommonLibs/libcommon.la
GSM_LA = $(top_builddir)/GSM/libGSM.la
SQLITE_LA = $(top_builddir)/sqlite3/libsqlite.la -ldl
MOSTLYCLEANFILES = *~

260
README
View File

@@ -1,168 +1,116 @@
Welcome to the OpenBTS source code.
This is the interface to the transcevier.
For free support, please subscribe to openbts-discuss@lists.sourceforge.net.
See http://sourceforge.net/mailarchive/forum.php?forum_name=openbts-discuss
and https://lists.sourceforge.net/lists/listinfo/openbts-discuss for details.
For additional information, refer to http://openbts.org.
These are the directories:
AsteriskConfig Asterisk configuration files for use with OpenBTS.
CommonLib Common-use libraries, mostly C++ wrappers for basic facilities.
Control Control-layer functions for the protocols of GSM 04.08 and SIP.
GSM The GSM stack.
SIP Components of the SIP state machines ued by the control layer.
SMS The SMS stack.
SR The subscriber registry.
TRXManager The interface between the GSM stack and the radio.
Transceiver The software transceiver and specific installation tests.
apps OpenBTS application binaries.
doc Project documentation.
tests Test fixtures for subsets of OpenBTS components.
smqueue RFC-3428 store-and-forward server for SMS
Each TRX Manager UDP socket interface represents a single ARFCN.
Each of these per-ARFCN interfaces is a pair of UDP sockets, one for control and one for data.
Give a base port B (5700), the master clock interface is at port P=B.
The TRX-side control interface for C(N) is on port P=B+2N+1 and the data interface is on an odd numbered port P=B+2N+2.
The corresponding core-side interface for every socket is at P+100.
For any given build, the number of ARFCN interfaces can be fixed.
By default, OpenBTS assumes the following UDP port assignments:
Indications on the Master Clock Interface
5060 -- Asterisk SIP interface
5061 -- local SIP softphone
5062 -- OpenBTS SIP interface
5063 -- smqueue SIP interface
5064 -- subscriber registry SIP interface
5700-range -- OpenBTS-transceiver interface
The master clock interface is output only (from the radio).
Messages are "indications".
These can be controlled in the CONFIG table in /etc/OpenBTS.db.
CLOCK gives the current value of the transceiver clock to be used by the core.
This message is sent whenever a trasmission packet arrives that is too late or too early. The clock value is NOT the current transceiver time. It is a time setting the the core should use to give better packet arrival times.
IND CLOCK <totalFrames>
Standrd paths:
/OpenBTS -- Binary installation.
/etc/OpenBTS -- Configuration databases.
/var/run/OpenBTS -- Real-time reporting databases.
The script apps/setUpFiles.sh will create these directories and install the
correct files in them.
Commands on the Per-ARFCN Control Interface
The per-ARFCN control interface uses a command-reponse protocol.
Commands are NULL-terminated ASCII strings, one per UDP socket.
Each command has a corresponding response.
Every command is of the form:
CMD <cmdtype> [params]
The <cmdtype> is the actual command.
Parameters are optional depending on the commands type.
Every response is of the form:
RSP <cmdtype> <status> [result]
The <status> is 0 for success and a non-zero error code for failure.
Successful responses may include results, depending on the command type.
Power Control
POWEROFF shuts off transmitter power and stops the demodulator.
CMD POWEROFF
RSP POWEROFF <status>
POWERON starts the transmitter and starts the demodulator. Initial power level is very low.
This command fails if the transmitter and receiver are not yet tuned.
This command fails if the transmit or receive frequency creates a conflict with another ARFCN that is already runnng.
If the transceiver is already on, it response with success to this command.
CMD POWERON
RSP POWERON <status>
SETPOWER sets output power in dB wrt full scale.
This command fails if the transmitter and receiver are not running.
CMD SETPOWER <dB>
RSP SETPOWER <status> <dB>
ADJPOWER adjusts power by the given dB step. Response returns resulting power level wrt full scale.
This command fails if the transmitter and receiver are not running.
CMD ADJPOWER <dBStep>
RSP ADJPOWER <status> <dBLevel>
Tuning Control
RXTUNE tunes the receiver to a given frequency in kHz.
This command fails if the receiver is already running.
(To re-tune you stop the radio, re-tune, and restart.)
This command fails if the transmit or receive frequency creates a conflict with another ARFCN that is already runnng.
CMD RXTUNE <kHz>
RSP RXTUNE <status> <kHz>
TXTUNE tunes the transmitter to a given frequency in kHz.
This command fails if the transmitter is already running.
(To re-tune you stop the radio, re-tune, and restart.)
This command fails if the transmit or receive frequency creates a conflict with another ARFCN that is already runnng.
CMD TXTUNE <kHz>
RSP TXTUNE <status> <kHz>
Timeslot Control
SETSLOT sets the format of the uplink timeslots in the ARFCN.
The <timeslot> indicates the timeslot of interest.
The <chantype> indicates the type of channel that occupies the timeslot.
A chantype of zero indicates the timeslot is off.
CMD SETSLOT <timeslot> <chantype>
RSP SETSLOT <status> <timeslot> <chantype>
Messages on the per-ARFCN Data Interface
Messages on the data interface carry one radio burst per UDP message.
Received Data Burst
1 byte timeslot index
4 bytes GSM frame number, big endian
1 byte RSSI in -dBm
2 bytes correlator timing offset in 1/256 symbol steps, 2's-comp, big endian
148 bytes soft symbol estimates, 0 -> definite "0", 255 -> definite "1"
Transmit Data Burst
1 byte timeslot index
4 bytes GSM frame number, big endian
1 byte transmit level wrt ARFCN max, -dB (attenuation)
148 bytes output symbol values, 0 & 1
Release history:
Release Name SVN Reposiory SVN Rev Comments
1.0 (none) SF.net ?? completed L1, L2
1.1 Arnaudville GNU Radio r10019 (trunk)
1.2 Breaux Bridge GNU Radio r10088 (trunk) GNU Build, very early assignment
1.3 Carencro KSP r1 (trunk) first post-injunction release
1.4 Donaldsonville KSP r23 (trunk) fixed Ubuntu build error
1.5 Eunice KSP r39 (trunk) fixed L2 bugs related to segmentation
removed incomplete SMS directory
moved "abort" calls into L3 subclasses
1.6 New Iberia KSP r130 (trunk) import of all 2.2 improvements to non-SMS release
2.0 St. Francisville KSP r54 (smswork) SMS support
file-based configuration
2.1 Grand Coteau KSP r70 (smswork) DTMF support
fixed more Linux-related build errors
-lpthread
TLMessage constructor
expanded stack to prevent overflows in Linux
moved gSIPInterface to main app
fixed iterator bug in Pager
2.2 Houma KSP r122 (smswork) added LEGAL notice
removed Assert classes
stop paging on page response
fixed Pager-spin bug
fixed Transceiver spin bugs
fixed 2^32 microsecond rollover bug
reduced stack footprints in Transceiver
fixed SMS timestamps
check LAI before using TMSI in LUR
reduced memory requirement by 75%
removed PagerTest
fixed stale-transaction bug in paging handler
fixed USRP clock rollover bug
faster call connection
new USRPDevice design
2.3 Jean Lafitte KSP r190? (trunk) check for out-of-date RACH bursts
better TRX-GSM clock sync
formal logging system
command line interface
emergency call setup
2.4 Kinder KSP r208? (trunk) fixed BCCH neighbor list bug
support for neighbor lists
fixed support for non-local Asterisk servers
cleaner configuration management
more realtime control of BCCH parameters
proper rejection of Hold messages
fixed L3 hanging bug in MTDCheckBYE
2.4.1 Kinder KSP r462 fixed lots of valgrind errors
2.4.2 Kinder KSP r482 zero-length calling party number bug
g++ 4.4 #includes
2.5 Lacassine KSP r551 imported Joshua Lackey patches
SIP fixes from Anne Kwong
SIP fixes from testing with SMS server
L3 TI handling fixes
SMS server support
GNU Radio 3.2 compatibility
configurable max range and LU-reject cause
"page" & "testcall" CLI features
2.5.1 Lacassine KSP r595 fixed some build bugs for some Linux distros
2.5.2 Lacassine KSP r630 fixed channel assignment bug for Nokia DCT4+ handsets
2.5.3 Lacassine KSP r756 merged fix for transceiver startup crash
due to use of uninitialized variables (r646)
merged fix for fusb bug from trunk (r582)
2.5.4 Lacassine KSP r812 merged fixes to build under latest Fedora and
to build with git GnuRadio (r814)
2.6 Mamou KSP r886 fixed infamous fusb bug (r582)
fixed idle-filling table size bug
smoother uplink power control
load-limiting downlink power control
new "config" features (optional, static)
IMEI interrogation
fixed MOD "missing FIFO" bug
configurable short code features
fixed transceiver startup crash (r646)
readline support is back
fixed timing advance bug (r844)
added CLI "chans" command
track time-of-use in TMSI table (r844)
added CLI "noise" command (r844)
added CLI "rxpower" command (r844)
added CLI "unconfig" command
2.7 Natchitoches Range rxxx (never released publicly)
converted TMSITable to sqlite3 (r902)
sqlite3-based configuration (r???)
converted Logger to syslogd (r903)
added support for rest octets (r1022)
external database for transaction reporting (r1184)
external database for channel status reporting (r1203)
in-call delivery and submission of text messages (r1231)
RFC-2833 DMTF (r1249)
2.8 Opelousas Range rxxx move databases to /etc and /var
RRLP aiding support

View File

@@ -0,0 +1,108 @@
/*
* Polyphase channelizer
*
* Copyright (C) 2012-2014 Tom Tsou <tom@tsou.cc>
* Copyright (C) 2015 Ettus Research LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* See the COPYING file in the main directory for details.
*/
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include <cstdio>
#include "Logger.h"
#include "Channelizer.h"
extern "C" {
#include "common/fft.h"
#include "common/convolve.h"
}
static void deinterleave(const float *in, size_t ilen,
float **out, size_t olen, size_t m)
{
size_t i, n;
for (i = 0; i < olen; i++) {
for (n = 0; n < m; n++) {
out[m - 1 - n][2 * i + 0] = in[2 * (i * m + n) + 0];
out[m - 1 - n][2 * i + 1] = in[2 * (i * m + n) + 1];
}
}
}
size_t Channelizer::inputLen() const
{
return blockLen * m;
}
size_t Channelizer::outputLen() const
{
return blockLen;
}
float *Channelizer::outputBuffer(size_t chan) const
{
if (chan >= m)
return NULL;
return hInputs[chan];
}
/*
* Implementation based on material found in:
*
* "harris, fred, Multirate Signal Processing, Upper Saddle River, NJ,
* Prentice Hall, 2006."
*/
bool Channelizer::rotate(const float *in, size_t len)
{
size_t hSize = 2 * hLen * sizeof(float);
if (!checkLen(blockLen, len))
return false;
deinterleave(in, len, hInputs, blockLen, m);
/*
* Convolve through filterbank while applying and saving sample history
*/
for (size_t i = 0; i < m; i++) {
memcpy(&hInputs[i][2 * -hLen], hist[i], hSize);
memcpy(hist[i], &hInputs[i][2 * (blockLen - hLen)], hSize);
convolve_real(hInputs[i], blockLen,
subFilters[i], hLen,
hOutputs[i], blockLen,
0, blockLen, 1, 0);
}
cxvec_fft(fftHandle);
return true;
}
/* Setup channelizer paramaters */
Channelizer::Channelizer(size_t m, size_t blockLen, size_t hLen)
: ChannelizerBase(m, blockLen, hLen)
{
}
Channelizer::~Channelizer()
{
}

View File

@@ -0,0 +1,34 @@
#ifndef _CHANNELIZER_RX_H_
#define _CHANNELIZER_RX_H_
#include "ChannelizerBase.h"
class Channelizer : public ChannelizerBase {
public:
/** Constructor for channelizing filter bank
@param m number of physical channels
@param blockLen number of samples per output of each iteration
@param hLen number of taps in each constituent filter path
*/
Channelizer(size_t m, size_t blockLen, size_t hLen = 16);
~Channelizer();
/* Return required input and output buffer lengths */
size_t inputLen() const;
size_t outputLen() const;
/** Rotate "input commutator" and drive samples through filterbank
@param in complex input vector
@param iLen number of samples in buffer (must match block length)
@return false on error and true otherwise
*/
bool rotate(const float *in, size_t iLen);
/** Get buffer for an output path
@param chan channel number of filterbank
@return NULL on error and pointer to buffer otherwise
*/
float *outputBuffer(size_t chan) const;
};
#endif /* _CHANNELIZER_RX_H_ */

View File

@@ -0,0 +1,251 @@
/*
* Polyphase channelizer
*
* Copyright (C) 2012-2014 Tom Tsou <tom@tsou.cc>
* Copyright (C) 2015 Ettus Research LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* See the COPYING file in the main directory for details.
*/
#include <malloc.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include <cstdio>
#include "Logger.h"
#include "ChannelizerBase.h"
extern "C" {
#include "common/fft.h"
}
static float sinc(float x)
{
if (x == 0.0f)
return 0.999999999999f;
return sin(M_PI * x) / (M_PI * x);
}
/*
* There are more efficient reversal algorithms, but we only reverse at
* initialization so we don't care.
*/
static void reverse(float *buf, size_t len)
{
float tmp[2 * len];
memcpy(tmp, buf, 2 * len * sizeof(float));
for (size_t i = 0; i < len; i++) {
buf[2 * i + 0] = tmp[2 * (len - 1 - i) + 0];
buf[2 * i + 1] = tmp[2 * (len - 1 - i) + 1];
}
}
/*
* Create polyphase filterbank
*
* Implementation based material found in,
*
* "harris, fred, Multirate Signal Processing, Upper Saddle River, NJ,
* Prentice Hall, 2006."
*/
bool ChannelizerBase::initFilters()
{
size_t protoLen = m * hLen;
float *proto;
float sum = 0.0f, scale = 0.0f;
float midpt = (float) (protoLen - 1.0) / 2.0;
/*
* Allocate 'M' partition filters and the temporary prototype
* filter. Coefficients are real only and must be 16-byte memory
* aligned for SSE usage.
*/
proto = new float[protoLen];
if (!proto)
return false;
subFilters = (float **) malloc(sizeof(float *) * m);
if (!subFilters) {
delete[] proto;
return false;
}
for (size_t i = 0; i < m; i++) {
subFilters[i] = (float *)
memalign(16, hLen * 2 * sizeof(float));
}
/*
* Generate the prototype filter with a Blackman-harris window.
* Scale coefficients with DC filter gain set to unity divided
* by the number of channels.
*/
float a0 = 0.35875;
float a1 = 0.48829;
float a2 = 0.14128;
float a3 = 0.01168;
for (size_t i = 0; i < protoLen; i++) {
proto[i] = sinc(((float) i - midpt) / (float) m);
proto[i] *= a0 -
a1 * cos(2 * M_PI * i / (protoLen - 1)) +
a2 * cos(4 * M_PI * i / (protoLen - 1)) -
a3 * cos(6 * M_PI * i / (protoLen - 1));
sum += proto[i];
}
scale = (float) m / sum;
/*
* Populate partition filters and reverse the coefficients per
* convolution requirements.
*/
for (size_t i = 0; i < hLen; i++) {
for (size_t n = 0; n < m; n++) {
subFilters[n][2 * i + 0] = proto[i * m + n] * scale;
subFilters[n][2 * i + 1] = 0.0f;
}
}
for (size_t i = 0; i < m; i++)
reverse(subFilters[i], hLen);
delete[] proto;
return true;
}
bool ChannelizerBase::initFFT()
{
size_t size;
if (fftInput || fftOutput || fftHandle)
return false;
size = blockLen * m * 2 * sizeof(float);
fftInput = (float *) fft_malloc(size);
memset(fftInput, 0, size);
size = (blockLen + hLen) * m * 2 * sizeof(float);
fftOutput = (float *) fft_malloc(size);
memset(fftOutput, 0, size);
if (!fftInput | !fftOutput) {
LOG(ALERT) << "Memory allocation error";
return false;
}
fftHandle = init_fft(0, m, blockLen, blockLen + hLen,
fftInput, fftOutput, hLen);
return true;
}
bool ChannelizerBase::mapBuffers()
{
if (!fftHandle) {
LOG(ALERT) << "FFT buffers not initialized";
return false;
}
hInputs = (float **) malloc(sizeof(float *) * m);
hOutputs = (float **) malloc(sizeof(float *) * m);
if (!hInputs | !hOutputs)
return false;
for (size_t i = 0; i < m; i++) {
hInputs[i] = &fftOutput[2 * (i * (blockLen + hLen) + hLen)];
hOutputs[i] = &fftInput[2 * (i * blockLen)];
}
return true;
}
/*
* Setup filterbank internals
*/
bool ChannelizerBase::init()
{
/*
* Filterbank coefficients, fft plan, history, and output sample
* rate conversion blocks
*/
if (!initFilters()) {
LOG(ALERT) << "Failed to initialize channelizing filter";
return false;
}
hist = (float **) malloc(sizeof(float *) * m);
for (size_t i = 0; i < m; i++) {
hist[i] = new float[2 * hLen];
memset(hist[i], 0, 2 * hLen * sizeof(float));
}
if (!initFFT()) {
LOG(ALERT) << "Failed to initialize FFT";
return false;
}
mapBuffers();
return true;
}
/* Check vector length validity */
bool ChannelizerBase::checkLen(size_t innerLen, size_t outerLen)
{
if (outerLen != innerLen * m) {
LOG(ALERT) << "Invalid outer length " << innerLen
<< " is not multiple of " << blockLen;
return false;
}
if (innerLen != blockLen) {
LOG(ALERT) << "Invalid inner length " << outerLen
<< " does not equal " << blockLen;
return false;
}
return true;
}
/*
* Setup channelizer paramaters
*/
ChannelizerBase::ChannelizerBase(size_t m, size_t blockLen, size_t hLen)
: fftInput(NULL), fftOutput(NULL), fftHandle(NULL)
{
this->m = m;
this->hLen = hLen;
this->blockLen = blockLen;
}
ChannelizerBase::~ChannelizerBase()
{
free_fft(fftHandle);
for (size_t i = 0; i < m; i++) {
free(subFilters[i]);
delete hist[i];
}
fft_free(fftInput);
fft_free(fftOutput);
free(hInputs);
free(hOutputs);
free(hist);
}

View File

@@ -0,0 +1,39 @@
#ifndef _CHANNELIZER_BASE_H_
#define _CHANNELIZER_BASE_H_
class ChannelizerBase {
protected:
ChannelizerBase(size_t m, size_t blockLen, size_t hLen);
~ChannelizerBase();
/* Channelizer parameters */
size_t m;
size_t hLen;
size_t blockLen;
/* Channelizer filterbank sub-filters */
float **subFilters;
/* Input/Output buffers */
float **hInputs, **hOutputs, **hist;
float *fftInput, *fftOutput;
/* Pointer to opaque FFT instance */
struct fft_hdl *fftHandle;
/* Initializer internals */
bool initFilters();
bool initFFT();
void releaseFilters();
/* Map overlapped FFT and filter I/O buffers */
bool mapBuffers();
/* Buffer length validity checking */
bool checkLen(size_t innerLen, size_t outerLen);
public:
/* Initilize channelizer/synthesis filter internals */
bool init();
};
#endif /* _CHANNELIZER_BASE_H_ */

View File

@@ -1,268 +0,0 @@
/*
* Copyright 2008, 2009, 2010, 2012 Free Software Foundation, Inc.
* Copyright 2013 Alexander Chemeris <Alexander.Chemeris@fairwaves.ru>
*
* This software is distributed under the terms of the GNU Public License.
* See the COPYING file in the main directory for details.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "DriveLoop.h"
#include <Logger.h>
using namespace GSM;
DriveLoop::DriveLoop(int wBasePort, const char *TRXAddress,
RadioInterface *wRadioInterface,
int wChanM, int wC0, int wSamplesPerSymbol,
GSM::Time wTransmitLatency)
: Thread("DriveLoop")
, mClockSocket(wBasePort, TRXAddress, wBasePort + 100)
, mC0(wC0)
{
mChanM = wChanM;
mSamplesPerSymbol = wSamplesPerSymbol;
mRadioInterface = wRadioInterface;
mStartTime = (random() % gHyperframe, 0);
mTransmitDeadlineClock = mStartTime;
mLatencyUpdateTime = mStartTime;
mTransmitLatency = wTransmitLatency;
mLastClockUpdateTime = mStartTime;
mRadioInterface->getClock()->set(mStartTime);
// generate pulse and setup up signal processing library
gsmPulse = generateGSMPulse(2, mSamplesPerSymbol);
LOG(DEBUG) << "gsmPulse: " << *gsmPulse;
sigProcLibSetup(mSamplesPerSymbol);
txFullScale = mRadioInterface->fullScaleInputValue();
// initialize filler tables with dummy bursts on C0, empty bursts otherwise
for (int i = 0; i < 8; i++) {
signalVector* modBurst = modulateBurst(gDummyBurst, *gsmPulse,
8 + (i % 4 == 0), mSamplesPerSymbol);
scaleVector(*modBurst, txFullScale);
for (int j = 0; j < 102; j++) {
for (int n = 0; n < mChanM; n++) {
if (n == mC0)
fillerTable[n][j][i] = new signalVector(*modBurst);
else
fillerTable[n][j][i] = new signalVector(modBurst->size());
}
}
delete modBurst;
for (int n = 0; n < mChanM; n++) {
fillerModulus[n][i] = 26;
mChanType[n][i] = NONE;
}
}
}
DriveLoop::~DriveLoop()
{
stopThread();
delete gsmPulse;
sigProcLibDestroy();
}
void DriveLoop::pushRadioVector(GSM::Time &nowTime)
{
int i;
radioVector *staleBurst;
radioVector *next;
for (i = 0; i < mChanM; i++) {
// dump stale bursts, if any
while (staleBurst = mTransmitPriorityQueue[i].getStaleBurst(nowTime)) {
// Even if the burst is stale, put it in the fillter table.
// (It might be an idle pattern.)
LOG(NOTICE) << "dumping STALE burst in TRX->USRP interface";
}
int TN = nowTime.TN();
int modFN = nowTime.FN() % fillerModulus[i][nowTime.TN()];
mTxBursts[i] = fillerTable[i][modFN][TN];
mIsFiller[i] = true;
mIsZero[i] = (mChanType[i][TN] == NONE);
// if queue contains data at the desired timestamp, stick it into FIFO
if (next = (radioVector*) mTransmitPriorityQueue[i].getCurrentBurst(nowTime)) {
LOG(DEBUG) << "transmitFIFO: wrote burst " << next << " at time: " << nowTime;
mTxBursts[i] = next;
mIsFiller[i] = false;
mIsZero[i] = false;
}
}
mRadioInterface->driveTransmitRadio(mTxBursts, mIsZero);
for (i = 0; i < mChanM; i++) {
if (!mIsFiller[i])
delete mTxBursts[i];
}
}
void DriveLoop::setModulus(int channel, int timeslot)
{
switch (mChanType[channel][timeslot]) {
case NONE:
case I:
case II:
case III:
case FILL:
fillerModulus[channel][timeslot] = 26;
break;
case IV:
case VI:
case V:
fillerModulus[channel][timeslot] = 51;
break;
//case V:
case VII:
fillerModulus[channel][timeslot] = 102;
break;
default:
break;
}
}
DriveLoop::CorrType DriveLoop::expectedCorrType(int channel, GSM::Time currTime)
{
unsigned burstTN = currTime.TN();
unsigned burstFN = currTime.FN();
switch (mChanType[channel][burstTN]) {
case NONE:
return OFF;
break;
case FILL:
return IDLE;
break;
case I:
return TSC;
/*if (burstFN % 26 == 25)
return IDLE;
else
return TSC;*/
break;
case II:
if (burstFN % 2 == 1)
return IDLE;
else
return TSC;
break;
case III:
return TSC;
break;
case IV:
case VI:
return RACH;
break;
case V: {
int mod51 = burstFN % 51;
if ((mod51 <= 36) && (mod51 >= 14))
return RACH;
else if ((mod51 == 4) || (mod51 == 5))
return RACH;
else if ((mod51 == 45) || (mod51 == 46))
return RACH;
else
return TSC;
break;
}
case VII:
if ((burstFN % 51 <= 14) && (burstFN % 51 >= 12))
return IDLE;
else
return TSC;
break;
case LOOPBACK:
if ((burstFN % 51 <= 50) && (burstFN % 51 >=48))
return IDLE;
else
return TSC;
break;
default:
return OFF;
break;
}
}
void DriveLoop::driveReceiveFIFO()
{
SoftVector *rxBurst = NULL;
int RSSI;
int TOA; // in 1/256 of a symbol
GSM::Time burstTime;
mRadioInterface->driveReceiveRadio();
}
/*
* Features a carefully controlled latency mechanism, to
* assure that transmit packets arrive at the radio/USRP
* before they need to be transmitted.
*
* Deadline clock indicates the burst that needs to be
* pushed into the FIFO right NOW. If transmit queue does
* not have a burst, stick in filler data.
*/
void DriveLoop::driveTransmitFIFO()
{
int i;
RadioClock *radioClock = (mRadioInterface->getClock());
while (radioClock->get() + mTransmitLatency > mTransmitDeadlineClock) {
pushRadioVector(mTransmitDeadlineClock);
mTransmitDeadlineClock.incTN();
}
// FIXME -- This should not be a hard spin.
// But any delay here causes us to throw omni_thread_fatal.
//else radioClock->wait();
}
void DriveLoop::writeClockInterface()
{
char command[50];
// FIXME -- This should be adaptive.
sprintf(command,"IND CLOCK %llu",
(unsigned long long) (mTransmitDeadlineClock.FN() + 2));
LOG(INFO) << "ClockInterface: sending " << command;
mClockSocket.write(command,strlen(command)+1);
mLastClockUpdateTime = mTransmitDeadlineClock;
}
void DriveLoop::runThread()
{
setPriority();
while (isThreadRunning()) {
driveReceiveFIFO();
driveTransmitFIFO();
}
}

View File

@@ -1,188 +0,0 @@
/*
* Copyright 2008, 2012 Free Software Foundation, Inc.
* Copyright 2013 Alexander Chemeris <Alexander.Chemeris@fairwaves.ru>
*
* This software is distributed under the terms of the GNU Public License.
* See the COPYING file in the main directory for details.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
Compilation switches
TRANSMIT_LOGGING write every burst on the given slot to a log
*/
#ifndef _DRIVELOOP_H_
#define _DRIVELOOP_H_
#include "radioInterface.h"
#include "Interthread.h"
#include "GSMCommon.h"
#include "Sockets.h"
#include <sys/types.h>
#include <sys/socket.h>
/** Define this to be the slot number to be logged. */
//#define TRANSMIT_LOGGING 1
/** The Transceiver class, responsible for physical layer of basestation */
class DriveLoop : public Thread {
private:
GSM::Time mTransmitLatency; ///< latency between basestation clock and transmit deadline clock
GSM::Time mLatencyUpdateTime; ///< last time latency was updated
GSM::Time mLastClockUpdateTime; ///< last time clock update was sent up to core
UDPSocket mClockSocket; ///< socket for writing clock updates to GSM core
VectorQueue mTransmitPriorityQueue[CHAN_MAX]; ///< priority queue of transmit bursts received from GSM core
GSM::Time mTransmitDeadlineClock; ///< deadline for pushing bursts into transmit FIFO
GSM::Time mStartTime; ///< random start time of the radio clock
RadioInterface *mRadioInterface; ///< associated radioInterface object
double txFullScale; ///< full scale input to radio
double rxFullScale; ///< full scale output to radio
/** Number of channels supported by the channelizer */
int mChanM;
/** unmodulate a modulated burst */
#ifdef TRANSMIT_LOGGING
void unModulateVector(signalVector wVector);
#endif
/** Push modulated burst into transmit FIFO corresponding to a particular timestamp */
void pushRadioVector(GSM::Time &nowTime);
/** Pull and demodulate a burst from the receive FIFO */
SoftVector *pullRadioVector(GSM::Time &wTime, int &RSSI, int &timingOffset);
signalVector *gsmPulse; ///< the GSM shaping pulse for modulation
int mSamplesPerSymbol; ///< number of samples per GSM symbol
int fillerModulus[CHAN_MAX][8]; ///< modulus values of all timeslots, in frames
signalVector *fillerTable[CHAN_MAX][102][8]; ///< table of modulated filler waveforms for all timeslots
/** Channelizer path for primary ARFCN */
int mC0;
signalVector *mTxBursts[CHAN_MAX];
bool mIsFiller[CHAN_MAX];
bool mIsZero[CHAN_MAX];
public:
/** Transceiver constructor
@param wBasePort base port number of UDP sockets
@param TRXAddress IP address of the TRX manager, as a string
@param wSamplesPerSymbol number of samples per GSM symbol
@param wTransmitLatency initial setting of transmit latency
@param radioInterface associated radioInterface object
*/
DriveLoop(int wBasePort, const char *TRXAddress,
RadioInterface *wRadioInterface,
int wChanM = 1, int wC0 = 0,
int wSamplesPerSymbol = SAMPSPERSYM,
GSM::Time wTransmitLatency = GSM::Time(3, 0));
/** Destructor */
~DriveLoop();
VectorQueue *priorityQueue(int m) { return &mTransmitPriorityQueue[m]; }
/** Codes for burst types of received bursts*/
typedef enum {
OFF, ///< timeslot is off
TSC, ///< timeslot should contain a normal burst
RACH, ///< timeslot should contain an access burst
IDLE ///< timeslot is an idle (or dummy) burst
} CorrType;
/** Codes for channel combinations */
typedef enum {
FILL, ///< Channel is transmitted, but unused
I, ///< TCH/FS
II, ///< TCH/HS, idle every other slot
III, ///< TCH/HS
IV, ///< FCCH+SCH+CCCH+BCCH, uplink RACH
V, ///< FCCH+SCH+CCCH+BCCH+SDCCH/4+SACCH/4, uplink RACH+SDCCH/4
VI, ///< CCCH+BCCH, uplink RACH
VII, ///< SDCCH/8 + SACCH/8
NONE, ///< Channel is inactive, default
LOOPBACK ///< similar go VII, used in loopback testing
} ChannelCombination;
/** Set modulus for specific timeslot */
void setModulus(int channel, int timeslot);
/** return the expected burst type for the specified timestamp */
CorrType expectedCorrType(int channel, GSM::Time currTime);
void setTimeslot(int m, int timeslot, ChannelCombination comb)
{
mChanType[m][timeslot] = comb;
}
GSM::Time getStartTime() { return mStartTime; }
GSM::Time getLastClockUpdate() { return mLastClockUpdateTime; }
GSM::Time getDeadlineClock() { return mTransmitDeadlineClock; }
/** send messages over the clock socket */
void writeClockInterface(void);
private:
ChannelCombination mChanType[CHAN_MAX][8]; ///< channel types for all timeslots
protected:
/** drive reception and demodulation of GSM bursts */
void driveReceiveFIFO();
/** drive transmission of GSM bursts */
void driveTransmitFIFO();
/** drive handling of control messages from GSM core */
void driveControl();
/**
drive modulation and sorting of GSM bursts from GSM core
@return true if a burst was transferred successfully
*/
bool driveTransmitPriorityQueue();
virtual void runThread();
void reset();
/** set priority on current thread */
void setPriority() { mRadioInterface->setPriority(); }
};
/** FIFO thread loop */
void *RadioDriveLoopAdapter(DriveLoop *);
#endif /* _DRIVELOOP_H_ */

View File

@@ -1,146 +0,0 @@
/*
* Copyright 2008, 2009 Free Software Foundation, Inc.
*
* This software is distributed under the terms of the GNU Public License.
* See the COPYING file in the main directory for details.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
Compilation Flags
SWLOOPBACK compile for software loopback testing
*/
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include "Threads.h"
#include "DummyLoad.h"
#include <Logger.h>
using namespace std;
int DummyLoad::loadBurst(short *wDummyBurst, int len) {
dummyBurst = wDummyBurst;
dummyBurstSz = len;
}
DummyLoad::DummyLoad (double _desiredSampleRate)
{
LOG(INFO) << "creating USRP device...";
sampleRate = _desiredSampleRate;
}
void DummyLoad::updateTime(void) {
gettimeofday(&currTime,NULL);
double timeElapsed = (currTime.tv_sec - startTime.tv_sec)*1.0e6 +
(currTime.tv_usec - startTime.tv_usec);
currstamp = (TIMESTAMP) floor(timeElapsed/(1.0e6/sampleRate));
}
bool DummyLoad::make(bool wSkipRx)
{
samplesRead = 0;
samplesWritten = 0;
return true;
}
bool DummyLoad::start()
{
LOG(INFO) << "starting USRP...";
underrun = false;
gettimeofday(&startTime,NULL);
dummyBurstCursor = 0;
return true;
}
bool DummyLoad::stop()
{
return true;
}
// NOTE: Assumes sequential reads
int DummyLoad::readSamples(short *buf, int len, bool *overrun,
TIMESTAMP timestamp,
bool *wUnderrun,
unsigned *RSSI)
{
updateTime();
underrunLock.lock();
*wUnderrun = underrun;
underrunLock.unlock();
if (currstamp+len < timestamp) {
usleep(100);
return 0;
}
else if (currstamp < timestamp) {
usleep(100);
return 0;
}
else if (timestamp+len < currstamp) {
memcpy(buf,dummyBurst+dummyBurstCursor*2,sizeof(short)*2*(dummyBurstSz-dummyBurstCursor));
int retVal = dummyBurstSz-dummyBurstCursor;
dummyBurstCursor = 0;
return retVal;
}
else if (timestamp + len > currstamp) {
int amount = timestamp + len - currstamp;
if (amount < dummyBurstSz-dummyBurstCursor) {
memcpy(buf,dummyBurst+dummyBurstCursor*2,sizeof(short)*2*amount);
dummyBurstCursor += amount;
return amount;
}
else {
memcpy(buf,dummyBurst+dummyBurstCursor*2,sizeof(short)*2*(dummyBurstSz-dummyBurstCursor));
int retVal = dummyBurstSz-dummyBurstCursor;
dummyBurstCursor = 0;
return retVal;
}
}
return 0;
}
int DummyLoad::writeSamples(short *buf, int len, bool *wUnderrun,
unsigned long long timestamp,
bool isControl)
{
updateTime();
underrunLock.lock();
underrun |= (currstamp+len < timestamp);
underrunLock.unlock();
return len;
}
bool DummyLoad::updateAlignment(TIMESTAMP timestamp)
{
return true;
}
bool DummyLoad::setTxFreq(double wFreq) { return true;};
bool DummyLoad::setRxFreq(double wFreq) { return true;};

View File

@@ -1,132 +0,0 @@
/*
* Copyright 2008 Free Software Foundation, Inc.
*
* This software is distributed under the terms of the GNU Public License.
* See the COPYING file in the main directory for details.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "radioDevice.h"
#include <sys/time.h>
#include <math.h>
#include <string>
#include <iostream>
/** A class to handle a USRP rev 4, with a two RFX900 daughterboards */
class DummyLoad: public RadioDevice {
private:
double sampleRate; ///< the desired sampling rate
unsigned long long samplesRead; ///< number of samples read from USRP
unsigned long long samplesWritten; ///< number of samples sent to USRP
Mutex underrunLock;
struct timeval startTime, currTime;
TIMESTAMP currstamp;
short *dummyBurst;
int dummyBurstSz;
int dummyBurstCursor;
bool underrun;
void updateTime(void);
public:
/** Object constructor */
DummyLoad (double _desiredSampleRate);
int loadBurst(short *wDummyBurst, int len);
/** Instantiate the USRP */
bool make(bool skipRx = false);
/** Start the USRP */
bool start();
/** Stop the USRP */
bool stop();
/**
Read samples from the USRP.
@param buf preallocated buf to contain read result
@param len number of samples desired
@param overrun Set if read buffer has been overrun, e.g. data not being read fast enough
@param timestamp The timestamp of the first samples to be read
@param underrun Set if USRP does not have data to transmit, e.g. data not being sent fast enough
@param RSSI The received signal strength of the read result
@return The number of samples actually read
*/
int readSamples(short *buf, int len, bool *overrun,
TIMESTAMP timestamp = 0xffffffff,
bool *underrun = NULL,
unsigned *RSSI = NULL);
/**
Write samples to the USRP.
@param buf Contains the data to be written.
@param len number of samples to write.
@param underrun Set if USRP does not have data to transmit, e.g. data not being sent fast enough
@param timestamp The timestamp of the first sample of the data buffer.
@param isControl Set if data is a control packet, e.g. a ping command
@return The number of samples actually written
*/
int writeSamples(short *buf, int len, bool *underrun,
TIMESTAMP timestamp = 0xffffffff,
bool isControl = false);
/** Update the alignment between the read and write timestamps */
bool updateAlignment(TIMESTAMP timestamp);
/** Set the transmitter frequency */
bool setTxFreq(double wFreq);
/** Set the receiver frequency */
bool setRxFreq(double wFreq);
/** Returns the starting write Timestamp*/
TIMESTAMP initialWriteTimestamp(void) { return 20000;}
/** Returns the starting read Timestamp*/
TIMESTAMP initialReadTimestamp(void) { return 20000;}
/** returns the full-scale transmit amplitude **/
double fullScaleInputValue() {return 13500.0;}
/** returns the full-scale receive amplitude **/
double fullScaleOutputValue() {return 9450.0;}
/** Return internal status values */
inline double getTxFreq() { return 0;}
inline double getRxFreq() { return 0;}
inline double getSampleRate() {return sampleRate;}
inline double numberRead() { return samplesRead; }
inline double numberWritten() { return samplesWritten;}
};

View File

@@ -21,20 +21,23 @@
include $(top_srcdir)/Makefile.common
#UHD wins if both are defined
if UHD
AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) $(UHD_CFLAGS)
else
if USRP1
AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) $(USRP_CFLAGS)
else
#we should never be here, as this doesn't build if one of the above
#doesn't exist
AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES)
endif
endif
AM_CPPFLAGS = -Wall $(STD_DEFINES_AND_INCLUDES) -I${srcdir}/common
AM_CXXFLAGS = -ldl -lpthread
SUBDIRS = arm x86
if ARCH_ARM
ARCH_LA = arm/libarch.la
else
ARCH_LA = x86/libarch.la
endif
if USRP1
AM_CPPFLAGS += $(USRP_CFLAGS)
else
AM_CPPFLAGS += $(UHD_CFLAGS)
endif
rev2dir = $(datadir)/usrp/rev2
rev4dir = $(datadir)/usrp/rev4
@@ -51,17 +54,25 @@ COMMON_SOURCES = \
radioInterface.cpp \
radioVector.cpp \
radioClock.cpp \
radioBuffer.cpp \
sigProcLib.cpp \
DriveLoop.cpp \
signalVector.cpp \
Transceiver.cpp \
DummyLoad.cpp
ChannelizerBase.cpp \
Channelizer.cpp \
Synthesis.cpp \
common/fft.c
libtransceiver_la_SOURCES = \
$(COMMON_SOURCES)
$(COMMON_SOURCES) \
Resampler.cpp \
radioInterfaceResamp.cpp \
radioInterfaceMulti.cpp
noinst_PROGRAMS = \
transceiver \
sigProcLibTest
bin_PROGRAMS = \
osmo-trx \
osmo-trx-gen \
osmo-trx-dec
noinst_HEADERS = \
Complex.h \
@@ -69,46 +80,46 @@ noinst_HEADERS = \
radioVector.h \
radioClock.h \
radioDevice.h \
radioBuffer.h \
sigProcLib.h \
signalVector.h \
Transceiver.h \
USRPDevice.h \
DummyLoad.h \
rcvLPF_651.h \
sendLPF_961.h
Resampler.h \
ChannelizerBase.h \
Channelizer.h \
Synthesis.h \
common/convolve.h \
common/convert.h \
common/scale.h \
common/mult.h \
common/fft.h
transceiver_SOURCES = multiTRX.cpp
transceiver_LDADD = \
osmo_trx_SOURCES = osmo-trx.cpp
osmo_trx_LDADD = \
libtransceiver.la \
$(ARCH_LA) \
$(GSM_LA) \
$(COMMON_LA) $(SQLITE3_LIBS)
osmo_trx_gen_SOURCES = osmo-trx-gen.cpp
osmo_trx_gen_LDADD = \
libtransceiver.la \
$(ARCH_LA) \
$(GSM_LA) \
$(COMMON_LA) $(SQLITE_LA)
sigProcLibTest_SOURCES = sigProcLibTest.cpp
sigProcLibTest_LDADD = \
osmo_trx_dec_SOURCES = osmo-trx-dec.cpp
osmo_trx_dec_LDADD = \
libtransceiver.la \
$(ARCH_LA) \
$(GSM_LA) \
$(COMMON_LA) $(SQLITE_LA)
#uhd wins
if UHD
libtransceiver_la_SOURCES += UHDDevice.cpp
transceiver_LDADD += $(UHD_LIBS)
sigProcLibTest_LDADD += $(UHD_LIBS)
else
if USRP1
if USRP1
libtransceiver_la_SOURCES += USRPDevice.cpp
transceiver_LDADD += $(USRP_LIBS)
sigProcLibTest_LDADD += $(USRP_LIBS)
osmo_trx_LDADD += $(USRP_LIBS)
else
#we should never be here, as one of the above mustbe defined for us to build
libtransceiver_la_SOURCES += UHDDevice.cpp
osmo_trx_LDADD += $(UHD_LIBS) $(FFTWF_LIBS)
endif
endif
MOSTLYCLEANFILES +=
#radioInterface.cpp
#ComplexTest.cpp
#sigProcLibTest.cpp
#sweepGenerator.cpp
#testRadio.cpp

View File

@@ -1,15 +0,0 @@
Basic model:
Have channel H = {h_0, h_1, ..., h_{K-1}}.
Have received sequence Y = {y_0, ..., y_{K+N}}.
Have transmitted sequence X = {x_0, ..., x_{N-1}}.
Denote state S_n = {x_n, x_{n-1}, ..., x_{n-L}}.
Define a bag as an unordered collection with two operations, add and take.
We have three bags:
S: a bag of survivors.
F: a bag of available data structures.
At time n, start with a non-empty bag S of survivors from time n-1.
Take a member out of S, and create all possible branches and their corresponding metrics. If metric ratio is above T, discard branch. Otherwise, check branch against entry in pruning table P. If branch metric is smaller than the existing entry's metric in P, then replace entry with branch. Otherwise, discard branch.
Once all possible branches of S have been created and pruned, S should be empty.Empty pruning table back into S, thus P is now empty. Repeat.

View File

@@ -0,0 +1,224 @@
/*
* Rational Sample Rate Conversion
* Copyright (C) 2012, 2013 Thomas Tsou <tom@tsou.cc>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <malloc.h>
#include <iostream>
#include "Resampler.h"
extern "C" {
#include "convolve.h"
}
#ifndef M_PI
#define M_PI 3.14159265358979323846264338327f
#endif
#define MAX_OUTPUT_LEN 4096
static float sinc(float x)
{
if (x == 0.0)
return 0.9999999999;
return sin(M_PI * x) / (M_PI * x);
}
bool Resampler::initFilters(float bw)
{
size_t proto_len = p * filt_len;
float *proto, val, cutoff;
float sum = 0.0f, scale = 0.0f;
float midpt = (float) (proto_len - 1.0) / 2.0;
/*
* Allocate partition filters and the temporary prototype filter
* according to numerator of the rational rate. Coefficients are
* real only and must be 16-byte memory aligned for SSE usage.
*/
proto = new float[proto_len];
if (!proto)
return false;
partitions = (float **) malloc(sizeof(float *) * p);
if (!partitions) {
delete[] proto;
return false;
}
for (size_t i = 0; i < p; i++) {
partitions[i] = (float *)
memalign(16, filt_len * 2 * sizeof(float));
}
/*
* Generate the prototype filter with a Blackman-harris window.
* Scale coefficients with DC filter gain set to unity divided
* by the number of filter partitions.
*/
float a0 = 0.35875;
float a1 = 0.48829;
float a2 = 0.14128;
float a3 = 0.01168;
if (p > q)
cutoff = (float) p;
else
cutoff = (float) q;
for (size_t i = 0; i < proto_len; i++) {
proto[i] = sinc(((float) i - midpt) / cutoff * bw);
proto[i] *= a0 -
a1 * cos(2 * M_PI * i / (proto_len - 1)) +
a2 * cos(4 * M_PI * i / (proto_len - 1)) -
a3 * cos(6 * M_PI * i / (proto_len - 1));
sum += proto[i];
}
scale = p / sum;
/* Populate filter partitions from the prototype filter */
for (size_t i = 0; i < filt_len; i++) {
for (size_t n = 0; n < p; n++) {
partitions[n][2 * i + 0] = proto[i * p + n] * scale;
partitions[n][2 * i + 1] = 0.0f;
}
}
/* For convolution, we store the filter taps in reverse */
for (size_t n = 0; n < p; n++) {
for (size_t i = 0; i < filt_len / 2; i++) {
val = partitions[n][2 * i];
partitions[n][2 * i] = partitions[n][2 * (filt_len - 1 - i)];
partitions[n][2 * (filt_len - 1 - i)] = val;
}
}
delete[] proto;
return true;
}
void Resampler::releaseFilters()
{
if (partitions) {
for (size_t i = 0; i < p; i++)
free(partitions[i]);
}
free(partitions);
partitions = NULL;
}
static bool check_vec_len(int in_len, int out_len, int p, int q)
{
if (in_len % q) {
std::cerr << "Invalid input length " << in_len
<< " is not multiple of " << q << std::endl;
return false;
}
if (out_len % p) {
std::cerr << "Invalid output length " << out_len
<< " is not multiple of " << p << std::endl;
return false;
}
if ((in_len / q) != (out_len / p)) {
std::cerr << "Input/output block length mismatch" << std::endl;
std::cerr << "P = " << p << ", Q = " << q << std::endl;
std::cerr << "Input len: " << in_len << std::endl;
std::cerr << "Output len: " << out_len << std::endl;
return false;
}
if (out_len > MAX_OUTPUT_LEN) {
std::cerr << "Block length of " << out_len
<< " exceeds max of " << MAX_OUTPUT_LEN << std::endl;
return false;
}
return true;
}
void Resampler::computePath()
{
for (int i = 0; i < MAX_OUTPUT_LEN; i++) {
in_index[i] = (q * i) / p;
out_path[i] = (q * i) % p;
}
}
int Resampler::rotate(const float *in, size_t in_len, float *out, size_t out_len)
{
int n, path;
if (!check_vec_len(in_len, out_len, p, q))
return -1;
/* Generate output from precomputed input/output paths */
for (size_t i = 0; i < out_len; i++) {
n = in_index[i];
path = out_path[i];
convolve_real(in, in_len,
partitions[path], filt_len,
&out[2 * i], out_len - i,
n, 1, 1, 0);
}
return out_len;
}
bool Resampler::init(float bw)
{
/* Filterbank filter internals */
if (!initFilters(bw))
return false;
/* Precompute filterbank paths */
in_index = new size_t[MAX_OUTPUT_LEN];
out_path = new size_t[MAX_OUTPUT_LEN];
computePath();
return true;
}
size_t Resampler::len()
{
return filt_len;
}
Resampler::Resampler(size_t p, size_t q, size_t filt_len)
: in_index(NULL), out_path(NULL), partitions(NULL)
{
this->p = p;
this->q = q;
this->filt_len = filt_len;
}
Resampler::~Resampler()
{
releaseFilters();
delete in_index;
delete out_path;
}

View File

@@ -0,0 +1,76 @@
/*
* Rational Sample Rate Conversion
* Copyright (C) 2012, 2013 Thomas Tsou <tom@tsou.cc>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _RESAMPLER_H_
#define _RESAMPLER_H_
class Resampler {
public:
/* Constructor for rational sample rate conversion
* @param p numerator of resampling ratio
* @param q denominator of resampling ratio
* @param filt_len length of each polyphase subfilter
*/
Resampler(size_t p, size_t q, size_t filt_len = 16);
~Resampler();
/* Initilize resampler filterbank.
* @param bw bandwidth factor on filter generation (pre-window)
* @return false on error, zero otherwise
*
* Automatic setting is to compute the filter to prevent aliasing with
* a Blackman-Harris window. Adjustment is made through a bandwith
* factor to shift the cutoff and/or the constituent filter lengths.
* Calculation of specific rolloff factors or 3-dB cutoff points is
* left as an excersize for the reader.
*/
bool init(float bw = 1.0f);
/* Rotate "commutator" and drive samples through filterbank
* @param in continuous buffer of input complex float values
* @param in_len input buffer length
* @param out continuous buffer of output complex float values
* @param out_len output buffer length
* @return number of samples outputted, negative on error
*
* Input and output vector lengths must of be equal multiples of the
* rational conversion rate denominator and numerator respectively.
*/
int rotate(const float *in, size_t in_len, float *out, size_t out_len);
/* Get filter length
* @return number of taps in each filter partition
*/
size_t len();
private:
size_t p;
size_t q;
size_t filt_len;
size_t *in_index;
size_t *out_path;
float **partitions;
bool initFilters(float bw);
void releaseFilters();
void computePath();
};
#endif /* _RESAMPLER_H_ */

View File

@@ -0,0 +1,121 @@
/*
* Polyphase synthesis filter
*
* Copyright (C) 2012-2014 Tom Tsou <tom@tsou.cc>
* Copyright (C) 2015 Ettus Research LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* See the COPYING file in the main directory for details.
*/
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include <cstdio>
#include "Logger.h"
#include "Synthesis.h"
extern "C" {
#include "common/fft.h"
#include "common/convolve.h"
}
static void interleave(float **in, size_t ilen,
float *out, size_t m)
{
size_t i, n;
for (i = 0; i < ilen; i++) {
for (n = 0; n < m; n++) {
out[2 * (i * m + n) + 0] = in[n][2 * i + 0];
out[2 * (i * m + n) + 1] = in[n][2 * i + 1];
}
}
}
size_t Synthesis::inputLen() const
{
return blockLen;
}
size_t Synthesis::outputLen() const
{
return blockLen * m;
}
float *Synthesis::inputBuffer(size_t chan) const
{
if (chan >= m)
return NULL;
return hOutputs[chan];
}
bool Synthesis::resetBuffer(size_t chan)
{
if (chan >= m)
return false;
memset(hOutputs[chan], 0, blockLen * 2 * sizeof(float));
return true;
}
/*
* Implementation based on material found in:
*
* "harris, fred, Multirate Signal Processing, Upper Saddle River, NJ,
* Prentice Hall, 2006."
*/
bool Synthesis::rotate(float *out, size_t len)
{
size_t hSize = 2 * hLen * sizeof(float);
if (!checkLen(blockLen, len)) {
std::cout << "Length fail" << std::endl;
exit(1);
return false;
}
cxvec_fft(fftHandle);
/*
* Convolve through filterbank while applying and saving sample history
*/
for (size_t i = 0; i < m; i++) {
memcpy(&hInputs[i][2 * -hLen], hist[i], hSize);
memcpy(hist[i], &hInputs[i][2 * (blockLen - hLen)], hSize);
convolve_real(hInputs[i], blockLen,
subFilters[i], hLen,
hOutputs[i], blockLen,
0, blockLen, 1, 0);
}
/* Interleave into output vector */
interleave(hOutputs, blockLen, out, m);
return true;
}
Synthesis::Synthesis(size_t m, size_t blockLen, size_t hLen)
: ChannelizerBase(m, blockLen, hLen)
{
}
Synthesis::~Synthesis()
{
}

View File

@@ -0,0 +1,35 @@
#ifndef _SYNTHESIS_H_
#define _SYNTHESIS_H_
#include "ChannelizerBase.h"
class Synthesis : public ChannelizerBase {
public:
/** Constructor for synthesis filterbank
@param m number of physical channels
@param blockLen number of samples per output of each iteration
@param hLen number of taps in each constituent filter path
*/
Synthesis(size_t m, size_t blockLen, size_t hLen = 16);
~Synthesis();
/* Return required input and output buffer lengths */
size_t inputLen() const;
size_t outputLen() const;
/** Rotate "output commutator" and drive samples through filterbank
@param out complex output vector
@param oLen number of samples in buffer (must match block length * m)
@return false on error and true otherwise
*/
bool rotate(float *out, size_t oLen);
/** Get buffer for an input path
@param chan channel number of filterbank
@return NULL on error and pointer to buffer otherwise
*/
float *inputBuffer(size_t chan) const;
bool resetBuffer(size_t chan);
};
#endif /* _SYNTHESIS_H_ */

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,5 @@
/*
* Copyright 2008, 2012 Free Software Foundation, Inc.
* Copyright 2013 Alexander Chemeris <Alexander.Chemeris@fairwaves.ru>
* Copyright 2008 Free Software Foundation, Inc.
*
* This software is distributed under the terms of the GNU Public License.
* See the COPYING file in the main directory for details.
@@ -23,14 +22,6 @@
*/
/*
Compilation switches
TRANSMIT_LOGGING write every burst on the given slot to a log
*/
#include "DriveLoop.h"
#include "radioInterface.h"
#include "Interthread.h"
#include "GSMCommon.h"
@@ -39,165 +30,252 @@
#include <sys/types.h>
#include <sys/socket.h>
/** Define this to be the slot number to be logged. */
//#define TRANSMIT_LOGGING 1
class Transceiver;
/** FIFO thread loop */
class FIFOServiceLoopThread : public Thread {
public:
FIFOServiceLoopThread() : Thread("FIFOServiceLoopThread") {}
Thread::ReturnStatus shutdown();
/** Channel descriptor for transceiver object and channel number pair */
struct TransceiverChannel {
TransceiverChannel(Transceiver *trx, int num)
{
this->trx = trx;
this->num = num;
}
protected:
virtual void runThread();
~TransceiverChannel()
{
}
Transceiver *trx;
size_t num;
};
/** control message handler thread loop */
class ControlServiceLoopThread : public Thread {
public:
ControlServiceLoopThread() : Thread("ControlServiceLoopThread") {}
Thread::ReturnStatus shutdown();
/** Internal transceiver state variables */
struct TransceiverState {
TransceiverState();
~TransceiverState();
protected:
virtual void runThread();
};
/* Initialize a multiframe slot in the filler table */
bool init(int filler, size_t sps, float scale, size_t rtsc, unsigned rach_delay);
/** transmit queueing thread loop */
class TransmitPriorityQueueServiceLoopThread : public Thread {
public:
TransmitPriorityQueueServiceLoopThread() : Thread("TransmitPriorityQueueServiceLoopThread") {}
Thread::ReturnStatus shutdown();
int chanType[8];
protected:
virtual void runThread();
/* Last timestamp of each timeslot's channel estimate */
GSM::Time chanEstimateTime[8];
/* The filler table */
signalVector *fillerTable[102][8];
int fillerModulus[8];
bool mRetrans;
/* Most recent channel estimate of all timeslots */
signalVector *chanResponse[8];
/* Most recent DFE feedback filter of all timeslots */
signalVector *DFEForward[8];
signalVector *DFEFeedback[8];
/* Most recent SNR, timing, and channel amplitude estimates */
float SNRestimate[8];
float chanRespOffset[8];
complex chanRespAmplitude[8];
/* Received noise energy levels */
float mNoiseLev;
noiseVector mNoises;
/* Shadowed downlink attenuation */
int mPower;
/* Pseudorandom bit sequence */
PRBS9 mPrbs;
};
/** The Transceiver class, responsible for physical layer of basestation */
class Transceiver {
public:
/** Transceiver constructor
@param wBasePort base port number of UDP sockets
@param TRXAddress IP address of the TRX manager, as a string
@param wSPS number of samples per GSM symbol
@param wTransmitLatency initial setting of transmit latency
@param radioInterface associated radioInterface object
*/
Transceiver(int wBasePort,
const char *TRXAddress,
size_t tx_sps, size_t rx_sps, size_t chans,
GSM::Time wTransmitLatency,
RadioInterface *wRadioInterface,
double wRssiOffset);
/** Destructor */
~Transceiver();
/** Start the control loop */
bool init(int filler, size_t rtsc, unsigned rach_delay, bool edge);
/** attach the radioInterface receive FIFO */
bool receiveFIFO(VectorFIFO *wFIFO, size_t chan)
{
if (chan >= mReceiveFIFO.size())
return false;
mReceiveFIFO[chan] = wFIFO;
return true;
}
/** accessor for number of channels */
size_t numChans() const { return mChans; };
/** Codes for channel combinations */
typedef enum {
FILL, ///< Channel is transmitted, but unused
I, ///< TCH/FS
II, ///< TCH/HS, idle every other slot
III, ///< TCH/HS
IV, ///< FCCH+SCH+CCCH+BCCH, uplink RACH
V, ///< FCCH+SCH+CCCH+BCCH+SDCCH/4+SACCH/4, uplink RACH+SDCCH/4
VI, ///< CCCH+BCCH, uplink RACH
VII, ///< SDCCH/8 + SACCH/8
VIII, ///< TCH/F + FACCH/F + SACCH/M
IX, ///< TCH/F + SACCH/M
X, ///< TCH/FD + SACCH/MD
XI, ///< PBCCH+PCCCH+PDTCH+PACCH+PTCCH
XII, ///< PCCCH+PDTCH+PACCH+PTCCH
XIII, ///< PDTCH+PACCH+PTCCH
NONE, ///< Channel is inactive, default
LOOPBACK ///< similar go VII, used in loopback testing
} ChannelCombination;
enum FillerType {
FILLER_DUMMY,
FILLER_ZERO,
FILLER_NORM_RAND,
FILLER_EDGE_RAND,
FILLER_ACCESS_RAND,
};
private:
DriveLoop *mDriveLoop;
int mBasePort;
std::string mAddr;
int mBasePort; ///< Base port address for all our ports
std::string mTRXAddress; ///< Address of the BTS TRX control interface
UDPSocket mDataSocket; ///< socket for writing to/reading from GSM core
UDPSocket mControlSocket; ///< socket for writing/reading control commands from GSM core
std::vector<UDPSocket *> mDataSockets; ///< socket for writing to/reading from GSM core
std::vector<UDPSocket *> mCtrlSockets; ///< socket for writing/reading control commands from GSM core
UDPSocket mClockSocket; ///< socket for writing clock updates to GSM core
VectorQueue *mTransmitPriorityQueue; ///< priority queue of transmit bursts received from GSM core
VectorFIFO* mReceiveFIFO; ///< radioInterface FIFO of receive bursts
std::vector<VectorQueue> mTxPriorityQueues; ///< priority queue of transmit bursts received from GSM core
std::vector<VectorFIFO *> mReceiveFIFO; ///< radioInterface FIFO of receive bursts
friend class FIFOServiceLoopThread;
FIFOServiceLoopThread mFIFOServiceLoop; ///< thread to push/pull bursts into transmit/receive FIFO
friend class ControlServiceLoopThread;
ControlServiceLoopThread mControlServiceLoop; ///< thread to process control messages from GSM core
friend class TransmitPriorityQueueServiceLoopThread;
TransmitPriorityQueueServiceLoopThread mTransmitPriorityQueueServiceLoop;///< thread to process transmit bursts from GSM core
std::vector<Thread *> mRxServiceLoopThreads; ///< thread to pull bursts into receive FIFO
Thread *mRxLowerLoopThread; ///< thread to pull bursts into receive FIFO
Thread *mTxLowerLoopThread; ///< thread to push bursts into transmit FIFO
std::vector<Thread *> mControlServiceLoopThreads; ///< thread to process control messages from GSM core
std::vector<Thread *> mTxPriorityQueueServiceLoopThreads; ///< thread to process transmit bursts from GSM core
int mChannel; ///< channelizer attach number between 0 and 'M-1'
GSM::Time mTransmitLatency; ///< latency between basestation clock and transmit deadline clock
GSM::Time mLatencyUpdateTime; ///< last time latency was updated
GSM::Time mTransmitDeadlineClock; ///< deadline for pushing bursts into transmit FIFO
GSM::Time mLastClockUpdateTime; ///< last time clock update was sent up to core
RadioInterface *mRadioInterface; ///< associated radioInterface object
double txFullScale; ///< full scale input to radio
double rxFullScale; ///< full scale output to radio
/** unmodulate a modulated burst */
#ifdef TRANSMIT_LOGGING
void unModulateVector(signalVector wVector);
#endif
double rssiOffset; ///< RSSI to dBm conversion offset
/** modulate and add a burst to the transmit queue */
void addRadioVector(BitVector &burst,
int RSSI,
GSM::Time &wTime);
void addRadioVector(size_t chan, BitVector &bits,
int RSSI, GSM::Time &wTime);
/** Update filler table */
void updateFillerTable(size_t chan, radioVector *burst);
/** Push modulated burst into transmit FIFO corresponding to a particular timestamp */
void pushRadioVector(GSM::Time &nowTime);
/** Pull and demodulate a burst from the receive FIFO */
SoftVector *pullRadioVector(GSM::Time &wTime,
int &RSSI,
int &timingOffset);
/** Pull and demodulate a burst from the receive FIFO */
SoftVector *pullRadioVector(GSM::Time &wTime, double &RSSI, bool &isRssiValid,
double &timingOffset, double &noise,
size_t chan = 0);
/** Set modulus for specific timeslot */
void setModulus(size_t timeslot, size_t chan);
/** return the expected burst type for the specified timestamp */
CorrType expectedCorrType(GSM::Time currTime, size_t chan);
/** send messages over the clock socket */
void writeClockInterface(void);
void pullFIFO(void); ///< blocking call on receive FIFO
int mSPSTx; ///< number of samples per Tx symbol
int mSPSRx; ///< number of samples per Rx symbol
size_t mChans;
signalVector *gsmPulse; ///< the GSM shaping pulse for modulation
int mSamplesPerSymbol; ///< number of samples per GSM symbol
bool mOn; ///< flag to indicate that transceiver is powered on
bool mRunning; ///< flag to indicate control loop is running
bool mPrimary; ///< flag to indicate C0 channel
bool mEdge;
bool mOn; ///< flag to indicate that transceiver is powered on
bool mHandover[8][8]; ///< expect handover to the timeslot/subslot
double mTxFreq; ///< the transmit frequency
double mRxFreq; ///< the receive frequency
double mFreqOffset; ///< RF frequency offset
int mPower; ///< the transmit power in dB
double mEnergyThreshold; ///< threshold to determine if received data is potentially a GSM burst
GSM::Time prevFalseDetectionTime; ///< last timestamp of a false energy detection
unsigned mMaxExpectedDelay; ///< maximum expected time-of-arrival offset in GSM symbols
unsigned mTSC; ///< the midamble sequence code
unsigned mMaxExpectedDelayAB; ///< maximum expected time-of-arrival offset in GSM symbols for Access Bursts (RACH)
unsigned mMaxExpectedDelayNB; ///< maximum expected time-of-arrival offset in GSM symbols for Normal Bursts
unsigned mWriteBurstToDiskMask; ///< debug: bitmask to indicate which timeslots to dump to disk
GSM::Time channelEstimateTime[8]; ///< last timestamp of each timeslot's channel estimate
signalVector *channelResponse[8]; ///< most recent channel estimate of all timeslots
float SNRestimate[8]; ///< most recent SNR estimate of all timeslots
signalVector *DFEForward[8]; ///< most recent DFE feedforward filter of all timeslots
signalVector *DFEFeedback[8]; ///< most recent DFE feedback filter of all timeslots
float chanRespOffset[8]; ///< most recent timing offset, e.g. TOA, of all timeslots
complex chanRespAmplitude[8]; ///< most recent channel amplitude of all timeslots
std::vector<TransceiverState> mStates;
static int mTSC; ///< the midamble sequence code
/** Start and stop I/O threads through the control socket API */
bool start();
void stop();
public:
/** Transceiver constructor
@param wBasePort base port number of UDP sockets
@param TRXAddress IP address of the TRX manager, as a string
@param wSamplesPerSymbol number of samples per GSM symbol
@param wTransmitLatency initial setting of transmit latency
@param radioInterface associated radioInterface object
*/
Transceiver(int wBasePort, const char *TRXAddress,
DriveLoop *wDriveLoop, RadioInterface *wRadioInterface,
int wSamplesPerSymbol = SAMPSPERSYM,
int wChannel = 0, bool wPrimary = true);
/** Destructor */
~Transceiver();
/** start the Transceiver */
void start();
/** shutdown (teardown threads) the Transceiver */
void shutdown();
/** Protect destructor accessable stop call */
Mutex mLock;
protected:
/** drive lower receive I/O and burst generation */
void driveReceiveRadio();
/** drive reception and demodulation of GSM bursts */
void driveReceiveFIFO();
/** drive demodulation of GSM bursts */
void driveReceiveFIFO(size_t chan);
/** drive transmission of GSM bursts */
void driveTransmitFIFO();
void driveTxFIFO();
/** drive handling of control messages from GSM core */
void driveControl();
void driveControl(size_t chan);
/**
drive modulation and sorting of GSM bursts from GSM core
@return true if a burst was transferred successfully
*/
bool driveTransmitPriorityQueue();
bool driveTxPriorityQueue(size_t chan);
friend void *RxUpperLoopAdapter(TransceiverChannel *);
friend void *TxUpperLoopAdapter(TransceiverChannel *);
friend void *RxLowerLoopAdapter(Transceiver *);
friend void *TxLowerLoopAdapter(Transceiver *);
friend void *ControlServiceLoopAdapter(TransceiverChannel *);
void reset();
/** return transceiver on/off status */
bool on() { return mOn; }
/** return control loop operational status */
bool running() { return mRunning; }
/** return the drive loop pointer */
DriveLoop *getDriveLoop() { return mDriveLoop; }
/** set priority on current thread */
void setPriority() { mRadioInterface->setPriority(); }
void setPriority(float prio = 0.5) { mRadioInterface->setPriority(prio); }
void logRxBurst(size_t chan, SoftVector *burst, GSM::Time time, double dbm,
double rssi, double noise, double toa);
};
void *RxUpperLoopAdapter(TransceiverChannel *);
/** Main drive threads */
void *RxLowerLoopAdapter(Transceiver *);
void *TxLowerLoopAdapter(Transceiver *);
/** control message handler thread loop */
void *ControlServiceLoopAdapter(TransceiverChannel *);
/** transmit queueing thread loop */
void *TxUpperLoopAdapter(TransceiverChannel *);

File diff suppressed because it is too large Load Diff

View File

@@ -59,14 +59,28 @@ const dboardConfigType dboardConfig = TXA_RXB;
const double USRPDevice::masterClockRate = 52.0e6;
USRPDevice::USRPDevice(int sps, bool skipRx)
: skipRx(skipRx)
USRPDevice::USRPDevice(size_t sps)
{
LOG(INFO) << "creating USRP device...";
this->sps = sps;
decimRate = (unsigned int) round(masterClockRate/((GSMRATE) * (double) sps));
actualSampleRate = masterClockRate/decimRate;
rxGain = 0;
/*
* Undetermined delay b/w ping response timestamp and true
* receive timestamp. Values are empirically measured. With
* split sample rate Tx/Rx - 4/1 sps we need to need to
* compensate for advance rather than delay.
*/
if (sps == 1)
pingOffset = 272;
else if (sps == 4)
pingOffset = 269 - 7500;
else
pingOffset = 0;
#ifdef SWLOOPBACK
samplePeriod = 1.0e6/actualSampleRate;
loopbackBufferSize = 0;
@@ -75,7 +89,7 @@ USRPDevice::USRPDevice(int sps, bool skipRx)
#endif
}
int USRPDevice::open(const std::string &)
int USRPDevice::open(const std::string &, int, bool)
{
writeLock.unlock();
@@ -86,14 +100,13 @@ int USRPDevice::open(const std::string &)
m_uRx.reset();
if (!skipRx) {
try {
m_uRx = usrp_standard_rx_sptr(usrp_standard_rx::make(0,decimRate,1,-1,
usrp_standard_rx::FPGA_MODE_NORMAL,
1024,16*8,rbf));
#ifdef HAVE_LIBUSRP_3_2
m_uRx = usrp_standard_rx_sptr(usrp_standard_rx::make(
0, decimRate * sps, 1, -1,
usrp_standard_rx::FPGA_MODE_NORMAL,
1024, 16 * 8, rbf));
m_uRx->set_fpga_master_clock_freq(masterClockRate);
#endif
}
catch(...) {
LOG(ALERT) << "make failed on Rx";
m_uRx.reset();
@@ -110,13 +123,12 @@ int USRPDevice::open(const std::string &)
}
try {
m_uTx = usrp_standard_tx_sptr(usrp_standard_tx::make(0,decimRate*2,1,-1,
1024,16*8,rbf));
#ifdef HAVE_LIBUSRP_3_2
m_uTx = usrp_standard_tx_sptr(usrp_standard_tx::make(
0, decimRate * 2, 1, -1,
1024, 16 * 8, rbf));
m_uTx->set_fpga_master_clock_freq(masterClockRate);
#endif
}
catch(...) {
LOG(ALERT) << "make failed on Tx";
m_uTx.reset();
@@ -253,49 +265,66 @@ double USRPDevice::minRxGain()
return m_dbRx->gain_min();
}
double USRPDevice::setTxGain(double dB) {
writeLock.lock();
if (dB > maxTxGain()) dB = maxTxGain();
if (dB < minTxGain()) dB = minTxGain();
double USRPDevice::setTxGain(double dB, size_t chan)
{
if (chan) {
LOG(ALERT) << "Invalid channel " << chan;
return 0.0;
}
LOG(NOTICE) << "Setting TX gain to " << dB << " dB.";
writeLock.lock();
if (dB > maxTxGain())
dB = maxTxGain();
if (dB < minTxGain())
dB = minTxGain();
if (!m_dbTx->set_gain(dB))
LOG(ERR) << "Error setting TX gain";
LOG(NOTICE) << "Setting TX gain to " << dB << " dB.";
writeLock.unlock();
return dB;
if (!m_dbTx->set_gain(dB))
LOG(ERR) << "Error setting TX gain";
writeLock.unlock();
return dB;
}
double USRPDevice::setRxGain(double dB) {
double USRPDevice::setRxGain(double dB, size_t chan)
{
if (chan) {
LOG(ALERT) << "Invalid channel " << chan;
return 0.0;
}
writeLock.lock();
if (dB > maxRxGain()) dB = maxRxGain();
if (dB < minRxGain()) dB = minRxGain();
LOG(NOTICE) << "Setting RX gain to " << dB << " dB.";
dB = 47.0;
if (!m_dbRx->set_gain(dB))
LOG(ERR) << "Error setting RX gain";
writeLock.unlock();
return dB;
writeLock.lock();
if (dB > maxRxGain())
dB = maxRxGain();
if (dB < minRxGain())
dB = minRxGain();
LOG(NOTICE) << "Setting RX gain to " << dB << " dB.";
if (!m_dbRx->set_gain(dB))
LOG(ERR) << "Error setting RX gain";
writeLock.unlock();
return dB;
}
// NOTE: Assumes sequential reads
int USRPDevice::readSamples(short *buf, int len, bool *overrun,
TIMESTAMP timestamp,
bool *underrun,
unsigned *RSSI)
int USRPDevice::readSamples(std::vector<short *> &bufs, int len, bool *overrun,
TIMESTAMP timestamp, bool *underrun, unsigned *RSSI)
{
#ifndef SWLOOPBACK
if (!m_uRx) return 0;
if (!m_uRx)
return 0;
short *buf = bufs[0];
timestamp += timestampOffset;
if (timestamp + len < timeStart) {
@@ -341,7 +370,7 @@ int USRPDevice::readSamples(short *buf, int len, bool *overrun,
uint32_t word2 = usrp_to_host_u32(tmpBuf[2]);
if ((word2 >> 16) == ((0x01 << 8) | 0x02)) {
timestamp -= timestampOffset;
timestampOffset = pktTimestamp - pingTimestamp + PINGOFFSET;
timestampOffset = pktTimestamp - pingTimestamp + pingOffset;
LOG(DEBUG) << "updating timestamp offset to: " << timestampOffset;
timestamp += timestampOffset;
isAligned = true;
@@ -437,17 +466,20 @@ int USRPDevice::readSamples(short *buf, int len, bool *overrun,
#endif
}
int USRPDevice::writeSamples(short *buf, int len, bool *underrun,
unsigned long long timestamp,
bool isControl)
int USRPDevice::writeSamples(std::vector<short *> &bufs, int len,
bool *underrun, unsigned long long timestamp,
bool isControl)
{
writeLock.lock();
#ifndef SWLOOPBACK
if (!m_uTx) return 0;
if (!m_uTx)
return 0;
short *buf = bufs[0];
static uint32_t outData[128*20];
for (int i = 0; i < len*2; i++) {
buf[i] = host_to_usrp_short(buf[i]);
}
@@ -499,7 +531,9 @@ bool USRPDevice::updateAlignment(TIMESTAMP timestamp)
uint32_t *wordPtr = (uint32_t *) data;
*wordPtr = host_to_usrp_u32(*wordPtr);
bool tmpUnderrun;
if (writeSamples((short *) data,1,&tmpUnderrun,timestamp & 0x0ffffffffll,true)) {
std::vector<short *> buf(1, data);
if (writeSamples(buf, 1, &tmpUnderrun, timestamp & 0x0ffffffffll, true)) {
pingTimestamp = timestamp;
return true;
}
@@ -510,10 +544,15 @@ bool USRPDevice::updateAlignment(TIMESTAMP timestamp)
}
#ifndef SWLOOPBACK
bool USRPDevice::setTxFreq(double wFreq)
bool USRPDevice::setTxFreq(double wFreq, size_t chan)
{
usrp_tune_result result;
if (chan) {
LOG(ALERT) << "Invalid channel " << chan;
return false;
}
if (m_uTx->tune(txSubdevSpec.side, m_dbTx, wFreq, &result)) {
LOG(INFO) << "set TX: " << wFreq << std::endl
<< " baseband freq: " << result.baseband_freq << std::endl
@@ -530,10 +569,15 @@ bool USRPDevice::setTxFreq(double wFreq)
}
}
bool USRPDevice::setRxFreq(double wFreq)
bool USRPDevice::setRxFreq(double wFreq, size_t chan)
{
usrp_tune_result result;
if (chan) {
LOG(ALERT) << "Invalid channel " << chan;
return false;
}
if (m_uRx->tune(0, m_dbRx, wFreq, &result)) {
LOG(INFO) << "set RX: " << wFreq << std::endl
<< " baseband freq: " << result.baseband_freq << std::endl
@@ -556,7 +600,8 @@ bool USRPDevice::setTxFreq(double wFreq) { return true;};
bool USRPDevice::setRxFreq(double wFreq) { return true;};
#endif
RadioDevice *RadioDevice::make(int sps, bool skipRx)
RadioDevice *RadioDevice::make(size_t tx_sps, size_t rx_sps,
size_t chans, double)
{
return new USRPDevice(sps, skipRx);
return new USRPDevice(tx_sps);
}

View File

@@ -21,29 +21,17 @@
#include "radioDevice.h"
#ifdef HAVE_LIBUSRP_3_3 // [
# include <usrp/usrp_standard.h>
# include <usrp/usrp_bytesex.h>
# include <usrp/usrp_prims.h>
#else // HAVE_LIBUSRP_3_3 ][
# include "usrp_standard.h"
# include "usrp_bytesex.h"
# include "usrp_prims.h"
#endif // !HAVE_LIBUSRP_3_3 ]
#include <usrp/usrp_standard.h>
#include <usrp/usrp_bytesex.h>
#include <usrp/usrp_prims.h>
#include <sys/time.h>
#include <math.h>
#include <string>
#include <iostream>
/** Define types which are not defined in libusrp-3.1 */
#ifndef HAVE_LIBUSRP_3_2
#include <boost/shared_ptr.hpp>
typedef boost::shared_ptr<usrp_standard_tx> usrp_standard_tx_sptr;
typedef boost::shared_ptr<usrp_standard_rx> usrp_standard_rx_sptr;
#endif // HAVE_LIBUSRP_3_2
/** A class to handle a USRP rev 4, with a two RFX900 daughterboards */
class USRPDevice: public RadioDevice {
@@ -60,6 +48,7 @@ private:
usrp_subdev_spec rxSubdevSpec;
usrp_subdev_spec txSubdevSpec;
int sps;
double actualSampleRate; ///< the actual USRP sampling rate
unsigned int decimRate; ///< the USRP decimation rate
@@ -87,7 +76,8 @@ private:
TIMESTAMP timestampOffset; ///< timestamp offset b/w Tx and Rx blocks
TIMESTAMP latestWriteTimestamp; ///< timestamp of most recent ping command
TIMESTAMP pingTimestamp; ///< timestamp of most recent ping response
static const TIMESTAMP PINGOFFSET = 272; ///< undetermined delay b/w ping response timestamp and true receive timestamp
long long pingOffset;
unsigned long hi32Timestamp;
unsigned long lastPktTimestamp;
@@ -103,19 +93,13 @@ private:
bool firstRead;
#endif
/** Set the transmission frequency */
bool tx_setFreq(double freq, double *actual_freq);
/** Set the receiver frequency */
bool rx_setFreq(double freq, double *actual_freq);
public:
/** Object constructor */
USRPDevice(int sps, bool skipRx);
USRPDevice(size_t sps);
/** Instantiate the USRP */
int open(const std::string &);
int open(const std::string &, int, bool);
/** Start the USRP */
bool start();
@@ -124,7 +108,7 @@ private:
bool stop();
/** Set priority not supported */
void setPriority() { return; }
void setPriority(float prio = 0.5) { }
enum TxWindowType getWindowType() { return TX_WINDOW_USRP1; }
@@ -138,10 +122,9 @@ private:
@param RSSI The received signal strength of the read result
@return The number of samples actually read
*/
int readSamples(short *buf, int len, bool *overrun,
TIMESTAMP timestamp = 0xffffffff,
bool *underrun = NULL,
unsigned *RSSI = NULL);
int readSamples(std::vector<short *> &buf, int len, bool *overrun,
TIMESTAMP timestamp = 0xffffffff, bool *underrun = NULL,
unsigned *RSSI = NULL);
/**
Write samples to the USRP.
@param buf Contains the data to be written.
@@ -151,18 +134,17 @@ private:
@param isControl Set if data is a control packet, e.g. a ping command
@return The number of samples actually written
*/
int writeSamples(short *buf, int len, bool *underrun,
TIMESTAMP timestamp = 0xffffffff,
bool isControl = false);
int writeSamples(std::vector<short *> &bufs, int len, bool *underrun,
TIMESTAMP timestamp = 0xffffffff, bool isControl = false);
/** Update the alignment between the read and write timestamps */
bool updateAlignment(TIMESTAMP timestamp);
/** Set the transmitter frequency */
bool setTxFreq(double wFreq);
bool setTxFreq(double wFreq, size_t chan = 0);
/** Set the receiver frequency */
bool setRxFreq(double wFreq);
bool setRxFreq(double wFreq, size_t chan = 0);
/** Returns the starting write Timestamp*/
TIMESTAMP initialWriteTimestamp(void) { return 20000;}
@@ -177,10 +159,10 @@ private:
double fullScaleOutputValue() {return 9450.0;}
/** sets the receive chan gain, returns the gain setting **/
double setRxGain(double dB);
double setRxGain(double dB, size_t chan = 0);
/** get the current receive gain */
double getRxGain(void) {return rxGain;}
double getRxGain(size_t chan = 0) { return rxGain; }
/** return maximum Rx Gain **/
double maxRxGain(void);
@@ -189,7 +171,7 @@ private:
double minRxGain(void);
/** sets the transmit chan gain, returns the gain setting **/
double setTxGain(double dB);
double setTxGain(double dB, size_t chan = 0);
/** return maximum Tx Gain **/
double maxTxGain(void);
@@ -197,13 +179,12 @@ private:
/** return minimum Rx Gain **/
double minTxGain(void);
/** Return internal status values */
inline double getTxFreq() { return 0;}
inline double getRxFreq() { return 0;}
inline double getSampleRate() {return actualSampleRate;}
inline double getTxFreq(size_t chan = 0) { return 0; }
inline double getRxFreq(size_t chan = 0) { return 0; }
inline double getSampleRate() { return actualSampleRate; }
inline double numberRead() { return samplesRead; }
inline double numberWritten() { return samplesWritten;}
inline double numberWritten() { return samplesWritten; }
};

View File

@@ -1,95 +0,0 @@
/*
* Copyright 2008, 2009 Free Software Foundation, Inc.
*
* This software is distributed under the terms of the GNU Public License.
* See the COPYING file in the main directory for details.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <stdio.h>
#include <Logger.h>
#include <Configuration.h>
#include "radioDevice.h"
ConfigurationTable gConfig;
using namespace std;
int main(int argc, char *argv[]) {
// Configure logger.
if (argc>1) gLogInit(argv[1]);
else gLogInit("DEBUG");
//if (argc>2) gSetLogFile(argv[2]);
RadioDevice *usrp = RadioDevice::make(52.0e6/192.0, 1);
usrp->open("");
TIMESTAMP timestamp;
usrp->setTxFreq(825.4e6);
usrp->setRxFreq(825.4e6);
usrp->start();
usrp->setRxGain(57);
LOG(INFO) << "Looping...";
bool underrun;
short data[]={0x00,0x02};
usrp->updateAlignment(20000);
usrp->updateAlignment(21000);
int numpkts = 1;
short data2[512*2*numpkts];
for (int i = 0; i < 512*numpkts; i++) {
data2[i<<1] = 10000;//4096*cos(2*3.14159*(i % 126)/126);
data2[(i<<1) + 1] = 10000;//4096*sin(2*3.14159*(i % 126)/126);
}
for (int i = 0; i < 1; i++)
usrp->writeSamples((short*) data2,512*numpkts,&underrun,102000+i*1000);
timestamp = 19000;
double sum = 0.0;
unsigned long num = 0;
while (1) {
short readBuf[512*2];
int rd = usrp->readSamples(readBuf,512,&underrun,timestamp);
if (rd) {
LOG(INFO) << "rcvd. data@:" << timestamp;
for (int i = 0; i < 512; i++) {
uint32_t *wordPtr = (uint32_t *) &readBuf[2*i];
printf ("%llu: %d %d\n", timestamp+i,readBuf[2*i],readBuf[2*i+1]);
sum += (readBuf[2*i+1]*readBuf[2*i+1] + readBuf[2*i]*readBuf[2*i]);
num++;
//if (num % 10000 == 0) printf("avg pwr: %f\n",sum/num);
}
timestamp += rd;
//usrp->writeSamples((short*) data2,512*numpkts,&underrun,timestamp+1000);
}
}
}

View File

@@ -0,0 +1,23 @@
if ARCH_ARM
if ARCH_ARM_A15
ARCH_FLAGS = -mfpu=neon-vfpv4
else
ARCH_FLAGS = -mfpu=neon
endif
AM_CFLAGS = -Wall $(ARCH_FLAGS) -std=gnu99 -I../common
AM_CCASFLAGS = $(ARCH_FLAGS)
noinst_LTLIBRARIES = libarch.la
libarch_la_SOURCES = \
../common/convolve_base.c \
convert.c \
convert_neon.S \
convolve.c \
convolve_neon.S \
scale.c \
scale_neon.S \
mult.c \
mult_neon.S
endif

View File

@@ -0,0 +1,83 @@
/*
* NEON type conversions
* Copyright (C) 2012, 2013 Thomas Tsou <tom@tsou.cc>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <malloc.h>
#include <string.h>
#include "convert.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
void neon_convert_ps_si16_4n(short *, const float *, const float *, int);
void neon_convert_si16_ps_4n(float *, const short *, int);
/* 4*N 16-bit signed integer conversion with remainder */
static void neon_convert_si16_ps(float *out,
const short *in,
int len)
{
int start = len / 4 * 4;
neon_convert_si16_ps_4n(out, in, len >> 2);
for (int i = 0; i < len % 4; i++)
out[start + i] = (float) in[start + i];
}
/* 4*N 16-bit signed integer conversion with remainder */
static void neon_convert_ps_si16(short *out,
const float *in,
const float *scale,
int len)
{
int start = len / 4 * 4;
neon_convert_ps_si16_4n(out, in, scale, len >> 2);
for (int i = 0; i < len % 4; i++)
out[start + i] = (short) (in[start + i] * (*scale));
}
#endif
void convert_float_short(short *out, const float *in, float scale, int len)
{
#ifdef HAVE_NEON
float q[4] = { scale, scale, scale, scale };
if (len % 4)
neon_convert_ps_si16(out, in, q, len);
else
neon_convert_ps_si16_4n(out, in, q, len >> 2);
#else
base_convert_float_short(out, in, scale, len);
#endif
}
void convert_short_float(float *out, const short *in, int len)
{
#ifdef HAVE_NEON
if (len % 4)
neon_convert_si16_ps(out, in, len);
else
neon_convert_si16_ps_4n(out, in, len >> 2);
#else
base_convert_short_float(out, in, len);
#endif
}

View File

@@ -0,0 +1,51 @@
/*
* NEON type conversions
* Copyright (C) 2012, 2013 Thomas Tsou <tom@tsou.cc>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
.syntax unified
.text
.align 2
.global neon_convert_ps_si16_4n
.type neon_convert_ps_si16_4n, %function
neon_convert_ps_si16_4n:
vld1.32 {q1}, [r2]
.loop_fltint:
vld1.64 {d0-d1}, [r1]!
vmul.f32 q0, q1
vcvt.s32.f32 q2, q0
vqmovn.s32 d0, q2
vst1.64 {d0}, [r0]!
subs r3, #1
bne .loop_fltint
bx lr
.size neon_convert_ps_si16_4n, .-neon_convert_ps_si16_4n
.text
.align 2
.global neon_convert_si16_ps_4n
.type neon_convert_si16_ps_4n, %function
neon_convert_si16_ps_4n:
.loop_intflt:
vld1.64 {d0}, [r1]!
vmovl.s16 q1, d0
vcvt.f32.s32 q0, q1
vst1.64 {q0}, [r0]!
subs r2, #1
bne .loop_intflt
bx lr
.size neon_convert_si16_ps_4n, .-neon_convert_si16_ps_4n
.section .note.GNU-stack,"",%progbits

View File

@@ -0,0 +1,146 @@
/*
* NEON Convolution
* Copyright (C) 2012, 2013 Thomas Tsou <tom@tsou.cc>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <malloc.h>
#include <string.h>
#include <stdio.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
/* Forward declarations from base implementation */
int _base_convolve_real(float *x, int x_len,
float *h, int h_len,
float *y, int y_len,
int start, int len,
int step, int offset);
int _base_convolve_complex(float *x, int x_len,
float *h, int h_len,
float *y, int y_len,
int start, int len,
int step, int offset);
int bounds_check(int x_len, int h_len, int y_len,
int start, int len, int step);
#ifdef HAVE_NEON
/* Calls into NEON assembler */
void neon_conv_real4(float *x, float *h, float *y, int len);
void neon_conv_real8(float *x, float *h, float *y, int len);
void neon_conv_real12(float *x, float *h, float *y, int len);
void neon_conv_real16(float *x, float *h, float *y, int len);
void neon_conv_real20(float *x, float *h, float *y, int len);
void mac_cx_neon4(float *x, float *h, float *y, int len);
/* Complex-complex convolution */
static void neon_conv_cmplx_4n(float *x, float *h, float *y, int h_len, int len)
{
for (int i = 0; i < len; i++)
mac_cx_neon4(&x[2 * i], h, &y[2 * i], h_len >> 2);
}
#endif
/* API: Initalize convolve module */
void convolve_init(void)
{
/* Stub */
return;
}
/* API: Aligned complex-real */
int convolve_real(float *x, int x_len,
float *h, int h_len,
float *y, int y_len,
int start, int len,
int step, int offset)
{
void (*conv_func)(float *, float *, float *, int) = NULL;
if (bounds_check(x_len, h_len, y_len, start, len, step) < 0)
return -1;
memset(y, 0, len * 2 * sizeof(float));
#ifdef HAVE_NEON
if (step <= 4) {
switch (h_len) {
case 4:
conv_func = neon_conv_real4;
break;
case 8:
conv_func = neon_conv_real8;
break;
case 12:
conv_func = neon_conv_real12;
break;
case 16:
conv_func = neon_conv_real16;
break;
case 20:
conv_func = neon_conv_real20;
break;
}
}
#endif
if (conv_func) {
conv_func(&x[2 * (-(h_len - 1) + start)],
h, y, len);
} else {
_base_convolve_real(x, x_len,
h, h_len,
y, y_len,
start, len, step, offset);
}
return len;
}
/* API: Aligned complex-complex */
int convolve_complex(float *x, int x_len,
float *h, int h_len,
float *y, int y_len,
int start, int len,
int step, int offset)
{
void (*conv_func)(float *, float *, float *, int, int) = NULL;
if (bounds_check(x_len, h_len, y_len, start, len, step) < 0)
return -1;
memset(y, 0, len * 2 * sizeof(float));
#ifdef HAVE_NEON
if (step <= 4 && !(h_len % 4))
conv_func = neon_conv_cmplx_4n;
#endif
if (conv_func) {
conv_func(&x[2 * (-(h_len - 1) + start)],
h, y, h_len, len);
} else {
_base_convolve_complex(x, x_len,
h, h_len,
y, y_len,
start, len, step, offset);
}
return len;
}

View File

@@ -0,0 +1,277 @@
/*
* NEON Convolution
* Copyright (C) 2012, 2013 Thomas Tsou <tom@tsou.cc>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
.syntax unified
.text
.align 2
.global neon_conv_real4
.type neon_conv_real4, %function
neon_conv_real4:
push {r4, lr}
vpush {q4-q7}
vld2.32 {q0-q1}, [r1]
ldr r4, =8
.neon_conv_loop4:
vld2.32 {q2-q3}, [r0], r4
vmul.f32 q4, q2, q0
vmul.f32 q5, q3, q0
vpadd.f32 d12, d8, d9
vpadd.f32 d13, d10, d11
vpadd.f32 d14, d12, d13
vst1.64 {d14}, [r2]!
subs r3, r3, #1
bne .neon_conv_loop4
vpop {q4-q7}
pop {r4, pc}
.size neon_conv_real4, .-neon_conv_real4
.align 2
.p2align 4,,15
.global neon_conv_real8
.type neon_conv_real8, %function
neon_conv_real8:
push {r4-r5, lr}
vpush {q4-q7}
vld2.32 {q0-q1}, [r1]!
vld2.32 {q2-q3}, [r1]
add r4, r0, #32
ldr r5, =8
.neon_conv_loop8:
vld2.32 {q4-q5}, [r0], r5
vld2.32 {q6-q7}, [r4], r5
vmul.f32 q8, q4, q0
vmul.f32 q9, q5, q0
vmul.f32 q10, q6, q2
vmul.f32 q11, q7, q2
vadd.f32 q12, q8, q10
vadd.f32 q13, q9, q11
vpadd.f32 d22, d24, d25
vpadd.f32 d23, d26, d27
vpadd.f32 d24, d22, d23
vst1.64 {d24}, [r2]!
subs r3, r3, #1
bne .neon_conv_loop8
vpop {q4-q7}
pop {r4-r5, pc}
.size neon_conv_real8, .-neon_conv_real8
.align 2
.global neon_conv_real12
.type neon_conv_real12, %function
neon_conv_real12:
push {r4-r6, lr}
vpush {q4-q7}
vld2.32 {q0-q1}, [r1]!
vld2.32 {q2-q3}, [r1]!
vld2.32 {q4-q5}, [r1]!
add r4, r0, #32
add r5, r0, #64
ldr r6, =8
.neon_conv_loop12:
vld2.32 {q6-q7}, [r0], r6
vld2.32 {q8-q9}, [r4], r6
vld2.32 {q10-q11}, [r5], r6
#ifdef HAVE_NEON_FMA
vfma.f32 q1, q6, q0
vfma.f32 q3, q7, q0
vfma.f32 q1, q8, q2
vfma.f32 q3, q9, q2
vfma.f32 q1, q10, q4
vfma.f32 q3, q11, q4
#else
vmul.f32 q12, q6, q0
vmul.f32 q13, q7, q0
vmul.f32 q14, q8, q2
vmul.f32 q15, q9, q2
vmul.f32 q1, q10, q4
vmul.f32 q3, q11, q4
vadd.f32 q5, q12, q14
vadd.f32 q6, q13, q15
vadd.f32 q1, q5, q1
vadd.f32 q3, q6, q3
#endif
vpadd.f32 d2, d2, d3
vpadd.f32 d3, d6, d7
vpadd.f32 d6, d2, d3
vst1.64 {d6}, [r2]!
subs r3, r3, #1
bne .neon_conv_loop12
vpop {q4-q7}
pop {r4-r6, pc}
.size neon_conv_real12, .-neon_conv_real12
.align 2
.global neon_conv_real16
.type neon_conv_real16, %function
neon_conv_real16:
push {r4-r7, lr}
vpush {q4-q7}
vld2.32 {q0-q1}, [r1]!
vld2.32 {q2-q3}, [r1]!
vld2.32 {q4-q5}, [r1]!
vld2.32 {q6-q7}, [r1]
add r4, r0, #32
add r5, r0, #64
add r6, r0, #96
ldr r7, =8
.neon_conv_loop16:
vld2.32 {q8-q9}, [r0], r7
vld2.32 {q10-q11}, [r4], r7
vld2.32 {q12-q13}, [r5], r7
vld2.32 {q14-q15}, [r6], r7
#ifdef HAVE_NEON_FMA
vmul.f32 q1, q8, q0
vmul.f32 q3, q9, q0
vfma.f32 q1, q10, q2
vfma.f32 q3, q11, q2
vfma.f32 q1, q12, q4
vfma.f32 q3, q13, q4
vfma.f32 q1, q14, q6
vfma.f32 q3, q15, q6
#else
vmul.f32 q1, q8, q0
vmul.f32 q3, q9, q0
vmul.f32 q5, q10, q2
vmul.f32 q7, q11, q2
vmul.f32 q8, q12, q4
vmul.f32 q9, q13, q4
vmul.f32 q10, q14, q6
vmul.f32 q11, q15, q6
vadd.f32 q1, q1, q5
vadd.f32 q3, q3, q7
vadd.f32 q5, q8, q10
vadd.f32 q7, q9, q11
vadd.f32 q1, q1, q5
vadd.f32 q3, q3, q7
#endif
vpadd.f32 d2, d2, d3
vpadd.f32 d3, d6, d7
vpadd.f32 d6, d2, d3
vst1.64 {d6}, [r2]!
subs r3, r3, #1
bne .neon_conv_loop16
vpop {q4-q7}
pop {r4-r7, pc}
.size neon_conv_real16, .-neon_conv_real16
.align 2
.global neon_conv_real20
.type neon_conv_real20, %function
neon_conv_real20:
push {r4-r8, lr}
vpush {q4-q7}
vld2.32 {q0-q1}, [r1]!
vld2.32 {q2-q3}, [r1]!
vld2.32 {q4-q5}, [r1]!
vld2.32 {q6-q7}, [r1]!
vld2.32 {q8-q9}, [r1]
add r4, r0, #32
add r5, r0, #64
add r6, r0, #96
add r7, r0, #128
ldr r8, =8
.neon_conv_loop20:
vld2.32 {q10-q11}, [r0], r8
vld2.32 {q12-q13}, [r4], r8
vld2.32 {q14-q15}, [r5], r8
#ifdef HAVE_NEON_FMA
vmul.f32 q1, q10, q0
vfma.f32 q1, q12, q2
vfma.f32 q1, q14, q4
vmul.f32 q3, q11, q0
vfma.f32 q3, q13, q2
vfma.f32 q3, q15, q4
vld2.32 {q12-q13}, [r6], r8
vld2.32 {q14-q15}, [r7], r8
vfma.f32 q1, q12, q6
vfma.f32 q3, q13, q6
vfma.f32 q1, q14, q8
vfma.f32 q3, q15, q8
#else
vmul.f32 q1, q10, q0
vmul.f32 q3, q12, q2
vmul.f32 q5, q14, q4
vmul.f32 q7, q11, q0
vmul.f32 q9, q13, q2
vmul.f32 q10, q15, q4
vadd.f32 q1, q1, q3
vadd.f32 q3, q7, q9
vadd.f32 q9, q1, q5
vadd.f32 q10, q3, q10
vld2.32 {q12-q13}, [r6], r8
vld2.32 {q14-q15}, [r7], r8
vmul.f32 q1, q12, q6
vmul.f32 q3, q13, q6
vmul.f32 q5, q14, q8
vmul.f32 q7, q15, q8
vadd.f32 q12, q1, q9
vadd.f32 q14, q3, q10
vadd.f32 q1, q12, q5
vadd.f32 q3, q14, q7
#endif
vpadd.f32 d2, d2, d3
vpadd.f32 d3, d6, d7
vpadd.f32 d6, d2, d3
vst1.64 {d6}, [r2]!
subs r3, r3, #1
bne .neon_conv_loop20
vpop {q4-q7}
pop {r4-r8, pc}
.size neon_conv_real20, .-neon_conv_real20
.align 2
.global mac_cx_neon4
.type mac_cx_neon4, %function
mac_cx_neon4:
push {r4, lr}
ldr r4, =32
veor q14, q14
veor q15, q15
.neon_conv_loop_mac4:
vld2.32 {q0-q1}, [r0], r4
vld2.32 {q2-q3}, [r1]!
vmul.f32 q10, q0, q2
vmul.f32 q11, q1, q3
vmul.f32 q12, q0, q3
vmul.f32 q13, q2, q1
vsub.f32 q8, q10, q11
vadd.f32 q9, q12, q13
vadd.f32 q14, q8
vadd.f32 q15, q9
subs r3, #1
bne .neon_conv_loop_mac4
vld1.64 d0, [r2]
vpadd.f32 d28, d28, d29
vpadd.f32 d30, d30, d31
vpadd.f32 d1, d28, d30
vadd.f32 d1, d0
vst1.64 d1, [r2]
pop {r4, pc}
.size mac_cx_neon4, .-mac_cx_neon4
.section .note.GNU-stack,"",%progbits

56
Transceiver52M/arm/mult.c Normal file
View File

@@ -0,0 +1,56 @@
/*
* NEON scaling
* Copyright (C) 2012,2013 Thomas Tsou <tom@tsou.cc>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <malloc.h>
#include <string.h>
#include <mult.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
void neon_cmplx_mul_4n(float *, float *, float *, int);
static void cmplx_mul_ps(float *out, float *a, float *b, int len)
{
float ai, aq, bi, bq;
for (int i = 0; i < len; i++) {
ai = a[2 * i + 0];
aq = a[2 * i + 1];
bi = b[2 * i + 0];
bq = b[2 * i + 1];
out[2 * i + 0] = ai * bi - aq * bq;
out[2 * i + 1] = ai * bq + aq * bi;
}
}
void mul_complex(float *out, float *a, float *b, int len)
{
#ifdef HAVE_NEON
if (len % 4)
cmplx_mul_ps(out, a, b, len);
else
neon_cmplx_mul_4n(out, a, b, len >> 2);
#else
cmplx_mul_ps(out, a, b, len);
#endif
}

View File

@@ -0,0 +1,42 @@
/*
* NEON complex multiplication
* Copyright (C) 2012,2013 Thomas Tsou <tom@tsou.cc>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
.syntax unified
.text
.align 2
.global neon_cmplx_mul_4n
.type neon_cmplx_mul_4n, %function
neon_cmplx_mul_4n:
vpush {q4-q7}
.loop_mul:
vld2.32 {q0-q1}, [r1]!
vld2.32 {q2-q3}, [r2]!
vmul.f32 q4, q0, q2
vmul.f32 q5, q1, q3
vmul.f32 q6, q0, q3
vmul.f32 q7, q2, q1
vsub.f32 q8, q4, q5
vadd.f32 q9, q6, q7
vst2.32 {q8-q9}, [r0]!
subs r3, #1
bne .loop_mul
vpop {q4-q7}
bx lr
.size neon_cmplx_mul_4n, .-neon_cmplx_mul_4n
.section .note.GNU-stack,"",%progbits

View File

@@ -0,0 +1,56 @@
/*
* NEON scaling
* Copyright (C) 2012,2013 Thomas Tsou <tom@tsou.cc>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <malloc.h>
#include <string.h>
#include <scale.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
void neon_scale_4n(float *, float *, float *, int);
static void scale_ps(float *out, float *in, float *scale, int len)
{
float ai, aq, bi, bq;
bi = scale[0];
bq = scale[1];
for (int i = 0; i < len; i++) {
ai = in[2 * i + 0];
aq = in[2 * i + 1];
out[2 * i + 0] = ai * bi - aq * bq;
out[2 * i + 1] = ai * bq + aq * bi;
}
}
void scale_complex(float *out, float *in, float* scale, int len)
{
#ifdef HAVE_NEON
if (len % 4)
scale_ps(out, in, scale, len);
else
neon_scale_4n(in, scale, out, len >> 2);
#else
scale_ps(out, in, scale, len);
#endif
}

View File

@@ -0,0 +1,50 @@
/*
* ARM NEON Scaling
* Copyright (C) 2013 Thomas Tsou <tom@tsou.cc>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
.syntax unified
.text
.align 2
.global neon_scale_4n
.type neon_scale_4n, %function
neon_scale_4n:
push {r4, lr}
ldr r4, =32
vld1.64 d0, [r1]
vmov.32 s4, s1
vmov.32 s1, s0
vmov.64 d1, d0
vmov.32 s5, s4
vmov.64 d3, d2
.loop_mul_const:
vld2.32 {q2-q3}, [r0], r4
vmul.f32 q8, q0, q2
vmul.f32 q9, q1, q3
vmul.f32 q10, q0, q3
vmul.f32 q11, q1, q2
vsub.f32 q8, q8, q9
vadd.f32 q9, q10, q11
vst2.32 {q8-q9}, [r2]!
subs r3, #1
bne .loop_mul_const
pop {r4, pc}
.size neon_scale_4n, .-neon_scale_4n
.section .note.GNU-stack,"",%progbits

View File

@@ -0,0 +1,15 @@
#ifndef _CONVERT_H_
#define _CONVERT_H_
void convert_float_short(short *out, const float *in, float scale, int len);
void convert_short_float(float *out, const short *in, int len);
void base_convert_float_short(short *out, const float *in,
float scale, int len);
void base_convert_short_float(float *out, const short *in, int len);
void convert_init(void);
#endif /* _CONVERT_H_ */

View File

@@ -0,0 +1,34 @@
/*
* Conversion
* Copyright (C) 2012, 2013 Thomas Tsou <tom@tsou.cc>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "convert.h"
void base_convert_float_short(short *out, const float *in,
float scale, int len)
{
for (int i = 0; i < len; i++)
out[i] = in[i] * scale;
}
void base_convert_short_float(float *out, const short *in, int len)
{
for (int i = 0; i < len; i++)
out[i] = in[i];
}

View File

@@ -0,0 +1,32 @@
#ifndef _CONVOLVE_H_
#define _CONVOLVE_H_
void *convolve_h_alloc(int num);
int convolve_real(const float *x, int x_len,
const float *h, int h_len,
float *y, int y_len,
int start, int len,
int step, int offset);
int convolve_complex(const float *x, int x_len,
const float *h, int h_len,
float *y, int y_len,
int start, int len,
int step, int offset);
int base_convolve_real(const float *x, int x_len,
const float *h, int h_len,
float *y, int y_len,
int start, int len,
int step, int offset);
int base_convolve_complex(const float *x, int x_len,
const float *h, int h_len,
float *y, int y_len,
int start, int len,
int step, int offset);
void convolve_init(void);
#endif /* _CONVOLVE_H_ */

View File

@@ -0,0 +1,156 @@
/*
* Convolution
* Copyright (C) 2012, 2013 Thomas Tsou <tom@tsou.cc>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <malloc.h>
#include <string.h>
#include <stdio.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
/* Base multiply and accumulate complex-real */
static void mac_real(const float *x, const float *h, float *y)
{
y[0] += x[0] * h[0];
y[1] += x[1] * h[0];
}
/* Base multiply and accumulate complex-complex */
static void mac_cmplx(const float *x, const float *h, float *y)
{
y[0] += x[0] * h[0] - x[1] * h[1];
y[1] += x[0] * h[1] + x[1] * h[0];
}
/* Base vector complex-complex multiply and accumulate */
static void mac_real_vec_n(const float *x, const float *h, float *y,
int len, int step, int offset)
{
for (int i = offset; i < len; i += step)
mac_real(&x[2 * i], &h[2 * i], y);
}
/* Base vector complex-complex multiply and accumulate */
static void mac_cmplx_vec_n(const float *x, const float *h, float *y,
int len, int step, int offset)
{
for (int i = offset; i < len; i += step)
mac_cmplx(&x[2 * i], &h[2 * i], y);
}
/* Base complex-real convolution */
int _base_convolve_real(const float *x, int x_len,
const float *h, int h_len,
float *y, int y_len,
int start, int len,
int step, int offset)
{
for (int i = 0; i < len; i++) {
mac_real_vec_n(&x[2 * (i - (h_len - 1) + start)],
h,
&y[2 * i], h_len,
step, offset);
}
return len;
}
/* Base complex-complex convolution */
int _base_convolve_complex(const float *x, int x_len,
const float *h, int h_len,
float *y, int y_len,
int start, int len,
int step, int offset)
{
for (int i = 0; i < len; i++) {
mac_cmplx_vec_n(&x[2 * (i - (h_len - 1) + start)],
h,
&y[2 * i],
h_len, step, offset);
}
return len;
}
/* Buffer validity checks */
int bounds_check(int x_len, int h_len, int y_len,
int start, int len, int step)
{
if ((x_len < 1) || (h_len < 1) ||
(y_len < 1) || (len < 1) || (step < 1)) {
fprintf(stderr, "Convolve: Invalid input\n");
return -1;
}
if ((start + len > x_len) || (len > y_len) || (x_len < h_len)) {
fprintf(stderr, "Convolve: Boundary exception\n");
fprintf(stderr, "start: %i, len: %i, x: %i, h: %i, y: %i\n",
start, len, x_len, h_len, y_len);
return -1;
}
return 0;
}
/* API: Non-aligned (no SSE) complex-real */
int base_convolve_real(const float *x, int x_len,
const float *h, int h_len,
float *y, int y_len,
int start, int len,
int step, int offset)
{
if (bounds_check(x_len, h_len, y_len, start, len, step) < 0)
return -1;
memset(y, 0, len * 2 * sizeof(float));
return _base_convolve_real(x, x_len,
h, h_len,
y, y_len,
start, len, step, offset);
}
/* API: Non-aligned (no SSE) complex-complex */
int base_convolve_complex(const float *x, int x_len,
const float *h, int h_len,
float *y, int y_len,
int start, int len,
int step, int offset)
{
if (bounds_check(x_len, h_len, y_len, start, len, step) < 0)
return -1;
memset(y, 0, len * 2 * sizeof(float));
return _base_convolve_complex(x, x_len,
h, h_len,
y, y_len,
start, len, step, offset);
}
/* Aligned filter tap allocation */
void *convolve_h_alloc(int len)
{
#ifdef HAVE_SSE3
return memalign(16, len * 2 * sizeof(float));
#else
return malloc(len * 2 * sizeof(float));
#endif
}

112
Transceiver52M/common/fft.c Normal file
View File

@@ -0,0 +1,112 @@
/*
* Fast Fourier transform
*
* Copyright (C) 2012 Tom Tsou <tom@tsou.cc>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
* See the COPYING file in the main directory for details.
*/
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <fftw3.h>
#include "fft.h"
struct fft_hdl {
float *fft_in;
float *fft_out;
int len;
fftwf_plan fft_plan;
};
/*! \brief Initialize FFT backend
* \param[in] reverse FFT direction
* \param[in] m FFT length
* \param[in] istride input stride count
* \param[in] ostride output stride count
* \param[in] in input buffer (FFTW aligned)
* \param[in] out output buffer (FFTW aligned)
* \param[in] ooffset initial offset into output buffer
*
* If the reverse is non-NULL, then an inverse FFT will be used. This is a
* wrapper for advanced non-contiguous FFTW usage. See FFTW documentation for
* further details.
*
* http://www.fftw.org/doc/Advanced-Complex-DFTs.html
*
* It is currently unknown how the offset of the output buffer affects FFTW
* memory alignment.
*/
struct fft_hdl *init_fft(int reverse, int m, int istride, int ostride,
float *in, float *out, int ooffset)
{
int rank = 1;
int n[] = { m };
int howmany = istride;
int idist = 1;
int odist = 1;
int *inembed = n;
int *onembed = n;
fftwf_complex *obuffer, *ibuffer;
struct fft_hdl *hdl = (struct fft_hdl *) malloc(sizeof(struct fft_hdl));
if (!hdl)
return NULL;
int direction = FFTW_FORWARD;
if (reverse)
direction = FFTW_BACKWARD;
ibuffer = (fftwf_complex *) in;
obuffer = (fftwf_complex *) out + ooffset;
hdl->fft_in = in;
hdl->fft_out = out;
hdl->fft_plan = fftwf_plan_many_dft(rank, n, howmany,
ibuffer, inembed, istride, idist,
obuffer, onembed, ostride, odist,
direction, FFTW_MEASURE);
return hdl;
}
void *fft_malloc(size_t size)
{
return fftwf_malloc(size);
}
void fft_free(void *ptr)
{
free(ptr);
}
/*! \brief Free FFT backend resources
*/
void free_fft(struct fft_hdl *hdl)
{
fftwf_destroy_plan(hdl->fft_plan);
free(hdl);
}
/*! \brief Run multiple DFT operations with the initialized plan
* \param[in] hdl handle to an intitialized fft struct
*
* Input and output buffers are configured with init_fft().
*/
int cxvec_fft(struct fft_hdl *hdl)
{
fftwf_execute(hdl->fft_plan);
return 0;
}

View File

@@ -0,0 +1,13 @@
#ifndef _FFT_H_
#define _FFT_H_
struct fft_hdl;
struct fft_hdl *init_fft(int reverse, int m, int istride, int ostride,
float *in, float *out, int ooffset);
void *fft_malloc(size_t size);
void fft_free(void *ptr);
void free_fft(struct fft_hdl *hdl);
int cxvec_fft(struct fft_hdl *hdl);
#endif /* _FFT_H_ */

View File

@@ -0,0 +1,6 @@
#ifndef _MULT_H_
#define _MULT_H_
void mul_complex(float *out, float *a, float *b, int len);
#endif /* _MULT_H_ */

View File

@@ -0,0 +1,6 @@
#ifndef _SCALE_H_
#define _SCALE_H_
void scale_complex(float *out, float *in, float *scale, int len);
#endif /* _SCALE_H_ */

83
Transceiver52M/laurent.m Normal file
View File

@@ -0,0 +1,83 @@
%
% Laurent decomposition of GMSK signals
% Generates C0, C1, and C2 pulse shapes
%
% Pierre Laurent, "Exact and Approximate Construction of Digital Phase
% Modulations by Superposition of Amplitude Modulated Pulses", IEEE
% Transactions of Communications, Vol. 34, No. 2, Feb 1986.
%
% Author: Thomas Tsou <tom@tsou.cc>
%
% Modulation parameters
oversamp = 16;
L = 3;
f = 270.83333e3;
T = 1/f;
h = 0.5;
BT = 0.30;
B = BT / T;
% Generate sampling points for L symbol periods
t = -(L*T/2):T/oversamp:(L*T/2);
t = t(1:end-1) + (T/oversamp/2);
% Generate Gaussian pulse
g = qfunc(2*pi*B*(t - T/2)/(log(2)^.5)) - qfunc(2*pi*B*(t + T/2)/(log(2)^.5));
g = g / sum(g) * pi/2;
g = [0 g];
% Integrate phase
q = 0;
for i = 1:size(g,2);
q(i) = sum(g(1:i));
end
% Compute two sided "generalized phase pulse" function
s = 0;
for i = 1:size(g,2);
s(i) = sin(q(i)) / sin(pi*h);
end
for i = (size(g,2) + 1):(2 * size(g,2) - 1);
s(i) = sin(pi*h - q(i - (size(g,2) - 1))) / sin(pi*h);
end
% Compute C0 pulse: valid for all L values
c0 = s(1:end-(oversamp*(L-1)));
for i = 1:L-1;
c0 = c0 .* s((1 + i*oversamp):end-(oversamp*(L - 1 - i)));
end
% Compute C1 pulse: valid for L = 3 only!
% C1 = S0 * S4 * S2
c1 = s(1:end-(oversamp*(4)));
c1 = c1 .* s((1 + 4*oversamp):end-(oversamp*(4 - 1 - 3)));
c1 = c1 .* s((1 + 2*oversamp):end-(oversamp*(4 - 1 - 1)));
% Compute C2 pulse: valid for L = 3 only!
% C2 = S0 * S1 * S5
c2 = s(1:end-(oversamp*(5)));
c2 = c2 .* s((1 + 1*oversamp):end-(oversamp*(5 - 1 - 0)));
c2 = c2 .* s((1 + 5*oversamp):end-(oversamp*(5 - 1 - 4)));
% Plot C0, C1, C2 Laurent pulse series
figure(1);
hold off;
plot((0:size(c0,2)-1)/oversamp - 2,c0, 'b');
hold on;
plot((0:size(c1,2)-1)/oversamp - 2,c1, 'r');
plot((0:size(c2,2)-1)/oversamp - 2,c2, 'g');
% Generate OpenBTS pulse
numSamples = size(c0,2);
centerPoint = (numSamples - 1)/2;
i = ((0:numSamples) - centerPoint) / oversamp;
xP = .96*exp(-1.1380*i.^2 - 0.527*i.^4);
xP = xP / max(xP) * max(c0);
% Plot C0 pulse compared to OpenBTS pulse
figure(2);
hold off;
plot((0:size(c0,2)-1)/oversamp, c0, 'b');
hold on;
plot((0:size(xP,2)-1)/oversamp, xP, 'r');

View File

@@ -1,120 +0,0 @@
/*
* Copyright 2012 Thomas Tsou <ttsou@vt.edu>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* See the COPYING file in the main directory for details.
*/
#include <time.h>
#include <signal.h>
#include <GSMCommon.h>
#include <Logger.h>
#include <Configuration.h>
#include "Transceiver.h"
#include "radioDevice.h"
ConfigurationTable gConfig("/etc/OpenBTS/OpenBTS.db");
volatile bool gbShutdown = false;
int Transceiver::mTSC = -1;
static void sigHandler(int signum)
{
LOG(NOTICE) << "Received shutdown signal";
gbShutdown = true;
}
static int setupSignals()
{
struct sigaction action;
action.sa_handler = sigHandler;
sigemptyset(&action.sa_mask);
action.sa_flags = 0;
if (sigaction(SIGINT, &action, NULL) < 0)
return -1;
if (sigaction(SIGTERM, &action, NULL) < 0)
return -1;
return 0;
}
int main(int argc, char *argv[])
{
int numARFCN = 1;
if (argc > 1) {
numARFCN = atoi(argv[1]);
if (numARFCN > CHAN_MAX) {
LOG(ALERT) << numARFCN << " channels not supported "
<< " with with current build";
exit(-1);
}
}
gLogInit("transceiver", gConfig.getStr("Log.Level").c_str(), LOG_LOCAL7);
srandom(time(NULL));
if (setupSignals() < 0) {
LOG(ERR) << "Failed to setup signal handlers, exiting...";
exit(-1);
}
RadioDevice *device = RadioDevice::make(SAMPSPERSYM);
int radioType = device->open("");
if (radioType < 0) {
LOG(ALERT) << "Failed to open device, exiting...";
return EXIT_FAILURE;
}
RadioInterface *radio;
switch (radioType) {
case RadioDevice::NORMAL:
radio = new RadioInterface(device, numARFCN);
break;
case RadioDevice::RESAMP:
default:
LOG(ALERT) << "Unsupported configuration";
return EXIT_FAILURE;
}
DriveLoop *drive = new DriveLoop(5700, "127.0.0.1", radio, numARFCN, 0);
Transceiver *trx[CHAN_MAX];
bool primary = true;
for (int i = 0; i < numARFCN; i++) {
trx[i] = new Transceiver(5700 + 2 * i, "127.0.0.1",
drive, radio, SAMPSPERSYM,
i, primary);
trx[i]->start();
primary = false;
}
while (!gbShutdown)
sleep(1);
LOG(NOTICE) << "Shutting down transceivers...";
for (int i = 0; i < numARFCN; i++)
trx[i]->shutdown();
for (int i = 0; i < numARFCN; i++)
delete trx[i];
delete drive;
delete radio;
delete device;
}

View File

@@ -0,0 +1,520 @@
/*
* Copyright (C) 2016-2017 Alexander Chemeris <Alexander.Chemeris@fairwaves.co>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <limits.h>
#include <fstream>
#include <iomanip>
#include "Logger.h"
#include "sigProcLib.h"
#include "signalVector.h"
#include "Transceiver.h"
#include "Configuration.h"
extern "C" {
#include "convolve.h"
#include "convert.h"
}
#define DEFAULT_RX_SPS 1
#define DEFAULT_SEARCH_WINDOW 30
// Tail + data + stealing + midamble + guard (without the last 0.25)
#define BURST_LEN_FULL 156
// Tail + data + stealing + midamble
#define BURST_LEN_ACTIVE 148
// Tail + data + stealing + midamble - 2*0.5
#define BURST_LEN_USEFUL 147
// Size of a sample in bytes as stores in a file
#define SAMPLE_SIZE_BYTES (2 * sizeof(float))
// Burst length in bytes as stored in a file
#define BURST_LEN_BYTES (BURST_LEN_FULL * SAMPLE_SIZE_BYTES)
ConfigurationTable gConfig;
struct trx_config {
std::string log_level;
unsigned sps;
unsigned tsc;
unsigned max_expected_delay_nb;
unsigned max_expected_delay_ab;
double full_scale;
bool edge;
CorrType type;
std::string filename;
unsigned ber_burst_avg; ///< Average BER over this many bursts.
///< Set to 0 to average for the whole duration.
};
class NormalBurstSoftbitMask {
public:
NormalBurstSoftbitMask(SoftVector &softBits)
: mSoftBits(softBits)
{
}
SoftVector &bits() { return mSoftBits; }
SoftVector tailBitsL() { return mSoftBits.segment(0,3); }
SoftVector dataBitsL() { return mSoftBits.segment(3,57); }
SoftVector stealingBitsL() { return mSoftBits.segment(60, 1); }
SoftVector midambleBits() { return mSoftBits.segment(61, 26); }
SoftVector stealingBitsR() { return mSoftBits.segment(87, 1); }
SoftVector dataBitsR() { return mSoftBits.segment(88,57); }
SoftVector tailBitsR() { return mSoftBits.segment(145,3); }
SoftVector guardBits() { return mSoftBits.segment(148,8); }
protected:
SoftVector &mSoftBits;
};
class SoftBurst {
public:
SoftBurst(SoftVector *softBits, double toa=0)
: mSoftBits(softBits), mTOA(toa)
{
assert(mSoftBits != NULL);
}
~SoftBurst()
{
delete mSoftBits;
}
void TOA(double TOA) { mTOA = TOA; }
double TOA() { return mTOA; }
NormalBurstSoftbitMask normalBurstMask() { return NormalBurstSoftbitMask(*mSoftBits); }
protected:
SoftVector *mSoftBits;
double mTOA;
};
class BEREstimator {
public:
BEREstimator(const PRBS& prbs)
: mPRBS(prbs), mTotalBits(0), mErrorBits(0), mSynchronized(false)
{}
unsigned synchronize(const BitVector &bits)
{
for (unsigned i=0; i<mPRBS.size(); i++) {
mPRBS.processBit(bits[i]);
}
mSynchronized = true;
return mPRBS.size();
}
void process(const BitVector &bits, size_t start_from = 0)
{
for (size_t i=start_from; i<bits.size(); i++) {
mTotalBits++;
if (mPRBS.generateBit() != bits.bit(i)) {
mErrorBits++;
}
}
}
void sync_and_process(const BitVector &bits)
{
unsigned skip = 0;
if (!mSynchronized) {
skip = synchronize(bits);
}
process(bits, skip);
}
void skip(size_t num)
{
for (size_t i=0; i<num; i++) {
mTotalBits++;
mErrorBits++;
mPRBS.generateBit();
}
}
void reset()
{
mTotalBits = 0;
mErrorBits = 0;
}
unsigned totalBits() const { return mTotalBits; }
unsigned errorBits() const { return mErrorBits; }
double BER() const { return mErrorBits/(double)mTotalBits; }
bool isSynchronized() const {return mSynchronized; }
protected:
PRBS mPRBS;
unsigned mTotalBits;
unsigned mErrorBits;
bool mSynchronized;
};
double getBurstRSSI(const signalVector &burst, unsigned sps, double full_scale)
{
/* Calculate average power of the burst */
float avg = energyDetect(burst, 20 * sps);
return 20.0 * log10(sqrt(avg) / full_scale);
}
void printDetectionResult(int rc)
{
if (rc > 0) {
std::cout << "Detected correlation type: " << (CorrType)rc << std::endl;
} else {
if (rc == -SIGERR_CLIP) {
std::cout << "Clipping detected on received RACH or Normal Burst" << std::endl;
} else if (rc != SIGERR_NONE) {
std::cout << "Unhandled RACH or Normal Burst detection error" << std::endl;
} else {
// std::cout << "No burst detected" << std::endl;
}
}
}
SoftVector *demodulateBurst(const signalVector &burst,
CorrType expected_type,
unsigned sps, unsigned tsc,
unsigned max_expected_delay,
double &timingOffset)
{
complex amp;
float toa;
int rc;
CorrType detected_type;
/* Detect normal or RACH bursts */
rc = detectAnyBurst(burst, tsc, BURST_THRESH, sps, expected_type, amp, toa,
max_expected_delay);
printDetectionResult(rc);
if (rc <= 0) {
return NULL;
}
// Convert samples to symbols
timingOffset = toa / sps;
// rc > 0 means it's a detected CorrType
detected_type = (CorrType)rc;
return demodAnyBurst(burst, sps, amp, toa, detected_type);
}
static bool processBurst(const trx_config &config, signalVector &burst,
unsigned max_expected_delay,
double &RSSI,
double &timingOffset,
BEREstimator &berEstimator)
{
RSSI = getBurstRSSI(burst, config.sps, config.full_scale);
SoftVector *softBits = demodulateBurst(burst, config.type, config.sps,config.tsc,
max_expected_delay, timingOffset);
/* Print burst information and content */
if (softBits == NULL) {
std::cout << "Skipped frame" << std::endl;
// TODO: This is different for EDGE
berEstimator.skip(57*2);
return false;
}
SoftBurst softBurst(softBits, timingOffset);
NormalBurstSoftbitMask nb = softBurst.normalBurstMask();
berEstimator.sync_and_process(nb.dataBitsL().sliced());
berEstimator.sync_and_process(nb.dataBitsR().sliced());
std::cout << "TOA: " << softBurst.TOA() << " symbols" << std::endl;
// Exclude tail and guard bits from the energy calculation
std::cout << "Energy: " << softBits->segment(3,142).getEnergy() << std::endl;
//std::cout << "Demodulated burst: " << *softBits << std::endl;
std::cout << " tail|--------------------------data---------------------------|f|--------midamble----------|f|--------------------------data---------------------------|tai|-guard--" << std::endl;
// " 000 010001011011110011101001100100000001010001011000100100010 0 11101111000100101110111100 0 011010111011101010011010111000101100001110101011011001011 000 1''..---"
std::cout << "Demodulated burst:"
<< " " << nb.tailBitsL()
<< " " << nb.dataBitsL()
<< " " << nb.stealingBitsL()
<< " " << nb.midambleBits()
<< " " << nb.stealingBitsR()
<< " " << nb.dataBitsR()
<< " " << nb.tailBitsR()
<< " " << nb.guardBits()
<< std::endl;
return true;
}
// Setup configuration values
static void print_config(struct trx_config *config)
{
std::ostringstream ost("");
ost << "Config Settings" << std::endl;
ost << " Source file name............. " << config->filename << std::endl;
ost << " Log Level.................... " << config->log_level << std::endl;
ost << " Rx Samples-per-Symbol........ " << config->sps << std::endl;
ost << " EDGE support................. " << (config->edge ? "Enabled" : "Disabled") << std::endl;
ost << " Burst type................... " << config->type << std::endl;
ost << " Burst TSC.................... " << config->tsc << std::endl;
ost << " Normal Burst search window... " << config->max_expected_delay_nb << std::endl;
ost << " Access Burst search window... " << config->max_expected_delay_ab << std::endl;
ost << " Signal full scale............ " << config->full_scale << std::endl;
ost << " BER average window (bursts).. " << config->ber_burst_avg << std::endl;
std::cout << ost << std::endl;
}
static void print_help()
{
fprintf(stdout, "Options:\n"
" -h This text\n"
" -l LEVEL Logging level (%s)\n"
" -e Enable EDGE receiver\n"
" -s SPS Samples-per-symbol (1 or 4, default: %d)\n"
" -t TSC Burst training sequence (0 to 7, default: 0)\n"
" -f FILE File to read\n"
" -w SYMBOLS Normal Burst search window (0 to 156, default: %d)\n"
" -W SYMBOLS Access Burst search window (0 to 156, default: %d)\n"
" -b BURSTS BER average window. Set to 0 to average over the whole file (default: 1)\n",
"EMERG, ALERT, CRT, ERR, WARNING, NOTICE, INFO, DEBUG",
DEFAULT_RX_SPS,
DEFAULT_SEARCH_WINDOW, DEFAULT_SEARCH_WINDOW);
}
static bool handle_options(int argc, char **argv, struct trx_config *config)
{
int option;
config->log_level = "NOTICE";
config->sps = DEFAULT_RX_SPS;
config->tsc = 0;
config->max_expected_delay_nb = DEFAULT_SEARCH_WINDOW;
config->max_expected_delay_ab = DEFAULT_SEARCH_WINDOW;
config->full_scale = SHRT_MAX;
config->edge = false;
config->type = TSC;
config->ber_burst_avg = 1;
while ((option = getopt(argc, argv, "ls:et:f:w:W:b:h")) != -1) {
switch (option) {
case 'l':
config->log_level = optarg;
break;
case 's':
config->sps = atoi(optarg);
break;
case 'e':
config->edge = true;
break;
case 't':
config->tsc = atoi(optarg);
break;
case 'f':
config->filename = optarg;
break;
case 'w':
config->max_expected_delay_nb = atoi(optarg);
break;
case 'W':
config->max_expected_delay_ab = atoi(optarg);
break;
case 'b':
config->ber_burst_avg = atoi(optarg);
break;
case 'h':
default:
print_help();
exit(0);
}
}
if ((config->sps != 1) && (config->sps != 4)) {
printf("ERROR: Unsupported samples-per-symbol %i\n\n", config->sps);
return false;
}
if (config->edge && (config->sps != 4)) {
printf("ERROR: EDGE only supported at 4 samples per symbol\n\n");
return false;
}
if (config->tsc > 7) {
printf("ERROR: Invalid training sequence %i\n\n", config->tsc);
return false;
}
if (config->filename.length() == 0) {
printf("ERROR: No input file specified\n\n");
return false;
}
if (config->max_expected_delay_nb > 156 || config->max_expected_delay_nb < 0 ||
config->max_expected_delay_ab > 156 || config->max_expected_delay_ab < 0) {
printf("ERROR: Invalid search window size, must be withit [1..156] range\n\n");
return false;
}
return true;
}
int main(int argc, char *argv[])
{
struct trx_config config;
#ifdef HAVE_SSE3
printf("Info: SSE3 support compiled in");
if (__builtin_cpu_supports("sse3"))
printf(" and supported by CPU\n");
else
printf(", but not supported by CPU\n");
#endif
#ifdef HAVE_SSE4_1
printf("Info: SSE4.1 support compiled in");
if (__builtin_cpu_supports("sse4.1"))
printf(" and supported by CPU\n");
else
printf(", but not supported by CPU\n");
#endif
convolve_init();
convert_init();
// Process command line options and print config to screen
if (!handle_options(argc, argv, &config)) {
print_help();
exit(0);
}
print_config(&config);
gLogInit("transceiver", config.log_level.c_str(), LOG_LOCAL7);
if (!sigProcLibSetup()) {
LOG(ALERT) << "Failed to initialize signal processing library";
return -1;
}
double RSSI;
double timingOffset, timingOffsetPrev = 0.0;
signalVector burst(2*BURST_LEN_FULL);
GSM::Time gsmTime;
bool syncedTo157bits = false; // We should syncronize to 156-157 frame structure only once
bool burst156_157 = false; // Set to true to enable 156-156-156-157 frame
int bitsReadExtra = 0; // set to 1 every 4 bursts and when TOA>1.0
int bitsToSkip = 0; // set to 1 when TOA<0.0
unsigned berBurstsAveraged = 0;
PRBS9 prbs;
BEREstimator berEstimator(prbs);
// Configure output stream
std::cout << std::fixed;
std::cout << std::setprecision(2);
std::ifstream file (config.filename.c_str(), std::ifstream::binary);
// Read the first burst, but do not process it, because we need at least two bursts
// worth of data for reliable initial detection.
file.read((char*)burst.begin(), config.sps * BURST_LEN_BYTES);
{signalVector t = burst.segment(0, BURST_LEN_FULL); scaleVector(t, complex(SHRT_MAX)); }
#if 0
/* Distort signal */
{
signalVector burst_read = burst.segment(85,156);
std::ifstream file (config.filename.c_str(), std::ifstream::binary);
file.read((char*)burst_read.begin(), burst_read.size() * 2 * sizeof(float));
file.close();
}
#endif
#if 1
// Read more data and try burst detection until successful
while(file.read((char*)(burst.begin()+config.sps*BURST_LEN_FULL), config.sps*BURST_LEN_BYTES))
{
{signalVector t = burst.segment(BURST_LEN_FULL, BURST_LEN_FULL); scaleVector(t, complex(SHRT_MAX)); }
bool found = processBurst(config, burst, BURST_LEN_FULL, RSSI, timingOffset, berEstimator);
std::cout << "RSSI: " << RSSI << " dBFS" << std::endl;
if (found) {
gsmTime.incTN();
berBurstsAveraged++;
break;
}
burst.segmentMove(config.sps*BURST_LEN_FULL, 0, config.sps*BURST_LEN_FULL);
}
// Align stream to burst
int offsetInt = (int)timingOffset;
burst.segmentMove(config.sps*(BURST_LEN_FULL+offsetInt), 0, config.sps*(BURST_LEN_FULL-offsetInt));
{signalVector t = burst.segment(0, BURST_LEN_FULL-offsetInt); scaleVector(t, complex(1.0/SHRT_MAX)); }
file.read((char*)(burst.begin()+config.sps*(BURST_LEN_FULL-offsetInt)), config.sps*offsetInt*SAMPLE_SIZE_BYTES);
#endif
// Resize burst vector to hold only one burst, because demodulation code
// always decode the full vector size.
burst.shrink(BURST_LEN_FULL+1);
// Process the rest of the stream
do {
{signalVector t = burst.segment(0, BURST_LEN_FULL); scaleVector(t, complex(SHRT_MAX)); }
processBurst(config, burst, (config.type==RACH)?config.max_expected_delay_ab:config.max_expected_delay_ab,
RSSI, timingOffset, berEstimator);
if (burst156_157 && !syncedTo157bits && timingOffset - timingOffsetPrev > .75) {
std::cout << "TOA adjust: Found a 157-bit burst, reset TN to mark it" << std::endl;
gsmTime.TN(2);
timingOffset -= 1.0;
// Make sure we do this adjustment only once.
syncedTo157bits = true;
} else {
gsmTime.incTN();
}
bitsToSkip = 0;
bitsReadExtra = 0;
if (timingOffset < 0.0) {
std::cout << "TOA adjust: skip a bit" << std::endl;
burst[0] = 0;
bitsToSkip = 1;
bitsReadExtra--;
}
bitsReadExtra += (gsmTime.TN()%4 == 0);
if (timingOffset > 1.1) {
std::cout << "TOA adjust: add extra bit" << std::endl;
bitsReadExtra++;
}
std::cout << "Clock: " << gsmTime;
std::cout << " RSSI: " << RSSI << " dBFS";
std::cout << " Error bits: " << berEstimator.errorBits() << " Total bits: " << berEstimator.totalBits()
<< " BER: " << 100.0*berEstimator.errorBits() / berEstimator.totalBits() << "%" << std::endl;
berBurstsAveraged++;
// Never reset if config.ber_burst_avg is 0
if (config.ber_burst_avg > 0 && berBurstsAveraged >= config.ber_burst_avg) {
berBurstsAveraged = 0;
berEstimator.reset();
}
std::cout << "bitsReadExtra: " << bitsReadExtra << " bitsToSkip: " << bitsToSkip << std::endl;
timingOffsetPrev = timingOffset;
} while(file.read((char*)(burst.begin()+bitsToSkip), config.sps*(BURST_LEN_BYTES+SAMPLE_SIZE_BYTES*bitsReadExtra)));
std::cout << "End of file reached" << std::endl;
file.close();
return 0;
}

View File

@@ -0,0 +1,334 @@
/*
* Copyright (C) 2017 Alexander Chemeris <Alexander.Chemeris@fairwaves.co>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <limits.h>
#include <fstream>
#include <iomanip>
#include <endian.h> // for byte order manipulation
#include "Logger.h"
#include "sigProcLib.h"
#include "GSMCommon.h"
#include "BitVector.h"
#include "Configuration.h"
extern "C" {
#include "convolve.h"
#include "convert.h"
}
#define DEFAULT_SPS 4
#define DEFAULT_SEARCH_WINDOW 30
// Tail + data + stealing + midamble + guard (without the last 0.25)
#define BURST_LEN_FULL 156
// Tail + data + stealing + midamble
#define BURST_LEN_ACTIVE 148
// Tail + data + stealing + midamble - 2*0.5
#define BURST_LEN_USEFUL 147
// Size of a sample in bytes as stores in a file
#define SAMPLE_SIZE_BYTES (2 * sizeof(float))
// Burst length in bytes as stored in a file
#define BURST_LEN_BYTES (BURST_LEN_FULL * SAMPLE_SIZE_BYTES)
ConfigurationTable gConfig;
enum FileType {
FLOAT_NORM_LE, ///< Float -1..+1 Little Endian
FLOAT16_LE, ///< Float -32767..+32767 Little Endian
SIGNED16_LE, ///< Integer -32767..+32767 Little Endian
SIGNED16_BE, ///< Integer -32767..+32767 Big Endian (Keysight waveform format)
};
struct trx_config {
std::string log_level;
unsigned sps;
unsigned tsc;
double full_scale;
bool edge;
CorrType type;
std::string filename;
FileType file_type;
};
std::ostream& operator<<(std::ostream& os, FileType ftype)
{
switch(ftype)
{
case FLOAT_NORM_LE:
os << "float";
break;
case FLOAT16_LE:
os << "float16";
break;
case SIGNED16_LE:
os << "signed16";
break;
case SIGNED16_BE:
os << "signed16be";
break;
default:
assert(!"unknown file type");
}
return os;
}
void writeBurstFloatNorm(std::ofstream& os, const signalVector& v)
{
os.write((char*)v.begin(), v.size() * 2 * sizeof(float));
}
void writeBurstFloat16LE(std::ofstream& os, const signalVector& v)
{
const complex *c = v.begin();
for (size_t i=0; i<v.size(); i++, c++) {
float iq[2];
iq[0] = c->real()*SHRT_MAX;
iq[1] = c->imag()*SHRT_MAX;
os.write((char*)&iq, 2*sizeof(float));
}
}
void writeBurstSigned16LE(std::ofstream& os, const signalVector& v)
{
const complex *c = v.begin();
for (size_t i=0; i<v.size(); i++, c++) {
int16_t iq[2];
iq[0] = c->real()*SHRT_MAX;
iq[1] = c->imag()*SHRT_MAX;
iq[0] = htole16(iq[0]);
iq[1] = htole16(iq[1]);
os.write((char*)&iq, 2*sizeof(int16_t));
}
}
void writeBurstSigned16BE(std::ofstream& os, const signalVector& v)
{
const complex *c = v.begin();
for (size_t i=0; i<v.size(); i++, c++) {
int16_t iq[2];
iq[0] = c->real()*SHRT_MAX;
iq[1] = c->imag()*SHRT_MAX;
iq[0] = htobe16(iq[0]);
iq[1] = htobe16(iq[1]);
os.write((char*)&iq, 2*sizeof(int16_t));
}
}
void writeBurst(std::ofstream& os, const signalVector& v, FileType ftype)
{
switch(ftype)
{
case FLOAT_NORM_LE:
writeBurstFloatNorm(os, v);
break;
case FLOAT16_LE:
writeBurstFloat16LE(os, v);
break;
case SIGNED16_LE:
writeBurstSigned16LE(os, v);
break;
case SIGNED16_BE:
writeBurstSigned16BE(os, v);
break;
default:
assert(!"unknown file type");
}
}
// Setup configuration values
static void print_config(struct trx_config *config)
{
std::ostringstream ost("");
ost << "Config Settings" << std::endl;
ost << " Destination file name........ " << config->filename << std::endl;
ost << " Destination file type........ " << config->file_type << std::endl;
ost << " Log Level.................... " << config->log_level << std::endl;
ost << " Tx Samples-per-Symbol........ " << config->sps << std::endl;
ost << " EDGE support................. " << (config->edge ? "Enabled" : "Disabled") << std::endl;
ost << " Burst type................... " << config->type << std::endl;
ost << " Burst TSC.................... " << config->tsc << std::endl;
ost << " Signal full scale............ " << config->full_scale << std::endl;
std::cout << ost << std::endl;
}
static void print_help()
{
fprintf(stdout,
"This utility generates waveform files aka IQ binary files in a number of formats"
"to use them as input to osmo-trx-dec or load them into signal generators.\n"
"\n"
"Options:\n"
" -h This text\n"
" -l LEVEL Logging level (%s)\n"
" -e Enable EDGE receiver\n"
" -s SPS Samples-per-symbol (1 or 4, default: %d)\n"
" -t TSC Burst training sequence (0 to 7, default: 0)\n"
" -f FILE File to write generated bursts to\n"
" -F FILETYPE Format of the file - float, float16, signed16, signed16be (default: f16)\n"
" Note: Keysight waveform format is signed16be. osmo-trx-dec accepts float16.\n",
"EMERG, ALERT, CRT, ERR, WARNING, NOTICE, INFO, DEBUG",
DEFAULT_SPS);
}
FileType option_to_file_type(const std::string &optarg)
{
if (optarg == "float") {
return FLOAT_NORM_LE;
} else if (optarg == "float16") {
return FLOAT16_LE;
} else if (optarg == "signed16") {
return SIGNED16_LE;
} else if (optarg == "signed16be") {
return SIGNED16_BE;
} else {
return (FileType)-1;
}
}
static bool handle_options(int argc, char **argv, struct trx_config *config)
{
int option;
config->log_level = "NOTICE";
config->sps = DEFAULT_SPS;
config->tsc = 0;
config->full_scale = SHRT_MAX;
config->edge = false;
config->type = TSC;
config->file_type = FLOAT16_LE;
while ((option = getopt(argc, argv, "ls:et:f:F:h")) != -1) {
switch (option) {
case 'l':
config->log_level = optarg;
break;
case 's':
config->sps = atoi(optarg);
break;
case 'e':
config->edge = true;
break;
case 't':
config->tsc = atoi(optarg);
break;
case 'f':
config->filename = optarg;
break;
case 'F':
config->file_type = option_to_file_type(optarg);
break;
case 'h':
default:
print_help();
exit(0);
}
}
if ((config->sps != 1) && (config->sps != 4)) {
printf("ERROR: Unsupported samples-per-symbol %i\n\n", config->sps);
return false;
}
if (config->edge && (config->sps != 4)) {
printf("ERROR: EDGE only supported at 4 samples per symbol\n\n");
return false;
}
if (config->tsc > 7) {
printf("ERROR: Invalid training sequence %i\n\n", config->tsc);
return false;
}
if (config->filename.length() == 0) {
printf("ERROR: No output file name specified\n\n");
return false;
}
if (config->file_type < 0) {
printf("ERROR: Wrong output file format\n\n");
}
return true;
}
int main(int argc, char *argv[])
{
struct trx_config config;
#ifdef HAVE_SSE3
printf("Info: SSE3 support compiled in");
if (__builtin_cpu_supports("sse3"))
printf(" and supported by CPU\n");
else
printf(", but not supported by CPU\n");
#endif
#ifdef HAVE_SSE4_1
printf("Info: SSE4.1 support compiled in");
if (__builtin_cpu_supports("sse4.1"))
printf(" and supported by CPU\n");
else
printf(", but not supported by CPU\n");
#endif
convolve_init();
convert_init();
// Process command line options and print config to screen
if (!handle_options(argc, argv, &config)) {
print_help();
exit(0);
}
print_config(&config);
gLogInit("transceiver", config.log_level.c_str(), LOG_LOCAL7);
if (!sigProcLibSetup()) {
LOG(ALERT) << "Failed to initialize signal processing library";
return -1;
}
signalVector burst(2*BURST_LEN_FULL);
GSM::Time gsmTime;
PRBS9 prbs;
// Configure output stream
std::cout << std::fixed;
std::cout << std::setprecision(2);
std::ofstream file (config.filename.c_str(), std::ifstream::binary);
for (int i=0; i<511; i++) {
signalVector *signal = genRandNormalBurst(config.tsc, config.sps, gsmTime.TN(), prbs);
writeBurst(file, *signal, config.file_type);
gsmTime.incTN();
}
file.close();
std::cout << "Done!" << std::endl;
return 0;
}

482
Transceiver52M/osmo-trx.cpp Normal file
View File

@@ -0,0 +1,482 @@
/*
* Copyright (C) 2013 Thomas Tsou <tom@tsou.cc>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "Transceiver.h"
#include "radioDevice.h"
#include <time.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <GSMCommon.h>
#include <Logger.h>
#include <Configuration.h>
extern "C" {
#include "convolve.h"
#include "convert.h"
}
/* Samples-per-symbol for downlink path
* 4 - Uses precision modulator (more computation, less distortion)
* 1 - Uses minimized modulator (less computation, more distortion)
*
* Other values are invalid. Receive path (uplink) is always
* downsampled to 1 sps. Default to 4 sps for all cases.
*/
#define DEFAULT_TX_SPS 4
/*
* Samples-per-symbol for uplink (receiver) path
* Do not modify this value. EDGE configures 4 sps automatically on
* B200/B210 devices only. Use of 4 sps on the receive path for other
* configurations is not supported.
*/
#define DEFAULT_RX_SPS 1
/* Default configuration parameters */
#define DEFAULT_TRX_PORT 5700
#define DEFAULT_TRX_IP "127.0.0.1"
#define DEFAULT_CHANS 1
struct trx_config {
std::string log_level;
std::string addr;
std::string dev_args;
unsigned port;
unsigned tx_sps;
unsigned rx_sps;
unsigned chans;
unsigned rtsc;
unsigned rach_delay;
bool extref;
bool gpsref;
Transceiver::FillerType filler;
bool mcbts;
double offset;
double rssi_offset;
bool swap_channels;
bool edge;
};
ConfigurationTable gConfig;
volatile bool gshutdown = false;
/* Setup configuration values
* Don't query the existence of the Log.Level because it's a
* mandatory value. That is, if it doesn't exist, the configuration
* table will crash or will have already crashed. Everything else we
* can survive without and use default values if the database entries
* are empty.
*/
bool trx_setup_config(struct trx_config *config)
{
std::string refstr, fillstr, divstr, mcstr, edgestr;
if (config->mcbts && config->chans > 5) {
std::cout << "Unsupported number of channels" << std::endl;
return false;
}
edgestr = config->edge ? "Enabled" : "Disabled";
mcstr = config->mcbts ? "Enabled" : "Disabled";
if (config->extref)
refstr = "External";
else if (config->gpsref)
refstr = "GPS";
else
refstr = "Internal";
switch (config->filler) {
case Transceiver::FILLER_DUMMY:
fillstr = "Dummy bursts";
break;
case Transceiver::FILLER_ZERO:
fillstr = "Disabled";
break;
case Transceiver::FILLER_NORM_RAND:
fillstr = "Normal busrts with random payload";
break;
case Transceiver::FILLER_EDGE_RAND:
fillstr = "EDGE busrts with random payload";
break;
case Transceiver::FILLER_ACCESS_RAND:
fillstr = "Access busrts with random payload";
break;
}
std::ostringstream ost("");
ost << "Config Settings" << std::endl;
ost << " Log Level............... " << config->log_level << std::endl;
ost << " Device args............. " << config->dev_args << std::endl;
ost << " TRX Base Port........... " << config->port << std::endl;
ost << " TRX Address............. " << config->addr << std::endl;
ost << " Channels................ " << config->chans << std::endl;
ost << " Tx Samples-per-Symbol... " << config->tx_sps << std::endl;
ost << " Rx Samples-per-Symbol... " << config->rx_sps << std::endl;
ost << " EDGE support............ " << edgestr << std::endl;
ost << " Reference............... " << refstr << std::endl;
ost << " C0 Filler Table......... " << fillstr << std::endl;
ost << " Multi-Carrier........... " << mcstr << std::endl;
ost << " Tuning offset........... " << config->offset << std::endl;
ost << " RSSI to dBm offset...... " << config->rssi_offset << std::endl;
ost << " Swap channels........... " << config->swap_channels << std::endl;
std::cout << ost << std::endl;
return true;
}
/* Create radio interface
* The interface consists of sample rate changes, frequency shifts,
* channel multiplexing, and other conversions. The transceiver core
* accepts input vectors sampled at multiples of the GSM symbol rate.
* The radio interface connects the main transceiver with the device
* object, which may be operating some other rate.
*/
RadioInterface *makeRadioInterface(struct trx_config *config,
RadioDevice *usrp, int type)
{
RadioInterface *radio = NULL;
switch (type) {
case RadioDevice::NORMAL:
radio = new RadioInterface(usrp, config->tx_sps,
config->rx_sps, config->chans);
break;
case RadioDevice::RESAMP_64M:
case RadioDevice::RESAMP_100M:
radio = new RadioInterfaceResamp(usrp, config->tx_sps,
config->rx_sps);
break;
case RadioDevice::MULTI_ARFCN:
radio = new RadioInterfaceMulti(usrp, config->tx_sps,
config->rx_sps, config->chans);
break;
default:
LOG(ALERT) << "Unsupported radio interface configuration";
return NULL;
}
if (!radio->init(type)) {
LOG(ALERT) << "Failed to initialize radio interface";
return NULL;
}
return radio;
}
/* Create transceiver core
* The multi-threaded modem core operates at multiples of the GSM rate of
* 270.8333 ksps and consists of GSM specific modulation, demodulation,
* and decoding schemes. Also included are the socket interfaces for
* connecting to the upper layer stack.
*/
Transceiver *makeTransceiver(struct trx_config *config, RadioInterface *radio)
{
Transceiver *trx;
VectorFIFO *fifo;
trx = new Transceiver(config->port, config->addr.c_str(),
config->tx_sps, config->rx_sps, config->chans,
GSM::Time(3,0), radio, config->rssi_offset);
if (!trx->init(config->filler, config->rtsc,
config->rach_delay, config->edge)) {
LOG(ALERT) << "Failed to initialize transceiver";
delete trx;
return NULL;
}
for (size_t i = 0; i < config->chans; i++) {
fifo = radio->receiveFIFO(i);
if (fifo && trx->receiveFIFO(fifo, i))
continue;
LOG(ALERT) << "Could not attach FIFO to channel " << i;
delete trx;
return NULL;
}
return trx;
}
static void sig_handler(int signo)
{
fprintf(stdout, "Received shutdown signal");
gshutdown = true;
}
static void setup_signal_handlers()
{
if (signal(SIGINT, sig_handler) == SIG_ERR) {
fprintf(stderr, "Failed to install SIGINT signal handler\n");
exit(EXIT_FAILURE);
}
if (signal(SIGTERM, sig_handler) == SIG_ERR) {
fprintf(stderr, "Couldn't install SIGTERM signal handler\n");
exit( EXIT_FAILURE);
}
}
static void print_help()
{
fprintf(stdout, "Options:\n"
" -h This text\n"
" -a UHD device args\n"
" -l Logging level (%s)\n"
" -i IP address of GSM core\n"
" -p Base port number\n"
" -e Enable EDGE receiver\n"
" -m Enable multi-ARFCN transceiver (default=disabled)\n"
" -x Enable external 10 MHz reference\n"
" -g Enable GPSDO reference\n"
" -s Tx samples-per-symbol (1 or 4)\n"
" -b Rx samples-per-symbol (1 or 4)\n"
" -c Number of ARFCN channels (default=1)\n"
" -f Enable C0 filler table\n"
" -o Set baseband frequency offset (default=auto)\n"
" -r Random GMSK Normal Burst test mode with given TSC\n"
" -E Random 8-PSK Normal Burst test mode with given TSC\n"
" -A Random Access Burst test mode with delay\n"
" -R RSSI to dBm offset in dB (default=0)\n"
" -S Swap channels (UmTRX only)\n",
"EMERG, ALERT, CRT, ERR, WARNING, NOTICE, INFO, DEBUG");
}
static void handle_options(int argc, char **argv, struct trx_config *config)
{
int option;
config->log_level = "NOTICE";
config->addr = DEFAULT_TRX_IP;
config->port = DEFAULT_TRX_PORT;
config->tx_sps = DEFAULT_TX_SPS;
config->rx_sps = DEFAULT_RX_SPS;
config->chans = DEFAULT_CHANS;
config->rtsc = 0;
config->rach_delay = 0;
config->extref = false;
config->gpsref = false;
config->filler = Transceiver::FILLER_ZERO;
config->mcbts = false;
config->offset = 0.0;
config->rssi_offset = 0.0;
config->swap_channels = false;
config->edge = false;
while ((option = getopt(argc, argv, "ha:l:i:p:c:dmxgfo:s:b:r:E:A:R:Se")) != -1) {
switch (option) {
case 'h':
print_help();
exit(0);
break;
case 'a':
config->dev_args = optarg;
break;
case 'l':
config->log_level = optarg;
break;
case 'i':
config->addr = optarg;
break;
case 'p':
config->port = atoi(optarg);
break;
case 'c':
config->chans = atoi(optarg);
break;
case 'm':
config->mcbts = true;
break;
case 'x':
config->extref = true;
break;
case 'g':
config->gpsref = true;
break;
case 'f':
config->filler = Transceiver::FILLER_DUMMY;
break;
case 'o':
config->offset = atof(optarg);
break;
case 's':
config->tx_sps = atoi(optarg);
break;
case 'b':
config->rx_sps = atoi(optarg);
break;
case 'r':
config->rtsc = atoi(optarg);
config->filler = Transceiver::FILLER_NORM_RAND;
break;
case 'E':
config->rtsc = atoi(optarg);
config->filler = Transceiver::FILLER_EDGE_RAND;
break;
case 'A':
config->rach_delay = atoi(optarg);
config->filler = Transceiver::FILLER_ACCESS_RAND;
break;
case 'R':
config->rssi_offset = atof(optarg);
break;
case 'S':
config->swap_channels = true;
break;
case 'e':
config->edge = true;
break;
default:
print_help();
exit(0);
}
}
/* Force 4 SPS for EDGE or multi-ARFCN configurations */
if ((config->edge) || (config->mcbts)) {
config->tx_sps = 4;
config->rx_sps = 4;
}
if (config->gpsref && config->extref) {
printf("External and GPSDO references unavailable at the same time\n\n");
goto bad_config;
}
if (!config->edge && (config->filler == Transceiver::FILLER_EDGE_RAND)) {
printf("Can't enable EDGE filler when EDGE mode is disabled\n\n");
goto bad_config;
}
if ((config->tx_sps != 1) && (config->tx_sps != 4) &&
(config->rx_sps != 1) && (config->rx_sps != 4)) {
printf("Unsupported samples-per-symbol %i\n\n", config->tx_sps);
goto bad_config;
}
if (config->rtsc > 7) {
printf("Invalid training sequence %i\n\n", config->rtsc);
goto bad_config;
}
if (config->rach_delay > 68) {
printf("RACH delay is too big %i\n\n", config->rach_delay);
goto bad_config;
}
return;
bad_config:
print_help();
exit(0);
}
int main(int argc, char *argv[])
{
int type, chans, ref;
RadioDevice *usrp;
RadioInterface *radio = NULL;
Transceiver *trx = NULL;
RadioDevice::InterfaceType iface = RadioDevice::NORMAL;
struct trx_config config;
#ifdef HAVE_SSE3
printf("Info: SSE3 support compiled in");
if (__builtin_cpu_supports("sse3"))
printf(" and supported by CPU\n");
else
printf(", but not supported by CPU\n");
#endif
#ifdef HAVE_SSE4_1
printf("Info: SSE4.1 support compiled in");
if (__builtin_cpu_supports("sse4.1"))
printf(" and supported by CPU\n");
else
printf(", but not supported by CPU\n");
#endif
convolve_init();
convert_init();
handle_options(argc, argv, &config);
setup_signal_handlers();
/* Check database sanity */
if (!trx_setup_config(&config)) {
std::cerr << "Config: Database failure - exiting" << std::endl;
return EXIT_FAILURE;
}
gLogInit("transceiver", config.log_level.c_str(), LOG_LOCAL7);
srandom(time(NULL));
/* Create the low level device object */
if (config.mcbts)
iface = RadioDevice::MULTI_ARFCN;
if (config.extref)
ref = RadioDevice::REF_EXTERNAL;
else if (config.gpsref)
ref = RadioDevice::REF_GPS;
else
ref = RadioDevice::REF_INTERNAL;
usrp = RadioDevice::make(config.tx_sps, config.rx_sps, iface,
config.chans, config.offset);
type = usrp->open(config.dev_args, ref, config.swap_channels);
if (type < 0) {
LOG(ALERT) << "Failed to create radio device" << std::endl;
goto shutdown;
}
/* Setup the appropriate device interface */
radio = makeRadioInterface(&config, usrp, type);
if (!radio)
goto shutdown;
/* Create the transceiver core */
trx = makeTransceiver(&config, radio);
if (!trx)
goto shutdown;
chans = trx->numChans();
std::cout << "-- Transceiver active with "
<< chans << " channel(s)" << std::endl;
while (!gshutdown)
sleep(1);
shutdown:
std::cout << "Shutting down transceiver..." << std::endl;
delete trx;
delete radio;
delete usrp;
return 0;
}

View File

@@ -0,0 +1,228 @@
/*
* Segmented Ring Buffer
*
* Copyright (C) 2015 Ettus Research LLC
*
* Author: Tom Tsou <tom@tsou.cc>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* See the COPYING file in the main directory for details.
*/
#include <string.h>
#include <iostream>
#include "radioBuffer.h"
RadioBuffer::RadioBuffer(size_t numSegments, size_t segmentLen,
size_t hLen, bool outDirection)
: writeIndex(0), readIndex(0), availSamples(0)
{
if (!outDirection)
hLen = 0;
buffer = new float[2 * (hLen + numSegments * segmentLen)];
bufferLen = numSegments * segmentLen;
segments.resize(numSegments);
for (size_t i = 0; i < numSegments; i++)
segments[i] = &buffer[2 * (hLen + i * segmentLen)];
this->outDirection = outDirection;
this->numSegments = numSegments;
this->segmentLen = segmentLen;
this->hLen = hLen;
}
RadioBuffer::~RadioBuffer()
{
delete[] buffer;
}
void RadioBuffer::reset()
{
writeIndex = 0;
readIndex = 0;
availSamples = 0;
}
/*
* Output direction
*
* Return a pointer to the oldest segment or NULL if a complete segment is not
* available.
*/
const float *RadioBuffer::getReadSegment()
{
if (!outDirection) {
std::cout << "Invalid direction" << std::endl;
return NULL;
}
if (availSamples < segmentLen) {
std::cout << "Not enough samples " << std::endl;
std::cout << availSamples << " available per segment "
<< segmentLen << std::endl;
return NULL;
}
size_t num = readIndex / segmentLen;
if (num >= numSegments) {
std::cout << "Invalid segment" << std::endl;
return NULL;
} else if (!num) {
memcpy(buffer,
&buffer[2 * bufferLen],
hLen * 2 * sizeof(float));
}
availSamples -= segmentLen;
readIndex = (readIndex + segmentLen) % bufferLen;
return segments[num];
}
/*
* Output direction
*
* Write a non-segment length of samples to the buffer.
*/
bool RadioBuffer::write(const float *wr, size_t len)
{
if (!outDirection) {
std::cout << "Invalid direction" << std::endl;
return false;
}
if (availSamples + len > bufferLen) {
std::cout << "Insufficient space" << std::endl;
std::cout << bufferLen - availSamples << " available per write "
<< len << std::endl;
return false;
}
if (writeIndex + len <= bufferLen) {
memcpy(&buffer[2 * (writeIndex + hLen)],
wr, len * 2 * sizeof(float));
} else {
size_t len0 = bufferLen - writeIndex;
size_t len1 = len - len0;
memcpy(&buffer[2 * (writeIndex + hLen)], wr, len0 * 2 * sizeof(float));
memcpy(&buffer[2 * hLen], &wr[2 * len0], len1 * 2 * sizeof(float));
}
availSamples += len;
writeIndex = (writeIndex + len) % bufferLen;
return true;
}
bool RadioBuffer::zero(size_t len)
{
if (!outDirection) {
std::cout << "Invalid direction" << std::endl;
return false;
}
if (availSamples + len > bufferLen) {
std::cout << "Insufficient space" << std::endl;
std::cout << bufferLen - availSamples << " available per zero "
<< len << std::endl;
return false;
}
if (writeIndex + len <= bufferLen) {
memset(&buffer[2 * (writeIndex + hLen)],
0, len * 2 * sizeof(float));
} else {
size_t len0 = bufferLen - writeIndex;
size_t len1 = len - len0;
memset(&buffer[2 * (writeIndex + hLen)], 0, len0 * 2 * sizeof(float));
memset(&buffer[2 * hLen], 0, len1 * 2 * sizeof(float));
}
availSamples += len;
writeIndex = (writeIndex + len) % bufferLen;
return true;
}
/*
* Input direction
*/
float *RadioBuffer::getWriteSegment()
{
if (outDirection) {
std::cout << "Invalid direction" << std::endl;
return NULL;
}
if (bufferLen - availSamples < segmentLen) {
std::cout << "Insufficient samples" << std::endl;
std::cout << bufferLen - availSamples
<< " available for segment " << segmentLen
<< std::endl;
return NULL;
}
if (writeIndex % segmentLen) {
std::cout << "Internal segment error" << std::endl;
return NULL;
}
size_t num = writeIndex / segmentLen;
if (num >= numSegments)
return NULL;
availSamples += segmentLen;
writeIndex = (writeIndex + segmentLen) % bufferLen;
return segments[num];
}
bool RadioBuffer::zeroWriteSegment()
{
float *segment = getWriteSegment();
if (!segment)
return false;
memset(segment, 0, segmentLen * 2 * sizeof(float));
return true;
}
bool RadioBuffer::read(float *rd, size_t len)
{
if (outDirection) {
std::cout << "Invalid direction" << std::endl;
return false;
}
if (availSamples < len) {
std::cout << "Insufficient samples" << std::endl;
std::cout << availSamples << " available for "
<< len << std::endl;
return false;
}
if (readIndex + len <= bufferLen) {
memcpy(rd, &buffer[2 * readIndex], len * 2 * sizeof(float));
} else {
size_t len0 = bufferLen - readIndex;
size_t len1 = len - len0;
memcpy(rd, &buffer[2 * readIndex], len0 * 2 * sizeof(float));
memcpy(&rd[2 * len0], buffer, len1 * 2 * sizeof(float));
}
availSamples -= len;
readIndex = (readIndex + len) % bufferLen;
return true;
}

View File

@@ -0,0 +1,45 @@
#include <stdlib.h>
#include <stddef.h>
#include <vector>
class RadioBuffer {
public:
RadioBuffer(size_t numSegments, size_t segmentLen,
size_t hLen, bool outDirection);
~RadioBuffer();
const size_t getSegmentLen() { return segmentLen; }
const size_t getNumSegments() { return numSegments; }
const size_t getAvailSamples() { return availSamples; }
const size_t getAvailSegments() { return availSamples / segmentLen; }
const size_t getFreeSamples()
{
return bufferLen - availSamples;
}
const size_t getFreeSegments()
{
return getFreeSamples() / segmentLen;
}
void reset();
/* Output direction */
const float *getReadSegment();
bool write(const float *wr, size_t len);
bool zero(size_t len);
/* Input direction */
float *getWriteSegment();
bool zeroWriteSegment();
bool read(float *rd, size_t len);
private:
size_t writeIndex, readIndex, availSamples;
size_t bufferLen, numSegments, segmentLen, hLen;
float *buffer;
std::vector<float *> segments;
bool outDirection;
};

View File

@@ -23,32 +23,27 @@
void RadioClock::set(const GSM::Time& wTime)
{
mLock.lock();
ScopedLock lock(mLock);
mClock = wTime;
updateSignal.signal();
mLock.unlock();
}
void RadioClock::incTN()
{
mLock.lock();
ScopedLock lock(mLock);
mClock.incTN();
updateSignal.signal();
mLock.unlock();
}
GSM::Time RadioClock::get()
{
mLock.lock();
ScopedLock lock(mLock);
GSM::Time retVal = mClock;
mLock.unlock();
return retVal;
}
void RadioClock::wait()
{
mLock.lock();
ScopedLock lock(mLock);
updateSignal.wait(mLock,1);
mLock.unlock();
}

View File

@@ -16,12 +16,14 @@
#define __RADIO_DEVICE_H__
#include <string>
#include <vector>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define GSMRATE 1625e3/6
#define GSMRATE (1625e3/6)
#define MCBTS_SPACING 800000.0
/** a 64-bit virtual timestamp for radio data */
typedef unsigned long long TIMESTAMP;
@@ -34,14 +36,26 @@ class RadioDevice {
enum TxWindowType { TX_WINDOW_USRP1, TX_WINDOW_FIXED };
/* Radio interface types */
enum RadioInterfaceType { NORMAL, RESAMP };
enum InterfaceType {
NORMAL,
RESAMP_64M,
RESAMP_100M,
MULTI_ARFCN,
};
static RadioDevice *make(int sps, bool skipRx = false);
enum ReferenceType {
REF_INTERNAL,
REF_EXTERNAL,
REF_GPS,
};
virtual ~RadioDevice() {};
static RadioDevice *make(size_t tx_sps, size_t rx_sps, InterfaceType type,
size_t chans = 1, double offset = 0.0);
/** Initialize the USRP */
virtual int open(const std::string &args)=0;
virtual int open(const std::string &args, int ref, bool swap_channels)=0;
virtual ~RadioDevice() { }
/** Start the USRP */
virtual bool start()=0;
@@ -53,7 +67,7 @@ class RadioDevice {
virtual enum TxWindowType getWindowType()=0;
/** Enable thread priority */
virtual void setPriority()=0;
virtual void setPriority(float prio = 0.5) = 0;
/**
Read samples from the radio.
@@ -65,9 +79,9 @@ class RadioDevice {
@param RSSI The received signal strength of the read result
@return The number of samples actually read
*/
virtual int readSamples(short **buf, int chans, int len, TIMESTAMP timestamp,
bool *overrun = NULL, bool *underrun = NULL,
unsigned *RSSI = NULL)=0;
virtual int readSamples(std::vector<short *> &bufs, int len, bool *overrun,
TIMESTAMP timestamp = 0xffffffff, bool *underrun = 0,
unsigned *RSSI = 0) = 0;
/**
Write samples to the radio.
@param buf Contains the data to be written.
@@ -77,17 +91,17 @@ class RadioDevice {
@param isControl Set if data is a control packet, e.g. a ping command
@return The number of samples actually written
*/
virtual int writeSamples(short **buf, int chans, int len, TIMESTAMP timestamp,
bool *underrun = NULL, bool isControl = false)=0;
virtual int writeSamples(std::vector<short *> &bufs, int len, bool *underrun,
TIMESTAMP timestamp, bool isControl = false) = 0;
/** Update the alignment between the read and write timestamps */
virtual bool updateAlignment(TIMESTAMP timestamp)=0;
/** Set the transmitter frequency */
virtual bool setTxFreq(double wFreq, int chan = 0)=0;
virtual bool setTxFreq(double wFreq, size_t chan = 0) = 0;
/** Set the receiver frequency */
virtual bool setRxFreq(double wFreq, int chan = 0)=0;
virtual bool setRxFreq(double wFreq, size_t chan = 0) = 0;
/** Returns the starting write Timestamp*/
virtual TIMESTAMP initialWriteTimestamp(void)=0;
@@ -102,10 +116,10 @@ class RadioDevice {
virtual double fullScaleOutputValue()=0;
/** sets the receive chan gain, returns the gain setting **/
virtual double setRxGain(double dB, int chan = 0)=0;
virtual double setRxGain(double dB, size_t chan = 0) = 0;
/** gets the current receive gain **/
virtual double getRxGain(int chan = 0)=0;
virtual double getRxGain(size_t chan = 0) = 0;
/** return maximum Rx Gain **/
virtual double maxRxGain(void) = 0;
@@ -114,7 +128,7 @@ class RadioDevice {
virtual double minRxGain(void) = 0;
/** sets the transmit chan gain, returns the gain setting **/
virtual double setTxGain(double dB, int chan = 0)=0;
virtual double setTxGain(double dB, size_t chan = 0) = 0;
/** return maximum Tx Gain **/
virtual double maxTxGain(void) = 0;
@@ -122,18 +136,13 @@ class RadioDevice {
/** return minimum Tx Gain **/
virtual double minTxGain(void) = 0;
/** set and return antennas selection **/
virtual void setTxAntenna(std::string &name) = 0;
virtual void setRxAntenna(std::string &name) = 0;
virtual std::string getRxAntenna() = 0;
virtual std::string getTxAntenna() = 0;
/** Return internal status values */
virtual double getTxFreq(int chan = 0)=0;
virtual double getRxFreq(int chan = 0)=0;
virtual double getTxFreq(size_t chan = 0) = 0;
virtual double getRxFreq(size_t chan = 0) = 0;
virtual double getSampleRate()=0;
virtual double numberRead()=0;
virtual double numberWritten()=0;
};
#endif

View File

@@ -1,79 +1,85 @@
/*
* Copyright 2008, 2009, 2012 Free Software Foundation, Inc.
*
* This software is distributed under the terms of the GNU Affero Public License.
* See the COPYING file in the main directory for details.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
* Radio device interface
*
* Copyright (C) 2008-2014 Free Software Foundation, Inc.
* Copyright (C) 2015 Ettus Research LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* See the COPYING file in the main directory for details.
*/
#include "radioInterface.h"
#include "Resampler.h"
#include <Logger.h>
#include <PRBS.h>
bool started = false;
/* Device side buffers */
static short *rx_buf[CHAN_MAX];
static short *tx_buf[CHAN_MAX];
/* Complex float to short conversion */
static void floatToShort(short *out, float *in, int num)
{
for (int i = 0; i < num; i++) {
out[2 * i + 0] = (short) in[2 * i + 0];
out[2 * i + 1] = (short) in[2 * i + 1];
}
extern "C" {
#include "convert.h"
}
/* Complex short to float conversion */
static void shortToFloat(float *out, short *in, int num)
{
for (int i = 0; i < num; i++) {
out[2 * i + 0] = (float) in[2 * i + 0];
out[2 * i + 1] = (float) in[2 * i + 1];
}
}
#define CHUNK 625
#define NUMCHUNKS 4
RadioInterface::RadioInterface(RadioDevice *wRadio,
int wChanM,
int wSPS,
int wReceiveOffset,
GSM::Time wStartTime)
: mChanM(wChanM), underrun(false), sendCursor(0), rcvCursor(0), mOn(false),
mRadio(wRadio), receiveOffset(wReceiveOffset), samplesPerSymbol(wSPS),
powerScaling(1.0), loadTest(false)
RadioInterface::RadioInterface(RadioDevice *wRadio, size_t tx_sps,
size_t rx_sps, size_t chans,
int wReceiveOffset, GSM::Time wStartTime)
: mRadio(wRadio), mSPSTx(tx_sps), mSPSRx(rx_sps), mChans(chans),
underrun(false), overrun(false), receiveOffset(wReceiveOffset), mOn(false)
{
mClock.set(wStartTime);
}
RadioInterface::~RadioInterface(void)
{
if (mOn) {
mRadio->stop();
close();
close();
}
for (int i = 0; i < mChanM; i++) {
if (rcvBuffer[i] != NULL)
delete rcvBuffer[i];
if (sendBuffer[i] != NULL)
delete sendBuffer[i];
}
bool RadioInterface::init(int type)
{
if ((type != RadioDevice::NORMAL) || !mChans) {
LOG(ALERT) << "Invalid configuration";
return false;
}
close();
sendBuffer.resize(mChans);
recvBuffer.resize(mChans);
convertSendBuffer.resize(mChans);
convertRecvBuffer.resize(mChans);
mReceiveFIFO.resize(mChans);
powerScaling.resize(mChans);
for (size_t i = 0; i < mChans; i++) {
sendBuffer[i] = new RadioBuffer(NUMCHUNKS, CHUNK * mSPSTx, 0, true);
recvBuffer[i] = new RadioBuffer(NUMCHUNKS, CHUNK * mSPSRx, 0, false);
convertSendBuffer[i] = new short[CHUNK * mSPSTx * 2];
convertRecvBuffer[i] = new short[CHUNK * mSPSRx * 2];
powerScaling[i] = 1.0;
}
return true;
}
void RadioInterface::close()
{
sendBuffer.resize(0);
recvBuffer.resize(0);
convertSendBuffer.resize(0);
convertRecvBuffer.resize(0);
}
double RadioInterface::fullScaleInputValue(void) {
@@ -84,111 +90,112 @@ double RadioInterface::fullScaleOutputValue(void) {
return mRadio->fullScaleOutputValue();
}
void RadioInterface::setPowerAttenuation(double atten, int chan)
int RadioInterface::setPowerAttenuation(int atten, size_t chan)
{
double rfGain, digAtten;
rfGain = mRadio->setTxGain(mRadio->maxTxGain() - atten, chan);
digAtten = atten - mRadio->maxTxGain() + rfGain;
if (chan >= mChans) {
LOG(ALERT) << "Invalid channel requested";
return -1;
}
if (atten < 0.0)
atten = 0.0;
rfGain = mRadio->setTxGain(mRadio->maxTxGain() - (double) atten, chan);
digAtten = (double) atten - mRadio->maxTxGain() + rfGain;
if (digAtten < 1.0)
powerScaling = 1.0;
powerScaling[chan] = 1.0;
else
powerScaling = 1.0/sqrt(pow(10, (digAtten/10.0)));
powerScaling[chan] = 1.0 / sqrt(pow(10, digAtten / 10.0));
return atten;
}
int RadioInterface::radioifyVector(signalVector &wVector,
float *retVector,
float scale,
bool zero)
size_t chan, bool zero)
{
int i;
signalVector::iterator itr = wVector.begin();
if (zero) {
memset(retVector, 0, wVector.size() * 2 * sizeof(float));
return wVector.size();
}
for (i = 0; i < wVector.size(); i++) {
retVector[2 * i + 0] = itr->real() * scale;
retVector[2 * i + 1] = itr->imag() * scale;
itr++;
}
if (zero)
sendBuffer[chan]->zero(wVector.size());
else
sendBuffer[chan]->write((float *) wVector.begin(), wVector.size());
return wVector.size();
}
int RadioInterface::unRadioifyVector(float *floatVector, int offset,
signalVector &newVector)
int RadioInterface::unRadioifyVector(signalVector *newVector, size_t chan)
{
int i;
signalVector::iterator itr = newVector.begin();
for (i = 0; i < newVector.size(); i++) {
*itr++ = Complex<float>(floatVector[offset + 2 * i + 0],
floatVector[offset + 2 * i + 1]);
if (newVector->size() > recvBuffer[chan]->getAvailSamples()) {
LOG(ALERT) << "Insufficient number of samples in receive buffer";
return -1;
}
return newVector.size();
recvBuffer[chan]->read((float *) newVector->begin(), newVector->size());
return newVector->size();
}
bool RadioInterface::tuneTx(double freq, int chan)
bool RadioInterface::tuneTx(double freq, size_t chan)
{
return mRadio->setTxFreq(freq, chan);
}
bool RadioInterface::tuneRx(double freq, int chan)
bool RadioInterface::tuneRx(double freq, size_t chan)
{
return mRadio->setRxFreq(freq, chan);
}
bool RadioInterface::start()
{
int i;
if (mOn)
return true;
LOG(INFO) << "Starting radio device";
#ifdef USRP1
mAlignRadioServiceLoopThread.start((void * (*)(void*))AlignRadioServiceLoopAdapter,
(void*)this);
#endif
if (!mRadio->start())
return false;
mOn = true;
#ifdef USRP1
mAlignRadioServiceLoopThread = new Thread(32768);
mAlignRadioServiceLoopThread->start((void * (*)(void*))AlignRadioServiceLoopAdapter,
(void*)this);
#endif
writeTimestamp = mRadio->initialWriteTimestamp();
readTimestamp = mRadio->initialReadTimestamp();
for (i = 0; i < mChanM; i++) {
sendBuffer[i] = new float[8*2*INCHUNK];
rcvBuffer[i] = new float[8*2*OUTCHUNK];
for (size_t i = 0; i < mChans; i++) {
sendBuffer[i]->reset();
recvBuffer[i]->reset();
}
/* Init I/O specific variables if applicable */
init();
writeTimestamp = mRadio->initialWriteTimestamp();
readTimestamp = mRadio->initialReadTimestamp();
mRadio->start();
LOG(DEBUG) << "Radio started";
mRadio->updateAlignment(writeTimestamp-10000);
mRadio->updateAlignment(writeTimestamp-10000);
mRadio->updateAlignment(writeTimestamp-10000);
mOn = true;
LOG(INFO) << "Radio started";
return true;
}
/*
* Stop the radio device
*
* This is a pass-through call to the device interface. Because the underlying
* stop command issuance generally doesn't return confirmation on device status,
* this call will only return false if the device is already stopped.
*/
bool RadioInterface::stop()
{
if (!mOn)
if (!mOn || !mRadio->stop())
return false;
mOn = false;
mRadio->stop();
return true;
}
#ifdef USRP1
void *AlignRadioServiceLoopAdapter(RadioInterface *radioInterface)
{
while (radioInterface->on()) {
while (1) {
radioInterface->alignRadio();
pthread_testcancel();
}
@@ -201,154 +208,151 @@ void RadioInterface::alignRadio() {
}
#endif
void RadioInterface::driveTransmitRadio(signalVector **radioBurst, bool *zeroBurst)
{
int i;
if (!mOn)
return;
for (i = 0; i < mChanM; i++) {
radioifyVector(*radioBurst[i], sendBuffer[i] + 2 * sendCursor,
powerScaling, zeroBurst[i]);
}
/*
* All bursts should be the same size since all transceivers are
* tied with a single clock in the radio interface.
*/
sendCursor += radioBurst[0]->size();
pushBuffer();
}
static inline void shiftRxBuffers(float **buf, int offset, int len, int chanM)
{
for (int i = 0; i < chanM; i++)
memmove(buf[i], buf[i] + offset, sizeof(float) * len);
}
void RadioInterface::loadVectors(unsigned tN, int samplesPerBurst,
int idx, GSM::Time rxClock)
{
int i;
for (i = 0; i < mChanM; i++) {
signalVector rxVector(samplesPerBurst);
unRadioifyVector(rcvBuffer[i], idx * 2, rxVector);
radioVector *rxBurst = new radioVector(rxVector, rxClock);
mReceiveFIFO[i].write(rxBurst);
}
}
void RadioInterface::driveReceiveRadio()
void RadioInterface::driveTransmitRadio(std::vector<signalVector *> &bursts,
std::vector<bool> &zeros)
{
if (!mOn)
return;
if (mReceiveFIFO[0].size() > 8)
return;
for (size_t i = 0; i < mChans; i++)
radioifyVector(*bursts[i], i, zeros[i]);
while (pushBuffer());
}
bool RadioInterface::driveReceiveRadio()
{
radioVector *burst = NULL;
if (!mOn)
return false;
pullBuffer();
GSM::Time rcvClock = mClock.get();
rcvClock.decTN(receiveOffset);
unsigned tN = rcvClock.TN();
int rcvSz = rcvCursor;
int readSz = 0;
int recvSz = recvBuffer[0]->getAvailSamples();
const int symbolsPerSlot = gSlotLen + 8;
int samplesPerBurst = (symbolsPerSlot + (tN % 4 == 0)) * samplesPerSymbol;
int burstSize;
// while there's enough data in receive buffer, form received
// GSM bursts and pass up to Transceiver
// Using the 157-156-156-156 symbols per timeslot format.
while (rcvSz >= samplesPerBurst) {
if (rcvClock.FN() >= 0) {
loadVectors(tN, samplesPerBurst, readSz, rcvClock);
if (mSPSRx == 4)
burstSize = 625;
else
burstSize = symbolsPerSlot + (tN % 4 == 0);
/*
* Pre-allocate head room for the largest correlation size
* so we can later avoid a re-allocation and copy
* */
size_t head = GSM::gRACHSynchSequence.size();
/*
* Form receive bursts and pass up to transceiver. Use repeating
* pattern of 157-156-156-156 symbols per timeslot
*/
while (recvSz > burstSize) {
for (size_t i = 0; i < mChans; i++) {
burst = new radioVector(rcvClock, burstSize, head);
unRadioifyVector(burst->getVector(), i);
if (mReceiveFIFO[i].size() < 32)
mReceiveFIFO[i].write(burst);
else
delete burst;
}
mClock.incTN();
rcvClock.incTN();
readSz += samplesPerBurst;
rcvSz -= samplesPerBurst;
recvSz -= burstSize;
tN = rcvClock.TN();
samplesPerBurst = (symbolsPerSlot + (tN % 4 == 0)) * samplesPerSymbol;
if (mSPSRx != 4)
burstSize = (symbolsPerSlot + (tN % 4 == 0)) * mSPSRx;
}
if (readSz > 0) {
rcvCursor -= readSz;
shiftRxBuffers(rcvBuffer, 2 * readSz, 2 * rcvCursor, mChanM);
}
return true;
}
double RadioInterface::setRxGain(double dB, int chan)
bool RadioInterface::isUnderrun()
{
if (mRadio)
return mRadio->setRxGain(dB, chan);
else
return -1;
bool retVal = underrun;
underrun = false;
return retVal;
}
double RadioInterface::getRxGain(int chan)
VectorFIFO* RadioInterface::receiveFIFO(size_t chan)
{
if (mRadio)
return mRadio->getRxGain(chan);
else
return -1;
if (chan >= mReceiveFIFO.size())
return NULL;
return &mReceiveFIFO[chan];
}
bool RadioInterface::init()
double RadioInterface::setRxGain(double dB, size_t chan)
{
for (int i = 0; i < CHAN_MAX; i++) {
rx_buf[i] = new short[2 * OUTCHUNK];
tx_buf[i] = new short[4 * 2 * INCHUNK];
}
return mRadio->setRxGain(dB, chan);
}
void RadioInterface::close()
double RadioInterface::getRxGain(size_t chan)
{
for (int i = 0; i < CHAN_MAX; i++) {
delete rx_buf[i];
delete tx_buf[i];
}
return mRadio->getRxGain(chan);
}
/* Receive a timestamped chunk from the device */
/* Receive a timestamped chunk from the device */
void RadioInterface::pullBuffer()
{
bool local_underrun;
size_t numRecv, segmentLen = recvBuffer[0]->getSegmentLen();
/* Read samples. Fail if we don't get what we want. */
int num_rd = mRadio->readSamples(rx_buf, mChanM, OUTCHUNK, readTimestamp);
LOG(DEBUG) << "Rx read " << num_rd << " samples from device";
assert(num_rd == OUTCHUNK);
underrun |= local_underrun;
readTimestamp += (TIMESTAMP) num_rd;
for (int i = 0; i < mChanM; i++)
shortToFloat(rcvBuffer[i] + 2 * rcvCursor, rx_buf[i], num_rd);
rcvCursor += num_rd;
}
/* Send timestamped chunk to the device with arbitrary size */
void RadioInterface::pushBuffer()
{
if (sendCursor < INCHUNK)
if (recvBuffer[0]->getFreeSegments() <= 0)
return;
for (int i = 0; i < mChanM; i++)
floatToShort(tx_buf[i], sendBuffer[i], sendCursor);
/* Outer buffer access size is fixed */
numRecv = mRadio->readSamples(convertRecvBuffer,
segmentLen,
&overrun,
readTimestamp,
&local_underrun);
/* Write samples. Fail if we don't get what we want. */
int num_smpls = mRadio->writeSamples(tx_buf, mChanM, sendCursor,
writeTimestamp, &underrun);
assert(num_smpls == sendCursor);
if (numRecv != segmentLen) {
LOG(ALERT) << "Receive error " << numRecv;
return;
}
writeTimestamp += (TIMESTAMP) num_smpls;
sendCursor = 0;
for (size_t i = 0; i < mChans; i++) {
convert_short_float(recvBuffer[i]->getWriteSegment(),
convertRecvBuffer[i],
segmentLen * 2);
}
underrun |= local_underrun;
readTimestamp += numRecv;
}
/* Send timestamped chunk to the device with arbitrary size */
bool RadioInterface::pushBuffer()
{
size_t numSent, segmentLen = sendBuffer[0]->getSegmentLen();
if (sendBuffer[0]->getAvailSegments() < 1)
return false;
for (size_t i = 0; i < mChans; i++) {
convert_float_short(convertSendBuffer[i],
(float *) sendBuffer[i]->getReadSegment(),
powerScaling[i],
segmentLen * 2);
}
/* Send the all samples in the send buffer */
numSent = mRadio->writeSamples(convertSendBuffer,
segmentLen,
&underrun,
writeTimestamp);
writeTimestamp += numSent;
return true;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008, 2012 Free Software Foundation, Inc.
* Copyright 2008 Free Software Foundation, Inc.
*
* This software is distributed under multiple licenses; see the COPYING file in the main directory for licensing information for this specific distribuion.
*
@@ -12,8 +12,7 @@
*/
#ifndef _RADIOINTEFACE_H_
#define _RADIOINTEFACE_H_
#include "sigProcLib.h"
#include "GSMCommon.h"
@@ -21,13 +20,10 @@
#include "radioDevice.h"
#include "radioVector.h"
#include "radioClock.h"
/** samples per GSM symbol */
#define SAMPSPERSYM 1
#define INCHUNK (625)
#define OUTCHUNK (625)
#define CHAN_MAX 2
#include "radioBuffer.h"
#include "Resampler.h"
#include "Channelizer.h"
#include "Synthesis.h"
static const unsigned gSlotLen = 148; ///< number of symbols per slot, not counting guard periods
@@ -36,18 +32,22 @@ class RadioInterface {
protected:
int mChanM; ///< channelizer width
Thread mAlignRadioServiceLoopThread; ///< thread that synchronizes transmit and receive sections
VectorFIFO mReceiveFIFO[CHAN_MAX]; ///< FIFO that holds receive bursts
std::vector<VectorFIFO> mReceiveFIFO; ///< FIFO that holds receive bursts
RadioDevice *mRadio; ///< the USRP object
float *sendBuffer[CHAN_MAX];
unsigned sendCursor;
float *rcvBuffer[CHAN_MAX];
unsigned rcvCursor;
size_t mSPSTx;
size_t mSPSRx;
size_t mChans;
std::vector<RadioBuffer *> sendBuffer;
std::vector<RadioBuffer *> recvBuffer;
std::vector<short *> convertRecvBuffer;
std::vector<short *> convertSendBuffer;
std::vector<float> powerScaling;
bool underrun; ///< indicates writes to USRP are too slow
bool overrun; ///< indicates reads from USRP are too slow
TIMESTAMP writeTimestamp; ///< sample timestamp of next packet written to USRP
@@ -55,89 +55,71 @@ protected:
RadioClock mClock; ///< the basestation clock!
int samplesPerSymbol; ///< samples per GSM symbol
int receiveOffset; ///< offset b/w transmit and receive GSM timestamps, in timeslots
bool mOn; ///< indicates radio is on
double powerScaling;
bool loadTest;
int mNumARFCNs;
signalVector *finalVec, *finalVec9;
private:
/** initialize I/O internals */
bool init();
/** format samples to USRP */
int radioifyVector(signalVector &wVector,
float *floatVector,
float scale,
bool zero);
/** format samples to USRP */
int radioifyVector(signalVector &wVector, size_t chan, bool zero);
/** format samples from USRP */
int unRadioifyVector(float *floatVector, int offset, signalVector &wVector);
int unRadioifyVector(signalVector *wVector, size_t chan);
/** push GSM bursts into the transmit buffer */
virtual void pushBuffer(void);
virtual bool pushBuffer(void);
/** pull GSM bursts from the receive buffer */
virtual void pullBuffer(void);
/** load receive vectors into FIFO's */
void loadVectors(unsigned tN, int samplesPerBurst, int index, GSM::Time rxClock);
public:
/** start the interface */
bool start();
bool stop();
bool started() { return mOn; };
/** shutdown interface */
void close();
/** intialization */
virtual bool init(int type);
virtual void close();
/** constructor */
RadioInterface(RadioDevice* wRadio,
int wChanM = 1,
int wSPS = SAMPSPERSYM,
int receiveOffset = 3,
GSM::Time wStartTime = GSM::Time(0, 0));
RadioInterface(RadioDevice* wRadio, size_t tx_sps, size_t rx_sps,
size_t chans = 1, int receiveOffset = 3,
GSM::Time wStartTime = GSM::Time(0));
/** destructor */
~RadioInterface();
virtual ~RadioInterface();
void setSamplesPerSymbol(int wSamplesPerSymbol) {if (!mOn) samplesPerSymbol = wSamplesPerSymbol;}
/** check for underrun, resets underrun value */
bool isUnderrun();
int getSamplesPerSymbol() { return samplesPerSymbol;}
/** return the receive FIFO */
VectorFIFO* receiveFIFO(int num) { return &mReceiveFIFO[num];}
VectorFIFO* receiveFIFO(size_t chan = 0);
/** return the basestation clock */
RadioClock* getClock(void) { return &mClock;};
/** set transmit frequency */
bool tuneTx(double freq, int chan = 0);
virtual bool tuneTx(double freq, size_t chan = 0);
/** set receive frequency */
bool tuneRx(double freq, int chan = 0);
virtual bool tuneRx(double freq, size_t chan = 0);
/** set receive gain */
double setRxGain(double dB, int chan = 0);
double setRxGain(double dB, size_t chan = 0);
/** get receive gain */
double getRxGain(int chan = 0);
double getRxGain(size_t chan = 0);
/** drive transmission of GSM bursts */
void driveTransmitRadio(signalVector **radioBurst, bool *zeroBurst);
void driveTransmitRadio(std::vector<signalVector *> &bursts,
std::vector<bool> &zeros);
/** drive reception of GSM bursts */
void driveReceiveRadio();
bool driveReceiveRadio();
void setPowerAttenuation(double atten, int chan = 0);
int setPowerAttenuation(int atten, size_t chan = 0);
/** returns the full-scale transmit amplitude **/
double fullScaleInputValue();
@@ -146,10 +128,66 @@ public:
double fullScaleOutputValue();
/** set thread priority on current thread */
void setPriority() { mRadio->setPriority(); }
void setPriority(float prio = 0.5) { mRadio->setPriority(prio); }
/** get transport window type of attached device */
enum RadioDevice::TxWindowType getWindowType() { return mRadio->getWindowType(); }
#if USRP1
protected:
/** drive synchronization of Tx/Rx of USRP */
void alignRadio();
friend void *AlignRadioServiceLoopAdapter(RadioInterface*);
#endif
};
#endif /* _RADIOINTEFACE_H_ */
#if USRP1
/** synchronization thread loop */
void *AlignRadioServiceLoopAdapter(RadioInterface*);
#endif
class RadioInterfaceResamp : public RadioInterface {
private:
signalVector *outerSendBuffer;
signalVector *outerRecvBuffer;
bool pushBuffer();
void pullBuffer();
public:
RadioInterfaceResamp(RadioDevice* wRadio, size_t tx_sps, size_t rx_sps);
~RadioInterfaceResamp();
bool init(int type);
void close();
};
class RadioInterfaceMulti : public RadioInterface {
private:
bool pushBuffer();
void pullBuffer();
signalVector *outerSendBuffer;
signalVector *outerRecvBuffer;
std::vector<signalVector *> history;
std::vector<bool> active;
Resampler *dnsampler;
Resampler *upsampler;
Channelizer *channelizer;
Synthesis *synthesis;
public:
RadioInterfaceMulti(RadioDevice* radio, size_t tx_sps,
size_t rx_sps, size_t chans = 1);
~RadioInterfaceMulti();
bool init(int type);
void close();
bool tuneTx(double freq, size_t chan);
bool tuneRx(double freq, size_t chan);
double setRxGain(double dB, size_t chan);
};

View File

@@ -0,0 +1,391 @@
/*
* Multi-carrier radio interface
*
* Copyright (C) 2016 Ettus Research LLC
*
* Author: Tom Tsou <tom.tsou@ettus.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* See the COPYING file in the main directory for details.
*/
#include <radioInterface.h>
#include <Logger.h>
#include "Resampler.h"
extern "C" {
#include "convert.h"
}
/* Resampling parameters for 64 MHz clocking */
#define RESAMP_INRATE 65
#define RESAMP_OUTRATE (96 / 2)
/* Universal resampling parameters */
#define NUMCHUNKS 24
#define MCHANS 4
RadioInterfaceMulti::RadioInterfaceMulti(RadioDevice *radio, size_t tx_sps,
size_t rx_sps, size_t chans)
: RadioInterface(radio, tx_sps, rx_sps, chans),
outerSendBuffer(NULL), outerRecvBuffer(NULL),
dnsampler(NULL), upsampler(NULL), channelizer(NULL), synthesis(NULL)
{
}
RadioInterfaceMulti::~RadioInterfaceMulti()
{
close();
}
void RadioInterfaceMulti::close()
{
delete outerSendBuffer;
delete outerRecvBuffer;
delete dnsampler;
delete upsampler;
delete channelizer;
delete synthesis;
outerSendBuffer = NULL;
outerRecvBuffer = NULL;
dnsampler = NULL;
upsampler = NULL;
channelizer = NULL;
synthesis = NULL;
mReceiveFIFO.resize(0);
powerScaling.resize(0);
history.resize(0);
active.resize(0);
RadioInterface::close();
}
static int getLogicalChan(size_t pchan, size_t chans)
{
switch (chans) {
case 1:
if (pchan == 0)
return 0;
else
return -1;
break;
case 2:
if (pchan == 0)
return 0;
if (pchan == 3)
return 1;
else
return -1;
break;
case 3:
if (pchan == 1)
return 0;
if (pchan == 0)
return 1;
if (pchan == 3)
return 2;
else
return -1;
break;
default:
break;
};
return -1;
}
static int getFreqShift(size_t chans)
{
switch (chans) {
case 1:
return 0;
case 2:
return 0;
case 3:
return 1;
default:
break;
};
return -1;
}
/* Initialize I/O specific objects */
bool RadioInterfaceMulti::init(int type)
{
float cutoff = 1.0f;
size_t inchunk = 0, outchunk = 0;
if (mChans > MCHANS - 1) {
LOG(ALERT) << "Invalid channel configuration " << mChans;
return false;
}
close();
sendBuffer.resize(mChans);
recvBuffer.resize(mChans);
convertSendBuffer.resize(1);
convertRecvBuffer.resize(1);
mReceiveFIFO.resize(mChans);
powerScaling.resize(mChans);
history.resize(mChans);
active.resize(MCHANS, false);
inchunk = RESAMP_INRATE * 4;
outchunk = RESAMP_OUTRATE * 4;
if (inchunk * NUMCHUNKS < 625 * 2) {
LOG(ALERT) << "Invalid inner chunk size " << inchunk;
return false;
}
dnsampler = new Resampler(RESAMP_INRATE, RESAMP_OUTRATE);
if (!dnsampler->init(1.0)) {
LOG(ALERT) << "Rx resampler failed to initialize";
return false;
}
upsampler = new Resampler(RESAMP_OUTRATE, RESAMP_INRATE);
if (!upsampler->init(cutoff)) {
LOG(ALERT) << "Tx resampler failed to initialize";
return false;
}
channelizer = new Channelizer(MCHANS, outchunk);
if (!channelizer->init()) {
LOG(ALERT) << "Rx channelizer failed to initialize";
return false;
}
synthesis = new Synthesis(MCHANS, outchunk);
if (!synthesis->init()) {
LOG(ALERT) << "Tx synthesis filter failed to initialize";
return false;
}
/*
* Allocate high and low rate buffers. The high rate receive
* buffer and low rate transmit vectors feed into the resampler
* and requires headroom equivalent to the filter length. Low
* rate buffers are allocated in the main radio interface code.
*/
for (size_t i = 0; i < mChans; i++) {
sendBuffer[i] = new RadioBuffer(NUMCHUNKS, inchunk,
upsampler->len(), true);
recvBuffer[i] = new RadioBuffer(NUMCHUNKS, inchunk,
0, false);
history[i] = new signalVector(dnsampler->len());
synthesis->resetBuffer(i);
}
outerSendBuffer = new signalVector(synthesis->outputLen());
outerRecvBuffer = new signalVector(channelizer->inputLen());
convertSendBuffer[0] = new short[2 * synthesis->outputLen()];
convertRecvBuffer[0] = new short[2 * channelizer->inputLen()];
/* Configure channels */
switch (mChans) {
case 1:
active[0] = true;
break;
case 2:
active[0] = true;
active[3] = true;
break;
case 3:
active[0] = true;
active[1] = true;
active[3] = true;
break;
default:
LOG(ALERT) << "Unsupported channel combination";
return false;
}
return true;
}
/* Receive a timestamped chunk from the device */
void RadioInterfaceMulti::pullBuffer()
{
bool local_underrun;
size_t num;
float *buf;
if (recvBuffer[0]->getFreeSegments() <= 0)
return;
/* Outer buffer access size is fixed */
num = mRadio->readSamples(convertRecvBuffer,
outerRecvBuffer->size(),
&overrun,
readTimestamp,
&local_underrun);
if (num != channelizer->inputLen()) {
LOG(ALERT) << "Receive error " << num << ", " << channelizer->inputLen();
return;
}
convert_short_float((float *) outerRecvBuffer->begin(),
convertRecvBuffer[0], 2 * outerRecvBuffer->size());
underrun |= local_underrun;
readTimestamp += num;
channelizer->rotate((float *) outerRecvBuffer->begin(),
outerRecvBuffer->size());
for (size_t pchan = 0; pchan < MCHANS; pchan++) {
if (!active[pchan])
continue;
int lchan = getLogicalChan(pchan, mChans);
if (lchan < 0) {
LOG(ALERT) << "Invalid logical channel " << pchan;
continue;
}
/*
* Update history by writing into the head portion of the
* channelizer output buffer. For this to work, filter length of
* the polyphase channelizer partition filter should be equal to
* or larger than the resampling filter.
*/
buf = channelizer->outputBuffer(pchan);
size_t cLen = channelizer->outputLen();
size_t hLen = dnsampler->len();
size_t hSize = 2 * hLen * sizeof(float);
memcpy(&buf[2 * -hLen], history[lchan]->begin(), hSize);
memcpy(history[lchan]->begin(), &buf[2 * (cLen - hLen)], hSize);
float *wr_segment = recvBuffer[lchan]->getWriteSegment();
/* Write to the end of the inner receive buffer */
if (!dnsampler->rotate(channelizer->outputBuffer(pchan),
channelizer->outputLen(),
wr_segment,
recvBuffer[lchan]->getSegmentLen())) {
LOG(ALERT) << "Sample rate upsampling error";
}
}
}
/* Send a timestamped chunk to the device */
bool RadioInterfaceMulti::pushBuffer()
{
if (sendBuffer[0]->getAvailSegments() <= 0)
return false;
for (size_t pchan = 0; pchan < MCHANS; pchan++) {
if (!active[pchan]) {
synthesis->resetBuffer(pchan);
continue;
}
int lchan = getLogicalChan(pchan, mChans);
if (lchan < 0) {
LOG(ALERT) << "Invalid logical channel " << pchan;
continue;
}
if (!upsampler->rotate(sendBuffer[lchan]->getReadSegment(),
sendBuffer[lchan]->getSegmentLen(),
synthesis->inputBuffer(pchan),
synthesis->inputLen())) {
LOG(ALERT) << "Sample rate downsampling error";
}
}
synthesis->rotate((float *) outerSendBuffer->begin(),
outerSendBuffer->size());
convert_float_short(convertSendBuffer[0],
(float *) outerSendBuffer->begin(),
1.0 / (float) mChans, 2 * outerSendBuffer->size());
size_t num = mRadio->writeSamples(convertSendBuffer,
outerSendBuffer->size(),
&underrun,
writeTimestamp);
if (num != outerSendBuffer->size()) {
LOG(ALERT) << "Transmit error " << num;
}
writeTimestamp += num;
return true;
}
/* Frequency comparison limit */
#define FREQ_DELTA_LIMIT 10.0
static bool fltcmp(double a, double b)
{
return fabs(a - b) < FREQ_DELTA_LIMIT ? true : false;
}
bool RadioInterfaceMulti::tuneTx(double freq, size_t chan)
{
if (chan >= mChans)
return false;
double shift = (double) getFreqShift(mChans);
if (!chan)
return mRadio->setTxFreq(freq + shift * MCBTS_SPACING);
double center = mRadio->getTxFreq();
if (!fltcmp(freq, center + (double) (chan - shift) * MCBTS_SPACING)) {
LOG(NOTICE) << "Channel " << chan << " RF frequency offset is "
<< freq / 1e6 << " MHz";
}
return true;
}
bool RadioInterfaceMulti::tuneRx(double freq, size_t chan)
{
if (chan >= mChans)
return false;
double shift = (double) getFreqShift(mChans);
if (!chan)
return mRadio->setRxFreq(freq + shift * MCBTS_SPACING);
double center = mRadio->getRxFreq();
if (!fltcmp(freq, center + (double) (chan - shift) * MCBTS_SPACING)) {
LOG(NOTICE) << "Channel " << chan << " RF frequency offset is "
<< freq / 1e6 << " MHz";
}
return true;
}
double RadioInterfaceMulti::setRxGain(double db, size_t chan)
{
if (!chan)
return mRadio->setRxGain(db);
else
return mRadio->getRxGain();
}

View File

@@ -0,0 +1,234 @@
/*
* Radio device interface with sample rate conversion
*
* Copyright (C) 2011-2014 Free Software Foundation, Inc.
* Copyright (C) 2015 Ettus Research LLC
*
* Author: Tom Tsou <tom@tsou.cc>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* See the COPYING file in the main directory for details.
*/
#include <radioInterface.h>
#include <Logger.h>
#include "Resampler.h"
extern "C" {
#include "convert.h"
}
/* Resampling parameters for 64 MHz clocking */
#define RESAMP_64M_INRATE 65
#define RESAMP_64M_OUTRATE 96
/* Resampling parameters for 100 MHz clocking */
#define RESAMP_100M_INRATE 52
#define RESAMP_100M_OUTRATE 75
/* Universal resampling parameters */
#define NUMCHUNKS 24
/*
* Resampling filter bandwidth scaling factor
* This narrows the filter cutoff relative to the output bandwidth
* of the polyphase resampler. At 4 samples-per-symbol using the
* 2 pulse Laurent GMSK approximation gives us below 0.5 degrees
* RMS phase error at the resampler output.
*/
#define RESAMP_TX4_FILTER 0.45
static Resampler *upsampler = NULL;
static Resampler *dnsampler = NULL;
static size_t resamp_inrate = 0;
static size_t resamp_inchunk = 0;
static size_t resamp_outrate = 0;
static size_t resamp_outchunk = 0;
RadioInterfaceResamp::RadioInterfaceResamp(RadioDevice *wRadio,
size_t tx_sps, size_t rx_sps)
: RadioInterface(wRadio, tx_sps, rx_sps, 1),
outerSendBuffer(NULL), outerRecvBuffer(NULL)
{
}
RadioInterfaceResamp::~RadioInterfaceResamp()
{
close();
}
void RadioInterfaceResamp::close()
{
delete outerSendBuffer;
delete outerRecvBuffer;
delete upsampler;
delete dnsampler;
outerSendBuffer = NULL;
outerRecvBuffer = NULL;
upsampler = NULL;
dnsampler = NULL;
if (sendBuffer.size())
sendBuffer[0] = NULL;
if (recvBuffer.size())
recvBuffer[0] = NULL;
RadioInterface::close();
}
/* Initialize I/O specific objects */
bool RadioInterfaceResamp::init(int type)
{
float cutoff = 1.0f;
close();
sendBuffer.resize(1);
recvBuffer.resize(1);
convertSendBuffer.resize(1);
convertRecvBuffer.resize(1);
mReceiveFIFO.resize(1);
powerScaling.resize(1);
switch (type) {
case RadioDevice::RESAMP_64M:
resamp_inrate = RESAMP_64M_INRATE;
resamp_outrate = RESAMP_64M_OUTRATE;
break;
case RadioDevice::RESAMP_100M:
resamp_inrate = RESAMP_100M_INRATE;
resamp_outrate = RESAMP_100M_OUTRATE;
break;
case RadioDevice::NORMAL:
default:
LOG(ALERT) << "Invalid device configuration";
return false;
}
resamp_inchunk = resamp_inrate * 4 * mSPSRx;
resamp_outchunk = resamp_outrate * 4 * mSPSRx;
if (mSPSTx == 4)
cutoff = RESAMP_TX4_FILTER;
dnsampler = new Resampler(resamp_inrate, resamp_outrate);
if (!dnsampler->init()) {
LOG(ALERT) << "Rx resampler failed to initialize";
return false;
}
upsampler = new Resampler(resamp_outrate, resamp_inrate);
if (!upsampler->init(cutoff)) {
LOG(ALERT) << "Tx resampler failed to initialize";
return false;
}
/*
* Allocate high and low rate buffers. The high rate receive
* buffer and low rate transmit vectors feed into the resampler
* and requires headroom equivalent to the filter length. Low
* rate buffers are allocated in the main radio interface code.
*/
sendBuffer[0] = new RadioBuffer(NUMCHUNKS, resamp_inchunk,
upsampler->len(), true);
recvBuffer[0] = new RadioBuffer(NUMCHUNKS * 20, resamp_inchunk, 0, false);
outerSendBuffer =
new signalVector(NUMCHUNKS * resamp_outchunk);
outerRecvBuffer =
new signalVector(resamp_outchunk, dnsampler->len());
convertSendBuffer[0] = new short[outerSendBuffer->size() * 2];
convertRecvBuffer[0] = new short[outerRecvBuffer->size() * 2];
return true;
}
/* Receive a timestamped chunk from the device */
void RadioInterfaceResamp::pullBuffer()
{
bool local_underrun;
int rc, num_recv;
if (recvBuffer[0]->getFreeSegments() <= 0)
return;
/* Outer buffer access size is fixed */
num_recv = mRadio->readSamples(convertRecvBuffer,
resamp_outchunk,
&overrun,
readTimestamp,
&local_underrun);
if (num_recv != (int) resamp_outchunk) {
LOG(ALERT) << "Receive error " << num_recv;
return;
}
convert_short_float((float *) outerRecvBuffer->begin(),
convertRecvBuffer[0], 2 * resamp_outchunk);
underrun |= local_underrun;
readTimestamp += (TIMESTAMP) resamp_outchunk;
/* Write to the end of the inner receive buffer */
rc = dnsampler->rotate((float *) outerRecvBuffer->begin(),
resamp_outchunk,
recvBuffer[0]->getWriteSegment(),
resamp_inchunk);
if (rc < 0) {
LOG(ALERT) << "Sample rate upsampling error";
}
/* Set history for the next chunk */
outerRecvBuffer->updateHistory();
}
/* Send a timestamped chunk to the device */
bool RadioInterfaceResamp::pushBuffer()
{
int rc;
size_t numSent;
if (sendBuffer[0]->getAvailSegments() <= 0)
return false;
/* Always send from the beginning of the buffer */
rc = upsampler->rotate(sendBuffer[0]->getReadSegment(),
resamp_inchunk,
(float *) outerSendBuffer->begin(),
resamp_outchunk);
if (rc < 0) {
LOG(ALERT) << "Sample rate downsampling error";
}
convert_float_short(convertSendBuffer[0],
(float *) outerSendBuffer->begin(),
powerScaling[0], 2 * resamp_outchunk);
numSent = mRadio->writeSamples(convertSendBuffer,
resamp_outchunk,
&underrun,
writeTimestamp);
if (numSent != resamp_outchunk) {
LOG(ALERT) << "Transmit error " << numSent;
}
writeTimestamp += resamp_outchunk;
return true;
}

View File

@@ -2,7 +2,7 @@
* Written by Thomas Tsou <ttsou@vt.edu>
* Based on code by Harvind S Samra <hssamra@kestrelsp.com>
*
* Copyright 2011, 2012 Free Software Foundation, Inc.
* Copyright 2011 Free Software Foundation, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@@ -21,9 +21,24 @@
#include "radioVector.h"
radioVector::radioVector(const signalVector& wVector, GSM::Time& wTime)
: signalVector(wVector), mTime(wTime)
radioVector::radioVector(GSM::Time &time, size_t size,
size_t start, size_t chans)
: vectors(chans), mTime(time)
{
for (size_t i = 0; i < vectors.size(); i++)
vectors[i] = new signalVector(size, start);
}
radioVector::radioVector(GSM::Time& wTime, signalVector *vector)
: vectors(1), mTime(wTime)
{
vectors[0] = vector;
}
radioVector::~radioVector()
{
for (size_t i = 0; i < vectors.size(); i++)
delete vectors[i];
}
GSM::Time radioVector::getTime() const
@@ -41,6 +56,52 @@ bool radioVector::operator>(const radioVector& other) const
return mTime > other.mTime;
}
signalVector *radioVector::getVector(size_t chan) const
{
if (chan >= vectors.size())
return NULL;
return vectors[chan];
}
bool radioVector::setVector(signalVector *vector, size_t chan)
{
if (chan >= vectors.size())
return false;
vectors[chan] = vector;
return true;
}
noiseVector::noiseVector(size_t size)
: std::vector<float>(size), itr(0)
{
}
float noiseVector::avg() const
{
float val = 0.0;
for (size_t i = 0; i < size(); i++)
val += (*this)[i];
return val / (float) size();
}
bool noiseVector::insert(float val)
{
if (!size())
return false;
if (itr >= this->size())
itr = 0;
(*this)[itr++] = val;
return true;
}
GSM::Time VectorQueue::nextTime() const
{
GSM::Time retVal;

View File

@@ -2,7 +2,7 @@
* Written by Thomas Tsou <ttsou@vt.edu>
* Based on code by Harvind S Samra <hssamra@kestrelsp.com>
*
* Copyright 2011, 2012 Free Software Foundation, Inc.
* Copyright 2011 Free Software Foundation, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@@ -26,20 +26,38 @@
#include "GSMCommon.h"
#include "Interthread.h"
class radioVector : public signalVector {
class radioVector {
public:
radioVector(const signalVector& wVector, GSM::Time& wTime);
radioVector(GSM::Time& wTime, size_t size = 0,
size_t start = 0, size_t chans = 1);
radioVector(GSM::Time& wTime, signalVector *vector);
~radioVector();
GSM::Time getTime() const;
void setTime(const GSM::Time& wTime);
bool operator>(const radioVector& other) const;
signalVector *getVector(size_t chan = 0) const;
bool setVector(signalVector *vector, size_t chan = 0);
size_t chans() const { return vectors.size(); }
private:
std::vector<signalVector *> vectors;
GSM::Time mTime;
};
class VectorFIFO : public InterthreadQueue<radioVector> {
class noiseVector : std::vector<float> {
public:
noiseVector(size_t size = 0);
bool insert(float val);
float avg() const;
private:
size_t itr;
};
class VectorFIFO : public InterthreadQueue<radioVector> { };
class VectorQueue : public InterthreadPriorityQueue<radioVector> {
public:
GSM::Time nextTime() const;

File diff suppressed because one or more lines are too long

View File

@@ -1,164 +0,0 @@
/*
* Copyright 2008, 2009, 2010 Free Software Foundation, Inc.
* Copyright 2010 Kestrel Signal Processing, Inc.
*
* This software is distributed under the terms of the GNU Affero Public License.
* See the COPYING file in the main directory for details.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Transceiver.h"
#include "radioDevice.h"
#include "DummyLoad.h"
#include <time.h>
#include <signal.h>
#include <GSMCommon.h>
#include <Logger.h>
#include <Configuration.h>
using namespace std;
ConfigurationTable gConfig("/etc/OpenBTS/OpenBTS.db");
volatile bool gbShutdown = false;
static void ctrlCHandler(int signo)
{
cout << "Received shutdown signal" << endl;;
gbShutdown = true;
}
int main(int argc, char *argv[])
{
std::string deviceArgs;
std::string txAntenna, rxAntenna;
if (argc == 3)
{
deviceArgs = std::string(argv[2]);
}
else
{
deviceArgs = "";
}
if ( signal( SIGINT, ctrlCHandler ) == SIG_ERR )
{
cerr << "Couldn't install signal handler for SIGINT" << endl;
exit(1);
}
if ( signal( SIGTERM, ctrlCHandler ) == SIG_ERR )
{
cerr << "Couldn't install signal handler for SIGTERM" << endl;
exit(1);
}
// Configure logger.
gLogInit("transceiver",gConfig.getStr("Log.Level").c_str(),LOG_LOCAL7);
int numARFCN=1;
LOG(NOTICE) << "starting transceiver with " << numARFCN << " ARFCNs (argc=" << argc << ")";
srandom(time(NULL));
RadioDevice *usrp = RadioDevice::make(SAMPSPERSYM);
int radioType = usrp->open(deviceArgs);
if (radioType < 0) {
LOG(ALERT) << "Transceiver exiting..." << std::endl;
return EXIT_FAILURE;
}
if (gConfig.defines("GSM.Radio.TxAntenna"))
txAntenna = gConfig.getStr("GSM.Radio.TxAntenna").c_str();
if (gConfig.defines("GSM.Radio.RxAntenna"))
rxAntenna = gConfig.getStr("GSM.Radio.RxAntenna").c_str();
if (txAntenna != "")
usrp->setTxAntenna(txAntenna);
if (rxAntenna != "")
usrp->setRxAntenna(rxAntenna);
LOG(INFO) << "transceiver using transmit antenna " << usrp->getRxAntenna();
LOG(INFO) << "transceiver using receive antenna " << usrp->getTxAntenna();
RadioInterface* radio;
switch (radioType) {
case RadioDevice::NORMAL:
radio = new RadioInterface(usrp, 3, SAMPSPERSYM, false);
break;
case RadioDevice::RESAMP:
default:
LOG(ALERT) << "Unsupported configuration";
return EXIT_FAILURE;
}
int port = gConfig.getNum("TRX.Port");
const char *addr = gConfig.getStr("TRX.IP").c_str();
DriveLoop *drive = new DriveLoop(SAMPSPERSYM,GSM::Time(3,0),radio);
Transceiver *trx = new Transceiver(port, addr, SAMPSPERSYM, radio, drive, 0);
radio->activateChan(0);
/*
signalVector *gsmPulse = generateGSMPulse(2,1);
BitVector normalBurstSeg = "0000101010100111110010101010010110101110011000111001101010000";
BitVector normalBurst(BitVector(normalBurstSeg,gTrainingSequence[0]),normalBurstSeg);
signalVector *modBurst = modulateBurst(normalBurst,*gsmPulse,8,1);
signalVector *modBurst9 = modulateBurst(normalBurst,*gsmPulse,9,1);
signalVector *interpolationFilter = createLPF(0.6/mOversamplingRate,6*mOversamplingRate,1);
signalVector totalBurst1(*modBurst,*modBurst9);
signalVector totalBurst2(*modBurst,*modBurst);
signalVector totalBurst(totalBurst1,totalBurst2);
scaleVector(totalBurst,usrp->fullScaleInputValue());
double beaconFreq = -1.0*(numARFCN-1)*200e3;
signalVector finalVec(625*mOversamplingRate);
for (int j = 0; j < numARFCN; j++) {
signalVector *frequencyShifter = new signalVector(625*mOversamplingRate);
frequencyShifter->fill(1.0);
frequencyShift(frequencyShifter,frequencyShifter,2.0*M_PI*(beaconFreq+j*400e3)/(1625.0e3/6.0*mOversamplingRate));
signalVector *interpVec = polyphaseResampleVector(totalBurst,mOversamplingRate,1,interpolationFilter);
multVector(*interpVec,*frequencyShifter);
addVector(finalVec,*interpVec);
}
signalVector::iterator itr = finalVec.begin();
short finalVecShort[2*finalVec.size()];
short *shortItr = finalVecShort;
while (itr < finalVec.end()) {
*shortItr++ = (short) (itr->real());
*shortItr++ = (short) (itr->imag());
itr++;
}
usrp->loadBurst(finalVecShort,finalVec.size());
*/
trx->start();
while(!gbShutdown) { sleep(1); }//i++; if (i==60) break;}
cout << "Shutting down transceiver..." << endl;
trx->shutdown();
delete trx;
delete drive;
delete radio;
}

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -18,74 +18,49 @@
#include "Vector.h"
#include "Complex.h"
#include "BitVector.h"
#include "PRBS.h"
#include "signalVector.h"
/** Indicated signalVector symmetry */
enum Symmetry {
NONE = 0,
ABSSYM = 1
};
/* Burst lengths */
#define NORMAL_BURST_NBITS 148
#define EDGE_BURST_NBITS 444
#define EDGE_BURST_NSYMS (EDGE_BURST_NBITS / 3)
/** Convolution type indicator */
enum ConvType {
FULL_SPAN = 0,
OVERLAP_ONLY = 1,
START_ONLY = 2,
WITH_TAIL = 3,
NO_DELAY = 4,
CUSTOM = 5,
UNDEFINED = 255
START_ONLY,
NO_DELAY,
CUSTOM,
UNDEFINED,
};
/** the core data structure of the Transceiver */
class signalVector: public Vector<complex>
{
private:
Symmetry symmetry; ///< the symmetry of the vector
bool realOnly; ///< true if vector is real-valued, not complex-valued
public:
/** Constructors */
signalVector(int dSize=0, Symmetry wSymmetry = NONE):
Vector<complex>(dSize),
realOnly(false)
{
symmetry = wSymmetry;
};
signalVector(complex* wData, size_t start,
size_t span, Symmetry wSymmetry = NONE):
Vector<complex>(NULL,wData+start,wData+start+span),
realOnly(false)
{
symmetry = wSymmetry;
};
signalVector(const signalVector &vec1, const signalVector &vec2):
Vector<complex>(vec1,vec2),
realOnly(false)
{
symmetry = vec1.symmetry;
};
signalVector(const signalVector &wVector):
Vector<complex>(wVector.size()),
realOnly(false)
{
wVector.copyTo(*this);
symmetry = wVector.getSymmetry();
};
/** symmetry operators */
Symmetry getSymmetry() const { return symmetry;};
void setSymmetry(Symmetry wSymmetry) { symmetry = wSymmetry;};
/** real-valued operators */
bool isRealOnly() const { return realOnly;};
void isRealOnly(bool wOnly) { realOnly = wOnly;};
/** Codes for burst types of received bursts*/
enum CorrType{
OFF, ///< timeslot is off
TSC, ///< timeslot should contain a normal burst
RACH, ///< timeslot should contain an access burst
EDGE, ///< timeslot should contain an EDGE burst
IDLE ///< timeslot is an idle (or dummy) burst
};
std::string corrTypeToString(CorrType corr);
std::ostream& operator<<(std::ostream& os, CorrType corr);
enum SignalError {
SIGERR_NONE,
SIGERR_BOUNDS,
SIGERR_CLIP,
SIGERR_UNSUPPORTED,
SIGERR_INTERNAL,
};
/*
* Burst detection threshold
*
* Decision threshold value for burst gating on peak-to-average value of
* correlated synchronization sequences. Lower values pass more bursts up
* to upper layers but will increase the false detection rate.
*/
#define BURST_THRESH 4.0
/** Convert a linear number to a dB value */
float dB(float x);
@@ -100,83 +75,89 @@ float vectorNorm2(const signalVector &x);
float vectorPower(const signalVector &x);
/** Setup the signal processing library */
void sigProcLibSetup(int samplesPerSymbol);
bool sigProcLibSetup();
/** Destroy the signal processing library */
void sigProcLibDestroy(void);
/**
Convolve two vectors.
@param a,b The vectors to be convolved.
@param c, A preallocated vector to hold the convolution result.
@param spanType The type/span of the convolution.
@return The convolution result.
/**
Convolve two vectors.
@param a,b The vectors to be convolved.
@param c, A preallocated vector to hold the convolution result.
@param spanType The type/span of the convolution.
@return The convolution result or NULL on error.
*/
signalVector* convolve(const signalVector *a,
const signalVector *b,
signalVector *c,
ConvType spanType,
unsigned startIx = 0,
unsigned len = 0);
signalVector *convolve(const signalVector *a, const signalVector *b,
signalVector *c, ConvType spanType,
size_t start = 0, size_t len = 0,
size_t step = 1, int offset = 0);
/**
Generate the GSM pulse.
@param samplesPerSymbol The number of samples per GSM symbol.
@param symbolLength The size of the pulse.
@return The GSM pulse.
*/
signalVector* generateGSMPulse(int samplesPerSymbol,
int symbolLength);
/**
/**
Frequency shift a vector.
@param y The frequency shifted vector.
@param x The vector to-be-shifted.
@param freq The digital frequency shift
@param startPhase The starting phase of the oscillator
@param finalPhase The final phase of the oscillator
@return The frequency shifted vector.
@param y The frequency shifted vector.
@param x The vector to-be-shifted.
@param freq The digital frequency shift
@param startPhase The starting phase of the oscillator
@param finalPhase The final phase of the oscillator
@return The frequency shifted vector.
*/
signalVector* frequencyShift(signalVector *y,
signalVector *x,
float freq = 0.0,
float startPhase = 0.0,
float *finalPhase=NULL);
signalVector *x,
float freq = 0.0,
float startPhase = 0.0,
float *finalPhase=NULL);
/**
Correlate two vectors.
/**
Correlate two vectors.
@param a,b The vectors to be correlated.
@param c, A preallocated vector to hold the correlation result.
@param spanType The type/span of the correlation.
@return The correlation result.
*/
signalVector* correlate(signalVector *a,
signalVector *b,
signalVector *c,
ConvType spanType,
signalVector *b,
signalVector *c,
ConvType spanType,
bool bReversedConjugated = false,
unsigned startIx = 0,
unsigned len = 0);
unsigned startIx = 0,
unsigned len = 0);
/** Operate soft slicer on real-valued portion of vector */
bool vectorSlicer(signalVector *x);
/** Operate soft slicer on a soft-bit vector */
bool vectorSlicer(SoftVector *x);
/** GMSK modulate a GSM burst of bits */
signalVector *modulateBurst(const BitVector &wBurst,
const signalVector &gsmPulse,
int guardPeriodLength,
int samplesPerSymbol);
int guardPeriodLength,
int sps, bool emptyPulse = false);
/** 8-PSK modulate a burst of bits */
signalVector *modulateEdgeBurst(const BitVector &bits,
int sps, bool emptyPulse = false);
/** Generate a EDGE burst with random payload - 4 SPS (625 samples) only */
signalVector *generateEdgeBurst(int tsc);
/** Generate an empty burst - 4 or 1 SPS */
signalVector *generateEmptyBurst(int sps, int tn);
/** Generate a normal GSM burst with random payload - 4 or 1 SPS */
signalVector *genRandNormalBurst(int tsc, int sps, int tn, PRBS &prbs);
/** Generate an access GSM burst with random payload - 4 or 1 SPS */
signalVector *genRandAccessBurst(int delay, int sps, int tn);
/** Generate a dummy GSM burst - 4 or 1 SPS */
signalVector *generateDummyBurst(int sps, int tn);
/** Sinc function */
float sinc(float x);
/** Delay a vector */
void delayVector(signalVector &wBurst,
float delay);
signalVector *delayVector(const signalVector *in, signalVector *out, float delay);
/** Add two vectors in-place */
bool addVector(signalVector &x,
signalVector &y);
signalVector &y);
/** Multiply two vectors in-place*/
bool multVector(signalVector &x,
@@ -188,24 +169,24 @@ signalVector *gaussianNoise(int length,
complex mean = complex(0.0));
/**
Given a non-integer index, interpolate a sample.
@param inSig The signal from which to interpolate.
@param ix The index.
@return The interpolated signal value.
Given a non-integer index, interpolate a sample.
@param inSig The signal from which to interpolate.
@param ix The index.
@return The interpolated signal value.
*/
complex interpolatePoint(const signalVector &inSig,
float ix);
float ix);
/**
Given a correlator output, locate the correlation peak.
@param rxBurst The correlator result.
@param peakIndex Pointer to value to receive interpolated peak index.
@param avgPower Power to value to receive mean power.
@return Peak value.
Given a correlator output, locate the correlation peak.
@param rxBurst The correlator result.
@param peakIndex Pointer to value to receive interpolated peak index.
@param avgPower Power to value to receive mean power.
@return Peak value.
*/
complex peakDetect(const signalVector &rxBurst,
float *peakIndex,
float *avgPwr);
float *peakIndex,
float *avgPwr);
/**
Apply a scalar to a vector.
@@ -213,174 +194,140 @@ complex peakDetect(const signalVector &rxBurst,
@param scale The scalar.
*/
void scaleVector(signalVector &x,
complex scale);
/**
Add a constant offset to a vecotr.
@param x The vector of interest.
@param offset The offset.
*/
void offsetVector(signalVector &x,
complex offset);
complex scale);
/**
Generate a modulated GSM midamble, stored within the library.
@param gsmPulse The GSM pulse used for modulation.
@param samplesPerSymbol The number of samples per GSM symbol.
@param TSC The training sequence [0..7]
@return Success.
*/
bool generateMidamble(signalVector &gsmPulse,
int samplesPerSymbol,
int TSC);
/**
Generate a modulated RACH sequence, stored within the library.
@param gsmPulse The GSM pulse used for modulation.
@param samplesPerSymbol The number of samples per GSM symbol.
@return Success.
*/
bool generateRACHSequence(signalVector &gsmPulse,
int samplesPerSymbol);
/**
Energy detector, checks to see if received burst energy is above a threshold.
@param rxBurst The received GSM burst of interest.
Rough energy estimator.
@param rxBurst A GSM burst.
@param windowLength The number of burst samples used to compute burst energy
@param detectThreshold The detection threshold, a linear value.
@param avgPwr The average power of the received burst.
@return True if burst energy is above threshold.
@return The average power of the received burst.
*/
bool energyDetect(signalVector &rxBurst,
unsigned windowLength,
float detectThreshold,
float *avgPwr = NULL);
float energyDetect(const signalVector &rxBurst,
unsigned windowLength);
/**
RACH correlator/detector.
@param rxBurst The received GSM burst of interest.
@param detectThreshold The threshold that the received burst's post-correlator SNR is compared against to determine validity.
@param samplesPerSymbol The number of samples per GSM symbol.
RACH aka Access Burst correlator/detector.
@param burst The received GSM burst of interest.
@param threshold The threshold that the received burst's post-correlator SNR is compared against to determine validity.
@param sps The number of samples per GSM symbol.
@param amplitude The estimated amplitude of received RACH burst.
@param TOA The estimate time-of-arrival of received RACH burst.
@return True if burst SNR is larger that the detectThreshold value.
@param toa The estimate time-of-arrival of received RACH burst.
@param max_toa The maximum expected time-of-arrival
@return 1 if threshold value is reached,
negative value (-SignalError) on error,
zero (SIGERR_NONE) if no burst is detected
*/
bool detectRACHBurst(signalVector &rxBurst,
float detectThreshold,
int samplesPerSymbol,
complex *amplitude,
float* TOA);
int detectRACHBurst(const signalVector &burst,
float threshold,
int sps,
complex &amplitude,
float &toa,
unsigned max_toa);
/**
Normal burst correlator, detector, channel estimator.
GMSK Normal Burst correlator/detector.
@param rxBurst The received GSM burst of interest.
@param detectThreshold The threshold that the received burst's post-correlator SNR is compared against to determine validity.
@param samplesPerSymbol The number of samples per GSM symbol.
@param tsc Midamble type (0..7) also known as TSC
@param threshold The threshold that the received burst's post-correlator SNR is compared against to determine validity.
@param sps The number of samples per GSM symbol.
@param amplitude The estimated amplitude of received TSC burst.
@param TOA The estimate time-of-arrival of received TSC burst.
@param maxTOA The maximum expected time-of-arrival
@param requestChannel Set to true if channel estimation is desired.
@param channelResponse The estimated channel.
@param channelResponseOffset The time offset b/w the first sample of the channel response and the reported TOA.
@return True if burst SNR is larger that the detectThreshold value.
@param toa The estimate time-of-arrival of received TSC burst.
@param max_toa The maximum expected time-of-arrival
@return 1 if threshold value is reached,
negative value (-SignalError) on error,
zero (SIGERR_NONE) if no burst is detected
*/
bool analyzeTrafficBurst(signalVector &rxBurst,
unsigned TSC,
float detectThreshold,
int samplesPerSymbol,
complex *amplitude,
float *TOA,
unsigned maxTOA,
bool requestChannel = false,
signalVector** channelResponse = NULL,
float *channelResponseOffset = NULL);
int analyzeTrafficBurst(const signalVector &burst,
unsigned tsc,
float threshold,
int sps,
complex &amplitude,
float &toa,
unsigned max_toa);
/**
Decimate a vector.
EDGE/8-PSK Normal Burst correlator/detector
@param burst The received GSM burst of interest
@param tsc Midamble type (0..7) also known as TSC
@param threshold The threshold that the received burst's post-correlator SNR is compared against to determine validity.
@param sps The number of samples per GSM symbol.
@param amplitude The estimated amplitude of received TSC burst.
@param toa The estimate time-of-arrival of received TSC burst.
@param max_toa The maximum expected time-of-arrival
@return 1 if threshold value is reached,
negative value (-SignalError) on error,
zero (SIGERR_NONE) if no burst is detected
*/
int detectEdgeBurst(const signalVector &burst,
unsigned tsc,
float threshold,
int sps,
complex &amplitude,
float &toa,
unsigned max_toa);
/**
8-PSK/GMSK/RACH burst detector
@param burst The received GSM burst of interest
@param tsc Midamble type (0..7) also known as TSC
@param threshold The threshold that the received burst's post-correlator SNR is compared against to determine validity.
@param sps The number of samples per GSM symbol.
@param amplitude The estimated amplitude of received TSC burst.
@param toa The estimate time-of-arrival of received TSC burst (in symbols).
@param max_toa The maximum expected time-of-arrival (in symbols).
@return positive value (CorrType) if threshold value is reached,
negative value (-SignalError) on error,
zero (SIGERR_NONE) if no burst is detected
*/
int detectAnyBurst(const signalVector &burst,
unsigned tsc,
float threshold,
int sps,
CorrType type,
complex &amp,
float &toa,
unsigned max_toa);
/**
Downsample 4 SPS to 1 SPS using a polyphase filterbank
@param burst Input burst of at least 624 symbols
@return Decimated signal vector of 156 symbols
*/
signalVector *downsampleBurst(const signalVector &burst);
/**
Decimate a vector.
@param wVector The vector of interest.
@param decimationFactor The amount of decimation, i.e. the decimation factor.
@param factor Decimation factor.
@return The decimated signal vector.
*/
signalVector *decimateVector(signalVector &wVector,
int decimationFactor);
signalVector *decimateVector(signalVector &wVector, size_t factor);
/**
Demodulates a received burst using a soft-slicer.
@param rxBurst The burst to be demodulated.
Demodulates a GMSK burst using a soft-slicer.
@param rxBurst The burst to be demodulated.
@param gsmPulse The GSM pulse.
@param samplesPerSymbol The number of samples per GSM symbol.
@param sps The number of samples per GSM symbol.
@param channel The amplitude estimate of the received burst.
@param TOA The time-of-arrival of the received burst.
@return The demodulated bit sequence.
*/
SoftVector *demodulateBurst(signalVector &rxBurst,
const signalVector &gsmPulse,
int samplesPerSymbol,
complex channel,
float TOA);
SoftVector *demodGmskBurst(const signalVector &rxBurst, int sps,
complex channel, float TOA);
/**
Creates a simple Kaiser-windowed low-pass FIR filter.
@param cutoffFreq The digital 3dB bandwidth of the filter.
@param filterLen The number of taps in the filter.
@param gainDC The DC gain of the filter.
@return The desired LPF
Demodulate 8-PSK EDGE burst with soft symbol ooutput
@param rxBurst The burst to be demodulated.
@param sps The number of samples per GSM symbol.
@param channel The amplitude estimate of the received burst.
@param TOA The time-of-arrival of the received burst.
@return The demodulated bit sequence.
*/
signalVector *createLPF(float cutoffFreq,
int filterLen,
float gainDC = 1.0);
SoftVector *demodEdgeBurst(const signalVector &rxBurst, int sps,
complex channel, float TOA);
/**
Change sampling rate of a vector via polyphase resampling.
@param wVector The vector to be resampled.
@param P The numerator, i.e. the amount of upsampling.
@param Q The denominator, i.e. the amount of downsampling.
@param LPF An optional low-pass filter used in the resampling process.
@return A vector resampled at P/Q of the original sampling rate.
*/
signalVector *polyphaseResampleVector(signalVector &wVector,
int P, int Q,
signalVector *LPF);
/**
Change the sampling rate of a vector via linear interpolation.
@param wVector The vector to be resampled.
@param expFactor Ratio of new sampling rate/original sampling rate.
@param endPoint ???
@return A vector resampled a expFactor*original sampling rate.
*/
signalVector *resampleVector(signalVector &wVector,
float expFactor,
complex endPoint);
/**
Design the necessary filters for a decision-feedback equalizer.
@param channelResponse The multipath channel that we're mitigating.
@param SNRestimate The signal-to-noise estimate of the channel, a linear value
@param Nf The number of taps in the feedforward filter.
@param feedForwardFilter The designed feed forward filter.
@param feedbackFilter The designed feedback filter.
@return True if DFE can be designed.
*/
bool designDFE(signalVector &channelResponse,
float SNRestimate,
int Nf,
signalVector **feedForwardFilter,
signalVector **feedbackFilter);
/**
Equalize/demodulate a received burst via a decision-feedback equalizer.
@param rxBurst The received burst to be demodulated.
@param TOA The time-of-arrival of the received burst.
@param samplesPerSymbol The number of samples per GSM symbol.
@param w The feed forward filter of the DFE.
@param b The feedback filter of the DFE.
@return The demodulated bit sequence.
*/
SoftVector *equalizeBurst(signalVector &rxBurst,
float TOA,
int samplesPerSymbol,
signalVector &w,
signalVector &b);
/** Demodulate burst basde on type and output soft bits */
SoftVector *demodAnyBurst(const signalVector &burst, int sps,
complex amp, float toa, CorrType type);
#endif /* SIGPROCLIB_H */

View File

@@ -1,170 +0,0 @@
/*
* Copyright 2011 Free Software Foundation, Inc.
* Copyright 2008, 2010 Kestrel Signal Processing, Inc.
*
* This software is distributed under the terms of the GNU Affero Public License.
* See the COPYING file in the main directory for details.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
Contributors:
Harvind S. Samra, hssamra@kestrelsp.com
*/
#include "sigProcLib.h"
//#include "radioInterface.h"
#include <Logger.h>
#include <Configuration.h>
#include <GSMCommon.h>
using namespace std;
using namespace GSM;
ConfigurationTable gConfig;
int main(int argc, char **argv) {
gLogInit("sigProcLibTest","DEBUG");
int samplesPerSymbol = 1;
int TSC = 2;
sigProcLibSetup(samplesPerSymbol);
signalVector *gsmPulse = generateGSMPulse(2,samplesPerSymbol);
cout << *gsmPulse << endl;
BitVector RACHBurstStart = "01010101";
BitVector RACHBurstRest = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
BitVector RACHBurst(BitVector(RACHBurstStart,gRACHSynchSequence),RACHBurstRest);
signalVector *RACHSeq = modulateBurst(RACHBurst,
*gsmPulse,
9,
samplesPerSymbol);
generateRACHSequence(*gsmPulse,samplesPerSymbol);
complex a; float t;
detectRACHBurst(*RACHSeq, 5, samplesPerSymbol,&a,&t);
//cout << *RACHSeq << endl;
//signalVector *autocorr = correlate(RACHSeq,RACHSeq,NULL,NO_DELAY);
//cout << *autocorr;
//exit(1);
/*signalVector x(6500);
x.fill(1.0);
frequencyShift(&x,&x,0.48*M_PI);
signalVector *y = polyphaseResampleVector(x,96,65,NULL);
cout << *y << endl;
exit(1);*/
//CommSig normalBurstSeg = "0000000000000000000000000000000000000000000000000000000000000";
BitVector normalBurstSeg = "0000101010100111110010101010010110101110011000111001101010000";
BitVector normalBurst(BitVector(normalBurstSeg,gTrainingSequence[TSC]),normalBurstSeg);
generateMidamble(*gsmPulse,samplesPerSymbol,TSC);
signalVector *modBurst = modulateBurst(normalBurst,*gsmPulse,
0,samplesPerSymbol);
//delayVector(*rsVector2,6.932);
complex ampl = 1;
float TOA = 0;
//modBurst = rsVector2;
//delayVector(*modBurst,0.8);
/*
signalVector channelResponse(4);
signalVector::iterator c=channelResponse.begin();
*c = (complex) 9000.0; c++;
*c = (complex) 0.4*9000.0; c++; c++;
*c = (complex) -1.2*0;
signalVector *guhBurst = convolve(modBurst,&channelResponse,NULL,NO_DELAY);
delete modBurst; modBurst = guhBurst;
*/
signalVector *chanResp;
/*
double noisePwr = 0.001/sqrtf(2);
signalVector *noise = gaussianNoise(modBurst->size(),noisePwr);
*/
float chanRespOffset;
analyzeTrafficBurst(*modBurst,TSC,8.0,samplesPerSymbol,&ampl,&TOA,1,true,&chanResp,&chanRespOffset);
//addVector(*modBurst,*noise);
cout << "ampl:" << ampl << endl;
cout << "TOA: " << TOA << endl;
//cout << "chanResp: " << *chanResp << endl;
SoftVector *demodBurst = demodulateBurst(*modBurst,*gsmPulse,samplesPerSymbol,(complex) ampl, TOA);
cout << *demodBurst << endl;
/*
COUT("chanResp: " << *chanResp);
signalVector *w,*b;
designDFE(*chanResp,1.0/noisePwr,7,&w,&b);
COUT("w: " << *w);
COUT("b: " << *b);
SoftSig *DFEBurst = equalizeBurst(*modBurst,TOA-chanRespOffset,samplesPerSymbol,*w,*b);
COUT("DFEBurst: " << *DFEBurst);
delete gsmPulse;
delete RACHSeq;
delete modBurst;
delete sendLPF;
delete rcvLPF;
delete rsVector;
//delete rsVector2;
delete autocorr;
delete chanResp;
delete noise;
delete demodBurst;
delete w;
delete b;
delete DFEBurst;
*/
sigProcLibDestroy();
}

View File

@@ -0,0 +1,95 @@
#include "signalVector.h"
signalVector::signalVector(size_t size)
: Vector<complex>(size),
real(false), aligned(false), symmetry(NONE)
{
}
signalVector::signalVector(size_t size, size_t start)
: Vector<complex>(size + start),
real(false), aligned(false), symmetry(NONE)
{
mStart = mData + start;
}
signalVector::signalVector(complex *data, size_t start, size_t span)
: Vector<complex>(NULL, data + start, data + start + span),
real(false), aligned(false), symmetry(NONE)
{
}
signalVector::signalVector(const signalVector &vector)
: Vector<complex>(vector.size() + vector.getStart()), aligned(false)
{
mStart = mData + vector.getStart();
vector.copyTo(*this);
symmetry = vector.getSymmetry();
real = vector.isReal();
};
signalVector::signalVector(const signalVector &vector,
size_t start, size_t tail)
: Vector<complex>(start + vector.size() + tail), aligned(false)
{
mStart = mData + start;
vector.copyTo(*this);
symmetry = vector.getSymmetry();
real = vector.isReal();
};
void signalVector::operator=(const signalVector& vector)
{
resize(vector.size() + vector.getStart());
memcpy(mData, vector.mData, bytes());
mStart = mData + vector.getStart();
}
signalVector signalVector::segment(size_t start, size_t span)
{
return signalVector(mData, start, span);
}
size_t signalVector::getStart() const
{
return mStart - mData;
}
size_t signalVector::updateHistory()
{
size_t num = getStart();
memmove(mData, mStart + this->size() - num, num * sizeof(complex));
return num;
}
Symmetry signalVector::getSymmetry() const
{
return symmetry;
}
void signalVector::setSymmetry(Symmetry symmetry)
{
this->symmetry = symmetry;
}
bool signalVector::isReal() const
{
return real;
}
void signalVector::isReal(bool wOnly)
{
real = wOnly;
}
bool signalVector::isAligned() const
{
return aligned;
}
void signalVector::setAligned(bool aligned)
{
this->aligned = aligned;
}

Some files were not shown because too many files have changed in this diff Show More