1
0
mirror of git://projects.qi-hardware.com/ben-wpan.git synced 2024-12-22 23:17:22 +02:00

libatrf: added HardMAC functions

This function set isn't really usable for real communication. Its main
purpose is to help with testing the firmware.

- tools/lib/driver.h (struct atrf_driver): added driver functions for
  HardMAC access
- tools/include/atrf.h (atrf_rx_mode, atrf_rx, atrf_tx),
  tools/lib/atrf.c: functions to enable/disable HardMAC mode and to
  send/receive frames
This commit is contained in:
Werner Almesberger 2011-07-12 12:03:12 -03:00
parent c1071309d8
commit 862b554e2d
6 changed files with 44 additions and 17 deletions

View File

@ -157,8 +157,8 @@ uint8_t irq_serial;
ISR(INT0_vect)
{
if (mac_irq) {
mac_irq();
return;
if (mac_irq())
return;
}
if (eps[1].state == EP_IDLE) {
led(1);

View File

@ -20,7 +20,7 @@
#include "mac.h"
void (*mac_irq)(void) = NULL;
int (*mac_irq)(void) = NULL;
static uint8_t rx_buf[MAX_PSDU+2]; /* PHDR+payload+LQ */
@ -51,35 +51,30 @@ static void reg_write(uint8_t reg, uint8_t value)
}
static void handle_irq(void)
static int handle_irq(void)
{
uint8_t irq;
uint8_t size, i;
irq = reg_read(REG_IRQ_STATUS);
if (!(irq & IRQ_TRX_END))
return;
/*
* @@@ we probably also have to handle at least IRQ_PLL_UNLOCK, because
* a PLL unlock should cause a transition out of BUSY_TX without
* TRX_END.
*/
if (txing) {
txing = 0;
return;
return 0;
}
irq = reg_read(REG_IRQ_STATUS);
if (!(irq & IRQ_TRX_END))
return 1;
/* unlikely */
if (eps[1].state != EP_IDLE)
return;
return 1;
spi_begin();
spi_send(AT86RF230_BUF_READ);
size = spi_recv();
if (size & 0x80) {
spi_end();
return;
return 1;
}
rx_buf[0] = size;
@ -87,6 +82,7 @@ static void handle_irq(void)
rx_buf[i+1] = spi_recv();
spi_end();
usb_send(&eps[1], rx_buf, size+2, NULL, NULL);
return 1;
}

View File

@ -16,7 +16,7 @@
#include <stdint.h>
extern void (*mac_irq)(void);
extern int (*mac_irq)(void);
int mac_rx(int on);
int mac_tx(uint16_t flags, uint16_t len);

View File

@ -57,4 +57,10 @@ uint8_t atrf_sram_read(struct atrf_dsc *dsc, uint8_t addr);
int atrf_interrupt_wait(struct atrf_dsc *dsc, int timeout_ms);
/* HardMAC operations */
void atrf_rx_mode(struct atrf_dsc *dsc, int on);
int atrf_rx(struct atrf_dsc *dsc, void *buf, int size, uint8_t *lqi);
void atrf_tx(struct atrf_dsc *dsc, const void *buf, int size);
#endif /* !ATRF_H */

View File

@ -322,3 +322,25 @@ int atrf_interrupt_wait(struct atrf_dsc *dsc, int timeout_ms)
{
return dsc->driver->interrupt_wait(dsc->handle, timeout_ms);
}
void atrf_rx_mode(struct atrf_dsc *dsc, int on)
{
if (dsc->driver->rx_mode)
dsc->driver->rx_mode(dsc->handle, on);
}
int atrf_rx(struct atrf_dsc *dsc, void *buf, int size, uint8_t *lqi)
{
if (!dsc->driver->rx)
return 0;
return dsc->driver->rx(dsc->handle, buf, size, lqi);
}
void atrf_tx(struct atrf_dsc *dsc, const void *buf, int size)
{
if (dsc->driver->tx)
dsc->driver->tx(dsc->handle, buf, size);
}

View File

@ -36,6 +36,9 @@ struct atrf_driver {
void (*sram_write)(void *dsc, uint8_t addr, uint8_t value);
uint8_t (*sram_read)(void *dsc, uint8_t addr);
int (*interrupt_wait)(void *dsc, int timeout_ms);
void (*rx_mode)(void *dsc, int on);
int (*rx)(void *dsc, void *buf, int size, uint8_t *lqi);
void (*tx)(void *dsc, const void *buf, int size);
};