Title |
Accessing video memory |
Ref. No. |
QNX.000009530 |
Category(ies) |
Video, Development |
Issue |
Is there a way we can get access to video memory in our Photon application?
|
Solution |
You can not access the video memory while you are in any graphical user interface. But, you can do it if you are only running QNX.
Here is a code sample to do this:
/* includes */ #include <stdio.h> #include <sys/pci.h> #include <string.h> #include <stddef.h> #include <sys/seginfo.h> #include <fcntl.h> #include <sys/mman.h> #include <errno.h> #include <stdlib.h> #include <sys/kernel.h>
char *mapPCI(int memsize) { unsigned busnum, devfuncnum; long address; int pci_index = 0; int fd;
if ( _CA_PCI_Find_Device ( YOUR_PCI_DEVICE_ID, YOUR_PCI_VENDOR_ID, pci_index, &busnum, &devfuncnum ) != PCI_SUCCESS) { fprintf ( stderr, "Can not find devicen"); exit (1); }
// determine device i/o and memory base addresses if ( _CA_PCI_Read_Config_DWord (busnum, devfuncnum, offsetof (struct _pci_config_regs, Base_Address_Regs[0]), 1,(char *) &address ) != PCI_SUCCESS) { fprintf ( stderr, "Error reading addressn"); exit (1); }
// open physical memory fd = shm_open ( "Physical", O_RDWR, 0777); if ( fd == -1) { fprintf ( stderr, "open failed:%sn",strerror (errno)); exit (1); }
// Map PCI Base memory address addr = mmap (0, memsize, PROT_READ | PROT_WRITE | PROT_NOCACHE, MAP_SHARED, fd, address); if ( addr == (void*) -1) { fprintf ( stderr, "mmap failed : %sn", strerror(errno)); addr=NULL; exit (1); }
// at this point, addr is the address to the video memory. You can use it to read and modify the values that you need to. The variables in this examples are defined in /usr/include/sys/pci.h |
|