diff --git a/sw/config b/sw/config new file mode 100644 index 0000000..bf76251 --- /dev/null +++ b/sw/config @@ -0,0 +1,13 @@ +#Feedback Loop Configuration File +# +#Each line of this file defines a configuration slot and consists of integer numbers delimited by white spaces in the following order: +#ADDSUB_MODE ADD_INPUT_MUX DELAY FACTOR TIMESTAMP +# +#ADDSUB_MODE: Select feedback mode (0=negative, 1=positive) +#ADD_INPUT_MUX: Select feedback input (0=GND[only ADC Input 1], 1=ADC Input 2[Both ADC inputs are used]) +#DELAY: Clock cycles counts (50 ns period) to delay the feedback signal [0-255] +#FACTOR: Multiplication factor to apply to the feedback signal [0-15] (NOTE: Integer is intepreted as a 1Q3 Fixed Point Number!) +#TIMESTAMP: Defines the clock count number from the sync pulse from which on the configurations settings will be applied. [32-bit unsigned integer] +# First Config slot should have a timestamp equal to zero. +1 0 0 8 0 +0 0 0 8 1200000000 diff --git a/sw/out b/sw/out new file mode 100644 index 0000000..285b4a8 Binary files /dev/null and b/sw/out differ diff --git a/sw/write_config b/sw/write_config new file mode 100755 index 0000000..ef38376 Binary files /dev/null and b/sw/write_config differ diff --git a/sw/write_config.c b/sw/write_config.c new file mode 100644 index 0000000..a6ccfbf --- /dev/null +++ b/sw/write_config.c @@ -0,0 +1,89 @@ +#include +#include +#include +#include +#include +#include +#include + +void bail(); + +FILE* src = NULL; +int dest = -1; +char* line = NULL; +size_t len = 0; + + +int main(int argc, char *argv[]){ + + if (argc != 3){ + fprintf(stderr,"USAGE:\n %s source-file target-file\n", argv[0]); + return -1; + } + + // Open Source Configuration File + src = fopen(argv[1], "r"); + if(src == NULL){ + perror("Failed to open file"); + bail(); + return -1; + } + + // Open Destination File + dest = open(argv[2], O_WRONLY); + if(dest == -1){ + perror("Failed to open file"); + bail(); + return -1; + } + + uint64_t data, addsub_mode, add_input_mode, delay, factor, timestamp; + + /*File Parsing Loop*/ + while(getline(&line, &len, src) != -1){ + //Check if Comment Line + if(line[0] == '#'){ + continue; + } + + if(sscanf(line, "%u %u %u %u %u", &addsub_mode, &add_input_mode, &delay, &factor, ×tamp) < 5){ + perror("Parsing of configuration file failed"); + fprintf(stderr, "Failing line: %s", line); + bail(); + return -1; + } + + data = 0x0; + data |= ((uint64_t)0x1 << 63) | ((addsub_mode & 0x1) << 62) | ((add_input_mode & 0x1) << 61) | ((delay & 0xFF) << 40) | + ((factor & 0xF) << 32) | (timestamp & 0xFFFFFFFF); + if(write(dest, &data, sizeof(uint64_t)) != sizeof(uint64_t)){ + perror("Failed to write data"); + bail(); + return -1; + } + } + + //Write A non enabled slot + data = 0x0; + if(write(dest, &data, sizeof(uint64_t)) != sizeof(uint64_t)){ + perror("Failed to write data"); + bail(); + return -1; + } + + //Exit safely + bail(); + return 0; +} + +void bail(){ + if(src != NULL){ + (void)fclose(src); + } + if(dest != -1){ + (void)close(dest); + } + if(line != NULL){ + free(line); + } +}