I have to address gpio’s on an embedded device (with MX27 processor) from my Qt application. I think I can do it via memory mapping, i.e. using /dev/mem. I found some examples in C code using mmap. However, I don’t know how to do it in Qt. Is it possible to use QFile for opening the device (and then use map() function to do the mapping) ? Or do I have to subclass QIODevice and implement things myself ? Are there better alternatives to address gpio ? Maybe an example ?
There is an abstraction for mmap in QFile:
This is the way I do it :
However, when running the application I get the following message on the console output :
QFSFileEngine::map: Mapping a file beyond its size is not portable
And I get the “Mapping failed” message indicating the map function returned a 0.
Did I make a mistake in using QFile and map ?
As a first experiment, I build my application for my host (Ubuntu 10.04). Can it be a problem when I use /dev/mem of the host pc to test mapping functionality ?
I also tested the mapping in its ‘basic’ way :
- int fd;
- void* map_base;
- if ((fd = open ("/dev/mem", O_RDWR | O_SYNC)) == -1)
- std::cerr << "Failed to open /dev/mem : " << strerror(errno) << std::endl;
- exit (1);
- std::cerr << "Open successful" << std::endl;
- map_base = mmap (0, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0x10015000UL);
- if (map_base == MAP_FAILED)
- std::cerr << "Mapping failed : " << strerror(errno) << std::endl;
- exit (2);
- std::cerr << "mapped on :" << map_base << std::endl;
But this also fails. The opening of the device is successful, but the mapping fails with :
Mapping failed : Operation not permitted
Any ideas ?