diff --git a/driver/radioberry.c b/driver/radioberry.c index 324772c..34a53dc 100644 --- a/driver/radioberry.c +++ b/driver/radioberry.c @@ -46,7 +46,7 @@ sudo cp radioberry.ko /lib/modules/$(uname -r)/kernel/drivers/sdr #include #include #include -#include +#include #include #include #include @@ -55,12 +55,14 @@ sudo cp radioberry.ko /lib/modules/$(uname -r)/kernel/drivers/sdr #include #include +static struct mutex spi_mutex; + #include "radioberry_rpi.h" #include "radioberry_ioctl.h" #include "radioberry_gateware.h" #include "radioberry_firmware.h" -#define VERSION "0.9" +#define VERSION "93" static DEFINE_MUTEX(radioberry_mutex); static wait_queue_head_t rx_sample_queue; @@ -126,7 +128,7 @@ ssize_t radioberry_read(struct file *flip, char *buf, size_t count, loff_t *pos) return count; } -static int radioberry_write(struct file *flip, const char *buf, size_t count, loff_t *pos) { +static ssize_t radioberry_write(struct file *flip, const char *buf, size_t count, loff_t *pos) { unsigned char tx_stream[4]; @@ -192,8 +194,9 @@ static long radioberry_ioctl(struct file *fp, unsigned int cmd, unsigned long ar //printk(KERN_INFO "Command kernel %2X - %2X - %2X - %2X - %2X - %2X \n", data[0], data[1], data[2], data[3], data[4], data[5]); if ((data[1] & 0xFE) == 0x00) lnrx = ((data[5] & 0x38) >> 3) + 1; - // tell the gateware the command. - spiXfer(data, data, 6); + mutex_lock(&spi_mutex); + spiXfer(0, data, data, 6); //spi channel 0 // tell the gateware the command. + mutex_unlock(&spi_mutex); _nrx = lnrx; @@ -203,7 +206,7 @@ static long radioberry_ioctl(struct file *fp, unsigned int cmd, unsigned long ar rb_info_ret.minor = data[5]; rb_info_ret.fpga = data[3] & 0x03; - rb_info_ret.version = 0.9; + rb_info_ret.version = 93; if (copy_to_user((struct rb_info_arg_t *)arg, &rb_info_ret, sizeof(struct rb_info_arg_t))) return -EACCES; @@ -314,6 +317,8 @@ static int __init radioberry_init(void) { NULL); printk(KERN_INFO "Radioberry: The interrupt request result is: %d\n", result); + + mutex_init(&spi_mutex); initialize_rpi(); loading_radioberry_gateware(radioberryCharDevice); @@ -340,6 +345,7 @@ static void __exit radioberry_exit(void) { unregister_chrdev(majorNumber, DEVICE_NAME); mutex_destroy(&radioberry_mutex); + mutex_destroy(&spi_mutex); deinitialize_rpi(); diff --git a/driver/radioberry.rbf b/driver/radioberry.rbf index 2079fe1..ae7ca25 100644 Binary files a/driver/radioberry.rbf and b/driver/radioberry.rbf differ diff --git a/driver/radioberry_firmware.h b/driver/radioberry_firmware.h index 33a6470..8446167 100644 --- a/driver/radioberry_firmware.h +++ b/driver/radioberry_firmware.h @@ -1,8 +1,6 @@ #ifndef __RADIOBERRY_FIRMWARE_H__ #define __RADIOBERRY_FIRMWARE_H__ -#include - #define PI_ALT0 4 #define RPI_RX_CLK 6 @@ -40,14 +38,14 @@ 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(char *txBuf, char *rxBuf, unsigned cnt); +int spiXfer(int spi_channel, char *txBuf, char *rxBuf, unsigned cnt); int write_iq_sample(unsigned char tx_iqdata[]); static int initialize_firmware() { //SPI mode pins setPinMode(RPI_SPI_CE0, PI_ALT0); - //setPinMode(RPI_SPI_CE1, PI_ALT0); + setPinMode(RPI_SPI_CE1, PI_ALT0); setPinMode(RPI_SPI_SCLK, PI_ALT0); setPinMode(RPI_SPI_MISO, PI_ALT0); @@ -57,27 +55,22 @@ static int initialize_firmware() { initialize_gpio_for_output(rpi_io, RPI_RX_CLK); *rpi_set_io_low = (1<> 16) & 1) << 7); - iqdata[i] |= (((value >> 19) & 1) << 6); - iqdata[i] |= (((value >> 20) & 1) << 5); - iqdata[i] |= (((value >> 21) & 1) << 4); - - *rpi_set_io_low = (1<> 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 >> 19) & 1) << 2); - iqdata[i] |= (((value >> 20) & 1) << 1); - iqdata[i] |= (((value >> 21) & 1)); + 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[]) { -int write_iq_sample(unsigned char tx_iqdata[]){ - - uint32_t value = 0; - int i = 0; - for (i = 0; i < 4 ; i++) { - if (tx_iqdata[i] & 0x80) *rpi_set_io_high = (1<<17); else *rpi_set_io_low = (1<<17); - if (tx_iqdata[i] & 0x40) *rpi_set_io_high = (1<<5); else *rpi_set_io_low = (1<<5); - if (tx_iqdata[i] & 0x20) *rpi_set_io_high = (1<<18); else *rpi_set_io_low = (1<<18); - if (tx_iqdata[i] & 0x10) *rpi_set_io_high = (1<<12); else *rpi_set_io_low = (1<<12); - *rpi_set_io_high = (1<> 7) & 1); + return 4; } #endif diff --git a/driver/radioberry_ioctl.h b/driver/radioberry_ioctl.h index e3cda54..f5f246d 100644 --- a/driver/radioberry_ioctl.h +++ b/driver/radioberry_ioctl.h @@ -14,7 +14,7 @@ struct rb_info_arg_t int fpga; - float version; + int version; int rb_command; int command;