1 #ifndef __ezusb_H 2 #define __ezusb_H 3 /* 4 * Copyright (c) 2001 Stephen Williams (steve@icarus.com) 5 * Copyright (c) 2002 David Brownell (dbrownell@users.sourceforge.net) 6 * 7 * This source code is free software; you can redistribute it 8 * and/or modify it in source code form under the terms of the GNU 9 * General Public License as published by the Free Software 10 * Foundation; either version 2 of the License, or (at your option) 11 * any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 21 */ 22 23 struct ezusb_backend; 24 25 typedef int ezusb_open_func_t(struct ezusb_backend *backend, 26 const char *devname, int mode); 27 typedef int ezusb_close_func_t(struct ezusb_backend *backend); 28 /* Type of a handler responsible for handling USB */ 29 typedef int ezusb_ctrl_msg_func_t(struct ezusb_backend *backend, 30 unsigned char requestType, unsigned char request, unsigned short 31 value, unsigned short index, unsigned char *data, size_t length); 32 33 enum { 34 EZUSB_INPUT, 35 EZUSB_OUTPUT 36 }; 37 38 /* What particular backends provide */ 39 struct ezusb_backend { 40 const char *name; 41 void *priv_data; 42 ezusb_open_func_t *open; 43 ezusb_close_func_t *close; 44 ezusb_ctrl_msg_func_t *ctrl_msg; 45 }; 46 47 /* Our main functions, that will call backend-specific routines */ 48 int ezusb_open(struct ezusb_backend *be, const char *device, int mode); 49 int ezusb_close(struct ezusb_backend *be); 50 int ezusb_ctrl_msg(struct ezusb_backend *backend, unsigned char 51 requestType, unsigned char request, unsigned short value, unsigned 52 short index, unsigned char *data, size_t length); 53 54 /* Our backend dispatcher */ 55 struct ezusb_backend *dispatch_backend(const char *backend); 56 57 #ifdef __linux__ 58 /* Linux specific handler for USB */ 59 extern struct ezusb_backend ezusb_backend_linux; 60 #endif 61 62 #if !defined(__linux__) || defined(LIBUSB_SUPPORT) 63 extern struct ezusb_backend ezusb_backend_libusb; 64 #endif 65 66 /* 67 * This function loads the firmware from the given file into RAM. 68 * The file is assumed to be in Intel HEX format. If fx2 is set, uses 69 * appropriate reset commands. Stage == 0 means this is a single stage 70 * load (or the first of two stages). Otherwise it's the second of 71 * two stages; the caller preloaded the second stage loader. 72 * 73 * The target processor is reset at the end of this download. 74 */ 75 extern int ezusb_load_ram (struct ezusb_backend *backend, const char *path, 76 const char *type, int stage); 77 78 /* 79 * This function stores the firmware from the given file into EEPROM. 80 * The file is assumed to be in Intel HEX format. This uses the right 81 * CPUCS address to terminate the EEPROM load with a reset command, 82 * where FX parts behave differently than FX2 ones. The configuration 83 * byte is as provided here (zero for an21xx parts) and the EEPROM 84 * type is set so that the microcontroller will boot from it. 85 * 86 * The caller must have preloaded a second stage loader that knows 87 * how to respond to the EEPROM write request. 88 */ 89 extern int ezusb_load_eeprom ( 90 struct ezusb_backend *backend, /* USB backend handle */ 91 const char *path, /* path to hexfile */ 92 const char *type, /* fx, fx2, an21 */ 93 int config /* config byte for fx/fx2; else zero */ 94 ); 95 96 97 /* boolean flag, says whether to write extra messages to stderr */ 98 extern int verbose; 99 100 /* Our error logging function */ 101 extern void logerror(const char *format, ...) 102 __attribute__ ((format (printf, 1, 2))); 103 104 /* 105 * $Log: ezusb.h,v $ 106 * Revision 1.4 2008/10/13 21:25:29 dbrownell 107 * Whitespace fixes. 108 * 109 * Revision 1.3 2002/04/12 00:28:21 dbrownell 110 * support "-t an21" to program EEPROMs for those microcontrollers 111 * 112 * Revision 1.2 2002/02/26 19:55:05 dbrownell 113 * 2nd stage loader support 114 * 115 * Revision 1.1 2001/06/12 00:00:50 stevewilliams 116 * Added the fxload program. 117 * Rework root makefile and hotplug.spec to install in prefix 118 * location without need of spec file for install. 119 * 120 */ 121 #endif 122