Преглед изворни кода

Добавлена функция вычитывания статуса LD

Mikhail Zaytsev пре 1 година
родитељ
комит
bd74ed89e6
3 измењених фајлова са 32 додато и 7 уклоњено
  1. 6 0
      Devices/lmx2594.c
  2. 2 0
      Devices/lmx2594.h
  3. 24 7
      command.c

+ 6 - 0
Devices/lmx2594.c

@@ -453,4 +453,10 @@ int lmx_freq_set(void *bar1, double freq) {
         lmx_freq_set_out_of_band(bar1, freq, f_pd);
     }
     return 0;
+}
+
+uint32_t lmx_ld_status(void *bar1) {
+    uint32_t *read_ptr = (uint32_t *)(bar1 + LMX_LD_STATUS_ADDR);
+    uint32_t read_value = *read_ptr;    
+    return read_value;
 }

+ 2 - 0
Devices/lmx2594.h

@@ -5,11 +5,13 @@
 
 #define     LMX_COUNT           113
 #define     LMX_BASE_ADDR       0x04
+#define     LMX_LD_STATUS_ADDR  0x18
 
 void lmx2594_init(void *bar1);
 
 int lmx_freq_set_main_band(void *bar1, double freq, double f_pd);
 int lmx_freq_set_out_of_band(void *bar1, double freq, double f_pd);
 int lmx_freq_set(void *bar1, double freq);
+uint32_t lmx_ld_status(void *bar1);
 
 #endif //DMADRIVER_LMX2594_H

+ 24 - 7
command.c

@@ -7,6 +7,8 @@
 #include <strings.h>
 #include <string.h>
 #include <sys/socket.h>
+#include <unistd.h>
+#include <time.h>
 
 #include "Devices/lmx2594.h"
 
@@ -37,17 +39,32 @@ void handleFreqCmd(const char* recvBuff)
 void handleLdCmd(const char* recvBuff)
 {
 	int n = 0;
-	char messageLd[] = "0\n";
+	char messageLd[] = "1\n";
 
 	printf("\nTMSG44:LD?\n");
 
-	if (1)
-	{
-		strcpy(messageLd, "1\n");
-	}
-	else if (0)
+	uint32_t ld_status = lmx_ld_status(bar1);
+	printf("LD status: %d\n", ld_status);
+
+	clock_t before = clock();
+	clock_t difference;
+	int difference_msec = 0;
+	int trigger = 10; //10ms
+
+	while(!ld_status)
 	{
-		strcpy(messageLd, "0\n");
+		difference = clock() - before;
+		difference_msec = difference * 1000 / CLOCKS_PER_SEC;
+
+		if(difference_msec >= trigger)
+		{
+			strcpy(messageLd, "0\n");
+			printf("LD timeout\n");
+			break;
+		}
+		
+		usleep(1000);
+		uint32_t ld_status = lmx_ld_status(bar1);
 	}
 
 	send(conn_fd, messageLd, sizeof(messageLd), 0);