comp.lang.ada
 help / color / mirror / Atom feed
* R/W hardware registers ?
@ 2017-06-29 22:38 patrick
  2017-06-30  7:48 ` Jacob Sparre Andersen
  0 siblings, 1 reply; 5+ messages in thread
From: patrick @ 2017-06-29 22:38 UTC (permalink / raw)


Hi Everyone

This post is partly a a continuation of this one:

https://groups.google.com/forum/#!searchin/comp.lang.ada/ada$20hardware|sort:relevance/comp.lang.ada/ZhB27DtPb9I/y7dxjrhZCAAJ

There are some really great applications written in C but I try to avoid C whenever I can. I haven't been able to avoid it over the past few months.

There are lots of ways to interact with hardware from a desktop PC but a lot of them involve C. Microprocesor, SBCs(like RPI) and microcontroller based solutions are probably easier than ever before. There is great work being done with AVR-Ada but really all I want to do is use a desktop computer with some circuits.

I have been fooling around with parallel ports on and off the past few months. I am thinking about getting an ISA breadboard card and fooling around a little more. I have other plans but right now it's just some hobby silliness.

I have been reading about writing Linux device drivers but I just don't need interupts and so on and I am losing interest in reading about this further.

Assuming these:
1)It's just hobby fun
2)I am the only user
3)it's on Posix, normally linux
4)I am interacting with CPU-less, passive circuitry

Then do you see any major problems with just reading and writing to a device's registers though root access and without a kernel API?

Please see this program, it's cut down to keep it simple:


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

  /* Address of the first parallel port. found in BIOS settings. */
  #define kDATA_REG (0xec00)          /* Base address = data register. */
  #define kSTAT_REG (kDATA_REG + 1)    /* Status register. */
  #define kCONT_REG (kDATA_REG + 2)    /* Control register. */

  int main()
  {
      int i;

      if (ioperm(kDATA_REG, 1, 1))    /* Get permission to access this port. */
          {
          printf("ioperm(%x) failed.\nYou must be root to execute!\n", kDATA_REG);
          return 1;
          }

      if (ioperm(kCONT_REG, 1, 1))    /* Get permission to access this port. */
          {
          printf("ioperm(%x) failed.\nYou must be root to execute!\n", kDATA_REG);
          return 1;
          }



      /* Assume port is already in output mode (bit 5 in control register). */
      for (i = 0; i <= 9; i++)        /* Let the LED(s) blink. */
          {
          outb(i, kDATA_REG);       /* All 8 datalines high. */
          printf("value sent is %d \n", i) ;
          sleep(5);

          }
      return 0;
  }





The above program does this.

If it's just me, do I really need a call to ioperm ?

Could I not access registers through access/pointers ?

I bet I could have lots of fun with parallel ports, ISA cards and then after that maybe I could write to the registers of a PIC-E cards and have parallel to serial conversion done by the OS and I could dump ISA later and control circuits in a serial manner(I am not sure about this last part at all)

Does anyone see a pitfall I am about to fall into ?

Thanks for reading-Patrick





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-06-30 15:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-29 22:38 R/W hardware registers ? patrick
2017-06-30  7:48 ` Jacob Sparre Andersen
2017-06-30 13:11   ` patrick
2017-06-30 14:40     ` patrick
2017-06-30 15:17     ` Dennis Lee Bieber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox