Beispiel #1
0
void raw1394_iso_shutdown(raw1394handle_t handle)
{
	if(handle->iso_buffer) {
		munmap(handle->iso_buffer, handle->iso_status.config.data_buf_size);
		handle->iso_buffer = NULL;
	}
	
	if(handle->iso_mode != ISO_INACTIVE) {
		raw1394_iso_stop(handle);
		ioctl(handle->fd, RAW1394_IOC_ISO_SHUTDOWN, 0);
	}

	handle->iso_mode = ISO_INACTIVE;
}
int main(int argc, char** argv)
{
    int rc; /**< return code */
    int port = 0;  /*!< fw handle port number */
    int nodeid = 0;   /*!< arm server node id */

    // parse command line (port number)
    opterr = 0;  // getopt no err output
    const char short_options[] = "hp:n:";
    int next_opt;
    do {
        next_opt = getopt(argc, argv, short_options);
        switch(next_opt)
        {
        case 'h':
            print_usage();
            return EXIT_SUCCESS;
            break;
        case 'p':
            port = atoi(optarg);
            break;
        case 'n':
            nodeid = atoi(optarg);
            break;
        case '?':
            std::cerr << "Invalid argument" << std::endl;
            break;
        default:
            break;
        }
    }
    while(next_opt != -1);


    // ----- Get handle and set port for the handle -------
    // create handle
    handle = raw1394_new_handle();
    if (handle == NULL) {
        std::cerr << "**** Error: could not create 1394 handle " << strerror(errno) << std::endl;
        return EXIT_FAILURE;
    }

    // get port number & sanity check
    int numPorts = raw1394_get_port_info(handle, NULL, 0);
    if (port < 0 || port >= numPorts) {
        std::cerr << "Invalid port number" << std::endl;
        return EXIT_FAILURE;
    }

    // let user to choose which port to use
    rc = raw1394_set_port(handle, port);
    if (rc) {
        std::cerr << "**** Error: failed to set port " << strerror(errno) << std::endl;
        return EXIT_FAILURE;
    }


    // -------- Set FireWire bus reset handler --------

    // set bus reset handler
    raw1394_set_bus_reset_handler(handle, my_bus_reset_handler);



    // ----------------------------------------------------------------------------
    // Start tutorial 6 isochronous send
    // ----------------------------------------------------------------------------

    /**
     * raw1394_iso_xmit_init - initialize isochronous transmission
     * @handle: libraw1394 handle
     * @handler: handler function for queueing packets
     * @buf_packets: number of isochronous packets to buffer
     * @max_packet_size: largest packet you need to handle, in bytes
     * (not including the isochronous header)
     * @channel: isochronous channel on which to transmit
     * @speed: speed at which to transmit
     * @irq_interval: maximum latency of wake-ups, in packets (-1 if you don't care)
     *
     * Allocates all user and kernel resources necessary for isochronous transmission.
     * Channel and bandwidth allocation at the IRM is not performed.
     *
     * Returns: 0 on success or -1 on failure (sets errno)
     **/
    size_t length;
    unsigned char channel, tag, sy;
    unsigned char buffer[BUF_SIZE + BUF_HEAD];
    channel = 5;
    tag = 6;
    sy = 7;

    // ----- transmitting end -------------
    rc = raw1394_iso_xmit_init(handle,      // 1394 handle
                               NULL,        // xmit handler
                               BUFFER,      // iso packets to buffer
                               MAX_PACKET,  // max packet size
                               channel,           // just pick 5 for fun
                               RAW1394_ISO_SPEED_400,
                               -1);         // irq_interval
    if (rc) {
        perror("raw1394_iso_xmit_init");
        exit(1);
    }
    rc = raw1394_iso_xmit_start(handle, -1, -1);
    if (rc) {
        perror("raw1394_iso_xmit_start");
        exit(1);
    }

    quadlet_t data = 0x0;
    while (true) {
        rc = raw1394_iso_xmit_write(handle,
                                    (unsigned char *)&data,
                                    4,
                                    tag,
                                    sy);
        if (rc) {
            perror("\nraw1394_iso_xmit_write");
            break;
        }
//        data++;
//        std::cout << "data = " << data << std::endl;
    }

    // stop, clean up & exit
    raw1394_iso_stop(handle);
    raw1394_iso_shutdown(handle);
    raw1394_destroy_handle(handle);

    return EXIT_SUCCESS;
}
int main(int argc, char** argv)
{
    int rc; /**< return code */
    int port = 0;  /*!< fw handle port number */
    int nodeid = 0;   /*!< arm server node id */

    // parse command line (port number)
    opterr = 0;  // getopt no err output
    const char short_options[] = "hp:n:";
    int next_opt;
    do {
        next_opt = getopt(argc, argv, short_options);
        switch(next_opt)
        {
        case 'h':
            print_usage();
            return EXIT_SUCCESS;
            break;
        case 'p':
            port = atoi(optarg);
            break;
        case 'n':
            nodeid = atoi(optarg);
            break;
        case '?':
            std::cerr << "Invalid argument" << std::endl;
            break;
        default:
            break;
        }
    }
    while(next_opt != -1);


    // ----- Get handle and set port for the handle -------
    // create handle
    handle = raw1394_new_handle();
    if (handle == NULL) {
        std::cerr << "**** Error: could not create 1394 handle " << strerror(errno) << std::endl;
        return EXIT_FAILURE;
    }

    // get port number & sanity check
    int numPorts = raw1394_get_port_info(handle, NULL, 0);
    if (port < 0 || port >= numPorts) {
        std::cerr << "Invalid port number" << std::endl;
        return EXIT_FAILURE;
    }

    // let user to choose which port to use
    rc = raw1394_set_port(handle, port);
    if (rc) {
        std::cerr << "**** Error: failed to set port " << strerror(errno) << std::endl;
        return EXIT_FAILURE;
    }


    // -------- Set FireWire bus reset handler --------

    // set bus reset handler
    raw1394_set_bus_reset_handler(handle, my_bus_reset_handler);



    // ----------------------------------------------------------------------------
    // Start tutorial 4 async broadcast
    // ----------------------------------------------------------------------------

    /**
     *
     */
    // ----- receving end -------------
    unsigned char channel = 0x5;
    raw1394_iso_dma_recv_mode mode = RAW1394_DMA_DEFAULT;

    raw1394_iso_recv_init(handle,
                          my_iso_recv_handler,
                          BUFFER,      // buf_packets
                          PACKET_MAX,  // max_packet_size
                          channel,     // channel
                          mode,        // dma mode
                          -1);         // irq_interval

    // start receiving
    raw1394_iso_recv_start(handle, -1, -1, 0);
    while (true)
    {
        rc = raw1394_loop_iterate(handle);
        if (rc) break;
    }

    // stop, clean up & exit
    raw1394_iso_stop(handle);
    raw1394_iso_shutdown(handle);
    raw1394_destroy_handle(handle);

    return EXIT_SUCCESS;
}
Beispiel #4
0
static int _raw1394_iso_recv_packets(raw1394handle_t handle)
{
	struct raw1394_iso_status *stat = &handle->iso_status;
	struct raw1394_iso_packets packets;

	int retval = -1, packets_done = 0;

	if(handle->iso_mode != ISO_RECV) {
		errno = EINVAL;
		return -1;
	}
	
	/* ask the kernel to fill an array with packet info structs */
	packets.n_packets = stat->n_packets;
	packets.infos = malloc(packets.n_packets * sizeof(struct raw1394_iso_packet_info));
	if(packets.infos == NULL)
		goto out;

	if(ioctl(handle->fd, RAW1394_IOC_ISO_RECV_PACKETS, &packets) < 0)
		goto out_free;

	while(stat->n_packets > 0) {
		struct raw1394_iso_packet_info *info;
		enum raw1394_iso_disposition disp;

		info = &packets.infos[packets_done];

		/* call handler */
		disp = handle->iso_recv_handler(handle,
						handle->iso_buffer + info->offset,
						info->len, info->channel,
						info->tag, info->sy,
						info->cycle,
						_raw1394_iso_dropped(handle));

		/* advance packet cursors */
		stat->n_packets--;
		packets_done++;
		
		if(disp == RAW1394_ISO_DEFER) {
			/* queue an event so that we don't hang in the next read() */
			if(ioctl(handle->fd, RAW1394_IOC_ISO_QUEUE_ACTIVITY, 0))
				goto out_consume;
			break;
		} else if(disp == RAW1394_ISO_STOP || disp == RAW1394_ISO_STOP_NOSYNC) {
			raw1394_iso_stop(handle);
			break;
		} else if(disp == RAW1394_ISO_ERROR) {
			goto out_consume;
		}
	}

	/* success */
	retval = 0;

out_consume:
	if(packets_done > 0) {
		if(ioctl(handle->fd, RAW1394_IOC_ISO_RECV_RELEASE_PACKETS, packets_done))
			retval = -1;
	}
out_free:
	free(packets.infos);
out:	
	return retval;
}
Beispiel #5
0
static int _raw1394_iso_xmit_queue_packets(raw1394handle_t handle)
{
	struct raw1394_iso_status *stat = &handle->iso_status;
	struct raw1394_iso_packets packets;
	int retval = -1;
	int stop_sync = 0;

	if(handle->iso_mode != ISO_XMIT) {
		errno = EINVAL;
		goto out;
	}

	/* we could potentially send up to stat->n_packets packets */
	packets.n_packets = 0;
	packets.infos = malloc(stat->n_packets * sizeof(struct raw1394_iso_packet_info));
	if(packets.infos == NULL)
		goto out;

	while(stat->n_packets > 0) {
		enum raw1394_iso_disposition disp;
		unsigned int len;
		
		struct raw1394_iso_packet_info *info = &packets.infos[packets.n_packets];

		info->offset = handle->iso_buf_stride * handle->next_packet;
		
		/* call handler */
		disp = handle->iso_xmit_handler(handle,
						handle->iso_buffer + info->offset,
						&len,
						&info->tag, &info->sy,
						stat->xmit_cycle,
						_raw1394_iso_dropped(handle));
		info->len = len;
		
		/* advance packet cursors and cycle counter */
		stat->n_packets--;
		handle->next_packet = (handle->next_packet + 1) % stat->config.buf_packets;
		if(stat->xmit_cycle != -1)
			stat->xmit_cycle = (stat->xmit_cycle + 1) % 8000;
		packets.n_packets++;

		if(disp == RAW1394_ISO_DEFER) {
			/* queue an event so that we don't hang in the next read() */
			if(ioctl(handle->fd, RAW1394_IOC_ISO_QUEUE_ACTIVITY, 0))
				goto out_produce;
			break;
		} else if(disp == RAW1394_ISO_STOP) {
			stop_sync = 1;
			break;
		} else if(disp == RAW1394_ISO_STOP_NOSYNC) {
			raw1394_iso_stop(handle);
			break;
		} else if(disp == RAW1394_ISO_ERROR) {
			goto out_produce;
		}
	}

	/* success */
	retval = 0;

out_produce:
	if(packets.n_packets > 0) {
		if(ioctl(handle->fd, RAW1394_IOC_ISO_XMIT_PACKETS, &packets))
			retval = -1;
	}
	free(packets.infos);
out:
	if(stop_sync) {
		if(raw1394_iso_xmit_sync(handle))
			return -1;
		raw1394_iso_stop(handle);
	}
	
	return retval;
}