kopia lustrzana https://github.com/cariboulabs/cariboulite
rodzic
b16d470fe4
commit
4d993d25ef
|
@ -503,6 +503,18 @@ static long smi_stream_ioctl(struct file *file, unsigned int cmd, unsigned long
|
|||
}
|
||||
break;
|
||||
}
|
||||
//-------------------------------
|
||||
case SMI_STREAM_IOC_FLUSH_FIFO:
|
||||
{
|
||||
if (mutex_lock_interruptible(&inst->read_lock))
|
||||
{
|
||||
return -EINTR;
|
||||
}
|
||||
kfifo_reset_out(&inst->rx_fifo);
|
||||
mutex_unlock(&inst->read_lock);
|
||||
|
||||
break;
|
||||
}
|
||||
//-------------------------------
|
||||
default:
|
||||
dev_err(inst->dev, "invalid ioctl cmd: %d", cmd);
|
||||
|
@ -816,15 +828,15 @@ int reader_thread_stream_function(void *pv)
|
|||
//--------------------------------------------------------
|
||||
// Don't wait for the buffer to fill in, copy the "other"
|
||||
// previously filled up buffer into the kfifo
|
||||
//if (mutex_lock_interruptible(&inst->read_lock))
|
||||
//{
|
||||
// return -EINTR;
|
||||
//}
|
||||
if (mutex_lock_interruptible(&inst->read_lock))
|
||||
{
|
||||
return -EINTR;
|
||||
}
|
||||
|
||||
start = ktime_get();
|
||||
|
||||
kfifo_in(&inst->rx_fifo, bounce->buffer[1-current_dma_buffer], DMA_BOUNCE_BUFFER_SIZE);
|
||||
//mutex_unlock(&inst->read_lock);
|
||||
mutex_unlock(&inst->read_lock);
|
||||
|
||||
// for the polling mechanism
|
||||
inst->readable = true;
|
||||
|
@ -1083,20 +1095,12 @@ static ssize_t smi_stream_read_file_fifo(struct file *file, char __user *buf, si
|
|||
size_t num_bytes = 0;
|
||||
unsigned int count_actual = count;
|
||||
|
||||
//if (kfifo_is_empty(&inst->rx_fifo))
|
||||
//{
|
||||
// return -EAGAIN;
|
||||
//}
|
||||
|
||||
/*if (mutex_lock_interruptible(&inst->read_lock))
|
||||
if (mutex_lock_interruptible(&inst->read_lock))
|
||||
{
|
||||
return -EINTR;
|
||||
}*/
|
||||
//num_bytes = kfifo_len (&inst->rx_fifo);
|
||||
//count_actual = num_bytes > count ? count : num_bytes;
|
||||
//ret = kfifo_to_user(&inst->rx_fifo, buf, count_actual, &copied);
|
||||
}
|
||||
ret = kfifo_to_user(&inst->rx_fifo, buf, count, &copied);
|
||||
//mutex_unlock(&inst->read_lock);
|
||||
mutex_unlock(&inst->read_lock);
|
||||
|
||||
return ret < 0 ? ret : (ssize_t)copied;
|
||||
}
|
||||
|
|
|
@ -105,5 +105,7 @@ struct bcm2835_smi_instance {
|
|||
#define SMI_STREAM_IOC_GET_FIFO_MULT _IO(BCM2835_SMI_IOC_MAGIC,(BCM2835_SMI_IOC_MAX+7))
|
||||
#define SMI_STREAM_IOC_GET_ADDR_DIR_OFFSET _IO(BCM2835_SMI_IOC_MAGIC,(BCM2835_SMI_IOC_MAX+8))
|
||||
#define SMI_STREAM_IOC_GET_ADDR_CH_OFFSET _IO(BCM2835_SMI_IOC_MAGIC,(BCM2835_SMI_IOC_MAX+9))
|
||||
#define SMI_STREAM_IOC_FLUSH_FIFO _IO(BCM2835_SMI_IOC_MAGIC,(BCM2835_SMI_IOC_MAX+10))
|
||||
|
||||
|
||||
#endif /* _SMI_STREAM_DEV_H_ */
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <CaribouLite.hpp>
|
||||
#include <thread>
|
||||
#include <complex>
|
||||
#include <cmath>
|
||||
|
||||
// Print Board Information
|
||||
void printInfo(CaribouLite& cl)
|
||||
|
@ -31,10 +32,38 @@ void detectBoard()
|
|||
}
|
||||
}
|
||||
|
||||
// Calculate the RSSI
|
||||
float RSSI(const std::complex<float>* signal, size_t num_of_samples)
|
||||
{
|
||||
if (num_of_samples == 0)
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
float sum_of_squares = 0.0f;
|
||||
for (size_t i = 0; i < num_of_samples && i < num_of_samples; ++i)
|
||||
{
|
||||
float vrms = std::norm(signal[i]);
|
||||
sum_of_squares += vrms * vrms / 100.0;
|
||||
}
|
||||
|
||||
float mean_of_squares = sum_of_squares / num_of_samples;
|
||||
|
||||
// Convert RMS value to dBm
|
||||
return 10 * log10(mean_of_squares);
|
||||
}
|
||||
|
||||
// Rx Callback (async)
|
||||
void receivedSamples(CaribouLiteRadio* radio, const std::complex<float>* samples, CaribouLiteMeta* sync, size_t num_samples)
|
||||
{
|
||||
std::cout << "Radio: " << radio->GetRadioName() << " Received " << std::dec << num_samples << " samples" << std::endl;
|
||||
/*for (int i = 0; i < 6; i ++)
|
||||
{
|
||||
std::cout << "[" << samples[i].real() << ", " << samples[i].imag() << "]";
|
||||
}
|
||||
std::cout << std::endl;*/
|
||||
|
||||
std::cout << "Radio: " << radio->GetRadioName() << " Received " << std::dec << num_samples << " samples"
|
||||
<< "RSSI: " << RSSI(samples, num_samples) << " dBm" << std::endl;
|
||||
|
||||
}
|
||||
|
||||
|
@ -74,34 +103,35 @@ int main ()
|
|||
}
|
||||
|
||||
// start receiving until enter pressed on 900MHz
|
||||
int num = 1;
|
||||
int num = 2;
|
||||
while (num --)
|
||||
{
|
||||
try
|
||||
{
|
||||
s1g->SetFrequency(900000000);
|
||||
s1g->FlushBuffers();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cout << "The specified freq couldn't be used" << std::endl;
|
||||
}
|
||||
|
||||
s1g->SetRxGain(50);
|
||||
s1g->SetRxGain(0);
|
||||
s1g->SetAgc(false);
|
||||
s1g->StartReceiving(receivedSamples);
|
||||
|
||||
getchar();
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
hif->SetFrequency(2400000000);
|
||||
hif->FlushBuffers();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cout << "The specified freq couldn't be used" << std::endl;
|
||||
}
|
||||
hif->SetRxGain(50);
|
||||
hif->SetRxGain(0);
|
||||
hif->SetAgc(false);
|
||||
hif->StartReceiving(receivedSamples, 20000);
|
||||
|
||||
|
|
|
@ -173,11 +173,12 @@ public:
|
|||
void StartTransmittingCw(void);
|
||||
void StopTransmitting(void);
|
||||
bool GetIsTransmittingLo(void);
|
||||
bool GetIsTransmittingCw(void);
|
||||
bool GetIsTransmittingCw(void);
|
||||
|
||||
// General
|
||||
size_t GetNativeMtuSample(void);
|
||||
std::string GetRadioName(void);
|
||||
void FlushBuffers(void);
|
||||
|
||||
private:
|
||||
const cariboulite_radio_state_st* _radio;
|
||||
|
|
|
@ -24,11 +24,12 @@ void CaribouLiteRadio::CaribouLiteRxThread(CaribouLiteRadio* radio)
|
|||
{
|
||||
if (ret == -1)
|
||||
{
|
||||
printf("reader thread failed to read SMI!\n");
|
||||
//printf("reader thread failed to read SMI!\n");
|
||||
}
|
||||
ret = 0;
|
||||
continue;
|
||||
}
|
||||
if (ret == 0) continue;
|
||||
|
||||
// convert the buffer
|
||||
if (radio->_rxCallbackType == CaribouLiteRadio::RxCbType::FloatSync || radio->_rxCallbackType == CaribouLiteRadio::RxCbType::Float)
|
||||
|
@ -533,3 +534,9 @@ std::string CaribouLiteRadio::GetRadioName()
|
|||
return std::string(name);
|
||||
}
|
||||
|
||||
//==================================================================
|
||||
void CaribouLiteRadio::FlushBuffers()
|
||||
{
|
||||
int res = cariboulite_flush_pipeline();
|
||||
|
||||
}
|
|
@ -757,3 +757,17 @@ size_t caribou_smi_get_native_batch_samples(caribou_smi_st* dev)
|
|||
//printf("DEBUG: native batch len: %lu\n", dev->native_batch_len / CARIBOU_SMI_BYTES_PER_SAMPLE);
|
||||
return (dev->native_batch_len / CARIBOU_SMI_BYTES_PER_SAMPLE);
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
int caribou_smi_flush_fifo(caribou_smi_st* dev)
|
||||
{
|
||||
if (!dev) return -1;
|
||||
if (!dev->initialized) return -1;
|
||||
int ret = ioctl(dev->filedesc, SMI_STREAM_IOC_FLUSH_FIFO, 1);
|
||||
if (ret != 0)
|
||||
{
|
||||
ZF_LOGE("failed flushing driver fifos");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -103,6 +103,7 @@ size_t caribou_smi_get_native_batch_samples(caribou_smi_st* dev);
|
|||
|
||||
void caribou_smi_setup_ios(caribou_smi_st* dev);
|
||||
void caribou_smi_set_sample_rate(caribou_smi_st* dev, uint32_t sample_rate);
|
||||
int caribou_smi_flush_fifo(caribou_smi_st* dev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -105,5 +105,7 @@ struct bcm2835_smi_instance {
|
|||
#define SMI_STREAM_IOC_GET_FIFO_MULT _IO(BCM2835_SMI_IOC_MAGIC,(BCM2835_SMI_IOC_MAX+7))
|
||||
#define SMI_STREAM_IOC_GET_ADDR_DIR_OFFSET _IO(BCM2835_SMI_IOC_MAGIC,(BCM2835_SMI_IOC_MAX+8))
|
||||
#define SMI_STREAM_IOC_GET_ADDR_CH_OFFSET _IO(BCM2835_SMI_IOC_MAGIC,(BCM2835_SMI_IOC_MAX+9))
|
||||
#define SMI_STREAM_IOC_FLUSH_FIFO _IO(BCM2835_SMI_IOC_MAGIC,(BCM2835_SMI_IOC_MAX+10))
|
||||
|
||||
|
||||
#endif /* _SMI_STREAM_DEV_H_ */
|
||||
|
|
Plik diff jest za duży
Load Diff
|
@ -242,4 +242,11 @@ int cariboulite_get_frequency_limits(cariboulite_channel_en ch, float *freq_low,
|
|||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
int cariboulite_flush_pipeline()
|
||||
{
|
||||
// request the smi driver to flush its drivers fifo
|
||||
return caribou_smi_flush_fifo(&sys.smi);
|
||||
}
|
|
@ -210,6 +210,14 @@ int cariboulite_get_frequency_limits(cariboulite_channel_en ch, float *freq_low,
|
|||
*/
|
||||
int cariboulite_get_channel_name(cariboulite_channel_en ch, char* name, size_t max_len);
|
||||
|
||||
/**
|
||||
* @brief Flush driver FIFO
|
||||
*
|
||||
* Removing all items in the pipeline (drivers kfifo)
|
||||
*
|
||||
* @return 0 (success) or -1 (failed - when channel is incorrect)
|
||||
*/
|
||||
int cariboulite_flush_pipeline(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -380,7 +380,7 @@ int cariboulite_radio_set_tx_power(cariboulite_radio_state_st* radio, int tx_pow
|
|||
if (radio->type == cariboulite_channel_s1g)
|
||||
{
|
||||
if (tx_power_dbm < -14) tx_power_dbm = -14;
|
||||
if (tx_power_dbm > 12) tx_power_dbm = 12;
|
||||
if (tx_power_dbm > 14) tx_power_dbm = 14;
|
||||
|
||||
x = tx_power_dbm;
|
||||
tx_power_ctrl_model = roundf(0.001502f*x*x*x + 0.020549f*x*x + 0.991045f*x + 13.727758f);
|
||||
|
@ -391,7 +391,7 @@ int cariboulite_radio_set_tx_power(cariboulite_radio_state_st* radio, int tx_pow
|
|||
else if (radio->type == cariboulite_channel_hif)
|
||||
{
|
||||
if (tx_power_dbm < -12) tx_power_dbm = -12;
|
||||
if (tx_power_dbm > 12) tx_power_dbm = 12;
|
||||
if (tx_power_dbm > 14) tx_power_dbm = 14;
|
||||
|
||||
x = tx_power_dbm;
|
||||
tx_power_ctrl_model = roundf(0.000710f*x*x*x*x + 0.010521f*x*x*x + 0.015169f*x*x + 0.914333f*x + 12.254084f);
|
||||
|
@ -399,6 +399,10 @@ int cariboulite_radio_set_tx_power(cariboulite_radio_state_st* radio, int tx_pow
|
|||
if (tx_power_ctrl < 0) tx_power_ctrl = 0;
|
||||
if (tx_power_ctrl > 31) tx_power_ctrl = 31;
|
||||
}
|
||||
|
||||
/*tx_power_ctrl = tx_power_dbm + 17;
|
||||
if (tx_power_ctrl < 0) tx_power_ctrl = 0;
|
||||
if (tx_power_ctrl > 31) tx_power_ctrl = 31;*/
|
||||
|
||||
at86rf215_radio_tx_ctrl_st cfg =
|
||||
{
|
||||
|
@ -435,7 +439,11 @@ int cariboulite_radio_get_tx_power(cariboulite_radio_state_st* radio, int *tx_po
|
|||
{
|
||||
actual_model = 0.000031f*x*x*x*x - 0.002344f*x*x*x + 0.040478f*x*x + 0.712209f*x - 11.168502;
|
||||
}
|
||||
|
||||
|
||||
/*actual_model = x - 17;
|
||||
if (actual_model < -17) actual_model = -17;
|
||||
if (actual_model > 14) actual_model = 14;*/
|
||||
|
||||
radio->tx_power = (int)(actual_model);
|
||||
radio->tx_bw = (cariboulite_radio_tx_cut_off_en)cfg.analog_bw;
|
||||
radio->tx_fcut = (cariboulite_radio_f_cut_en)cfg.digital_bw;
|
||||
|
|
|
@ -98,7 +98,7 @@ static void init_program_state(void)
|
|||
state.write_metadata = 0;
|
||||
|
||||
// state
|
||||
state.sample_infinite = 0;
|
||||
state.sample_infinite = 1;
|
||||
state.program_running = 1;
|
||||
state.sys_type = system_type_cariboulite_ism;
|
||||
state.native_read_len = 1024 * 1024 / 8;
|
||||
|
@ -192,7 +192,14 @@ int analyze_arguments(int argc, char *argv[])
|
|||
break;
|
||||
case 'g':
|
||||
state.gain = (int)(atof(optarg));
|
||||
printf("DBG: Rx Gain = %.1f dB\n", state.gain);
|
||||
if (state.gain == -1)
|
||||
{
|
||||
printf("DBG: Rx Gain = AGC\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("DBG: Rx Gain = %.1f dB\n", state.gain);
|
||||
}
|
||||
break;
|
||||
case 'p':
|
||||
state.ppm_error = atof(optarg);
|
||||
|
|
Ładowanie…
Reference in New Issue