Date:2010-08-19 14:04:51 (8 years 9 months ago)
Author:Werner Almesberger
Commit:ada1ee037f4367ebe21689cb40aed6a9b9e038c1
Message:fw/atspi/: added application with basic EP0 protocol

Files: fw/atspi/Makefile (1 diff)
fw/atspi/atspi.c (1 diff)
fw/atspi/descr.c (1 diff)
fw/atspi/ep0.c (1 diff)
fw/atspi/io.h (1 diff)
fw/include/atspi/ep0.h (1 diff)

Change Details

fw/atspi/Makefile
1#
2# atspi/Makefile - Makefile for USB to SPI translator (for AT86RF230)
3#
4# Written 2010 by Werner Almesberger
5# Copyright 2010 Werner Almesberger
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12
13
14MAIN = atspi
15OBJS = $(MAIN) usb descr version ep0
16
17F32XBASE = ../../../f32xbase
18
19include $(F32XBASE)/fw/common/Makefile.system
20include $(F32XBASE)/fw/common/Makefile.common
21
22CFLAGS += -I../include
23LDFLAGS += --code-size $(PAYLOAD_SIZE) --code-loc $(PAYLOAD_START)
24
25USB_ID = $(shell \
26  `( echo '#include "config.h"'; echo USB_VENDOR:USB_PRODUCT; ) | \
27  cpp | sed '/^ *$/d;/^#/d')
28
29.PHONY: dfu
30
31dfu:
32        dfu-util -d $(USB_ID) -D $(MAIN).bin
fw/atspi/atspi.c
1/*
2 * atspi/atspi.c - ATSPIinitialization and main loop
3 *
4 * Written 2008-2010 by Werner Almesberger
5 * Copyright 2008-2010 Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#include "regs.h"
15#include "io.h"
16#include "usb.h"
17#include "atspi/ep0.h"
18#include "version.h"
19
20
21void main(void)
22{
23    usb_init();
24    ep0_init();
25
26    while (1) {
27        usb_poll();
28    }
29}
fw/atspi/descr.c
1/*
2 * atspi/descr.c - USB descriptors
3 *
4 * Written 2008-2010 by Werner Almesberger
5 * Copyright 2008-2010 Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#include "usb.h"
15
16#include "config.h"
17
18
19/*
20 * Device descriptor
21 */
22
23const uint8_t device_descriptor[18] = {
24    18, /* bLength */
25    USB_DT_DEVICE, /* bDescriptorType */
26    LE(0x200), /* bcdUSB */
27    USB_CLASS_VENDOR_SPEC, /* bDeviceClass */
28    0x00, /* bDeviceSubClass */
29    0x00, /* bDeviceProtocol */
30    EP0_SIZE, /* bMaxPacketSize */
31    LE(USB_VENDOR), /* idVendor */
32    LE(USB_PRODUCT), /* idProduct */
33    LE(0x0001), /* bcdDevice */
34    0, /* iManufacturer */
35    0, /* iProduct */
36    0, /* iSerialNumber */
37    1 /* bNumConfigurations */
38};
39
40
41/*
42 * Our configuration
43 *
44 * While in DFU mode, we're always bus-powered.
45 */
46
47const uint8_t config_descriptor[] = {
48    9, /* bLength */
49    USB_DT_CONFIG, /* bDescriptorType */
50    LE(9+9+7+7), /* wTotalLength */
51    1, /* bNumInterfaces */
52    1, /* bConfigurationValue (> 0 !) */
53    0, /* iConfiguration */
54// USB_ATTR_SELF_POWERED | USB_ATTR_BUS_POWERED,
55    USB_ATTR_BUS_POWERED, /* bmAttributes */
56    15, /* bMaxPower */
57
58    /* Interface #0 */
59
60    9, /* bLength */
61    USB_DT_INTERFACE, /* bDescriptorType */
62    0, /* bInterfaceNumber */
63    0, /* bAlternateSetting */
64    2, /* bNumEndpoints */
65    USB_CLASS_VENDOR_SPEC, /* bInterfaceClass */
66    0, /* bInterfaceSubClass */
67    0, /* bInterfaceProtocol */
68    0, /* iInterface */
69
70    /* EP OUT */
71
72    7, /* bLength */
73    USB_DT_ENDPOINT, /* bDescriptorType */
74    0x01, /* bEndPointAddress */
75    0x02, /* bmAttributes (bulk) */
76    LE(EP1_SIZE), /* wMaxPacketSize */
77    0, /* bInterval */
78
79    /* EP IN */
80
81    7, /* bLength */
82    USB_DT_ENDPOINT, /* bDescriptorType */
83    0x81, /* bEndPointAddress */
84    0x02, /* bmAttributes (bulk) */
85    LE(EP1_SIZE), /* wMaxPacketSize */
86    0, /* bInterval */
87
88};
fw/atspi/ep0.c
1/*
2 * atspi/ep0.c - EP0 extension protocol
3 *
4 * Written 2008-2010 by Werner Almesberger
5 * Copyright 2008-2010 Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#include <stdint.h>
15
16#ifndef NULL
17#define NULL 0
18#endif
19
20#include "regs.h"
21//#include "uart.h"
22#include "usb.h"
23#include "atspi/ep0.h"
24#include "version.h"
25
26
27#define debug(...)
28#define error(...)
29
30
31static const uint8_t id[] = { EP0ATSPI_MAJOR, EP0ATSPI_MINOR, HW_TYPE };
32
33
34static __bit my_setup(struct setup_request *setup) __reentrant
35{
36    uint8_t size;
37
38    switch (setup->bmRequestType | setup->bRequest << 8) {
39    case ATSPI_FROM_DEV(ATSPI_ID):
40        debug("ATSPI_ID\n");
41        if (setup->wLength > 3)
42            return 0;
43        usb_send(&ep0, id, setup->wLength, NULL, NULL);
44        return 1;
45    case ATSPI_FROM_DEV(ATSPI_BUILD_NUMBER):
46        debug("ATSPI_BUILD_NUMBER\n");
47        if (setup->wLength > 2)
48            return 0;
49        usb_send(&ep0, (void *) &build_number, setup->wLength,
50            NULL, NULL);
51        return 1;
52    case ATSPI_FROM_DEV(ATSPI_BUILD_DATE):
53        debug("ATSPI_BUILD_DATE\n");
54        for (size = 0; build_date[size]; size++);
55        if (size > EP1_SIZE)
56            return 0;
57        if (size > setup->wLength)
58            return 0;
59        usb_send(&ep0, build_date, size, NULL, NULL);
60        return 1;
61    case ATSPI_TO_DEV(ATSPI_RESET):
62        debug("ATSPI_RESET\n");
63        RSTSRC = SWRSF;
64        while (1);
65
66    default:
67        error("Unrecognized SETUP: 0x%02x 0x%02x ...\n",
68            setup->bmRequestType, setup->bRequest);
69        return 0;
70    }
71}
72
73
74void ep0_init(void)
75{
76    user_setup = my_setup;
77}
fw/atspi/io.h
1/*
2 * atspi/io.h - I/O pin assignment
3 *
4 * Written 2010 by Werner Almesberger
5 * Copyright 2010 Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#ifndef IO_H
15#define IO_H
16
17/* Diagnostic LED */
18
19#define LED P0_1
20
21/* SPI */
22
23#define MOSI P2_2
24#define MISO P2_5
25#define SCLK P2_4
26#define nSS P2_3
27
28/* Miscellaneous RF signals */
29
30#define nRST_RF P2_0
31#define IRQ_RF P0_2
32#define SLP_TR P2_1
33
34#endif /* !IO_H */
fw/include/atspi/ep0.h
1/*
2 * include/atspi/ep0.h - EP0 extension protocol
3 *
4 * Written 2008-2010 by Werner Almesberger
5 * Copyright 2008-2010 Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#ifndef EP0_H
15#define EP0_H
16
17/*
18 * Direction bRequest wValue wIndex wLength
19 *
20 * ->host ATSPI_ID 0 0 3
21 * host-> ATSPI_RESET 0 0 0
22 * ->host ATSPI_BUILD_NUMBER - - 2
23 * ->host ATSPI_BUILD_DATE - - #bytes
24 */
25
26/*
27 * EP0 protocol:
28 *
29 * 0.0 initial release
30 */
31
32#define EP0ATSPI_MAJOR 0 /* EP0 protocol, major revision */
33#define EP0ATSPI_MINOR 0 /* EP0 protocol, minor revision */
34
35#define HW_TYPE_100813 0 /* 100813 */
36
37
38/*
39 * bmRequestType:
40 *
41 * D7 D6..5 D4...0
42 * | | |
43 * direction (0 = host->dev)
44 * type (2 = vendor)
45 * recipient (0 = device)
46 */
47
48
49#define ATSPI_TO_DEV(req) (0x40 | (req) << 8)
50#define ATSPI_FROM_DEV(req) (0xc0 | (req) << 8)
51
52
53enum atspi_requests {
54    ATSPI_ID = 0x00,
55    ATSPI_RESET,
56    ATSPI_BUILD_NUMBER,
57    ATSPI_BUILD_DATE,
58};
59
60
61void ep0_init(void);
62
63#endif /* !EP0_H */

Archive Download the corresponding diff file



interactive