To: | |
---|---|
Subject: | Re: [ts-7000] Re: TS-XDIO sample code. |
From: | "Don W. Carr" <> |
Date: | Mon, 17 Apr 2006 16:07:32 -0500 |
Well, I could see the attachment on my end, maybe because I sent it. I
suppose they might strip the the attachments off at yahoo. Anyway, here
is the code pasted directly as text. Don. #include <stdio.h> #include <unistd.h> #include <sys/time.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <sys/mman.h> /******************************************************************/ static unsigned char *xdio_start; static unsigned char *xdio_r0; static unsigned char *xdio_r1; static unsigned char *xdio_r2; static unsigned char *xdio_r3; static unsigned short *ptr16; #define TV_ELAPSED_US(x, y) ((((x).tv_sec - (y).tv_sec) * 1000000) + \ ((x).tv_usec - (y).tv_usec)) /*********************************************************************/ long calc_dif(long count, long last) { if (last > count) { // Ok, we rolled over return count + 65536 - last; } else { return count - last; } } /*********************************************************************/ int main(int argc, char *argv[]) { int fd = open("/dev/mem", O_RDWR|O_SYNC); //xdio at 0x12c00000-0x12c00003 xdio_start = (unsigned char *) mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x12C00000); xdio_r0 = (unsigned char *) (xdio_start + 0); xdio_r1 = (unsigned char *) (xdio_start + 1); xdio_r2 = (unsigned char *) (xdio_start + 2); xdio_r3 = (unsigned char *) (xdio_start + 3); ptr16 = (unsigned short *) xdio_r2; *xdio_r0 = 0x40; // ?? give me the value to write here *xdio_r1 = 0x00; // ?? give me the value to write here /*** *xdio_r0 = 0x82; *xdio_r1 = 0x00; for discrete outputs *xdio_r0 = 0x00; *xdio_r1 = 0xFF; ****/ printf("Wrote, r0 = 0x43, r1 = 0x00\n"); struct timeval now; struct timeval last_time; gettimeofday(&last_time, NULL); unsigned short last_count = *ptr16; while (1) { sleep(1); gettimeofday(&now, NULL); unsigned short count16 = *ptr16; int elapsed_time = TV_ELAPSED_US(now, last_time); long n_pulses = calc_dif((long) count16, (long) last_count); double frequency = ((double) n_pulses) / (((double) elapsed_time) / 1000000); unsigned char byte0 = *xdio_r2; unsigned char byte1 = *xdio_r3; printf("--- %02hhx %02hhx %02hhx %02hhx - %hx %hu %d %d %0.0lf\n", xdio_r0, *xdio_r1, byte0, byte1, count16, count16, n_pulses, elapsed_time, frequency); last_count = count16; last_time = now; } } /******************************************************************/ On 4/17/06, rx7vt <> wrote:
-- Dr. Don W. Carr J. G. Montenegro 2258 Guadalajara, Mexico +52-333-630-0704 +52-333-836-4500 ext 2930 YAHOO! GROUPS LINKS
|
<Prev in Thread] | Current Thread | [Next in Thread> |
---|---|---|
|
Previous by Date: | [ts-7000] Re: 983.04 Khz timer, Yan Seiner |
---|---|
Next by Date: | Re: [ts-7000] another newbie question - interfacing to TTL, Don W. Carr |
Previous by Thread: | [ts-7000] Re: TS-XDIO sample code., rx7vt |
Next by Thread: | [ts-7000] Re: TS-XDIO sample code., xioaya12 |
Indexes: | [Date] [Thread] [Top] [All Lists] |
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