예제 #1
0
static int parport_quit(void)
{
    parport_led(0);

    if (parport_exit) {
        dataport_value = cable->PORT_EXIT;
        parport_write_data();
    }

    if (parport_cable) {
        free(parport_cable);
        parport_cable = NULL;
    }

    return ERROR_OK;
}
예제 #2
0
static int parport_init(void)
{
    struct cable *cur_cable;
    cur_cable = cables;


    if(ser_open())
    {
        printf("ser_open failed\n");
    }


    parport_cable = "jtagproxy";

    while (cur_cable->name) {
        if (strcmp(cur_cable->name, parport_cable) == 0) {
            cable = cur_cable;
            break;
        }
        cur_cable++;
    }

    if (!cable) {
        LOG_ERROR("No matching cable found for %s", parport_cable);
        return ERROR_JTAG_INIT_FAILED;
    }

    dataport_value = cable->PORT_INIT;

    parport_reset(0, 0);
    parport_write(0, 0, 0);
    parport_led(1);

    bitbang_interface = &parport_bitbang;

    return ERROR_OK;
}
예제 #3
0
파일: parport.c 프로젝트: FelixVi/openocd
static int parport_init(void)
{
	const struct cable *cur_cable;
#if PARPORT_USE_PPDEV == 1
	char buffer[256];
#endif

	cur_cable = cables;

	if (parport_cable == NULL) {
		parport_cable = strdup("wiggler");
		LOG_WARNING("No parport cable specified, using default 'wiggler'");
	}

	while (cur_cable->name) {
		if (strcmp(cur_cable->name, parport_cable) == 0) {
			cable = cur_cable;
			break;
		}
		cur_cable++;
	}

	if (!cable) {
		LOG_ERROR("No matching cable found for %s", parport_cable);
		return ERROR_JTAG_INIT_FAILED;
	}

	dataport_value = cable->PORT_INIT;

#if PARPORT_USE_PPDEV == 1
	if (device_handle > 0) {
		LOG_ERROR("device is already opened");
		return ERROR_JTAG_INIT_FAILED;
	}

#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
	LOG_DEBUG("opening /dev/ppi%d...", parport_port);

	snprintf(buffer, 256, "/dev/ppi%d", parport_port);
	device_handle = open(buffer, O_WRONLY);
#else /* not __FreeBSD__, __FreeBSD_kernel__ */
	LOG_DEBUG("opening /dev/parport%d...", parport_port);

	snprintf(buffer, 256, "/dev/parport%d", parport_port);
	device_handle = open(buffer, O_WRONLY);
#endif /* __FreeBSD__, __FreeBSD_kernel__ */

	if (device_handle < 0) {
		int err = errno;
		LOG_ERROR("cannot open device. check it exists and that user read and write rights are set. errno=%d", err);
		return ERROR_JTAG_INIT_FAILED;
	}

	LOG_DEBUG("...open");

#if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__)
	int i = ioctl(device_handle, PPCLAIM);

	if (i < 0) {
		LOG_ERROR("cannot claim device");
		return ERROR_JTAG_INIT_FAILED;
	}

	i = PARPORT_MODE_COMPAT;
	i = ioctl(device_handle, PPSETMODE, &i);
	if (i < 0) {
		LOG_ERROR(" cannot set compatible mode to device");
		return ERROR_JTAG_INIT_FAILED;
	}

	i = IEEE1284_MODE_COMPAT;
	i = ioctl(device_handle, PPNEGOT, &i);
	if (i < 0) {
		LOG_ERROR("cannot set compatible 1284 mode to device");
		return ERROR_JTAG_INIT_FAILED;
	}
#endif /* not __FreeBSD__, __FreeBSD_kernel__ */

#else /* not PARPORT_USE_PPDEV */
	if (parport_port == 0) {
		parport_port = 0x378;
		LOG_WARNING("No parport port specified, using default '0x378' (LPT1)");
	}

	dataport = parport_port;
	statusport = parport_port + 1;

	LOG_DEBUG("requesting privileges for parallel port 0x%lx...", dataport);
#if PARPORT_USE_GIVEIO == 1
	if (parport_get_giveio_access() != 0) {
#else /* PARPORT_USE_GIVEIO */
	if (ioperm(dataport, 3, 1) != 0) {
#endif /* PARPORT_USE_GIVEIO */
		LOG_ERROR("missing privileges for direct i/o");
		return ERROR_JTAG_INIT_FAILED;
	}
	LOG_DEBUG("...privileges granted");

	/* make sure parallel port is in right mode (clear tristate and interrupt */
	#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
		outb(parport_port + 2, 0x0);
	#else
		outb(0x0, parport_port + 2);
	#endif

#endif /* PARPORT_USE_PPDEV */

	parport_reset(0, 0);
	parport_write(0, 0, 0);
	parport_led(1);

	bitbang_interface = &parport_bitbang;

	return ERROR_OK;
}

static int parport_quit(void)
{
	parport_led(0);

	if (parport_exit) {
		dataport_value = cable->PORT_EXIT;
		parport_write_data();
	}

	if (parport_cable) {
		free(parport_cable);
		parport_cable = NULL;
	}

	return ERROR_OK;
}