Find the answer to your Linux question:
Results 1 to 6 of 6
I have been looking for a script example of reading and writing to the parallel port's data, status, and control registers using bash. I see it done in pascal, tcl, ...
  1. #1
    Linux User
    Join Date
    Mar 2008
    Posts
    287

    bash to read write registers

    I have been looking for a script example of reading and writing to the parallel port's data, status, and control registers using bash. I see it done in pascal, tcl, etc. but nothing in bash. Is this just impossible to do?

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    There are some command-line programs on some embedded systems I work with that allow you to read/write I/O addresses; however, these are not standard command-line (bash) tools. You can write your own easily enough, using mmap() to map the I/O (register) address to virtual memory in the application.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Linux Newbie theNbomr's Avatar
    Join Date
    May 2007
    Location
    BC Canada
    Posts
    150
    Rubberman, are you sure you can map x86 IO space (question seems to imply x86) to virtual memory? I've not heard of that, only memory space.
    Other possibilities would be to create userspace utilities to access IO space through either the /dev/port facility, or the ioperm()/iopl()/inb()/outb() interfaces. In any case, the application will need to run with root privileges.
    If you have the wherewithall to create such utilities, it probably makes sense to create the entire application. Anything you can do with the data in bash is probably easier in C.

    --- rod.
    Stuff happens. Then stays happened.

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Some embedded systems have mapped I/O ports to system memory space (a lot of Debian-based ARM systems do this), but you are correct that normally you use the port address, or /dev/port to access the port, although you need to enable access first using ioperm() or iopl().
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  5. #5
    Linux Newbie theNbomr's Avatar
    Join Date
    May 2007
    Location
    BC Canada
    Posts
    150
    As far as I know, ARM CPUs do not distinguish between IO and memory address space; IO is all memory mapped. Distinct IO & memory address space is unique to, or at least most commonly associated with x86 and some ancestor CPUs like 8080 family and the Z80 derivative family. I'm pretty sure there is no mmap()-like equivalent for IO address space in Linux.
    --- rod.
    Stuff happens. Then stays happened.

  6. #6
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Quote Originally Posted by theNbomr View Post
    As far as I know, ARM CPUs do not distinguish between IO and memory address space; IO is all memory mapped. Distinct IO & memory address space is unique to, or at least most commonly associated with x86 and some ancestor CPUs like 8080 family and the Z80 derivative family. I'm pretty sure there is no mmap()-like equivalent for IO address space in Linux.
    --- rod.
    You may well be correct in this. I've just recently starting working with ARM systems and the I/O ports are memory mapped. I just made the assumption that it was done with some kernel driver fudging, but am likely incorrect in that. I know that you use inb() and outb() on most (or all) x86 system to read/write I/O ports/registers. Personally, I like the memory mapping used on ARM systems better. It's dead-bang simple to set up and use. Very effective. In any case, on the ARM embedded systems I am working on we do use mmap() to create VM addresses to access the I/O registers of various devices such as DIO, relays, A/D converters, etc. It makes for a very consistent and simple programming model. It only took me a couple of days to write reliable code to control and respond to an Allen-Bradley PLC that was controlling a conveyor line and distribution gates.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...