Root/atusb/fw/usb/dfu.h

Source at commit d233c04c86c2fde39b5e069bb6750caef3393f32 created 9 years 6 months ago.
By Werner Almesberger, atusb/fw: implemented USB bus reset (to host) and polling of reset from host
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
20enum dfu_request {
21    DFU_DETACH,
22    DFU_DNLOAD,
23    DFU_UPLOAD,
24    DFU_GETSTATUS,
25    DFU_CLRSTATUS,
26    DFU_GETSTATE,
27    DFU_ABORT,
28};
29
30
31enum dfu_status {
32    OK,
33    errTARGET,
34    errFILE,
35    errWRITE,
36    errERASE,
37    errCHECK_ERASED,
38    errPROG,
39    errVERIFY,
40    errADDRESS,
41    errNOTDONE,
42    errFIRMWARE,
43    errVENDOR,
44    errUSBR,
45    errPOR,
46    errUNKNOWN,
47    errSTALLEDPKT,
48};
49
50
51enum dfu_state {
52    appIDLE,
53    appDETACH,
54    dfuIDLE,
55    dfuDNLOAD_SYNC,
56    dfuDNBUSY,
57    dfuDNLOAD_IDLE,
58    dfuMANIFEST_SYNC,
59    dfuMANIFEST,
60    dfuMANIFEST_WAIT_RESET,
61    dfuUPLOAD_IDLE,
62    dfuERROR
63};
64
65
66#define DFU_DT_FUNCTIONAL 0x21 /* DFU FUNCTIONAL descriptor type */
67
68
69#define DFU_TO_DEV(req) (0x21 | (req) << 8)
70#define DFU_FROM_DEV(req) (0xa1 | (req) << 8)
71
72
73struct dfu {
74    uint8_t status; /* bStatus */
75    uint8_t toL, toM, toH; /* bwPollTimeout */
76    uint8_t state; /* bState */
77    uint8_t iString;
78};
79
80
81extern struct dfu dfu;
82
83
84void flash_start(void);
85int flash_can_write(uint16_t size);
86void flash_write(const uint8_t *buf, uint16_t size);
87void flash_end_write(void);
88uint16_t flash_read(uint8_t *buf, uint16_t size);
89
90
91void dfu_init(void);
92
93#endif /* !DFU_H */
94

Archive Download this file



interactive