dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
bl_messages.h
Go to the documentation of this file.
1 
12 /*
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  * for more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with this program; if not, see <http://www.gnu.org/licenses/>
25  */
26 
27 #ifndef BL_MESSAGES_H_
28 #define BL_MESSAGES_H_
29 
30 #ifndef PACK
31 #ifdef _MSC_VER
32 #define PACK(__Declaration__) __pragma(pack(push, 1)) __Declaration__ __pragma(pack(pop))
33 #else
34 #define PACK(__Declaration__) __Declaration__ __attribute__((__packed__))
35 #endif /* _MSC_VER */
36 #endif /* PACK */
37 
38 namespace tl_dfu {
39 
40 #define BL_INCLUDE_CAP_EXTENSIONS
41 
42 #define uint8_t quint8
43 #define uint16_t quint16
44 #define uint32_t quint32
45 
46 /* Note:
47  * Writes are from PC -> FC
48  * Reads are from FC -> PC
49  */
65 
67  0x27, // f1 bl masks with 0b11111 so this looks like BL_MSG_WRITE_CONT there
68  // the 6th bit ends up being start flag
69 };
70 
71 #define BL_MSG_FLAGS_ECHO_REQ 0x80
72 #define BL_MSG_FLAGS_ECHO_REP 0x40
73 #define BL_MSG_FLAGS_MASK 0xC0
74 #define BL_MSG_COMMAND_MASK 0x3F
75 
76 #if !defined(ntohl)
77 #define ntohl(v) \
78  ((((v)&0xFF000000) >> 24) | (((v)&0x00FF0000) >> 8) | (((v)&0x0000FF00) << 8) \
79  | (((v)&0x000000FF) << 24))
80 
81 #define ntohs(v) ((((v)&0xFF00) >> 8) | (((v)&0x00FF) << 8))
82 
83 #define htonl(v) ntohl((v))
84 
85 #define htons(v) ntohs((v))
86 #endif
87 
88 /*
89  * Note: These enum values MUST NOT be changed or backward
90  * compatibility will be broken
91  */
92 
93 #ifdef _MSC_VER
94 #pragma pack(push, 1)
95 #endif
104 #ifdef _MSC_VER
105 };
106 #pragma pack(pop)
107 #else
108 } __attribute__((packed));
109 #endif
110 
112 {
113  uint8_t unused[4];
114  uint8_t device_number;
115 };
116 
118 {
119  uint8_t unused[4];
121  uint16_t wrflags;
122 };
123 
125 {
126  uint32_t fw_size;
127  uint8_t device_number;
128  uint8_t bl_version;
129  uint8_t desc_size;
130  uint8_t board_rev;
131  uint32_t fw_crc;
132  uint16_t device_id;
133 #if defined(BL_INCLUDE_CAP_EXTENSIONS)
134 /* Extensions to original protocol */
135 #define BL_CAP_EXTENSION_MAGIC 0x3456
137  uint32_t partition_sizes[10];
138 #endif /* BL_INCLUDE_CAP_EXTENSIONS */
139 };
140 
142 {
143  uint8_t unused[4];
144  uint8_t device_number;
145 };
146 
148 {
149  uint8_t unused[4];
150  uint8_t unused2[2];
151  uint16_t safe_word;
152 };
153 
154 struct msg_reset
155 {
156  /* No subfields */
157 };
158 
160 {
161  /* No subfields */
162 };
163 
165 {
166  /* No subfields */
167 };
168 
169 PACK(struct msg_xfer_start {
170  uint32_t packets_in_transfer;
171  uint8_t label;
172  uint8_t words_in_last_packet;
173  uint32_t expected_crc; /* only used in writes */
174 });
175 
176 #define XFER_BYTES_PER_PACKET 56
178 {
180  uint8_t data[XFER_BYTES_PER_PACKET];
181 };
182 
184 {
185  /* No subfields */
186 };
187 
189 {
191  uint8_t current_state;
192 };
193 
195 {
196  uint8_t label;
197 };
198 
199 PACK(union msg_contents {
200  struct msg_capabilities_req cap_req;
201  struct msg_capabilities_rep_all cap_rep_all;
202  struct msg_capabilities_rep_specific cap_rep_specific;
203  struct msg_enter_dfu enter_dfu;
204  struct msg_jump_fw jump_fw;
205  struct msg_reset reset;
206  struct msg_op_abort op_abort;
207  struct msg_op_end op_end;
208  struct msg_xfer_start xfer_start;
209  struct msg_xfer_cont xfer_cont;
210  struct msg_status_req status_req;
211  struct msg_status_rep status_rep;
212  struct msg_wipe_partition wipe_partition;
213  uint8_t pad[62];
214 });
215 
216 PACK(struct bl_messages {
217  uint8_t flags_command;
218 
219  union msg_contents v;
220 });
221 
222 } /* namespace tl_dfu */
223 
224 #endif // BL_MESSAGES_H
uint8_t unused2[2]
Definition: bl_messages.h:150
uint8_t unused[4]
Definition: bl_messages.h:143
uint32_t additional_state
Definition: bl_messages.h:190
uint8_t data[XFER_BYTES_PER_PACKET]
Definition: bl_messages.h:180
uint32_t current_packet_number
Definition: bl_messages.h:179
uint16_t safe_word
Definition: bl_messages.h:151
__attribute__((packed))
PACK(struct msg_xfer_start{uint32_t packets_in_transfer;uint8_t label;uint8_t words_in_last_packet;uint32_t expected_crc;})
dfu_partition_label
Definition: bl_messages.h:96
uint8_t device_number
Definition: bl_messages.h:144
uint8_t current_state
Definition: bl_messages.h:191
uint8_t unused[4]
Definition: bl_messages.h:149