Update README.md
[mfgtools.git] / libuuu / libuuu.h
blob97f0f7f745f46e5a444ffe108a495343d0090359
1 /*
2 * Copyright 2018 NXP.
4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright notice, this
11 * list of conditions and the following disclaimer in the documentation and/or
12 * other materials provided with the distribution.
14 * Neither the name of the NXP Semiconductor nor the names of its
15 * contributors may be used to endorse or promote products derived from this
16 * software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
31 #ifndef __libuuu___
32 #define __libuuu___
34 #include <stdint.h>
35 #include <stddef.h>
37 #ifdef __cplusplus
38 #define EXT extern "C"
39 #else
40 #define EXT
41 #endif
43 /**
44 * Get Last error string
45 * @return last error string
47 EXT const char * uuu_get_last_err_string();
49 /**
50 * Get Last error code
51 * @return last error code
53 EXT int uuu_get_last_err();
55 EXT const char * uuu_get_version_string();
57 /**
58 * 1.0.1
59 * bit[31:24].bit[23:12].bit[11:0]
62 EXT int uuu_get_version();
66 struct uuu_notify
68 enum NOTIFY_TYPE
70 NOTIFY_CMD_TOTAL,
71 NOTIFY_CMD_START, /* str is command name*/
72 NOTIFY_CMD_END, /* status show command finish status. 0 is success. Other failure.*/
73 NOTIFY_CMD_INDEX, /*Current running command index*/
75 NOTIFY_CMD_INFO, /* Status info string */
77 NOTIFY_PHASE_TOTAL,
78 NOTIFY_PHASE_INDEX, /*Current running phase*/
80 NOTIFY_TRANS_SIZE, /*Total size*/
81 NOTIFY_TRANS_POS, /*Current finished transfer pos*/
83 NOTIFY_WAIT_FOR,
84 NOTIFY_DEV_ATTACH,
86 NOTIFY_DECOMPRESS_START,
87 NOTIFY_DECOMPRESS_SIZE,
88 NOTIFY_DECOMPRESS_POS,
90 NOTIFY_DOWNLOAD_START,
91 NOTIFY_DOWNLOAD_END,
92 NOTIFY_THREAD_EXIT,
94 NOTIFY_DONE,
97 NOTIFY_TYPE type;
98 uint64_t id;
99 uint64_t timestamp;
100 union
102 int status;
103 size_t index;
104 size_t total;
105 char *str;
109 typedef int (*uuu_notify_fun)(struct uuu_notify, void *data);
111 int uuu_register_notify_callback(uuu_notify_fun f, void *data);
112 int uuu_unregister_notify_callback(uuu_notify_fun f);
114 typedef int(*uuu_show_cfg)(const char *pro, const char *chip, const char *comp, uint16_t vid, uint16_t pid, uint16_t bcdlow, uint16_t bcdhigh, void *p);
115 int uuu_for_each_cfg(uuu_show_cfg fn, void *p);
117 typedef int(*uuu_ls_file)(const char *path, void *p);
118 int uuu_for_each_ls_file(uuu_ls_file fn, const char *path, void *p);
120 typedef int(*uuu_ls_usb_devices)(const char *path, const char *chip, const char *pro, uint16_t vid, uint16_t pid, uint16_t bcd, const char *serial_no, void *p);
121 int uuu_for_each_devices(uuu_ls_usb_devices fn, void *p);
123 int uuu_run_cmd(const char * cmd, int dry);
124 int uuu_run_cmd_script(const char *script, int dry);
126 int uuu_auto_detect_file(const char * filename);
127 int uuu_wait_uuu_finish(int deamon, int dry);
128 int uuu_add_usbpath_filter(const char *path);
129 int uuu_add_usbserial_no_filter(const char *serial_no);
131 /*Set timeout wait for known devices appeared*/
132 int uuu_set_wait_timeout(int timeout_in_seconds);
133 /*Set timeout wait for next devices appeared, e.g. FB -> FBK*/
134 int uuu_set_wait_next_timeout(int timeout_in_seconds);
135 /*Set usb device polling period */
136 void uuu_set_poll_period(int period_in_milliseconds);
138 * bit 0:15 for libusb
139 * bit 16:31 for uuu
141 void uuu_set_debug_level(uint32_t mask);
144 * 0 disable small memory mode, buffer all data, it is used for multi-board program.
146 void uuu_set_small_mem(uint32_t val);
148 #define MAX_USER_LEN 128
149 typedef int (*uuu_askpasswd)(char* prompt, char user[MAX_USER_LEN], char passwd[MAX_USER_LEN]);
150 int uuu_set_askpasswd(uuu_askpasswd ask);
152 enum class bmap_mode {
153 Default,
154 Force,
155 Ignore
158 /*Get .bmap handling mode*/
159 static inline bmap_mode uuu_get_bmap_mode() {
160 extern bmap_mode g_bmap_mode;
161 return g_bmap_mode;
164 static inline int uuu_force_bmap() {
165 return uuu_get_bmap_mode() == bmap_mode::Force;
168 static inline int uuu_ignore_bmap() {
169 return uuu_get_bmap_mode() == bmap_mode::Ignore;
172 #endif