jim herd / FPGA_bus
Revision:
23:4b391cfd4f2d
Parent:
22:c47d4177d59c
Child:
25:9cdeb5267a47
--- a/FPGA_bus.cpp	Tue Jun 23 11:39:07 2020 +0000
+++ b/FPGA_bus.cpp	Fri Jun 26 11:02:30 2020 +0000
@@ -474,25 +474,35 @@
 //      BUS_FAIL_2 = no handshake response
 //      BUS_FAIL_3 = handshake failed to terminate correctly
 //
+
 int32_t FPGA_bus::soft_check_bus(void)
 {
+uint32_t  timeout_counter;
 
-    wait_us(uS_DELAY_BEFORE_TEST_HANDSHAKE);
-    
-    if (uP_handshake_2 == HIGH) {
-        return  BUS_FAIL_1;       // handshake line in wrong init state
+    timeout_counter = HANDSHAKE_TIMEOUT_COUNT;
+    while (uP_handshake_2 == HIGH) {
+        timeout_counter--;
+        if (timeout_counter == 0) {
+            return  BUS_FAIL_1;       // handshake line in wrong init state
+        }
     }
     async_uP_handshake_1 = HIGH;
-    wait_us(uS_DELAY_BEFORE_TEST_HANDSHAKE);
-    if (uP_handshake_2 == LOW) {
-        async_uP_handshake_1 = LOW;
-        return  BUS_FAIL_2;       // no handshake response
+    timeout_counter = HANDSHAKE_TIMEOUT_COUNT;
+    while (uP_handshake_2 == LOW) {
+        timeout_counter--;
+        if (timeout_counter == 0) {
+            async_uP_handshake_1 = LOW;
+            return  BUS_FAIL_1;       // no handshake response
+        }
     }
     async_uP_handshake_1 = LOW;
-    wait_us(uS_DELAY_BEFORE_TEST_HANDSHAKE);
-    if (uP_handshake_2 == HIGH) {
-        return  BUS_FAIL_2;       // handshake failed to terminate correctly
-    }        
+    timeout_counter = HANDSHAKE_TIMEOUT_COUNT;
+    while (uP_handshake_2 == HIGH) {
+        timeout_counter--;
+        if (timeout_counter == 0) {
+            return  BUS_FAIL_2;       // handshake failed to terminate correctly
+        }
+    }    
     return NO_ERROR;
 }