Root/tools/lib/misctxrx.c

Source at commit 1fb05c221dcff657e49cc766e8ff7baa1d3434fc created 8 years 10 months ago.
By Werner Almesberger, misctxrx.c (wait_for_interrupt): let "ignore" control printing more tightly
1/*
2 * lib/misctxrx.c - Miscellaenous transceiver helper functions
3 *
4 * Written 2010-2011 by Werner Almesberger
5 * Copyright 2010-2011 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 <stdint.h>
15#include <stdlib.h>
16#include <stdio.h>
17#include <unistd.h>
18#include <signal.h>
19
20#include "at86rf230.h"
21#include "atrf.h"
22#include "misctxrx.h"
23
24
25static volatile int run = 1;
26
27
28static void die(int sig)
29{
30    run = 0;
31}
32
33
34uint8_t wait_for_interrupt(struct atrf_dsc *dsc, uint8_t wait_for,
35    uint8_t ignore, int sleep_us, int timeout)
36{
37    uint8_t irq = 0, show;
38    void (*old_sig)(int);
39
40    run = 1;
41    old_sig = signal(SIGINT, die);
42    while (run) {
43        while (run && !atrf_interrupt(dsc)) {
44            usleep(sleep_us);
45            if (timeout && !--timeout) {
46                irq = 0;
47                goto out;
48            }
49        }
50        irq = atrf_reg_read(dsc, REG_IRQ_STATUS);
51        if (atrf_error(dsc))
52            exit(1);
53        if (!irq)
54            continue;
55        show = irq & ~ignore;
56        if (!show) {
57            if (irq & wait_for)
58                break;
59            continue;
60        }
61        fprintf(stderr, "IRQ (0x%02x):", irq);
62        if (irq & IRQ_PLL_LOCK)
63            fprintf(stderr, " PLL_LOCK");
64        if (irq & IRQ_PLL_UNLOCK)
65            fprintf(stderr, " PLL_UNLOCK");
66        if (irq & IRQ_RX_START)
67            fprintf(stderr, " RX_START");
68        if (irq & IRQ_TRX_END)
69            fprintf(stderr, " TRX_END");
70        if (irq & IRQ_CCA_ED_DONE)
71            fprintf(stderr, " CCA_ED_DONE");
72        if (irq & IRQ_AMI)
73            fprintf(stderr, " AMI");
74        if (irq & IRQ_TRX_UR)
75            fprintf(stderr, " TRX_UR");
76        if (irq & IRQ_BAT_LOW)
77            fprintf(stderr, " BAT_LOW");
78        fprintf(stderr, "\n");
79        if (irq & wait_for)
80            break;
81    }
82out:
83    signal(SIGINT, old_sig);
84    if (!run)
85        raise(SIGINT);
86    return irq;
87}
88

Archive Download this file



interactive