Commit 97a11be1 authored by Alessandro Rubini's avatar Alessandro Rubini

tools: added fd-raw-settime

parent d68573e4
fd-raw-input
parport-burst
fd-raw-gettime
fd-raw-settime
......@@ -6,6 +6,7 @@ HOSTCC ?= gcc
hostprogs-y := fd-raw-input
hostprogs-y += fd-raw-gettime
hostprogs-y += fd-raw-settime
hostprogs-y += parport-burst
# we are not in the kernel, so we need to piggy-back on "make modules"
......@@ -19,4 +20,4 @@ module_install:
# we need this as we are out of the kernel
%: %.c
$(HOSTCC) $(HOST_EXTRACFLAGS) -Wall $^ -o $@
$(HOSTCC) $(HOST_EXTRACFLAGS) -O2 -Wall $^ -o $@
/*
* a tool to set the fdelay time through sysfs
*
* Copyright (C) 2012 CERN (www.cern.ch)
* Author: Alessandro Rubini <rubini@gnudd.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2 as published by the Free Software Foundation or, at your
* option, any later version.
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <glob.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/select.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/zio.h>
#include <linux/zio-user.h>
#include <fine-delay.h>
#include "fdelay-raw.h"
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
struct time_word {
uint32_t val;
char *name;
};
struct time_word words[] = {
{0, "coarse"},
{0, "utc-l"},
{0, "utc-h"}, /* This must be last, as this forces hardware access */
};
int main(int argc, char **argv)
{
char *sysnames[10];
char path[80];
int i, err;
if (argc < 2 || argc > 3) {
fprintf(stderr, "%s: Use \"%s <sec> [<nsec>]\"\n",
argv[0], argv[0]);
exit(1);
}
i = fdelay_get_sysnames(sysnames);
if (!i) {
fprintf(stderr, "%s: no fine-delay devices\n", argv[0]);
exit(1);
}
if (i > 1) {
fprintf(stderr, "%s: several fine-delay devices, using %s\n",
argv[0], sysnames[0]);
}
words[0].val = 0;
words[1].val = atoi(argv[1]); /* FIXME: error check */
words[2].val = 0;
if (argc == 3)
words[0].val = atoi(argv[2]) / 8; /* FIXME: error check */
for (i = 0, err = 0; i < ARRAY_SIZE(words); i++) {
sprintf(path, "%s/%s", sysnames[0], words[i].name);
if (fdelay_sysfs_set(path, &words[i].val) != 0)
err++;
}
if (err) {
fprintf(stderr, "%s: got %i errors writing %i attributes\n",
argv[0], err, ARRAY_SIZE(words));
}
return 0;
}
......@@ -29,3 +29,18 @@ static inline int fdelay_sysfs_get(char *path, uint32_t *resp)
fclose(f);
return 0;
}
static inline int fdelay_sysfs_set(char *path, uint32_t *value)
{
FILE *f = fopen(path, "w");
if (!f)
return -1;
if (fprintf(f, "%i\n", *value) < 2) {
fclose(f);
errno = EINVAL;
return -1;
}
fclose(f);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment