Skip to content

Commit

Permalink
fix unmapping problem
Browse files Browse the repository at this point in the history
  • Loading branch information
euang committed Mar 6, 2015
1 parent 39afaac commit 73997a5
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions ws2811.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,24 @@ static int max_channel_led_count(ws2811_t *ws2811)
return max;
}

/**
* Unmap a physical address and length from virtual memory.
*
* @param addr Virtual address pointer of device registers.
* @param len Length of mapped region.
*
* @returns None
*/
static void unmap_device(volatile void *addr, const uint32_t len)
{
uint32_t virt = (uint32_t)addr;
uint32_t start_page_addr = virt & PAGE_MASK;
uint32_t end_page_addr = (virt + len) & PAGE_MASK;
uint32_t pages = end_page_addr - start_page_addr + 1;

munmap((void *)addr, PAGE_SIZE * pages);
}

/**
* Map all devices into userspace memory.
*
Expand Down Expand Up @@ -173,22 +191,22 @@ static void unmap_registers(ws2811_t *ws2811)

if (device->dma)
{
unmapmem((void *)device->dma, sizeof(dma_t));
unmap_device(device->dma, sizeof(dma_t));
}

if (device->pwm)
{
unmapmem((void *)device->pwm, sizeof(pwm_t));
unmap_device(device->pwm, sizeof(pwm_t));
}

if (device->cm_pwm)
{
unmapmem((void *)device->cm_pwm, sizeof(cm_pwm_t));
unmap_device(device->cm_pwm, sizeof(cm_pwm_t));
}

if (device->gpio)
{
unmapmem((void *)device->gpio, sizeof(gpio_t));
unmap_device(device->gpio, sizeof(gpio_t));
}
}

Expand Down

0 comments on commit 73997a5

Please sign in to comment.