kopia lustrzana https://github.com/pa3gsb/Radioberry-2.x
commit
9a57ad6083
|
@ -29,7 +29,7 @@ if (NOT SoapySDR_FOUND)
|
|||
message(WARNING "SoapySDR development files not found - skipping support")
|
||||
return()
|
||||
endif ()
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
|
||||
#include_directories(${MY_DEVICE_INCLUDE_DIRS})
|
||||
SOAPY_SDR_MODULE_UTIL(
|
||||
TARGET SoapyRadioberrySDR
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
#define TX_MAX 4800
|
||||
#define TX_MAX_BUFFER (TX_MAX * 8)
|
||||
const int npackages = 4;
|
||||
|
||||
typedef enum radioberrysdrStreamFormat {
|
||||
RADIOBERRY_SDR_CF32,
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <cmath>
|
||||
#include "SoapyRadioberry.hpp"
|
||||
|
||||
void SoapyRadioberry::setSampleRate( const int direction, const size_t channel, const double rate ) {
|
||||
|
@ -113,6 +114,7 @@ SoapySDR::Stream *SoapyRadioberry::setupStream(
|
|||
if (format == SOAPY_SDR_CF32) {
|
||||
SoapySDR_log(SOAPY_SDR_INFO, "Using format CF32.");
|
||||
ptr->set_stream_format(RADIOBERRY_SDR_CF32);
|
||||
mox = true;
|
||||
}
|
||||
else if(format == SOAPY_SDR_CS16 && direction == SOAPY_SDR_TX)
|
||||
{
|
||||
|
@ -158,7 +160,8 @@ int SoapyRadioberry::readStream(
|
|||
const long timeoutUs )
|
||||
{
|
||||
int nr_samples, no_bytes, iq=0;
|
||||
|
||||
int npackages = numElems / 63;
|
||||
|
||||
void *buff_base = buffs[0];
|
||||
float *target_buffer = (float *) buff_base;
|
||||
int16_t *itarget_buffer = (int16_t *) buff_base;
|
||||
|
@ -202,16 +205,11 @@ int SoapyRadioberry::readStream(
|
|||
itarget_buffer[iq++] = (int16_t)(right_sample >> 8); // 16 bit sample
|
||||
}
|
||||
}
|
||||
//printf("nr_samples %d sample: %d %d \n", nr_samples, left_sample, right_sample);
|
||||
//printf("nr_samples %d sample: %f %f \n", nr_samples, (float)left_sample / 8388608.0, (float)right_sample / 8388608.0);
|
||||
}
|
||||
return (npackages * nr_samples); //return the number of IQ samples
|
||||
}
|
||||
|
||||
union uTxBuffer
|
||||
{
|
||||
std::uint16_t i16TxBuffer[2];
|
||||
unsigned char i8TxBuffer[4];
|
||||
};
|
||||
|
||||
int SoapyRadioberry::writeStream(SoapySDR::Stream *stream, const void * const *buffs, const size_t numElems, int &flags, const long long timeNs, const long timeoutUs)
|
||||
{
|
||||
|
@ -222,16 +220,26 @@ int SoapyRadioberry::writeStream(SoapySDR::Stream *stream, const void * const *b
|
|||
void const *buff_base = buffs[0];
|
||||
float *target_buffer = (float *) buff_base;
|
||||
int16_t *itarget_buffer = (int16_t *) buff_base;
|
||||
uTxBuffer tx;
|
||||
sdr_stream *ptr = (sdr_stream *)stream;
|
||||
unsigned char i8TxBuffer[6];
|
||||
|
||||
if (ptr->get_stream_format() == RADIOBERRY_SDR_CF32)
|
||||
{
|
||||
for (int ii = 0; ii < numElems; ii++)
|
||||
{
|
||||
tx.i16TxBuffer[0] = (int16_t)(target_buffer[iq++] * 16384.0f);
|
||||
tx.i16TxBuffer[1] = (int16_t)(target_buffer[iq++] * 16384.0f);
|
||||
ret = write(fd_rb, &tx, 4 * sizeof(uint8_t));
|
||||
const float gain = 8388608.0f;
|
||||
int isample = target_buffer[iq] >= 0.0 ? (long)floor(target_buffer[iq] * gain + 0.5) : (long)ceil(target_buffer[iq] * gain - 0.5);
|
||||
int qsample = target_buffer[iq + 1] >= 0.0 ? (long)floor(target_buffer[iq + 1] * gain + 0.5) : (long)ceil(target_buffer[iq + 1] * gain - 0.5);
|
||||
|
||||
//printf("nr_samples %d sample: %d %d \n", iq, isample,qsample );
|
||||
|
||||
i8TxBuffer[0] = isample >> 16;
|
||||
i8TxBuffer[1] = isample >> 8;
|
||||
i8TxBuffer[2] = qsample >> 16;
|
||||
i8TxBuffer[3] = qsample >> 8;
|
||||
ret = write(fd_rb, i8TxBuffer, 4);
|
||||
iq++;
|
||||
iq++;
|
||||
}
|
||||
}
|
||||
if (ptr->get_stream_format() == RADIOBERRY_SDR_CS16)
|
||||
|
@ -240,12 +248,11 @@ int SoapyRadioberry::writeStream(SoapySDR::Stream *stream, const void * const *b
|
|||
|
||||
for (int ii = 0; ii < numElems; ii++)
|
||||
{
|
||||
tx.i8TxBuffer[0] = (unsigned char)((itarget_buffer[j] & 0xff00) >> 8);
|
||||
tx.i8TxBuffer[1] = (unsigned char)(itarget_buffer[j] & 0xff);
|
||||
tx.i8TxBuffer[2] = (unsigned char)(((-1 * itarget_buffer[j + 1]) & 0xff00) >> 8);
|
||||
tx.i8TxBuffer[3] = (unsigned char)((-1 * itarget_buffer[j + 1]) & 0xff);
|
||||
|
||||
ret = write(fd_rb, &tx, sizeof(uint32_t));
|
||||
i8TxBuffer[0] = (unsigned char)((itarget_buffer[j] & 0xff00) >> 8);
|
||||
i8TxBuffer[1] = (unsigned char)(itarget_buffer[j] & 0xff);
|
||||
i8TxBuffer[2] = (unsigned char)(((itarget_buffer[j + 1]) & 0xff00) >> 8);
|
||||
i8TxBuffer[3] = (unsigned char)((itarget_buffer[j + 1]) & 0xff);
|
||||
ret = write(fd_rb, i8TxBuffer, 4);
|
||||
j += 2;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
CCFLAGS += -Wcast-function-type
|
||||
|
||||
KERNEL_HEADERS=/lib/modules/$(shell uname -r)/build
|
||||
|
||||
obj-m := radioberry.o
|
||||
|
|
|
@ -62,31 +62,19 @@ static struct mutex spi_mutex;
|
|||
#include "radioberry_gateware.h"
|
||||
#include "radioberry_firmware.h"
|
||||
|
||||
#define VERSION "94"
|
||||
#define VERSION "95"
|
||||
|
||||
static DEFINE_MUTEX(radioberry_mutex);
|
||||
static wait_queue_head_t rx_sample_queue;
|
||||
|
||||
#define DEVICE_NAME "radioberry"
|
||||
#define DRIVER_NAME "radioberry"
|
||||
#define CLASS_NAME "radioberry"
|
||||
|
||||
static int _nrx = 1;
|
||||
static int majorNumber;
|
||||
static struct class* radioberryCharClass = NULL;
|
||||
static struct device* radioberryCharDevice = NULL;
|
||||
|
||||
#define SAMPLE_BYTES 512
|
||||
static int _nrx = 1;
|
||||
|
||||
static unsigned int irqNumber;
|
||||
static unsigned int gpioRxSamplesiPin = 25;
|
||||
|
||||
static irq_handler_t radioberry_irq_handler(unsigned int irq, void *dev_id, struct pt_regs *regs){
|
||||
wake_up_interruptible(&rx_sample_queue);
|
||||
return (irq_handler_t) IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static void firmware_load(char *firmware, int size) {
|
||||
static void firmware_load(const char *firmware, int size) {
|
||||
printk(KERN_INFO "inside %s function \n", __FUNCTION__);
|
||||
|
||||
u8 *buf = kmalloc(size + 1, GFP_KERNEL);
|
||||
|
@ -120,14 +108,82 @@ static void loading_radioberry_gateware(struct device *dev) {
|
|||
release_firmware(fw_entry);
|
||||
}
|
||||
|
||||
ssize_t radioberry_read(struct file *flip, char *buf, size_t count, loff_t *pos) {
|
||||
unsigned char rx_stream[SAMPLE_BYTES]={};
|
||||
wait_event_interruptible(rx_sample_queue, (((*rpi_read_io) >> 25) & 1) != 0);
|
||||
count = rxStream(_nrx, rx_stream);
|
||||
if (copy_to_user((char *)buf, &rx_stream, count)) return -EFAULT;
|
||||
return count;
|
||||
ssize_t radioberry_read(struct file *flip, char *buf, size_t count, loff_t *pos){
|
||||
unsigned char iqdata[SAMPLE_BYTES]={};
|
||||
int nr_samples = (_nrx == 1)? 63 : (_nrx == 2)? 72: (_nrx ==3)? 75: (_nrx ==4)? 76: (_nrx ==5)? 75: (_nrx ==6)? 78: (_nrx ==7)? 77: 80;
|
||||
uint32_t value = 0;
|
||||
|
||||
int s = 0, i = 0;
|
||||
while ((((*rpi_read_io) >> 25) & 1) == 0)
|
||||
udelay(100);
|
||||
for (s = 0; s < nr_samples; s++) {
|
||||
value = 0;
|
||||
*rpi_set_io_high = (1<<RPI_RX_CLK);
|
||||
value = *rpi_read_io;
|
||||
iqdata[i] = (((value >> 23) & 1) << 7);
|
||||
iqdata[i] |= (((value >> 20) & 1) << 6);
|
||||
iqdata[i] |= (((value >> 19) & 1) << 5);
|
||||
iqdata[i] |= (((value >> 18) & 1) << 4);
|
||||
iqdata[i] |= (((value >> 16) & 1) << 3);
|
||||
iqdata[i] |= (((value >> 13) & 1) << 2);
|
||||
iqdata[i] |= (((value >> 12) & 1) << 1);
|
||||
iqdata[i++] |= (((value >> 5) & 1));
|
||||
*rpi_set_io_low = (1<<RPI_RX_CLK);
|
||||
value = *rpi_read_io;
|
||||
iqdata[i] = (((value >> 23) & 1) << 7);
|
||||
iqdata[i] |= (((value >> 20) & 1) << 6);
|
||||
iqdata[i] |= (((value >> 19) & 1) << 5);
|
||||
iqdata[i] |= (((value >> 18) & 1) << 4);
|
||||
iqdata[i] |= (((value >> 16) & 1) << 3);
|
||||
iqdata[i] |= (((value >> 13) & 1) << 2);
|
||||
iqdata[i] |= (((value >> 12) & 1) << 1);
|
||||
iqdata[i++] |= (((value >> 5) & 1));
|
||||
*rpi_set_io_high = (1<<RPI_RX_CLK);
|
||||
value = *rpi_read_io;
|
||||
iqdata[i] = (((value >> 23) & 1) << 7);
|
||||
iqdata[i] |= (((value >> 20) & 1) << 6);
|
||||
iqdata[i] |= (((value >> 19) & 1) << 5);
|
||||
iqdata[i] |= (((value >> 18) & 1) << 4);
|
||||
iqdata[i] |= (((value >> 16) & 1) << 3);
|
||||
iqdata[i] |= (((value >> 13) & 1) << 2);
|
||||
iqdata[i] |= (((value >> 12) & 1) << 1);
|
||||
iqdata[i++] |= (((value >> 5) & 1));
|
||||
*rpi_set_io_low = (1<<RPI_RX_CLK);
|
||||
value = *rpi_read_io;
|
||||
iqdata[i] = (((value >> 23) & 1) << 7);
|
||||
iqdata[i] |= (((value >> 20) & 1) << 6);
|
||||
iqdata[i] |= (((value >> 19) & 1) << 5);
|
||||
iqdata[i] |= (((value >> 18) & 1) << 4);
|
||||
iqdata[i] |= (((value >> 16) & 1) << 3);
|
||||
iqdata[i] |= (((value >> 13) & 1) << 2);
|
||||
iqdata[i] |= (((value >> 12) & 1) << 1);
|
||||
iqdata[i++] |= (((value >> 5) & 1));
|
||||
*rpi_set_io_high = (1<<RPI_RX_CLK);
|
||||
value = *rpi_read_io;
|
||||
iqdata[i] = (((value >> 23) & 1) << 7);
|
||||
iqdata[i] |= (((value >> 20) & 1) << 6);
|
||||
iqdata[i] |= (((value >> 19) & 1) << 5);
|
||||
iqdata[i] |= (((value >> 18) & 1) << 4);
|
||||
iqdata[i] |= (((value >> 16) & 1) << 3);
|
||||
iqdata[i] |= (((value >> 13) & 1) << 2);
|
||||
iqdata[i] |= (((value >> 12) & 1) << 1);
|
||||
iqdata[i++] |= (((value >> 5) & 1));
|
||||
*rpi_set_io_low = (1<<RPI_RX_CLK);
|
||||
value = *rpi_read_io;
|
||||
iqdata[i] = (((value >> 23) & 1) << 7);
|
||||
iqdata[i] |= (((value >> 20) & 1) << 6);
|
||||
iqdata[i] |= (((value >> 19) & 1) << 5);
|
||||
iqdata[i] |= (((value >> 18) & 1) << 4);
|
||||
iqdata[i] |= (((value >> 16) & 1) << 3);
|
||||
iqdata[i] |= (((value >> 13) & 1) << 2);
|
||||
iqdata[i] |= (((value >> 12) & 1) << 1);
|
||||
iqdata[i++] |= (((value >> 5) & 1));
|
||||
}
|
||||
if (copy_to_user((char *)buf, &iqdata, nr_samples * 6)) return -EFAULT;
|
||||
return nr_samples * 6;
|
||||
}
|
||||
|
||||
|
||||
static ssize_t radioberry_write(struct file *flip, const char *buf, size_t count, loff_t *pos) {
|
||||
|
||||
unsigned char tx_stream[4];
|
||||
|
@ -150,7 +206,7 @@ static int radioberry_open(struct inode *inode, struct file *filep) {
|
|||
return -EBUSY;
|
||||
}
|
||||
int *minor = (int *)kmalloc(sizeof(int), GFP_KERNEL);
|
||||
int major = MAJOR(inode->i_rdev);
|
||||
// not used int major = MAJOR(inode->i_rdev);
|
||||
*minor = MINOR(inode->i_rdev);
|
||||
filep->private_data = (void *)minor;
|
||||
|
||||
|
@ -195,7 +251,7 @@ static long radioberry_ioctl(struct file *fp, unsigned int cmd, unsigned long ar
|
|||
if ((data[1] & 0xFE) == 0x00) lnrx = ((data[5] & 0x38) >> 3) + 1;
|
||||
|
||||
mutex_lock(&spi_mutex);
|
||||
spiXfer(0, data, data, 6); //spi channel 0 // tell the gateware the command.
|
||||
spiXfer(0,data, data, 6); //spi channel 0 // tell the gateware the command.
|
||||
mutex_unlock(&spi_mutex);
|
||||
|
||||
_nrx = lnrx;
|
||||
|
@ -230,9 +286,49 @@ static struct file_operations radioberry_fops = {
|
|||
|
||||
static int radioberry_probe(struct platform_device *pdev)
|
||||
{
|
||||
printk(KERN_INFO "inside %s function \n", __FUNCTION__);
|
||||
struct device *dev = &pdev->dev;
|
||||
return 0;
|
||||
int result;
|
||||
|
||||
printk(KERN_INFO "inside %s function \n", __FUNCTION__);
|
||||
if(!device_property_present(&pdev->dev, "rx-sample-gpio"))
|
||||
{
|
||||
printk("radioberry - Error! Device overlay property 'rx-sample-gpio' not found!\n");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
printk("radioberry - Device property 'rx-sample-gpio' found!\n");
|
||||
|
||||
|
||||
// Dynamically allocate a major number for the device
|
||||
majorNumber = register_chrdev(0, DEVICE_NAME, &radioberry_fops);
|
||||
if (majorNumber<0){
|
||||
printk(KERN_ALERT "Radioberry driver failed to register a major number\n");
|
||||
return majorNumber;
|
||||
}
|
||||
printk(KERN_INFO "Radioberry: registered correctly with major number %d\n", majorNumber);
|
||||
|
||||
// Register the device class
|
||||
radioberryCharClass = class_create(CLASS_NAME);
|
||||
if (IS_ERR(radioberryCharClass)){
|
||||
unregister_chrdev(majorNumber, DEVICE_NAME);
|
||||
printk(KERN_ALERT "Failed to register device class\n");
|
||||
return PTR_ERR(radioberryCharClass);
|
||||
}
|
||||
printk(KERN_INFO "Radioberry: device class registered correctly\n");
|
||||
|
||||
// Register the device driver
|
||||
radioberryCharDevice = device_create(radioberryCharClass, NULL, MKDEV(majorNumber, 0), NULL, DEVICE_NAME);
|
||||
if (IS_ERR(radioberryCharDevice)){
|
||||
class_destroy(radioberryCharClass);
|
||||
unregister_chrdev(majorNumber, DEVICE_NAME);
|
||||
printk(KERN_ALERT "Failed to create the device\n");
|
||||
return PTR_ERR(radioberryCharDevice);
|
||||
}
|
||||
printk(KERN_INFO "Radioberry char: device class created correctly\n");
|
||||
mutex_init(&spi_mutex);
|
||||
initialize_rpi();
|
||||
loading_radioberry_gateware(radioberryCharDevice);
|
||||
initialize_firmware();
|
||||
return result;
|
||||
}
|
||||
|
||||
static int radioberry_remove(struct platform_device *pdev)
|
||||
|
@ -259,86 +355,18 @@ static struct platform_driver radioberry_driver = {
|
|||
};
|
||||
|
||||
static int __init radioberry_init(void) {
|
||||
int retval;
|
||||
size_t size;
|
||||
|
||||
printk(KERN_INFO "inside %s function \n", __FUNCTION__);
|
||||
printk(KERN_INFO "%s loading...\n", DRIVER_NAME);
|
||||
|
||||
int result = platform_driver_register(&radioberry_driver);
|
||||
printk(KERN_INFO "platform driver registered %d \n", result);
|
||||
|
||||
// Dynamically allocate a major number for the device
|
||||
majorNumber = register_chrdev(0, DEVICE_NAME, &radioberry_fops);
|
||||
if (majorNumber<0){
|
||||
printk(KERN_ALERT "Radioberry driver failed to register a major number\n");
|
||||
return majorNumber;
|
||||
}
|
||||
printk(KERN_INFO "Radioberry: registered correctly with major number %d\n", majorNumber);
|
||||
|
||||
// Register the device class
|
||||
radioberryCharClass = class_create(THIS_MODULE, CLASS_NAME);
|
||||
if (IS_ERR(radioberryCharClass)){
|
||||
unregister_chrdev(majorNumber, DEVICE_NAME);
|
||||
printk(KERN_ALERT "Failed to register device class\n");
|
||||
return PTR_ERR(radioberryCharClass);
|
||||
}
|
||||
printk(KERN_INFO "Radioberry: device class registered correctly\n");
|
||||
|
||||
// Register the device driver
|
||||
radioberryCharDevice = device_create(radioberryCharClass, NULL, MKDEV(majorNumber, 0), NULL, DEVICE_NAME);
|
||||
if (IS_ERR(radioberryCharDevice)){
|
||||
class_destroy(radioberryCharClass);
|
||||
unregister_chrdev(majorNumber, DEVICE_NAME);
|
||||
printk(KERN_ALERT "Failed to create the device\n");
|
||||
return PTR_ERR(radioberryCharDevice);
|
||||
}
|
||||
printk(KERN_INFO "Radioberry char: device class created correctly\n");
|
||||
|
||||
mutex_init(&radioberry_mutex);
|
||||
init_waitqueue_head(&rx_sample_queue);
|
||||
|
||||
//configure irq.
|
||||
gpio_request(gpioRxSamplesiPin, "sysfs");
|
||||
gpio_direction_input(gpioRxSamplesiPin);
|
||||
gpio_export(gpioRxSamplesiPin, false);
|
||||
|
||||
printk(KERN_INFO "Radioberry: The rx sample state is currently: %d\n", gpio_get_value(gpioRxSamplesiPin));
|
||||
|
||||
// GPIO numbers and IRQ numbers are not the same! This function performs the mapping for us
|
||||
irqNumber = gpio_to_irq(gpioRxSamplesiPin);
|
||||
printk(KERN_INFO "Radioberry: The rx samples pin is mapped to IRQ: %d\n", irqNumber);
|
||||
|
||||
// This next call requests an interrupt line
|
||||
result = request_irq(irqNumber,
|
||||
(irq_handler_t) radioberry_irq_handler,
|
||||
IRQF_TRIGGER_RISING, // Interrupt on rising edge RQF_TRIGGER_RISING
|
||||
"radioberry_rx_irq", // Used in /proc/interrupts to identify the owner
|
||||
NULL);
|
||||
|
||||
printk(KERN_INFO "Radioberry: The interrupt request result is: %d\n", result);
|
||||
|
||||
mutex_init(&spi_mutex);
|
||||
|
||||
initialize_rpi();
|
||||
loading_radioberry_gateware(radioberryCharDevice);
|
||||
initialize_firmware();
|
||||
|
||||
printk(KERN_INFO "platform driver registered %d \n", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void __exit radioberry_exit(void) {
|
||||
int i;
|
||||
dev_t devno;
|
||||
dev_t devno_top;
|
||||
|
||||
printk(KERN_INFO "inside %s function \n", __FUNCTION__);
|
||||
|
||||
free_irq(irqNumber, NULL);
|
||||
gpio_unexport(gpioRxSamplesiPin);
|
||||
|
||||
platform_driver_unregister(&radioberry_driver);
|
||||
|
||||
platform_driver_unregister(&radioberry_driver);
|
||||
device_destroy(radioberryCharClass, MKDEV(majorNumber, 0));
|
||||
class_unregister(radioberryCharClass);
|
||||
class_destroy(radioberryCharClass);
|
||||
|
|
|
@ -19,32 +19,17 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
/dts-v1/;
|
||||
/plugin/;
|
||||
|
||||
/{
|
||||
compatible = "brcm,bcm2711";
|
||||
|
||||
fragment@0 {
|
||||
target = <&gpio>;
|
||||
__overlay__ {
|
||||
radioberry_gpio: radioberry_gpio {
|
||||
brcm,pins = <22 26 27 13 24>;
|
||||
brcm,function = <0x00 0x00 0x01 0x01 0x01>; //0 =input; 1=output
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
fragment@1 {
|
||||
target-path = "/";
|
||||
__overlay__ {
|
||||
radio: radio {
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <&radioberry_gpio>;
|
||||
compatible = "sdr,radioberry";
|
||||
gateware-gpios = <&gpio 22 0>, <&gpio 26 0>, <&gpio 27 0>, <&gpio 13 0>, <&gpio 24 0>;
|
||||
};
|
||||
};
|
||||
};
|
||||
fragment@0 {
|
||||
target-path = "/";
|
||||
__overlay__ {
|
||||
radio {
|
||||
compatible = "sdr,radioberry";
|
||||
rx-sample-gpio = <&gpio 25 0>;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
|
@ -35,9 +35,8 @@
|
|||
#define SPI_LTOH 4
|
||||
#define SPI_DC 5
|
||||
|
||||
#define SAMPLE_BYTES 512
|
||||
static int initialize_firmware(void);
|
||||
int rxStream(int nrx, unsigned char stream[]);
|
||||
void read_iq_sample(int lnrx, int iqs, unsigned char iqdata[]);
|
||||
int spiXfer(int spi_channel, char *txBuf, char *rxBuf, unsigned cnt);
|
||||
int write_iq_sample(unsigned char tx_iqdata[]);
|
||||
|
||||
|
@ -126,45 +125,6 @@ int spiXfer(int spi_channel, char *txBuf, char *rxBuf, unsigned cnt){
|
|||
return 0;
|
||||
}
|
||||
|
||||
int rxStream(int nrx, unsigned char stream[]){
|
||||
unsigned char iqdata[6];
|
||||
int iqs = 1;
|
||||
|
||||
int nr_samples = (nrx == 1)? 63 : (nrx == 2)? 72: (nrx ==3)? 75: (nrx ==4)? 76: (nrx ==5)? 75: (nrx ==6)? 78: (nrx ==7)? 77: 80;
|
||||
|
||||
int s = 0;
|
||||
for (s = 0; s < nr_samples; s++) {
|
||||
read_iq_sample(nrx, iqs, iqdata);
|
||||
memcpy(stream + (s * 6), iqdata, 6);
|
||||
iqs++;
|
||||
}
|
||||
return nr_samples * 6;
|
||||
}
|
||||
|
||||
void read_iq_sample(int lnrx, int iqs, unsigned char iqdata[]){
|
||||
uint32_t value = 0;
|
||||
|
||||
int i = 0;
|
||||
for (i = 0; i < 6 ; i++) {
|
||||
|
||||
if (i % 2 == 0) {
|
||||
*rpi_set_io_high = (1<<RPI_RX_CLK);
|
||||
value = *rpi_read_io;
|
||||
} else {
|
||||
*rpi_set_io_low = (1<<RPI_RX_CLK);
|
||||
value = *rpi_read_io;
|
||||
}
|
||||
iqdata[i] = (((value >> 23) & 1) << 7);
|
||||
iqdata[i] |= (((value >> 20) & 1) << 6);
|
||||
iqdata[i] |= (((value >> 19) & 1) << 5);
|
||||
iqdata[i] |= (((value >> 18) & 1) << 4);
|
||||
iqdata[i] |= (((value >> 16) & 1) << 3);
|
||||
iqdata[i] |= (((value >> 13) & 1) << 2);
|
||||
iqdata[i] |= (((value >> 12) & 1) << 1);
|
||||
iqdata[i] |= (((value >> 5) & 1));
|
||||
}
|
||||
}
|
||||
|
||||
int write_iq_sample(unsigned char tx_iqdata[]) {
|
||||
|
||||
unsigned char data[4];
|
||||
|
|
|
@ -35,8 +35,12 @@ install_dependency git
|
|||
install_dependency device-tree-compiler
|
||||
install_dependency pigpio
|
||||
|
||||
git clone --depth=1 https://github.com/pa3gsb/Radioberry-2.x
|
||||
|
||||
if [ -d "Radioberry-2.x" ]; then
|
||||
DO_CLEANUP=false
|
||||
else
|
||||
DO_CLEANUP=true
|
||||
git clone --depth=1 https://github.com/pa3gsb/Radioberry-2.x
|
||||
fi
|
||||
|
||||
sudo systemctl stop radioberry
|
||||
sudo systemctl disable radioberry
|
||||
|
@ -72,6 +76,13 @@ echo "Installing Radioberry driver..."
|
|||
|
||||
#unregister radioberry driver
|
||||
sudo modprobe -r radioberry
|
||||
|
||||
# new raspios uses /boot/firmware instead of /boot
|
||||
if [ -d "/boot/firmware" ]; then
|
||||
BOOT_PATH="/boot/firmware"
|
||||
else
|
||||
BOOT_PATH="/boot"
|
||||
fi
|
||||
|
||||
if [ ! -d "/lib/modules/$(uname -r)/kernel/drivers/sdr" ]; then
|
||||
sudo mkdir /lib/modules/$(uname -r)/kernel/drivers/sdr
|
||||
|
@ -83,9 +94,9 @@ if [ $? -eq 0 ]; then
|
|||
sudo cp radioberry.ko /lib/modules/$(uname -r)/kernel/drivers/sdr
|
||||
|
||||
sudo dtc -@ -I dts -O dtb -o radioberry.dtbo radioberry.dts
|
||||
sudo cp radioberry.dtbo /boot/overlays
|
||||
sudo cp radioberry.dtbo "$BOOT_PATH/overlays"
|
||||
#add driver to config.txt
|
||||
sudo grep -Fxq "dtoverlay=radioberry" /boot/config.txt || sudo sed -i '$ a dtoverlay=radioberry' /boot/config.txt
|
||||
sudo grep -Fxq "dtoverlay=radioberry" "$BOOT_PATH/config.txt" || sudo sed -i '$ a dtoverlay=radioberry' "$BOOT_PATH/config.txt"
|
||||
|
||||
cd ../../../../..
|
||||
|
||||
|
@ -103,7 +114,10 @@ else
|
|||
echo ""
|
||||
echo "You are using a linux version without linux header files; choose an other distro."
|
||||
|
||||
sudo rm -rf Radioberry-2.x
|
||||
if [ "$DO_CLEANUP" = true ]; then
|
||||
echo "Cleaning up..."
|
||||
sudo rm -rf Radioberry-2.x
|
||||
fi
|
||||
|
||||
exit 1
|
||||
fi
|
||||
|
@ -128,7 +142,10 @@ else
|
|||
echo ""
|
||||
echo "Looking into the log and try to find out what is wrong."
|
||||
|
||||
sudo rm -rf Radioberry-2.x
|
||||
if [ "$DO_CLEANUP" = true ]; then
|
||||
echo "Cleaning up..."
|
||||
sudo rm -rf Radioberry-2.x
|
||||
fi
|
||||
|
||||
exit 1
|
||||
fi
|
||||
|
@ -147,7 +164,10 @@ cd ../../../../..
|
|||
echo "Radioberry service installed."
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
sudo rm -rf Radioberry-2.x
|
||||
if [ "$DO_CLEANUP" = true ]; then
|
||||
echo "Cleaning up..."
|
||||
sudo rm -rf Radioberry-2.x
|
||||
fi
|
||||
|
||||
sudo systemctl enable radioberry
|
||||
sudo systemctl start radioberry
|
||||
|
|
Ładowanie…
Reference in New Issue