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 428390047f5fdc13bf60f2d2e2671d1afb120459 created 8 years 11 months ago. By Werner Almesberger, fw/atusb/ (dfu_flash_ops): make const | |
---|---|
1 | /* |
2 | * boot/dfu.h - DFU protocol constants and data structures |
3 | * |
4 | * Written 2008, 2011, 2013-2015 by Werner Almesberger |
5 | * Copyright 2008, 2011, 2013-2015 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 DFU_H |
15 | #define DFU_H |
16 | |
17 | #include <stdbool.h> |
18 | #include <stdint.h> |
19 | |
20 | #include "usb.h" |
21 | |
22 | |
23 | enum dfu_request { |
24 | DFU_DETACH, |
25 | DFU_DNLOAD, |
26 | DFU_UPLOAD, |
27 | DFU_GETSTATUS, |
28 | DFU_CLRSTATUS, |
29 | DFU_GETSTATE, |
30 | DFU_ABORT, |
31 | }; |
32 | |
33 | |
34 | enum dfu_status { |
35 | OK, |
36 | errTARGET, |
37 | errFILE, |
38 | errWRITE, |
39 | errERASE, |
40 | errCHECK_ERASED, |
41 | errPROG, |
42 | errVERIFY, |
43 | errADDRESS, |
44 | errNOTDONE, |
45 | errFIRMWARE, |
46 | errVENDOR, |
47 | errUSBR, |
48 | errPOR, |
49 | errUNKNOWN, |
50 | errSTALLEDPKT, |
51 | }; |
52 | |
53 | |
54 | enum dfu_state { |
55 | appIDLE, |
56 | appDETACH, |
57 | dfuIDLE, |
58 | dfuDNLOAD_SYNC, |
59 | dfuDNBUSY, |
60 | dfuDNLOAD_IDLE, |
61 | dfuMANIFEST_SYNC, |
62 | dfuMANIFEST, |
63 | dfuMANIFEST_WAIT_RESET, |
64 | dfuUPLOAD_IDLE, |
65 | dfuERROR |
66 | }; |
67 | |
68 | enum dfu_itf_proto { |
69 | dfu_proto_runtime = 1, /* Runtime protocol */ |
70 | dfu_proto_dfu = 2, /* DFU mode protocol */ |
71 | }; |
72 | |
73 | |
74 | #define DFU_DT_FUNCTIONAL 0x21 /* DFU FUNCTIONAL descriptor type */ |
75 | |
76 | |
77 | #define DFU_TO_DEV(req) (0x21 | (req) << 8) |
78 | #define DFU_FROM_DEV(req) (0xa1 | (req) << 8) |
79 | |
80 | |
81 | struct dfu { |
82 | uint8_t status; /* bStatus */ |
83 | uint8_t toL, toM, toH; /* bwPollTimeout */ |
84 | uint8_t state; /* bState */ |
85 | uint8_t iString; |
86 | }; |
87 | |
88 | |
89 | #define DFU_ITF_DESCR(itf, alt, proto, idx) \ |
90 | 9, /* bLength */ \ |
91 | USB_DT_INTERFACE, /* bDescriptorType */ \ |
92 | (itf), /* bInterfaceNumber */ \ |
93 | (alt), /* bAlternateSetting */ \ |
94 | 0, /* bNumEndpoints */ \ |
95 | 0xfe, /* bInterfaceClass (application specific) */ \ |
96 | 0x01, /* bInterfaceSubClass (device fw upgrade) */ \ |
97 | (proto), /* bInterfaceProtocol (dfu_proto_*) */ \ |
98 | (idx), /* iInterface */ |
99 | |
100 | |
101 | struct dfu_flash_ops { |
102 | void (*start)(void); |
103 | bool (*can_write)(uint16_t size); |
104 | void (*write)(const uint8_t *buf, uint16_t size); |
105 | void (*end_write)(void); |
106 | uint16_t (*read)(uint8_t *buf, uint16_t size); |
107 | }; |
108 | |
109 | extern struct dfu dfu; |
110 | extern const struct dfu_flash_ops *dfu_flash_ops; |
111 | |
112 | |
113 | bool dfu_setup_common(const struct setup_request *setup); |
114 | bool dfu_my_descr(uint8_t type, uint8_t index, const uint8_t **reply, |
115 | uint8_t *size); |
116 | |
117 | void dfu_init(void); |
118 | |
119 | #endif /* !DFU_H */ |
120 |