Firmware
uploader.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2012-2015 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
39 #ifndef _PX4IO_UPLOADER_H
40 #define _PX4IO_UPLOADER_H value
41 
42 #include <stdint.h>
43 #include <stdbool.h>
44 
45 
47 {
48 public:
50  virtual ~PX4IO_Uploader() = default;
51 
52  int upload(const char *filenames[]);
53 
54 private:
55  enum {
56 
57  PROTO_NOP = 0x00,
58  PROTO_OK = 0x10,
59  PROTO_FAILED = 0x11,
60  PROTO_INSYNC = 0x12,
61  PROTO_INVALID = 0x13,
62  PROTO_BAD_SILICON_REV = 0x14,
63  PROTO_EOC = 0x20,
64  PROTO_GET_SYNC = 0x21,
65  PROTO_GET_DEVICE = 0x22,
66  PROTO_CHIP_ERASE = 0x23,
67  PROTO_CHIP_VERIFY = 0x24,
68  PROTO_PROG_MULTI = 0x27,
69  PROTO_READ_MULTI = 0x28,
70  PROTO_GET_CRC = 0x29,
71  PROTO_GET_OTP = 0x2a,
72  PROTO_GET_SN = 0x2b,
73  PROTO_GET_CHIP = 0x2c,
74  PROTO_SET_DELAY = 0x2d,
75  PROTO_GET_CHIP_DES = 0x2e,
76  PROTO_REBOOT = 0x30,
77 
78  INFO_BL_REV = 1,
79  BL_REV = 5,
80  INFO_BOARD_ID = 2,
81  INFO_BOARD_REV = 3,
82  INFO_FLASH_SIZE = 4,
84  PROG_MULTI_MAX = 248,
86  };
87 
88  int _io_fd;
89  int _fw_fd;
90 
91  uint32_t bl_rev;
93  void log(const char *fmt, ...);
94 
95  int recv_byte_with_timeout(uint8_t *c, unsigned timeout);
96  int recv_bytes(uint8_t *p, unsigned count);
97  void drain();
98  int send(uint8_t c);
99  int send(uint8_t *p, unsigned count);
100  int get_sync(unsigned timeout = 40);
101  int sync();
102  int get_info(int param, uint32_t &val);
103  int erase();
104  int program(size_t fw_size);
105  int verify_rev2(size_t fw_size);
106  int verify_rev3(size_t fw_size);
107  int reboot();
108 };
109 
110 #endif
Definition: uploader.h:46