- Added further locks
authorTom Knot <tomasknot@gmail.com>
Fri, 29 Jun 2018 09:12:03 +0000 (11:12 +0200)
committerTom Knot <tomasknot@gmail.com>
Fri, 29 Jun 2018 09:12:03 +0000 (11:12 +0200)
- c_iflags hopefully does not get set

modules/unipi/src/unipi_tty.c
modules/unipi/src/unipi_uart.c
version.txt

index 65698be166988bb3fbe464d6cfafad25bd1ac777..79f260d978888f489a1638fe81b4d65d6bab8e94 100644 (file)
@@ -25,7 +25,7 @@ struct tty_ldisc_ops neuronspi_tty_ldisc;
 int neuronspi_tty_init()
 {
        int err;
-       printk(KERN_INFO "NEURONSPI TTYInit\n");
+       printk(KERN_INFO "NEURONSPI TTY Init\n");
        memset(&neuronspi_tty_ldisc, 0, sizeof(neuronspi_tty_ldisc));
        n_tty_inherit_ops(&neuronspi_tty_ldisc);
        neuronspi_tty_ldisc.magic                       = TTY_LDISC_MAGIC;
index 029f430b72de308351dd4393cb9df8967dfd07a2..42b6da65512f37189be6dd570eedb2b209f95d1e 100644 (file)
@@ -163,10 +163,9 @@ void neuronspi_uart_set_termios(struct uart_port *port, struct ktermios *termios
 //#endif
        neuronspi_spi_uart_set_cflag(neuronspi_s_dev[n_port->dev_index], n_port->dev_port, termios->c_cflag);
        if (old && termios && (old->c_iflag & PARMRK) != (termios->c_iflag & PARMRK)) {
+               neuronspi_uart_set_iflags(port, termios->c_iflag);
                if (termios->c_iflag & PARMRK) {
-                       neuronspi_uart_set_iflags(port, termios->c_iflag);
-               } else {
-                       neuronspi_uart_set_iflags(port, termios->c_iflag);
+                       termios->c_iflag &= ~PARMRK;
                }
        }
        if (old && termios && old->c_line != termios->c_line) {
@@ -266,15 +265,13 @@ s32 neuronspi_uart_alloc_line(void)
 
 void neuronspi_uart_handle_rx(struct neuronspi_port *port, u32 rxlen, u32 iir)
 {
-       u32 ch, flag, bytes_read, i;
+       u32 ch, flag, flags, bytes_read, i;
        while (rxlen) {
-
                neuronspi_uart_fifo_read(&port->port, rxlen);
                bytes_read = rxlen;
-
+               spin_lock_irqsave(&port->port.lock, flags);
                port->port.icount.rx++;
                flag = TTY_NORMAL;
-
                for (i = 0; i < bytes_read; ++i) {
 #if NEURONSPI_DETAILED_DEBUG > 0
                        printk(KERN_INFO "NEURONSPI: UART Insert Char:%x\n", port->buf[i]);
@@ -286,14 +283,14 @@ void neuronspi_uart_handle_rx(struct neuronspi_port *port, u32 rxlen, u32 iir)
                        uart_insert_char(&port->port, 0, 0, ch, flag);
                }
                rxlen -= bytes_read;
+               spin_lock_irqrestore(&port->port.lock, flags);
        }
-
        tty_flip_buffer_push(&port->port.state->port);
 }
 
 void neuronspi_uart_handle_tx(struct neuronspi_port *port)
 {
-       u32 max_txlen, to_send, to_send_packet, i;
+       s32 max_txlen, to_send, to_send_packet, i;
        unsigned long flags;
        struct spi_device *spi;
        struct neuronspi_driver_data *d_data;
@@ -335,36 +332,31 @@ void neuronspi_uart_handle_tx(struct neuronspi_port *port)
                        /* Add data to send */
                        spin_lock_irqsave(&port->port.lock, flags);
                        port->port.icount.tx += to_send_packet;
-                       spin_unlock_irqrestore(&port->port.lock, flags);
-
                        /* Convert to linear buffer */
                        for (i = 0; i < to_send_packet; ++i) {
-                               spin_lock_irqsave(&port->port.lock, flags);
                                port->buf[i] = xmit->buf[xmit->tail];
                                xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
-                               spin_unlock_irqrestore(&port->port.lock, flags);
                        }
+                       spin_unlock_irqrestore(&port->port.lock, flags);
                        printk(KERN_INFO "NEURONSPI UART_HANDLE_TX B, to_send:%d\n", to_send_packet);
                        neuronspi_uart_fifo_write(port, to_send_packet);
-                       to_send -= to_send_packet;
+                       spin_lock_irqsave(&port->port.lock, flags);
+                       to_send = uart_circ_chars_pending(xmit);
+                       spin_unlock_irqrestore(&port->port.lock, flags);
                }
-               to_send = (to_send > NEURONSPI_FIFO_SIZE - NEURONSPI_FIFO_MIN_CONTINUOUS) ? NEURONSPI_FIFO_SIZE - NEURONSPI_FIFO_MIN_CONTINUOUS : to_send;
-
-               /* Add data to send */
                spin_lock_irqsave(&port->port.lock, flags);
-               port->port.icount.tx += to_send;
-               spin_unlock_irqrestore(&port->port.lock, flags);
-
+               to_send = uart_circ_chars_pending(xmit);
+               to_send_packet = (to_send > max_txlen) ? max_txlen : to_send;
+               /* Add data to send */
+               port->port.icount.tx += to_send_packet;
                /* Convert to linear buffer */
-               for (i = 0; i < to_send; ++i) {
-                       spin_lock_irqsave(&port->port.lock, flags);
+               for (i = 0; i < to_send_packet; ++i) {
                        port->buf[i] = xmit->buf[xmit->tail];
                        xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
-                       spin_unlock_irqrestore(&port->port.lock, flags);
                }
-               printk(KERN_INFO "NEURONSPI UART_HANDLE_TX C, to_send:%d\n", to_send);
-               neuronspi_uart_fifo_write(port, to_send);
-
+               spin_unlock_irqrestore(&port->port.lock, flags);
+               printk(KERN_INFO "NEURONSPI UART_HANDLE_TX C, to_send:%d\n", to_send_packet);
+               neuronspi_uart_fifo_write(port, to_send_packet);
        }
 
        spin_lock_irqsave(&port->port.lock, flags);
@@ -563,7 +555,9 @@ void neuronspi_uart_rx_proc(struct kthread_work *ws)
                if (recv_buf[6] == 0x65 && recv_buf[7] > 0) {
                        mutex_lock(&neuronspi_master_mutex);
                        memcpy(&d_data->uart_buf[0], &recv_buf[10], recv_buf[7]);
+                       mutex_unlock(&neuronspi_master_mutex);
                        neuronspi_uart_handle_rx(n_port, recv_buf[7], 1);
+                       mutex_lock(&neuronspi_master_mutex);
                        read_count = recv_buf[9];
                        mutex_unlock(&neuronspi_master_mutex);
                } else if (recv_buf[0] != 0x41) {
index 0f1edc8543dd6c85c4920e216270e4338e57625d..c21f0c4452573104852c8f5a78ab698ed3037afb 100644 (file)
@@ -1 +1 @@
-Repository:neuron-kernel ActiveBranch:[uart_timeout] PrecedingRelease:v.0.12 PrecedingRevision:70(0561924) LatestCommit:Wed Jun 27 18:15:18 CEST 2018
+Repository:neuron-kernel ActiveBranch:[uart_timeout] PrecedingRelease:v.0.12 PrecedingRevision:71(84e5bdd) LatestCommit:Fri Jun 29 11:12:04 CEST 2018