blob: 311af3423d492245023e3dca15b80cfefd43b2b1 [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" {
Pau Espin Pedrol553a2502020-07-29 18:05:25 +020030#include <osmocom/core/utils.h>
31#include <osmocom/vty/cpu_sched_vty.h>
32
Thomas Tsou9471d762013-08-20 21:24:24 -040033#include "convert.h"
34}
35
Thomas Tsou3952d802013-10-15 15:12:24 -040036#define CHUNK 625
37#define NUMCHUNKS 4
kurtis.heimerl9b557832011-11-26 03:18:34 +000038
Pau Espin Pedrola801ae52019-09-13 15:59:29 +020039RadioInterface::RadioInterface(RadioDevice *wDevice, size_t tx_sps,
Tom Tsoud6ae8642017-03-30 17:22:58 -070040 size_t rx_sps, size_t chans,
Thomas Tsoue90a42b2013-11-13 23:38:09 -050041 int wReceiveOffset, GSM::Time wStartTime)
Eric5561f112022-07-19 21:18:21 +020042 : mSPSTx(tx_sps), mSPSRx(rx_sps), mChans(chans), mReceiveFIFO(mChans), mDevice(wDevice),
43 sendBuffer(mChans), recvBuffer(mChans), convertRecvBuffer(mChans),
44 convertSendBuffer(mChans), powerScaling(mChans), underrun(false), overrun(false),
45 writeTimestamp(0), readTimestamp(0), receiveOffset(wReceiveOffset), mOn(false)
dburgessb3a0ca42011-10-12 07:44:40 +000046{
dburgessb3a0ca42011-10-12 07:44:40 +000047 mClock.set(wStartTime);
dburgessb3a0ca42011-10-12 07:44:40 +000048}
49
Thomas Tsou03e6ecf2013-08-20 20:54:54 -040050RadioInterface::~RadioInterface(void)
51{
52 close();
53}
kurtis.heimerl54354042011-11-26 03:18:49 +000054
Thomas Tsoufe269fe2013-10-14 23:56:51 -040055bool RadioInterface::init(int type)
Thomas Tsou03e6ecf2013-08-20 20:54:54 -040056{
Tom Tsoud6ae8642017-03-30 17:22:58 -070057 if ((type != RadioDevice::NORMAL) || !mChans) {
Thomas Tsoue90a42b2013-11-13 23:38:09 -050058 LOG(ALERT) << "Invalid configuration";
Thomas Tsou204a9f12013-10-29 18:34:16 -040059 return false;
60 }
61
Thomas Tsou204a9f12013-10-29 18:34:16 -040062 for (size_t i = 0; i < mChans; i++) {
Tom Tsou28670fb2015-08-21 19:32:58 -070063 sendBuffer[i] = new RadioBuffer(NUMCHUNKS, CHUNK * mSPSTx, 0, true);
64 recvBuffer[i] = new RadioBuffer(NUMCHUNKS, CHUNK * mSPSRx, 0, false);
Thomas Tsou204a9f12013-10-29 18:34:16 -040065
Tom Tsou28670fb2015-08-21 19:32:58 -070066 convertSendBuffer[i] = new short[CHUNK * mSPSTx * 2];
67 convertRecvBuffer[i] = new short[CHUNK * mSPSRx * 2];
Alexander Chemeris19174f52016-06-18 11:16:54 +030068
69 powerScaling[i] = 1.0;
Thomas Tsou204a9f12013-10-29 18:34:16 -040070 }
Thomas Tsou03e6ecf2013-08-20 20:54:54 -040071
Thomas Tsou03e6ecf2013-08-20 20:54:54 -040072 return true;
73}
74
75void RadioInterface::close()
76{
Pau Espin Pedrol39e0bba2018-12-03 12:19:51 +010077 for (std::vector<RadioBuffer*>::iterator it = sendBuffer.begin(); it != sendBuffer.end(); ++it)
78 delete *it;
79 for (std::vector<RadioBuffer*>::iterator it = recvBuffer.begin(); it != recvBuffer.end(); ++it)
80 delete *it;
81 for (std::vector<short*>::iterator it = convertSendBuffer.begin(); it != convertSendBuffer.end(); ++it)
82 delete[] *it;
83 for (std::vector<short*>::iterator it = convertRecvBuffer.begin(); it != convertRecvBuffer.end(); ++it)
84 delete[] *it;
Thomas Tsou204a9f12013-10-29 18:34:16 -040085 sendBuffer.resize(0);
86 recvBuffer.resize(0);
87 convertSendBuffer.resize(0);
88 convertRecvBuffer.resize(0);
dburgessb3a0ca42011-10-12 07:44:40 +000089}
90
91double RadioInterface::fullScaleInputValue(void) {
Pau Espin Pedrola801ae52019-09-13 15:59:29 +020092 return mDevice->fullScaleInputValue();
dburgessb3a0ca42011-10-12 07:44:40 +000093}
94
95double RadioInterface::fullScaleOutputValue(void) {
Pau Espin Pedrola801ae52019-09-13 15:59:29 +020096 return mDevice->fullScaleOutputValue();
dburgessb3a0ca42011-10-12 07:44:40 +000097}
98
Tom Tsoua4d1a412014-11-25 15:46:56 -080099int RadioInterface::setPowerAttenuation(int atten, size_t chan)
dburgessb3a0ca42011-10-12 07:44:40 +0000100{
Pau Espin Pedrol992c9bd2020-06-08 13:44:24 +0200101 double rfAtten, digAtten;
kurtis.heimerlee5347a2011-11-26 03:18:05 +0000102
Thomas Tsou204a9f12013-10-29 18:34:16 -0400103 if (chan >= mChans) {
104 LOG(ALERT) << "Invalid channel requested";
Tom Tsoua4d1a412014-11-25 15:46:56 -0800105 return -1;
Thomas Tsou204a9f12013-10-29 18:34:16 -0400106 }
107
Tom Tsoua4d1a412014-11-25 15:46:56 -0800108 if (atten < 0.0)
109 atten = 0.0;
110
Pau Espin Pedrol992c9bd2020-06-08 13:44:24 +0200111 rfAtten = mDevice->setPowerAttenuation((double) atten, chan);
112 digAtten = (double) atten - rfAtten;
kurtis.heimerlee5347a2011-11-26 03:18:05 +0000113
114 if (digAtten < 1.0)
Thomas Tsoucb269a32013-11-15 14:15:47 -0500115 powerScaling[chan] = 1.0;
kurtis.heimerlee5347a2011-11-26 03:18:05 +0000116 else
Thomas Tsoucb269a32013-11-15 14:15:47 -0500117 powerScaling[chan] = 1.0 / sqrt(pow(10, digAtten / 10.0));
Tom Tsoua4d1a412014-11-25 15:46:56 -0800118
119 return atten;
dburgessb3a0ca42011-10-12 07:44:40 +0000120}
121
Pau Espin Pedrol0e09e7c2020-05-29 16:39:07 +0200122int RadioInterface::getNominalTxPower(size_t chan)
123{
124 if (chan >= mChans) {
125 LOG(ALERT) << "Invalid channel requested";
126 return -1;
127 }
128
129 return mDevice->getNominalTxPower(chan);
130}
131
kurtis.heimerl9b557832011-11-26 03:18:34 +0000132int RadioInterface::radioifyVector(signalVector &wVector,
Tom Tsou28670fb2015-08-21 19:32:58 -0700133 size_t chan, bool zero)
dburgessb3a0ca42011-10-12 07:44:40 +0000134{
Tom Tsou28670fb2015-08-21 19:32:58 -0700135 if (zero)
136 sendBuffer[chan]->zero(wVector.size());
137 else
138 sendBuffer[chan]->write((float *) wVector.begin(), wVector.size());
kurtis.heimerl9b557832011-11-26 03:18:34 +0000139
140 return wVector.size();
dburgessb3a0ca42011-10-12 07:44:40 +0000141}
142
Tom Tsou28670fb2015-08-21 19:32:58 -0700143int RadioInterface::unRadioifyVector(signalVector *newVector, size_t chan)
dburgessb3a0ca42011-10-12 07:44:40 +0000144{
Tom Tsou28670fb2015-08-21 19:32:58 -0700145 if (newVector->size() > recvBuffer[chan]->getAvailSamples()) {
Thomas Tsou9471d762013-08-20 21:24:24 -0400146 LOG(ALERT) << "Insufficient number of samples in receive buffer";
147 return -1;
148 }
149
Tom Tsou28670fb2015-08-21 19:32:58 -0700150 recvBuffer[chan]->read((float *) newVector->begin(), newVector->size());
dburgessb3a0ca42011-10-12 07:44:40 +0000151
Tom Tsou28670fb2015-08-21 19:32:58 -0700152 return newVector->size();
dburgessb3a0ca42011-10-12 07:44:40 +0000153}
154
Thomas Tsou204a9f12013-10-29 18:34:16 -0400155bool RadioInterface::tuneTx(double freq, size_t chan)
dburgessb3a0ca42011-10-12 07:44:40 +0000156{
Pau Espin Pedrola801ae52019-09-13 15:59:29 +0200157 return mDevice->setTxFreq(freq, chan);
dburgessb3a0ca42011-10-12 07:44:40 +0000158}
159
Thomas Tsou204a9f12013-10-29 18:34:16 -0400160bool RadioInterface::tuneRx(double freq, size_t chan)
dburgessb3a0ca42011-10-12 07:44:40 +0000161{
Pau Espin Pedrola801ae52019-09-13 15:59:29 +0200162 return mDevice->setRxFreq(freq, chan);
dburgessb3a0ca42011-10-12 07:44:40 +0000163}
164
Pau Espin Pedrol0fc20d12018-04-24 17:48:52 +0200165/** synchronization thread loop */
166void *AlignRadioServiceLoopAdapter(RadioInterface *radioInterface)
167{
Pau Espin Pedrol5b60c982018-09-20 18:04:46 +0200168 set_selfthread_name("AlignRadio");
Pau Espin Pedrol553a2502020-07-29 18:05:25 +0200169 OSMO_ASSERT(osmo_cpu_sched_vty_apply_localthread() == 0);
Pau Espin Pedrol0fc20d12018-04-24 17:48:52 +0200170 while (1) {
171 sleep(60);
172 radioInterface->alignRadio();
173 pthread_testcancel();
174 }
175 return NULL;
176}
177
178void RadioInterface::alignRadio() {
Pau Espin Pedrola801ae52019-09-13 15:59:29 +0200179 mDevice->updateAlignment(writeTimestamp+ (TIMESTAMP) 10000);
Pau Espin Pedrol0fc20d12018-04-24 17:48:52 +0200180}
181
Tom Tsoueb54bdd2014-11-25 16:06:32 -0800182bool RadioInterface::start()
dburgessb3a0ca42011-10-12 07:44:40 +0000183{
Tom Tsoueb54bdd2014-11-25 16:06:32 -0800184 if (mOn)
185 return true;
186
187 LOG(INFO) << "Starting radio device";
Pau Espin Pedrola801ae52019-09-13 15:59:29 +0200188 if (mDevice->requiresRadioAlign())
Pau Espin Pedrol0fc20d12018-04-24 17:48:52 +0200189 mAlignRadioServiceLoopThread.start(
190 (void * (*)(void*))AlignRadioServiceLoopAdapter,
191 (void*)this);
Tom Tsoueb54bdd2014-11-25 16:06:32 -0800192
Pau Espin Pedrola801ae52019-09-13 15:59:29 +0200193 if (!mDevice->start())
Tom Tsoueb54bdd2014-11-25 16:06:32 -0800194 return false;
195
Tom Tsou28670fb2015-08-21 19:32:58 -0700196 for (size_t i = 0; i < mChans; i++) {
197 sendBuffer[i]->reset();
198 recvBuffer[i]->reset();
199 }
Tom Tsoud7610cf2015-05-07 17:39:49 -0700200
Pau Espin Pedrola801ae52019-09-13 15:59:29 +0200201 writeTimestamp = mDevice->initialWriteTimestamp();
202 readTimestamp = mDevice->initialReadTimestamp();
Thomas Tsou18d3b832014-02-13 14:55:23 -0500203
Pau Espin Pedrola801ae52019-09-13 15:59:29 +0200204 mDevice->updateAlignment(writeTimestamp-10000);
205 mDevice->updateAlignment(writeTimestamp-10000);
dburgessb3a0ca42011-10-12 07:44:40 +0000206
dburgessb3a0ca42011-10-12 07:44:40 +0000207 mOn = true;
Thomas Tsou18d3b832014-02-13 14:55:23 -0500208 LOG(INFO) << "Radio started";
Tom Tsoueb54bdd2014-11-25 16:06:32 -0800209 return true;
210}
211
212/*
213 * Stop the radio device
214 *
215 * This is a pass-through call to the device interface. Because the underlying
216 * stop command issuance generally doesn't return confirmation on device status,
217 * this call will only return false if the device is already stopped.
218 */
219bool RadioInterface::stop()
220{
Pau Espin Pedrola801ae52019-09-13 15:59:29 +0200221 if (!mOn || !mDevice->stop())
Tom Tsoueb54bdd2014-11-25 16:06:32 -0800222 return false;
223
224 mOn = false;
225 return true;
dburgessb3a0ca42011-10-12 07:44:40 +0000226}
227
Thomas Tsou204a9f12013-10-29 18:34:16 -0400228void RadioInterface::driveTransmitRadio(std::vector<signalVector *> &bursts,
229 std::vector<bool> &zeros)
Thomas Tsou03e6ecf2013-08-20 20:54:54 -0400230{
231 if (!mOn)
232 return;
dburgessb3a0ca42011-10-12 07:44:40 +0000233
Tom Tsou28670fb2015-08-21 19:32:58 -0700234 for (size_t i = 0; i < mChans; i++)
235 radioifyVector(*bursts[i], i, zeros[i]);
dburgessb3a0ca42011-10-12 07:44:40 +0000236
Tom Tsou28670fb2015-08-21 19:32:58 -0700237 while (pushBuffer());
dburgessb3a0ca42011-10-12 07:44:40 +0000238}
239
Pau Espin Pedrol8e498bf2018-09-03 16:45:15 +0200240int RadioInterface::driveReceiveRadio()
Thomas Tsou204a9f12013-10-29 18:34:16 -0400241{
242 radioVector *burst = NULL;
dburgessb3a0ca42011-10-12 07:44:40 +0000243
Thomas Tsou204a9f12013-10-29 18:34:16 -0400244 if (!mOn)
Pau Espin Pedrol8e498bf2018-09-03 16:45:15 +0200245 return 0;
dburgessb3a0ca42011-10-12 07:44:40 +0000246
Pau Espin Pedrol8e498bf2018-09-03 16:45:15 +0200247 if (pullBuffer() < 0)
248 return -1;
dburgessb3a0ca42011-10-12 07:44:40 +0000249
250 GSM::Time rcvClock = mClock.get();
251 rcvClock.decTN(receiveOffset);
252 unsigned tN = rcvClock.TN();
Tom Tsou28670fb2015-08-21 19:32:58 -0700253 int recvSz = recvBuffer[0]->getAvailSamples();
dburgessb3a0ca42011-10-12 07:44:40 +0000254 const int symbolsPerSlot = gSlotLen + 8;
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800255 int burstSize;
256
257 if (mSPSRx == 4)
258 burstSize = 625;
259 else
260 burstSize = symbolsPerSlot + (tN % 4 == 0);
dburgessb3a0ca42011-10-12 07:44:40 +0000261
Pau Espin Pedrol46444632018-09-03 16:42:04 +0200262 /*
Thomas Tsoud0f3ca32013-11-09 22:05:23 -0500263 * Pre-allocate head room for the largest correlation size
264 * so we can later avoid a re-allocation and copy
265 * */
Vadim Yanitskiya79bc702018-10-17 11:01:58 +0200266 size_t head = GSM::gRACHSynchSequenceTS0.size();
Thomas Tsoud0f3ca32013-11-09 22:05:23 -0500267
268 /*
269 * Form receive bursts and pass up to transceiver. Use repeating
270 * pattern of 157-156-156-156 symbols per timeslot
271 */
Thomas Tsoue0fa2bf2013-11-09 02:46:29 -0500272 while (recvSz > burstSize) {
Thomas Tsou204a9f12013-10-29 18:34:16 -0400273 for (size_t i = 0; i < mChans; i++) {
Tom Tsoud6ae8642017-03-30 17:22:58 -0700274 burst = new radioVector(rcvClock, burstSize, head);
275 unRadioifyVector(burst->getVector(), i);
Thomas Tsoue90a42b2013-11-13 23:38:09 -0500276
Thomas Tsoue0fa2bf2013-11-09 02:46:29 -0500277 if (mReceiveFIFO[i].size() < 32)
Thomas Tsou204a9f12013-10-29 18:34:16 -0400278 mReceiveFIFO[i].write(burst);
Thomas Tsoue0fa2bf2013-11-09 02:46:29 -0500279 else
Thomas Tsou204a9f12013-10-29 18:34:16 -0400280 delete burst;
dburgessb3a0ca42011-10-12 07:44:40 +0000281 }
Thomas Tsou204a9f12013-10-29 18:34:16 -0400282
283 mClock.incTN();
dburgessb3a0ca42011-10-12 07:44:40 +0000284 rcvClock.incTN();
Thomas Tsoue0fa2bf2013-11-09 02:46:29 -0500285 recvSz -= burstSize;
dburgessb3a0ca42011-10-12 07:44:40 +0000286
287 tN = rcvClock.TN();
Thomas Tsoue0fa2bf2013-11-09 02:46:29 -0500288
Tom Tsou5cd70dc2016-03-06 01:28:40 -0800289 if (mSPSRx != 4)
290 burstSize = (symbolsPerSlot + (tN % 4 == 0)) * mSPSRx;
dburgessb3a0ca42011-10-12 07:44:40 +0000291 }
292
Pau Espin Pedrol8e498bf2018-09-03 16:45:15 +0200293 return 1;
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000294}
295
296bool RadioInterface::isUnderrun()
297{
Pau Espin Pedrole503c982019-09-13 18:56:08 +0200298 bool retVal;
299 /* atomically get previous value of "underrun" and set the var to false */
300 retVal = osmo_trx_sync_fetch_and_and(&underrun, false);
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000301 return retVal;
302}
303
Thomas Tsou204a9f12013-10-29 18:34:16 -0400304VectorFIFO* RadioInterface::receiveFIFO(size_t chan)
305{
306 if (chan >= mReceiveFIFO.size())
307 return NULL;
308
309 return &mReceiveFIFO[chan];
310}
311
312double RadioInterface::setRxGain(double dB, size_t chan)
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000313{
Pau Espin Pedrola801ae52019-09-13 15:59:29 +0200314 return mDevice->setRxGain(dB, chan);
kurtis.heimerle724d6d2011-11-26 03:18:46 +0000315}
316
Pau Espin Pedrole91544d2020-10-13 17:03:37 +0200317double RadioInterface::rssiOffset(size_t chan)
318{
319 return mDevice->rssiOffset(chan);
320}
321
Thomas Tsouc1f7c422013-10-11 13:49:55 -0400322/* Receive a timestamped chunk from the device */
Pau Espin Pedrol8e498bf2018-09-03 16:45:15 +0200323int RadioInterface::pullBuffer()
Thomas Tsoucb69f082013-04-08 14:18:26 -0400324{
325 bool local_underrun;
Pau Espin Pedrol97009692018-09-03 17:01:59 +0200326 int numRecv;
327 size_t segmentLen = recvBuffer[0]->getSegmentLen();
Thomas Tsoucb69f082013-04-08 14:18:26 -0400328
Tom Tsou28670fb2015-08-21 19:32:58 -0700329 if (recvBuffer[0]->getFreeSegments() <= 0)
Pau Espin Pedrol8e498bf2018-09-03 16:45:15 +0200330 return -1;
Thomas Tsou3952d802013-10-15 15:12:24 -0400331
Thomas Tsouc1f7c422013-10-11 13:49:55 -0400332 /* Outer buffer access size is fixed */
Pau Espin Pedrola801ae52019-09-13 15:59:29 +0200333 numRecv = mDevice->readSamples(convertRecvBuffer,
Tom Tsou28670fb2015-08-21 19:32:58 -0700334 segmentLen,
335 &overrun,
336 readTimestamp,
337 &local_underrun);
338
Pau Espin Pedrol97009692018-09-03 17:01:59 +0200339 if ((size_t) numRecv != segmentLen) {
Tom Tsou28670fb2015-08-21 19:32:58 -0700340 LOG(ALERT) << "Receive error " << numRecv;
Pau Espin Pedrol8e498bf2018-09-03 16:45:15 +0200341 return -1;
Thomas Tsou9471d762013-08-20 21:24:24 -0400342 }
Thomas Tsoucb69f082013-04-08 14:18:26 -0400343
Thomas Tsou204a9f12013-10-29 18:34:16 -0400344 for (size_t i = 0; i < mChans; i++) {
Tom Tsou28670fb2015-08-21 19:32:58 -0700345 convert_short_float(recvBuffer[i]->getWriteSegment(),
346 convertRecvBuffer[i],
347 segmentLen * 2);
Thomas Tsou204a9f12013-10-29 18:34:16 -0400348 }
Thomas Tsoucb69f082013-04-08 14:18:26 -0400349
Pau Espin Pedrole503c982019-09-13 18:56:08 +0200350 osmo_trx_sync_or_and_fetch(&underrun, local_underrun);
Tom Tsou28670fb2015-08-21 19:32:58 -0700351 readTimestamp += numRecv;
Pau Espin Pedrol8e498bf2018-09-03 16:45:15 +0200352 return 0;
Thomas Tsoucb69f082013-04-08 14:18:26 -0400353}
354
Thomas Tsouc1f7c422013-10-11 13:49:55 -0400355/* Send timestamped chunk to the device with arbitrary size */
Tom Tsou28670fb2015-08-21 19:32:58 -0700356bool RadioInterface::pushBuffer()
Thomas Tsoucb69f082013-04-08 14:18:26 -0400357{
Pau Espin Pedrol2c673e02019-07-29 20:14:47 +0200358 bool local_underrun;
Tom Tsou28670fb2015-08-21 19:32:58 -0700359 size_t numSent, segmentLen = sendBuffer[0]->getSegmentLen();
Thomas Tsou9471d762013-08-20 21:24:24 -0400360
Tom Tsou28670fb2015-08-21 19:32:58 -0700361 if (sendBuffer[0]->getAvailSegments() < 1)
362 return false;
Thomas Tsou3952d802013-10-15 15:12:24 -0400363
Thomas Tsou204a9f12013-10-29 18:34:16 -0400364 for (size_t i = 0; i < mChans; i++) {
365 convert_float_short(convertSendBuffer[i],
Tom Tsoub577ef02016-07-12 16:07:48 -0700366 (float *) sendBuffer[i]->getReadSegment(),
Tom Tsou28670fb2015-08-21 19:32:58 -0700367 powerScaling[i],
368 segmentLen * 2);
Thomas Tsou204a9f12013-10-29 18:34:16 -0400369 }
Thomas Tsoucb69f082013-04-08 14:18:26 -0400370
Tom Tsou28670fb2015-08-21 19:32:58 -0700371 /* Send the all samples in the send buffer */
Pau Espin Pedrola801ae52019-09-13 15:59:29 +0200372 numSent = mDevice->writeSamples(convertSendBuffer,
Tom Tsou28670fb2015-08-21 19:32:58 -0700373 segmentLen,
Pau Espin Pedrol2c673e02019-07-29 20:14:47 +0200374 &local_underrun,
Tom Tsou28670fb2015-08-21 19:32:58 -0700375 writeTimestamp);
Pau Espin Pedrole503c982019-09-13 18:56:08 +0200376 osmo_trx_sync_or_and_fetch(&underrun, local_underrun);
Tom Tsou28670fb2015-08-21 19:32:58 -0700377 writeTimestamp += numSent;
378
379 return true;
Thomas Tsoucb69f082013-04-08 14:18:26 -0400380}