int zigbee_init(unsigned long baud) { int result; charZigbee.TxQueueLength = 10; charZigbee.RxQueueLength = 20; charZigbee.QueueWait = 0; charZigbee.PortBase = UART2_BASE; result = prepare_device(&charZigbee); if(result){ printf("Zigbee queue creation fail\n"); return result; } SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); GPIOPinTypeUART(GPIO_PORTG_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTConfigSetExpClk(UART2_BASE, SysCtlClockGet(), baud, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); IntRegister(INT_UART2, zigbee_isr); UARTIntDisable(UART2_BASE, 0xFFFFFFFF); IntPrioritySet(INT_UART2,configKERNEL_INTERRUPT_PRIORITY); IntEnable(INT_UART2); UARTEnable(UART2_BASE); UARTFIFODisable(UART2_BASE); UARTIntEnable(UART2_BASE, UART_INT_TX | UART_INT_RX); return result; }
static int run_tcases_per_fs(void) { int ret = 0; unsigned int i; const char *const *filesystems = tst_get_supported_fs_types(); if (!filesystems[0]) tst_brk(TCONF, "There are no supported filesystems"); for (i = 0; filesystems[i]; i++) { tdev.fs_type = filesystems[i]; prepare_device(); ret = fork_testrun(); if (mntpoint_mounted) { tst_umount(tst_test->mntpoint); mntpoint_mounted = 0; } if (ret == TCONF) { update_results(ret); continue; } if (ret == 0) continue; do_exit(ret); } return ret; }
static int prepare_audiounit(_THIS, void *handle, int iscapture, const AudioStreamBasicDescription * strdesc) { OSStatus result = noErr; AURenderCallbackStruct callback; AudioComponentDescription desc; AudioComponent comp = NULL; const AudioUnitElement output_bus = 0; const AudioUnitElement input_bus = 1; const AudioUnitElement bus = ((iscapture) ? input_bus : output_bus); const AudioUnitScope scope = ((iscapture) ? kAudioUnitScope_Output : kAudioUnitScope_Input); #if MACOSX_COREAUDIO if (!prepare_device(this, handle, iscapture)) { return 0; } #endif SDL_zero(desc); desc.componentType = kAudioUnitType_Output; desc.componentManufacturer = kAudioUnitManufacturer_Apple; #if MACOSX_COREAUDIO desc.componentSubType = kAudioUnitSubType_DefaultOutput; #else desc.componentSubType = kAudioUnitSubType_RemoteIO; #endif comp = AudioComponentFindNext(NULL, &desc); if (comp == NULL) { SDL_SetError("Couldn't find requested CoreAudio component"); return 0; } /* Open & initialize the audio unit */ result = AudioComponentInstanceNew(comp, &this->hidden->audioUnit); CHECK_RESULT("AudioComponentInstanceNew"); this->hidden->audioUnitOpened = 1; #if MACOSX_COREAUDIO result = AudioUnitSetProperty(this->hidden->audioUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &this->hidden->deviceID, sizeof(AudioDeviceID)); CHECK_RESULT ("AudioUnitSetProperty (kAudioOutputUnitProperty_CurrentDevice)"); #endif /* Set the data format of the audio unit. */ result = AudioUnitSetProperty(this->hidden->audioUnit, kAudioUnitProperty_StreamFormat, scope, bus, strdesc, sizeof(*strdesc)); CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_StreamFormat)"); /* Set the audio callback */ SDL_memset(&callback, 0, sizeof(AURenderCallbackStruct)); callback.inputProc = ((iscapture) ? inputCallback : outputCallback); callback.inputProcRefCon = this; result = AudioUnitSetProperty(this->hidden->audioUnit, kAudioUnitProperty_SetRenderCallback, scope, bus, &callback, sizeof(callback)); CHECK_RESULT ("AudioUnitSetProperty (kAudioUnitProperty_SetRenderCallback)"); /* Calculate the final parameters for this audio specification */ SDL_CalculateAudioSpec(&this->spec); /* Allocate a sample buffer */ this->hidden->bufferOffset = this->hidden->bufferSize = this->spec.size; this->hidden->buffer = SDL_malloc(this->hidden->bufferSize); result = AudioUnitInitialize(this->hidden->audioUnit); CHECK_RESULT("AudioUnitInitialize"); /* Finally, start processing of the audio unit */ result = AudioOutputUnitStart(this->hidden->audioUnit); CHECK_RESULT("AudioOutputUnitStart"); #if MACOSX_COREAUDIO /* Fire a callback if the device stops being "alive" (disconnected, etc). */ AudioObjectAddPropertyListener(this->hidden->deviceID, &alive_address, device_unplugged, this); #endif /* We're running! */ return 1; }
int main(int argc, char **argv) { char dbpath[PATH_MAX] = "/tmp/tesla.rrd"; libusb_context *ctx = NULL; libusb_device_handle *dev_handle = NULL; signal(SIGINT, sigint_handler); int c = 0; while ((c = getopt(argc, argv, "hd")) != -1) { switch (c) { case 'd': ++_debug; break; case 'h': default: usage(); return 0; } } argc -= optind; argv += optind; if (argc == 1) realpath(argv[0], dbpath); if (access(dbpath, F_OK) == -1) { DPRINTF(1, "Creating db: %s\n", dbpath); if (RRD_create(dbpath, 60)) return -1; } DPRINTF(2, "Using DB: %s\n", dbpath); DPRINTF(1, "Please plug your CM160 device...\n"); if (scan_usb(ctx, &dev_handle)) return 1; if (prepare_device(dev_handle)) return 1; DPRINTF(1, "Start acquiring data...\n"); struct record_history *hist; if (init_history(&hist)) return 1; while (!stop) if (get_data(dbpath, hist, dev_handle)) stop = 1; DPRINTF(2, "\nClosing connection with the device\n"); if (libusb_release_interface(dev_handle, INTERFACE)) fprintf(stderr, "Cannot release interface.\n"); libusb_reset_device(dev_handle); libusb_close(dev_handle); libusb_exit(ctx); free_history(&hist); return 0; }
static int usb_open(void *transport_config){ int r; sco_state_machine_init(); sco_ring_init(); handle_packet = NULL; // default endpoint addresses event_in_addr = 0x81; // EP1, IN interrupt acl_in_addr = 0x82; // EP2, IN bulk acl_out_addr = 0x02; // EP2, OUT bulk sco_in_addr = 0x83; // EP3, IN isochronous sco_out_addr = 0x03; // EP3, OUT isochronous // USB init r = libusb_init(NULL); if (r < 0) return -1; libusb_state = LIB_USB_OPENED; // configure debug level libusb_set_debug(NULL, LIBUSB_LOG_LEVEL_WARNING); #ifdef HAVE_USB_VENDOR_ID_AND_PRODUCT_ID // Use a specified device log_info("Want vend: %04x, prod: %04x", USB_VENDOR_ID, USB_PRODUCT_ID); handle = libusb_open_device_with_vid_pid(NULL, USB_VENDOR_ID, USB_PRODUCT_ID); if (!handle){ log_error("libusb_open_device_with_vid_pid failed!"); usb_close(handle); return -1; } log_info("libusb open %d, handle %p", r, handle); r = prepare_device(handle); if (r < 0){ usb_close(handle); return -1; } #else // Scan system for an appropriate devices libusb_device **devs; ssize_t cnt; log_info("Scanning for USB Bluetooth device"); cnt = libusb_get_device_list(NULL, &devs); if (cnt < 0) { usb_close(handle); return -1; } int startIndex = 0; dev = NULL; while (1){ int deviceIndex = scan_for_bt_device(devs, startIndex); if (deviceIndex < 0){ break; } startIndex = deviceIndex+1; log_info("USB Bluetooth device found, index %u", deviceIndex); handle = NULL; r = libusb_open(devs[deviceIndex], &handle); if (r < 0) { log_error("libusb_open failed!"); handle = NULL; continue; } log_info("libusb open %d, handle %p", r, handle); // reset device libusb_reset_device(handle); if (r < 0) { log_error("libusb_reset_device failed!"); libusb_close(handle); handle = NULL; continue; } // device found r = prepare_device(handle); if (r < 0){ continue; } libusb_state = LIB_USB_INTERFACE_CLAIMED; break; } libusb_free_device_list(devs, 1); if (handle == 0){ log_error("No USB Bluetooth device found"); return -1; } scan_for_bt_endpoints(); #endif // allocate transfer handlers int c; for (c = 0 ; c < ASYNC_BUFFERS ; c++) { event_in_transfer[c] = libusb_alloc_transfer(0); // 0 isochronous transfers Events acl_in_transfer[c] = libusb_alloc_transfer(0); // 0 isochronous transfers ACL in if ( !event_in_transfer[c] || !acl_in_transfer[c]) { usb_close(handle); return LIBUSB_ERROR_NO_MEM; } } command_out_transfer = libusb_alloc_transfer(0); acl_out_transfer = libusb_alloc_transfer(0); // TODO check for error libusb_state = LIB_USB_TRANSFERS_ALLOCATED; #ifdef HAVE_SCO // incoming for (c = 0 ; c < ASYNC_BUFFERS ; c++) { sco_in_transfer[c] = libusb_alloc_transfer(NUM_ISO_PACKETS); // isochronous transfers SCO in log_info("Alloc iso transfer"); if (!sco_in_transfer[c]) { usb_close(handle); return LIBUSB_ERROR_NO_MEM; } // configure sco_in handlers libusb_fill_iso_transfer(sco_in_transfer[c], handle, sco_in_addr, hci_sco_in_buffer[c], SCO_PACKET_SIZE, NUM_ISO_PACKETS, async_callback, NULL, 0); libusb_set_iso_packet_lengths(sco_in_transfer[c], ISO_PACKET_SIZE); r = libusb_submit_transfer(sco_in_transfer[c]); log_info("Submit iso transfer res = %d", r); if (r) { log_error("Error submitting isochronous in transfer %d", r); usb_close(handle); return r; } } // outgoing for (c=0; c < SCO_RING_BUFFER_COUNT ; c++){ sco_ring_transfers[c] = libusb_alloc_transfer(NUM_ISO_PACKETS); // 1 isochronous transfers SCO out - up to 3 parts } #endif for (c = 0 ; c < ASYNC_BUFFERS ; c++) { // configure event_in handlers libusb_fill_interrupt_transfer(event_in_transfer[c], handle, event_in_addr, hci_event_in_buffer[c], HCI_ACL_BUFFER_SIZE, async_callback, NULL, 0) ; r = libusb_submit_transfer(event_in_transfer[c]); if (r) { log_error("Error submitting interrupt transfer %d", r); usb_close(handle); return r; } // configure acl_in handlers libusb_fill_bulk_transfer(acl_in_transfer[c], handle, acl_in_addr, hci_acl_in_buffer[c] + HCI_INCOMING_PRE_BUFFER_SIZE, HCI_ACL_BUFFER_SIZE, async_callback, NULL, 0) ; r = libusb_submit_transfer(acl_in_transfer[c]); if (r) { log_error("Error submitting bulk in transfer %d", r); usb_close(handle); return r; } } // Check for pollfds functionality doing_pollfds = libusb_pollfds_handle_timeouts(NULL); // NOTE: using pollfds doesn't work on Linux, so it is disable until further investigation here doing_pollfds = 0; if (doing_pollfds) { log_info("Async using pollfds:"); const struct libusb_pollfd ** pollfd = libusb_get_pollfds(NULL); for (num_pollfds = 0 ; pollfd[num_pollfds] ; num_pollfds++); pollfd_data_sources = malloc(sizeof(data_source_t) * num_pollfds); if (!pollfd_data_sources){ log_error("Cannot allocate data sources for pollfds"); usb_close(handle); return 1; } for (r = 0 ; r < num_pollfds ; r++) { data_source_t *ds = &pollfd_data_sources[r]; ds->fd = pollfd[r]->fd; ds->process = usb_process_ds; run_loop_add_data_source(ds); log_info("%u: %p fd: %u, events %x", r, pollfd[r], pollfd[r]->fd, pollfd[r]->events); } free(pollfd); } else { log_info("Async using timers:"); usb_timer.process = usb_process_ts; run_loop_set_timer(&usb_timer, AYSNC_POLLING_INTERVAL_MS); run_loop_add_timer(&usb_timer); usb_timer_active = 1; } return 0; }
static void do_setup(int argc, char *argv[]) { if (!tst_test) tst_brk(TBROK, "No tests to run"); if (tst_test->tconf_msg) tst_brk(TCONF, "%s", tst_test->tconf_msg); assert_test_fn(); tid = get_tid(argv); if (tst_test->sample) tst_test = tst_timer_test_setup(tst_test); parse_opts(argc, argv); if (tst_test->needs_root && geteuid() != 0) tst_brk(TCONF, "Test needs to be run as root"); if (tst_test->min_kver) check_kver(); if (tst_test->format_device) tst_test->needs_device = 1; if (tst_test->mount_device) { tst_test->needs_device = 1; tst_test->format_device = 1; } if (tst_test->all_filesystems) tst_test->needs_device = 1; setup_ipc(); if (needs_tmpdir() && !tst_tmpdir_created()) tst_tmpdir(); if (tst_test->mntpoint) SAFE_MKDIR(tst_test->mntpoint, 0777); if ((tst_test->needs_rofs || tst_test->mount_device || tst_test->all_filesystems) && !tst_test->mntpoint) { tst_brk(TBROK, "tst_test->mntpoint must be set!"); } if (tst_test->needs_rofs) { /* If we failed to mount read-only tmpfs. Fallback to * using a device with empty read-only filesystem. */ if (mount(NULL, tst_test->mntpoint, "tmpfs", MS_RDONLY, NULL)) { tst_res(TINFO | TERRNO, "Can't mount tmpfs read-only" " at %s, setting up a device instead\n", tst_test->mntpoint); tst_test->mount_device = 1; tst_test->needs_device = 1; tst_test->format_device = 1; tst_test->mnt_flags = MS_RDONLY; } else { mntpoint_mounted = 1; } } if (tst_test->needs_device && !mntpoint_mounted) { tdev.dev = tst_acquire_device_(NULL, tst_test->dev_min_size); if (!tdev.dev) tst_brk(TCONF, "Failed to acquire device"); tst_device = &tdev; if (tst_test->dev_fs_type) tdev.fs_type = tst_test->dev_fs_type; else tdev.fs_type = tst_dev_fs_type(); if (!tst_test->all_filesystems) prepare_device(); } if (tst_test->resource_files) copy_resources(); }