Root/atrf/tools/atspi-trim/atspi-trim.c

Source at commit b7700518d9a2276137e51c7ed8de8373a43007f9 created 10 years 30 days ago.
By Werner Almesberger, atspi-trim: utility to set the crystal trimming capacitors.
1/*
2 * atspi-trim/atspi-trim.c - AF86RF230 oscillator trim utility
3 *
4 * Written 2010 by Werner Almesberger
5 * Copyright 2010 Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#include <stdlib.h>
15#include <stdio.h>
16#include <usb.h>
17#include <sys/time.h>
18
19#include "at86rf230.h"
20#include "atspi/ep0.h"
21#include "atspi.h"
22
23
24static void usage(const char *name)
25{
26    fprintf(stderr, "%s [trim_value]\n", name);
27    exit(1);
28}
29
30
31int main(int argc, const char **argv)
32{
33    usb_dev_handle *dev;
34    int trim = -1;
35    char *end;
36
37    switch (argc) {
38    case 1:
39        break;
40    case 2:
41        trim = strtoul(argv[1], &end, 0);
42        if (*end || trim > 15)
43            usage(*argv);
44        break;
45    default:
46        usage(*argv);
47    }
48
49    dev = atspi_open();
50    if (!dev)
51        return 1;
52
53    if (trim == -1) {
54        trim = atspi_reg_read(dev, REG_XOSC_CTRL) & XTAL_TRIM_MASK;
55        printf("%d (%d.%d pF)\n", trim, trim*3/10, trim*3 % 10);
56    } else {
57        atspi_reg_write(dev, REG_XOSC_CTRL,
58            (XTAL_MODE_INT << XTAL_MODE_SHIFT) | trim);
59    }
60
61    return 0;
62}
63

Archive Download this file



interactive