IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Git Source Tree
Root/
Source at commit ebe667197a3c09a1f9b3005efcf7729c8b12da84 created 13 years 2 months ago. By Werner Almesberger, dirtly made the atrf tools run with the new atusd board | |
---|---|
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 | |
25 | static volatile int run = 1; |
26 | |
27 | |
28 | static void die(int sig) |
29 | { |
30 | run = 0; |
31 | } |
32 | |
33 | |
34 | uint8_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 ((irq & wait_for) && !show) |
57 | break; |
58 | fprintf(stderr, "IRQ (0x%02x):", irq); |
59 | if (irq & IRQ_PLL_LOCK) |
60 | fprintf(stderr, " PLL_LOCK"); |
61 | if (irq & IRQ_PLL_UNLOCK) |
62 | fprintf(stderr, " PLL_UNLOCK"); |
63 | if (irq & IRQ_RX_START) |
64 | fprintf(stderr, " RX_START"); |
65 | if (irq & IRQ_TRX_END) |
66 | fprintf(stderr, " TRX_END"); |
67 | if (irq & IRQ_CCA_ED_DONE) |
68 | fprintf(stderr, " CCA_ED_DONE"); |
69 | if (irq & IRQ_AMI) |
70 | fprintf(stderr, " AMI"); |
71 | if (irq & IRQ_TRX_UR) |
72 | fprintf(stderr, " TRX_UR"); |
73 | if (irq & IRQ_BAT_LOW) |
74 | fprintf(stderr, " BAT_LOW"); |
75 | fprintf(stderr, "\n"); |
76 | if (irq & wait_for) |
77 | break; |
78 | } |
79 | out: |
80 | signal(SIGINT, old_sig); |
81 | if (!run) |
82 | raise(SIGINT); |
83 | return irq; |
84 | } |
85 |