port iso examples to rawiso API
git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@147 53a565d1-3bb7-0310-b661-cf11e63c67ab
This commit is contained in:
parent
d5902a8715
commit
eb9b08bd5c
1
NEWS
1
NEWS
|
@ -14,6 +14,7 @@ Version 1.1.0:
|
||||||
- deprecate old isochronous API.
|
- deprecate old isochronous API.
|
||||||
- move API comment documentation to header and reformat header comments as
|
- move API comment documentation to header and reformat header comments as
|
||||||
kernel-doc (use linux/scripts/kernel-doc to extract and format them).
|
kernel-doc (use linux/scripts/kernel-doc to extract and format them).
|
||||||
|
- updated tools/dumpiso and tools/sendiso to new isochronous API.
|
||||||
|
|
||||||
Version 0.10:
|
Version 0.10:
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,7 @@ int raw1394_iso_xmit_init(raw1394handle_t handle,
|
||||||
* @max_packet_size: largest packet you need to handle, in bytes (not including
|
* @max_packet_size: largest packet you need to handle, in bytes (not including
|
||||||
* the isochronous header)
|
* the isochronous header)
|
||||||
* @channel: isochronous channel to receive
|
* @channel: isochronous channel to receive
|
||||||
* @speed: speed at which to receive
|
* @mode: bufferfill or packet per buffer mode
|
||||||
* @irq_interval: maximum latency of wake-ups, in packets
|
* @irq_interval: maximum latency of wake-ups, in packets
|
||||||
* (-1 if you don't care)
|
* (-1 if you don't care)
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,3 +1,13 @@
|
||||||
|
/*
|
||||||
|
* libraw1394 - library for raw access to the 1394 bus with the Linux subsystem.
|
||||||
|
*
|
||||||
|
* Copyright (C) 1999,2000 Andreas Bombe
|
||||||
|
*
|
||||||
|
* This library is licensed under the GNU Lesser General Public License (LGPL),
|
||||||
|
* version 2.1 or later. See the file COPYING.LIB in the distribution for
|
||||||
|
* details.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -7,13 +17,14 @@
|
||||||
|
|
||||||
#include "../src/raw1394.h"
|
#include "../src/raw1394.h"
|
||||||
|
|
||||||
|
#define BUFFER 1000
|
||||||
|
#define PACKET_MAX 4096
|
||||||
|
|
||||||
u_int64_t listen_channels;
|
u_int64_t listen_channels;
|
||||||
unsigned long which_port;
|
unsigned long which_port;
|
||||||
char *filename;
|
char *filename;
|
||||||
int file;
|
int file;
|
||||||
|
enum raw1394_iso_dma_recv_mode mode = RAW1394_DMA_DEFAULT;
|
||||||
int done;
|
|
||||||
|
|
||||||
void usage_exit(int exitcode)
|
void usage_exit(int exitcode)
|
||||||
{
|
{
|
||||||
|
@ -70,6 +81,8 @@ void parse_args(int argc, char **argv)
|
||||||
optarg);
|
optarg);
|
||||||
usage_exit(1);
|
usage_exit(1);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
mode = RAW1394_DMA_PACKET_PER_BUFFER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chan2 < chan1) {
|
if (chan2 < chan1) {
|
||||||
|
@ -160,28 +173,38 @@ void open_dumpfile()
|
||||||
write_header();
|
write_header();
|
||||||
}
|
}
|
||||||
|
|
||||||
int iso_packet_handler(raw1394handle_t handle, int channel, size_t length,
|
static enum raw1394_iso_disposition
|
||||||
quadlet_t *data)
|
iso_handler(raw1394handle_t handle, unsigned char *data,
|
||||||
|
unsigned int length, unsigned char channel,
|
||||||
|
unsigned char tag, unsigned char sy, unsigned int cycle,
|
||||||
|
unsigned int dropped)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
static unsigned int count;
|
static unsigned int counter = 0;
|
||||||
|
|
||||||
count++;
|
if (++counter % 1000 == 0)
|
||||||
fprintf(stderr, "\r%u", count);
|
fprintf(stderr, "\r%uK packets", counter/1000);
|
||||||
fflush(stderr);
|
|
||||||
|
/* write header */
|
||||||
|
write(file, &length, sizeof(length));
|
||||||
|
write(file, &channel, sizeof(channel));
|
||||||
|
write(file, &tag, sizeof(tag));
|
||||||
|
write(file, &sy, sizeof(sy));
|
||||||
|
sy = 0;
|
||||||
|
write(file, &sy, sizeof(sy));
|
||||||
|
|
||||||
while (length) {
|
while (length) {
|
||||||
ret = write(file, data, length);
|
ret = write(file, data, length);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
perror("data write");
|
perror("data write");
|
||||||
exit(1);
|
return RAW1394_ISO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
length -= ret;
|
length -= ret;
|
||||||
data = (quadlet_t *)(((char *)data) + ret);
|
data += ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return RAW1394_ISO_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
@ -221,16 +244,24 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
open_dumpfile();
|
open_dumpfile();
|
||||||
|
|
||||||
for (i = 0; i < 64; i++) {
|
if (mode == RAW1394_DMA_DEFAULT) {
|
||||||
if (!(listen_channels & 1ULL << i)) continue;
|
raw1394_iso_multichannel_recv_init(handle, iso_handler,
|
||||||
|
BUFFER, 2048, -1); /* >2048 makes rawiso stall! */
|
||||||
|
raw1394_iso_recv_set_channel_mask(handle, listen_channels);
|
||||||
|
|
||||||
raw1394_set_iso_handler(handle, i, iso_packet_handler);
|
} else for (i = 0; i < 64; i++) {
|
||||||
raw1394_start_iso_rcv(handle, i);
|
if (!(listen_channels & 1ULL << i))
|
||||||
|
continue;
|
||||||
|
raw1394_iso_recv_init(handle, iso_handler, BUFFER, PACKET_MAX,
|
||||||
|
i, mode, -1);
|
||||||
}
|
}
|
||||||
|
raw1394_iso_recv_start(handle, -1, -1, 0);
|
||||||
|
|
||||||
/* This should actually do something with the done variable, and set up
|
while (raw1394_loop_iterate(handle) == 0);
|
||||||
signal handlers. */
|
|
||||||
while (!done) raw1394_loop_iterate(handle);
|
fprintf(stderr, "\n");
|
||||||
|
raw1394_iso_shutdown(handle);
|
||||||
|
raw1394_destroy_handle(handle);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
#include "../src/raw1394.h"
|
#include "../src/raw1394.h"
|
||||||
|
|
||||||
|
#define BUFFER 1000
|
||||||
|
#define PACKET_MAX 4096
|
||||||
|
|
||||||
unsigned long which_port;
|
unsigned long which_port;
|
||||||
char *filename;
|
char *filename;
|
||||||
|
@ -86,15 +88,15 @@ void parse_args(int argc, char **argv)
|
||||||
switch (speed) {
|
switch (speed) {
|
||||||
case 1:
|
case 1:
|
||||||
case 100:
|
case 100:
|
||||||
speed = 0;
|
speed = RAW1394_ISO_SPEED_100;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
case 200:
|
case 200:
|
||||||
speed = 1;
|
speed = RAW1394_ISO_SPEED_200;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
case 400:
|
case 400:
|
||||||
speed = 2;
|
speed = RAW1394_ISO_SPEED_400;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
|
@ -134,66 +136,72 @@ void parse_args(int argc, char **argv)
|
||||||
if (argc) filename = *argv;
|
if (argc) filename = *argv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define BUF_SIZE 4096
|
||||||
static int dec_int_callback(raw1394handle_t unused, void *counter, raw1394_errcode_t unused_errcode)
|
#define BUF_HEAD 8
|
||||||
{
|
|
||||||
(*(int *)counter)--;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
static int pend_req;
|
|
||||||
|
|
||||||
#define BUF_SIZE 65536
|
|
||||||
#define BUF_OVER BUF_SIZE
|
|
||||||
void send_file_once(raw1394handle_t handle, int file)
|
void send_file_once(raw1394handle_t handle, int file)
|
||||||
{
|
{
|
||||||
int count, i, ret;
|
int count, i, ret;
|
||||||
unsigned channel, tag, sy;
|
unsigned channel, tag, sy;
|
||||||
size_t length;
|
size_t length;
|
||||||
static char buffer[BUF_SIZE + BUF_OVER];
|
static char buffer[BUF_SIZE + BUF_HEAD];
|
||||||
|
static unsigned int counter = 0;
|
||||||
static struct raw1394_reqhandle rh = {
|
static int inited = 0;
|
||||||
dec_int_callback,
|
|
||||||
&pend_req
|
|
||||||
};
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
while (pend_req > 30) raw1394_loop_iterate(handle);
|
count = read(file, buffer, BUF_HEAD);
|
||||||
|
|
||||||
count = read(file, buffer, BUF_SIZE);
|
|
||||||
if (count < 0) {
|
if (count < 0) {
|
||||||
perror("read");
|
perror("read");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (count < 4) return;
|
if (count < BUF_HEAD)
|
||||||
|
return;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < count) {
|
length = ((unsigned int *)buffer)[i];
|
||||||
length = (buffer[i] << 8) | buffer[i + 1];
|
channel = buffer[i + 4];
|
||||||
channel = buffer[i + 2] & 0x3f;
|
tag = buffer[i + 5];
|
||||||
tag = buffer[i + 2] >> 6;
|
sy = buffer[i + 6];
|
||||||
sy = buffer[i + 3] & 0xf;
|
|
||||||
|
|
||||||
i += 4;
|
i += BUF_HEAD;
|
||||||
while (i + length > count) {
|
while (count < length + BUF_HEAD) {
|
||||||
ret = read(file, buffer + BUF_SIZE,
|
ret = read(file, buffer + count,
|
||||||
i + length - BUF_SIZE);
|
length - count + BUF_HEAD);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
perror("read");
|
perror("read");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
|
||||||
|
|
||||||
if (ret == 0) return;
|
}
|
||||||
|
if (ret == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
count += ret;
|
count += ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
raw1394_start_iso_write(handle, channel, tag, sy,
|
if (inited == 0) {
|
||||||
speed, length,
|
/*
|
||||||
(quadlet_t *)(buffer + i),
|
fprintf(stderr, "transmitting first packet with length "
|
||||||
(unsigned long)&rh);
|
"%d on channel %d with tag %d and sy %d\n",
|
||||||
i += length;
|
length, channel, tag, sy);
|
||||||
pend_req++;
|
*/
|
||||||
|
ret = raw1394_iso_xmit_init(handle, NULL, BUFFER,
|
||||||
|
PACKET_MAX, channel, speed, -1);
|
||||||
|
if (ret < 0) {
|
||||||
|
perror("raw1394_iso_xmit_init");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
raw1394_iso_xmit_start(handle, -1, -1);
|
||||||
|
inited = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (++counter % 1000 == 0)
|
||||||
|
fprintf(stderr, "\r%uK packets", counter/1000);
|
||||||
|
|
||||||
|
ret = raw1394_iso_xmit_write(handle, &buffer[i],
|
||||||
|
length, tag, sy);
|
||||||
|
if (ret < 0) {
|
||||||
|
perror("\nraw1394_iso_xmit_write");
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -299,5 +307,9 @@ int main(int argc, char **argv)
|
||||||
if (filename)
|
if (filename)
|
||||||
send_iso_file(handle);
|
send_iso_file(handle);
|
||||||
|
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
raw1394_iso_shutdown(handle);
|
||||||
|
raw1394_destroy_handle(handle);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue