blob: fbcacf165f4f6a9134c6f794fdafe536fd36cb76 [file] [log] [blame]
dburgessb3a0ca42011-10-12 07:44:40 +00001/*
Tom Tsou28670fb2015-08-21 19:32:58 -07002 * Radio device interface
3 *
4 * Copyright (C) 2008-2014 Free Software Foundation, Inc.
5 * Copyright (C) 2015 Ettus Research LLC
6 *
Pau Espin Pedrol21d03d32019-07-22 12:05:52 +02007 * SPDX-License-Identifier: AGPL-3.0+
8 *
Tom Tsou28670fb2015-08-21 19:32:58 -07009 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
18 *
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * See the COPYING file in the main directory for details.
22 */
dburgessb3a0ca42011-10-12 07:44:40 +000023
dburgessb3a0ca42011-10-12 07:44:40 +000024#include "radioInterface.h"
Thomas Tsouc1f7c422013-10-11 13:49:55 -040025#include "Resampler.h"
dburgessb3a0ca42011-10-12 07:44:40 +000026#include <Logger.h>
Pau Espin Pedrole503c982019-09-13 18:56:08 +020027#include <Threads.h>
dburgessb3a0ca42011-10-12 07:44:40 +000028
Thomas Tsou9471d762013-08-20 21:24:24 -040029extern "C" {
30#include "convert.h"
31}
32
Thomas Tsou3952d802013-10-15 15:12:24 -040033#define CHUNK 625
34#define NUMCHUNKS 4
kurtis.heimerl9b557832011-11-26 03:18:34 +000035
Pau Espin Pedrola801ae52019-09-13 15:59:29 +020036RadioInterface::RadioInterface(RadioDevice *wDevice, size_t tx_sps,
Tom Tsoud6ae8642017-03-30 17:22:58 -070037 size_t rx_sps, size_t chans,
Thomas Tsoue90a42b2013-11-13 23:38:09 -050038 int wReceiveOffset, GSM::Time wStartTime)
Pau Espin Pedrola801ae52019-09-13 15:59:29 +020039 : mDevice(wDevice), mSPSTx(tx_sps), mSPSRx(rx_sps), mChans(chans),
Harald Welte2896cec2019-07-21 11:55:22 +020040 underrun(false), overrun(false), writeTimestamp(0), readTimestamp(0),
41 receiveOffset(wReceiveOffset), mOn(false)
dburgessb3a0ca42011-10-12 07:44:40 +000042{
dburgessb3a0ca42011-10-12 07:44:40 +000043 mClock.set(wStartTime);
dburgessb3a0ca42011-10-12 07:44:40 +000044}
45
Thomas Tsou03e6ecf2013-08-20 20:54:54 -040046RadioInterface::~RadioInterface(void)
47{
48 close();
49}
kurtis.heimerl54354042011-11-26 03:18:49 +000050
Thomas Tsoufe269fe2013-10-14 23:56:51 -040051bool RadioInterface::init(int type)
Thomas Tsou03e6ecf2013-08-20 20:54:54 -040052{
Tom Tsoud6ae8642017-03-30 17:22:58 -070053 if ((type != RadioDevice::NORMAL) || !mChans) {
Thomas Tsoue90a42b2013-11-13 23:38:09 -050054 LOG(ALERT) << "Invalid configuration";
Thomas Tsou204a9f12013-10-29 18:34:16 -040055 return false;
56 }
57
Thomas Tsou03e6ecf2013-08-20 20:54:54 -040058 close();
59
Thomas Tsou204a9f12013-10-29 18:34:16 -040060 sendBuffer.resize(mChans);
61 recvBuffer.resize(mChans);
62 convertSendBuffer.resize(mChans);
63 convertRecvBuffer.resize(mChans);
64 mReceiveFIFO.resize(mChans);
Thomas Tsoucb269a32013-11-15 14:15:47 -050065 powerScaling.resize(mChans);
Thomas Tsou03e6ecf2013-08-20 20:54:54 -040066
Thomas Tsou204a9f12013-10-29 18:34:16 -040067 for (size_t i = 0; i < mChans; i++) {
Tom Tsou28670fb2015-08-21 19:32:58 -070068 sendBuffer[i] = new RadioBuffer(NUMCHUNKS, CHUNK * mSPSTx, 0, true);
69 recvBuffer[i] = new RadioBuffer(NUMCHUNKS, CHUNK * mSPSRx, 0, false);
Thomas Tsou204a9f12013-10-29 18:34:16 -040070
Tom Tsou28670fb2015-08-21 19:32:58 -070071 convertSendBuffer[i] = new short[CHUNK * mSPSTx * 2];
72 convertRecvBuffer[i] = new short[CHUNK * mSPSRx * 2];
Alexander Chemeris19174f52016-06-18 11:16:54 +030073
74 powerScaling[i] = 1.0;
Thomas Tsou204a9f12013-10-29 18:34:16 -040075 }
Thomas Tsou03e6ecf2013-08-20 20:54:54 -040076
Thomas Tsou03e6ecf2013-08-20 20:54:54 -040077 return true;
78}
79
80void RadioInterface::close()
81{
Pau Espin Pedrol39e0bba2018-12-03 12:19:51 +010082 for (std::vector<RadioBuffer*>::iterator it = sendBuffer.begin(); it != sendBuffer.end(); ++it)
83 delete *it;
84 for (std::vector<RadioBuffer*>::iterator it = recvBuffer.begin(); it != recvBuffer.end(); ++it)
85 delete *it;
86 for (std::vector<short*>::iterator it = convertSendBuffer.begin(); it != convertSendBuffer.end(); ++it)
87 delete[] *it;
88 for (std::vector<short*>::iterator it = convertRecvBuffer.begin(); it != convertRecvBuffer.end(); ++it)
89 delete[] *it;
Thomas Tsou204a9f12013-10-29 18:34:16 -040090 sendBuffer.resize(0);
91 recvBuffer.resize(0);
92 convertSendBuffer.resize(0);
93 convertRecvBuffer.resize(0);
dburgessb3a0ca42011-10-12 07:44:40 +000094}
95
96double RadioInterface::fullScaleInputValue(void) {
Pau Espin Pedrola801ae52019-09-13 15:59:29 +020097 return mDevice->fullScaleInputValue();
dburgessb3a0ca42011-10-12 07:44:40 +000098}
99
100double RadioInterface::fullScaleOutputValue(void) {
Pau Espin Pedrola801ae52019-09-13 15:59:29 +0200101 return mDevice->fullScaleOutputValue();
dburgessb3a0ca42011-10-12 07:44:40 +0000102}
103
Tom Tsoua4d1a412014-11-25 15:46:56 -0800104int RadioInterface::setPowerAttenuation(int atten, size_t chan)
dburgessb3a0ca42011-10-12 07:44:40 +0000105{
kurtis.heimerl16c65402011-11-26 03:18:11 +0000106 double rfGain, digAtten;
kurtis.heimerlee5347a2011-11-26 03:18:05 +0000107
Thomas Tsou204a9f12013-10-29 18:34:16 -0400108 if (chan >= mChans) {
109 LOG(ALERT) << "Invalid channel requested";
Tom Tsoua4d1a412014-11-25 15:46:56 -0800110 return -1;
Thomas Tsou204a9f12013-10-29 18:34:16 -0400111 }
112
Tom Tsoua4d1a412014-11-25 15:46:56 -0800113 if (atten < 0.0)
114 atten = 0.0;
115
Pau Espin Pedrol62845242019-09-13 17:29:21 +0200116 rfGain = setTxGain(mDevice->maxTxGain() - (double) atten, chan);
Pau Espin Pedrola801ae52019-09-13 15:59:29 +0200117 digAtten = (double) atten - mDevice->maxTxGain() + rfGain;
kurtis.heimerlee5347a2011-11-26 03:18:05 +0000118
119 if (digAtten < 1.0)
Thomas Tsoucb269a32013-11-15 14:15:47 -0500120 powerScaling[chan] = 1.0;
kurtis.heimerlee5347a2011-11-26 03:18:05 +0000121 else
Thomas Tsoucb269a32013-11-15 14:15:47 -0500122 powerScaling[chan] = 1.0 / sqrt(pow(10, digAtten / 10.0));
Tom Tsoua4d1a412014-11-25 15:46:56 -0800123
124 return atten;
dburgessb3a0ca42011-10-12 07:44:40 +0000125}
126
kurtis.heimerl9b557832011-11-26 03:18:34 +0000127int RadioInterface::radioifyVector(signalVector &wVector,
Tom Tsou28670fb2015-08-21 19:32:58 -0700128 size_t chan, bool zero)
dburgessb3a0ca42011-10-12 07:44:40 +0000129{
Tom Tsou28670fb2015-08-21 19:32:58 -0700130 if (zero)
131 sendBuffer[chan]->zero(wVector.size());
132 else
133 sendBuffer[chan]->write((float *) wVector.begin(), wVector.size());
kurtis.heimerl9b557832011-11-26 03:18:34 +0000134
135 return wVector.size();
dburgessb3a0ca42011-10-12 07:44:40 +0000136}
137
Tom Tsou28670fb2015-08-21 19:32:58 -0700138int RadioInterface::unRadioifyVector(signalVector *newVector, size_t chan)
dburgessb3a0ca42011-10-12 07:44:40 +0000139{
Tom Tsou28670fb2015-08-21 19:32:58 -0700140 if (newVector->size() > recvBuffer[chan]->getAvailSamples()) {
Thomas Tsou9471d762013-08-20 21:24:24 -0400141 LOG(ALERT) << "Insufficient number of samples in receive buffer";
142 return -1;
143 }
144
Tom Tsou28670fb2015-08-21 19:32:58 -0700145 recvBuffer[chan]->read((float *) newVector->begin(), newVector->size());
dburgessb3a0ca42011-10-12 07:44:40 +0000146
Tom Tsou28670fb2015-08-21 19:32:58 -0700147 return newVector->size();
dburgessb3a0ca42011-10-12 07:44:40 +0000148}
149
Thomas Tsou204a9f12013-10-29 18:34:16 -0400150bool RadioInterface::tuneTx(double freq, size_t chan)
dburgessb3a0ca42011-10-12 07:44:40 +0000151{
Pau Espin Pedrola801ae52019-09-13 15:59:29 +0200152 return mDevice->setTxFreq(freq, chan);
dburgessb3a0ca42011-10-12 07:44:40 +0000153}
154
Thomas Tsou204a9f12013-10-29 18:34:16 -0400155bool RadioInterface::tuneRx(double freq, size_t chan)
dburgessb3a0ca42011-10-12 07:44:40 +0000156{
Pau Espin Pedrola801ae52019-09-13 15:59:29 +0200157 return mDevice->setRxFreq(freq, chan);
dburgessb3a0ca42011-10-12 07:44:40 +0000158}
159
Pau Espin Pedrol0fc20d12018-04-24 17:48:52 +0200160/** synchronization thread loop */
161void *AlignRadioServiceLoopAdapter(RadioInterface *radioInterface)
162{
Pau Espin Pedrol5b60c982018-09-20 18:04:46 +0200163 set_selfthread_name("AlignRadio");
Pau Espin Pedrol0fc20d12018-04-24 17:48:52 +0200164 while (1) {
165 sleep(60);
166 radioInterface->alignRadio();
167 pthread_testcancel();
168 }
169 return NULL;
170}
171
172void RadioInterface::alignRadio() {
Pau Espin Pedrola801ae52019-09-13 15:59:29 +0200173 mDevice->updateAlignment(writeTimestamp+ (TIMESTAMP) 10000);
Pau Espin Pedrol0fc20d12018-04-24 17:48:52 +0200174}
175
Tom Tsoueb54bdd2014-11-25 16:06:32 -0800176bool RadioInterface::start()
dburgessb3a0ca42011-10-12 07:44:40 +0000177{
Tom Tsoueb54bdd2014-11-25 16:06:32 -0800178 if (mOn)
179 return true;
180
181 LOG(INFO) << "Starting radio device";
Pau Espin Pedrola801ae52019-09-13 15:59:29 +0200182 if (mDevice->requiresRadioAlign())
Pau Espin Pedrol0fc20d12018-04-24 17:48:52 +0200183 mAlignRadioServiceLoopThread.start(
184 (void * (*)(void*))AlignRadioServiceLoopAdapter,
185 (void*)this);
Tom Tsoueb54bdd2014-11-25 16:06:32 -0800186
Pau Espin Pedrola801ae52019-09-13 15:59:29 +0200187 if (!mDevice->start())
Tom Tsoueb54bdd2014-11-25 16:06:32 -0800188 return false;
189
Tom Tsou28670fb2015-08-21 19:32:58 -0700190 for (size_t i = 0; i < mChans; i++) {
191 sendBuffer[i]->reset();
192 recvBuffer[i]->reset();
193 }
Tom Tsoud7610cf2015-05-07 17:39:49 -0700194
Pau Espin Pedrola801ae52019-09-13 15:59:29 +0200195 writeTimestamp = mDevice->initialWriteTimestamp();
196 readTimestamp = mDevice->initialReadTimestamp();
Thomas Tsou18d3b832014-02-13 14:55:23 -0500197
Pau Espin Pedrola801ae52019-09-13 15:59:29 +0200198 mDevice->updateAlignment(writeTimestamp-10000);
199 mDevice->updateAlignment(writeTimestamp-10000);
dburgessb3a0ca42011-10-12 07:44:40 +0000200
dburgessb3a0ca42011-10-12 07:44:40 +0000201 mOn = true;
Thomas Tsou18d3b832014-02-13 14:55:23 -0500202 LOG(INFO) << "Radio started";
Tom Tsoueb54bdd2014-11-25 16:06:32 -0800203 return true;
204}
205
206/*
207 * Stop the radio device
208 *
209 * This is a pass-through call to the device interface. Because the underlying
210 * stop command issuance generally doesn't return confirmation on device status,
211 * this call will only return false if the device is already stopped.
212 */
213bool RadioInterface::stop()
214{
Pau Espin Pedrola801ae52019-09-13 15:59:29 +0200215 if (!mOn || !mDevice->stop())
Tom Tsoueb54bdd2014-11-25 16:06:32 -0800216 return false;
217
218 mOn = false;
219 return true;
dburgessb3a0ca42011-10-12 07:44:40 +0000220}
221
Thomas Tsou204a9f12013-10-29 18:34:16 -0400222void RadioInterface::driveTransmitRadio(std::vector<signalVector *> &bursts,
223 std::vector<bool> &zeros)
Thomas Tsou03e6ecf2013-08-20 20:54:54 -0400224{
225 if (!mOn)
226 return;
dburgessb3a0ca42011-10-12 07:44:40 +0000227
Tom Tsou28670fb2015-08-21 19:32:58 -0700228 for (size_t i = 0; i < mChans; i++)
229 radioifyVector(*bursts[i], i, zeros[i]);
dburgessb3a0ca42011-10-12 07:44:40 +0000230
Tom Tsou28670fb2015-08-21 19:32:58 -0700231 while (pushBuffer());
dburgessb3a0ca42011-10-12 07:44:40 +0000232}
233
Pau Espin Pedrol8e498bf2018-09-03 16:45:15 +0200234int RadioInterface::driveReceiveRadio()
Thomas Tsou204a9f12013-10-29 18:34:16 -0400235{
236 radioVector *burst = NULL;
dburgessb3a0ca42011-10-12 07:44:40 +0000237
Thomas Tsou204a9f12013-10-29 18:34:16 -0400238 if (!mOn)
Pau Espin Pedrol8e498bf2018-09-03 16:45:15 +0200239 return 0;
dburgessb3a0ca42011-10-12 07:44:40 +0000240
Pau Espin Pedrol8e498bf2018-09-03 16:45:15 +0200241 if (pullBuffer() < 0)
242 return -1;
dburgessb3a0ca42011-10-12 07:44:40 +0000243
244 GSM::Time rcvClock = mClock.get();
245 rcvClock.decTN(receiveOffset);
246 unsigned tN = rcvClock.TN();
Tom Tsou28670fb2015-08-21 19:32:58 -0700247 int recvSz = recvBuffer[0]->getAvailSamples();
dburgessb3a0ca42011-10-12 07:44:40 +0000248 const int symbolsPerSlot = gSlotLen + 8;
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800249 int burstSize;
250
251 if (mSPSRx == 4)
252 burstSize = 625;
253 else
254 burstSize = symbolsPerSlot + (tN % 4 == 0);
dburgessb3a0ca42011-10-12 07:44:40 +0000255
Pau Espin Pedrol46444632018-09-03 16:42:04 +0200256 /*
Thomas Tsoud0f3ca32013-11-09 22:05:23 -0500257 * Pre-allocate head room for the largest correlation size
258 * so we can later avoid a re-allocation and copy
259 * */
Vadim Yanitskiya79bc702018-10-17 11:01:58 +0200260 size_t head = GSM::gRACHSynchSequenceTS0.size();
Thomas Tsoud0f3ca32013-11-09 22:05:23 -0500261
262 /*
263 * Form receive bursts and pass up to transceiver. Use repeating
264 * pattern of 157-156-156-156 symbols per timeslot
265 */
Thomas Tsoue0fa2bf2013-11-09 02:46:29 -0500266 while (recvSz > burstSize) {
Thomas Tsou204a9f12013-10-29 18:34:16 -0400267 for (size_t i = 0; i < mChans; i++) {
Tom Tsoud6ae8642017-03-30 17:22:58 -0700268 burst = new radioVector(rcvClock, burstSize, head);
269 unRadioifyVector(burst->getVector(), i);
Thomas Tsoue90a42b2013-11-13 23:38:09 -0500270
Thomas Tsoue0fa2bf2013-11-09 02:46:29 -0500271 if (mReceiveFIFO[i].size() < 32)
Thomas Tsou204a9f12013-10-29 18:34:16 -0400272 mReceiveFIFO[i].write(burst);
Thomas Tsoue0fa2bf2013-11-09 02:46:29 -0500273 else
Thomas Tsou204a9f12013-10-29 18:34:16 -0400274 delete burst;
dburgessb3a0ca42011-10-12 07:44:40 +0000275 }
Thomas Tsou204a9f12013-10-29 18:34:16 -0400276
277 mClock.incTN();
dburgessb3a0ca42011-10-12 07:44:40 +0000278 rcvClock.incTN();
Thomas Tsoue0fa2bf2013-11-09 02:46:29 -0500279 recvSz -= burstSize;
dburgessb3a0ca42011-10-12 07:44:40 +0000280
281 tN = rcvClock.TN();
Thomas Tsoue0fa2bf2013-11-09 02:46:29 -0500282
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800283 if (mSPSRx != 4)
284 burstSize = (symbolsPerSlot + (tN % 4 == 0)) * mSPSRx;
dburgessb3a0ca42011-10-12 07:44:40 +0000285 }
286
Pau Espin Pedrol8e498bf2018-09-03 16:45:15 +0200287 return 1;
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000288}
289
290bool RadioInterface::isUnderrun()
291{
Pau Espin Pedrole503c982019-09-13 18:56:08 +0200292 bool retVal;
293 /* atomically get previous value of "underrun" and set the var to false */
294 retVal = osmo_trx_sync_fetch_and_and(&underrun, false);
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000295 return retVal;
296}
297
Thomas Tsou204a9f12013-10-29 18:34:16 -0400298VectorFIFO* RadioInterface::receiveFIFO(size_t chan)
299{
300 if (chan >= mReceiveFIFO.size())
301 return NULL;
302
303 return &mReceiveFIFO[chan];
304}
305
306double RadioInterface::setRxGain(double dB, size_t chan)
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000307{
Pau Espin Pedrola801ae52019-09-13 15:59:29 +0200308 return mDevice->setRxGain(dB, chan);
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000309}
310
Pau Espin Pedrol62845242019-09-13 17:29:21 +0200311double RadioInterface::setTxGain(double dB, size_t chan)
312{
313 return mDevice->setTxGain(dB, chan);
314}
315
Thomas Tsouc1f7c422013-10-11 13:49:55 -0400316/* Receive a timestamped chunk from the device */
Pau Espin Pedrol8e498bf2018-09-03 16:45:15 +0200317int RadioInterface::pullBuffer()
Thomas Tsoucb69f082013-04-08 14:18:26 -0400318{
319 bool local_underrun;
Pau Espin Pedrol97009692018-09-03 17:01:59 +0200320 int numRecv;
321 size_t segmentLen = recvBuffer[0]->getSegmentLen();
Thomas Tsoucb69f082013-04-08 14:18:26 -0400322
Tom Tsou28670fb2015-08-21 19:32:58 -0700323 if (recvBuffer[0]->getFreeSegments() <= 0)
Pau Espin Pedrol8e498bf2018-09-03 16:45:15 +0200324 return -1;
Thomas Tsou3952d802013-10-15 15:12:24 -0400325
Thomas Tsouc1f7c422013-10-11 13:49:55 -0400326 /* Outer buffer access size is fixed */
Pau Espin Pedrola801ae52019-09-13 15:59:29 +0200327 numRecv = mDevice->readSamples(convertRecvBuffer,
Tom Tsou28670fb2015-08-21 19:32:58 -0700328 segmentLen,
329 &overrun,
330 readTimestamp,
331 &local_underrun);
332
Pau Espin Pedrol97009692018-09-03 17:01:59 +0200333 if ((size_t) numRecv != segmentLen) {
Tom Tsou28670fb2015-08-21 19:32:58 -0700334 LOG(ALERT) << "Receive error " << numRecv;
Pau Espin Pedrol8e498bf2018-09-03 16:45:15 +0200335 return -1;
Thomas Tsou9471d762013-08-20 21:24:24 -0400336 }
Thomas Tsoucb69f082013-04-08 14:18:26 -0400337
Thomas Tsou204a9f12013-10-29 18:34:16 -0400338 for (size_t i = 0; i < mChans; i++) {
Tom Tsou28670fb2015-08-21 19:32:58 -0700339 convert_short_float(recvBuffer[i]->getWriteSegment(),
340 convertRecvBuffer[i],
341 segmentLen * 2);
Thomas Tsou204a9f12013-10-29 18:34:16 -0400342 }
Thomas Tsoucb69f082013-04-08 14:18:26 -0400343
Pau Espin Pedrole503c982019-09-13 18:56:08 +0200344 osmo_trx_sync_or_and_fetch(&underrun, local_underrun);
Tom Tsou28670fb2015-08-21 19:32:58 -0700345 readTimestamp += numRecv;
Pau Espin Pedrol8e498bf2018-09-03 16:45:15 +0200346 return 0;
Thomas Tsoucb69f082013-04-08 14:18:26 -0400347}
348
Thomas Tsouc1f7c422013-10-11 13:49:55 -0400349/* Send timestamped chunk to the device with arbitrary size */
Tom Tsou28670fb2015-08-21 19:32:58 -0700350bool RadioInterface::pushBuffer()
Thomas Tsoucb69f082013-04-08 14:18:26 -0400351{
Pau Espin Pedrol2c673e02019-07-29 20:14:47 +0200352 bool local_underrun;
Tom Tsou28670fb2015-08-21 19:32:58 -0700353 size_t numSent, segmentLen = sendBuffer[0]->getSegmentLen();
Thomas Tsou9471d762013-08-20 21:24:24 -0400354
Tom Tsou28670fb2015-08-21 19:32:58 -0700355 if (sendBuffer[0]->getAvailSegments() < 1)
356 return false;
Thomas Tsou3952d802013-10-15 15:12:24 -0400357
Thomas Tsou204a9f12013-10-29 18:34:16 -0400358 for (size_t i = 0; i < mChans; i++) {
359 convert_float_short(convertSendBuffer[i],
Tom Tsoub577ef02016-07-12 16:07:48 -0700360 (float *) sendBuffer[i]->getReadSegment(),
Tom Tsou28670fb2015-08-21 19:32:58 -0700361 powerScaling[i],
362 segmentLen * 2);
Thomas Tsou204a9f12013-10-29 18:34:16 -0400363 }
Thomas Tsoucb69f082013-04-08 14:18:26 -0400364
Tom Tsou28670fb2015-08-21 19:32:58 -0700365 /* Send the all samples in the send buffer */
Pau Espin Pedrola801ae52019-09-13 15:59:29 +0200366 numSent = mDevice->writeSamples(convertSendBuffer,
Tom Tsou28670fb2015-08-21 19:32:58 -0700367 segmentLen,
Pau Espin Pedrol2c673e02019-07-29 20:14:47 +0200368 &local_underrun,
Tom Tsou28670fb2015-08-21 19:32:58 -0700369 writeTimestamp);
Pau Espin Pedrole503c982019-09-13 18:56:08 +0200370 osmo_trx_sync_or_and_fetch(&underrun, local_underrun);
Tom Tsou28670fb2015-08-21 19:32:58 -0700371 writeTimestamp += numSent;
372
373 return true;
Thomas Tsoucb69f082013-04-08 14:18:26 -0400374}