mirror of
git://projects.qi-hardware.com/ben-wpan.git
synced 2024-11-22 15:15:18 +02:00
atusb/fw/: added "HardMAC" support (not yet using the TRX's MAC)
- include/atusb/ep0.h (enum atspi_requests), ep0.c (my_setup): added new "HardMAC" requests ATUSB_RX_MODE and ATUSB_TX - mac.h, mac.c: basic "HardMAC" procedure - board_app.c (INT0_vect): call MAC-specific interrupt handler if provided - Makefile (OBJS): added mac.o
This commit is contained in:
parent
e700b81642
commit
c1071309d8
@ -31,7 +31,7 @@ SIZE = $(AVR_PREFIX)size
|
||||
USB_ID = 20b7:1540
|
||||
|
||||
OBJS = atusb.o board.o board_app.o sernum.o spi.o descr.o ep0.o \
|
||||
dfu_common.o usb.o app-atu2.o
|
||||
dfu_common.o usb.o app-atu2.o mac.o
|
||||
BOOT_OBJS = boot.o board.o sernum.o spi.o flash.o dfu.o \
|
||||
dfu_common.o usb.o boot-atu2.o
|
||||
|
||||
|
@ -22,8 +22,9 @@
|
||||
|
||||
#include "usb.h"
|
||||
#include "at86rf230.h"
|
||||
#include "board.h"
|
||||
#include "spi.h"
|
||||
#include "mac.h"
|
||||
#include "board.h"
|
||||
|
||||
|
||||
static volatile uint32_t timer_h = 0; /* 2^(16+32) / 8 MHz = ~1.1 years */
|
||||
@ -155,6 +156,10 @@ uint8_t irq_serial;
|
||||
|
||||
ISR(INT0_vect)
|
||||
{
|
||||
if (mac_irq) {
|
||||
mac_irq();
|
||||
return;
|
||||
}
|
||||
if (eps[1].state == EP_IDLE) {
|
||||
led(1);
|
||||
irq_serial = (irq_serial+1) | 0x80;
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "board.h"
|
||||
#include "sernum.h"
|
||||
#include "spi.h"
|
||||
#include "mac.h"
|
||||
|
||||
|
||||
#define HW_TYPE HW_TYPE_110131
|
||||
@ -239,6 +240,11 @@ static int my_setup(const struct setup_request *setup)
|
||||
usb_send(&eps[0], buf, setup->wLength, NULL, NULL);
|
||||
return 1;
|
||||
|
||||
case ATUSB_TO_DEV(ATUSB_RX_MODE):
|
||||
return mac_rx(setup->wValue);
|
||||
case ATUSB_TO_DEV(ATUSB_TX):
|
||||
return mac_tx(setup->wValue, setup->wLength);
|
||||
|
||||
default:
|
||||
error("Unrecognized SETUP: 0x%02x 0x%02x ...\n",
|
||||
setup->bmRequestType, setup->bRequest);
|
||||
|
@ -39,7 +39,10 @@
|
||||
* host-> ATUSB_SPI_WRITE byte0 byte1 #bytes
|
||||
* ->host ATUSB_SPI_READ1 byte0 - #bytes
|
||||
* ->host ATUSB_SPI_READ2 byte0 byte1 #bytes
|
||||
* ->host ATUSB_SPI_WRITE2_SYNC byte0 bute1 0/1
|
||||
* ->host ATUSB_SPI_WRITE2_SYNC byte0 byte1 0/1
|
||||
*
|
||||
* host-> ATUSB_RX_MODE on - 0
|
||||
* host-> ATUSB_TX flags 0 #bytes
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -93,6 +96,8 @@ enum atspi_requests {
|
||||
ATUSB_SPI_READ1,
|
||||
ATUSB_SPI_READ2,
|
||||
ATUSB_SPI_WRITE2_SYNC,
|
||||
ATUSB_RX_MODE = 0x40, /* HardMAC group */
|
||||
ATUSB_TX,
|
||||
};
|
||||
|
||||
|
||||
|
154
atusb/fw/mac.c
Normal file
154
atusb/fw/mac.c
Normal file
@ -0,0 +1,154 @@
|
||||
/*
|
||||
* fw/mac.c - HardMAC functions
|
||||
*
|
||||
* Written 2011 by Werner Almesberger
|
||||
* Copyright 2011 Werner Almesberger
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "usb.h"
|
||||
|
||||
#include "at86rf230.h"
|
||||
#include "spi.h"
|
||||
#include "mac.h"
|
||||
|
||||
|
||||
void (*mac_irq)(void) = NULL;
|
||||
|
||||
|
||||
static uint8_t rx_buf[MAX_PSDU+2]; /* PHDR+payload+LQ */
|
||||
static uint8_t tx_buf[MAX_PSDU];
|
||||
static uint8_t tx_size = 0;
|
||||
static int txing = 0;
|
||||
|
||||
|
||||
static uint8_t reg_read(uint8_t reg)
|
||||
{
|
||||
uint8_t value;
|
||||
|
||||
spi_begin();
|
||||
spi_send(AT86RF230_REG_READ | reg);
|
||||
value= spi_recv();
|
||||
spi_end();
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
static void reg_write(uint8_t reg, uint8_t value)
|
||||
{
|
||||
spi_begin();
|
||||
spi_send(AT86RF230_REG_WRITE | reg);
|
||||
spi_send(value);
|
||||
spi_end();
|
||||
}
|
||||
|
||||
|
||||
static void 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;
|
||||
}
|
||||
|
||||
/* unlikely */
|
||||
if (eps[1].state != EP_IDLE)
|
||||
return;
|
||||
|
||||
spi_begin();
|
||||
spi_send(AT86RF230_BUF_READ);
|
||||
size = spi_recv();
|
||||
if (size & 0x80) {
|
||||
spi_end();
|
||||
return;
|
||||
}
|
||||
|
||||
rx_buf[0] = size;
|
||||
for (i = 0; i != size+1; i++)
|
||||
rx_buf[i+1] = spi_recv();
|
||||
spi_end();
|
||||
usb_send(&eps[1], rx_buf, size+2, NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
int mac_rx(int on)
|
||||
{
|
||||
if (on) {
|
||||
mac_irq = handle_irq;
|
||||
reg_read(REG_IRQ_STATUS);
|
||||
reg_write(REG_TRX_STATE, TRX_CMD_RX_ON);
|
||||
} else {
|
||||
mac_irq = NULL;
|
||||
reg_write(REG_TRX_STATE, TRX_CMD_FORCE_TRX_OFF);
|
||||
txing = 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static void do_tx(void *user)
|
||||
{
|
||||
uint8_t status;
|
||||
uint8_t i;
|
||||
|
||||
do status = reg_read(REG_TRX_STATUS) & TRX_STATUS_MASK;
|
||||
while (status != TRX_STATUS_RX_ON && status != TRX_STATUS_RX_AACK_ON);
|
||||
|
||||
/*
|
||||
* We use TRX_CMD_FORCE_PLL_ON instead of TRX_CMD_PLL_ON because a new
|
||||
* reception may have begun while we were still working on the previous
|
||||
* one.
|
||||
*/
|
||||
reg_write(REG_TRX_STATE, TRX_CMD_FORCE_PLL_ON);
|
||||
|
||||
handle_irq();
|
||||
|
||||
spi_begin();
|
||||
spi_send(AT86RF230_BUF_WRITE);
|
||||
spi_send(tx_size);
|
||||
for (i = 0; i != tx_size; i++)
|
||||
spi_send(tx_buf[i]);
|
||||
spi_end();
|
||||
|
||||
reg_write(REG_TRX_STATE, TRX_CMD_TX_START);
|
||||
|
||||
txing = 1;
|
||||
|
||||
/*
|
||||
* Wait until we reach BUSY_TX, so that we command the transition to
|
||||
* RX_ON which will be executed upon TX completion.
|
||||
*/
|
||||
while ((reg_read(REG_TRX_STATUS) & TRX_STATUS_MASK) ==
|
||||
TRX_STATUS_TRANSITION);
|
||||
reg_write(REG_TRX_STATE, TRX_CMD_RX_ON);
|
||||
}
|
||||
|
||||
|
||||
int mac_tx(uint16_t flags, uint16_t len)
|
||||
{
|
||||
if (len > MAX_PSDU)
|
||||
return 0;
|
||||
tx_size = len;
|
||||
usb_recv(&eps[0], tx_buf, len, do_tx, NULL);
|
||||
return 1;
|
||||
|
||||
}
|
24
atusb/fw/mac.h
Normal file
24
atusb/fw/mac.h
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* fw/mac.h - HardMAC functions
|
||||
*
|
||||
* Written 2011 by Werner Almesberger
|
||||
* Copyright 2011 Werner Almesberger
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
#ifndef MAC_H
|
||||
#define MAC_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
extern void (*mac_irq)(void);
|
||||
|
||||
int mac_rx(int on);
|
||||
int mac_tx(uint16_t flags, uint16_t len);
|
||||
|
||||
#endif /* !MAC_H */
|
Loading…
Reference in New Issue
Block a user