I hope this isn't too esoteric but I'm pretty well at wits end on this.
I am trying to use the ieee1284 library to build a tool for accessing parallel ports in some non-standard ways. The docs are fairly clear and my code builds cleanly, but I cannot get around the problem of exclusive access denial.
I set the environment variable LIBIEEE1284_DEBUG="1", and run th following code as root:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <ieee1284.h>
int main( int argc, char * argv[] ){
int lp;
unsigned char byte;
unsigned int baseAddr;
int i;
struct parport_list lpList;
struct parport * port;
int capabilities;
int portStatus;
if( argc < 2 ){
printf( "No output byte\n" );
exit(1);
}
sscanf( argv[1], "%i", &byte );
printf( "Outp byte: %02X\n", byte );
ieee1284_find_ports( &lpList, 0 );
for( i = 0; i < lpList.portc; i++ ){
port = lpList.portv[i];
printf( " Name[%d] = %s\n", i, port -> name );
printf( " BaseAddr[%d] = %04X\n", i, port -> base_addr );
printf( "hiBaseAddr[%d] = %04X\n", i, port -> hibase_addr );
printf( " Filename[%d] = %s\n\n", i, port -> filename );
}
if( lpList.portc ){
port = lpList.portv[0];
baseAddr = port -> base_addr;
}
else{
printf( "No ieee1284 port\n" );
exit(1);
}
/*
** Exclusive access fails at ieee1284_claim....
**
** portStatus = ieee1284_open( port, 0, &capabilities );
*/
portStatus = ieee1284_open( port, F1284_EXCL, &capabilities );
printf( "Open Status: %d\n", portStatus );
printf( "Open Capabilities: %04X\n", capabilities );
if( capabilities & CAP1284_RAW ){
printf( "CAP1284_RAW, " );
}
if( capabilities & CAP1284_NIBBLE ){
printf( "CAP1284_NIBBLE, " );
}
if( capabilities & CAP1284_BYTE ){
printf( "CAP1284_BYTE, " );
}
if( capabilities & CAP1284_COMPAT ){
printf( "CAP1284_COMPAT, " );
}
if( capabilities & CAP1284_ECP ){
printf( "CAP1284_ECP, " );
}
if( capabilities & CAP1284_ECPRLE ){
printf( "CAP1284_ECPRLE, " );
}
if( capabilities & CAP1284_ECPSWE ){
printf( "CAP1284_ECPSWE, " );
}
if( capabilities & CAP1284_BECP ){
printf( "CAP1284_BECP, " );
}
if( capabilities & CAP1284_EPP ){
printf( "CAP1284_EPP, " );
}
if( capabilities & CAP1284_EPPSWE ){
printf( "CAP1284_EPPSWE, " );
}
if( capabilities & CAP1284_IRQ ){
printf( "CAP1284_IRQ, " );
}
if( capabilities & CAP1284_DMA ){
printf( "CAP1284_DMA, " );
}
printf( "\n" );
/* Something on the net said try this, but it makes no diff...
*/
ieee1284_free_ports( &lpList );
portStatus = ieee1284_claim( port );
printf( "Claim Status: %d\n", portStatus );
if( portStatus & E1284_SYS ){
perror( "ieee1284 Claim: " );
exit(1);
}
ieee1284_write_data( port, byte );
printf( "WriteData Status: %d\n", portStatus );
if( portStatus & E1284_SYS ){
perror( "ieee1284 WriteData: " );
exit(1);
}
ieee1284_release( port );
printf( "Release Status: %d\n", portStatus );
if( portStatus & E1284_SYS ){
perror( "ieee1284 Release: " );
exit(1);
}
portStatus = ieee1284_close( port );
printf( "\nClose Status: %d\n", portStatus );
exit(0);
}
As far as I can tell, I start out with no loadable modules that would want to access the parallel port, so I don't see where there should be any contention for the hardware or device file (/dev/parport0)
The output from the code, including the driver debug output:
Code:
./lptTest2 0x0ff
Outp byte: FF
/dev/parport0 is accessible
We can use ioperm()
/dev/port is accessible
/dev/lp0 is accessible
This system has /proc/sys/dev/parport
Name[0] = parport0
BaseAddr[0] = 0378
hiBaseAddr[0] = 0778
Filename[0] = /dev/parport0
==> ieee1284_open
==> init_port
Got 0 from ppdev init
<== 0
Open Status: 0
Open Capabilities: 01EE
CAP1284_NIBBLE, CAP1284_BYTE, CAP1284_COMPAT, CAP1284_ECP, CAP1284_ECPRLE, CAP1284_ECPSWE, CAP1284_EPP,
==> claim
<== E1284_SYS
Claim Status: -8
ieee1284 Claim: : No such device or address
Interestingly, lsmod now shows a bunch of modules related to parallel ports.
Code:
/sbin/lsmod
Module Size Used by
lp 14893 0
parport_pc 27777 1
ppdev 12613 0
parport 37256 3 lp,parport_pc,ppdev
(more unrelated stuff omitted....)
Who can explain what I'm seeing, and how to gain exclusive access?
uname -a
Linux 2.6.9-42.0.3.ELhugemem #1 SMP Thu Oct 5 15:24:32 CDT 2006 i686 i686 i386 GNU/Linux
Thanks.
--- rod.