Writing diretly to memory (memory mapped IO)

Sep 06, 2005 8 Replies

Hi



Can i directly write to memory ?



eg :



unsigned char * mappedport= 0x04000000L;


*=mappedport=my_data_to_write


My first attemps failed , do i need some kind of privilege before i can do that ?



Johan



(i am using uclinux on coldfire platform dilnetpc dnp/5280)


Yes.

That's not quite C, but you're headed the right direction. You'd better delcaer mappedport a pointer to a volatile data type.

You've got to make sure your task's memory map is set up so that the virtual address to which you're writing is mapped to the physical addres to which you want to write.

The "right" way to do it is probably to write a device driver that impliments the mmap() call allowing the device's I/O registers to be mapped into userspace.

Grant Edwards grante Yow! Now my EMOTIONAL at RESOURCES are heavily visi.com committed to 23

could you please tell us a link where to find an example of such thing?

Just call mmap() on /dev/mem, which is standard on Linux - you do not need to write a device driver.

True, if you know where your hardware is in memory, and you don't have to do anything like scan the PCI bus, or tweak the MMU to allow access to the region in question.

Grant Edwards grante Yow! Here I am at the flea at market but nobody is buying visi.com my urine sample bottles...

interesting to know that. I'm just thinking of developping a PCI driver that use the memory mapp so that I can declare some variables in my software that are located in the PCI controller of the PCI board (so that the location is transparent for the software), do you know an open source driver that do such thing or an example of to use this driver ?

Best regards

Here's a demo driver I wrote about 6 years ago. I don't know how compatible it is with newer kernels.

ftp://ftp.visi.com/users/grante/stuff/demomm.tar.gz

Grant Edwards grante Yow! Yow! Are we in the at perfect mood? visi.com

perfect, I will have a look at it to get an example. Thanks a lot!

I think the kernel's PIC API has been re-written at least once snice I wrote that, so you might want to look at a more recent driver for PCI examples.

Grant Edwards grante Yow! The PILLSBURY at DOUGHBOY is CRYING for visi.com an END to BURT REYNOLDS movies!!

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required