MCPcopy Create free account
hub / github.com/WiringPi/WiringPi / wiringPiGlobalMemoryAccess

Function wiringPiGlobalMemoryAccess

wiringPi/wiringPi.c:3383–3434  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3381
3382
3383int wiringPiGlobalMemoryAccess(void)
3384{
3385 const char* gpiomemGlobal;
3386 int fd=-1;
3387 unsigned int MMAP_size;
3388 unsigned int BaseAddr, PWMAddr;
3389
3390 piBoard();
3391 if (piRP1Model()) {
3392 GetRP1Memory();
3393 gpiomemGlobal = pciemem_RP1;
3394 MMAP_size = pciemem_RP1_Size;
3395 BaseAddr = 0x00000000;
3396 PWMAddr = 0x00000000; //not supported so far
3397 } else {
3398 gpiomemGlobal = gpiomem_global;
3399 MMAP_size = BLOCK_SIZE;
3400 BaseAddr = piGpioBase + 0x00200000 ;
3401 PWMAddr = piGpioBase + 0x0020C000 ;
3402 }
3403
3404 if ((fd = open (gpiomemGlobal, O_RDWR | O_SYNC | O_CLOEXEC)) >0) {
3405 int returnvalue = 1; // OK
3406
3407 uint32_t * lgpio = (uint32_t *)mmap(0, MMAP_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, BaseAddr) ;
3408 if (lgpio == MAP_FAILED) {
3409 returnvalue = 0;
3410 if (wiringPiDebug)
3411 fprintf(stderr,"wiringPiGlobalMemoryAccess: mmap (GPIO 0x%X,0x%X) failed: %s\n", BaseAddr, MMAP_size, strerror (errno)) ;
3412 } else {
3413 munmap(lgpio, MMAP_size);
3414 if (piRP1Model()) {
3415 returnvalue = 2; // GPIO & PWM accessible (same area, nothing to mmap)
3416 } else {
3417 //check PWM area
3418 uint32_t* lpwm = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, PWMAddr) ;
3419 if (lpwm == MAP_FAILED) {
3420 returnvalue = 1; // only GPIO accessible
3421 if (wiringPiDebug)
3422 fprintf(stderr,"wiringPiGlobalMemoryAccess: mmap (PWM 0x%X,0x%X) failed: %s\n", PWMAddr, MMAP_size, strerror (errno)) ;
3423 } else {
3424 returnvalue = 2; // GPIO & PWM accessible
3425 munmap(lpwm, BLOCK_SIZE);
3426 }
3427 }
3428 }
3429
3430 close(fd);
3431 return returnvalue;
3432 }
3433 return 0; // Failed!
3434}
3435
3436/*
3437 * wiringPiSetup:

Callers 1

doVersionFunction · 0.85

Calls 3

piBoardFunction · 0.85
piRP1ModelFunction · 0.85
GetRP1MemoryFunction · 0.85

Tested by

no test coverage detected