From 9df66d5c96af6eabf8dc6075a6421b3d8469149f Mon Sep 17 00:00:00 2001 From: Stefan Ritt Date: Wed, 12 Apr 2017 10:26:50 +0200 Subject: [PATCH] =?UTF-8?q?Implemented=20=E2=80=9C-l=E2=80=9D=20option=20t?= =?UTF-8?q?o=20check=20USB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../drscl/drs_exam.xcodeproj/project.pbxproj | 13 ++++++- software/drscl/drscl.cpp | 21 +++++++++++- .../drscl/drscl.xcodeproj/project.pbxproj | 2 ++ software/include/musbstd.h | 2 +- software/src/DRS.cpp | 5 +-- software/src/musbstd.c | 34 +++++++++++++------ 6 files changed, 62 insertions(+), 15 deletions(-) diff --git a/software/drscl/drs_exam.xcodeproj/project.pbxproj b/software/drscl/drs_exam.xcodeproj/project.pbxproj index d6e4439..86e992c 100644 --- a/software/drscl/drs_exam.xcodeproj/project.pbxproj +++ b/software/drscl/drs_exam.xcodeproj/project.pbxproj @@ -121,7 +121,7 @@ D5446422141E1BB40027AF52 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0500; + LastUpgradeCheck = 0820; ORGANIZATIONNAME = PSI; }; buildConfigurationList = D5446425141E1BB40027AF52 /* Build configuration list for PBXProject "drs_exam" */; @@ -166,12 +166,18 @@ CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -200,12 +206,17 @@ CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_NO_COMMON_BLOCKS = YES; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; diff --git a/software/drscl/drscl.cpp b/software/drscl/drscl.cpp index 1b808ac..faf3fca 100644 --- a/software/drscl/drscl.cpp +++ b/software/drscl/drscl.cpp @@ -49,6 +49,7 @@ const char *drscl_svn_revision = "$Id: drscl.cpp 21435 2014-07-30 13:02:31Z ritt $"; +void lusb(void); void print_help(); void clear_screen(); int match(const char *str, const char *cmd); @@ -177,6 +178,19 @@ void ProgressBar::Progress(int prog) /*------------------------------------------------------------------*/ +void lusb(void) +{ +#ifdef HAVE_USB + MUSB_INTERFACE *usb_interface; + + musb_open(&usb_interface, 0x04B4, 0x1175, 0, 1, 0, 1); + musb_close(usb_interface); + +#endif // HAVE_USB +} + +/*------------------------------------------------------------------*/ + void cmd_loop() { int i, j, idx, i_start, i_end, nparam, calib, status, debug, cascading, @@ -1636,8 +1650,13 @@ void cmd_loop() /*------------------------------------------------------------------*/ -int main() +int main(int argc, char *argv[]) { + if (argc == 2 && argv[1][1] == 'l') { + lusb(); + return 0; + } + printf("DRS command line tool, Revision %d\n", atoi(drscl_svn_revision+15)); printf("Type 'help' for a list of available commands.\n\n"); diff --git a/software/drscl/drscl.xcodeproj/project.pbxproj b/software/drscl/drscl.xcodeproj/project.pbxproj index b096066..91b025f 100644 --- a/software/drscl/drscl.xcodeproj/project.pbxproj +++ b/software/drscl/drscl.xcodeproj/project.pbxproj @@ -252,6 +252,7 @@ IOKit, "-framework", Carbon, + "--stdlib=libc++", ); PRELINK_LIBS = ""; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -273,6 +274,7 @@ IOKit, "-framework", Carbon, + "--stdlib=libc++", ); PRELINK_LIBS = ""; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/software/include/musbstd.h b/software/include/musbstd.h index 45a6981..f4e102e 100644 --- a/software/include/musbstd.h +++ b/software/include/musbstd.h @@ -80,7 +80,7 @@ extern "C" { #endif #endif -int EXPRT musb_open(MUSB_INTERFACE **musb_interface, int vendor, int product, int instance, int configuration, int usbinterface); +int EXPRT musb_open(MUSB_INTERFACE **musb_interface, int vendor, int product, int instance, int configuration, int usbinterface, int debug); int EXPRT musb_close(MUSB_INTERFACE *musb_interface); int EXPRT musb_write(MUSB_INTERFACE *musb_interface,int endpoint,const void *buf,int count,int timeout_ms); int EXPRT musb_read(MUSB_INTERFACE *musb_interface,int endpoint,void *buf,int count,int timeout_ms); diff --git a/software/src/DRS.cpp b/software/src/DRS.cpp index 05d98aa..62415d4 100644 --- a/software/src/DRS.cpp +++ b/software/src/DRS.cpp @@ -308,7 +308,7 @@ DRS::DRS() found = 0; /* check for USB-Mezzanine test board */ - if (musb_open(&usb_interface, 0x10C4, 0x1175, index, 1, 0) == MUSB_SUCCESS) { + if (musb_open(&usb_interface, 0x10C4, 0x1175, index, 1, 0, 0) == MUSB_SUCCESS) { /* check ID */ buffer[0] = USB_CMD_IDENT; @@ -332,7 +332,7 @@ DRS::DRS() } /* check for DRS4 evaluation board */ - if (musb_open(&usb_interface, 0x04B4, 0x1175, index, 1, 0) == MUSB_SUCCESS) { + if (musb_open(&usb_interface, 0x04B4, 0x1175, index, 1, 0, 0) == MUSB_SUCCESS) { /* check ID */ if (musb_get_device(usb_interface) != 1) { @@ -393,6 +393,7 @@ DRS::~DRS() /*------------------------------------------------------------------*/ + void DRS::SortBoards() { /* sort boards according to serial number (simple bubble sort) */ diff --git a/software/src/musbstd.c b/software/src/musbstd.c index 1862349..20068a8 100755 --- a/software/src/musbstd.c +++ b/software/src/musbstd.c @@ -142,7 +142,7 @@ IOReturn darwin_configure_device(MUSB_INTERFACE* musb) #endif -int musb_open(MUSB_INTERFACE **musb_interface, int vendor, int product, int instance, int configuration, int usbinterface) +int musb_open(MUSB_INTERFACE **musb_interface, int vendor, int product, int instance, int configuration, int usbinterface, int debug) { #if defined(HAVE_LIBUSB) @@ -169,7 +169,7 @@ int musb_open(MUSB_INTERFACE **musb_interface, int vendor, int product, int inst } status = usb_set_configuration(udev, configuration); - if (status < 0) { + if (status != 0) { fprintf(stderr, "musb_open: usb_set_configuration() error %d (%s)\n", status, strerror(-status)); fprintf(stderr, @@ -180,7 +180,7 @@ int musb_open(MUSB_INTERFACE **musb_interface, int vendor, int product, int inst /* see if we have write access */ status = usb_claim_interface(udev, usbinterface); - if (status < 0) { + if (status != 0) { fprintf(stderr, "musb_open: usb_claim_interface() error %d (%s)\n", status, strerror(-status)); @@ -222,18 +222,25 @@ int musb_open(MUSB_INTERFACE **musb_interface, int vendor, int product, int inst if (first_call) { first_call = 0; - libusb_init(NULL); - // libusb_set_debug(NULL, 3); + status = libusb_init(NULL); + if (status != 0) + printf("libusb_init returns error code %d\n", status); + if (debug) + libusb_set_debug(NULL, 3); } n = libusb_get_device_list(NULL, &dev_list); + if (debug) + printf("Found %d USB devices\n", n); for (i=0 ; idev = dev; (*musb_interface)->usb_configuration = configuration; (*musb_interface)->usb_interface = usbinterface; - return MUSB_SUCCESS; - + + if (debug) + printf("Found DRS4 evaluation board and successfully claimed interface\n"); + else + return MUSB_SUCCESS; } count++; } @@ -472,7 +482,11 @@ int musb_close(MUSB_INTERFACE *musb_interface) #elif defined(HAVE_LIBUSB10) int status; + if (!musb_interface) + return 0; + status = libusb_release_interface(musb_interface->dev, musb_interface->usb_interface); + if (status < 0) fprintf(stderr, "musb_close: libusb_release_interface() error %d\n", status);