ts-7000
[Top] [All Lists]

Re: [ts-7000] Reading GPIO ports

To:
Subject: Re: [ts-7000] Reading GPIO ports
From: Matt Godbolt <>
Date: Thu, 13 Jul 2006 22:28:23 +0100
Jim Jackson wrote:
>
>
> Matt,
>
> Show us the code - or at least the code snippet.
> Have you specified the port access pointer you are using as "volatile"?
>
> Jim
>








Hi Jim,

The code really is pretty much the same as the button.c demo - and yes,
it's volatile (I checked the disassembly too and that makes sense). 
I've attached the exact code (please excuse the mess in there, it's very
much a 'hack it around til it works' prototype type thing.

Cheers,

Matt
-==-




------------------------ Yahoo! Groups Sponsor --------------------~--> 
Check out the new improvements in Yahoo! Groups email.
http://us.click.yahoo.com/6pRQfA/fOaOAA/yQLSAA/CFFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/ts-7000/

<*> To unsubscribe from this group, send an email to:
    

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 
// filename button.c
// connect a button to DIO pin 1 and ground
// blinks green and red led on the ts-7200 when button is pressed
//
// compile arm-linux-gcc -o button button.c
//

#include<unistd.h>
#include<sys/types.h>
#include<sys/mman.h>
#include<stdio.h>
#include<fcntl.h>
#include<string.h>

int main(int argc, char **argv)
{
   volatile unsigned int *PEDR, *PEDDR, *PBDR, *PBDDR, *GPIOBDB;
   int i;
   unsigned char state;
   unsigned char *start;
   int fd = open("/dev/mem", O_RDWR);

   start = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 
0x80840000);
   PBDR = (unsigned int *)(start + 0x04);     // port b
   PBDDR = (unsigned int *)(start + 0x14);    // port b direction register
   PEDR = (unsigned int *)(start + 0x20);     // port e data
   PEDDR = (unsigned int *)(start + 0x24);    // port e direction register
   GPIOBDB = (unsigned int *)(start + 0xC4);  // debounce on port b

   *PBDDR = 0xf0;                             // upper nibble output, lower 
nibble input
   *PEDDR = 0xff;                             // all output (just 2 bits)
   *GPIOBDB = 0x0;                            // disable debounce on bit 0

for (;;)
{   
   state = *PBDR;                             // read initial state
   while (state & 0x01) {                     // wait until button goes low
      state = *PBDR;                          // remember bit 0 is pulled up 
with 4.7k ohm
   }
  
        printf("yay\n"); 

   state = *PBDR;                             // read initial state
   while (!(state & 0x01)) {                     // wait until button goes low
      state = *PBDR;                          // remember bit 0 is pulled up wi$
   }

        printf("boo\n");
}

   // blink 5 times, sleep 1 second so it's visible
//   for (i = 0; i < 5; i++) {
//      *PEDR = 0xff;
  //    sleep(1);
    //  *PEDR = 0x00;
//      sleep(1);
//   }
   close(fd);
   return 0;
}
<Prev in Thread] Current Thread [Next in Thread>
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU