Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

I/O Access

121 views
Skip to first unread message

tie

unread,
Jun 10, 2002, 6:02:22 PM6/10/02
to
1)Does anyone know how to use in8() and out8() in qnx?
2)Can I use these functions to read and write
data from I/O port?
3)In QNX 6.2 library,
uint8_t in8(uintptr_t port);
what 's the meaning of unintptr and uint8_t?
4)Is in8() and out() same with _inp() and
_outp() function in Visual C++?

Tie Hu
6/10


David Gibbs

unread,
Jun 10, 2002, 6:03:58 PM6/10/02
to
tie <t...@cbis.ece.drexel.edu> wrote:

Answered elsewhere in detail.

> 1)Does anyone know how to use in8() and out8() in qnx?

Yes. Need ThreadCtl() first.

> 2)Can I use these functions to read and write
> data from I/O port?

Yes, that's what they're for.

> 3)In QNX 6.2 library,
> uint8_t in8(uintptr_t port);
> what 's the meaning of unintptr and uint8_t?

Returns unsigned 8-bit value, takes a pointer to an unsigned integer
(i.e. an address) as a parameter.

> 4)Is in8() and out() same with _inp() and
> _outp() function in Visual C++?

Essentially, yes.

See /usr/include/x86/inout.h for more detail of x86 implementation.

-David
--
QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

tie

unread,
Jun 11, 2002, 6:49:42 PM6/11/02
to
The following is a small program I make to write I/O port. But it doesn't
work.
After I compile it with qcc and run it, "Memory Fault(Core Dump)" will
appear.
Can anyone help me?


/* Library for I/O and Thread Control*/
#include <sys/neutrino.h>
#include <hw/inout.h>
#include <sys/mman.h>


#define cfr 0x2e6 /* configulation register */


int
main()
{

ThreadCtl(_NTO_TCTL_IO,0);/* Thread control*/


mmap_device_io(1,cfr); /* Map device I/O */


out8( cfr, 0x80 ); /* Software Reset*/

return(0);

}


Best Regard


Tie Hu

6/11/02


Paul N. Leonard

unread,
Jun 11, 2002, 7:50:38 PM6/11/02
to
I believe you need to set the privity level during compile to 0 and
you must run as root in order to access IO of any sort.

During compilation, add the flag "-T 0" to your other flags and see
if that helps.

Chris McKillop

unread,
Jun 12, 2002, 2:00:02 AM6/12/02
to
Paul N. Leonard <pa...@ifspurity.com> wrote:
> I believe you need to set the privity level during compile to 0 and
> you must run as root in order to access IO of any sort.
>
> During compilation, add the flag "-T 0" to your other flags and see
> if that helps.
>

That is how it works under QNX4. The key is making sure you are
running the code as root. Also, you should be making sure you check
the return values of all your function calls and error-ing out on
any failure. You would have gotten an error on your call to ThreadCtrl().

chris

>
> tie wrote:
>>
>> The following is a small program I make to write I/O port. But it doesn't
>> work.
>> After I compile it with qcc and run it, "Memory Fault(Core Dump)" will
>> appear.
>> Can anyone help me?
>>
>> /* Library for I/O and Thread Control*/
>> #include <sys/neutrino.h>
>> #include <hw/inout.h>
>> #include <sys/mman.h>
>>
>> #define cfr 0x2e6 /* configulation register */
>>
>> int
>> main()
>> {
>>
>> ThreadCtl(_NTO_TCTL_IO,0);/* Thread control*/
>>
>> mmap_device_io(1,cfr); /* Map device I/O */
>>
>> out8( cfr, 0x80 ); /* Software Reset*/
>>
>> return(0);
>>
>> }
>>
>> Best Regard
>>
>> Tie Hu
>>
>> 6/11/02

--
Chris McKillop <c...@qnx.com> "The faster I go, the behinder I get."
Software Engineer, QSSL -- Lewis Carroll --
http://qnx.wox.org/


David Gibbs

unread,
Jun 12, 2002, 9:31:09 AM6/12/02
to
tie <t...@cbis.ece.drexel.edu> wrote:
> The following is a small program I make to write I/O port. But it doesn't
> work.
> After I compile it with qcc and run it, "Memory Fault(Core Dump)" will
> appear.
> Can anyone help me?


> /* Library for I/O and Thread Control*/
> #include <sys/neutrino.h>
> #include <hw/inout.h>
> #include <sys/mman.h>

#include <errno.h>

> #define cfr 0x2e6 /* configulation register */


> int
> main()
> {

uintptr_t port;
int ret;

if( ThreadCtl(_NTO_TCTL_IO,0) == -1 ) /* Thread control*/
{
perror("threadctl failed");
return 1;
}


port = mmap_device_io(1,cfr); /* Map device I/O */
if( MAP_FAILED == port )
{
perror("mmap failed");
return 1;
}

out8( port, 0x80 ); /* Software Reset*/

> return(0);

> }


When something isn't working, error checking is usually helpful.

> Best Regard


> Tie Hu

> 6/11/02

--

Dmitri Ivanov

unread,
Jun 18, 2002, 7:37:16 AM6/18/02
to

> port = mmap_device_io(1,cfr); /* Map device I/O */
> if( MAP_FAILED == port )
> {
> perror("mmap failed");
> return 1;
> }
>

what's mmap_device_io() for ?


Akhilesh Mritunjai

unread,
Jun 23, 2002, 6:25:59 AM6/23/02
to
Hi

"Dmitri Ivanov" <iv...@yahoo.com> wrote in message

> what's mmap_device_io() for ?

mmap_device_io is a cross platform way to access hardware ports. On an
x86, it will simply return the port number ,so you're essentially
doing out8(0x2e6, 0x80) on an x86. But on other platforms like
mips/sh/arm where some of them map ioports to memory addesses or do
other wizardary, mmap_device_io will return the handle to IO region
which in*/out* functions will use to perform the IO.

--
Regards
- Mritunjai

David Gibbs

unread,
Jun 24, 2002, 3:16:10 PM6/24/02
to
Dmitri Ivanov <iv...@yahoo.com> wrote:

On x86 it doesn't do anything. On most other platforms, there
are NOT special op-codes for accessing "io ports", though on
other platforms, these are often called "hardware registers"
or "control registers", so they must be accessed as memory.
mmap_device_io() does a mmap() with the appropriate flags to
give you a virtual pointer to the hardware registers you
wish to read/modify.

On these platforms the inxx()/outxx() functions do the
appropriate work to read/write those memory locations along
with whatever synchronisation operation might be needed.

-David

0 new messages