IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Git Source Tree
Root/
Source at commit ada1ee037f4367ebe21689cb40aed6a9b9e038c1 created 13 years 7 months ago. By Werner Almesberger, fw/atspi/: added application with basic EP0 protocol | |
---|---|
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 | |
31 | static const uint8_t id[] = { EP0ATSPI_MAJOR, EP0ATSPI_MINOR, HW_TYPE }; |
32 | |
33 | |
34 | static __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 | |
74 | void ep0_init(void) |
75 | { |
76 | user_setup = my_setup; |
77 | } |
78 |