static const char *do_libdivecomputer_import(device_data_t *data) { device_t *device = NULL; device_status_t rc; rc = device_open(data->devname, data->type, &device); if (rc != DEVICE_STATUS_SUCCESS) return "Unable to open %s (%s)"; // Register the event handler. int events = DEVICE_EVENT_WAITING | DEVICE_EVENT_PROGRESS | DEVICE_EVENT_DEVINFO | DEVICE_EVENT_CLOCK; rc = device_set_events(device, events, event_cb, data); if (rc != DEVICE_STATUS_SUCCESS) { device_close(device); return "Error registering the event handler."; } // Register the cancellation handler. rc = device_set_cancel(device, cancel_cb, data); if (rc != DEVICE_STATUS_SUCCESS) { device_close(device); return "Error registering the cancellation handler."; } rc = import_device_data(device, data); if (rc != DEVICE_STATUS_SUCCESS) { device_close(device); return "Dive data import error"; } device_close(device); return NULL; }
device_status_t test_dump_memory_dives (const char* name, const char* filename) { device_t *device = NULL; message ("reefnet_sensusultra_device_open\n"); device_status_t rc = reefnet_sensusultra_device_open (&device, name); if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Error opening serial port."); return rc; } time_t now = time (NULL); char datetime[21] = {0}; strftime (datetime, sizeof (datetime), "%Y-%m-%dT%H:%M:%SZ", gmtime (&now)); message ("time=%lu (%s)\n", (unsigned long)now, datetime); message ("device_foreach\n"); rc = device_foreach (device, NULL, NULL); if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Cannot read dives."); device_close (device); return rc; } message ("device_close\n"); rc = device_close (device); if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Cannot close device."); return rc; } return DEVICE_STATUS_SUCCESS; }
static int usb_init(void) { int ret = 0; struct device *usb_dev; struct device *hub_dev; hub_dev = device_open(DEVICE_TYPE_HSIC_DEVICE, 1); if (!hub_dev) { printf("Error: can't open USB3813 device\n"); return -ENODEV; } device_hsic_hold_reset(hub_dev); usb_dev = device_open(DEVICE_TYPE_USB_PCD, 0); if (!usb_dev) { printf("Error: can't open USB device\n"); device_close(hub_dev); return -ENODEV; } device_hsic_release_reset(hub_dev); device_close(hub_dev); usbdev_apbinitialize(usb_dev, &usb_driver); return ret; }
static int v4l_suspend(vbi_capture_v4l *v) { int fd; v4l_read_stop(v); if (v->read_active) { printv("Suspending read: re-open device...\n"); /* hack: cannot suspend read to allow SVBIFMT, need to close device */ fd = device_open (v->capture.sys_log_fp, v->p_dev_name, O_RDWR, 0); if (-1 == fd) { printv ("v4l2-suspend: failed to re-open " "VBI device: %d: %s\n", errno, strerror(errno)); return -1; } /* use dup2() to keep the same fd, which may be used by our client */ device_close (v->capture.sys_log_fp, v->fd); dup2 (fd, v->fd); device_close (v->capture.sys_log_fp, fd); v->read_active = FALSE; } return 0; }
device_status_t test_dump_memory (const char* filename) { device_t *device = NULL; message ("uwatec_smart_device_open\n"); device_status_t rc = uwatec_smart_device_open (&device); if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Cannot open device."); return rc; } message ("device_version\n"); unsigned char version[UWATEC_SMART_VERSION_SIZE] = {0}; rc = device_version (device, version, sizeof (version)); if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Cannot identify computer."); device_close (device); return rc; } dc_buffer_t *buffer = dc_buffer_new (0); message ("device_dump\n"); rc = device_dump (device, buffer); if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Cannot read memory."); dc_buffer_free (buffer); device_close (device); return rc; } message ("Dumping data\n"); FILE* fp = fopen (filename, "wb"); if (fp != NULL) { fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp); fclose (fp); } dc_buffer_free (buffer); message ("device_close\n"); rc = device_close (device); if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Cannot close device."); return rc; } return DEVICE_STATUS_SUCCESS; }
device_status_t test_dump_memory (const char* name, const char* filename) { device_t *device = NULL; message ("oceanic_atom2_device_open\n"); device_status_t rc = oceanic_atom2_device_open (&device, name); if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Error opening serial port."); return rc; } dc_buffer_t *buffer = dc_buffer_new (0); message ("device_dump\n"); rc = device_dump (device, buffer); if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Cannot read memory."); dc_buffer_free (buffer); device_close (device); return rc; } message ("Dumping data\n"); FILE* fp = fopen (filename, "wb"); if (fp != NULL) { fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp); fclose (fp); } dc_buffer_free (buffer); message ("device_foreach\n"); rc = device_foreach (device, NULL, NULL); if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Cannot read dives."); device_close (device); return rc; } message ("device_close\n"); rc = device_close (device); if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Cannot close device."); return rc; } return DEVICE_STATUS_SUCCESS; }
int main(int argc, char *argv[]) { device_t tty_dev; int i, error; char buf[] = "?\n"; size_t len; sys_log("Keyboard test program\n"); error = device_open("tty", 0, &tty_dev); if (error) sys_log("device open error!\n"); sys_log("Press any key 10 times\n"); for (i = 0; i < 10; i++) { len = 1; device_read(tty_dev, buf, &len, 0); sys_log(buf); } error = device_close(tty_dev); if (error) sys_log("device close error!\n"); sys_log("Test completed.\n"); return 0; }
/** * @brief Close SPI device * * This function is called when the caller is no longer using this driver. It * should release or close all resources that were allocated by the open() * function. This function should be called after the open() function. If the * device is not opened yet, this function should return without any operations. * * @param dev pointer to structure of device data */ static void tsb_spi_dev_close(struct device *dev) { int i; struct tsb_spi_dev_info *info = NULL; /* check input parameter */ if (!dev || !device_get_private(dev)) { return; } info = device_get_private(dev); sem_wait(&info->lock); up_disable_irq(TSB_IRQ_SPI); irq_detach(TSB_IRQ_SPI); tsb_spi_hw_deinit(info); for (i = 0; i < info->num_boards; i++) { device_close(info->dev_spi_board[i]); info->dev_spi_board[i] = NULL; } info->state = TSB_SPI_STATE_CLOSED; sem_post(&info->lock); }
static int gb_ptp_init(unsigned int cport) { int ret = 0; ptp_info = zalloc(sizeof(*ptp_info)); if (!ptp_info) { gb_info("%s(): failed to allocate memory\n", __func__); ret = -ENOMEM; goto done; } ptp_info->cport = cport; ptp_info->dev = device_open(DEVICE_TYPE_PTP_HW, 0); if (!ptp_info->dev) { gb_info("%s(): failed to open device\n", __func__); ret = -EIO; goto err; } ret = device_ptp_register_callback(ptp_info->dev, gb_ptp_changed); if (ret) { gb_info("%s(): failed to register ptp changed callback\n", __func__); goto err; } return 0; err: device_close(ptp_info->dev); free(ptp_info); done: return ret; }
int main(int argc, char *argv[]) { int i, fuse_stat; printf("mounting file system...\n"); for(i = 1; i < argc && (argv[i][0] == '-'); i++) ; if (!device_open(realpath(argv[i], NULL)) ) { printf("Cannot open device file %s\n", argv[i]); return 1; } for(; i < argc; i++) argv[i] = argv[i+1]; argc--; fuse_stat = fuse_main(argc, argv, &fs_oper, NULL); device_close(); printf("fuse_main returned %d\n", fuse_stat); return fuse_stat; }
static error_t pc_mouse_start (void *handle) { error_t err; char device_name[9]; int devnum = majordev << 3 | minordev; device_t device_master; sprintf (device_name, "mouse%d", devnum); err = get_privileged_ports (0, &device_master); if (err) return err; err = device_open (device_master, D_READ, device_name, &mousedev); mach_port_deallocate (mach_task_self (), device_master); if (err) return ENODEV; err = driver_add_input (&pc_mouse_ops, NULL); if (err) { device_close (mousedev); mach_port_deallocate (mach_task_self (), mousedev); return err; } cthread_detach (cthread_fork (input_loop, NULL)); if (repeater_node) setrepeater (repeater_node); return 0; }
int kernel_main() { init_kernel_stack(KERN_HEAP_OFFSET); init_device_drivers(); device_open(TTY, 0); k_printf("entered into main kernel..!\n"); k_printf("and initialized device drivers.\n"); init_gdt(); k_printf("initialized protected mode.\n"); check_physical_mem_size(); k_printf("physical memory size : %d megabytes.\n", physical_mem_size>>20); init_paging(); k_printf("initialized paging.\n"); init_vfs(); k_printf("initialized file system (fat16).\n"); init_idt(); k_printf("initialized interrupt.\n"); init_tss(); struct fat16_file_kt f; f = fs_open_fat16("/apps/snake.bin"); create_task(f.buffer, f.information.file_size); dump_task_queue(); current_task = pop_task_queue(); create_task(init1, 256); create_task(init2, 256); create_task(init3, 256); create_task(init4, 256); create_task(init5, 256); dump_task_queue(); /* do { struct task_struct_kt *cur = task_head; do { k_printf("#%d - stack %x, start %x\n", cur->tid, cur->sp_page, cur->start_entry); cur = cur->next; } while (cur != task_head); } while(0); */ //for(;;); // user page가 제대로 동작할때까지 막아둠. cli(); SCHEDULE(); for(;;); device_close(TTY, 0); return 0; }
void prog_exit() { printf("\r\n"); device_close(); libusb_exit(NULL); exit(0); }
device_status_t test_dump_memory (const char* name, const char* filename) { device_t *device = NULL; message ("reefnet_sensuspro_device_open\n"); device_status_t rc = reefnet_sensuspro_device_open (&device, name); if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Error opening serial port."); return rc; } time_t now = time (NULL); char datetime[21] = {0}; strftime (datetime, sizeof (datetime), "%Y-%m-%dT%H:%M:%SZ", gmtime (&now)); message ("time=%lu (%s)\n", (unsigned long)now, datetime); dc_buffer_t *buffer = dc_buffer_new (0); message ("device_dump\n"); rc = device_dump (device, buffer); if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Cannot read memory."); dc_buffer_free (buffer); device_close (device); return rc; } message ("Dumping data\n"); FILE* fp = fopen (filename, "wb"); if (fp != NULL) { fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp); fclose (fp); } dc_buffer_free (buffer); message ("device_close\n"); rc = device_close (device); if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Cannot close device."); return rc; } return DEVICE_STATUS_SUCCESS; }
int main(int argc, char *argv[]) { u_int led; u_int count; u_int status; u_int all_mask = 0; device_t dev; int err; printf("led driver test program\n"); printf("Open led device... "); err = device_open("led", O_RDWR, &dev); check(err); if (err) { return 0; } printf("Query led count... "); check(led_count(dev, &count)); printf("Count is %d\n", count); timer_sleep(1000, 0); for (led = 0; led < count; ++led) { printf("Turn on LED %d... ", led); check(led_on(dev, 1 << led)); timer_sleep(1000, 0); printf("Turn off LED %d... ", led); check(led_off(dev, 1 << led)); timer_sleep(1000, 0); all_mask |= (1 << led); } printf("Turn on all LEDs... "); check(led_on(dev, all_mask)); printf("Get LED status... "); check(led_status(dev, &status)); printf("Status is %x == %x\n", status, all_mask); timer_sleep(1000, 0); printf("Turn off all LEDs... "); check(led_off(dev, all_mask)); printf("Get LED status... "); check(led_status(dev, &status)); printf("Status is %x == 0\n", status); timer_sleep(1000, 0); printf("Close the device..."); err = device_close(dev); check(err); return 0; }
/* * Given the root disk device name, read the label from * the device, and construct a configuration nvlist. */ int vdev_disk_read_rootlabel(char *devname, nvlist_t **config) { vdev_label_t *label; struct device *dev; uint64_t size; int l; int error = -1; char *minor_name; error = device_open(devname + 5, DO_RDWR, &dev); if (error) return error; size = P2ALIGN_TYPED(dev->size, sizeof (vdev_label_t), uint64_t); label = kmem_alloc(sizeof (vdev_label_t), KM_SLEEP); *config = NULL; for (l = 0; l < VDEV_LABELS; l++) { uint64_t offset, state, txg = 0; /* read vdev label */ offset = vdev_label_offset(size, l, 0); if (vdev_disk_physio(dev, (caddr_t)label, VDEV_SKIP_SIZE + VDEV_PHYS_SIZE, offset, 0) != 0) continue; if (nvlist_unpack(label->vl_vdev_phys.vp_nvlist, sizeof (label->vl_vdev_phys.vp_nvlist), config, 0) != 0) { *config = NULL; continue; } if (nvlist_lookup_uint64(*config, ZPOOL_CONFIG_POOL_STATE, &state) != 0 || state >= POOL_STATE_DESTROYED) { nvlist_free(*config); *config = NULL; continue; } if (nvlist_lookup_uint64(*config, ZPOOL_CONFIG_POOL_TXG, &txg) != 0 || txg == 0) { nvlist_free(*config); *config = NULL; continue; } break; } kmem_free(label, sizeof (vdev_label_t)); device_close(dev); if (*config == NULL) error = EIDRM; return (error); }
/** * @brief Greybus Camera Protocol deinitialize function * * This function is called when protocol terminated. * * @param operation The pointer to structure of gb_operation. * @return None. */ static void gb_camera_exit(unsigned int cport) { DEBUGASSERT(cport == info->cport); device_close(info->dev); free(info); info = NULL; }
static error_t pc_mouse_fini (void *handle, int force) { device_close (mousedev); mach_port_deallocate (mach_task_self (), mousedev); console_unregister_consnode (cnode); console_destroy_consnode (cnode); return 0; }
device_status_t test_dump_memory_user (const char* name, const char* filename) { device_t *device = NULL; unsigned char data[REEFNET_SENSUSULTRA_MEMORY_USER_SIZE] = {0}; message ("reefnet_sensusultra_device_open\n"); device_status_t rc = reefnet_sensusultra_device_open (&device, name); if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Error opening serial port."); return rc; } time_t now = time (NULL); char datetime[21] = {0}; strftime (datetime, sizeof (datetime), "%Y-%m-%dT%H:%M:%SZ", gmtime (&now)); message ("time=%lu (%s)\n", (unsigned long)now, datetime); message ("reefnet_sensusultra_device_read_user\n"); rc = reefnet_sensusultra_device_read_user (device, data, sizeof (data)); if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Cannot read memory."); device_close (device); return rc; } message ("Dumping data\n"); FILE* fp = fopen (filename, "wb"); if (fp != NULL) { fwrite (data, sizeof (unsigned char), sizeof (data), fp); fclose (fp); } message ("device_close\n"); rc = device_close (device); if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Cannot close device."); return rc; } return DEVICE_STATUS_SUCCESS; }
static int devfs_close(struct vnode *vp, struct file *fp) { DPRINTF(("devfs_close: fp=%x\n", fp)); if (!strcmp(fp->f_dentry->d_path, "/")) /* root ? */ return 0; return device_close(vp->v_data); }
static int vt6656_suspend(struct usb_interface *intf, pm_message_t message) { struct vnt_private *device = usb_get_intfdata(intf); if (!device || !device->dev) return -ENODEV; if (device->flags & DEVICE_FLAGS_OPENED) device_close(device->dev); return 0; }
static void cmd_shutdown(int argc, char **argv) { device_t pm_dev; int error, state = PWR_OFF; if ((error = device_open("pm", 0, &pm_dev)) == 0) { error = device_ioctl(pm_dev, PMIOC_SET_POWER, &state); device_close(pm_dev); } if (error) printf("Error %d\n", error); }
static void serial_close_device(struct async_struct *info) { if (info->device_port != MACH_PORT_NULL) { device_close(info->device_port); mach_port_destroy(mach_task_self(), info->device_port); device_reply_deregister(info->reply_port); info->reply_port = MACH_PORT_NULL; info->device_port = MACH_PORT_NULL; } }
gn_error link_terminate(struct gn_statemachine *state) { if (!state) return GN_ERR_FAILED; /* device_close(&(state->Device)); */ if (state->link.cleanup) state->link.cleanup(state); free(state->link.link_instance); state->link.link_instance = NULL; device_close(state); return GN_ERR_NONE; /* FIXME */ }
int ethernet_close (struct device *dev) { struct ether_device *edev = (struct ether_device *) dev->priv; mach_port_deallocate (mach_task_self (), edev->readptname); edev->readptname = MACH_PORT_NULL; ports_destroy_right (edev->readpt); edev->readpt = NULL; device_close (edev->ether_port); mach_port_deallocate (mach_task_self (), edev->ether_port); edev->ether_port = MACH_PORT_NULL; }
// See of the device is ok and connected, if not, try reconnecting static bool checkDevice(bool usbOk) { if(!usbOk || !device_valid()) { device_close(); device_open(); actions_showConnectionStatus(); if(!device_valid()) return false; actions_showCurrentSettings(); actions_setTransitionTime(); } return true; }
static int touch_remove(struct i2c_client *client) { struct lge_touch_driver *touch = i2c_get_clientdata(client); #ifdef CONFIG_HAS_EARLYSUSPEND unregister_early_suspend(&touch->early_suspend); #endif touch->h_inputDev->close(touch->h_touch); touch->h_task->close(touch->h_touch); touch->h_interrupt->close(touch->h_touch); device_close(touch->h_touch); remove_touch_object(touch); return 0; }
u_long get_time(void) { device_t rtc_dev; int err; u_long sec; size_t len; err = device_open("rtc", 0, &rtc_dev); if (err) { printf("error to open rtc device!\n"); return 0; } len = sizeof(sec); err = device_read(rtc_dev, &sec, &len, 0); if (err) { printf("error in reading from rtc device\n"); device_close(rtc_dev); return 0; } device_close(rtc_dev); return sec; }
int reboot(int howto) { device_t pm_dev; int err, mode; mode = (howto & RB_POWERDOWN) ? POWER_OFF : POWER_REBOOT; if ((err = device_open("pm", 0, &pm_dev)) == 0) { err = device_ioctl(pm_dev, PMIOC_SET_POWER, &mode); device_close(pm_dev); } return err; }
/** * @brief Protocol exit function. * * This function can be called when protocol terminated. * * @param operation The pointer to structure of gb_operation. * @return None. */ static void gb_uart_exit(unsigned int cport) { device_uart_attach_ls_callback(info->dev, NULL); device_uart_attach_ms_callback(info->dev, NULL); device_close(info->dev); uart_receiver_cb_deinit(); uart_status_cb_deinit(); free(info); }