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.8xn",
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 %dn", 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 %dn", h, l, i,
i);
}
return 0;
} /* main */
void init(void)
{
unsigned char *start;
int fd;
fd = open("/dev/mem", O_RDWR _SYNC);
printf("fd:%x start:%pn", 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.8xn",
*start);
/* print TS-7400 model register */
start = mmap(0, getpagesize(), PROT_READ|PROT_WRITE,
MAP_SHARED,
fd, TS7400MODEL);
printf("TS-7400 model:0x%8.8xn", *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:%pn", PADR, PADDR);
printf("PBDR:%p PBDDR:%pn", PBDR, PBDDR);
printf("PEDR:%p PEDDR:%pn", PEDR, PEDDR);
printf("GPIOADB:%pn", GPIOADB);
printf("GPIOBDB:%pn", 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:%pn", *TS74LDR,
*TS74LDDR);
printf("*TS74HDR:%p *TS74HDDR:%pn", *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.8xn", *PADDR,
*PBDDR, *PEDDR);
printf("*GPIOADB:0x%8.8x *GPIOBDB:0x%8.8xn",
*GPIOADB, *GPIOBDB);
printf("*TS74LDDR:0x%8.8x
*TS74HDDR:0x%8.8xn", *TS74LDDR, *TS74HDDR);
printf("*TS74LDR:0x%8.8x *TS74HDR:0x%8.8xn",
*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://gro
ups.yahoo.com/group/ts-7000/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:ts-7000-digest@yahoogroups.com
mailto:ts-7000-fullfeatured@yahoogroups.com
<*> To unsubscribe from this group, send an email to:
ts-7000-unsubscribe@yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.c
om/info/terms/
|