mirror of
git://projects.qi-hardware.com/ben-wpan.git
synced 2024-11-05 06:58:06 +02:00
tools/lib/: added interrupt_wait support to atusb and atusb-spi driver
- atusb-common.c (atusb_open): claim interface, so that we can do bulk I/O without complaints from the kernel - atusb-common.h (atusb_interrupt_wait), atusb-common.c: blocking read for interrupt status byte on EP1 - atusb.c (atusb_driver), atusb-spi.c (atusb_spi_driver): provide the interrupt_wait operation
This commit is contained in:
parent
e6f0a1d410
commit
110ecf67a1
@ -15,10 +15,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <usb.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "atusb/ep0.h"
|
||||
#include "atusb/usb-ids.h"
|
||||
|
||||
#include "at86rf230.h"
|
||||
#include "usbopen.h"
|
||||
#include "driver.h"
|
||||
#include "atusb-common.h"
|
||||
@ -53,6 +55,7 @@ void *atusb_open(const char *arg)
|
||||
{
|
||||
usb_dev_handle *dev;
|
||||
struct atusb_dsc *dsc;
|
||||
int res;
|
||||
|
||||
usb_unrestrict();
|
||||
if (arg)
|
||||
@ -63,6 +66,12 @@ void *atusb_open(const char *arg)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
res = usb_claim_interface(dev, 0);
|
||||
if (res) {
|
||||
fprintf(stderr, "usb_claim_interface: %d\n", res);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dsc = malloc(sizeof(*dsc));
|
||||
if (!dsc) {
|
||||
perror("malloc");
|
||||
@ -186,6 +195,64 @@ int atusb_interrupt(void *handle)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* The logic here is a bit tricky. Assuming that we can get a lot of
|
||||
* interrupts, system state can change as follows:
|
||||
*
|
||||
* Event IRQ_STATUS EP1 on atusb EP1 on host irq
|
||||
* INT (var)
|
||||
* -------------------- ------- --- ------------ ----------- -----
|
||||
* interrupt A A H EP_IDLE - -
|
||||
* INT0 handler - - EP_TX (A) - -
|
||||
* interrupt B B H EP_TX (A) - -
|
||||
* INT0 handler B H EP_TX (A) - -
|
||||
* IN from host B H EP_IDLE A -
|
||||
* interrupt C B+C H EP_IDLE A -
|
||||
* call to atusb_interrupt_wait
|
||||
* read IRQ_STATUS - - EP_IDLE A B+C
|
||||
* interrupt D D H EP_IDLE A B+C
|
||||
* INT0 handler - - EP_TX (D) A B+C
|
||||
* IN from host - - EP_IDLE A, D B+C
|
||||
* usb_bulk_read - - EP_IDLE - A+B+C+D
|
||||
* usb_bulk_read -> no more data, done
|
||||
*
|
||||
* We therefore have to consider interrupts queued up at the host and pending
|
||||
* in REG_IRQ_STATUS in addition to anything that may arrive while we wait.
|
||||
*/
|
||||
|
||||
|
||||
int atusb_interrupt_wait(void *handle, int timeout_ms)
|
||||
{
|
||||
struct atusb_dsc *dsc = handle;
|
||||
uint8_t irq, buf[100];
|
||||
int res, i;
|
||||
|
||||
if (dsc->error)
|
||||
return 0;
|
||||
|
||||
irq = atusb_driver.reg_read(handle, REG_IRQ_STATUS);
|
||||
if (irq)
|
||||
timeout_ms = 1;
|
||||
|
||||
while (1) {
|
||||
res = usb_bulk_read(dsc->dev, 1,
|
||||
(char *) &buf, sizeof(buf), timeout_ms);
|
||||
if (res == -ETIMEDOUT)
|
||||
break;
|
||||
if (res < 0) {
|
||||
fprintf(stderr, "usb_bulk_read: %d\n", res);
|
||||
dsc->error = 1;
|
||||
return 0;
|
||||
/* < 0 is already taken by atrf_interrupt_wait */
|
||||
}
|
||||
timeout_ms = 1;
|
||||
for (i = 0; i != res; i++)
|
||||
irq |= buf[i];
|
||||
}
|
||||
return irq;
|
||||
}
|
||||
|
||||
|
||||
/* ----- CLKM handling ----------------------------------------------------- */
|
||||
|
||||
|
||||
|
@ -34,6 +34,8 @@ void atusb_reset_rf(void *handle);
|
||||
void atusb_test_mode(void *handle);
|
||||
void atusb_slp_tr(void *handle, int on, int pulse);
|
||||
int atusb_interrupt(void *handle);
|
||||
int atusb_interrupt_wait(void *handle, int timeout_ms);
|
||||
|
||||
int atusb_set_clkm(void *handle, int mhz);
|
||||
|
||||
#endif /* !ATUSB_COMMON_H */
|
||||
|
@ -168,4 +168,5 @@ struct atrf_driver atusb_spi_driver = {
|
||||
.sram_write = atusb_spi_sram_write,
|
||||
.sram_read = atusb_spi_sram_read,
|
||||
.interrupt = atusb_interrupt,
|
||||
.interrupt_wait = atusb_interrupt_wait,
|
||||
};
|
||||
|
@ -162,4 +162,5 @@ struct atrf_driver atusb_driver = {
|
||||
.sram_write = atusb_sram_write,
|
||||
.sram_read = atusb_sram_read,
|
||||
.interrupt = atusb_interrupt,
|
||||
.interrupt_wait = atusb_interrupt_wait,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user