1
0
mirror of git://projects.qi-hardware.com/ben-wpan.git synced 2024-07-01 03:33:17 +03:00

tools/lib/: added HardMAC functions to the atusb drivers

This commit is contained in:
Werner Almesberger 2011-07-12 12:10:48 -03:00
parent 862b554e2d
commit 49d6067e88
4 changed files with 88 additions and 0 deletions

View File

@ -14,6 +14,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <usb.h>
#include <errno.h>
@ -276,6 +277,84 @@ int atusb_set_clkm(void *handle, int mhz)
}
/* ----- HardMAC ----------------------------------------------------------- */
void atusb_rx_mode(void *handle, int on)
{
struct atusb_dsc *dsc = handle;
int res;
if (dsc->error)
return;
res = usb_control_msg(dsc->dev, TO_DEV, ATUSB_RX_MODE,
on, 0, NULL, 0, 1000);
if (res < 0) {
fprintf(stderr, "ATUSB_RX_MODE: %d\n", res);
dsc->error = 1;
}
}
int atusb_rx(void *handle, void *buf, int size, uint8_t *lqi)
{
struct atusb_dsc *dsc = handle;
uint8_t len;
int res;
uint8_t tmp[MAX_PSDU+2]; /* PHR, LQI */
/*
* Seems that either the USB stack of libusb doesn't like it if we do a
* 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.
*/
res = usb_bulk_read(dsc->dev, 1, (char *) tmp, sizeof(tmp), 0);
if (res < 0) {
fprintf(stderr, "usb_bulk_read: %d\n", res);
dsc->error = 1;
return 0;
}
len = tmp[0];
if (len & 0x80) {
fprintf(stderr, "atusb_rx: invalid length 0x%02x\n", len);
return 0;
}
if (len > size) {
fprintf(stderr, "atusb_rx: len %u > size %d\n", len, size);
return 0;
}
if (len > res+2) {
fprintf(stderr, "atusb_rx: len %u > res %d+2\n", len, res);
return 0;
}
memcpy(buf, tmp+1, len);
if (lqi)
*lqi = tmp[len+1];
return len;
}
void atusb_tx(void *handle, const void *buf, int size)
{
struct atusb_dsc *dsc = handle;
int res;
if (dsc->error)
return;
res = usb_control_msg(dsc->dev, TO_DEV, ATUSB_TX,
0, 0, (void *) buf, size, 1000);
if (res < 0) {
fprintf(stderr, "ATUSB_TX: %d\n", res);
dsc->error = 1;
}
}
/* ----- Driver-specific hacks --------------------------------------------- */

View File

@ -34,6 +34,9 @@ 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_wait(void *handle, int timeout_ms);
void atusb_rx_mode(void *handle, int on);
int atusb_rx(void *handle, void *buf, int size, uint8_t *lqi);
void atusb_tx(void *handle, const void *buf, int size);
int atusb_set_clkm(void *handle, int mhz);

View File

@ -168,4 +168,7 @@ struct atrf_driver atusb_spi_driver = {
.sram_write = atusb_spi_sram_write,
.sram_read = atusb_spi_sram_read,
.interrupt_wait = atusb_interrupt_wait,
.rx_mode = atusb_rx_mode,
.rx = atusb_rx,
.tx = atusb_tx,
};

View File

@ -162,4 +162,7 @@ struct atrf_driver atusb_driver = {
.sram_write = atusb_sram_write,
.sram_read = atusb_sram_read,
.interrupt_wait = atusb_interrupt_wait,
.rx_mode = atusb_rx_mode,
.rx = atusb_rx,
.tx = atusb_tx,
};