1
0
mirror of git://projects.qi-hardware.com/ben-wpan.git synced 2024-11-26 04:56:16 +02:00

tools/: add timeout_ms argument to atrf_rx

This commit is contained in:
Werner Almesberger 2013-02-12 16:19:09 -03:00
parent 125cc6ad9f
commit 8ac87a3fa1
6 changed files with 18 additions and 14 deletions

View File

@ -299,7 +299,7 @@ static void receive_hmac(struct atrf_dsc *dsc)
int n, i; int n, i;
atrf_rx_mode(dsc, 1); atrf_rx_mode(dsc, 1);
n = atrf_rx(dsc, buf, sizeof(buf), &lqi); n = atrf_rx(dsc, buf, sizeof(buf), 0, &lqi);
atrf_rx_mode(dsc, 0); atrf_rx_mode(dsc, 0);
if (n < 2) { if (n < 2) {

View File

@ -60,7 +60,8 @@ int atrf_interrupt_wait(struct atrf_dsc *dsc, int timeout_ms);
/* HardMAC operations */ /* HardMAC operations */
void atrf_rx_mode(struct atrf_dsc *dsc, int on); void atrf_rx_mode(struct atrf_dsc *dsc, int on);
int atrf_rx(struct atrf_dsc *dsc, void *buf, int size, uint8_t *lqi); int atrf_rx(struct atrf_dsc *dsc, void *buf, int size, int timeout_ms,
uint8_t *lqi);
void atrf_tx(struct atrf_dsc *dsc, const void *buf, int size); void atrf_tx(struct atrf_dsc *dsc, const void *buf, int size);
#endif /* !ATRF_H */ #endif /* !ATRF_H */

View File

@ -1,8 +1,8 @@
/* /*
* lib/atrf.c - ATRF access functions library * lib/atrf.c - ATRF access functions library
* *
* Written 2010-2011 by Werner Almesberger * Written 2010-2011, 2013 by Werner Almesberger
* Copyright 2010-2011 Werner Almesberger * Copyright 2010-2011, 2013 Werner Almesberger
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -331,11 +331,12 @@ void atrf_rx_mode(struct atrf_dsc *dsc, int on)
} }
int atrf_rx(struct atrf_dsc *dsc, void *buf, int size, uint8_t *lqi) int atrf_rx(struct atrf_dsc *dsc, void *buf, int size, int timeout_ms,
uint8_t *lqi)
{ {
if (!dsc->driver->rx) if (!dsc->driver->rx)
return 0; return 0;
return dsc->driver->rx(dsc->handle, buf, size, lqi); return dsc->driver->rx(dsc->handle, buf, size, timeout_ms, lqi);
} }

View File

@ -297,7 +297,7 @@ void atusb_rx_mode(void *handle, int on)
} }
int atusb_rx(void *handle, void *buf, int size, uint8_t *lqi) int atusb_rx(void *handle, void *buf, int size, int timeout_ms, uint8_t *lqi)
{ {
struct atusb_dsc *dsc = handle; struct atusb_dsc *dsc = handle;
uint8_t len; uint8_t len;
@ -309,7 +309,9 @@ int atusb_rx(void *handle, void *buf, int size, uint8_t *lqi)
* read of size one followed by the full read. Therefore, we just do * read of size one followed by the full read. Therefore, we just do
* a maximum-sized read and hope that we don't split packets. * a maximum-sized read and hope that we don't split packets.
*/ */
res = usb_bulk_read(dsc->dev, 1, (char *) tmp, sizeof(tmp), 0); res = usb_bulk_read(dsc->dev, 1, (char *) tmp, sizeof(tmp), timeout_ms);
if (res == -ETIMEDOUT)
return 0;
if (res < 0) { if (res < 0) {
fprintf(stderr, "usb_bulk_read: %d\n", res); fprintf(stderr, "usb_bulk_read: %d\n", res);
dsc->error = 1; dsc->error = 1;

View File

@ -1,8 +1,8 @@
/* /*
* lib/atusb-common.h - ATUSB access functions shared by all ATUSB drivers * lib/atusb-common.h - ATUSB access functions shared by all ATUSB drivers
* *
* Written 2010-2011 by Werner Almesberger * Written 2010-2011, 2013 by Werner Almesberger
* Copyright 2010-2011 Werner Almesberger * Copyright 2010-2011, 2013 Werner Almesberger
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -35,7 +35,7 @@ void atusb_test_mode(void *handle);
void atusb_slp_tr(void *handle, int on, int pulse); void atusb_slp_tr(void *handle, int on, int pulse);
int atusb_interrupt_wait(void *handle, int timeout_ms); int atusb_interrupt_wait(void *handle, int timeout_ms);
void atusb_rx_mode(void *handle, int on); void atusb_rx_mode(void *handle, int on);
int atusb_rx(void *handle, void *buf, int size, uint8_t *lqi); int atusb_rx(void *handle, void *buf, int size, int timeout_ms, uint8_t *lqi);
void atusb_tx(void *handle, const void *buf, int size); void atusb_tx(void *handle, const void *buf, int size);
int atusb_set_clkm(void *handle, int mhz); int atusb_set_clkm(void *handle, int mhz);

View File

@ -1,8 +1,8 @@
/* /*
* lib/driver.h - ATRF driver API * lib/driver.h - ATRF driver API
* *
* Written 2010-2011 by Werner Almesberger * Written 2010-2011, 2013 by Werner Almesberger
* Copyright 2010-2011 Werner Almesberger * Copyright 2010-2011, 2013 Werner Almesberger
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -37,7 +37,7 @@ struct atrf_driver {
uint8_t (*sram_read)(void *dsc, uint8_t addr); uint8_t (*sram_read)(void *dsc, uint8_t addr);
int (*interrupt_wait)(void *dsc, int timeout_ms); int (*interrupt_wait)(void *dsc, int timeout_ms);
void (*rx_mode)(void *dsc, int on); void (*rx_mode)(void *dsc, int on);
int (*rx)(void *dsc, void *buf, int size, uint8_t *lqi); int (*rx)(void *dsc, void *buf, int size, int timeout_ms, uint8_t *lqi);
void (*tx)(void *dsc, const void *buf, int size); void (*tx)(void *dsc, const void *buf, int size);
}; };