| 1 |
/* |
| 2 |
* libiec61883 - Linux IEEE 1394 streaming media library. |
| 3 |
* Copyright (C) 2004 Kristian Hogsberg, Dan Dennedy, and Dan Maas. |
| 4 |
* This code originally written by Andreas Micklei, then revised over the years |
| 5 |
* by Dan Dennedy. |
| 6 |
* |
| 7 |
* This library is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU Lesser General Public |
| 9 |
* License as published by the Free Software Foundation; either |
| 10 |
* version 2.1 of the License, or (at your option) any later version. |
| 11 |
* |
| 12 |
* This library is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
* Lesser General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU Lesser General Public |
| 18 |
* License along with this library; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifdef HAVE_CONFIG_H |
| 23 |
#include <config.h> |
| 24 |
#endif |
| 25 |
|
| 26 |
#include "cooked.h" |
| 27 |
|
| 28 |
#include <errno.h> |
| 29 |
#include <time.h> |
| 30 |
|
| 31 |
/* |
| 32 |
* constants for use with raw1394 ARM |
| 33 |
* The following probably should be in raw1394.h |
| 34 |
*/ |
| 35 |
|
| 36 |
|
| 37 |
/* maximum number of retry attempts on raw1394 async transactions */ |
| 38 |
#define MAXTRIES 20 |
| 39 |
|
| 40 |
/* amount of delay in nanoseconds to wait before retrying raw1394 async transaction */ |
| 41 |
#define RETRY_DELAY 20000 |
| 42 |
|
| 43 |
int |
| 44 |
iec61883_cooked_read(raw1394handle_t handle, nodeid_t node, nodeaddr_t addr, |
| 45 |
size_t length, quadlet_t *buffer) |
| 46 |
{ |
| 47 |
int retval, i; |
| 48 |
struct timespec ts = {0, RETRY_DELAY}; |
| 49 |
for (i = 0; i < MAXTRIES; i++) { |
| 50 |
retval = raw1394_read (handle, node, addr, length, buffer); |
| 51 |
if (retval < 0 && errno == EAGAIN) |
| 52 |
nanosleep(&ts, NULL); |
| 53 |
else |
| 54 |
return retval; |
| 55 |
} |
| 56 |
return -1; |
| 57 |
} |
| 58 |
|
| 59 |
int |
| 60 |
iec61883_cooked_write(raw1394handle_t handle, nodeid_t node, nodeaddr_t addr, |
| 61 |
size_t length, quadlet_t *data) |
| 62 |
{ |
| 63 |
int retval, i; |
| 64 |
struct timespec ts = {0, RETRY_DELAY}; |
| 65 |
for (i = 0; i < MAXTRIES; i++) { |
| 66 |
retval = raw1394_write (handle, node, addr, length, data); |
| 67 |
if (retval < 0 && errno == EAGAIN) |
| 68 |
nanosleep(&ts, NULL); |
| 69 |
else |
| 70 |
return retval; |
| 71 |
} |
| 72 |
return -1; |
| 73 |
} |