IO with custom made isa board

jrwilson
jrwilson used Ask the Experts™
on
I designed, etched and built an isa board to buffer the isa bus.  I then wrote a module to register the board, a program to access the board with inb and outb, and used mknod to create a /dev entry.  I am using a logic probe to determine whether a bit has been flipped on a latch.  The isa board is connected to an experimenter (bread) board with a ribbon cable.  The address bus and some signals are buffered with 74ls244 ic's and the data bus is buffered with a 74ls245 ic on the isa  board.  The logic and latch on the experimenter (bread) board are
also 74ls ic's.  The linux kerner version is 2.4.5, glibc is 2.2.1, and I doubt germane, gcc is 2.95.2.  The program and makefile for the module is:
#define MODULE

#include <linux/module.h>
#include <linux/fs.h>
#include <linux/ioport.h>

struct file_operations *my_port_fops = {
};

unsigned long start, range;

int init_module (void)
{
  int status;
  start = 0x0200;
  range   = 0x05;

  register_chrdev(147, "my_port", &my_port_fops);

  status =  check_region (start, range);
        if (status == 0) {
                printk ("The ports are available in that range.\n");  
                request_region(start, range, "my_port");
             } else {
                printk ("The ports are already in use. Try other range.\n");
                return (status);
        }
        return 0;
}

void cleanup_module (void)
{
        release_region(start, range);
        printk (" your device is released\n");
        unregister_chrdev(147, "my_port");
        printk (" your device is unregistered\n");
}
       
# Makefile for prt1.c

CFLAGS = -0 -Wall               # with optimiaztion for inlines and all warnings

prt1.o: prt1.c
        cc -c prt1.c

clean:
        /bin/rm *.o

And the program and makefile to access the port:
//      A first try at the ioport.  Hex 0200 seems empty

#include <stdio.h>
#include <sys/io.h>

#define BASEPORT 0x200
int main()  {
        int i;

        printf("Here\n");
        if (ioperm(BASEPORT, 3, 1))     //ioperm returns 0 on success
                printf("Bad\n");
        else
                printf("Good\n");

        outb(0xff, BASEPORT);
       
        if (ioperm(BASEPORT, 3, 0)) {perror("ioperm"); exit(1);}
       
        printf("Done\n");
        exit(0);
}
# Makefile for try.c

CFLAGS = -O -Wall               # with optimiaztion for inlines and all warnings

try:    try.o
        cc  -o try try.o

try.o: try.c
        cc -c try.c

clean:
        /bin/rm *.o

I think this all the information needed, but I would be glad to answer any questions one might have.  And so, without further preamble, the question.  What do I yet need to do to flip a bit on the experimenter board from user space?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
fridomCEO/Programmer

Commented:
I probably misunderstood you. Does you post mean you have developed and ISA Borad on you own? Than I want to ask what driver can be used for your board?

As I understand you, you probably want to write a device driver for that board. If that is what you do check out the O'Reilly books about Linux Device Driver development.

Regards
Friedrich
Commented:
I agree with fridom that your question is not clear.
Do you want to access your H/W from user mode and
your code doesn't work ?
If you need to access IO from user application you can use:

#include <unistd.h>
#include <asm/io.h>
int main()
{
  iopl(3); /* to allow IO functions to be used */
  outb( byteData, port ); /* write byte to port */
  outw( wordData, port ); /* write 16-bit to port */
  byteData = inb( port ); /* read byte from port */
  wordData = inw( port ); /* read 16-bit fromo port */
}

Author

Commented:
I agree that the first paragraph is a cryptic description of what I had done.  I fabricated a board to insert into an isa slot.  The board can have any address in the io ports address space.  I chose 0x0200 because there was nothing there.  Maybe I should mention that all this board does is pass the bus signals to an experimenter (bread) board and from there I can do whatever with the signals and assorted parts (ic's).  The first program and makefile create an entry in /proc/ioports and /proc/devices.  It is barebones, on purpose, because I will be (?) accessing the hardware from user space, which is what the second program does using ioperm.
By the way glibc2 requires <sys/io.h> not <asm/io.h>.  Both programs compile and run cleanly.

The mini-howto on ioports doesn't mention ports other than lp. game and serial.  It doesn't mention whether these devices need to insmod'd for them to work.  There are user space drivers out there which use resources the kernel knows about.  X and gpm come to mind.  I suspect  
the module needs more work.  Perhaps open and release functions to plug into the file_operations structure.
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Commented:
It's still a little confusing what you built, because you say all it does is pass the bus signals to an experimenter board, but also say that the board has an address, which means it's also interpreting those signals and presumably responding to them when it concludes that it is being addressed.

Still I get the idea you just want to put an input or output cycle on the ISA bus, via a user space program, and inb() and outb() are fine for that.  There's no need for any kernel module.

inb() and outb() are kind of outdated; /dev/port might suit your needs better -- see the source code for hwclock for an example of that (ftp://ibiblio.org/pub/Linux/system/hardware).

Author

Commented:
The isa board that I built just passes the isa bus signals to a proto-typing board after buffering the signals.  Buffering is an electronic term which basicly means to electrically isolate.  In this case the computer from the experimenter board.  A picture can be had of the experimenter board by doing a google search for "global specialties exp-300".  Exp-300 is the model number of the experimenter board that I am using from Global Specialties.  On the experimenter board, I have interconnected a few IC's (integrated circuits) to decode an address, anything in the 64k io range, but I chose 0x200 for simplicity of hardware design (less wires).

You can use an experimenter board to build whatever you'd like.  An eprom burner, a temperature sensor, voltmeter, digital oscope. function generator and the list is only limited by your imagination, pocket book and knowledge.  It may be obvious that a knowledge of electronics might be of use or that one could use it to acquire a knowledge of electronics.

The hints that I've seen about programming io-ports only mentions the standard ports (devices)  which are existant in any computer (maybe not crays).  While this is an unstandard port (device) in one computer.  So I wonder whether I have to tell the kernel about this previously non-existant port (device).

Commented:
inb() and outb() and /dev/port have no knowledge of what ports are conventional and what ports are not.  They just see 65536 identical ports.  So there's nothing to tell the kernel about.

By the way, this whole discussion assumes an IA32 CPU (80386, etc.).  If you have an ISA bus driven by some other kind of CPU, there's no telling how you put IN and OUT cycles on that bus.

It should not be very hard to test this stuff out.  Type the following and see if it selects your device for an IN cycle and prints whatever byte the device transfers:

  dd bs=1 if=/dev/port skip=512 count=1

Note that 512 is your device address.

Author

Commented:
You've, by inference, indicated that the program above, try.c should work.  It is an IA32 CPU 80686.  There are two isa slots.  This has been tried on a CPU 80386 having no pci slots.

 dd bs=1 if=/dev/port skip=0x0200 count=1
01+0 records in
1+0 records out
A logic probe will indicate whether an electical point is high or low or will pulse if it's on a point which changes often; like an address line or clock.  It will also remember whether a change in state has occured, that is low to high or high to low.  A separate circuit, on another board, identical to the one connected to the computer shows that it is correctly wired.

Before inserting the isa board into it's slot I checked whether a signal from  each finger would pass through the buffering ic's to the ribbon cable connector.

Author

Commented:
You've, by inference, indicated that the program above, try.c should work.  It is an IA32 CPU 80686.  There are two isa slots.  This has been tried on a CPU 80386 having no pci slots.

 dd bs=1 if=/dev/port skip=0x0200 count=1
01+0 records in
1+0 records out
A logic probe will indicate whether an electical point is high or low or will pulse if it's on a point which changes often; like an address line or clock.  It will also remember whether a change in state has occured, that is low to high or high to low.  A separate circuit, on another board, identical to the one connected to the computer shows that it is correctly wired.

Before inserting the isa board into it's slot I checked whether a signal from  each finger would pass through the buffering ic's to the ribbon cable connector.

Author

Commented:
You've, by inference, indicated that the program above, try.c should work.  It is an IA32 CPU 80686.  There are two isa slots.  This has been tried on a CPU 80386 having no pci slots.

 dd bs=1 if=/dev/port skip=0x0200 count=1
01+0 records in
1+0 records out
A logic probe will indicate whether an electical point is high or low or will pulse if it's on a point which changes often; like an address line or clock.  It will also remember whether a change in state has occured, that is low to high or high to low.  A separate circuit, on another board, identical to the one connected to the computer shows that it is correctly wired.

Before inserting the isa board into it's slot I checked whether a signal from  each finger would pass through the buffering ic's to the ribbon cable connector.

Commented:
I agree with all that.  Do you mean to say that try.c and/or dd don't work?

Author

Commented:
You've, by inference, indicated that the program above, try.c should work.  It is an IA32 CPU 80686.  There are two isa slots.  This has been tried on a CPU 80386 having no pci slots.

 dd bs=1 if=/dev/port skip=0x0200 count=1
01+0 records in
1+0 records out
A logic probe will indicate whether an electical point is high or low or will pulse if it's on a point which changes often; like an address line or clock.  It will also remember whether a change in state has occured, that is low to high or high to low.  A separate circuit, on another board, identical to the one connected to the computer shows that it is correctly wired.

Before inserting the isa board into it's slot I checked whether a signal from  each finger would pass through the buffering ic's to the ribbon cable connector.

Author

Commented:
Yes.  Both try.c and dd show no output in the decoding circuit.  I'm baffled.  By the way, please excuse my double post.  I wasn't aware that I could post with cookies turned off.

Author

Commented:
Yes.  Both try.c and dd show no output in the decoding circuit.  I'm baffled.  By the way, please excuse my double post.  I wasn't aware that I could post with cookies turned off.

Commented:
I agree with all that.  Do you mean to say that try.c and/or dd don't work?

Commented:
Can you decode port addresses that you know are working?  Like the keyboard?  Do you see activity on the address lines and strobes going into the decoder?  Can you plug an ordinary card (e.g. serial card, ethernet, card, ...) into the other ISA slot and address it?

Author

Commented:
Yes.  Both try.c and dd show no output in the decoding circuit.  I'm baffled.  By the way, please excuse my double post.  I wasn't aware that I could post with cookies turned off.

Author

Commented:
I have become convinced that the problem is the isa board so I'm going to redesign and rebuild it.  I used a printf  "printf("Input byte from address  %x   %d\n", BASEPORT, inb(BASEPORT));" and got a variety of values from a variety of ports.  Bryanh's suggestion to decode other addresses, a lack of comment concerning the code, the discussion at sci.eletronics.basics, and the problems I had with the assembly of the board have led me to this conclusion.  I think bryanh was about to make the same conclusion.

The original design required soldering on the component side of the board eliminating the use of a heat sink and the ic's got a trifle warm.  No plated through holes.  I'll use vias to transfer the data and address lines to the solder side of the board.  I'll also eliminate all but the lower 10 address lines which will leave room to interleave ground leads between the control signals on the ribbon cable, removing crosstalk.

I will award the points after I have the new board up and running.  Wish me luck.

Thanks All

Author

Commented:
I have become convinced that the problem is the isa board so I'm going to redesign and rebuild it.  I used a printf  "printf("Input byte from address  %x   %d\n", BASEPORT, inb(BASEPORT));" and got a variety of values from a variety of ports.  Bryanh's suggestion to decode other addresses, a lack of comment concerning the code, the discussion at sci.eletronics.basics, and the problems I had with the assembly of the board have led me to this conclusion.  I think bryanh was about to make the same conclusion.

The original design required soldering on the component side of the board eliminating the use of a heat sink and the ic's got a trifle warm.  No plated through holes.  I'll use vias to transfer the data and address lines to the solder side of the board.  I'll also eliminate all but the lower 10 address lines which will leave room to interleave ground leads between the control signals on the ribbon cable, removing crosstalk.

I will award the points after I have the new board up and running.  Wish me luck.

Thanks All
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: dimitry {http:#7462631} & bryanh {http:#7467130}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial