added memory barriers

added bit to bit delay in bitbanging spi
bug_fixes_integration_tx
David Michaeli 2023-06-13 08:36:20 +01:00
rodzic 7398158576
commit d8d8531137
3 zmienionych plików z 51 dodań i 42 usunięć

Wyświetl plik

@ -66,58 +66,55 @@ void CalculateMagnitudeVector(complex_sample_16_t *data, uint16_t *mag, uint32_t
}
//=================================================================================
void runSoapyProcess( SoapySDR::Device *device,
SoapySDR::Stream *stream,
const size_t elemSize)
void runSoapyProcess( SoapySDR::Device *device, SoapySDR::Stream *stream, const size_t elemSize)
{
// allocate buffers for the stream read/write
const size_t numElems = device->getStreamMTU(stream);
complex_sample_16_t* samples = (complex_sample_16_t*)malloc(sizeof(complex_sample_16_t)*numElems);
uint16_t* mag = (uint16_t*)malloc(sizeof(uint16_t)*numElems);
uint16_t* mag = (uint16_t*)malloc(sizeof(uint16_t)*numElems);
// MODE-S
mode_s_t state;
mode_s_init(&state);
// MODE-S
mode_s_t state;
mode_s_init(&state);
std::cout << "Starting stream loop, press Ctrl+C to exit..." << std::endl;
device->activateStream(stream);
signal(SIGINT, sigIntHandler);
// Main Processing Loop
// Main Processing Loop
while (not loopDone)
{
long long timeUS = numElems;
int flags = 0;
int flags = 0;
int numSamplesRead = device->readStream(stream, (void* const*)&samples, numElems, flags, timeUS);
if (numSamplesRead < 0)
if (numSamplesRead < 0)
{
//std::cerr << "Unexpected stream error " << numSamplesRead << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(5));
continue;
}
switch (numSamplesRead)
{
case SOAPY_SDR_TIMEOUT:
case SOAPY_SDR_OVERFLOW:
case SOAPY_SDR_UNDERFLOW:
continue;
default:
break;
}
switch (numSamplesRead)
{
case SOAPY_SDR_TIMEOUT:
case SOAPY_SDR_OVERFLOW:
case SOAPY_SDR_UNDERFLOW:
continue;
default:
break;
}
// Proceed to DSP - compute the magnitude of the signal
CalculateMagnitudeVector(samples, mag, numSamplesRead);
// detect Mode S messages in the signal and call on_msg with each message
mode_s_detect(&state, mag, numSamplesRead, onModeSMessage);
// Proceed to DSP - compute the magnitude of the signal
CalculateMagnitudeVector(samples, mag, numSamplesRead);
// detect Mode S messages in the signal and call on_msg with each message
mode_s_detect(&state, mag, numSamplesRead, onModeSMessage);
}
device->deactivateStream(stream);
// free memory
free(samples);
free(mag);
// free memory
free(samples);
free(mag);
}
@ -126,7 +123,7 @@ void runSoapyProcess( SoapySDR::Device *device,
**********************************************************************/
int main(int argc, char *argv[])
{
SoapySDR::ModuleManager mm(false);
SoapySDR::ModuleManager mm(false);
SoapySDR::Device *device(nullptr);
std::vector<size_t> channels;
std::string argStr = "driver=Cariboulite,channel=HiF";
@ -137,21 +134,26 @@ int main(int argc, char *argv[])
try
{
device = SoapySDR::Device::make(argStr);
if (device == NULL)
{
std::cerr << "Initialization Error" << std::endl;
return EXIT_FAILURE;
}
// set the sample rate, frequency, ...
device->setSampleRate(SOAPY_SDR_RX, 0, 2e6); // needs to be sampled at 2MSPS
device->setBandwidth(SOAPY_SDR_RX, 0, 200e5);
device->setGainMode(SOAPY_SDR_RX, 0, false);
device->setGain(SOAPY_SDR_RX, 0, 50);
device->setFrequency(SOAPY_SDR_RX, 0, 1090e6);
device->setBandwidth(SOAPY_SDR_RX, 0, 200e5);
device->setGainMode(SOAPY_SDR_RX, 0, false);
device->setGain(SOAPY_SDR_RX, 0, 50);
device->setFrequency(SOAPY_SDR_RX, 0, 1090e6);
// create the stream, use the native format
// create the stream, use the native format
const auto format = device->getNativeStreamFormat(SOAPY_SDR_RX, 0, fullScale);
const size_t elemSize = SoapySDR::formatToSize(format);
auto stream = device->setupStream(SOAPY_SDR_RX, format, channels);
// run the rate test one setup is complete
std::cout << std::endl << "Running Soapy process with CaribouLite Config:" << std::endl;
std::cout << std::endl << "Running Soapy process with CaribouLite Config:" << std::endl;
std::cout << " Stream format: " << format << std::endl;
std::cout << " Channel: HiF" << std::endl;
std::cout << " Sample size: " << elemSize << " bytes" << std::endl;

Wyświetl plik

@ -60,7 +60,7 @@ static int io_utils_spi_setup_chip(io_utils_spi_st* dev, int handle)
io_utils_set_gpio_mode(miso_pin, io_utils_alt_gpio_in);
io_utils_set_gpio_mode(mosi_pin, io_utils_alt_gpio_out);
io_utils_set_gpio_mode(sck_pin, io_utils_alt_gpio_out);
dev->current_chip = chip;
dev->current_chip = chip;
return 0;
}
@ -86,6 +86,7 @@ static int io_utils_spi_setup_chip(io_utils_spi_st* dev, int handle)
io_utils_set_gpio_mode(dev->miso, io_utils_alt_4);
io_utils_set_gpio_mode(dev->mosi, io_utils_alt_4);
io_utils_set_gpio_mode(dev->sck, io_utils_alt_4);
io_utils_usleep(100);
}
return setup_spi_dev;
@ -95,7 +96,7 @@ static int io_utils_spi_setup_chip(io_utils_spi_st* dev, int handle)
static int io_utils_spi_write_rffc507x(io_utils_spi_st* dev, io_utils_spi_chip_st* chip, uint8_t reg, uint16_t val)
{
int bits = 25;
int nop_cnt = 50;
int nop_cnt = 200;
int msb = 1 << (bits - 1);
uint32_t data = reg;
data = ((data & 0x7f) << 16) | val;
@ -149,7 +150,7 @@ static int io_utils_spi_write_rffc507x(io_utils_spi_st* dev, io_utils_spi_chip_s
static int io_utils_spi_read_rffc507x(io_utils_spi_st* dev, io_utils_spi_chip_st* chip, uint8_t reg)
{
int bits = 9;
int nop_cnt = 50;
int nop_cnt = 200;
int msb = 1 << (bits -1);
uint32_t data = 0x80 | (reg & 0x7f);
@ -224,7 +225,7 @@ static int io_utils_spi_read_rffc507x(io_utils_spi_st* dev, io_utils_spi_chip_st
static int io_utils_ice40_transfer_spi(io_utils_spi_st* dev, io_utils_spi_chip_st* chip,
const uint8_t *tx, unsigned int len)
{
int nop_cnt = 300;
int nop_cnt = 400;
int data_pin = chip->miso_mosi_swap?dev->miso:dev->mosi;
int sck_pin = dev->sck;
@ -254,7 +255,7 @@ static int io_utils_ice40_transfer_spi(io_utils_spi_st* dev, io_utils_spi_chip_s
static int io_utils_modem_bitbang_transfer_spi(io_utils_spi_st* dev, io_utils_spi_chip_st* chip,
const uint8_t *tx, uint8_t *rx, unsigned int len)
{
int nop_cnt = 120;
int nop_cnt = 200;
int cs_pin = chip->cs_pin;
int mosi_pin = chip->miso_mosi_swap?dev->miso:dev->mosi;
int miso_pin = chip->miso_mosi_swap?dev->mosi:dev->miso;
@ -651,4 +652,4 @@ void io_utils_spi_print_setup(io_utils_spi_st* dev)
}
}
pthread_mutex_unlock(&dev->mtx);
}
}

Wyświetl plik

@ -448,19 +448,23 @@ uint32_t clearBit(volatile uint32_t* reg, uint8_t position)
uint8_t isBitSet(volatile uint32_t* reg, uint8_t position)
{
uint32_t mask = 1 << position;
__sync_synchronize();
return *reg & mask ? 1 : 0;
}
/* Read content of a peripheral register */
uint32_t pr_read(volatile uint32_t* reg)
{
__sync_synchronize();
return *reg;
}
/* Write a value to a peripheral register */
uint32_t pr_write(volatile uint32_t* reg, uint32_t value)
{
__sync_synchronize();
*reg = value;
__sync_synchronize();
return *reg;
}
@ -488,7 +492,7 @@ void set_gpio(uint8_t pin, uint8_t fsel){
/* get base address (GPFSEL0 to GPFSEL5) using *(GPFSEL0 + (pin/10))
* get mask using (alt << ((pin)%10)*3)
*/
__sync_synchronize();
volatile uint32_t *gpsel = (uint32_t *)(GPIO_GPFSEL0 + (pin/10)); // get the GPFSEL0 pointer (GPFSEL0 ~ GPFSEL5) based on the pin number selected
uint32_t mask = ~ (7 << (pin % 10)*3); // mask to reset fsel to 0 first
*gpsel &= mask; // reset gpsel value to 0
@ -506,6 +510,7 @@ uint8_t get_gpio(uint8_t pin)
uint32_t cur_val = *gpsel;
cur_val >>= (pin % 10)*3;
__sync_synchronize();
return cur_val & 0x7;
}
@ -626,6 +631,7 @@ void gpio_pulse(uint8_t pin, int td){
* 1 (ON state)
*/
uint8_t gpio_read(uint8_t pin) {
__sync_synchronize();
return isBitSet(GPIO_GPLEV0, pin);
}