Pārlūkot izejas kodu

Переиспользование порта. Изменения в отгрузках LMX

zaytsev.mikhail.olegovich@gmail.com 1 gadu atpakaļ
vecāks
revīzija
38f7a75117
3 mainītis faili ar 66 papildinājumiem un 32 dzēšanām
  1. 47 10
      Devices/lmx2594.c
  2. 13 17
      command.c
  3. 6 5
      main.c

+ 47 - 10
Devices/lmx2594.c

@@ -101,10 +101,10 @@ uint32_t lmx2594regs[LMX_COUNT] = {
         0x14D848,
         0x1327B7,
         0x120064,
-        0x110130,
+        0x11012C,
         0x100080,
         0x0F064F,
-        0x0E1E40,
+        0x0E1E70,
         0x0D4000,
         0x0C5001,
         0x0B0018,
@@ -165,8 +165,16 @@ int lmx_freq_set_main_band(void *bar1, double freq, double f_pd) {
     // Set the MASH_ORDER to 3
     lmx2594regs[112-MASH_ORDER] = lmx2594regs[112-MASH_ORDER] | ENUM_LMX2594_R44_MASH_ORDER_3;
     // Set PF_DLY_SEL to 3
-    lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] & (~BITM_LMX2594_R37_PFD_DLY_SEL);
-    lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] | (0x3 << BITP_LMX2594_R37_PFD_DLY_SEL);
+    if (freq <= 10e9) {
+        lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] & (~BITM_LMX2594_R37_PFD_DLY_SEL);
+        lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] | (0x3 << BITP_LMX2594_R37_PFD_DLY_SEL);
+        printf("PFD_DLY_SEL = %d\n", 3);
+    }
+    else if (freq > 10e9) {
+        lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] & (~BITM_LMX2594_R37_PFD_DLY_SEL);
+        lmx2594regs[112-PFD_DLY_SEL] = lmx2594regs[112-PFD_DLY_SEL] | (0x4 << BITP_LMX2594_R37_PFD_DLY_SEL);
+        printf("PFD_DLY_SEL = %d\n", 4);
+    }
     lmx2594regs[112-PLL_N_S] = lmx2594regs[112-PLL_N_S] &(~0xFFFF);
     lmx2594regs[112-PLL_N_S] = lmx2594regs[112-PLL_N_S] | (N >> 16);
     //CLear the lower 16 bits of the register
@@ -188,6 +196,8 @@ int lmx_freq_set_main_band(void *bar1, double freq, double f_pd) {
     lmx2594regs[112-PLL_DEN_M] = lmx2594regs[112-PLL_DEN_M] & (~0xFFFF);
     // Next 16 bits of the denominator
     lmx2594regs[112-PLL_DEN_M] = lmx2594regs[112-PLL_DEN_M] | (frac_d & 0xFFFF);
+    lmx2594regs[112-CHDIV_DIV2] = lmx2594regs[112 - CHDIV_DIV2] & (~BITM_LMX2594_R31_CHDIV_DIV2);
+    lmx2594regs[112 - CHDIV] = lmx2594regs[112 - CHDIV] & (~BITM_LMX2594_R75_CHDIV);
     // Set the OUTA_MUX to channel divider R45[12:11]; 0 - Channel divider, 1 - VCO;
     lmx2594regs[112 - OUTA_MUX] = lmx2594regs[112 - OUTA_MUX] & (~BITM_LMX2594_R45_OUTA_MUX);
     lmx2594regs[112 - OUTA_MUX] = lmx2594regs[112 - OUTA_MUX] | ENUM_LMX2594_R45_OUTA_MUX_VCO;
@@ -204,6 +214,8 @@ int lmx_freq_set_main_band(void *bar1, double freq, double f_pd) {
             lmx2594regs[112-PLL_DEN_M],
             lmx2594regs[112-PLL_NUM_S],
             lmx2594regs[112-PLL_NUM_M],
+            lmx2594regs[112 - CHDIV],
+            lmx2594regs[112 - CHDIV_DIV2],
             lmx2594regs[112-OUTA_MUX],
             lmx2594regs[112-FCAL_ADDR]
     };
@@ -216,6 +228,12 @@ int lmx_freq_set_main_band(void *bar1, double freq, double f_pd) {
         *data_ptr = lmx_change_freq_regs[i];
     }
     usleep(1);
+    printf("N_div = %f\n", N_div);
+    printf("f_vco = %f\n", freq);
+    printf("SEG1_EN %08X\n",lmx2594regs[112 - CHDIV_DIV2]);
+    printf("N = %d\n", N);
+    printf("frac_n = %d\n", frac_n);
+    printf("frac_d = %d\n", frac_d);
     return 0;
 }
 
@@ -370,9 +388,17 @@ int lmx_freq_set_out_of_band(void *bar1, double freq, double f_pd) {
     lmx2594regs[112 - MASH_ORDER] = lmx2594regs[112 - MASH_ORDER] & (~BITM_LMX2594_R44_MASH_ORDER);
     // Set the MASH_ORDER to 3
     lmx2594regs[112 - MASH_ORDER] = lmx2594regs[112 - MASH_ORDER] | ENUM_LMX2594_R44_MASH_ORDER_3;
-    // Set PF_DLY_SEL to 3
-    lmx2594regs[112 - PFD_DLY_SEL] = lmx2594regs[112 - PFD_DLY_SEL] & (~BITM_LMX2594_R37_PFD_DLY_SEL);
-    lmx2594regs[112 - PFD_DLY_SEL] = lmx2594regs[112 - PFD_DLY_SEL] | (0x3 << BITP_LMX2594_R37_PFD_DLY_SEL);
+    // Set PF_DLY_SEL to appropriate value
+    if (f_vco <=10e9){
+        lmx2594regs[112 - PFD_DLY_SEL] = lmx2594regs[112 - PFD_DLY_SEL] & (~BITM_LMX2594_R37_PFD_DLY_SEL);
+        lmx2594regs[112 - PFD_DLY_SEL] = lmx2594regs[112 - PFD_DLY_SEL] | (0x3 << BITP_LMX2594_R37_PFD_DLY_SEL);
+        printf("PFD_DLY_SEL = %d\n", 3);
+    }
+    else if (f_vco > 10e9) {
+        lmx2594regs[112 - PFD_DLY_SEL] = lmx2594regs[112 - PFD_DLY_SEL] & (~BITM_LMX2594_R37_PFD_DLY_SEL);
+        lmx2594regs[112 - PFD_DLY_SEL] = lmx2594regs[112 - PFD_DLY_SEL] | (0x4 << BITP_LMX2594_R37_PFD_DLY_SEL);
+        printf("PFD_DLY_SEL = %d\n", 4);
+    }
     lmx2594regs[112 - PLL_N_S] = lmx2594regs[112 - PLL_N_S] & (~0xFFFF);
     lmx2594regs[112 - PLL_N_S] = lmx2594regs[112 - PLL_N_S] | (N >> 16);
     //CLear the lower 16 bits of the register
@@ -403,6 +429,9 @@ int lmx_freq_set_out_of_band(void *bar1, double freq, double f_pd) {
         lmx2594regs[112 - CHDIV_DIV2] = lmx2594regs[112 - CHDIV_DIV2] & (~BITM_LMX2594_R31_CHDIV_DIV2);
         lmx2594regs[112 - CHDIV_DIV2] = lmx2594regs[112 - CHDIV_DIV2] | (ENUM_LMX2594_R31_CHDIV_DIV2_EN);
     }
+    else {
+        lmx2594regs[112-CHDIV_DIV2] =  lmx2594regs[112 - CHDIV_DIV2] & (~BITM_LMX2594_R31_CHDIV_DIV2);
+    }
     // Set the OUTA_MUX to channel divider R45[12:11]; 0 - Channel divider, 1 - VCO;
     lmx2594regs[112 - OUTA_MUX] = lmx2594regs[112 - OUTA_MUX] & (~BITM_LMX2594_R45_OUTA_MUX);
     lmx2594regs[112 - OUTA_MUX] = lmx2594regs[112 - OUTA_MUX] | ENUM_LMX2594_R45_OUTA_MUX_CH_DIV;
@@ -419,10 +448,10 @@ int lmx_freq_set_out_of_band(void *bar1, double freq, double f_pd) {
             lmx2594regs[112 - PLL_DEN_M],
             lmx2594regs[112 - PLL_NUM_S],
             lmx2594regs[112 - PLL_NUM_M],
-            lmx2594regs[112 - FCAL_ADDR],
-            lmx2594regs[112 - CHDIV_DIV2],
             lmx2594regs[112 - CHDIV],
-            lmx2594regs[112 - OUTA_MUX]
+            lmx2594regs[112 - CHDIV_DIV2],
+            lmx2594regs[112 - OUTA_MUX],
+            lmx2594regs[112 - FCAL_ADDR]
     };
     // Create a header for the LMX2594 with the appropriate number of words
     uint32_t LMX_HEADER = ((0 << 23) | (DeviceIdLmx2594 << 18) | ((sizeof(lmx_change_freq_regs) / 4) << 1) | 1);
@@ -434,6 +463,14 @@ int lmx_freq_set_out_of_band(void *bar1, double freq, double f_pd) {
         *data_ptr = lmx_change_freq_regs[i];
     }
     usleep(1);
+            printf("N_div = %f\n", N_div);
+            printf("f_vco = %f\n", f_vco);
+            printf("SEG1_EN %08X\n",lmx2594regs[112 - CHDIV_DIV2]);
+            printf("N = %d\n", N);
+            printf("frac_n = %d\n", frac_n);
+            printf("frac_d = %d\n", frac_d);
+            printf("chan_div = %d\n", chan_div);
+            printf("chan_div_reg = %d\n", ch_div_reg);
     return 0;
 }
 

+ 13 - 17
command.c

@@ -26,14 +26,14 @@ Command commands[] = {
 //handleXXXXCmd - обработчики команд
 void handleFreqCmd(const char* recvBuff)
 {
-	printf("\nTMSG44:FREQ\n");
+	printf("\nHandle command \"TMSG44:FREQ\"\n");
 	double freq[1] = {0};
 
 	splitLexeme(recvBuff, freq, sizeof(freq[0]), convertToDouble);
 
-	printf("%f\n", freq[0]);
+	printf("Frequency: %.2f Hz\n", freq[0]);
     lmx_freq_set(bar1, freq[0]);
-    printf("The frequency is set to %f Hz\n", freq[0]);
+    printf("The frequency is set to %.2f MHz\n", freq[0]/1e6);
 }
 
 void handleLdCmd(const char* recvBuff)
@@ -41,15 +41,14 @@ void handleLdCmd(const char* recvBuff)
 	int n = 0;
 	char messageLd[] = "1\n";
 
-	printf("\nTMSG44:LD?\n");
+	printf("\nHandle command \"TMSG44:LD?\"\n");
 
 	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
+	int trigger = 10000; //10ms
 
 	while(!ld_status)
 	{
@@ -62,19 +61,18 @@ void handleLdCmd(const char* recvBuff)
 			printf("LD timeout\n");
 			break;
 		}
-		
-		usleep(1000);
-		uint32_t ld_status = lmx_ld_status(bar1);
+		ld_status = lmx_ld_status(bar1);
+		// printf("WHILE LD status: %d\n", ld_status);
 	}
 
 	send(conn_fd, messageLd, sizeof(messageLd), 0);
 	
-	printf("\nSend msg LD!\n");
+	printf("\nSend msg LD: %d!\n", ld_status);
 }
 
 void handlePowCmd(const char* recvBuff)
 {
-	printf("\nTMSG44:POW\n");
+	printf("\nHandle command \"TMSG44:POW\"\n");
 	double pow[1] = {0};
 
 	splitLexeme(recvBuff, pow, sizeof(pow[0]), convertToDouble);
@@ -83,7 +81,7 @@ void handlePowCmd(const char* recvBuff)
 
 void handleArmCmd(const char* recvBuff)
 {
-	printf("\nTMSG44:ARM\n");
+	printf("\nHandle command \"TMSG44:ARM\"\n");
 	uint16_t armCode[1] = {0};
 
 	splitLexeme(recvBuff, armCode, sizeof(armCode[0]), convertToUInt16);
@@ -92,7 +90,7 @@ void handleArmCmd(const char* recvBuff)
 
 void handleAttCmd(const char* recvBuff)
 {
-	printf("\nTMSG44:ATT\n");
+	printf("\nHandle command \"TMSG44:ATT\"\n");
 	uint16_t attCode[1] = {0};
 
 	splitLexeme(recvBuff, attCode, sizeof(attCode[0]), convertToUInt16);
@@ -101,12 +99,10 @@ void handleAttCmd(const char* recvBuff)
 
 void handleIdnCmd(const char* recvBuff)
 {
-	ssize_t n;
-	printf("\n*IDN?\n");
+	printf("\nHandle command \"*IDN?\"\n");
 
 	char messageIdn[] = "TMSG44_CoolPi\n";
-	n = send(conn_fd, messageIdn, sizeof(messageIdn), 0);
-	printf("%ld \n", n);
+	send(conn_fd, messageIdn, sizeof(messageIdn), 0);
 }
 
 //Проходим по массиву команд и ищем команду, которая совпадает с началом строки recvBuff. 

+ 6 - 5
main.c

@@ -95,7 +95,6 @@ int main(int argc, char *argv[])
     }
 
     bar1 = mmap(NULL, REQUESTED_MEMORY_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, pci_fd, 0);
-    printf("bar0 ptr %p\n", bar1);
     if (bar1 == MAP_FAILED) {
         perror("mmap");
         close(pci_fd);
@@ -125,10 +124,10 @@ int main(int argc, char *argv[])
 	serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
 	serv_addr.sin_port = htons(SERVER_PORT); 
 
-	// if (setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int)) < 0)
-    // {
-	// 	error("setsockopt(SO_REUSEADDR) failed");
-	// }
+	if (setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int)) < 0)
+    {
+		error("setsockopt(SO_REUSEADDR) failed");
+	}
 
 	if (bind(listen_fd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) 
 	{
@@ -157,11 +156,13 @@ int main(int argc, char *argv[])
 		while ((n = recv(conn_fd, recvBuff, sizeof(recvBuff) - 1, 0)) > 0)
 		{
 			recvBuff[n] = 0;
+		
 			if(fputs(recvBuff, stdout) == EOF)
 			{
 				printf("\n Error : Fputs error\n");
 				break;
 			}
+		
 			// Указатель команды
 			ptrLexeme = NULL;
 			// Указатель для хранения контекста токенизации