I try to write a simple IO Lib for me. For that I use a modification of a existing code:
- Code: Select all
- #include <stdio.h>
 #include <sys/mman.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
 #define BLOCK_SIZE 4096
 #define GPIO_Basis 0x10000600
 struct RT5350_Peripherie {
 unsigned long Adresse;
 int Memory;
 void *Map;
 volatile unsigned int *Addr;
 };
 struct RT5350_Peripherie GPIO = {GPIO_Basis};
 int RAM_Map(struct RT5350_Peripherie *Peripherie);
 // Funktion zum markieren der Speicherbereiche
 int RAM_Map(struct RT5350_Peripherie *Peripherie)
 {
 Peripherie->Memory = open("/dev/mem", O_RDWR | O_SYNC);
 if(Peripherie->Memory < 0)
 {
 printf("Oeffnen von /dev/mem fehlgeschlagen!\n");
 return -1;
 }
 Peripherie->Map = mmap(
 NULL,
 BLOCK_SIZE,
 PROT_READ | PROT_WRITE,
 MAP_SHARED,
 Peripherie->Memory,
 Peripherie->Adresse
 );
 if(Peripherie->Map < 0)
 {
 printf("Mapping fehlgeschlagen!\n");
 return -1;
 }
 Peripherie->Addr = (volatile unsigned int *)Peripherie->Map;
 return 0;
 }
 int main()
 {
 if(RAM_Map(&GPIO) == -1)
 {
 printf("Mappen der GPIO fehlgeschlagen!\n");
 return -1;
 }
 *(GPIO.Addr + 0x74) = 16;
 *(GPIO.Addr + 0x78) = 16;
 }
I want to set GPIO 26 to High-State, but I got a "Segmentation fault" error.
Did I use the wrong adresses?
Thanks!

 ?
?