Added locking behaviour to prevent byte swapping due to UART/SPI asynchronousness
authorTom Knot <tomasknot@gmail.com>
Tue, 14 Aug 2018 16:02:57 +0000 (18:02 +0200)
committerTom Knot <tomasknot@gmail.com>
Tue, 14 Aug 2018 16:02:57 +0000 (18:02 +0200)
modules/unipi/src/unipi_spi.c
modules/unipi/src/unipi_uart.c
version.txt

index e1438962cd1fc2531742d1fb82febe4f7fb7af2f..592bfbd50441df28dfb14d8d1abaa709988fa830 100644 (file)
@@ -60,6 +60,7 @@ struct neuronspi_char_driver neuronspi_cdrv =
 };
 
 struct mutex neuronspi_master_mutex;
+struct mutex neuronspi_uart_mutex;
 struct mutex unipi_inv_speed_mutex;
 struct spinlock *neuronspi_spi_w_spinlock;
 int neuronspi_model_id = -1;
@@ -747,6 +748,7 @@ int neuronspi_spi_send_message(struct spi_device* spi_dev, u8 *send_buf, u8 *rec
 #if NEURONSPI_DETAILED_DEBUG > 1
                printk(KERN_INFO "UNIPISPI: SPI CRC1 Correct");
 #endif
+                       mutex_lock(&neuronspi_uart_mutex);
                        if (d_data && recv_buf[0] == 0x41) {
                                d_data->uart_buf[0] = recv_buf[3];
 #if NEURONSPI_DETAILED_DEBUG > 0
@@ -770,6 +772,10 @@ int neuronspi_spi_send_message(struct spi_device* spi_dev, u8 *send_buf, u8 *rec
                                        }
                                }
                        }
+                       mutex_unlock(&neuronspi_uart_mutex);
+                       if (d_data && recv_buf[0] == 0x65) {
+                               mutex_lock(&neuronspi_uart_mutex);
+                       }
                }
 #if NEURONSPI_DETAILED_DEBUG > 0
                else {
@@ -1536,6 +1542,7 @@ static s32 __init neuronspi_init(void)
        neuronspi_probe_spinlock = kzalloc(sizeof(struct spinlock), GFP_ATOMIC);
        spin_lock_init(neuronspi_probe_spinlock);
        mutex_init(&neuronspi_master_mutex);
+       mutex_init(&neuronspi_uart_mutex);
        mutex_init(&unipi_inv_speed_mutex);
        memset(&neuronspi_s_dev, 0, sizeof(neuronspi_s_dev));
        ret = spi_register_driver(&neuronspi_spi_driver);
index d0b875db14c434c96665c905fee5f9d238fc3b78..56e7b9c6b6f11f7d2b86c59ee873aa4c0ccb75c7 100644 (file)
@@ -579,6 +579,7 @@ void neuronspi_uart_rx_proc(struct kthread_work *ws)
                        end_flag = 1;
                        mutex_unlock(&neuronspi_master_mutex);
                }
+               mutex_unlock(&neuronspi_uart_mutex);
        }
        kfree(recv_buf);
        kfree(send_buf);
index b2d3493b6cf631367f2c63211234c38e6f0056a0..cd9c38b270a79397e4c32effb24eaef07464dafc 100644 (file)
@@ -1 +1 @@
-Repository:unipi-kernel ActiveBranch:[master] PrecedingRelease:v.0.12 PrecedingRevision:100(1ab48c5) LatestCommit:Mon Aug 6 16:55:47 CEST 2018
+Repository:unipi-kernel ActiveBranch:[master] PrecedingRelease:v.0.12 PrecedingRevision:101(d663411) LatestCommit:Tue Aug 14 18:02:57 CEST 2018