Date:2010-09-09 22:42:47 (9 years 3 months ago)
Author:Werner Almesberger
Commit:2a245e1ee3b62e9b98b89f9b87732ed865e29764
Message:Make wait_for_interrupt available to all atspi tools.

- tools/atspi-txrx/atspi-txrx.c: cleaned up includes - we need stdint.h but
we don't need atspi/ep0.h
- tools/atspi-txrx/atspi-txrx.c (wait_for_interrupt),
tools/include/misctxrx.h (wait_for_interrupt), tools/lib/Makefile (OBJS),
tools/lib/misctxrx.c (wait_for_interrupt): moved wait_for_interrupt from
atspi-txrx to the atspi library, so that we can share it
Files: tools/atspi-txrx/atspi-txrx.c (2 diffs)
tools/include/misctxrx.h (1 diff)
tools/lib/Makefile (1 diff)
tools/lib/misctxrx.c (1 diff)

Change Details

tools/atspi-txrx/atspi-txrx.c
1111 */
1212
1313
14#include <stdint.h>
1415#include <stdlib.h>
1516#include <stdio.h>
1617#include <unistd.h>
1718#include <string.h>
1819
1920#include "at86rf230.h"
20#include "atspi/ep0.h"
2121#include "atspi.h"
22#include "misctxrx.h"
2223
2324
2425/*
...... 
6970}
7071
7172
72static uint8_t wait_for_interrupt(struct atspi_dsc *dsc, uint8_t wait_for,
73    uint8_t ignore, int sleep_us, int timeout)
74{
75    uint8_t irq, show;
76
77    while (1) {
78        while (!atspi_interrupt(dsc)) {
79            usleep(sleep_us);
80            if (timeout && !--timeout)
81                return 0;
82        }
83        irq = atspi_reg_read(dsc, REG_IRQ_STATUS);
84        if (atspi_error(dsc))
85            exit(1);
86        if (!irq)
87            continue;
88        show = irq & ~ignore;
89        if ((irq & wait_for) && !show)
90            break;
91        fprintf(stderr, "IRQ (0x%02x):", irq);
92        if (irq & IRQ_PLL_LOCK)
93            fprintf(stderr, " PLL_LOCK");
94        if (irq & IRQ_PLL_UNLOCK)
95            fprintf(stderr, " PLL_UNLOCK");
96        if (irq & IRQ_RX_START)
97            fprintf(stderr, " RX_START");
98        if (irq & IRQ_TRX_END)
99            fprintf(stderr, " TRX_END");
100        if (irq & IRQ_TRX_UR)
101            fprintf(stderr, " TRX_UR");
102        if (irq & IRQ_BAT_LOW)
103            fprintf(stderr, " BAT_LOW");
104        fprintf(stderr, "\n");
105        if (irq & wait_for)
106            break;
107    }
108    return irq;
109}
110
111
11273static void set_channel(struct atspi_dsc *dsc, int channel)
11374{
11475    atspi_reg_write(dsc, REG_PHY_CC_CCA, (1 << CCA_MODE_SHIFT) | channel);
tools/include/misctxrx.h
1/*
2 * include/misctxrx.h - 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#ifndef MISCTXRX_H
14#define MISCTXRX_H
15
16#include <stdint.h>
17
18#include "atspi.h"
19
20
21uint8_t wait_for_interrupt(struct atspi_dsc *dsc, uint8_t wait_for,
22    uint8_t ignore, int sleep_us, int timeout);
23
24#endif /* !MISCTXRX_H */
tools/lib/Makefile
1818CFLAGS += -Wall -I$(F32XBASE)/include
1919OBJS_host = atusb.o $(F32XBASE)/lib/usb.o
2020OBJS_ben = atusd.o
21OBJS = atspi.o $(OBJS_$(TARGET))
21OBJS = atspi.o misctxrx.o $(OBJS_$(TARGET))
2222
2323.PHONY: all clean spotless
2424
tools/lib/misctxrx.c
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
24uint8_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}

Archive Download the corresponding diff file



interactive