From 0120f62242f99554614ff1f3fa4fd7ac16cf17da Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Mon, 20 Jun 2011 15:49:33 -0300 Subject: [PATCH] atusb/fw/: added reporting of RF interrupts via bulk EP1 - board.h (board_app_init), board_app.c (board_app_init): new function for application-specific board initialization - atusb.c (main): call board_app_init - board_app.c (INT0_vect): on RF interrupt, read REG_IRQ_STATUS and send the status byte on EP1 - board_app.c (board_app_init): set up interrupt on rising edge of INT0 (INT_RF) - descr.c (config_descriptor): added EP1 as bulk IN --- atusb/fw/atusb.c | 1 + atusb/fw/board.h | 1 + atusb/fw/board_app.c | 25 +++++++++++++++++++++++++ atusb/fw/descr.c | 10 ++++------ 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/atusb/fw/atusb.c b/atusb/fw/atusb.c index 6264d7c..f526844 100644 --- a/atusb/fw/atusb.c +++ b/atusb/fw/atusb.c @@ -28,6 +28,7 @@ int main(void) { board_init(); + board_app_init(); reset_rf(); user_get_descriptor = sernum_get_descr; diff --git a/atusb/fw/board.h b/atusb/fw/board.h index 1188a6b..90fb584 100644 --- a/atusb/fw/board.h +++ b/atusb/fw/board.h @@ -83,5 +83,6 @@ void timer_init(void); int gpio(uint8_t port, uint8_t data, uint8_t dir, uint8_t mask, uint8_t *res); void board_init(void); +void board_app_init(void); #endif /* !BOARD_H */ diff --git a/atusb/fw/board_app.c b/atusb/fw/board_app.c index ba1dd67..67e6353 100644 --- a/atusb/fw/board_app.c +++ b/atusb/fw/board_app.c @@ -11,6 +11,7 @@ */ +#include #include #include @@ -19,6 +20,8 @@ #define F_CPU 8000000UL #include +#include "usb.h" +#include "at86rf230.h" #include "board.h" #include "spi.h" @@ -131,3 +134,25 @@ int gpio(uint8_t port, uint8_t data, uint8_t dir, uint8_t mask, uint8_t *res) return 1; } + + +ISR(INT0_vect) +{ + static uint8_t irq; + + if (eps[1].state != EP_IDLE) + return; + spi_begin(); + spi_send(AT86RF230_REG_READ | REG_IRQ_STATUS); + irq = spi_recv(); + spi_end(); + usb_send(&eps[1], &irq, 1, NULL, NULL); +} + + +void board_app_init(void) +{ + /* enable INT0, trigger on rising edge */ + EICRA = 1 << ISC01 | 1 << ISC00; + EIMSK = 1; +} diff --git a/atusb/fw/descr.c b/atusb/fw/descr.c index d32d455..147e180 100644 --- a/atusb/fw/descr.c +++ b/atusb/fw/descr.c @@ -56,7 +56,7 @@ const uint8_t config_descriptor[] = { #if 0 LE(9+9+7+7), /* wTotalLength */ #else - LE(9+9+9), /* wTotalLength */ + LE(9+9+7+9), /* wTotalLength */ #endif 2, /* bNumInterfaces */ 1, /* bConfigurationValue (> 0 !) */ @@ -70,11 +70,7 @@ const uint8_t config_descriptor[] = { USB_DT_INTERFACE, /* bDescriptorType */ 0, /* bInterfaceNumber */ 0, /* bAlternateSetting */ -#if 0 - 2, /* bNumEndpoints */ -#else - 0, -#endif + 1, /* bNumEndpoints */ USB_CLASS_VENDOR_SPEC, /* bInterfaceClass */ 0, /* bInterfaceSubClass */ 0, /* bInterfaceProtocol */ @@ -89,7 +85,9 @@ const uint8_t config_descriptor[] = { 0x02, /* bmAttributes (bulk) */ LE(EP1_SIZE), /* wMaxPacketSize */ 0, /* bInterval */ +#endif +#if 1 /* EP IN */ 7, /* bLength */