Root/atusb/fw/usb/dfu.h

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

Archive Download this file



interactive