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 2a245e1ee3b62e9b98b89f9b87732ed865e29764 created 13 years 6 months ago. By Werner Almesberger, Make wait_for_interrupt available to all atspi tools. | |
---|---|
1 | /* |
2 | * lib/misctxrx.c - Miscellaenous transceiver helper functions |
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 <stdint.h> |
15 | #include <stdlib.h> |
16 | #include <stdio.h> |
17 | #include <unistd.h> |
18 | |
19 | #include "at86rf230.h" |
20 | #include "atspi.h" |
21 | #include "misctxrx.h" |
22 | |
23 | |
24 | uint8_t wait_for_interrupt(struct atspi_dsc *dsc, uint8_t wait_for, |
25 | uint8_t ignore, int sleep_us, int timeout) |
26 | { |
27 | uint8_t irq, show; |
28 | |
29 | while (1) { |
30 | while (!atspi_interrupt(dsc)) { |
31 | usleep(sleep_us); |
32 | if (timeout && !--timeout) |
33 | return 0; |
34 | } |
35 | irq = atspi_reg_read(dsc, REG_IRQ_STATUS); |
36 | if (atspi_error(dsc)) |
37 | exit(1); |
38 | if (!irq) |
39 | continue; |
40 | show = irq & ~ignore; |
41 | if ((irq & wait_for) && !show) |
42 | break; |
43 | fprintf(stderr, "IRQ (0x%02x):", irq); |
44 | if (irq & IRQ_PLL_LOCK) |
45 | fprintf(stderr, " PLL_LOCK"); |
46 | if (irq & IRQ_PLL_UNLOCK) |
47 | fprintf(stderr, " PLL_UNLOCK"); |
48 | if (irq & IRQ_RX_START) |
49 | fprintf(stderr, " RX_START"); |
50 | if (irq & IRQ_TRX_END) |
51 | fprintf(stderr, " TRX_END"); |
52 | if (irq & IRQ_TRX_UR) |
53 | fprintf(stderr, " TRX_UR"); |
54 | if (irq & IRQ_BAT_LOW) |
55 | fprintf(stderr, " BAT_LOW"); |
56 | fprintf(stderr, "\n"); |
57 | if (irq & wait_for) |
58 | break; |
59 | } |
60 | return irq; |
61 | } |
62 |