-
Notifications
You must be signed in to change notification settings - Fork 1
/
dfu_priv.h
139 lines (115 loc) · 3.99 KB
/
dfu_priv.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
*
* Copyright 2018 The wookey project team <[email protected]>
* - Ryad Benadjila
* - Arnauld Michelizza
* - Mathieu Renard
* - Philippe Thierry
* - Philippe Trebuchet
*
* This package is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* the Free Software Foundation; either version 2.1 of the License, or (at
* ur option) any later version.
*
* This package is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with this package; if not, write to the Free Software Foundation, Inc., 51
* Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef USB_DFU_PRIV_H_
#define USB_DFU_PRIV_H_
#include "api/dfu.h"
#define MAX_TIME_DETACH 4000
#if CONFIG_USR_LIB_DFU_DEBUG
# define log_printf(...) printf(__VA_ARGS__)
#else
# define log_printf(...)
#endif
typedef struct __packed {
uint32_t magic;
uint32_t type;
uint32_t version;
uint32_t len;
uint32_t siglen;
} dfu_sec_metadata_hdr_t;
typedef struct __packed {
uint16_t bcdDevice;
uint16_t idProduct;
uint16_t idVendor;
uint16_t bcdDFU;
uint8_t ucDfuSignature[3];
uint8_t bLength;
uint32_t dwCRC;
} dfu_suffix_t;
typedef enum dfu_request {
USB_RQST_DFU_DETACH = 0x00,
USB_RQST_DFU_DNLOAD = 0x01,
USB_RQST_DFU_UPLOAD = 0x02,
USB_RQST_DFU_GET_STATUS = 0x03,
USB_RQST_DFU_CLEAR_STATUS = 0x04,
USB_RQST_DFU_GET_STATE = 0x05,
USB_RQST_DFU_ABORT = 0x06
} dfu_request_t;
typedef enum dfu_state_enum {
APPIDLE = 0x00,
APPDETACH = 0x01,
DFUIDLE = 0x02,
DFUDNLOAD_SYNC = 0x03,
DFUDNBUSY = 0x04,
DFUDNLOAD_IDLE = 0x05,
DFUMANIFEST_SYNC = 0x06,
DFUMANIFEST = 0x07,
DFUMANIFEST_WAIT_RESET = 0x08,
DFUUPLOAD_IDLE = 0x09,
DFUERROR = 0x0A,
}dfu_state_enum_t;
typedef struct __packed {
uint8_t bStatus;
uint8_t bwPollTimeout[3];
uint8_t bState;
uint8_t iString;
} device_dfu_status_t;
#ifdef __FRAMAC__
#define MAX_TRANSITION_DFU_STATE 7
/*@ predicate is_valid_dfu_state(dfu_state_enum_t i) =
i == APPIDLE ||
i == APPDETACH ||
i == DFUIDLE ||
i == DFUDNLOAD_SYNC ||
i == DFUDNBUSY ||
i == DFUDNLOAD_IDLE ||
i == DFUMANIFEST_SYNC ||
i == DFUMANIFEST ||
i == DFUMANIFEST_WAIT_RESET ||
i == DFUUPLOAD_IDLE ||
i == DFUERROR ;
*/
/*@ predicate is_valid_dfu_request(dfu_request_t i) =
i == USB_RQST_DFU_DETACH ||
i == USB_RQST_DFU_DNLOAD ||
i == USB_RQST_DFU_UPLOAD ||
i == USB_RQST_DFU_GET_STATUS ||
i == USB_RQST_DFU_CLEAR_STATUS ||
i == USB_RQST_DFU_GET_STATE ||
i == USB_RQST_DFU_ABORT ;
*/
/*
* export internal dfu functions to emulate asynchronous triggers from framaC entrypoint
*/
mbed_error_t dfu_class_parse_request(uint32_t usbdci_handler __attribute__((unused)),
usbctrl_setup_pkt_t *setup_packet);
mbed_error_t dfu_data_out_handler(uint32_t dev_id __attribute__((unused)),
uint32_t size __attribute__((unused)),
uint8_t ep_id __attribute__((unused)));
mbed_error_t dfu_data_in_handler(uint32_t dev_id __attribute__((unused)),
uint32_t size __attribute__((unused)),
uint8_t ep_id __attribute__((unused)));
void dfu_store_finished(void);
void dfu_load_finished(uint16_t bytes_read);
#endif
#endif/*USB_DFU_PRIV_H_*/