changeset 271:49f2db0470a5

BUG-id: DIO-19: SPICompositeMessage.appendDelay() method does not have any effect Summary: SPICompositeMessage.append delay behavior is implemented using Thread.sleep functionality. Also it is based on a contract which claims that SPI transfer operations are performed through the native call of transfer method and it means that if device transfer is implemented through the other calls(e.g. endTransaction()) it will not have any effect. Reviewed-by: snazarki Contributed-by: amironenko
author onazarkina
date Mon, 21 Mar 2016 14:07:14 +0300
parents 68069d97828b
children 04fedde14532
files src/se/classes/com/oracle/dio/utils/ExceptionMessage.java src/share/classes/com/oracle/dio/spibus/impl/SPICompositeMessageImpl.java
diffstat 2 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/se/classes/com/oracle/dio/utils/ExceptionMessage.java	Tue Mar 15 17:17:36 2016 +0300
+++ b/src/se/classes/com/oracle/dio/utils/ExceptionMessage.java	Mon Mar 21 14:07:14 2016 +0300
@@ -153,7 +153,8 @@
     public static final int SPIBUS_SLAVE_WORD_LENGTH                 = SPIBUS_FIRST + 0;
     public static final int SPIBUS_BYTE_NUMBER_BELIES_WORD_LENGTH    = SPIBUS_FIRST + 1;
     public static final int SPIBUS_BYTE_BUFFER_MODIFICATION          = SPIBUS_FIRST + 2;
-    public static final int SPIBUS_LAST = SPIBUS_BYTE_BUFFER_MODIFICATION;
+    public static final int SPIBUS_TRANSFER_INTERRUPTED              = SPIBUS_FIRST + 3;
+    public static final int SPIBUS_LAST = SPIBUS_TRANSFER_INTERRUPTED;
 
     public static final int UART_FIRST = SPIBUS_LAST + 1;
     public static final int UART_CANT_GET_PORT_NAME                  = UART_FIRST + 0;
@@ -279,6 +280,7 @@
         "Slave Word Length is %d",
         "the number of bytes to receive/send belies word length",
         "The original read buffer was modified after append",
+        "Delay operation in composite message was interrupted",
 
         // uart messages
         "Cannot get serial port name",
--- a/src/share/classes/com/oracle/dio/spibus/impl/SPICompositeMessageImpl.java	Tue Mar 15 17:17:36 2016 +0300
+++ b/src/share/classes/com/oracle/dio/spibus/impl/SPICompositeMessageImpl.java	Mon Mar 21 14:07:14 2016 +0300
@@ -29,8 +29,11 @@
 import java.util.ArrayList;
 
 import com.oracle.dio.utils.ExceptionMessage;
+import java.io.InterruptedIOException;
 import java.nio.BufferOverflowException;
 import java.util.ConcurrentModificationException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import jdk.dio.ClosedDeviceException;
 import jdk.dio.UnavailableDeviceException;
@@ -236,6 +239,8 @@
                     if(message.newRx.remaining() > 0) {
                         device.transferWithLock(message.newTx, message.newRx);
                     }
+                    
+                    Thread.currentThread().sleep((message.delay / 1000), (message.delay % 1000) * 1000);
                 }
                 
                 device.endTransaction();
@@ -268,6 +273,9 @@
                 
                 return bytesRead;
             
+            } catch (InterruptedException ex) {
+                throw new InterruptedIOException(ExceptionMessage.format(
+                        ExceptionMessage.SPIBUS_TRANSFER_INTERRUPTED));
             } finally {
                 device.endTransaction();
             }