SDRPlay Independent Community Forum › Forums › SDR Software (RSP Compatible) › Failed to lock mutex from sdrplay_api_Init
Tagged: sdrplay_api_Init mutex
- This topic has 0 replies, 1 voice, and was last updated by .
-
AuthorPosts
-
May 24, 2023 at 8:14 pm #2226Robert-sdrplayParticipant
i’m running your sdrplay_api_sample_app.c from the 3.07 document on a RSPdx. i get this error:
sdrplay_api_Init(): line 583: Failed to lock mutexcan you explain why? this is a modified version of your sample app. i’m trying to just run a single app on linux.
#include “sdrplay_api.h”
#include <stdio.h>
#include <unistd.h>int masterInitialised = 0;
int slaveUninitialised = 0;
sdrplay_api_DeviceT *dev = NULL;void StreamACallback(
short *xi,
short *xq,
sdrplay_api_StreamCbParamsT *params,
unsigned int numSamples,
unsigned int reset,
void *cbContext
) {if (reset)
printf(“sdrplay_api_StreamACallback: numSamples=%d\n”, numSamples);
return;
}void StreamBCallback(
short *xi,
short *xq,
sdrplay_api_StreamCbParamsT *params,
unsigned int numSamples,
unsigned int reset,
void *cbContext) {if (reset)
printf(“sdrplay_api_StreamBCallback: numSamples=%d\n”, numSamples);
return;
}void EventCallback(
sdrplay_api_EventT eventId,
sdrplay_api_TunerSelectT tuner,
sdrplay_api_EventParamsT *params,
void *cbContext) {switch (eventId) {
case sdrplay_api_GainChange:
printf(“sdrplay_api_EventCb: %s, tuner=%s gRdB=%d lnaGRdB=%d systemGain=%.2f\n”,
“sdrplay_api_GainChange”, (tuner == sdrplay_api_Tuner_A) ? “sdrplay_api_Tuner_A” : “sdrplay_api_Tuner_B”, params->gainParams.gRdB, params->gainParams.lnaGRdB,
params->gainParams.currGain);
break;
case sdrplay_api_PowerOverloadChange:
printf(“sdrplay_api_PowerOverloadChange: tuner=%s powerOverloadChangeType=%s\n”,
(tuner == sdrplay_api_Tuner_A) ? “sdrplay_api_Tuner_A” : “sdrplay_api_Tuner_B”,
(params->powerOverloadParams.powerOverloadChangeType ==
sdrplay_api_Overload_Detected) ? “sdrplay_api_Overload_Detected” : “sdrplay_api_Overload_Corrected”);
sdrplay_api_Update(dev, tuner, sdrplay_api_Update_Ctrl_OverloadMsgAck, sdrplay_api_Update_Ext1_None);
break;
case sdrplay_api_RspDuoModeChange:
printf(“sdrplay_api_RspDuoModeChange, tuner = %s\n”, tuner==sdrplay_api_Tuner_A ? “sdrplay_api_Tuner_A” : “sdrplay_api_Tuner_B”);
printf(“modeChangeType\n”);
if (params->rspDuoModeParams.modeChangeType == sdrplay_api_MasterInitialised) {
printf(“sdrplay_api_MasterInitialised\n”);
}
else if (params->rspDuoModeParams.modeChangeType == sdrplay_api_SlaveAttached) {
printf(“sdrplay_api_SlaveAttached\n”);
}
else if (params->rspDuoModeParams.modeChangeType == sdrplay_api_SlaveDetached) {
printf(“sdrplay_api_SlaveDetached\n”);
}
else if (params->rspDuoModeParams.modeChangeType == sdrplay_api_SlaveInitialised) {
printf(“sdrplay_api_SlaveInitialised\n”);
}
else if (params->rspDuoModeParams.modeChangeType == sdrplay_api_SlaveUninitialised) {
printf(“sdrplay_api_SlaveUninitialised\n”);
}
else
printf(“unknown type\n”);if (params->rspDuoModeParams.modeChangeType == sdrplay_api_MasterInitialised)
masterInitialised = 1;
if (params->rspDuoModeParams.modeChangeType == sdrplay_api_SlaveUninitialised)
slaveUninitialised = 1;
break;case sdrplay_api_DeviceRemoved:
printf(“sdrplay_api_EventCb: %s\n”, “sdrplay_api_DeviceRemoved”);
break;
default:
printf(“sdrplay_api_EventCb: %d, unknown event\n”, eventId);
break;
}
} // void EventCallbackint main() {
int bp = 0;
int i;
int master_slave = 0; // 0 = single tuner, 1 = master/slave
int masterInitialised = 0;
int slaveUninitialised = 0;
sdrplay_api_ErrT err;
sdrplay_api_DeviceParamsT *deviceParams = NULL;
sdrplay_api_CallbackFnsT cbFns;
sdrplay_api_RxChannelParamsT *chParams;
sdrplay_api_DeviceT devs[1]; // support up to 6 connected devices
unsigned int ndevs;
float ver;err = sdrplay_api_Open();
if (err != sdrplay_api_Success) {
printf(“sdrplay_api_Open failed %s\n”, sdrplay_api_GetErrorString(err));
return 1;
}err = sdrplay_api_ApiVersion(&ver); // 3.07
if (ver != SDRPLAY_API_VERSION) {
printf(“API version don’t match\n”);
sdrplay_api_Close();
return 1;
}sdrplay_api_LockDeviceApi(); // Lock API while device selection is performed
if ((err = sdrplay_api_GetDevices(devs, &ndevs, sizeof(devs) / sizeof(sdrplay_api_DeviceT))) != sdrplay_api_Success) {
printf(“sdrplay_api_GetDevices failed %s\n”, sdrplay_api_GetErrorString(err));
sdrplay_api_UnlockDeviceApi();
sdrplay_api_Close();
return 1;
}dev = &devs[0];
printf(“Dev%d: SerNo=%s hwVer=%d tuner=0x%.2x\n”, i, dev->SerNo, dev->hwVer, dev->tuner);if ((err = sdrplay_api_SelectDevice(dev)) != sdrplay_api_Success) {
printf(“sdrplay_api_SelectDevice failed %s\n”, sdrplay_api_GetErrorString(err));
sdrplay_api_UnlockDeviceApi();
sdrplay_api_Close();
return 1;
}sdrplay_api_UnlockDeviceApi();
if ((err = sdrplay_api_GetDeviceParams(dev->dev, &deviceParams)) != sdrplay_api_Success) {
printf(“sdrplay_api_GetDeviceParams failed %s\n”, sdrplay_api_GetErrorString(err));
sdrplay_api_Close();
return 1;
}if (deviceParams == NULL) {
printf(“sdrplay_api_GetDeviceParams returned NULL deviceParams\n”);
sdrplay_api_Close();
return 1;
}if (deviceParams->devParams != NULL) {
if (master_slave == 0) { // Single tuner mode
deviceParams->devParams->fsFreq.fsHz = 8000000.0; // Change from default Fs to 8MHz
}
else {
// Can’t change Fs in master/slave mode
}
}chParams = (dev->tuner == sdrplay_api_Tuner_B) ? deviceParams->rxChannelB : deviceParams->rxChannelA;
if (chParams != NULL) {
chParams->tunerParams.rfFreq.rfHz = 220000000.0;
chParams->tunerParams.bwType = sdrplay_api_BW_1_536;
if (master_slave == 0) { // Change single tuner mode to ZIF
chParams->tunerParams.ifType = sdrplay_api_IF_Zero;
}
chParams->tunerParams.gain.gRdB = 40;
chParams->tunerParams.gain.LNAstate = 5;
// Disable AGC
chParams->ctrlParams.agc.enable = sdrplay_api_AGC_DISABLE;
}
else {
printf(“sdrplay_api_GetDeviceParams returned NULL chParams pointer\n”);
sdrplay_api_Close();
return 1;
}deviceParams->rxChannelA->tunerParams.rfFreq.rfHz = 100000000.0; // Set frequency to 100 MHz
deviceParams->rxChannelA->tunerParams.bwType = sdrplay_api_BW_1_536; // Set bandwidth
deviceParams->rxChannelA->tunerParams.ifType = sdrplay_api_IF_Zero; // Set IF frequency to zero
deviceParams->rxChannelA->tunerParams.gain.gRdB = 50; // Set gain reduction
deviceParams->rxChannelA->tunerParams.gain.LNAstate = 4; // Set LNA state Setup callback functions cbFns.EventCbFn =cbFns.StreamACbFn = StreamACallback;
cbFns.StreamBCbFn = StreamBCallback;
cbFns.EventCbFn = EventCallback;if ((err = sdrplay_api_Init(dev, &cbFns, NULL)) != sdrplay_api_Success) {
printf(“sdrplay_api_Init failed %s\n”, sdrplay_api_GetErrorString(err));
if (err == sdrplay_api_StartPending) { // This can happen if we’re starting in master / slave mode as a slave and the master is not yet running
while (1) {
usleep(1000*1000);
if (masterInitialised) { // Keep polling flag set in event callback until the master is initialised
// Redo call – should succeed this time
if ((err = sdrplay_api_Init(dev, &cbFns, NULL)) != sdrplay_api_Success) {
printf(“sdrplay_api_Init failed %s\n”, sdrplay_api_GetErrorString(err));
}
sdrplay_api_ReleaseDevice(dev);
sdrplay_api_Close();
return 1;
}
printf(“Waiting for master to initialise\n”);
}
}
else {
sdrplay_api_ErrorInfoT *errInfo = sdrplay_api_GetLastError(NULL);
if (errInfo != NULL) {
// line 583: Failed to lock mutex
printf(“Error in %s: %s(): line %d: %s\n”, errInfo->file, errInfo-> function, errInfo->line, errInfo->message);
}
sdrplay_api_ReleaseDevice(dev);
sdrplay_api_Close();
return 1;
}
}sdrplay_api_ReleaseDevice(dev);
sdrplay_api_Close();
return 0;
} -
AuthorPosts
- You must be logged in to reply to this topic.