mirror of
git://projects.qi-hardware.com/ben-wpan.git
synced 2024-11-26 12:16:14 +02:00
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
This commit is contained in:
parent
be624169a9
commit
2a245e1ee3
@ -11,14 +11,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "at86rf230.h"
|
#include "at86rf230.h"
|
||||||
#include "atspi/ep0.h"
|
|
||||||
#include "atspi.h"
|
#include "atspi.h"
|
||||||
|
#include "misctxrx.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -69,46 +70,6 @@ static struct atspi_dsc *init_txrx(int trim)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static uint8_t wait_for_interrupt(struct atspi_dsc *dsc, uint8_t wait_for,
|
|
||||||
uint8_t ignore, int sleep_us, int timeout)
|
|
||||||
{
|
|
||||||
uint8_t irq, show;
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
while (!atspi_interrupt(dsc)) {
|
|
||||||
usleep(sleep_us);
|
|
||||||
if (timeout && !--timeout)
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
irq = atspi_reg_read(dsc, REG_IRQ_STATUS);
|
|
||||||
if (atspi_error(dsc))
|
|
||||||
exit(1);
|
|
||||||
if (!irq)
|
|
||||||
continue;
|
|
||||||
show = irq & ~ignore;
|
|
||||||
if ((irq & wait_for) && !show)
|
|
||||||
break;
|
|
||||||
fprintf(stderr, "IRQ (0x%02x):", irq);
|
|
||||||
if (irq & IRQ_PLL_LOCK)
|
|
||||||
fprintf(stderr, " PLL_LOCK");
|
|
||||||
if (irq & IRQ_PLL_UNLOCK)
|
|
||||||
fprintf(stderr, " PLL_UNLOCK");
|
|
||||||
if (irq & IRQ_RX_START)
|
|
||||||
fprintf(stderr, " RX_START");
|
|
||||||
if (irq & IRQ_TRX_END)
|
|
||||||
fprintf(stderr, " TRX_END");
|
|
||||||
if (irq & IRQ_TRX_UR)
|
|
||||||
fprintf(stderr, " TRX_UR");
|
|
||||||
if (irq & IRQ_BAT_LOW)
|
|
||||||
fprintf(stderr, " BAT_LOW");
|
|
||||||
fprintf(stderr, "\n");
|
|
||||||
if (irq & wait_for)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return irq;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void set_channel(struct atspi_dsc *dsc, int channel)
|
static void set_channel(struct atspi_dsc *dsc, int channel)
|
||||||
{
|
{
|
||||||
atspi_reg_write(dsc, REG_PHY_CC_CCA, (1 << CCA_MODE_SHIFT) | channel);
|
atspi_reg_write(dsc, REG_PHY_CC_CCA, (1 << CCA_MODE_SHIFT) | channel);
|
||||||
|
24
tools/include/misctxrx.h
Normal file
24
tools/include/misctxrx.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* include/misctxrx.h - Miscellaenous transceiver helper functions
|
||||||
|
*
|
||||||
|
* Written 2010 by Werner Almesberger
|
||||||
|
* Copyright 2010 Werner Almesberger
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MISCTXRX_H
|
||||||
|
#define MISCTXRX_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "atspi.h"
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t wait_for_interrupt(struct atspi_dsc *dsc, uint8_t wait_for,
|
||||||
|
uint8_t ignore, int sleep_us, int timeout);
|
||||||
|
|
||||||
|
#endif /* !MISCTXRX_H */
|
@ -18,7 +18,7 @@ include ../Makefile.common
|
|||||||
CFLAGS += -Wall -I$(F32XBASE)/include
|
CFLAGS += -Wall -I$(F32XBASE)/include
|
||||||
OBJS_host = atusb.o $(F32XBASE)/lib/usb.o
|
OBJS_host = atusb.o $(F32XBASE)/lib/usb.o
|
||||||
OBJS_ben = atusd.o
|
OBJS_ben = atusd.o
|
||||||
OBJS = atspi.o $(OBJS_$(TARGET))
|
OBJS = atspi.o misctxrx.o $(OBJS_$(TARGET))
|
||||||
|
|
||||||
.PHONY: all clean spotless
|
.PHONY: all clean spotless
|
||||||
|
|
||||||
|
61
tools/lib/misctxrx.c
Normal file
61
tools/lib/misctxrx.c
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* lib/misctxrx.c - Miscellaenous transceiver helper functions
|
||||||
|
*
|
||||||
|
* Written 2010 by Werner Almesberger
|
||||||
|
* Copyright 2010 Werner Almesberger
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "at86rf230.h"
|
||||||
|
#include "atspi.h"
|
||||||
|
#include "misctxrx.h"
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t wait_for_interrupt(struct atspi_dsc *dsc, uint8_t wait_for,
|
||||||
|
uint8_t ignore, int sleep_us, int timeout)
|
||||||
|
{
|
||||||
|
uint8_t irq, show;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
while (!atspi_interrupt(dsc)) {
|
||||||
|
usleep(sleep_us);
|
||||||
|
if (timeout && !--timeout)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
irq = atspi_reg_read(dsc, REG_IRQ_STATUS);
|
||||||
|
if (atspi_error(dsc))
|
||||||
|
exit(1);
|
||||||
|
if (!irq)
|
||||||
|
continue;
|
||||||
|
show = irq & ~ignore;
|
||||||
|
if ((irq & wait_for) && !show)
|
||||||
|
break;
|
||||||
|
fprintf(stderr, "IRQ (0x%02x):", irq);
|
||||||
|
if (irq & IRQ_PLL_LOCK)
|
||||||
|
fprintf(stderr, " PLL_LOCK");
|
||||||
|
if (irq & IRQ_PLL_UNLOCK)
|
||||||
|
fprintf(stderr, " PLL_UNLOCK");
|
||||||
|
if (irq & IRQ_RX_START)
|
||||||
|
fprintf(stderr, " RX_START");
|
||||||
|
if (irq & IRQ_TRX_END)
|
||||||
|
fprintf(stderr, " TRX_END");
|
||||||
|
if (irq & IRQ_TRX_UR)
|
||||||
|
fprintf(stderr, " TRX_UR");
|
||||||
|
if (irq & IRQ_BAT_LOW)
|
||||||
|
fprintf(stderr, " BAT_LOW");
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
if (irq & wait_for)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return irq;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user