ts-7000
[Top] [All Lists]

[ts-7000] TS-7400 GPIO problem

To:
Subject: [ts-7000] TS-7400 GPIO problem
From: "jan_fristedt" <>
Date: Mon, 29 Jan 2007 17:55:55 -0000
Hi again,
For some reason I can't get the TS-7400 GPIO to work.
When I write a pattern to the outputs and read it back it seem like
even and odd bits are connected together. I have verified it with my
oscilloscope. When I write 00 to a pair of bits I read back 00 and the
pin level is close to zero. When I write 01 or 10 I read back 11 and
the pin level is ~1,8V, close to 50%. When I write 11 I read back 11
and the pin level is close to 3,3V.
I have tried both with pointers and peek/poke.
/Janne

// filename gpout.c
// output value on TS-7400 GPIO
//
// compile arm-linux-gcc -mcpu=arm9 -o gpout gpout.c
//

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

//#define PEEKPOKE
#define VERBOSE
#define BUFSZ 100

#define TS7400CPLD 0x23400000
#define TS7400MODEL 0x22000000
#define TS7400GPIO 0x12c00000
#define EP9300GPIO 0x80840000
#define EP9300SSP 0x808a0000
#define REDLED 0x02
#define GREENLED 0x01

void init(void);
void redLed(int on);
void greenLed(int on);

volatile unsigned int *PADR, *PADDR, *PBDR, *PBDDR, *PEDR, *PEDDR,
*GPIOADB, *GPIOBDB;
unsigned char *TS74LDDR, *TS74HDDR, *TS74LDR, *TS74HDR;


int main(int argc, char **argv)
{
    int i;
    char buf[BUFSZ];
    unsigned char l, h;
    unsigned long ts74ldr, ts74hdr;

    init();

    greenLed(0);

    ts74ldr = (unsigned long) TS74LDR;
    ts74hdr = (unsigned long) TS74HDR;

    printf("\nts74ldr:0x%8.8x ts74hdr:0x%8.8x\n", ts74ldr, ts74hdr);

    for (;;) {
        redLed(0);
        fputs("Value: ", stdout);
        fgets(buf, BUFSZ, stdin);
        redLed(1);
        i = (int) strtol(buf, NULL, 0);
        l = (0xff & i);
        h = (0xff & (i >> 8));

        printf("\nH:%2.2x L:%2.2x 0x%x %d\n", h, l, i, i);

#ifdef PEEKPOKE
        POKE8(ts74ldr, l);
        POKE8(ts74hdr, h);
        l = PEEK8(ts74ldr);
        h = PEEK8(ts74hdr);
#else
        *TS74LDR = l;
        *TS74HDR = h;

        l = *TS74LDR;
        h = *TS74HDR;
#endif

        printf("\nH:%2.2x L:%2.2x 0x%x %d\n", h, l, i, i);
    }

   return 0;
} /* main */


void init(void)
{
    unsigned char *start;
    int fd;

    fd = open("/dev/mem", O_RDWR|O_SYNC);
    printf("fd:%x start:%p\n", fd, start);

    /* print TS-7400 CPLD revision register */
    start = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED,
fd, TS7400CPLD);
    printf("TS-7400 CPLD revision:0x%8.8x\n", *start);

    /* print TS-7400 model register */
    start = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED,
fd, TS7400MODEL);
    printf("TS-7400 model:0x%8.8x\n", *start);

    /* pointers to EP930x GPIO */
    start = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED,
fd, EP9300GPIO);
    PADR = (unsigned int *)(start + 0x00);     // port a
    PADDR = (unsigned int *)(start + 0x10);    // port a direction
register
    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
    GPIOADB = (unsigned int *)(start + 0xa8);  // debounce on port 1
    GPIOBDB = (unsigned int *)(start + 0xc4);  // debounce on port b

#ifdef VERBOSE
    printf("PADR:%p PADDR:%p\n", PADR, PADDR);
    printf("PBDR:%p PBDDR:%p\n", PBDR, PBDDR);
    printf("PEDR:%p PEDDR:%p\n", PEDR, PEDDR);
    printf("GPIOADB:%p\n", GPIOADB);
    printf("GPIOBDB:%p\n", GPIOBDB);
#endif

    /* pointers to TS-7400 GPIO */
    start = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED,
fd, TS7400GPIO);
    TS74LDDR = (unsigned char *)(start + 0x00); // port a direction
register
    TS74HDDR = (unsigned char *)(start + 0x01); // port b direction
register
    TS74LDR = (unsigned char *)(start + 0x02);  // port a
    TS74HDR = (unsigned char *)(start + 0x03);  // port b

#ifdef VERBOSE
    printf("*TS74LDR:%p *TS74LDDR:%p\n", *TS74LDR, *TS74LDDR);
    printf("*TS74HDR:%p *TS74HDDR:%p\n", *TS74HDR, *TS74HDDR);
#endif

    *PADDR = 0xf0;                             // upper nibble output, lower 
nibble input
    *PBDDR = 0xf0;                             // upper nibble output, lower 
nibble input
    *PEDDR = 0xff;                             // all output (just 2 bits)
    *GPIOADB = 0x01;                           // enable debounce on bit 0
    *GPIOBDB = 0x01;                           // enable debounce on bit 0
//    POKE8(TS74LDDR, 0xff);                   // all outputs
    *TS74LDDR = 0xff;                          // all outputs
//    POKE8(TS74HDDR, 0xff);                   // all outputs
    *TS74HDDR = 0xff;                          // all outputs

#ifdef VERBOSE
    printf("*PADDR:0x%8.8x *PBDDR:0x%8.8x *PEDDR:0x%8.8x\n", *PADDR,
*PBDDR, *PEDDR);
    printf("*GPIOADB:0x%8.8x *GPIOBDB:0x%8.8x\n", *GPIOADB, *GPIOBDB);
    printf("*TS74LDDR:0x%8.8x *TS74HDDR:0x%8.8x\n", *TS74LDDR, *TS74HDDR);
    printf("*TS74LDR:0x%8.8x *TS74HDR:0x%8.8x\n", *TS74LDR, *TS74HDR);
#endif

    close(fd);

} /* init */


void redLed(int on)
{
    if (on) {
        *PEDR |= REDLED;
    } else {
        *PEDR &= ~REDLED;
    }
} /* redLed */


void greenLed(int on)
{
    if (on) {
        *PEDR |= GREENLED;
    } else {
        *PEDR &= ~GREENLED;
    }
} /* greenLed */





 
Yahoo! Groups Links

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

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/ts-7000/join
    (Yahoo! ID required)

<*> To change settings via email:
     
    

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

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

<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