ts-7000
[Top] [All Lists]

[ts-7000] TS7200 Accessing LEDs - Why must I use mmap()?

To:
Subject: [ts-7000] TS7200 Accessing LEDs - Why must I use mmap()?
From: "frank_kienast" <>
Date: Wed, 05 Jan 2011 16:19:42 -0000
Maybe I'm doing something stupid here, but it seems like I have to use mmap() 
to access the LEDs on the TS7200.  The following works:

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

#define LED_ADDR 0x80840020

extern int errno;


int main()
{
        int i;
        unsigned char *leds;
        unsigned char val;

        int fd = open("/dev/mem",O_RDWR|O_SYNC);
        if(fd < 0)
        {
                printf("Can't open /dev/mem\n");
                return 1;
        }
        leds = (unsigned char *) mmap(0, getpagesize(), PROT_READ|PROT_WRITE, 
MAP_SHARED, fd, 0x80840000);
        if(leds == NULL)
        {
                printf("Can't mmap\n");
                return 1;
        }
        else
                printf("leds=%x\n",leds);

        for(i = 0; i < 256; i++)
        {
                val = i % 4;
                leds[0x20] = val;

                sleep(1);
        }

        return 0;
}


But the following gets an error on the write
System error:  22 = Invalid argument

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

#define LED_ADDR 0x80840020

extern int errno;

int main()
{
        int i;
        off_t cs;
        unsigned char val;

        int fd = open("/dev/mem",O_RDWR|O_SYNC);
        if(fd < 0)
        {
                printf("Can't open /dev/mem\n");
                return 1;
        }

        for(i = 0; i < 256; i++)
        {

                cs=lseek(fd,LED_ADDR,SEEK_SET);
                if(cs != LED_ADDR)
                {
                        printf("Can't lseek\n");
                        return 1;
                }
                val = i % 4;
                cs=write(fd,&val,1);
                if(cs != 1)
                {
                        printf("Write failed: %d\n",errno);
                        return 1;
                }

                sleep(1);
        }

        return 0;
}


Shouldn't either method work?

Thanks,
Frank





------------------------------------

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