summaryrefslogtreecommitdiffstats
path: root/src/iso.c
diff options
context:
space:
mode:
authorGravatar Dan Dennedy 2008-04-23 17:44:36 -0700
committerGravatar Dan Dennedy 2008-04-23 17:44:36 -0700
commit0ea462ae9895ca903c8d3134910c06e1869560c4 (patch)
treec1b72a170cfca14c1b9cccd552e5cadc249bd483 /src/iso.c
parentFix configure.ac missing fi after initial merge. (diff)
First cut at integrating juju
This is currently working with legacy ieee1394 and tools/testlibraw.
Diffstat (limited to 'src/iso.c')
-rw-r--r--src/iso.c195
1 files changed, 68 insertions, 127 deletions
diff --git a/src/iso.c b/src/iso.c
index a16196a..9b62ac1 100644
--- a/src/iso.c
+++ b/src/iso.c
@@ -34,71 +34,8 @@ static inline int increment_and_wrap(int x, int n)
return x;
}
-/* old ISO API - kept for backwards compatibility */
-
-static int do_iso_listen(struct raw1394_handle *handle, int channel)
-{
- struct sync_cb_data sd = { 0, 0 };
- struct raw1394_reqhandle rh = { (req_callback_t)_raw1394_sync_cb, &sd };
- int err;
- struct raw1394_request req;
-
- CLEAR_REQ(&req);
- req.type = RAW1394_REQ_ISO_LISTEN;
- req.generation = handle->generation;
- req.misc = channel;
- req.tag = ptr2int(&rh);
- req.recvb = ptr2int(handle->buffer);
- req.length = HBUF_SIZE;
-
- err = write(handle->fd, &req, sizeof(req));
- while (!sd.done) {
- if (err < 0) return err;
- err = raw1394_loop_iterate(handle);
- }
-
- switch (sd.errcode) {
- case RAW1394_ERROR_ALREADY:
- errno = EALREADY;
- return -1;
-
- case RAW1394_ERROR_INVALID_ARG:
- errno = EINVAL;
- return -1;
-
- default:
- errno = 0;
- return sd.errcode;
- }
-}
-
-int raw1394_start_iso_rcv(struct raw1394_handle *handle, unsigned int channel)
-{
- if (channel > 63) {
- errno = EINVAL;
- return -1;
- }
-
- return do_iso_listen(handle, channel);
-}
-
-int raw1394_stop_iso_rcv(struct raw1394_handle *handle, unsigned int channel)
-{
- if (channel > 63) {
- errno = EINVAL;
- return -1;
- }
-
- return do_iso_listen(handle, ~channel);
-}
-
-
-
-/* new ISO API */
-
-
/* reset the dropped counter each time it is seen */
-static unsigned int _raw1394_iso_dropped(raw1394handle_t handle)
+static unsigned int _iso_dropped(ieee1394handle_t handle)
{
unsigned int retval = handle->iso_packets_dropped;
handle->iso_packets_dropped = 0;
@@ -107,7 +44,7 @@ static unsigned int _raw1394_iso_dropped(raw1394handle_t handle)
/* common code for iso_xmit_init and iso_recv_init */
-static int do_iso_init(raw1394handle_t handle,
+static int do_iso_init(ieee1394handle_t handle,
unsigned int buf_packets,
unsigned int max_packet_size,
int channel,
@@ -185,7 +122,7 @@ static int do_iso_init(raw1394handle_t handle,
return 0;
}
-int raw1394_iso_xmit_init(raw1394handle_t handle,
+int ieee1394_iso_xmit_init(ieee1394handle_t handle,
raw1394_iso_xmit_handler_t handler,
unsigned int buf_packets,
unsigned int max_packet_size,
@@ -204,12 +141,12 @@ int raw1394_iso_xmit_init(raw1394handle_t handle,
return 0;
}
-int raw1394_iso_recv_init(raw1394handle_t handle,
+int ieee1394_iso_recv_init(ieee1394handle_t handle,
raw1394_iso_recv_handler_t handler,
unsigned int buf_packets,
unsigned int max_packet_size,
unsigned char channel,
- enum raw1394_iso_dma_recv_mode mode,
+ enum raw1394_iso_dma_recv_mode mode,
int irq_interval)
{
/* any speed will work */
@@ -222,7 +159,7 @@ int raw1394_iso_recv_init(raw1394handle_t handle,
return 0;
}
-int raw1394_iso_multichannel_recv_init(raw1394handle_t handle,
+int ieee1394_iso_multichannel_recv_init(ieee1394handle_t handle,
raw1394_iso_recv_handler_t handler,
unsigned int buf_packets,
unsigned int max_packet_size,
@@ -239,7 +176,7 @@ int raw1394_iso_multichannel_recv_init(raw1394handle_t handle,
return 0;
}
-int raw1394_iso_recv_listen_channel(raw1394handle_t handle, unsigned char channel)
+int ieee1394_iso_recv_listen_channel(ieee1394handle_t handle, unsigned char channel)
{
if (handle->iso_mode != ISO_RECV) {
errno = EINVAL;
@@ -249,7 +186,7 @@ int raw1394_iso_recv_listen_channel(raw1394handle_t handle, unsigned char channe
return ioctl(handle->fd, RAW1394_IOC_ISO_RECV_LISTEN_CHANNEL, channel);
}
-int raw1394_iso_recv_unlisten_channel(raw1394handle_t handle, unsigned char channel)
+int ieee1394_iso_recv_unlisten_channel(ieee1394handle_t handle, unsigned char channel)
{
if (handle->iso_mode != ISO_RECV) {
errno = EINVAL;
@@ -259,7 +196,7 @@ int raw1394_iso_recv_unlisten_channel(raw1394handle_t handle, unsigned char chan
return ioctl(handle->fd, RAW1394_IOC_ISO_RECV_UNLISTEN_CHANNEL, channel);
}
-int raw1394_iso_recv_flush(raw1394handle_t handle)
+int ieee1394_iso_recv_flush(ieee1394handle_t handle)
{
if (handle->iso_mode != ISO_RECV) {
errno = EINVAL;
@@ -269,7 +206,7 @@ int raw1394_iso_recv_flush(raw1394handle_t handle)
return ioctl(handle->fd, RAW1394_IOC_ISO_RECV_FLUSH, 0);
}
-int raw1394_iso_recv_set_channel_mask(raw1394handle_t handle, u_int64_t mask)
+int ieee1394_iso_recv_set_channel_mask(ieee1394handle_t handle, u_int64_t mask)
{
if (handle->iso_mode != ISO_RECV) {
errno = EINVAL;
@@ -279,7 +216,7 @@ int raw1394_iso_recv_set_channel_mask(raw1394handle_t handle, u_int64_t mask)
return ioctl(handle->fd, RAW1394_IOC_ISO_RECV_SET_CHANNEL_MASK, (void*) &mask);
}
-int raw1394_iso_recv_start(raw1394handle_t handle, int start_on_cycle, int tag_mask, int sync)
+int ieee1394_iso_recv_start(ieee1394handle_t handle, int start_on_cycle, int tag_mask, int sync)
{
int args[3];
@@ -299,14 +236,15 @@ int raw1394_iso_recv_start(raw1394handle_t handle, int start_on_cycle, int tag_m
return 0;
}
-static int _raw1394_iso_xmit_queue_packets(raw1394handle_t handle)
+static int _iso_xmit_queue_packets(raw1394handle_t handle)
{
- struct raw1394_iso_status *stat = &handle->iso_status;
+ ieee1394handle_t ihandle = handle->mode.ieee1394;
+ struct raw1394_iso_status *stat = &ihandle->iso_status;
struct raw1394_iso_packets packets;
int retval = -1;
int stop_sync = 0;
- if(handle->iso_mode != ISO_XMIT) {
+ if(ihandle->iso_mode != ISO_XMIT) {
errno = EINVAL;
goto out;
}
@@ -317,7 +255,7 @@ static int _raw1394_iso_xmit_queue_packets(raw1394handle_t handle)
/* we could potentially send up to stat->n_packets packets */
packets.n_packets = 0;
- packets.infos = handle->iso_packet_infos;
+ packets.infos = ihandle->iso_packet_infos;
if(packets.infos == NULL)
goto out;
@@ -327,27 +265,27 @@ static int _raw1394_iso_xmit_queue_packets(raw1394handle_t handle)
struct raw1394_iso_packet_info *info = &packets.infos[packets.n_packets];
- info->offset = handle->iso_buf_stride * handle->next_packet;
+ info->offset = ihandle->iso_buf_stride * ihandle->next_packet;
/* call handler */
- disp = handle->iso_xmit_handler(handle,
- handle->iso_buffer + info->offset,
+ disp = ihandle->iso_xmit_handler(handle,
+ ihandle->iso_buffer + info->offset,
&len,
&info->tag, &info->sy,
stat->xmit_cycle,
- _raw1394_iso_dropped(handle));
+ _iso_dropped(ihandle));
info->len = len;
/* advance packet cursors and cycle counter */
stat->n_packets--;
- handle->next_packet = increment_and_wrap(handle->next_packet, stat->config.buf_packets);
+ ihandle->next_packet = increment_and_wrap(ihandle->next_packet, stat->config.buf_packets);
if(stat->xmit_cycle != -1)
stat->xmit_cycle = increment_and_wrap(stat->xmit_cycle, 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))
+ if(ioctl(ihandle->fd, RAW1394_IOC_ISO_QUEUE_ACTIVITY, 0))
goto out_produce;
break;
} else if(disp == RAW1394_ISO_AGAIN) {
@@ -355,14 +293,14 @@ static int _raw1394_iso_xmit_queue_packets(raw1394handle_t handle)
packets.n_packets--;
/* queue an event so that we don't hang in the next read() */
- if(ioctl(handle->fd, RAW1394_IOC_ISO_QUEUE_ACTIVITY, 0))
+ if(ioctl(ihandle->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);
+ ieee1394_iso_stop(ihandle);
break;
} else if(disp == RAW1394_ISO_ERROR) {
goto out_produce;
@@ -374,68 +312,69 @@ static int _raw1394_iso_xmit_queue_packets(raw1394handle_t handle)
out_produce:
if(packets.n_packets > 0) {
- if(ioctl(handle->fd, RAW1394_IOC_ISO_XMIT_PACKETS, &packets))
+ if(ioctl(ihandle->fd, RAW1394_IOC_ISO_XMIT_PACKETS, &packets))
retval = -1;
}
out:
if(stop_sync) {
- if(raw1394_iso_xmit_sync(handle))
+ if(ieee1394_iso_xmit_sync(ihandle))
return -1;
- raw1394_iso_stop(handle);
+ ieee1394_iso_stop(ihandle);
}
return retval;
}
-int raw1394_iso_xmit_write(raw1394handle_t handle, unsigned char *data, unsigned int len,
+int ieee1394_iso_xmit_write(raw1394handle_t handle, unsigned char *data, unsigned int len,
unsigned char tag, unsigned char sy)
{
- struct raw1394_iso_status *stat = &handle->iso_status;
+ ieee1394handle_t ihandle = handle->mode.ieee1394;
+ struct raw1394_iso_status *stat = &ihandle->iso_status;
struct raw1394_iso_packets packets;
struct raw1394_iso_packet_info info;
- if(handle->iso_mode != ISO_XMIT || handle->iso_xmit_handler != NULL) {
+ if(ihandle->iso_mode != ISO_XMIT || ihandle->iso_xmit_handler != NULL) {
errno = EINVAL;
return -1;
}
/* wait until buffer space is available */
- while(handle->iso_status.n_packets <= 1) {
+ while(ihandle->iso_status.n_packets <= 1) {
/* if the file descriptor has been set non-blocking,
return immediately */
- if(fcntl(handle->fd, F_GETFL) & O_NONBLOCK) {
+ if(fcntl(ihandle->fd, F_GETFL) & O_NONBLOCK) {
errno = EAGAIN;
return -1;
}
- if(raw1394_loop_iterate(handle)) {
+ if(ieee1394_loop_iterate(handle)) {
return -1;
}
}
/* copy the data to the packet buffer */
- info.offset = handle->next_packet * handle->iso_buf_stride;
+ info.offset = ihandle->next_packet * ihandle->iso_buf_stride;
info.len = len;
info.tag = tag;
info.sy = sy;
- memcpy(handle->iso_buffer + info.offset, data, len);
+ memcpy(ihandle->iso_buffer + info.offset, data, len);
packets.n_packets = 1;
packets.infos = &info;
- if(ioctl(handle->fd, RAW1394_IOC_ISO_XMIT_PACKETS, &packets))
+ if(ioctl(ihandle->fd, RAW1394_IOC_ISO_XMIT_PACKETS, &packets))
return -1;
stat->n_packets--;
- handle->next_packet = increment_and_wrap(handle->next_packet, stat->config.buf_packets);
+ ihandle->next_packet = increment_and_wrap(ihandle->next_packet, stat->config.buf_packets);
if(stat->xmit_cycle != -1)
stat->xmit_cycle = increment_and_wrap(stat->xmit_cycle, 8000);
return 0;
}
-int raw1394_iso_xmit_start(raw1394handle_t handle, int start_on_cycle, int prebuffer_packets)
+int ieee1394_iso_xmit_start(ieee1394handle_t handle, int start_on_cycle, int prebuffer_packets)
{
int args[2];
@@ -454,7 +393,7 @@ int raw1394_iso_xmit_start(raw1394handle_t handle, int start_on_cycle, int prebu
return 0;
}
-int raw1394_iso_xmit_sync(raw1394handle_t handle)
+int ieee1394_iso_xmit_sync(ieee1394handle_t handle)
{
if(handle->iso_mode != ISO_XMIT) {
errno = EINVAL;
@@ -463,7 +402,7 @@ int raw1394_iso_xmit_sync(raw1394handle_t handle)
return ioctl(handle->fd, RAW1394_IOC_ISO_XMIT_SYNC, 0);
}
-void raw1394_iso_stop(raw1394handle_t handle)
+void ieee1394_iso_stop(ieee1394handle_t handle)
{
if(handle->iso_mode == ISO_INACTIVE) {
return;
@@ -473,7 +412,7 @@ void raw1394_iso_stop(raw1394handle_t handle)
handle->iso_state = ISO_STOP;
}
-void raw1394_iso_shutdown(raw1394handle_t handle)
+void ieee1394_iso_shutdown(ieee1394handle_t handle)
{
if(handle->iso_buffer) {
munmap(handle->iso_buffer, handle->iso_status.config.data_buf_size);
@@ -481,7 +420,7 @@ void raw1394_iso_shutdown(raw1394handle_t handle)
}
if(handle->iso_mode != ISO_INACTIVE) {
- raw1394_iso_stop(handle);
+ ieee1394_iso_stop(handle);
ioctl(handle->fd, RAW1394_IOC_ISO_SHUTDOWN, 0);
}
@@ -498,7 +437,7 @@ void raw1394_iso_shutdown(raw1394handle_t handle)
handle->iso_mode = ISO_INACTIVE;
}
-int raw1394_read_cycle_timer(raw1394handle_t handle,
+int ieee1394_read_cycle_timer(ieee1394handle_t handle,
u_int32_t *cycle_timer, u_int64_t *local_time)
{
int err;
@@ -512,25 +451,26 @@ int raw1394_read_cycle_timer(raw1394handle_t handle,
return err;
}
-static int _raw1394_iso_recv_packets(raw1394handle_t handle)
+static int _iso_recv_packets(raw1394handle_t handle)
{
- struct raw1394_iso_status *stat = &handle->iso_status;
+ ieee1394handle_t ihandle = handle->mode.ieee1394;
+ struct raw1394_iso_status *stat = &ihandle->iso_status;
struct raw1394_iso_packets packets;
int retval = -1, packets_done = 0;
- if(handle->iso_mode != ISO_RECV) {
+ if(ihandle->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 = handle->iso_packet_infos;
+ packets.infos = ihandle->iso_packet_infos;
if(packets.infos == NULL)
goto out;
- if(ioctl(handle->fd, RAW1394_IOC_ISO_RECV_PACKETS, &packets) < 0)
+ if(ioctl(ihandle->fd, RAW1394_IOC_ISO_RECV_PACKETS, &packets) < 0)
goto out;
while(stat->n_packets > 0) {
@@ -540,12 +480,12 @@ static int _raw1394_iso_recv_packets(raw1394handle_t handle)
info = &packets.infos[packets_done];
/* call handler */
- disp = handle->iso_recv_handler(handle,
- handle->iso_buffer + info->offset,
+ disp = ihandle->iso_recv_handler(handle,
+ ihandle->iso_buffer + info->offset,
info->len, info->channel,
info->tag, info->sy,
info->cycle,
- _raw1394_iso_dropped(handle));
+ _iso_dropped(ihandle));
/* advance packet cursors */
stat->n_packets--;
@@ -553,11 +493,11 @@ static int _raw1394_iso_recv_packets(raw1394handle_t handle)
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))
+ if(ioctl(ihandle->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);
+ ieee1394_iso_stop(ihandle);
break;
} else if(disp == RAW1394_ISO_ERROR) {
goto out_consume;
@@ -569,7 +509,7 @@ static int _raw1394_iso_recv_packets(raw1394handle_t handle)
out_consume:
if(packets_done > 0) {
- if(ioctl(handle->fd, RAW1394_IOC_ISO_RECV_RELEASE_PACKETS, packets_done))
+ if(ioctl(ihandle->fd, RAW1394_IOC_ISO_RECV_RELEASE_PACKETS, packets_done))
retval = -1;
}
out:
@@ -577,29 +517,30 @@ out:
}
/* run the ISO state machine; called from raw1394_loop_iterate() */
-int _raw1394_iso_iterate(raw1394handle_t handle)
+int _ieee1394_iso_iterate(raw1394handle_t handle)
{
+ ieee1394handle_t ihandle = handle->mode.ieee1394;
int err;
- if(handle->iso_mode == ISO_INACTIVE)
+ if(ihandle->iso_mode == ISO_INACTIVE)
return 0;
- err = ioctl(handle->fd, RAW1394_IOC_ISO_GET_STATUS, &handle->iso_status);
+ err = ioctl(ihandle->fd, RAW1394_IOC_ISO_GET_STATUS, &ihandle->iso_status);
if(err != 0)
return err;
- handle->iso_packets_dropped += handle->iso_status.overflows;
+ ihandle->iso_packets_dropped += ihandle->iso_status.overflows;
- if(handle->iso_state == ISO_GO) {
- if(handle->iso_mode == ISO_XMIT) {
- if(handle->iso_xmit_handler) {
- return _raw1394_iso_xmit_queue_packets(handle);
+ if(ihandle->iso_state == ISO_GO) {
+ if(ihandle->iso_mode == ISO_XMIT) {
+ if(ihandle->iso_xmit_handler) {
+ return _iso_xmit_queue_packets(handle);
}
}
- if(handle->iso_mode == ISO_RECV) {
- if(handle->iso_recv_handler) {
- return _raw1394_iso_recv_packets(handle);
+ if(ihandle->iso_mode == ISO_RECV) {
+ if(ihandle->iso_recv_handler) {
+ return _iso_recv_packets(handle);
}
}
}