[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Access to csp0

On Mon, Aug 06, 2001 at 08:54:31AM +0200, Mikael Starvik wrote:
> The summary is that you have to do a mmap but MTD may be able to do
> this for you. Maybe Adam Felson can tell us how it was finally solved?

Yeah, I did mmap, I guess it's the best solution, here is the sample
code just for archiving purposes:

PS: This is specific to my application but it will give an idea how to do
your thang :^)

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#define NO_CACHE        0x80000000
#define CSP0            0x10000000
#define BASE            CSP0
#define KEYB            0x8
int main(){
        unsigned long int reg;
        int memfd;
        void *mem;
        unsigned char data, *p;
        reg = (NO_CACHE|BASE);
        memfd = open("mem", O_RDWR);
        if(memfd < 0){
                perror("Can open memory device");
                return 1;
        mem = mmap(0, 100, PROT_READ|PROT_WRITE, MAP_SHARED, memfd, reg);
        if(mem < 0){
                return 1;
        p = (unsigned char*)mem;
        p += KEYB;
        data = *p;
        data = (unsigned char)~data;
        printf("Reading Base(%0lx)(%#2.2x)\n", reg+KEYB, data);
        /* memory gets unmaped when we exit, fh get closed too but anyway */
return 0;

Peace can only come as a natural consequence
of universal enlightenment. -Dr. Nikola Tesla