Port-arm archive

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

impossible to access /dev/mem on RPi B+ [Was: Sound issues on RPi B+, Jun's latest image]



Thanks Jun,

I want to clarify/correct two things:

(1) The most important issue is the impossible access to /dev/mem, even being root. This character device is registered in /dev/ with major=0 and minor=0. user is root, group is kmem and rights are rw-r-----. Apparently this prevents full use of the GPIO as we have to map memory regions, like in the code snippet given at the end of this email (taken from http://elinux.org/RPi_Low-level_peripherals#C).

(2) Concerning audio output, everything is fine now, except that I have no clue how to control the volume level and that it is impossible to do it from within mplayer (no error output, but controls are ineffective).

Thanks a lot,
   JB

==== example code to play with the GPIO (needs access to /dev/mem as root) ====

//
// Set up a memory regions to access GPIO
//
void setup_io()
{
   /* open /dev/mem */
   if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) {
      printf("can't open /dev/mem \n");
      exit(-1);
   }
 
   /* mmap GPIO */
   gpio_map = mmap(
      NULL,             //Any adddress in our space will do
      BLOCK_SIZE,       //Map length
      PROT_READ|PROT_WRITE,// Enable reading & writting to mapped memory
      MAP_SHARED,       //Shared with other processes
      mem_fd,           //File to map
      GPIO_BASE         //Offset to GPIO peripheral
   );
 
   close(mem_fd); //No need to keep mem_fd open after mmap
 
   if (gpio_map == MAP_FAILED) {
      printf("mmap error %d\n", (int)gpio_map);//errno also set!
      exit(-1);
   }
 
   // Always use volatile pointer!
   gpio = (volatile unsigned *)gpio_map;
 
 
} // setup_io


Home | Main Index | Thread Index | Old Index