add functions for allocating and releasing bandwidth and channels

git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@154 53a565d1-3bb7-0310-b661-cf11e63c67ab
This commit is contained in:
ddennedy 2005-02-16 16:54:58 +00:00
parent 9d07aaadda
commit 246f623e35
6 changed files with 296 additions and 5 deletions

4
NEWS
View File

@ -1,3 +1,7 @@
Version 1.2.0:
- added constants useful for ARM: transaction and response return codes.
- added raw1394_bandwidth_modify() and raw1394_channel_modify().
Version 1.1.0:
- added ability to specify the isochronous receive mode in the new
rawiso (raw1394_iso_*) API. Therefore, the signature of

View File

@ -1,6 +1,6 @@
# process this file with autoconf to get a configure script
AC_INIT(libraw1394, 1.1.0)
AC_INIT(libraw1394, 1.2.0)
AC_CONFIG_SRCDIR(src/raw1394.h)
AM_CONFIG_HEADER(config.h)
@ -16,9 +16,9 @@ AC_C_CONST
AC_C_BIGENDIAN
# set the libtool so version numbers
lt_major=8
lt_major=9
lt_revision=0
lt_age=0
lt_age=1
AC_SUBST(lt_major)
AC_SUBST(lt_revision)

View File

@ -4,7 +4,7 @@
<bookinfo>
<title>libraw1394</title>
<subtitle>version 1.1.0</subtitle>
<subtitle>version 1.2.0</subtitle>
<copyright>
<year>2001-2004</year>
@ -4891,6 +4891,130 @@
</refsect1>
</refentry>
<refentry>
<refmeta>
<refentrytitle><phrase id="API-raw1394-bandwidth-modify">raw1394_bandwidth_modify</phrase></refentrytitle>
</refmeta>
<refnamediv>
<refname>raw1394_bandwidth_modify</refname>
<refpurpose>
allocate or release bandwidth
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<title>Synopsis</title>
<funcsynopsis><funcprototype>
<funcdef>int <function>raw1394_bandwidth_modify </function></funcdef>
<paramdef>raw1394handle_t <parameter>handle</parameter></paramdef>
<paramdef>unsigned int <parameter>bandwidth</parameter></paramdef>
<paramdef>enum raw1394_modify_mode <parameter>mode</parameter></paramdef>
</funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>Arguments</title>
<variablelist>
<varlistentry>
<term><parameter>handle</parameter></term>
<listitem>
<para>
a libraw1394 handle
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>bandwidth</parameter></term>
<listitem>
<para>
IEEE 1394 Bandwidth Alloction Units
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>mode</parameter></term>
<listitem>
<para>
whether to allocate or free
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
Communicates with the isochronous resource manager.
</para>
</refsect1>
<refsect1>
<title>Return</title>
<para>
-1 for failure, 0 for success
</para>
</refsect1>
</refentry>
<refentry>
<refmeta>
<refentrytitle><phrase id="API-raw1394-channel-modify">raw1394_channel_modify</phrase></refentrytitle>
</refmeta>
<refnamediv>
<refname>raw1394_channel_modify</refname>
<refpurpose>
allocate or release isochronous channel
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<title>Synopsis</title>
<funcsynopsis><funcprototype>
<funcdef>int <function>raw1394_channel_modify </function></funcdef>
<paramdef>raw1394handle_t <parameter>handle</parameter></paramdef>
<paramdef>unsigned int <parameter>channel</parameter></paramdef>
<paramdef>enum raw1394_modify_mode <parameter>mode</parameter></paramdef>
</funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>Arguments</title>
<variablelist>
<varlistentry>
<term><parameter>handle</parameter></term>
<listitem>
<para>
a libraw1394 handle
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>channel</parameter></term>
<listitem>
<para>
isochronous channel
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>mode</parameter></term>
<listitem>
<para>
whether to allocate or free
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
Communicates with the isochronous resource manager.
</para>
</refsect1>
<refsect1>
<title>Return</title>
<para>
-1 for failure, 0 for success
</para>
</refsect1>
</refentry>
<refentry>
<refmeta>
<refentrytitle><phrase id="API-int">int</phrase></refentrytitle>

View File

@ -27,8 +27,10 @@
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <netinet/in.h>
#include "raw1394.h"
#include "csr.h"
#include "kernel-raw1394.h"
#include "raw1394_private.h"
@ -367,3 +369,111 @@ int raw1394_get_config_rom(raw1394handle_t handle, quadlet_t *buffer,
return status;
}
int raw1394_bandwidth_modify (raw1394handle_t handle, unsigned int bandwidth,
enum raw1394_modify_mode mode)
{
quadlet_t buffer, compare, swap, new;
int retry = 3;
int result;
if (bandwidth == 0)
return 0;
/* Reading current bandwidth usage from IRM. */
result = raw1394_read (handle, raw1394_get_irm_id (handle),
CSR_REGISTER_BASE + CSR_BANDWIDTH_AVAILABLE,
sizeof (quadlet_t), &buffer);
if (result < 0)
return -1;
buffer = ntohl (buffer);
compare = buffer;
while (retry > 0) {
if (mode == RAW1394_MODIFY_ALLOC ) {
if (compare < bandwidth) {
return -1;
}
swap = compare - bandwidth;
}
else {
swap = compare + bandwidth;
if( swap > MAXIMUM_BANDWIDTH ) {
swap = MAXIMUM_BANDWIDTH;
}
}
result = raw1394_lock (handle, raw1394_get_irm_id (handle),
CSR_REGISTER_BASE + CSR_BANDWIDTH_AVAILABLE,
RAW1394_EXTCODE_COMPARE_SWAP, ntohl(swap), ntohl(compare),
&new);
if (result < 0)
return -1;
new = ntohl (new);
if (new != compare) {
compare = new;
retry--;
if ( retry == 0 )
return -1;
}
else {
/* Success. */
retry = 0;
return 0;
}
}
return 0;
}
int raw1394_channel_modify (raw1394handle_t handle, unsigned int channel,
enum raw1394_modify_mode mode)
{
quadlet_t buffer;
int result;
nodeaddr_t addr = CSR_REGISTER_BASE;
unsigned int c = channel;
quadlet_t compare, swap = 0, new;
if (c > 31 && c < 64) {
addr += CSR_CHANNELS_AVAILABLE_LO;
c -= 32;
} else if (c < 64)
addr += CSR_CHANNELS_AVAILABLE_HI;
else
return -1;
c = 31 - c;
result = raw1394_read (handle, raw1394_get_irm_id (handle), addr,
sizeof (quadlet_t), &buffer);
if (result < 0)
return -1;
buffer = ntohl (buffer);
if ( mode == RAW1394_MODIFY_ALLOC ) {
if( (buffer & (1 << c)) == 0 )
return -1;
swap = htonl (buffer & ~(1 << c));
}
else if ( mode == RAW1394_MODIFY_FREE ) {
if ( (buffer & (1 << c)) != 0 )
return -1;
swap = htonl (buffer | (1 << c));
}
compare = htonl (buffer);
result = raw1394_lock (handle, raw1394_get_irm_id (handle), addr,
RAW1394_EXTCODE_COMPARE_SWAP, swap, compare, &new);
if ( (result < 0) || (new != compare) )
return -1;
return 0;
}

View File

@ -12,6 +12,8 @@
#ifndef _LIBRAW1394_RAW1394_H
#define _LIBRAW1394_RAW1394_H
#include <sys/types.h>
#define RAW1394_ARM_READ 1
#define RAW1394_ARM_WRITE 2
#define RAW1394_ARM_LOCK 4
@ -23,7 +25,21 @@
#define RAW1394_NOTIFY_OFF 0
#define RAW1394_NOTIFY_ON 1
#include <sys/types.h>
/* extended transaction codes (lock-request-response) */
#define RAW1394_EXTCODE_MASK_SWAP 0x1
#define RAW1394_EXTCODE_COMPARE_SWAP 0x2
#define RAW1394_EXTCODE_FETCH_ADD 0x3
#define RAW1394_EXTCODE_LITTLE_ADD 0x4
#define RAW1394_EXTCODE_BOUNDED_ADD 0x5
#define RAW1394_EXTCODE_WRAP_ADD 0x6
/* response codes */
#define RAW1394_RCODE_COMPLETE 0x0
#define RAW1394_RCODE_CONFLICT_ERROR 0x4
#define RAW1394_RCODE_DATA_ERROR 0x5
#define RAW1394_RCODE_TYPE_ERROR 0x6
#define RAW1394_RCODE_ADDRESS_ERROR 0x7
typedef u_int8_t byte_t;
typedef u_int32_t quadlet_t;
typedef u_int64_t octlet_t;
@ -92,6 +108,12 @@ enum raw1394_iso_disposition {
RAW1394_ISO_STOP_NOSYNC = 4,
};
enum raw1394_modify_mode {
RAW1394_MODIFY_ALLOC,
RAW1394_MODIFY_FREE
};
#ifdef __cplusplus
extern "C" {
#endif
@ -1124,6 +1146,36 @@ int raw1394_update_config_rom(raw1394handle_t handle, const quadlet_t
int raw1394_get_config_rom(raw1394handle_t handle, quadlet_t *buffer,
size_t buffersize, size_t *rom_size, unsigned char *rom_version);
/**
* raw1394_bandwidth_modify - allocate or release bandwidth
* @handle: a libraw1394 handle
* @bandwidth: IEEE 1394 Bandwidth Alloction Units
* @mode: whether to allocate or free
*
* Communicates with the isochronous resource manager.
*
* Return:
* -1 for failure, 0 for success
**/
int
raw1394_bandwidth_modify (raw1394handle_t handle, unsigned int bandwidth,
enum raw1394_modify_mode mode);
/**
* raw1394_bandwidth_modify - allocate or release isochronous channel
* @handle: a libraw1394 handle
* @channel: isochronous channel
* @mode: whether to allocate or free
*
* Communicates with the isochronous resource manager.
*
* Return:
* -1 for failure, 0 for success
**/
int
raw1394_channel_modify (raw1394handle_t handle, unsigned int channel,
enum raw1394_modify_mode mode);
/**
* iso_handler_t - DEPRECATED

View File

@ -4,6 +4,7 @@
#define HBUF_SIZE 8192
#define ARM_REC_LENGTH 4096
#define MAXIMUM_BANDWIDTH 4915
struct raw1394_handle {
int fd;