mirror of
git://projects.qi-hardware.com/ben-wpan.git
synced 2024-11-25 18:57:11 +02:00
fw/atspi/: added application with basic EP0 protocol
This commit is contained in:
parent
2c8c609316
commit
ada1ee037f
32
fw/atspi/Makefile
Normal file
32
fw/atspi/Makefile
Normal file
@ -0,0 +1,32 @@
|
||||
#
|
||||
# atspi/Makefile - Makefile for USB to SPI translator (for AT86RF230)
|
||||
#
|
||||
# Written 2010 by Werner Almesberger
|
||||
# Copyright 2010 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.
|
||||
#
|
||||
|
||||
|
||||
MAIN = atspi
|
||||
OBJS = $(MAIN) usb descr version ep0
|
||||
|
||||
F32XBASE = ../../../f32xbase
|
||||
|
||||
include $(F32XBASE)/fw/common/Makefile.system
|
||||
include $(F32XBASE)/fw/common/Makefile.common
|
||||
|
||||
CFLAGS += -I../include
|
||||
LDFLAGS += --code-size $(PAYLOAD_SIZE) --code-loc $(PAYLOAD_START)
|
||||
|
||||
USB_ID = $(shell \
|
||||
`( echo '#include "config.h"'; echo USB_VENDOR:USB_PRODUCT; ) | \
|
||||
cpp | sed '/^ *$/d;/^#/d')
|
||||
|
||||
.PHONY: dfu
|
||||
|
||||
dfu:
|
||||
dfu-util -d $(USB_ID) -D $(MAIN).bin
|
29
fw/atspi/atspi.c
Normal file
29
fw/atspi/atspi.c
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* atspi/atspi.c - ATSPIinitialization and main loop
|
||||
*
|
||||
* Written 2008-2010 by Werner Almesberger
|
||||
* Copyright 2008-2010 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 "regs.h"
|
||||
#include "io.h"
|
||||
#include "usb.h"
|
||||
#include "atspi/ep0.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
void main(void)
|
||||
{
|
||||
usb_init();
|
||||
ep0_init();
|
||||
|
||||
while (1) {
|
||||
usb_poll();
|
||||
}
|
||||
}
|
88
fw/atspi/descr.c
Normal file
88
fw/atspi/descr.c
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* atspi/descr.c - USB descriptors
|
||||
*
|
||||
* Written 2008-2010 by Werner Almesberger
|
||||
* Copyright 2008-2010 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 "usb.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
|
||||
/*
|
||||
* Device descriptor
|
||||
*/
|
||||
|
||||
const uint8_t device_descriptor[18] = {
|
||||
18, /* bLength */
|
||||
USB_DT_DEVICE, /* bDescriptorType */
|
||||
LE(0x200), /* bcdUSB */
|
||||
USB_CLASS_VENDOR_SPEC, /* bDeviceClass */
|
||||
0x00, /* bDeviceSubClass */
|
||||
0x00, /* bDeviceProtocol */
|
||||
EP0_SIZE, /* bMaxPacketSize */
|
||||
LE(USB_VENDOR), /* idVendor */
|
||||
LE(USB_PRODUCT), /* idProduct */
|
||||
LE(0x0001), /* bcdDevice */
|
||||
0, /* iManufacturer */
|
||||
0, /* iProduct */
|
||||
0, /* iSerialNumber */
|
||||
1 /* bNumConfigurations */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Our configuration
|
||||
*
|
||||
* While in DFU mode, we're always bus-powered.
|
||||
*/
|
||||
|
||||
const uint8_t config_descriptor[] = {
|
||||
9, /* bLength */
|
||||
USB_DT_CONFIG, /* bDescriptorType */
|
||||
LE(9+9+7+7), /* wTotalLength */
|
||||
1, /* bNumInterfaces */
|
||||
1, /* bConfigurationValue (> 0 !) */
|
||||
0, /* iConfiguration */
|
||||
// USB_ATTR_SELF_POWERED | USB_ATTR_BUS_POWERED,
|
||||
USB_ATTR_BUS_POWERED, /* bmAttributes */
|
||||
15, /* bMaxPower */
|
||||
|
||||
/* Interface #0 */
|
||||
|
||||
9, /* bLength */
|
||||
USB_DT_INTERFACE, /* bDescriptorType */
|
||||
0, /* bInterfaceNumber */
|
||||
0, /* bAlternateSetting */
|
||||
2, /* bNumEndpoints */
|
||||
USB_CLASS_VENDOR_SPEC, /* bInterfaceClass */
|
||||
0, /* bInterfaceSubClass */
|
||||
0, /* bInterfaceProtocol */
|
||||
0, /* iInterface */
|
||||
|
||||
/* EP OUT */
|
||||
|
||||
7, /* bLength */
|
||||
USB_DT_ENDPOINT, /* bDescriptorType */
|
||||
0x01, /* bEndPointAddress */
|
||||
0x02, /* bmAttributes (bulk) */
|
||||
LE(EP1_SIZE), /* wMaxPacketSize */
|
||||
0, /* bInterval */
|
||||
|
||||
/* EP IN */
|
||||
|
||||
7, /* bLength */
|
||||
USB_DT_ENDPOINT, /* bDescriptorType */
|
||||
0x81, /* bEndPointAddress */
|
||||
0x02, /* bmAttributes (bulk) */
|
||||
LE(EP1_SIZE), /* wMaxPacketSize */
|
||||
0, /* bInterval */
|
||||
|
||||
};
|
77
fw/atspi/ep0.c
Normal file
77
fw/atspi/ep0.c
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* atspi/ep0.c - EP0 extension protocol
|
||||
*
|
||||
* Written 2008-2010 by Werner Almesberger
|
||||
* Copyright 2008-2010 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 <stdint.h>
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
#include "regs.h"
|
||||
//#include "uart.h"
|
||||
#include "usb.h"
|
||||
#include "atspi/ep0.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
#define debug(...)
|
||||
#define error(...)
|
||||
|
||||
|
||||
static const uint8_t id[] = { EP0ATSPI_MAJOR, EP0ATSPI_MINOR, HW_TYPE };
|
||||
|
||||
|
||||
static __bit my_setup(struct setup_request *setup) __reentrant
|
||||
{
|
||||
uint8_t size;
|
||||
|
||||
switch (setup->bmRequestType | setup->bRequest << 8) {
|
||||
case ATSPI_FROM_DEV(ATSPI_ID):
|
||||
debug("ATSPI_ID\n");
|
||||
if (setup->wLength > 3)
|
||||
return 0;
|
||||
usb_send(&ep0, id, setup->wLength, NULL, NULL);
|
||||
return 1;
|
||||
case ATSPI_FROM_DEV(ATSPI_BUILD_NUMBER):
|
||||
debug("ATSPI_BUILD_NUMBER\n");
|
||||
if (setup->wLength > 2)
|
||||
return 0;
|
||||
usb_send(&ep0, (void *) &build_number, setup->wLength,
|
||||
NULL, NULL);
|
||||
return 1;
|
||||
case ATSPI_FROM_DEV(ATSPI_BUILD_DATE):
|
||||
debug("ATSPI_BUILD_DATE\n");
|
||||
for (size = 0; build_date[size]; size++);
|
||||
if (size > EP1_SIZE)
|
||||
return 0;
|
||||
if (size > setup->wLength)
|
||||
return 0;
|
||||
usb_send(&ep0, build_date, size, NULL, NULL);
|
||||
return 1;
|
||||
case ATSPI_TO_DEV(ATSPI_RESET):
|
||||
debug("ATSPI_RESET\n");
|
||||
RSTSRC = SWRSF;
|
||||
while (1);
|
||||
|
||||
default:
|
||||
error("Unrecognized SETUP: 0x%02x 0x%02x ...\n",
|
||||
setup->bmRequestType, setup->bRequest);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ep0_init(void)
|
||||
{
|
||||
user_setup = my_setup;
|
||||
}
|
34
fw/atspi/io.h
Normal file
34
fw/atspi/io.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* atspi/io.h - I/O pin assignment
|
||||
*
|
||||
* Written 2010 by Werner Almesberger
|
||||
* Copyright 2010 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 IO_H
|
||||
#define IO_H
|
||||
|
||||
/* Diagnostic LED */
|
||||
|
||||
#define LED P0_1
|
||||
|
||||
/* SPI */
|
||||
|
||||
#define MOSI P2_2
|
||||
#define MISO P2_5
|
||||
#define SCLK P2_4
|
||||
#define nSS P2_3
|
||||
|
||||
/* Miscellaneous RF signals */
|
||||
|
||||
#define nRST_RF P2_0
|
||||
#define IRQ_RF P0_2
|
||||
#define SLP_TR P2_1
|
||||
|
||||
#endif /* !IO_H */
|
63
fw/include/atspi/ep0.h
Normal file
63
fw/include/atspi/ep0.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* include/atspi/ep0.h - EP0 extension protocol
|
||||
*
|
||||
* Written 2008-2010 by Werner Almesberger
|
||||
* Copyright 2008-2010 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 EP0_H
|
||||
#define EP0_H
|
||||
|
||||
/*
|
||||
* Direction bRequest wValue wIndex wLength
|
||||
*
|
||||
* ->host ATSPI_ID 0 0 3
|
||||
* host-> ATSPI_RESET 0 0 0
|
||||
* ->host ATSPI_BUILD_NUMBER - - 2
|
||||
* ->host ATSPI_BUILD_DATE - - #bytes
|
||||
*/
|
||||
|
||||
/*
|
||||
* EP0 protocol:
|
||||
*
|
||||
* 0.0 initial release
|
||||
*/
|
||||
|
||||
#define EP0ATSPI_MAJOR 0 /* EP0 protocol, major revision */
|
||||
#define EP0ATSPI_MINOR 0 /* EP0 protocol, minor revision */
|
||||
|
||||
#define HW_TYPE_100813 0 /* 100813 */
|
||||
|
||||
|
||||
/*
|
||||
* bmRequestType:
|
||||
*
|
||||
* D7 D6..5 D4...0
|
||||
* | | |
|
||||
* direction (0 = host->dev)
|
||||
* type (2 = vendor)
|
||||
* recipient (0 = device)
|
||||
*/
|
||||
|
||||
|
||||
#define ATSPI_TO_DEV(req) (0x40 | (req) << 8)
|
||||
#define ATSPI_FROM_DEV(req) (0xc0 | (req) << 8)
|
||||
|
||||
|
||||
enum atspi_requests {
|
||||
ATSPI_ID = 0x00,
|
||||
ATSPI_RESET,
|
||||
ATSPI_BUILD_NUMBER,
|
||||
ATSPI_BUILD_DATE,
|
||||
};
|
||||
|
||||
|
||||
void ep0_init(void);
|
||||
|
||||
#endif /* !EP0_H */
|
Loading…
Reference in New Issue
Block a user