* Add C Program to write configuration
This commit is contained in:
parent
a5c68d1fea
commit
c60bcd97f6
13
sw/config
Normal file
13
sw/config
Normal file
@ -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
|
||||
BIN
sw/write_config
Executable file
BIN
sw/write_config
Executable file
Binary file not shown.
89
sw/write_config.c
Normal file
89
sw/write_config.c
Normal file
@ -0,0 +1,89 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user