Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timer rollover is over1000 years #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 18 additions & 26 deletions src/dsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ actionTable_t *table = NULL;

int main(int argc, char *argv[])
{
printf("hello, w\n");

if (initTimer() == 1){
printf("init timer failed\n");
fprintf(stderr, "init timer failed\n");
_exit(2);
};

Expand All @@ -61,10 +59,8 @@ int main(int argc, char *argv[])
}

if (signal(SIGINT, sig_handler) == SIG_ERR){
printf("Signal handler failed\n");
}

printf("hello, world!\n");
fprintf(stderr, "Signal handler failed\n");
}

if (argc != 2) {
printf("USAGE: dsp ACTIONTABLEFILE\n");
Expand All @@ -74,7 +70,7 @@ int main(int argc, char *argv[])
FILE *fp;
fp = fopen(argv[1], "r");
if (fp == NULL) {
printf("Could not open file %s\n", argv[1]);
fprintf(stderr, "Could not open file %s\n", argv[1]);
_exit(2);
}

Expand All @@ -90,7 +86,7 @@ int main(int argc, char *argv[])
table = malloc(sizeof(actionTable_t)*lines);

if (readActionTable(fp, lines) != 0){
printf("Failed to read action table file.\n");
fprintf(stderr, "Failed to read action table file.\n");
_exit(3);
}
printf("read action table file.\n");
Expand All @@ -102,13 +98,13 @@ int main(int argc, char *argv[])
struct sched_param params;
params.sched_priority = 99;
if (sched_setscheduler(0, SCHED_FIFO, &params) == -1){
printf("Failed to set priority.\n");
fprintf(stderr, "Failed to set priority.\n");
_exit(4);
}

int execstatus = execActionTable(lines);
if (execstatus < 0) {
printf("Failed to exec action table (%i).\n", execstatus);
fprintf(stderr, "Failed to exec action table (%i).\n", execstatus);
_exit(5);
}
printf("exec action table done.\n");
Expand All @@ -128,12 +124,12 @@ int readActionTable(FILE *fp, long lines) {
for (lineno = 0; lineno < lines; lineno++){
bytes_read = getline(&linestr, &linelen, fp);
if (bytes_read <= 0){
printf("read %lu lines of action table, but was empty\n", lineno);
fprintf(stderr, "read %lu lines of action table, but was empty\n", lineno);
free(linestr);
return -1;
}
if (readActionTableLine(linestr, lineno) < 0){
printf("readActionTableLine failed on %lu\n", lineno);
fprintf(stderr, "readActionTableLine failed on %lu\n", lineno);
free(linestr);
return -1;
}
Expand All @@ -154,27 +150,27 @@ int readActionTableLine(char *line, long lineno){

nstime_s = strtok(line, DELIM); // REMINDER: first strtok call needs the str.
if (nstime_s == NULL){
printf("action nstime is NULL for '%s'\n", line);
fprintf(stderr, "action nstime is NULL for '%s'\n", line);
return -1;
}
pinP_s = strtok(NULL, DELIM);
if (pinP_s == NULL){
printf("pinP is NULL for %s\n", line);
fprintf(stderr,"pinP is NULL for %s\n", line);
return -1;
}
pinN_s = strtok(NULL, DELIM);
if (pinN_s == NULL){
printf("pinN is NULL for %s\n", line);
fprintf(stderr,"pinN is NULL for %s\n", line);
return -1;
}
a1_s = strtok(NULL, DELIM);
if (a1_s == NULL){
printf("a1_s is NULL for %s", line);
fprintf(stderr,"a1_s is NULL for %s", line);
return -1;
}
a2_s = strtok(NULL, DELIM);
if (a2_s == NULL){
printf("a2_s is NULL for %s", line);
fprintf(stderr,"a2_s is NULL for %s", line);
return -1;
}
table[lineno].clocks = (strtoull(nstime_s, NULL, 10) * COUNTS_PER_SECOND) / 1000000000L;
Expand All @@ -190,20 +186,16 @@ int readActionTableLine(char *line, long lineno){
int execActionTable(long lines) {
printf("exec action table\n");
// float a_volts = 0;
// rp_GenWaveform(RP_CH_1, RP_WAVEFORM_DC);
// rp_GenWaveform(RP_CH_1, RP_WAVEFORM_DC);
// rp_GenWaveform(RP_CH_2, RP_WAVEFORM_DC);
// rp_GenAmp(RP_CH_1, a_volts);
// rp_GenAmp(RP_CH_2, a_volts);
// rp_GenOutEnable(RP_CH_1);
// rp_GenOutEnable(RP_CH_2);

printf("faffing with actiontables\n");
XTime now;

printf("set time\n");

long line;
XTime_SetTime(0);

XTime_GetTime(&now);
for (line = 0; line < lines; line++){
while (now <= table[line].clocks) XTime_GetTime(&now);
Expand All @@ -218,8 +210,8 @@ int execActionTable(long lines) {


void sig_handler(int signo){
if (signo == SIGINT)
_exit(5);
if (signo == SIGINT)
_exit(5);
}

void _exit(int status) {
Expand Down