I/O Access

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

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.


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

Paul N. Leonard <paull@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 <cdm@qnx.com> “The faster I go, the behinder I get.”
Software Engineer, QSSL – Lewis Carroll –
http://qnx.wox.org/

tie <tie@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


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

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 ?

Dmitri Ivanov <ivdal@yahoo.com> wrote:

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 ?

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

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