Date:2011-07-12 17:03:12 (9 years 1 month ago)
Author:Werner Almesberger
Commit:862b554e2d5d3b00c9d2669ac57484c0cf3e4982
Message: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
Files: atusb/fw/board_app.c (1 diff)
atusb/fw/mac.c (3 diffs)
atusb/fw/mac.h (1 diff)
tools/include/atrf.h (1 diff)
tools/lib/atrf.c (1 diff)
tools/lib/driver.h (1 diff)

Change Details

atusb/fw/board_app.c
157157ISR(INT0_vect)
158158{
159159    if (mac_irq) {
160        mac_irq();
161        return;
160        if (mac_irq())
161            return;
162162    }
163163    if (eps[1].state == EP_IDLE) {
164164        led(1);
atusb/fw/mac.c
2020#include "mac.h"
2121
2222
23void (*mac_irq)(void) = NULL;
23int (*mac_irq)(void) = NULL;
2424
2525
2626static uint8_t rx_buf[MAX_PSDU+2]; /* PHDR+payload+LQ */
...... 
5151}
5252
5353
54static void handle_irq(void)
54static int handle_irq(void)
5555{
5656    uint8_t irq;
5757    uint8_t size, i;
5858
59    irq = reg_read(REG_IRQ_STATUS);
60    if (!(irq & IRQ_TRX_END))
61        return;
62
63    /*
64     * @@@ we probably also have to handle at least IRQ_PLL_UNLOCK, because
65     * a PLL unlock should cause a transition out of BUSY_TX without
66     * TRX_END.
67     */
6859    if (txing) {
6960        txing = 0;
70        return;
61        return 0;
7162    }
7263
64    irq = reg_read(REG_IRQ_STATUS);
65    if (!(irq & IRQ_TRX_END))
66        return 1;
67
7368    /* unlikely */
7469    if (eps[1].state != EP_IDLE)
75        return;
70        return 1;
7671
7772    spi_begin();
7873    spi_send(AT86RF230_BUF_READ);
7974    size = spi_recv();
8075    if (size & 0x80) {
8176        spi_end();
82        return;
77        return 1;
8378    }
8479
8580    rx_buf[0] = size;
...... 
8782        rx_buf[i+1] = spi_recv();
8883    spi_end();
8984    usb_send(&eps[1], rx_buf, size+2, NULL, NULL);
85    return 1;
9086}
9187
9288
atusb/fw/mac.h
1616#include <stdint.h>
1717
1818
19extern void (*mac_irq)(void);
19extern int (*mac_irq)(void);
2020
2121int mac_rx(int on);
2222int mac_tx(uint16_t flags, uint16_t len);
tools/include/atrf.h
5757
5858int atrf_interrupt_wait(struct atrf_dsc *dsc, int timeout_ms);
5959
60/* HardMAC operations */
61
62void atrf_rx_mode(struct atrf_dsc *dsc, int on);
63int atrf_rx(struct atrf_dsc *dsc, void *buf, int size, uint8_t *lqi);
64void atrf_tx(struct atrf_dsc *dsc, const void *buf, int size);
65
6066#endif /* !ATRF_H */
tools/lib/atrf.c
322322{
323323    return dsc->driver->interrupt_wait(dsc->handle, timeout_ms);
324324}
325
326
327void atrf_rx_mode(struct atrf_dsc *dsc, int on)
328{
329    if (dsc->driver->rx_mode)
330        dsc->driver->rx_mode(dsc->handle, on);
331}
332
333
334int atrf_rx(struct atrf_dsc *dsc, void *buf, int size, uint8_t *lqi)
335{
336    if (!dsc->driver->rx)
337        return 0;
338    return dsc->driver->rx(dsc->handle, buf, size, lqi);
339}
340
341
342void atrf_tx(struct atrf_dsc *dsc, const void *buf, int size)
343{
344    if (dsc->driver->tx)
345        dsc->driver->tx(dsc->handle, buf, size);
346}
tools/lib/driver.h
3636    void (*sram_write)(void *dsc, uint8_t addr, uint8_t value);
3737    uint8_t (*sram_read)(void *dsc, uint8_t addr);
3838    int (*interrupt_wait)(void *dsc, int timeout_ms);
39    void (*rx_mode)(void *dsc, int on);
40    int (*rx)(void *dsc, void *buf, int size, uint8_t *lqi);
41    void (*tx)(void *dsc, const void *buf, int size);
3942};
4043
4144

Archive Download the corresponding diff file



interactive