Writing diretly to memory (memory mapped IO)

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)

Reply to
Sagaert Johan
Loading thread data ...

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
 Click to see the full signature
Reply to
Grant Edwards

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

Reply to
Mouarf

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

Reply to
Geronimo W. Christ Esq

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
 Click to see the full signature
Reply to
Grant Edwards

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

Reply to
Mouarf

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?
 Click to see the full signature
Reply to
Grant Edwards

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

Reply to
Mouarf

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
 Click to see the full signature
Reply to
Grant Edwards

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.