Hi all,

I'm not proficient at all with ioctl calls in Perl, so maybe someone can enlighten me on this one. Given a kernel module to access a PCI card /dev/pcicard. The following C code is working for writing a value to an internal register of the PCI card. The following code is proven to work:
#include <stdio.h> #include <sys/ioctl.h> #include <fcntl.h> #include "pcicard.h" int main(int argc, char **argv) { u8 val; int fd; if ((fd = open('/dev/pcicard', O_RDWR)) == -1) { perror("open"); exit(1); } val = 0x03; ioctl(fd, PCICARD_SET_REGISTER, &val); close(fd); exit(1); }
Here's a snipplet from pcicard.h:
#define PCIMAX_IOC_NUM 'O' #define PCICARD_SET_REGISTER _IOR(PCICARD_IOC_NUM, 1, u8 *) #define PCICARD_GET_REGISTER _IOW(PCICARD_IOC_NUM, 2, u8 *)
After converting with h2ph and moving the relevant lines into the Perl script itself, it looks as follows:
#!/usr/bin/perl require 'sys/ioctl.ph'; require '_h2ph_pre.ph'; sub PCICARD_IOC_NUM () { ord('0'); } sub PCICARD_SET_REGISTER () { &_IOR( &PCICARD_IOC_NUM, 1, 'int' ); } sub PCICARD_GET_REGISTER () { &_IOW( &PCICARD_IOC_NUM, 2, 'int' ); } $value = 0x03; open(PCI, '+</dev/pcimax'); ioctl(PCI, &PCICARD_SET_REGISTER, \$value); close(PCI);
However, this does not work. The corresponding code in the kernel module is not being executed. Any hints what I'm missing here? Many thanks!
Sven

Retitled by davido per consideration vote.


In reply to Help using ioctl to write a PCI device by p-rex

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.