Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
21 years ago

Low Level IO

Hi

I'm using Microtronix uClinux ver 2.6 for NiosII

I am trying to utilize the low level IO functions inb, outb etc in one of my apps. to read / write my hardware devices but I cannot build my project without getting "implicit declaration of inb..." etc. warnings

How do I access these IO functions from within user space in uClinux? Is there a user level io.h somewhere or can I set a compiler flag to access the kernel level functions???

Nick

1 Reply

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi nipri,

    inb(), outb(), etc. are defined in asm/io.h ... but they're normally wrapped with

    an# ifdef __KERNEL__ ... this means they're intended for use by the kernel itself

    (or loadable modules) ... pulling them into user-space apps is not recommended.

    A device driver is where this type of hardware access is typically implemented.

    That said, you can just define your own macros ... hoist them from the kernel

    sources (or u-boot) into your app's source tree as they're normally just a set of

    macros (see below) ... without an MMU, uClinux won't care.

    Regards,

    --Scott

    #define readb(addr)
        ({unsigned char val;
      asm volatile( "ldbio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;})
    # define readw(addr)
        ({unsigned short val;
      asm volatile( "ldhio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;})
    # define readl(addr)
        ({unsigned long val;
      asm volatile( "ldwio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;})
    # define writeb(addr,val)
        asm volatile ("stbio %0, 0(%1)" : : "r" (addr), "r" (val))
    # define writew(addr,val)
        asm volatile ("sthio %0, 0(%1)" : : "r" (addr), "r" (val))
    # define writel(addr,val)
        asm volatile ("stwio %0, 0(%1)" : : "r" (addr), "r" (val))
    # define inb(addr)    readb(addr)# define inw(addr)    readw(addr)# define inl(addr)    readl(addr)# define outb(addr,val)    writeb(addr,val)# define outw(addr,val)    writew(addr,val)# define outl(addr,val)    writel(addr,val)