Re: port I/O in C

Discussion in 'C Programming' started by Bryan Bullard, Jul 7, 2003.

  1. as was stated these operation are platform specific. however, they are
    generally easily implemented with an assembler (either inline or separately
    linked).

    e.g.

    BYTE
    _in(WORD wPort)
    {
    BYTE value;
    asm volatile ("inb %w1,%b0" : "=a"(value) : "d"(wPort));
    return value;
    }

    good luck
    -bryan


    "Kevin Cifuentes" <> wrote in message
    news:p_LNa.6699$...
    > Hey all i need some of your help. I tried compiling this using Dev-C++ and
    > at no suprise it gave me an error. I say w/out suprise because I just
    > discovered that the _outp and possibly the _inp functions are
    > windows-specific in conio.h. I checked in conio.h provided in Dev-C++ and

    I
    > couldn't find the functions anywhere. Do any of you know where I can find

    a
    > header or library that has port I/O specific functions much similar to

    _inp
    > and _outp? Thanx. Here's the code:
    >
    > Code:
    >
    > #include <time.h>
    > #include <conio.h>
    >
    > int status;
    > if(!m_iNote) return;
    > m_iNote = (unsigned)(1193280L / m_iNote);
    > _outp(0x43,0xb6);
    > _outp(0x42,(char)m_iNote);
    > _outp(0x42,(char)(m_iNote >> 8));
    > status = _inp(0x61);
    > _outp(0x61,status | 0x03);
    > delay( (clock_t)m_iDuration );
    > _outp(0x61, status );
    >
    >
    Bryan Bullard, Jul 7, 2003
    #1
    1. Advertising

  2. Bryan Bullard

    Lew Pitcher Guest

    On Mon, 07 Jul 2003 14:48:55 GMT, "Bryan Bullard" <>
    wrote:

    >as was stated these operation are platform specific. however, they are
    >generally easily implemented with an assembler (either inline


    "inline assembly" is also a platform-specific extension of the C language.

    >or separately linked).
    >
    >e.g.
    >
    >BYTE
    >_in(WORD wPort)
    >{
    > BYTE value;
    > asm volatile ("inb %w1,%b0" : "=a"(value) : "d"(wPort));


    a) won't work in a strictly conforming standard C compiler
    b) won't work on an IBM S/390 processor

    > return value;
    >}
    >


    --
    Lew Pitcher
    IT Consultant, Enterprise Technology Solutions
    Toronto Dominion Bank Financial Group

    (Opinions expressed are my own, not my employers')
    Lew Pitcher, Jul 7, 2003
    #2
    1. Advertising

  3. Bryan Bullard

    Tom St Denis Guest

    Lew Pitcher wrote:
    > On Mon, 07 Jul 2003 14:48:55 GMT, "Bryan Bullard" <>
    > wrote:
    >
    >
    >>as was stated these operation are platform specific. however, they are
    >>generally easily implemented with an assembler (either inline

    >
    >
    > "inline assembly" is also a platform-specific extension of the C language.
    >
    >
    >>or separately linked).
    >>
    >>e.g.
    >>
    >>BYTE
    >>_in(WORD wPort)
    >>{
    >> BYTE value;
    >> asm volatile ("inb %w1,%b0" : "=a"(value) : "d"(wPort));

    >
    >
    > a) won't work in a strictly conforming standard C compiler
    > b) won't work on an IBM S/390 processor



    I don't get the point of this thread. If you are doing hardware I/O
    that is *BY DEFINITION* platform dependent. Find me an 8051 with an AGP
    port and I'll buy ya a beer.

    Besides GCC has #defines for various processors. So if you wanted to
    support multiple hardware archs from the same code you could.

    Tom
    Tom St Denis, Jul 7, 2003
    #3
  4. guys-

    like i said, "these operation are platform specific." the code listing was
    an EXAMPLE for mr. kevin.

    lighten up.

    -bryan

    "Tom St Denis" <> wrote in message
    news:HhgOa.90404$...
    > Lew Pitcher wrote:
    > > On Mon, 07 Jul 2003 14:48:55 GMT, "Bryan Bullard"

    <>
    > > wrote:
    > >
    > >
    > >>as was stated these operation are platform specific. however, they are
    > >>generally easily implemented with an assembler (either inline

    > >
    > >
    > > "inline assembly" is also a platform-specific extension of the C

    language.
    > >
    > >
    > >>or separately linked).
    > >>
    > >>e.g.
    > >>
    > >>BYTE
    > >>_in(WORD wPort)
    > >>{
    > >> BYTE value;
    > >> asm volatile ("inb %w1,%b0" : "=a"(value) : "d"(wPort));

    > >
    > >
    > > a) won't work in a strictly conforming standard C compiler
    > > b) won't work on an IBM S/390 processor

    >
    >
    > I don't get the point of this thread. If you are doing hardware I/O
    > that is *BY DEFINITION* platform dependent. Find me an 8051 with an AGP
    > port and I'll buy ya a beer.
    >
    > Besides GCC has #defines for various processors. So if you wanted to
    > support multiple hardware archs from the same code you could.
    >
    > Tom
    >
    Bryan Bullard, Jul 7, 2003
    #4
  5. Bryan Bullard

    Mr. 4X Guest

    "Bryan Bullard" <> wrote:

    > as was stated these operation are platform specific. however, they
    > are generally easily implemented with an assembler (either inline or
    > separately linked).
    >
    > e.g.
    >
    > BYTE
    > _in(WORD wPort)
    > {
    > BYTE value;
    > asm volatile ("inb %w1,%b0" : "=a"(value) : "d"(wPort));


    Now THAT is really platform specific - and I guess really OT here :|

    > return value;
    > }
    >
    > good luck
    > -bryan
    >
    >
    > "Kevin Cifuentes" <> wrote in message
    > news:p_LNa.6699$...
    >> Hey all i need some of your help. I tried compiling this using
    >> Dev-C++ and at no suprise it gave me an error. I say w/out suprise
    >> because I just discovered that the _outp and possibly the _inp
    >> functions are windows-specific in conio.h. I checked in conio.h
    >> provided in Dev-C++ and

    > I
    >> couldn't find the functions anywhere. Do any of you know where I can
    >> find

    > a
    >> header or library that has port I/O specific functions much similar
    >> to

    > _inp
    >> and _outp? Thanx. Here's the code:
    >>
    >> Code:
    >>
    >> #include <time.h>
    >> #include <conio.h>
    >>
    >> int status;
    >> if(!m_iNote) return;
    >> m_iNote = (unsigned)(1193280L / m_iNote);
    >> _outp(0x43,0xb6);
    >> _outp(0x42,(char)m_iNote);
    >> _outp(0x42,(char)(m_iNote >> 8));
    >> status = _inp(0x61);
    >> _outp(0x61,status | 0x03);
    >> delay( (clock_t)m_iDuration );
    >> _outp(0x61, status );
    >>
    >>

    >
    >
    Mr. 4X, Jul 7, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John T. Goodman

    Overhead of 4-port over 2-port SRAM

    John T. Goodman, Jan 25, 2005, in forum: VHDL
    Replies:
    0
    Views:
    588
    John T. Goodman
    Jan 25, 2005
  2. Sean Wolfe
    Replies:
    1
    Views:
    2,237
    Joerg Jooss
    Apr 28, 2005
  3. b3ny
    Replies:
    11
    Views:
    908
    Babu Kalakrishnan
    Nov 20, 2004
  4. Gerald Klix
    Replies:
    0
    Views:
    1,258
    Gerald Klix
    Oct 26, 2005
  5. Pom
    Replies:
    2
    Views:
    1,630
    Bas-i
    Jan 31, 2007
Loading...

Share This Page