io ports access stupid question

Can anyone give me an step-by step example for
accessing, say, io port 0x3f8?

\

vadik likholetov (7 812) 2189478

What’s a problem ?
Smth like that:


#include <sys/neutrino.h>
#include <hw/inout.h>

#define PORT_NUMBER 0x03FF

ThreadCtl(_NTO_TCTL_IO,0); // rights to io-operations

// reading from port:
unsigned char dataReadFromPort = in8(PORT_NUMBER);

// lets write to the port
unsigned char dataToWriteToPort=0;
out8(PORT_NUMBER,dataToWriteToPort);

If you are root all should be OK. I don’t remember how
ThreadCtl indicate errors - see help.

Alexey S. Drozdov <adrozdov@itsib.ru> wrote:

What’s a problem ?
Smth like that:

I’m wondering what for mmap_device_io for than?


#include <sys/neutrino.h
#include <hw/inout.h

#define PORT_NUMBER 0x03FF

ThreadCtl(_NTO_TCTL_IO,0); // rights to io-operations

// reading from port:
unsigned char dataReadFromPort = in8(PORT_NUMBER);

// lets write to the port
unsigned char dataToWriteToPort=0;
out8(PORT_NUMBER,dataToWriteToPort);

If you are root all should be OK. I don’t remember how
ThreadCtl indicate errors - see help.

vadik likholetov (7 812) 2189478

“Alexey S. Drozdov” <adrozdov@itsib.ru> wrote in message
news:90t5c8$pod$1@inn.qnx.com

What’s a problem ?
Smth like that:


#include <sys/neutrino.h
#include <hw/inout.h

#define PORT_NUMBER 0x03FF

ThreadCtl(_NTO_TCTL_IO,0); // rights to io-operations

Na the proper way is:

port = mmap_device_io (PORT_NUBMER…)

// reading from port:

unsigned char dataReadFromPort = in8(port);

// lets write to the port
unsigned char dataToWriteToPort=0;
out8( port, ataToWriteToPort);

This will make the code portabble on various platform (PPC, MIPS)
On x86 mmap_device_io does nothing -).

If you are root all should be OK. I don’t remember how
ThreadCtl indicate errors - see help.

vadik likholetov <vadik@hq.pu.ru> wrote:

Alexey S. Drozdov <> adrozdov@itsib.ru> > wrote:
What’s a problem ?
Smth like that:

I’m wondering what for mmap_device_io for than?

On non-x86 systems, io-ports don’t exist as special locations
with operations the way they do on x86. mmap_device_io() will
do a mmap() of the appropriate type to map the address space for
those devices into your program. On x86, it won’t do anything.
Use it for portability. (Your example with a port of 0x3FF was
pretty clearly x86 based just from the ioport value.)

On x86, in8/out8 etc are special instructions. On non-x86, they are
usually a memory assigned/check along with a “synchronise the IO
bus” instruction.

-David


#include <sys/neutrino.h
#include <hw/inout.h

#define PORT_NUMBER 0x03FF

ThreadCtl(_NTO_TCTL_IO,0); // rights to io-operations

// reading from port:
unsigned char dataReadFromPort = in8(PORT_NUMBER);

// lets write to the port
unsigned char dataToWriteToPort=0;
out8(PORT_NUMBER,dataToWriteToPort);

If you are root all should be OK. I don’t remember how
ThreadCtl indicate errors - see help.



vadik likholetov (7 812) 2189478

“David Gibbs” <dagibbs@qnx.com> wrote in message
news:918mf0$pm0$1@nntp.qnx.com


On non-x86, they are
usually a memory assigned/check along with a “synchronise the IO
bus” instruction.

Can you elaborate on the syncrhonise the IO bus instruction thingie?

Mario Charest <mcharest@void_zinformatic.com> wrote:

“David Gibbs” <> dagibbs@qnx.com> > wrote in message
news:918mf0$pm0$> 1@nntp.qnx.com> …



On non-x86, they are
usually a memory assigned/check along with a “synchronise the IO
bus” instruction.

Can you elaborate on the syncrhonise the IO bus instruction thingie?

From /usr/nto/include/ppc/inout.h

#define eieio() asm volatile( “eieio” )


/* … */

static inline void attribute((unused))
out8(_uintptr __addr, _uint8 __data) {
*(volatile _uint8 *)__addr = __data;
eieio();
}


From /usr/nto/include/mips/inout.h

#if defined(GNUC)
#define eieio() asm volatile( “sync” )
#elif defined(MWERKS)
asm static /inline/ void eieio(void) {
sync
jr na
nop /* branch delay slot */
}
#endif

/* … */

static inline void attribute((unused))
out8(_uintptr __addr, _uint8 __data) {
*(volatile _uint8 *)__addr = __data;
eieio();
}

Does that help?

-David

“David Gibbs” <dagibbs@qnx.com> wrote in message
news:918ucd$175$1@nntp.qnx.com

Mario Charest <mcharest@void_zinformatic.com> wrote:

“David Gibbs” <> dagibbs@qnx.com> > wrote in message
news:918mf0$pm0$> 1@nntp.qnx.com> …


On non-x86, they are
usually a memory assigned/check along with a “synchronise the IO
bus” instruction.

Can you elaborate on the syncrhonise the IO bus instruction thingie?

From /usr/nto/include/ppc/inout.h

#define eieio() asm volatile( “eieio” )


/* … */

static inline void attribute((unused))
out8(_uintptr __addr, _uint8 __data) {
*(volatile _uint8 *)__addr = __data;
eieio();
}


From /usr/nto/include/mips/inout.h

#if defined(GNUC)
#define eieio() asm volatile( “sync” )
#elif defined(MWERKS)
asm static /inline/ void eieio(void) {
sync
jr na
nop /* branch delay slot */
}
#endif

/* … */

static inline void attribute((unused))
out8(_uintptr __addr, _uint8 __data) {
*(volatile _uint8 *)__addr = __data;
eieio();
}

Does that help?

Actually a LOT yes, thanks (you may just have provided
me with a solution to a nasty bug)

-David

Mario Charest <mcharest@void_zinformatic.com> wrote:

“David Gibbs” <> dagibbs@qnx.com> > wrote in message
news:918ucd$175$> 1@nntp.qnx.com> …
Mario Charest <mcharest@void_zinformatic.com> wrote:


From /usr/nto/include/ppc/inout.h

#define eieio() asm volatile( “eieio” )


/* … */

static inline void attribute((unused))
out8(_uintptr __addr, _uint8 __data) {
*(volatile _uint8 *)__addr = __data;
eieio();
}


Does that help?


Actually a LOT yes, thanks (you may just have provided
me with a solution to a nasty bug)

Glad to help. Got to love the instruction though…

Old Macdonald had a bus
eieio
And on that bus he had some output
eieio
With an out-out here
And an out-out there…

:slight_smile:

-David