#include "potentiometer.h" #include "tmsgheaders.h" uint32_t pot_array [2] = {0,0}; double freq_file [50] = {0}; uint32_t pot_offset [50]= {0}; uint32_t pot_slope [50]= {0}; uint32_t pot_ch_a_file; uint32_t pot_ch_b_file; /* arrays of potentiometer values from file */ void potentiometer_set(reg_addr_pci* pci_bar_1, uint8_t pot_val_ch_a, uint8_t pot_val_ch_b) { usleep(1); uint32_t cfg_reg = get_cfg_reg(); SET_REGISTER_PARAM(cfg_reg, CFG_REG_SPI_MODE_BITM, CFG_REG_SPI_MODE_BITP, CFG_REG_SPI_MODE_4MOSI); pci_bar_1->cfg_reg_addr = cfg_reg; uint32_t pot_ch_a = (TPL0202_CMD_WR_WIPER_REG_ENUM << TPL0202_CMD_BITP)|(TPL0202_ADR_B_ENUM << TPL0202_ADR_BITP)|(pot_val_ch_a << TPL0202_DATA_BITP); uint32_t pot_ch_b = (TPL0202_CMD_WR_WIPER_REG_ENUM << TPL0202_CMD_BITP)|(TPL0202_ADR_A_ENUM << TPL0202_ADR_BITP)|(pot_val_ch_b << TPL0202_DATA_BITP); // Create a header for the Potentiometer 4MOSI uint32_t pot_header = (ENUM_SPIMODE_4MOSI | (0x2 << BITP_POT_4MOSI_HEADER) | SB_HEADER_TERM_BIT_1); pci_bar_1->sbtmsg_addr = pot_header; // Send the data pci_bar_1->sbtmsg_addr = pot_ch_a; pci_bar_1->sbtmsg_addr = pot_ch_b; usleep(1); SET_REGISTER_PARAM(cfg_reg, CFG_REG_SPI_MODE_BITM, CFG_REG_SPI_MODE_BITP, CFG_REG_SPI_MODE_1MOSI); pci_bar_1->cfg_reg_addr = cfg_reg; set_cfg_reg(cfg_reg); usleep(1); } /* Read the potentiometer values from the file */ void read_pot_file (const char* filename) { FILE *file = fopen(filename, "r"); if (file == NULL) { printf("Error: File not found\n"); return; } int i = 0; while (fscanf(file, "%lf %u %u", &freq_file[i], &pot_offset[i], &pot_slope[i]) != EOF) { i++; } fclose(file); } void set_pot_values(double freq){ for (int i = 0; i < 50; i++) { if (freq <= freq_file[i]) { pot_ch_a_file = (TPL0202_CMD_WR_WIPER_REG_ENUM << TPL0202_CMD_BITP)|(TPL0202_ADR_A_ENUM << TPL0202_ADR_BITP)|(pot_offset[i-1] << TPL0202_DATA_BITP); pot_ch_b_file = (TPL0202_CMD_WR_WIPER_REG_ENUM << TPL0202_CMD_BITP)|(TPL0202_ADR_B_ENUM << TPL0202_ADR_BITP)|(pot_slope[i-1]<< TPL0202_DATA_BITP); break; } } } void potentiometer_set_offset (reg_addr_pci* pci_bar_1, uint8_t pot_offset) { uint32_t pot_ch_a = (TPL0202_CMD_WR_WIPER_REG_ENUM << TPL0202_CMD_BITP)|(TPL0202_ADR_A_ENUM << TPL0202_ADR_BITP)|(pot_offset << TPL0202_DATA_BITP); //Create a header pci_bar_1->sbtmsg_addr = ((ENUM_SPIMODE_4MOSI) |(0x1 << BITP_POT_4MOSI_HEADER)| TERM_BIT_1); pci_bar_1->sbtmsg_addr = pot_ch_a; } void potentiometer_set_slope (reg_addr_pci* pci_bar_1, uint8_t pot_slope) { uint32_t pot_ch_b = (TPL0202_CMD_WR_WIPER_REG_ENUM << TPL0202_CMD_BITP)|(TPL0202_ADR_B_ENUM << TPL0202_ADR_BITP)|(pot_slope << TPL0202_DATA_BITP); //Create a header pci_bar_1->sbtmsg_addr = ((ENUM_SPIMODE_4MOSI) |(0x1 << BITP_POT_4MOSI_HEADER)| TERM_BIT_1); pci_bar_1->sbtmsg_addr = pot_ch_b; }