static int ppdev_close (urj_parport_t *parport) { int r = URJ_STATUS_OK; ppdev_params_t *p = parport->params; if (ioctl (p->fd, PPRELEASE) == -1) { urj_error_IO_set ("ioctl(PPRELEASE) fails"); r = URJ_STATUS_FAIL; } if (close (p->fd) != 0) { urj_error_IO_set ("Cannot close(%d)", p->fd); return URJ_STATUS_FAIL; } p->fd = -1; return r; }
static int ts7800_gpio_open (urj_cable_t *cable) { ts7800_params_t *p = cable->params; off_t map_mask; /* Open the memory device so we can access the hardware registers */ p->fd_dev_mem = open ("/dev/mem", O_RDWR | O_SYNC); if (p->fd_dev_mem == -1) { urj_error_IO_set (_("unable to open /dev/mem")); return URJ_STATUS_FAIL; } p->map_size = getpagesize (); map_mask = p->map_size - 1; /* Map the GPIO registers */ p->map_base = mmap (0, p->map_size, PROT_READ | PROT_WRITE, MAP_SHARED, p->fd_dev_mem, GPIO_BASE & ~map_mask); if (p->map_base == MAP_FAILED) { urj_error_IO_set (_("unable to mmap the GPIO registers")); close (p->fd_dev_mem); return URJ_STATUS_FAIL; } /* Create the pointers to access the GPIO registers */ p->gpio_base = p->map_base; /* Set the GPIO pins as inputs/outputs as needed for the JTAG interface */ p->gpio_base[GPIO_DIR] = (p->gpio_base[GPIO_DIR] & GPIO_BITMASK) | GPIO_OUTPUT_MASK; p->lastout = p->gpio_base[GPIO_OUT]; return URJ_STATUS_OK; }
static int ts7800_gpio_close (urj_cable_t *cable) { ts7800_params_t *p = cable->params; /* Unmap the GPIO registers */ if (munmap (p->map_base, p->map_size) == -1) { urj_error_IO_set (_("unable to munmap the GPIO registers")); } close (p->fd_dev_mem); return URJ_STATUS_OK; }
static int ppdev_set_data (urj_parport_t *parport, unsigned char data) { ppdev_params_t *p = parport->params; if (ioctl (p->fd, PPWDATA, &data) == -1) { urj_error_IO_set ("ioctl(PPWDATA) fails"); return URJ_STATUS_FAIL; } return URJ_STATUS_OK; }
static int ppdev_get_status (urj_parport_t *parport) { unsigned char d; ppdev_params_t *p = parport->params; if (ioctl (p->fd, PPRSTATUS, &d) == -1) { urj_error_IO_set ("ioctl(PPRSTATUS) fails"); return -1; } return d ^ 0x80; /* BUSY is inverted */ }
static int ppdev_get_data (urj_parport_t *parport) { unsigned char d; ppdev_params_t *p = parport->params; if (ioctl (p->fd, PPRDATA, &d) == -1) { urj_error_IO_set ("ioctl(PPRDATA) fails"); return -1; } return d; }
static int ppdev_open (urj_parport_t *parport) { ppdev_params_t *p = parport->params; p->fd = open (p->portname, O_RDWR); if (p->fd < 0) { urj_error_IO_set (_("Could not open port %s"), p->portname); return URJ_STATUS_FAIL; } if ( /*(ioctl( p->fd, PPEXCL ) == -1) || */ (ioctl (p->fd, PPCLAIM) == -1)) { urj_error_IO_set (_("Could not claim ppdev device")); close (p->fd); p->fd = -1; return URJ_STATUS_FAIL; } return URJ_STATUS_OK; }
static int cmd_flashmem_run (urj_chain_t *chain, char *params[]) { int msbin; int noverify = 0; long unsigned adr = 0; FILE *f; int paramc = urj_cmd_params (params); int r; if (paramc < 3) { urj_error_set (URJ_ERROR_SYNTAX, "%s: #parameters should be >= %d, not %d", params[0], 3, urj_cmd_params (params)); return URJ_STATUS_FAIL; } if (!urj_bus) { urj_error_set (URJ_ERROR_ILLEGAL_STATE, _("Bus driver missing")); return URJ_STATUS_FAIL; } msbin = strcasecmp ("msbin", params[1]) == 0; if (!msbin && urj_cmd_get_number (params[1], &adr) != URJ_STATUS_OK) return URJ_STATUS_FAIL; if (paramc > 3) noverify = strcasecmp ("noverify", params[3]) == 0; else noverify = 0; f = fopen (params[2], "rb"); if (!f) { urj_error_IO_set (_("Unable to open file `%s'"), params[2]); return URJ_STATUS_FAIL; } if (msbin) r = urj_flashmsbin (urj_bus, f, noverify); else r = urj_flashmem (urj_bus, f, adr, noverify); fclose (f); return r; }
static int ppdev_set_control (urj_parport_t *parport, unsigned char data) { ppdev_params_t *p = parport->params; data ^= 0x0B; /* SELECT, AUTOFD, and STROBE are inverted */ if (ioctl (p->fd, PPWCONTROL, &data) == -1) { urj_error_IO_set ("ioctl(PPWCONTROL) fails"); return URJ_STATUS_FAIL; } return URJ_STATUS_OK; }