Forráskód Böngészése

Поменял AM_ALC_1_FIX в GPIO reg на 0, изменил входной клок lmk_a на 100MHz.

Anatoliy Chigirinskiy 1 éve
szülő
commit
dcb211588f
4 módosított fájl, 171 hozzáadás és 197 törlés
  1. 4 5
      Devices/ad9912.c
  2. 13 13
      Devices/lmk04821.c
  3. 1 1
      Devices/tmsgheaders.c
  4. 153 178
      command.c

+ 4 - 5
Devices/ad9912.c

@@ -65,13 +65,13 @@ double ad9912_set_main_band(double lmx_freq,double f_pd) {
     if (lmx_freq <= 12500e6) {
         if (N < 28){
             N = 28;
-        };
+        }
     }
     else if (lmx_freq > 12500e6) {
         if (N < 32) {
             N = 32;
         }
-    };
+    }
     printf("N = %d\n", N);
     // Calculate the new phase detector frequency by dividing the frequency by the new value of N
     f_pd = lmx_freq/N; // Phase detector frequency
@@ -163,13 +163,13 @@ double ad9912_set_out_of_band(double lmx_freq,double f_pd) {
     if (f_vco <= 12500e6) {
         if (N < 28){
             N = 28;
-        };
+        }
     }
     else if (f_vco > 12500e6) {
         if (N < 32) {
             N = 32;
         }
-    };
+    }
     // Calculate the new phase detector frequency by dividing the frequency by the new value of N
     f_pd = f_vco/N; // Phase detector frequency
 
@@ -187,7 +187,6 @@ double ad9912_set(reg_addr_pci* pci_bar_1, double freq, double f_pd) {
     }
     else {
         return -1;
-        printf("Frequency is out of range\n");
     }
     printf("f_pd = %f\n", f_pd);
     // FTW word

+ 13 - 13
Devices/lmk04821.c

@@ -142,46 +142,46 @@ const uint32_t lmk04821regs_a[LMK_COUNT] = {
         0x000600,
         0x000C51,
         0x000D04,
-        0x010001,
+        0x010002,
         0x010197,
         0x010255,
-        0x010302,
+        0x010301,
         0x010402,
         0x010500,
-        0x0106F1,
+        0x0106F0,
         0x010707,
-        0x010801,
+        0x010802,
         0x010955,
         0x010A55,
-        0x010B02,
+        0x010B01,
         0x010C02,
         0x010D00,
         0x010EB1,
         0x010F07,
-        0x011001,
+        0x011002,
         0x011155,
         0x011255,
-        0x011302,
+        0x011301,
         0x011402,
         0x011500,
         0x0116F1,
         0x011707,
-        0x011801,
+        0x011802,
         0x011955,
         0x011A55,
-        0x011B02,
+        0x011B01,
         0x011C02,
         0x011D00,
         0x011EF1,
         0x011F07,
-        0x012001,
+        0x012002,
         0x012155,
         0x012255,
-        0x012302,
+        0x012301,
         0x012402,
         0x012500,
-        0x0126F1,
-        0x012707,
+        0x0126F0,
+        0x012717,
         0x012801,
         0x012955,
         0x012A55,

+ 1 - 1
Devices/tmsgheaders.c

@@ -21,7 +21,7 @@ uint32_t tmsg_shift_reg = SHIFT_REG;
 						PLL_SYNC_0				|
 						PLL_SYNC_CTRL_0			|
 						PLL_VTUNE_CTRL_1		|
-						AM_ALC_1_FIX_1			|
+						AM_ALC_1_FIX_0			|
 						SW_CAP1_0				|
 						SW_CAP2_0				|
 						SW_CAP3_0				|

+ 153 - 178
command.c

@@ -24,222 +24,197 @@ uint16_t offsetCode[1] = {0};
 uint16_t slopeCode[1] = {0};
 
 //Массив структур command, который связывает строки команд с соответствующими функциями.
-command commands[] = {
-	{"TMSG44:FREQ ", 	handle_freq_cmd},
-	{"TMSG44:LD?", 		handle_ld_cmd},
-	{"TMSG44:POW ", 	handle_pow_cmd},
-	{"TMSG44:ARM ", 	handle_arm_cmd},
-	{"TMSG44:ATT ", 	handle_att_cmd},
-	{"*IDN?", 			handle_idn_cmd},
-	{"TMSG44:OFFSET ",	handle_offset_cmd},
-	{"TMSG44:SLOPE ",	handle_slope_cmd},
-	{NULL, NULL} // Завершающий элемент для обозначения конца массива
+command commands[] = {{"TMSG44:FREQ ",   handle_freq_cmd},
+                      {"TMSG44:LD?",     handle_ld_cmd},
+                      {"TMSG44:POW ",    handle_pow_cmd},
+                      {"TMSG44:ARM ",    handle_arm_cmd},
+                      {"TMSG44:ATT ",    handle_att_cmd},
+                      {"*IDN?",          handle_idn_cmd},
+                      {"TMSG44:OFFSET ", handle_offset_cmd},
+                      {"TMSG44:SLOPE ",  handle_slope_cmd},
+                      {NULL, NULL} // Завершающий элемент для обозначения конца массива
 };
 
 //handleXXXXCmd - обработчики команд
-void handle_freq_cmd(const char* recv_buff)
-{
-	
-	printf("\nHandle command \"TMSG44:FREQ\"\n");
-	double freq[1] = {0};
-	double lmx_freq = 0;
-
-	split_lexeme(recv_buff, freq, sizeof(freq[0]), convert_to_double);
-	
-	lmx_freq = lmx_get_freq(freq[0]);
-	f_pd = ad9912_set(pci_bar_1, lmx_freq, f_pd);
-	printf("f_pd frequency is set to %.6f MHz\n", f_pd/1e6);
+void handle_freq_cmd(const char *recv_buff) {
+
+    printf("\nHandle command \"TMSG44:FREQ\"\n");
+    double freq[1] = {0};
+    double lmx_freq = 0;
+
+    split_lexeme(recv_buff, freq, sizeof(freq[0]), convert_to_double);
+
+    lmx_freq = lmx_get_freq(freq[0]);
+    f_pd = ad9912_set(pci_bar_1, lmx_freq, f_pd);
+    printf("f_pd frequency is set to %.6f MHz\n", f_pd / 1e6);
     lmx_freq_set(pci_bar_1, lmx_freq, f_pd);
-	// Switch the keys 
-	key_switch(pci_bar_1, freq[0],lmx_freq);
-    printf("The frequency is set to %.2f MHz\n", freq[0]/1e6);
-	// Send the data 
-	send_data_qspi(pci_bar_1);
-	   // Return the 1 MOSI mode
-    // usleep(1);
-	// cfg_reg = get_cfg_reg();
-    // SET_REGISTER_PARAM(cfg_reg,CFG_REG_SPI_MODE_BITM,CFG_REG_SPI_MODE_BITP, CFG_REG_SPI_MODE_1MOSI);
-    // *spi_mode = cfg_reg;
-    // set_cfg_reg(cfg_reg);
-	
+    // Switch the keys
+    key_switch(pci_bar_1, freq[0], lmx_freq);
+    printf("The frequency is set to %.2f MHz\n", freq[0] / 1e6);
+    // Send the data
+    send_data_qspi(pci_bar_1);
+
 }
-void send_data_qspi(reg_addr_pci* pci_bar_1) {
-	// get the gpio reg and shift reg data 
-	uint32_t gpio_reg = get_tmsg_gpio_reg();
-	uint32_t shift_reg = get_tmsg_shift_reg();
-	
-	// Create a header 4 Mosi mode
-	uint32_t qspi_header = ((ENUM_SPIMODE_4MOSI) | 
-							(0x1 << BITP_GPIO_4MOSI_HEADER) | 
-							(0x1 << BITP_SHIFT_REG_4MOSI_HEADER ) | 
-							((sizeof(ad9912_ftw_regs_qspi) / 4) << BITP_DDS_4MOSI_HEADER) | 
-							((sizeof(lmx_change_freq_regs) / 4) << BITP_LMX2594_4MOSI_HEADER) | 
-							(TERM_BIT_1));
-	
-	pci_bar_1->sbtmsg_addr = qspi_header;
-
-	// Initialize the registers
-	// Send the data for AD9912
-	for (int i = 0; i < sizeof(ad9912_ftw_regs_qspi) / 4; i++) {
-		pci_bar_1->sbtmsg_addr = ad9912_ftw_regs_qspi[i];
-	}
-
-	// Send the data for the GPIO
-	pci_bar_1->sbtmsg_addr = gpio_reg;
-
-	// Send the data for LMX2594
-	for (int i = 0; i < sizeof(lmx_change_freq_regs) / 4; i++) {
-		pci_bar_1->sbtmsg_addr = lmx_change_freq_regs[i];
-	}
-
-	// Send the data for the shift register
-	pci_bar_1->sbtmsg_addr = shift_reg;
+
+void send_data_qspi(reg_addr_pci *pci_bar_1) {
+    // get the gpio reg and shift reg data
+    uint32_t gpio_reg = get_tmsg_gpio_reg();
+    uint32_t shift_reg = get_tmsg_shift_reg();
+
+    // Create a header 4 Mosi mode
+    uint32_t qspi_header = ((ENUM_SPIMODE_4MOSI) | (0x1 << BITP_GPIO_4MOSI_HEADER) |
+                            (0x1 << BITP_SHIFT_REG_4MOSI_HEADER) |
+                            ((sizeof(ad9912_ftw_regs_qspi) / 4) << BITP_DDS_4MOSI_HEADER) |
+                            ((sizeof(lmx_change_freq_regs) / 4) << BITP_LMX2594_4MOSI_HEADER) | (TERM_BIT_1));
+
+    pci_bar_1->sbtmsg_addr = qspi_header;
+
+    // Initialize the registers
+    // Send the data for AD9912
+    for (int i = 0; i < sizeof(ad9912_ftw_regs_qspi) / 4; i++) {
+        pci_bar_1->sbtmsg_addr = ad9912_ftw_regs_qspi[i];
+    }
+
+    // Send the data for the GPIO
+    pci_bar_1->sbtmsg_addr = gpio_reg;
+
+    // Send the data for LMX2594
+    for (int i = 0; i < sizeof(lmx_change_freq_regs) / 4; i++) {
+        pci_bar_1->sbtmsg_addr = lmx_change_freq_regs[i];
+    }
+
+    // Send the data for the shift register
+    pci_bar_1->sbtmsg_addr = shift_reg;
 }
 
-void handle_ld_cmd(const char* recv_buff)
-{
-	char messageLd[] = "1\n";
-
-	printf("\nHandle command \"TMSG44:LD?\"\n");
-
-	uint32_t ld_status = lmx_ld_status(pci_bar_1);
-
-	clock_t before = clock();
-	clock_t difference;
-	int difference_msec = 0;
-	int trigger = 10000; //10ms
-
-	while(!ld_status)
-	{
-		difference = clock() - before;
-		difference_msec = difference * 1000 / CLOCKS_PER_SEC;
-
-		if(difference_msec >= trigger)
-		{
-			strcpy(messageLd, "0\n");
-			printf("LD timeout\n");
-			break;
-		}
-		ld_status = lmx_ld_status(pci_bar_1);
-		// printf("WHILE LD status: %d\n", ld_status);
-	}
-
-	send(conn_fd, messageLd, sizeof(messageLd), 0);
-	
-	printf("\nSend msg LD: %d!\n", ld_status);
+void handle_ld_cmd(const char *recv_buff) {
+    char messageLd[] = "1\n";
+
+    printf("\nHandle command \"TMSG44:LD?\"\n");
+
+    uint32_t ld_status = lmx_ld_status(pci_bar_1);
+
+    clock_t before = clock();
+    clock_t difference;
+    int difference_msec = 0;
+    int trigger = 10000; //10ms
+
+    while (!ld_status) {
+        difference = clock() - before;
+        difference_msec = difference * 1000 / CLOCKS_PER_SEC;
+
+        if (difference_msec >= trigger) {
+            strcpy(messageLd, "0\n");
+            printf("LD timeout\n");
+            break;
+        }
+        ld_status = lmx_ld_status(pci_bar_1);
+        // printf("WHILE LD status: %d\n", ld_status);
+    }
+
+    send(conn_fd, messageLd, sizeof(messageLd), 0);
+
+    printf("\nSend msg LD: %d!\n", ld_status);
 }
 
-void handle_pow_cmd(const char* recv_buff)
-{
-	printf("\nHandle command \"TMSG44:POW\"\n");
-	double pow[1] = {0};
+void handle_pow_cmd(const char *recv_buff) {
+    printf("\nHandle command \"TMSG44:POW\"\n");
+    double pow[1] = {0};
 
-	split_lexeme(recv_buff, pow, sizeof(pow[0]), convert_to_double);
-	printf("%f\n", pow[0]);
+    split_lexeme(recv_buff, pow, sizeof(pow[0]), convert_to_double);
+    printf("%f\n", pow[0]);
 }
 
-void handle_arm_cmd(const char* recv_buff)
-{
-	printf("\nHandle command \"TMSG44:ARM\"\n");
+void handle_arm_cmd(const char *recv_buff) {
+    printf("\nHandle command \"TMSG44:ARM\"\n");
 
-	split_lexeme(recv_buff, armCode, sizeof(armCode[0]), convert_to_uint16);
-	printf("\n%u\n", armCode[0]);
-	dac8811_set_qspi(pci_bar_1, armCode[0]);
+    split_lexeme(recv_buff, armCode, sizeof(armCode[0]), convert_to_uint16);
+    printf("\n%u\n", armCode[0]);
+    dac8811_set_qspi(pci_bar_1, armCode[0]);
 }
 
-void handle_att_cmd(const char* recv_buff)
-{
-	printf("\nHandle command \"TMSG44:ATT\"\n");
+void handle_att_cmd(const char *recv_buff) {
+    printf("\nHandle command \"TMSG44:ATT\"\n");
 
-	split_lexeme(recv_buff, attCode, sizeof(attCode[0]), convert_to_uint16);
-	printf("\n%u\n", attCode[0]);
-	dac8811_att_set_qspi(pci_bar_1, attCode[0]);
+    split_lexeme(recv_buff, attCode, sizeof(attCode[0]), convert_to_uint16);
+    printf("\n%u\n", attCode[0]);
+    dac8811_att_set_qspi(pci_bar_1, attCode[0]);
 }
 
-void handle_idn_cmd(const char* recv_buff)
-{
-	printf("\nHandle command \"*IDN?\"\n");
+void handle_idn_cmd(const char *recv_buff) {
+    printf("\nHandle command \"*IDN?\"\n");
 
-	char messageIdn[] = "TMSG44_CoolPi\n";
-	send(conn_fd, messageIdn, sizeof(messageIdn), 0);
+    char messageIdn[] = "TMSG44_CoolPi\n";
+    send(conn_fd, messageIdn, sizeof(messageIdn), 0);
 }
 
-void handle_offset_cmd(const char* recv_buff)
-{
-	printf("\nHandle command \"TMSG44:OFFSET\"\n");
+void handle_offset_cmd(const char *recv_buff) {
+    printf("\nHandle command \"TMSG44:OFFSET\"\n");
 
-	split_lexeme(recv_buff, offsetCode, sizeof(offsetCode[0]), convert_to_uint16);
-	printf("\n%u\n", offsetCode[0]);
-	potentiometer_set_offset(pci_bar_1, offsetCode[0]);
+    split_lexeme(recv_buff, offsetCode, sizeof(offsetCode[0]), convert_to_uint16);
+    printf("\n%u\n", offsetCode[0]);
+    potentiometer_set_offset(pci_bar_1, offsetCode[0]);
 }
 
-void handle_slope_cmd(const char* recv_buff)
-{
-	printf("\nHandle command \"TMSG44:SLOPE\"\n");
-	split_lexeme(recv_buff, slopeCode, sizeof(slopeCode[0]), convert_to_uint16);
-	printf("\n%u\n", slopeCode[0]);
-	potentiometer_set_slope(pci_bar_1, slopeCode[0]);
+void handle_slope_cmd(const char *recv_buff) {
+    printf("\nHandle command \"TMSG44:SLOPE\"\n");
+    split_lexeme(recv_buff, slopeCode, sizeof(slopeCode[0]), convert_to_uint16);
+    printf("\n%u\n", slopeCode[0]);
+    potentiometer_set_slope(pci_bar_1, slopeCode[0]);
 }
 
 //Проходим по массиву команд и ищем команду, которая совпадает с началом строки recv_buff. 
 //Если команда найдена, вызывается соответствующая функция-обработчик
-void process_command(const char* recv_buff) 
-{
-	for (int i = 0; commands[i].command != NULL; i++) 
-	{
-		if (!strncasecmp(recv_buff, commands[i].command, strlen(commands[i].command))) 
-		{
-			commands[i].handler(recv_buff);
-			return;
-		}
-	}
-	printf("\nUnknown command: %s\n", recv_buff);
+void process_command(const char *recv_buff) {
+    for (int i = 0; commands[i].command != NULL; i++) {
+        if (!strncasecmp(recv_buff, commands[i].command, strlen(commands[i].command))) {
+            commands[i].handler(recv_buff);
+            return;
+        }
+    }
+    printf("\nUnknown command: %s\n", recv_buff);
 }
 
 // Преобразование строки в uint16_t
-void convert_to_uint16(const char *str, void *output) 
-{
-	*(uint16_t *)output = (uint16_t)strtoul(str, NULL, 10);
+void convert_to_uint16(const char *str, void *output) {
+    *(uint16_t *) output = (uint16_t) strtoul(str, NULL, 10);
 }
 
 // Преобразование строки в unsigned long long int
-void convert_to_uint64(const char *str, void *output) 
-{
-	*(uint64_t *)output = (uint64_t)strtoull(str, NULL, 10);
+void convert_to_uint64(const char *str, void *output) {
+    *(uint64_t *) output = (uint64_t) strtoull(str, NULL, 10);
 }
 
 // Преобразование строки в double
-void convert_to_double(const char *str, void *output) 
-{
-	*(double *)output = strtod(str, NULL);
+void convert_to_double(const char *str, void *output) {
+    *(double *) output = strtod(str, NULL);
 }
 
 // Универсальная функция для разделения строки на лексемы
-void split_lexeme(const char *ptr_scpi, void *out_value, size_t element_size, convert_func_type convert_func) 
-{
-	uint8_t counter = 0;
-
-	// Разделители лексем
-	const char charSeparator[] = {" "};
-	char *ptr_lexeme = NULL;
-	// Указатель для хранения контекста токенизации
-	char *savePtr;
-
-	// Инициализируем функцию
-	ptr_lexeme = strtok_r((char *)ptr_scpi, charSeparator, &savePtr);
-
-	// Ищем лексемы разделенные разделителем
-	ptr_lexeme = strtok_r(NULL, charSeparator, &savePtr);
-
-	// Ищем лексемы строки
-	while (ptr_lexeme) {
-		// Проверяем, является ли первый символ лексемы числом
-		if(('0' <= ptr_lexeme[0]) && (ptr_lexeme[0] <= '9')) {
-			// Преобразуем строку с числом в число
-			convert_func(ptr_lexeme, (uint8_t *)out_value + counter * element_size);
-			counter++;
-		}
-		// Ищем лексемы разделенные разделителем
-		ptr_lexeme = strtok_r(NULL, charSeparator, &savePtr);
-	}
+void split_lexeme(const char *ptr_scpi, void *out_value, size_t element_size, convert_func_type convert_func) {
+    uint8_t counter = 0;
+
+    // Разделители лексем
+    const char charSeparator[] = {" "};
+    char *ptr_lexeme = NULL;
+    // Указатель для хранения контекста токенизации
+    char *savePtr;
+
+    // Инициализируем функцию
+    ptr_lexeme = strtok_r((char *) ptr_scpi, charSeparator, &savePtr);
+
+    // Ищем лексемы разделенные разделителем
+    ptr_lexeme = strtok_r(NULL, charSeparator, &savePtr);
+
+    // Ищем лексемы строки
+    while (ptr_lexeme) {
+        // Проверяем, является ли первый символ лексемы числом
+        if (('0' <= ptr_lexeme[0]) && (ptr_lexeme[0] <= '9')) {
+            // Преобразуем строку с числом в число
+            convert_func(ptr_lexeme, (uint8_t *) out_value + counter * element_size);
+            counter++;
+        }
+        // Ищем лексемы разделенные разделителем
+        ptr_lexeme = strtok_r(NULL, charSeparator, &savePtr);
+    }
 }