Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG UE
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenXG
OpenXG UE
Commits
501c5c9a
Commit
501c5c9a
authored
Apr 08, 2021
by
rmagueta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert code indentation in usrp_lib
parent
29fcb25a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
410 additions
and
390 deletions
+410
-390
targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp
targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp
+410
-390
No files found.
targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp
View file @
501c5c9a
...
...
@@ -272,6 +272,7 @@ static int sync_to_gps(openair0_device *device) {
*/
static
int
trx_usrp_start
(
openair0_device
*
device
)
{
usrp_state_t
*
s
=
(
usrp_state_t
*
)
device
->
priv
;
// setup GPIO for TDD, GPIO(4) = ATR_RX
//set data direction register (DDR) to output
s
->
usrp
->
set_gpio_attr
(
"FP0"
,
"DDR"
,
0xfff
,
0xfff
);
...
...
@@ -284,16 +285,17 @@ static int trx_usrp_start(openair0_device *device) {
s
->
usrp
->
set_gpio_attr
(
"FP0"
,
"ATR_XX"
,
(
1
<<
5
),
0x7f
);
// set the output pins to 1
s
->
usrp
->
set_gpio_attr
(
"FP0"
,
"OUT"
,
7
<<
7
,
0xf80
);
s
->
wait_for_first_pps
=
1
;
s
->
rx_count
=
0
;
s
->
tx_count
=
0
;
//s->first_tx = 1;
//s->first_rx = 1;
s
->
rx_timestamp
=
0
;
s
->
usrp
->
set_time_next_pps
(
uhd
::
time_spec_t
(
0.0
));
// wait for the pps to change
uhd
::
time_spec_t
time_last_pps
=
s
->
usrp
->
get_time_last_pps
();
while
(
time_last_pps
==
s
->
usrp
->
get_time_last_pps
())
{
boost
::
this_thread
::
sleep
(
boost
::
posix_time
::
milliseconds
(
1
));
}
...
...
@@ -302,6 +304,7 @@ static int trx_usrp_start(openair0_device *device) {
cmd
.
time_spec
=
uhd
::
time_spec_t
(
1.0
);
cmd
.
stream_now
=
false
;
// start at constant delay
s
->
rx_stream
->
issue_stream_cmd
(
cmd
);
return
0
;
}
/*! \brief Terminate operation of the USRP transceiver -- free all associated resources
...
...
@@ -315,8 +318,9 @@ static void trx_usrp_end(openair0_device *device) {
if
(
s
==
NULL
)
return
;
iqrecorder_end
(
device
);
}
/*! \brief Called to send samples to the USRP RF target
...
...
@@ -336,12 +340,16 @@ static int trx_usrp_write(openair0_device *device,
int
ret
=
0
;
usrp_state_t
*
s
=
(
usrp_state_t
*
)
device
->
priv
;
int
nsamps2
;
// aligned to upper 32 or 16 byte boundary
int
flags_lsb
=
flags
&
0xff
;
int
flags_msb
=
(
flags
>>
8
)
&
0xff
;
int
end
;
openair0_thread_t
*
write_thread
=
&
device
->
write_thread
;
openair0_write_package_t
*
write_package
=
write_thread
->
write_package
;
AssertFatal
(
MAX_WRITE_THREAD_BUFFER_SIZE
>=
cc
,
"Do not support more than %d cc number
\n
"
,
MAX_WRITE_THREAD_BUFFER_SIZE
);
boolean_t
first_packet_state
=
false
,
last_packet_state
=
false
;
if
(
flags_lsb
==
2
)
{
// start of burst
...
...
@@ -364,7 +372,8 @@ static int trx_usrp_write(openair0_device *device,
// s->tx_md.end_of_burst = false;
first_packet_state
=
false
;
last_packet_state
=
false
;
}
else
if
(
flags_lsb
==
10
)
{
// fail safe mode
}
else
if
(
flags_lsb
==
10
)
{
// fail safe mode
// s->tx_md.has_time_spec = false;
// s->tx_md.start_of_burst = false;
// s->tx_md.end_of_burst = true;
...
...
@@ -372,15 +381,15 @@ static int trx_usrp_write(openair0_device *device,
last_packet_state
=
true
;
}
if
(
usrp_tx_thread
==
0
)
{
if
(
usrp_tx_thread
==
0
){
#if defined(__x86_64) || defined(__i386__)
#ifdef __AVX2__
#ifdef __AVX2__
nsamps2
=
(
nsamps
+
7
)
>>
3
;
__m256i
buff_tx
[
8
][
nsamps2
];
#else
#else
nsamps2
=
(
nsamps
+
3
)
>>
2
;
__m128i
buff_tx
[
8
][
nsamps2
];
#endif
#endif
#elif defined(__arm__)
nsamps2
=
(
nsamps
+
3
)
>>
2
;
int16x8_t
buff_tx
[
8
][
nsamps2
];
...
...
@@ -408,8 +417,8 @@ static int trx_usrp_write(openair0_device *device,
s
->
tx_md
.
end_of_burst
=
last_packet_state
;
s
->
tx_md
.
time_spec
=
uhd
::
time_spec_t
::
from_ticks
(
timestamp
,
s
->
sample_rate
);
s
->
tx_count
++
;
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME
(
VCD_SIGNAL_DUMPER_FUNCTIONS_BEAM_SWITCHING_GPIO
,
1
);
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME
(
VCD_SIGNAL_DUMPER_FUNCTIONS_BEAM_SWITCHING_GPIO
,
1
);
// bit 3 enables gpio (for backward compatibility)
if
(
flags_msb
&
8
)
{
// push GPIO bits 7-9 from flags_msb
...
...
@@ -418,8 +427,7 @@ static int trx_usrp_write(openair0_device *device,
s
->
usrp
->
set_gpio_attr
(
"FP0"
,
"OUT"
,
gpio789
,
0x380
);
s
->
usrp
->
clear_command_time
();
}
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME
(
VCD_SIGNAL_DUMPER_FUNCTIONS_BEAM_SWITCHING_GPIO
,
0
);
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME
(
VCD_SIGNAL_DUMPER_FUNCTIONS_BEAM_SWITCHING_GPIO
,
0
);
if
(
cc
>
1
)
{
std
::
vector
<
void
*>
buff_ptrs
;
...
...
@@ -428,18 +436,18 @@ static int trx_usrp_write(openair0_device *device,
buff_ptrs
.
push_back
(
&
(((
int16_t
*
)
buff_tx
[
i
])[
0
]));
ret
=
(
int
)
s
->
tx_stream
->
send
(
buff_ptrs
,
nsamps
,
s
->
tx_md
);
}
else
{
}
else
{
ret
=
(
int
)
s
->
tx_stream
->
send
(
&
(((
int16_t
*
)
buff_tx
[
0
])[
0
]),
nsamps
,
s
->
tx_md
);
}
if
(
ret
!=
nsamps
)
LOG_E
(
HW
,
"[xmit] tx samples %d != %d
\n
"
,
ret
,
nsamps
);
if
(
ret
!=
nsamps
)
LOG_E
(
HW
,
"[xmit] tx samples %d != %d
\n
"
,
ret
,
nsamps
);
return
ret
;
}
else
{
}
else
{
pthread_mutex_lock
(
&
write_thread
->
mutex_write
);
if
(
write_thread
->
count_write
>=
MAX_WRITE_THREAD_PACKAGE
)
{
if
(
write_thread
->
count_write
>=
MAX_WRITE_THREAD_PACKAGE
){
LOG_W
(
HW
,
"Buffer overflow, count_write = %d, start = %d end = %d, resetting write package
\n
"
,
write_thread
->
count_write
,
write_thread
->
start
,
write_thread
->
end
);
write_thread
->
end
=
write_thread
->
start
;
write_thread
->
count_write
=
0
;
...
...
@@ -452,16 +460,15 @@ static int trx_usrp_write(openair0_device *device,
write_package
[
end
].
first_packet
=
first_packet_state
;
write_package
[
end
].
last_packet
=
last_packet_state
;
write_package
[
end
].
flags_msb
=
flags_msb
;
for
(
int
i
=
0
;
i
<
cc
;
i
++
)
write_package
[
end
].
buff
[
i
]
=
buff
[
i
];
write_thread
->
count_write
++
;
write_thread
->
end
=
(
write_thread
->
end
+
1
)
%
MAX_WRITE_THREAD_PACKAGE
;
pthread_cond_signal
(
&
write_thread
->
cond_write
);
pthread_mutex_unlock
(
&
write_thread
->
mutex_write
);
return
0
;
}
}
//-----------------------start--------------------------
...
...
@@ -473,11 +480,12 @@ static int trx_usrp_write(openair0_device *device,
@param antenna_id index of the antenna if the device has multiple antennas
@param flags flags must be set to TRUE if timestamp parameter needs to be applied
*/
void
*
trx_usrp_write_thread
(
void
*
arg
)
{
void
*
trx_usrp_write_thread
(
void
*
arg
)
{
int
ret
=
0
;
openair0_device
*
device
=
(
openair0_device
*
)
arg
;
openair0_thread_t
*
write_thread
=
&
device
->
write_thread
;
openair0_write_package_t
*
write_package
=
write_thread
->
write_package
;
usrp_state_t
*
s
;
int
nsamps2
;
// aligned to upper 32 or 16 byte boundary
int
start
;
...
...
@@ -489,13 +497,11 @@ void *trx_usrp_write_thread(void *arg) {
signed
char
last_packet
;
int
flags_msb
;
while
(
1
)
{
while
(
1
){
pthread_mutex_lock
(
&
write_thread
->
mutex_write
);
while
(
write_thread
->
count_write
==
0
)
{
pthread_cond_wait
(
&
write_thread
->
cond_write
,
&
write_thread
->
mutex_write
);
// this unlocks mutex_rxtx while waiting and then locks it again
}
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME
(
VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_WRITE_THREAD
,
1
);
s
=
(
usrp_state_t
*
)
device
->
priv
;
start
=
write_thread
->
start
;
...
...
@@ -512,36 +518,38 @@ void *trx_usrp_write_thread(void *arg) {
/*if(write_thread->count_write != 0){
LOG_W(HW,"count write = %d, start = %d, end = %d\n", write_thread->count_write, write_thread->start, write_thread->end);
}*/
#if defined(__x86_64) || defined(__i386__)
#ifdef __AVX2__
#if defined(__x86_64) || defined(__i386__)
#ifdef __AVX2__
nsamps2
=
(
nsamps
+
7
)
>>
3
;
__m256i
buff_tx
[
8
][
nsamps2
];
#else
#else
nsamps2
=
(
nsamps
+
3
)
>>
2
;
__m128i
buff_tx
[
8
][
nsamps2
];
#endif
#elif defined(__arm__)
#endif
#elif defined(__arm__)
nsamps2
=
(
nsamps
+
3
)
>>
2
;
int16x8_t
buff_tx
[
8
][
nsamps2
];
#else
#error Unsupported CPU architecture, USRP device cannot be built
#endif
#else
#error Unsupported CPU architecture, USRP device cannot be built
#endif
// bring RX data into 12 LSBs for softmodem RX
for
(
int
i
=
0
;
i
<
cc
;
i
++
)
{
for
(
int
j
=
0
;
j
<
nsamps2
;
j
++
)
{
#if defined(__x86_64__) || defined(__i386__)
#ifdef __AVX2__
#if defined(__x86_64__) || defined(__i386__)
#ifdef __AVX2__
buff_tx
[
i
][
j
]
=
_mm256_slli_epi16
(((
__m256i
*
)
buff
[
i
])[
j
],
4
);
#else
#else
buff_tx
[
i
][
j
]
=
_mm_slli_epi16
(((
__m128i
*
)
buff
[
i
])[
j
],
4
);
#endif
#elif defined(__arm__)
#endif
#elif defined(__arm__)
buff_tx
[
i
][
j
]
=
vshlq_n_s16
(((
int16x8_t
*
)
buff
[
i
])[
j
],
4
);
#endif
#endif
}
}
s
->
tx_md
.
has_time_spec
=
true
;
s
->
tx_md
.
start_of_burst
=
(
s
->
tx_count
==
0
)
?
true
:
first_packet
;
s
->
tx_md
.
end_of_burst
=
last_packet
;
...
...
@@ -564,32 +572,34 @@ void *trx_usrp_write_thread(void *arg) {
buff_ptrs
.
push_back
(
&
(((
int16_t
*
)
buff_tx
[
i
])[
0
]));
ret
=
(
int
)
s
->
tx_stream
->
send
(
buff_ptrs
,
nsamps
,
s
->
tx_md
);
}
else
{
}
else
{
ret
=
(
int
)
s
->
tx_stream
->
send
(
&
(((
int16_t
*
)
buff_tx
[
0
])[
0
]),
nsamps
,
s
->
tx_md
);
}
if
(
ret
!=
nsamps
)
LOG_E
(
HW
,
"[xmit] tx samples %d != %d
\n
"
,
ret
,
nsamps
);
if
(
ret
!=
nsamps
)
LOG_E
(
HW
,
"[xmit] tx samples %d != %d
\n
"
,
ret
,
nsamps
);
VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME
(
VCD_SIGNAL_DUMPER_VARIABLES_USRP_SEND_RETURN
,
ret
);
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME
(
VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_WRITE_THREAD
,
0
);
if
(
0
)
break
;
if
(
0
)
break
;
}
return
NULL
;
}
int
trx_usrp_write_init
(
openair0_device
*
device
)
{
int
trx_usrp_write_init
(
openair0_device
*
device
){
uhd
::
set_thread_priority_safe
(
1.0
);
openair0_thread_t
*
write_thread
=
&
device
->
write_thread
;
printf
(
"initializing tx write thread
\n
"
);
write_thread
->
start
=
0
;
write_thread
->
end
=
0
;
write_thread
->
count_write
=
0
;
printf
(
"end of tx write thread
\n
"
);
pthread_create
(
&
write_thread
->
pthread_write
,
NULL
,
trx_usrp_write_thread
,(
void
*
)
device
);
return
(
0
);
}
...
...
@@ -627,8 +637,7 @@ static int trx_usrp_read(openair0_device *device, openair0_timestamp *ptimestamp
// receive multiple channels (e.g. RF A and RF B)
std
::
vector
<
void
*>
buff_ptrs
;
for
(
int
i
=
0
;
i
<
cc
;
i
++
)
buff_ptrs
.
push_back
(
buff_tmp
[
i
]);
for
(
int
i
=
0
;
i
<
cc
;
i
++
)
buff_ptrs
.
push_back
(
buff_tmp
[
i
]);
samples_received
=
s
->
rx_stream
->
recv
(
buff_ptrs
,
nsamps
,
s
->
rx_md
);
}
else
{
...
...
@@ -636,7 +645,7 @@ static int trx_usrp_read(openair0_device *device, openair0_timestamp *ptimestamp
samples_received
=
0
;
while
(
samples_received
!=
nsamps
)
{
samples_received
+=
s
->
rx_stream
->
recv
((
void
*
)((
int32_t
*
)
buff_tmp
[
0
]
+
samples_received
),
samples_received
+=
s
->
rx_stream
->
recv
((
void
*
)((
int32_t
*
)
buff_tmp
[
0
]
+
samples_received
),
nsamps
-
samples_received
,
s
->
rx_md
);
if
((
s
->
wait_for_first_pps
==
0
)
&&
(
s
->
rx_md
.
error_code
!=
uhd
::
rx_metadata_t
::
ERROR_CODE_NONE
))
...
...
@@ -646,9 +655,7 @@ static int trx_usrp_read(openair0_device *device, openair0_timestamp *ptimestamp
printf
(
"sleep...
\n
"
);
//usleep(100);
}
}
if
(
samples_received
==
nsamps
)
s
->
wait_for_first_pps
=
0
;
if
(
samples_received
==
nsamps
)
s
->
wait_for_first_pps
=
0
;
}
// bring RX data into 12 LSBs for softmodem RX
...
...
@@ -684,6 +691,7 @@ static int trx_usrp_read(openair0_device *device, openair0_timestamp *ptimestamp
s
->
rx_count
+=
nsamps
;
s
->
rx_timestamp
=
s
->
rx_md
.
time_spec
.
to_ticks
(
s
->
sample_rate
);
*
ptimestamp
=
s
->
rx_timestamp
;
// push GPIO bits 7-9 from flags_msb
/*s->usrp->set_command_time(uhd::time_spec_t::from_ticks((s->rx_timestamp+(2*nsamps)),s->sample_rate));
s->usrp->set_gpio_attr("FP0", "OUT", gpio789<<7, 0x380);
...
...
@@ -937,6 +945,8 @@ extern "C" {
device
->
trx_set_freq_func
=
trx_usrp_set_freq
;
device
->
trx_set_gains_func
=
trx_usrp_set_gains
;
device
->
trx_write_init
=
trx_usrp_write_init
;
// hotfix! to be checked later
uhd
::
set_thread_priority_safe
(
1.0
);
// Initialize USRP device
...
...
@@ -1006,16 +1016,20 @@ extern "C" {
if
(
openair0_cfg
[
0
].
clock_source
==
internal
)
{
s
->
usrp
->
set_clock_source
(
"internal"
);
LOG_D
(
HW
,
"Setting clock source to internal
\n
"
);
}
else
if
(
openair0_cfg
[
0
].
clock_source
==
external
)
{
}
else
if
(
openair0_cfg
[
0
].
clock_source
==
external
)
{
s
->
usrp
->
set_clock_source
(
"external"
);
LOG_D
(
HW
,
"Setting clock source to external
\n
"
);
}
else
if
(
openair0_cfg
[
0
].
clock_source
==
gpsdo
)
{
}
else
if
(
openair0_cfg
[
0
].
clock_source
==
gpsdo
)
{
s
->
usrp
->
set_clock_source
(
"gpsdo"
);
LOG_D
(
HW
,
"Setting clock source to gpsdo
\n
"
);
}
else
{
}
else
{
LOG_W
(
HW
,
"Clock source set neither in usrp_args nor on command line, using default!
\n
"
);
}
}
else
{
}
else
{
if
(
openair0_cfg
[
0
].
clock_source
!=
unset
)
{
LOG_W
(
HW
,
"Clock source set in both usrp_args and in clock_source, ingnoring the latter!
\n
"
);
}
...
...
@@ -1025,21 +1039,26 @@ extern "C" {
if
(
openair0_cfg
[
0
].
time_source
==
internal
)
{
s
->
usrp
->
set_time_source
(
"internal"
);
LOG_D
(
HW
,
"Setting time source to internal
\n
"
);
}
else
if
(
openair0_cfg
[
0
].
time_source
==
external
)
{
}
else
if
(
openair0_cfg
[
0
].
time_source
==
external
)
{
s
->
usrp
->
set_time_source
(
"external"
);
LOG_D
(
HW
,
"Setting time source to external
\n
"
);
}
else
if
(
openair0_cfg
[
0
].
time_source
==
gpsdo
)
{
}
else
if
(
openair0_cfg
[
0
].
time_source
==
gpsdo
)
{
s
->
usrp
->
set_time_source
(
"gpsdo"
);
LOG_D
(
HW
,
"Setting time source to gpsdo
\n
"
);
}
else
{
}
else
{
LOG_W
(
HW
,
"Time source set neither in usrp_args nor on command line, using default!
\n
"
);
}
}
else
{
}
else
{
if
(
openair0_cfg
[
0
].
clock_source
!=
unset
)
{
LOG_W
(
HW
,
"Time source set in both usrp_args and in time_source, ingnoring the latter!
\n
"
);
}
}
if
(
s
->
usrp
->
get_clock_source
(
0
)
==
"gpsdo"
)
{
s
->
use_gps
=
1
;
...
...
@@ -1068,6 +1087,7 @@ extern "C" {
std
::
cerr
<<
"-- Using calibration table: calib_table_n310"
<<
std
::
endl
;
}
if
(
device
->
type
==
USRP_N300_DEV
||
device
->
type
==
USRP_X300_DEV
)
{
LOG_I
(
HW
,
"%s() sample_rate:%u
\n
"
,
__FUNCTION__
,
(
int
)
openair0_cfg
[
0
].
sample_rate
);
...
...
@@ -1331,6 +1351,6 @@ extern "C" {
}
}
return
0
;
}
/*@}*/
}
/*@}*/
}
/* extern c */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment